Merge tag 'v6.6-vfs.super' of git://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs
authorLinus Torvalds <torvalds@linux-foundation.org>
Mon, 28 Aug 2023 18:04:18 +0000 (11:04 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Mon, 28 Aug 2023 18:04:18 +0000 (11:04 -0700)
Pull superblock updates from Christian Brauner:
 "This contains the super rework that was ready for this cycle. The
  first part changes the order of how we open block devices and allocate
  superblocks, contains various cleanups, simplifications, and a new
  mechanism to wait on superblock state changes.

  This unblocks work to ultimately limit the number of writers to a
  block device. Jan has already scheduled follow-up work that will be
  ready for v6.7 and allows us to restrict the number of writers to a
  given block device. That series builds on this work right here.

  The second part contains filesystem freezing updates.

  Overview:

  The generic superblock changes are rougly organized as follows
  (ignoring additional minor cleanups):

   (1) Removal of the bd_super member from struct block_device.

       This was a very odd back pointer to struct super_block with
       unclear rules. For all relevant places we have other means to get
       the same information so just get rid of this.

   (2) Simplify rules for superblock cleanup.

       Roughly, everything that is allocated during fs_context
       initialization and that's stored in fs_context->s_fs_info needs
       to be cleaned up by the fs_context->free() implementation before
       the superblock allocation function has been called successfully.

       After sget_fc() returned fs_context->s_fs_info has been
       transferred to sb->s_fs_info at which point sb->kill_sb() if
       fully responsible for cleanup. Adhering to these rules means that
       cleanup of sb->s_fs_info in fill_super() is to be avoided as it's
       brittle and inconsistent.

       Cleanup shouldn't be duplicated between sb->put_super() as
       sb->put_super() is only called if sb->s_root has been set aka
       when the filesystem has been successfully born (SB_BORN). That
       complexity should be avoided.

       This also means that block devices are to be closed in
       sb->kill_sb() instead of sb->put_super(). More details in the
       lower section.

   (3) Make it possible to lookup or create a superblock before opening
       block devices

       There's a subtle dependency on (2) as some filesystems did rely
       on fill_super() to be called in order to correctly clean up
       sb->s_fs_info. All these filesystems have been fixed.

   (4) Switch most filesystem to follow the same logic as the generic
       mount code now does as outlined in (3).

   (5) Use the superblock as the holder of the block device. We can now
       easily go back from block device to owning superblock.

   (6) Export and extend the generic fs_holder_ops and use them as
       holder ops everywhere and remove the filesystem specific holder
       ops.

   (7) Call from the block layer up into the filesystem layer when the
       block device is removed, allowing to shut down the filesystem
       without risk of deadlocks.

   (8) Get rid of get_super().

       We can now easily go back from the block device to owning
       superblock and can call up from the block layer into the
       filesystem layer when the device is removed. So no need to wade
       through all registered superblock to find the owning superblock
       anymore"

Link: https://lore.kernel.org/lkml/20230824-prall-intakt-95dbffdee4a0@brauner/
* tag 'v6.6-vfs.super' of git://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs: (47 commits)
  super: use higher-level helper for {freeze,thaw}
  super: wait until we passed kill super
  super: wait for nascent superblocks
  super: make locking naming consistent
  super: use locking helpers
  fs: simplify invalidate_inodes
  fs: remove get_super
  block: call into the file system for ioctl BLKFLSBUF
  block: call into the file system for bdev_mark_dead
  block: consolidate __invalidate_device and fsync_bdev
  block: drop the "busy inodes on changed media" log message
  dasd: also call __invalidate_device when setting the device offline
  amiflop: don't call fsync_bdev in FDFMTBEG
  floppy: call disk_force_media_change when changing the format
  block: simplify the disk_force_media_change interface
  nbd: call blk_mark_disk_dead in nbd_clear_sock_ioctl
  xfs use fs_holder_ops for the log and RT devices
  xfs: drop s_umount over opening the log and RT devices
  ext4: use fs_holder_ops for the log device
  ext4: drop s_umount over opening the log device
  ...

17 files changed:
1  2 
Documentation/filesystems/vfs.rst
drivers/block/loop.c
drivers/s390/block/dasd.c
fs/buffer.c
fs/cramfs/inode.c
fs/exfat/super.c
fs/ext4/super.c
fs/f2fs/super.c
fs/gfs2/super.c
fs/inode.c
fs/ioctl.c
fs/romfs/super.c
fs/super.c
fs/xfs/xfs_super.c
include/linux/blkdev.h
include/linux/fs.h
include/linux/fs_context.h

Simple merge
Simple merge
Simple merge
diff --cc fs/buffer.c
Simple merge
Simple merge
Simple merge
diff --cc fs/ext4/super.c
index cb1ff47af1561c4ed0adfc7c19dcd6cbdc5df0aa,60d2815a0b7ea555cfb18c8d14ce93504b0dba01..73547d2334fd7c3b605cf08b78d7a0eef5018b81
@@@ -7278,8 -7271,8 +7271,8 @@@ static struct file_system_type ext4_fs_
        .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,
 +      .fs_flags               = FS_REQUIRES_DEV | FS_ALLOW_IDMAP | FS_MGTIME,
  };
  MODULE_ALIAS_FS("ext4");
  
diff --cc fs/f2fs/super.c
Simple merge
diff --cc fs/gfs2/super.c
Simple merge
diff --cc fs/inode.c
Simple merge
diff --cc fs/ioctl.c
Simple merge
Simple merge
diff --cc fs/super.c
index e04a403dbffd464e97cad78fa1dac13dd513dbca,ef87103e2a5197b1d4ffe882948d4f86f6752694..692654c2af365f2450284742315a78eb4490065a
@@@ -617,16 -798,12 +812,16 @@@ retry
        return s;
  
  share_extant_sb:
 -      if (user_ns != old->s_user_ns) {
 +      if (user_ns != old->s_user_ns || fc->exclusive) {
                spin_unlock(&sb_lock);
                destroy_unused_super(s);
 +              if (fc->exclusive)
 +                      warnfc(fc, "reusing existing filesystem not allowed");
 +              else
 +                      warnfc(fc, "reusing existing filesystem in another namespace not allowed");
                return ERR_PTR(-EBUSY);
        }
-       if (!grab_super(old))
+       if (!grab_super_dead(old))
                goto retry;
        destroy_unused_super(s);
        return old;
index 4b10edb2c9724c2445094437ea6dd082df2710a2,8fee152924994bd8c708fb981f8280cb113a7951..c79eac048456bd06e79c11d9fadf5d8d5abc02cf
@@@ -2008,8 -2032,8 +2032,8 @@@ static struct file_system_type xfs_fs_t
        .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,
 +      .fs_flags               = FS_REQUIRES_DEV | FS_ALLOW_IDMAP | FS_MGTIME,
  };
  MODULE_ALIAS_FS("xfs");
  
Simple merge
Simple merge
Simple merge