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>
26 #include "os/fs/aio.h"
28 #define SPDK_PREFIX "spdk:"
30 /// track in-flight io
35 void *nvme_task_first
= nullptr;
36 void *nvme_task_last
= nullptr;
40 std::condition_variable cond
;
42 std::list
<aio_t
> pending_aios
; ///< not yet submitted
43 std::list
<aio_t
> running_aios
; ///< submitting or submitted
44 std::atomic_int num_pending
= {0};
45 std::atomic_int num_running
= {0};
47 explicit IOContext(CephContext
* cct
, void *p
)
52 IOContext(const IOContext
& other
) = delete;
53 IOContext
&operator=(const IOContext
& other
) = delete;
55 bool has_pending_aios() {
56 return num_pending
.load();
62 std::lock_guard
<std::mutex
> l(lock
);
65 assert(num_running
== 0);
74 std::mutex ioc_reap_lock
;
75 std::vector
<IOContext
*> ioc_reap_queue
;
76 std::atomic_int ioc_reap_count
= {0};
79 bool rotational
= true;
82 BlockDevice(CephContext
* cct
) : cct(cct
) {}
83 virtual ~BlockDevice() = default;
84 typedef void (*aio_callback_t
)(void *handle
, void *aio
);
86 static BlockDevice
*create(
87 CephContext
* cct
, const std::string
& path
, aio_callback_t cb
, void *cbpriv
);
88 virtual bool supported_bdev_label() { return true; }
89 virtual bool is_rotational() { return rotational
; }
91 virtual void aio_submit(IOContext
*ioc
) = 0;
93 virtual uint64_t get_size() const = 0;
94 virtual uint64_t get_block_size() const = 0;
96 virtual int collect_metadata(std::string prefix
, std::map
<std::string
,std::string
> *pm
) const = 0;
104 virtual int read_random(
114 virtual int aio_read(
119 virtual int aio_write(
124 virtual int flush() = 0;
126 void queue_reap_ioc(IOContext
*ioc
);
129 // for managing buffered readers/writers
130 virtual int invalidate_cache(uint64_t off
, uint64_t len
) = 0;
131 virtual int open(const std::string
& path
) = 0;
132 virtual void close() = 0;
135 #endif //CEPH_OS_BLUESTORE_BLOCKDEVICE_H