]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
os/bluestore: move assert of read/write to base class 17033/head
authormychoxin <mychoxin@gmail.com>
Tue, 15 Aug 2017 11:33:12 +0000 (19:33 +0800)
committermychoxin <mychoxin@gmail.com>
Wed, 23 Aug 2017 05:29:36 +0000 (13:29 +0800)
Signed-off-by: mychoxin <mychoxin@gmail.com>
src/os/bluestore/BlockDevice.h
src/os/bluestore/KernelDevice.cc
src/os/bluestore/NVMEDevice.cc
src/os/bluestore/PMEMDevice.cc
src/os/bluestore/PMEMDevice.h

index 45e4df8c5301cc8eb293e4ce9b84889953069f63..2f6dc17ad64f177e9c0cdad8a4b6713d42e595f5 100644 (file)
@@ -148,6 +148,15 @@ public:
   virtual int invalidate_cache(uint64_t off, uint64_t len) = 0;
   virtual int open(const std::string& path) = 0;
   virtual void close() = 0;
+
+protected:
+  bool is_valid_io(uint64_t off, uint64_t len) const {
+    return (off % block_size == 0 &&
+            len % block_size == 0 &&
+            len > 0 &&
+            off < size &&
+            off + len <= size);
+  }
 };
 
 #endif //CEPH_OS_BLUESTORE_BLOCKDEVICE_H
index b1e9126326af54e618fd0675bea1cd460b49d3d6..5ae6fae8f108a1293e113aafe34bba474e664b0b 100644 (file)
@@ -567,11 +567,7 @@ int KernelDevice::write(
   dout(20) << __func__ << " 0x" << std::hex << off << "~" << len << std::dec
           << (buffered ? " (buffered)" : " (direct)")
           << dendl;
-  assert(off % block_size == 0);
-  assert(len % block_size == 0);
-  assert(len > 0);
-  assert(off < size);
-  assert(off + len <= size);
+  assert(is_valid_io(off, len));
 
   if ((!buffered || bl.get_num_buffers() >= IOV_MAX) &&
       bl.rebuild_aligned_size_and_memory(block_size, block_size)) {
@@ -653,11 +649,7 @@ int KernelDevice::read(uint64_t off, uint64_t len, bufferlist *pbl,
   dout(5) << __func__ << " 0x" << std::hex << off << "~" << len << std::dec
          << (buffered ? " (buffered)" : " (direct)")
          << dendl;
-  assert(off % block_size == 0);
-  assert(len % block_size == 0);
-  assert(len > 0);
-  assert(off < size);
-  assert(off + len <= size);
+  assert(is_valid_io(off, len));
 
   _aio_log_start(ioc, off, len);
 
index c30ecf61b6d14cfa5313dde3a7f94ce2f34b1536..95984d5f5ef89373113c4024cad69aeefa332880 100644 (file)
@@ -988,11 +988,7 @@ int NVMEDevice::aio_write(
   uint64_t len = bl.length();
   dout(20) << __func__ << " " << off << "~" << len << " ioc " << ioc
            << " buffered " << buffered << dendl;
-  assert(off % block_size == 0);
-  assert(len % block_size == 0);
-  assert(len > 0);
-  assert(off < size);
-  assert(off + len <= size);
+  assert(is_valid_io(off, len));
 
   Task *t = new Task(this, IOCommand::WRITE_COMMAND, off, len);
 
@@ -1036,11 +1032,7 @@ int NVMEDevice::read(uint64_t off, uint64_t len, bufferlist *pbl,
                      bool buffered)
 {
   dout(5) << __func__ << " " << off << "~" << len << " ioc " << ioc << dendl;
-  assert(off % block_size == 0);
-  assert(len % block_size == 0);
-  assert(len > 0);
-  assert(off < size);
-  assert(off + len <= size);
+  assert(is_valid_io(off, len));
 
   Task *t = new Task(this, IOCommand::READ_COMMAND, off, len, 1);
   bufferptr p = buffer::create_page_aligned(len);
@@ -1071,11 +1063,7 @@ int NVMEDevice::aio_read(
     IOContext *ioc)
 {
   dout(20) << __func__ << " " << off << "~" << len << " ioc " << ioc << dendl;
-  assert(off % block_size == 0);
-  assert(len % block_size == 0);
-  assert(len > 0);
-  assert(off < size);
-  assert(off + len <= size);
+  assert(is_valid_io(off, len));
 
   Task *t = new Task(this, IOCommand::READ_COMMAND, off, len);
 
index b86ddc080b21ef7d8a11abc5cce5421bcfddee51..f094c56c137311ed841c8c7cb65639df65db0cfc 100644 (file)
@@ -217,9 +217,7 @@ int PMEMDevice::write(uint64_t off, bufferlist& bl, bool buffered)
 {
   uint64_t len = bl.length();
   dout(20) << __func__ << " " << off << "~" << len  << dendl;
-  assert(len > 0);
-  assert(off < size);
-  assert(off + len <= size);
+  assert(is_valid_io(off, len));
 
   dout(40) << "data: ";
   bl.hexdump(*_dout);
@@ -261,9 +259,7 @@ int PMEMDevice::read(uint64_t off, uint64_t len, bufferlist *pbl,
                      bool buffered)
 {
   dout(5) << __func__ << " " << off << "~" << len  << dendl;
-  assert(len > 0);
-  assert(off < size);
-  assert(off + len <= size);
+  assert(is_valid_io(off, len));
 
   bufferptr p = buffer::create_page_aligned(len);
   memcpy(p.c_str(), addr + off, len);
@@ -286,9 +282,8 @@ int PMEMDevice::aio_read(uint64_t off, uint64_t len, bufferlist *pbl,
 
 int PMEMDevice::read_random(uint64_t off, uint64_t len, char *buf, bool buffered)
 {
-  assert(len > 0);
-  assert(off < size);
-  assert(off + len <= size);
+  dout(5) << __func__ << " " << off << "~" << len << dendl;
+  assert(is_valid_io(off, len));
 
   memcpy(buf, addr + off, len);
   return 0;
index ab3507192c88b5a61ec823db3bf15e18c7dc5b79..89dba8a878402e4fea3ddfbd15876ceec1f998f2 100644 (file)
@@ -60,6 +60,13 @@ public:
   int invalidate_cache(uint64_t off, uint64_t len) override;
   int open(const std::string &path) override;
   void close() override;
+
+private:
+  bool is_valid_io(uint64_t off, uint64_t len) const {
+    return (len > 0 &&
+            off < size &&
+            off + len <= size);
+  }
 };
 
 #endif