Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/common/strtol.cc
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,9 @@ T strict_iec_cast(std::string_view str, std::string *err)
// handling cases when prefixes entered as KB, MB, ...
// and KiB, MiB, ....
if (unit.length() > 1 && unit.back() == 'B') {
if (unit.front() != 'B') {
unit = unit.substr(0, unit.length() - 1);
}
}
// we accept both old si prefixes as well as the proper iec prefixes
// i.e. K, M, ... and Ki, Mi, ...
Expand Down
71 changes: 63 additions & 8 deletions src/mds/Server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6110,6 +6110,58 @@ int Server::parse_layout_vxattr(string name, string value, const OSDMap& osdmap,
return 0;
}

int64_t Server::make_quota_max_byte_parseable(string val)
{
string before_decimal;
string after_decimal;
int64_t dec_len;
int64_t q;
string cast_err;
string unit;

size_t dec_index = val.find_first_of(".");
size_t unit_index = val.find_first_of("ABCDEFGHIJKLMNOPQRSTUVWXYZ");

if (dec_index != std::string::npos) {
if (unit_index == std::string::npos) {
dout(10) << __func__ << ": failed to parse quota.max_bytes: "
<< "Invalid Byte value" << dendl;
return -EINVAL;
}
unit = val.substr(unit_index, val.length() - unit_index);
if (unit == "B") {
dout(10) << __func__ << ": failed to parse quota.max_bytes: "
<< "Invalid Byte value" << dendl;
return -EINVAL;
}
}

dec_len = unit_index - dec_index - 1;
if ((dec_len == 0) || (dec_index == val.length() - 1) ||
(dec_index != val.find_last_of("."))) {
dout(10) << __func__ << ": failed to parse quota.max_bytes: "
<< "Invalid Float value" << dendl;
return -EINVAL;
}

if (dec_index != std::string::npos) {
before_decimal = val.substr(0, dec_index);
after_decimal = val.substr(dec_index + 1, val.length() - dec_index - 1);
before_decimal.append(after_decimal);
q = strict_iec_cast<int64_t>(before_decimal, &cast_err);
q = q / (std::pow(10, dec_len));
Comment thread
neesingh-rh marked this conversation as resolved.
Resolved
}
else {
q = strict_iec_cast<int64_t>(val, &cast_err);
}
if(!cast_err.empty()) {
dout(10) << __func__ << ": failed to parse quota.max_bytes: "
<< cast_err << dendl;
q = -EINVAL;
}
return q;
}

int Server::parse_quota_vxattr(string name, string value, quota_info_t *quota)
{
dout(20) << "parse_quota_vxattr name " << name << " value '" << value << "'" << dendl;
Expand All @@ -6136,14 +6188,17 @@ int Server::parse_quota_vxattr(string name, string value, quota_info_t *quota)
return r;
}
} else if (name == "quota.max_bytes") {
string cast_err;
int64_t q = strict_iec_cast<int64_t>(value, &cast_err);
if(!cast_err.empty()) {
dout(10) << __func__ << ": failed to parse quota.max_bytes: "
<< cast_err << dendl;
return -EINVAL;
}
quota->max_bytes = q;
std::string *err;
int64_t res = make_quota_max_byte_parseable(value);
if(res == -EINVAL) {
ostringstream oss;
oss << "Invalid Input/Suffix '";
*err = oss.str();
//respond_to_request(mdr, "Invalid input/suffix");
//derr << __func__ << "Invalid input" << value << dendl;
return 0;
}
quota->max_bytes = res;
} else if (name == "quota.max_files") {
int64_t q = boost::lexical_cast<int64_t>(value);
if (q < 0)
Expand Down
1 change: 1 addition & 0 deletions src/mds/Server.h
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ class Server {
void handle_client_setlayout(const MDRequestRef& mdr);
void handle_client_setdirlayout(const MDRequestRef& mdr);

int64_t make_quota_max_byte_parseable(std::string val);
int parse_quota_vxattr(std::string name, std::string value, quota_info_t *quota);
void create_quota_realm(CInode *in);
int parse_layout_vxattr_json(std::string name, std::string value,
Expand Down
Loading