1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 * Ceph - scalable distributed file system
6 * Copyright (C) 2015 XSky <haomai@xsky.com>
8 * Author: Haomai Wang <haomaiwang@gmail.com>
10 * This is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License version 2.1, as published by the Free Software
13 * Foundation. See file COPYING.
17 #ifndef CEPH_OS_BLUESTORE_BLOCKDEVICE_H
18 #define CEPH_OS_BLUESTORE_BLOCKDEVICE_H
21 #include <condition_variable>
28 #define SPDK_PREFIX "spdk:"
30 /// track in-flight io
34 std::condition_variable cond;
40 void *nvme_task_first = nullptr;
41 void *nvme_task_last = nullptr;
45 std::list<aio_t> pending_aios; ///< not yet submitted
46 std::list<aio_t> running_aios; ///< submitting or submitted
47 std::atomic_int num_pending = {0};
48 std::atomic_int num_running = {0};
50 explicit IOContext(CephContext* cct, void *p)
55 IOContext(const IOContext& other) = delete;
56 IOContext &operator=(const IOContext& other) = delete;
58 bool has_pending_aios() {
59 return num_pending.load();
65 if (num_running == 1) {
67 // we might have some pending IOs submitted after the check
68 // as there is no lock protection for aio_submit.
69 // Hence we might have false conditional trigger.
70 // aio_wait has to handle that hence do not care here.
71 std::lock_guard<std::mutex> l(lock);
74 assert(num_running >= 0);
86 std::mutex ioc_reap_lock;
87 std::vector<IOContext*> ioc_reap_queue;
88 std::atomic_int ioc_reap_count = {0};
91 bool rotational = true;
94 BlockDevice(CephContext* cct) : cct(cct) {}
95 virtual ~BlockDevice() = default;
96 typedef void (*aio_callback_t)(void *handle, void *aio);
98 static BlockDevice *create(
99 CephContext* cct, const std::string& path, aio_callback_t cb, void *cbpriv);
100 virtual bool supported_bdev_label() { return true; }
101 virtual bool is_rotational() { return rotational; }
103 virtual void aio_submit(IOContext *ioc) = 0;
105 virtual uint64_t get_size() const = 0;
106 virtual uint64_t get_block_size() const = 0;
108 virtual int collect_metadata(std::string prefix, std::map<std::string,std::string> *pm) const = 0;
116 virtual int read_random(
126 virtual int aio_read(
131 virtual int aio_write(
136 virtual int flush() = 0;
138 void queue_reap_ioc(IOContext *ioc);
141 // for managing buffered readers/writers
142 virtual int invalidate_cache(uint64_t off, uint64_t len) = 0;
143 virtual int open(const std::string& path) = 0;
144 virtual void close() = 0;
147 #endif //CEPH_OS_BLUESTORE_BLOCKDEVICE_H