From: Sage Weil Date: Wed, 23 Dec 2015 21:38:50 +0000 (-0500) Subject: osd: do not catch mkfs exceptions X-Git-Tag: v10.0.3~154^2~31 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=97373a7723e8a310cff0844202697ea75aa812ad;p=ceph.git osd: do not catch mkfs exceptions We either want to take a clean error path, or dump core. Signed-off-by: Sage Weil --- diff --git a/src/osd/OSD.cc b/src/osd/OSD.cc index f5d4a3fcd500..c587c08ac63c 100644 --- a/src/osd/OSD.cc +++ b/src/osd/OSD.cc @@ -1366,88 +1366,79 @@ int OSD::mkfs(CephContext *cct, ObjectStore *store, const string &dev, ceph::shared_ptr osr( new ObjectStore::Sequencer("mkfs")); + OSDSuperblock sb; + bufferlist sbbl; + C_SaferCond waiter; - try { - // if we are fed a uuid for this osd, use it. - store->set_fsid(cct->_conf->osd_uuid); - - ret = store->mkfs(); - if (ret) { - derr << "OSD::mkfs: ObjectStore::mkfs failed with error " << ret << dendl; - goto free_store; - } - - ret = store->mount(); - if (ret) { - derr << "OSD::mkfs: couldn't mount ObjectStore: error " << ret << dendl; - goto free_store; - } - - OSDSuperblock sb; - bufferlist sbbl; - ret = store->read(coll_t::meta(), OSD_SUPERBLOCK_POBJECT, 0, 0, sbbl); - if (ret >= 0) { - /* if we already have superblock, check content of superblock */ - dout(0) << " have superblock" << dendl; - bufferlist::iterator p; - p = sbbl.begin(); - ::decode(sb, p); - if (whoami != sb.whoami) { - derr << "provided osd id " << whoami << " != superblock's " << sb.whoami << dendl; - ret = -EINVAL; - goto umount_store; - } - if (fsid != sb.cluster_fsid) { - derr << "provided cluster fsid " << fsid << " != superblock's " << sb.cluster_fsid << dendl; - ret = -EINVAL; - goto umount_store; - } - } else { - // create superblock - if (fsid.is_zero()) { - derr << "must specify cluster fsid" << dendl; - ret = -EINVAL; - goto umount_store; - } + // if we are fed a uuid for this osd, use it. + store->set_fsid(cct->_conf->osd_uuid); - sb.cluster_fsid = fsid; - sb.osd_fsid = store->get_fsid(); - sb.whoami = whoami; - sb.compat_features = get_osd_initial_compat_set(); + ret = store->mkfs(); + if (ret) { + derr << "OSD::mkfs: ObjectStore::mkfs failed with error " << ret << dendl; + goto free_store; + } - bufferlist bl; - ::encode(sb, bl); + ret = store->mount(); + if (ret) { + derr << "OSD::mkfs: couldn't mount ObjectStore: error " << ret << dendl; + goto free_store; + } - ObjectStore::Transaction t; - t.create_collection(coll_t::meta(), 0); - t.write(coll_t::meta(), OSD_SUPERBLOCK_POBJECT, 0, bl.length(), bl); - ret = store->apply_transaction(osr.get(), t); - if (ret) { - derr << "OSD::mkfs: error while writing OSD_SUPERBLOCK_POBJECT: " - << "apply_transaction returned " << ret << dendl; - goto umount_store; - } + ret = store->read(coll_t::meta(), OSD_SUPERBLOCK_POBJECT, 0, 0, sbbl); + if (ret >= 0) { + /* if we already have superblock, check content of superblock */ + dout(0) << " have superblock" << dendl; + bufferlist::iterator p; + p = sbbl.begin(); + ::decode(sb, p); + if (whoami != sb.whoami) { + derr << "provided osd id " << whoami << " != superblock's " << sb.whoami + << dendl; + ret = -EINVAL; + goto umount_store; } - - C_SaferCond waiter; - if (!osr->flush_commit(&waiter)) { - waiter.wait(); + if (fsid != sb.cluster_fsid) { + derr << "provided cluster fsid " << fsid + << " != superblock's " << sb.cluster_fsid << dendl; + ret = -EINVAL; + goto umount_store; } + } else { + // create superblock + if (fsid.is_zero()) { + derr << "must specify cluster fsid" << dendl; + ret = -EINVAL; + goto umount_store; + } + + sb.cluster_fsid = fsid; + sb.osd_fsid = store->get_fsid(); + sb.whoami = whoami; + sb.compat_features = get_osd_initial_compat_set(); - ret = write_meta(store, sb.cluster_fsid, sb.osd_fsid, whoami); + bufferlist bl; + ::encode(sb, bl); + + ObjectStore::Transaction t; + t.create_collection(coll_t::meta(), 0); + t.write(coll_t::meta(), OSD_SUPERBLOCK_POBJECT, 0, bl.length(), bl); + ret = store->apply_transaction(osr.get(), t); if (ret) { - derr << "OSD::mkfs: failed to write fsid file: error " << ret << dendl; + derr << "OSD::mkfs: error while writing OSD_SUPERBLOCK_POBJECT: " + << "apply_transaction returned " << ret << dendl; goto umount_store; } - } - catch (const std::exception &se) { - derr << "OSD::mkfs: caught exception " << se.what() << dendl; - ret = 1000; + + if (!osr->flush_commit(&waiter)) { + waiter.wait(); } - catch (...) { - derr << "OSD::mkfs: caught unknown exception." << dendl; - ret = 1000; + + ret = write_meta(store, sb.cluster_fsid, sb.osd_fsid, whoami); + if (ret) { + derr << "OSD::mkfs: failed to write fsid file: error " << ret << dendl; + goto umount_store; } umount_store: