util: Fix gem5img when used to manually unmount a disk image.
authorRichard Cooper <richard.cooper@arm.com>
Fri, 2 Oct 2020 16:50:07 +0000 (17:50 +0100)
committerRichard Cooper <richard.cooper@arm.com>
Mon, 1 Feb 2021 09:48:02 +0000 (09:48 +0000)
When unmounting a disk image manually using the
`gem5img umount mount_point` command, the operation can fail if the
process is unable to stat any of the mounts in the mount table. On
some systems this can occur even when running using sudo.

Added an exception check so any mount points that fail to stat will not
cause the whole script to terminate early.

Change-Id: I69cd2494ad0e8c989e19ecd8af8a811905cd6c09
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/39897
Reviewed-by: Bobby R. Bruce <bbruce@ucdavis.edu>
Reviewed-by: Gabe Black <gabe.black@gmail.com>
Maintainer: Bobby R. Bruce <bbruce@ucdavis.edu>
Maintainer: Gabe Black <gabe.black@gmail.com>
Tested-by: kokoro <noreply+kokoro@google.com>
util/gem5img.py

index 616dd7259bda00c3cee2f0ef1849ee3315f31254..9523a77222b5e483b938368ba6995e45981d7972 100755 (executable)
@@ -208,8 +208,11 @@ def mountPointToDev(mountPoint):
     mountTable = mountTable.splitlines()
     for line in mountTable:
         chunks = line.split()
-        if os.path.samefile(chunks[2], mountPoint):
-            return LoopbackDevice(chunks[0])
+        try:
+            if os.path.samefile(chunks[2], mountPoint):
+                return LoopbackDevice(chunks[0])
+        except OSError:
+            continue
     return None
 
 
@@ -283,8 +286,8 @@ def mountComFunc(options, args):
 mountCom.func = mountComFunc
 
 # A command to unmount the first partition in the image.
-umountCom = Command('umount', 'Unmount the first partition in the disk image.',
-                    [('mount point', 'What mount point to unmount.')])
+umountCom = Command('umount', 'Unmount the disk image mounted at mount_point.',
+                    [('mount_point', 'What mount point to unmount.')])
 
 def umountComFunc(options, args):
     (mountPoint,) = args