1 from __future__
import print_function
5 from textwrap
import dedent
6 from ceph_volume
import decorators
, process
7 from ceph_volume
.util
import disk
10 logger
= logging
.getLogger(__name__
)
13 def direct_report(devices
):
15 Other non-cli consumers of listing information will want to consume the
16 report without the need to parse arguments or other flags. This helper
17 bypasses the need to deal with the class interface which is meant for cli
21 return _list
.generate(devices
)
23 def _get_bluestore_info(dev
):
24 out
, err
, rc
= process
.call([
25 'ceph-bluestore-tool', 'show-label',
26 '--dev', dev
], verbose_on_failure
=False)
28 # ceph-bluestore-tool returns an error (below) if device is not bluestore OSD
29 # > unable to read label for <device>: (2) No such file or directory
30 # but it's possible the error could be for a different reason (like if the disk fails)
31 logger
.debug('assuming device {} is not BlueStore; ceph-bluestore-tool failed to get info from device: {}\n{}'.format(dev
, out
, err
))
33 oj
= json
.loads(''.join(out
))
35 # should be impossible, so warn
36 logger
.warning('skipping device {} because it is not reported in ceph-bluestore-tool output: {}'.format(dev
, out
))
40 'osd_uuid': oj
[dev
]['osd_uuid'],
42 if oj
[dev
]['description'] == 'main':
43 whoami
= oj
[dev
]['whoami']
46 'osd_id': int(whoami
),
47 'ceph_fsid': oj
[dev
]['ceph_fsid'],
50 elif oj
[dev
]['description'] == 'bluefs db':
52 elif oj
[dev
]['description'] == 'bluefs wal':
56 # this will appear for devices that have a bluestore header but aren't valid OSDs
57 # for example, due to incomplete rollback of OSDs: https://tracker.ceph.com/issues/51869
58 logger
.error('device {} does not have all BlueStore data needed to be a valid OSD: {}\n{}'.format(dev
, out
, e
))
64 help = 'list BlueStore OSDs on raw devices'
66 def __init__(self
, argv
):
69 def generate(self
, devs
=None):
70 logger
.debug('Listing block devices via lsblk...')
71 info_devices
= disk
.lsblk_all(abspath
=True)
72 if devs
is None or devs
== []:
73 # If no devs are given initially, we want to list ALL devices including children and
74 # parents. Parent disks with child partitions may be the appropriate device to return if
75 # the parent disk has a bluestore header, but children may be the most appropriate
76 # devices to return if the parent disk does not have a bluestore header.
77 devs
= [device
['NAME'] for device
in info_devices
if device
.get('NAME',)]
80 logger
.debug('inspecting devices: {}'.format(devs
))
82 # Linux kernels built with CONFIG_ATARI_PARTITION enabled can falsely interpret
83 # bluestore's on-disk format as an Atari partition table. These false Atari partitions
84 # can be interpreted as real OSDs if a bluestore OSD was previously created on the false
85 # partition. See https://tracker.ceph.com/issues/52060 for more info. If a device has a
86 # parent, it is a child. If the parent is a valid bluestore OSD, the child will only
87 # exist if it is a phantom Atari partition, and the child should be ignored. If the
88 # parent isn't bluestore, then the child could be a valid bluestore OSD. If we fail to
89 # determine whether a parent is bluestore, we should err on the side of not reporting
90 # the child so as not to give a false negative.
91 for info_device
in info_devices
:
92 if 'PKNAME' in info_device
and info_device
['PKNAME'] != "":
93 parent
= info_device
['PKNAME']
95 if disk
.has_bluestore_label(parent
):
96 logger
.warning(('ignoring child device {} whose parent {} is a BlueStore OSD.'.format(dev
, parent
),
97 'device is likely a phantom Atari partition. device info: {}'.format(info_device
)))
100 logger
.error(('ignoring child device {} to avoid reporting invalid BlueStore data from phantom Atari partitions.'.format(dev
),
101 'failed to determine if parent device {} is BlueStore. err: {}'.format(parent
, e
)))
104 bs_info
= _get_bluestore_info(dev
)
106 # None is also returned in the rare event that there is an issue reading info from
107 # a BlueStore disk, so be sure to log our assumption that it isn't bluestore
108 logger
.info('device {} does not have BlueStore information'.format(dev
))
110 uuid
= bs_info
['osd_uuid']
111 if uuid
not in result
:
113 result
[uuid
].update(bs_info
)
117 @decorators.needs_root
118 def list(self
, args
):
119 report
= self
.generate(args
.device
)
120 if args
.format
== 'json':
121 print(json
.dumps(report
, indent
=4, sort_keys
=True))
124 raise SystemExit('No valid Ceph devices found')
125 raise RuntimeError('not implemented yet')
128 sub_command_help
= dedent("""
129 List OSDs on raw devices with raw device labels (usually the first
130 block of the device).
132 Full listing of all identifiable (currently, BlueStore) OSDs
137 List a particular device, reporting all metadata about it::
139 ceph-volume raw list /dev/sda1
142 parser
= argparse
.ArgumentParser(
143 prog
='ceph-volume raw list',
144 formatter_class
=argparse
.RawDescriptionHelpFormatter
,
145 description
=sub_command_help
,
152 help='Path to a device like /dev/sda1'
157 help='output format, defaults to "pretty"',
159 choices
=['json', 'pretty'],
162 args
= parser
.parse_args(self
.argv
)