mirror of
git://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs.git
synced 2026-11-05 00:52:57 +01:00
Immutable biovecs are going to require an explicit iterator. To implement immutable bvecs, a later patch is going to add a bi_bvec_done member to this struct; for now, this patch effectively just renames things. Signed-off-by: Kent Overstreet <[email protected]> Cc: Jens Axboe <[email protected]> Cc: Geert Uytterhoeven <[email protected]> Cc: Benjamin Herrenschmidt <[email protected]> Cc: Paul Mackerras <[email protected]> Cc: "Ed L. Cashin" <[email protected]> Cc: Nick Piggin <[email protected]> Cc: Lars Ellenberg <[email protected]> Cc: Jiri Kosina <[email protected]> Cc: Matthew Wilcox <[email protected]> Cc: Geoff Levand <[email protected]> Cc: Yehuda Sadeh <[email protected]> Cc: Sage Weil <[email protected]> Cc: Alex Elder <[email protected]> Cc: [email protected] Cc: Joshua Morris <[email protected]> Cc: Philip Kelleher <[email protected]> Cc: Rusty Russell <[email protected]> Cc: "Michael S. Tsirkin" <[email protected]> Cc: Konrad Rzeszutek Wilk <[email protected]> Cc: Jeremy Fitzhardinge <[email protected]> Cc: Neil Brown <[email protected]> Cc: Alasdair Kergon <[email protected]> Cc: Mike Snitzer <[email protected]> Cc: [email protected] Cc: Martin Schwidefsky <[email protected]> Cc: Heiko Carstens <[email protected]> Cc: [email protected] Cc: Boaz Harrosh <[email protected]> Cc: Benny Halevy <[email protected]> Cc: "James E.J. Bottomley" <[email protected]> Cc: Greg Kroah-Hartman <[email protected]> Cc: "Nicholas A. Bellinger" <[email protected]> Cc: Alexander Viro <[email protected]> Cc: Chris Mason <[email protected]> Cc: "Theodore Ts'o" <[email protected]> Cc: Andreas Dilger <[email protected]> Cc: Jaegeuk Kim <[email protected]> Cc: Steven Whitehouse <[email protected]> Cc: Dave Kleikamp <[email protected]> Cc: Joern Engel <[email protected]> Cc: Prasad Joshi <[email protected]> Cc: Trond Myklebust <[email protected]> Cc: KONISHI Ryusuke <[email protected]> Cc: Mark Fasheh <[email protected]> Cc: Joel Becker <[email protected]> Cc: Ben Myers <[email protected]> Cc: [email protected] Cc: Steven Rostedt <[email protected]> Cc: Frederic Weisbecker <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Len Brown <[email protected]> Cc: Pavel Machek <[email protected]> Cc: "Rafael J. Wysocki" <[email protected]> Cc: Herton Ronaldo Krzesinski <[email protected]> Cc: Ben Hutchings <[email protected]> Cc: Andrew Morton <[email protected]> Cc: Guo Chao <[email protected]> Cc: Tejun Heo <[email protected]> Cc: Asai Thambi S P <[email protected]> Cc: Selvan Mani <[email protected]> Cc: Sam Bradshaw <[email protected]> Cc: Wei Yongjun <[email protected]> Cc: "Roger Pau Monné" <[email protected]> Cc: Jan Beulich <[email protected]> Cc: Stefano Stabellini <[email protected]> Cc: Ian Campbell <[email protected]> Cc: Sebastian Ott <[email protected]> Cc: Christian Borntraeger <[email protected]> Cc: Minchan Kim <[email protected]> Cc: Jiang Liu <[email protected]> Cc: Nitin Gupta <[email protected]> Cc: Jerome Marchand <[email protected]> Cc: Joe Perches <[email protected]> Cc: Peng Tao <[email protected]> Cc: Andy Adamson <[email protected]> Cc: fanchaoting <[email protected]> Cc: Jie Liu <[email protected]> Cc: Sunil Mushran <[email protected]> Cc: "Martin K. Petersen" <[email protected]> Cc: Namjae Jeon <[email protected]> Cc: Pankaj Kumar <[email protected]> Cc: Dan Magenheimer <[email protected]> Cc: Mel Gorman <[email protected]>6
104 lines
2.4 KiB
C
104 lines
2.4 KiB
C
/*
|
|
* This file provides functions for block I/O operations on swap/file.
|
|
*
|
|
* Copyright (C) 1998,2001-2005 Pavel Machek <[email protected]>
|
|
* Copyright (C) 2006 Rafael J. Wysocki <[email protected]>
|
|
*
|
|
* This file is released under the GPLv2.
|
|
*/
|
|
|
|
#include <linux/bio.h>
|
|
#include <linux/kernel.h>
|
|
#include <linux/pagemap.h>
|
|
#include <linux/swap.h>
|
|
|
|
#include "power.h"
|
|
|
|
/**
|
|
* submit - submit BIO request.
|
|
* @rw: READ or WRITE.
|
|
* @off physical offset of page.
|
|
* @page: page we're reading or writing.
|
|
* @bio_chain: list of pending biod (for async reading)
|
|
*
|
|
* Straight from the textbook - allocate and initialize the bio.
|
|
* If we're reading, make sure the page is marked as dirty.
|
|
* Then submit it and, if @bio_chain == NULL, wait.
|
|
*/
|
|
static int submit(int rw, struct block_device *bdev, sector_t sector,
|
|
struct page *page, struct bio **bio_chain)
|
|
{
|
|
const int bio_rw = rw | REQ_SYNC;
|
|
struct bio *bio;
|
|
|
|
bio = bio_alloc(__GFP_WAIT | __GFP_HIGH, 1);
|
|
bio->bi_iter.bi_sector = sector;
|
|
bio->bi_bdev = bdev;
|
|
bio->bi_end_io = end_swap_bio_read;
|
|
|
|
if (bio_add_page(bio, page, PAGE_SIZE, 0) < PAGE_SIZE) {
|
|
printk(KERN_ERR "PM: Adding page to bio failed at %llu\n",
|
|
(unsigned long long)sector);
|
|
bio_put(bio);
|
|
return -EFAULT;
|
|
}
|
|
|
|
lock_page(page);
|
|
bio_get(bio);
|
|
|
|
if (bio_chain == NULL) {
|
|
submit_bio(bio_rw, bio);
|
|
wait_on_page_locked(page);
|
|
if (rw == READ)
|
|
bio_set_pages_dirty(bio);
|
|
bio_put(bio);
|
|
} else {
|
|
if (rw == READ)
|
|
get_page(page); /* These pages are freed later */
|
|
bio->bi_private = *bio_chain;
|
|
*bio_chain = bio;
|
|
submit_bio(bio_rw, bio);
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
int hib_bio_read_page(pgoff_t page_off, void *addr, struct bio **bio_chain)
|
|
{
|
|
return submit(READ, hib_resume_bdev, page_off * (PAGE_SIZE >> 9),
|
|
virt_to_page(addr), bio_chain);
|
|
}
|
|
|
|
int hib_bio_write_page(pgoff_t page_off, void *addr, struct bio **bio_chain)
|
|
{
|
|
return submit(WRITE, hib_resume_bdev, page_off * (PAGE_SIZE >> 9),
|
|
virt_to_page(addr), bio_chain);
|
|
}
|
|
|
|
int hib_wait_on_bio_chain(struct bio **bio_chain)
|
|
{
|
|
struct bio *bio;
|
|
struct bio *next_bio;
|
|
int ret = 0;
|
|
|
|
if (bio_chain == NULL)
|
|
return 0;
|
|
|
|
bio = *bio_chain;
|
|
if (bio == NULL)
|
|
return 0;
|
|
while (bio) {
|
|
struct page *page;
|
|
|
|
next_bio = bio->bi_private;
|
|
page = bio->bi_io_vec[0].bv_page;
|
|
wait_on_page_locked(page);
|
|
if (!PageUptodate(page) || PageError(page))
|
|
ret = -EIO;
|
|
put_page(page);
|
|
bio_put(bio);
|
|
bio = next_bio;
|
|
}
|
|
*bio_chain = NULL;
|
|
return ret;
|
|
}
|