Skip to content

Commit

Permalink
CA-286144: add usb-scan systemd units
Browse files Browse the repository at this point in the history
udev does not tolerate the time it can take for XAPI to complete a
pUSB rescan request. Use a service listening on a socket to perform
the scan request so that the udev action just becomes writing to a
non-blocking pipe.
  • Loading branch information
Simon Rowe committed Nov 5, 2018
1 parent 26096a2 commit f64dd9d
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 2 deletions.
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@ install: precheck
$(SM_STAGING)/$(SYSTEMD_SERVICE_DIR)
install -m 644 systemd/xs-sm.service \
$(SM_STAGING)/$(SYSTEMD_SERVICE_DIR)
install -m 644 systemd/usb-scan.* \
$(SM_STAGING)/$(SYSTEMD_SERVICE_DIR)
for i in $(UDEV_RULES); do \
install -m 644 udev/$$i.rules \
$(SM_STAGING)$(UDEV_RULES_DIR); done
Expand Down
4 changes: 2 additions & 2 deletions scripts/usb_change
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@
#
# called by UDEV rule to trigger pusb scan, when USB device change is detected

. /etc/xensource-inventory
xe pusb-scan host-uuid=${INSTALLATION_UUID}
# wake up usb-scan.service waiting on the pipe
dd if=/dev/zero of=/var/run/usb-scan.sock bs=8 count=1 status=none conv=notrunc,noerror oflag=nonblock
7 changes: 7 additions & 0 deletions systemd/usb-scan.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Unit]
Description=USB device scanner

[Service]
StandardInput=socket
ExecStart=/usr/bin/sh -c '. /etc/xensource-inventory; while dd of=/dev/null bs=4096 count=1 status=none conv=noerror; do xe pusb-scan host-uuid=$${INSTALLATION_UUID}; done'
Restart=always
9 changes: 9 additions & 0 deletions systemd/usb-scan.socket
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[Unit]
Before=systemd-udevd

[Socket]
ListenFIFO=/var/run/usb-scan.sock
PipeSize=4096

[Install]
WantedBy=multi-user.target

0 comments on commit f64dd9d

Please sign in to comment.