]> git.proxmox.com Git - ceph.git/blob - ceph/src/os/bluestore/KernelDevice.h
import 14.2.4 nautilus point release
[ceph.git] / ceph / src / os / bluestore / KernelDevice.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3 /*
4 * Ceph - scalable distributed file system
5 *
6 * Copyright (C) 2014 Red Hat
7 *
8 * This is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License version 2.1, as published by the Free Software
11 * Foundation. See file COPYING.
12 *
13 */
14
15 #ifndef CEPH_OS_BLUESTORE_KERNELDEVICE_H
16 #define CEPH_OS_BLUESTORE_KERNELDEVICE_H
17
18 #include <atomic>
19
20 #include "include/types.h"
21 #include "include/interval_set.h"
22 #include "common/Thread.h"
23 #include "include/utime.h"
24
25 #include "ceph_aio.h"
26 #include "BlockDevice.h"
27
28 #ifndef RW_IO_MAX
29 #define RW_IO_MAX 0x7FFFF000
30 #endif
31
32
33 class KernelDevice : public BlockDevice {
34 std::vector<int> fd_directs, fd_buffereds;
35 bool enable_wrt = true;
36 std::string path;
37 bool aio, dio;
38
39 int vdo_fd = -1; ///< fd for vdo sysfs directory
40 string vdo_name;
41
42 std::string devname; ///< kernel dev name (/sys/block/$devname), if any
43
44 ceph::mutex debug_lock = ceph::make_mutex("KernelDevice::debug_lock");
45 interval_set<uint64_t> debug_inflight;
46
47 std::atomic<bool> io_since_flush = {false};
48 ceph::mutex flush_mutex = ceph::make_mutex("KernelDevice::flush_mutex");
49
50 aio_queue_t aio_queue;
51 aio_callback_t discard_callback;
52 void *discard_callback_priv;
53 bool aio_stop;
54 bool discard_started;
55 bool discard_stop;
56
57 ceph::mutex discard_lock = ceph::make_mutex("KernelDevice::discard_lock");
58 ceph::condition_variable discard_cond;
59 bool discard_running = false;
60 interval_set<uint64_t> discard_queued;
61 interval_set<uint64_t> discard_finishing;
62
63 struct AioCompletionThread : public Thread {
64 KernelDevice *bdev;
65 explicit AioCompletionThread(KernelDevice *b) : bdev(b) {}
66 void *entry() override {
67 bdev->_aio_thread();
68 return NULL;
69 }
70 } aio_thread;
71
72 struct DiscardThread : public Thread {
73 KernelDevice *bdev;
74 explicit DiscardThread(KernelDevice *b) : bdev(b) {}
75 void *entry() override {
76 bdev->_discard_thread();
77 return NULL;
78 }
79 } discard_thread;
80
81 std::atomic_int injecting_crash;
82
83 void _aio_thread();
84 void _discard_thread();
85 int queue_discard(interval_set<uint64_t> &to_release) override;
86
87 int _aio_start();
88 void _aio_stop();
89
90 int _discard_start();
91 void _discard_stop();
92
93 void _aio_log_start(IOContext *ioc, uint64_t offset, uint64_t length);
94 void _aio_log_finish(IOContext *ioc, uint64_t offset, uint64_t length);
95
96 int _sync_write(uint64_t off, bufferlist& bl, bool buffered, int write_hint);
97
98 int _lock();
99
100 int direct_read_unaligned(uint64_t off, uint64_t len, char *buf);
101
102 // stalled aio debugging
103 aio_list_t debug_queue;
104 ceph::mutex debug_queue_lock = ceph::make_mutex("KernelDevice::debug_queue_lock");
105 aio_t *debug_oldest = nullptr;
106 utime_t debug_stall_since;
107 void debug_aio_link(aio_t& aio);
108 void debug_aio_unlink(aio_t& aio);
109
110 void _detect_vdo();
111 int choose_fd(bool buffered, int write_hint) const;
112
113 public:
114 KernelDevice(CephContext* cct, aio_callback_t cb, void *cbpriv, aio_callback_t d_cb, void *d_cbpriv);
115
116 void aio_submit(IOContext *ioc) override;
117 void discard_drain() override;
118
119 int collect_metadata(const std::string& prefix, map<std::string,std::string> *pm) const override;
120 int get_devname(std::string *s) override {
121 if (devname.empty()) {
122 return -ENOENT;
123 }
124 *s = devname;
125 return 0;
126 }
127 int get_devices(std::set<std::string> *ls) override;
128
129 bool get_thin_utilization(uint64_t *total, uint64_t *avail) const override;
130
131 int read(uint64_t off, uint64_t len, bufferlist *pbl,
132 IOContext *ioc,
133 bool buffered) override;
134 int aio_read(uint64_t off, uint64_t len, bufferlist *pbl,
135 IOContext *ioc) override;
136 int read_random(uint64_t off, uint64_t len, char *buf, bool buffered) override;
137
138 int write(uint64_t off, bufferlist& bl, bool buffered, int write_hint = WRITE_LIFE_NOT_SET) override;
139 int aio_write(uint64_t off, bufferlist& bl,
140 IOContext *ioc,
141 bool buffered,
142 int write_hint = WRITE_LIFE_NOT_SET) override;
143 int flush() override;
144 int discard(uint64_t offset, uint64_t len) override;
145
146 // for managing buffered readers/writers
147 int invalidate_cache(uint64_t off, uint64_t len) override;
148 int open(const std::string& path) override;
149 void close() override;
150 };
151
152 #endif