From: Yu Kuai yukuai3@huawei.com
hulk inclusion category: feature bugzilla: https://gitee.com/openeuler/kernel/issues/I40JRR CVE: NA
--------------------------------------
Page wears are preallocated ints for all pages, each of the ints records the number of writes to the page. This is used to coarse-grainedly show the degree of wear.
Signed-off-by: Mingkai Dong dongmingkai1@huawei.com Signed-off-by: Yu Kuai yukuai3@huawei.com Reviewed-by: Hou Tao houtao1@huawei.com Signed-off-by: Zheng Zengkai zhengzengkai@huawei.com --- fs/eulerfs/wear.c | 48 +++++++++++++++++++++++++++++++++++++++++++++++ fs/eulerfs/wear.h | 30 +++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+) create mode 100644 fs/eulerfs/wear.c create mode 100644 fs/eulerfs/wear.h
diff --git a/fs/eulerfs/wear.c b/fs/eulerfs/wear.c new file mode 100644 index 000000000000..3535efab9fa8 --- /dev/null +++ b/fs/eulerfs/wear.c @@ -0,0 +1,48 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (C) 2021. Huawei Technologies Co., Ltd. All rights reserved. + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 and + * only version 2 as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include "wear.h" +#include <linux/vmalloc.h> +#include "euler.h" + +void wear_init(struct super_block *sb) +{ + struct eufs_sb_info *sbi = EUFS_SB(sb); + + if (!wear_control) + return; + sbi->page_wears = vmalloc(sizeof(struct page_wear) * sbi->npages); + memset(sbi->page_wears, 0, sizeof(struct page_wear) * sbi->npages); +} + +void wear_fini(struct super_block *sb) +{ + struct eufs_sb_info *sbi = EUFS_SB(sb); + + if (!wear_control) + return; + if (sbi->page_wears) + vfree(sbi->page_wears); + sbi->page_wears = NULL; +} + +/* Return whether it's in a good state */ +bool wear_inc(struct super_block *sb, void *page) +{ + struct eufs_sb_info *sbi = EUFS_SB(sb); + + if (!wear_control) + return true; + return sbi->page_wears[(page - sbi->data_start) / PAGE_SIZE].wear++ <= + wear_threshold; +} diff --git a/fs/eulerfs/wear.h b/fs/eulerfs/wear.h new file mode 100644 index 000000000000..d0114813f1ef --- /dev/null +++ b/fs/eulerfs/wear.h @@ -0,0 +1,30 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Copyright (C) 2021. Huawei Technologies Co., Ltd. All rights reserved. + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 and + * only version 2 as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#ifndef EUFS_WEAR_H +#define EUFS_WEAR_H + +#include <linux/fs.h> + +extern int wear_threshold; +extern int wear_control; + +struct page_wear { + int wear; +}; + +void wear_init(struct super_block *sb); +void wear_fini(struct super_block *sb); +bool wear_inc(struct super_block *sb, void *page); + +#endif /* EUFS_WEAR_H */