From patchwork Tue Nov 15 14:10:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yu Kuai X-Patchwork-Id: 20387 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2740908wru; Tue, 15 Nov 2022 05:54:42 -0800 (PST) X-Google-Smtp-Source: AA0mqf4wbXZKN74QiLE71/1G0Ls7tSO74yjWNrbapm8HBrpe9t8V8qtYyzJGpWZ8b8diMvq0KmB1 X-Received: by 2002:a05:6402:22e5:b0:457:791d:8348 with SMTP id dn5-20020a05640222e500b00457791d8348mr15228402edb.306.1668520481943; Tue, 15 Nov 2022 05:54:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668520481; cv=none; d=google.com; s=arc-20160816; b=gyy/LPy2zEmGt81xmkT3NdjfsaPy786gTu7svBh8oX52oCAWp3mZe/yknZMpf+zQZw Lvsrt2g2G/2mXUlIg5o0ZTnlCNombOLcIw3f8S8fNI2ao8qcG67499S5yMeIwt/l7Mkj JHfpgz+mDVJFSdwxl4mtAeEFmmLZK/kDpbmrBzfK/ru+MxEFT5whspyEdKwyajgGsPXm cWtQOK96ZO4qtToIpGb1MdrfXi43z6KUTFDQ/fRAEJ+5cB4xJxEris77Ho7o0ozon5Bm D23i1XhTLyE9bBxpyvCVv66ctxkh8XXiInz3gKjZsjutZUDLDI4dUyg7yHvfyCtdcT9L 974w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=wr6fBAILtjbuGCgyOYjkA0GrVhxgKGvn+8upW1UKROU=; b=Ujpma1+EOC/e94gXKyfYgnDbqvs3/udU+eQzAbfEqmqBgQYR6k2UswL1az2wFcI3pz jWp1MQeI/mrf9LPMsf3rlq/6g5SMSLOPkXbdlgwrrbV1F2zuzsz8kaPwFaHL2cq/Zj/j hgU+QNnpVwZPyHiY+7BPSPxIuVUNuB7DygwG3p+KcnB9FVfx1p5wXJkBKWVGPFizCoaA Gf1OtTPXsVyUhScjbehcMBk/+YQDGIYjaXqBjmXC4bFIYOhcBQKs/khK10fn1tPx5P5R Y6/3wP/rpQlhYzFZ+rAi1ksekx8FoeaHjxom2o/Bz9JGLvSCZ8r9KHe4fyf74mtyThJj Ai+Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id qb12-20020a1709077e8c00b0079800b81747si11615534ejc.735.2022.11.15.05.54.14; Tue, 15 Nov 2022 05:54:41 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238473AbiKONtr (ORCPT + 99 others); Tue, 15 Nov 2022 08:49:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49678 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230245AbiKONtg (ORCPT ); Tue, 15 Nov 2022 08:49:36 -0500 Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 96CDF24BFF; Tue, 15 Nov 2022 05:49:33 -0800 (PST) Received: from mail02.huawei.com (unknown [172.30.67.153]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4NBSGH51dfz4f3k6b; Tue, 15 Nov 2022 21:49:27 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.127.227]) by APP4 (Coremail) with SMTP id gCh0CgBni9jnmHNjrPFIAg--.61645S8; Tue, 15 Nov 2022 21:49:30 +0800 (CST) From: Yu Kuai To: hch@lst.de, axboe@kernel.dk, agk@redhat.com, snitzer@kernel.org, dm-devel@redhat.com Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, yukuai3@huawei.com, yukuai1@huaweicloud.com, yi.zhang@huawei.com Subject: [PATCH v3 04/10] dm: cleanup close_table_device Date: Tue, 15 Nov 2022 22:10:48 +0800 Message-Id: <20221115141054.1051801-5-yukuai1@huaweicloud.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20221115141054.1051801-1-yukuai1@huaweicloud.com> References: <20221115141054.1051801-1-yukuai1@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: gCh0CgBni9jnmHNjrPFIAg--.61645S8 X-Coremail-Antispam: 1UD129KBjvJXoW7urWkKrWrtFy7ur1UKFW8Crg_yoW8WFy5p3 W3Ja4jqrW5GrZ29w4UZr4j9Fy3Kr4jka4Fkry5Cw1xKw1UZryFvFWrJFy3XFykJ3yxGF98 Xa47KryrWF4xKr7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUPY14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7 IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4U M4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwACI402YVCY1x02628vn2 kIc2xKxwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E 14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_Jw0_GFylIx kGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWUJVWUCwCI42IY6xIIjxv20xvEc7CjxVAF wI0_Gr0_Cr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r1j6r 4UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Gr0_Gr1UYxBIdaVFxhVjvjDU0xZFpf9x0JUQSdkU UUUU= X-CM-SenderInfo: 51xn3trlr6x35dzhxuhorxvhhfrp/ X-CFilter-Loop: Reflected X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749570533025937465?= X-GMAIL-MSGID: =?utf-8?q?1749570533025937465?= From: Christoph Hellwig Take the list unlink and free into close_table_device so that no half torn down table_devices exist. Also remove the check for a NULL bdev as that can't happen - open_table_device never adds a table_device to the list that does not have a valid block_device. Signed-off-by: Christoph Hellwig Signed-off-by: Yu Kuai Reviewed-by: Mike Snitzer --- drivers/md/dm.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/drivers/md/dm.c b/drivers/md/dm.c index 28d7581b6a82..2917700b1e15 100644 --- a/drivers/md/dm.c +++ b/drivers/md/dm.c @@ -774,14 +774,11 @@ static struct table_device *open_table_device(struct mapped_device *md, */ static void close_table_device(struct table_device *td, struct mapped_device *md) { - if (!td->dm_dev.bdev) - return; - bd_unlink_disk_holder(td->dm_dev.bdev, dm_disk(md)); blkdev_put(td->dm_dev.bdev, td->dm_dev.mode | FMODE_EXCL); put_dax(td->dm_dev.dax_dev); - td->dm_dev.bdev = NULL; - td->dm_dev.dax_dev = NULL; + list_del(&td->list); + kfree(td); } static struct table_device *find_table_device(struct list_head *l, dev_t dev, @@ -823,11 +820,8 @@ void dm_put_table_device(struct mapped_device *md, struct dm_dev *d) struct table_device *td = container_of(d, struct table_device, dm_dev); mutex_lock(&md->table_devices_lock); - if (refcount_dec_and_test(&td->count)) { + if (refcount_dec_and_test(&td->count)) close_table_device(td, md); - list_del(&td->list); - kfree(td); - } mutex_unlock(&md->table_devices_lock); }