Merge tag 'folio-6.0' of git://git.infradead.org/users/willy/pagecache
[platform/kernel/linux-starfive.git] / fs / buffer.c
index 5717d18..55e762a 100644 (file)
@@ -52,7 +52,7 @@
 #include "internal.h"
 
 static int fsync_buffers_list(spinlock_t *lock, struct list_head *list);
-static int submit_bh_wbc(int op, int op_flags, struct buffer_head *bh,
+static int submit_bh_wbc(blk_opf_t opf, struct buffer_head *bh,
                         struct writeback_control *wbc);
 
 #define BH_ENTRY(list) list_entry((list), struct buffer_head, b_assoc_buffers)
@@ -562,7 +562,7 @@ void write_boundary_block(struct block_device *bdev,
        struct buffer_head *bh = __find_get_block(bdev, bblock + 1, blocksize);
        if (bh) {
                if (buffer_dirty(bh))
-                       ll_rw_block(REQ_OP_WRITE, 0, 1, &bh);
+                       ll_rw_block(REQ_OP_WRITE, 1, &bh);
                put_bh(bh);
        }
 }
@@ -1174,7 +1174,7 @@ static struct buffer_head *__bread_slow(struct buffer_head *bh)
        } else {
                get_bh(bh);
                bh->b_end_io = end_buffer_read_sync;
-               submit_bh(REQ_OP_READ, 0, bh);
+               submit_bh(REQ_OP_READ, bh);
                wait_on_buffer(bh);
                if (buffer_uptodate(bh))
                        return bh;
@@ -1342,7 +1342,7 @@ void __breadahead(struct block_device *bdev, sector_t block, unsigned size)
 {
        struct buffer_head *bh = __getblk(bdev, block, size);
        if (likely(bh)) {
-               ll_rw_block(REQ_OP_READ, REQ_RAHEAD, 1, &bh);
+               ll_rw_block(REQ_OP_READ | REQ_RAHEAD, 1, &bh);
                brelse(bh);
        }
 }
@@ -1353,7 +1353,7 @@ void __breadahead_gfp(struct block_device *bdev, sector_t block, unsigned size,
 {
        struct buffer_head *bh = __getblk_gfp(bdev, block, size, gfp);
        if (likely(bh)) {
-               ll_rw_block(REQ_OP_READ, REQ_RAHEAD, 1, &bh);
+               ll_rw_block(REQ_OP_READ | REQ_RAHEAD, 1, &bh);
                brelse(bh);
        }
 }
@@ -1716,7 +1716,7 @@ int __block_write_full_page(struct inode *inode, struct page *page,
        struct buffer_head *bh, *head;
        unsigned int blocksize, bbits;
        int nr_underway = 0;
-       int write_flags = wbc_to_write_flags(wbc);
+       blk_opf_t write_flags = wbc_to_write_flags(wbc);
 
        head = create_page_buffers(page, inode,
                                        (1 << BH_Dirty)|(1 << BH_Uptodate));
@@ -1804,7 +1804,7 @@ int __block_write_full_page(struct inode *inode, struct page *page,
        do {
                struct buffer_head *next = bh->b_this_page;
                if (buffer_async_write(bh)) {
-                       submit_bh_wbc(REQ_OP_WRITE, write_flags, bh, wbc);
+                       submit_bh_wbc(REQ_OP_WRITE | write_flags, bh, wbc);
                        nr_underway++;
                }
                bh = next;
@@ -1858,7 +1858,7 @@ recover:
                struct buffer_head *next = bh->b_this_page;
                if (buffer_async_write(bh)) {
                        clear_buffer_dirty(bh);
-                       submit_bh_wbc(REQ_OP_WRITE, write_flags, bh, wbc);
+                       submit_bh_wbc(REQ_OP_WRITE | write_flags, bh, wbc);
                        nr_underway++;
                }
                bh = next;
@@ -2033,7 +2033,7 @@ int __block_write_begin_int(struct folio *folio, loff_t pos, unsigned len,
                if (!buffer_uptodate(bh) && !buffer_delay(bh) &&
                    !buffer_unwritten(bh) &&
                     (block_start < from || block_end > to)) {
-                       ll_rw_block(REQ_OP_READ, 0, 1, &bh);
+                       ll_rw_block(REQ_OP_READ, 1, &bh);
                        *wait_bh++=bh;
                }
        }
@@ -2337,7 +2337,7 @@ int block_read_full_folio(struct folio *folio, get_block_t *get_block)
                if (buffer_uptodate(bh))
                        end_buffer_async_read(bh, 1);
                else
-                       submit_bh(REQ_OP_READ, 0, bh);
+                       submit_bh(REQ_OP_READ, bh);
        }
        return 0;
 }
@@ -2594,7 +2594,7 @@ int block_truncate_page(struct address_space *mapping,
 
        if (!buffer_uptodate(bh) && !buffer_delay(bh) && !buffer_unwritten(bh)) {
                err = -EIO;
-               ll_rw_block(REQ_OP_READ, 0, 1, &bh);
+               ll_rw_block(REQ_OP_READ, 1, &bh);
                wait_on_buffer(bh);
                /* Uhhuh. Read error. Complain and punt. */
                if (!buffer_uptodate(bh))
@@ -2673,9 +2673,10 @@ static void end_bio_bh_io_sync(struct bio *bio)
        bio_put(bio);
 }
 
-static int submit_bh_wbc(int op, int op_flags, struct buffer_head *bh,
+static int submit_bh_wbc(blk_opf_t opf, struct buffer_head *bh,
                         struct writeback_control *wbc)
 {
+       const enum req_op op = opf & REQ_OP_MASK;
        struct bio *bio;
 
        BUG_ON(!buffer_locked(bh));
@@ -2691,11 +2692,11 @@ static int submit_bh_wbc(int op, int op_flags, struct buffer_head *bh,
                clear_buffer_write_io_error(bh);
 
        if (buffer_meta(bh))
-               op_flags |= REQ_META;
+               opf |= REQ_META;
        if (buffer_prio(bh))
-               op_flags |= REQ_PRIO;
+               opf |= REQ_PRIO;
 
-       bio = bio_alloc(bh->b_bdev, 1, op | op_flags, GFP_NOIO);
+       bio = bio_alloc(bh->b_bdev, 1, opf, GFP_NOIO);
 
        fscrypt_set_bio_crypt_ctx_bh(bio, bh, GFP_NOIO);
 
@@ -2719,22 +2720,21 @@ static int submit_bh_wbc(int op, int op_flags, struct buffer_head *bh,
        return 0;
 }
 
-int submit_bh(int op, int op_flags, struct buffer_head *bh)
+int submit_bh(blk_opf_t opf, struct buffer_head *bh)
 {
-       return submit_bh_wbc(op, op_flags, bh, NULL);
+       return submit_bh_wbc(opf, bh, NULL);
 }
 EXPORT_SYMBOL(submit_bh);
 
 /**
  * ll_rw_block: low-level access to block devices (DEPRECATED)
- * @op: whether to %READ or %WRITE
- * @op_flags: req_flag_bits
+ * @opf: block layer request operation and flags.
  * @nr: number of &struct buffer_heads in the array
  * @bhs: array of pointers to &struct buffer_head
  *
  * ll_rw_block() takes an array of pointers to &struct buffer_heads, and
  * requests an I/O operation on them, either a %REQ_OP_READ or a %REQ_OP_WRITE.
- * @op_flags contains flags modifying the detailed I/O behavior, most notably
+ * @opf contains flags modifying the detailed I/O behavior, most notably
  * %REQ_RAHEAD.
  *
  * This function drops any buffer that it cannot get a lock on (with the
@@ -2751,8 +2751,9 @@ EXPORT_SYMBOL(submit_bh);
  * All of the buffers must be for the same device, and must also be a
  * multiple of the current approved size for the device.
  */
-void ll_rw_block(int op, int op_flags,  int nr, struct buffer_head *bhs[])
+void ll_rw_block(const blk_opf_t opf, int nr, struct buffer_head *bhs[])
 {
+       const enum req_op op = opf & REQ_OP_MASK;
        int i;
 
        for (i = 0; i < nr; i++) {
@@ -2760,18 +2761,18 @@ void ll_rw_block(int op, int op_flags,  int nr, struct buffer_head *bhs[])
 
                if (!trylock_buffer(bh))
                        continue;
-               if (op == WRITE) {
+               if (op == REQ_OP_WRITE) {
                        if (test_clear_buffer_dirty(bh)) {
                                bh->b_end_io = end_buffer_write_sync;
                                get_bh(bh);
-                               submit_bh(op, op_flags, bh);
+                               submit_bh(opf, bh);
                                continue;
                        }
                } else {
                        if (!buffer_uptodate(bh)) {
                                bh->b_end_io = end_buffer_read_sync;
                                get_bh(bh);
-                               submit_bh(op, op_flags, bh);
+                               submit_bh(opf, bh);
                                continue;
                        }
                }
@@ -2780,7 +2781,7 @@ void ll_rw_block(int op, int op_flags,  int nr, struct buffer_head *bhs[])
 }
 EXPORT_SYMBOL(ll_rw_block);
 
-void write_dirty_buffer(struct buffer_head *bh, int op_flags)
+void write_dirty_buffer(struct buffer_head *bh, blk_opf_t op_flags)
 {
        lock_buffer(bh);
        if (!test_clear_buffer_dirty(bh)) {
@@ -2789,7 +2790,7 @@ void write_dirty_buffer(struct buffer_head *bh, int op_flags)
        }
        bh->b_end_io = end_buffer_write_sync;
        get_bh(bh);
-       submit_bh(REQ_OP_WRITE, op_flags, bh);
+       submit_bh(REQ_OP_WRITE | op_flags, bh);
 }
 EXPORT_SYMBOL(write_dirty_buffer);
 
@@ -2798,7 +2799,7 @@ EXPORT_SYMBOL(write_dirty_buffer);
  * and then start new I/O and then wait upon it.  The caller must have a ref on
  * the buffer_head.
  */
-int __sync_dirty_buffer(struct buffer_head *bh, int op_flags)
+int __sync_dirty_buffer(struct buffer_head *bh, blk_opf_t op_flags)
 {
        int ret = 0;
 
@@ -2816,7 +2817,7 @@ int __sync_dirty_buffer(struct buffer_head *bh, int op_flags)
 
                get_bh(bh);
                bh->b_end_io = end_buffer_write_sync;
-               ret = submit_bh(REQ_OP_WRITE, op_flags, bh);
+               ret = submit_bh(REQ_OP_WRITE | op_flags, bh);
                wait_on_buffer(bh);
                if (!ret && !buffer_uptodate(bh))
                        ret = -EIO;
@@ -3044,7 +3045,7 @@ int bh_submit_read(struct buffer_head *bh)
 
        get_bh(bh);
        bh->b_end_io = end_buffer_read_sync;
-       submit_bh(REQ_OP_READ, 0, bh);
+       submit_bh(REQ_OP_READ, bh);
        wait_on_buffer(bh);
        if (buffer_uptodate(bh))
                return 0;