From patchwork Sat Jun 6 19:17:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukas Straub X-Patchwork-Id: 11591329 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 65CCD138C for ; Sat, 6 Jun 2020 19:22:00 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3D21C2067B for ; Sat, 6 Jun 2020 19:22:00 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=web.de header.i=@web.de header.b="YeVFkuTP" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3D21C2067B Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=web.de Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:37718 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jheOF-0006lI-AC for patchwork-qemu-devel@patchwork.kernel.org; Sat, 06 Jun 2020 15:21:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40734) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jheKu-0004Mi-Ta for qemu-devel@nongnu.org; Sat, 06 Jun 2020 15:18:32 -0400 Received: from mout.web.de ([212.227.15.3]:37187) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jheKo-0005aK-19 for qemu-devel@nongnu.org; Sat, 06 Jun 2020 15:18:32 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=web.de; s=dbaedf251592; t=1591471074; bh=pEB8U8yNVa9GJCfnqrcey1P+mvKxuLB/fVnqTRIanMQ=; h=X-UI-Sender-Class:Date:From:To:Cc:Subject:In-Reply-To:References; b=YeVFkuTPJx6ohBJ8PDS7sMdL2aHf4A7+6JoWcGIfmDxcrXcDpqVYipaoxW7TtqY1h 695QHiuhdIT/AtcIFjmXvecEnb4s9gTZpKVJIXUrZ5IVbpqvHP1/GaV41IQTH3EXZc qfPISEQPRJ0byXKIXSeATdWOX39Wh70HdzYGvkLg= X-UI-Sender-Class: c548c8c5-30a9-4db5-a2e7-cb6cb037b8f9 Received: from luklap ([87.123.206.73]) by smtp.web.de (mrweb004 [213.165.67.108]) with ESMTPSA (Nemesis) id 0Lpyh5-1j4Cuc3RcF-00fgp5; Sat, 06 Jun 2020 21:17:53 +0200 Date: Sat, 6 Jun 2020 21:17:51 +0200 From: Lukas Straub To: qemu-devel Subject: [PATCH v2 1/7] block/quorum.c: stable children names Message-ID: <6775a26cfe07bea3481ccf60ea7ce464d1b6c41d.1591456338.git.lukasstraub2@web.de> In-Reply-To: References: MIME-Version: 1.0 X-Provags-ID: V03:K1:x+Bhnza/LWN/meoyccth2M9MnpWy6xVZrIkpATAr5iPR4A2ccMH szK4pmZJf4qQP8wksxSLFrWc5YnAZThkFHTn6Id9vCNpr3RTgkLox1Yn6lODO5pBhY3Xlps JXl/iiDvGX5GabJghk5MHG2vUqEIgyLYjVfLy+vBN9RPIIRRkIeib3sPZBD17wtCSUe5va3 W0w3jrsGmaJ+KboN9RJVw== X-UI-Out-Filterresults: notjunk:1;V03:K0:uq+01L1sZdQ=:bFQsEj/u8Hom3WZHSJqWmm orWElE1+VFGrw3lfTvrCrsi1CukqFVbUTRkXkQn6vaWsWBO/ZPNXP2awuVaxt/kJykH0q6+pn 1h4tDYgRjBa7SjSbv481rzyw7Of/IkaIoEE2V3hFsDk5+rkYlhrhJhjC6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7Hpt7/n5gB7pWq/j3yfN 5ksQSBU4pbzkB/2vj Received-SPF: pass client-ip=212.227.15.3; envelope-from=lukasstraub2@web.de; helo=mout.web.de X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/06 15:17:41 X-ACL-Warn: Detected OS = Linux 3.11 and newer X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN 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: Kevin Wolf , Alberto Garcia , "Dr. David Alan Gilbert" , Wainer dos Santos Moschetta , Max Reitz , Zhang Chen , Cleber Rosa , Philippe =?utf-8?q?Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" 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 --- block/quorum.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) -- 2.20.1 diff --git a/block/quorum.c b/block/quorum.c index 6d7a56bd93..acfa09c2cc 100644 --- a/block/quorum.c +++ b/block/quorum.c @@ -29,6 +29,8 @@ #define HASH_LENGTH 32 +#define INDEXSTR_LEN 32 + #define QUORUM_OPT_VOTE_THRESHOLD "vote-threshold" #define QUORUM_OPT_BLKVERIFY "blkverify" #define QUORUM_OPT_REWRITE "rewrite-corrupted" @@ -972,9 +974,9 @@ static int quorum_open(BlockDriverState *bs, QDict *options, int flags, opened = g_new0(bool, s->num_children); for (i = 0; i < s->num_children; i++) { - char indexstr[32]; - ret = snprintf(indexstr, 32, "children.%d", i); - assert(ret < 32); + char indexstr[INDEXSTR_LEN]; + ret = snprintf(indexstr, INDEXSTR_LEN, "children.%d", i); + assert(ret < INDEXSTR_LEN); s->children[i] = bdrv_open_child(NULL, options, indexstr, bs, &child_format, false, &local_err); @@ -1026,7 +1028,7 @@ static void quorum_add_child(BlockDriverState *bs, BlockDriverState *child_bs, { BDRVQuorumState *s = bs->opaque; BdrvChild *child; - char indexstr[32]; + char indexstr[INDEXSTR_LEN]; int ret; if (s->is_blkverify) { @@ -1041,8 +1043,8 @@ static void quorum_add_child(BlockDriverState *bs, BlockDriverState *child_bs, return; } - ret = snprintf(indexstr, 32, "children.%u", s->next_child_index); - if (ret < 0 || ret >= 32) { + ret = snprintf(indexstr, INDEXSTR_LEN, "children.%u", s->next_child_index); + if (ret < 0 || ret >= INDEXSTR_LEN) { error_setg(errp, "cannot generate child name"); return; } @@ -1069,6 +1071,7 @@ static void quorum_del_child(BlockDriverState *bs, BdrvChild *child, Error **errp) { BDRVQuorumState *s = bs->opaque; + char indexstr[INDEXSTR_LEN]; int i; for (i = 0; i < s->num_children; i++) { @@ -1090,6 +1093,11 @@ static void quorum_del_child(BlockDriverState *bs, BdrvChild *child, /* We know now that num_children > threshold, so blkverify must be false */ assert(!s->is_blkverify); + 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); /* We can safely remove this child now */