diff --git a/daemon/event.c b/daemon/event.c index 06f9aad0e322078c14b93e687326cb8a82226cb8..a983b353e6a724818d3ec24d7016c6c28ed43622 100644 --- a/daemon/event.c +++ b/daemon/event.c @@ -73,11 +73,11 @@ struct virEventLoop { int running; virThread leader; int wakeupfd[2]; - int handlesCount; - int handlesAlloc; + size_t handlesCount; + size_t handlesAlloc; struct virEventHandle *handles; - int timeoutsCount; - int timeoutsAlloc; + size_t timeoutsCount; + size_t timeoutsAlloc; struct virEventTimeout *timeouts; }; @@ -103,14 +103,13 @@ int virEventAddHandleImpl(int fd, int events, EVENT_DEBUG("Add handle fd=%d events=%d cb=%p opaque=%p", fd, events, cb, opaque); virMutexLock(&eventLoop.lock); if (eventLoop.handlesCount == eventLoop.handlesAlloc) { - EVENT_DEBUG("Used %d handle slots, adding %d more", + EVENT_DEBUG("Used %zu handle slots, adding at least %d more", eventLoop.handlesAlloc, EVENT_ALLOC_EXTENT); - if (VIR_REALLOC_N(eventLoop.handles, - (eventLoop.handlesAlloc + EVENT_ALLOC_EXTENT)) < 0) { + if (VIR_RESIZE_N(eventLoop.handles, eventLoop.handlesAlloc, + eventLoop.handlesCount, EVENT_ALLOC_EXTENT) < 0) { virMutexUnlock(&eventLoop.lock); return -1; } - eventLoop.handlesAlloc += EVENT_ALLOC_EXTENT; } watch = nextWatch++; @@ -204,14 +203,13 @@ int virEventAddTimeoutImpl(int frequency, virMutexLock(&eventLoop.lock); if (eventLoop.timeoutsCount == eventLoop.timeoutsAlloc) { - EVENT_DEBUG("Used %d timeout slots, adding %d more", + EVENT_DEBUG("Used %zu timeout slots, adding at least %d more", eventLoop.timeoutsAlloc, EVENT_ALLOC_EXTENT); - if (VIR_REALLOC_N(eventLoop.timeouts, - (eventLoop.timeoutsAlloc + EVENT_ALLOC_EXTENT)) < 0) { + if (VIR_RESIZE_N(eventLoop.timeouts, eventLoop.timeoutsAlloc, + eventLoop.timeoutsCount, EVENT_ALLOC_EXTENT) < 0) { virMutexUnlock(&eventLoop.lock); return -1; } - eventLoop.timeoutsAlloc += EVENT_ALLOC_EXTENT; } eventLoop.timeouts[eventLoop.timeoutsCount].timer = nextTimer++; @@ -301,7 +299,7 @@ int virEventRemoveTimeoutImpl(int timer) { static int virEventCalculateTimeout(int *timeout) { unsigned long long then = 0; int i; - EVENT_DEBUG("Calculate expiry of %d timers", eventLoop.timeoutsCount); + EVENT_DEBUG("Calculate expiry of %zu timers", eventLoop.timeoutsCount); /* Figure out if we need a timeout */ for (i = 0 ; i < eventLoop.timeoutsCount ; i++) { if (eventLoop.timeouts[i].frequency < 0) @@ -482,7 +480,7 @@ static int virEventDispatchHandles(int nfds, struct pollfd *fds) { */ static int virEventCleanupTimeouts(void) { int i; - DEBUG("Cleanup %d", eventLoop.timeoutsCount); + DEBUG("Cleanup %zu", eventLoop.timeoutsCount); /* Remove deleted entries, shuffling down remaining * entries as needed to form contiguous series @@ -507,12 +505,10 @@ static int virEventCleanupTimeouts(void) { /* Release some memory if we've got a big chunk free */ if ((eventLoop.timeoutsAlloc - EVENT_ALLOC_EXTENT) > eventLoop.timeoutsCount) { - EVENT_DEBUG("Releasing %d out of %d timeout slots used, releasing %d", + EVENT_DEBUG("Releasing %zu out of %zu timeout slots used, releasing %d", eventLoop.timeoutsCount, eventLoop.timeoutsAlloc, EVENT_ALLOC_EXTENT); - if (VIR_REALLOC_N(eventLoop.timeouts, - (eventLoop.timeoutsAlloc - EVENT_ALLOC_EXTENT)) < 0) - return -1; - eventLoop.timeoutsAlloc -= EVENT_ALLOC_EXTENT; + VIR_SHRINK_N(eventLoop.timeouts, eventLoop.timeoutsAlloc, + EVENT_ALLOC_EXTENT); } return 0; } @@ -523,7 +519,7 @@ static int virEventCleanupTimeouts(void) { */ static int virEventCleanupHandles(void) { int i; - DEBUG("Cleanupo %d", eventLoop.handlesCount); + DEBUG("Cleanup %zu", eventLoop.handlesCount); /* Remove deleted entries, shuffling down remaining * entries as needed to form contiguous series @@ -547,12 +543,10 @@ static int virEventCleanupHandles(void) { /* Release some memory if we've got a big chunk free */ if ((eventLoop.handlesAlloc - EVENT_ALLOC_EXTENT) > eventLoop.handlesCount) { - EVENT_DEBUG("Releasing %d out of %d handles slots used, releasing %d", + EVENT_DEBUG("Releasing %zu out of %zu handles slots used, releasing %d", eventLoop.handlesCount, eventLoop.handlesAlloc, EVENT_ALLOC_EXTENT); - if (VIR_REALLOC_N(eventLoop.handles, - (eventLoop.handlesAlloc - EVENT_ALLOC_EXTENT)) < 0) - return -1; - eventLoop.handlesAlloc -= EVENT_ALLOC_EXTENT; + VIR_SHRINK_N(eventLoop.handles, eventLoop.handlesAlloc, + EVENT_ALLOC_EXTENT); } return 0; } diff --git a/daemon/libvirtd.c b/daemon/libvirtd.c index 1673e91d6720eae488a42af4f8f8fb9d89c64d6f..e544c482d146500c0a4ef2d57b2e1c0bca29a90e 100644 --- a/daemon/libvirtd.c +++ b/daemon/libvirtd.c @@ -1333,7 +1333,8 @@ static int qemudDispatchServer(struct qemud_server *server, struct qemud_socket goto error; } - if (VIR_REALLOC_N(server->clients, server->nclients+1) < 0) { + if (VIR_RESIZE_N(server->clients, server->nclients_max, + server->nclients, 1) < 0) { VIR_ERROR0(_("Out of memory allocating clients")); goto error; } @@ -2361,10 +2362,7 @@ static void *qemudRunLoop(void *opaque) { server->clients + i + 1, sizeof (*server->clients) * (server->nclients - i)); - if (VIR_REALLOC_N(server->clients, - server->nclients) < 0) { - ; /* ignore */ - } + VIR_SHRINK_N(server->clients, server->nclients, 0); goto reprocess; } } diff --git a/daemon/libvirtd.h b/daemon/libvirtd.h index 785ac07c235f9608b4fbd97d8194ca1def6ecaea..af20e565e71404e6162db28032cb184e57dd51aa 100644 --- a/daemon/libvirtd.h +++ b/daemon/libvirtd.h @@ -1,7 +1,7 @@ /* * libvirtd.h: daemon data structure definitions * - * Copyright (C) 2006-2009 Red Hat, Inc. + * Copyright (C) 2006-2010 Red Hat, Inc. * Copyright (C) 2006 Daniel P. Berrange * * This library is free software; you can redistribute it and/or @@ -283,12 +283,13 @@ struct qemud_server { int privileged; - int nworkers; - int nactiveworkers; + size_t nworkers; + size_t nactiveworkers; struct qemud_worker *workers; - int nsockets; + size_t nsockets; struct qemud_socket *sockets; - int nclients; + size_t nclients; + size_t nclients_max; struct qemud_client **clients; int sigread;