From patchwork Fri Jan 13 13:14:04 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 135830 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 4116FB6F6F for ; Sat, 14 Jan 2012 00:16:11 +1100 (EST) Received: from localhost ([::1]:38560 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RlgzC-0005zE-8M for incoming@patchwork.ozlabs.org; Fri, 13 Jan 2012 08:16:02 -0500 Received: from eggs.gnu.org ([140.186.70.92]:46243) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RlgyU-0004rO-Dz for qemu-devel@nongnu.org; Fri, 13 Jan 2012 08:15:24 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RlgyL-0007kq-SV for qemu-devel@nongnu.org; Fri, 13 Jan 2012 08:15:18 -0500 Received: from e06smtp15.uk.ibm.com ([195.75.94.111]:34196) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RlgyL-0007kg-FJ for qemu-devel@nongnu.org; Fri, 13 Jan 2012 08:15:09 -0500 Received: from /spool/local by e06smtp15.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 13 Jan 2012 13:15:07 -0000 Received: from d06nrmr1407.portsmouth.uk.ibm.com ([9.149.38.185]) by e06smtp15.uk.ibm.com ([192.168.101.145]) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Fri, 13 Jan 2012 13:14:30 -0000 Received: from d06av09.portsmouth.uk.ibm.com (d06av09.portsmouth.uk.ibm.com [9.149.37.250]) by d06nrmr1407.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id q0DDEReg1978388 for ; Fri, 13 Jan 2012 13:14:29 GMT Received: from d06av09.portsmouth.uk.ibm.com (loopback [127.0.0.1]) by d06av09.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id q0DDERPl016001 for ; Fri, 13 Jan 2012 06:14:27 -0700 Received: from localhost (stefanha-thinkpad.manchester-maybrook.uk.ibm.com [9.174.219.31]) by d06av09.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id q0DDERpA015996; Fri, 13 Jan 2012 06:14:27 -0700 From: Stefan Hajnoczi To: Date: Fri, 13 Jan 2012 13:14:04 +0000 Message-Id: <1326460457-19446-3-git-send-email-stefanha@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.7.3 In-Reply-To: <1326460457-19446-1-git-send-email-stefanha@linux.vnet.ibm.com> References: <1326460457-19446-1-git-send-email-stefanha@linux.vnet.ibm.com> x-cbid: 12011313-0342-0000-0000-0000009B3BDE X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 195.75.94.111 Cc: Kevin Wolf , Marcelo Tosatti , Stefan Hajnoczi , Luiz Capitulino Subject: [Qemu-devel] [PATCH v5 02/15] block: check bdrv_in_use() before blockdev operations 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 Long-running block operations like block migration and image streaming must have continual access to their block device. It is not safe to perform operations like hotplug, eject, change, resize, commit, or external snapshot while a long-running operation is in progress. This patch adds the missing bdrv_in_use() checks so that block migration and image streaming never have the rug pulled out from underneath them. Signed-off-by: Stefan Hajnoczi --- block.c | 4 ++++ blockdev.c | 16 +++++++++++++++- 2 files changed, 19 insertions(+), 1 deletions(-) diff --git a/block.c b/block.c index 967a583..daf92c2 100644 --- a/block.c +++ b/block.c @@ -1020,6 +1020,10 @@ int bdrv_commit(BlockDriverState *bs) return -EACCES; } + if (bdrv_in_use(bs) || bdrv_in_use(bs->backing_hd)) { + return -EBUSY; + } + backing_drv = bs->backing_hd->drv; ro = bs->backing_hd->read_only; strncpy(filename, bs->backing_hd->filename, sizeof(filename)); diff --git a/blockdev.c b/blockdev.c index c832782..6d78b36 100644 --- a/blockdev.c +++ b/blockdev.c @@ -592,12 +592,18 @@ void do_commit(Monitor *mon, const QDict *qdict) if (!strcmp(device, "all")) { bdrv_commit_all(); } else { + int ret; + bs = bdrv_find(device); if (!bs) { qerror_report(QERR_DEVICE_NOT_FOUND, device); return; } - bdrv_commit(bs); + ret = bdrv_commit(bs); + if (ret == -EBUSY) { + qerror_report(QERR_DEVICE_IN_USE, device); + return; + } } } @@ -616,6 +622,10 @@ void qmp_blockdev_snapshot_sync(const char *device, const char *snapshot_file, error_set(errp, QERR_DEVICE_NOT_FOUND, device); return; } + if (bdrv_in_use(bs)) { + error_set(errp, QERR_DEVICE_IN_USE, device); + return; + } pstrcpy(old_filename, sizeof(old_filename), bs->filename); @@ -667,6 +677,10 @@ void qmp_blockdev_snapshot_sync(const char *device, const char *snapshot_file, static int eject_device(Monitor *mon, BlockDriverState *bs, int force) { + if (bdrv_in_use(bs)) { + qerror_report(QERR_DEVICE_IN_USE, bdrv_get_device_name(bs)); + return -1; + } if (!bdrv_dev_has_removable_media(bs)) { qerror_report(QERR_DEVICE_NOT_REMOVABLE, bdrv_get_device_name(bs)); return -1;