[libvirt] RFC: Introduce API to return configuration/state paths of the network driver

Nehal J. Wani nehaljw.kkd1 at gmail.com
Thu Jul 25 08:32:36 UTC 2013


Currently, there is no API which returns configuration/state paths of the
network driver.
Although it is a private implementation of the network driver, I don't see
any harm in
making the locations public because although the locations might change,
there will always
be a location for these files. There is a need for this API to implement
method 2 of the
"API to query ip addresses of a given domain", refer:
http://www.mail-archive.com/libvir-list@redhat.com/msg79793.html . It is
required to parse
the leases file generated by dnsmasq. So, this API will be used by the qemu
driver, but it
can also be made public, so that, if a user wants to know get some
information from a
configuration file, he can get the location from libvirt and analyze it on
his own. Right now,
there is an alternate way to get the info: by using
networkDnsmasqLeaseFileNameDefault,
defined in /src/network/bridge_driver.c Since this function is static, it
is part of the private
implementation and not visible outside. To make it public, the following
hack is possible:

diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c
index a7ff602..7274861 100644
--- a/src/network/bridge_driver.c
+++ b/src/network/bridge_driver.c
@@ -124,7 +124,7 @@ static int networkUnplugBandwidth(virNetworkObjPtr net,

 static struct network_driver *driverState = NULL;

-static char *
+char *
 networkDnsmasqLeaseFileNameDefault(const char *netname)
 {
     char *leasefile;
diff --git a/src/network/bridge_driver.h b/src/network/bridge_driver.h
index 50258b5..40e3990 100644
--- a/src/network/bridge_driver.h
+++ b/src/network/bridge_driver.h
@@ -49,6 +49,8 @@ int networkDnsmasqConfContents(virNetworkObjPtr network,
                         char **configstr,
                         dnsmasqContext *dctx,
                         dnsmasqCapsPtr caps);
+char * networkDnsmasqLeaseFileNameDefault(const char *netname)
+    ATTRIBUTE_NONNULL(1);
 # else
 /* Define no-op replacements that don't drag in any link dependencies.  */
 #  define networkAllocateActualDevice(iface) 0
@@ -57,6 +59,7 @@ int networkDnsmasqConfContents(virNetworkObjPtr network,
 #  define networkGetNetworkAddress(netname, netaddr) (-2)
 #  define networkDnsmasqConfContents(network, pidfile, configstr, \
                     dctx, caps) 0
+#  define networkDnsmasqLeaseFileNameDefault(netname) 0
 # endif

 typedef char *(*networkDnsmasqLeaseFileNameFunc)(const char *netname);

Similar hack has been used so that networkAllocateActualDevice() can be
called
from qemu_command.c. Although the above method works, we want to have a
formal API and not leave things like a hack.

/*
 * @conn: connection object
 * @params: array to populate on output
 * @nparams: number of parameters that will be filled
 * @flags: not supported, user should pass 0 for now
 * return 0 on success -1 otherwise
 * Valid parameter field names:
 * VIR_NETWORK_CONFIG_DIR, VIR_NETWORK_AUTOSTART_DIR, VIR_STATE_DIR,
 * VIR_PID_DIR, VIR_DNSMASQ_STATE_DIR, VIR_RADVD_STATE_DIR
 * All the above will of the type VIR_TYPED_PARAM_STRING
 */
int virNetworkGetConfigFileName(virConnectPtr conn,
                                virTypedParameterPtr params,
                                int nparams,
                                unsigned int flags)


Nehal J. Wani
UG3, BTech CS+MS(CL)
IIIT-Hyderabad
http://commandlinewani.blogspot.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20130725/c38fe789/attachment-0001.htm>


More information about the libvir-list mailing list