33 int bulkAioRead::addRequest(
size_t obj_idx,
char* out_buf,
size_t size, off64_t offset) {
52 auto &op_data = operations[obj_idx];
54 buffers.emplace_back(out_buf);
55 auto &buf = buffers.back();
56 op_data.ceph_read_op.read(offset, size, &buf.bl, &buf.rc);
57 }
catch (std::bad_alloc&) {
58 log_func((
char*)
"Memory allocation failed while reading file %s", file_ref->
name.c_str());
74 for (
auto &op_data: operations) {
75 size_t obj_idx = op_data.first;
77 char object_suffix[18];
79 sp_bytes_written = snprintf(object_suffix,
sizeof(object_suffix),
".%016zx", obj_idx);
80 if (sp_bytes_written >= (
int)
sizeof(object_suffix)) {
81 log_func((
char*)
"Can not fit object suffix into buffer for file %s -- too big\n", file_ref->
name.c_str());
87 obj_name = file_ref->
name + std::string(object_suffix);
88 }
catch (std::bad_alloc&) {
89 log_func((
char*)
"Can not create object string for file %s)", file_ref->
name.c_str());
92 context->aio_operate(obj_name, op_data.second.cmpl.use(), &op_data.second.ceph_read_op, 0);
95 for (
auto &op_data: operations) {
96 op_data.second.cmpl.wait_for_complete();
97 int rval = op_data.second.cmpl.get_return_value();
107 log_func((
char*)
"Read of the object %ld for file %s failed", op_data.first, file_ref->
name.c_str());
127 for (ReadOpData &op_data: buffers) {
128 if (op_data.rc < 0) {
130 log_func((
char*)
"One of the reads failed with rc %d", op_data.rc);
133 op_data.bl.begin().copy(op_data.bl.length(), op_data.out_buf);
134 res += op_data.bl.length();
159 log_func((
char*)
"Zero-length read request for file %s, probably client error", file_ref->
name.c_str());
163 char*
const buf_start_ptr = (
char*) out_buf;
167 size_t to_read = req_size;
169 size_t start_block = offset / object_size;
171 size_t chunk_start = offset % object_size;
173 while (to_read > 0) {
174 size_t chunk_len = std::min(to_read, object_size - chunk_start);
176 if (buf_pos >= req_size) {
177 log_func((
char*)
"Internal bug! Attempt to read %lu data for block (%lu, %lu) of file %s\n", buf_pos, offset, req_size, file_ref->
name.c_str());
181 int rc = addRequest(start_block, buf_start_ptr + buf_pos, chunk_len, chunk_start);
183 log_func((
char*)
"Unable to submit async read request, rc=%d\n", rc);
187 buf_pos += chunk_len;
191 if (chunk_len > to_read) {
192 log_func((
char*)
"Internal bug! Read %lu bytes, more than expected %lu bytes for block (%lu, %lu) of file %s\n", chunk_len, to_read, offset, req_size, file_ref->
name.c_str());
195 to_read = to_read - chunk_len;
static void logwrapper(char *format, va_list argp)
int read(void *out_buf, size_t size, off64_t offset)
bulkAioRead(librados::IoCtx *ct, logfunc_pointer ptr, CephFileRef *fileref)
int submit_and_wait_for_complete()
unsigned long long objectSize