δΊ 2011-12-24 4:01, Chip Vincent ει:
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.
OK. A pure C project which would include only the function code and C
testing cases was sent before. Running that would be easy to view what
it does.
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(a)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(a)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?
Sorry I did not catch your idea. Do you mean that this file should
be merged to another 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.
There is a member in struct iface recording the active state, so
this function would retrieve all ifaces information.
> +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.
What I intended to do is that errno was returned when CIM model
code call the "API" functions, and CIM model code could use the errno
to call this function to get a string, which was used to tell the user
like wbemcli what was happening. Do you mean that this details should
be hidden inside libvirt-cim?
> 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(a)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
--
Best Regards
Wayne Xia
mail:xiawenc@linux.vnet.ibm.com
tel:86-010-82450803