From fed29b08721194a4fdf745d14c05d3b2824f6aeb Mon Sep 17 00:00:00 2001 From: =?utf8?q?Franti=C5=A1ek=20Dvo=C5=99=C3=A1k?= Date: Sun, 1 Dec 2013 17:24:01 +0100 Subject: [PATCH] All other replica operations. --- run.cpp | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 53 insertions(+), 12 deletions(-) diff --git a/run.cpp b/run.cpp index 3225933..cc3752e 100644 --- a/run.cpp +++ b/run.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include #include #include @@ -21,6 +22,25 @@ static void outstat(dmlite::ExtendedStat& xStat) { } +static void usage(const std::string name) { + std::cout << "Usage: " << name << " [ DMLITE_CONFIGFILE [ s | d | h | (r|w|c) [PATH] | z [PATH [SIZE]] | m PATH mode ] ]" << std::endl; + std::cout << " s ... stat" << std::endl; + std::cout << " d ... opendir/readdir" << std::endl; + std::cout << " r ... read" << std::endl; + std::cout << " h ... chdir" << std::endl; + std::cout << " w ... whereToWrite" << std::endl; + std::cout << " c ... create" << std::endl; + std::cout << " z ... setSize" << std::endl; + std::cout << " m ... setMode" << std::endl; + std::cout << " k ... makeDir" << std::endl; + std::cout << " p ... replicas:" << std::endl; + std::cout << " p list FILE" << std::endl; + std::cout << " p add FILE URL" << std::endl; + std::cout << " p delete FILE REPLICAID" << std::endl; + std::cout << " p update FILE REPLICAID URL" << std::endl; +} + + int main(int argc, char *argv[]) { dmlite::PluginManager manager; @@ -31,16 +51,8 @@ int main(int argc, char *argv[]) { std::string arg; if (argc < 3) { - std::cout << "Usage: " << argv[0] << " [ DMLITE_CONFIGFILE [ s | d | h | (r|w|c) [PATH] | z [PATH [SIZE]] | m PATH mode ] ]" << std::endl; - std::cout << " s ... stat" << std::endl; - std::cout << " d ... opendir/readdir" << std::endl; - std::cout << " r ... read" << std::endl; - std::cout << " h ... chdir" << std::endl; - std::cout << " w ... whereToWrite" << std::endl; - std::cout << " c ... create" << std::endl; - std::cout << " z ... setSize" << std::endl; - std::cout << " m ... setMode" << std::endl; - std::cout << " k ... makeDir" << std::endl; + usage(argv[0]); + return 0; } if (argc >= 2) conf = argv[1]; @@ -254,14 +266,16 @@ int main(int argc, char *argv[]) { std::vector replicas; char *cmd, *path, *rfn; size_t i; + int64_t replicaid; if (argc < 4) { std::cerr << "Missing command" << std::endl; + usage(argv[0]); return 1; } cmd = argv[3]; if (strcasecmp(cmd, "add") == 0 && argc >= 6) { - operation = "replica add"; + operation = "add replica"; path = argv[4]; rfn = argv[5]; @@ -270,7 +284,7 @@ int main(int argc, char *argv[]) { replica.rfn = rfn; catalog->addReplica(replica); } else if (strcasecmp(cmd, "list") == 0 && argc >= 5) { - operation = "replica list"; + operation = "list replicas"; path = argv[4]; replicas = catalog->getReplicas(path); @@ -278,10 +292,37 @@ int main(int argc, char *argv[]) { for (i = 0; i < replicas.size(); i++) { printf(" %lu: inode %lu, server '%s', rfn '%s'\n", replicas[i].replicaid, replicas[i].fileid, replicas[i].server.c_str(), replicas[i].rfn.c_str()); } + } else if (strcasecmp(cmd, "delete") == 0 && argc >= 6) { + operation = "delete replica"; + path = argv[4]; + replicaid = atoll(argv[5]); + + xstat = catalog->extendedStat(path); + replica.fileid = xstat.stat.st_ino; + replica.replicaid = replicaid; + catalog->deleteReplica(replica); + } else if (strcasecmp(cmd, "update") == 0 && argc >= 7) { + operation = "update replica"; + path = argv[4]; + replicaid = atoll(argv[5]); + rfn = argv[6]; + + xstat = catalog->extendedStat(path); + replica.fileid = xstat.stat.st_ino; + replica.replicaid = replicaid; + replica.rfn = rfn; + catalog->updateReplica(replica); } else { std::cerr << "Bad aruments for 'p'" << std::endl; + usage(argv[0]); return 1; } + break; + } + + default: { + std::cerr << "Unknown command " << argv[2] << std::endl; + usage(argv[0]); } } -- 1.8.2.3