Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp4432552rwb; Mon, 31 Jul 2023 06:55:37 -0700 (PDT) X-Google-Smtp-Source: APBJJlFos9TZCIFRRzd06C10BEA22NJ5IpmwoRA5VBcrfRrKFG0uIamordRoXIEmRO3URdM/A5h8 X-Received: by 2002:a17:906:2181:b0:997:865a:77e5 with SMTP id 1-20020a170906218100b00997865a77e5mr8275097eju.45.1690811736973; Mon, 31 Jul 2023 06:55:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690811736; cv=none; d=google.com; s=arc-20160816; b=imp2qMl0K9Ok6+a+AVNuF0EtZETtvO1+HlWRYFGyYsBu2OpfNVI+04Hx5HragIDfEn mYfb0Q4JfX6ozDFMVji72Ed5YgE/sCEiSgSi6k89ZOdcBjd4B9HcVuQF6IXTuEUH2v19 +X+ARlVOwYrXto3SKUl4EjjQvrz7SgKyanKRbrPCBHk4AIoe2sXrKZqoyxfNAzvQiABP Ralo89tCko2jZ0Ig6K/TTDrORSGb5P5k4iGfcqwpEk5k8a5/XRaHt0BSX36r6UM4HXSE ArC0tC4shjORYraOh4b6TxM7A70Hws9Pjitkh2lw3rc99eBuzwBkpHABzZhVMvF6L4Vb G8qw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to :mime-version:user-agent:date:message-id:from:references:cc:to :subject; bh=S+rIP5MrHJuCLq8trkazG3JYskIsSLaE3E7M/UE/944=; fh=6U5kMr9WsaIPulD0vmK7Vi6vsoc2e89GVYF2val76Ys=; b=FxlaEP5LS+PikYTyHZRpObal6tf3p7qKTPP9baAmpJz9RZR8F7o9SCyAwc8yP9MwKU 6l2sjfRLgAa5MIm0noEX0BfT8i3Sc65lQP7xhT5eX4TLgpKTMVjc8MD5/4beS01apyGx 1bUtEdJkcHoSYWEfIUyDGX1MR+QDHzX8Tx+mT07IgC2Ny2ISr+prM0n4MDGMyoezbRNB 3QL6nRJ/ngcFZFL8AWdXOOOwbyKpcY1ApV98G+e6KAst3rtEX165ZrAjYd7GQ6JymxHP o5r9w2b8ngDJdpEL3FFQ3F5zDucPCxpSFvE0L/51iprYQpaE6KOPT3h6IGE+owGeUw9l /2XA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id rs5-20020a170907036500b00992bf8cc68asi2819955ejb.968.2023.07.31.06.55.12; Mon, 31 Jul 2023 06:55:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-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; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229997AbjGaNoj (ORCPT + 99 others); Mon, 31 Jul 2023 09:44:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39378 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229578AbjGaNoi (ORCPT ); Mon, 31 Jul 2023 09:44:38 -0400 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A3D7B1709 for ; Mon, 31 Jul 2023 06:44:34 -0700 (PDT) Received: from kwepemm600013.china.huawei.com (unknown [172.30.72.53]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4RDztQ4qbKzLnsg; Mon, 31 Jul 2023 21:41:50 +0800 (CST) Received: from [10.174.178.46] (10.174.178.46) by kwepemm600013.china.huawei.com (7.193.23.68) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Mon, 31 Jul 2023 21:44:30 +0800 Subject: Re: [RFC 1/1] ubi: An interface is added for dump the mapping between LEBs and PEBs To: ZhaoLong Wang , , , CC: , , References: <20230722102302.1848135-1-wangzhaolong1@huawei.com> <20230722102302.1848135-2-wangzhaolong1@huawei.com> From: Zhihao Cheng Message-ID: <1c00466c-cbe1-9bb0-b96e-461ec02b986d@huawei.com> Date: Mon, 31 Jul 2023 21:44:18 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.5.0 MIME-Version: 1.0 In-Reply-To: <20230722102302.1848135-2-wangzhaolong1@huawei.com> Content-Type: text/plain; charset="gbk"; format=flowed Content-Transfer-Encoding: 8bit X-Originating-IP: [10.174.178.46] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To kwepemm600013.china.huawei.com (7.193.23.68) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,NICE_REPLY_A, RCVD_IN_DNSWL_MED,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE 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-kernel@vger.kernel.org ?? 2023/7/22 18:23, ZhaoLong Wang ะด??: > A debugfs interface named "detailed_eba_table_info" is added to view > the PEB and LEB mapping information of all volumes on a UBI device. > > $ cat /sys/kernel/debug/ubi/ubi1/detailed_eba_table_info > > ========= vol_name:"test_volA",id:2 ======== > logical_block_number physical_block_number > 0 274 > 1 275 > 2 276 > 3 277 > 4 278 > ...... > ========= vol_name:"test_volB",id:3 ======== > logical_block_number physical_block_number > 0 619 > 1 613 > 2 614 > 3 (unmaped) > 4 622 > ...... > > Signed-off-by: ZhaoLong Wang > --- > drivers/mtd/ubi/debug.c | 104 ++++++++++++++++++++++++++++++++++++++++ > drivers/mtd/ubi/eba.c | 24 ---------- > drivers/mtd/ubi/ubi.h | 24 ++++++++++ > 3 files changed, 128 insertions(+), 24 deletions(-) > > diff --git a/drivers/mtd/ubi/debug.c b/drivers/mtd/ubi/debug.c > index 27168f511d6d..c6be9450b509 100644 > --- a/drivers/mtd/ubi/debug.c > +++ b/drivers/mtd/ubi/debug.c > @@ -386,6 +386,7 @@ static const struct file_operations dfs_fops = { > .owner = THIS_MODULE, > }; > > + > /* As long as the position is less then that total number of erase blocks, > * we still have more to print. > */ > @@ -493,6 +494,106 @@ static const struct file_operations eraseblk_count_fops = { > .release = eraseblk_count_release, > }; > > +static void *eba_table_seq_start(struct seq_file *s, loff_t *pos) > +{ > + int volumes_length = UBI_MAX_VOLUMES + UBI_INT_VOL_COUNT; > + > + if (*pos >= 0 && *pos < volumes_length) > + return pos; > + > + return NULL; > +} > + > +static void *eba_table_seq_next(struct seq_file *s, void *v, loff_t *pos) > +{ > + int volumes_length = UBI_MAX_VOLUMES + UBI_INT_VOL_COUNT; > + > + (*pos)++; > + > + if (*pos >= 0 && *pos < volumes_length) > + return pos; > + > + return NULL; > +} > + > +static void eba_table_seq_stop(struct seq_file *s, void *v) > +{ > +} > + > +static int eba_table_seq_show(struct seq_file *s, void *iter) > +{ > + struct ubi_device *ubi = s->private; > + int *vol_idx = iter; > + struct ubi_volume *vol; > + int lnum, pnum, vol_id; > + > + vol = ubi->volumes[*vol_idx]; > + if (vol == NULL) > + return 0; > + > + vol_id = vol->vol_id; > + seq_printf(s, "========= vol_name:\"%s\",id:%d ========\n", vol->name, vol_id); > + seq_puts(s, "logical_block_number\tphysical_block_number\n"); > + spin_lock(&ubi->volumes_lock); > + for (lnum = 0; lnum < vol->reserved_pebs; ++lnum) { > + pnum = vol->eba_tbl->entries[lnum].pnum; > + if (pnum >= 0) > + seq_printf(s, "%-22d\t %-11d\n", lnum, pnum); > + else > + seq_printf(s, "%-22d\t(unmaped)\n", lnum); > + } > + spin_unlock(&ubi->volumes_lock); > + > + return 0; > +} Mote, this traversal of 'vol->eba_tbl->entries' depends on https://patchwork.ozlabs.org/project/linux-mtd/patch/20230504025354.3595768-1-wangzhaolong1@huawei.com/. Reviewed-by: Zhihao Cheng > + > +static const struct seq_operations eba_table_seq_ops = { > + .start = eba_table_seq_start, > + .next = eba_table_seq_next, > + .stop = eba_table_seq_stop, > + .show = eba_table_seq_show > +}; > + > +static int eba_table_open(struct inode *inode, struct file *f) > +{ > + struct seq_file *s; > + int err; > + > + err = seq_open(f, &eba_table_seq_ops); > + if (err) > + return err; > + > + s = f->private_data; > + s->private = ubi_get_device((unsigned long)inode->i_private); > + > + if (!s->private) > + return -ENODEV; > + else > + return 0; > +} > + > +static int eba_table_release(struct inode *inode, struct file *f) > +{ > + struct seq_file *s = f->private_data; > + struct ubi_device *ubi = s->private; > + > + ubi_put_device(ubi); > + > + return seq_release(inode, f); > +} > + > +/* File operations for UBI debugfs files which to read > + * eba_tbl to help developer get the map status of ubi > + * volumes > + */ > +static const struct file_operations eba_table_fops = { > + .owner = THIS_MODULE, > + .open = eba_table_open, > + .read = seq_read, > + .llseek = no_llseek, > + .release = eba_table_release, > +}; > + > /** > * ubi_debugfs_init_dev - initialize debugfs for an UBI device. > * @ubi: UBI device description object > @@ -556,6 +657,9 @@ int ubi_debugfs_init_dev(struct ubi_device *ubi) > mode, d->dfs_dir, > (void *)ubi_num, &dfs_fops); > > + debugfs_create_file("detailed_eba_table_info", S_IRUSR, d->dfs_dir, > + (void *)ubi_num, &eba_table_fops); > + > debugfs_create_file("detailed_erase_block_info", S_IRUSR, d->dfs_dir, > (void *)ubi_num, &eraseblk_count_fops); > > diff --git a/drivers/mtd/ubi/eba.c b/drivers/mtd/ubi/eba.c > index 655ff41863e2..c856ea73a67c 100644 > --- a/drivers/mtd/ubi/eba.c > +++ b/drivers/mtd/ubi/eba.c > @@ -36,30 +36,6 @@ > /* Number of physical eraseblocks reserved for atomic LEB change operation */ > #define EBA_RESERVED_PEBS 1 > > -/** > - * struct ubi_eba_entry - structure encoding a single LEB -> PEB association > - * @pnum: the physical eraseblock number attached to the LEB > - * > - * This structure is encoding a LEB -> PEB association. Note that the LEB > - * number is not stored here, because it is the index used to access the > - * entries table. > - */ > -struct ubi_eba_entry { > - int pnum; > -}; > - > -/** > - * struct ubi_eba_table - LEB -> PEB association information > - * @entries: the LEB to PEB mapping (one entry per LEB). > - * > - * This structure is private to the EBA logic and should be kept here. > - * It is encoding the LEB to PEB association table, and is subject to > - * changes. > - */ > -struct ubi_eba_table { > - struct ubi_eba_entry *entries; > -}; > - > /** > * ubi_next_sqnum - get next sequence number. > * @ubi: UBI device description object > diff --git a/drivers/mtd/ubi/ubi.h b/drivers/mtd/ubi/ubi.h > index c8f1bd4fa100..1457657901df 100644 > --- a/drivers/mtd/ubi/ubi.h > +++ b/drivers/mtd/ubi/ubi.h > @@ -153,6 +153,30 @@ enum { > POWER_CUT_VID_WRITE = 0x02, > }; > > +/** > + * struct ubi_eba_entry - structure encoding a single LEB -> PEB association > + * @pnum: the physical eraseblock number attached to the LEB > + * > + * This structure is encoding a LEB -> PEB association. Note that the LEB > + * number is not stored here, because it is the index used to access the > + * entries table. > + */ > +struct ubi_eba_entry { > + int pnum; > +}; > + > +/** > + * struct ubi_eba_table - LEB -> PEB association information > + * @entries: the LEB to PEB mapping (one entry per LEB). > + * > + * This structure is private to the EBA logic and should be kept here. > + * It is encoding the LEB to PEB association table, and is subject to > + * changes. > + */ > +struct ubi_eba_table { > + struct ubi_eba_entry *entries; > +}; > + > /** > * struct ubi_vid_io_buf - VID buffer used to read/write VID info to/from the > * flash. >