Merge remote-tracking branch 'origin/upstream-f2fs-stable-linux-4.19.y' into android-4.19
* origin/upstream-f2fs-stable-linux-4.19.y: f2fs: use EINVAL for superblock with invalid magic f2fs: fix to read source block before invalidating it f2fs: remove redundant check from f2fs_setflags_common() f2fs: use generic checking function for FS_IOC_FSSETXATTR f2fs: use generic checking and prep function for FS_IOC_SETFLAGS ubifs, fscrypt: cache decrypted symlink target in ->i_link vfs: use READ_ONCE() to access ->i_link fs, fscrypt: clear DCACHE_ENCRYPTED_NAME when unaliasing directory fscrypt: cache decrypted symlink target in ->i_link fscrypt: fix race where ->lookup() marks plaintext dentry as ciphertext fscrypt: only set dentry_operations on ciphertext dentries fscrypt: fix race allowing rename() and link() of ciphertext dentries fscrypt: clean up and improve dentry revalidation fscrypt: use READ_ONCE() to access ->i_crypt_info fscrypt: remove WARN_ON_ONCE() when decryption fails fscrypt: drop inode argument from fscrypt_get_ctx() f2fs: improve print log in f2fs_sanity_check_ckpt() f2fs: avoid out-of-range memory access f2fs: fix to avoid long latency during umount f2fs: allow all the users to pin a file f2fs: support swap file w/ DIO f2fs: allocate blocks for pinned file f2fs: fix is_idle() check for discard type f2fs: add a rw_sem to cover quota flag changes f2fs: set SBI_NEED_FSCK for xattr corruption case f2fs: use generic EFSBADCRC/EFSCORRUPTED f2fs: Use DIV_ROUND_UP() instead of open-coding f2fs: print kernel message if filesystem is inconsistent f2fs: introduce f2fs_<level> macros to wrap f2fs_printk() f2fs: avoid get_valid_blocks() for cleanup f2fs: ioctl for removing a range from F2FS f2fs: only set project inherit bit for directory f2fs: separate f2fs i_flags from fs_flags and ext4 i_flags f2fs: Add option to limit required GC for checkpoint=disable f2fs: Fix accounting for unusable blocks f2fs: Fix root reserved on remount f2fs: Lower threshold for disable_cp_again f2fs: fix sparse warning f2fs: fix f2fs_show_options to show nodiscard mount option f2fs: add error prints for debugging mount failure f2fs: fix to do sanity check on segment bitmap of LFS curseg f2fs: add missing sysfs entries in documentation f2fs: fix to avoid deadloop if data_flush is on f2fs: always assume that the device is idle under gc_urgent f2fs: add bio cache for IPU f2fs: allow ssr block allocation during checkpoint=disable period f2fs: fix to check layout on last valid checkpoint park Change-Id: Ie910f127f574c2115e5b9a6725461ce002c267be Signed-off-by: Jaegeuk Kim <jaegeuk@google.com>
This commit is contained in:
commit
e6f3ddbf65
39 changed files with 1864 additions and 1000 deletions
|
@ -243,3 +243,11 @@ Description:
|
|||
- 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
|
||||
|
||||
What: /sys/fs/f2fs/<disk>/unusable
|
||||
Date April 2019
|
||||
Contact: "Daniel Rosenberg" <drosen@google.com>
|
||||
Description:
|
||||
If checkpoint=disable, it displays the number of blocks that are unusable.
|
||||
If checkpoint=enable it displays the enumber of blocks that would be unusable
|
||||
if checkpoint=disable were to be set.
|
||||
|
|
|
@ -214,11 +214,22 @@ fsync_mode=%s Control the policy of fsync. Currently supports "posix",
|
|||
non-atomic files likewise "nobarrier" mount option.
|
||||
test_dummy_encryption Enable dummy encryption, which provides a fake fscrypt
|
||||
context. The fake fscrypt context is used by xfstests.
|
||||
checkpoint=%s Set to "disable" to turn off checkpointing. Set to "enable"
|
||||
checkpoint=%s[:%u[%]] Set to "disable" to turn off checkpointing. Set to "enable"
|
||||
to reenable checkpointing. Is enabled by default. While
|
||||
disabled, any unmounting or unexpected shutdowns will cause
|
||||
the filesystem contents to appear as they did when the
|
||||
filesystem was mounted with that option.
|
||||
While mounting with checkpoint=disabled, the filesystem must
|
||||
run garbage collection to ensure that all available space can
|
||||
be used. If this takes too much time, the mount may return
|
||||
EAGAIN. You may optionally add a value to indicate how much
|
||||
of the disk you would be willing to temporarily give up to
|
||||
avoid additional garbage collection. This can be given as a
|
||||
number of blocks, or as a percent. For instance, mounting
|
||||
with checkpoint=disable:100% would always succeed, but it may
|
||||
hide up to all remaining free space. The actual space that
|
||||
would be unusable can be viewed at /sys/fs/f2fs/<disk>/unusable
|
||||
This space is reclaimed once checkpoint=enable.
|
||||
|
||||
================================================================================
|
||||
DEBUGFS ENTRIES
|
||||
|
@ -246,11 +257,14 @@ Files in /sys/fs/f2fs/<devname>
|
|||
..............................................................................
|
||||
File Content
|
||||
|
||||
gc_max_sleep_time This tuning parameter controls the maximum sleep
|
||||
gc_urgent_sleep_time This parameter controls sleep time for gc_urgent.
|
||||
500 ms is set by default. See above gc_urgent.
|
||||
|
||||
gc_min_sleep_time This tuning parameter controls the minimum sleep
|
||||
time for the garbage collection thread. Time is
|
||||
in milliseconds.
|
||||
|
||||
gc_min_sleep_time This tuning parameter controls the minimum sleep
|
||||
gc_max_sleep_time This tuning parameter controls the maximum sleep
|
||||
time for the garbage collection thread. Time is
|
||||
in milliseconds.
|
||||
|
||||
|
@ -270,9 +284,6 @@ Files in /sys/fs/f2fs/<devname>
|
|||
to 1, background thread starts to do GC by given
|
||||
gc_urgent_sleep_time interval.
|
||||
|
||||
gc_urgent_sleep_time This parameter controls sleep time for gc_urgent.
|
||||
500 ms is set by default. See above gc_urgent.
|
||||
|
||||
reclaim_segments This parameter controls the number of prefree
|
||||
segments to be reclaimed. If the number of prefree
|
||||
segments is larger than the number of segments
|
||||
|
@ -287,7 +298,16 @@ Files in /sys/fs/f2fs/<devname>
|
|||
checkpoint is triggered, and issued during the
|
||||
checkpoint. By default, it is disabled with 0.
|
||||
|
||||
trim_sections This parameter controls the number of sections
|
||||
discard_granularity This parameter controls the granularity of discard
|
||||
command size. It will issue discard commands iif
|
||||
the size is larger than given granularity. Its
|
||||
unit size is 4KB, and 4 (=16KB) is set by default.
|
||||
The maximum value is 128 (=512KB).
|
||||
|
||||
reserved_blocks This parameter indicates the number of blocks that
|
||||
f2fs reserves internally for root.
|
||||
|
||||
batched_trim_sections This parameter controls the number of sections
|
||||
to be trimmed out in batch mode when FITRIM
|
||||
conducts. 32 sections is set by default.
|
||||
|
||||
|
@ -309,11 +329,35 @@ Files in /sys/fs/f2fs/<devname>
|
|||
the number is less than this value, it triggers
|
||||
in-place-updates.
|
||||
|
||||
min_seq_blocks This parameter controls the threshold to serialize
|
||||
write IOs issued by multiple threads in parallel.
|
||||
|
||||
min_hot_blocks This parameter controls the threshold to allocate
|
||||
a hot data log for pending data blocks to write.
|
||||
|
||||
min_ssr_sections This parameter adds the threshold when deciding
|
||||
SSR block allocation. If this is large, SSR mode
|
||||
will be enabled early.
|
||||
|
||||
ram_thresh This parameter controls the memory footprint used
|
||||
by free nids and cached nat entries. By default,
|
||||
10 is set, which indicates 10 MB / 1 GB RAM.
|
||||
|
||||
ra_nid_pages When building free nids, F2FS reads NAT blocks
|
||||
ahead for speed up. Default is 0.
|
||||
|
||||
dirty_nats_ratio Given dirty ratio of cached nat entries, F2FS
|
||||
determines flushing them in background.
|
||||
|
||||
max_victim_search This parameter controls the number of trials to
|
||||
find a victim segment when conducting SSR and
|
||||
cleaning operations. The default value is 4096
|
||||
which covers 8GB block address range.
|
||||
|
||||
migration_granularity For large-sized sections, F2FS can stop GC given
|
||||
this granularity instead of reclaiming entire
|
||||
section.
|
||||
|
||||
dir_level This parameter controls the directory level to
|
||||
support large directory. If a directory has a
|
||||
number of files, it can reduce the file lookup
|
||||
|
@ -321,9 +365,53 @@ Files in /sys/fs/f2fs/<devname>
|
|||
Otherwise, it needs to decrease this value to
|
||||
reduce the space overhead. The default value is 0.
|
||||
|
||||
ram_thresh This parameter controls the memory footprint used
|
||||
by free nids and cached nat entries. By default,
|
||||
10 is set, which indicates 10 MB / 1 GB RAM.
|
||||
cp_interval F2FS tries to do checkpoint periodically, 60 secs
|
||||
by default.
|
||||
|
||||
idle_interval F2FS detects system is idle, if there's no F2FS
|
||||
operations during given interval, 5 secs by
|
||||
default.
|
||||
|
||||
discard_idle_interval F2FS detects the discard thread is idle, given
|
||||
time interval. Default is 5 secs.
|
||||
|
||||
gc_idle_interval F2FS detects the GC thread is idle, given time
|
||||
interval. Default is 5 secs.
|
||||
|
||||
umount_discard_timeout When unmounting the disk, F2FS waits for finishing
|
||||
queued discard commands which can take huge time.
|
||||
This gives time out for it, 5 secs by default.
|
||||
|
||||
iostat_enable This controls to enable/disable iostat in F2FS.
|
||||
|
||||
readdir_ra This enables/disabled readahead of inode blocks
|
||||
in readdir, and default is enabled.
|
||||
|
||||
gc_pin_file_thresh This indicates how many GC can be failed for the
|
||||
pinned file. If it exceeds this, F2FS doesn't
|
||||
guarantee its pinning state. 2048 trials is set
|
||||
by default.
|
||||
|
||||
extension_list This enables to change extension_list for hot/cold
|
||||
files in runtime.
|
||||
|
||||
inject_rate This controls injection rate of arbitrary faults.
|
||||
|
||||
inject_type This controls injection type of arbitrary faults.
|
||||
|
||||
dirty_segments This shows # of dirty segments.
|
||||
|
||||
lifetime_write_kbytes This shows # of data written to the disk.
|
||||
|
||||
features This shows current features enabled on F2FS.
|
||||
|
||||
current_reserved_blocks This shows # of blocks currently reserved.
|
||||
|
||||
unusable If checkpoint=disable, this shows the number of
|
||||
blocks that are unusable.
|
||||
If checkpoint=enable it shows the number of blocks
|
||||
that would be unusable if checkpoint=disable were
|
||||
to be set.
|
||||
|
||||
================================================================================
|
||||
USAGE
|
||||
|
@ -716,3 +804,28 @@ 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
|
||||
|
||||
Fallocate(2) Policy
|
||||
-------------------
|
||||
|
||||
The default policy follows the below posix rule.
|
||||
|
||||
Allocating disk space
|
||||
The default operation (i.e., mode is zero) of fallocate() allocates
|
||||
the disk space within the range specified by offset and len. The
|
||||
file size (as reported by stat(2)) will be changed if offset+len is
|
||||
greater than the file size. Any subregion within the range specified
|
||||
by offset and len that did not contain data before the call will be
|
||||
initialized to zero. This default behavior closely resembles the
|
||||
behavior of the posix_fallocate(3) library function, and is intended
|
||||
as a method of optimally implementing that function.
|
||||
|
||||
However, once F2FS receives ioctl(fd, F2FS_IOC_SET_PIN_FILE) in prior to
|
||||
fallocate(fd, DEFAULT_MODE), it allocates on-disk blocks addressess having
|
||||
zero or random data, which is useful to the below scenario where:
|
||||
1. create(fd)
|
||||
2. ioctl(fd, F2FS_IOC_SET_PIN_FILE)
|
||||
3. fallocate(fd, 0, 0, size)
|
||||
4. address = fibmap(fd, offset)
|
||||
5. open(blkdev)
|
||||
6. write(blkdev, address)
|
||||
|
|
|
@ -36,12 +36,10 @@ static void __fscrypt_decrypt_bio(struct bio *bio, bool done)
|
|||
int ret = fscrypt_decrypt_page(page->mapping->host, page,
|
||||
PAGE_SIZE, 0, page->index);
|
||||
|
||||
if (ret) {
|
||||
WARN_ON_ONCE(1);
|
||||
if (ret)
|
||||
SetPageError(page);
|
||||
} else if (done) {
|
||||
else if (done)
|
||||
SetPageUptodate(page);
|
||||
}
|
||||
if (done)
|
||||
unlock_page(page);
|
||||
}
|
||||
|
@ -103,7 +101,7 @@ int fscrypt_zeroout_range(const struct inode *inode, pgoff_t lblk,
|
|||
|
||||
BUG_ON(inode->i_sb->s_blocksize != PAGE_SIZE);
|
||||
|
||||
ctx = fscrypt_get_ctx(inode, GFP_NOFS);
|
||||
ctx = fscrypt_get_ctx(GFP_NOFS);
|
||||
if (IS_ERR(ctx))
|
||||
return PTR_ERR(ctx);
|
||||
|
||||
|
|
|
@ -87,23 +87,17 @@ EXPORT_SYMBOL(fscrypt_release_ctx);
|
|||
|
||||
/**
|
||||
* fscrypt_get_ctx() - Gets an encryption context
|
||||
* @inode: The inode for which we are doing the crypto
|
||||
* @gfp_flags: The gfp flag for memory allocation
|
||||
*
|
||||
* Allocates and initializes an encryption context.
|
||||
*
|
||||
* Return: An allocated and initialized encryption context on success; error
|
||||
* value or NULL otherwise.
|
||||
* Return: A new encryption context on success; an ERR_PTR() otherwise.
|
||||
*/
|
||||
struct fscrypt_ctx *fscrypt_get_ctx(const struct inode *inode, gfp_t gfp_flags)
|
||||
struct fscrypt_ctx *fscrypt_get_ctx(gfp_t gfp_flags)
|
||||
{
|
||||
struct fscrypt_ctx *ctx = NULL;
|
||||
struct fscrypt_info *ci = inode->i_crypt_info;
|
||||
struct fscrypt_ctx *ctx;
|
||||
unsigned long flags;
|
||||
|
||||
if (ci == NULL)
|
||||
return ERR_PTR(-ENOKEY);
|
||||
|
||||
/*
|
||||
* We first try getting the ctx from a free list because in
|
||||
* the common case the ctx will have an allocated and
|
||||
|
@ -260,9 +254,9 @@ struct page *fscrypt_encrypt_page(const struct inode *inode,
|
|||
if (WARN_ON_ONCE(!PageLocked(page)))
|
||||
return ERR_PTR(-EINVAL);
|
||||
|
||||
ctx = fscrypt_get_ctx(inode, gfp_flags);
|
||||
ctx = fscrypt_get_ctx(gfp_flags);
|
||||
if (IS_ERR(ctx))
|
||||
return (struct page *)ctx;
|
||||
return ERR_CAST(ctx);
|
||||
|
||||
/* The encryption operation will require a bounce page. */
|
||||
ciphertext_page = fscrypt_alloc_bounce_page(ctx, gfp_flags);
|
||||
|
@ -316,45 +310,47 @@ int fscrypt_decrypt_page(const struct inode *inode, struct page *page,
|
|||
EXPORT_SYMBOL(fscrypt_decrypt_page);
|
||||
|
||||
/*
|
||||
* Validate dentries for encrypted directories to make sure we aren't
|
||||
* potentially caching stale data after a key has been added or
|
||||
* removed.
|
||||
* Validate dentries in encrypted directories to make sure we aren't potentially
|
||||
* caching stale dentries after a key has been added.
|
||||
*/
|
||||
static int fscrypt_d_revalidate(struct dentry *dentry, unsigned int flags)
|
||||
{
|
||||
struct dentry *dir;
|
||||
int dir_has_key, cached_with_key;
|
||||
int err;
|
||||
int valid;
|
||||
|
||||
/*
|
||||
* Plaintext names are always valid, since fscrypt doesn't support
|
||||
* reverting to ciphertext names without evicting the directory's inode
|
||||
* -- which implies eviction of the dentries in the directory.
|
||||
*/
|
||||
if (!(dentry->d_flags & DCACHE_ENCRYPTED_NAME))
|
||||
return 1;
|
||||
|
||||
/*
|
||||
* Ciphertext name; valid if the directory's key is still unavailable.
|
||||
*
|
||||
* Although fscrypt forbids rename() on ciphertext names, we still must
|
||||
* use dget_parent() here rather than use ->d_parent directly. That's
|
||||
* because a corrupted fs image may contain directory hard links, which
|
||||
* the VFS handles by moving the directory's dentry tree in the dcache
|
||||
* each time ->lookup() finds the directory and it already has a dentry
|
||||
* elsewhere. Thus ->d_parent can be changing, and we must safely grab
|
||||
* a reference to some ->d_parent to prevent it from being freed.
|
||||
*/
|
||||
|
||||
if (flags & LOOKUP_RCU)
|
||||
return -ECHILD;
|
||||
|
||||
dir = dget_parent(dentry);
|
||||
if (!IS_ENCRYPTED(d_inode(dir))) {
|
||||
dput(dir);
|
||||
return 0;
|
||||
}
|
||||
|
||||
spin_lock(&dentry->d_lock);
|
||||
cached_with_key = dentry->d_flags & DCACHE_ENCRYPTED_WITH_KEY;
|
||||
spin_unlock(&dentry->d_lock);
|
||||
dir_has_key = (d_inode(dir)->i_crypt_info != NULL);
|
||||
err = fscrypt_get_encryption_info(d_inode(dir));
|
||||
valid = !fscrypt_has_encryption_key(d_inode(dir));
|
||||
dput(dir);
|
||||
|
||||
/*
|
||||
* If the dentry was cached without the key, and it is a
|
||||
* negative dentry, it might be a valid name. We can't check
|
||||
* if the key has since been made available due to locking
|
||||
* reasons, so we fail the validation so ext4_lookup() can do
|
||||
* this check.
|
||||
*
|
||||
* We also fail the validation if the dentry was created with
|
||||
* the key present, but we no longer have the key, or vice versa.
|
||||
*/
|
||||
if ((!cached_with_key && d_is_negative(dentry)) ||
|
||||
(!cached_with_key && dir_has_key) ||
|
||||
(cached_with_key && !dir_has_key))
|
||||
return 0;
|
||||
return 1;
|
||||
if (err < 0)
|
||||
return err;
|
||||
|
||||
return valid;
|
||||
}
|
||||
|
||||
const struct dentry_operations fscrypt_d_ops = {
|
||||
|
|
|
@ -269,7 +269,7 @@ int fscrypt_fname_disk_to_usr(struct inode *inode,
|
|||
if (iname->len < FS_CRYPTO_BLOCK_SIZE)
|
||||
return -EUCLEAN;
|
||||
|
||||
if (inode->i_crypt_info)
|
||||
if (fscrypt_has_encryption_key(inode))
|
||||
return fname_decrypt(inode, iname, oname);
|
||||
|
||||
if (iname->len <= FSCRYPT_FNAME_MAX_UNDIGESTED_SIZE) {
|
||||
|
@ -336,7 +336,7 @@ int fscrypt_setup_filename(struct inode *dir, const struct qstr *iname,
|
|||
if (ret)
|
||||
return ret;
|
||||
|
||||
if (dir->i_crypt_info) {
|
||||
if (fscrypt_has_encryption_key(dir)) {
|
||||
if (!fscrypt_fname_encrypted_size(dir, iname->len,
|
||||
dir->i_sb->s_cop->max_namelen,
|
||||
&fname->crypto_buf.len))
|
||||
|
@ -356,6 +356,7 @@ int fscrypt_setup_filename(struct inode *dir, const struct qstr *iname,
|
|||
}
|
||||
if (!lookup)
|
||||
return -ENOKEY;
|
||||
fname->is_ciphertext_name = true;
|
||||
|
||||
/*
|
||||
* We don't have the key and we are doing a lookup; decode the
|
||||
|
|
|
@ -49,7 +49,8 @@ int fscrypt_file_open(struct inode *inode, struct file *filp)
|
|||
}
|
||||
EXPORT_SYMBOL_GPL(fscrypt_file_open);
|
||||
|
||||
int __fscrypt_prepare_link(struct inode *inode, struct inode *dir)
|
||||
int __fscrypt_prepare_link(struct inode *inode, struct inode *dir,
|
||||
struct dentry *dentry)
|
||||
{
|
||||
int err;
|
||||
|
||||
|
@ -57,6 +58,10 @@ int __fscrypt_prepare_link(struct inode *inode, struct inode *dir)
|
|||
if (err)
|
||||
return err;
|
||||
|
||||
/* ... in case we looked up ciphertext name before key was added */
|
||||
if (dentry->d_flags & DCACHE_ENCRYPTED_NAME)
|
||||
return -ENOKEY;
|
||||
|
||||
if (!fscrypt_has_permitted_context(dir, inode))
|
||||
return -EXDEV;
|
||||
|
||||
|
@ -78,6 +83,11 @@ int __fscrypt_prepare_rename(struct inode *old_dir, struct dentry *old_dentry,
|
|||
if (err)
|
||||
return err;
|
||||
|
||||
/* ... in case we looked up ciphertext name(s) before key was added */
|
||||
if ((old_dentry->d_flags | new_dentry->d_flags) &
|
||||
DCACHE_ENCRYPTED_NAME)
|
||||
return -ENOKEY;
|
||||
|
||||
if (old_dir != new_dir) {
|
||||
if (IS_ENCRYPTED(new_dir) &&
|
||||
!fscrypt_has_permitted_context(new_dir,
|
||||
|
@ -94,21 +104,21 @@ int __fscrypt_prepare_rename(struct inode *old_dir, struct dentry *old_dentry,
|
|||
}
|
||||
EXPORT_SYMBOL_GPL(__fscrypt_prepare_rename);
|
||||
|
||||
int __fscrypt_prepare_lookup(struct inode *dir, struct dentry *dentry)
|
||||
int __fscrypt_prepare_lookup(struct inode *dir, struct dentry *dentry,
|
||||
struct fscrypt_name *fname)
|
||||
{
|
||||
int err = fscrypt_get_encryption_info(dir);
|
||||
int err = fscrypt_setup_filename(dir, &dentry->d_name, 1, fname);
|
||||
|
||||
if (err)
|
||||
if (err && err != -ENOENT)
|
||||
return err;
|
||||
|
||||
if (fscrypt_has_encryption_key(dir)) {
|
||||
if (fname->is_ciphertext_name) {
|
||||
spin_lock(&dentry->d_lock);
|
||||
dentry->d_flags |= DCACHE_ENCRYPTED_WITH_KEY;
|
||||
dentry->d_flags |= DCACHE_ENCRYPTED_NAME;
|
||||
spin_unlock(&dentry->d_lock);
|
||||
d_set_d_op(dentry, &fscrypt_d_ops);
|
||||
}
|
||||
|
||||
d_set_d_op(dentry, &fscrypt_d_ops);
|
||||
return 0;
|
||||
return err;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(__fscrypt_prepare_lookup);
|
||||
|
||||
|
@ -179,11 +189,9 @@ int __fscrypt_encrypt_symlink(struct inode *inode, const char *target,
|
|||
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;
|
||||
}
|
||||
if (err)
|
||||
goto err_free_sd;
|
||||
|
||||
/*
|
||||
* Null-terminating the ciphertext doesn't make sense, but we still
|
||||
* count the null terminator in the length, so we might as well
|
||||
|
@ -191,9 +199,20 @@ int __fscrypt_encrypt_symlink(struct inode *inode, const char *target,
|
|||
*/
|
||||
sd->encrypted_path[ciphertext_len] = '\0';
|
||||
|
||||
/* Cache the plaintext symlink target for later use by get_link() */
|
||||
err = -ENOMEM;
|
||||
inode->i_link = kmemdup(target, len + 1, GFP_NOFS);
|
||||
if (!inode->i_link)
|
||||
goto err_free_sd;
|
||||
|
||||
if (!disk_link->name)
|
||||
disk_link->name = (unsigned char *)sd;
|
||||
return 0;
|
||||
|
||||
err_free_sd:
|
||||
if (!disk_link->name)
|
||||
kfree(sd);
|
||||
return err;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(__fscrypt_encrypt_symlink);
|
||||
|
||||
|
@ -202,7 +221,7 @@ EXPORT_SYMBOL_GPL(__fscrypt_encrypt_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
|
||||
* @done: if successful, will be set up to free the returned target if needed
|
||||
*
|
||||
* If the symlink's encryption key is available, we decrypt its target.
|
||||
* Otherwise, we encode its target for presentation.
|
||||
|
@ -217,12 +236,18 @@ const char *fscrypt_get_symlink(struct inode *inode, const void *caddr,
|
|||
{
|
||||
const struct fscrypt_symlink_data *sd;
|
||||
struct fscrypt_str cstr, pstr;
|
||||
bool has_key;
|
||||
int err;
|
||||
|
||||
/* This is for encrypted symlinks only */
|
||||
if (WARN_ON(!IS_ENCRYPTED(inode)))
|
||||
return ERR_PTR(-EINVAL);
|
||||
|
||||
/* If the decrypted target is already cached, just return it. */
|
||||
pstr.name = READ_ONCE(inode->i_link);
|
||||
if (pstr.name)
|
||||
return pstr.name;
|
||||
|
||||
/*
|
||||
* Try to set up the symlink's encryption key, but we can continue
|
||||
* regardless of whether the key is available or not.
|
||||
|
@ -230,6 +255,7 @@ const char *fscrypt_get_symlink(struct inode *inode, const void *caddr,
|
|||
err = fscrypt_get_encryption_info(inode);
|
||||
if (err)
|
||||
return ERR_PTR(err);
|
||||
has_key = fscrypt_has_encryption_key(inode);
|
||||
|
||||
/*
|
||||
* For historical reasons, encrypted symlink targets are prefixed with
|
||||
|
@ -261,7 +287,17 @@ const char *fscrypt_get_symlink(struct inode *inode, const void *caddr,
|
|||
goto err_kfree;
|
||||
|
||||
pstr.name[pstr.len] = '\0';
|
||||
set_delayed_call(done, kfree_link, pstr.name);
|
||||
|
||||
/*
|
||||
* Cache decrypted symlink targets in i_link for later use. Don't cache
|
||||
* symlink targets encoded without the key, since those become outdated
|
||||
* once the key is added. This pairs with the READ_ONCE() above and in
|
||||
* the VFS path lookup code.
|
||||
*/
|
||||
if (!has_key ||
|
||||
cmpxchg_release(&inode->i_link, NULL, pstr.name) != NULL)
|
||||
set_delayed_call(done, kfree_link, pstr.name);
|
||||
|
||||
return pstr.name;
|
||||
|
||||
err_kfree:
|
||||
|
|
|
@ -509,7 +509,7 @@ int fscrypt_get_encryption_info(struct inode *inode)
|
|||
u8 *raw_key = NULL;
|
||||
int res;
|
||||
|
||||
if (inode->i_crypt_info)
|
||||
if (fscrypt_has_encryption_key(inode))
|
||||
return 0;
|
||||
|
||||
res = fscrypt_initialize(inode->i_sb->s_cop->flags);
|
||||
|
@ -573,7 +573,7 @@ int fscrypt_get_encryption_info(struct inode *inode)
|
|||
if (res)
|
||||
goto out;
|
||||
|
||||
if (cmpxchg(&inode->i_crypt_info, NULL, crypt_info) == NULL)
|
||||
if (cmpxchg_release(&inode->i_crypt_info, NULL, crypt_info) == NULL)
|
||||
crypt_info = NULL;
|
||||
out:
|
||||
if (res == -ENOKEY)
|
||||
|
@ -584,9 +584,30 @@ int fscrypt_get_encryption_info(struct inode *inode)
|
|||
}
|
||||
EXPORT_SYMBOL(fscrypt_get_encryption_info);
|
||||
|
||||
/**
|
||||
* fscrypt_put_encryption_info - free most of an inode's fscrypt data
|
||||
*
|
||||
* Free the inode's fscrypt_info. Filesystems must call this when the inode is
|
||||
* being evicted. An RCU grace period need not have elapsed yet.
|
||||
*/
|
||||
void fscrypt_put_encryption_info(struct inode *inode)
|
||||
{
|
||||
put_crypt_info(inode->i_crypt_info);
|
||||
inode->i_crypt_info = NULL;
|
||||
}
|
||||
EXPORT_SYMBOL(fscrypt_put_encryption_info);
|
||||
|
||||
/**
|
||||
* fscrypt_free_inode - free an inode's fscrypt data requiring RCU delay
|
||||
*
|
||||
* Free the inode's cached decrypted symlink target, if any. Filesystems must
|
||||
* call this after an RCU grace period, just before they free the inode.
|
||||
*/
|
||||
void fscrypt_free_inode(struct inode *inode)
|
||||
{
|
||||
if (IS_ENCRYPTED(inode) && S_ISLNK(inode->i_mode)) {
|
||||
kfree(inode->i_link);
|
||||
inode->i_link = NULL;
|
||||
}
|
||||
}
|
||||
EXPORT_SYMBOL(fscrypt_free_inode);
|
||||
|
|
|
@ -196,8 +196,8 @@ int fscrypt_has_permitted_context(struct inode *parent, struct inode *child)
|
|||
res = fscrypt_get_encryption_info(child);
|
||||
if (res)
|
||||
return 0;
|
||||
parent_ci = parent->i_crypt_info;
|
||||
child_ci = child->i_crypt_info;
|
||||
parent_ci = READ_ONCE(parent->i_crypt_info);
|
||||
child_ci = READ_ONCE(child->i_crypt_info);
|
||||
|
||||
if (parent_ci && child_ci) {
|
||||
return memcmp(parent_ci->ci_master_key_descriptor,
|
||||
|
@ -248,7 +248,7 @@ int fscrypt_inherit_context(struct inode *parent, struct inode *child,
|
|||
if (res < 0)
|
||||
return res;
|
||||
|
||||
ci = parent->i_crypt_info;
|
||||
ci = READ_ONCE(parent->i_crypt_info);
|
||||
if (ci == NULL)
|
||||
return -ENOKEY;
|
||||
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
#include <linux/string.h>
|
||||
#include <linux/mm.h>
|
||||
#include <linux/fs.h>
|
||||
#include <linux/fscrypt.h>
|
||||
#include <linux/fsnotify.h>
|
||||
#include <linux/slab.h>
|
||||
#include <linux/init.h>
|
||||
|
@ -2785,6 +2786,7 @@ static void __d_move(struct dentry *dentry, struct dentry *target,
|
|||
list_move(&dentry->d_child, &dentry->d_parent->d_subdirs);
|
||||
__d_rehash(dentry);
|
||||
fsnotify_update_flags(dentry);
|
||||
fscrypt_handle_d_move(dentry);
|
||||
|
||||
write_seqcount_end(&target->d_seq);
|
||||
write_seqcount_end(&dentry->d_seq);
|
||||
|
|
|
@ -2292,23 +2292,47 @@ extern unsigned ext4_free_clusters_after_init(struct super_block *sb,
|
|||
ext4_fsblk_t ext4_inode_to_goal_block(struct inode *);
|
||||
|
||||
#ifdef CONFIG_FS_ENCRYPTION
|
||||
static inline void ext4_fname_from_fscrypt_name(struct ext4_filename *dst,
|
||||
const struct fscrypt_name *src)
|
||||
{
|
||||
memset(dst, 0, sizeof(*dst));
|
||||
|
||||
dst->usr_fname = src->usr_fname;
|
||||
dst->disk_name = src->disk_name;
|
||||
dst->hinfo.hash = src->hash;
|
||||
dst->hinfo.minor_hash = src->minor_hash;
|
||||
dst->crypto_buf = src->crypto_buf;
|
||||
}
|
||||
|
||||
static inline int ext4_fname_setup_filename(struct inode *dir,
|
||||
const struct qstr *iname,
|
||||
int lookup, struct ext4_filename *fname)
|
||||
const struct qstr *iname,
|
||||
int lookup,
|
||||
struct ext4_filename *fname)
|
||||
{
|
||||
struct fscrypt_name name;
|
||||
int err;
|
||||
|
||||
memset(fname, 0, sizeof(struct ext4_filename));
|
||||
|
||||
err = fscrypt_setup_filename(dir, iname, lookup, &name);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
fname->usr_fname = name.usr_fname;
|
||||
fname->disk_name = name.disk_name;
|
||||
fname->hinfo.hash = name.hash;
|
||||
fname->hinfo.minor_hash = name.minor_hash;
|
||||
fname->crypto_buf = name.crypto_buf;
|
||||
return err;
|
||||
ext4_fname_from_fscrypt_name(fname, &name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline int ext4_fname_prepare_lookup(struct inode *dir,
|
||||
struct dentry *dentry,
|
||||
struct ext4_filename *fname)
|
||||
{
|
||||
struct fscrypt_name name;
|
||||
int err;
|
||||
|
||||
err = fscrypt_prepare_lookup(dir, dentry, &name);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
ext4_fname_from_fscrypt_name(fname, &name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline void ext4_fname_free_filename(struct ext4_filename *fname)
|
||||
|
@ -2322,19 +2346,27 @@ static inline void ext4_fname_free_filename(struct ext4_filename *fname)
|
|||
fname->usr_fname = NULL;
|
||||
fname->disk_name.name = NULL;
|
||||
}
|
||||
#else
|
||||
#else /* !CONFIG_FS_ENCRYPTION */
|
||||
static inline int ext4_fname_setup_filename(struct inode *dir,
|
||||
const struct qstr *iname,
|
||||
int lookup, struct ext4_filename *fname)
|
||||
const struct qstr *iname,
|
||||
int lookup,
|
||||
struct ext4_filename *fname)
|
||||
{
|
||||
fname->usr_fname = iname;
|
||||
fname->disk_name.name = (unsigned char *) iname->name;
|
||||
fname->disk_name.len = iname->len;
|
||||
return 0;
|
||||
}
|
||||
static inline void ext4_fname_free_filename(struct ext4_filename *fname) { }
|
||||
|
||||
#endif
|
||||
static inline int ext4_fname_prepare_lookup(struct inode *dir,
|
||||
struct dentry *dentry,
|
||||
struct ext4_filename *fname)
|
||||
{
|
||||
return ext4_fname_setup_filename(dir, &dentry->d_name, 1, fname);
|
||||
}
|
||||
|
||||
static inline void ext4_fname_free_filename(struct ext4_filename *fname) { }
|
||||
#endif /* !CONFIG_FS_ENCRYPTION */
|
||||
|
||||
/* dir.c */
|
||||
extern int __ext4_check_dir_entry(const char *, unsigned int, struct inode *,
|
||||
|
|
|
@ -1343,7 +1343,7 @@ static int is_dx_internal_node(struct inode *dir, ext4_lblk_t block,
|
|||
}
|
||||
|
||||
/*
|
||||
* ext4_find_entry()
|
||||
* __ext4_find_entry()
|
||||
*
|
||||
* finds an entry in the specified directory with the wanted name. It
|
||||
* returns the cache buffer in which the entry was found, and the entry
|
||||
|
@ -1353,39 +1353,32 @@ static int is_dx_internal_node(struct inode *dir, ext4_lblk_t block,
|
|||
* The returned buffer_head has ->b_count elevated. The caller is expected
|
||||
* to brelse() it when appropriate.
|
||||
*/
|
||||
static struct buffer_head * ext4_find_entry (struct inode *dir,
|
||||
const struct qstr *d_name,
|
||||
struct ext4_dir_entry_2 **res_dir,
|
||||
int *inlined)
|
||||
static struct buffer_head *__ext4_find_entry(struct inode *dir,
|
||||
struct ext4_filename *fname,
|
||||
struct ext4_dir_entry_2 **res_dir,
|
||||
int *inlined)
|
||||
{
|
||||
struct super_block *sb;
|
||||
struct buffer_head *bh_use[NAMEI_RA_SIZE];
|
||||
struct buffer_head *bh, *ret = NULL;
|
||||
ext4_lblk_t start, block;
|
||||
const u8 *name = d_name->name;
|
||||
const u8 *name = fname->usr_fname->name;
|
||||
size_t ra_max = 0; /* Number of bh's in the readahead
|
||||
buffer, bh_use[] */
|
||||
size_t ra_ptr = 0; /* Current index into readahead
|
||||
buffer */
|
||||
ext4_lblk_t nblocks;
|
||||
int i, namelen, retval;
|
||||
struct ext4_filename fname;
|
||||
|
||||
*res_dir = NULL;
|
||||
sb = dir->i_sb;
|
||||
namelen = d_name->len;
|
||||
namelen = fname->usr_fname->len;
|
||||
if (namelen > EXT4_NAME_LEN)
|
||||
return NULL;
|
||||
|
||||
retval = ext4_fname_setup_filename(dir, d_name, 1, &fname);
|
||||
if (retval == -ENOENT)
|
||||
return NULL;
|
||||
if (retval)
|
||||
return ERR_PTR(retval);
|
||||
|
||||
if (ext4_has_inline_data(dir)) {
|
||||
int has_inline_data = 1;
|
||||
ret = ext4_find_inline_entry(dir, &fname, res_dir,
|
||||
ret = ext4_find_inline_entry(dir, fname, res_dir,
|
||||
&has_inline_data);
|
||||
if (has_inline_data) {
|
||||
if (inlined)
|
||||
|
@ -1405,7 +1398,7 @@ static struct buffer_head * ext4_find_entry (struct inode *dir,
|
|||
goto restart;
|
||||
}
|
||||
if (is_dx(dir)) {
|
||||
ret = ext4_dx_find_entry(dir, &fname, res_dir);
|
||||
ret = ext4_dx_find_entry(dir, fname, res_dir);
|
||||
/*
|
||||
* On success, or if the error was file not found,
|
||||
* return. Otherwise, fall back to doing a search the
|
||||
|
@ -1469,7 +1462,7 @@ static struct buffer_head * ext4_find_entry (struct inode *dir,
|
|||
goto cleanup_and_exit;
|
||||
}
|
||||
set_buffer_verified(bh);
|
||||
i = search_dirblock(bh, dir, &fname,
|
||||
i = search_dirblock(bh, dir, fname,
|
||||
block << EXT4_BLOCK_SIZE_BITS(sb), res_dir);
|
||||
if (i == 1) {
|
||||
EXT4_I(dir)->i_dir_start_lookup = block;
|
||||
|
@ -1500,10 +1493,50 @@ static struct buffer_head * ext4_find_entry (struct inode *dir,
|
|||
/* Clean up the read-ahead blocks */
|
||||
for (; ra_ptr < ra_max; ra_ptr++)
|
||||
brelse(bh_use[ra_ptr]);
|
||||
ext4_fname_free_filename(&fname);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static struct buffer_head *ext4_find_entry(struct inode *dir,
|
||||
const struct qstr *d_name,
|
||||
struct ext4_dir_entry_2 **res_dir,
|
||||
int *inlined)
|
||||
{
|
||||
int err;
|
||||
struct ext4_filename fname;
|
||||
struct buffer_head *bh;
|
||||
|
||||
err = ext4_fname_setup_filename(dir, d_name, 1, &fname);
|
||||
if (err == -ENOENT)
|
||||
return NULL;
|
||||
if (err)
|
||||
return ERR_PTR(err);
|
||||
|
||||
bh = __ext4_find_entry(dir, &fname, res_dir, inlined);
|
||||
|
||||
ext4_fname_free_filename(&fname);
|
||||
return bh;
|
||||
}
|
||||
|
||||
static struct buffer_head *ext4_lookup_entry(struct inode *dir,
|
||||
struct dentry *dentry,
|
||||
struct ext4_dir_entry_2 **res_dir)
|
||||
{
|
||||
int err;
|
||||
struct ext4_filename fname;
|
||||
struct buffer_head *bh;
|
||||
|
||||
err = ext4_fname_prepare_lookup(dir, dentry, &fname);
|
||||
if (err == -ENOENT)
|
||||
return NULL;
|
||||
if (err)
|
||||
return ERR_PTR(err);
|
||||
|
||||
bh = __ext4_find_entry(dir, &fname, res_dir, NULL);
|
||||
|
||||
ext4_fname_free_filename(&fname);
|
||||
return bh;
|
||||
}
|
||||
|
||||
static struct buffer_head * ext4_dx_find_entry(struct inode *dir,
|
||||
struct ext4_filename *fname,
|
||||
struct ext4_dir_entry_2 **res_dir)
|
||||
|
@ -1562,16 +1595,11 @@ static struct dentry *ext4_lookup(struct inode *dir, struct dentry *dentry, unsi
|
|||
struct inode *inode;
|
||||
struct ext4_dir_entry_2 *de;
|
||||
struct buffer_head *bh;
|
||||
int err;
|
||||
|
||||
err = fscrypt_prepare_lookup(dir, dentry, flags);
|
||||
if (err)
|
||||
return ERR_PTR(err);
|
||||
|
||||
if (dentry->d_name.len > EXT4_NAME_LEN)
|
||||
return ERR_PTR(-ENAMETOOLONG);
|
||||
|
||||
bh = ext4_find_entry(dir, &dentry->d_name, &de, NULL);
|
||||
bh = ext4_lookup_entry(dir, dentry, &de);
|
||||
if (IS_ERR(bh))
|
||||
return (struct dentry *) bh;
|
||||
inode = NULL;
|
||||
|
|
|
@ -282,7 +282,7 @@ int ext4_mpage_readpages(struct address_space *mapping,
|
|||
struct fscrypt_ctx *ctx = NULL;
|
||||
|
||||
if (IS_ENCRYPTED(inode) && S_ISREG(inode->i_mode)) {
|
||||
ctx = fscrypt_get_ctx(inode, GFP_NOFS);
|
||||
ctx = fscrypt_get_ctx(GFP_NOFS);
|
||||
if (IS_ERR(ctx))
|
||||
goto set_error_page;
|
||||
}
|
||||
|
|
|
@ -1110,6 +1110,9 @@ static int ext4_drop_inode(struct inode *inode)
|
|||
static void ext4_i_callback(struct rcu_head *head)
|
||||
{
|
||||
struct inode *inode = container_of(head, struct inode, i_rcu);
|
||||
|
||||
fscrypt_free_inode(inode);
|
||||
|
||||
kmem_cache_free(ext4_inode_cachep, EXT4_I(inode));
|
||||
}
|
||||
|
||||
|
|
|
@ -146,8 +146,8 @@ static bool __is_bitmap_valid(struct f2fs_sb_info *sbi, block_t blkaddr,
|
|||
|
||||
exist = f2fs_test_bit(offset, se->cur_valid_map);
|
||||
if (!exist && type == DATA_GENERIC_ENHANCE) {
|
||||
f2fs_msg(sbi->sb, KERN_ERR, "Inconsistent error "
|
||||
"blkaddr:%u, sit bitmap:%d", blkaddr, exist);
|
||||
f2fs_err(sbi, "Inconsistent error blkaddr:%u, sit bitmap:%d",
|
||||
blkaddr, exist);
|
||||
set_sbi_flag(sbi, SBI_NEED_FSCK);
|
||||
WARN_ON(1);
|
||||
}
|
||||
|
@ -184,8 +184,8 @@ bool f2fs_is_valid_blkaddr(struct f2fs_sb_info *sbi,
|
|||
case DATA_GENERIC_ENHANCE_READ:
|
||||
if (unlikely(blkaddr >= MAX_BLKADDR(sbi) ||
|
||||
blkaddr < MAIN_BLKADDR(sbi))) {
|
||||
f2fs_msg(sbi->sb, KERN_WARNING,
|
||||
"access invalid blkaddr:%u", blkaddr);
|
||||
f2fs_warn(sbi, "access invalid blkaddr:%u",
|
||||
blkaddr);
|
||||
set_sbi_flag(sbi, SBI_NEED_FSCK);
|
||||
WARN_ON(1);
|
||||
return false;
|
||||
|
@ -657,9 +657,8 @@ static int recover_orphan_inode(struct f2fs_sb_info *sbi, nid_t ino)
|
|||
|
||||
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);
|
||||
f2fs_warn(sbi, "%s: orphan failed (ino=%x), run fsck to fix.",
|
||||
__func__, ino);
|
||||
return err;
|
||||
}
|
||||
|
||||
|
@ -676,13 +675,12 @@ int f2fs_recover_orphan_inodes(struct f2fs_sb_info *sbi)
|
|||
return 0;
|
||||
|
||||
if (bdev_read_only(sbi->sb->s_bdev)) {
|
||||
f2fs_msg(sbi->sb, KERN_INFO, "write access "
|
||||
"unavailable, skipping orphan cleanup");
|
||||
f2fs_info(sbi, "write access unavailable, skipping orphan cleanup");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (s_flags & SB_RDONLY) {
|
||||
f2fs_msg(sbi->sb, KERN_INFO, "orphan cleanup on readonly fs");
|
||||
f2fs_info(sbi, "orphan cleanup on readonly fs");
|
||||
sbi->sb->s_flags &= ~SB_RDONLY;
|
||||
}
|
||||
|
||||
|
@ -827,26 +825,14 @@ static int get_checkpoint_version(struct f2fs_sb_info *sbi, block_t cp_addr,
|
|||
if (crc_offset < CP_MIN_CHKSUM_OFFSET ||
|
||||
crc_offset > CP_CHKSUM_OFFSET) {
|
||||
f2fs_put_page(*cp_page, 1);
|
||||
f2fs_msg(sbi->sb, KERN_WARNING,
|
||||
"invalid crc_offset: %zu", crc_offset);
|
||||
f2fs_warn(sbi, "invalid crc_offset: %zu", crc_offset);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (__is_set_ckpt_flags(*cp_block, CP_LARGE_NAT_BITMAP_FLAG)) {
|
||||
if (crc_offset != CP_MIN_CHKSUM_OFFSET) {
|
||||
f2fs_put_page(*cp_page, 1);
|
||||
f2fs_msg(sbi->sb, KERN_WARNING,
|
||||
"layout of large_nat_bitmap is deprecated, "
|
||||
"run fsck to repair, chksum_offset: %zu",
|
||||
crc_offset);
|
||||
return -EINVAL;
|
||||
}
|
||||
}
|
||||
|
||||
crc = f2fs_checkpoint_chksum(sbi, *cp_block);
|
||||
if (crc != cur_cp_crc(*cp_block)) {
|
||||
f2fs_put_page(*cp_page, 1);
|
||||
f2fs_msg(sbi->sb, KERN_WARNING, "invalid crc value");
|
||||
f2fs_warn(sbi, "invalid crc value");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
|
@ -869,9 +855,8 @@ static struct page *validate_checkpoint(struct f2fs_sb_info *sbi,
|
|||
|
||||
if (le32_to_cpu(cp_block->cp_pack_total_block_count) >
|
||||
sbi->blocks_per_seg) {
|
||||
f2fs_msg(sbi->sb, KERN_WARNING,
|
||||
"invalid cp_pack_total_block_count:%u",
|
||||
le32_to_cpu(cp_block->cp_pack_total_block_count));
|
||||
f2fs_warn(sbi, "invalid cp_pack_total_block_count:%u",
|
||||
le32_to_cpu(cp_block->cp_pack_total_block_count));
|
||||
goto invalid_cp;
|
||||
}
|
||||
pre_version = *version;
|
||||
|
@ -905,6 +890,7 @@ int f2fs_get_valid_checkpoint(struct f2fs_sb_info *sbi)
|
|||
unsigned int cp_blks = 1 + __cp_payload(sbi);
|
||||
block_t cp_blk_no;
|
||||
int i;
|
||||
int err;
|
||||
|
||||
sbi->ckpt = f2fs_kzalloc(sbi, array_size(blk_size, cp_blks),
|
||||
GFP_KERNEL);
|
||||
|
@ -932,6 +918,7 @@ int f2fs_get_valid_checkpoint(struct f2fs_sb_info *sbi)
|
|||
} else if (cp2) {
|
||||
cur_page = cp2;
|
||||
} else {
|
||||
err = -EFSCORRUPTED;
|
||||
goto fail_no_cp;
|
||||
}
|
||||
|
||||
|
@ -944,8 +931,10 @@ int f2fs_get_valid_checkpoint(struct f2fs_sb_info *sbi)
|
|||
sbi->cur_cp_pack = 2;
|
||||
|
||||
/* Sanity checking of checkpoint */
|
||||
if (f2fs_sanity_check_ckpt(sbi))
|
||||
if (f2fs_sanity_check_ckpt(sbi)) {
|
||||
err = -EFSCORRUPTED;
|
||||
goto free_fail_no_cp;
|
||||
}
|
||||
|
||||
if (cp_blks <= 1)
|
||||
goto done;
|
||||
|
@ -959,8 +948,10 @@ int f2fs_get_valid_checkpoint(struct f2fs_sb_info *sbi)
|
|||
unsigned char *ckpt = (unsigned char *)sbi->ckpt;
|
||||
|
||||
cur_page = f2fs_get_meta_page(sbi, cp_blk_no + i);
|
||||
if (IS_ERR(cur_page))
|
||||
if (IS_ERR(cur_page)) {
|
||||
err = PTR_ERR(cur_page);
|
||||
goto free_fail_no_cp;
|
||||
}
|
||||
sit_bitmap_ptr = page_address(cur_page);
|
||||
memcpy(ckpt + i * blk_size, sit_bitmap_ptr, blk_size);
|
||||
f2fs_put_page(cur_page, 1);
|
||||
|
@ -975,7 +966,7 @@ int f2fs_get_valid_checkpoint(struct f2fs_sb_info *sbi)
|
|||
f2fs_put_page(cp2, 1);
|
||||
fail_no_cp:
|
||||
kvfree(sbi->ckpt);
|
||||
return -EINVAL;
|
||||
return err;
|
||||
}
|
||||
|
||||
static void __add_dirty_inode(struct inode *inode, enum inode_type type)
|
||||
|
@ -1142,17 +1133,24 @@ static void __prepare_cp_block(struct f2fs_sb_info *sbi)
|
|||
|
||||
static bool __need_flush_quota(struct f2fs_sb_info *sbi)
|
||||
{
|
||||
bool ret = false;
|
||||
|
||||
if (!is_journalled_quota(sbi))
|
||||
return false;
|
||||
if (is_sbi_flag_set(sbi, SBI_QUOTA_SKIP_FLUSH))
|
||||
return false;
|
||||
if (is_sbi_flag_set(sbi, SBI_QUOTA_NEED_REPAIR))
|
||||
return false;
|
||||
if (is_sbi_flag_set(sbi, SBI_QUOTA_NEED_FLUSH))
|
||||
return true;
|
||||
if (get_pages(sbi, F2FS_DIRTY_QDATA))
|
||||
return true;
|
||||
return false;
|
||||
|
||||
down_write(&sbi->quota_sem);
|
||||
if (is_sbi_flag_set(sbi, SBI_QUOTA_SKIP_FLUSH)) {
|
||||
ret = false;
|
||||
} else if (is_sbi_flag_set(sbi, SBI_QUOTA_NEED_REPAIR)) {
|
||||
ret = false;
|
||||
} else if (is_sbi_flag_set(sbi, SBI_QUOTA_NEED_FLUSH)) {
|
||||
clear_sbi_flag(sbi, SBI_QUOTA_NEED_FLUSH);
|
||||
ret = true;
|
||||
} else if (get_pages(sbi, F2FS_DIRTY_QDATA)) {
|
||||
ret = true;
|
||||
}
|
||||
up_write(&sbi->quota_sem);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -1171,26 +1169,22 @@ static int block_operations(struct f2fs_sb_info *sbi)
|
|||
blk_start_plug(&plug);
|
||||
|
||||
retry_flush_quotas:
|
||||
f2fs_lock_all(sbi);
|
||||
if (__need_flush_quota(sbi)) {
|
||||
int locked;
|
||||
|
||||
if (++cnt > DEFAULT_RETRY_QUOTA_FLUSH_COUNT) {
|
||||
set_sbi_flag(sbi, SBI_QUOTA_SKIP_FLUSH);
|
||||
f2fs_lock_all(sbi);
|
||||
set_sbi_flag(sbi, SBI_QUOTA_NEED_FLUSH);
|
||||
goto retry_flush_dents;
|
||||
}
|
||||
clear_sbi_flag(sbi, SBI_QUOTA_NEED_FLUSH);
|
||||
f2fs_unlock_all(sbi);
|
||||
|
||||
/* only failed during mount/umount/freeze/quotactl */
|
||||
locked = down_read_trylock(&sbi->sb->s_umount);
|
||||
f2fs_quota_sync(sbi->sb, -1);
|
||||
if (locked)
|
||||
up_read(&sbi->sb->s_umount);
|
||||
}
|
||||
|
||||
f2fs_lock_all(sbi);
|
||||
if (__need_flush_quota(sbi)) {
|
||||
f2fs_unlock_all(sbi);
|
||||
cond_resched();
|
||||
goto retry_flush_quotas;
|
||||
}
|
||||
|
@ -1212,12 +1206,6 @@ static int block_operations(struct f2fs_sb_info *sbi)
|
|||
*/
|
||||
down_write(&sbi->node_change);
|
||||
|
||||
if (__need_flush_quota(sbi)) {
|
||||
up_write(&sbi->node_change);
|
||||
f2fs_unlock_all(sbi);
|
||||
goto retry_flush_quotas;
|
||||
}
|
||||
|
||||
if (get_pages(sbi, F2FS_DIRTY_IMETA)) {
|
||||
up_write(&sbi->node_change);
|
||||
f2fs_unlock_all(sbi);
|
||||
|
@ -1313,7 +1301,8 @@ static void update_ckpt_flags(struct f2fs_sb_info *sbi, struct cp_control *cpc)
|
|||
else
|
||||
__clear_ckpt_flags(ckpt, CP_ORPHAN_PRESENT_FLAG);
|
||||
|
||||
if (is_sbi_flag_set(sbi, SBI_NEED_FSCK))
|
||||
if (is_sbi_flag_set(sbi, SBI_NEED_FSCK) ||
|
||||
is_sbi_flag_set(sbi, SBI_IS_RESIZEFS))
|
||||
__set_ckpt_flags(ckpt, CP_FSCK_FLAG);
|
||||
|
||||
if (is_sbi_flag_set(sbi, SBI_CP_DISABLED))
|
||||
|
@ -1569,8 +1558,7 @@ int f2fs_write_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc)
|
|||
if (unlikely(is_sbi_flag_set(sbi, SBI_CP_DISABLED))) {
|
||||
if (cpc->reason != CP_PAUSE)
|
||||
return 0;
|
||||
f2fs_msg(sbi->sb, KERN_WARNING,
|
||||
"Start checkpoint disabled!");
|
||||
f2fs_warn(sbi, "Start checkpoint disabled!");
|
||||
}
|
||||
mutex_lock(&sbi->cp_mutex);
|
||||
|
||||
|
@ -1636,8 +1624,7 @@ int f2fs_write_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc)
|
|||
stat_inc_cp_count(sbi->stat_info);
|
||||
|
||||
if (cpc->reason & CP_RECOVERY)
|
||||
f2fs_msg(sbi->sb, KERN_NOTICE,
|
||||
"checkpoint: version = %llx", ckpt_ver);
|
||||
f2fs_notice(sbi, "checkpoint: version = %llx", ckpt_ver);
|
||||
|
||||
/* do checkpoint periodically */
|
||||
f2fs_update_time(sbi, CP_TIME);
|
||||
|
|
249
fs/f2fs/data.c
249
fs/f2fs/data.c
|
@ -14,6 +14,7 @@
|
|||
#include <linux/pagevec.h>
|
||||
#include <linux/blkdev.h>
|
||||
#include <linux/bio.h>
|
||||
#include <linux/swap.h>
|
||||
#include <linux/prefetch.h>
|
||||
#include <linux/uio.h>
|
||||
#include <linux/cleancache.h>
|
||||
|
@ -55,7 +56,7 @@ static bool __is_cp_guaranteed(struct page *page)
|
|||
|
||||
static enum count_type __read_io_type(struct page *page)
|
||||
{
|
||||
struct address_space *mapping = page->mapping;
|
||||
struct address_space *mapping = page_file_mapping(page);
|
||||
|
||||
if (mapping) {
|
||||
struct inode *inode = mapping->host;
|
||||
|
@ -383,20 +384,20 @@ static void __submit_merged_bio(struct f2fs_bio_info *io)
|
|||
io->bio = NULL;
|
||||
}
|
||||
|
||||
static bool __has_merged_page(struct f2fs_bio_info *io, struct inode *inode,
|
||||
static bool __has_merged_page(struct bio *bio, struct inode *inode,
|
||||
struct page *page, nid_t ino)
|
||||
{
|
||||
struct bio_vec *bvec;
|
||||
struct page *target;
|
||||
int i;
|
||||
|
||||
if (!io->bio)
|
||||
if (!bio)
|
||||
return false;
|
||||
|
||||
if (!inode && !page && !ino)
|
||||
return true;
|
||||
|
||||
bio_for_each_segment_all(bvec, io->bio, i) {
|
||||
bio_for_each_segment_all(bvec, bio, i) {
|
||||
|
||||
if (bvec->bv_page->mapping)
|
||||
target = bvec->bv_page;
|
||||
|
@ -447,7 +448,7 @@ static void __submit_merged_write_cond(struct f2fs_sb_info *sbi,
|
|||
struct f2fs_bio_info *io = sbi->write_io[btype] + temp;
|
||||
|
||||
down_read(&io->io_rwsem);
|
||||
ret = __has_merged_page(io, inode, page, ino);
|
||||
ret = __has_merged_page(io->bio, inode, page, ino);
|
||||
up_read(&io->io_rwsem);
|
||||
}
|
||||
if (ret)
|
||||
|
@ -491,7 +492,7 @@ int f2fs_submit_page_bio(struct f2fs_io_info *fio)
|
|||
if (!f2fs_is_valid_blkaddr(fio->sbi, fio->new_blkaddr,
|
||||
fio->is_por ? META_POR : (__is_meta_io(fio) ?
|
||||
META_GENERIC : DATA_GENERIC_ENHANCE)))
|
||||
return -EFAULT;
|
||||
return -EFSCORRUPTED;
|
||||
|
||||
trace_f2fs_submit_page_bio(page, fio);
|
||||
f2fs_trace_ios(fio, 0);
|
||||
|
@ -520,6 +521,61 @@ int f2fs_submit_page_bio(struct f2fs_io_info *fio)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int f2fs_merge_page_bio(struct f2fs_io_info *fio)
|
||||
{
|
||||
struct bio *bio = *fio->bio;
|
||||
struct page *page = fio->encrypted_page ?
|
||||
fio->encrypted_page : fio->page;
|
||||
|
||||
if (!f2fs_is_valid_blkaddr(fio->sbi, fio->new_blkaddr,
|
||||
__is_meta_io(fio) ? META_GENERIC : DATA_GENERIC))
|
||||
return -EFSCORRUPTED;
|
||||
|
||||
trace_f2fs_submit_page_bio(page, fio);
|
||||
f2fs_trace_ios(fio, 0);
|
||||
|
||||
if (bio && (*fio->last_block + 1 != fio->new_blkaddr ||
|
||||
!__same_bdev(fio->sbi, fio->new_blkaddr, bio))) {
|
||||
__submit_bio(fio->sbi, bio, fio->type);
|
||||
bio = NULL;
|
||||
}
|
||||
alloc_new:
|
||||
if (!bio) {
|
||||
bio = __bio_alloc(fio->sbi, fio->new_blkaddr, fio->io_wbc,
|
||||
BIO_MAX_PAGES, false, fio->type, fio->temp);
|
||||
bio_set_op_attrs(bio, fio->op, fio->op_flags);
|
||||
}
|
||||
|
||||
if (bio_add_page(bio, page, PAGE_SIZE, 0) < PAGE_SIZE) {
|
||||
__submit_bio(fio->sbi, bio, fio->type);
|
||||
bio = NULL;
|
||||
goto alloc_new;
|
||||
}
|
||||
|
||||
if (fio->io_wbc)
|
||||
wbc_account_io(fio->io_wbc, page, PAGE_SIZE);
|
||||
|
||||
inc_page_count(fio->sbi, WB_DATA_TYPE(page));
|
||||
|
||||
*fio->last_block = fio->new_blkaddr;
|
||||
*fio->bio = bio;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void f2fs_submit_ipu_bio(struct f2fs_sb_info *sbi, struct bio **bio,
|
||||
struct page *page)
|
||||
{
|
||||
if (!bio)
|
||||
return;
|
||||
|
||||
if (!__has_merged_page(*bio, NULL, page, 0))
|
||||
return;
|
||||
|
||||
__submit_bio(sbi, *bio, DATA);
|
||||
*bio = NULL;
|
||||
}
|
||||
|
||||
void f2fs_submit_page_write(struct f2fs_io_info *fio)
|
||||
{
|
||||
struct f2fs_sb_info *sbi = fio->sbi;
|
||||
|
@ -773,7 +829,7 @@ struct page *f2fs_get_read_data_page(struct inode *inode, pgoff_t index,
|
|||
dn.data_blkaddr = ei.blk + index - ei.fofs;
|
||||
if (!f2fs_is_valid_blkaddr(F2FS_I_SB(inode), dn.data_blkaddr,
|
||||
DATA_GENERIC_ENHANCE_READ)) {
|
||||
err = -EFAULT;
|
||||
err = -EFSCORRUPTED;
|
||||
goto put_err;
|
||||
}
|
||||
goto got_it;
|
||||
|
@ -793,7 +849,7 @@ struct page *f2fs_get_read_data_page(struct inode *inode, pgoff_t index,
|
|||
!f2fs_is_valid_blkaddr(F2FS_I_SB(inode),
|
||||
dn.data_blkaddr,
|
||||
DATA_GENERIC_ENHANCE)) {
|
||||
err = -EFAULT;
|
||||
err = -EFSCORRUPTED;
|
||||
goto put_err;
|
||||
}
|
||||
got_it:
|
||||
|
@ -1139,7 +1195,7 @@ int f2fs_map_blocks(struct inode *inode, struct f2fs_map_blocks *map,
|
|||
|
||||
if (__is_valid_data_blkaddr(blkaddr) &&
|
||||
!f2fs_is_valid_blkaddr(sbi, blkaddr, DATA_GENERIC_ENHANCE)) {
|
||||
err = -EFAULT;
|
||||
err = -EFSCORRUPTED;
|
||||
goto sync_out;
|
||||
}
|
||||
|
||||
|
@ -1569,7 +1625,7 @@ static int f2fs_read_single_page(struct inode *inode, struct page *page,
|
|||
sector_t block_nr;
|
||||
int ret = 0;
|
||||
|
||||
block_in_file = (sector_t)page->index;
|
||||
block_in_file = (sector_t)page_index(page);
|
||||
last_block = block_in_file + nr_pages;
|
||||
last_block_in_file = (i_size_read(inode) + blocksize - 1) >>
|
||||
blkbits;
|
||||
|
@ -1602,14 +1658,15 @@ static int f2fs_read_single_page(struct inode *inode, struct page *page,
|
|||
block_nr = map->m_pblk + block_in_file - map->m_lblk;
|
||||
SetPageMappedToDisk(page);
|
||||
|
||||
if (!PageUptodate(page) && !cleancache_get_page(page)) {
|
||||
if (!PageUptodate(page) && (!PageSwapCache(page) &&
|
||||
!cleancache_get_page(page))) {
|
||||
SetPageUptodate(page);
|
||||
goto confused;
|
||||
}
|
||||
|
||||
if (!f2fs_is_valid_blkaddr(F2FS_I_SB(inode), block_nr,
|
||||
DATA_GENERIC_ENHANCE_READ)) {
|
||||
ret = -EFAULT;
|
||||
ret = -EFSCORRUPTED;
|
||||
goto out;
|
||||
}
|
||||
} else {
|
||||
|
@ -1700,7 +1757,7 @@ static int f2fs_mpage_readpages(struct address_space *mapping,
|
|||
prefetchw(&page->flags);
|
||||
list_del(&page->lru);
|
||||
if (add_to_page_cache_lru(page, mapping,
|
||||
page->index,
|
||||
page_index(page),
|
||||
readahead_gfp_mask(mapping)))
|
||||
goto next_page;
|
||||
}
|
||||
|
@ -1724,7 +1781,7 @@ static int f2fs_mpage_readpages(struct address_space *mapping,
|
|||
|
||||
static int f2fs_read_data_page(struct file *file, struct page *page)
|
||||
{
|
||||
struct inode *inode = page->mapping->host;
|
||||
struct inode *inode = page_file_mapping(page)->host;
|
||||
int ret = -EAGAIN;
|
||||
|
||||
trace_f2fs_readpage(page, DATA);
|
||||
|
@ -1733,7 +1790,8 @@ static int f2fs_read_data_page(struct file *file, struct page *page)
|
|||
if (f2fs_has_inline_data(inode))
|
||||
ret = f2fs_read_inline_data(inode, page);
|
||||
if (ret == -EAGAIN)
|
||||
ret = f2fs_mpage_readpages(page->mapping, NULL, page, 1, false);
|
||||
ret = f2fs_mpage_readpages(page_file_mapping(page),
|
||||
NULL, page, 1, false);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -1890,7 +1948,7 @@ int f2fs_do_write_data_page(struct f2fs_io_info *fio)
|
|||
|
||||
if (!f2fs_is_valid_blkaddr(fio->sbi, fio->old_blkaddr,
|
||||
DATA_GENERIC_ENHANCE))
|
||||
return -EFAULT;
|
||||
return -EFSCORRUPTED;
|
||||
|
||||
ipu_force = true;
|
||||
fio->need_lock = LOCK_DONE;
|
||||
|
@ -1917,7 +1975,7 @@ int f2fs_do_write_data_page(struct f2fs_io_info *fio)
|
|||
if (__is_valid_data_blkaddr(fio->old_blkaddr) &&
|
||||
!f2fs_is_valid_blkaddr(fio->sbi, fio->old_blkaddr,
|
||||
DATA_GENERIC_ENHANCE)) {
|
||||
err = -EFAULT;
|
||||
err = -EFSCORRUPTED;
|
||||
goto out_writepage;
|
||||
}
|
||||
/*
|
||||
|
@ -1986,6 +2044,8 @@ int f2fs_do_write_data_page(struct f2fs_io_info *fio)
|
|||
}
|
||||
|
||||
static int __write_data_page(struct page *page, bool *submitted,
|
||||
struct bio **bio,
|
||||
sector_t *last_block,
|
||||
struct writeback_control *wbc,
|
||||
enum iostat_type io_type)
|
||||
{
|
||||
|
@ -2011,6 +2071,8 @@ static int __write_data_page(struct page *page, bool *submitted,
|
|||
.need_lock = LOCK_RETRY,
|
||||
.io_type = io_type,
|
||||
.io_wbc = wbc,
|
||||
.bio = bio,
|
||||
.last_block = last_block,
|
||||
};
|
||||
|
||||
trace_f2fs_writepage(page, DATA);
|
||||
|
@ -2109,10 +2171,13 @@ static int __write_data_page(struct page *page, bool *submitted,
|
|||
|
||||
unlock_page(page);
|
||||
if (!S_ISDIR(inode->i_mode) && !IS_NOQUOTA(inode) &&
|
||||
!F2FS_I(inode)->cp_task)
|
||||
!F2FS_I(inode)->cp_task) {
|
||||
f2fs_submit_ipu_bio(sbi, bio, page);
|
||||
f2fs_balance_fs(sbi, need_balance_fs);
|
||||
}
|
||||
|
||||
if (unlikely(f2fs_cp_error(sbi))) {
|
||||
f2fs_submit_ipu_bio(sbi, bio, page);
|
||||
f2fs_submit_merged_write(sbi, DATA);
|
||||
submitted = NULL;
|
||||
}
|
||||
|
@ -2139,7 +2204,7 @@ static int __write_data_page(struct page *page, bool *submitted,
|
|||
static int f2fs_write_data_page(struct page *page,
|
||||
struct writeback_control *wbc)
|
||||
{
|
||||
return __write_data_page(page, NULL, wbc, FS_DATA_IO);
|
||||
return __write_data_page(page, NULL, NULL, NULL, wbc, FS_DATA_IO);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -2155,6 +2220,8 @@ static int f2fs_write_cache_pages(struct address_space *mapping,
|
|||
int done = 0;
|
||||
struct pagevec pvec;
|
||||
struct f2fs_sb_info *sbi = F2FS_M_SB(mapping);
|
||||
struct bio *bio = NULL;
|
||||
sector_t last_block;
|
||||
int nr_pages;
|
||||
pgoff_t uninitialized_var(writeback_index);
|
||||
pgoff_t index;
|
||||
|
@ -2231,17 +2298,20 @@ static int f2fs_write_cache_pages(struct address_space *mapping,
|
|||
}
|
||||
|
||||
if (PageWriteback(page)) {
|
||||
if (wbc->sync_mode != WB_SYNC_NONE)
|
||||
if (wbc->sync_mode != WB_SYNC_NONE) {
|
||||
f2fs_wait_on_page_writeback(page,
|
||||
DATA, true, true);
|
||||
else
|
||||
f2fs_submit_ipu_bio(sbi, &bio, page);
|
||||
} else {
|
||||
goto continue_unlock;
|
||||
}
|
||||
}
|
||||
|
||||
if (!clear_page_dirty_for_io(page))
|
||||
goto continue_unlock;
|
||||
|
||||
ret = __write_data_page(page, &submitted, wbc, io_type);
|
||||
ret = __write_data_page(page, &submitted, &bio,
|
||||
&last_block, wbc, io_type);
|
||||
if (unlikely(ret)) {
|
||||
/*
|
||||
* keep nr_to_write, since vfs uses this to
|
||||
|
@ -2290,6 +2360,9 @@ static int f2fs_write_cache_pages(struct address_space *mapping,
|
|||
if (nwritten)
|
||||
f2fs_submit_merged_write_cond(F2FS_M_SB(mapping), mapping->host,
|
||||
NULL, 0, DATA);
|
||||
/* submit cached bio of IPU write */
|
||||
if (bio)
|
||||
__submit_bio(sbi, bio, DATA);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
@ -2301,6 +2374,9 @@ static inline bool __should_serialize_io(struct inode *inode,
|
|||
return false;
|
||||
if (IS_NOQUOTA(inode))
|
||||
return false;
|
||||
/* to avoid deadlock in path of data flush */
|
||||
if (F2FS_I(inode)->cp_task)
|
||||
return false;
|
||||
if (wbc->sync_mode != WB_SYNC_ALL)
|
||||
return true;
|
||||
if (get_dirty_pages(inode) >= SM_I(F2FS_I_SB(inode))->min_seq_blocks)
|
||||
|
@ -2582,7 +2658,7 @@ static int f2fs_write_begin(struct file *file, struct address_space *mapping,
|
|||
} else {
|
||||
if (!f2fs_is_valid_blkaddr(sbi, blkaddr,
|
||||
DATA_GENERIC_ENHANCE_READ)) {
|
||||
err = -EFAULT;
|
||||
err = -EFSCORRUPTED;
|
||||
goto fail;
|
||||
}
|
||||
err = f2fs_submit_page_read(inode, page, blkaddr);
|
||||
|
@ -2858,13 +2934,14 @@ int f2fs_release_page(struct page *page, gfp_t wait)
|
|||
|
||||
static int f2fs_set_data_page_dirty(struct page *page)
|
||||
{
|
||||
struct address_space *mapping = page->mapping;
|
||||
struct inode *inode = mapping->host;
|
||||
struct inode *inode = page_file_mapping(page)->host;
|
||||
|
||||
trace_f2fs_set_page_dirty(page, DATA);
|
||||
|
||||
if (!PageUptodate(page))
|
||||
SetPageUptodate(page);
|
||||
if (PageSwapCache(page))
|
||||
return __set_page_dirty_nobuffers(page);
|
||||
|
||||
if (f2fs_is_atomic_file(inode) && !f2fs_is_commit_atomic_write(inode)) {
|
||||
if (!IS_ATOMIC_WRITTEN_PAGE(page)) {
|
||||
|
@ -2956,6 +3033,126 @@ int f2fs_migrate_page(struct address_space *mapping,
|
|||
}
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_SWAP
|
||||
/* Copied from generic_swapfile_activate() to check any holes */
|
||||
static int check_swap_activate(struct file *swap_file, unsigned int max)
|
||||
{
|
||||
struct address_space *mapping = swap_file->f_mapping;
|
||||
struct inode *inode = mapping->host;
|
||||
unsigned blocks_per_page;
|
||||
unsigned long page_no;
|
||||
unsigned blkbits;
|
||||
sector_t probe_block;
|
||||
sector_t last_block;
|
||||
sector_t lowest_block = -1;
|
||||
sector_t highest_block = 0;
|
||||
|
||||
blkbits = inode->i_blkbits;
|
||||
blocks_per_page = PAGE_SIZE >> blkbits;
|
||||
|
||||
/*
|
||||
* Map all the blocks into the extent list. This code doesn't try
|
||||
* to be very smart.
|
||||
*/
|
||||
probe_block = 0;
|
||||
page_no = 0;
|
||||
last_block = i_size_read(inode) >> blkbits;
|
||||
while ((probe_block + blocks_per_page) <= last_block && page_no < max) {
|
||||
unsigned block_in_page;
|
||||
sector_t first_block;
|
||||
|
||||
cond_resched();
|
||||
|
||||
first_block = bmap(inode, probe_block);
|
||||
if (first_block == 0)
|
||||
goto bad_bmap;
|
||||
|
||||
/*
|
||||
* It must be PAGE_SIZE aligned on-disk
|
||||
*/
|
||||
if (first_block & (blocks_per_page - 1)) {
|
||||
probe_block++;
|
||||
goto reprobe;
|
||||
}
|
||||
|
||||
for (block_in_page = 1; block_in_page < blocks_per_page;
|
||||
block_in_page++) {
|
||||
sector_t block;
|
||||
|
||||
block = bmap(inode, probe_block + block_in_page);
|
||||
if (block == 0)
|
||||
goto bad_bmap;
|
||||
if (block != first_block + block_in_page) {
|
||||
/* Discontiguity */
|
||||
probe_block++;
|
||||
goto reprobe;
|
||||
}
|
||||
}
|
||||
|
||||
first_block >>= (PAGE_SHIFT - blkbits);
|
||||
if (page_no) { /* exclude the header page */
|
||||
if (first_block < lowest_block)
|
||||
lowest_block = first_block;
|
||||
if (first_block > highest_block)
|
||||
highest_block = first_block;
|
||||
}
|
||||
|
||||
page_no++;
|
||||
probe_block += blocks_per_page;
|
||||
reprobe:
|
||||
continue;
|
||||
}
|
||||
return 0;
|
||||
|
||||
bad_bmap:
|
||||
pr_err("swapon: swapfile has holes\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
static int f2fs_swap_activate(struct swap_info_struct *sis, struct file *file,
|
||||
sector_t *span)
|
||||
{
|
||||
struct inode *inode = file_inode(file);
|
||||
int ret;
|
||||
|
||||
if (!S_ISREG(inode->i_mode))
|
||||
return -EINVAL;
|
||||
|
||||
if (f2fs_readonly(F2FS_I_SB(inode)->sb))
|
||||
return -EROFS;
|
||||
|
||||
ret = f2fs_convert_inline_inode(inode);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
ret = check_swap_activate(file, sis->max);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
set_inode_flag(inode, FI_PIN_FILE);
|
||||
f2fs_precache_extents(inode);
|
||||
f2fs_update_time(F2FS_I_SB(inode), REQ_TIME);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void f2fs_swap_deactivate(struct file *file)
|
||||
{
|
||||
struct inode *inode = file_inode(file);
|
||||
|
||||
clear_inode_flag(inode, FI_PIN_FILE);
|
||||
}
|
||||
#else
|
||||
static int f2fs_swap_activate(struct swap_info_struct *sis, struct file *file,
|
||||
sector_t *span)
|
||||
{
|
||||
return -EOPNOTSUPP;
|
||||
}
|
||||
|
||||
static void f2fs_swap_deactivate(struct file *file)
|
||||
{
|
||||
}
|
||||
#endif
|
||||
|
||||
const struct address_space_operations f2fs_dblock_aops = {
|
||||
.readpage = f2fs_read_data_page,
|
||||
.readpages = f2fs_read_data_pages,
|
||||
|
@ -2968,6 +3165,8 @@ const struct address_space_operations f2fs_dblock_aops = {
|
|||
.releasepage = f2fs_release_page,
|
||||
.direct_IO = f2fs_direct_IO,
|
||||
.bmap = f2fs_bmap,
|
||||
.swap_activate = f2fs_swap_activate,
|
||||
.swap_deactivate = f2fs_swap_deactivate,
|
||||
#ifdef CONFIG_MIGRATION
|
||||
.migratepage = f2fs_migrate_page,
|
||||
#endif
|
||||
|
|
|
@ -27,8 +27,15 @@ static DEFINE_MUTEX(f2fs_stat_mutex);
|
|||
static void update_general_status(struct f2fs_sb_info *sbi)
|
||||
{
|
||||
struct f2fs_stat_info *si = F2FS_STAT(sbi);
|
||||
struct f2fs_super_block *raw_super = F2FS_RAW_SUPER(sbi);
|
||||
int i;
|
||||
|
||||
/* these will be changed if online resize is done */
|
||||
si->main_area_segs = le32_to_cpu(raw_super->segment_count_main);
|
||||
si->main_area_sections = le32_to_cpu(raw_super->section_count);
|
||||
si->main_area_zones = si->main_area_sections /
|
||||
le32_to_cpu(raw_super->secs_per_zone);
|
||||
|
||||
/* validation check of the segment numbers */
|
||||
si->hit_largest = atomic64_read(&sbi->read_hit_largest);
|
||||
si->hit_cached = atomic64_read(&sbi->read_hit_cached);
|
||||
|
|
|
@ -218,9 +218,8 @@ struct f2fs_dir_entry *__f2fs_find_entry(struct inode *dir,
|
|||
|
||||
max_depth = F2FS_I(dir)->i_current_depth;
|
||||
if (unlikely(max_depth > MAX_DIR_HASH_DEPTH)) {
|
||||
f2fs_msg(F2FS_I_SB(dir)->sb, KERN_WARNING,
|
||||
"Corrupted max_depth of %lu: %u",
|
||||
dir->i_ino, max_depth);
|
||||
f2fs_warn(F2FS_I_SB(dir), "Corrupted max_depth of %lu: %u",
|
||||
dir->i_ino, max_depth);
|
||||
max_depth = MAX_DIR_HASH_DEPTH;
|
||||
f2fs_i_depth_write(dir, max_depth);
|
||||
}
|
||||
|
@ -816,11 +815,10 @@ int f2fs_fill_dentries(struct dir_context *ctx, struct f2fs_dentry_ptr *d,
|
|||
bit_pos += GET_DENTRY_SLOTS(le16_to_cpu(de->name_len));
|
||||
if (unlikely(bit_pos > d->max ||
|
||||
le16_to_cpu(de->name_len) > F2FS_NAME_LEN)) {
|
||||
f2fs_msg(sbi->sb, KERN_WARNING,
|
||||
"%s: corrupted namelen=%d, run fsck to fix.",
|
||||
__func__, le16_to_cpu(de->name_len));
|
||||
f2fs_warn(sbi, "%s: corrupted namelen=%d, run fsck to fix.",
|
||||
__func__, le16_to_cpu(de->name_len));
|
||||
set_sbi_flag(sbi, SBI_NEED_FSCK);
|
||||
err = -EINVAL;
|
||||
err = -EFSCORRUPTED;
|
||||
goto out;
|
||||
}
|
||||
|
||||
|
@ -828,8 +826,8 @@ int f2fs_fill_dentries(struct dir_context *ctx, struct f2fs_dentry_ptr *d,
|
|||
int save_len = fstr->len;
|
||||
|
||||
err = fscrypt_fname_disk_to_usr(d->inode,
|
||||
(u32)de->hash_code, 0,
|
||||
&de_name, fstr);
|
||||
(u32)le32_to_cpu(de->hash_code),
|
||||
0, &de_name, fstr);
|
||||
if (err)
|
||||
goto out;
|
||||
|
||||
|
|
|
@ -184,10 +184,9 @@ bool f2fs_check_rb_tree_consistence(struct f2fs_sb_info *sbi,
|
|||
next_re = rb_entry(next, struct rb_entry, rb_node);
|
||||
|
||||
if (cur_re->ofs + cur_re->len > next_re->ofs) {
|
||||
f2fs_msg(sbi->sb, KERN_INFO, "inconsistent rbtree, "
|
||||
"cur(%u, %u) next(%u, %u)",
|
||||
cur_re->ofs, cur_re->len,
|
||||
next_re->ofs, next_re->len);
|
||||
f2fs_info(sbi, "inconsistent rbtree, cur(%u, %u) next(%u, %u)",
|
||||
cur_re->ofs, cur_re->len,
|
||||
next_re->ofs, next_re->len);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
129
fs/f2fs/f2fs.h
129
fs/f2fs/f2fs.h
|
@ -136,6 +136,9 @@ struct f2fs_mount_info {
|
|||
int alloc_mode; /* segment allocation policy */
|
||||
int fsync_mode; /* fsync policy */
|
||||
bool test_dummy_encryption; /* test dummy encryption */
|
||||
block_t unusable_cap; /* Amount of space allowed to be
|
||||
* unusable when disabling checkpoint
|
||||
*/
|
||||
};
|
||||
|
||||
#define F2FS_FEATURE_ENCRYPT 0x0001
|
||||
|
@ -412,6 +415,7 @@ static inline bool __has_cursum_space(struct f2fs_journal *journal,
|
|||
#define F2FS_IOC_SET_PIN_FILE _IOW(F2FS_IOCTL_MAGIC, 13, __u32)
|
||||
#define F2FS_IOC_GET_PIN_FILE _IOR(F2FS_IOCTL_MAGIC, 14, __u32)
|
||||
#define F2FS_IOC_PRECACHE_EXTENTS _IO(F2FS_IOCTL_MAGIC, 15)
|
||||
#define F2FS_IOC_RESIZE_FS _IOW(F2FS_IOCTL_MAGIC, 16, __u64)
|
||||
|
||||
#define F2FS_IOC_SET_ENCRYPTION_POLICY FS_IOC_SET_ENCRYPTION_POLICY
|
||||
#define F2FS_IOC_GET_ENCRYPTION_POLICY FS_IOC_GET_ENCRYPTION_POLICY
|
||||
|
@ -476,8 +480,8 @@ static inline int get_inline_xattr_addrs(struct inode *inode);
|
|||
#define NR_INLINE_DENTRY(inode) (MAX_INLINE_DATA(inode) * BITS_PER_BYTE / \
|
||||
((SIZE_OF_DIR_ENTRY + F2FS_SLOT_LEN) * \
|
||||
BITS_PER_BYTE + 1))
|
||||
#define INLINE_DENTRY_BITMAP_SIZE(inode) ((NR_INLINE_DENTRY(inode) + \
|
||||
BITS_PER_BYTE - 1) / BITS_PER_BYTE)
|
||||
#define INLINE_DENTRY_BITMAP_SIZE(inode) \
|
||||
DIV_ROUND_UP(NR_INLINE_DENTRY(inode), BITS_PER_BYTE)
|
||||
#define INLINE_RESERVED_SIZE(inode) (MAX_INLINE_DATA(inode) - \
|
||||
((SIZE_OF_DIR_ENTRY + F2FS_SLOT_LEN) * \
|
||||
NR_INLINE_DENTRY(inode) + \
|
||||
|
@ -1052,6 +1056,8 @@ struct f2fs_io_info {
|
|||
bool retry; /* need to reallocate block address */
|
||||
enum iostat_type io_type; /* io type */
|
||||
struct writeback_control *io_wbc; /* writeback control */
|
||||
struct bio **bio; /* bio for ipu */
|
||||
sector_t *last_block; /* last block number in bio */
|
||||
unsigned char version; /* version of the node */
|
||||
};
|
||||
|
||||
|
@ -1111,6 +1117,7 @@ enum {
|
|||
SBI_QUOTA_NEED_FLUSH, /* need to flush quota info in CP */
|
||||
SBI_QUOTA_SKIP_FLUSH, /* skip flushing quota in current CP */
|
||||
SBI_QUOTA_NEED_REPAIR, /* quota file may be corrupted */
|
||||
SBI_IS_RESIZEFS, /* resizefs is in process */
|
||||
};
|
||||
|
||||
enum {
|
||||
|
@ -1207,6 +1214,7 @@ struct f2fs_sb_info {
|
|||
/* for inode management */
|
||||
struct list_head inode_list[NR_INODE_TYPE]; /* dirty inode list */
|
||||
spinlock_t inode_lock[NR_INODE_TYPE]; /* for dirty inode list lock */
|
||||
struct mutex flush_lock; /* for flush exclusion */
|
||||
|
||||
/* for extent tree cache */
|
||||
struct radix_tree_root extent_tree_root;/* cache extent cache entries */
|
||||
|
@ -1230,6 +1238,7 @@ struct f2fs_sb_info {
|
|||
unsigned int segs_per_sec; /* segments per section */
|
||||
unsigned int secs_per_zone; /* sections per zone */
|
||||
unsigned int total_sections; /* total section count */
|
||||
struct mutex resize_mutex; /* for resize exclusion */
|
||||
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 */
|
||||
|
@ -1247,6 +1256,7 @@ struct f2fs_sb_info {
|
|||
block_t unusable_block_count; /* # of blocks saved by last cp */
|
||||
|
||||
unsigned int nquota_files; /* # of quota sysfile */
|
||||
struct rw_semaphore quota_sem; /* blocking cp for flags */
|
||||
|
||||
/* # of pages, see count_type */
|
||||
atomic_t nr_pages[NR_COUNT_TYPE];
|
||||
|
@ -1489,7 +1499,7 @@ static inline struct f2fs_sb_info *F2FS_M_SB(struct address_space *mapping)
|
|||
|
||||
static inline struct f2fs_sb_info *F2FS_P_SB(struct page *page)
|
||||
{
|
||||
return F2FS_M_SB(page->mapping);
|
||||
return F2FS_M_SB(page_file_mapping(page));
|
||||
}
|
||||
|
||||
static inline struct f2fs_super_block *F2FS_RAW_SUPER(struct f2fs_sb_info *sbi)
|
||||
|
@ -1767,8 +1777,12 @@ static inline int inc_valid_block_count(struct f2fs_sb_info *sbi,
|
|||
|
||||
if (!__allow_reserved_blocks(sbi, inode, true))
|
||||
avail_user_block_count -= F2FS_OPTION(sbi).root_reserved_blocks;
|
||||
if (unlikely(is_sbi_flag_set(sbi, SBI_CP_DISABLED)))
|
||||
avail_user_block_count -= sbi->unusable_block_count;
|
||||
if (unlikely(is_sbi_flag_set(sbi, SBI_CP_DISABLED))) {
|
||||
if (avail_user_block_count > sbi->unusable_block_count)
|
||||
avail_user_block_count -= sbi->unusable_block_count;
|
||||
else
|
||||
avail_user_block_count = 0;
|
||||
}
|
||||
if (unlikely(sbi->total_valid_block_count > avail_user_block_count)) {
|
||||
diff = sbi->total_valid_block_count - avail_user_block_count;
|
||||
if (diff > *count)
|
||||
|
@ -1796,7 +1810,20 @@ static inline int inc_valid_block_count(struct f2fs_sb_info *sbi,
|
|||
return -ENOSPC;
|
||||
}
|
||||
|
||||
void f2fs_msg(struct super_block *sb, const char *level, const char *fmt, ...);
|
||||
__printf(2, 3)
|
||||
void f2fs_printk(struct f2fs_sb_info *sbi, const char *fmt, ...);
|
||||
|
||||
#define f2fs_err(sbi, fmt, ...) \
|
||||
f2fs_printk(sbi, KERN_ERR fmt, ##__VA_ARGS__)
|
||||
#define f2fs_warn(sbi, fmt, ...) \
|
||||
f2fs_printk(sbi, KERN_WARNING fmt, ##__VA_ARGS__)
|
||||
#define f2fs_notice(sbi, fmt, ...) \
|
||||
f2fs_printk(sbi, KERN_NOTICE fmt, ##__VA_ARGS__)
|
||||
#define f2fs_info(sbi, fmt, ...) \
|
||||
f2fs_printk(sbi, KERN_INFO fmt, ##__VA_ARGS__)
|
||||
#define f2fs_debug(sbi, fmt, ...) \
|
||||
f2fs_printk(sbi, KERN_DEBUG fmt, ##__VA_ARGS__)
|
||||
|
||||
static inline void dec_valid_block_count(struct f2fs_sb_info *sbi,
|
||||
struct inode *inode,
|
||||
block_t count)
|
||||
|
@ -1812,11 +1839,10 @@ static inline void dec_valid_block_count(struct f2fs_sb_info *sbi,
|
|||
sbi->current_reserved_blocks + count);
|
||||
spin_unlock(&sbi->stat_lock);
|
||||
if (unlikely(inode->i_blocks < sectors)) {
|
||||
f2fs_msg(sbi->sb, KERN_WARNING,
|
||||
"Inconsistent i_blocks, ino:%lu, iblocks:%llu, sectors:%llu",
|
||||
inode->i_ino,
|
||||
(unsigned long long)inode->i_blocks,
|
||||
(unsigned long long)sectors);
|
||||
f2fs_warn(sbi, "Inconsistent i_blocks, ino:%lu, iblocks:%llu, sectors:%llu",
|
||||
inode->i_ino,
|
||||
(unsigned long long)inode->i_blocks,
|
||||
(unsigned long long)sectors);
|
||||
set_sbi_flag(sbi, SBI_NEED_FSCK);
|
||||
return;
|
||||
}
|
||||
|
@ -1968,7 +1994,7 @@ static inline int inc_valid_node_count(struct f2fs_sb_info *sbi,
|
|||
struct inode *inode, bool is_inode)
|
||||
{
|
||||
block_t valid_block_count;
|
||||
unsigned int valid_node_count;
|
||||
unsigned int valid_node_count, user_block_count;
|
||||
int err;
|
||||
|
||||
if (is_inode) {
|
||||
|
@ -1995,10 +2021,11 @@ static inline int inc_valid_node_count(struct f2fs_sb_info *sbi,
|
|||
|
||||
if (!__allow_reserved_blocks(sbi, inode, false))
|
||||
valid_block_count += F2FS_OPTION(sbi).root_reserved_blocks;
|
||||
user_block_count = sbi->user_block_count;
|
||||
if (unlikely(is_sbi_flag_set(sbi, SBI_CP_DISABLED)))
|
||||
valid_block_count += sbi->unusable_block_count;
|
||||
user_block_count -= sbi->unusable_block_count;
|
||||
|
||||
if (unlikely(valid_block_count > sbi->user_block_count)) {
|
||||
if (unlikely(valid_block_count > user_block_count)) {
|
||||
spin_unlock(&sbi->stat_lock);
|
||||
goto enospc;
|
||||
}
|
||||
|
@ -2053,10 +2080,9 @@ static inline void dec_valid_node_count(struct f2fs_sb_info *sbi,
|
|||
dquot_free_inode(inode);
|
||||
} else {
|
||||
if (unlikely(inode->i_blocks == 0)) {
|
||||
f2fs_msg(sbi->sb, KERN_WARNING,
|
||||
"Inconsistent i_blocks, ino:%lu, iblocks:%llu",
|
||||
inode->i_ino,
|
||||
(unsigned long long)inode->i_blocks);
|
||||
f2fs_warn(sbi, "Inconsistent i_blocks, ino:%lu, iblocks:%llu",
|
||||
inode->i_ino,
|
||||
(unsigned long long)inode->i_blocks);
|
||||
set_sbi_flag(sbi, SBI_NEED_FSCK);
|
||||
return;
|
||||
}
|
||||
|
@ -2192,6 +2218,9 @@ static inline struct bio *f2fs_bio_alloc(struct f2fs_sb_info *sbi,
|
|||
|
||||
static inline bool is_idle(struct f2fs_sb_info *sbi, int type)
|
||||
{
|
||||
if (sbi->gc_mode == GC_URGENT)
|
||||
return true;
|
||||
|
||||
if (get_pages(sbi, F2FS_RD_DATA) || get_pages(sbi, F2FS_RD_NODE) ||
|
||||
get_pages(sbi, F2FS_RD_META) || get_pages(sbi, F2FS_WB_DATA) ||
|
||||
get_pages(sbi, F2FS_WB_CP_DATA) ||
|
||||
|
@ -2199,7 +2228,7 @@ static inline bool is_idle(struct f2fs_sb_info *sbi, int type)
|
|||
get_pages(sbi, F2FS_DIO_WRITE))
|
||||
return false;
|
||||
|
||||
if (SM_I(sbi) && SM_I(sbi)->dcc_info &&
|
||||
if (type != DISCARD_TIME && SM_I(sbi) && SM_I(sbi)->dcc_info &&
|
||||
atomic_read(&SM_I(sbi)->dcc_info->queued_discard))
|
||||
return false;
|
||||
|
||||
|
@ -2321,57 +2350,23 @@ static inline void f2fs_change_bit(unsigned int nr, char *addr)
|
|||
}
|
||||
|
||||
/*
|
||||
* Inode flags
|
||||
* On-disk inode flags (f2fs_inode::i_flags)
|
||||
*/
|
||||
#define F2FS_SECRM_FL 0x00000001 /* Secure deletion */
|
||||
#define F2FS_UNRM_FL 0x00000002 /* Undelete */
|
||||
#define F2FS_COMPR_FL 0x00000004 /* Compress file */
|
||||
#define F2FS_SYNC_FL 0x00000008 /* Synchronous updates */
|
||||
#define F2FS_IMMUTABLE_FL 0x00000010 /* Immutable file */
|
||||
#define F2FS_APPEND_FL 0x00000020 /* writes to file may only append */
|
||||
#define F2FS_NODUMP_FL 0x00000040 /* do not dump file */
|
||||
#define F2FS_NOATIME_FL 0x00000080 /* do not update atime */
|
||||
/* Reserved for compression usage... */
|
||||
#define F2FS_DIRTY_FL 0x00000100
|
||||
#define F2FS_COMPRBLK_FL 0x00000200 /* One or more compressed clusters */
|
||||
#define F2FS_NOCOMPR_FL 0x00000400 /* Don't compress */
|
||||
#define F2FS_ENCRYPT_FL 0x00000800 /* encrypted file */
|
||||
/* End compression flags --- maybe not all used */
|
||||
#define F2FS_INDEX_FL 0x00001000 /* hash-indexed directory */
|
||||
#define F2FS_IMAGIC_FL 0x00002000 /* AFS directory */
|
||||
#define F2FS_JOURNAL_DATA_FL 0x00004000 /* file data should be journaled */
|
||||
#define F2FS_NOTAIL_FL 0x00008000 /* file tail should not be merged */
|
||||
#define F2FS_DIRSYNC_FL 0x00010000 /* dirsync behaviour (directories only) */
|
||||
#define F2FS_TOPDIR_FL 0x00020000 /* Top of directory hierarchies*/
|
||||
#define F2FS_HUGE_FILE_FL 0x00040000 /* Set to each huge file */
|
||||
#define F2FS_EXTENTS_FL 0x00080000 /* Inode uses extents */
|
||||
#define F2FS_EA_INODE_FL 0x00200000 /* Inode used for large EA */
|
||||
#define F2FS_EOFBLOCKS_FL 0x00400000 /* Blocks allocated beyond EOF */
|
||||
#define F2FS_NOCOW_FL 0x00800000 /* Do not cow file */
|
||||
#define F2FS_INLINE_DATA_FL 0x10000000 /* Inode has inline data. */
|
||||
#define F2FS_PROJINHERIT_FL 0x20000000 /* Create with parents projid */
|
||||
#define F2FS_RESERVED_FL 0x80000000 /* reserved for ext4 lib */
|
||||
|
||||
#define F2FS_FL_USER_VISIBLE 0x30CBDFFF /* User visible flags */
|
||||
#define F2FS_FL_USER_MODIFIABLE 0x204BC0FF /* User modifiable flags */
|
||||
|
||||
/* Flags we can manipulate with through F2FS_IOC_FSSETXATTR */
|
||||
#define F2FS_FL_XFLAG_VISIBLE (F2FS_SYNC_FL | \
|
||||
F2FS_IMMUTABLE_FL | \
|
||||
F2FS_APPEND_FL | \
|
||||
F2FS_NODUMP_FL | \
|
||||
F2FS_NOATIME_FL | \
|
||||
F2FS_PROJINHERIT_FL)
|
||||
|
||||
/* Flags that should be inherited by new inodes from their parent. */
|
||||
#define F2FS_FL_INHERITED (F2FS_SECRM_FL | F2FS_UNRM_FL | F2FS_COMPR_FL |\
|
||||
F2FS_SYNC_FL | F2FS_NODUMP_FL | F2FS_NOATIME_FL |\
|
||||
F2FS_NOCOMPR_FL | F2FS_JOURNAL_DATA_FL |\
|
||||
F2FS_NOTAIL_FL | F2FS_DIRSYNC_FL |\
|
||||
F2FS_PROJINHERIT_FL)
|
||||
#define F2FS_FL_INHERITED (F2FS_SYNC_FL | F2FS_NODUMP_FL | F2FS_NOATIME_FL | \
|
||||
F2FS_DIRSYNC_FL | F2FS_PROJINHERIT_FL)
|
||||
|
||||
/* Flags that are appropriate for regular files (all but dir-specific ones). */
|
||||
#define F2FS_REG_FLMASK (~(F2FS_DIRSYNC_FL | F2FS_TOPDIR_FL))
|
||||
#define F2FS_REG_FLMASK (~(F2FS_DIRSYNC_FL | F2FS_PROJINHERIT_FL))
|
||||
|
||||
/* Flags that are appropriate for non-directories/regular files. */
|
||||
#define F2FS_OTHER_FLMASK (F2FS_NODUMP_FL | F2FS_NOATIME_FL)
|
||||
|
@ -2857,9 +2852,8 @@ static inline void verify_blkaddr(struct f2fs_sb_info *sbi,
|
|||
block_t blkaddr, int type)
|
||||
{
|
||||
if (!f2fs_is_valid_blkaddr(sbi, blkaddr, type)) {
|
||||
f2fs_msg(sbi->sb, KERN_ERR,
|
||||
"invalid blkaddr: %u, type: %d, run fsck to fix.",
|
||||
blkaddr, type);
|
||||
f2fs_err(sbi, "invalid blkaddr: %u, type: %d, run fsck to fix.",
|
||||
blkaddr, type);
|
||||
f2fs_bug_on(sbi, 1);
|
||||
}
|
||||
}
|
||||
|
@ -2990,8 +2984,6 @@ int f2fs_quota_sync(struct super_block *sb, int type);
|
|||
void f2fs_quota_off_umount(struct super_block *sb);
|
||||
int f2fs_commit_super(struct f2fs_sb_info *sbi, bool recover);
|
||||
int f2fs_sync_fs(struct super_block *sb, int sync);
|
||||
extern __printf(3, 4)
|
||||
void f2fs_msg(struct super_block *sb, const char *level, const char *fmt, ...);
|
||||
int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi);
|
||||
|
||||
/*
|
||||
|
@ -3075,9 +3067,12 @@ bool f2fs_issue_discard_timeout(struct f2fs_sb_info *sbi);
|
|||
void f2fs_clear_prefree_segments(struct f2fs_sb_info *sbi,
|
||||
struct cp_control *cpc);
|
||||
void f2fs_dirty_to_prefree(struct f2fs_sb_info *sbi);
|
||||
int f2fs_disable_cp_again(struct f2fs_sb_info *sbi);
|
||||
block_t f2fs_get_unusable_blocks(struct f2fs_sb_info *sbi);
|
||||
int f2fs_disable_cp_again(struct f2fs_sb_info *sbi, block_t unusable);
|
||||
void f2fs_release_discard_addrs(struct f2fs_sb_info *sbi);
|
||||
int f2fs_npages_for_summary_flush(struct f2fs_sb_info *sbi, bool for_ra);
|
||||
void allocate_segment_for_resize(struct f2fs_sb_info *sbi, int type,
|
||||
unsigned int start, unsigned int end);
|
||||
void f2fs_allocate_new_segments(struct f2fs_sb_info *sbi);
|
||||
int f2fs_trim_fs(struct f2fs_sb_info *sbi, struct fstrim_range *range);
|
||||
bool f2fs_exist_trim_candidates(struct f2fs_sb_info *sbi,
|
||||
|
@ -3170,6 +3165,7 @@ void f2fs_submit_merged_write_cond(struct f2fs_sb_info *sbi,
|
|||
nid_t ino, enum page_type type);
|
||||
void f2fs_flush_merged_writes(struct f2fs_sb_info *sbi);
|
||||
int f2fs_submit_page_bio(struct f2fs_io_info *fio);
|
||||
int f2fs_merge_page_bio(struct f2fs_io_info *fio);
|
||||
void f2fs_submit_page_write(struct f2fs_io_info *fio);
|
||||
struct block_device *f2fs_target_device(struct f2fs_sb_info *sbi,
|
||||
block_t blk_addr, struct bio *bio);
|
||||
|
@ -3215,6 +3211,7 @@ block_t f2fs_start_bidx_of_node(unsigned int node_ofs, struct inode *inode);
|
|||
int f2fs_gc(struct f2fs_sb_info *sbi, bool sync, bool background,
|
||||
unsigned int segno);
|
||||
void f2fs_build_gc_manager(struct f2fs_sb_info *sbi);
|
||||
int f2fs_resize_fs(struct f2fs_sb_info *sbi, __u64 block_count);
|
||||
|
||||
/*
|
||||
* recovery.c
|
||||
|
@ -3687,7 +3684,8 @@ static inline bool f2fs_force_buffered_io(struct inode *inode,
|
|||
if (test_opt(sbi, LFS) && (rw == WRITE) &&
|
||||
block_unaligned_IO(inode, iocb, iter))
|
||||
return true;
|
||||
if (is_sbi_flag_set(F2FS_I_SB(inode), SBI_CP_DISABLED))
|
||||
if (is_sbi_flag_set(F2FS_I_SB(inode), SBI_CP_DISABLED) &&
|
||||
!(inode->i_flags & S_SWAPFILE))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
|
@ -3713,4 +3711,7 @@ static inline bool is_journalled_quota(struct f2fs_sb_info *sbi)
|
|||
return false;
|
||||
}
|
||||
|
||||
#define EFSBADCRC EBADMSG /* Bad CRC detected */
|
||||
#define EFSCORRUPTED EUCLEAN /* Filesystem is corrupted */
|
||||
|
||||
#endif /* _LINUX_F2FS_H */
|
||||
|
|
355
fs/f2fs/file.c
355
fs/f2fs/file.c
|
@ -719,11 +719,9 @@ int f2fs_getattr(const struct path *path, struct kstat *stat,
|
|||
stat->btime.tv_nsec = fi->i_crtime.tv_nsec;
|
||||
}
|
||||
|
||||
flags = fi->i_flags & F2FS_FL_USER_VISIBLE;
|
||||
flags = fi->i_flags;
|
||||
if (flags & F2FS_APPEND_FL)
|
||||
stat->attributes |= STATX_ATTR_APPEND;
|
||||
if (flags & F2FS_COMPR_FL)
|
||||
stat->attributes |= STATX_ATTR_COMPRESSED;
|
||||
if (IS_ENCRYPTED(inode))
|
||||
stat->attributes |= STATX_ATTR_ENCRYPTED;
|
||||
if (flags & F2FS_IMMUTABLE_FL)
|
||||
|
@ -732,7 +730,6 @@ int f2fs_getattr(const struct path *path, struct kstat *stat,
|
|||
stat->attributes |= STATX_ATTR_NODUMP;
|
||||
|
||||
stat->attributes_mask |= (STATX_ATTR_APPEND |
|
||||
STATX_ATTR_COMPRESSED |
|
||||
STATX_ATTR_ENCRYPTED |
|
||||
STATX_ATTR_IMMUTABLE |
|
||||
STATX_ATTR_NODUMP);
|
||||
|
@ -1038,7 +1035,7 @@ static int __read_out_blkaddrs(struct inode *inode, block_t *blkaddr,
|
|||
!f2fs_is_valid_blkaddr(sbi, *blkaddr,
|
||||
DATA_GENERIC_ENHANCE)) {
|
||||
f2fs_put_dnode(&dn);
|
||||
return -EFAULT;
|
||||
return -EFSCORRUPTED;
|
||||
}
|
||||
|
||||
if (!f2fs_is_checkpointed_data(sbi, *blkaddr)) {
|
||||
|
@ -1226,7 +1223,7 @@ static int __exchange_data_block(struct inode *src_inode,
|
|||
static int f2fs_do_collapse(struct inode *inode, loff_t offset, loff_t len)
|
||||
{
|
||||
struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
|
||||
pgoff_t nrpages = (i_size_read(inode) + PAGE_SIZE - 1) / PAGE_SIZE;
|
||||
pgoff_t nrpages = DIV_ROUND_UP(i_size_read(inode), PAGE_SIZE);
|
||||
pgoff_t start = offset >> PAGE_SHIFT;
|
||||
pgoff_t end = (offset + len) >> PAGE_SHIFT;
|
||||
int ret;
|
||||
|
@ -1479,7 +1476,7 @@ static int f2fs_insert_range(struct inode *inode, loff_t offset, loff_t len)
|
|||
pg_start = offset >> PAGE_SHIFT;
|
||||
pg_end = (offset + len) >> PAGE_SHIFT;
|
||||
delta = pg_end - pg_start;
|
||||
idx = (i_size_read(inode) + PAGE_SIZE - 1) / PAGE_SIZE;
|
||||
idx = DIV_ROUND_UP(i_size_read(inode), PAGE_SIZE);
|
||||
|
||||
/* avoid gc operation during block exchange */
|
||||
down_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]);
|
||||
|
@ -1543,7 +1540,12 @@ static int expand_inode_data(struct inode *inode, loff_t offset,
|
|||
if (off_end)
|
||||
map.m_len++;
|
||||
|
||||
err = f2fs_map_blocks(inode, &map, 1, F2FS_GET_BLOCK_PRE_AIO);
|
||||
if (f2fs_is_pinned_file(inode))
|
||||
map.m_seg_type = CURSEG_COLD_DATA;
|
||||
|
||||
err = f2fs_map_blocks(inode, &map, 1, (f2fs_is_pinned_file(inode) ?
|
||||
F2FS_GET_BLOCK_PRE_DIO :
|
||||
F2FS_GET_BLOCK_PRE_AIO));
|
||||
if (err) {
|
||||
pgoff_t last_off;
|
||||
|
||||
|
@ -1660,44 +1662,15 @@ static int f2fs_file_flush(struct file *file, fl_owner_t id)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int f2fs_ioc_getflags(struct file *filp, unsigned long arg)
|
||||
{
|
||||
struct inode *inode = file_inode(filp);
|
||||
struct f2fs_inode_info *fi = F2FS_I(inode);
|
||||
unsigned int flags = fi->i_flags;
|
||||
|
||||
if (IS_ENCRYPTED(inode))
|
||||
flags |= F2FS_ENCRYPT_FL;
|
||||
if (f2fs_has_inline_data(inode) || f2fs_has_inline_dentry(inode))
|
||||
flags |= F2FS_INLINE_DATA_FL;
|
||||
if (is_inode_flag_set(inode, FI_PIN_FILE))
|
||||
flags |= F2FS_NOCOW_FL;
|
||||
|
||||
flags &= F2FS_FL_USER_VISIBLE;
|
||||
|
||||
return put_user(flags, (int __user *)arg);
|
||||
}
|
||||
|
||||
static int __f2fs_ioc_setflags(struct inode *inode, unsigned int flags)
|
||||
static int f2fs_setflags_common(struct inode *inode, u32 iflags, u32 mask)
|
||||
{
|
||||
struct f2fs_inode_info *fi = F2FS_I(inode);
|
||||
unsigned int oldflags;
|
||||
|
||||
/* Is it quota file? Do not allow user to mess with it */
|
||||
if (IS_NOQUOTA(inode))
|
||||
return -EPERM;
|
||||
|
||||
flags = f2fs_mask_flags(inode->i_mode, flags);
|
||||
|
||||
oldflags = fi->i_flags;
|
||||
|
||||
if ((flags ^ oldflags) & (F2FS_APPEND_FL | F2FS_IMMUTABLE_FL))
|
||||
if (!capable(CAP_LINUX_IMMUTABLE))
|
||||
return -EPERM;
|
||||
|
||||
flags = flags & F2FS_FL_USER_MODIFIABLE;
|
||||
flags |= oldflags & ~F2FS_FL_USER_MODIFIABLE;
|
||||
fi->i_flags = flags;
|
||||
fi->i_flags = iflags | (fi->i_flags & ~mask);
|
||||
|
||||
if (fi->i_flags & F2FS_PROJINHERIT_FL)
|
||||
set_inode_flag(inode, FI_PROJ_INHERIT);
|
||||
|
@ -1710,26 +1683,131 @@ static int __f2fs_ioc_setflags(struct inode *inode, unsigned int flags)
|
|||
return 0;
|
||||
}
|
||||
|
||||
/* FS_IOC_GETFLAGS and FS_IOC_SETFLAGS support */
|
||||
|
||||
/*
|
||||
* To make a new on-disk f2fs i_flag gettable via FS_IOC_GETFLAGS, add an entry
|
||||
* for it to f2fs_fsflags_map[], and add its FS_*_FL equivalent to
|
||||
* F2FS_GETTABLE_FS_FL. To also make it settable via FS_IOC_SETFLAGS, also add
|
||||
* its FS_*_FL equivalent to F2FS_SETTABLE_FS_FL.
|
||||
*/
|
||||
|
||||
static const struct {
|
||||
u32 iflag;
|
||||
u32 fsflag;
|
||||
} f2fs_fsflags_map[] = {
|
||||
{ F2FS_SYNC_FL, FS_SYNC_FL },
|
||||
{ F2FS_IMMUTABLE_FL, FS_IMMUTABLE_FL },
|
||||
{ F2FS_APPEND_FL, FS_APPEND_FL },
|
||||
{ F2FS_NODUMP_FL, FS_NODUMP_FL },
|
||||
{ F2FS_NOATIME_FL, FS_NOATIME_FL },
|
||||
{ F2FS_INDEX_FL, FS_INDEX_FL },
|
||||
{ F2FS_DIRSYNC_FL, FS_DIRSYNC_FL },
|
||||
{ F2FS_PROJINHERIT_FL, FS_PROJINHERIT_FL },
|
||||
};
|
||||
|
||||
#define F2FS_GETTABLE_FS_FL ( \
|
||||
FS_SYNC_FL | \
|
||||
FS_IMMUTABLE_FL | \
|
||||
FS_APPEND_FL | \
|
||||
FS_NODUMP_FL | \
|
||||
FS_NOATIME_FL | \
|
||||
FS_INDEX_FL | \
|
||||
FS_DIRSYNC_FL | \
|
||||
FS_PROJINHERIT_FL | \
|
||||
FS_ENCRYPT_FL | \
|
||||
FS_INLINE_DATA_FL | \
|
||||
FS_NOCOW_FL)
|
||||
|
||||
#define F2FS_SETTABLE_FS_FL ( \
|
||||
FS_SYNC_FL | \
|
||||
FS_IMMUTABLE_FL | \
|
||||
FS_APPEND_FL | \
|
||||
FS_NODUMP_FL | \
|
||||
FS_NOATIME_FL | \
|
||||
FS_DIRSYNC_FL | \
|
||||
FS_PROJINHERIT_FL)
|
||||
|
||||
/* Convert f2fs on-disk i_flags to FS_IOC_{GET,SET}FLAGS flags */
|
||||
static inline u32 f2fs_iflags_to_fsflags(u32 iflags)
|
||||
{
|
||||
u32 fsflags = 0;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(f2fs_fsflags_map); i++)
|
||||
if (iflags & f2fs_fsflags_map[i].iflag)
|
||||
fsflags |= f2fs_fsflags_map[i].fsflag;
|
||||
|
||||
return fsflags;
|
||||
}
|
||||
|
||||
/* Convert FS_IOC_{GET,SET}FLAGS flags to f2fs on-disk i_flags */
|
||||
static inline u32 f2fs_fsflags_to_iflags(u32 fsflags)
|
||||
{
|
||||
u32 iflags = 0;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(f2fs_fsflags_map); i++)
|
||||
if (fsflags & f2fs_fsflags_map[i].fsflag)
|
||||
iflags |= f2fs_fsflags_map[i].iflag;
|
||||
|
||||
return iflags;
|
||||
}
|
||||
|
||||
static int f2fs_ioc_getflags(struct file *filp, unsigned long arg)
|
||||
{
|
||||
struct inode *inode = file_inode(filp);
|
||||
struct f2fs_inode_info *fi = F2FS_I(inode);
|
||||
u32 fsflags = f2fs_iflags_to_fsflags(fi->i_flags);
|
||||
|
||||
if (IS_ENCRYPTED(inode))
|
||||
fsflags |= FS_ENCRYPT_FL;
|
||||
if (f2fs_has_inline_data(inode) || f2fs_has_inline_dentry(inode))
|
||||
fsflags |= FS_INLINE_DATA_FL;
|
||||
if (is_inode_flag_set(inode, FI_PIN_FILE))
|
||||
fsflags |= FS_NOCOW_FL;
|
||||
|
||||
fsflags &= F2FS_GETTABLE_FS_FL;
|
||||
|
||||
return put_user(fsflags, (int __user *)arg);
|
||||
}
|
||||
|
||||
static int f2fs_ioc_setflags(struct file *filp, unsigned long arg)
|
||||
{
|
||||
struct inode *inode = file_inode(filp);
|
||||
unsigned int flags;
|
||||
struct f2fs_inode_info *fi = F2FS_I(inode);
|
||||
u32 fsflags, old_fsflags;
|
||||
u32 iflags;
|
||||
int ret;
|
||||
|
||||
if (!inode_owner_or_capable(inode))
|
||||
return -EACCES;
|
||||
|
||||
if (get_user(flags, (int __user *)arg))
|
||||
if (get_user(fsflags, (int __user *)arg))
|
||||
return -EFAULT;
|
||||
|
||||
if (fsflags & ~F2FS_GETTABLE_FS_FL)
|
||||
return -EOPNOTSUPP;
|
||||
fsflags &= F2FS_SETTABLE_FS_FL;
|
||||
|
||||
iflags = f2fs_fsflags_to_iflags(fsflags);
|
||||
if (f2fs_mask_flags(inode->i_mode, iflags) != iflags)
|
||||
return -EOPNOTSUPP;
|
||||
|
||||
ret = mnt_want_write_file(filp);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
inode_lock(inode);
|
||||
|
||||
ret = __f2fs_ioc_setflags(inode, flags);
|
||||
old_fsflags = f2fs_iflags_to_fsflags(fi->i_flags);
|
||||
ret = vfs_ioc_setflags_prepare(inode, old_fsflags, fsflags);
|
||||
if (ret)
|
||||
goto out;
|
||||
|
||||
ret = f2fs_setflags_common(inode, iflags,
|
||||
f2fs_fsflags_to_iflags(F2FS_SETTABLE_FS_FL));
|
||||
out:
|
||||
inode_unlock(inode);
|
||||
mnt_drop_write_file(filp);
|
||||
return ret;
|
||||
|
@ -1776,9 +1854,8 @@ static int f2fs_ioc_start_atomic_write(struct file *filp)
|
|||
* f2fs_is_atomic_file.
|
||||
*/
|
||||
if (get_dirty_pages(inode))
|
||||
f2fs_msg(F2FS_I_SB(inode)->sb, KERN_WARNING,
|
||||
"Unexpected flush for atomic writes: ino=%lu, npages=%u",
|
||||
inode->i_ino, get_dirty_pages(inode));
|
||||
f2fs_warn(F2FS_I_SB(inode), "Unexpected flush for atomic writes: ino=%lu, npages=%u",
|
||||
inode->i_ino, get_dirty_pages(inode));
|
||||
ret = filemap_write_and_wait_range(inode->i_mapping, 0, LLONG_MAX);
|
||||
if (ret) {
|
||||
up_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]);
|
||||
|
@ -2213,8 +2290,7 @@ static int f2fs_ioc_write_checkpoint(struct file *filp, unsigned long arg)
|
|||
return -EROFS;
|
||||
|
||||
if (unlikely(is_sbi_flag_set(sbi, SBI_CP_DISABLED))) {
|
||||
f2fs_msg(sbi->sb, KERN_INFO,
|
||||
"Skipping Checkpoint. Checkpoints currently disabled.");
|
||||
f2fs_info(sbi, "Skipping Checkpoint. Checkpoints currently disabled.");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
|
@ -2303,7 +2379,7 @@ static int f2fs_defragment_range(struct f2fs_sb_info *sbi,
|
|||
if (!fragmented)
|
||||
goto out;
|
||||
|
||||
sec_num = (total + BLKS_PER_SEC(sbi) - 1) / BLKS_PER_SEC(sbi);
|
||||
sec_num = DIV_ROUND_UP(total, BLKS_PER_SEC(sbi));
|
||||
|
||||
/*
|
||||
* make sure there are enough free section for LFS allocation, this can
|
||||
|
@ -2599,10 +2675,8 @@ static int f2fs_ioc_flush_device(struct file *filp, unsigned long arg)
|
|||
|
||||
if (!f2fs_is_multi_device(sbi) || sbi->s_ndevs - 1 <= range.dev_num ||
|
||||
__is_large_section(sbi)) {
|
||||
f2fs_msg(sbi->sb, KERN_WARNING,
|
||||
"Can't flush %u in %d for segs_per_sec %u != 1",
|
||||
range.dev_num, sbi->s_ndevs,
|
||||
sbi->segs_per_sec);
|
||||
f2fs_warn(sbi, "Can't flush %u in %d for segs_per_sec %u != 1",
|
||||
range.dev_num, sbi->s_ndevs, sbi->segs_per_sec);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
|
@ -2739,100 +2813,87 @@ static int f2fs_ioc_setproject(struct file *filp, __u32 projid)
|
|||
}
|
||||
#endif
|
||||
|
||||
/* Transfer internal flags to xflags */
|
||||
static inline __u32 f2fs_iflags_to_xflags(unsigned long iflags)
|
||||
{
|
||||
__u32 xflags = 0;
|
||||
/* FS_IOC_FSGETXATTR and FS_IOC_FSSETXATTR support */
|
||||
|
||||
/*
|
||||
* To make a new on-disk f2fs i_flag gettable via FS_IOC_FSGETXATTR and settable
|
||||
* via FS_IOC_FSSETXATTR, add an entry for it to f2fs_xflags_map[], and add its
|
||||
* FS_XFLAG_* equivalent to F2FS_SUPPORTED_XFLAGS.
|
||||
*/
|
||||
|
||||
static const struct {
|
||||
u32 iflag;
|
||||
u32 xflag;
|
||||
} f2fs_xflags_map[] = {
|
||||
{ F2FS_SYNC_FL, FS_XFLAG_SYNC },
|
||||
{ F2FS_IMMUTABLE_FL, FS_XFLAG_IMMUTABLE },
|
||||
{ F2FS_APPEND_FL, FS_XFLAG_APPEND },
|
||||
{ F2FS_NODUMP_FL, FS_XFLAG_NODUMP },
|
||||
{ F2FS_NOATIME_FL, FS_XFLAG_NOATIME },
|
||||
{ F2FS_PROJINHERIT_FL, FS_XFLAG_PROJINHERIT },
|
||||
};
|
||||
|
||||
#define F2FS_SUPPORTED_XFLAGS ( \
|
||||
FS_XFLAG_SYNC | \
|
||||
FS_XFLAG_IMMUTABLE | \
|
||||
FS_XFLAG_APPEND | \
|
||||
FS_XFLAG_NODUMP | \
|
||||
FS_XFLAG_NOATIME | \
|
||||
FS_XFLAG_PROJINHERIT)
|
||||
|
||||
/* Convert f2fs on-disk i_flags to FS_IOC_FS{GET,SET}XATTR flags */
|
||||
static inline u32 f2fs_iflags_to_xflags(u32 iflags)
|
||||
{
|
||||
u32 xflags = 0;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(f2fs_xflags_map); i++)
|
||||
if (iflags & f2fs_xflags_map[i].iflag)
|
||||
xflags |= f2fs_xflags_map[i].xflag;
|
||||
|
||||
if (iflags & F2FS_SYNC_FL)
|
||||
xflags |= FS_XFLAG_SYNC;
|
||||
if (iflags & F2FS_IMMUTABLE_FL)
|
||||
xflags |= FS_XFLAG_IMMUTABLE;
|
||||
if (iflags & F2FS_APPEND_FL)
|
||||
xflags |= FS_XFLAG_APPEND;
|
||||
if (iflags & F2FS_NODUMP_FL)
|
||||
xflags |= FS_XFLAG_NODUMP;
|
||||
if (iflags & F2FS_NOATIME_FL)
|
||||
xflags |= FS_XFLAG_NOATIME;
|
||||
if (iflags & F2FS_PROJINHERIT_FL)
|
||||
xflags |= FS_XFLAG_PROJINHERIT;
|
||||
return xflags;
|
||||
}
|
||||
|
||||
#define F2FS_SUPPORTED_FS_XFLAGS (FS_XFLAG_SYNC | FS_XFLAG_IMMUTABLE | \
|
||||
FS_XFLAG_APPEND | FS_XFLAG_NODUMP | \
|
||||
FS_XFLAG_NOATIME | FS_XFLAG_PROJINHERIT)
|
||||
|
||||
/* Transfer xflags flags to internal */
|
||||
static inline unsigned long f2fs_xflags_to_iflags(__u32 xflags)
|
||||
/* Convert FS_IOC_FS{GET,SET}XATTR flags to f2fs on-disk i_flags */
|
||||
static inline u32 f2fs_xflags_to_iflags(u32 xflags)
|
||||
{
|
||||
unsigned long iflags = 0;
|
||||
u32 iflags = 0;
|
||||
int i;
|
||||
|
||||
if (xflags & FS_XFLAG_SYNC)
|
||||
iflags |= F2FS_SYNC_FL;
|
||||
if (xflags & FS_XFLAG_IMMUTABLE)
|
||||
iflags |= F2FS_IMMUTABLE_FL;
|
||||
if (xflags & FS_XFLAG_APPEND)
|
||||
iflags |= F2FS_APPEND_FL;
|
||||
if (xflags & FS_XFLAG_NODUMP)
|
||||
iflags |= F2FS_NODUMP_FL;
|
||||
if (xflags & FS_XFLAG_NOATIME)
|
||||
iflags |= F2FS_NOATIME_FL;
|
||||
if (xflags & FS_XFLAG_PROJINHERIT)
|
||||
iflags |= F2FS_PROJINHERIT_FL;
|
||||
for (i = 0; i < ARRAY_SIZE(f2fs_xflags_map); i++)
|
||||
if (xflags & f2fs_xflags_map[i].xflag)
|
||||
iflags |= f2fs_xflags_map[i].iflag;
|
||||
|
||||
return iflags;
|
||||
}
|
||||
|
||||
static void f2fs_fill_fsxattr(struct inode *inode, struct fsxattr *fa)
|
||||
{
|
||||
struct f2fs_inode_info *fi = F2FS_I(inode);
|
||||
|
||||
simple_fill_fsxattr(fa, f2fs_iflags_to_xflags(fi->i_flags));
|
||||
|
||||
if (f2fs_sb_has_project_quota(F2FS_I_SB(inode)))
|
||||
fa->fsx_projid = from_kprojid(&init_user_ns, fi->i_projid);
|
||||
}
|
||||
|
||||
static int f2fs_ioc_fsgetxattr(struct file *filp, unsigned long arg)
|
||||
{
|
||||
struct inode *inode = file_inode(filp);
|
||||
struct f2fs_inode_info *fi = F2FS_I(inode);
|
||||
struct fsxattr fa;
|
||||
|
||||
memset(&fa, 0, sizeof(struct fsxattr));
|
||||
fa.fsx_xflags = f2fs_iflags_to_xflags(fi->i_flags &
|
||||
F2FS_FL_USER_VISIBLE);
|
||||
|
||||
if (f2fs_sb_has_project_quota(F2FS_I_SB(inode)))
|
||||
fa.fsx_projid = (__u32)from_kprojid(&init_user_ns,
|
||||
fi->i_projid);
|
||||
f2fs_fill_fsxattr(inode, &fa);
|
||||
|
||||
if (copy_to_user((struct fsxattr __user *)arg, &fa, sizeof(fa)))
|
||||
return -EFAULT;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int f2fs_ioctl_check_project(struct inode *inode, struct fsxattr *fa)
|
||||
{
|
||||
/*
|
||||
* Project Quota ID state is only allowed to change from within the init
|
||||
* namespace. Enforce that restriction only if we are trying to change
|
||||
* the quota ID state. Everything else is allowed in user namespaces.
|
||||
*/
|
||||
if (current_user_ns() == &init_user_ns)
|
||||
return 0;
|
||||
|
||||
if (__kprojid_val(F2FS_I(inode)->i_projid) != fa->fsx_projid)
|
||||
return -EINVAL;
|
||||
|
||||
if (F2FS_I(inode)->i_flags & F2FS_PROJINHERIT_FL) {
|
||||
if (!(fa->fsx_xflags & FS_XFLAG_PROJINHERIT))
|
||||
return -EINVAL;
|
||||
} else {
|
||||
if (fa->fsx_xflags & FS_XFLAG_PROJINHERIT)
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int f2fs_ioc_fssetxattr(struct file *filp, unsigned long arg)
|
||||
{
|
||||
struct inode *inode = file_inode(filp);
|
||||
struct f2fs_inode_info *fi = F2FS_I(inode);
|
||||
struct fsxattr fa;
|
||||
unsigned int flags;
|
||||
struct fsxattr fa, old_fa;
|
||||
u32 iflags;
|
||||
int err;
|
||||
|
||||
if (copy_from_user(&fa, (struct fsxattr __user *)arg, sizeof(fa)))
|
||||
|
@ -2842,11 +2903,11 @@ static int f2fs_ioc_fssetxattr(struct file *filp, unsigned long arg)
|
|||
if (!inode_owner_or_capable(inode))
|
||||
return -EACCES;
|
||||
|
||||
if (fa.fsx_xflags & ~F2FS_SUPPORTED_FS_XFLAGS)
|
||||
if (fa.fsx_xflags & ~F2FS_SUPPORTED_XFLAGS)
|
||||
return -EOPNOTSUPP;
|
||||
|
||||
flags = f2fs_xflags_to_iflags(fa.fsx_xflags);
|
||||
if (f2fs_mask_flags(inode->i_mode, flags) != flags)
|
||||
iflags = f2fs_xflags_to_iflags(fa.fsx_xflags);
|
||||
if (f2fs_mask_flags(inode->i_mode, iflags) != iflags)
|
||||
return -EOPNOTSUPP;
|
||||
|
||||
err = mnt_want_write_file(filp);
|
||||
|
@ -2854,12 +2915,14 @@ static int f2fs_ioc_fssetxattr(struct file *filp, unsigned long arg)
|
|||
return err;
|
||||
|
||||
inode_lock(inode);
|
||||
err = f2fs_ioctl_check_project(inode, &fa);
|
||||
|
||||
f2fs_fill_fsxattr(inode, &old_fa);
|
||||
err = vfs_ioc_fssetxattr_check(inode, &old_fa, &fa);
|
||||
if (err)
|
||||
goto out;
|
||||
flags = (fi->i_flags & ~F2FS_FL_XFLAG_VISIBLE) |
|
||||
(flags & F2FS_FL_XFLAG_VISIBLE);
|
||||
err = __f2fs_ioc_setflags(inode, flags);
|
||||
|
||||
err = f2fs_setflags_common(inode, iflags,
|
||||
f2fs_xflags_to_iflags(F2FS_SUPPORTED_XFLAGS));
|
||||
if (err)
|
||||
goto out;
|
||||
|
||||
|
@ -2881,10 +2944,9 @@ int f2fs_pin_file_control(struct inode *inode, bool inc)
|
|||
fi->i_gc_failures[GC_FAILURE_PIN] + 1);
|
||||
|
||||
if (fi->i_gc_failures[GC_FAILURE_PIN] > sbi->gc_pin_file_threshold) {
|
||||
f2fs_msg(sbi->sb, KERN_WARNING,
|
||||
"%s: Enable GC = ino %lx after %x GC trials",
|
||||
__func__, inode->i_ino,
|
||||
fi->i_gc_failures[GC_FAILURE_PIN]);
|
||||
f2fs_warn(sbi, "%s: Enable GC = ino %lx after %x GC trials",
|
||||
__func__, inode->i_ino,
|
||||
fi->i_gc_failures[GC_FAILURE_PIN]);
|
||||
clear_inode_flag(inode, FI_PIN_FILE);
|
||||
return -EAGAIN;
|
||||
}
|
||||
|
@ -2897,9 +2959,6 @@ static int f2fs_ioc_set_pin_file(struct file *filp, unsigned long arg)
|
|||
__u32 pin;
|
||||
int ret = 0;
|
||||
|
||||
if (!capable(CAP_SYS_ADMIN))
|
||||
return -EPERM;
|
||||
|
||||
if (get_user(pin, (__u32 __user *)arg))
|
||||
return -EFAULT;
|
||||
|
||||
|
@ -2992,6 +3051,27 @@ static int f2fs_ioc_precache_extents(struct file *filp, unsigned long arg)
|
|||
return f2fs_precache_extents(file_inode(filp));
|
||||
}
|
||||
|
||||
static int f2fs_ioc_resize_fs(struct file *filp, unsigned long arg)
|
||||
{
|
||||
struct f2fs_sb_info *sbi = F2FS_I_SB(file_inode(filp));
|
||||
__u64 block_count;
|
||||
int ret;
|
||||
|
||||
if (!capable(CAP_SYS_ADMIN))
|
||||
return -EPERM;
|
||||
|
||||
if (f2fs_readonly(sbi->sb))
|
||||
return -EROFS;
|
||||
|
||||
if (copy_from_user(&block_count, (void __user *)arg,
|
||||
sizeof(block_count)))
|
||||
return -EFAULT;
|
||||
|
||||
ret = f2fs_resize_fs(sbi, block_count);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
long f2fs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
|
||||
{
|
||||
if (unlikely(f2fs_cp_error(F2FS_I_SB(file_inode(filp)))))
|
||||
|
@ -3048,6 +3128,8 @@ long f2fs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
|
|||
return f2fs_ioc_set_pin_file(filp, arg);
|
||||
case F2FS_IOC_PRECACHE_EXTENTS:
|
||||
return f2fs_ioc_precache_extents(filp, arg);
|
||||
case F2FS_IOC_RESIZE_FS:
|
||||
return f2fs_ioc_resize_fs(filp, arg);
|
||||
default:
|
||||
return -ENOTTY;
|
||||
}
|
||||
|
@ -3161,6 +3243,7 @@ long f2fs_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
|
|||
case F2FS_IOC_GET_PIN_FILE:
|
||||
case F2FS_IOC_SET_PIN_FILE:
|
||||
case F2FS_IOC_PRECACHE_EXTENTS:
|
||||
case F2FS_IOC_RESIZE_FS:
|
||||
break;
|
||||
default:
|
||||
return -ENOIOCTLCMD;
|
||||
|
|
266
fs/f2fs/gc.c
266
fs/f2fs/gc.c
|
@ -311,10 +311,11 @@ static int get_victim_by_default(struct f2fs_sb_info *sbi,
|
|||
struct sit_info *sm = SIT_I(sbi);
|
||||
struct victim_sel_policy p;
|
||||
unsigned int secno, last_victim;
|
||||
unsigned int last_segment = MAIN_SEGS(sbi);
|
||||
unsigned int last_segment;
|
||||
unsigned int nsearched = 0;
|
||||
|
||||
mutex_lock(&dirty_i->seglist_lock);
|
||||
last_segment = MAIN_SECS(sbi) * sbi->segs_per_sec;
|
||||
|
||||
p.alloc_mode = alloc_mode;
|
||||
select_policy(sbi, gc_type, type, &p);
|
||||
|
@ -387,7 +388,8 @@ static int get_victim_by_default(struct f2fs_sb_info *sbi,
|
|||
goto next;
|
||||
/* Don't touch checkpointed data */
|
||||
if (unlikely(is_sbi_flag_set(sbi, SBI_CP_DISABLED) &&
|
||||
get_ckpt_valid_blocks(sbi, segno)))
|
||||
get_ckpt_valid_blocks(sbi, segno) &&
|
||||
p.alloc_mode != SSR))
|
||||
goto next;
|
||||
if (gc_type == BG_GC && test_bit(secno, dirty_i->victim_secmap))
|
||||
goto next;
|
||||
|
@ -404,7 +406,8 @@ static int get_victim_by_default(struct f2fs_sb_info *sbi,
|
|||
sm->last_victim[p.gc_mode] = last_victim + 1;
|
||||
else
|
||||
sm->last_victim[p.gc_mode] = segno + 1;
|
||||
sm->last_victim[p.gc_mode] %= MAIN_SEGS(sbi);
|
||||
sm->last_victim[p.gc_mode] %=
|
||||
(MAIN_SECS(sbi) * sbi->segs_per_sec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -615,9 +618,8 @@ static bool is_alive(struct f2fs_sb_info *sbi, struct f2fs_summary *sum,
|
|||
}
|
||||
|
||||
if (sum->version != dni->version) {
|
||||
f2fs_msg(sbi->sb, KERN_WARNING,
|
||||
"%s: valid data with mismatched node version.",
|
||||
__func__);
|
||||
f2fs_warn(sbi, "%s: valid data with mismatched node version.",
|
||||
__func__);
|
||||
set_sbi_flag(sbi, SBI_NEED_FSCK);
|
||||
}
|
||||
|
||||
|
@ -658,7 +660,7 @@ static int ra_data_block(struct inode *inode, pgoff_t index)
|
|||
dn.data_blkaddr = ei.blk + index - ei.fofs;
|
||||
if (unlikely(!f2fs_is_valid_blkaddr(sbi, dn.data_blkaddr,
|
||||
DATA_GENERIC_ENHANCE_READ))) {
|
||||
err = -EFAULT;
|
||||
err = -EFSCORRUPTED;
|
||||
goto put_page;
|
||||
}
|
||||
goto got_it;
|
||||
|
@ -676,7 +678,7 @@ static int ra_data_block(struct inode *inode, pgoff_t index)
|
|||
}
|
||||
if (unlikely(!f2fs_is_valid_blkaddr(sbi, dn.data_blkaddr,
|
||||
DATA_GENERIC_ENHANCE))) {
|
||||
err = -EFAULT;
|
||||
err = -EFSCORRUPTED;
|
||||
goto put_page;
|
||||
}
|
||||
got_it:
|
||||
|
@ -794,6 +796,29 @@ static int move_data_block(struct inode *inode, block_t bidx,
|
|||
if (lfs_mode)
|
||||
down_write(&fio.sbi->io_order_lock);
|
||||
|
||||
mpage = f2fs_grab_cache_page(META_MAPPING(fio.sbi),
|
||||
fio.old_blkaddr, false);
|
||||
if (!mpage)
|
||||
goto up_out;
|
||||
|
||||
fio.encrypted_page = mpage;
|
||||
|
||||
/* read source block in mpage */
|
||||
if (!PageUptodate(mpage)) {
|
||||
err = f2fs_submit_page_bio(&fio);
|
||||
if (err) {
|
||||
f2fs_put_page(mpage, 1);
|
||||
goto up_out;
|
||||
}
|
||||
lock_page(mpage);
|
||||
if (unlikely(mpage->mapping != META_MAPPING(fio.sbi) ||
|
||||
!PageUptodate(mpage))) {
|
||||
err = -EIO;
|
||||
f2fs_put_page(mpage, 1);
|
||||
goto up_out;
|
||||
}
|
||||
}
|
||||
|
||||
f2fs_allocate_data_block(fio.sbi, NULL, fio.old_blkaddr, &newaddr,
|
||||
&sum, CURSEG_COLD_DATA, NULL, false);
|
||||
|
||||
|
@ -801,44 +826,18 @@ static int move_data_block(struct inode *inode, block_t bidx,
|
|||
newaddr, FGP_LOCK | FGP_CREAT, GFP_NOFS);
|
||||
if (!fio.encrypted_page) {
|
||||
err = -ENOMEM;
|
||||
f2fs_put_page(mpage, 1);
|
||||
goto recover_block;
|
||||
}
|
||||
|
||||
mpage = f2fs_pagecache_get_page(META_MAPPING(fio.sbi),
|
||||
fio.old_blkaddr, FGP_LOCK, GFP_NOFS);
|
||||
if (mpage) {
|
||||
bool updated = false;
|
||||
|
||||
if (PageUptodate(mpage)) {
|
||||
memcpy(page_address(fio.encrypted_page),
|
||||
page_address(mpage), PAGE_SIZE);
|
||||
updated = true;
|
||||
}
|
||||
f2fs_put_page(mpage, 1);
|
||||
invalidate_mapping_pages(META_MAPPING(fio.sbi),
|
||||
fio.old_blkaddr, fio.old_blkaddr);
|
||||
if (updated)
|
||||
goto write_page;
|
||||
}
|
||||
|
||||
err = f2fs_submit_page_bio(&fio);
|
||||
if (err)
|
||||
goto put_page_out;
|
||||
|
||||
/* write page */
|
||||
lock_page(fio.encrypted_page);
|
||||
|
||||
if (unlikely(fio.encrypted_page->mapping != META_MAPPING(fio.sbi))) {
|
||||
err = -EIO;
|
||||
goto put_page_out;
|
||||
}
|
||||
if (unlikely(!PageUptodate(fio.encrypted_page))) {
|
||||
err = -EIO;
|
||||
goto put_page_out;
|
||||
}
|
||||
|
||||
write_page:
|
||||
/* write target block */
|
||||
f2fs_wait_on_page_writeback(fio.encrypted_page, DATA, true, true);
|
||||
memcpy(page_address(fio.encrypted_page),
|
||||
page_address(mpage), PAGE_SIZE);
|
||||
f2fs_put_page(mpage, 1);
|
||||
invalidate_mapping_pages(META_MAPPING(fio.sbi),
|
||||
fio.old_blkaddr, fio.old_blkaddr);
|
||||
|
||||
set_page_dirty(fio.encrypted_page);
|
||||
if (clear_page_dirty_for_io(fio.encrypted_page))
|
||||
dec_page_count(fio.sbi, F2FS_DIRTY_META);
|
||||
|
@ -869,11 +868,12 @@ static int move_data_block(struct inode *inode, block_t bidx,
|
|||
put_page_out:
|
||||
f2fs_put_page(fio.encrypted_page, 1);
|
||||
recover_block:
|
||||
if (lfs_mode)
|
||||
up_write(&fio.sbi->io_order_lock);
|
||||
if (err)
|
||||
f2fs_do_replace_block(fio.sbi, &sum, newaddr, fio.old_blkaddr,
|
||||
true, true);
|
||||
up_out:
|
||||
if (lfs_mode)
|
||||
up_write(&fio.sbi->io_order_lock);
|
||||
put_out:
|
||||
f2fs_put_dnode(&dn);
|
||||
out:
|
||||
|
@ -1180,9 +1180,8 @@ static int do_garbage_collect(struct f2fs_sb_info *sbi,
|
|||
|
||||
sum = page_address(sum_page);
|
||||
if (type != GET_SUM_TYPE((&sum->footer))) {
|
||||
f2fs_msg(sbi->sb, KERN_ERR, "Inconsistent segment (%u) "
|
||||
"type [%d, %d] in SSA and SIT",
|
||||
segno, type, GET_SUM_TYPE((&sum->footer)));
|
||||
f2fs_err(sbi, "Inconsistent segment (%u) type [%d, %d] in SSA and SIT",
|
||||
segno, type, GET_SUM_TYPE((&sum->footer)));
|
||||
set_sbi_flag(sbi, SBI_NEED_FSCK);
|
||||
f2fs_stop_checkpoint(sbi, false);
|
||||
goto skip;
|
||||
|
@ -1360,3 +1359,176 @@ void f2fs_build_gc_manager(struct f2fs_sb_info *sbi)
|
|||
SIT_I(sbi)->last_victim[ALLOC_NEXT] =
|
||||
GET_SEGNO(sbi, FDEV(0).end_blk) + 1;
|
||||
}
|
||||
|
||||
static int free_segment_range(struct f2fs_sb_info *sbi, unsigned int start,
|
||||
unsigned int end)
|
||||
{
|
||||
int type;
|
||||
unsigned int segno, next_inuse;
|
||||
int err = 0;
|
||||
|
||||
/* Move out cursegs from the target range */
|
||||
for (type = CURSEG_HOT_DATA; type < NR_CURSEG_TYPE; type++)
|
||||
allocate_segment_for_resize(sbi, type, start, end);
|
||||
|
||||
/* do GC to move out valid blocks in the range */
|
||||
for (segno = start; segno <= end; segno += sbi->segs_per_sec) {
|
||||
struct gc_inode_list gc_list = {
|
||||
.ilist = LIST_HEAD_INIT(gc_list.ilist),
|
||||
.iroot = RADIX_TREE_INIT(gc_list.iroot, GFP_NOFS),
|
||||
};
|
||||
|
||||
mutex_lock(&sbi->gc_mutex);
|
||||
do_garbage_collect(sbi, segno, &gc_list, FG_GC);
|
||||
mutex_unlock(&sbi->gc_mutex);
|
||||
put_gc_inode(&gc_list);
|
||||
|
||||
if (get_valid_blocks(sbi, segno, true))
|
||||
return -EAGAIN;
|
||||
}
|
||||
|
||||
err = f2fs_sync_fs(sbi->sb, 1);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
next_inuse = find_next_inuse(FREE_I(sbi), end + 1, start);
|
||||
if (next_inuse <= end) {
|
||||
f2fs_err(sbi, "segno %u should be free but still inuse!",
|
||||
next_inuse);
|
||||
f2fs_bug_on(sbi, 1);
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
static void update_sb_metadata(struct f2fs_sb_info *sbi, int secs)
|
||||
{
|
||||
struct f2fs_super_block *raw_sb = F2FS_RAW_SUPER(sbi);
|
||||
int section_count = le32_to_cpu(raw_sb->section_count);
|
||||
int segment_count = le32_to_cpu(raw_sb->segment_count);
|
||||
int segment_count_main = le32_to_cpu(raw_sb->segment_count_main);
|
||||
long long block_count = le64_to_cpu(raw_sb->block_count);
|
||||
int segs = secs * sbi->segs_per_sec;
|
||||
|
||||
raw_sb->section_count = cpu_to_le32(section_count + secs);
|
||||
raw_sb->segment_count = cpu_to_le32(segment_count + segs);
|
||||
raw_sb->segment_count_main = cpu_to_le32(segment_count_main + segs);
|
||||
raw_sb->block_count = cpu_to_le64(block_count +
|
||||
(long long)segs * sbi->blocks_per_seg);
|
||||
}
|
||||
|
||||
static void update_fs_metadata(struct f2fs_sb_info *sbi, int secs)
|
||||
{
|
||||
int segs = secs * sbi->segs_per_sec;
|
||||
long long user_block_count =
|
||||
le64_to_cpu(F2FS_CKPT(sbi)->user_block_count);
|
||||
|
||||
SM_I(sbi)->segment_count = (int)SM_I(sbi)->segment_count + segs;
|
||||
MAIN_SEGS(sbi) = (int)MAIN_SEGS(sbi) + segs;
|
||||
FREE_I(sbi)->free_sections = (int)FREE_I(sbi)->free_sections + secs;
|
||||
FREE_I(sbi)->free_segments = (int)FREE_I(sbi)->free_segments + segs;
|
||||
F2FS_CKPT(sbi)->user_block_count = cpu_to_le64(user_block_count +
|
||||
(long long)segs * sbi->blocks_per_seg);
|
||||
}
|
||||
|
||||
int f2fs_resize_fs(struct f2fs_sb_info *sbi, __u64 block_count)
|
||||
{
|
||||
__u64 old_block_count, shrunk_blocks;
|
||||
unsigned int secs;
|
||||
int gc_mode, gc_type;
|
||||
int err = 0;
|
||||
__u32 rem;
|
||||
|
||||
old_block_count = le64_to_cpu(F2FS_RAW_SUPER(sbi)->block_count);
|
||||
if (block_count > old_block_count)
|
||||
return -EINVAL;
|
||||
|
||||
/* new fs size should align to section size */
|
||||
div_u64_rem(block_count, BLKS_PER_SEC(sbi), &rem);
|
||||
if (rem)
|
||||
return -EINVAL;
|
||||
|
||||
if (block_count == old_block_count)
|
||||
return 0;
|
||||
|
||||
if (is_sbi_flag_set(sbi, SBI_NEED_FSCK)) {
|
||||
f2fs_err(sbi, "Should run fsck to repair first.");
|
||||
return -EFSCORRUPTED;
|
||||
}
|
||||
|
||||
if (test_opt(sbi, DISABLE_CHECKPOINT)) {
|
||||
f2fs_err(sbi, "Checkpoint should be enabled.");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
freeze_bdev(sbi->sb->s_bdev);
|
||||
|
||||
shrunk_blocks = old_block_count - block_count;
|
||||
secs = div_u64(shrunk_blocks, BLKS_PER_SEC(sbi));
|
||||
spin_lock(&sbi->stat_lock);
|
||||
if (shrunk_blocks + valid_user_blocks(sbi) +
|
||||
sbi->current_reserved_blocks + sbi->unusable_block_count +
|
||||
F2FS_OPTION(sbi).root_reserved_blocks > sbi->user_block_count)
|
||||
err = -ENOSPC;
|
||||
else
|
||||
sbi->user_block_count -= shrunk_blocks;
|
||||
spin_unlock(&sbi->stat_lock);
|
||||
if (err) {
|
||||
thaw_bdev(sbi->sb->s_bdev, sbi->sb);
|
||||
return err;
|
||||
}
|
||||
|
||||
mutex_lock(&sbi->resize_mutex);
|
||||
set_sbi_flag(sbi, SBI_IS_RESIZEFS);
|
||||
|
||||
mutex_lock(&DIRTY_I(sbi)->seglist_lock);
|
||||
|
||||
MAIN_SECS(sbi) -= secs;
|
||||
|
||||
for (gc_mode = 0; gc_mode < MAX_GC_POLICY; gc_mode++)
|
||||
if (SIT_I(sbi)->last_victim[gc_mode] >=
|
||||
MAIN_SECS(sbi) * sbi->segs_per_sec)
|
||||
SIT_I(sbi)->last_victim[gc_mode] = 0;
|
||||
|
||||
for (gc_type = BG_GC; gc_type <= FG_GC; gc_type++)
|
||||
if (sbi->next_victim_seg[gc_type] >=
|
||||
MAIN_SECS(sbi) * sbi->segs_per_sec)
|
||||
sbi->next_victim_seg[gc_type] = NULL_SEGNO;
|
||||
|
||||
mutex_unlock(&DIRTY_I(sbi)->seglist_lock);
|
||||
|
||||
err = free_segment_range(sbi, MAIN_SECS(sbi) * sbi->segs_per_sec,
|
||||
MAIN_SEGS(sbi) - 1);
|
||||
if (err)
|
||||
goto out;
|
||||
|
||||
update_sb_metadata(sbi, -secs);
|
||||
|
||||
err = f2fs_commit_super(sbi, false);
|
||||
if (err) {
|
||||
update_sb_metadata(sbi, secs);
|
||||
goto out;
|
||||
}
|
||||
|
||||
update_fs_metadata(sbi, -secs);
|
||||
clear_sbi_flag(sbi, SBI_IS_RESIZEFS);
|
||||
err = f2fs_sync_fs(sbi->sb, 1);
|
||||
if (err) {
|
||||
update_fs_metadata(sbi, secs);
|
||||
update_sb_metadata(sbi, secs);
|
||||
f2fs_commit_super(sbi, false);
|
||||
}
|
||||
out:
|
||||
if (err) {
|
||||
set_sbi_flag(sbi, SBI_NEED_FSCK);
|
||||
f2fs_err(sbi, "resize_fs failed, should run fsck to repair!");
|
||||
|
||||
MAIN_SECS(sbi) += secs;
|
||||
spin_lock(&sbi->stat_lock);
|
||||
sbi->user_block_count += shrunk_blocks;
|
||||
spin_unlock(&sbi->stat_lock);
|
||||
}
|
||||
clear_sbi_flag(sbi, SBI_IS_RESIZEFS);
|
||||
mutex_unlock(&sbi->resize_mutex);
|
||||
thaw_bdev(sbi->sb->s_bdev, sbi->sb);
|
||||
return err;
|
||||
}
|
||||
|
|
|
@ -158,11 +158,9 @@ int f2fs_convert_inline_page(struct dnode_of_data *dn, struct page *page)
|
|||
if (unlikely(dn->data_blkaddr != NEW_ADDR)) {
|
||||
f2fs_put_dnode(dn);
|
||||
set_sbi_flag(fio.sbi, SBI_NEED_FSCK);
|
||||
f2fs_msg(fio.sbi->sb, KERN_WARNING,
|
||||
"%s: corrupted inline inode ino=%lx, i_addr[0]:0x%x, "
|
||||
"run fsck to fix.",
|
||||
__func__, dn->inode->i_ino, dn->data_blkaddr);
|
||||
return -EINVAL;
|
||||
f2fs_warn(fio.sbi, "%s: corrupted inline inode ino=%lx, i_addr[0]:0x%x, run fsck to fix.",
|
||||
__func__, dn->inode->i_ino, dn->data_blkaddr);
|
||||
return -EFSCORRUPTED;
|
||||
}
|
||||
|
||||
f2fs_bug_on(F2FS_P_SB(page), PageWriteback(page));
|
||||
|
@ -401,11 +399,9 @@ static int f2fs_move_inline_dirents(struct inode *dir, struct page *ipage,
|
|||
if (unlikely(dn.data_blkaddr != NEW_ADDR)) {
|
||||
f2fs_put_dnode(&dn);
|
||||
set_sbi_flag(F2FS_P_SB(page), SBI_NEED_FSCK);
|
||||
f2fs_msg(F2FS_P_SB(page)->sb, KERN_WARNING,
|
||||
"%s: corrupted inline inode ino=%lx, i_addr[0]:0x%x, "
|
||||
"run fsck to fix.",
|
||||
__func__, dir->i_ino, dn.data_blkaddr);
|
||||
err = -EINVAL;
|
||||
f2fs_warn(F2FS_P_SB(page), "%s: corrupted inline inode ino=%lx, i_addr[0]:0x%x, run fsck to fix.",
|
||||
__func__, dir->i_ino, dn.data_blkaddr);
|
||||
err = -EFSCORRUPTED;
|
||||
goto out;
|
||||
}
|
||||
|
||||
|
|
|
@ -74,7 +74,7 @@ static int __written_first_block(struct f2fs_sb_info *sbi,
|
|||
if (!__is_valid_data_blkaddr(addr))
|
||||
return 1;
|
||||
if (!f2fs_is_valid_blkaddr(sbi, addr, DATA_GENERIC_ENHANCE))
|
||||
return -EFAULT;
|
||||
return -EFSCORRUPTED;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -176,9 +176,8 @@ bool f2fs_inode_chksum_verify(struct f2fs_sb_info *sbi, struct page *page)
|
|||
calculated = f2fs_inode_chksum(sbi, page);
|
||||
|
||||
if (provided != calculated)
|
||||
f2fs_msg(sbi->sb, KERN_WARNING,
|
||||
"checksum invalid, nid = %lu, ino_of_node = %x, %x vs. %x",
|
||||
page->index, ino_of_node(page), provided, calculated);
|
||||
f2fs_warn(sbi, "checksum invalid, nid = %lu, ino_of_node = %x, %x vs. %x",
|
||||
page->index, ino_of_node(page), provided, calculated);
|
||||
|
||||
return provided == calculated;
|
||||
}
|
||||
|
@ -202,50 +201,41 @@ static bool sanity_check_inode(struct inode *inode, struct page *node_page)
|
|||
iblocks = le64_to_cpu(F2FS_INODE(node_page)->i_blocks);
|
||||
if (!iblocks) {
|
||||
set_sbi_flag(sbi, SBI_NEED_FSCK);
|
||||
f2fs_msg(sbi->sb, KERN_WARNING,
|
||||
"%s: corrupted inode i_blocks i_ino=%lx iblocks=%llu, "
|
||||
"run fsck to fix.",
|
||||
__func__, inode->i_ino, iblocks);
|
||||
f2fs_warn(sbi, "%s: corrupted inode i_blocks i_ino=%lx iblocks=%llu, run fsck to fix.",
|
||||
__func__, inode->i_ino, iblocks);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (ino_of_node(node_page) != nid_of_node(node_page)) {
|
||||
set_sbi_flag(sbi, SBI_NEED_FSCK);
|
||||
f2fs_msg(sbi->sb, KERN_WARNING,
|
||||
"%s: corrupted inode footer i_ino=%lx, ino,nid: "
|
||||
"[%u, %u] run fsck to fix.",
|
||||
__func__, inode->i_ino,
|
||||
ino_of_node(node_page), nid_of_node(node_page));
|
||||
f2fs_warn(sbi, "%s: corrupted inode footer i_ino=%lx, ino,nid: [%u, %u] run fsck to fix.",
|
||||
__func__, inode->i_ino,
|
||||
ino_of_node(node_page), nid_of_node(node_page));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (f2fs_sb_has_flexible_inline_xattr(sbi)
|
||||
&& !f2fs_has_extra_attr(inode)) {
|
||||
set_sbi_flag(sbi, SBI_NEED_FSCK);
|
||||
f2fs_msg(sbi->sb, KERN_WARNING,
|
||||
"%s: corrupted inode ino=%lx, run fsck to fix.",
|
||||
__func__, inode->i_ino);
|
||||
f2fs_warn(sbi, "%s: corrupted inode ino=%lx, run fsck to fix.",
|
||||
__func__, inode->i_ino);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (f2fs_has_extra_attr(inode) &&
|
||||
!f2fs_sb_has_extra_attr(sbi)) {
|
||||
set_sbi_flag(sbi, SBI_NEED_FSCK);
|
||||
f2fs_msg(sbi->sb, KERN_WARNING,
|
||||
"%s: inode (ino=%lx) is with extra_attr, "
|
||||
"but extra_attr feature is off",
|
||||
__func__, inode->i_ino);
|
||||
f2fs_warn(sbi, "%s: inode (ino=%lx) is with extra_attr, but extra_attr feature is off",
|
||||
__func__, inode->i_ino);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (fi->i_extra_isize > F2FS_TOTAL_EXTRA_ATTR_SIZE ||
|
||||
fi->i_extra_isize % sizeof(__le32)) {
|
||||
set_sbi_flag(sbi, SBI_NEED_FSCK);
|
||||
f2fs_msg(sbi->sb, KERN_WARNING,
|
||||
"%s: inode (ino=%lx) has corrupted i_extra_isize: %d, "
|
||||
"max: %zu",
|
||||
__func__, inode->i_ino, fi->i_extra_isize,
|
||||
F2FS_TOTAL_EXTRA_ATTR_SIZE);
|
||||
f2fs_warn(sbi, "%s: inode (ino=%lx) has corrupted i_extra_isize: %d, max: %zu",
|
||||
__func__, inode->i_ino, fi->i_extra_isize,
|
||||
F2FS_TOTAL_EXTRA_ATTR_SIZE);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -255,11 +245,9 @@ static bool sanity_check_inode(struct inode *inode, struct page *node_page)
|
|||
(!fi->i_inline_xattr_size ||
|
||||
fi->i_inline_xattr_size > MAX_INLINE_XATTR_SIZE)) {
|
||||
set_sbi_flag(sbi, SBI_NEED_FSCK);
|
||||
f2fs_msg(sbi->sb, KERN_WARNING,
|
||||
"%s: inode (ino=%lx) has corrupted "
|
||||
"i_inline_xattr_size: %d, max: %zu",
|
||||
__func__, inode->i_ino, fi->i_inline_xattr_size,
|
||||
MAX_INLINE_XATTR_SIZE);
|
||||
f2fs_warn(sbi, "%s: inode (ino=%lx) has corrupted i_inline_xattr_size: %d, max: %zu",
|
||||
__func__, inode->i_ino, fi->i_inline_xattr_size,
|
||||
MAX_INLINE_XATTR_SIZE);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -272,11 +260,9 @@ static bool sanity_check_inode(struct inode *inode, struct page *node_page)
|
|||
!f2fs_is_valid_blkaddr(sbi, ei->blk + ei->len - 1,
|
||||
DATA_GENERIC_ENHANCE))) {
|
||||
set_sbi_flag(sbi, SBI_NEED_FSCK);
|
||||
f2fs_msg(sbi->sb, KERN_WARNING,
|
||||
"%s: inode (ino=%lx) extent info [%u, %u, %u] "
|
||||
"is incorrect, run fsck to fix",
|
||||
__func__, inode->i_ino,
|
||||
ei->blk, ei->fofs, ei->len);
|
||||
f2fs_warn(sbi, "%s: inode (ino=%lx) extent info [%u, %u, %u] is incorrect, run fsck to fix",
|
||||
__func__, inode->i_ino,
|
||||
ei->blk, ei->fofs, ei->len);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -284,19 +270,15 @@ static bool sanity_check_inode(struct inode *inode, struct page *node_page)
|
|||
if (f2fs_has_inline_data(inode) &&
|
||||
(!S_ISREG(inode->i_mode) && !S_ISLNK(inode->i_mode))) {
|
||||
set_sbi_flag(sbi, SBI_NEED_FSCK);
|
||||
f2fs_msg(sbi->sb, KERN_WARNING,
|
||||
"%s: inode (ino=%lx, mode=%u) should not have "
|
||||
"inline_data, run fsck to fix",
|
||||
__func__, inode->i_ino, inode->i_mode);
|
||||
f2fs_warn(sbi, "%s: inode (ino=%lx, mode=%u) should not have inline_data, run fsck to fix",
|
||||
__func__, inode->i_ino, inode->i_mode);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (f2fs_has_inline_dentry(inode) && !S_ISDIR(inode->i_mode)) {
|
||||
set_sbi_flag(sbi, SBI_NEED_FSCK);
|
||||
f2fs_msg(sbi->sb, KERN_WARNING,
|
||||
"%s: inode (ino=%lx, mode=%u) should not have "
|
||||
"inline_dentry, run fsck to fix",
|
||||
__func__, inode->i_ino, inode->i_mode);
|
||||
f2fs_warn(sbi, "%s: inode (ino=%lx, mode=%u) should not have inline_dentry, run fsck to fix",
|
||||
__func__, inode->i_ino, inode->i_mode);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -343,6 +325,8 @@ static int do_read_inode(struct inode *inode)
|
|||
le16_to_cpu(ri->i_gc_failures);
|
||||
fi->i_xattr_nid = le32_to_cpu(ri->i_xattr_nid);
|
||||
fi->i_flags = le32_to_cpu(ri->i_flags);
|
||||
if (S_ISREG(inode->i_mode))
|
||||
fi->i_flags &= ~F2FS_PROJINHERIT_FL;
|
||||
fi->flags = 0;
|
||||
fi->i_advise = ri->i_advise;
|
||||
fi->i_pino = le32_to_cpu(ri->i_pino);
|
||||
|
@ -374,7 +358,7 @@ static int do_read_inode(struct inode *inode)
|
|||
|
||||
if (!sanity_check_inode(inode, node_page)) {
|
||||
f2fs_put_page(node_page, 1);
|
||||
return -EINVAL;
|
||||
return -EFSCORRUPTED;
|
||||
}
|
||||
|
||||
/* check data exist */
|
||||
|
@ -783,8 +767,7 @@ void f2fs_handle_failed_inode(struct inode *inode)
|
|||
err = f2fs_get_node_info(sbi, inode->i_ino, &ni);
|
||||
if (err) {
|
||||
set_sbi_flag(sbi, SBI_NEED_FSCK);
|
||||
f2fs_msg(sbi->sb, KERN_WARNING,
|
||||
"May loss orphan inode, run fsck to fix.");
|
||||
f2fs_warn(sbi, "May loss orphan inode, run fsck to fix.");
|
||||
goto out;
|
||||
}
|
||||
|
||||
|
@ -792,8 +775,7 @@ void f2fs_handle_failed_inode(struct inode *inode)
|
|||
err = f2fs_acquire_orphan_inode(sbi);
|
||||
if (err) {
|
||||
set_sbi_flag(sbi, SBI_NEED_FSCK);
|
||||
f2fs_msg(sbi->sb, KERN_WARNING,
|
||||
"Too many orphan inodes, run fsck to fix.");
|
||||
f2fs_warn(sbi, "Too many orphan inodes, run fsck to fix.");
|
||||
} else {
|
||||
f2fs_add_orphan_inode(inode);
|
||||
}
|
||||
|
|
|
@ -385,9 +385,8 @@ static int __recover_dot_dentries(struct inode *dir, nid_t pino)
|
|||
int err = 0;
|
||||
|
||||
if (f2fs_readonly(sbi->sb)) {
|
||||
f2fs_msg(sbi->sb, KERN_INFO,
|
||||
"skip recovering inline_dots inode (ino:%lu, pino:%u) "
|
||||
"in readonly mountpoint", dir->i_ino, pino);
|
||||
f2fs_info(sbi, "skip recovering inline_dots inode (ino:%lu, pino:%u) in readonly mountpoint",
|
||||
dir->i_ino, pino);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -436,19 +435,23 @@ static struct dentry *f2fs_lookup(struct inode *dir, struct dentry *dentry,
|
|||
nid_t ino = -1;
|
||||
int err = 0;
|
||||
unsigned int root_ino = F2FS_ROOT_INO(F2FS_I_SB(dir));
|
||||
struct fscrypt_name fname;
|
||||
|
||||
trace_f2fs_lookup_start(dir, dentry, flags);
|
||||
|
||||
err = fscrypt_prepare_lookup(dir, dentry, flags);
|
||||
if (err)
|
||||
goto out;
|
||||
|
||||
if (dentry->d_name.len > F2FS_NAME_LEN) {
|
||||
err = -ENAMETOOLONG;
|
||||
goto out;
|
||||
}
|
||||
|
||||
de = f2fs_find_entry(dir, &dentry->d_name, &page);
|
||||
err = fscrypt_prepare_lookup(dir, dentry, &fname);
|
||||
if (err == -ENOENT)
|
||||
goto out_splice;
|
||||
if (err)
|
||||
goto out;
|
||||
de = __f2fs_find_entry(dir, &fname, &page);
|
||||
fscrypt_free_filename(&fname);
|
||||
|
||||
if (!de) {
|
||||
if (IS_ERR(page)) {
|
||||
err = PTR_ERR(page);
|
||||
|
@ -480,16 +483,14 @@ static struct dentry *f2fs_lookup(struct inode *dir, struct dentry *dentry,
|
|||
if (IS_ENCRYPTED(dir) &&
|
||||
(S_ISDIR(inode->i_mode) || S_ISLNK(inode->i_mode)) &&
|
||||
!fscrypt_has_permitted_context(dir, inode)) {
|
||||
f2fs_msg(inode->i_sb, KERN_WARNING,
|
||||
"Inconsistent encryption contexts: %lu/%lu",
|
||||
dir->i_ino, inode->i_ino);
|
||||
f2fs_warn(F2FS_I_SB(inode), "Inconsistent encryption contexts: %lu/%lu",
|
||||
dir->i_ino, inode->i_ino);
|
||||
err = -EPERM;
|
||||
goto out_iput;
|
||||
}
|
||||
out_splice:
|
||||
new = d_splice_alias(inode, dentry);
|
||||
if (IS_ERR(new))
|
||||
err = PTR_ERR(new);
|
||||
err = PTR_ERR_OR_ZERO(new);
|
||||
trace_f2fs_lookup_end(dir, dentry, ino, err);
|
||||
return new;
|
||||
out_iput:
|
||||
|
|
|
@ -34,10 +34,9 @@ int f2fs_check_nid_range(struct f2fs_sb_info *sbi, nid_t nid)
|
|||
{
|
||||
if (unlikely(nid < F2FS_ROOT_INO(sbi) || nid >= NM_I(sbi)->max_nid)) {
|
||||
set_sbi_flag(sbi, SBI_NEED_FSCK);
|
||||
f2fs_msg(sbi->sb, KERN_WARNING,
|
||||
"%s: out-of-range nid=%x, run fsck to fix.",
|
||||
__func__, nid);
|
||||
return -EINVAL;
|
||||
f2fs_warn(sbi, "%s: out-of-range nid=%x, run fsck to fix.",
|
||||
__func__, nid);
|
||||
return -EFSCORRUPTED;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -1187,10 +1186,8 @@ int f2fs_remove_inode_page(struct inode *inode)
|
|||
}
|
||||
|
||||
if (unlikely(inode->i_blocks != 0 && inode->i_blocks != 8)) {
|
||||
f2fs_msg(F2FS_I_SB(inode)->sb, KERN_WARNING,
|
||||
"Inconsistent i_blocks, ino:%lu, iblocks:%llu",
|
||||
inode->i_ino,
|
||||
(unsigned long long)inode->i_blocks);
|
||||
f2fs_warn(F2FS_I_SB(inode), "Inconsistent i_blocks, ino:%lu, iblocks:%llu",
|
||||
inode->i_ino, (unsigned long long)inode->i_blocks);
|
||||
set_sbi_flag(F2FS_I_SB(inode), SBI_NEED_FSCK);
|
||||
}
|
||||
|
||||
|
@ -1289,7 +1286,7 @@ static int read_node_page(struct page *page, int op_flags)
|
|||
if (PageUptodate(page)) {
|
||||
if (!f2fs_inode_chksum_verify(sbi, page)) {
|
||||
ClearPageUptodate(page);
|
||||
return -EBADMSG;
|
||||
return -EFSBADCRC;
|
||||
}
|
||||
return LOCKED_PAGE;
|
||||
}
|
||||
|
@ -1375,16 +1372,15 @@ static struct page *__get_node_page(struct f2fs_sb_info *sbi, pgoff_t nid,
|
|||
}
|
||||
|
||||
if (!f2fs_inode_chksum_verify(sbi, page)) {
|
||||
err = -EBADMSG;
|
||||
err = -EFSBADCRC;
|
||||
goto out_err;
|
||||
}
|
||||
page_hit:
|
||||
if(unlikely(nid != nid_of_node(page))) {
|
||||
f2fs_msg(sbi->sb, KERN_WARNING, "inconsistent node block, "
|
||||
"nid:%lu, node_footer[nid:%u,ino:%u,ofs:%u,cpver:%llu,blkaddr:%u]",
|
||||
nid, nid_of_node(page), ino_of_node(page),
|
||||
ofs_of_node(page), cpver_of_node(page),
|
||||
next_blkaddr_of_node(page));
|
||||
f2fs_warn(sbi, "inconsistent node block, nid:%lu, node_footer[nid:%u,ino:%u,ofs:%u,cpver:%llu,blkaddr:%u]",
|
||||
nid, nid_of_node(page), ino_of_node(page),
|
||||
ofs_of_node(page), cpver_of_node(page),
|
||||
next_blkaddr_of_node(page));
|
||||
err = -EINVAL;
|
||||
out_err:
|
||||
ClearPageUptodate(page);
|
||||
|
@ -1752,9 +1748,8 @@ int f2fs_fsync_node_pages(struct f2fs_sb_info *sbi, struct inode *inode,
|
|||
break;
|
||||
}
|
||||
if (!ret && atomic && !marked) {
|
||||
f2fs_msg(sbi->sb, KERN_DEBUG,
|
||||
"Retry to write fsync mark: ino=%u, idx=%lx",
|
||||
ino, last_page->index);
|
||||
f2fs_debug(sbi, "Retry to write fsync mark: ino=%u, idx=%lx",
|
||||
ino, last_page->index);
|
||||
lock_page(last_page);
|
||||
f2fs_wait_on_page_writeback(last_page, NODE, true, true);
|
||||
set_page_dirty(last_page);
|
||||
|
@ -2304,8 +2299,7 @@ static int __f2fs_build_free_nids(struct f2fs_sb_info *sbi,
|
|||
if (ret) {
|
||||
up_read(&nm_i->nat_tree_lock);
|
||||
f2fs_bug_on(sbi, !mount);
|
||||
f2fs_msg(sbi->sb, KERN_ERR,
|
||||
"NAT is corrupt, run fsck to fix it");
|
||||
f2fs_err(sbi, "NAT is corrupt, run fsck to fix it");
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
@ -2725,7 +2719,7 @@ static void __update_nat_bits(struct f2fs_sb_info *sbi, nid_t start_nid,
|
|||
i = 1;
|
||||
}
|
||||
for (; i < NAT_ENTRY_PER_BLOCK; i++) {
|
||||
if (nat_blk->entries[i].block_addr != NULL_ADDR)
|
||||
if (le32_to_cpu(nat_blk->entries[i].block_addr) != NULL_ADDR)
|
||||
valid++;
|
||||
}
|
||||
if (valid == 0) {
|
||||
|
@ -2915,7 +2909,7 @@ static int __get_nat_bitmaps(struct f2fs_sb_info *sbi)
|
|||
nm_i->full_nat_bits = nm_i->nat_bits + 8;
|
||||
nm_i->empty_nat_bits = nm_i->full_nat_bits + nat_bits_bytes;
|
||||
|
||||
f2fs_msg(sbi->sb, KERN_NOTICE, "Found nat_bits in checkpoint");
|
||||
f2fs_notice(sbi, "Found nat_bits in checkpoint");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -188,10 +188,9 @@ static int recover_dentry(struct inode *inode, struct page *ipage,
|
|||
name = "<encrypted>";
|
||||
else
|
||||
name = raw_inode->i_name;
|
||||
f2fs_msg(inode->i_sb, KERN_NOTICE,
|
||||
"%s: ino = %x, name = %s, dir = %lx, err = %d",
|
||||
__func__, ino_of_node(ipage), name,
|
||||
IS_ERR(dir) ? 0 : dir->i_ino, err);
|
||||
f2fs_notice(F2FS_I_SB(inode), "%s: ino = %x, name = %s, dir = %lx, err = %d",
|
||||
__func__, ino_of_node(ipage), name,
|
||||
IS_ERR(dir) ? 0 : dir->i_ino, err);
|
||||
return err;
|
||||
}
|
||||
|
||||
|
@ -292,9 +291,8 @@ static int recover_inode(struct inode *inode, struct page *page)
|
|||
else
|
||||
name = F2FS_INODE(page)->i_name;
|
||||
|
||||
f2fs_msg(inode->i_sb, KERN_NOTICE,
|
||||
"recover_inode: ino = %x, name = %s, inline = %x",
|
||||
ino_of_node(page), name, raw->i_inline);
|
||||
f2fs_notice(F2FS_I_SB(inode), "recover_inode: ino = %x, name = %s, inline = %x",
|
||||
ino_of_node(page), name, raw->i_inline);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -371,10 +369,9 @@ static int find_fsync_dnodes(struct f2fs_sb_info *sbi, struct list_head *head,
|
|||
/* 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));
|
||||
f2fs_notice(sbi, "%s: detect looped node chain, blkaddr:%u, next:%u",
|
||||
__func__, blkaddr,
|
||||
next_blkaddr_of_node(page));
|
||||
f2fs_put_page(page, 1);
|
||||
err = -EINVAL;
|
||||
break;
|
||||
|
@ -553,11 +550,10 @@ static int do_recover_data(struct f2fs_sb_info *sbi, struct inode *inode,
|
|||
f2fs_bug_on(sbi, ni.ino != ino_of_node(page));
|
||||
|
||||
if (ofs_of_node(dn.node_page) != ofs_of_node(page)) {
|
||||
f2fs_msg(sbi->sb, KERN_WARNING,
|
||||
"Inconsistent ofs_of_node, ino:%lu, ofs:%u, %u",
|
||||
inode->i_ino, ofs_of_node(dn.node_page),
|
||||
ofs_of_node(page));
|
||||
err = -EFAULT;
|
||||
f2fs_warn(sbi, "Inconsistent ofs_of_node, ino:%lu, ofs:%u, %u",
|
||||
inode->i_ino, ofs_of_node(dn.node_page),
|
||||
ofs_of_node(page));
|
||||
err = -EFSCORRUPTED;
|
||||
goto err;
|
||||
}
|
||||
|
||||
|
@ -569,13 +565,13 @@ static int do_recover_data(struct f2fs_sb_info *sbi, struct inode *inode,
|
|||
|
||||
if (__is_valid_data_blkaddr(src) &&
|
||||
!f2fs_is_valid_blkaddr(sbi, src, META_POR)) {
|
||||
err = -EFAULT;
|
||||
err = -EFSCORRUPTED;
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (__is_valid_data_blkaddr(dest) &&
|
||||
!f2fs_is_valid_blkaddr(sbi, dest, META_POR)) {
|
||||
err = -EFAULT;
|
||||
err = -EFSCORRUPTED;
|
||||
goto err;
|
||||
}
|
||||
|
||||
|
@ -642,11 +638,9 @@ static int do_recover_data(struct f2fs_sb_info *sbi, struct inode *inode,
|
|||
err:
|
||||
f2fs_put_dnode(&dn);
|
||||
out:
|
||||
f2fs_msg(sbi->sb, KERN_NOTICE,
|
||||
"recover_data: ino = %lx (i_size: %s) recovered = %d, err = %d",
|
||||
inode->i_ino,
|
||||
file_keep_isize(inode) ? "keep" : "recover",
|
||||
recovered, err);
|
||||
f2fs_notice(sbi, "recover_data: ino = %lx (i_size: %s) recovered = %d, err = %d",
|
||||
inode->i_ino, file_keep_isize(inode) ? "keep" : "recover",
|
||||
recovered, err);
|
||||
return err;
|
||||
}
|
||||
|
||||
|
@ -734,8 +728,7 @@ int f2fs_recover_fsync_data(struct f2fs_sb_info *sbi, bool check_only)
|
|||
#endif
|
||||
|
||||
if (s_flags & SB_RDONLY) {
|
||||
f2fs_msg(sbi->sb, KERN_INFO,
|
||||
"recover fsync data on readonly fs");
|
||||
f2fs_info(sbi, "recover fsync data on readonly fs");
|
||||
sbi->sb->s_flags &= ~SB_RDONLY;
|
||||
}
|
||||
|
||||
|
|
|
@ -546,9 +546,13 @@ void f2fs_balance_fs_bg(struct f2fs_sb_info *sbi)
|
|||
if (test_opt(sbi, DATA_FLUSH)) {
|
||||
struct blk_plug plug;
|
||||
|
||||
mutex_lock(&sbi->flush_lock);
|
||||
|
||||
blk_start_plug(&plug);
|
||||
f2fs_sync_dirty_inodes(sbi, FILE_INODE);
|
||||
blk_finish_plug(&plug);
|
||||
|
||||
mutex_unlock(&sbi->flush_lock);
|
||||
}
|
||||
f2fs_sync_fs(sbi->sb, true);
|
||||
stat_inc_bg_cp_count(sbi->stat_info);
|
||||
|
@ -869,11 +873,14 @@ void f2fs_dirty_to_prefree(struct f2fs_sb_info *sbi)
|
|||
mutex_unlock(&dirty_i->seglist_lock);
|
||||
}
|
||||
|
||||
int f2fs_disable_cp_again(struct f2fs_sb_info *sbi)
|
||||
block_t f2fs_get_unusable_blocks(struct f2fs_sb_info *sbi)
|
||||
{
|
||||
int ovp_hole_segs =
|
||||
(overprovision_segments(sbi) - reserved_segments(sbi));
|
||||
block_t ovp_holes = ovp_hole_segs << sbi->log_blocks_per_seg;
|
||||
struct dirty_seglist_info *dirty_i = DIRTY_I(sbi);
|
||||
block_t ovp = overprovision_segments(sbi) << sbi->log_blocks_per_seg;
|
||||
block_t holes[2] = {0, 0}; /* DATA and NODE */
|
||||
block_t unusable;
|
||||
struct seg_entry *se;
|
||||
unsigned int segno;
|
||||
|
||||
|
@ -887,10 +894,20 @@ int f2fs_disable_cp_again(struct f2fs_sb_info *sbi)
|
|||
}
|
||||
mutex_unlock(&dirty_i->seglist_lock);
|
||||
|
||||
if (holes[DATA] > ovp || holes[NODE] > ovp)
|
||||
unusable = holes[DATA] > holes[NODE] ? holes[DATA] : holes[NODE];
|
||||
if (unusable > ovp_holes)
|
||||
return unusable - ovp_holes;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int f2fs_disable_cp_again(struct f2fs_sb_info *sbi, block_t unusable)
|
||||
{
|
||||
int ovp_hole_segs =
|
||||
(overprovision_segments(sbi) - reserved_segments(sbi));
|
||||
if (unusable > F2FS_OPTION(sbi).unusable_cap)
|
||||
return -EAGAIN;
|
||||
if (is_sbi_flag_set(sbi, SBI_CP_DISABLED_QUICK) &&
|
||||
dirty_segments(sbi) > overprovision_segments(sbi))
|
||||
dirty_segments(sbi) > ovp_hole_segs)
|
||||
return -EAGAIN;
|
||||
return 0;
|
||||
}
|
||||
|
@ -1480,6 +1497,10 @@ static int __issue_discard_cmd(struct f2fs_sb_info *sbi,
|
|||
list_for_each_entry_safe(dc, tmp, pend_list, list) {
|
||||
f2fs_bug_on(sbi, dc->state != D_PREP);
|
||||
|
||||
if (dpolicy->timeout != 0 &&
|
||||
f2fs_time_over(sbi, dpolicy->timeout))
|
||||
break;
|
||||
|
||||
if (dpolicy->io_aware && i < dpolicy->io_aware_gran &&
|
||||
!is_idle(sbi, DISCARD_TIME)) {
|
||||
io_interrupted = true;
|
||||
|
@ -1740,8 +1761,7 @@ static int __f2fs_issue_discard_zone(struct f2fs_sb_info *sbi,
|
|||
devi = f2fs_target_device_index(sbi, blkstart);
|
||||
if (blkstart < FDEV(devi).start_blk ||
|
||||
blkstart > FDEV(devi).end_blk) {
|
||||
f2fs_msg(sbi->sb, KERN_ERR, "Invalid block %x",
|
||||
blkstart);
|
||||
f2fs_err(sbi, "Invalid block %x", blkstart);
|
||||
return -EIO;
|
||||
}
|
||||
blkstart -= FDEV(devi).start_blk;
|
||||
|
@ -1754,10 +1774,9 @@ static int __f2fs_issue_discard_zone(struct f2fs_sb_info *sbi,
|
|||
|
||||
if (sector & (bdev_zone_sectors(bdev) - 1) ||
|
||||
nr_sects != bdev_zone_sectors(bdev)) {
|
||||
f2fs_msg(sbi->sb, KERN_ERR,
|
||||
"(%d) %s: Unaligned zone reset attempted (block %x + %x)",
|
||||
devi, sbi->s_ndevs ? FDEV(devi).path: "",
|
||||
blkstart, blklen);
|
||||
f2fs_err(sbi, "(%d) %s: Unaligned zone reset attempted (block %x + %x)",
|
||||
devi, sbi->s_ndevs ? FDEV(devi).path : "",
|
||||
blkstart, blklen);
|
||||
return -EIO;
|
||||
}
|
||||
trace_f2fs_issue_reset_zone(bdev, blkstart);
|
||||
|
@ -2121,15 +2140,14 @@ static void update_sit_entry(struct f2fs_sb_info *sbi, block_t blkaddr, int del)
|
|||
mir_exist = f2fs_test_and_set_bit(offset,
|
||||
se->cur_valid_map_mir);
|
||||
if (unlikely(exist != mir_exist)) {
|
||||
f2fs_msg(sbi->sb, KERN_ERR, "Inconsistent error "
|
||||
"when setting bitmap, blk:%u, old bit:%d",
|
||||
blkaddr, exist);
|
||||
f2fs_err(sbi, "Inconsistent error when setting bitmap, blk:%u, old bit:%d",
|
||||
blkaddr, exist);
|
||||
f2fs_bug_on(sbi, 1);
|
||||
}
|
||||
#endif
|
||||
if (unlikely(exist)) {
|
||||
f2fs_msg(sbi->sb, KERN_ERR,
|
||||
"Bitmap was wrongly set, blk:%u", blkaddr);
|
||||
f2fs_err(sbi, "Bitmap was wrongly set, blk:%u",
|
||||
blkaddr);
|
||||
f2fs_bug_on(sbi, 1);
|
||||
se->valid_blocks--;
|
||||
del = 0;
|
||||
|
@ -2150,15 +2168,14 @@ static void update_sit_entry(struct f2fs_sb_info *sbi, block_t blkaddr, int del)
|
|||
mir_exist = f2fs_test_and_clear_bit(offset,
|
||||
se->cur_valid_map_mir);
|
||||
if (unlikely(exist != mir_exist)) {
|
||||
f2fs_msg(sbi->sb, KERN_ERR, "Inconsistent error "
|
||||
"when clearing bitmap, blk:%u, old bit:%d",
|
||||
blkaddr, exist);
|
||||
f2fs_err(sbi, "Inconsistent error when clearing bitmap, blk:%u, old bit:%d",
|
||||
blkaddr, exist);
|
||||
f2fs_bug_on(sbi, 1);
|
||||
}
|
||||
#endif
|
||||
if (unlikely(!exist)) {
|
||||
f2fs_msg(sbi->sb, KERN_ERR,
|
||||
"Bitmap was wrongly cleared, blk:%u", blkaddr);
|
||||
f2fs_err(sbi, "Bitmap was wrongly cleared, blk:%u",
|
||||
blkaddr);
|
||||
f2fs_bug_on(sbi, 1);
|
||||
se->valid_blocks++;
|
||||
del = 0;
|
||||
|
@ -2640,6 +2657,39 @@ static void allocate_segment_by_default(struct f2fs_sb_info *sbi,
|
|||
stat_inc_seg_type(sbi, curseg);
|
||||
}
|
||||
|
||||
void allocate_segment_for_resize(struct f2fs_sb_info *sbi, int type,
|
||||
unsigned int start, unsigned int end)
|
||||
{
|
||||
struct curseg_info *curseg = CURSEG_I(sbi, type);
|
||||
unsigned int segno;
|
||||
|
||||
down_read(&SM_I(sbi)->curseg_lock);
|
||||
mutex_lock(&curseg->curseg_mutex);
|
||||
down_write(&SIT_I(sbi)->sentry_lock);
|
||||
|
||||
segno = CURSEG_I(sbi, type)->segno;
|
||||
if (segno < start || segno > end)
|
||||
goto unlock;
|
||||
|
||||
if (f2fs_need_SSR(sbi) && get_ssr_segment(sbi, type))
|
||||
change_curseg(sbi, type);
|
||||
else
|
||||
new_curseg(sbi, type, true);
|
||||
|
||||
stat_inc_seg_type(sbi, curseg);
|
||||
|
||||
locate_dirty_segment(sbi, segno);
|
||||
unlock:
|
||||
up_write(&SIT_I(sbi)->sentry_lock);
|
||||
|
||||
if (segno != curseg->segno)
|
||||
f2fs_notice(sbi, "For resize: curseg of type %d: %u ==> %u",
|
||||
type, segno, curseg->segno);
|
||||
|
||||
mutex_unlock(&curseg->curseg_mutex);
|
||||
up_read(&SM_I(sbi)->curseg_lock);
|
||||
}
|
||||
|
||||
void f2fs_allocate_new_segments(struct f2fs_sb_info *sbi)
|
||||
{
|
||||
struct curseg_info *curseg;
|
||||
|
@ -2772,9 +2822,8 @@ int f2fs_trim_fs(struct f2fs_sb_info *sbi, struct fstrim_range *range)
|
|||
goto out;
|
||||
|
||||
if (is_sbi_flag_set(sbi, SBI_NEED_FSCK)) {
|
||||
f2fs_msg(sbi->sb, KERN_WARNING,
|
||||
"Found FS corruption, run fsck to fix.");
|
||||
return -EIO;
|
||||
f2fs_warn(sbi, "Found FS corruption, run fsck to fix.");
|
||||
return -EFSCORRUPTED;
|
||||
}
|
||||
|
||||
/* start/end segment number in main_area */
|
||||
|
@ -3197,12 +3246,17 @@ int f2fs_inplace_write_data(struct f2fs_io_info *fio)
|
|||
|
||||
if (!IS_DATASEG(get_seg_entry(sbi, segno)->type)) {
|
||||
set_sbi_flag(sbi, SBI_NEED_FSCK);
|
||||
return -EFAULT;
|
||||
f2fs_warn(sbi, "%s: incorrect segment(%u) type, run fsck to fix.",
|
||||
__func__, segno);
|
||||
return -EFSCORRUPTED;
|
||||
}
|
||||
|
||||
stat_inc_inplace_blocks(fio->sbi);
|
||||
|
||||
err = f2fs_submit_page_bio(fio);
|
||||
if (fio->bio)
|
||||
err = f2fs_merge_page_bio(fio);
|
||||
else
|
||||
err = f2fs_submit_page_bio(fio);
|
||||
if (!err) {
|
||||
update_device_state(fio);
|
||||
f2fs_update_iostat(fio->sbi, fio->io_type, F2FS_BLKSIZE);
|
||||
|
@ -3535,8 +3589,11 @@ static int restore_curseg_summaries(struct f2fs_sb_info *sbi)
|
|||
|
||||
/* sanity check for summary blocks */
|
||||
if (nats_in_cursum(nat_j) > NAT_JOURNAL_ENTRIES ||
|
||||
sits_in_cursum(sit_j) > SIT_JOURNAL_ENTRIES)
|
||||
sits_in_cursum(sit_j) > SIT_JOURNAL_ENTRIES) {
|
||||
f2fs_err(sbi, "invalid journal entries nats %u sits %u\n",
|
||||
nats_in_cursum(nat_j), sits_in_cursum(sit_j));
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -3767,7 +3824,7 @@ void f2fs_flush_sit_entries(struct f2fs_sb_info *sbi, struct cp_control *cpc)
|
|||
struct f2fs_journal *journal = curseg->journal;
|
||||
struct sit_entry_set *ses, *tmp;
|
||||
struct list_head *head = &SM_I(sbi)->sit_entry_set;
|
||||
bool to_journal = true;
|
||||
bool to_journal = !is_sbi_flag_set(sbi, SBI_IS_RESIZEFS);
|
||||
struct seg_entry *se;
|
||||
|
||||
down_write(&sit_i->sentry_lock);
|
||||
|
@ -3786,7 +3843,8 @@ void f2fs_flush_sit_entries(struct f2fs_sb_info *sbi, struct cp_control *cpc)
|
|||
* entries, remove all entries from journal and add and account
|
||||
* them in sit entry set.
|
||||
*/
|
||||
if (!__has_cursum_space(journal, sit_i->dirty_sentries, SIT_JOURNAL))
|
||||
if (!__has_cursum_space(journal, sit_i->dirty_sentries, SIT_JOURNAL) ||
|
||||
!to_journal)
|
||||
remove_sits_in_journal(sbi);
|
||||
|
||||
/*
|
||||
|
@ -4101,11 +4159,10 @@ static int build_sit_entries(struct f2fs_sb_info *sbi)
|
|||
|
||||
start = le32_to_cpu(segno_in_journal(journal, i));
|
||||
if (start >= MAIN_SEGS(sbi)) {
|
||||
f2fs_msg(sbi->sb, KERN_ERR,
|
||||
"Wrong journal entry on segno %u",
|
||||
start);
|
||||
f2fs_err(sbi, "Wrong journal entry on segno %u",
|
||||
start);
|
||||
set_sbi_flag(sbi, SBI_NEED_FSCK);
|
||||
err = -EINVAL;
|
||||
err = -EFSCORRUPTED;
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -4142,11 +4199,10 @@ static int build_sit_entries(struct f2fs_sb_info *sbi)
|
|||
up_read(&curseg->journal_rwsem);
|
||||
|
||||
if (!err && total_node_blocks != valid_node_count(sbi)) {
|
||||
f2fs_msg(sbi->sb, KERN_ERR,
|
||||
"SIT is corrupted node# %u vs %u",
|
||||
total_node_blocks, valid_node_count(sbi));
|
||||
f2fs_err(sbi, "SIT is corrupted node# %u vs %u",
|
||||
total_node_blocks, valid_node_count(sbi));
|
||||
set_sbi_flag(sbi, SBI_NEED_FSCK);
|
||||
err = -EINVAL;
|
||||
err = -EFSCORRUPTED;
|
||||
}
|
||||
|
||||
return err;
|
||||
|
@ -4237,6 +4293,39 @@ static int build_dirty_segmap(struct f2fs_sb_info *sbi)
|
|||
return init_victim_secmap(sbi);
|
||||
}
|
||||
|
||||
static int sanity_check_curseg(struct f2fs_sb_info *sbi)
|
||||
{
|
||||
int i;
|
||||
|
||||
/*
|
||||
* In LFS/SSR curseg, .next_blkoff should point to an unused blkaddr;
|
||||
* In LFS curseg, all blkaddr after .next_blkoff should be unused.
|
||||
*/
|
||||
for (i = 0; i < NO_CHECK_TYPE; i++) {
|
||||
struct curseg_info *curseg = CURSEG_I(sbi, i);
|
||||
struct seg_entry *se = get_seg_entry(sbi, curseg->segno);
|
||||
unsigned int blkofs = curseg->next_blkoff;
|
||||
|
||||
if (f2fs_test_bit(blkofs, se->cur_valid_map))
|
||||
goto out;
|
||||
|
||||
if (curseg->alloc_type == SSR)
|
||||
continue;
|
||||
|
||||
for (blkofs += 1; blkofs < sbi->blocks_per_seg; blkofs++) {
|
||||
if (!f2fs_test_bit(blkofs, se->cur_valid_map))
|
||||
continue;
|
||||
out:
|
||||
f2fs_err(sbi,
|
||||
"Current segment's next free block offset is inconsistent with bitmap, logtype:%u, segno:%u, type:%u, next_blkoff:%u, blkofs:%u",
|
||||
i, curseg->segno, curseg->alloc_type,
|
||||
curseg->next_blkoff, blkofs);
|
||||
return -EFSCORRUPTED;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Update min, max modified time for cost-benefit GC algorithm
|
||||
*/
|
||||
|
@ -4332,6 +4421,10 @@ int f2fs_build_segment_manager(struct f2fs_sb_info *sbi)
|
|||
if (err)
|
||||
return err;
|
||||
|
||||
err = sanity_check_curseg(sbi);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
init_min_max_mtime(sbi);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -109,7 +109,7 @@
|
|||
#define START_SEGNO(segno) \
|
||||
(SIT_BLOCK_OFFSET(segno) * SIT_ENTRY_PER_BLOCK)
|
||||
#define SIT_BLK_CNT(sbi) \
|
||||
((MAIN_SEGS(sbi) + SIT_ENTRY_PER_BLOCK - 1) / SIT_ENTRY_PER_BLOCK)
|
||||
DIV_ROUND_UP(MAIN_SEGS(sbi), SIT_ENTRY_PER_BLOCK)
|
||||
#define f2fs_bitmap_size(nr) \
|
||||
(BITS_TO_LONGS(nr) * sizeof(unsigned long))
|
||||
|
||||
|
@ -693,21 +693,19 @@ static inline int check_block_count(struct f2fs_sb_info *sbi,
|
|||
} while (cur_pos < sbi->blocks_per_seg);
|
||||
|
||||
if (unlikely(GET_SIT_VBLOCKS(raw_sit) != valid_blocks)) {
|
||||
f2fs_msg(sbi->sb, KERN_ERR,
|
||||
"Mismatch valid blocks %d vs. %d",
|
||||
GET_SIT_VBLOCKS(raw_sit), valid_blocks);
|
||||
f2fs_err(sbi, "Mismatch valid blocks %d vs. %d",
|
||||
GET_SIT_VBLOCKS(raw_sit), valid_blocks);
|
||||
set_sbi_flag(sbi, SBI_NEED_FSCK);
|
||||
return -EINVAL;
|
||||
return -EFSCORRUPTED;
|
||||
}
|
||||
|
||||
/* check segment usage, and check boundary of a given segment number */
|
||||
if (unlikely(GET_SIT_VBLOCKS(raw_sit) > sbi->blocks_per_seg
|
||||
|| segno > TOTAL_SEGS(sbi) - 1)) {
|
||||
f2fs_msg(sbi->sb, KERN_ERR,
|
||||
"Wrong valid blocks %d or segno %u",
|
||||
GET_SIT_VBLOCKS(raw_sit), segno);
|
||||
f2fs_err(sbi, "Wrong valid blocks %d or segno %u",
|
||||
GET_SIT_VBLOCKS(raw_sit), segno);
|
||||
set_sbi_flag(sbi, SBI_NEED_FSCK);
|
||||
return -EINVAL;
|
||||
return -EFSCORRUPTED;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
648
fs/f2fs/super.c
648
fs/f2fs/super.c
File diff suppressed because it is too large
Load diff
|
@ -68,6 +68,20 @@ static ssize_t dirty_segments_show(struct f2fs_attr *a,
|
|||
(unsigned long long)(dirty_segments(sbi)));
|
||||
}
|
||||
|
||||
static ssize_t unusable_show(struct f2fs_attr *a,
|
||||
struct f2fs_sb_info *sbi, char *buf)
|
||||
{
|
||||
block_t unusable;
|
||||
|
||||
if (test_opt(sbi, DISABLE_CHECKPOINT))
|
||||
unusable = sbi->unusable_block_count;
|
||||
else
|
||||
unusable = f2fs_get_unusable_blocks(sbi);
|
||||
return snprintf(buf, PAGE_SIZE, "%llu\n",
|
||||
(unsigned long long)unusable);
|
||||
}
|
||||
|
||||
|
||||
static ssize_t lifetime_write_kbytes_show(struct f2fs_attr *a,
|
||||
struct f2fs_sb_info *sbi, char *buf)
|
||||
{
|
||||
|
@ -440,6 +454,7 @@ F2FS_GENERAL_RO_ATTR(dirty_segments);
|
|||
F2FS_GENERAL_RO_ATTR(lifetime_write_kbytes);
|
||||
F2FS_GENERAL_RO_ATTR(features);
|
||||
F2FS_GENERAL_RO_ATTR(current_reserved_blocks);
|
||||
F2FS_GENERAL_RO_ATTR(unusable);
|
||||
|
||||
#ifdef CONFIG_FS_ENCRYPTION
|
||||
F2FS_FEATURE_RO_ATTR(encryption, FEAT_CRYPTO);
|
||||
|
@ -495,6 +510,7 @@ static struct attribute *f2fs_attrs[] = {
|
|||
ATTR_LIST(inject_type),
|
||||
#endif
|
||||
ATTR_LIST(dirty_segments),
|
||||
ATTR_LIST(unusable),
|
||||
ATTR_LIST(lifetime_write_kbytes),
|
||||
ATTR_LIST(features),
|
||||
ATTR_LIST(reserved_blocks),
|
||||
|
@ -566,8 +582,7 @@ static int __maybe_unused segment_info_seq_show(struct seq_file *seq,
|
|||
|
||||
if ((i % 10) == 0)
|
||||
seq_printf(seq, "%-10d", i);
|
||||
seq_printf(seq, "%d|%-3u", se->type,
|
||||
get_valid_blocks(sbi, i, false));
|
||||
seq_printf(seq, "%d|%-3u", se->type, se->valid_blocks);
|
||||
if ((i % 10) == 9 || i == (total_segs - 1))
|
||||
seq_putc(seq, '\n');
|
||||
else
|
||||
|
@ -593,8 +608,7 @@ static int __maybe_unused segment_bits_seq_show(struct seq_file *seq,
|
|||
struct seg_entry *se = get_seg_entry(sbi, i);
|
||||
|
||||
seq_printf(seq, "%-10d", i);
|
||||
seq_printf(seq, "%d|%-3u|", se->type,
|
||||
get_valid_blocks(sbi, i, false));
|
||||
seq_printf(seq, "%d|%-3u|", se->type, se->valid_blocks);
|
||||
for (j = 0; j < SIT_VBLOCK_MAP_SIZE; j++)
|
||||
seq_printf(seq, " %.2x", se->cur_valid_map[j]);
|
||||
seq_putc(seq, '\n');
|
||||
|
|
|
@ -346,7 +346,10 @@ static int lookup_all_xattrs(struct inode *inode, struct page *ipage,
|
|||
|
||||
*xe = __find_xattr(cur_addr, last_txattr_addr, index, len, name);
|
||||
if (!*xe) {
|
||||
err = -EFAULT;
|
||||
f2fs_err(F2FS_I_SB(inode), "inode (%lu) has corrupted xattr",
|
||||
inode->i_ino);
|
||||
set_sbi_flag(F2FS_I_SB(inode), SBI_NEED_FSCK);
|
||||
err = -EFSCORRUPTED;
|
||||
goto out;
|
||||
}
|
||||
check:
|
||||
|
@ -622,7 +625,10 @@ static int __f2fs_setxattr(struct inode *inode, int index,
|
|||
/* find entry with wanted name. */
|
||||
here = __find_xattr(base_addr, last_base_addr, index, len, name);
|
||||
if (!here) {
|
||||
error = -EFAULT;
|
||||
f2fs_err(F2FS_I_SB(inode), "inode (%lu) has corrupted xattr",
|
||||
inode->i_ino);
|
||||
set_sbi_flag(F2FS_I_SB(inode), SBI_NEED_FSCK);
|
||||
error = -EFSCORRUPTED;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
|
|
86
fs/inode.c
86
fs/inode.c
|
@ -2161,3 +2161,89 @@ struct timespec64 current_time(struct inode *inode)
|
|||
return timespec64_trunc(now, inode->i_sb->s_time_gran);
|
||||
}
|
||||
EXPORT_SYMBOL(current_time);
|
||||
|
||||
/*
|
||||
* Generic function to check FS_IOC_SETFLAGS values and reject any invalid
|
||||
* configurations.
|
||||
*
|
||||
* Note: the caller should be holding i_mutex, or else be sure that they have
|
||||
* exclusive access to the inode structure.
|
||||
*/
|
||||
int vfs_ioc_setflags_prepare(struct inode *inode, unsigned int oldflags,
|
||||
unsigned int flags)
|
||||
{
|
||||
/*
|
||||
* The IMMUTABLE and APPEND_ONLY flags can only be changed by
|
||||
* the relevant capability.
|
||||
*
|
||||
* This test looks nicer. Thanks to Pauline Middelink
|
||||
*/
|
||||
if ((flags ^ oldflags) & (FS_APPEND_FL | FS_IMMUTABLE_FL) &&
|
||||
!capable(CAP_LINUX_IMMUTABLE))
|
||||
return -EPERM;
|
||||
|
||||
return 0;
|
||||
}
|
||||
EXPORT_SYMBOL(vfs_ioc_setflags_prepare);
|
||||
|
||||
/*
|
||||
* Generic function to check FS_IOC_FSSETXATTR values and reject any invalid
|
||||
* configurations.
|
||||
*
|
||||
* Note: the caller should be holding i_mutex, or else be sure that they have
|
||||
* exclusive access to the inode structure.
|
||||
*/
|
||||
int vfs_ioc_fssetxattr_check(struct inode *inode, const struct fsxattr *old_fa,
|
||||
struct fsxattr *fa)
|
||||
{
|
||||
/*
|
||||
* Can't modify an immutable/append-only file unless we have
|
||||
* appropriate permission.
|
||||
*/
|
||||
if ((old_fa->fsx_xflags ^ fa->fsx_xflags) &
|
||||
(FS_XFLAG_IMMUTABLE | FS_XFLAG_APPEND) &&
|
||||
!capable(CAP_LINUX_IMMUTABLE))
|
||||
return -EPERM;
|
||||
|
||||
/*
|
||||
* Project Quota ID state is only allowed to change from within the init
|
||||
* namespace. Enforce that restriction only if we are trying to change
|
||||
* the quota ID state. Everything else is allowed in user namespaces.
|
||||
*/
|
||||
if (current_user_ns() != &init_user_ns) {
|
||||
if (old_fa->fsx_projid != fa->fsx_projid)
|
||||
return -EINVAL;
|
||||
if ((old_fa->fsx_xflags ^ fa->fsx_xflags) &
|
||||
FS_XFLAG_PROJINHERIT)
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
/* Check extent size hints. */
|
||||
if ((fa->fsx_xflags & FS_XFLAG_EXTSIZE) && !S_ISREG(inode->i_mode))
|
||||
return -EINVAL;
|
||||
|
||||
if ((fa->fsx_xflags & FS_XFLAG_EXTSZINHERIT) &&
|
||||
!S_ISDIR(inode->i_mode))
|
||||
return -EINVAL;
|
||||
|
||||
if ((fa->fsx_xflags & FS_XFLAG_COWEXTSIZE) &&
|
||||
!S_ISREG(inode->i_mode) && !S_ISDIR(inode->i_mode))
|
||||
return -EINVAL;
|
||||
|
||||
/*
|
||||
* It is only valid to set the DAX flag on regular files and
|
||||
* directories on filesystems.
|
||||
*/
|
||||
if ((fa->fsx_xflags & FS_XFLAG_DAX) &&
|
||||
!(S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode)))
|
||||
return -EINVAL;
|
||||
|
||||
/* Extent size hints of zero turn off the flags. */
|
||||
if (fa->fsx_extsize == 0)
|
||||
fa->fsx_xflags &= ~(FS_XFLAG_EXTSIZE | FS_XFLAG_EXTSZINHERIT);
|
||||
if (fa->fsx_cowextsize == 0)
|
||||
fa->fsx_xflags &= ~FS_XFLAG_COWEXTSIZE;
|
||||
|
||||
return 0;
|
||||
}
|
||||
EXPORT_SYMBOL(vfs_ioc_fssetxattr_check);
|
||||
|
|
|
@ -1078,7 +1078,7 @@ const char *get_link(struct nameidata *nd)
|
|||
return ERR_PTR(error);
|
||||
|
||||
nd->last_type = LAST_BIND;
|
||||
res = inode->i_link;
|
||||
res = READ_ONCE(inode->i_link);
|
||||
if (!res) {
|
||||
const char * (*get)(struct dentry *, struct inode *,
|
||||
struct delayed_call *);
|
||||
|
@ -4809,7 +4809,7 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen)
|
|||
spin_unlock(&inode->i_lock);
|
||||
}
|
||||
|
||||
link = inode->i_link;
|
||||
link = READ_ONCE(inode->i_link);
|
||||
if (!link) {
|
||||
link = inode->i_op->get_link(dentry, inode, &done);
|
||||
if (IS_ERR(link))
|
||||
|
|
|
@ -220,11 +220,9 @@ static struct dentry *ubifs_lookup(struct inode *dir, struct dentry *dentry,
|
|||
|
||||
dbg_gen("'%pd' in dir ino %lu", dentry, dir->i_ino);
|
||||
|
||||
err = fscrypt_prepare_lookup(dir, dentry, flags);
|
||||
if (err)
|
||||
return ERR_PTR(err);
|
||||
|
||||
err = fscrypt_setup_filename(dir, &dentry->d_name, 1, &nm);
|
||||
err = fscrypt_prepare_lookup(dir, dentry, &nm);
|
||||
if (err == -ENOENT)
|
||||
return d_splice_alias(NULL, dentry);
|
||||
if (err)
|
||||
return ERR_PTR(err);
|
||||
|
||||
|
|
|
@ -276,6 +276,8 @@ static void ubifs_i_callback(struct rcu_head *head)
|
|||
{
|
||||
struct inode *inode = container_of(head, struct inode, i_rcu);
|
||||
struct ubifs_inode *ui = ubifs_inode(inode);
|
||||
|
||||
fscrypt_free_inode(inode);
|
||||
kmem_cache_free(ubifs_inode_slab, ui);
|
||||
}
|
||||
|
||||
|
|
|
@ -211,7 +211,7 @@ struct dentry_operations {
|
|||
|
||||
#define DCACHE_MAY_FREE 0x00800000
|
||||
#define DCACHE_FALLTHRU 0x01000000 /* Fall through to lower layer */
|
||||
#define DCACHE_ENCRYPTED_WITH_KEY 0x02000000 /* dir is encrypted with a valid key */
|
||||
#define DCACHE_ENCRYPTED_NAME 0x02000000 /* Encrypted name (dir key was unavailable) */
|
||||
#define DCACHE_OP_REAL 0x04000000
|
||||
|
||||
#define DCACHE_PAR_LOOKUP 0x10000000 /* being looked up (with parent locked shared) */
|
||||
|
|
|
@ -3492,4 +3492,16 @@ extern void inode_nohighmem(struct inode *inode);
|
|||
extern int vfs_fadvise(struct file *file, loff_t offset, loff_t len,
|
||||
int advice);
|
||||
|
||||
int vfs_ioc_setflags_prepare(struct inode *inode, unsigned int oldflags,
|
||||
unsigned int flags);
|
||||
|
||||
int vfs_ioc_fssetxattr_check(struct inode *inode, const struct fsxattr *old_fa,
|
||||
struct fsxattr *fa);
|
||||
|
||||
static inline void simple_fill_fsxattr(struct fsxattr *fa, __u32 xflags)
|
||||
{
|
||||
memset(fa, 0, sizeof(*fa));
|
||||
fa->fsx_xflags = xflags;
|
||||
}
|
||||
|
||||
#endif /* _LINUX_FS_H */
|
||||
|
|
|
@ -33,6 +33,7 @@ struct fscrypt_name {
|
|||
u32 hash;
|
||||
u32 minor_hash;
|
||||
struct fscrypt_str crypto_buf;
|
||||
bool is_ciphertext_name;
|
||||
};
|
||||
|
||||
#define FSTR_INIT(n, l) { .name = n, .len = l }
|
||||
|
@ -79,7 +80,8 @@ struct fscrypt_ctx {
|
|||
|
||||
static inline bool fscrypt_has_encryption_key(const struct inode *inode)
|
||||
{
|
||||
return (inode->i_crypt_info != NULL);
|
||||
/* pairs with cmpxchg_release() in fscrypt_get_encryption_info() */
|
||||
return READ_ONCE(inode->i_crypt_info) != NULL;
|
||||
}
|
||||
|
||||
static inline bool fscrypt_dummy_context_enabled(struct inode *inode)
|
||||
|
@ -88,9 +90,21 @@ static inline bool fscrypt_dummy_context_enabled(struct inode *inode)
|
|||
inode->i_sb->s_cop->dummy_context(inode);
|
||||
}
|
||||
|
||||
/*
|
||||
* When d_splice_alias() moves a directory's encrypted alias to its decrypted
|
||||
* alias as a result of the encryption key being added, DCACHE_ENCRYPTED_NAME
|
||||
* must be cleared. Note that we don't have to support arbitrary moves of this
|
||||
* flag because fscrypt doesn't allow encrypted aliases to be the source or
|
||||
* target of a rename().
|
||||
*/
|
||||
static inline void fscrypt_handle_d_move(struct dentry *dentry)
|
||||
{
|
||||
dentry->d_flags &= ~DCACHE_ENCRYPTED_NAME;
|
||||
}
|
||||
|
||||
/* crypto.c */
|
||||
extern void fscrypt_enqueue_decrypt_work(struct work_struct *);
|
||||
extern struct fscrypt_ctx *fscrypt_get_ctx(const struct inode *, gfp_t);
|
||||
extern struct fscrypt_ctx *fscrypt_get_ctx(gfp_t);
|
||||
extern void fscrypt_release_ctx(struct fscrypt_ctx *);
|
||||
extern struct page *fscrypt_encrypt_page(const struct inode *, struct page *,
|
||||
unsigned int, unsigned int,
|
||||
|
@ -114,6 +128,7 @@ extern int fscrypt_inherit_context(struct inode *, struct inode *,
|
|||
/* keyinfo.c */
|
||||
extern int fscrypt_get_encryption_info(struct inode *);
|
||||
extern void fscrypt_put_encryption_info(struct inode *);
|
||||
extern void fscrypt_free_inode(struct inode *);
|
||||
|
||||
/* fname.c */
|
||||
extern int fscrypt_setup_filename(struct inode *, const struct qstr *,
|
||||
|
@ -214,13 +229,15 @@ extern int fscrypt_zeroout_range(const struct inode *, pgoff_t, sector_t,
|
|||
|
||||
/* hooks.c */
|
||||
extern int fscrypt_file_open(struct inode *inode, struct file *filp);
|
||||
extern int __fscrypt_prepare_link(struct inode *inode, struct inode *dir);
|
||||
extern int __fscrypt_prepare_link(struct inode *inode, struct inode *dir,
|
||||
struct dentry *dentry);
|
||||
extern int __fscrypt_prepare_rename(struct inode *old_dir,
|
||||
struct dentry *old_dentry,
|
||||
struct inode *new_dir,
|
||||
struct dentry *new_dentry,
|
||||
unsigned int flags);
|
||||
extern int __fscrypt_prepare_lookup(struct inode *dir, struct dentry *dentry);
|
||||
extern int __fscrypt_prepare_lookup(struct inode *dir, struct dentry *dentry,
|
||||
struct fscrypt_name *fname);
|
||||
extern int __fscrypt_prepare_symlink(struct inode *dir, unsigned int len,
|
||||
unsigned int max_len,
|
||||
struct fscrypt_str *disk_link);
|
||||
|
@ -242,13 +259,16 @@ static inline bool fscrypt_dummy_context_enabled(struct inode *inode)
|
|||
return false;
|
||||
}
|
||||
|
||||
static inline void fscrypt_handle_d_move(struct dentry *dentry)
|
||||
{
|
||||
}
|
||||
|
||||
/* crypto.c */
|
||||
static inline void fscrypt_enqueue_decrypt_work(struct work_struct *work)
|
||||
{
|
||||
}
|
||||
|
||||
static inline struct fscrypt_ctx *fscrypt_get_ctx(const struct inode *inode,
|
||||
gfp_t gfp_flags)
|
||||
static inline struct fscrypt_ctx *fscrypt_get_ctx(gfp_t gfp_flags)
|
||||
{
|
||||
return ERR_PTR(-EOPNOTSUPP);
|
||||
}
|
||||
|
@ -322,6 +342,10 @@ static inline void fscrypt_put_encryption_info(struct inode *inode)
|
|||
return;
|
||||
}
|
||||
|
||||
static inline void fscrypt_free_inode(struct inode *inode)
|
||||
{
|
||||
}
|
||||
|
||||
/* fname.c */
|
||||
static inline int fscrypt_setup_filename(struct inode *dir,
|
||||
const struct qstr *iname,
|
||||
|
@ -330,7 +354,7 @@ static inline int fscrypt_setup_filename(struct inode *dir,
|
|||
if (IS_ENCRYPTED(dir))
|
||||
return -EOPNOTSUPP;
|
||||
|
||||
memset(fname, 0, sizeof(struct fscrypt_name));
|
||||
memset(fname, 0, sizeof(*fname));
|
||||
fname->usr_fname = iname;
|
||||
fname->disk_name.name = (unsigned char *)iname->name;
|
||||
fname->disk_name.len = iname->len;
|
||||
|
@ -401,8 +425,8 @@ static inline int fscrypt_file_open(struct inode *inode, struct file *filp)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static inline int __fscrypt_prepare_link(struct inode *inode,
|
||||
struct inode *dir)
|
||||
static inline int __fscrypt_prepare_link(struct inode *inode, struct inode *dir,
|
||||
struct dentry *dentry)
|
||||
{
|
||||
return -EOPNOTSUPP;
|
||||
}
|
||||
|
@ -417,7 +441,8 @@ static inline int __fscrypt_prepare_rename(struct inode *old_dir,
|
|||
}
|
||||
|
||||
static inline int __fscrypt_prepare_lookup(struct inode *dir,
|
||||
struct dentry *dentry)
|
||||
struct dentry *dentry,
|
||||
struct fscrypt_name *fname)
|
||||
{
|
||||
return -EOPNOTSUPP;
|
||||
}
|
||||
|
@ -497,7 +522,7 @@ static inline int fscrypt_prepare_link(struct dentry *old_dentry,
|
|||
struct dentry *dentry)
|
||||
{
|
||||
if (IS_ENCRYPTED(dir))
|
||||
return __fscrypt_prepare_link(d_inode(old_dentry), dir);
|
||||
return __fscrypt_prepare_link(d_inode(old_dentry), dir, dentry);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -538,27 +563,32 @@ static inline int fscrypt_prepare_rename(struct inode *old_dir,
|
|||
* fscrypt_prepare_lookup - prepare to lookup a name in a possibly-encrypted directory
|
||||
* @dir: directory being searched
|
||||
* @dentry: filename being looked up
|
||||
* @flags: lookup flags
|
||||
* @fname: (output) the name to use to search the on-disk directory
|
||||
*
|
||||
* Prepare for ->lookup() in a directory which may be encrypted. Lookups can be
|
||||
* done with or without the directory's encryption key; without the key,
|
||||
* Prepare for ->lookup() in a directory which may be encrypted by determining
|
||||
* the name that will actually be used to search the directory on-disk. Lookups
|
||||
* can be done with or without the directory's encryption key; without the key,
|
||||
* filenames are presented in encrypted form. Therefore, we'll try to set up
|
||||
* the directory's encryption key, but even without it the lookup can continue.
|
||||
*
|
||||
* To allow invalidating stale dentries if the directory's encryption key is
|
||||
* added later, we also install a custom ->d_revalidate() method and use the
|
||||
* DCACHE_ENCRYPTED_WITH_KEY flag to indicate whether a given dentry is a
|
||||
* plaintext name (flag set) or a ciphertext name (flag cleared).
|
||||
* This also installs a custom ->d_revalidate() method which will invalidate the
|
||||
* dentry if it was created without the key and the key is later added.
|
||||
*
|
||||
* Return: 0 on success, -errno if a problem occurred while setting up the
|
||||
* encryption key
|
||||
* Return: 0 on success; -ENOENT if key is unavailable but the filename isn't a
|
||||
* correctly formed encoded ciphertext name, so a negative dentry should be
|
||||
* created; or another -errno code.
|
||||
*/
|
||||
static inline int fscrypt_prepare_lookup(struct inode *dir,
|
||||
struct dentry *dentry,
|
||||
unsigned int flags)
|
||||
struct fscrypt_name *fname)
|
||||
{
|
||||
if (IS_ENCRYPTED(dir))
|
||||
return __fscrypt_prepare_lookup(dir, dentry);
|
||||
return __fscrypt_prepare_lookup(dir, dentry, fname);
|
||||
|
||||
memset(fname, 0, sizeof(*fname));
|
||||
fname->usr_fname = &dentry->d_name;
|
||||
fname->disk_name.name = (unsigned char *)dentry->d_name.name;
|
||||
fname->disk_name.len = dentry->d_name.len;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -1029,8 +1029,8 @@ DECLARE_EVENT_CLASS(f2fs__submit_page_bio,
|
|||
),
|
||||
|
||||
TP_fast_assign(
|
||||
__entry->dev = page->mapping->host->i_sb->s_dev;
|
||||
__entry->ino = page->mapping->host->i_ino;
|
||||
__entry->dev = page_file_mapping(page)->host->i_sb->s_dev;
|
||||
__entry->ino = page_file_mapping(page)->host->i_ino;
|
||||
__entry->index = page->index;
|
||||
__entry->old_blkaddr = fio->old_blkaddr;
|
||||
__entry->new_blkaddr = fio->new_blkaddr;
|
||||
|
@ -1217,10 +1217,11 @@ DECLARE_EVENT_CLASS(f2fs__page,
|
|||
),
|
||||
|
||||
TP_fast_assign(
|
||||
__entry->dev = page->mapping->host->i_sb->s_dev;
|
||||
__entry->ino = page->mapping->host->i_ino;
|
||||
__entry->dev = page_file_mapping(page)->host->i_sb->s_dev;
|
||||
__entry->ino = page_file_mapping(page)->host->i_ino;
|
||||
__entry->type = type;
|
||||
__entry->dir = S_ISDIR(page->mapping->host->i_mode);
|
||||
__entry->dir =
|
||||
S_ISDIR(page_file_mapping(page)->host->i_mode);
|
||||
__entry->index = page->index;
|
||||
__entry->dirty = PageDirty(page);
|
||||
__entry->uptodate = PageUptodate(page);
|
||||
|
|
Loading…
Add table
Reference in a new issue