mirror of
https://github.com/ceph/ceph
synced 2024-12-29 15:03:33 +00:00
osd: fail startup if store is in use (before we fork)
This commit is contained in:
parent
226c727eaf
commit
d17257b983
15
src/cosd.cc
15
src/cosd.cc
@ -145,11 +145,9 @@ int main(int argc, const char **argv)
|
||||
|
||||
g_timer.shutdown();
|
||||
messenger->register_entity(entity_name_t::OSD(whoami));
|
||||
assert_warn(messenger);
|
||||
if (!messenger)
|
||||
return 1;
|
||||
messenger_hb->register_entity(entity_name_t::OSD(whoami));
|
||||
assert_warn(messenger_hb);
|
||||
if (!messenger_hb)
|
||||
return 1;
|
||||
|
||||
@ -157,13 +155,22 @@ int main(int argc, const char **argv)
|
||||
messenger->set_policy(entity_name_t::TYPE_MON, SimpleMessenger::Policy::client());
|
||||
messenger->set_policy(entity_name_t::TYPE_OSD, SimpleMessenger::Policy::lossless_peer());
|
||||
|
||||
|
||||
OSD *osd = new OSD(whoami, messenger, messenger_hb, &mc, g_conf.osd_data, g_conf.osd_journal, mkjournal);
|
||||
|
||||
int err = osd->pre_init();
|
||||
if (err < 0) {
|
||||
char buf[80];
|
||||
cerr << "error initializing osd: " << strerror_r(-err, buf, sizeof(buf)) << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
messenger->start();
|
||||
messenger_hb->start(true); // only need to daemon() once
|
||||
|
||||
// start osd
|
||||
OSD *osd = new OSD(whoami, messenger, messenger_hb, &mc, g_conf.osd_data, g_conf.osd_journal, mkjournal);
|
||||
if (osd->init() < 0) {
|
||||
cout << "error initializing osd" << std::endl;
|
||||
cout << "error starting osd" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -351,12 +351,29 @@ int FileStore::lock_fsid()
|
||||
int r = ::fcntl(fsid_fd, F_SETLK, &l);
|
||||
if (r < 0) {
|
||||
char buf[80];
|
||||
derr(0) << "mount failed to lock " << basedir << "/fsid, is another cosd still running? " << strerror_r(errno, buf, sizeof(buf)) << dendl;
|
||||
derr(0) << "lock_fsid failed to lock " << basedir << "/fsid, is another cosd still running? " << strerror_r(errno, buf, sizeof(buf)) << dendl;
|
||||
return -errno;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool FileStore::test_mount_in_use()
|
||||
{
|
||||
dout(5) << "test_mount basedir " << basedir << " journal " << journalpath << dendl;
|
||||
char fn[PATH_MAX];
|
||||
snprintf(fn, sizeof(fn), "%s/fsid", basedir.c_str());
|
||||
|
||||
// verify fs isn't in use
|
||||
|
||||
fsid_fd = ::open(fn, O_RDWR, 0644);
|
||||
if (fsid_fd < 0)
|
||||
return 0; // no fsid, ok.
|
||||
bool inuse = lock_fsid() < 0;
|
||||
::close(fsid_fd);
|
||||
fsid_fd = -1;
|
||||
return inuse;
|
||||
}
|
||||
|
||||
int FileStore::mount()
|
||||
{
|
||||
char buf[80];
|
||||
|
@ -106,6 +106,7 @@ class FileStore : public JournalingObjectStore {
|
||||
lock("FileStore::lock"),
|
||||
sync_epoch(0), stop(false), sync_thread(this), flusher_queue_len(0), flusher_thread(this) { }
|
||||
|
||||
bool test_mount_in_use();
|
||||
int mount();
|
||||
int umount();
|
||||
int mkfs();
|
||||
|
@ -430,6 +430,7 @@ public:
|
||||
virtual ~ObjectStore() {}
|
||||
|
||||
// mgmt
|
||||
virtual bool test_mount_in_use() = 0;
|
||||
virtual int mount() = 0;
|
||||
virtual int umount() = 0;
|
||||
virtual int mkfs() = 0; // wipe
|
||||
|
@ -389,17 +389,33 @@ void handle_signal(int signal)
|
||||
|
||||
void cls_initialize(OSD *_osd);
|
||||
|
||||
|
||||
int OSD::pre_init()
|
||||
{
|
||||
Mutex::Locker lock(osd_lock);
|
||||
|
||||
assert(!store);
|
||||
store = create_object_store(dev_path, journal_path);
|
||||
if (!store) {
|
||||
dout(0) << " unable to create object store" << dendl;
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
if (store->test_mount_in_use()) {
|
||||
dout(0) << "object store " << dev_path << " is currently in use" << dendl;
|
||||
cout << "object store " << dev_path << " is currently in use (cosd already running?)" << std::endl;
|
||||
return -EBUSY;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int OSD::init()
|
||||
{
|
||||
Mutex::Locker lock(osd_lock);
|
||||
|
||||
// mount.
|
||||
dout(2) << "mounting " << dev_path << " " << (journal_path ? journal_path : "(no journal)") << dendl;
|
||||
store = create_object_store(dev_path, journal_path);
|
||||
if (!store) {
|
||||
dout(0) << " unable to create object store" << dendl;
|
||||
return -ENODEV;
|
||||
}
|
||||
assert(store); // call pre_init() first!
|
||||
|
||||
if (mknewjournal) {
|
||||
int r = store->mkjournal();
|
||||
|
@ -865,6 +865,7 @@ public:
|
||||
|
||||
|
||||
// startup/shutdown
|
||||
int pre_init();
|
||||
int init();
|
||||
int shutdown();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user