]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
NVMEDevice: impl read_buffered method
authorHaomai Wang <haomai@xsky.com>
Sat, 9 Jan 2016 14:12:46 +0000 (22:12 +0800)
committerHaomai Wang <haomai@xsky.com>
Mon, 1 Feb 2016 14:00:46 +0000 (22:00 +0800)
Signed-off-by: Haomai Wang <haomai@xsky.com>
src/common/Makefile.am
src/common/align.h [new file with mode: 0644]
src/os/bluestore/BlockDevice.h
src/os/bluestore/NVMEDevice.cc
src/os/bluestore/NVMEDevice.h

index c94232210e2ad4090b767f114d0e36b45900f225..3401bcb87f58db64d01f6b7c9ae5a513d2d546ca 100644 (file)
@@ -269,7 +269,8 @@ noinst_HEADERS += \
        common/event_socket.h \
        common/PluginRegistry.h \
        common/ceph_time.h \
-       common/ceph_timer.h
+       common/ceph_timer.h \
+       common/align.h
 
 if ENABLE_XIO
 noinst_HEADERS += \
diff --git a/src/common/align.h b/src/common/align.h
new file mode 100644 (file)
index 0000000..b5c25b9
--- /dev/null
@@ -0,0 +1,30 @@
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+// vim: ts=8 sw=2 smarttab
+/*
+ * Ceph - scalable distributed file system
+  *
+ * Copyright (C) 2015 XSky <haomai@xsky.com>
+ *
+ * Author: Haomai Wang <haomaiwang@gmail.com>
+ *
+ * This is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software
+ * Foundation.  See file COPYING.
+ *
+ */
+
+#ifndef CEPH_COMMON_ALIGN_H
+#define CEPH_COMMON_ALIGN_H
+
+template <typename T>
+inline constexpr T align_up(T v, T align) {
+  return (v + align - 1) & ~(align - 1);
+}
+
+template <typename T>
+inline constexpr T align_down(T v, T align) {
+  return v & ~(align - 1);
+}
+
+#endif /* CEPH_COMMON_ALIGN_H */
index a5057260c57141397d38fd386b1d0d16092d23a3..123c8461d7c5baac07623b92e6631f931e2123cf 100644 (file)
@@ -76,6 +76,7 @@ public:
 
   virtual int read(uint64_t off, uint64_t len, bufferlist *pbl,
           IOContext *ioc, bool buffered) = 0;
+  virtual int read_buffered(uint64_t off, uint64_t len, char *buf) = 0;
 
   virtual int aio_write(uint64_t off, bufferlist& bl,
                IOContext *ioc, bool buffered) = 0;
index a9897bdec12cf97cbb6d3ee1112af4f2b4b5247d..fbf5721a848ad59463e890de27863e5beaddb63d 100644 (file)
@@ -34,6 +34,7 @@
 #include "include/stringify.h"
 #include "include/types.h"
 #include "include/compat.h"
+#include "common/align.h"
 #include "common/errno.h"
 #include "common/debug.h"
 #include "common/Initialize.h"
@@ -320,7 +321,6 @@ NVMEDevice::NVMEDevice(aio_callback_t cb, void *cbpriv)
 {
   zeros = buffer::create_page_aligned(1048576);
   zeros.zero();
-
 }
 
 
@@ -682,6 +682,58 @@ int NVMEDevice::read(uint64_t off, uint64_t len, bufferlist *pbl,
   return r;
 }
 
+int NVMEDevice::read_buffered(uint64_t off, uint64_t len, char *buf)
+{
+  dout(5) << __func__ << " " << off << "~" << len << dendl;
+  assert(len > 0);
+  assert(off < size);
+  assert(off + len <= size);
+
+  uint64_t aligned_off = align_down(off, block_size);
+  uint64_t aligned_len = align_up(len, block_size);
+  IOContext ioc(nullptr);
+  Task *t;
+  int r = rte_mempool_get(task_pool, (void **)&t);
+  if (r < 0) {
+    derr << __func__ << " task_pool rte_mempool_get failed" << dendl;
+    return r;
+  }
+  t->start = ceph_clock_now(g_ceph_context);
+  t->buf = rte_malloc(NULL, aligned_len, block_size);
+  if (t->buf == NULL) {
+    derr << __func__ << " task->buf rte_malloc failed" << dendl;
+    r = -ENOMEM;
+    goto out;
+  }
+  t->ctx = ioc;
+  t->command = IOCommand::READ_COMMAND;
+  t->offset = aligned_off;
+  t->len = aligned_len;
+  t->device = this;
+  t->return_code = 1;
+  t->next = t->prev = nullptr;
+  ioc->num_reading.inc();;
+  {
+    Mutex::Locker l(queue_lock);
+    task_queue.push(t);
+    if (queue_empty.read()) {
+      queue_empty.dec();
+      queue_cond.Signal();
+    }
+  }
+
+  {
+    Mutex::Locker l(ioc->lock);
+    while (t->return_code > 0)
+      ioc->cond.Wait(ioc->lock);
+  }
+  memcpy(buf, t->buf+off-aligned_off, len);
+  r = t->return_code;
+  rte_free(t->buf);
+
+  return r;
+}
+
 int NVMEDevice::invalidate_cache(uint64_t off, uint64_t len)
 {
   dout(5) << __func__ << " " << off << "~" << len << dendl;
index b7e365277688a6eb0fd9d9f207b37dfc32344732..59d8f14a821278135316a969a44d559dd4915d5b 100644 (file)
@@ -121,6 +121,7 @@ class NVMEDevice : public BlockDevice {
   int aio_zero(uint64_t off, uint64_t len,
                IOContext *ioc) override;
   int flush() override;
+  int read_buffered(uint64_t off, uint64_t len, char *buf) override;
 
   // for managing buffered readers/writers
   int invalidate_cache(uint64_t off, uint64_t len) override;