hothd-usb: Bind service lifetime to its USB device

hothd-usb@.service has no dependency on the USB device it serves. When
the USB tree is reset (some platforms reset the USB hubs more than once
during boot from their platform init scripts), hothd fails with "Lost
connection with Hoth" and Restart=always schedules a restart 5s later.
If that restart fires while the device is still gone, hothd_usb.sh
finds no HOTH_USB_NAMES entry, exits 10 ("Missing mapping"), and
RestartPreventExitStatus=10 keeps the unit dead for the rest of the
boot. If the udev add event for the returning device lands while that
start job is still running, it is merged into it and nothing starts the
unit again.

Seen in the field: one Hoth instance never registered on D-Bus after
boot and stayed missing until the next power cycle.

Add BindsTo=%i.device and After=%i.device. The instance name is the
escaped sysfs path that udev passes via SYSTEMD_WANTS, so %i.device is
the device unit for that port. systemd now stops the service when the
device disappears (a stop, so Restart= does not fire), refuses to start
it while the device is absent, and udev starts it again when the device
returns, with the device present.

This needs the device unit to exist. 70-hothd-usb.rules only matched
ACTION=="add", so the "bind" uevent that follows every USB add dropped
the systemd tag from CURRENT_TAGS and systemd never created (or
removed) the .device unit. With BindsTo alone every hothd-usb instance
was stopped. Match ACTION!="remove|unbind" so the tag sticks across
bind and change events, and drops as soon as the driver detaches: on
"unbind" the device unit goes inactive and BindsTo stops hothd, and a
later "bind" plugs it again and starts hothd once.

Tested: on a gBMC with three Hoth USB devices behind a downstream hub,
cycled the hub (hub driver unbind/bind) 12 times while forcing a unit
restart during the gap, rebinding 0.3s-3.0s later, 35s apart.
  Before (stock rules + unit):
    Missing mapping / status=10: 12/12 iterations, 24 starts, 12 failed
  After (this change, as /etc overrides):
    Missing mapping / status=10: 0/12, 12 starts, 0 failed
    restart while device absent -> "Dependency failed", then
    "Starting"/"Started" when the device returns
  Hub down without a forced restart: device unit and service
  inactive (dead), not failed; running again 2s after the hub returns.
  USB driver unbind/bind of one Hoth device (device stays enumerated):
    on unbind CURRENT_TAGS is empty, device unit and service go
    inactive (dead), nothing restarts hothd; after bind it is running
    again in 1s, one start per cycle.
  All 7 hothd-usb units and 8 Hoth D-Bus objects stayed up otherwise.

Google-Bug-Id: 581687485
Change-Id: Id807e77074e2ae0ece40ee0f8bd5affbfa787b74
2 files changed