Tue Feb 14 14:42:38 EST 2007 Mark McLoughlin <markmc@redhat.com

* src/internal.h: add virConnect->qemud_fd so that
        xen and qemu don't share the handle member.

        * src/hash.c, src/qemu_internal.c: update
This commit is contained in:
Mark McLoughlin 2007-02-14 15:45:49 +00:00
parent c9724cf339
commit d16a83dd7c
4 changed files with 27 additions and 301 deletions

View File

@ -1,102 +1,16 @@
Tue Feb 14 15:43:28 EST 2007 Mark McLoughlin <markmc@redhat.com> Tue Feb 14 14:42:38 EST 2007 Mark McLoughlin <markmc@redhat.com
* src/virsh.c: add the net-* commands.
Tue Feb 14 15:37:17 EST 2007 Mark McLoughlin <markmc@redhat.com>
Note: potential ABI break here, but people should
only really be using virError structs returned from
libvirt itself.
* include/libvirt/virterror.h: add virNetwork
to virError
* src/internal.h, src/virterror.c: add network param
to __virRaiseError()
* src/conf.c, src/hash.c, src/libvirt.c, src/proxy_internal.c,
src/qemu_internal.c, src/sexpr.c, src/test.c, src/xen_internal.c,
src/xend_internal.c, src/xm_internal.c, src/xml.c, src/xmlrpc.c,
src/xs_internal.c: update.
Tue Feb 14 15:33:05 EST 2007 Mark McLoughlin <markmc@redhat.com>
* include/libvirt/libvirt.h.in: add the networks APIs
* include/libvirt/virterror.h: add some error codes
* src/driver.h: add network driver vtable
* src/hash.c: add networks hash
* src/internal.h: add virNetwork
* src/libvirt.c: hook up the APIs to the network
driver
* src/libvirt_sym.version: add the new APIs
* src/virterror.c: handle the new error codes
Tue Feb 14 15:07:26 EST 2007 Mark McLoughlin <markmc@redhat.com>
* src/conf.h: fix merge error - remove the argc argument
from qemudBuildCommandLine()
Tue Feb 14 15:03:22 EST 2007 Mark McLoughlin <markmc@redhat.com>
* src/virsh.c: Re-name some of the VSH_DOMBYFOO stuff
to VSH_BYFOO in order to re-use it for the network stuff.
Tue Feb 14 14:58:35 EST 2007 Mark McLoughlin <markmc@redhat.com>
* src/hash.c, src/internal.h: Re-name virConnect->domains_mux
to virConnect->hashes_mux since it will also be used to
protect the networks hash.
Tue Feb 14 14:57:52 EST 2007 Mark McLoughlin <markmc@redhat.com>
* qemud/conf.c: qemudSaveConfig() will always report a
more specific error, so we should avoid overwriting
this error.
Tue Feb 14 14:54:25 EST 2007 Mark McLoughlin <markmc@redhat.com>
* qemud/qemud.c: Re-factor out qemudExec() so that it can
be used to launch dnsmasq.
* qemud/conf.c: don't return argc from qemudBuildCommandLine()
as exec() doesn't need it.
Tue Feb 14 14:52:12 EST 2007 Mark McLoughlin <markmc@redhat.com>
* qemud/conf.c: Re-factor bits of conf.c so that:
- qemudMakeConfigPath() can be re-used given another configDir
- split qemudEnsureConfigDir() out of qemudSaveConfig() so
that it may be re-used to create another configDir
- split qemudScanConfigDir() out so that qemudScanConfigs()
can scan multiple configDirs
Tue Feb 14 14:50:22 EST 2007 Mark McLoughlin <markmc@redhat.com>
* qemud/conf.c: handle an unspecified MAC address,
fix the argv freeing code in qemudBuildCommandLine()
and fix copy and paste error in qemudGenerateXML()
Tue Feb 14 14:42:38 EST 2007 Mark McLoughlin <markmc@redhat.com>
* src/internal.h: add virConnect->qemud_fd so that * src/internal.h: add virConnect->qemud_fd so that
xen and qemu don't share the handle member. xen and qemu don't share the handle member.
* src/hash.c, src/qemu_internal.c: update * src/hash.c, src/qemu_internal.c: update
Tue Feb 14 14:40:52 EST 2007 Mark McLoughlin <markmc@redhat.com> Tue Feb 14 14:40:52 EST 2007 Mark McLoughlin <markmc@redhat.com
* qemud/conf.c, qemud/dispatch.c, qemud/driver.c, * qemud/conf.c, qemud/dispatch.c, qemud/driver.c,
qemud/qemud.c: include autoconf's config.h qemud/qemud.c: include autoconf's config.h
Tue Feb 14 14:39:18 EST 2007 Mark McLoughlin <markmc@redhat.com> Tue Feb 14 14:39:18 EST 2007 Mark McLoughlin <markmc@redhat.com
* conf.[ch]: rename from config.[ch] so we can use * conf.[ch]: rename from config.[ch] so we can use
autoconf's config.h autoconf's config.h
@ -105,7 +19,7 @@ Tue Feb 14 14:39:18 EST 2007 Mark McLoughlin <markmc@redhat.com>
* driver.c, qemud.c: upd. * driver.c, qemud.c: upd.
Tue Feb 14 14:33:22 EST 2007 Mark McLoughlin <markmc@redhat.com> Tue Feb 14 14:33:22 EST 2007 Mark McLoughlin <markmc@redhat.com
* autogen.sh: run autoheader * autogen.sh: run autoheader

View File

@ -617,7 +617,7 @@ virHashError(virConnectPtr conn, virErrorNumber error, const char *info)
return; return;
errmsg = __virErrorMsg(error, info); errmsg = __virErrorMsg(error, info);
__virRaiseError(conn, NULL, NULL, VIR_FROM_NONE, error, VIR_ERR_ERROR, __virRaiseError(conn, NULL, VIR_FROM_NONE, error, VIR_ERR_ERROR,
errmsg, info, NULL, 0, 0, errmsg, info); errmsg, info, NULL, 0, 0, errmsg, info);
} }
@ -636,20 +636,6 @@ virDomainFreeName(virDomainPtr domain, const char *name ATTRIBUTE_UNUSED)
return (virDomainFree(domain)); return (virDomainFree(domain));
} }
/**
* virNetworkFreeName:
* @network: a network object
*
* Destroy the network object, this is just used by the network hash callback.
*
* Returns 0 in case of success and -1 in case of failure.
*/
static int
virNetworkFreeName(virNetworkPtr network, const char *name ATTRIBUTE_UNUSED)
{
return (virNetworkFree(network));
}
/** /**
* virGetConnect: * virGetConnect:
* *
@ -674,11 +660,8 @@ virGetConnect(void) {
ret->domains = virHashCreate(20); ret->domains = virHashCreate(20);
if (ret->domains == NULL) if (ret->domains == NULL)
goto failed; goto failed;
ret->networks = virHashCreate(20); ret->domains_mux = xmlNewMutex();
if (ret->networks == NULL) if (ret->domains_mux == NULL)
goto failed;
ret->hashes_mux = xmlNewMutex();
if (ret->hashes_mux == NULL)
goto failed; goto failed;
ret->uses = 1; ret->uses = 1;
@ -688,10 +671,8 @@ failed:
if (ret != NULL) { if (ret != NULL) {
if (ret->domains != NULL) if (ret->domains != NULL)
virHashFree(ret->domains, (virHashDeallocator) virDomainFreeName); virHashFree(ret->domains, (virHashDeallocator) virDomainFreeName);
if (ret->networks != NULL) if (ret->domains_mux != NULL)
virHashFree(ret->networks, (virHashDeallocator) virNetworkFreeName); xmlFreeMutex(ret->domains_mux);
if (ret->hashes_mux != NULL)
xmlFreeMutex(ret->hashes_mux);
free(ret); free(ret);
} }
return(NULL); return(NULL);
@ -710,24 +691,22 @@ int
virFreeConnect(virConnectPtr conn) { virFreeConnect(virConnectPtr conn) {
int ret; int ret;
if ((!VIR_IS_CONNECT(conn)) || (conn->hashes_mux == NULL)) { if ((!VIR_IS_CONNECT(conn)) || (conn->domains_mux == NULL)) {
virHashError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__); virHashError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
return(-1); return(-1);
} }
xmlMutexLock(conn->hashes_mux); xmlMutexLock(conn->domains_mux);
conn->uses--; conn->uses--;
ret = conn->uses; ret = conn->uses;
if (ret > 0) { if (ret > 0) {
xmlMutexUnlock(conn->hashes_mux); xmlMutexUnlock(conn->domains_mux);
return(ret); return(ret);
} }
if (conn->domains != NULL) if (conn->domains != NULL)
virHashFree(conn->domains, (virHashDeallocator) virDomainFreeName); virHashFree(conn->domains, (virHashDeallocator) virDomainFreeName);
if (conn->networks != NULL) if (conn->domains_mux != NULL)
virHashFree(conn->networks, (virHashDeallocator) virNetworkFreeName); xmlFreeMutex(conn->domains_mux);
if (conn->hashes_mux != NULL)
xmlFreeMutex(conn->hashes_mux);
free(conn); free(conn);
return(0); return(0);
} }
@ -750,11 +729,11 @@ virGetDomain(virConnectPtr conn, const char *name, const unsigned char *uuid) {
virDomainPtr ret = NULL; virDomainPtr ret = NULL;
if ((!VIR_IS_CONNECT(conn)) || ((name == NULL) && (uuid == NULL)) || if ((!VIR_IS_CONNECT(conn)) || ((name == NULL) && (uuid == NULL)) ||
(conn->hashes_mux == NULL)) { (conn->domains_mux == NULL)) {
virHashError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__); virHashError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
return(NULL); return(NULL);
} }
xmlMutexLock(conn->hashes_mux); xmlMutexLock(conn->domains_mux);
/* TODO search by UUID first as they are better differenciators */ /* TODO search by UUID first as they are better differenciators */
@ -792,11 +771,11 @@ virGetDomain(virConnectPtr conn, const char *name, const unsigned char *uuid) {
conn->uses++; conn->uses++;
done: done:
ret->uses++; ret->uses++;
xmlMutexUnlock(conn->hashes_mux); xmlMutexUnlock(conn->domains_mux);
return(ret); return(ret);
error: error:
xmlMutexUnlock(conn->hashes_mux); xmlMutexUnlock(conn->domains_mux);
if (ret != NULL) { if (ret != NULL) {
if (ret->name != NULL) if (ret->name != NULL)
free(ret->name ); free(ret->name );
@ -820,11 +799,11 @@ virFreeDomain(virConnectPtr conn, virDomainPtr domain) {
int ret = 0; int ret = 0;
if ((!VIR_IS_CONNECT(conn)) || (!VIR_IS_CONNECTED_DOMAIN(domain)) || if ((!VIR_IS_CONNECT(conn)) || (!VIR_IS_CONNECTED_DOMAIN(domain)) ||
(domain->conn != conn) || (conn->hashes_mux == NULL)) { (domain->conn != conn) || (conn->domains_mux == NULL)) {
virHashError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__); virHashError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
return(-1); return(-1);
} }
xmlMutexLock(conn->hashes_mux); xmlMutexLock(conn->domains_mux);
/* /*
* decrement the count for the domain * decrement the count for the domain
@ -860,13 +839,13 @@ virFreeDomain(virConnectPtr conn, virDomainPtr domain) {
if (conn->domains != NULL) if (conn->domains != NULL)
virHashFree(conn->domains, (virHashDeallocator) virDomainFreeName); virHashFree(conn->domains, (virHashDeallocator) virDomainFreeName);
if (conn->hashes_mux != NULL) if (conn->domains_mux != NULL)
xmlFreeMutex(conn->hashes_mux); xmlFreeMutex(conn->domains_mux);
free(conn); free(conn);
return(0); return(0);
done: done:
xmlMutexUnlock(conn->hashes_mux); xmlMutexUnlock(conn->domains_mux);
return(ret); return(ret);
} }
@ -891,7 +870,7 @@ virGetDomainByID(virConnectPtr conn, int id) {
virHashError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__); virHashError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
return(NULL); return(NULL);
} }
xmlMutexLock(conn->hashes_mux); xmlMutexLock(conn->domains_mux);
table = conn->domains; table = conn->domains;
if ((table == NULL) || (table->nbElems == 0)) if ((table == NULL) || (table->nbElems == 0))
@ -911,142 +890,9 @@ virGetDomainByID(virConnectPtr conn, int id) {
} }
} }
done: done:
xmlMutexUnlock(conn->hashes_mux); xmlMutexUnlock(conn->domains_mux);
return(ret); return(ret);
} }
/**
* virGetNetwork:
* @conn: the hypervisor connection
* @name: pointer to the network name or NULL
* @uuid: pointer to the uuid or NULL
*
* Lookup if the network is already registered for that connection,
* if yes return a new pointer to it, if no allocate a new structure,
* and register it in the table. In any case a corresponding call to
* virFreeNetwork() is needed to not leak data.
*
* Returns a pointer to the network, or NULL in case of failure
*/
virNetworkPtr
virGetNetwork(virConnectPtr conn, const char *name, const unsigned char *uuid) {
virNetworkPtr ret = NULL;
if ((!VIR_IS_CONNECT(conn)) || ((name == NULL) && (uuid == NULL)) ||
(conn->hashes_mux == NULL)) {
virHashError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
return(NULL);
}
xmlMutexLock(conn->hashes_mux);
/* TODO search by UUID first as they are better differenciators */
ret = (virNetworkPtr) virHashLookup(conn->networks, name);
if (ret != NULL) {
/* TODO check the UUID */
goto done;
}
/*
* not found, allocate a new one
*/
ret = (virNetworkPtr) malloc(sizeof(virNetwork));
if (ret == NULL) {
virHashError(conn, VIR_ERR_NO_MEMORY, _("allocating network"));
goto error;
}
memset(ret, 0, sizeof(virNetwork));
ret->name = strdup(name);
if (ret->name == NULL) {
virHashError(conn, VIR_ERR_NO_MEMORY, _("allocating network"));
goto error;
}
ret->magic = VIR_NETWORK_MAGIC;
ret->conn = conn;
if (uuid != NULL)
memcpy(&(ret->uuid[0]), uuid, VIR_UUID_BUFLEN);
if (virHashAddEntry(conn->networks, name, ret) < 0) {
virHashError(conn, VIR_ERR_INTERNAL_ERROR,
_("failed to add network to connection hash table"));
goto error;
}
conn->uses++;
done:
ret->uses++;
xmlMutexUnlock(conn->hashes_mux);
return(ret);
error:
xmlMutexUnlock(conn->hashes_mux);
if (ret != NULL) {
if (ret->name != NULL)
free(ret->name );
free(ret);
}
return(NULL);
}
/**
* virFreeNetwork:
* @conn: the hypervisor connection
* @network: the network to release
*
* Release the given network, if the reference count drops to zero, then
* the network is really freed.
*
* Returns the reference count or -1 in case of failure.
*/
int
virFreeNetwork(virConnectPtr conn, virNetworkPtr network) {
int ret = 0;
if ((!VIR_IS_CONNECT(conn)) || (!VIR_IS_CONNECTED_NETWORK(network)) ||
(network->conn != conn) || (conn->hashes_mux == NULL)) {
virHashError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
return(-1);
}
xmlMutexLock(conn->hashes_mux);
/*
* decrement the count for the network
*/
network->uses--;
ret = network->uses;
if (ret > 0)
goto done;
/* TODO search by UUID first as they are better differenciators */
if (virHashRemoveEntry(conn->networks, network->name, NULL) < 0) {
virHashError(conn, VIR_ERR_INTERNAL_ERROR,
_("network missing from connection hash table"));
goto done;
}
network->magic = -1;
if (network->name)
free(network->name);
free(network);
/*
* decrement the count for the connection
*/
conn->uses--;
if (conn->uses > 0)
goto done;
if (conn->networks != NULL)
virHashFree(conn->networks, (virHashDeallocator) virNetworkFreeName);
if (conn->hashes_mux != NULL)
xmlFreeMutex(conn->hashes_mux);
free(conn);
return(0);
done:
xmlMutexUnlock(conn->hashes_mux);
return(ret);
}
/* /*
* Local variables: * Local variables:
* indent-tabs-mode: nil * indent-tabs-mode: nil

View File

@ -84,16 +84,6 @@ extern "C" {
#define VIR_IS_DOMAIN(obj) ((obj) && (obj)->magic==VIR_DOMAIN_MAGIC) #define VIR_IS_DOMAIN(obj) ((obj) && (obj)->magic==VIR_DOMAIN_MAGIC)
#define VIR_IS_CONNECTED_DOMAIN(obj) (VIR_IS_DOMAIN(obj) && VIR_IS_CONNECT((obj)->conn)) #define VIR_IS_CONNECTED_DOMAIN(obj) (VIR_IS_DOMAIN(obj) && VIR_IS_CONNECT((obj)->conn))
/**
* VIR_NETWORK_MAGIC:
*
* magic value used to protect the API when pointers to network structures
* are passed down by the uers.
*/
#define VIR_NETWORK_MAGIC 0xDEAD1234
#define VIR_IS_NETWORK(obj) ((obj) && (obj)->magic==VIR_NETWORK_MAGIC)
#define VIR_IS_CONNECTED_NETWORK(obj) (VIR_IS_NETWORK(obj) && VIR_IS_CONNECT((obj)->conn))
#define MAX_DRIVERS 10 #define MAX_DRIVERS 10
/* /*
@ -114,10 +104,6 @@ struct _virConnect {
virDriverPtr drivers[MAX_DRIVERS]; virDriverPtr drivers[MAX_DRIVERS];
int nb_drivers; int nb_drivers;
/* the list of available network drivers */
virNetworkDriverPtr networkDrivers[MAX_DRIVERS];
int nb_network_drivers;
/* extra data needed by drivers */ /* extra data needed by drivers */
int handle; /* internal handle used for hypercall */ int handle; /* internal handle used for hypercall */
struct xs_handle *xshandle;/* handle to talk to the xenstore */ struct xs_handle *xshandle;/* handle to talk to the xenstore */
@ -139,9 +125,8 @@ struct _virConnect {
void *userData; /* the user data */ void *userData; /* the user data */
/* misc */ /* misc */
xmlMutexPtr hashes_mux;/* a mutex to protect the domain and networks hash tables */ xmlMutexPtr domains_mux;/* a mutex to protect the domain hash table */
virHashTablePtr domains;/* hash table for known domains */ virHashTablePtr domains;/* hash table for known domains */
virHashTablePtr networks;/* hash table for known domains */
int flags; /* a set of connection flags */ int flags; /* a set of connection flags */
}; };
@ -173,19 +158,6 @@ struct _virDomain {
char *xml; /* the XML description for defined domains */ char *xml; /* the XML description for defined domains */
}; };
/**
* _virNetwork:
*
* Internal structure associated to a domain
*/
struct _virNetwork {
unsigned int magic; /* specific value to check */
int uses; /* reference count */
virConnectPtr conn; /* pointer back to the connection */
char *name; /* the network external name */
unsigned char uuid[VIR_UUID_BUFLEN]; /* the network unique identifier */
};
/* /*
* Internal routines * Internal routines
*/ */
@ -200,7 +172,6 @@ char *virDomainGetVMInfo(virDomainPtr domain,
************************************************************************/ ************************************************************************/
void __virRaiseError(virConnectPtr conn, void __virRaiseError(virConnectPtr conn,
virDomainPtr dom, virDomainPtr dom,
virNetworkPtr net,
int domain, int domain,
int code, int code,
virErrorLevel level, virErrorLevel level,
@ -225,11 +196,6 @@ int virFreeDomain (virConnectPtr conn,
virDomainPtr domain); virDomainPtr domain);
virDomainPtr virGetDomainByID(virConnectPtr conn, virDomainPtr virGetDomainByID(virConnectPtr conn,
int id); int id);
virNetworkPtr virGetNetwork (virConnectPtr conn,
const char *name,
const unsigned char *uuid);
int virFreeNetwork (virConnectPtr conn,
virNetworkPtr domain);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -61,7 +61,7 @@ qemuError(virConnectPtr con,
return; return;
errmsg = __virErrorMsg(error, info); errmsg = __virErrorMsg(error, info);
__virRaiseError(con, dom, NULL, VIR_FROM_QEMU, error, VIR_ERR_ERROR, __virRaiseError(con, dom, VIR_FROM_QEMU, error, VIR_ERR_ERROR,
errmsg, info, NULL, 0, 0, errmsg, info, 0); errmsg, info, NULL, 0, 0, errmsg, info, 0);
} }