[libvirt] [PATCH 25/30] macvtap: Remove virConnectPtr from ReportError

Matthias Bolte matthias.bolte at googlemail.com
Sun Apr 4 17:36:48 UTC 2010


Also rename ReportError to macvtapError.
---
 src/qemu/qemu_conf.c |    2 +-
 src/util/macvtap.c   |   63 +++++++++++++++++++++++---------------------------
 src/util/macvtap.h   |    3 +-
 3 files changed, 31 insertions(+), 37 deletions(-)

diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
index b679b35..f20ee21 100644
--- a/src/qemu/qemu_conf.c
+++ b/src/qemu/qemu_conf.c
@@ -1469,7 +1469,7 @@ qemudPhysIfaceConnect(virConnectPtr conn,
         net->model && STREQ(net->model, "virtio"))
         vnet_hdr = 1;
 
-    rc = openMacvtapTap(conn, net->ifname, net->mac, linkdev, brmode,
+    rc = openMacvtapTap(net->ifname, net->mac, linkdev, brmode,
                         &res_ifname, vnet_hdr);
     if (rc >= 0) {
         VIR_FREE(net->ifname);
diff --git a/src/util/macvtap.c b/src/util/macvtap.c
index 999e670..87c2800 100644
--- a/src/util/macvtap.c
+++ b/src/util/macvtap.c
@@ -49,9 +49,9 @@
 
 # define VIR_FROM_THIS VIR_FROM_NET
 
-# define ReportError(conn, code, ...)                                      \
-        virReportErrorHelper(conn, VIR_FROM_NET, code, __FILE__,          \
-                               __FUNCTION__, __LINE__, __VA_ARGS__)
+# define macvtapError(code, ...)                                           \
+        virReportErrorHelper(NULL, VIR_FROM_NET, code, __FILE__,           \
+                             __FUNCTION__, __LINE__, __VA_ARGS__)
 
 # define MACVTAP_NAME_PREFIX	"macvtap"
 # define MACVTAP_NAME_PATTERN	"macvtap%d"
@@ -193,7 +193,7 @@ nlAppend(struct nlmsghdr *nlm, int totlen, const void *data, int datalen)
 
 
 static int
-getIfIndex(virConnectPtr conn,
+getIfIndex(int reportError,
            const char *ifname,
            int *idx)
 {
@@ -206,20 +206,20 @@ getIfIndex(virConnectPtr conn,
 
     if (virStrncpy(ifreq.ifr_name, ifname, strlen(ifname),
                    sizeof(ifreq.ifr_name)) == NULL) {
-        if (conn)
-            ReportError(conn, VIR_ERR_INTERNAL_ERROR,
-                        _("invalid interface name %s"),
-                        ifname);
+        if (reportError)
+            macvtapError(VIR_ERR_INTERNAL_ERROR,
+                         _("invalid interface name %s"),
+                         ifname);
         rc = EINVAL;
         goto err_exit;
     }
     if (ioctl(fd, SIOCGIFINDEX, &ifreq) >= 0)
         *idx = ifreq.ifr_ifindex;
     else {
-        if (conn)
-            ReportError(conn, VIR_ERR_INTERNAL_ERROR,
-                        _("interface %s does not exist"),
-                        ifname);
+        if (reportError)
+            macvtapError(VIR_ERR_INTERNAL_ERROR,
+                         _("interface %s does not exist"),
+                         ifname);
         rc = ENODEV;
     }
 
@@ -296,8 +296,7 @@ ifUp(const char *name, int up)
 
 
 static int
-link_add(virConnectPtr conn,
-         const char *type,
+link_add(const char *type,
          const unsigned char *macaddress, int macaddrsize,
          const char *ifname,
          const char *srcdev,
@@ -315,7 +314,7 @@ link_add(virConnectPtr conn,
     char *recvbuf = NULL;
     int recvbuflen;
 
-    if (getIfIndex(conn, srcdev, &ifindex) != 0)
+    if (getIfIndex(1, srcdev, &ifindex) != 0)
         return -1;
 
     *retry = 0;
@@ -434,14 +433,14 @@ link_add(virConnectPtr conn,
     return rc;
 
 malformed_resp:
-    ReportError(conn, VIR_ERR_INTERNAL_ERROR,
-                "%s", _("malformed netlink response message"));
+    macvtapError(VIR_ERR_INTERNAL_ERROR, "%s",
+                 _("malformed netlink response message"));
     VIR_FREE(recvbuf);
     return -1;
 
 buffer_too_small:
-    ReportError(conn, VIR_ERR_INTERNAL_ERROR,
-                "%s", _("internal buffer is too small"));
+    macvtapError(VIR_ERR_INTERNAL_ERROR, "%s",
+                 _("internal buffer is too small"));
     return -1;
 }
 
@@ -512,21 +511,20 @@ link_del(const char *name)
     return rc;
 
 malformed_resp:
-    ReportError(NULL, VIR_ERR_INTERNAL_ERROR,
-                "%s", _("malformed netlink response message"));
+    macvtapError(VIR_ERR_INTERNAL_ERROR, "%s",
+                 _("malformed netlink response message"));
     VIR_FREE(recvbuf);
     return -1;
 
 buffer_too_small:
-    ReportError(NULL, VIR_ERR_INTERNAL_ERROR,
-                "%s", _("internal buffer is too small"));
+    macvtapError(VIR_ERR_INTERNAL_ERROR, "%s",
+                 _("internal buffer is too small"));
     return -1;
 }
 
 
 /* Open the macvtap's tap device.
- * @conn: Pointer to virConnect object
- * @name: Name of the macvtap interface
+ * @ifname: Name of the macvtap interface
  * @retries : Number of retries in case udev for example may need to be
  *            waited for to create the tap chardev
  * Returns negative value in case of error, the file descriptor otherwise.
@@ -677,7 +675,6 @@ configMacvtapTap(int tapfd, int vnet_hdr)
  * openMacvtapTap:
  * Create an instance of a macvtap device and open its tap character
  * device.
- * @conn: Pointer to virConnect object
  * @tgifname: Interface name that the macvtap is supposed to have. May
  *    be NULL if this function is supposed to choose a name
  * @macaddress: The MAC address for the macvtap device
@@ -689,13 +686,11 @@ configMacvtapTap(int tapfd, int vnet_hdr)
  *     to the caller to free the string.
  *
  * Returns file descriptor of the tap device in case of success,
- * negative value otherwise with error message attached to the 'conn'
- * object.
+ * negative value otherwise with error reported.
  *
  */
 int
-openMacvtapTap(virConnectPtr conn,
-               const char *tgifname,
+openMacvtapTap(const char *tgifname,
                const unsigned char *macaddress,
                const char *linkdev,
                int mode,
@@ -713,7 +708,7 @@ openMacvtapTap(virConnectPtr conn,
     *res_ifname = NULL;
 
     if (tgifname) {
-        if(getIfIndex(NULL, tgifname, &ifindex) == 0) {
+        if(getIfIndex(0, tgifname, &ifindex) == 0) {
             if (STRPREFIX(tgifname,
                           MACVTAP_NAME_PREFIX)) {
                 goto create_name;
@@ -723,7 +718,7 @@ openMacvtapTap(virConnectPtr conn,
             return -1;
         }
         cr_ifname = tgifname;
-        rc = link_add(conn, type, macaddress, 6, tgifname, linkdev,
+        rc = link_add(type, macaddress, 6, tgifname, linkdev,
                       macvtapMode, &do_retry);
         if (rc)
             return -1;
@@ -732,8 +727,8 @@ create_name:
         retries = 5;
         for (c = 0; c < 8192; c++) {
             snprintf(ifname, sizeof(ifname), MACVTAP_NAME_PATTERN, c);
-            if (getIfIndex(NULL, ifname, &ifindex) == ENODEV) {
-                rc = link_add(conn, type, macaddress, 6, ifname, linkdev,
+            if (getIfIndex(0, ifname, &ifindex) == ENODEV) {
+                rc = link_add(type, macaddress, 6, ifname, linkdev,
                               macvtapMode, &do_retry);
                 if (rc == 0)
                     break;
diff --git a/src/util/macvtap.h b/src/util/macvtap.h
index bd5f4d6..5d4ea5e 100644
--- a/src/util/macvtap.h
+++ b/src/util/macvtap.h
@@ -28,8 +28,7 @@
 
 #  include "internal.h"
 
-int openMacvtapTap(virConnectPtr conn,
-                   const char *ifname,
+int openMacvtapTap(const char *ifname,
                    const unsigned char *macaddress,
                    const char *linkdev,
                    int mode,
-- 
1.6.3.3




More information about the libvir-list mailing list