From: Darrick J. Wong Date: Thu, 27 Feb 2020 20:19:51 +0000 (-0500) Subject: libxfs: clean up libxfs_destroy X-Git-Tag: v5.5.0-rc1~38 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a9468486b859214560db69814ee9deea42631fb9;p=thirdparty%2Fxfsprogs-dev.git libxfs: clean up libxfs_destroy 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 Reviewed-by: Eric Sandeen Reviewed-by: Brian Foster Reviewed-by: Christoph Hellwig Signed-off-by: Eric Sandeen --- diff --git a/copy/xfs_copy.c b/copy/xfs_copy.c index a6d670388..7f4615ac7 100644 --- a/copy/xfs_copy.c +++ b/copy/xfs_copy.c @@ -1200,7 +1200,7 @@ main(int argc, char **argv) check_errors(); libxfs_umount(mp); - libxfs_destroy(); + libxfs_destroy(&xargs); return 0; } diff --git a/db/init.c b/db/init.c index 0ac373685..e5450d2b5 100644 --- 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; } diff --git a/include/libxfs.h b/include/libxfs.h index aaac00f67..504f6e9cd 100644 --- a/include/libxfs.h +++ b/include/libxfs.h @@ -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); diff --git a/libxfs/init.c b/libxfs/init.c index a0d4b7f4d..3c3063fc7 100644 --- a/libxfs/init.c +++ b/libxfs/init.c @@ -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(); diff --git a/mkfs/xfs_mkfs.c b/mkfs/xfs_mkfs.c index cc71fd392..d3b36756a 100644 --- a/mkfs/xfs_mkfs.c +++ b/mkfs/xfs_mkfs.c @@ -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; } diff --git a/repair/xfs_repair.c b/repair/xfs_repair.c index eb1ce5460..2c15125f6 100644 --- a/repair/xfs_repair.c +++ b/repair/xfs_repair.c @@ -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();