From nobody Wed May 1 06:13:36 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1528471101730901.0489322653441; Fri, 8 Jun 2018 08:18:21 -0700 (PDT) Received: from localhost ([::1]:36524 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fRJ9Z-00050H-Bb for importer@patchew.org; Fri, 08 Jun 2018 11:18:13 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39351) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fRJ81-0004PY-HD for qemu-devel@nongnu.org; Fri, 08 Jun 2018 11:16:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fRJ7x-00023Q-Hd for qemu-devel@nongnu.org; Fri, 08 Jun 2018 11:16:37 -0400 Received: from fanzine.igalia.com ([91.117.99.155]:34637) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fRJ7x-0001ez-2y; Fri, 08 Jun 2018 11:16:33 -0400 Received: from [194.100.51.2] (helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1fRJ7K-0001En-GV; Fri, 08 Jun 2018 17:15:54 +0200 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1fRJ75-0001vi-01; Fri, 08 Jun 2018 18:15:39 +0300 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Message-Id:Date:Subject:Cc:To:From; bh=02MI24XiPDVxHz6o8plRtnqxwOXuab/M8oVtHc3gMKY=; b=X/eBCpO6X4XoIAmlSibt0Vrv/ML/5Bk1k6Ck7DeiEq6yXZPDu2eb0rZsmW8wUQyXqVUe25PFMWa0GdD/QMbTMPsB0VOqg45V1jFFc0D0H2eovnwiXfne18vCDcweQR8gbEQPDSoKfNfuOTstPE/rIosq/8XQWqzevU4y8lKqgpW09JQr8+KArGMRn/jKwB12sBddXuMAr/xr3CdXFv1cj2V68G+VtLHCJ+jRRsgn1C9oUDgCH4a6nE4e3UBpf7tuHvBDkY+dE9ntm02lirVJ7DbUB32jbEf6weaFILkI5QFoPVN10R0vsa+w/VK2CRRxaNZoC6LMAprlDN6CHtXekg==; From: Alberto Garcia To: qemu-devel@nongnu.org Date: Fri, 8 Jun 2018 18:15:36 +0300 Message-Id: <20180608151536.7378-1-berto@igalia.com> X-Mailer: git-send-email 2.11.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 91.117.99.155 Subject: [Qemu-devel] [PATCH] throttle: Fix crash on reopen X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Alberto Garcia , qemu-block@nongnu.org, Manos Pitsidianakis , qemu-stable@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The throttle block filter can be reopened, and with this it is possible to change the throttle group that the filter belongs to. The way the code does that is the following: - On throttle_reopen_prepare(): create a new ThrottleGroupMember and attach it to the new throttle group. - On throttle_reopen_commit(): detach the old ThrottleGroupMember, delete it and replace it with the new one. The problem with this is that by replacing the ThrottleGroupMember the previous value of io_limits_disabled is lost, causing an assertion failure in throttle_co_drain_end(). This problem can be reproduced by reopening a throttle node: $QEMU -monitor stdio -object throttle-group,id=3Dtg0,x-iops-total=3D1000 \ -blockdev node-name=3Dhd0,driver=3Dqcow2,file.driver=3Dfile,file.filenam= e=3Dhd.qcow2 \ -blockdev node-name=3Droot,driver=3Dthrottle,throttle-group=3Dtg0,file= =3Dhd0,read-only=3Don (qemu) block_stream root block/throttle.c:214: throttle_co_drain_end: Assertion `tgm->io_limits_d= isabled' failed. Since we only want to change the throttle group on reopen there's no need to create a ThrottleGroupMember and discard the old one. It's easier if we simply detach it from its current group and attach it to the new one. Signed-off-by: Alberto Garcia --- block/throttle.c | 54 +++++++++++++++++++++++++++++++++-------------------= -- 1 file changed, 33 insertions(+), 21 deletions(-) diff --git a/block/throttle.c b/block/throttle.c index 95ed06acd8..026f408aa6 100644 --- a/block/throttle.c +++ b/block/throttle.c @@ -36,9 +36,12 @@ static QemuOptsList throttle_opts =3D { }, }; =20 -static int throttle_configure_tgm(BlockDriverState *bs, - ThrottleGroupMember *tgm, - QDict *options, Error **errp) +/* + * If this function succeeds then the throttle group name is stored in + * @group and must be freed by the caller. + * If there's an error then @group remains unmodified. + */ +static int throttle_parse_options(QDict *options, char **group, Error **er= rp) { int ret; const char *group_name; @@ -63,8 +66,7 @@ static int throttle_configure_tgm(BlockDriverState *bs, goto fin; } =20 - /* Register membership to group with name group_name */ - throttle_group_register_tgm(tgm, group_name, bdrv_get_aio_context(bs)); + *group =3D g_strdup(group_name); ret =3D 0; fin: qemu_opts_del(opts); @@ -75,6 +77,8 @@ static int throttle_open(BlockDriverState *bs, QDict *opt= ions, int flags, Error **errp) { ThrottleGroupMember *tgm =3D bs->opaque; + char *group; + int ret; =20 bs->file =3D bdrv_open_child(NULL, options, "file", bs, &child_file, false, errp); @@ -84,7 +88,14 @@ static int throttle_open(BlockDriverState *bs, QDict *op= tions, bs->supported_write_flags =3D bs->file->bs->supported_write_flags; bs->supported_zero_flags =3D bs->file->bs->supported_zero_flags; =20 - return throttle_configure_tgm(bs, tgm, options, errp); + ret =3D throttle_parse_options(options, &group, errp); + if (ret =3D=3D 0) { + /* Register membership to group with name group_name */ + throttle_group_register_tgm(tgm, group, bdrv_get_aio_context(bs)); + g_free(group); + } + + return ret; } =20 static void throttle_close(BlockDriverState *bs) @@ -160,35 +171,36 @@ static void throttle_attach_aio_context(BlockDriverSt= ate *bs, static int throttle_reopen_prepare(BDRVReopenState *reopen_state, BlockReopenQueue *queue, Error **errp) { - ThrottleGroupMember *tgm; + int ret; + char *group =3D NULL; =20 assert(reopen_state !=3D NULL); assert(reopen_state->bs !=3D NULL); =20 - reopen_state->opaque =3D g_new0(ThrottleGroupMember, 1); - tgm =3D reopen_state->opaque; - - return throttle_configure_tgm(reopen_state->bs, tgm, reopen_state->opt= ions, - errp); + ret =3D throttle_parse_options(reopen_state->options, &group, errp); + reopen_state->opaque =3D group; + return ret; } =20 static void throttle_reopen_commit(BDRVReopenState *reopen_state) { - ThrottleGroupMember *old_tgm =3D reopen_state->bs->opaque; - ThrottleGroupMember *new_tgm =3D reopen_state->opaque; + BlockDriverState *bs =3D reopen_state->bs; + ThrottleGroupMember *tgm =3D bs->opaque; + char *group =3D reopen_state->opaque; =20 - throttle_group_unregister_tgm(old_tgm); - g_free(old_tgm); - reopen_state->bs->opaque =3D new_tgm; + assert(group); + + if (strcmp(group, throttle_group_get_name(tgm))) { + throttle_group_unregister_tgm(tgm); + throttle_group_register_tgm(tgm, group, bdrv_get_aio_context(bs)); + } + g_free(reopen_state->opaque); reopen_state->opaque =3D NULL; } =20 static void throttle_reopen_abort(BDRVReopenState *reopen_state) { - ThrottleGroupMember *tgm =3D reopen_state->opaque; - - throttle_group_unregister_tgm(tgm); - g_free(tgm); + g_free(reopen_state->opaque); reopen_state->opaque =3D NULL; } =20 --=20 2.11.0