From: Sage Weil Date: Wed, 18 Nov 2009 18:49:38 +0000 (-0800) Subject: osd: allow reinitialization of osd journal X-Git-Tag: v0.18~98^2~3 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=4fab3f754d2be3b6114e4011d27ced9ed2647166;p=ceph.git osd: allow reinitialization of osd journal (without hosing osd data) --- diff --git a/src/cosd.cc b/src/cosd.cc index 4336a676474d..aa34cf3f4a9e 100644 --- a/src/cosd.cc +++ b/src/cosd.cc @@ -37,7 +37,7 @@ using namespace std; void usage() { - cerr << "usage: cosd -i osdid [--osd-data=path] [--osd-journal=path] [--mkfs]" << std::endl; + cerr << "usage: cosd -i osdid [--osd-data=path] [--osd-journal=path] [--mkfs] [--mkjournal]" << std::endl; cerr << " --debug_osd N set debug level (e.g. 10)" << std::endl; generic_server_usage(); } @@ -54,10 +54,13 @@ int main(int argc, const char **argv) if (g_conf.clock_tare) g_clock.tare(); // osd specific args - bool mkfs = 0; + bool mkfs = false; + bool mkjournal = false; FOR_EACH_ARG(args) { if (CONF_ARG_EQ("mkfs", '\0')) { - mkfs = 1; + mkfs = true; + } else if (CONF_ARG_EQ("mkjournal", '\0')) { + mkjournal = true; } else { cerr << "unrecognized arg " << args[i] << std::endl; ARGS_USAGE(); @@ -151,7 +154,7 @@ int main(int argc, const char **argv) rank.start(); // start osd - OSD *osd = new OSD(whoami, m, hbm, &mc, g_conf.osd_data, g_conf.osd_journal); + OSD *osd = new OSD(whoami, m, hbm, &mc, g_conf.osd_data, g_conf.osd_journal, mkjournal); if (osd->init() < 0) { cout << "error initializing osd" << std::endl; return 1; diff --git a/src/os/FileStore.cc b/src/os/FileStore.cc index 464f454e5a18..91fa7dcbe3dc 100644 --- a/src/os/FileStore.cc +++ b/src/os/FileStore.cc @@ -328,18 +328,9 @@ int FileStore::mkfs() dout(10) << "mkfs fsid is " << fsid << dendl; // journal? - open_journal(); - if (journal) { - if (journal->create() < 0) { - dout(0) << "mkfs error creating journal on " << fn << dendl; - } else { - dout(0) << "mkfs created journal on " << fn << dendl; - } - delete journal; - journal = 0; - } else { - dout(10) << "mkfs no journal at " << fn << dendl; - } + int err = mkjournal(); + if (err) + return err; if (g_conf.filestore_dev) { char cmd[PATH_MAX]; @@ -349,10 +340,31 @@ int FileStore::mkfs() } dout(1) << "mkfs done in " << basedir << dendl; - return 0; } +int FileStore::mkjournal() +{ + int err; + + open_journal(); + if (journal) { + err = journal->create(); + if (err < 0) { + dout(0) << "mkjournal error creating journal on " << journalpath << dendl; + } else { + dout(0) << "mkjournal created journal on " << journalpath << dendl; + } + delete journal; + journal = 0; + } else { + err = -ENOENT; + dout(10) << "mkjournal no journal at " << journalpath << dendl; + } + return err; +} + + Mutex sig_lock("FileStore.cc sig_lock"); Cond sig_cond; bool sig_installed = false; diff --git a/src/os/FileStore.h b/src/os/FileStore.h index f7dfc99846e8..53a82b411ed0 100644 --- a/src/os/FileStore.h +++ b/src/os/FileStore.h @@ -109,6 +109,7 @@ class FileStore : public JournalingObjectStore { int mount(); int umount(); int mkfs(); + int mkjournal(); int statfs(struct statfs *buf); diff --git a/src/os/ObjectStore.h b/src/os/ObjectStore.h index adbd025553fb..26bd74e70f1a 100644 --- a/src/os/ObjectStore.h +++ b/src/os/ObjectStore.h @@ -429,6 +429,7 @@ public: virtual int mount() = 0; virtual int umount() = 0; virtual int mkfs() = 0; // wipe + virtual int mkjournal() = 0; // journal only virtual int statfs(struct statfs *buf) = 0; diff --git a/src/osd/OSD.cc b/src/osd/OSD.cc index a8fed4391303..7284ed6f7a70 100644 --- a/src/osd/OSD.cc +++ b/src/osd/OSD.cc @@ -220,7 +220,7 @@ int OSD::peek_super(const char *dev, nstring& magic, ceph_fsid_t& fsid, int& who // cons/des -OSD::OSD(int id, Messenger *m, Messenger *hbm, MonClient *mc, const char *dev, const char *jdev) : +OSD::OSD(int id, Messenger *m, Messenger *hbm, MonClient *mc, const char *dev, const char *jdev, bool newjournal) : osd_lock("OSD::osd_lock"), timer(osd_lock), messenger(m), @@ -265,6 +265,7 @@ OSD::OSD(int id, Messenger *m, Messenger *hbm, MonClient *mc, const char *dev, c { monc->set_messenger(messenger); + mknewjournal = newjournal; osdmap = 0; memset(&my_stat, 0, sizeof(my_stat)); @@ -317,10 +318,19 @@ int OSD::init() dout(0) << " unable to create object store" << dendl; return -ENODEV; } + + if (mknewjournal) { + int r = store->mkjournal(); + if (r < 0) { + dout(0) << " unable to create new jouranl" << dendl; + return r; + } + } + int r = store->mount(); if (r < 0) { dout(0) << " unable to mount object store" << dendl; - return -1; + return r; } dout(2) << "boot" << dendl; diff --git a/src/osd/OSD.h b/src/osd/OSD.h index ee8e633aa6c8..5d662cb1fdc4 100644 --- a/src/osd/OSD.h +++ b/src/osd/OSD.h @@ -103,6 +103,7 @@ protected: int whoami; const char *dev_path, *journal_path; + bool mknewjournal; class C_Tick : public Context { OSD *osd; @@ -820,7 +821,7 @@ protected: void ms_handle_remote_reset(Connection *con) {} public: - OSD(int id, Messenger *m, Messenger *hbm, MonClient *mc, const char *dev = 0, const char *jdev = 0); + OSD(int id, Messenger *m, Messenger *hbm, MonClient *mc, const char *dev = 0, const char *jdev = 0, bool newjournal=false); ~OSD(); // static bits