[v2] block: fix the return errno for direct IO
diff mbox series

Message ID 20190412020916.1160-1-yanaijie@huawei.com
State New
Headers show
Series
  • [v2] block: fix the return errno for direct IO
Related show

Commit Message

Jason Yan April 12, 2019, 2:09 a.m. UTC
If the last bio returned is not dio->bio, the status of the bio will
not assigned to dio->bio if it is error. This will cause the whole IO
status wrong.

    ksoftirqd/21-117   [021] ..s.  4017.966090:   8,0    C   N 4883648 [0]
          <idle>-0     [018] ..s.  4017.970888:   8,0    C  WS 4924800 + 1024 [0]
          <idle>-0     [018] ..s.  4017.970909:   8,0    D  WS 4935424 + 1024 [<idle>]
          <idle>-0     [018] ..s.  4017.970924:   8,0    D  WS 4936448 + 321 [<idle>]
    ksoftirqd/21-117   [021] ..s.  4017.995033:   8,0    C   R 4883648 + 336 [65475]
    ksoftirqd/21-117   [021] d.s.  4018.001988: myprobe1: (blkdev_bio_end_io+0x0/0x168) bi_status=7
    ksoftirqd/21-117   [021] d.s.  4018.001992: myprobe: (aio_complete_rw+0x0/0x148) x0=0xffff802f2595ad80 res=0x12a000 res2=0x0

We always have to assign bio->bi_status to dio->bio.bi_status because we
will only check dio->bio.bi_status when we return the whole IO to
the upper layer.

Fixes: 542ff7bf18c6 ("block: new direct I/O implementation")
Cc: Christoph Hellwig <hch@lst.de>
Cc: Jens Axboe <axboe@kernel.dk>
Cc: Ming Lei <ming.lei@redhat.com>
Signed-off-by: Jason Yan <yanaijie@huawei.com>
---

v2: remove white space changes

 fs/block_dev.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

Comments

Ming Lei April 12, 2019, 2:43 a.m. UTC | #1
On Fri, Apr 12, 2019 at 9:53 AM Jason Yan <yanaijie@huawei.com> wrote:
>
> If the last bio returned is not dio->bio, the status of the bio will
> not assigned to dio->bio if it is error. This will cause the whole IO
> status wrong.
>
>     ksoftirqd/21-117   [021] ..s.  4017.966090:   8,0    C   N 4883648 [0]
>           <idle>-0     [018] ..s.  4017.970888:   8,0    C  WS 4924800 + 1024 [0]
>           <idle>-0     [018] ..s.  4017.970909:   8,0    D  WS 4935424 + 1024 [<idle>]
>           <idle>-0     [018] ..s.  4017.970924:   8,0    D  WS 4936448 + 321 [<idle>]
>     ksoftirqd/21-117   [021] ..s.  4017.995033:   8,0    C   R 4883648 + 336 [65475]
>     ksoftirqd/21-117   [021] d.s.  4018.001988: myprobe1: (blkdev_bio_end_io+0x0/0x168) bi_status=7
>     ksoftirqd/21-117   [021] d.s.  4018.001992: myprobe: (aio_complete_rw+0x0/0x148) x0=0xffff802f2595ad80 res=0x12a000 res2=0x0
>
> We always have to assign bio->bi_status to dio->bio.bi_status because we
> will only check dio->bio.bi_status when we return the whole IO to
> the upper layer.
>
> Fixes: 542ff7bf18c6 ("block: new direct I/O implementation")
> Cc: Christoph Hellwig <hch@lst.de>
> Cc: Jens Axboe <axboe@kernel.dk>
> Cc: Ming Lei <ming.lei@redhat.com>
> Signed-off-by: Jason Yan <yanaijie@huawei.com>
> ---
>
> v2: remove white space changes
>
>  fs/block_dev.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/fs/block_dev.c b/fs/block_dev.c
> index 78d3257435c0..24615c76c1d0 100644
> --- a/fs/block_dev.c
> +++ b/fs/block_dev.c
> @@ -307,10 +307,10 @@ static void blkdev_bio_end_io(struct bio *bio)
>         struct blkdev_dio *dio = bio->bi_private;
>         bool should_dirty = dio->should_dirty;
>
> -       if (dio->multi_bio && !atomic_dec_and_test(&dio->ref)) {
> -               if (bio->bi_status && !dio->bio.bi_status)
> -                       dio->bio.bi_status = bio->bi_status;
> -       } else {
> +       if (bio->bi_status && !dio->bio.bi_status)
> +               dio->bio.bi_status = bio->bi_status;
> +
> +       if (!dio->multi_bio || atomic_dec_and_test(&dio->ref)) {
>                 if (!dio->is_sync) {
>                         struct kiocb *iocb = dio->iocb;
>                         ssize_t ret;
> --
> 2.17.2
>

Looks fine:

Reviewed-by: Ming Lei <ming.lei@redhat.com>
Jens Axboe April 12, 2019, 3:22 a.m. UTC | #2
On 4/11/19 8:09 PM, Jason Yan wrote:
> If the last bio returned is not dio->bio, the status of the bio will
> not assigned to dio->bio if it is error. This will cause the whole IO
> status wrong.
> 
>     ksoftirqd/21-117   [021] ..s.  4017.966090:   8,0    C   N 4883648 [0]
>           <idle>-0     [018] ..s.  4017.970888:   8,0    C  WS 4924800 + 1024 [0]
>           <idle>-0     [018] ..s.  4017.970909:   8,0    D  WS 4935424 + 1024 [<idle>]
>           <idle>-0     [018] ..s.  4017.970924:   8,0    D  WS 4936448 + 321 [<idle>]
>     ksoftirqd/21-117   [021] ..s.  4017.995033:   8,0    C   R 4883648 + 336 [65475]
>     ksoftirqd/21-117   [021] d.s.  4018.001988: myprobe1: (blkdev_bio_end_io+0x0/0x168) bi_status=7
>     ksoftirqd/21-117   [021] d.s.  4018.001992: myprobe: (aio_complete_rw+0x0/0x148) x0=0xffff802f2595ad80 res=0x12a000 res2=0x0
> 
> We always have to assign bio->bi_status to dio->bio.bi_status because we
> will only check dio->bio.bi_status when we return the whole IO to
> the upper layer.

Looks good, thanks. Applide for 5.1, marked stable.
Chaitanya Kulkarni April 12, 2019, 3:37 a.m. UTC | #3
Looks good.

Reviewed-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>

On 4/11/19 6:52 PM, Jason Yan wrote:
> If the last bio returned is not dio->bio, the status of the bio will
> not assigned to dio->bio if it is error. This will cause the whole IO
> status wrong.
> 
>      ksoftirqd/21-117   [021] ..s.  4017.966090:   8,0    C   N 4883648 [0]
>            <idle>-0     [018] ..s.  4017.970888:   8,0    C  WS 4924800 + 1024 [0]
>            <idle>-0     [018] ..s.  4017.970909:   8,0    D  WS 4935424 + 1024 [<idle>]
>            <idle>-0     [018] ..s.  4017.970924:   8,0    D  WS 4936448 + 321 [<idle>]
>      ksoftirqd/21-117   [021] ..s.  4017.995033:   8,0    C   R 4883648 + 336 [65475]
>      ksoftirqd/21-117   [021] d.s.  4018.001988: myprobe1: (blkdev_bio_end_io+0x0/0x168) bi_status=7
>      ksoftirqd/21-117   [021] d.s.  4018.001992: myprobe: (aio_complete_rw+0x0/0x148) x0=0xffff802f2595ad80 res=0x12a000 res2=0x0
> 
> We always have to assign bio->bi_status to dio->bio.bi_status because we
> will only check dio->bio.bi_status when we return the whole IO to
> the upper layer.
> 
> Fixes: 542ff7bf18c6 ("block: new direct I/O implementation")
> Cc: Christoph Hellwig <hch@lst.de>
> Cc: Jens Axboe <axboe@kernel.dk>
> Cc: Ming Lei <ming.lei@redhat.com>
> Signed-off-by: Jason Yan <yanaijie@huawei.com>
> ---
> 
> v2: remove white space changes
> 
>   fs/block_dev.c | 8 ++++----
>   1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/fs/block_dev.c b/fs/block_dev.c
> index 78d3257435c0..24615c76c1d0 100644
> --- a/fs/block_dev.c
> +++ b/fs/block_dev.c
> @@ -307,10 +307,10 @@ static void blkdev_bio_end_io(struct bio *bio)
>   	struct blkdev_dio *dio = bio->bi_private;
>   	bool should_dirty = dio->should_dirty;
>   
> -	if (dio->multi_bio && !atomic_dec_and_test(&dio->ref)) {
> -		if (bio->bi_status && !dio->bio.bi_status)
> -			dio->bio.bi_status = bio->bi_status;
> -	} else {
> +	if (bio->bi_status && !dio->bio.bi_status)
> +		dio->bio.bi_status = bio->bi_status;
> +
> +	if (!dio->multi_bio || atomic_dec_and_test(&dio->ref)) {
>   		if (!dio->is_sync) {
>   			struct kiocb *iocb = dio->iocb;
>   			ssize_t ret;
>

Patch
diff mbox series

diff --git a/fs/block_dev.c b/fs/block_dev.c
index 78d3257435c0..24615c76c1d0 100644
--- a/fs/block_dev.c
+++ b/fs/block_dev.c
@@ -307,10 +307,10 @@  static void blkdev_bio_end_io(struct bio *bio)
 	struct blkdev_dio *dio = bio->bi_private;
 	bool should_dirty = dio->should_dirty;
 
-	if (dio->multi_bio && !atomic_dec_and_test(&dio->ref)) {
-		if (bio->bi_status && !dio->bio.bi_status)
-			dio->bio.bi_status = bio->bi_status;
-	} else {
+	if (bio->bi_status && !dio->bio.bi_status)
+		dio->bio.bi_status = bio->bi_status;
+
+	if (!dio->multi_bio || atomic_dec_and_test(&dio->ref)) {
 		if (!dio->is_sync) {
 			struct kiocb *iocb = dio->iocb;
 			ssize_t ret;