diff mbox series

[RFC,v3,2/2] pmem: enable pmem_submit_bio for asynchronous flush

Message ID 20220111161937.56272-3-pankaj.gupta.linux@gmail.com (mailing list archive)
State New, archived
Headers show
Series virtio-pmem: Asynchronous flush | expand

Commit Message

Pankaj Gupta Jan. 11, 2022, 4:19 p.m. UTC
Return from "pmem_submit_bio" when asynchronous flush is
still in progress in other context.

Signed-off-by: Pankaj Gupta <pankaj.gupta.linux@gmail.com>
---
 drivers/nvdimm/pmem.c        | 15 ++++++++++++---
 drivers/nvdimm/region_devs.c |  4 +++-
 2 files changed, 15 insertions(+), 4 deletions(-)

Comments

Dan Williams Feb. 16, 2022, 3:34 a.m. UTC | #1
On Tue, Jan 11, 2022 at 8:21 AM Pankaj Gupta
<pankaj.gupta.linux@gmail.com> wrote:
>
> Return from "pmem_submit_bio" when asynchronous flush is
> still in progress in other context.
>
> Signed-off-by: Pankaj Gupta <pankaj.gupta.linux@gmail.com>
> ---
>  drivers/nvdimm/pmem.c        | 15 ++++++++++++---
>  drivers/nvdimm/region_devs.c |  4 +++-
>  2 files changed, 15 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/nvdimm/pmem.c b/drivers/nvdimm/pmem.c
> index fe7ece1534e1..f20e30277a68 100644
> --- a/drivers/nvdimm/pmem.c
> +++ b/drivers/nvdimm/pmem.c
> @@ -201,8 +201,12 @@ static void pmem_submit_bio(struct bio *bio)
>         struct pmem_device *pmem = bio->bi_bdev->bd_disk->private_data;
>         struct nd_region *nd_region = to_region(pmem);
>
> -       if (bio->bi_opf & REQ_PREFLUSH)
> +       if (bio->bi_opf & REQ_PREFLUSH) {
>                 ret = nvdimm_flush(nd_region, bio);
> +               /* asynchronous flush completes in other context */

I think a negative error code is a confusing way to capture the case
of "bio successfully coalesced to previously pending flush request.
Perhaps reserve negative codes for failure, 0 for synchronously
completed, and > 0 for coalesced flush request.

> +               if (ret == -EINPROGRESS)
> +                       return;
> +       }
>
>         do_acct = blk_queue_io_stat(bio->bi_bdev->bd_disk->queue);
>         if (do_acct)
> @@ -222,13 +226,18 @@ static void pmem_submit_bio(struct bio *bio)
>         if (do_acct)
>                 bio_end_io_acct(bio, start);
>
> -       if (bio->bi_opf & REQ_FUA)
> +       if (bio->bi_opf & REQ_FUA) {
>                 ret = nvdimm_flush(nd_region, bio);
> +               /* asynchronous flush completes in other context */
> +               if (ret == -EINPROGRESS)
> +                       return;
> +       }
>
>         if (ret)
>                 bio->bi_status = errno_to_blk_status(ret);
>
> -       bio_endio(bio);
> +       if (bio)
> +               bio_endio(bio);
>  }
>
>  static int pmem_rw_page(struct block_device *bdev, sector_t sector,
> diff --git a/drivers/nvdimm/region_devs.c b/drivers/nvdimm/region_devs.c
> index 9ccf3d608799..8512d2eaed4e 100644
> --- a/drivers/nvdimm/region_devs.c
> +++ b/drivers/nvdimm/region_devs.c
> @@ -1190,7 +1190,9 @@ int nvdimm_flush(struct nd_region *nd_region, struct bio *bio)
>         if (!nd_region->flush)
>                 rc = generic_nvdimm_flush(nd_region);
>         else {
> -               if (nd_region->flush(nd_region, bio))
> +               rc = nd_region->flush(nd_region, bio);
> +               /* ongoing flush in other context */
> +               if (rc && rc != -EINPROGRESS)
>                         rc = -EIO;

Why change this to -EIO vs just let the error code through untranslated?

>         }
>
> --
> 2.25.1
>
>
Pankaj Gupta Feb. 16, 2022, 8:39 a.m. UTC | #2
> >
> > Return from "pmem_submit_bio" when asynchronous flush is
> > still in progress in other context.
> >
> > Signed-off-by: Pankaj Gupta <pankaj.gupta.linux@gmail.com>
> > ---
> >  drivers/nvdimm/pmem.c        | 15 ++++++++++++---
> >  drivers/nvdimm/region_devs.c |  4 +++-
> >  2 files changed, 15 insertions(+), 4 deletions(-)
> >
> > diff --git a/drivers/nvdimm/pmem.c b/drivers/nvdimm/pmem.c
> > index fe7ece1534e1..f20e30277a68 100644
> > --- a/drivers/nvdimm/pmem.c
> > +++ b/drivers/nvdimm/pmem.c
> > @@ -201,8 +201,12 @@ static void pmem_submit_bio(struct bio *bio)
> >         struct pmem_device *pmem = bio->bi_bdev->bd_disk->private_data;
> >         struct nd_region *nd_region = to_region(pmem);
> >
> > -       if (bio->bi_opf & REQ_PREFLUSH)
> > +       if (bio->bi_opf & REQ_PREFLUSH) {
> >                 ret = nvdimm_flush(nd_region, bio);
> > +               /* asynchronous flush completes in other context */
>
> I think a negative error code is a confusing way to capture the case
> of "bio successfully coalesced to previously pending flush request.
> Perhaps reserve negative codes for failure, 0 for synchronously
> completed, and > 0 for coalesced flush request.

Yes. I implemented this way previously, will revert it to. Thanks!

>
> > +               if (ret == -EINPROGRESS)
> > +                       return;
> > +       }
> >
> >         do_acct = blk_queue_io_stat(bio->bi_bdev->bd_disk->queue);
> >         if (do_acct)
> > @@ -222,13 +226,18 @@ static void pmem_submit_bio(struct bio *bio)
> >         if (do_acct)
> >                 bio_end_io_acct(bio, start);
> >
> > -       if (bio->bi_opf & REQ_FUA)
> > +       if (bio->bi_opf & REQ_FUA) {
> >                 ret = nvdimm_flush(nd_region, bio);
> > +               /* asynchronous flush completes in other context */
> > +               if (ret == -EINPROGRESS)
> > +                       return;
> > +       }
> >
> >         if (ret)
> >                 bio->bi_status = errno_to_blk_status(ret);
> >
> > -       bio_endio(bio);
> > +       if (bio)
> > +               bio_endio(bio);
> >  }
> >
> >  static int pmem_rw_page(struct block_device *bdev, sector_t sector,
> > diff --git a/drivers/nvdimm/region_devs.c b/drivers/nvdimm/region_devs.c
> > index 9ccf3d608799..8512d2eaed4e 100644
> > --- a/drivers/nvdimm/region_devs.c
> > +++ b/drivers/nvdimm/region_devs.c
> > @@ -1190,7 +1190,9 @@ int nvdimm_flush(struct nd_region *nd_region, struct bio *bio)
> >         if (!nd_region->flush)
> >                 rc = generic_nvdimm_flush(nd_region);
> >         else {
> > -               if (nd_region->flush(nd_region, bio))
> > +               rc = nd_region->flush(nd_region, bio);
> > +               /* ongoing flush in other context */
> > +               if (rc && rc != -EINPROGRESS)
> >                         rc = -EIO;
>
> Why change this to -EIO vs just let the error code through untranslated?

The reason was to be generic error code instead of returning host side
return codes to guest?

Thanks!
Pankaj
>
> >         }
> >
> > --
> > 2.25.1
> >
> >
Dan Williams Feb. 16, 2022, 4:25 p.m. UTC | #3
On Wed, Feb 16, 2022 at 12:39 AM Pankaj Gupta
<pankaj.gupta.linux@gmail.com> wrote:
>
> > >
> > > Return from "pmem_submit_bio" when asynchronous flush is
> > > still in progress in other context.
> > >
> > > Signed-off-by: Pankaj Gupta <pankaj.gupta.linux@gmail.com>
> > > ---
> > >  drivers/nvdimm/pmem.c        | 15 ++++++++++++---
> > >  drivers/nvdimm/region_devs.c |  4 +++-
> > >  2 files changed, 15 insertions(+), 4 deletions(-)
> > >
> > > diff --git a/drivers/nvdimm/pmem.c b/drivers/nvdimm/pmem.c
> > > index fe7ece1534e1..f20e30277a68 100644
> > > --- a/drivers/nvdimm/pmem.c
> > > +++ b/drivers/nvdimm/pmem.c
> > > @@ -201,8 +201,12 @@ static void pmem_submit_bio(struct bio *bio)
> > >         struct pmem_device *pmem = bio->bi_bdev->bd_disk->private_data;
> > >         struct nd_region *nd_region = to_region(pmem);
> > >
> > > -       if (bio->bi_opf & REQ_PREFLUSH)
> > > +       if (bio->bi_opf & REQ_PREFLUSH) {
> > >                 ret = nvdimm_flush(nd_region, bio);
> > > +               /* asynchronous flush completes in other context */
> >
> > I think a negative error code is a confusing way to capture the case
> > of "bio successfully coalesced to previously pending flush request.
> > Perhaps reserve negative codes for failure, 0 for synchronously
> > completed, and > 0 for coalesced flush request.
>
> Yes. I implemented this way previously, will revert it to. Thanks!
>
> >
> > > +               if (ret == -EINPROGRESS)
> > > +                       return;
> > > +       }
> > >
> > >         do_acct = blk_queue_io_stat(bio->bi_bdev->bd_disk->queue);
> > >         if (do_acct)
> > > @@ -222,13 +226,18 @@ static void pmem_submit_bio(struct bio *bio)
> > >         if (do_acct)
> > >                 bio_end_io_acct(bio, start);
> > >
> > > -       if (bio->bi_opf & REQ_FUA)
> > > +       if (bio->bi_opf & REQ_FUA) {
> > >                 ret = nvdimm_flush(nd_region, bio);
> > > +               /* asynchronous flush completes in other context */
> > > +               if (ret == -EINPROGRESS)
> > > +                       return;
> > > +       }
> > >
> > >         if (ret)
> > >                 bio->bi_status = errno_to_blk_status(ret);
> > >
> > > -       bio_endio(bio);
> > > +       if (bio)
> > > +               bio_endio(bio);
> > >  }
> > >
> > >  static int pmem_rw_page(struct block_device *bdev, sector_t sector,
> > > diff --git a/drivers/nvdimm/region_devs.c b/drivers/nvdimm/region_devs.c
> > > index 9ccf3d608799..8512d2eaed4e 100644
> > > --- a/drivers/nvdimm/region_devs.c
> > > +++ b/drivers/nvdimm/region_devs.c
> > > @@ -1190,7 +1190,9 @@ int nvdimm_flush(struct nd_region *nd_region, struct bio *bio)
> > >         if (!nd_region->flush)
> > >                 rc = generic_nvdimm_flush(nd_region);
> > >         else {
> > > -               if (nd_region->flush(nd_region, bio))
> > > +               rc = nd_region->flush(nd_region, bio);
> > > +               /* ongoing flush in other context */
> > > +               if (rc && rc != -EINPROGRESS)
> > >                         rc = -EIO;
> >
> > Why change this to -EIO vs just let the error code through untranslated?
>
> The reason was to be generic error code instead of returning host side
> return codes to guest?

Ok, maybe a comment to indicate the need to avoid exposing these error
codes toa guest so someone does not ask the same question in the
future?
Pankaj Gupta Feb. 16, 2022, 5:01 p.m. UTC | #4
> > > > Return from "pmem_submit_bio" when asynchronous flush is
> > > > still in progress in other context.
> > > >
> > > > Signed-off-by: Pankaj Gupta <pankaj.gupta.linux@gmail.com>
> > > > ---
> > > >  drivers/nvdimm/pmem.c        | 15 ++++++++++++---
> > > >  drivers/nvdimm/region_devs.c |  4 +++-
> > > >  2 files changed, 15 insertions(+), 4 deletions(-)
> > > >
> > > > diff --git a/drivers/nvdimm/pmem.c b/drivers/nvdimm/pmem.c
> > > > index fe7ece1534e1..f20e30277a68 100644
> > > > --- a/drivers/nvdimm/pmem.c
> > > > +++ b/drivers/nvdimm/pmem.c
> > > > @@ -201,8 +201,12 @@ static void pmem_submit_bio(struct bio *bio)
> > > >         struct pmem_device *pmem = bio->bi_bdev->bd_disk->private_data;
> > > >         struct nd_region *nd_region = to_region(pmem);
> > > >
> > > > -       if (bio->bi_opf & REQ_PREFLUSH)
> > > > +       if (bio->bi_opf & REQ_PREFLUSH) {
> > > >                 ret = nvdimm_flush(nd_region, bio);
> > > > +               /* asynchronous flush completes in other context */
> > >
> > > I think a negative error code is a confusing way to capture the case
> > > of "bio successfully coalesced to previously pending flush request.
> > > Perhaps reserve negative codes for failure, 0 for synchronously
> > > completed, and > 0 for coalesced flush request.
> >
> > Yes. I implemented this way previously, will revert it to. Thanks!
> >
> > >
> > > > +               if (ret == -EINPROGRESS)
> > > > +                       return;
> > > > +       }
> > > >
> > > >         do_acct = blk_queue_io_stat(bio->bi_bdev->bd_disk->queue);
> > > >         if (do_acct)
> > > > @@ -222,13 +226,18 @@ static void pmem_submit_bio(struct bio *bio)
> > > >         if (do_acct)
> > > >                 bio_end_io_acct(bio, start);
> > > >
> > > > -       if (bio->bi_opf & REQ_FUA)
> > > > +       if (bio->bi_opf & REQ_FUA) {
> > > >                 ret = nvdimm_flush(nd_region, bio);
> > > > +               /* asynchronous flush completes in other context */
> > > > +               if (ret == -EINPROGRESS)
> > > > +                       return;
> > > > +       }
> > > >
> > > >         if (ret)
> > > >                 bio->bi_status = errno_to_blk_status(ret);
> > > >
> > > > -       bio_endio(bio);
> > > > +       if (bio)
> > > > +               bio_endio(bio);
> > > >  }
> > > >
> > > >  static int pmem_rw_page(struct block_device *bdev, sector_t sector,
> > > > diff --git a/drivers/nvdimm/region_devs.c b/drivers/nvdimm/region_devs.c
> > > > index 9ccf3d608799..8512d2eaed4e 100644
> > > > --- a/drivers/nvdimm/region_devs.c
> > > > +++ b/drivers/nvdimm/region_devs.c
> > > > @@ -1190,7 +1190,9 @@ int nvdimm_flush(struct nd_region *nd_region, struct bio *bio)
> > > >         if (!nd_region->flush)
> > > >                 rc = generic_nvdimm_flush(nd_region);
> > > >         else {
> > > > -               if (nd_region->flush(nd_region, bio))
> > > > +               rc = nd_region->flush(nd_region, bio);
> > > > +               /* ongoing flush in other context */
> > > > +               if (rc && rc != -EINPROGRESS)
> > > >                         rc = -EIO;
> > >
> > > Why change this to -EIO vs just let the error code through untranslated?
> >
> > The reason was to be generic error code instead of returning host side
> > return codes to guest?
>
> Ok, maybe a comment to indicate the need to avoid exposing these error
> codes toa guest so someone does not ask the same question in the
> future?

Sure.

Thanks,
Pankaj
diff mbox series

Patch

diff --git a/drivers/nvdimm/pmem.c b/drivers/nvdimm/pmem.c
index fe7ece1534e1..f20e30277a68 100644
--- a/drivers/nvdimm/pmem.c
+++ b/drivers/nvdimm/pmem.c
@@ -201,8 +201,12 @@  static void pmem_submit_bio(struct bio *bio)
 	struct pmem_device *pmem = bio->bi_bdev->bd_disk->private_data;
 	struct nd_region *nd_region = to_region(pmem);
 
-	if (bio->bi_opf & REQ_PREFLUSH)
+	if (bio->bi_opf & REQ_PREFLUSH) {
 		ret = nvdimm_flush(nd_region, bio);
+		/* asynchronous flush completes in other context */
+		if (ret == -EINPROGRESS)
+			return;
+	}
 
 	do_acct = blk_queue_io_stat(bio->bi_bdev->bd_disk->queue);
 	if (do_acct)
@@ -222,13 +226,18 @@  static void pmem_submit_bio(struct bio *bio)
 	if (do_acct)
 		bio_end_io_acct(bio, start);
 
-	if (bio->bi_opf & REQ_FUA)
+	if (bio->bi_opf & REQ_FUA) {
 		ret = nvdimm_flush(nd_region, bio);
+		/* asynchronous flush completes in other context */
+		if (ret == -EINPROGRESS)
+			return;
+	}
 
 	if (ret)
 		bio->bi_status = errno_to_blk_status(ret);
 
-	bio_endio(bio);
+	if (bio)
+		bio_endio(bio);
 }
 
 static int pmem_rw_page(struct block_device *bdev, sector_t sector,
diff --git a/drivers/nvdimm/region_devs.c b/drivers/nvdimm/region_devs.c
index 9ccf3d608799..8512d2eaed4e 100644
--- a/drivers/nvdimm/region_devs.c
+++ b/drivers/nvdimm/region_devs.c
@@ -1190,7 +1190,9 @@  int nvdimm_flush(struct nd_region *nd_region, struct bio *bio)
 	if (!nd_region->flush)
 		rc = generic_nvdimm_flush(nd_region);
 	else {
-		if (nd_region->flush(nd_region, bio))
+		rc = nd_region->flush(nd_region, bio);
+		/* ongoing flush in other context */
+		if (rc && rc != -EINPROGRESS)
 			rc = -EIO;
 	}