diff mbox series

block: Export blk_alloc_discard_bio

Message ID 20240903073915.989741-1-luca.stefani.ge1@gmail.com (mailing list archive)
State New, archived
Headers show
Series block: Export blk_alloc_discard_bio | expand

Commit Message

Luca Stefani Sept. 3, 2024, 7:39 a.m. UTC
The fs trim loops over ranges and sends discard requests, some ranges
can be large so it's all transparently handled by blkdev_issue_discard()
and processed in smaller chunks.

To support cancellation (or suspend) requests we need to insert checks
into the the loop, exporting the symbol allows to reimplement
such loop with the desired behavior.

Signed-off-by: Luca Stefani <luca.stefani.ge1@gmail.com>
---
 block/blk-lib.c        | 1 +
 include/linux/blkdev.h | 2 ++
 2 files changed, 3 insertions(+)

Comments

Jens Axboe Sept. 3, 2024, 3:49 p.m. UTC | #1
On 9/3/24 1:39 AM, Luca Stefani wrote:
> The fs trim loops over ranges and sends discard requests, some ranges
> can be large so it's all transparently handled by blkdev_issue_discard()
> and processed in smaller chunks.
> 
> To support cancellation (or suspend) requests we need to insert checks
> into the the loop, exporting the symbol allows to reimplement
> such loop with the desired behavior.
> 
> Signed-off-by: Luca Stefani <luca.stefani.ge1@gmail.com>
> ---
>  block/blk-lib.c        | 1 +
>  include/linux/blkdev.h | 2 ++
>  2 files changed, 3 insertions(+)
> 
> diff --git a/block/blk-lib.c b/block/blk-lib.c
> index 4c9f20a689f7..ebaef47d8ce7 100644
> --- a/block/blk-lib.c
> +++ b/block/blk-lib.c
> @@ -59,6 +59,7 @@ struct bio *blk_alloc_discard_bio(struct block_device *bdev,
>  	cond_resched();
>  	return bio;
>  }
> +EXPORT_SYMBOL_GPL(blk_alloc_discard_bio);
>  
>  int __blkdev_issue_discard(struct block_device *bdev, sector_t sector,
>  		sector_t nr_sects, gfp_t gfp_mask, struct bio **biop)
> diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
> index b7664d593486..f3631044d905 100644
> --- a/include/linux/blkdev.h
> +++ b/include/linux/blkdev.h
> @@ -1088,6 +1088,8 @@ static inline long nr_blockdev_pages(void)
>  
>  extern void blk_io_schedule(void);
>  
> +struct bio *blk_alloc_discard_bio(struct block_device *bdev,
> +		sector_t *sector, sector_t *nr_sects, gfp_t gfp_mask);
>  int blkdev_issue_discard(struct block_device *bdev, sector_t sector,
>  		sector_t nr_sects, gfp_t gfp_mask);
>  int __blkdev_issue_discard(struct block_device *bdev, sector_t sector,

Since blk_alloc_discard_bio() is already defined in a header (otherwise
it would've been static and your export symbol above would have failed
miserably), why add it to another header?
Luca Stefani Sept. 3, 2024, 4:02 p.m. UTC | #2
On 03/09/24 17:49, Jens Axboe wrote:
> On 9/3/24 1:39 AM, Luca Stefani wrote:
>> The fs trim loops over ranges and sends discard requests, some ranges
>> can be large so it's all transparently handled by blkdev_issue_discard()
>> and processed in smaller chunks.
>>
>> To support cancellation (or suspend) requests we need to insert checks
>> into the the loop, exporting the symbol allows to reimplement
>> such loop with the desired behavior.
>>
>> Signed-off-by: Luca Stefani <luca.stefani.ge1@gmail.com>
>> ---
>>   block/blk-lib.c        | 1 +
>>   include/linux/blkdev.h | 2 ++
>>   2 files changed, 3 insertions(+)
>>
>> diff --git a/block/blk-lib.c b/block/blk-lib.c
>> index 4c9f20a689f7..ebaef47d8ce7 100644
>> --- a/block/blk-lib.c
>> +++ b/block/blk-lib.c
>> @@ -59,6 +59,7 @@ struct bio *blk_alloc_discard_bio(struct block_device *bdev,
>>   	cond_resched();
>>   	return bio;
>>   }
>> +EXPORT_SYMBOL_GPL(blk_alloc_discard_bio);
>>   
>>   int __blkdev_issue_discard(struct block_device *bdev, sector_t sector,
>>   		sector_t nr_sects, gfp_t gfp_mask, struct bio **biop)
>> diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
>> index b7664d593486..f3631044d905 100644
>> --- a/include/linux/blkdev.h
>> +++ b/include/linux/blkdev.h
>> @@ -1088,6 +1088,8 @@ static inline long nr_blockdev_pages(void)
>>   
>>   extern void blk_io_schedule(void);
>>   
>> +struct bio *blk_alloc_discard_bio(struct block_device *bdev,
>> +		sector_t *sector, sector_t *nr_sects, gfp_t gfp_mask);
>>   int blkdev_issue_discard(struct block_device *bdev, sector_t sector,
>>   		sector_t nr_sects, gfp_t gfp_mask);
>>   int __blkdev_issue_discard(struct block_device *bdev, sector_t sector,
> 
> Since blk_alloc_discard_bio() is already defined in a header (otherwise
> it would've been static and your export symbol above would have failed
> miserably), why add it to another header?
> 

ACK, will remove the header change in v4,

Thanks.
diff mbox series

Patch

diff --git a/block/blk-lib.c b/block/blk-lib.c
index 4c9f20a689f7..ebaef47d8ce7 100644
--- a/block/blk-lib.c
+++ b/block/blk-lib.c
@@ -59,6 +59,7 @@  struct bio *blk_alloc_discard_bio(struct block_device *bdev,
 	cond_resched();
 	return bio;
 }
+EXPORT_SYMBOL_GPL(blk_alloc_discard_bio);
 
 int __blkdev_issue_discard(struct block_device *bdev, sector_t sector,
 		sector_t nr_sects, gfp_t gfp_mask, struct bio **biop)
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index b7664d593486..f3631044d905 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -1088,6 +1088,8 @@  static inline long nr_blockdev_pages(void)
 
 extern void blk_io_schedule(void);
 
+struct bio *blk_alloc_discard_bio(struct block_device *bdev,
+		sector_t *sector, sector_t *nr_sects, gfp_t gfp_mask);
 int blkdev_issue_discard(struct block_device *bdev, sector_t sector,
 		sector_t nr_sects, gfp_t gfp_mask);
 int __blkdev_issue_discard(struct block_device *bdev, sector_t sector,