[libvirt] virsh "net-create" explanation

Hi all, I am new to libvirt and started looking at the source code. While tracing back the virsh command "net-create", I got stuck into a loop and I would really like someone to explain how this works. In the virsh-network.c, from: network = virNetworkCreateXML(ctl->conn, buffer); I traced back to: if (conn->networkDriver && conn->networkDriver->networkCreateXML) { virNetworkPtr ret; ret = conn->networkDriver->networkCreateXML(conn, xmlDesc); Then I traced back to the following struct to find how networkCreateXML is working: struct _virNetworkDriver { const char * name; /* the name of the driver */ virDrvOpen open; virDrvClose close; virDrvNumOfNetworks numOfNetworks; virDrvListNetworks listNetworks; virDrvNumOfDefinedNetworks numOfDefinedNetworks; virDrvListDefinedNetworks listDefinedNetworks; virDrvListAllNetworks listAllNetworks; virDrvNetworkLookupByUUID networkLookupByUUID; virDrvNetworkLookupByName networkLookupByName; virDrvNetworkCreateXML networkCreateXML;
From the above code, I located the definition of virDrvNetworkCreateXML and found the following:
typedef virNetworkPtr (*virDrvNetworkCreateXML) (virConnectPtr conn, const char *xmlDesc); This is where I am unable to trace back to any other code. Can someone please explain the code with typedef above and where is the definition of the function this function pointer is pointing to? I want to get to the root of the networkCreateXML function and how it exactly works. Can someone please explain? Thanks a lot, Bilal

On 2012年12月26日 23:36, Bilal Ahmad wrote:
Hi all,
I am new to libvirt and started looking at the source code. While tracing back the virsh command "net-create", I got stuck into a loop and I would really like someone to explain how this works.
In the virsh-network.c, from:
network = virNetworkCreateXML(ctl->conn, buffer);
I traced back to:
if (conn->networkDriver && conn->networkDriver->networkCreateXML) { virNetworkPtr ret; ret = conn->networkDriver->networkCreateXML(conn, xmlDesc);
Then I traced back to the following struct to find how networkCreateXML is working:
struct _virNetworkDriver { const char * name; /* the name of the driver */ virDrvOpen open; virDrvClose close; virDrvNumOfNetworks numOfNetworks; virDrvListNetworks listNetworks; virDrvNumOfDefinedNetworks numOfDefinedNetworks; virDrvListDefinedNetworks listDefinedNetworks; virDrvListAllNetworks listAllNetworks; virDrvNetworkLookupByUUID networkLookupByUUID; virDrvNetworkLookupByName networkLookupByName; virDrvNetworkCreateXML networkCreateXML;
From the above code, I located the definition of virDrvNetworkCreateXML and found the following:
typedef virNetworkPtr (*virDrvNetworkCreateXML) (virConnectPtr conn, const char *xmlDesc); This is where I am unable to trace back to any other code. Can someone please explain the code with typedef above and where is the definition of the function this function pointer is pointing to? I want to get to the root of the networkCreateXML function and how it exactly works. Can someone please explain?
It's implemented in network driver (src/network/bridge_driver.*). Similar for other drivers.
Thanks a lot, Bilal
-- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list

On 26.12.2012 16:36, Bilal Ahmad wrote:
Hi all,
I am new to libvirt and started looking at the source code. While tracing back the virsh command "net-create", I got stuck into a loop and I would really like someone to explain how this works.
In the virsh-network.c, from:
network = virNetworkCreateXML(ctl->conn, buffer);
I traced back to:
if (conn->networkDriver && conn->networkDriver->networkCreateXML) { virNetworkPtr ret; ret = conn->networkDriver->networkCreateXML(conn, xmlDesc);
Some hypervisors manage networks on their own (e.g. VBox) while others rely on our bridge driver. Since we've switched to C99 struct initialization, you can simply grep for networkCreateXML: $ git grep networkCreateXML and you'll see which functions implements the functionality: [...] src/network/bridge_driver.c: .networkCreateXML = networkCreate, /* 0.2.0 */ src/remote/remote_driver.c: .networkCreateXML = remoteNetworkCreateXML, /* 0.3.0 */ src/test/test_driver.c: .networkCreateXML = testNetworkCreate, /* 0.3.2 */ src/vbox/vbox_tmpl.c: .networkCreateXML = vboxNetworkCreateXML, /* 0.6.4 */ And now you can look deeper into networkCreate(), testNetworkCreate() or vboxNetworkCreateXML(). You can repeat the process with other driver methods and drivers as well. Michal
participants (3)
-
Bilal Ahmad
-
Michal Privoznik
-
Osier Yang