[Plugin] USB_Manager


SimonF

Recommended Posts

16 hours ago, JhonScript said:

I forgot to mention that before testing with the VID 0000 Mouse, I had two xbox 360 controls connected and then I forcibly disconnected them. do not disassociate them

You need to add the script change into the qemu hooks file as per the first post.

 

With the VID Mouse connected, Can you provide me output of /usr/local/emhttp/state/usb.ini and lsusb.

 

Link to comment
On 4/10/2021 at 1:47 AM, SimonF said:

@garydapogiEach VM has a limit on the number of Virtual USB ports, I think the default is 5. I think you can increase, not sure why it would have changed in 6.9.2.

 

You can sometimes clear by powering down VM and restarting. Not reboot has that doesnt release the virtual ports.

 

Also disconnects can sometimes leave devices connected and not freeing up ports..

 

This was the post for increasing ports.

 

 

 

You need to change USB type in template to 

 

image.png.bbbc99e9bebb2afa74a2879e1b338b0b.png

 

This will support 15 ports.

 

Hi @SimonF

 

I'm still experiencing similar error, keyboard gets disconnected randomly. Keeps happening on specific keyboard.

Should I increase the ports? -- (turned out it was already set to 15, which is the maximum)

Error in the USBIP Devices Page:

error: Failed to attach device from /tmp/libvirthotplugusbbybusLinuxMint 20.1.xml error: internal error: No free USB ports 

 

Error in Log:

 

Apr 28 01:07:11 AORUSPROAC kernel: input: SONiX USB Keyboard as /devices/pci0000:00/0000:00:01.2/0000:02:00.0/usb1/1-6/1-6.1/1-6.1:1.0/0003:0C45:9510.0028/input/input88
Apr 28 01:07:11 AORUSPROAC kernel: hid-generic 0003:0C45:9510.0028: input,hidraw0: USB HID v1.11 Keyboard [SONiX USB Keyboard] on usb-0000:02:00.0-6.1/input0
Apr 28 01:07:11 AORUSPROAC kernel: input: SONiX USB Keyboard Consumer Control as /devices/pci0000:00/0000:00:01.2/0000:02:00.0/usb1/1-6/1-6.1/1-6.1:1.1/0003:0C45:9510.0029/input/input89
Apr 28 01:07:11 AORUSPROAC kernel: input: SONiX USB Keyboard System Control as /devices/pci0000:00/0000:00:01.2/0000:02:00.0/usb1/1-6/1-6.1/1-6.1:1.1/0003:0C45:9510.0029/input/input90
Apr 28 01:07:11 AORUSPROAC kernel: input: SONiX USB Keyboard as /devices/pci0000:00/0000:00:01.2/0000:02:00.0/usb1/1-6/1-6.1/1-6.1:1.1/0003:0C45:9510.0029/input/input92
Apr 28 01:07:11 AORUSPROAC kernel: hid-generic 0003:0C45:9510.0029: input,hiddev96,hidraw2: USB HID v1.11 Keyboard [SONiX USB Keyboard] on usb-0000:02:00.0-6.1/input1
Apr 28 01:07:12 AORUSPROAC unraid.usbip-gui: Info: rc.unraid.usbip-gui usb_add SONiX_USB_Keyboard /dev/bus/usb/001/024 001 024
Apr 28 01:07:12 AORUSPROAC unraid.usbip-gui: Info: rc.unraid.usbip-gui Autoconnect vm state:running SONiX_USB_Keyboard running 001 024
Apr 28 01:07:12 AORUSPROAC acpid: input device has been disconnected, fd 6
Apr 28 01:07:12 AORUSPROAC acpid: input device has been disconnected, fd 7
Apr 28 01:07:12 AORUSPROAC acpid: input device has been disconnected, fd 8
Apr 28 01:07:12 AORUSPROAC acpid: input device has been disconnected, fd 9
Apr 28 01:07:31 AORUSPROAC kernel: usb 1-6-port1: disabled by hub (EMI?), re-enabling...
Apr 28 01:07:31 AORUSPROAC kernel: usb 1-6.1: USB disconnect, device number 24
Apr 28 01:07:31 AORUSPROAC unraid.usbip-gui: Info: rc.unraid.usbip-gui usb_remove /dev/bus/usb/001/024 001 024
Apr 28 01:07:31 AORUSPROAC unraid.usbip-gui: Info: rc.unraid.usbip-gui Removed SONiX_USB_Keyboard vm: LinuxMint 20.1 001 024
Apr 28 01:07:31 AORUSPROAC kernel: usb 1-6.1: new low-speed USB device number 25 using xhci_hcd
Apr 28 01:07:31 AORUSPROAC kernel: input: SONiX USB Keyboard as /devices/pci0000:00/0000:00:01.2/0000:02:00.0/usb1/1-6/1-6.1/1-6.1:1.0/0003:0C45:9510.002A/input/input93
Apr 28 01:07:31 AORUSPROAC kernel: hid-generic 0003:0C45:9510.002A: input,hidraw0: USB HID v1.11 Keyboard [SONiX USB Keyboard] on usb-0000:02:00.0-6.1/input0
Apr 28 01:07:31 AORUSPROAC kernel: input: SONiX USB Keyboard Consumer Control as /devices/pci0000:00/0000:00:01.2/0000:02:00.0/usb1/1-6/1-6.1/1-6.1:1.1/0003:0C45:9510.002B/input/input94
Apr 28 01:07:31 AORUSPROAC kernel: input: SONiX USB Keyboard System Control as /devices/pci0000:00/0000:00:01.2/0000:02:00.0/usb1/1-6/1-6.1/1-6.1:1.1/0003:0C45:9510.002B/input/input95
Apr 28 01:07:31 AORUSPROAC kernel: input: SONiX USB Keyboard as /devices/pci0000:00/0000:00:01.2/0000:02:00.0/usb1/1-6/1-6.1/1-6.1:1.1/0003:0C45:9510.002B/input/input97
Apr 28 01:07:31 AORUSPROAC kernel: hid-generic 0003:0C45:9510.002B: input,hiddev96,hidraw2: USB HID v1.11 Keyboard [SONiX USB Keyboard] on usb-0000:02:00.0-6.1/input1
Apr 28 01:07:31 AORUSPROAC unraid.usbip-gui: Info: rc.unraid.usbip-gui usb_add SONiX_USB_Keyboard /dev/bus/usb/001/025 001 025
Apr 28 01:07:32 AORUSPROAC unraid.usbip-gui: Info: rc.unraid.usbip-gui Autoconnect vm state:running SONiX_USB_Keyboard

 

Edited by garydapogi
Link to comment
19 minutes ago, garydapogi said:

Should I increase the ports?

I think they are already at the maximum.

 

When you get the error can you run  virsh qemu-monitor-command "Windows 10" --hmp 'info usb'   replacing Windows 10 with your VM Name i.e. Mintxxxx

 

You should get an output similar to below. Please can you post this output.

 

root@computenode:~# virsh qemu-monitor-command "Windows 10" --hmp 'info usb'
  Device 0.1, Port 1, Speed 480 Mb/s, Product QEMU USB Tablet, ID: input0
  Device 0.2, Port 2, Speed 1.5 Mb/s, Product USB Keyboard, ID: hostdev2
  Device 0.3, Port 3, Speed 1.5 Mb/s, Product USB GAMING MOUSE , ID: hostdev3
  Device 0.0, Port 4, Speed 480 Mb/s, Product UDisk           , ID: hostdev4

Link to comment
On 4/28/2021 at 2:42 AM, SimonF said:

When you get the error can you run  virsh qemu-monitor-command "Windows 10" --hmp 'info usb'   replacing Windows 10 with your VM Name i.e. Mintxxxx

 

So, it happened again, please check output below:

 

Device 0.0, Port 2, Speed 1.5 Mb/s, Product USB Optical Mouse, ID: hostdev5
Device 0.0, Port 4, Speed 12 Mb/s, Product Gaming Mouse, ID: hostdev7
Device 0.0, Port 5, Speed 12 Mb/s, Product Gaming Mouse, ID: hostdev8
Device 0.0, Port 6, Speed 1.5 Mb/s, Product USB Optical Mouse, ID: hostdev9
Device 0.0, Port 7, Speed 12 Mb/s, Product Gaming Mouse, ID: hostdev10
Device 0.0, Port 8, Speed 1.5 Mb/s, Product USB Optical Mouse, ID: hostdev11
Device 0.0, Port 9, Speed 12 Mb/s, Product Gaming Mouse, ID: hostdev12
Device 0.0, Port 10, Speed 12 Mb/s, Product Gaming Mouse, ID: hostdev13
Device 0.0, Port 11, Speed 1.5 Mb/s, Product USB Optical Mouse, ID: hostdev14
Device 0.0, Port 12, Speed 12 Mb/s, Product Gaming Mouse, ID: hostdev15
Device 0.0, Port 13, Speed 1.5 Mb/s, Product USB Optical Mouse, ID: hostdev16
Device 0.0, Port 14, Speed 12 Mb/s, Product Gaming Mouse, ID: hostdev17
Device 0.0, Port 15, Speed 12 Mb/s, Product Gaming Mouse, ID: hostdev18
Device 0.1, Port 1, Speed 1.5 Mb/s, Product USB Keyboard, ID: hostdev19
Device 0.2, Port 3, Speed 1.5 Mb/s, Product USB Optical Mouse, ID: hostdev20

 

Link to comment

@garydapogiOk I can produce the error on my test machine.

 

I thought QEMU removed the device when it was disconnected from the host, but doesn't seem to be the case. Will add function to disconnect the device if udev detects a change.

 

Do you get this once the system wakes up from sleep? Can you provide an extract of your syslog after a wake up so I can see if there are any USB disconnects.

Edited by SimonF
Link to comment
On 4/29/2021 at 1:03 PM, garydapogi said:

 

No, I get the error randomly, while using the VM.

I think I have a fix, will look to release over next few days after a bit more testing. 30.04.21 released

Edited by SimonF
Link to comment
1 hour ago, JoergHH said:

I would like to connect a DVB-C USB stick plugged to a Raspberry Pi to the Plex Docker on the Unraid server to use Live TV & DVR from Plex directly.

Can this work and if so, how?

 

Yes it should work, But I cannot say how performant it will be.

 

Also USBIP has no security so should only be run on a local LAN.

 

If unraid is just going to be the client then you only need to have the vhci_hcd module loaded, Daemon and the usbip_host is only required if you want to attach Unraid connected devices to another host.

 

You will need to install the USBIP on the pi, there are screen prints of pi and unraid on the first page.

 

sudo apt-get install usbip
 

Once installed you need do

 

sudo modprobe usbip_host

sudo usbipd -D to start the Daemon.

 

Add remote host to in plugin.

 

image.thumb.png.a3dde2f5c1ed0c695efe0a3d9ffd222e.png

 

sudo usbip list -l should provide you a list of devices

 

pi@raspberrypi:~ $ usbip list -l
 - busid 1-1 (0930:653e)
   Toshiba Corp. : Flash Memory (0930:653e)

 

sudo bind -b 1-1 this matches your device from the list above.

 

pi@raspberrypi:~ $ sudo usbip bind -b 1-1
usbip: info: bind device on busid 1-1: complete
pi@raspberrypi:~ $

 

image.thumb.png.395dcc73ec09af6986658f5b3f2d68d3.png

 

Click attach

 

image.thumb.png.50651cee8a538f77b8f7411dffa2a8d5.png

 

Device appears in your list of USB devices as if attach locally See Toshiba device at 003 002

 

 

root@computenode:~# lsusb
Bus 004 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 003 Device 002: ID 0930:653e Toshiba Corp. Flash Memory
Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 002: ID 054c:05bf Sony Corp. Hard Drive
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 006: ID 0781:5567 SanDisk Corp. Cruzer Blade
Bus 001 Device 004: ID 0781:5567 SanDisk Corp. Cruzer Blade
Bus 001 Device 011: ID 1c4f:0016 SiGma Micro USB Keyboard
Bus 001 Device 012: ID 04b3:310c IBM Corp. Wheel Mouse
Bus 001 Device 003: ID 05e3:0606 Genesys Logic, Inc. USB 2.0 Hub / D-Link DUB-H4 USB 2.0 Hub
Bus 001 Device 009: ID 05e3:0608 Genesys Logic, Inc. Hub
Bus 001 Device 008: ID 0781:5567 SanDisk Corp. Cruzer Blade
Bus 001 Device 002: ID 048d:04d2 Integrated Technology Express, Inc. UDisk           
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
root@computenode:~# 

 

Edited by SimonF
Link to comment

I think this plugin is exactly what i need to get Home Assistant(HA) VM working with my USB Zigbee coordinator. I'm struggling with where in the qemu script the extra lines posted should be inserted. I tried appending to the end of the file but that throws errors for me. Any help would be appreciated.

 

Original script listed below:

if (!isset($argv[2]) || $argv[2] != 'start') {
        exit(0);
}

$strXML = file_get_contents('php://stdin');

$doc = new DOMDocument();
$doc->loadXML($strXML);

$xpath = new DOMXpath($doc);

$args = $xpath->evaluate("//domain/*[name()='qemu:commandline']/*[name()='qemu:arg']/@value");

for ($i = 0; $i < $args->length; $i++){
        $arg_list = explode(',', $args->item($i)->nodeValue);

        if ($arg_list[0] !== 'vfio-pci') {
                continue;
        }

        foreach ($arg_list as $arg) {
                $keypair = explode('=', $arg);

                if ($keypair[0] == 'host' && !empty($keypair[1])) {
                        vfio_bind($keypair[1]);
                        break;
                }
        }
}

exit(0); // end of script



function vfio_bind($strPassthruDevice) {
        // Ensure we have leading 0000:
        $strPassthruDeviceShort = str_replace('0000:', '', $strPassthruDevice);
        $strPassthruDeviceLong = '0000:' . $strPassthruDeviceShort;

        // Determine the driver currently assigned to the device
        $strDriverSymlink = @readlink('/sys/bus/pci/devices/' . $strPassthruDeviceLong . '/driver');

        if ($strDriverSymlink !== false) {
                // Device is bound to a Driver already

                if (strpos($strDriverSymlink, 'vfio-pci') !== false) {
                        // Driver bound to vfio-pci already - nothing left to do for this device now regarding vfio
                        return true;
                }

                // Driver bound to some other driver - attempt to unbind driver
                if (file_put_contents('/sys/bus/pci/devices/' . $strPassthruDeviceLong . '/driver/unbind', $strPassthruDeviceLong) === false) {
                        file_put_contents('php://stderr', 'Failed to unbind device ' . $strPassthruDeviceShort . ' from current driver');
                        exit(1);
                        return false;
                }
        }

        // Get Vendor and Device IDs for the passthru device
        $strVendor = file_get_contents('/sys/bus/pci/devices/' . $strPassthruDeviceLong . '/vendor');
        $strDevice = file_get_contents('/sys/bus/pci/devices/' . $strPassthruDeviceLong . '/device');

        // Attempt to bind driver to vfio-pci
        if (file_put_contents('/sys/bus/pci/drivers/vfio-pci/new_id', $strVendor . ' ' . $strDevice) === false) {
                file_put_contents('php://stderr', 'Failed to bind device ' . $strPassthruDeviceShort . ' to vfio-pci driver');
                exit(1);
                return false;
        }

        return true;
}

 

Edited by Jayg37
add additional info on code
Link to comment
10 minutes ago, Jayg37 said:

I think this plugin is exactly what i need to get Home Assistant(HA) VM working with my USB Zigbee coordinator. I'm struggling with where in the qemu script the extra lines posted should be inserted. I tried appending to the end of the file but that throws errors for me. Any help would be appreciated.

 

Original script listed below:

 

 

Here is the first lines of my hooks/qemu file

 

root@Tower:/usr/src/linux-5.10.21-Unraid# cat /etc/libvirt/hooks/qemu
#!/usr/bin/env php

<?php

if ($argv[2] == 'prepare' || $argv[2] == 'stopped'){
    shell_exec("/usr/local/emhttp/plugins/unraid.usbip-gui/scripts/rc.unraid.usbip-gui vm_action '{$argv[1]}' {$argv[2]} {$argv[3]} {$argv[4]}  >/dev/null 2>&1 & disown") ;
}

if (!isset($argv[2]) || $argv[2] != 'start') {
        exit(0);
}


 

Link to comment

I have released beta version of USB_Manager.  USBIP-GUi and USB_Manager cannot co-exist and currently there is not an automated upgrade. 

 

You can uninstall USBIP-GUI and Install USB_Manager. Note there is an addon for the USBIP support that needs to be installed.

 

You can copy the configs from usbip-guito the usb_manager as they are compatible.

Link to comment

Looking to get this up and running but getting the following error message "Following are missing or not loaded: USBIP Commands." from the above replies it seems that the "usbip-1 package" is not being installed for whatever reason?

 

I tried uninstalling both plug-ins, restarting unraid, etc however no luck. Any tips? I'm installing the latest "USB Manager (BETA)" from the App store and have not installed any versions of this plugin previously.

 

I can see the libvirt.img was created under a system share.

 

Here are my settings:

 

image.thumb.png.ca9906f8a598d8fabf513ca42d05ac10.png

Edited by Sean M.
Link to comment
10 minutes ago, Sean M. said:

Here are my settings:

Are you running 6.8.3? if yes install usbip plugin also, not the usbip-gui one.

 

Need to disable the install button if not on 6.9.0 and above.

 

Are you looking to use the USBIP functions?

Edited by SimonF
Link to comment
15 minutes ago, SimonF said:

Are you running 6.8.3? if yes install usbip plugin also, not the usbip-gui one.

 

Need to disable the install button if not on 6.9.0 and above.

 

Are you looking to use the USBIP functions?

 

I am running 6.9.2 and not out of the gate planning to use USBIP but just wanted to make sure everything was setup correctly.

Link to comment
6 minutes ago, Sean M. said:

 

I am running 6.9.2 and not out of the gate planning to use USBIP but just wanted to make sure everything was setup correctly.

OK, let me check the checking for the command. if you run usbip from a command line do you see the following output. If you dont need USBIP at present you dont need to enable or install the additional package.

 

root@computenode:~# usbip
usage: usbip [--debug] [--log] [--tcp-port PORT] [version]
             [help] <command> <args>

  attach     Attach a remote USB device
  detach     Detach a remote USB device
  list       List exportable or local USB devices
  bind       Bind device to usbip-host.ko
  unbind     Unbind device from usbip-host.ko
  port       Show imported USB devices

root@computenode:~# 

 

Edited by SimonF
Link to comment
11 minutes ago, SimonF said:

OK, let me check the checking for the command. if you run usbip from a command line do you see the following output. If you dont need USBIP at present you dont need to enable or install the additional package.

 



root@computenode:~# usbip
usage: usbip [--debug] [--log] [--tcp-port PORT] [version]
             [help] <command> <args>

  attach     Attach a remote USB device
  detach     Detach a remote USB device
  list       List exportable or local USB devices
  bind       Bind device to usbip-host.ko
  unbind     Unbind device from usbip-host.ko
  port       Show imported USB devices

root@computenode:~# 

 

 

Results from command line:

 

image.thumb.png.84b76e60b04c9906c259fd0f7700b90a.png

 

And yea if I disable USBIP in the plugin settings then no error and things look as expected :) 

Edited by Sean M.
Link to comment
4 minutes ago, Sean M. said:

 

Results from command line:

 

image.thumb.png.84b76e60b04c9906c259fd0f7700b90a.png

 

And yea once if I disable USBIP in the plugin settings then no error and things look as expected :) 

Just fixed the error, you should see an update in plugin manager to 2021.06.08. Thanks for reporting.

Link to comment
  • 1 month later...

Any one had "Libvirt Service failed to start." - Also still got this following an uninstall:

 

 /etc/libvirt-/hooks/qemu

 

#!/usr/bin/env php

<?php
if (!isset($argv[2]) || $argv[2] != 'start') {
	exit(0);
}

$strXML = file_get_contents('php://stdin');

$doc = new DOMDocument();
$doc->loadXML($strXML);

$xpath = new DOMXpath($doc);

$args = $xpath->evaluate("//domain/*[name()='qemu:commandline']/*[name()='qemu:arg']/@value");

for ($i = 0; $i < $args->length; $i++){
	$arg_list = explode(',', $args->item($i)->nodeValue);

	if ($arg_list[0] !== 'vfio-pci') {
		continue;
	}

	foreach ($arg_list as $arg) {
		$keypair = explode('=', $arg);

		if ($keypair[0] == 'host' && !empty($keypair[1])) {
			vfio_bind($keypair[1]);
			break;
		}
	}
}

exit(0); // end of script



function vfio_bind($strPassthruDevice) {
	// Ensure we have leading 0000:
	$strPassthruDeviceShort = str_replace('0000:', '', $strPassthruDevice);
	$strPassthruDeviceLong = '0000:' . $strPassthruDeviceShort;

	// Determine the driver currently assigned to the device
	$strDriverSymlink = @readlink('/sys/bus/pci/devices/' . $strPassthruDeviceLong . '/driver');

	if ($strDriverSymlink !== false) {
		// Device is bound to a Driver already

	 	if (strpos($strDriverSymlink, 'vfio-pci') !== false) {
	 		// Driver bound to vfio-pci already - nothing left to do for this device now regarding vfio
	 		return true;
	 	}

 		// Driver bound to some other driver - attempt to unbind driver
 		if (file_put_contents('/sys/bus/pci/devices/' . $strPassthruDeviceLong . '/driver/unbind', $strPassthruDeviceLong) === false) {
			file_put_contents('php://stderr', 'Failed to unbind device ' . $strPassthruDeviceShort . ' from current driver');
			exit(1);
			return false;
 		}
	}

	// Get Vendor and Device IDs for the passthru device
	$strVendor = file_get_contents('/sys/bus/pci/devices/' . $strPassthruDeviceLong . '/vendor');
	$strDevice = file_get_contents('/sys/bus/pci/devices/' . $strPassthruDeviceLong . '/device');

	// Attempt to bind driver to vfio-pci
	if (file_put_contents('/sys/bus/pci/drivers/vfio-pci/new_id', $strVendor . ' ' . $strDevice) === false) {
		file_put_contents('php://stderr', 'Failed to bind device ' . $strPassthruDeviceShort . ' to vfio-pci driver');
		exit(1);
		return false;
	}

	return true;

 

Libvirt Log

Quote

2021-07-18 15:36:01.287+0000: 12358: info : libvirt version: 6.5.0
2021-07-18 15:36:01.287+0000: 12358: info : hostname: tbmaindoma
2021-07-18 15:36:01.287+0000: 12358: warning : networkNetworkObjTaint:5292 : Network name='default' uuid=03992cfe-2f56-45e7-a079-c12c04bf2bfe is tainted: hook-script
2021-07-18 15:36:02.412+0000: 12358: warning : qemuDomainObjTaint:6075 : Domain id=1 name='Windows_10' uuid=f38438bf-dc10-f726-455d-5d7d58587c1a is tainted: high-privileges
2021-07-18 15:36:02.412+0000: 12358: warning : qemuDomainObjTaint:6075 : Domain id=1 name='Windows_10' uuid=f38438bf-dc10-f726-455d-5d7d58587c1a is tainted: host-cpu
2021-07-24 10:36:02.265+0000: 12621: error : qemuMonitorIO:578 : internal error: End of file from qemu monitor

 

I have also had the following when installed:

 

Quote

Following are missing or not loaded: usbip_host module vhci_hcd module

 

When installed my config file looks like this:

 

#!/usr/bin/env php

<?php
if (!isset($argv[2]) || $argv[2] != 'start') {
	exit(0);
}

$strXML = file_get_contents('php://stdin');

$doc = new DOMDocument();
$doc->loadXML($strXML);

$xpath = new DOMXpath($doc);

$args = $xpath->evaluate("//domain/*[name()='qemu:commandline']/*[name()='qemu:arg']/@value");

for ($i = 0; $i < $args->length; $i++){
	$arg_list = explode(',', $args->item($i)->nodeValue);

	if ($arg_list[0] !== 'vfio-pci') {
		continue;
	}

	foreach ($arg_list as $arg) {
		$keypair = explode('=', $arg);

		if ($keypair[0] == 'host' && !empty($keypair[1])) {
			vfio_bind($keypair[1]);
			break;
		}
	}
}

exit(0); // end of script



function vfio_bind($strPassthruDevice) {
	// Ensure we have leading 0000:
	$strPassthruDeviceShort = str_replace('0000:', '', $strPassthruDevice);
	$strPassthruDeviceLong = '0000:' . $strPassthruDeviceShort;

	// Determine the driver currently assigned to the device
	$strDriverSymlink = @readlink('/sys/bus/pci/devices/' . $strPassthruDeviceLong . '/driver');

	if ($strDriverSymlink !== false) {
		// Device is bound to a Driver already

	 	if (strpos($strDriverSymlink, 'vfio-pci') !== false) {
	 		// Driver bound to vfio-pci already - nothing left to do for this device now regarding vfio
	 		return true;
	 	}

 		// Driver bound to some other driver - attempt to unbind driver
 		if (file_put_contents('/sys/bus/pci/devices/' . $strPassthruDeviceLong . '/driver/unbind', $strPassthruDeviceLong) === false) {
			file_put_contents('php://stderr', 'Failed to unbind device ' . $strPassthruDeviceShort . ' from current driver');
			exit(1);
			return false;
 		}
	}

	// Get Vendor and Device IDs for the passthru device
	$strVendor = file_get_contents('/sys/bus/pci/devices/' . $strPassthruDeviceLong . '/vendor');
	$strDevice = file_get_contents('/sys/bus/pci/devices/' . $strPassthruDeviceLong . '/device');

	// Attempt to bind driver to vfio-pci
	if (file_put_contents('/sys/bus/pci/drivers/vfio-pci/new_id', $strVendor . ' ' . $strDevice) === false) {
		file_put_contents('php://stderr', 'Failed to bind device ' . $strPassthruDeviceShort . ' to vfio-pci driver');
		exit(1);
		return false;
	}

	return true;
}

 

And my log:

 

Quote

 

2021-07-18 15:36:01.287+0000: 12358: info : libvirt version: 6.5.0
2021-07-18 15:36:01.287+0000: 12358: info : hostname: tbmaindoma
2021-07-18 15:36:01.287+0000: 12358: warning : networkNetworkObjTaint:5292 : Network name='default' uuid=03992cfe-2f56-45e7-a079-c12c04bf2bfe is tainted: hook-script
2021-07-18 15:36:02.412+0000: 12358: warning : qemuDomainObjTaint:6075 : Domain id=1 name='Windows_10' uuid=f38438bf-dc10-f726-455d-5d7d58587c1a is tainted: high-privileges
2021-07-18 15:36:02.412+0000: 12358: warning : qemuDomainObjTaint:6075 : Domain id=1 name='Windows_10' uuid=f38438bf-dc10-f726-455d-5d7d58587c1a is tainted: host-cpu
2021-07-24 10:36:02.265+0000: 12621: error : qemuMonitorIO:578 : internal error: End of file from qemu monitor

 

?

 

Terram

Edited by ccsnet
Link to comment
  • SimonF changed the title to [Plugin] USB_Manager

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.