-
Notifications
You must be signed in to change notification settings - Fork 244
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Btrfs filesystem show JSON format support #761
base: master
Are you sure you want to change the base?
Conversation
Introduce helper functions for printing the filesystem data and list of devices. This prepares the both printing code paths of filesystem show to support json output. Signed-off-by: Jelle van der Waa <[email protected]>
To support JSON formatted output for `filesystem show` stdout can't contain warnings, the warning macro prints to stderr.
Implements JSON-formatted output for the `filesystem show` command using the `--format json` global option. Devices are in a `device-list` array, optionally showing if a device is missing. Signed-off-by: Jelle van der Waa <[email protected]>
a42f5cd
to
75d699b
Compare
Generally no, but there are a few exceptions. The ioctl and block methods build the device list from sources with different information availability. The ioctl (mounted) method can simply read the chunk tree from the kernel and get all information about all devices except for path, which is filled in by searching /dev and matching up devuuids (there's some udev in between, but /dev + brute-force search is the ultimate source of the information). This can build a complete list of missing device IDs, UUIDs, and sizes (which are stored in the metadata) but not paths (which are missing by definition) or any data that requires the path as an input (such as device slack or rotational status). Consistency is expected because btrfs wouldn't mount the filesystem otherwise (the information could change while The block device method reads the superblock of every device available in /dev, which tells it how many devices to expect per filesystem and the devid and devuuid of every device that is present. No information is available about devices that are missing. The number of missing devices is the difference between the number of devices found and the number of devices expected. If the number of devices expected is lower than the largest device ID in the filesystem, then it's not possible to tell which device IDs are missing from the available information. If number of devices expected is equal to the largest device ID, then the missing devices are any devid numbers between 1 and the number of devices expected that are not found during the superblock search. If there's an existing device ID that is higher than For both methods to behave like the ioctl case, you'd have to read the device tree from the metadata to get the device list (i.e. emulate the ioctl in userspace). If too many devices are missing or there's inconsistent superblocks present, reading the tree won't be possible, and the block device method is the only option. |
Thanks for the detailed information @Zygo, do you consider not having the missing devices in the output a blocker for merging this PR? |
The JSON output should be consistent with the legacy text output in either mounted or unmounted cases, and the missing devices reports are important, so I think we do need to figure out how to represent them in JSON. The number of devices is always known (every device's superblock has a
Missing devices never have paths--a device with a path is not missing. The converse isn't always true--if a Missing devices might not have IDs. You might know that there are 3 devices, but if only 1 device is online, and you can't read the device tree, you don't know what any of the missing device IDs are. To add another wrinkle, device replace adds an additional device with devid 0, without changing devid shouldn't be an integer if the device is missing and the devid is unknown--even negative numbers are off limits, as they may conflict with some future btrfs extension. For that matter...same with "size" and "used", they should only be present when known. 0 is a valid value for both: size is set to 0 during device delete, and a device could be empty.
That might be useful to have as a separate filesystem-level field in either mounted or unmounted cases. It could be a count of the number of devices that are known to be missing: in the mounted case, the number of devices where the missing attribute is true, and in the unmounted case, the difference between the number of devices expected vs found. |
Introduce JSON format support for
btrfs subvolume show
, there are two ways this information can be obtained either via an ioctl or via reading the block device. So I have taken the liberty of merging the print paths together in a re-usable function before adding JSON support.I've chosen to format the JSON as I would have expected, an Object with "metadata" and the list of devices as part of that under
device-list
. See for example a single device volume:There is one open issue, when you have an unmounted btrfs volume with multiple devices where one is missing it won't show up the json output:
I could add a
missing_devices
property to the btrfs filesystem information but then that is inconsistent with the mounted missing device output (where it is a missing property in the device object).Is it possible to show what device is missing for the unmounted case? So
btrfs subvolume show
would be consistent either way? (Seems device id is known, not sure about the path?).