Whamcloud - gitweb
LU-2638 ldiskfs: update dotdot entry for rename
[fs/lustre-release.git] / ldiskfs / kernel_patches / patches / ext4_data_in_dirent-rhel6.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: linux-stage/fs/ext4/dir.c
11 ===================================================================
12 --- linux-stage.orig/fs/ext4/dir.c
13 +++ linux-stage/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 @@ -70,11 +77,11 @@ int ext4_check_dir_entry(const char *fun
36         const int rlen = ext4_rec_len_from_disk(de->rec_len,
37                                                 dir->i_sb->s_blocksize);
38  
39 -       if (unlikely(rlen < EXT4_DIR_REC_LEN(1)))
40 +       if (unlikely(rlen < __EXT4_DIR_REC_LEN(1)))
41                 error_msg = "rec_len is smaller than minimal";
42         else if (unlikely(rlen % 4 != 0))
43                 error_msg = "rec_len % 4 != 0";
44 -       else if (unlikely(rlen < EXT4_DIR_REC_LEN(de->name_len)))
45 +       else if (unlikely(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 @@ -182,7 +189,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                                                             sb->s_blocksize);
58 @@ -345,12 +352,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 @@ -359,7 +371,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: linux-stage/fs/ext4/ext4.h
87 ===================================================================
88 --- linux-stage.orig/fs/ext4/ext4.h
89 +++ linux-stage/fs/ext4/ext4.h
90 @@ -1267,6 +1267,7 @@ EXT4_INODE_BIT_FNS(state, state_flags)
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 @@ -1275,7 +1276,9 @@ EXT4_INODE_BIT_FNS(state, state_flags)
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 @@ -1357,6 +1360,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 @@ -1365,8 +1405,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 int
166 @@ -1726,7 +1769,7 @@ extern struct buffer_head * ext4_find_en
167                                             struct ext4_dir_entry_2 ** res_dir);
168  #define ll_ext4_find_entry(inode, dentry, res_dir) ext4_find_entry(inode, &(dentry)->d_name, 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 struct buffer_head *ext4_append(handle_t *handle,
173                                        struct inode *inode,
174                                        ext4_lblk_t *block, int *err);
175 @@ -2069,6 +2112,28 @@ extern wait_queue_head_t aio_wq[];
176  #define to_aio_wq(v) (&aio_wq[((unsigned long)v) % WQ_HASH_SZ])
177  extern void ext4_aio_wait(struct inode *inode);
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 +static inline int ext4_get_dirent_data_len(struct ext4_dir_entry_2 *de)
186 +{
187 +       char *len = de->name + de->name_len + 1 /* NUL terminator */;
188 +       int dlen = 0;
189 +       __u8 extra_data_flags = (de->file_type & ~EXT4_FT_MASK) >> 4;
190 +
191 +       while (extra_data_flags) {
192 +               if (extra_data_flags & 1) {
193 +                       dlen += *len + (dlen == 0);
194 +                       len += *len;
195 +               }
196 +               extra_data_flags >>= 1;
197 +       }
198 +       return dlen;
199 +}
200 +
201  #endif /* __KERNEL__ */
202  
203  #endif /* _EXT4_H */
204 Index: linux-stage/fs/ext4/namei.c
205 ===================================================================
206 --- linux-stage.orig/fs/ext4/namei.c
207 +++ linux-stage/fs/ext4/namei.c
208 @@ -169,7 +169,8 @@ static unsigned dx_get_count(struct dx_e
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(const struct qstr *d_name,
217                                  struct inode *dir,
218 @@ -212,11 +213,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 @@ -261,16 +263,23 @@ static inline void dx_set_limit(struct d
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 @@ -317,7 +326,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, size);
272 @@ -419,7 +428,8 @@ dx_probe(const struct qstr *d_name, stru
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, "dx entry: limit != root limit");
281                 brelse(bh);
282 @@ -608,7 +618,7 @@ static int htree_dirblock_to_tree(struct
283         de = (struct ext4_dir_entry_2 *) bh->b_data;
284         top = (struct ext4_dir_entry_2 *) ((char *) de +
285                                            dir->i_sb->s_blocksize -
286 -                                          EXT4_DIR_REC_LEN(0));
287 +                                          __EXT4_DIR_REC_LEN(0));
288         for (; de < top; de = ext4_next_entry(de, dir->i_sb->s_blocksize)) {
289                 if (!ext4_check_dir_entry("htree_dirblock_to_tree", dir, de, bh,
290                                         (block<<EXT4_BLOCK_SIZE_BITS(dir->i_sb))
291 @@ -1020,7 +1030,7 @@ static struct buffer_head * ext4_dx_find
292                         goto errout;
293                 de = (struct ext4_dir_entry_2 *) bh->b_data;
294                 top = (struct ext4_dir_entry_2 *) ((char *) de + sb->s_blocksize -
295 -                                      EXT4_DIR_REC_LEN(0));
296 +                                      __EXT4_DIR_REC_LEN(0));
297                 for (; de < top; de = ext4_next_entry(de, sb->s_blocksize)) {
298                         int off = (block << EXT4_BLOCK_SIZE_BITS(sb))
299                                   + ((char *) de - bh->b_data);
300 @@ -1181,7 +1191,7 @@ dx_move_dirents(char *from, char *to, st
301         while (count--) {
302                 struct ext4_dir_entry_2 *de = (struct ext4_dir_entry_2 *) 
303                                                 (from + (map->offs<<2));
304 -               rec_len = EXT4_DIR_REC_LEN(de->name_len);
305 +               rec_len = EXT4_DIR_REC_LEN(de);
306                 memcpy (to, de, rec_len);
307                 ((struct ext4_dir_entry_2 *) to)->rec_len =
308                                 ext4_rec_len_to_disk(rec_len, blocksize);
309 @@ -1205,7 +1215,7 @@ static struct ext4_dir_entry_2* dx_pack_
310         while ((char*)de < base + blocksize) {
311                 next = ext4_next_entry(de, blocksize);
312                 if (de->inode && de->name_len) {
313 -                       rec_len = EXT4_DIR_REC_LEN(de->name_len);
314 +                       rec_len = EXT4_DIR_REC_LEN(de);
315                         if (de > to)
316                                 memmove(to, de, rec_len);
317                         to->rec_len = ext4_rec_len_to_disk(rec_len, blocksize);
318 @@ -1335,10 +1345,16 @@ static int add_dirent_to_buf(handle_t *h
319         unsigned int    offset = 0;
320         unsigned int    blocksize = dir->i_sb->s_blocksize;
321         unsigned short  reclen;
322 -       int             nlen, rlen, err;
323 +       int             nlen, rlen, err, dlen = 0;
324 +       unsigned char   *data;
325         char            *top;
326  
327 -       reclen = EXT4_DIR_REC_LEN(namelen);
328 +       data = ext4_dentry_get_data(inode->i_sb, (struct ext4_dentry_param *)
329 +                                               dentry->d_fsdata);
330 +       if (data)
331 +               dlen = (*data) + 1;
332 +
333 +       reclen = __EXT4_DIR_REC_LEN(namelen + dlen);
334         if (!de) {
335                 de = (struct ext4_dir_entry_2 *)bh->b_data;
336                 top = bh->b_data + blocksize - reclen;
337 @@ -1348,7 +1364,7 @@ static int add_dirent_to_buf(handle_t *h
338                                 return -EIO;
339                         if (ext4_match(namelen, name, de))
340                                 return -EEXIST;
341 -                       nlen = EXT4_DIR_REC_LEN(de->name_len);
342 +                       nlen = EXT4_DIR_REC_LEN(de);
343                         rlen = ext4_rec_len_from_disk(de->rec_len, blocksize);
344                         if ((de->inode? rlen - nlen: rlen) >= reclen)
345                                 break;
346 @@ -1366,7 +1382,7 @@ static int add_dirent_to_buf(handle_t *h
347         }
348  
349         /* By now the buffer is marked for journaling */
350 -       nlen = EXT4_DIR_REC_LEN(de->name_len);
351 +       nlen = EXT4_DIR_REC_LEN(de);
352         rlen = ext4_rec_len_from_disk(de->rec_len, blocksize);
353         if (de->inode) {
354                 struct ext4_dir_entry_2 *de1 = (struct ext4_dir_entry_2 *)((char *)de + nlen);
355 @@ -1382,6 +1398,12 @@ static int add_dirent_to_buf(handle_t *h
356                 de->inode = 0;
357         de->name_len = namelen;
358         memcpy(de->name, name, namelen);
359 +       if (data) {
360 +               de->name[namelen] = 0;
361 +               memcpy(&de->name[namelen + 1], data, *(char *) data);
362 +               de->file_type |= EXT4_DIRENT_LUFID;
363 +       }
364 +
365         /*
366          * XXX shouldn't update any times until successful
367          * completion of syscall, but too many callers depend
368 @@ -1480,7 +1502,8 @@ static int make_indexed_dir(handle_t *ha
369  
370         dx_set_block(entries, 1);
371         dx_set_count(entries, 1);
372 -       dx_set_limit(entries, dx_root_limit(dir, sizeof(*dx_info)));
373 +       dx_set_limit(entries, dx_root_limit(dir->i_sb->s_blocksize,
374 +                                        dot_de, sizeof(*dx_info)));
375  
376         /* Initialize as for dx_probe */
377         hinfo.hash_version = dx_info->hash_version;
378 @@ -1511,6 +1534,8 @@ static int ext4_update_dotdot(handle_t *
379         struct buffer_head * dir_block;
380         struct ext4_dir_entry_2 * de;
381         int len, journal = 0, err = 0;
382 +       int dlen = 0;
383 +       char *data;
384  
385         if (IS_ERR(handle))
386                 return PTR_ERR(handle);
387 @@ -1526,19 +1551,24 @@ static int ext4_update_dotdot(handle_t *
388         /* the first item must be "." */
389         assert(de->name_len == 1 && de->name[0] == '.');
390         len = le16_to_cpu(de->rec_len);
391 -       assert(len >= EXT4_DIR_REC_LEN(1));
392 -       if (len > EXT4_DIR_REC_LEN(1)) {
393 +       assert(len >= __EXT4_DIR_REC_LEN(1));
394 +       if (len > __EXT4_DIR_REC_LEN(1)) {
395                 BUFFER_TRACE(dir_block, "get_write_access");
396                 err = ext4_journal_get_write_access(handle, dir_block);
397                 if (err)
398                         goto out_journal;
399  
400                 journal = 1;
401 -               de->rec_len = cpu_to_le16(EXT4_DIR_REC_LEN(1));
402 +               de->rec_len = cpu_to_le16(EXT4_DIR_REC_LEN(de));
403         }
404  
405 -       len -= EXT4_DIR_REC_LEN(1);
406 -       assert(len == 0 || len >= EXT4_DIR_REC_LEN(2));
407 +       len -= EXT4_DIR_REC_LEN(de);
408 +       data = ext4_dentry_get_data(dir->i_sb,
409 +                       (struct ext4_dentry_param *) dentry->d_fsdata);
410 +       if (data)
411 +               dlen = *data + 1;
412 +       assert(len == 0 || len >= __EXT4_DIR_REC_LEN(2 + dlen));
413 +
414         de = (struct ext4_dir_entry_2 *)
415                         ((char *) de + le16_to_cpu(de->rec_len));
416         if (!journal) {
417 @@ -1552,10 +1582,15 @@ static int ext4_update_dotdot(handle_t *
418         if (len > 0)
419                 de->rec_len = cpu_to_le16(len);
420         else
421 -               assert(le16_to_cpu(de->rec_len) >= EXT4_DIR_REC_LEN(2));
422 +               assert(le16_to_cpu(de->rec_len) >= __EXT4_DIR_REC_LEN(2));
423         de->name_len = 2;
424         strcpy (de->name, "..");
425 -       ext4_set_de_type(dir->i_sb, de, S_IFDIR);
426 +       if (data != NULL && ext4_get_dirent_data_len(de) >= dlen) {
427 +               de->name[2] = 0;
428 +               memcpy(&de->name[2 + 1], data, *data);
429 +               ext4_set_de_type(dir->i_sb, de, S_IFDIR);
430 +               de->file_type |= EXT4_DIRENT_LUFID;
431 +       }
432  
433  out_journal:
434         if (journal) {
435 @@ -1978,12 +2013,13 @@ retry:
436  /* Initialize @inode as a subdirectory of @dir, and add the
437   * "." and ".." entries into the first directory block. */
438  int ext4_add_dot_dotdot(handle_t *handle, struct inode * dir,
439 -                       struct inode *inode)
440 +                       struct inode *inode,
441 +                        const void *data1, const void *data2)
442  {
443         struct buffer_head * dir_block;
444         struct ext4_dir_entry_2 * de;
445         unsigned int blocksize = dir->i_sb->s_blocksize;
446 -       int err = 0;
447 +       int err = 0, dot_reclen;
448  
449         if (IS_ERR(handle))
450                 return PTR_ERR(handle);
451 @@ -1996,28 +2032,40 @@ int ext4_add_dot_dotdot(handle_t *handle
452         inode->i_fop = &ext4_dir_operations;
453         inode->i_size = EXT4_I(inode)->i_disksize = inode->i_sb->s_blocksize;
454         dir_block = ext4_bread(handle, inode, 0, 1, &err);
455 -       if (!dir_block) {
456 -               clear_nlink(inode);
457 -               ext4_mark_inode_dirty(handle, inode);
458 -               iput (inode);
459 +       if (!dir_block)
460                 goto get_out;
461 -       }
462 +
463         BUFFER_TRACE(dir_block, "get_write_access");
464         ext4_journal_get_write_access(handle, dir_block);
465         de = (struct ext4_dir_entry_2 *) dir_block->b_data;
466         de->inode = cpu_to_le32(inode->i_ino);
467         de->name_len = 1;
468 -       de->rec_len = ext4_rec_len_to_disk(EXT4_DIR_REC_LEN(de->name_len),
469 -                                          blocksize);
470         strcpy(de->name, ".");
471         ext4_set_de_type(dir->i_sb, de, S_IFDIR);
472 +       /* get packed fid data*/
473 +       data1 = ext4_dentry_get_data(dir->i_sb,
474 +                               (struct ext4_dentry_param *) data1);
475 +       if (data1) {
476 +               de->name[1] = 0;
477 +               memcpy(&de->name[2], data1, *(char *) data1);
478 +               de->file_type |= EXT4_DIRENT_LUFID;
479 +       }
480 +       de->rec_len = cpu_to_le16(EXT4_DIR_REC_LEN(de));
481 +       dot_reclen = cpu_to_le16(de->rec_len);
482         de = ext4_next_entry(de, blocksize);
483         de->inode = cpu_to_le32(dir->i_ino);
484 -       de->rec_len = ext4_rec_len_to_disk(blocksize - EXT4_DIR_REC_LEN(1),
485 +       de->rec_len = ext4_rec_len_to_disk(blocksize - dot_reclen,
486                                            blocksize);
487         de->name_len = 2;
488         strcpy(de->name, "..");
489         ext4_set_de_type(dir->i_sb, de, S_IFDIR);
490 +       data2 = ext4_dentry_get_data(dir->i_sb,
491 +                       (struct ext4_dentry_param *) data2);
492 +       if (data2) {
493 +               de->name[2] = 0;
494 +               memcpy(&de->name[3], data2, *(char *) data2);
495 +               de->file_type |= EXT4_DIRENT_LUFID;
496 +       }
497         inode->i_nlink = 2;
498         BUFFER_TRACE(dir_block, "call ext4_handle_dirty_metadata");
499         ext4_handle_dirty_metadata(handle, dir, dir_block);
500 @@ -2054,9 +2102,12 @@ retry:
501         if (IS_ERR(inode))
502                 goto out_stop;
503  
504 -       err = ext4_add_dot_dotdot(handle, dir, inode);
505 +       err = ext4_add_dot_dotdot(handle, dir, inode, NULL, NULL);
506         if (err) {
507 +               clear_nlink(inode);
508                 unlock_new_inode(inode);
509 +               ext4_mark_inode_dirty(handle, inode);
510 +               iput (inode);
511                 goto out_stop;
512         }
513  
514 @@ -2092,7 +2143,7 @@ static int empty_dir(struct inode *inode
515         int err = 0;
516  
517         sb = inode->i_sb;
518 -       if (inode->i_size < EXT4_DIR_REC_LEN(1) + EXT4_DIR_REC_LEN(2) ||
519 +       if (inode->i_size < __EXT4_DIR_REC_LEN(1) + __EXT4_DIR_REC_LEN(2) ||
520             !(bh = ext4_bread(NULL, inode, 0, 0, &err))) {
521                 if (err)
522                         ext4_error(inode->i_sb,