From patchwork Sat Jun 8 06:57:58 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wayne Xia X-Patchwork-Id: 249931 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 02AF22C00A3 for ; Sat, 8 Jun 2013 17:11:30 +1000 (EST) Received: from localhost ([::1]:58029 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UlDJ9-0004Fn-PV for incoming@patchwork.ozlabs.org; Sat, 08 Jun 2013 03:11:27 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54982) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UlDIt-0004Ef-Ro for qemu-devel@nongnu.org; Sat, 08 Jun 2013 03:11:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UlDIs-00038g-AD for qemu-devel@nongnu.org; Sat, 08 Jun 2013 03:11:11 -0400 Received: from e23smtp06.au.ibm.com ([202.81.31.148]:42998) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UlDIr-00038W-Fs for qemu-devel@nongnu.org; Sat, 08 Jun 2013 03:11:10 -0400 Received: from /spool/local by e23smtp06.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Sat, 8 Jun 2013 16:54:09 +1000 Received: from d23dlp03.au.ibm.com (202.81.31.214) by e23smtp06.au.ibm.com (202.81.31.212) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Sat, 8 Jun 2013 16:54:07 +1000 Received: from d23relay03.au.ibm.com (d23relay03.au.ibm.com [9.190.235.21]) by d23dlp03.au.ibm.com (Postfix) with ESMTP id 6EA7A3578050 for ; Sat, 8 Jun 2013 17:00:58 +1000 (EST) Received: from d23av03.au.ibm.com (d23av03.au.ibm.com [9.190.234.97]) by d23relay03.au.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id r5870oIN18088022 for ; Sat, 8 Jun 2013 17:00:50 +1000 Received: from d23av03.au.ibm.com (loopback [127.0.0.1]) by d23av03.au.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id r5870wkx025984 for ; Sat, 8 Jun 2013 17:00:58 +1000 Received: from RH63Wenchao.localdomain ([9.125.31.72]) by d23av03.au.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id r586w9Iu018747; Sat, 8 Jun 2013 17:00:55 +1000 From: Wenchao Xia To: qemu-devel@nongnu.org Date: Sat, 8 Jun 2013 14:57:58 +0800 Message-Id: <1370674687-13849-3-git-send-email-xiawenc@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1370674687-13849-1-git-send-email-xiawenc@linux.vnet.ibm.com> References: <1370674687-13849-1-git-send-email-xiawenc@linux.vnet.ibm.com> X-Content-Scanned: Fidelis XPS MAILER x-cbid: 13060806-7014-0000-0000-00000322FEE8 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 202.81.31.148 Cc: kwolf@redhat.com, phrdina@redhat.com, armbru@redhat.com, lcapitulino@redhat.com, stefanha@redhat.com, pbonzini@redhat.com, dietmar@proxmox.com Subject: [Qemu-devel] [PATCH 02/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 From: Stefan Hajnoczi 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: Wenchao Xia --- blockdev.c | 104 ++++++++++++++++++++++++++++++------------------------------ 1 files changed, 52 insertions(+), 52 deletions(-) diff --git a/blockdev.c b/blockdev.c index e70225b..46a43b0 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); } }