Commit ae85a807 authored by Minchan Kim's avatar Minchan Kim Committed by Linus Torvalds

zram: identify asynchronous IO's return value

For upcoming asynchronous IO like writeback, zram_rw_page should be
aware of that whether requested IO was completed or submitted
successfully, otherwise error.

For the goal, zram_bvec_rw has three return values.

-errno: returns error number
     0: IO request is done synchronously
     1: IO request is issued successfully.

Link: http://lkml.kernel.org/r/1498459987-24562-7-git-send-email-minchan@kernel.orgSigned-off-by: default avatarMinchan Kim <minchan@kernel.org>
Cc: Juneho Choi <juno.choi@lge.com>
Cc: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 1363d466
...@@ -772,7 +772,7 @@ static int zram_bvec_read(struct zram *zram, struct bio_vec *bvec, ...@@ -772,7 +772,7 @@ static int zram_bvec_read(struct zram *zram, struct bio_vec *bvec,
static int __zram_bvec_write(struct zram *zram, struct bio_vec *bvec, u32 index) static int __zram_bvec_write(struct zram *zram, struct bio_vec *bvec, u32 index)
{ {
int ret; int ret = 0;
unsigned long alloced_pages; unsigned long alloced_pages;
unsigned long handle = 0; unsigned long handle = 0;
unsigned int comp_len = 0; unsigned int comp_len = 0;
...@@ -877,7 +877,7 @@ static int __zram_bvec_write(struct zram *zram, struct bio_vec *bvec, u32 index) ...@@ -877,7 +877,7 @@ static int __zram_bvec_write(struct zram *zram, struct bio_vec *bvec, u32 index)
/* Update stats */ /* Update stats */
atomic64_inc(&zram->stats.pages_stored); atomic64_inc(&zram->stats.pages_stored);
return 0; return ret;
} }
static int zram_bvec_write(struct zram *zram, struct bio_vec *bvec, static int zram_bvec_write(struct zram *zram, struct bio_vec *bvec,
...@@ -959,6 +959,11 @@ static void zram_bio_discard(struct zram *zram, u32 index, ...@@ -959,6 +959,11 @@ static void zram_bio_discard(struct zram *zram, u32 index,
} }
} }
/*
* Returns errno if it has some problem. Otherwise return 0 or 1.
* Returns 0 if IO request was done synchronously
* Returns 1 if IO request was successfully submitted.
*/
static int zram_bvec_rw(struct zram *zram, struct bio_vec *bvec, u32 index, static int zram_bvec_rw(struct zram *zram, struct bio_vec *bvec, u32 index,
int offset, bool is_write) int offset, bool is_write)
{ {
...@@ -980,7 +985,7 @@ static int zram_bvec_rw(struct zram *zram, struct bio_vec *bvec, u32 index, ...@@ -980,7 +985,7 @@ static int zram_bvec_rw(struct zram *zram, struct bio_vec *bvec, u32 index,
generic_end_io_acct(rw_acct, &zram->disk->part0, start_time); generic_end_io_acct(rw_acct, &zram->disk->part0, start_time);
if (unlikely(ret)) { if (unlikely(ret < 0)) {
if (!is_write) if (!is_write)
atomic64_inc(&zram->stats.failed_reads); atomic64_inc(&zram->stats.failed_reads);
else else
...@@ -1073,7 +1078,7 @@ static void zram_slot_free_notify(struct block_device *bdev, ...@@ -1073,7 +1078,7 @@ static void zram_slot_free_notify(struct block_device *bdev,
static int zram_rw_page(struct block_device *bdev, sector_t sector, static int zram_rw_page(struct block_device *bdev, sector_t sector,
struct page *page, bool is_write) struct page *page, bool is_write)
{ {
int offset, err = -EIO; int offset, ret;
u32 index; u32 index;
struct zram *zram; struct zram *zram;
struct bio_vec bv; struct bio_vec bv;
...@@ -1082,7 +1087,7 @@ static int zram_rw_page(struct block_device *bdev, sector_t sector, ...@@ -1082,7 +1087,7 @@ static int zram_rw_page(struct block_device *bdev, sector_t sector,
if (!valid_io_request(zram, sector, PAGE_SIZE)) { if (!valid_io_request(zram, sector, PAGE_SIZE)) {
atomic64_inc(&zram->stats.invalid_io); atomic64_inc(&zram->stats.invalid_io);
err = -EINVAL; ret = -EINVAL;
goto out; goto out;
} }
...@@ -1093,7 +1098,7 @@ static int zram_rw_page(struct block_device *bdev, sector_t sector, ...@@ -1093,7 +1098,7 @@ static int zram_rw_page(struct block_device *bdev, sector_t sector,
bv.bv_len = PAGE_SIZE; bv.bv_len = PAGE_SIZE;
bv.bv_offset = 0; bv.bv_offset = 0;
err = zram_bvec_rw(zram, &bv, index, offset, is_write); ret = zram_bvec_rw(zram, &bv, index, offset, is_write);
out: out:
/* /*
* If I/O fails, just return error(ie, non-zero) without * If I/O fails, just return error(ie, non-zero) without
...@@ -1103,9 +1108,20 @@ static int zram_rw_page(struct block_device *bdev, sector_t sector, ...@@ -1103,9 +1108,20 @@ static int zram_rw_page(struct block_device *bdev, sector_t sector,
* bio->bi_end_io does things to handle the error * bio->bi_end_io does things to handle the error
* (e.g., SetPageError, set_page_dirty and extra works). * (e.g., SetPageError, set_page_dirty and extra works).
*/ */
if (err == 0) if (unlikely(ret < 0))
return ret;
switch (ret) {
case 0:
page_endio(page, is_write, 0); page_endio(page, is_write, 0);
return err; break;
case 1:
ret = 0;
break;
default:
WARN_ON(1);
}
return ret;
} }
static void zram_reset_device(struct zram *zram) static void zram_reset_device(struct zram *zram)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment