提交 75158ebb 编写于 作者: M Markus Armbruster

qerror: Eliminate QERR_DEVICE_NOT_FOUND

Error classes other than ERROR_CLASS_GENERIC_ERROR should not be used
in new code.  Hiding them in QERR_ macros makes new uses hard to spot.
Fortunately, there's just one such macro left.  Eliminate it with this
coccinelle semantic patch:

    @@
    expression EP, E;
    @@
    -error_set(EP, QERR_DEVICE_NOT_FOUND, E)
    +error_set(EP, ERROR_CLASS_DEVICE_NOT_FOUND, "Device '%s' not found", E)
Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
Reviewed-by: NEric Blake <eblake@redhat.com>
Reviewed-by: NStefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: NLuiz Capitulino <lcapitulino@redhat.com>
上级 c6bf0f7f
...@@ -147,7 +147,8 @@ static void rng_egd_opened(RngBackend *b, Error **errp) ...@@ -147,7 +147,8 @@ static void rng_egd_opened(RngBackend *b, Error **errp)
s->chr = qemu_chr_find(s->chr_name); s->chr = qemu_chr_find(s->chr_name);
if (s->chr == NULL) { if (s->chr == NULL) {
error_set(errp, QERR_DEVICE_NOT_FOUND, s->chr_name); error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND,
"Device '%s' not found", s->chr_name);
return; return;
} }
......
...@@ -91,7 +91,8 @@ void qmp_nbd_server_add(const char *device, bool has_writable, bool writable, ...@@ -91,7 +91,8 @@ void qmp_nbd_server_add(const char *device, bool has_writable, bool writable,
blk = blk_by_name(device); blk = blk_by_name(device);
if (!blk) { if (!blk) {
error_set(errp, QERR_DEVICE_NOT_FOUND, device); error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND,
"Device '%s' not found", device);
return; return;
} }
if (!blk_is_inserted(blk)) { if (!blk_is_inserted(blk)) {
......
...@@ -1111,7 +1111,8 @@ SnapshotInfo *qmp_blockdev_snapshot_delete_internal_sync(const char *device, ...@@ -1111,7 +1111,8 @@ SnapshotInfo *qmp_blockdev_snapshot_delete_internal_sync(const char *device,
blk = blk_by_name(device); blk = blk_by_name(device);
if (!blk) { if (!blk) {
error_set(errp, QERR_DEVICE_NOT_FOUND, device); error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND,
"Device '%s' not found", device);
return NULL; return NULL;
} }
bs = blk_bs(blk); bs = blk_bs(blk);
...@@ -1300,7 +1301,8 @@ static void internal_snapshot_prepare(BlkTransactionState *common, ...@@ -1300,7 +1301,8 @@ static void internal_snapshot_prepare(BlkTransactionState *common,
/* 2. check for validation */ /* 2. check for validation */
blk = blk_by_name(device); blk = blk_by_name(device);
if (!blk) { if (!blk) {
error_set(errp, QERR_DEVICE_NOT_FOUND, device); error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND,
"Device '%s' not found", device);
return; return;
} }
bs = blk_bs(blk); bs = blk_bs(blk);
...@@ -1580,7 +1582,8 @@ static void drive_backup_prepare(BlkTransactionState *common, Error **errp) ...@@ -1580,7 +1582,8 @@ static void drive_backup_prepare(BlkTransactionState *common, Error **errp)
blk = blk_by_name(backup->device); blk = blk_by_name(backup->device);
if (!blk) { if (!blk) {
error_set(errp, QERR_DEVICE_NOT_FOUND, backup->device); error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND,
"Device '%s' not found", backup->device);
return; return;
} }
bs = blk_bs(blk); bs = blk_bs(blk);
...@@ -1850,7 +1853,8 @@ void qmp_eject(const char *device, bool has_force, bool force, Error **errp) ...@@ -1850,7 +1853,8 @@ void qmp_eject(const char *device, bool has_force, bool force, Error **errp)
blk = blk_by_name(device); blk = blk_by_name(device);
if (!blk) { if (!blk) {
error_set(errp, QERR_DEVICE_NOT_FOUND, device); error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND,
"Device '%s' not found", device);
return; return;
} }
...@@ -1910,7 +1914,8 @@ void qmp_change_blockdev(const char *device, const char *filename, ...@@ -1910,7 +1914,8 @@ void qmp_change_blockdev(const char *device, const char *filename,
blk = blk_by_name(device); blk = blk_by_name(device);
if (!blk) { if (!blk) {
error_set(errp, QERR_DEVICE_NOT_FOUND, device); error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND,
"Device '%s' not found", device);
return; return;
} }
bs = blk_bs(blk); bs = blk_bs(blk);
...@@ -1971,7 +1976,8 @@ void qmp_block_set_io_throttle(const char *device, int64_t bps, int64_t bps_rd, ...@@ -1971,7 +1976,8 @@ void qmp_block_set_io_throttle(const char *device, int64_t bps, int64_t bps_rd,
blk = blk_by_name(device); blk = blk_by_name(device);
if (!blk) { if (!blk) {
error_set(errp, QERR_DEVICE_NOT_FOUND, device); error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND,
"Device '%s' not found", device);
return; return;
} }
bs = blk_bs(blk); bs = blk_bs(blk);
...@@ -2291,7 +2297,8 @@ void qmp_block_stream(const char *device, ...@@ -2291,7 +2297,8 @@ void qmp_block_stream(const char *device,
blk = blk_by_name(device); blk = blk_by_name(device);
if (!blk) { if (!blk) {
error_set(errp, QERR_DEVICE_NOT_FOUND, device); error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND,
"Device '%s' not found", device);
return; return;
} }
bs = blk_bs(blk); bs = blk_bs(blk);
...@@ -2365,7 +2372,8 @@ void qmp_block_commit(const char *device, ...@@ -2365,7 +2372,8 @@ void qmp_block_commit(const char *device,
* scenario in which all optional arguments are omitted. */ * scenario in which all optional arguments are omitted. */
blk = blk_by_name(device); blk = blk_by_name(device);
if (!blk) { if (!blk) {
error_set(errp, QERR_DEVICE_NOT_FOUND, device); error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND,
"Device '%s' not found", device);
return; return;
} }
bs = blk_bs(blk); bs = blk_bs(blk);
...@@ -2477,7 +2485,8 @@ void qmp_drive_backup(const char *device, const char *target, ...@@ -2477,7 +2485,8 @@ void qmp_drive_backup(const char *device, const char *target,
blk = blk_by_name(device); blk = blk_by_name(device);
if (!blk) { if (!blk) {
error_set(errp, QERR_DEVICE_NOT_FOUND, device); error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND,
"Device '%s' not found", device);
return; return;
} }
bs = blk_bs(blk); bs = blk_bs(blk);
...@@ -2691,7 +2700,8 @@ void qmp_drive_mirror(const char *device, const char *target, ...@@ -2691,7 +2700,8 @@ void qmp_drive_mirror(const char *device, const char *target,
blk = blk_by_name(device); blk = blk_by_name(device);
if (!blk) { if (!blk) {
error_set(errp, QERR_DEVICE_NOT_FOUND, device); error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND,
"Device '%s' not found", device);
return; return;
} }
bs = blk_bs(blk); bs = blk_bs(blk);
...@@ -2957,7 +2967,8 @@ void qmp_change_backing_file(const char *device, ...@@ -2957,7 +2967,8 @@ void qmp_change_backing_file(const char *device,
blk = blk_by_name(device); blk = blk_by_name(device);
if (!blk) { if (!blk) {
error_set(errp, QERR_DEVICE_NOT_FOUND, device); error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND,
"Device '%s' not found", device);
return; return;
} }
bs = blk_bs(blk); bs = blk_bs(blk);
......
...@@ -1867,7 +1867,8 @@ void hmp_qemu_io(Monitor *mon, const QDict *qdict) ...@@ -1867,7 +1867,8 @@ void hmp_qemu_io(Monitor *mon, const QDict *qdict)
if (blk) { if (blk) {
qemuio_command(blk, command); qemuio_command(blk, command);
} else { } else {
error_set(&err, QERR_DEVICE_NOT_FOUND, device); error_set(&err, ERROR_CLASS_DEVICE_NOT_FOUND,
"Device '%s' not found", device);
} }
hmp_handle_error(mon, &err); hmp_handle_error(mon, &err);
...@@ -1995,7 +1996,8 @@ void hmp_qom_set(Monitor *mon, const QDict *qdict) ...@@ -1995,7 +1996,8 @@ void hmp_qom_set(Monitor *mon, const QDict *qdict)
obj = object_resolve_path(path, &ambiguous); obj = object_resolve_path(path, &ambiguous);
if (obj == NULL) { if (obj == NULL) {
error_set(&err, QERR_DEVICE_NOT_FOUND, path); error_set(&err, ERROR_CLASS_DEVICE_NOT_FOUND,
"Device '%s' not found", path);
} else { } else {
if (ambiguous) { if (ambiguous) {
monitor_printf(mon, "Warning: Path '%s' is ambiguous\n", path); monitor_printf(mon, "Warning: Path '%s' is ambiguous\n", path);
......
...@@ -55,9 +55,6 @@ void qerror_report_err(Error *err); ...@@ -55,9 +55,6 @@ void qerror_report_err(Error *err);
#define QERR_DEVICE_NO_HOTPLUG \ #define QERR_DEVICE_NO_HOTPLUG \
ERROR_CLASS_GENERIC_ERROR, "Device '%s' does not support hotplugging" ERROR_CLASS_GENERIC_ERROR, "Device '%s' does not support hotplugging"
#define QERR_DEVICE_NOT_FOUND \
ERROR_CLASS_DEVICE_NOT_FOUND, "Device '%s' not found"
#define QERR_FD_NOT_FOUND \ #define QERR_FD_NOT_FOUND \
ERROR_CLASS_GENERIC_ERROR, "File descriptor named '%s' not found" ERROR_CLASS_GENERIC_ERROR, "File descriptor named '%s' not found"
......
...@@ -1127,7 +1127,8 @@ void qmp_netdev_del(const char *id, Error **errp) ...@@ -1127,7 +1127,8 @@ void qmp_netdev_del(const char *id, Error **errp)
nc = qemu_find_netdev(id); nc = qemu_find_netdev(id);
if (!nc) { if (!nc) {
error_set(errp, QERR_DEVICE_NOT_FOUND, id); error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND,
"Device '%s' not found", id);
return; return;
} }
...@@ -1238,7 +1239,8 @@ void qmp_set_link(const char *name, bool up, Error **errp) ...@@ -1238,7 +1239,8 @@ void qmp_set_link(const char *name, bool up, Error **errp)
MAX_QUEUE_NUM); MAX_QUEUE_NUM);
if (queues == 0) { if (queues == 0) {
error_set(errp, QERR_DEVICE_NOT_FOUND, name); error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND,
"Device '%s' not found", name);
return; return;
} }
nc = ncs[0]; nc = ncs[0];
......
...@@ -457,7 +457,8 @@ static BusState *qbus_find(const char *path, Error **errp) ...@@ -457,7 +457,8 @@ static BusState *qbus_find(const char *path, Error **errp)
pos += len; pos += len;
dev = qbus_find_dev(bus, elem); dev = qbus_find_dev(bus, elem);
if (!dev) { if (!dev) {
error_set(errp, QERR_DEVICE_NOT_FOUND, elem); error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND,
"Device '%s' not found", elem);
#if 0 /* conversion from qerror_report() to error_set() broke this: */ #if 0 /* conversion from qerror_report() to error_set() broke this: */
if (!monitor_cur_is_qmp()) { if (!monitor_cur_is_qmp()) {
qbus_list_dev(bus); qbus_list_dev(bus);
...@@ -793,7 +794,8 @@ void qmp_device_del(const char *id, Error **errp) ...@@ -793,7 +794,8 @@ void qmp_device_del(const char *id, Error **errp)
g_free(path); g_free(path);
if (!obj) { if (!obj) {
error_set(errp, QERR_DEVICE_NOT_FOUND, id); error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND,
"Device '%s' not found", id);
return; return;
} }
......
...@@ -206,7 +206,8 @@ ObjectPropertyInfoList *qmp_qom_list(const char *path, Error **errp) ...@@ -206,7 +206,8 @@ ObjectPropertyInfoList *qmp_qom_list(const char *path, Error **errp)
if (ambiguous) { if (ambiguous) {
error_setg(errp, "Path '%s' is ambiguous", path); error_setg(errp, "Path '%s' is ambiguous", path);
} else { } else {
error_set(errp, QERR_DEVICE_NOT_FOUND, path); error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND,
"Device '%s' not found", path);
} }
return NULL; return NULL;
} }
...@@ -236,7 +237,8 @@ int qmp_qom_set(Monitor *mon, const QDict *qdict, QObject **ret) ...@@ -236,7 +237,8 @@ int qmp_qom_set(Monitor *mon, const QDict *qdict, QObject **ret)
obj = object_resolve_path(path, NULL); obj = object_resolve_path(path, NULL);
if (!obj) { if (!obj) {
error_set(&local_err, QERR_DEVICE_NOT_FOUND, path); error_set(&local_err, ERROR_CLASS_DEVICE_NOT_FOUND,
"Device '%s' not found", path);
goto out; goto out;
} }
...@@ -261,7 +263,8 @@ int qmp_qom_get(Monitor *mon, const QDict *qdict, QObject **ret) ...@@ -261,7 +263,8 @@ int qmp_qom_get(Monitor *mon, const QDict *qdict, QObject **ret)
obj = object_resolve_path(path, NULL); obj = object_resolve_path(path, NULL);
if (!obj) { if (!obj) {
error_set(&local_err, QERR_DEVICE_NOT_FOUND, path); error_set(&local_err, ERROR_CLASS_DEVICE_NOT_FOUND,
"Device '%s' not found", path);
goto out; goto out;
} }
...@@ -518,7 +521,8 @@ DevicePropertyInfoList *qmp_device_list_properties(const char *typename, ...@@ -518,7 +521,8 @@ DevicePropertyInfoList *qmp_device_list_properties(const char *typename,
klass = object_class_by_name(typename); klass = object_class_by_name(typename);
if (klass == NULL) { if (klass == NULL) {
error_set(errp, QERR_DEVICE_NOT_FOUND, typename); error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND,
"Device '%s' not found", typename);
return NULL; return NULL;
} }
......
...@@ -999,7 +999,8 @@ Object *object_property_get_link(Object *obj, const char *name, ...@@ -999,7 +999,8 @@ Object *object_property_get_link(Object *obj, const char *name,
if (str && *str) { if (str && *str) {
target = object_resolve_path(str, NULL); target = object_resolve_path(str, NULL);
if (!target) { if (!target) {
error_set(errp, QERR_DEVICE_NOT_FOUND, str); error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND,
"Device '%s' not found", str);
} }
} }
...@@ -1305,7 +1306,8 @@ static Object *object_resolve_link(Object *obj, const char *name, ...@@ -1305,7 +1306,8 @@ static Object *object_resolve_link(Object *obj, const char *name,
if (target || ambiguous) { if (target || ambiguous) {
error_set(errp, QERR_INVALID_PARAMETER_TYPE, name, target_type); error_set(errp, QERR_INVALID_PARAMETER_TYPE, name, target_type);
} else { } else {
error_set(errp, QERR_DEVICE_NOT_FOUND, path); error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND,
"Device '%s' not found", path);
} }
target = NULL; target = NULL;
} }
......
...@@ -84,7 +84,8 @@ void qemu_input_handler_bind(QemuInputHandlerState *s, ...@@ -84,7 +84,8 @@ void qemu_input_handler_bind(QemuInputHandlerState *s,
dev = qdev_find_recursive(sysbus_get_default(), device_id); dev = qdev_find_recursive(sysbus_get_default(), device_id);
if (dev == NULL) { if (dev == NULL) {
error_set(errp, QERR_DEVICE_NOT_FOUND, device_id); error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND,
"Device '%s' not found", device_id);
return; return;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册