Skip to contentSkip to conversation

f2fs: introduce device aliasing file

PATCH Superseded Daeho Jeong 4 participants 8 messages Oct 10, 2024 – Oct 15, 2024

Subsystems (3)

v5 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

PATCH v5 1/1 f2fs: introduce device aliasing file

From: Daeho Jeong <[email protected]>

F2FS should understand how the device aliasing file works and support deleting the file after use. A device aliasing file can be created by mkfs.f2fs tool and it can map the whole device with an extrent, not using node blocks. The file space should be pinned and normally used for read-only usages.

---
v5: added a ioctl to know whether a file is for device aliasing
v4: added file pinning check in sanity check
v3: merged Chao's extent cache sanity check.
prevented device aliasing support with noextent mount option
v2: changed the position of f2fs_destroy_extent_tree() only for device
aliasing files

---
 fs/f2fs/data.c            |  5 +++++
 fs/f2fs/extent_cache.c    | 45 ++++++++++++++++++++++++++++++++++++++-
 fs/f2fs/f2fs.h            |  5 +++++
 fs/f2fs/file.c            | 44 ++++++++++++++++++++++++++++++++++----
 fs/f2fs/inode.c           | 19 ++++++++++++++++-
 fs/f2fs/super.c           |  4 ++++
 fs/f2fs/sysfs.c           |  2 ++
 include/uapi/linux/f2fs.h |  1 +
 8 files changed, 119 insertions(+), 6 deletions(-)
fs/f2fs/data.c +5 -0
index b94cf6eea2f9..385b46e62ede 100644
@@ -3441,6 +3441,11 @@ static int prepare_write_begin(struct f2fs_sb_info *sbi,
 
 	if (!f2fs_lookup_read_extent_cache_block(inode, index,
 						 &dn.data_blkaddr)) {
+		if (IS_DEVICE_ALIASING(inode)) {
+			err = -ENODATA;
+			goto out;
+		}
+
 		if (locked) {
 			err = f2fs_reserve_block(&dn, index);
 			goto out;
fs/f2fs/extent_cache.c +44 -1

75 lines not on this page · raw message

fs/f2fs/f2fs.h +5 -0
index 33f5449dc22d..b6ba22a1da47 100644
@@ -213,6 +213,7 @@ struct f2fs_mount_info {
 #define F2FS_FEATURE_CASEFOLD			0x00001000
 #define F2FS_FEATURE_COMPRESSION		0x00002000
 #define F2FS_FEATURE_RO				0x00004000
+#define F2FS_FEATURE_DEVICE_ALIAS		0x00008000
 
 #define __F2FS_HAS_FEATURE(raw_super, mask)				\
 	((raw_super->feature & cpu_to_le32(mask)) != 0)
@@ -3046,6 +3047,7 @@ static inline void f2fs_change_bit(unsigned int nr, char *addr)
 #define F2FS_DIRSYNC_FL			0x00010000 /* dirsync behaviour (directories only) */
 #define F2FS_PROJINHERIT_FL		0x20000000 /* Create with parents projid */
 #define F2FS_CASEFOLD_FL		0x40000000 /* Casefolded file */
+#define F2FS_DEVICE_ALIAS_FL		0x80000000 /* File for aliasing a device */
 
 #define F2FS_QUOTA_DEFAULT_FL		(F2FS_NOATIME_FL | F2FS_IMMUTABLE_FL)
 
@@ -3061,6 +3063,8 @@ static inline void f2fs_change_bit(unsigned int nr, char *addr)
 /* Flags that are appropriate for non-directories/regular files. */
 #define F2FS_OTHER_FLMASK	(F2FS_NODUMP_FL | F2FS_NOATIME_FL)
 
+#define IS_DEVICE_ALIASING(inode)	(F2FS_I(inode)->i_flags & F2FS_DEVICE_ALIAS_FL)
+
 static inline __u32 f2fs_mask_flags(umode_t mode, __u32 flags)
 {
 	if (S_ISDIR(mode))
@@ -4510,6 +4514,7 @@ F2FS_FEATURE_FUNCS(sb_chksum, SB_CHKSUM);
 F2FS_FEATURE_FUNCS(casefold, CASEFOLD);
 F2FS_FEATURE_FUNCS(compression, COMPRESSION);
 F2FS_FEATURE_FUNCS(readonly, RO);
+F2FS_FEATURE_FUNCS(device_alias, DEVICE_ALIAS);
 
 #ifdef CONFIG_BLK_DEV_ZONED
 static inline bool f2fs_blkz_is_seq(struct f2fs_sb_info *sbi, int devi,
fs/f2fs/file.c +40 -4

104 lines not on this page · raw message

fs/f2fs/inode.c +18 -1
index 1ed86df343a5..194dc0f53ad8 100644
@@ -372,6 +372,19 @@ static bool sanity_check_inode(struct inode *inode, struct page *node_page)
 		return false;
 	}
 
+	if (IS_DEVICE_ALIASING(inode)) {
+		if (!f2fs_sb_has_device_alias(sbi)) {
+			f2fs_warn(sbi, "%s: inode (ino=%lx) has device alias flag, but the feature is off",
+				  __func__, inode->i_ino);
+			return false;
+		}
+		if (!f2fs_is_pinned_file(inode)) {
+			f2fs_warn(sbi, "%s: inode (ino=%lx) has device alias flag, but is not pinned",
+				  __func__, inode->i_ino);
+			return false;
+		}
+	}
+
 	return true;
 }
 
@@ -823,7 +836,8 @@ void f2fs_evict_inode(struct inode *inode)
 	f2fs_bug_on(sbi, get_dirty_pages(inode));
 	f2fs_remove_dirty_inode(inode);
 
-	f2fs_destroy_extent_tree(inode);
+	if (!IS_DEVICE_ALIASING(inode))
+		f2fs_destroy_extent_tree(inode);
 
 	if (inode->i_nlink || is_bad_inode(inode))
 		goto no_delete;
@@ -879,6 +893,9 @@ void f2fs_evict_inode(struct inode *inode)
 		goto retry;
 	}
 
+	if (IS_DEVICE_ALIASING(inode))
+		f2fs_destroy_extent_tree(inode);
+
 	if (err) {
 		f2fs_update_inode_page(inode);
 		if (dquot_initialize_needed(inode))
fs/f2fs/super.c +4 -0
index fc2c586c7619..95097498b544 100644
@@ -834,6 +834,10 @@ static int parse_options(struct super_block *sb, char *options, bool is_remount)
 			set_opt(sbi, READ_EXTENT_CACHE);
 			break;
 		case Opt_noextent_cache:
+			if (F2FS_HAS_FEATURE(sbi, F2FS_FEATURE_DEVICE_ALIAS)) {
+				f2fs_err(sbi, "device aliasing requires extent cache");
+				return -EINVAL;
+			}
 			clear_opt(sbi, READ_EXTENT_CACHE);
 			break;
 		case Opt_noinline_data:
fs/f2fs/sysfs.c +2 -0
index c56e8c873935..e51304bc65ea 100644
@@ -1313,6 +1313,7 @@ F2FS_SB_FEATURE_RO_ATTR(sb_checksum, SB_CHKSUM);
 F2FS_SB_FEATURE_RO_ATTR(casefold, CASEFOLD);
 F2FS_SB_FEATURE_RO_ATTR(compression, COMPRESSION);
 F2FS_SB_FEATURE_RO_ATTR(readonly, RO);
+F2FS_SB_FEATURE_RO_ATTR(device_alias, DEVICE_ALIAS);
 
 static struct attribute *f2fs_sb_feat_attrs[] = {
 	ATTR_LIST(sb_encryption),
@@ -1329,6 +1330,7 @@ static struct attribute *f2fs_sb_feat_attrs[] = {
 	ATTR_LIST(sb_casefold),
 	ATTR_LIST(sb_compression),
 	ATTR_LIST(sb_readonly),
+	ATTR_LIST(sb_device_alias),
 	NULL,
 };
 ATTRIBUTE_GROUPS(f2fs_sb_feat);
include/uapi/linux/f2fs.h +1 -0
index 955d440be104..f7aaf8d23e20 100644
@@ -43,6 +43,7 @@
 #define F2FS_IOC_DECOMPRESS_FILE	_IO(F2FS_IOCTL_MAGIC, 23)
 #define F2FS_IOC_COMPRESS_FILE		_IO(F2FS_IOCTL_MAGIC, 24)
 #define F2FS_IOC_START_ATOMIC_REPLACE	_IO(F2FS_IOCTL_MAGIC, 25)
+#define F2FS_IOC_GET_DEV_ALIAS_FILE	_IOR(F2FS_IOCTL_MAGIC, 26, __u32)
 
 /*
  * should be same as XFS_IOC_GOINGDOWN.
Signature · 1 line
2.47.0.rc1.288.g06298d1525-goog
maintainer Reviewed-by on v5 1/1
#1 lore raw
Quoted 10 lines · Daeho Jeong

From: Daeho Jeong <[email protected]>

F2FS should understand how the device aliasing file works and support deleting the file after use. A device aliasing file can be created by mkfs.f2fs tool and it can map the whole device with an extrent, not using node blocks. The file space should be pinned and normally used for read-only usages.

Quoted 2 lines

---
v5: added a ioctl to know whether a file is for device aliasing

IMO, maybe we need to add a common wrapper to export all trivial flags of f2fs, which can improve scalability, it benefits the case whenever we want to export new flags.

Thanks,

#2 lore raw
In reply to Daeho Jeong
Quoted 5 lines · Daeho Jeong

From: Daeho Jeong <[email protected]>

F2FS should understand how the device aliasing file works and support deleting the file after use. A device aliasing file can be created by mkfs.f2fs tool and it can map the whole device with an extrent, not

s/extrent/extent/g

Quoted 2 lines

using node blocks. The file space should be pinned and normally used for read-only usages.

Is there an explanation somewhere what a 'device aliasing file' is?

#3 lore raw
Quoted 8 lines · Christoph Hellwig
Quoted 5 lines · Daeho Jeong

From: Daeho Jeong <[email protected]>

F2FS should understand how the device aliasing file works and support deleting the file after use. A device aliasing file can be created by mkfs.f2fs tool and it can map the whole device with an extrent, not

Quoted 6 lines

s/extrent/extent/g

Quoted 2 lines

using node blocks. The file space should be pinned and normally used for read-only usages.

Is there an explanation somewhere what a 'device aliasing file' is?

Plz, refer to this patch and the description there.

https://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs-tools.git/commit/?h=dev-test&id=8cc4e257ec20bee207bb034d5ac406e1ab31eaea

Thank you,

Quoted 1 line
maintainer
#4 lore raw
Quoted 10 lines · Daeho Jeong
Quoted 9 lines · Christoph Hellwig
Quoted 5 lines · Daeho Jeong

From: Daeho Jeong <[email protected]>

F2FS should understand how the device aliasing file works and support deleting the file after use. A device aliasing file can be created by mkfs.f2fs tool and it can map the whole device with an extrent, not

s/extrent/extent/g

Applied with the fix.

Quoted 9 lines
Quoted 5 lines
Quoted 3 lines

using node blocks. The file space should be pinned and normally used for read-only usages.

Is there an explanation somewhere what a 'device aliasing file' is?

Plz, refer to this patch and the description there.

https://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs-tools.git/commit/?h=dev-test&id=8cc4e257ec20bee207bb034d5ac406e1ab31eaea

Also, I added this in the description.

---
For example,
"mkfs.f2fs -c /dev/block/test@test_alias /dev/block/main" gives a file $root/test_alias which carves out /dev/block/test partition.
---

Quoted 11 lines

Thank you,

Quoted 1 line

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

#5 lore raw
Quoted 11 lines · Jaegeuk Kim
Quoted 4 lines

Plz, refer to this patch and the description there.

https://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs-tools.git/commit/?h=dev-test&id=8cc4e257ec20bee207bb034d5ac406e1ab31eaea

Also, I added this in the description.

---
For example,
"mkfs.f2fs -c /dev/block/test@test_alias /dev/block/main" gives a file $root/test_alias which carves out /dev/block/test partition.

What partition?

So mkfs.f2fs adds additional devices based on the man page.

So the above creates a file system with two devices, but the second device is not added to the general space pool, but mapped to a specific file? How does this file work. I guess it can't be unlinked and renamed. It probably also can't be truncated and hole punched, or use insert/collapse range. How does the user find out about this magic file? What is the use case? Are the exact semantics documented somewhere?

maintainer
#6 lore raw
Quoted 17 lines · Christoph Hellwig
Quoted 11 lines · Jaegeuk Kim
Quoted 4 lines

Plz, refer to this patch and the description there.

https://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs-tools.git/commit/?h=dev-test&id=8cc4e257ec20bee207bb034d5ac406e1ab31eaea

Also, I added this in the description.

---
For example,
"mkfs.f2fs -c /dev/block/test@test_alias /dev/block/main" gives a file $root/test_alias which carves out /dev/block/test partition.

What partition?

So mkfs.f2fs adds additional devices based on the man page.

Quoted 7 lines

So the above creates a file system with two devices, but the second device is not added to the general space pool, but mapped to a specific file? How does this file work. I guess it can't be unlinked and renamed. It probably also can't be truncated and hole punched, or use insert/collapse range. How does the user find out about this magic file? What is the use case? Are the exact semantics documented somewhere?

Let me ask for putting some design in Documentation. Just for a quick reference, the use-case looks like:

# ls /dev/vd*
/dev/vdb (32GB) /dev/vdc (32GB)
# mkfs.ext4 /dev/vdc
# mkfs.f2fs -c /dev/[email protected] /dev/vdb
# mount /dev/vdb /mnt/f2fs
# ls -l /mnt/f2fs
vdc.file
# df -h
/dev/vdb                            64G   33G   32G  52% /mnt/f2fs
# mount -o loop /dev/vdc /mnt/ext4
# df -h
/dev/vdb                            64G   33G   32G  52% /mnt/f2fs
/dev/loop7                          32G   24K   30G   1% /mnt/ext4
# umount /mnt/ext4
# f2fs_io getflags /mnt/f2fs/vdc.file 
get a flag on /mnt/f2fs/vdc.file ret=0, flags=nocow(pinned),immutable
# f2fs_io setflags noimmutable /mnt/f2fs/vdc.file
get a flag on noimmutable ret=0, flags=800010
set a flag on /mnt/f2fs/vdc.file ret=0, flags=noimmutable
# rm /mnt/f2fs/vdc.file
# df -h
/dev/vdb                            64G  753M   64G   2% /mnt/f2fs

So, key idea is, user can do any file operations on /dev/vdc, and reclaim the space after the use, while the space is counted as /data. That doesn't require modifying partition size and filesystem format.

#7 lore raw
In reply to Daeho Jeong
Quoted 11 lines · Daeho Jeong
Quoted 10 lines · Christoph Hellwig
Quoted 5 lines · Daeho Jeong

From: Daeho Jeong <[email protected]>

F2FS should understand how the device aliasing file works and support deleting the file after use. A device aliasing file can be created by mkfs.f2fs tool and it can map the whole device with an extrent, not

s/extrent/extent/g

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

using node blocks. The file space should be pinned and normally used for read-only usages.

Is there an explanation somewhere what a 'device aliasing file' is?

Plz, refer to this patch and the description there.

https://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs-tools.git/commit/?h=dev-test&id=8cc4e257ec20bee207bb034d5ac406e1ab31eaea

This is about the extent I know, and I'm still utterly confused.