Hi,
I had a go at creating a snap for USB/IP today. The use case it to start the usbip daemon, bind device(s), and attach them to a remote system via the network.
I got it working, but unfortunately the raw-usb
interface is not quite enough, and I had to expose some /sys
files using the system-files
interface. There a few problems with this technique, it feels like an abuse of the interface and because it does not support any globbing or wildcards it means any snap would have to be very hardware specific in terms of devices and how they connected.
There is also a slight issue with kernel revision support, but I will gloss over that for now
Here is the rough snapcraft.yaml
I got working for testing:
name: usbip
base: core20
summary: USB over IP
description: |
USB over IP server and setup
confinement: strict
#adopt-info: ci-metadata
version: 5.4.0-77.000
plugs:
usb-bind:
interface: system-files
write:
- /sys/bus/usb/drivers/usb/bind
- /sys/bus/usb/drivers/usb/unbind
- /sys/bus/usb/drivers/usbip-host
# This is hardware dependant - required for devices under: /sys/devices/pci0000:00/0000:00:14.0/usb1/1-2/usbip_sockfd
#- /sys/devices/pci0000:00/0000:00:14.0/usb1
- /sys/devices/pci0000:00/0000:00:14.0/usb1/1-2/usbip_sockfd
apps:
module-setup:
command: sbin/modprobe -a usbip_core usbip_host
daemon: oneshot
plugs:
- kernel-module-control
daemon:
command: usr/lib/linux-tools/5.4.0-77-generic/usbipd
environment:
PYTHONPATH: $SNAP/usr/lib/python3/dist-packages:/usr/lib/python3/dist-packages
daemon: simple
restart-condition: on-failure
restart-delay: 3s
after:
- module-setup
plugs:
- raw-usb
- usb-bind
- network-bind
bind:
command: usr/lib/linux-tools/5.4.0-77-generic/usbip bind -b 1-2
environment:
PYTHONPATH: $SNAP/usr/lib/python3/dist-packages:/usr/lib/python3/dist-packages
plugs:
- raw-usb
- usb-bind
- network
unbind:
command: usr/lib/linux-tools/5.4.0-77-generic/usbip unbind -b 1-2
environment:
PYTHONPATH: $SNAP/usr/lib/python3/dist-packages:/usr/lib/python3/dist-packages
plugs:
- raw-usb
- usb-bind
- network
list:
command: usr/lib/linux-tools/5.4.0-77-generic/usbip list -l
plugs:
- raw-usb
- network
layout:
/usr/share/hwdata/usb.ids:
symlink: $SNAP/usr/share/hwdata/usb.ids
parts:
usbip:
plugin: nil
stage-packages:
- linux-tools-5.4.0-77-generic
- linux-tools-common
- kmod
- usbutils
- hwdata
Is this a case for a new snapd interface ?
I guess it would have to support parameters to it could be locked to particular PCI paths and devices.
On a side note, this is where I noticed that globbing is not supported for the system-files
interface, so I really can’t do this with that interface in any elegant way: Glob patterns with the system-file interface - #2 by jdstrand
If I am to peruse this, what’s the best way ? Is there something I’m not thinking of here ?
Cheers, Just