]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
add fs_types.h, with file_layout_t
authorSage Weil <sage@redhat.com>
Tue, 10 Nov 2015 11:40:09 +0000 (06:40 -0500)
committerSage Weil <sage@redhat.com>
Tue, 1 Mar 2016 16:16:59 +0000 (11:16 -0500)
Signed-off-by: Sage Weil <sage@redhat.com>
13 files changed:
src/common/Makefile.am
src/common/fs_types.cc [new file with mode: 0644]
src/common/snap_types.h
src/include/Makefile.am
src/include/ceph_features.h
src/include/filepath.h
src/include/fs_types.h [new file with mode: 0644]
src/include/types.h
src/mds/mdstypes.cc
src/mds/mdstypes.h
src/messages/MClientReply.h
src/test/encoding/types.h
src/tools/cephfs/Dumper.cc

index 1cd2ddb84910f66c4ae30d44f15522eef24f625f..538788ed64dd543d5cd4fcf42715bffce23ad6c9 100644 (file)
@@ -30,6 +30,7 @@ libcommon_internal_la_SOURCES = \
        common/MemoryModel.cc \
        common/armor.c \
        common/fd.cc \
+       common/fs_types.cc \
        common/safe_io.c \
        common/snap_types.cc \
        common/str_list.cc \
diff --git a/src/common/fs_types.cc b/src/common/fs_types.cc
new file mode 100644 (file)
index 0000000..72a0ddf
--- /dev/null
@@ -0,0 +1,117 @@
+
+#include "include/fs_types.h"
+#include "common/Formatter.h"
+#include "include/ceph_features.h"
+
+void dump(const ceph_file_layout& l, Formatter *f)
+{
+  f->dump_unsigned("stripe_unit", l.fl_stripe_unit);
+  f->dump_unsigned("stripe_count", l.fl_stripe_count);
+  f->dump_unsigned("object_size", l.fl_object_size);
+  if (l.fl_cas_hash)
+    f->dump_unsigned("cas_hash", l.fl_cas_hash);
+  if (l.fl_object_stripe_unit)
+    f->dump_unsigned("object_stripe_unit", l.fl_object_stripe_unit);
+  if (l.fl_pg_pool)
+    f->dump_unsigned("pg_pool", l.fl_pg_pool);
+}
+
+void dump(const ceph_dir_layout& l, Formatter *f)
+{
+  f->dump_unsigned("dir_hash", l.dl_dir_hash);
+}
+
+
+// file_layout_t
+
+bool file_layout_t::is_valid() const
+{
+  /* stripe unit, object size must be non-zero, 64k increment */
+  if (!stripe_unit || (stripe_unit & (CEPH_MIN_STRIPE_UNIT-1)))
+    return false;
+  if (!object_size || (object_size & (CEPH_MIN_STRIPE_UNIT-1)))
+    return false;
+  /* object size must be a multiple of stripe unit */
+  if (object_size < stripe_unit || object_size % stripe_unit)
+    return false;
+  /* stripe count must be non-zero */
+  if (!stripe_count)
+    return false;
+  return true;
+}
+
+void file_layout_t::from_legacy(const ceph_file_layout& fl)
+{
+  stripe_unit = fl.fl_stripe_unit;
+  stripe_count = fl.fl_stripe_count;
+  object_size = fl.fl_object_size;
+  pool_id = (int32_t)fl.fl_pg_pool;
+  pool_ns.clear();
+}
+
+void file_layout_t::to_legacy(ceph_file_layout *fl) const
+{
+  fl->fl_stripe_unit = stripe_unit;
+  fl->fl_stripe_count = stripe_count;
+  fl->fl_object_size = object_size;
+  fl->fl_cas_hash = 0;
+  fl->fl_object_stripe_unit = 0;
+  fl->fl_unused = 0;
+  fl->fl_pg_pool = pool_id;
+}
+
+void file_layout_t::encode(bufferlist& bl, uint64_t features) const
+{
+  if ((features & CEPH_FEATURE_FS_FILE_LAYOUT_V2) == 0) {
+    ceph_file_layout fl;
+    assert((stripe_unit & 0xff) == 0);  // first byte must be 0
+    to_legacy(&fl);
+    ::encode(fl, bl);
+    return;
+  }
+
+  ENCODE_START(2, 2, bl);
+  ::encode(stripe_unit, bl);
+  ::encode(stripe_count, bl);
+  ::encode(object_size, bl);
+  ::encode(pool_id, bl);
+  ::encode(pool_ns, bl);
+  ENCODE_FINISH(bl);
+}
+
+void file_layout_t::decode(bufferlist::iterator& p)
+{
+  if (*p == 0) {
+    ceph_file_layout fl;
+    ::decode(fl, p);
+    from_legacy(fl);
+    return;
+  }
+  DECODE_START(2, p);
+  ::decode(stripe_unit, p);
+  ::decode(stripe_count, p);
+  ::decode(object_size, p);
+  ::decode(pool_id, p);
+  ::decode(pool_ns, p);
+  DECODE_FINISH(p);
+}
+
+void file_layout_t::dump(Formatter *f) const
+{
+  f->dump_unsigned("stripe_unit", stripe_unit);
+  f->dump_unsigned("stripe_count", stripe_count);
+  f->dump_unsigned("object_size", object_size);
+  f->dump_unsigned("pool_id", pool_id);
+  f->dump_string("pool_ns", pool_ns);
+}
+
+void file_layout_t::generate_test_instances(list<file_layout_t*>& o)
+{
+  o.push_back(new file_layout_t);
+  o.push_back(new file_layout_t);
+  o.back()->stripe_unit = 4096;
+  o.back()->stripe_count = 16;
+  o.back()->object_size = 1048576;
+  o.back()->pool_id = 3;
+  o.back()->pool_ns = "myns";
+}
index 76d5c535097f55245ef68ef72e65c30cdc0624c7..af0d02527612e32600fe5a55fcf34aa39b05c899 100644 (file)
@@ -2,6 +2,7 @@
 #define __CEPH_SNAP_TYPES_H
 
 #include "include/types.h"
+#include "include/fs_types.h"
 
 namespace ceph {
 
index 1224c1ea1138ccbeba5a7ee2aa2a83650f894ae0..d17605fb173485ee9395c01a4baab23288e3c0d6 100644 (file)
@@ -80,6 +80,7 @@ noinst_HEADERS += \
        include/error.h \
        include/filepath.h \
        include/frag.h \
+       include/fs_types.h \
        include/hash.h \
        include/inline_memory.h \
        include/intarith.h \
index 2b22378c2c6ffe15c2754685c6ea95a29c038fc9..1513e9d54e101863dc48b9c53b2df18ef67c3add 100755 (executable)
@@ -76,7 +76,8 @@
 #define CEPH_FEATURE_SERVER_JEWEL (1ULL<<57)   /* overlap, features introduced in jewel */
 #define CEPH_FEATURE_CRUSH_TUNABLES5   (1ULL<<58) /* chooseleaf stable mode */
 // duplicated since it was introduced at the same time as CEPH_FEATURE_CRUSH_TUNABLES5
-#define CEPH_FEATURE_NEW_OSDOPREPLY_ENCODING   (1ULL<<58) /* New, v7 encoding */
+#define CEPH_FEATURE_NEW_OSDOPREPLY_ENCODING (1ULL<<58) /* New, v7 encoding */
+#define CEPH_FEATURE_FS_FILE_LAYOUT_V2       (1ULL<<58) /* file_layout_t */
 
 #define CEPH_FEATURE_RESERVED2 (1ULL<<61)  /* slow down, we are almost out... */
 #define CEPH_FEATURE_RESERVED  (1ULL<<62)  /* DO NOT USE THIS ... last bit! */
index f7318470011e7757b4bafdd09ca9a825cd8581e8..15c3783f03af796918bd2ebcec0ead5dbd7109d1 100644 (file)
@@ -31,6 +31,7 @@ using namespace std;
 #include "buffer.h"
 #include "encoding.h"
 #include "include/types.h"
+#include "include/fs_types.h"
 
 #include "common/Formatter.h"
 
diff --git a/src/include/fs_types.h b/src/include/fs_types.h
new file mode 100644 (file)
index 0000000..bc5ef20
--- /dev/null
@@ -0,0 +1,104 @@
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+// vim: ts=8 sw=2 smarttab
+#ifndef CEPH_INCLUDE_FS_TYPES_H
+#define CEPH_INCLUDE_FS_TYPES_H
+
+#include "types.h"
+#include "utime.h"
+
+// --------------------------------------
+// ino
+
+typedef uint64_t _inodeno_t;
+
+struct inodeno_t {
+  _inodeno_t val;
+  inodeno_t() : val(0) {}
+  // cppcheck-suppress noExplicitConstructor
+  inodeno_t(_inodeno_t v) : val(v) {}
+  inodeno_t operator+=(inodeno_t o) { val += o.val; return *this; }
+  operator _inodeno_t() const { return val; }
+
+  void encode(bufferlist& bl) const {
+    ::encode(val, bl);
+  }
+  void decode(bufferlist::iterator& p) {
+    ::decode(val, p);
+  }
+} __attribute__ ((__may_alias__));
+WRITE_CLASS_ENCODER(inodeno_t)
+
+inline ostream& operator<<(ostream& out, inodeno_t ino) {
+  return out << hex << ino.val << dec;
+}
+
+namespace std {
+  template<> struct hash< inodeno_t >
+  {
+    size_t operator()( const inodeno_t& x ) const
+    {
+      static rjhash<uint64_t> H;
+      return H(x.val);
+    }
+  };
+} // namespace std
+
+
+// file modes
+
+static inline bool file_mode_is_readonly(int mode) {
+  return (mode & CEPH_FILE_MODE_WR) == 0;
+}
+
+
+// dentries
+#define MAX_DENTRY_LEN 255
+
+// --
+namespace ceph {
+  class Formatter;
+}
+void dump(const ceph_file_layout& l, ceph::Formatter *f);
+void dump(const ceph_dir_layout& l, ceph::Formatter *f);
+
+
+
+// file_layout_t
+
+struct file_layout_t {
+  // file -> object mapping
+  uint32_t stripe_unit;   ///< stripe unit, in bytes,
+  uint32_t stripe_count;  ///< over this many objects
+  uint32_t object_size;   ///< until objects are this big
+
+  int64_t pool_id;        ///< rados pool id
+  string pool_ns;         ///< rados pool namespace
+
+  file_layout_t(uint32_t su=0, uint32_t sc=0, uint32_t os=0)
+    : stripe_unit(su),
+      stripe_count(sc),
+      object_size(os),
+      pool_id(-1) {
+  }
+
+  static file_layout_t get_default() {
+    return file_layout_t(1<<22, 1, 1<<22);
+  }
+
+  uint64_t get_period() const {
+    return stripe_count * object_size;
+  }
+
+  void from_legacy(const ceph_file_layout& fl);
+  void to_legacy(ceph_file_layout *fl) const;
+
+  bool is_valid() const;
+
+  void encode(bufferlist& bl, uint64_t features) const;
+  void decode(bufferlist::iterator& p);
+  void dump(Formatter *f) const;
+  static void generate_test_instances(list<file_layout_t*>& o);
+};
+WRITE_CLASS_ENCODER_FEATURES(file_layout_t)
+
+#endif
index 8e35ba0f5a7c31a111371055b13cfd6fb2a49dfd..92fb8ca6bb44ee782a28e9610c05d10b4c206e7a 100644 (file)
@@ -311,62 +311,6 @@ inline ostream& operator<<(ostream& out, const client_t& c) {
 
 
 
-// --------------------------------------
-// ino
-
-typedef uint64_t _inodeno_t;
-
-struct inodeno_t {
-  _inodeno_t val;
-  inodeno_t() : val(0) {}
-  // cppcheck-suppress noExplicitConstructor
-  inodeno_t(_inodeno_t v) : val(v) {}
-  inodeno_t operator+=(inodeno_t o) { val += o.val; return *this; }
-  operator _inodeno_t() const { return val; }
-
-  void encode(bufferlist& bl) const {
-    ::encode(val, bl);
-  }
-  void decode(bufferlist::iterator& p) {
-    ::decode(val, p);
-  }
-} __attribute__ ((__may_alias__));
-WRITE_CLASS_ENCODER(inodeno_t)
-
-inline ostream& operator<<(ostream& out, inodeno_t ino) {
-  return out << hex << ino.val << dec;
-}
-
-namespace std {
-  template<> struct hash< inodeno_t >
-  {
-    size_t operator()( const inodeno_t& x ) const
-    {
-      static rjhash<uint64_t> H;
-      return H(x.val);
-    }
-  };
-} // namespace std
-
-
-// file modes
-
-static inline bool file_mode_is_readonly(int mode) {
-  return (mode & CEPH_FILE_MODE_WR) == 0;
-}
-
-
-// dentries
-#define MAX_DENTRY_LEN 255
-
-// --
-namespace ceph {
-  class Formatter;
-}
-void dump(const ceph_file_layout& l, ceph::Formatter *f);
-void dump(const ceph_dir_layout& l, ceph::Formatter *f);
-
-
 // --
 
 struct prettybyte_t {
index 08879c32a0967a0e7a9bc10ef6df8bc9da805981..20ce63a001b4d526009cf74e8a3a22e5f359f4c6 100644 (file)
@@ -7,24 +7,6 @@
 const mds_gid_t MDS_GID_NONE = mds_gid_t(0);
 const mds_rank_t MDS_RANK_NONE = mds_rank_t(-1);
 
-void dump(const ceph_file_layout& l, Formatter *f)
-{
-  f->dump_unsigned("stripe_unit", l.fl_stripe_unit);
-  f->dump_unsigned("stripe_count", l.fl_stripe_count);
-  f->dump_unsigned("object_size", l.fl_object_size);
-  if (l.fl_cas_hash)
-    f->dump_unsigned("cas_hash", l.fl_cas_hash);
-  if (l.fl_object_stripe_unit)
-    f->dump_unsigned("object_stripe_unit", l.fl_object_stripe_unit);
-  if (l.fl_pg_pool)
-    f->dump_unsigned("pg_pool", l.fl_pg_pool);
-}
-
-void dump(const ceph_dir_layout& l, Formatter *f)
-{
-  f->dump_unsigned("dir_hash", l.dl_dir_hash);
-}
-
 
 /*
  * frag_info_t
index a5300524a7f964e492e322e1401705c945604104..5ac957a38b210820ed824c9870a6c7bb161be1c5 100644 (file)
@@ -21,6 +21,7 @@
 #include "include/interval_set.h"
 #include "include/compact_map.h"
 #include "include/compact_set.h"
+#include "include/fs_types.h"
 
 #include "inode_backtrace.h"
 
index d3ee05e9537b75240778dc8bd2cbb0561e5354fc..e89d412cdf9507bc5a7e59c156df7b80365edc61 100644 (file)
@@ -17,6 +17,7 @@
 #define CEPH_MCLIENTREPLY_H
 
 #include "include/types.h"
+#include "include/fs_types.h"
 #include "MClientRequest.h"
 
 #include "msg/Message.h"
index 4ffab8743cba30f29fd2c74c1dddef456bde4670..2668f0b01408f0d5fece60a5018617506158f8a7 100644 (file)
@@ -181,6 +181,9 @@ TYPE(cap_reconnect_t)
 TYPE(inode_backtrace_t)
 TYPE(inode_backpointer_t)
 TYPE(quota_info_t)
+
+#include "include/fs_types.h"
+TYPE_FEATUREFUL(file_layout_t)
 TYPE(ceph_file_layout_wrapper)
 
 #include "mds/CInode.h"
index 1abd74c70ec61c4f837ac479d714c4eb2bc2f5e8..02e1202d89d91567fc814ecafa7892fcb7e0fc9c 100644 (file)
@@ -17,6 +17,7 @@
 #endif
 
 #include "include/compat.h"
+#include "include/fs_types.h"
 #include "common/entity_name.h"
 #include "common/errno.h"
 #include "common/safe_io.h"