treewide: fix replace nbd@openwrt.org with nbd@nbd.name
[openwrt.git] / target / linux / generic / patches-4.4 / 110-jffs2-use-.rename2-and-add-RENAME_WHITEOUT-support.patch
1 From: Felix Fietkau <nbd@nbd.name>
2 Date: Fri, 10 Apr 2015 13:35:29 +0200
3 Subject: [PATCH] jffs2: use .rename2 and add RENAME_WHITEOUT support
4
5 It is required for renames on overlayfs
6
7 Signed-off-by: Felix Fietkau <nbd@nbd.name>
8 ---
9
10 --- a/fs/jffs2/dir.c
11 +++ b/fs/jffs2/dir.c
12 @@ -35,7 +35,7 @@ static int jffs2_mkdir (struct inode *,s
13  static int jffs2_rmdir (struct inode *,struct dentry *);
14  static int jffs2_mknod (struct inode *,struct dentry *,umode_t,dev_t);
15  static int jffs2_rename (struct inode *, struct dentry *,
16 -                        struct inode *, struct dentry *);
17 +                        struct inode *, struct dentry *, unsigned int);
18  
19  const struct file_operations jffs2_dir_operations =
20  {
21 @@ -57,7 +57,7 @@ const struct inode_operations jffs2_dir_
22         .mkdir =        jffs2_mkdir,
23         .rmdir =        jffs2_rmdir,
24         .mknod =        jffs2_mknod,
25 -       .rename =       jffs2_rename,
26 +       .rename2 =      jffs2_rename,
27         .get_acl =      jffs2_get_acl,
28         .set_acl =      jffs2_set_acl,
29         .setattr =      jffs2_setattr,
30 @@ -754,8 +754,27 @@ static int jffs2_mknod (struct inode *di
31         return ret;
32  }
33  
34 +static int jffs2_whiteout(struct inode *old_dir, struct dentry *old_dentry)
35 +{
36 +       struct dentry *wh;
37 +       int err;
38 +
39 +       wh = d_alloc(old_dentry->d_parent, &old_dentry->d_name);
40 +       if (!wh)
41 +               return -ENOMEM;
42 +
43 +       err = jffs2_mknod(old_dir, wh, S_IFCHR | WHITEOUT_MODE,
44 +                         WHITEOUT_DEV);
45 +       if (err)
46 +               return err;
47 +
48 +       d_rehash(wh);
49 +       return 0;
50 +}
51 +
52  static int jffs2_rename (struct inode *old_dir_i, struct dentry *old_dentry,
53 -                        struct inode *new_dir_i, struct dentry *new_dentry)
54 +                        struct inode *new_dir_i, struct dentry *new_dentry,
55 +                        unsigned int flags)
56  {
57         int ret;
58         struct jffs2_sb_info *c = JFFS2_SB_INFO(old_dir_i->i_sb);
59 @@ -763,6 +782,9 @@ static int jffs2_rename (struct inode *o
60         uint8_t type;
61         uint32_t now;
62  
63 +       if (flags & ~RENAME_WHITEOUT)
64 +               return -EINVAL;
65 +
66         /* The VFS will check for us and prevent trying to rename a
67          * file over a directory and vice versa, but if it's a directory,
68          * the VFS can't check whether the victim is empty. The filesystem
69 @@ -826,9 +848,14 @@ static int jffs2_rename (struct inode *o
70         if (d_is_dir(old_dentry) && !victim_f)
71                 inc_nlink(new_dir_i);
72  
73 -       /* Unlink the original */
74 -       ret = jffs2_do_unlink(c, JFFS2_INODE_INFO(old_dir_i),
75 -                             old_dentry->d_name.name, old_dentry->d_name.len, NULL, now);
76 +       if (flags & RENAME_WHITEOUT)
77 +               /* Replace with whiteout */
78 +               ret = jffs2_whiteout(old_dir_i, old_dentry);
79 +       else
80 +               /* Unlink the original */
81 +               ret = jffs2_do_unlink(c, JFFS2_INODE_INFO(old_dir_i),
82 +                                     old_dentry->d_name.name,
83 +                                     old_dentry->d_name.len, NULL, now);
84  
85         /* We don't touch inode->i_nlink */
86