From nobody Tue Apr 15 08:23:34 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1600167340; cv=none; d=zohomail.com; s=zohoarc; b=PE8T8wiDEVxLVxzl0gr+x2Hb8K01RhvBcLx0mxLFQBwvUbbClgPe4VGkk0zvrZ524TSxntyPkylHJI8jFAe/Q7qBw35K9iljZXGW5bDoEBllrQAin1YUGkzhUjpXz72ZbxSuGWWC6SZL8wsIQY97fO5Q6NBg942Lo/Xdb8idRHs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600167340; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=uP30DnVeODMLdNm9vUyTjR1z7jdsH9mOP9byIYWIgbY=; b=fWX50Bb/WZ1rhCiK1MKnr5jo6QrtqCmjYvKSLn6J2EZ7VP+HCpg6Tyoo+xPyRWfJa/Q6+rhbiDN/pMxf1HtUWtBmO/Ca0SRk07c8P1WwASZWYbqDJU/vx00kh82FOmdyattqniBOKef2fdupJQ+yDd1Dlf8WW2oBZZHpBtLBkeM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1600167340953309.13260502433025; Tue, 15 Sep 2020 03:55:40 -0700 (PDT) Received: from localhost ([::1]:39346 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kI8cd-00052Q-Sa for importer@patchew.org; Tue, 15 Sep 2020 06:55:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52532) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kI8UD-0000UK-FI for qemu-devel@nongnu.org; Tue, 15 Sep 2020 06:46:57 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:20914 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kI8U9-0004YK-7R for qemu-devel@nongnu.org; Tue, 15 Sep 2020 06:46:57 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-83-NX41xAwaP7SAoHmCzt_gVw-1; Tue, 15 Sep 2020 06:46:44 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E798D64087; Tue, 15 Sep 2020 10:46:42 +0000 (UTC) Received: from localhost (ovpn-113-7.ams2.redhat.com [10.36.113.7]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8A5345DC1E; Tue, 15 Sep 2020 10:46:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600166811; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=uP30DnVeODMLdNm9vUyTjR1z7jdsH9mOP9byIYWIgbY=; b=hMQD/FgyrT7yUMrdNdY0ye6/y+0UyH2J0GB3jC4uphtJcjlV++zDV+yiR2FlNVwY18Z2vA UqTMriTBmIk28QPc3IIaOG+Nlr4GeSLbgeHB6bYOW8LGQB8k4sEQWgJCgaQWbtbu7MsMQ1 2m3o1icBiO5sNDvmyVgIHiFwGtncUKY= X-MC-Unique: NX41xAwaP7SAoHmCzt_gVw-1 From: Max Reitz To: qemu-block@nongnu.org Subject: [PULL 06/22] block/quorum.c: stable children names Date: Tue, 15 Sep 2020 12:46:11 +0200 Message-Id: <20200915104627.699552-7-mreitz@redhat.com> In-Reply-To: <20200915104627.699552-1-mreitz@redhat.com> References: <20200915104627.699552-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mreitz@redhat.com X-Mimecast-Spam-Score: 0.001 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=207.211.31.120; envelope-from=mreitz@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/15 02:29:39 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -38 X-Spam_score: -3.9 X-Spam_bar: --- X-Spam_report: (-3.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.792, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , qemu-devel@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) Content-Type: text/plain; charset="utf-8" From: Lukas Straub If we remove the child with the highest index from the quorum, decrement s->next_child_index. This way we get stable children names as long as we only remove the last child. Signed-off-by: Lukas Straub Fixes: https://bugs.launchpad.net/bugs/1881231 Reviewed-by: Zhang Chen Reviewed-by: Alberto Garcia Message-Id: <5d5f930424c1c770754041aa8ad6421dc4e2b58e.1596536719.git.lukass= traub2@web.de> Signed-off-by: Max Reitz --- block/quorum.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/block/quorum.c b/block/quorum.c index 6df9449fc2..e846a7e892 100644 --- a/block/quorum.c +++ b/block/quorum.c @@ -29,6 +29,8 @@ =20 #define HASH_LENGTH 32 =20 +#define INDEXSTR_LEN 32 + #define QUORUM_OPT_VOTE_THRESHOLD "vote-threshold" #define QUORUM_OPT_BLKVERIFY "blkverify" #define QUORUM_OPT_REWRITE "rewrite-corrupted" @@ -970,9 +972,9 @@ static int quorum_open(BlockDriverState *bs, QDict *opt= ions, int flags, opened =3D g_new0(bool, s->num_children); =20 for (i =3D 0; i < s->num_children; i++) { - char indexstr[32]; - ret =3D snprintf(indexstr, 32, "children.%d", i); - assert(ret < 32); + char indexstr[INDEXSTR_LEN]; + ret =3D snprintf(indexstr, INDEXSTR_LEN, "children.%d", i); + assert(ret < INDEXSTR_LEN); =20 s->children[i] =3D bdrv_open_child(NULL, options, indexstr, bs, &child_of_bds, BDRV_CHILD_DATA, f= alse, @@ -1024,7 +1026,7 @@ static void quorum_add_child(BlockDriverState *bs, Bl= ockDriverState *child_bs, { BDRVQuorumState *s =3D bs->opaque; BdrvChild *child; - char indexstr[32]; + char indexstr[INDEXSTR_LEN]; int ret; =20 if (s->is_blkverify) { @@ -1039,8 +1041,8 @@ static void quorum_add_child(BlockDriverState *bs, Bl= ockDriverState *child_bs, return; } =20 - ret =3D snprintf(indexstr, 32, "children.%u", s->next_child_index); - if (ret < 0 || ret >=3D 32) { + ret =3D snprintf(indexstr, INDEXSTR_LEN, "children.%u", s->next_child_= index); + if (ret < 0 || ret >=3D INDEXSTR_LEN) { error_setg(errp, "cannot generate child name"); return; } @@ -1068,6 +1070,7 @@ static void quorum_del_child(BlockDriverState *bs, Bd= rvChild *child, Error **errp) { BDRVQuorumState *s =3D bs->opaque; + char indexstr[INDEXSTR_LEN]; int i; =20 for (i =3D 0; i < s->num_children; i++) { @@ -1089,6 +1092,11 @@ static void quorum_del_child(BlockDriverState *bs, B= drvChild *child, /* We know now that num_children > threshold, so blkverify must be fal= se */ assert(!s->is_blkverify); =20 + snprintf(indexstr, INDEXSTR_LEN, "children.%u", s->next_child_index - = 1); + if (!strncmp(child->name, indexstr, INDEXSTR_LEN)) { + s->next_child_index--; + } + bdrv_drained_begin(bs); =20 /* We can safely remove this child now */ --=20 2.26.2