Skip to content

Commit

Permalink
cephfs: define and initial worm file attribute info
Browse files Browse the repository at this point in the history
Signed-off-by: Wei Qiaomiao <wei.qiaomiao@zte.com.cn>
  • Loading branch information
weiqiaomiao committed Mar 16, 2019
1 parent e9491ee commit 58fd92a
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 0 deletions.
Empty file modified src/common/legacy_config_opts.h
100644 → 100755
Empty file.
24 changes: 24 additions & 0 deletions src/common/options.cc
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,11 @@ constexpr unsigned long long operator"" _hr (unsigned long long hr) {
constexpr unsigned long long operator"" _day (unsigned long long day) {
return day * 60 * 60 * 24;
}

constexpr unsigned long long operator"" _year (unsigned long long year) {
return year * 60 * 60 * 24 * 365;
}

constexpr unsigned long long operator"" _K (unsigned long long n) {
return n << 10;
}
Expand Down Expand Up @@ -7882,6 +7887,25 @@ std::vector<Option> get_mds_options() {
.set_default(0)
.set_description("threshold for cache usage to disallow \"dump cache\" operation to file")
.set_long_description("Disallow MDS from dumping caches to file via \"dump cache\" command if cache usage exceeds this threshold."),

Option("mds_worm_commit_period", Option::TYPE_UINT, Option::LEVEL_ADVANCED)
.set_default(2_hr)
.set_min_max(1_min, 30_day)
.set_description("default auto commit period for worm feature"),

Option("mds_worm_retention_period", Option::TYPE_UINT, Option::LEVEL_ADVANCED)
.set_default(1_hr)
.set_description("default retention period for worm feature,this value must between mds_worm_min_retention_period and mds_worm_max_retention_period"),

Option("mds_worm_min_retention_period", Option::TYPE_UINT, Option::LEVEL_ADVANCED)
.set_default(1_hr)
.set_min_max(1_min, 30_year)
.set_description("min retention period for worm feature"),

Option("mds_worm_max_retention_period", Option::TYPE_UINT, Option::LEVEL_ADVANCED)
.set_default(30_year)
.set_min_max(1_hr, 70_year)
.set_description("max retention period for worm feature"),
});
}

Expand Down
82 changes: 82 additions & 0 deletions src/mds/mdstypes.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,13 @@
#define MDS_TRAVERSE_DISCOVER 2 // skips permissions checks etc.
#define MDS_TRAVERSE_DISCOVERXLOCK 3 // succeeds on (foreign?) null, xlocked dentries.

#define WORM_ENABLE 1
#define WORM_IS_ROOT 2
#define WORM_RETAIN 4
#define WORM_EXPIRE 8
#define WORM_RETEN_PERIOD_ULIMIT 16
#define MAX_MIN_RETEN_PERIOD 946080000 // 30 years
#define MIN_MAX_RETEN_PERIOD 2207520000 // 70 years

typedef int32_t mds_rank_t;
constexpr mds_rank_t MDS_RANK_NONE = -1;
Expand Down Expand Up @@ -378,6 +385,81 @@ inline std::ostream& operator<<(std::ostream &out, const vinodeno_t &vino) {
}


/*
* worm_info_t
*/
struct worm_info_t {
uint32_t worm_state;
uint32_t auto_commit_period;
uint32_t retention_period ;
uint32_t min_retention_period;
uint32_t max_retention_period;

worm_info_t() {
worm_state = 0;
auto_commit_period = 0;
retention_period = 0;
min_retention_period = 0;
max_retention_period = 0;
}

void encode(bufferlist& bl) const {
ENCODE_START(1, 1, bl);
encode(worm_state, bl);
encode(auto_commit_period, bl);
encode(retention_period, bl);
encode(min_retention_period, bl);
encode(max_retention_period, bl);
ENCODE_FINISH(bl);
}
void decode(bufferlist::const_iterator& bl) {
DECODE_START(1, bl);
decode(worm_state, bl);
decode(auto_commit_period, bl);
decode(retention_period, bl);
decode(min_retention_period, bl);
decode(max_retention_period, bl);
DECODE_FINISH(bl);
}

bool is_valid() const {
return (auto_commit_period > 0 && retention_period >= min_retention_period
&& retention_period <= max_retention_period && min_retention_period <= max_retention_period);
}

bool is_root() const {
return (worm_state & WORM_IS_ROOT) == WORM_IS_ROOT;
}

bool is_enable() const {
return (worm_state & WORM_ENABLE) == WORM_ENABLE;
}

bool is_expire() const {
return (worm_state & WORM_EXPIRE) == WORM_EXPIRE;
}

bool is_retain() const {
return (worm_state & WORM_RETAIN) == WORM_RETAIN;
}

bool is_reten_period_ulimit() const {
return (worm_state & WORM_RETEN_PERIOD_ULIMIT) == WORM_RETEN_PERIOD_ULIMIT;
}

};

WRITE_CLASS_ENCODER(worm_info_t)

inline std::ostream& operator<<(std::ostream &out, const worm_info_t &worm){
return out << "state(" << worm.worm_state << ")," <<
"retention_period(" << worm.retention_period << ")," <<
"auto_commit_period(" << worm.auto_commit_period << ")" <<
"min_retention_period(" << worm.min_retention_period << ")" <<
"max_retention_period(" << worm.max_retention_period << ")";
}


/*
* client_writeable_range_t
*/
Expand Down

0 comments on commit 58fd92a

Please sign in to comment.