Move to monitor.c:monitor_handle_fd_param() as a common helper. Signed-off-by: Alex Williamson <alex.william...@redhat.com> ---
I'd like to use this for the proposed device assignment configfd parameter since there's nothing net specific about it. monitor.c | 17 +++++++++++++++++ monitor.h | 1 + net.c | 17 ----------------- net.h | 2 -- net/socket.c | 3 ++- net/tap.c | 5 +++-- 6 files changed, 23 insertions(+), 22 deletions(-) diff --git a/monitor.c b/monitor.c index ad50f12..b7bf991 100644 --- a/monitor.c +++ b/monitor.c @@ -2496,6 +2496,23 @@ int monitor_get_fd(Monitor *mon, const char *fdname) return -1; } +int monitor_handle_fd_param(Monitor *mon, const char *param) +{ + if (!qemu_isdigit(param[0])) { + int fd; + + fd = monitor_get_fd(mon, param); + if (fd == -1) { + error_report("No file descriptor named %s found", param); + return -1; + } + + return fd; + } else { + return strtol(param, NULL, 0); + } +} + static const mon_cmd_t mon_cmds[] = { #include "qemu-monitor.h" { NULL, NULL, }, diff --git a/monitor.h b/monitor.h index ea15469..354c968 100644 --- a/monitor.h +++ b/monitor.h @@ -44,6 +44,7 @@ int monitor_read_bdrv_key_start(Monitor *mon, BlockDriverState *bs, void *opaque); int monitor_get_fd(Monitor *mon, const char *fdname); +int monitor_handle_fd_param(Monitor *mon, const char *param); void monitor_vprintf(Monitor *mon, const char *fmt, va_list ap); void monitor_printf(Monitor *mon, const char *fmt, ...) diff --git a/net.c b/net.c index 378edfc..af4ffaf 100644 --- a/net.c +++ b/net.c @@ -737,23 +737,6 @@ int qemu_find_nic_model(NICInfo *nd, const char * const *models, return -1; } -int net_handle_fd_param(Monitor *mon, const char *param) -{ - if (!qemu_isdigit(param[0])) { - int fd; - - fd = monitor_get_fd(mon, param); - if (fd == -1) { - error_report("No file descriptor named %s found", param); - return -1; - } - - return fd; - } else { - return strtol(param, NULL, 0); - } -} - static int net_init_nic(QemuOpts *opts, Monitor *mon, const char *name, diff --git a/net.h b/net.h index b83f615..20b4840 100644 --- a/net.h +++ b/net.h @@ -177,6 +177,4 @@ int do_netdev_del(Monitor *mon, const QDict *qdict, QObject **ret_data); void qdev_set_nic_properties(DeviceState *dev, NICInfo *nd); -int net_handle_fd_param(Monitor *mon, const char *param); - #endif diff --git a/net/socket.c b/net/socket.c index 1c4e153..89ccf1d 100644 --- a/net/socket.c +++ b/net/socket.c @@ -31,6 +31,7 @@ #include "qemu-error.h" #include "qemu-option.h" #include "qemu_socket.h" +#include "monitor.h" typedef struct NetSocketState { VLANClientState nc; @@ -510,7 +511,7 @@ int net_init_socket(QemuOpts *opts, return -1; } - fd = net_handle_fd_param(mon, qemu_opt_get(opts, "fd")); + fd = monitor_handle_fd_param(mon, qemu_opt_get(opts, "fd")); if (fd == -1) { return -1; } diff --git a/net/tap.c b/net/tap.c index 0147dab..645cc16 100644 --- a/net/tap.c +++ b/net/tap.c @@ -39,6 +39,7 @@ #include "qemu-char.h" #include "qemu-common.h" #include "qemu-error.h" +#include "monitor.h" #include "net/tap-linux.h" @@ -413,7 +414,7 @@ int net_init_tap(QemuOpts *opts, Monitor *mon, const char *name, VLANState *vlan return -1; } - fd = net_handle_fd_param(mon, qemu_opt_get(opts, "fd")); + fd = monitor_handle_fd_param(mon, qemu_opt_get(opts, "fd")); if (fd == -1) { return -1; } @@ -468,7 +469,7 @@ int net_init_tap(QemuOpts *opts, Monitor *mon, const char *name, VLANState *vlan if (qemu_opt_get_bool(opts, "vhost", !!qemu_opt_get(opts, "vhostfd"))) { int vhostfd, r; if (qemu_opt_get(opts, "vhostfd")) { - r = net_handle_fd_param(mon, qemu_opt_get(opts, "vhostfd")); + r = monitor_handle_fd_param(mon, qemu_opt_get(opts, "vhostfd")); if (r == -1) { return -1; }