Skip to content

Commit

Permalink
block: Accept device model name for eject
Browse files Browse the repository at this point in the history
In order to remove the need for BlockBackend names in the external API,
we want to allow qdev device names in all device related commands.

This converts eject to accept a qdev device name.

Signed-off-by: Kevin Wolf <[email protected]>
  • Loading branch information
kevmw committed Sep 23, 2016
1 parent 00949ba commit fbe2d81
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 10 deletions.
10 changes: 7 additions & 3 deletions blockdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -2265,7 +2265,9 @@ void qmp_transaction(TransactionActionList *dev_list,
block_job_txn_unref(block_job_txn);
}

void qmp_eject(const char *device, bool has_force, bool force, Error **errp)
void qmp_eject(bool has_device, const char *device,
bool has_id, const char *id,
bool has_force, bool force, Error **errp)
{
Error *local_err = NULL;
int rc;
Expand All @@ -2274,14 +2276,16 @@ void qmp_eject(const char *device, bool has_force, bool force, Error **errp)
force = false;
}

rc = do_open_tray(device, NULL, force, &local_err);
rc = do_open_tray(has_device ? device : NULL,
has_id ? id : NULL,
force, &local_err);
if (rc && rc != -ENOSYS) {
error_propagate(errp, local_err);
return;
}
error_free(local_err);

qmp_x_blockdev_remove_medium(true, device, false, NULL, errp);
qmp_x_blockdev_remove_medium(has_device, device, has_id, id, errp);
}

void qmp_block_passwd(bool has_device, const char *device,
Expand Down
8 changes: 5 additions & 3 deletions docs/qmp-commands.txt
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,14 @@ Eject a removable medium.

Arguments:

- force: force ejection (json-bool, optional)
- device: device name (json-string)
- "force": force ejection (json-bool, optional)
- "device": block device name (deprecated, use @id instead)
(json-string, optional)
- "id": the name or QOM path of the guest device (json-string, optional)

Example:

-> { "execute": "eject", "arguments": { "device": "ide1-cd0" } }
-> { "execute": "eject", "arguments": { "id": "ide0-1-0" } }
<- { "return": {} }

Note: The "force" argument defaults to false.
Expand Down
2 changes: 1 addition & 1 deletion hmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1376,7 +1376,7 @@ void hmp_eject(Monitor *mon, const QDict *qdict)
const char *device = qdict_get_str(qdict, "device");
Error *err = NULL;

qmp_eject(device, true, force, &err);
qmp_eject(true, device, false, NULL, true, force, &err);
hmp_handle_error(mon, &err);
}

Expand Down
9 changes: 7 additions & 2 deletions qapi/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,9 @@
#
# Ejects a device from a removable drive.
#
# @device: The name of the device
# @device: #optional Block device name (deprecated, use @id instead)
#
# @id: #optional The name or QOM path of the guest device (since: 2.8)
#
# @force: @optional If true, eject regardless of whether the drive is locked.
# If not specified, the default value is false.
Expand All @@ -137,7 +139,10 @@
#
# Since: 0.14.0
##
{ 'command': 'eject', 'data': {'device': 'str', '*force': 'bool'} }
{ 'command': 'eject',
'data': { '*device': 'str',
'*id': 'str',
'*force': 'bool' } }

##
# @nbd-server-start:
Expand Down
3 changes: 2 additions & 1 deletion ui/cocoa.m
Original file line number Diff line number Diff line change
Expand Up @@ -1085,7 +1085,8 @@ - (void)ejectDeviceMedia:(id)sender
}

Error *err = NULL;
qmp_eject([drive cStringUsingEncoding: NSASCIIStringEncoding], false, false, &err);
qmp_eject(true, [drive cStringUsingEncoding: NSASCIIStringEncoding],
false, NULL, false, false, &err);
handleAnyDeviceErrors(err);
}

Expand Down

0 comments on commit fbe2d81

Please sign in to comment.