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

[Libvir] 3/4 Remote driver



This implements the changes in the client & server ends of the remote
driver.

Rich.

-- 
Emerging Technologies, Red Hat - http://et.redhat.com/~rjones/
Registered Address: Red Hat UK Ltd, Amberley Place, 107-111 Peascod
Street, Windsor, Berkshire, SL4 1TE, United Kingdom.  Registered in
England and Wales under Company Registration No. 03798903
Index: src/remote_internal.c
===================================================================
RCS file: /data/cvs/libvirt/src/remote_internal.c,v
retrieving revision 1.60
diff -u -r1.60 remote_internal.c
--- src/remote_internal.c	20 Feb 2008 15:23:36 -0000	1.60
+++ src/remote_internal.c	21 Feb 2008 20:44:08 -0000
@@ -2681,9 +2681,104 @@
     return 0;
 }
 
+static int
+remoteNetworkNumOfDHCPHostMappings (virNetworkPtr network)
+{
+    remote_network_num_of_dhcp_host_mappings_args args;
+    remote_network_num_of_dhcp_host_mappings_ret ret;
+    GET_NETWORK_PRIVATE (network->conn, -1);
+
+    make_nonnull_network (&args.net, network);
+
+    if (call (network->conn, priv, 0, REMOTE_PROC_NETWORK_NUM_OF_DHCP_HOST_MAPPINGS,
+              (xdrproc_t) xdr_remote_network_num_of_dhcp_host_mappings_args, (char *) &args,
+              (xdrproc_t) xdr_remote_network_num_of_dhcp_host_mappings_ret, (char *) &ret) == -1)
+        return -1;
+
+    return ret.num;
+}
+
+
+static int
+remoteNetworkListDHCPHostMappings (virNetworkPtr network,
+                                   virNetworkDHCPHostMappingPtr *const mappings,
+                                   int maxmappings)
+{
+    remote_network_list_dhcp_host_mappings_args args;
+    remote_network_list_dhcp_host_mappings_ret ret;
+    int i;
+    GET_NETWORK_PRIVATE (network->conn, -1);
+
+    make_nonnull_network (&args.net, network);
+    args.maxmappings = maxmappings;
 
+    if (call (network->conn, priv, 0, REMOTE_PROC_NETWORK_LIST_DHCP_HOST_MAPPINGS,
+              (xdrproc_t) xdr_remote_network_list_dhcp_host_mappings_args, (char *) &args,
+              (xdrproc_t) xdr_remote_network_list_dhcp_host_mappings_ret, (char *) &ret) == -1)
+        return -1;
+
+    if (ret.mappings.mappings_len > maxmappings) {
+        error (network->conn, VIR_ERR_INTERNAL_ERROR,
+               _("remote end returned more mappings than we asked for"));
+        return -1;
+    }
+
+    /* We allocate them, caller frees. */
+    for (i = 0; i < ret.mappings.mappings_len; ++i) {
+        mappings[i] = malloc (sizeof (virNetworkDHCPHostMapping));
+        mappings[i]->hwaddr = ret.mappings.mappings_val[i].hwaddr;
+        mappings[i]->ipaddr = ret.mappings.mappings_val[i].ipaddr;
+        mappings[i]->hostname =
+            ret.mappings.mappings_val[i].hostname == NULL ?
+            NULL : *(ret.mappings.mappings_val[i].hostname);
+    }
+
+    return ret.mappings.mappings_len;
+}
 
 
+static int
+remoteNetworkAddDHCPHostMapping (virNetworkPtr network,
+                                 const char *hwaddr,
+                                 const char *ipaddr,
+                                 const char *hostname,
+                                 unsigned int flags)
+{
+    remote_network_add_dhcp_host_mapping_args args;
+    GET_NETWORK_PRIVATE (network->conn, -1);
+
+    make_nonnull_network (&args.net, network);
+    args.hwaddr = (char *) hwaddr;
+    args.ipaddr = (char *) ipaddr;
+    args.hostname = hostname == NULL ? NULL : (char **) &hostname;
+    args.flags = flags;
+
+    if (call (network->conn, priv, 0, REMOTE_PROC_NETWORK_ADD_DHCP_HOST_MAPPING,
+              (xdrproc_t) xdr_remote_network_add_dhcp_host_mapping_args, (char *) &args,
+              (xdrproc_t) xdr_void, (char *) NULL) == -1)
+        return -1;
+
+    return 0;
+}
+
+static int
+remoteNetworkDeleteDHCPHostMapping (virNetworkPtr network,
+                                    const char *hwaddr)
+{
+    remote_network_add_dhcp_host_mapping_args args;
+    GET_NETWORK_PRIVATE (network->conn, -1);
+
+    make_nonnull_network (&args.net, network);
+    args.hwaddr = (char *) hwaddr;
+
+    if (call (network->conn, priv, 0, REMOTE_PROC_NETWORK_DELETE_DHCP_HOST_MAPPING,
+              (xdrproc_t) xdr_remote_network_delete_dhcp_host_mapping_args, (char *) &args,
+              (xdrproc_t) xdr_void, (char *) NULL) == -1)
+        return -1;
+
+    return 0;
+}
+
 /*----------------------------------------------------------------------*/
 
 static int
@@ -4671,6 +4766,10 @@
     .networkGetBridgeName = remoteNetworkGetBridgeName,
     .networkGetAutostart = remoteNetworkGetAutostart,
     .networkSetAutostart = remoteNetworkSetAutostart,
+    .networkNumOfDHCPHostMappings = remoteNetworkNumOfDHCPHostMappings,
+    .networkListDHCPHostMappings = remoteNetworkListDHCPHostMappings,
+    .networkAddDHCPHostMapping = remoteNetworkAddDHCPHostMapping,
+    .networkDeleteDHCPHostMapping = remoteNetworkDeleteDHCPHostMapping,
 };
 
 static virStorageDriver storage_driver = {
Index: qemud/remote.c
===================================================================
RCS file: /data/cvs/libvirt/qemud/remote.c,v
retrieving revision 1.23
diff -u -r1.23 remote.c
--- qemud/remote.c	20 Feb 2008 16:54:36 -0000	1.23
+++ qemud/remote.c	21 Feb 2008 20:44:11 -0000
@@ -2058,6 +2058,143 @@
 
 
 static int
+remoteDispatchNetworkNumOfDhcpHostMappings (struct qemud_server *server ATTRIBUTE_UNUSED,
+                                            struct qemud_client *client,
+                                            remote_message_header *req,
+                                            remote_network_num_of_dhcp_host_mappings_args *args,
+                                            remote_network_num_of_dhcp_host_mappings_ret *ret)
+{
+    virNetworkPtr net;
+    CHECK_CONN(client);
+
+    net = get_nonnull_network (client->conn, args->net);
+    if (net == NULL) {
+        remoteDispatchError (client, req, "network not found");
+        return -2;
+    }
+
+    ret->num = virNetworkNumOfDHCPHostMappings (net);
+    if (ret->num == -1) {
+        virNetworkFree (net);
+        return -1;
+    }
+
+    virNetworkFree (net);
+    return 0;
+}
+
+
+static int
+remoteDispatchNetworkListDhcpHostMappings (struct qemud_server *server ATTRIBUTE_UNUSED,
+                                           struct qemud_client *client,
+                                           remote_message_header *req,
+                                           remote_network_list_dhcp_host_mappings_args *args,
+                                           remote_network_list_dhcp_host_mappings_ret *ret)
+{
+    virNetworkPtr net;
+    virNetworkDHCPHostMappingPtr *mappings;
+    int nr_mappings, i;
+    CHECK_CONN(client);
+
+    net = get_nonnull_network (client->conn, args->net);
+    if (net == NULL) {
+        remoteDispatchError (client, req, "network not found");
+        return -2;
+    }
+
+    if (args->maxmappings > REMOTE_NETWORK_DHCP_HOST_MAPPINGS_LIST_MAX) {
+        remoteDispatchError (client, req,
+                             "maxmappings > REMOTE_NETWORK_DHCP_HOST_MAPPINGS_LIST_MAX");
+        return -2;
+    }
+
+    mappings = malloc (args->maxmappings * sizeof (virNetworkDHCPHostMappingPtr));
+
+    nr_mappings = virNetworkListDHCPHostMappings (net,
+                                                  mappings, args->maxmappings);
+    if (nr_mappings == -1) {
+        virNetworkFree(net);
+        free (mappings);
+        return -1;
+    }
+
+    ret->mappings.mappings_len = nr_mappings;
+    ret->mappings.mappings_val =
+        calloc (nr_mappings, sizeof (*(ret->mappings.mappings_val)));
+    for (i = 0; i < nr_mappings; ++i) {
+        ret->mappings.mappings_val[i].hwaddr = mappings[i]->hwaddr;
+        ret->mappings.mappings_val[i].ipaddr = mappings[i]->ipaddr;
+        ret->mappings.mappings_val[i].hostname =
+            mappings[i]->hostname == NULL ? NULL : &mappings[i]->hostname;
+    }
+
+    free (mappings); /* NB: Just free the array, caller frees the rest. */
+
+    virNetworkFree(net);
+    return 0;
+}
+
+
+static int
+remoteDispatchNetworkAddDhcpHostMapping (struct qemud_server *server ATTRIBUTE_UNUSED,
+                                         struct qemud_client *client,
+                                         remote_message_header *req,
+                                         remote_network_add_dhcp_host_mapping_args *args,
+                                         void *ret ATTRIBUTE_UNUSED)
+{
+    virNetworkPtr net;
+    char *hwaddr, *ipaddr, *hostname;
+    CHECK_CONN(client);
+
+    net = get_nonnull_network (client->conn, args->net);
+    if (net == NULL) {
+        remoteDispatchError (client, req, "network not found");
+        return -2;
+    }
+
+    hwaddr = args->hwaddr;
+    ipaddr = args->ipaddr;
+    hostname = *args->hostname == NULL ? NULL : *args->hostname;
+
+    if (virNetworkAddDHCPHostMapping (net, hwaddr, ipaddr, hostname, args->flags) == -1) {
+        virNetworkFree (net);
+        return -1;
+    }
+
+    virNetworkFree (net);
+    return 0;
+}
+
+static int
+remoteDispatchNetworkDeleteDhcpHostMapping (struct qemud_server *server ATTRIBUTE_UNUSED,
+                                            struct qemud_client *client,
+                                            remote_message_header *req,
+                                            remote_network_delete_dhcp_host_mapping_args *args,
+                                            void *ret ATTRIBUTE_UNUSED)
+{
+    virNetworkPtr net;
+    char *hwaddr;
+    CHECK_CONN(client);
+
+    net = get_nonnull_network (client->conn, args->net);
+    if (net == NULL) {
+        remoteDispatchError (client, req, "network not found");
+        return -2;
+    }
+
+    hwaddr = args->hwaddr;
+
+    if (virNetworkDeleteDHCPHostMapping (net, hwaddr) == -1) {
+        virNetworkFree (net);
+        return -1;
+    }
+
+    virNetworkFree (net);
+    return 0;
+}
+
+
+static int
 remoteDispatchAuthList (struct qemud_server *server ATTRIBUTE_UNUSED,
                         struct qemud_client *client,
                         remote_message_header *req ATTRIBUTE_UNUSED,
Index: qemud/remote_protocol.x
===================================================================
RCS file: /data/cvs/libvirt/qemud/remote_protocol.x,v
retrieving revision 1.10
diff -u -r1.10 remote_protocol.x
--- qemud/remote_protocol.x	20 Feb 2008 15:22:35 -0000	1.10
+++ qemud/remote_protocol.x	21 Feb 2008 20:44:11 -0000
@@ -78,6 +78,9 @@
 /* Upper limit on lists of network names. */
 const REMOTE_NETWORK_NAME_LIST_MAX = 256;
 
+/* Upper limit on lists of DHCP host mappings. */
+const REMOTE_NETWORK_DHCP_HOST_MAPPINGS_LIST_MAX = 256;
+
 /* Upper limit on lists of storage pool names. */
 const REMOTE_STORAGE_POOL_NAME_LIST_MAX = 256;
 
@@ -109,6 +112,13 @@
     remote_uuid uuid;
 };
 
+/* A DHCP host mapping which may not be NULL. */
+struct remote_nonnull_dhcp_host_mapping {
+    remote_nonnull_string hwaddr;
+    remote_nonnull_string ipaddr;
+    remote_string hostname;
+};
+
 /* A storage pool which may not be NULL. */
 struct remote_nonnull_storage_pool {
     remote_nonnull_string name;
@@ -647,6 +657,35 @@
     int autostart;
 };
 
+struct remote_network_num_of_dhcp_host_mappings_args {
+    remote_nonnull_network net;
+};
+
+struct remote_network_num_of_dhcp_host_mappings_ret {
+    int num;
+};
+
+struct remote_network_list_dhcp_host_mappings_args {
+    remote_nonnull_network net;
+    int maxmappings;
+};
+
+struct remote_network_list_dhcp_host_mappings_ret {
+    remote_nonnull_dhcp_host_mapping mappings<REMOTE_NETWORK_DHCP_HOST_MAPPINGS_LIST_MAX>;
+};
+
+struct remote_network_add_dhcp_host_mapping_args {
+    remote_nonnull_network net;
+    remote_nonnull_string hwaddr;
+    remote_nonnull_string ipaddr;
+    remote_string hostname;
+    int flags;
+};
+
+struct remote_network_delete_dhcp_host_mapping_args {
+    remote_nonnull_network net;
+    remote_nonnull_string hwaddr;
+};
 
 struct remote_auth_list_ret {
     remote_auth_type types<REMOTE_AUTH_TYPE_LIST_MAX>;
@@ -1017,7 +1056,12 @@
     REMOTE_PROC_STORAGE_VOL_LOOKUP_BY_PATH = 97,
     REMOTE_PROC_STORAGE_VOL_GET_INFO = 98,
     REMOTE_PROC_STORAGE_VOL_DUMP_XML = 99,
-    REMOTE_PROC_STORAGE_VOL_GET_PATH = 100
+    REMOTE_PROC_STORAGE_VOL_GET_PATH = 100,
+
+    REMOTE_PROC_NETWORK_ADD_DHCP_HOST_MAPPING = 101,
+    REMOTE_PROC_NETWORK_DELETE_DHCP_HOST_MAPPING = 102,
+    REMOTE_PROC_NETWORK_LIST_DHCP_HOST_MAPPINGS = 103,
+    REMOTE_PROC_NETWORK_NUM_OF_DHCP_HOST_MAPPINGS = 104
 };
 
 /* Custom RPC structure. */

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