generic: 5.15: copy config and patch from 5.10
[openwrt/staging/dedeckeh.git] / target / linux / generic / pending-5.15 / 140-jffs2-use-.rename2-and-add-RENAME_WHITEOUT-support.patch
1 From: Felix Fietkau <nbd@nbd.name>
2 Subject: jffs2: use .rename2 and add RENAME_WHITEOUT support
3
4 It is required for renames on overlayfs
5
6 Signed-off-by: Felix Fietkau <nbd@nbd.name>
7 ---
8
9 --- a/fs/jffs2/dir.c
10 +++ b/fs/jffs2/dir.c
11 @@ -609,7 +609,8 @@ static int jffs2_rmdir (struct inode *di
12 return ret;
13 }
14
15 -static int jffs2_mknod (struct inode *dir_i, struct dentry *dentry, umode_t mode, dev_t rdev)
16 +static int __jffs2_mknod (struct inode *dir_i, struct dentry *dentry,
17 + umode_t mode, dev_t rdev, bool whiteout)
18 {
19 struct jffs2_inode_info *f, *dir_f;
20 struct jffs2_sb_info *c;
21 @@ -748,7 +749,11 @@ static int jffs2_mknod (struct inode *di
22 mutex_unlock(&dir_f->sem);
23 jffs2_complete_reservation(c);
24
25 - d_instantiate_new(dentry, inode);
26 + if (!whiteout)
27 + d_instantiate_new(dentry, inode);
28 + else
29 + unlock_new_inode(inode);
30 +
31 return 0;
32
33 fail:
34 @@ -756,6 +761,17 @@ static int jffs2_mknod (struct inode *di
35 return ret;
36 }
37
38 +static int jffs2_mknod (struct inode *dir_i, struct dentry *dentry, umode_t mode, dev_t rdev)
39 +{
40 + return __jffs2_mknod(dir_i, dentry, mode, rdev, false);
41 +}
42 +
43 +static int jffs2_whiteout (struct inode *old_dir, struct dentry *old_dentry)
44 +{
45 + return __jffs2_mknod(old_dir, old_dentry, S_IFCHR | WHITEOUT_MODE,
46 + WHITEOUT_DEV, true);
47 +}
48 +
49 static int jffs2_rename (struct inode *old_dir_i, struct dentry *old_dentry,
50 struct inode *new_dir_i, struct dentry *new_dentry,
51 unsigned int flags)
52 @@ -766,7 +782,7 @@ static int jffs2_rename (struct inode *o
53 uint8_t type;
54 uint32_t now;
55
56 - if (flags & ~RENAME_NOREPLACE)
57 + if (flags & ~(RENAME_NOREPLACE|RENAME_WHITEOUT))
58 return -EINVAL;
59
60 /* The VFS will check for us and prevent trying to rename a
61 @@ -832,9 +848,14 @@ static int jffs2_rename (struct inode *o
62 if (d_is_dir(old_dentry) && !victim_f)
63 inc_nlink(new_dir_i);
64
65 - /* Unlink the original */
66 - ret = jffs2_do_unlink(c, JFFS2_INODE_INFO(old_dir_i),
67 - old_dentry->d_name.name, old_dentry->d_name.len, NULL, now);
68 + if (flags & RENAME_WHITEOUT)
69 + /* Replace with whiteout */
70 + ret = jffs2_whiteout(old_dir_i, old_dentry);
71 + else
72 + /* Unlink the original */
73 + ret = jffs2_do_unlink(c, JFFS2_INODE_INFO(old_dir_i),
74 + old_dentry->d_name.name,
75 + old_dentry->d_name.len, NULL, now);
76
77 /* We don't touch inode->i_nlink */
78