2
0

052-01-ubifs-Implement-O_TMPFILE.patch 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. This patchs adds O_TMPFILE support to UBIFS.
  5. A temp file is a reference to an unlinked inode, a user
  6. holding the reference can use it. As soon it is being closed
  7. all data vanishes.
  8. Signed-off-by: Richard Weinberger <richard@nod.at>
  9. ---
  10. --- a/fs/ubifs/dir.c
  11. +++ b/fs/ubifs/dir.c
  12. @@ -301,6 +301,76 @@ out_budg:
  13. return err;
  14. }
  15. +static int ubifs_tmpfile(struct inode *dir, struct dentry *dentry,
  16. + umode_t mode)
  17. +{
  18. + struct inode *inode;
  19. + struct ubifs_info *c = dir->i_sb->s_fs_info;
  20. + struct ubifs_budget_req req = { .new_ino = 1, .new_dent = 1};
  21. + struct ubifs_budget_req ino_req = { .dirtied_ino = 1 };
  22. + struct ubifs_inode *ui, *dir_ui = ubifs_inode(dir);
  23. + int err, instantiated = 0;
  24. +
  25. + /*
  26. + * Budget request settings: new dirty inode, new direntry,
  27. + * budget for dirtied inode will be released via writeback.
  28. + */
  29. +
  30. + dbg_gen("dent '%pd', mode %#hx in dir ino %lu",
  31. + dentry, mode, dir->i_ino);
  32. +
  33. + err = ubifs_budget_space(c, &req);
  34. + if (err)
  35. + return err;
  36. +
  37. + err = ubifs_budget_space(c, &ino_req);
  38. + if (err) {
  39. + ubifs_release_budget(c, &req);
  40. + return err;
  41. + }
  42. +
  43. + inode = ubifs_new_inode(c, dir, mode);
  44. + if (IS_ERR(inode)) {
  45. + err = PTR_ERR(inode);
  46. + goto out_budg;
  47. + }
  48. + ui = ubifs_inode(inode);
  49. +
  50. + err = ubifs_init_security(dir, inode, &dentry->d_name);
  51. + if (err)
  52. + goto out_inode;
  53. +
  54. + mutex_lock(&ui->ui_mutex);
  55. + insert_inode_hash(inode);
  56. + d_tmpfile(dentry, inode);
  57. + ubifs_assert(ui->dirty);
  58. + instantiated = 1;
  59. + mutex_unlock(&ui->ui_mutex);
  60. +
  61. + mutex_lock(&dir_ui->ui_mutex);
  62. + err = ubifs_jnl_update(c, dir, &dentry->d_name, inode, 1, 0);
  63. + if (err)
  64. + goto out_cancel;
  65. + mutex_unlock(&dir_ui->ui_mutex);
  66. +
  67. + ubifs_release_budget(c, &req);
  68. +
  69. + return 0;
  70. +
  71. +out_cancel:
  72. + mutex_unlock(&dir_ui->ui_mutex);
  73. +out_inode:
  74. + make_bad_inode(inode);
  75. + if (!instantiated)
  76. + iput(inode);
  77. +out_budg:
  78. + ubifs_release_budget(c, &req);
  79. + if (!instantiated)
  80. + ubifs_release_budget(c, &ino_req);
  81. + ubifs_err(c, "cannot create temporary file, error %d", err);
  82. + return err;
  83. +}
  84. +
  85. /**
  86. * vfs_dent_type - get VFS directory entry type.
  87. * @type: UBIFS directory entry type
  88. @@ -1195,6 +1265,7 @@ const struct inode_operations ubifs_dir_
  89. #ifdef CONFIG_UBIFS_ATIME_SUPPORT
  90. .update_time = ubifs_update_time,
  91. #endif
  92. + .tmpfile = ubifs_tmpfile,
  93. };
  94. const struct file_operations ubifs_dir_operations = {