Skip to contentSkip to conversation

block-backend: Always notify on blk_eject

PATCH Superseded John Snow 2 participants 4 messages Oct 28, 2016 – Oct 31, 2016 Block layer

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

John Snow

author
#0 lore raw

PATCH 1/1 block-backend: Always notify on blk_eject

blk_eject is only used by scsi-disk and atapi, and in both cases we only attempt to invoke blk_eject if we have a bona-fide change in tray state.

The "issue" here is that the tray state does not generate a QMP event unless there is a medium/BDS attached to the device, so if libvirt et al are waiting for a tray event to occur from an empty-but-closed drive, software opening that drive will not emit an event and libvirt will wait forever.

Change this by modifying blk_eject to always emit an event, instead of conditionally on a "real" backend eject.

---
 block/block-backend.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)
block/block-backend.c +7 -6
index c53ca30..2044f20 100644
@@ -1381,15 +1381,16 @@ void blk_eject(BlockBackend *blk, bool eject_flag)
     /* blk_eject is only called by qdevified devices */
     assert(!blk->legacy_dev);
 
+    id = blk_get_attached_dev_id(blk);
     if (bs) {
         bdrv_eject(bs, eject_flag);
-
-        id = blk_get_attached_dev_id(blk);
-        qapi_event_send_device_tray_moved(blk_name(blk), id,
-                                          eject_flag, &error_abort);
-        g_free(id);
-
     }
+
+    /* Whether or not we ejected on the backend,
+     * the frontend experienced a tray event. */
+    qapi_event_send_device_tray_moved(blk_name(blk), id,
+                                      eject_flag, &error_abort);
+    g_free(id);
 }
 
 int blk_get_flags(BlockBackend *blk)
Signature · 1 line
2.7.4
author
#1 lore raw
Quoted 26 lines · John Snow

blk_eject is only used by scsi-disk and atapi, and in both cases we only attempt to invoke blk_eject if we have a bona-fide change in tray state.

The "issue" here is that the tray state does not generate a QMP event unless there is a medium/BDS attached to the device, so if libvirt et al are waiting for a tray event to occur from an empty-but-closed drive, software opening that drive will not emit an event and libvirt will wait forever.

Change this by modifying blk_eject to always emit an event, instead of conditionally on a "real" backend eject.

---
 block/block-backend.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)
block/block-backend.c +0 -0
index c53ca30..2044f20 100644

block/block-backend.c void blk_eject(BlockBackend *blk, bool eject_flag) · line 1384

Quoted 4 lines
block/block-backend.c +1 -0
@@ -1381,15 +1381,16 @@ void blk_eject(BlockBackend *blk, bool eject_flag)
     /* blk_eject is only called by qdevified devices */
     assert(!blk->legacy_dev);
 
+    id = blk_get_attached_dev_id(blk);

Uhh, whoops, I left a change in my local branch that kept this right before the tray event. Sorry about that.

Quoted 19 lines
block/block-backend.c +6 -6
     if (bs) {
         bdrv_eject(bs, eject_flag);
-
-        id = blk_get_attached_dev_id(blk);
-        qapi_event_send_device_tray_moved(blk_name(blk), id,
-                                          eject_flag, &error_abort);
-        g_free(id);
-
     }
+
+    /* Whether or not we ejected on the backend,
+     * the frontend experienced a tray event. */
+    qapi_event_send_device_tray_moved(blk_name(blk), id,
+                                      eject_flag, &error_abort);
+    g_free(id);
 }
 
 int blk_get_flags(BlockBackend *blk)
#2 lore raw

Am 28.10.2016 um 23:30 hat John Snow geschrieben:

Quoted 30 lines · John Snow
Quoted 29 lines

blk_eject is only used by scsi-disk and atapi, and in both cases we only attempt to invoke blk_eject if we have a bona-fide change in tray state.

The "issue" here is that the tray state does not generate a QMP event unless there is a medium/BDS attached to the device, so if libvirt et al are waiting for a tray event to occur from an empty-but-closed drive, software opening that drive will not emit an event and libvirt will wait forever.

Change this by modifying blk_eject to always emit an event, instead of conditionally on a "real" backend eject.

---
block/block-backend.c | 13 +++++++------

1 file changed, 7 insertions(+), 6 deletions(-)
block/block-backend.c +0 -0
index c53ca30..2044f20 100644
@@ -1381,15 +1381,16 @@ void blk_eject(BlockBackend *blk, bool eject_flag)
    /* blk_eject is only called by qdevified devices */
    assert(!blk->legacy_dev);
 
Quoted 4 lines

block/block-backend.c void blk_eject(BlockBackend *blk, bool eject_flag) · line 1384

Quoted 1 line
block/block-backend.c +1 -0
+    id = blk_get_attached_dev_id(blk);

Uhh, whoops, I left a change in my local branch that kept this right before the tray event. Sorry about that.

The patch looks good to me, but moving the line would indeed be nicer. Are you going to send a v2 then?

Also, at the risk of sounding like a broken record, I think a test case would be nice.

Kevin

author
#3 lore raw
Quoted 31 lines · Kevin Wolf

Am 28.10.2016 um 23:30 hat John Snow geschrieben:

Quoted 30 lines · John Snow
Quoted 29 lines

blk_eject is only used by scsi-disk and atapi, and in both cases we only attempt to invoke blk_eject if we have a bona-fide change in tray state.

The "issue" here is that the tray state does not generate a QMP event unless there is a medium/BDS attached to the device, so if libvirt et al are waiting for a tray event to occur from an empty-but-closed drive, software opening that drive will not emit an event and libvirt will wait forever.

Change this by modifying blk_eject to always emit an event, instead of conditionally on a "real" backend eject.

---
block/block-backend.c | 13 +++++++------

1 file changed, 7 insertions(+), 6 deletions(-)
block/block-backend.c +0 -0
index c53ca30..2044f20 100644
@@ -1381,15 +1381,16 @@ void blk_eject(BlockBackend *blk, bool eject_flag)
    /* blk_eject is only called by qdevified devices */
    assert(!blk->legacy_dev);
 
Quoted 8 lines
Quoted 4 lines

block/block-backend.c void blk_eject(BlockBackend *blk, bool eject_flag) · line 1384

Quoted 1 line
block/block-backend.c +1 -0
+    id = blk_get_attached_dev_id(blk);

Uhh, whoops, I left a change in my local branch that kept this right before the tray event. Sorry about that.

The patch looks good to me, but moving the line would indeed be nicer. Are you going to send a v2 then?

Yep.

Quoted 3 lines

Also, at the risk of sounding like a broken record, I think a test case would be nice.

"What's good for the goose is good for the gander"

I'll send tests for these two patches.

--js

Quoted 2 lines

Kevin