PCI: hotplug: Add 'uevent' sysfs attribute to trigger slot events
Subsystems (3)
v6 cover PCI: hotplug: Add 'uevent' sysfs attribute to trigger slot events
Hi all,
This patch adds support for synthesizing PCI hotplug slot uevents via a sysfs attribute.
The patch has been rebased on top of the current upstream development branch and addresses the feedback received during previous review rounds. In particular, the unnecessary ".show = NULL" assignment noted during review has been removed.
The Reviewed-by and Tested-by tags from the previous revision have been retained.
I'd appreciate any additional feedback. Please let me know if further changes are needed.
Thanks,
Ramesh Errabolu
Changes in v6:
- Remove unnecessary .show = NULL as suggested by Bjorn Helgaas
- Rebase onto the latest upstream development branch
Ramesh Errabolu (1):
PCI: hotplug: Add 'uevent' sysfs attribute to trigger slot events
drivers/pci/hotplug/pci_hotplug_core.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+)
Signature · 1 line
2.43.0
PATCH v6 1/1 PCI: hotplug: Add 'uevent' sysfs attribute to trigger slot events
Add a write-only 'uevent' sysfs attribute for synthesizing uevents for a PCI slot. This extends the existing uevent support which emits a KOBJ_ADD uevent in pci_hp_add() with the ability to replay such uevents for cold plugged devices. As such events are only emitted by hotplug capable PCI slots so is the support for synthesizing them.
The change was validated by manually triggering 'add' uevent for a specific hotplug PCI slot:
$ echo "add $(uuidgen)" | sudo tee \
/sys/bus/pci/slots/<slot-id>/uevent--- drivers/pci/hotplug/pci_hotplug_core.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+)
drivers/pci/hotplug/pci_hotplug_core.c +24 -0
@@ -173,12 +173,26 @@ static ssize_t presence_read_file(struct pci_slot *pci_slot, char *buf)static struct pci_slot_attribute hotplug_slot_attr_presence = { .attr = {.name ="adapter" , .mode =S_IFREG |S_IRUGO }, .show = presence_read_file, }; +static ssize_t uevent_write_file (struct pci_slot *slot, +const char *buf,size_t len) +{ +int rc; + + rc =kobject_synth_uevent (&slot->kobj, buf, len); +return rc ? rc : len; +} + +static struct pci_slot_attribute hotplug_slot_attr_uevent = { + .attr = {.name ="uevent" , .mode =S_IFREG |0200 }, + .store = uevent_write_file +}; +static ssize_t test_write_file (struct pci_slot *pci_slot,const char *buf,size_t count) {struct hotplug_slot *slot = pci_slot->hotplug;unsigned long ltest;u32 test;
@@ -251,12 +265,17 @@ static int fs_add_slot(struct hotplug_slot *slot, struct pci_slot *pci_slot)if (retval)dev_err (&pci_slot->bus->dev,"Error creating sysfs link (%d)\n" , retval);kobject_put (kobj); } + retval =sysfs_create_file (&pci_slot->kobj, + &hotplug_slot_attr_uevent.attr); +if (retval) + goto exit_uevent; +if (has_power_file (slot)) { retval =sysfs_create_file (&pci_slot->kobj, &hotplug_slot_attr_power.attr);if (retval) goto exit_power; }
@@ -303,19 +322,24 @@ static int fs_add_slot(struct hotplug_slot *slot, struct pci_slot *pci_slot)sysfs_remove_file (&pci_slot->kobj, &hotplug_slot_attr_attention.attr); exit_attention:if (has_power_file (slot))sysfs_remove_file (&pci_slot->kobj, &hotplug_slot_attr_power.attr); exit_power: +sysfs_remove_file (&pci_slot->kobj, + &hotplug_slot_attr_uevent.attr); +exit_uevent:sysfs_remove_link (&pci_slot->kobj,"module" ); exit:return retval; }static void fs_remove_slot (struct hotplug_slot *slot,struct pci_slot *pci_slot) { +sysfs_remove_file (&pci_slot->kobj, &hotplug_slot_attr_uevent.attr); +if (has_power_file (slot))sysfs_remove_file (&pci_slot->kobj, &hotplug_slot_attr_power.attr);if (has_attention_file (slot))sysfs_remove_file (&pci_slot->kobj, &hotplug_slot_attr_attention.attr);
Signature · 1 line
2.43.0
[email protected]
AI reviewSashiko has reviewed this patch and found no issues. It looks great!
Quoted 7 lines
Add a write-only 'uevent' sysfs attribute for synthesizing uevents for a PCI slot. This extends the existing uevent support which emits a
KOBJ_ADDuevent inpci_hp_add()with the ability to replay such uevents for cold plugged devices. As such events are only emitted by hotplug capable PCI slots so is the support for synthesizing them.
Quoted 7 lines
The change was validated by manually triggering 'add' uevent for a specific hotplug PCI slot:
$ echo "add $(uuidgen)" | sudo tee \ /sys/bus/pci/slots/<slot-id>/ueventSigned-off-by Ramesh Errabolu <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Quoted 7 lines · Ramesh Errabolu
Add a write-only 'uevent' sysfs attribute for synthesizing uevents for a PCI slot. This extends the existing uevent support which emits a
KOBJ_ADDuevent inpci_hp_add()with the ability to replay such uevents for cold plugged devices. As such events are only emitted by hotplug capable PCI slots so is the support for synthesizing them.
Quoted 7 lines
The change was validated by manually triggering 'add' uevent for a specific hotplug PCI slot:
$ echo "add $(uuidgen)" | sudo tee \ /sys/bus/pci/slots/<slot-id>/ueventSigned-off-by Ramesh Errabolu <[email protected]>
- Mani
Signature · 1 line
மணிவண்ணன் சதாசிவம்