All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] hotremoving a disk qmp/hmp
@ 2014-11-18 10:02 William Dauchy
  2014-11-18 14:22 ` Markus Armbruster
  0 siblings, 1 reply; 5+ messages in thread
From: William Dauchy @ 2014-11-18 10:02 UTC (permalink / raw)
  To: QEMU Developers; +Cc: Paolo Bonzini, Ian Main, Fam Zheng, Markus Armbruster

[-- Attachment #1: Type: text/plain, Size: 1773 bytes --]

Hello,

When hotremoving a disk I'm using the QMP API with device_del command;

Previous query-block command result:

{   u'device': u'disk1',
    u'inserted': {   u'backing_file_depth': 0,
                     u'bps': 0,
                     u'bps_rd': 0,
                     u'bps_wr': 0,
                     u'detect_zeroes': u'off',
                     u'drv': u'raw',
                     u'encrypted': False,
                     u'encryption_key_missing': False,
                     u'file': u'/dev/sda',
                     u'image': {   u'actual-size': 0,
                                   u'dirty-flag': False,
                                   u'filename': u'/dev/sda',
                                   u'format': u'raw',
                                   u'virtual-size': 3221225472},
                     u'iops': 0,
                     u'iops_rd': 0,
                     u'iops_wr': 0,
                     u'ro': False},
    u'io-status': u'ok',
    u'locked': True,
    u'removable': True,
    u'tray_open': False,
    u'type': u'unknown'}

After a device_del command I have the same thing but "'locked': False"
Then I can also do `eject device=disk1` which bring me to:

{   u'device': u'disk1',
                       u'io-status': u'ok',
                       u'locked': False,
                       u'removable': True,
                       u'tray_open': False,
                       u'type': u'unknown'}

But I did not found a way to completely remove the disk1 entry in order
to be able to add it again.
To complete the operation I need to use the old HMP API and use
`drive_del` command.

Did I miss something? or is it still something missing in QMP API?

Best regards,
-- 
William

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 181 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] hotremoving a disk qmp/hmp
  2014-11-18 10:02 [Qemu-devel] hotremoving a disk qmp/hmp William Dauchy
@ 2014-11-18 14:22 ` Markus Armbruster
  2014-11-18 15:08   ` William Dauchy
  0 siblings, 1 reply; 5+ messages in thread
From: Markus Armbruster @ 2014-11-18 14:22 UTC (permalink / raw)
  To: William Dauchy; +Cc: Paolo Bonzini, Ian Main, Fam Zheng, QEMU Developers

William Dauchy <william@gandi.net> writes:

> Hello,
>
> When hotremoving a disk I'm using the QMP API with device_del command;
>
> Previous query-block command result:
>
> {   u'device': u'disk1',
>     u'inserted': {   u'backing_file_depth': 0,
>                      u'bps': 0,
>                      u'bps_rd': 0,
>                      u'bps_wr': 0,
>                      u'detect_zeroes': u'off',
>                      u'drv': u'raw',
>                      u'encrypted': False,
>                      u'encryption_key_missing': False,
>                      u'file': u'/dev/sda',
>                      u'image': {   u'actual-size': 0,
>                                    u'dirty-flag': False,
>                                    u'filename': u'/dev/sda',
>                                    u'format': u'raw',
>                                    u'virtual-size': 3221225472},
>                      u'iops': 0,
>                      u'iops_rd': 0,
>                      u'iops_wr': 0,
>                      u'ro': False},
>     u'io-status': u'ok',
>     u'locked': True,
>     u'removable': True,
>     u'tray_open': False,
>     u'type': u'unknown'}

This is block backend "disk1".

> After a device_del command I have the same thing but "'locked': False"

I presume you're deleting the device using backend "disk1".

What kind of device is this?  PCI, perhaps?

> Then I can also do `eject device=disk1` which bring me to:
>
> {   u'device': u'disk1',
>                        u'io-status': u'ok',
>                        u'locked': False,
>                        u'removable': True,
>                        u'tray_open': False,
>                        u'type': u'unknown'}
>
> But I did not found a way to completely remove the disk1 entry in order
> to be able to add it again.
> To complete the operation I need to use the old HMP API and use
> `drive_del` command.
>
> Did I miss something? or is it still something missing in QMP API?

Please show us a complete QMP conversation.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] hotremoving a disk qmp/hmp
  2014-11-18 14:22 ` Markus Armbruster
@ 2014-11-18 15:08   ` William Dauchy
  2014-11-18 17:15     ` Markus Armbruster
  0 siblings, 1 reply; 5+ messages in thread
From: William Dauchy @ 2014-11-18 15:08 UTC (permalink / raw)
  To: Markus Armbruster; +Cc: Paolo Bonzini, Ian Main, Fam Zheng, QEMU Developers

[-- Attachment #1: Type: text/plain, Size: 8428 bytes --]

On Nov18 15:22, Markus Armbruster wrote:
> This is block backend "disk1".

yes indeed.

> I presume you're deleting the device using backend "disk1".

yes

> What kind of device is this?  PCI, perhaps?
> Please show us a complete QMP conversation.

Here it is:

live vm with one disk:

(QEMU) query-block
{   u'return': [   {   u'device': u'disk0',
                       u'inserted': {   u'backing_file_depth': 0,
                                        u'bps': 0,
                                        u'bps_rd': 0,
                                        u'bps_wr': 0,
                                        u'detect_zeroes': u'off',
                                        u'drv': u'raw',
                                        u'encrypted': False,
                                        u'encryption_key_missing': False,
                                        u'file': u'/dev/sda',
                                        u'image': {   u'actual-size': 0,
                                                      u'dirty-flag': False,
                                                      u'filename': u'/dev/sda',
                                                      u'format': u'raw',
                                                      u'virtual-size': 3221225472},
                                        u'iops': 0,
                                        u'iops_rd': 0,
                                        u'iops_wr': 0,
                                        u'ro': False},
                       u'io-status': u'ok',
                       u'locked': True,
                       u'removable': True,
                       u'tray_open': False,
                       u'type': u'unknown'}]}

hotplugging one disk:

(QEMU) blockdev-add
with
{'options' : {
    'driver': 'raw',
    'id': 'disk1',
    'file': {
        'driver': 'file',
        'filename': /dev/sdb,
        }
}}

(QEMU) device_add
with:
{
    'driver': 'scsi-hd',
    'id': 'disk1',
    'drive': 'disk1',
    'scsi-id': 1,
    'removable': 'on',
    'dpofua': 'off'
}

(QEMU) query-block
{   u'return': [   {   u'device': u'disk0',
                       u'inserted': {   u'backing_file_depth': 0,
                                        u'bps': 0,
                                        u'bps_rd': 0,
                                        u'bps_wr': 0,
                                        u'detect_zeroes': u'off',
                                        u'drv': u'raw',
                                        u'encrypted': False,
                                        u'encryption_key_missing': False,
                                        u'file': u'/dev/sda',
                                        u'image': {   u'actual-size': 0,
                                                      u'dirty-flag': False,
                                                      u'filename': u'/dev/sda',
                                                      u'format': u'raw',
                                                      u'virtual-size': 3221225472},
                                        u'iops': 0,
                                        u'iops_rd': 0,
                                        u'iops_wr': 0,
                                        u'ro': False},
                       u'io-status': u'ok',
                       u'locked': True,
                       u'removable': True,
                       u'tray_open': False,
                       u'type': u'unknown'},,
                   {   u'device': u'disk1',
                       u'inserted': {   u'backing_file_depth': 0,
                                        u'bps': 0,
                                        u'bps_rd': 0,
                                        u'bps_wr': 0,
                                        u'detect_zeroes': u'off',
                                        u'drv': u'raw',
                                        u'encrypted': False,
                                        u'encryption_key_missing': False,
                                        u'file': u'/dev/sdb',
                                        u'image': {   u'actual-size': 0,
                                                      u'dirty-flag': False,
                                                      u'filename': u'/dev/sdb',
                                                      u'format': u'raw',
                                                      u'virtual-size': 3221225472},
                                        u'iops': 0,
                                        u'iops_rd': 0,
                                        u'iops_wr': 0,
                                        u'ro': False},
                       u'io-status': u'ok',
                       u'locked': True,
                       u'removable': True,
                       u'tray_open': False,
                       u'type': u'unknown'}]}

hotremoving disk1:

(QEMU) device_del
with:
{'id': 'disk1'}

(QEMU) query-block
{   u'return': [   {   u'device': u'disk0',
                       u'inserted': {   u'backing_file_depth': 0,
                                        u'bps': 0,
                                        u'bps_rd': 0,
                                        u'bps_wr': 0,
                                        u'detect_zeroes': u'off',
                                        u'drv': u'raw',
                                        u'encrypted': False,
                                        u'encryption_key_missing': False,
                                        u'file': u'/dev/sda',
                                        u'image': {   u'actual-size': 0,
                                                      u'dirty-flag': False,
                                                      u'filename': u'/dev/sda',
                                                      u'format': u'raw',
                                                      u'virtual-size': 3221225472},
                                        u'iops': 0,
                                        u'iops_rd': 0,
                                        u'iops_wr': 0,
                                        u'ro': False},
                       u'io-status': u'ok',
                       u'locked': True,
                       u'removable': True,
                       u'tray_open': False,
                       u'type': u'unknown'},,
                   {   u'device': u'disk1',
                       u'inserted': {   u'backing_file_depth': 0,
                                        u'bps': 0,
                                        u'bps_rd': 0,
                                        u'bps_wr': 0,
                                        u'detect_zeroes': u'off',
                                        u'drv': u'raw',
                                        u'encrypted': False,
                                        u'encryption_key_missing': False,
                                        u'file': u'/dev/sdb,
                                        u'image': {   u'actual-size': 0,
                                                      u'dirty-flag': False,
                                                      u'filename': u'/dev/sdb',
                                                      u'format': u'raw',
                                                      u'virtual-size': 3221225472},
                                        u'iops': 0,
                                        u'iops_rd': 0,
                                        u'iops_wr': 0,
                                        u'ro': False},
                       u'io-status': u'ok',
                       u'locked': False,
                       u'removable': True,
                       u'tray_open': False,
                       u'type': u'unknown'}]}

So now I have locked == False but I don't know how to clean the object
with QMP API.
so...
switching to HMP API:

(QEMU) info block
disk0: /dev/sda (raw)
    Removable device: locked, tray closed

disk1: /dev/sdb (raw)
    Removable device: not locked, tray closed

(QEMU) drive_del disk1
(QEMU) info block
disk0: /dev/sda (raw)
    Removable device: locked, tray closed


Is there a way to do the same with QMP commands?

Thanks,
-- 
William

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 181 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] hotremoving a disk qmp/hmp
  2014-11-18 15:08   ` William Dauchy
@ 2014-11-18 17:15     ` Markus Armbruster
  2014-11-19  9:58       ` William Dauchy
  0 siblings, 1 reply; 5+ messages in thread
From: Markus Armbruster @ 2014-11-18 17:15 UTC (permalink / raw)
  To: William Dauchy; +Cc: Paolo Bonzini, Ian Main, Fam Zheng, QEMU Developers

William Dauchy <william@gandi.net> writes:

> On Nov18 15:22, Markus Armbruster wrote:
>> This is block backend "disk1".
>
> yes indeed.
>
>> I presume you're deleting the device using backend "disk1".
>
> yes
>
>> What kind of device is this?  PCI, perhaps?
>> Please show us a complete QMP conversation.
>
> Here it is:
>
> live vm with one disk:
>
> (QEMU) query-block
> {   u'return': [   {   u'device': u'disk0',
>                        u'inserted': {   u'backing_file_depth': 0,
>                                         u'bps': 0,
>                                         u'bps_rd': 0,
>                                         u'bps_wr': 0,
>                                         u'detect_zeroes': u'off',
>                                         u'drv': u'raw',
>                                         u'encrypted': False,
>                                         u'encryption_key_missing': False,
>                                         u'file': u'/dev/sda',
>                                         u'image': {   u'actual-size': 0,
>                                                       u'dirty-flag': False,
>                                                       u'filename': u'/dev/sda',
>                                                       u'format': u'raw',
>                                                       u'virtual-size': 3221225472},
>                                         u'iops': 0,
>                                         u'iops_rd': 0,
>                                         u'iops_wr': 0,
>                                         u'ro': False},
>                        u'io-status': u'ok',
>                        u'locked': True,
>                        u'removable': True,
>                        u'tray_open': False,
>                        u'type': u'unknown'}]}
>
> hotplugging one disk:
>
> (QEMU) blockdev-add
> with
> {'options' : {
>     'driver': 'raw',
>     'id': 'disk1',
>     'file': {
>         'driver': 'file',
>         'filename': /dev/sdb,
>         }
> }}
>
> (QEMU) device_add
> with:
> {
>     'driver': 'scsi-hd',
>     'id': 'disk1',

Using the same ID for different things currently works, but it's awfully
confusing.  Please don't :)

>     'drive': 'disk1',
>     'scsi-id': 1,
>     'removable': 'on',
>     'dpofua': 'off'
> }
>
> (QEMU) query-block
> {   u'return': [   {   u'device': u'disk0',
>                        u'inserted': {   u'backing_file_depth': 0,
>                                         u'bps': 0,
>                                         u'bps_rd': 0,
>                                         u'bps_wr': 0,
>                                         u'detect_zeroes': u'off',
>                                         u'drv': u'raw',
>                                         u'encrypted': False,
>                                         u'encryption_key_missing': False,
>                                         u'file': u'/dev/sda',
>                                         u'image': {   u'actual-size': 0,
>                                                       u'dirty-flag': False,
>                                                       u'filename': u'/dev/sda',
>                                                       u'format': u'raw',
>                                                       u'virtual-size': 3221225472},
>                                         u'iops': 0,
>                                         u'iops_rd': 0,
>                                         u'iops_wr': 0,
>                                         u'ro': False},
>                        u'io-status': u'ok',
>                        u'locked': True,
>                        u'removable': True,
>                        u'tray_open': False,
>                        u'type': u'unknown'},,
>                    {   u'device': u'disk1',
>                        u'inserted': {   u'backing_file_depth': 0,
>                                         u'bps': 0,
>                                         u'bps_rd': 0,
>                                         u'bps_wr': 0,
>                                         u'detect_zeroes': u'off',
>                                         u'drv': u'raw',
>                                         u'encrypted': False,
>                                         u'encryption_key_missing': False,
>                                         u'file': u'/dev/sdb',
>                                         u'image': {   u'actual-size': 0,
>                                                       u'dirty-flag': False,
>                                                       u'filename': u'/dev/sdb',
>                                                       u'format': u'raw',
>                                                       u'virtual-size': 3221225472},
>                                         u'iops': 0,
>                                         u'iops_rd': 0,
>                                         u'iops_wr': 0,
>                                         u'ro': False},
>                        u'io-status': u'ok',
>                        u'locked': True,
>                        u'removable': True,
>                        u'tray_open': False,
>                        u'type': u'unknown'}]}
>
> hotremoving disk1:
>
> (QEMU) device_del
> with:
> {'id': 'disk1'}

Since you still didn't provide your *complete* QMP conversation, you
leave me guessing what device_del did.  I guess device_del succeeded,
and you got a DEVICE_DELETED event.

This is the kind of information I was looking for:

    $ rlwrap -H ~/.qmp_history socat UNIX:/work/armbru/images/test-qmp STDIO
    {"QMP": {"version": {"qemu": {"micro": 91, "minor": 1, "major": 2}, "package": ""}, "capabilities": []}}
    { "execute": "qmp_capabilities" }
    {"return": {}}
    { "execute": "blockdev-add", "arguments": {'options' : {'driver': 'raw', 'id': 'disk1', 'file': {'driver': 'file', 'filename': '/dev/sdb'}}} }
    {"error": {"class": "GenericError", "desc": "could not open disk image disk1: Could not open '/dev/sdb': Permission denied"}}

Block backends created with drive_add get destroyed when a device using
it gets destroyed, unlike any other backend.  We refrained from bringing
this wart forward to blockdev-add.  Thus, the backend is still around:

> (QEMU) query-block
> {   u'return': [   {   u'device': u'disk0',
>                        u'inserted': {   u'backing_file_depth': 0,
>                                         u'bps': 0,
>                                         u'bps_rd': 0,
>                                         u'bps_wr': 0,
>                                         u'detect_zeroes': u'off',
>                                         u'drv': u'raw',
>                                         u'encrypted': False,
>                                         u'encryption_key_missing': False,
>                                         u'file': u'/dev/sda',
>                                         u'image': {   u'actual-size': 0,
>                                                       u'dirty-flag': False,
>                                                       u'filename': u'/dev/sda',
>                                                       u'format': u'raw',
>                                                       u'virtual-size': 3221225472},
>                                         u'iops': 0,
>                                         u'iops_rd': 0,
>                                         u'iops_wr': 0,
>                                         u'ro': False},
>                        u'io-status': u'ok',
>                        u'locked': True,
>                        u'removable': True,
>                        u'tray_open': False,
>                        u'type': u'unknown'},,
>                    {   u'device': u'disk1',
>                        u'inserted': {   u'backing_file_depth': 0,
>                                         u'bps': 0,
>                                         u'bps_rd': 0,
>                                         u'bps_wr': 0,
>                                         u'detect_zeroes': u'off',
>                                         u'drv': u'raw',
>                                         u'encrypted': False,
>                                         u'encryption_key_missing': False,
>                                         u'file': u'/dev/sdb,
>                                         u'image': {   u'actual-size': 0,
>                                                       u'dirty-flag': False,
>                                                       u'filename': u'/dev/sdb',
>                                                       u'format': u'raw',
>                                                       u'virtual-size': 3221225472},
>                                         u'iops': 0,
>                                         u'iops_rd': 0,
>                                         u'iops_wr': 0,
>                                         u'ro': False},
>                        u'io-status': u'ok',
>                        u'locked': False,
>                        u'removable': True,
>                        u'tray_open': False,
>                        u'type': u'unknown'}]}
>
> So now I have locked == False but I don't know how to clean the object
> with QMP API.
> so...
> switching to HMP API:
>
> (QEMU) info block
> disk0: /dev/sda (raw)
>     Removable device: locked, tray closed
>
> disk1: /dev/sdb (raw)
>     Removable device: not locked, tray closed
>
> (QEMU) drive_del disk1
> (QEMU) info block
> disk0: /dev/sda (raw)
>     Removable device: locked, tray closed

Looks like you're using an old version of QEMU.  drive_del has been
fixed to refuse touching a backend created with blockdev-add:

commit 48f364dd0ba8d6323ee9ac2b35996eef667bac39
Author: Markus Armbruster <armbru@redhat.com>
Date:   Thu Sep 11 16:45:39 2014 +0200

    blockdev: Refuse to drive_del something added with blockdev-add
    
    For some device models, the guest can prevent unplug.  Some users need a
    way to forcibly revoke device model access to the block backend then, so
    the underlying images can be safely used for something else.
    
    drive_del lets you do that.  Unfortunately, it conflates revoking access
    with destroying the backend.
    
    Commit 9063f81 made drive_del immediately destroy the root BDS.  Nice:
    the device name becomes available for reuse immediately.  Not so nice:
    the device model's pointer to the root BDS dangles, and we're prone to
    crash when the memory gets reused.
    
    Commit d22b2f4 fixed that by hiding the root BDS instead of destroying
    it.  Destruction only happens on unplug.  "Hiding" means removing it
    from bdrv_states and graph_bdrv_states; see bdrv_make_anon().
    
    This "destroy on revoke" is a misfeature we don't want to carry
    forward to blockdev-add, just like "destroy on unplug" (commit
    2d246f0).  So make drive_del fail on anything added with blockdev-add.
    
    We'll add separate QMP commands to revoke device model access and to
    destroy backends.
    
    Signed-off-by: Markus Armbruster <armbru@redhat.com>
    Signed-off-by: Kevin Wolf <kwolf@redhat.com>

> Is there a way to do the same with QMP commands?

You can't destroy a backend created with blockdev-add, yet.  I hope to
have blockdev-del in 2.3.

My advice is to stick to drive_add and drive_del for now.  Not in QMP,
so you need to use HMP.  You can do that in QMP with
human-monitor-command.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] hotremoving a disk qmp/hmp
  2014-11-18 17:15     ` Markus Armbruster
@ 2014-11-19  9:58       ` William Dauchy
  0 siblings, 0 replies; 5+ messages in thread
From: William Dauchy @ 2014-11-19  9:58 UTC (permalink / raw)
  To: Markus Armbruster; +Cc: Paolo Bonzini, Ian Main, Fam Zheng, QEMU Developers

[-- Attachment #1: Type: text/plain, Size: 688 bytes --]

On Nov18 18:15, Markus Armbruster wrote:
> Looks like you're using an old version of QEMU.  drive_del has been
> fixed to refuse touching a backend created with blockdev-add:

I am using the last v2.1.x version but there was indeed some commits
since

> You can't destroy a backend created with blockdev-add, yet.  I hope to
> have blockdev-del in 2.3.

thanks for the information

> My advice is to stick to drive_add and drive_del for now.  Not in QMP,
> so you need to use HMP.  You can do that in QMP with
> human-monitor-command.

ok understood that's what I was suspecting after not finding a way to
delete an object added by blockdev-add

Thanks,
-- 
William

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 181 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2014-11-19  9:58 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-11-18 10:02 [Qemu-devel] hotremoving a disk qmp/hmp William Dauchy
2014-11-18 14:22 ` Markus Armbruster
2014-11-18 15:08   ` William Dauchy
2014-11-18 17:15     ` Markus Armbruster
2014-11-19  9:58       ` William Dauchy

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.