From patchwork Thu Aug 24 07:03:43 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Omar Sandoval X-Patchwork-Id: 9919143 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 EEDE260327 for ; Thu, 24 Aug 2017 07:03:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E0F9428B50 for ; Thu, 24 Aug 2017 07:03:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D5E1628B65; Thu, 24 Aug 2017 07:03:57 +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 789D028B51 for ; Thu, 24 Aug 2017 07:03:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751258AbdHXHD5 (ORCPT ); Thu, 24 Aug 2017 03:03:57 -0400 Received: from mail-pg0-f54.google.com ([74.125.83.54]:33375 "EHLO mail-pg0-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751183AbdHXHD4 (ORCPT ); Thu, 24 Aug 2017 03:03:56 -0400 Received: by mail-pg0-f54.google.com with SMTP id t3so12573991pgt.0 for ; Thu, 24 Aug 2017 00:03:56 -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=+8wpFCtL9FW2ffyFFJYN8L9tN1j/Zu4L6nVC64JmsSc=; b=r86Q3M6A26zgXZ/yuGTVYvI/oWMHk0h/mjyz9RX6VoIi/pTW9j2B4314uY9gFEiPPh 62E4/43gaEAtDKYvroEFDqFvatV/Y9YQFkrWvCx8BiCSr5LZK2VenXzApMPPoMkFWBfL BuEEB0Sju9scvKptsqE0Z1YjgZfM6R5jIVmsMaoN+VbkOp1cgn/qeu44cPmgGi1Sa9HD 7lRY4JEFXn8HZB9OsNiiMjKiMXZbf1aJ0l74kM883tmxHoGwqaFvJ8bHiDYK+yca/wiN 9nIOX9uoRRlBd4ozh0e5jVHqwvHAtBNnkE5MlKiG8EfBmeZnRZTBs87IUC/0lnkN317k JwtA== 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=+8wpFCtL9FW2ffyFFJYN8L9tN1j/Zu4L6nVC64JmsSc=; b=g6Umf/PR3A3gX7+efpw1s7FObilU2KmggeMOZwKcvx0aUZhIqgRI1R/k62rF61Rgiz v3HN+3SyTdBultvgO6xXn4lVvJWWjWzjMT86reTeOyZfbOEXm+aOFOQmMTtmmqyZ7se2 w2i7VMKrHtUY7MKar4e8a8NtskKdCz5IQTothJ7SB8ZGu17BblKl+KkuoFslUV6pV9bt /aXF3gzJawxTS+GPxsIaIwY5vhXnD0okJABVAL37XXdqUcyTT5XhCrT+pHtRMirREYxh 2a/qrDmlyNcBmPbHpPP9LdAZjOQAOzf7ulLIjamCtM6UOShToBnjMVoWZFDzAkyMz6DL ghXA== X-Gm-Message-State: AHYfb5j7HzAmEQx73IAmmnRflXhnpzG3oo7k324/WdtHffmTQBhA4akV tYFwN2g/t5HVDZNtYRCAlg== X-Received: by 10.98.35.217 with SMTP id q86mr5543122pfj.148.1503558235490; Thu, 24 Aug 2017 00:03:55 -0700 (PDT) Received: from vader.thefacebook.com ([2620:10d:c090:180::1:90fd]) by smtp.gmail.com with ESMTPSA id g2sm6187459pgu.86.2017.08.24.00.03.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 24 Aug 2017 00:03:54 -0700 (PDT) From: Omar Sandoval To: linux-block@vger.kernel.org Cc: kernel-team@fb.com, Hannes Reinecke , Ming Lei , Karel Zak , Milan Broz Subject: [PATCH 3/4] loop: add ioctl for changing logical block size Date: Thu, 24 Aug 2017 00:03:43 -0700 Message-Id: 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 This is a different approach from the first attempt in f2c6df7dbf9a ("loop: support 4k physical blocksize"). Rather than extending LOOP_{GET,SET}_STATUS, add a separate ioctl just for setting the block size. Signed-off-by: Omar Sandoval Reviewed-by: Hannes Reinecke --- drivers/block/loop.c | 24 ++++++++++++++++++++++++ include/uapi/linux/loop.h | 1 + 2 files changed, 25 insertions(+) diff --git a/drivers/block/loop.c b/drivers/block/loop.c index 1a5b4ecf54ec..6b1d932028e3 100644 --- a/drivers/block/loop.c +++ b/drivers/block/loop.c @@ -1047,6 +1047,7 @@ static int loop_clr_fd(struct loop_device *lo) memset(lo->lo_encrypt_key, 0, LO_KEY_SIZE); memset(lo->lo_crypt_name, 0, LO_NAME_SIZE); memset(lo->lo_file_name, 0, LO_NAME_SIZE); + blk_queue_logical_block_size(lo->lo_queue, 512); if (bdev) { bdput(bdev); invalidate_bdev(bdev); @@ -1330,6 +1331,24 @@ static int loop_set_dio(struct loop_device *lo, unsigned long arg) return error; } +static int loop_set_block_size(struct loop_device *lo, unsigned long arg) +{ + if (lo->lo_state != Lo_bound) + return -ENXIO; + + if (arg < 512 || arg > PAGE_SIZE || !is_power_of_2(arg)) + return -EINVAL; + + blk_mq_freeze_queue(lo->lo_queue); + + blk_queue_logical_block_size(lo->lo_queue, arg); + loop_update_dio(lo); + + blk_mq_unfreeze_queue(lo->lo_queue); + + return 0; +} + static int lo_ioctl(struct block_device *bdev, fmode_t mode, unsigned int cmd, unsigned long arg) { @@ -1378,6 +1397,11 @@ static int lo_ioctl(struct block_device *bdev, fmode_t mode, if ((mode & FMODE_WRITE) || capable(CAP_SYS_ADMIN)) err = loop_set_dio(lo, arg); break; + case LOOP_SET_BLOCK_SIZE: + err = -EPERM; + if ((mode & FMODE_WRITE) || capable(CAP_SYS_ADMIN)) + err = loop_set_block_size(lo, arg); + break; default: err = lo->ioctl ? lo->ioctl(lo, cmd, arg) : -EINVAL; } diff --git a/include/uapi/linux/loop.h b/include/uapi/linux/loop.h index c8125ec1f4f2..23158dbe2424 100644 --- a/include/uapi/linux/loop.h +++ b/include/uapi/linux/loop.h @@ -88,6 +88,7 @@ struct loop_info64 { #define LOOP_CHANGE_FD 0x4C06 #define LOOP_SET_CAPACITY 0x4C07 #define LOOP_SET_DIRECT_IO 0x4C08 +#define LOOP_SET_BLOCK_SIZE 0x4C09 /* /dev/loop-control interface */ #define LOOP_CTL_ADD 0x4C80