From patchwork Mon Mar 5 18:10:11 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 144751 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 71E4EB6EE8 for ; Tue, 6 Mar 2012 05:56:02 +1100 (EST) Received: from localhost ([::1]:46736 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S4d0t-0000mX-OM for incoming@patchwork.ozlabs.org; Mon, 05 Mar 2012 13:52:03 -0500 Received: from eggs.gnu.org ([208.118.235.92]:44356) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S4d0m-0000f3-Np for qemu-devel@nongnu.org; Mon, 05 Mar 2012 13:51:58 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1S4d0h-0003GF-Od for qemu-devel@nongnu.org; Mon, 05 Mar 2012 13:51:56 -0500 Received: from e06smtp12.uk.ibm.com ([195.75.94.108]:44246) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S4d0h-0003Fv-GW for qemu-devel@nongnu.org; Mon, 05 Mar 2012 13:51:51 -0500 Received: from /spool/local by e06smtp12.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 5 Mar 2012 18:51:47 -0000 Received: from d06nrmr1507.portsmouth.uk.ibm.com (9.149.38.233) by e06smtp12.uk.ibm.com (192.168.101.142) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 5 Mar 2012 18:51:45 -0000 Received: from d06av01.portsmouth.uk.ibm.com (d06av01.portsmouth.uk.ibm.com [9.149.37.212]) by d06nrmr1507.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id q25IpixS2539542 for ; Mon, 5 Mar 2012 18:51:44 GMT Received: from d06av01.portsmouth.uk.ibm.com (loopback [127.0.0.1]) by d06av01.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id q25IpiNk026606 for ; Mon, 5 Mar 2012 11:51:44 -0700 Received: from localhost (sig-9-79-10-190.uk.ibm.com [9.79.10.190]) by d06av01.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id q25Ipi1t026598; Mon, 5 Mar 2012 11:51:44 -0700 From: Stefan Hajnoczi To: Date: Mon, 5 Mar 2012 18:10:11 +0000 Message-Id: <1330971011-31646-1-git-send-email-stefanha@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.9.1 x-cbid: 12030518-8372-0000-0000-000001E72B63 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 195.75.94.108 Cc: Kevin Wolf , Stefan Hajnoczi Subject: [Qemu-devel] [PATCH] block: handle -EBUSY in bdrv_commit_all() 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 Monitor operations that manipulate image files must not execute while a background job (like image streaming) is in progress. This prevents corruptions from happening when two pieces of code are manipulating the image file without knowledge of each other. The monitor "commit" command raises QERR_DEVICE_IN_USE when bdrv_commit() returns -EBUSY but "commit all" has no error handling. This is easy to fix, although note that we do not deliver a detailed error about which device was busy in the "commit all" case. Suggested-by: Kevin Wolf Signed-off-by: Stefan Hajnoczi --- block.c | 8 ++++++-- block.h | 2 +- blockdev.c | 9 ++++++--- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/block.c b/block.c index 52ffe14..b88ee90 100644 --- a/block.c +++ b/block.c @@ -1244,13 +1244,17 @@ ro_cleanup: return ret; } -void bdrv_commit_all(void) +int bdrv_commit_all(void) { BlockDriverState *bs; QTAILQ_FOREACH(bs, &bdrv_states, list) { - bdrv_commit(bs); + int ret = bdrv_commit(bs); + if (ret < 0) { + return ret; + } } + return 0; } struct BdrvTrackedRequest { diff --git a/block.h b/block.h index 48d0bf3..415bb17 100644 --- a/block.h +++ b/block.h @@ -165,7 +165,7 @@ int64_t bdrv_get_allocated_file_size(BlockDriverState *bs); void bdrv_get_geometry(BlockDriverState *bs, uint64_t *nb_sectors_ptr); void bdrv_guess_geometry(BlockDriverState *bs, int *pcyls, int *pheads, int *psecs); int bdrv_commit(BlockDriverState *bs); -void bdrv_commit_all(void); +int bdrv_commit_all(void); int bdrv_change_backing_file(BlockDriverState *bs, const char *backing_file, const char *backing_fmt); void bdrv_register(BlockDriver *bdrv); diff --git a/blockdev.c b/blockdev.c index d78aa51..c6c66ee 100644 --- a/blockdev.c +++ b/blockdev.c @@ -627,12 +627,15 @@ void do_commit(Monitor *mon, const QDict *qdict) { const char *device = qdict_get_str(qdict, "device"); BlockDriverState *bs; + int ret; if (!strcmp(device, "all")) { - bdrv_commit_all(); + ret = bdrv_commit_all(); + if (ret == -EBUSY) { + qerror_report(QERR_DEVICE_IN_USE, device); + return; + } } else { - int ret; - bs = bdrv_find(device); if (!bs) { qerror_report(QERR_DEVICE_NOT_FOUND, device);