Bug 1849095 - qemu-pr-helper does not pass scsi reservations due to qemu mount namespace
Summary: qemu-pr-helper does not pass scsi reservations due to qemu mount namespace
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Enterprise Linux Advanced Virtualization
Classification: Red Hat
Component: libvirt
Version: 8.2
Hardware: Unspecified
OS: Unspecified
urgent
high
Target Milestone: rc
: 8.3
Assignee: Michal Privoznik
QA Contact: gaojianan
URL:
Whiteboard:
Depends On: 1839992
Blocks:
TreeView+ depends on / blocked
 
Reported: 2020-06-19 15:32 UTC by Michal Privoznik
Modified: 2020-11-19 08:58 UTC (History)
18 users (show)

Fixed In Version: libvirt-6.0.0-25.el8
Doc Type: Bug Fix
Doc Text:
Cause: As a part of fix of 1823976 a patch that I wrote was merged. However, the patch did not do what we think it would. The idea was to use a libdevmapper API to determine whether given path is managed by devmapper or not. If it isn't then devmapper is not consulted any further. If it is, then devmapper is asked to provide list of dependencies for the device. The aforementioned API to determine whether a path is managed or not uses the major() number of a device. So libvirt did stat() and then used major() to get the major number. But it was doing so over wrong member of the stat structure. Long story short, libvirt was passing garbage to devmapper hoping it will figure out what is it we want. Well, it didn't. Consequence: Dependent devices were not created in namespace, nor CGroups and thus SCSI persistent reservations did not work from inside the guest. Fix: The fix is hilarious - I've discovered that libvirt already has the code which asks devmapper the same thing. And it's written correctly. So I've thrown my code out and replaced it with the code that works. Result: SCSI persistent reservations work again.
Clone Of: 1839992
Environment:
Last Closed: 2020-07-28 07:13:49 UTC
Type: Bug
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Red Hat Product Errata RHBA-2020:3172 0 None None None 2020-07-28 07:14:41 UTC

Comment 6 gaojianan 2020-06-28 08:49:41 UTC
Reproduced in libvirt version and get the same results:
libvirt-6.0.0-25.module+el8.2.1+7154+47ffd890.x86_64

Step:
Scenario1:
Edit the qemu.conf namespace as 
namespaces = [ "mount" ]

1.Prepare scsi device and start qemu-pr-helper:
# multipath -ll
mpathb (36001405cd0c22e55a414b35a89d9b955) dm-3 LIO-ORG,device.logical-
size=100M features='0' hwhandler='1 alua' wp=rw
`-+- policy='service-time 0' prio=50 status=active
  `- 15:0:0:0 sdb 8:16 active ready running

#systemctl start qemu-pr-helper
# ps -ef |grep qemu-pr                                                                                           
root      327871       1  0 04:08 ?        00:00:00 /usr/bin/qemu-pr-helper                                                              
root      329690       1  0 04:42 ?        00:00:00 /usr/bin/qemu-pr-helper -k /var/lib/libvirt/qemu/domain-2-avocado-vt-vm1/pr-helper0.sock -f /var/lib/libvirt/qemu/domain-2-avocado-vt-vm1/pr-helper0.pid

2.Prepare a guest and attach xml:
# cat attach.xml
<disk type='block' device='lun'>
      <driver name='qemu' type='raw'/>
      <source dev='/dev/mapper/mpathb'/>
      <reservations managed='yes'>
    </reservations>
<target dev='sdb' bus='scsi'/>
    </disk>

3.Hot-plug the device with 'reservations'
# virsh attach-device avocado-vt-vm1 attach.xml 
Device attached successfully

4.Login the guest and run script as:
# cat test.sh
#! /bin/sh
sg_persist --no-inquiry -v --out --register-ignore --param-sark 123aaa "$@"
sg_persist --no-inquiry --in -k "$@"
sg_persist --no-inquiry -v --out --reserve --param-rk 123aaa --prout-type 5 "$@"
sg_persist --no-inquiry --in -r "$@"
sg_persist --no-inquiry -v --out --release --param-rk 123aaa --prout-type 5 "$@"
sg_persist --no-inquiry --in -r "$@"
sg_persist --no-inquiry -v --out --register --param-rk 123aaa --prout-type 5 "$@"
sg_persist --no-inquiry --in -k "$@"

# sh test.sh /dev/sda
    Persistent reservation out cdb: 5f 06 00 00 00 00 00 00 18 00
PR out: command (Register and ignore existing key) successful
  PR generation=0x1, 1 registered reservation key follows:
    0x123aaa
    Persistent reservation out cdb: 5f 01 05 00 00 00 00 00 18 00
PR out: command (Reserve) successful
  PR generation=0x1, Reservation follows:
    Key=0x123aaa
    scope: LU_SCOPE,  type: Write Exclusive, registrants only
    Persistent reservation out cdb: 5f 02 05 00 00 00 00 00 18 00
PR out: command (Release) successful
  PR generation=0x1, there is NO reservation held
    Persistent reservation out cdb: 5f 00 05 00 00 00 00 00 18 00
PR out: command (Register) successful
  PR generation=0x1, there are NO registered reservation keys

Scenario 2:
Edit the qemu.conf namespace as 
namespaces = [  ]
Also works well

So verified as expected

Comment 8 errata-xmlrpc 2020-07-28 07:13:49 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHBA-2020:3172


Note You need to log in before you can comment on or make changes to this bug.