e2fsprogs: Support for orphan file feature
v2 cover e2fsprogs: Support for orphan file feature
Hello,
this is the second version of support for orphan file feature in e2fsprogs.
Since v1, I have finished and debugged e2fsck support, fixed a couple of issues in mke2fs and tune2fs and also incorporated changes resulting from the review. The only unresolved issue I'm aware of is which reserved inode will we use for this feature.
If nobody speaks up, I will pick up patches from Konstantin to support increasing number of reserved inodes (he implemented it in resize2fs, I will move it to tune2fs by moving some resize2fs functionality to libext2fs). That will practically remove the current limitation of the number of reserved inodes.
Honza
PATCH 2/5 mke2fs: Add support for orphan_file feature
--- misc/mke2fs.8.in | 5 +++++ misc/mke2fs.c | 44 +++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 48 insertions(+), 1 deletion(-)
misc/mke2fs.8.in +5 -0
@@ -359,6 +359,11 @@ filesystem to change based on the user running \fBmke2fs\fR. Set a flag in the filesystem superblock indicating that it may be mounted using experimental kernel code, such as the ext4dev filesystem. .TP +.BI orphan_file_size= size +Set size of the file for tracking unlinked but still open inodes and inodes +with truncate in progress. Larger file allows for better scalability, reserving +a few blocks per cpu is ideal. +.TP .BI discard Attempt to discard blocks at mkfs time (discarding blocks initially is useful on solid state devices and sparse / thin-provisioned storage). When the device
misc/mke2fs.c +43 -1
68 lines not on this page · raw message
Signature · 1 line
2.1.4
PATCH 1/5 libext2fs: Support for orphan file feature
In reply to Jan KaraAdd support for creating and deleting orphan file and a couple of utility functions that will be used in other tools.
--- lib/e2p/feature.c | 4 + lib/ext2fs/Makefile.in | 2 + lib/ext2fs/ext2_fs.h | 11 +++ lib/ext2fs/ext2fs.h | 29 ++++++- lib/ext2fs/orphan.c | 227 +++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 271 insertions(+), 2 deletions(-) create mode 100644 lib/ext2fs/orphan.c
lib/e2p/feature.c +4 -0
@@ -45,6 +45,8 @@ static struct feature feature_list[] = { "snapshot_bitmap" }, {E2P_FEATURE_COMPAT ,EXT4_FEATURE_COMPAT_SPARSE_SUPER2 , "sparse_super2" }, + { E2P_FEATURE_COMPAT, EXT4_FEATURE_COMPAT_ORPHAN_FILE, + "orphan_file" }, { E2P_FEATURE_RO_INCOMPAT, EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER, "sparse_super" },
@@ -70,6 +72,8 @@ static struct feature feature_list[] = { "replica" }, {E2P_FEATURE_RO_INCOMPAT ,EXT4_FEATURE_RO_COMPAT_READONLY , "read-only" }, + { E2P_FEATURE_RO_INCOMPAT, EXT4_FEATURE_RO_COMPAT_ORPHAN_PRESENT, + "orphan_file_used" }, { E2P_FEATURE_INCOMPAT, EXT2_FEATURE_INCOMPAT_COMPRESSION, "compression" },
lib/ext2fs/Makefile.in +2 -0
@@ -109,6 +109,7 @@ OBJS= $(DEBUGFS_LIB_OBJS) $(RESIZE_LIB_OBJS) $(E2IMAGE_LIB_OBJS) \ native.o \ newdir.o \ openfs.o \ + orphan.o \ progress.o \ punch.o \ qcow2.o \
@@ -189,6 +190,7 @@ SRCS= ext2_err.c \ $(srcdir)/native.c \ $(srcdir)/newdir.c \ $(srcdir)/openfs.c \ + $(srcdir)/orphan.c \ $(srcdir)/progress.c \ $(srcdir)/punch.c \ $(srcdir)/qcow2.c \
lib/ext2fs/ext2_fs.h +11 -0
@@ -52,6 +52,7 @@#define EXT2_JOURNAL_INO 8/* Journal inode */ #define EXT2_EXCLUDE_INO 9/* The "exclude" inode, for snapshots */ #define EXT4_REPLICA_INO 10/* Used by non-upstream feature */ +#define EXT4_ORPHAN_INO 9/* Inode with orphan entries */ /* First non-reserved inode for old ext2 filesystems */ #define EXT2_GOOD_OLD_FIRST_INO 11
@@ -769,6 +770,7 @@ struct ext2_super_block {/* #define EXT2_FEATURE_COMPAT_EXCLUDE_INODE 0x0080 not used, legacy */ #define EXT2_FEATURE_COMPAT_EXCLUDE_BITMAP 0x0100#define EXT4_FEATURE_COMPAT_SPARSE_SUPER2 0x0200 +#define EXT4_FEATURE_COMPAT_ORPHAN_FILE 0x0400#define EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER 0x0001
@@ -789,6 +791,7 @@ struct ext2_super_block {#define EXT4_FEATURE_RO_COMPAT_METADATA_CSUM 0x0400#define EXT4_FEATURE_RO_COMPAT_REPLICA 0x0800#define EXT4_FEATURE_RO_COMPAT_READONLY 0x1000 +#define EXT4_FEATURE_RO_COMPAT_ORPHAN_PRESENT 0x2000#define EXT2_FEATURE_INCOMPAT_COMPRESSION 0x0001
@@ -838,6 +841,14 @@ struct ext2_super_block {#define EXT4_DEFM_DISCARD 0x0400#define EXT4_DEFM_NODELALLOC 0x0800 +#define EXT4_ORPHAN_BLOCK_MAGIC 0x0b10ca04 + +/* Structure at the tail of orphan block */ +struct ext4_orphan_block_tail { +__u32 ob_magic; +__u32 ob_checksum; +}; +/* * Structure of a directory entry */
lib/ext2fs/ext2fs.h +27 -2
@@ -555,7 +555,8 @@ typedef struct ext2_icount *ext2_icount_t; EXT2_FEATURE_COMPAT_RESIZE_INODE|\ EXT2_FEATURE_COMPAT_DIR_INDEX|\ EXT2_FEATURE_COMPAT_EXT_ATTR|\ - EXT4_FEATURE_COMPAT_SPARSE_SUPER2) + EXT4_FEATURE_COMPAT_SPARSE_SUPER2|\ + EXT4_FEATURE_COMPAT_ORPHAN_FILE)#ifdef CONFIG_MMP #define EXT4_LIB_INCOMPAT_MMP EXT4_FEATURE_INCOMPAT_MMP
@@ -589,7 +590,8 @@ typedef struct ext2_icount *ext2_icount_t;EXT4_FEATURE_RO_COMPAT_BIGALLOC |\EXT4_LIB_RO_COMPAT_QUOTA |\EXT4_FEATURE_RO_COMPAT_METADATA_CSUM |\ - EXT4_FEATURE_RO_COMPAT_READONLY) +EXT4_FEATURE_RO_COMPAT_READONLY |\ + EXT4_FEATURE_RO_COMPAT_ORPHAN_PRESENT)/* * These features are only allowed if EXT2_FLAG_SOFTSUPP_FEATURES is passed
@@ -1512,6 +1514,13 @@ errcode_t ext2fs_get_data_io(ext2_filsys fs, io_channel *old_io);errcode_t ext2fs_set_data_io (ext2_filsys fs,io_channel new_io);errcode_t ext2fs_rewrite_to_io (ext2_filsys fs,io_channel new_io); +/* orphan.c */ +extern errcode_t ext2fs_create_orphan_file (ext2_filsys fs,blk_t num_blocks); +extern errcode_t ext2fs_truncate_orphan_file (ext2_filsys fs); +extern e2_blkcnt_t ext2fs_default_orphan_file_blocks (__u64 num_blocks); +extern errcode_t ext2fs_orphan_file_block_csum_set (ext2_filsys fs,char *buf); +extern int ext2fs_orphan_file_block_csum_verify (ext2_filsys fs,char *buf); +/* get_pathname.c */ extern errcode_t ext2fs_get_pathname (ext2_filsys fs,ext2_ino_t dir,ext2_ino_t ino,char **name);
@@ -1645,6 +1654,9 @@ extern int ext2fs_dirent_name_len(const struct ext2_dir_entry *entry);extern void ext2fs_dirent_set_name_len (struct ext2_dir_entry *entry,int len);extern int ext2fs_dirent_file_type (const struct ext2_dir_entry *entry);extern void ext2fs_dirent_set_file_type (struct ext2_dir_entry *entry,int type); +extern int ext2fs_inodes_per_orphan_block (ext2_filsys fs); +extern struct ext4_orphan_block_tail *ext2fs_orphan_block_tail (ext2_filsys fs, + char *buf)#endif
@@ -1915,6 +1927,19 @@ _INLINE_ void ext2fs_dirent_set_file_type(struct ext2_dir_entry *entry, int type entry->name_len = (entry->name_len &0xff ) | (type <<8 ); } +_INLINE_ int ext2fs_inodes_per_orphan_block(ext2_filsys fs) +{ +return (fs->blocksize -sizeof (struct ext4_orphan_block_tail )) / +sizeof (__u32); +} + +_INLINE_ struct ext4_orphan_block_tail * +ext2fs_orphan_block_tail (ext2_filsys fs,char *buf) +{ +return (struct ext4_orphan_block_tail *)(buf + fs->blocksize - +sizeof (struct ext4_orphan_block_tail )); +} +#undef _INLINE_#endif
lib/ext2fs/orphan.c new file +227 -0
227 lines not on this page · raw message
Signature · 1 line
2.1.4
PATCH 3/5 e2fsck: Add support for handling orphan file
In reply to Jan Kara--- e2fsck/pass1.c | 27 +++++ e2fsck/problem.c | 80 +++++++++++++ e2fsck/problem.h | 51 +++++++++ e2fsck/super.c | 343 ++++++++++++++++++++++++++++++++++++++++++++++++------- e2fsck/unix.c | 68 +++++++++++ 5 files changed, 530 insertions(+), 39 deletions(-)
e2fsck/pass1.c +27 -0
@@ -1466,6 +1466,33 @@ void e2fsck_pass1(e2fsck_t ctx) inode_size, "pass1"); failed_csum =0 ; } + }else if (ino ==EXT4_ORPHAN_INO ) { +ext2fs_mark_inode_bitmap2 (ctx->inode_used_map, ino); +if (fs->super->s_feature_compat & +EXT4_FEATURE_COMPAT_ORPHAN_FILE ) { +if (!LINUX_S_ISREG (inode->i_mode) && +fix_problem (ctx,PR_1_ORPHAN_FILE_BAD_MODE , + &pctx)) { + inode->i_mode =LINUX_S_IFREG ; +e2fsck_write_inode (ctx, ino, inode, +"pass1" ); + failed_csum =0 ; + } +check_blocks (ctx, &pctx, block_buf); +FINISH_INODE_LOOP (ctx, ino, &pctx, failed_csum); +continue ; + } +if ((inode->i_links_count || + inode->i_blocks || inode->i_block[0 ]) && +fix_problem (ctx,PR_1_ORPHAN_FILE_NOT_CLEAR , + &pctx)) { +memset (inode,0 , inode_size); +ext2fs_icount_store (ctx->inode_link_info, ino, +0 ); +e2fsck_write_inode_full (ctx, ino, inode, + inode_size,"pass1" ); + failed_csum =0 ; + } }else if (ino <EXT2_FIRST_INODE (fs->super)) {problem_t problem =0 ;
e2fsck/problem.c +80 -0
98 lines not on this page · raw message
e2fsck/problem.h +51 -0
69 lines not on this page · raw message
e2fsck/super.c +304 -39
386 lines not on this page · raw message
e2fsck/unix.c +68 -0
76 lines not on this page · raw message
Signature · 1 line
2.1.4
PATCH 4/5 tune2fs: Add support for orphan_file feature
In reply to Jan Kara--- misc/tune2fs.8.in | 5 ++++ misc/tune2fs.c | 84 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 87 insertions(+), 2 deletions(-)
misc/tune2fs.8.in +5 -0
@@ -232,6 +232,11 @@ program. This superblock setting is only honored in 2.6.35+ kernels; and not at all by the ext2 and ext3 file system drivers. .TP +.BI orphan_file_size= size +Set size of the file for tracking unlinked but still open inodes and inodes +with truncate in progress. Larger file allows for better scalability, reserving +a few blocks per cpu is ideal. +.TP .B test_fs Set a flag in the filesystem superblock indicating that it may be mounted using experimental kernel code, such as the ext4dev filesystem.
misc/tune2fs.c +82 -2
120 lines not on this page · raw message
Signature · 1 line
2.1.4
PATCH 5/5 mke2fs: Add orphan_file feature into mke2fs.conf
In reply to Jan KaraEnable orphan_file feature by default in larger filesystems. Since the feature is COMPAT, older kernels will just ignore it and happily work with the filesystem as well.
--- misc/mke2fs.conf.in | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
misc/mke2fs.conf.in +4 -2
@@ -11,21 +11,23 @@ features = has_journal } ext4 = { - features = has_journal,extent,huge_file,flex_bg,uninit_bg,dir_nlink,extra_isize + features = has_journal,extent,huge_file,flex_bg,uninit_bg,dir_nlink,extra_isize,orphan_file auto_64-bit_support = 1 inode_size = 256 } ext4dev = { - features = has_journal,extent,huge_file,flex_bg,metadata_csum,inline_data,64bit,dir_nlink,extra_isize + features = has_journal,extent,huge_file,flex_bg,metadata_csum,inline_data,64bit,dir_nlink,extra_isize,orphan_file inode_size = 256 options = test_fs=1 } small = { + default_features = ^orphan_file blocksize = 1024 inode_size = 128 inode_ratio = 4096 } floppy = { + default_features = ^orphan_file blocksize = 1024 inode_size = 128 inode_ratio = 8192
Signature · 1 line
2.1.4
Hi,
Quoted 25 lines · Shilong Wang
2015-05-26 15:51 GMT+08:00 Jan Kara <[email protected]>:
Quoted 12 lines
Hello,
this is the second version of support for orphan file feature in
e2fsprogs.
Since v1, I have finished and debugged e2fsck support, fixed a couple of issues
in mke2fs and tune2fs and also incorporated changes resulting from the review.
The only unresolved issue I'm aware of is which reserved inode will we use for
this feature.Quoted 6 lines
If nobody speaks up, I will pick up patches from Konstantin to support increasing number of reserved inodes (he implemented it in resize2fs, I will
move it to tune2fs by moving some resize2fs functionality to libext2fs). That
will practically remove the current limitation of the number of reservedinodes.
Quoted 1 line
Quoted 6 lines
Any progress about this? More reserved inodes are also needed by project quota.
BTW, i noticed if i extends_first_ino, many e2fsprogs tests will fail because
tests results reiled on previous confirmed system inodes, any idea about this?
Yes, I'm working on this on-and-off for some time. I already have separated functionality to move blocks and to move inodes from resize2fs into libext2fs. So the hardest part is hopefully done. But it needs testing and I need to figure out whether some group accounting parts also don't need to be moved into libext2fs as they may be needed in more places. So overall it's about one or two days of work to finish this but I get preempted by other stuff...
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR