From patchwork Thu May 8 10:24:42 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Namjae Jeon X-Patchwork-Id: 346980 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id D21A0140088 for ; Thu, 8 May 2014 20:25:00 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752947AbaEHKYq (ORCPT ); Thu, 8 May 2014 06:24:46 -0400 Received: from mailout4.samsung.com ([203.254.224.34]:25447 "EHLO mailout4.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752493AbaEHKYo (ORCPT ); Thu, 8 May 2014 06:24:44 -0400 Received: from epcpsbgr1.samsung.com (u141.gpu120.samsung.co.kr [203.254.230.141]) by mailout4.samsung.com (Oracle Communications Messaging Server 7u4-24.01 (7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0N5900J5R3L77W50@mailout4.samsung.com>; Thu, 08 May 2014 19:24:43 +0900 (KST) Received: from epcpsbgm1.samsung.com ( [172.20.52.116]) by epcpsbgr1.samsung.com (EPCPMTA) with SMTP id 86.01.18501.B6B5B635; Thu, 08 May 2014 19:24:43 +0900 (KST) X-AuditID: cbfee68d-b7f4e6d000004845-f9-536b5b6b62a9 Received: from epmmp1.local.host ( [203.254.227.16]) by epcpsbgm1.samsung.com (EPCPMTA) with SMTP id B8.35.27725.B6B5B635; Thu, 08 May 2014 19:24:43 +0900 (KST) Received: from DONAMJAEJEO06 ([10.88.104.63]) by mmp1.samsung.com (Oracle Communications Messaging Server 7u4-24.01 (7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTPA id <0N5900G3C3L64O60@mmp1.samsung.com>; Thu, 08 May 2014 19:24:42 +0900 (KST) From: Namjae Jeon To: 'Dave Chinner' , 'Theodore Ts'o' Cc: 'linux-ext4' , xfs@oss.sgi.com, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, 'Ashish Sangwan' Subject: [PATCH v2 1/10] fs: Add support FALLOC_FL_INSERT_RANGE for fallocate Date: Thu, 08 May 2014 19:24:42 +0900 Message-id: <003701cf6aa7$ba00c8d0$2e025a70$@samsung.com> MIME-version: 1.0 Content-type: text/plain; charset=us-ascii Content-transfer-encoding: 7bit X-Mailer: Microsoft Outlook 14.0 Thread-index: Ac9qp5ImXCTRP02WQyqa5euW3XEtIw== Content-language: ko X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrGIsWRmVeSWpSXmKPExsWyRsSkRDc7OjvY4PJpIYulEy8xW2w5do/R Yua8O2wWe/aeZLG4vGsOm0Vrz092i0V9txgd2D1OLZLwaDpzlNlj9YWtjB59W1YxenzeJBfA GsVlk5Kak1mWWqRvl8CVsWLBNqaCZWIV//ZuY2lgbBDqYuTgkBAwkXjznqmLkRPIFJO4cG89 WxcjF4eQwFJGie3rWtkhEiYSO/6dY4ZILGKUWPijlREkISTwl1Fiz2kJkEFsAtoSf7aIgoRF BDwlFh/fCjaIWWAlo8S94x/ZQBLCAr4Sb9pXs4LUswioSqw8YQwS5hWwlJj37DojhC0o8WPy PRYQm1lAS2L9zuNMELa8xOY1b5kh7lGQ2HH2NSPIGBEBPYljE8IhSkQk9r14xwiyVkLgGrvE xJcNYPUsAgIS3yYfYoH4V1Zi0wGoMZISB1fcYJnAKDYLyeZZSDbPQrJ5FpIVCxhZVjGKphYk FxQnpRcZ6hUn5haX5qXrJefnbmIExuHpf896dzDePmB9iDEZaP1EZinR5HxgHOeVxBsamxlZ mJqYGhuZW5qRJqwkzpv0MClISCA9sSQ1OzW1ILUovqg0J7X4ECMTB6dUA+MW+5kNUxXkVRgW yW7bbHJP4PWvuiVz7U4sl1hlusjoa5y12KYXYj4iqrI9J2/+WCEiMv+E9JNCPp3VimcTZ+5s ul+0yL9V+3/XgoXdZoqM2+wnrli2eMu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ter-Loop: Reflected Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org FALLOC_FL_INSERT_RANGE command is the opposite command of FALLOC_FL_COLLAPSE_RANGE that is needed for advertisers or someone who want to add some data in the middle of file. FALLOC_FL_INSERT_RANGE will insert a range of a file after shifting extents to right as given length. and this command also has same limitation as FALLOC_FL_COLLAPSE_RANGE, block boundary and use ftruncate(2) for crosses EOF. Signed-off-by: Namjae Jeon Signed-off-by: Ashish Sangwan --- fs/open.c | 8 +++++++- include/uapi/linux/falloc.h | 17 +++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/fs/open.c b/fs/open.c index 36662d0..74ed498 100644 --- a/fs/open.c +++ b/fs/open.c @@ -232,7 +232,8 @@ int do_fallocate(struct file *file, int mode, loff_t offset, loff_t len) /* 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_COLLAPSE_RANGE | FALLOC_FL_ZERO_RANGE | + FALLOC_FL_INSERT_RANGE)) return -EOPNOTSUPP; /* Punch hole and zero range are mutually exclusive */ @@ -250,6 +251,11 @@ int do_fallocate(struct file *file, int mode, loff_t offset, loff_t len) (mode & ~FALLOC_FL_COLLAPSE_RANGE)) return -EINVAL; + /* Insert range should only be used exclusively. */ + if ((mode & FALLOC_FL_INSERT_RANGE) && + (mode & ~FALLOC_FL_INSERT_RANGE)) + return -EINVAL; + if (!(file->f_mode & FMODE_WRITE)) return -EBADF; diff --git a/include/uapi/linux/falloc.h b/include/uapi/linux/falloc.h index d1197ae..f4d12eb 100644 --- a/include/uapi/linux/falloc.h +++ b/include/uapi/linux/falloc.h @@ -41,4 +41,21 @@ */ #define FALLOC_FL_ZERO_RANGE 0x10 +/* + * FALLOC_FL_INSERT_RANGE is use to allocate disk space within the file size + * without overwriting any existing data. The contents of the file beyond offset + * are shifted towards right by len bytes to create space for inserting + * new disk blocks and in this space new zeroed out disk blocks are inserted. + * As such, this operation will increase the size of the file by len bytes. + * Different filesystems may implement different limitations on the granularity + * of the operation. Most will limit operations to filesystem block size + * boundaries, but this boundary may be larger or smaller depending on + * the filesystem and/or the configuration of the filesystem or file. + * + * Attempting to allocate new blocks using this flag at OR beyond the end of + * the file is considered an illegal operation - just use ftruncate(2) or + * fallocate(2) with mode 0 for such type of operations. + */ +#define FALLOC_FL_INSERT_RANGE 0x20 + #endif /* _UAPI_FALLOC_H_ */