Whamcloud - gitweb
b=22769 improve error message for dx_probe
[fs/lustre-release.git] / ldiskfs / kernel_patches / patches / 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 Index: b/fs/ext4/dir.c
11 ===================================================================
12 --- a/fs/ext4/dir.c
13 +++ b/fs/ext4/dir.c
14 @@ -53,11 +53,18 @@ const struct file_operations ext4_dir_op
15  
16  static unsigned char get_dtype(struct super_block *sb, int filetype)
17  {
18 +       int fl_index = filetype & EXT4_FT_MASK;
19 +
20         if (!EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_FILETYPE) ||
21 -           (filetype >= EXT4_FT_MAX))
22 +           (fl_index >= EXT4_FT_MAX))
23                 return DT_UNKNOWN;
24  
25 -       return (ext4_filetype_table[filetype]);
26 +       if (!EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_DIRDATA))
27 +               return (ext4_filetype_table[fl_index]);
28 +
29 +       return (ext4_filetype_table[fl_index]) |
30 +               (filetype & EXT4_DIRENT_LUFID);
31 +
32  }
33  
34  
35 @@ -69,11 +76,11 @@ int ext4_check_dir_entry (const char * f
36         const char * error_msg = NULL;
37         const int rlen = ext4_rec_len_from_disk(de->rec_len);
38  
39 -       if (rlen < EXT4_DIR_REC_LEN(1))
40 +       if (rlen < __EXT4_DIR_REC_LEN(1))
41                 error_msg = "rec_len is smaller than minimal";
42         else if (rlen % 4 != 0)
43                 error_msg = "rec_len % 4 != 0";
44 -       else if (rlen < EXT4_DIR_REC_LEN(de->name_len))
45 +       else if (rlen < EXT4_DIR_REC_LEN(de))
46                 error_msg = "rec_len is too small for name_len";
47         else if (((char *) de - bh->b_data) + rlen > dir->i_sb->s_blocksize)
48                 error_msg = "directory entry across blocks";
49 @@ -175,7 +182,7 @@ revalidate:
50                                  * failure will be detected in the
51                                  * dirent test below. */
52                                 if (ext4_rec_len_from_disk(de->rec_len,
53 -                                       sb->s_blocksize) < EXT4_DIR_REC_LEN(1))
54 +                                       sb->s_blocksize) < __EXT4_DIR_REC_LEN(1))
55                                         break;
56                                 i += ext4_rec_len_from_disk(de->rec_len);
57                         }
58 @@ -335,12 +342,17 @@ int ext4_htree_store_dirent(struct file 
59         struct fname * fname, *new_fn;
60         struct dir_private_info *info;
61         int len;
62 +       int extra_data = 1;
63  
64         info = (struct dir_private_info *) dir_file->private_data;
65         p = &info->root.rb_node;
66  
67         /* Create and allocate the fname structure */
68 -       len = sizeof(struct fname) + dirent->name_len + 1;
69 +       if (dirent->file_type & EXT4_DIRENT_LUFID)
70 +               extra_data = ext4_get_dirent_data_len(dirent);
71 +
72 +       len = sizeof(struct fname) + dirent->name_len + extra_data;
73 +
74         new_fn = kzalloc(len, GFP_KERNEL);
75         if (!new_fn)
76                 return -ENOMEM;
77 @@ -349,7 +361,7 @@ int ext4_htree_store_dirent(struct file 
78         new_fn->inode = le32_to_cpu(dirent->inode);
79         new_fn->name_len = dirent->name_len;
80         new_fn->file_type = dirent->file_type;
81 -       memcpy(new_fn->name, dirent->name, dirent->name_len);
82 +       memcpy(new_fn->name, dirent->name, dirent->name_len + extra_data);
83         new_fn->name[dirent->name_len] = 0;
84  
85         while (*p) {
86 Index: b/fs/ext4/ext4.h
87 ===================================================================
88 --- a/fs/ext4/ext4.h
89 +++ b/fs/ext4/ext4.h
90 @@ -771,6 +771,7 @@ static inline int ext4_valid_inum(struct
91  #define EXT4_FEATURE_INCOMPAT_64BIT            0x0080
92  #define EXT4_FEATURE_INCOMPAT_MMP               0x0100
93  #define EXT4_FEATURE_INCOMPAT_FLEX_BG          0x0200
94 +#define EXT4_FEATURE_INCOMPAT_DIRDATA          0x1000
95  
96  #define EXT4_FEATURE_COMPAT_SUPP       EXT2_FEATURE_COMPAT_EXT_ATTR
97  #define EXT4_FEATURE_INCOMPAT_SUPP     (EXT4_FEATURE_INCOMPAT_FILETYPE| \
98 @@ -779,7 +780,9 @@ static inline int ext4_valid_inum(struct
99                                          EXT4_FEATURE_INCOMPAT_EXTENTS| \
100                                          EXT4_FEATURE_INCOMPAT_64BIT| \
101                                          EXT4_FEATURE_INCOMPAT_FLEX_BG| \
102 -                                        EXT4_FEATURE_INCOMPAT_MMP)
103 +                                        EXT4_FEATURE_INCOMPAT_MMP| \
104 +                                        EXT4_FEATURE_INCOMPAT_DIRDATA)
105 +
106  #define EXT4_FEATURE_RO_COMPAT_SUPP    (EXT4_FEATURE_RO_COMPAT_SPARSE_SUPER| \
107                                          EXT4_FEATURE_RO_COMPAT_LARGE_FILE| \
108                                          EXT4_FEATURE_RO_COMPAT_GDT_CSUM| \
109 @@ -847,6 +850,43 @@ struct ext4_dir_entry_2 {
110  #define EXT4_FT_SYMLINK                7
111  
112  #define EXT4_FT_MAX            8
113 +#define EXT4_FT_MASK           0xf
114 +
115 +#if EXT4_FT_MAX > EXT4_FT_MASK
116 +#error "conflicting EXT4_FT_MAX and EXT4_FT_MASK"
117 +#endif
118 +
119 +/*
120 + * d_type has 4 unused bits, so it can hold four types data. these different
121 + * type of data (e.g. lustre data, high 32 bits of 64-bit inode number) can be
122 + * stored, in flag order, after file-name in ext4 dirent.
123 +*/
124 +/*
125 + * this flag is added to d_type if ext4 dirent has extra data after
126 + * filename. this data length is variable and length is stored in first byte
127 + * of data. data start after filename NUL byte.
128 + * This is used by Lustre FS.
129 +  */
130 +#define EXT4_DIRENT_LUFID              0x10
131 +
132 +#define EXT4_LUFID_MAGIC    0xAD200907UL
133 +struct ext4_dentry_param {
134 +       __u32  edp_magic;       /* EXT4_LUFID_MAGIC */
135 +       char   edp_len;         /* size of edp_data in bytes */
136 +       char   edp_data[0];     /* packed array of data */
137 +} __attribute__((packed));
138 +
139 +static inline unsigned char *ext4_dentry_get_data(struct super_block *sb,
140 +               struct ext4_dentry_param* p)
141 +
142 +{
143 +       if (!EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_DIRDATA))
144 +               return NULL;
145 +       if (p && p->edp_magic == EXT4_LUFID_MAGIC)
146 +               return &p->edp_len;
147 +       else
148 +               return NULL;
149 +}
150  
151  /*
152   * EXT4_DIR_PAD defines the directory entries boundaries
153 @@ -855,8 +895,11 @@ struct ext4_dir_entry_2 {
154   */
155  #define EXT4_DIR_PAD                   4
156  #define EXT4_DIR_ROUND                 (EXT4_DIR_PAD - 1)
157 -#define EXT4_DIR_REC_LEN(name_len)     (((name_len) + 8 + EXT4_DIR_ROUND) & \
158 +#define __EXT4_DIR_REC_LEN(name_len)   (((name_len) + 8 + EXT4_DIR_ROUND) & \
159                                          ~EXT4_DIR_ROUND)
160 +#define EXT4_DIR_REC_LEN(de)           (__EXT4_DIR_REC_LEN(de->name_len +\
161 +                                       ext4_get_dirent_data_len(de)))
162 +
163  #define EXT4_MAX_REC_LEN               ((1<<16)-1)
164  
165  static inline unsigned ext4_rec_len_from_disk(__le16 dlen)
166 @@ -1155,7 +1198,7 @@ extern struct buffer_head * ext4_find_en
167                                             struct ext4_dir_entry_2
168                                             ** res_dir);
169  extern int ext4_add_dot_dotdot(handle_t *handle, struct inode *dir,
170 -                                 struct inode *inode);
171 +                         struct inode *inode, const void *, const void *);
172  extern unsigned int ext4_rec_len_from_disk(__le16 dlen, unsigned blocksize);
173  extern __le16 ext4_rec_len_to_disk(unsigned len, unsigned blocksize);
174  extern int ext4_orphan_add(handle_t *, struct inode *);
175 @@ -1343,6 +1386,28 @@ static inline int ext4_is_group_locked(s
176
177         return spin_is_locked(ext4_group_lock_ptr(sb, group));
178  }
179 +/*
180 + * Compute the total directory entry data length.
181 + * This includes the filename and an implicit NUL terminator (always present),
182 + * and optional extensions.  Each extension has a bit set in the high 4 bits of
183 + * de->file_type, and the extension length is the first byte in each entry.
184 + */
185 +
186 +static inline int ext4_get_dirent_data_len(struct ext4_dir_entry_2 *de)
187 +{
188 +       char *len = de->name + de->name_len + 1 /* NUL terminator */;
189 +       int dlen = 0;
190 +       __u8 extra_data_flags = (de->file_type & ~EXT4_FT_MASK) >> 4;
191 +
192 +       while (extra_data_flags) {
193 +               if (extra_data_flags & 1) {
194 +                       dlen += *len + (dlen == 0);
195 +                       len += *len;
196 +               }
197 +               extra_data_flags >>= 1;
198 +       }
199 +       return dlen;
200 +}
201  
202  #endif /* __KERNEL__ */
203  
204 Index: b/fs/ext4/namei.c
205 ===================================================================
206 --- a/fs/ext4/namei.c
207 +++ b/fs/ext4/namei.c
208 @@ -177,7 +177,8 @@ static unsigned dx_get_count (struct dx_
209  static unsigned dx_get_limit (struct dx_entry *entries);
210  static void dx_set_count(struct dx_entry *entries, unsigned value);
211  static void dx_set_limit(struct dx_entry *entries, unsigned value);
212 -static unsigned dx_root_limit(struct inode *dir, unsigned infosize);
213 +static inline unsigned dx_root_limit(__u32 blocksize,
214 +               struct ext4_dir_entry_2 *dot_de, unsigned infosize);
215  static unsigned dx_node_limit(struct inode *dir);
216  static struct dx_frame *dx_probe(struct dentry *dentry,
217                                  struct inode *dir,
218 @@ -218,11 +219,12 @@ ext4_next_entry(struct ext4_dir_entry_2 
219   */
220  struct dx_root_info * dx_get_dx_info(struct ext4_dir_entry_2 *de)
221  {
222 -       /* get dotdot first */
223 -       de = (struct ext4_dir_entry_2 *)((char *)de + EXT4_DIR_REC_LEN(1));
224 +       BUG_ON(de->name_len != 1);
225 +       /* get dotdot first */
226 +       de = (struct ext4_dir_entry_2 *)((char *)de + EXT4_DIR_REC_LEN(de));
227  
228 -       /* dx root info is after dotdot entry */
229 -       de = (struct ext4_dir_entry_2 *)((char *)de + EXT4_DIR_REC_LEN(2));
230 +       /* dx root info is after dotdot entry */
231 +       de = (struct ext4_dir_entry_2 *)((char *)de + EXT4_DIR_REC_LEN(de));
232  
233         return (struct dx_root_info *) de;
234  }
235 @@ -267,16 +269,23 @@ static inline void dx_set_limit (struct 
236         ((struct dx_countlimit *) entries)->limit = cpu_to_le16(value);
237  }
238  
239 -static inline unsigned dx_root_limit(struct inode *dir, unsigned infosize)
240 +static inline unsigned dx_root_limit(__u32 blocksize,
241 +               struct ext4_dir_entry_2 *dot_de, unsigned infosize)
242  {
243 -       unsigned entry_space = dir->i_sb->s_blocksize - EXT4_DIR_REC_LEN(1) -
244 -               EXT4_DIR_REC_LEN(2) - infosize;
245 +       struct ext4_dir_entry_2 *dotdot_de;
246 +       unsigned entry_space;
247 +
248 +       BUG_ON(dot_de->name_len != 1);
249 +       dotdot_de = ext4_next_entry(dot_de, blocksize);
250 +       entry_space = blocksize - EXT4_DIR_REC_LEN(dot_de) -
251 +                        EXT4_DIR_REC_LEN(dotdot_de) - infosize;
252 +
253         return entry_space / sizeof(struct dx_entry);
254  }
255  
256  static inline unsigned dx_node_limit(struct inode *dir)
257  {
258 -       unsigned entry_space = dir->i_sb->s_blocksize - EXT4_DIR_REC_LEN(0);
259 +       unsigned entry_space = dir->i_sb->s_blocksize - __EXT4_DIR_REC_LEN(0);
260         return entry_space / sizeof(struct dx_entry);
261  }
262  
263 @@ -323,7 +332,7 @@ static struct stats dx_show_leaf(struct 
264                                 printk(":%x.%u ", h.hash,
265                                        ((char *) de - base));
266                         }
267 -                       space += EXT4_DIR_REC_LEN(de->name_len);
268 +                       space += EXT4_DIR_REC_LEN(de);
269                         names++;
270                 }
271                 de = ext4_next_entry(de);
272 @@ -427,7 +436,8 @@ dx_probe(struct dentry *dentry, struct i
273  
274         entries = (struct dx_entry *) (((char *)info) + info->info_length);
275  
276 -       if (dx_get_limit(entries) != dx_root_limit(dir,
277 +       if (dx_get_limit(entries) != dx_root_limit(dir->i_sb->s_blocksize,
278 +                                                  (struct ext4_dir_entry_2*)bh->b_data,
279                                                    info->info_length)) {
280                 ext4_warning(dir->i_sb, __func__,
281                              "dx entry: limit != root limit");
282 @@ -485,14 +495,17 @@ dx_probe(const struct qstr *d_name, stru
283                 if (!indirect--) return frame;
284                 if (!(bh = ext4_bread (NULL,dir, dx_get_block(at), 0, err)))
285                         goto fail2;
286 -               at = entries = ((struct dx_node *) bh->b_data)->entries;
287 +               entries = ((struct dx_node *) bh->b_data)->entries;
288                 if (dx_get_limit(entries) != dx_node_limit (dir)) {
289                         ext4_warning(dir->i_sb, __func__,
290 -                                    "dx entry: limit != node limit");
291 +                                    "block %u(%lu): limit %u != node limit %u",
292 +                                    dx_get_block(at), (long)bh->b_blocknr,
293 +                                    dx_get_limit(entries), dx_node_limit(dir));
294                         brelse(bh);
295                         *err = ERR_BAD_DX_DIR;
296                         goto fail2;
297                 }
298 +               at = entries;
299                 frame++;
300                 frame->bh = NULL;
301         }
302 @@ -618,7 +631,7 @@ static int htree_dirblock_to_tree(struct
303         de = (struct ext4_dir_entry_2 *) bh->b_data;
304         top = (struct ext4_dir_entry_2 *) ((char *) de +
305                                            dir->i_sb->s_blocksize -
306 -                                          EXT4_DIR_REC_LEN(0));
307 +                                          __EXT4_DIR_REC_LEN(0));
308         for (; de < top; de = ext4_next_entry(de, dir->i_sb->s_blocksize)) {
309                 if (!ext4_check_dir_entry("htree_dirblock_to_tree", dir, de, bh,
310                                         (block<<EXT4_BLOCK_SIZE_BITS(dir->i_sb))
311 @@ -1026,7 +1036,7 @@ static struct buffer_head * ext4_dx_find
312                         goto errout;
313                 de = (struct ext4_dir_entry_2 *) bh->b_data;
314                 top = (struct ext4_dir_entry_2 *) ((char *) de + sb->s_blocksize -
315 -                                      EXT4_DIR_REC_LEN(0));
316 +                                       __EXT4_DIR_REC_LEN(0));
317                 for (; de < top; de = ext4_next_entry(de, sb->s_blocksize)) {
318                         int off = (block << EXT4_BLOCK_SIZE_BITS(sb))
319                                   + ((char *) de - bh->b_data);
320 @@ -1193,7 +1203,7 @@ dx_move_dirents(char *from, char *to, st
321         while (count--) {
322                 struct ext4_dir_entry_2 *de = (struct ext4_dir_entry_2 *) 
323                                                 (from + (map->offs<<2));
324 -               rec_len = EXT4_DIR_REC_LEN(de->name_len);
325 +               rec_len = EXT4_DIR_REC_LEN(de);
326                 memcpy (to, de, rec_len);
327                 ((struct ext4_dir_entry_2 *) to)->rec_len =
328                                 ext4_rec_len_to_disk(rec_len);
329 @@ -1217,7 +1227,7 @@ static struct ext4_dir_entry_2* dx_pack_
330         while ((char*)de < base + size) {
331                 next = ext4_next_entry(de);
332                 if (de->inode && de->name_len) {
333 -                       rec_len = EXT4_DIR_REC_LEN(de->name_len);
334 +                       rec_len = EXT4_DIR_REC_LEN(de);
335                         if (de > to)
336                                 memmove(to, de, rec_len);
337                         to->rec_len = ext4_rec_len_to_disk(rec_len);
338 @@ -1347,10 +1357,16 @@ static int add_dirent_to_buf(handle_t *h
339         int             namelen = dentry->d_name.len;
340         unsigned long   offset = 0;
341         unsigned short  reclen;
342 -       int             nlen, rlen, err;
343 +       int             nlen, rlen, err, dlen = 0;
344 +       unsigned char   *data;
345         char            *top;
346  
347 -       reclen = EXT4_DIR_REC_LEN(namelen);
348 +       data = ext4_dentry_get_data(inode->i_sb, (struct ext4_dentry_param *)
349 +                                               dentry->d_fsdata);
350 +       if (data)
351 +               dlen = (*data) + 1;
352 +
353 +       reclen = __EXT4_DIR_REC_LEN(namelen + dlen);
354         if (!de) {
355                 de = (struct ext4_dir_entry_2 *)bh->b_data;
356                 top = bh->b_data + dir->i_sb->s_blocksize - reclen;
357 @@ -1364,7 +1380,7 @@ static int add_dirent_to_buf(handle_t *h
358                                 brelse (bh);
359                                 return -EEXIST;
360                         }
361 -                       nlen = EXT4_DIR_REC_LEN(de->name_len);
362 +                       nlen = EXT4_DIR_REC_LEN(de);
363                         rlen = ext4_rec_len_from_disk(de->rec_len, blocksize);
364                         if ((de->inode? rlen - nlen: rlen) >= reclen)
365                                 break;
366 @@ -1383,7 +1399,7 @@ static int add_dirent_to_buf(handle_t *h
367         }
368  
369         /* By now the buffer is marked for journaling */
370 -       nlen = EXT4_DIR_REC_LEN(de->name_len);
371 +       nlen = EXT4_DIR_REC_LEN(de);
372         rlen = ext4_rec_len_from_disk(de->rec_len, blocksize);
373         if (de->inode) {
374                 struct ext4_dir_entry_2 *de1 = (struct ext4_dir_entry_2 *)((char *)de + nlen);
375 @@ -1399,6 +1415,12 @@ static int add_dirent_to_buf(handle_t *h
376                 de->inode = 0;
377         de->name_len = namelen;
378         memcpy(de->name, name, namelen);
379 +       if (data) {
380 +               de->name[namelen] = 0;
381 +               memcpy(&de->name[namelen + 1], data, *(char *) data);
382 +               de->file_type |= EXT4_DIRENT_LUFID;
383 +       }
384 +
385         /*
386          * XXX shouldn't update any times until successful
387          * completion of syscall, but too many callers depend
388 @@ -1488,7 +1510,8 @@ static int make_indexed_dir(handle_t *ha
389  
390         dx_set_block(entries, 1);
391         dx_set_count(entries, 1);
392 -       dx_set_limit(entries, dx_root_limit(dir, sizeof(*dx_info)));
393 +       dx_set_limit(entries, dx_root_limit(dir->i_sb->s_blocksize,
394 +                                        dot_de, sizeof(*dx_info)));
395  
396         /* Initialize as for dx_probe */
397         hinfo.hash_version = dx_info->hash_version;
398 @@ -1516,6 +1539,8 @@ static int ext4_update_dotdot(handle_t *
399         struct buffer_head * dir_block;
400         struct ext4_dir_entry_2 * de;
401         int len, journal = 0, err = 0;
402 +       int dlen = 0;
403 +       char *data;
404  
405         if (IS_ERR(handle))
406                 return PTR_ERR(handle);
407 @@ -1531,19 +1556,24 @@ static int ext4_update_dotdot(handle_t *
408         /* the first item must be "." */
409         assert(de->name_len == 1 && de->name[0] == '.');
410         len = le16_to_cpu(de->rec_len);
411 -       assert(len >= EXT4_DIR_REC_LEN(1));
412 -       if (len > EXT4_DIR_REC_LEN(1)) {
413 +       assert(len >= __EXT4_DIR_REC_LEN(1));
414 +       if (len > __EXT4_DIR_REC_LEN(1)) {
415                 BUFFER_TRACE(dir_block, "get_write_access");
416                 err = ext4_journal_get_write_access(handle, dir_block);
417                 if (err)
418                         goto out_journal;
419  
420                 journal = 1;
421 -               de->rec_len = cpu_to_le16(EXT4_DIR_REC_LEN(1));
422 +               de->rec_len = cpu_to_le16(EXT4_DIR_REC_LEN(de));
423         }
424  
425 -       len -= EXT4_DIR_REC_LEN(1);
426 -       assert(len == 0 || len >= EXT4_DIR_REC_LEN(2));
427 +       len -= EXT4_DIR_REC_LEN(de);
428 +       data = ext4_dentry_get_data(dir->i_sb,
429 +                       (struct ext4_dentry_param *) dentry->d_fsdata);
430 +       if (data)
431 +               dlen = *data + 1;
432 +       assert(len == 0 || len >= __EXT4_DIR_REC_LEN(2 + dlen));
433 +
434         de = (struct ext4_dir_entry_2 *)
435                         ((char *) de + le16_to_cpu(de->rec_len));
436         if (!journal) {
437 @@ -1557,10 +1587,15 @@ static int ext4_update_dotdot(handle_t *
438         if (len > 0)
439                 de->rec_len = cpu_to_le16(len);
440         else
441 -               assert(le16_to_cpu(de->rec_len) >= EXT4_DIR_REC_LEN(2));
442 +               assert(le16_to_cpu(de->rec_len) >= __EXT4_DIR_REC_LEN(2));
443         de->name_len = 2;
444         strcpy (de->name, "..");
445         ext4_set_de_type(dir->i_sb, de, S_IFDIR);
446 +       if (data) {
447 +               de->name[2] = 0;
448 +               memcpy(&de->name[2 + 1], data, dlen);
449 +               de->file_type |= EXT4_DIRENT_LUFID;
450 +       }
451  
452  out_journal:
453         if (journal) {
454 @@ -1972,12 +2007,13 @@ retry:
455  /* Initialize @inode as a subdirectory of @dir, and add the
456   * "." and ".." entries into the first directory block. */
457  int ext4_add_dot_dotdot(handle_t *handle, struct inode * dir,
458 -                       struct inode *inode)
459 +                        struct inode *inode,
460 +                        const void *data1, const void *data2)
461  {
462         unsigned int blocksize = dir->i_sb->s_blocksize;
463         struct buffer_head * dir_block;
464         struct ext4_dir_entry_2 * de;
465 -       int err = 0;
466 +       int err = 0, dot_reclen;
467  
468         if (IS_ERR(handle))
469                 return PTR_ERR(handle);
470 @@ -1993,17 +2029,34 @@ int ext4_add_dot_dotdot(handle_t *handle
471         de = (struct ext4_dir_entry_2 *) dir_block->b_data;
472         de->inode = cpu_to_le32(inode->i_ino);
473         de->name_len = 1;
474 -       de->rec_len = ext4_rec_len_to_disk(EXT4_DIR_REC_LEN(de->name_len),
475 -                                          blocksize);
476         strcpy(de->name, ".");
477         ext4_set_de_type(dir->i_sb, de, S_IFDIR);
478 +       /* get packed fid data*/
479 +       data1 = ext4_dentry_get_data(dir->i_sb,
480 +                               (struct ext4_dentry_param *) data1);
481 +       if (data1) {
482 +               de->name[1] = 0;
483 +               memcpy(&de->name[2], data1, *(char *) data1);
484 +               de->file_type |= EXT4_DIRENT_LUFID;
485 +       }
486 +       de->rec_len = cpu_to_le16(EXT4_DIR_REC_LEN(de));
487 +       dot_reclen = cpu_to_le16(de->rec_len);
488 +
489         de = ext4_next_entry(de, blocksize);
490         de->inode = cpu_to_le32(dir->i_ino);
491 -       de->rec_len = ext4_rec_len_to_disk(blocksize - EXT4_DIR_REC_LEN(1),
492 +       de->rec_len = ext4_rec_len_to_disk(blocksize - dot_reclen,
493                                            blocksize);
494         de->name_len = 2;
495         strcpy(de->name, "..");
496         ext4_set_de_type(dir->i_sb, de, S_IFDIR);
497 +       data2 = ext4_dentry_get_data(dir->i_sb,
498 +                       (struct ext4_dentry_param *) data2);
499 +       if (data2) {
500 +               de->name[2] = 0;
501 +               memcpy(&de->name[3], data2, *(char *) data2);
502 +               de->file_type |= EXT4_DIRENT_LUFID;
503 +       }
504 +
505         inode->i_nlink = 2;
506         BUFFER_TRACE(dir_block, "call ext4_journal_dirty_metadata");
507         ext4_journal_dirty_metadata(handle, dir_block);
508 @@ -2037,7 +2091,7 @@ retry:
509         if (IS_ERR(inode))
510                 goto out_stop;
511  
512 -       err = ext4_add_dot_dotdot(handle, dir, inode);
513 +       err = ext4_add_dot_dotdot(handle, dir, inode, NULL, NULL);
514         if (err)
515                 goto out_stop;
516  
517 @@ -2071,7 +2125,7 @@ static int empty_dir (struct inode * ino
518         int err = 0;
519  
520         sb = inode->i_sb;
521 -       if (inode->i_size < EXT4_DIR_REC_LEN(1) + EXT4_DIR_REC_LEN(2) ||
522 +       if (inode->i_size < __EXT4_DIR_REC_LEN(1) + __EXT4_DIR_REC_LEN(2) ||
523             !(bh = ext4_bread(NULL, inode, 0, 0, &err))) {
524                 if (err)
525                         ext4_error(inode->i_sb, __func__,