From patchwork Mon Jul 23 14:22:58 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Benoit Canet X-Patchwork-Id: 172695 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 CAF862C0261 for ; Tue, 24 Jul 2012 00:23:27 +1000 (EST) Received: from localhost ([::1]:40187 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1StJXh-0006TW-QO for incoming@patchwork.ozlabs.org; Mon, 23 Jul 2012 10:23:25 -0400 Received: from eggs.gnu.org ([208.118.235.92]:57813) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1StJXS-0006TO-Je for qemu-devel@nongnu.org; Mon, 23 Jul 2012 10:23:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1StJXO-0005vG-L8 for qemu-devel@nongnu.org; Mon, 23 Jul 2012 10:23:10 -0400 Received: from mail-bk0-f45.google.com ([209.85.214.45]:65306) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1StJXO-0005uq-EG for qemu-devel@nongnu.org; Mon, 23 Jul 2012 10:23:06 -0400 Received: by mail-bk0-f45.google.com with SMTP id ji1so4506612bkc.4 for ; Mon, 23 Jul 2012 07:23:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references :mime-version:content-type:content-transfer-encoding; bh=++WOzZ1gakwAuInUMj/dzwcsW83qkcHuv27oWVGW06s=; b=yCDe2pdClA7YCg8juXYe2cSRxkwGhek5SJyR6lodUtWXE8CqMwPsMi2XyAdisvRha9 sfz3YgBfvYV9gX2KIrWPCfBCBYzIYnWCu/wWoU/fs/y50E1ggv9S77lGeIhoO/K3DVKR Vh7tBNtD4a6Chw47I7u/rh2iebeY7OJNQgdKWdAgia82MsKh4H+LBVD0m8ciESbCMfBI C1YDchaG2QJ+VwKgqi4H1i+xr2eR8hIXtl39gCquT6uJrTPC0nN94U1zjSToDzlN4dEc X2i6eoljQjzcVDXhlDjHZ4NZ1dLwpBjVozSz7oLjBp68PFKLvvHKiHeB2KVIvtKKZhsE VlGw== Received: by 10.204.155.69 with SMTP id r5mr7749522bkw.49.1343053386036; Mon, 23 Jul 2012 07:23:06 -0700 (PDT) Received: from Laure.box.in.irqsave.net (paradis.irqsave.net. [109.190.18.76]) by mx.google.com with ESMTPS id he8sm7745617bkc.3.2012.07.23.07.23.04 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 23 Jul 2012 07:23:05 -0700 (PDT) From: benoit.canet@gmail.com To: qemu-devel@nongnu.org Date: Mon, 23 Jul 2012 16:22:58 +0200 Message-Id: <1343053380-12133-2-git-send-email-benoit@irqsave.net> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1343053380-12133-1-git-send-email-benoit@irqsave.net> References: <1343053380-12133-1-git-send-email-benoit@irqsave.net> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.85.214.45 Cc: kwolf@redhat.com, stefanha@gmail.com, =?UTF-8?q?Beno=C3=AEt=20Canet?= , stefanha@linux.vnet.ibm.com, pbonzini@redhat.com Subject: [Qemu-devel] [PATCH V4 1/3] block: Add bdrv_are_busy() 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: BenoƮt Canet bdrv_are_busy will be used to check if any of the bs are in use or if one of them have a running block job. The first user will be qmp_migrate(). Signed-off-by: Benoit Canet --- block.c | 13 +++++++++++++ block.h | 2 ++ 2 files changed, 15 insertions(+) diff --git a/block.c b/block.c index ce7eb8f..bc8f160 100644 --- a/block.c +++ b/block.c @@ -4027,6 +4027,19 @@ out: return ret; } +int bdrv_are_busy(void) +{ + BlockDriverState *bs; + + QTAILQ_FOREACH(bs, &bdrv_states, list) { + if (bs->job || bdrv_in_use(bs)) { + return -EBUSY; + } + } + + return 0; +} + void *block_job_create(const BlockJobType *job_type, BlockDriverState *bs, int64_t speed, BlockDriverCompletionFunc *cb, void *opaque, Error **errp) diff --git a/block.h b/block.h index c89590d..0a3de2f 100644 --- a/block.h +++ b/block.h @@ -337,6 +337,8 @@ void bdrv_disable_copy_on_read(BlockDriverState *bs); void bdrv_set_in_use(BlockDriverState *bs, int in_use); int bdrv_in_use(BlockDriverState *bs); +int bdrv_are_busy(void); + enum BlockAcctType { BDRV_ACCT_READ, BDRV_ACCT_WRITE,