btrfs: pass the dentry to btrfs_log_new_name() instead of the inode
authorFilipe Manana <fdmanana@suse.com>
Thu, 20 Jan 2022 11:00:07 +0000 (11:00 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 31 Aug 2022 15:16:36 +0000 (17:16 +0200)
[ Upstream commit d5f5bd546552a94eefd68c42f40f778c40a89d2c ]

In the next patch in the series, there will be the need to access the old
name, and its length, of an inode when logging the inode during a rename.
So instead of passing the inode to btrfs_log_new_name() pass the dentry,
because from the dentry we can get the inode, the name and its length.

This will avoid passing 3 new parameters to btrfs_log_new_name() in the
next patch - the name, its length and an index number. This way we end
up passing only 1 new parameter, the index number.

Signed-off-by: Filipe Manana <fdmanana@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
fs/btrfs/inode.c
fs/btrfs/tree-log.c
fs/btrfs/tree-log.h

index 26a4acb..428a56f 100644 (file)
@@ -6952,7 +6952,7 @@ static int btrfs_link(struct dentry *old_dentry, struct inode *dir,
                                goto fail;
                }
                d_instantiate(dentry, inode);
-               btrfs_log_new_name(trans, BTRFS_I(inode), NULL, parent);
+               btrfs_log_new_name(trans, old_dentry, NULL, parent);
        }
 
 fail:
@@ -9621,13 +9621,13 @@ static int btrfs_rename_exchange(struct inode *old_dir,
                BTRFS_I(new_inode)->dir_index = new_idx;
 
        if (root_log_pinned) {
-               btrfs_log_new_name(trans, BTRFS_I(old_inode), BTRFS_I(old_dir),
+               btrfs_log_new_name(trans, old_dentry, BTRFS_I(old_dir),
                                   new_dentry->d_parent);
                btrfs_end_log_trans(root);
                root_log_pinned = false;
        }
        if (dest_log_pinned) {
-               btrfs_log_new_name(trans, BTRFS_I(new_inode), BTRFS_I(new_dir),
+               btrfs_log_new_name(trans, new_dentry, BTRFS_I(new_dir),
                                   old_dentry->d_parent);
                btrfs_end_log_trans(dest);
                dest_log_pinned = false;
@@ -9908,7 +9908,7 @@ static int btrfs_rename(struct user_namespace *mnt_userns,
                BTRFS_I(old_inode)->dir_index = index;
 
        if (log_pinned) {
-               btrfs_log_new_name(trans, BTRFS_I(old_inode), BTRFS_I(old_dir),
+               btrfs_log_new_name(trans, old_dentry, BTRFS_I(old_dir),
                                   new_dentry->d_parent);
                btrfs_end_log_trans(root);
                log_pinned = false;
index e9e1aae..1d7e981 100644 (file)
@@ -6628,14 +6628,25 @@ void btrfs_record_snapshot_destroy(struct btrfs_trans_handle *trans,
        mutex_unlock(&dir->log_mutex);
 }
 
-/*
- * Call this after adding a new name for a file and it will properly
- * update the log to reflect the new name.
+/**
+ * Update the log after adding a new name for an inode.
+ *
+ * @trans:              Transaction handle.
+ * @old_dentry:         The dentry associated with the old name and the old
+ *                      parent directory.
+ * @old_dir:            The inode of the previous parent directory for the case
+ *                      of a rename. For a link operation, it must be NULL.
+ * @parent:             The dentry associated with the directory under which the
+ *                      new name is located.
+ *
+ * Call this after adding a new name for an inode, as a result of a link or
+ * rename operation, and it will properly update the log to reflect the new name.
  */
 void btrfs_log_new_name(struct btrfs_trans_handle *trans,
-                       struct btrfs_inode *inode, struct btrfs_inode *old_dir,
+                       struct dentry *old_dentry, struct btrfs_inode *old_dir,
                        struct dentry *parent)
 {
+       struct btrfs_inode *inode = BTRFS_I(d_inode(old_dentry));
        struct btrfs_log_ctx ctx;
 
        /*
index 731bd9c..7ffcac8 100644 (file)
@@ -84,7 +84,7 @@ void btrfs_record_unlink_dir(struct btrfs_trans_handle *trans,
 void btrfs_record_snapshot_destroy(struct btrfs_trans_handle *trans,
                                   struct btrfs_inode *dir);
 void btrfs_log_new_name(struct btrfs_trans_handle *trans,
-                       struct btrfs_inode *inode, struct btrfs_inode *old_dir,
+                       struct dentry *old_dentry, struct btrfs_inode *old_dir,
                        struct dentry *parent);
 
 #endif