From: Loic Dachary Date: Mon, 30 Dec 2013 11:26:20 +0000 (+0100) Subject: ceph-disk: prepare --data-dir must not override files X-Git-Tag: v0.67.6~1^2~21 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=5df1eaa55bc7ebe68473831d06cf9819fa39baa6;p=ceph.git ceph-disk: prepare --data-dir must not override files ceph-disk does nothing when given a device that is already prepared. If given a directory that already contains a successfully prepared OSD, it will however override it. Instead of overriding the files in the osd data directory, return immediately if the magic file exists. Make it so the magic file is created last to accurately reflect the success of the OSD preparation. Signed-off-by: Loic Dachary (cherry picked from commit 7dfe550ce18623cde4ae43a2416e31ef81381ab9) --- diff --git a/src/ceph-disk b/src/ceph-disk index 39f7fd06a6055..920a88947852f 100755 --- a/src/ceph-disk +++ b/src/ceph-disk @@ -1051,7 +1051,12 @@ def prepare_dir( journal_uuid, journal_dmcrypt = None, ): - LOG.debug('Preparing osd data dir %s', path) + + if os.path.exists(os.path.join(path, 'magic')): + LOG.debug('Data dir %s already exists', path) + return + else: + LOG.debug('Preparing osd data dir %s', path) if osd_uuid is None: osd_uuid = str(uuid.uuid4()) @@ -1070,12 +1075,14 @@ def prepare_dir( write_one_line(path, 'ceph_fsid', cluster_uuid) write_one_line(path, 'fsid', osd_uuid) - write_one_line(path, 'magic', CEPH_OSD_ONDISK_MAGIC) if journal_uuid is not None: # i.e., journal is a tagged partition write_one_line(path, 'journal_uuid', journal_uuid) + write_one_line(path, 'magic', CEPH_OSD_ONDISK_MAGIC) + + def prepare_dev( data, journal, diff --git a/src/test/cli/ceph-disk/data-dir.t b/src/test/cli/ceph-disk/data-dir.t new file mode 100644 index 0000000000000..a0bb563f2a1a4 --- /dev/null +++ b/src/test/cli/ceph-disk/data-dir.t @@ -0,0 +1,22 @@ + $ uuid=$(uuidgen) + $ export CEPH_CONF=$TESTDIR/ceph.conf + $ echo "[global]\nfsid = $uuid\nosd_data = $TESTDIR/osd-data\n" > $CEPH_CONF + $ osd_data=$(ceph-conf osd_data) + $ mkdir $osd_data +# a failure to create the fsid file implies the magic file is not created + $ mkdir $osd_data/fsid + $ ceph-disk --verbose prepare $osd_data 2>&1 | grep 'Is a directory' + OSError: [Errno 21] Is a directory + $ ! [ -f $osd_data/magic ] + $ rmdir $osd_data/fsid +# successfully prepare the OSD + $ ceph-disk --verbose prepare $osd_data + DEBUG:ceph-disk:Preparing osd data dir .* (re) + $ grep $uuid $osd_data/ceph_fsid > /dev/null + $ [ -f $osd_data/magic ] +# will not override an existing OSD + $ echo "[global]\nfsid = $(uuidgen)\nosd_data = $TESTDIR/osd-data\n" > $CEPH_CONF + $ ceph-disk --verbose prepare $osd_data + DEBUG:ceph-disk:Data dir .* already exists (re) + $ grep $uuid $osd_data/ceph_fsid > /dev/null + $ rm -fr $osd_data $TESTDIR/ceph.conf