@@ -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+ */
879893void 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+ */
15171548static 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}
17281759EXPORT_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+ */
17301768struct 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}
17481786EXPORT_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+ */
17501795void put_disk (struct gendisk * disk )
17511796{
17521797 if (disk )
17531798 kobject_put (& disk_to_dev (disk )-> kobj );
17541799}
17551800EXPORT_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