Commit 942d33da authored by Linus Torvalds's avatar Linus Torvalds

Merge tag 'f2fs-for-v3.10' of git://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs

Pull f2fs updates from Jaegeuk Kim:
 "This patch-set includes the following major enhancement patches.
   - introduce a new gloabl lock scheme
   - add tracepoints on several major functions
   - fix the overall cleaning process focused on victim selection
   - apply the block plugging to merge IOs as much as possible
   - enhance management of free nids and its list
   - enhance the readahead mode for node pages
   - address several cretical deadlock conditions
   - reduce lock_page calls

  The other minor bug fixes and enhancements are as follows.
   - calculation mistakes: overflow
   - bio types: READ, READA, and READ_SYNC
   - fix the recovery flow, data races, and null pointer errors"

* tag 'f2fs-for-v3.10' of git://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs: (68 commits)
  f2fs: cover free_nid management with spin_lock
  f2fs: optimize scan_nat_page()
  f2fs: code cleanup for scan_nat_page() and build_free_nids()
  f2fs: bugfix for alloc_nid_failed()
  f2fs: recover when journal contains deleted files
  f2fs: continue to mount after failing recovery
  f2fs: avoid deadlock during evict after f2fs_gc
  f2fs: modify the number of issued pages to merge IOs
  f2fs: remove useless #include <linux/proc_fs.h> as we're now using sysfs as debug entry.
  f2fs: fix inconsistent using of NM_WOUT_THRESHOLD
  f2fs: check truncation of mapping after lock_page
  f2fs: enhance alloc_nid and build_free_nids flows
  f2fs: add a tracepoint on f2fs_new_inode
  f2fs: check nid == 0 in add_free_nid
  f2fs: add REQ_META about metadata requests for submit
  f2fs: give a chance to merge IOs by IO scheduler
  f2fs: avoid frequent background GC
  f2fs: add tracepoints to debug checkpoint request
  f2fs: add tracepoints for write page operations
  f2fs: add tracepoints to debug the block allocation
  ...
parents 246e6a0d 59bbd474
...@@ -146,7 +146,7 @@ USAGE ...@@ -146,7 +146,7 @@ USAGE
Format options Format options
-------------- --------------
-l [label] : Give a volume label, up to 256 unicode name. -l [label] : Give a volume label, up to 512 unicode name.
-a [0 or 1] : Split start location of each area for heap-based allocation. -a [0 or 1] : Split start location of each area for heap-based allocation.
1 is set by default, which performs this. 1 is set by default, which performs this.
-o [int] : Set overprovision ratio in percent over volume size. -o [int] : Set overprovision ratio in percent over volume size.
...@@ -156,6 +156,8 @@ Format options ...@@ -156,6 +156,8 @@ Format options
-z [int] : Set the number of sections per zone. -z [int] : Set the number of sections per zone.
1 is set by default. 1 is set by default.
-e [str] : Set basic extension list. e.g. "mp3,gif,mov" -e [str] : Set basic extension list. e.g. "mp3,gif,mov"
-t [0 or 1] : Disable discard command or not.
1 is set by default, which conducts discard.
================================================================================ ================================================================================
DESIGN DESIGN
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include "f2fs.h" #include "f2fs.h"
#include "node.h" #include "node.h"
#include "segment.h" #include "segment.h"
#include <trace/events/f2fs.h>
static struct kmem_cache *orphan_entry_slab; static struct kmem_cache *orphan_entry_slab;
static struct kmem_cache *inode_entry_slab; static struct kmem_cache *inode_entry_slab;
...@@ -57,13 +58,19 @@ struct page *get_meta_page(struct f2fs_sb_info *sbi, pgoff_t index) ...@@ -57,13 +58,19 @@ struct page *get_meta_page(struct f2fs_sb_info *sbi, pgoff_t index)
cond_resched(); cond_resched();
goto repeat; goto repeat;
} }
if (f2fs_readpage(sbi, page, index, READ_SYNC)) { if (PageUptodate(page))
goto out;
if (f2fs_readpage(sbi, page, index, READ_SYNC))
goto repeat;
lock_page(page);
if (page->mapping != mapping) {
f2fs_put_page(page, 1); f2fs_put_page(page, 1);
goto repeat; goto repeat;
} }
out:
mark_page_accessed(page); mark_page_accessed(page);
/* We do not allow returning an errorneous page */
return page; return page;
} }
...@@ -541,54 +548,44 @@ void sync_dirty_dir_inodes(struct f2fs_sb_info *sbi) ...@@ -541,54 +548,44 @@ void sync_dirty_dir_inodes(struct f2fs_sb_info *sbi)
*/ */
static void block_operations(struct f2fs_sb_info *sbi) static void block_operations(struct f2fs_sb_info *sbi)
{ {
int t;
struct writeback_control wbc = { struct writeback_control wbc = {
.sync_mode = WB_SYNC_ALL, .sync_mode = WB_SYNC_ALL,
.nr_to_write = LONG_MAX, .nr_to_write = LONG_MAX,
.for_reclaim = 0, .for_reclaim = 0,
}; };
struct blk_plug plug;
/* Stop renaming operation */ blk_start_plug(&plug);
mutex_lock_op(sbi, RENAME);
mutex_lock_op(sbi, DENTRY_OPS);
retry_dents: retry_flush_dents:
/* write all the dirty dentry pages */ mutex_lock_all(sbi);
sync_dirty_dir_inodes(sbi);
mutex_lock_op(sbi, DATA_WRITE); /* write all the dirty dentry pages */
if (get_pages(sbi, F2FS_DIRTY_DENTS)) { if (get_pages(sbi, F2FS_DIRTY_DENTS)) {
mutex_unlock_op(sbi, DATA_WRITE); mutex_unlock_all(sbi);
goto retry_dents; sync_dirty_dir_inodes(sbi);
goto retry_flush_dents;
} }
/* block all the operations */
for (t = DATA_NEW; t <= NODE_TRUNC; t++)
mutex_lock_op(sbi, t);
mutex_lock(&sbi->write_inode);
/* /*
* POR: we should ensure that there is no dirty node pages * POR: we should ensure that there is no dirty node pages
* until finishing nat/sit flush. * until finishing nat/sit flush.
*/ */
retry: retry_flush_nodes:
sync_node_pages(sbi, 0, &wbc); mutex_lock(&sbi->node_write);
mutex_lock_op(sbi, NODE_WRITE);
if (get_pages(sbi, F2FS_DIRTY_NODES)) { if (get_pages(sbi, F2FS_DIRTY_NODES)) {
mutex_unlock_op(sbi, NODE_WRITE); mutex_unlock(&sbi->node_write);
goto retry; sync_node_pages(sbi, 0, &wbc);
goto retry_flush_nodes;
} }
mutex_unlock(&sbi->write_inode); blk_finish_plug(&plug);
} }
static void unblock_operations(struct f2fs_sb_info *sbi) static void unblock_operations(struct f2fs_sb_info *sbi)
{ {
int t; mutex_unlock(&sbi->node_write);
for (t = NODE_WRITE; t >= RENAME; t--) mutex_unlock_all(sbi);
mutex_unlock_op(sbi, t);
} }
static void do_checkpoint(struct f2fs_sb_info *sbi, bool is_umount) static void do_checkpoint(struct f2fs_sb_info *sbi, bool is_umount)
...@@ -727,9 +724,13 @@ void write_checkpoint(struct f2fs_sb_info *sbi, bool is_umount) ...@@ -727,9 +724,13 @@ void write_checkpoint(struct f2fs_sb_info *sbi, bool is_umount)
struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi); struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi);
unsigned long long ckpt_ver; unsigned long long ckpt_ver;
trace_f2fs_write_checkpoint(sbi->sb, is_umount, "start block_ops");
mutex_lock(&sbi->cp_mutex); mutex_lock(&sbi->cp_mutex);
block_operations(sbi); block_operations(sbi);
trace_f2fs_write_checkpoint(sbi->sb, is_umount, "finish block_ops");
f2fs_submit_bio(sbi, DATA, true); f2fs_submit_bio(sbi, DATA, true);
f2fs_submit_bio(sbi, NODE, true); f2fs_submit_bio(sbi, NODE, true);
f2fs_submit_bio(sbi, META, true); f2fs_submit_bio(sbi, META, true);
...@@ -746,13 +747,13 @@ void write_checkpoint(struct f2fs_sb_info *sbi, bool is_umount) ...@@ -746,13 +747,13 @@ void write_checkpoint(struct f2fs_sb_info *sbi, bool is_umount)
flush_nat_entries(sbi); flush_nat_entries(sbi);
flush_sit_entries(sbi); flush_sit_entries(sbi);
reset_victim_segmap(sbi);
/* unlock all the fs_lock[] in do_checkpoint() */ /* unlock all the fs_lock[] in do_checkpoint() */
do_checkpoint(sbi, is_umount); do_checkpoint(sbi, is_umount);
unblock_operations(sbi); unblock_operations(sbi);
mutex_unlock(&sbi->cp_mutex); mutex_unlock(&sbi->cp_mutex);
trace_f2fs_write_checkpoint(sbi->sb, is_umount, "finish checkpoint");
} }
void init_orphan_info(struct f2fs_sb_info *sbi) void init_orphan_info(struct f2fs_sb_info *sbi)
......
This diff is collapsed.
...@@ -13,7 +13,6 @@ ...@@ -13,7 +13,6 @@
#include <linux/fs.h> #include <linux/fs.h>
#include <linux/backing-dev.h> #include <linux/backing-dev.h>
#include <linux/proc_fs.h>
#include <linux/f2fs_fs.h> #include <linux/f2fs_fs.h>
#include <linux/blkdev.h> #include <linux/blkdev.h>
#include <linux/debugfs.h> #include <linux/debugfs.h>
...@@ -106,7 +105,7 @@ static void update_sit_info(struct f2fs_sb_info *sbi) ...@@ -106,7 +105,7 @@ static void update_sit_info(struct f2fs_sb_info *sbi)
} }
} }
mutex_unlock(&sit_i->sentry_lock); mutex_unlock(&sit_i->sentry_lock);
dist = sbi->total_sections * hblks_per_sec * hblks_per_sec / 100; dist = TOTAL_SECS(sbi) * hblks_per_sec * hblks_per_sec / 100;
si->bimodal = bimodal / dist; si->bimodal = bimodal / dist;
if (si->dirty_count) if (si->dirty_count)
si->avg_vblocks = total_vblocks / ndirty; si->avg_vblocks = total_vblocks / ndirty;
...@@ -138,14 +137,13 @@ static void update_mem_info(struct f2fs_sb_info *sbi) ...@@ -138,14 +137,13 @@ static void update_mem_info(struct f2fs_sb_info *sbi)
si->base_mem += f2fs_bitmap_size(TOTAL_SEGS(sbi)); si->base_mem += f2fs_bitmap_size(TOTAL_SEGS(sbi));
si->base_mem += 2 * SIT_VBLOCK_MAP_SIZE * TOTAL_SEGS(sbi); si->base_mem += 2 * SIT_VBLOCK_MAP_SIZE * TOTAL_SEGS(sbi);
if (sbi->segs_per_sec > 1) if (sbi->segs_per_sec > 1)
si->base_mem += sbi->total_sections * si->base_mem += TOTAL_SECS(sbi) * sizeof(struct sec_entry);
sizeof(struct sec_entry);
si->base_mem += __bitmap_size(sbi, SIT_BITMAP); si->base_mem += __bitmap_size(sbi, SIT_BITMAP);
/* build free segmap */ /* build free segmap */
si->base_mem += sizeof(struct free_segmap_info); si->base_mem += sizeof(struct free_segmap_info);
si->base_mem += f2fs_bitmap_size(TOTAL_SEGS(sbi)); si->base_mem += f2fs_bitmap_size(TOTAL_SEGS(sbi));
si->base_mem += f2fs_bitmap_size(sbi->total_sections); si->base_mem += f2fs_bitmap_size(TOTAL_SECS(sbi));
/* build curseg */ /* build curseg */
si->base_mem += sizeof(struct curseg_info) * NR_CURSEG_TYPE; si->base_mem += sizeof(struct curseg_info) * NR_CURSEG_TYPE;
...@@ -154,7 +152,7 @@ static void update_mem_info(struct f2fs_sb_info *sbi) ...@@ -154,7 +152,7 @@ static void update_mem_info(struct f2fs_sb_info *sbi)
/* build dirty segmap */ /* build dirty segmap */
si->base_mem += sizeof(struct dirty_seglist_info); si->base_mem += sizeof(struct dirty_seglist_info);
si->base_mem += NR_DIRTY_TYPE * f2fs_bitmap_size(TOTAL_SEGS(sbi)); si->base_mem += NR_DIRTY_TYPE * f2fs_bitmap_size(TOTAL_SEGS(sbi));
si->base_mem += 2 * f2fs_bitmap_size(TOTAL_SEGS(sbi)); si->base_mem += f2fs_bitmap_size(TOTAL_SECS(sbi));
/* buld nm */ /* buld nm */
si->base_mem += sizeof(struct f2fs_nm_info); si->base_mem += sizeof(struct f2fs_nm_info);
......
...@@ -148,7 +148,7 @@ static struct f2fs_dir_entry *find_in_level(struct inode *dir, ...@@ -148,7 +148,7 @@ static struct f2fs_dir_entry *find_in_level(struct inode *dir,
for (; bidx < end_block; bidx++) { for (; bidx < end_block; bidx++) {
/* no need to allocate new dentry pages to all the indices */ /* no need to allocate new dentry pages to all the indices */
dentry_page = find_data_page(dir, bidx); dentry_page = find_data_page(dir, bidx, true);
if (IS_ERR(dentry_page)) { if (IS_ERR(dentry_page)) {
room = true; room = true;
continue; continue;
...@@ -189,6 +189,9 @@ struct f2fs_dir_entry *f2fs_find_entry(struct inode *dir, ...@@ -189,6 +189,9 @@ struct f2fs_dir_entry *f2fs_find_entry(struct inode *dir,
unsigned int max_depth; unsigned int max_depth;
unsigned int level; unsigned int level;
if (namelen > F2FS_NAME_LEN)
return NULL;
if (npages == 0) if (npages == 0)
return NULL; return NULL;
...@@ -246,9 +249,6 @@ ino_t f2fs_inode_by_name(struct inode *dir, struct qstr *qstr) ...@@ -246,9 +249,6 @@ ino_t f2fs_inode_by_name(struct inode *dir, struct qstr *qstr)
void f2fs_set_link(struct inode *dir, struct f2fs_dir_entry *de, void f2fs_set_link(struct inode *dir, struct f2fs_dir_entry *de,
struct page *page, struct inode *inode) struct page *page, struct inode *inode)
{ {
struct f2fs_sb_info *sbi = F2FS_SB(dir->i_sb);
mutex_lock_op(sbi, DENTRY_OPS);
lock_page(page); lock_page(page);
wait_on_page_writeback(page); wait_on_page_writeback(page);
de->ino = cpu_to_le32(inode->i_ino); de->ino = cpu_to_le32(inode->i_ino);
...@@ -262,7 +262,6 @@ void f2fs_set_link(struct inode *dir, struct f2fs_dir_entry *de, ...@@ -262,7 +262,6 @@ void f2fs_set_link(struct inode *dir, struct f2fs_dir_entry *de,
F2FS_I(inode)->i_pino = dir->i_ino; F2FS_I(inode)->i_pino = dir->i_ino;
f2fs_put_page(page, 1); f2fs_put_page(page, 1);
mutex_unlock_op(sbi, DENTRY_OPS);
} }
void init_dent_inode(const struct qstr *name, struct page *ipage) void init_dent_inode(const struct qstr *name, struct page *ipage)
...@@ -281,6 +280,43 @@ void init_dent_inode(const struct qstr *name, struct page *ipage) ...@@ -281,6 +280,43 @@ void init_dent_inode(const struct qstr *name, struct page *ipage)
set_page_dirty(ipage); set_page_dirty(ipage);
} }
static int make_empty_dir(struct inode *inode, struct inode *parent)
{
struct page *dentry_page;
struct f2fs_dentry_block *dentry_blk;
struct f2fs_dir_entry *de;
void *kaddr;
dentry_page = get_new_data_page(inode, 0, true);
if (IS_ERR(dentry_page))
return PTR_ERR(dentry_page);
kaddr = kmap_atomic(dentry_page);
dentry_blk = (struct f2fs_dentry_block *)kaddr;
de = &dentry_blk->dentry[0];
de->name_len = cpu_to_le16(1);
de->hash_code = 0;
de->ino = cpu_to_le32(inode->i_ino);
memcpy(dentry_blk->filename[0], ".", 1);
set_de_type(de, inode);
de = &dentry_blk->dentry[1];
de->hash_code = 0;
de->name_len = cpu_to_le16(2);
de->ino = cpu_to_le32(parent->i_ino);
memcpy(dentry_blk->filename[1], "..", 2);
set_de_type(de, inode);
test_and_set_bit_le(0, &dentry_blk->dentry_bitmap);
test_and_set_bit_le(1, &dentry_blk->dentry_bitmap);
kunmap_atomic(kaddr);
set_page_dirty(dentry_page);
f2fs_put_page(dentry_page, 1);
return 0;
}
static int init_inode_metadata(struct inode *inode, static int init_inode_metadata(struct inode *inode,
struct inode *dir, const struct qstr *name) struct inode *dir, const struct qstr *name)
{ {
...@@ -291,7 +327,7 @@ static int init_inode_metadata(struct inode *inode, ...@@ -291,7 +327,7 @@ static int init_inode_metadata(struct inode *inode,
return err; return err;
if (S_ISDIR(inode->i_mode)) { if (S_ISDIR(inode->i_mode)) {
err = f2fs_make_empty(inode, dir); err = make_empty_dir(inode, dir);
if (err) { if (err) {
remove_inode_page(inode); remove_inode_page(inode);
return err; return err;
...@@ -314,7 +350,7 @@ static int init_inode_metadata(struct inode *inode, ...@@ -314,7 +350,7 @@ static int init_inode_metadata(struct inode *inode,
} }
if (is_inode_flag_set(F2FS_I(inode), FI_INC_LINK)) { if (is_inode_flag_set(F2FS_I(inode), FI_INC_LINK)) {
inc_nlink(inode); inc_nlink(inode);
f2fs_write_inode(inode, NULL); update_inode_page(inode);
} }
return 0; return 0;
} }
...@@ -338,7 +374,7 @@ static void update_parent_metadata(struct inode *dir, struct inode *inode, ...@@ -338,7 +374,7 @@ static void update_parent_metadata(struct inode *dir, struct inode *inode,
} }
if (need_dir_update) if (need_dir_update)
f2fs_write_inode(dir, NULL); update_inode_page(dir);
else else
mark_inode_dirty(dir); mark_inode_dirty(dir);
...@@ -370,6 +406,10 @@ static int room_for_filename(struct f2fs_dentry_block *dentry_blk, int slots) ...@@ -370,6 +406,10 @@ static int room_for_filename(struct f2fs_dentry_block *dentry_blk, int slots)
goto next; goto next;
} }
/*
* Caller should grab and release a mutex by calling mutex_lock_op() and
* mutex_unlock_op().
*/
int __f2fs_add_link(struct inode *dir, const struct qstr *name, struct inode *inode) int __f2fs_add_link(struct inode *dir, const struct qstr *name, struct inode *inode)
{ {
unsigned int bit_pos; unsigned int bit_pos;
...@@ -379,7 +419,6 @@ int __f2fs_add_link(struct inode *dir, const struct qstr *name, struct inode *in ...@@ -379,7 +419,6 @@ int __f2fs_add_link(struct inode *dir, const struct qstr *name, struct inode *in
f2fs_hash_t dentry_hash; f2fs_hash_t dentry_hash;
struct f2fs_dir_entry *de; struct f2fs_dir_entry *de;
unsigned int nbucket, nblock; unsigned int nbucket, nblock;
struct f2fs_sb_info *sbi = F2FS_SB(dir->i_sb);
size_t namelen = name->len; size_t namelen = name->len;
struct page *dentry_page = NULL; struct page *dentry_page = NULL;
struct f2fs_dentry_block *dentry_blk = NULL; struct f2fs_dentry_block *dentry_blk = NULL;
...@@ -409,12 +448,9 @@ int __f2fs_add_link(struct inode *dir, const struct qstr *name, struct inode *in ...@@ -409,12 +448,9 @@ int __f2fs_add_link(struct inode *dir, const struct qstr *name, struct inode *in
bidx = dir_block_index(level, (le32_to_cpu(dentry_hash) % nbucket)); bidx = dir_block_index(level, (le32_to_cpu(dentry_hash) % nbucket));
for (block = bidx; block <= (bidx + nblock - 1); block++) { for (block = bidx; block <= (bidx + nblock - 1); block++) {
mutex_lock_op(sbi, DENTRY_OPS);
dentry_page = get_new_data_page(dir, block, true); dentry_page = get_new_data_page(dir, block, true);
if (IS_ERR(dentry_page)) { if (IS_ERR(dentry_page))
mutex_unlock_op(sbi, DENTRY_OPS);
return PTR_ERR(dentry_page); return PTR_ERR(dentry_page);
}
dentry_blk = kmap(dentry_page); dentry_blk = kmap(dentry_page);
bit_pos = room_for_filename(dentry_blk, slots); bit_pos = room_for_filename(dentry_blk, slots);
...@@ -423,7 +459,6 @@ int __f2fs_add_link(struct inode *dir, const struct qstr *name, struct inode *in ...@@ -423,7 +459,6 @@ int __f2fs_add_link(struct inode *dir, const struct qstr *name, struct inode *in
kunmap(dentry_page); kunmap(dentry_page);
f2fs_put_page(dentry_page, 1); f2fs_put_page(dentry_page, 1);
mutex_unlock_op(sbi, DENTRY_OPS);
} }
/* Move to next level to find the empty slot for new dentry */ /* Move to next level to find the empty slot for new dentry */
...@@ -453,7 +488,6 @@ int __f2fs_add_link(struct inode *dir, const struct qstr *name, struct inode *in ...@@ -453,7 +488,6 @@ int __f2fs_add_link(struct inode *dir, const struct qstr *name, struct inode *in
fail: fail:
kunmap(dentry_page); kunmap(dentry_page);
f2fs_put_page(dentry_page, 1); f2fs_put_page(dentry_page, 1);
mutex_unlock_op(sbi, DENTRY_OPS);
return err; return err;
} }
...@@ -473,8 +507,6 @@ void f2fs_delete_entry(struct f2fs_dir_entry *dentry, struct page *page, ...@@ -473,8 +507,6 @@ void f2fs_delete_entry(struct f2fs_dir_entry *dentry, struct page *page,
void *kaddr = page_address(page); void *kaddr = page_address(page);
int i; int i;
mutex_lock_op(sbi, DENTRY_OPS);
lock_page(page); lock_page(page);
wait_on_page_writeback(page); wait_on_page_writeback(page);
...@@ -494,7 +526,7 @@ void f2fs_delete_entry(struct f2fs_dir_entry *dentry, struct page *page, ...@@ -494,7 +526,7 @@ void f2fs_delete_entry(struct f2fs_dir_entry *dentry, struct page *page,
if (inode && S_ISDIR(inode->i_mode)) { if (inode && S_ISDIR(inode->i_mode)) {
drop_nlink(dir); drop_nlink(dir);
f2fs_write_inode(dir, NULL); update_inode_page(dir);
} else { } else {
mark_inode_dirty(dir); mark_inode_dirty(dir);
} }
...@@ -506,7 +538,8 @@ void f2fs_delete_entry(struct f2fs_dir_entry *dentry, struct page *page, ...@@ -506,7 +538,8 @@ void f2fs_delete_entry(struct f2fs_dir_entry *dentry, struct page *page,
drop_nlink(inode); drop_nlink(inode);
i_size_write(inode, 0); i_size_write(inode, 0);
} }
f2fs_write_inode(inode, NULL); update_inode_page(inode);
if (inode->i_nlink == 0) if (inode->i_nlink == 0)
add_orphan_inode(sbi, inode->i_ino); add_orphan_inode(sbi, inode->i_ino);
} }
...@@ -519,45 +552,6 @@ void f2fs_delete_entry(struct f2fs_dir_entry *dentry, struct page *page, ...@@ -519,45 +552,6 @@ void f2fs_delete_entry(struct f2fs_dir_entry *dentry, struct page *page,
inode_dec_dirty_dents(dir); inode_dec_dirty_dents(dir);
} }
f2fs_put_page(page, 1); f2fs_put_page(page, 1);
mutex_unlock_op(sbi, DENTRY_OPS);
}
int f2fs_make_empty(struct inode *inode, struct inode *parent)
{
struct page *dentry_page;
struct f2fs_dentry_block *dentry_blk;
struct f2fs_dir_entry *de;
void *kaddr;
dentry_page = get_new_data_page(inode, 0, true);
if (IS_ERR(dentry_page))
return PTR_ERR(dentry_page);
kaddr = kmap_atomic(dentry_page);
dentry_blk = (struct f2fs_dentry_block *)kaddr;
de = &dentry_blk->dentry[0];
de->name_len = cpu_to_le16(1);
de->hash_code = f2fs_dentry_hash(".", 1);
de->ino = cpu_to_le32(inode->i_ino);
memcpy(dentry_blk->filename[0], ".", 1);
set_de_type(de, inode);
de = &dentry_blk->dentry[1];
de->hash_code = f2fs_dentry_hash("..", 2);
de->name_len = cpu_to_le16(2);
de->ino = cpu_to_le32(parent->i_ino);
memcpy(dentry_blk->filename[1], "..", 2);
set_de_type(de, inode);
test_and_set_bit_le(0, &dentry_blk->dentry_bitmap);
test_and_set_bit_le(1, &dentry_blk->dentry_bitmap);
kunmap_atomic(kaddr);
set_page_dirty(dentry_page);
f2fs_put_page(dentry_page, 1);
return 0;
} }
bool f2fs_empty_dir(struct inode *dir) bool f2fs_empty_dir(struct inode *dir)
......
...@@ -125,11 +125,15 @@ static inline int update_sits_in_cursum(struct f2fs_summary_block *rs, int i) ...@@ -125,11 +125,15 @@ static inline int update_sits_in_cursum(struct f2fs_summary_block *rs, int i)
* file keeping -1 as its node offset to * file keeping -1 as its node offset to
* distinguish from index node blocks. * distinguish from index node blocks.
*/ */
#define RDONLY_NODE 1 /* enum {
* specify a read-only mode when getting ALLOC_NODE, /* allocate a new node page if needed */
* a node block. 0 is read-write mode. LOOKUP_NODE, /* look up a node without readahead */
* used by get_dnode_of_data(). LOOKUP_NODE_RA, /*
* look up a node with readahead called
* by get_datablock_ro.
*/ */
};
#define F2FS_LINK_MAX 32000 /* maximum link count per file */ #define F2FS_LINK_MAX 32000 /* maximum link count per file */
/* for in-memory extent cache entry */ /* for in-memory extent cache entry */
...@@ -144,6 +148,7 @@ struct extent_info { ...@@ -144,6 +148,7 @@ struct extent_info {
* i_advise uses FADVISE_XXX_BIT. We can add additional hints later. * i_advise uses FADVISE_XXX_BIT. We can add additional hints later.
*/ */
#define FADVISE_COLD_BIT 0x01 #define FADVISE_COLD_BIT 0x01
#define FADVISE_CP_BIT 0x02
struct f2fs_inode_info { struct f2fs_inode_info {
struct inode vfs_inode; /* serve a vfs inode */ struct inode vfs_inode; /* serve a vfs inode */
...@@ -155,7 +160,6 @@ struct f2fs_inode_info { ...@@ -155,7 +160,6 @@ struct f2fs_inode_info {
/* Use below internally in f2fs*/ /* Use below internally in f2fs*/
unsigned long flags; /* use to pass per-file flags */ unsigned long flags; /* use to pass per-file flags */
unsigned long long data_version;/* latest version of data for fsync */
atomic_t dirty_dents; /* # of dirty dentry pages */ atomic_t dirty_dents; /* # of dirty dentry pages */
f2fs_hash_t chash; /* hash value of given file name */ f2fs_hash_t chash; /* hash value of given file name */
unsigned int clevel; /* maximum level of given file name */ unsigned int clevel; /* maximum level of given file name */
...@@ -186,7 +190,6 @@ static inline void set_raw_extent(struct extent_info *ext, ...@@ -186,7 +190,6 @@ static inline void set_raw_extent(struct extent_info *ext,
struct f2fs_nm_info { struct f2fs_nm_info {
block_t nat_blkaddr; /* base disk address of NAT */ block_t nat_blkaddr; /* base disk address of NAT */
nid_t max_nid; /* maximum possible node ids */ nid_t max_nid; /* maximum possible node ids */
nid_t init_scan_nid; /* the first nid to be scanned */
nid_t next_scan_nid; /* the next nid to be scanned */ nid_t next_scan_nid; /* the next nid to be scanned */
/* NAT cache management */ /* NAT cache management */
...@@ -305,23 +308,12 @@ enum count_type { ...@@ -305,23 +308,12 @@ enum count_type {
}; };
/* /*
* FS_LOCK nesting subclasses for the lock validator: * Uses as sbi->fs_lock[NR_GLOBAL_LOCKS].
* * The checkpoint procedure blocks all the locks in this fs_lock array.
* The locking order between these classes is * Some FS operations grab free locks, and if there is no free lock,
* RENAME -> DENTRY_OPS -> DATA_WRITE -> DATA_NEW * then wait to grab a lock in a round-robin manner.
* -> DATA_TRUNC -> NODE_WRITE -> NODE_NEW -> NODE_TRUNC
*/ */
enum lock_type { #define NR_GLOBAL_LOCKS 8
RENAME, /* for renaming operations */
DENTRY_OPS, /* for directory operations */
DATA_WRITE, /* for data write */
DATA_NEW, /* for data allocation */
DATA_TRUNC, /* for data truncate */
NODE_NEW, /* for node allocation */
NODE_TRUNC, /* for node truncate */
NODE_WRITE, /* for node write */
NR_LOCK_TYPE,
};
/* /*
* The below are the page types of bios used in submti_bio(). * The below are the page types of bios used in submti_bio().
...@@ -361,11 +353,13 @@ struct f2fs_sb_info { ...@@ -361,11 +353,13 @@ struct f2fs_sb_info {
/* for checkpoint */ /* for checkpoint */
struct f2fs_checkpoint *ckpt; /* raw checkpoint pointer */ struct f2fs_checkpoint *ckpt; /* raw checkpoint pointer */
struct inode *meta_inode; /* cache meta blocks */ struct inode *meta_inode; /* cache meta blocks */
struct mutex cp_mutex; /* for checkpoint procedure */ struct mutex cp_mutex; /* checkpoint procedure lock */
struct mutex fs_lock[NR_LOCK_TYPE]; /* for blocking FS operations */ struct mutex fs_lock[NR_GLOBAL_LOCKS]; /* blocking FS operations */
struct mutex write_inode; /* mutex for write inode */ struct mutex node_write; /* locking node writes */
struct mutex writepages; /* mutex for writepages() */ struct mutex writepages; /* mutex for writepages() */
unsigned char next_lock_num; /* round-robin global locks */
int por_doing; /* recovery is doing or not */ int por_doing; /* recovery is doing or not */
int on_build_free_nids; /* build_free_nids is doing */
/* for orphan inode management */ /* for orphan inode management */
struct list_head orphan_inode_list; /* orphan inode list */ struct list_head orphan_inode_list; /* orphan inode list */
...@@ -406,6 +400,7 @@ struct f2fs_sb_info { ...@@ -406,6 +400,7 @@ struct f2fs_sb_info {
/* for cleaning operations */ /* for cleaning operations */
struct mutex gc_mutex; /* mutex for GC */ struct mutex gc_mutex; /* mutex for GC */
struct f2fs_gc_kthread *gc_thread; /* GC thread */ struct f2fs_gc_kthread *gc_thread; /* GC thread */
unsigned int cur_victim_sec; /* current victim section num */
/* /*
* for stat information. * for stat information.
...@@ -498,22 +493,51 @@ static inline void clear_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f) ...@@ -498,22 +493,51 @@ static inline void clear_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f)
cp->ckpt_flags = cpu_to_le32(ckpt_flags); cp->ckpt_flags = cpu_to_le32(ckpt_flags);
} }
static inline void mutex_lock_op(struct f2fs_sb_info *sbi, enum lock_type t) static inline void mutex_lock_all(struct f2fs_sb_info *sbi)
{ {
mutex_lock_nested(&sbi->fs_lock[t], t); int i = 0;
for (; i < NR_GLOBAL_LOCKS; i++)
mutex_lock(&sbi->fs_lock[i]);
} }
static inline void mutex_unlock_op(struct f2fs_sb_info *sbi, enum lock_type t) static inline void mutex_unlock_all(struct f2fs_sb_info *sbi)
{ {
mutex_unlock(&sbi->fs_lock[t]); int i = 0;
for (; i < NR_GLOBAL_LOCKS; i++)
mutex_unlock(&sbi->fs_lock[i]);
}
static inline int mutex_lock_op(struct f2fs_sb_info *sbi)
{
unsigned char next_lock = sbi->next_lock_num % NR_GLOBAL_LOCKS;
int i = 0;
for (; i < NR_GLOBAL_LOCKS; i++)
if (mutex_trylock(&sbi->fs_lock[i]))
return i;
mutex_lock(&sbi->fs_lock[next_lock]);
sbi->next_lock_num++;
return next_lock;
}
static inline void mutex_unlock_op(struct f2fs_sb_info *sbi, int ilock)
{
if (ilock < 0)
return;
BUG_ON(ilock >= NR_GLOBAL_LOCKS);
mutex_unlock(&sbi->fs_lock[ilock]);
} }
/* /*
* Check whether the given nid is within node id range. * Check whether the given nid is within node id range.
*/ */
static inline void check_nid_range(struct f2fs_sb_info *sbi, nid_t nid) static inline int check_nid_range(struct f2fs_sb_info *sbi, nid_t nid)
{ {
BUG_ON((nid >= NM_I(sbi)->max_nid)); WARN_ON((nid >= NM_I(sbi)->max_nid));
if (nid >= NM_I(sbi)->max_nid)
return -EINVAL;
return 0;
} }
#define F2FS_DEFAULT_ALLOCATED_BLOCKS 1 #define F2FS_DEFAULT_ALLOCATED_BLOCKS 1
...@@ -819,7 +843,6 @@ static inline int f2fs_clear_bit(unsigned int nr, char *addr) ...@@ -819,7 +843,6 @@ static inline int f2fs_clear_bit(unsigned int nr, char *addr)
/* used for f2fs_inode_info->flags */ /* used for f2fs_inode_info->flags */
enum { enum {
FI_NEW_INODE, /* indicate newly allocated inode */ FI_NEW_INODE, /* indicate newly allocated inode */
FI_NEED_CP, /* need to do checkpoint during fsync */
FI_INC_LINK, /* need to increment i_nlink */ FI_INC_LINK, /* need to increment i_nlink */
FI_ACL_MODE, /* indicate acl mode */ FI_ACL_MODE, /* indicate acl mode */
FI_NO_ALLOC, /* should not allocate any blocks */ FI_NO_ALLOC, /* should not allocate any blocks */
...@@ -872,6 +895,7 @@ long f2fs_compat_ioctl(struct file *, unsigned int, unsigned long); ...@@ -872,6 +895,7 @@ long f2fs_compat_ioctl(struct file *, unsigned int, unsigned long);
void f2fs_set_inode_flags(struct inode *); void f2fs_set_inode_flags(struct inode *);
struct inode *f2fs_iget(struct super_block *, unsigned long); struct inode *f2fs_iget(struct super_block *, unsigned long);
void update_inode(struct inode *, struct page *); void update_inode(struct inode *, struct page *);
int update_inode_page(struct inode *);
int f2fs_write_inode(struct inode *, struct writeback_control *); int f2fs_write_inode(struct inode *, struct writeback_control *);
void f2fs_evict_inode(struct inode *); void f2fs_evict_inode(struct inode *);
...@@ -973,7 +997,6 @@ int lookup_journal_in_cursum(struct f2fs_summary_block *, ...@@ -973,7 +997,6 @@ int lookup_journal_in_cursum(struct f2fs_summary_block *,
int, unsigned int, int); int, unsigned int, int);
void flush_sit_entries(struct f2fs_sb_info *); void flush_sit_entries(struct f2fs_sb_info *);
int build_segment_manager(struct f2fs_sb_info *); int build_segment_manager(struct f2fs_sb_info *);
void reset_victim_segmap(struct f2fs_sb_info *);
void destroy_segment_manager(struct f2fs_sb_info *); void destroy_segment_manager(struct f2fs_sb_info *);
/* /*
...@@ -1000,7 +1023,7 @@ void destroy_checkpoint_caches(void); ...@@ -1000,7 +1023,7 @@ void destroy_checkpoint_caches(void);
*/ */
int reserve_new_block(struct dnode_of_data *); int reserve_new_block(struct dnode_of_data *);
void update_extent_cache(block_t, struct dnode_of_data *); void update_extent_cache(block_t, struct dnode_of_data *);
struct page *find_data_page(struct inode *, pgoff_t); struct page *find_data_page(struct inode *, pgoff_t, bool);
struct page *get_lock_data_page(struct inode *, pgoff_t); struct page *get_lock_data_page(struct inode *, pgoff_t);
struct page *get_new_data_page(struct inode *, pgoff_t, bool); struct page *get_new_data_page(struct inode *, pgoff_t, bool);
int f2fs_readpage(struct f2fs_sb_info *, struct page *, block_t, int); int f2fs_readpage(struct f2fs_sb_info *, struct page *, block_t, int);
...@@ -1020,7 +1043,7 @@ void destroy_gc_caches(void); ...@@ -1020,7 +1043,7 @@ void destroy_gc_caches(void);
/* /*
* recovery.c * recovery.c
*/ */
void recover_fsync_data(struct f2fs_sb_info *); int recover_fsync_data(struct f2fs_sb_info *);
bool space_for_roll_forward(struct f2fs_sb_info *); bool space_for_roll_forward(struct f2fs_sb_info *);
/* /*
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include <linux/stat.h> #include <linux/stat.h>
#include <linux/buffer_head.h> #include <linux/buffer_head.h>
#include <linux/writeback.h> #include <linux/writeback.h>
#include <linux/blkdev.h>
#include <linux/falloc.h> #include <linux/falloc.h>
#include <linux/types.h> #include <linux/types.h>
#include <linux/compat.h> #include <linux/compat.h>
...@@ -24,6 +25,7 @@ ...@@ -24,6 +25,7 @@
#include "segment.h" #include "segment.h"
#include "xattr.h" #include "xattr.h"
#include "acl.h" #include "acl.h"
#include <trace/events/f2fs.h>
static int f2fs_vm_page_mkwrite(struct vm_area_struct *vma, static int f2fs_vm_page_mkwrite(struct vm_area_struct *vma,
struct vm_fault *vmf) struct vm_fault *vmf)
...@@ -33,19 +35,18 @@ static int f2fs_vm_page_mkwrite(struct vm_area_struct *vma, ...@@ -33,19 +35,18 @@ static int f2fs_vm_page_mkwrite(struct vm_area_struct *vma,
struct f2fs_sb_info *sbi = F2FS_SB(inode->i_sb); struct f2fs_sb_info *sbi = F2FS_SB(inode->i_sb);
block_t old_blk_addr; block_t old_blk_addr;
struct dnode_of_data dn; struct dnode_of_data dn;
int err; int err, ilock;
f2fs_balance_fs(sbi); f2fs_balance_fs(sbi);
sb_start_pagefault(inode->i_sb); sb_start_pagefault(inode->i_sb);
mutex_lock_op(sbi, DATA_NEW);
/* block allocation */ /* block allocation */
ilock = mutex_lock_op(sbi);
set_new_dnode(&dn, inode, NULL, NULL, 0); set_new_dnode(&dn, inode, NULL, NULL, 0);
err = get_dnode_of_data(&dn, page->index, 0); err = get_dnode_of_data(&dn, page->index, ALLOC_NODE);
if (err) { if (err) {
mutex_unlock_op(sbi, DATA_NEW); mutex_unlock_op(sbi, ilock);
goto out; goto out;
} }
...@@ -55,13 +56,12 @@ static int f2fs_vm_page_mkwrite(struct vm_area_struct *vma, ...@@ -55,13 +56,12 @@ static int f2fs_vm_page_mkwrite(struct vm_area_struct *vma,
err = reserve_new_block(&dn); err = reserve_new_block(&dn);
if (err) { if (err) {
f2fs_put_dnode(&dn); f2fs_put_dnode(&dn);
mutex_unlock_op(sbi, DATA_NEW); mutex_unlock_op(sbi, ilock);
goto out; goto out;
} }
} }
f2fs_put_dnode(&dn); f2fs_put_dnode(&dn);
mutex_unlock_op(sbi, ilock);
mutex_unlock_op(sbi, DATA_NEW);
lock_page(page); lock_page(page);
if (page->mapping != inode->i_mapping || if (page->mapping != inode->i_mapping ||
...@@ -102,28 +102,10 @@ static const struct vm_operations_struct f2fs_file_vm_ops = { ...@@ -102,28 +102,10 @@ static const struct vm_operations_struct f2fs_file_vm_ops = {
.remap_pages = generic_file_remap_pages, .remap_pages = generic_file_remap_pages,
}; };
static int need_to_sync_dir(struct f2fs_sb_info *sbi, struct inode *inode)
{
struct dentry *dentry;
nid_t pino;
inode = igrab(inode);
dentry = d_find_any_alias(inode);
if (!dentry) {
iput(inode);
return 0;
}
pino = dentry->d_parent->d_inode->i_ino;
dput(dentry);
iput(inode);
return !is_checkpointed_node(sbi, pino);
}
int f2fs_sync_file(struct file *file, loff_t start, loff_t end, int datasync) int f2fs_sync_file(struct file *file, loff_t start, loff_t end, int datasync)
{ {
struct inode *inode = file->f_mapping->host; struct inode *inode = file->f_mapping->host;
struct f2fs_sb_info *sbi = F2FS_SB(inode->i_sb); struct f2fs_sb_info *sbi = F2FS_SB(inode->i_sb);
unsigned long long cur_version;
int ret = 0; int ret = 0;
bool need_cp = false; bool need_cp = false;
struct writeback_control wbc = { struct writeback_control wbc = {
...@@ -135,9 +117,12 @@ int f2fs_sync_file(struct file *file, loff_t start, loff_t end, int datasync) ...@@ -135,9 +117,12 @@ int f2fs_sync_file(struct file *file, loff_t start, loff_t end, int datasync)
if (inode->i_sb->s_flags & MS_RDONLY) if (inode->i_sb->s_flags & MS_RDONLY)
return 0; return 0;
trace_f2fs_sync_file_enter(inode);
ret = filemap_write_and_wait_range(inode->i_mapping, start, end); ret = filemap_write_and_wait_range(inode->i_mapping, start, end);
if (ret) if (ret) {
trace_f2fs_sync_file_exit(inode, need_cp, datasync, ret);
return ret; return ret;
}
/* guarantee free sections for fsync */ /* guarantee free sections for fsync */
f2fs_balance_fs(sbi); f2fs_balance_fs(sbi);
...@@ -147,28 +132,18 @@ int f2fs_sync_file(struct file *file, loff_t start, loff_t end, int datasync) ...@@ -147,28 +132,18 @@ int f2fs_sync_file(struct file *file, loff_t start, loff_t end, int datasync)
if (datasync && !(inode->i_state & I_DIRTY_DATASYNC)) if (datasync && !(inode->i_state & I_DIRTY_DATASYNC))
goto out; goto out;
mutex_lock(&sbi->cp_mutex);
cur_version = le64_to_cpu(F2FS_CKPT(sbi)->checkpoint_ver);
mutex_unlock(&sbi->cp_mutex);
if (F2FS_I(inode)->data_version != cur_version &&
!(inode->i_state & I_DIRTY))
goto out;
F2FS_I(inode)->data_version--;
if (!S_ISREG(inode->i_mode) || inode->i_nlink != 1) if (!S_ISREG(inode->i_mode) || inode->i_nlink != 1)
need_cp = true; need_cp = true;
else if (is_inode_flag_set(F2FS_I(inode), FI_NEED_CP)) else if (is_cp_file(inode))
need_cp = true; need_cp = true;
else if (!space_for_roll_forward(sbi)) else if (!space_for_roll_forward(sbi))
need_cp = true; need_cp = true;
else if (need_to_sync_dir(sbi, inode)) else if (!is_checkpointed_node(sbi, F2FS_I(inode)->i_pino))
need_cp = true; need_cp = true;
if (need_cp) { if (need_cp) {
/* all the dirty node pages should be flushed for POR */ /* all the dirty node pages should be flushed for POR */
ret = f2fs_sync_fs(inode->i_sb, 1); ret = f2fs_sync_fs(inode->i_sb, 1);
clear_inode_flag(F2FS_I(inode), FI_NEED_CP);
} else { } else {
/* if there is no written node page, write its inode page */ /* if there is no written node page, write its inode page */
while (!sync_node_pages(sbi, inode->i_ino, &wbc)) { while (!sync_node_pages(sbi, inode->i_ino, &wbc)) {
...@@ -178,9 +153,11 @@ int f2fs_sync_file(struct file *file, loff_t start, loff_t end, int datasync) ...@@ -178,9 +153,11 @@ int f2fs_sync_file(struct file *file, loff_t start, loff_t end, int datasync)
} }
filemap_fdatawait_range(sbi->node_inode->i_mapping, filemap_fdatawait_range(sbi->node_inode->i_mapping,
0, LONG_MAX); 0, LONG_MAX);
ret = blkdev_issue_flush(inode->i_sb->s_bdev, GFP_KERNEL, NULL);
} }
out: out:
mutex_unlock(&inode->i_mutex); mutex_unlock(&inode->i_mutex);
trace_f2fs_sync_file_exit(inode, need_cp, datasync, ret);
return ret; return ret;
} }
...@@ -216,6 +193,9 @@ static int truncate_data_blocks_range(struct dnode_of_data *dn, int count) ...@@ -216,6 +193,9 @@ static int truncate_data_blocks_range(struct dnode_of_data *dn, int count)
sync_inode_page(dn); sync_inode_page(dn);
} }
dn->ofs_in_node = ofs; dn->ofs_in_node = ofs;
trace_f2fs_truncate_data_blocks_range(dn->inode, dn->nid,
dn->ofs_in_node, nr_free);
return nr_free; return nr_free;
} }
...@@ -232,11 +212,15 @@ static void truncate_partial_data_page(struct inode *inode, u64 from) ...@@ -232,11 +212,15 @@ static void truncate_partial_data_page(struct inode *inode, u64 from)
if (!offset) if (!offset)
return; return;
page = find_data_page(inode, from >> PAGE_CACHE_SHIFT); page = find_data_page(inode, from >> PAGE_CACHE_SHIFT, false);
if (IS_ERR(page)) if (IS_ERR(page))
return; return;
lock_page(page); lock_page(page);
if (page->mapping != inode->i_mapping) {
f2fs_put_page(page, 1);
return;
}
wait_on_page_writeback(page); wait_on_page_writeback(page);
zero_user(page, offset, PAGE_CACHE_SIZE - offset); zero_user(page, offset, PAGE_CACHE_SIZE - offset);
set_page_dirty(page); set_page_dirty(page);
...@@ -249,20 +233,22 @@ static int truncate_blocks(struct inode *inode, u64 from) ...@@ -249,20 +233,22 @@ static int truncate_blocks(struct inode *inode, u64 from)
unsigned int blocksize = inode->i_sb->s_blocksize; unsigned int blocksize = inode->i_sb->s_blocksize;
struct dnode_of_data dn; struct dnode_of_data dn;
pgoff_t free_from; pgoff_t free_from;
int count = 0; int count = 0, ilock = -1;
int err; int err;
trace_f2fs_truncate_blocks_enter(inode, from);
free_from = (pgoff_t) free_from = (pgoff_t)
((from + blocksize - 1) >> (sbi->log_blocksize)); ((from + blocksize - 1) >> (sbi->log_blocksize));
mutex_lock_op(sbi, DATA_TRUNC); ilock = mutex_lock_op(sbi);
set_new_dnode(&dn, inode, NULL, NULL, 0); set_new_dnode(&dn, inode, NULL, NULL, 0);
err = get_dnode_of_data(&dn, free_from, RDONLY_NODE); err = get_dnode_of_data(&dn, free_from, LOOKUP_NODE);
if (err) { if (err) {
if (err == -ENOENT) if (err == -ENOENT)
goto free_next; goto free_next;
mutex_unlock_op(sbi, DATA_TRUNC); mutex_unlock_op(sbi, ilock);
trace_f2fs_truncate_blocks_exit(inode, err);
return err; return err;
} }
...@@ -273,6 +259,7 @@ static int truncate_blocks(struct inode *inode, u64 from) ...@@ -273,6 +259,7 @@ static int truncate_blocks(struct inode *inode, u64 from)
count -= dn.ofs_in_node; count -= dn.ofs_in_node;
BUG_ON(count < 0); BUG_ON(count < 0);
if (dn.ofs_in_node || IS_INODE(dn.node_page)) { if (dn.ofs_in_node || IS_INODE(dn.node_page)) {
truncate_data_blocks_range(&dn, count); truncate_data_blocks_range(&dn, count);
free_from += count; free_from += count;
...@@ -281,11 +268,12 @@ static int truncate_blocks(struct inode *inode, u64 from) ...@@ -281,11 +268,12 @@ static int truncate_blocks(struct inode *inode, u64 from)
f2fs_put_dnode(&dn); f2fs_put_dnode(&dn);
free_next: free_next:
err = truncate_inode_blocks(inode, free_from); err = truncate_inode_blocks(inode, free_from);
mutex_unlock_op(sbi, DATA_TRUNC); mutex_unlock_op(sbi, ilock);
/* lastly zero out the first data page */ /* lastly zero out the first data page */
truncate_partial_data_page(inode, from); truncate_partial_data_page(inode, from);
trace_f2fs_truncate_blocks_exit(inode, err);
return err; return err;
} }
...@@ -295,6 +283,8 @@ void f2fs_truncate(struct inode *inode) ...@@ -295,6 +283,8 @@ void f2fs_truncate(struct inode *inode)
S_ISLNK(inode->i_mode))) S_ISLNK(inode->i_mode)))
return; return;
trace_f2fs_truncate(inode);
if (!truncate_blocks(inode, i_size_read(inode))) { if (!truncate_blocks(inode, i_size_read(inode))) {
inode->i_mtime = inode->i_ctime = CURRENT_TIME; inode->i_mtime = inode->i_ctime = CURRENT_TIME;
mark_inode_dirty(inode); mark_inode_dirty(inode);
...@@ -389,15 +379,16 @@ static void fill_zero(struct inode *inode, pgoff_t index, ...@@ -389,15 +379,16 @@ static void fill_zero(struct inode *inode, pgoff_t index,
{ {
struct f2fs_sb_info *sbi = F2FS_SB(inode->i_sb); struct f2fs_sb_info *sbi = F2FS_SB(inode->i_sb);
struct page *page; struct page *page;
int ilock;
if (!len) if (!len)
return; return;
f2fs_balance_fs(sbi); f2fs_balance_fs(sbi);
mutex_lock_op(sbi, DATA_NEW); ilock = mutex_lock_op(sbi);
page = get_new_data_page(inode, index, false); page = get_new_data_page(inode, index, false);
mutex_unlock_op(sbi, DATA_NEW); mutex_unlock_op(sbi, ilock);
if (!IS_ERR(page)) { if (!IS_ERR(page)) {
wait_on_page_writeback(page); wait_on_page_writeback(page);
...@@ -414,15 +405,10 @@ int truncate_hole(struct inode *inode, pgoff_t pg_start, pgoff_t pg_end) ...@@ -414,15 +405,10 @@ int truncate_hole(struct inode *inode, pgoff_t pg_start, pgoff_t pg_end)
for (index = pg_start; index < pg_end; index++) { for (index = pg_start; index < pg_end; index++) {
struct dnode_of_data dn; struct dnode_of_data dn;
struct f2fs_sb_info *sbi = F2FS_SB(inode->i_sb);
f2fs_balance_fs(sbi);
mutex_lock_op(sbi, DATA_TRUNC);
set_new_dnode(&dn, inode, NULL, NULL, 0); set_new_dnode(&dn, inode, NULL, NULL, 0);
err = get_dnode_of_data(&dn, index, RDONLY_NODE); err = get_dnode_of_data(&dn, index, LOOKUP_NODE);
if (err) { if (err) {
mutex_unlock_op(sbi, DATA_TRUNC);
if (err == -ENOENT) if (err == -ENOENT)
continue; continue;
return err; return err;
...@@ -431,7 +417,6 @@ int truncate_hole(struct inode *inode, pgoff_t pg_start, pgoff_t pg_end) ...@@ -431,7 +417,6 @@ int truncate_hole(struct inode *inode, pgoff_t pg_start, pgoff_t pg_end)
if (dn.data_blkaddr != NULL_ADDR) if (dn.data_blkaddr != NULL_ADDR)
truncate_data_blocks_range(&dn, 1); truncate_data_blocks_range(&dn, 1);
f2fs_put_dnode(&dn); f2fs_put_dnode(&dn);
mutex_unlock_op(sbi, DATA_TRUNC);
} }
return 0; return 0;
} }
...@@ -461,12 +446,19 @@ static int punch_hole(struct inode *inode, loff_t offset, loff_t len, int mode) ...@@ -461,12 +446,19 @@ static int punch_hole(struct inode *inode, loff_t offset, loff_t len, int mode)
if (pg_start < pg_end) { if (pg_start < pg_end) {
struct address_space *mapping = inode->i_mapping; struct address_space *mapping = inode->i_mapping;
loff_t blk_start, blk_end; loff_t blk_start, blk_end;
struct f2fs_sb_info *sbi = F2FS_SB(inode->i_sb);
int ilock;
f2fs_balance_fs(sbi);
blk_start = pg_start << PAGE_CACHE_SHIFT; blk_start = pg_start << PAGE_CACHE_SHIFT;
blk_end = pg_end << PAGE_CACHE_SHIFT; blk_end = pg_end << PAGE_CACHE_SHIFT;
truncate_inode_pages_range(mapping, blk_start, truncate_inode_pages_range(mapping, blk_start,
blk_end - 1); blk_end - 1);
ilock = mutex_lock_op(sbi);
ret = truncate_hole(inode, pg_start, pg_end); ret = truncate_hole(inode, pg_start, pg_end);
mutex_unlock_op(sbi, ilock);
} }
} }
...@@ -500,13 +492,13 @@ static int expand_inode_data(struct inode *inode, loff_t offset, ...@@ -500,13 +492,13 @@ static int expand_inode_data(struct inode *inode, loff_t offset,
for (index = pg_start; index <= pg_end; index++) { for (index = pg_start; index <= pg_end; index++) {
struct dnode_of_data dn; struct dnode_of_data dn;
int ilock;
mutex_lock_op(sbi, DATA_NEW); ilock = mutex_lock_op(sbi);
set_new_dnode(&dn, inode, NULL, NULL, 0); set_new_dnode(&dn, inode, NULL, NULL, 0);
ret = get_dnode_of_data(&dn, index, 0); ret = get_dnode_of_data(&dn, index, ALLOC_NODE);
if (ret) { if (ret) {
mutex_unlock_op(sbi, DATA_NEW); mutex_unlock_op(sbi, ilock);
break; break;
} }
...@@ -514,13 +506,12 @@ static int expand_inode_data(struct inode *inode, loff_t offset, ...@@ -514,13 +506,12 @@ static int expand_inode_data(struct inode *inode, loff_t offset,
ret = reserve_new_block(&dn); ret = reserve_new_block(&dn);
if (ret) { if (ret) {
f2fs_put_dnode(&dn); f2fs_put_dnode(&dn);
mutex_unlock_op(sbi, DATA_NEW); mutex_unlock_op(sbi, ilock);
break; break;
} }
} }
f2fs_put_dnode(&dn); f2fs_put_dnode(&dn);
mutex_unlock_op(sbi, ilock);
mutex_unlock_op(sbi, DATA_NEW);
if (pg_start == pg_end) if (pg_start == pg_end)
new_size = offset + len; new_size = offset + len;
...@@ -559,6 +550,7 @@ static long f2fs_fallocate(struct file *file, int mode, ...@@ -559,6 +550,7 @@ static long f2fs_fallocate(struct file *file, int mode,
inode->i_mtime = inode->i_ctime = CURRENT_TIME; inode->i_mtime = inode->i_ctime = CURRENT_TIME;
mark_inode_dirty(inode); mark_inode_dirty(inode);
} }
trace_f2fs_fallocate(inode, mode, offset, len, ret);
return ret; return ret;
} }
......
...@@ -11,7 +11,6 @@ ...@@ -11,7 +11,6 @@
#include <linux/fs.h> #include <linux/fs.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/backing-dev.h> #include <linux/backing-dev.h>
#include <linux/proc_fs.h>
#include <linux/init.h> #include <linux/init.h>
#include <linux/f2fs_fs.h> #include <linux/f2fs_fs.h>
#include <linux/kthread.h> #include <linux/kthread.h>
...@@ -23,6 +22,7 @@ ...@@ -23,6 +22,7 @@
#include "node.h" #include "node.h"
#include "segment.h" #include "segment.h"
#include "gc.h" #include "gc.h"
#include <trace/events/f2fs.h>
static struct kmem_cache *winode_slab; static struct kmem_cache *winode_slab;
...@@ -81,9 +81,6 @@ static int gc_thread_func(void *data) ...@@ -81,9 +81,6 @@ static int gc_thread_func(void *data)
/* if return value is not zero, no victim was selected */ /* if return value is not zero, no victim was selected */
if (f2fs_gc(sbi)) if (f2fs_gc(sbi))
wait_ms = GC_THREAD_NOGC_SLEEP_TIME; wait_ms = GC_THREAD_NOGC_SLEEP_TIME;
else if (wait_ms == GC_THREAD_NOGC_SLEEP_TIME)
wait_ms = GC_THREAD_MAX_SLEEP_TIME;
} while (!kthread_should_stop()); } while (!kthread_should_stop());
return 0; return 0;
} }
...@@ -131,7 +128,7 @@ static void select_policy(struct f2fs_sb_info *sbi, int gc_type, ...@@ -131,7 +128,7 @@ static void select_policy(struct f2fs_sb_info *sbi, int gc_type,
{ {
struct dirty_seglist_info *dirty_i = DIRTY_I(sbi); struct dirty_seglist_info *dirty_i = DIRTY_I(sbi);
if (p->alloc_mode) { if (p->alloc_mode == SSR) {
p->gc_mode = GC_GREEDY; p->gc_mode = GC_GREEDY;
p->dirty_segmap = dirty_i->dirty_segmap[type]; p->dirty_segmap = dirty_i->dirty_segmap[type];
p->ofs_unit = 1; p->ofs_unit = 1;
...@@ -160,18 +157,21 @@ static unsigned int get_max_cost(struct f2fs_sb_info *sbi, ...@@ -160,18 +157,21 @@ static unsigned int get_max_cost(struct f2fs_sb_info *sbi,
static unsigned int check_bg_victims(struct f2fs_sb_info *sbi) static unsigned int check_bg_victims(struct f2fs_sb_info *sbi)
{ {
struct dirty_seglist_info *dirty_i = DIRTY_I(sbi); struct dirty_seglist_info *dirty_i = DIRTY_I(sbi);
unsigned int segno; unsigned int hint = 0;
unsigned int secno;
/* /*
* If the gc_type is FG_GC, we can select victim segments * If the gc_type is FG_GC, we can select victim segments
* selected by background GC before. * selected by background GC before.
* Those segments guarantee they have small valid blocks. * Those segments guarantee they have small valid blocks.
*/ */
segno = find_next_bit(dirty_i->victim_segmap[BG_GC], next:
TOTAL_SEGS(sbi), 0); secno = find_next_bit(dirty_i->victim_secmap, TOTAL_SECS(sbi), hint++);
if (segno < TOTAL_SEGS(sbi)) { if (secno < TOTAL_SECS(sbi)) {
clear_bit(segno, dirty_i->victim_segmap[BG_GC]); if (sec_usage_check(sbi, secno))
return segno; goto next;
clear_bit(secno, dirty_i->victim_secmap);
return secno * sbi->segs_per_sec;
} }
return NULL_SEGNO; return NULL_SEGNO;
} }
...@@ -234,7 +234,7 @@ static int get_victim_by_default(struct f2fs_sb_info *sbi, ...@@ -234,7 +234,7 @@ static int get_victim_by_default(struct f2fs_sb_info *sbi,
{ {
struct dirty_seglist_info *dirty_i = DIRTY_I(sbi); struct dirty_seglist_info *dirty_i = DIRTY_I(sbi);
struct victim_sel_policy p; struct victim_sel_policy p;
unsigned int segno; unsigned int secno;
int nsearched = 0; int nsearched = 0;
p.alloc_mode = alloc_mode; p.alloc_mode = alloc_mode;
...@@ -253,6 +253,7 @@ static int get_victim_by_default(struct f2fs_sb_info *sbi, ...@@ -253,6 +253,7 @@ static int get_victim_by_default(struct f2fs_sb_info *sbi,
while (1) { while (1) {
unsigned long cost; unsigned long cost;
unsigned int segno;
segno = find_next_bit(p.dirty_segmap, segno = find_next_bit(p.dirty_segmap,
TOTAL_SEGS(sbi), p.offset); TOTAL_SEGS(sbi), p.offset);
...@@ -265,13 +266,11 @@ static int get_victim_by_default(struct f2fs_sb_info *sbi, ...@@ -265,13 +266,11 @@ static int get_victim_by_default(struct f2fs_sb_info *sbi,
break; break;
} }
p.offset = ((segno / p.ofs_unit) * p.ofs_unit) + p.ofs_unit; p.offset = ((segno / p.ofs_unit) * p.ofs_unit) + p.ofs_unit;
secno = GET_SECNO(sbi, segno);
if (test_bit(segno, dirty_i->victim_segmap[FG_GC])) if (sec_usage_check(sbi, secno))
continue;
if (gc_type == BG_GC &&
test_bit(segno, dirty_i->victim_segmap[BG_GC]))
continue; continue;
if (IS_CURSEC(sbi, GET_SECNO(sbi, segno))) if (gc_type == BG_GC && test_bit(secno, dirty_i->victim_secmap))
continue; continue;
cost = get_gc_cost(sbi, segno, &p); cost = get_gc_cost(sbi, segno, &p);
...@@ -291,13 +290,18 @@ static int get_victim_by_default(struct f2fs_sb_info *sbi, ...@@ -291,13 +290,18 @@ static int get_victim_by_default(struct f2fs_sb_info *sbi,
} }
got_it: got_it:
if (p.min_segno != NULL_SEGNO) { if (p.min_segno != NULL_SEGNO) {
*result = (p.min_segno / p.ofs_unit) * p.ofs_unit;
if (p.alloc_mode == LFS) { if (p.alloc_mode == LFS) {
int i; secno = GET_SECNO(sbi, p.min_segno);
for (i = 0; i < p.ofs_unit; i++) if (gc_type == FG_GC)
set_bit(*result + i, sbi->cur_victim_sec = secno;
dirty_i->victim_segmap[gc_type]); else
set_bit(secno, dirty_i->victim_secmap);
} }
*result = (p.min_segno / p.ofs_unit) * p.ofs_unit;
trace_f2fs_get_victim(sbi->sb, type, gc_type, &p,
sbi->cur_victim_sec,
prefree_segments(sbi), free_segments(sbi));
} }
mutex_unlock(&dirty_i->seglist_lock); mutex_unlock(&dirty_i->seglist_lock);
...@@ -381,6 +385,7 @@ static void gc_node_segment(struct f2fs_sb_info *sbi, ...@@ -381,6 +385,7 @@ static void gc_node_segment(struct f2fs_sb_info *sbi,
next_step: next_step:
entry = sum; entry = sum;
for (off = 0; off < sbi->blocks_per_seg; off++, entry++) { for (off = 0; off < sbi->blocks_per_seg; off++, entry++) {
nid_t nid = le32_to_cpu(entry->nid); nid_t nid = le32_to_cpu(entry->nid);
struct page *node_page; struct page *node_page;
...@@ -401,11 +406,18 @@ static void gc_node_segment(struct f2fs_sb_info *sbi, ...@@ -401,11 +406,18 @@ static void gc_node_segment(struct f2fs_sb_info *sbi,
continue; continue;
/* set page dirty and write it */ /* set page dirty and write it */
if (gc_type == FG_GC) {
f2fs_submit_bio(sbi, NODE, true);
wait_on_page_writeback(node_page);
set_page_dirty(node_page);
} else {
if (!PageWriteback(node_page)) if (!PageWriteback(node_page))
set_page_dirty(node_page); set_page_dirty(node_page);
}
f2fs_put_page(node_page, 1); f2fs_put_page(node_page, 1);
stat_inc_node_blk_count(sbi, 1); stat_inc_node_blk_count(sbi, 1);
} }
if (initial) { if (initial) {
initial = false; initial = false;
goto next_step; goto next_step;
...@@ -418,6 +430,13 @@ static void gc_node_segment(struct f2fs_sb_info *sbi, ...@@ -418,6 +430,13 @@ static void gc_node_segment(struct f2fs_sb_info *sbi,
.for_reclaim = 0, .for_reclaim = 0,
}; };
sync_node_pages(sbi, 0, &wbc); sync_node_pages(sbi, 0, &wbc);
/*
* In the case of FG_GC, it'd be better to reclaim this victim
* completely.
*/
if (get_valid_blocks(sbi, segno, 1) != 0)
goto next_step;
} }
} }
...@@ -481,21 +500,19 @@ static int check_dnode(struct f2fs_sb_info *sbi, struct f2fs_summary *sum, ...@@ -481,21 +500,19 @@ static int check_dnode(struct f2fs_sb_info *sbi, struct f2fs_summary *sum,
static void move_data_page(struct inode *inode, struct page *page, int gc_type) static void move_data_page(struct inode *inode, struct page *page, int gc_type)
{ {
if (page->mapping != inode->i_mapping) if (gc_type == BG_GC) {
goto out;
if (inode != page->mapping->host)
goto out;
if (PageWriteback(page)) if (PageWriteback(page))
goto out; goto out;
if (gc_type == BG_GC) {
set_page_dirty(page); set_page_dirty(page);
set_cold_data(page); set_cold_data(page);
} else { } else {
struct f2fs_sb_info *sbi = F2FS_SB(inode->i_sb); struct f2fs_sb_info *sbi = F2FS_SB(inode->i_sb);
mutex_lock_op(sbi, DATA_WRITE);
if (PageWriteback(page)) {
f2fs_submit_bio(sbi, DATA, true);
wait_on_page_writeback(page);
}
if (clear_page_dirty_for_io(page) && if (clear_page_dirty_for_io(page) &&
S_ISDIR(inode->i_mode)) { S_ISDIR(inode->i_mode)) {
dec_page_count(sbi, F2FS_DIRTY_DENTS); dec_page_count(sbi, F2FS_DIRTY_DENTS);
...@@ -503,7 +520,6 @@ static void move_data_page(struct inode *inode, struct page *page, int gc_type) ...@@ -503,7 +520,6 @@ static void move_data_page(struct inode *inode, struct page *page, int gc_type)
} }
set_cold_data(page); set_cold_data(page);
do_write_data_page(page); do_write_data_page(page);
mutex_unlock_op(sbi, DATA_WRITE);
clear_cold_data(page); clear_cold_data(page);
} }
out: out:
...@@ -530,6 +546,7 @@ static void gc_data_segment(struct f2fs_sb_info *sbi, struct f2fs_summary *sum, ...@@ -530,6 +546,7 @@ static void gc_data_segment(struct f2fs_sb_info *sbi, struct f2fs_summary *sum,
next_step: next_step:
entry = sum; entry = sum;
for (off = 0; off < sbi->blocks_per_seg; off++, entry++) { for (off = 0; off < sbi->blocks_per_seg; off++, entry++) {
struct page *data_page; struct page *data_page;
struct inode *inode; struct inode *inode;
...@@ -567,7 +584,7 @@ static void gc_data_segment(struct f2fs_sb_info *sbi, struct f2fs_summary *sum, ...@@ -567,7 +584,7 @@ static void gc_data_segment(struct f2fs_sb_info *sbi, struct f2fs_summary *sum,
continue; continue;
data_page = find_data_page(inode, data_page = find_data_page(inode,
start_bidx + ofs_in_node); start_bidx + ofs_in_node, false);
if (IS_ERR(data_page)) if (IS_ERR(data_page))
goto next_iput; goto next_iput;
...@@ -588,11 +605,22 @@ static void gc_data_segment(struct f2fs_sb_info *sbi, struct f2fs_summary *sum, ...@@ -588,11 +605,22 @@ static void gc_data_segment(struct f2fs_sb_info *sbi, struct f2fs_summary *sum,
next_iput: next_iput:
iput(inode); iput(inode);
} }
if (++phase < 4) if (++phase < 4)
goto next_step; goto next_step;
if (gc_type == FG_GC) if (gc_type == FG_GC) {
f2fs_submit_bio(sbi, DATA, true); f2fs_submit_bio(sbi, DATA, true);
/*
* In the case of FG_GC, it'd be better to reclaim this victim
* completely.
*/
if (get_valid_blocks(sbi, segno, 1) != 0) {
phase = 2;
goto next_step;
}
}
} }
static int __get_victim(struct f2fs_sb_info *sbi, unsigned int *victim, static int __get_victim(struct f2fs_sb_info *sbi, unsigned int *victim,
...@@ -611,18 +639,15 @@ static void do_garbage_collect(struct f2fs_sb_info *sbi, unsigned int segno, ...@@ -611,18 +639,15 @@ static void do_garbage_collect(struct f2fs_sb_info *sbi, unsigned int segno,
{ {
struct page *sum_page; struct page *sum_page;
struct f2fs_summary_block *sum; struct f2fs_summary_block *sum;
struct blk_plug plug;
/* read segment summary of victim */ /* read segment summary of victim */
sum_page = get_sum_page(sbi, segno); sum_page = get_sum_page(sbi, segno);
if (IS_ERR(sum_page)) if (IS_ERR(sum_page))
return; return;
/* blk_start_plug(&plug);
* CP needs to lock sum_page. In this time, we don't need
* to lock this page, because this summary page is not gone anywhere.
* Also, this page is not gonna be updated before GC is done.
*/
unlock_page(sum_page);
sum = page_address(sum_page); sum = page_address(sum_page);
switch (GET_SUM_TYPE((&sum->footer))) { switch (GET_SUM_TYPE((&sum->footer))) {
...@@ -633,10 +658,12 @@ static void do_garbage_collect(struct f2fs_sb_info *sbi, unsigned int segno, ...@@ -633,10 +658,12 @@ static void do_garbage_collect(struct f2fs_sb_info *sbi, unsigned int segno,
gc_data_segment(sbi, sum->entries, ilist, segno, gc_type); gc_data_segment(sbi, sum->entries, ilist, segno, gc_type);
break; break;
} }
blk_finish_plug(&plug);
stat_inc_seg_count(sbi, GET_SUM_TYPE((&sum->footer))); stat_inc_seg_count(sbi, GET_SUM_TYPE((&sum->footer)));
stat_inc_call_count(sbi->stat_info); stat_inc_call_count(sbi->stat_info);
f2fs_put_page(sum_page, 0); f2fs_put_page(sum_page, 1);
} }
int f2fs_gc(struct f2fs_sb_info *sbi) int f2fs_gc(struct f2fs_sb_info *sbi)
...@@ -652,8 +679,10 @@ int f2fs_gc(struct f2fs_sb_info *sbi) ...@@ -652,8 +679,10 @@ int f2fs_gc(struct f2fs_sb_info *sbi)
if (!(sbi->sb->s_flags & MS_ACTIVE)) if (!(sbi->sb->s_flags & MS_ACTIVE))
goto stop; goto stop;
if (gc_type == BG_GC && has_not_enough_free_secs(sbi, nfree)) if (gc_type == BG_GC && has_not_enough_free_secs(sbi, nfree)) {
gc_type = FG_GC; gc_type = FG_GC;
write_checkpoint(sbi, false);
}
if (!__get_victim(sbi, &segno, gc_type, NO_CHECK_TYPE)) if (!__get_victim(sbi, &segno, gc_type, NO_CHECK_TYPE))
goto stop; goto stop;
...@@ -662,9 +691,11 @@ int f2fs_gc(struct f2fs_sb_info *sbi) ...@@ -662,9 +691,11 @@ int f2fs_gc(struct f2fs_sb_info *sbi)
for (i = 0; i < sbi->segs_per_sec; i++) for (i = 0; i < sbi->segs_per_sec; i++)
do_garbage_collect(sbi, segno + i, &ilist, gc_type); do_garbage_collect(sbi, segno + i, &ilist, gc_type);
if (gc_type == FG_GC && if (gc_type == FG_GC) {
get_valid_blocks(sbi, segno, sbi->segs_per_sec) == 0) sbi->cur_victim_sec = NULL_SEGNO;
nfree++; nfree++;
WARN_ON(get_valid_blocks(sbi, segno, sbi->segs_per_sec));
}
if (has_not_enough_free_secs(sbi, nfree)) if (has_not_enough_free_secs(sbi, nfree))
goto gc_more; goto gc_more;
......
...@@ -13,9 +13,9 @@ ...@@ -13,9 +13,9 @@
* whether IO subsystem is idle * whether IO subsystem is idle
* or not * or not
*/ */
#define GC_THREAD_MIN_SLEEP_TIME 10000 /* milliseconds */ #define GC_THREAD_MIN_SLEEP_TIME 30000 /* milliseconds */
#define GC_THREAD_MAX_SLEEP_TIME 30000 #define GC_THREAD_MAX_SLEEP_TIME 60000
#define GC_THREAD_NOGC_SLEEP_TIME 10000 #define GC_THREAD_NOGC_SLEEP_TIME 300000 /* wait 5 min */
#define LIMIT_INVALID_BLOCK 40 /* percentage over total user space */ #define LIMIT_INVALID_BLOCK 40 /* percentage over total user space */
#define LIMIT_FREE_BLOCK 40 /* percentage over invalid + free space */ #define LIMIT_FREE_BLOCK 40 /* percentage over invalid + free space */
...@@ -58,6 +58,9 @@ static inline block_t limit_free_user_blocks(struct f2fs_sb_info *sbi) ...@@ -58,6 +58,9 @@ static inline block_t limit_free_user_blocks(struct f2fs_sb_info *sbi)
static inline long increase_sleep_time(long wait) static inline long increase_sleep_time(long wait)
{ {
if (wait == GC_THREAD_NOGC_SLEEP_TIME)
return wait;
wait += GC_THREAD_MIN_SLEEP_TIME; wait += GC_THREAD_MIN_SLEEP_TIME;
if (wait > GC_THREAD_MAX_SLEEP_TIME) if (wait > GC_THREAD_MAX_SLEEP_TIME)
wait = GC_THREAD_MAX_SLEEP_TIME; wait = GC_THREAD_MAX_SLEEP_TIME;
...@@ -66,6 +69,9 @@ static inline long increase_sleep_time(long wait) ...@@ -66,6 +69,9 @@ static inline long increase_sleep_time(long wait)
static inline long decrease_sleep_time(long wait) static inline long decrease_sleep_time(long wait)
{ {
if (wait == GC_THREAD_NOGC_SLEEP_TIME)
wait = GC_THREAD_MAX_SLEEP_TIME;
wait -= GC_THREAD_MIN_SLEEP_TIME; wait -= GC_THREAD_MIN_SLEEP_TIME;
if (wait <= GC_THREAD_MIN_SLEEP_TIME) if (wait <= GC_THREAD_MIN_SLEEP_TIME)
wait = GC_THREAD_MIN_SLEEP_TIME; wait = GC_THREAD_MIN_SLEEP_TIME;
......
...@@ -16,6 +16,8 @@ ...@@ -16,6 +16,8 @@
#include "f2fs.h" #include "f2fs.h"
#include "node.h" #include "node.h"
#include <trace/events/f2fs.h>
void f2fs_set_inode_flags(struct inode *inode) void f2fs_set_inode_flags(struct inode *inode)
{ {
unsigned int flags = F2FS_I(inode)->i_flags; unsigned int flags = F2FS_I(inode)->i_flags;
...@@ -44,7 +46,11 @@ static int do_read_inode(struct inode *inode) ...@@ -44,7 +46,11 @@ static int do_read_inode(struct inode *inode)
struct f2fs_inode *ri; struct f2fs_inode *ri;
/* Check if ino is within scope */ /* Check if ino is within scope */
check_nid_range(sbi, inode->i_ino); if (check_nid_range(sbi, inode->i_ino)) {
f2fs_msg(inode->i_sb, KERN_ERR, "bad inode number: %lu",
(unsigned long) inode->i_ino);
return -EINVAL;
}
node_page = get_node_page(sbi, inode->i_ino); node_page = get_node_page(sbi, inode->i_ino);
if (IS_ERR(node_page)) if (IS_ERR(node_page))
...@@ -76,7 +82,6 @@ static int do_read_inode(struct inode *inode) ...@@ -76,7 +82,6 @@ static int do_read_inode(struct inode *inode)
fi->i_xattr_nid = le32_to_cpu(ri->i_xattr_nid); fi->i_xattr_nid = le32_to_cpu(ri->i_xattr_nid);
fi->i_flags = le32_to_cpu(ri->i_flags); fi->i_flags = le32_to_cpu(ri->i_flags);
fi->flags = 0; fi->flags = 0;
fi->data_version = le64_to_cpu(F2FS_CKPT(sbi)->checkpoint_ver) - 1;
fi->i_advise = ri->i_advise; fi->i_advise = ri->i_advise;
fi->i_pino = le32_to_cpu(ri->i_pino); fi->i_pino = le32_to_cpu(ri->i_pino);
get_extent_info(&fi->ext, ri->i_ext); get_extent_info(&fi->ext, ri->i_ext);
...@@ -88,13 +93,16 @@ struct inode *f2fs_iget(struct super_block *sb, unsigned long ino) ...@@ -88,13 +93,16 @@ struct inode *f2fs_iget(struct super_block *sb, unsigned long ino)
{ {
struct f2fs_sb_info *sbi = F2FS_SB(sb); struct f2fs_sb_info *sbi = F2FS_SB(sb);
struct inode *inode; struct inode *inode;
int ret; int ret = 0;
inode = iget_locked(sb, ino); inode = iget_locked(sb, ino);
if (!inode) if (!inode)
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
if (!(inode->i_state & I_NEW))
if (!(inode->i_state & I_NEW)) {
trace_f2fs_iget(inode);
return inode; return inode;
}
if (ino == F2FS_NODE_INO(sbi) || ino == F2FS_META_INO(sbi)) if (ino == F2FS_NODE_INO(sbi) || ino == F2FS_META_INO(sbi))
goto make_now; goto make_now;
...@@ -136,11 +144,12 @@ struct inode *f2fs_iget(struct super_block *sb, unsigned long ino) ...@@ -136,11 +144,12 @@ struct inode *f2fs_iget(struct super_block *sb, unsigned long ino)
goto bad_inode; goto bad_inode;
} }
unlock_new_inode(inode); unlock_new_inode(inode);
trace_f2fs_iget(inode);
return inode; return inode;
bad_inode: bad_inode:
iget_failed(inode); iget_failed(inode);
trace_f2fs_iget_exit(inode, ret);
return ERR_PTR(ret); return ERR_PTR(ret);
} }
...@@ -192,47 +201,51 @@ void update_inode(struct inode *inode, struct page *node_page) ...@@ -192,47 +201,51 @@ void update_inode(struct inode *inode, struct page *node_page)
set_page_dirty(node_page); set_page_dirty(node_page);
} }
int f2fs_write_inode(struct inode *inode, struct writeback_control *wbc) int update_inode_page(struct inode *inode)
{ {
struct f2fs_sb_info *sbi = F2FS_SB(inode->i_sb); struct f2fs_sb_info *sbi = F2FS_SB(inode->i_sb);
struct page *node_page; struct page *node_page;
bool need_lock = false;
if (inode->i_ino == F2FS_NODE_INO(sbi) ||
inode->i_ino == F2FS_META_INO(sbi))
return 0;
if (wbc)
f2fs_balance_fs(sbi);
node_page = get_node_page(sbi, inode->i_ino); node_page = get_node_page(sbi, inode->i_ino);
if (IS_ERR(node_page)) if (IS_ERR(node_page))
return PTR_ERR(node_page); return PTR_ERR(node_page);
if (!PageDirty(node_page)) {
need_lock = true;
f2fs_put_page(node_page, 1);
mutex_lock(&sbi->write_inode);
node_page = get_node_page(sbi, inode->i_ino);
if (IS_ERR(node_page)) {
mutex_unlock(&sbi->write_inode);
return PTR_ERR(node_page);
}
}
update_inode(inode, node_page); update_inode(inode, node_page);
f2fs_put_page(node_page, 1); f2fs_put_page(node_page, 1);
if (need_lock)
mutex_unlock(&sbi->write_inode);
return 0; return 0;
} }
int f2fs_write_inode(struct inode *inode, struct writeback_control *wbc)
{
struct f2fs_sb_info *sbi = F2FS_SB(inode->i_sb);
int ret, ilock;
if (inode->i_ino == F2FS_NODE_INO(sbi) ||
inode->i_ino == F2FS_META_INO(sbi))
return 0;
if (wbc)
f2fs_balance_fs(sbi);
/*
* We need to lock here to prevent from producing dirty node pages
* during the urgent cleaning time when runing out of free sections.
*/
ilock = mutex_lock_op(sbi);
ret = update_inode_page(inode);
mutex_unlock_op(sbi, ilock);
return ret;
}
/* /*
* Called at the last iput() if i_nlink is zero * Called at the last iput() if i_nlink is zero
*/ */
void f2fs_evict_inode(struct inode *inode) void f2fs_evict_inode(struct inode *inode)
{ {
struct f2fs_sb_info *sbi = F2FS_SB(inode->i_sb); struct f2fs_sb_info *sbi = F2FS_SB(inode->i_sb);
int ilock;
trace_f2fs_evict_inode(inode);
truncate_inode_pages(&inode->i_data, 0); truncate_inode_pages(&inode->i_data, 0);
if (inode->i_ino == F2FS_NODE_INO(sbi) || if (inode->i_ino == F2FS_NODE_INO(sbi) ||
...@@ -252,7 +265,10 @@ void f2fs_evict_inode(struct inode *inode) ...@@ -252,7 +265,10 @@ void f2fs_evict_inode(struct inode *inode)
if (F2FS_HAS_BLOCKS(inode)) if (F2FS_HAS_BLOCKS(inode))
f2fs_truncate(inode); f2fs_truncate(inode);
ilock = mutex_lock_op(sbi);
remove_inode_page(inode); remove_inode_page(inode);
mutex_unlock_op(sbi, ilock);
sb_end_intwrite(inode->i_sb); sb_end_intwrite(inode->i_sb);
no_delete: no_delete:
clear_inode(inode); clear_inode(inode);
......
...@@ -15,8 +15,10 @@ ...@@ -15,8 +15,10 @@
#include <linux/ctype.h> #include <linux/ctype.h>
#include "f2fs.h" #include "f2fs.h"
#include "node.h"
#include "xattr.h" #include "xattr.h"
#include "acl.h" #include "acl.h"
#include <trace/events/f2fs.h>
static struct inode *f2fs_new_inode(struct inode *dir, umode_t mode) static struct inode *f2fs_new_inode(struct inode *dir, umode_t mode)
{ {
...@@ -25,19 +27,19 @@ static struct inode *f2fs_new_inode(struct inode *dir, umode_t mode) ...@@ -25,19 +27,19 @@ static struct inode *f2fs_new_inode(struct inode *dir, umode_t mode)
nid_t ino; nid_t ino;
struct inode *inode; struct inode *inode;
bool nid_free = false; bool nid_free = false;
int err; int err, ilock;
inode = new_inode(sb); inode = new_inode(sb);
if (!inode) if (!inode)
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
mutex_lock_op(sbi, NODE_NEW); ilock = mutex_lock_op(sbi);
if (!alloc_nid(sbi, &ino)) { if (!alloc_nid(sbi, &ino)) {
mutex_unlock_op(sbi, NODE_NEW); mutex_unlock_op(sbi, ilock);
err = -ENOSPC; err = -ENOSPC;
goto fail; goto fail;
} }
mutex_unlock_op(sbi, NODE_NEW); mutex_unlock_op(sbi, ilock);
inode->i_uid = current_fsuid(); inode->i_uid = current_fsuid();
...@@ -61,7 +63,7 @@ static struct inode *f2fs_new_inode(struct inode *dir, umode_t mode) ...@@ -61,7 +63,7 @@ static struct inode *f2fs_new_inode(struct inode *dir, umode_t mode)
nid_free = true; nid_free = true;
goto out; goto out;
} }
trace_f2fs_new_inode(inode, 0);
mark_inode_dirty(inode); mark_inode_dirty(inode);
return inode; return inode;
...@@ -69,6 +71,8 @@ static struct inode *f2fs_new_inode(struct inode *dir, umode_t mode) ...@@ -69,6 +71,8 @@ static struct inode *f2fs_new_inode(struct inode *dir, umode_t mode)
clear_nlink(inode); clear_nlink(inode);
unlock_new_inode(inode); unlock_new_inode(inode);
fail: fail:
trace_f2fs_new_inode(inode, err);
make_bad_inode(inode);
iput(inode); iput(inode);
if (nid_free) if (nid_free)
alloc_nid_failed(sbi, ino); alloc_nid_failed(sbi, ino);
...@@ -82,7 +86,7 @@ static int is_multimedia_file(const unsigned char *s, const char *sub) ...@@ -82,7 +86,7 @@ static int is_multimedia_file(const unsigned char *s, const char *sub)
int ret; int ret;
if (sublen > slen) if (sublen > slen)
return 1; return 0;
ret = memcmp(s + slen - sublen, sub, sublen); ret = memcmp(s + slen - sublen, sub, sublen);
if (ret) { /* compare upper case */ if (ret) { /* compare upper case */
...@@ -90,16 +94,16 @@ static int is_multimedia_file(const unsigned char *s, const char *sub) ...@@ -90,16 +94,16 @@ static int is_multimedia_file(const unsigned char *s, const char *sub)
char upper_sub[8]; char upper_sub[8];
for (i = 0; i < sublen && i < sizeof(upper_sub); i++) for (i = 0; i < sublen && i < sizeof(upper_sub); i++)
upper_sub[i] = toupper(sub[i]); upper_sub[i] = toupper(sub[i]);
return memcmp(s + slen - sublen, upper_sub, sublen); return !memcmp(s + slen - sublen, upper_sub, sublen);
} }
return ret; return !ret;
} }
/* /*
* Set multimedia files as cold files for hot/cold data separation * Set multimedia files as cold files for hot/cold data separation
*/ */
static inline void set_cold_file(struct f2fs_sb_info *sbi, struct inode *inode, static inline void set_cold_files(struct f2fs_sb_info *sbi, struct inode *inode,
const unsigned char *name) const unsigned char *name)
{ {
int i; int i;
...@@ -107,8 +111,8 @@ static inline void set_cold_file(struct f2fs_sb_info *sbi, struct inode *inode, ...@@ -107,8 +111,8 @@ static inline void set_cold_file(struct f2fs_sb_info *sbi, struct inode *inode,
int count = le32_to_cpu(sbi->raw_super->extension_count); int count = le32_to_cpu(sbi->raw_super->extension_count);
for (i = 0; i < count; i++) { for (i = 0; i < count; i++) {
if (!is_multimedia_file(name, extlist[i])) { if (is_multimedia_file(name, extlist[i])) {
F2FS_I(inode)->i_advise |= FADVISE_COLD_BIT; set_cold_file(inode);
break; break;
} }
} }
...@@ -121,7 +125,7 @@ static int f2fs_create(struct inode *dir, struct dentry *dentry, umode_t mode, ...@@ -121,7 +125,7 @@ static int f2fs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
struct f2fs_sb_info *sbi = F2FS_SB(sb); struct f2fs_sb_info *sbi = F2FS_SB(sb);
struct inode *inode; struct inode *inode;
nid_t ino = 0; nid_t ino = 0;
int err; int err, ilock;
f2fs_balance_fs(sbi); f2fs_balance_fs(sbi);
...@@ -130,14 +134,16 @@ static int f2fs_create(struct inode *dir, struct dentry *dentry, umode_t mode, ...@@ -130,14 +134,16 @@ static int f2fs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
return PTR_ERR(inode); return PTR_ERR(inode);
if (!test_opt(sbi, DISABLE_EXT_IDENTIFY)) if (!test_opt(sbi, DISABLE_EXT_IDENTIFY))
set_cold_file(sbi, inode, dentry->d_name.name); set_cold_files(sbi, inode, dentry->d_name.name);
inode->i_op = &f2fs_file_inode_operations; inode->i_op = &f2fs_file_inode_operations;
inode->i_fop = &f2fs_file_operations; inode->i_fop = &f2fs_file_operations;
inode->i_mapping->a_ops = &f2fs_dblock_aops; inode->i_mapping->a_ops = &f2fs_dblock_aops;
ino = inode->i_ino; ino = inode->i_ino;
ilock = mutex_lock_op(sbi);
err = f2fs_add_link(dentry, inode); err = f2fs_add_link(dentry, inode);
mutex_unlock_op(sbi, ilock);
if (err) if (err)
goto out; goto out;
...@@ -150,6 +156,7 @@ static int f2fs_create(struct inode *dir, struct dentry *dentry, umode_t mode, ...@@ -150,6 +156,7 @@ static int f2fs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
out: out:
clear_nlink(inode); clear_nlink(inode);
unlock_new_inode(inode); unlock_new_inode(inode);
make_bad_inode(inode);
iput(inode); iput(inode);
alloc_nid_failed(sbi, ino); alloc_nid_failed(sbi, ino);
return err; return err;
...@@ -161,7 +168,7 @@ static int f2fs_link(struct dentry *old_dentry, struct inode *dir, ...@@ -161,7 +168,7 @@ static int f2fs_link(struct dentry *old_dentry, struct inode *dir,
struct inode *inode = old_dentry->d_inode; struct inode *inode = old_dentry->d_inode;
struct super_block *sb = dir->i_sb; struct super_block *sb = dir->i_sb;
struct f2fs_sb_info *sbi = F2FS_SB(sb); struct f2fs_sb_info *sbi = F2FS_SB(sb);
int err; int err, ilock;
f2fs_balance_fs(sbi); f2fs_balance_fs(sbi);
...@@ -169,14 +176,23 @@ static int f2fs_link(struct dentry *old_dentry, struct inode *dir, ...@@ -169,14 +176,23 @@ static int f2fs_link(struct dentry *old_dentry, struct inode *dir,
atomic_inc(&inode->i_count); atomic_inc(&inode->i_count);
set_inode_flag(F2FS_I(inode), FI_INC_LINK); set_inode_flag(F2FS_I(inode), FI_INC_LINK);
ilock = mutex_lock_op(sbi);
err = f2fs_add_link(dentry, inode); err = f2fs_add_link(dentry, inode);
mutex_unlock_op(sbi, ilock);
if (err) if (err)
goto out; goto out;
/*
* This file should be checkpointed during fsync.
* We lost i_pino from now on.
*/
set_cp_file(inode);
d_instantiate(dentry, inode); d_instantiate(dentry, inode);
return 0; return 0;
out: out:
clear_inode_flag(F2FS_I(inode), FI_INC_LINK); clear_inode_flag(F2FS_I(inode), FI_INC_LINK);
make_bad_inode(inode);
iput(inode); iput(inode);
return err; return err;
} }
...@@ -197,7 +213,7 @@ static struct dentry *f2fs_lookup(struct inode *dir, struct dentry *dentry, ...@@ -197,7 +213,7 @@ static struct dentry *f2fs_lookup(struct inode *dir, struct dentry *dentry,
struct f2fs_dir_entry *de; struct f2fs_dir_entry *de;
struct page *page; struct page *page;
if (dentry->d_name.len > F2FS_MAX_NAME_LEN) if (dentry->d_name.len > F2FS_NAME_LEN)
return ERR_PTR(-ENAMETOOLONG); return ERR_PTR(-ENAMETOOLONG);
de = f2fs_find_entry(dir, &dentry->d_name, &page); de = f2fs_find_entry(dir, &dentry->d_name, &page);
...@@ -222,7 +238,9 @@ static int f2fs_unlink(struct inode *dir, struct dentry *dentry) ...@@ -222,7 +238,9 @@ static int f2fs_unlink(struct inode *dir, struct dentry *dentry)
struct f2fs_dir_entry *de; struct f2fs_dir_entry *de;
struct page *page; struct page *page;
int err = -ENOENT; int err = -ENOENT;
int ilock;
trace_f2fs_unlink_enter(dir, dentry);
f2fs_balance_fs(sbi); f2fs_balance_fs(sbi);
de = f2fs_find_entry(dir, &dentry->d_name, &page); de = f2fs_find_entry(dir, &dentry->d_name, &page);
...@@ -236,11 +254,14 @@ static int f2fs_unlink(struct inode *dir, struct dentry *dentry) ...@@ -236,11 +254,14 @@ static int f2fs_unlink(struct inode *dir, struct dentry *dentry)
goto fail; goto fail;
} }
ilock = mutex_lock_op(sbi);
f2fs_delete_entry(de, page, inode); f2fs_delete_entry(de, page, inode);
mutex_unlock_op(sbi, ilock);
/* In order to evict this inode, we set it dirty */ /* In order to evict this inode, we set it dirty */
mark_inode_dirty(inode); mark_inode_dirty(inode);
fail: fail:
trace_f2fs_unlink_exit(inode, err);
return err; return err;
} }
...@@ -251,7 +272,7 @@ static int f2fs_symlink(struct inode *dir, struct dentry *dentry, ...@@ -251,7 +272,7 @@ static int f2fs_symlink(struct inode *dir, struct dentry *dentry,
struct f2fs_sb_info *sbi = F2FS_SB(sb); struct f2fs_sb_info *sbi = F2FS_SB(sb);
struct inode *inode; struct inode *inode;
size_t symlen = strlen(symname) + 1; size_t symlen = strlen(symname) + 1;
int err; int err, ilock;
f2fs_balance_fs(sbi); f2fs_balance_fs(sbi);
...@@ -262,7 +283,9 @@ static int f2fs_symlink(struct inode *dir, struct dentry *dentry, ...@@ -262,7 +283,9 @@ static int f2fs_symlink(struct inode *dir, struct dentry *dentry,
inode->i_op = &f2fs_symlink_inode_operations; inode->i_op = &f2fs_symlink_inode_operations;
inode->i_mapping->a_ops = &f2fs_dblock_aops; inode->i_mapping->a_ops = &f2fs_dblock_aops;
ilock = mutex_lock_op(sbi);
err = f2fs_add_link(dentry, inode); err = f2fs_add_link(dentry, inode);
mutex_unlock_op(sbi, ilock);
if (err) if (err)
goto out; goto out;
...@@ -275,6 +298,7 @@ static int f2fs_symlink(struct inode *dir, struct dentry *dentry, ...@@ -275,6 +298,7 @@ static int f2fs_symlink(struct inode *dir, struct dentry *dentry,
out: out:
clear_nlink(inode); clear_nlink(inode);
unlock_new_inode(inode); unlock_new_inode(inode);
make_bad_inode(inode);
iput(inode); iput(inode);
alloc_nid_failed(sbi, inode->i_ino); alloc_nid_failed(sbi, inode->i_ino);
return err; return err;
...@@ -284,7 +308,7 @@ static int f2fs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode) ...@@ -284,7 +308,7 @@ static int f2fs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
{ {
struct f2fs_sb_info *sbi = F2FS_SB(dir->i_sb); struct f2fs_sb_info *sbi = F2FS_SB(dir->i_sb);
struct inode *inode; struct inode *inode;
int err; int err, ilock;
f2fs_balance_fs(sbi); f2fs_balance_fs(sbi);
...@@ -298,7 +322,9 @@ static int f2fs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode) ...@@ -298,7 +322,9 @@ static int f2fs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
mapping_set_gfp_mask(inode->i_mapping, GFP_F2FS_ZERO); mapping_set_gfp_mask(inode->i_mapping, GFP_F2FS_ZERO);
set_inode_flag(F2FS_I(inode), FI_INC_LINK); set_inode_flag(F2FS_I(inode), FI_INC_LINK);
ilock = mutex_lock_op(sbi);
err = f2fs_add_link(dentry, inode); err = f2fs_add_link(dentry, inode);
mutex_unlock_op(sbi, ilock);
if (err) if (err)
goto out_fail; goto out_fail;
...@@ -313,6 +339,7 @@ static int f2fs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode) ...@@ -313,6 +339,7 @@ static int f2fs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
clear_inode_flag(F2FS_I(inode), FI_INC_LINK); clear_inode_flag(F2FS_I(inode), FI_INC_LINK);
clear_nlink(inode); clear_nlink(inode);
unlock_new_inode(inode); unlock_new_inode(inode);
make_bad_inode(inode);
iput(inode); iput(inode);
alloc_nid_failed(sbi, inode->i_ino); alloc_nid_failed(sbi, inode->i_ino);
return err; return err;
...@@ -333,6 +360,7 @@ static int f2fs_mknod(struct inode *dir, struct dentry *dentry, ...@@ -333,6 +360,7 @@ static int f2fs_mknod(struct inode *dir, struct dentry *dentry,
struct f2fs_sb_info *sbi = F2FS_SB(sb); struct f2fs_sb_info *sbi = F2FS_SB(sb);
struct inode *inode; struct inode *inode;
int err = 0; int err = 0;
int ilock;
if (!new_valid_dev(rdev)) if (!new_valid_dev(rdev))
return -EINVAL; return -EINVAL;
...@@ -346,7 +374,9 @@ static int f2fs_mknod(struct inode *dir, struct dentry *dentry, ...@@ -346,7 +374,9 @@ static int f2fs_mknod(struct inode *dir, struct dentry *dentry,
init_special_inode(inode, inode->i_mode, rdev); init_special_inode(inode, inode->i_mode, rdev);
inode->i_op = &f2fs_special_inode_operations; inode->i_op = &f2fs_special_inode_operations;
ilock = mutex_lock_op(sbi);
err = f2fs_add_link(dentry, inode); err = f2fs_add_link(dentry, inode);
mutex_unlock_op(sbi, ilock);
if (err) if (err)
goto out; goto out;
...@@ -357,6 +387,7 @@ static int f2fs_mknod(struct inode *dir, struct dentry *dentry, ...@@ -357,6 +387,7 @@ static int f2fs_mknod(struct inode *dir, struct dentry *dentry,
out: out:
clear_nlink(inode); clear_nlink(inode);
unlock_new_inode(inode); unlock_new_inode(inode);
make_bad_inode(inode);
iput(inode); iput(inode);
alloc_nid_failed(sbi, inode->i_ino); alloc_nid_failed(sbi, inode->i_ino);
return err; return err;
...@@ -374,7 +405,7 @@ static int f2fs_rename(struct inode *old_dir, struct dentry *old_dentry, ...@@ -374,7 +405,7 @@ static int f2fs_rename(struct inode *old_dir, struct dentry *old_dentry,
struct f2fs_dir_entry *old_dir_entry = NULL; struct f2fs_dir_entry *old_dir_entry = NULL;
struct f2fs_dir_entry *old_entry; struct f2fs_dir_entry *old_entry;
struct f2fs_dir_entry *new_entry; struct f2fs_dir_entry *new_entry;
int err = -ENOENT; int err = -ENOENT, ilock = -1;
f2fs_balance_fs(sbi); f2fs_balance_fs(sbi);
...@@ -389,7 +420,7 @@ static int f2fs_rename(struct inode *old_dir, struct dentry *old_dentry, ...@@ -389,7 +420,7 @@ static int f2fs_rename(struct inode *old_dir, struct dentry *old_dentry,
goto out_old; goto out_old;
} }
mutex_lock_op(sbi, RENAME); ilock = mutex_lock_op(sbi);
if (new_inode) { if (new_inode) {
struct page *new_page; struct page *new_page;
...@@ -412,7 +443,7 @@ static int f2fs_rename(struct inode *old_dir, struct dentry *old_dentry, ...@@ -412,7 +443,7 @@ static int f2fs_rename(struct inode *old_dir, struct dentry *old_dentry,
drop_nlink(new_inode); drop_nlink(new_inode);
if (!new_inode->i_nlink) if (!new_inode->i_nlink)
add_orphan_inode(sbi, new_inode->i_ino); add_orphan_inode(sbi, new_inode->i_ino);
f2fs_write_inode(new_inode, NULL); update_inode_page(new_inode);
} else { } else {
err = f2fs_add_link(new_dentry, old_inode); err = f2fs_add_link(new_dentry, old_inode);
if (err) if (err)
...@@ -420,12 +451,11 @@ static int f2fs_rename(struct inode *old_dir, struct dentry *old_dentry, ...@@ -420,12 +451,11 @@ static int f2fs_rename(struct inode *old_dir, struct dentry *old_dentry,
if (old_dir_entry) { if (old_dir_entry) {
inc_nlink(new_dir); inc_nlink(new_dir);
f2fs_write_inode(new_dir, NULL); update_inode_page(new_dir);
} }
} }
old_inode->i_ctime = CURRENT_TIME; old_inode->i_ctime = CURRENT_TIME;
set_inode_flag(F2FS_I(old_inode), FI_NEED_CP);
mark_inode_dirty(old_inode); mark_inode_dirty(old_inode);
f2fs_delete_entry(old_entry, old_page, NULL); f2fs_delete_entry(old_entry, old_page, NULL);
...@@ -439,10 +469,10 @@ static int f2fs_rename(struct inode *old_dir, struct dentry *old_dentry, ...@@ -439,10 +469,10 @@ static int f2fs_rename(struct inode *old_dir, struct dentry *old_dentry,
f2fs_put_page(old_dir_page, 0); f2fs_put_page(old_dir_page, 0);
} }
drop_nlink(old_dir); drop_nlink(old_dir);
f2fs_write_inode(old_dir, NULL); update_inode_page(old_dir);
} }
mutex_unlock_op(sbi, RENAME); mutex_unlock_op(sbi, ilock);
return 0; return 0;
out_dir: out_dir:
...@@ -450,7 +480,7 @@ static int f2fs_rename(struct inode *old_dir, struct dentry *old_dentry, ...@@ -450,7 +480,7 @@ static int f2fs_rename(struct inode *old_dir, struct dentry *old_dentry,
kunmap(old_dir_page); kunmap(old_dir_page);
f2fs_put_page(old_dir_page, 0); f2fs_put_page(old_dir_page, 0);
} }
mutex_unlock_op(sbi, RENAME); mutex_unlock_op(sbi, ilock);
out_old: out_old:
kunmap(old_page); kunmap(old_page);
f2fs_put_page(old_page, 0); f2fs_put_page(old_page, 0);
......
This diff is collapsed.
...@@ -29,6 +29,9 @@ ...@@ -29,6 +29,9 @@
/* vector size for gang look-up from nat cache that consists of radix tree */ /* vector size for gang look-up from nat cache that consists of radix tree */
#define NATVEC_SIZE 64 #define NATVEC_SIZE 64
/* return value for read_node_page */
#define LOCKED_PAGE 1
/* /*
* For node information * For node information
*/ */
...@@ -239,7 +242,7 @@ static inline bool IS_DNODE(struct page *node_page) ...@@ -239,7 +242,7 @@ static inline bool IS_DNODE(struct page *node_page)
return false; return false;
if (ofs >= 6 + 2 * NIDS_PER_BLOCK) { if (ofs >= 6 + 2 * NIDS_PER_BLOCK) {
ofs -= 6 + 2 * NIDS_PER_BLOCK; ofs -= 6 + 2 * NIDS_PER_BLOCK;
if ((long int)ofs % (NIDS_PER_BLOCK + 1)) if (!((long int)ofs % (NIDS_PER_BLOCK + 1)))
return false; return false;
} }
return true; return true;
...@@ -277,6 +280,21 @@ static inline int is_cold_file(struct inode *inode) ...@@ -277,6 +280,21 @@ static inline int is_cold_file(struct inode *inode)
return F2FS_I(inode)->i_advise & FADVISE_COLD_BIT; return F2FS_I(inode)->i_advise & FADVISE_COLD_BIT;
} }
static inline void set_cold_file(struct inode *inode)
{
F2FS_I(inode)->i_advise |= FADVISE_COLD_BIT;
}
static inline int is_cp_file(struct inode *inode)
{
return F2FS_I(inode)->i_advise & FADVISE_CP_BIT;
}
static inline void set_cp_file(struct inode *inode)
{
F2FS_I(inode)->i_advise |= FADVISE_CP_BIT;
}
static inline int is_cold_data(struct page *page) static inline int is_cold_data(struct page *page)
{ {
return PageChecked(page); return PageChecked(page);
......
...@@ -53,7 +53,7 @@ static int recover_dentry(struct page *ipage, struct inode *inode) ...@@ -53,7 +53,7 @@ static int recover_dentry(struct page *ipage, struct inode *inode)
dir = f2fs_iget(inode->i_sb, le32_to_cpu(raw_inode->i_pino)); dir = f2fs_iget(inode->i_sb, le32_to_cpu(raw_inode->i_pino));
if (IS_ERR(dir)) { if (IS_ERR(dir)) {
err = -EINVAL; err = PTR_ERR(dir);
goto out; goto out;
} }
...@@ -112,11 +112,14 @@ static int find_fsync_dnodes(struct f2fs_sb_info *sbi, struct list_head *head) ...@@ -112,11 +112,14 @@ static int find_fsync_dnodes(struct f2fs_sb_info *sbi, struct list_head *head)
while (1) { while (1) {
struct fsync_inode_entry *entry; struct fsync_inode_entry *entry;
if (f2fs_readpage(sbi, page, blkaddr, READ_SYNC)) err = f2fs_readpage(sbi, page, blkaddr, READ_SYNC);
if (err)
goto out; goto out;
lock_page(page);
if (cp_ver != cpver_of_node(page)) if (cp_ver != cpver_of_node(page))
goto out; goto unlock_out;
if (!is_fsync_dnode(page)) if (!is_fsync_dnode(page))
goto next; goto next;
...@@ -129,24 +132,23 @@ static int find_fsync_dnodes(struct f2fs_sb_info *sbi, struct list_head *head) ...@@ -129,24 +132,23 @@ static int find_fsync_dnodes(struct f2fs_sb_info *sbi, struct list_head *head)
FI_INC_LINK); FI_INC_LINK);
} else { } else {
if (IS_INODE(page) && is_dent_dnode(page)) { if (IS_INODE(page) && is_dent_dnode(page)) {
if (recover_inode_page(sbi, page)) { err = recover_inode_page(sbi, page);
err = -ENOMEM; if (err)
goto out; goto unlock_out;
}
} }
/* add this fsync inode to the list */ /* add this fsync inode to the list */
entry = kmem_cache_alloc(fsync_entry_slab, GFP_NOFS); entry = kmem_cache_alloc(fsync_entry_slab, GFP_NOFS);
if (!entry) { if (!entry) {
err = -ENOMEM; err = -ENOMEM;
goto out; goto unlock_out;
} }
entry->inode = f2fs_iget(sbi->sb, ino_of_node(page)); entry->inode = f2fs_iget(sbi->sb, ino_of_node(page));
if (IS_ERR(entry->inode)) { if (IS_ERR(entry->inode)) {
err = PTR_ERR(entry->inode); err = PTR_ERR(entry->inode);
kmem_cache_free(fsync_entry_slab, entry); kmem_cache_free(fsync_entry_slab, entry);
goto out; goto unlock_out;
} }
list_add_tail(&entry->list, head); list_add_tail(&entry->list, head);
...@@ -154,16 +156,20 @@ static int find_fsync_dnodes(struct f2fs_sb_info *sbi, struct list_head *head) ...@@ -154,16 +156,20 @@ static int find_fsync_dnodes(struct f2fs_sb_info *sbi, struct list_head *head)
} }
if (IS_INODE(page)) { if (IS_INODE(page)) {
err = recover_inode(entry->inode, page); err = recover_inode(entry->inode, page);
if (err) if (err == -ENOENT) {
goto out; goto next;
} else if (err) {
err = -EINVAL;
goto unlock_out;
}
} }
next: next:
/* check next segment */ /* check next segment */
blkaddr = next_blkaddr_of_node(page); blkaddr = next_blkaddr_of_node(page);
ClearPageUptodate(page);
} }
out: unlock_out:
unlock_page(page); unlock_page(page);
out:
__free_pages(page, 0); __free_pages(page, 0);
return err; return err;
} }
...@@ -232,13 +238,15 @@ static void check_index_in_prev_nodes(struct f2fs_sb_info *sbi, ...@@ -232,13 +238,15 @@ static void check_index_in_prev_nodes(struct f2fs_sb_info *sbi,
iput(inode); iput(inode);
} }
static void do_recover_data(struct f2fs_sb_info *sbi, struct inode *inode, static int do_recover_data(struct f2fs_sb_info *sbi, struct inode *inode,
struct page *page, block_t blkaddr) struct page *page, block_t blkaddr)
{ {
unsigned int start, end; unsigned int start, end;
struct dnode_of_data dn; struct dnode_of_data dn;
struct f2fs_summary sum; struct f2fs_summary sum;
struct node_info ni; struct node_info ni;
int err = 0;
int ilock;
start = start_bidx_of_node(ofs_of_node(page)); start = start_bidx_of_node(ofs_of_node(page));
if (IS_INODE(page)) if (IS_INODE(page))
...@@ -246,9 +254,14 @@ static void do_recover_data(struct f2fs_sb_info *sbi, struct inode *inode, ...@@ -246,9 +254,14 @@ static void do_recover_data(struct f2fs_sb_info *sbi, struct inode *inode,
else else
end = start + ADDRS_PER_BLOCK; end = start + ADDRS_PER_BLOCK;
ilock = mutex_lock_op(sbi);
set_new_dnode(&dn, inode, NULL, NULL, 0); set_new_dnode(&dn, inode, NULL, NULL, 0);
if (get_dnode_of_data(&dn, start, 0))
return; err = get_dnode_of_data(&dn, start, ALLOC_NODE);
if (err) {
mutex_unlock_op(sbi, ilock);
return err;
}
wait_on_page_writeback(dn.node_page); wait_on_page_writeback(dn.node_page);
...@@ -293,14 +306,17 @@ static void do_recover_data(struct f2fs_sb_info *sbi, struct inode *inode, ...@@ -293,14 +306,17 @@ static void do_recover_data(struct f2fs_sb_info *sbi, struct inode *inode,
recover_node_page(sbi, dn.node_page, &sum, &ni, blkaddr); recover_node_page(sbi, dn.node_page, &sum, &ni, blkaddr);
f2fs_put_dnode(&dn); f2fs_put_dnode(&dn);
mutex_unlock_op(sbi, ilock);
return 0;
} }
static void recover_data(struct f2fs_sb_info *sbi, static int recover_data(struct f2fs_sb_info *sbi,
struct list_head *head, int type) struct list_head *head, int type)
{ {
unsigned long long cp_ver = le64_to_cpu(sbi->ckpt->checkpoint_ver); unsigned long long cp_ver = le64_to_cpu(sbi->ckpt->checkpoint_ver);
struct curseg_info *curseg; struct curseg_info *curseg;
struct page *page; struct page *page;
int err = 0;
block_t blkaddr; block_t blkaddr;
/* get node pages in the current segment */ /* get node pages in the current segment */
...@@ -310,23 +326,29 @@ static void recover_data(struct f2fs_sb_info *sbi, ...@@ -310,23 +326,29 @@ static void recover_data(struct f2fs_sb_info *sbi,
/* read node page */ /* read node page */
page = alloc_page(GFP_NOFS | __GFP_ZERO); page = alloc_page(GFP_NOFS | __GFP_ZERO);
if (IS_ERR(page)) if (IS_ERR(page))
return; return -ENOMEM;
lock_page(page); lock_page(page);
while (1) { while (1) {
struct fsync_inode_entry *entry; struct fsync_inode_entry *entry;
if (f2fs_readpage(sbi, page, blkaddr, READ_SYNC)) err = f2fs_readpage(sbi, page, blkaddr, READ_SYNC);
if (err)
goto out; goto out;
lock_page(page);
if (cp_ver != cpver_of_node(page)) if (cp_ver != cpver_of_node(page))
goto out; goto unlock_out;
entry = get_fsync_inode(head, ino_of_node(page)); entry = get_fsync_inode(head, ino_of_node(page));
if (!entry) if (!entry)
goto next; goto next;
do_recover_data(sbi, entry->inode, page, blkaddr); err = do_recover_data(sbi, entry->inode, page, blkaddr);
if (err)
goto out;
if (entry->blkaddr == blkaddr) { if (entry->blkaddr == blkaddr) {
iput(entry->inode); iput(entry->inode);
...@@ -336,28 +358,32 @@ static void recover_data(struct f2fs_sb_info *sbi, ...@@ -336,28 +358,32 @@ static void recover_data(struct f2fs_sb_info *sbi,
next: next:
/* check next segment */ /* check next segment */
blkaddr = next_blkaddr_of_node(page); blkaddr = next_blkaddr_of_node(page);
ClearPageUptodate(page);
} }
out: unlock_out:
unlock_page(page); unlock_page(page);
out:
__free_pages(page, 0); __free_pages(page, 0);
if (!err)
allocate_new_segments(sbi); allocate_new_segments(sbi);
return err;
} }
void recover_fsync_data(struct f2fs_sb_info *sbi) int recover_fsync_data(struct f2fs_sb_info *sbi)
{ {
struct list_head inode_list; struct list_head inode_list;
int err;
fsync_entry_slab = f2fs_kmem_cache_create("f2fs_fsync_inode_entry", fsync_entry_slab = f2fs_kmem_cache_create("f2fs_fsync_inode_entry",
sizeof(struct fsync_inode_entry), NULL); sizeof(struct fsync_inode_entry), NULL);
if (unlikely(!fsync_entry_slab)) if (unlikely(!fsync_entry_slab))
return; return -ENOMEM;
INIT_LIST_HEAD(&inode_list); INIT_LIST_HEAD(&inode_list);
/* step #1: find fsynced inode numbers */ /* step #1: find fsynced inode numbers */
if (find_fsync_dnodes(sbi, &inode_list)) err = find_fsync_dnodes(sbi, &inode_list);
if (err)
goto out; goto out;
if (list_empty(&inode_list)) if (list_empty(&inode_list))
...@@ -365,11 +391,12 @@ void recover_fsync_data(struct f2fs_sb_info *sbi) ...@@ -365,11 +391,12 @@ void recover_fsync_data(struct f2fs_sb_info *sbi)
/* step #2: recover data */ /* step #2: recover data */
sbi->por_doing = 1; sbi->por_doing = 1;
recover_data(sbi, &inode_list, CURSEG_WARM_NODE); err = recover_data(sbi, &inode_list, CURSEG_WARM_NODE);
sbi->por_doing = 0; sbi->por_doing = 0;
BUG_ON(!list_empty(&inode_list)); BUG_ON(!list_empty(&inode_list));
out: out:
destroy_fsync_dnodes(sbi, &inode_list); destroy_fsync_dnodes(sbi, &inode_list);
kmem_cache_destroy(fsync_entry_slab); kmem_cache_destroy(fsync_entry_slab);
write_checkpoint(sbi, false); write_checkpoint(sbi, false);
return err;
} }
This diff is collapsed.
...@@ -8,10 +8,13 @@ ...@@ -8,10 +8,13 @@
* it under the terms of the GNU General Public License version 2 as * it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation. * published by the Free Software Foundation.
*/ */
#include <linux/blkdev.h>
/* constant macro */ /* constant macro */
#define NULL_SEGNO ((unsigned int)(~0)) #define NULL_SEGNO ((unsigned int)(~0))
#define NULL_SECNO ((unsigned int)(~0))
/* V: Logical segment # in volume, R: Relative segment # in main area */ /* L: Logical segment # in volume, R: Relative segment # in main area */
#define GET_L2R_SEGNO(free_i, segno) (segno - free_i->start_segno) #define GET_L2R_SEGNO(free_i, segno) (segno - free_i->start_segno)
#define GET_R2L_SEGNO(free_i, segno) (segno + free_i->start_segno) #define GET_R2L_SEGNO(free_i, segno) (segno + free_i->start_segno)
...@@ -23,13 +26,13 @@ ...@@ -23,13 +26,13 @@
((t == CURSEG_HOT_NODE) || (t == CURSEG_COLD_NODE) || \ ((t == CURSEG_HOT_NODE) || (t == CURSEG_COLD_NODE) || \
(t == CURSEG_WARM_NODE)) (t == CURSEG_WARM_NODE))
#define IS_CURSEG(sbi, segno) \ #define IS_CURSEG(sbi, seg) \
((segno == CURSEG_I(sbi, CURSEG_HOT_DATA)->segno) || \ ((seg == CURSEG_I(sbi, CURSEG_HOT_DATA)->segno) || \
(segno == CURSEG_I(sbi, CURSEG_WARM_DATA)->segno) || \ (seg == CURSEG_I(sbi, CURSEG_WARM_DATA)->segno) || \
(segno == CURSEG_I(sbi, CURSEG_COLD_DATA)->segno) || \ (seg == CURSEG_I(sbi, CURSEG_COLD_DATA)->segno) || \
(segno == CURSEG_I(sbi, CURSEG_HOT_NODE)->segno) || \ (seg == CURSEG_I(sbi, CURSEG_HOT_NODE)->segno) || \
(segno == CURSEG_I(sbi, CURSEG_WARM_NODE)->segno) || \ (seg == CURSEG_I(sbi, CURSEG_WARM_NODE)->segno) || \
(segno == CURSEG_I(sbi, CURSEG_COLD_NODE)->segno)) (seg == CURSEG_I(sbi, CURSEG_COLD_NODE)->segno))
#define IS_CURSEC(sbi, secno) \ #define IS_CURSEC(sbi, secno) \
((secno == CURSEG_I(sbi, CURSEG_HOT_DATA)->segno / \ ((secno == CURSEG_I(sbi, CURSEG_HOT_DATA)->segno / \
...@@ -81,9 +84,12 @@ ...@@ -81,9 +84,12 @@
#define f2fs_bitmap_size(nr) \ #define f2fs_bitmap_size(nr) \
(BITS_TO_LONGS(nr) * sizeof(unsigned long)) (BITS_TO_LONGS(nr) * sizeof(unsigned long))
#define TOTAL_SEGS(sbi) (SM_I(sbi)->main_segments) #define TOTAL_SEGS(sbi) (SM_I(sbi)->main_segments)
#define TOTAL_SECS(sbi) (sbi->total_sections)
#define SECTOR_FROM_BLOCK(sbi, blk_addr) \ #define SECTOR_FROM_BLOCK(sbi, blk_addr) \
(blk_addr << ((sbi)->log_blocksize - F2FS_LOG_SECTOR_SIZE)) (blk_addr << ((sbi)->log_blocksize - F2FS_LOG_SECTOR_SIZE))
#define SECTOR_TO_BLOCK(sbi, sectors) \
(sectors >> ((sbi)->log_blocksize - F2FS_LOG_SECTOR_SIZE))
/* during checkpoint, bio_private is used to synchronize the last bio */ /* during checkpoint, bio_private is used to synchronize the last bio */
struct bio_private { struct bio_private {
...@@ -213,7 +219,7 @@ struct dirty_seglist_info { ...@@ -213,7 +219,7 @@ struct dirty_seglist_info {
unsigned long *dirty_segmap[NR_DIRTY_TYPE]; unsigned long *dirty_segmap[NR_DIRTY_TYPE];
struct mutex seglist_lock; /* lock for segment bitmaps */ struct mutex seglist_lock; /* lock for segment bitmaps */
int nr_dirty[NR_DIRTY_TYPE]; /* # of dirty segments */ int nr_dirty[NR_DIRTY_TYPE]; /* # of dirty segments */
unsigned long *victim_segmap[2]; /* BG_GC, FG_GC */ unsigned long *victim_secmap; /* background GC victims */
}; };
/* victim selection function for cleaning and SSR */ /* victim selection function for cleaning and SSR */
...@@ -464,8 +470,7 @@ static inline bool has_not_enough_free_secs(struct f2fs_sb_info *sbi, int freed) ...@@ -464,8 +470,7 @@ static inline bool has_not_enough_free_secs(struct f2fs_sb_info *sbi, int freed)
static inline int utilization(struct f2fs_sb_info *sbi) static inline int utilization(struct f2fs_sb_info *sbi)
{ {
return (long int)valid_user_blocks(sbi) * 100 / return div_u64(valid_user_blocks(sbi) * 100, sbi->user_block_count);
(long int)sbi->user_block_count;
} }
/* /*
...@@ -616,3 +621,17 @@ static inline block_t sum_blk_addr(struct f2fs_sb_info *sbi, int base, int type) ...@@ -616,3 +621,17 @@ static inline block_t sum_blk_addr(struct f2fs_sb_info *sbi, int base, int type)
le32_to_cpu(F2FS_CKPT(sbi)->cp_pack_total_block_count) le32_to_cpu(F2FS_CKPT(sbi)->cp_pack_total_block_count)
- (base + 1) + type; - (base + 1) + type;
} }
static inline bool sec_usage_check(struct f2fs_sb_info *sbi, unsigned int secno)
{
if (IS_CURSEC(sbi, secno) || (sbi->cur_victim_sec == secno))
return true;
return false;
}
static inline unsigned int max_hw_blocks(struct f2fs_sb_info *sbi)
{
struct block_device *bdev = sbi->sb->s_bdev;
struct request_queue *q = bdev_get_queue(bdev);
return SECTOR_TO_BLOCK(sbi, queue_max_sectors(q));
}
...@@ -12,7 +12,6 @@ ...@@ -12,7 +12,6 @@
#include <linux/init.h> #include <linux/init.h>
#include <linux/fs.h> #include <linux/fs.h>
#include <linux/statfs.h> #include <linux/statfs.h>
#include <linux/proc_fs.h>
#include <linux/buffer_head.h> #include <linux/buffer_head.h>
#include <linux/backing-dev.h> #include <linux/backing-dev.h>
#include <linux/kthread.h> #include <linux/kthread.h>
...@@ -21,12 +20,17 @@ ...@@ -21,12 +20,17 @@
#include <linux/seq_file.h> #include <linux/seq_file.h>
#include <linux/random.h> #include <linux/random.h>
#include <linux/exportfs.h> #include <linux/exportfs.h>
#include <linux/blkdev.h>
#include <linux/f2fs_fs.h> #include <linux/f2fs_fs.h>
#include "f2fs.h" #include "f2fs.h"
#include "node.h" #include "node.h"
#include "segment.h"
#include "xattr.h" #include "xattr.h"
#define CREATE_TRACE_POINTS
#include <trace/events/f2fs.h>
static struct kmem_cache *f2fs_inode_cachep; static struct kmem_cache *f2fs_inode_cachep;
enum { enum {
...@@ -94,6 +98,20 @@ static struct inode *f2fs_alloc_inode(struct super_block *sb) ...@@ -94,6 +98,20 @@ static struct inode *f2fs_alloc_inode(struct super_block *sb)
return &fi->vfs_inode; return &fi->vfs_inode;
} }
static int f2fs_drop_inode(struct inode *inode)
{
/*
* This is to avoid a deadlock condition like below.
* writeback_single_inode(inode)
* - f2fs_write_data_page
* - f2fs_gc -> iput -> evict
* - inode_wait_for_writeback(inode)
*/
if (!inode_unhashed(inode) && inode->i_state & I_SYNC)
return 0;
return generic_drop_inode(inode);
}
static void f2fs_i_callback(struct rcu_head *head) static void f2fs_i_callback(struct rcu_head *head)
{ {
struct inode *inode = container_of(head, struct inode, i_rcu); struct inode *inode = container_of(head, struct inode, i_rcu);
...@@ -132,13 +150,18 @@ int f2fs_sync_fs(struct super_block *sb, int sync) ...@@ -132,13 +150,18 @@ int f2fs_sync_fs(struct super_block *sb, int sync)
{ {
struct f2fs_sb_info *sbi = F2FS_SB(sb); struct f2fs_sb_info *sbi = F2FS_SB(sb);
trace_f2fs_sync_fs(sb, sync);
if (!sbi->s_dirty && !get_pages(sbi, F2FS_DIRTY_NODES)) if (!sbi->s_dirty && !get_pages(sbi, F2FS_DIRTY_NODES))
return 0; return 0;
if (sync) if (sync) {
mutex_lock(&sbi->gc_mutex);
write_checkpoint(sbi, false); write_checkpoint(sbi, false);
else mutex_unlock(&sbi->gc_mutex);
} else {
f2fs_balance_fs(sbi); f2fs_balance_fs(sbi);
}
return 0; return 0;
} }
...@@ -180,7 +203,7 @@ static int f2fs_statfs(struct dentry *dentry, struct kstatfs *buf) ...@@ -180,7 +203,7 @@ static int f2fs_statfs(struct dentry *dentry, struct kstatfs *buf)
buf->f_files = sbi->total_node_count; buf->f_files = sbi->total_node_count;
buf->f_ffree = sbi->total_node_count - valid_inode_count(sbi); buf->f_ffree = sbi->total_node_count - valid_inode_count(sbi);
buf->f_namelen = F2FS_MAX_NAME_LEN; buf->f_namelen = F2FS_NAME_LEN;
buf->f_fsid.val[0] = (u32)id; buf->f_fsid.val[0] = (u32)id;
buf->f_fsid.val[1] = (u32)(id >> 32); buf->f_fsid.val[1] = (u32)(id >> 32);
...@@ -223,6 +246,7 @@ static int f2fs_show_options(struct seq_file *seq, struct dentry *root) ...@@ -223,6 +246,7 @@ static int f2fs_show_options(struct seq_file *seq, struct dentry *root)
static struct super_operations f2fs_sops = { static struct super_operations f2fs_sops = {
.alloc_inode = f2fs_alloc_inode, .alloc_inode = f2fs_alloc_inode,
.drop_inode = f2fs_drop_inode,
.destroy_inode = f2fs_destroy_inode, .destroy_inode = f2fs_destroy_inode,
.write_inode = f2fs_write_inode, .write_inode = f2fs_write_inode,
.show_options = f2fs_show_options, .show_options = f2fs_show_options,
...@@ -457,6 +481,7 @@ static void init_sb_info(struct f2fs_sb_info *sbi) ...@@ -457,6 +481,7 @@ static void init_sb_info(struct f2fs_sb_info *sbi)
sbi->root_ino_num = le32_to_cpu(raw_super->root_ino); sbi->root_ino_num = le32_to_cpu(raw_super->root_ino);
sbi->node_ino_num = le32_to_cpu(raw_super->node_ino); sbi->node_ino_num = le32_to_cpu(raw_super->node_ino);
sbi->meta_ino_num = le32_to_cpu(raw_super->meta_ino); sbi->meta_ino_num = le32_to_cpu(raw_super->meta_ino);
sbi->cur_victim_sec = NULL_SECNO;
for (i = 0; i < NR_COUNT_TYPE; i++) for (i = 0; i < NR_COUNT_TYPE; i++)
atomic_set(&sbi->nr_pages[i], 0); atomic_set(&sbi->nr_pages[i], 0);
...@@ -473,7 +498,7 @@ static int validate_superblock(struct super_block *sb, ...@@ -473,7 +498,7 @@ static int validate_superblock(struct super_block *sb,
if (!*raw_super_buf) { if (!*raw_super_buf) {
f2fs_msg(sb, KERN_ERR, "unable to read %s superblock", f2fs_msg(sb, KERN_ERR, "unable to read %s superblock",
super); super);
return 1; return -EIO;
} }
*raw_super = (struct f2fs_super_block *) *raw_super = (struct f2fs_super_block *)
...@@ -485,7 +510,7 @@ static int validate_superblock(struct super_block *sb, ...@@ -485,7 +510,7 @@ static int validate_superblock(struct super_block *sb,
f2fs_msg(sb, KERN_ERR, "Can't find a valid F2FS filesystem " f2fs_msg(sb, KERN_ERR, "Can't find a valid F2FS filesystem "
"in %s superblock", super); "in %s superblock", super);
return 1; return -EINVAL;
} }
static int f2fs_fill_super(struct super_block *sb, void *data, int silent) static int f2fs_fill_super(struct super_block *sb, void *data, int silent)
...@@ -508,9 +533,12 @@ static int f2fs_fill_super(struct super_block *sb, void *data, int silent) ...@@ -508,9 +533,12 @@ static int f2fs_fill_super(struct super_block *sb, void *data, int silent)
goto free_sbi; goto free_sbi;
} }
if (validate_superblock(sb, &raw_super, &raw_super_buf, 0)) { err = validate_superblock(sb, &raw_super, &raw_super_buf, 0);
if (err) {
brelse(raw_super_buf); brelse(raw_super_buf);
if (validate_superblock(sb, &raw_super, &raw_super_buf, 1)) /* check secondary superblock when primary failed */
err = validate_superblock(sb, &raw_super, &raw_super_buf, 1);
if (err)
goto free_sb_buf; goto free_sb_buf;
} }
/* init some FS parameters */ /* init some FS parameters */
...@@ -525,7 +553,8 @@ static int f2fs_fill_super(struct super_block *sb, void *data, int silent) ...@@ -525,7 +553,8 @@ static int f2fs_fill_super(struct super_block *sb, void *data, int silent)
set_opt(sbi, POSIX_ACL); set_opt(sbi, POSIX_ACL);
#endif #endif
/* parse mount options */ /* parse mount options */
if (parse_options(sb, sbi, (char *)data)) err = parse_options(sb, sbi, (char *)data);
if (err)
goto free_sb_buf; goto free_sb_buf;
sb->s_maxbytes = max_file_size(le32_to_cpu(raw_super->log_blocksize)); sb->s_maxbytes = max_file_size(le32_to_cpu(raw_super->log_blocksize));
...@@ -547,11 +576,11 @@ static int f2fs_fill_super(struct super_block *sb, void *data, int silent) ...@@ -547,11 +576,11 @@ static int f2fs_fill_super(struct super_block *sb, void *data, int silent)
sbi->raw_super = raw_super; sbi->raw_super = raw_super;
sbi->raw_super_buf = raw_super_buf; sbi->raw_super_buf = raw_super_buf;
mutex_init(&sbi->gc_mutex); mutex_init(&sbi->gc_mutex);
mutex_init(&sbi->write_inode);
mutex_init(&sbi->writepages); mutex_init(&sbi->writepages);
mutex_init(&sbi->cp_mutex); mutex_init(&sbi->cp_mutex);
for (i = 0; i < NR_LOCK_TYPE; i++) for (i = 0; i < NR_GLOBAL_LOCKS; i++)
mutex_init(&sbi->fs_lock[i]); mutex_init(&sbi->fs_lock[i]);
mutex_init(&sbi->node_write);
sbi->por_doing = 0; sbi->por_doing = 0;
spin_lock_init(&sbi->stat_lock); spin_lock_init(&sbi->stat_lock);
init_rwsem(&sbi->bio_sem); init_rwsem(&sbi->bio_sem);
...@@ -638,8 +667,12 @@ static int f2fs_fill_super(struct super_block *sb, void *data, int silent) ...@@ -638,8 +667,12 @@ static int f2fs_fill_super(struct super_block *sb, void *data, int silent)
} }
/* recover fsynced data */ /* recover fsynced data */
if (!test_opt(sbi, DISABLE_ROLL_FORWARD)) if (!test_opt(sbi, DISABLE_ROLL_FORWARD)) {
recover_fsync_data(sbi); err = recover_fsync_data(sbi);
if (err)
f2fs_msg(sb, KERN_ERR,
"Cannot recover all fsync data errno=%ld", err);
}
/* After POR, we can run background GC thread */ /* After POR, we can run background GC thread */
err = start_gc_thread(sbi); err = start_gc_thread(sbi);
...@@ -650,6 +683,14 @@ static int f2fs_fill_super(struct super_block *sb, void *data, int silent) ...@@ -650,6 +683,14 @@ static int f2fs_fill_super(struct super_block *sb, void *data, int silent)
if (err) if (err)
goto fail; goto fail;
if (test_opt(sbi, DISCARD)) {
struct request_queue *q = bdev_get_queue(sb->s_bdev);
if (!blk_queue_discard(q))
f2fs_msg(sb, KERN_WARNING,
"mounting with \"discard\" option, but "
"the device does not support discard");
}
return 0; return 0;
fail: fail:
stop_gc_thread(sbi); stop_gc_thread(sbi);
......
...@@ -307,27 +307,30 @@ int f2fs_setxattr(struct inode *inode, int name_index, const char *name, ...@@ -307,27 +307,30 @@ int f2fs_setxattr(struct inode *inode, int name_index, const char *name,
int error, found, free, newsize; int error, found, free, newsize;
size_t name_len; size_t name_len;
char *pval; char *pval;
int ilock;
if (name == NULL) if (name == NULL)
return -EINVAL; return -EINVAL;
name_len = strlen(name);
if (value == NULL) if (value == NULL)
value_len = 0; value_len = 0;
if (name_len > 255 || value_len > MAX_VALUE_LEN) name_len = strlen(name);
if (name_len > F2FS_NAME_LEN || value_len > MAX_VALUE_LEN)
return -ERANGE; return -ERANGE;
f2fs_balance_fs(sbi); f2fs_balance_fs(sbi);
mutex_lock_op(sbi, NODE_NEW); ilock = mutex_lock_op(sbi);
if (!fi->i_xattr_nid) { if (!fi->i_xattr_nid) {
/* Allocate new attribute block */ /* Allocate new attribute block */
struct dnode_of_data dn; struct dnode_of_data dn;
if (!alloc_nid(sbi, &fi->i_xattr_nid)) { if (!alloc_nid(sbi, &fi->i_xattr_nid)) {
mutex_unlock_op(sbi, NODE_NEW); error = -ENOSPC;
return -ENOSPC; goto exit;
} }
set_new_dnode(&dn, inode, NULL, NULL, fi->i_xattr_nid); set_new_dnode(&dn, inode, NULL, NULL, fi->i_xattr_nid);
mark_inode_dirty(inode); mark_inode_dirty(inode);
...@@ -336,8 +339,8 @@ int f2fs_setxattr(struct inode *inode, int name_index, const char *name, ...@@ -336,8 +339,8 @@ int f2fs_setxattr(struct inode *inode, int name_index, const char *name,
if (IS_ERR(page)) { if (IS_ERR(page)) {
alloc_nid_failed(sbi, fi->i_xattr_nid); alloc_nid_failed(sbi, fi->i_xattr_nid);
fi->i_xattr_nid = 0; fi->i_xattr_nid = 0;
mutex_unlock_op(sbi, NODE_NEW); error = PTR_ERR(page);
return PTR_ERR(page); goto exit;
} }
alloc_nid_done(sbi, fi->i_xattr_nid); alloc_nid_done(sbi, fi->i_xattr_nid);
...@@ -349,8 +352,8 @@ int f2fs_setxattr(struct inode *inode, int name_index, const char *name, ...@@ -349,8 +352,8 @@ int f2fs_setxattr(struct inode *inode, int name_index, const char *name,
/* The inode already has an extended attribute block. */ /* The inode already has an extended attribute block. */
page = get_node_page(sbi, fi->i_xattr_nid); page = get_node_page(sbi, fi->i_xattr_nid);
if (IS_ERR(page)) { if (IS_ERR(page)) {
mutex_unlock_op(sbi, NODE_NEW); error = PTR_ERR(page);
return PTR_ERR(page); goto exit;
} }
base_addr = page_address(page); base_addr = page_address(page);
...@@ -432,12 +435,13 @@ int f2fs_setxattr(struct inode *inode, int name_index, const char *name, ...@@ -432,12 +435,13 @@ int f2fs_setxattr(struct inode *inode, int name_index, const char *name,
inode->i_ctime = CURRENT_TIME; inode->i_ctime = CURRENT_TIME;
clear_inode_flag(fi, FI_ACL_MODE); clear_inode_flag(fi, FI_ACL_MODE);
} }
f2fs_write_inode(inode, NULL); update_inode_page(inode);
mutex_unlock_op(sbi, NODE_NEW); mutex_unlock_op(sbi, ilock);
return 0; return 0;
cleanup: cleanup:
f2fs_put_page(page, 1); f2fs_put_page(page, 1);
mutex_unlock_op(sbi, NODE_NEW); exit:
mutex_unlock_op(sbi, ilock);
return error; return error;
} }
...@@ -139,7 +139,7 @@ struct f2fs_extent { ...@@ -139,7 +139,7 @@ struct f2fs_extent {
__le32 len; /* lengh of the extent */ __le32 len; /* lengh of the extent */
} __packed; } __packed;
#define F2FS_MAX_NAME_LEN 256 #define F2FS_NAME_LEN 255
#define ADDRS_PER_INODE 923 /* Address Pointers in an Inode */ #define ADDRS_PER_INODE 923 /* Address Pointers in an Inode */
#define ADDRS_PER_BLOCK 1018 /* Address Pointers in a Direct Block */ #define ADDRS_PER_BLOCK 1018 /* Address Pointers in a Direct Block */
#define NIDS_PER_BLOCK 1018 /* Node IDs in an Indirect Block */ #define NIDS_PER_BLOCK 1018 /* Node IDs in an Indirect Block */
...@@ -165,7 +165,8 @@ struct f2fs_inode { ...@@ -165,7 +165,8 @@ struct f2fs_inode {
__le32 i_flags; /* file attributes */ __le32 i_flags; /* file attributes */
__le32 i_pino; /* parent inode number */ __le32 i_pino; /* parent inode number */
__le32 i_namelen; /* file name length */ __le32 i_namelen; /* file name length */
__u8 i_name[F2FS_MAX_NAME_LEN]; /* file name for SPOR */ __u8 i_name[F2FS_NAME_LEN]; /* file name for SPOR */
__u8 i_reserved2; /* for backward compatibility */
struct f2fs_extent i_ext; /* caching a largest extent */ struct f2fs_extent i_ext; /* caching a largest extent */
...@@ -362,10 +363,10 @@ struct f2fs_summary_block { ...@@ -362,10 +363,10 @@ struct f2fs_summary_block {
typedef __le32 f2fs_hash_t; typedef __le32 f2fs_hash_t;
/* One directory entry slot covers 8bytes-long file name */ /* One directory entry slot covers 8bytes-long file name */
#define F2FS_NAME_LEN 8 #define F2FS_SLOT_LEN 8
#define F2FS_NAME_LEN_BITS 3 #define F2FS_SLOT_LEN_BITS 3
#define GET_DENTRY_SLOTS(x) ((x + F2FS_NAME_LEN - 1) >> F2FS_NAME_LEN_BITS) #define GET_DENTRY_SLOTS(x) ((x + F2FS_SLOT_LEN - 1) >> F2FS_SLOT_LEN_BITS)
/* the number of dentry in a block */ /* the number of dentry in a block */
#define NR_DENTRY_IN_BLOCK 214 #define NR_DENTRY_IN_BLOCK 214
...@@ -377,10 +378,10 @@ typedef __le32 f2fs_hash_t; ...@@ -377,10 +378,10 @@ typedef __le32 f2fs_hash_t;
#define SIZE_OF_DENTRY_BITMAP ((NR_DENTRY_IN_BLOCK + BITS_PER_BYTE - 1) / \ #define SIZE_OF_DENTRY_BITMAP ((NR_DENTRY_IN_BLOCK + BITS_PER_BYTE - 1) / \
BITS_PER_BYTE) BITS_PER_BYTE)
#define SIZE_OF_RESERVED (PAGE_SIZE - ((SIZE_OF_DIR_ENTRY + \ #define SIZE_OF_RESERVED (PAGE_SIZE - ((SIZE_OF_DIR_ENTRY + \
F2FS_NAME_LEN) * \ F2FS_SLOT_LEN) * \
NR_DENTRY_IN_BLOCK + SIZE_OF_DENTRY_BITMAP)) NR_DENTRY_IN_BLOCK + SIZE_OF_DENTRY_BITMAP))
/* One directory entry slot representing F2FS_NAME_LEN-sized file name */ /* One directory entry slot representing F2FS_SLOT_LEN-sized file name */
struct f2fs_dir_entry { struct f2fs_dir_entry {
__le32 hash_code; /* hash code of file name */ __le32 hash_code; /* hash code of file name */
__le32 ino; /* inode number */ __le32 ino; /* inode number */
...@@ -394,7 +395,7 @@ struct f2fs_dentry_block { ...@@ -394,7 +395,7 @@ struct f2fs_dentry_block {
__u8 dentry_bitmap[SIZE_OF_DENTRY_BITMAP]; __u8 dentry_bitmap[SIZE_OF_DENTRY_BITMAP];
__u8 reserved[SIZE_OF_RESERVED]; __u8 reserved[SIZE_OF_RESERVED];
struct f2fs_dir_entry dentry[NR_DENTRY_IN_BLOCK]; struct f2fs_dir_entry dentry[NR_DENTRY_IN_BLOCK];
__u8 filename[NR_DENTRY_IN_BLOCK][F2FS_NAME_LEN]; __u8 filename[NR_DENTRY_IN_BLOCK][F2FS_SLOT_LEN];
} __packed; } __packed;
/* file types used in inode_info->flags */ /* file types used in inode_info->flags */
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment