Merge tag 'pull-bd_inode-1' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs
authorLinus Torvalds <torvalds@linux-foundation.org>
Tue, 21 May 2024 16:51:42 +0000 (09:51 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Tue, 21 May 2024 16:51:42 +0000 (09:51 -0700)
Pull bdev bd_inode updates from Al Viro:
 "Replacement of bdev->bd_inode with sane(r) set of primitives by me and
  Yu Kuai"

* tag 'pull-bd_inode-1' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs:
  RIP ->bd_inode
  dasd_format(): killing the last remaining user of ->bd_inode
  nilfs_attach_log_writer(): use ->bd_mapping->host instead of ->bd_inode
  block/bdev.c: use the knowledge of inode/bdev coallocation
  gfs2: more obvious initializations of mapping->host
  fs/buffer.c: massage the remaining users of ->bd_inode to ->bd_mapping
  blk_ioctl_{discard,zeroout}(): we only want ->bd_inode->i_mapping here...
  grow_dev_folio(): we only want ->bd_inode->i_mapping there
  use ->bd_mapping instead of ->bd_inode->i_mapping
  block_device: add a pointer to struct address_space (page cache of bdev)
  missing helpers: bdev_unhash(), bdev_drop()
  block: move two helpers into bdev.c
  block2mtd: prevent direct access of bd_inode
  dm-vdo: use bdev_nr_bytes(bdev) instead of i_size_read(bdev->bd_inode)
  blkdev_write_iter(): saner way to get inode and bdev
  bcachefs: remove dead function bdev_sectors()
  ext4: remove block_device_ejected()
  erofs_buf: store address_space instead of inode
  erofs: switch erofs_bread() to passing offset instead of block number

21 files changed:
1  2 
block/bdev.c
block/blk-zoned.c
block/blk.h
block/fops.c
block/genhd.c
block/ioctl.c
block/partitions/core.c
drivers/md/bcache/super.c
fs/btrfs/disk-io.c
fs/btrfs/volumes.c
fs/buffer.c
fs/erofs/internal.h
fs/erofs/super.c
fs/ext4/super.c
fs/gfs2/glock.c
fs/gfs2/ops_fstype.c
fs/nilfs2/segment.c
include/linux/blk_types.h
include/linux/blkdev.h
include/linux/buffer_head.h
include/linux/jbd2.h

diff --cc block/bdev.c
Simple merge
Simple merge
diff --cc block/blk.h
Simple merge
diff --cc block/fops.c
Simple merge
diff --cc block/genhd.c
Simple merge
diff --cc block/ioctl.c
@@@ -95,12 -95,8 +95,11 @@@ static int compat_blkpg_ioctl(struct bl
  static int blk_ioctl_discard(struct block_device *bdev, blk_mode_t mode,
                unsigned long arg)
  {
 -      uint64_t range[2];
 -      uint64_t start, len, end;
 +      unsigned int bs_mask = bdev_logical_block_size(bdev) - 1;
-       struct inode *inode = bdev->bd_inode;
 +      uint64_t range[2], start, len, end;
 +      struct bio *prev = NULL, *bio;
 +      sector_t sector, nr_sects;
 +      struct blk_plug plug;
        int err;
  
        if (!(mode & BLK_OPEN_WRITE))
        err = truncate_bdev_range(bdev, mode, start, start + len - 1);
        if (err)
                goto fail;
 -      err = blkdev_issue_discard(bdev, start >> 9, len >> 9, GFP_KERNEL);
 +
 +      sector = start >> SECTOR_SHIFT;
 +      nr_sects = len >> SECTOR_SHIFT;
 +
 +      blk_start_plug(&plug);
 +      while (1) {
 +              if (fatal_signal_pending(current)) {
 +                      if (prev)
 +                              bio_await_chain(prev);
 +                      err = -EINTR;
 +                      goto out_unplug;
 +              }
 +              bio = blk_alloc_discard_bio(bdev, &sector, &nr_sects,
 +                              GFP_KERNEL);
 +              if (!bio)
 +                      break;
 +              prev = bio_chain_and_submit(prev, bio);
 +      }
 +      if (prev) {
 +              err = submit_bio_wait(prev);
 +              if (err == -EOPNOTSUPP)
 +                      err = 0;
 +              bio_put(prev);
 +      }
 +out_unplug:
 +      blk_finish_plug(&plug);
  fail:
-       filemap_invalidate_unlock(inode->i_mapping);
+       filemap_invalidate_unlock(bdev->bd_mapping);
        return err;
  }
  
Simple merge
Simple merge
@@@ -3743,9 -3738,10 +3743,9 @@@ static int write_dev_supers(struct btrf
                            struct btrfs_super_block *sb, int max_mirrors)
  {
        struct btrfs_fs_info *fs_info = device->fs_info;
-       struct address_space *mapping = device->bdev->bd_inode->i_mapping;
+       struct address_space *mapping = device->bdev->bd_mapping;
        SHASH_DESC_ON_STACK(shash, fs_info->csum_shash);
        int i;
 -      int errors = 0;
        int ret;
        u64 bytenr, bytenr_orig;
  
@@@ -3861,21 -3855,30 +3861,21 @@@ static int wait_dev_supers(struct btrfs
                    device->commit_total_bytes)
                        break;
  
-               folio = filemap_get_folio(device->bdev->bd_inode->i_mapping,
 -              page = find_get_page(device->bdev->bd_mapping,
 -                                   bytenr >> PAGE_SHIFT);
 -              if (!page) {
 -                      errors++;
 -                      if (i == 0)
 -                              primary_failed = true;
++              folio = filemap_get_folio(device->bdev->bd_mapping,
 +                                        bytenr >> PAGE_SHIFT);
 +              /* If the folio has been removed, then we know it completed. */
 +              if (IS_ERR(folio))
                        continue;
 -              }
 -              /* Page is submitted locked and unlocked once the IO completes */
 -              wait_on_page_locked(page);
 -              if (PageError(page)) {
 -                      errors++;
 -                      if (i == 0)
 -                              primary_failed = true;
 -              }
 -
 -              /* Drop our reference */
 -              put_page(page);
 +              ASSERT(folio_order(folio) == 0);
  
 -              /* Drop the reference from the writing run */
 -              put_page(page);
 +              /* Folio will be unlocked once the write completes. */
 +              folio_wait_locked(folio);
 +              folio_put(folio);
        }
  
 -      /* log error, force error return */
 +      errors += atomic_read(&device->sb_write_errors);
 +      if (errors >= BTRFS_SUPER_PRIMARY_WRITE_ERROR)
 +              primary_failed = true;
        if (primary_failed) {
                btrfs_err(device->fs_info, "error writing primary super block to device %llu",
                          device->devid);
Simple merge
diff --cc fs/buffer.c
Simple merge
Simple merge
Simple merge
diff --cc fs/ext4/super.c
Simple merge
diff --cc fs/gfs2/glock.c
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge