mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-23 14:15:28 +00:00
Convert public datatypes to inherit from virObject
This converts the following public API datatypes to use the virObject infrastructure: virConnectPtr virDomainPtr virDomainSnapshotPtr virInterfacePtr virNetworkPtr virNodeDevicePtr virNWFilterPtr virSecretPtr virStreamPtr virStorageVolPtr virStoragePoolPtr The code is significantly simplified, since the mutex in the virConnectPtr object now only needs to be held when accessing the per-connection virError object instance. All other operations are completely lock free. * src/datatypes.c, src/datatypes.h, src/libvirt.c: Convert public datatypes to use virObject * src/conf/domain_event.c, src/phyp/phyp_driver.c, src/qemu/qemu_command.c, src/qemu/qemu_migration.c, src/qemu/qemu_process.c, src/storage/storage_driver.c, src/vbox/vbox_tmpl.c, src/xen/xend_internal.c, tests/qemuxml2argvtest.c, tests/qemuxmlnstest.c, tests/sexpr2xmltest.c, tests/xmconfigtest.c: Convert to use virObjectUnref/virObjectRef Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
This commit is contained in:
parent
784a99f794
commit
46ec5f85c8
@ -34,7 +34,7 @@ foreach my $elflib (@elflibs) {
|
||||
open NM, "-|", "nm", $elflib or die "cannot run 'nm $elflib': $!";
|
||||
|
||||
while (<NM>) {
|
||||
next unless /^\S+\s(?:T|D)\s(\S+)\s*$/;
|
||||
next unless /^\S+\s(?:[TBD])\s(\S+)\s*$/;
|
||||
|
||||
$gotsyms{$1} = 1;
|
||||
}
|
||||
|
@ -169,7 +169,7 @@ virDomainEventCallbackListRemove(virConnectPtr conn,
|
||||
virFreeCallback freecb = cbList->callbacks[i]->freecb;
|
||||
if (freecb)
|
||||
(*freecb)(cbList->callbacks[i]->opaque);
|
||||
virUnrefConnect(cbList->callbacks[i]->conn);
|
||||
virObjectUnref(cbList->callbacks[i]->conn);
|
||||
VIR_FREE(cbList->callbacks[i]);
|
||||
|
||||
if (i < (cbList->count - 1))
|
||||
@ -219,7 +219,7 @@ virDomainEventCallbackListRemoveID(virConnectPtr conn,
|
||||
virFreeCallback freecb = cbList->callbacks[i]->freecb;
|
||||
if (freecb)
|
||||
(*freecb)(cbList->callbacks[i]->opaque);
|
||||
virUnrefConnect(cbList->callbacks[i]->conn);
|
||||
virObjectUnref(cbList->callbacks[i]->conn);
|
||||
VIR_FREE(cbList->callbacks[i]);
|
||||
|
||||
if (i < (cbList->count - 1))
|
||||
@ -309,7 +309,7 @@ virDomainEventCallbackListPurgeMarked(virDomainEventCallbackListPtr cbList)
|
||||
virFreeCallback freecb = cbList->callbacks[i]->freecb;
|
||||
if (freecb)
|
||||
(*freecb)(cbList->callbacks[i]->opaque);
|
||||
virUnrefConnect(cbList->callbacks[i]->conn);
|
||||
virObjectUnref(cbList->callbacks[i]->conn);
|
||||
VIR_FREE(cbList->callbacks[i]);
|
||||
|
||||
if (i < (cbList->count - 1))
|
||||
@ -395,7 +395,7 @@ virDomainEventCallbackListAddID(virConnectPtr conn,
|
||||
if (VIR_REALLOC_N(cbList->callbacks, cbList->count + 1) < 0)
|
||||
goto no_memory;
|
||||
|
||||
event->conn->refs++;
|
||||
virObjectRef(event->conn);
|
||||
|
||||
cbList->callbacks[cbList->count] = event;
|
||||
cbList->count++;
|
||||
|
1028
src/datatypes.c
1028
src/datatypes.c
File diff suppressed because it is too large
Load Diff
271
src/datatypes.h
271
src/datatypes.h
@ -19,125 +19,79 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef __VIRT_DATATYPES_H_
|
||||
# define __VIRT_DATATYPES_H_
|
||||
#ifndef __VIR_DATATYPES_H_
|
||||
# define __VIR_DATATYPES_H_
|
||||
|
||||
# include "internal.h"
|
||||
|
||||
# include "driver.h"
|
||||
# include "threads.h"
|
||||
# include "virobject.h"
|
||||
|
||||
/**
|
||||
* VIR_CONNECT_MAGIC:
|
||||
*
|
||||
* magic value used to protect the API when pointers to connection structures
|
||||
* are passed down by the users.
|
||||
*/
|
||||
# define VIR_CONNECT_MAGIC 0x4F23DEAD
|
||||
# define VIR_IS_CONNECT(obj) ((obj) && (obj)->magic==VIR_CONNECT_MAGIC)
|
||||
extern virClassPtr virConnectClass;
|
||||
extern virClassPtr virDomainClass;
|
||||
extern virClassPtr virDomainSnapshotClass;
|
||||
extern virClassPtr virInterfaceClass;
|
||||
extern virClassPtr virNetworkClass;
|
||||
extern virClassPtr virNodeDeviceClass;
|
||||
extern virClassPtr virNWFilterClass;
|
||||
extern virClassPtr virSecretClass;
|
||||
extern virClassPtr virStreamClass;
|
||||
extern virClassPtr virStorageVolClass;
|
||||
extern virClassPtr virStoragePoolClass;
|
||||
|
||||
# define VIR_IS_CONNECT(obj) \
|
||||
(virObjectIsClass((obj), virConnectClass))
|
||||
|
||||
/**
|
||||
* VIR_DOMAIN_MAGIC:
|
||||
*
|
||||
* magic value used to protect the API when pointers to domain structures
|
||||
* are passed down by the users.
|
||||
*/
|
||||
# define VIR_DOMAIN_MAGIC 0xDEAD4321
|
||||
# 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_DOMAIN(obj) \
|
||||
(virObjectIsClass((obj), virDomainClass))
|
||||
# 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 users.
|
||||
*/
|
||||
# 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 VIR_IS_NETWORK(obj) \
|
||||
(virObjectIsClass((obj), virNetworkClass))
|
||||
# define VIR_IS_CONNECTED_NETWORK(obj) \
|
||||
(VIR_IS_NETWORK(obj) && VIR_IS_CONNECT((obj)->conn))
|
||||
|
||||
/**
|
||||
* VIR_INTERFACE_MAGIC:
|
||||
*
|
||||
* magic value used to protect the API when pointers to interface structures
|
||||
* are passed down by the users.
|
||||
*/
|
||||
# define VIR_INTERFACE_MAGIC 0xDEAD5309
|
||||
# define VIR_IS_INTERFACE(obj) ((obj) && (obj)->magic==VIR_INTERFACE_MAGIC)
|
||||
# define VIR_IS_CONNECTED_INTERFACE(obj) (VIR_IS_INTERFACE(obj) && VIR_IS_CONNECT((obj)->conn))
|
||||
# define VIR_IS_INTERFACE(obj) \
|
||||
(virObjectIsClass((obj), virInterfaceClass))
|
||||
# define VIR_IS_CONNECTED_INTERFACE(obj) \
|
||||
(VIR_IS_INTERFACE(obj) && VIR_IS_CONNECT((obj)->conn))
|
||||
|
||||
/**
|
||||
* VIR_STORAGE_POOL_MAGIC:
|
||||
*
|
||||
* magic value used to protect the API when pointers to storage pool structures
|
||||
* are passed down by the users.
|
||||
*/
|
||||
# define VIR_STORAGE_POOL_MAGIC 0xDEAD5678
|
||||
# define VIR_IS_STORAGE_POOL(obj) ((obj) && (obj)->magic==VIR_STORAGE_POOL_MAGIC)
|
||||
# define VIR_IS_CONNECTED_STORAGE_POOL(obj) (VIR_IS_STORAGE_POOL(obj) && VIR_IS_CONNECT((obj)->conn))
|
||||
# define VIR_IS_STORAGE_POOL(obj) \
|
||||
(virObjectIsClass((obj), virStoragePoolClass))
|
||||
# define VIR_IS_CONNECTED_STORAGE_POOL(obj) \
|
||||
(VIR_IS_STORAGE_POOL(obj) && VIR_IS_CONNECT((obj)->conn))
|
||||
|
||||
/**
|
||||
* VIR_STORAGE_VOL_MAGIC:
|
||||
*
|
||||
* magic value used to protect the API when pointers to storage vol structures
|
||||
* are passed down by the users.
|
||||
*/
|
||||
# define VIR_STORAGE_VOL_MAGIC 0xDEAD8765
|
||||
# define VIR_IS_STORAGE_VOL(obj) ((obj) && (obj)->magic==VIR_STORAGE_VOL_MAGIC)
|
||||
# define VIR_IS_CONNECTED_STORAGE_VOL(obj) (VIR_IS_STORAGE_VOL(obj) && VIR_IS_CONNECT((obj)->conn))
|
||||
# define VIR_IS_STORAGE_VOL(obj) \
|
||||
(virObjectIsClass((obj), virStorageVolClass))
|
||||
# define VIR_IS_CONNECTED_STORAGE_VOL(obj) \
|
||||
(VIR_IS_STORAGE_VOL(obj) && VIR_IS_CONNECT((obj)->conn))
|
||||
|
||||
/**
|
||||
* VIR_NODE_DEVICE_MAGIC:
|
||||
*
|
||||
* magic value used to protect the API when pointers to storage vol structures
|
||||
* are passed down by the users.
|
||||
*/
|
||||
# define VIR_NODE_DEVICE_MAGIC 0xDEAD5679
|
||||
# define VIR_IS_NODE_DEVICE(obj) ((obj) && (obj)->magic==VIR_NODE_DEVICE_MAGIC)
|
||||
# define VIR_IS_CONNECTED_NODE_DEVICE(obj) (VIR_IS_NODE_DEVICE(obj) && VIR_IS_CONNECT((obj)->conn))
|
||||
# define VIR_IS_NODE_DEVICE(obj) \
|
||||
(virObjectIsClass((obj), virNodeDeviceClass))
|
||||
# define VIR_IS_CONNECTED_NODE_DEVICE(obj) \
|
||||
(VIR_IS_NODE_DEVICE(obj) && VIR_IS_CONNECT((obj)->conn))
|
||||
|
||||
/**
|
||||
* VIR_SECRET_MAGIC:
|
||||
*
|
||||
* magic value used to protect the API when pointers to secret structures are
|
||||
* passed down by the users.
|
||||
*/
|
||||
# define VIR_SECRET_MAGIC 0x5678DEAD
|
||||
# define VIR_IS_SECRET(obj) ((obj) && (obj)->magic==VIR_SECRET_MAGIC)
|
||||
# define VIR_IS_CONNECTED_SECRET(obj) (VIR_IS_SECRET(obj) && VIR_IS_CONNECT((obj)->conn))
|
||||
# define VIR_IS_SECRET(obj) \
|
||||
(virObjectIsClass((obj), virSecretClass))
|
||||
# define VIR_IS_CONNECTED_SECRET(obj) \
|
||||
(VIR_IS_SECRET(obj) && VIR_IS_CONNECT((obj)->conn))
|
||||
|
||||
# define VIR_IS_STREAM(obj) \
|
||||
(virObjectIsClass((obj), virStreamClass))
|
||||
# define VIR_IS_CONNECTED_STREAM(obj) \
|
||||
(VIR_IS_STREAM(obj) && VIR_IS_CONNECT((obj)->conn))
|
||||
|
||||
/**
|
||||
* VIR_STREAM_MAGIC:
|
||||
*
|
||||
* magic value used to protect the API when pointers to stream structures
|
||||
* are passed down by the users.
|
||||
*/
|
||||
# define VIR_STREAM_MAGIC 0x1DEAD666
|
||||
# define VIR_IS_STREAM(obj) ((obj) && (obj)->magic==VIR_STREAM_MAGIC)
|
||||
# define VIR_IS_CONNECTED_STREAM(obj) (VIR_IS_STREAM(obj) && VIR_IS_CONNECT((obj)->conn))
|
||||
# define VIR_IS_NWFILTER(obj) \
|
||||
(virObjectIsClass((obj), virNWFilterClass))
|
||||
# define VIR_IS_CONNECTED_NWFILTER(obj) \
|
||||
(VIR_IS_NWFILTER(obj) && VIR_IS_CONNECT((obj)->conn))
|
||||
|
||||
|
||||
/**
|
||||
* VIR_NWFILTER_MAGIC:
|
||||
*
|
||||
* magic value used to protect the API when pointers to network filter
|
||||
* pool structures are passed down by the users.
|
||||
*/
|
||||
# define VIR_NWFILTER_MAGIC 0xDEAD7777
|
||||
# define VIR_IS_NWFILTER(obj) ((obj) && (obj)->magic==VIR_NWFILTER_MAGIC)
|
||||
# define VIR_IS_CONNECTED_NWFILTER(obj) (VIR_IS_NWFILTER(obj) && VIR_IS_CONNECT((obj)->conn))
|
||||
|
||||
/**
|
||||
* VIR_SNAPSHOT_MAGIC:
|
||||
*
|
||||
* magic value used to protect the API when pointers to snapshot structures
|
||||
* are passed down by the users.
|
||||
*/
|
||||
# define VIR_SNAPSHOT_MAGIC 0x6666DEAD
|
||||
# define VIR_IS_SNAPSHOT(obj) ((obj) && (obj)->magic==VIR_SNAPSHOT_MAGIC)
|
||||
# define VIR_IS_DOMAIN_SNAPSHOT(obj) (VIR_IS_SNAPSHOT(obj) && VIR_IS_DOMAIN((obj)->domain))
|
||||
# define VIR_IS_SNAPSHOT(obj) \
|
||||
(virObjectIsClass((obj), virDomainSnapshotClass))
|
||||
# define VIR_IS_DOMAIN_SNAPSHOT(obj) \
|
||||
(VIR_IS_SNAPSHOT(obj) && VIR_IS_DOMAIN((obj)->domain))
|
||||
|
||||
/**
|
||||
* _virConnect:
|
||||
@ -145,11 +99,11 @@
|
||||
* Internal structure associated to a connection
|
||||
*/
|
||||
struct _virConnect {
|
||||
virObject object;
|
||||
/* All the variables from here, until the 'lock' declaration
|
||||
* are setup at time of connection open, and never changed
|
||||
* since. Thus no need to lock when accessing them
|
||||
*/
|
||||
unsigned int magic; /* specific value to check */
|
||||
unsigned int flags; /* a set of connection flags */
|
||||
virURIPtr uri; /* connection URI */
|
||||
|
||||
@ -193,8 +147,6 @@ struct _virConnect {
|
||||
virFreeCallback closeFreeCallback;
|
||||
bool closeDispatch;
|
||||
unsigned closeUnregisterCount;
|
||||
|
||||
int refs; /* reference count */
|
||||
};
|
||||
|
||||
/**
|
||||
@ -203,8 +155,7 @@ struct _virConnect {
|
||||
* Internal structure associated to a domain
|
||||
*/
|
||||
struct _virDomain {
|
||||
unsigned int magic; /* specific value to check */
|
||||
int refs; /* reference count */
|
||||
virObject object;
|
||||
virConnectPtr conn; /* pointer back to the connection */
|
||||
char *name; /* the domain external name */
|
||||
int id; /* the domain ID */
|
||||
@ -217,8 +168,7 @@ struct _virDomain {
|
||||
* Internal structure associated to a domain
|
||||
*/
|
||||
struct _virNetwork {
|
||||
unsigned int magic; /* specific value to check */
|
||||
int refs; /* reference count */
|
||||
virObject object;
|
||||
virConnectPtr conn; /* pointer back to the connection */
|
||||
char *name; /* the network external name */
|
||||
unsigned char uuid[VIR_UUID_BUFLEN]; /* the network unique identifier */
|
||||
@ -230,8 +180,7 @@ struct _virNetwork {
|
||||
* Internal structure associated to a physical host interface
|
||||
*/
|
||||
struct _virInterface {
|
||||
unsigned int magic; /* specific value to check */
|
||||
int refs; /* reference count */
|
||||
virObject object;
|
||||
virConnectPtr conn; /* pointer back to the connection */
|
||||
char *name; /* the network external name */
|
||||
char *mac; /* the interface MAC address */
|
||||
@ -243,8 +192,7 @@ struct _virInterface {
|
||||
* Internal structure associated to a storage pool
|
||||
*/
|
||||
struct _virStoragePool {
|
||||
unsigned int magic; /* specific value to check */
|
||||
int refs; /* reference count */
|
||||
virObject object;
|
||||
virConnectPtr conn; /* pointer back to the connection */
|
||||
char *name; /* the storage pool external name */
|
||||
unsigned char uuid[VIR_UUID_BUFLEN]; /* the storage pool unique identifier */
|
||||
@ -256,8 +204,7 @@ struct _virStoragePool {
|
||||
* Internal structure associated to a storage volume
|
||||
*/
|
||||
struct _virStorageVol {
|
||||
unsigned int magic; /* specific value to check */
|
||||
int refs; /* reference count */
|
||||
virObject object;
|
||||
virConnectPtr conn; /* pointer back to the connection */
|
||||
char *pool; /* Pool name of owner */
|
||||
char *name; /* the storage vol external name */
|
||||
@ -270,8 +217,7 @@ struct _virStorageVol {
|
||||
* Internal structure associated with a node device
|
||||
*/
|
||||
struct _virNodeDevice {
|
||||
unsigned int magic; /* specific value to check */
|
||||
int refs; /* reference count */
|
||||
virObject object;
|
||||
virConnectPtr conn; /* pointer back to the connection */
|
||||
char *name; /* device name (unique on node) */
|
||||
char *parent; /* parent device name */
|
||||
@ -283,8 +229,7 @@ struct _virNodeDevice {
|
||||
* Internal structure associated with a secret
|
||||
*/
|
||||
struct _virSecret {
|
||||
unsigned int magic; /* specific value to check */
|
||||
int refs; /* reference count */
|
||||
virObject object;
|
||||
virConnectPtr conn; /* pointer back to the connection */
|
||||
unsigned char uuid[VIR_UUID_BUFLEN]; /* the domain unique identifier */
|
||||
int usageType; /* the type of usage */
|
||||
@ -301,9 +246,8 @@ typedef int (*virStreamFinishFunc)(virStreamPtr, void *opaque);
|
||||
* Internal structure associated with an input stream
|
||||
*/
|
||||
struct _virStream {
|
||||
unsigned int magic;
|
||||
virObject object;
|
||||
virConnectPtr conn;
|
||||
int refs;
|
||||
unsigned int flags;
|
||||
|
||||
virStreamDriverPtr driver;
|
||||
@ -316,77 +260,56 @@ struct _virStream {
|
||||
* Internal structure associated with a domain snapshot
|
||||
*/
|
||||
struct _virDomainSnapshot {
|
||||
unsigned int magic;
|
||||
int refs;
|
||||
virObject object;
|
||||
char *name;
|
||||
virDomainPtr domain;
|
||||
};
|
||||
|
||||
/************************************************************************
|
||||
* *
|
||||
* API for domain/connections (de)allocations and lookups *
|
||||
* *
|
||||
************************************************************************/
|
||||
|
||||
virConnectPtr virGetConnect(void);
|
||||
int virUnrefConnect(virConnectPtr conn);
|
||||
virDomainPtr virGetDomain(virConnectPtr conn,
|
||||
const char *name,
|
||||
const unsigned char *uuid);
|
||||
int virUnrefDomain(virDomainPtr domain);
|
||||
virNetworkPtr virGetNetwork(virConnectPtr conn,
|
||||
const char *name,
|
||||
const unsigned char *uuid);
|
||||
int virUnrefNetwork(virNetworkPtr network);
|
||||
|
||||
virInterfacePtr virGetInterface(virConnectPtr conn,
|
||||
const char *name,
|
||||
const char *mac);
|
||||
int virUnrefInterface(virInterfacePtr iface);
|
||||
|
||||
virStoragePoolPtr virGetStoragePool(virConnectPtr conn,
|
||||
const char *name,
|
||||
const unsigned char *uuid);
|
||||
int virUnrefStoragePool(virStoragePoolPtr pool);
|
||||
virStorageVolPtr virGetStorageVol(virConnectPtr conn,
|
||||
const char *pool,
|
||||
const char *name,
|
||||
const char *key);
|
||||
int virUnrefStorageVol(virStorageVolPtr vol);
|
||||
|
||||
virNodeDevicePtr virGetNodeDevice(virConnectPtr conn,
|
||||
const char *name);
|
||||
int virUnrefNodeDevice(virNodeDevicePtr dev);
|
||||
|
||||
virSecretPtr virGetSecret(virConnectPtr conn,
|
||||
const unsigned char *uuid,
|
||||
int usageType,
|
||||
const char *usageID);
|
||||
int virUnrefSecret(virSecretPtr secret);
|
||||
|
||||
virStreamPtr virGetStream(virConnectPtr conn);
|
||||
int virUnrefStream(virStreamPtr st);
|
||||
|
||||
/**
|
||||
* _virNWFilter:
|
||||
*
|
||||
* Internal structure associated to a network filter
|
||||
*/
|
||||
struct _virNWFilter {
|
||||
unsigned int magic; /* specific value to check */
|
||||
int refs; /* reference count */
|
||||
virObject object;
|
||||
virConnectPtr conn; /* pointer back to the connection */
|
||||
char *name; /* the network filter external name */
|
||||
unsigned char uuid[VIR_UUID_BUFLEN]; /* the network filter unique identifier */
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* Helper APIs for allocating new object instances
|
||||
*/
|
||||
|
||||
virConnectPtr virGetConnect(void);
|
||||
virDomainPtr virGetDomain(virConnectPtr conn,
|
||||
const char *name,
|
||||
const unsigned char *uuid);
|
||||
virNetworkPtr virGetNetwork(virConnectPtr conn,
|
||||
const char *name,
|
||||
const unsigned char *uuid);
|
||||
virInterfacePtr virGetInterface(virConnectPtr conn,
|
||||
const char *name,
|
||||
const char *mac);
|
||||
virStoragePoolPtr virGetStoragePool(virConnectPtr conn,
|
||||
const char *name,
|
||||
const unsigned char *uuid);
|
||||
virStorageVolPtr virGetStorageVol(virConnectPtr conn,
|
||||
const char *pool,
|
||||
const char *name,
|
||||
const char *key);
|
||||
virNodeDevicePtr virGetNodeDevice(virConnectPtr conn,
|
||||
const char *name);
|
||||
virSecretPtr virGetSecret(virConnectPtr conn,
|
||||
const unsigned char *uuid,
|
||||
int usageType,
|
||||
const char *usageID);
|
||||
virStreamPtr virGetStream(virConnectPtr conn);
|
||||
virNWFilterPtr virGetNWFilter(virConnectPtr conn,
|
||||
const char *name,
|
||||
const unsigned char *uuid);
|
||||
int virUnrefNWFilter(virNWFilterPtr nwfilter);
|
||||
|
||||
virDomainSnapshotPtr virGetDomainSnapshot(virDomainPtr domain,
|
||||
const char *name);
|
||||
int virUnrefDomainSnapshot(virDomainSnapshotPtr snapshot);
|
||||
|
||||
#endif
|
||||
#endif /* __VIR_DATATYPES_H__ */
|
||||
|
145
src/libvirt.c
145
src/libvirt.c
@ -1293,7 +1293,7 @@ do_open (const char *name,
|
||||
|
||||
failed:
|
||||
virConfFree(conf);
|
||||
virUnrefConnect(ret);
|
||||
virObjectUnref(ret);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
@ -1428,14 +1428,16 @@ error:
|
||||
* matching virConnectClose, and all other references will be released
|
||||
* after the corresponding operation completes.
|
||||
*
|
||||
* Returns the number of remaining references on success
|
||||
* (positive implies that some other call still has a reference open,
|
||||
* 0 implies that no references remain and the connection is closed),
|
||||
* or -1 on failure. It is possible for the last virConnectClose to
|
||||
* return a positive value if some other object still has a temporary
|
||||
* reference to the connection, but the application should not try to
|
||||
* further use a connection after the virConnectClose that matches the
|
||||
* initial open.
|
||||
* Returns a positive number if at least 1 reference remains on
|
||||
* success. The returned value should not be assumed to be the total
|
||||
* reference count. A return of 0 implies no references remain and
|
||||
* the connection is closed and memory has been freed. A return of -1
|
||||
* implies a failure.
|
||||
*
|
||||
* It is possible for the last virConnectClose to return a positive
|
||||
* value if some other object still has a temporary reference to the
|
||||
* connection, but the application should not try to further use a
|
||||
* connection after the virConnectClose that matches the initial open.
|
||||
*/
|
||||
int
|
||||
virConnectClose(virConnectPtr conn)
|
||||
@ -1450,10 +1452,9 @@ virConnectClose(virConnectPtr conn)
|
||||
goto error;
|
||||
}
|
||||
|
||||
ret = virUnrefConnect(conn);
|
||||
if (ret < 0)
|
||||
goto error;
|
||||
return ret;
|
||||
if (!virObjectUnref(conn))
|
||||
return 0;
|
||||
return 1;
|
||||
|
||||
error:
|
||||
virDispatchError(NULL);
|
||||
@ -1485,10 +1486,8 @@ virConnectRef(virConnectPtr conn)
|
||||
virDispatchError(NULL);
|
||||
return -1;
|
||||
}
|
||||
virMutexLock(&conn->lock);
|
||||
VIR_DEBUG("conn=%p refs=%d", conn, conn->refs);
|
||||
conn->refs++;
|
||||
virMutexUnlock(&conn->lock);
|
||||
VIR_DEBUG("conn=%p refs=%d", conn, conn->object.refs);
|
||||
virObjectRef(conn);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -2285,10 +2284,7 @@ virDomainFree(virDomainPtr domain)
|
||||
virDispatchError(NULL);
|
||||
return -1;
|
||||
}
|
||||
if (virUnrefDomain(domain) < 0) {
|
||||
virDispatchError(NULL);
|
||||
return -1;
|
||||
}
|
||||
virObjectUnref(domain);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -2317,10 +2313,9 @@ virDomainRef(virDomainPtr domain)
|
||||
virDispatchError(NULL);
|
||||
return -1;
|
||||
}
|
||||
virMutexLock(&domain->conn->lock);
|
||||
VIR_DOMAIN_DEBUG(domain, "refs=%d", domain->refs);
|
||||
domain->refs++;
|
||||
virMutexUnlock(&domain->conn->lock);
|
||||
|
||||
VIR_DOMAIN_DEBUG(domain, "refs=%d", domain->object.refs);
|
||||
virObjectRef(domain);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -10117,10 +10112,7 @@ virNetworkFree(virNetworkPtr network)
|
||||
virDispatchError(NULL);
|
||||
return -1;
|
||||
}
|
||||
if (virUnrefNetwork(network) < 0) {
|
||||
virDispatchError(NULL);
|
||||
return -1;
|
||||
}
|
||||
virObjectUnref(network);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -10149,10 +10141,8 @@ virNetworkRef(virNetworkPtr network)
|
||||
virDispatchError(NULL);
|
||||
return -1;
|
||||
}
|
||||
virMutexLock(&network->conn->lock);
|
||||
VIR_DEBUG("network=%p refs=%d", network, network->refs);
|
||||
network->refs++;
|
||||
virMutexUnlock(&network->conn->lock);
|
||||
VIR_DEBUG("network=%p refs=%d", network, network->object.refs);
|
||||
virObjectRef(network);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -11022,10 +11012,8 @@ virInterfaceRef(virInterfacePtr iface)
|
||||
virDispatchError(NULL);
|
||||
return -1;
|
||||
}
|
||||
virMutexLock(&iface->conn->lock);
|
||||
VIR_DEBUG("iface=%p refs=%d", iface, iface->refs);
|
||||
iface->refs++;
|
||||
virMutexUnlock(&iface->conn->lock);
|
||||
VIR_DEBUG("iface=%p refs=%d", iface, iface->object.refs);
|
||||
virObjectRef(iface);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -11050,10 +11038,7 @@ virInterfaceFree(virInterfacePtr iface)
|
||||
virDispatchError(NULL);
|
||||
return -1;
|
||||
}
|
||||
if (virUnrefInterface(iface) < 0) {
|
||||
virDispatchError(NULL);
|
||||
return -1;
|
||||
}
|
||||
virObjectUnref(iface);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -11959,10 +11944,7 @@ virStoragePoolFree(virStoragePoolPtr pool)
|
||||
virDispatchError(NULL);
|
||||
return -1;
|
||||
}
|
||||
if (virUnrefStoragePool(pool) < 0) {
|
||||
virDispatchError(NULL);
|
||||
return -1;
|
||||
}
|
||||
virObjectUnref(pool);
|
||||
return 0;
|
||||
|
||||
}
|
||||
@ -11993,10 +11975,8 @@ virStoragePoolRef(virStoragePoolPtr pool)
|
||||
virDispatchError(NULL);
|
||||
return -1;
|
||||
}
|
||||
virMutexLock(&pool->conn->lock);
|
||||
VIR_DEBUG("pool=%p refs=%d", pool, pool->refs);
|
||||
pool->refs++;
|
||||
virMutexUnlock(&pool->conn->lock);
|
||||
VIR_DEBUG("pool=%p refs=%d", pool, pool->object.refs);
|
||||
virObjectRef(pool);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -13025,10 +13005,7 @@ virStorageVolFree(virStorageVolPtr vol)
|
||||
virDispatchError(NULL);
|
||||
return -1;
|
||||
}
|
||||
if (virUnrefStorageVol(vol) < 0) {
|
||||
virDispatchError(NULL);
|
||||
return -1;
|
||||
}
|
||||
virObjectUnref(vol);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -13058,10 +13035,8 @@ virStorageVolRef(virStorageVolPtr vol)
|
||||
virDispatchError(NULL);
|
||||
return -1;
|
||||
}
|
||||
virMutexLock(&vol->conn->lock);
|
||||
VIR_DEBUG("vol=%p refs=%d", vol, vol->refs);
|
||||
vol->refs++;
|
||||
virMutexUnlock(&vol->conn->lock);
|
||||
VIR_DEBUG("vol=%p refs=%d", vol, vol->object.refs);
|
||||
virObjectRef(vol);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -13600,10 +13575,7 @@ int virNodeDeviceFree(virNodeDevicePtr dev)
|
||||
virDispatchError(NULL);
|
||||
return -1;
|
||||
}
|
||||
if (virUnrefNodeDevice(dev) < 0) {
|
||||
virDispatchError(NULL);
|
||||
return -1;
|
||||
}
|
||||
virObjectUnref(dev);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -13633,10 +13605,8 @@ virNodeDeviceRef(virNodeDevicePtr dev)
|
||||
virDispatchError(NULL);
|
||||
return -1;
|
||||
}
|
||||
virMutexLock(&dev->conn->lock);
|
||||
VIR_DEBUG("dev=%p refs=%d", dev, dev->refs);
|
||||
dev->refs++;
|
||||
virMutexUnlock(&dev->conn->lock);
|
||||
VIR_DEBUG("dev=%p refs=%d", dev, dev->object.refs);
|
||||
virObjectRef(dev);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -14606,10 +14576,8 @@ virSecretRef(virSecretPtr secret)
|
||||
virDispatchError(NULL);
|
||||
return -1;
|
||||
}
|
||||
virMutexLock(&secret->conn->lock);
|
||||
VIR_DEBUG("secret=%p refs=%d", secret, secret->refs);
|
||||
secret->refs++;
|
||||
virMutexUnlock(&secret->conn->lock);
|
||||
VIR_DEBUG("secret=%p refs=%d", secret, secret->object.refs);
|
||||
virObjectRef(secret);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -14633,10 +14601,7 @@ virSecretFree(virSecretPtr secret)
|
||||
virDispatchError(NULL);
|
||||
return -1;
|
||||
}
|
||||
if (virUnrefSecret(secret) < 0) {
|
||||
virDispatchError(NULL);
|
||||
return -1;
|
||||
}
|
||||
virObjectUnref(secret);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -14705,10 +14670,8 @@ virStreamRef(virStreamPtr stream)
|
||||
virDispatchError(NULL);
|
||||
return -1;
|
||||
}
|
||||
virMutexLock(&stream->conn->lock);
|
||||
VIR_DEBUG("stream=%p refs=%d", stream, stream->refs);
|
||||
stream->refs++;
|
||||
virMutexUnlock(&stream->conn->lock);
|
||||
VIR_DEBUG("stream=%p refs=%d", stream, stream->object.refs);
|
||||
virObjectRef(stream);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -15349,10 +15312,7 @@ int virStreamFree(virStreamPtr stream)
|
||||
|
||||
/* XXX Enforce shutdown before free'ing resources ? */
|
||||
|
||||
if (virUnrefStream(stream) < 0) {
|
||||
virDispatchError(NULL);
|
||||
return -1;
|
||||
}
|
||||
virObjectUnref(stream);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -15813,10 +15773,8 @@ virNWFilterFree(virNWFilterPtr nwfilter)
|
||||
virDispatchError(NULL);
|
||||
return -1;
|
||||
}
|
||||
if (virUnrefNWFilter(nwfilter) < 0) {
|
||||
virDispatchError(NULL);
|
||||
return -1;
|
||||
}
|
||||
|
||||
virObjectUnref(nwfilter);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -16072,10 +16030,8 @@ virNWFilterRef(virNWFilterPtr nwfilter)
|
||||
virDispatchError(NULL);
|
||||
return -1;
|
||||
}
|
||||
virMutexLock(&nwfilter->conn->lock);
|
||||
VIR_DEBUG("nwfilter=%p refs=%d", nwfilter, nwfilter->refs);
|
||||
nwfilter->refs++;
|
||||
virMutexUnlock(&nwfilter->conn->lock);
|
||||
VIR_DEBUG("nwfilter=%p refs=%d", nwfilter, nwfilter->object.refs);
|
||||
virObjectRef(nwfilter);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -17959,10 +17915,8 @@ virDomainSnapshotRef(virDomainSnapshotPtr snapshot)
|
||||
virDispatchError(NULL);
|
||||
return -1;
|
||||
}
|
||||
virMutexLock(&snapshot->domain->conn->lock);
|
||||
VIR_DEBUG("snapshot=%p, refs=%d", snapshot, snapshot->refs);
|
||||
snapshot->refs++;
|
||||
virMutexUnlock(&snapshot->domain->conn->lock);
|
||||
VIR_DEBUG("snapshot=%p, refs=%d", snapshot, snapshot->object.refs);
|
||||
virObjectRef(snapshot);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -17988,10 +17942,7 @@ virDomainSnapshotFree(virDomainSnapshotPtr snapshot)
|
||||
virDispatchError(NULL);
|
||||
return -1;
|
||||
}
|
||||
if (virUnrefDomainSnapshot(snapshot) < 0) {
|
||||
virDispatchError(NULL);
|
||||
return -1;
|
||||
}
|
||||
virObjectUnref(snapshot);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -194,6 +194,9 @@ virCPUModeTypeToString;
|
||||
|
||||
|
||||
# datatypes.h
|
||||
virConnectClass;
|
||||
virDomainClass;
|
||||
virDomainSnapshotClass;
|
||||
virGetConnect;
|
||||
virGetDomain;
|
||||
virGetDomainSnapshot;
|
||||
@ -205,12 +208,14 @@ virGetSecret;
|
||||
virGetStoragePool;
|
||||
virGetStorageVol;
|
||||
virGetStream;
|
||||
virUnrefConnect;
|
||||
virUnrefDomain;
|
||||
virUnrefNWFilter;
|
||||
virUnrefSecret;
|
||||
virUnrefStorageVol;
|
||||
virUnrefStream;
|
||||
virInterfaceClass;
|
||||
virNetworkClass;
|
||||
virNodeDeviceClass;
|
||||
virNWFilterClass;
|
||||
virSecretClass;
|
||||
virStoragePoolClass;
|
||||
virStorageVolClass;
|
||||
virStreamClass;
|
||||
|
||||
|
||||
# dnsmasq.h
|
||||
|
@ -1600,14 +1600,14 @@ parallelsCreateVm(virConnectPtr conn, virDomainDefPtr def)
|
||||
goto error2;
|
||||
|
||||
virStoragePoolObjUnlock(pool);
|
||||
virUnrefStorageVol(vol);
|
||||
virObjectUnref(vol);
|
||||
|
||||
return 0;
|
||||
|
||||
error2:
|
||||
virStoragePoolObjUnlock(pool);
|
||||
error:
|
||||
virUnrefStorageVol(vol);
|
||||
virObjectUnref(vol);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -2085,7 +2085,7 @@ phypStorageVolCreateXML(virStoragePoolPtr pool,
|
||||
/* checking if this name already exists on this system */
|
||||
if ((dup_vol = phypVolumeLookupByName(pool, voldef->name)) != NULL) {
|
||||
VIR_ERROR(_("StoragePool name already exists."));
|
||||
virUnrefStorageVol(dup_vol);
|
||||
virObjectUnref(dup_vol);
|
||||
goto err;
|
||||
}
|
||||
|
||||
@ -2121,8 +2121,7 @@ err:
|
||||
VIR_FREE(key);
|
||||
virStorageVolDefFree(voldef);
|
||||
virStoragePoolDefFree(spdef);
|
||||
if (vol)
|
||||
virUnrefStorageVol(vol);
|
||||
virObjectUnref(vol);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -2321,8 +2320,7 @@ phypVolumeGetXMLDesc(virStorageVolPtr vol, unsigned int flags)
|
||||
VIR_FREE(voldef.key);
|
||||
|
||||
cleanup:
|
||||
if (sp)
|
||||
virUnrefStoragePool(sp);
|
||||
virObjectUnref(sp);
|
||||
return xml;
|
||||
}
|
||||
|
||||
@ -2718,14 +2716,14 @@ phypStoragePoolCreateXML(virConnectPtr conn,
|
||||
/* checking if this name already exists on this system */
|
||||
if ((dup_sp = phypStoragePoolLookupByName(conn, def->name)) != NULL) {
|
||||
VIR_WARN("StoragePool name already exists.");
|
||||
virUnrefStoragePool(dup_sp);
|
||||
virObjectUnref(dup_sp);
|
||||
goto err;
|
||||
}
|
||||
|
||||
/* checking if ID or UUID already exists on this system */
|
||||
if ((dup_sp = phypGetStoragePoolLookUpByUUID(conn, def->uuid)) != NULL) {
|
||||
VIR_WARN("StoragePool uuid already exists.");
|
||||
virUnrefStoragePool(dup_sp);
|
||||
virObjectUnref(dup_sp);
|
||||
goto err;
|
||||
}
|
||||
|
||||
@ -2739,8 +2737,7 @@ phypStoragePoolCreateXML(virConnectPtr conn,
|
||||
|
||||
err:
|
||||
virStoragePoolDefFree(def);
|
||||
if (sp)
|
||||
virUnrefStoragePool(sp);
|
||||
virObjectUnref(sp);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -3685,8 +3682,7 @@ phypDomainCreateAndStart(virConnectPtr conn,
|
||||
|
||||
err:
|
||||
virDomainDefFree(def);
|
||||
if (dom)
|
||||
virUnrefDomain(dom);
|
||||
virObjectUnref(dom);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -1896,8 +1896,7 @@ qemuBuildRBDString(virConnectPtr conn,
|
||||
|
||||
cleanup:
|
||||
VIR_FREE(secret);
|
||||
if (sec)
|
||||
virUnrefSecret(sec);
|
||||
virObjectUnref(sec);
|
||||
|
||||
return ret;
|
||||
|
||||
|
@ -2285,14 +2285,13 @@ finish:
|
||||
|
||||
cleanup:
|
||||
if (ddomain) {
|
||||
virUnrefDomain(ddomain);
|
||||
virObjectUnref(ddomain);
|
||||
ret = 0;
|
||||
} else {
|
||||
ret = -1;
|
||||
}
|
||||
|
||||
if (st)
|
||||
virUnrefStream(st);
|
||||
virObjectUnref(st);
|
||||
|
||||
if (orig_err) {
|
||||
virSetError(orig_err);
|
||||
@ -2479,14 +2478,13 @@ finish:
|
||||
|
||||
cleanup:
|
||||
if (ddomain) {
|
||||
virUnrefDomain(ddomain);
|
||||
virObjectUnref(ddomain);
|
||||
ret = 0;
|
||||
} else {
|
||||
ret = -1;
|
||||
}
|
||||
|
||||
if (st)
|
||||
virUnrefStream(st);
|
||||
virObjectUnref(st);
|
||||
|
||||
if (orig_err) {
|
||||
virSetError(orig_err);
|
||||
|
@ -447,7 +447,7 @@ qemuProcessGetVolumeQcowPassphrase(virConnectPtr conn,
|
||||
goto cleanup;
|
||||
data = conn->secretDriver->getValue(secret, &size, 0,
|
||||
VIR_SECRET_GET_VALUE_INTERNAL_CALL);
|
||||
virUnrefSecret(secret);
|
||||
virObjectUnref(secret);
|
||||
if (data == NULL)
|
||||
goto cleanup;
|
||||
|
||||
|
@ -1398,8 +1398,7 @@ storageVolumeCreateXML(virStoragePoolPtr obj,
|
||||
voldef = NULL;
|
||||
|
||||
cleanup:
|
||||
if (volobj)
|
||||
virUnrefStorageVol(volobj);
|
||||
virObjectUnref(volobj);
|
||||
virStorageVolDefFree(voldef);
|
||||
if (pool)
|
||||
virStoragePoolObjUnlock(pool);
|
||||
@ -1560,8 +1559,7 @@ storageVolumeCreateXMLFrom(virStoragePoolPtr obj,
|
||||
volobj = NULL;
|
||||
|
||||
cleanup:
|
||||
if (volobj)
|
||||
virUnrefStorageVol(volobj);
|
||||
virObjectUnref(volobj);
|
||||
virStorageVolDefFree(newvol);
|
||||
if (pool)
|
||||
virStoragePoolObjUnlock(pool);
|
||||
|
@ -1204,7 +1204,7 @@ static virDomainPtr vboxDomainCreateXML(virConnectPtr conn, const char *xml,
|
||||
|
||||
if (vboxDomainCreate(dom) < 0) {
|
||||
vboxDomainUndefineFlags(dom, 0);
|
||||
virUnrefDomain(dom);
|
||||
virObjectUnref(dom);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -1236,8 +1236,7 @@ sexpr_to_domain(virConnectPtr conn, const struct sexpr *root)
|
||||
error:
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
"%s", _("failed to parse Xend domain information"));
|
||||
if (ret != NULL)
|
||||
virUnrefDomain(ret);
|
||||
virObjectUnref(ret);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -2600,7 +2599,7 @@ xenDaemonCreateXML(virConnectPtr conn, const char *xmlDesc,
|
||||
/* Make sure we don't leave a still-born domain around */
|
||||
if (dom != NULL) {
|
||||
xenDaemonDomainDestroyFlags(dom, 0);
|
||||
virUnrefDomain(dom);
|
||||
virObjectUnref(dom);
|
||||
}
|
||||
virDomainDefFree(def);
|
||||
return NULL;
|
||||
|
@ -40,23 +40,12 @@ fakeSecretLookupByUsage(virConnectPtr conn,
|
||||
int usageType ATTRIBUTE_UNUSED,
|
||||
const char *usageID)
|
||||
{
|
||||
virSecretPtr ret = NULL;
|
||||
int err;
|
||||
unsigned char uuid[VIR_UUID_BUFLEN];
|
||||
if (STRNEQ(usageID, "mycluster_myname"))
|
||||
return NULL;
|
||||
err = VIR_ALLOC(ret);
|
||||
if (err < 0)
|
||||
return NULL;
|
||||
ret->magic = VIR_SECRET_MAGIC;
|
||||
ret->refs = 1;
|
||||
ret->usageID = strdup(usageID);
|
||||
if (!ret->usageID) {
|
||||
VIR_FREE(ret);
|
||||
return NULL;
|
||||
}
|
||||
ret->conn = conn;
|
||||
conn->refs++;
|
||||
return ret;
|
||||
|
||||
virUUIDGenerate(uuid);
|
||||
return virGetSecret(conn, uuid, usageType, usageID);
|
||||
}
|
||||
|
||||
static int
|
||||
@ -239,7 +228,7 @@ out:
|
||||
VIR_FREE(actualargv);
|
||||
virCommandFree(cmd);
|
||||
virDomainDefFree(vmdef);
|
||||
virUnrefConnect(conn);
|
||||
virObjectUnref(conn);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -157,7 +157,7 @@ static int testCompareXMLToArgvFiles(const char *xml,
|
||||
VIR_FREE(actualargv);
|
||||
virCommandFree(cmd);
|
||||
virDomainDefFree(vmdef);
|
||||
virUnrefConnect(conn);
|
||||
virObjectUnref(conn);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -71,8 +71,7 @@ testCompareFiles(const char *xml, const char *sexpr, int xendConfigVersion)
|
||||
VIR_FREE(sexprData);
|
||||
VIR_FREE(gotxml);
|
||||
virDomainDefFree(def);
|
||||
if (conn)
|
||||
virUnrefConnect(conn);
|
||||
virObjectUnref(conn);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
@ -93,7 +93,7 @@ testCompareParseXML(const char *xmcfg, const char *xml, int xendConfigVersion)
|
||||
if (conf)
|
||||
virConfFree(conf);
|
||||
virDomainDefFree(def);
|
||||
virUnrefConnect(conn);
|
||||
virObjectUnref(conn);
|
||||
|
||||
return ret;
|
||||
}
|
||||
@ -147,7 +147,7 @@ testCompareFormatXML(const char *xmcfg, const char *xml, int xendConfigVersion)
|
||||
VIR_FREE(xmcfgData);
|
||||
VIR_FREE(gotxml);
|
||||
virDomainDefFree(def);
|
||||
virUnrefConnect(conn);
|
||||
virObjectUnref(conn);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user