Bug 862253

Summary: [lvmetad] deadlock
Product: Red Hat Enterprise Linux 6 Reporter: Marian Csontos <mcsontos>
Component: lvm2Assignee: Petr Rockai <prockai>
Status: CLOSED ERRATA QA Contact: Cluster QE <mspqa-list>
Severity: high Docs Contact:
Priority: high    
Version: 6.4CC: agk, cmarthal, coughlan, dwysocha, heinzm, jbrassow, msnitzer, prajnoha, prockai, thornber, zkabelac
Target Milestone: rc   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: lvm2-2.02.98-1.el6 Doc Type: Bug Fix
Doc Text:
Under relatively heavy load (many parallel LVM commands running) lvmetad could deadlock and cause other LVM commands to stop responding. The problem has been tracked down to a race condition in lvmetad's multi-threaded code and has been fixed.
Story Points: ---
Clone Of: Environment:
Last Closed: 2013-02-21 08:14:12 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:

Description Marian Csontos 2012-10-02 13:04:50 UTC
Description of problem:
running pvs in parallel may result in deadlock

Version-Release number of selected component (if applicable):
- upstream git commit 886656e4 (nightly build 2.02.98-0.183.el6.x86_64)

How reproducible:
- low

Steps to Reproduce:
1. run few pvs in parallel
  
Actual results:
deadlock

Expected results:
both command should succeed

Additional info:
## Thread_16 waiting for lock_vg, hold by Thread_20 acquired on Line_130 in lock_vg

    Thread 16 (Thread 0x7f7b73eef700 (LWP 4086)):
    #0  __lll_lock_wait () at ../nptl/sysdeps/unix/sysv/linux/x86_64/lowlevellock.S:136
    #1  0x00007f7b746e73a3 in _L_lock_892 () from /lib64/libpthread.so.0
    #2  0x00007f7b746e7287 in __pthread_mutex_lock (mutex=0x7f7b6c001d00)
        at pthread_mutex_lock.c:82
    #3  0x0000000000402ee9 in lock_vg (s=0x7fffb5b85ef0, 
        id=0x12692a0 "yxBztw-XtbD-vYva-nnNA-mdpf-vxvK-4wWLLe") at lvmetad-core.c:130
    #4  0x0000000000404777 in vg_lookup (s=..., h=..., r=...) at lvmetad-core.c:431
    #5  handler (s=..., h=..., r=...) at lvmetad-core.c:955
    #6  0x00000000004052e4 in client_thread (baton=0x1144150) at daemon-server.c:391
    #7  0x00007f7b746e5851 in start_thread (arg=0x7f7b73eef700) at pthread_create.c:301
    #8  0x00007f7b7443367d in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:115

### lock_vg - owned by Thread_20

    #2  0x00007f7b746e7287 in __pthread_mutex_lock (mutex=0x7f7b6c001d00)
    (gdb) print mutex->__data.__owner
    $6 = 4066 # Thread_20

## Thread_20 waiting for lock_vgid_to_metadata, hold by Thread_16 acquired on Line_115 in lock_vg

    Thread 20 (Thread 0x7f7b716eb700 (LWP 4066)):
    #0  __lll_lock_wait () at ../nptl/sysdeps/unix/sysv/linux/x86_64/lowlevellock.S:136
    #1  0x00007f7b746e73a3 in _L_lock_892 () from /lib64/libpthread.so.0
    #2  0x00007f7b746e7287 in __pthread_mutex_lock (mutex=0x7fffb5b85f60)
        at pthread_mutex_lock.c:82
    #3  0x0000000000402dce in lock_vgid_to_metadata (s=0x7fffb5b85ef0, 
        id=0x128f720 "yxBztw-XtbD-vYva-nnNA-mdpf-vxvK-4wWLLe") at lvmetad-core.c:87
    #4  unlock_vg (s=0x7fffb5b85ef0, id=0x128f720 "yxBztw-XtbD-vYva-nnNA-mdpf-vxvK-4wWLLe")
        at lvmetad-core.c:140
    #5  0x000000000040488b in vg_lookup (s=..., h=..., r=...) at lvmetad-core.c:467
    #6  handler (s=..., h=..., r=...) at lvmetad-core.c:955
    #7  0x00000000004052e4 in client_thread (baton=0x1167060) at daemon-server.c:391
    #8  0x00007f7b746e5851 in start_thread (arg=0x7f7b716eb700) at pthread_create.c:301
    #9  0x00007f7b7443367d in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:115

### lock_vgid_to_metadata - owned by Thread_16:

    #2  0x00007f7b746e7287 in __pthread_mutex_lock (mutex=0x7fffb5b85f60)
    (gdb) print mutex->__data.__owner
    $8 = 4086 # Thread_16

Comment 2 Petr Rockai 2012-10-08 14:33:50 UTC
Should be fixed upstream now.

Comment 3 Alasdair Kergon 2012-10-08 16:07:18 UTC
What was wrong?  How was it fixed?

Comment 5 Petr Rockai 2012-10-09 09:12:33 UTC
commit 6e312c56adb04e709819868c6fa89f5984013a65
    lvmetad: Avoid overlapping locks that could cause a deadlock (BZ 862253).

The bug was present in 6.3 as well, but apparently never tripped. The fix was relatively easy (see patch: git log 6e312c56adb04e709819868c6fa89f5984013a65 -p -n 1).

Comment 6 Petr Rockai 2012-10-12 09:10:23 UTC
To QA: The reproducer should be the original bug description, i.e. run "pvs" in parallel while lvmetad is running. When lvmetad stops responding, you have hit the bug. (I didn't manage to reproduce the problem myself, but I could see the problem in the source code. Marian should be able to reproduce this. I'd say if you stress-test lvmetad with parallel access from multiple LVM commands for a while and don't hit a deadlock, it's as verified as it gets).

Comment 9 Corey Marthaler 2013-01-24 21:48:55 UTC
I was unable to hit a deadlock, but I was able to hit what appears to be bug 889361 fairly easily.

# run 20 pvs in parallel:

  [...]
  Skipping volume group raid_sanity
  Volume group "raid_sanity" not found
  Request to list PVs in lvmetad gave response Connection reset by peer.

Jan 24 15:30:10 hayes-03 kernel: lvmetad[25889] general protection ip:3a97a76205 sp:7f1b1cdf9b90 error:0 in libc-2.12.so[3a97a00000+18a000]


[root@hayes-03 ~]# pvscan
  WARNING: Failed to connect to lvmetad: Connection refused. Falling back to internal scanning.
  PV /dev/etherd/e1.1p1    VG raid_sanity   lvm2 [908.23 GiB / 907.93 GiB free]
  PV /dev/etherd/e1.1p10   VG raid_sanity   lvm2 [908.23 GiB / 908.23 GiB free]
  PV /dev/etherd/e1.1p2    VG raid_sanity   lvm2 [908.23 GiB / 908.23 GiB free]

Comment 11 errata-xmlrpc 2013-02-21 08:14:12 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.

http://rhn.redhat.com/errata/RHBA-2013-0501.html