]> git.proxmox.com Git - ceph.git/blob - ceph/src/os/bluestore/BlockDevice.cc
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / os / bluestore / BlockDevice.cc
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) 2015 XSky <haomai@xsky.com>
7 *
8 * Author: Haomai Wang <haomaiwang@gmail.com>
9 *
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.
14 *
15 */
16
17 #include <libgen.h>
18 #include <unistd.h>
19
20 #include "KernelDevice.h"
21 #if defined(HAVE_SPDK)
22 #include "NVMEDevice.h"
23 #endif
24
25 #include "common/debug.h"
26 #include "common/EventTrace.h"
27
28 #define dout_context cct
29 #define dout_subsys ceph_subsys_bdev
30 #undef dout_prefix
31 #define dout_prefix *_dout << "bdev "
32
33 void IOContext::aio_wait()
34 {
35 std::unique_lock<std::mutex> l(lock);
36 // see _aio_thread for waker logic
37 while (num_running.load() > 0) {
38 dout(10) << __func__ << " " << this
39 << " waiting for " << num_running.load() << " aios to complete"
40 << dendl;
41 cond.wait(l);
42 }
43 dout(20) << __func__ << " " << this << " done" << dendl;
44 }
45
46 BlockDevice *BlockDevice::create(CephContext* cct, const string& path,
47 aio_callback_t cb, void *cbpriv)
48 {
49 string type = "kernel";
50 char buf[PATH_MAX + 1];
51 int r = ::readlink(path.c_str(), buf, sizeof(buf) - 1);
52 if (r >= 0) {
53 buf[r] = '\0';
54 char *bname = ::basename(buf);
55 if (strncmp(bname, SPDK_PREFIX, sizeof(SPDK_PREFIX)-1) == 0)
56 type = "ust-nvme";
57 }
58 dout(1) << __func__ << " path " << path << " type " << type << dendl;
59
60 if (type == "kernel") {
61 return new KernelDevice(cct, cb, cbpriv);
62 }
63 #if defined(HAVE_SPDK)
64 if (type == "ust-nvme") {
65 return new NVMEDevice(cct, cb, cbpriv);
66 }
67 #endif
68
69 derr << __func__ << " unknown backend " << type << dendl;
70 ceph_abort();
71 return NULL;
72 }
73
74 void BlockDevice::queue_reap_ioc(IOContext *ioc)
75 {
76 std::lock_guard<std::mutex> l(ioc_reap_lock);
77 if (ioc_reap_count.load() == 0)
78 ++ioc_reap_count;
79 ioc_reap_queue.push_back(ioc);
80 }
81
82 void BlockDevice::reap_ioc()
83 {
84 if (ioc_reap_count.load()) {
85 std::lock_guard<std::mutex> l(ioc_reap_lock);
86 for (auto p : ioc_reap_queue) {
87 dout(20) << __func__ << " reap ioc " << p << dendl;
88 delete p;
89 }
90 ioc_reap_queue.clear();
91 --ioc_reap_count;
92 }
93 }