Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ext4: Add inode version support in ext4

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.
This field is incremented in case the ext4_inode is large enough. A
i_version mount option has been added to enable the feature.

Signed-off-by: Mingming Cao <cmm@us.ibm.com>
Signed-off-by: Andreas Dilger <adilger@clusterfs.com>
Signed-off-by: Kalpak Shah <kalpak@clusterfs.com>
Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: Jean Noel Cordenner <jean-noel.cordenner@bull.net>

authored by

Jean Noel Cordenner and committed by
Theodore Ts'o
25ec56b5 7a224228

+45 -22
+17 -1
fs/ext4/inode.c
··· 2781 2781 EXT4_INODE_GET_XTIME(i_atime, inode, raw_inode); 2782 2782 EXT4_EINODE_GET_XTIME(i_crtime, ei, raw_inode); 2783 2783 2784 + inode->i_version = le32_to_cpu(raw_inode->i_disk_version); 2785 + if (EXT4_INODE_SIZE(inode->i_sb) > EXT4_GOOD_OLD_INODE_SIZE) { 2786 + if (EXT4_FITS_IN_INODE(raw_inode, ei, i_version_hi)) 2787 + inode->i_version |= 2788 + (__u64)(le32_to_cpu(raw_inode->i_version_hi)) << 32; 2789 + } 2790 + 2784 2791 if (S_ISREG(inode->i_mode)) { 2785 2792 inode->i_op = &ext4_file_inode_operations; 2786 2793 inode->i_fop = &ext4_file_operations; ··· 2970 2963 } else for (block = 0; block < EXT4_N_BLOCKS; block++) 2971 2964 raw_inode->i_block[block] = ei->i_data[block]; 2972 2965 2973 - if (ei->i_extra_isize) 2966 + raw_inode->i_disk_version = cpu_to_le32(inode->i_version); 2967 + if (ei->i_extra_isize) { 2968 + if (EXT4_FITS_IN_INODE(raw_inode, ei, i_version_hi)) 2969 + raw_inode->i_version_hi = 2970 + cpu_to_le32(inode->i_version >> 32); 2974 2971 raw_inode->i_extra_isize = cpu_to_le16(ei->i_extra_isize); 2972 + } 2973 + 2975 2974 2976 2975 BUFFER_TRACE(bh, "call ext4_journal_dirty_metadata"); 2977 2976 rc = ext4_journal_dirty_metadata(handle, bh); ··· 3203 3190 struct inode *inode, struct ext4_iloc *iloc) 3204 3191 { 3205 3192 int err = 0; 3193 + 3194 + if (test_opt(inode->i_sb, I_VERSION)) 3195 + inode_inc_iversion(inode); 3206 3196 3207 3197 /* the do_update_inode consumes one bh->b_count */ 3208 3198 get_bh(iloc->bh);
+8 -2
fs/ext4/super.c
··· 732 732 seq_puts(seq, ",nobh"); 733 733 if (!test_opt(sb, EXTENTS)) 734 734 seq_puts(seq, ",noextents"); 735 + if (test_opt(sb, I_VERSION)) 736 + seq_puts(seq, ",i_version"); 735 737 736 738 if (test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_JOURNAL_DATA) 737 739 seq_puts(seq, ",data=journal"); ··· 876 874 Opt_usrjquota, Opt_grpjquota, Opt_offusrjquota, Opt_offgrpjquota, 877 875 Opt_jqfmt_vfsold, Opt_jqfmt_vfsv0, Opt_quota, Opt_noquota, 878 876 Opt_ignore, Opt_barrier, Opt_err, Opt_resize, Opt_usrquota, 879 - Opt_grpquota, Opt_extents, Opt_noextents, 877 + Opt_grpquota, Opt_extents, Opt_noextents, Opt_i_version, 880 878 }; 881 879 882 880 static match_table_t tokens = { ··· 930 928 {Opt_barrier, "barrier=%u"}, 931 929 {Opt_extents, "extents"}, 932 930 {Opt_noextents, "noextents"}, 931 + {Opt_i_version, "i_version"}, 933 932 {Opt_err, NULL}, 934 933 {Opt_resize, "resize"}, 935 934 }; ··· 1275 1272 break; 1276 1273 case Opt_noextents: 1277 1274 clear_opt (sbi->s_mount_opt, EXTENTS); 1275 + break; 1276 + case Opt_i_version: 1277 + set_opt(sbi->s_mount_opt, I_VERSION); 1278 + sb->s_flags |= MS_I_VERSION; 1278 1279 break; 1279 1280 default: 1280 1281 printk (KERN_ERR ··· 3204 3197 i_size_write(inode, off+len-towrite); 3205 3198 EXT4_I(inode)->i_disksize = inode->i_size; 3206 3199 } 3207 - inode->i_version++; 3208 3200 inode->i_mtime = inode->i_ctime = CURRENT_TIME; 3209 3201 ext4_mark_inode_dirty(handle, inode); 3210 3202 mutex_unlock(&inode->i_mutex);
-17
fs/inode.c
··· 1243 1243 EXPORT_SYMBOL(touch_atime); 1244 1244 1245 1245 /** 1246 - * inode_inc_iversion - increments i_version 1247 - * @inode: inode that need to be updated 1248 - * 1249 - * Every time the inode is modified, the i_version field 1250 - * will be incremented. 1251 - * The filesystem has to be mounted with i_version flag 1252 - * 1253 - */ 1254 - 1255 - void inode_inc_iversion(struct inode *inode) 1256 - { 1257 - spin_lock(&inode->i_lock); 1258 - inode->i_version++; 1259 - spin_unlock(&inode->i_lock); 1260 - } 1261 - 1262 - /** 1263 1246 * file_update_time - update mtime and ctime time 1264 1247 * @file: file accessed 1265 1248 *
+5 -1
include/linux/ext4_fs.h
··· 292 292 __le32 i_flags; /* File flags */ 293 293 union { 294 294 struct { 295 - __u32 l_i_reserved1; 295 + __le32 l_i_version; 296 296 } linux1; 297 297 struct { 298 298 __u32 h_i_translator; ··· 334 334 __le32 i_atime_extra; /* extra Access time (nsec << 2 | epoch) */ 335 335 __le32 i_crtime; /* File Creation time */ 336 336 __le32 i_crtime_extra; /* extra FileCreationtime (nsec << 2 | epoch) */ 337 + __le32 i_version_hi; /* high 32 bits for 64-bit version */ 337 338 }; 338 339 339 340 ··· 408 407 raw_inode->xtime ## _extra); \ 409 408 } while (0) 410 409 410 + #define i_disk_version osd1.linux1.l_i_version 411 + 411 412 #if defined(__KERNEL__) || defined(__linux__) 412 413 #define i_reserved1 osd1.linux1.l_i_reserved1 413 414 #define i_file_acl_high osd2.linux2.l_i_file_acl_high ··· 472 469 #define EXT4_MOUNT_EXTENTS 0x400000 /* Extents support */ 473 470 #define EXT4_MOUNT_JOURNAL_CHECKSUM 0x800000 /* Journal checksums */ 474 471 #define EXT4_MOUNT_JOURNAL_ASYNC_COMMIT 0x1000000 /* Journal Async Commit */ 472 + #define EXT4_MOUNT_I_VERSION 0x2000000 /* i_version support */ 475 473 /* Compatibility, for having both ext2_fs.h and ext4_fs.h included at once */ 476 474 #ifndef _LINUX_EXT2_FS_H 477 475 #define clear_opt(o, opt) o &= ~EXT4_MOUNT_##opt
+15 -1
include/linux/fs.h
··· 1396 1396 mark_inode_dirty(inode); 1397 1397 } 1398 1398 1399 - extern void inode_inc_iversion(struct inode *inode); 1399 + /** 1400 + * inode_inc_iversion - increments i_version 1401 + * @inode: inode that need to be updated 1402 + * 1403 + * Every time the inode is modified, the i_version field will be incremented. 1404 + * The filesystem has to be mounted with i_version flag 1405 + */ 1406 + 1407 + static inline void inode_inc_iversion(struct inode *inode) 1408 + { 1409 + spin_lock(&inode->i_lock); 1410 + inode->i_version++; 1411 + spin_unlock(&inode->i_lock); 1412 + } 1413 + 1400 1414 extern void touch_atime(struct vfsmount *mnt, struct dentry *dentry); 1401 1415 static inline void file_accessed(struct file *file) 1402 1416 {