]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
crimson/tools: fix bugs introduced in 3333ff 38577/head
authorSamuel Just <sjust@redhat.com>
Tue, 15 Dec 2020 03:04:02 +0000 (19:04 -0800)
committerSamuel Just <sjust@redhat.com>
Tue, 15 Dec 2020 03:04:17 +0000 (03:04 +0000)
You can't actually mix buffered and direct io on a stream.

Signed-off-by: Samuel Just <sjust@redhat.com>
src/crimson/tools/store-nbd.cc
src/include/buffer.h

index 5e5625397334eb8df32b918b7921f36ed2006b05..c4e528ed7c5a2e8a1fe31e6ae3166e5dd6deb40a 100644 (file)
@@ -168,7 +168,7 @@ struct request_context_t {
       memcpy(handle, p, sizeof(handle));
       p += sizeof(handle);
       from = seastar::consume_be<uint64_t>(p);
-      len = seastar::consume_be<uint64_t>(p);
+      len = seastar::consume_be<uint32_t>(p);
       logger().debug(
         "Got request, magic {}, type {}, from {}, len {}",
        magic, type, from, len);
@@ -194,9 +194,14 @@ struct request_context_t {
     return out.write(std::move(buffer)).then([this, &out] {
       if (out_buffer) {
         return seastar::do_for_each(
-          out_buffer->buffers(),
-          [&out](auto &ptr) {
-            return out.write(ptr.c_str(), ptr.length());
+          out_buffer->mut_buffers(),
+          [&out](bufferptr &ptr) {
+            return out.write(
+             seastar::temporary_buffer<char>(
+               ptr.c_str(),
+               ptr.length(),
+               seastar::make_deleter([ptr](){}))
+           );
           });
       } else {
         return seastar::now();
@@ -324,6 +329,7 @@ int main(int argc, char** argv)
 }
 
 class nbd_oldstyle_negotiation_t {
+  uint64_t magic = seastar::cpu_to_be(0x4e42444d41474943); // "NBDMAGIC"
   uint64_t magic2 = seastar::cpu_to_be(0x00420281861253);  // "IHAVEOPT"
   uint64_t size = 0;
   uint32_t flags = seastar::cpu_to_be(0);
@@ -338,11 +344,10 @@ seastar::future<> send_negotiation(
   size_t size,
   seastar::output_stream<char>& out)
 {
-  return out.write("NBDMAGIC").then([size, &out] {
-    seastar::temporary_buffer<char> buf{sizeof(nbd_oldstyle_negotiation_t)};
-    new (buf.get_write()) nbd_oldstyle_negotiation_t(size, 1);
-    return out.write(std::move(buf));
-  }).then([&out] {
+  seastar::temporary_buffer<char> buf{sizeof(nbd_oldstyle_negotiation_t)};
+  new (buf.get_write()) nbd_oldstyle_negotiation_t(size, 1);
+  return out.write(std::move(buf)
+  ).then([&out] {
     return out.flush();
   });
 }
index f24459958da810dbb09e9e27a5777f3455ffcfc4..7c8f90e9fb5d3ad55757a8eceb422ec726594c0f 100644 (file)
@@ -989,6 +989,7 @@ struct error_code;
     }
 
     const buffers_t& buffers() const { return _buffers; }
+    buffers_t& mut_buffers() { return _buffers; }
     void swap(list& other) noexcept;
     unsigned length() const {
 #if 0