All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Sterba <dsterba@suse.cz>
To: Christoph Hellwig <hch@lst.de>
Cc: Nikolay Borisov <nborisov@suse.com>,
	Josef Bacik <josef@toxicpanda.com>,
	David Sterba <dsterba@suse.com>,
	linux-btrfs@vger.kernel.org
Subject: Re: [PATCH 3/3] btrfs: pass the btrfs_bio_ctrl to submit_one_bio
Date: Mon, 6 Jun 2022 22:23:22 +0200	[thread overview]
Message-ID: <20220606202322.GE20633@twin.jikos.cz> (raw)
In-Reply-To: <20220606162929.GA10835@lst.de>

On Mon, Jun 06, 2022 at 06:29:29PM +0200, Christoph Hellwig wrote:
> On Mon, Jun 06, 2022 at 01:41:50PM +0300, Nikolay Borisov wrote:
> >> +static void submit_one_bio(struct btrfs_bio_ctrl *bio_ctrl)
> >> +{
> >> +	if (bio_ctrl->bio)
> >> +		__submit_one_bio(bio_ctrl);
> >>   }
> >
> > Why do you need a function just to put an if in it, just move this atop 
> > __submit_one_bio :
> >
> > if (!bio_ctrl->bio)
> >     return
> >
> > and rename it to submit_one_bio.
> 
> Because just moving it to the top will lead to null pointer dereferences.
> I'd also have to move some initialization down.  Based on that the
> wrapper seems cleaner and safer to me.

I don't see much reason to have the safe and unsafe variants, it's all
for internal use in one file, also there's only one real instance where
__submit_one_bio can be used.  I'd expect a normal and __ variant for
some public API. Moving the initialization does not seem to be making
the code hard to read, so I'd apply this diff on top of your patch:

--- a/fs/btrfs/extent_io.c
+++ b/fs/btrfs/extent_io.c
@@ -179,11 +179,18 @@ static int add_extent_changeset(struct extent_state *state, u32 bits,
        return ret;
 }
 
-static void __submit_one_bio(struct btrfs_bio_ctrl *bio_ctrl)
+static void submit_one_bio(struct btrfs_bio_ctrl *bio_ctrl)
 {
-       struct bio *bio = bio_ctrl->bio;
-       struct inode *inode = bio_first_page_all(bio)->mapping->host;
-       int mirror_num = bio_ctrl->mirror_num;
+       struct bio *bio;
+       struct inode *inode;
+       int mirror_num;
+
+       if (!bio_ctrl->bio)
+               return;
+
+       bio = bio_ctrl->bio;
+       inode = bio_first_page_all(bio)->mapping->host;
+       mirror_num = bio_ctrl->mirror_num;
 
        /* Caller should ensure the bio has at least some range added */
        ASSERT(bio->bi_iter.bi_size);
@@ -200,12 +207,6 @@ static void __submit_one_bio(struct btrfs_bio_ctrl *bio_ctrl)
        bio_ctrl->bio = NULL;
 }
 
-static void submit_one_bio(struct btrfs_bio_ctrl *bio_ctrl)
-{
-       if (bio_ctrl->bio)
-               __submit_one_bio(bio_ctrl);
-}
-
 /*
  * Submit or fail the current bio in an extent_page_data structure.
  */
@@ -223,7 +224,7 @@ static void submit_write_bio(struct extent_page_data *epd, int ret)
                /* The bio is owned by the bi_end_io handler now */
                epd->bio_ctrl.bio = NULL;
        } else {
-               __submit_one_bio(&epd->bio_ctrl);
+               submit_one_bio(&epd->bio_ctrl);
        }
 }
---

  reply	other threads:[~2022-06-06 20:29 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-03  7:11 extent_io bio submission cleanup Christoph Hellwig
2022-06-03  7:11 ` [PATCH 1/3] btrfs: don't use bio->bi_private to pass the inode to submit_one_bio Christoph Hellwig
2022-06-03 10:33   ` Qu Wenruo
2022-06-03  7:11 ` [PATCH 2/3] btrfs: merge end_write_bio and flush_write_bio Christoph Hellwig
2022-06-03 10:40   ` Qu Wenruo
2022-06-03  7:11 ` [PATCH 3/3] btrfs: pass the btrfs_bio_ctrl to submit_one_bio Christoph Hellwig
2022-06-04 22:31   ` Qu Wenruo
2022-06-06  6:30     ` Christoph Hellwig
2022-06-06 10:41   ` Nikolay Borisov
2022-06-06 16:29     ` Christoph Hellwig
2022-06-06 20:23       ` David Sterba [this message]
2022-06-06 20:26 ` extent_io bio submission cleanup David Sterba

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220606202322.GE20633@twin.jikos.cz \
    --to=dsterba@suse.cz \
    --cc=dsterba@suse.com \
    --cc=hch@lst.de \
    --cc=josef@toxicpanda.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=nborisov@suse.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.