Skip to contentSkip to conversation

move net_handle_fd_param() into a common utility function

PATCH In review Alex Williamson 2 participants 2 messages May 26, 2010 – May 27, 2010

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 move net_handle_fd_param() into a common utility function

Move to monitor.c:monitor_handle_fd_param() as a common helper.

---

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(-)
monitor.c +17 -0
index ad50f12..b7bf991 100644
@@ -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, },
monitor.h +1 -0
index ea15469..354c968 100644
@@ -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, ...)
net.c +0 -17
index 378edfc..af4ffaf 100644
@@ -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,
net.h +0 -2
index b83f615..20b4840 100644
@@ -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
net/socket.c +2 -1
index 1c4e153..89ccf1d 100644
@@ -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;
         }
net/tap.c +3 -2
index 0147dab..645cc16 100644
@@ -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;
             }
#1 lore raw
Quoted 7 lines · Alex Williamson

Move to monitor.c:monitor_handle_fd_param() as a common helper.

---

I'd like to use this for the proposed device assignment configfd parameter since there's nothing net specific about it.

Looks good.

Error checking after strtol() is as absent as before, but that's a separate issue, which shouldn't stop this patch.