From patchwork Mon Sep 18 15:52:21 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukas Czerner X-Patchwork-Id: 9957013 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 1962B6039A for ; Mon, 18 Sep 2017 15:53:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0814328CCE for ; Mon, 18 Sep 2017 15:53:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EF4FA28D1C; Mon, 18 Sep 2017 15:52:59 +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,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 9553B28CCE for ; Mon, 18 Sep 2017 15:52:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754478AbdIRPw6 (ORCPT ); Mon, 18 Sep 2017 11:52:58 -0400 Received: from mx1.redhat.com ([209.132.183.28]:52012 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753979AbdIRPw6 (ORCPT ); Mon, 18 Sep 2017 11:52:58 -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 D8EE34DAFA for ; Mon, 18 Sep 2017 15:52:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com D8EE34DAFA Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.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 733295D6A8; Mon, 18 Sep 2017 15:52:55 +0000 (UTC) From: Lukas Czerner To: linux-fsdevel@vger.kernel.org Cc: Lukas Czerner Subject: [PATCH 1/7] vfs: Introduce fallocate query support mode Date: Mon, 18 Sep 2017 17:52:21 +0200 Message-Id: <1505749947-26360-2-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.29]); Mon, 18 Sep 2017 15:52:58 +0000 (UTC) Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Filesystems are free to implement any subset of fallocate modes and there is currently no way of telling what modes are actually supported by the file system other than trying them all. Change this by introducing new fallocate mode FALLOC_FL_QUERY_SUPPORT that is supposed to return all supported modes. FALLOC_FL_QUERY_SUPPORT mode can be only used exclusively with offset and length set to zero. Signed-off-by: Lukas Czerner --- fs/open.c | 18 +++++++++++++++++- include/linux/falloc.h | 4 +++- include/uapi/linux/falloc.h | 13 +++++++++++++ 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/fs/open.c b/fs/open.c index 7ea1184..15c3fce 100644 --- a/fs/open.c +++ b/fs/open.c @@ -241,13 +241,22 @@ int vfs_fallocate(struct file *file, int mode, loff_t offset, loff_t len) struct inode *inode = file_inode(file); long ret; - if (offset < 0 || len <= 0) + if ((offset < 0 || len <= 0) && !(mode & FALLOC_FL_QUERY_SUPPORT)) return -EINVAL; /* Return error if mode is not supported */ if (mode & ~FALLOC_FL_SUPPORTED_MASK) return -EOPNOTSUPP; + /* offset and length are not used in query support */ + if ((mode & FALLOC_FL_QUERY_SUPPORT) && (offset != 0 || len != 0)) + return -EINVAL; + + /* Query support should only be used exclusively */ + if ((mode & FALLOC_FL_QUERY_SUPPORT) && + (mode & ~FALLOC_FL_QUERY_SUPPORT)) + return -EINVAL; + /* Punch hole and zero range are mutually exclusive */ if ((mode & (FALLOC_FL_PUNCH_HOLE | FALLOC_FL_ZERO_RANGE)) == (FALLOC_FL_PUNCH_HOLE | FALLOC_FL_ZERO_RANGE)) @@ -328,6 +337,13 @@ int vfs_fallocate(struct file *file, int mode, loff_t offset, loff_t len) if (ret == 0) fsnotify_modify(file); + /* + * Let's not allow file systems return any random data, just fallocate + * modes. + */ + if ((ret > 0) && (mode & FALLOC_FL_QUERY_SUPPORT)) + ret &= FALLOC_FL_SUPPORTED_MASK; + file_end_write(file); return ret; } diff --git a/include/linux/falloc.h b/include/linux/falloc.h index 7494dc6..1558bce 100644 --- a/include/linux/falloc.h +++ b/include/linux/falloc.h @@ -26,6 +26,8 @@ struct space_resv { FALLOC_FL_COLLAPSE_RANGE | \ FALLOC_FL_ZERO_RANGE | \ FALLOC_FL_INSERT_RANGE | \ - FALLOC_FL_UNSHARE_RANGE) + FALLOC_FL_QUERY_SUPPORT | \ + FALLOC_FL_UNSHARE_RANGE | \ + FALLOC_FL_PREALLOC_RANGE) #endif /* _FALLOC_H_ */ diff --git a/include/uapi/linux/falloc.h b/include/uapi/linux/falloc.h index b075f60..9959355 100644 --- a/include/uapi/linux/falloc.h +++ b/include/uapi/linux/falloc.h @@ -76,4 +76,17 @@ */ #define FALLOC_FL_UNSHARE_RANGE 0x40 +/* + * FALLOC_FL_QUERY_SUPPORT is used to query file system, or block device + * for a supported fallocate flags. + */ +#define FALLOC_FL_QUERY_SUPPORT 0x80 + +/* + * FALLOC_FL_PREALLOC_RANGE is a placeholder for a default preallocation + * mode. It has the same effect as not specifying any flag at all. We need + * this to report back support for this particular mode, + */ +#define FALLOC_FL_PREALLOC_RANGE 0x100 + #endif /* _UAPI_FALLOC_H_ */