2 #include "include/fs_types.h"
3 #include "common/Formatter.h"
4 #include "include/ceph_features.h"
6 void dump(const ceph_file_layout& l, Formatter *f)
8 f->dump_unsigned("stripe_unit", l.fl_stripe_unit);
9 f->dump_unsigned("stripe_count", l.fl_stripe_count);
10 f->dump_unsigned("object_size", l.fl_object_size);
12 f->dump_unsigned("cas_hash", l.fl_cas_hash);
13 if (l.fl_object_stripe_unit)
14 f->dump_unsigned("object_stripe_unit", l.fl_object_stripe_unit);
16 f->dump_unsigned("pg_pool", l.fl_pg_pool);
19 void dump(const ceph_dir_layout& l, Formatter *f)
21 f->dump_unsigned("dir_hash", l.dl_dir_hash);
27 bool file_layout_t::is_valid() const
29 /* stripe unit, object size must be non-zero, 64k increment */
30 if (!stripe_unit || (stripe_unit & (CEPH_MIN_STRIPE_UNIT-1)))
32 if (!object_size || (object_size & (CEPH_MIN_STRIPE_UNIT-1)))
34 /* object size must be a multiple of stripe unit */
35 if (object_size < stripe_unit || object_size % stripe_unit)
37 /* stripe count must be non-zero */
43 void file_layout_t::from_legacy(const ceph_file_layout& fl)
45 stripe_unit = fl.fl_stripe_unit;
46 stripe_count = fl.fl_stripe_count;
47 object_size = fl.fl_object_size;
48 pool_id = (int32_t)fl.fl_pg_pool;
49 // in the legacy encoding, a zeroed structure was the default and
50 // would have pool 0 instead of -1.
51 if (pool_id == 0 && stripe_unit == 0 && stripe_count == 0 && object_size == 0)
56 void file_layout_t::to_legacy(ceph_file_layout *fl) const
58 fl->fl_stripe_unit = stripe_unit;
59 fl->fl_stripe_count = stripe_count;
60 fl->fl_object_size = object_size;
62 fl->fl_object_stripe_unit = 0;
64 // in the legacy encoding, pool 0 was undefined.
66 fl->fl_pg_pool = pool_id;
71 void file_layout_t::encode(bufferlist& bl, uint64_t features) const
73 if ((features & CEPH_FEATURE_FS_FILE_LAYOUT_V2) == 0) {
75 assert((stripe_unit & 0xff) == 0); // first byte must be 0
81 ENCODE_START(2, 2, bl);
82 ::encode(stripe_unit, bl);
83 ::encode(stripe_count, bl);
84 ::encode(object_size, bl);
85 ::encode(pool_id, bl);
86 ::encode(pool_ns, bl);
90 void file_layout_t::decode(bufferlist::iterator& p)
99 ::decode(stripe_unit, p);
100 ::decode(stripe_count, p);
101 ::decode(object_size, p);
102 ::decode(pool_id, p);
103 ::decode(pool_ns, p);
107 void file_layout_t::dump(Formatter *f) const
109 f->dump_unsigned("stripe_unit", stripe_unit);
110 f->dump_unsigned("stripe_count", stripe_count);
111 f->dump_unsigned("object_size", object_size);
112 f->dump_int("pool_id", pool_id);
113 f->dump_string("pool_ns", pool_ns);
116 void file_layout_t::generate_test_instances(list<file_layout_t*>& o)
118 o.push_back(new file_layout_t);
119 o.push_back(new file_layout_t);
120 o.back()->stripe_unit = 4096;
121 o.back()->stripe_count = 16;
122 o.back()->object_size = 1048576;
123 o.back()->pool_id = 3;
124 o.back()->pool_ns = "myns";
127 ostream& operator<<(ostream& out, const file_layout_t &layout)