* [PATCH] ubifs: Implement O_TMPFILE
@ 2016-02-21 9:46 Richard Weinberger
2016-02-23 20:45 ` Pavel Machek
0 siblings, 1 reply; 3+ messages in thread
From: Richard Weinberger @ 2016-02-21 9:46 UTC (permalink / raw)
To: linux-mtd; +Cc: dedekind1, adrian.hunter, linux-kernel, Richard Weinberger
This patchs adds O_TMPFILE support to UBIFS.
Signed-off-by: Richard Weinberger <richard@nod.at>
---
fs/ubifs/dir.c | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 71 insertions(+)
diff --git a/fs/ubifs/dir.c b/fs/ubifs/dir.c
index 795992a..660eefe 100644
--- a/fs/ubifs/dir.c
+++ b/fs/ubifs/dir.c
@@ -301,6 +301,76 @@ out_budg:
return err;
}
+static int ubifs_tmpfile(struct inode *dir, struct dentry *dentry,
+ umode_t mode)
+{
+ struct inode *inode;
+ struct ubifs_info *c = dir->i_sb->s_fs_info;
+ struct ubifs_budget_req req = { .new_ino = 1, .new_dent = 1};
+ struct ubifs_budget_req ino_req = { .dirtied_ino = 1 };
+ struct ubifs_inode *ui, *dir_ui = ubifs_inode(dir);
+ int err, instantiated = 0;
+
+ /*
+ * Budget request settings: new dirty inode, new direntry,
+ * budget for dirtied inode will be released via ubifs_evict_inode().
+ */
+
+ dbg_gen("dent '%pd', mode %#hx in dir ino %lu",
+ dentry, mode, dir->i_ino);
+
+ err = ubifs_budget_space(c, &req);
+ if (err)
+ return err;
+
+ err = ubifs_budget_space(c, &ino_req);
+ if (err) {
+ ubifs_release_budget(c, &req);
+ return err;
+ }
+
+ inode = ubifs_new_inode(c, dir, mode);
+ if (IS_ERR(inode)) {
+ err = PTR_ERR(inode);
+ goto out_budg;
+ }
+ ui = ubifs_inode(inode);
+
+ err = ubifs_init_security(dir, inode, &dentry->d_name);
+ if (err)
+ goto out_inode;
+
+ mutex_lock(&ui->ui_mutex);
+ insert_inode_hash(inode);
+ d_tmpfile(dentry, inode);
+ ubifs_assert(ui->dirty);
+ instantiated = 1;
+ mutex_unlock(&ui->ui_mutex);
+
+ mutex_lock(&dir_ui->ui_mutex);
+ err = ubifs_jnl_update(c, dir, &dentry->d_name, inode, 1, 0);
+ if (err)
+ goto out_cancel;
+ mutex_unlock(&dir_ui->ui_mutex);
+
+ ubifs_release_budget(c, &req);
+
+ return 0;
+
+out_cancel:
+ mutex_unlock(&dir_ui->ui_mutex);
+out_inode:
+ make_bad_inode(inode);
+ if (!instantiated)
+ iput(inode);
+out_budg:
+ ubifs_release_budget(c, &req);
+ if (!instantiated)
+ ubifs_release_budget(c, &ino_req);
+ ubifs_err(c, "cannot create temporary file, error %d", err);
+ return err;
+}
+
/**
* vfs_dent_type - get VFS directory entry type.
* @type: UBIFS directory entry type
@@ -1189,6 +1259,7 @@ const struct inode_operations ubifs_dir_inode_operations = {
#ifdef CONFIG_UBIFS_ATIME_SUPPORT
.update_time = ubifs_update_time,
#endif
+ .tmpfile = ubifs_tmpfile,
};
const struct file_operations ubifs_dir_operations = {
--
2.5.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] ubifs: Implement O_TMPFILE
2016-02-21 9:46 [PATCH] ubifs: Implement O_TMPFILE Richard Weinberger
@ 2016-02-23 20:45 ` Pavel Machek
2016-02-23 21:15 ` Richard Weinberger
0 siblings, 1 reply; 3+ messages in thread
From: Pavel Machek @ 2016-02-23 20:45 UTC (permalink / raw)
To: Richard Weinberger; +Cc: linux-mtd, dedekind1, adrian.hunter, linux-kernel
Hi!
> + ui = ubifs_inode(inode);
> +
> + err = ubifs_init_security(dir, inode, &dentry->d_name);
> + if (err)
> + goto out_inode;
> +
> + mutex_lock(&ui->ui_mutex);
> + insert_inode_hash(inode);
> + d_tmpfile(dentry, inode);
> + ubifs_assert(ui->dirty);
> + instantiated = 1;
> + mutex_unlock(&ui->ui_mutex);
> +
> + mutex_lock(&dir_ui->ui_mutex);
> + err = ubifs_jnl_update(c, dir, &dentry->d_name, inode, 1, 0);
> + if (err)
> + goto out_cancel;
> + mutex_unlock(&dir_ui->ui_mutex);
Move the if () below unlock, and make it goto out_inode?
Pavel
--
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] ubifs: Implement O_TMPFILE
2016-02-23 20:45 ` Pavel Machek
@ 2016-02-23 21:15 ` Richard Weinberger
0 siblings, 0 replies; 3+ messages in thread
From: Richard Weinberger @ 2016-02-23 21:15 UTC (permalink / raw)
To: Pavel Machek; +Cc: linux-mtd, dedekind1, adrian.hunter, linux-kernel
Am 23.02.2016 um 21:45 schrieb Pavel Machek:
> Hi!
>
>> + ui = ubifs_inode(inode);
>> +
>> + err = ubifs_init_security(dir, inode, &dentry->d_name);
>> + if (err)
>> + goto out_inode;
>> +
>> + mutex_lock(&ui->ui_mutex);
>> + insert_inode_hash(inode);
>> + d_tmpfile(dentry, inode);
>> + ubifs_assert(ui->dirty);
>> + instantiated = 1;
>> + mutex_unlock(&ui->ui_mutex);
>> +
>> + mutex_lock(&dir_ui->ui_mutex);
>> + err = ubifs_jnl_update(c, dir, &dentry->d_name, inode, 1, 0);
>> + if (err)
>> + goto out_cancel;
>> + mutex_unlock(&dir_ui->ui_mutex);
>
> Move the if () below unlock, and make it goto out_inode?
Yes. That's better. :)
Thanks,
//richard
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2016-02-23 21:15 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-02-21 9:46 [PATCH] ubifs: Implement O_TMPFILE Richard Weinberger
2016-02-23 20:45 ` Pavel Machek
2016-02-23 21:15 ` Richard Weinberger
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).