From patchwork Tue Jul 4 12:21:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kara X-Patchwork-Id: 13301089 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id AEF73EB64DD for ; Tue, 4 Jul 2023 12:22:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6AE8D90000D; Tue, 4 Jul 2023 08:22:30 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 65E9D90001A; Tue, 4 Jul 2023 08:22:30 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4FEBA90000D; Tue, 4 Jul 2023 08:22:30 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 428D790001A for ; Tue, 4 Jul 2023 08:22:30 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id E5521140A3D for ; Tue, 4 Jul 2023 12:22:29 +0000 (UTC) X-FDA: 80973842418.14.954B436 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by imf12.hostedemail.com (Postfix) with ESMTP id A6AF140011 for ; Tue, 4 Jul 2023 12:22:27 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=a81BmTCZ; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=Cm9YT4Ht; spf=pass (imf12.hostedemail.com: domain of jack@suse.cz designates 195.135.220.28 as permitted sender) smtp.mailfrom=jack@suse.cz; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1688473347; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=mdnEy6doZuj4T4K7nSzTIyIECtQFFVt3/RzDP88gsmY=; b=gcddiOg9lIwCUtmoPOZWxWZ+o34vYfloK0twr+tZd4k6+9JXztH4o7jQoI1BFVirjZ05oW VA016fqJSWM3numBkHzI7Bi5WplYKyVO4anXgfE3SunFo8iePr/a74iy71IOG5rJxa5HdS dsIT7O+qTNA823CvQZ4TjStaqGMsNeM= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1688473347; a=rsa-sha256; cv=none; b=hSmPHVDIf3MI8HkONk3+kZvXvW0+H/qdglTr5ViWblOacHJMvTiK84CYBYd/P7Uxw3GOjV 3DCfPiTUXcbNgfewuJeajOmPu40miSkmk5dMxPpRP8+SWZwFG6pUb8zYPg8DjE3+tOOmsu R3ylqLfwfqVsHR/TrKsjcH3lgeh0R34= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=a81BmTCZ; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=Cm9YT4Ht; spf=pass (imf12.hostedemail.com: domain of jack@suse.cz designates 195.135.220.28 as permitted sender) smtp.mailfrom=jack@suse.cz; dmarc=none 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-out1.suse.de (Postfix) with ESMTPS id 6A18822873; Tue, 4 Jul 2023 12:22:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1688473346; 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=mdnEy6doZuj4T4K7nSzTIyIECtQFFVt3/RzDP88gsmY=; b=a81BmTCZ90hLkXKtL+oiXj66o12wEJNqm/5N+YhSzQN//2u76/Sx/Ix2IzjSd2/ieb0Izd L1C0d9f7SEEFrpVNL1TLjbeBzGvcTpJYG4FMamPZHYghYBGMRk3zka0XU61wA63v6wqVX1 uWHCCk/yQiEzKPBOl5UqSaLQoClKgwg= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1688473346; 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=mdnEy6doZuj4T4K7nSzTIyIECtQFFVt3/RzDP88gsmY=; b=Cm9YT4HtRVGdabVASUQcZymzmzyV9VOKtf4HzOMxaRIqr1Q9vWi5U4iD7mqh2LYosKOtIu 5TQo9zlahslRH/Dw== 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 59B9513A98; Tue, 4 Jul 2023 12:22:26 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id /63gFQIPpGREMAAAMHmgww (envelope-from ); Tue, 04 Jul 2023 12:22:26 +0000 Received: by quack3.suse.cz (Postfix, from userid 1000) id 0CA26A077D; Tue, 4 Jul 2023 14:22:25 +0200 (CEST) From: Jan Kara To: Cc: , Jens Axboe , Christoph Hellwig , Jan Kara , linux-mm@kvack.org, Andrew Morton Subject: [PATCH 19/32] mm/swap: Convert to use blkdev_get_handle_by_dev() Date: Tue, 4 Jul 2023 14:21:46 +0200 Message-Id: <20230704122224.16257-19-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=2688; i=jack@suse.cz; h=from:subject; bh=wVpmIfN/eR5Ua8hSYo1mzxPGdVVPf7LYMVYIJFGGkHQ=; b=owEBbQGS/pANAwAIAZydqgc/ZEDZAcsmYgBkpA7bCKbxtHM46e9K00CmUmLKjtHbRBO9emBILVuZ hg9lmwOJATMEAAEIAB0WIQSrWdEr1p4yirVVKBycnaoHP2RA2QUCZKQO2wAKCRCcnaoHP2RA2ZCWB/ 9gpG67tIbc+Tvq85swoTN5lhCJ84EUHxZ+l5N6M6RpnR6hh+jUdzysCV/gfzdf1IbOkpwLhbsByeDB NQK6WTFg6tM7pUKTgqv/9CZqTqZO2ZB0/tgItgl6jf5ZirEuiXBAj45bkJ4h2HrruVsjBt4B4LX9L/ py35F0C37hdadhgcSfE9tc+xYWd3bolllxfISCrrBWE3c4Wi5DFCN9K749Vkfr4MxWifCJvhyxx/Bg aU9voIO+nVorMt8dwQgXwJlfWefUHOqn7RsZbwmNrvt4QHtSHaBMIfyXBLP29YS9QqPnq9s8ih2F+V KexxrhIyaScM7/+txmNwayQDHvcUcx X-Developer-Key: i=jack@suse.cz; a=openpgp; fpr=93C6099A142276A28BBE35D815BC833443038D8C X-Stat-Signature: t1naeinwz3gcejew6a6k5kwgym3nkcu5 X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: A6AF140011 X-Rspam-User: X-HE-Tag: 1688473347-362785 X-HE-Meta: U2FsdGVkX1/VPQN46O2Vpu0ft3joheDlfvzENaLZtmmKPH3uXYhayPNRHOwfPSiyV4Qlz+fU2abWktGlxCUlkZKQn6fXM2GqH/YtfZ16XLKPP7sICzr2liOgq/o0SUMZoVF8639oQOO/y81FZZycm8OJh2VXj4GE7rolNY0aF1vqyfOeQGF5QO0rtC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u1YbyFzWL0bZ7k8lXRtSQMBDNv8l5bhnvIUgcbayr74Hr2I46zmV4CWoyHp+NgTJpxDOL35Cs8Om8 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: Convert swapping code to use blkdev_get_handle_by_dev() and pass the handle around. CC: linux-mm@kvack.org CC: Andrew Morton Signed-off-by: Jan Kara --- include/linux/swap.h | 1 + mm/swapfile.c | 21 ++++++++++----------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/include/linux/swap.h b/include/linux/swap.h index 456546443f1f..62334f8d4932 100644 --- a/include/linux/swap.h +++ b/include/linux/swap.h @@ -298,6 +298,7 @@ struct swap_info_struct { unsigned int __percpu *cluster_next_cpu; /*percpu index for next allocation */ struct percpu_cluster __percpu *percpu_cluster; /* per cpu's swap location */ struct rb_root swap_extent_root;/* root of the swap extent rbtree */ + struct bdev_handle *bdev_handle;/* open handle of the bdev */ struct block_device *bdev; /* swap device or bdev of swap file */ struct file *swap_file; /* seldom referenced */ unsigned int old_block_size; /* seldom referenced */ diff --git a/mm/swapfile.c b/mm/swapfile.c index 8e6dde68b389..dbd37aa4724d 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -2526,11 +2526,9 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile) exit_swap_address_space(p->type); inode = mapping->host; - if (S_ISBLK(inode->i_mode)) { - struct block_device *bdev = I_BDEV(inode); - - set_blocksize(bdev, old_block_size); - blkdev_put(bdev, p); + if (p->bdev_handle) { + set_blocksize(p->bdev, old_block_size); + blkdev_handle_put(p->bdev_handle); } inode_lock(inode); @@ -2760,13 +2758,14 @@ static int claim_swapfile(struct swap_info_struct *p, struct inode *inode) int error; if (S_ISBLK(inode->i_mode)) { - p->bdev = blkdev_get_by_dev(inode->i_rdev, + p->bdev_handle = blkdev_get_handle_by_dev(inode->i_rdev, BLK_OPEN_READ | BLK_OPEN_WRITE, p, NULL); - if (IS_ERR(p->bdev)) { - error = PTR_ERR(p->bdev); - p->bdev = NULL; + if (IS_ERR(p->bdev_handle)) { + error = PTR_ERR(p->bdev_handle); + p->bdev_handle = NULL; return error; } + p->bdev = p->bdev_handle->bdev; p->old_block_size = block_size(p->bdev); error = set_blocksize(p->bdev, PAGE_SIZE); if (error < 0) @@ -3210,9 +3209,9 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags) p->percpu_cluster = NULL; free_percpu(p->cluster_next_cpu); p->cluster_next_cpu = NULL; - if (inode && S_ISBLK(inode->i_mode) && p->bdev) { + if (p->bdev_handle) { set_blocksize(p->bdev, p->old_block_size); - blkdev_put(p->bdev, p); + blkdev_handle_put(p->bdev_handle); } inode = NULL; destroy_swap_extents(p);