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 <tv@inktank.com>
This commit is contained in:
Tommi Virtanen 2012-10-02 16:04:15 -07:00
parent 18d1580d1c
commit 0b934e19d9

View File

@ -55,7 +55,7 @@ def write_one_line(parent, name, text):
CEPH_OSD_ONDISK_MAGIC = 'ceph osd volume v026' CEPH_OSD_ONDISK_MAGIC = 'ceph osd volume v026'
def get_fsid(cluster): def get_conf(cluster, variable):
try: try:
p = subprocess.Popen( p = subprocess.Popen(
args=[ args=[
@ -65,7 +65,7 @@ def get_fsid(cluster):
), ),
'--name=osd.', '--name=osd.',
'--lookup', '--lookup',
'fsid', variable,
], ],
stdout=subprocess.PIPE, stdout=subprocess.PIPE,
close_fds=True, close_fds=True,
@ -74,18 +74,43 @@ def get_fsid(cluster):
raise PrepareError('error executing ceph-conf', e) raise PrepareError('error executing ceph-conf', e)
(out, _err) = p.communicate() (out, _err) = p.communicate()
ret = p.wait() ret = p.wait()
if ret != 0: if ret == 1:
raise PrepareError('getting cluster uuid from configuration failed') # config entry not found
fsid = out.split('\n', 1)[0]
if not fsid:
return None 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 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( MOUNT_OPTIONS = dict(
ext4='user_xattr', 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( def mount(
dev, dev,
@ -138,6 +163,7 @@ def unmount(
def prepare( def prepare(
disk, disk,
fstype,
cluster_uuid, cluster_uuid,
): ):
""" """
@ -166,18 +192,18 @@ def prepare(
except subprocess.CalledProcessError as e: except subprocess.CalledProcessError as e:
raise PrepareError(e) raise PrepareError(e)
# TODO make fstype configurable; both ceph.conf and command line
fstype = 'ext4'
dev = '{disk}1'.format(disk=disk) dev = '{disk}1'.format(disk=disk)
args = [
'mkfs',
'--type={fstype}'.format(fstype=fstype),
]
args.extend(MKFS_ARGS.get(fstype, []))
args.extend([
'--',
dev,
])
try: try:
subprocess.check_call( subprocess.check_call(args=args)
args=[
'mkfs',
'--type={fstype}'.format(fstype=fstype),
'--',
dev,
],
)
except subprocess.CalledProcessError as e: except subprocess.CalledProcessError as e:
raise PrepareError(e) raise PrepareError(e)
@ -210,6 +236,10 @@ def parse_args():
metavar='UUID', metavar='UUID',
help='cluster uuid to assign this disk to', 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( parser.add_argument(
'disk', 'disk',
metavar='DISK', metavar='DISK',
@ -242,8 +272,17 @@ def main():
raise PrepareError( raise PrepareError(
'must have fsid in config or pass --cluster--uuid=', '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( prepare(
disk=args.disk, disk=args.disk,
fstype=args.fs_type,
cluster_uuid=args.cluster_uuid, cluster_uuid=args.cluster_uuid,
) )
except PrepareError as e: except PrepareError as e: