[PATCH] Fix up style issues in device_parsing.c
by Dan Smith
# HG changeset patch
# User Dan Smith <danms(a)us.ibm.com>
# Date 1199483177 28800
# Node ID 533fee39dd71883c5effeed14a88a9146a15524d
# Parent ea65740aa1ffe73b47a4a14c8a853dbb3f040016
Fix up style issues in device_parsing.c
Lots of whitespace issues were corrected as well. Any lines that look
untouched are trailing whitespace fixes.
Changed non-error "err" labels to "out".
Lots of other stuff.
Signed-off-by: Dan Smith <danms(a)us.ibm.com>
diff -r ea65740aa1ff -r 533fee39dd71 libxkutil/device_parsing.c
--- a/libxkutil/device_parsing.c Fri Jan 04 12:53:44 2008 -0800
+++ b/libxkutil/device_parsing.c Fri Jan 04 13:46:17 2008 -0800
@@ -42,6 +42,8 @@
#define DEFAULT_BRIDGE "xenbr0"
+#define XSTREQ(x, y) (STREQ((char *)x, y))
+
static void cleanup_disk_device(struct disk_device *dev)
{
free(dev->type);
@@ -100,7 +102,7 @@ void cleanup_virt_devices(struct virt_de
*_devs = NULL;
}
-static char * get_attr_value(xmlNode *node, char *attrname)
+static char *get_attr_value(xmlNode *node, char *attrname)
{
char *buf = NULL;
char *ret = NULL;
@@ -110,6 +112,7 @@ static char * get_attr_value(xmlNode *no
ret = strdup(buf);
xmlFree(buf);
}
+
return ret;
}
@@ -127,9 +130,13 @@ static char *get_node_content(xmlNode *n
return buf;
}
-static int parse_disk_device(xmlNode *dnode, struct virt_device *vdev)
+static bool parse_disk_device(xmlNode *dnode, struct virt_device *vdev)
{
struct disk_device *ddev = &(vdev->dev.disk);
+ xmlNode * child = NULL;
+
+ memset(ddev, 0, sizeof(*ddev));
+
ddev->type = get_attr_value(dnode, "type");
if (!ddev->type)
goto err;
@@ -137,18 +144,13 @@ static int parse_disk_device(xmlNode *dn
ddev->device = get_attr_value(dnode, "device");
if (!ddev->device)
goto err;
-
- xmlNode * child = NULL;
- ddev->driver = NULL;
- ddev->source = NULL;
- ddev->virtual_dev = NULL;
- for (child = dnode->children; child != NULL;
- child = child->next) {
- if (STREQ((char*)child->name, "driver")) {
+
+ for (child = dnode->children; child != NULL; child = child->next) {
+ if (XSTREQ(child->name, "driver")) {
ddev->driver = get_attr_value(child, "name");
if (!ddev->driver)
goto err;
- } else if (STREQ((char*)child->name, "source")) {
+ } else if (XSTREQ(child->name, "source")) {
ddev->source = get_attr_value(child, "file");
if (ddev->source) {
ddev->disk_type = DISK_FILE;
@@ -160,131 +162,152 @@ static int parse_disk_device(xmlNode *dn
continue;
}
goto err;
- } else if (STREQ((char*)child->name, "target")) {
+ } else if (XSTREQ(child->name, "target")) {
ddev->virtual_dev = get_attr_value(child, "dev");
if (!ddev->virtual_dev)
goto err;
}
}
- if (! (ddev->source && ddev->virtual_dev))
+ if (! (ddev->source && ddev->virtual_dev))
goto err;
+
vdev->type = VIRT_DEV_DISK;
vdev->id = strdup(ddev->virtual_dev);
- return 1;
+ return true;
err:
cleanup_disk_device(ddev);
- return 0;
-}
-
-static int parse_net_device(xmlNode *inode, struct virt_device *vdev)
+ return false;
+}
+
+static bool parse_net_device(xmlNode *inode, struct virt_device *vdev)
{
struct net_device *ndev = &(vdev->dev.net);
+ xmlNode *child = NULL;
+
+ memset(ndev, 0, sizeof(*ndev));
+
ndev->type = get_attr_value(inode, "type");
if (!ndev->type)
goto err;
- xmlNode *child = NULL;
- ndev->mac = NULL;
- ndev->bridge = NULL;
- for (child = inode->children; child != NULL;
- child = child->next) {
- if (STREQ((char *)child->name, "mac")) {
+ for (child = inode->children; child != NULL; child = child->next) {
+ if (XSTREQ(child->name, "mac")) {
ndev->mac = get_attr_value(child, "address");
if (!ndev->mac)
goto err;
- } else if (STREQ((char *)child->name, "source")) {
+ } else if (XSTREQ(child->name, "source")) {
ndev->bridge = get_attr_value(child, "bridge");
if (!ndev->bridge)
goto err;
}
}
+
if (!ndev->mac)
goto err;
+
if (!ndev->bridge) {
ndev->bridge = strdup(DEFAULT_BRIDGE);
printf("No bridge, taking default of `%s'\n", ndev->bridge);
}
+
vdev->type = VIRT_DEV_NET;
vdev->id = strdup(ndev->mac);
- return 1;
+ return true;
err:
cleanup_net_device(ndev);
-
- return 0;
-}
-
-static int parse_emu_device(xmlNode *node, struct virt_device *vdev)
+
+ return false;
+}
+
+static bool parse_emu_device(xmlNode *node, struct virt_device *vdev)
{
struct emu_device *edev = &(vdev->dev.emu);
edev->path = get_node_content(node);
+ if (edev->path != NULL)
+ goto err;
vdev->type = VIRT_DEV_EMU;
- return 1;
-}
-
-static int parse_graphics_device(xmlNode *node, struct virt_device *vdev)
+ return true;
+ err:
+ cleanup_emu_device(edev);
+
+ return false;
+}
+
+static bool parse_graphics_device(xmlNode *node, struct virt_device *vdev)
{
struct graphics_device *gdev = &(vdev->dev.graphics);
gdev->type = get_attr_value(node, "type");
gdev->port = get_attr_value(node, "port");
+ if ((gdev->type == NULL) || (gdev->port == NULL))
+ goto err;
+
vdev->type = VIRT_DEV_GRAPHICS;
- return 1;
+ return true;
+ err:
+ cleanup_graphics_device(gdev);
+
+ return false;
}
static int do_parse(xmlNodeSet *nsv, int type, struct virt_device **l)
{
- int i = 0;
- int j = 0;
+ int devidx;
+ int lstidx;
int count = 0;
struct virt_device *list = NULL;
xmlNode **dev_nodes = NULL;
- int (*do_real_parse)(xmlNode *, struct virt_device *) = NULL;
-
+ bool (*do_real_parse)(xmlNode *, struct virt_device *) = NULL;
+
/* point to correct parser function according to type */
- if (type == VIRT_DEV_NET)
- do_real_parse = &parse_net_device;
- else if (type == VIRT_DEV_DISK)
- do_real_parse = &parse_disk_device;
+ if (type == VIRT_DEV_NET)
+ do_real_parse = &parse_net_device;
+ else if (type == VIRT_DEV_DISK)
+ do_real_parse = &parse_disk_device;
else if (type == VIRT_DEV_EMU)
do_real_parse = parse_emu_device;
else if (type == VIRT_DEV_GRAPHICS)
do_real_parse = parse_graphics_device;
else
- goto err;
+ goto out;
if (!nsv)
- goto err;
+ goto out;
+
dev_nodes = nsv->nodeTab;
count = nsv ? nsv->nodeNr : 0;
-
- if (count > 0) {
- list = (struct virt_device *)malloc(
- count * sizeof(struct virt_device));
- if (!list) {
- count = 0;
- goto err;
- }
- /* walk thru the array, do real parsing on each node */
- while (i <= count-1) {
- if (do_real_parse(dev_nodes[i], &list[j]))
- j++;
- i++;
- }
- if (j < i) {
- list = realloc(list, j * sizeof(struct virt_device));
- count = j;
- }
- }
- err:
+
+ if (count <= 0)
+ goto out;
+
+ list = (struct virt_device *)malloc(count * sizeof(struct virt_device));
+ if (!list) {
+ count = 0;
+ goto out;
+ }
+
+ /* walk thru the array, do real parsing on each node */
+ lstidx = 0;
+ for (devidx = 0; devidx < count; devidx++) {
+ if (do_real_parse(dev_nodes[devidx], &list[lstidx]))
+ lstidx++;
+ }
+
+ if (lstidx < devidx) {
+ list = realloc(list, lstidx * sizeof(struct virt_device));
+ count = lstidx;
+ }
+
+ out:
*l = list;
return count;
}
@@ -297,13 +320,13 @@ static void swallow_err_msg(void *ctx, c
static int parse_devices(char *xml, struct virt_device **_list, int type)
{
- int i = 0;
+ int len = 0;
int count = 0;
xmlDoc *xmldoc;
xmlXPathContext *xpathCtx;
xmlXPathObject *xpathObj;
- xmlChar *xpathstr;
+ xmlChar *xpathstr;
if (type == VIRT_DEV_NET)
xpathstr = NET_XPATH;
@@ -315,22 +338,22 @@ static int parse_devices(char *xml, stru
xpathstr = GRAPHICS_XPATH;
else
goto err1;
-
- i = strlen(xml) + 1;
+
+ len = strlen(xml) + 1;
xmlSetGenericErrorFunc(NULL, swallow_err_msg);
- if ((xmldoc = xmlParseMemory(xml, i)) == NULL)
+ if ((xmldoc = xmlParseMemory(xml, len)) == NULL)
goto err1;
if ((xpathCtx = xmlXPathNewContext(xmldoc)) == NULL)
goto err2;
-
+
if ((xpathObj = xmlXPathEvalExpression(xpathstr, xpathCtx))
== NULL)
goto err3;
count = do_parse(xpathObj->nodesetval, type, _list);
-
+
xmlSetGenericErrorFunc(NULL, NULL);
xmlXPathFreeObject(xpathObj);
err3:
@@ -372,7 +395,7 @@ struct virt_device *virt_device_dup(stru
dev->dev.vcpu.state = _dev->dev.vcpu.state;
dev->dev.vcpu.cpuTime = _dev->dev.vcpu.cpuTime;
dev->dev.vcpu.cpu = _dev->dev.vcpu.cpu;
- }
+ }
return dev;
}
@@ -384,7 +407,7 @@ static int get_emu_device(virDomainPtr d
struct virt_device *list = NULL;
xml = virDomainGetXMLDesc(dom, 0);
- if (!xml)
+ if (xml == NULL)
return 0;
ret = parse_devices(xml, &list, VIRT_DEV_EMU);
@@ -405,7 +428,7 @@ static int get_graphics_device(virDomain
struct virt_device *list = NULL;
xml = virDomainGetXMLDesc(dom, 0);
- if (!xml)
+ if (xml == NULL)
return 0;
ret = parse_devices(xml, &list, VIRT_DEV_GRAPHICS);
@@ -425,7 +448,7 @@ int get_disk_devices(virDomainPtr dom, s
int ret;
xml = virDomainGetXMLDesc(dom, 0);
- if (!xml)
+ if (xml == NULL)
return 0;
ret = parse_devices(xml, list, VIRT_DEV_DISK);
@@ -441,7 +464,7 @@ int get_net_devices(virDomainPtr dom, st
int ret;
xml = virDomainGetXMLDesc(dom, 0);
- if (!xml)
+ if (xml == NULL)
return 0;
ret = parse_devices(xml, list, VIRT_DEV_NET);
@@ -459,25 +482,25 @@ int get_mem_devices(virDomainPtr dom, st
struct virt_device *ret_list = NULL;
rc = virDomainGetInfo(dom, &dom_info);
- if (rc == -1){
+ if (rc == -1) {
ret = -1;
- goto err;
+ goto out;
}
mem_size = (uint64_t)dom_info.memory;
mem_maxsize = (uint64_t)dom_info.maxMem;
if (mem_size > mem_maxsize) {
ret = -1;
- goto err;
- }
-
+ goto out;
+ }
+
ret_list = malloc(sizeof(struct virt_device));
if (!ret_list) {
ret = -1;
free (ret_list);
- goto err;
- }
-
+ goto out;
+ }
+
ret_list->type = VIRT_DEV_MEM;
ret_list->dev.mem.size = mem_size;
ret_list->dev.mem.maxsize = mem_maxsize;
@@ -485,8 +508,7 @@ int get_mem_devices(virDomainPtr dom, st
ret = 1;
*list = ret_list;
-
- err:
+ out:
return ret;
}
@@ -500,7 +522,7 @@ int get_vcpu_devices(virDomainPtr dom, s
rc = virDomainGetInfo(dom, &dom_info);
if (rc == -1) {
ret = -1;
- goto error1;
+ goto out1;
}
num_vcpus = dom_info.nrVirtCpu;
@@ -508,7 +530,7 @@ int get_vcpu_devices(virDomainPtr dom, s
num_filled = virDomainGetVcpus(dom, vcpu_info, num_vcpus, NULL, 0);
if (num_vcpus != num_filled) {
ret = -1;
- goto error2;
+ goto out2;
}
ret_list = calloc(num_vcpus, sizeof(struct virt_device));
@@ -519,15 +541,15 @@ int get_vcpu_devices(virDomainPtr dom, s
vcpu_info[i].number) == -1) {
ret = -1;
free(ret_list);
- goto error2;
+ goto out2;
}
}
ret = num_vcpus;
*list = ret_list;
- error2:
+ out2:
free(vcpu_info);
- error1:
+ out1:
return ret;
}
@@ -537,7 +559,6 @@ char *get_fq_devid(char *host, char *_de
if (asprintf(&devid, "%s/%s", host, _devid) == -1)
return NULL;
-
else
return devid;
}
@@ -560,7 +581,6 @@ int parse_fq_devid(const char *devid, ch
return 1;
}
-#define XSTREQ(x, y) (STREQ((char *)x, y))
#define STRPROP(d, p, n) (d->p = get_node_content(n))
static int parse_os(struct domain *dominfo, xmlNode *os)
16 years, 10 months
[PATCH] Make NetworkPool use libvirt's virtual network API
by Dan Smith
# HG changeset patch
# User Dan Smith <danms(a)us.ibm.com>
# Date 1199377368 28800
# Node ID 3a838dfd165b5f721687a2bb0b2e03bb0c8192b7
# Parent 84b72fff34f65ad578d70fcc67b141510e34e24e
Make NetworkPool use libvirt's virtual network API
This means that you no longer see a NetworkPool for each bridge on the
system, but rather one per configured virtual network in libvirt. The
id is NetworkPool/NetName, and the Caption property of the instance
includes the bridge name for reference.
This change removes the need for the contents of hostres.{c,h}, so it is
removed here. That makes the net change -85 lines of pure goodness.
Changes since last version:
- Fixed netpool_member_of() to do extra level of bridge->network mapping
Signed-off-by: Dan Smith <danms(a)us.ibm.com>
diff -r 84b72fff34f6 -r 3a838dfd165b libxkutil/Makefile.am
--- a/libxkutil/Makefile.am Wed Jan 02 09:18:22 2008 -0800
+++ b/libxkutil/Makefile.am Thu Jan 03 08:22:48 2008 -0800
@@ -4,11 +4,11 @@ SUBDIRS = tests
CFLAGS += $(CFLAGS_STRICT)
-noinst_HEADERS = cs_util.h misc_util.h device_parsing.h hostres.h xmlgen.h
+noinst_HEADERS = cs_util.h misc_util.h device_parsing.h xmlgen.h
lib_LTLIBRARIES = libxkutil.la
AM_LDFLAGS = -lvirt -luuid
libxkutil_la_SOURCES = cs_util_instance.c misc_util.c device_parsing.c \
- xmlgen.c hostres.c
+ xmlgen.c
diff -r 84b72fff34f6 -r 3a838dfd165b libxkutil/hostres.c
--- a/libxkutil/hostres.c Wed Jan 02 09:18:22 2008 -0800
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,84 +0,0 @@
-/*
- * Copyright IBM Corp. 2007
- *
- * Authors:
- * Dan Smith <danms(a)us.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.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-#include <stdio.h>
-#include <stdbool.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <dirent.h>
-
-#include "hostres.h"
-
-bool is_bridge(const char *name)
-{
- char *path = NULL;
- int ret;
- struct stat s;
-
- ret = asprintf(&path, "/sys/class/net/%s/bridge", name);
- if (ret == -1)
- return false;
-
- if (stat(path, &s) != 0)
- return false;
-
- if (S_ISDIR(s.st_mode))
- return true;
- else
- return false;
-}
-
-char **list_bridges(void)
-{
- char **list = NULL;
- DIR *dir = NULL;
- struct dirent *de;
- int count = 0;
-
- dir = opendir("/sys/class/net");
- if (dir == NULL)
- return NULL;
-
- while ((de = readdir(dir))) {
- if (is_bridge(de->d_name)) {
- list = realloc(list, ++count);
- list[count-1] = strdup(de->d_name);
- }
- }
-
- /* Leave a NULL at the end, no matter what */
- list = realloc(list, count + 1);
- list[count] = NULL;
-
- return list;
-}
-
-/*
- * Local Variables:
- * mode: C
- * c-set-style: "K&R"
- * tab-width: 8
- * c-basic-offset: 8
- * indent-tabs-mode: nil
- * End:
- */
diff -r 84b72fff34f6 -r 3a838dfd165b libxkutil/hostres.h
--- a/libxkutil/hostres.h Wed Jan 02 09:18:22 2008 -0800
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,32 +0,0 @@
-/*
- * Copyright IBM Corp. 2007
- *
- * Authors:
- * Dan Smith <danms(a)us.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.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-#ifndef __HOSTRES_H
-#define __HOSTRES_H
-
-#include <stdbool.h>
-
-bool is_bridge(const char *name);
-
-/* Return a NULL-terminated array of bridge names on the system.
- Result must be free()d, as well as each of the array members */
-char **list_bridges(void);
-
-#endif
diff -r 84b72fff34f6 -r 3a838dfd165b src/Virt_DevicePool.c
--- a/src/Virt_DevicePool.c Wed Jan 02 09:18:22 2008 -0800
+++ b/src/Virt_DevicePool.c Thu Jan 03 08:22:48 2008 -0800
@@ -35,7 +35,6 @@
#include "config.h"
#include "misc_util.h"
-#include "hostres.h"
#include "device_parsing.h"
#include <libcmpiutil/libcmpiutil.h>
@@ -196,6 +195,74 @@ static char *diskpool_member_of(const CM
return pool;
}
+static virNetworkPtr bridge_to_network(virConnectPtr conn,
+ const char *bridge)
+{
+ char **networks = NULL;
+ virNetworkPtr network = NULL;
+ int num;
+ int i;
+
+ num = virConnectNumOfNetworks(conn);
+ if (num < 0)
+ return NULL;
+
+ networks = calloc(num, sizeof(*networks));
+ if (networks == NULL)
+ return NULL;
+
+ num = virConnectListNetworks(conn, networks, num);
+
+ for (i = 0; i < num; i++) {
+ char *_bridge;
+
+ network = virNetworkLookupByName(conn, networks[i]);
+ if (network == NULL)
+ continue;
+
+ _bridge = virNetworkGetBridgeName(network);
+ CU_DEBUG("Network `%s' has bridge `%s'", networks[i], _bridge);
+ if (STREQ(bridge, _bridge)) {
+ i = num;
+ } else {
+ virNetworkFree(network);
+ network = NULL;
+ }
+
+ free(_bridge);
+ }
+
+ free(networks);
+
+ return network;
+}
+
+static char *_netpool_member_of(virConnectPtr conn,
+ const char *bridge)
+{
+ virNetworkPtr net = NULL;
+ const char *netname;
+ char *pool = NULL;
+
+ net = bridge_to_network(conn, bridge);
+ if (net == NULL)
+ goto out;
+
+ netname = virNetworkGetName(net);
+ if (netname == NULL)
+ goto out;
+
+ if (asprintf(&pool, "NetworkPool/%s", netname) == -1)
+ pool = NULL;
+
+ CU_DEBUG("Determined pool: %s (%s, %s)", pool, bridge, netname);
+
+ out:
+ virNetworkFree(net);
+
+ return pool;
+}
+
static char *netpool_member_of(const CMPIBroker *broker,
const char *rasd_id,
const char *refcn)
@@ -227,11 +294,8 @@ static char *netpool_member_of(const CMP
for (i = 0; i < count; i++) {
if (STREQ((devs[i].id), dev)) {
- ret = asprintf(&result,
- "NetworkPool/%s",
- devs[i].dev.net.bridge);
- if (ret == -1)
- result = NULL;
+ result = _netpool_member_of(conn,
+ devs[i].dev.net.bridge);
break;
}
}
@@ -416,31 +480,54 @@ static CMPIStatus procpool_instance(virC
return s;
}
-static CMPIStatus _netpool_for_bridge(struct inst_list *list,
- const char *ns,
- const char *bridge,
- const char *refcn,
- const CMPIBroker *broker)
-{
- char *id = NULL;
+static CMPIStatus _netpool_for_network(struct inst_list *list,
+ const char *ns,
+ virConnectPtr conn,
+ const char *netname,
+ const char *refcn,
+ const CMPIBroker *broker)
+{
+ char *str = NULL;
+ char *bridge = NULL;
uint16_t type = CIM_RASD_TYPE_NET;
CMPIInstance *inst;
+ virNetworkPtr network = NULL;
+
+ CU_DEBUG("Looking up network `%s'", netname);
+ network = virNetworkLookupByName(conn, netname);
+ if (network == NULL) {
+ CMPIStatus s;
+
+ cu_statusf(broker, &s,
+ CMPI_RC_ERR_FAILED,
+ "No such NetworkPool: %s", netname);
+ return s;
+ }
inst = get_typed_instance(broker,
refcn,
"NetworkPool",
ns);
- if (asprintf(&id, "NetworkPool/%s", bridge) == -1)
+ if (asprintf(&str, "NetworkPool/%s", netname) == -1)
return (CMPIStatus){CMPI_RC_ERR_FAILED, NULL};
CMSetProperty(inst, "InstanceID",
- (CMPIValue *)id, CMPI_chars);
+ (CMPIValue *)str, CMPI_chars);
+ free(str);
+
+ bridge = virNetworkGetBridgeName(network);
+ if (asprintf(&str, "Bridge: %s", bridge) == -1)
+ return (CMPIStatus){CMPI_RC_ERR_FAILED, NULL};
+
+ CMSetProperty(inst, "Caption",
+ (CMPIValue *)str, CMPI_chars);
+ free(str);
+ free(bridge);
CMSetProperty(inst, "ResourceType",
(CMPIValue *)&type, CMPI_uint16);
- free(id);
inst_list_add(list, inst);
@@ -454,39 +541,49 @@ static CMPIStatus netpool_instance(virCo
const CMPIBroker *broker)
{
CMPIStatus s = {CMPI_RC_OK, NULL};
- char **bridges;
+ char **netnames = NULL;
int i;
+ int nets;
if (id != NULL) {
- if (!is_bridge(id)) {
- cu_statusf(broker, &s,
- CMPI_RC_ERR_FAILED,
- "No such network pool `%s'", id);
- goto out;
- }
- return _netpool_for_bridge(list,
- ns,
- id,
- pfx_from_conn(conn),
- broker);
- }
-
- bridges = list_bridges();
- if (bridges == NULL)
- return (CMPIStatus){CMPI_RC_ERR_FAILED, NULL};
-
- for (i = 0; bridges[i]; i++) {
- _netpool_for_bridge(list,
- ns,
- bridges[i],
- pfx_from_conn(conn),
- broker);
- free(bridges[i]);
- }
-
- free(bridges);
-
- out:
+ return _netpool_for_network(list,
+ ns,
+ conn,
+ id,
+ pfx_from_conn(conn),
+ broker);
+ }
+
+ nets = virConnectNumOfNetworks(conn);
+ if (nets < 0) {
+ cu_statusf(broker, &s,
+ CMPI_RC_ERR_FAILED,
+ "Unable to list networks");
+ goto out;
+ }
+
+ netnames = calloc(nets, sizeof(*netnames));
+ if (netnames == NULL) {
+ cu_statusf(broker, &s,
+ CMPI_RC_ERR_FAILED,
+ "Failed to allocate memory for %i net names", nets);
+ goto out;
+ }
+
+ nets = virConnectListNetworks(conn, netnames, nets);
+
+ for (i = 0; i < nets; i++) {
+ _netpool_for_network(list,
+ ns,
+ conn,
+ netnames[i],
+ pfx_from_conn(conn),
+ broker);
+ }
+
+ out:
+ free(netnames);
+
return s;
}
16 years, 10 months
[PATCH] VirtualSystemManagementCapabilities GetInstance() returns inst for invalid ref
by Kaitlin Rupert
# HG changeset patch
# User Kaitlin Rupert <karupert(a)us.ibm.com>
# Date 1199396274 28800
# Node ID 652cc30234dacb2bca5ca1b185dad32246aead48
# Parent 615554f6eca4cd21e5715a3af73a616637e54f96
VirtualSystemManagementCapabilities GetInstance() returns inst for invalid ref.
Instead of return_vsm_cap(), call get_vsm_cap() and the compare the properties of the ref with the instance returned by get_vsm_cap().
Failing query:
wbemcli gi 'http://localhost/root/virt:Xen_VirtualSystemManagementCapabilities.Instan..."wrong"'
Signed-off-by: Kaitlin Rupert <karupert(a)us.ibm.com>
diff -r 615554f6eca4 -r 652cc30234da src/Virt_VirtualSystemManagementCapabilities.c
--- a/src/Virt_VirtualSystemManagementCapabilities.c Fri Dec 14 16:13:18 2007 -0800
+++ b/src/Virt_VirtualSystemManagementCapabilities.c Thu Jan 03 13:37:54 2008 -0800
@@ -172,7 +172,24 @@ static CMPIStatus GetInstance(CMPIInstan
const CMPIObjectPath *reference,
const char **properties)
{
- return return_vsm_cap(reference, results, 0);
+ CMPIInstance *inst;
+ CMPIStatus s;
+ const char *prop;
+
+ s = get_vsm_cap(_BROKER, reference, &inst);
+ if (s.rc != CMPI_RC_OK)
+ return s;
+
+ prop = cu_compare_ref(reference, inst);
+ if (prop != NULL) {
+ cu_statusf(_BROKER, &s,
+ CMPI_RC_ERR_NOT_FOUND,
+ "No such instance (%s)", prop);
+ } else {
+ CMReturnInstance(results, inst);
+ }
+
+ return s;
}
DEFAULT_CI();
16 years, 10 months
[PATCH 0 of 5] #2 EAFP and RAFP support invalid references.
by Kaitlin Rupert
Updates from last set:
-"Cleanup device_type_from_poolid() in DevicePool" - reverted the function name back to device_type_from_poolid() instead of device_type_from_str()
-Added two new patches:
-"GetInstance() in DevicePool returns an instance for invalid refs."
-"Roll DevicePool GetInstance() functionality into a seperate function."
-Re-worked EAFP and RAFP patches based on the two new patches.
This fix makes it so that EAFP and RAFP do not return instances if an invalid ref is given.
These patches are dependant on the "Clean up RAFP and EAFP pool_to_* handlers." patchset.
16 years, 10 months
[PATCH] Make NetworkPool use libvirt's virtual network API
by Dan Smith
# HG changeset patch
# User Dan Smith <danms(a)us.ibm.com>
# Date 1199297921 28800
# Node ID 7d60f44ffb2d1e4efccd1b46bd184d2ca57063c0
# Parent 84b72fff34f65ad578d70fcc67b141510e34e24e
Make NetworkPool use libvirt's virtual network API
This means that you no longer see a NetworkPool for each bridge on the
system, but rather one per configured virtual network in libvirt. The
id is NetworkPool/NetName, and the Caption property of the instance
includes the bridge name for reference.
This change removes the need for the contents of hostres.{c,h}, so it is
removed here. That makes the net change -85 lines of pure goodness.
Signed-off-by: Dan Smith <danms(a)us.ibm.com>
diff -r 84b72fff34f6 -r 7d60f44ffb2d libxkutil/Makefile.am
--- a/libxkutil/Makefile.am Wed Jan 02 09:18:22 2008 -0800
+++ b/libxkutil/Makefile.am Wed Jan 02 10:18:41 2008 -0800
@@ -4,11 +4,11 @@ SUBDIRS = tests
CFLAGS += $(CFLAGS_STRICT)
-noinst_HEADERS = cs_util.h misc_util.h device_parsing.h hostres.h xmlgen.h
+noinst_HEADERS = cs_util.h misc_util.h device_parsing.h xmlgen.h
lib_LTLIBRARIES = libxkutil.la
AM_LDFLAGS = -lvirt -luuid
libxkutil_la_SOURCES = cs_util_instance.c misc_util.c device_parsing.c \
- xmlgen.c hostres.c
+ xmlgen.c
diff -r 84b72fff34f6 -r 7d60f44ffb2d libxkutil/hostres.c
--- a/libxkutil/hostres.c Wed Jan 02 09:18:22 2008 -0800
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,84 +0,0 @@
-/*
- * Copyright IBM Corp. 2007
- *
- * Authors:
- * Dan Smith <danms(a)us.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.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-#include <stdio.h>
-#include <stdbool.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <dirent.h>
-
-#include "hostres.h"
-
-bool is_bridge(const char *name)
-{
- char *path = NULL;
- int ret;
- struct stat s;
-
- ret = asprintf(&path, "/sys/class/net/%s/bridge", name);
- if (ret == -1)
- return false;
-
- if (stat(path, &s) != 0)
- return false;
-
- if (S_ISDIR(s.st_mode))
- return true;
- else
- return false;
-}
-
-char **list_bridges(void)
-{
- char **list = NULL;
- DIR *dir = NULL;
- struct dirent *de;
- int count = 0;
-
- dir = opendir("/sys/class/net");
- if (dir == NULL)
- return NULL;
-
- while ((de = readdir(dir))) {
- if (is_bridge(de->d_name)) {
- list = realloc(list, ++count);
- list[count-1] = strdup(de->d_name);
- }
- }
-
- /* Leave a NULL at the end, no matter what */
- list = realloc(list, count + 1);
- list[count] = NULL;
-
- return list;
-}
-
-/*
- * Local Variables:
- * mode: C
- * c-set-style: "K&R"
- * tab-width: 8
- * c-basic-offset: 8
- * indent-tabs-mode: nil
- * End:
- */
diff -r 84b72fff34f6 -r 7d60f44ffb2d libxkutil/hostres.h
--- a/libxkutil/hostres.h Wed Jan 02 09:18:22 2008 -0800
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,32 +0,0 @@
-/*
- * Copyright IBM Corp. 2007
- *
- * Authors:
- * Dan Smith <danms(a)us.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.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-#ifndef __HOSTRES_H
-#define __HOSTRES_H
-
-#include <stdbool.h>
-
-bool is_bridge(const char *name);
-
-/* Return a NULL-terminated array of bridge names on the system.
- Result must be free()d, as well as each of the array members */
-char **list_bridges(void);
-
-#endif
diff -r 84b72fff34f6 -r 7d60f44ffb2d src/Virt_DevicePool.c
--- a/src/Virt_DevicePool.c Wed Jan 02 09:18:22 2008 -0800
+++ b/src/Virt_DevicePool.c Wed Jan 02 10:18:41 2008 -0800
@@ -35,7 +35,6 @@
#include "config.h"
#include "misc_util.h"
-#include "hostres.h"
#include "device_parsing.h"
#include <libcmpiutil/libcmpiutil.h>
@@ -416,31 +415,53 @@ static CMPIStatus procpool_instance(virC
return s;
}
-static CMPIStatus _netpool_for_bridge(struct inst_list *list,
- const char *ns,
- const char *bridge,
- const char *refcn,
- const CMPIBroker *broker)
-{
- char *id = NULL;
+static CMPIStatus _netpool_for_network(struct inst_list *list,
+ const char *ns,
+ virConnectPtr conn,
+ const char *netname,
+ const char *refcn,
+ const CMPIBroker *broker)
+{
+ char *str = NULL;
+ char *bridge = NULL;
uint16_t type = CIM_RASD_TYPE_NET;
CMPIInstance *inst;
+ virNetworkPtr network = NULL;
+
+ network = virNetworkLookupByName(conn, netname);
+ if (network == NULL) {
+ CMPIStatus s;
+
+ cu_statusf(broker, &s,
+ CMPI_RC_ERR_FAILED,
+ "No such NetworkPool: %s", netname);
+ return s;
+ }
inst = get_typed_instance(broker,
refcn,
"NetworkPool",
ns);
- if (asprintf(&id, "NetworkPool/%s", bridge) == -1)
+ if (asprintf(&str, "NetworkPool/%s", netname) == -1)
return (CMPIStatus){CMPI_RC_ERR_FAILED, NULL};
CMSetProperty(inst, "InstanceID",
- (CMPIValue *)id, CMPI_chars);
+ (CMPIValue *)str, CMPI_chars);
+ free(str);
+
+ bridge = virNetworkGetBridgeName(network);
+ if (asprintf(&str, "Bridge: %s", bridge) == -1)
+ return (CMPIStatus){CMPI_RC_ERR_FAILED, NULL};
+
+ CMSetProperty(inst, "Caption",
+ (CMPIValue *)str, CMPI_chars);
+ free(str);
+ free(bridge);
CMSetProperty(inst, "ResourceType",
(CMPIValue *)&type, CMPI_uint16);
- free(id);
inst_list_add(list, inst);
@@ -454,39 +475,49 @@ static CMPIStatus netpool_instance(virCo
const CMPIBroker *broker)
{
CMPIStatus s = {CMPI_RC_OK, NULL};
- char **bridges;
+ char **netnames = NULL;
int i;
+ int nets;
if (id != NULL) {
- if (!is_bridge(id)) {
- cu_statusf(broker, &s,
- CMPI_RC_ERR_FAILED,
- "No such network pool `%s'", id);
- goto out;
- }
- return _netpool_for_bridge(list,
- ns,
- id,
- pfx_from_conn(conn),
- broker);
- }
-
- bridges = list_bridges();
- if (bridges == NULL)
- return (CMPIStatus){CMPI_RC_ERR_FAILED, NULL};
-
- for (i = 0; bridges[i]; i++) {
- _netpool_for_bridge(list,
- ns,
- bridges[i],
- pfx_from_conn(conn),
- broker);
- free(bridges[i]);
- }
-
- free(bridges);
-
- out:
+ return _netpool_for_network(list,
+ ns,
+ conn,
+ id,
+ pfx_from_conn(conn),
+ broker);
+ }
+
+ nets = virConnectNumOfNetworks(conn);
+ if (nets < 0) {
+ cu_statusf(broker, &s,
+ CMPI_RC_ERR_FAILED,
+ "Unable to list networks");
+ goto out;
+ }
+
+ netnames = calloc(nets, sizeof(*netnames));
+ if (netnames == NULL) {
+ cu_statusf(broker, &s,
+ CMPI_RC_ERR_FAILED,
+ "Failed to allocate memory for %i net names", nets);
+ goto out;
+ }
+
+ nets = virConnectListNetworks(conn, netnames, nets);
+
+ for (i = 0; i < nets; i++) {
+ _netpool_for_network(list,
+ ns,
+ conn,
+ netnames[i],
+ pfx_from_conn(conn),
+ broker);
+ }
+
+ out:
+ free(netnames);
+
return s;
}
16 years, 10 months
[PATCH] .#2 HRP accepts invalid references
by Kaitlin Rupert
# HG changeset patch
# User Kaitlin Rupert <karupert(a)us.ibm.com>
# Date 1199294302 28800
# Node ID b58d2ec7a275dce6fab21e1ae7f414b6159ce141
# Parent 3ea63b2076c1d02b7c3c48910809b9fb11ee290f
.#2 HRP accepts invalid references.
Updates: Fixed errors in commit message. Previous message didn't make any sense.
Add a get_pool_inst() call to pool_to_sys() handler. The get_pool_inst() call will verify whether the reference passed in is valid.
This patch is dependant on the "#2 EAFP and RAFP support invalid references" patchset.
Failing query:
wbemcli ain -ac Xen_HostedResourcePool http://localhost/root/virt:Xen_MemoryPool.InstanceID="wrong"
Signed-off-by: Kaitlin Rupert <karupert(a)us.ibm.com>
diff -r 3ea63b2076c1 -r b58d2ec7a275 src/Virt_HostedResourcePool.c
--- a/src/Virt_HostedResourcePool.c Fri Dec 21 10:58:37 2007 -0800
+++ b/src/Virt_HostedResourcePool.c Wed Jan 02 09:18:22 2008 -0800
@@ -43,8 +43,13 @@ static CMPIStatus pool_to_sys(const CMPI
{
CMPIInstance *host;
CMPIStatus s = {CMPI_RC_OK, NULL};
+ CMPIInstance *inst;
if (!match_hypervisor_prefix(ref, info))
+ return s;
+
+ s = get_pool_inst(_BROKER, ref, &inst);
+ if ((s.rc != CMPI_RC_OK) || (inst == NULL))
return s;
s = get_host_cs(_BROKER, ref, &host);
16 years, 10 months