kernel: update 4.4 to 4.4.83
[oweals/openwrt.git] / target / linux / generic / pending-4.4 / 052-01-ubifs-Implement-O_TMPFILE.patch
1 From: Richard Weinberger <richard@nod.at>
2 Date: Tue, 13 Sep 2016 16:18:55 +0200
3 Subject: [PATCH] ubifs: Implement O_TMPFILE
4
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
8 all data vanishes.
9
10 Signed-off-by: Richard Weinberger <richard@nod.at>
11 ---
12
13 --- a/fs/ubifs/dir.c
14 +++ b/fs/ubifs/dir.c
15 @@ -301,6 +301,76 @@ out_budg:
16         return err;
17  }
18  
19 +static int ubifs_tmpfile(struct inode *dir, struct dentry *dentry,
20 +                        umode_t mode)
21 +{
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;
28 +
29 +       /*
30 +        * Budget request settings: new dirty inode, new direntry,
31 +        * budget for dirtied inode will be released via writeback.
32 +        */
33 +
34 +       dbg_gen("dent '%pd', mode %#hx in dir ino %lu",
35 +               dentry, mode, dir->i_ino);
36 +
37 +       err = ubifs_budget_space(c, &req);
38 +       if (err)
39 +               return err;
40 +
41 +       err = ubifs_budget_space(c, &ino_req);
42 +       if (err) {
43 +               ubifs_release_budget(c, &req);
44 +               return err;
45 +       }
46 +
47 +       inode = ubifs_new_inode(c, dir, mode);
48 +       if (IS_ERR(inode)) {
49 +               err = PTR_ERR(inode);
50 +               goto out_budg;
51 +       }
52 +       ui = ubifs_inode(inode);
53 +
54 +       err = ubifs_init_security(dir, inode, &dentry->d_name);
55 +       if (err)
56 +               goto out_inode;
57 +
58 +       mutex_lock(&ui->ui_mutex);
59 +       insert_inode_hash(inode);
60 +       d_tmpfile(dentry, inode);
61 +       ubifs_assert(ui->dirty);
62 +       instantiated = 1;
63 +       mutex_unlock(&ui->ui_mutex);
64 +
65 +       mutex_lock(&dir_ui->ui_mutex);
66 +       err = ubifs_jnl_update(c, dir, &dentry->d_name, inode, 1, 0);
67 +       if (err)
68 +               goto out_cancel;
69 +       mutex_unlock(&dir_ui->ui_mutex);
70 +
71 +       ubifs_release_budget(c, &req);
72 +
73 +       return 0;
74 +
75 +out_cancel:
76 +       mutex_unlock(&dir_ui->ui_mutex);
77 +out_inode:
78 +       make_bad_inode(inode);
79 +       if (!instantiated)
80 +               iput(inode);
81 +out_budg:
82 +       ubifs_release_budget(c, &req);
83 +       if (!instantiated)
84 +               ubifs_release_budget(c, &ino_req);
85 +       ubifs_err(c, "cannot create temporary file, error %d", err);
86 +       return err;
87 +}
88 +
89  /**
90   * vfs_dent_type - get VFS directory entry type.
91   * @type: UBIFS directory entry type
92 @@ -1195,6 +1265,7 @@ const struct inode_operations ubifs_dir_
93  #ifdef CONFIG_UBIFS_ATIME_SUPPORT
94         .update_time = ubifs_update_time,
95  #endif
96 +       .tmpfile     = ubifs_tmpfile,
97  };
98  
99  const struct file_operations ubifs_dir_operations = {