1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 #include "include/fs_types.h"
5 #include "common/Formatter.h"
6 #include "include/ceph_features.h"
7 #include "common/ceph_json.h"
9 void dump(const ceph_file_layout
& l
, ceph::Formatter
*f
)
11 f
->dump_unsigned("stripe_unit", l
.fl_stripe_unit
);
12 f
->dump_unsigned("stripe_count", l
.fl_stripe_count
);
13 f
->dump_unsigned("object_size", l
.fl_object_size
);
15 f
->dump_unsigned("cas_hash", l
.fl_cas_hash
);
16 if (l
.fl_object_stripe_unit
)
17 f
->dump_unsigned("object_stripe_unit", l
.fl_object_stripe_unit
);
19 f
->dump_unsigned("pg_pool", l
.fl_pg_pool
);
22 void dump(const ceph_dir_layout
& l
, ceph::Formatter
*f
)
24 f
->dump_unsigned("dir_hash", l
.dl_dir_hash
);
25 f
->dump_unsigned("unused1", l
.dl_unused1
);
26 f
->dump_unsigned("unused2", l
.dl_unused2
);
27 f
->dump_unsigned("unused3", l
.dl_unused3
);
33 bool file_layout_t::is_valid() const
35 /* stripe unit, object size must be non-zero, 64k increment */
36 if (!stripe_unit
|| (stripe_unit
& (CEPH_MIN_STRIPE_UNIT
-1)))
38 if (!object_size
|| (object_size
& (CEPH_MIN_STRIPE_UNIT
-1)))
40 /* object size must be a multiple of stripe unit */
41 if (object_size
< stripe_unit
|| object_size
% stripe_unit
)
43 /* stripe count must be non-zero */
49 void file_layout_t::from_legacy(const ceph_file_layout
& fl
)
51 stripe_unit
= fl
.fl_stripe_unit
;
52 stripe_count
= fl
.fl_stripe_count
;
53 object_size
= fl
.fl_object_size
;
54 pool_id
= (int32_t)fl
.fl_pg_pool
;
55 // in the legacy encoding, a zeroed structure was the default and
56 // would have pool 0 instead of -1.
57 if (pool_id
== 0 && stripe_unit
== 0 && stripe_count
== 0 && object_size
== 0)
62 void file_layout_t::to_legacy(ceph_file_layout
*fl
) const
64 fl
->fl_stripe_unit
= stripe_unit
;
65 fl
->fl_stripe_count
= stripe_count
;
66 fl
->fl_object_size
= object_size
;
68 fl
->fl_object_stripe_unit
= 0;
70 // in the legacy encoding, pool 0 was undefined.
72 fl
->fl_pg_pool
= pool_id
;
77 void file_layout_t::encode(ceph::buffer::list
& bl
, uint64_t features
) const
80 if ((features
& CEPH_FEATURE_FS_FILE_LAYOUT_V2
) == 0) {
82 ceph_assert((stripe_unit
& 0xff) == 0); // first byte must be 0
88 ENCODE_START(2, 2, bl
);
89 encode(stripe_unit
, bl
);
90 encode(stripe_count
, bl
);
91 encode(object_size
, bl
);
97 void file_layout_t::decode(ceph::buffer::list::const_iterator
& p
)
107 decode(stripe_unit
, p
);
108 decode(stripe_count
, p
);
109 decode(object_size
, p
);
115 void file_layout_t::dump(ceph::Formatter
*f
) const
117 f
->dump_unsigned("stripe_unit", stripe_unit
);
118 f
->dump_unsigned("stripe_count", stripe_count
);
119 f
->dump_unsigned("object_size", object_size
);
120 f
->dump_int("pool_id", pool_id
);
121 f
->dump_string("pool_ns", pool_ns
);
124 void file_layout_t::decode_json(JSONObj
*obj
){
126 JSONDecoder::decode_json("stripe_unit", stripe_unit
, obj
, true);
127 JSONDecoder::decode_json("stripe_count", stripe_count
, obj
, true);
128 JSONDecoder::decode_json("object_size", object_size
, obj
, true);
129 JSONDecoder::decode_json("pool_id", pool_id
, obj
, true);
130 JSONDecoder::decode_json("pool_ns", pool_ns
, obj
, true);
133 void file_layout_t::generate_test_instances(std::list
<file_layout_t
*>& o
)
135 o
.push_back(new file_layout_t
);
136 o
.push_back(new file_layout_t
);
137 o
.back()->stripe_unit
= 4096;
138 o
.back()->stripe_count
= 16;
139 o
.back()->object_size
= 1048576;
140 o
.back()->pool_id
= 3;
141 o
.back()->pool_ns
= "myns";
144 std::ostream
& operator<<(std::ostream
& out
, const file_layout_t
&layout
)
146 ceph::JSONFormatter f
;