]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
ceph-disk: prepare --data-dir must not override files
authorLoic Dachary <loic@dachary.org>
Mon, 30 Dec 2013 11:26:20 +0000 (12:26 +0100)
committerAlfredo Deza <alfredo@deza.pe>
Wed, 12 Feb 2014 21:17:11 +0000 (16:17 -0500)
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 <loic@dachary.org>
(cherry picked from commit 7dfe550ce18623cde4ae43a2416e31ef81381ab9)

src/ceph-disk
src/test/cli/ceph-disk/data-dir.t [new file with mode: 0644]

index 39f7fd06a6055b3a04c19cfb0ea497c18f238747..920a88947852fbc160b8953dbf6377f11fe0e25c 100755 (executable)
@@ -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 (file)
index 0000000..a0bb563
--- /dev/null
@@ -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