1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
5 * Ceph - scalable distributed file system
7 * Copyright (C) 2021 Red Hat, Inc.
9 * This is free software; you can redistribute it and/or modify it under the
10 * terms of the GNU Lesser General Public License version 2.1, as published by
11 * the Free Software Foundation. See file COPYING.
15 #ifndef _SIMPLERADOSSTRIPER_H
16 #define _SIMPLERADOSSTRIPER_H
19 #include <string_view>
22 #include "include/buffer.h"
23 #include "include/rados/librados.hpp"
24 #include "include/uuid.h"
25 #include "include/types.h"
27 #include "common/ceph_time.h"
28 #include "common/perf_counters.h"
30 class [[gnu::visibility("default")]] SimpleRADOSStriper
33 using aiocompletionptr
= std::unique_ptr
<librados::AioCompletion
>;
34 using clock
= ceph::coarse_mono_clock
;
35 using time
= ceph::coarse_mono_time
;
37 static inline const uint64_t object_size
= 22; /* power of 2 */
38 static inline const uint64_t min_growth
= (1<<27); /* 128 MB */
39 static int config_logger(CephContext
* cct
, std::string_view name
, std::shared_ptr
<PerfCounters
>* l
);
41 SimpleRADOSStriper() = default;
42 SimpleRADOSStriper(librados::IoCtx _ioctx
, std::string _oid
)
43 : ioctx(std::move(_ioctx
))
44 , oid(std::move(_oid
))
46 cookie
.generate_random();
47 auto r
= librados::Rados(ioctx
);
48 myaddrs
= r
.get_addrs();
50 SimpleRADOSStriper(const SimpleRADOSStriper
&) = delete;
51 SimpleRADOSStriper
& operator=(const SimpleRADOSStriper
&) = delete;
52 SimpleRADOSStriper
& operator=(SimpleRADOSStriper
&&) = delete;
53 SimpleRADOSStriper(SimpleRADOSStriper
&&) = delete;
54 ~SimpleRADOSStriper();
59 int stat(uint64_t* size
);
60 ssize_t
write(const void* data
, size_t len
, uint64_t off
);
61 ssize_t
read(void* data
, size_t len
, uint64_t off
);
62 int truncate(size_t size
);
64 int lock(uint64_t timeoutms
);
66 int is_locked() const {
69 int print_lockers(std::ostream
& out
);
70 void set_logger(std::shared_ptr
<PerfCounters
> l
) {
71 logger
= std::move(l
);
73 void set_lock_interval(std::chrono::milliseconds t
) {
74 lock_keeper_interval
= t
;
76 void set_lock_timeout(std::chrono::milliseconds t
) {
77 lock_keeper_timeout
= t
;
79 void set_blocklist_the_dead(bool b
) {
80 blocklist_the_dead
= b
;
90 ceph::bufferlist
str2bl(std::string_view sv
);
91 ceph::bufferlist
uint2bl(uint64_t v
);
92 int set_metadata(uint64_t new_size
, bool update_size
);
93 int shrink_alloc(uint64_t a
);
94 int maybe_shrink_alloc();
95 int wait_for_aios(bool block
);
97 extent
get_next_extent(uint64_t off
, size_t len
) const;
98 extent
get_first_extent() const {
99 return get_next_extent(0, 0);
103 static inline const char XATTR_EXCL
[] = "striper.excl";
104 static inline const char XATTR_SIZE
[] = "striper.size";
105 static inline const char XATTR_ALLOCATED
[] = "striper.allocated";
106 static inline const char XATTR_VERSION
[] = "striper.version";
107 static inline const char XATTR_LAYOUT_STRIPE_UNIT
[] = "striper.layout.stripe_unit";
108 static inline const char XATTR_LAYOUT_STRIPE_COUNT
[] = "striper.layout.stripe_count";
109 static inline const char XATTR_LAYOUT_OBJECT_SIZE
[] = "striper.layout.object_size";
110 static inline const std::string biglock
= "striper.lock";
111 static inline const std::string lockdesc
= "SimpleRADOSStriper";
113 void lock_keeper_main();
115 librados::IoCtx ioctx
;
116 std::shared_ptr
<PerfCounters
> logger
;
118 std::thread lock_keeper
;
119 std::condition_variable lock_keeper_cvar
;
120 std::mutex lock_keeper_mutex
;
121 time last_renewal
= time::min();
122 std::chrono::milliseconds lock_keeper_interval
= 2000ms
;
123 std::chrono::milliseconds lock_keeper_timeout
= 30000ms
;
124 std::atomic
<bool> blocklisted
= false;
125 bool shutdown
= false;
126 version_t version
= 0;
127 std::string exclusive_holder
;
129 uint64_t allocated
= 0;
132 bool size_dirty
= false;
133 bool blocklist_the_dead
= true;
134 std::queue
<aiocompletionptr
> aios
;
135 int aios_failure
= 0;
139 #endif /* _SIMPLERADOSSTRIPER_H */