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
;
41 void *nvme_task_first
= nullptr;
42 void *nvme_task_last
= nullptr;
46 std::list
<aio_t
> pending_aios
; ///< not yet submitted
47 std::list
<aio_t
> running_aios
; ///< submitting or submitted
48 std::atomic_int num_pending
= {0};
49 std::atomic_int num_running
= {0};
52 explicit IOContext(CephContext
* cct
, void *p
, bool allow_eio
= false)
53 : cct(cct
), priv(p
), allow_eio(allow_eio
)
57 IOContext(const IOContext
& other
) = delete;
58 IOContext
&operator=(const IOContext
& other
) = delete;
60 bool has_pending_aios() {
61 return num_pending
.load();
67 if (num_running
== 1) {
69 // we might have some pending IOs submitted after the check
70 // as there is no lock protection for aio_submit.
71 // Hence we might have false conditional trigger.
72 // aio_wait has to handle that hence do not care here.
73 std::lock_guard
<std::mutex
> l(lock
);
76 assert(num_running
>= 0);
82 void set_return_value(int _r
) {
86 int get_return_value() const {
96 std::mutex ioc_reap_lock
;
97 std::vector
<IOContext
*> ioc_reap_queue
;
98 std::atomic_int ioc_reap_count
= {0};
101 bool rotational
= true;
104 BlockDevice(CephContext
* cct
) : cct(cct
) {}
105 virtual ~BlockDevice() = default;
106 typedef void (*aio_callback_t
)(void *handle
, void *aio
);
108 static BlockDevice
*create(
109 CephContext
* cct
, const std::string
& path
, aio_callback_t cb
, void *cbpriv
);
110 virtual bool supported_bdev_label() { return true; }
111 virtual bool is_rotational() { return rotational
; }
113 virtual void aio_submit(IOContext
*ioc
) = 0;
115 virtual uint64_t get_size() const = 0;
116 virtual uint64_t get_block_size() const = 0;
118 virtual int collect_metadata(std::string prefix
, std::map
<std::string
,std::string
> *pm
) const = 0;
126 virtual int read_random(
136 virtual int aio_read(
141 virtual int aio_write(
146 virtual int flush() = 0;
148 void queue_reap_ioc(IOContext
*ioc
);
151 // for managing buffered readers/writers
152 virtual int invalidate_cache(uint64_t off
, uint64_t len
) = 0;
153 virtual int open(const std::string
& path
) = 0;
154 virtual void close() = 0;
157 #endif //CEPH_OS_BLUESTORE_BLOCKDEVICE_H