From patchwork Wed Nov 11 08:26:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 322958 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=-9.9 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, UNWANTED_LANGUAGE_BODY, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable 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 1AD7EC388F9 for ; Wed, 11 Nov 2020 08:29:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BAC9A206F1 for ; Wed, 11 Nov 2020 08:29:45 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="J7buGI+/" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726962AbgKKI3e (ORCPT ); Wed, 11 Nov 2020 03:29:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33506 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726325AbgKKI1W (ORCPT ); Wed, 11 Nov 2020 03:27:22 -0500 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6C01BC0617A7; Wed, 11 Nov 2020 00:27:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=GTpuLBfYyo8TaeZo/z07ad7aIfYXt5VjexG6J+Un22Y=; b=J7buGI+/FIE7Z9SkwKpEv6Dzao H6Jb7XY7aLyNJQXzdjS8KYFAIVquuUqCDHM7hyICJO7/G/MCyKCn0iuzxejTcLdTDO2OcEOx0dcDS xhDrtjFYbZTHZdcrjKzLNs7zeWZH6NtDmauWmpSq/4neZW0FKJUBESEe2290E+/sWMUiz2KhrZVe1 zSq1a/6hxWMD2sjWBneREarqtdUM/v40hRmP7cNWbUvCbhYM5UtDwGuEnfrwRt02CysygTP9nvqBk hiXdS7b3AluL/i5ahJdcWqTTM/kEXp3nGDMSv/NxeIEiOg6Xnf7cpb5dGWOuvMZ+I/jr2gTe4ccJr Dzzb4ntg==; Received: from [2001:4bb8:180:6600:bcde:334f:863c:27b8] (helo=localhost) by casper.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1kclT4-0007Zh-93; Wed, 11 Nov 2020 08:27:02 +0000 From: Christoph Hellwig To: Jens Axboe Cc: Justin Sanders , Josef Bacik , Ilya Dryomov , Jack Wang , "Michael S. Tsirkin" , Jason Wang , Paolo Bonzini , Stefan Hajnoczi , Konrad Rzeszutek Wilk , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Minchan Kim , Mike Snitzer , Song Liu , "Martin K. Petersen" , dm-devel@redhat.com, linux-block@vger.kernel.org, drbd-dev@lists.linbit.com, nbd@other.debian.org, ceph-devel@vger.kernel.org, xen-devel@lists.xenproject.org, linux-raid@vger.kernel.org, linux-nvme@lists.infradead.org, linux-scsi@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH 02/24] loop: remove loop_set_size Date: Wed, 11 Nov 2020 09:26:36 +0100 Message-Id: <20201111082658.3401686-3-hch@lst.de> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201111082658.3401686-1-hch@lst.de> References: <20201111082658.3401686-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org Just use set_capacity_revalidate_and_notify directly, as this function can update the block device size as well when the last parameter is set to true. Signed-off-by: Christoph Hellwig --- drivers/block/loop.c | 37 +++++++------------------------------ 1 file changed, 7 insertions(+), 30 deletions(-) diff --git a/drivers/block/loop.c b/drivers/block/loop.c index cb1191d6e945f2..86eb7e0691eef5 100644 --- a/drivers/block/loop.c +++ b/drivers/block/loop.c @@ -241,23 +241,6 @@ loop_validate_block_size(unsigned short bsize) return 0; } -/** - * loop_set_size() - sets device size and notifies userspace - * @lo: struct loop_device to set the size for - * @size: new size of the loop device - * - * Callers must validate that the size passed into this function fits into - * a sector_t, eg using loop_validate_size() - */ -static void loop_set_size(struct loop_device *lo, loff_t size) -{ - struct block_device *bdev = lo->lo_device; - - bd_set_nr_sectors(bdev, size); - - set_capacity_revalidate_and_notify(lo->lo_disk, size, false); -} - static inline int lo_do_transfer(struct loop_device *lo, int cmd, struct page *rpage, unsigned roffs, @@ -1076,7 +1059,6 @@ static int loop_configure(struct loop_device *lo, fmode_t mode, struct address_space *mapping; struct block_device *claimed_bdev = NULL; int error; - loff_t size; bool partscan; unsigned short bsize; @@ -1164,9 +1146,8 @@ static int loop_configure(struct loop_device *lo, fmode_t mode, loop_update_dio(lo); loop_sysfs_init(lo); - size = get_loop_size(lo, file); - loop_set_size(lo, size); - + set_capacity_revalidate_and_notify(lo->lo_disk, get_loop_size(lo, file), + true); set_blocksize(bdev, S_ISBLK(inode->i_mode) ? block_size(inode->i_bdev) : PAGE_SIZE); @@ -1402,9 +1383,9 @@ loop_set_status(struct loop_device *lo, const struct loop_info64 *info) lo->lo_flags |= prev_lo_flags & ~LOOP_SET_STATUS_CLEARABLE_FLAGS; if (size_changed) { - loff_t new_size = get_size(lo->lo_offset, lo->lo_sizelimit, - lo->lo_backing_file); - loop_set_size(lo, new_size); + set_capacity_revalidate_and_notify(lo->lo_disk, + get_size(lo->lo_offset, lo->lo_sizelimit, + lo->lo_backing_file), true); } loop_config_discard(lo); @@ -1580,14 +1561,10 @@ loop_get_status64(struct loop_device *lo, struct loop_info64 __user *arg) { static int loop_set_capacity(struct loop_device *lo) { - loff_t size; - if (unlikely(lo->lo_state != Lo_bound)) return -ENXIO; - - size = get_loop_size(lo, lo->lo_backing_file); - loop_set_size(lo, size); - + set_capacity_revalidate_and_notify(lo->lo_disk, + get_loop_size(lo, lo->lo_backing_file), true); return 0; }