How does 'virsh' determine (iscsi) unit names and can they be changed?

I've got a kvm host running that has and iscsi backed storage pool:

virsh # pool-info mypool
Name:           mypool
UUID:           913210f2-f8a0-4a56-b7bf-ef00b0080ee1
State:          running
Persistent:     yes
Autostart:      yes
Capacity:       2,00 TiB
Allocation:     2,00 TiB
Available:      0,00 B

The pool has just one volume (which is a LUN) at the moment:

virsh # vol-list mypool
Name                 Path                                    
-----------------------------------------
unit:0:0:1           /dev/disk/by-path/ip-192.168.44.44:3260-iscsi-iqn.2016-08.iscsihost:volume-lun-1

How is the name or that volume determined? Bonus question: The iscsi target uses 'tgtd'. It seems that the volume name cannot be influenced by setting the 'vendor_id' or 'product_id' of the LUN. Is there a way to have more pretty names (ideally, the LUN is create for a particular VM and that name shows up in virsh's vol-list or the virt-manager GUI)?


Looks like it's hard coded and it looks like the iscsi and scsi backends share some code.

scsi storage backend (re: device name assignment unit:x:x:x) : https://github.com/libvirt/libvirt/blob/master/src/storage/storage_backend_scsi.c#L197

storage backend (re: iSCSI uses unit:): https://github.com/libvirt/libvirt/blob/master/src/storage/storage_driver.c#L3364

I don't understand all the code so here the rest of the storage stuff: https://github.com/libvirt/libvirt/tree/master/src/storage

Have you tried mounting and accessing the iscsi targets as regular files (as a "dir" pool) from libvirt? Maybe they then won't have ambiguous names. https://libvirt.org/storage.html#StorageBackendDir

I don't use iSCSI, but I use ZFS and have it configured like this:

<pool type='dir'>
  <name>pool2</name>
  <uuid>e725f5e4-3f9b-44a9-a47c-2b04cb154636</uuid>
  <capacity unit='bytes'>0</capacity>
  <allocation unit='bytes'>0</allocation>
  <available unit='bytes'>0</available>
  <source>
  </source>
  <target>
    <path>/dev/zvol/pool2</path>
  </target>
</pool>

So the device names looks like this

root@igor:~# virsh  vol-list pool2
 Name                 Path                                    
------------------------------------------------------------------------------
 echo_root            /dev/zvol/pool2/echo_root               
 echo_root-part1      /dev/zvol/pool2/echo_root-part1         
 echo_root-part2      /dev/zvol/pool2/echo_root-part2         
 echo_root-part5      /dev/zvol/pool2/echo_root-part5         
 landscape_root       /dev/zvol/pool2/landscape_root          
 landscape_root-part1 /dev/zvol/pool2/landscape_root-part1    
 landscape_root-part2 /dev/zvol/pool2/landscape_root-part2    
 landscape_root-part5 /dev/zvol/pool2/landscape_root-part5    
 mail_root            /dev/zvol/pool2/mail_root               
 mail_root-part1      /dev/zvol/pool2/mail_root-part1         
 mail_root-part2      /dev/zvol/pool2/mail_root-part2         
 mail_root-part5      /dev/zvol/pool2/mail_root-part5         
 spectre_root         /dev/zvol/pool2/spectre_root            
 spectre_root-part1   /dev/zvol/pool2/spectre_root-part1      
 spectre_root-part2   /dev/zvol/pool2/spectre_root-part2      
 swap                 /dev/zvol/pool2/swap                    
 test                 /dev/zvol/pool2/test                    
 www1_root            /dev/zvol/pool2/www1_root               
 www1_root-part1      /dev/zvol/pool2/www1_root-part1         
 www1_root-part2      /dev/zvol/pool2/www1_root-part2         
 www1_root-part5      /dev/zvol/pool2/www1_root-part5