[PATCH v2 6/8] remote: Implement virDomainInterfacesAddresses

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



---
 daemon/remote.c              | 140 +++++++++++++++++++++++++++++++++++++++++++
 src/remote/remote_driver.c   |  94 +++++++++++++++++++++++++++++
 src/remote/remote_protocol.x |  27 ++++++++-
 src/remote_protocol-structs  |  27 +++++++++
 4 files changed, 287 insertions(+), 1 deletion(-)

diff --git a/daemon/remote.c b/daemon/remote.c
index 8767c18..7363e2a 100644
--- a/daemon/remote.c
+++ b/daemon/remote.c
@@ -4783,3 +4783,143 @@ no_memory:
     virReportOOMError();
     return -1;
 }
+
+static int
+remoteSerializeDomainInterfacesPtr(virDomainInterfacePtr *ifaces,
+                                   int ifacesCount,
+                                   remote_domain_interfaces_addresses_ret *ret)
+{
+    int i, j;
+
+    if (!ifacesCount)
+        return 0;
+
+    if (VIR_ALLOC_N(ret->ifaces.ifaces_val, ifacesCount) < 0) {
+        virReportOOMError();
+        return -1;
+    }
+
+    ret->ifaces.ifaces_len = ifacesCount;
+
+    for (i = 0; i < ifacesCount; i++) {
+        virDomainInterfacePtr tmp = ifaces[i];
+        remote_domain_interface *tmp_ret = &(ret->ifaces.ifaces_val[i]);
+
+        if (!(tmp_ret->name = strdup(tmp->name)))
+            goto no_memory;
+
+        if (tmp->hwaddr) {
+            char **hwaddr_p = NULL;
+            if (VIR_ALLOC(hwaddr_p) < 0)
+                goto no_memory;
+            *hwaddr_p = strdup(tmp->hwaddr);
+            if (!*hwaddr_p) {
+                VIR_FREE(hwaddr_p);
+                goto no_memory;
+            }
+
+            tmp_ret->hwaddr = hwaddr_p;
+        }
+
+        tmp_ret->flags = tmp->flags;
+
+        if (!tmp->ip_addrs_count)
+            continue;
+
+        if (VIR_ALLOC_N(tmp_ret->ip_addrs.ip_addrs_val,
+                        tmp->ip_addrs_count) < 0)
+            goto no_memory;
+
+        tmp_ret->ip_addrs.ip_addrs_len = tmp->ip_addrs_count;
+
+        for (j = 0; j < tmp->ip_addrs_count; j++) {
+            virDomainIPAddress addr = tmp->ip_addrs[j];
+            remote_domain_ip_addrs *addr_ret = &(tmp_ret->ip_addrs.ip_addrs_val[j]);
+
+            addr_ret->prefix = addr.prefix;
+            addr_ret->type = addr.type;
+
+            if (addr.addr) {
+                char **addr_p = NULL;
+                if (VIR_ALLOC(addr_p) < 0)
+                    goto no_memory;
+                *addr_p = strdup(addr.addr);
+                if (!*addr_p) {
+                    VIR_FREE(addr_p);
+                    goto no_memory;
+                }
+                addr_ret->addr = addr_p;
+            }
+
+            if (addr.dstaddr) {
+                char **addr_p = NULL;
+                if (VIR_ALLOC(addr_p) < 0)
+                    goto no_memory;
+                *addr_p = strdup(addr.dstaddr);
+                if (!*addr_p) {
+                    VIR_FREE(addr_p);
+                    goto no_memory;
+                }
+                addr_ret->dstaddr = addr_p;
+            }
+        }
+    }
+
+    return 0;
+
+no_memory:
+    virReportOOMError();
+    for (i = 0; i < ret->ifaces.ifaces_len; i++) {
+        remote_domain_interface tmp_ret = ret->ifaces.ifaces_val[i];
+
+        VIR_FREE(tmp_ret.name);
+        VIR_FREE(tmp_ret.hwaddr);
+        for (j = 0; j < tmp_ret.ip_addrs.ip_addrs_len; j++) {
+            VIR_FREE(tmp_ret.ip_addrs.ip_addrs_val[j].addr);
+            VIR_FREE(tmp_ret.ip_addrs.ip_addrs_val[j].dstaddr);
+        }
+    }
+    VIR_FREE(ret->ifaces.ifaces_val);
+
+    return -1;
+}
+
+static int
+remoteDispatchDomainInterfacesAddresses(virNetServerPtr server ATTRIBUTE_UNUSED,
+                                        virNetServerClientPtr client,
+                                        virNetMessagePtr msg ATTRIBUTE_UNUSED,
+                                        virNetMessageErrorPtr rerr,
+                                        remote_domain_interfaces_addresses_args *args,
+                                        remote_domain_interfaces_addresses_ret *ret)
+{
+    int rv = -1;
+    virDomainPtr dom = NULL;
+    virDomainInterfacePtr *ifaces = NULL;
+    int ifacesCount = 0;
+    struct daemonClientPrivate *priv = virNetServerClientGetPrivateData(client);
+
+    if (!(dom = get_nonnull_domain(priv->conn, args->domain)))
+        goto cleanup;
+
+    ifacesCount = virDomainInterfacesAddresses(dom, &ifaces,
+                                               args->method,
+                                               args->flags);
+    if (ifacesCount < 0)
+        goto cleanup;
+
+    if (remoteSerializeDomainInterfacesPtr(ifaces, ifacesCount, ret) < 0)
+        goto cleanup;
+
+    rv = 0;
+
+cleanup:
+    if (rv < 0)
+        virNetMessageSaveError(rerr);
+    if (dom)
+        virDomainFree(dom);
+
+    while (ifacesCount > 0)
+        virDomainInterfaceFree(ifaces[--ifacesCount]);
+    VIR_FREE(ifaces);
+    return rv;
+}
diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c
index ae861cc..7290f30 100644
--- a/src/remote/remote_driver.c
+++ b/src/remote/remote_driver.c
@@ -5834,6 +5834,99 @@ done:
     return rv;
 }
 
+static int
+remoteDomainInterfacesAddresses(virDomainPtr dom,
+                                virDomainInterfacePtr **ifaces,
+                                unsigned int method,
+                                unsigned int flags)
+{
+    int rv = -1;
+    remote_domain_interfaces_addresses_args args;
+    remote_domain_interfaces_addresses_ret ret;
+    struct private_data *priv = dom->conn->privateData;
+    int i, j;
+
+    *ifaces = NULL;
+
+    memset(&ret, 0, sizeof(ret));
+    make_nonnull_domain(&args.domain, dom);
+    args.method = method;
+    args.flags = flags;
+
+    remoteDriverLock(priv);
+
+    if (call(dom->conn, priv, 0, REMOTE_PROC_DOMAIN_INTERFACES_ADDRESSES,
+             (xdrproc_t)xdr_remote_domain_interfaces_addresses_args,
+             (char *)&args,
+             (xdrproc_t)xdr_remote_domain_interfaces_addresses_ret,
+             (char *)&ret) == -1)
+        goto cleanup;
+
+    if (!ret.ifaces.ifaces_len) {
+        rv = 0;
+        goto cleanup;
+    }
+
+    if (VIR_ALLOC_N(*ifaces, ret.ifaces.ifaces_len * sizeof(virDomainInterfacePtr)) < 0)
+        goto no_memory;
+
+    for (i = 0; i < ret.ifaces.ifaces_len; i++) {
+        virDomainInterfacePtr tmp = NULL;
+        remote_domain_interface tmp_ret = ret.ifaces.ifaces_val[i];
+
+        if (VIR_ALLOC(tmp) < 0)
+            goto no_memory;
+
+        (*ifaces)[i] = tmp;
+
+        if (!(tmp->name = strdup(tmp_ret.name)))
+            goto no_memory;
+
+        if (tmp_ret.hwaddr &&
+            !(tmp->hwaddr = strdup(*tmp_ret.hwaddr)))
+            goto no_memory;
+
+        tmp->flags = tmp_ret.flags;
+
+        if (!tmp_ret.ip_addrs.ip_addrs_len)
+            continue;
+
+        if (VIR_ALLOC_N(tmp->ip_addrs, tmp_ret.ip_addrs.ip_addrs_len) < 0)
+            goto no_memory;
+
+        tmp->ip_addrs_count = tmp_ret.ip_addrs.ip_addrs_len;
+        for (j = 0; j < tmp->ip_addrs_count; j++) {
+            virDomainIPAddressPtr addr = &(tmp->ip_addrs[j]);
+            remote_domain_ip_addrs addr_ret = tmp_ret.ip_addrs.ip_addrs_val[j];
+
+            addr->prefix = addr_ret.prefix;
+            addr->type = addr_ret.type;
+            if (addr_ret.addr &&
+                !(addr->addr = strdup(*addr_ret.addr)))
+                goto no_memory;
+
+            if (addr_ret.dstaddr &&
+                !(addr->dstaddr = strdup(*addr_ret.dstaddr)))
+                goto no_memory;
+        }
+    }
+
+    rv = ret.ifaces.ifaces_len;
+
+cleanup:
+    remoteDriverUnlock(priv);
+    xdr_free((xdrproc_t)xdr_remote_domain_interfaces_addresses_ret,
+             (char *) &ret);
+    return rv;
+
+no_memory:
+    virReportOOMError();
+    for (i = 0; i < ret.ifaces.ifaces_len; i++)
+        virDomainInterfaceFree((*ifaces)[i]);
+    VIR_FREE(*ifaces);
+    goto cleanup;
+}
+
 static void
 remoteDomainEventQueue(struct private_data *priv, virDomainEventPtr event)
 {
@@ -6153,6 +6246,7 @@ static virDriver remote_driver = {
     .nodeGetMemoryParameters = remoteNodeGetMemoryParameters, /* 0.10.2 */
     .nodeGetCPUMap = remoteNodeGetCPUMap, /* 1.0.0 */
     .domainFSTrim = remoteDomainFSTrim, /* 1.0.1 */
+    .domainInterfacesAddresses = remoteDomainInterfacesAddresses, /* 1.0.2 */
 };
 
 static virNetworkDriver network_driver = {
diff --git a/src/remote/remote_protocol.x b/src/remote/remote_protocol.x
index bdad9f0..bd15107 100644
--- a/src/remote/remote_protocol.x
+++ b/src/remote/remote_protocol.x
@@ -2696,6 +2696,30 @@ struct remote_domain_fstrim_args {
     unsigned int flags;
 };
 
+struct remote_domain_ip_addrs {
+    int type;
+    remote_string addr;
+    int prefix;
+    remote_string dstaddr;
+};
+
+struct remote_domain_interface {
+    remote_nonnull_string name;
+    unsigned int flags;
+    remote_string hwaddr;
+    remote_domain_ip_addrs ip_addrs<>;
+};
+
+struct remote_domain_interfaces_addresses_args {
+    remote_nonnull_domain domain;
+    unsigned int method;
+    unsigned int flags;
+};
+
+struct remote_domain_interfaces_addresses_ret {
+    remote_domain_interface ifaces<>;
+};
+
 /*----- Protocol. -----*/
 
 /* Define the program number, protocol version and procedure numbers here. */
@@ -3042,7 +3066,8 @@ enum remote_procedure {
     REMOTE_PROC_DOMAIN_EVENT_PMSUSPEND_DISK = 292, /* autogen autogen */
     REMOTE_PROC_NODE_GET_CPU_MAP = 293, /* skipgen skipgen */
     REMOTE_PROC_DOMAIN_FSTRIM = 294, /* autogen autogen */
-    REMOTE_PROC_DOMAIN_SEND_PROCESS_SIGNAL = 295 /* autogen autogen */
+    REMOTE_PROC_DOMAIN_SEND_PROCESS_SIGNAL = 295, /* autogen autogen */
+    REMOTE_PROC_DOMAIN_INTERFACES_ADDRESSES = 296 /* skipgen skipgen */
 
     /*
      * Notice how the entries are grouped in sets of 10 ?
diff --git a/src/remote_protocol-structs b/src/remote_protocol-structs
index e7d05b8..b481f4f 100644
--- a/src/remote_protocol-structs
+++ b/src/remote_protocol-structs
@@ -2151,6 +2151,32 @@ struct remote_domain_fstrim_args {
         uint64_t                   minimum;
         u_int                      flags;
 };
+struct remote_domain_ip_addrs {
+        int                        type;
+        remote_string              addr;
+        int                        prefix;
+        remote_string              dstaddr;
+};
+struct remote_domain_interface {
+        remote_nonnull_string      name;
+        u_int                      flags;
+        remote_string              hwaddr;
+        struct {
+                u_int              ip_addrs_len;
+                remote_domain_ip_addrs * ip_addrs_val;
+        } ip_addrs;
+};
+struct remote_domain_interfaces_addresses_args {
+        remote_nonnull_domain      domain;
+        u_int                      method;
+        u_int                      flags;
+};
+struct remote_domain_interfaces_addresses_ret {
+        struct {
+                u_int              ifaces_len;
+                remote_domain_interface * ifaces_val;
+        } ifaces;
+};
 enum remote_procedure {
         REMOTE_PROC_OPEN = 1,
         REMOTE_PROC_CLOSE = 2,
@@ -2447,4 +2473,5 @@ enum remote_procedure {
         REMOTE_PROC_NODE_GET_CPU_MAP = 293,
         REMOTE_PROC_DOMAIN_FSTRIM = 294,
         REMOTE_PROC_DOMAIN_SEND_PROCESS_SIGNAL = 295,
+        REMOTE_PROC_DOMAIN_INTERFACES_ADDRESSES = 296,
 };
-- 
1.8.0.2

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]