}
if (recovered == 0) {
+ //Check if the headers are available in the dump file
+ if (!strstr(buf, "stripe_unit")) {
+ derr << "Invalid header, no 'stripe_unit' embedded" << dendl;
+ ::close(fd);
+ return -EINVAL;
+ } else if (!strstr(buf, "stripe_count")) {
+ derr << "Invalid header, no 'stripe_count' embedded" << dendl;
+ ::close(fd);
+ return -EINVAL;
+ } else if (!strstr(buf, "object_size")) {
+ derr << "Invalid header, no 'object_size' embedded" << dendl;
+ ::close(fd);
+ return -EINVAL;
+ }
auto&& last_committed = journaler.get_last_committed();
stripe_unit = last_committed.layout.stripe_unit;
stripe_count = last_committed.layout.stripe_count;
object_size = last_committed.layout.object_size;
} else {
// try to get layout from dump file header, if failed set layout to default
- if (strstr(buf, "stripe_unit")) {
- sscanf(strstr(buf, "stripe_unit"), "stripe_unit %lu", &stripe_unit);
+ char *p_stripe_unit = strstr(buf, "stripe_unit");
+ if (p_stripe_unit) {
+ sscanf(p_stripe_unit, "stripe_unit %lu", &stripe_unit);
} else {
stripe_unit = file_layout_t::get_default().stripe_unit;
}
- if (strstr(buf, "stripe_count")) {
- sscanf(strstr(buf, "stripe_count"), "stripe_count %lu", &stripe_count);
+ char *p_stripe_count = strstr(buf, "stripe_count");
+ if (p_stripe_count) {
+ sscanf(p_stripe_count, "stripe_count %lu", &stripe_count);
} else {
stripe_count = file_layout_t::get_default().stripe_count;
}
- if (strstr(buf, "object_size")) {
- sscanf(strstr(buf, "object_size"), "object_size %lu", &object_size);
+ char *p_object_size = strstr(buf, "object_size");
+ if (p_object_size) {
+ sscanf(p_object_size, "object_size %lu", &object_size);
} else {
object_size = file_layout_t::get_default().object_size;
}