1 From: Felix Fietkau <nbd@nbd.name>
2 Subject: jffs2: use .rename2 and add RENAME_WHITEOUT support
4 It is required for renames on overlayfs
6 Signed-off-by: Felix Fietkau <nbd@nbd.name>
11 @@ -617,8 +617,8 @@ static int jffs2_rmdir (struct inode *di
15 -static int jffs2_mknod (struct mnt_idmap *idmap, struct inode *dir_i,
16 - struct dentry *dentry, umode_t mode, dev_t rdev)
17 +static int __jffs2_mknod (struct mnt_idmap *idmap, struct inode *dir_i,
18 + struct dentry *dentry, umode_t mode, dev_t rdev, bool whiteout)
20 struct jffs2_inode_info *f, *dir_f;
21 struct jffs2_sb_info *c;
22 @@ -758,7 +758,11 @@ static int jffs2_mknod (struct mnt_idmap
23 mutex_unlock(&dir_f->sem);
24 jffs2_complete_reservation(c);
26 - d_instantiate_new(dentry, inode);
28 + d_instantiate_new(dentry, inode);
30 + unlock_new_inode(inode);
35 @@ -766,6 +770,19 @@ static int jffs2_mknod (struct mnt_idmap
39 +static int jffs2_mknod (struct mnt_idmap *idmap, struct inode *dir_i,
40 + struct dentry *dentry, umode_t mode, dev_t rdev)
42 + return __jffs2_mknod(idmap, dir_i, dentry, mode, rdev, false);
45 +static int jffs2_whiteout (struct mnt_idmap *idmap, struct inode *old_dir,
46 + struct dentry *old_dentry)
48 + return __jffs2_mknod(idmap, old_dir, old_dentry, S_IFCHR | WHITEOUT_MODE,
49 + WHITEOUT_DEV, true);
52 static int jffs2_rename (struct mnt_idmap *idmap,
53 struct inode *old_dir_i, struct dentry *old_dentry,
54 struct inode *new_dir_i, struct dentry *new_dentry,
55 @@ -777,7 +794,7 @@ static int jffs2_rename (struct mnt_idma
59 - if (flags & ~RENAME_NOREPLACE)
60 + if (flags & ~(RENAME_NOREPLACE|RENAME_WHITEOUT))
63 /* The VFS will check for us and prevent trying to rename a
64 @@ -843,9 +860,14 @@ static int jffs2_rename (struct mnt_idma
65 if (d_is_dir(old_dentry) && !victim_f)
68 - /* Unlink the original */
69 - ret = jffs2_do_unlink(c, JFFS2_INODE_INFO(old_dir_i),
70 - old_dentry->d_name.name, old_dentry->d_name.len, NULL, now);
71 + if (flags & RENAME_WHITEOUT)
72 + /* Replace with whiteout */
73 + ret = jffs2_whiteout(idmap, old_dir_i, old_dentry);
75 + /* Unlink the original */
76 + ret = jffs2_do_unlink(c, JFFS2_INODE_INFO(old_dir_i),
77 + old_dentry->d_name.name,
78 + old_dentry->d_name.len, NULL, now);
80 /* We don't touch inode->i_nlink */