From 85cdc783008ff0e0566c34aaab7cd5f12db1cbc7 Mon Sep 17 00:00:00 2001 From: Alfredo Deza Date: Mon, 16 Oct 2017 06:51:05 -0400 Subject: [PATCH] ceph-volume util.prepare separate filestore vs. bluestore prepare utils Signed-off-by: Alfredo Deza --- src/ceph-volume/ceph_volume/util/prepare.py | 82 ++++++++++++++++++++- 1 file changed, 78 insertions(+), 4 deletions(-) diff --git a/src/ceph-volume/ceph_volume/util/prepare.py b/src/ceph-volume/ceph_volume/util/prepare.py index 58d43d9b22a3b..ebec603b030c3 100644 --- a/src/ceph-volume/ceph_volume/util/prepare.py +++ b/src/ceph-volume/ceph_volume/util/prepare.py @@ -57,8 +57,21 @@ def create_id(fsid, json_secrets): return ' '.join(stdout).strip() -def create_path(osd_id): +def mount_tmpfs(path): + process.run([ + 'sudo', + 'mount', + '-t', + 'tmpfs', 'tmpfs', + path + ]) + + +def create_osd_path(osd_id, tmpfs=False): + path = '/var/lib/ceph/osd/%s-%s' % (conf.cluster, osd_id) system.mkdir_p('/var/lib/ceph/osd/%s-%s' % (conf.cluster, osd_id)) + if tmpfs: + mount_tmpfs(path) def format_device(device): @@ -110,6 +123,8 @@ def _link_device(device, device_type, osd_id): device_type ) command = ['sudo', 'ln', '-s', device, device_path] + system.chown(device) + process.run(command) @@ -122,11 +137,11 @@ def link_block(block_device, osd_id): def link_wal(wal_device, osd_id): - _link_device(wal_device, 'wal', osd_id) + _link_device(wal_device, 'block.wal', osd_id) def link_db(db_device, osd_id): - _link_device(db_device, 'db', osd_id) + _link_device(db_device, 'block.db', osd_id) def get_monmap(osd_id): @@ -152,7 +167,64 @@ def get_monmap(osd_id): ]) -def osd_mkfs(osd_id, fsid): +def osd_mkfs_bluestore(osd_id, fsid, keyring=None, wal=False, db=False): + """ + Create the files for the OSD to function. A normal call will look like: + + ceph-osd --cluster ceph --mkfs --mkkey -i 0 \ + --monmap /var/lib/ceph/osd/ceph-0/activate.monmap \ + --osd-data /var/lib/ceph/osd/ceph-0 \ + --osd-uuid 8d208665-89ae-4733-8888-5d3bfbeeec6c \ + --keyring /var/lib/ceph/osd/ceph-0/keyring \ + --setuser ceph --setgroup ceph + + In some cases it is required to use the keyring, when it is passed in as + a keywork argument it is used as part of the ceph-osd command + """ + path = '/var/lib/ceph/osd/%s-%s/' % (conf.cluster, osd_id) + monmap = os.path.join(path, 'activate.monmap') + wal_path = os.path.join(path, 'block.wal') + db_path = os.path.join(path, 'block.db') + + system.chown(path) + + base_command = [ + 'sudo', + 'ceph-osd', + '--cluster', conf.cluster, + # undocumented flag, sets the `type` file to contain 'bluestore' + '--osd-objectstore', 'bluestore', + '--mkfs', + '-i', osd_id, + '--monmap', monmap, + ] + + supplementary_command = [ + '--osd-data', path, + '--osd-uuid', fsid, + '--setuser', 'ceph', + '--setgroup', 'ceph' + ] + + if keyring is not None: + base_command.extend(['--key', keyring]) + + if wal: + base_command.extend( + ['--bluestore-block-wal-path', wal_path] + ) + + if db: + base_command.extend( + ['--bluestore-block-db-path', db_path] + ) + + command = base_command + supplementary_command + + process.run(command, obfuscate='--key') + + +def osd_mkfs_filestore(osd_id, fsid): """ Create the files for the OSD to function. A normal call will look like: @@ -176,6 +248,8 @@ def osd_mkfs(osd_id, fsid): 'sudo', 'ceph-osd', '--cluster', conf.cluster, + # undocumented flag, sets the `type` file to contain 'filestore' + '--osd-objectstore', 'filestore', '--mkfs', '-i', osd_id, '--monmap', monmap, -- 2.39.5