Note: This bug is displayed in read-only format because the product is no longer active in Red Hat Bugzilla.

Bug 1849095

Summary: qemu-pr-helper does not pass scsi reservations due to qemu mount namespace
Product: Red Hat Enterprise Linux Advanced Virtualization Reporter: Michal Privoznik <mprivozn>
Component: libvirtAssignee: Michal Privoznik <mprivozn>
Status: CLOSED ERRATA QA Contact: gaojianan <jgao>
Severity: high Docs Contact:
Priority: urgent    
Version: 8.2CC: aadam, agk, coli, ehadley, hhan, jdenemar, jgao, jinzhao, jsuchane, juzhang, michal.skrivanek, mprivozn, pvlasin, qinwang, rhodain, virt-maint, yalzhang, yisun
Target Milestone: rcKeywords: Upstream
Target Release: 8.3Flags: pm-rhel: mirror+
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
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.
Story Points: ---
Clone Of: 1839992 Environment:
Last Closed: 2020-07-28 07:13:49 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On: 1839992    
Bug Blocks:    

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