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 @@ -609,7 +609,8 @@ static int jffs2_rmdir (struct inode *di
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)
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);
25 - d_instantiate_new(dentry, inode);
27 + d_instantiate_new(dentry, inode);
29 + unlock_new_inode(inode);
34 @@ -756,6 +761,17 @@ static int jffs2_mknod (struct inode *di
38 +static int jffs2_mknod (struct inode *dir_i, struct dentry *dentry, umode_t mode, dev_t rdev)
40 + return __jffs2_mknod(dir_i, dentry, mode, rdev, false);
43 +static int jffs2_whiteout (struct inode *old_dir, struct dentry *old_dentry)
45 + return __jffs2_mknod(old_dir, old_dentry, S_IFCHR | WHITEOUT_MODE,
46 + WHITEOUT_DEV, true);
49 static int jffs2_rename (struct inode *old_dir_i, struct dentry *old_dentry,
50 struct inode *new_dir_i, struct dentry *new_dentry,
52 @@ -766,7 +782,7 @@ static int jffs2_rename (struct inode *o
56 - if (flags & ~RENAME_NOREPLACE)
57 + if (flags & ~(RENAME_NOREPLACE|RENAME_WHITEOUT))
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)
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);
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);
77 /* We don't touch inode->i_nlink */