[Libvirt-cim] [PATCH 12/15] vlan extension - function lib - add the API

Chip Vincent cvincent at linux.vnet.ibm.com
Fri Dec 23 20:01:14 UTC 2011


Just a thought: I would expect the ordering of the patches to be library 
(libxkutil) files first, followed by the providers and schema. That's because 
you have to review the library code to be able to make sense of the providers, etc.

On 12/07/2011 04:25 AM, Wayne Xia wrote:
> this is the API layer let the libvirt-cim call.
>
> Signed-off-by: Wayne Xia<xiawenc at linux.vnet.ibm.com>
> ---
>   libxkutil/host_network_API.c |  150 ++++++++++++++++++++++++++++++++++++++++++
>   libxkutil/host_network_API.h |   32 +++++++++
>   2 files changed, 182 insertions(+), 0 deletions(-)
>   create mode 100644 libxkutil/host_network_API.c
>   create mode 100644 libxkutil/host_network_API.h
>
> diff --git a/libxkutil/host_network_API.c b/libxkutil/host_network_API.c
> new file mode 100644
> index 0000000..89a9879
> --- /dev/null
> +++ b/libxkutil/host_network_API.c
> @@ -0,0 +1,150 @@
> +/*
> + * Copyright IBM Corp. 2011
> + *
> + * Authors:
> + *  Wenchao Xia<xiawenc at cn.ibm.com>
> + *
> + * This library is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU Lesser General Public
> + * License as published by the Free Software Foundation; either
> + * version 2.1 of the License, or (at your option) any later version.
> + */
> +
> +
> +#include "host_network_API.h"
> +#include "host_network_implement_cmdline.h"
> +#include "host_network_error.h"

Is there a good reason we can combine some of this into a network_device and/or 
host_network files?
> +
> +/* this layer is added to devide the abstraction and implemention, so that
> +   different implemention could be used and switched */
> +
> +int get_host_ifaces(EthIfacesList *plist,
> +                        eth_iface_filter_func filter_func, void *filter_opaque)
> +{
> +    return get_host_eth_ifaces_cmd_all(plist, filter_func, filter_opaque);
> +}
> +
Question: Is there any checking to ensure the iface is active? How do we handle 
inactive ifaces? Ignore if this is presented elsewhere. I'm working backwards 
through the code.
> +int add_host_iface(EthIface *piface, int persist_flag)
> +{
> +    int ret = 0;
> +    if (piface->eth_type == ETH_TYPE_BRIDGE) {
> +        ret = add_host_br_cmd(piface, persist_flag);
> +    } else if (piface->eth_type == ETH_TYPE_VLAN) {
> +
> +        if (piface->pvlan_prop == NULL) {
> +            CU_DEBUG("requested an unsupported operation.");
> +            ret = ERR_REQUEST_NOT_SUPPORT;
> +        } else {
> +            if (piface->pvlan_prop->vlan_type == VLAN_TYPE_802_1_Q) {
> +                ret = add_host_vlan_8021q_cmd(piface, persist_flag);
> +            } else {
> +                CU_DEBUG("requested an unsupported operation.");
> +                ret = ERR_REQUEST_NOT_SUPPORT;
> +            }
> +        }
> +
> +    } else {
> +        CU_DEBUG("requested an unsupported operation.");
> +        ret = ERR_REQUEST_NOT_SUPPORT;
> +    }
> +
> +    return ret;
> +}
> +
> +int del_host_iface(EthIface *piface, int persist_flag)
> +{
> +    int ret = 0;
> +    if (piface->eth_type == ETH_TYPE_BRIDGE) {
> +        ret = del_host_br_cmd(piface, persist_flag);
> +    } else if (piface->eth_type == ETH_TYPE_VLAN) {
> +
> +        if (piface->pvlan_prop == NULL) {
> +            CU_DEBUG("requested an unsupported operation.");
> +            ret = ERR_REQUEST_NOT_SUPPORT;
> +        } else {
> +            if (piface->pvlan_prop->vlan_type == VLAN_TYPE_802_1_Q) {
> +                ret = del_host_vlan_8021q_cmd(piface, persist_flag);
> +            } else {
> +                CU_DEBUG("requested an unsupported operation.");
> +                ret = ERR_REQUEST_NOT_SUPPORT;
> +            }
> +        }
> +
> +    } else {
> +        CU_DEBUG("requested an unsupported operation.");
> +        ret = ERR_REQUEST_NOT_SUPPORT;
> +    }
> +
> +    return ret;
> +}
It appears we can never delete a physical NIC. Good.
> +
> +int mod_host_iface(EthIface *piface, int persist_flag)
> +{
> +    int ret = 0;
> +    if (piface->eth_type == ETH_TYPE_BRIDGE) {
> +        ret = mod_host_br_cmd(piface, persist_flag);
> +    } else if (piface->eth_type == ETH_TYPE_VLAN) {
> +
> +        if (piface->pvlan_prop == NULL) {
> +            CU_DEBUG("requested an unsupported operation.");
> +            ret = ERR_REQUEST_NOT_SUPPORT;
> +        } else {
> +            if (piface->pvlan_prop->vlan_type == VLAN_TYPE_802_1_Q) {
> +                ret = mod_host_vlan_8021q_cmd(piface, persist_flag);
> +            } else {
> +                CU_DEBUG("requested an unsupported operation.");
> +                ret = ERR_REQUEST_NOT_SUPPORT;
> +            }
> +        }
> +
> +    } else {
> +        CU_DEBUG("requested an unsupported operation.");
> +        ret = ERR_REQUEST_NOT_SUPPORT;
> +    }
> +
> +    return ret;
> +}
> +
> +int change_state_host_iface(EthIface *piface, int state)
> +{
> +    return change_state_host_iface_cmd(piface, state);
> +}
> +
> +int connect_two_ifaces(EthIface *p1, EthIface *p2, int persist_flag)
> +{
> +    if ((p1 == NULL) || (p2 == NULL)) {
> +        return 0;
> +    }
> +    if ((p1->eth_type == ETH_TYPE_BRIDGE)&&
> +                                (p2->eth_type != ETH_TYPE_BRIDGE)) {
> +        return add_host_iface_to_br_cmd(p2, p1, persist_flag);
> +    } else if ((p1->eth_type != ETH_TYPE_BRIDGE)&&
> +                                (p2->eth_type == ETH_TYPE_BRIDGE)) {
> +        return add_host_iface_to_br_cmd(p1, p2, persist_flag);
> +    } else {
> +        CU_DEBUG("requested an unsupported operation.");
> +        return ERR_REQUEST_NOT_SUPPORT;
> +    }
> +}
> +
> +int disconnect_two_ifaces(EthIface *p1, EthIface *p2, int persist_flag)
> +{
> +    if ((p1 == NULL) || (p2 == NULL)) {
> +        return 0;
> +    }
> +    if ((p1->eth_type == ETH_TYPE_BRIDGE)&&
> +                                (p2->eth_type != ETH_TYPE_BRIDGE)) {
> +        return remove_host_iface_from_br_cmd(p2, p1, persist_flag);
> +    } else if ((p1->eth_type != ETH_TYPE_BRIDGE)&&
> +                                (p2->eth_type == ETH_TYPE_BRIDGE)) {
> +        return remove_host_iface_from_br_cmd(p1, p2, persist_flag);
> +    } else {
> +        CU_DEBUG("requested an unsupported operation.");
> +        return ERR_REQUEST_NOT_SUPPORT;
> +    }
> +}
> +
> +char *get_host_iface_error_reason(int errno)
> +{
> +    return translate_error_no(errno);
> +}
I would expect the errno checks would be abstracted. That is, they would be 
checked after the relevant syscalls and be translated into internal error codes 
and returned by our wrapper functions.

> diff --git a/libxkutil/host_network_API.h b/libxkutil/host_network_API.h
> new file mode 100644
> index 0000000..b821d58
> --- /dev/null
> +++ b/libxkutil/host_network_API.h
> @@ -0,0 +1,32 @@
> +/*
> + * Copyright IBM Corp. 2011
> + *
> + * Authors:
> + *  Wenchao Xia<xiawenc at cn.ibm.com>
> + *
> + * This library is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU Lesser General Public
> + * License as published by the Free Software Foundation; either
> + * version 2.1 of the License, or (at your option) any later version.
> + */
> +
> +#ifndef HOST_NETWORK_API
> +#define HOST_NETWORK_API
> +
> +#include "host_network_basic.h"
> +#include "host_network_helper.h"
> +
> +int get_host_ifaces(EthIfacesList *plist,
> +                        eth_iface_filter_func filter_func, void *filter_opaque);
> +
> +int add_host_iface(EthIface *piface, int persist_flag);
> +int del_host_iface(EthIface *piface, int persist_flag);
> +int mod_host_iface(EthIface *piface, int persist_flag);
> +int change_state_host_iface(EthIface *piface, int state);
> +
> +int connect_two_ifaces(EthIface *p1, EthIface *p2, int persist_flag);
> +int disconnect_two_ifaces(EthIface *p1, EthIface *p2, int persist_flag);
> +
> +char *get_host_iface_error_reason(int errno);
> +
> +#endif


-- 
Chip Vincent
Open Virtualization
IBM Linux Technology Center
cvincent at linux.vnet.ibm.com




More information about the Libvirt-cim mailing list