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) 2014 Red Hat
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.
15 #ifndef CEPH_OS_BLUESTORE_KERNELDEVICE_H
16 #define CEPH_OS_BLUESTORE_KERNELDEVICE_H
21 #include "include/interval_set.h"
24 #include "BlockDevice.h"
26 class KernelDevice
: public BlockDevice
{
27 int fd_direct
, fd_buffered
;
35 interval_set
<uint64_t> debug_inflight
;
37 std::atomic
<bool> io_since_flush
= {false};
38 std::mutex flush_mutex
;
40 aio_queue_t aio_queue
;
41 aio_callback_t aio_callback
;
42 void *aio_callback_priv
;
45 struct AioCompletionThread
: public Thread
{
47 explicit AioCompletionThread(KernelDevice
*b
) : bdev(b
) {}
48 void *entry() override
{
54 std::atomic_int injecting_crash
;
60 void _aio_log_start(IOContext
*ioc
, uint64_t offset
, uint64_t length
);
61 void _aio_log_finish(IOContext
*ioc
, uint64_t offset
, uint64_t length
);
63 int _sync_write(uint64_t off
, bufferlist
& bl
, bool buffered
);
67 int direct_read_unaligned(uint64_t off
, uint64_t len
, char *buf
);
69 // stalled aio debugging
70 aio_list_t debug_queue
;
71 std::mutex debug_queue_lock
;
72 aio_t
*debug_oldest
= nullptr;
73 utime_t debug_stall_since
;
74 void debug_aio_link(aio_t
& aio
);
75 void debug_aio_unlink(aio_t
& aio
);
78 KernelDevice(CephContext
* cct
, aio_callback_t cb
, void *cbpriv
);
80 void aio_submit(IOContext
*ioc
) override
;
82 uint64_t get_size() const override
{
85 uint64_t get_block_size() const override
{
89 int collect_metadata(std::string prefix
, map
<std::string
,std::string
> *pm
) const override
;
91 int read(uint64_t off
, uint64_t len
, bufferlist
*pbl
,
93 bool buffered
) override
;
94 int aio_read(uint64_t off
, uint64_t len
, bufferlist
*pbl
,
95 IOContext
*ioc
) override
;
96 int read_random(uint64_t off
, uint64_t len
, char *buf
, bool buffered
) override
;
98 int write(uint64_t off
, bufferlist
& bl
, bool buffered
) override
;
99 int aio_write(uint64_t off
, bufferlist
& bl
,
101 bool buffered
) override
;
102 int flush() override
;
104 // for managing buffered readers/writers
105 int invalidate_cache(uint64_t off
, uint64_t len
) override
;
106 int open(const std::string
& path
) override
;
107 void close() override
;