Skip to content

Commit

Permalink
Merge PR ceph#22211 into master
Browse files Browse the repository at this point in the history
* refs/pull/22211/head:
	cephfs-journal-tool: get and check layout info during dump/undump

Reviewed-by: Patrick Donnelly <pdonnell@redhat.com>
Reviewed-by: Zheng Yan <zyan@redhat.com>
  • Loading branch information
batrick committed Jul 15, 2018
2 parents 37b085c + 989ecf2 commit a2cb12c
Showing 1 changed file with 48 additions and 4 deletions.
52 changes: 48 additions & 4 deletions src/tools/cephfs/Dumper.cc
Expand Up @@ -112,13 +112,19 @@ int Dumper::dump(const char *dump_file)
fsid.print(fsid_str);
char buf[HEADER_LEN];
memset(buf, 0, sizeof(buf));
snprintf(buf, HEADER_LEN, "Ceph mds%d journal dump\n start offset %llu (0x%llx)\n length %llu (0x%llx)\n write_pos %llu (0x%llx)\n format %llu\n trimmed_pos %llu (0x%llx)\n fsid %s\n%c",
snprintf(buf, HEADER_LEN, "Ceph mds%d journal dump\n start offset %llu (0x%llx)\n\
length %llu (0x%llx)\n write_pos %llu (0x%llx)\n format %llu\n\
trimmed_pos %llu (0x%llx)\n stripe_unit %lu (0x%lx)\n stripe_count %lu (0x%lx)\n\
object_size %lu (0x%lx)\n fsid %s\n%c",
role.rank,
(unsigned long long)start, (unsigned long long)start,
(unsigned long long)len, (unsigned long long)len,
(unsigned long long)journaler.last_committed.write_pos, (unsigned long long)journaler.last_committed.write_pos,
(unsigned long long)journaler.last_committed.stream_format,
(unsigned long long)journaler.last_committed.trimmed_pos, (unsigned long long)journaler.last_committed.trimmed_pos,
(unsigned long)journaler.last_committed.layout.stripe_unit, (unsigned long)journaler.last_committed.layout.stripe_unit,
(unsigned long)journaler.last_committed.layout.stripe_count, (unsigned long)journaler.last_committed.layout.stripe_count,
(unsigned long)journaler.last_committed.layout.object_size, (unsigned long)journaler.last_committed.layout.object_size,
fsid_str,
4);
r = safe_write(fd, buf, sizeof(buf));
Expand Down Expand Up @@ -198,6 +204,15 @@ int Dumper::undump(const char *dump_file, bool force)
assert(fs != nullptr);

int r = 0;
// try get layout info from cluster
Journaler journaler("umdumper", ino, fs->mds_map.get_metadata_pool(),
CEPH_FS_ONDISK_MAGIC, objecter, 0, 0,
&finisher);
int recovered = recover_journal(&journaler);
if (recovered != 0) {
derr << "recover_journal failed, try to get header from dump file " << dendl;
}

int fd = ::open(dump_file, O_RDONLY);
if (fd < 0) {
r = errno;
Expand All @@ -217,6 +232,7 @@ int Dumper::undump(const char *dump_file, bool force)
}

long long unsigned start, len, write_pos, format, trimmed_pos;
long unsigned stripe_unit, stripe_count, object_size;
sscanf(strstr(buf, "start offset"), "start offset %llu", &start);
sscanf(strstr(buf, "length"), "length %llu", &len);
sscanf(strstr(buf, "write_pos"), "write_pos %llu", &write_pos);
Expand Down Expand Up @@ -248,12 +264,35 @@ int Dumper::undump(const char *dump_file, bool force)
}
}

if (recovered == 0) {
stripe_unit = journaler.last_committed.layout.stripe_unit;
stripe_count = journaler.last_committed.layout.stripe_count;
object_size = journaler.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);
} 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);
} 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);
} else {
object_size = file_layout_t::get_default().object_size;
}
}

if (strstr(buf, "trimmed_pos")) {
sscanf(strstr(buf, "trimmed_pos"), "trimmed_pos %llu", &trimmed_pos);
} else {
// Old format dump, any untrimmed objects before expire_pos will
// be discarded as trash.
trimmed_pos = start - (start % file_layout_t::get_default().object_size);
trimmed_pos = start - (start % object_size);
}

if (trimmed_pos > start) {
Expand All @@ -274,7 +313,10 @@ int Dumper::undump(const char *dump_file, bool force)
" len " << len <<
" write_pos " << write_pos <<
" format " << format <<
" trimmed_pos " << trimmed_pos << std::endl;
" trimmed_pos " << trimmed_pos <<
" stripe_unit " << stripe_unit <<
" stripe_count " << stripe_count <<
" object_size " << object_size << std::endl;

Journaler::Header h;
h.trimmed_pos = trimmed_pos;
Expand All @@ -283,7 +325,9 @@ int Dumper::undump(const char *dump_file, bool force)
h.stream_format = format;
h.magic = CEPH_FS_ONDISK_MAGIC;

h.layout = file_layout_t::get_default();
h.layout.stripe_unit = stripe_unit;
h.layout.stripe_count = stripe_count;
h.layout.object_size = object_size;
h.layout.pool_id = fs->mds_map.get_metadata_pool();

bufferlist hbl;
Expand Down

0 comments on commit a2cb12c

Please sign in to comment.