]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
libxfs: clean up libxfs_destroy
authorDarrick J. Wong <darrick.wong@oracle.com>
Thu, 27 Feb 2020 20:19:51 +0000 (15:19 -0500)
committerEric Sandeen <sandeen@sandeen.net>
Thu, 27 Feb 2020 20:19:51 +0000 (15:19 -0500)
It's weird that libxfs_init opens the three devices passed in via the
libxfs_xinit structure but libxfs_destroy doesn't actually close them.
Fix this inconsistency and remove all the open-coded device closing.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
copy/xfs_copy.c
db/init.c
include/libxfs.h
libxfs/init.c
mkfs/xfs_mkfs.c
repair/xfs_repair.c

index a6d670388f74bc2ce668d2ef39995325c9553e09..7f4615ac705aacc9563bad5466ac55cc7c5392c5 100644 (file)
@@ -1200,7 +1200,7 @@ main(int argc, char **argv)
 
        check_errors();
        libxfs_umount(mp);
-       libxfs_destroy();
+       libxfs_destroy(&xargs);
 
        return 0;
 }
index 0ac3736851601a124d6aaa0f02b4bf2bae491e3b..e5450d2b56ced89f1a166543a9b84a184520b4b3 100644 (file)
--- a/db/init.c
+++ b/db/init.c
@@ -217,13 +217,7 @@ close_devices:
        while (iocur_sp > start_iocur_sp)
                pop_cur();
        libxfs_umount(mp);
-       if (x.ddev)
-               libxfs_device_close(x.ddev);
-       if (x.logdev && x.logdev != x.ddev)
-               libxfs_device_close(x.logdev);
-       if (x.rtdev)
-               libxfs_device_close(x.rtdev);
-       libxfs_destroy();
+       libxfs_destroy(&x);
 
        return exitcode;
 }
index aaac00f6761235169a4bab004191e35f95fdd546..504f6e9cd1eb5ffb270f24bcafa23a5995e920df 100644 (file)
@@ -136,7 +136,7 @@ typedef struct libxfs_xinit {
 extern char    *progname;
 extern xfs_lsn_t libxfs_max_lsn;
 extern int     libxfs_init (libxfs_init_t *);
-extern void    libxfs_destroy (void);
+void           libxfs_destroy(struct libxfs_xinit *li);
 extern int     libxfs_device_to_fd (dev_t);
 extern dev_t   libxfs_device_open (char *, int, int, int);
 extern void    libxfs_device_close (dev_t);
index a0d4b7f4d42531ef4ad9a4e569f70f4059774428..3c3063fc773473bfe12b2a264e15846705d3a635 100644 (file)
@@ -259,6 +259,21 @@ destroy_zones(void)
        return leaked;
 }
 
+static void
+libxfs_close_devices(
+       struct libxfs_xinit     *li)
+{
+       if (li->ddev)
+               libxfs_device_close(li->ddev);
+       if (li->logdev && li->logdev != li->ddev)
+               libxfs_device_close(li->logdev);
+       if (li->rtdev)
+               libxfs_device_close(li->rtdev);
+
+       li->ddev = li->logdev = li->rtdev = 0;
+       li->dfd = li->logfd = li->rtfd = -1;
+}
+
 /*
  * libxfs initialization.
  * Caller gets a 0 on failure (and we print a message), 1 on success.
@@ -385,12 +400,9 @@ done:
                unlink(rtpath);
        if (fd >= 0)
                close(fd);
-       if (!rval && a->ddev)
-               libxfs_device_close(a->ddev);
-       if (!rval && a->logdev)
-               libxfs_device_close(a->logdev);
-       if (!rval && a->rtdev)
-               libxfs_device_close(a->rtdev);
+       if (!rval)
+               libxfs_close_devices(a);
+
        return rval;
 }
 
@@ -822,9 +834,12 @@ libxfs_umount(xfs_mount_t *mp)
  * Release any global resources used by libxfs.
  */
 void
-libxfs_destroy(void)
+libxfs_destroy(
+       struct libxfs_xinit     *li)
 {
-       int     leaked;
+       int                     leaked;
+
+       libxfs_close_devices(li);
 
        /* Free everything from the buffer cache before freeing buffer zone */
        libxfs_bcache_purge();
index cc71fd392519b737c8adf926c1315b6f59bead2d..d3b36756a37bc30aab2c39aa49c126266f45dccd 100644 (file)
@@ -3892,12 +3892,7 @@ main(
        libxfs_writebuf(buf, LIBXFS_EXIT_ON_FAILURE);
 
        libxfs_umount(mp);
-       if (xi.rtdev)
-               libxfs_device_close(xi.rtdev);
-       if (xi.logdev && xi.logdev != xi.ddev)
-               libxfs_device_close(xi.logdev);
-       libxfs_device_close(xi.ddev);
-       libxfs_destroy();
+       libxfs_destroy(&xi);
 
        return 0;
 }
index eb1ce5460d3825aaec0cd4613b8daa552da79bf2..2c15125f682064549559be30ccbc42f8c2fb8b28 100644 (file)
@@ -1106,12 +1106,7 @@ _("Note - stripe unit (%d) and width (%d) were copied from a backup superblock.\
        format_log_max_lsn(mp);
        libxfs_umount(mp);
 
-       if (x.rtdev)
-               libxfs_device_close(x.rtdev);
-       if (x.logdev && x.logdev != x.ddev)
-               libxfs_device_close(x.logdev);
-       libxfs_device_close(x.ddev);
-       libxfs_destroy();
+       libxfs_destroy(&x);
 
        if (verbose)
                summary_report();