From nobody Fri Jul 24 05:23:54 2026 Received: from canpmsgout02.his.huawei.com (canpmsgout02.his.huawei.com [113.46.200.217]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 27E883446C9 for ; Thu, 23 Jul 2026 02:19:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=113.46.200.217 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784773187; cv=none; b=Z+OIJHd0djfz5i1lZO1957BRNZSLPpzJHoMfNLBsDnEpc8qenkc9oG6RTGseF0OOKluNjkB8ni5uyVfXSfoWqZQUgpoRHKrMGsvmvvPIBc8eRY3aMcRKKxhWEUWUxN3LLKDPUxzxNvXUqBklTdwTqrzwlffFyEugfMTOe5LZH00= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784773187; c=relaxed/simple; bh=6Mm8Iaz36SSMcBEs1tDBtG2AGmOOnF4/uFp4JpsMd8E=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=ex9qcr7iTxS+o0v9u3Lh7jmhmnuOzSjck3dqpmVz5fHoE51I9AVMUDoXz8ieW5ye/QGJpKf49gCRT+JZ1yK7bU49ieEKxPq/Unj/ho2vYX6EMklqGMGZ7/uggH/6yOoHc1+PlnZ/viajR5JPi21ouScfHLUqjfkxhX/sqKTt2yw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.b=qWi95YXN; arc=none smtp.client-ip=113.46.200.217 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.b="qWi95YXN" dkim-signature: v=1; a=rsa-sha256; d=huawei.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=9/H4aykUPuReZUKx+4cRRx5ORlkaqD8sN2tNfpWsy70=; b=qWi95YXNeVOVIojZnl7w6HpkrQGqgTGVkLYauCfd0NsbQGteDEKZuY9kFRSkmpcIxz2CNBNuW 8sRVfYq6QnoFZ4riGO9tJMoBpHtFf5ZrhLv6/OOsONg3MYzAYEdX96mocFSXgEIBeNX0pEEysUv ut2yj24PNbvqOckJiiJf5cU= Received: from mail.maildlp.com (unknown [172.19.162.144]) by canpmsgout02.his.huawei.com (SkyGuard) with ESMTPS id 4h5F2B53D7zcZyH; Thu, 23 Jul 2026 10:10:10 +0800 (CST) Received: from dggpemr200001.china.huawei.com (unknown [7.185.36.96]) by mail.maildlp.com (Postfix) with ESMTPS id C168C40538; Thu, 23 Jul 2026 10:19:40 +0800 (CST) Received: from huawei.com (10.50.85.155) by dggpemr200001.china.huawei.com (7.185.36.96) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Thu, 23 Jul 2026 10:19:40 +0800 From: Ran Hongyun To: CC: , , , Subject: [PATCH] ubi-utils: add wear-leveling threshold parameter to ubiattach Date: Thu, 23 Jul 2026 10:10:11 +0800 Message-ID: <20260723021011.3163900-1-ranhongyun1@huawei.com> X-Mailer: git-send-email 2.52.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: kwepems500002.china.huawei.com (7.221.188.17) To dggpemr200001.china.huawei.com (7.185.36.96) Content-Type: text/plain; charset="utf-8" Add wl_threshold support end-to-end: expose the kernel's wear-leveling threshold via a new --wl-threshold / -w option in ubiattach, plumb it through libubi, and define it by replacing 4 bytes of padding in struct ubi_attach_req. Valid range is 2-65536; 0 means use the kernel default. Signed-off-by: Ran Hongyun --- include/libubi.h | 2 ++ include/mtd/ubi-user.h | 3 ++- lib/libubi.c | 1 + ubi-utils/ubiattach.c | 24 +++++++++++++++++++++++- 4 files changed, 28 insertions(+), 2 deletions(-) diff --git a/include/libubi.h b/include/libubi.h index b5b3d8f..9203416 100644 --- a/include/libubi.h +++ b/include/libubi.h @@ -56,6 +56,7 @@ typedef void * libubi_t; * @max_beb_per1024: Maximum expected bad eraseblocks per 1024 eraseblocks * @disable_fm: whether disable fastmap * @need_resv_pool: whether reserve free pebs for filling pool/wl_pool + * @wl_threshold: wear-leveling threshold (0 means use kernel default) */ struct ubi_attach_request { @@ -66,6 +67,7 @@ struct ubi_attach_request int max_beb_per1024; bool disable_fm; bool need_resv_pool; + int wl_threshold; }; =20 /** diff --git a/include/mtd/ubi-user.h b/include/mtd/ubi-user.h index bb5c0f9..601f3f4 100644 --- a/include/mtd/ubi-user.h +++ b/include/mtd/ubi-user.h @@ -284,7 +284,8 @@ struct ubi_attach_req { int16_t max_beb_per1024; int8_t disable_fm; int8_t need_resv_pool; - int8_t padding[8]; + int32_t wl_threshold; + int8_t padding[4]; }; =20 /* diff --git a/lib/libubi.c b/lib/libubi.c index 86736dd..5d55148 100644 --- a/lib/libubi.c +++ b/lib/libubi.c @@ -769,6 +769,7 @@ int ubi_attach(libubi_t desc, const char *node, struct = ubi_attach_request *req) r.vid_hdr_offset =3D req->vid_hdr_offset; r.disable_fm =3D req->disable_fm ? 1 : 0; r.need_resv_pool =3D req->need_resv_pool ? 1 : 0; + r.wl_threshold =3D req->wl_threshold; =20 if (req->max_beb_per1024) { /* diff --git a/ubi-utils/ubiattach.c b/ubi-utils/ubiattach.c index 11e171b..0789a5f 100644 --- a/ubi-utils/ubiattach.c +++ b/ubi-utils/ubiattach.c @@ -44,6 +44,7 @@ struct args { int max_beb_per1024; bool disable_fm; bool need_resv_pool; + int wl_threshold; }; =20 static struct args args =3D { @@ -55,6 +56,7 @@ static struct args args =3D { .max_beb_per1024 =3D 0, .disable_fm =3D false, .need_resv_pool =3D false, + .wl_threshold =3D 0, }; =20 static const char doc[] =3D PROGRAM_NAME " version " VERSION @@ -76,6 +78,9 @@ static const char optionsstr[] =3D "-r, --reserve-pool Slow down the frequency of updating fastmap by rese= rving\n" " pebs for filling pool/wl_pool, which can prolong fl= ash\n" " service life.\n" +"-w, --wl-threshold Set the wear-leveling threshold for this UBI device= .\n" +" If 0, the kernel default value is used.\n" +" Accepted range is 2-65536.\n" "-h, --help print help message\n" "-V, --version print program version"; =20 @@ -85,6 +90,7 @@ static const char usage[] =3D "\t[--mtdn=3D] [--devn=3D]\n" "\t[--dev-path=3D] [-f] [--disable-fastmap] [-r] [--reserv= e-pool]\n" "\t[--max-beb-per1024=3D]\n" +"\t[--wl-threshold=3D]\n" "UBI control device defaults to " DEFAULT_CTRL_DEV " if not supplied.\n" "Example 1: " PROGRAM_NAME " -p /dev/mtd0 - attach /dev/mtd0 to UBI\n" "Example 2: " PROGRAM_NAME " -m 0 - attach MTD device 0 (mtd0) to UBI\n" @@ -104,6 +110,7 @@ static const struct option long_options[] =3D { { .name =3D "max-beb-per1024", .has_arg =3D 1, .flag =3D NULL, .val =3D '= b' }, { .name =3D "disable-fastmap", .has_arg =3D 0, .flag =3D NULL, .val =3D '= f' }, { .name =3D "reserve-pool", .has_arg =3D 0, .flag =3D NULL, .val =3D '= r' }, + { .name =3D "wl-threshold", .has_arg =3D 1, .flag =3D NULL, .val =3D '= w' }, { .name =3D "help", .has_arg =3D 0, .flag =3D NULL, .val =3D '= h' }, { .name =3D "version", .has_arg =3D 0, .flag =3D NULL, .val =3D '= V' }, { NULL, 0, NULL, 0}, @@ -114,7 +121,7 @@ static int parse_opt(int argc, char * const argv[]) while (1) { int key, error =3D 0; =20 - key =3D getopt_long(argc, argv, "p:m:d:O:b:frhV", long_options, NULL); + key =3D getopt_long(argc, argv, "p:m:d:O:b:frw:hV", long_options, NULL); if (key =3D=3D -1) break; =20 @@ -162,6 +169,20 @@ static int parse_opt(int argc, char * const argv[]) args.need_resv_pool =3D true; break; =20 + case 'w': + { + unsigned long tmp =3D simple_strtoul(optarg, &error); + + if (error || (tmp && (tmp < 2 || tmp > 65536))) + return errmsg("bad wear-leveling threshold: \"%s\" (2-65536)", + optarg); + if (tmp =3D=3D 0) + warnmsg("wear-leveling threshold use the default kernel value"); + args.wl_threshold =3D tmp; + + break; + } + case 'h': printf("%s\n\n", doc); printf("%s\n\n", usage); @@ -234,6 +255,7 @@ int main(int argc, char * const argv[]) req.max_beb_per1024 =3D args.max_beb_per1024; req.disable_fm =3D args.disable_fm; req.need_resv_pool =3D args.need_resv_pool; + req.wl_threshold =3D args.wl_threshold; =20 err =3D ubi_attach(libubi, args.node, &req); if (err < 0) { --=20 2.52.0