// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2004-2006 Sage Weil * * This is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License version 2.1, as published by the Free Software * Foundation. See file COPYING. * */ #include "mon/MonitorStore.cc" #include "config.h" #include "mon/Monitor.h" #include "mon/MonMap.h" #include "mds/MDSMap.h" #include "osd/OSDMap.h" #include "mon/PGMap.h" void usage() { cerr << "usage: ./mkmonfs [--clobber] --mon --monmap --osdmap " << std::endl; exit(1); } int main(int argc, const char **argv) { vector args; argv_to_vec(argc, argv, args); bool clobber = false; const char *fsdir = 0; int whoami = -1; const char *monmapfn = 0; for (unsigned i = 0; i < args.size(); i++) { if (strcmp(args[i], "--clobber") == 0) clobber = true; else if (strcmp(args[i], "--mon") == 0) whoami = atoi(args[++i]); else if (strcmp(args[i], "--monmap") == 0) monmapfn = args[++i]; else if (!fsdir) fsdir = args[i]; else usage(); } if (!fsdir || !monmapfn || whoami < 0) usage(); if (!clobber) { // make sure it doesn't exist struct stat st; if (::lstat(fsdir, &st) == 0) { cerr << "monfs dir " << fsdir << " already exists; remove it first" << std::endl; usage(); } } // load monmap bufferlist monmapbl; int err = monmapbl.read_file(monmapfn); if (err < 0) exit(1); MonMap monmap; monmap.decode(monmapbl); // go MonitorStore store(fsdir); Monitor mon(whoami, &store, 0, &monmap); mon.mkfs(); cout << argv[0] << ": created monfs at " << fsdir << " for mon" << whoami << std::endl; return 0; }