Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp3701274rdb; Wed, 27 Dec 2023 17:42:10 -0800 (PST) X-Google-Smtp-Source: AGHT+IGX96cW1yJVJ+dYHB5mak7ELmUiXIAJX2s6FpK5F8qB4VOADojoCHiiZzCmo+LlI4ASqxkP X-Received: by 2002:a05:6358:7213:b0:172:d986:53f7 with SMTP id h19-20020a056358721300b00172d98653f7mr10300020rwa.3.1703727729970; Wed, 27 Dec 2023 17:42:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703727729; cv=none; d=google.com; s=arc-20160816; b=qUuMf/EKDECCLg75sLn1/jw8QqLvtDfiJJhvhjfLMrU59Ue4Oazkj6icGSjz3f/lo7 ub1LEUFjTcxoac3btotvgmZPFudLrqAtN/JkREpmKsgFYWltHp/u0naiPQuzT8C7bub5 9g5ynEIvXIE2JYlnbYRzE0336L3lhZ/2CQ56rNeLc/tPdSQwQ0KxZa4FKNONl1QavkUg pHQ59UV1BnUKXOkdG/UIUmcBHeNzIgTjCZCx7WfAYhRntjf3Uk9s675gzwe4gj/MGXJh b9lmOfIQAi/vk56dkG+kzRJ6X+EH/WyB0VLO8WzQBuklxEy2YIqhO39/bdbe5zqPq4ny Wwuw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=JKK4LOxhBtQPsngyIfUmqLERSNo+P0FT6ogJu9TmOeM=; fh=3kaVOPShTC55oj708yh1yJALapWuogKx6Yvc3sQq9zY=; b=hR02DRLXu849gY0Uv4IhtI+lyHGZI0zP/2Mm2FCS0406dIVWO28GZZu+BC0MG5pLET p0YHZCP4vAx2mv1tmcBma2y61Inmjr4PD8bd3S6fxnMvUlY4qSjSnhOLOC9kzNYhMET8 HNcGtzWNuCYq7drdYtd1O/D80CHjwOYHNHQD1VdzABG2QtB32auKm4ZhIJZ8pIRsv2bK OWhVaDWI+mhGN+pt/Caihgj6+FpWT3CIa0+tgvFWxpmdoWLqh0I59Wm8zAd+ewI0i94O xyIPj4DuUYLnqGslEw021c3/4Ukw/k8s/f9LFceRio73aFi6P9jT46rdPbhmS9l2XFAk 9NpQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-12365-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-12365-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id n9-20020a6563c9000000b005cd82a478f6si11828613pgv.759.2023.12.27.17.42.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Dec 2023 17:42:09 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-12365-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-12365-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-12365-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 95EC4281C39 for ; Thu, 28 Dec 2023 01:42:09 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DABEF3C3B; Thu, 28 Dec 2023 01:39:47 +0000 (UTC) X-Original-To: linux-kernel@vger.kernel.org Received: from szxga04-in.huawei.com (szxga04-in.huawei.com [45.249.212.190]) (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 A41F94684 for ; Thu, 28 Dec 2023 01:39:45 +0000 (UTC) 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 Received: from mail.maildlp.com (unknown [172.19.88.214]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4T0rlX6Fjjz1wqCg; Thu, 28 Dec 2023 09:39:20 +0800 (CST) Received: from kwepemm000013.china.huawei.com (unknown [7.193.23.81]) by mail.maildlp.com (Postfix) with ESMTPS id AF5441A019A; Thu, 28 Dec 2023 09:39:28 +0800 (CST) Received: from huawei.com (10.175.127.227) by kwepemm000013.china.huawei.com (7.193.23.81) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Thu, 28 Dec 2023 09:38:15 +0800 From: Zhihao Cheng To: , , , , CC: , Subject: [PATCH RFC 16/17] ubifs: Enable ubifs_repair in '/sys/kernel/debug/ubifs/repair_fs' Date: Thu, 28 Dec 2023 09:41:11 +0800 Message-ID: <20231228014112.2836317-17-chengzhihao1@huawei.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20231228014112.2836317-1-chengzhihao1@huawei.com> References: <20231228014112.2836317-1-chengzhihao1@huawei.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To kwepemm000013.china.huawei.com (7.193.23.81) Add new interface '/sys/kernel/debug/ubifs/repair_fs' to enable ubifs repair. Invoke UBIFS repair by: echo UBIFS_DEV > /sys/kernel/debug/ubifs/repair_fs, UBIFS_DEV could be: 1. ubiX_Y: X means UBI device number and Y means UBI volume number. For example: echo "ubi0_0" > /sys/kernel/debug/ubifs/repair_fs 2. /dev/ubiX_Y: X means UBI device number and Y means UBI volume number. For example: echo "/dev/ubi0_0" > /sys/kernel/debug/ubifs/repair_fs 3. ubiX:NAME: X means UBI device number and NAME means UBI volume name. For example: echo "ubi0:userdata" > /sys/kernel/debug/ubifs/repair_fs Signed-off-by: Zhihao Cheng --- fs/ubifs/debug.c | 33 +++++++++++++++++++++++++++++++++ fs/ubifs/repair.h | 2 ++ 2 files changed, 35 insertions(+) diff --git a/fs/ubifs/debug.c b/fs/ubifs/debug.c index 1fe180c22b96..e8d6e948c32c 100644 --- a/fs/ubifs/debug.c +++ b/fs/ubifs/debug.c @@ -22,6 +22,7 @@ #include #include #include "ubifs.h" +#include "repair.h" static DEFINE_SPINLOCK(dbg_lock); @@ -2868,6 +2869,7 @@ static struct dentry *dfs_chk_orph; static struct dentry *dfs_chk_lprops; static struct dentry *dfs_chk_fs; static struct dentry *dfs_tst_rcvry; +static struct dentry *dfs_repair_fs; static ssize_t dfs_global_file_read(struct file *file, char __user *u, size_t count, loff_t *ppos) @@ -2899,6 +2901,33 @@ static ssize_t dfs_global_file_write(struct file *file, const char __user *u, struct dentry *dent = file->f_path.dentry; int val; + if (dent == dfs_repair_fs) { + int ret, i; + size_t buf_size; + char *dev_name; + + dev_name = vmalloc(PAGE_SIZE); + if (!dev_name) + return -ENOMEM; + + buf_size = min_t(size_t, count, PAGE_SIZE - 1); + if (copy_from_user(dev_name, u, buf_size)) { + vfree(dev_name); + return -EFAULT; + } + + /* Filter '\n' */ + for (i = 0; i < buf_size; ++i) + if (dev_name[i] == '\n' || dev_name[i] == '\0') + break; + dev_name[i] = '\0'; + + ret = ubifs_repair(dev_name); + vfree(dev_name); + + return ret < 0 ? ret : count; + } + val = interpret_user_input(u, count); if (val < 0) return val; @@ -2965,6 +2994,10 @@ void dbg_debugfs_init(void) fname = "tst_recovery"; dfs_tst_rcvry = debugfs_create_file(fname, S_IRUSR | S_IWUSR, dfs_rootdir, NULL, &dfs_global_fops); + + fname = "repair_fs"; + dfs_repair_fs = debugfs_create_file(fname, S_IWUSR, dfs_rootdir, + NULL, &dfs_global_fops); } /** diff --git a/fs/ubifs/repair.h b/fs/ubifs/repair.h index f8d18f07e324..3dcf94787cbe 100644 --- a/fs/ubifs/repair.h +++ b/fs/ubifs/repair.h @@ -171,4 +171,6 @@ struct ubifs_repair_info { bool need_update_lpt; }; +int ubifs_repair(const char *dev_name); + #endif /* !__UBIFS_REPAIR_H__ */ -- 2.31.1