Commit 705ee6df authored by Iustin Pop's avatar Iustin Pop
Browse files

lvmstrap: add explicit test for swap backends



Similar to mounted filesystems, recent kernel/userland report swap
backends:

    root@node4:~# fuser -avm /dev/sda6
                         USER        PID ACCESS COMMAND
    /dev/sda6:           root     kernel swap  /dev/sda6

But old ones not:

    node1# fuser -avm /dev/sda6
                         USER        PID ACCESS COMMAND
    /dev/sda6:

So we add an explicit test for swap backends using /proc/swaps.
Signed-off-by: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarMichael Hanselmann <hansmi@google.com>
parent 5e861051
......@@ -489,6 +489,14 @@ def GetMountInfo():
return mounts
def GetSwapInfo():
"""Reads /proc/swaps and returns the list of swap backing stores.
"""
swaplines = ReadFile("/proc/swaps").splitlines()[1:]
return [line.split(None, 1)[0] for line in swaplines]
def DevInfo(name, dev, mountinfo):
"""Computes miscellaneous information about a block device.
......@@ -637,12 +645,20 @@ def CheckMounted(name):
return dev not in minfo
def CheckSwap(name):
"""Check to see if a block device is being used as swap.
"""
name = "/dev/%s" % name
return name not in GetSwapInfo()
def InUse(name):
"""Returns if a disk is in use or not.
"""
return not (CheckSysfsHolders(name) and CheckReread(name) and
CheckMounted(name))
CheckMounted(name) and CheckSwap(name))
def WipeDisk(name):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment