From: Sage Weil Date: Thu, 13 Jun 2013 22:54:58 +0000 (-0700) Subject: ceph-disk: implement 'activate-journal' X-Git-Tag: v0.65~74^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=a2a78e8d16db0a71b13fc15457abc5fe0091c84c;p=ceph.git ceph-disk: implement 'activate-journal' 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 --- diff --git a/src/ceph-disk b/src/ceph-disk index d5642c58a92..13d9f8203ce 100755 --- a/src/ceph-disk +++ b/src/ceph-disk @@ -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, diff --git a/udev/95-ceph-osd.rules b/udev/95-ceph-osd.rules index 77e6ef37c5d..9798e648483 100644 --- a/udev/95-ceph-osd.rules +++ b/udev/95-ceph-osd.rules @@ -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", \