MCPcopy Create free account
hub / github.com/ceph/ceph / queue_read_head

Function queue_read_head

src/cls/queue/cls_queue_src.cc:47–105  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

45}
46
47int queue_read_head(cls_method_context_t hctx, cls_queue_head& head)
48{
49 uint64_t chunk_size = page_size, start_offset = 0;
50
51 bufferlist bl_head;
52 const auto ret = cls_cxx_read(hctx, start_offset, chunk_size, &bl_head);
53 if (ret < 0) {
54 CLS_LOG(5, "ERROR: queue_read_head: failed to read head");
55 return ret;
56 }
57 if (ret == 0) {
58 CLS_LOG(20, "INFO: queue_read_head: empty head, not initialized yet");
59 return -EINVAL;
60 }
61
62 //Process the chunk of data read
63 auto it = bl_head.cbegin();
64 // Queue head start
65 uint16_t queue_head_start;
66 try {
67 decode(queue_head_start, it);
68 } catch (const ceph::buffer::error& err) {
69 CLS_LOG(0, "ERROR: queue_read_head: failed to decode queue start: %s", err.what());
70 return -EINVAL;
71 }
72 if (queue_head_start != QUEUE_HEAD_START) {
73 CLS_LOG(0, "ERROR: queue_read_head: invalid queue start");
74 return -EINVAL;
75 }
76
77 uint64_t encoded_len;
78 try {
79 decode(encoded_len, it);
80 } catch (const ceph::buffer::error& err) {
81 CLS_LOG(0, "ERROR: queue_read_head: failed to decode encoded head size: %s", err.what());
82 return -EINVAL;
83 }
84
85 if (encoded_len > (chunk_size - QUEUE_ENTRY_OVERHEAD)) {
86 start_offset = chunk_size;
87 chunk_size = (encoded_len - (chunk_size - QUEUE_ENTRY_OVERHEAD));
88 bufferlist bl_remaining_head;
89 const auto ret = cls_cxx_read2(hctx, start_offset, chunk_size, &bl_remaining_head, CEPH_OSD_OP_FLAG_FADVISE_SEQUENTIAL);
90 if (ret < 0) {
91 CLS_LOG(5, "ERROR: queue_read_head: failed to read remaining part of head");
92 return ret;
93 }
94 bl_head.claim_append(bl_remaining_head);
95 }
96
97 try {
98 decode(head, it);
99 } catch (const ceph::buffer::error& err) {
100 CLS_LOG(0, "ERROR: queue_read_head: failed to decode head: %s", err.what());
101 return -EINVAL;
102 }
103
104 return 0;

Callers 15

cls_2pc_queue_reserveFunction · 0.85
cls_2pc_queue_commitFunction · 0.85
cls_2pc_queue_abortFunction · 0.85
queue_initFunction · 0.85
queue_get_capacityFunction · 0.85
cls_queue_enqueueFunction · 0.85
cls_queue_list_entriesFunction · 0.85

Calls 6

cls_cxx_readFunction · 0.50
decodeFunction · 0.50
cls_cxx_read2Function · 0.50
cbeginMethod · 0.45
whatMethod · 0.45
claim_appendMethod · 0.45

Tested by

no test coverage detected