diff mbox series

[13/23] libxfs: merge the file vs device cases in libxfs_init

Message ID 20231211163742.837427-14-hch@lst.de (mailing list archive)
State Accepted
Headers show
Series [01/23] libxfs: remove the unused icache_flags member from struct libxfs_xinit | expand

Commit Message

Christoph Hellwig Dec. 11, 2023, 4:37 p.m. UTC
The only special handling for an XFS device on a regular file is that
we skip the checks in check_open.  Simplify perform those conditionally
instead of duplicating the entire sequence.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 libxfs/init.c | 74 ++++++++++++++++-----------------------------------
 1 file changed, 23 insertions(+), 51 deletions(-)

Comments

Carlos Maiolino Dec. 18, 2023, 9:23 a.m. UTC | #1
On Mon, Dec 11, 2023 at 05:37:32PM +0100, Christoph Hellwig wrote:
> The only special handling for an XFS device on a regular file is that
> we skip the checks in check_open.  Simplify perform those conditionally
> instead of duplicating the entire sequence.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>

Reviewed-by: Carlos Maiolino <cmaiolino@redhat.com>

> ---
>  libxfs/init.c | 74 ++++++++++++++++-----------------------------------
>  1 file changed, 23 insertions(+), 51 deletions(-)
> 
> diff --git a/libxfs/init.c b/libxfs/init.c
> index 14962b9fa..86b810bfe 100644
> --- a/libxfs/init.c
> +++ b/libxfs/init.c
> @@ -313,59 +313,31 @@ libxfs_init(struct libxfs_init *a)
>  	radix_tree_init();
> 
>  	if (dname) {
> -		if (a->disfile) {
> -			a->ddev= libxfs_device_open(dname, a->dcreat, flags,
> -						    a->setblksize);
> -			a->dfd = libxfs_device_to_fd(a->ddev);
> -			platform_findsizes(dname, a->dfd, &a->dsize,
> -					   &a->dbsize);
> -		} else {
> -			if (!check_open(dname, flags))
> -				goto done;
> -			a->ddev = libxfs_device_open(dname,
> -					a->dcreat, flags, a->setblksize);
> -			a->dfd = libxfs_device_to_fd(a->ddev);
> -			platform_findsizes(dname, a->dfd,
> -					   &a->dsize, &a->dbsize);
> -		}
> -	} else
> -		a->dsize = 0;
> +		if (!a->disfile && !check_open(dname, flags))
> +			goto done;
> +		a->ddev = libxfs_device_open(dname, a->dcreat, flags,
> +				a->setblksize);
> +		a->dfd = libxfs_device_to_fd(a->ddev);
> +		platform_findsizes(dname, a->dfd, &a->dsize, &a->dbsize);
> +	}
>  	if (logname) {
> -		if (a->lisfile) {
> -			a->logdev = libxfs_device_open(logname,
> -					a->lcreat, flags, a->setblksize);
> -			a->logfd = libxfs_device_to_fd(a->logdev);
> -			platform_findsizes(dname, a->logfd, &a->logBBsize,
> -					   &a->lbsize);
> -		} else {
> -			if (!check_open(logname, flags))
> -				goto done;
> -			a->logdev = libxfs_device_open(logname,
> -					a->lcreat, flags, a->setblksize);
> -			a->logfd = libxfs_device_to_fd(a->logdev);
> -			platform_findsizes(logname, a->logfd,
> -					   &a->logBBsize, &a->lbsize);
> -		}
> -	} else
> -		a->logBBsize = 0;
> +		if (!a->lisfile && !check_open(logname, flags))
> +			goto done;
> +		a->logdev = libxfs_device_open(logname, a->lcreat, flags,
> +				a->setblksize);
> +		a->logfd = libxfs_device_to_fd(a->logdev);
> +		platform_findsizes(logname, a->logfd, &a->logBBsize,
> +				&a->lbsize);
> +	}
>  	if (rtname) {
> -		if (a->risfile) {
> -			a->rtdev = libxfs_device_open(rtname,
> -					a->rcreat, flags, a->setblksize);
> -			a->rtfd = libxfs_device_to_fd(a->rtdev);
> -			platform_findsizes(dname, a->rtfd, &a->rtsize,
> -					   &a->rtbsize);
> -		} else {
> -			if (!check_open(rtname, flags))
> -				goto done;
> -			a->rtdev = libxfs_device_open(rtname,
> -					a->rcreat, flags, a->setblksize);
> -			a->rtfd = libxfs_device_to_fd(a->rtdev);
> -			platform_findsizes(rtname, a->rtfd,
> -					   &a->rtsize, &a->rtbsize);
> -		}
> -	} else
> -		a->rtsize = 0;
> +		if (a->risfile && !check_open(rtname, flags))
> +			goto done;
> +		a->rtdev = libxfs_device_open(rtname, a->rcreat, flags,
> +				a->setblksize);
> +		a->rtfd = libxfs_device_to_fd(a->rtdev);
> +		platform_findsizes(dname, a->rtfd, &a->rtsize, &a->rtbsize);
> +	}
> +
>  	if (a->dsize < 0) {
>  		fprintf(stderr, _("%s: can't get size for data subvolume\n"),
>  			progname);
> --
> 2.39.2
>
diff mbox series

Patch

diff --git a/libxfs/init.c b/libxfs/init.c
index 14962b9fa..86b810bfe 100644
--- a/libxfs/init.c
+++ b/libxfs/init.c
@@ -313,59 +313,31 @@  libxfs_init(struct libxfs_init *a)
 	radix_tree_init();
 
 	if (dname) {
-		if (a->disfile) {
-			a->ddev= libxfs_device_open(dname, a->dcreat, flags,
-						    a->setblksize);
-			a->dfd = libxfs_device_to_fd(a->ddev);
-			platform_findsizes(dname, a->dfd, &a->dsize,
-					   &a->dbsize);
-		} else {
-			if (!check_open(dname, flags))
-				goto done;
-			a->ddev = libxfs_device_open(dname,
-					a->dcreat, flags, a->setblksize);
-			a->dfd = libxfs_device_to_fd(a->ddev);
-			platform_findsizes(dname, a->dfd,
-					   &a->dsize, &a->dbsize);
-		}
-	} else
-		a->dsize = 0;
+		if (!a->disfile && !check_open(dname, flags))
+			goto done;
+		a->ddev = libxfs_device_open(dname, a->dcreat, flags,
+				a->setblksize);
+		a->dfd = libxfs_device_to_fd(a->ddev);
+		platform_findsizes(dname, a->dfd, &a->dsize, &a->dbsize);
+	}
 	if (logname) {
-		if (a->lisfile) {
-			a->logdev = libxfs_device_open(logname,
-					a->lcreat, flags, a->setblksize);
-			a->logfd = libxfs_device_to_fd(a->logdev);
-			platform_findsizes(dname, a->logfd, &a->logBBsize,
-					   &a->lbsize);
-		} else {
-			if (!check_open(logname, flags))
-				goto done;
-			a->logdev = libxfs_device_open(logname,
-					a->lcreat, flags, a->setblksize);
-			a->logfd = libxfs_device_to_fd(a->logdev);
-			platform_findsizes(logname, a->logfd,
-					   &a->logBBsize, &a->lbsize);
-		}
-	} else
-		a->logBBsize = 0;
+		if (!a->lisfile && !check_open(logname, flags))
+			goto done;
+		a->logdev = libxfs_device_open(logname, a->lcreat, flags,
+				a->setblksize);
+		a->logfd = libxfs_device_to_fd(a->logdev);
+		platform_findsizes(logname, a->logfd, &a->logBBsize,
+				&a->lbsize);
+	}
 	if (rtname) {
-		if (a->risfile) {
-			a->rtdev = libxfs_device_open(rtname,
-					a->rcreat, flags, a->setblksize);
-			a->rtfd = libxfs_device_to_fd(a->rtdev);
-			platform_findsizes(dname, a->rtfd, &a->rtsize,
-					   &a->rtbsize);
-		} else {
-			if (!check_open(rtname, flags))
-				goto done;
-			a->rtdev = libxfs_device_open(rtname,
-					a->rcreat, flags, a->setblksize);
-			a->rtfd = libxfs_device_to_fd(a->rtdev);
-			platform_findsizes(rtname, a->rtfd,
-					   &a->rtsize, &a->rtbsize);
-		}
-	} else
-		a->rtsize = 0;
+		if (a->risfile && !check_open(rtname, flags))
+			goto done;
+		a->rtdev = libxfs_device_open(rtname, a->rcreat, flags,
+				a->setblksize);
+		a->rtfd = libxfs_device_to_fd(a->rtdev);
+		platform_findsizes(dname, a->rtfd, &a->rtsize, &a->rtbsize);
+	}
+
 	if (a->dsize < 0) {
 		fprintf(stderr, _("%s: can't get size for data subvolume\n"),
 			progname);