From patchwork Thu Jun 23 00:12:11 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cole Robinson X-Patchwork-Id: 70704 Delivered-To: patch@linaro.org Received: by 10.140.28.4 with SMTP id 4csp167585qgy; Wed, 22 Jun 2016 17:15:14 -0700 (PDT) X-Received: by 10.194.105.41 with SMTP id gj9mr16771810wjb.22.1466640914641; Wed, 22 Jun 2016 17:15:14 -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 d66si2143513wme.81.2016.06.22.17.15.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 22 Jun 2016 17:15:14 -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 u5N0Cb9h011002; Wed, 22 Jun 2016 20:12:37 -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 u5N0CJ3c003790 for ; Wed, 22 Jun 2016 20:12:19 -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 u5N0CHC2010243; Wed, 22 Jun 2016 20:12:18 -0400 From: Cole Robinson To: libvirt-list@redhat.com Date: Wed, 22 Jun 2016 20:12:11 -0400 Message-Id: <3ffd1f7787babb3cc9c13b2eff327651e0b39fdd.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 1/6] storage: Break out storageDriverAutostartPool 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 For autostarting a single pool. Lets us exit the function early which simplifies the control flow, and it matches the pattern of storagePoolUpdateAllState --- src/storage/storage_driver.c | 84 +++++++++++++++++++++++--------------------- 1 file changed, 43 insertions(+), 41 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 e2d729f..3bdc13f 100644 --- a/src/storage/storage_driver.c +++ b/src/storage/storage_driver.c @@ -149,6 +149,48 @@ storagePoolUpdateAllState(void) } static void +storageDriverAutostartPool(virConnectPtr conn, + virStoragePoolObjPtr pool) +{ + virStorageBackendPtr backend; + char *stateFile = NULL; + + if ((backend = virStorageBackendForType(pool->def->type)) == NULL) + goto cleanup; + + if (virStoragePoolObjIsActive(pool) || !pool->autostart) + goto cleanup; + + if (backend->startPool && + backend->startPool(conn, pool) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Failed to autostart storage pool '%s': %s"), + pool->def->name, virGetLastErrorMessage()); + goto cleanup; + } + + virStoragePoolObjClearVols(pool); + stateFile = virFileBuildPath(driver->stateDir, + pool->def->name, ".xml"); + if (!stateFile || + virStoragePoolSaveState(stateFile, pool->def) < 0 || + backend->refreshPool(conn, pool) < 0) { + if (stateFile) + unlink(stateFile); + if (backend->stopPool) + backend->stopPool(conn, pool); + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Failed to autostart storage pool '%s': %s"), + pool->def->name, virGetLastErrorMessage()); + goto cleanup; + } + + pool->active = true; + cleanup: + VIR_FREE(stateFile); +} + +static void storageDriverAutostart(void) { size_t i; @@ -163,49 +205,9 @@ storageDriverAutostart(void) for (i = 0; i < driver->pools.count; i++) { virStoragePoolObjPtr pool = driver->pools.objs[i]; - virStorageBackendPtr backend; - bool started = false; virStoragePoolObjLock(pool); - if ((backend = virStorageBackendForType(pool->def->type)) == NULL) { - virStoragePoolObjUnlock(pool); - continue; - } - - if (pool->autostart && - !virStoragePoolObjIsActive(pool)) { - if (backend->startPool && - backend->startPool(conn, pool) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Failed to autostart storage pool '%s': %s"), - pool->def->name, virGetLastErrorMessage()); - virStoragePoolObjUnlock(pool); - continue; - } - started = true; - } - - if (started) { - char *stateFile; - - virStoragePoolObjClearVols(pool); - stateFile = virFileBuildPath(driver->stateDir, - pool->def->name, ".xml"); - if (!stateFile || - virStoragePoolSaveState(stateFile, pool->def) < 0 || - backend->refreshPool(conn, pool) < 0) { - if (stateFile) - unlink(stateFile); - if (backend->stopPool) - backend->stopPool(conn, pool); - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Failed to autostart storage pool '%s': %s"), - pool->def->name, virGetLastErrorMessage()); - } else { - pool->active = true; - } - VIR_FREE(stateFile); - } + storageDriverAutostartPool(conn, pool); virStoragePoolObjUnlock(pool); }