diff --git a/fs/eulerfs/wear.c b/fs/eulerfs/wear.c new file mode 100644 index 0000000000000000000000000000000000000000..3535efab9fa898ca15e07bfe458717ff2f3689f9 --- /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 +#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 0000000000000000000000000000000000000000..d0114813f1efc344f56d4b45096370a7b786c2d3 --- /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 + +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 */