Skip to contentSkip to conversation

block: Correct comment on bio_alloc_clone()

PATCH In review John Garry 2 participants 6 messages Feb 20 Block layer

lore
Share & tools
lore

John Garry

author
#0 lore raw

PATCH 1/1 block: Correct comment on bio_alloc_clone()

Correct the comment that the source bio must not be freed before the clone.

block/bio.c +1 -1
index 8203bb7455a9f..9d9191fe19b50 100644
@@ -900,7 +900,7 @@ static int __bio_clone(struct bio *bio, struct bio *bio_src, gfp_t gfp)
  * Allocate a new bio that is a clone of @bio_src. The caller owns the returned
  * bio, but not the actual data it points to.
  *
- * The caller must ensure that the return bio is not freed before @bio_src.
+ * The caller must ensure that @bio_src is not freed before the returned bio.
  */
 struct bio *bio_alloc_clone(struct block_device *bdev, struct bio *bio_src,
 		gfp_t gfp, struct bio_set *bs)
Signature · 1 line
2.43.5
#1 lore raw
Quoted 1 line · John Garry

Correct the comment that the source bio must not be freed before the clone.

Note that while this version is better, it's not actually true either. The bi_io_vec used by the clone must be freed after the clone, but it might might not be owned by the passed in bio_src.

author
#2 lore raw
Quoted 7 lines · Christoph Hellwig
Quoted 1 line · John Garry

Correct the comment that the source bio must not be freed before the clone.

Note that while this version is better, it's not actually true either. The bi_io_vec used by the clone must be freed after the clone, but it might might not be owned by the passed in bio_src.

This is the complete function comment today:

* Allocate a new bio that is a clone of @bio_src. The caller owns the
returned
* bio, but not the actual data it points to.
*
* The caller must ensure that the return bio is not freed before @bio_src.

So I can have this:

* Allocate a new bio that is a clone of @bio_src. The caller owns the
returned
* bio, but not the actual data it points to, bi_io_vec.
*
* The caller must ensure that the returned bio is freed before bi_io_vec.

ok?

#3 lore raw
Quoted 6 lines · John Garry

So I can have this:

* Allocate a new bio that is a clone of @bio_src. The caller owns the
returned
* bio, but not the actual data it points to, bi_io_vec.

Well, bi_io_vec isn't really the data, but the indirection pointing to the data. I guess we need to come up with consistent terminology first before we can make good sense of this.

Allocate a new bio that is a clone of @bio_src. This reuses the bio_vecs pointed to by @bio_src->bi_io_vec, and clones the iterator pointing to the current position in it. The caller owns the returned bio, but not the bio_vecs, and must ensure the bio is freed before the memory pointed to by @bio_Src->bi_io_vecs.

author
#4 lore raw
Quoted 9 lines · Christoph Hellwig

Well, bi_io_vec isn't really the data, but the indirection pointing to the data. I guess we need to come up with consistent terminology first before we can make good sense of this.

Allocate a new bio that is a clone of @bio_src. This reuses the bio_vecs pointed to by @bio_src->bi_io_vec, and clones the iterator pointing to the current position in it. The caller owns the returned bio, but not the bio_vecs, and must ensure the bio is freed before the memory pointed to by @bio_Src->bi_io_vecs.

ok, fine.

BTW, the comment for bio_init_clone() was much the same as bio_alloc_clone(), modulo what I tried to originally remedy. I can just mention that that the same bio_src->bi_io_vec lifecycle rules apply there (as bio_alloc_clone())

#5 lore raw
Quoted 4 lines · John Garry

BTW, the comment for bio_init_clone() was much the same as bio_alloc_clone(), modulo what I tried to originally remedy. I can just mention that that the same bio_src->bi_io_vec lifecycle rules apply there (as bio_alloc_clone())

Sounds good.