From cf2e3b15cea99cc100169e7a67103676d8990aee Mon Sep 17 00:00:00 2001 From: Tommi Virtanen Date: Tue, 2 Oct 2012 16:04:15 -0700 Subject: [PATCH] ceph-disk-prepare: Allow specifying fs type to use. Either use ceph.conf variable osd_fs_type or command line option --fs-type= Default is still ext4, as currently nothing guarantees xfsprogs or btrfs-tools are installed. Currently both btrfs and xfs seems to trigger a disk hotplug event at mount time, thus triggering a useless and unwanted ceph-disk-activate run. This will be worked around in a later commit. Currently mkfs and mount options cannot be configured. Bug: #2549 Signed-off-by: Tommi Virtanen --- src/ceph-disk-prepare | 71 +++++++++++++++++++++++++++++++++---------- 1 file changed, 55 insertions(+), 16 deletions(-) diff --git a/src/ceph-disk-prepare b/src/ceph-disk-prepare index dc16ab7fe782..2edaf464bdec 100755 --- a/src/ceph-disk-prepare +++ b/src/ceph-disk-prepare @@ -55,7 +55,7 @@ def write_one_line(parent, name, text): CEPH_OSD_ONDISK_MAGIC = 'ceph osd volume v026' -def get_fsid(cluster): +def get_conf(cluster, variable): try: p = subprocess.Popen( args=[ @@ -65,7 +65,7 @@ def get_fsid(cluster): ), '--name=osd.', '--lookup', - 'fsid', + variable, ], stdout=subprocess.PIPE, close_fds=True, @@ -74,18 +74,43 @@ def get_fsid(cluster): raise PrepareError('error executing ceph-conf', e) (out, _err) = p.communicate() ret = p.wait() - if ret != 0: - raise PrepareError('getting cluster uuid from configuration failed') - fsid = out.split('\n', 1)[0] - if not fsid: + if ret == 1: + # config entry not found + return None + elif ret != 0: + raise PrepareError('getting variable from configuration failed') + value = out.split('\n', 1)[0] + # don't differentiate between "var=" and no var set + if not value: return None + return value + + +def get_fsid(cluster): + fsid = get_conf(cluster=cluster, variable='fsid') + if fsid is None: + raise PrepareError('getting cluster uuid from configuration failed') return fsid +# TODO depend on xfsprogs? +# TODO switch default to xfs once xfsprogs is guaranteed. +# TODO depend on btrfs-tools? +DEFAULT_FS_TYPE = 'ext4' + MOUNT_OPTIONS = dict( ext4='user_xattr', ) +MKFS_ARGS = dict( + xfs=[ + # xfs insists on not overwriting previous fs; even if we wipe + # partition table, we often recreate it exactly the same way, + # so we'll see ghosts of filesystems past + '-f', + ], + ) + def mount( dev, @@ -138,6 +163,7 @@ def unmount( def prepare( disk, + fstype, cluster_uuid, ): """ @@ -166,18 +192,18 @@ def prepare( except subprocess.CalledProcessError as e: raise PrepareError(e) - # TODO make fstype configurable; both ceph.conf and command line - fstype = 'ext4' dev = '{disk}1'.format(disk=disk) + args = [ + 'mkfs', + '--type={fstype}'.format(fstype=fstype), + ] + args.extend(MKFS_ARGS.get(fstype, [])) + args.extend([ + '--', + dev, + ]) try: - subprocess.check_call( - args=[ - 'mkfs', - '--type={fstype}'.format(fstype=fstype), - '--', - dev, - ], - ) + subprocess.check_call(args=args) except subprocess.CalledProcessError as e: raise PrepareError(e) @@ -210,6 +236,10 @@ def parse_args(): metavar='UUID', help='cluster uuid to assign this disk to', ) + parser.add_argument( + '--fs-type', + help='file system type to use (e.g. "ext4")', + ) parser.add_argument( 'disk', metavar='DISK', @@ -242,8 +272,17 @@ def main(): raise PrepareError( 'must have fsid in config or pass --cluster--uuid=', ) + + if args.fs_type is None: + args.fs_type = get_conf( + cluster=args.cluster, + variable='osd_fs_type', + ) + if args.fs_type is None: + args.fs_type = DEFAULT_FS_TYPE prepare( disk=args.disk, + fstype=args.fs_type, cluster_uuid=args.cluster_uuid, ) except PrepareError as e: -- 2.47.3