From patchwork Wed Jul 3 01:25:28 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Zhihao Cheng X-Patchwork-Id: 1126570 X-Patchwork-Delegate: richard@nod.at Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=huawei.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="HONpfil2"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 45dk344VFvz9s3Z for ; Wed, 3 Jul 2019 11:26:22 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:In-Reply-To:References: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=H25sZ4bviuxkOOgbvh+IraB2wVKnQ8PeWzPtXgsBrsw=; b=HONpfil2Qf0Wez PgGFq7Jh4D12Q5CXBWqSuECRW605eC8ZVhRIXxFIiHhN3Aio9bK9frn6kJzAE5jgnmr8Zy1tef2yP lp6TYttn8YmHy7nX27fLrg6R2U1RR0xioSneEqVVw6UfmpPZPfRKGuYVCi8+D2Z5VyGOUb9dnVgyu ycfXSCybCIap3M0i48FPGk0zKaglB2Wrn7nHefnr8WHRXIGg4Jyq8VdYXYcsBousJHE2qOqcACXia nOQoVYtKtZNHL8Y/Dj7rpB3UUh27SpGlZkBzmjVLEW5AiQsRI+MRBnpABF2o3r5+t3xQtiXAJLGWT T6S5FgYk5qbP4C4GL2qQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92 #3 (Red Hat Linux)) id 1hiU1w-0004Op-VJ; Wed, 03 Jul 2019 01:25:53 +0000 Received: from szxga08-in.huawei.com ([45.249.212.255] helo=huawei.com) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1hiU1s-0004NS-8l for linux-mtd@lists.infradead.org; Wed, 03 Jul 2019 01:25:50 +0000 Received: from dggemi404-hub.china.huawei.com (unknown [172.30.72.55]) by Forcepoint Email with ESMTP id 3C9D01080821BB1EDA5F; Wed, 3 Jul 2019 09:25:39 +0800 (CST) Received: from DGGEMI524-MBX.china.huawei.com ([169.254.7.145]) by dggemi404-hub.china.huawei.com ([10.3.17.142]) with mapi id 14.03.0399.000; Wed, 3 Jul 2019 09:25:29 +0800 From: chengzhihao To: "david.oberhollenzer@sigma-star.at" , "richard@nod.at" , "david@sigma-star.at" , "boris.brezillon@free-electrons.com" , "zhangyi (F)" Subject: =?gb2312?b?tPC4tDogW1BBVENIIFJGQyB2Ml0gbXRkOiB1Ymk6IEFkZCBmYXN0?= =?gb2312?b?bWFwIHN5c2ZzIGF0dHJpYnV0ZQ==?= Thread-Topic: [PATCH RFC v2] mtd: ubi: Add fastmap sysfs attribute Thread-Index: AQHVLakkEpLEJIeKg0yEh5ZV5Mu1B6a4IOEQ Date: Wed, 3 Jul 2019 01:25:28 +0000 Message-ID: <0B80F9D4116B2F4484E7279D5A66984F793E33@dggemi524-mbx.china.huawei.com> References: <1561723581-70340-1-git-send-email-chengzhihao1@huawei.com> In-Reply-To: <1561723581-70340-1-git-send-email-chengzhihao1@huawei.com> Accept-Language: en-US Content-Language: zh-CN X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.177.224.82] MIME-Version: 1.0 X-CFilter-Loop: Reflected X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190702_182548_603633_44F84413 X-CRM114-Status: GOOD ( 13.84 ) X-Spam-Score: -2.3 (--) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (-2.3 points) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at https://www.dnswl.org/, medium trust [45.249.212.255 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -0.0 SPF_HELO_PASS SPF: HELO matches SPF record X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "linux-mtd@lists.infradead.org" , "linux-kernel@vger.kernel.org" Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org ping ~ -----邮件原件----- 发件人: chengzhihao 发送时间: 2019年6月28日 20:06 收件人: david.oberhollenzer@sigma-star.at; richard@nod.at; david@sigma-star.at; boris.brezillon@free-electrons.com; zhangyi (F) 抄送: linux-mtd@lists.infradead.org; linux-kernel@vger.kernel.org; chengzhihao 主题: [PATCH RFC v2] mtd: ubi: Add fastmap sysfs attribute The UBI device can be attached to a MTD device via fastmap by setting CONFIG_MTD_UBI_FASTMAP to 'y' (If there already exists a fastmap on the UBI device). To support some debugging scenarios, attaching process by fastmap can be confirmed in dmesg. If the UBI device is attached by fastmap, logs like following will appear in dmesg: ubi0: attached by fastmap If multiple UBI devices are attached to multiple MTD devices at the same time, how to distinguish which UBI devices are successfully attached by fastmap? Extracting attaching information for each UBI device one by one from dmesg is a way. A better method is to record fastmap existence in sysfs, so it can be obtained by userspace tools. This patch exposes fastmap on sysfs. Suppose you attach an UBI device to a MTD device by fastmap: if fastmap equals to '1', that is, the fastmap generated before last detaching operation is confirmed valid. Else, there may be some problems with old fastmap. Besides, userspace tool can also check whether the fastmap updating triggered by other operations (such as resize volume) is successful by reading this sysfs attribute. Signed-off-by: Zhihao Cheng --- Documentation/ABI/stable/sysfs-class-ubi | 15 +++++++++++++++ drivers/mtd/ubi/build.c | 9 ++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) ret = sprintf(buf, "%d\n", ubi->mtd->index); else if (attr == &dev_ro_mode) ret = sprintf(buf, "%d\n", ubi->ro_mode); - else + else if (attr == &dev_fastmap) { + down_write(&ubi->fm_protect); + ret = sprintf(buf, "%d\n", ubi->fm ? 1 : 0); + up_write(&ubi->fm_protect); + } else ret = -EINVAL; ubi_put_device(ubi); @@ -398,6 +404,7 @@ static struct attribute *ubi_dev_attrs[] = { &dev_bgt_enabled.attr, &dev_mtd_num.attr, &dev_ro_mode.attr, + &dev_fastmap.attr, NULL }; ATTRIBUTE_GROUPS(ubi_dev); -- 2.7.4 diff --git a/Documentation/ABI/stable/sysfs-class-ubi b/Documentation/ABI/stable/sysfs-class-ubi index a6b3240..1d96cf0 100644 --- a/Documentation/ABI/stable/sysfs-class-ubi +++ b/Documentation/ABI/stable/sysfs-class-ubi @@ -116,6 +116,21 @@ Description: device, and "0\n" if it is cleared. UBI devices mark themselves as read-only when they detect an unrecoverable error. +What: /sys/class/ubi/ubiX/fastmap +Date: June 2019 +KernelVersion: 5.2 +Contact: linux-mtd@lists.infradead.org +Description: + Contains ASCII "1\n" if there exists a fastmap on UBI device, + and "0\n" if there not exists a fastmap on UBI device. After + attaching the UBI device to a MTD device via fastmap, userspace + tool can sense that there is a fastmap on UBI device by + checking sysfs attribute 'fastmap', that is, the fastmap + generated before last detaching operation is valid. In addition, + userspace tool can also check whether the fastmap updating + triggered by volume operation is successful by reading this + sysfs attribute. + What: /sys/class/ubi/ubiX/total_eraseblocks Date: July 2006 KernelVersion: 2.6.22 diff --git a/drivers/mtd/ubi/build.c b/drivers/mtd/ubi/build.c index d636bbe..0cd6b8e 100644 --- a/drivers/mtd/ubi/build.c +++ b/drivers/mtd/ubi/build.c @@ -140,6 +140,8 @@ static struct device_attribute dev_mtd_num = __ATTR(mtd_num, S_IRUGO, dev_attribute_show, NULL); static struct device_attribute dev_ro_mode = __ATTR(ro_mode, S_IRUGO, dev_attribute_show, NULL); +static struct device_attribute dev_fastmap = + __ATTR(fastmap, S_IRUGO, dev_attribute_show, NULL); /** * ubi_volume_notify - send a volume change notification. @@ -378,7 +380,11 @@ static ssize_t dev_attribute_show(struct device *dev,