Whamcloud - gitweb
LU-5626 ldiskfs: update non-htree dotdot in rename
[fs/lustre-release.git] / ldiskfs / kernel_patches / patches / rhel6.3 / ext4-data-in-dirent.patch
1 this patch implements feature which allows ext4 fs users (e.g. Lustre)
2 to store data in ext4 dirent.
3 data is stored in ext4 dirent after file-name, this space is accounted
4 in de->rec_len. flag EXT4_DIRENT_LUFID added to d_type if extra data
5 is present.
6
7 make use of dentry->d_fsdata to pass fid to ext4. so no
8 changes in ext4_add_entry() interface required.
9
10 --- a/fs/ext4/dir.c
11 +++ b/fs/ext4/dir.c
12 @@ -37,11 +37,18 @@ static int ext4_dx_readdir(struct file *
13  
14  static unsigned char get_dtype(struct super_block *sb, int filetype)
15  {
16 +       int fl_index = filetype & EXT4_FT_MASK;
17 +
18         if (!EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_FILETYPE) ||
19 -           (filetype >= EXT4_FT_MAX))
20 +           (fl_index >= EXT4_FT_MAX))
21                 return DT_UNKNOWN;
22  
23 -       return (ext4_filetype_table[filetype]);
24 +       if (!test_opt(sb, DIRDATA))
25 +               return (ext4_filetype_table[fl_index]);
26 +
27 +       return (ext4_filetype_table[fl_index]) |
28 +               (filetype & EXT4_DIRENT_LUFID);
29 +
30  }
31  
32  /**
33 @@ -73,11 +80,11 @@ int ext4_check_dir_entry(const char *fun
34         const int rlen = ext4_rec_len_from_disk(de->rec_len,
35                                                 dir->i_sb->s_blocksize);
36  
37 -       if (unlikely(rlen < EXT4_DIR_REC_LEN(1)))
38 +       if (unlikely(rlen < __EXT4_DIR_REC_LEN(1)))
39                 error_msg = "rec_len is smaller than minimal";
40         else if (unlikely(rlen % 4 != 0))
41                 error_msg = "rec_len % 4 != 0";
42 -       else if (unlikely(rlen < EXT4_DIR_REC_LEN(de->name_len)))
43 +       else if (unlikely(rlen < EXT4_DIR_REC_LEN(de)))
44                 error_msg = "rec_len is too small for name_len";
45         else if (unlikely(((char *) de - bh->b_data) + rlen > dir->i_sb->s_blocksize))
46                 error_msg = "directory entry across blocks";
47 @@ -181,7 +188,7 @@ revalidate:
48                                  * failure will be detected in the
49                                  * dirent test below. */
50                                 if (ext4_rec_len_from_disk(de->rec_len,
51 -                                       sb->s_blocksize) < EXT4_DIR_REC_LEN(1))
52 +                                       sb->s_blocksize) < __EXT4_DIR_REC_LEN(1))
53                                         break;
54                                 i += ext4_rec_len_from_disk(de->rec_len,
55                                                             sb->s_blocksize);
56 @@ -457,12 +464,17 @@ int ext4_htree_store_dirent(struct file
57         struct fname *fname, *new_fn;
58         struct dir_private_info *info;
59         int len;
60 +       int extra_data = 0;
61  
62         info = (struct dir_private_info *) dir_file->private_data;
63         p = &info->root.rb_node;
64  
65         /* Create and allocate the fname structure */
66 -       len = sizeof(struct fname) + dirent->name_len + 1;
67 +       if (dirent->file_type & EXT4_DIRENT_LUFID)
68 +               extra_data = ext4_get_dirent_data_len(dirent);
69 +
70 +       len = sizeof(struct fname) + dirent->name_len + extra_data + 1;
71 +
72         new_fn = kzalloc(len, GFP_KERNEL);
73         if (!new_fn)
74                 return -ENOMEM;
75 @@ -471,7 +483,7 @@ int ext4_htree_store_dirent(struct file
76         new_fn->inode = le32_to_cpu(dirent->inode);
77         new_fn->name_len = dirent->name_len;
78         new_fn->file_type = dirent->file_type;
79 -       memcpy(new_fn->name, dirent->name, dirent->name_len);
80 +       memcpy(new_fn->name, dirent->name, dirent->name_len + extra_data);
81         new_fn->name[dirent->name_len] = 0;
82  
83         while (*p) {
84 Index: linux-stage/fs/ext4/ext4.h
85 ===================================================================
86 --- linux-stage.orig/fs/ext4/ext4.h
87 +++ linux-stage/fs/ext4/ext4.h
88 @@ -843,6 +843,7 @@ struct ext4_inode_info {
89  #define EXT4_MOUNT_ERRORS_PANIC                0x00040 /* Panic on errors */
90  #define EXT4_MOUNT_MINIX_DF            0x00080 /* Mimics the Minix statfs */
91  #define EXT4_MOUNT_NOLOAD              0x00100 /* Don't use existing journal*/
92 +#define EXT4_MOUNT_DIRDATA             0x00200 /* Data in directory entries*/
93  #define EXT4_MOUNT_DATA_FLAGS          0x00C00 /* Mode for data writes: */
94  #define EXT4_MOUNT_JOURNAL_DATA                0x00400 /* Write data to journal */
95  #define EXT4_MOUNT_ORDERED_DATA                0x00800 /* Flush data before commit */
96 @@ -1294,6 +1295,7 @@ EXT4_INODE_BIT_FNS(state, state_flags)
97  #define EXT4_FEATURE_INCOMPAT_64BIT            0x0080
98  #define EXT4_FEATURE_INCOMPAT_MMP               0x0100
99  #define EXT4_FEATURE_INCOMPAT_FLEX_BG          0x0200
100 +#define EXT4_FEATURE_INCOMPAT_DIRDATA          0x1000
101  
102  #define EXT4_FEATURE_COMPAT_SUPP       EXT2_FEATURE_COMPAT_EXT_ATTR
103  #define EXT4_FEATURE_INCOMPAT_SUPP     (EXT4_FEATURE_INCOMPAT_FILETYPE| \
104 @@ -1302,7 +1303,9 @@ EXT4_INODE_BIT_FNS(state, state_flags)
105                                          EXT4_FEATURE_INCOMPAT_EXTENTS| \
106                                          EXT4_FEATURE_INCOMPAT_64BIT| \
107                                          EXT4_FEATURE_INCOMPAT_FLEX_BG| \
108 -                                        EXT4_FEATURE_INCOMPAT_MMP)
109 +                                        EXT4_FEATURE_INCOMPAT_MMP| \
110 +                                        EXT4_FEATURE_INCOMPAT_DIRDATA)
111 +
112  #define EXT4_FEATURE_RO_COMPAT_SUPP    (EXT4_FEATURE_RO_COMPAT_SPARSE_SUPER| \
113                                          EXT4_FEATURE_RO_COMPAT_LARGE_FILE| \
114                                          EXT4_FEATURE_RO_COMPAT_GDT_CSUM| \
115 @@ -1388,6 +1391,43 @@ struct ext4_dir_entry_2 {
116  #define EXT4_FT_SYMLINK                7
117  
118  #define EXT4_FT_MAX            8
119 +#define EXT4_FT_MASK           0xf
120 +
121 +#if EXT4_FT_MAX > EXT4_FT_MASK
122 +#error "conflicting EXT4_FT_MAX and EXT4_FT_MASK"
123 +#endif
124 +
125 +/*
126 + * d_type has 4 unused bits, so it can hold four types data. these different
127 + * type of data (e.g. lustre data, high 32 bits of 64-bit inode number) can be
128 + * stored, in flag order, after file-name in ext4 dirent.
129 +*/
130 +/*
131 + * this flag is added to d_type if ext4 dirent has extra data after
132 + * filename. this data length is variable and length is stored in first byte
133 + * of data. data start after filename NUL byte.
134 + * This is used by Lustre FS.
135 +  */
136 +#define EXT4_DIRENT_LUFID              0x10
137 +
138 +#define EXT4_LUFID_MAGIC    0xAD200907UL
139 +struct ext4_dentry_param {
140 +       __u32  edp_magic;       /* EXT4_LUFID_MAGIC */
141 +       char   edp_len;         /* size of edp_data in bytes */
142 +       char   edp_data[0];     /* packed array of data */
143 +} __attribute__((packed));
144 +
145 +static inline unsigned char *ext4_dentry_get_data(struct super_block *sb,
146 +               struct ext4_dentry_param* p)
147 +
148 +{
149 +       if (!EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_DIRDATA))
150 +               return NULL;
151 +       if (p && p->edp_magic == EXT4_LUFID_MAGIC)
152 +               return &p->edp_len;
153 +       else
154 +               return NULL;
155 +}
156  
157  /*
158   * EXT4_DIR_PAD defines the directory entries boundaries
159 @@ -1396,8 +1436,11 @@ struct ext4_dir_entry_2 {
160   */
161  #define EXT4_DIR_PAD                   4
162  #define EXT4_DIR_ROUND                 (EXT4_DIR_PAD - 1)
163 -#define EXT4_DIR_REC_LEN(name_len)     (((name_len) + 8 + EXT4_DIR_ROUND) & \
164 +#define __EXT4_DIR_REC_LEN(name_len)   (((name_len) + 8 + EXT4_DIR_ROUND) & \
165                                          ~EXT4_DIR_ROUND)
166 +#define EXT4_DIR_REC_LEN(de)           (__EXT4_DIR_REC_LEN(de->name_len +\
167 +                                       ext4_get_dirent_data_len(de)))
168 +
169  #define EXT4_MAX_REC_LEN               ((1<<16)-1)
170  
171  static inline unsigned int
172 @@ -1791,7 +1834,7 @@ extern struct buffer_head * ext4_find_en
173                                             struct ext4_dir_entry_2 ** res_dir);
174  #define ll_ext4_find_entry(inode, dentry, res_dir) ext4_find_entry(inode, &(dentry)->d_name, res_dir)
175  extern int ext4_add_dot_dotdot(handle_t *handle, struct inode *dir,
176 -                              struct inode *inode);
177 +                              struct inode *inode, const void *, const void *);
178  extern struct buffer_head *ext4_append(handle_t *handle,
179                                        struct inode *inode,
180                                        ext4_lblk_t *block, int *err);
181 @@ -2143,6 +2186,28 @@ extern wait_queue_head_t aio_wq[];
182  #define to_aio_wq(v) (&aio_wq[((unsigned long)v) % WQ_HASH_SZ])
183  extern void ext4_aio_wait(struct inode *inode);
184  
185 +/*
186 + * Compute the total directory entry data length.
187 + * This includes the filename and an implicit NUL terminator (always present),
188 + * and optional extensions.  Each extension has a bit set in the high 4 bits of
189 + * de->file_type, and the extension length is the first byte in each entry.
190 + */
191 +static inline int ext4_get_dirent_data_len(struct ext4_dir_entry_2 *de)
192 +{
193 +       char *len = de->name + de->name_len + 1 /* NUL terminator */;
194 +       int dlen = 0;
195 +       __u8 extra_data_flags = (de->file_type & ~EXT4_FT_MASK) >> 4;
196 +
197 +       while (extra_data_flags) {
198 +               if (extra_data_flags & 1) {
199 +                       dlen += *len + (dlen == 0);
200 +                       len += *len;
201 +               }
202 +               extra_data_flags >>= 1;
203 +       }
204 +       return dlen;
205 +}
206 +
207  #endif /* __KERNEL__ */
208  
209  #endif /* _EXT4_H */
210 --- a/fs/ext4/namei.c
211 +++ b/fs/ext4/namei.c
212 @@ -169,7 +169,8 @@ static unsigned dx_get_count(struct dx_e
213  static unsigned dx_get_limit(struct dx_entry *entries);
214  static void dx_set_count(struct dx_entry *entries, unsigned value);
215  static void dx_set_limit(struct dx_entry *entries, unsigned value);
216 -static unsigned dx_root_limit(struct inode *dir, unsigned infosize);
217 +static inline unsigned dx_root_limit(__u32 blocksize,
218 +               struct ext4_dir_entry_2 *dot_de, unsigned infosize);
219  static unsigned dx_node_limit(struct inode *dir);
220  static struct dx_frame *dx_probe(const struct qstr *d_name,
221                                  struct inode *dir,
222 @@ -212,11 +213,12 @@ ext4_next_entry(struct ext4_dir_entry_2
223   */
224  struct dx_root_info * dx_get_dx_info(struct ext4_dir_entry_2 *de)
225  {
226 -       /* get dotdot first */
227 -       de = (struct ext4_dir_entry_2 *)((char *)de + EXT4_DIR_REC_LEN(1));
228 +       BUG_ON(de->name_len != 1);
229 +       /* get dotdot first */
230 +       de = (struct ext4_dir_entry_2 *)((char *)de + EXT4_DIR_REC_LEN(de));
231  
232 -       /* dx root info is after dotdot entry */
233 -       de = (struct ext4_dir_entry_2 *)((char *)de + EXT4_DIR_REC_LEN(2));
234 +       /* dx root info is after dotdot entry */
235 +       de = (struct ext4_dir_entry_2 *)((char *)de + EXT4_DIR_REC_LEN(de));
236  
237         return (struct dx_root_info *) de;
238  }
239 @@ -261,16 +263,23 @@ static inline void dx_set_limit(struct d
240         ((struct dx_countlimit *) entries)->limit = cpu_to_le16(value);
241  }
242  
243 -static inline unsigned dx_root_limit(struct inode *dir, unsigned infosize)
244 +static inline unsigned dx_root_limit(__u32 blocksize,
245 +               struct ext4_dir_entry_2 *dot_de, unsigned infosize)
246  {
247 -       unsigned entry_space = dir->i_sb->s_blocksize - EXT4_DIR_REC_LEN(1) -
248 -               EXT4_DIR_REC_LEN(2) - infosize;
249 +       struct ext4_dir_entry_2 *dotdot_de;
250 +       unsigned entry_space;
251 +
252 +       BUG_ON(dot_de->name_len != 1);
253 +       dotdot_de = ext4_next_entry(dot_de, blocksize);
254 +       entry_space = blocksize - EXT4_DIR_REC_LEN(dot_de) -
255 +                        EXT4_DIR_REC_LEN(dotdot_de) - infosize;
256 +
257         return entry_space / sizeof(struct dx_entry);
258  }
259  
260  static inline unsigned dx_node_limit(struct inode *dir)
261  {
262 -       unsigned entry_space = dir->i_sb->s_blocksize - EXT4_DIR_REC_LEN(0);
263 +       unsigned entry_space = dir->i_sb->s_blocksize - __EXT4_DIR_REC_LEN(0);
264         return entry_space / sizeof(struct dx_entry);
265  }
266  
267 @@ -317,7 +326,7 @@ static struct stats dx_show_leaf(struct
268                                 printk(":%x.%u ", h.hash,
269                                        ((char *) de - base));
270                         }
271 -                       space += EXT4_DIR_REC_LEN(de->name_len);
272 +                       space += EXT4_DIR_REC_LEN(de);
273                         names++;
274                 }
275                 de = ext4_next_entry(de, size);
276 @@ -419,7 +428,8 @@ dx_probe(const struct qstr *d_name, stru
277  
278         entries = (struct dx_entry *) (((char *)info) + info->info_length);
279  
280 -       if (dx_get_limit(entries) != dx_root_limit(dir,
281 +       if (dx_get_limit(entries) != dx_root_limit(dir->i_sb->s_blocksize,
282 +                                                  (struct ext4_dir_entry_2*)bh->b_data,
283                                                    info->info_length)) {
284                 ext4_warning(dir->i_sb, "dx entry: limit != root limit");
285                 brelse(bh);
286 @@ -608,7 +618,7 @@ static int htree_dirblock_to_tree(struct
287         de = (struct ext4_dir_entry_2 *) bh->b_data;
288         top = (struct ext4_dir_entry_2 *) ((char *) de +
289                                            dir->i_sb->s_blocksize -
290 -                                          EXT4_DIR_REC_LEN(0));
291 +                                          __EXT4_DIR_REC_LEN(0));
292         for (; de < top; de = ext4_next_entry(de, dir->i_sb->s_blocksize)) {
293                 if (!ext4_check_dir_entry("htree_dirblock_to_tree", dir, de, bh,
294                                         (block<<EXT4_BLOCK_SIZE_BITS(dir->i_sb))
295 @@ -1020,7 +1030,7 @@ static struct buffer_head * ext4_dx_find
296                         goto errout;
297                 de = (struct ext4_dir_entry_2 *) bh->b_data;
298                 top = (struct ext4_dir_entry_2 *) ((char *) de + sb->s_blocksize -
299 -                                      EXT4_DIR_REC_LEN(0));
300 +                                      __EXT4_DIR_REC_LEN(0));
301                 for (; de < top; de = ext4_next_entry(de, sb->s_blocksize)) {
302                         int off = (block << EXT4_BLOCK_SIZE_BITS(sb))
303                                   + ((char *) de - bh->b_data);
304 @@ -1181,7 +1191,7 @@ dx_move_dirents(char *from, char *to, st
305         while (count--) {
306                 struct ext4_dir_entry_2 *de = (struct ext4_dir_entry_2 *) 
307                                                 (from + (map->offs<<2));
308 -               rec_len = EXT4_DIR_REC_LEN(de->name_len);
309 +               rec_len = EXT4_DIR_REC_LEN(de);
310                 memcpy (to, de, rec_len);
311                 ((struct ext4_dir_entry_2 *) to)->rec_len =
312                                 ext4_rec_len_to_disk(rec_len, blocksize);
313 @@ -1205,7 +1215,7 @@ static struct ext4_dir_entry_2* dx_pack_
314         while ((char*)de < base + blocksize) {
315                 next = ext4_next_entry(de, blocksize);
316                 if (de->inode && de->name_len) {
317 -                       rec_len = EXT4_DIR_REC_LEN(de->name_len);
318 +                       rec_len = EXT4_DIR_REC_LEN(de);
319                         if (de > to)
320                                 memmove(to, de, rec_len);
321                         to->rec_len = ext4_rec_len_to_disk(rec_len, blocksize);
322 @@ -1334,11 +1344,28 @@ static int add_dirent_to_buf(handle_t *h
323         int             namelen = dentry->d_name.len;
324         unsigned int    offset = 0;
325         unsigned int    blocksize = dir->i_sb->s_blocksize;
326 -       unsigned short  reclen;
327 -       int             nlen, rlen, err;
328 +       unsigned short  reclen, dotdot_reclen = 0;
329 +       int             nlen, rlen, err, dlen = 0;
330 +       bool            is_dotdot = false, write_short_dotdot = false;
331 +       unsigned char   *data;
332         char            *top;
333  
334 -       reclen = EXT4_DIR_REC_LEN(namelen);
335 +       data = ext4_dentry_get_data(inode->i_sb, (struct ext4_dentry_param *)
336 +                                               dentry->d_fsdata);
337 +       if (data)
338 +               dlen = (*data) + 1;
339 +
340 +       is_dotdot = (namelen == 2 &&
341 +                    memcmp(dentry->d_name.name, "..", 2) == 0);
342 +
343 +       /* dotdot entries must be in the second place in a directory block,
344 +        * so calculate an alternate length without the FID so they can
345 +        * always be made to fit in the existing slot - LU-5626 */
346 +       if (is_dotdot)
347 +               dotdot_reclen = __EXT4_DIR_REC_LEN(namelen);
348 +
349 +       reclen = __EXT4_DIR_REC_LEN(namelen + dlen);
350 +
351         if (!de) {
352                 de = (struct ext4_dir_entry_2 *)bh->b_data;
353                 top = bh->b_data + blocksize - reclen;
354 @@ -1348,10 +1375,25 @@ static int add_dirent_to_buf(handle_t *h
355                                 return -EIO;
356                         if (ext4_match(namelen, name, de))
357                                 return -EEXIST;
358 -                       nlen = EXT4_DIR_REC_LEN(de->name_len);
359 +                       nlen = EXT4_DIR_REC_LEN(de);
360                         rlen = ext4_rec_len_from_disk(de->rec_len, blocksize);
361 -                       if ((de->inode? rlen - nlen: rlen) >= reclen)
362 +                       /* Check first for enough space for the full entry */
363 +                       if ((de->inode ? rlen - nlen : rlen) >= reclen)
364                                 break;
365 +                       /* Then for dotdot entries, check for the smaller space
366 +                        * required for just the entry, no FID */
367 +                       if (is_dotdot) {
368 +                               if ((de->inode ? rlen - nlen : rlen) >=
369 +                                   dotdot_reclen) {
370 +                                       write_short_dotdot = true;
371 +                                       break;
372 +                               }
373 +                               /* The new ".." entry mut be written over the
374 +                                * previous ".." entry, which is the first
375 +                                * entry traversed by this scan.  If it doesn't
376 +                                * fit, something is badly wrong, so -EIO. */
377 +                               return -EIO;
378 +                       }
379                         de = (struct ext4_dir_entry_2 *)((char *)de + rlen);
380                         offset += rlen;
381                 }
382 @@ -1366,7 +1408,7 @@ static int add_dirent_to_buf(handle_t *h
383         }
384  
385         /* By now the buffer is marked for journaling */
386 -       nlen = EXT4_DIR_REC_LEN(de->name_len);
387 +       nlen = EXT4_DIR_REC_LEN(de);
388         rlen = ext4_rec_len_from_disk(de->rec_len, blocksize);
389         if (de->inode) {
390                 struct ext4_dir_entry_2 *de1 = (struct ext4_dir_entry_2 *)((char *)de + nlen);
391 @@ -1382,6 +1424,13 @@ static int add_dirent_to_buf(handle_t *h
392                 de->inode = 0;
393         de->name_len = namelen;
394         memcpy(de->name, name, namelen);
395 +       /* If we're writing the short form of "dotdot", don't add the data section */
396 +       if (data && !write_short_dotdot) {
397 +               de->name[namelen] = 0;
398 +               memcpy(&de->name[namelen + 1], data, *(char *) data);
399 +               de->file_type |= EXT4_DIRENT_LUFID;
400 +       }
401 +
402         /*
403          * XXX shouldn't update any times until successful
404          * completion of syscall, but too many callers depend
405 @@ -1480,7 +1529,8 @@ static int make_indexed_dir(handle_t *ha
406  
407         dx_set_block(entries, 1);
408         dx_set_count(entries, 1);
409 -       dx_set_limit(entries, dx_root_limit(dir, sizeof(*dx_info)));
410 +       dx_set_limit(entries, dx_root_limit(dir->i_sb->s_blocksize,
411 +                                        dot_de, sizeof(*dx_info)));
412  
413         /* Initialize as for dx_probe */
414         hinfo.hash_version = dx_info->hash_version;
415 @@ -1523,6 +1573,8 @@ static int ext4_update_dotdot(handle_t *
416         struct buffer_head * dir_block;
417         struct ext4_dir_entry_2 * de;
418         int len, journal = 0, err = 0;
419 +       int dlen = 0;
420 +       char *data;
421  
422         if (IS_ERR(handle))
423                 return PTR_ERR(handle);
424 @@ -1538,19 +1590,24 @@ static int ext4_update_dotdot(handle_t *
425         /* the first item must be "." */
426         assert(de->name_len == 1 && de->name[0] == '.');
427         len = le16_to_cpu(de->rec_len);
428 -       assert(len >= EXT4_DIR_REC_LEN(1));
429 -       if (len > EXT4_DIR_REC_LEN(1)) {
430 +       assert(len >= __EXT4_DIR_REC_LEN(1));
431 +       if (len > __EXT4_DIR_REC_LEN(1)) {
432                 BUFFER_TRACE(dir_block, "get_write_access");
433                 err = ext4_journal_get_write_access(handle, dir_block);
434                 if (err)
435                         goto out_journal;
436  
437                 journal = 1;
438 -               de->rec_len = cpu_to_le16(EXT4_DIR_REC_LEN(1));
439 +               de->rec_len = cpu_to_le16(EXT4_DIR_REC_LEN(de));
440         }
441  
442 -       len -= EXT4_DIR_REC_LEN(1);
443 -       assert(len == 0 || len >= EXT4_DIR_REC_LEN(2));
444 +       len -= EXT4_DIR_REC_LEN(de);
445 +       data = ext4_dentry_get_data(dir->i_sb,
446 +                       (struct ext4_dentry_param *) dentry->d_fsdata);
447 +       if (data)
448 +               dlen = *data + 1;
449 +       assert(len == 0 || len >= __EXT4_DIR_REC_LEN(2 + dlen));
450 +
451         de = (struct ext4_dir_entry_2 *)
452                         ((char *) de + le16_to_cpu(de->rec_len));
453         if (!journal) {
454 @@ -1564,10 +1621,15 @@ static int ext4_update_dotdot(handle_t *
455         if (len > 0)
456                 de->rec_len = cpu_to_le16(len);
457         else
458 -               assert(le16_to_cpu(de->rec_len) >= EXT4_DIR_REC_LEN(2));
459 +               assert(le16_to_cpu(de->rec_len) >= __EXT4_DIR_REC_LEN(2));
460         de->name_len = 2;
461         strcpy (de->name, "..");
462 -       ext4_set_de_type(dir->i_sb, de, S_IFDIR);
463 +       if (data != NULL && ext4_get_dirent_data_len(de) >= dlen) {
464 +               de->name[2] = 0;
465 +               memcpy(&de->name[2 + 1], data, *data);
466 +               ext4_set_de_type(dir->i_sb, de, S_IFDIR);
467 +               de->file_type |= EXT4_DIRENT_LUFID;
468 +       }
469  
470  out_journal:
471         if (journal) {
472 @@ -1991,12 +2053,13 @@ retry:
473  /* Initialize @inode as a subdirectory of @dir, and add the
474   * "." and ".." entries into the first directory block. */
475  int ext4_add_dot_dotdot(handle_t *handle, struct inode * dir,
476 -                       struct inode *inode)
477 +                       struct inode *inode,
478 +                        const void *data1, const void *data2)
479  {
480         struct buffer_head * dir_block;
481         struct ext4_dir_entry_2 * de;
482         unsigned int blocksize = dir->i_sb->s_blocksize;
483 -       int err = 0;
484 +       int err = 0, dot_reclen;
485  
486         if (IS_ERR(handle))
487                 return PTR_ERR(handle);
488 @@ -2017,17 +2080,32 @@ int ext4_add_dot_dotdot(handle_t *handle
489         de = (struct ext4_dir_entry_2 *) dir_block->b_data;
490         de->inode = cpu_to_le32(inode->i_ino);
491         de->name_len = 1;
492 -       de->rec_len = ext4_rec_len_to_disk(EXT4_DIR_REC_LEN(de->name_len),
493 -                                          blocksize);
494         strcpy(de->name, ".");
495         ext4_set_de_type(dir->i_sb, de, S_IFDIR);
496 +       /* get packed fid data*/
497 +       data1 = ext4_dentry_get_data(dir->i_sb,
498 +                               (struct ext4_dentry_param *) data1);
499 +       if (data1) {
500 +               de->name[1] = 0;
501 +               memcpy(&de->name[2], data1, *(char *) data1);
502 +               de->file_type |= EXT4_DIRENT_LUFID;
503 +       }
504 +       de->rec_len = cpu_to_le16(EXT4_DIR_REC_LEN(de));
505 +       dot_reclen = cpu_to_le16(de->rec_len);
506         de = ext4_next_entry(de, blocksize);
507         de->inode = cpu_to_le32(dir->i_ino);
508 -       de->rec_len = ext4_rec_len_to_disk(blocksize - EXT4_DIR_REC_LEN(1),
509 +       de->rec_len = ext4_rec_len_to_disk(blocksize - dot_reclen,
510                                            blocksize);
511         de->name_len = 2;
512         strcpy(de->name, "..");
513         ext4_set_de_type(dir->i_sb, de, S_IFDIR);
514 +       data2 = ext4_dentry_get_data(dir->i_sb,
515 +                       (struct ext4_dentry_param *) data2);
516 +       if (data2) {
517 +               de->name[2] = 0;
518 +               memcpy(&de->name[3], data2, *(char *) data2);
519 +               de->file_type |= EXT4_DIRENT_LUFID;
520 +       }
521         inode->i_nlink = 2;
522         BUFFER_TRACE(dir_block, "call ext4_handle_dirty_metadata");
523         err = ext4_handle_dirty_metadata(handle, inode, dir_block);
524 @@ -2066,7 +2144,7 @@ retry:
525         if (IS_ERR(inode))
526                 goto out_stop;
527  
528 -       err = ext4_add_dot_dotdot(handle, dir, inode);
529 +       err = ext4_add_dot_dotdot(handle, dir, inode, NULL, NULL);
530         if (err)
531                 goto out_clear_inode;
532  
533 @@ -2105,7 +2183,7 @@ static int empty_dir(struct inode *inode
534         int err = 0;
535  
536         sb = inode->i_sb;
537 -       if (inode->i_size < EXT4_DIR_REC_LEN(1) + EXT4_DIR_REC_LEN(2) ||
538 +       if (inode->i_size < __EXT4_DIR_REC_LEN(1) + __EXT4_DIR_REC_LEN(2) ||
539             !(bh = ext4_bread(NULL, inode, 0, 0, &err))) {
540                 if (err)
541                         ext4_error(inode->i_sb,
542 diff -ur a/fs/ext4/super.c b/fs/ext4/super.c
543 --- a/fs/ext4/super.c    2014-01-02 11:40:34.000000000 -0500
544 +++ b/fs/ext4/super.c 2014-01-02 11:46:45.000000000 -0500
545 @@ -1191,7 +1191,7 @@
546         Opt_usrjquota, Opt_grpjquota, Opt_offusrjquota, Opt_offgrpjquota,
547         Opt_jqfmt_vfsold, Opt_jqfmt_vfsv0, Opt_jqfmt_vfsv1, Opt_quota,
548         Opt_noquota, Opt_ignore, Opt_barrier, Opt_nobarrier, Opt_err,
549 -       Opt_iopen, Opt_noiopen, Opt_iopen_nopriv,
550 +       Opt_iopen, Opt_noiopen, Opt_iopen_nopriv, Opt_dirdata,
551         Opt_resize, Opt_usrquota, Opt_grpquota, Opt_i_version,
552         Opt_stripe, Opt_delalloc, Opt_nodelalloc,
553         Opt_block_validity, Opt_noblock_validity,
554 @@ -1253,6 +1253,7 @@
555         {Opt_iopen, "iopen"},
556         {Opt_noiopen, "noiopen"},
557         {Opt_iopen_nopriv, "iopen_nopriv"},
558 +       {Opt_dirdata, "dirdata"},
559         {Opt_barrier, "barrier=%u"},
560         {Opt_barrier, "barrier"},
561         {Opt_nobarrier, "nobarrier"},
562 @@ -1631,6 +1632,9 @@
563                 case Opt_noiopen:
564                 case Opt_iopen_nopriv:
565                         break;
566 +               case Opt_dirdata:
567 +                       set_opt(sbi->s_mount_opt, DIRDATA);
568 +                       break;
569                 case Opt_ignore:
570                         break;
571                 case Opt_resize: