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
Protect against colons in pvdisplay output #2903
Conversation
LVM can be configured to show device names under /dev/disk/by-path in command output. These names often contain colons that separate fields like channel and target (for example /dev/disk/by-path/pci-*-scsi-0:0:1:0-*, similarly the pci-* part, which contains colon-separated PCI bus and device numbers). Since the "pvdisplay -c" output also uses colons as field separators and does not escape embedded colons in any way, embedded colons break parsing of this output. As a fix, use the pipe character '|' as the field separator in pvdisplay output. (This would break if a PV device has a '|' in its name, but this is very much less likely than having a ':' .) Also, configure explicitly what fields to output - "pvdisplay -c" prints many fields, but I have not found documentation about what fields is it using exactly, so one had to guess what the output means. Using "pvdisplay -C" and selecting the fields explicitly is much clearer. This also changes the PV size field to match documentation, the comment says that size is in bytes, but it actually was not in bytes. As nothing is actually using the PV size field, this inconsistency has not caused any problem in practice, and no code needs adjusting for the change.
|
@pcahyna I think when we have '|' as field separator I remove all space characters via The sets the non-standard IFS value only for the 'read' command |
|
Hello @jsmeix , thank you for the suggestion, but I must say I am reluctant to make such changes to the layout code, if there is no bug to fix (except the bug fixed by the PR in the current form) . |
|
@pcahyna I had meant it only as a suggestion for further improvement. |
Protect against colons in pvdisplay output
Pull Request Details:
Type: Bug Fix
Impact: Normal
Reference to related issue (URL): fixes Support by-path PVs #1958
How was this pull request tested?
/dev/disk/by-pathdevice symlinks instead of the usual/dev/sd*device nodes by using this line in /etc/lvm/lvm.conf:filter = [ "r|/dev/disk/by-path/.*-usb-|", "a|/dev/disk/by-path/pci-.*-nvme-|", "a|/dev/disk/by-path/pci-.*-scsi-|", "a|/dev/disk/by-path/pci-.*-ata-|", "a|/dev/disk/by-path/pci-.*-sas-|", "a|loop|", "r|.*|" ].This case breaks with the original code already during
rear savelayoutand is fixed by this change.Brief description of the changes in this pull request:
LVM can be configured to show device names under
/dev/disk/by-pathin command output. These names often contain colons that separate fields like channel and target (for example/dev/disk/by-path/pci-*-scsi-0:0:1:0-*, similarly thepci-*part, which contains colon-separated PCI bus and device numbers). Since the "pvdisplay -c" output also uses colons as field separators and does not escape embedded colons in any way, embedded colons break parsing of this output.As a fix, use the pipe character '
|' as the field separator in pvdisplay output. (This would break if a PV device has a '|' in its name, but this is very much less likely than having a ':' .)I did a survey of how similar problems are handled in other tools. Some Solaris tools (ipadm, dladm, zoneadm) have a special switch (
-p) to request machine-parseable format. This format has colon-separated fields, and embedded colons are escaped by backslash to allow parsing by the shell "read" command (this escaping is the key functionality missing in the pvdisplay command). zfs has a-Hoption which uses an alternative parseable format: in addition to omitting headers it separates the fields by a single TAB character. This would be in principle ideal for our purpose (TABs are unlikely to occur in the values), but in our case the output is processed via an unquoted "echo" command, which would not preserve the TAB character. (This is needed to remove the two leading spaces in the output, not sure what their purpose is.) I believe that using|as the separator is the best choice in our situation.Also, configure explicitly what fields to output - "
pvdisplay -c" prints many fields, but I have not found documentation about what fields is it using exactly, so one had to guess what the output means. Using "pvdisplay -C" and selecting the fields explicitly is much clearer.This also changes the PV size field to match documentation, the comment says that size is in bytes, but it actually was not in bytes. As nothing is actually using the PV size field, this inconsistency has not caused any problem in practice, and no code needs adjusting for the change.
Fix provided by a customer in https://bugzilla.redhat.com/show_bug.cgi?id=2091163 .