f2fs/fscrypt: updates to v4.17-rc1
Pull f2fs update from Jaegeuk Kim: "In this round, we've mainly focused on performance tuning and critical bug fixes occurred in low-end devices. Sheng Yong introduced lost_found feature to keep missing files during recovery instead of thrashing them. We're preparing coming fsverity implementation. And, we've got more features to communicate with users for better performance. In low-end devices, some memory-related issues were fixed, and subtle race condtions and corner cases were addressed as well. Enhancements: - large nat bitmaps for more free node ids - add three block allocation policies to pass down write hints given by user - expose extension list to user and introduce hot file extension - tune small devices seamlessly for low-end devices - set readdir_ra by default - give more resources under gc_urgent mode regarding to discard and cleaning - introduce fsync_mode to enforce posix or not - nowait aio support - add lost_found feature to keep dangling inodes - reserve bits for future fsverity feature - add test_dummy_encryption for FBE Bug fixes: - don't use highmem for dentry pages - align memory boundary for bitops - truncate preallocated blocks in write errors - guarantee i_times on fsync call - clear CP_TRIMMED_FLAG correctly - prevent node chain loop during recovery - avoid data race between atomic write and background cleaning - avoid unnecessary selinux violation warnings on resgid option - GFP_NOFS to avoid deadlock in quota and read paths - fix f2fs_skip_inode_update to allow i_size recovery In addition to the above, there are several minor bug fixes and clean-ups" Cherry-pick from origin/upstream-f2fs-stable-linux-4.4.y:42bf67fc54
f2fs: remain written times to update inode during fsync6cb5aa02bf
f2fs: make assignment of t->dentry_bitmap more readablea8d07f1f9c
f2fs: truncate preallocated blocks in error case86444d6006
f2fs: fix a wrong condition in f2fs_skip_inode_updatedb2188a687
f2fs: reserve bits for fs-verityee2e74b3f0
f2fs: Add a segment type check in inplace write0192e0a450
f2fs: no need to initialize zero value for GFP_F2FS_ZERO49338842e9
f2fs: don't track new nat entry in nat setd6a69d5e65
f2fs: clean up with F2FS_BLK_ALIGN2c8834a7a2
f2fs: check blkaddr more accuratly before issue a bio6ab573a9d9
f2fs: Set GF_NOFS in read_cache_page_gfp while doing f2fs_quota_read7419dcb8be
f2fs: introduce a new mount option test_dummy_encryption9321e22c03
f2fs: introduce F2FS_FEATURE_LOST_FOUND feature8a57196158
f2fs: release locks before return in f2fs_ioc_gc_range()739ace131c
f2fs: align memory boundary for bitops4c55abe4f8
f2fs: remove unneeded set_cold_node()30654507e0
f2fs: add nowait aio supportd909e94106
f2fs: wrap all options with f2fs_sb_info.mount_opt5738be52b3
f2fs: Don't overwrite all types of node to keep node chain0bdeb167c8
f2fs: introduce mount option for fsync mode6bc490f0ee
f2fs: fix to restore old mount option in ->remount_fs0c9c3e0344
f2fs: wrap sb_rdonly with f2fs_readonly6c6611223a
f2fs: avoid selinux denial on CAP_SYS_RESOURCE076a6f32fe
f2fs: support hot file extension58edcdbca6
f2fs: fix to avoid race in between atomic write and background GC1e0aeb0af9
f2fs: do gc in greedy mode for whole range if gc_urgent mode is set10b2d001d6
f2fs: issue discard aggressively in the gc_urgent modea5052f32b9
f2fs: set readdir_ra by default1aa536a624
f2fs: add auto tuning for small devices0ffdffc8f1
f2fs: add mount option for segment allocation policyb798298912
f2fs: don't stop GC if GC is contended766d232169
f2fs: expose extension_list sysfs entry98b329de50
f2fs: fix to set KEEP_SIZE bit in f2fs_zero_range4d409fa334
f2fs: introduce sb_lock to make encrypt pwsalt update exclusive1f6bac14c1
f2fs: remove redundant initialization of pointer 'p'946aefc754
f2fs: flush cp pack except cp pack 2 page at firste5081a52ac
f2fs: clean up f2fs_sb_has_xxx functionsa292477154
f2fs: remove redundant check of page type when submit bio190e64a819
f2fs: fix to handle looped node chain during recovery889d980876
f2fs: handle quota for orphan inodes92b12bb1a2
f2fs: support passing down write hints to block layer with F2FS policy22fa74c2b0
f2fs: support passing down write hints given by users to block layer180900373e
f2fs: fix to clear CP_TRIMMED_FLAG0671fae134
f2fs: support large nat bitmapeceb943d5d
f2fs: fix to check extent cache in f2fs_drop_extent_tree2e2a339c98
f2fs: restrict inline_xattr_size configuration41dda11641
f2fs: fix heap mode to reset it back39575737bb
f2fs: fix potential corruption in area before F2FS_SUPER_OFFSET7e0e7995ee
fscrypt: fix build with pre-4.6 gcc versions31d3279a4f
fscrypt: fix up fscrypt_fname_encrypted_size() for internal use82bec88856
fscrypt: define fscrypt_fname_alloc_buffer() to be for presented names168a907828
fscrypt: calculate NUL-padding length in one place only042ae9f4cf
fscrypt: move fscrypt_symlink_data to fscrypt_private.hf9550c24c2
fscrypt: remove fscrypt_fname_usr_to_disk()7ac4756a24
f2fs: switch to fscrypt_get_symlink()6b76f58e24
f2fs: switch to fscrypt ->symlink() helper functionsfd457d2c4e
fscrypt: new helper function - fscrypt_get_symlink()a1cdacb7ae
fscrypt: new helper functions for ->symlink()7f43602f4d
fscrypt: trim down fscrypt.h includesd9cadc11bd
fscrypt: move fscrypt_is_dot_dotdot() to fs/crypto/fname.ce6fe930580
fscrypt: move fscrypt_valid_enc_modes() to fscrypt_private.hefefa434f4
fscrypt: move fscrypt_operations declaration to fscrypt_supp.h7ed178bc8a
fscrypt: split fscrypt_dummy_context_enabled() into supp/notsupp versions3f16e09dad
fscrypt: move fscrypt_ctx declaration to fscrypt_supp.h8216a0b51a
fscrypt: move fscrypt_info_cachep declaration to fscrypt_private.hdfe0b3b1b6
fscrypt: move fscrypt_control_page() to supp/notsupp headers3a2c791778
fscrypt: move fscrypt_has_encryption_key() to supp/notsupp headers Signed-off-by: Jaegeuk Kim <jaegeuk@google.com>
This commit is contained in:
parent
c758d68c86
commit
24a2d90393
30 changed files with 1487 additions and 651 deletions
|
@ -192,3 +192,14 @@ Date: November 2017
|
|||
Contact: "Sheng Yong" <shengyong1@huawei.com>
|
||||
Description:
|
||||
Controls readahead inode block in readdir.
|
||||
|
||||
What: /sys/fs/f2fs/<disk>/extension_list
|
||||
Date: Feburary 2018
|
||||
Contact: "Chao Yu" <yuchao0@huawei.com>
|
||||
Description:
|
||||
Used to control configure extension list:
|
||||
- Query: cat /sys/fs/f2fs/<disk>/extension_list
|
||||
- Add: echo '[h/c]extension' > /sys/fs/f2fs/<disk>/extension_list
|
||||
- Del: echo '[h/c]!extension' > /sys/fs/f2fs/<disk>/extension_list
|
||||
- [h] means add/del hot file extension
|
||||
- [c] means add/del cold file extension
|
||||
|
|
|
@ -172,6 +172,23 @@ offgrpjquota Turn off group journelled quota.
|
|||
offprjjquota Turn off project journelled quota.
|
||||
quota Enable plain user disk quota accounting.
|
||||
noquota Disable all plain disk quota option.
|
||||
whint_mode=%s Control which write hints are passed down to block
|
||||
layer. This supports "off", "user-based", and
|
||||
"fs-based". In "off" mode (default), f2fs does not pass
|
||||
down hints. In "user-based" mode, f2fs tries to pass
|
||||
down hints given by users. And in "fs-based" mode, f2fs
|
||||
passes down hints with its policy.
|
||||
alloc_mode=%s Adjust block allocation policy, which supports "reuse"
|
||||
and "default".
|
||||
fsync_mode=%s Control the policy of fsync. Currently supports "posix"
|
||||
and "strict". In "posix" mode, which is default, fsync
|
||||
will follow POSIX semantics and does a light operation
|
||||
to improve the filesystem performance. In "strict" mode,
|
||||
fsync will be heavy and behaves in line with xfs, ext4
|
||||
and btrfs, where xfstest generic/342 will pass, but the
|
||||
performance will regress.
|
||||
test_dummy_encryption Enable dummy encryption, which provides a fake fscrypt
|
||||
context. The fake fscrypt context is used by xfstests.
|
||||
|
||||
================================================================================
|
||||
DEBUGFS ENTRIES
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
#include <linux/dcache.h>
|
||||
#include <linux/namei.h>
|
||||
#include <crypto/aes.h>
|
||||
#include <crypto/skcipher.h>
|
||||
#include "fscrypt_private.h"
|
||||
|
||||
static unsigned int num_prealloc_crypto_pages = 32;
|
||||
|
|
|
@ -12,42 +12,46 @@
|
|||
|
||||
#include <linux/scatterlist.h>
|
||||
#include <linux/ratelimit.h>
|
||||
#include <crypto/skcipher.h>
|
||||
#include "fscrypt_private.h"
|
||||
|
||||
static inline bool fscrypt_is_dot_dotdot(const struct qstr *str)
|
||||
{
|
||||
if (str->len == 1 && str->name[0] == '.')
|
||||
return true;
|
||||
|
||||
if (str->len == 2 && str->name[0] == '.' && str->name[1] == '.')
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* fname_encrypt() - encrypt a filename
|
||||
*
|
||||
* The caller must have allocated sufficient memory for the @oname string.
|
||||
* The output buffer must be at least as large as the input buffer.
|
||||
* Any extra space is filled with NUL padding before encryption.
|
||||
*
|
||||
* Return: 0 on success, -errno on failure
|
||||
*/
|
||||
static int fname_encrypt(struct inode *inode,
|
||||
const struct qstr *iname, struct fscrypt_str *oname)
|
||||
int fname_encrypt(struct inode *inode, const struct qstr *iname,
|
||||
u8 *out, unsigned int olen)
|
||||
{
|
||||
struct skcipher_request *req = NULL;
|
||||
DECLARE_CRYPTO_WAIT(wait);
|
||||
struct fscrypt_info *ci = inode->i_crypt_info;
|
||||
struct crypto_skcipher *tfm = ci->ci_ctfm;
|
||||
struct crypto_skcipher *tfm = inode->i_crypt_info->ci_ctfm;
|
||||
int res = 0;
|
||||
char iv[FS_CRYPTO_BLOCK_SIZE];
|
||||
struct scatterlist sg;
|
||||
int padding = 4 << (ci->ci_flags & FS_POLICY_FLAGS_PAD_MASK);
|
||||
unsigned int lim;
|
||||
unsigned int cryptlen;
|
||||
|
||||
lim = inode->i_sb->s_cop->max_namelen(inode);
|
||||
if (iname->len <= 0 || iname->len > lim)
|
||||
return -EIO;
|
||||
|
||||
/*
|
||||
* Copy the filename to the output buffer for encrypting in-place and
|
||||
* pad it with the needed number of NUL bytes.
|
||||
*/
|
||||
cryptlen = max_t(unsigned int, iname->len, FS_CRYPTO_BLOCK_SIZE);
|
||||
cryptlen = round_up(cryptlen, padding);
|
||||
cryptlen = min(cryptlen, lim);
|
||||
memcpy(oname->name, iname->name, iname->len);
|
||||
memset(oname->name + iname->len, 0, cryptlen - iname->len);
|
||||
if (WARN_ON(olen < iname->len))
|
||||
return -ENOBUFS;
|
||||
memcpy(out, iname->name, iname->len);
|
||||
memset(out + iname->len, 0, olen - iname->len);
|
||||
|
||||
/* Initialize the IV */
|
||||
memset(iv, 0, FS_CRYPTO_BLOCK_SIZE);
|
||||
|
@ -62,8 +66,8 @@ static int fname_encrypt(struct inode *inode,
|
|||
skcipher_request_set_callback(req,
|
||||
CRYPTO_TFM_REQ_MAY_BACKLOG | CRYPTO_TFM_REQ_MAY_SLEEP,
|
||||
crypto_req_done, &wait);
|
||||
sg_init_one(&sg, oname->name, cryptlen);
|
||||
skcipher_request_set_crypt(req, &sg, &sg, cryptlen, iv);
|
||||
sg_init_one(&sg, out, olen);
|
||||
skcipher_request_set_crypt(req, &sg, &sg, olen, iv);
|
||||
|
||||
/* Do the encryption */
|
||||
res = crypto_wait_req(crypto_skcipher_encrypt(req), &wait);
|
||||
|
@ -74,7 +78,6 @@ static int fname_encrypt(struct inode *inode,
|
|||
return res;
|
||||
}
|
||||
|
||||
oname->len = cryptlen;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -187,50 +190,52 @@ static int digest_decode(const char *src, int len, char *dst)
|
|||
return cp - dst;
|
||||
}
|
||||
|
||||
u32 fscrypt_fname_encrypted_size(const struct inode *inode, u32 ilen)
|
||||
bool fscrypt_fname_encrypted_size(const struct inode *inode, u32 orig_len,
|
||||
u32 max_len, u32 *encrypted_len_ret)
|
||||
{
|
||||
int padding = 32;
|
||||
struct fscrypt_info *ci = inode->i_crypt_info;
|
||||
int padding = 4 << (inode->i_crypt_info->ci_flags &
|
||||
FS_POLICY_FLAGS_PAD_MASK);
|
||||
u32 encrypted_len;
|
||||
|
||||
if (ci)
|
||||
padding = 4 << (ci->ci_flags & FS_POLICY_FLAGS_PAD_MASK);
|
||||
ilen = max(ilen, (u32)FS_CRYPTO_BLOCK_SIZE);
|
||||
return round_up(ilen, padding);
|
||||
if (orig_len > max_len)
|
||||
return false;
|
||||
encrypted_len = max(orig_len, (u32)FS_CRYPTO_BLOCK_SIZE);
|
||||
encrypted_len = round_up(encrypted_len, padding);
|
||||
*encrypted_len_ret = min(encrypted_len, max_len);
|
||||
return true;
|
||||
}
|
||||
EXPORT_SYMBOL(fscrypt_fname_encrypted_size);
|
||||
|
||||
/**
|
||||
* fscrypt_fname_crypto_alloc_obuff() -
|
||||
* fscrypt_fname_alloc_buffer - allocate a buffer for presented filenames
|
||||
*
|
||||
* Allocates an output buffer that is sufficient for the crypto operation
|
||||
* specified by the context and the direction.
|
||||
* Allocate a buffer that is large enough to hold any decrypted or encoded
|
||||
* filename (null-terminated), for the given maximum encrypted filename length.
|
||||
*
|
||||
* Return: 0 on success, -errno on failure
|
||||
*/
|
||||
int fscrypt_fname_alloc_buffer(const struct inode *inode,
|
||||
u32 ilen, struct fscrypt_str *crypto_str)
|
||||
u32 max_encrypted_len,
|
||||
struct fscrypt_str *crypto_str)
|
||||
{
|
||||
u32 olen = fscrypt_fname_encrypted_size(inode, ilen);
|
||||
const u32 max_encoded_len =
|
||||
max_t(u32, BASE64_CHARS(FSCRYPT_FNAME_MAX_UNDIGESTED_SIZE),
|
||||
1 + BASE64_CHARS(sizeof(struct fscrypt_digested_name)));
|
||||
u32 max_presented_len;
|
||||
|
||||
crypto_str->len = olen;
|
||||
olen = max(olen, max_encoded_len);
|
||||
max_presented_len = max(max_encoded_len, max_encrypted_len);
|
||||
|
||||
/*
|
||||
* Allocated buffer can hold one more character to null-terminate the
|
||||
* string
|
||||
*/
|
||||
crypto_str->name = kmalloc(olen + 1, GFP_NOFS);
|
||||
if (!(crypto_str->name))
|
||||
crypto_str->name = kmalloc(max_presented_len + 1, GFP_NOFS);
|
||||
if (!crypto_str->name)
|
||||
return -ENOMEM;
|
||||
crypto_str->len = max_presented_len;
|
||||
return 0;
|
||||
}
|
||||
EXPORT_SYMBOL(fscrypt_fname_alloc_buffer);
|
||||
|
||||
/**
|
||||
* fscrypt_fname_crypto_free_buffer() -
|
||||
* fscrypt_fname_free_buffer - free the buffer for presented filenames
|
||||
*
|
||||
* Frees the buffer allocated for crypto operation.
|
||||
* Free the buffer allocated by fscrypt_fname_alloc_buffer().
|
||||
*/
|
||||
void fscrypt_fname_free_buffer(struct fscrypt_str *crypto_str)
|
||||
{
|
||||
|
@ -296,35 +301,6 @@ int fscrypt_fname_disk_to_usr(struct inode *inode,
|
|||
}
|
||||
EXPORT_SYMBOL(fscrypt_fname_disk_to_usr);
|
||||
|
||||
/**
|
||||
* fscrypt_fname_usr_to_disk() - converts a filename from user space to disk
|
||||
* space
|
||||
*
|
||||
* The caller must have allocated sufficient memory for the @oname string.
|
||||
*
|
||||
* Return: 0 on success, -errno on failure
|
||||
*/
|
||||
int fscrypt_fname_usr_to_disk(struct inode *inode,
|
||||
const struct qstr *iname,
|
||||
struct fscrypt_str *oname)
|
||||
{
|
||||
if (fscrypt_is_dot_dotdot(iname)) {
|
||||
oname->name[0] = '.';
|
||||
oname->name[iname->len - 1] = '.';
|
||||
oname->len = iname->len;
|
||||
return 0;
|
||||
}
|
||||
if (inode->i_crypt_info)
|
||||
return fname_encrypt(inode, iname, oname);
|
||||
/*
|
||||
* Without a proper key, a user is not allowed to modify the filenames
|
||||
* in a directory. Consequently, a user space name cannot be mapped to
|
||||
* a disk-space name
|
||||
*/
|
||||
return -ENOKEY;
|
||||
}
|
||||
EXPORT_SYMBOL(fscrypt_fname_usr_to_disk);
|
||||
|
||||
/**
|
||||
* fscrypt_setup_filename() - prepare to search a possibly encrypted directory
|
||||
* @dir: the directory that will be searched
|
||||
|
@ -368,11 +344,17 @@ int fscrypt_setup_filename(struct inode *dir, const struct qstr *iname,
|
|||
return ret;
|
||||
|
||||
if (dir->i_crypt_info) {
|
||||
ret = fscrypt_fname_alloc_buffer(dir, iname->len,
|
||||
&fname->crypto_buf);
|
||||
if (ret)
|
||||
return ret;
|
||||
ret = fname_encrypt(dir, iname, &fname->crypto_buf);
|
||||
if (!fscrypt_fname_encrypted_size(dir, iname->len,
|
||||
dir->i_sb->s_cop->max_namelen(dir),
|
||||
&fname->crypto_buf.len))
|
||||
return -ENAMETOOLONG;
|
||||
fname->crypto_buf.name = kmalloc(fname->crypto_buf.len,
|
||||
GFP_NOFS);
|
||||
if (!fname->crypto_buf.name)
|
||||
return -ENOMEM;
|
||||
|
||||
ret = fname_encrypt(dir, iname, fname->crypto_buf.name,
|
||||
fname->crypto_buf.len);
|
||||
if (ret)
|
||||
goto errout;
|
||||
fname->disk_name.name = fname->crypto_buf.name;
|
||||
|
@ -424,7 +406,7 @@ int fscrypt_setup_filename(struct inode *dir, const struct qstr *iname,
|
|||
return 0;
|
||||
|
||||
errout:
|
||||
fscrypt_fname_free_buffer(&fname->crypto_buf);
|
||||
kfree(fname->crypto_buf.name);
|
||||
return ret;
|
||||
}
|
||||
EXPORT_SYMBOL(fscrypt_setup_filename);
|
||||
|
|
|
@ -49,6 +49,15 @@ struct fscrypt_context {
|
|||
|
||||
#define FS_ENCRYPTION_CONTEXT_FORMAT_V1 1
|
||||
|
||||
/**
|
||||
* For encrypted symlinks, the ciphertext length is stored at the beginning
|
||||
* of the string in little-endian format.
|
||||
*/
|
||||
struct fscrypt_symlink_data {
|
||||
__le16 len;
|
||||
char encrypted_path[1];
|
||||
} __packed;
|
||||
|
||||
/*
|
||||
* A pointer to this structure is stored in the file system's in-core
|
||||
* representation of an inode.
|
||||
|
@ -81,7 +90,22 @@ static inline void bio_set_op_attrs(struct bio *bio, unsigned op,
|
|||
bio->bi_rw = op | op_flags;
|
||||
}
|
||||
|
||||
static inline bool fscrypt_valid_enc_modes(u32 contents_mode,
|
||||
u32 filenames_mode)
|
||||
{
|
||||
if (contents_mode == FS_ENCRYPTION_MODE_AES_128_CBC &&
|
||||
filenames_mode == FS_ENCRYPTION_MODE_AES_128_CTS)
|
||||
return true;
|
||||
|
||||
if (contents_mode == FS_ENCRYPTION_MODE_AES_256_XTS &&
|
||||
filenames_mode == FS_ENCRYPTION_MODE_AES_256_CTS)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/* crypto.c */
|
||||
extern struct kmem_cache *fscrypt_info_cachep;
|
||||
extern int fscrypt_initialize(unsigned int cop_flags);
|
||||
extern struct workqueue_struct *fscrypt_read_workqueue;
|
||||
extern int fscrypt_do_page_crypto(const struct inode *inode,
|
||||
|
@ -93,6 +117,13 @@ extern int fscrypt_do_page_crypto(const struct inode *inode,
|
|||
extern struct page *fscrypt_alloc_bounce_page(struct fscrypt_ctx *ctx,
|
||||
gfp_t gfp_flags);
|
||||
|
||||
/* fname.c */
|
||||
extern int fname_encrypt(struct inode *inode, const struct qstr *iname,
|
||||
u8 *out, unsigned int olen);
|
||||
extern bool fscrypt_fname_encrypted_size(const struct inode *inode,
|
||||
u32 orig_len, u32 max_len,
|
||||
u32 *encrypted_len_ret);
|
||||
|
||||
/* keyinfo.c */
|
||||
extern void __exit fscrypt_essiv_cleanup(void);
|
||||
|
||||
|
|
|
@ -110,3 +110,159 @@ int __fscrypt_prepare_lookup(struct inode *dir, struct dentry *dentry)
|
|||
return 0;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(__fscrypt_prepare_lookup);
|
||||
|
||||
int __fscrypt_prepare_symlink(struct inode *dir, unsigned int len,
|
||||
unsigned int max_len,
|
||||
struct fscrypt_str *disk_link)
|
||||
{
|
||||
int err;
|
||||
|
||||
/*
|
||||
* To calculate the size of the encrypted symlink target we need to know
|
||||
* the amount of NUL padding, which is determined by the flags set in
|
||||
* the encryption policy which will be inherited from the directory.
|
||||
* The easiest way to get access to this is to just load the directory's
|
||||
* fscrypt_info, since we'll need it to create the dir_entry anyway.
|
||||
*
|
||||
* Note: in test_dummy_encryption mode, @dir may be unencrypted.
|
||||
*/
|
||||
err = fscrypt_get_encryption_info(dir);
|
||||
if (err)
|
||||
return err;
|
||||
if (!fscrypt_has_encryption_key(dir))
|
||||
return -ENOKEY;
|
||||
|
||||
/*
|
||||
* Calculate the size of the encrypted symlink and verify it won't
|
||||
* exceed max_len. Note that for historical reasons, encrypted symlink
|
||||
* targets are prefixed with the ciphertext length, despite this
|
||||
* actually being redundant with i_size. This decreases by 2 bytes the
|
||||
* longest symlink target we can accept.
|
||||
*
|
||||
* We could recover 1 byte by not counting a null terminator, but
|
||||
* counting it (even though it is meaningless for ciphertext) is simpler
|
||||
* for now since filesystems will assume it is there and subtract it.
|
||||
*/
|
||||
if (!fscrypt_fname_encrypted_size(dir, len,
|
||||
max_len - sizeof(struct fscrypt_symlink_data),
|
||||
&disk_link->len))
|
||||
return -ENAMETOOLONG;
|
||||
disk_link->len += sizeof(struct fscrypt_symlink_data);
|
||||
|
||||
disk_link->name = NULL;
|
||||
return 0;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(__fscrypt_prepare_symlink);
|
||||
|
||||
int __fscrypt_encrypt_symlink(struct inode *inode, const char *target,
|
||||
unsigned int len, struct fscrypt_str *disk_link)
|
||||
{
|
||||
int err;
|
||||
struct qstr iname = QSTR_INIT(target, len);
|
||||
struct fscrypt_symlink_data *sd;
|
||||
unsigned int ciphertext_len;
|
||||
|
||||
err = fscrypt_require_key(inode);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
if (disk_link->name) {
|
||||
/* filesystem-provided buffer */
|
||||
sd = (struct fscrypt_symlink_data *)disk_link->name;
|
||||
} else {
|
||||
sd = kmalloc(disk_link->len, GFP_NOFS);
|
||||
if (!sd)
|
||||
return -ENOMEM;
|
||||
}
|
||||
ciphertext_len = disk_link->len - sizeof(*sd);
|
||||
sd->len = cpu_to_le16(ciphertext_len);
|
||||
|
||||
err = fname_encrypt(inode, &iname, sd->encrypted_path, ciphertext_len);
|
||||
if (err) {
|
||||
if (!disk_link->name)
|
||||
kfree(sd);
|
||||
return err;
|
||||
}
|
||||
/*
|
||||
* Null-terminating the ciphertext doesn't make sense, but we still
|
||||
* count the null terminator in the length, so we might as well
|
||||
* initialize it just in case the filesystem writes it out.
|
||||
*/
|
||||
sd->encrypted_path[ciphertext_len] = '\0';
|
||||
|
||||
if (!disk_link->name)
|
||||
disk_link->name = (unsigned char *)sd;
|
||||
return 0;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(__fscrypt_encrypt_symlink);
|
||||
|
||||
/**
|
||||
* fscrypt_get_symlink - get the target of an encrypted symlink
|
||||
* @inode: the symlink inode
|
||||
* @caddr: the on-disk contents of the symlink
|
||||
* @max_size: size of @caddr buffer
|
||||
* @done: if successful, will be set up to free the returned target
|
||||
*
|
||||
* If the symlink's encryption key is available, we decrypt its target.
|
||||
* Otherwise, we encode its target for presentation.
|
||||
*
|
||||
* This may sleep, so the filesystem must have dropped out of RCU mode already.
|
||||
*
|
||||
* Return: the presentable symlink target or an ERR_PTR()
|
||||
*/
|
||||
void *fscrypt_get_symlink(struct inode *inode, const void *caddr,
|
||||
unsigned int max_size)
|
||||
{
|
||||
const struct fscrypt_symlink_data *sd;
|
||||
struct fscrypt_str cstr, pstr;
|
||||
int err;
|
||||
|
||||
/* This is for encrypted symlinks only */
|
||||
if (WARN_ON(!IS_ENCRYPTED(inode)))
|
||||
return ERR_PTR(-EINVAL);
|
||||
|
||||
/*
|
||||
* Try to set up the symlink's encryption key, but we can continue
|
||||
* regardless of whether the key is available or not.
|
||||
*/
|
||||
err = fscrypt_get_encryption_info(inode);
|
||||
if (err)
|
||||
return ERR_PTR(err);
|
||||
|
||||
/*
|
||||
* For historical reasons, encrypted symlink targets are prefixed with
|
||||
* the ciphertext length, even though this is redundant with i_size.
|
||||
*/
|
||||
|
||||
if (max_size < sizeof(*sd))
|
||||
return ERR_PTR(-EUCLEAN);
|
||||
sd = caddr;
|
||||
cstr.name = (unsigned char *)sd->encrypted_path;
|
||||
cstr.len = le16_to_cpu(sd->len);
|
||||
|
||||
if (cstr.len == 0)
|
||||
return ERR_PTR(-EUCLEAN);
|
||||
|
||||
if (cstr.len + sizeof(*sd) - 1 > max_size)
|
||||
return ERR_PTR(-EUCLEAN);
|
||||
|
||||
err = fscrypt_fname_alloc_buffer(inode, cstr.len, &pstr);
|
||||
if (err)
|
||||
return ERR_PTR(err);
|
||||
|
||||
err = fscrypt_fname_disk_to_usr(inode, 0, 0, &cstr, &pstr);
|
||||
if (err)
|
||||
goto err_kfree;
|
||||
|
||||
err = -EUCLEAN;
|
||||
if (pstr.name[0] == '\0')
|
||||
goto err_kfree;
|
||||
|
||||
pstr.name[pstr.len] = '\0';
|
||||
return pstr.name;
|
||||
|
||||
err_kfree:
|
||||
kfree(pstr.name);
|
||||
return ERR_PTR(err);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(fscrypt_get_symlink);
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
#include <linux/ratelimit.h>
|
||||
#include <crypto/aes.h>
|
||||
#include <crypto/sha.h>
|
||||
#include <crypto/skcipher.h>
|
||||
#include "fscrypt_private.h"
|
||||
|
||||
static struct crypto_shash *essiv_hash_tfm;
|
||||
|
|
|
@ -68,6 +68,7 @@ static struct page *__get_meta_page(struct f2fs_sb_info *sbi, pgoff_t index,
|
|||
.old_blkaddr = index,
|
||||
.new_blkaddr = index,
|
||||
.encrypted_page = NULL,
|
||||
.is_meta = is_meta,
|
||||
};
|
||||
|
||||
if (unlikely(!is_meta))
|
||||
|
@ -163,6 +164,7 @@ int ra_meta_pages(struct f2fs_sb_info *sbi, block_t start, int nrpages,
|
|||
REQ_RAHEAD,
|
||||
.encrypted_page = NULL,
|
||||
.in_list = false,
|
||||
.is_meta = (type != META_POR),
|
||||
};
|
||||
struct blk_plug plug;
|
||||
|
||||
|
@ -573,13 +575,8 @@ static int recover_orphan_inode(struct f2fs_sb_info *sbi, nid_t ino)
|
|||
struct node_info ni;
|
||||
int err = acquire_orphan_inode(sbi);
|
||||
|
||||
if (err) {
|
||||
set_sbi_flag(sbi, SBI_NEED_FSCK);
|
||||
f2fs_msg(sbi->sb, KERN_WARNING,
|
||||
"%s: orphan failed (ino=%x), run fsck to fix.",
|
||||
__func__, ino);
|
||||
return err;
|
||||
}
|
||||
if (err)
|
||||
goto err_out;
|
||||
|
||||
__add_ino_entry(sbi, ino, 0, ORPHAN_INO);
|
||||
|
||||
|
@ -593,6 +590,11 @@ static int recover_orphan_inode(struct f2fs_sb_info *sbi, nid_t ino)
|
|||
return PTR_ERR(inode);
|
||||
}
|
||||
|
||||
err = dquot_initialize(inode);
|
||||
if (err)
|
||||
goto err_out;
|
||||
|
||||
dquot_initialize(inode);
|
||||
clear_nlink(inode);
|
||||
|
||||
/* truncate all the data during iput */
|
||||
|
@ -602,14 +604,18 @@ static int recover_orphan_inode(struct f2fs_sb_info *sbi, nid_t ino)
|
|||
|
||||
/* ENOMEM was fully retried in f2fs_evict_inode. */
|
||||
if (ni.blk_addr != NULL_ADDR) {
|
||||
set_sbi_flag(sbi, SBI_NEED_FSCK);
|
||||
f2fs_msg(sbi->sb, KERN_WARNING,
|
||||
"%s: orphan failed (ino=%x) by kernel, retry mount.",
|
||||
__func__, ino);
|
||||
return -EIO;
|
||||
err = -EIO;
|
||||
goto err_out;
|
||||
}
|
||||
__remove_ino_entry(sbi, ino, ORPHAN_INO);
|
||||
return 0;
|
||||
|
||||
err_out:
|
||||
set_sbi_flag(sbi, SBI_NEED_FSCK);
|
||||
f2fs_msg(sbi->sb, KERN_WARNING,
|
||||
"%s: orphan failed (ino=%x), run fsck to fix.",
|
||||
__func__, ino);
|
||||
return err;
|
||||
}
|
||||
|
||||
int recover_orphan_inodes(struct f2fs_sb_info *sbi)
|
||||
|
@ -1140,6 +1146,8 @@ static void update_ckpt_flags(struct f2fs_sb_info *sbi, struct cp_control *cpc)
|
|||
|
||||
if (cpc->reason & CP_TRIMMED)
|
||||
__set_ckpt_flags(ckpt, CP_TRIMMED_FLAG);
|
||||
else
|
||||
__clear_ckpt_flags(ckpt, CP_TRIMMED_FLAG);
|
||||
|
||||
if (cpc->reason & CP_UMOUNT)
|
||||
__set_ckpt_flags(ckpt, CP_UMOUNT_FLAG);
|
||||
|
@ -1166,6 +1174,39 @@ static void update_ckpt_flags(struct f2fs_sb_info *sbi, struct cp_control *cpc)
|
|||
spin_unlock_irqrestore(&sbi->cp_lock, flags);
|
||||
}
|
||||
|
||||
static void commit_checkpoint(struct f2fs_sb_info *sbi,
|
||||
void *src, block_t blk_addr)
|
||||
{
|
||||
struct writeback_control wbc = {
|
||||
.for_reclaim = 0,
|
||||
};
|
||||
|
||||
/*
|
||||
* pagevec_lookup_tag and lock_page again will take
|
||||
* some extra time. Therefore, update_meta_pages and
|
||||
* sync_meta_pages are combined in this function.
|
||||
*/
|
||||
struct page *page = grab_meta_page(sbi, blk_addr);
|
||||
int err;
|
||||
|
||||
memcpy(page_address(page), src, PAGE_SIZE);
|
||||
set_page_dirty(page);
|
||||
|
||||
f2fs_wait_on_page_writeback(page, META, true);
|
||||
f2fs_bug_on(sbi, PageWriteback(page));
|
||||
if (unlikely(!clear_page_dirty_for_io(page)))
|
||||
f2fs_bug_on(sbi, 1);
|
||||
|
||||
/* writeout cp pack 2 page */
|
||||
err = __f2fs_write_meta_page(page, &wbc, FS_CP_META_IO);
|
||||
f2fs_bug_on(sbi, err);
|
||||
|
||||
f2fs_put_page(page, 0);
|
||||
|
||||
/* submit checkpoint (with barrier if NOBARRIER is not set) */
|
||||
f2fs_submit_merged_write(sbi, META_FLUSH);
|
||||
}
|
||||
|
||||
static int do_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc)
|
||||
{
|
||||
struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi);
|
||||
|
@ -1268,16 +1309,6 @@ static int do_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc)
|
|||
}
|
||||
}
|
||||
|
||||
/* need to wait for end_io results */
|
||||
wait_on_all_pages_writeback(sbi);
|
||||
if (unlikely(f2fs_cp_error(sbi)))
|
||||
return -EIO;
|
||||
|
||||
/* flush all device cache */
|
||||
err = f2fs_flush_device_cache(sbi);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
/* write out checkpoint buffer at block 0 */
|
||||
update_meta_page(sbi, ckpt, start_blk++);
|
||||
|
||||
|
@ -1305,26 +1336,26 @@ static int do_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc)
|
|||
start_blk += NR_CURSEG_NODE_TYPE;
|
||||
}
|
||||
|
||||
/* writeout checkpoint block */
|
||||
update_meta_page(sbi, ckpt, start_blk);
|
||||
/* update user_block_counts */
|
||||
sbi->last_valid_block_count = sbi->total_valid_block_count;
|
||||
percpu_counter_set(&sbi->alloc_valid_block_count, 0);
|
||||
|
||||
/* wait for previous submitted node/meta pages writeback */
|
||||
/* Here, we have one bio having CP pack except cp pack 2 page */
|
||||
sync_meta_pages(sbi, META, LONG_MAX, FS_CP_META_IO);
|
||||
|
||||
/* wait for previous submitted meta pages writeback */
|
||||
wait_on_all_pages_writeback(sbi);
|
||||
|
||||
if (unlikely(f2fs_cp_error(sbi)))
|
||||
return -EIO;
|
||||
|
||||
filemap_fdatawait_range(NODE_MAPPING(sbi), 0, LLONG_MAX);
|
||||
filemap_fdatawait_range(META_MAPPING(sbi), 0, LLONG_MAX);
|
||||
/* flush all device cache */
|
||||
err = f2fs_flush_device_cache(sbi);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
/* update user_block_counts */
|
||||
sbi->last_valid_block_count = sbi->total_valid_block_count;
|
||||
percpu_counter_set(&sbi->alloc_valid_block_count, 0);
|
||||
|
||||
/* Here, we only have one bio having CP pack */
|
||||
sync_meta_pages(sbi, META_FLUSH, LONG_MAX, FS_CP_META_IO);
|
||||
|
||||
/* wait for previous submitted meta pages writeback */
|
||||
/* barrier and flush checkpoint cp pack 2 page if it can */
|
||||
commit_checkpoint(sbi, ckpt, start_blk);
|
||||
wait_on_all_pages_writeback(sbi);
|
||||
|
||||
release_ino_entry(sbi, false);
|
||||
|
|
|
@ -174,15 +174,22 @@ static bool __same_bdev(struct f2fs_sb_info *sbi,
|
|||
*/
|
||||
static struct bio *__bio_alloc(struct f2fs_sb_info *sbi, block_t blk_addr,
|
||||
struct writeback_control *wbc,
|
||||
int npages, bool is_read)
|
||||
int npages, bool is_read,
|
||||
enum page_type type, enum temp_type temp)
|
||||
{
|
||||
struct bio *bio;
|
||||
|
||||
bio = f2fs_bio_alloc(sbi, npages, true);
|
||||
|
||||
f2fs_target_device(sbi, blk_addr, bio);
|
||||
bio->bi_end_io = is_read ? f2fs_read_end_io : f2fs_write_end_io;
|
||||
bio->bi_private = is_read ? NULL : sbi;
|
||||
if (is_read) {
|
||||
bio->bi_end_io = f2fs_read_end_io;
|
||||
bio->bi_private = NULL;
|
||||
} else {
|
||||
bio->bi_end_io = f2fs_write_end_io;
|
||||
bio->bi_private = sbi;
|
||||
bio->bi_write_hint = io_type_to_rw_hint(sbi, type, temp);
|
||||
}
|
||||
if (wbc)
|
||||
wbc_init_bio(wbc, bio);
|
||||
|
||||
|
@ -195,13 +202,12 @@ static inline void __submit_bio(struct f2fs_sb_info *sbi,
|
|||
if (!is_read_io(bio_op(bio))) {
|
||||
unsigned int start;
|
||||
|
||||
if (f2fs_sb_mounted_blkzoned(sbi->sb) &&
|
||||
current->plug && (type == DATA || type == NODE))
|
||||
blk_finish_plug(current->plug);
|
||||
|
||||
if (type != DATA && type != NODE)
|
||||
goto submit_io;
|
||||
|
||||
if (f2fs_sb_has_blkzoned(sbi->sb) && current->plug)
|
||||
blk_finish_plug(current->plug);
|
||||
|
||||
start = bio->bi_iter.bi_size >> F2FS_BLKSIZE_BITS;
|
||||
start %= F2FS_IO_SIZE(sbi);
|
||||
|
||||
|
@ -376,12 +382,13 @@ int f2fs_submit_page_bio(struct f2fs_io_info *fio)
|
|||
struct page *page = fio->encrypted_page ?
|
||||
fio->encrypted_page : fio->page;
|
||||
|
||||
verify_block_addr(fio, fio->new_blkaddr);
|
||||
trace_f2fs_submit_page_bio(page, fio);
|
||||
f2fs_trace_ios(fio, 0);
|
||||
|
||||
/* Allocate a new bio */
|
||||
bio = __bio_alloc(fio->sbi, fio->new_blkaddr, fio->io_wbc,
|
||||
1, is_read_io(fio->op));
|
||||
1, is_read_io(fio->op), fio->type, fio->temp);
|
||||
|
||||
if (bio_add_page(bio, page, PAGE_SIZE, 0) < PAGE_SIZE) {
|
||||
bio_put(bio);
|
||||
|
@ -421,8 +428,8 @@ next:
|
|||
}
|
||||
|
||||
if (fio->old_blkaddr != NEW_ADDR)
|
||||
verify_block_addr(sbi, fio->old_blkaddr);
|
||||
verify_block_addr(sbi, fio->new_blkaddr);
|
||||
verify_block_addr(fio, fio->old_blkaddr);
|
||||
verify_block_addr(fio, fio->new_blkaddr);
|
||||
|
||||
bio_page = fio->encrypted_page ? fio->encrypted_page : fio->page;
|
||||
|
||||
|
@ -444,7 +451,8 @@ alloc_new:
|
|||
goto out_fail;
|
||||
}
|
||||
io->bio = __bio_alloc(sbi, fio->new_blkaddr, fio->io_wbc,
|
||||
BIO_MAX_PAGES, false);
|
||||
BIO_MAX_PAGES, false,
|
||||
fio->type, fio->temp);
|
||||
io->fio = *fio;
|
||||
}
|
||||
|
||||
|
@ -831,13 +839,6 @@ alloc:
|
|||
return 0;
|
||||
}
|
||||
|
||||
static inline bool __force_buffered_io(struct inode *inode, int rw)
|
||||
{
|
||||
return (f2fs_encrypted_file(inode) ||
|
||||
(rw == WRITE && test_opt(F2FS_I_SB(inode), LFS)) ||
|
||||
F2FS_I_SB(inode)->s_ndevs);
|
||||
}
|
||||
|
||||
int f2fs_preallocate_blocks(struct kiocb *iocb, struct iov_iter *from)
|
||||
{
|
||||
struct inode *inode = file_inode(iocb->ki_filp);
|
||||
|
@ -868,9 +869,8 @@ int f2fs_preallocate_blocks(struct kiocb *iocb, struct iov_iter *from)
|
|||
map.m_seg_type = NO_CHECK_TYPE;
|
||||
|
||||
if (direct_io) {
|
||||
/* map.m_seg_type = rw_hint_to_seg_type(iocb->ki_hint); */
|
||||
map.m_seg_type = rw_hint_to_seg_type(WRITE_LIFE_NOT_SET);
|
||||
flag = __force_buffered_io(inode, WRITE) ?
|
||||
map.m_seg_type = rw_hint_to_seg_type(iocb->ki_hint);
|
||||
flag = f2fs_force_buffered_io(inode, WRITE) ?
|
||||
F2FS_GET_BLOCK_PRE_AIO :
|
||||
F2FS_GET_BLOCK_PRE_DIO;
|
||||
goto map_blocks;
|
||||
|
@ -1114,6 +1114,31 @@ out:
|
|||
return err;
|
||||
}
|
||||
|
||||
bool f2fs_overwrite_io(struct inode *inode, loff_t pos, size_t len)
|
||||
{
|
||||
struct f2fs_map_blocks map;
|
||||
block_t last_lblk;
|
||||
int err;
|
||||
|
||||
if (pos + len > i_size_read(inode))
|
||||
return false;
|
||||
|
||||
map.m_lblk = F2FS_BYTES_TO_BLK(pos);
|
||||
map.m_next_pgofs = NULL;
|
||||
map.m_next_extent = NULL;
|
||||
map.m_seg_type = NO_CHECK_TYPE;
|
||||
last_lblk = F2FS_BLK_ALIGN(pos + len);
|
||||
|
||||
while (map.m_lblk < last_lblk) {
|
||||
map.m_len = last_lblk - map.m_lblk;
|
||||
err = f2fs_map_blocks(inode, &map, 0, F2FS_GET_BLOCK_DEFAULT);
|
||||
if (err || map.m_len == 0)
|
||||
return false;
|
||||
map.m_lblk += map.m_len;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static int __get_data_block(struct inode *inode, sector_t iblock,
|
||||
struct buffer_head *bh, int create, int flag,
|
||||
pgoff_t *next_pgofs, int seg_type)
|
||||
|
@ -1151,8 +1176,7 @@ static int get_data_block_dio(struct inode *inode, sector_t iblock,
|
|||
return __get_data_block(inode, iblock, bh_result, create,
|
||||
F2FS_GET_BLOCK_DEFAULT, NULL,
|
||||
rw_hint_to_seg_type(
|
||||
WRITE_LIFE_NOT_SET));
|
||||
/* inode->i_write_hint)); */
|
||||
inode->i_write_hint));
|
||||
}
|
||||
|
||||
static int get_data_block_bmap(struct inode *inode, sector_t iblock,
|
||||
|
@ -2304,15 +2328,18 @@ static ssize_t f2fs_direct_IO(struct kiocb *iocb, struct iov_iter *iter,
|
|||
{
|
||||
struct address_space *mapping = iocb->ki_filp->f_mapping;
|
||||
struct inode *inode = mapping->host;
|
||||
struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
|
||||
size_t count = iov_iter_count(iter);
|
||||
int rw = iov_iter_rw(iter);
|
||||
int err;
|
||||
enum rw_hint hint = iocb->ki_hint;
|
||||
int whint_mode = F2FS_OPTION(sbi).whint_mode;
|
||||
|
||||
err = check_direct_IO(inode, iter, offset);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
if (__force_buffered_io(inode, rw))
|
||||
if (f2fs_force_buffered_io(inode, rw))
|
||||
return 0;
|
||||
|
||||
if (trace_android_fs_dataread_start_enabled() &&
|
||||
|
@ -2339,11 +2366,24 @@ static ssize_t f2fs_direct_IO(struct kiocb *iocb, struct iov_iter *iter,
|
|||
}
|
||||
trace_f2fs_direct_IO_enter(inode, offset, count, rw);
|
||||
|
||||
down_read(&F2FS_I(inode)->dio_rwsem[rw]);
|
||||
if (rw == WRITE && whint_mode == WHINT_MODE_OFF)
|
||||
iocb->ki_hint = WRITE_LIFE_NOT_SET;
|
||||
|
||||
if (!down_read_trylock(&F2FS_I(inode)->dio_rwsem[rw])) {
|
||||
if (iocb->ki_flags & IOCB_NOWAIT) {
|
||||
iocb->ki_hint = hint;
|
||||
err = -EAGAIN;
|
||||
goto out;
|
||||
}
|
||||
down_read(&F2FS_I(inode)->dio_rwsem[rw]);
|
||||
}
|
||||
|
||||
err = blockdev_direct_IO(iocb, inode, iter, offset, get_data_block_dio);
|
||||
up_read(&F2FS_I(inode)->dio_rwsem[rw]);
|
||||
|
||||
if (rw == WRITE) {
|
||||
if (whint_mode == WHINT_MODE_OFF)
|
||||
iocb->ki_hint = hint;
|
||||
if (err > 0) {
|
||||
f2fs_update_iostat(F2FS_I_SB(inode), APP_DIRECT_IO,
|
||||
err);
|
||||
|
@ -2352,7 +2392,7 @@ static ssize_t f2fs_direct_IO(struct kiocb *iocb, struct iov_iter *iter,
|
|||
f2fs_write_failed(mapping, offset + count);
|
||||
}
|
||||
}
|
||||
|
||||
out:
|
||||
if (trace_android_fs_dataread_start_enabled() &&
|
||||
(iov_iter_rw(iter) == READ))
|
||||
trace_android_fs_dataread_end(inode, offset, count);
|
||||
|
|
|
@ -361,6 +361,7 @@ struct page *init_inode_metadata(struct inode *inode, struct inode *dir,
|
|||
struct page *dpage)
|
||||
{
|
||||
struct page *page;
|
||||
int dummy_encrypt = DUMMY_ENCRYPTION_ENABLED(F2FS_I_SB(dir));
|
||||
int err;
|
||||
|
||||
if (is_inode_flag_set(inode, FI_NEW_INODE)) {
|
||||
|
@ -387,7 +388,8 @@ struct page *init_inode_metadata(struct inode *inode, struct inode *dir,
|
|||
if (err)
|
||||
goto put_error;
|
||||
|
||||
if (f2fs_encrypted_inode(dir) && f2fs_may_encrypt(inode)) {
|
||||
if ((f2fs_encrypted_inode(dir) || dummy_encrypt) &&
|
||||
f2fs_may_encrypt(inode)) {
|
||||
err = fscrypt_inherit_context(dir, inode, page, false);
|
||||
if (err)
|
||||
goto put_error;
|
||||
|
@ -396,8 +398,6 @@ struct page *init_inode_metadata(struct inode *inode, struct inode *dir,
|
|||
page = get_node_page(F2FS_I_SB(dir), inode->i_ino);
|
||||
if (IS_ERR(page))
|
||||
return page;
|
||||
|
||||
set_cold_node(inode, page);
|
||||
}
|
||||
|
||||
if (new_name) {
|
||||
|
@ -704,7 +704,8 @@ void f2fs_delete_entry(struct f2fs_dir_entry *dentry, struct page *page,
|
|||
|
||||
f2fs_update_time(F2FS_I_SB(dir), REQ_TIME);
|
||||
|
||||
add_ino_entry(F2FS_I_SB(dir), dir->i_ino, TRANS_DIR_INO);
|
||||
if (F2FS_OPTION(F2FS_I_SB(dir)).fsync_mode == FSYNC_MODE_STRICT)
|
||||
add_ino_entry(F2FS_I_SB(dir), dir->i_ino, TRANS_DIR_INO);
|
||||
|
||||
if (f2fs_has_inline_dentry(dir))
|
||||
return f2fs_delete_inline_entry(dentry, page, dir, inode);
|
||||
|
|
|
@ -460,7 +460,7 @@ static struct extent_node *__insert_extent_tree(struct inode *inode,
|
|||
struct rb_node *insert_parent)
|
||||
{
|
||||
struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
|
||||
struct rb_node **p = &et->root.rb_node;
|
||||
struct rb_node **p;
|
||||
struct rb_node *parent = NULL;
|
||||
struct extent_node *en = NULL;
|
||||
|
||||
|
@ -706,6 +706,9 @@ void f2fs_drop_extent_tree(struct inode *inode)
|
|||
struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
|
||||
struct extent_tree *et = F2FS_I(inode)->extent_tree;
|
||||
|
||||
if (!f2fs_may_extent_tree(inode))
|
||||
return;
|
||||
|
||||
set_inode_flag(inode, FI_NO_EXTENT);
|
||||
|
||||
write_lock(&et->lock);
|
||||
|
|
192
fs/f2fs/f2fs.h
192
fs/f2fs/f2fs.h
|
@ -99,9 +99,10 @@ extern char *fault_name[FAULT_MAX];
|
|||
#define F2FS_MOUNT_INLINE_XATTR_SIZE 0x00800000
|
||||
#define F2FS_MOUNT_RESERVE_ROOT 0x01000000
|
||||
|
||||
#define clear_opt(sbi, option) ((sbi)->mount_opt.opt &= ~F2FS_MOUNT_##option)
|
||||
#define set_opt(sbi, option) ((sbi)->mount_opt.opt |= F2FS_MOUNT_##option)
|
||||
#define test_opt(sbi, option) ((sbi)->mount_opt.opt & F2FS_MOUNT_##option)
|
||||
#define F2FS_OPTION(sbi) ((sbi)->mount_opt)
|
||||
#define clear_opt(sbi, option) (F2FS_OPTION(sbi).opt &= ~F2FS_MOUNT_##option)
|
||||
#define set_opt(sbi, option) (F2FS_OPTION(sbi).opt |= F2FS_MOUNT_##option)
|
||||
#define test_opt(sbi, option) (F2FS_OPTION(sbi).opt & F2FS_MOUNT_##option)
|
||||
|
||||
#define ver_after(a, b) (typecheck(unsigned long long, a) && \
|
||||
typecheck(unsigned long long, b) && \
|
||||
|
@ -114,7 +115,26 @@ typedef u32 block_t; /*
|
|||
typedef u32 nid_t;
|
||||
|
||||
struct f2fs_mount_info {
|
||||
unsigned int opt;
|
||||
unsigned int opt;
|
||||
int write_io_size_bits; /* Write IO size bits */
|
||||
block_t root_reserved_blocks; /* root reserved blocks */
|
||||
kuid_t s_resuid; /* reserved blocks for uid */
|
||||
kgid_t s_resgid; /* reserved blocks for gid */
|
||||
int active_logs; /* # of active logs */
|
||||
int inline_xattr_size; /* inline xattr size */
|
||||
#ifdef CONFIG_F2FS_FAULT_INJECTION
|
||||
struct f2fs_fault_info fault_info; /* For fault injection */
|
||||
#endif
|
||||
#ifdef CONFIG_QUOTA
|
||||
/* Names of quota files with journalled quota */
|
||||
char *s_qf_names[MAXQUOTAS];
|
||||
int s_jquota_fmt; /* Format of quota to use */
|
||||
#endif
|
||||
/* For which write hints are passed down to block layer */
|
||||
int whint_mode;
|
||||
int alloc_mode; /* segment allocation policy */
|
||||
int fsync_mode; /* fsync policy */
|
||||
bool test_dummy_encryption; /* test dummy encryption */
|
||||
};
|
||||
|
||||
#define F2FS_FEATURE_ENCRYPT 0x0001
|
||||
|
@ -126,6 +146,8 @@ struct f2fs_mount_info {
|
|||
#define F2FS_FEATURE_FLEXIBLE_INLINE_XATTR 0x0040
|
||||
#define F2FS_FEATURE_QUOTA_INO 0x0080
|
||||
#define F2FS_FEATURE_INODE_CRTIME 0x0100
|
||||
#define F2FS_FEATURE_LOST_FOUND 0x0200
|
||||
#define F2FS_FEATURE_VERITY 0x0400 /* reserved */
|
||||
|
||||
#define F2FS_HAS_FEATURE(sb, mask) \
|
||||
((F2FS_SB(sb)->raw_super->feature & cpu_to_le32(mask)) != 0)
|
||||
|
@ -509,7 +531,7 @@ static inline void make_dentry_ptr_block(struct inode *inode,
|
|||
d->inode = inode;
|
||||
d->max = NR_DENTRY_IN_BLOCK;
|
||||
d->nr_bitmap = SIZE_OF_DENTRY_BITMAP;
|
||||
d->bitmap = &t->dentry_bitmap;
|
||||
d->bitmap = t->dentry_bitmap;
|
||||
d->dentry = t->dentry;
|
||||
d->filename = t->filename;
|
||||
}
|
||||
|
@ -635,6 +657,8 @@ enum {
|
|||
#define FADVISE_ENCRYPT_BIT 0x04
|
||||
#define FADVISE_ENC_NAME_BIT 0x08
|
||||
#define FADVISE_KEEP_SIZE_BIT 0x10
|
||||
#define FADVISE_HOT_BIT 0x20
|
||||
#define FADVISE_VERITY_BIT 0x40 /* reserved */
|
||||
|
||||
#define file_is_cold(inode) is_file(inode, FADVISE_COLD_BIT)
|
||||
#define file_wrong_pino(inode) is_file(inode, FADVISE_LOST_PINO_BIT)
|
||||
|
@ -649,6 +673,9 @@ enum {
|
|||
#define file_set_enc_name(inode) set_file(inode, FADVISE_ENC_NAME_BIT)
|
||||
#define file_keep_isize(inode) is_file(inode, FADVISE_KEEP_SIZE_BIT)
|
||||
#define file_set_keep_isize(inode) set_file(inode, FADVISE_KEEP_SIZE_BIT)
|
||||
#define file_is_hot(inode) is_file(inode, FADVISE_HOT_BIT)
|
||||
#define file_set_hot(inode) set_file(inode, FADVISE_HOT_BIT)
|
||||
#define file_clear_hot(inode) clear_file(inode, FADVISE_HOT_BIT)
|
||||
|
||||
#define DEF_DIR_LEVEL 0
|
||||
|
||||
|
@ -696,6 +723,7 @@ struct f2fs_inode_info {
|
|||
kprojid_t i_projid; /* id for project quota */
|
||||
int i_inline_xattr_size; /* inline xattr size */
|
||||
struct timespec i_crtime; /* inode creation time */
|
||||
struct timespec i_disk_time[4]; /* inode disk times */
|
||||
};
|
||||
|
||||
static inline void get_extent_info(struct extent_info *ext,
|
||||
|
@ -802,7 +830,7 @@ struct f2fs_nm_info {
|
|||
unsigned int nid_cnt[MAX_NID_STATE]; /* the number of free node id */
|
||||
spinlock_t nid_list_lock; /* protect nid lists ops */
|
||||
struct mutex build_lock; /* lock for build free nids */
|
||||
unsigned char (*free_nid_bitmap)[NAT_ENTRY_BITMAP_SIZE];
|
||||
unsigned char **free_nid_bitmap;
|
||||
unsigned char *nat_block_bitmap;
|
||||
unsigned short *free_nid_count; /* free nid count of NAT block */
|
||||
|
||||
|
@ -1035,6 +1063,7 @@ struct f2fs_io_info {
|
|||
bool submitted; /* indicate IO submission */
|
||||
int need_lock; /* indicate we need to lock cp_rwsem */
|
||||
bool in_list; /* indicate fio is in io_list */
|
||||
bool is_meta; /* indicate borrow meta inode mapping or not */
|
||||
enum iostat_type io_type; /* io type */
|
||||
struct writeback_control *io_wbc; /* writeback control */
|
||||
};
|
||||
|
@ -1096,10 +1125,34 @@ enum {
|
|||
MAX_TIME,
|
||||
};
|
||||
|
||||
enum {
|
||||
WHINT_MODE_OFF, /* not pass down write hints */
|
||||
WHINT_MODE_USER, /* try to pass down hints given by users */
|
||||
WHINT_MODE_FS, /* pass down hints with F2FS policy */
|
||||
};
|
||||
|
||||
enum {
|
||||
ALLOC_MODE_DEFAULT, /* stay default */
|
||||
ALLOC_MODE_REUSE, /* reuse segments as much as possible */
|
||||
};
|
||||
|
||||
enum fsync_mode {
|
||||
FSYNC_MODE_POSIX, /* fsync follows posix semantics */
|
||||
FSYNC_MODE_STRICT, /* fsync behaves in line with ext4 */
|
||||
};
|
||||
|
||||
#ifdef CONFIG_F2FS_FS_ENCRYPTION
|
||||
#define DUMMY_ENCRYPTION_ENABLED(sbi) \
|
||||
(unlikely(F2FS_OPTION(sbi).test_dummy_encryption))
|
||||
#else
|
||||
#define DUMMY_ENCRYPTION_ENABLED(sbi) (0)
|
||||
#endif
|
||||
|
||||
struct f2fs_sb_info {
|
||||
struct super_block *sb; /* pointer to VFS super block */
|
||||
struct proc_dir_entry *s_proc; /* proc entry */
|
||||
struct f2fs_super_block *raw_super; /* raw super block pointer */
|
||||
struct rw_semaphore sb_lock; /* lock for raw super block */
|
||||
int valid_super_block; /* valid super block no */
|
||||
unsigned long s_flag; /* flags for sbi */
|
||||
|
||||
|
@ -1119,7 +1172,6 @@ struct f2fs_sb_info {
|
|||
struct f2fs_bio_info *write_io[NR_PAGE_TYPE]; /* for write bios */
|
||||
struct mutex wio_mutex[NR_PAGE_TYPE - 1][NR_TEMP_TYPE];
|
||||
/* bio ordering for NODE/DATA */
|
||||
int write_io_size_bits; /* Write IO size bits */
|
||||
mempool_t *write_io_dummy; /* Dummy pages */
|
||||
|
||||
/* for checkpoint */
|
||||
|
@ -1169,9 +1221,7 @@ struct f2fs_sb_info {
|
|||
unsigned int total_node_count; /* total node block count */
|
||||
unsigned int total_valid_node_count; /* valid node block count */
|
||||
loff_t max_file_blocks; /* max block index of file */
|
||||
int active_logs; /* # of active logs */
|
||||
int dir_level; /* directory level */
|
||||
int inline_xattr_size; /* inline xattr size */
|
||||
unsigned int trigger_ssr_threshold; /* threshold to trigger ssr */
|
||||
int readdir_ra; /* readahead inode in readdir */
|
||||
|
||||
|
@ -1181,9 +1231,6 @@ struct f2fs_sb_info {
|
|||
block_t last_valid_block_count; /* for recovery */
|
||||
block_t reserved_blocks; /* configurable reserved blocks */
|
||||
block_t current_reserved_blocks; /* current reserved blocks */
|
||||
block_t root_reserved_blocks; /* root reserved blocks */
|
||||
kuid_t s_resuid; /* reserved blocks for uid */
|
||||
kgid_t s_resgid; /* reserved blocks for gid */
|
||||
|
||||
unsigned int nquota_files; /* # of quota sysfile */
|
||||
|
||||
|
@ -1268,17 +1315,6 @@ struct f2fs_sb_info {
|
|||
|
||||
/* Precomputed FS UUID checksum for seeding other checksums */
|
||||
__u32 s_chksum_seed;
|
||||
|
||||
/* For fault injection */
|
||||
#ifdef CONFIG_F2FS_FAULT_INJECTION
|
||||
struct f2fs_fault_info fault_info;
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_QUOTA
|
||||
/* Names of quota files with journalled quota */
|
||||
char *s_qf_names[MAXQUOTAS];
|
||||
int s_jquota_fmt; /* Format of quota to use */
|
||||
#endif
|
||||
};
|
||||
|
||||
#ifdef CONFIG_F2FS_FAULT_INJECTION
|
||||
|
@ -1288,7 +1324,7 @@ struct f2fs_sb_info {
|
|||
__func__, __builtin_return_address(0))
|
||||
static inline bool time_to_inject(struct f2fs_sb_info *sbi, int type)
|
||||
{
|
||||
struct f2fs_fault_info *ffi = &sbi->fault_info;
|
||||
struct f2fs_fault_info *ffi = &F2FS_OPTION(sbi).fault_info;
|
||||
|
||||
if (!ffi->inject_rate)
|
||||
return false;
|
||||
|
@ -1645,13 +1681,13 @@ static inline bool __allow_reserved_blocks(struct f2fs_sb_info *sbi,
|
|||
return false;
|
||||
if (IS_NOQUOTA(inode))
|
||||
return true;
|
||||
if (uid_eq(F2FS_OPTION(sbi).s_resuid, current_fsuid()))
|
||||
return true;
|
||||
if (!gid_eq(F2FS_OPTION(sbi).s_resgid, GLOBAL_ROOT_GID) &&
|
||||
in_group_p(F2FS_OPTION(sbi).s_resgid))
|
||||
return true;
|
||||
if (capable(CAP_SYS_RESOURCE))
|
||||
return true;
|
||||
if (uid_eq(sbi->s_resuid, current_fsuid()))
|
||||
return true;
|
||||
if (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) &&
|
||||
in_group_p(sbi->s_resgid))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -1686,7 +1722,7 @@ static inline int inc_valid_block_count(struct f2fs_sb_info *sbi,
|
|||
sbi->current_reserved_blocks;
|
||||
|
||||
if (!__allow_reserved_blocks(sbi, inode))
|
||||
avail_user_block_count -= sbi->root_reserved_blocks;
|
||||
avail_user_block_count -= F2FS_OPTION(sbi).root_reserved_blocks;
|
||||
|
||||
if (unlikely(sbi->total_valid_block_count > avail_user_block_count)) {
|
||||
diff = sbi->total_valid_block_count - avail_user_block_count;
|
||||
|
@ -1821,6 +1857,12 @@ static inline void *__bitmap_ptr(struct f2fs_sb_info *sbi, int flag)
|
|||
struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi);
|
||||
int offset;
|
||||
|
||||
if (is_set_ckpt_flags(sbi, CP_LARGE_NAT_BITMAP_FLAG)) {
|
||||
offset = (flag == SIT_BITMAP) ?
|
||||
le32_to_cpu(ckpt->nat_ver_bitmap_bytesize) : 0;
|
||||
return &ckpt->sit_nat_version_bitmap + offset;
|
||||
}
|
||||
|
||||
if (__cp_payload(sbi) > 0) {
|
||||
if (flag == NAT_BITMAP)
|
||||
return &ckpt->sit_nat_version_bitmap;
|
||||
|
@ -1887,7 +1929,7 @@ static inline int inc_valid_node_count(struct f2fs_sb_info *sbi,
|
|||
sbi->current_reserved_blocks + 1;
|
||||
|
||||
if (!__allow_reserved_blocks(sbi, inode))
|
||||
valid_block_count += sbi->root_reserved_blocks;
|
||||
valid_block_count += F2FS_OPTION(sbi).root_reserved_blocks;
|
||||
|
||||
if (unlikely(valid_block_count > sbi->user_block_count)) {
|
||||
spin_unlock(&sbi->stat_lock);
|
||||
|
@ -2489,7 +2531,17 @@ static inline bool f2fs_skip_inode_update(struct inode *inode, int dsync)
|
|||
}
|
||||
if (!is_inode_flag_set(inode, FI_AUTO_RECOVER) ||
|
||||
file_keep_isize(inode) ||
|
||||
i_size_read(inode) & PAGE_MASK)
|
||||
i_size_read(inode) & ~PAGE_MASK)
|
||||
return false;
|
||||
|
||||
if (!timespec_equal(F2FS_I(inode)->i_disk_time, &inode->i_atime))
|
||||
return false;
|
||||
if (!timespec_equal(F2FS_I(inode)->i_disk_time + 1, &inode->i_ctime))
|
||||
return false;
|
||||
if (!timespec_equal(F2FS_I(inode)->i_disk_time + 2, &inode->i_mtime))
|
||||
return false;
|
||||
if (!timespec_equal(F2FS_I(inode)->i_disk_time + 3,
|
||||
&F2FS_I(inode)->i_crtime))
|
||||
return false;
|
||||
|
||||
down_read(&F2FS_I(inode)->i_sem);
|
||||
|
@ -2499,8 +2551,7 @@ static inline bool f2fs_skip_inode_update(struct inode *inode, int dsync)
|
|||
return ret;
|
||||
}
|
||||
|
||||
#define sb_rdonly f2fs_readonly
|
||||
static inline int f2fs_readonly(struct super_block *sb)
|
||||
static inline bool f2fs_readonly(struct super_block *sb)
|
||||
{
|
||||
return sb->s_flags & MS_RDONLY;
|
||||
}
|
||||
|
@ -2562,15 +2613,6 @@ static inline void *kvzalloc(size_t size, gfp_t flags)
|
|||
return ret;
|
||||
}
|
||||
|
||||
enum rw_hint {
|
||||
WRITE_LIFE_NOT_SET = 0,
|
||||
WRITE_LIFE_NONE = 1, /* RWH_WRITE_LIFE_NONE */
|
||||
WRITE_LIFE_SHORT = 2, /* RWH_WRITE_LIFE_SHORT */
|
||||
WRITE_LIFE_MEDIUM = 3, /* RWH_WRITE_LIFE_MEDIUM */
|
||||
WRITE_LIFE_LONG = 4, /* RWH_WRITE_LIFE_LONG */
|
||||
WRITE_LIFE_EXTREME = 5, /* RWH_WRITE_LIFE_EXTREME */
|
||||
};
|
||||
|
||||
static inline void *f2fs_kzalloc(struct f2fs_sb_info *sbi,
|
||||
size_t size, gfp_t flags)
|
||||
{
|
||||
|
@ -2679,6 +2721,8 @@ void handle_failed_inode(struct inode *inode);
|
|||
/*
|
||||
* namei.c
|
||||
*/
|
||||
int update_extension_list(struct f2fs_sb_info *sbi, const char *name,
|
||||
bool hot, bool set);
|
||||
struct dentry *f2fs_get_parent(struct dentry *child);
|
||||
|
||||
/*
|
||||
|
@ -2851,6 +2895,8 @@ void destroy_segment_manager(struct f2fs_sb_info *sbi);
|
|||
int __init create_segment_manager_caches(void);
|
||||
void destroy_segment_manager_caches(void);
|
||||
int rw_hint_to_seg_type(enum rw_hint hint);
|
||||
enum rw_hint io_type_to_rw_hint(struct f2fs_sb_info *sbi, enum page_type type,
|
||||
enum temp_type temp);
|
||||
|
||||
/*
|
||||
* checkpoint.c
|
||||
|
@ -2933,6 +2979,7 @@ int f2fs_release_page(struct page *page, gfp_t wait);
|
|||
int f2fs_migrate_page(struct address_space *mapping, struct page *newpage,
|
||||
struct page *page, enum migrate_mode mode);
|
||||
#endif
|
||||
bool f2fs_overwrite_io(struct inode *inode, loff_t pos, size_t len);
|
||||
|
||||
/*
|
||||
* gc.c
|
||||
|
@ -3255,45 +3302,21 @@ static inline bool f2fs_bio_encrypted(struct bio *bio)
|
|||
return bio->bi_private != NULL;
|
||||
}
|
||||
|
||||
static inline int f2fs_sb_has_crypto(struct super_block *sb)
|
||||
{
|
||||
return F2FS_HAS_FEATURE(sb, F2FS_FEATURE_ENCRYPT);
|
||||
#define F2FS_FEATURE_FUNCS(name, flagname) \
|
||||
static inline int f2fs_sb_has_##name(struct super_block *sb) \
|
||||
{ \
|
||||
return F2FS_HAS_FEATURE(sb, F2FS_FEATURE_##flagname); \
|
||||
}
|
||||
|
||||
static inline int f2fs_sb_mounted_blkzoned(struct super_block *sb)
|
||||
{
|
||||
return F2FS_HAS_FEATURE(sb, F2FS_FEATURE_BLKZONED);
|
||||
}
|
||||
|
||||
static inline int f2fs_sb_has_extra_attr(struct super_block *sb)
|
||||
{
|
||||
return F2FS_HAS_FEATURE(sb, F2FS_FEATURE_EXTRA_ATTR);
|
||||
}
|
||||
|
||||
static inline int f2fs_sb_has_project_quota(struct super_block *sb)
|
||||
{
|
||||
return F2FS_HAS_FEATURE(sb, F2FS_FEATURE_PRJQUOTA);
|
||||
}
|
||||
|
||||
static inline int f2fs_sb_has_inode_chksum(struct super_block *sb)
|
||||
{
|
||||
return F2FS_HAS_FEATURE(sb, F2FS_FEATURE_INODE_CHKSUM);
|
||||
}
|
||||
|
||||
static inline int f2fs_sb_has_flexible_inline_xattr(struct super_block *sb)
|
||||
{
|
||||
return F2FS_HAS_FEATURE(sb, F2FS_FEATURE_FLEXIBLE_INLINE_XATTR);
|
||||
}
|
||||
|
||||
static inline int f2fs_sb_has_quota_ino(struct super_block *sb)
|
||||
{
|
||||
return F2FS_HAS_FEATURE(sb, F2FS_FEATURE_QUOTA_INO);
|
||||
}
|
||||
|
||||
static inline int f2fs_sb_has_inode_crtime(struct super_block *sb)
|
||||
{
|
||||
return F2FS_HAS_FEATURE(sb, F2FS_FEATURE_INODE_CRTIME);
|
||||
}
|
||||
F2FS_FEATURE_FUNCS(encrypt, ENCRYPT);
|
||||
F2FS_FEATURE_FUNCS(blkzoned, BLKZONED);
|
||||
F2FS_FEATURE_FUNCS(extra_attr, EXTRA_ATTR);
|
||||
F2FS_FEATURE_FUNCS(project_quota, PRJQUOTA);
|
||||
F2FS_FEATURE_FUNCS(inode_chksum, INODE_CHKSUM);
|
||||
F2FS_FEATURE_FUNCS(flexible_inline_xattr, FLEXIBLE_INLINE_XATTR);
|
||||
F2FS_FEATURE_FUNCS(quota_ino, QUOTA_INO);
|
||||
F2FS_FEATURE_FUNCS(inode_crtime, INODE_CRTIME);
|
||||
F2FS_FEATURE_FUNCS(lost_found, LOST_FOUND);
|
||||
|
||||
#ifdef CONFIG_BLK_DEV_ZONED
|
||||
static inline int get_blkz_type(struct f2fs_sb_info *sbi,
|
||||
|
@ -3313,7 +3336,7 @@ static inline bool f2fs_discard_en(struct f2fs_sb_info *sbi)
|
|||
{
|
||||
struct request_queue *q = bdev_get_queue(sbi->sb->s_bdev);
|
||||
|
||||
return blk_queue_discard(q) || f2fs_sb_mounted_blkzoned(sbi->sb);
|
||||
return blk_queue_discard(q) || f2fs_sb_has_blkzoned(sbi->sb);
|
||||
}
|
||||
|
||||
static inline void set_opt_mode(struct f2fs_sb_info *sbi, unsigned int mt)
|
||||
|
@ -3342,4 +3365,11 @@ static inline bool f2fs_may_encrypt(struct inode *inode)
|
|||
#endif
|
||||
}
|
||||
|
||||
static inline bool f2fs_force_buffered_io(struct inode *inode, int rw)
|
||||
{
|
||||
return (f2fs_encrypted_file(inode) ||
|
||||
(rw == WRITE && test_opt(F2FS_I_SB(inode), LFS)) ||
|
||||
F2FS_I_SB(inode)->s_ndevs);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -166,9 +166,10 @@ static inline enum cp_reason_type need_do_checkpoint(struct inode *inode)
|
|||
cp_reason = CP_NODE_NEED_CP;
|
||||
else if (test_opt(sbi, FASTBOOT))
|
||||
cp_reason = CP_FASTBOOT_MODE;
|
||||
else if (sbi->active_logs == 2)
|
||||
else if (F2FS_OPTION(sbi).active_logs == 2)
|
||||
cp_reason = CP_SPEC_LOG_NUM;
|
||||
else if (need_dentry_mark(sbi, inode->i_ino) &&
|
||||
else if (F2FS_OPTION(sbi).fsync_mode == FSYNC_MODE_STRICT &&
|
||||
need_dentry_mark(sbi, inode->i_ino) &&
|
||||
exist_written_data(sbi, F2FS_I(inode)->i_pino, TRANS_DIR_INO))
|
||||
cp_reason = CP_RECOVER_DIR;
|
||||
|
||||
|
@ -481,6 +482,9 @@ static int f2fs_file_open(struct inode *inode, struct file *filp)
|
|||
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
filp->f_mode |= FMODE_NOWAIT;
|
||||
|
||||
return dquot_file_open(inode, filp);
|
||||
}
|
||||
|
||||
|
@ -571,7 +575,6 @@ truncate_out:
|
|||
int truncate_blocks(struct inode *inode, u64 from, bool lock)
|
||||
{
|
||||
struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
|
||||
unsigned int blocksize = inode->i_sb->s_blocksize;
|
||||
struct dnode_of_data dn;
|
||||
pgoff_t free_from;
|
||||
int count = 0, err = 0;
|
||||
|
@ -580,7 +583,7 @@ int truncate_blocks(struct inode *inode, u64 from, bool lock)
|
|||
|
||||
trace_f2fs_truncate_blocks_enter(inode, from);
|
||||
|
||||
free_from = (pgoff_t)F2FS_BYTES_TO_BLK(from + blocksize - 1);
|
||||
free_from = (pgoff_t)F2FS_BLK_ALIGN(from);
|
||||
|
||||
if (free_from >= sbi->max_file_blocks)
|
||||
goto free_partial;
|
||||
|
@ -1354,8 +1357,12 @@ static int f2fs_zero_range(struct inode *inode, loff_t offset, loff_t len,
|
|||
}
|
||||
|
||||
out:
|
||||
if (!(mode & FALLOC_FL_KEEP_SIZE) && i_size_read(inode) < new_size)
|
||||
f2fs_i_size_write(inode, new_size);
|
||||
if (new_size > i_size_read(inode)) {
|
||||
if (mode & FALLOC_FL_KEEP_SIZE)
|
||||
file_set_keep_isize(inode);
|
||||
else
|
||||
f2fs_i_size_write(inode, new_size);
|
||||
}
|
||||
out_sem:
|
||||
up_write(&F2FS_I(inode)->i_mmap_sem);
|
||||
|
||||
|
@ -1709,6 +1716,8 @@ static int f2fs_ioc_commit_atomic_write(struct file *filp)
|
|||
|
||||
inode_lock(inode);
|
||||
|
||||
down_write(&F2FS_I(inode)->dio_rwsem[WRITE]);
|
||||
|
||||
if (f2fs_is_volatile_file(inode))
|
||||
goto err_out;
|
||||
|
||||
|
@ -1727,6 +1736,7 @@ static int f2fs_ioc_commit_atomic_write(struct file *filp)
|
|||
ret = f2fs_do_sync_file(filp, 0, LLONG_MAX, 1, false);
|
||||
}
|
||||
err_out:
|
||||
up_write(&F2FS_I(inode)->dio_rwsem[WRITE]);
|
||||
inode_unlock(inode);
|
||||
mnt_drop_write_file(filp);
|
||||
return ret;
|
||||
|
@ -1936,7 +1946,7 @@ static int f2fs_ioc_set_encryption_policy(struct file *filp, unsigned long arg)
|
|||
{
|
||||
struct inode *inode = file_inode(filp);
|
||||
|
||||
if (!f2fs_sb_has_crypto(inode->i_sb))
|
||||
if (!f2fs_sb_has_encrypt(inode->i_sb))
|
||||
return -EOPNOTSUPP;
|
||||
|
||||
f2fs_update_time(F2FS_I_SB(inode), REQ_TIME);
|
||||
|
@ -1946,7 +1956,7 @@ static int f2fs_ioc_set_encryption_policy(struct file *filp, unsigned long arg)
|
|||
|
||||
static int f2fs_ioc_get_encryption_policy(struct file *filp, unsigned long arg)
|
||||
{
|
||||
if (!f2fs_sb_has_crypto(file_inode(filp)->i_sb))
|
||||
if (!f2fs_sb_has_encrypt(file_inode(filp)->i_sb))
|
||||
return -EOPNOTSUPP;
|
||||
return fscrypt_ioctl_get_policy(filp, (void __user *)arg);
|
||||
}
|
||||
|
@ -1957,16 +1967,18 @@ static int f2fs_ioc_get_encryption_pwsalt(struct file *filp, unsigned long arg)
|
|||
struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
|
||||
int err;
|
||||
|
||||
if (!f2fs_sb_has_crypto(inode->i_sb))
|
||||
if (!f2fs_sb_has_encrypt(inode->i_sb))
|
||||
return -EOPNOTSUPP;
|
||||
|
||||
if (uuid_is_nonzero(sbi->raw_super->encrypt_pw_salt))
|
||||
goto got_it;
|
||||
|
||||
err = mnt_want_write_file(filp);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
down_write(&sbi->sb_lock);
|
||||
|
||||
if (uuid_is_nonzero(sbi->raw_super->encrypt_pw_salt))
|
||||
goto got_it;
|
||||
|
||||
/* update superblock with uuid */
|
||||
generate_random_uuid(sbi->raw_super->encrypt_pw_salt);
|
||||
|
||||
|
@ -1974,15 +1986,16 @@ static int f2fs_ioc_get_encryption_pwsalt(struct file *filp, unsigned long arg)
|
|||
if (err) {
|
||||
/* undo new data */
|
||||
memset(sbi->raw_super->encrypt_pw_salt, 0, 16);
|
||||
mnt_drop_write_file(filp);
|
||||
return err;
|
||||
goto out_err;
|
||||
}
|
||||
mnt_drop_write_file(filp);
|
||||
got_it:
|
||||
if (copy_to_user((__u8 __user *)arg, sbi->raw_super->encrypt_pw_salt,
|
||||
16))
|
||||
return -EFAULT;
|
||||
return 0;
|
||||
err = -EFAULT;
|
||||
out_err:
|
||||
up_write(&sbi->sb_lock);
|
||||
mnt_drop_write_file(filp);
|
||||
return err;
|
||||
}
|
||||
|
||||
static int f2fs_ioc_gc(struct file *filp, unsigned long arg)
|
||||
|
@ -2043,8 +2056,10 @@ static int f2fs_ioc_gc_range(struct file *filp, unsigned long arg)
|
|||
return ret;
|
||||
|
||||
end = range.start + range.len;
|
||||
if (range.start < MAIN_BLKADDR(sbi) || end >= MAX_BLKADDR(sbi))
|
||||
return -EINVAL;
|
||||
if (range.start < MAIN_BLKADDR(sbi) || end >= MAX_BLKADDR(sbi)) {
|
||||
ret = -EINVAL;
|
||||
goto out;
|
||||
}
|
||||
do_more:
|
||||
if (!range.sync) {
|
||||
if (!mutex_trylock(&sbi->gc_mutex)) {
|
||||
|
@ -2685,25 +2700,54 @@ static ssize_t f2fs_file_write_iter(struct kiocb *iocb, struct iov_iter *from)
|
|||
if (unlikely(f2fs_cp_error(F2FS_I_SB(inode))))
|
||||
return -EIO;
|
||||
|
||||
inode_lock(inode);
|
||||
if ((iocb->ki_flags & IOCB_NOWAIT) && !(iocb->ki_flags & IOCB_DIRECT))
|
||||
return -EINVAL;
|
||||
|
||||
if (!inode_trylock(inode)) {
|
||||
if (iocb->ki_flags & IOCB_NOWAIT)
|
||||
return -EAGAIN;
|
||||
inode_lock(inode);
|
||||
}
|
||||
|
||||
ret = generic_write_checks(iocb, from);
|
||||
if (ret > 0) {
|
||||
bool preallocated = false;
|
||||
size_t target_size = 0;
|
||||
int err;
|
||||
|
||||
if (iov_iter_fault_in_readable(from, iov_iter_count(from)))
|
||||
set_inode_flag(inode, FI_NO_PREALLOC);
|
||||
|
||||
err = f2fs_preallocate_blocks(iocb, from);
|
||||
if (err) {
|
||||
clear_inode_flag(inode, FI_NO_PREALLOC);
|
||||
inode_unlock(inode);
|
||||
return err;
|
||||
if ((iocb->ki_flags & IOCB_NOWAIT) &&
|
||||
(iocb->ki_flags & IOCB_DIRECT)) {
|
||||
if (!f2fs_overwrite_io(inode, iocb->ki_pos,
|
||||
iov_iter_count(from)) ||
|
||||
f2fs_has_inline_data(inode) ||
|
||||
f2fs_force_buffered_io(inode, WRITE)) {
|
||||
inode_unlock(inode);
|
||||
return -EAGAIN;
|
||||
}
|
||||
|
||||
} else {
|
||||
preallocated = true;
|
||||
target_size = iocb->ki_pos + iov_iter_count(from);
|
||||
|
||||
err = f2fs_preallocate_blocks(iocb, from);
|
||||
if (err) {
|
||||
clear_inode_flag(inode, FI_NO_PREALLOC);
|
||||
inode_unlock(inode);
|
||||
return err;
|
||||
}
|
||||
}
|
||||
blk_start_plug(&plug);
|
||||
ret = __generic_file_write_iter(iocb, from);
|
||||
blk_finish_plug(&plug);
|
||||
clear_inode_flag(inode, FI_NO_PREALLOC);
|
||||
|
||||
/* if we couldn't write data, we should deallocate blocks. */
|
||||
if (preallocated && i_size_read(inode) < target_size)
|
||||
f2fs_truncate(inode);
|
||||
|
||||
if (ret > 0)
|
||||
f2fs_update_iostat(F2FS_I_SB(inode), APP_WRITE_IO, ret);
|
||||
}
|
||||
|
|
23
fs/f2fs/gc.c
23
fs/f2fs/gc.c
|
@ -76,14 +76,15 @@ static int gc_thread_func(void *data)
|
|||
* invalidated soon after by user update or deletion.
|
||||
* So, I'd like to wait some time to collect dirty segments.
|
||||
*/
|
||||
if (!mutex_trylock(&sbi->gc_mutex))
|
||||
goto next;
|
||||
|
||||
if (gc_th->gc_urgent) {
|
||||
wait_ms = gc_th->urgent_sleep_time;
|
||||
mutex_lock(&sbi->gc_mutex);
|
||||
goto do_gc;
|
||||
}
|
||||
|
||||
if (!mutex_trylock(&sbi->gc_mutex))
|
||||
goto next;
|
||||
|
||||
if (!is_idle(sbi)) {
|
||||
increase_sleep_time(gc_th, &wait_ms);
|
||||
mutex_unlock(&sbi->gc_mutex);
|
||||
|
@ -161,12 +162,17 @@ static int select_gc_type(struct f2fs_gc_kthread *gc_th, int gc_type)
|
|||
{
|
||||
int gc_mode = (gc_type == BG_GC) ? GC_CB : GC_GREEDY;
|
||||
|
||||
if (gc_th && gc_th->gc_idle) {
|
||||
if (!gc_th)
|
||||
return gc_mode;
|
||||
|
||||
if (gc_th->gc_idle) {
|
||||
if (gc_th->gc_idle == 1)
|
||||
gc_mode = GC_CB;
|
||||
else if (gc_th->gc_idle == 2)
|
||||
gc_mode = GC_GREEDY;
|
||||
}
|
||||
if (gc_th->gc_urgent)
|
||||
gc_mode = GC_GREEDY;
|
||||
return gc_mode;
|
||||
}
|
||||
|
||||
|
@ -188,11 +194,14 @@ static void select_policy(struct f2fs_sb_info *sbi, int gc_type,
|
|||
}
|
||||
|
||||
/* we need to check every dirty segments in the FG_GC case */
|
||||
if (gc_type != FG_GC && p->max_search > sbi->max_victim_search)
|
||||
if (gc_type != FG_GC &&
|
||||
(sbi->gc_thread && !sbi->gc_thread->gc_urgent) &&
|
||||
p->max_search > sbi->max_victim_search)
|
||||
p->max_search = sbi->max_victim_search;
|
||||
|
||||
/* let's select beginning hot/small space first */
|
||||
if (type == CURSEG_HOT_DATA || IS_NODESEG(type))
|
||||
/* let's select beginning hot/small space first in no_heap mode*/
|
||||
if (test_opt(sbi, NOHEAP) &&
|
||||
(type == CURSEG_HOT_DATA || IS_NODESEG(type)))
|
||||
p->offset = 0;
|
||||
else
|
||||
p->offset = SIT_I(sbi)->last_victim[p->gc_mode];
|
||||
|
|
|
@ -284,6 +284,10 @@ static int do_read_inode(struct inode *inode)
|
|||
fi->i_crtime.tv_nsec = le32_to_cpu(ri->i_crtime_nsec);
|
||||
}
|
||||
|
||||
F2FS_I(inode)->i_disk_time[0] = inode->i_atime;
|
||||
F2FS_I(inode)->i_disk_time[1] = inode->i_ctime;
|
||||
F2FS_I(inode)->i_disk_time[2] = inode->i_mtime;
|
||||
F2FS_I(inode)->i_disk_time[3] = F2FS_I(inode)->i_crtime;
|
||||
f2fs_put_page(node_page, 1);
|
||||
|
||||
stat_inc_inline_xattr(inode);
|
||||
|
@ -439,12 +443,15 @@ void update_inode(struct inode *inode, struct page *node_page)
|
|||
}
|
||||
|
||||
__set_inode_rdev(inode, ri);
|
||||
set_cold_node(inode, node_page);
|
||||
|
||||
/* deleted inode */
|
||||
if (inode->i_nlink == 0)
|
||||
clear_inline_node(node_page);
|
||||
|
||||
F2FS_I(inode)->i_disk_time[0] = inode->i_atime;
|
||||
F2FS_I(inode)->i_disk_time[1] = inode->i_ctime;
|
||||
F2FS_I(inode)->i_disk_time[2] = inode->i_mtime;
|
||||
F2FS_I(inode)->i_disk_time[3] = F2FS_I(inode)->i_crtime;
|
||||
}
|
||||
|
||||
void update_inode_page(struct inode *inode)
|
||||
|
|
247
fs/f2fs/namei.c
247
fs/f2fs/namei.c
|
@ -78,7 +78,8 @@ static struct inode *f2fs_new_inode(struct inode *dir, umode_t mode)
|
|||
set_inode_flag(inode, FI_NEW_INODE);
|
||||
|
||||
/* If the directory encrypted, then we should encrypt the inode. */
|
||||
if (f2fs_encrypted_inode(dir) && f2fs_may_encrypt(inode))
|
||||
if ((f2fs_encrypted_inode(dir) || DUMMY_ENCRYPTION_ENABLED(sbi)) &&
|
||||
f2fs_may_encrypt(inode))
|
||||
f2fs_set_encrypted_inode(inode);
|
||||
|
||||
if (f2fs_sb_has_extra_attr(sbi->sb)) {
|
||||
|
@ -97,7 +98,7 @@ static struct inode *f2fs_new_inode(struct inode *dir, umode_t mode)
|
|||
if (f2fs_sb_has_flexible_inline_xattr(sbi->sb)) {
|
||||
f2fs_bug_on(sbi, !f2fs_has_extra_attr(inode));
|
||||
if (f2fs_has_inline_xattr(inode))
|
||||
xattr_size = sbi->inline_xattr_size;
|
||||
xattr_size = F2FS_OPTION(sbi).inline_xattr_size;
|
||||
/* Otherwise, will be 0 */
|
||||
} else if (f2fs_has_inline_xattr(inode) ||
|
||||
f2fs_has_inline_dentry(inode)) {
|
||||
|
@ -142,7 +143,7 @@ fail_drop:
|
|||
return ERR_PTR(err);
|
||||
}
|
||||
|
||||
static int is_multimedia_file(const unsigned char *s, const char *sub)
|
||||
static int is_extension_exist(const unsigned char *s, const char *sub)
|
||||
{
|
||||
size_t slen = strlen(s);
|
||||
size_t sublen = strlen(sub);
|
||||
|
@ -168,19 +169,94 @@ static int is_multimedia_file(const unsigned char *s, const char *sub)
|
|||
/*
|
||||
* Set multimedia files as cold files for hot/cold data separation
|
||||
*/
|
||||
static inline void set_cold_files(struct f2fs_sb_info *sbi, struct inode *inode,
|
||||
static inline void set_file_temperature(struct f2fs_sb_info *sbi, struct inode *inode,
|
||||
const unsigned char *name)
|
||||
{
|
||||
int i;
|
||||
__u8 (*extlist)[8] = sbi->raw_super->extension_list;
|
||||
__u8 (*extlist)[F2FS_EXTENSION_LEN] = sbi->raw_super->extension_list;
|
||||
int i, cold_count, hot_count;
|
||||
|
||||
int count = le32_to_cpu(sbi->raw_super->extension_count);
|
||||
for (i = 0; i < count; i++) {
|
||||
if (is_multimedia_file(name, extlist[i])) {
|
||||
down_read(&sbi->sb_lock);
|
||||
|
||||
cold_count = le32_to_cpu(sbi->raw_super->extension_count);
|
||||
hot_count = sbi->raw_super->hot_ext_count;
|
||||
|
||||
for (i = 0; i < cold_count + hot_count; i++) {
|
||||
if (!is_extension_exist(name, extlist[i]))
|
||||
continue;
|
||||
if (i < cold_count)
|
||||
file_set_cold(inode);
|
||||
break;
|
||||
}
|
||||
else
|
||||
file_set_hot(inode);
|
||||
break;
|
||||
}
|
||||
|
||||
up_read(&sbi->sb_lock);
|
||||
}
|
||||
|
||||
int update_extension_list(struct f2fs_sb_info *sbi, const char *name,
|
||||
bool hot, bool set)
|
||||
{
|
||||
__u8 (*extlist)[F2FS_EXTENSION_LEN] = sbi->raw_super->extension_list;
|
||||
int cold_count = le32_to_cpu(sbi->raw_super->extension_count);
|
||||
int hot_count = sbi->raw_super->hot_ext_count;
|
||||
int total_count = cold_count + hot_count;
|
||||
int start, count;
|
||||
int i;
|
||||
|
||||
if (set) {
|
||||
if (total_count == F2FS_MAX_EXTENSION)
|
||||
return -EINVAL;
|
||||
} else {
|
||||
if (!hot && !cold_count)
|
||||
return -EINVAL;
|
||||
if (hot && !hot_count)
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (hot) {
|
||||
start = cold_count;
|
||||
count = total_count;
|
||||
} else {
|
||||
start = 0;
|
||||
count = cold_count;
|
||||
}
|
||||
|
||||
for (i = start; i < count; i++) {
|
||||
if (strcmp(name, extlist[i]))
|
||||
continue;
|
||||
|
||||
if (set)
|
||||
return -EINVAL;
|
||||
|
||||
memcpy(extlist[i], extlist[i + 1],
|
||||
F2FS_EXTENSION_LEN * (total_count - i - 1));
|
||||
memset(extlist[total_count - 1], 0, F2FS_EXTENSION_LEN);
|
||||
if (hot)
|
||||
sbi->raw_super->hot_ext_count = hot_count - 1;
|
||||
else
|
||||
sbi->raw_super->extension_count =
|
||||
cpu_to_le32(cold_count - 1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!set)
|
||||
return -EINVAL;
|
||||
|
||||
if (hot) {
|
||||
strncpy(extlist[count], name, strlen(name));
|
||||
sbi->raw_super->hot_ext_count = hot_count + 1;
|
||||
} else {
|
||||
char buf[F2FS_MAX_EXTENSION][F2FS_EXTENSION_LEN];
|
||||
|
||||
memcpy(buf, &extlist[cold_count],
|
||||
F2FS_EXTENSION_LEN * hot_count);
|
||||
memset(extlist[cold_count], 0, F2FS_EXTENSION_LEN);
|
||||
strncpy(extlist[cold_count], name, strlen(name));
|
||||
memcpy(&extlist[cold_count + 1], buf,
|
||||
F2FS_EXTENSION_LEN * hot_count);
|
||||
sbi->raw_super->extension_count = cpu_to_le32(cold_count + 1);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int f2fs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
|
||||
|
@ -203,7 +279,7 @@ static int f2fs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
|
|||
return PTR_ERR(inode);
|
||||
|
||||
if (!test_opt(sbi, DISABLE_EXT_IDENTIFY))
|
||||
set_cold_files(sbi, inode, dentry->d_name.name);
|
||||
set_file_temperature(sbi, inode, dentry->d_name.name);
|
||||
|
||||
inode->i_op = &f2fs_file_inode_operations;
|
||||
inode->i_fop = &f2fs_file_operations;
|
||||
|
@ -478,27 +554,16 @@ static int f2fs_symlink(struct inode *dir, struct dentry *dentry,
|
|||
struct f2fs_sb_info *sbi = F2FS_I_SB(dir);
|
||||
struct inode *inode;
|
||||
size_t len = strlen(symname);
|
||||
struct fscrypt_str disk_link = FSTR_INIT((char *)symname, len + 1);
|
||||
struct fscrypt_symlink_data *sd = NULL;
|
||||
struct fscrypt_str disk_link;
|
||||
int err;
|
||||
|
||||
if (unlikely(f2fs_cp_error(sbi)))
|
||||
return -EIO;
|
||||
|
||||
if (f2fs_encrypted_inode(dir)) {
|
||||
err = fscrypt_get_encryption_info(dir);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
if (!fscrypt_has_encryption_key(dir))
|
||||
return -ENOKEY;
|
||||
|
||||
disk_link.len = (fscrypt_fname_encrypted_size(dir, len) +
|
||||
sizeof(struct fscrypt_symlink_data));
|
||||
}
|
||||
|
||||
if (disk_link.len > dir->i_sb->s_blocksize)
|
||||
return -ENAMETOOLONG;
|
||||
err = fscrypt_prepare_symlink(dir, symname, len, dir->i_sb->s_blocksize,
|
||||
&disk_link);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
err = dquot_initialize(dir);
|
||||
if (err)
|
||||
|
@ -508,7 +573,7 @@ static int f2fs_symlink(struct inode *dir, struct dentry *dentry,
|
|||
if (IS_ERR(inode))
|
||||
return PTR_ERR(inode);
|
||||
|
||||
if (f2fs_encrypted_inode(inode))
|
||||
if (IS_ENCRYPTED(inode))
|
||||
inode->i_op = &f2fs_encrypted_symlink_inode_operations;
|
||||
else
|
||||
inode->i_op = &f2fs_symlink_inode_operations;
|
||||
|
@ -518,38 +583,13 @@ static int f2fs_symlink(struct inode *dir, struct dentry *dentry,
|
|||
f2fs_lock_op(sbi);
|
||||
err = f2fs_add_link(dentry, inode);
|
||||
if (err)
|
||||
goto out;
|
||||
goto out_handle_failed_inode;
|
||||
f2fs_unlock_op(sbi);
|
||||
alloc_nid_done(sbi, inode->i_ino);
|
||||
|
||||
if (f2fs_encrypted_inode(inode)) {
|
||||
struct qstr istr = QSTR_INIT(symname, len);
|
||||
struct fscrypt_str ostr;
|
||||
|
||||
sd = f2fs_kzalloc(sbi, disk_link.len, GFP_NOFS);
|
||||
if (!sd) {
|
||||
err = -ENOMEM;
|
||||
goto err_out;
|
||||
}
|
||||
|
||||
err = fscrypt_get_encryption_info(inode);
|
||||
if (err)
|
||||
goto err_out;
|
||||
|
||||
if (!fscrypt_has_encryption_key(inode)) {
|
||||
err = -ENOKEY;
|
||||
goto err_out;
|
||||
}
|
||||
|
||||
ostr.name = sd->encrypted_path;
|
||||
ostr.len = disk_link.len;
|
||||
err = fscrypt_fname_usr_to_disk(inode, &istr, &ostr);
|
||||
if (err)
|
||||
goto err_out;
|
||||
|
||||
sd->len = cpu_to_le16(ostr.len);
|
||||
disk_link.name = (char *)sd;
|
||||
}
|
||||
err = fscrypt_encrypt_symlink(inode, symname, len, &disk_link);
|
||||
if (err)
|
||||
goto err_out;
|
||||
|
||||
err = page_symlink(inode, disk_link.name, disk_link.len);
|
||||
|
||||
|
@ -576,12 +616,14 @@ err_out:
|
|||
f2fs_unlink(dir, dentry);
|
||||
}
|
||||
|
||||
kfree(sd);
|
||||
|
||||
f2fs_balance_fs(sbi, true);
|
||||
return err;
|
||||
out:
|
||||
goto out_free_encrypted_link;
|
||||
|
||||
out_handle_failed_inode:
|
||||
handle_failed_inode(inode);
|
||||
out_free_encrypted_link:
|
||||
if (disk_link.name != (unsigned char *)symname)
|
||||
kfree(disk_link.name);
|
||||
return err;
|
||||
}
|
||||
|
||||
|
@ -743,10 +785,12 @@ out:
|
|||
|
||||
static int f2fs_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode)
|
||||
{
|
||||
if (unlikely(f2fs_cp_error(F2FS_I_SB(dir))))
|
||||
struct f2fs_sb_info *sbi = F2FS_I_SB(dir);
|
||||
|
||||
if (unlikely(f2fs_cp_error(sbi)))
|
||||
return -EIO;
|
||||
|
||||
if (f2fs_encrypted_inode(dir)) {
|
||||
if (f2fs_encrypted_inode(dir) || DUMMY_ENCRYPTION_ENABLED(sbi)) {
|
||||
int err = fscrypt_get_encryption_info(dir);
|
||||
if (err)
|
||||
return err;
|
||||
|
@ -926,7 +970,8 @@ static int f2fs_rename(struct inode *old_dir, struct dentry *old_dentry,
|
|||
f2fs_put_page(old_dir_page, 0);
|
||||
f2fs_i_links_write(old_dir, false);
|
||||
}
|
||||
add_ino_entry(sbi, new_dir->i_ino, TRANS_DIR_INO);
|
||||
if (F2FS_OPTION(sbi).fsync_mode == FSYNC_MODE_STRICT)
|
||||
add_ino_entry(sbi, new_dir->i_ino, TRANS_DIR_INO);
|
||||
|
||||
f2fs_unlock_op(sbi);
|
||||
|
||||
|
@ -1076,8 +1121,10 @@ static int f2fs_cross_rename(struct inode *old_dir, struct dentry *old_dentry,
|
|||
}
|
||||
f2fs_mark_inode_dirty_sync(new_dir, false);
|
||||
|
||||
add_ino_entry(sbi, old_dir->i_ino, TRANS_DIR_INO);
|
||||
add_ino_entry(sbi, new_dir->i_ino, TRANS_DIR_INO);
|
||||
if (F2FS_OPTION(sbi).fsync_mode == FSYNC_MODE_STRICT) {
|
||||
add_ino_entry(sbi, old_dir->i_ino, TRANS_DIR_INO);
|
||||
add_ino_entry(sbi, new_dir->i_ino, TRANS_DIR_INO);
|
||||
}
|
||||
|
||||
f2fs_unlock_op(sbi);
|
||||
|
||||
|
@ -1127,65 +1174,21 @@ static int f2fs_rename2(struct inode *old_dir, struct dentry *old_dentry,
|
|||
|
||||
static const char *f2fs_encrypted_follow_link(struct dentry *dentry, void **cookie)
|
||||
{
|
||||
struct page *cpage = NULL;
|
||||
char *caddr, *paddr = NULL;
|
||||
struct fscrypt_str cstr = FSTR_INIT(NULL, 0);
|
||||
struct fscrypt_str pstr = FSTR_INIT(NULL, 0);
|
||||
struct fscrypt_symlink_data *sd;
|
||||
struct inode *inode = d_inode(dentry);
|
||||
u32 max_size = inode->i_sb->s_blocksize;
|
||||
int res;
|
||||
struct page *page;
|
||||
void *target;
|
||||
|
||||
res = fscrypt_get_encryption_info(inode);
|
||||
if (res)
|
||||
return ERR_PTR(res);
|
||||
if (!dentry)
|
||||
return ERR_PTR(-ECHILD);
|
||||
|
||||
cpage = read_mapping_page(inode->i_mapping, 0, NULL);
|
||||
if (IS_ERR(cpage))
|
||||
return ERR_CAST(cpage);
|
||||
caddr = page_address(cpage);
|
||||
page = read_mapping_page(inode->i_mapping, 0, NULL);
|
||||
if (IS_ERR(page))
|
||||
return ERR_CAST(page);
|
||||
|
||||
/* Symlink is encrypted */
|
||||
sd = (struct fscrypt_symlink_data *)caddr;
|
||||
cstr.name = sd->encrypted_path;
|
||||
cstr.len = le16_to_cpu(sd->len);
|
||||
|
||||
/* this is broken symlink case */
|
||||
if (unlikely(cstr.len == 0)) {
|
||||
res = -ENOENT;
|
||||
goto errout;
|
||||
}
|
||||
|
||||
if ((cstr.len + sizeof(struct fscrypt_symlink_data) - 1) > max_size) {
|
||||
/* Symlink data on the disk is corrupted */
|
||||
res = -EIO;
|
||||
goto errout;
|
||||
}
|
||||
res = fscrypt_fname_alloc_buffer(inode, cstr.len, &pstr);
|
||||
if (res)
|
||||
goto errout;
|
||||
|
||||
res = fscrypt_fname_disk_to_usr(inode, 0, 0, &cstr, &pstr);
|
||||
if (res)
|
||||
goto errout;
|
||||
|
||||
/* this is broken symlink case */
|
||||
if (unlikely(pstr.name[0] == 0)) {
|
||||
res = -ENOENT;
|
||||
goto errout;
|
||||
}
|
||||
|
||||
paddr = pstr.name;
|
||||
|
||||
/* Null-terminate the name */
|
||||
paddr[pstr.len] = '\0';
|
||||
|
||||
put_page(cpage);
|
||||
return *cookie = paddr;
|
||||
errout:
|
||||
fscrypt_fname_free_buffer(&pstr);
|
||||
put_page(cpage);
|
||||
return ERR_PTR(res);
|
||||
target = fscrypt_get_symlink(inode, page_address(page),
|
||||
inode->i_sb->s_blocksize);
|
||||
put_page(page);
|
||||
return *cookie = target;
|
||||
}
|
||||
|
||||
const struct inode_operations f2fs_encrypted_symlink_inode_operations = {
|
||||
|
|
|
@ -193,8 +193,8 @@ static void __del_from_nat_cache(struct f2fs_nm_info *nm_i, struct nat_entry *e)
|
|||
__free_nat_entry(e);
|
||||
}
|
||||
|
||||
static void __set_nat_cache_dirty(struct f2fs_nm_info *nm_i,
|
||||
struct nat_entry *ne)
|
||||
static struct nat_entry_set *__grab_nat_entry_set(struct f2fs_nm_info *nm_i,
|
||||
struct nat_entry *ne)
|
||||
{
|
||||
nid_t set = NAT_BLOCK_OFFSET(ne->ni.nid);
|
||||
struct nat_entry_set *head;
|
||||
|
@ -209,15 +209,36 @@ static void __set_nat_cache_dirty(struct f2fs_nm_info *nm_i,
|
|||
head->entry_cnt = 0;
|
||||
f2fs_radix_tree_insert(&nm_i->nat_set_root, set, head);
|
||||
}
|
||||
return head;
|
||||
}
|
||||
|
||||
static void __set_nat_cache_dirty(struct f2fs_nm_info *nm_i,
|
||||
struct nat_entry *ne)
|
||||
{
|
||||
struct nat_entry_set *head;
|
||||
bool new_ne = nat_get_blkaddr(ne) == NEW_ADDR;
|
||||
|
||||
if (!new_ne)
|
||||
head = __grab_nat_entry_set(nm_i, ne);
|
||||
|
||||
/*
|
||||
* update entry_cnt in below condition:
|
||||
* 1. update NEW_ADDR to valid block address;
|
||||
* 2. update old block address to new one;
|
||||
*/
|
||||
if (!new_ne && (get_nat_flag(ne, IS_PREALLOC) ||
|
||||
!get_nat_flag(ne, IS_DIRTY)))
|
||||
head->entry_cnt++;
|
||||
|
||||
set_nat_flag(ne, IS_PREALLOC, new_ne);
|
||||
|
||||
if (get_nat_flag(ne, IS_DIRTY))
|
||||
goto refresh_list;
|
||||
|
||||
nm_i->dirty_nat_cnt++;
|
||||
head->entry_cnt++;
|
||||
set_nat_flag(ne, IS_DIRTY, true);
|
||||
refresh_list:
|
||||
if (nat_get_blkaddr(ne) == NEW_ADDR)
|
||||
if (new_ne)
|
||||
list_del_init(&ne->list);
|
||||
else
|
||||
list_move_tail(&ne->list, &head->entry_list);
|
||||
|
@ -1076,7 +1097,7 @@ struct page *new_node_page(struct dnode_of_data *dn, unsigned int ofs)
|
|||
|
||||
f2fs_wait_on_page_writeback(page, NODE, true);
|
||||
fill_node_footer(page, dn->nid, dn->inode->i_ino, ofs, true);
|
||||
set_cold_node(dn->inode, page);
|
||||
set_cold_node(page, S_ISDIR(dn->inode->i_mode));
|
||||
if (!PageUptodate(page))
|
||||
SetPageUptodate(page);
|
||||
if (set_page_dirty(page))
|
||||
|
@ -2313,6 +2334,7 @@ retry:
|
|||
if (!PageUptodate(ipage))
|
||||
SetPageUptodate(ipage);
|
||||
fill_node_footer(ipage, ino, ino, 0, true);
|
||||
set_cold_node(page, false);
|
||||
|
||||
src = F2FS_INODE(page);
|
||||
dst = F2FS_INODE(ipage);
|
||||
|
@ -2602,8 +2624,7 @@ static int __get_nat_bitmaps(struct f2fs_sb_info *sbi)
|
|||
if (!enabled_nat_bits(sbi, NULL))
|
||||
return 0;
|
||||
|
||||
nm_i->nat_bits_blocks = F2FS_BYTES_TO_BLK((nat_bits_bytes << 1) + 8 +
|
||||
F2FS_BLKSIZE - 1);
|
||||
nm_i->nat_bits_blocks = F2FS_BLK_ALIGN((nat_bits_bytes << 1) + 8);
|
||||
nm_i->nat_bits = f2fs_kzalloc(sbi,
|
||||
nm_i->nat_bits_blocks << F2FS_BLKSIZE_BITS, GFP_KERNEL);
|
||||
if (!nm_i->nat_bits)
|
||||
|
@ -2729,12 +2750,20 @@ static int init_node_manager(struct f2fs_sb_info *sbi)
|
|||
static int init_free_nid_cache(struct f2fs_sb_info *sbi)
|
||||
{
|
||||
struct f2fs_nm_info *nm_i = NM_I(sbi);
|
||||
int i;
|
||||
|
||||
nm_i->free_nid_bitmap = f2fs_kvzalloc(sbi, nm_i->nat_blocks *
|
||||
NAT_ENTRY_BITMAP_SIZE, GFP_KERNEL);
|
||||
nm_i->free_nid_bitmap = f2fs_kzalloc(sbi, nm_i->nat_blocks *
|
||||
sizeof(unsigned char *), GFP_KERNEL);
|
||||
if (!nm_i->free_nid_bitmap)
|
||||
return -ENOMEM;
|
||||
|
||||
for (i = 0; i < nm_i->nat_blocks; i++) {
|
||||
nm_i->free_nid_bitmap[i] = f2fs_kvzalloc(sbi,
|
||||
NAT_ENTRY_BITMAP_SIZE_ALIGNED, GFP_KERNEL);
|
||||
if (!nm_i->free_nid_bitmap)
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
nm_i->nat_block_bitmap = f2fs_kvzalloc(sbi, nm_i->nat_blocks / 8,
|
||||
GFP_KERNEL);
|
||||
if (!nm_i->nat_block_bitmap)
|
||||
|
@ -2825,7 +2854,13 @@ void destroy_node_manager(struct f2fs_sb_info *sbi)
|
|||
up_write(&nm_i->nat_tree_lock);
|
||||
|
||||
kvfree(nm_i->nat_block_bitmap);
|
||||
kvfree(nm_i->free_nid_bitmap);
|
||||
if (nm_i->free_nid_bitmap) {
|
||||
int i;
|
||||
|
||||
for (i = 0; i < nm_i->nat_blocks; i++)
|
||||
kvfree(nm_i->free_nid_bitmap[i]);
|
||||
kfree(nm_i->free_nid_bitmap);
|
||||
}
|
||||
kvfree(nm_i->free_nid_count);
|
||||
|
||||
kfree(nm_i->nat_bitmap);
|
||||
|
|
|
@ -44,6 +44,7 @@ enum {
|
|||
HAS_FSYNCED_INODE, /* is the inode fsynced before? */
|
||||
HAS_LAST_FSYNC, /* has the latest node fsync mark? */
|
||||
IS_DIRTY, /* this nat entry is dirty? */
|
||||
IS_PREALLOC, /* nat entry is preallocated */
|
||||
};
|
||||
|
||||
/*
|
||||
|
@ -422,12 +423,12 @@ static inline void clear_inline_node(struct page *page)
|
|||
ClearPageChecked(page);
|
||||
}
|
||||
|
||||
static inline void set_cold_node(struct inode *inode, struct page *page)
|
||||
static inline void set_cold_node(struct page *page, bool is_dir)
|
||||
{
|
||||
struct f2fs_node *rn = F2FS_NODE(page);
|
||||
unsigned int flag = le32_to_cpu(rn->footer.flag);
|
||||
|
||||
if (S_ISDIR(inode->i_mode))
|
||||
if (is_dir)
|
||||
flag &= ~(0x1 << COLD_BIT_SHIFT);
|
||||
else
|
||||
flag |= (0x1 << COLD_BIT_SHIFT);
|
||||
|
|
|
@ -242,6 +242,9 @@ static int find_fsync_dnodes(struct f2fs_sb_info *sbi, struct list_head *head,
|
|||
struct curseg_info *curseg;
|
||||
struct page *page = NULL;
|
||||
block_t blkaddr;
|
||||
unsigned int loop_cnt = 0;
|
||||
unsigned int free_blocks = sbi->user_block_count -
|
||||
valid_user_blocks(sbi);
|
||||
int err = 0;
|
||||
|
||||
/* get node pages in the current segment */
|
||||
|
@ -294,6 +297,17 @@ static int find_fsync_dnodes(struct f2fs_sb_info *sbi, struct list_head *head,
|
|||
if (IS_INODE(page) && is_dent_dnode(page))
|
||||
entry->last_dentry = blkaddr;
|
||||
next:
|
||||
/* sanity check in order to detect looped node chain */
|
||||
if (++loop_cnt >= free_blocks ||
|
||||
blkaddr == next_blkaddr_of_node(page)) {
|
||||
f2fs_msg(sbi->sb, KERN_NOTICE,
|
||||
"%s: detect looped node chain, "
|
||||
"blkaddr:%u, next:%u",
|
||||
__func__, blkaddr, next_blkaddr_of_node(page));
|
||||
err = -EINVAL;
|
||||
break;
|
||||
}
|
||||
|
||||
/* check next segment */
|
||||
blkaddr = next_blkaddr_of_node(page);
|
||||
f2fs_put_page(page, 1);
|
||||
|
|
|
@ -1491,12 +1491,11 @@ static int issue_discard_thread(void *data)
|
|||
if (kthread_should_stop())
|
||||
return 0;
|
||||
|
||||
if (dcc->discard_wake) {
|
||||
if (dcc->discard_wake)
|
||||
dcc->discard_wake = 0;
|
||||
if (sbi->gc_thread && sbi->gc_thread->gc_urgent)
|
||||
init_discard_policy(&dpolicy,
|
||||
DPOLICY_FORCE, 1);
|
||||
}
|
||||
|
||||
if (sbi->gc_thread && sbi->gc_thread->gc_urgent)
|
||||
init_discard_policy(&dpolicy, DPOLICY_FORCE, 1);
|
||||
|
||||
sb_start_intwrite(sbi->sb);
|
||||
|
||||
|
@ -1565,7 +1564,7 @@ static int __issue_discard_async(struct f2fs_sb_info *sbi,
|
|||
struct block_device *bdev, block_t blkstart, block_t blklen)
|
||||
{
|
||||
#ifdef CONFIG_BLK_DEV_ZONED
|
||||
if (f2fs_sb_mounted_blkzoned(sbi->sb) &&
|
||||
if (f2fs_sb_has_blkzoned(sbi->sb) &&
|
||||
bdev_zoned_model(bdev) != BLK_ZONED_NONE)
|
||||
return __f2fs_issue_discard_zone(sbi, bdev, blkstart, blklen);
|
||||
#endif
|
||||
|
@ -1763,7 +1762,7 @@ find_next:
|
|||
sbi->blocks_per_seg, cur_pos);
|
||||
len = next_pos - cur_pos;
|
||||
|
||||
if (f2fs_sb_mounted_blkzoned(sbi->sb) ||
|
||||
if (f2fs_sb_has_blkzoned(sbi->sb) ||
|
||||
(force && len < cpc->trim_minlen))
|
||||
goto skip;
|
||||
|
||||
|
@ -1807,7 +1806,7 @@ void init_discard_policy(struct discard_policy *dpolicy,
|
|||
} else if (discard_type == DPOLICY_FORCE) {
|
||||
dpolicy->min_interval = DEF_MIN_DISCARD_ISSUE_TIME;
|
||||
dpolicy->max_interval = DEF_MAX_DISCARD_ISSUE_TIME;
|
||||
dpolicy->io_aware = true;
|
||||
dpolicy->io_aware = false;
|
||||
} else if (discard_type == DPOLICY_FSTRIM) {
|
||||
dpolicy->io_aware = false;
|
||||
} else if (discard_type == DPOLICY_UMOUNT) {
|
||||
|
@ -1943,7 +1942,7 @@ static void update_sit_entry(struct f2fs_sb_info *sbi, block_t blkaddr, int del)
|
|||
sbi->discard_blks--;
|
||||
|
||||
/* don't overwrite by SSR to keep node chain */
|
||||
if (se->type == CURSEG_WARM_NODE) {
|
||||
if (IS_NODESEG(se->type)) {
|
||||
if (!f2fs_test_and_set_bit(offset, se->ckpt_valid_map))
|
||||
se->ckpt_valid_blocks++;
|
||||
}
|
||||
|
@ -2244,11 +2243,17 @@ static unsigned int __get_next_segno(struct f2fs_sb_info *sbi, int type)
|
|||
if (sbi->segs_per_sec != 1)
|
||||
return CURSEG_I(sbi, type)->segno;
|
||||
|
||||
if (type == CURSEG_HOT_DATA || IS_NODESEG(type))
|
||||
if (test_opt(sbi, NOHEAP) &&
|
||||
(type == CURSEG_HOT_DATA || IS_NODESEG(type)))
|
||||
return 0;
|
||||
|
||||
if (SIT_I(sbi)->last_victim[ALLOC_NEXT])
|
||||
return SIT_I(sbi)->last_victim[ALLOC_NEXT];
|
||||
|
||||
/* find segments from 0 to reuse freed segments */
|
||||
if (F2FS_OPTION(sbi).alloc_mode == ALLOC_MODE_REUSE)
|
||||
return 0;
|
||||
|
||||
return CURSEG_I(sbi, type)->segno;
|
||||
}
|
||||
|
||||
|
@ -2535,6 +2540,101 @@ int rw_hint_to_seg_type(enum rw_hint hint)
|
|||
}
|
||||
}
|
||||
|
||||
/* This returns write hints for each segment type. This hints will be
|
||||
* passed down to block layer. There are mapping tables which depend on
|
||||
* the mount option 'whint_mode'.
|
||||
*
|
||||
* 1) whint_mode=off. F2FS only passes down WRITE_LIFE_NOT_SET.
|
||||
*
|
||||
* 2) whint_mode=user-based. F2FS tries to pass down hints given by users.
|
||||
*
|
||||
* User F2FS Block
|
||||
* ---- ---- -----
|
||||
* META WRITE_LIFE_NOT_SET
|
||||
* HOT_NODE "
|
||||
* WARM_NODE "
|
||||
* COLD_NODE "
|
||||
* ioctl(COLD) COLD_DATA WRITE_LIFE_EXTREME
|
||||
* extension list " "
|
||||
*
|
||||
* -- buffered io
|
||||
* WRITE_LIFE_EXTREME COLD_DATA WRITE_LIFE_EXTREME
|
||||
* WRITE_LIFE_SHORT HOT_DATA WRITE_LIFE_SHORT
|
||||
* WRITE_LIFE_NOT_SET WARM_DATA WRITE_LIFE_NOT_SET
|
||||
* WRITE_LIFE_NONE " "
|
||||
* WRITE_LIFE_MEDIUM " "
|
||||
* WRITE_LIFE_LONG " "
|
||||
*
|
||||
* -- direct io
|
||||
* WRITE_LIFE_EXTREME COLD_DATA WRITE_LIFE_EXTREME
|
||||
* WRITE_LIFE_SHORT HOT_DATA WRITE_LIFE_SHORT
|
||||
* WRITE_LIFE_NOT_SET WARM_DATA WRITE_LIFE_NOT_SET
|
||||
* WRITE_LIFE_NONE " WRITE_LIFE_NONE
|
||||
* WRITE_LIFE_MEDIUM " WRITE_LIFE_MEDIUM
|
||||
* WRITE_LIFE_LONG " WRITE_LIFE_LONG
|
||||
*
|
||||
* 3) whint_mode=fs-based. F2FS passes down hints with its policy.
|
||||
*
|
||||
* User F2FS Block
|
||||
* ---- ---- -----
|
||||
* META WRITE_LIFE_MEDIUM;
|
||||
* HOT_NODE WRITE_LIFE_NOT_SET
|
||||
* WARM_NODE "
|
||||
* COLD_NODE WRITE_LIFE_NONE
|
||||
* ioctl(COLD) COLD_DATA WRITE_LIFE_EXTREME
|
||||
* extension list " "
|
||||
*
|
||||
* -- buffered io
|
||||
* WRITE_LIFE_EXTREME COLD_DATA WRITE_LIFE_EXTREME
|
||||
* WRITE_LIFE_SHORT HOT_DATA WRITE_LIFE_SHORT
|
||||
* WRITE_LIFE_NOT_SET WARM_DATA WRITE_LIFE_LONG
|
||||
* WRITE_LIFE_NONE " "
|
||||
* WRITE_LIFE_MEDIUM " "
|
||||
* WRITE_LIFE_LONG " "
|
||||
*
|
||||
* -- direct io
|
||||
* WRITE_LIFE_EXTREME COLD_DATA WRITE_LIFE_EXTREME
|
||||
* WRITE_LIFE_SHORT HOT_DATA WRITE_LIFE_SHORT
|
||||
* WRITE_LIFE_NOT_SET WARM_DATA WRITE_LIFE_NOT_SET
|
||||
* WRITE_LIFE_NONE " WRITE_LIFE_NONE
|
||||
* WRITE_LIFE_MEDIUM " WRITE_LIFE_MEDIUM
|
||||
* WRITE_LIFE_LONG " WRITE_LIFE_LONG
|
||||
*/
|
||||
|
||||
enum rw_hint io_type_to_rw_hint(struct f2fs_sb_info *sbi,
|
||||
enum page_type type, enum temp_type temp)
|
||||
{
|
||||
if (F2FS_OPTION(sbi).whint_mode == WHINT_MODE_USER) {
|
||||
if (type == DATA) {
|
||||
if (temp == WARM)
|
||||
return WRITE_LIFE_NOT_SET;
|
||||
else if (temp == HOT)
|
||||
return WRITE_LIFE_SHORT;
|
||||
else if (temp == COLD)
|
||||
return WRITE_LIFE_EXTREME;
|
||||
} else {
|
||||
return WRITE_LIFE_NOT_SET;
|
||||
}
|
||||
} else if (F2FS_OPTION(sbi).whint_mode == WHINT_MODE_FS) {
|
||||
if (type == DATA) {
|
||||
if (temp == WARM)
|
||||
return WRITE_LIFE_LONG;
|
||||
else if (temp == HOT)
|
||||
return WRITE_LIFE_SHORT;
|
||||
else if (temp == COLD)
|
||||
return WRITE_LIFE_EXTREME;
|
||||
} else if (type == NODE) {
|
||||
if (temp == WARM || temp == HOT)
|
||||
return WRITE_LIFE_NOT_SET;
|
||||
else if (temp == COLD)
|
||||
return WRITE_LIFE_NONE;
|
||||
} else if (type == META) {
|
||||
return WRITE_LIFE_MEDIUM;
|
||||
}
|
||||
}
|
||||
return WRITE_LIFE_NOT_SET;
|
||||
}
|
||||
|
||||
static int __get_segment_type_2(struct f2fs_io_info *fio)
|
||||
{
|
||||
if (fio->type == DATA)
|
||||
|
@ -2567,7 +2667,8 @@ static int __get_segment_type_6(struct f2fs_io_info *fio)
|
|||
|
||||
if (is_cold_data(fio->page) || file_is_cold(inode))
|
||||
return CURSEG_COLD_DATA;
|
||||
if (is_inode_flag_set(inode, FI_HOT_DATA))
|
||||
if (file_is_hot(inode) ||
|
||||
is_inode_flag_set(inode, FI_HOT_DATA))
|
||||
return CURSEG_HOT_DATA;
|
||||
/* rw_hint_to_seg_type(inode->i_write_hint); */
|
||||
return CURSEG_WARM_DATA;
|
||||
|
@ -2583,7 +2684,7 @@ static int __get_segment_type(struct f2fs_io_info *fio)
|
|||
{
|
||||
int type = 0;
|
||||
|
||||
switch (fio->sbi->active_logs) {
|
||||
switch (F2FS_OPTION(fio->sbi).active_logs) {
|
||||
case 2:
|
||||
type = __get_segment_type_2(fio);
|
||||
break;
|
||||
|
@ -2723,6 +2824,7 @@ void write_meta_page(struct f2fs_sb_info *sbi, struct page *page,
|
|||
struct f2fs_io_info fio = {
|
||||
.sbi = sbi,
|
||||
.type = META,
|
||||
.temp = HOT,
|
||||
.op = REQ_OP_WRITE,
|
||||
.op_flags = REQ_SYNC | REQ_NOIDLE | REQ_META | REQ_PRIO,
|
||||
.old_blkaddr = page->index,
|
||||
|
@ -2769,8 +2871,15 @@ void write_data_page(struct dnode_of_data *dn, struct f2fs_io_info *fio)
|
|||
int rewrite_data_page(struct f2fs_io_info *fio)
|
||||
{
|
||||
int err;
|
||||
struct f2fs_sb_info *sbi = fio->sbi;
|
||||
|
||||
fio->new_blkaddr = fio->old_blkaddr;
|
||||
/* i/o temperature is needed for passing down write hints */
|
||||
__get_segment_type(fio);
|
||||
|
||||
f2fs_bug_on(sbi, !IS_DATASEG(get_seg_entry(sbi,
|
||||
GET_SEGNO(sbi, fio->new_blkaddr))->type));
|
||||
|
||||
stat_inc_inplace_blocks(fio->sbi);
|
||||
|
||||
err = f2fs_submit_page_bio(fio);
|
||||
|
|
|
@ -53,13 +53,19 @@
|
|||
((secno) == CURSEG_I(sbi, CURSEG_COLD_NODE)->segno / \
|
||||
(sbi)->segs_per_sec)) \
|
||||
|
||||
#define MAIN_BLKADDR(sbi) (SM_I(sbi)->main_blkaddr)
|
||||
#define SEG0_BLKADDR(sbi) (SM_I(sbi)->seg0_blkaddr)
|
||||
#define MAIN_BLKADDR(sbi) \
|
||||
(SM_I(sbi) ? SM_I(sbi)->main_blkaddr : \
|
||||
le32_to_cpu(F2FS_RAW_SUPER(sbi)->main_blkaddr))
|
||||
#define SEG0_BLKADDR(sbi) \
|
||||
(SM_I(sbi) ? SM_I(sbi)->seg0_blkaddr : \
|
||||
le32_to_cpu(F2FS_RAW_SUPER(sbi)->segment0_blkaddr))
|
||||
|
||||
#define MAIN_SEGS(sbi) (SM_I(sbi)->main_segments)
|
||||
#define MAIN_SECS(sbi) ((sbi)->total_sections)
|
||||
|
||||
#define TOTAL_SEGS(sbi) (SM_I(sbi)->segment_count)
|
||||
#define TOTAL_SEGS(sbi) \
|
||||
(SM_I(sbi) ? SM_I(sbi)->segment_count : \
|
||||
le32_to_cpu(F2FS_RAW_SUPER(sbi)->segment_count))
|
||||
#define TOTAL_BLKS(sbi) (TOTAL_SEGS(sbi) << (sbi)->log_blocks_per_seg)
|
||||
|
||||
#define MAX_BLKADDR(sbi) (SEG0_BLKADDR(sbi) + TOTAL_BLKS(sbi))
|
||||
|
@ -596,6 +602,8 @@ static inline int utilization(struct f2fs_sb_info *sbi)
|
|||
#define DEF_MIN_FSYNC_BLOCKS 8
|
||||
#define DEF_MIN_HOT_BLOCKS 16
|
||||
|
||||
#define SMALL_VOLUME_SEGMENTS (16 * 512) /* 16GB */
|
||||
|
||||
enum {
|
||||
F2FS_IPU_FORCE,
|
||||
F2FS_IPU_SSR,
|
||||
|
@ -630,10 +638,17 @@ static inline void check_seg_range(struct f2fs_sb_info *sbi, unsigned int segno)
|
|||
f2fs_bug_on(sbi, segno > TOTAL_SEGS(sbi) - 1);
|
||||
}
|
||||
|
||||
static inline void verify_block_addr(struct f2fs_sb_info *sbi, block_t blk_addr)
|
||||
static inline void verify_block_addr(struct f2fs_io_info *fio, block_t blk_addr)
|
||||
{
|
||||
BUG_ON(blk_addr < SEG0_BLKADDR(sbi)
|
||||
|| blk_addr >= MAX_BLKADDR(sbi));
|
||||
struct f2fs_sb_info *sbi = fio->sbi;
|
||||
|
||||
if (PAGE_TYPE_OF_BIO(fio->type) == META &&
|
||||
(!is_read_io(fio->op) || fio->is_meta))
|
||||
BUG_ON(blk_addr < SEG0_BLKADDR(sbi) ||
|
||||
blk_addr >= MAIN_BLKADDR(sbi));
|
||||
else
|
||||
BUG_ON(blk_addr < MAIN_BLKADDR(sbi) ||
|
||||
blk_addr >= MAX_BLKADDR(sbi));
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
348
fs/f2fs/super.c
348
fs/f2fs/super.c
|
@ -60,7 +60,7 @@ char *fault_name[FAULT_MAX] = {
|
|||
static void f2fs_build_fault_attr(struct f2fs_sb_info *sbi,
|
||||
unsigned int rate)
|
||||
{
|
||||
struct f2fs_fault_info *ffi = &sbi->fault_info;
|
||||
struct f2fs_fault_info *ffi = &F2FS_OPTION(sbi).fault_info;
|
||||
|
||||
if (rate) {
|
||||
atomic_set(&ffi->inject_ops, 0);
|
||||
|
@ -129,6 +129,10 @@ enum {
|
|||
Opt_jqfmt_vfsold,
|
||||
Opt_jqfmt_vfsv0,
|
||||
Opt_jqfmt_vfsv1,
|
||||
Opt_whint,
|
||||
Opt_alloc,
|
||||
Opt_fsync,
|
||||
Opt_test_dummy_encryption,
|
||||
Opt_err,
|
||||
};
|
||||
|
||||
|
@ -182,6 +186,10 @@ static match_table_t f2fs_tokens = {
|
|||
{Opt_jqfmt_vfsold, "jqfmt=vfsold"},
|
||||
{Opt_jqfmt_vfsv0, "jqfmt=vfsv0"},
|
||||
{Opt_jqfmt_vfsv1, "jqfmt=vfsv1"},
|
||||
{Opt_whint, "whint_mode=%s"},
|
||||
{Opt_alloc, "alloc_mode=%s"},
|
||||
{Opt_fsync, "fsync_mode=%s"},
|
||||
{Opt_test_dummy_encryption, "test_dummy_encryption"},
|
||||
{Opt_err, NULL},
|
||||
};
|
||||
|
||||
|
@ -202,21 +210,24 @@ static inline void limit_reserve_root(struct f2fs_sb_info *sbi)
|
|||
block_t limit = (sbi->user_block_count << 1) / 1000;
|
||||
|
||||
/* limit is 0.2% */
|
||||
if (test_opt(sbi, RESERVE_ROOT) && sbi->root_reserved_blocks > limit) {
|
||||
sbi->root_reserved_blocks = limit;
|
||||
if (test_opt(sbi, RESERVE_ROOT) &&
|
||||
F2FS_OPTION(sbi).root_reserved_blocks > limit) {
|
||||
F2FS_OPTION(sbi).root_reserved_blocks = limit;
|
||||
f2fs_msg(sbi->sb, KERN_INFO,
|
||||
"Reduce reserved blocks for root = %u",
|
||||
sbi->root_reserved_blocks);
|
||||
F2FS_OPTION(sbi).root_reserved_blocks);
|
||||
}
|
||||
if (!test_opt(sbi, RESERVE_ROOT) &&
|
||||
(!uid_eq(sbi->s_resuid,
|
||||
(!uid_eq(F2FS_OPTION(sbi).s_resuid,
|
||||
make_kuid(&init_user_ns, F2FS_DEF_RESUID)) ||
|
||||
!gid_eq(sbi->s_resgid,
|
||||
!gid_eq(F2FS_OPTION(sbi).s_resgid,
|
||||
make_kgid(&init_user_ns, F2FS_DEF_RESGID))))
|
||||
f2fs_msg(sbi->sb, KERN_INFO,
|
||||
"Ignore s_resuid=%u, s_resgid=%u w/o reserve_root",
|
||||
from_kuid_munged(&init_user_ns, sbi->s_resuid),
|
||||
from_kgid_munged(&init_user_ns, sbi->s_resgid));
|
||||
from_kuid_munged(&init_user_ns,
|
||||
F2FS_OPTION(sbi).s_resuid),
|
||||
from_kgid_munged(&init_user_ns,
|
||||
F2FS_OPTION(sbi).s_resgid));
|
||||
}
|
||||
|
||||
static void init_once(void *foo)
|
||||
|
@ -236,7 +247,7 @@ static int f2fs_set_qf_name(struct super_block *sb, int qtype,
|
|||
char *qname;
|
||||
int ret = -EINVAL;
|
||||
|
||||
if (sb_any_quota_loaded(sb) && !sbi->s_qf_names[qtype]) {
|
||||
if (sb_any_quota_loaded(sb) && !F2FS_OPTION(sbi).s_qf_names[qtype]) {
|
||||
f2fs_msg(sb, KERN_ERR,
|
||||
"Cannot change journaled "
|
||||
"quota options when quota turned on");
|
||||
|
@ -254,8 +265,8 @@ static int f2fs_set_qf_name(struct super_block *sb, int qtype,
|
|||
"Not enough memory for storing quotafile name");
|
||||
return -EINVAL;
|
||||
}
|
||||
if (sbi->s_qf_names[qtype]) {
|
||||
if (strcmp(sbi->s_qf_names[qtype], qname) == 0)
|
||||
if (F2FS_OPTION(sbi).s_qf_names[qtype]) {
|
||||
if (strcmp(F2FS_OPTION(sbi).s_qf_names[qtype], qname) == 0)
|
||||
ret = 0;
|
||||
else
|
||||
f2fs_msg(sb, KERN_ERR,
|
||||
|
@ -268,7 +279,7 @@ static int f2fs_set_qf_name(struct super_block *sb, int qtype,
|
|||
"quotafile must be on filesystem root");
|
||||
goto errout;
|
||||
}
|
||||
sbi->s_qf_names[qtype] = qname;
|
||||
F2FS_OPTION(sbi).s_qf_names[qtype] = qname;
|
||||
set_opt(sbi, QUOTA);
|
||||
return 0;
|
||||
errout:
|
||||
|
@ -280,13 +291,13 @@ static int f2fs_clear_qf_name(struct super_block *sb, int qtype)
|
|||
{
|
||||
struct f2fs_sb_info *sbi = F2FS_SB(sb);
|
||||
|
||||
if (sb_any_quota_loaded(sb) && sbi->s_qf_names[qtype]) {
|
||||
if (sb_any_quota_loaded(sb) && F2FS_OPTION(sbi).s_qf_names[qtype]) {
|
||||
f2fs_msg(sb, KERN_ERR, "Cannot change journaled quota options"
|
||||
" when quota turned on");
|
||||
return -EINVAL;
|
||||
}
|
||||
kfree(sbi->s_qf_names[qtype]);
|
||||
sbi->s_qf_names[qtype] = NULL;
|
||||
kfree(F2FS_OPTION(sbi).s_qf_names[qtype]);
|
||||
F2FS_OPTION(sbi).s_qf_names[qtype] = NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -302,15 +313,19 @@ static int f2fs_check_quota_options(struct f2fs_sb_info *sbi)
|
|||
"Cannot enable project quota enforcement.");
|
||||
return -1;
|
||||
}
|
||||
if (sbi->s_qf_names[USRQUOTA] || sbi->s_qf_names[GRPQUOTA] ||
|
||||
sbi->s_qf_names[PRJQUOTA]) {
|
||||
if (test_opt(sbi, USRQUOTA) && sbi->s_qf_names[USRQUOTA])
|
||||
if (F2FS_OPTION(sbi).s_qf_names[USRQUOTA] ||
|
||||
F2FS_OPTION(sbi).s_qf_names[GRPQUOTA] ||
|
||||
F2FS_OPTION(sbi).s_qf_names[PRJQUOTA]) {
|
||||
if (test_opt(sbi, USRQUOTA) &&
|
||||
F2FS_OPTION(sbi).s_qf_names[USRQUOTA])
|
||||
clear_opt(sbi, USRQUOTA);
|
||||
|
||||
if (test_opt(sbi, GRPQUOTA) && sbi->s_qf_names[GRPQUOTA])
|
||||
if (test_opt(sbi, GRPQUOTA) &&
|
||||
F2FS_OPTION(sbi).s_qf_names[GRPQUOTA])
|
||||
clear_opt(sbi, GRPQUOTA);
|
||||
|
||||
if (test_opt(sbi, PRJQUOTA) && sbi->s_qf_names[PRJQUOTA])
|
||||
if (test_opt(sbi, PRJQUOTA) &&
|
||||
F2FS_OPTION(sbi).s_qf_names[PRJQUOTA])
|
||||
clear_opt(sbi, PRJQUOTA);
|
||||
|
||||
if (test_opt(sbi, GRPQUOTA) || test_opt(sbi, USRQUOTA) ||
|
||||
|
@ -320,19 +335,19 @@ static int f2fs_check_quota_options(struct f2fs_sb_info *sbi)
|
|||
return -1;
|
||||
}
|
||||
|
||||
if (!sbi->s_jquota_fmt) {
|
||||
if (!F2FS_OPTION(sbi).s_jquota_fmt) {
|
||||
f2fs_msg(sbi->sb, KERN_ERR, "journaled quota format "
|
||||
"not specified");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
if (f2fs_sb_has_quota_ino(sbi->sb) && sbi->s_jquota_fmt) {
|
||||
if (f2fs_sb_has_quota_ino(sbi->sb) && F2FS_OPTION(sbi).s_jquota_fmt) {
|
||||
f2fs_msg(sbi->sb, KERN_INFO,
|
||||
"QUOTA feature is enabled, so ignore jquota_fmt");
|
||||
sbi->s_jquota_fmt = 0;
|
||||
F2FS_OPTION(sbi).s_jquota_fmt = 0;
|
||||
}
|
||||
if (f2fs_sb_has_quota_ino(sbi->sb) && sb_rdonly(sbi->sb)) {
|
||||
if (f2fs_sb_has_quota_ino(sbi->sb) && f2fs_readonly(sbi->sb)) {
|
||||
f2fs_msg(sbi->sb, KERN_INFO,
|
||||
"Filesystem with quota feature cannot be mounted RDWR "
|
||||
"without CONFIG_QUOTA");
|
||||
|
@ -403,14 +418,14 @@ static int parse_options(struct super_block *sb, char *options)
|
|||
q = bdev_get_queue(sb->s_bdev);
|
||||
if (blk_queue_discard(q)) {
|
||||
set_opt(sbi, DISCARD);
|
||||
} else if (!f2fs_sb_mounted_blkzoned(sb)) {
|
||||
} else if (!f2fs_sb_has_blkzoned(sb)) {
|
||||
f2fs_msg(sb, KERN_WARNING,
|
||||
"mounting with \"discard\" option, but "
|
||||
"the device does not support discard");
|
||||
}
|
||||
break;
|
||||
case Opt_nodiscard:
|
||||
if (f2fs_sb_mounted_blkzoned(sb)) {
|
||||
if (f2fs_sb_has_blkzoned(sb)) {
|
||||
f2fs_msg(sb, KERN_WARNING,
|
||||
"discard is required for zoned block devices");
|
||||
return -EINVAL;
|
||||
|
@ -440,7 +455,7 @@ static int parse_options(struct super_block *sb, char *options)
|
|||
if (args->from && match_int(args, &arg))
|
||||
return -EINVAL;
|
||||
set_opt(sbi, INLINE_XATTR_SIZE);
|
||||
sbi->inline_xattr_size = arg;
|
||||
F2FS_OPTION(sbi).inline_xattr_size = arg;
|
||||
break;
|
||||
#else
|
||||
case Opt_user_xattr:
|
||||
|
@ -480,7 +495,7 @@ static int parse_options(struct super_block *sb, char *options)
|
|||
return -EINVAL;
|
||||
if (arg != 2 && arg != 4 && arg != NR_CURSEG_TYPE)
|
||||
return -EINVAL;
|
||||
sbi->active_logs = arg;
|
||||
F2FS_OPTION(sbi).active_logs = arg;
|
||||
break;
|
||||
case Opt_disable_ext_identify:
|
||||
set_opt(sbi, DISABLE_EXT_IDENTIFY);
|
||||
|
@ -524,9 +539,9 @@ static int parse_options(struct super_block *sb, char *options)
|
|||
if (test_opt(sbi, RESERVE_ROOT)) {
|
||||
f2fs_msg(sb, KERN_INFO,
|
||||
"Preserve previous reserve_root=%u",
|
||||
sbi->root_reserved_blocks);
|
||||
F2FS_OPTION(sbi).root_reserved_blocks);
|
||||
} else {
|
||||
sbi->root_reserved_blocks = arg;
|
||||
F2FS_OPTION(sbi).root_reserved_blocks = arg;
|
||||
set_opt(sbi, RESERVE_ROOT);
|
||||
}
|
||||
break;
|
||||
|
@ -539,7 +554,7 @@ static int parse_options(struct super_block *sb, char *options)
|
|||
"Invalid uid value %d", arg);
|
||||
return -EINVAL;
|
||||
}
|
||||
sbi->s_resuid = uid;
|
||||
F2FS_OPTION(sbi).s_resuid = uid;
|
||||
break;
|
||||
case Opt_resgid:
|
||||
if (args->from && match_int(args, &arg))
|
||||
|
@ -550,7 +565,7 @@ static int parse_options(struct super_block *sb, char *options)
|
|||
"Invalid gid value %d", arg);
|
||||
return -EINVAL;
|
||||
}
|
||||
sbi->s_resgid = gid;
|
||||
F2FS_OPTION(sbi).s_resgid = gid;
|
||||
break;
|
||||
case Opt_mode:
|
||||
name = match_strdup(&args[0]);
|
||||
|
@ -559,7 +574,7 @@ static int parse_options(struct super_block *sb, char *options)
|
|||
return -ENOMEM;
|
||||
if (strlen(name) == 8 &&
|
||||
!strncmp(name, "adaptive", 8)) {
|
||||
if (f2fs_sb_mounted_blkzoned(sb)) {
|
||||
if (f2fs_sb_has_blkzoned(sb)) {
|
||||
f2fs_msg(sb, KERN_WARNING,
|
||||
"adaptive mode is not allowed with "
|
||||
"zoned block device feature");
|
||||
|
@ -585,7 +600,7 @@ static int parse_options(struct super_block *sb, char *options)
|
|||
1 << arg, BIO_MAX_PAGES);
|
||||
return -EINVAL;
|
||||
}
|
||||
sbi->write_io_size_bits = arg;
|
||||
F2FS_OPTION(sbi).write_io_size_bits = arg;
|
||||
break;
|
||||
case Opt_fault_injection:
|
||||
if (args->from && match_int(args, &arg))
|
||||
|
@ -646,13 +661,13 @@ static int parse_options(struct super_block *sb, char *options)
|
|||
return ret;
|
||||
break;
|
||||
case Opt_jqfmt_vfsold:
|
||||
sbi->s_jquota_fmt = QFMT_VFS_OLD;
|
||||
F2FS_OPTION(sbi).s_jquota_fmt = QFMT_VFS_OLD;
|
||||
break;
|
||||
case Opt_jqfmt_vfsv0:
|
||||
sbi->s_jquota_fmt = QFMT_VFS_V0;
|
||||
F2FS_OPTION(sbi).s_jquota_fmt = QFMT_VFS_V0;
|
||||
break;
|
||||
case Opt_jqfmt_vfsv1:
|
||||
sbi->s_jquota_fmt = QFMT_VFS_V1;
|
||||
F2FS_OPTION(sbi).s_jquota_fmt = QFMT_VFS_V1;
|
||||
break;
|
||||
case Opt_noquota:
|
||||
clear_opt(sbi, QUOTA);
|
||||
|
@ -679,6 +694,73 @@ static int parse_options(struct super_block *sb, char *options)
|
|||
"quota operations not supported");
|
||||
break;
|
||||
#endif
|
||||
case Opt_whint:
|
||||
name = match_strdup(&args[0]);
|
||||
if (!name)
|
||||
return -ENOMEM;
|
||||
if (strlen(name) == 10 &&
|
||||
!strncmp(name, "user-based", 10)) {
|
||||
F2FS_OPTION(sbi).whint_mode = WHINT_MODE_USER;
|
||||
} else if (strlen(name) == 3 &&
|
||||
!strncmp(name, "off", 3)) {
|
||||
F2FS_OPTION(sbi).whint_mode = WHINT_MODE_OFF;
|
||||
} else if (strlen(name) == 8 &&
|
||||
!strncmp(name, "fs-based", 8)) {
|
||||
F2FS_OPTION(sbi).whint_mode = WHINT_MODE_FS;
|
||||
} else {
|
||||
kfree(name);
|
||||
return -EINVAL;
|
||||
}
|
||||
kfree(name);
|
||||
break;
|
||||
case Opt_alloc:
|
||||
name = match_strdup(&args[0]);
|
||||
if (!name)
|
||||
return -ENOMEM;
|
||||
|
||||
if (strlen(name) == 7 &&
|
||||
!strncmp(name, "default", 7)) {
|
||||
F2FS_OPTION(sbi).alloc_mode = ALLOC_MODE_DEFAULT;
|
||||
} else if (strlen(name) == 5 &&
|
||||
!strncmp(name, "reuse", 5)) {
|
||||
F2FS_OPTION(sbi).alloc_mode = ALLOC_MODE_REUSE;
|
||||
} else {
|
||||
kfree(name);
|
||||
return -EINVAL;
|
||||
}
|
||||
kfree(name);
|
||||
break;
|
||||
case Opt_fsync:
|
||||
name = match_strdup(&args[0]);
|
||||
if (!name)
|
||||
return -ENOMEM;
|
||||
if (strlen(name) == 5 &&
|
||||
!strncmp(name, "posix", 5)) {
|
||||
F2FS_OPTION(sbi).fsync_mode = FSYNC_MODE_POSIX;
|
||||
} else if (strlen(name) == 6 &&
|
||||
!strncmp(name, "strict", 6)) {
|
||||
F2FS_OPTION(sbi).fsync_mode = FSYNC_MODE_STRICT;
|
||||
} else {
|
||||
kfree(name);
|
||||
return -EINVAL;
|
||||
}
|
||||
kfree(name);
|
||||
break;
|
||||
case Opt_test_dummy_encryption:
|
||||
#ifdef CONFIG_F2FS_FS_ENCRYPTION
|
||||
if (!f2fs_sb_has_encrypt(sb)) {
|
||||
f2fs_msg(sb, KERN_ERR, "Encrypt feature is off");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
F2FS_OPTION(sbi).test_dummy_encryption = true;
|
||||
f2fs_msg(sb, KERN_INFO,
|
||||
"Test dummy encryption mode enabled");
|
||||
#else
|
||||
f2fs_msg(sb, KERN_INFO,
|
||||
"Test dummy encryption mount option ignored");
|
||||
#endif
|
||||
break;
|
||||
default:
|
||||
f2fs_msg(sb, KERN_ERR,
|
||||
"Unrecognized mount option \"%s\" or missing value",
|
||||
|
@ -699,14 +781,22 @@ static int parse_options(struct super_block *sb, char *options)
|
|||
}
|
||||
|
||||
if (test_opt(sbi, INLINE_XATTR_SIZE)) {
|
||||
if (!f2fs_sb_has_extra_attr(sb) ||
|
||||
!f2fs_sb_has_flexible_inline_xattr(sb)) {
|
||||
f2fs_msg(sb, KERN_ERR,
|
||||
"extra_attr or flexible_inline_xattr "
|
||||
"feature is off");
|
||||
return -EINVAL;
|
||||
}
|
||||
if (!test_opt(sbi, INLINE_XATTR)) {
|
||||
f2fs_msg(sb, KERN_ERR,
|
||||
"inline_xattr_size option should be "
|
||||
"set with inline_xattr option");
|
||||
return -EINVAL;
|
||||
}
|
||||
if (!sbi->inline_xattr_size ||
|
||||
sbi->inline_xattr_size >= DEF_ADDRS_PER_INODE -
|
||||
if (!F2FS_OPTION(sbi).inline_xattr_size ||
|
||||
F2FS_OPTION(sbi).inline_xattr_size >=
|
||||
DEF_ADDRS_PER_INODE -
|
||||
F2FS_TOTAL_EXTRA_ATTR_SIZE -
|
||||
DEF_INLINE_RESERVED_SIZE -
|
||||
DEF_MIN_INLINE_SIZE) {
|
||||
|
@ -715,6 +805,12 @@ static int parse_options(struct super_block *sb, char *options)
|
|||
return -EINVAL;
|
||||
}
|
||||
}
|
||||
|
||||
/* Not pass down write hints if the number of active logs is lesser
|
||||
* than NR_CURSEG_TYPE.
|
||||
*/
|
||||
if (F2FS_OPTION(sbi).active_logs != NR_CURSEG_TYPE)
|
||||
F2FS_OPTION(sbi).whint_mode = WHINT_MODE_OFF;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -731,7 +827,6 @@ static struct inode *f2fs_alloc_inode(struct super_block *sb)
|
|||
/* Initialize f2fs-specific inode info */
|
||||
atomic_set(&fi->dirty_pages, 0);
|
||||
fi->i_current_depth = 1;
|
||||
fi->i_advise = 0;
|
||||
init_rwsem(&fi->i_sem);
|
||||
INIT_LIST_HEAD(&fi->dirty_list);
|
||||
INIT_LIST_HEAD(&fi->gdirty_list);
|
||||
|
@ -743,10 +838,6 @@ static struct inode *f2fs_alloc_inode(struct super_block *sb)
|
|||
init_rwsem(&fi->i_mmap_sem);
|
||||
init_rwsem(&fi->i_xattr_sem);
|
||||
|
||||
#ifdef CONFIG_QUOTA
|
||||
memset(&fi->i_dquot, 0, sizeof(fi->i_dquot));
|
||||
fi->i_reserved_quota = 0;
|
||||
#endif
|
||||
/* Will be used by directory only */
|
||||
fi->i_dir_level = F2FS_SB(sb)->dir_level;
|
||||
|
||||
|
@ -957,7 +1048,7 @@ static void f2fs_put_super(struct super_block *sb)
|
|||
mempool_destroy(sbi->write_io_dummy);
|
||||
#ifdef CONFIG_QUOTA
|
||||
for (i = 0; i < MAXQUOTAS; i++)
|
||||
kfree(sbi->s_qf_names[i]);
|
||||
kfree(F2FS_OPTION(sbi).s_qf_names[i]);
|
||||
#endif
|
||||
destroy_percpu_info(sbi);
|
||||
for (i = 0; i < NR_PAGE_TYPE; i++)
|
||||
|
@ -1071,8 +1162,9 @@ static int f2fs_statfs(struct dentry *dentry, struct kstatfs *buf)
|
|||
buf->f_blocks = total_count - start_count;
|
||||
buf->f_bfree = user_block_count - valid_user_blocks(sbi) -
|
||||
sbi->current_reserved_blocks;
|
||||
if (buf->f_bfree > sbi->root_reserved_blocks)
|
||||
buf->f_bavail = buf->f_bfree - sbi->root_reserved_blocks;
|
||||
if (buf->f_bfree > F2FS_OPTION(sbi).root_reserved_blocks)
|
||||
buf->f_bavail = buf->f_bfree -
|
||||
F2FS_OPTION(sbi).root_reserved_blocks;
|
||||
else
|
||||
buf->f_bavail = 0;
|
||||
|
||||
|
@ -1107,10 +1199,10 @@ static inline void f2fs_show_quota_options(struct seq_file *seq,
|
|||
#ifdef CONFIG_QUOTA
|
||||
struct f2fs_sb_info *sbi = F2FS_SB(sb);
|
||||
|
||||
if (sbi->s_jquota_fmt) {
|
||||
if (F2FS_OPTION(sbi).s_jquota_fmt) {
|
||||
char *fmtname = "";
|
||||
|
||||
switch (sbi->s_jquota_fmt) {
|
||||
switch (F2FS_OPTION(sbi).s_jquota_fmt) {
|
||||
case QFMT_VFS_OLD:
|
||||
fmtname = "vfsold";
|
||||
break;
|
||||
|
@ -1124,14 +1216,17 @@ static inline void f2fs_show_quota_options(struct seq_file *seq,
|
|||
seq_printf(seq, ",jqfmt=%s", fmtname);
|
||||
}
|
||||
|
||||
if (sbi->s_qf_names[USRQUOTA])
|
||||
seq_show_option(seq, "usrjquota", sbi->s_qf_names[USRQUOTA]);
|
||||
if (F2FS_OPTION(sbi).s_qf_names[USRQUOTA])
|
||||
seq_show_option(seq, "usrjquota",
|
||||
F2FS_OPTION(sbi).s_qf_names[USRQUOTA]);
|
||||
|
||||
if (sbi->s_qf_names[GRPQUOTA])
|
||||
seq_show_option(seq, "grpjquota", sbi->s_qf_names[GRPQUOTA]);
|
||||
if (F2FS_OPTION(sbi).s_qf_names[GRPQUOTA])
|
||||
seq_show_option(seq, "grpjquota",
|
||||
F2FS_OPTION(sbi).s_qf_names[GRPQUOTA]);
|
||||
|
||||
if (sbi->s_qf_names[PRJQUOTA])
|
||||
seq_show_option(seq, "prjjquota", sbi->s_qf_names[PRJQUOTA]);
|
||||
if (F2FS_OPTION(sbi).s_qf_names[PRJQUOTA])
|
||||
seq_show_option(seq, "prjjquota",
|
||||
F2FS_OPTION(sbi).s_qf_names[PRJQUOTA]);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -1166,7 +1261,7 @@ static int f2fs_show_options(struct seq_file *seq, struct dentry *root)
|
|||
seq_puts(seq, ",noinline_xattr");
|
||||
if (test_opt(sbi, INLINE_XATTR_SIZE))
|
||||
seq_printf(seq, ",inline_xattr_size=%u",
|
||||
sbi->inline_xattr_size);
|
||||
F2FS_OPTION(sbi).inline_xattr_size);
|
||||
#endif
|
||||
#ifdef CONFIG_F2FS_FS_POSIX_ACL
|
||||
if (test_opt(sbi, POSIX_ACL))
|
||||
|
@ -1202,18 +1297,20 @@ static int f2fs_show_options(struct seq_file *seq, struct dentry *root)
|
|||
seq_puts(seq, "adaptive");
|
||||
else if (test_opt(sbi, LFS))
|
||||
seq_puts(seq, "lfs");
|
||||
seq_printf(seq, ",active_logs=%u", sbi->active_logs);
|
||||
seq_printf(seq, ",active_logs=%u", F2FS_OPTION(sbi).active_logs);
|
||||
if (test_opt(sbi, RESERVE_ROOT))
|
||||
seq_printf(seq, ",reserve_root=%u,resuid=%u,resgid=%u",
|
||||
sbi->root_reserved_blocks,
|
||||
from_kuid_munged(&init_user_ns, sbi->s_resuid),
|
||||
from_kgid_munged(&init_user_ns, sbi->s_resgid));
|
||||
F2FS_OPTION(sbi).root_reserved_blocks,
|
||||
from_kuid_munged(&init_user_ns,
|
||||
F2FS_OPTION(sbi).s_resuid),
|
||||
from_kgid_munged(&init_user_ns,
|
||||
F2FS_OPTION(sbi).s_resgid));
|
||||
if (F2FS_IO_SIZE_BITS(sbi))
|
||||
seq_printf(seq, ",io_size=%uKB", F2FS_IO_SIZE_KB(sbi));
|
||||
#ifdef CONFIG_F2FS_FAULT_INJECTION
|
||||
if (test_opt(sbi, FAULT_INJECTION))
|
||||
seq_printf(seq, ",fault_injection=%u",
|
||||
sbi->fault_info.inject_rate);
|
||||
F2FS_OPTION(sbi).fault_info.inject_rate);
|
||||
#endif
|
||||
#ifdef CONFIG_QUOTA
|
||||
if (test_opt(sbi, QUOTA))
|
||||
|
@ -1226,15 +1323,37 @@ static int f2fs_show_options(struct seq_file *seq, struct dentry *root)
|
|||
seq_puts(seq, ",prjquota");
|
||||
#endif
|
||||
f2fs_show_quota_options(seq, sbi->sb);
|
||||
if (F2FS_OPTION(sbi).whint_mode == WHINT_MODE_USER)
|
||||
seq_printf(seq, ",whint_mode=%s", "user-based");
|
||||
else if (F2FS_OPTION(sbi).whint_mode == WHINT_MODE_FS)
|
||||
seq_printf(seq, ",whint_mode=%s", "fs-based");
|
||||
#ifdef CONFIG_F2FS_FS_ENCRYPTION
|
||||
if (F2FS_OPTION(sbi).test_dummy_encryption)
|
||||
seq_puts(seq, ",test_dummy_encryption");
|
||||
#endif
|
||||
|
||||
if (F2FS_OPTION(sbi).alloc_mode == ALLOC_MODE_DEFAULT)
|
||||
seq_printf(seq, ",alloc_mode=%s", "default");
|
||||
else if (F2FS_OPTION(sbi).alloc_mode == ALLOC_MODE_REUSE)
|
||||
seq_printf(seq, ",alloc_mode=%s", "reuse");
|
||||
|
||||
if (F2FS_OPTION(sbi).fsync_mode == FSYNC_MODE_POSIX)
|
||||
seq_printf(seq, ",fsync_mode=%s", "posix");
|
||||
else if (F2FS_OPTION(sbi).fsync_mode == FSYNC_MODE_STRICT)
|
||||
seq_printf(seq, ",fsync_mode=%s", "strict");
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void default_options(struct f2fs_sb_info *sbi)
|
||||
{
|
||||
/* init some FS parameters */
|
||||
sbi->active_logs = NR_CURSEG_TYPE;
|
||||
sbi->inline_xattr_size = DEFAULT_INLINE_XATTR_ADDRS;
|
||||
F2FS_OPTION(sbi).active_logs = NR_CURSEG_TYPE;
|
||||
F2FS_OPTION(sbi).inline_xattr_size = DEFAULT_INLINE_XATTR_ADDRS;
|
||||
F2FS_OPTION(sbi).whint_mode = WHINT_MODE_OFF;
|
||||
F2FS_OPTION(sbi).alloc_mode = ALLOC_MODE_DEFAULT;
|
||||
F2FS_OPTION(sbi).fsync_mode = FSYNC_MODE_POSIX;
|
||||
F2FS_OPTION(sbi).test_dummy_encryption = false;
|
||||
sbi->readdir_ra = 1;
|
||||
|
||||
set_opt(sbi, BG_GC);
|
||||
set_opt(sbi, INLINE_XATTR);
|
||||
|
@ -1244,7 +1363,7 @@ static void default_options(struct f2fs_sb_info *sbi)
|
|||
set_opt(sbi, NOHEAP);
|
||||
sbi->sb->s_flags |= MS_LAZYTIME;
|
||||
set_opt(sbi, FLUSH_MERGE);
|
||||
if (f2fs_sb_mounted_blkzoned(sbi->sb)) {
|
||||
if (f2fs_sb_has_blkzoned(sbi->sb)) {
|
||||
set_opt_mode(sbi, F2FS_MOUNT_LFS);
|
||||
set_opt(sbi, DISCARD);
|
||||
} else {
|
||||
|
@ -1271,16 +1390,11 @@ static int f2fs_remount(struct super_block *sb, int *flags, char *data)
|
|||
struct f2fs_sb_info *sbi = F2FS_SB(sb);
|
||||
struct f2fs_mount_info org_mount_opt;
|
||||
unsigned long old_sb_flags;
|
||||
int err, active_logs;
|
||||
int err;
|
||||
bool need_restart_gc = false;
|
||||
bool need_stop_gc = false;
|
||||
bool no_extent_cache = !test_opt(sbi, EXTENT_CACHE);
|
||||
#ifdef CONFIG_F2FS_FAULT_INJECTION
|
||||
struct f2fs_fault_info ffi = sbi->fault_info;
|
||||
#endif
|
||||
#ifdef CONFIG_QUOTA
|
||||
int s_jquota_fmt;
|
||||
char *s_qf_names[MAXQUOTAS];
|
||||
int i, j;
|
||||
#endif
|
||||
|
||||
|
@ -1290,21 +1404,21 @@ static int f2fs_remount(struct super_block *sb, int *flags, char *data)
|
|||
*/
|
||||
org_mount_opt = sbi->mount_opt;
|
||||
old_sb_flags = sb->s_flags;
|
||||
active_logs = sbi->active_logs;
|
||||
|
||||
#ifdef CONFIG_QUOTA
|
||||
s_jquota_fmt = sbi->s_jquota_fmt;
|
||||
org_mount_opt.s_jquota_fmt = F2FS_OPTION(sbi).s_jquota_fmt;
|
||||
for (i = 0; i < MAXQUOTAS; i++) {
|
||||
if (sbi->s_qf_names[i]) {
|
||||
s_qf_names[i] = kstrdup(sbi->s_qf_names[i],
|
||||
GFP_KERNEL);
|
||||
if (!s_qf_names[i]) {
|
||||
if (F2FS_OPTION(sbi).s_qf_names[i]) {
|
||||
org_mount_opt.s_qf_names[i] =
|
||||
kstrdup(F2FS_OPTION(sbi).s_qf_names[i],
|
||||
GFP_KERNEL);
|
||||
if (!org_mount_opt.s_qf_names[i]) {
|
||||
for (j = 0; j < i; j++)
|
||||
kfree(s_qf_names[j]);
|
||||
kfree(org_mount_opt.s_qf_names[j]);
|
||||
return -ENOMEM;
|
||||
}
|
||||
} else {
|
||||
s_qf_names[i] = NULL;
|
||||
org_mount_opt.s_qf_names[i] = NULL;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
@ -1374,7 +1488,8 @@ static int f2fs_remount(struct super_block *sb, int *flags, char *data)
|
|||
need_stop_gc = true;
|
||||
}
|
||||
|
||||
if (*flags & MS_RDONLY) {
|
||||
if (*flags & MS_RDONLY ||
|
||||
F2FS_OPTION(sbi).whint_mode != org_mount_opt.whint_mode) {
|
||||
writeback_inodes_sb(sb, WB_REASON_SYNC);
|
||||
sync_inodes_sb(sb);
|
||||
|
||||
|
@ -1400,7 +1515,7 @@ skip:
|
|||
#ifdef CONFIG_QUOTA
|
||||
/* Release old quota file names */
|
||||
for (i = 0; i < MAXQUOTAS; i++)
|
||||
kfree(s_qf_names[i]);
|
||||
kfree(org_mount_opt.s_qf_names[i]);
|
||||
#endif
|
||||
/* Update the POSIXACL Flag */
|
||||
sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
|
||||
|
@ -1418,18 +1533,14 @@ restore_gc:
|
|||
}
|
||||
restore_opts:
|
||||
#ifdef CONFIG_QUOTA
|
||||
sbi->s_jquota_fmt = s_jquota_fmt;
|
||||
F2FS_OPTION(sbi).s_jquota_fmt = org_mount_opt.s_jquota_fmt;
|
||||
for (i = 0; i < MAXQUOTAS; i++) {
|
||||
kfree(sbi->s_qf_names[i]);
|
||||
sbi->s_qf_names[i] = s_qf_names[i];
|
||||
kfree(F2FS_OPTION(sbi).s_qf_names[i]);
|
||||
F2FS_OPTION(sbi).s_qf_names[i] = org_mount_opt.s_qf_names[i];
|
||||
}
|
||||
#endif
|
||||
sbi->mount_opt = org_mount_opt;
|
||||
sbi->active_logs = active_logs;
|
||||
sb->s_flags = old_sb_flags;
|
||||
#ifdef CONFIG_F2FS_FAULT_INJECTION
|
||||
sbi->fault_info = ffi;
|
||||
#endif
|
||||
return err;
|
||||
}
|
||||
|
||||
|
@ -1457,7 +1568,7 @@ static ssize_t f2fs_quota_read(struct super_block *sb, int type, char *data,
|
|||
while (toread > 0) {
|
||||
tocopy = min_t(unsigned long, sb->s_blocksize - offset, toread);
|
||||
repeat:
|
||||
page = read_mapping_page(mapping, blkidx, NULL);
|
||||
page = read_cache_page_gfp(mapping, blkidx, GFP_NOFS);
|
||||
if (IS_ERR(page)) {
|
||||
if (PTR_ERR(page) == -ENOMEM) {
|
||||
congestion_wait(BLK_RW_ASYNC, HZ/50);
|
||||
|
@ -1551,8 +1662,8 @@ static qsize_t *f2fs_get_reserved_space(struct inode *inode)
|
|||
|
||||
static int f2fs_quota_on_mount(struct f2fs_sb_info *sbi, int type)
|
||||
{
|
||||
return dquot_quota_on_mount(sbi->sb, sbi->s_qf_names[type],
|
||||
sbi->s_jquota_fmt, type);
|
||||
return dquot_quota_on_mount(sbi->sb, F2FS_OPTION(sbi).s_qf_names[type],
|
||||
F2FS_OPTION(sbi).s_jquota_fmt, type);
|
||||
}
|
||||
|
||||
int f2fs_enable_quota_files(struct f2fs_sb_info *sbi, bool rdonly)
|
||||
|
@ -1571,7 +1682,7 @@ int f2fs_enable_quota_files(struct f2fs_sb_info *sbi, bool rdonly)
|
|||
}
|
||||
|
||||
for (i = 0; i < MAXQUOTAS; i++) {
|
||||
if (sbi->s_qf_names[i]) {
|
||||
if (F2FS_OPTION(sbi).s_qf_names[i]) {
|
||||
err = f2fs_quota_on_mount(sbi, i);
|
||||
if (!err) {
|
||||
enabled = 1;
|
||||
|
@ -1801,11 +1912,28 @@ static int f2fs_get_context(struct inode *inode, void *ctx, size_t len)
|
|||
static int f2fs_set_context(struct inode *inode, const void *ctx, size_t len,
|
||||
void *fs_data)
|
||||
{
|
||||
struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
|
||||
|
||||
/*
|
||||
* Encrypting the root directory is not allowed because fsck
|
||||
* expects lost+found directory to exist and remain unencrypted
|
||||
* if LOST_FOUND feature is enabled.
|
||||
*
|
||||
*/
|
||||
if (f2fs_sb_has_lost_found(sbi->sb) &&
|
||||
inode->i_ino == F2FS_ROOT_INO(sbi))
|
||||
return -EPERM;
|
||||
|
||||
return f2fs_setxattr(inode, F2FS_XATTR_INDEX_ENCRYPTION,
|
||||
F2FS_XATTR_NAME_ENCRYPTION_CONTEXT,
|
||||
ctx, len, fs_data, XATTR_CREATE);
|
||||
}
|
||||
|
||||
static bool f2fs_dummy_context(struct inode *inode)
|
||||
{
|
||||
return DUMMY_ENCRYPTION_ENABLED(F2FS_I_SB(inode));
|
||||
}
|
||||
|
||||
static unsigned f2fs_max_namelen(struct inode *inode)
|
||||
{
|
||||
return S_ISLNK(inode->i_mode) ?
|
||||
|
@ -1816,6 +1944,7 @@ static const struct fscrypt_operations f2fs_cryptops = {
|
|||
.key_prefix = "f2fs:",
|
||||
.get_context = f2fs_get_context,
|
||||
.set_context = f2fs_set_context,
|
||||
.dummy_context = f2fs_dummy_context,
|
||||
.empty_dir = f2fs_empty_dir,
|
||||
.max_namelen = f2fs_max_namelen,
|
||||
};
|
||||
|
@ -1898,7 +2027,6 @@ static int __f2fs_commit_super(struct buffer_head *bh,
|
|||
lock_buffer(bh);
|
||||
if (super)
|
||||
memcpy(bh->b_data + F2FS_SUPER_OFFSET, super, sizeof(*super));
|
||||
set_buffer_uptodate(bh);
|
||||
set_buffer_dirty(bh);
|
||||
unlock_buffer(bh);
|
||||
|
||||
|
@ -2185,6 +2313,8 @@ static void init_sb_info(struct f2fs_sb_info *sbi)
|
|||
|
||||
sbi->dirty_device = 0;
|
||||
spin_lock_init(&sbi->dev_lock);
|
||||
|
||||
init_rwsem(&sbi->sb_lock);
|
||||
}
|
||||
|
||||
static int init_percpu_info(struct f2fs_sb_info *sbi)
|
||||
|
@ -2210,7 +2340,7 @@ static int init_blkz_info(struct f2fs_sb_info *sbi, int devi)
|
|||
unsigned int n = 0;
|
||||
int err = -EIO;
|
||||
|
||||
if (!f2fs_sb_mounted_blkzoned(sbi->sb))
|
||||
if (!f2fs_sb_has_blkzoned(sbi->sb))
|
||||
return 0;
|
||||
|
||||
if (sbi->blocks_per_blkz && sbi->blocks_per_blkz !=
|
||||
|
@ -2338,7 +2468,7 @@ int f2fs_commit_super(struct f2fs_sb_info *sbi, bool recover)
|
|||
}
|
||||
|
||||
/* write back-up superblock first */
|
||||
bh = sb_getblk(sbi->sb, sbi->valid_super_block ? 0: 1);
|
||||
bh = sb_bread(sbi->sb, sbi->valid_super_block ? 0 : 1);
|
||||
if (!bh)
|
||||
return -EIO;
|
||||
err = __f2fs_commit_super(bh, F2FS_RAW_SUPER(sbi));
|
||||
|
@ -2349,7 +2479,7 @@ int f2fs_commit_super(struct f2fs_sb_info *sbi, bool recover)
|
|||
return err;
|
||||
|
||||
/* write current valid superblock */
|
||||
bh = sb_getblk(sbi->sb, sbi->valid_super_block);
|
||||
bh = sb_bread(sbi->sb, sbi->valid_super_block);
|
||||
if (!bh)
|
||||
return -EIO;
|
||||
err = __f2fs_commit_super(bh, F2FS_RAW_SUPER(sbi));
|
||||
|
@ -2421,7 +2551,7 @@ static int f2fs_scan_devices(struct f2fs_sb_info *sbi)
|
|||
|
||||
#ifdef CONFIG_BLK_DEV_ZONED
|
||||
if (bdev_zoned_model(FDEV(i).bdev) == BLK_ZONED_HM &&
|
||||
!f2fs_sb_mounted_blkzoned(sbi->sb)) {
|
||||
!f2fs_sb_has_blkzoned(sbi->sb)) {
|
||||
f2fs_msg(sbi->sb, KERN_ERR,
|
||||
"Zoned block device feature not enabled\n");
|
||||
return -EINVAL;
|
||||
|
@ -2455,6 +2585,18 @@ static int f2fs_scan_devices(struct f2fs_sb_info *sbi)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static void f2fs_tuning_parameters(struct f2fs_sb_info *sbi)
|
||||
{
|
||||
struct f2fs_sm_info *sm_i = SM_I(sbi);
|
||||
|
||||
/* adjust parameters according to the volume size */
|
||||
if (sm_i->main_segments <= SMALL_VOLUME_SEGMENTS) {
|
||||
F2FS_OPTION(sbi).alloc_mode = ALLOC_MODE_REUSE;
|
||||
sm_i->dcc_info->discard_granularity = 1;
|
||||
sm_i->ipu_policy = 1 << F2FS_IPU_FORCE;
|
||||
}
|
||||
}
|
||||
|
||||
static int f2fs_fill_super(struct super_block *sb, void *data, int silent)
|
||||
{
|
||||
struct f2fs_sb_info *sbi;
|
||||
|
@ -2502,8 +2644,8 @@ try_onemore:
|
|||
sb->s_fs_info = sbi;
|
||||
sbi->raw_super = raw_super;
|
||||
|
||||
sbi->s_resuid = make_kuid(&init_user_ns, F2FS_DEF_RESUID);
|
||||
sbi->s_resgid = make_kgid(&init_user_ns, F2FS_DEF_RESGID);
|
||||
F2FS_OPTION(sbi).s_resuid = make_kuid(&init_user_ns, F2FS_DEF_RESUID);
|
||||
F2FS_OPTION(sbi).s_resgid = make_kgid(&init_user_ns, F2FS_DEF_RESGID);
|
||||
|
||||
/* precompute checksum seed for metadata */
|
||||
if (f2fs_sb_has_inode_chksum(sb))
|
||||
|
@ -2516,7 +2658,7 @@ try_onemore:
|
|||
* devices, but mandatory for host-managed zoned block devices.
|
||||
*/
|
||||
#ifndef CONFIG_BLK_DEV_ZONED
|
||||
if (f2fs_sb_mounted_blkzoned(sb)) {
|
||||
if (f2fs_sb_has_blkzoned(sb)) {
|
||||
f2fs_msg(sb, KERN_ERR,
|
||||
"Zoned block device support is not enabled\n");
|
||||
err = -EOPNOTSUPP;
|
||||
|
@ -2732,7 +2874,7 @@ try_onemore:
|
|||
* Turn on quotas which were not enabled for read-only mounts if
|
||||
* filesystem has quota feature, so that they are updated correctly.
|
||||
*/
|
||||
if (f2fs_sb_has_quota_ino(sb) && !sb_rdonly(sb)) {
|
||||
if (f2fs_sb_has_quota_ino(sb) && !f2fs_readonly(sb)) {
|
||||
err = f2fs_enable_quotas(sb);
|
||||
if (err) {
|
||||
f2fs_msg(sb, KERN_ERR,
|
||||
|
@ -2807,6 +2949,8 @@ skip_recovery:
|
|||
|
||||
f2fs_join_shrinker(sbi);
|
||||
|
||||
f2fs_tuning_parameters(sbi);
|
||||
|
||||
f2fs_msg(sbi->sb, KERN_NOTICE, "Mounted with checkpoint version = %llx",
|
||||
cur_cp_version(F2FS_CKPT(sbi)));
|
||||
f2fs_update_time(sbi, CP_TIME);
|
||||
|
@ -2815,7 +2959,7 @@ skip_recovery:
|
|||
|
||||
free_meta:
|
||||
#ifdef CONFIG_QUOTA
|
||||
if (f2fs_sb_has_quota_ino(sb) && !sb_rdonly(sb))
|
||||
if (f2fs_sb_has_quota_ino(sb) && !f2fs_readonly(sb))
|
||||
f2fs_quota_off_umount(sbi->sb);
|
||||
#endif
|
||||
f2fs_sync_inode_meta(sbi);
|
||||
|
@ -2859,7 +3003,7 @@ free_bio_info:
|
|||
free_options:
|
||||
#ifdef CONFIG_QUOTA
|
||||
for (i = 0; i < MAXQUOTAS; i++)
|
||||
kfree(sbi->s_qf_names[i]);
|
||||
kfree(F2FS_OPTION(sbi).s_qf_names[i]);
|
||||
#endif
|
||||
kfree(options);
|
||||
free_sb_buf:
|
||||
|
|
|
@ -58,7 +58,7 @@ static unsigned char *__struct_ptr(struct f2fs_sb_info *sbi, int struct_type)
|
|||
#ifdef CONFIG_F2FS_FAULT_INJECTION
|
||||
else if (struct_type == FAULT_INFO_RATE ||
|
||||
struct_type == FAULT_INFO_TYPE)
|
||||
return (unsigned char *)&sbi->fault_info;
|
||||
return (unsigned char *)&F2FS_OPTION(sbi).fault_info;
|
||||
#endif
|
||||
return NULL;
|
||||
}
|
||||
|
@ -92,10 +92,10 @@ static ssize_t features_show(struct f2fs_attr *a,
|
|||
if (!sb->s_bdev->bd_part)
|
||||
return snprintf(buf, PAGE_SIZE, "0\n");
|
||||
|
||||
if (f2fs_sb_has_crypto(sb))
|
||||
if (f2fs_sb_has_encrypt(sb))
|
||||
len += snprintf(buf, PAGE_SIZE - len, "%s",
|
||||
"encryption");
|
||||
if (f2fs_sb_mounted_blkzoned(sb))
|
||||
if (f2fs_sb_has_blkzoned(sb))
|
||||
len += snprintf(buf + len, PAGE_SIZE - len, "%s%s",
|
||||
len ? ", " : "", "blkzoned");
|
||||
if (f2fs_sb_has_extra_attr(sb))
|
||||
|
@ -116,6 +116,9 @@ static ssize_t features_show(struct f2fs_attr *a,
|
|||
if (f2fs_sb_has_inode_crtime(sb))
|
||||
len += snprintf(buf + len, PAGE_SIZE - len, "%s%s",
|
||||
len ? ", " : "", "inode_crtime");
|
||||
if (f2fs_sb_has_lost_found(sb))
|
||||
len += snprintf(buf + len, PAGE_SIZE - len, "%s%s",
|
||||
len ? ", " : "", "lost_found");
|
||||
len += snprintf(buf + len, PAGE_SIZE - len, "\n");
|
||||
return len;
|
||||
}
|
||||
|
@ -136,6 +139,27 @@ static ssize_t f2fs_sbi_show(struct f2fs_attr *a,
|
|||
if (!ptr)
|
||||
return -EINVAL;
|
||||
|
||||
if (!strcmp(a->attr.name, "extension_list")) {
|
||||
__u8 (*extlist)[F2FS_EXTENSION_LEN] =
|
||||
sbi->raw_super->extension_list;
|
||||
int cold_count = le32_to_cpu(sbi->raw_super->extension_count);
|
||||
int hot_count = sbi->raw_super->hot_ext_count;
|
||||
int len = 0, i;
|
||||
|
||||
len += snprintf(buf + len, PAGE_SIZE - len,
|
||||
"cold file extenstion:\n");
|
||||
for (i = 0; i < cold_count; i++)
|
||||
len += snprintf(buf + len, PAGE_SIZE - len, "%s\n",
|
||||
extlist[i]);
|
||||
|
||||
len += snprintf(buf + len, PAGE_SIZE - len,
|
||||
"hot file extenstion:\n");
|
||||
for (i = cold_count; i < cold_count + hot_count; i++)
|
||||
len += snprintf(buf + len, PAGE_SIZE - len, "%s\n",
|
||||
extlist[i]);
|
||||
return len;
|
||||
}
|
||||
|
||||
ui = (unsigned int *)(ptr + a->offset);
|
||||
|
||||
return snprintf(buf, PAGE_SIZE, "%u\n", *ui);
|
||||
|
@ -154,6 +178,41 @@ static ssize_t f2fs_sbi_store(struct f2fs_attr *a,
|
|||
if (!ptr)
|
||||
return -EINVAL;
|
||||
|
||||
if (!strcmp(a->attr.name, "extension_list")) {
|
||||
const char *name = strim((char *)buf);
|
||||
bool set = true, hot;
|
||||
|
||||
if (!strncmp(name, "[h]", 3))
|
||||
hot = true;
|
||||
else if (!strncmp(name, "[c]", 3))
|
||||
hot = false;
|
||||
else
|
||||
return -EINVAL;
|
||||
|
||||
name += 3;
|
||||
|
||||
if (*name == '!') {
|
||||
name++;
|
||||
set = false;
|
||||
}
|
||||
|
||||
if (strlen(name) >= F2FS_EXTENSION_LEN)
|
||||
return -EINVAL;
|
||||
|
||||
down_write(&sbi->sb_lock);
|
||||
|
||||
ret = update_extension_list(sbi, name, hot, set);
|
||||
if (ret)
|
||||
goto out;
|
||||
|
||||
ret = f2fs_commit_super(sbi, false);
|
||||
if (ret)
|
||||
update_extension_list(sbi, name, hot, !set);
|
||||
out:
|
||||
up_write(&sbi->sb_lock);
|
||||
return ret ? ret : count;
|
||||
}
|
||||
|
||||
ui = (unsigned int *)(ptr + a->offset);
|
||||
|
||||
ret = kstrtoul(skip_spaces(buf), 0, &t);
|
||||
|
@ -166,7 +225,7 @@ static ssize_t f2fs_sbi_store(struct f2fs_attr *a,
|
|||
if (a->struct_type == RESERVED_BLOCKS) {
|
||||
spin_lock(&sbi->stat_lock);
|
||||
if (t > (unsigned long)(sbi->user_block_count -
|
||||
sbi->root_reserved_blocks)) {
|
||||
F2FS_OPTION(sbi).root_reserved_blocks)) {
|
||||
spin_unlock(&sbi->stat_lock);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
@ -236,6 +295,7 @@ enum feat_id {
|
|||
FEAT_FLEXIBLE_INLINE_XATTR,
|
||||
FEAT_QUOTA_INO,
|
||||
FEAT_INODE_CRTIME,
|
||||
FEAT_LOST_FOUND,
|
||||
};
|
||||
|
||||
static ssize_t f2fs_feature_show(struct f2fs_attr *a,
|
||||
|
@ -251,6 +311,7 @@ static ssize_t f2fs_feature_show(struct f2fs_attr *a,
|
|||
case FEAT_FLEXIBLE_INLINE_XATTR:
|
||||
case FEAT_QUOTA_INO:
|
||||
case FEAT_INODE_CRTIME:
|
||||
case FEAT_LOST_FOUND:
|
||||
return snprintf(buf, PAGE_SIZE, "supported\n");
|
||||
}
|
||||
return 0;
|
||||
|
@ -307,6 +368,7 @@ F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, idle_interval, interval_time[REQ_TIME]);
|
|||
F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, iostat_enable, iostat_enable);
|
||||
F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, readdir_ra, readdir_ra);
|
||||
F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, gc_pin_file_thresh, gc_pin_file_threshold);
|
||||
F2FS_RW_ATTR(F2FS_SBI, f2fs_super_block, extension_list, extension_list);
|
||||
#ifdef CONFIG_F2FS_FAULT_INJECTION
|
||||
F2FS_RW_ATTR(FAULT_INFO_RATE, f2fs_fault_info, inject_rate, inject_rate);
|
||||
F2FS_RW_ATTR(FAULT_INFO_TYPE, f2fs_fault_info, inject_type, inject_type);
|
||||
|
@ -329,6 +391,7 @@ F2FS_FEATURE_RO_ATTR(inode_checksum, FEAT_INODE_CHECKSUM);
|
|||
F2FS_FEATURE_RO_ATTR(flexible_inline_xattr, FEAT_FLEXIBLE_INLINE_XATTR);
|
||||
F2FS_FEATURE_RO_ATTR(quota_ino, FEAT_QUOTA_INO);
|
||||
F2FS_FEATURE_RO_ATTR(inode_crtime, FEAT_INODE_CRTIME);
|
||||
F2FS_FEATURE_RO_ATTR(lost_found, FEAT_LOST_FOUND);
|
||||
|
||||
#define ATTR_LIST(name) (&f2fs_attr_##name.attr)
|
||||
static struct attribute *f2fs_attrs[] = {
|
||||
|
@ -357,6 +420,7 @@ static struct attribute *f2fs_attrs[] = {
|
|||
ATTR_LIST(iostat_enable),
|
||||
ATTR_LIST(readdir_ra),
|
||||
ATTR_LIST(gc_pin_file_thresh),
|
||||
ATTR_LIST(extension_list),
|
||||
#ifdef CONFIG_F2FS_FAULT_INJECTION
|
||||
ATTR_LIST(inject_rate),
|
||||
ATTR_LIST(inject_type),
|
||||
|
@ -383,6 +447,7 @@ static struct attribute *f2fs_feat_attrs[] = {
|
|||
ATTR_LIST(flexible_inline_xattr),
|
||||
ATTR_LIST(quota_ino),
|
||||
ATTR_LIST(inode_crtime),
|
||||
ATTR_LIST(lost_found),
|
||||
NULL,
|
||||
};
|
||||
|
||||
|
|
|
@ -47,6 +47,7 @@ struct bio {
|
|||
struct bio *bi_next; /* request queue link */
|
||||
struct block_device *bi_bdev;
|
||||
unsigned int bi_flags; /* status, command, etc */
|
||||
unsigned short bi_write_hint;
|
||||
int bi_error;
|
||||
unsigned long bi_rw; /* bottom bits READ/WRITE,
|
||||
* top bits priority
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#define F2FS_BLKSIZE 4096 /* support only 4KB block */
|
||||
#define F2FS_BLKSIZE_BITS 12 /* bits for F2FS_BLKSIZE */
|
||||
#define F2FS_MAX_EXTENSION 64 /* # of extension entries */
|
||||
#define F2FS_EXTENSION_LEN 8 /* max size of extension */
|
||||
#define F2FS_BLK_ALIGN(x) (((x) + F2FS_BLKSIZE - 1) >> F2FS_BLKSIZE_BITS)
|
||||
|
||||
#define NULL_ADDR ((block_t)0) /* used as block_t addresses */
|
||||
|
@ -38,10 +39,10 @@
|
|||
|
||||
#define F2FS_MAX_QUOTAS 3
|
||||
|
||||
#define F2FS_IO_SIZE(sbi) (1 << (sbi)->write_io_size_bits) /* Blocks */
|
||||
#define F2FS_IO_SIZE_KB(sbi) (1 << ((sbi)->write_io_size_bits + 2)) /* KB */
|
||||
#define F2FS_IO_SIZE_BYTES(sbi) (1 << ((sbi)->write_io_size_bits + 12)) /* B */
|
||||
#define F2FS_IO_SIZE_BITS(sbi) ((sbi)->write_io_size_bits) /* power of 2 */
|
||||
#define F2FS_IO_SIZE(sbi) (1 << F2FS_OPTION(sbi).write_io_size_bits) /* Blocks */
|
||||
#define F2FS_IO_SIZE_KB(sbi) (1 << (F2FS_OPTION(sbi).write_io_size_bits + 2)) /* KB */
|
||||
#define F2FS_IO_SIZE_BYTES(sbi) (1 << (F2FS_OPTION(sbi).write_io_size_bits + 12)) /* B */
|
||||
#define F2FS_IO_SIZE_BITS(sbi) (F2FS_OPTION(sbi).write_io_size_bits) /* power of 2 */
|
||||
#define F2FS_IO_SIZE_MASK(sbi) (F2FS_IO_SIZE(sbi) - 1)
|
||||
|
||||
/* This flag is used by node and meta inodes, and by recovery */
|
||||
|
@ -101,7 +102,7 @@ struct f2fs_super_block {
|
|||
__u8 uuid[16]; /* 128-bit uuid for volume */
|
||||
__le16 volume_name[MAX_VOLUME_NAME]; /* volume name */
|
||||
__le32 extension_count; /* # of extensions below */
|
||||
__u8 extension_list[F2FS_MAX_EXTENSION][8]; /* extension array */
|
||||
__u8 extension_list[F2FS_MAX_EXTENSION][F2FS_EXTENSION_LEN];/* extension array */
|
||||
__le32 cp_payload;
|
||||
__u8 version[VERSION_LEN]; /* the kernel version */
|
||||
__u8 init_version[VERSION_LEN]; /* the initial kernel version */
|
||||
|
@ -110,12 +111,14 @@ struct f2fs_super_block {
|
|||
__u8 encrypt_pw_salt[16]; /* Salt used for string2key algorithm */
|
||||
struct f2fs_device devs[MAX_DEVICES]; /* device list */
|
||||
__le32 qf_ino[F2FS_MAX_QUOTAS]; /* quota inode numbers */
|
||||
__u8 reserved[315]; /* valid reserved region */
|
||||
__u8 hot_ext_count; /* # of hot file extension */
|
||||
__u8 reserved[314]; /* valid reserved region */
|
||||
} __packed;
|
||||
|
||||
/*
|
||||
* For checkpoint
|
||||
*/
|
||||
#define CP_LARGE_NAT_BITMAP_FLAG 0x00000400
|
||||
#define CP_NOCRC_RECOVERY_FLAG 0x00000200
|
||||
#define CP_TRIMMED_FLAG 0x00000100
|
||||
#define CP_NAT_BITS_FLAG 0x00000080
|
||||
|
@ -302,6 +305,10 @@ struct f2fs_node {
|
|||
*/
|
||||
#define NAT_ENTRY_PER_BLOCK (PAGE_SIZE / sizeof(struct f2fs_nat_entry))
|
||||
#define NAT_ENTRY_BITMAP_SIZE ((NAT_ENTRY_PER_BLOCK + 7) / 8)
|
||||
#define NAT_ENTRY_BITMAP_SIZE_ALIGNED \
|
||||
((NAT_ENTRY_BITMAP_SIZE + BITS_PER_LONG - 1) / \
|
||||
BITS_PER_LONG * BITS_PER_LONG)
|
||||
|
||||
|
||||
struct f2fs_nat_entry {
|
||||
__u8 version; /* latest version of cached nat entry */
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#include <linux/rwsem.h>
|
||||
#include <linux/capability.h>
|
||||
#include <linux/semaphore.h>
|
||||
#include <linux/fcntl.h>
|
||||
#include <linux/fiemap.h>
|
||||
#include <linux/rculist_bl.h>
|
||||
#include <linux/atomic.h>
|
||||
|
@ -143,6 +144,9 @@ typedef void (dax_iodone_t)(struct buffer_head *bh_map, int uptodate);
|
|||
/* File was opened by fanotify and shouldn't generate fanotify events */
|
||||
#define FMODE_NONOTIFY ((__force fmode_t)0x4000000)
|
||||
|
||||
/* File is capable of returning -EAGAIN if I/O will block */
|
||||
#define FMODE_NOWAIT ((__force fmode_t)0x8000000)
|
||||
|
||||
/*
|
||||
* Flag for rw_copy_check_uvector and compat_rw_copy_check_uvector
|
||||
* that indicates that they should check the contents of the iovec are
|
||||
|
@ -319,9 +323,22 @@ struct page;
|
|||
struct address_space;
|
||||
struct writeback_control;
|
||||
|
||||
/*
|
||||
* Write life time hint values.
|
||||
*/
|
||||
enum rw_hint {
|
||||
WRITE_LIFE_NOT_SET = 0,
|
||||
WRITE_LIFE_NONE = RWH_WRITE_LIFE_NONE,
|
||||
WRITE_LIFE_SHORT = RWH_WRITE_LIFE_SHORT,
|
||||
WRITE_LIFE_MEDIUM = RWH_WRITE_LIFE_MEDIUM,
|
||||
WRITE_LIFE_LONG = RWH_WRITE_LIFE_LONG,
|
||||
WRITE_LIFE_EXTREME = RWH_WRITE_LIFE_EXTREME,
|
||||
};
|
||||
|
||||
#define IOCB_EVENTFD (1 << 0)
|
||||
#define IOCB_APPEND (1 << 1)
|
||||
#define IOCB_DIRECT (1 << 2)
|
||||
#define IOCB_NOWAIT (1 << 7)
|
||||
|
||||
struct kiocb {
|
||||
struct file *ki_filp;
|
||||
|
@ -329,6 +346,7 @@ struct kiocb {
|
|||
void (*ki_complete)(struct kiocb *iocb, long ret, long ret2);
|
||||
void *private;
|
||||
int ki_flags;
|
||||
enum rw_hint ki_hint;
|
||||
};
|
||||
|
||||
static inline bool is_sync_kiocb(struct kiocb *kiocb)
|
||||
|
@ -625,6 +643,7 @@ struct inode {
|
|||
spinlock_t i_lock; /* i_blocks, i_bytes, maybe i_size */
|
||||
unsigned short i_bytes;
|
||||
unsigned int i_blkbits;
|
||||
enum rw_hint i_write_hint;
|
||||
blkcnt_t i_blocks;
|
||||
|
||||
#ifdef __NEED_I_SIZE_ORDERED
|
||||
|
@ -1059,8 +1078,6 @@ struct file_lock_context {
|
|||
#define OFFT_OFFSET_MAX INT_LIMIT(off_t)
|
||||
#endif
|
||||
|
||||
#include <linux/fcntl.h>
|
||||
|
||||
extern void send_sigio(struct fown_struct *fown, int fd, int band);
|
||||
|
||||
#ifdef CONFIG_FILE_LOCKING
|
||||
|
|
|
@ -13,42 +13,13 @@
|
|||
#ifndef _LINUX_FSCRYPT_H
|
||||
#define _LINUX_FSCRYPT_H
|
||||
|
||||
#include <linux/key.h>
|
||||
#include <linux/fs.h>
|
||||
#include <linux/mm.h>
|
||||
#include <linux/bio.h>
|
||||
#include <linux/dcache.h>
|
||||
#include <crypto/skcipher.h>
|
||||
#include <uapi/linux/fs.h>
|
||||
|
||||
#define FS_CRYPTO_BLOCK_SIZE 16
|
||||
|
||||
struct fscrypt_ctx;
|
||||
struct fscrypt_info;
|
||||
|
||||
struct fscrypt_ctx {
|
||||
union {
|
||||
struct {
|
||||
struct page *bounce_page; /* Ciphertext page */
|
||||
struct page *control_page; /* Original page */
|
||||
} w;
|
||||
struct {
|
||||
struct bio *bio;
|
||||
struct work_struct work;
|
||||
} r;
|
||||
struct list_head free_list; /* Free list */
|
||||
};
|
||||
u8 flags; /* Flags */
|
||||
};
|
||||
|
||||
/**
|
||||
* For encrypted symlinks, the ciphertext length is stored at the beginning
|
||||
* of the string in little-endian format.
|
||||
*/
|
||||
struct fscrypt_symlink_data {
|
||||
__le16 len;
|
||||
char encrypted_path[1];
|
||||
} __packed;
|
||||
|
||||
struct fscrypt_str {
|
||||
unsigned char *name;
|
||||
u32 len;
|
||||
|
@ -67,86 +38,11 @@ struct fscrypt_name {
|
|||
#define fname_name(p) ((p)->disk_name.name)
|
||||
#define fname_len(p) ((p)->disk_name.len)
|
||||
|
||||
/*
|
||||
* fscrypt superblock flags
|
||||
*/
|
||||
#define FS_CFLG_OWN_PAGES (1U << 1)
|
||||
|
||||
/*
|
||||
* crypto opertions for filesystems
|
||||
*/
|
||||
struct fscrypt_operations {
|
||||
unsigned int flags;
|
||||
const char *key_prefix;
|
||||
int (*get_context)(struct inode *, void *, size_t);
|
||||
int (*set_context)(struct inode *, const void *, size_t, void *);
|
||||
bool (*dummy_context)(struct inode *);
|
||||
bool (*empty_dir)(struct inode *);
|
||||
unsigned (*max_namelen)(struct inode *);
|
||||
};
|
||||
|
||||
static inline bool fscrypt_dummy_context_enabled(struct inode *inode)
|
||||
{
|
||||
if (inode->i_sb->s_cop->dummy_context &&
|
||||
inode->i_sb->s_cop->dummy_context(inode))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
static inline bool fscrypt_valid_enc_modes(u32 contents_mode,
|
||||
u32 filenames_mode)
|
||||
{
|
||||
if (contents_mode == FS_ENCRYPTION_MODE_AES_128_CBC &&
|
||||
filenames_mode == FS_ENCRYPTION_MODE_AES_128_CTS)
|
||||
return true;
|
||||
|
||||
if (contents_mode == FS_ENCRYPTION_MODE_AES_256_XTS &&
|
||||
filenames_mode == FS_ENCRYPTION_MODE_AES_256_CTS)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static inline bool fscrypt_is_dot_dotdot(const struct qstr *str)
|
||||
{
|
||||
if (str->len == 1 && str->name[0] == '.')
|
||||
return true;
|
||||
|
||||
if (str->len == 2 && str->name[0] == '.' && str->name[1] == '.')
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
#if __FS_HAS_ENCRYPTION
|
||||
|
||||
static inline struct page *fscrypt_control_page(struct page *page)
|
||||
{
|
||||
return ((struct fscrypt_ctx *)page_private(page))->w.control_page;
|
||||
}
|
||||
|
||||
static inline bool fscrypt_has_encryption_key(const struct inode *inode)
|
||||
{
|
||||
return (inode->i_crypt_info != NULL);
|
||||
}
|
||||
|
||||
#include <linux/fscrypt_supp.h>
|
||||
|
||||
#else /* !__FS_HAS_ENCRYPTION */
|
||||
|
||||
static inline struct page *fscrypt_control_page(struct page *page)
|
||||
{
|
||||
WARN_ON_ONCE(1);
|
||||
return ERR_PTR(-EINVAL);
|
||||
}
|
||||
|
||||
static inline bool fscrypt_has_encryption_key(const struct inode *inode)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
#else
|
||||
#include <linux/fscrypt_notsupp.h>
|
||||
#endif /* __FS_HAS_ENCRYPTION */
|
||||
#endif
|
||||
|
||||
/**
|
||||
* fscrypt_require_key - require an inode's encryption key
|
||||
|
@ -287,4 +183,68 @@ static inline int fscrypt_prepare_setattr(struct dentry *dentry,
|
|||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* fscrypt_prepare_symlink - prepare to create a possibly-encrypted symlink
|
||||
* @dir: directory in which the symlink is being created
|
||||
* @target: plaintext symlink target
|
||||
* @len: length of @target excluding null terminator
|
||||
* @max_len: space the filesystem has available to store the symlink target
|
||||
* @disk_link: (out) the on-disk symlink target being prepared
|
||||
*
|
||||
* This function computes the size the symlink target will require on-disk,
|
||||
* stores it in @disk_link->len, and validates it against @max_len. An
|
||||
* encrypted symlink may be longer than the original.
|
||||
*
|
||||
* Additionally, @disk_link->name is set to @target if the symlink will be
|
||||
* unencrypted, but left NULL if the symlink will be encrypted. For encrypted
|
||||
* symlinks, the filesystem must call fscrypt_encrypt_symlink() to create the
|
||||
* on-disk target later. (The reason for the two-step process is that some
|
||||
* filesystems need to know the size of the symlink target before creating the
|
||||
* inode, e.g. to determine whether it will be a "fast" or "slow" symlink.)
|
||||
*
|
||||
* Return: 0 on success, -ENAMETOOLONG if the symlink target is too long,
|
||||
* -ENOKEY if the encryption key is missing, or another -errno code if a problem
|
||||
* occurred while setting up the encryption key.
|
||||
*/
|
||||
static inline int fscrypt_prepare_symlink(struct inode *dir,
|
||||
const char *target,
|
||||
unsigned int len,
|
||||
unsigned int max_len,
|
||||
struct fscrypt_str *disk_link)
|
||||
{
|
||||
if (IS_ENCRYPTED(dir) || fscrypt_dummy_context_enabled(dir))
|
||||
return __fscrypt_prepare_symlink(dir, len, max_len, disk_link);
|
||||
|
||||
disk_link->name = (unsigned char *)target;
|
||||
disk_link->len = len + 1;
|
||||
if (disk_link->len > max_len)
|
||||
return -ENAMETOOLONG;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* fscrypt_encrypt_symlink - encrypt the symlink target if needed
|
||||
* @inode: symlink inode
|
||||
* @target: plaintext symlink target
|
||||
* @len: length of @target excluding null terminator
|
||||
* @disk_link: (in/out) the on-disk symlink target being prepared
|
||||
*
|
||||
* If the symlink target needs to be encrypted, then this function encrypts it
|
||||
* into @disk_link->name. fscrypt_prepare_symlink() must have been called
|
||||
* previously to compute @disk_link->len. If the filesystem did not allocate a
|
||||
* buffer for @disk_link->name after calling fscrypt_prepare_link(), then one
|
||||
* will be kmalloc()'ed and the filesystem will be responsible for freeing it.
|
||||
*
|
||||
* Return: 0 on success, -errno on failure
|
||||
*/
|
||||
static inline int fscrypt_encrypt_symlink(struct inode *inode,
|
||||
const char *target,
|
||||
unsigned int len,
|
||||
struct fscrypt_str *disk_link)
|
||||
{
|
||||
if (IS_ENCRYPTED(inode))
|
||||
return __fscrypt_encrypt_symlink(inode, target, len, disk_link);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif /* _LINUX_FSCRYPT_H */
|
||||
|
|
|
@ -13,6 +13,16 @@
|
|||
#ifndef _LINUX_FSCRYPT_NOTSUPP_H
|
||||
#define _LINUX_FSCRYPT_NOTSUPP_H
|
||||
|
||||
static inline bool fscrypt_has_encryption_key(const struct inode *inode)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
static inline bool fscrypt_dummy_context_enabled(struct inode *inode)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/* crypto.c */
|
||||
static inline struct fscrypt_ctx *fscrypt_get_ctx(const struct inode *inode,
|
||||
gfp_t gfp_flags)
|
||||
|
@ -42,6 +52,11 @@ static inline int fscrypt_decrypt_page(const struct inode *inode,
|
|||
return -EOPNOTSUPP;
|
||||
}
|
||||
|
||||
static inline struct page *fscrypt_control_page(struct page *page)
|
||||
{
|
||||
WARN_ON_ONCE(1);
|
||||
return ERR_PTR(-EINVAL);
|
||||
}
|
||||
|
||||
static inline void fscrypt_restore_control_page(struct page *page)
|
||||
{
|
||||
|
@ -115,16 +130,8 @@ static inline void fscrypt_free_filename(struct fscrypt_name *fname)
|
|||
return;
|
||||
}
|
||||
|
||||
static inline u32 fscrypt_fname_encrypted_size(const struct inode *inode,
|
||||
u32 ilen)
|
||||
{
|
||||
/* never happens */
|
||||
WARN_ON(1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline int fscrypt_fname_alloc_buffer(const struct inode *inode,
|
||||
u32 ilen,
|
||||
u32 max_encrypted_len,
|
||||
struct fscrypt_str *crypto_str)
|
||||
{
|
||||
return -EOPNOTSUPP;
|
||||
|
@ -143,13 +150,6 @@ static inline int fscrypt_fname_disk_to_usr(struct inode *inode,
|
|||
return -EOPNOTSUPP;
|
||||
}
|
||||
|
||||
static inline int fscrypt_fname_usr_to_disk(struct inode *inode,
|
||||
const struct qstr *iname,
|
||||
struct fscrypt_str *oname)
|
||||
{
|
||||
return -EOPNOTSUPP;
|
||||
}
|
||||
|
||||
static inline bool fscrypt_match_name(const struct fscrypt_name *fname,
|
||||
const u8 *de_name, u32 de_name_len)
|
||||
{
|
||||
|
@ -207,4 +207,27 @@ static inline int __fscrypt_prepare_lookup(struct inode *dir,
|
|||
return -EOPNOTSUPP;
|
||||
}
|
||||
|
||||
static inline int __fscrypt_prepare_symlink(struct inode *dir,
|
||||
unsigned int len,
|
||||
unsigned int max_len,
|
||||
struct fscrypt_str *disk_link)
|
||||
{
|
||||
return -EOPNOTSUPP;
|
||||
}
|
||||
|
||||
static inline int __fscrypt_encrypt_symlink(struct inode *inode,
|
||||
const char *target,
|
||||
unsigned int len,
|
||||
struct fscrypt_str *disk_link)
|
||||
{
|
||||
return -EOPNOTSUPP;
|
||||
}
|
||||
|
||||
static inline void *fscrypt_get_symlink(struct inode *inode,
|
||||
const void *caddr,
|
||||
unsigned int max_size)
|
||||
{
|
||||
return ERR_PTR(-EOPNOTSUPP);
|
||||
}
|
||||
|
||||
#endif /* _LINUX_FSCRYPT_NOTSUPP_H */
|
||||
|
|
|
@ -10,8 +10,54 @@
|
|||
#ifndef _LINUX_FSCRYPT_SUPP_H
|
||||
#define _LINUX_FSCRYPT_SUPP_H
|
||||
|
||||
#include <linux/mm.h>
|
||||
#include <linux/slab.h>
|
||||
|
||||
/*
|
||||
* fscrypt superblock flags
|
||||
*/
|
||||
#define FS_CFLG_OWN_PAGES (1U << 1)
|
||||
|
||||
/*
|
||||
* crypto operations for filesystems
|
||||
*/
|
||||
struct fscrypt_operations {
|
||||
unsigned int flags;
|
||||
const char *key_prefix;
|
||||
int (*get_context)(struct inode *, void *, size_t);
|
||||
int (*set_context)(struct inode *, const void *, size_t, void *);
|
||||
bool (*dummy_context)(struct inode *);
|
||||
bool (*empty_dir)(struct inode *);
|
||||
unsigned (*max_namelen)(struct inode *);
|
||||
};
|
||||
|
||||
struct fscrypt_ctx {
|
||||
union {
|
||||
struct {
|
||||
struct page *bounce_page; /* Ciphertext page */
|
||||
struct page *control_page; /* Original page */
|
||||
} w;
|
||||
struct {
|
||||
struct bio *bio;
|
||||
struct work_struct work;
|
||||
} r;
|
||||
struct list_head free_list; /* Free list */
|
||||
};
|
||||
u8 flags; /* Flags */
|
||||
};
|
||||
|
||||
static inline bool fscrypt_has_encryption_key(const struct inode *inode)
|
||||
{
|
||||
return (inode->i_crypt_info != NULL);
|
||||
}
|
||||
|
||||
static inline bool fscrypt_dummy_context_enabled(struct inode *inode)
|
||||
{
|
||||
return inode->i_sb->s_cop->dummy_context &&
|
||||
inode->i_sb->s_cop->dummy_context(inode);
|
||||
}
|
||||
|
||||
/* crypto.c */
|
||||
extern struct kmem_cache *fscrypt_info_cachep;
|
||||
extern struct fscrypt_ctx *fscrypt_get_ctx(const struct inode *, gfp_t);
|
||||
extern void fscrypt_release_ctx(struct fscrypt_ctx *);
|
||||
extern struct page *fscrypt_encrypt_page(const struct inode *, struct page *,
|
||||
|
@ -19,6 +65,12 @@ extern struct page *fscrypt_encrypt_page(const struct inode *, struct page *,
|
|||
u64, gfp_t);
|
||||
extern int fscrypt_decrypt_page(const struct inode *, struct page *, unsigned int,
|
||||
unsigned int, u64);
|
||||
|
||||
static inline struct page *fscrypt_control_page(struct page *page)
|
||||
{
|
||||
return ((struct fscrypt_ctx *)page_private(page))->w.control_page;
|
||||
}
|
||||
|
||||
extern void fscrypt_restore_control_page(struct page *);
|
||||
|
||||
extern const struct dentry_operations fscrypt_d_ops;
|
||||
|
@ -54,14 +106,11 @@ static inline void fscrypt_free_filename(struct fscrypt_name *fname)
|
|||
kfree(fname->crypto_buf.name);
|
||||
}
|
||||
|
||||
extern u32 fscrypt_fname_encrypted_size(const struct inode *, u32);
|
||||
extern int fscrypt_fname_alloc_buffer(const struct inode *, u32,
|
||||
struct fscrypt_str *);
|
||||
extern void fscrypt_fname_free_buffer(struct fscrypt_str *);
|
||||
extern int fscrypt_fname_disk_to_usr(struct inode *, u32, u32,
|
||||
const struct fscrypt_str *, struct fscrypt_str *);
|
||||
extern int fscrypt_fname_usr_to_disk(struct inode *, const struct qstr *,
|
||||
struct fscrypt_str *);
|
||||
|
||||
#define FSCRYPT_FNAME_MAX_UNDIGESTED_SIZE 32
|
||||
|
||||
|
@ -152,5 +201,13 @@ extern int __fscrypt_prepare_rename(struct inode *old_dir,
|
|||
struct dentry *new_dentry,
|
||||
unsigned int flags);
|
||||
extern int __fscrypt_prepare_lookup(struct inode *dir, struct dentry *dentry);
|
||||
extern int __fscrypt_prepare_symlink(struct inode *dir, unsigned int len,
|
||||
unsigned int max_len,
|
||||
struct fscrypt_str *disk_link);
|
||||
extern int __fscrypt_encrypt_symlink(struct inode *inode, const char *target,
|
||||
unsigned int len,
|
||||
struct fscrypt_str *disk_link);
|
||||
extern void *fscrypt_get_symlink(struct inode *inode, const void *caddr,
|
||||
unsigned int max_size);
|
||||
|
||||
#endif /* _LINUX_FSCRYPT_SUPP_H */
|
||||
|
|
|
@ -42,6 +42,27 @@
|
|||
#define F_SEAL_WRITE 0x0008 /* prevent writes */
|
||||
/* (1U << 31) is reserved for signed error codes */
|
||||
|
||||
/*
|
||||
* Set/Get write life time hints. {GET,SET}_RW_HINT operate on the
|
||||
* underlying inode, while {GET,SET}_FILE_RW_HINT operate only on
|
||||
* the specific file.
|
||||
*/
|
||||
#define F_GET_RW_HINT (F_LINUX_SPECIFIC_BASE + 11)
|
||||
#define F_SET_RW_HINT (F_LINUX_SPECIFIC_BASE + 12)
|
||||
#define F_GET_FILE_RW_HINT (F_LINUX_SPECIFIC_BASE + 13)
|
||||
#define F_SET_FILE_RW_HINT (F_LINUX_SPECIFIC_BASE + 14)
|
||||
|
||||
/*
|
||||
* Valid hint values for F_{GET,SET}_RW_HINT. 0 is "not set", or can be
|
||||
* used to clear any hints previously set.
|
||||
*/
|
||||
#define RWF_WRITE_LIFE_NOT_SET 0
|
||||
#define RWH_WRITE_LIFE_NONE 1
|
||||
#define RWH_WRITE_LIFE_SHORT 2
|
||||
#define RWH_WRITE_LIFE_MEDIUM 3
|
||||
#define RWH_WRITE_LIFE_LONG 4
|
||||
#define RWH_WRITE_LIFE_EXTREME 5
|
||||
|
||||
/*
|
||||
* Types of directory notifications that may be requested.
|
||||
*/
|
||||
|
|
Loading…
Add table
Reference in a new issue