Skip to content

Commit 0300dce

Browse files
authored
Merge pull request ceph#64323 from guits/cv-seastore
ceph-volume: add seastore OSDs support Reviewed-by: Adam King <[email protected]> Reviewed-by: Matan Breizman <[email protected]> Reviewed-by: Yingxin Cheng <[email protected]>
2 parents a1baaa6 + 1b83235 commit 0300dce

File tree

24 files changed

+450
-435
lines changed

24 files changed

+450
-435
lines changed

src/ceph-volume/ceph_volume/activate/main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
import argparse
44

55
from ceph_volume import terminal
6-
from ceph_volume.objectstore.lvmbluestore import LvmBlueStore as LVMActivate
7-
from ceph_volume.objectstore.rawbluestore import RawBlueStore as RAWActivate
6+
from ceph_volume.objectstore.lvm import Lvm as LVMActivate
7+
from ceph_volume.objectstore.raw import Raw as RAWActivate
88
from ceph_volume.devices.simple.activate import Activate as SimpleActivate
99

1010

src/ceph-volume/ceph_volume/devices/lvm/batch.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,7 @@ def main(self) -> None:
373373
def _execute(self, plan: List["OSD"]) -> None:
374374
defaults = common.get_default_args()
375375
global_args = [
376+
'objectstore',
376377
'bluestore',
377378
'dmcrypt',
378379
'with_tpm',
@@ -417,8 +418,7 @@ def get_deployment_layout(self) -> List["OSD"]:
417418
return plan
418419
requested_osds = self.args.osds_per_device * len(phys_devs) + len(lvm_devs)
419420

420-
if self.args.objectstore == 'bluestore':
421-
fast_type = 'block_db'
421+
fast_type = 'block_db'
422422
fast_allocations = self.fast_allocations(fast_devices,
423423
requested_osds,
424424
num_osds,

src/ceph-volume/ceph_volume/devices/lvm/zap.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ def zap_device(path: str) -> None:
2323
Args:
2424
path (str): The path to the device to zap.
2525
"""
26-
zap_bluestore(path)
26+
if disk.has_bluestore_label(path):
27+
zap_bluestore(path)
2728
wipefs(path)
2829
zap_data(path)
2930

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
1-
from . import lvmbluestore
2-
from . import rawbluestore
1+
from . import lvm
2+
from . import raw
33
from typing import Any, Dict
4+
from enum import Enum
45

56

7+
class ObjectStore(str, Enum):
8+
bluestore: str = 'bluestore'
9+
seastore: str = 'seastore'
10+
611
mapping: Dict[str, Any] = {
712
'LVM': {
8-
'bluestore': lvmbluestore.LvmBlueStore
13+
ObjectStore.bluestore: lvm.Lvm,
14+
ObjectStore.seastore: lvm.Lvm
915
},
1016
'RAW': {
11-
'bluestore': rawbluestore.RawBlueStore
17+
ObjectStore.bluestore: raw.Raw
1218
}
1319
}

src/ceph-volume/ceph_volume/objectstore/baseobjectstore.py

Lines changed: 85 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,18 @@ def __init__(self, args: "argparse.Namespace") -> None:
3232
self.osd_id: str = ''
3333
self.osd_fsid: str = ''
3434
self.cephx_lockbox_secret: str = ''
35-
self.objectstore: str = ''
35+
self.objectstore: str = getattr(args, "objectstore", '')
3636
self.osd_mkfs_cmd: List[str] = []
3737
self.block_device_path: str = ''
3838
self.dmcrypt_key: str = encryption_utils.create_dmcrypt_key()
3939
self.with_tpm: int = int(getattr(self.args, 'with_tpm', False))
4040
self.method: str = ''
41+
self.osd_path: str = ''
42+
self.key: Optional[str] = None
43+
self.block_device_path: str = ''
44+
self.wal_device_path: str = ''
45+
self.db_device_path: str = ''
46+
self.block_lv: Optional[Volume] = None
4147
if getattr(self.args, 'dmcrypt', False):
4248
self.encrypted = 1
4349
if not self.with_tpm:
@@ -68,7 +74,41 @@ def safe_prepare(self, args: Optional["argparse.Namespace"] = None) -> None:
6874
raise NotImplementedError()
6975

7076
def add_objectstore_opts(self) -> None:
71-
raise NotImplementedError()
77+
"""
78+
Create the files for the OSD to function. A normal call will look like:
79+
80+
ceph-osd --cluster ceph --mkfs --mkkey -i 0 \
81+
--monmap /var/lib/ceph/osd/ceph-0/activate.monmap \
82+
--osd-data /var/lib/ceph/osd/ceph-0 \
83+
--osd-uuid 8d208665-89ae-4733-8888-5d3bfbeeec6c \
84+
--keyring /var/lib/ceph/osd/ceph-0/keyring \
85+
--setuser ceph --setgroup ceph
86+
87+
In some cases it is required to use the keyring, when it is passed
88+
in as a keyword argument it is used as part of the ceph-osd command
89+
"""
90+
91+
if self.wal_device_path:
92+
self.osd_mkfs_cmd.extend(
93+
['--bluestore-block-wal-path', self.wal_device_path]
94+
)
95+
system.chown(self.wal_device_path)
96+
97+
if self.db_device_path:
98+
self.osd_mkfs_cmd.extend(
99+
['--bluestore-block-db-path', self.db_device_path]
100+
)
101+
system.chown(self.db_device_path)
102+
103+
if self.get_osdspec_affinity():
104+
self.osd_mkfs_cmd.extend(['--osdspec-affinity',
105+
self.get_osdspec_affinity()])
106+
107+
def unlink_bs_symlinks(self) -> None:
108+
for link_name in ['block', 'block.db', 'block.wal']:
109+
link_path = os.path.join(self.osd_path, link_name)
110+
if os.path.exists(link_path):
111+
os.unlink(os.path.join(self.osd_path, link_name))
72112

73113
def prepare_osd_req(self, tmpfs: bool = True) -> None:
74114
# create the directory
@@ -116,10 +156,8 @@ def build_osd_mkfs_cmd(self) -> List[str]:
116156
]
117157
if self.cephx_secret is not None:
118158
self.osd_mkfs_cmd.extend(['--keyfile', '-'])
119-
try:
120-
self.add_objectstore_opts()
121-
except NotImplementedError:
122-
logger.info("No specific objectstore options to add.")
159+
160+
self.add_objectstore_opts()
123161

124162
self.osd_mkfs_cmd.extend(self.supplementary_command)
125163
return self.osd_mkfs_cmd
@@ -154,6 +192,20 @@ def osd_mkfs(self) -> None:
154192
raise RuntimeError('Command failed with exit code %s: %s' %
155193
(returncode, ' '.join(cmd)))
156194

195+
mapping: Dict[str, Any] = {'raw': ['data', 'block_db', 'block_wal'],
196+
'lvm': ['ceph.block_device', 'ceph.db_device', 'ceph.wal_device']}
197+
if self.args.dmcrypt:
198+
for dev_type in mapping[self.method]:
199+
if self.method == 'raw':
200+
path = self.args.__dict__.get(dev_type, None)
201+
else:
202+
if self.block_lv is not None:
203+
path = self.block_lv.tags.get(dev_type, None)
204+
else:
205+
raise RuntimeError('Unexpected error while running bluestore mkfs.')
206+
if path is not None:
207+
encryption_utils.CephLuks2(path).config_luks2({'subsystem': f'ceph_fsid={self.osd_fsid}'})
208+
157209
def activate(self) -> None:
158210
raise NotImplementedError()
159211

@@ -179,3 +231,30 @@ def enroll_tpm2(self, device: str) -> None:
179231
device, '--unlock-key-file', temp_file_name,
180232
'--tpm2-pcrs', '9+12', '--wipe-slot', 'tpm2']
181233
process.call(cmd, run_on_host=True, show_command=True)
234+
235+
def add_label(self, key: str,
236+
value: str,
237+
device: str) -> None:
238+
"""Add a label to a BlueStore device.
239+
Args:
240+
key (str): The name of the label being added.
241+
value (str): Value of the label being added.
242+
device (str): The path of the BlueStore device.
243+
Raises:
244+
RuntimeError: If `ceph-bluestore-tool` command doesn't success.
245+
"""
246+
247+
command: List[str] = ['ceph-bluestore-tool',
248+
'set-label-key',
249+
'-k',
250+
key,
251+
'-v',
252+
value,
253+
'--dev',
254+
device]
255+
256+
_, err, rc = process.call(command,
257+
terminal_verbose=True,
258+
show_command=True)
259+
if rc:
260+
raise RuntimeError(f"Can't add BlueStore label '{key}' to device {device}: {err}")

src/ceph-volume/ceph_volume/objectstore/bluestore.py

Lines changed: 0 additions & 109 deletions
This file was deleted.

src/ceph-volume/ceph_volume/objectstore/lvmbluestore.py renamed to src/ceph-volume/ceph_volume/objectstore/lvm.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from ceph_volume.systemd import systemctl
1010
from ceph_volume.devices.lvm.common import rollback_osd
1111
from ceph_volume.devices.lvm.listing import direct_report
12-
from .bluestore import BlueStore
12+
from .baseobjectstore import BaseObjectStore
1313
from typing import Dict, Any, Optional, List, TYPE_CHECKING
1414

1515
if TYPE_CHECKING:
@@ -19,7 +19,7 @@
1919
logger = logging.getLogger(__name__)
2020

2121

22-
class LvmBlueStore(BlueStore):
22+
class Lvm(BaseObjectStore):
2323
def __init__(self, args: "argparse.Namespace") -> None:
2424
super().__init__(args)
2525
self.method = 'lvm'
@@ -59,6 +59,7 @@ def pre_prepare(self) -> None:
5959
self.block_lv = self.prepare_data_device('block', self.osd_fsid)
6060
self.block_device_path = self.block_lv.__dict__['lv_path']
6161

62+
self.tags['ceph.objectstore'] = self.objectstore
6263
self.tags['ceph.block_device'] = self.block_lv.__dict__['lv_path']
6364
self.tags['ceph.block_uuid'] = self.block_lv.__dict__['lv_uuid']
6465
self.tags['ceph.cephx_lockbox_secret'] = self.cephx_lockbox_secret
@@ -392,12 +393,14 @@ def _activate(self,
392393
# ``prime-osd-dir`` can succeed even if permissions are
393394
# somehow messed up.
394395
system.chown(self.osd_path)
395-
prime_command = [
396-
'ceph-bluestore-tool', '--cluster=%s' % conf.cluster,
397-
'prime-osd-dir', '--dev', osd_lv_path,
398-
'--path', self.osd_path, '--no-mon-config']
399-
400-
process.run(prime_command)
396+
objectstore = osd_block_lv.tags.get('ceph.objectstore', 'bluestore')
397+
if objectstore == 'bluestore':
398+
prime_command = [
399+
'ceph-bluestore-tool', '--cluster=%s' % conf.cluster,
400+
'prime-osd-dir', '--dev', osd_lv_path,
401+
'--path', self.osd_path, '--no-mon-config']
402+
403+
process.run(prime_command)
401404
# always re-do the symlink regardless if it exists, so that the block,
402405
# block.wal, and block.db devices that may have changed can be mapped
403406
# correctly every time

src/ceph-volume/ceph_volume/objectstore/rawbluestore.py renamed to src/ceph-volume/ceph_volume/objectstore/raw.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import logging
22
import json
33
import os
4-
from .bluestore import BlueStore
4+
from .baseobjectstore import BaseObjectStore
55
from ceph_volume import terminal, decorators, conf, process
66
from ceph_volume.util import system, disk
77
from ceph_volume.util import prepare as prepare_utils
@@ -17,7 +17,7 @@
1717
logger = logging.getLogger(__name__)
1818

1919

20-
class RawBlueStore(BlueStore):
20+
class Raw(BaseObjectStore):
2121
def __init__(self, args: "argparse.Namespace") -> None:
2222
super().__init__(args)
2323
self.method = 'raw'
File renamed without changes.

0 commit comments

Comments
 (0)