2022-10-18 01:01:36 +08:00
|
|
|
--- a/fs/ubifs/dir.c
|
|
|
|
+++ b/fs/ubifs/dir.c
|
|
|
|
@@ -356,6 +356,32 @@ out_budg:
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
+/**
|
|
|
|
+ * lock_2_inodes - a wrapper for locking two UBIFS inodes.
|
|
|
|
+ * @inode1: first inode
|
|
|
|
+ * @inode2: second inode
|
|
|
|
+ *
|
|
|
|
+ * We do not implement any tricks to guarantee strict lock ordering, because
|
|
|
|
+ * VFS has already done it for us on the @i_mutex. So this is just a simple
|
|
|
|
+ * wrapper function.
|
|
|
|
+ */
|
|
|
|
+static void lock_2_inodes(struct inode *inode1, struct inode *inode2)
|
|
|
|
+{
|
|
|
|
+ mutex_lock_nested(&ubifs_inode(inode1)->ui_mutex, WB_MUTEX_1);
|
|
|
|
+ mutex_lock_nested(&ubifs_inode(inode2)->ui_mutex, WB_MUTEX_2);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * unlock_2_inodes - a wrapper for unlocking two UBIFS inodes.
|
|
|
|
+ * @inode1: first inode
|
|
|
|
+ * @inode2: second inode
|
|
|
|
+ */
|
|
|
|
+static void unlock_2_inodes(struct inode *inode1, struct inode *inode2)
|
|
|
|
+{
|
|
|
|
+ mutex_unlock(&ubifs_inode(inode2)->ui_mutex);
|
|
|
|
+ mutex_unlock(&ubifs_inode(inode1)->ui_mutex);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
static int do_tmpfile(struct inode *dir, struct dentry *dentry,
|
|
|
|
umode_t mode, struct inode **whiteout)
|
|
|
|
{
|
2023-06-28 01:25:09 +08:00
|
|
|
@@ -364,7 +390,7 @@ static int do_tmpfile(struct inode *dir,
|
2022-10-18 01:01:36 +08:00
|
|
|
struct ubifs_budget_req req = { .new_ino = 1, .new_dent = 1,
|
|
|
|
.dirtied_ino = 1};
|
|
|
|
struct ubifs_budget_req ino_req = { .dirtied_ino = 1 };
|
|
|
|
- struct ubifs_inode *ui, *dir_ui = ubifs_inode(dir);
|
|
|
|
+ struct ubifs_inode *ui;
|
|
|
|
int err, instantiated = 0;
|
|
|
|
struct fscrypt_name nm;
|
|
|
|
|
2023-06-28 01:25:09 +08:00
|
|
|
@@ -426,11 +452,11 @@ static int do_tmpfile(struct inode *dir,
|
2022-10-18 01:01:36 +08:00
|
|
|
instantiated = 1;
|
|
|
|
mutex_unlock(&ui->ui_mutex);
|
|
|
|
|
|
|
|
- mutex_lock(&dir_ui->ui_mutex);
|
|
|
|
+ lock_2_inodes(dir, inode);
|
|
|
|
err = ubifs_jnl_update(c, dir, &nm, inode, 1, 0);
|
|
|
|
if (err)
|
|
|
|
goto out_cancel;
|
|
|
|
- mutex_unlock(&dir_ui->ui_mutex);
|
|
|
|
+ unlock_2_inodes(dir, inode);
|
|
|
|
|
|
|
|
ubifs_release_budget(c, &req);
|
2023-06-28 01:25:09 +08:00
|
|
|
fscrypt_free_filename(&nm);
|
|
|
|
@@ -438,7 +464,7 @@ static int do_tmpfile(struct inode *dir,
|
2022-10-18 01:01:36 +08:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
out_cancel:
|
|
|
|
- mutex_unlock(&dir_ui->ui_mutex);
|
|
|
|
+ unlock_2_inodes(dir, inode);
|
|
|
|
out_inode:
|
|
|
|
make_bad_inode(inode);
|
|
|
|
if (!instantiated)
|
2023-06-28 01:25:09 +08:00
|
|
|
@@ -673,32 +699,6 @@ static int ubifs_dir_release(struct inod
|
2022-10-18 01:01:36 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
-/**
|
|
|
|
- * lock_2_inodes - a wrapper for locking two UBIFS inodes.
|
|
|
|
- * @inode1: first inode
|
|
|
|
- * @inode2: second inode
|
|
|
|
- *
|
|
|
|
- * We do not implement any tricks to guarantee strict lock ordering, because
|
|
|
|
- * VFS has already done it for us on the @i_mutex. So this is just a simple
|
|
|
|
- * wrapper function.
|
|
|
|
- */
|
|
|
|
-static void lock_2_inodes(struct inode *inode1, struct inode *inode2)
|
|
|
|
-{
|
|
|
|
- mutex_lock_nested(&ubifs_inode(inode1)->ui_mutex, WB_MUTEX_1);
|
|
|
|
- mutex_lock_nested(&ubifs_inode(inode2)->ui_mutex, WB_MUTEX_2);
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-/**
|
|
|
|
- * unlock_2_inodes - a wrapper for unlocking two UBIFS inodes.
|
|
|
|
- * @inode1: first inode
|
|
|
|
- * @inode2: second inode
|
|
|
|
- */
|
|
|
|
-static void unlock_2_inodes(struct inode *inode1, struct inode *inode2)
|
|
|
|
-{
|
|
|
|
- mutex_unlock(&ubifs_inode(inode2)->ui_mutex);
|
|
|
|
- mutex_unlock(&ubifs_inode(inode1)->ui_mutex);
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
static int ubifs_link(struct dentry *old_dentry, struct inode *dir,
|
|
|
|
struct dentry *dentry)
|
|
|
|
{
|