From: Sage Weil Date: Tue, 10 Nov 2015 11:40:09 +0000 (-0500) Subject: add fs_types.h, with file_layout_t X-Git-Tag: v10.1.0~241^2~30 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=982208135cecfb3cc3cf317ebe54580a806c3e89;p=ceph.git add fs_types.h, with file_layout_t Signed-off-by: Sage Weil --- diff --git a/src/common/Makefile.am b/src/common/Makefile.am index 1cd2ddb84910..538788ed64dd 100644 --- a/src/common/Makefile.am +++ b/src/common/Makefile.am @@ -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 index 000000000000..72a0ddffc07c --- /dev/null +++ b/src/common/fs_types.cc @@ -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& 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"; +} diff --git a/src/common/snap_types.h b/src/common/snap_types.h index 76d5c535097f..af0d02527612 100644 --- a/src/common/snap_types.h +++ b/src/common/snap_types.h @@ -2,6 +2,7 @@ #define __CEPH_SNAP_TYPES_H #include "include/types.h" +#include "include/fs_types.h" namespace ceph { diff --git a/src/include/Makefile.am b/src/include/Makefile.am index 1224c1ea1138..d17605fb1734 100644 --- a/src/include/Makefile.am +++ b/src/include/Makefile.am @@ -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 \ diff --git a/src/include/ceph_features.h b/src/include/ceph_features.h index 2b22378c2c6f..1513e9d54e10 100755 --- a/src/include/ceph_features.h +++ b/src/include/ceph_features.h @@ -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! */ diff --git a/src/include/filepath.h b/src/include/filepath.h index f7318470011e..15c3783f03af 100644 --- a/src/include/filepath.h +++ b/src/include/filepath.h @@ -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 index 000000000000..bc5ef2040323 --- /dev/null +++ b/src/include/fs_types.h @@ -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 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& o); +}; +WRITE_CLASS_ENCODER_FEATURES(file_layout_t) + +#endif diff --git a/src/include/types.h b/src/include/types.h index 8e35ba0f5a7c..92fb8ca6bb44 100644 --- a/src/include/types.h +++ b/src/include/types.h @@ -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 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 { diff --git a/src/mds/mdstypes.cc b/src/mds/mdstypes.cc index 08879c32a096..20ce63a001b4 100644 --- a/src/mds/mdstypes.cc +++ b/src/mds/mdstypes.cc @@ -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 diff --git a/src/mds/mdstypes.h b/src/mds/mdstypes.h index a5300524a7f9..5ac957a38b21 100644 --- a/src/mds/mdstypes.h +++ b/src/mds/mdstypes.h @@ -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" diff --git a/src/messages/MClientReply.h b/src/messages/MClientReply.h index d3ee05e9537b..e89d412cdf95 100644 --- a/src/messages/MClientReply.h +++ b/src/messages/MClientReply.h @@ -17,6 +17,7 @@ #define CEPH_MCLIENTREPLY_H #include "include/types.h" +#include "include/fs_types.h" #include "MClientRequest.h" #include "msg/Message.h" diff --git a/src/test/encoding/types.h b/src/test/encoding/types.h index 4ffab8743cba..2668f0b01408 100644 --- a/src/test/encoding/types.h +++ b/src/test/encoding/types.h @@ -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" diff --git a/src/tools/cephfs/Dumper.cc b/src/tools/cephfs/Dumper.cc index 1abd74c70ec6..02e1202d89d9 100644 --- a/src/tools/cephfs/Dumper.cc +++ b/src/tools/cephfs/Dumper.cc @@ -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"