1 From: Richard Weinberger <richard@nod.at>
2 Date: Tue, 13 Sep 2016 16:18:55 +0200
3 Subject: [PATCH] ubifs: Implement O_TMPFILE
5 This patchs adds O_TMPFILE support to UBIFS.
6 A temp file is a reference to an unlinked inode, a user
7 holding the reference can use it. As soon it is being closed
10 Signed-off-by: Richard Weinberger <richard@nod.at>
15 @@ -301,6 +301,76 @@ out_budg:
19 +static int ubifs_tmpfile(struct inode *dir, struct dentry *dentry,
22 + struct inode *inode;
23 + struct ubifs_info *c = dir->i_sb->s_fs_info;
24 + struct ubifs_budget_req req = { .new_ino = 1, .new_dent = 1};
25 + struct ubifs_budget_req ino_req = { .dirtied_ino = 1 };
26 + struct ubifs_inode *ui, *dir_ui = ubifs_inode(dir);
27 + int err, instantiated = 0;
30 + * Budget request settings: new dirty inode, new direntry,
31 + * budget for dirtied inode will be released via writeback.
34 + dbg_gen("dent '%pd', mode %#hx in dir ino %lu",
35 + dentry, mode, dir->i_ino);
37 + err = ubifs_budget_space(c, &req);
41 + err = ubifs_budget_space(c, &ino_req);
43 + ubifs_release_budget(c, &req);
47 + inode = ubifs_new_inode(c, dir, mode);
48 + if (IS_ERR(inode)) {
49 + err = PTR_ERR(inode);
52 + ui = ubifs_inode(inode);
54 + err = ubifs_init_security(dir, inode, &dentry->d_name);
58 + mutex_lock(&ui->ui_mutex);
59 + insert_inode_hash(inode);
60 + d_tmpfile(dentry, inode);
61 + ubifs_assert(ui->dirty);
63 + mutex_unlock(&ui->ui_mutex);
65 + mutex_lock(&dir_ui->ui_mutex);
66 + err = ubifs_jnl_update(c, dir, &dentry->d_name, inode, 1, 0);
69 + mutex_unlock(&dir_ui->ui_mutex);
71 + ubifs_release_budget(c, &req);
76 + mutex_unlock(&dir_ui->ui_mutex);
78 + make_bad_inode(inode);
82 + ubifs_release_budget(c, &req);
84 + ubifs_release_budget(c, &ino_req);
85 + ubifs_err(c, "cannot create temporary file, error %d", err);
90 * vfs_dent_type - get VFS directory entry type.
91 * @type: UBIFS directory entry type
92 @@ -1189,6 +1259,7 @@ const struct inode_operations ubifs_dir_
93 #ifdef CONFIG_UBIFS_ATIME_SUPPORT
94 .update_time = ubifs_update_time,
96 + .tmpfile = ubifs_tmpfile,
99 const struct file_operations ubifs_dir_operations = {