Skip to content

Commit b5bd357

Browse files
mcgrofaxboe
authored andcommitted
block: add docs for gendisk / request_queue refcount helpers
This adds documentation for the gendisk / request_queue refcount helpers. Signed-off-by: Luis Chamberlain <mcgrof@kernel.org> Reviewed-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Bart Van Assche <bvanassche@acm.org> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent ff02945 commit b5bd357

File tree

2 files changed

+62
-1
lines changed

2 files changed

+62
-1
lines changed

block/blk-core.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,13 @@ void blk_clear_pm_only(struct request_queue *q)
321321
}
322322
EXPORT_SYMBOL_GPL(blk_clear_pm_only);
323323

324+
/**
325+
* blk_put_queue - decrement the request_queue refcount
326+
* @q: the request_queue structure to decrement the refcount for
327+
*
328+
* Decrements the refcount of the request_queue kobject. When this reaches 0
329+
* we'll have blk_release_queue() called.
330+
*/
324331
void blk_put_queue(struct request_queue *q)
325332
{
326333
kobject_put(&q->kobj);
@@ -598,6 +605,12 @@ struct request_queue *blk_alloc_queue(make_request_fn make_request, int node_id)
598605
}
599606
EXPORT_SYMBOL(blk_alloc_queue);
600607

608+
/**
609+
* blk_get_queue - increment the request_queue refcount
610+
* @q: the request_queue structure to increment the refcount for
611+
*
612+
* Increment the refcount of the request_queue kobject.
613+
*/
601614
bool blk_get_queue(struct request_queue *q)
602615
{
603616
if (likely(!blk_queue_dying(q))) {

block/genhd.c

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -876,6 +876,20 @@ static void invalidate_partition(struct gendisk *disk, int partno)
876876
bdput(bdev);
877877
}
878878

879+
/**
880+
* del_gendisk - remove the gendisk
881+
* @disk: the struct gendisk to remove
882+
*
883+
* Removes the gendisk and all its associated resources. This deletes the
884+
* partitions associated with the gendisk, and unregisters the associated
885+
* request_queue.
886+
*
887+
* This is the counter to the respective __device_add_disk() call.
888+
*
889+
* The final removal of the struct gendisk happens when its refcount reaches 0
890+
* with put_disk(), which should be called after del_gendisk(), if
891+
* __device_add_disk() was used.
892+
*/
879893
void del_gendisk(struct gendisk *disk)
880894
{
881895
struct disk_part_iter piter;
@@ -1514,6 +1528,23 @@ int disk_expand_part_tbl(struct gendisk *disk, int partno)
15141528
return 0;
15151529
}
15161530

1531+
/**
1532+
* disk_release - releases all allocated resources of the gendisk
1533+
* @dev: the device representing this disk
1534+
*
1535+
* This function releases all allocated resources of the gendisk.
1536+
*
1537+
* The struct gendisk refcount is incremented with get_gendisk() or
1538+
* get_disk_and_module(), and its refcount is decremented with
1539+
* put_disk_and_module() or put_disk(). Once the refcount reaches 0 this
1540+
* function is called.
1541+
*
1542+
* Drivers which used __device_add_disk() have a gendisk with a request_queue
1543+
* assigned. Since the request_queue sits on top of the gendisk for these
1544+
* drivers we also call blk_put_queue() for them, and we expect the
1545+
* request_queue refcount to reach 0 at this point, and so the request_queue
1546+
* will also be freed prior to the disk.
1547+
*/
15171548
static void disk_release(struct device *dev)
15181549
{
15191550
struct gendisk *disk = dev_to_disk(dev);
@@ -1727,6 +1758,13 @@ struct gendisk *__alloc_disk_node(int minors, int node_id)
17271758
}
17281759
EXPORT_SYMBOL(__alloc_disk_node);
17291760

1761+
/**
1762+
* get_disk_and_module - increments the gendisk and gendisk fops module refcount
1763+
* @disk: the struct gendisk to to increment the refcount for
1764+
*
1765+
* This increments the refcount for the struct gendisk, and the gendisk's
1766+
* fops module owner.
1767+
*/
17301768
struct kobject *get_disk_and_module(struct gendisk *disk)
17311769
{
17321770
struct module *owner;
@@ -1747,14 +1785,24 @@ struct kobject *get_disk_and_module(struct gendisk *disk)
17471785
}
17481786
EXPORT_SYMBOL(get_disk_and_module);
17491787

1788+
/**
1789+
* put_disk - decrements the gendisk refcount
1790+
* @disk: the struct gendisk to to decrement the refcount for
1791+
*
1792+
* This decrements the refcount for the struct gendisk. When this reaches 0
1793+
* we'll have disk_release() called.
1794+
*/
17501795
void put_disk(struct gendisk *disk)
17511796
{
17521797
if (disk)
17531798
kobject_put(&disk_to_dev(disk)->kobj);
17541799
}
17551800
EXPORT_SYMBOL(put_disk);
17561801

1757-
/*
1802+
/**
1803+
* put_disk_and_module - decrements the module and gendisk refcount
1804+
* @disk: the struct gendisk to to decrement the refcount for
1805+
*
17581806
* This is a counterpart of get_disk_and_module() and thus also of
17591807
* get_gendisk().
17601808
*/

0 commit comments

Comments
 (0)