Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit acce952

Browse files
liubchrismason-xx
authored andcommitted
Btrfs: forced readonly mounts on errors
This patch comes from "Forced readonly mounts on errors" ideas. As we know, this is the first step in being more fault tolerant of disk corruptions instead of just using BUG() statements. The major content: - add a framework for generating errors that should result in filesystems going readonly. - keep FS state in disk super block. - make sure that all of resource will be freed and released at umount time. - make sure that fter FS is forced readonly on error, there will be no more disk change before FS is corrected. For this, we should stop write operation. After this patch is applied, the conversion from BUG() to such a framework can happen incrementally. Signed-off-by: Liu Bo <[email protected]> Signed-off-by: Chris Mason <[email protected]>
1 parent 6f88a44 commit acce952

File tree

7 files changed

+523
-2
lines changed

7 files changed

+523
-2
lines changed

fs/btrfs/ctree.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,14 @@ static inline unsigned long btrfs_chunk_item_size(int num_stripes)
295295
#define BTRFS_FSID_SIZE 16
296296
#define BTRFS_HEADER_FLAG_WRITTEN (1ULL << 0)
297297
#define BTRFS_HEADER_FLAG_RELOC (1ULL << 1)
298+
299+
/*
300+
* File system states
301+
*/
302+
303+
/* Errors detected */
304+
#define BTRFS_SUPER_FLAG_ERROR (1ULL << 2)
305+
298306
#define BTRFS_SUPER_FLAG_SEEDING (1ULL << 32)
299307
#define BTRFS_SUPER_FLAG_METADUMP (1ULL << 33)
300308

@@ -1058,6 +1066,9 @@ struct btrfs_fs_info {
10581066
unsigned metadata_ratio;
10591067

10601068
void *bdev_holder;
1069+
1070+
/* filesystem state */
1071+
u64 fs_state;
10611072
};
10621073

10631074
/*
@@ -2203,6 +2214,11 @@ int btrfs_set_block_group_rw(struct btrfs_root *root,
22032214
struct btrfs_block_group_cache *cache);
22042215
void btrfs_put_block_group_cache(struct btrfs_fs_info *info);
22052216
u64 btrfs_account_ro_block_groups_free_space(struct btrfs_space_info *sinfo);
2217+
int btrfs_error_unpin_extent_range(struct btrfs_root *root,
2218+
u64 start, u64 end);
2219+
int btrfs_error_discard_extent(struct btrfs_root *root, u64 bytenr,
2220+
u64 num_bytes);
2221+
22062222
/* ctree.c */
22072223
int btrfs_bin_search(struct extent_buffer *eb, struct btrfs_key *key,
22082224
int level, int *slot);
@@ -2556,6 +2572,14 @@ ssize_t btrfs_listxattr(struct dentry *dentry, char *buffer, size_t size);
25562572
/* super.c */
25572573
int btrfs_parse_options(struct btrfs_root *root, char *options);
25582574
int btrfs_sync_fs(struct super_block *sb, int wait);
2575+
void __btrfs_std_error(struct btrfs_fs_info *fs_info, const char *function,
2576+
unsigned int line, int errno);
2577+
2578+
#define btrfs_std_error(fs_info, errno) \
2579+
do { \
2580+
if ((errno)) \
2581+
__btrfs_std_error((fs_info), __func__, __LINE__, (errno));\
2582+
} while (0)
25592583

25602584
/* acl.c */
25612585
#ifdef CONFIG_BTRFS_FS_POSIX_ACL

0 commit comments

Comments
 (0)