#include <unistd.h>
#include <cstring>
#include <cstdio>
+#include <cstdlib>
#include <iostream>
#include <dmlite/cpp/dmlite.h>
#include <dmlite/cpp/catalog.h>
}
+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;
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];
std::vector<dmlite::Replica> 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];
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);
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]);
}
}