Skip to contentSkip to conversation

block: fix spurious DEVICE_TRAY_MOVED events on shutdown

PATCH Superseded Pavel Hrdina 2 participants 5 messages Jun 17, 2013 – Jun 20, 2013

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v3 cover block: fix spurious DEVICE_TRAY_MOVED events on shutdown

This fixes a regression introduced by commit 9ca111544.

The first commit is done by Luiz and I've just use it as it is.

The second commit moves the bdrv_dev_change_media_cb() into eject_device(), called by QMP and HMP eject command, and into qmp_bdrv_open_encrypted(), called by QMP and HMP change command. These are the only place where I think that should call the bdrv_dev_change_media_cb() function.

There is no reason to call this function while we are removing the device from the guest, for example while closing and deleting all devices on shutdown.

* changes from v1:
- used the first patch from Luiz's series

* changes from v2:
- added comment that the error QERR_DEVICE_NOT_ENCRYPTED is used as warning

Luiz Capitulino (1):
block: make bdrv_dev_change_media_cb() public

Pavel Hrdina (1):
block: move the bdrv_dev_change_media_cb()

 block.c               | 11 +----------
 blockdev.c            |  7 +++++++
 include/block/block.h |  1 +
 3 files changed, 9 insertions(+), 10 deletions(-)
Signature · 1 line
1.8.1.4
#1 lore raw

PATCH v3 1/2 block: make bdrv_dev_change_media_cb() public

From: Luiz Capitulino <[email protected]>

Next commit wants to use it.

---
 block.c               | 3 +--
 include/block/block.h | 1 +
 2 files changed, 2 insertions(+), 2 deletions(-)
block.c +1 -2
index 79ad33d..9fbaf1a 100644
@@ -56,7 +56,6 @@ typedef enum {
     BDRV_REQ_ZERO_WRITE   = 0x2,
 } BdrvRequestFlags;
 
-static void bdrv_dev_change_media_cb(BlockDriverState *bs, bool load);
 static BlockDriverAIOCB *bdrv_aio_readv_em(BlockDriverState *bs,
         int64_t sector_num, QEMUIOVector *qiov, int nb_sectors,
         BlockDriverCompletionFunc *cb, void *opaque);
@@ -1682,7 +1681,7 @@ static void bdrv_emit_qmp_eject_event(BlockDriverState *bs, bool ejected)
     qobject_decref(data);
 }
 
-static void bdrv_dev_change_media_cb(BlockDriverState *bs, bool load)
+void bdrv_dev_change_media_cb(BlockDriverState *bs, bool load)
 {
     if (bs->dev_ops && bs->dev_ops->change_media_cb) {
         bool tray_was_closed = !bdrv_dev_is_tray_open(bs);
include/block/block.h +1 -0
index 2307f67..2cc93ab 100644
@@ -148,6 +148,7 @@ void bdrv_set_dev_ops(BlockDriverState *bs, const BlockDevOps *ops,
                       void *opaque);
 void bdrv_dev_eject_request(BlockDriverState *bs, bool force);
 bool bdrv_dev_has_removable_media(BlockDriverState *bs);
+void bdrv_dev_change_media_cb(BlockDriverState *bs, bool load);
 bool bdrv_dev_is_tray_open(BlockDriverState *bs);
 bool bdrv_dev_is_medium_locked(BlockDriverState *bs);
 int bdrv_read(BlockDriverState *bs, int64_t sector_num,
Signature · 1 line
1.8.1.4
#2 lore raw

PATCH v3 2/2 block: move the bdrv_dev_change_media_cb()

In reply to Pavel Hrdina

The bdrv_dev_change_media_cb() should be called only for eject and change commands. We should call that function only if that command is successful.

What this function does is that it calls the change_media_cb() and also emit the QEVENT_DEVICE_TRAY_MOVED event.

If a password is not required, but user provides some, the error is used as warning.

---
 block.c    | 8 --------
 blockdev.c | 7 +++++++
 2 files changed, 7 insertions(+), 8 deletions(-)
block.c +0 -8
index 9fbaf1a..0411c85 100644
@@ -1092,10 +1092,6 @@ int bdrv_open(BlockDriverState *bs, const char *filename, QDict *options,
     }
     QDECREF(options);
 
-    if (!bdrv_key_required(bs)) {
-        bdrv_dev_change_media_cb(bs, true);
-    }
-
     /* throttling disk I/O limits */
     if (bs->io_limits_enabled) {
         bdrv_io_limits_enable(bs);
@@ -1394,8 +1390,6 @@ void bdrv_close(BlockDriverState *bs)
         }
     }
 
-    bdrv_dev_change_media_cb(bs, false);
-
     /*throttling disk I/O limits*/
     if (bs->io_limits_enabled) {
         bdrv_io_limits_disable(bs);
@@ -2846,8 +2840,6 @@ int bdrv_set_key(BlockDriverState *bs, const char *key)
         bs->valid_key = 0;
     } else if (!bs->valid_key) {
         bs->valid_key = 1;
-        /* call the change callback now, we skipped it on open */
-        bdrv_dev_change_media_cb(bs, true);
     }
     return ret;
 }
blockdev.c +7 -0
index 9937311..3498413 100644
@@ -1022,6 +1022,7 @@ static void eject_device(BlockDriverState *bs, int force, Error **errp)
     }
 
     bdrv_close(bs);
+    bdrv_dev_change_media_cb(bs, false);
 }
 
 void qmp_eject(const char *device, bool has_force, bool force, Error **errp)
@@ -1071,14 +1072,20 @@ static void qmp_bdrv_open_encrypted(BlockDriverState *bs, const char *filename,
         if (password) {
             if (bdrv_set_key(bs, password) < 0) {
                 error_set(errp, QERR_INVALID_PASSWORD);
+                return;
             }
         } else {
             error_set(errp, QERR_DEVICE_ENCRYPTED, bdrv_get_device_name(bs),
                       bdrv_get_encrypted_filename(bs));
+            return;
         }
     } else if (password) {
+        /* This is only warning that you shoud not use a password for not
+         * encrypted device. */
         error_set(errp, QERR_DEVICE_NOT_ENCRYPTED, bdrv_get_device_name(bs));
     }
+
+    bdrv_dev_change_media_cb(bs, true);
 }
 
 void qmp_change_blockdev(const char *device, const char *filename,
Signature · 1 line
1.8.1.4
#3 lore raw

Re: [Qemu-devel] [PATCH v3 2/2] block: move the bdrv_dev_change_media_cb()

Quoted 6 lines · Pavel Hrdina

The bdrv_dev_change_media_cb() should be called only for eject and change commands. We should call that function only if that command is successful.

What this function does is that it calls the change_media_cb() and also emit the QEVENT_DEVICE_TRAY_MOVED event.

Quoted 8 lines

If a password is not required, but user provides some, the error is used as warning.

---
 block.c    | 8 --------
 blockdev.c | 7 +++++++
 2 files changed, 7 insertions(+), 8 deletions(-)

This commit description explains what the code changes do but it doesn't explain why. The cover letter mentions a regression without going into detail, and that will not be commited to git. Please add information about the regression that this patch fixes so the git history has enough information to justify this patch.

Markus posted a list of places that are affected by this change. Have you worked through them to show this patch is safe?

Stefan

#4 lore raw

Re: [Qemu-devel] [PATCH v3 2/2] block: move the bdrv_dev_change_media_cb()

Quoted 16 lines · Stefan Hajnoczi
Quoted 6 lines · Pavel Hrdina

The bdrv_dev_change_media_cb() should be called only for eject and change commands. We should call that function only if that command is successful.

What this function does is that it calls the change_media_cb() and also emit the QEVENT_DEVICE_TRAY_MOVED event.

Quoted 8 lines

If a password is not required, but user provides some, the error is used as warning.

---
  block.c    | 8 --------
  blockdev.c | 7 +++++++
  2 files changed, 7 insertions(+), 8 deletions(-)
Quoted 5 lines

This commit description explains what the code changes do but it doesn't explain why. The cover letter mentions a regression without going into detail, and that will not be commited to git. Please add information about the regression that this patch fixes so the git history has enough information to justify this patch.

Thanks, I explain this change directly in the commit message.

Quoted 3 lines

Markus posted a list of places that are affected by this change. Have you worked through them to show this patch is safe?

Today I've checked hopefully all possible ways how to get into the 'bdrv_dev_change_media_cb()' regarding Markus' comment.

The only relevant callers are the qmp_change and qmp_eject because the purpose of the 'bdrv_dev_change_media_cb()' is to call the devices' handlers for change media event, update the tray status and also emit the DEVICE_TRAY_MOVED event.

Pavel

Quoted 3 lines

Stefan