Note: This is a beta release of Red Hat Bugzilla 5.0. The data contained within is a snapshot of the live data so any changes you make will not be reflected in the production Bugzilla. Also email is disabled so feel free to test any aspect of the site that you want. File any problems you find or give feedback here.
Bug 1517374 - $parent variable expansion producing empty string when called from udev rule
Summary: $parent variable expansion producing empty string when called from udev rule
Keywords:
Status: CLOSED NOTABUG
Alias: None
Product: Fedora
Classification: Fedora
Component: systemd
Version: 27
Hardware: Unspecified
OS: Linux
unspecified
medium
Target Milestone: ---
Assignee: systemd-maint
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2017-11-24 17:02 UTC by John Pittman
Modified: 2017-11-27 14:37 UTC (History)
8 users (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2017-11-27 14:37:02 UTC


Attachments (Terms of Use)

Description John Pittman 2017-11-24 17:02:44 UTC
Description of problem:

When attempting to use $parent or %P in a udev rule, the variable expansion is not working.  Instead of producing the parent node name, it produces a blank string.

Version-Release number of selected component (if applicable):

systemd-udev-234-9.fc27.x86_64
kernel-4.13.13-300.fc27.x86_64
systemd-234-9.fc27.x86_64
libgudev-232-1.fc27.x86_64

How reproducible:

[root@localhost ~]# udevadm control --reload

[root@localhost ~]# udevadm trigger

[root@localhost ~]# cat /etc/udev/rules.d/99-test.rules 
KERNEL=="sdc", SUBSYSTEM=="block", SYMLINK+="parent_dir/%k-parent_node-%P-test_disk"

[root@localhost ~]# ls -lah /dev/parent_dir/
total 0
drwxr-xr-x.  2 root root   60 Nov 24 11:43 .
drwxr-xr-x. 23 root root 3.9K Nov 24 11:43 ..
lrwxrwxrwx.  1 root root    6 Nov 24 11:57 sdc-parent_node--test_disk -> ../sdc

Actual results:

$parent/%P produces a blank string

Expected results:

Should produce the node name of the parent as mentioned in the man page.

       $parent, %P
           The node name of the parent device.

Additional info:

[root@localhost ~]# udevadm info --attribute-walk --name=sdc

Udevadm info starts with the device specified by the devpath and then
walks up the chain of parent devices. It prints for every device
found, all possible attributes in the udev rules key format.
A rule to match, can be composed by the attributes of the device
and the attributes from one single parent device.

  looking at device '/devices/pci0000:00/0000:00:08.0/virtio2/host2/target2:0:0/2:0:0:2/block/sdc':
    KERNEL=="sdc"
    SUBSYSTEM=="block"
    DRIVER==""
    ATTR{alignment_offset}=="0"
    ATTR{capability}=="50"
    ATTR{discard_alignment}=="0"
    ATTR{events}==""
    ATTR{events_async}==""
    ATTR{events_poll_msecs}=="-1"
    ATTR{ext_range}=="256"
    ATTR{inflight}=="       0        0"
    ATTR{range}=="16"
    ATTR{removable}=="0"
    ATTR{ro}=="0"
    ATTR{size}=="2097152"
    ATTR{stat}=="     123        0      830       13        0        0        0        0        0       13       13"

  looking at parent device '/devices/pci0000:00/0000:00:08.0/virtio2/host2/target2:0:0/2:0:0:2':
    KERNELS=="2:0:0:2"
    SUBSYSTEMS=="scsi"
    DRIVERS=="sd"
    ATTRS{device_blocked}=="0"
    ATTRS{device_busy}=="0"
[ ...snip ]

[root@localhost ~]# udevadm info --query=all --name=sdc
P: /devices/pci0000:00/0000:00:08.0/virtio2/host2/target2:0:0/2:0:0:2/block/sdc
N: sdc
S: disk/by-id/scsi-0QEMU_QEMU_HARDDISK_drive-scsi0-0-0-2
S: disk/by-path/pci-0000:00:08.0-scsi-0:0:0:2
S: parent_dir/sdc-parent_node--test_disk
E: DEVLINKS=/dev/disk/by-path/pci-0000:00:08.0-scsi-0:0:0:2 /dev/parent_dir/sdc-parent_node--test_disk /dev/disk/by-id/scsi-0QEMU_QEMU_HARDDISK_drive-scsi0-0-0-2
E: DEVNAME=/dev/sdc
E: DEVPATH=/devices/pci0000:00/0000:00:08.0/virtio2/host2/target2:0:0/2:0:0:2/block/sdc
E: DEVTYPE=disk
E: ID_BUS=scsi
E: ID_FS_LABEL=localhost.localdomain:3
E: ID_FS_LABEL_ENC=localhost.localdomain:3
E: ID_FS_TYPE=linux_raid_member
E: ID_FS_USAGE=raid
E: ID_FS_UUID=0bf8614f-86db-3ac5-956d-fa9417e7f4cc
E: ID_FS_UUID_ENC=0bf8614f-86db-3ac5-956d-fa9417e7f4cc
E: ID_FS_UUID_SUB=1fa52e61-ad12-29ae-f3ca-3b024a8ce190
E: ID_FS_UUID_SUB_ENC=1fa52e61-ad12-29ae-f3ca-3b024a8ce190
E: ID_FS_VERSION=1.2
E: ID_MODEL=QEMU_HARDDISK
E: ID_MODEL_ENC=QEMU\x20HARDDISK\x20\x20\x20
E: ID_PATH=pci-0000:00:08.0-scsi-0:0:0:2
E: ID_PATH_TAG=pci-0000_00_08_0-scsi-0_0_0_2
E: ID_REVISION=2.5+
E: ID_SCSI=1
E: ID_SERIAL=0QEMU_QEMU_HARDDISK_drive-scsi0-0-0-2
E: ID_SERIAL_SHORT=drive-scsi0-0-0-2
E: ID_TYPE=disk
E: ID_VENDOR=QEMU
E: ID_VENDOR_ENC=QEMU\x20\x20\x20\x20
E: MAJOR=8
E: MINOR=32
E: SUBSYSTEM=block
E: TAGS=:systemd:
E: UDISKS_MD_MEMBER_DEVICES=3
E: UDISKS_MD_MEMBER_DEV_UUID=1fa52e61:ad1229ae:f3ca3b02:4a8ce190
E: UDISKS_MD_MEMBER_EVENTS=28
E: UDISKS_MD_MEMBER_LEVEL=raid0
E: UDISKS_MD_MEMBER_NAME=localhost.localdomain:3
E: UDISKS_MD_MEMBER_UPDATE_TIME=1508441859
E: UDISKS_MD_MEMBER_UUID=0bf8614f:86db3ac5:956dfa94:17e7f4cc
E: USEC_INITIALIZED=3782595

Comment 2 John Pittman 2017-11-27 14:37:02 UTC
Closing as NOTABUG.  Solution provided in comment 8 of bz1517377.  The below rule should work.

KERNEL=="sdc", SUBSYSTEM=="block", KERNELS=="[0-9]*:*[0-9]" SYMLINK+="parent_dir/%k-parent_node-%b-test_disk"


Note You need to log in before you can comment on or make changes to this bug.