From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.0 required=3.0 tests=INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6D8DCC433DF for ; Fri, 19 Jun 2020 20:47:37 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 39E012100A for ; Fri, 19 Jun 2020 20:47:37 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 39E012100A Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id AB04F8D00FA; Fri, 19 Jun 2020 16:47:36 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A60FA8D00E9; Fri, 19 Jun 2020 16:47:36 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 977098D00FA; Fri, 19 Jun 2020 16:47:36 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0099.hostedemail.com [216.40.44.99]) by kanga.kvack.org (Postfix) with ESMTP id 8093A8D00E9 for ; Fri, 19 Jun 2020 16:47:36 -0400 (EDT) Received: from smtpin06.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 0BCB68248068 for ; Fri, 19 Jun 2020 20:47:36 +0000 (UTC) X-FDA: 76947147312.06.sand54_0f03e8826e1b Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin06.hostedemail.com (Postfix) with ESMTP id D04731003F9B7 for ; Fri, 19 Jun 2020 20:47:35 +0000 (UTC) X-HE-Tag: sand54_0f03e8826e1b X-Filterd-Recvd-Size: 7274 Received: from mail-pf1-f196.google.com (mail-pf1-f196.google.com [209.85.210.196]) by imf47.hostedemail.com (Postfix) with ESMTP for ; Fri, 19 Jun 2020 20:47:35 +0000 (UTC) Received: by mail-pf1-f196.google.com with SMTP id 10so4922601pfx.8 for ; Fri, 19 Jun 2020 13:47:35 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=IR8sE8tegFIZFEE9c+9scyuraOZnu4HrFVBH9bLfdFU=; b=smVj3idyQDACKvcYCCYzoeCU791ucNYdBcBnkvOszXe3nLmKDOLYXb6y5w2gTt5/aF HHoVX+8QGoOxd/u1BXAADm0eAJAq00CU/ZIDTKvycec+/JqlWYbnLmC7k43TxE/DKqZ2 VfJMEoztlhRfpMch+2udP+g9NZwv6WVp9IYvSNcNJ3OkZAQionOjr3fUP8BR6MHZICme 6wnn9SQY6gnGZRAkZNKcKRP7KjO/Vkv6CZtgn9ZYwayi/zYq2AwJSNBZTxBnRXuMiyRi qcfrjUppwKsHtN1GNyXaB52zh9tMpH+PEJebwTuWZPx5Y4FAxPqs1Y3A8+sjmuKXWe6r /oxw== X-Gm-Message-State: AOAM530VNFyyd9I3YiyTH/r1S4HA1r1KmZ5iP4bkToM1G2ixQbqHHaC4 N7njaayI2+KUa2OfcGzQS0g= X-Google-Smtp-Source: ABdhPJyVHEmV58NGZTznpaBP/xgk4sbNqpUUFbscfauH7CNuFRiXIQShxRF2mjNHNu7Ts1PNNvwYJQ== X-Received: by 2002:a63:20d:: with SMTP id 13mr629527pgc.166.1592599654228; Fri, 19 Jun 2020 13:47:34 -0700 (PDT) Received: from 42.do-not-panic.com (42.do-not-panic.com. [157.230.128.187]) by smtp.gmail.com with ESMTPSA id 127sm4494638pgf.5.2020.06.19.13.47.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Jun 2020 13:47:32 -0700 (PDT) Received: by 42.do-not-panic.com (Postfix, from userid 1000) id 2A5FE40B6C; Fri, 19 Jun 2020 20:47:32 +0000 (UTC) From: Luis Chamberlain To: axboe@kernel.dk, viro@zeniv.linux.org.uk, bvanassche@acm.org, gregkh@linuxfoundation.org, rostedt@goodmis.org, mingo@redhat.com, jack@suse.cz, ming.lei@redhat.com, nstange@suse.de, akpm@linux-foundation.org Cc: mhocko@suse.com, yukuai3@huawei.com, martin.petersen@oracle.com, jejb@linux.ibm.com, linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Luis Chamberlain , Christoph Hellwig Subject: [PATCH v7 1/8] block: add docs for gendisk / request_queue refcount helpers Date: Fri, 19 Jun 2020 20:47:23 +0000 Message-Id: <20200619204730.26124-2-mcgrof@kernel.org> X-Mailer: git-send-email 2.23.0.rc1 In-Reply-To: <20200619204730.26124-1-mcgrof@kernel.org> References: <20200619204730.26124-1-mcgrof@kernel.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: D04731003F9B7 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam01 Content-Transfer-Encoding: quoted-printable X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: This adds documentation for the gendisk / request_queue refcount helpers. Reviewed-by: Christoph Hellwig Reviewed-by: Bart Van Assche Signed-off-by: Luis Chamberlain --- block/blk-core.c | 13 +++++++++++++ block/genhd.c | 50 +++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 62 insertions(+), 1 deletion(-) diff --git a/block/blk-core.c b/block/blk-core.c index 62a4904db921..a0760aac110a 100644 --- a/block/blk-core.c +++ b/block/blk-core.c @@ -321,6 +321,13 @@ void blk_clear_pm_only(struct request_queue *q) } EXPORT_SYMBOL_GPL(blk_clear_pm_only); =20 +/** + * blk_put_queue - decrement the request_queue refcount + * @q: the request_queue structure to decrement the refcount for + * + * Decrements the refcount of the request_queue kobject. When this reach= es 0 + * we'll have blk_release_queue() called. + */ void blk_put_queue(struct request_queue *q) { kobject_put(&q->kobj); @@ -598,6 +605,12 @@ struct request_queue *blk_alloc_queue(make_request_f= n make_request, int node_id) } EXPORT_SYMBOL(blk_alloc_queue); =20 +/** + * blk_get_queue - increment the request_queue refcount + * @q: the request_queue structure to increment the refcount for + * + * Increment the refcount of the request_queue kobject. + */ bool blk_get_queue(struct request_queue *q) { if (likely(!blk_queue_dying(q))) { diff --git a/block/genhd.c b/block/genhd.c index 1a7659327664..f741613d731f 100644 --- a/block/genhd.c +++ b/block/genhd.c @@ -876,6 +876,20 @@ static void invalidate_partition(struct gendisk *dis= k, int partno) bdput(bdev); } =20 +/** + * del_gendisk - remove the gendisk + * @disk: the struct gendisk to remove + * + * Removes the gendisk and all its associated resources. This deletes th= e + * partitions associated with the gendisk, and unregisters the associate= d + * request_queue. + * + * This is the counter to the respective __device_add_disk() call. + * + * The final removal of the struct gendisk happens when its refcount rea= ches 0 + * with put_disk(), which should be called after del_gendisk(), if + * __device_add_disk() was used. + */ void del_gendisk(struct gendisk *disk) { struct disk_part_iter piter; @@ -1514,6 +1528,23 @@ int disk_expand_part_tbl(struct gendisk *disk, int= partno) return 0; } =20 +/** + * disk_release - releases all allocated resources of the gendisk + * @dev: the device representing this disk + * + * This function releases all allocated resources of the gendisk. + * + * The struct gendisk refcount is incremented with get_gendisk() or + * get_disk_and_module(), and its refcount is decremented with + * put_disk_and_module() or put_disk(). Once the refcount reaches 0 this + * function is called. + * + * Drivers which used __device_add_disk() have a gendisk with a request_= queue + * assigned. Since the request_queue sits on top of the gendisk for thes= e + * drivers we also call blk_put_queue() for them, and we expect the + * request_queue refcount to reach 0 at this point, and so the request_q= ueue + * will also be freed prior to the disk. + */ static void disk_release(struct device *dev) { struct gendisk *disk =3D dev_to_disk(dev); @@ -1727,6 +1758,13 @@ struct gendisk *__alloc_disk_node(int minors, int = node_id) } EXPORT_SYMBOL(__alloc_disk_node); =20 +/** + * get_disk_and_module - increments the gendisk and gendisk fops module = refcount + * @disk: the struct gendisk to to increment the refcount for + * + * This increments the refcount for the struct gendisk, and the gendisk'= s + * fops module owner. + */ struct kobject *get_disk_and_module(struct gendisk *disk) { struct module *owner; @@ -1747,6 +1785,13 @@ struct kobject *get_disk_and_module(struct gendisk= *disk) } EXPORT_SYMBOL(get_disk_and_module); =20 +/** + * put_disk - decrements the gendisk refcount + * @disk: the struct gendisk to to decrement the refcount for + * + * This decrements the refcount for the struct gendisk. When this reache= s 0 + * we'll have disk_release() called. + */ void put_disk(struct gendisk *disk) { if (disk) @@ -1754,7 +1799,10 @@ void put_disk(struct gendisk *disk) } EXPORT_SYMBOL(put_disk); =20 -/* +/** + * put_disk_and_module - decrements the module and gendisk refcount + * @disk: the struct gendisk to to decrement the refcount for + * * This is a counterpart of get_disk_and_module() and thus also of * get_gendisk(). */ --=20 2.26.2