From patchwork Thu May 30 12:34:55 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 247558 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 297E92C0089 for ; Thu, 30 May 2013 22:39:55 +1000 (EST) Received: from localhost ([::1]:39038 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ui293-0005vQ-E2 for incoming@patchwork.ozlabs.org; Thu, 30 May 2013 08:39:53 -0400 Received: from eggs.gnu.org ([208.118.235.92]:43073) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ui28N-0005Kx-Em for qemu-devel@nongnu.org; Thu, 30 May 2013 08:39:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Ui28D-0007It-If for qemu-devel@nongnu.org; Thu, 30 May 2013 08:39:11 -0400 Received: from mx1.redhat.com ([209.132.183.28]:24909) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ui24n-00061f-FE for qemu-devel@nongnu.org; Thu, 30 May 2013 08:35:29 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r4UCZRAx005236 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 30 May 2013 08:35:27 -0400 Received: from localhost (ovpn-112-44.ams2.redhat.com [10.36.112.44]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r4UCZPQC018169; Thu, 30 May 2013 08:35:26 -0400 From: Stefan Hajnoczi To: Date: Thu, 30 May 2013 14:34:55 +0200 Message-Id: <1369917299-5725-8-git-send-email-stefanha@redhat.com> In-Reply-To: <1369917299-5725-1-git-send-email-stefanha@redhat.com> References: <1369917299-5725-1-git-send-email-stefanha@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Kevin Wolf , Fam Zheng , xiawenc@linux.vnet.ibm.com, imain@redhat.com, Stefan Hajnoczi , Paolo Bonzini , dietmar@proxmox.com Subject: [Qemu-devel] [PATCH v5 07/11] blockdev: rename BlkTransactionStates to singular X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org The QMP 'transaction' command keeps a list of in-flight transactions. The transaction state structure is called BlkTransactionStates even though it only deals with a single transaction. The only plural thing is the linked list of transaction states. I find it confusing to call the single structure "States". This patch renames it to "State", just like BlockDriverState is singular. Signed-off-by: Stefan Hajnoczi Reviewed-by: Eric Blake Reviewed-by: Kevin Wolf --- blockdev.c | 104 ++++++++++++++++++++++++++++++------------------------------- 1 file changed, 52 insertions(+), 52 deletions(-) diff --git a/blockdev.c b/blockdev.c index 5de33f5..94ad829 100644 --- a/blockdev.c +++ b/blockdev.c @@ -780,7 +780,7 @@ void qmp_blockdev_snapshot_sync(const char *device, const char *snapshot_file, /* New and old BlockDriverState structs for group snapshots */ -typedef struct BlkTransactionStates BlkTransactionStates; +typedef struct BlkTransactionState BlkTransactionState; /* Only prepare() may fail. In a single transaction, only one of commit() or abort() will be called, clean() will always be called if it present. */ @@ -788,13 +788,13 @@ typedef struct BdrvActionOps { /* Size of state struct, in bytes. */ size_t instance_size; /* Prepare the work, must NOT be NULL. */ - void (*prepare)(BlkTransactionStates *common, Error **errp); + void (*prepare)(BlkTransactionState *common, Error **errp); /* Commit the changes, must NOT be NULL. */ - void (*commit)(BlkTransactionStates *common); + void (*commit)(BlkTransactionState *common); /* Abort the changes on fail, can be NULL. */ - void (*abort)(BlkTransactionStates *common); + void (*abort)(BlkTransactionState *common); /* Clean up resource in the end, can be NULL. */ - void (*clean)(BlkTransactionStates *common); + void (*clean)(BlkTransactionState *common); } BdrvActionOps; /* @@ -802,20 +802,20 @@ typedef struct BdrvActionOps { * that compiler will also arrange it to the same address with parent instance. * Later it will be used in free(). */ -struct BlkTransactionStates { +struct BlkTransactionState { TransactionAction *action; const BdrvActionOps *ops; - QSIMPLEQ_ENTRY(BlkTransactionStates) entry; + QSIMPLEQ_ENTRY(BlkTransactionState) entry; }; /* external snapshot private data */ -typedef struct ExternalSnapshotStates { - BlkTransactionStates common; +typedef struct ExternalSnapshotState { + BlkTransactionState common; BlockDriverState *old_bs; BlockDriverState *new_bs; -} ExternalSnapshotStates; +} ExternalSnapshotState; -static void external_snapshot_prepare(BlkTransactionStates *common, +static void external_snapshot_prepare(BlkTransactionState *common, Error **errp) { BlockDriver *drv; @@ -825,8 +825,8 @@ static void external_snapshot_prepare(BlkTransactionStates *common, const char *new_image_file; const char *format = "qcow2"; enum NewImageMode mode = NEW_IMAGE_MODE_ABSOLUTE_PATHS; - ExternalSnapshotStates *states = - DO_UPCAST(ExternalSnapshotStates, common, common); + ExternalSnapshotState *state = + DO_UPCAST(ExternalSnapshotState, common, common); TransactionAction *action = common->action; /* get parameters */ @@ -848,36 +848,36 @@ static void external_snapshot_prepare(BlkTransactionStates *common, return; } - states->old_bs = bdrv_find(device); - if (!states->old_bs) { + state->old_bs = bdrv_find(device); + if (!state->old_bs) { error_set(errp, QERR_DEVICE_NOT_FOUND, device); return; } - if (!bdrv_is_inserted(states->old_bs)) { + if (!bdrv_is_inserted(state->old_bs)) { error_set(errp, QERR_DEVICE_HAS_NO_MEDIUM, device); return; } - if (bdrv_in_use(states->old_bs)) { + if (bdrv_in_use(state->old_bs)) { error_set(errp, QERR_DEVICE_IN_USE, device); return; } - if (!bdrv_is_read_only(states->old_bs)) { - if (bdrv_flush(states->old_bs)) { + if (!bdrv_is_read_only(state->old_bs)) { + if (bdrv_flush(state->old_bs)) { error_set(errp, QERR_IO_ERROR); return; } } - flags = states->old_bs->open_flags; + flags = state->old_bs->open_flags; /* create new image w/backing file */ if (mode != NEW_IMAGE_MODE_EXISTING) { bdrv_img_create(new_image_file, format, - states->old_bs->filename, - states->old_bs->drv->format_name, + state->old_bs->filename, + state->old_bs->drv->format_name, NULL, -1, flags, &local_err, false); if (error_is_set(&local_err)) { error_propagate(errp, local_err); @@ -886,42 +886,42 @@ static void external_snapshot_prepare(BlkTransactionStates *common, } /* We will manually add the backing_hd field to the bs later */ - states->new_bs = bdrv_new(""); + state->new_bs = bdrv_new(""); /* TODO Inherit bs->options or only take explicit options with an * extended QMP command? */ - ret = bdrv_open(states->new_bs, new_image_file, NULL, + ret = bdrv_open(state->new_bs, new_image_file, NULL, flags | BDRV_O_NO_BACKING, drv); if (ret != 0) { error_set(errp, QERR_OPEN_FILE_FAILED, new_image_file); } } -static void external_snapshot_commit(BlkTransactionStates *common) +static void external_snapshot_commit(BlkTransactionState *common) { - ExternalSnapshotStates *states = - DO_UPCAST(ExternalSnapshotStates, common, common); + ExternalSnapshotState *state = + DO_UPCAST(ExternalSnapshotState, common, common); - /* This removes our old bs from the bdrv_states, and adds the new bs */ - bdrv_append(states->new_bs, states->old_bs); + /* This removes our old bs and adds the new bs */ + bdrv_append(state->new_bs, state->old_bs); /* We don't need (or want) to use the transactional * bdrv_reopen_multiple() across all the entries at once, because we * don't want to abort all of them if one of them fails the reopen */ - bdrv_reopen(states->new_bs, states->new_bs->open_flags & ~BDRV_O_RDWR, + bdrv_reopen(state->new_bs, state->new_bs->open_flags & ~BDRV_O_RDWR, NULL); } -static void external_snapshot_abort(BlkTransactionStates *common) +static void external_snapshot_abort(BlkTransactionState *common) { - ExternalSnapshotStates *states = - DO_UPCAST(ExternalSnapshotStates, common, common); - if (states->new_bs) { - bdrv_delete(states->new_bs); + ExternalSnapshotState *state = + DO_UPCAST(ExternalSnapshotState, common, common); + if (state->new_bs) { + bdrv_delete(state->new_bs); } } static const BdrvActionOps actions[] = { [TRANSACTION_ACTION_KIND_BLOCKDEV_SNAPSHOT_SYNC] = { - .instance_size = sizeof(ExternalSnapshotStates), + .instance_size = sizeof(ExternalSnapshotState), .prepare = external_snapshot_prepare, .commit = external_snapshot_commit, .abort = external_snapshot_abort, @@ -936,10 +936,10 @@ static const BdrvActionOps actions[] = { void qmp_transaction(TransactionActionList *dev_list, Error **errp) { TransactionActionList *dev_entry = dev_list; - BlkTransactionStates *states, *next; + BlkTransactionState *state, *next; Error *local_err = NULL; - QSIMPLEQ_HEAD(snap_bdrv_states, BlkTransactionStates) snap_bdrv_states; + QSIMPLEQ_HEAD(snap_bdrv_states, BlkTransactionState) snap_bdrv_states; QSIMPLEQ_INIT(&snap_bdrv_states); /* drain all i/o before any snapshots */ @@ -956,20 +956,20 @@ void qmp_transaction(TransactionActionList *dev_list, Error **errp) assert(dev_info->kind < ARRAY_SIZE(actions)); ops = &actions[dev_info->kind]; - states = g_malloc0(ops->instance_size); - states->ops = ops; - states->action = dev_info; - QSIMPLEQ_INSERT_TAIL(&snap_bdrv_states, states, entry); + state = g_malloc0(ops->instance_size); + state->ops = ops; + state->action = dev_info; + QSIMPLEQ_INSERT_TAIL(&snap_bdrv_states, state, entry); - states->ops->prepare(states, &local_err); + state->ops->prepare(state, &local_err); if (error_is_set(&local_err)) { error_propagate(errp, local_err); goto delete_and_fail; } } - QSIMPLEQ_FOREACH(states, &snap_bdrv_states, entry) { - states->ops->commit(states); + QSIMPLEQ_FOREACH(state, &snap_bdrv_states, entry) { + state->ops->commit(state); } /* success */ @@ -980,17 +980,17 @@ delete_and_fail: * failure, and it is all-or-none; abandon each new bs, and keep using * the original bs for all images */ - QSIMPLEQ_FOREACH(states, &snap_bdrv_states, entry) { - if (states->ops->abort) { - states->ops->abort(states); + QSIMPLEQ_FOREACH(state, &snap_bdrv_states, entry) { + if (state->ops->abort) { + state->ops->abort(state); } } exit: - QSIMPLEQ_FOREACH_SAFE(states, &snap_bdrv_states, entry, next) { - if (states->ops->clean) { - states->ops->clean(states); + QSIMPLEQ_FOREACH_SAFE(state, &snap_bdrv_states, entry, next) { + if (state->ops->clean) { + state->ops->clean(state); } - g_free(states); + g_free(state); } }