diff --git a/src/conf/nwfilter_ipaddrmap.c b/src/conf/nwfilter_ipaddrmap.c index 9cbad49c747e50842da31e8e47ec7fb35fdf12d2..4bb6775e2c926e02e882963cefc377aa28c59d32 100644 --- a/src/conf/nwfilter_ipaddrmap.c +++ b/src/conf/nwfilter_ipaddrmap.c @@ -33,7 +33,7 @@ #define VIR_FROM_THIS VIR_FROM_NWFILTER -static virMutex ipAddressMapLock; +static virMutex ipAddressMapLock = VIR_MUTEX_INITIALIZER; static virNWFilterHashTablePtr ipAddressMap; @@ -147,11 +147,6 @@ virNWFilterIPAddrMapInit(void) if (!ipAddressMap) return -1; - if (virMutexInit(&ipAddressMapLock) < 0) { - virNWFilterIPAddrMapShutdown(); - return -1; - } - return 0; } diff --git a/src/lxc/lxc_controller.c b/src/lxc/lxc_controller.c index 1d3a74b33d47c0b21d689888713c71f70d3ad741..c05dfec6428cad927cd5751004a4f3afc67899de 100644 --- a/src/lxc/lxc_controller.c +++ b/src/lxc/lxc_controller.c @@ -823,7 +823,7 @@ static int lxcControllerClearCapabilities(void) } static bool wantReboot = false; -static virMutex lock; +static virMutex lock = VIR_MUTEX_INITIALIZER; static void virLXCControllerSignalChildIO(virNetServerPtr server, @@ -1108,9 +1108,6 @@ static int virLXCControllerMain(virLXCControllerPtr ctrl) int rc = -1; size_t i; - if (virMutexInit(&lock) < 0) - goto cleanup2; - if (virNetServerAddSignalHandler(ctrl->server, SIGCHLD, virLXCControllerSignalChildIO, @@ -1164,9 +1161,6 @@ static int virLXCControllerMain(virLXCControllerPtr ctrl) rc = wantReboot ? 1 : 0; cleanup: - virMutexDestroy(&lock); - cleanup2: - for (i = 0; i < ctrl->nconsoles; i++) virLXCControllerConsoleClose(&(ctrl->consoles[i])); diff --git a/src/nwfilter/nwfilter_ebiptables_driver.c b/src/nwfilter/nwfilter_ebiptables_driver.c index 8dbab185520d8f6a5e18331b3edadcdb7d283e1d..ce0b7e3568f51cfa0dac043d6e750ec153c59e84 100644 --- a/src/nwfilter/nwfilter_ebiptables_driver.c +++ b/src/nwfilter/nwfilter_ebiptables_driver.c @@ -211,7 +211,7 @@ static void ebiptablesDriverShutdown(void); static void ebtablesCleanAll(const char *ifname); static int ebiptablesAllTeardown(const char *ifname); -static virMutex execCLIMutex; +static virMutex execCLIMutex = VIR_MUTEX_INITIALIZER; struct ushort_map { unsigned short attr; @@ -4376,9 +4376,6 @@ ebiptablesDriverInit(bool privileged) if (!privileged) return 0; - if (virMutexInit(&execCLIMutex) < 0) - return -EINVAL; - grep_cmd_path = virFindFileInPath("grep"); /* diff --git a/src/nwfilter/nwfilter_learnipaddr.c b/src/nwfilter/nwfilter_learnipaddr.c index 1ffed7838f2234f98352221de7f6c067cad06402..a6cdc87d8f08f67f1ab332d29b8b66b2c28493dc 100644 --- a/src/nwfilter/nwfilter_learnipaddr.c +++ b/src/nwfilter/nwfilter_learnipaddr.c @@ -119,10 +119,10 @@ struct ether_vlan_header } ATTRIBUTE_PACKED; -static virMutex pendingLearnReqLock; +static virMutex pendingLearnReqLock = VIR_MUTEX_INITIALIZER; static virHashTablePtr pendingLearnReq; -static virMutex ifaceMapLock; +static virMutex ifaceMapLock = VIR_MUTEX_INITIALIZER; static virHashTablePtr ifaceLockMap; typedef struct _virNWFilterIfaceLock virNWFilterIfaceLock; @@ -806,22 +806,12 @@ virNWFilterLearnInit(void) return -1; } - if (virMutexInit(&pendingLearnReqLock) < 0) { - virNWFilterLearnShutdown(); - return -1; - } - ifaceLockMap = virHashCreate(0, virHashValueFree); if (!ifaceLockMap) { virNWFilterLearnShutdown(); return -1; } - if (virMutexInit(&ifaceMapLock) < 0) { - virNWFilterLearnShutdown(); - return -1; - } - return 0; } diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 77e30b29c42d138fdc8efbdcc2b0628bd5e741aa..64f3daaeb15fedeef9261d92b2530d4fa0f39148 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -119,7 +119,7 @@ typedef struct _testConn *testConnPtr; static testConn defaultConn; static int defaultConnections; -static virMutex defaultLock; +static virMutex defaultLock = VIR_MUTEX_INITIALIZER; #define TEST_MODEL "i686" #define TEST_MODEL_WORDSIZE 32 @@ -141,15 +141,6 @@ static int testConnectClose(virConnectPtr conn); static void testObjectEventQueue(testConnPtr driver, virObjectEventPtr event); -static int -testOnceInit(void) -{ - return virMutexInit(&defaultLock); -} - -VIR_ONCE_GLOBAL_INIT(test) - - static void testDriverLock(testConnPtr driver) { virMutexLock(&driver->lock); @@ -1554,9 +1545,6 @@ static virDrvOpenStatus testConnectOpen(virConnectPtr conn, virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR); - if (testInitialize() < 0) - return VIR_DRV_OPEN_ERROR; - if (!conn->uri) return VIR_DRV_OPEN_DECLINED; @@ -1596,9 +1584,6 @@ static int testConnectClose(virConnectPtr conn) { testConnPtr privconn = conn->privateData; - if (testInitialize() < 0) - return -1; - if (privconn == &defaultConn) { virMutexLock(&defaultLock); if (--defaultConnections) { diff --git a/src/util/virnetdevmacvlan.c b/src/util/virnetdevmacvlan.c index 42313b708a2841a7a6e2e1c6dd592f7a7c2a4eb0..7bbf5406091a2121f70534112338345d6e42a837 100644 --- a/src/util/virnetdevmacvlan.c +++ b/src/util/virnetdevmacvlan.c @@ -73,18 +73,7 @@ VIR_LOG_INIT("util.netdevmacvlan"); # define MACVLAN_NAME_PREFIX "macvlan" # define MACVLAN_NAME_PATTERN "macvlan%d" -virMutex virNetDevMacVLanCreateMutex; - -static int virNetDevMacVLanCreateMutexOnceInit(void) -{ - if (virMutexInit(&virNetDevMacVLanCreateMutex) < 0) { - virReportSystemError(errno, "%s", _("unable to init mutex")); - return -1; - } - return 0; -} - -VIR_ONCE_GLOBAL_INIT(virNetDevMacVLanCreateMutex); +virMutex virNetDevMacVLanCreateMutex = VIR_MUTEX_INITIALIZER; /** * virNetDevMacVLanCreate: @@ -873,8 +862,6 @@ int virNetDevMacVLanCreateWithVPortProfile(const char *tgifname, } else { create_name: retries = 5; - if (virNetDevMacVLanCreateMutexInitialize() < 0) - return -1; virMutexLock(&virNetDevMacVLanCreateMutex); for (c = 0; c < 8192; c++) { snprintf(ifname, sizeof(ifname), pattern, c); diff --git a/src/util/virnetdevveth.c b/src/util/virnetdevveth.c index 14febb7c39e09efd921bd23c78d41c68feec3cee..e9d6f9c514d4e4566ea16f8277726b0136693a11 100644 --- a/src/util/virnetdevveth.c +++ b/src/util/virnetdevveth.c @@ -41,18 +41,7 @@ VIR_LOG_INIT("util.netdevveth"); /* Functions */ -virMutex virNetDevVethCreateMutex; - -static int virNetDevVethCreateMutexOnceInit(void) -{ - if (virMutexInit(&virNetDevVethCreateMutex) < 0) { - virReportSystemError(errno, "%s", _("unable to init mutex")); - return -1; - } - return 0; -} - -VIR_ONCE_GLOBAL_INIT(virNetDevVethCreateMutex); +virMutex virNetDevVethCreateMutex = VIR_MUTEX_INITIALIZER; static int virNetDevVethExists(int devNum) { @@ -132,9 +121,6 @@ int virNetDevVethCreate(char** veth1, char** veth2) * We might race with other containers, but this is reasonably * unlikely, so don't do too many retries for device creation */ - if (virNetDevVethCreateMutexInitialize() < 0) - return -1; - virMutexLock(&virNetDevVethCreateMutex); #define MAX_VETH_RETRIES 10 diff --git a/src/util/virnodesuspend.c b/src/util/virnodesuspend.c index 8088931ecc6604b3853d0b9132c0e16edfa65a0b..08c47aa20f18a7d92908d4978b10695c07c30ebe 100644 --- a/src/util/virnodesuspend.c +++ b/src/util/virnodesuspend.c @@ -46,7 +46,7 @@ VIR_LOG_INIT("util.nodesuspend"); static unsigned int nodeSuspendTargetMask; static bool nodeSuspendTargetMaskInit; -static virMutex virNodeSuspendMutex; +static virMutex virNodeSuspendMutex = VIR_MUTEX_INITIALIZER; static bool aboutToSuspend; @@ -61,20 +61,6 @@ static void virNodeSuspendUnlock(void) } -static int virNodeSuspendOnceInit(void) -{ - if (virMutexInit(&virNodeSuspendMutex) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Unable to initialize mutex")); - return -1; - } - - return 0; -} - -VIR_ONCE_GLOBAL_INIT(virNodeSuspend) - - /** * virNodeSuspendSetNodeWakeup: * @alarmTime: time in seconds from now, at which the RTC alarm has to be set. @@ -178,9 +164,6 @@ int nodeSuspendForDuration(unsigned int target, virCheckFlags(0, -1); - if (virNodeSuspendInitialize() < 0) - return -1; - if (virNodeSuspendGetTargetMask(&supported) < 0) return -1; @@ -267,9 +250,6 @@ virNodeSuspendSupportsTarget(unsigned int target, bool *supported) int status; int ret = -1; - if (virNodeSuspendInitialize() < 0) - return -1; - *supported = false; switch (target) { diff --git a/src/util/virrandom.c b/src/util/virrandom.c index 3f17f5e11f96b99cef0e40ef57a03ab6707f0ebc..4301f3f3d6fc4eb0c7dd64fa1d1faf24da07673c 100644 --- a/src/util/virrandom.c +++ b/src/util/virrandom.c @@ -56,7 +56,7 @@ enum { static char randomState[RANDOM_STATE_SIZE]; static struct random_data randomData; -static virMutex randomLock; +static virMutex randomLock = VIR_MUTEX_INITIALIZER; static int @@ -74,9 +74,6 @@ virRandomOnceInit(void) return -1; #endif - if (virMutexInit(&randomLock) < 0) - return -1; - if (initstate_r(seed, randomState, sizeof(randomState), diff --git a/src/util/virthread.h b/src/util/virthread.h index eba8dc369ca1e4c25a886404551371226c89ec84..4b92a43c629ea7181aee69128f587b9860a73370 100644 --- a/src/util/virthread.h +++ b/src/util/virthread.h @@ -71,6 +71,11 @@ struct virOnceControl { }; +# define VIR_MUTEX_INITIALIZER \ + { \ + .lock = PTHREAD_MUTEX_INITIALIZER \ + } + # define VIR_ONCE_CONTROL_INITIALIZER \ { \ .once = PTHREAD_ONCE_INIT \