diff mbox series

[05/15] btrfs: clarify btrfs_lookup_bio_sums documentation

Message ID 2ee5f090b52dc23569bf94a5a2609dfc49ac4a4b.1583789410.git.osandov@fb.com (mailing list archive)
State New, archived
Headers show
Series btrfs: read repair/direct I/O improvements | expand

Commit Message

Omar Sandoval March 9, 2020, 9:32 p.m. UTC
From: Omar Sandoval <osandov@fb.com>

Fix a couple of issues in the btrfs_lookup_bio_sums documentation:

* The bio doesn't need to be a btrfs_io_bio if dst was provided. Move
  the declaration in the code to make that clear, too.
* dst must be large enough to hold nblocks * csum_size, not just
  csum_size.

Signed-off-by: Omar Sandoval <osandov@fb.com>
---
 fs/btrfs/file-item.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

Comments

Josef Bacik March 11, 2020, 5:56 p.m. UTC | #1
On 3/9/20 5:32 PM, Omar Sandoval wrote:
> From: Omar Sandoval <osandov@fb.com>
> 
> Fix a couple of issues in the btrfs_lookup_bio_sums documentation:
> 
> * The bio doesn't need to be a btrfs_io_bio if dst was provided. Move
>    the declaration in the code to make that clear, too.
> * dst must be large enough to hold nblocks * csum_size, not just
>    csum_size.
> 
> Signed-off-by: Omar Sandoval <osandov@fb.com>
> ---
>   fs/btrfs/file-item.c | 11 +++++++----
>   1 file changed, 7 insertions(+), 4 deletions(-)
> 
> diff --git a/fs/btrfs/file-item.c b/fs/btrfs/file-item.c
> index 6c849e8fd5a1..fa9f4a92f74d 100644
> --- a/fs/btrfs/file-item.c
> +++ b/fs/btrfs/file-item.c
> @@ -242,11 +242,13 @@ int btrfs_lookup_file_extent(struct btrfs_trans_handle *trans,
>   /**
>    * btrfs_lookup_bio_sums - Look up checksums for a bio.
>    * @inode: inode that the bio is for.
> - * @bio: bio embedded in btrfs_io_bio.
> + * @bio: bio to look up.
>    * @offset: Unless (u64)-1, look up checksums for this offset in the file.
>    *          If (u64)-1, use the page offsets from the bio instead.
> - * @dst: Buffer of size btrfs_super_csum_size() used to return checksum. If
> - *       NULL, the checksum is returned in btrfs_io_bio(bio)->csum instead.
> + * @dst: Buffer of size nblocks * btrfs_super_csum_size() used to return
> + *       checksum (nblocks = bio->bi_iter.bi_size / sectorsize). If NULL, the
> + *       checksum buffer is allocated and returned in btrfs_io_bio(bio)->csum
> + *       instead.
>    *
>    * Return: BLK_STS_RESOURCE if allocating memory fails, BLK_STS_OK otherwise.
>    */
> @@ -256,7 +258,6 @@ blk_status_t btrfs_lookup_bio_sums(struct inode *inode, struct bio *bio,
>   	struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb);
>   	struct bio_vec bvec;
>   	struct bvec_iter iter;
> -	struct btrfs_io_bio *btrfs_bio = btrfs_io_bio(bio);
>   	struct btrfs_csum_item *item = NULL;
>   	struct extent_io_tree *io_tree = &BTRFS_I(inode)->io_tree;
>   	struct btrfs_path *path;
> @@ -277,6 +278,8 @@ blk_status_t btrfs_lookup_bio_sums(struct inode *inode, struct bio *bio,
>   
>   	nblocks = bio->bi_iter.bi_size >> inode->i_sb->s_blocksize_bits;
>   	if (!dst) {
> +		struct btrfs_io_bio *btrfs_bio = btrfs_io_bio(bio);
> +

Looks like you have some extra changes in here?

Josef
Omar Sandoval March 11, 2020, 6:23 p.m. UTC | #2
On Wed, Mar 11, 2020 at 01:56:44PM -0400, Josef Bacik wrote:
> On 3/9/20 5:32 PM, Omar Sandoval wrote:
> > From: Omar Sandoval <osandov@fb.com>
> > 
> > Fix a couple of issues in the btrfs_lookup_bio_sums documentation:
> > 
> > * The bio doesn't need to be a btrfs_io_bio if dst was provided. Move
> >    the declaration in the code to make that clear, too.
> > * dst must be large enough to hold nblocks * csum_size, not just
> >    csum_size.
> > 
> > Signed-off-by: Omar Sandoval <osandov@fb.com>
> > ---
> >   fs/btrfs/file-item.c | 11 +++++++----
> >   1 file changed, 7 insertions(+), 4 deletions(-)
> > 
> > diff --git a/fs/btrfs/file-item.c b/fs/btrfs/file-item.c
> > index 6c849e8fd5a1..fa9f4a92f74d 100644
> > --- a/fs/btrfs/file-item.c
> > +++ b/fs/btrfs/file-item.c
> > @@ -242,11 +242,13 @@ int btrfs_lookup_file_extent(struct btrfs_trans_handle *trans,
> >   /**
> >    * btrfs_lookup_bio_sums - Look up checksums for a bio.
> >    * @inode: inode that the bio is for.
> > - * @bio: bio embedded in btrfs_io_bio.
> > + * @bio: bio to look up.
> >    * @offset: Unless (u64)-1, look up checksums for this offset in the file.
> >    *          If (u64)-1, use the page offsets from the bio instead.
> > - * @dst: Buffer of size btrfs_super_csum_size() used to return checksum. If
> > - *       NULL, the checksum is returned in btrfs_io_bio(bio)->csum instead.
> > + * @dst: Buffer of size nblocks * btrfs_super_csum_size() used to return
> > + *       checksum (nblocks = bio->bi_iter.bi_size / sectorsize). If NULL, the
> > + *       checksum buffer is allocated and returned in btrfs_io_bio(bio)->csum
> > + *       instead.
> >    *
> >    * Return: BLK_STS_RESOURCE if allocating memory fails, BLK_STS_OK otherwise.
> >    */
> > @@ -256,7 +258,6 @@ blk_status_t btrfs_lookup_bio_sums(struct inode *inode, struct bio *bio,
> >   	struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb);
> >   	struct bio_vec bvec;
> >   	struct bvec_iter iter;
> > -	struct btrfs_io_bio *btrfs_bio = btrfs_io_bio(bio);
> >   	struct btrfs_csum_item *item = NULL;
> >   	struct extent_io_tree *io_tree = &BTRFS_I(inode)->io_tree;
> >   	struct btrfs_path *path;
> > @@ -277,6 +278,8 @@ blk_status_t btrfs_lookup_bio_sums(struct inode *inode, struct bio *bio,
> >   	nblocks = bio->bi_iter.bi_size >> inode->i_sb->s_blocksize_bits;
> >   	if (!dst) {
> > +		struct btrfs_io_bio *btrfs_bio = btrfs_io_bio(bio);
> > +
> 
> Looks like you have some extra changes in here?

I mentioned it in the commit message: "Move the declaration in the code
to make that clear". It looks weird to document that the bio only needs
to be a btrfs_io_bio if dst == NULL and then always get the btrfs_bio,
even if we don't use it.
Josef Bacik March 11, 2020, 6:34 p.m. UTC | #3
On 3/11/20 2:23 PM, Omar Sandoval wrote:
> On Wed, Mar 11, 2020 at 01:56:44PM -0400, Josef Bacik wrote:
>> On 3/9/20 5:32 PM, Omar Sandoval wrote:
>>> From: Omar Sandoval <osandov@fb.com>
>>>
>>> Fix a couple of issues in the btrfs_lookup_bio_sums documentation:
>>>
>>> * The bio doesn't need to be a btrfs_io_bio if dst was provided. Move
>>>     the declaration in the code to make that clear, too.
>>> * dst must be large enough to hold nblocks * csum_size, not just
>>>     csum_size.
>>>
>>> Signed-off-by: Omar Sandoval <osandov@fb.com>
>>> ---
>>>    fs/btrfs/file-item.c | 11 +++++++----
>>>    1 file changed, 7 insertions(+), 4 deletions(-)
>>>
>>> diff --git a/fs/btrfs/file-item.c b/fs/btrfs/file-item.c
>>> index 6c849e8fd5a1..fa9f4a92f74d 100644
>>> --- a/fs/btrfs/file-item.c
>>> +++ b/fs/btrfs/file-item.c
>>> @@ -242,11 +242,13 @@ int btrfs_lookup_file_extent(struct btrfs_trans_handle *trans,
>>>    /**
>>>     * btrfs_lookup_bio_sums - Look up checksums for a bio.
>>>     * @inode: inode that the bio is for.
>>> - * @bio: bio embedded in btrfs_io_bio.
>>> + * @bio: bio to look up.
>>>     * @offset: Unless (u64)-1, look up checksums for this offset in the file.
>>>     *          If (u64)-1, use the page offsets from the bio instead.
>>> - * @dst: Buffer of size btrfs_super_csum_size() used to return checksum. If
>>> - *       NULL, the checksum is returned in btrfs_io_bio(bio)->csum instead.
>>> + * @dst: Buffer of size nblocks * btrfs_super_csum_size() used to return
>>> + *       checksum (nblocks = bio->bi_iter.bi_size / sectorsize). If NULL, the
>>> + *       checksum buffer is allocated and returned in btrfs_io_bio(bio)->csum
>>> + *       instead.
>>>     *
>>>     * Return: BLK_STS_RESOURCE if allocating memory fails, BLK_STS_OK otherwise.
>>>     */
>>> @@ -256,7 +258,6 @@ blk_status_t btrfs_lookup_bio_sums(struct inode *inode, struct bio *bio,
>>>    	struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb);
>>>    	struct bio_vec bvec;
>>>    	struct bvec_iter iter;
>>> -	struct btrfs_io_bio *btrfs_bio = btrfs_io_bio(bio);
>>>    	struct btrfs_csum_item *item = NULL;
>>>    	struct extent_io_tree *io_tree = &BTRFS_I(inode)->io_tree;
>>>    	struct btrfs_path *path;
>>> @@ -277,6 +278,8 @@ blk_status_t btrfs_lookup_bio_sums(struct inode *inode, struct bio *bio,
>>>    	nblocks = bio->bi_iter.bi_size >> inode->i_sb->s_blocksize_bits;
>>>    	if (!dst) {
>>> +		struct btrfs_io_bio *btrfs_bio = btrfs_io_bio(bio);
>>> +
>>
>> Looks like you have some extra changes in here?
> 
> I mentioned it in the commit message: "Move the declaration in the code
> to make that clear". It looks weird to document that the bio only needs
> to be a btrfs_io_bio if dst == NULL and then always get the btrfs_bio,
> even if we don't use it.
> 

Apparently I can't read multi-sentence bullet points.

Reviewed-by: Josef Bacik <josef@toxicpanda.com>

Thanks,

Josef
Nikolay Borisov March 17, 2020, 2:38 p.m. UTC | #4
On 9.03.20 г. 23:32 ч., Omar Sandoval wrote:
> From: Omar Sandoval <osandov@fb.com>
> 
> Fix a couple of issues in the btrfs_lookup_bio_sums documentation:
> 
> * The bio doesn't need to be a btrfs_io_bio if dst was provided. Move
>   the declaration in the code to make that clear, too.
> * dst must be large enough to hold nblocks * csum_size, not just
>   csum_size.
> 
> Signed-off-by: Omar Sandoval <osandov@fb.com>
> ---
>  fs/btrfs/file-item.c | 11 +++++++----
>  1 file changed, 7 insertions(+), 4 deletions(-)
> 
> diff --git a/fs/btrfs/file-item.c b/fs/btrfs/file-item.c
> index 6c849e8fd5a1..fa9f4a92f74d 100644
> --- a/fs/btrfs/file-item.c
> +++ b/fs/btrfs/file-item.c
> @@ -242,11 +242,13 @@ int btrfs_lookup_file_extent(struct btrfs_trans_handle *trans,
>  /**
>   * btrfs_lookup_bio_sums - Look up checksums for a bio.
>   * @inode: inode that the bio is for.
> - * @bio: bio embedded in btrfs_io_bio.
> + * @bio: bio to look up.
>   * @offset: Unless (u64)-1, look up checksums for this offset in the file.
>   *          If (u64)-1, use the page offsets from the bio instead.
> - * @dst: Buffer of size btrfs_super_csum_size() used to return checksum. If
> - *       NULL, the checksum is returned in btrfs_io_bio(bio)->csum instead.
> + * @dst: Buffer of size nblocks * btrfs_super_csum_size() used to return
> + *       checksum (nblocks = bio->bi_iter.bi_size / sectorsize). If NULL, the

nit: sector here refers to btrfs' notion of a sector which is 4k and not
the default understanding of 512 bytes. Dunno if it makes sense to make
that a bit more emphatic. Also nblocks is really number of checksums.
Looking at file-item.c I see there is only 1 menition of ncsums or
csums_in_item. I guess if we can make that nblocks a bit more explicit?

> + *       checksum buffer is allocated and returned in btrfs_io_bio(bio)->csum
> + *       instead.
>   *
>   * Return: BLK_STS_RESOURCE if allocating memory fails, BLK_STS_OK otherwise.
>   */
> @@ -256,7 +258,6 @@ blk_status_t btrfs_lookup_bio_sums(struct inode *inode, struct bio *bio,
>  	struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb);
>  	struct bio_vec bvec;
>  	struct bvec_iter iter;
> -	struct btrfs_io_bio *btrfs_bio = btrfs_io_bio(bio);
>  	struct btrfs_csum_item *item = NULL;
>  	struct extent_io_tree *io_tree = &BTRFS_I(inode)->io_tree;
>  	struct btrfs_path *path;
> @@ -277,6 +278,8 @@ blk_status_t btrfs_lookup_bio_sums(struct inode *inode, struct bio *bio,
>  
>  	nblocks = bio->bi_iter.bi_size >> inode->i_sb->s_blocksize_bits;
>  	if (!dst) {
> +		struct btrfs_io_bio *btrfs_bio = btrfs_io_bio(bio);
> +
>  		if (nblocks * csum_size > BTRFS_BIO_INLINE_CSUM_SIZE) {
>  			btrfs_bio->csum = kmalloc_array(nblocks, csum_size,
>  							GFP_NOFS);
>
diff mbox series

Patch

diff --git a/fs/btrfs/file-item.c b/fs/btrfs/file-item.c
index 6c849e8fd5a1..fa9f4a92f74d 100644
--- a/fs/btrfs/file-item.c
+++ b/fs/btrfs/file-item.c
@@ -242,11 +242,13 @@  int btrfs_lookup_file_extent(struct btrfs_trans_handle *trans,
 /**
  * btrfs_lookup_bio_sums - Look up checksums for a bio.
  * @inode: inode that the bio is for.
- * @bio: bio embedded in btrfs_io_bio.
+ * @bio: bio to look up.
  * @offset: Unless (u64)-1, look up checksums for this offset in the file.
  *          If (u64)-1, use the page offsets from the bio instead.
- * @dst: Buffer of size btrfs_super_csum_size() used to return checksum. If
- *       NULL, the checksum is returned in btrfs_io_bio(bio)->csum instead.
+ * @dst: Buffer of size nblocks * btrfs_super_csum_size() used to return
+ *       checksum (nblocks = bio->bi_iter.bi_size / sectorsize). If NULL, the
+ *       checksum buffer is allocated and returned in btrfs_io_bio(bio)->csum
+ *       instead.
  *
  * Return: BLK_STS_RESOURCE if allocating memory fails, BLK_STS_OK otherwise.
  */
@@ -256,7 +258,6 @@  blk_status_t btrfs_lookup_bio_sums(struct inode *inode, struct bio *bio,
 	struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb);
 	struct bio_vec bvec;
 	struct bvec_iter iter;
-	struct btrfs_io_bio *btrfs_bio = btrfs_io_bio(bio);
 	struct btrfs_csum_item *item = NULL;
 	struct extent_io_tree *io_tree = &BTRFS_I(inode)->io_tree;
 	struct btrfs_path *path;
@@ -277,6 +278,8 @@  blk_status_t btrfs_lookup_bio_sums(struct inode *inode, struct bio *bio,
 
 	nblocks = bio->bi_iter.bi_size >> inode->i_sb->s_blocksize_bits;
 	if (!dst) {
+		struct btrfs_io_bio *btrfs_bio = btrfs_io_bio(bio);
+
 		if (nblocks * csum_size > BTRFS_BIO_INLINE_CSUM_SIZE) {
 			btrfs_bio->csum = kmalloc_array(nblocks, csum_size,
 							GFP_NOFS);