From patchwork Sat Apr 27 21:10:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Al Viro X-Patchwork-Id: 13645760 Received: from zeniv.linux.org.uk (zeniv.linux.org.uk [62.89.141.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2BED863B9; Sat, 27 Apr 2024 21:10:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=62.89.141.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714252211; cv=none; b=Vzm9e+w3h6YBkQ4upplzg0Kk3sttNjTzSGp7xzRqj50MQAWe2zo0GHeUZ3Nrx/SYVcVdZNiFmUZQYjU/cJUevsZhL7Fxvac0+tTiqIeHvHHrUoibl3AV44jUt9miGkCLQb8Orq/lrbROdBR6NjkAZc72Yg5GEAsR67DAKOyYfhI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714252211; c=relaxed/simple; bh=dVsV+suRWdeSLs4M2uRGgnhXWCL23HP01Bass/RE1+4=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=TTT0GdULWF6B30wUpIbkY1XBIqXx44GmR6S3gASqJAd/WYiC2En/esvCUw66u/DhaWAWavC+q58S1rtJsLtJTcG9QZwNLku2Cg8gTdr+iSEFY2ulRnanolBMEhyjyB+AmCf/S3APDbme/Mu6X82Iv+Hdwzora8IHjRFfZpaOxcE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=zeniv.linux.org.uk; spf=none smtp.mailfrom=ftp.linux.org.uk; dkim=pass (2048-bit key) header.d=linux.org.uk header.i=@linux.org.uk header.b=fZUZ8m1I; arc=none smtp.client-ip=62.89.141.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=zeniv.linux.org.uk Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=ftp.linux.org.uk Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linux.org.uk header.i=@linux.org.uk header.b="fZUZ8m1I" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=linux.org.uk; s=zeniv-20220401; h=Sender:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=xFS+qBCy2Bcky/O/uXQHGoo0wfXXcYfy2ak+7vNvwmw=; b=fZUZ8m1IEx8EYaPX7L6Cex2RE5 GlWSFtLJkNHsVnz4B0d+O8+7nCN1fcfzqKWhJKzsEuE5x9mWnIriMFjWghPzG/LUMf6csTtHgC0Xr hk0fkR41EgBmilvf2XJR/0JDKXohhk6qTriDjghnT4pS6WtKnGmKuzZFnrqVefGsqXPqgXJBTz33J Ke7S8cebKcAAMdQLO+pZG4SxbiGBqpbOIXkD7cD0VnriPyaVXoHzYs6j5wX7ta6Vf6zJ5TG1wq8ok Zb5rKClmJXRDqke4GG2XKAPntgEHalyHA3ShzPnw0hmPTInuyzsRaFNM+Gu9CcgCkEqvS/eJVlEt8 tqFyM05A==; Received: from viro by zeniv.linux.org.uk with local (Exim 4.96 #2 (Red Hat Linux)) id 1s0pJ9-006H26-0S; Sat, 27 Apr 2024 21:10:07 +0000 Date: Sat, 27 Apr 2024 22:10:07 +0100 From: Al Viro To: linux-fsdevel@vger.kernel.org Cc: Linus Torvalds , Christian Brauner , Christoph Hellwig , linux-block@vger.kernel.org, Jens Axboe , linux-btrfs@vger.kernel.org, "Rafael J. Wysocki" , Andrew Morton Subject: [PATCH 1/7] bcache_register(): don't bother with set_blocksize() Message-ID: <20240427211007.GA1495312@ZenIV> References: <20240427210920.GR2118490@ZenIV> Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20240427210920.GR2118490@ZenIV> Sender: Al Viro We are not using __bread() anymore and read_cache_page_gfp() doesn't care about block size. Moreover, we should *not* change block size on a device that is currently held exclusive - filesystems that use buffer cache expect the block numbers to be interpreted in units set by filesystem. ACKed-by: Kent Overstreet Signed-off-by: Al Viro Reviewed-by: Christoph Hellwig Reviewed-by: Christian Brauner --- drivers/md/bcache/super.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c index 330bcd9ea4a9..0ee5e17ae2dd 100644 --- a/drivers/md/bcache/super.c +++ b/drivers/md/bcache/super.c @@ -2554,10 +2554,6 @@ static ssize_t register_bcache(struct kobject *k, struct kobj_attribute *attr, if (IS_ERR(bdev_file)) goto out_free_sb; - err = "failed to set blocksize"; - if (set_blocksize(file_bdev(bdev_file), 4096)) - goto out_blkdev_put; - err = read_super(sb, file_bdev(bdev_file), &sb_disk); if (err) goto out_blkdev_put; From patchwork Sat Apr 27 21:10:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Al Viro X-Patchwork-Id: 13645761 Received: from zeniv.linux.org.uk (zeniv.linux.org.uk [62.89.141.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9A3177829C; Sat, 27 Apr 2024 21:10:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=62.89.141.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714252236; cv=none; b=VkmVg2wAEt8A6xBhKtoQE8KwE66Q/EtIEIXNJRPLaatD/vbC0xJ92Z9i5i2yjwR1fsKSG34xCLg4Z4JDIlNn+jj35A7W4aNpetsolf/E1IQL7npjl2TWvfOb3ePdUY0Ew8tfppj/pJkJblZZaXt+M/oWZJHS00K6p4bjnqk7pqE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714252236; c=relaxed/simple; bh=keXklkI5MpK+WSOJstDI2j7Is+66EDTxHHrVeD4/YpQ=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=EjaoxRIFeH8ukA0M5HTiLqfbXdokWLOUC2II0juvmA7VqN9PBzHzN2gGPAI1949YzT5bNWPgcaPGVwZQzKTKALallkL1bonl/t0bAiYHih8FY1jJqxO/6ac989tANflBT4P7RIRI/oyIrv+3mmbJF51acf7FH4XvgFdjvZkBDao= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=zeniv.linux.org.uk; spf=none smtp.mailfrom=ftp.linux.org.uk; dkim=pass (2048-bit key) header.d=linux.org.uk header.i=@linux.org.uk header.b=X3sQcUSY; arc=none smtp.client-ip=62.89.141.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=zeniv.linux.org.uk Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=ftp.linux.org.uk Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linux.org.uk header.i=@linux.org.uk header.b="X3sQcUSY" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=linux.org.uk; s=zeniv-20220401; h=Sender:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=0qlr0K6sGy3kLxE9t546t+u43Rg6mO6BGU1U6yKNgEQ=; b=X3sQcUSY8DO28QtKAPTqvw2YZR 7wJEBmHL1p9UUTkkozrZ3OZVHqCAJav3cdl388Cbxb+1dJF6GR1VfPavqNsHwBp70BZt/H7KUsYig DQ8gDSFSTy2c2cuxquHethWunJUWC7CUfp6ldlKZIt2zYgwA1a48tGqDhW0nFYRVi1w2zIYNKWyWP XvjmdGyikmK5byznTq+4F5bVFfDFeQDQmlcf8iPij3erRhv75wWPa0cUUC2y4Y99cxzkn/+y8FRC/ BNY5VLWRMuIa4vzeDke7P361ytkyY8A4gzMUJUNA75OISehOsiG950ws3oxaYVr3wTrSgWKMVUP7P 66wF9E/w==; Received: from viro by zeniv.linux.org.uk with local (Exim 4.96 #2 (Red Hat Linux)) id 1s0pJY-006H3K-2k; Sat, 27 Apr 2024 21:10:33 +0000 Date: Sat, 27 Apr 2024 22:10:32 +0100 From: Al Viro To: linux-fsdevel@vger.kernel.org Cc: Linus Torvalds , Christian Brauner , Christoph Hellwig , linux-block@vger.kernel.org, Jens Axboe , linux-btrfs@vger.kernel.org, "Rafael J. Wysocki" , Andrew Morton Subject: [PATCH 2/7] pktcdvd: sort set_blocksize() calls out Message-ID: <20240427211032.GB1495312@ZenIV> References: <20240427210920.GR2118490@ZenIV> Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20240427210920.GR2118490@ZenIV> Sender: Al Viro 1) it doesn't make any sense to have ->open() call set_blocksize() on the device being opened - the caller will override that anyway. 2) setting block size on underlying device, OTOH, ought to be done when we are opening it exclusive - i.e. as part of pkt_open_dev(). Having it done at setup time doesn't guarantee us anything about the state at the time we start talking to it. Worse, if you happen to have the underlying device containing e.g. ext2 with 4Kb blocks that is currently mounted r/o, that set_blocksize() will confuse the hell out of filesystem. Signed-off-by: Al Viro Reviewed-by: Christoph Hellwig Reviewed-by: Christian Brauner --- drivers/block/pktcdvd.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c index 21728e9ea5c3..05933f25b397 100644 --- a/drivers/block/pktcdvd.c +++ b/drivers/block/pktcdvd.c @@ -2215,6 +2215,7 @@ static int pkt_open_dev(struct pktcdvd_device *pd, bool write) } dev_info(ddev, "%lukB available on disc\n", lba << 1); } + set_blocksize(file_bdev(bdev_file), CD_FRAMESIZE); return 0; @@ -2278,11 +2279,6 @@ static int pkt_open(struct gendisk *disk, blk_mode_t mode) ret = pkt_open_dev(pd, mode & BLK_OPEN_WRITE); if (ret) goto out_dec; - /* - * needed here as well, since ext2 (among others) may change - * the blocksize at mount time - */ - set_blocksize(disk->part0, CD_FRAMESIZE); } mutex_unlock(&ctl_mutex); mutex_unlock(&pktcdvd_mutex); @@ -2526,7 +2522,6 @@ static int pkt_new_dev(struct pktcdvd_device *pd, dev_t dev) __module_get(THIS_MODULE); pd->bdev_file = bdev_file; - set_blocksize(file_bdev(bdev_file), CD_FRAMESIZE); atomic_set(&pd->cdrw.pending_bios, 0); pd->cdrw.thread = kthread_run(kcdrwd, pd, "%s", pd->disk->disk_name); From patchwork Sat Apr 27 21:10:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Al Viro X-Patchwork-Id: 13645772 Received: from zeniv.linux.org.uk (zeniv.linux.org.uk [62.89.141.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E80883A8EF; Sat, 27 Apr 2024 21:11:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=62.89.141.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714252262; cv=none; b=VKouOY1LTVYR18emqg/vJsCAMllzKQLiVqxuNqJmhlpMx0eeCbtcD2w83OgSQLz4JuOQ4gi+DAuD7MBAuBytWwaYuOe3jtSTIa1kh0+c5RhGnICZmdBpCWRL3pwehlrrjxJgjRhnUdNDN9EIkKV2uALH7+/730jWCbpOievcMbg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714252262; c=relaxed/simple; bh=pV4AKnwLUN6/zLcC1XNnmdJnkupWesLB1fJcblepBfE=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=HUYPEPUjMYl58gPVa2ZPt3cpa1kO8jefSUI8DWHL7MNx0Q65KsKlPFeL0/WW+/+BFBJVsZcb/Uo+4x/zcUhKCUcQrfKMJUPUlZW5XjOLEXyj5cqqb0nCHSPjhzILjrtbrC+03g1f/N5On+KR3X2dIDUejDCR6pzaZ398v9vCV0w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=zeniv.linux.org.uk; spf=none smtp.mailfrom=ftp.linux.org.uk; dkim=pass (2048-bit key) header.d=linux.org.uk header.i=@linux.org.uk header.b=oW5Iw2xj; arc=none smtp.client-ip=62.89.141.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=zeniv.linux.org.uk Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=ftp.linux.org.uk Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linux.org.uk header.i=@linux.org.uk header.b="oW5Iw2xj" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=linux.org.uk; s=zeniv-20220401; h=Sender:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=ZtY0zDJFh1bfYVr5+ZZnCLSP+bf/SXfawfhTG/pucxs=; b=oW5Iw2xjh5J37/WSeVlsGwYIwK Emz20AS/AmmX1FhRZaZDmaLx3oElfpmrK74GulHgBM6d3OHlz5QpDpjGIsH5O2nSVKwjnBzcu7Ye8 zBfgEv16Cuu22zADjlGSzS9B0DSIwqvFsLVkUoDbcklvVhnjmB0MSTsY7HxXamylZc0Nh6FSWdI1Q tPD/5fnArCfj54pYAAjVh9o2cXS8zJgOyQdFXUbw+RXQ5+7rrAp9LDK3Pw/WNT3c0o6sEWslbs0Tx XHoQdPOYx0RxY4yBAmsaNfKKcesIT4P4LcOI+8I06no8EBuLgkOK2+TqR67gIkhDq9RyzM/jS4sQE Kw3CvaGg==; Received: from viro by zeniv.linux.org.uk with local (Exim 4.96 #2 (Red Hat Linux)) id 1s0pJz-006H4s-0g; Sat, 27 Apr 2024 21:10:59 +0000 Date: Sat, 27 Apr 2024 22:10:59 +0100 From: Al Viro To: linux-fsdevel@vger.kernel.org Cc: Linus Torvalds , Christian Brauner , Christoph Hellwig , linux-block@vger.kernel.org, Jens Axboe , linux-btrfs@vger.kernel.org, "Rafael J. Wysocki" , Andrew Morton Subject: [PATCH 3/7] swapon(2)/swapoff(2): don't bother with block size Message-ID: <20240427211059.GC1495312@ZenIV> References: <20240427210920.GR2118490@ZenIV> Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20240427210920.GR2118490@ZenIV> Sender: Al Viro once upon a time that used to matter; these days we do swap IO for swap devices at the level that doesn't give a damn about block size, buffer_head or anything of that sort - just attach the page to bio, set the location and size (the latter to PAGE_SIZE) and feed into queue. Signed-off-by: Al Viro Reviewed-by: Christoph Hellwig Reviewed-by: Christian Brauner --- include/linux/swap.h | 1 - mm/swapfile.c | 12 +----------- 2 files changed, 1 insertion(+), 12 deletions(-) diff --git a/include/linux/swap.h b/include/linux/swap.h index f53d608daa01..a5b640cca459 100644 --- a/include/linux/swap.h +++ b/include/linux/swap.h @@ -301,7 +301,6 @@ struct swap_info_struct { struct file *bdev_file; /* 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 */ struct completion comp; /* seldom referenced */ spinlock_t lock; /* * protect map scan related fields like diff --git a/mm/swapfile.c b/mm/swapfile.c index 4919423cce76..304f74d039f3 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -2417,7 +2417,6 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile) struct inode *inode; struct filename *pathname; int err, found = 0; - unsigned int old_block_size; if (!capable(CAP_SYS_ADMIN)) return -EPERM; @@ -2529,7 +2528,6 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile) } swap_file = p->swap_file; - old_block_size = p->old_block_size; p->swap_file = NULL; p->max = 0; swap_map = p->swap_map; @@ -2553,7 +2551,6 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile) inode = mapping->host; if (p->bdev_file) { - set_blocksize(p->bdev, old_block_size); fput(p->bdev_file); p->bdev_file = NULL; } @@ -2782,21 +2779,15 @@ static struct swap_info_struct *alloc_swap_info(void) static int claim_swapfile(struct swap_info_struct *p, struct inode *inode) { - int error; - if (S_ISBLK(inode->i_mode)) { p->bdev_file = bdev_file_open_by_dev(inode->i_rdev, BLK_OPEN_READ | BLK_OPEN_WRITE, p, NULL); if (IS_ERR(p->bdev_file)) { - error = PTR_ERR(p->bdev_file); + int error = PTR_ERR(p->bdev_file); p->bdev_file = NULL; return error; } p->bdev = file_bdev(p->bdev_file); - p->old_block_size = block_size(p->bdev); - error = set_blocksize(p->bdev, PAGE_SIZE); - if (error < 0) - return error; /* * Zoned block devices contain zones that have a sequential * write only restriction. Hence zoned block devices are not @@ -3235,7 +3226,6 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags) free_percpu(p->cluster_next_cpu); p->cluster_next_cpu = NULL; if (p->bdev_file) { - set_blocksize(p->bdev, p->old_block_size); fput(p->bdev_file); p->bdev_file = NULL; } From patchwork Sat Apr 27 21:11:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Al Viro X-Patchwork-Id: 13645773 Received: from zeniv.linux.org.uk (zeniv.linux.org.uk [62.89.141.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EBC483A8EF; Sat, 27 Apr 2024 21:11:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=62.89.141.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714252292; cv=none; b=frOhVcy6qbW973+NBWgmT7Ka6DGLnKncmxYbJLeb8mIcnMFX24rphkM9O+vVezUCUtYTlEdiojbw5ee9mY3M+FTyCgS6QzgJ5QVrIIRNECFuWMCqXi6ShwxCKG+Et35sqrJ2j2ejxZ/1oMO9N3+LQUpLnoyKD2GS86WTEMJNe1M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714252292; c=relaxed/simple; bh=Dq5f+ejUETiFzRlLl7Y5xg/5QsFIWYNnilGxhCvIZK0=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=mIw46uT8WwPSZhoH+ptsIX7vcgdwwc3zly1AD0KpoC2ngF3uOF18FD0gU/KGZe2w+Acrw3rdLV+4t2BuGA9GG51nULZ7u/jZdaFRbOUAfcy+9o81W0V9hNAYe0gH8j+6iNiPerimOR1s2UjTRcV8rPU08dJ39zZheNWF0dGNa6w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=zeniv.linux.org.uk; spf=none smtp.mailfrom=ftp.linux.org.uk; dkim=pass (2048-bit key) header.d=linux.org.uk header.i=@linux.org.uk header.b=nVWT2uoE; arc=none smtp.client-ip=62.89.141.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=zeniv.linux.org.uk Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=ftp.linux.org.uk Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linux.org.uk header.i=@linux.org.uk header.b="nVWT2uoE" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=linux.org.uk; s=zeniv-20220401; h=Sender:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=vtUeEAm40my/mX+7c/W6sObNsUyFrfkBXLiOVdV8j6c=; b=nVWT2uoExcrdvF43eehWNT4Dds //4aNiCI8Pa5L9TLDC+kVmTqqZ5j8JTSD07b78/XIqveealmG2PTwT3eNRLq7iB7Dex14fnJFKXSc FmPsZ18sKMoqZjEGUAyNKoTwDlaEV/4cIc58pV+rGwpvl3y4eLZZoruIMZAJHErm6bkLKAhhszlMh X3dgTy+BQlB6otIRhsXFt1RdTEOzRaVwkjr2pvgt9JtiQ6kvrRxPKNB7QrO8PXEhS2xPGHTRifZDt F6ZpBL+FJY5+f499oKaa4NkDLpblohAKJC+SnGn3cUxmLS9oklO4nFj+4tYDLH3MVkTABr2IB6+Zk W/GANHHw==; Received: from viro by zeniv.linux.org.uk with local (Exim 4.96 #2 (Red Hat Linux)) id 1s0pKS-006H66-0m; Sat, 27 Apr 2024 21:11:28 +0000 Date: Sat, 27 Apr 2024 22:11:28 +0100 From: Al Viro To: linux-fsdevel@vger.kernel.org Cc: Linus Torvalds , Christian Brauner , Christoph Hellwig , linux-block@vger.kernel.org, Jens Axboe , linux-btrfs@vger.kernel.org, "Rafael J. Wysocki" , Andrew Morton Subject: [PATCH 4/7] swapon(2): open swap with O_EXCL Message-ID: <20240427211128.GD1495312@ZenIV> References: <20240427210920.GR2118490@ZenIV> Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20240427210920.GR2118490@ZenIV> Sender: Al Viro ... eliminating the need to reopen block devices so they could be exclusively held. Signed-off-by: Al Viro Signed-off-by: Al Viro Reviewed-by: Christoph Hellwig Reviewed-by: Christian Brauner --- include/linux/swap.h | 1 - mm/swapfile.c | 19 ++----------------- 2 files changed, 2 insertions(+), 18 deletions(-) diff --git a/include/linux/swap.h b/include/linux/swap.h index a5b640cca459..7e61a4aef2fc 100644 --- a/include/linux/swap.h +++ b/include/linux/swap.h @@ -298,7 +298,6 @@ 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 file *bdev_file; /* open handle of the bdev */ struct block_device *bdev; /* swap device or bdev of swap file */ struct file *swap_file; /* seldom referenced */ struct completion comp; /* seldom referenced */ diff --git a/mm/swapfile.c b/mm/swapfile.c index 304f74d039f3..71cb76a2d0ce 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -2550,10 +2550,6 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile) exit_swap_address_space(p->type); inode = mapping->host; - if (p->bdev_file) { - fput(p->bdev_file); - p->bdev_file = NULL; - } inode_lock(inode); inode->i_flags &= ~S_SWAPFILE; @@ -2780,14 +2776,7 @@ static struct swap_info_struct *alloc_swap_info(void) static int claim_swapfile(struct swap_info_struct *p, struct inode *inode) { if (S_ISBLK(inode->i_mode)) { - p->bdev_file = bdev_file_open_by_dev(inode->i_rdev, - BLK_OPEN_READ | BLK_OPEN_WRITE, p, NULL); - if (IS_ERR(p->bdev_file)) { - int error = PTR_ERR(p->bdev_file); - p->bdev_file = NULL; - return error; - } - p->bdev = file_bdev(p->bdev_file); + p->bdev = I_BDEV(inode); /* * Zoned block devices contain zones that have a sequential * write only restriction. Hence zoned block devices are not @@ -3028,7 +3017,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags) name = NULL; goto bad_swap; } - swap_file = file_open_name(name, O_RDWR|O_LARGEFILE, 0); + swap_file = file_open_name(name, O_RDWR|O_LARGEFILE|O_EXCL, 0); if (IS_ERR(swap_file)) { error = PTR_ERR(swap_file); swap_file = NULL; @@ -3225,10 +3214,6 @@ 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 (p->bdev_file) { - fput(p->bdev_file); - p->bdev_file = NULL; - } inode = NULL; destroy_swap_extents(p); swap_cgroup_swapoff(p->type); From patchwork Sat Apr 27 21:11:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Al Viro X-Patchwork-Id: 13645774 Received: from zeniv.linux.org.uk (zeniv.linux.org.uk [62.89.141.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C6FD0A94A; Sat, 27 Apr 2024 21:11:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=62.89.141.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714252319; cv=none; b=D5mLVaf1+ZcFQVxt/l+4AEGz1HkbXjRU8sODfAFwg3tUZ4wk+zPaR0EAw+WHt4RsCU1ck3KINSnpVR7k9Sy8b85ezj4FQC+xV+If84L2G8OWYt1gjsHUKLqQuufcfldjlT+EbHO6VLCr6zqpnc67Q0xBj37XdOJC0WNAu+0z8nE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714252319; c=relaxed/simple; bh=QgGwImN6jpVG+wtsSYEOgvYeCii6ig8WxuUbcd20cWY=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=NbhuVCxuKePFGmmYuKlaek/LixjIa22YByjd+uvFrnIXVelh8QIMu+5RoXH4hj4HWjdkBnvvZ/pcqcTG4UF1mkHLHETmwF1bUUmJM3vj41++zN6haPWwxgOo+oduRaLv9rMYSezWp1glk8sY8vMOBojH9q7s8ms6fVJ8YJkZ7E0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=zeniv.linux.org.uk; spf=none smtp.mailfrom=ftp.linux.org.uk; dkim=pass (2048-bit key) header.d=linux.org.uk header.i=@linux.org.uk header.b=Ro7FcQrR; arc=none smtp.client-ip=62.89.141.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=zeniv.linux.org.uk Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=ftp.linux.org.uk Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linux.org.uk header.i=@linux.org.uk header.b="Ro7FcQrR" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=linux.org.uk; s=zeniv-20220401; h=Sender:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=2lMOQ0YycRNGTONn7yZIj4k2x5DO9aZnEg8nbgmrNB8=; b=Ro7FcQrRMFIfEuK3esHGPFOWTz 3xywmrs95JpCnzXaAHOtHR01ffxcAPoRrV6IAdErreTcdgXiFU8cJNrZiXKv7VkXJ7bmOnP2jwMl+ 27yPhgHxWoWunqMOUkKNeOQbzfqghWYndy7n+eznD1U0kgv8w+hp9StzOGp0EdRWP/L9h8ADRxyNV 9F1xa4lofryKjcaRFJj14vaiboq4dfUS7uh8IX42x9IkLby5takqvpblCqXFOGDvEY33zgFnIl62t KpLUTBiFot+t1LJFqNGCL7LBkxk+JKGlNt0rRIRn9H3qOWwRe6SeqYuDy8dx/2kwb2Lsuw/eFXcb+ HQ5veOcw==; Received: from viro by zeniv.linux.org.uk with local (Exim 4.96 #2 (Red Hat Linux)) id 1s0pKu-006H7i-0s; Sat, 27 Apr 2024 21:11:56 +0000 Date: Sat, 27 Apr 2024 22:11:56 +0100 From: Al Viro To: linux-fsdevel@vger.kernel.org Cc: Linus Torvalds , Christian Brauner , Christoph Hellwig , linux-block@vger.kernel.org, Jens Axboe , linux-btrfs@vger.kernel.org, "Rafael J. Wysocki" , Andrew Morton Subject: [PATCH 5/7] swsusp: don't bother with setting block size Message-ID: <20240427211156.GE1495312@ZenIV> References: <20240427210920.GR2118490@ZenIV> Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20240427210920.GR2118490@ZenIV> Sender: Al Viro same as with the swap... Signed-off-by: Al Viro Reviewed-by: Christoph Hellwig Reviewed-by: Christian Brauner --- kernel/power/swap.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/kernel/power/swap.c b/kernel/power/swap.c index 5bc04bfe2db1..d9abb7ab031d 100644 --- a/kernel/power/swap.c +++ b/kernel/power/swap.c @@ -368,11 +368,7 @@ static int swsusp_swap_check(void) if (IS_ERR(hib_resume_bdev_file)) return PTR_ERR(hib_resume_bdev_file); - res = set_blocksize(file_bdev(hib_resume_bdev_file), PAGE_SIZE); - if (res < 0) - fput(hib_resume_bdev_file); - - return res; + return 0; } /** @@ -1574,7 +1570,6 @@ int swsusp_check(bool exclusive) hib_resume_bdev_file = bdev_file_open_by_dev(swsusp_resume_device, BLK_OPEN_READ, holder, NULL); if (!IS_ERR(hib_resume_bdev_file)) { - set_blocksize(file_bdev(hib_resume_bdev_file), PAGE_SIZE); clear_page(swsusp_header); error = hib_submit_io(REQ_OP_READ, swsusp_resume_block, swsusp_header, NULL); From patchwork Sat Apr 27 21:12:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Al Viro X-Patchwork-Id: 13645775 Received: from zeniv.linux.org.uk (zeniv.linux.org.uk [62.89.141.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B38F9A94A; Sat, 27 Apr 2024 21:12:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=62.89.141.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714252353; cv=none; b=t0zRrF41f6mgG26aXiCVAGqdpR7LFnilTivbGwZtr2zdzjdYxzPjoUqXoCKUc7YTN2UCesHwumq8z8EyP4zJTSn2i7uE8FRJaYWCyVCq1pXvPCl4UIVT3wyrfovAT8rL6x7AyA3LStc7VVbmlhf2zKJqe8NhhNNLvQUwOJZokFI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714252353; c=relaxed/simple; bh=fBiRQG4zecCqFY+7My1+SzX1mZB1ITQwnnWZw52sMRk=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=O9zOyVAodgAEeW4KxRuU6PzfybmRNAXjEu4vAlD/MQN8xHPZS7vjSubBGFdRLGI8OLIL8rzoZpXS8mVSV++LhcZ4BvrKqp/0cMCwavmSycLBUeGJtyLNcH4ZqRUMa3pHHgY2sN0tTWyfmxHwqlUQaSi6QMsLs95W7n1m+MMTwCE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=zeniv.linux.org.uk; spf=none smtp.mailfrom=ftp.linux.org.uk; dkim=pass (2048-bit key) header.d=linux.org.uk header.i=@linux.org.uk header.b=omTIS9S8; arc=none smtp.client-ip=62.89.141.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=zeniv.linux.org.uk Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=ftp.linux.org.uk Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linux.org.uk header.i=@linux.org.uk header.b="omTIS9S8" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=linux.org.uk; s=zeniv-20220401; h=Sender:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=BEkSoGdMPNYqtxDnNFJLbgBxb+qoovcKUxzy5IqMZzc=; b=omTIS9S86XvOfK19Z/zDAHAOUj Y2BpMZI0j7c9/sURct/WamvEk2BuCZxyIo/x5KgpasE2AczMrZTDqcegGBQXtk9AOdhEWorRi4Qbw d7YE+0iz7CKwKPEJWSD8QZMaHftIy6r4X8oFVWhNi7fogBzCa3V5CuYNTiWXZFBwUebfnTOcx0Y8k AFJkFjyZHjOdw1Uk5IVxJHPH1HXV5TJk7w5clQibvIFVMuU5iJKRjFB2EdBnBXj8b8Uvp3P5zLqof 07nnLYueFMseAB92B9ggiRpNCM9/ZW0Zn/sYHh+rp5NO2QBu8q9kWfBg+3rpxKKNNzsdpTd38NWPd 5qcva90Q==; Received: from viro by zeniv.linux.org.uk with local (Exim 4.96 #2 (Red Hat Linux)) id 1s0pLS-006H99-0M; Sat, 27 Apr 2024 21:12:30 +0000 Date: Sat, 27 Apr 2024 22:12:30 +0100 From: Al Viro To: linux-fsdevel@vger.kernel.org Cc: Linus Torvalds , Christian Brauner , Christoph Hellwig , linux-block@vger.kernel.org, Jens Axboe , linux-btrfs@vger.kernel.org, "Rafael J. Wysocki" , Andrew Morton Subject: [PATCH 6/7] btrfs_get_dev_args_from_path(): don't call set_blocksize() Message-ID: <20240427211230.GF1495312@ZenIV> References: <20240427210920.GR2118490@ZenIV> Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20240427210920.GR2118490@ZenIV> Sender: Al Viro We don't have bdev opened exclusive there. And I'm rather dubious about the need to do set_blocksize() anywhere in btrfs, to be honest - there's some access to page cache of underlying block devices in there, but it's nowhere near the hot paths, AFAICT. In any case, btrfs_get_dev_args_from_path() only needs to read the on-disk superblock and copy several fields out of it; all callers are only interested in devices that are already opened and brought into per-filesystem set, so setting the block size is redundant for those and actively harmful if we are given a pathname of unrelated device. Signed-off-by: Al Viro Reviewed-by: Christoph Hellwig Reviewed-by: Christian Brauner --- fs/btrfs/volumes.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index f15591f3e54f..43af5a9fb547 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -482,10 +482,12 @@ btrfs_get_bdev_and_sb(const char *device_path, blk_mode_t flags, void *holder, if (flush) sync_blockdev(bdev); - ret = set_blocksize(bdev, BTRFS_BDEV_BLOCKSIZE); - if (ret) { - fput(*bdev_file); - goto error; + if (holder) { + ret = set_blocksize(bdev, BTRFS_BDEV_BLOCKSIZE); + if (ret) { + fput(*bdev_file); + goto error; + } } invalidate_bdev(bdev); *disk_super = btrfs_read_dev_super(bdev); @@ -498,6 +500,7 @@ btrfs_get_bdev_and_sb(const char *device_path, blk_mode_t flags, void *holder, return 0; error: + *disk_super = NULL; *bdev_file = NULL; return ret; } From patchwork Sat Apr 27 21:13:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Al Viro X-Patchwork-Id: 13645776 Received: from zeniv.linux.org.uk (zeniv.linux.org.uk [62.89.141.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BACB5A94A; Sat, 27 Apr 2024 21:13:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=62.89.141.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714252388; cv=none; b=BpiywYQsYlYX38wYWvhjLOwvlHANPe+PRlOyQDz5TmOzfCCxTXkYanwam22TpPZ8VxYzACuQESCvE6nZ1Y4mzf4gklXakrO8sJvoWvyvb/xLU35U93NnkJePA17TPt68EmmO4mfqeUwhBPBDauwkdXKw6tNHpvkXclm6F1iIaBU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714252388; c=relaxed/simple; bh=r4NGhejj79ghjawb1edryTjprXuMxikLIrLf5O+qfUA=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=S1iWoMu9M5ZurOrCuSKD+SnRLKKX0t61BRmDG2IsXLwfjdE/DnQmSrp/mFwcuixonUf6gj3chWsYaLt+GIWfWiQ0cjLtGKdO+nG4eR73vjY+WTFglnSb5Ykheyuc5KceE0ydwX8DII2RF+1fy3tH7CXNnJpmvidNzupP4HgHIT4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=zeniv.linux.org.uk; spf=none smtp.mailfrom=ftp.linux.org.uk; dkim=pass (2048-bit key) header.d=linux.org.uk header.i=@linux.org.uk header.b=UiBsKh7/; arc=none smtp.client-ip=62.89.141.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=zeniv.linux.org.uk Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=ftp.linux.org.uk Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linux.org.uk header.i=@linux.org.uk header.b="UiBsKh7/" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=linux.org.uk; s=zeniv-20220401; h=Sender:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=T09a3W2M0shAKd9LrH44PfI4tW9LI+0vm0S2Nbv0AhQ=; b=UiBsKh7/9WyTJ7r7iPYPSJPmlb guVLn9LqAICStN8o8btol1aGryFeHpJkPC+UtSlRxWLd5qb2wltp9Xy+E+885mvoSiAGIL0iMxLh8 rz0Kg2NHX31ObY6XWc2ncuvJ1/mq7vgeC1oTdhwRN+jVrCgHsAGSffG7r46Dc1El7LJJxgub5/gpQ HwMrV2MDbi4yWs4/Gwo6CzEhTty7mt6FcVhsPBq3RH+pUJV8a0PxSZBX07U+bRmGGL2DFCDSRRyC5 gNhL+zTd5sUkklUjJey97nqpuxkCvl2mMaOLUTLOeiECY8Lz1e426CeilocbkIvCUYwf00ufB6lww R8HiciCw==; Received: from viro by zeniv.linux.org.uk with local (Exim 4.96 #2 (Red Hat Linux)) id 1s0pM1-006HAz-0A; Sat, 27 Apr 2024 21:13:05 +0000 Date: Sat, 27 Apr 2024 22:13:05 +0100 From: Al Viro To: linux-fsdevel@vger.kernel.org Cc: Linus Torvalds , Christian Brauner , Christoph Hellwig , linux-block@vger.kernel.org, Jens Axboe , linux-btrfs@vger.kernel.org, "Rafael J. Wysocki" , Andrew Morton Subject: [PATCH 7/7] set_blocksize(): switch to passing struct file *, fail if it's not opened exclusive Message-ID: <20240427211305.GG1495312@ZenIV> References: <20240427210920.GR2118490@ZenIV> Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20240427210920.GR2118490@ZenIV> Sender: Al Viro Signed-off-by: Al Viro Reviewed-by: Christian Brauner --- block/bdev.c | 14 ++++++++++---- block/ioctl.c | 21 ++++++++++++--------- drivers/block/pktcdvd.c | 2 +- fs/btrfs/dev-replace.c | 2 +- fs/btrfs/volumes.c | 4 ++-- fs/ext4/super.c | 2 +- fs/reiserfs/journal.c | 5 ++--- fs/xfs/xfs_buf.c | 2 +- include/linux/blkdev.h | 2 +- 9 files changed, 31 insertions(+), 23 deletions(-) diff --git a/block/bdev.c b/block/bdev.c index b8e32d933a63..a89bce368b64 100644 --- a/block/bdev.c +++ b/block/bdev.c @@ -144,8 +144,11 @@ static void set_init_blocksize(struct block_device *bdev) bdev->bd_inode->i_blkbits = blksize_bits(bsize); } -int set_blocksize(struct block_device *bdev, int size) +int set_blocksize(struct file *file, int size) { + struct inode *inode = file->f_mapping->host; + struct block_device *bdev = I_BDEV(inode); + /* Size must be a power of two, and between 512 and PAGE_SIZE */ if (size > PAGE_SIZE || size < 512 || !is_power_of_2(size)) return -EINVAL; @@ -154,10 +157,13 @@ int set_blocksize(struct block_device *bdev, int size) if (size < bdev_logical_block_size(bdev)) return -EINVAL; + if (!file->private_data) + return -EINVAL; + /* Don't change the size if it is same as current */ - if (bdev->bd_inode->i_blkbits != blksize_bits(size)) { + if (inode->i_blkbits != blksize_bits(size)) { sync_blockdev(bdev); - bdev->bd_inode->i_blkbits = blksize_bits(size); + inode->i_blkbits = blksize_bits(size); kill_bdev(bdev); } return 0; @@ -167,7 +173,7 @@ EXPORT_SYMBOL(set_blocksize); int sb_set_blocksize(struct super_block *sb, int size) { - if (set_blocksize(sb->s_bdev, size)) + if (set_blocksize(sb->s_bdev_file, size)) return 0; /* If we get here, we know size is power of two * and it's value is between 512 and PAGE_SIZE */ diff --git a/block/ioctl.c b/block/ioctl.c index a9028a2c2db5..1c800364bc70 100644 --- a/block/ioctl.c +++ b/block/ioctl.c @@ -473,11 +473,14 @@ static int compat_hdio_getgeo(struct block_device *bdev, #endif /* set the logical block size */ -static int blkdev_bszset(struct block_device *bdev, blk_mode_t mode, +static int blkdev_bszset(struct file *file, blk_mode_t mode, int __user *argp) { + // this one might be file_inode(file)->i_rdev - a rare valid + // use of file_inode() for those. + dev_t dev = I_BDEV(file->f_mapping->host)->bd_dev; + struct file *excl_file; int ret, n; - struct file *file; if (!capable(CAP_SYS_ADMIN)) return -EACCES; @@ -487,13 +490,13 @@ static int blkdev_bszset(struct block_device *bdev, blk_mode_t mode, return -EFAULT; if (mode & BLK_OPEN_EXCL) - return set_blocksize(bdev, n); + return set_blocksize(file, n); - file = bdev_file_open_by_dev(bdev->bd_dev, mode, &bdev, NULL); - if (IS_ERR(file)) + excl_file = bdev_file_open_by_dev(dev, mode, &dev, NULL); + if (IS_ERR(excl_file)) return -EBUSY; - ret = set_blocksize(bdev, n); - fput(file); + ret = set_blocksize(excl_file, n); + fput(excl_file); return ret; } @@ -621,7 +624,7 @@ long blkdev_ioctl(struct file *file, unsigned cmd, unsigned long arg) case BLKBSZGET: /* get block device soft block size (cf. BLKSSZGET) */ return put_int(argp, block_size(bdev)); case BLKBSZSET: - return blkdev_bszset(bdev, mode, argp); + return blkdev_bszset(file, mode, argp); case BLKGETSIZE64: return put_u64(argp, bdev_nr_bytes(bdev)); @@ -681,7 +684,7 @@ long compat_blkdev_ioctl(struct file *file, unsigned cmd, unsigned long arg) case BLKBSZGET_32: /* get the logical block size (cf. BLKSSZGET) */ return put_int(argp, bdev_logical_block_size(bdev)); case BLKBSZSET_32: - return blkdev_bszset(bdev, mode, argp); + return blkdev_bszset(file, mode, argp); case BLKGETSIZE64_32: return put_u64(argp, bdev_nr_bytes(bdev)); diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c index 05933f25b397..8a2ce8070010 100644 --- a/drivers/block/pktcdvd.c +++ b/drivers/block/pktcdvd.c @@ -2215,7 +2215,7 @@ static int pkt_open_dev(struct pktcdvd_device *pd, bool write) } dev_info(ddev, "%lukB available on disc\n", lba << 1); } - set_blocksize(file_bdev(bdev_file), CD_FRAMESIZE); + set_blocksize(bdev_file, CD_FRAMESIZE); return 0; diff --git a/fs/btrfs/dev-replace.c b/fs/btrfs/dev-replace.c index 7696beec4c21..7130040d92ab 100644 --- a/fs/btrfs/dev-replace.c +++ b/fs/btrfs/dev-replace.c @@ -316,7 +316,7 @@ static int btrfs_init_dev_replace_tgtdev(struct btrfs_fs_info *fs_info, set_bit(BTRFS_DEV_STATE_IN_FS_METADATA, &device->dev_state); set_bit(BTRFS_DEV_STATE_REPLACE_TGT, &device->dev_state); device->dev_stats_valid = 1; - set_blocksize(device->bdev, BTRFS_BDEV_BLOCKSIZE); + set_blocksize(bdev_file, BTRFS_BDEV_BLOCKSIZE); device->fs_devices = fs_devices; ret = btrfs_get_dev_zone_info(device, false); diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 43af5a9fb547..65c03ddecc59 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -483,7 +483,7 @@ btrfs_get_bdev_and_sb(const char *device_path, blk_mode_t flags, void *holder, if (flush) sync_blockdev(bdev); if (holder) { - ret = set_blocksize(bdev, BTRFS_BDEV_BLOCKSIZE); + ret = set_blocksize(*bdev_file, BTRFS_BDEV_BLOCKSIZE); if (ret) { fput(*bdev_file); goto error; @@ -2717,7 +2717,7 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_path set_bit(BTRFS_DEV_STATE_IN_FS_METADATA, &device->dev_state); clear_bit(BTRFS_DEV_STATE_REPLACE_TGT, &device->dev_state); device->dev_stats_valid = 1; - set_blocksize(device->bdev, BTRFS_BDEV_BLOCKSIZE); + set_blocksize(device->bdev_file, BTRFS_BDEV_BLOCKSIZE); if (seeding_dev) { btrfs_clear_sb_rdonly(sb); diff --git a/fs/ext4/super.c b/fs/ext4/super.c index 044135796f2b..9988b3a40b42 100644 --- a/fs/ext4/super.c +++ b/fs/ext4/super.c @@ -5873,7 +5873,7 @@ static struct file *ext4_get_journal_blkdev(struct super_block *sb, sb_block = EXT4_MIN_BLOCK_SIZE / blocksize; offset = EXT4_MIN_BLOCK_SIZE % blocksize; - set_blocksize(bdev, blocksize); + set_blocksize(bdev_file, blocksize); bh = __bread(bdev, sb_block, blocksize); if (!bh) { ext4_msg(sb, KERN_ERR, "couldn't read superblock of " diff --git a/fs/reiserfs/journal.c b/fs/reiserfs/journal.c index e539ccd39e1e..e477ee0ff35d 100644 --- a/fs/reiserfs/journal.c +++ b/fs/reiserfs/journal.c @@ -2626,8 +2626,7 @@ static int journal_init_dev(struct super_block *super, MAJOR(jdev), MINOR(jdev), result); return result; } else if (jdev != super->s_dev) - set_blocksize(file_bdev(journal->j_bdev_file), - super->s_blocksize); + set_blocksize(journal->j_bdev_file, super->s_blocksize); return 0; } @@ -2643,7 +2642,7 @@ static int journal_init_dev(struct super_block *super, return result; } - set_blocksize(file_bdev(journal->j_bdev_file), super->s_blocksize); + set_blocksize(journal->j_bdev_file, super->s_blocksize); reiserfs_info(super, "journal_init_dev: journal device: %pg\n", file_bdev(journal->j_bdev_file)); diff --git a/fs/xfs/xfs_buf.c b/fs/xfs/xfs_buf.c index f0fa02264eda..2dc0eacb0999 100644 --- a/fs/xfs/xfs_buf.c +++ b/fs/xfs/xfs_buf.c @@ -2043,7 +2043,7 @@ xfs_setsize_buftarg( btp->bt_meta_sectorsize = sectorsize; btp->bt_meta_sectormask = sectorsize - 1; - if (set_blocksize(btp->bt_bdev, sectorsize)) { + if (set_blocksize(btp->bt_bdev_file, sectorsize)) { xfs_warn(btp->bt_mount, "Cannot set_blocksize to %u on device %pg", sectorsize, btp->bt_bdev); diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index 172c91879999..20c749b2ebc2 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -1474,7 +1474,7 @@ static inline void bio_end_io_acct(struct bio *bio, unsigned long start_time) } int bdev_read_only(struct block_device *bdev); -int set_blocksize(struct block_device *bdev, int size); +int set_blocksize(struct file *file, int size); int lookup_bdev(const char *pathname, dev_t *dev);