libvirt scsi passthrough troubles

Goal:

I would like to make a SATA optical drive available to a vm.

Attempted solution:

The docs and every post I have stumbled upon indicate the the solution is the following snippet:


<controller type='scsi' index='0' model='virtio-scsi'/> 
<hostdev mode='subsystem' type='scsi'>
  <source>
  <adapter name='scsi_host2'/>
  <address type='scsi' bus='0' target='0' unit='0'/>
  </source>
  <readonly/> 
  <address type='drive' controller='0' bus='0' target='0' unit='0'/>
</hostdev>

So I change the value of scsi_hostN according to the output of lsscsi

$ lsscsi
 [1:0:0:0]    cd/dvd  HL-DT-ST DVD+-RW GSA-H73N C106  /dev/sr0

and I virsh edit the vm. It gets changed to the following by libvirt:

    <controller type='scsi' index='0' model='virtio-scsi'>
      <address type='pci' domain='0x0000' bus='0x08' slot='0x00' function='0x0'/>
    </controller>
    ...
    <hostdev mode='subsystem' type='scsi' managed='no'>
      <source>
        <adapter name='scsi_host1'/>
        <address bus='0' target='0' unit='0'/>
      </source>
      <readonly/>
      <address type='drive' controller='0' bus='0' target='0' unit='0'/>
    </hostdev>

And when I try to start the vm:

$ virsh -c qemu:///system start myDomain1
error: Failed to start domain 'myDomain1'
error: cannot open directory '/sys/bus/scsi/devices/1:0:0:0/scsi_generic': No such file or directory

Here’s the content of the parent directory of the nonexistant scsi_generic file/dir in case it reveals something

$ ls -l /sys/devices/pci0000:00/0000:00:17.0/ata2/host1/target1:0:0/1:0:0:0 | awk '{print $1 " [...] " $9 $10 $11}'
total [...]
-r--r--r-- [...] access_state
-r--r--r-- [...] blacklist
drwxr-xr-x [...] block
drwxr-xr-x [...] bsg
-rw-r--r-- [...] cdl_enable
-r--r--r-- [...] cdl_supported
--w------- [...] delete
-r--r--r-- [...] device_blocked
-r--r--r-- [...] device_busy
-rw-r--r-- [...] dh_state
lrwxrwxrwx [...] driver -> ../../../../../../../bus/scsi/drivers/sr
-rw-r--r-- [...] eh_timeout
-r--r--r-- [...] evt_capacity_change_reported
-r--r--r-- [...] evt_inquiry_change_reported
-r--r--r-- [...] evt_lun_change_reported
-r--r--r-- [...] evt_media_change
-r--r--r-- [...] evt_mode_parameter_change_reported
-r--r--r-- [...] evt_soft_threshold_reached
-r--r--r-- [...] inquiry
-r--r--r-- [...] iocounterbits
-r--r--r-- [...] iodone_cnt
-r--r--r-- [...] ioerr_cnt
-r--r--r-- [...] iorequest_cnt
-r--r--r-- [...] iotmo_cnt
-r--r--r-- [...] modalias
-r--r--r-- [...] model
-rw-r--r-- [...] ncq_prio_enable
-r--r--r-- [...] ncq_prio_supported
drwxr-xr-x [...] power
-r--r--r-- [...] preferred_path
-rw-r--r-- [...] queue_depth
-rw-r--r-- [...] queue_ramp_up_period
-rw-r--r-- [...] queue_type
--w------- [...] rescan
-r--r--r-- [...] rev
drwxr-xr-x [...] scsi_device
-r--r--r-- [...] scsi_level
-rw-r--r-- [...] state
lrwxrwxrwx [...] subsystem -> ../../../../../../../bus/scsi
-rw-r--r-- [...] sw_activity
-rw-r--r-- [...] timeout
-r--r--r-- [...] type
-rw-r--r-- [...] uevent
-rw-r--r-- [...] unload_heads
-r--r--r-- [...] vendor
-r--r--r-- [...] wwid

I have tried virsh editing the hostdev out but keeping the controller, to see if hot plugging the drive is possible, but it did not work.

Questions:

  1. What does the scsi_generic file or directory represent?
  2. Why is libvirt looking for this scsi_generic?
    I see from ancient scriptures that “Sg is a SCSI command pass through device that uses a char device interface. … Applications such as SANE (for scanners), cdrecord and cdrdao (for cd writers) and cdparanoia (for reading audio CDs digitally) use sg.” But a differnt section says sg and sr are essentailly equivalent. So I am wondering if scsi_generic is related to this and if there is some xml to change to use sr instead since the drive shows up as sr0 on the host, or maybe some host driver or config to look at.