]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
ceph-disk: prepare --data-dir must not override files 1020/head
authorLoic Dachary <loic@dachary.org>
Mon, 30 Dec 2013 11:26:20 +0000 (12:26 +0100)
committerLoic Dachary <loic@dachary.org>
Wed, 1 Jan 2014 10:48:24 +0000 (11:48 +0100)
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>
src/ceph-disk
src/test/cli/ceph-disk/data-dir.t [new file with mode: 0644]

index 52026d1dcd3dd4aabd444104f704effe0e4111c2..94cbbbf8c93f21303ed1bc03fa2b8dc9c593452b 100755 (executable)
@@ -1048,7 +1048,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())
@@ -1067,12 +1072,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