From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933444AbbBQJWI (ORCPT ); Tue, 17 Feb 2015 04:22:08 -0500 Received: from mailout2.samsung.com ([203.254.224.25]:55685 "EHLO mailout2.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756366AbbBQJWF (ORCPT ); Tue, 17 Feb 2015 04:22:05 -0500 X-AuditID: cbfee68f-f791c6d000004834-93-54e3083a8fbd From: Namjae Jeon To: Dave Chinner Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, xfs@oss.sgi.com, Brian Foster , Ashish Sangwan Subject: [PATCH v10 1/12] fs: Add support FALLOC_FL_INSERT_RANGE for fallocate Date: Tue, 17 Feb 2015 18:22:02 +0900 Message-id: <003801d04a93$3026ee10$9074ca30$@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: AdBKj+yEirRICLAnRF2AIwjME+JZgQ== Content-language: ko X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrOIsWRmVeSWpSXmKPExsWyRsSkWNeK43GIweunShZLJ15itnj3ucpi y7F7jBZ79p5ksbi8aw6bxaK+W4wObB6nFkl4rL6wldHj/b6rbB59W1YxenzeJBfAGsVlk5Ka k1mWWqRvl8CV8W17D2NBh1TF3DfNzA2MHaJdjJwcEgImEjtf3GWDsMUkLtxbD2RzcQgJLGWU mHHmBAtM0fGrM9hBbCGB6YwSsxbHQhT9ZZT49WEmcxcjBwebgLbEny1gQ0UE1CQmTdrBDFLD LDCfUaKhdz8jSEJYwE/ix5PFYENZBFQljt5bBRbnFbCUuNCxggXCFpT4MfkemM0soCWxfudx JghbXmLzmrfMEAcpSOw4+5oRYpmexIJ3z1khakQk9r14xwhRc4xdYuk0c4hdAhLfJh9iAblT QkBWYtMBqDGSEgdX3GCZwCg2C8nmWUg2z0KyeRaS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Dk6pBkYGxe/59Q47glMPWxl7PeFY /W7pbQPNvPjyLNuMFEvfS9cyZjCxXpBlCzDcoMsltPmlUMrX8xM2CcyelLeFs1hxJftepkR2 8dmzqtbK8P75OOd2oYb8Nd8dxQ57/I6sjWl0u/F1TvqkoPS5LzmEFxlPudHGMf29dNWEm3tz vTO85x2oz/p5qliJpTgj0VCLuag4EQBnLzbWBQMAAA== DLP-Filter: Pass X-MTR: 20000000000000000@CPGS X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@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 create space for writing new data within a file after shifting extents to right as given length. and this command also has same limitation as FALLOC_FL_COLLAPSE_RANGE, that is block boundary and use ftruncate(2) for crosses EOF. Signed-off-by: Namjae Jeon Signed-off-by: Ashish Sangwan --- fs/open.c | 8 ++++++-- include/linux/falloc.h | 6 ++++++ include/uapi/linux/falloc.h | 17 +++++++++++++++++ 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/fs/open.c b/fs/open.c index 33f9cbf..b724cc0 100644 --- a/fs/open.c +++ b/fs/open.c @@ -231,8 +231,7 @@ int vfs_fallocate(struct file *file, int mode, loff_t offset, loff_t len) return -EINVAL; /* 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)) + if (mode & ~FALLOC_FL_SUPPORTED_MASK) return -EOPNOTSUPP; /* Punch hole and zero range are mutually exclusive */ @@ -250,6 +249,11 @@ int vfs_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/linux/falloc.h b/include/linux/falloc.h index 3159168..9961110 100644 --- a/include/linux/falloc.h +++ b/include/linux/falloc.h @@ -21,4 +21,10 @@ struct space_resv { #define FS_IOC_RESVSP _IOW('X', 40, struct space_resv) #define FS_IOC_RESVSP64 _IOW('X', 42, struct space_resv) +#define FALLOC_FL_SUPPORTED_MASK (FALLOC_FL_KEEP_SIZE | \ + FALLOC_FL_PUNCH_HOLE | \ + FALLOC_FL_COLLAPSE_RANGE | \ + FALLOC_FL_ZERO_RANGE | \ + FALLOC_FL_INSERT_RANGE) + #endif /* _FALLOC_H_ */ diff --git a/include/uapi/linux/falloc.h b/include/uapi/linux/falloc.h index d1197ae..3e445a7 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 insert 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 a hole. 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 insert space 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_ */ -- 1.8.5.5