diff options
author | Darrick J. Wong <darrick.wong@oracle.com> | 2016-10-03 12:11:14 -0400 |
---|---|---|
committer | Darrick J. Wong <darrick.wong@oracle.com> | 2016-10-03 12:11:14 -0400 |
commit | 71be6b4942dd64bc17728f82f787be98fd8afed7 (patch) | |
tree | c5a219e8c9d574051b01551d6e24012519213a03 | |
parent | 0a6eab8bd4e0120d49511acbb294797d96ef9e4a (diff) |
vfs: add a FALLOC_FL_UNSHARE mode to fallocate to unshare a range of blocks
Add a new fallocate mode flag that explicitly unshares blocks on
filesystems that support such features. The new flag can only
be used with an allocate-mode fallocate call.
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
-rw-r--r-- | fs/open.c | 5 | ||||
-rw-r--r-- | include/linux/falloc.h | 3 | ||||
-rw-r--r-- | include/uapi/linux/falloc.h | 18 |
3 files changed, 25 insertions, 1 deletions
@@ -256,6 +256,11 @@ int vfs_fallocate(struct file *file, int mode, loff_t offset, loff_t len) | |||
256 | (mode & ~FALLOC_FL_INSERT_RANGE)) | 256 | (mode & ~FALLOC_FL_INSERT_RANGE)) |
257 | return -EINVAL; | 257 | return -EINVAL; |
258 | 258 | ||
259 | /* Unshare range should only be used with allocate mode. */ | ||
260 | if ((mode & FALLOC_FL_UNSHARE_RANGE) && | ||
261 | (mode & ~(FALLOC_FL_UNSHARE_RANGE | FALLOC_FL_KEEP_SIZE))) | ||
262 | return -EINVAL; | ||
263 | |||
259 | if (!(file->f_mode & FMODE_WRITE)) | 264 | if (!(file->f_mode & FMODE_WRITE)) |
260 | return -EBADF; | 265 | return -EBADF; |
261 | 266 | ||
diff --git a/include/linux/falloc.h b/include/linux/falloc.h index 996111000a8c..7494dc67c66f 100644 --- a/include/linux/falloc.h +++ b/include/linux/falloc.h | |||
@@ -25,6 +25,7 @@ struct space_resv { | |||
25 | FALLOC_FL_PUNCH_HOLE | \ | 25 | FALLOC_FL_PUNCH_HOLE | \ |
26 | FALLOC_FL_COLLAPSE_RANGE | \ | 26 | FALLOC_FL_COLLAPSE_RANGE | \ |
27 | FALLOC_FL_ZERO_RANGE | \ | 27 | FALLOC_FL_ZERO_RANGE | \ |
28 | FALLOC_FL_INSERT_RANGE) | 28 | FALLOC_FL_INSERT_RANGE | \ |
29 | FALLOC_FL_UNSHARE_RANGE) | ||
29 | 30 | ||
30 | #endif /* _FALLOC_H_ */ | 31 | #endif /* _FALLOC_H_ */ |
diff --git a/include/uapi/linux/falloc.h b/include/uapi/linux/falloc.h index 3e445a760f14..b075f601919b 100644 --- a/include/uapi/linux/falloc.h +++ b/include/uapi/linux/falloc.h | |||
@@ -58,4 +58,22 @@ | |||
58 | */ | 58 | */ |
59 | #define FALLOC_FL_INSERT_RANGE 0x20 | 59 | #define FALLOC_FL_INSERT_RANGE 0x20 |
60 | 60 | ||
61 | /* | ||
62 | * FALLOC_FL_UNSHARE_RANGE is used to unshare shared blocks within the | ||
63 | * file size without overwriting any existing data. The purpose of this | ||
64 | * call is to preemptively reallocate any blocks that are subject to | ||
65 | * copy-on-write. | ||
66 | * | ||
67 | * Different filesystems may implement different limitations on the | ||
68 | * granularity of the operation. Most will limit operations to filesystem | ||
69 | * block size boundaries, but this boundary may be larger or smaller | ||
70 | * depending on the filesystem and/or the configuration of the filesystem | ||
71 | * or file. | ||
72 | * | ||
73 | * This flag can only be used with allocate-mode fallocate, which is | ||
74 | * to say that it cannot be used with the punch, zero, collapse, or | ||
75 | * insert range modes. | ||
76 | */ | ||
77 | #define FALLOC_FL_UNSHARE_RANGE 0x40 | ||
78 | |||
61 | #endif /* _UAPI_FALLOC_H_ */ | 79 | #endif /* _UAPI_FALLOC_H_ */ |