Skip to contentSkip to conversation

f2fs: add per-device superblocks

RFC PATCH New sunqiuyang 1 participant 1 message Nov 9, 2017

Subsystems (2)
lore
Share & tools
lore

sunqiuyang

author
#0 lore raw

RFC PATCH 1/1 f2fs: add per-device superblocks

From: Qiuyang Sun <[email protected]>

Currently, a multi-device F2FS only has superblocks written in its start device, but not the others. Thus, we cannot tell if a single device is part of a F2FS by reading itself only, which may be unsafe in scenarios like transferring devices between computer systems. This patch embeds per-device superblock sections into the main area.

- In the main area, we reserve the start section of each device for extra copies of the superblock on its 0th and 1st blocks. All blocks in such segments are counted as valid, disabling them to be allocated for other uses. These segments cannot be GCed.
- Reserve a bit in f2fs_super_block::feature to represent whether superblock sections exist on all devices. This feature is backward compatible by a mount option "-o per_dev_sb": Any valid data or node blocks in the target sections will be moved out by calling do_garbage_collect(); if succeeded, new superblock sections will be built, otherwise the mount fails.
- With this feature, a F2FS can be mounted from any of its devices.

TODO:
- f2fs-tools:
- mkfs.f2fs: allow building per-device superblocks offline when

    formatting a F2FS;

- fsck.f2fs: treat the per-device superblock segments correctly.
- Identify each device in a F2FS by its UUID in struct f2fs_super_block, instead of the path.

---
 fs/f2fs/f2fs.h    |  18 ++++++++
 fs/f2fs/gc.c      |   7 ++-
 fs/f2fs/gc.h      |   5 --
 fs/f2fs/segment.c | 102 +++++++++++++++++++++++++++++++++++++++++
 fs/f2fs/segment.h |   1 +
 fs/f2fs/super.c   | 133 +++++++++++++++++++++++++++++++++++++++++++++++++-----
 6 files changed, 248 insertions(+), 18 deletions(-)
fs/f2fs/f2fs.h +18 -0
index e1d3a94..f994dab 100644
@@ -96,6 +96,7 @@ extern char *fault_name[FAULT_MAX];
 #define F2FS_MOUNT_PRJQUOTA		0x00200000
 #define F2FS_MOUNT_QUOTA		0x00400000
 #define F2FS_MOUNT_INLINE_XATTR_SIZE	0x00800000
+#define F2FS_MOUNT_PER_DEV_SB		0x01000000
 
 #define clear_opt(sbi, option)	((sbi)->mount_opt.opt &= ~F2FS_MOUNT_##option)
 #define set_opt(sbi, option)	((sbi)->mount_opt.opt |= F2FS_MOUNT_##option)
@@ -123,6 +124,7 @@ struct f2fs_mount_info {
 #define F2FS_FEATURE_INODE_CHKSUM	0x0020
 #define F2FS_FEATURE_FLEXIBLE_INLINE_XATTR	0x0040
 #define F2FS_FEATURE_QUOTA_INO		0x0080
+#define F2FS_FEATURE_PER_DEV_SB		0x0100
 
 #define F2FS_HAS_FEATURE(sb, mask)					\
 	((F2FS_SB(sb)->raw_super->feature & cpu_to_le32(mask)) != 0)
@@ -969,6 +971,7 @@ struct f2fs_dev_info {
 	unsigned int nr_blkz;			/* Total number of zones */
 	u8 *blkz_type;				/* Array of zones type */
 #endif
+	bool sb_valid[2];	/* Validity of two per-device superblocks */
 };
 
 enum inode_type {
@@ -2648,6 +2651,8 @@ int build_segment_manager(struct f2fs_sb_info *sbi);
 void destroy_segment_manager(struct f2fs_sb_info *sbi);
 int __init create_segment_manager_caches(void);
 void destroy_segment_manager_caches(void);
+int build_device_sb_sections(struct f2fs_sb_info *sbi);
+void set_per_device_sb_sentries(struct f2fs_sb_info *sbi);
 
 /*
  * checkpoint.c
@@ -2732,12 +2737,20 @@ int f2fs_migrate_page(struct address_space *mapping, struct page *newpage,
 /*
  * gc.c
  */
+struct gc_inode_list {
+	struct list_head ilist;
+	struct radix_tree_root iroot;
+};
+
 int start_gc_thread(struct f2fs_sb_info *sbi);
 void stop_gc_thread(struct f2fs_sb_info *sbi);
 block_t start_bidx_of_node(unsigned int node_ofs, struct inode *inode);
 int f2fs_gc(struct f2fs_sb_info *sbi, bool sync, bool background,
 			unsigned int segno);
 void build_gc_manager(struct f2fs_sb_info *sbi);
+void put_gc_inode(struct gc_inode_list *gc_list);
+int do_garbage_collect(struct f2fs_sb_info *sbi, unsigned int start_segno,
+				struct gc_inode_list *gc_list, int gc_type);
 
 /*
  * recovery.c
@@ -3083,6 +3096,11 @@ static inline int f2fs_sb_has_quota_ino(struct super_block *sb)
 	return F2FS_HAS_FEATURE(sb, F2FS_FEATURE_QUOTA_INO);
 }
 
+static inline int f2fs_sb_has_per_device_sb(struct super_block *sb)
+{
+	return F2FS_HAS_FEATURE(sb, F2FS_FEATURE_PER_DEV_SB);
+}
+
 #ifdef CONFIG_BLK_DEV_ZONED
 static inline int get_blkz_type(struct f2fs_sb_info *sbi,
 			struct block_device *bdev, block_t blkaddr)
fs/f2fs/gc.c +5 -2
index c7b1d70..2f665e2 100644
@@ -438,7 +438,7 @@ static void add_gc_inode(struct gc_inode_list *gc_list, struct inode *inode)
 	list_add_tail(&new_ie->list, &gc_list->ilist);
 }
 
-static void put_gc_inode(struct gc_inode_list *gc_list)
+void put_gc_inode(struct gc_inode_list *gc_list)
 {
 	struct inode_entry *ie, *next_ie;
 	list_for_each_entry_safe(ie, next_ie, &gc_list->ilist, list) {
@@ -900,7 +900,7 @@ static int __get_victim(struct f2fs_sb_info *sbi, unsigned int *victim,
 	return ret;
 }
 
-static int do_garbage_collect(struct f2fs_sb_info *sbi,
+int do_garbage_collect(struct f2fs_sb_info *sbi,
 				unsigned int start_segno,
 				struct gc_inode_list *gc_list, int gc_type)
 {
@@ -913,6 +913,9 @@ static int do_garbage_collect(struct f2fs_sb_info *sbi,
 	unsigned char type = IS_DATASEG(get_seg_entry(sbi, segno)->type) ?
 						SUM_TYPE_DATA : SUM_TYPE_NODE;
 
+	if (get_seg_entry(sbi, segno)->per_dev_sb)
+		return 0;
+
 	/* readahead multi ssa blocks those have contiguous address */
 	if (sbi->segs_per_sec > 1)
 		ra_meta_pages(sbi, GET_SUM_BLOCK(sbi, segno),
fs/f2fs/gc.h +0 -5
index 9325191..01d0da5 100644
@@ -39,11 +39,6 @@ struct f2fs_gc_kthread {
 	unsigned int gc_wake;
 };
 
-struct gc_inode_list {
-	struct list_head ilist;
-	struct radix_tree_root iroot;
-};
-
 /*
  * inline functions
  */
fs/f2fs/segment.c +102 -0

111 lines not on this page · raw message

fs/f2fs/segment.h +1 -0
index 8d93652..dff4b29 100644
@@ -187,6 +187,7 @@ struct seg_entry {
 	unsigned char *ckpt_valid_map;	/* validity bitmap of blocks last cp */
 	unsigned char *discard_map;
 	unsigned long long mtime;	/* modification time of the segment */
+	bool per_dev_sb;
 };
 
 struct sec_entry {
fs/f2fs/super.c +122 -11

212 lines not on this page · raw message

Signature · 1 line
2.5.0