diff mbox

[v3,2/2] block: move the bdrv_dev_change_media_cb()

Message ID 6c33b1e54320663db2ae9c606bde4cb13ca42928.1371474572.git.phrdina@redhat.com
State New
Headers show

Commit Message

Pavel Hrdina June 17, 2013, 1:21 p.m. UTC
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.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
---
 block.c    | 8 --------
 blockdev.c | 7 +++++++
 2 files changed, 7 insertions(+), 8 deletions(-)

Comments

Stefan Hajnoczi June 19, 2013, 10:16 a.m. UTC | #1
On Mon, Jun 17, 2013 at 03:21:41PM +0200, Pavel Hrdina wrote:
> 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.
> 
> Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
> ---
>  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
Pavel Hrdina June 20, 2013, 2:06 p.m. UTC | #2
On 19.6.2013 12:16, Stefan Hajnoczi wrote:
> On Mon, Jun 17, 2013 at 03:21:41PM +0200, Pavel Hrdina wrote:
>> 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.
>>
>> Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
>> ---
>>   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.

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

>
> 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

>
> Stefan
>
diff mbox

Patch

diff --git a/block.c b/block.c
index 9fbaf1a..0411c85 100644
--- a/block.c
+++ b/block.c
@@ -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;
 }
diff --git a/blockdev.c b/blockdev.c
index 9937311..3498413 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -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,