diff options
| author | Jaegeuk Kim <jaegeuk@kernel.org> | 2019-06-26 21:23:05 -0400 |
|---|---|---|
| committer | Jaegeuk Kim <jaegeuk@kernel.org> | 2019-07-02 18:40:42 -0400 |
| commit | cad3836f9eb292647c9e3e5c6c778e6fa6e6bf15 (patch) | |
| tree | d2dfb3cfe303ed1bb3f4d834d964e6a60872cfad | |
| parent | 56659ce838456c6f2315ce8a4bd686ac4b23e9d1 (diff) | |
f2fs: allocate blocks for pinned file
This patch allows fallocate to allocate physical blocks for pinned file.
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
| -rw-r--r-- | Documentation/filesystems/f2fs.txt | 25 | ||||
| -rw-r--r-- | fs/f2fs/file.c | 7 |
2 files changed, 31 insertions, 1 deletions
diff --git a/Documentation/filesystems/f2fs.txt b/Documentation/filesystems/f2fs.txt index bebd1be3ba49..496fa28b2492 100644 --- a/Documentation/filesystems/f2fs.txt +++ b/Documentation/filesystems/f2fs.txt | |||
| @@ -804,3 +804,28 @@ WRITE_LIFE_NOT_SET WARM_DATA WRITE_LIFE_NOT_SET | |||
| 804 | WRITE_LIFE_NONE " WRITE_LIFE_NONE | 804 | WRITE_LIFE_NONE " WRITE_LIFE_NONE |
| 805 | WRITE_LIFE_MEDIUM " WRITE_LIFE_MEDIUM | 805 | WRITE_LIFE_MEDIUM " WRITE_LIFE_MEDIUM |
| 806 | WRITE_LIFE_LONG " WRITE_LIFE_LONG | 806 | WRITE_LIFE_LONG " WRITE_LIFE_LONG |
| 807 | |||
| 808 | Fallocate(2) Policy | ||
| 809 | ------------------- | ||
| 810 | |||
| 811 | The default policy follows the below posix rule. | ||
| 812 | |||
| 813 | Allocating disk space | ||
| 814 | The default operation (i.e., mode is zero) of fallocate() allocates | ||
| 815 | the disk space within the range specified by offset and len. The | ||
| 816 | file size (as reported by stat(2)) will be changed if offset+len is | ||
| 817 | greater than the file size. Any subregion within the range specified | ||
| 818 | by offset and len that did not contain data before the call will be | ||
| 819 | initialized to zero. This default behavior closely resembles the | ||
| 820 | behavior of the posix_fallocate(3) library function, and is intended | ||
| 821 | as a method of optimally implementing that function. | ||
| 822 | |||
| 823 | However, once F2FS receives ioctl(fd, F2FS_IOC_SET_PIN_FILE) in prior to | ||
| 824 | fallocate(fd, DEFAULT_MODE), it allocates on-disk blocks addressess having | ||
| 825 | zero or random data, which is useful to the below scenario where: | ||
| 826 | 1. create(fd) | ||
| 827 | 2. ioctl(fd, F2FS_IOC_SET_PIN_FILE) | ||
| 828 | 3. fallocate(fd, 0, 0, size) | ||
| 829 | 4. address = fibmap(fd, offset) | ||
| 830 | 5. open(blkdev) | ||
| 831 | 6. write(blkdev, address) | ||
diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c index c67ff5057472..b164f48e0f31 100644 --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c | |||
| @@ -1528,7 +1528,12 @@ static int expand_inode_data(struct inode *inode, loff_t offset, | |||
| 1528 | if (off_end) | 1528 | if (off_end) |
| 1529 | map.m_len++; | 1529 | map.m_len++; |
| 1530 | 1530 | ||
| 1531 | err = f2fs_map_blocks(inode, &map, 1, F2FS_GET_BLOCK_PRE_AIO); | 1531 | if (f2fs_is_pinned_file(inode)) |
| 1532 | map.m_seg_type = CURSEG_COLD_DATA; | ||
| 1533 | |||
| 1534 | err = f2fs_map_blocks(inode, &map, 1, (f2fs_is_pinned_file(inode) ? | ||
| 1535 | F2FS_GET_BLOCK_PRE_DIO : | ||
| 1536 | F2FS_GET_BLOCK_PRE_AIO)); | ||
| 1532 | if (err) { | 1537 | if (err) { |
| 1533 | pgoff_t last_off; | 1538 | pgoff_t last_off; |
| 1534 | 1539 | ||
