From patchwork Fri Aug 18 19:27:36 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Omar Sandoval X-Patchwork-Id: 9909827 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 385E8603FB for ; Fri, 18 Aug 2017 19:28:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 294C628D3F for ; Fri, 18 Aug 2017 19:28:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 18C6628D4E; Fri, 18 Aug 2017 19:28:33 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7597028D4F for ; Fri, 18 Aug 2017 19:28:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751446AbdHRT1r (ORCPT ); Fri, 18 Aug 2017 15:27:47 -0400 Received: from mail-pg0-f53.google.com ([74.125.83.53]:36689 "EHLO mail-pg0-f53.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750993AbdHRT1r (ORCPT ); Fri, 18 Aug 2017 15:27:47 -0400 Received: by mail-pg0-f53.google.com with SMTP id i12so70097018pgr.3 for ; Fri, 18 Aug 2017 12:27:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=osandov-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=DhcP/tYaarWg1D0GdggRA0ZJE+Z0iyxiur9DNHjIbDE=; b=b52hNzWdaaU2IA8ZAm+lrgDSvcQ/vY6iS0BrkWw7DhdqyG2J1n+ubfvznxaZAsLQCQ 7hFsQ5sLy5jIih2vkjCi7/l1q7wHiwvr+VyBqnqaSk6BycXQEgiwGU73xOxeY0F/7kNU TyhoPZBmYXOLrm89+qh8d7UA8X5VOqdBOazFezwqWJ1qpkYDhmj9jL3JYOchXuSQyuM2 0LUVizNZq0BCUTcHQCjvEXMVUoIXY+qFjBtzURxCx95u/A0Jnmo+7TOFmNutTeBZbMXH 4rJUfXysBlwrVEjSWs7J535EOE/+655G6TYXbHcnVtoinAfXae41jW0NleR2i5tTdCAR 6XrA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=DhcP/tYaarWg1D0GdggRA0ZJE+Z0iyxiur9DNHjIbDE=; b=E5zNuRp9RbTFuwYX0WdWOR6CIERjadIAkppnkYoReCxUrG+SKUpM82LPC2yALJ6qDh F/wm4+n4tApjrYSvPu81vzyYaXCQRDco4joag4GOUAgH5LV7lf91OXmvkjRZDl41yL+h AM+DMdqVKY4VGFBT1c4s1nKKgrbumXByDktd++9Yy+AQZ5hTOSkVYwsuKDbt612v/Wbk S1SriL214eJmpqtoyVgHVKLP3EbBUW8/3OA9zQLd/CsxLWts1YYY93qM4v/QPYMGiT5X k4Nq871p0IE4Bh2cpDVAS9tEkLQKNkhca3zDNyIuBkMIy7bHyRRDIkGcSYiNw7w0FLp1 Z2Sw== X-Gm-Message-State: AHYfb5irXVfEwtbnw5UBHzfEvk4YXhpn3Axogw9XLwBrgslxVTKSbv4X eB4bD4zOKJYBUwheuZUFfg== X-Received: by 10.99.125.13 with SMTP id y13mr5954014pgc.183.1503084466472; Fri, 18 Aug 2017 12:27:46 -0700 (PDT) Received: from vader.thefacebook.com ([2620:10d:c090:200::7:7002]) by smtp.gmail.com with ESMTPSA id d3sm9972633pgf.75.2017.08.18.12.27.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 18 Aug 2017 12:27:45 -0700 (PDT) From: Omar Sandoval To: linux-block@vger.kernel.org Cc: kernel-team@fb.com, Hannes Reinecke , Ming Lei , Karel Zak Subject: [PATCH v2 2/3] loop: use queue limit instead of private lo_logical_blocksize Date: Fri, 18 Aug 2017 12:27:36 -0700 Message-Id: <561f8505816afb6d0dacd4697087141c95566225.1503084216.git.osandov@fb.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: References: In-Reply-To: References: Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Omar Sandoval There's no reason to track this separately; just use the logical_block_size queue limit. Signed-off-by: Omar Sandoval Reviewed-by: Hannes Reinecke --- drivers/block/loop.c | 44 ++++++++++++++++++-------------------------- drivers/block/loop.h | 1 - 2 files changed, 18 insertions(+), 27 deletions(-) diff --git a/drivers/block/loop.c b/drivers/block/loop.c index 26548e07bc31..94227a327ce2 100644 --- a/drivers/block/loop.c +++ b/drivers/block/loop.c @@ -221,8 +221,7 @@ static void __loop_update_dio(struct loop_device *lo, bool dio) } static int -figure_loop_size(struct loop_device *lo, loff_t offset, loff_t sizelimit, - loff_t logical_blocksize) +figure_loop_size(struct loop_device *lo, loff_t offset, loff_t sizelimit) { loff_t size = get_size(offset, sizelimit, lo->lo_backing_file); sector_t x = (sector_t)size; @@ -234,12 +233,6 @@ figure_loop_size(struct loop_device *lo, loff_t offset, loff_t sizelimit, lo->lo_offset = offset; if (lo->lo_sizelimit != sizelimit) lo->lo_sizelimit = sizelimit; - if (lo->lo_flags & LO_FLAGS_BLOCKSIZE) { - lo->lo_logical_blocksize = logical_blocksize; - blk_queue_physical_block_size(lo->lo_queue, lo->lo_blocksize); - blk_queue_logical_block_size(lo->lo_queue, - lo->lo_logical_blocksize); - } set_capacity(lo->lo_disk, x); bd_set_size(bdev, (loff_t)get_capacity(bdev->bd_disk) << 9); /* let user-space know about the new size */ @@ -820,7 +813,7 @@ static void loop_config_discard(struct loop_device *lo) struct file *file = lo->lo_backing_file; struct inode *inode = file->f_mapping->host; struct request_queue *q = lo->lo_queue; - int lo_bits = 9; + int lo_bits = blksize_bits(queue_logical_block_size(q)); /* * We use punch hole to reclaim the free space used by the @@ -840,8 +833,6 @@ static void loop_config_discard(struct loop_device *lo) q->limits.discard_granularity = inode->i_sb->s_blocksize; q->limits.discard_alignment = 0; - if (lo->lo_flags & LO_FLAGS_BLOCKSIZE) - lo_bits = blksize_bits(lo->lo_logical_blocksize); blk_queue_max_discard_sectors(q, UINT_MAX >> lo_bits); blk_queue_max_write_zeroes_sectors(q, UINT_MAX >> lo_bits); @@ -938,7 +929,6 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode, lo->use_dio = false; lo->lo_blocksize = lo_blocksize; - lo->lo_logical_blocksize = 512; lo->lo_device = bdev; lo->lo_flags = lo_flags; lo->lo_backing_file = file; @@ -950,6 +940,9 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode, if (!(lo_flags & LO_FLAGS_READ_ONLY) && file->f_op->fsync) blk_queue_write_cache(lo->lo_queue, true, false); + blk_queue_logical_block_size(lo->lo_queue, 512); + blk_queue_physical_block_size(lo->lo_queue, 512); + blk_queue_io_min(lo->lo_queue, 512); loop_update_dio(lo); set_capacity(lo->lo_disk, size); @@ -1137,14 +1130,7 @@ loop_set_status(struct loop_device *lo, const struct loop_info64 *info) } else xfer = NULL; - err = loop_init_xfer(lo, xfer, info); - if (err) - goto exit; - if (info->lo_flags & LO_FLAGS_BLOCKSIZE) { - if (!(lo->lo_flags & LO_FLAGS_BLOCKSIZE)) - lo->lo_logical_blocksize = 512; - lo->lo_flags |= LO_FLAGS_BLOCKSIZE; if (LO_INFO_BLOCKSIZE(info) != 512 && LO_INFO_BLOCKSIZE(info) != 1024 && LO_INFO_BLOCKSIZE(info) != 2048 && @@ -1158,18 +1144,25 @@ loop_set_status(struct loop_device *lo, const struct loop_info64 *info) } } + err = loop_init_xfer(lo, xfer, info); + if (err) + goto exit; + if (lo->lo_offset != info->lo_offset || lo->lo_sizelimit != info->lo_sizelimit || - lo->lo_flags != lo_flags || - ((lo->lo_flags & LO_FLAGS_BLOCKSIZE) && - lo->lo_logical_blocksize != LO_INFO_BLOCKSIZE(info))) { - if (figure_loop_size(lo, info->lo_offset, info->lo_sizelimit, - LO_INFO_BLOCKSIZE(info))) { + lo->lo_flags != lo_flags) { + if (figure_loop_size(lo, info->lo_offset, info->lo_sizelimit)) { err = -EFBIG; goto exit; } } + if (info->lo_flags & LO_FLAGS_BLOCKSIZE) { + blk_queue_logical_block_size(lo->lo_queue, LO_INFO_BLOCKSIZE(info)); + blk_queue_physical_block_size(lo->lo_queue, LO_INFO_BLOCKSIZE(info)); + blk_queue_io_min(lo->lo_queue, LO_INFO_BLOCKSIZE(info)); + } + loop_config_discard(lo); memcpy(lo->lo_file_name, info->lo_file_name, LO_NAME_SIZE); @@ -1356,8 +1349,7 @@ static int loop_set_capacity(struct loop_device *lo) if (unlikely(lo->lo_state != Lo_bound)) return -ENXIO; - return figure_loop_size(lo, lo->lo_offset, lo->lo_sizelimit, - lo->lo_logical_blocksize); + return figure_loop_size(lo, lo->lo_offset, lo->lo_sizelimit); } static int loop_set_dio(struct loop_device *lo, unsigned long arg) diff --git a/drivers/block/loop.h b/drivers/block/loop.h index 2c096b9a17b8..fecd3f97ef8c 100644 --- a/drivers/block/loop.h +++ b/drivers/block/loop.h @@ -49,7 +49,6 @@ struct loop_device { struct file * lo_backing_file; struct block_device *lo_device; unsigned lo_blocksize; - unsigned lo_logical_blocksize; void *key_data; gfp_t old_gfp_mask;