diff options
| author | Chao Yu <yuchao0@huawei.com> | 2018-07-19 23:57:54 +0800 |
|---|---|---|
| committer | Jaegeuk Kim <jaegeuk@kernel.org> | 2018-09-18 13:38:17 -0700 |
| commit | a2ee1be2b06a82a248c3591f8c3ffd4fa1eee074 (patch) | |
| tree | e45de63eea37983df433ad07d5f970ac7968f179 /fs | |
| parent | bc9e6f1a0f5037cbd6ed8402d24f7293e90834eb (diff) | |
f2fs: restrict setting up inode.i_advise
In order to give advise to f2fs to recognize hot/cold file, it is possible
that we can set specific bit in inode.i_advise through setxattr(), but
there are several bits which are used internally, such as encrypt_bit,
keep_size_bit, they should never be changed through setxattr().
So that this patch 1) adds FADVISE_MODIFIABLE_BITS to filter modifiable
bits user given, 2) supports to clear {hot,cold}_file bits.
Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
Diffstat (limited to 'fs')
| -rw-r--r-- | fs/f2fs/f2fs.h | 2 | ||||
| -rw-r--r-- | fs/f2fs/xattr.c | 11 |
2 files changed, 12 insertions, 1 deletions
diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index cbbe917412a4..17fa394449b6 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -669,6 +669,8 @@ enum { #define FADVISE_HOT_BIT 0x20 #define FADVISE_VERITY_BIT 0x40 /* reserved */ +#define FADVISE_MODIFIABLE_BITS (FADVISE_COLD_BIT | FADVISE_HOT_BIT) + #define file_is_cold(inode) is_file(inode, FADVISE_COLD_BIT) #define file_wrong_pino(inode) is_file(inode, FADVISE_LOST_PINO_BIT) #define file_set_cold(inode) set_file(inode, FADVISE_COLD_BIT) diff --git a/fs/f2fs/xattr.c b/fs/f2fs/xattr.c index 34b7f691cf12..152078bb4829 100644 --- a/fs/f2fs/xattr.c +++ b/fs/f2fs/xattr.c @@ -136,6 +136,8 @@ static int f2fs_xattr_advise_set(const struct xattr_handler *handler, size_t size, int flags) { struct inode *inode = d_inode(dentry); + unsigned char old_advise = F2FS_I(inode)->i_advise; + unsigned char new_advise; if (strcmp(name, "") != 0) return -EINVAL; @@ -144,7 +146,14 @@ static int f2fs_xattr_advise_set(const struct xattr_handler *handler, if (value == NULL) return -EINVAL; - F2FS_I(inode)->i_advise |= *(char *)value; + new_advise = *(char *)value; + if (new_advise & ~FADVISE_MODIFIABLE_BITS) + return -EINVAL; + + new_advise = new_advise & FADVISE_MODIFIABLE_BITS; + new_advise |= old_advise & ~FADVISE_MODIFIABLE_BITS; + + F2FS_I(inode)->i_advise = new_advise; f2fs_mark_inode_dirty_sync(inode, true); return 0; } |
