i_version update - ext4 part
Subsystems (2)
PATCH 2/2 i_version update - ext4 part
The patch is on top of the ext4 tree:
http://repo.or.cz/w/ext4-patch-queue.git
In this part, the i_version counter is stored into 2 32bit fields of the ext4_inode structure osd1.linux1.l_i_version and i_version_hi.
I included the ext4_expand_inode_extra_isize patch, which does part of the job, checking if there is enough room for extra fields in the inode (i_version_hi). The other patch increments the counter on inode modifications and set it on inode creation.
This patch is on top of the nanosecond timestamp and i_version_hi patches.
This patch adds 64-bit inode version support to ext4. The lower 32 bits are stored in the osd1.linux1.l_i_version field while the high 32 bits are stored in the i_version_hi field newly created in the ext4_inode.
We need to make sure that existing filesystems can also avail the new fields that have been added to the inode. We use s_want_extra_isize and s_min_extra_isize to decide by how much we should expand the inode. If EXT4_FEATURE_RO_COMPAT_EXTRA_ISIZE feature is set then we expand by max(s_want_extra_isize, s_min_extra_isize , sizeof(ext4_inode) - EXT4_GOOD_OLD_INODE_SIZE) bytes. Actually it is still an open question about whether users should be able to set s_*_extra_isize smaller than the known fields or not.
This patch also adds the functionality to expand inodes to include the newly added fields. We start by trying to expand by s_want_extra_isize bytes and if its fails we try to expand by s_min_extra_isize bytes. This is done by changing the i_extra_isize if enough space is available in the inode and no EAs are present. If EAs are present and there is enough space in the inode then the EAs in the inode are shifted to make space. If enough space is not available in the inode due to the EAs then 1 or more EAs are shifted to the external EA block. In the worst case when even the external EA block does not have enough space we inform the user that some EA would need to be deleted or s_min_extra_isize would have to be reduced.
This would be online expansion of inodes. I am also working on adding an "expand_inodes" option to e2fsck which will expand all the used inodes.
fs/ext4/inode.c +37 -2
@@ -2709,6 +2709,13 @@EXT4_INODE_GET_XTIME (i_atime, inode, raw_inode);EXT4_EINODE_GET_XTIME (i_crtime, ei, raw_inode); + ei->i_fs_version =le32_to_cpu (raw_inode->i_disk_version); +if (EXT4_INODE_SIZE (inode->i_sb) >EXT4_GOOD_OLD_INODE_SIZE ) { +if (EXT4_FITS_IN_INODE (raw_inode, ei, i_version_hi)) + ei->i_fs_version |= + (__u64)(le32_to_cpu (raw_inode->i_version_hi)) <<32 ; + } +if (S_ISREG (inode->i_mode)) { inode->i_op = &ext4_file_inode_operations; inode->i_fop = &ext4_file_operations;
@@ -2852,8 +2859,14 @@ }else for (block =0 ; block <EXT4_N_BLOCKS ; block++) raw_inode->i_block[block] = ei->i_data[block]; -if (ei->i_extra_isize) + raw_inode->i_disk_version =cpu_to_le32 (ei->i_fs_version); +if (ei->i_extra_isize) { +if (EXT4_FITS_IN_INODE (raw_inode, ei, i_version_hi)) { + raw_inode->i_version_hi = +cpu_to_le32 (ei->i_fs_version >>32 ); + } raw_inode->i_extra_isize =cpu_to_le16 (ei->i_extra_isize); + }BUFFER_TRACE (bh,"call ext4_journal_dirty_metadata" ); rc =ext4_journal_dirty_metadata (handle, bh);
@@ -3127,10 +3140,32 @@int ext4_mark_inode_dirty (handle_t *handle,struct inode *inode) {struct ext4_iloc iloc; -int err; +int err, ret; +static int expand_message;might_sleep (); err =ext4_reserve_inode_write (handle, inode, &iloc); +if (EXT4_I (inode)->i_extra_isize < +EXT4_SB (inode->i_sb)->s_want_extra_isize && + !(EXT4_I (inode)->i_state &EXT4_STATE_NO_EXPAND )) { +/* We need extra buffer credits since we may write into EA block +* with this same handle */ +if ((jbd2_journal_extend (handle, +EXT4_DATA_TRANS_BLOCKS (inode->i_sb))) ==0 ) { + ret =ext4_expand_extra_isize (inode, +EXT4_SB (inode->i_sb)->s_want_extra_isize, + iloc, handle); +if (ret) { +EXT4_I (inode)->i_state |=EXT4_STATE_NO_EXPAND ; +if (!expand_message) { +ext4_warning (inode->i_sb, __FUNCTION__, +"Unable to expand inode %lu. Delete some" +" EAs or run e2fsck." , inode->i_ino); + expand_message =1 ; + } + } + } + }if (!err) err =ext4_mark_iloc_dirty (handle, inode, &iloc);return err;
include/linux/ext4_fs.h +4 -1
@@ -202,6 +202,7 @@#define EXT4_STATE_JDATA 0x00000001/* journaled data exists */ #define EXT4_STATE_NEW 0x00000002/* inode is newly created */ #define EXT4_STATE_XATTR 0x00000004/* has in-inode xattrs */ +#define EXT4_STATE_NO_EXPAND 0x00000008/* No space for expansion */ /* Used to pass group descriptor data when online resize is done */ struct ext4_new_group_input {
@@ -297,7 +298,7 @@__le32 i_flags;/* File flags */ union {struct { -__u32 l_i_reserved1; +__u32 l_i_version; } linux1;struct {__u32 h_i_translator;
@@ -405,6 +406,8 @@ raw_inode->xtime ## _extra); \ } while (0) +#define i_disk_version osd1.linux1.l_i_version +#if defined(__KERNEL__) || defined(__linux__)#define i_reserved1 osd1.linux1.l_i_reserved1#define i_frag osd2.linux2.l_i_frag
include/linux/ext4_fs_i.h +1 -0
@@ -154,6 +154,7 @@unsigned long i_ext_generation;struct ext4_ext_cache i_cached_extent;struct timespec i_crtime; + __u64 i_fs_version; };#endif /* _LINUX_EXT4_FS_I */
fs/ext4/xattr.c +262 -0
286 lines not on this page · raw message
fs/ext4/xattr.h +3 -0
@@ -74,6 +74,9 @@extern void ext4_xattr_delete_inode (handle_t *,struct inode *);extern void ext4_xattr_put_super (struct super_block *); +int ext4_expand_extra_isize (struct inode *inode,int new_extra_isize, +struct ext4_iloc iloc,handle_t *handle); +extern int init_ext4_xattr (void );extern void exit_ext4_xattr (void );
This patch is on top of i_version_update_vfs.
The i_version field of the inode is set on inode creation and incremented when the inode is being modified.
fs/ext4/ialloc.c +1 -0
@@ -565,6 +565,7 @@ inode->i_blocks =0 ; inode->i_mtime = inode->i_atime = inode->i_ctime = ei->i_crtime =ext4_current_time (inode); + inode->i_version =1 ;memset (ei->i_data,0 ,sizeof (ei->i_data)); ei->i_dir_start_lookup =0 ;
fs/ext4/inode.c +1 -0
@@ -3082,6 +3082,7 @@ {int err =0 ; + inode->i_version++;/* the do_update_inode consumes one bh->b_count */ get_bh (iloc->bh);
fs/ext4/super.c +1 -1
@@ -2839,8 +2839,8 @@i_size_write (inode, off+len-towrite);EXT4_I (inode)->i_disksize = inode->i_size; } - inode->i_version++; inode->i_mtime = inode->i_ctime =CURRENT_TIME ; + inode->i_version =1 ;ext4_mark_inode_dirty (handle, inode);mutex_unlock (&inode->i_mutex);return len - towrite;
Quoted 6 lines · Jean noel Cordenner
The patch is on top of the ext4 tree:
http://repo.or.cz/w/ext4-patch-queue.gitIn this part, the
i_versioncounter is stored into 2 32bit fields of theext4_inodestructure osd1.linux1.l_i_version andi_version_hi.
Quoted 9 lines
I included the
ext4_expand_inode_extra_isizepatch, which does part of the job, checking if there is enough room for extra fields in the inode (i_version_hi). The other patch increments the counter on inode modifications and set it on inode creation.
plain text document attachment (i_version_update_ext4)
This patch is on top ofi_version_update_vfs.
Thei_versionfield of the inode is set on inode creation and incremented when the inode is being modified.
I am a little bit confused about the two patches.
It appears in the ext4_expand_inode_extra_isize patch by Kalpak, there a new 64 bit i_fs_version field is added to ext4 inode structure for inode versioning support. read/store of this counter are properly handled, but missing the inode versioning counter update.
But later in the second patch by Jean Noel, he re-used the VFS inode-
Quoted 1 line
i_versionfor ext4 inode versioning, the counter is being updated every
time the file is being changed.
To me, i_fs_version and inode_version are the same thing, right? Shouldn't we choose one(I assume inode i_version?), and combine these two patch together? How about split the inode versioning part from the ext4_expand_inode_extra_isize patch(it does multiple things, and i_versioning doesn't longs there) and put it together with the rest of i_version update patches?
BTW, how could NFS/user space to access the inode version counter?
Thanks,
Mingming
Quoted 40 lines
Signed-off-by Jean Noel Cordenner <[email protected]>Index:
linux-2.6.22-rc2-ext4-1/fs/ext4/ialloc.c
===================================================================fs/ext4/ialloc.c +1
-0@@ -565,6 +565,7 @@ inode->i_blocks =0 ; inode->i_mtime = inode->i_atime = inode->i_ctime = ei->i_crtime =ext4_current_time (inode); + inode->i_version =1 ;memset (ei->i_data,0 ,sizeof (ei->i_data)); ei->i_dir_start_lookup =0 ;Index:
linux-2.6.22-rc2-ext4-1/fs/ext4/inode.c
===================================================================fs/ext4/inode.c +1
-0@@ -3082,6 +3082,7 @@ {int err =0 ; + inode->i_version++;/* the do_update_inode consumes one bh->b_count */ get_bh (iloc->bh);Index:
linux-2.6.22-rc2-ext4-1/fs/ext4/super.c
===================================================================fs/ext4/super.c +1
-1@@ -2839,8 +2839,8 @@i_size_write (inode, off+len-towrite);EXT4_I (inode)->i_disksize = inode->i_size; } - inode->i_version++; inode->i_mtime = inode->i_ctime =CURRENT_TIME ; + inode->i_version =1 ;ext4_mark_inode_dirty (handle, inode);mutex_unlock (&inode->i_mutex);return len - towrite;
Quoted 6 lines · Mingming Cao
I am a little bit confused about the two patches.
It appears in the
ext4_expand_inode_extra_isizepatch by Kalpak, there a new 64 biti_fs_versionfield is added to ext4 inode structure for inode versioning support. read/store of this counter are properly handled, but missing the inode versioning counter update.
For the Lustre use of the inode version we don't care about the VFS changes to i_version. In fact - we want to be able to control the changes to inode version ourselves so that e.g. file defragmenting or atime updates don't change the inode version, and that recovery can restore the version to a known state along with the rest of the metadata.
That said, since Lustre isn't in the kernel and we patch our version of ext3 anyways it doesn't really matter what is done for NFS. We will just patch in our own behaviour if the final ext4 code isn't suitable in all of the details. Having 99% of the code the same at least makes this a lot less work.
Quoted 3 lines
But later in the second patch by Jean Noel, he re-used the VFS inode-
Quoted 1 line
i_versionfor ext4 inode versioning, the counter is being updated everytime the file is being changed.
I don't know what the NFS requirements for the version are. There may also be some complaints from others if the i_version is 64 bits because this contributes to generic inode growth and isn't used for other filesystems.
Quoted 6 lines
To me,
i_fs_versionandinode_versionare the same thing, right? Shouldn't we chooseone(I assume inode i_version?), and combine these two patch together? How about split the inode versioning part from theext4_expand_inode_extra_isizepatch(it does multiple things, and i_versioning doesn't longs there)and put it together with the rest ofi_versionupdate patches?
I don't have an objection to that, but I don't think it is required.
Quoted 1 line
BTW, how could NFS/user space to access the inode version counter?
If the Bull patch uses i_version then knfsd can just access it directly. I don't think there is any API to access it from userspace. One option is to add a virtual EA like user.inode_version and have the kernel fill this in from i_version.
Lustre will manipulate the ei->i_fs_version directly.
Cheers, Andreas
--
Andreas Dilger
Principal Software Engineer
Cluster File Systems, Inc.
Quoted 8 lines · Andreas Dilger
Quoted 6 lines · Mingming Cao
I am a little bit confused about the two patches.
It appears in the
ext4_expand_inode_extra_isizepatch by Kalpak, there a new 64 biti_fs_versionfield is added to ext4 inode structure for inode versioning support. read/store of this counter are properly handled, but missing the inode versioning counter update.
Quoted 6 lines
For the Lustre use of the inode version we don't care about the VFS changes to
i_version. In fact - we want to be able to control the changes to inode version ourselves so that e.g. file defragmenting or atime updates don't change the inode version, and that recovery can restore the version to a known state along with the rest of the metadata.
It's a pity that VFS i_version can't serve Lustre need completely. :(
If the unnecessary inode version update is a concern, then, with current implementation (i_version being updated in ext4_mark_inode_dirty()-
Quoted 1 line
ext4_mark_iloc_dirty()), thei_versioncan be increased multiple times
during one write() operation (unlike ctime update). I know doing the update in ext4_mark_inode_dirty() (rather than update inode version on every mtime/ctime update) clearly simplified the code changes. So I am not sure if the increased update is a concern or not.
In any case, does the VFS inode version get update when atime updates?
Quoted 6 lines
That said, since Lustre isn't in the kernel and we patch our version of ext3 anyways it doesn't really matter what is done for NFS. We will just patch in our own behaviour if the final ext4 code isn't suitable in all of the details. Having 99% of the code the same at least makes this a lot less work.
Quoted 9 lines
Quoted 3 lines
But later in the second patch by Jean Noel, he re-used the VFS inode-
Quoted 1 line
i_versionfor ext4 inode versioning, the counter is being updated everytime the file is being changed.
I don't know what the NFS requirements for the version are. There may also be some complaints from others if the
i_versionis 64 bits because this contributes to generic inode growth and isn't used for other filesystems.
That should benefit for other filesystems, as I thought this NFS requirements apply to all filesystems.
Quoted 24 lines
Quoted 6 lines
To me,
i_fs_versionandinode_versionare the same thing, right? Shouldn't we chooseone(I assume inode i_version?), and combine these two patch together? How about split the inode versioning part from theext4_expand_inode_extra_isizepatch(it does multiple things, and i_versioning doesn't longs there)and put it together with the rest ofi_versionupdate patches?I don't have an objection to that, but I don't think it is required.
Quoted 1 line
BTW, how could NFS/user space to access the inode version counter?
If the Bull patch uses
i_versionthen knfsd can just access it directly. I don't think there is any API to access it from userspace. One option is to add a virtual EA like user.inode_version and have the kernel fill this in fromi_version.Lustre will manipulate the
ei->i_fs_versiondirectly.Cheers, Andreas
--
Andreas Dilger
Principal Software Engineer
Cluster File Systems, Inc.
Quoted 8 lines · Mingming Cao
Quoted 5 lines · Andreas Dilger
I don't know what the NFS requirements for the version are. There may also be some complaints from others if the
i_versionis 64 bits because this contributes to generic inode growth and isn't used for other filesystems.That should benefit for other filesystems, as I thought this NFS requirements apply to all filesystems.
Right. The point here is that the NFS protocol needs to impose certain requirements on _all_ filesystems that want to be supported, and so it is in the interest of everyone to have a generic update mechanism available in the VFS in order to avoid code (and bug) replication.
Now if Lustre doesn't care about NFS compatibility, then I suppose it would be fairly easy to engineer the i_version update interface to allow them to use that field in whatever way suits them best.
Trond