The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
To: Javier Martinez Canillas <javierm@redhat.com>
Cc: linux-kernel@vger.kernel.org, Peter Jones <pjones@redhat.com>,
	Alexander Larsson <alexl@redhat.com>,
	Colin Walters <walters@verbum.org>,
	Alberto Ruiz <aruiz@redhat.com>,
	Muhammad Usama Anjum <usama.anjum@collabora.com>,
	Lennart Poettering <lennart@poettering.net>,
	Chung-Chiang Cheng <cccheng@synology.com>,
	Christian Kellner <ckellner@redhat.com>,
	Carlos Maiolino <cmaiolin@redhat.com>
Subject: Re: [PATCH v5 3/4] fat: add renameat2 RENAME_EXCHANGE flag support
Date: Fri, 10 Jun 2022 04:17:38 +0900	[thread overview]
Message-ID: <878rq54pf1.fsf@mail.parknet.co.jp> (raw)
In-Reply-To: <20220609093638.664034-4-javierm@redhat.com> (Javier Martinez Canillas's message of "Thu, 9 Jun 2022 11:36:36 +0200")

Javier Martinez Canillas <javierm@redhat.com> writes:

> +static void vfat_update_nlink(struct inode *dir, struct inode *inode)
> +{
> +		if (S_ISDIR(inode->i_mode))
> +			drop_nlink(dir);
> +		else
> +			inc_nlink(dir);
> +}

[...]

> +	vfat_update_dir_metadata(old_dir, &ts);
> +	/* if directories are not the same, update new_dir as well */
> +	if (old_dir != new_dir) {
> +		vfat_update_dir_metadata(new_dir, &ts);
> +		/* nlink only needs to be updated if the file types differ */
> +		if (old_inode->i_mode != new_inode->i_mode) {
> +			vfat_update_nlink(old_dir, old_inode);
> +			vfat_update_nlink(new_dir, new_inode);
> +		}
> +	}

Looks like unnecessary complex (and comparing raw i_mode, not S_ISDIR(),
better to change before make dir dirty).  How about this change, it is
only tested slightly though? Can you review and test?

Thanks.
-- 
OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>


Signed-off-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
---
 fs/fat/namei_vfat.c |   25 ++++++++++++-------------
 1 file changed, 12 insertions(+), 13 deletions(-)

diff --git a/fs/fat/namei_vfat.c b/fs/fat/namei_vfat.c
index c30f829..3aef834 100644
--- a/fs/fat/namei_vfat.c	2022-06-10 03:33:40.334212176 +0900
+++ b/fs/fat/namei_vfat.c	2022-06-10 04:11:30.817064192 +0900
@@ -1055,12 +1055,10 @@ static void vfat_exchange_ipos(struct in
 	fat_attach(new_inode, old_i_pos);
 }
 
-static void vfat_update_nlink(struct inode *dir, struct inode *inode)
+static void vfat_move_nlink(struct inode *src, struct inode *dst)
 {
-		if (S_ISDIR(inode->i_mode))
-			drop_nlink(dir);
-		else
-			inc_nlink(dir);
+	drop_nlink(src);
+	inc_nlink(dst);
 }
 
 static int vfat_rename_exchange(struct inode *old_dir, struct dentry *old_dentry,
@@ -1112,7 +1110,6 @@ static int vfat_rename_exchange(struct i
 		if (err)
 			goto error_old_dotdot;
 	}
-
 	if (new_dotdot_de) {
 		err = vfat_update_dotdot_de(old_dir, new_inode, new_dotdot_bh,
 					    new_dotdot_de);
@@ -1120,16 +1117,18 @@ static int vfat_rename_exchange(struct i
 			goto error_new_dotdot;
 	}
 
+	/* if cross directory and only one is a directory, adjust nlink */
+	if (!old_dotdot_de != !new_dotdot_de) {
+		if (old_dotdot_de)
+			vfat_move_nlink(old_dir, new_dir);
+		else
+			vfat_move_nlink(new_dir, old_dir);
+	}
+
 	vfat_update_dir_metadata(old_dir, &ts);
 	/* if directories are not the same, update new_dir as well */
-	if (old_dir != new_dir) {
+	if (old_dir != new_dir)
 		vfat_update_dir_metadata(new_dir, &ts);
-		/* nlink only needs to be updated if the file types differ */
-		if (old_inode->i_mode != new_inode->i_mode) {
-			vfat_update_nlink(old_dir, old_inode);
-			vfat_update_nlink(new_dir, new_inode);
-		}
-	}
 
 out:
 	brelse(old_dotdot_bh);
_

  reply	other threads:[~2022-06-09 19:17 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-09  9:36 [PATCH v5 0/4] fat: add support for the renameat2 RENAME_EXCHANGE flag Javier Martinez Canillas
2022-06-09  9:36 ` [PATCH v5 1/4] fat: add a vfat_rename2() and make existing .rename callback a helper Javier Martinez Canillas
2022-06-09  9:36 ` [PATCH v5 2/4] fat: factor out reusable code in vfat_rename() as helper functions Javier Martinez Canillas
2022-06-09  9:36 ` [PATCH v5 3/4] fat: add renameat2 RENAME_EXCHANGE flag support Javier Martinez Canillas
2022-06-09 19:17   ` OGAWA Hirofumi [this message]
2022-06-09 20:36     ` Javier Martinez Canillas
2022-06-10  3:17       ` OGAWA Hirofumi
2022-06-10  6:27         ` Javier Martinez Canillas
2022-06-09  9:36 ` [PATCH v5 4/4] selftests/filesystems: add a vfat RENAME_EXCHANGE test Javier Martinez Canillas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=878rq54pf1.fsf@mail.parknet.co.jp \
    --to=hirofumi@mail.parknet.co.jp \
    --cc=alexl@redhat.com \
    --cc=aruiz@redhat.com \
    --cc=cccheng@synology.com \
    --cc=ckellner@redhat.com \
    --cc=cmaiolin@redhat.com \
    --cc=javierm@redhat.com \
    --cc=lennart@poettering.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pjones@redhat.com \
    --cc=usama.anjum@collabora.com \
    --cc=walters@verbum.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox