]> git.proxmox.com Git - ceph.git/blob - ceph/src/os/bluestore/KernelDevice.h
update sources to ceph Nautilus 14.2.1
[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 class KernelDevice : public BlockDevice {
29 std::vector<int> fd_directs, fd_buffereds;
30 bool enable_wrt = true;
31 std::string path;
32 bool aio, dio;
33
34 int vdo_fd = -1; ///< fd for vdo sysfs directory
35 string vdo_name;
36
37 std::string devname; ///< kernel dev name (/sys/block/$devname), if any
38
39 ceph::mutex debug_lock = ceph::make_mutex("KernelDevice::debug_lock");
40 interval_set<uint64_t> debug_inflight;
41
42 std::atomic<bool> io_since_flush = {false};
43 ceph::mutex flush_mutex = ceph::make_mutex("KernelDevice::flush_mutex");
44
45 aio_queue_t aio_queue;
46 aio_callback_t discard_callback;
47 void *discard_callback_priv;
48 bool aio_stop;
49 bool discard_started;
50 bool discard_stop;
51
52 ceph::mutex discard_lock = ceph::make_mutex("KernelDevice::discard_lock");
53 ceph::condition_variable discard_cond;
54 bool discard_running = false;
55 interval_set<uint64_t> discard_queued;
56 interval_set<uint64_t> discard_finishing;
57
58 struct AioCompletionThread : public Thread {
59 KernelDevice *bdev;
60 explicit AioCompletionThread(KernelDevice *b) : bdev(b) {}
61 void *entry() override {
62 bdev->_aio_thread();
63 return NULL;
64 }
65 } aio_thread;
66
67 struct DiscardThread : public Thread {
68 KernelDevice *bdev;
69 explicit DiscardThread(KernelDevice *b) : bdev(b) {}
70 void *entry() override {
71 bdev->_discard_thread();
72 return NULL;
73 }
74 } discard_thread;
75
76 std::atomic_int injecting_crash;
77
78 void _aio_thread();
79 void _discard_thread();
80 int queue_discard(interval_set<uint64_t> &to_release) override;
81
82 int _aio_start();
83 void _aio_stop();
84
85 int _discard_start();
86 void _discard_stop();
87
88 void _aio_log_start(IOContext *ioc, uint64_t offset, uint64_t length);
89 void _aio_log_finish(IOContext *ioc, uint64_t offset, uint64_t length);
90
91 int _sync_write(uint64_t off, bufferlist& bl, bool buffered, int write_hint);
92
93 int _lock();
94
95 int direct_read_unaligned(uint64_t off, uint64_t len, char *buf);
96
97 // stalled aio debugging
98 aio_list_t debug_queue;
99 ceph::mutex debug_queue_lock = ceph::make_mutex("KernelDevice::debug_queue_lock");
100 aio_t *debug_oldest = nullptr;
101 utime_t debug_stall_since;
102 void debug_aio_link(aio_t& aio);
103 void debug_aio_unlink(aio_t& aio);
104
105 void _detect_vdo();
106 int choose_fd(bool buffered, int write_hint) const;
107
108 public:
109 KernelDevice(CephContext* cct, aio_callback_t cb, void *cbpriv, aio_callback_t d_cb, void *d_cbpriv);
110
111 void aio_submit(IOContext *ioc) override;
112 void discard_drain() override;
113
114 int collect_metadata(const std::string& prefix, map<std::string,std::string> *pm) const override;
115 int get_devname(std::string *s) override {
116 if (devname.empty()) {
117 return -ENOENT;
118 }
119 *s = devname;
120 return 0;
121 }
122 int get_devices(std::set<std::string> *ls) override;
123
124 bool get_thin_utilization(uint64_t *total, uint64_t *avail) const override;
125
126 int read(uint64_t off, uint64_t len, bufferlist *pbl,
127 IOContext *ioc,
128 bool buffered) override;
129 int aio_read(uint64_t off, uint64_t len, bufferlist *pbl,
130 IOContext *ioc) override;
131 int read_random(uint64_t off, uint64_t len, char *buf, bool buffered) override;
132
133 int write(uint64_t off, bufferlist& bl, bool buffered, int write_hint = WRITE_LIFE_NOT_SET) override;
134 int aio_write(uint64_t off, bufferlist& bl,
135 IOContext *ioc,
136 bool buffered,
137 int write_hint = WRITE_LIFE_NOT_SET) override;
138 int flush() override;
139 int discard(uint64_t offset, uint64_t len) override;
140
141 // for managing buffered readers/writers
142 int invalidate_cache(uint64_t off, uint64_t len) override;
143 int open(const std::string& path) override;
144 void close() override;
145 };
146
147 #endif