[libvirt] [PATCH 23/49] list: Implement listAllNetworks for network driver

Laine Stump laine at laine.org
Mon Jul 23 21:12:01 UTC 2012


On 07/20/2012 10:25 AM, Osier Yang wrote:
> src/network/bridge_driver.c: Implement listAllNetworks.
> ---
>  src/network/bridge_driver.c |   18 ++++++++++++++++++
>  1 files changed, 18 insertions(+), 0 deletions(-)
>
> diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c
> index bb2a765..6a3ed3f 100644
> --- a/src/network/bridge_driver.c
> +++ b/src/network/bridge_driver.c
> @@ -47,6 +47,7 @@
>  #include "datatypes.h"
>  #include "bridge_driver.h"
>  #include "network_conf.h"
> +#include "virobjectlist.h"
>  #include "driver.h"
>  #include "buf.h"
>  #include "virpidfile.h"
> @@ -2201,6 +2202,22 @@ static int networkListDefinedNetworks(virConnectPtr conn, char **const names, in
>      return -1;
>  }
>  
> +static int
> +networkListAllNetworks(virConnectPtr conn,
> +                       virNetworkPtr **nets,
> +                       unsigned int flags)
> +{
> +    struct network_driver *driver = conn->networkPrivateData;
> +    int ret = -1;
> +
> +    virCheckFlags(VIR_CONNECT_LIST_NETWORKS_FILTERS_ALL, -1);

If you return with an error here, nets will be unset. Even though a
*sane* caller would check the return value prior to dereferencing
anything in nets, it would still be a good idea to to "*nets = NULL"
before anything else.

Otherwise, ACK.

> +
> +    networkDriverLock(driver);
> +    ret = virNetworkList(conn, driver->networks, nets, flags);
> +    networkDriverUnlock(driver);
> +
> +    return ret;
> +}
>  
>  static int networkIsActive(virNetworkPtr net)
>  {
> @@ -2689,6 +2706,7 @@ static virNetworkDriver networkDriver = {
>      .listNetworks = networkListNetworks, /* 0.2.0 */
>      .numOfDefinedNetworks = networkNumDefinedNetworks, /* 0.2.0 */
>      .listDefinedNetworks = networkListDefinedNetworks, /* 0.2.0 */
> +    .listAllNetworks = networkListAllNetworks, /* 0.9.14 */
>      .networkLookupByUUID = networkLookupByUUID, /* 0.2.0 */
>      .networkLookupByName = networkLookupByName, /* 0.2.0 */
>      .networkCreateXML = networkCreate, /* 0.2.0 */




More information about the libvir-list mailing list