]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
libxfs: merge the file vs device cases in libxfs_init
authorChristoph Hellwig <hch@lst.de>
Mon, 11 Dec 2023 16:37:32 +0000 (17:37 +0100)
committerCarlos Maiolino <cem@kernel.org>
Mon, 18 Dec 2023 13:57:48 +0000 (14:57 +0100)
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: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Carlos Maiolino <cmaiolino@redhat.com>
Signed-off-by: Carlos Maiolino <cem@kernel.org>
libxfs/init.c

index 14962b9fa33ac9337f044ae9c0e3dbf36fe02b6a..86b810bfe9a3f755e1f215093de24742c1c66fee 100644 (file)
@@ -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);