]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
libxfs: clean up xfs_da_unmount usage
authorDarrick J. Wong <djwong@kernel.org>
Mon, 22 Apr 2024 17:00:49 +0000 (10:00 -0700)
committerDarrick J. Wong <djwong@kernel.org>
Mon, 3 Jun 2024 18:37:35 +0000 (11:37 -0700)
Replace the open-coded xfs_da_unmount usage in libxfs_umount and teach
libxfs_mount not to leak the dir/attr geometry structures when the mount
attempt fails.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
libxfs/init.c

index c9c61ac18793b94d81655a9ae1e26fe00c87268b..b2d7bc1364d3cb9363747687b699ee41b48ae0d5 100644 (file)
@@ -721,7 +721,7 @@ libxfs_mount(
        if (error) {
                fprintf(stderr, _("%s: data size check failed\n"), progname);
                if (!xfs_is_debugger(mp))
-                       return NULL;
+                       goto out_da;
        } else
                libxfs_buf_relse(bp);
 
@@ -735,7 +735,7 @@ libxfs_mount(
                        fprintf(stderr, _("%s: log size checks failed\n"),
                                        progname);
                        if (!xfs_is_debugger(mp))
-                               return NULL;
+                               goto out_da;
                }
                if (bp)
                        libxfs_buf_relse(bp);
@@ -746,8 +746,8 @@ libxfs_mount(
        /* Initialize realtime fields in the mount structure */
        if (rtmount_init(mp)) {
                fprintf(stderr, _("%s: realtime device init failed\n"),
-                       progname);
-                       return NULL;
+                               progname);
+                       goto out_da;
        }
 
        /*
@@ -765,7 +765,7 @@ libxfs_mount(
                        fprintf(stderr, _("%s: read of AG %u failed\n"),
                                                progname, sbp->sb_agcount);
                        if (!xfs_is_debugger(mp))
-                               return NULL;
+                               goto out_da;
                        fprintf(stderr, _("%s: limiting reads to AG 0\n"),
                                                                progname);
                        sbp->sb_agcount = 1;
@@ -783,6 +783,9 @@ libxfs_mount(
        xfs_set_perag_data_loaded(mp);
 
        return mp;
+out_da:
+       xfs_da_unmount(mp);
+       return NULL;
 }
 
 void
@@ -905,8 +908,7 @@ libxfs_umount(
        if (xfs_is_perag_data_loaded(mp))
                libxfs_free_perag(mp);
 
-       kmem_free(mp->m_attr_geo);
-       kmem_free(mp->m_dir_geo);
+       xfs_da_unmount(mp);
 
        free(mp->m_fsname);
        mp->m_fsname = NULL;