Skip to contentSkip to conversation

64 bit inode counter support

PATCH In review Artem Blagodarenko 3 participants 7 messages Feb 2, 2018 – Feb 18, 2018 ext4 file system

lore
Share & tools
lore
#0 lore raw

v4 cover 64 bit inode counter support

With current hardware clusters faced with the trouble of creating enough inodes on partitions. Lustre has 0-size files to store some information about files. Current MDS disk sizes allow to store large amount of such files, but EXT4 limits this number to ~4 billions.

Lustre FS has features like DNE to distribute metadata over many targets (disks), but disks are used not effectively. It would be great to have ability to store more then ~4 billions inodes on one EXT4 file system.

This patches add 1) dirdata feature, that allow to store additional data in direntry 2) code that uses dirdata to store high bits of 64bit inode number.

This is 4th version of the patch set. Changes since v3:

* ext4_warning_inode() is used to print messages
* DIRENT_INODE_LEN size is 4 bytes
* using structures to access dirdata fields
* some code pieces moved to appropriate patches
* added high part for s_last_orphan, s_first_error_ino, and s_last_error_ino fields
* ext4_dirent_inohi changed to ext4_dirent_inode64
* s_inode_goal become 64 bit
* __u64 goal in ext4_ext_migrate()
* added functions set_inode() and get_inode()
(in separate patch 3/4)
* 64 bit support in htree_inlinedir_to_tree(), ext4_try_create_inline_dir() and ext4_add_dirent_to_inline()
* skip the NUL separator after the name
* high part of inode number is accessed only if EXT4_DIRENT_INODE64 enabled
* 64bit support for ext4_rename_dir_prepare(), ext4_rename_dir_finish(), ext4_rename_delete(), ext4_cross_rename(), ext4_empty_dir(), ext4_rmdir(), ext4_rename(), ext4_unlink(), and ext4_setent()
* heleper functions for access to high part of superblock fields based on macroses
* high part of inode number is copied to prevent align problems
* style fixes

Andreas Dilger (1):
ext4: dirdata feature

Artem Blagodarenko (2):
ext4: Add helper functions to access inode numbers
ext4: Add 64-bit inode number support

Yang Sheng (1):
ext4: Removes static definition of dx_root struct

 fs/ext4/dir.c     |  20 ++-
 fs/ext4/ext4.h    | 182 +++++++++++++++++++++----
 fs/ext4/ialloc.c  |  19 ++-
 fs/ext4/inline.c  |  47 ++++---
 fs/ext4/inode.c   |   5 +
 fs/ext4/migrate.c |   2 +-
 fs/ext4/namei.c   | 390 ++++++++++++++++++++++++++++++++++++++----------------
 fs/ext4/resize.c  |   8 +-
 fs/ext4/super.c   |  54 ++++----
 9 files changed, 528 insertions(+), 199 deletions(-)
Signature · 1 line
2.14.3 (Apple Git-98)
#1 lore raw

PATCH v4 1/4 ext4: Removes static definition of dx_root struct

From: Yang Sheng <[email protected]>

Removes static definition of dx_root struct. so that "." and ".." dirent can have extra data. This patch does not change any functionality but is required for ext4_data_in_dirent patch.

---
 fs/ext4/namei.c | 125 ++++++++++++++++++++++++++++++--------------------------
 1 file changed, 68 insertions(+), 57 deletions(-)
fs/ext4/namei.c +68 -57
index c1cf020d1889..0cb6a061aff6 100644
@@ -193,23 +193,13 @@ struct dx_entry
  * dirent the two low bits of the hash version will be zero.  Therefore, the
  * hash version mod 4 should never be 0.  Sincerely, the paranoia department.
  */
-
-struct dx_root
+struct dx_root_info
 {
-	struct fake_dirent dot;
-	char dot_name[4];
-	struct fake_dirent dotdot;
-	char dotdot_name[4];
-	struct dx_root_info
-	{
-		__le32 reserved_zero;
-		u8 hash_version;
-		u8 info_length; /* 8 */
-		u8 indirect_levels;
-		u8 unused_flags;
-	}
-	info;
-	struct dx_entry	entries[0];
+	__le32 reserved_zero;
+	u8 hash_version;
+	u8 info_length; /* 8 */
+	u8 indirect_levels;
+	u8 unused_flags;
 };
 
 struct dx_node
@@ -521,6 +511,17 @@ static inline void dx_set_block(struct dx_entry *entry, ext4_lblk_t value)
 	entry->block = cpu_to_le32(value);
 }
 
+struct dx_root_info *dx_get_dx_info(struct ext4_dir_entry_2 *de)
+{
+	/* get dotdot first */
+	de = (struct ext4_dir_entry_2 *)((char *)de + EXT4_DIR_NAME_LEN(1));
+
+	/* dx root info is after dotdot entry */
+	de = (struct ext4_dir_entry_2 *)((char *)de + EXT4_DIR_NAME_LEN(2));
+
+	return (struct dx_root_info *)de;
+}
+
 static inline unsigned dx_get_hash(struct dx_entry *entry)
 {
 	return le32_to_cpu(entry->hash);
@@ -734,7 +735,7 @@ dx_probe(struct ext4_filename *fname, struct inode *dir,
 {
 	unsigned count, indirect;
 	struct dx_entry *at, *entries, *p, *q, *m;
-	struct dx_root *root;
+	struct dx_root_info *info;
 	struct dx_frame *frame = frame_in;
 	struct dx_frame *ret_err = ERR_PTR(ERR_BAD_DX_DIR);
 	u32 hash;
@@ -744,17 +745,17 @@ dx_probe(struct ext4_filename *fname, struct inode *dir,
 	if (IS_ERR(frame->bh))
 		return (struct dx_frame *) frame->bh;
 
-	root = (struct dx_root *) frame->bh->b_data;
-	if (root->info.hash_version != DX_HASH_TEA &&
-	    root->info.hash_version != DX_HASH_HALF_MD4 &&
-	    root->info.hash_version != DX_HASH_LEGACY) {
+	info = dx_get_dx_info((struct ext4_dir_entry_2 *)frame->bh->b_data);
+	if (info->hash_version != DX_HASH_TEA &&
+	    info->hash_version != DX_HASH_HALF_MD4 &&
+	    info->hash_version != DX_HASH_LEGACY) {
 		ext4_warning_inode(dir, "Unrecognised inode hash code %u",
-				   root->info.hash_version);
+				   info->hash_version);
 		goto fail;
 	}
 	if (fname)
 		hinfo = &fname->hinfo;
-	hinfo->hash_version = root->info.hash_version;
+	hinfo->hash_version = info->hash_version;
 	if (hinfo->hash_version <= DX_HASH_TEA)
 		hinfo->hash_version += EXT4_SB(dir->i_sb)->s_hash_unsigned;
 	hinfo->seed = EXT4_SB(dir->i_sb)->s_hash_seed;
@@ -762,18 +763,17 @@ dx_probe(struct ext4_filename *fname, struct inode *dir,
 		ext4fs_dirhash(fname_name(fname), fname_len(fname), hinfo);
 	hash = hinfo->hash;
 
-	if (root->info.unused_flags & 1) {
+	if (info->unused_flags & 1) {
 		ext4_warning_inode(dir, "Unimplemented hash flags: %#06x",
-				   root->info.unused_flags);
+				   info->unused_flags);
 		goto fail;
 	}
 
-	indirect = root->info.indirect_levels;
+	indirect = info->indirect_levels;
 	if (indirect >= ext4_dir_htree_level(dir->i_sb)) {
-		ext4_warning(dir->i_sb,
-			     "Directory (ino: %lu) htree depth %#06x exceed"
-			     "supported value", dir->i_ino,
-			     ext4_dir_htree_level(dir->i_sb));
+		ext4_warning_inode(dir,
+			"directory htree depth %u exceeds supported value",
+			ext4_dir_htree_level(dir->i_sb));
 		if (ext4_dir_htree_level(dir->i_sb) < EXT4_HTREE_LEVEL) {
 			ext4_warning(dir->i_sb, "Enable large directory "
 						"feature to access it");
@@ -781,14 +781,17 @@ dx_probe(struct ext4_filename *fname, struct inode *dir,
 		goto fail;
 	}
 
-	entries = (struct dx_entry *)(((char *)&root->info) +
-				      root->info.info_length);
+	entries = (struct dx_entry *)(((char *)info) + info->info_length);
 
-	if (dx_get_limit(entries) != dx_root_limit(dir,
-						   root->info.info_length)) {
+	if (dx_get_limit(entries) !=
+	    dx_root_limit(dir, (struct ext4_dir_entry_2 *) frame->bh->b_data,
+			  info->info_length)) {
 		ext4_warning_inode(dir, "dx entry: limit %u != root limit %u",
 				   dx_get_limit(entries),
-				   dx_root_limit(dir, root->info.info_length));
+				   dx_root_limit(dir,
+						 (struct ext4_dir_entry_2 *)
+						 frame->bh->b_data,
+						 info->info_length));
 		goto fail;
 	}
 
@@ -872,7 +875,7 @@ static void dx_release(struct dx_frame *frames)
 	if (frames[0].bh == NULL)
 		return;
 
-	info = &((struct dx_root *)frames[0].bh->b_data)->info;
+	info = dx_get_dx_info((struct ext4_dir_entry_2 *)frames[0].bh->b_data);
 	for (i = 0; i <= info->indirect_levels; i++) {
 		if (frames[i].bh == NULL)
 			break;
@@ -1907,17 +1910,16 @@ static int make_indexed_dir(handle_t *handle, struct ext4_filename *fname,
 			    struct inode *inode, struct buffer_head *bh)
 {
 	struct buffer_head *bh2;
-	struct dx_root	*root;
 	struct dx_frame	frames[EXT4_HTREE_LEVEL], *frame;
 	struct dx_entry *entries;
-	struct ext4_dir_entry_2	*de, *de2;
+	struct ext4_dir_entry_2 *de, *de2, *dot_de, *dotdot_de;
 	struct ext4_dir_entry_tail *t;
 	char		*data1, *top;
 	unsigned	len;
 	int		retval;
 	unsigned	blocksize;
 	ext4_lblk_t  block;
-	struct fake_dirent *fde;
+	struct dx_root_info *dx_info;
 	int csum_size = 0;
 
 	if (ext4_has_metadata_csum(inode->i_sb))
@@ -1932,18 +1934,19 @@ static int make_indexed_dir(handle_t *handle, struct ext4_filename *fname,
 		brelse(bh);
 		return retval;
 	}
-	root = (struct dx_root *) bh->b_data;
+
+	dot_de = (struct ext4_dir_entry_2 *)bh->b_data;
+	dotdot_de = ext4_next_entry(dot_de, blocksize);
 
 	/* The 0th block becomes the root, move the dirents out */
-	fde = &root->dotdot;
-	de = (struct ext4_dir_entry_2 *)((char *)fde +
-		ext4_rec_len_from_disk(fde->rec_len, blocksize));
-	if ((char *) de >= (((char *) root) + blocksize)) {
+	de = (struct ext4_dir_entry_2 *)((char *)dotdot_de +
+		ext4_rec_len_from_disk(dotdot_de->rec_len, blocksize));
+	if ((char *)de >= (((char *)dot_de) + blocksize)) {
 		EXT4_ERROR_INODE(dir, "invalid rec_len for '..'");
 		brelse(bh);
 		return -EFSCORRUPTED;
 	}
-	len = ((char *) root) + (blocksize - csum_size) - (char *) de;
+	len = ((char *)dot_de) + (blocksize - csum_size) - (char *)de;
 
 	/* Allocate new block for the 0th block's dirents */
 	bh2 = ext4_append(handle, dir, &block);
@@ -1969,19 +1972,26 @@ static int make_indexed_dir(handle_t *handle, struct ext4_filename *fname,
 	}
 
 	/* Initialize the root; the dot dirents already exist */
-	de = (struct ext4_dir_entry_2 *) (&root->dotdot);
-	de->rec_len = ext4_rec_len_to_disk(blocksize - EXT4_DIR_REC_LEN(2),
-					   blocksize);
-	memset (&root->info, 0, sizeof(root->info));
-	root->info.info_length = sizeof(root->info);
-	root->info.hash_version = EXT4_SB(dir->i_sb)->s_def_hash_version;
-	entries = root->entries;
+	dotdot_de->rec_len =
+		ext4_rec_len_to_disk(blocksize - le16_to_cpu(dot_de->rec_len),
+				     blocksize);
+
+	/* initialize hashing info */
+	dx_info = dx_get_dx_info(dot_de);
+	memset(dx_info, 0, sizeof(*dx_info));
+	dx_info->info_length = sizeof(*dx_info);
+	dx_info->hash_version = EXT4_SB(dir->i_sb)->s_def_hash_version;
+
+	entries = (void *)dx_info + sizeof(*dx_info);
+
 	dx_set_block(entries, 1);
 	dx_set_count(entries, 1);
-	dx_set_limit(entries, dx_root_limit(dir, sizeof(root->info)));
+	dx_set_limit(entries, dx_root_limit(dir, (struct ext4_dir_entry_2 *)
+					    frame->bh->b_data,
+					    sizeof(*dx_info)));
 
 	/* Initialize as for dx_probe */
-	fname->hinfo.hash_version = root->info.hash_version;
+	fname->hinfo.hash_version = dx_info->hash_version;
 	if (fname->hinfo.hash_version <= DX_HASH_TEA)
 		fname->hinfo.hash_version += EXT4_SB(dir->i_sb)->s_hash_unsigned;
 	fname->hinfo.seed = EXT4_SB(dir->i_sb)->s_hash_seed;
@@ -2252,7 +2262,7 @@ static int ext4_dx_add_entry(handle_t *handle, struct ext4_filename *fname,
 				goto journal_error;
 			}
 		} else {
-			struct dx_root *dxroot;
+			struct dx_root_info *info;
 			memcpy((char *) entries2, (char *) entries,
 			       icount * sizeof(struct dx_entry));
 			dx_set_limit(entries2, dx_node_limit(dir));
@@ -2260,8 +2270,9 @@ static int ext4_dx_add_entry(handle_t *handle, struct ext4_filename *fname,
 			/* Set up root */
 			dx_set_count(entries, 1);
 			dx_set_block(entries + 0, newblock);
-			dxroot = (struct dx_root *)frames[0].bh->b_data;
-			dxroot->info.indirect_levels += 1;
+			info = dx_get_dx_info((struct ext4_dir_entry_2 *)
+					      frames[0].bh->b_data);
+			info->indirect_levels += 1;
 			dxtrace(printk(KERN_DEBUG
 				       "Creating %d level index...\n",
 				       info->indirect_levels));
Signature · 1 line
2.14.3 (Apple Git-98)
#2 lore raw

PATCH v4 2/4 ext4: dirdata feature

In reply to Artem Blagodarenko

From: Andreas Dilger <[email protected]>

This patch implements feature which allows ext4 fs users (e.g. Lustre) to store data in ext4 dirent. Data is stored in ext4 dirent after file-name, this space is accounted in de->rec_len.
Flag EXT4_DIRENT_LUFID added to d_type if extra data
is present.

Make use of dentry->d_fsdata to pass fid to ext4. so no changes in ext4_add_entry() interface required.

---
 fs/ext4/dir.c    |  16 +++++---
 fs/ext4/ext4.h   | 102 ++++++++++++++++++++++++++++++++++++++++++++---
 fs/ext4/inline.c |  18 ++++-----
 fs/ext4/namei.c  | 119 ++++++++++++++++++++++++++++++++++++++++++-------------
 fs/ext4/super.c  |   3 +-
 5 files changed, 210 insertions(+), 48 deletions(-)
fs/ext4/dir.c +11 -5
index b04e882179c6..02d6fd0d643e 100644
@@ -67,11 +67,11 @@ int __ext4_check_dir_entry(const char *function, unsigned int line,
 	const int rlen = ext4_rec_len_from_disk(de->rec_len,
 						dir->i_sb->s_blocksize);
 
-	if (unlikely(rlen < EXT4_DIR_REC_LEN(1)))
+	if (unlikely(rlen < EXT4_DIR_NAME_LEN(1)))
 		error_msg = "rec_len is smaller than minimal";
 	else if (unlikely(rlen % 4 != 0))
 		error_msg = "rec_len % 4 != 0";
-	else if (unlikely(rlen < EXT4_DIR_REC_LEN(de->name_len)))
+	else if (unlikely(rlen < EXT4_DIR_REC_LEN(de)))
 		error_msg = "rec_len is too small for name_len";
 	else if (unlikely(((char *) de - buf) + rlen > size))
 		error_msg = "directory entry across range";
@@ -218,7 +218,8 @@ static int ext4_readdir(struct file *file, struct dir_context *ctx)
 				 * failure will be detected in the
 				 * dirent test below. */
 				if (ext4_rec_len_from_disk(de->rec_len,
-					sb->s_blocksize) < EXT4_DIR_REC_LEN(1))
+							   sb->s_blocksize) <
+				    EXT4_DIR_NAME_LEN(1))
 					break;
 				i += ext4_rec_len_from_disk(de->rec_len,
 							    sb->s_blocksize);
@@ -441,12 +442,17 @@ int ext4_htree_store_dirent(struct file *dir_file, __u32 hash,
 	struct fname *fname, *new_fn;
 	struct dir_private_info *info;
 	int len;
+	int extra_data = 0;
 
 	info = dir_file->private_data;
 	p = &info->root.rb_node;
 
 	/* Create and allocate the fname structure */
-	len = sizeof(struct fname) + ent_name->len + 1;
+	if (dirent->file_type & ~EXT4_FT_MASK)
+		extra_data = ext4_get_dirent_data_len(dirent);
+
+	len = sizeof(struct fname) + dirent->name_len + extra_data + 1;
+
 	new_fn = kzalloc(len, GFP_KERNEL);
 	if (!new_fn)
 		return -ENOMEM;
@@ -455,7 +461,7 @@ int ext4_htree_store_dirent(struct file *dir_file, __u32 hash,
 	new_fn->inode = le32_to_cpu(dirent->inode);
 	new_fn->name_len = ent_name->len;
 	new_fn->file_type = dirent->file_type;
-	memcpy(new_fn->name, ent_name->name, ent_name->len);
+	memcpy(new_fn->name, ent_name->name, ent_name->len + extra_data);
 	new_fn->name[ent_name->len] = 0;
 
 	while (*p) {
fs/ext4/ext4.h +97 -5

147 lines not on this page · raw message

fs/ext4/inline.c +9 -9
index 28c5c3abddb3..666891dc03cd 100644
@@ -1026,7 +1026,7 @@ static int ext4_add_dirent_to_inline(handle_t *handle,
 	struct ext4_dir_entry_2 *de;
 
 	err = ext4_find_dest_de(dir, inode, iloc->bh, inline_start,
-				inline_size, fname, &de);
+				inline_size, fname, &de, 0, NULL, 0);
 	if (err)
 		return err;
 
@@ -1103,7 +1103,7 @@ static int ext4_update_inline_dir(handle_t *handle, struct inode *dir,
 	int old_size = EXT4_I(dir)->i_inline_size - EXT4_MIN_INLINE_DATA_SIZE;
 	int new_size = get_max_inline_xattr_value_size(dir, iloc);
 
-	if (new_size - old_size <= EXT4_DIR_REC_LEN(1))
+	if (new_size - old_size <= EXT4_DIR_NAME_LEN(1))
 		return -ENOSPC;
 
 	ret = ext4_update_inline_data(handle, dir,
@@ -1384,8 +1384,8 @@ int htree_inlinedir_to_tree(struct file *dir_file,
 			fake.name_len = 1;
 			strcpy(fake.name, ".");
 			fake.rec_len = ext4_rec_len_to_disk(
-						EXT4_DIR_REC_LEN(fake.name_len),
-						inline_size);
+					EXT4_DIR_NAME_LEN(fake.name_len),
+					inline_size);
 			ext4_set_de_type(inode->i_sb, &fake, S_IFDIR);
 			de = &fake;
 			pos = EXT4_INLINE_DOTDOT_OFFSET;
@@ -1394,8 +1394,8 @@ int htree_inlinedir_to_tree(struct file *dir_file,
 			fake.name_len = 2;
 			strcpy(fake.name, "..");
 			fake.rec_len = ext4_rec_len_to_disk(
-						EXT4_DIR_REC_LEN(fake.name_len),
-						inline_size);
+					EXT4_DIR_NAME_LEN(fake.name_len),
+					inline_size);
 			ext4_set_de_type(inode->i_sb, &fake, S_IFDIR);
 			de = &fake;
 			pos = EXT4_INLINE_DOTDOT_SIZE;
@@ -1492,8 +1492,8 @@ int ext4_read_inline_dir(struct file *file,
 	 * So we will use extra_offset and extra_size to indicate them
 	 * during the inline dir iteration.
 	 */
-	dotdot_offset = EXT4_DIR_REC_LEN(1);
-	dotdot_size = dotdot_offset + EXT4_DIR_REC_LEN(2);
+	dotdot_offset = EXT4_DIR_NAME_LEN(1);
+	dotdot_size = dotdot_offset + EXT4_DIR_NAME_LEN(2);
 	extra_offset = dotdot_size - EXT4_INLINE_DOTDOT_SIZE;
 	extra_size = extra_offset + inline_size;
 
@@ -1528,7 +1528,7 @@ int ext4_read_inline_dir(struct file *file,
 			 * failure will be detected in the
 			 * dirent test below. */
 			if (ext4_rec_len_from_disk(de->rec_len, extra_size)
-				< EXT4_DIR_REC_LEN(1))
+				< EXT4_DIR_NAME_LEN(1))
 				break;
 			i += ext4_rec_len_from_disk(de->rec_len,
 						    extra_size);
fs/ext4/namei.c +91 -28

272 lines not on this page · raw message

fs/ext4/super.c +2 -1
index b0915b734a38..ead9406d9cff 100644
@@ -1339,7 +1339,7 @@ enum {
 	Opt_data_err_abort, Opt_data_err_ignore, Opt_test_dummy_encryption,
 	Opt_usrjquota, Opt_grpjquota, Opt_offusrjquota, Opt_offgrpjquota,
 	Opt_jqfmt_vfsold, Opt_jqfmt_vfsv0, Opt_jqfmt_vfsv1, Opt_quota,
-	Opt_noquota, Opt_barrier, Opt_nobarrier, Opt_err,
+	Opt_noquota, Opt_barrier, Opt_nobarrier, Opt_err, Opt_dirdata,
 	Opt_usrquota, Opt_grpquota, Opt_prjquota, Opt_i_version, Opt_dax,
 	Opt_stripe, Opt_delalloc, Opt_nodelalloc, Opt_mblk_io_submit,
 	Opt_lazytime, Opt_nolazytime, Opt_debug_want_extra_isize,
@@ -1400,6 +1400,7 @@ static const match_table_t tokens = {
 	{Opt_noquota, "noquota"},
 	{Opt_quota, "quota"},
 	{Opt_usrquota, "usrquota"},
+	{Opt_dirdata, "dirdata"},
 	{Opt_prjquota, "prjquota"},
 	{Opt_barrier, "barrier=%u"},
 	{Opt_barrier, "barrier"},
Signature · 1 line
2.14.3 (Apple Git-98)
#3 lore raw

PATCH v4 3/4 ext4: Add helper functions to access inode numbers

In reply to Artem Blagodarenko

64-bit inodes counter uses extra fields to store hight part. Let's incapsulate inode number reading and writing to extend counter in next commits.

---
 fs/ext4/dir.c    |  4 +--
 fs/ext4/ext4.h   | 44 +++++++++++++++++++++++---------
 fs/ext4/ialloc.c | 12 ++++-----
 fs/ext4/namei.c  | 78 +++++++++++++++++++++++++++++++++++++++-----------------
 fs/ext4/resize.c |  8 +++---
 fs/ext4/super.c  | 45 ++++++++++++++++----------------
 6 files changed, 121 insertions(+), 70 deletions(-)
fs/ext4/dir.c +2 -2
index 02d6fd0d643e..49ddbbf1ed90 100644
@@ -76,7 +76,7 @@ int __ext4_check_dir_entry(const char *function, unsigned int line,
 	else if (unlikely(((char *) de - buf) + rlen > size))
 		error_msg = "directory entry across range";
 	else if (unlikely(le32_to_cpu(de->inode) >
-			le32_to_cpu(EXT4_SB(dir->i_sb)->s_es->s_inodes_count)))
+		 ext4_get_inodes_count(dir->i_sb)))
 		error_msg = "inode out of bounds";
 	else
 		return 0;
@@ -382,7 +382,7 @@ struct fname {
 	__u32		minor_hash;
 	struct rb_node	rb_hash;
 	struct fname	*next;
-	__u32		inode;
+	__u64		inode;
 	__u8		name_len;
 	__u8		file_type;
 	char		name[0];
fs/ext4/ext4.h +32 -12

56 lines not on this page · raw message

fs/ext4/ialloc.c +6 -6
index ee823022aa34..25dbc15e2ee1 100644
@@ -303,7 +303,7 @@ void ext4_free_inode(handle_t *handle, struct inode *inode)
 	ext4_clear_inode(inode);
 
 	es = EXT4_SB(sb)->s_es;
-	if (ino < EXT4_FIRST_INO(sb) || ino > le32_to_cpu(es->s_inodes_count)) {
+	if (ino < EXT4_FIRST_INO(sb) || ino > ext4_get_inodes_count(sb)) {
 		ext4_error(sb, "reserved or nonexistent inode %lu", ino);
 		goto error_return;
 	}
@@ -887,7 +887,7 @@ struct inode *__ext4_new_inode(handle_t *handle, struct inode *dir,
 	if (!goal)
 		goal = sbi->s_inode_goal;
 
-	if (goal && goal <= le32_to_cpu(sbi->s_es->s_inodes_count)) {
+	if (goal && goal <= ext4_get_inodes_count(sb)) {
 		group = (goal - 1) / EXT4_INODES_PER_GROUP(sb);
 		ino = (goal - 1) % EXT4_INODES_PER_GROUP(sb);
 		ret2 = 0;
@@ -1226,7 +1226,7 @@ struct inode *__ext4_new_inode(handle_t *handle, struct inode *dir,
 /* Verify that we are loading a valid orphan from disk */
 struct inode *ext4_orphan_get(struct super_block *sb, unsigned long ino)
 {
-	unsigned long max_ino = le32_to_cpu(EXT4_SB(sb)->s_es->s_inodes_count);
+	unsigned long max_ino = ext4_get_inodes_count(sb);
 	ext4_group_t block_group;
 	int bit;
 	struct buffer_head *bitmap_bh = NULL;
@@ -1330,9 +1330,9 @@ unsigned long ext4_count_free_inodes(struct super_block *sb)
 		bitmap_count += x;
 	}
 	brelse(bitmap_bh);
-	printk(KERN_DEBUG "ext4_count_free_inodes: "
-	       "stored = %u, computed = %lu, %lu\n",
-	       le32_to_cpu(es->s_free_inodes_count), desc_count, bitmap_count);
+	printk(KERN_DEBUG "ext4_count_free_inodes:\n"
+	       "stored = %lu, computed = %lu, %lu\n",
+	       ext4_get_inodes_count(sb), desc_count, bitmap_count);
 	return desc_count;
 #else
 	desc_count = 0;
fs/ext4/namei.c +54 -24

251 lines not on this page · raw message

fs/ext4/resize.c +4 -4
index 035cd3f4785e..d0d5acd1a70d 100644
@@ -1337,10 +1337,10 @@ static void ext4_update_super(struct super_block *sb,
 
 	ext4_blocks_count_set(es, ext4_blocks_count(es) + blocks_count);
 	ext4_free_blocks_count_set(es, ext4_free_blocks_count(es) + free_blocks);
-	le32_add_cpu(&es->s_inodes_count, EXT4_INODES_PER_GROUP(sb) *
-		     flex_gd->count);
-	le32_add_cpu(&es->s_free_inodes_count, EXT4_INODES_PER_GROUP(sb) *
-		     flex_gd->count);
+	ext4_set_inodes_count(sb, ext4_get_inodes_count(sb) +
+			      EXT4_INODES_PER_GROUP(sb) * flex_gd->count);
+	ext4_set_free_inodes_count(sb, ext4_get_free_inodes_count(sb) +
+			EXT4_INODES_PER_GROUP(sb) * flex_gd->count);
 
 	ext4_debug("free blocks count %llu", ext4_free_blocks_count(es));
 	/*
fs/ext4/super.c +23 -22

128 lines not on this page · raw message

Signature · 1 line
2.14.3 (Apple Git-98)
#4 lore raw

Re: [PATCH v4 3/4] ext4: Add helper functions to access inode numbers

Quoted 16 lines · Artem Blagodarenko

64-bit inodes counter uses extra fields to store hight part. Let's incapsulate inode number reading and writing to extend counter in next commits.

---

fs/ext4/dir.c    |  4 +--
fs/ext4/ext4.h   | 44 +++++++++++++++++++++++---------
fs/ext4/ialloc.c | 12 ++++-----
fs/ext4/namei.c  | 78 +++++++++++++++++++++++++++++++++++++++-----------------
fs/ext4/resize.c |  8 +++---
fs/ext4/super.c  | 45 ++++++++++++++++----------------
6 files changed, 121 insertions(+), 70 deletions(-)

fs/ext4/ext4.h static inline unsigned int ext4_flex_bg_size(struct ext4_sb_info *sbi) · line 2899

Quoted 7 lines
fs/ext4/ext4.h +7 -0
+#define EXT4_SB_VALUES(name) \
+static inline unsigned long ext4_get_##name(struct super_block *sb) \
+{ \
+	struct ext4_super_block *es = EXT4_SB(sb)->s_es; \
+	unsigned long value = le32_to_cpu(es->s_##name); \
+	return value; \
+} \

(style) my preference is to have the linefeed escape '\' aligned at the end of the line, so they don't interfere with the code, but I see that is inconsistently used

fs/ext4/ext4.h static inline unsigned int ext4_flex_bg_size(struct ext4_sb_info *sbi) · line 2901

Quoted 2 lines
fs/ext4/ext4.h +2 -0
+static inline void ext4_set_##name(struct super_block *sb,\
+					   unsigned long val)\

(style) align continued line after '(' on previous line

fs/ext4/ext4.h static inline unsigned int ext4_flex_bg_size(struct ext4_sb_info *sbi) · line 2911

Quoted 10 lines
fs/ext4/ext4.h +10 -0
+{ \
+	struct ext4_super_block *es = EXT4_SB(sb)->s_es; \
+	es->s_##name = cpu_to_le32(val); \
+}
+
+EXT4_SB_VALUES(inodes_count)
+EXT4_SB_VALUES(free_inodes_count)
+EXT4_SB_VALUES(last_orphan)
+EXT4_SB_VALUES(first_error_ino)
+EXT4_SB_VALUES(last_error_ino)

One minor issue with macros like this is that it is not possible to use tags or grep to find "ext4_{get,set}_inodes_count()" and other generated function names. It is useful to at least have those function names in the comments here, something like:

/*
ext4_get_inodes_count(), ext4_set_inodes_count();
*/
EXT4_SB_VALUES(inodes_count);

so that there is at least some chance of finding them. I always have the same problem with the ext4_has_feature_*() macros as well, and I'd rather avoid it here.

fs/ext4/namei.c static struct buffer_head * ext4_dx_find_entry(struct inode *dir, · line 1547

Quoted 10 lines
fs/ext4/namei.c +2 -0
index b6681aebe5cf..21f86c48708b 100644
@@ -1543,6 +1543,23 @@ static struct buffer_head * ext4_dx_find_entry(struct inode *dir,
 	return bh;
 }
 
+static int get_ino(struct inode *dir,
+			     struct ext4_dir_entry_2 *de, __u32 *ino)

(style) align after '(' on previous line

Quoted 4 lines
fs/ext4/namei.c +4 -0
+{
+	struct super_block *sb = dir->i_sb;
+
+	*ino = le32_to_cpu(de->inode);

fs/ext4/namei.c static struct buffer_head * ext4_dx_find_entry(struct inode *dir, · line 1561

Quoted 10 lines
fs/ext4/namei.c +10 -0
+	return 0;
+}
+
+static void set_ino(struct inode *dir,
+		    struct ext4_dir_entry_2 *de, unsigned long i_ino)
+{
+	struct super_block *sb = dir->i_sb;
+
+	de->inode = cpu_to_le32(i_ino);
+}

"get_ino" and "set_ino" are pretty generic function names. Also, it is better to put the common components at the start of the name so they can sort together. Better to use "dirent_ino_{get,set}()" or maybe "ext4_dirent_ino_{get,set}()"?

fs/ext4/namei.c bool ext4_empty_dir(struct inode *inode) · line 2797

Quoted 9 lines
fs/ext4/namei.c +2 -2
@@ -2772,8 +2792,8 @@ bool ext4_empty_dir(struct inode *inode)
 
 	de = (struct ext4_dir_entry_2 *) bh->b_data;
 	de1 = ext4_next_entry(de, sb->s_blocksize);
-	if (le32_to_cpu(de->inode) != inode->i_ino ||
-			le32_to_cpu(de1->inode) == 0 ||
+	if (get_ino(inode, de, &ino) || ino != inode->i_ino ||
+			get_ino(inode, de1, &ino2) || ino2 == 0 ||
 			strcmp(".", de->name) || strcmp("..", de1->name)) {

(style) this is confusingly indented (the original was as well). Should be aligned after the first '(' on the "if" line.

fs/ext4/namei.c int ext4_orphan_del(handle_t *handle, struct inode *inode) · line 2966

Quoted 6 lines
fs/ext4/namei.c +1 -1
@@ -2943,14 +2963,14 @@ int ext4_orphan_del(handle_t *handle, struct inode *inode)
 
 	ino_next = NEXT_ORPHAN(inode);
 	if (prev == &sbi->s_orphan) {
-		jbd_debug(4, "superblock will point to %u\n", ino_next);
+		jbd_debug(4, "superblock will point to %lu\n", ino_next);

(defect) this whole patch chunk should probably be part of the next patch, since ino_next is not yet changed to __u64, and using cpu_to_le64() to swab a __u32 value below would lead to data corruption on big-endian CPUs.

fs/ext4/namei.c int ext4_orphan_del(handle_t *handle, struct inode *inode) · line 2973

Quoted 8 lines
fs/ext4/namei.c +1 -1
 		BUFFER_TRACE(sbi->s_sbh, "get_write_access");
 		err = ext4_journal_get_write_access(handle, sbi->s_sbh);
 		if (err) {
 			mutex_unlock(&sbi->s_orphan_lock);
 			goto out_brelse;
 		}
-		sbi->s_es->s_last_orphan = cpu_to_le32(ino_next);
+		ext4_set_last_orphan(inode->i_sb, cpu_to_le64(ino_next));

Also, since ext4_set_last_orphan() is swabbing "value" internally, this is going to be broken on big-endian machines.

Quoted 24 lines
fs/ext4/namei.c +2 -1
 		mutex_unlock(&sbi->s_orphan_lock);
 		err = ext4_handle_dirty_super(handle, inode->i_sb);
 	} else {
@@ -2989,6 +3009,7 @@ static int ext4_rmdir(struct inode *dir, struct dentry *dentry)
 	struct buffer_head *bh;
 	struct ext4_dir_entry_2 *de;
 	handle_t *handle = NULL;
+	__u32 ino;
 
 	if (unlikely(ext4_forced_shutdown(EXT4_SB(dir->i_sb))))
 		return -EIO;
@@ -3012,7 +3033,7 @@ static int ext4_rmdir(struct inode *dir, struct dentry *dentry)
 	inode = d_inode(dentry);
 
 	retval = -EFSCORRUPTED;
-	if (le32_to_cpu(de->inode) != inode->i_ino)
+	if (get_ino(dir, de, &ino) || ino != inode->i_ino)
 		goto end_rmdir;
 
 	retval = -ENOTEMPTY;
@@ -3392,13 +3414,15 @@ struct ext4_renament {
 static int ext4_rename_dir_prepare(handle_t *handle, struct ext4_renament *ent)
 {
 	int retval;

fs/ext4/namei.c struct ext4_renament { · line 3425

Quoted 10 lines
fs/ext4/namei.c +3 -1
+	__u32 ino;
 
 	ent->dir_bh = ext4_get_first_dir_block(handle, ent->inode,
 					      &retval, &ent->parent_de,
 					      &ent->dir_inlined);
 	if (!ent->dir_bh)
 		return retval;
-	if (le32_to_cpu(ent->parent_de->inode) != ent->dir->i_ino)
+	if (get_ino(ent->dir, ent->parent_de, &ino) ||
+							ino != ent->dir->i_ino)

(style) should align after first '(' on previous line

fs/ext4/namei.c static int ext4_rename(struct inode *old_dir, struct dentry *old_dentry, · line 3650

Quoted 7 lines
fs/ext4/namei.c +2 -1
@@ -3620,7 +3646,8 @@ static int ext4_rename(struct inode *old_dir, struct dentry *old_dentry,
 	 *  same name. Goodbye sticky bit ;-<
 	 */
 	retval = -ENOENT;
-	if (!old.bh || le32_to_cpu(old.de->inode) != old.inode->i_ino)
+	if (!old.bh || get_ino(old.dir, old.de, &ino) ||
+						ino != old.inode->i_ino)

(style) align after first '(' on previous line

Quoted 7 lines
fs/ext4/namei.c +2 -1
@@ -3834,7 +3862,8 @@ static int ext4_cross_rename(struct inode *old_dir, struct dentry *old_dentry,
 	 *  same name. Goodbye sticky bit ;-<
 	 */
 	retval = -ENOENT;
-	if (!old.bh || le32_to_cpu(old.de->inode) != old.inode->i_ino)
+	if (!old.bh || get_ino(old.dir, old.de, &ino) ||
+						ino != old.inode->i_ino)

...

Quoted 7 lines
fs/ext4/namei.c +2 -1
@@ -3846,7 +3875,8 @@ static int ext4_cross_rename(struct inode *old_dir, struct dentry *old_dentry,
 	}
 
 	/* RENAME_EXCHANGE case: old *and* new must both exist */
-	if (!new.bh || le32_to_cpu(new.de->inode) != new.inode->i_ino)
+	if (!new.bh || get_ino(new.dir, new.de, &ino) ||
+						ino != new.inode->i_ino)

...

Quoted 6 lines
fs/ext4/resize.c +0 -0
index 035cd3f4785e..d0d5acd1a70d 100644
@@ -1337,10 +1337,10 @@ static void ext4_update_super(struct super_block *sb,
 

fs/ext4/resize.c static void ext4_update_super(struct super_block *sb, · line 1343

Quoted 10 lines
fs/ext4/resize.c +4 -4
 	ext4_blocks_count_set(es, ext4_blocks_count(es) + blocks_count);
 	ext4_free_blocks_count_set(es, ext4_free_blocks_count(es) + free_blocks);
-	le32_add_cpu(&es->s_inodes_count, EXT4_INODES_PER_GROUP(sb) *
-		     flex_gd->count);
-	le32_add_cpu(&es->s_free_inodes_count, EXT4_INODES_PER_GROUP(sb) *
-		     flex_gd->count);
+	ext4_set_inodes_count(sb, ext4_get_inodes_count(sb) +
+			      EXT4_INODES_PER_GROUP(sb) * flex_gd->count);
+	ext4_set_free_inodes_count(sb, ext4_get_free_inodes_count(sb) +
+				   EXT4_INODES_PER_GROUP(sb) * flex_gd->count);

(style) align after '(' on previous line

fs/ext4/super.c void __ext4_error_inode(struct inode *inode, const char *function, · line 473

Quoted 10 lines
fs/ext4/super.c +1 -1
index ead9406d9cff..455cad8c29e1 100644
@@ -470,7 +470,7 @@ void __ext4_error_inode(struct inode *inode, const char *function,
 	if (unlikely(ext4_forced_shutdown(EXT4_SB(inode->i_sb))))
 		return;
 
-	es->s_last_error_ino = cpu_to_le32(inode->i_ino);
+	ext4_set_last_error_ino(inode->i_sb, cpu_to_le64(inode->i_ino));

(defect) Should be part of next patch that actually converts to 64-bit inodes. Also, this would be double-swabbing "inode->i_ino", since that is being done in the macro now (which also avoids the need to change this code to handle 64-bit inodes in your next patch). Should just be:

	ext4_set_last_error_ino(inode->i_sb, inode->i_ino);

fs/ext4/super.c void __ext4_error_file(struct file *file, const char *function, · line 509

Quoted 9 lines
fs/ext4/super.c +1 -1
 	es->s_last_error_block = cpu_to_le64(block);
 	if (ext4_error_ratelimit(inode->i_sb)) {
 		va_start(args, fmt);
@@ -506,7 +506,7 @@ void __ext4_error_file(struct file *file, const char *function,
 		return;
 
 	es = EXT4_SB(inode->i_sb)->s_es;
-	es->s_last_error_ino = cpu_to_le32(inode->i_ino);
+	ext4_set_last_error_ino(inode->i_sb, cpu_to_le64(inode->i_ino));

(defect) ...

fs/ext4/super.c __acquires(bitlock) · line 720

Quoted 6 lines
fs/ext4/super.c +1 -1
@@ -717,7 +717,7 @@ __acquires(bitlock)
 	if (unlikely(ext4_forced_shutdown(EXT4_SB(sb))))
 		return;
 
-	es->s_last_error_ino = cpu_to_le32(ino);
+	ext4_set_last_error_ino(sb, cpu_to_le64(ino));

(defect) ...

fs/ext4/super.c static void dump_orphan_list(struct super_block *sb, struct ext4_sb_info *sbi) · line 833

Quoted 8 lines
fs/ext4/super.c +2 -2
@@ -829,8 +829,8 @@ static void dump_orphan_list(struct super_block *sb, struct ext4_sb_info *sbi)
 {
 	struct list_head *l;
 
-	ext4_msg(sb, KERN_ERR, "sb orphan head is %d",
-		 le32_to_cpu(sbi->s_es->s_last_orphan));
+	ext4_msg(sb, KERN_ERR, "sb orphan head is %llu",
+		 le64_to_cpu(ext4_get_last_orphan(sb)));

(defect) ... should just be "ext4_get_last_orphan(sb)" without swab

fs/ext4/super.c static void ext4_orphan_cleanup(struct super_block *sb, · line 2491

Quoted 12 lines
fs/ext4/super.c +3 -2
@@ -2483,11 +2483,12 @@ static void ext4_orphan_cleanup(struct super_block *sb,
 		 */
 		if (EXT4_SB(sb)->s_mount_state & EXT4_ERROR_FS) {
 			jbd_debug(1, "Skipping orphan recovery on fs with errors.\n");
-			es->s_last_orphan = 0;
+			ext4_set_last_orphan(sb, 0);
 			break;
 		}
 
-		inode = ext4_orphan_get(sb, le32_to_cpu(es->s_last_orphan));
+		inode = ext4_orphan_get(sb,
+					le64_to_cpu(ext4_get_last_orphan(sb)));

(defect) ...

fs/ext4/super.c static void print_daily_error_info(unsigned long arg) · line 2817

Quoted 10 lines
fs/ext4/super.c +3 -3
@@ -2811,9 +2812,9 @@ static void print_daily_error_info(unsigned long arg)
 		       (int) sizeof(es->s_first_error_func),
 		       es->s_first_error_func,
 		       le32_to_cpu(es->s_first_error_line));
-		if (es->s_first_error_ino)
-			printk(KERN_CONT ": inode %u",
-			       le32_to_cpu(es->s_first_error_ino));
+		if (ext4_get_first_error_ino(sb))
+			printk(KERN_CONT ": inode %llu",
+			       le64_to_cpu(ext4_get_first_error_ino(sb)));

(defect) no need for swab

Also, since the inodes are always "unsigned long" you can just change the format to "%lu" and no need to change it in your next patch.

fs/ext4/super.c static void print_daily_error_info(unsigned long arg) · line 2831

Quoted 10 lines
fs/ext4/super.c +3 -3
@@ -2825,9 +2826,9 @@ static void print_daily_error_info(unsigned long arg)
 		       (int) sizeof(es->s_last_error_func),
 		       es->s_last_error_func,
 		       le32_to_cpu(es->s_last_error_line));
-		if (es->s_last_error_ino)
-			printk(KERN_CONT ": inode %u",
-			       le32_to_cpu(es->s_last_error_ino));
+		if (ext4_get_last_error_ino(sb))
+			printk(KERN_CONT ": inode %llu",
+			       le64_to_cpu(ext4_get_last_error_ino(sb)));

(defect) ...

fs/ext4/super.c static int ext4_commit_super(struct super_block *sb, int sync) · line 4711

Quoted 10 lines
fs/ext4/super.c +3 -3
@@ -4705,9 +4706,9 @@ static int ext4_commit_super(struct super_block *sb, int sync)
 			EXT4_C2B(EXT4_SB(sb), percpu_counter_sum_positive(
 				&EXT4_SB(sb)->s_freeclusters_counter)));
 	if (percpu_counter_initialized(&EXT4_SB(sb)->s_freeinodes_counter))
-		es->s_free_inodes_count =
-			cpu_to_le32(percpu_counter_sum_positive(
-				&EXT4_SB(sb)->s_freeinodes_counter));
+		ext4_set_free_inodes_count(sb,
+				cpu_to_le32(percpu_counter_sum_positive(
+				&EXT4_SB(sb)->s_freeinodes_counter)));

(defect) no need for swab

Cheers, Andreas

#5 lore raw

PATCH v4 4/4 ext4: Add 64-bit inode number support

In reply to Artem Blagodarenko

Use dirdata to store high bits of 64bit inode
number.

---
 fs/ext4/ext4.h    |  38 +++++++++++---
 fs/ext4/ialloc.c  |   7 ++-
 fs/ext4/inline.c  |  31 ++++++-----
 fs/ext4/inode.c   |   5 ++
 fs/ext4/migrate.c |   2 +-
 fs/ext4/namei.c   | 150 +++++++++++++++++++++++++++++++++++++-----------------
 fs/ext4/super.c   |   6 +++
 7 files changed, 172 insertions(+), 67 deletions(-)
fs/ext4/ext4.h +31 -7
index 51aadb2c294b..0cfb95c4e723 100644
@@ -1291,7 +1291,7 @@ struct ext4_super_block {
 	__le32	s_r_blocks_count_hi;	/* Reserved blocks count */
 	__le32	s_free_blocks_count_hi;	/* Free blocks count */
 	__le16	s_min_extra_isize;	/* All inodes have at least # bytes */
-	__le16	s_want_extra_isize; 	/* New inodes should reserve # bytes */
+	__le16	s_want_extra_isize;	/* New inodes should reserve # bytes */
 	__le32	s_flags;		/* Miscellaneous flags */
 	__le16  s_raid_stride;		/* RAID stride */
 	__le16  s_mmp_update_interval;  /* # seconds to wait in MMP checking */
@@ -1303,6 +1303,7 @@ struct ext4_super_block {
 	__u8	s_reserved_pad;		/* Padding to next 32bits */
 	__le64	s_kbytes_written;	/* nr of lifetime kilobytes written */
 	__le32	s_snapshot_inum;	/* Inode number of active snapshot */
+	/* there is no high part of s_snapshot_inum yet */
 	__le32	s_snapshot_id;		/* sequential ID of active snapshot */
 	__le64	s_snapshot_r_blocks_count; /* reserved blocks for active
 					      snapshot's future use */
@@ -1331,7 +1332,13 @@ struct ext4_super_block {
 	__le32	s_lpf_ino;		/* Location of the lost+found inode */
 	__le32	s_prj_quota_inum;	/* inode for tracking project quota */
 	__le32	s_checksum_seed;	/* crc32c(uuid) if csum_seed set */
-	__le32	s_reserved[98];		/* Padding to the end of the block */
+	__le32	s_inodes_count_hi;	/* higth part of inode count */
+	__le32	s_free_inodes_count_hi;	/* Free inodes count */
+	__le32	s_prj_quota_inum_hi;	/* high part of project quota inode */
+	__le32	s_last_orphan_hi;	/* high part of last orphan */
+	__le32	s_first_error_ino_hi;	/* high part of first error ino */
+	__le32	s_last_error_ino_hi;	/* high part of last error ino */
+	__le32	s_reserved[92];		/* Padding to the end of the block */
 	__le32	s_checksum;		/* crc32c(superblock) */
 };
 
@@ -1392,7 +1399,7 @@ struct ext4_sb_info {
 	int s_inode_size;
 	int s_first_ino;
 	unsigned int s_inode_readahead_blks;
-	unsigned int s_inode_goal;
+	unsigned long s_inode_goal;
 	spinlock_t s_next_gen_lock;
 	u32 s_next_generation;
 	u32 s_hash_seed[4];
@@ -1677,6 +1684,7 @@ static inline void ext4_clear_state_flags(struct ext4_inode_info *ei)
 #define EXT4_FEATURE_INCOMPAT_LARGEDIR		0x4000 /* >2GB or 3-lvl htree */
 #define EXT4_FEATURE_INCOMPAT_INLINE_DATA	0x8000 /* data in inode */
 #define EXT4_FEATURE_INCOMPAT_ENCRYPT		0x10000
+#define EXT4_FEATURE_INCOMPAT_INODE64		0x20000
 
 #define EXT4_FEATURE_COMPAT_FUNCS(name, flagname) \
 static inline bool ext4_has_feature_##name(struct super_block *sb) \
@@ -1765,6 +1773,8 @@ EXT4_FEATURE_INCOMPAT_FUNCS(csum_seed,		CSUM_SEED)
 EXT4_FEATURE_INCOMPAT_FUNCS(largedir,		LARGEDIR)
 EXT4_FEATURE_INCOMPAT_FUNCS(inline_data,	INLINE_DATA)
 EXT4_FEATURE_INCOMPAT_FUNCS(encrypt,		ENCRYPT)
+EXT4_FEATURE_INCOMPAT_FUNCS(inode64,		INODE64)
+
 
 #define EXT2_FEATURE_COMPAT_SUPP	EXT4_FEATURE_COMPAT_EXT_ATTR
 #define EXT2_FEATURE_INCOMPAT_SUPP	(EXT4_FEATURE_INCOMPAT_FILETYPE| \
@@ -1793,6 +1803,7 @@ EXT4_FEATURE_INCOMPAT_FUNCS(encrypt,		ENCRYPT)
 					 EXT4_FEATURE_INCOMPAT_INLINE_DATA | \
 					 EXT4_FEATURE_INCOMPAT_ENCRYPT | \
 					 EXT4_FEATURE_INCOMPAT_CSUM_SEED | \
+					 EXT4_FEATURE_INCOMPAT_INODE64 | \
 					 EXT4_FEATURE_INCOMPAT_LARGEDIR | \
 					 EXT4_FEATURE_INCOMPAT_DIRDATA)
 #define EXT4_FEATURE_RO_COMPAT_SUPP	(EXT4_FEATURE_RO_COMPAT_SPARSE_SUPER| \
@@ -1974,7 +1985,7 @@ struct ext4_dir_entry_tail {
  */
 #define EXT4_DIRENT_LUFID		0x10
 #define EXT4_DIRENT_INODE		0x20
-
+#define DIRENT_INODE_LEN                4
 #define EXT4_LUFID_MAGIC    0xAD200907UL
 
 struct ext4_dirent_data_header {
@@ -1987,6 +1998,11 @@ struct ext4_dirent_lufid {
 	__u8				dl_data[0];
 } __packed;
 
+struct ext4_dirent_inode64 {
+	struct ext4_dirent_data_header	di_header; /* 1 + 4 */
+	__le32				di_inohi;
+} __packed;
+
 struct ext4_dentry_param {
 	__u32				edp_magic; /* EXT4_LUFID_MAGIC */
 	struct ext4_dirent_lufid	edp_lufid;
@@ -2428,7 +2444,9 @@ extern int ext4_find_dest_de(struct inode *dir, struct inode *inode,
 void ext4_insert_dentry(struct inode *inode,
 			struct ext4_dir_entry_2 *de,
 			int buf_size,
-			struct ext4_filename *fname);
+			struct ext4_filename *fname,
+			bool write_short_dotdot,
+			struct dentry *dentry);
 static inline void ext4_update_dx_flag(struct inode *inode)
 {
 	if (!ext4_has_feature_dir_index(inode->i_sb))
@@ -2463,7 +2481,7 @@ extern int ext4fs_dirhash(const char *name, int len, struct
 
 /* ialloc.c */
 extern struct inode *__ext4_new_inode(handle_t *, struct inode *, umode_t,
-				      const struct qstr *qstr, __u32 goal,
+				      const struct qstr *qstr, __u64 goal,
 				      uid_t *owner, __u32 i_flags,
 				      int handle_type, unsigned int line_no,
 				      int nblocks);
@@ -3106,7 +3124,8 @@ extern int ext4_da_write_inline_data_end(struct inode *inode, loff_t pos,
 					 struct page *page);
 extern int ext4_try_add_inline_entry(handle_t *handle,
 				     struct ext4_filename *fname,
-				     struct inode *dir, struct inode *inode);
+				     struct inode *dir, struct inode *inode,
+				     struct dentry *dentry);
 extern int ext4_try_create_inline_dir(handle_t *handle,
 				      struct inode *parent,
 				      struct inode *inode);
@@ -3383,6 +3402,11 @@ static inline int ext4_get_dirent_data_len(struct ext4_dir_entry_2 *de)
 	return dlen;
 }
 
+extern int get_ino(struct inode *dir,
+			     struct ext4_dir_entry_2 *de, unsigned long *ino);
+extern void set_ino(struct inode *dir,
+		    struct ext4_dir_entry_2 *de, unsigned long i_ino,
+		    bool write_short_dotdot, struct dentry *dentry);
 #endif	/* __KERNEL__ */
 
 #define EFSBADCRC	EBADMSG		/* Bad CRC detected */
fs/ext4/ialloc.c +6 -1
index 25dbc15e2ee1..e23dc4133e84 100644
@@ -770,7 +770,7 @@ static int find_inode_bit(struct super_block *sb, ext4_group_t group,
  */
 struct inode *__ext4_new_inode(handle_t *handle, struct inode *dir,
 			       umode_t mode, const struct qstr *qstr,
-			       __u32 goal, uid_t *owner, __u32 i_flags,
+			       __u64 goal, uid_t *owner, __u32 i_flags,
 			       int handle_type, unsigned int line_no,
 			       int nblocks)
 {
@@ -1149,6 +1149,11 @@ struct inode *__ext4_new_inode(handle_t *handle, struct inode *dir,
 		__le32 gen = cpu_to_le32(inode->i_generation);
 		csum = ext4_chksum(sbi, sbi->s_csum_seed, (__u8 *)&inum,
 				   sizeof(inum));
+		if (inode->i_ino >> 32) {
+			inum = cpu_to_le32(inode->i_ino >> 32);
+			csum = ext4_chksum(sbi, sbi->s_csum_seed,
+					(__u8 *)&inum, sizeof(inum));
+		}
 		ei->i_csum_seed = ext4_chksum(sbi, csum, (__u8 *)&gen,
 					      sizeof(gen));
 	}
fs/ext4/inline.c +19 -12
index 666891dc03cd..f3d0d7f9d331 100644
@@ -1020,13 +1020,16 @@ static int ext4_add_dirent_to_inline(handle_t *handle,
 				     struct inode *dir,
 				     struct inode *inode,
 				     struct ext4_iloc *iloc,
-				     void *inline_start, int inline_size)
+				     void *inline_start, int inline_size,
+				     struct dentry *dentry)
 {
 	int		err;
 	struct ext4_dir_entry_2 *de;
+	bool write_short_dotdot = 0;
 
 	err = ext4_find_dest_de(dir, inode, iloc->bh, inline_start,
-				inline_size, fname, &de, 0, NULL, 0);
+				inline_size, fname, &de, 0,
+				&write_short_dotdot, 0);
 	if (err)
 		return err;
 
@@ -1034,7 +1037,8 @@ static int ext4_add_dirent_to_inline(handle_t *handle,
 	err = ext4_journal_get_write_access(handle, iloc->bh);
 	if (err)
 		return err;
-	ext4_insert_dentry(inode, de, inline_size, fname);
+	ext4_insert_dentry(inode, de, inline_size, fname,
+			   write_short_dotdot, dentry);
 
 	ext4_show_inline_dir(dir, iloc->bh, inline_start, inline_size);
 
@@ -1264,7 +1268,8 @@ static int ext4_convert_inline_data_nolock(handle_t *handle,
  * the new created block.
  */
 int ext4_try_add_inline_entry(handle_t *handle, struct ext4_filename *fname,
-			      struct inode *dir, struct inode *inode)
+			      struct inode *dir, struct inode *inode,
+			      struct dentry *dentry)
 {
 	int ret, inline_size, no_expand;
 	void *inline_start;
@@ -1283,7 +1288,7 @@ int ext4_try_add_inline_entry(handle_t *handle, struct ext4_filename *fname,
 	inline_size = EXT4_MIN_INLINE_DATA_SIZE - EXT4_INLINE_DOTDOT_SIZE;
 
 	ret = ext4_add_dirent_to_inline(handle, fname, dir, inode, &iloc,
-					inline_start, inline_size);
+					inline_start, inline_size, dentry);
 	if (ret != -ENOSPC)
 		goto out;
 
@@ -1305,7 +1310,7 @@ int ext4_try_add_inline_entry(handle_t *handle, struct ext4_filename *fname,
 
 		ret = ext4_add_dirent_to_inline(handle, fname, dir,
 						inode, &iloc, inline_start,
-						inline_size);
+						inline_size, dentry);
 
 		if (ret != -ENOSPC)
 			goto out;
@@ -1337,7 +1342,7 @@ int htree_inlinedir_to_tree(struct file *dir_file,
 			    int *has_inline_data)
 {
 	int err = 0, count = 0;
-	unsigned int parent_ino;
+	unsigned long parent_ino;
 	int pos;
 	struct ext4_dir_entry_2 *de;
 	struct inode *inode = file_inode(dir_file);
@@ -1372,7 +1377,9 @@ int htree_inlinedir_to_tree(struct file *dir_file,
 		goto out;
 
 	pos = 0;
-	parent_ino = le32_to_cpu(((struct ext4_dir_entry_2 *)dir_buf)->inode);
+	ret = get_ino(inode, (struct ext4_dir_entry_2 *)dir_buf, &parent_ino);
+	if (ret)
+		goto out;
 	while (pos < inline_size) {
 		/*
 		 * As inlined dir doesn't store any information about '.' and
@@ -1380,9 +1387,9 @@ int htree_inlinedir_to_tree(struct file *dir_file,
 		 * them differently.
 		 */
 		if (pos == 0) {
-			fake.inode = cpu_to_le32(inode->i_ino);
 			fake.name_len = 1;
 			strcpy(fake.name, ".");
+			set_ino(inode, &fake, inode->i_ino, 0, NULL);
 			fake.rec_len = ext4_rec_len_to_disk(
 					EXT4_DIR_NAME_LEN(fake.name_len),
 					inline_size);
@@ -1390,9 +1397,9 @@ int htree_inlinedir_to_tree(struct file *dir_file,
 			de = &fake;
 			pos = EXT4_INLINE_DOTDOT_OFFSET;
 		} else if (pos == EXT4_INLINE_DOTDOT_OFFSET) {
-			fake.inode = cpu_to_le32(parent_ino);
 			fake.name_len = 2;
 			strcpy(fake.name, "..");
+			set_ino(inode, &fake, parent_ino, 0, NULL);
 			fake.rec_len = ext4_rec_len_to_disk(
 					EXT4_DIR_NAME_LEN(fake.name_len),
 					inline_size);
@@ -1612,9 +1619,9 @@ int ext4_try_create_inline_dir(handle_t *handle, struct inode *parent,
 	 * and create a fake dentry to cover the left space.
 	 */
 	de = (struct ext4_dir_entry_2 *)ext4_raw_inode(&iloc)->i_block;
-	de->inode = cpu_to_le32(parent->i_ino);
+	set_ino(parent, de, parent->i_ino, 0, NULL);
 	de = (struct ext4_dir_entry_2 *)((void *)de + EXT4_INLINE_DOTDOT_SIZE);
-	de->inode = 0;
+	set_ino(parent, de, 0, 0, NULL);
 	de->rec_len = ext4_rec_len_to_disk(
 				inline_size - EXT4_INLINE_DOTDOT_SIZE,
 				inline_size);
fs/ext4/inode.c +5 -0
index 31db875bc7a1..9caefee1bce9 100644
@@ -4691,6 +4691,11 @@ struct inode *ext4_iget(struct super_block *sb, unsigned long ino)
 		__le32 gen = raw_inode->i_generation;
 		csum = ext4_chksum(sbi, sbi->s_csum_seed, (__u8 *)&inum,
 				   sizeof(inum));
+		if (inode->i_ino >> 32) {
+			inum = cpu_to_le32(inode->i_ino >> 32);
+			csum = ext4_chksum(sbi, sbi->s_csum_seed,
+					(__u8 *)&inum, sizeof(inum));
+		}
 		ei->i_csum_seed = ext4_chksum(sbi, csum, (__u8 *)&gen,
 					      sizeof(gen));
 	}
fs/ext4/migrate.c +1 -1
index cf5181b62df1..89266764908b 100644
@@ -441,7 +441,7 @@ int ext4_ext_migrate(struct inode *inode)
 	struct inode *tmp_inode = NULL;
 	struct migrate_struct lb;
 	unsigned long max_entries;
-	__u32 goal;
+	__u64 goal;
 	uid_t owner[2];
 
 	/*
fs/ext4/namei.c +104 -46

313 lines not on this page · raw message

fs/ext4/super.c +6 -0
index 455cad8c29e1..8f81adda722f 100644
@@ -3490,6 +3490,12 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
 		goto cantfind_ext4;
 	}
 
+	if (ext4_has_feature_inode64(sb) &&
+	    (sizeof(u64) != sizeof(unsigned long))) {
+		ext4_msg(sb, KERN_ERR, "64-bit inodes need 64 bit kernel.");
+		goto failed_mount;
+	}
+
 	/* Load the checksum driver */
 	if (ext4_has_feature_metadata_csum(sb) ||
 	    ext4_has_feature_ea_inode(sb)) {
Signature · 1 line
2.14.3 (Apple Git-98)
maintainer
#6 lore raw

Re: [PATCH v4 4/4] ext4: Add 64-bit inode number support

Hi Artem,

I was debugging another problem and it caused me to ask myself, "Huh. I wonder how the 64-bit inode number support deals with the orphaned inode list ---- since we use the dtime field in the inode as part of a linked list with the 32-bit s_orphan_inum has the head of that linked list."

So I took a quick look at your patch, and noted that in the v3 version Andreas had asked you what about adding support for the 32-bito s_last_orphan field, so you have added support for s_last_orphan_hi. But it doesn't appear that you are *using* that field for anything. Also, although you have made ino_next in ext4_orphan_add() a 64-bit field, it doesn't appear that you changed how the linked list of the orphaned inode list is stored.

BTW, I also don't see any places where s_first_error_ino_hi and s_last_error_ino_hi are used.

This brings up a question --- how much testing have you done with your patch, and how are you testing it? It's pretty clear that if you had tried a test where inodes with bits set in the 32-bits of the inode number, codepaths which depend on the orphan inode handling would have blown up. You might want to consider a debugging mode where the inode allocator preferentially tries to use inode numbers that start at (2**32) + 1 and then try running xfstests on it.

Another debugging mode that would be useful is one which doesn't require really big file systems, so it can be used by kvm-xfstest and gce-xfstest. You might do this forces the high 32-bits of the inode to be (17 << 32), and changes ext4_get_inode_loc() so that it returns an error if the high bits are not (17 << 32). (Similar adjustments would be needed for access to the inode allocation bitmap.)

Cheers,

- Ted