]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
ceph-disk: implement 'activate-journal'
authorSage Weil <sage@inktank.com>
Thu, 13 Jun 2013 22:54:58 +0000 (15:54 -0700)
committerSage Weil <sage@inktank.com>
Fri, 14 Jun 2013 21:09:29 +0000 (14:09 -0700)
Activate an osd via its journal device.  udev populates its symlinks and
triggers events in an order that is not related to whether the device is
an osd data partition or a journal.  That means that triggering
'ceph-disk activate' can happen before the journal (or journal symlink)
is present and then fail.

Similarly, it may be that they are on different disks that are hotplugged
with the journal second.

This can be wired up to the journal partition type to ensure that osds are
started when the journal appears second.

Include the udev rules to trigger this.

Signed-off-by: Sage Weil <sage@inktank.com>
(cherry picked from commit a2a78e8d16db0a71b13fc15457abc5fe0091c84c)

src/ceph-disk
udev/95-ceph-osd.rules

index 60498b4acc6bc52ebf19b29407e8b2c734dd3961..3e808c78df8f8ce4c48bf9c037b604f30ae1b465 100755 (executable)
@@ -1606,6 +1606,64 @@ def main_activate(args):
         activate_lock.release()
 
 
+###########################
+
+def get_journal_osd_uuid(path):
+    if not os.path.exists(path):
+        raise Error('%s does not exist', path)
+
+    mode = os.stat(path).st_mode
+    if not stat.S_ISBLK(mode):
+        raise Error('%s is not a block device', path)
+
+    try:
+        out = _check_output(
+            args=[
+                'ceph-osd',
+                '-i', '0',   # this is ignored
+                '--get-journal-uuid',
+                '--osd-journal',
+                path,
+                ],
+            close_fds=True,
+            )
+    except subprocess.CalledProcessError as e:
+        raise Error(
+            'failed to get osd uuid/fsid from journal',
+            e,
+            )
+    value = str(out).split('\n', 1)[0]
+    LOG.debug('Journal %s has OSD UUID %s', path, value)
+    return value
+
+def main_activate_journal(args):
+    if not os.path.exists(args.dev):
+        raise Error('%s does not exist', args.dev)
+
+    cluster = None
+    osd_id = None
+    osd_uuid = None
+    activate_lock.acquire()
+    try:
+        osd_uuid = get_journal_osd_uuid(args.dev)
+        path = os.path.join('/dev/disk/by-partuuid/', osd_uuid.lower())
+
+        (cluster, osd_id) = mount_activate(
+            dev=path,
+            activate_key_template=args.activate_key_template,
+            init=args.mark_init,
+            )
+
+        start_daemon(
+            cluster=cluster,
+            osd_id=osd_id,
+            )
+
+        activate_lock.release()
+
+    except:
+        activate_lock.release()
+        raise
 
 ###########################
 
@@ -1986,6 +2044,30 @@ def parse_args():
         func=main_activate,
         )
 
+    activate_journal_parser = subparsers.add_parser('activate-journal', help='Activate an OSD via its journal device')
+    activate_journal_parser.add_argument(
+        'dev',
+        metavar='DEV',
+        help='path to journal block device',
+        )
+    activate_journal_parser.add_argument(
+        '--activate-key',
+        metavar='PATH',
+        help='bootstrap-osd keyring path template (%(default)s)',
+        dest='activate_key_template',
+        )
+    activate_journal_parser.add_argument(
+        '--mark-init',
+        metavar='INITSYSTEM',
+        help='init system to manage this dir',
+        default='auto',
+        choices=INIT_SYSTEMS,
+        )
+    activate_journal_parser.set_defaults(
+        activate_key_template='/var/lib/ceph/bootstrap-osd/{cluster}.keyring',
+        func=main_activate_journal,
+        )
+
     list_parser = subparsers.add_parser('list', help='List disks, partitions, and Ceph OSDs')
     list_parser.set_defaults(
         func=main_list,
index 77e6ef37c5d4ffec09da65f1af7cf50478ce4140..9798e648483499c4b8cb75f14abcfa19f139cd39 100644 (file)
@@ -4,6 +4,12 @@ ACTION=="add", SUBSYSTEM=="block", \
   ENV{ID_PART_ENTRY_TYPE}=="4fbd7e29-9d25-41b8-afd0-062c0ceff05d", \
   RUN+="/usr/sbin/ceph-disk-activate --mount /dev/$name"
 
+# activate ceph-tagged partitions
+ACTION=="add", SUBSYSTEM=="block", \
+  ENV{DEVTYPE}=="partition", \
+  ENV{ID_PART_ENTRY_TYPE}=="45b0969e-9b03-4f30-b4c6-b4b80ceff106", \
+  RUN+="/usr/sbin/ceph-disk activate-journal /dev/$name"
+
 # Map journal if using dm-crypt
 ACTION=="add" SUBSYSTEM=="block", \
   ENV{DEVTYPE}=="partition", \