Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp568837rwb; Fri, 18 Nov 2022 05:33:18 -0800 (PST) X-Google-Smtp-Source: AA0mqf47TckFkz/zAlJl2MZsiO29wxYMnjRQQOj1mN4QOSF/GidTAs9cjyI9Bcd9FSFtS5dbLFMF X-Received: by 2002:a63:5a62:0:b0:476:ed2a:6215 with SMTP id k34-20020a635a62000000b00476ed2a6215mr6712641pgm.559.1668778398201; Fri, 18 Nov 2022 05:33:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668778398; cv=none; d=google.com; s=arc-20160816; b=GaSKJpoMEq/vPg+1bSJ7GAOQyjvoFF9/quwWROXoHMNpun9QdVsEwwfrs3v5AxQoEP 1KnQjc70PUpUJDUKnl3F+XK78zc6CvukOTggGTBLD0sDVOPKTbNKodySXoQBgEWmICfj nxsf0aWMv6anNCR6AfobQdv1EywBdXovyIFDAQ+h9ZvGcCDxJGR7O/YjFs7/U8bfK5sc 0Wm94uOTclzr8Znzx+vArJjQp8sP0l+L29wTaLWMziD3riy/4XmgQcaUUoLdiNg9TRc7 hGb4yRY7Y2cfLvonlkzG25D5ZbAZ8GU5+wLYpALBFzwU/0ZCVUK3RXkVArnf7d5HAbPO 93wA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:in-reply-to:cc:references:message-id:date :subject:mime-version:from:content-transfer-encoding:dkim-signature; bh=cHz0Nc9xRFDikzbKReRE/I4YGqC1pkEJE5elJpVu7Aw=; b=W82KfOXF986bdQneIfvbleloU7irHp5hU3MvbNgICtA5ogHSq7yP1q5H63mXsygW4J d2dMCUckUNr+nfQaB/b3AUnXjj1boEemyK+XxSFTNIupNMdFpgelRHN0E2CCw4sXWjbY M5knDQ9sGnWoGTfjAcfiEEScLyFTwhl84AxbViXiyOVS1Tp1lwpndIGqO6+pROgKN5dQ nAMuVdc3AF7qzd5bSRdu0/YMME2rG8cCwib4ksOu4eG3TCF2TbIfaqLJO4s//hPRW6zs 93Dzm/n8bc2Kzk1ahe492dbw0U6j/tDU+0skniu2o2WL+dvJm6n6uwhK9mUAVMUH0fI9 +cjQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@dilger-ca.20210112.gappssmtp.com header.s=20210112 header.b=3VoftXP1; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i136-20020a62878e000000b00571d24aad85si3519408pfe.86.2022.11.18.05.33.02; Fri, 18 Nov 2022 05:33:18 -0800 (PST) Received-SPF: pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@dilger-ca.20210112.gappssmtp.com header.s=20210112 header.b=3VoftXP1; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241561AbiKRNbW (ORCPT + 99 others); Fri, 18 Nov 2022 08:31:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52266 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232495AbiKRNbV (ORCPT ); Fri, 18 Nov 2022 08:31:21 -0500 Received: from mail-oi1-x235.google.com (mail-oi1-x235.google.com [IPv6:2607:f8b0:4864:20::235]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 868178C4A0 for ; Fri, 18 Nov 2022 05:31:19 -0800 (PST) Received: by mail-oi1-x235.google.com with SMTP id n205so5344198oib.1 for ; Fri, 18 Nov 2022 05:31:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dilger-ca.20210112.gappssmtp.com; s=20210112; h=to:in-reply-to:cc:references:message-id:date:subject:mime-version :from:content-transfer-encoding:from:to:cc:subject:date:message-id :reply-to; bh=cHz0Nc9xRFDikzbKReRE/I4YGqC1pkEJE5elJpVu7Aw=; b=3VoftXP17vGPVNHrXcxy/t/1y4vHCX2NjQ6KGBLWYINgb7HMNwH+2eN3FYvbMqd8NG x4wMckStS1o8Hqup044ILvFnidlRxdocAZCBduLBTcypN+rKy20BkOeO4jiP05kUaDEN YESrWSONG63a8i/LLHhTYthIKa4UHvaauI9jI03K5z+nUl7TBspUdQ4awR99qZaLS3mv rIjpiITeaA0GJ6vvRhfO+XlSsmzTayqE/8znjawnNKqYLxuAE0Ij7Dvjwn0PlrXorhOc cVfTWnuJ1voBYXf8xN8dcGJD9i6aIkxxW73PhBrUOQt+bJXhUYA+nMAnxV51Ii+n9A2X UffA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=to:in-reply-to:cc:references:message-id:date:subject:mime-version :from:content-transfer-encoding:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=cHz0Nc9xRFDikzbKReRE/I4YGqC1pkEJE5elJpVu7Aw=; b=fqQtU5MM5RGoAQccQgb4B7Q0+q6CF19VeL+ulY5i13S4Atp+L9Qn/teTIw6qCavPhD HvbHf5L3dJ1f58GsQEVQ5dtK5rpBGhKfPdGGEQDMP3mBOUqkB1CfkvGR8F5Vd77VqmN/ KKIchR1tpfKxwIfbBP8dzdOXiiDDcsCRKDjCF8uG36plYt6VEFRCZXw/Eej46VRG81rx iNKscmOPuueiBxD1ODXxj9lIhhxEJnZYxHs+V451HLKTg5Xa/qqdfRyc0AWLDG36r5JW LIzC5OOqQfT92GQ7T4fGRKbJfPOl6q7EVNleEOVbjdX5qCAdQgEOAdWzZCGEoKeNYNFE 2mZg== X-Gm-Message-State: ANoB5pkJ4jxeU72v7ZxBeakZrbK7Nl6T9KKXkq3KxEiyh1gS42EOXuuQ Hg3dIncHaEh2h1qshMDQKIYOgmfSsroBJPYA X-Received: by 2002:a05:6808:3096:b0:355:ebd:8b3a with SMTP id bl22-20020a056808309600b003550ebd8b3amr3385467oib.117.1668778278337; Fri, 18 Nov 2022 05:31:18 -0800 (PST) Received: from smtpclient.apple ([205.169.26.81]) by smtp.gmail.com with ESMTPSA id r186-20020acac1c3000000b0035a9003b8edsm1363544oif.40.2022.11.18.05.31.17 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 18 Nov 2022 05:31:17 -0800 (PST) Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable From: Andreas Dilger Mime-Version: 1.0 (1.0) Subject: Re: [RFCv1 05/72] badblocks: Add badblocks merge logic Date: Fri, 18 Nov 2022 07:31:17 -0600 Message-Id: References: <01e72f626dcebdb8f0a78b53e4cd093357d82787.1667822611.git.ritesh.list@gmail.com> Cc: Theodore Ts'o , linux-ext4@vger.kernel.org, Harshad Shirwadkar , Wang Shilong , Andreas Dilger , Li Xi In-Reply-To: <01e72f626dcebdb8f0a78b53e4cd093357d82787.1667822611.git.ritesh.list@gmail.com> To: "Ritesh Harjani (IBM)" X-Mailer: iPhone Mail (19H12) X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org On Nov 7, 2022, at 06:22, Ritesh Harjani (IBM) wrote= : >=20 > =EF=BB=BFFrom: Wang Shilong >=20 > Add badblocks merge logic >=20 > Signed-off-by: Wang Shilong > Signed-off-by: Ritesh Harjani (IBM) Reviewed-by: Andreas Dilger > --- > lib/ext2fs/badblocks.c | 75 ++++++++++++++++++++++++++++++++++++++++++ > lib/ext2fs/ext2fs.h | 2 ++ > 2 files changed, 77 insertions(+) >=20 > diff --git a/lib/ext2fs/badblocks.c b/lib/ext2fs/badblocks.c > index 345168e0..36794e69 100644 > --- a/lib/ext2fs/badblocks.c > +++ b/lib/ext2fs/badblocks.c > @@ -56,6 +56,74 @@ static errcode_t make_u32_list(int size, int num, __u32= *list, > return 0; > } >=20 > +static inline int insert_ok(blk_t *array, int cnt, blk_t new) > +{ > + return (cnt =3D=3D 0 || array[cnt - 1] !=3D new); > +} > + > +/* > + * Merge list from src to dest > + */ > +static errcode_t merge_u32_list(ext2_u32_list src, ext2_u32_list dest) > +{ > + errcode_t retval; > + int src_count =3D src->num; > + int dest_count =3D dest->num; > + int size =3D src_count + dest_count; > + int size_entry =3D sizeof(blk_t); > + blk_t *array; > + blk_t *src_array =3D src->list; > + blk_t *dest_array =3D dest->list; > + int src_index =3D 0; > + int dest_index =3D 0; > + int uniq_cnt =3D 0; > + > + if (src->num =3D=3D 0) > + return 0; > + > + retval =3D ext2fs_get_array(size, size_entry, &array); > + if (retval) > + return retval; > + > + /* > + * It is possible that src list and dest list could be > + * duplicated when merging badblocks. > + */ > + while (src_index < src_count || dest_index < dest_count) { > + if (src_index >=3D src_count) { > + for (; dest_index < dest_count; dest_index++) > + if (insert_ok(array, uniq_cnt, dest_array[dest_index])) > + array[uniq_cnt++] =3D dest_array[dest_index]; > + break; > + } > + if (dest_index >=3D dest_count) { > + for (; src_index < src_count; src_index++) > + if (insert_ok(array, uniq_cnt, src_array[src_index])) > + array[uniq_cnt++] =3D src_array[src_index]; > + break; > + } > + if (src_array[src_index] < dest_array[dest_index]) { > + if (insert_ok(array, uniq_cnt, src_array[src_index])) > + array[uniq_cnt++] =3D src_array[src_index]; > + src_index++; > + } else if (src_array[src_index] > dest_array[dest_index]) { > + if (insert_ok(array, uniq_cnt, dest_array[dest_index])) > + array[uniq_cnt++] =3D dest_array[dest_index]; > + dest_index++; > + } else { > + if (insert_ok(array, uniq_cnt, dest_array[dest_index])) > + array[uniq_cnt++] =3D dest_array[dest_index]; > + src_index++; > + dest_index++; > + } > + } > + > + ext2fs_free_mem(&dest->list); > + dest->list =3D array; > + dest->num =3D uniq_cnt; > + dest->size =3D size; > + return 0; > +} >=20 > /* > * This procedure creates an empty u32 list. > @@ -91,6 +159,13 @@ errcode_t ext2fs_badblocks_copy(ext2_badblocks_list sr= c, > (ext2_u32_list *) dest); > } >=20 > +errcode_t ext2fs_badblocks_merge(ext2_badblocks_list src, > + ext2_badblocks_list dest) > +{ > + return merge_u32_list((ext2_u32_list) src, > + (ext2_u32_list) dest); > +} > + > /* > * This procedure frees a badblocks list. > * > diff --git a/lib/ext2fs/ext2fs.h b/lib/ext2fs/ext2fs.h > index 9cc994b1..18dddc2c 100644 > --- a/lib/ext2fs/ext2fs.h > +++ b/lib/ext2fs/ext2fs.h > @@ -845,6 +845,8 @@ extern int ext2fs_badblocks_list_iterate(ext2_badblock= s_iterate iter, > extern void ext2fs_badblocks_list_iterate_end(ext2_badblocks_iterate iter)= ; > extern errcode_t ext2fs_badblocks_copy(ext2_badblocks_list src, > ext2_badblocks_list *dest); > +extern errcode_t ext2fs_badblocks_merge(ext2_badblocks_list src, > + ext2_badblocks_list dest); > extern int ext2fs_badblocks_equal(ext2_badblocks_list bb1, > ext2_badblocks_list bb2); > extern int ext2fs_u32_list_count(ext2_u32_list bb); > --=20 > 2.37.3 >=20