s_fs_info and ->kill_sb revisited
Subsystems (5)
Hi all,
this series is against the VFS vfs.super branch does two slightly related things:
- move closing of the external devices in ext4 and xfs from ->put_super into ->kill_sb so that this isn't done under s_umount which creates lock ordere reversal
- move freeing the private dta in s_fs_info into ->kill_sb for file systems that pass it in through the fs_context, as otherwise we could leak it before fill_super is called (this is something new on the vfs.super branch because of the changed place where blkdev_get is called)
Diffstat:
exfat/exfat_fs.h | 2 - exfat/super.c | 39 +++++++++++++------------- ext4/super.c | 50 +++++++++++++++++----------------- ntfs3/super.c | 33 ++++++++++------------ xfs/xfs_buf.c | 7 +++- xfs/xfs_super.c | 80 +++++++++++++++++++++++++------------------------------ 6 files changed, 102 insertions(+), 109 deletions(-)
PATCH 1/13 xfs: reformat the xfs_fs_free prototype
The xfs_fs_free prototype formatting is a weird mix of the classic XFS style and the Linux style. Fix it up to be consistent.
--- fs/xfs/xfs_super.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
fs/xfs/xfs_super.c +2 -1
@@ -1933,7 +1933,8 @@ xfs_fs_reconfigure(return 0 ; } -static void xfs_fs_free ( +static void +xfs_fs_free (struct fs_context *fc) {struct xfs_mount *mp = fc->s_fs_info;
Signature · 1 line
2.39.2
Re: [PATCH 01/13] xfs: reformat the xfs_fs_free prototype
Quoted 4 lines · Christoph Hellwig
The
xfs_fs_freeprototype formatting is a weird mix of the classic XFS style and the Linux style. Fix it up to be consistent.Signed-off-by Christoph Hellwig <[email protected]>
--D
Quoted 21 lines
--- fs/xfs/xfs_super.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)fs/xfs/xfs_super.c +2
-1@@ -1933,7 +1933,8 @@ xfs_fs_reconfigure(return 0 ; } -static void xfs_fs_free ( +static void +xfs_fs_free (struct fs_context *fc) {struct xfs_mount *mp = fc->s_fs_info;Signature · 1 line
2.39.2
PATCH 2/13 xfs: remove a superflous s_fs_info NULL check in xfs_fs_put_super
In reply to Christoph Hellwig->put_super is only called when sb->s_root is set, and thus when fill_super succeeds. Thus drop the NULL check that can't happen in xfs_fs_put_super.
--- fs/xfs/xfs_super.c | 4 ---- 1 file changed, 4 deletions(-)
fs/xfs/xfs_super.c +0 -4
@@ -1132,10 +1132,6 @@ xfs_fs_put_super( {struct xfs_mount *mp =XFS_M (sb); -/* if ->fill_super failed, we have no mount to tear down */ -if (!sb->s_fs_info) -return ; -xfs_notice (mp,"Unmounting Filesystem %pU" , &mp->m_sb.sb_uuid);xfs_filestream_unmount (mp);xfs_unmountfs (mp);
Signature · 1 line
2.39.2
Re: [PATCH 02/13] xfs: remove a superflous s_fs_info NULL check in xfs_fs_put_super
Quoted 6 lines · Christoph Hellwig
->put_super is only called when
sb->s_rootis set, and thus whenfill_supersucceeds. Thus drop the NULL check that can't happen inxfs_fs_put_super.Signed-off-by Christoph Hellwig <[email protected]>---
Looks good to me,
Re: [PATCH 02/13] xfs: remove a superflous s_fs_info NULL check in xfs_fs_put_super
In reply to Christoph HellwigQuoted 5 lines · Christoph Hellwig
->put_super is only called when
sb->s_rootis set, and thus whenfill_supersucceeds. Thus drop the NULL check that can't happen inxfs_fs_put_super.Signed-off-by Christoph Hellwig <[email protected]>
Ahahaha, here's the /rest/ of the patchset. I wondered if vger was busted yesterday. Carrying on...
--D
Quoted 22 lines
--- fs/xfs/xfs_super.c | 4 ---- 1 file changed, 4 deletions(-)fs/xfs/xfs_super.c +0
-4@@ -1132,10 +1132,6 @@ xfs_fs_put_super( {struct xfs_mount *mp =XFS_M (sb); -/* if ->fill_super failed, we have no mount to tear down */ -if (!sb->s_fs_info) -return ; -xfs_notice (mp,"Unmounting Filesystem %pU" , &mp->m_sb.sb_uuid);xfs_filestream_unmount (mp);xfs_unmountfs (mp);Signature · 1 line
2.39.2
PATCH 3/13 xfs: free the mount in ->kill_sb
In reply to Christoph HellwigAs a rule of thumb everything allocated to the fs_context and moved into the super_block should be freed by ->kill_sb so that the teardown handling doesn't need to be duplicated between the fill_super error path and put_super. Implement a XFS-specific kill_sb method to do that.
--- fs/xfs/xfs_super.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-)
fs/xfs/xfs_super.c +11 -9
@@ -1143,9 +1143,6 @@ xfs_fs_put_super(xfs_destroy_percpu_counters (mp);xfs_destroy_mount_workqueues (mp);xfs_close_devices (mp); - - sb->s_fs_info =NULL ; -xfs_mount_free (mp); } static long
@@ -1487,7 +1484,7 @@ xfs_fs_fill_super( error =xfs_fs_validate_params (mp);if (error) - goto out_free_names; +return error;sb_min_blocksize (sb,BBSIZE ); sb->s_xattr = xfs_xattr_handlers;
@@ -1514,7 +1511,7 @@ xfs_fs_fill_super( error =xfs_open_devices (mp);if (error) - goto out_free_names; +return error; error =xfs_init_mount_workqueues (mp);if (error)
@@ -1734,9 +1731,6 @@ xfs_fs_fill_super(xfs_destroy_mount_workqueues (mp); out_close_devices:xfs_close_devices (mp); - out_free_names: - sb->s_fs_info =NULL ; -xfs_mount_free (mp);return error; out_unmount:
@@ -1999,12 +1993,20 @@ static int xfs_init_fs_context(return 0 ; } +static void +xfs_kill_sb ( +struct super_block *sb) +{ +kill_block_super (sb); +xfs_mount_free (XFS_M (sb)); +} +static struct file_system_type xfs_fs_type = { .owner =THIS_MODULE , .name ="xfs" , .init_fs_context = xfs_init_fs_context, .parameters = xfs_fs_parameters, - .kill_sb = kill_block_super, + .kill_sb = xfs_kill_sb, .fs_flags =FS_REQUIRES_DEV |FS_ALLOW_IDMAP , };MODULE_ALIAS_FS ("xfs" );
Signature · 1 line
2.39.2
Re: [PATCH 03/13] xfs: free the mount in ->kill_sb
Quoted 7 lines · Christoph Hellwig
As a rule of thumb everything allocated to the
fs_contextand moved into thesuper_blockshould be freed by ->kill_sb so that the teardown handling doesn't need to be duplicated between thefill_supererror path andput_super. Implement a XFS-specifickill_sbmethod to do that.Signed-off-by Christoph Hellwig <[email protected]>---
Looks good to me,
For filesystems on the new mount api it's always nice if the rules can simply be made:
* prior to sget_fc() succeeding fc->s_fs_info and freed in fs_context_operations->free()
* after sget_fc() succeeding fc->s_fs_info transfered to sb->s_fs_info and freed in fs_type->kill_sb()
Re: [PATCH 03/13] xfs: free the mount in ->kill_sb
Quoted 5 lines · Christian Brauner
For filesystems on the new mount api it's always nice if the rules can simply be made:
* prior to
sget_fc()succeedingfc->s_fs_infoand freed infs_context_operations->free()
* aftersget_fc()succeedingfc->s_fs_infotransfered tosb->s_fs_infoand freed infs_type->kill_sb()
Yes. I've been wanting to write this down somewhere, but I can't really think of a good place.
Re: [PATCH 03/13] xfs: free the mount in ->kill_sb
In reply to Christoph HellwigQuoted 6 lines · Christoph Hellwig
As a rule of thumb everything allocated to the
fs_contextand moved into thesuper_blockshould be freed by ->kill_sb so that the teardown handling doesn't need to be duplicated between thefill_supererror path andput_super. Implement a XFS-specifickill_sbmethod to do that.Signed-off-by Christoph Hellwig <[email protected]>
Looks good,
--D
Quoted 71 lines
--- fs/xfs/xfs_super.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-)fs/xfs/xfs_super.c +11
-9@@ -1143,9 +1143,6 @@ xfs_fs_put_super(xfs_destroy_percpu_counters (mp);xfs_destroy_mount_workqueues (mp);xfs_close_devices (mp); - - sb->s_fs_info =NULL ; -xfs_mount_free (mp); } static long@@ -1487,7 +1484,7 @@ xfs_fs_fill_super( error =xfs_fs_validate_params (mp);if (error) - goto out_free_names; +return error;sb_min_blocksize (sb,BBSIZE ); sb->s_xattr = xfs_xattr_handlers;@@ -1514,7 +1511,7 @@ xfs_fs_fill_super( error =xfs_open_devices (mp);if (error) - goto out_free_names; +return error; error =xfs_init_mount_workqueues (mp);if (error)@@ -1734,9 +1731,6 @@ xfs_fs_fill_super(xfs_destroy_mount_workqueues (mp); out_close_devices:xfs_close_devices (mp); - out_free_names: - sb->s_fs_info =NULL ; -xfs_mount_free (mp);return error; out_unmount:@@ -1999,12 +1993,20 @@ static int xfs_init_fs_context(return 0 ; } +static void +xfs_kill_sb ( +struct super_block *sb) +{ +kill_block_super (sb); +xfs_mount_free (XFS_M (sb)); +} +static struct file_system_type xfs_fs_type = { .owner =THIS_MODULE , .name ="xfs" , .init_fs_context = xfs_init_fs_context, .parameters = xfs_fs_parameters, - .kill_sb = kill_block_super, + .kill_sb = xfs_kill_sb, .fs_flags =FS_REQUIRES_DEV |FS_ALLOW_IDMAP , };MODULE_ALIAS_FS ("xfs" );Signature · 1 line
2.39.2
PATCH 4/13 xfs: remove xfs_blkdev_put
In reply to Christoph HellwigThere isn't much use for this trivial wrapper, especially as the NULL check is only needed in a single call site.
--- fs/xfs/xfs_super.c | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-)
fs/xfs/xfs_super.c +5 -13
@@ -395,15 +395,6 @@ xfs_blkdev_get(return error; } -STATIC void -xfs_blkdev_put ( -struct xfs_mount *mp, -struct block_device *bdev) -{ -if (bdev) -blkdev_put (bdev, mp->m_super); -} - STATIC voidxfs_close_devices (struct xfs_mount *mp)
@@ -412,13 +403,13 @@ xfs_close_devices(struct block_device *logdev = mp->m_logdev_targp->bt_bdev;xfs_free_buftarg (mp->m_logdev_targp); -xfs_blkdev_put (mp, logdev); +blkdev_put (logdev, mp->m_super); }if (mp->m_rtdev_targp) {struct block_device *rtdev = mp->m_rtdev_targp->bt_bdev;xfs_free_buftarg (mp->m_rtdev_targp); -xfs_blkdev_put (mp, rtdev); +blkdev_put (rtdev, mp->m_super); }xfs_free_buftarg (mp->m_ddev_targp); }
@@ -503,10 +494,11 @@ xfs_open_devices( out_free_ddev_targ:xfs_free_buftarg (mp->m_ddev_targp); out_close_rtdev: -xfs_blkdev_put (mp, rtdev); +if (rtdev) +blkdev_put (rtdev, sb); out_close_logdev:if (logdev && logdev != ddev) -xfs_blkdev_put (mp, logdev); +blkdev_put (logdev, sb); goto out_relock; }
Signature · 1 line
2.39.2
Re: [PATCH 04/13] xfs: remove xfs_blkdev_put
Quoted 45 lines · Christoph Hellwig
There isn't much use for this trivial wrapper, especially as the NULL check is only needed in a single call site.
Signed-off-by Christoph Hellwig <[email protected]>--- fs/xfs/xfs_super.c | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-)fs/xfs/xfs_super.c +2
-11@@ -395,15 +395,6 @@ xfs_blkdev_get(return error; } -STATIC void -xfs_blkdev_put ( -struct xfs_mount *mp, -struct block_device *bdev) -{ -if (bdev) -blkdev_put (bdev, mp->m_super); -} - STATIC voidxfs_close_devices (struct xfs_mount *mp)@@ -412,13 +403,13 @@ xfs_close_devices(struct block_device *logdev = mp->m_logdev_targp->bt_bdev;xfs_free_buftarg (mp->m_logdev_targp); -xfs_blkdev_put (mp, logdev); +blkdev_put (logdev, mp->m_super); }if (mp->m_rtdev_targp) {struct block_device *rtdev = mp->m_rtdev_targp->bt_bdev;xfs_free_buftarg (mp->m_rtdev_targp); -xfs_blkdev_put (mp, rtdev); +blkdev_put (rtdev, mp->m_super); }xfs_free_buftarg (mp->m_ddev_targp); }
fs/xfs/xfs_super.c xfs_open_devices( · line 497
Quoted 5 lines
fs/xfs/xfs_super.c +1
-1@@ -503,10 +494,11 @@ xfs_open_devices( out_free_ddev_targ:xfs_free_buftarg (mp->m_ddev_targp); out_close_rtdev: -xfs_blkdev_put (mp, rtdev); +if (rtdev)
nit: I think there's a stray space here.
Otherwise,
Re: [PATCH 04/13] xfs: remove xfs_blkdev_put
In reply to Christoph HellwigQuoted 45 lines · Christoph Hellwig
There isn't much use for this trivial wrapper, especially as the NULL check is only needed in a single call site.
Signed-off-by Christoph Hellwig <[email protected]>--- fs/xfs/xfs_super.c | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-)fs/xfs/xfs_super.c +2
-11@@ -395,15 +395,6 @@ xfs_blkdev_get(return error; } -STATIC void -xfs_blkdev_put ( -struct xfs_mount *mp, -struct block_device *bdev) -{ -if (bdev) -blkdev_put (bdev, mp->m_super); -} - STATIC voidxfs_close_devices (struct xfs_mount *mp)@@ -412,13 +403,13 @@ xfs_close_devices(struct block_device *logdev = mp->m_logdev_targp->bt_bdev;xfs_free_buftarg (mp->m_logdev_targp); -xfs_blkdev_put (mp, logdev); +blkdev_put (logdev, mp->m_super); }if (mp->m_rtdev_targp) {struct block_device *rtdev = mp->m_rtdev_targp->bt_bdev;xfs_free_buftarg (mp->m_rtdev_targp); -xfs_blkdev_put (mp, rtdev); +blkdev_put (rtdev, mp->m_super); }xfs_free_buftarg (mp->m_ddev_targp); }
fs/xfs/xfs_super.c xfs_open_devices( · line 497
Quoted 5 lines
fs/xfs/xfs_super.c +1
-1@@ -503,10 +494,11 @@ xfs_open_devices( out_free_ddev_targ:xfs_free_buftarg (mp->m_ddev_targp); out_close_rtdev: -xfs_blkdev_put (mp, rtdev); +if (rtdev)
^ extra space here
With that removed,
--D
Quoted 11 lines
fs/xfs/xfs_super.c +2
-1+blkdev_put (rtdev, sb); out_close_logdev:if (logdev && logdev != ddev) -xfs_blkdev_put (mp, logdev); +blkdev_put (logdev, sb); goto out_relock; }Signature · 1 line
2.39.2
PATCH 5/13 xfs: don't call invalidate_bdev in xfs_free_buftarg
In reply to Christoph HellwigXFS never uses the block device mapping, so there is no point in calling invalidate_bdev which invalidates said mapping.
--- fs/xfs/xfs_buf.c | 1 - 1 file changed, 1 deletion(-)
fs/xfs/xfs_buf.c +0 -1
@@ -1944,7 +1944,6 @@ xfs_free_buftarg(list_lru_destroy (&btp->bt_lru);blkdev_issue_flush (btp->bt_bdev); -invalidate_bdev (btp->bt_bdev);fs_put_dax (btp->bt_daxdev, btp->bt_mount);kmem_free (btp);
Signature · 1 line
2.39.2
Re: [PATCH 05/13] xfs: don't call invalidate_bdev in xfs_free_buftarg
Quoted 4 lines · Christoph Hellwig
XFS never uses the block device mapping, so there is no point in calling
invalidate_bdevwhich invalidates said mapping.Signed-off-by Christoph Hellwig <[email protected]>
This is a revert of commit 032e160305f68 ("xfs: invalidate block device page cache during unmount"). How do you propose dealing with the block device mapping being incoherent due to unmount write races so you don't re-break my test system?
--D
Quoted 19 lines
--- fs/xfs/xfs_buf.c | 1 - 1 file changed, 1 deletion(-)fs/xfs/xfs_buf.c +0
-1@@ -1944,7 +1944,6 @@ xfs_free_buftarg(list_lru_destroy (&btp->bt_lru);blkdev_issue_flush (btp->bt_bdev); -invalidate_bdev (btp->bt_bdev);fs_put_dax (btp->bt_daxdev, btp->bt_mount);kmem_free (btp);Signature · 1 line
2.39.2
PATCH 6/13 xfs: close the RT and log block devices in xfs_free_buftarg
In reply to Christoph HellwigClosing the block devices logically belongs into xfs_free_buftarg, So instead of open coding it in the caller move it there and add a check for the s_bdev so that the main device isn't close as that's done by the VFS helper.
--- fs/xfs/xfs_buf.c | 5 +++++ fs/xfs/xfs_super.c | 12 ++---------- 2 files changed, 7 insertions(+), 10 deletions(-)
fs/xfs/xfs_buf.c +5 -0
@@ -1938,6 +1938,8 @@ voidxfs_free_buftarg ( struct xfs_buftarg *btp) { +struct block_device *bdev = btp->bt_bdev; +unregister_shrinker (&btp->bt_shrinker);ASSERT (percpu_counter_sum (&btp->bt_io_count) ==0 );percpu_counter_destroy (&btp->bt_io_count);
@@ -1945,6 +1947,9 @@ xfs_free_buftarg(blkdev_issue_flush (btp->bt_bdev);fs_put_dax (btp->bt_daxdev, btp->bt_mount); +/* the main block device is closed by kill_block_super */ +if (bdev != btp->bt_mount->m_super->s_bdev) +blkdev_put (bdev, btp->bt_mount->m_super);kmem_free (btp); }
fs/xfs/xfs_super.c +2 -10
@@ -399,18 +399,10 @@ STATIC voidxfs_close_devices ( struct xfs_mount *mp) { -if (mp->m_logdev_targp && mp->m_logdev_targp != mp->m_ddev_targp) { -struct block_device *logdev = mp->m_logdev_targp->bt_bdev; - +if (mp->m_logdev_targp && mp->m_logdev_targp != mp->m_ddev_targp)xfs_free_buftarg (mp->m_logdev_targp); -blkdev_put (logdev, mp->m_super); - } -if (mp->m_rtdev_targp) { -struct block_device *rtdev = mp->m_rtdev_targp->bt_bdev; - +if (mp->m_rtdev_targp)xfs_free_buftarg (mp->m_rtdev_targp); -blkdev_put (rtdev, mp->m_super); - }xfs_free_buftarg (mp->m_ddev_targp); }
Signature · 1 line
2.39.2
Re: [PATCH 06/13] xfs: close the RT and log block devices in xfs_free_buftarg
Quoted 24 lines · Christoph Hellwig
Closing the block devices logically belongs into
xfs_free_buftarg, So instead of open coding it in the caller move it there and add a check for thes_bdevso that the main device isn't close as that's done by the VFS helper.Signed-off-by Christoph Hellwig <[email protected]>--- fs/xfs/xfs_buf.c | 5 +++++ fs/xfs/xfs_super.c | 12 ++---------- 2 files changed, 7 insertions(+), 10 deletions(-)fs/xfs/xfs_buf.c +2
-0@@ -1938,6 +1938,8 @@ voidxfs_free_buftarg ( struct xfs_buftarg *btp) { +struct block_device *bdev = btp->bt_bdev; +unregister_shrinker (&btp->bt_shrinker);ASSERT (percpu_counter_sum (&btp->bt_io_count) ==0 );percpu_counter_destroy (&btp->bt_io_count);
fs/xfs/xfs_buf.c xfs_free_buftarg( · line 1952
Quoted 6 lines
fs/xfs/xfs_buf.c +3
-0@@ -1945,6 +1947,9 @@ xfs_free_buftarg(blkdev_issue_flush (btp->bt_bdev);fs_put_dax (btp->bt_daxdev, btp->bt_mount); +/* the main block device is closed by kill_block_super */ +if (bdev != btp->bt_mount->m_super->s_bdev) +blkdev_put (bdev, btp->bt_mount->m_super);
Hmm... I feel like this would be cleaner if the data dev buftarg could get its own refcount separate from super_block.s_bdev, but I looked through the code and couldn't identify a simple way to do that. Soo...
--D
Quoted 31 lines
fs/xfs/xfs_buf.c +0
-0kmem_free (btp); }fs/xfs/xfs_super.c +2
-10@@ -399,18 +399,10 @@ STATIC voidxfs_close_devices ( struct xfs_mount *mp) { -if (mp->m_logdev_targp && mp->m_logdev_targp != mp->m_ddev_targp) { -struct block_device *logdev = mp->m_logdev_targp->bt_bdev; - +if (mp->m_logdev_targp && mp->m_logdev_targp != mp->m_ddev_targp)xfs_free_buftarg (mp->m_logdev_targp); -blkdev_put (logdev, mp->m_super); - } -if (mp->m_rtdev_targp) { -struct block_device *rtdev = mp->m_rtdev_targp->bt_bdev; - +if (mp->m_rtdev_targp)xfs_free_buftarg (mp->m_rtdev_targp); -blkdev_put (rtdev, mp->m_super); - }xfs_free_buftarg (mp->m_ddev_targp); }Signature · 1 line
2.39.2
Re: [PATCH 06/13] xfs: close the RT and log block devices in xfs_free_buftarg
Quoted 9 lines · Darrick J. Wong
fs/xfs/xfs_buf.c xfs_free_buftarg( · line 1952
Quoted 5 lines
fs/xfs/xfs_buf.c +3
-0blkdev_issue_flush (btp->bt_bdev);fs_put_dax (btp->bt_daxdev, btp->bt_mount); +/* the main block device is closed by kill_block_super */ +if (bdev != btp->bt_mount->m_super->s_bdev) +blkdev_put (bdev, btp->bt_mount->m_super);Hmm... I feel like this would be cleaner if the data dev buftarg could get its own refcount separate from super_block.s_bdev, but I looked through the code and couldn't identify a simple way to do that. Soo...
blkdev_put doesn't really drop a refcount, it closes the device. It just happens to be misnamed, but Jan is looking into a series that will as a side effect end up with a better name for this functionality.
PATCH 7/13 xfs: close the external block devices in xfs_mount_free
In reply to Christoph Hellwigblkdev_put must not be called under sb->s_umount to avoid a lock order reversal with disk->open_mutex. Move closing the buftargs into ->kill_sb to archive that. Note that the flushing of the disk caches needs to be kept in ->put_super as the main block device is closed in kill_block_super already.
--- fs/xfs/xfs_buf.c | 1 - fs/xfs/xfs_super.c | 27 +++++++++++++++++++-------- 2 files changed, 19 insertions(+), 9 deletions(-)
fs/xfs/xfs_buf.c +0 -1
@@ -1945,7 +1945,6 @@ xfs_free_buftarg(percpu_counter_destroy (&btp->bt_io_count);list_lru_destroy (&btp->bt_lru); -blkdev_issue_flush (btp->bt_bdev);fs_put_dax (btp->bt_daxdev, btp->bt_mount);/* the main block device is closed by kill_block_super */ if (bdev != btp->bt_mount->m_super->s_bdev)
fs/xfs/xfs_super.c +19 -8
@@ -396,14 +396,14 @@ xfs_blkdev_get( } STATIC void -xfs_close_devices ( +xfs_flush_disk_caches (struct xfs_mount *mp) {if (mp->m_logdev_targp && mp->m_logdev_targp != mp->m_ddev_targp) -xfs_free_buftarg (mp->m_logdev_targp); +blkdev_issue_flush (mp->m_logdev_targp->bt_bdev);if (mp->m_rtdev_targp) -xfs_free_buftarg (mp->m_rtdev_targp); -xfs_free_buftarg (mp->m_ddev_targp); +blkdev_issue_flush (mp->m_rtdev_targp->bt_bdev); +blkdev_issue_flush (mp->m_ddev_targp->bt_bdev); }/*
@@ -741,6 +741,17 @@ static voidxfs_mount_free ( struct xfs_mount *mp) { +/* +* Free the buftargs here because blkdev_put needs to be called outside +* of sb->s_umount, which is held around the call to ->put_super. +*/ +if (mp->m_logdev_targp && mp->m_logdev_targp != mp->m_ddev_targp) +xfs_free_buftarg (mp->m_logdev_targp); +if (mp->m_rtdev_targp) +xfs_free_buftarg (mp->m_rtdev_targp); +if (mp->m_ddev_targp) +xfs_free_buftarg (mp->m_ddev_targp); +kfree (mp->m_rtname);kfree (mp->m_logname);kmem_free (mp);
@@ -1126,7 +1137,7 @@ xfs_fs_put_super(xfs_inodegc_free_percpu (mp);xfs_destroy_percpu_counters (mp);xfs_destroy_mount_workqueues (mp); -xfs_close_devices (mp); +xfs_flush_disk_caches (mp); } static long
@@ -1499,7 +1510,7 @@ xfs_fs_fill_super( error =xfs_init_mount_workqueues (mp);if (error) - goto out_close_devices; + goto out_flush_caches; error =xfs_init_percpu_counters (mp);if (error)
@@ -1713,8 +1724,8 @@ xfs_fs_fill_super(xfs_destroy_percpu_counters (mp); out_destroy_workqueues:xfs_destroy_mount_workqueues (mp); - out_close_devices: -xfs_close_devices (mp); + out_flush_caches: +xfs_flush_disk_caches (mp);return error; out_unmount:
Signature · 1 line
2.39.2
Re: [PATCH 07/13] xfs: close the external block devices in xfs_mount_free
Quoted 34 lines · Christoph Hellwig
blkdev_putmust not be called undersb->s_umountto avoid a lock order reversal withdisk->open_mutex. Move closing the buftargs into ->kill_sb to archive that. Note that the flushing of the disk caches needs to be kept in ->put_super as the main block device is closed inkill_block_superalready.Signed-off-by Christoph Hellwig <[email protected]>--- fs/xfs/xfs_buf.c | 1 - fs/xfs/xfs_super.c | 27 +++++++++++++++++++-------- 2 files changed, 19 insertions(+), 9 deletions(-)fs/xfs/xfs_buf.c +0
-1@@ -1945,7 +1945,6 @@ xfs_free_buftarg(percpu_counter_destroy (&btp->bt_io_count);list_lru_destroy (&btp->bt_lru); -blkdev_issue_flush (btp->bt_bdev);fs_put_dax (btp->bt_daxdev, btp->bt_mount);/* the main block device is closed by kill_block_super */ if (bdev != btp->bt_mount->m_super->s_bdev)fs/xfs/xfs_super.c +1
-1@@ -396,14 +396,14 @@ xfs_blkdev_get( } STATIC void -xfs_close_devices( +xfs_flush_disk_caches(
fs/xfs/xfs_super.c xfs_blkdev_get( · line 406
Quoted 10 lines
fs/xfs/xfs_super.c +3
-3struct xfs_mount *mp) {if (mp->m_logdev_targp && mp->m_logdev_targp != mp->m_ddev_targp) -xfs_free_buftarg (mp->m_logdev_targp); +blkdev_issue_flush (mp->m_logdev_targp->bt_bdev);if (mp->m_rtdev_targp) -xfs_free_buftarg (mp->m_rtdev_targp); -xfs_free_buftarg (mp->m_ddev_targp); +blkdev_issue_flush (mp->m_rtdev_targp->bt_bdev); +blkdev_issue_flush (mp->m_ddev_targp->bt_bdev);
If I'm following this correctly, putting the superblock flushes the bdevs (though it doesn't invalidate the bdev mapping!) and only later when we free the xfs_mount do we actually put the buftargs?
That works, though I still think we need to invalidate the bdev pagecache for the log and data bdevs.
--D
Quoted 53 lines
fs/xfs/xfs_super.c +15
-4}/* @@ -741,6 +741,17 @@ static voidxfs_mount_free ( struct xfs_mount *mp) { +/* +* Free the buftargs here because blkdev_put needs to be called outside +* of sb->s_umount, which is held around the call to ->put_super. +*/ +if (mp->m_logdev_targp && mp->m_logdev_targp != mp->m_ddev_targp) +xfs_free_buftarg (mp->m_logdev_targp); +if (mp->m_rtdev_targp) +xfs_free_buftarg (mp->m_rtdev_targp); +if (mp->m_ddev_targp) +xfs_free_buftarg (mp->m_ddev_targp); +kfree (mp->m_rtname);kfree (mp->m_logname);kmem_free (mp);@@ -1126,7 +1137,7 @@ xfs_fs_put_super(xfs_inodegc_free_percpu (mp);xfs_destroy_percpu_counters (mp);xfs_destroy_mount_workqueues (mp); -xfs_close_devices (mp); +xfs_flush_disk_caches (mp); } static long@@ -1499,7 +1510,7 @@ xfs_fs_fill_super( error =xfs_init_mount_workqueues (mp);if (error) - goto out_close_devices; + goto out_flush_caches; error =xfs_init_percpu_counters (mp);if (error)@@ -1713,8 +1724,8 @@ xfs_fs_fill_super(xfs_destroy_percpu_counters (mp); out_destroy_workqueues:xfs_destroy_mount_workqueues (mp); - out_close_devices: -xfs_close_devices (mp); + out_flush_caches: +xfs_flush_disk_caches (mp);return error; out_unmount:Signature · 1 line
2.39.2
Re: [PATCH 07/13] xfs: close the external block devices in xfs_mount_free
Quoted 6 lines · Darrick J. Wong
If I'm following this correctly, putting the superblock flushes the bdevs (though it doesn't invalidate the bdev mapping!) and only later when we free the
xfs_mountdo we actually put the buftargs?That works, though I still think we need to invalidate the bdev pagecache for the log and data bdevs.
Yes, I'll respin it with that. And I'll also add a comment to the invalidate_bdev calls because it's completely non-obvious as-is.
Re: [PATCH 07/13] xfs: close the external block devices in xfs_mount_free
Quoted 10 lines · Christoph Hellwig
Quoted 6 lines · Darrick J. Wong
If I'm following this correctly, putting the superblock flushes the bdevs (though it doesn't invalidate the bdev mapping!) and only later when we free the
xfs_mountdo we actually put the buftargs?That works, though I still think we need to invalidate the bdev pagecache for the log and data bdevs.
Yes, I'll respin it with that. And I'll also add a comment to the
invalidate_bdevcalls because it's completely non-obvious as-is.
Ok, thanks! You can reuse the commit message if you want. :)
--D
PATCH 8/13 ext4: close the external journal device in ->kill_sb
In reply to Christoph Hellwigblkdev_put must not be called under sb->s_umount to avoid a lock order reversal with disk->open_mutex. Move closing the external journal device into ->kill_sb to archive that.
--- fs/ext4/super.c | 50 ++++++++++++++++++++++++------------------------- 1 file changed, 25 insertions(+), 25 deletions(-)
fs/ext4/super.c +25 -25
@@ -93,6 +93,7 @@ static int ext4_get_tree(struct fs_context *fc);static int ext4_reconfigure (struct fs_context *fc);static void ext4_fc_free (struct fs_context *fc);static int ext4_init_fs_context (struct fs_context *fc); +static void ext4_kill_sb (struct super_block *sb);static const struct fs_parameter_spec ext4_param_specs[];/*
@@ -135,7 +136,7 @@ static struct file_system_type ext2_fs_type = { .name = "ext2", .init_fs_context = ext4_init_fs_context, .parameters = ext4_param_specs, - .kill_sb = kill_block_super, + .kill_sb = ext4_kill_sb, .fs_flags = FS_REQUIRES_DEV, };MODULE_ALIAS_FS ("ext2" );
@@ -151,7 +152,7 @@ static struct file_system_type ext3_fs_type = { .name = "ext3", .init_fs_context = ext4_init_fs_context, .parameters = ext4_param_specs, - .kill_sb = kill_block_super, + .kill_sb = ext4_kill_sb, .fs_flags = FS_REQUIRES_DEV, };MODULE_ALIAS_FS ("ext3" );
@@ -1116,25 +1117,6 @@ static struct block_device *ext4_blkdev_get(dev_t dev, struct super_block *sb)return NULL ; } -/* -* Release the journal device -*/ -static void ext4_blkdev_remove (struct ext4_sb_info *sbi) -{ -struct block_device *bdev; - bdev = sbi->s_journal_bdev; -if (bdev) { -/* -* Invalidate the journal device's buffers. We don't want them -* floating about in memory - the physical journal device may -* hotswapped, and it breaks the `ro-after' testing code. -*/ -invalidate_bdev (bdev); -blkdev_put (bdev, sbi->s_sb); - sbi->s_journal_bdev =NULL ; - } -} -static inline struct inode *orphan_list_entry (struct list_head *l) { return &list_entry(l, struct ext4_inode_info, i_orphan)->vfs_inode;
@@ -1330,8 +1312,13 @@ static void ext4_put_super(struct super_block *sb)sync_blockdev (sb->s_bdev);invalidate_bdev (sb->s_bdev);if (sbi->s_journal_bdev) { +/* +* Invalidate the journal device's buffers. We don't want them +* floating about in memory - the physical journal device may +* hotswapped, and it breaks the `ro-after' testing code. +*/ sync_blockdev (sbi->s_journal_bdev); -ext4_blkdev_remove (sbi); +invalidate_bdev (sbi->s_journal_bdev); }ext4_xattr_destroy_cache (sbi->s_ea_inode_cache);
@@ -5655,9 +5642,11 @@ failed_mount9: __maybe_unusedkfree (get_qf_name (sb, sbi, i));#endif fscrypt_free_dummy_policy (&sbi->s_dummy_enc_policy); -/* ext4_blkdev_remove() calls kill_bdev(), release bh before it. */ brelse (sbi->s_sbh); -ext4_blkdev_remove (sbi); +if (sbi->s_journal_bdev) { +invalidate_bdev (sbi->s_journal_bdev); +blkdev_put (sbi->s_journal_bdev, sb); + } out_fail:invalidate_bdev (sb->s_bdev); sb->s_fs_info =NULL ;
@@ -7267,12 +7256,23 @@ static inline int ext3_feature_set_ok(struct super_block *sb)return 1 ; } +static void ext4_kill_sb (struct super_block *sb) +{ +struct ext4_sb_info *sbi =EXT4_SB (sb); +struct block_device *journal_bdev = sbi ? sbi->s_journal_bdev :NULL ; + +kill_block_super (sb); + +if (journal_bdev) +blkdev_put (journal_bdev, sb); +} +static struct file_system_type ext4_fs_type = { .owner =THIS_MODULE , .name ="ext4" , .init_fs_context = ext4_init_fs_context, .parameters = ext4_param_specs, - .kill_sb = kill_block_super, + .kill_sb = ext4_kill_sb, .fs_flags =FS_REQUIRES_DEV |FS_ALLOW_IDMAP , };MODULE_ALIAS_FS ("ext4" );
Signature · 1 line
2.39.2
PATCH 9/13 exfat: don't RCU-free the sbi
In reply to Christoph HellwigThere are no RCU critical sections for accessing any information in the sbi, so drop the call_rcu indirection for freeing the sbi.
--- fs/exfat/exfat_fs.h | 2 -- fs/exfat/super.c | 15 ++++----------- 2 files changed, 4 insertions(+), 13 deletions(-)
fs/exfat/exfat_fs.h +0 -2
@@ -273,8 +273,6 @@ struct exfat_sb_info {spinlock_t inode_hash_lock;struct hlist_head inode_hashtable[EXFAT_HASH_SIZE ]; - -struct rcu_head rcu; };#define EXFAT_CACHE_VALID 0
fs/exfat/super.c +4 -11
@@ -31,16 +31,6 @@ static void exfat_free_iocharset(struct exfat_sb_info *sbi)kfree (sbi->options.iocharset); } -static void exfat_delayed_free (struct rcu_head *p) -{ - struct exfat_sb_info *sbi = container_of(p, struct exfat_sb_info, rcu); - -unload_nls (sbi->nls_io); -exfat_free_iocharset (sbi); -exfat_free_upcase_table (sbi); -kfree (sbi); -} -static void exfat_put_super (struct super_block *sb) {struct exfat_sb_info *sbi =EXFAT_SB (sb);
@@ -50,7 +40,10 @@ static void exfat_put_super(struct super_block *sb)brelse (sbi->boot_bh);mutex_unlock (&sbi->s_lock); -call_rcu (&sbi->rcu, exfat_delayed_free); +unload_nls (sbi->nls_io); +exfat_free_iocharset (sbi); +exfat_free_upcase_table (sbi); +kfree (sbi); }static int exfat_sync_fs (struct super_block *sb,int wait)
Signature · 1 line
2.39.2
PATCH 10/13 exfat: free the sbi and iocharset in ->kill_sb
In reply to Christoph HellwigAs a rule of thumb everything allocated to the fs_context and moved into the super_block should be freed by ->kill_sb so that the teardown handling doesn't need to be duplicated between the fill_super error path and put_super. Implement an exfat-specific kill_sb method to do that and share the code with the mount contex free helper for the mount error handling case.
--- fs/exfat/super.c | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-)
fs/exfat/super.c +18 -10
@@ -41,9 +41,7 @@ static void exfat_put_super(struct super_block *sb)mutex_unlock (&sbi->s_lock);unload_nls (sbi->nls_io); -exfat_free_iocharset (sbi);exfat_free_upcase_table (sbi); -kfree (sbi); }static int exfat_sync_fs (struct super_block *sb,int wait)
@@ -703,9 +701,6 @@ static int exfat_fill_super(struct super_block *sb, struct fs_context *fc) check_nls_io:unload_nls (sbi->nls_io); -exfat_free_iocharset (sbi); - sb->s_fs_info =NULL ; -kfree (sbi);return err; }
@@ -714,14 +709,18 @@ static int exfat_get_tree(struct fs_context *fc)return get_tree_bdev (fc, exfat_fill_super); } +static void exfat_free_sbi (struct exfat_sb_info *sbi) +{ +exfat_free_iocharset (sbi); +kfree (sbi); +} +static void exfat_free (struct fs_context *fc) {struct exfat_sb_info *sbi = fc->s_fs_info; -if (sbi) { -exfat_free_iocharset (sbi); -kfree (sbi); - } +if (sbi) +exfat_free_sbi (sbi); }static int exfat_reconfigure (struct fs_context *fc)
@@ -766,12 +765,21 @@ static int exfat_init_fs_context(struct fs_context *fc)return 0 ; } +static void exfat_kill_sb (struct super_block *sb) +{ +struct exfat_sb_info *sbi = sb->s_fs_info; + +kill_block_super (sb); +if (sbi) +exfat_free_sbi (sbi); +} +static struct file_system_type exfat_fs_type = { .owner =THIS_MODULE , .name ="exfat" , .init_fs_context = exfat_init_fs_context, .parameters = exfat_parameters, - .kill_sb = kill_block_super, + .kill_sb = exfat_kill_sb, .fs_flags =FS_REQUIRES_DEV , };
Signature · 1 line
2.39.2
PATCH 11/13 ntfs3: rename put_ntfs ntfs3_free_sbi
In reply to Christoph Hellwigput_ntfs is a rather unconventional name for a function that frees the sbi and associated resources. Give it a more descriptive name and drop the duplicate name in the top of the function comment.
--- fs/ntfs3/super.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
fs/ntfs3/super.c +5 -5
@@ -569,9 +569,9 @@ static void init_once(void *foo) }/* -* put_ntfs - Noinline to reduce binary size. +* Noinline to reduce binary size. */ -static noinline void put_ntfs(struct ntfs_sb_info *sbi) +static noinline void ntfs3_free_sbi(struct ntfs_sb_info *sbi) {kfree (sbi->new_rec);kvfree (ntfs_put_shared (sbi->upcase));
@@ -627,7 +627,7 @@ static void ntfs_put_super(struct super_block *sb)ntfs_set_state (sbi,NTFS_DIRTY_CLEAR );put_mount_options (sbi->options); -put_ntfs (sbi); +ntfs3_free_sbi (sbi); sb->s_fs_info =NULL ;sync_blockdev (sb->s_bdev);
@@ -1569,7 +1569,7 @@ static int ntfs_fill_super(struct super_block *sb, struct fs_context *fc)* ntfs_fs_free will be called with fc->s_fs_info = NULL */ put_mount_options (sbi->options); -put_ntfs (sbi); +ntfs3_free_sbi (sbi); sb->s_fs_info =NULL ;kfree (boot2);
@@ -1659,7 +1659,7 @@ static void ntfs_fs_free(struct fs_context *fc)struct ntfs_sb_info *sbi = fc->s_fs_info;if (sbi) -put_ntfs (sbi); +ntfs3_free_sbi (sbi);if (opts)put_mount_options (opts);
Signature · 1 line
2.39.2
Re: [PATCH 11/13] ntfs3: rename put_ntfs ntfs3_free_sbi
Quoted 6 lines · Christoph Hellwig
put_ntfsis a rather unconventional name for a function that frees the sbi and associated resources. Give it a more descriptive name and drop the duplicate name in the top of the function comment.Signed-off-by Christoph Hellwig <[email protected]>---
Looks good to me,
PATCH 12/13 ntfs3: don't call sync_blockdev in ntfs_put_super
In reply to Christoph Hellwigkill_block_super will call sync_blockdev just a tad later already.
--- fs/ntfs3/super.c | 2 -- 1 file changed, 2 deletions(-)
fs/ntfs3/super.c +0 -2
@@ -629,8 +629,6 @@ static void ntfs_put_super(struct super_block *sb)put_mount_options (sbi->options);ntfs3_free_sbi (sbi); sb->s_fs_info =NULL ; - -sync_blockdev (sb->s_bdev); }static int ntfs_statfs (struct dentry *dentry,struct kstatfs *buf)
Signature · 1 line
2.39.2
Re: [PATCH 12/13] ntfs3: don't call sync_blockdev in ntfs_put_super
Quoted 4 lines · Christoph Hellwig
kill_block_superwill callsync_blockdevjust a tad later already.Signed-off-by Christoph Hellwig <[email protected]>---
Looks good to me,
PATCH 13/13 ntfs3: free the sbi in ->kill_sb
In reply to Christoph HellwigAs a rule of thumb everything allocated to the fs_context and moved into the super_block should be freed by ->kill_sb so that the teardown handling doesn't need to be duplicated between the fill_super error path and put_super. Implement an ntfs3-specific kill_sb method to do that.
--- fs/ntfs3/super.c | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-)
fs/ntfs3/super.c +12 -13
@@ -625,10 +625,6 @@ static void ntfs_put_super(struct super_block *sb)/* Mark rw ntfs as clear, if possible. */ ntfs_set_state (sbi,NTFS_DIRTY_CLEAR ); - -put_mount_options (sbi->options); -ntfs3_free_sbi (sbi); - sb->s_fs_info =NULL ; }static int ntfs_statfs (struct dentry *dentry,struct kstatfs *buf)
@@ -1562,15 +1558,7 @@ static int ntfs_fill_super(struct super_block *sb, struct fs_context *fc) put_inode_out:iput (inode); out: -/* -* Free resources here. -* ntfs_fs_free will be called with fc->s_fs_info = NULL -*/ -put_mount_options (sbi->options); -ntfs3_free_sbi (sbi); - sb->s_fs_info =NULL ;kfree (boot2); -return err; }
@@ -1726,13 +1714,24 @@ static int ntfs_init_fs_context(struct fs_context *fc)return -ENOMEM ; } +static void ntfs3_kill_sb (struct super_block *sb) +{ +struct ntfs_sb_info *sbi = sb->s_fs_info; + +kill_block_super (sb); + +if (sbi->options) +put_mount_options (sbi->options); +ntfs3_free_sbi (sbi); +} +// clang-format off static struct file_system_type ntfs_fs_type = { .owner =THIS_MODULE , .name ="ntfs3" , .init_fs_context = ntfs_init_fs_context, .parameters = ntfs_fs_parameters, - .kill_sb = kill_block_super, + .kill_sb = ntfs3_kill_sb, .fs_flags =FS_REQUIRES_DEV |FS_ALLOW_IDMAP , };// clang-format on
Signature · 1 line
2.39.2
Re: [PATCH 13/13] ntfs3: free the sbi in ->kill_sb
Quoted 8 lines · Christoph Hellwig
As a rule of thumb everything allocated to the
fs_contextand moved into thesuper_blockshould be freed by ->kill_sb so that the teardown handling doesn't need to be duplicated between thefill_supererror path andput_super. Implement an ntfs3-specifickill_sbmethod to do that.Signed-off-by Christoph Hellwig <[email protected]>---
Looks good to me,