summaryrefslogtreecommitdiffstats
path: root/src/osdc/Objecter.h
blob: 163a3359de799f6b909c7e4ef1465cbc40ca062c (plain)
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
// -*- 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 <sage@newdream.net>
 *
 * 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.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/admin_socket.h"
#include "common/async/completion.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/Throttle.h"

#include "mon/MonClient.h"

#include "messages/MOSDOp.h"
#include "msg/Dispatcher.h"

#include "osd/OSDMap.h"

class Context;
class Messenger;
class MonClient;
class Message;

class MPoolOpReply;

class MGetPoolStatsReply;
class MStatfsReply;
class MCommandReply;
class MWatchNotify;
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, 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, 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, nullptr_t) {
    add_op(CEPH_OSD_OP_STAT);
    set_handler(CB_ObjectOperation_stat(psize, nullptr, nullptr, pts, nullptr,
					nullptr));
  }
  void stat(uint64_t *psize, nullptr_t, 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;
    std::size_t* s = nullptr;
    explicit CB_ObjectOperation_cmpext(int *prval)
      : prval(prval) {}
    CB_ObjectOperation_cmpext(boost::system::error_code* ec, std::size_t* s)
      : ec(ec), s(s) {}

    void operator()(boost::system::error_code ec, int r, const ceph::buffer::list&) {
      if (prval)
        *prval = r;
      if (this->ec)
	*this->ec = ec;
      if (s)
	*s = static_cast<std::size_t>(-(MAX_ERRNO - r));
    }
  };

  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,
	      std::size_t* s) {
    add_data(CEPH_OSD_OP_CMPEXT, off, cmp_bl.length(), cmp_bl);
    set_handler(CB_ObjectOperation_cmpext(ec, s));
    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) {
    ceph::buffer::list bl;
    add_data(CEPH_OSD_OP_SPARSE_READ, off, len, bl);
    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_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 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);
  }

  // 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(map<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;
    encode(start_after, bl);
    encode(max_to_get, bl);
    encode(filter_prefix, bl);
    op.op.extent.offset = 0;
    op.op.extent.length = bl.length();
    op.indata.claim_append(bl);
    if (prval || out_set || ptruncated) {
      set_handler(CB_ObjectOperation_decodevals(max_to_get, out_set, ptruncated,
						prval, nullptr));
      out_rval.back() = prval;
    }
  }

  void omap_get_vals(std::optional<std::string_view> start_after,
		     std::optional<std::string_view> filter_prefix,
		     uint64_t max_to_get,
		     boost::system::error_code* ec,
		     boost::container::flat_map<std::string, ceph::buffer::list> *out_set,
		     bool *ptruncated) {
    OSDOp &op = add_op(CEPH_OSD_OP_OMAPGETVALS);
    ceph::buffer::list bl;
    encode(start_after ? *start_after : std::string_view{}, bl);
    encode(max_to_get, bl);
    encode(filter_prefix ? *start_after : std::string_view{}, bl);
    op.op.extent.offset = 0;
    op.op.extent.length = bl.length();
    op.indata.claim_append(bl);
    set_handler(CB_ObjectOperation_decodevals(max_to_get, out_set, ptruncated,
					      nullptr, ec));
    out_ec.back() = ec;
  }

  void omap_get_vals_by_keys(const std::set<std::string> &to_get,
			     std::map<std::string, ceph::buffer::list> *out_set,
			     int *prval) {
    OSDOp &op = add_op(CEPH_OSD_OP_OMAPGETVALSBYKEYS);
    ceph::buffer::list bl;
    encode(to_get, bl);
    op.op.extent.offset = 0;
    op.op.extent.length = bl.length();
    op.indata.claim_append(bl);
    if (prval || out_set) {
      set_handler(CB_ObjectOperation_decodevals(0, out_set, nullptr, prval,
						nullptr));
      out_rval.back() = prval;
    }
  }

  void omap_get_vals_by_keys(
    const boost::container::flat_set<std::string>& to_get,
    boost::system::error_code* ec,
    boost::container::flat_map<std::string, ceph::buffer::list> *out_set) {
    OSDOp &op = add_op(CEPH_OSD_OP_OMAPGETVALSBYKEYS);
    ceph::buffer::list bl;
    encode(to_get, bl);
    op.op.extent.offset = 0;
    op.op.extent.length = bl.length();
    op.indata.claim_append(bl);
    set_handler(CB_ObjectOperation_decodevals(0, out_set, nullptr, nullptr,
					      ec));
    out_ec.back() = ec;
  }

  void omap_cmp(const std::map<std::string, pair<ceph::buffer::list,int> > &assertions,
		int *prval) {
    using ceph::encode;
    OSDOp &op = add_op(CEPH_OSD_OP_OMAP_CMP);
    ceph::buffer::list bl;
    encode(assertions, bl);
    op.op.extent.offset = 0;
    op.op.extent.length = bl.length();
    op.indata.claim_append(bl);
    if (prval) {
      unsigned p = ops.size() - 1;
      out_rval[p] = prval;
    }
  }

  void omap_cmp(const boost::container::flat_map<
		  std::string, pair<ceph::buffer::list, int>>& assertions,
		boost::system::error_code *ec) {
    OSDOp &op = add_op(CEPH_OSD_OP_OMAP_CMP);
    ceph::buffer::list bl;
    encode(assertions, bl);
    op.op.extent.offset = 0;
    op.op.extent.length = bl.length();
    op.indata.claim_append(bl);
    out_ec.back() = ec;
  }

  struct C_ObjectOperation_copyget : public Context {
    ceph::buffer::list bl;
    object_copy_cursor_t *cursor;
    uint64_t *out_size;
    ceph::real_time *out_mtime;
    std::map<std::string,ceph::buffer::list> *out_attrs;
    ceph::buffer::list *out_data, *out_omap_header, *out_omap_data;
    std::vector<snapid_t> *out_snaps;
    snapid_t *out_snap_seq;
    uint32_t *out_flags;
    uint32_t *out_data_digest;
    uint32_t *out_omap_digest;
    mempool::osd_pglog::vector<std::pair<osd_reqid_t, version_t> > *out_reqids;
    mempool::osd_pglog::map<uint32_t, int> *out_reqid_return_codes;
    uint64_t *out_truncate_seq;
    uint64_t *out_truncate_size;
    int *prval;
    C_ObjectOperation_copyget(object_copy_cursor_t *c,
			      uint64_t *s,
			      ceph::real_time *m,
			      std::map<std::string,ceph::buffer::list> *a,
			      ceph::buffer::list *d, ceph::buffer::list *oh,
			      ceph::buffer::list *o,
			      std::vector<snapid_t> *osnaps,
			      snapid_t *osnap_seq,
			      uint32_t *flags,
			      uint32_t *dd,
			      uint32_t *od,
			      mempool::osd_pglog::vector<std::pair<osd_reqid_t, version_t> > *oreqids,
			      mempool::osd_pglog::map<uint32_t, int> *oreqid_return_codes,
			      uint64_t *otseq,
			      uint64_t *otsize,
			      int *r)
      : cursor(c),
	out_size(s), out_mtime(m),
	out_attrs(a), out_data(d), out_omap_header(oh),
	out_omap_data(o), out_snaps(osnaps), out_snap_seq(osnap_seq),
	out_flags(flags), out_data_digest(dd), out_omap_digest(od),
	out_reqids(oreqids),
	out_reqid_return_codes(oreqid_return_codes),
	out_truncate_seq(otseq),
	out_truncate_size(otsize),
	prval(r) {}
    void finish(int r) override {
      using ceph::decode;
      // reqids are copied on ENOENT
      if (r < 0 && r != -ENOENT)
	return;
      try {
	auto p = bl.cbegin();
	object_copy_data_t copy_reply;
	decode(copy_reply, p);
	if (r == -ENOENT) {
	  if (out_reqids)
	    *out_reqids = copy_reply.reqids;
	  return;
	}
	if (out_size)
	  *out_size = copy_reply.size;
	if (out_mtime)
	  *out_mtime = ceph::real_clock::from_ceph_timespec(copy_reply.mtime);
	if (out_attrs)
	  *out_attrs = copy_reply.attrs;
	if (out_data)
	  out_data->claim_append(copy_reply.data);
	if (out_omap_header)
	  out_omap_header->claim_append(copy_reply.omap_header);
	if (out_omap_data)
	  *out_omap_data = copy_reply.omap_data;
	if (out_snaps)
	  *out_snaps = copy_reply.snaps;
	if (out_snap_seq)
	  *out_snap_seq = copy_reply.snap_seq;
	if (out_flags)
	  *out_flags = copy_reply.flags;
	if (out_data_digest)
	  *out_data_digest = copy_reply.data_digest;
	if (out_omap_digest)
	  *out_omap_digest = copy_reply.omap_digest;
	if (out_reqids)
	  *out_reqids = copy_reply.reqids;
	if (out_reqid_return_codes)
	  *out_reqid_return_codes = copy_reply.reqid_return_codes;
	if (out_truncate_seq)
	  *out_truncate_seq = copy_reply.truncate_seq;
	if (out_truncate_size)
	  *out_truncate_size = copy_reply.truncate_size;
	*cursor = copy_reply.cursor;
      } catch (const ceph::buffer::error& e) {
	if (prval)
	  *prval = -EIO;
      }
    }
  };

  void copy_get(object_copy_cursor_t *cursor,
		uint64_t max,
		uint64_t *out_size,
		ceph::real_time *out_mtime,
		std::map<std::string,ceph::buffer::list> *out_attrs,
		ceph::buffer::list *out_data,
		ceph::buffer::list *out_omap_header,
		ceph::buffer::list *out_omap_data,
		std::vector<snapid_t> *out_snaps,
		snapid_t *out_snap_seq,
		uint32_t *out_flags,
		uint32_t *out_data_digest,
		uint32_t *out_omap_digest,
		mempool::osd_pglog::vector<std::pair<osd_reqid_t, version_t> > *out_reqids,
		mempool::osd_pglog::map<uint32_t, int> *out_reqid_return_codes,
		uint64_t *truncate_seq,
		uint64_t *truncate_size,
		int *prval) {
    using ceph::encode;
    OSDOp& osd_op = add_op(CEPH_OSD_OP_COPY_GET);
    osd_op.op.copy_get.max = max;
    encode(*cursor, osd_op.indata);
    encode(max, osd_op.indata);
    unsigned p = ops.size() - 1;
    out_rval[p] = prval;
    C_ObjectOperation_copyget *h =
      new C_ObjectOperation_copyget(cursor, out_size, out_mtime,
				    out_attrs, out_data, out_omap_header,
				    out_omap_data, out_snaps, out_snap_seq,
				    out_flags, out_data_digest,
				    out_omap_digest, out_reqids,
				    out_reqid_return_codes, truncate_seq,
				    truncate_size, prval);
    out_bl[p] = &h->bl;
    set_handler(h);
  }

  void undirty() {
    add_op(CEPH_OSD_OP_UNDIRTY);
  }

  struct C_ObjectOperation_isdirty : public Context {
    ceph::buffer::list bl;
    bool *pisdirty;
    int *prval;
    C_ObjectOperation_isdirty(bool *p, int *r)
      : pisdirty(p), prval(r) {}
    void finish(int r) override {
      using ceph::decode;
      if (r < 0)
	return;
      try {
	auto p = bl.cbegin();
	bool isdirty;
	decode(isdirty, p);
	if (pisdirty)
	  *pisdirty = isdirty;
      } catch (const ceph::buffer::error& e) {
	if (prval)
	  *prval = -EIO;
      }
    }
  };

  void is_dirty(bool *pisdirty, int *prval) {
    add_op(CEPH_OSD_OP_ISDIRTY);
    unsigned p = ops.size() - 1;
    out_rval[p] = prval;
    C_ObjectOperation_isdirty *h =
      new C_ObjectOperation_isdirty(pisdirty, prval);
    out_bl[p] = &h->bl;
    set_handler(h);
  }

  struct C_ObjectOperation_hit_set_ls : public Context {
    ceph::buffer::list bl;
    std::list< std::pair<time_t, time_t> > *ptls;
    std::list< std::pair<ceph::real_time, ceph::real_time> > *putls;
    int *prval;
    C_ObjectOperation_hit_set_ls(std::list< std::pair<time_t, time_t> > *t,
				 std::list< std::pair<ceph::real_time,
						      ceph::real_time> > *ut,
				 int *r)
      : ptls(t), putls(ut), prval(r) {}
    void finish(int r) override {
      using ceph::decode;
      if (r < 0)
	return;
      try {
	auto p = bl.cbegin();
	std::list< std::pair<ceph::real_time, ceph::real_time> > ls;
	decode(ls, p);
	if (ptls) {
	  ptls->clear();
	  for (auto p = ls.begin(); p != ls.end(); ++p)
	    // round initial timestamp up to the next full second to
	    // keep this a valid interval.
	    ptls->push_back(
	      std::make_pair(ceph::real_clock::to_time_t(
			  ceph::ceil(p->first,
				     // Sadly, no time literals until C++14.
				     std::chrono::seconds(1))),
			ceph::real_clock::to_time_t(p->second)));
	}
	if (putls)
	  putls->swap(ls);
      } catch (const ceph::buffer::error& e) {
	r = -EIO;
      }
      if (prval)
	*prval = r;
    }
  };

  /**
   * std::list available HitSets.
   *
   * We will get back a std::list of time intervals.  Note that the most
   * recent range may have an empty end timestamp if it is still
   * accumulating.
   *
   * @param pls [out] std::list of time intervals
   * @param prval [out] return value
   */
  void hit_set_ls(std::list< std::pair<time_t, time_t> > *pls, int *prval) {
    add_op(CEPH_OSD_OP_PG_HITSET_LS);
    unsigned p = ops.size() - 1;
    out_rval[p] = prval;
    C_ObjectOperation_hit_set_ls *h =
      new C_ObjectOperation_hit_set_ls(pls, NULL, prval);
    out_bl[p] = &h->bl;
    set_handler(h);
  }
  void hit_set_ls(std::list<std::pair<ceph::real_time, ceph::real_time> > *pls,
		  int *prval) {
    add_op(CEPH_OSD_OP_PG_HITSET_LS);
    unsigned p = ops.size() - 1;
    out_rval[p] = prval;
    C_ObjectOperation_hit_set_ls *h =
      new C_ObjectOperation_hit_set_ls(NULL, pls, prval);
    out_bl[p] = &h->bl;
    set_handler(h);
  }

  /**
   * get HitSet
   *
   * Return an encoded HitSet that includes the provided time
   * interval.
   *
   * @param stamp [in] timestamp
   * @param pbl [out] target buffer for encoded HitSet
   * @param prval [out] return value
   */
  void hit_set_get(ceph::real_time stamp, ceph::buffer::list *pbl, int *prval) {
    OSDOp& op = add_op(CEPH_OSD_OP_PG_HITSET_GET);
    op.op.hit_set_get.stamp = ceph::real_clock::to_ceph_timespec(stamp);
    unsigned p = ops.size() - 1;
    out_rval[p] = prval;
    out_bl[p] = pbl;
  }

  void omap_get_header(ceph::buffer::list *bl, int *prval) {
    add_op(CEPH_OSD_OP_OMAPGETHEADER);
    unsigned p = ops.size() - 1;
    out_bl[p] = bl;
    out_rval[p] = prval;
  }

  void omap_get_header(boost::system::error_code* ec, ceph::buffer::list *bl) {
    add_op(CEPH_OSD_OP_OMAPGETHEADER);
    out_bl.back() = bl;
    out_ec.back() = ec;
  }

  void omap_set(const map<string, ceph::buffer::list> &map) {
    ceph::buffer::list bl;
    encode(map, bl);
    add_data(CEPH_OSD_OP_OMAPSETVALS, 0, bl.length(), bl);
  }

  void omap_set(const boost::container::flat_map<string, ceph::buffer::list>& map) {
    ceph::buffer::list bl;
    encode(map, bl);
    add_data(CEPH_OSD_OP_OMAPSETVALS, 0, bl.length(), bl);
  }

  void omap_set_header(ceph::buffer::list &bl) {
    add_data(CEPH_OSD_OP_OMAPSETHEADER, 0, bl.length(), bl);
  }

  void omap_clear() {
    add_op(CEPH_OSD_OP_OMAPCLEAR);
  }

  void omap_rm_keys(const std::set<std::string> &to_remove) {
    using ceph::encode;
    ceph::buffer::list bl;
    encode(to_remove, bl);
    add_data(CEPH_OSD_OP_OMAPRMKEYS, 0, bl.length(), bl);
  }
  void omap_rm_keys(const boost::container::flat_set<std::string>& to_remove) {
    ceph::buffer::list bl;
    encode(to_remove, bl);
    add_data(CEPH_OSD_OP_OMAPRMKEYS, 0, bl.length(), bl);
  }

  void omap_rm_range(std::string_view key_begin, std::string_view key_end) {
    ceph::buffer::list bl;
    using ceph::encode;
    encode(key_begin, bl);
    encode(key_end, bl);
    add_data(CEPH_OSD_OP_OMAPRMKEYRANGE, 0, bl.length(), bl);
  }

  // object classes
  void call(const char *cname, const char *method, ceph::buffer::list &indata) {
    add_call(CEPH_OSD_OP_CALL, cname, method, indata, NULL, NULL, NULL);
  }

  void call(const char *cname, const char *method, ceph::buffer::list &indata,
	    ceph::buffer::list *outdata, Context *ctx, int *prval) {
    add_call(CEPH_OSD_OP_CALL, cname, method, indata, outdata, ctx, prval);
  }

  void call(std::string_view cname, std::string_view method,
	    const ceph::buffer::list& indata, boost::system::error_code* ec) {
    add_call(CEPH_OSD_OP_CALL, cname, method, indata, NULL, NULL, NULL);
    out_ec.back() = ec;
  }

  void call(std::string_view cname, std::string_view method, const ceph::buffer::list& indata,
	    boost::system::error_code* ec, ceph::buffer::list *outdata) {
    add_call(CEPH_OSD_OP_CALL, cname, method, indata, outdata, nullptr, nullptr);
    out_ec.back() = ec;
  }
  void call(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) {
    add_call(CEPH_OSD_OP_CALL, cname, method, indata, std::move(f));
  }
  void call(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) {
    add_call(CEPH_OSD_OP_CALL, cname, method, indata, std::move(f));
  }

  // watch/notify
  void watch(uint64_t cookie, __u8 op, uint32_t timeout = 0) {
    OSDOp& osd_op = add_op(CEPH_OSD_OP_WATCH);
    osd_op.op.watch.cookie = cookie;
    osd_op.op.watch.op = op;
    osd_op.op.watch.timeout = timeout;
  }

  void notify(uint64_t cookie, uint32_t prot_ver, uint32_t timeout,
              ceph::buffer::list &bl, ceph::buffer::list *inbl) {
    using ceph::encode;
    OSDOp& osd_op = add_op(CEPH_OSD_OP_NOTIFY);
    osd_op.op.notify.cookie = cookie;
    encode(prot_ver, *inbl);
    encode(timeout, *inbl);
    encode(bl, *inbl);
    osd_op.indata.append(*inbl);
  }

  void notify_ack(uint64_t notify_id, uint64_t cookie,
		  ceph::buffer::list& reply_bl) {
    using ceph::encode;
    OSDOp& osd_op = add_op(CEPH_OSD_OP_NOTIFY_ACK);
    ceph::buffer::list bl;
    encode(notify_id, bl);
    encode(cookie, bl);
    encode(reply_bl, bl);
    osd_op.indata.append(bl);
  }

  void list_watchers(std::list<obj_watch_t> *out,
		     int *prval) {
    add_op(CEPH_OSD_OP_LIST_WATCHERS);
    if (prval || out) {
      set_handler(CB_ObjectOperation_decodewatchers(out, prval, nullptr));
      out_rval.back() = prval;
    }
  }
  void list_watchers(vector<neorados::ObjWatcher>* out,
		     boost::system::error_code* ec) {
    add_op(CEPH_OSD_OP_LIST_WATCHERS);
    set_handler(CB_ObjectOperation_decodewatchersneo(out, nullptr, ec));
    out_ec.back() = ec;
  }

  void list_snaps(librados::snap_set_t *out, int *prval,
		  boost::system::error_code* ec = nullptr) {
    add_op(CEPH_OSD_OP_LIST_SNAPS);
    if (prval || out || ec) {
      set_handler(CB_ObjectOperation_decodesnaps(out, nullptr, prval, ec));
      out_rval.back() = prval;
      out_ec.back() = ec;
    }
  }

  void list_snaps(neorados::SnapSet *out, int *prval,
		  boost::system::error_code* ec = nullptr) {
    add_op(CEPH_OSD_OP_LIST_SNAPS);
    if (prval || out || ec) {
      set_handler(CB_ObjectOperation_decodesnaps(nullptr, out, prval, ec));
      out_rval.back() = prval;
      out_ec.back() = ec;
    }
  }

  void assert_version(uint64_t ver) {
    OSDOp& osd_op = add_op(CEPH_OSD_OP_ASSERT_VER);
    osd_op.op.assert_ver.ver = ver;
  }

  void cmpxattr(const char *name, const ceph::buffer::list& val,
		int op, int mode) {
    add_xattr(CEPH_OSD_OP_CMPXATTR, name, val);
    OSDOp& o = *ops.rbegin();
    o.op.xattr.cmp_op = op;
    o.op.xattr.cmp_mode = mode;
  }

  void rollback(uint64_t snapid) {
    OSDOp& osd_op = add_op(CEPH_OSD_OP_ROLLBACK);
    osd_op.op.snap.snapid = snapid;
  }

  void copy_from(object_t src, snapid_t snapid, object_locator_t src_oloc,
		 version_t src_version, unsigned flags,
		 unsigned src_fadvise_flags) {
    using ceph::encode;
    OSDOp& osd_op = add_op(CEPH_OSD_OP_COPY_FROM);
    osd_op.op.copy_from.snapid = snapid;
    osd_op.op.copy_from.src_version = src_version;
    osd_op.op.copy_from.flags = flags;
    osd_op.op.copy_from.src_fadvise_flags = src_fadvise_flags;
    encode(src, osd_op.indata);
    encode(src_oloc, osd_op.indata);
  }
  void copy_from2(object_t src, snapid_t snapid, object_locator_t src_oloc,
		 version_t src_version, unsigned flags,
		 uint32_t truncate_seq, uint64_t truncate_size,
		 unsigned src_fadvise_flags) {
    using ceph::encode;
    OSDOp& osd_op = add_op(CEPH_OSD_OP_COPY_FROM2);
    osd_op.op.copy_from.snapid = snapid;
    osd_op.op.copy_from.src_version = src_version;
    osd_op.op.copy_from.flags = flags;
    osd_op.op.copy_from.src_fadvise_flags = src_fadvise_flags;
    encode(src, osd_op.indata);
    encode(src_oloc, osd_op.indata);
    encode(truncate_seq, osd_op.indata);
    encode(truncate_size, osd_op.indata);
  }

  /**
   * writeback content to backing tier
   *
   * If object is marked dirty in the cache tier, write back content
   * to backing tier. If the object is clean this is a no-op.
   *
   * If writeback races with an update, the update will block.
   *
   * use with IGNORE_CACHE to avoid triggering promote.
   */
  void cache_flush() {
    add_op(CEPH_OSD_OP_CACHE_FLUSH);
  }

  /**
   * writeback content to backing tier
   *
   * If object is marked dirty in the cache tier, write back content
   * to backing tier. If the object is clean this is a no-op.
   *
   * If writeback races with an update, return EAGAIN.  Requires that
   * the SKIPRWLOCKS flag be set.
   *
   * use with IGNORE_CACHE to avoid triggering promote.
   */
  void cache_try_flush() {
    add_op(CEPH_OSD_OP_CACHE_TRY_FLUSH);
  }

  /**
   * evict object from cache tier
   *
   * If object is marked clean, remove the object from the cache tier.
   * Otherwise, return EBUSY.
   *
   * use with IGNORE_CACHE to avoid triggering promote.
   */
  void cache_evict() {
    add_op(CEPH_OSD_OP_CACHE_EVICT);
  }

  /*
   * Extensible tier
   */
  void set_redirect(object_t tgt, snapid_t snapid, object_locator_t tgt_oloc, 
		    version_t tgt_version, int flag) {
    using ceph::encode;
    OSDOp& osd_op = add_op(CEPH_OSD_OP_SET_REDIRECT);
    osd_op.op.copy_from.snapid = snapid;
    osd_op.op.copy_from.src_version = tgt_version;
    encode(tgt, osd_op.indata);
    encode(tgt_oloc, osd_op.indata);
    set_last_op_flags(flag);
  }

  void set_chunk(uint64_t src_offset, uint64_t src_length, object_locator_t tgt_oloc,
		 object_t tgt_oid, uint64_t tgt_offset, int flag) {
    using ceph::encode;
    OSDOp& osd_op = add_op(CEPH_OSD_OP_SET_CHUNK);
    encode(src_offset, osd_op.indata);
    encode(src_length, osd_op.indata);
    encode(tgt_oloc, osd_op.indata);
    encode(tgt_oid, osd_op.indata);
    encode(tgt_offset, osd_op.indata);
    set_last_op_flags(flag);
  }

  void tier_promote() {
    add_op(CEPH_OSD_OP_TIER_PROMOTE);
  }

  void unset_manifest() {
    add_op(CEPH_OSD_OP_UNSET_MANIFEST);
  }

  void tier_flush() {
    add_op(CEPH_OSD_OP_TIER_FLUSH);
  }

  void tier_evict() {
    add_op(CEPH_OSD_OP_TIER_EVICT);
  }

  void set_alloc_hint(uint64_t expected_object_size,
                      uint64_t expected_write_size,
		      uint32_t flags) {
    add_alloc_hint(CEPH_OSD_OP_SETALLOCHINT, expected_object_size,
		   expected_write_size, flags);

    // CEPH_OSD_OP_SETALLOCHINT op is advisory and therefore deemed
    // not worth a feature bit.  Set FAILOK per-op flag to make
    // sure older osds don't trip over an unsupported opcode.
    set_last_op_flags(CEPH_OSD_OP_FLAG_FAILOK);
  }

  template<typename V>
  void dup(V& sops) {
    ops.clear();
    std::copy(sops.begin(), sops.end(),
	      std::back_inserter(ops));
    out_bl.resize(sops.size());
    out_handler.resize(sops.size());
    out_rval.resize(sops.size());
    out_ec.resize(sops.size());
    for (uint32_t i = 0; i < sops.size(); i++) {
      out_bl[i] = &sops[i].outdata;
      out_rval[i] = &sops[i].rval;
      out_ec[i] = nullptr;
    }
  }

  /**
   * Pin/unpin an object in cache tier
   */
  void cache_pin() {
    add_op(CEPH_OSD_OP_CACHE_PIN);
  }

  void cache_unpin() {
    add_op(CEPH_OSD_OP_CACHE_UNPIN);
  }
};

inline std::ostream& operator <<(std::ostream& m, const ObjectOperation& oo) {
  auto i = oo.ops.cbegin();
  m << '[';
  while (i != oo.ops.cend()) {
    if (i != oo.ops.cbegin())
      m << ' ';
    m << *i;
    ++i;
  }
  m << ']';
  return m;
}


// ----------------

class Objecter : public md_config_obs_t, public Dispatcher {
  using MOSDOp = _mosdop::MOSDOp<osdc_opvec>;
public:
  using OpSignature = void(boost::system::error_code);
  using OpCompletion = ceph::async::Completion<OpSignature>;

  // config observer bits
  const char** get_tracked_conf_keys() const override;
  void handle_conf_change(const ConfigProxy& conf,
                          const std::set <std::string> &changed) override;

public:
  Messenger *messenger;
  MonClient *monc;
  boost::asio::io_context& service;
  // The guaranteed sequenced, one-at-a-time execution and apparently
  // people sometimes depend on this.
  boost::asio::io_context::strand finish_strand{service};
  ZTracer::Endpoint trace_endpoint{"0.0.0.0", 0, "Objecter"};
private:
  std::unique_ptr<OSDMap> osdmap{std::make_unique<OSDMap>()};
public:
  using Dispatcher::cct;
  std::multimap<std::string,std::string> crush_location;

  std::atomic<bool> initialized{false};

private:
  std::atomic<uint64_t> last_tid{0};
  std::atomic<unsigned> inflight_ops{0};
  std::atomic<int> client_inc{-1};
  uint64_t max_linger_id{0};
  std::atomic<unsigned> num_in_flight{0};
  std::atomic<int> global_op_flags{0}; // flags which are applied to each IO op
  bool keep_balanced_budget = false;
  bool honor_pool_full = true;

  // If this is true, accumulate a set of blocklisted entities
  // to be drained by consume_blocklist_events.
  bool blocklist_events_enabled = false;
  std::set<entity_addr_t> blocklist_events;
  struct pg_mapping_t {
    epoch_t epoch = 0;
    std::vector<int> up;
    int up_primary = -1;
    std::vector<int> acting;
    int acting_primary = -1;

    pg_mapping_t() {}
    pg_mapping_t(epoch_t epoch, std::vector<int> up, int up_primary,
                 std::vector<int> acting, int acting_primary)
               : epoch(epoch), up(up), up_primary(up_primary),
                 acting(acting), acting_primary(acting_primary) {}
  };
  ceph::shared_mutex pg_mapping_lock =
    ceph::make_shared_mutex("Objecter::pg_mapping_lock");
  // pool -> pg mapping
  std::map<int64_t, std::vector<pg_mapping_t>> pg_mappings;

  // convenient accessors
  bool lookup_pg_mapping(const pg_t& pg, pg_mapping_t* pg_mapping) {
    std::shared_lock l{pg_mapping_lock};
    auto it = pg_mappings.find(pg.pool());
    if (it == pg_mappings.end())
      return false;
    auto& mapping_array = it->second;
    if (pg.ps() >= mapping_array.size())
      return false;
    if (mapping_array[pg.ps()].epoch != pg_mapping->epoch) // stale
      return false;
    *pg_mapping = mapping_array[pg.ps()];
    return true;
  }
  void update_pg_mapping(const pg_t& pg, pg_mapping_t&& pg_mapping) {
    std::lock_guard l{pg_mapping_lock};
    auto& mapping_array = pg_mappings[pg.pool()];
    ceph_assert(pg.ps() < mapping_array.size());
    mapping_array[pg.ps()] = std::move(pg_mapping);
  }
  void prune_pg_mapping(const mempool::osdmap::map<int64_t,pg_pool_t>& pools) {
    std::lock_guard l{pg_mapping_lock};
    for (auto& pool : pools) {
      auto& mapping_array = pg_mappings[pool.first];
      size_t pg_num = pool.second.get_pg_num();
      if (mapping_array.size() != pg_num) {
        // catch both pg_num increasing & decreasing
        mapping_array.resize(pg_num);
      }
    }
    for (auto it = pg_mappings.begin(); it != pg_mappings.end(); ) {
      if (!pools.count(it->first)) {
        // pool is gone
        pg_mappings.erase(it++);
        continue;
      }
      it++;
    }
  }

public:
  void maybe_request_map();

  void enable_blocklist_events();
private:

  void _maybe_request_map();

  version_t last_seen_osdmap_version = 0;
  version_t last_seen_pgmap_version = 0;

  mutable ceph::shared_mutex rwlock =
	   ceph::make_shared_mutex("Objecter::rwlock");
  ceph::timer<ceph::coarse_mono_clock> timer;

  PerfCounters* logger = nullptr;

  uint64_t tick_event = 0;

  void start_tick();
  void tick();
  void update_crush_location();

  class RequestStateHook;

  RequestStateHook *m_request_state_hook = nullptr;

public:
  /*** track pending operations ***/
  // read

  struct OSDSession;

  struct op_target_t {
    int flags = 0;

    epoch_t epoch = 0;  ///< latest epoch we calculated the mapping

    object_t base_oid;
    object_locator_t base_oloc;
    object_t target_oid;
    object_locator_t target_oloc;

    ///< true if we are directed at base_pgid, not base_oid
    bool precalc_pgid = false;

    ///< true if we have ever mapped to a valid pool
    bool pool_ever_existed = false;

    ///< explcit pg target, if any
    pg_t base_pgid;

    pg_t pgid; ///< last (raw) pg we mapped to
    spg_t actual_pgid; ///< last (actual) spg_t we mapped to
    unsigned pg_num = 0; ///< last pg_num we mapped to
    unsigned pg_num_mask = 0; ///< last pg_num_mask we mapped to
    unsigned pg_num_pending = 0; ///< last pg_num we mapped to
    std::vector<int> up; ///< set of up osds for last pg we mapped to
    std::vector<int> acting; ///< set of acting osds for last pg we mapped to
    int up_primary = -1; ///< last up_primary we mapped to
    int acting_primary = -1;  ///< last acting_primary we mapped to
    int size = -1; ///< the size of the pool when were were last mapped
    int min_size = -1; ///< the min size of the pool when were were last mapped
    bool sort_bitwise = false; ///< whether the hobject_t sort order is bitwise
    bool recovery_deletes = false; ///< whether the deletes are performed during recovery instead of peering
    uint32_t peering_crush_bucket_count = 0;
    uint32_t peering_crush_bucket_target = 0;
    uint32_t peering_crush_bucket_barrier = 0;
    int32_t peering_crush_mandatory_member = CRUSH_ITEM_NONE;

    bool used_replica = false;
    bool paused = false;

    int osd = -1;      ///< the final target osd, or -1

    epoch_t last_force_resend = 0;

    op_target_t(object_t oid, object_locator_t oloc, int flags)
      : flags(flags),
	base_oid(oid),
	base_oloc(oloc)
      {}

    explicit op_target_t(pg_t pgid)
      : base_oloc(pgid.pool(), pgid.ps()),
	precalc_pgid(true),
	base_pgid(pgid)
      {}

    op_target_t() = default;

    hobject_t get_hobj() {
      return hobject_t(target_oid,
		       target_oloc.key,
		       CEPH_NOSNAP,
		       target_oloc.hash >= 0 ? target_oloc.hash : pgid.ps(),
		       target_oloc.pool,
		       target_oloc.nspace);
    }

    bool contained_by(const hobject_t& begin, const hobject_t& end) {
      hobject_t h = get_hobj();
      int r = cmp(h, begin);
      return r == 0 || (r > 0 && h < end);
    }

    bool respects_full() const {
      return
	(flags & (CEPH_OSD_FLAG_WRITE | CEPH_OSD_FLAG_RWORDERED)) &&
	!(flags & (CEPH_OSD_FLAG_FULL_TRY | CEPH_OSD_FLAG_FULL_FORCE));
    }

    void dump(ceph::Formatter *f) const;
  };

  std::unique_ptr<ceph::async::Completion<void(boost::system::error_code)>>
  OpContextVert(Context* c) {
    if (c)
      return ceph::async::Completion<void(boost::system::error_code)>::create(
	service.get_executor(),
	[c = std::unique_ptr<Context>(c)]
	(boost::system::error_code e) mutable {
	  c.release()->complete(e);
	});
    else
      return nullptr;
  }

  template<typename T>
  std::unique_ptr<ceph::async::Completion<void(boost::system::error_code, T)>>
  OpContextVert(Context* c, T* p) {

    if (c || p)
      return
	ceph::async::Completion<void(boost::system::error_code, T)>::create(
	  service.get_executor(),
	  [c = std::unique_ptr<Context>(c), p]
	  (boost::system::error_code e, T r) mutable {
	      if (p)
		*p = std::move(r);
	      if (c)
		c.release()->complete(ceph::from_error_code(e));
	    });
    else
      return nullptr;
  }

  template<typename T>
  std::unique_ptr<ceph::async::Completion<void(boost::system::error_code, T)>>
  OpContextVert(Context* c, T& p) {
    if (c)
      return ceph::async::Completion<
	void(boost::system::error_code, T)>::create(
	  service.get_executor(),
	  [c = std::unique_ptr<Context>(c), &p]
	  (boost::system::error_code e, T r) mutable {
	    p = std::move(r);
	    if (c)
	      c.release()->complete(ceph::from_error_code(e));
	  });
    else
      return nullptr;
  }

  struct Op : public RefCountedObject {
    OSDSession *session = nullptr;
    int incarnation = 0;

    op_target_t target;

    ConnectionRef con = nullptr;  // for rx buffer only
    uint64_t features = CEPH_FEATURES_SUPPORTED_DEFAULT; // explicitly specified op features

    osdc_opvec ops;

    snapid_t snapid = CEPH_NOSNAP;
    SnapContext snapc;
    ceph::real_time mtime;

    ceph::buffer::list *outbl = nullptr;
    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;

    int priority = 0;
    using OpSig = void(boost::system::error_code);
    using OpComp = ceph::async::Completion<OpSig>;
    // Due to an irregularity of cmpxattr, we actualy need the 'int'
    // value for onfinish for legacy librados users. As such just
    // preserve the Context* in this one case. That way we can have
    // our callers just pass in a unique_ptr<OpComp> and not deal with
    // our signature in Objecter being different than the exposed
    // signature in RADOS.
    //
    // Add a function for the linger case, where we want better
    // semantics than Context, but still need to be under the completion_lock.
    std::variant<std::unique_ptr<OpComp>, fu2::unique_function<OpSig>,
		 Context*> onfinish;
    uint64_t ontimeout = 0;

    ceph_tid_t tid = 0;
    int attempts = 0;

    version_t *objver;
    epoch_t *reply_epoch = nullptr;

    ceph::coarse_mono_time stamp;

    epoch_t map_dne_bound = 0;

    int budget = -1;

    /// true if we should resend this message on failure
    bool should_resend = true;

    /// true if the throttle budget is get/put on a series of OPs,
    /// instead of per OP basis, when this flag is set, the budget is
    /// acquired before sending the very first OP of the series and
    /// released upon receiving the last OP reply.
    bool ctx_budgeted = false;

    int *data_offset;

    osd_reqid_t reqid; // explicitly setting reqid
    ZTracer::Trace trace;

    static bool has_completion(decltype(onfinish)& f) {
      return std::visit([](auto&& arg) { return bool(arg);}, f);
    }
    bool has_completion() {
      return has_completion(onfinish);
    }

    static void complete(decltype(onfinish)&& f, boost::system::error_code ec,
			 int r) {
      std::visit([ec, r](auto&& arg) {
		   if constexpr (std::is_same_v<std::decay_t<decltype(arg)>,
				 Context*>) {
		     arg->complete(r);
		   } else if constexpr (std::is_same_v<std::decay_t<decltype(arg)>,
			      fu2::unique_function<OpSig>>) {
		     std::move(arg)(ec);
                   } else {
		     arg->defer(std::move(arg), ec);
		   }
		 }, std::move(f));
    }
    void complete(boost::system::error_code ec, int r) {
      complete(std::move(onfinish), ec, r);
    }

    Op(const object_t& o, const object_locator_t& ol,  osdc_opvec&& _ops,
       int f, std::unique_ptr<OpComp>&& fin,
       version_t *ov, int *offset = nullptr,
       ZTracer::Trace *parent_trace = nullptr) :
      target(o, ol, f),
      ops(std::move(_ops)),
      out_bl(ops.size(), nullptr),
      out_handler(ops.size()),
      out_rval(ops.size(), nullptr),
      out_ec(ops.size(), nullptr),
      onfinish(std::move(fin)),
      objver(ov),
      data_offset(offset) {
      if (target.base_oloc.key == o)
	target.base_oloc.key.clear();
      if (parent_trace && parent_trace->valid()) {
        trace.init("op", nullptr, parent_trace);
        trace.event("start");
      }
    }

    Op(const object_t& o, const object_locator_t& ol, osdc_opvec&& _ops,
       int f, Context* fin, version_t *ov, int *offset = nullptr,
       ZTracer::Trace *parent_trace = nullptr) :
      target(o, ol, f),
      ops(std::move(_ops)),
      out_bl(ops.size(), nullptr),
      out_handler(ops.size()),
      out_rval(ops.size(), nullptr),
      out_ec(ops.size(), nullptr),
      onfinish(fin),
      objver(ov),
      data_offset(offset) {
      if (target.base_oloc.key == o)
	target.base_oloc.key.clear();
      if (parent_trace && parent_trace->valid()) {
        trace.init("op", nullptr, parent_trace);
        trace.event("start");
      }
    }

    Op(const object_t& o, const object_locator_t& ol, osdc_opvec&&  _ops,
       int f, fu2::unique_function<OpSig>&& fin, version_t *ov, int *offset = nullptr,
       ZTracer::Trace *parent_trace = nullptr) :
      target(o, ol, f),
      ops(std::move(_ops)),
      out_bl(ops.size(), nullptr),
      out_handler(ops.size()),
      out_rval(ops.size(), nullptr),
      out_ec(ops.size(), nullptr),
      onfinish(std::move(fin)),
      objver(ov),
      data_offset(offset) {
      if (target.base_oloc.key == o)
	target.base_oloc.key.clear();
      if (parent_trace && parent_trace->valid()) {
        trace.init("op", nullptr, parent_trace);
        trace.event("start");
      }
    }

    bool operator<(const Op& other) const {
      return tid < other.tid;
    }

  private:
    ~Op() override {
      trace.event("finish");
    }
  };

  struct CB_Op_Map_Latest {
    Objecter *objecter;
    ceph_tid_t tid;
    CB_Op_Map_Latest(Objecter *o, ceph_tid_t t) : objecter(o), tid(t) {}
    void operator()(boost::system::error_code err, version_t latest, version_t);
  };

  struct CB_Command_Map_Latest {
    Objecter *objecter;
    uint64_t tid;
    CB_Command_Map_Latest(Objecter *o, ceph_tid_t t) :  objecter(o), tid(t) {}
    void operator()(boost::system::error_code err, version_t latest, version_t);
  };

  struct C_Stat : public Context {
    ceph::buffer::list bl;
    uint64_t *psize;
    ceph::real_time *pmtime;
    Context *fin;
    C_Stat(uint64_t *ps, ceph::real_time *pm, Context *c) :
      psize(ps), pmtime(pm), fin(c) {}
    void finish(int r) override {
      using ceph::decode;
      if (r >= 0) {
	auto p = bl.cbegin();
	uint64_t s;
	ceph::real_time m;
	decode(s, p);
	decode(m, p);
	if (psize)
	  *psize = s;
	if (pmtime)
	  *pmtime = m;
      }
      fin->complete(r);
    }
  };

  struct C_GetAttrs : public Context {
    ceph::buffer::list bl;
    std::map<std::string,ceph::buffer::list>& attrset;
    Context *fin;
    C_GetAttrs(std::map<std::string, ceph::buffer::list>& set, Context *c) : attrset(set),
							   fin(c) {}
    void finish(int r) override {
      using ceph::decode;
      if (r >= 0) {
	auto p = bl.cbegin();
	decode(attrset, p);
      }
      fin->complete(r);
    }
  };


  // Pools and statistics
  struct NListContext {
    collection_list_handle_t pos;

    // these are for !sortbitwise compat only
    int current_pg = 0;
    int starting_pg_num = 0;
    bool sort_bitwise = false;

    bool at_end_of_pool = false; ///< publicly visible end flag

    int64_t pool_id = -1;
    int pool_snap_seq = 0;
    uint64_t max_entries = 0;
    std::string nspace;

    ceph::buffer::list bl;   // raw data read to here
    std::list<librados::ListObjectImpl> list;

    ceph::buffer::list filter;

    // The budget associated with this context, once it is set (>= 0),
    // the budget is not get/released on OP basis, instead the budget
    // is acquired before sending the first OP and released upon receiving
    // the last op reply.
    int ctx_budget = -1;

    bool at_end() const {
      return at_end_of_pool;
    }

    uint32_t get_pg_hash_position() const {
      return pos.get_hash();
    }
  };

  struct C_NList : public Context {
    NListContext *list_context;
    Context *final_finish;
    Objecter *objecter;
    epoch_t epoch;
    C_NList(NListContext *lc, Context * finish, Objecter *ob) :
      list_context(lc), final_finish(finish), objecter(ob), epoch(0) {}
    void finish(int r) override {
      if (r >= 0) {
	objecter->_nlist_reply(list_context, r, final_finish, epoch);
      } else {
	final_finish->complete(r);
      }
    }
  };

  struct PoolStatOp {
    ceph_tid_t tid;
    std::vector<std::string> pools;
    using OpSig = void(boost::system::error_code,
		       boost::container::flat_map<std::string, pool_stat_t>,
		       bool);
    using OpComp = ceph::async::Completion<OpSig>;
    std::unique_ptr<OpComp> onfinish;
    std::uint64_t ontimeout;
    ceph::coarse_mono_time last_submit;
  };

  struct StatfsOp {
    ceph_tid_t tid;
    boost::optional<int64_t> data_pool;
    using OpSig = void(boost::system::error_code,
		       const struct ceph_statfs);
    using OpComp = ceph::async::Completion<OpSig>;

    std::unique_ptr<OpComp> onfinish;
    uint64_t ontimeout;

    ceph::coarse_mono_time last_submit;
  };

  struct PoolOp {
    ceph_tid_t tid = 0;
    int64_t pool = 0;
    std::string name;
    using OpSig = void(boost::system::error_code, ceph::buffer::list);
    using OpComp = ceph::async::Completion<OpSig>;
    std::unique_ptr<OpComp> onfinish;
    uint64_t ontimeout = 0;
    int pool_op = 0;
    int16_t crush_rule = 0;
    snapid_t snapid = 0;
    ceph::coarse_mono_time last_submit;

    PoolOp() {}
  };

  // -- osd commands --
  struct CommandOp : public RefCountedObject {
    OSDSession *session = nullptr;
    ceph_tid_t tid = 0;
    std::vector<std::string> cmd;
    ceph::buffer::list inbl;

    // target_osd == -1 means target_pg is valid
    const int target_osd = -1;
    const pg_t target_pg;

    op_target_t target;

    epoch_t map_dne_bound = 0;
    int map_check_error = 0; // error to return if std::map check fails
    const char *map_check_error_str = nullptr;

    using OpSig = void(boost::system::error_code, std::string,
		       ceph::buffer::list);
    using OpComp = ceph::async::Completion<OpSig>;
    std::unique_ptr<OpComp> onfinish;

    uint64_t ontimeout = 0;
    ceph::coarse_mono_time last_submit;

    CommandOp(
      int target_osd,
      std::vector<string>&& cmd,
      ceph::buffer::list&& inbl,
      decltype(onfinish)&& onfinish)
      : cmd(std::move(cmd)),
	inbl(std::move(inbl)),
	target_osd(target_osd),
	onfinish(std::move(onfinish)) {}

    CommandOp(
      pg_t pgid,
      std::vector<string>&& cmd,
      ceph::buffer::list&& inbl,
      decltype(onfinish)&& onfinish)
      : cmd(std::move(cmd)),
	inbl(std::move(inbl)),
	target_pg(pgid),
	target(pgid),
	onfinish(std::move(onfinish)) {}
  };

  void submit_command(CommandOp *c, ceph_tid_t *ptid);
  int _calc_command_target(CommandOp *c,
			   ceph::shunique_lock<ceph::shared_mutex> &sul);
  void _assign_command_session(CommandOp *c,
			       ceph::shunique_lock<ceph::shared_mutex> &sul);
  void _send_command(CommandOp *c);
  int command_op_cancel(OSDSession *s, ceph_tid_t tid,
			boost::system::error_code ec);
  void _finish_command(CommandOp *c, boost::system::error_code ec,
		       std::string&& rs, ceph::buffer::list&& bl);
  void handle_command_reply(MCommandReply *m);

  // -- lingering ops --

  struct LingerOp : public RefCountedObject {
    Objecter *objecter;
    uint64_t linger_id{0};
    op_target_t target{object_t(), object_locator_t(), 0};
    snapid_t snap{CEPH_NOSNAP};
    SnapContext snapc;
    ceph::real_time mtime;

    osdc_opvec ops;
    ceph::buffer::list inbl;
    version_t *pobjver{nullptr};

    bool is_watch{false};
    ceph::coarse_mono_time watch_valid_thru; ///< send time for last acked ping
    boost::system::error_code last_error;  ///< error from last failed ping|reconnect, if any
    ceph::shared_mutex watch_lock;

    // queue of pending async operations, with the timestamp of
    // when they were queued.
    std::list<ceph::coarse_mono_time> watch_pending_async;

    uint32_t register_gen{0};
    bool registered{false};
    bool canceled{false};
    using OpSig = void(boost::system::error_code, ceph::buffer::list);
    using OpComp = ceph::async::Completion<OpSig>;
    std::unique_ptr<OpComp> on_reg_commit;
    std::unique_ptr<OpComp> on_notify_finish;
    uint64_t notify_id{0};

    fu2::unique_function<void(boost::system::error_code,
			      uint64_t notify_id,
			      uint64_t cookie,
			      uint64_t notifier_id,
			      ceph::buffer::list&& bl)> handle;
    OSDSession *session{nullptr};

    int ctx_budget{-1};
    ceph_tid_t register_tid{0};
    ceph_tid_t ping_tid{0};
    epoch_t map_dne_bound{0};

    void _queued_async() {
      // watch_lock ust be locked unique
      watch_pending_async.push_back(ceph::coarse_mono_clock::now());
    }
    void finished_async() {
      unique_lock l(watch_lock);
      ceph_assert(!watch_pending_async.empty());
      watch_pending_async.pop_front();
    }

    LingerOp(Objecter *o, uint64_t linger_id);
    const LingerOp& operator=(const LingerOp& r) = delete;
    LingerOp(const LingerOp& o) = delete;

    uint64_t get_cookie() {
      return reinterpret_cast<uint64_t>(this);
    }
  };

  struct CB_Linger_Commit {
    Objecter *objecter;
    boost::intrusive_ptr<LingerOp> info;
    ceph::buffer::list outbl;  // used for notify only
    CB_Linger_Commit(Objecter *o, LingerOp *l) : objecter(o), info(l) {}
    ~CB_Linger_Commit() = default;

    void operator()(boost::system::error_code ec) {
      objecter->_linger_commit(info.get(), ec, outbl);
    }
  };

  struct CB_Linger_Reconnect {
    Objecter *objecter;
    boost::intrusive_ptr<LingerOp> info;
    CB_Linger_Reconnect(Objecter *o, LingerOp *l) : objecter(o), info(l) {}
    ~CB_Linger_Reconnect() = default;

    void operator()(boost::system::error_code ec) {
      objecter->_linger_reconnect(info.get(), ec);
      info.reset();
    }
  };

  struct CB_Linger_Ping {
    Objecter *objecter;
    boost::intrusive_ptr<LingerOp> info;
    ceph::coarse_mono_time sent;
    uint32_t register_gen;
    CB_Linger_Ping(Objecter *o, LingerOp *l, ceph::coarse_mono_time s)
      : objecter(o), info(l), sent(s), register_gen(info->register_gen) {}
    void operator()(boost::system::error_code ec) {
      objecter->_linger_ping(info.get(), ec, sent, register_gen);
      info.reset();
    }
  };

  struct CB_Linger_Map_Latest {
    Objecter *objecter;
    uint64_t linger_id;
    CB_Linger_Map_Latest(Objecter *o, uint64_t id) : objecter(o), linger_id(id) {}
    void operator()(boost::system::error_code err, version_t latest, version_t);
  };

  // -- osd sessions --
  struct OSDBackoff {
    spg_t pgid;
    uint64_t id;
    hobject_t begin, end;
  };

  struct OSDSession : public RefCountedObject {
    // pending ops
    std::map<ceph_tid_t,Op*> ops;
    std::map<uint64_t, LingerOp*> linger_ops;
    std::map<ceph_tid_t,CommandOp*> command_ops;

    // backoffs
    std::map<spg_t,std::map<hobject_t,OSDBackoff>> backoffs;
    std::map<uint64_t,OSDBackoff*> backoffs_by_id;

    int osd;
    // NB locking two sessions at the same time is only safe because
    // it is only done in _recalc_linger_op_target with s and
    // linger_op->session, and it holds rwlock for write.  We disable
    // lockdep (using std::sharedMutex) because lockdep doesn't know
    // that.
    std::shared_mutex lock;

    int incarnation;
    ConnectionRef con;
    int num_locks;
    std::unique_ptr<std::mutex[]> completion_locks;

    OSDSession(CephContext *cct, int o) :
      osd(o), incarnation(0), con(NULL),
      num_locks(cct->_conf->objecter_completion_locks_per_session),
      completion_locks(new std::mutex[num_locks]) {}

    ~OSDSession() override;

    bool is_homeless() { return (osd == -1); }

    std::unique_lock<std::mutex> get_lock(object_t& oid);
  };
  std::map<int,OSDSession*> osd_sessions;

  bool osdmap_full_flag() const;
  bool osdmap_pool_full(const int64_t pool_id) const;


 private:

  /**
   * Test pg_pool_t::FLAG_FULL on a pool
   *
   * @return true if the pool exists and has the flag set, or
   *         the global full flag is set, else false
   */
  bool _osdmap_pool_full(const int64_t pool_id) const;
  bool _osdmap_pool_full(const pg_pool_t &p) const {
    return p.has_flag(pg_pool_t::FLAG_FULL) && honor_pool_full;
  }
  void update_pool_full_map(std::map<int64_t, bool>& pool_full_map);

  std::map<uint64_t, LingerOp*> linger_ops;
  // we use this just to confirm a cookie is valid before dereferencing the ptr
  std::set<LingerOp*> linger_ops_set;

  std::map<ceph_tid_t,PoolStatOp*> poolstat_ops;
  std::map<ceph_tid_t,StatfsOp*> statfs_ops;
  std::map<ceph_tid_t,PoolOp*> pool_ops;
  std::atomic<unsigned> num_homeless_ops{0};

  OSDSession* homeless_session = new OSDSession(cct, -1);


  // ops waiting for an osdmap with a new pool or confirmation that
  // the pool does not exist (may be expanded to other uses later)
  std::map<uint64_t, LingerOp*> check_latest_map_lingers;
  std::map<ceph_tid_t, Op*> check_latest_map_ops;
  std::map<ceph_tid_t, CommandOp*> check_latest_map_commands;

  std::map<epoch_t,
	   std::vector<std::pair<std::unique_ptr<OpCompletion>,
				 boost::system::error_code>>> waiting_for_map;

  ceph::timespan mon_timeout;
  ceph::timespan osd_timeout;

  MOSDOp *_prepare_osd_op(Op *op);
  void _send_op(Op *op);
  void _send_op_account(Op *op);
  void _cancel_linger_op(Op *op);
  void _finish_op(Op *op, int r);
  static bool is_pg_changed(
    int oldprimary,
    const std::vector<int>& oldacting,
    int newprimary,
    const std::vector<int>& newacting,
    bool any_change=false);
  enum recalc_op_target_result {
    RECALC_OP_TARGET_NO_ACTION = 0,
    RECALC_OP_TARGET_NEED_RESEND,
    RECALC_OP_TARGET_POOL_DNE,
    RECALC_OP_TARGET_OSD_DNE,
    RECALC_OP_TARGET_OSD_DOWN,
  };
  bool _osdmap_full_flag() const;
  bool _osdmap_has_pool_full() const;
  void _prune_snapc(
    const mempool::osdmap::map<int64_t, snap_interval_set_t>& new_removed_snaps,
    Op *op);

  bool target_should_be_paused(op_target_t *op);
  int _calc_target(op_target_t *t, Connection *con,
		   bool any_change = false);
  int _map_session(op_target_t *op, OSDSession **s,
		   ceph::shunique_lock<ceph::shared_mutex>& lc);

  void _session_op_assign(OSDSession *s, Op *op);
  void _session_op_remove(OSDSession *s, Op *op);
  void _session_linger_op_assign(OSDSession *to, LingerOp *op);
  void _session_linger_op_remove(OSDSession *from, LingerOp *op);
  void _session_command_op_assign(OSDSession *to, CommandOp *op);
  void _session_command_op_remove(OSDSession *from, CommandOp *op);

  int _assign_op_target_session(Op *op, ceph::shunique_lock<ceph::shared_mutex>& lc,
				bool src_session_locked,
				bool dst_session_locked);
  int _recalc_linger_op_target(LingerOp *op,
			       ceph::shunique_lock<ceph::shared_mutex>& lc);

  void _linger_submit(LingerOp *info,
		      ceph::shunique_lock<ceph::shared_mutex>& sul);
  void _send_linger(LingerOp *info,
		    ceph::shunique_lock<ceph::shared_mutex>& sul);
  void _linger_commit(LingerOp *info, boost::system::error_code ec,
		      ceph::buffer::list& outbl);
  void _linger_reconnect(LingerOp *info, boost::system::error_code ec);
  void _send_linger_ping(LingerOp *info);
  void _linger_ping(LingerOp *info, boost::system::error_code ec,
		    ceph::coarse_mono_time sent, uint32_t register_gen);
  boost::system::error_code _normalize_watch_error(boost::system::error_code ec);

  friend class CB_Objecter_GetVersion;
  friend class CB_DoWatchError;
public:
  template<typename CT>
  auto linger_callback_flush(CT&& ct) {
    boost::asio::async_completion<CT, void(void)> init(ct);
    boost::asio::defer(finish_strand, std::move(init.completion_handler));
    return init.result.get();
  }

private:
  void _check_op_pool_dne(Op *op, std::unique_lock<std::shared_mutex> *sl);
  void _send_op_map_check(Op *op);
  void _op_cancel_map_check(Op *op);
  void _check_linger_pool_dne(LingerOp *op, bool *need_unregister);
  void _send_linger_map_check(LingerOp *op);
  void _linger_cancel_map_check(LingerOp *op);
  void _check_command_map_dne(CommandOp *op);
  void _send_command_map_check(CommandOp *op);
  void _command_cancel_map_check(CommandOp *op);

  void _kick_requests(OSDSession *session, std::map<uint64_t, LingerOp *>& lresend);
  void _linger_ops_resend(std::map<uint64_t, LingerOp *>& lresend,
			  std::unique_lock<ceph::shared_mutex>& ul);

  int _get_session(int osd, OSDSession **session,
		   ceph::shunique_lock<ceph::shared_mutex>& sul);
  void put_session(OSDSession *s);
  void get_session(OSDSession *s);
  void _reopen_session(OSDSession *session);
  void close_session(OSDSession *session);

  void _nlist_reply(NListContext *list_context, int r, Context *final_finish,
		   epoch_t reply_epoch);

  void resend_mon_ops();

  /**
   * handle a budget for in-flight ops
   * budget is taken whenever an op goes into the ops std::map
   * and returned whenever an op is removed from the std::map
   * If throttle_op needs to throttle it will unlock client_lock.
   */
  int calc_op_budget(const boost::container::small_vector_base<OSDOp>& ops);
  void _throttle_op(Op *op, ceph::shunique_lock<ceph::shared_mutex>& sul,
		    int op_size = 0);
  int _take_op_budget(Op *op, ceph::shunique_lock<ceph::shared_mutex>& sul) {
    ceph_assert(sul && sul.mutex() == &rwlock);
    int op_budget = calc_op_budget(op->ops);
    if (keep_balanced_budget) {
      _throttle_op(op, sul, op_budget);
    } else { // update take_linger_budget to match this!
      op_throttle_bytes.take(op_budget);
      op_throttle_ops.take(1);
    }
    op->budget = op_budget;
    return op_budget;
  }
  int take_linger_budget(LingerOp *info);
  void put_op_budget_bytes(int op_budget) {
    ceph_assert(op_budget >= 0);
    op_throttle_bytes.put(op_budget);
    op_throttle_ops.put(1);
  }
  void put_nlist_context_budget(NListContext *list_context);
  Throttle op_throttle_bytes{cct, "objecter_bytes",
			     static_cast<int64_t>(
			       cct->_conf->objecter_inflight_op_bytes)};
  Throttle op_throttle_ops{cct, "objecter_ops",
			   static_cast<int64_t>(
			     cct->_conf->objecter_inflight_ops)};
 public:
  Objecter(CephContext *cct, Messenger *m, MonClient *mc,
	   boost::asio::io_context& service);
  ~Objecter() override;

  void init();
  void start(const OSDMap *o = nullptr);
  void shutdown();

  // These two templates replace osdmap_(get)|(put)_read. Simply wrap
  // whatever functionality you want to use the OSDMap in a lambda like:
  //
  // with_osdmap([](const OSDMap& o) { o.do_stuff(); });
  //
  // or
  //
  // auto t = with_osdmap([&](const OSDMap& o) { return o.lookup_stuff(x); });
  //
  // Do not call into something that will try to lock the OSDMap from
  // here or you will have great woe and misery.

  template<typename Callback, typename...Args>
  decltype(auto) with_osdmap(Callback&& cb, Args&&... args) {
    shared_lock l(rwlock);
    return std::forward<Callback>(cb)(*osdmap, std::forward<Args>(args)...);
  }


  /**
   * Tell the objecter to throttle outgoing ops according to its
   * budget (in _conf). If you do this, ops can block, in
   * which case it will unlock client_lock and sleep until
   * incoming messages reduce the used budget low enough for
   * the ops to continue going; then it will lock client_lock again.
   */
  void set_balanced_budget() { keep_balanced_budget = true; }
  void unset_balanced_budget() { keep_balanced_budget = false; }

  void set_honor_pool_full() { honor_pool_full = true; }
  void unset_honor_pool_full() { honor_pool_full = false; }

  void _scan_requests(
    OSDSession *s,
    bool skipped_map,
    bool cluster_full,
    std::map<int64_t, bool> *pool_full_map,
    std::map<ceph_tid_t, Op*>& need_resend,
    std::list<LingerOp*>& need_resend_linger,
    std::map<ceph_tid_t, CommandOp*>& need_resend_command,
    ceph::shunique_lock<ceph::shared_mutex>& sul);

  int64_t get_object_hash_position(int64_t pool, const std::string& key,
				   const std::string& ns);
  int64_t get_object_pg_hash_position(int64_t pool, const std::string& key,
				      const std::string& ns);

  // messages
 public:
  bool ms_dispatch(Message *m) override;
  bool ms_can_fast_dispatch_any() const override {
    return true;
  }
  bool ms_can_fast_dispatch(const Message *m) const override {
    switch (m->get_type()) {
    case CEPH_MSG_OSD_OPREPLY:
    case CEPH_MSG_WATCH_NOTIFY:
      return true;
    default:
      return false;
    }
  }
  void ms_fast_dispatch(Message *m) override {
    if (!ms_dispatch(m)) {
      m->put();
    }
  }

  void handle_osd_op_reply(class MOSDOpReply *m);
  void handle_osd_backoff(class MOSDBackoff *m);
  void handle_watch_notify(class MWatchNotify *m);
  void handle_osd_map(class MOSDMap *m);
  void wait_for_osd_map(epoch_t e=0);

  template<typename CompletionToken>
  auto wait_for_osd_map(CompletionToken&& token) {
    boost::asio::async_completion<CompletionToken, void()> init(token);
    unique_lock l(rwlock);
    if (osdmap->get_epoch()) {
      l.unlock();
      boost::asio::post(std::move(init.completion_handler));
    } else {
      waiting_for_map[0].emplace_back(
	OpCompletion::create(
	  service.get_executor(),
	  [c = std::move(init.completion_handler)]
	  (boost::system::error_code) mutable {
	    std::move(c)();
	  }), boost::system::error_code{});
      l.unlock();
    }
    return init.result.get();
  }


  /**
   * Get std::list of entities blocklisted since this was last called,
   * and reset the std::list.
   *
   * Uses a std::set because typical use case is to compare some
   * other std::list of clients to see which overlap with the blocklisted
   * addrs.
   *
   */
  void consume_blocklist_events(std::set<entity_addr_t> *events);

  int pool_snap_by_name(int64_t poolid,
			const char *snap_name,
			snapid_t *snap) const;
  int pool_snap_get_info(int64_t poolid, snapid_t snap,
			 pool_snap_info_t *info) const;
  int pool_snap_list(int64_t poolid, std::vector<uint64_t> *snaps);
private:

  void emit_blocklist_events(const OSDMap::Incremental &inc);
  void emit_blocklist_events(const OSDMap &old_osd_map,
                             const OSDMap &new_osd_map);

  // low-level
  void _op_submit(Op *op, ceph::shunique_lock<ceph::shared_mutex>& lc,
		  ceph_tid_t *ptid);
  void _op_submit_with_budget(Op *op,
			      ceph::shunique_lock<ceph::shared_mutex>& lc,
			      ceph_tid_t *ptid,
			      int *ctx_budget = NULL);
  // public interface
public:
  void op_submit(Op *op, ceph_tid_t *ptid = NULL, int *ctx_budget = NULL);
  bool is_active() {
    std::shared_lock l(rwlock);
    return !((!inflight_ops) && linger_ops.empty() &&
	     poolstat_ops.empty() && statfs_ops.empty());
  }

  /**
   * Output in-flight requests
   */
  void _dump_active(OSDSession *s);
  void _dump_active();
  void dump_active();
  void dump_requests(ceph::Formatter *fmt);
  void _dump_ops(const OSDSession *s, ceph::Formatter *fmt);
  void dump_ops(ceph::Formatter *fmt);
  void _dump_linger_ops(const OSDSession *s, ceph::Formatter *fmt);
  void dump_linger_ops(ceph::Formatter *fmt);
  void _dump_command_ops(const OSDSession *s, ceph::Formatter *fmt);
  void dump_command_ops(ceph::Formatter *fmt);
  void dump_pool_ops(ceph::Formatter *fmt) const;
  void dump_pool_stat_ops(ceph::Formatter *fmt) const;
  void dump_statfs_ops(ceph::Formatter *fmt) const;

  int get_client_incarnation() const { return client_inc; }
  void set_client_incarnation(int inc) { client_inc = inc; }

  bool have_map(epoch_t epoch);

  struct CB_Objecter_GetVersion {
    Objecter *objecter;
    std::unique_ptr<OpCompletion> fin;

    CB_Objecter_GetVersion(Objecter *o, std::unique_ptr<OpCompletion> c)
      : objecter(o), fin(std::move(c)) {}
    void operator()(boost::system::error_code ec, version_t newest,
		    version_t oldest) {
      if (ec == boost::system::errc::resource_unavailable_try_again) {
	// try again as instructed
	objecter->_wait_for_latest_osdmap(std::move(*this));
      } else if (ec) {
	ceph::async::post(std::move(fin), ec);
      } else {
	auto l = std::unique_lock(objecter->rwlock);
	objecter->_get_latest_version(oldest, newest, std::move(fin),
				      std::move(l));
      }
    }
  };

  template<typename CompletionToken>
  auto wait_for_map(epoch_t epoch, CompletionToken&& token) {
    boost::asio::async_completion<CompletionToken, OpSignature> init(token);

    if (osdmap->get_epoch() >= epoch) {
      boost::asio::post(service,
			ceph::async::bind_handler(
			  std::move(init.completion_handler),
			  boost::system::error_code()));
    } else {
      monc->get_version("osdmap",
			CB_Objecter_GetVersion(
			  this,
			  OpCompletion::create(service.get_executor(),
					       std::move(init.completion_handler))));
    }
    return init.result.get();
  }

  void _wait_for_new_map(std::unique_ptr<OpCompletion>, epoch_t epoch,
			 boost::system::error_code = {});

private:
  void _wait_for_latest_osdmap(CB_Objecter_GetVersion&& c) {
    monc->get_version("osdmap", std::move(c));
  }

public:

  template<typename CompletionToken>
  auto wait_for_latest_osdmap(CompletionToken&& token) {
    boost::asio::async_completion<CompletionToken, OpSignature> init(token);

    monc->get_version("osdmap",
		      CB_Objecter_GetVersion(
			this,
			OpCompletion::create(service.get_executor(),
					     std::move(init.completion_handler))));
    return init.result.get();
  }

  void wait_for_latest_osdmap(std::unique_ptr<OpCompletion> c) {
    monc->get_version("osdmap",
		      CB_Objecter_GetVersion(this, std::move(c)));
  }

  template<typename CompletionToken>
  auto get_latest_version(epoch_t oldest, epoch_t newest,
			  CompletionToken&& token) {
    boost::asio::async_completion<CompletionToken, OpSignature> init(token);
    {
      std::unique_lock wl(rwlock);
      _get_latest_version(oldest, newest,
			  OpCompletion::create(
			    service.get_executor(),
			    std::move(init.completion_handler)),
			  std::move(wl));
    }
    return init.result.get();
  }

  void _get_latest_version(epoch_t oldest, epoch_t neweset,
			   std::unique_ptr<OpCompletion> fin,
			   std::unique_lock<ceph::shared_mutex>&& ul);

  /** Get the current set of global op flags */
  int get_global_op_flags() const { return global_op_flags; }
  /** Add a flag to the global op flags, not really atomic operation */
  void add_global_op_flags(int flag) {
    global_op_flags.fetch_or(flag);
  }
  /** Clear the passed flags from the global op flag set */
  void clear_global_op_flag(int flags) {
    global_op_flags.fetch_and(~flags);
  }

  /// cancel an in-progress request with the given return code
private:
  int op_cancel(OSDSession *s, ceph_tid_t tid, int r);
  int _op_cancel(ceph_tid_t tid, int r);
public:
  int op_cancel(ceph_tid_t tid, int r);
  int op_cancel(const std::vector<ceph_tid_t>& tidls, int r);

  /**
   * Any write op which is in progress at the start of this call shall no
   * longer be in progress when this call ends.  Operations started after the
   * start of this call may still be in progress when this call ends.
   *
   * @return the latest possible epoch in which a cancelled op could have
   *         existed, or -1 if nothing was cancelled.
   */
  epoch_t op_cancel_writes(int r, int64_t pool=-1);

  // commands
  void osd_command(int osd, std::vector<std::string> cmd,
		   ceph::buffer::list inbl, ceph_tid_t *ptid,
		   decltype(CommandOp::onfinish)&& onfinish) {
    ceph_assert(osd >= 0);
    auto c = new CommandOp(
      osd,
      std::move(cmd),
      std::move(inbl),
      std::move(onfinish));
    submit_command(c, ptid);
  }
  template<typename CompletionToken>
  auto osd_command(int osd, std::vector<std::string> cmd,
		   ceph::buffer::list inbl, ceph_tid_t *ptid,
		   CompletionToken&& token) {
    boost::asio::async_completion<CompletionToken,
				  CommandOp::OpSig> init(token);
    osd_command(osd, std::move(cmd), std::move(inbl), ptid,
		CommandOp::OpComp::create(service.get_executor(),
					  std::move(init.completion_handler)));
    return init.result.get();
  }

  void pg_command(pg_t pgid, std::vector<std::string> cmd,
		  ceph::buffer::list inbl, ceph_tid_t *ptid,
		  decltype(CommandOp::onfinish)&& onfinish) {
    auto *c = new CommandOp(
      pgid,
      std::move(cmd),
      std::move(inbl),
      std::move(onfinish));
    submit_command(c, ptid);
  }

  template<typename CompletionToken>
  auto pg_command(pg_t pgid, std::vector<std::string> cmd,
		  ceph::buffer::list inbl, ceph_tid_t *ptid,
		  CompletionToken&& token) {
    boost::asio::async_completion<CompletionToken,
				  CommandOp::OpSig> init(token);
    pg_command(pgid, std::move(cmd), std::move(inbl), ptid,
	       CommandOp::OpComp::create(service.get_executor(),
					 std::move(init.completion_handler)));
    return init.result.get();
  }

  // mid-level helpers
  Op *prepare_mutate_op(
    const object_t& oid, const object_locator_t& oloc,
    ObjectOperation& op, const SnapContext& snapc,
    ceph::real_time mtime, int flags,
    Context *oncommit, version_t *objver = NULL,
    osd_reqid_t reqid = osd_reqid_t(),
    ZTracer::Trace *parent_trace = nullptr) {
    Op *o = new Op(oid, oloc, std::move(op.ops), flags | global_op_flags |
		   CEPH_OSD_FLAG_WRITE, oncommit, objver,
		   nullptr, parent_trace);
    o->priority = op.priority;
    o->mtime = mtime;
    o->snapc = snapc;
    o->out_rval.swap(op.out_rval);
    o->out_bl.swap(op.out_bl);
    o->out_handler.swap(op.out_handler);
    o->out_ec.swap(op.out_ec);
    o->reqid = reqid;
    op.clear();
    return o;
  }
  ceph_tid_t mutate(
    const object_t& oid, const object_locator_t& oloc,
    ObjectOperation& op, const SnapContext& snapc,
    ceph::real_time mtime, int flags,
    Context *oncommit, version_t *objver = NULL,
    osd_reqid_t reqid = osd_reqid_t()) {
    Op *o = prepare_mutate_op(oid, oloc, op, snapc, mtime, flags,
			      oncommit, objver, reqid);
    ceph_tid_t tid;
    op_submit(o, &tid);
    return tid;
  }

  void mutate(const object_t& oid, const object_locator_t& oloc,
	      ObjectOperation&& op, const SnapContext& snapc,
	      ceph::real_time mtime, int flags,
	      std::unique_ptr<Op::OpComp>&& oncommit,
	      version_t *objver = NULL, osd_reqid_t reqid = osd_reqid_t(),
	      ZTracer::Trace *parent_trace = nullptr) {
    Op *o = new Op(oid, oloc, std::move(op.ops), flags | global_op_flags |
		   CEPH_OSD_FLAG_WRITE, std::move(oncommit), objver,
		   nullptr, parent_trace);
    o->priority = op.priority;
    o->mtime = mtime;
    o->snapc = snapc;
    o->out_bl.swap(op.out_bl);
    o->out_handler.swap(op.out_handler);
    o->out_rval.swap(op.out_rval);
    o->out_ec.swap(op.out_ec);
    o->reqid = reqid;
    op.clear();
    op_submit(o);
  }

  Op *prepare_read_op(
    const object_t& oid, const object_locator_t& oloc,
    ObjectOperation& op,
    snapid_t snapid, ceph::buffer::list *pbl, int flags,
    Context *onack, version_t *objver = NULL,
    int *data_offset = NULL,
    uint64_t features = 0,
    ZTracer::Trace *parent_trace = nullptr) {
    Op *o = new Op(oid, oloc, std::move(op.ops), flags | global_op_flags |
		   CEPH_OSD_FLAG_READ, onack, objver,
		   data_offset, parent_trace);
    o->priority = op.priority;
    o->snapid = snapid;
    o->outbl = pbl;
    if (!o->outbl && op.size() == 1 && op.out_bl[0] && op.out_bl[0]->length())
	o->outbl = op.out_bl[0];
    o->out_bl.swap(op.out_bl);
    o->out_handler.swap(op.out_handler);
    o->out_rval.swap(op.out_rval);
    o->out_ec.swap(op.out_ec);
    op.clear();
    return o;
  }
  ceph_tid_t read(
    const object_t& oid, const object_locator_t& oloc,
    ObjectOperation& op,
    snapid_t snapid, ceph::buffer::list *pbl, int flags,
    Context *onack, version_t *objver = NULL,
    int *data_offset = NULL,
    uint64_t features = 0) {
    Op *o = prepare_read_op(oid, oloc, op, snapid, pbl, flags, onack, objver,
			    data_offset);
    if (features)
      o->features = features;
    ceph_tid_t tid;
    op_submit(o, &tid);
    return tid;
  }

  void read(const object_t& oid, const object_locator_t& oloc,
	    ObjectOperation&& op, snapid_t snapid, ceph::buffer::list *pbl,
	    int flags, std::unique_ptr<Op::OpComp>&& onack,
	    version_t *objver = nullptr, int *data_offset = nullptr,
	    uint64_t features = 0, ZTracer::Trace *parent_trace = nullptr) {
    Op *o = new Op(oid, oloc, std::move(op.ops), flags | global_op_flags |
		   CEPH_OSD_FLAG_READ, std::move(onack), objver,
		   data_offset, parent_trace);
    o->priority = op.priority;
    o->snapid = snapid;
    o->outbl = pbl;
    // XXX
    if (!o->outbl && op.size() == 1 && op.out_bl[0] && op.out_bl[0]->length()) {
      o->outbl = op.out_bl[0];
    }
    o->out_bl.swap(op.out_bl);
    o->out_handler.swap(op.out_handler);
    o->out_rval.swap(op.out_rval);
    o->out_ec.swap(op.out_ec);
    if (features)
      o->features = features;
    op.clear();
    op_submit(o);
  }


  Op *prepare_pg_read_op(
    uint32_t hash, object_locator_t oloc,
    ObjectOperation& op, ceph::buffer::list *pbl, int flags,
    Context *onack, epoch_t *reply_epoch,
    int *ctx_budget) {
    Op *o = new Op(object_t(), oloc,
		   std::move(op.ops),
		   flags | global_op_flags | CEPH_OSD_FLAG_READ |
		   CEPH_OSD_FLAG_IGNORE_OVERLAY,
		   onack, NULL);
    o->target.precalc_pgid = true;
    o->target.base_pgid = pg_t(hash, oloc.pool);
    o->priority = op.priority;
    o->snapid = CEPH_NOSNAP;
    o->outbl = pbl;
    o->out_bl.swap(op.out_bl);
    o->out_handler.swap(op.out_handler);
    o->out_rval.swap(op.out_rval);
    o->out_ec.swap(op.out_ec);
    o->reply_epoch = reply_epoch;
    if (ctx_budget) {
      // budget is tracked by listing context
      o->ctx_budgeted = true;
    }
    op.clear();
    return o;
  }
  ceph_tid_t pg_read(
    uint32_t hash, object_locator_t oloc,
    ObjectOperation& op, ceph::buffer::list *pbl, int flags,
    Context *onack, epoch_t *reply_epoch,
    int *ctx_budget) {
    Op *o = prepare_pg_read_op(hash, oloc, op, pbl, flags,
			       onack, reply_epoch, ctx_budget);
    ceph_tid_t tid;
    op_submit(o, &tid, ctx_budget);
    return tid;
  }

  ceph_tid_t pg_read(
    uint32_t hash, object_locator_t oloc,
    ObjectOperation& op, ceph::buffer::list *pbl, int flags,
    std::unique_ptr<Op::OpComp>&& onack, epoch_t *reply_epoch, int *ctx_budget) {
    ceph_tid_t tid;
    Op *o = new Op(object_t(), oloc,
		   std::move(op.ops),
		   flags | global_op_flags | CEPH_OSD_FLAG_READ |
		   CEPH_OSD_FLAG_IGNORE_OVERLAY,
		   std::move(onack), nullptr);
    o->target.precalc_pgid = true;
    o->target.base_pgid = pg_t(hash, oloc.pool);
    o->priority = op.priority;
    o->snapid = CEPH_NOSNAP;
    o->outbl = pbl;
    o->out_bl.swap(op.out_bl);
    o->out_handler.swap(op.out_handler);
    o->out_rval.swap(op.out_rval);
    o->out_ec.swap(op.out_ec);
    o->reply_epoch = reply_epoch;
    if (ctx_budget) {
      // budget is tracked by listing context
      o->ctx_budgeted = true;
    }
    op_submit(o, &tid, ctx_budget);
    op.clear();
    return tid;
  }

  // caller owns a ref
  LingerOp *linger_register(const object_t& oid, const object_locator_t& oloc,
			    int flags);
  ceph_tid_t linger_watch(LingerOp *info,
			  ObjectOperation& op,
			  const SnapContext& snapc, ceph::real_time mtime,
			  ceph::buffer::list& inbl,
			  decltype(info->on_reg_commit)&& oncommit,
			  version_t *objver);
  ceph_tid_t linger_watch(LingerOp *info,
			  ObjectOperation& op,
			  const SnapContext& snapc, ceph::real_time mtime,
			  ceph::buffer::list& inbl,
			  Context* onfinish,
			  version_t *objver) {
    return linger_watch(info, op, snapc, mtime, inbl,
			OpContextVert<ceph::buffer::list>(onfinish, nullptr), objver);
  }
  ceph_tid_t linger_notify(LingerOp *info,
			   ObjectOperation& op,
			   snapid_t snap, ceph::buffer::list& inbl,
			   decltype(LingerOp::on_reg_commit)&& onfinish,
			   version_t *objver);
  ceph_tid_t linger_notify(LingerOp *info,
			   ObjectOperation& op,
			   snapid_t snap, ceph::buffer::list& inbl,
			   ceph::buffer::list *poutbl,
			   Context* onack,
			   version_t *objver) {
    return linger_notify(info, op, snap, inbl,
			 OpContextVert(onack, poutbl),
			 objver);
  }
  tl::expected<ceph::timespan,
	       boost::system::error_code> linger_check(LingerOp *info);
  void linger_cancel(LingerOp *info);  // releases a reference
  void _linger_cancel(LingerOp *info);

  void _do_watch_notify(boost::intrusive_ptr<LingerOp> info,
                        boost::intrusive_ptr<MWatchNotify> m);

  /**
   * set up initial ops in the op std::vector, and allocate a final op slot.
   *
   * The caller is responsible for filling in the final ops_count ops.
   *
   * @param ops op std::vector
   * @param ops_count number of final ops the caller will fill in
   * @param extra_ops pointer to [array of] initial op[s]
   * @return index of final op (for caller to fill in)
   */
  int init_ops(boost::container::small_vector_base<OSDOp>& ops, int ops_count,
	       ObjectOperation *extra_ops) {
    int i;
    int extra = 0;

    if (extra_ops)
      extra = extra_ops->ops.size();

    ops.resize(ops_count + extra);

    for (i=0; i<extra; i++) {
      ops[i] = extra_ops->ops[i];
    }

    return i;
  }


  // high-level helpers
  Op *prepare_stat_op(
    const object_t& oid, const object_locator_t& oloc,
    snapid_t snap, uint64_t *psize, ceph::real_time *pmtime,
    int flags, Context *onfinish, version_t *objver = NULL,
    ObjectOperation *extra_ops = NULL) {
    osdc_opvec ops;
    int i = init_ops(ops, 1, extra_ops);
    ops[i].op.op = CEPH_OSD_OP_STAT;
    C_Stat *fin = new C_Stat(psize, pmtime, onfinish);
    Op *o = new Op(oid, oloc, std::move(ops), flags | global_op_flags |
		   CEPH_OSD_FLAG_READ, fin, objver);
    o->snapid = snap;
    o->outbl = &fin->bl;
    return o;
  }
  ceph_tid_t stat(
    const object_t& oid, const object_locator_t& oloc,
    snapid_t snap, uint64_t *psize, ceph::real_time *pmtime,
    int flags, Context *onfinish, version_t *objver = NULL,
    ObjectOperation *extra_ops = NULL) {
    Op *o = prepare_stat_op(oid, oloc, snap, psize, pmtime, flags,
			    onfinish, objver, extra_ops);
    ceph_tid_t tid;
    op_submit(o, &tid);
    return tid;
  }

  Op *prepare_read_op(
    const object_t& oid, const object_locator_t& oloc,
    uint64_t off, uint64_t len, snapid_t snap, ceph::buffer::list *pbl,
    int flags, Context *onfinish, version_t *objver = NULL,
    ObjectOperation *extra_ops = NULL, int op_flags = 0,
    ZTracer::Trace *parent_trace = nullptr) {
    osdc_opvec ops;
    int i = init_ops(ops, 1, extra_ops);
    ops[i].op.op = CEPH_OSD_OP_READ;
    ops[i].op.extent.offset = off;
    ops[i].op.extent.length = len;
    ops[i].op.extent.truncate_size = 0;
    ops[i].op.extent.truncate_seq = 0;
    ops[i].op.flags = op_flags;
    Op *o = new Op(oid, oloc, std::move(ops), flags | global_op_flags |
		   CEPH_OSD_FLAG_READ, onfinish, objver,
		   nullptr, parent_trace);
    o->snapid = snap;
    o->outbl = pbl;
    return o;
  }
  ceph_tid_t read(
    const object_t& oid, const object_locator_t& oloc,
    uint64_t off, uint64_t len, snapid_t snap, ceph::buffer::list *pbl,
    int flags, Context *onfinish, version_t *objver = NULL,
    ObjectOperation *extra_ops = NULL, int op_flags = 0) {
    Op *o = prepare_read_op(oid, oloc, off, len, snap, pbl, flags,
			    onfinish, objver, extra_ops, op_flags);
    ceph_tid_t tid;
    op_submit(o, &tid);
    return tid;
  }

  Op *prepare_cmpext_op(
    const object_t& oid, const object_locator_t& oloc,
    uint64_t off, ceph::buffer::list &cmp_bl,
    snapid_t snap, int flags, Context *onfinish, version_t *objver = NULL,
    ObjectOperation *extra_ops = NULL, int op_flags = 0) {
    osdc_opvec ops;
    int i = init_ops(ops, 1, extra_ops);
    ops[i].op.op = CEPH_OSD_OP_CMPEXT;
    ops[i].op.extent.offset = off;
    ops[i].op.extent.length = cmp_bl.length();
    ops[i].op.extent.truncate_size = 0;
    ops[i].op.extent.truncate_seq = 0;
    ops[i].indata = cmp_bl;
    ops[i].op.flags = op_flags;
    Op *o = new Op(oid, oloc, std::move(ops), flags | global_op_flags |
		   CEPH_OSD_FLAG_READ, onfinish, objver);
    o->snapid = snap;
    return o;
  }

  ceph_tid_t cmpext(
    const object_t& oid, const object_locator_t& oloc,
    uint64_t off, ceph::buffer::list &cmp_bl,
    snapid_t snap, int flags, Context *onfinish, version_t *objver = NULL,
    ObjectOperation *extra_ops = NULL, int op_flags = 0) {
    Op *o = prepare_cmpext_op(oid, oloc, off, cmp_bl, snap,
			      flags, onfinish, objver, extra_ops, op_flags);
    ceph_tid_t tid;
    op_submit(o, &tid);
    return tid;
  }

  ceph_tid_t read_trunc(const object_t& oid, const object_locator_t& oloc,
			uint64_t off, uint64_t len, snapid_t snap,
			ceph::buffer::list *pbl, int flags, uint64_t trunc_size,
			__u32 trunc_seq, Context *onfinish,
			version_t *objver = NULL,
			ObjectOperation *extra_ops = NULL, int op_flags = 0) {
    osdc_opvec ops;
    int i = init_ops(ops, 1, extra_ops);
    ops[i].op.op = CEPH_OSD_OP_READ;
    ops[i].op.extent.offset = off;
    ops[i].op.extent.length = len;
    ops[i].op.extent.truncate_size = trunc_size;
    ops[i].op.extent.truncate_seq = trunc_seq;
    ops[i].op.flags = op_flags;
    Op *o = new Op(oid, oloc, std::move(ops), flags | global_op_flags |
		   CEPH_OSD_FLAG_READ, onfinish, objver);
    o->snapid = snap;
    o->outbl = pbl;
    ceph_tid_t tid;
    op_submit(o, &tid);
    return tid;
  }
  ceph_tid_t mapext(const object_t& oid, const object_locator_t& oloc,
		    uint64_t off, uint64_t len, snapid_t snap, ceph::buffer::list *pbl,
		    int flags, Context *onfinish, version_t *objver = NULL,
		    ObjectOperation *extra_ops = NULL) {
    osdc_opvec ops;
    int i = init_ops(ops, 1, extra_ops);
    ops[i].op.op = CEPH_OSD_OP_MAPEXT;
    ops[i].op.extent.offset = off;
    ops[i].op.extent.length = len;
    ops[i].op.extent.truncate_size = 0;
    ops[i].op.extent.truncate_seq = 0;
    Op *o = new Op(oid, oloc, std::move(ops), flags | global_op_flags |
		   CEPH_OSD_FLAG_READ, onfinish, objver);
    o->snapid = snap;
    o->outbl = pbl;
    ceph_tid_t tid;
    op_submit(o, &tid);
    return tid;
  }
  ceph_tid_t getxattr(const object_t& oid, const object_locator_t& oloc,
	     const char *name, snapid_t snap, ceph::buffer::list *pbl, int flags,
	     Context *onfinish,
	     version_t *objver = NULL, ObjectOperation *extra_ops = NULL) {
    osdc_opvec ops;
    int i = init_ops(ops, 1, extra_ops);
    ops[i].op.op = CEPH_OSD_OP_GETXATTR;
    ops[i].op.xattr.name_len = (name ? strlen(name) : 0);
    ops[i].op.xattr.value_len = 0;
    if (name)
      ops[i].indata.append(name, ops[i].op.xattr.name_len);
    Op *o = new Op(oid, oloc, std::move(ops), flags | global_op_flags |
		   CEPH_OSD_FLAG_READ, onfinish, objver);
    o->snapid = snap;
    o->outbl = pbl;
    ceph_tid_t tid;
    op_submit(o, &tid);
    return tid;
  }

  ceph_tid_t getxattrs(const object_t& oid, const object_locator_t& oloc,
		       snapid_t snap, std::map<std::string,ceph::buffer::list>& attrset,
		       int flags, Context *onfinish, version_t *objver = NULL,
		       ObjectOperation *extra_ops = NULL) {
    osdc_opvec ops;
    int i = init_ops(ops, 1, extra_ops);
    ops[i].op.op = CEPH_OSD_OP_GETXATTRS;
    C_GetAttrs *fin = new C_GetAttrs(attrset, onfinish);
    Op *o = new Op(oid, oloc, std::move(ops), flags | global_op_flags |
		   CEPH_OSD_FLAG_READ, fin, objver);
    o->snapid = snap;
    o->outbl = &fin->bl;
    ceph_tid_t tid;
    op_submit(o, &tid);
    return tid;
  }

  ceph_tid_t read_full(const object_t& oid, const object_locator_t& oloc,
		       snapid_t snap, ceph::buffer::list *pbl, int flags,
		       Context *onfinish, version_t *objver = NULL,
		       ObjectOperation *extra_ops = NULL) {
    return read(oid, oloc, 0, 0, snap, pbl, flags | global_op_flags |
		CEPH_OSD_FLAG_READ, onfinish, objver, extra_ops);
  }


  // writes
  ceph_tid_t _modify(const object_t& oid, const object_locator_t& oloc,
		     osdc_opvec& ops,
		     ceph::real_time mtime,
		     const SnapContext& snapc, int flags,
		     Context *oncommit,
		     version_t *objver = NULL) {
    Op *o = new Op(oid, oloc, std::move(ops), flags | global_op_flags |
		   CEPH_OSD_FLAG_WRITE, oncommit, objver);
    o->mtime = mtime;
    o->snapc = snapc;
    ceph_tid_t tid;
    op_submit(o, &tid);
    return tid;
  }
  Op *prepare_write_op(
    const object_t& oid, const object_locator_t& oloc,
    uint64_t off, uint64_t len, const SnapContext& snapc,
    const ceph::buffer::list &bl, ceph::real_time mtime, int flags,
    Context *oncommit, version_t *objver = NULL,
    ObjectOperation *extra_ops = NULL, int op_flags = 0,
    ZTracer::Trace *parent_trace = nullptr) {
    osdc_opvec ops;
    int i = init_ops(ops, 1, extra_ops);
    ops[i].op.op = CEPH_OSD_OP_WRITE;
    ops[i].op.extent.offset = off;
    ops[i].op.extent.length = len;
    ops[i].op.extent.truncate_size = 0;
    ops[i].op.extent.truncate_seq = 0;
    ops[i].indata = bl;
    ops[i].op.flags = op_flags;
    Op *o = new Op(oid, oloc, std::move(ops), flags | global_op_flags |
		   CEPH_OSD_FLAG_WRITE, std::move(oncommit), objver,
                   nullptr, parent_trace);
    o->mtime = mtime;
    o->snapc = snapc;
    return o;
  }
  ceph_tid_t write(
    const object_t& oid, const object_locator_t& oloc,
    uint64_t off, uint64_t len, const SnapContext& snapc,
    const ceph::buffer::list &bl, ceph::real_time mtime, int flags,
    Context *oncommit, version_t *objver = NULL,
    ObjectOperation *extra_ops = NULL, int op_flags = 0) {
    Op *o = prepare_write_op(oid, oloc, off, len, snapc, bl, mtime, flags,
			     oncommit, objver, extra_ops, op_flags);
    ceph_tid_t tid;
    op_submit(o, &tid);
    return tid;
  }
  Op *prepare_append_op(
    const object_t& oid, const object_locator_t& oloc,
    uint64_t len, const SnapContext& snapc,
    const ceph::buffer::list &bl, ceph::real_time mtime, int flags,
    Context *oncommit,
    version_t *objver = NULL,
    ObjectOperation *extra_ops = NULL) {
    osdc_opvec ops;
    int i = init_ops(ops, 1, extra_ops);
    ops[i].op.op = CEPH_OSD_OP_APPEND;
    ops[i].op.extent.offset = 0;
    ops[i].op.extent.length = len;
    ops[i].op.extent.truncate_size = 0;
    ops[i].op.extent.truncate_seq = 0;
    ops[i].indata = bl;
    Op *o = new Op(oid, oloc, std::move(ops), flags | global_op_flags |
		   CEPH_OSD_FLAG_WRITE, oncommit, objver);
    o->mtime = mtime;
    o->snapc = snapc;
    return o;
  }
  ceph_tid_t append(
    const object_t& oid, const object_locator_t& oloc,
    uint64_t len, const SnapContext& snapc,
    const ceph::buffer::list &bl, ceph::real_time mtime, int flags,
    Context *oncommit,
    version_t *objver = NULL,
    ObjectOperation *extra_ops = NULL) {
    Op *o = prepare_append_op(oid, oloc, len, snapc, bl, mtime, flags,
			      oncommit, objver, extra_ops);
    ceph_tid_t tid;
    op_submit(o, &tid);
    return tid;
  }
  ceph_tid_t write_trunc(const object_t& oid, const object_locator_t& oloc,
			 uint64_t off, uint64_t len, const SnapContext& snapc,
			 const ceph::buffer::list &bl, ceph::real_time mtime, int flags,
			 uint64_t trunc_size, __u32 trunc_seq,
			 Context *oncommit,
			 version_t *objver = NULL,
			 ObjectOperation *extra_ops = NULL, int op_flags = 0) {
    osdc_opvec ops;
    int i = init_ops(ops, 1, extra_ops);
    ops[i].op.op = CEPH_OSD_OP_WRITE;
    ops[i].op.extent.offset = off;
    ops[i].op.extent.length = len;
    ops[i].op.extent.truncate_size = trunc_size;
    ops[i].op.extent.truncate_seq = trunc_seq;
    ops[i].indata = bl;
    ops[i].op.flags = op_flags;
    Op *o = new Op(oid, oloc, std::move(ops), flags | global_op_flags |
		   CEPH_OSD_FLAG_WRITE, oncommit, objver);
    o->mtime = mtime;
    o->snapc = snapc;
    ceph_tid_t tid;
    op_submit(o, &tid);
    return tid;
  }
  Op *prepare_write_full_op(
    const object_t& oid, const object_locator_t& oloc,
    const SnapContext& snapc, const ceph::buffer::list &bl,
    ceph::real_time mtime, int flags,
    Context *oncommit, version_t *objver = NULL,
    ObjectOperation *extra_ops = NULL, int op_flags = 0) {
    osdc_opvec ops;
    int i = init_ops(ops, 1, extra_ops);
    ops[i].op.op = CEPH_OSD_OP_WRITEFULL;
    ops[i].op.extent.offset = 0;
    ops[i].op.extent.length = bl.length();
    ops[i].indata = bl;
    ops[i].op.flags = op_flags;
    Op *o = new Op(oid, oloc, std::move(ops), flags | global_op_flags |
		   CEPH_OSD_FLAG_WRITE, oncommit, objver);
    o->mtime = mtime;
    o->snapc = snapc;
    return o;
  }
  ceph_tid_t write_full(
    const object_t& oid, const object_locator_t& oloc,
    const SnapContext& snapc, const ceph::buffer::list &bl,
    ceph::real_time mtime, int flags,
    Context *oncommit, version_t *objver = NULL,
    ObjectOperation *extra_ops = NULL, int op_flags = 0) {
    Op *o = prepare_write_full_op(oid, oloc, snapc, bl, mtime, flags,
				  oncommit, objver, extra_ops, op_flags);
    ceph_tid_t tid;
    op_submit(o, &tid);
    return tid;
  }
  Op *prepare_writesame_op(
    const object_t& oid, const object_locator_t& oloc,
    uint64_t write_len, uint64_t off,
    const SnapContext& snapc, const ceph::buffer::list &bl,
    ceph::real_time mtime, int flags,
    Context *oncommit, version_t *objver = NULL,
    ObjectOperation *extra_ops = NULL, int op_flags = 0) {

    osdc_opvec ops;
    int i = init_ops(ops, 1, extra_ops);
    ops[i].op.op = CEPH_OSD_OP_WRITESAME;
    ops[i].op.writesame.offset = off;
    ops[i].op.writesame.length = write_len;
    ops[i].op.writesame.data_length = bl.length();
    ops[i].indata = bl;
    ops[i].op.flags = op_flags;
    Op *o = new Op(oid, oloc, std::move(ops), flags | global_op_flags |
		   CEPH_OSD_FLAG_WRITE, oncommit, objver);
    o->mtime = mtime;
    o->snapc = snapc;
    return o;
  }
  ceph_tid_t writesame(
    const object_t& oid, const object_locator_t& oloc,
    uint64_t write_len, uint64_t off,
    const SnapContext& snapc, const ceph::buffer::list &bl,
    ceph::real_time mtime, int flags,
    Context *oncommit, version_t *objver = NULL,
    ObjectOperation *extra_ops = NULL, int op_flags = 0) {

    Op *o = prepare_writesame_op(oid, oloc, write_len, off, snapc, bl,
				 mtime, flags, oncommit, objver,
				 extra_ops, op_flags);

    ceph_tid_t tid;
    op_submit(o, &tid);
    return tid;
  }
  ceph_tid_t trunc(const object_t& oid, const object_locator_t& oloc,
		   const SnapContext& snapc, ceph::real_time mtime, int flags,
		   uint64_t trunc_size, __u32 trunc_seq,
		   Context *oncommit, version_t *objver = NULL,
		   ObjectOperation *extra_ops = NULL) {
    osdc_opvec ops;
    int i = init_ops(ops, 1, extra_ops);
    ops[i].op.op = CEPH_OSD_OP_TRUNCATE;
    ops[i].op.extent.offset = trunc_size;
    ops[i].op.extent.truncate_size = trunc_size;
    ops[i].op.extent.truncate_seq = trunc_seq;
    Op *o = new Op(oid, oloc, std::move(ops), flags | global_op_flags |
		   CEPH_OSD_FLAG_WRITE, oncommit, objver);
    o->mtime = mtime;
    o->snapc = snapc;
    ceph_tid_t tid;
    op_submit(o, &tid);
    return tid;
  }
  ceph_tid_t zero(const object_t& oid, const object_locator_t& oloc,
		  uint64_t off, uint64_t len, const SnapContext& snapc,
		  ceph::real_time mtime, int flags, Context *oncommit,
	     version_t *objver = NULL, ObjectOperation *extra_ops = NULL) {
    osdc_opvec ops;
    int i = init_ops(ops, 1, extra_ops);
    ops[i].op.op = CEPH_OSD_OP_ZERO;
    ops[i].op.extent.offset = off;
    ops[i].op.extent.length = len;
    Op *o = new Op(oid, oloc, std::move(ops), flags | global_op_flags |
		   CEPH_OSD_FLAG_WRITE, oncommit, objver);
    o->mtime = mtime;
    o->snapc = snapc;
    ceph_tid_t tid;
    op_submit(o, &tid);
    return tid;
  }
  ceph_tid_t rollback_object(const object_t& oid, const object_locator_t& oloc,
			     const SnapContext& snapc, snapid_t snapid,
			     ceph::real_time mtime, Context *oncommit,
			     version_t *objver = NULL,
			     ObjectOperation *extra_ops = NULL) {
    osdc_opvec ops;
    int i = init_ops(ops, 1, extra_ops);
    ops[i].op.op = CEPH_OSD_OP_ROLLBACK;
    ops[i].op.snap.snapid = snapid;
    Op *o = new Op(oid, oloc, std::move(ops), CEPH_OSD_FLAG_WRITE, oncommit, objver);
    o->mtime = mtime;
    o->snapc = snapc;
    ceph_tid_t tid;
    op_submit(o, &tid);
    return tid;
  }
  ceph_tid_t create(const object_t& oid, const object_locator_t& oloc,
		    const SnapContext& snapc, ceph::real_time mtime, int global_flags,
		    int create_flags, Context *oncommit,
		    version_t *objver = NULL,
		    ObjectOperation *extra_ops = NULL) {
    osdc_opvec ops;
    int i = init_ops(ops, 1, extra_ops);
    ops[i].op.op = CEPH_OSD_OP_CREATE;
    ops[i].op.flags = create_flags;
    Op *o = new Op(oid, oloc, std::move(ops), global_flags | global_op_flags |
		   CEPH_OSD_FLAG_WRITE, oncommit, objver);
    o->mtime = mtime;
    o->snapc = snapc;
    ceph_tid_t tid;
    op_submit(o, &tid);
    return tid;
  }
  Op *prepare_remove_op(
    const object_t& oid, const object_locator_t& oloc,
    const SnapContext& snapc, ceph::real_time mtime, int flags,
    Context *oncommit,
    version_t *objver = NULL, ObjectOperation *extra_ops = NULL) {
    osdc_opvec ops;
    int i = init_ops(ops, 1, extra_ops);
    ops[i].op.op = CEPH_OSD_OP_DELETE;
    Op *o = new Op(oid, oloc, std::move(ops), flags | global_op_flags |
		   CEPH_OSD_FLAG_WRITE, oncommit, objver);
    o->mtime = mtime;
    o->snapc = snapc;
    return o;
  }
  ceph_tid_t remove(
    const object_t& oid, const object_locator_t& oloc,
    const SnapContext& snapc, ceph::real_time mtime, int flags,
    Context *oncommit,
    version_t *objver = NULL, ObjectOperation *extra_ops = NULL) {
    Op *o = prepare_remove_op(oid, oloc, snapc, mtime, flags,
			      oncommit, objver, extra_ops);
    ceph_tid_t tid;
    op_submit(o, &tid);
    return tid;
  }

  ceph_tid_t setxattr(const object_t& oid, const object_locator_t& oloc,
	      const char *name, const SnapContext& snapc, const ceph::buffer::list &bl,
	      ceph::real_time mtime, int flags,
	      Context *oncommit,
	      version_t *objver = NULL, ObjectOperation *extra_ops = NULL) {
    osdc_opvec ops;
    int i = init_ops(ops, 1, extra_ops);
    ops[i].op.op = CEPH_OSD_OP_SETXATTR;
    ops[i].op.xattr.name_len = (name ? strlen(name) : 0);
    ops[i].op.xattr.value_len = bl.length();
    if (name)
      ops[i].indata.append(name, ops[i].op.xattr.name_len);
    ops[i].indata.append(bl);
    Op *o = new Op(oid, oloc, std::move(ops), flags | global_op_flags |
		   CEPH_OSD_FLAG_WRITE, oncommit,
		   objver);
    o->mtime = mtime;
    o->snapc = snapc;
    ceph_tid_t tid;
    op_submit(o, &tid);
    return tid;
  }
  ceph_tid_t removexattr(const object_t& oid, const object_locator_t& oloc,
	      const char *name, const SnapContext& snapc,
	      ceph::real_time mtime, int flags,
	      Context *oncommit,
	      version_t *objver = NULL, ObjectOperation *extra_ops = NULL) {
    osdc_opvec ops;
    int i = init_ops(ops, 1, extra_ops);
    ops[i].op.op = CEPH_OSD_OP_RMXATTR;
    ops[i].op.xattr.name_len = (name ? strlen(name) : 0);
    ops[i].op.xattr.value_len = 0;
    if (name)
      ops[i].indata.append(name, ops[i].op.xattr.name_len);
    Op *o = new Op(oid, oloc, std::move(ops), flags | global_op_flags |
		   CEPH_OSD_FLAG_WRITE, oncommit, objver);
    o->mtime = mtime;
    o->snapc = snapc;
    ceph_tid_t tid;
    op_submit(o, &tid);
    return tid;
  }

  void list_nobjects(NListContext *p, Context *onfinish);
  uint32_t list_nobjects_seek(NListContext *p, uint32_t pos);
  uint32_t list_nobjects_seek(NListContext *list_context, const hobject_t& c);
  void list_nobjects_get_cursor(NListContext *list_context, hobject_t *c);

  hobject_t enumerate_objects_begin();
  hobject_t enumerate_objects_end();

  template<typename T>
  friend struct EnumerationContext;
  template<typename T>
  friend struct CB_EnumerateReply;
  template<typename T>
  void enumerate_objects(
    int64_t pool_id,
    std::string_view ns,
    hobject_t start,
    hobject_t end,
    const uint32_t max,
    const ceph::buffer::list& filter_bl,
    fu2::unique_function<void(boost::system::error_code,
			      std::vector<T>,
			      hobject_t) &&> on_finish);
  template<typename T>
  void _issue_enumerate(hobject_t start,
			std::unique_ptr<EnumerationContext<T>>);
  template<typename T>
  void _enumerate_reply(
    ceph::buffer::list&& bl,
    boost::system::error_code ec,
    std::unique_ptr<EnumerationContext<T>>&& ectx);

  // -------------------------
  // pool ops
private:
  void pool_op_submit(PoolOp *op);
  void _pool_op_submit(PoolOp *op);
  void _finish_pool_op(PoolOp *op, int r);
  void _do_delete_pool(int64_t pool,
		       decltype(PoolOp::onfinish)&& onfinish);

public:
  void create_pool_snap(int64_t pool, std::string_view snapName,
			decltype(PoolOp::onfinish)&& onfinish);
  void create_pool_snap(int64_t pool, std::string_view snapName,
			Context* c) {
    create_pool_snap(pool, snapName,
		     OpContextVert<ceph::buffer::list>(c, nullptr));
  }
  void allocate_selfmanaged_snap(int64_t pool,
				 std::unique_ptr<ceph::async::Completion<
				 void(boost::system::error_code,
				      snapid_t)>> onfinish);
  void allocate_selfmanaged_snap(int64_t pool, snapid_t* psnapid,
				 Context* c) {
    allocate_selfmanaged_snap(pool,
			      OpContextVert(c, psnapid));
  }
  void delete_pool_snap(int64_t pool, std::string_view snapName,
			decltype(PoolOp::onfinish)&& onfinish);
  void delete_pool_snap(int64_t pool, std::string_view snapName,
			Context* c) {
    delete_pool_snap(pool, snapName,
		     OpContextVert<ceph::buffer::list>(c, nullptr));
  }

  void delete_selfmanaged_snap(int64_t pool, snapid_t snap,
			       decltype(PoolOp::onfinish)&& onfinish);
  void delete_selfmanaged_snap(int64_t pool, snapid_t snap,
			       Context* c) {
    delete_selfmanaged_snap(pool, snap,
			    OpContextVert<ceph::buffer::list>(c, nullptr));
  }


  void create_pool(std::string_view name,
		   decltype(PoolOp::onfinish)&& onfinish,
		   int crush_rule=-1);
  void create_pool(std::string_view name, Context *onfinish,
		  int crush_rule=-1) {
    create_pool(name,
		OpContextVert<ceph::buffer::list>(onfinish, nullptr),
		crush_rule);
  }
  void delete_pool(int64_t pool,
		   decltype(PoolOp::onfinish)&& onfinish);
  void delete_pool(int64_t pool,
		   Context* onfinish) {
    delete_pool(pool, OpContextVert<ceph::buffer::list>(onfinish, nullptr));
  }

  void delete_pool(std::string_view name,
		   decltype(PoolOp::onfinish)&& onfinish);

  void delete_pool(std::string_view name,
		   Context* onfinish) {
    delete_pool(name, OpContextVert<ceph::buffer::list>(onfinish, nullptr));
  }

  void handle_pool_op_reply(MPoolOpReply *m);
  int pool_op_cancel(ceph_tid_t tid, int r);

  // --------------------------
  // pool stats
private:
  void _poolstat_submit(PoolStatOp *op);
public:
  void handle_get_pool_stats_reply(MGetPoolStatsReply *m);
  void get_pool_stats(const std::vector<std::string>& pools,
		      decltype(PoolStatOp::onfinish)&& onfinish);
  template<typename CompletionToken>
  auto get_pool_stats(const std::vector<std::string>& pools,
		      CompletionToken&& token) {
    boost::asio::async_completion<CompletionToken,
				  PoolStatOp::OpSig> init(token);
    get_pool_stats(pools,
		   PoolStatOp::OpComp::create(
		     service.get_executor(),
		     std::move(init.completion_handler)));
    return init.result.get();
  }
  int pool_stat_op_cancel(ceph_tid_t tid, int r);
  void _finish_pool_stat_op(PoolStatOp *op, int r);

  // ---------------------------
  // df stats
private:
  void _fs_stats_submit(StatfsOp *op);
public:
  void handle_fs_stats_reply(MStatfsReply *m);
  void get_fs_stats(boost::optional<int64_t> poolid,
		    decltype(StatfsOp::onfinish)&& onfinish);
  template<typename CompletionToken>
  auto get_fs_stats(boost::optional<int64_t> poolid,
		    CompletionToken&& token) {
    boost::asio::async_completion<CompletionToken, StatfsOp::OpSig> init(token);
    get_fs_stats(poolid,
		 StatfsOp::OpComp::create(service.get_executor(),
					  std::move(init.completion_handler)));
    return init.result.get();
  }
  void get_fs_stats(struct ceph_statfs& result, boost::optional<int64_t> poolid,
		    Context *onfinish) {
    get_fs_stats(poolid, OpContextVert(onfinish, result));
  }
  int statfs_op_cancel(ceph_tid_t tid, int r);
  void _finish_statfs_op(StatfsOp *op, int r);

  // ---------------------------
  // some scatter/gather hackery

  void _sg_read_finish(std::vector<ObjectExtent>& extents,
		       std::vector<ceph::buffer::list>& resultbl,
		       ceph::buffer::list *bl, Context *onfinish);

  struct C_SGRead : public Context {
    Objecter *objecter;
    std::vector<ObjectExtent> extents;
    std::vector<ceph::buffer::list> resultbl;
    ceph::buffer::list *bl;
    Context *onfinish;
    C_SGRead(Objecter *ob,
	     std::vector<ObjectExtent>& e, std::vector<ceph::buffer::list>& r, ceph::buffer::list *b,
	     Context *c) :
      objecter(ob), bl(b), onfinish(c) {
      extents.swap(e);
      resultbl.swap(r);
    }
    void finish(int r) override {
      objecter->_sg_read_finish(extents, resultbl, bl, onfinish);
    }
  };

  void sg_read_trunc(std::vector<ObjectExtent>& extents, snapid_t snap,
		     ceph::buffer::list *bl, int flags, uint64_t trunc_size,
		     __u32 trunc_seq, Context *onfinish, int op_flags = 0) {
    if (extents.size() == 1) {
      read_trunc(extents[0].oid, extents[0].oloc, extents[0].offset,
		 extents[0].length, snap, bl, flags, extents[0].truncate_size,
		 trunc_seq, onfinish, 0, 0, op_flags);
    } else {
      C_GatherBuilder gather(cct);
      std::vector<ceph::buffer::list> resultbl(extents.size());
      int i=0;
      for (auto p = extents.begin(); p != extents.end(); ++p) {
	read_trunc(p->oid, p->oloc, p->offset, p->length, snap, &resultbl[i++],
		   flags, p->truncate_size, trunc_seq, gather.new_sub(),
		   0, 0, op_flags);
      }
      gather.set_finisher(new C_SGRead(this, extents, resultbl, bl, onfinish));
      gather.activate();
    }
  }

  void sg_read(std::vector<ObjectExtent>& extents, snapid_t snap, ceph::buffer::list *bl,
	       int flags, Context *onfinish, int op_flags = 0) {
    sg_read_trunc(extents, snap, bl, flags, 0, 0, onfinish, op_flags);
  }

  void sg_write_trunc(std::vector<ObjectExtent>& extents, const SnapContext& snapc,
		      const ceph::buffer::list& bl, ceph::real_time mtime, int flags,
		      uint64_t trunc_size, __u32 trunc_seq,
		      Context *oncommit, int op_flags = 0) {
    if (extents.size() == 1) {
      write_trunc(extents[0].oid, extents[0].oloc, extents[0].offset,
		  extents[0].length, snapc, bl, mtime, flags,
		  extents[0].truncate_size, trunc_seq, oncommit,
		  0, 0, op_flags);
    } else {
      C_GatherBuilder gcom(cct, oncommit);
      auto it = bl.cbegin();
      for (auto p = extents.begin(); p != extents.end(); ++p) {
	ceph::buffer::list cur;
	for (auto bit = p->buffer_extents.begin();
	     bit != p->buffer_extents.end();
	     ++bit) {
	  if (it.get_off() != bit->first) {
	    it.seek(bit->first);
	  }
	  it.copy(bit->second, cur);
	}
	ceph_assert(cur.length() == p->length);
	write_trunc(p->oid, p->oloc, p->offset, p->length,
	      snapc, cur, mtime, flags, p->truncate_size, trunc_seq,
	      oncommit ? gcom.new_sub():0,
	      0, 0, op_flags);
      }
      gcom.activate();
    }
  }

  void sg_write(std::vector<ObjectExtent>& extents, const SnapContext& snapc,
		const ceph::buffer::list& bl, ceph::real_time mtime, int flags,
		Context *oncommit, int op_flags = 0) {
    sg_write_trunc(extents, snapc, bl, mtime, flags, 0, 0, oncommit,
		   op_flags);
  }

  void ms_handle_connect(Connection *con) override;
  bool ms_handle_reset(Connection *con) override;
  void ms_handle_remote_reset(Connection *con) override;
  bool ms_handle_refused(Connection *con) override;

  void blocklist_self(bool set);

private:
  epoch_t epoch_barrier = 0;
  bool retry_writes_after_first_reply =
    cct->_conf->objecter_retry_writes_after_first_reply;

public:
  void set_epoch_barrier(epoch_t epoch);

  PerfCounters *get_logger() {
    return logger;
  }
};

#endif