blockdev: Make eject fail for non-removable drives even with -f
authorMarkus Armbruster <armbru@redhat.com>
Wed, 20 Jul 2011 16:23:35 +0000 (18:23 +0200)
committerKevin Wolf <kwolf@redhat.com>
Mon, 1 Aug 2011 10:09:11 +0000 (12:09 +0200)
Ejecting hard disk platters can only end in tears.

If you need to revoke access to an image, use drive_del, not eject -f.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
blockdev.c

index 0b8d3a4f83b645134c3a770a80d2f5c43587e85c..a25367a9e3c2f1744c464f1a4fd27b407b06fe11 100644 (file)
@@ -646,16 +646,13 @@ out:
 
 static int eject_device(Monitor *mon, BlockDriverState *bs, int force)
 {
-    if (!force) {
-        if (!bdrv_is_removable(bs)) {
-            qerror_report(QERR_DEVICE_NOT_REMOVABLE,
-                           bdrv_get_device_name(bs));
-            return -1;
-        }
-        if (bdrv_is_locked(bs)) {
-            qerror_report(QERR_DEVICE_LOCKED, bdrv_get_device_name(bs));
-            return -1;
-        }
+    if (!bdrv_is_removable(bs)) {
+        qerror_report(QERR_DEVICE_NOT_REMOVABLE, bdrv_get_device_name(bs));
+        return -1;
+    }
+    if (!force && bdrv_is_locked(bs)) {
+        qerror_report(QERR_DEVICE_LOCKED, bdrv_get_device_name(bs));
+        return -1;
     }
     bdrv_close(bs);
     return 0;