From patchwork Tue Jul 4 12:21:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kara X-Patchwork-Id: 13301062 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E312CEB64DA for ; Tue, 4 Jul 2023 12:23:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231741AbjGDMXP (ORCPT ); Tue, 4 Jul 2023 08:23:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39276 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231613AbjGDMWk (ORCPT ); Tue, 4 Jul 2023 08:22:40 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7650410D5; Tue, 4 Jul 2023 05:22:34 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id EB17E20565; Tue, 4 Jul 2023 12:22:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1688473345; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2k+j+NE7t+sLhdMxVC5FbUtMZY9ghkeloF+1sdNBw5U=; b=bJTDv9Oe6VTEkA9Nhd3EAypNI+c9gp/+E4ZEHfcaqq+ASBHa/KS/VLHE5SLtemqufQqbli h7FxUWrIk6Y546WHYmWnF5nEQodmH5lyGHf1mz46U/Qrqov7nnXTcXrH3kjyF0pJfYb0Z2 E4MUTfbtTpQeSlFq6ezcIve4RiOb2Is= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1688473345; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2k+j+NE7t+sLhdMxVC5FbUtMZY9ghkeloF+1sdNBw5U=; b=jwiqwhK0A/AO7ckOIsmCljZpUg1l+B8uOPzP72ThC49vlUv7wzsvJA80LRIvfEPC5tKOpC 38hZ7g60My3rFvCQ== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id DC709139ED; Tue, 4 Jul 2023 12:22:25 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id CBXPNQEPpGQuMAAAMHmgww (envelope-from ); Tue, 04 Jul 2023 12:22:25 +0000 Received: by quack3.suse.cz (Postfix, from userid 1000) id E17D3A0771; Tue, 4 Jul 2023 14:22:24 +0200 (CEST) From: Jan Kara To: Cc: , Jens Axboe , Christoph Hellwig , Jan Kara , linux-nvme@lists.infradead.org Subject: [PATCH 14/32] nvmet: Convert to blkdev_get_handle_by_path() Date: Tue, 4 Jul 2023 14:21:41 +0200 Message-Id: <20230704122224.16257-14-jack@suse.cz> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230629165206.383-1-jack@suse.cz> References: <20230629165206.383-1-jack@suse.cz> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2126; i=jack@suse.cz; h=from:subject; bh=SMA9+AJK4skV38lQheF5vU7uxGpgwS7tw1AAPHPgwXA=; b=owEBbQGS/pANAwAIAZydqgc/ZEDZAcsmYgBkpA7WUlCLN1lE1WDAZ8su7Zxa6wNR0751J0IzdLis KCB8UpWJATMEAAEIAB0WIQSrWdEr1p4yirVVKBycnaoHP2RA2QUCZKQO1gAKCRCcnaoHP2RA2fD7B/ 0ZzomC6r5IMCN5PEDZh85MjDl2Hk141xaglkf/++C3+/kBWW/YIEGYx3CkLjCto5WH0QXGZSzdXBUE CCkhNSMSb2efJJpzrNBqhnDPF9nJ33V+M1T7vJQoOZWoam7wI6r1LmusjtBr4X1+dJiW4TuO8L0Ydu pVvLx2Wr7OvyVOt4fDPvK3+ZT+lt/etsHVH2RRzEo7K6bu5azEBZnn5qjo7gxed00OyK5wh9v8kYjd 4gmSTjc6azKCcoboXDlCE6ksKQU6yGr0gRboYxGyD6Yane5I74B02+XUu+9E1b3HyFA3LnMhFwNRD5 +c7lKSDHE2veqnT22pzHefvMBZueK6 X-Developer-Key: i=jack@suse.cz; a=openpgp; fpr=93C6099A142276A28BBE35D815BC833443038D8C Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Convert nvmet to use blkdev_get_handle_by_path() and pass the handle around. CC: linux-nvme@lists.infradead.org Signed-off-by: Jan Kara --- drivers/nvme/target/io-cmd-bdev.c | 20 +++++++++++--------- drivers/nvme/target/nvmet.h | 1 + 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/drivers/nvme/target/io-cmd-bdev.c b/drivers/nvme/target/io-cmd-bdev.c index 2733e0158585..0f177a7e3b37 100644 --- a/drivers/nvme/target/io-cmd-bdev.c +++ b/drivers/nvme/target/io-cmd-bdev.c @@ -50,9 +50,10 @@ void nvmet_bdev_set_limits(struct block_device *bdev, struct nvme_id_ns *id) void nvmet_bdev_ns_disable(struct nvmet_ns *ns) { - if (ns->bdev) { - blkdev_put(ns->bdev, NULL); + if (ns->bdev_handle) { + blkdev_handle_put(ns->bdev_handle); ns->bdev = NULL; + ns->bdev_handle = NULL; } } @@ -84,17 +85,18 @@ int nvmet_bdev_ns_enable(struct nvmet_ns *ns) if (ns->buffered_io) return -ENOTBLK; - ns->bdev = blkdev_get_by_path(ns->device_path, - BLK_OPEN_READ | BLK_OPEN_WRITE, NULL, NULL); - if (IS_ERR(ns->bdev)) { - ret = PTR_ERR(ns->bdev); + ns->bdev_handle = blkdev_get_handle_by_path(ns->device_path, + BLK_OPEN_READ | BLK_OPEN_WRITE, NULL, NULL); + if (IS_ERR(ns->bdev_handle)) { + ret = PTR_ERR(ns->bdev_handle); if (ret != -ENOTBLK) { - pr_err("failed to open block device %s: (%ld)\n", - ns->device_path, PTR_ERR(ns->bdev)); + pr_err("failed to open block device %s: (%d)\n", + ns->device_path, ret); } - ns->bdev = NULL; + ns->bdev_handle = NULL; return ret; } + ns->bdev = ns->bdev_handle->bdev; ns->size = bdev_nr_bytes(ns->bdev); ns->blksize_shift = blksize_bits(bdev_logical_block_size(ns->bdev)); diff --git a/drivers/nvme/target/nvmet.h b/drivers/nvme/target/nvmet.h index 6cf723bc664e..eac3f2c814b8 100644 --- a/drivers/nvme/target/nvmet.h +++ b/drivers/nvme/target/nvmet.h @@ -58,6 +58,7 @@ struct nvmet_ns { struct percpu_ref ref; + struct bdev_handle *bdev_handle; struct block_device *bdev; struct file *file; bool readonly;