From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54657) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YpxQg-0004ph-DX for qemu-devel@nongnu.org; Wed, 06 May 2015 07:23:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YpxQf-0003Le-LV for qemu-devel@nongnu.org; Wed, 06 May 2015 07:23:54 -0400 From: Fam Zheng Date: Wed, 6 May 2015 19:23:33 +0800 Message-Id: <1430911419-8256-2-git-send-email-famz@redhat.com> In-Reply-To: <1430911419-8256-1-git-send-email-famz@redhat.com> References: <1430911419-8256-1-git-send-email-famz@redhat.com> Subject: [Qemu-devel] [RFC PATCH 1/7] block: Add op blocker type "device IO" List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Kevin Wolf , qemu-block@nongnu.org, jcody@redhat.com, armbru@redhat.com, mreitz@redhat.com, Stefan Hajnoczi , pbonzini@redhat.com Preventing device from submitting IO is useful around various nested poll. Op blocker is a good place to put this flag. Devices would submit IO requests through blk_* block backend interface, which calls blk_check_request to check the validity. Return -EBUSY if the operation is blocked, in which case device IO is temporarily disabled by another BDS user. Signed-off-by: Fam Zheng --- block/block-backend.c | 4 ++++ include/block/block.h | 1 + 2 files changed, 5 insertions(+) diff --git a/block/block-backend.c b/block/block-backend.c index 93e46f3..71fc695 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -478,6 +478,10 @@ static int blk_check_request(BlockBackend *blk, int64_t sector_num, return -EIO; } + if (bdrv_op_is_blocked(blk->bs, BLOCK_OP_TYPE_DEVICE_IO, NULL)) { + return -EBUSY; + } + return blk_check_byte_request(blk, sector_num * BDRV_SECTOR_SIZE, nb_sectors * BDRV_SECTOR_SIZE); } diff --git a/include/block/block.h b/include/block/block.h index 7d1a717..906fb31 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -159,6 +159,7 @@ typedef enum BlockOpType { BLOCK_OP_TYPE_RESIZE, BLOCK_OP_TYPE_STREAM, BLOCK_OP_TYPE_REPLACE, + BLOCK_OP_TYPE_DEVICE_IO, BLOCK_OP_TYPE_MAX, } BlockOpType; -- 1.9.3