return check_output(cmd, stderr=nullfd).split()[3]
+# return a list of unique PGS given an osd subdirectory
+def get_osd_pgs(SUBDIR, ID):
+ PGS = []
+ if ID:
+ endhead = re.compile("{id}.*_head$".format(id=ID))
+ DIR = os.path.join(SUBDIR, "current")
+ PGS += [f for f in os.listdir(DIR) if os.path.isdir(os.path.join(DIR, f)) and (ID == None or endhead.match(f))]
+ PGS = [re.sub("_head", "", p) for p in PGS if "_head" in p]
+ return PGS
+
+
# return a sorted list of unique PGs given a directory
def get_pgs(DIR, ID):
OSDS = [f for f in os.listdir(DIR) if os.path.isdir(os.path.join(DIR, f)) and string.find(f, "osd") == 0]
PGS = []
- endhead = re.compile("{id}.*_head$".format(id=ID))
for d in OSDS:
- DIRL2 = os.path.join(DIR, d)
- SUBDIR = os.path.join(DIRL2, "current")
- PGS += [f for f in os.listdir(SUBDIR) if os.path.isdir(os.path.join(SUBDIR, f)) and endhead.match(f)]
- PGS = [re.sub("_head", "", p) for p in PGS]
+ SUBDIR = os.path.join(DIR, d)
+ PGS += get_osd_pgs(SUBDIR, ID)
return sorted(set(PGS))
except:
pass
+ print "Test list-pgs"
+ for osd in [f for f in os.listdir(OSDDIR) if os.path.isdir(os.path.join(OSDDIR, f)) and string.find(f, "osd") == 0]:
+
+ CHECK_PGS = get_osd_pgs(os.path.join(OSDDIR, osd), None)
+ CHECK_PGS = sorted(CHECK_PGS)
+
+ cmd = (CFSD_PREFIX + "--op list-pgs").format(osd=osd)
+ logging.debug(cmd)
+ TEST_PGS = check_output(cmd, shell=True).split("\n")
+ TEST_PGS = sorted(TEST_PGS)[1:] # Skip extra blank line
+
+ if TEST_PGS != CHECK_PGS:
+ logging.error("list-pgs got wrong result for osd.{osd}".format(osd=osd))
+ logging.error("Expected {pgs}".format(pgs=CHECK_PGS))
+ logging.error("Got {pgs}".format(pgs=TEST_PGS))
+ ERRORS += 1
+
print "Test pg export"
EXP_ERRORS = 0
os.mkdir(TESTDIR)
("pgid", po::value<string>(&pgidstr),
"PG id, mandatory except for import, list-lost, fix-lost")
("op", po::value<string>(&op),
- "Arg is one of [info, log, remove, export, import, list, list-lost, fix-lost]")
+ "Arg is one of [info, log, remove, export, import, list, list-lost, fix-lost, list-pgs]")
("file", po::value<string>(&file),
"path of file to export or import")
("debug", "Enable diagnostic output to stderr")
usage(desc);
}
if (op != "import" && op != "list-lost" && op != "fix-lost"
- && !vm.count("pgid")) {
+ && op != "list-pgs" && !vm.count("pgid")) {
cerr << "Must provide pgid" << std::endl;
usage(desc);
}
goto out;
}
+ if (debug && op == "list-pgs")
+ cout << "Performing list-pgs operation" << std::endl;
+
+ // Find pg
for (it = ls.begin(); it != ls.end(); ++it) {
snapid_t snap;
spg_t tmppgid;
continue;
}
- if (tmppgid != pgid) {
+ if (op != "list-pgs" && tmppgid != pgid) {
continue;
}
if (snap != CEPH_NOSNAP && debug) {
continue;
}
- //Found!
- break;
+ if (op != "list-pgs") {
+ //Found!
+ break;
+ }
+
+ cout << tmppgid << std::endl;
+ }
+
+ if (op == "list-pgs") {
+ ret = 0;
+ goto out;
}
epoch_t map_epoch;
formatter->flush(cout);
cout << std::endl;
} else {
- cerr << "Must provide --op (info, log, remove, export, import, list, list-lost, fix-lost)"
+ cerr << "Must provide --op (info, log, remove, export, import, list, list-lost, fix-lost, list-pgs)"
<< std::endl;
usage(desc);
}