]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/commitdiff
block: move guard_bio_eod to bio.c
authorChristoph Hellwig <hch@lst.de>
Wed, 25 Mar 2020 15:48:40 +0000 (16:48 +0100)
committerJens Axboe <axboe@kernel.dk>
Wed, 25 Mar 2020 15:50:08 +0000 (09:50 -0600)
This is bio layer functionality and not related to buffer heads.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
block/bio.c
fs/buffer.c
fs/internal.h
include/linux/bio.h

index bc9152977bf0c501b97c814fe2ad3aaba848c0be..11e6aac35092db56d0e31f4967e8fe708b5bc9b4 100644 (file)
@@ -588,6 +588,49 @@ void bio_truncate(struct bio *bio, unsigned new_size)
        bio->bi_iter.bi_size = new_size;
 }
 
+/**
+ * guard_bio_eod - truncate a BIO to fit the block device
+ * @bio:       bio to truncate
+ *
+ * This allows us to do IO even on the odd last sectors of a device, even if the
+ * block size is some multiple of the physical sector size.
+ *
+ * We'll just truncate the bio to the size of the device, and clear the end of
+ * the buffer head manually.  Truly out-of-range accesses will turn into actual
+ * I/O errors, this only handles the "we need to be able to do I/O at the final
+ * sector" case.
+ */
+void guard_bio_eod(struct bio *bio)
+{
+       sector_t maxsector;
+       struct hd_struct *part;
+
+       rcu_read_lock();
+       part = __disk_get_part(bio->bi_disk, bio->bi_partno);
+       if (part)
+               maxsector = part_nr_sects_read(part);
+       else
+               maxsector = get_capacity(bio->bi_disk);
+       rcu_read_unlock();
+
+       if (!maxsector)
+               return;
+
+       /*
+        * If the *whole* IO is past the end of the device,
+        * let it through, and the IO layer will turn it into
+        * an EIO.
+        */
+       if (unlikely(bio->bi_iter.bi_sector >= maxsector))
+               return;
+
+       maxsector -= bio->bi_iter.bi_sector;
+       if (likely((bio->bi_iter.bi_size >> 9) <= maxsector))
+               return;
+
+       bio_truncate(bio, maxsector << 9);
+}
+
 /**
  * bio_put - release a reference to a bio
  * @bio:   bio to release reference to
index b8d28370cfd7f25cb5ed6e44fa7a073547ba5319..3f5758e01e40b4b76f377195eb5376f61e560727 100644 (file)
@@ -3019,49 +3019,6 @@ static void end_bio_bh_io_sync(struct bio *bio)
        bio_put(bio);
 }
 
-/*
- * This allows us to do IO even on the odd last sectors
- * of a device, even if the block size is some multiple
- * of the physical sector size.
- *
- * We'll just truncate the bio to the size of the device,
- * and clear the end of the buffer head manually.
- *
- * Truly out-of-range accesses will turn into actual IO
- * errors, this only handles the "we need to be able to
- * do IO at the final sector" case.
- */
-void guard_bio_eod(struct bio *bio)
-{
-       sector_t maxsector;
-       struct hd_struct *part;
-
-       rcu_read_lock();
-       part = __disk_get_part(bio->bi_disk, bio->bi_partno);
-       if (part)
-               maxsector = part_nr_sects_read(part);
-       else
-               maxsector = get_capacity(bio->bi_disk);
-       rcu_read_unlock();
-
-       if (!maxsector)
-               return;
-
-       /*
-        * If the *whole* IO is past the end of the device,
-        * let it through, and the IO layer will turn it into
-        * an EIO.
-        */
-       if (unlikely(bio->bi_iter.bi_sector >= maxsector))
-               return;
-
-       maxsector -= bio->bi_iter.bi_sector;
-       if (likely((bio->bi_iter.bi_size >> 9) <= maxsector))
-               return;
-
-       bio_truncate(bio, maxsector << 9);
-}
-
 static int submit_bh_wbc(int op, int op_flags, struct buffer_head *bh,
                         enum rw_hint write_hint, struct writeback_control *wbc)
 {
index f3f280b952a3ce831be6d806ffdb7ac813e4a756..4d37912a5587e464116135519a325bff6a1ab20c 100644 (file)
@@ -38,7 +38,6 @@ static inline int __sync_blockdev(struct block_device *bdev, int wait)
 /*
  * buffer.c
  */
-extern void guard_bio_eod(struct bio *bio);
 extern int __block_write_begin_int(struct page *page, loff_t pos, unsigned len,
                get_block_t *get_block, struct iomap *iomap);
 
index 853d92ceee64ed5d89f8900f2235af22b1b6fbe1..a430e9c1c2d2993c83fccfdbb1aa2c7ad52e407f 100644 (file)
@@ -471,6 +471,7 @@ extern struct bio *bio_copy_user_iov(struct request_queue *,
 extern int bio_uncopy_user(struct bio *);
 void zero_fill_bio_iter(struct bio *bio, struct bvec_iter iter);
 void bio_truncate(struct bio *bio, unsigned new_size);
+void guard_bio_eod(struct bio *bio);
 
 static inline void zero_fill_bio(struct bio *bio)
 {