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: Iustin Pop <iustin@google.com>
Reviewed-by: Michael Hanselmann <hansmi@google.com>
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.
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):