Allow more than 32000 subdirectories
PATCH 6/13 Allow more than 32000 subdirectories
This patch includes the changes required to e2fsck to understand the nlink count changes made in the kernel. In pass2, while counting the links for a directory, if the link count exceeds 65000, its permanently set to EXT2_NLINK_MAXED (EXT2_LINK_MAX + 100). In pass4, when the counted and actual nlink counts are compared, e2fsck does not flag an error if counted links = EXT2_NLINK_MAXED and existing link count is 1.
It also handles the case when a directory had more than 65000 subdirs and they were later deleted. The nlink count of such a directory remains
1. In pass4 if counted links are 2 and if existing nlink count = 1, e2fsck corrects the nlink count without displaying any errors.
e2fsck/pass2.c +6 -4
@@ -717,7 +717,7 @@ static int check_dir_block(ext2_filsys fblk_t block_nr = db->blk;ext2_ino_t ino = db->ino;ext2_ino_t subdir_parent; -__u16 links; +__u32 links;struct check_dir_struct *cd;char *buf;e2fsck_t ctx;
@@ -1024,9 +1024,11 @@ static int check_dir_block(ext2_filsys f dups_found++; }else dict_alloc_insert (&de_dict, dirent, dirent); - -ext2fs_icount_increment (ctx->inode_count, dirent->inode, - &links); + +ext2fs_icount_inc32 (ctx->inode_count, dirent->inode, &links, +ext2fs_test_inode_bitmap (ctx->inode_dir_map, + dirent->inode) ? +EXT2_LINK_MAX : (__u32 )~0U );if (links >1 ) ctx->fs_links_count++; ctx->fs_total_count++;
e2fsck/pass4.c +14 -6
@@ -99,7 +99,8 @@ void e2fsck_pass4(e2fsck_t ctx)struct resource_track rtrack;#endif struct problem_context pctx; -__u16 link_count, link_counted; +__u16 link_count; +__u32 link_counted;char *buf =0 ;int group, maxgroup;
@@ -145,7 +146,7 @@ void e2fsck_pass4(e2fsck_t ctx) ext2fs_test_inode_bitmap(ctx->inode_bb_map, i))) continue;ext2fs_icount_fetch (ctx->inode_link_info, i, &link_count); -ext2fs_icount_fetch (ctx->inode_count, i, &link_counted); +ext2fs_icount_fetch32 (ctx->inode_count, i, &link_counted);if (link_counted ==0 ) {if (!buf) buf = e2fsck_allocate_memory(ctx,
@@ -156,10 +157,12 @@ void e2fsck_pass4(e2fsck_t ctx)continue ;ext2fs_icount_fetch (ctx->inode_link_info, i, &link_count); -ext2fs_icount_fetch (ctx->inode_count, i, - &link_counted); +ext2fs_icount_fetch32 (ctx->inode_count, i, + &link_counted); } -if (link_counted != link_count) { +if (link_counted != link_count && + !(ext2fs_test_inode_bitmap (ctx->inode_dir_map, i) && + link_count ==1 && link_counted >EXT2_LINK_MAX )) {e2fsck_read_inode (ctx, i, inode,"pass4" ); pctx.ino = i; pctx.inode = inode;
@@ -169,7 +172,12 @@ void e2fsck_pass4(e2fsck_t ctx) PR_4_INCONSISTENT_COUNT, &pctx); } pctx.num = link_counted; -if (fix_problem (ctx,PR_4_BAD_REF_COUNT , &pctx)) { +/* i_link_count was previously exceeded, but no longer +* is, fix this but don't consider it an error */ +if ((LINUX_S_ISDIR (inode->i_mode) && link_counted >1 && + (inode->i_flags &EXT2_INDEX_FL ) && + link_count ==1 && !(ctx->options &E2F_OPT_NO )) || + (fix_problem (ctx,PR_4_BAD_REF_COUNT , &pctx))) { inode->i_links_count = link_counted;e2fsck_write_inode (ctx, i, inode,"pass4" ); }
lib/ext2fs/ext2_fs.h +1 -0
@@ -646,6 +646,7 @@ struct ext2_super_block {#define EXT2_FEATURE_INCOMPAT_SUPP (EXT2_FEATURE_INCOMPAT_FILETYPE)#define EXT2_FEATURE_RO_COMPAT_SUPP (EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER| \ EXT2_FEATURE_RO_COMPAT_LARGE_FILE| \ + EXT4_FEATURE_RO_COMPAT_DIR_NLINK| \ EXT2_FEATURE_RO_COMPAT_BTREE_DIR)/*
lib/ext2fs/ext2fs.h +10 -2
@@ -462,7 +462,8 @@ typedef struct ext2_icount *ext2_icount_ EXT3_FEATURE_INCOMPAT_RECOVER)#endif #define EXT2_LIB_FEATURE_RO_COMPAT_SUPP (EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER|\ - EXT2_FEATURE_RO_COMPAT_LARGE_FILE) + EXT2_FEATURE_RO_COMPAT_LARGE_FILE|\ + EXT4_FEATURE_RO_COMPAT_DIR_NLINK)/* * These features are only allowed if EXT2_FLAG_SOFTSUPP_FEATURES is passed
@@ -471,7 +472,6 @@ typedef struct ext2_icount *ext2_icount_#define EXT2_LIB_SOFTSUPP_INCOMPAT (EXT3_FEATURE_INCOMPAT_EXTENTS)#define EXT2_LIB_SOFTSUPP_RO_COMPAT (EXT4_FEATURE_RO_COMPAT_HUGE_FILE|\ EXT4_FEATURE_RO_COMPAT_GDT_CSUM|\ - EXT4_FEATURE_RO_COMPAT_DIR_NLINK|\ EXT4_FEATURE_RO_COMPAT_EXTRA_ISIZE)/*
@@ -795,12 +795,20 @@ extern errcode_t ext2fs_create_icount2(eextern errcode_t ext2fs_create_icount (ext2_filsys fs,int flags,unsigned int size,ext2_icount_t *ret); +extern errcode_t ext2fs_icount_fetch32 (ext2_icount_t icount,ext2_ino_t ino, +__u32 *ret);extern errcode_t ext2fs_icount_fetch (ext2_icount_t icount,ext2_ino_t ino,__u16 *ret); +extern errcode_t ext2fs_icount_inc32 (ext2_icount_t icount,ext2_ino_t ino, +__u32 *ret,__u32 overflow);extern errcode_t ext2fs_icount_increment (ext2_icount_t icount,ext2_ino_t ino,__u16 *ret); +extern errcode_t ext2fs_icount_dec32 (ext2_icount_t icount,ext2_ino_t ino, +__u32 *ret);extern errcode_t ext2fs_icount_decrement (ext2_icount_t icount,ext2_ino_t ino,__u16 *ret); +extern errcode_t ext2fs_icount_store32 (ext2_icount_t icount,ext2_ino_t ino, +__u32 count);extern errcode_t ext2fs_icount_store (ext2_icount_t icount,ext2_ino_t ino,__u16 count);extern ext2_ino_t ext2fs_get_icount_size (ext2_icount_t icount);
lib/ext2fs/icount.c +62 -15
154 lines not on this page · raw message
e2fsck/pass3.c +6 -3
@@ -581,19 +581,22 @@ errcode_t e2fsck_adjust_inode_count(e2fs#endif if (adj ==1 ) { -ext2fs_icount_increment (ctx->inode_count, ino,0 ); +ext2fs_icount_inc32 (ctx->inode_count, ino,0 , +ext2fs_test_inode_bitmap (ctx->inode_dir_map, + ino) ? +EXT2_LINK_MAX : ~0U );if (inode.i_links_count == (__u16 ) ~0 )return 0 ;ext2fs_icount_increment (ctx->inode_link_info, ino,0 ); inode.i_links_count++; }else if (adj ==-1 ) { -ext2fs_icount_decrement (ctx->inode_count, ino,0 ); +ext2fs_icount_dec32 (ctx->inode_count, ino,0 );if (inode.i_links_count ==0 )return 0 ;ext2fs_icount_decrement (ctx->inode_link_info, ino,0 ); inode.i_links_count--; } - + retval =ext2fs_write_inode (fs, ino, &inode);if (retval)return retval;
Quoted 6 lines · Girish Shilamkar
This patch includes the changes required to e2fsck to understand the nlink count changes made in the kernel. In pass2, while counting the links for a directory, if the link count exceeds 65000, its permanently set to
EXT2_NLINK_MAXED(EXT2_LINK_MAX+ 100). In pass4, when the counted and actual nlink counts are compared, e2fsck does not flag an error if counted links =EXT2_NLINK_MAXEDand existing link count is 1.
Has this actually been implemented in the kernel? I don't think I've seen a patch which implements the a large number file links. The 65000 subdir patch does *not* define EXT2_NLINK_MAXED, nor does this
patch. And this patch seems to use EXT2_LINK_MAX + 10, not +100.
- Ted
Quoted 8 lines · Theodore Tso
Quoted 6 lines · Girish Shilamkar
This patch includes the changes required to e2fsck to understand the nlink count changes made in the kernel. In pass2, while counting the links for a directory, if the link count exceeds 65000, its permanently set to
EXT2_NLINK_MAXED(EXT2_LINK_MAX+ 100). In pass4, when the counted and actual nlink counts are compared, e2fsck does not flag an error if counted links =EXT2_NLINK_MAXEDand existing link count is 1.
Quoted 4 lines
Has this actually been implemented in the kernel? I don't think I've seen a patch which implements the a large number file links. The 65000 subdir patch does *not* define
EXT2_NLINK_MAXED, nor does this
patch. And this patch seems to useEXT2_LINK_MAX+ 10, not +100.
I haven't tested hard-linked files myself, but they should remain with a limit of EXT2_LINK_MAX. It is only for directories that the link count can be exceeded. We have definitely tested with > 65000 subdirs.
Cheers, Andreas
--
Andreas Dilger
Principal Software Engineer
Cluster File Systems, Inc.