Patchwork [01/29] blockdev: Make eject fail for non-removable drives even with -f

login
register
mail settings
Submitter Kevin Wolf
Date Aug. 3, 2011, 2:13 p.m.
Message ID <1312380864-15605-2-git-send-email-kwolf@redhat.com>
Download mbox | patch
Permalink /patch/108207/
State New
Headers show

Comments

Kevin Wolf - Aug. 3, 2011, 2:13 p.m.
From: Markus Armbruster <armbru@redhat.com>

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 |   17 +++++++----------
 1 files changed, 7 insertions(+), 10 deletions(-)

Patch

diff --git a/blockdev.c b/blockdev.c
index 0b8d3a4..a25367a 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -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;