]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
librbd: move buf_is_zero() to new common/util.cc and include/util.h
authorDan Mick <dan.mick@inktank.com>
Thu, 20 Dec 2012 21:58:55 +0000 (13:58 -0800)
committerDan Mick <dan.mick@inktank.com>
Sat, 22 Dec 2012 01:03:38 +0000 (17:03 -0800)
Signed-off-by: Dan Mick <dan.mick@inktank.com>
Reviewed-by: Josh Durgin <josh.durgin@inktank.com>
src/Makefile.am
src/common/util.cc [new file with mode: 0644]
src/include/util.h [new file with mode: 0644]
src/librbd/internal.cc

index 1497b9dd34194a9006a3a015073f02bb563a4966..c04b262930ad455cbca288e83b3c94c1ed96754d 100644 (file)
@@ -402,7 +402,8 @@ librbd_la_SOURCES = \
        osdc/Striper.cc \
        cls/lock/cls_lock_client.cc \
        cls/lock/cls_lock_types.cc \
-       cls/lock/cls_lock_ops.cc
+       cls/lock/cls_lock_ops.cc \
+       common/util.cc
 librbd_la_CFLAGS = ${AM_CFLAGS} ${CRYPTO_CFLAGS}
 librbd_la_CXXFLAGS = ${AM_CXXFLAGS}
 librbd_la_LIBADD = librados.la
@@ -1602,6 +1603,7 @@ noinst_HEADERS = \
        include/rbd/features.h\
        include/rbd/librbd.h\
        include/rbd/librbd.hpp\
+        include/util.h\
        librados/AioCompletionImpl.h\
        librados/IoCtxImpl.h\
        librados/PoolAsyncCompletionImpl.h\
diff --git a/src/common/util.cc b/src/common/util.cc
new file mode 100644 (file)
index 0000000..73b0c36
--- /dev/null
@@ -0,0 +1,36 @@
+// -*- 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) 2012 Inktank Storage, Inc.
+ *
+ * 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.
+ * 
+ */
+
+#include "include/util.h"
+
+// test if an entire buf is zero in 8-byte chunks
+bool buf_is_zero(const char *buf, size_t len)
+{
+  size_t ofs;
+  int chunk = sizeof(uint64_t);
+
+  for (ofs = 0; ofs < len; ofs += sizeof(uint64_t)) {
+    if (*(uint64_t *)(buf + ofs) != 0) {
+      return false;
+    }
+  }
+  for (ofs = (len / chunk) * chunk; ofs < len; ofs++) {
+    if (buf[ofs] != '\0') {
+      return false;
+    }
+  }
+  return true;
+}
+
+
diff --git a/src/include/util.h b/src/include/util.h
new file mode 100644 (file)
index 0000000..d215678
--- /dev/null
@@ -0,0 +1,19 @@
+// -*- 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) 2012 Inktank Storage, Inc.
+ *
+ * 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.
+ */
+
+// is buf~len completely zero (in 8-byte chunks)
+
+#include "include/types.h"
+
+bool buf_is_zero(const char *buf, size_t len);
+
index 25f723b4b568ac737d756627867f95881e1994de..1f7f7c8862994965a4b85925544e32c4bcc440fa 100644 (file)
@@ -18,6 +18,7 @@
 
 #include "librbd/internal.h"
 #include "librbd/parent_types.h"
+#include "include/util.h"
 
 #define dout_subsys ceph_subsys_rbd
 #undef dout_prefix
@@ -1933,25 +1934,6 @@ reprotect_and_return_err:
     delete ictx;
   }
 
-  // test if an entire buf is zero in 8-byte chunks
-  static bool buf_is_zero(char *buf, size_t len)
-  {
-    size_t ofs;
-    int chunk = sizeof(uint64_t);
-
-    for (ofs = 0; ofs < len; ofs += sizeof(uint64_t)) {
-      if (*(uint64_t *)(buf + ofs) != 0) {
-       return false;
-      }
-    }
-    for (ofs = (len / chunk) * chunk; ofs < len; ofs++) {
-      if (buf[ofs] != '\0') {
-       return false;
-      }
-    }
-    return true;
-  }
-
   // 'flatten' child image by copying all parent's blocks
   int flatten(ImageCtx *ictx, ProgressContext &prog_ctx)
   {