From patchwork Mon Sep 18 15:52:22 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukas Czerner X-Patchwork-Id: 814992 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-ext4-owner@vger.kernel.org; receiver=) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3xwrBc06H7z9s5L for ; Tue, 19 Sep 2017 01:53:12 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755362AbdIRPxC (ORCPT ); Mon, 18 Sep 2017 11:53:02 -0400 Received: from mx1.redhat.com ([209.132.183.28]:42434 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754499AbdIRPxC (ORCPT ); Mon, 18 Sep 2017 11:53:02 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CDD936A15; Mon, 18 Sep 2017 15:53:01 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com CDD936A15 Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=lczerner@redhat.com Received: from rh_laptop.brq.redhat.com (unknown [10.43.17.67]) by smtp.corp.redhat.com (Postfix) with ESMTP id 03CBF5D6A8; Mon, 18 Sep 2017 15:53:00 +0000 (UTC) From: Lukas Czerner To: linux-fsdevel@vger.kernel.org Cc: Lukas Czerner , linux-ext4@vger.kernel.org Subject: [PATCH 2/7] ext4: Implement fallocate query support mode Date: Mon, 18 Sep 2017 17:52:22 +0200 Message-Id: <1505749947-26360-3-git-send-email-lczerner@redhat.com> In-Reply-To: <1505749947-26360-1-git-send-email-lczerner@redhat.com> References: <1505749947-26360-1-git-send-email-lczerner@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Mon, 18 Sep 2017 15:53:01 +0000 (UTC) Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org Return all fallocate modes supported by ext4 file system. Ext4 does have a lot of exceptions for inodes with various features enabled so take that into account as well. Cc: linux-ext4@vger.kernel.org Signed-off-by: Lukas Czerner --- fs/ext4/ext4.h | 11 +++++++++++ fs/ext4/extents.c | 42 ++++++++++++++++++------------------------ 2 files changed, 29 insertions(+), 24 deletions(-) diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h index e2abe01..6546c2c 100644 --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h @@ -558,6 +558,17 @@ enum { }; /* + * Supported fallocate modes + */ +#define EXT4_FALLOC_SUPPORTED (FALLOC_FL_KEEP_SIZE | \ + FALLOC_FL_PUNCH_HOLE | \ + FALLOC_FL_COLLAPSE_RANGE | \ + FALLOC_FL_ZERO_RANGE | \ + FALLOC_FL_INSERT_RANGE | \ + FALLOC_FL_QUERY_SUPPORT | \ + FALLOC_FL_PREALLOC_RANGE) + +/* * Flags used by ext4_map_blocks() */ /* Allocate any needed blocks and/or convert an unwritten diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c index 97f0fd0..91071b3 100644 --- a/fs/ext4/extents.c +++ b/fs/ext4/extents.c @@ -4905,7 +4905,7 @@ long ext4_fallocate(struct file *file, int mode, loff_t offset, loff_t len) loff_t new_size = 0; unsigned int max_blocks; int ret = 0; - int flags; + int flags = 0; ext4_lblk_t lblk; unsigned int blkbits = inode->i_blkbits; @@ -4919,17 +4919,27 @@ long ext4_fallocate(struct file *file, int mode, loff_t offset, loff_t len) * leave it disabled for encrypted inodes for now. This is a * bug we should fix.... */ - if (ext4_encrypted_inode(inode) && - (mode & (FALLOC_FL_COLLAPSE_RANGE | FALLOC_FL_INSERT_RANGE | - FALLOC_FL_ZERO_RANGE))) - return -EOPNOTSUPP; + if (ext4_encrypted_inode(inode)) { + /* Modes not supported on encrypted indoes */ + flags |= (FALLOC_FL_COLLAPSE_RANGE | + FALLOC_FL_INSERT_RANGE | + FALLOC_FL_ZERO_RANGE); + } + if (!ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS)) { + /* Modes not supported on non-extent inodes */ + flags |= (FALLOC_FL_COLLAPSE_RANGE | + FALLOC_FL_INSERT_RANGE | + FALLOC_FL_ZERO_RANGE | + FALLOC_FL_PREALLOC_RANGE); + } /* Return error if mode is not supported */ - if (mode & ~(FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE | - FALLOC_FL_COLLAPSE_RANGE | FALLOC_FL_ZERO_RANGE | - FALLOC_FL_INSERT_RANGE)) + if (mode & ~(EXT4_FALLOC_SUPPORTED & ~flags)) return -EOPNOTSUPP; + if (mode & FALLOC_FL_QUERY_SUPPORT) + return EXT4_FALLOC_SUPPORTED & ~flags; + if (mode & FALLOC_FL_PUNCH_HOLE) return ext4_punch_hole(inode, offset, len); @@ -5449,14 +5459,6 @@ int ext4_collapse_range(struct inode *inode, loff_t offset, loff_t len) loff_t new_size, ioffset; int ret; - /* - * We need to test this early because xfstests assumes that a - * collapse range of (0, 1) will return EOPNOTSUPP if the file - * system does not support collapse range. - */ - if (!ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS)) - return -EOPNOTSUPP; - /* Collapse range works only on fs block size aligned offsets. */ if (offset & (EXT4_CLUSTER_SIZE(sb) - 1) || len & (EXT4_CLUSTER_SIZE(sb) - 1)) @@ -5596,14 +5598,6 @@ int ext4_insert_range(struct inode *inode, loff_t offset, loff_t len) int ret = 0, depth, split_flag = 0; loff_t ioffset; - /* - * We need to test this early because xfstests assumes that an - * insert range of (0, 1) will return EOPNOTSUPP if the file - * system does not support insert range. - */ - if (!ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS)) - return -EOPNOTSUPP; - /* Insert range works only on fs block size aligned offsets. */ if (offset & (EXT4_CLUSTER_SIZE(sb) - 1) || len & (EXT4_CLUSTER_SIZE(sb) - 1))