| 45 | } |
| 46 | |
| 47 | int 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; |
no test coverage detected