]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
ceph-disk: allow using a regular file as a journal 11657/head
authorJayashree Candadai <jayaajay@indiana.edu>
Fri, 21 Oct 2016 17:52:05 +0000 (13:52 -0400)
committerLoic Dachary <ldachary@redhat.com>
Wed, 26 Oct 2016 09:29:40 +0000 (11:29 +0200)
Because of a missing return, ceph-disk prepare would fail if given a
regular file as a journal. If the journal file does not exist, ceph-disk
will create it but fail to ensure that the ceph user owns it. The
symlink to the journal file is not set when the journal file is
specified on the command line and the journal file does not exist at
all. The ceph-osd daemon will silently create it as a file but it will
not be the file given in argument.

Add a test case to verify using a regular file as a journal works as
expected.

Fixes: http://tracker.ceph.com/issues/17662
Signed-off-by: Jayashree Candadai <jayaajay@indiana.edu>
Signed-off-by: Loic Dachary <ldachary@redhat.com>
(cherry picked from commit db917d50eb5f86a07a5487e130f46a6b1d27672a)

qa/workunits/ceph-disk/ceph-disk-test.py
src/ceph-disk/ceph_disk/main.py

index cdcfc8483ad999ad4fd1d09077cf0f1f983fdc7c..63c2c7a8ecc869e118a814f5d5b2a63159a45df1 100644 (file)
@@ -488,6 +488,35 @@ class TestCephDisk(object):
         os.unlink(symlink)
         os.rmdir(tempdir)
 
+    def test_activate_journal_file(self):
+        c = CephDisk()
+        disks = c.unused_disks()
+        data_disk = disks[0]
+        #
+        # /var/lib/ceph/osd is required otherwise it may violate
+        # restrictions enforced by systemd regarding the directories
+        # which ceph-osd is allowed to read/write
+        #
+        tempdir = tempfile.mkdtemp(dir='/var/lib/ceph/osd')
+        c.sh("chown ceph:ceph " + tempdir + " || true")
+        journal_file = os.path.join(tempdir, 'journal')
+        osd_uuid = str(uuid.uuid1())
+        c.sh("ceph-disk --verbose prepare --osd-uuid " + osd_uuid +
+             " " + data_disk + " " + journal_file)
+        c.wait_for_osd_up(osd_uuid)
+        device = json.loads(
+            c.sh("ceph-disk list --format json " + data_disk))[0]
+        assert len(device['partitions']) == 1
+        partition = device['partitions'][0]
+        assert journal_file == os.readlink(
+            os.path.join(partition['mount'], 'journal'))
+        c.check_osd_status(osd_uuid)
+        c.helper("pool_read_write 1")  # 1 == pool size
+        c.destroy_osd(osd_uuid)
+        c.sh("ceph-disk --verbose zap " + data_disk)
+        os.unlink(journal_file)
+        os.rmdir(tempdir)
+
     def test_activate_separated_journal(self):
         c = CephDisk()
         disks = c.unused_disks()
index 42664497ea6825153b6d75e3361b68c302264bf5..89374272109450a43b93eb00a7803dbfba80cb6a 100755 (executable)
@@ -1904,6 +1904,7 @@ class PrepareSpace(object):
                 raise Error('%s is not a block device' % name.capitalize,
                             getattr(args, name))
             self.type = self.FILE
+            return
 
         raise Error('%s %s is neither a block device nor regular file' %
                     (name.capitalize, getattr(args, name)))
@@ -1962,13 +1963,13 @@ class PrepareSpace(object):
         if getattr(self.args, space_uuid) is not None:
             write_one_line(path, space_uuid,
                            getattr(self.args, space_uuid))
-
-    def populate_data_path_device(self, path):
-        self.populate_data_path_file(path)
         if self.space_symlink is not None:
             adjust_symlink(self.space_symlink,
                            os.path.join(path, self.name))
 
+    def populate_data_path_device(self, path):
+        self.populate_data_path_file(path)
+
         if self.space_dmcrypt is not None:
             adjust_symlink(self.space_dmcrypt,
                            os.path.join(path, self.name + '_dmcrypt'))
@@ -1997,6 +1998,7 @@ class PrepareSpace(object):
                       space_filename)
             space_file = open(space_filename, 'wb')
             space_file.close()
+            path_set_context(space_filename)
 
         LOG.debug('%s is file %s',
                   self.name.capitalize(),