diff --git a/src/os/bluestore/NVMEDevice.cc b/src/os/bluestore/NVMEDevice.cc index 19d2b81af9885..0bfaf6d67dd04 100644 --- a/src/os/bluestore/NVMEDevice.cc +++ b/src/os/bluestore/NVMEDevice.cc @@ -299,7 +299,7 @@ struct Task { IOCommand command; uint64_t offset; uint64_t len; - bufferlist write_bl; + bufferlist bl; std::function fill_cb; Task *next = nullptr; int64_t return_code; @@ -328,6 +328,11 @@ struct Task { io_request.nseg = 0; } + void copy_to_buf(const bufferptr& p, uint64_t off, uint64_t len) { + copy_to_buf((char *)p.c_str(), off, len); + bl.append(std::move(p)); + } + void copy_to_buf(char *buf, uint64_t off, uint64_t len) { uint64_t copied = 0; uint64_t left = len; @@ -430,14 +435,14 @@ int SharedDriverQueueData::alloc_buf_from_pool(Task *t, bool write) t->io_request.nseg = count; t->ctx->total_nseg += count; if (write) { - auto blp = t->write_bl.begin(); + auto blp = t->bl.begin(); uint32_t len = 0; uint16_t i = 0; for (; i < count - 1; ++i) { blp.copy(data_buffer_size, static_cast(segs[i])); len += data_buffer_size; } - blp.copy(t->write_bl.length() - len, static_cast(segs[i])); + blp.copy(t->bl.length() - len, static_cast(segs[i])); } return 0; @@ -1003,7 +1008,7 @@ int NVMEDevice::aio_write( // TODO: if upper layer alloc memory with known physical address, // we can reduce this copy - t->write_bl = std::move(bl); + t->bl = std::move(bl); t->ctx = ioc; Task *first = static_cast(ioc->nvme_task_first); @@ -1036,7 +1041,7 @@ int NVMEDevice::write(uint64_t off, bufferlist &bl, bool buffered) // TODO: if upper layer alloc memory with known physical address, // we can reduce this copy - t->write_bl = std::move(bl); + t->bl = std::move(bl); t->ctx = &ioc; if(queue_id == -1) queue_id = ceph_gettid(); @@ -1059,9 +1064,9 @@ int NVMEDevice::read(uint64_t off, uint64_t len, bufferlist *pbl, bufferptr p = buffer::create_page_aligned(len); int r = 0; t->ctx = ioc; - char *buf = p.c_str(); - t->fill_cb = [buf, t]() { - t->copy_to_buf(buf, 0, t->len); + pbl->append(std::move(t->bl)); + t->fill_cb = [p, t]() { + t->copy_to_buf(p, 0, t->len); }; ++ioc->num_running; if(queue_id == -1) @@ -1089,11 +1094,10 @@ int NVMEDevice::aio_read( Task *t = new Task(this, IOCommand::READ_COMMAND, off, len); bufferptr p = buffer::create_page_aligned(len); - pbl->append(p); + pbl->append(std::move(t->bl)); t->ctx = ioc; - char *buf = p.c_str(); - t->fill_cb = [buf, t]() { - t->copy_to_buf(buf, 0, t->len); + t->fill_cb = [p, t]() { + t->copy_to_buf(p, 0, t->len); }; Task *first = static_cast(ioc->nvme_task_first);