From patchwork Mon Oct 12 20:00:21 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Reitz X-Patchwork-Id: 529421 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)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id F2B13140D8F for ; Tue, 13 Oct 2015 07:08:20 +1100 (AEDT) Received: from localhost ([::1]:58405 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZljON-0002Ap-4r for incoming@patchwork.ozlabs.org; Mon, 12 Oct 2015 16:08:19 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52306) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZljIF-0007wk-Ci for qemu-devel@nongnu.org; Mon, 12 Oct 2015 16:02:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZljIE-0000lr-1q for qemu-devel@nongnu.org; Mon, 12 Oct 2015 16:01:59 -0400 Received: from mx1.redhat.com ([209.132.183.28]:46955) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZljI7-0000jh-Qg; Mon, 12 Oct 2015 16:01:51 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (Postfix) with ESMTPS id 57AC3A8A; Mon, 12 Oct 2015 20:01:51 +0000 (UTC) Received: from localhost (ovpn-116-16.ams2.redhat.com [10.36.116.16]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t9CK1nZ3005445 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Mon, 12 Oct 2015 16:01:50 -0400 From: Max Reitz To: qemu-block@nongnu.org Date: Mon, 12 Oct 2015 22:00:21 +0200 Message-Id: <1444680042-13207-19-git-send-email-mreitz@redhat.com> In-Reply-To: <1444680042-13207-1-git-send-email-mreitz@redhat.com> References: <1444680042-13207-1-git-send-email-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Kevin Wolf , Alberto Garcia , Markus Armbruster , qemu-devel@nongnu.org, Max Reitz , John Snow , Stefan Hajnoczi Subject: [Qemu-devel] [PATCH v6 18/39] block: Add BlockBackendRootState 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 This structure will store some of the state of the root BDS if the BDS tree is removed, so that state can be restored once a new BDS tree is inserted. Signed-off-by: Max Reitz --- block/block-backend.c | 40 ++++++++++++++++++++++++++++++++++++++++ include/block/block_int.h | 10 ++++++++++ include/qemu/typedefs.h | 1 + include/sysemu/block-backend.h | 2 ++ 4 files changed, 53 insertions(+) diff --git a/block/block-backend.c b/block/block-backend.c index 2708ad1..6a3f0c7 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -13,6 +13,7 @@ #include "sysemu/block-backend.h" #include "block/block_int.h" #include "block/blockjob.h" +#include "block/throttle-groups.h" #include "sysemu/blockdev.h" #include "sysemu/sysemu.h" #include "qapi-event.h" @@ -37,6 +38,10 @@ struct BlockBackend { /* the block size for which the guest device expects atomicity */ int guest_block_size; + /* If the BDS tree is removed, some of its options are stored here (which + * can be used to restore those options in the new BDS on insert) */ + BlockBackendRootState root_state; + /* I/O stats (display with "info blockstats"). */ BlockAcctStats stats; @@ -161,6 +166,10 @@ static void blk_delete(BlockBackend *blk) bdrv_unref(blk->bs); blk->bs = NULL; } + if (blk->root_state.throttle_state) { + g_free(blk->root_state.throttle_group); + throttle_group_unref(blk->root_state.throttle_state); + } /* Avoid double-remove after blk_hide_on_behalf_of_hmp_drive_del() */ if (blk->name[0]) { QTAILQ_REMOVE(&blk_backends, blk, link); @@ -1067,3 +1076,34 @@ int blk_probe_geometry(BlockBackend *blk, HDGeometry *geo) { return bdrv_probe_geometry(blk->bs, geo); } + +/* + * Updates the BlockBackendRootState object with data from the currently + * attached BlockDriverState. + */ +void blk_update_root_state(BlockBackend *blk) +{ + assert(blk->bs); + + blk->root_state.open_flags = blk->bs->open_flags; + blk->root_state.read_only = blk->bs->read_only; + blk->root_state.detect_zeroes = blk->bs->detect_zeroes; + + if (blk->root_state.throttle_group) { + g_free(blk->root_state.throttle_group); + throttle_group_unref(blk->root_state.throttle_state); + } + if (blk->bs->throttle_state) { + const char *name = throttle_group_get_name(blk->bs); + blk->root_state.throttle_group = g_strdup(name); + blk->root_state.throttle_state = throttle_group_incref(name); + } else { + blk->root_state.throttle_group = NULL; + blk->root_state.throttle_state = NULL; + } +} + +BlockBackendRootState *blk_get_root_state(BlockBackend *blk) +{ + return &blk->root_state; +} diff --git a/include/block/block_int.h b/include/block/block_int.h index 009d6ea..e472a03 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -26,6 +26,7 @@ #include "block/accounting.h" #include "block/block.h" +#include "block/throttle-groups.h" #include "qemu/option.h" #include "qemu/queue.h" #include "block/coroutine.h" @@ -449,6 +450,15 @@ struct BlockDriverState { NotifierWithReturn write_threshold_notifier; }; +struct BlockBackendRootState { + int open_flags; + bool read_only; + BlockdevDetectZeroesOptions detect_zeroes; + + char *throttle_group; + ThrottleState *throttle_state; +}; + static inline BlockDriverState *backing_bs(BlockDriverState *bs) { return bs->backing ? bs->backing->bs : NULL; diff --git a/include/qemu/typedefs.h b/include/qemu/typedefs.h index ee1ce1d..2e39751 100644 --- a/include/qemu/typedefs.h +++ b/include/qemu/typedefs.h @@ -11,6 +11,7 @@ typedef struct AddressSpace AddressSpace; typedef struct AioContext AioContext; typedef struct AudioState AudioState; typedef struct BlockBackend BlockBackend; +typedef struct BlockBackendRootState BlockBackendRootState; typedef struct BlockDriverState BlockDriverState; typedef struct BusClass BusClass; typedef struct BusState BusState; diff --git a/include/sysemu/block-backend.h b/include/sysemu/block-backend.h index eafcef0..52e35a1 100644 --- a/include/sysemu/block-backend.h +++ b/include/sysemu/block-backend.h @@ -163,6 +163,8 @@ void blk_add_close_notifier(BlockBackend *blk, Notifier *notify); void blk_io_plug(BlockBackend *blk); void blk_io_unplug(BlockBackend *blk); BlockAcctStats *blk_get_stats(BlockBackend *blk); +BlockBackendRootState *blk_get_root_state(BlockBackend *blk); +void blk_update_root_state(BlockBackend *blk); void *blk_aio_get(const AIOCBInfo *aiocb_info, BlockBackend *blk, BlockCompletionFunc *cb, void *opaque);