Whamcloud - gitweb
Branch HEAD
[fs/lustre-release.git] / lustre / kernel_patches / patches / ext3-nanosecond-2.6-rhel4.patch
1 Index: linux-2.6.9-rhel4/fs/ext3/ialloc.c
2 ===================================================================
3 --- linux-2.6.9-rhel4.orig/fs/ext3/ialloc.c
4 +++ linux-2.6.9-rhel4/fs/ext3/ialloc.c
5 @@ -612,7 +612,8 @@ got:
6         /* This is the optimal IO size (for stat), not the fs block size */
7         inode->i_blksize = PAGE_SIZE;
8         inode->i_blocks = 0;
9 -       inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME_SEC;
10 +       inode->i_mtime = inode->i_atime = inode->i_ctime = ei->i_crtime =
11 +                                                      ext3_current_time(inode);
12  
13         memset(ei->i_data, 0, sizeof(ei->i_data));
14         ei->i_next_alloc_block = 0;
15 @@ -650,9 +651,8 @@ got:
16         spin_unlock(&sbi->s_next_gen_lock);
17  
18         ei->i_state = EXT3_STATE_NEW;
19 -       ei->i_extra_isize =
20 -               (EXT3_INODE_SIZE(inode->i_sb) > EXT3_GOOD_OLD_INODE_SIZE) ?
21 -               sizeof(struct ext3_inode) - EXT3_GOOD_OLD_INODE_SIZE : 0;
22 +
23 +       ei->i_extra_isize = EXT3_SB(sb)->s_want_extra_isize;
24  
25         ret = inode;
26         if(DQUOT_ALLOC_INODE(inode)) {
27 Index: linux-2.6.9-rhel4/fs/ext3/inode.c
28 ===================================================================
29 --- linux-2.6.9-rhel4.orig/fs/ext3/inode.c
30 +++ linux-2.6.9-rhel4/fs/ext3/inode.c
31 @@ -627,7 +627,7 @@ static int ext3_splice_branch(handle_t *
32  
33         /* We are done with atomic stuff, now do the rest of housekeeping */
34  
35 -       inode->i_ctime = CURRENT_TIME_SEC;
36 +       inode->i_ctime = ext3_current_time(inode);
37         ext3_mark_inode_dirty(handle, inode);
38  
39         /* had we spliced it onto indirect block? */
40 @@ -2227,7 +2227,7 @@ do_indirects:
41                         ;
42         }
43         up(&ei->truncate_sem);
44 -       inode->i_mtime = inode->i_ctime = CURRENT_TIME_SEC;
45 +       inode->i_mtime = inode->i_ctime = ext3_current_time(inode);
46         ext3_mark_inode_dirty(handle, inode);
47  
48         /* In a multi-transaction truncate, we only make the final
49 @@ -2454,10 +2454,6 @@ void ext3_read_inode(struct inode * inod
50         }
51         inode->i_nlink = le16_to_cpu(raw_inode->i_links_count);
52         inode->i_size = le32_to_cpu(raw_inode->i_size);
53 -       inode->i_atime.tv_sec = le32_to_cpu(raw_inode->i_atime);
54 -       inode->i_ctime.tv_sec = le32_to_cpu(raw_inode->i_ctime);
55 -       inode->i_mtime.tv_sec = le32_to_cpu(raw_inode->i_mtime);
56 -       inode->i_atime.tv_nsec = inode->i_ctime.tv_nsec = inode->i_mtime.tv_nsec = 0;
57  
58         ei->i_state = 0;
59         ei->i_next_alloc_block = 0;
60 @@ -2518,6 +2514,11 @@ void ext3_read_inode(struct inode * inod
61         else
62                 ei->i_extra_isize = 0;
63  
64 +       EXT3_INODE_GET_XTIME(i_ctime, inode, raw_inode);
65 +       EXT3_INODE_GET_XTIME(i_mtime, inode, raw_inode);
66 +       EXT3_INODE_GET_XTIME(i_atime, inode, raw_inode);
67 +       EXT3_EINODE_GET_XTIME(i_crtime, ei, raw_inode);
68 +
69         if (S_ISREG(inode->i_mode)) {
70                 inode->i_op = &ext3_file_inode_operations;
71                 inode->i_fop = &ext3_file_operations;
72 @@ -2598,9 +2599,12 @@ static int ext3_do_update_inode(handle_t
73         }
74         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
75         raw_inode->i_size = cpu_to_le32(ei->i_disksize);
76 -       raw_inode->i_atime = cpu_to_le32(inode->i_atime.tv_sec);
77 -       raw_inode->i_ctime = cpu_to_le32(inode->i_ctime.tv_sec);
78 -       raw_inode->i_mtime = cpu_to_le32(inode->i_mtime.tv_sec);
79 +
80 +       EXT3_INODE_SET_XTIME(i_ctime, inode, raw_inode);
81 +       EXT3_INODE_SET_XTIME(i_mtime, inode, raw_inode);
82 +       EXT3_INODE_SET_XTIME(i_atime, inode, raw_inode);
83 +       EXT3_EINODE_SET_XTIME(i_crtime, ei, raw_inode);
84 +
85         raw_inode->i_blocks = cpu_to_le32(inode->i_blocks);
86         raw_inode->i_dtime = cpu_to_le32(ei->i_dtime);
87         raw_inode->i_flags = cpu_to_le32(ei->i_flags);
88 Index: linux-2.6.9-rhel4/fs/ext3/ioctl.c
89 ===================================================================
90 --- linux-2.6.9-rhel4.orig/fs/ext3/ioctl.c
91 +++ linux-2.6.9-rhel4/fs/ext3/ioctl.c
92 @@ -112,7 +112,7 @@ int ext3_ioctl (struct inode * inode, st
93                 ei->i_flags = flags;
94  
95                 ext3_set_inode_flags(inode);
96 -               inode->i_ctime = CURRENT_TIME_SEC;
97 +               inode->i_ctime = ext3_current_time(inode);
98  
99                 err = ext3_mark_iloc_dirty(handle, inode, &iloc);
100  flags_err:
101 @@ -150,7 +150,7 @@ flags_err:
102                         return PTR_ERR(handle);
103                 err = ext3_reserve_inode_write(handle, inode, &iloc);
104                 if (err == 0) {
105 -                       inode->i_ctime = CURRENT_TIME_SEC;
106 +                       inode->i_ctime = ext3_current_time(inode);
107                         inode->i_generation = generation;
108                         err = ext3_mark_iloc_dirty(handle, inode, &iloc);
109                 }
110 Index: linux-2.6.9-rhel4/fs/ext3/namei.c
111 ===================================================================
112 --- linux-2.6.9-rhel4.orig/fs/ext3/namei.c
113 +++ linux-2.6.9-rhel4/fs/ext3/namei.c
114 @@ -1302,7 +1302,7 @@ static int add_dirent_to_buf(handle_t *h
115          * happen is that the times are slightly out of date
116          * and/or different from the directory change time.
117          */
118 -       dir->i_mtime = dir->i_ctime = CURRENT_TIME_SEC;
119 +       dir->i_mtime = dir->i_ctime = ext3_current_time(dir);
120         ext3_update_dx_flag(dir);
121         dir->i_version++;
122         ext3_mark_inode_dirty(handle, dir);
123 @@ -2098,7 +2098,7 @@ static int ext3_rmdir (struct inode * di
124         inode->i_version++;
125         inode->i_nlink = 0;
126         ext3_orphan_add(handle, inode);
127 -       inode->i_ctime = dir->i_ctime = dir->i_mtime = CURRENT_TIME_SEC;
128 +       inode->i_ctime = dir->i_ctime = dir->i_mtime = ext3_current_time(inode);
129         ext3_mark_inode_dirty(handle, inode);
130         ext3_dec_count(handle, dir);
131         ext3_update_dx_flag(dir);
132 @@ -2148,13 +2148,13 @@ static int ext3_unlink(struct inode * di
133         retval = ext3_delete_entry(handle, dir, de, bh);
134         if (retval)
135                 goto end_unlink;
136 -       dir->i_ctime = dir->i_mtime = CURRENT_TIME_SEC;
137 +       dir->i_ctime = dir->i_mtime = ext3_current_time(dir);
138         ext3_update_dx_flag(dir);
139         ext3_mark_inode_dirty(handle, dir);
140         ext3_dec_count(handle, inode);
141         if (!inode->i_nlink)
142                 ext3_orphan_add(handle, inode);
143 -       inode->i_ctime = dir->i_ctime;
144 +       inode->i_ctime = ext3_current_time(inode);
145         ext3_mark_inode_dirty(handle, inode);
146         retval = 0;
147  
148 @@ -2255,7 +2255,7 @@ retry:
149         if (IS_DIRSYNC(dir))
150                 handle->h_sync = 1;
151  
152 -       inode->i_ctime = CURRENT_TIME_SEC;
153 +       inode->i_ctime = ext3_current_time(inode);
154         ext3_inc_count(handle, inode);
155         atomic_inc(&inode->i_count);
156  
157 @@ -2357,7 +2357,7 @@ static int ext3_rename (struct inode * o
158          * Like most other Unix systems, set the ctime for inodes on a
159          * rename.
160          */
161 -       old_inode->i_ctime = CURRENT_TIME_SEC;
162 +       old_inode->i_ctime = ext3_current_time(old_inode);
163         ext3_mark_inode_dirty(handle, old_inode);
164  
165         /*
166 @@ -2390,9 +2390,9 @@ static int ext3_rename (struct inode * o
167  
168         if (new_inode) {
169                 ext3_dec_count(handle, new_inode);
170 -               new_inode->i_ctime = CURRENT_TIME_SEC;
171 +               new_inode->i_ctime = ext3_current_time(new_inode);
172         }
173 -       old_dir->i_ctime = old_dir->i_mtime = CURRENT_TIME_SEC;
174 +       old_dir->i_ctime = old_dir->i_mtime = ext3_current_time(old_dir);
175         ext3_update_dx_flag(old_dir);
176         if (dir_bh) {
177                 BUFFER_TRACE(dir_bh, "get_write_access");
178 Index: linux-2.6.9-rhel4/fs/ext3/super.c
179 ===================================================================
180 --- linux-2.6.9-rhel4.orig/fs/ext3/super.c
181 +++ linux-2.6.9-rhel4/fs/ext3/super.c
182 @@ -1468,6 +1468,8 @@ static int ext3_fill_super (struct super
183                                 sbi->s_inode_size);
184                         goto failed_mount;
185                 }
186 +               if (sbi->s_inode_size > EXT3_GOOD_OLD_INODE_SIZE)
187 +                       sb->s_time_gran = 1 << (EXT3_EPOCH_BITS - 2);
188         }
189         sbi->s_frag_size = EXT3_MIN_FRAG_SIZE <<
190                                    le32_to_cpu(es->s_log_frag_size);
191 @@ -1654,6 +1656,32 @@ static int ext3_fill_super (struct super
192         }
193  
194         ext3_setup_super (sb, es, sb->s_flags & MS_RDONLY);
195 +
196 +       /* determine the minimum size of new large inodes, if present */
197 +       if (sbi->s_inode_size > EXT3_GOOD_OLD_INODE_SIZE) {
198 +               sbi->s_want_extra_isize = sizeof(struct ext3_inode) -
199 +                                                    EXT3_GOOD_OLD_INODE_SIZE;
200 +               if (EXT3_HAS_RO_COMPAT_FEATURE(sb,
201 +                                      EXT3_FEATURE_RO_COMPAT_EXTRA_ISIZE)) {
202 +                       if (sbi->s_want_extra_isize <
203 +                           le16_to_cpu(es->s_want_extra_isize))
204 +                               sbi->s_want_extra_isize =
205 +                                       le16_to_cpu(es->s_want_extra_isize);
206 +                       if (sbi->s_want_extra_isize <
207 +                           le16_to_cpu(es->s_min_extra_isize))
208 +                               sbi->s_want_extra_isize =
209 +                                       le16_to_cpu(es->s_min_extra_isize);
210 +               }
211 +       }
212 +       /* Check if enough inode space is available */
213 +       if (EXT3_GOOD_OLD_INODE_SIZE + sbi->s_want_extra_isize >
214 +                                                       sbi->s_inode_size) {
215 +               sbi->s_want_extra_isize = sizeof(struct ext3_inode) -
216 +                                                      EXT3_GOOD_OLD_INODE_SIZE;
217 +               printk(KERN_INFO "EXT3-fs: required extra inode space not"
218 +                       "available.\n");
219 +       }
220 +
221         /*
222          * akpm: core read_super() calls in here with the superblock locked.
223          * That deadlocks, because orphan cleanup needs to lock the superblock
224 Index: linux-2.6.9-rhel4/fs/ext3/xattr.c
225 ===================================================================
226 --- linux-2.6.9-rhel4.orig/fs/ext3/xattr.c
227 +++ linux-2.6.9-rhel4/fs/ext3/xattr.c
228 @@ -1305,7 +1305,7 @@ getblk_failed:
229  
230         /* Update the inode. */
231         EXT3_I(inode)->i_file_acl = new_bh ? new_bh->b_blocknr : 0;
232 -       inode->i_ctime = CURRENT_TIME_SEC;
233 +       inode->i_ctime = ext3_current_time(inode);
234         ext3_mark_inode_dirty(handle, inode);
235         if (IS_SYNC(inode))
236                 handle->h_sync = 1;
237 Index: linux-2.6.9-rhel4/include/linux/ext3_fs.h
238 ===================================================================
239 --- linux-2.6.9-rhel4.orig/include/linux/ext3_fs.h
240 +++ linux-2.6.9-rhel4/include/linux/ext3_fs.h
241 @@ -258,7 +258,7 @@ struct ext3_inode {
242         __le16  i_uid;          /* Low 16 bits of Owner Uid */
243         __le32  i_size;         /* Size in bytes */
244         __le32  i_atime;        /* Access time */
245 -       __le32  i_ctime;        /* Creation time */
246 +       __le32  i_ctime;        /* Inode Change time */
247         __le32  i_mtime;        /* Modification time */
248         __le32  i_dtime;        /* Deletion Time */
249         __le16  i_gid;          /* Low 16 bits of Group Id */
250 @@ -307,10 +307,73 @@ struct ext3_inode {
251         } osd2;                         /* OS dependent 2 */
252         __u16   i_extra_isize;
253         __u16   i_pad1;
254 +       __le32  i_ctime_extra;  /* extra Change time      (nsec << 2 | epoch) */
255 +       __le32  i_mtime_extra;  /* extra Modification time(nsec << 2 | epoch) */
256 +       __le32  i_atime_extra;  /* extra Access time      (nsec << 2 | epoch) */
257 +       __le32  i_crtime;       /* File Creation time */
258 +       __le32  i_crtime_extra; /* extra File Creation time (nsec << 2 | epoch) */
259  };
260  
261  #define i_size_high    i_dir_acl
262  
263 +#define EXT3_EPOCH_BITS 2
264 +#define EXT3_EPOCH_MASK ((1 << EXT3_EPOCH_BITS) - 1)
265 +#define EXT3_NSEC_MASK  (~0UL << EXT3_EPOCH_BITS)
266 +
267 +#define EXT3_FITS_IN_INODE(ext3_inode, einode, field)   \
268 +       ((offsetof(typeof(*ext3_inode), field) +        \
269 +        sizeof((ext3_inode)->field))                   \
270 +        <= (EXT3_GOOD_OLD_INODE_SIZE +                 \
271 +            (einode)->i_extra_isize))                  \
272 +
273 +static inline __le32 ext3_encode_extra_time(struct timespec *time)
274 +{
275 +       return cpu_to_le32((sizeof(time->tv_sec) > 4 ?
276 +                          time->tv_sec >> 32 : 0) |
277 +                          ((time->tv_nsec << 2) & EXT3_NSEC_MASK));
278 +}
279 +
280 +static inline void ext3_decode_extra_time(struct timespec *time, __le32 extra) {
281 +       if (sizeof(time->tv_sec) > 4)
282 +              time->tv_sec |= (__u64)(le32_to_cpu(extra) & EXT3_EPOCH_MASK)
283 +                                      << 32;
284 +       time->tv_nsec = (le32_to_cpu(extra) & EXT3_NSEC_MASK) >> 2;
285 +}
286 +
287 +#define EXT3_INODE_SET_XTIME(xtime, inode, raw_inode)                   \
288 +do {                                                                    \
289 +       (raw_inode)->xtime = cpu_to_le32((inode)->xtime.tv_sec);                 \
290 +       if (EXT3_FITS_IN_INODE(raw_inode, EXT3_I(inode), xtime ## _extra))\
291 +              (raw_inode)->xtime ## _extra =                            \
292 +                              ext3_encode_extra_time(&(inode)->xtime);  \
293 +} while (0)
294 +
295 +#define EXT3_EINODE_SET_XTIME(xtime, einode, raw_inode)                         \
296 +do {                                                                    \
297 +       if (EXT3_FITS_IN_INODE(raw_inode, einode, xtime))                \
298 +              (raw_inode)->xtime = cpu_to_le32((einode)->xtime.tv_sec); \
299 +       if (EXT3_FITS_IN_INODE(raw_inode, einode, xtime ## _extra))      \
300 +              (raw_inode)->xtime ## _extra =                            \
301 +                              ext3_encode_extra_time(&(einode)->xtime); \
302 +} while (0)
303 +
304 +#define EXT3_INODE_GET_XTIME(xtime, inode, raw_inode)                   \
305 +do {                                                                    \
306 +       (inode)->xtime.tv_sec = le32_to_cpu((raw_inode)->xtime);                 \
307 +       if (EXT3_FITS_IN_INODE(raw_inode, EXT3_I(inode), xtime ## _extra))\
308 +              ext3_decode_extra_time(&(inode)->xtime,                   \
309 +                                     raw_inode->xtime ## _extra);       \
310 +} while (0)
311 +
312 +#define EXT3_EINODE_GET_XTIME(xtime, einode, raw_inode)                         \
313 +do {                                                                    \
314 +       if (EXT3_FITS_IN_INODE(raw_inode, einode, xtime))                \
315 +              (einode)->xtime.tv_sec = le32_to_cpu((raw_inode)->xtime); \
316 +       if (EXT3_FITS_IN_INODE(raw_inode, einode, xtime ## _extra))      \
317 +              ext3_decode_extra_time(&(einode)->xtime,                  \
318 +                                     raw_inode->xtime ## _extra);       \
319 +} while (0)
320 +
321  #if defined(__KERNEL__) || defined(__linux__)
322  #define i_reserved1    osd1.linux1.l_i_reserved1
323  #define i_frag         osd2.linux2.l_i_frag
324 @@ -490,7 +553,9 @@ struct ext3_super_block {
325         __u16   s_reserved_word_pad;
326         __le32  s_default_mount_opts;
327         __le32  s_first_meta_bg;        /* First metablock block group */
328 -       __u32   s_reserved[190];        /* Padding to the end of the block */
329 +       __le16  s_min_extra_isize;      /* All inodes have at least # bytes */
330 +       __le16  s_want_extra_isize;     /* New inodes should reserve # bytes */
331 +       __u32   s_reserved[189];        /* Padding to the end of the block */
332  };
333  
334  #ifdef __KERNEL__
335 @@ -565,6 +630,8 @@ static inline struct ext3_inode_info *EX
336  #define EXT3_FEATURE_RO_COMPAT_LARGE_FILE      0x0002
337  #define EXT3_FEATURE_RO_COMPAT_BTREE_DIR       0x0004
338  #define EXT3_FEATURE_RO_COMPAT_DIR_NLINK       0x0020
339 +#define EXT3_FEATURE_RO_COMPAT_EXTRA_ISIZE     0x0040
340 +
341  
342  #define EXT3_FEATURE_INCOMPAT_COMPRESSION      0x0001
343  #define EXT3_FEATURE_INCOMPAT_FILETYPE         0x0002
344 @@ -581,6 +648,7 @@ static inline struct ext3_inode_info *EX
345  #define EXT3_FEATURE_RO_COMPAT_SUPP    (EXT3_FEATURE_RO_COMPAT_SPARSE_SUPER| \
346                                          EXT3_FEATURE_RO_COMPAT_LARGE_FILE| \
347                                          EXT3_FEATURE_RO_COMPAT_DIR_NLINK| \
348 +                                        EXT3_FEATURE_RO_COMPAT_EXTRA_ISIZE| \
349                                          EXT3_FEATURE_RO_COMPAT_BTREE_DIR)
350  
351  /*
352 @@ -708,6 +776,12 @@ static inline struct ext3_inode *ext3_ra
353         return (struct ext3_inode *) (iloc->bh->b_data + iloc->offset);
354  }
355  
356 +static inline struct timespec ext3_current_time(struct inode *inode)
357 +{
358 +       return (inode->i_sb->s_time_gran < NSEC_PER_SEC) ?
359 +               current_fs_time(inode->i_sb) : CURRENT_TIME_SEC;
360 +}
361 +
362  /*
363   * This structure is stuffed into the struct file's private_data field
364   * for directories.  It is where we put information so that we can do
365 Index: linux-2.6.9-rhel4/include/linux/ext3_fs_i.h
366 ===================================================================
367 --- linux-2.6.9-rhel4.orig/include/linux/ext3_fs_i.h
368 +++ linux-2.6.9-rhel4/include/linux/ext3_fs_i.h
369 @@ -130,6 +130,7 @@ struct ext3_inode_info {
370         struct inode vfs_inode;
371  
372         __u32 i_cached_extent[4];
373 +       struct timespec i_crtime;
374  };
375  
376  #endif /* _LINUX_EXT3_FS_I */
377 Index: linux-2.6.9-rhel4/include/linux/ext3_fs_sb.h
378 ===================================================================
379 --- linux-2.6.9-rhel4.orig/include/linux/ext3_fs_sb.h
380 +++ linux-2.6.9-rhel4/include/linux/ext3_fs_sb.h
381 @@ -122,6 +122,8 @@ struct ext3_sb_info {
382         spinlock_t s_bal_lock;
383         unsigned long s_mb_buddies_generated;
384         unsigned long long s_mb_generation_time;
385 +
386 +       unsigned int s_want_extra_isize; /* New inodes should reserve # bytes */
387  };
388  
389  #define EXT3_GROUP_INFO(sb, group)                                        \