From a53b1489bae503a902bac0d905f5cf76e6f258c3 Mon Sep 17 00:00:00 2001 From: Esteban Molina-Estolano Date: Mon, 8 Sep 2008 12:48:20 -0700 Subject: [PATCH] synclient: dump placement --- src/client/SyntheticClient.cc | 65 ++++++++++++++++++++++++++++++++++- src/client/SyntheticClient.h | 6 ++++ 2 files changed, 70 insertions(+), 1 deletion(-) diff --git a/src/client/SyntheticClient.cc b/src/client/SyntheticClient.cc index eaba4dac21ef4..4713ef02e422f 100644 --- a/src/client/SyntheticClient.cc +++ b/src/client/SyntheticClient.cc @@ -111,7 +111,9 @@ void parse_syn_options(vector& args) syn_modes.push_back( SYNCLIENT_MODE_READFILE ); syn_iargs.push_back( a ); syn_iargs.push_back( b ); - + } else if (strcmp(args[i],"dumpplacement") == 0) { + syn_modes.push_back( SYNCLIENT_MODE_DUMP ); + syn_sargs.push_back( args[++i] ); } else if (strcmp(args[i],"makedirs") == 0) { syn_modes.push_back( SYNCLIENT_MODE_MAKEDIRS ); syn_iargs.push_back( atoi(args[++i]) ); @@ -430,6 +432,19 @@ int SyntheticClient::run() } break; + + case SYNCLIENT_MODE_DUMP: + { + string sarg1 = get_sarg(0); + if (run_me()) { + dout(2) << "placement dump " << sarg1 << dendl; + dump_placement(sarg1); + } + did_run_me(); + } + break; + + case SYNCLIENT_MODE_MAKEDIRMESS: { string sarg1 = get_sarg(0); @@ -1556,6 +1571,54 @@ int SyntheticClient::full_walk(string& basedir) return 0; } + + +int SyntheticClient::dump_placement(string& fn) { + + // open file + int fd = client->open(fn.c_str(), O_RDONLY); + dout(5) << "reading from " << fn << " fd " << fd << dendl; + if (fd < 0) return fd; + + + // How big is it? + struct stat stbuf; + int lstat_result = client->lstat(fn.c_str(), &stbuf); + if (lstat_result < 0) { + derr(0) << "lstat error for file " << fn << dendl; + return lstat_result; + } + + off_t filesize = stbuf.st_size; + + // grab the placement info + list extents; + off_t offset = 0; + client->enumerate_layout(fd, extents, filesize, offset); + client->close(fd); + + + // run through all the object extents + dout(0) << "file size is " << filesize << dendl; + dout(0) << "(osd, start, length) tuples for file " << fn << dendl; + for (list::iterator i = extents.begin(); + i != extents.end(); ++i) { + + int osd = client->osdmap->get_pg_primary(pg_t(i->layout.ol_pgid.v)); + + // run through all the buffer extents + for (map::iterator j = i ->buffer_extents.begin(); + j != i->buffer_extents.end(); ++j) { + + dout(0) << "OSD " << osd << ", offset " << (*j).first << + ", length " << (*j).second << dendl; + } + } + return 0; +} + + + int SyntheticClient::make_dirs(const char *basedir, int dirs, int files, int depth) { if (time_to_stop()) return 0; diff --git a/src/client/SyntheticClient.h b/src/client/SyntheticClient.h index b128ce0f7f69e..d02d0adb7fa65 100644 --- a/src/client/SyntheticClient.h +++ b/src/client/SyntheticClient.h @@ -69,6 +69,9 @@ #define SYNCLIENT_MODE_RANDOMSLEEP 61 #define SYNCLIENT_MODE_SLEEP 62 +#define SYNCLIENT_MODE_DUMP 63 + + #define SYNCLIENT_MODE_TRUNCATE 200 #define SYNCLIENT_MODE_FOO 100 @@ -213,6 +216,9 @@ class SyntheticClient { int full_walk(string& fromdir); int random_walk(int n); + int dump_placement(string& fn); + + int make_dirs(const char *basedir, int dirs, int files, int depth); int stat_dirs(const char *basedir, int dirs, int files, int depth); int read_dirs(const char *basedir, int dirs, int files, int depth); -- 2.39.5