-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathObjecter.h
4147 lines (3795 loc) · 132 KB
/
Objecter.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
/*
* Ceph - scalable distributed file system
*
* Copyright (C) 2004-2006 Sage Weil <[email protected]>
*
* This is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1, as published by the Free Software
* Foundation. See file COPYING.
*
*/
#ifndef CEPH_OBJECTER_H
#define CEPH_OBJECTER_H
#include <condition_variable>
#include <list>
#include <map>
#include <mutex>
#include <memory>
#include <sstream>
#include <string>
#include <string_view>
#include <type_traits>
#include <variant>
#include <boost/container/small_vector.hpp>
#include <boost/asio/any_completion_handler.hpp>
#include <boost/asio/append.hpp>
#include <boost/asio/async_result.hpp>
#include <boost/asio/consign.hpp>
#include <boost/asio/defer.hpp>
#include <boost/asio/io_context.hpp>
#include <boost/asio/io_context_strand.hpp>
#include <boost/asio/post.hpp>
#include <fmt/format.h>
#include "include/buffer.h"
#include "include/ceph_assert.h"
#include "include/ceph_fs.h"
#include "include/common_fwd.h"
#include "include/expected.hpp"
#include "include/types.h"
#include "include/rados/rados_types.hpp"
#include "include/function2.hpp"
#include "include/neorados/RADOS_Decodable.hpp"
#include "common/async/completion.h"
#include "common/admin_socket.h"
#include "common/ceph_time.h"
#include "common/ceph_mutex.h"
#include "common/ceph_timer.h"
#include "common/config_obs.h"
#include "common/shunique_lock.h"
#include "common/zipkin_trace.h"
#include "common/tracer.h"
#include "common/Throttle.h"
#include "mon/MonClient.h"
#include "messages/MOSDOp.h"
#include "msg/Dispatcher.h"
#include "osd/OSDMap.h"
#include "osd/error_code.h"
class Context;
class Messenger;
class MonClient;
class Message;
class MPoolOpReply;
class MGetPoolStatsReply;
class MStatfsReply;
class MCommandReply;
class MWatchNotify;
struct ObjectOperation;
template<typename T>
struct EnumerationContext;
template<typename t>
struct CB_EnumerateReply;
inline constexpr std::size_t osdc_opvec_len = 2;
using osdc_opvec = boost::container::small_vector<OSDOp, osdc_opvec_len>;
// -----------------------------------------
struct ObjectOperation {
osdc_opvec ops;
int flags = 0;
int priority = 0;
boost::container::small_vector<ceph::buffer::list*, osdc_opvec_len> out_bl;
boost::container::small_vector<
fu2::unique_function<void(boost::system::error_code, int,
const ceph::buffer::list& bl) &&>,
osdc_opvec_len> out_handler;
boost::container::small_vector<int*, osdc_opvec_len> out_rval;
boost::container::small_vector<boost::system::error_code*,
osdc_opvec_len> out_ec;
ObjectOperation() = default;
ObjectOperation(const ObjectOperation&) = delete;
ObjectOperation& operator =(const ObjectOperation&) = delete;
ObjectOperation(ObjectOperation&&) = default;
ObjectOperation& operator =(ObjectOperation&&) = default;
~ObjectOperation() = default;
size_t size() const {
return ops.size();
}
void clear() {
ops.clear();
flags = 0;
priority = 0;
out_bl.clear();
out_handler.clear();
out_rval.clear();
out_ec.clear();
}
void set_last_op_flags(int flags) {
ceph_assert(!ops.empty());
ops.rbegin()->op.flags = flags;
}
void set_handler(fu2::unique_function<void(boost::system::error_code, int,
const ceph::buffer::list&) &&> f) {
if (f) {
if (out_handler.back()) {
// This happens seldom enough that we may as well keep folding
// functions together when we get another one rather than
// using a container.
out_handler.back() =
[f = std::move(f),
g = std::move(std::move(out_handler.back()))]
(boost::system::error_code ec, int r,
const ceph::buffer::list& bl) mutable {
std::move(g)(ec, r, bl);
std::move(f)(ec, r, bl);
};
} else {
out_handler.back() = std::move(f);
}
}
ceph_assert(ops.size() == out_handler.size());
}
void set_handler(Context *c) {
if (c)
set_handler([c = std::unique_ptr<Context>(c)](boost::system::error_code,
int r,
const ceph::buffer::list&) mutable {
c.release()->complete(r);
});
}
OSDOp& add_op(int op) {
ops.emplace_back();
ops.back().op.op = op;
out_bl.push_back(nullptr);
ceph_assert(ops.size() == out_bl.size());
out_handler.emplace_back();
ceph_assert(ops.size() == out_handler.size());
out_rval.push_back(nullptr);
ceph_assert(ops.size() == out_rval.size());
out_ec.push_back(nullptr);
ceph_assert(ops.size() == out_ec.size());
return ops.back();
}
void add_data(int op, uint64_t off, uint64_t len, ceph::buffer::list& bl) {
OSDOp& osd_op = add_op(op);
osd_op.op.extent.offset = off;
osd_op.op.extent.length = len;
osd_op.indata.claim_append(bl);
}
void add_writesame(int op, uint64_t off, uint64_t write_len,
ceph::buffer::list& bl) {
OSDOp& osd_op = add_op(op);
osd_op.op.writesame.offset = off;
osd_op.op.writesame.length = write_len;
osd_op.op.writesame.data_length = bl.length();
osd_op.indata.claim_append(bl);
}
void add_xattr(int op, const char *name, const ceph::buffer::list& data) {
OSDOp& osd_op = add_op(op);
osd_op.op.xattr.name_len = (name ? strlen(name) : 0);
osd_op.op.xattr.value_len = data.length();
if (name)
osd_op.indata.append(name, osd_op.op.xattr.name_len);
osd_op.indata.append(data);
}
void add_xattr_cmp(int op, const char *name, uint8_t cmp_op,
uint8_t cmp_mode, const ceph::buffer::list& data) {
OSDOp& osd_op = add_op(op);
osd_op.op.xattr.name_len = (name ? strlen(name) : 0);
osd_op.op.xattr.value_len = data.length();
osd_op.op.xattr.cmp_op = cmp_op;
osd_op.op.xattr.cmp_mode = cmp_mode;
if (name)
osd_op.indata.append(name, osd_op.op.xattr.name_len);
osd_op.indata.append(data);
}
void add_xattr(int op, std::string_view name, const ceph::buffer::list& data) {
OSDOp& osd_op = add_op(op);
osd_op.op.xattr.name_len = name.size();
osd_op.op.xattr.value_len = data.length();
osd_op.indata.append(name.data(), osd_op.op.xattr.name_len);
osd_op.indata.append(data);
}
void add_xattr_cmp(int op, std::string_view name, uint8_t cmp_op,
uint8_t cmp_mode, const ceph::buffer::list& data) {
OSDOp& osd_op = add_op(op);
osd_op.op.xattr.name_len = name.size();
osd_op.op.xattr.value_len = data.length();
osd_op.op.xattr.cmp_op = cmp_op;
osd_op.op.xattr.cmp_mode = cmp_mode;
if (!name.empty())
osd_op.indata.append(name.data(), osd_op.op.xattr.name_len);
osd_op.indata.append(data);
}
void add_call(int op, std::string_view cname, std::string_view method,
const ceph::buffer::list &indata,
ceph::buffer::list *outbl, Context *ctx, int *prval) {
OSDOp& osd_op = add_op(op);
unsigned p = ops.size() - 1;
set_handler(ctx);
out_bl[p] = outbl;
out_rval[p] = prval;
osd_op.op.cls.class_len = cname.size();
osd_op.op.cls.method_len = method.size();
osd_op.op.cls.indata_len = indata.length();
osd_op.indata.append(cname.data(), osd_op.op.cls.class_len);
osd_op.indata.append(method.data(), osd_op.op.cls.method_len);
osd_op.indata.append(indata);
}
void add_call(int op, std::string_view cname, std::string_view method,
const ceph::buffer::list &indata,
fu2::unique_function<void(boost::system::error_code,
const ceph::buffer::list&) &&> f) {
OSDOp& osd_op = add_op(op);
set_handler([f = std::move(f)](boost::system::error_code ec,
int,
const ceph::buffer::list& bl) mutable {
std::move(f)(ec, bl);
});
osd_op.op.cls.class_len = cname.size();
osd_op.op.cls.method_len = method.size();
osd_op.op.cls.indata_len = indata.length();
osd_op.indata.append(cname.data(), osd_op.op.cls.class_len);
osd_op.indata.append(method.data(), osd_op.op.cls.method_len);
osd_op.indata.append(indata);
}
void add_call(int op, std::string_view cname, std::string_view method,
const ceph::buffer::list &indata,
fu2::unique_function<void(boost::system::error_code, int,
const ceph::buffer::list&) &&> f) {
OSDOp& osd_op = add_op(op);
set_handler([f = std::move(f)](boost::system::error_code ec,
int r,
const ceph::buffer::list& bl) mutable {
std::move(f)(ec, r, bl);
});
osd_op.op.cls.class_len = cname.size();
osd_op.op.cls.method_len = method.size();
osd_op.op.cls.indata_len = indata.length();
osd_op.indata.append(cname.data(), osd_op.op.cls.class_len);
osd_op.indata.append(method.data(), osd_op.op.cls.method_len);
osd_op.indata.append(indata);
}
void add_pgls(int op, uint64_t count, collection_list_handle_t cookie,
epoch_t start_epoch) {
using ceph::encode;
OSDOp& osd_op = add_op(op);
osd_op.op.pgls.count = count;
osd_op.op.pgls.start_epoch = start_epoch;
encode(cookie, osd_op.indata);
}
void add_pgls_filter(int op, uint64_t count, const ceph::buffer::list& filter,
collection_list_handle_t cookie, epoch_t start_epoch) {
using ceph::encode;
OSDOp& osd_op = add_op(op);
osd_op.op.pgls.count = count;
osd_op.op.pgls.start_epoch = start_epoch;
std::string cname = "pg";
std::string mname = "filter";
encode(cname, osd_op.indata);
encode(mname, osd_op.indata);
osd_op.indata.append(filter);
encode(cookie, osd_op.indata);
}
void add_alloc_hint(int op, uint64_t expected_object_size,
uint64_t expected_write_size,
uint32_t flags) {
OSDOp& osd_op = add_op(op);
osd_op.op.alloc_hint.expected_object_size = expected_object_size;
osd_op.op.alloc_hint.expected_write_size = expected_write_size;
osd_op.op.alloc_hint.flags = flags;
}
// ------
// pg
void pg_ls(uint64_t count, ceph::buffer::list& filter,
collection_list_handle_t cookie, epoch_t start_epoch) {
if (filter.length() == 0)
add_pgls(CEPH_OSD_OP_PGLS, count, cookie, start_epoch);
else
add_pgls_filter(CEPH_OSD_OP_PGLS_FILTER, count, filter, cookie,
start_epoch);
flags |= CEPH_OSD_FLAG_PGOP;
}
void pg_nls(uint64_t count, const ceph::buffer::list& filter,
collection_list_handle_t cookie, epoch_t start_epoch) {
if (filter.length() == 0)
add_pgls(CEPH_OSD_OP_PGNLS, count, cookie, start_epoch);
else
add_pgls_filter(CEPH_OSD_OP_PGNLS_FILTER, count, filter, cookie,
start_epoch);
flags |= CEPH_OSD_FLAG_PGOP;
}
void scrub_ls(const librados::object_id_t& start_after,
uint64_t max_to_get,
std::vector<librados::inconsistent_obj_t> *objects,
uint32_t *interval,
int *rval);
void scrub_ls(const librados::object_id_t& start_after,
uint64_t max_to_get,
std::vector<librados::inconsistent_snapset_t> *objects,
uint32_t *interval,
int *rval);
void create(bool excl) {
OSDOp& o = add_op(CEPH_OSD_OP_CREATE);
o.op.flags = (excl ? CEPH_OSD_OP_FLAG_EXCL : 0);
}
struct CB_ObjectOperation_stat {
ceph::buffer::list bl;
uint64_t *psize;
ceph::real_time *pmtime;
time_t *ptime;
struct timespec *pts;
int *prval;
boost::system::error_code* pec;
CB_ObjectOperation_stat(uint64_t *ps, ceph::real_time *pm, time_t *pt, struct timespec *_pts,
int *prval, boost::system::error_code* pec)
: psize(ps), pmtime(pm), ptime(pt), pts(_pts), prval(prval), pec(pec) {}
void operator()(boost::system::error_code ec, int r, const ceph::buffer::list& bl) {
using ceph::decode;
if (r >= 0) {
auto p = bl.cbegin();
try {
uint64_t size;
ceph::real_time mtime;
decode(size, p);
decode(mtime, p);
if (psize)
*psize = size;
if (pmtime)
*pmtime = mtime;
if (ptime)
*ptime = ceph::real_clock::to_time_t(mtime);
if (pts)
*pts = ceph::real_clock::to_timespec(mtime);
} catch (const ceph::buffer::error& e) {
if (prval)
*prval = -EIO;
if (pec)
*pec = e.code();
}
}
}
};
void stat(uint64_t *psize, ceph::real_time *pmtime, int *prval) {
add_op(CEPH_OSD_OP_STAT);
set_handler(CB_ObjectOperation_stat(psize, pmtime, nullptr, nullptr, prval,
nullptr));
out_rval.back() = prval;
}
void stat(uint64_t *psize, ceph::real_time *pmtime,
boost::system::error_code* ec) {
add_op(CEPH_OSD_OP_STAT);
set_handler(CB_ObjectOperation_stat(psize, pmtime, nullptr, nullptr,
nullptr, ec));
out_ec.back() = ec;
}
void stat(uint64_t *psize, time_t *ptime, int *prval) {
add_op(CEPH_OSD_OP_STAT);
set_handler(CB_ObjectOperation_stat(psize, nullptr, ptime, nullptr, prval,
nullptr));
out_rval.back() = prval;
}
void stat(uint64_t *psize, struct timespec *pts, int *prval) {
add_op(CEPH_OSD_OP_STAT);
set_handler(CB_ObjectOperation_stat(psize, nullptr, nullptr, pts, prval, nullptr));
out_rval.back() = prval;
}
void stat(uint64_t *psize, ceph::real_time *pmtime, std::nullptr_t) {
add_op(CEPH_OSD_OP_STAT);
set_handler(CB_ObjectOperation_stat(psize, pmtime, nullptr, nullptr, nullptr,
nullptr));
}
void stat(uint64_t *psize, time_t *ptime, std::nullptr_t) {
add_op(CEPH_OSD_OP_STAT);
set_handler(CB_ObjectOperation_stat(psize, nullptr, ptime, nullptr, nullptr,
nullptr));
}
void stat(uint64_t *psize, struct timespec *pts, std::nullptr_t) {
add_op(CEPH_OSD_OP_STAT);
set_handler(CB_ObjectOperation_stat(psize, nullptr, nullptr, pts, nullptr,
nullptr));
}
void stat(uint64_t *psize, std::nullptr_t, std::nullptr_t) {
add_op(CEPH_OSD_OP_STAT);
set_handler(CB_ObjectOperation_stat(psize, nullptr, nullptr, nullptr,
nullptr, nullptr));
}
// object cmpext
struct CB_ObjectOperation_cmpext {
int* prval = nullptr;
boost::system::error_code* ec = nullptr;
uint64_t* mismatch_offset = nullptr;
explicit CB_ObjectOperation_cmpext(int *prval)
: prval(prval) {}
CB_ObjectOperation_cmpext(boost::system::error_code* ec,
uint64_t* mismatch_offset)
: ec(ec), mismatch_offset(mismatch_offset) {}
void operator()(boost::system::error_code ec, int r,
const ceph::buffer::list&) {
if (prval)
*prval = r;
if (r <= -MAX_ERRNO) {
if (this->ec) {
*this->ec = make_error_code(osd_errc::cmpext_mismatch);
}
if (mismatch_offset) {
*mismatch_offset = -MAX_ERRNO - r;
}
throw boost::system::system_error(osd_errc::cmpext_mismatch);
} else if (r < 0) {
if (this->ec) {
*this->ec = ec;
}
if (mismatch_offset) {
*mismatch_offset = -1;
}
} else {
if (this->ec) {
this->ec->clear();
}
if (mismatch_offset) {
*mismatch_offset = -1;
}
}
}
};
void cmpext(uint64_t off, ceph::buffer::list& cmp_bl, int *prval) {
add_data(CEPH_OSD_OP_CMPEXT, off, cmp_bl.length(), cmp_bl);
set_handler(CB_ObjectOperation_cmpext(prval));
out_rval.back() = prval;
}
void cmpext(uint64_t off, ceph::buffer::list&& cmp_bl, boost::system::error_code* ec,
uint64_t* mismatch_offset) {
add_data(CEPH_OSD_OP_CMPEXT, off, cmp_bl.length(), cmp_bl);
set_handler(CB_ObjectOperation_cmpext(ec, mismatch_offset));
out_ec.back() = ec;
}
// Used by C API
void cmpext(uint64_t off, uint64_t cmp_len, const char *cmp_buf, int *prval) {
ceph::buffer::list cmp_bl;
cmp_bl.append(cmp_buf, cmp_len);
add_data(CEPH_OSD_OP_CMPEXT, off, cmp_len, cmp_bl);
set_handler(CB_ObjectOperation_cmpext(prval));
out_rval.back() = prval;
}
void read(uint64_t off, uint64_t len, ceph::buffer::list *pbl, int *prval,
Context* ctx) {
ceph::buffer::list bl;
add_data(CEPH_OSD_OP_READ, off, len, bl);
unsigned p = ops.size() - 1;
out_bl[p] = pbl;
out_rval[p] = prval;
set_handler(ctx);
}
void read(uint64_t off, uint64_t len, boost::system::error_code* ec,
ceph::buffer::list* pbl) {
ceph::buffer::list bl;
add_data(CEPH_OSD_OP_READ, off, len, bl);
out_ec.back() = ec;
out_bl.back() = pbl;
}
template<typename Ex>
struct CB_ObjectOperation_sparse_read {
ceph::buffer::list* data_bl;
Ex* extents;
int* prval;
boost::system::error_code* pec;
CB_ObjectOperation_sparse_read(ceph::buffer::list* data_bl,
Ex* extents,
int* prval,
boost::system::error_code* pec)
: data_bl(data_bl), extents(extents), prval(prval), pec(pec) {}
void operator()(boost::system::error_code ec, int r, const ceph::buffer::list& bl) {
auto iter = bl.cbegin();
if (r >= 0) {
// NOTE: it's possible the sub-op has not been executed but the result
// code remains zeroed. Avoid the costly exception handling on a
// potential IO path.
if (bl.length() > 0) {
try {
decode(*extents, iter);
decode(*data_bl, iter);
} catch (const ceph::buffer::error& e) {
if (prval)
*prval = -EIO;
if (pec)
*pec = e.code();
}
} else if (prval) {
*prval = -EIO;
if (pec)
*pec = buffer::errc::end_of_buffer;
}
}
}
};
void sparse_read(uint64_t off, uint64_t len, std::map<uint64_t, uint64_t>* m,
ceph::buffer::list* data_bl, int* prval,
uint64_t truncate_size = 0, uint32_t truncate_seq = 0) {
ceph::buffer::list bl;
add_data(CEPH_OSD_OP_SPARSE_READ, off, len, bl);
OSDOp& o = *ops.rbegin();
o.op.extent.truncate_size = truncate_size;
o.op.extent.truncate_seq = truncate_seq;
set_handler(CB_ObjectOperation_sparse_read(data_bl, m, prval, nullptr));
out_rval.back() = prval;
}
void sparse_read(uint64_t off, uint64_t len,
boost::system::error_code* ec,
std::vector<std::pair<uint64_t, uint64_t>>* m,
ceph::buffer::list* data_bl) {
ceph::buffer::list bl;
add_data(CEPH_OSD_OP_SPARSE_READ, off, len, bl);
set_handler(CB_ObjectOperation_sparse_read(data_bl, m, nullptr, ec));
out_ec.back() = ec;
}
void write(uint64_t off, ceph::buffer::list& bl,
uint64_t truncate_size,
uint32_t truncate_seq) {
add_data(CEPH_OSD_OP_WRITE, off, bl.length(), bl);
OSDOp& o = *ops.rbegin();
o.op.extent.truncate_size = truncate_size;
o.op.extent.truncate_seq = truncate_seq;
}
void write(uint64_t off, ceph::buffer::list& bl) {
write(off, bl, 0, 0);
}
void write(uint64_t off, ceph::buffer::list&& bl) {
write(off, bl, 0, 0);
}
void write_full(ceph::buffer::list& bl) {
add_data(CEPH_OSD_OP_WRITEFULL, 0, bl.length(), bl);
}
void write_full(ceph::buffer::list&& bl) {
add_data(CEPH_OSD_OP_WRITEFULL, 0, bl.length(), bl);
}
void writesame(uint64_t off, uint64_t write_len, ceph::buffer::list& bl) {
add_writesame(CEPH_OSD_OP_WRITESAME, off, write_len, bl);
}
void writesame(uint64_t off, uint64_t write_len, ceph::buffer::list&& bl) {
add_writesame(CEPH_OSD_OP_WRITESAME, off, write_len, bl);
}
void append(ceph::buffer::list& bl) {
add_data(CEPH_OSD_OP_APPEND, 0, bl.length(), bl);
}
void append(ceph::buffer::list&& bl) {
add_data(CEPH_OSD_OP_APPEND, 0, bl.length(), bl);
}
void zero(uint64_t off, uint64_t len) {
ceph::buffer::list bl;
add_data(CEPH_OSD_OP_ZERO, off, len, bl);
}
void truncate(uint64_t off) {
ceph::buffer::list bl;
add_data(CEPH_OSD_OP_TRUNCATE, off, 0, bl);
}
void remove() {
ceph::buffer::list bl;
add_data(CEPH_OSD_OP_DELETE, 0, 0, bl);
}
void mapext(uint64_t off, uint64_t len) {
ceph::buffer::list bl;
add_data(CEPH_OSD_OP_MAPEXT, off, len, bl);
}
void sparse_read(uint64_t off, uint64_t len) {
ceph::buffer::list bl;
add_data(CEPH_OSD_OP_SPARSE_READ, off, len, bl);
}
void checksum(uint8_t type, const ceph::buffer::list &init_value_bl,
uint64_t off, uint64_t len, size_t chunk_size,
ceph::buffer::list *pbl, int *prval, Context *ctx) {
OSDOp& osd_op = add_op(CEPH_OSD_OP_CHECKSUM);
osd_op.op.checksum.offset = off;
osd_op.op.checksum.length = len;
osd_op.op.checksum.type = type;
osd_op.op.checksum.chunk_size = chunk_size;
osd_op.indata.append(init_value_bl);
unsigned p = ops.size() - 1;
out_bl[p] = pbl;
out_rval[p] = prval;
set_handler(ctx);
}
void checksum(uint8_t type, ceph::buffer::list&& init_value,
uint64_t off, uint64_t len, size_t chunk_size,
fu2::unique_function<void(boost::system::error_code, int,
const ceph::buffer::list&) &&> f,
boost::system::error_code* ec) {
OSDOp& osd_op = add_op(CEPH_OSD_OP_CHECKSUM);
osd_op.op.checksum.offset = off;
osd_op.op.checksum.length = len;
osd_op.op.checksum.type = type;
osd_op.op.checksum.chunk_size = chunk_size;
osd_op.indata.append(std::move(init_value));
unsigned p = ops.size() - 1;
out_ec[p] = ec;
set_handler(std::move(f));
}
// object attrs
void getxattr(const char *name, ceph::buffer::list *pbl, int *prval) {
ceph::buffer::list bl;
add_xattr(CEPH_OSD_OP_GETXATTR, name, bl);
unsigned p = ops.size() - 1;
out_bl[p] = pbl;
out_rval[p] = prval;
}
void getxattr(std::string_view name, boost::system::error_code* ec,
buffer::list *pbl) {
ceph::buffer::list bl;
add_xattr(CEPH_OSD_OP_GETXATTR, name, bl);
out_bl.back() = pbl;
out_ec.back() = ec;
}
template<typename Vals>
struct CB_ObjectOperation_decodevals {
uint64_t max_entries;
Vals* pattrs;
bool* ptruncated;
int* prval;
boost::system::error_code* pec;
CB_ObjectOperation_decodevals(uint64_t m, Vals* pa,
bool *pt, int *pr,
boost::system::error_code* pec)
: max_entries(m), pattrs(pa), ptruncated(pt), prval(pr), pec(pec) {
if (ptruncated) {
*ptruncated = false;
}
}
void operator()(boost::system::error_code ec, int r, const ceph::buffer::list& bl) {
if (r >= 0) {
auto p = bl.cbegin();
try {
if (pattrs)
decode(*pattrs, p);
if (ptruncated) {
Vals ignore;
if (!pattrs) {
decode(ignore, p);
pattrs = &ignore;
}
if (!p.end()) {
decode(*ptruncated, p);
} else {
// The OSD did not provide this. Since old OSDs do not
// enfoce omap result limits either, we can infer it from
// the size of the result
*ptruncated = (pattrs->size() == max_entries);
}
}
} catch (const ceph::buffer::error& e) {
if (prval)
*prval = -EIO;
if (pec)
*pec = e.code();
}
}
}
};
template<typename Keys>
struct CB_ObjectOperation_decodekeys {
uint64_t max_entries;
Keys* pattrs;
bool *ptruncated;
int *prval;
boost::system::error_code* pec;
CB_ObjectOperation_decodekeys(uint64_t m, Keys* pa, bool *pt,
int *pr, boost::system::error_code* pec)
: max_entries(m), pattrs(pa), ptruncated(pt), prval(pr), pec(pec) {
if (ptruncated) {
*ptruncated = false;
}
}
void operator()(boost::system::error_code ec, int r, const ceph::buffer::list& bl) {
if (r >= 0) {
using ceph::decode;
auto p = bl.cbegin();
try {
if (pattrs)
decode(*pattrs, p);
if (ptruncated) {
Keys ignore;
if (!pattrs) {
decode(ignore, p);
pattrs = &ignore;
}
if (!p.end()) {
decode(*ptruncated, p);
} else {
// the OSD did not provide this. since old OSDs do not
// enforce omap result limits either, we can infer it from
// the size of the result
*ptruncated = (pattrs->size() == max_entries);
}
}
} catch (const ceph::buffer::error& e) {
if (prval)
*prval = -EIO;
if (pec)
*pec = e.code();
}
}
}
};
struct CB_ObjectOperation_decodewatchers {
std::list<obj_watch_t>* pwatchers;
int* prval;
boost::system::error_code* pec;
CB_ObjectOperation_decodewatchers(std::list<obj_watch_t>* pw, int* pr,
boost::system::error_code* pec)
: pwatchers(pw), prval(pr), pec(pec) {}
void operator()(boost::system::error_code ec, int r,
const ceph::buffer::list& bl) {
if (r >= 0) {
auto p = bl.cbegin();
try {
obj_list_watch_response_t resp;
decode(resp, p);
if (pwatchers) {
for (const auto& watch_item : resp.entries) {
obj_watch_t ow;
std::string sa = watch_item.addr.get_legacy_str();
strncpy(ow.addr, sa.c_str(), sizeof(ow.addr) - 1);
ow.addr[sizeof(ow.addr) - 1] = '\0';
ow.watcher_id = watch_item.name.num();
ow.cookie = watch_item.cookie;
ow.timeout_seconds = watch_item.timeout_seconds;
pwatchers->push_back(std::move(ow));
}
}
} catch (const ceph::buffer::error& e) {
if (prval)
*prval = -EIO;
if (pec)
*pec = e.code();
}
}
}
};
struct CB_ObjectOperation_decodewatchersneo {
std::vector<neorados::ObjWatcher>* pwatchers;
int* prval;
boost::system::error_code* pec;
CB_ObjectOperation_decodewatchersneo(std::vector<neorados::ObjWatcher>* pw,
int* pr,
boost::system::error_code* pec)
: pwatchers(pw), prval(pr), pec(pec) {}
void operator()(boost::system::error_code ec, int r,
const ceph::buffer::list& bl) {
if (r >= 0) {
auto p = bl.cbegin();
try {
obj_list_watch_response_t resp;
decode(resp, p);
if (pwatchers) {
for (const auto& watch_item : resp.entries) {
neorados::ObjWatcher ow;
ow.addr = watch_item.addr.get_legacy_str();
ow.watcher_id = watch_item.name.num();
ow.cookie = watch_item.cookie;
ow.timeout_seconds = watch_item.timeout_seconds;
pwatchers->push_back(std::move(ow));
}
}
} catch (const ceph::buffer::error& e) {
if (prval)
*prval = -EIO;
if (pec)
*pec = e.code();
}
}
}
};
struct CB_ObjectOperation_decodesnaps {
librados::snap_set_t *psnaps;
neorados::SnapSet *neosnaps;
int *prval;
boost::system::error_code* pec;
CB_ObjectOperation_decodesnaps(librados::snap_set_t* ps,
neorados::SnapSet* ns, int* pr,
boost::system::error_code* pec)
: psnaps(ps), neosnaps(ns), prval(pr), pec(pec) {}
void operator()(boost::system::error_code ec, int r, const ceph::buffer::list& bl) {
if (r >= 0) {
using ceph::decode;
auto p = bl.cbegin();
try {
obj_list_snap_response_t resp;
decode(resp, p);
if (psnaps) {
psnaps->clones.clear();
for (auto ci = resp.clones.begin();
ci != resp.clones.end();
++ci) {
librados::clone_info_t clone;
clone.cloneid = ci->cloneid;
clone.snaps.reserve(ci->snaps.size());
clone.snaps.insert(clone.snaps.end(), ci->snaps.begin(),
ci->snaps.end());
clone.overlap = ci->overlap;
clone.size = ci->size;
psnaps->clones.push_back(clone);
}
psnaps->seq = resp.seq;
}
if (neosnaps) {
neosnaps->clones.clear();
for (auto&& c : resp.clones) {
neorados::CloneInfo clone;
clone.cloneid = std::move(c.cloneid);
clone.snaps.reserve(c.snaps.size());
std::move(c.snaps.begin(), c.snaps.end(),
std::back_inserter(clone.snaps));
clone.overlap = c.overlap;
clone.size = c.size;
neosnaps->clones.push_back(std::move(clone));
}
neosnaps->seq = resp.seq;
}
} catch (const ceph::buffer::error& e) {
if (prval)
*prval = -EIO;
if (pec)
*pec = e.code();
}
}
}
};
void getxattrs(std::map<std::string,ceph::buffer::list> *pattrs, int *prval) {
add_op(CEPH_OSD_OP_GETXATTRS);
if (pattrs || prval) {
set_handler(CB_ObjectOperation_decodevals(0, pattrs, nullptr, prval,
nullptr));
out_rval.back() = prval;
}
}
void getxattrs(boost::system::error_code* ec,
boost::container::flat_map<std::string, ceph::buffer::list> *pattrs) {
add_op(CEPH_OSD_OP_GETXATTRS);
set_handler(CB_ObjectOperation_decodevals(0, pattrs, nullptr, nullptr, ec));
out_ec.back() = ec;
}
void setxattr(const char *name, const ceph::buffer::list& bl) {
add_xattr(CEPH_OSD_OP_SETXATTR, name, bl);
}
void setxattr(std::string_view name, const ceph::buffer::list& bl) {
add_xattr(CEPH_OSD_OP_SETXATTR, name, bl);
}
void setxattr(const char *name, const std::string& s) {
ceph::buffer::list bl;
bl.append(s);
add_xattr(CEPH_OSD_OP_SETXATTR, name, bl);
}
void cmpxattr(const char *name, uint8_t cmp_op, uint8_t cmp_mode,
const ceph::buffer::list& bl) {
add_xattr_cmp(CEPH_OSD_OP_CMPXATTR, name, cmp_op, cmp_mode, bl);
}
void cmpxattr(std::string_view name, uint8_t cmp_op, uint8_t cmp_mode,
const ceph::buffer::list& bl) {
add_xattr_cmp(CEPH_OSD_OP_CMPXATTR, name, cmp_op, cmp_mode, bl);
}
void rmxattr(const char *name) {
ceph::buffer::list bl;
add_xattr(CEPH_OSD_OP_RMXATTR, name, bl);
}
void rmxattr(std::string_view name) {
ceph::buffer::list bl;
add_xattr(CEPH_OSD_OP_RMXATTR, name, bl);
}
void setxattrs(std::map<std::string, ceph::buffer::list>& attrs) {
using ceph::encode;
ceph::buffer::list bl;
encode(attrs, bl);
add_xattr(CEPH_OSD_OP_RESETXATTRS, 0, bl.length());
}
void resetxattrs(const char *prefix, std::map<std::string, ceph::buffer::list>& attrs) {
using ceph::encode;
ceph::buffer::list bl;
encode(attrs, bl);
add_xattr(CEPH_OSD_OP_RESETXATTRS, prefix, bl);
}
// trivialmap
void tmap_update(ceph::buffer::list& bl) {
add_data(CEPH_OSD_OP_TMAPUP, 0, 0, bl);
}
// objectmap
void omap_get_keys(const std::string &start_after,
uint64_t max_to_get,
std::set<std::string> *out_set,
bool *ptruncated,
int *prval) {
using ceph::encode;
OSDOp &op = add_op(CEPH_OSD_OP_OMAPGETKEYS);
ceph::buffer::list bl;
encode(start_after, bl);
encode(max_to_get, bl);
op.op.extent.offset = 0;
op.op.extent.length = bl.length();
op.indata.claim_append(bl);
if (prval || ptruncated || out_set) {
set_handler(CB_ObjectOperation_decodekeys(max_to_get, out_set, ptruncated, prval,
nullptr));
out_rval.back() = prval;
}
}
void omap_get_keys(std::optional<std::string_view> start_after,
uint64_t max_to_get,
boost::system::error_code* ec,
boost::container::flat_set<std::string> *out_set,
bool *ptruncated) {
OSDOp& op = add_op(CEPH_OSD_OP_OMAPGETKEYS);
ceph::buffer::list bl;
encode(start_after ? *start_after : std::string_view{}, bl);
encode(max_to_get, bl);
op.op.extent.offset = 0;
op.op.extent.length = bl.length();
op.indata.claim_append(bl);
set_handler(
CB_ObjectOperation_decodekeys(max_to_get, out_set, ptruncated, nullptr,
ec));
out_ec.back() = ec;
}
void omap_get_vals(const std::string &start_after,
const std::string &filter_prefix,
uint64_t max_to_get,
std::map<std::string, ceph::buffer::list> *out_set,
bool *ptruncated,
int *prval) {
using ceph::encode;
OSDOp &op = add_op(CEPH_OSD_OP_OMAPGETVALS);
ceph::buffer::list bl;