From patchwork Thu Jun 23 00:12:12 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cole Robinson X-Patchwork-Id: 70703 Delivered-To: patch@linaro.org Received: by 10.140.28.4 with SMTP id 4csp167544qgy; Wed, 22 Jun 2016 17:15:08 -0700 (PDT) X-Received: by 10.194.82.36 with SMTP id f4mr27544262wjy.104.1466640908091; Wed, 22 Jun 2016 17:15:08 -0700 (PDT) Return-Path: Received: from mx5-phx2.redhat.com (mx5-phx2.redhat.com. [209.132.183.37]) by mx.google.com with ESMTPS id w2si2943146wjm.223.2016.06.22.17.15.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 22 Jun 2016 17:15:08 -0700 (PDT) Received-SPF: pass (google.com: domain of libvir-list-bounces@redhat.com designates 209.132.183.37 as permitted sender) client-ip=209.132.183.37; Authentication-Results: mx.google.com; spf=pass (google.com: domain of libvir-list-bounces@redhat.com designates 209.132.183.37 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by mx5-phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u5N0CfCl011021; Wed, 22 Jun 2016 20:12:41 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id u5N0CKq7003798 for ; Wed, 22 Jun 2016 20:12:20 -0400 Received: from colepc.redhat.com (ovpn-116-65.rdu2.redhat.com [10.10.116.65]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u5N0CHC3010243; Wed, 22 Jun 2016 20:12:19 -0400 From: Cole Robinson To: libvirt-list@redhat.com Date: Wed, 22 Jun 2016 20:12:12 -0400 Message-Id: <731c614cd8cc8af3a6b5dc760bdb2bcbce0c7f4b.1466640165.git.crobinso@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 2/6] storage: Add storagePoolSetInactive X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com This function handles newDef assignment and transient pool removal when an object is set inactive. The return value notifies callers if the pool was removed, so they know not to try to access the pool object anymore. Some users don't gain anything from it at this point, but future patches will improve that. --- src/storage/storage_driver.c | 54 +++++++++++++++++++++++++++++++------------- 1 file changed, 38 insertions(+), 16 deletions(-) -- 2.7.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c index 3bdc13f..c7ffea8 100644 --- a/src/storage/storage_driver.c +++ b/src/storage/storage_driver.c @@ -76,6 +76,32 @@ static void storageDriverUnlock(void) virMutexUnlock(&driver->lock); } +/* + * storagePoolSetInactive: + * Helper for setting a pool object as 'inactive'. Handles reassigning + * newDef for persistent pools, and removing and freeing the object + * for transient pools. + * + * Returns true if pool was removed from driver->pools + */ +static bool +storagePoolSetInactive(virStoragePoolObjPtr pool) +{ + bool ret = false; + pool->active = false; + + if (pool->configFile == NULL) { + virStoragePoolObjRemove(&driver->pools, pool); + ret = true; + } else if (pool->newDef) { + virStoragePoolDefFree(pool->def); + pool->def = pool->newDef; + pool->newDef = NULL; + } + + return ret; +} + static void storagePoolUpdateState(virStoragePoolObjPtr pool) { @@ -182,6 +208,10 @@ storageDriverAutostartPool(virConnectPtr conn, virReportError(VIR_ERR_INTERNAL_ERROR, _("Failed to autostart storage pool '%s': %s"), pool->def->name, virGetLastErrorMessage()); + + /* Don't check the return value, it should never be 'true' here + * since this function requires a non-transient pool */ + storagePoolSetInactive(pool); goto cleanup; } @@ -739,8 +769,8 @@ storagePoolCreateXML(virConnectPtr conn, unlink(stateFile); if (backend->stopPool) backend->stopPool(conn, pool); - virStoragePoolObjRemove(&driver->pools, pool); - pool = NULL; + if (storagePoolSetInactive(pool)) + pool = NULL; goto cleanup; } @@ -956,6 +986,10 @@ storagePoolCreate(virStoragePoolPtr obj, unlink(stateFile); if (backend->stopPool) backend->stopPool(obj->conn, pool); + + /* Don't check the return value, it should never be 'true' here + * since this function requires a non-transient pool */ + storagePoolSetInactive(pool); goto cleanup; } @@ -1070,16 +1104,8 @@ storagePoolDestroy(virStoragePoolPtr obj) VIR_STORAGE_POOL_EVENT_STOPPED, 0); - pool->active = false; - - if (pool->configFile == NULL) { - virStoragePoolObjRemove(&driver->pools, pool); + if (storagePoolSetInactive(pool)) pool = NULL; - } else if (pool->newDef) { - virStoragePoolDefFree(pool->def); - pool->def = pool->newDef; - pool->newDef = NULL; - } ret = 0; @@ -1199,12 +1225,8 @@ storagePoolRefresh(virStoragePoolPtr obj, pool->def->uuid, VIR_STORAGE_POOL_EVENT_STOPPED, 0); - pool->active = false; - - if (pool->configFile == NULL) { - virStoragePoolObjRemove(&driver->pools, pool); + if (storagePoolSetInactive(pool)) pool = NULL; - } goto cleanup; }