From c8b9798a69bd1655a7131c7bce8a14c2c74aba0c Mon Sep 17 00:00:00 2001 From: Loic Dachary Date: Fri, 3 Jan 2014 16:03:09 +0100 Subject: [PATCH] ceph-disk: implement --statedir as /var/lib/ceph Replace hardcoded /var/lib/ceph with the STATEDIR global variable and implement the --statedir option to override the default value. Signed-off-by: Loic Dachary (cherry picked from commit ca713f48ae7a1fece2869f1a1c97d23ab33fb441) --- src/ceph-disk | 53 ++++++++++++++++++++++++++++++++++----------------- 1 file changed, 36 insertions(+), 17 deletions(-) diff --git a/src/ceph-disk b/src/ceph-disk index 64449991b02bc..f2ee0ee6e8f96 100755 --- a/src/ceph-disk +++ b/src/ceph-disk @@ -115,6 +115,8 @@ INIT_SYSTEMS = [ 'none', ] +STATEDIR = '/var/lib/ceph' + # Nuke the TERM variable to avoid confusing any subprocesses we call. # For example, libreadline will print weird control sequences for some # TERM values. @@ -146,11 +148,6 @@ class filelock(object): fcntl.lockf(self.fd, fcntl.LOCK_UN) self.fd = None - -prepare_lock = filelock('/var/lib/ceph/tmp/ceph-disk.prepare.lock') -activate_lock = filelock('/var/lib/ceph/tmp/ceph-disk.activate.lock') - - ###### exceptions ######## class Error(Exception): @@ -767,7 +764,7 @@ def mount( # mount path = tempfile.mkdtemp( prefix='mnt.', - dir='/var/lib/ceph/tmp', + dir=STATEDIR + '/tmp', ) try: LOG.debug('Mounting %s on %s with options %s', dev, path, options) @@ -1476,7 +1473,7 @@ def move_mount( mount_options, ): LOG.debug('Moving mount to final location...') - parent = '/var/lib/ceph/osd' + parent = STATEDIR + '/osd' osd_data = os.path.join( parent, '{cluster}-{osd_id}'.format(cluster=cluster, osd_id=osd_id), @@ -1520,7 +1517,7 @@ def start_daemon( ): LOG.debug('Starting %s osd.%s...', cluster, osd_id) - path = '/var/lib/ceph/osd/{cluster}-{osd_id}'.format( + path = (STATEDIR + '/osd/{cluster}-{osd_id}').format( cluster=cluster, osd_id=osd_id) # upstart? @@ -1631,16 +1628,16 @@ def mount_activate( other = False src_dev = os.stat(path).st_dev try: - dst_dev = os.stat('/var/lib/ceph/osd/{cluster}-{osd_id}'.format( + dst_dev = os.stat((STATEDIR + '/osd/{cluster}-{osd_id}').format( cluster=cluster, osd_id=osd_id)).st_dev if src_dev == dst_dev: active = True else: - parent_dev = os.stat('/var/lib/ceph/osd').st_dev + parent_dev = os.stat(STATEDIR + '/osd').st_dev if dst_dev != parent_dev: other = True - elif os.listdir('/var/lib/ceph/osd/{cluster}-{osd_id}'.format( + elif os.listdir((STATEDIR + '/osd/{cluster}-{osd_id}').format( cluster=cluster, osd_id=osd_id, )): @@ -1689,7 +1686,7 @@ def activate_dir( (osd_id, cluster) = activate(path, activate_key_template, init) if init not in ( None, 'none' ): - canonical = '/var/lib/ceph/osd/{cluster}-{osd_id}'.format( + canonical = (STATEDIR + '/osd/{cluster}-{osd_id}').format( cluster=cluster, osd_id=osd_id) if path != canonical: @@ -2166,8 +2163,6 @@ def main_list(args): # means suppressing sdb will stop activate on sdb1, sdb2, etc. # -SUPPRESS_PREFIX = '/var/lib/ceph/tmp/suppress-activate.' - def is_suppressed(path): disk = os.path.realpath(path) try: @@ -2225,6 +2220,23 @@ def main_zap(args): ########################### +def setup_statedir(dir): + global STATEDIR + STATEDIR = dir + + if not os.path.exists(STATEDIR): + os.mkdir(STATEDIR) + if not os.path.exists(STATEDIR + "/tmp"): + os.mkdir(STATEDIR + "/tmp") + + global prepare_lock + prepare_lock = filelock(STATEDIR + '/tmp/ceph-disk.prepare.lock') + + global activate_lock + activate_lock = filelock(STATEDIR + '/tmp/ceph-disk.activate.lock') + + global SUPPRESS_PREFIX + SUPPRESS_PREFIX = STATEDIR + '/tmp/suppress-activate.' def parse_args(): parser = argparse.ArgumentParser( @@ -2241,6 +2253,12 @@ def parse_args(): default='/usr/bin', help='prepend PATH to $PATH for backward compatibility (default /usr/bin)', ) + parser.add_argument( + '--statedir', + metavar='PATH', + default='/var/lib/ceph', + help='directory in which ceph state is preserved (default /var/lib/ceph)', + ) parser.set_defaults( # we want to hold on to this, for later prog=parser.prog, @@ -2356,7 +2374,7 @@ def parse_args(): help='path to block device or directory', ) activate_parser.set_defaults( - activate_key_template='/var/lib/ceph/bootstrap-osd/{cluster}.keyring', + activate_key_template=STATEDIR + '/bootstrap-osd/{cluster}.keyring', func=main_activate, ) @@ -2380,7 +2398,7 @@ def parse_args(): choices=INIT_SYSTEMS, ) activate_journal_parser.set_defaults( - activate_key_template='/var/lib/ceph/bootstrap-osd/{cluster}.keyring', + activate_key_template=STATEDIR + '/bootstrap-osd/{cluster}.keyring', func=main_activate_journal, ) @@ -2399,7 +2417,7 @@ def parse_args(): choices=INIT_SYSTEMS, ) activate_all_parser.set_defaults( - activate_key_template='/var/lib/ceph/bootstrap-osd/{cluster}.keyring', + activate_key_template=STATEDIR + '/bootstrap-osd/{cluster}.keyring', func=main_activate_all, ) @@ -2460,6 +2478,7 @@ def main(): path = os.environ.get('PATH', '') os.environ['PATH'] = args.prepend_to_path + ":" + path + setup_statedir(args.statedir) try: args.func(args) -- 2.39.5