From: Sage Weil Date: Sun, 27 Jan 2013 04:33:16 +0000 (-0800) Subject: ceph-disk-activate: detect whether PATH is mount or dir X-Git-Tag: v0.58~78^2~3 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=191d5f7535f8d96d493e1b35b43a421c67c168ea;p=ceph.git ceph-disk-activate: detect whether PATH is mount or dir remove in-the-way symlinks in /var/lib/ceph/osd This is simpler. Just detect what the path is and Do The Right Thing. Closes #3341 (which wanted to make --mount the default) Signed-off-by: Sage Weil --- diff --git a/src/ceph-disk-activate b/src/ceph-disk-activate index cf3c23692e0d..18c33ef3d3d2 100755 --- a/src/ceph-disk-activate +++ b/src/ceph-disk-activate @@ -7,6 +7,7 @@ import os import os.path import re import subprocess +import stat import sys import tempfile @@ -69,6 +70,10 @@ class UnmountError(ActivateError): def maybe_mkdir(*a, **kw): + # remove any symlink, if it is there.. + if os.path.exists(*a) and stat.S_ISLNK(os.lstat(*a).st_mode): + log.debug('Removing old symlink at %s', *a) + os.unlink(*a) try: os.mkdir(*a, **kw) except OSError, e: @@ -491,9 +496,44 @@ def mount_activate( # remove out temp dir os.rmdir(path) + +def activate_dir( + path, + activate_key_template, + init, + ): + + if not os.path.exists(path): + raise ActivateError( + 'directory %s does not exist' % path ) - path = mount(dev=path, fstype=fstype, options=mount_options) + (osd_id, cluster) = activate(path, activate_key_template, init) + canonical = '/var/lib/ceph/osd/{cluster}-{osd_id}'.format( + cluster=cluster, + osd_id=osd_id) + if path != canonical: + # symlink it from the proper location + create = True + if os.path.lexists(canonical): + old = os.readlink(canonical) + if old != path: + log.debug('Removing old symlink %s -> %s', canonical, old) + try: + os.unlink(canonical) + except: + raise ActivateError('unable to remove old symlink %s', canonical) + else: + create = False + if create: + log.debug('Creating symlink %s -> %s', canonical, path) + try: + os.symlink(path, canonical) + except: + raise ActivateError('unable to create symlink %s -> %s', canonical, path) + + return (cluster, osd_id) + def activate( path, @@ -591,7 +631,8 @@ def parse_args(): parser.add_argument( 'path', metavar='PATH', - help='path to block device when using --mount', + nargs='?', + help='path to block device or directory', ) parser.add_argument( '--mark-init', @@ -622,12 +663,25 @@ def main(): try: cluster = None osd_id = None - if args.mount: + + if not os.path.exists(args.path): + raise ActivateError('%s does not exist', args.path) + + mode = os.stat(args.path).st_mode + if stat.S_ISBLK(mode): (cluster, osd_id) = mount_activate( dev=args.path, activate_key_template=args.activate_key_template, init=args.mark_init, ) + elif stat.S_ISDIR(mode): + (cluster, osd_id) = activate_dir( + path=args.path, + activate_key_template=args.activate_key_template, + init=args.mark_init, + ) + else: + raise ActivateError('%s is not a directory or block device', args.path) start_daemon( cluster=cluster,