[f2fs-dev] [PATCH] f2fs: add a modify discard command function
This patch add a function to modify discard command if one segment reuse before discard. Split this segment from multi-segments discard range, and discard the left bigger range. Signed-off-by: Yunlei He--- fs/f2fs/segment.c | 18 +- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c index 9006d8e..5af736b 100644 --- a/fs/f2fs/segment.c +++ b/fs/f2fs/segment.c @@ -672,6 +672,22 @@ static void __remove_discard_cmd(struct f2fs_sb_info *sbi, struct discard_cmd *d kmem_cache_free(discard_cmd_slab, dc); } +static void __modify_discard_cmd(struct f2fs_sb_info *sbi, struct discard_cmd *dc, block_t blkaddr) +{ + block_t end_block = START_BLOCK(sbi, GET_SEGNO(sbi, blkaddr) + 1); + + if (dc->lstart + dc->len <= end_block) { +__remove_discard_cmd(sbi, dc); + return; + } + + if (dc->lstart - blkaddr < dc->lstart + dc->len - end_block) { + dc->lstart = end_block; + dc->len -= (end_block - dc->lstart); + } else + dc->len = blkaddr - dc->lstart; +} + /* This should be covered by global mutex, _i->sentry_lock */ void f2fs_wait_discard_bio(struct f2fs_sb_info *sbi, block_t blkaddr) { @@ -699,7 +715,7 @@ void f2fs_wait_discard_bio(struct f2fs_sb_info *sbi, block_t blkaddr) if (dc->state == D_SUBMIT) wait_for_completion_io(>wait); else - __remove_discard_cmd(sbi, dc); + __modify_discard_cmd(sbi, dc, blkaddr); } } blk_finish_plug(); -- 2.10.1 -- Check out the vibrant tech community on one of the world's most engaging tech sites, SlashDot.org! http://sdm.link/slashdot ___ Linux-f2fs-devel mailing list Linux-f2fs-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Re: [f2fs-dev] [PATCH] f2fs: avoid unnecessary fg_gc
On 2017/2/26 3:39, Jaegeuk Kim wrote: > On 02/25, heyunlei wrote: >> Hi all, >> >> I am really confused by the condition below use sec_freed, is it always >> equal to zero? > > Seems it is always zero. Let's fix it together. > > Pengyang, > > I merged your patches and finally got this. > How do you think? > >>From d1c2206e4f245a8fedec3a8f21ad522b3b1b2d0c Mon Sep 17 00:00:00 2001 > From: Hou Pengyang> Date: Sat, 25 Feb 2017 03:57:38 + > Subject: [PATCH] f2fs: avoid bggc->fggc when enough free segments are > avaliable after cp > > We use has_not_enough_free_secs to check if there are enough free segments, > > (free_sections(sbi) + freed) <= > (node_secs + 2 * dent_secs + imeta_secs + >reserved_sections(sbi) + needed); > > Under scenario with large number of dirty nodes, these nodes would be flushed > during cp, as a result, right side of the inequality would be decreased, while > left side stays unchanged if these nodes are flushed in SSR way, which means > there are enough free segments after this cp. > > For this case, we just do a bggc instead of fggc. > > Signed-off-by: Hou Pengyang > Signed-off-by: Jaegeuk Kim Reviewed-by: Chao Yu Thanks, -- Check out the vibrant tech community on one of the world's most engaging tech sites, SlashDot.org! http://sdm.link/slashdot ___ Linux-f2fs-devel mailing list Linux-f2fs-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Re: [f2fs-dev] [PATCH] f2fs: use MAX_FREE_NIDS for the free nids target
On 2017/2/26 20:47, Kinglong Mee wrote: > F2FS has define MAX_FREE_NIDS for maximum of cached free nids target. > > #define MAX_FREE_NIDS (NAT_ENTRY_PER_BLOCK * FREE_NID_PAGES) > > Signed-off-by: Kinglong MeeAll clean patches looks good to me. To Jaegeuk, please add: Reviewed-by: Chao Yu Thanks, > --- > fs/f2fs/node.c | 8 +++- > 1 file changed, 3 insertions(+), 5 deletions(-) > > diff --git a/fs/f2fs/node.c b/fs/f2fs/node.c > index 6d43095..9284f65 100644 > --- a/fs/f2fs/node.c > +++ b/fs/f2fs/node.c > @@ -1870,7 +1870,6 @@ static void scan_free_nid_bits(struct f2fs_sb_info *sbi) > struct curseg_info *curseg = CURSEG_I(sbi, CURSEG_HOT_DATA); > struct f2fs_journal *journal = curseg->journal; > unsigned int i, idx; > - unsigned int target = FREE_NID_PAGES * NAT_ENTRY_PER_BLOCK; > > down_read(_i->nat_tree_lock); > > @@ -1886,7 +1885,7 @@ static void scan_free_nid_bits(struct f2fs_sb_info *sbi) > nid = i * NAT_ENTRY_PER_BLOCK + idx; > add_free_nid(sbi, nid, true); > > - if (nm_i->nid_cnt[FREE_NID_LIST] >= target) > + if (nm_i->nid_cnt[FREE_NID_LIST] >= MAX_FREE_NIDS) > goto out; > } > } > @@ -1912,7 +1911,6 @@ static int scan_nat_bits(struct f2fs_sb_info *sbi) > struct f2fs_nm_info *nm_i = NM_I(sbi); > struct page *page; > unsigned int i = 0; > - nid_t target = FREE_NID_PAGES * NAT_ENTRY_PER_BLOCK; > nid_t nid; > > if (!enabled_nat_bits(sbi, NULL)) > @@ -1933,7 +1931,7 @@ static int scan_nat_bits(struct f2fs_sb_info *sbi) > add_free_nid(sbi, nid, true); > } > > - if (nm_i->nid_cnt[FREE_NID_LIST] >= target) > + if (nm_i->nid_cnt[FREE_NID_LIST] >= MAX_FREE_NIDS) > goto out; > i++; > goto check_empty; > @@ -1951,7 +1949,7 @@ static int scan_nat_bits(struct f2fs_sb_info *sbi) > scan_nat_page(sbi, page, nid); > f2fs_put_page(page, 1); > > - if (nm_i->nid_cnt[FREE_NID_LIST] < target) { > + if (nm_i->nid_cnt[FREE_NID_LIST] < MAX_FREE_NIDS) { > i++; > goto check_partial; > } > -- Check out the vibrant tech community on one of the world's most engaging tech sites, SlashDot.org! http://sdm.link/slashdot ___ Linux-f2fs-devel mailing list Linux-f2fs-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Re: [f2fs-dev] [PATCH] f2fs: skip checkpoint if having a dirty segment but no prefree at BG_GC -> FG_GC
On 2017/2/26 3:56, Jaegeuk Kim wrote: > On 02/25, guoweichao wrote: >> Hi Jaegeuk, >> >> I regard no enough free sections as a precondition when talking about >> BG_GC -> FG_GC. I mean that for both case a) and b) I mentioned has no enough >> free sections implicitly. >> >> On 2017/2/25 2:49, Jaegeuk Kim wrote: >>> Hi Weichao, >>> >>> On 02/25, Weichao Guo wrote: When turning to FG_GC from BG_GC, we need to write checkpoint in 2 cases: * a) BG_GC have made some progress, e.g.: some prefree segments. * b) There is no victim and no prefree segment. >>> >>> You missed >>> * c) has_not_enough_free_secs() introduced by >>> 6e17bfbc75a5cb ("f2fs: fix to overcome inline_data floods") >> As we have enabled SSR for warm node(5b6c6be2d8 ("f2fs: use SSR for warm >> node as well")), >> I think inline data floods should not be a problem in most cases. >>> >>> And, Yunlong pointed that we can't find a case to avoid write_checkpoint() >>> mostly due to c) condition. >> As inline data floods is an extreme case, and there is little possibility >> caused panic >> for inline data floods now, there should be lots of chance to skip >> checkpoint. I mean >> that we can make some accurate inline data floods checking before writing >> checkpoint. > > For now, the safest way is our first option. So, I decided to start with doing > checkpoint due to previous inline_data flooding issue even though it's an > extreme case under SSR. > > Anyway, I agree that we need to find a way to detect when to avoid checkpoint. Hi all, I proposed a approach before, can you please check that one? https://www.mail-archive.com/linux-f2fs-devel@lists.sourceforge.net/msg03632.html Thanks, > > Thanks, > >>> >>> Thanks, >>> For case a), previously, we also check if there is a dirty segment for infering blocks moving in last BG_GC. But dirty segments do not always indicate that, BG_GC may just start and do not move any blocks at all. Futhermore, skipping checkpoint if there are some dirty segments but no prefree segments is OK. >>> >>> Signed-off-by: Weichao Guo--- fs/f2fs/gc.c | 7 ++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/fs/f2fs/gc.c b/fs/f2fs/gc.c index 6c996e3..30d206a 100644 --- a/fs/f2fs/gc.c +++ b/fs/f2fs/gc.c @@ -958,7 +958,12 @@ int f2fs_gc(struct f2fs_sb_info *sbi, bool sync, bool background) * enough free sections, we should flush dent/node blocks and do * garbage collections. */ - ret = write_checkpoint(sbi, ); + if (prefree_segments(sbi)) + ret = write_checkpoint(sbi, ); + else if (!__get_victim(sbi, , gc_type) { + segno = NULL_SEGNO; + ret = write_checkpoint(sbi, ); + } if (ret) goto stop; } else if (gc_type == BG_GC && !background) { -- 2.10.1 >>> >>> . >>> >> >> Thanks, >> Weichao > > . > -- Check out the vibrant tech community on one of the world's most engaging tech sites, SlashDot.org! http://sdm.link/slashdot ___ Linux-f2fs-devel mailing list Linux-f2fs-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Re: [f2fs-dev] [PATCH 3/3] f2fs: drop calling alloc_nid_failed when no nid is allocated
On 2017/2/27 11:08, Kinglong Mee wrote: > On 2/27/2017 10:21, Chao Yu wrote: >> On 2017/2/25 19:23, Kinglong Mee wrote: >>> If hsize is less than or equal to inlien_size, and i_xattr_nid is valid, >>> the new_nid is not allocated (no alloc_nid is called). >>> >>>if (hsize > inline_size && !F2FS_I(inode)->i_xattr_nid) >>> if (!alloc_nid(sbi, _nid)) >>> return -ENOSPC; >>> >>> Although it's harmless calling alloc_nid_failed, it's better drop them. >>> >>> Signed-off-by: Kinglong Mee>>> --- >>> fs/f2fs/xattr.c | 9 - >>> 1 file changed, 4 insertions(+), 5 deletions(-) >>> >>> diff --git a/fs/f2fs/xattr.c b/fs/f2fs/xattr.c >>> index 7298a44..fd9dc99 100644 >>> --- a/fs/f2fs/xattr.c >>> +++ b/fs/f2fs/xattr.c >>> @@ -428,19 +428,18 @@ static inline int write_all_xattrs(struct inode >>> *inode, __u32 hsize, >>> /* no need to use xattr node block */ >>> if (hsize <= inline_size) { >>> err = truncate_xattr_node(inode, ipage); >>> - alloc_nid_failed(sbi, new_nid); >> >> Should keep this since new_nid was assigned above? > > alloc_nid is called when, > > > 403 if (hsize > inline_size && !F2FS_I(inode)->i_xattr_nid) > 404 if (!alloc_nid(sbi, _nid)) > 405 return -ENOSPC; > > if (hsize <= inline_size), alloc_nid isn't called. You're right, I can confirm that. :) Thanks, > > thanks, > Kinglong Mee >> >>> + f2fs_bug_on(sbi, new_nid); >>> return err; >>> } >>> } >>> >>> /* write to xattr node block */ >>> if (F2FS_I(inode)->i_xattr_nid) { >>> + f2fs_bug_on(sbi, new_nid); >>> xpage = get_node_page(sbi, F2FS_I(inode)->i_xattr_nid); >>> - if (IS_ERR(xpage)) { >>> - alloc_nid_failed(sbi, new_nid); >>> + if (IS_ERR(xpage)) >>> return PTR_ERR(xpage); >>> - } >>> - f2fs_bug_on(sbi, new_nid); >> >> Cleanup here looks good to me. >> >> Thanks, >> >>> + >>> f2fs_wait_on_page_writeback(xpage, NODE, true); >>> } else { >>> struct dnode_of_data dn; >>> >> >> > > . > -- Check out the vibrant tech community on one of the world's most engaging tech sites, SlashDot.org! http://sdm.link/slashdot ___ Linux-f2fs-devel mailing list Linux-f2fs-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Re: [f2fs-dev] [PATCH V2] f2fs: introduce free nid bitmap
On 2017/2/26 3:02, Jaegeuk Kim wrote: > On 02/25, Chao Yu wrote: >> Hi Jaegeuk, >> >> I added below diff code into this patch in order to fix incorrectly nid >> status >> updating to reduce large latency of generic/251 in fstest, could you help to >> review code below? > > Understand the problem, and how about this? > > diff --git a/fs/f2fs/node.c b/fs/f2fs/node.c > index 52db02396878..83b305689913 100644 > --- a/fs/f2fs/node.c > +++ b/fs/f2fs/node.c > @@ -1765,7 +1765,7 @@ static void __remove_nid_from_list(struct f2fs_sb_info > *sbi, > radix_tree_delete(_i->free_nid_root, i->nid); > } > > -static int add_free_nid(struct f2fs_sb_info *sbi, nid_t nid, bool build) > +static bool add_free_nid(struct f2fs_sb_info *sbi, nid_t nid, bool build) > { > struct f2fs_nm_info *nm_i = NM_I(sbi); > struct free_nid *i; > @@ -1774,14 +1774,14 @@ static int add_free_nid(struct f2fs_sb_info *sbi, > nid_t nid, bool build) > > /* 0 nid should not be used */ > if (unlikely(nid == 0)) > - return 0; > + return false; > > if (build) { > /* do not add allocated nids */ > ne = __lookup_nat_cache(nm_i, nid); > if (ne && (!get_nat_flag(ne, IS_CHECKPOINTED) || > nat_get_blkaddr(ne) != NULL_ADDR)) > - return 0; > + return false; > } > > i = f2fs_kmem_cache_alloc(free_nid_slab, GFP_NOFS); > @@ -1790,7 +1790,7 @@ static int add_free_nid(struct f2fs_sb_info *sbi, nid_t > nid, bool build) > > if (radix_tree_preload(GFP_NOFS)) { > kmem_cache_free(free_nid_slab, i); > - return 0; > + return false; If there is no memory, actually current free nid is still available, we need to return true (or other value -1?), then caller can set free_nid_bitmap correctly. > } > > spin_lock(_i->nid_list_lock); > @@ -1799,9 +1799,9 @@ static int add_free_nid(struct f2fs_sb_info *sbi, nid_t > nid, bool build) > radix_tree_preload_end(); > if (err) { > kmem_cache_free(free_nid_slab, i); > - return 0; > + return false; ditto. Thanks, > } > - return 1; > + return true; > } > > static void remove_free_nid(struct f2fs_sb_info *sbi, nid_t nid) > @@ -1851,6 +1851,7 @@ static void scan_nat_page(struct f2fs_sb_info *sbi, > i = start_nid % NAT_ENTRY_PER_BLOCK; > > for (; i < NAT_ENTRY_PER_BLOCK; i++, start_nid++) { > + bool freed = false; > > if (unlikely(start_nid >= nm_i->max_nid)) > break; > @@ -1858,8 +1859,8 @@ static void scan_nat_page(struct f2fs_sb_info *sbi, > blk_addr = le32_to_cpu(nat_blk->entries[i].block_addr); > f2fs_bug_on(sbi, blk_addr == NEW_ADDR); > if (blk_addr == NULL_ADDR) > - add_free_nid(sbi, start_nid, true); > - update_free_nid_bitmap(sbi, start_nid, blk_addr == NULL_ADDR); > + freed = add_free_nid(sbi, start_nid, true); > + update_free_nid_bitmap(sbi, start_nid, freed); > } > } > > -- Check out the vibrant tech community on one of the world's most engaging tech sites, SlashDot.org! http://sdm.link/slashdot ___ Linux-f2fs-devel mailing list Linux-f2fs-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Re: [f2fs-dev] [PATCH 3/3] f2fs: drop calling alloc_nid_failed when no nid is allocated
On 2/27/2017 10:21, Chao Yu wrote: > On 2017/2/25 19:23, Kinglong Mee wrote: >> If hsize is less than or equal to inlien_size, and i_xattr_nid is valid, >> the new_nid is not allocated (no alloc_nid is called). >> >>if (hsize > inline_size && !F2FS_I(inode)->i_xattr_nid) >> if (!alloc_nid(sbi, _nid)) >> return -ENOSPC; >> >> Although it's harmless calling alloc_nid_failed, it's better drop them. >> >> Signed-off-by: Kinglong Mee>> --- >> fs/f2fs/xattr.c | 9 - >> 1 file changed, 4 insertions(+), 5 deletions(-) >> >> diff --git a/fs/f2fs/xattr.c b/fs/f2fs/xattr.c >> index 7298a44..fd9dc99 100644 >> --- a/fs/f2fs/xattr.c >> +++ b/fs/f2fs/xattr.c >> @@ -428,19 +428,18 @@ static inline int write_all_xattrs(struct inode >> *inode, __u32 hsize, >> /* no need to use xattr node block */ >> if (hsize <= inline_size) { >> err = truncate_xattr_node(inode, ipage); >> -alloc_nid_failed(sbi, new_nid); > > Should keep this since new_nid was assigned above? alloc_nid is called when, 403 if (hsize > inline_size && !F2FS_I(inode)->i_xattr_nid) 404 if (!alloc_nid(sbi, _nid)) 405 return -ENOSPC; if (hsize <= inline_size), alloc_nid isn't called. thanks, Kinglong Mee > >> +f2fs_bug_on(sbi, new_nid); >> return err; >> } >> } >> >> /* write to xattr node block */ >> if (F2FS_I(inode)->i_xattr_nid) { >> +f2fs_bug_on(sbi, new_nid); >> xpage = get_node_page(sbi, F2FS_I(inode)->i_xattr_nid); >> -if (IS_ERR(xpage)) { >> -alloc_nid_failed(sbi, new_nid); >> +if (IS_ERR(xpage)) >> return PTR_ERR(xpage); >> -} >> -f2fs_bug_on(sbi, new_nid); > > Cleanup here looks good to me. > > Thanks, > >> + >> f2fs_wait_on_page_writeback(xpage, NODE, true); >> } else { >> struct dnode_of_data dn; >> > > -- Check out the vibrant tech community on one of the world's most engaging tech sites, SlashDot.org! http://sdm.link/slashdot ___ Linux-f2fs-devel mailing list Linux-f2fs-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Re: [f2fs-dev] [PATCH] f2fs: avoid unnecessary fg_gc
Hi Jaegeuk, On 2017/2/27 9:59, Hou Pengyang wrote: > We use has_not_enough_free_secs to check if there are enough free segments, > > (free_sections(sbi) + freed) <= > (node_secs + 2 * dent_secs + imeta_secs + > reserved_sections(sbi) + needed); Now node SSR is enable, how can we change this condition simply as: (free_sections(sbi) + freed) <= reserved_sections(sbi) If dirty node pages can find SSR segment, write it in SSR mode, or it will consume free segments, and then we do FG_GC. Another thing is that each process has a chance to do FG_GC, it's no problem for all normal processes, but may be not a good thing for a process within certain limits such as lower priority, with bound cpu to do FG_GC. Maybe it will block system for a long time. So what can we do to improve this? Thanks. -- Check out the vibrant tech community on one of the world's most engaging tech sites, SlashDot.org! http://sdm.link/slashdot ___ Linux-f2fs-devel mailing list Linux-f2fs-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Re: [f2fs-dev] [PATCH 3/3] f2fs: drop calling alloc_nid_failed when no nid is allocated
On 2017/2/25 19:23, Kinglong Mee wrote: > If hsize is less than or equal to inlien_size, and i_xattr_nid is valid, > the new_nid is not allocated (no alloc_nid is called). > >if (hsize > inline_size && !F2FS_I(inode)->i_xattr_nid) > if (!alloc_nid(sbi, _nid)) > return -ENOSPC; > > Although it's harmless calling alloc_nid_failed, it's better drop them. > > Signed-off-by: Kinglong Mee> --- > fs/f2fs/xattr.c | 9 - > 1 file changed, 4 insertions(+), 5 deletions(-) > > diff --git a/fs/f2fs/xattr.c b/fs/f2fs/xattr.c > index 7298a44..fd9dc99 100644 > --- a/fs/f2fs/xattr.c > +++ b/fs/f2fs/xattr.c > @@ -428,19 +428,18 @@ static inline int write_all_xattrs(struct inode *inode, > __u32 hsize, > /* no need to use xattr node block */ > if (hsize <= inline_size) { > err = truncate_xattr_node(inode, ipage); > - alloc_nid_failed(sbi, new_nid); Should keep this since new_nid was assigned above? > + f2fs_bug_on(sbi, new_nid); > return err; > } > } > > /* write to xattr node block */ > if (F2FS_I(inode)->i_xattr_nid) { > + f2fs_bug_on(sbi, new_nid); > xpage = get_node_page(sbi, F2FS_I(inode)->i_xattr_nid); > - if (IS_ERR(xpage)) { > - alloc_nid_failed(sbi, new_nid); > + if (IS_ERR(xpage)) > return PTR_ERR(xpage); > - } > - f2fs_bug_on(sbi, new_nid); Cleanup here looks good to me. Thanks, > + > f2fs_wait_on_page_writeback(xpage, NODE, true); > } else { > struct dnode_of_data dn; > -- Check out the vibrant tech community on one of the world's most engaging tech sites, SlashDot.org! http://sdm.link/slashdot ___ Linux-f2fs-devel mailing list Linux-f2fs-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Re: [f2fs-dev] [PATCH 1/4] f2fs: avoid very large discard command
On 2017/2/23 12:28, Jaegeuk Kim wrote: > This patch adds MAX_DISCARD_BLOCKS() to avoid issuing too much large single > discard command. > > Signed-off-by: Jaegeuk KimThis patch set looks good to me, please add reviewed-by into all patches. :) Reviewed-by: Chao Yu -- Check out the vibrant tech community on one of the world's most engaging tech sites, SlashDot.org! http://sdm.link/slashdot ___ Linux-f2fs-devel mailing list Linux-f2fs-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
[f2fs-dev] [PATCH] mkfs.f2fs: check filesystem overwrite before formatting
Mkfs.f2fs doesn't check the overwrite of exist filesystem. Avoid formatting an exist filesystem by mistake, a notice is important. The code is modified from xfsprogs. Signed-off-by: Kinglong Mee--- configure.ac| 20 +-- mkfs/Makefile.am| 4 +-- mkfs/f2fs_format_main.c | 89 - 3 files changed, 108 insertions(+), 5 deletions(-) diff --git a/configure.ac b/configure.ac index 6a3f7c4..d6de43b 100644 --- a/configure.ac +++ b/configure.ac @@ -48,8 +48,11 @@ AC_CHECK_HEADERS_ONCE([ # Test configure options. AC_ARG_WITH([selinux], AS_HELP_STRING([--without-selinux], - [Ignore presence of libselinux and disable selinux support]) -) + [Ignore presence of libselinux and disable selinux support])) + +AC_ARG_WITH([blkid], + AS_HELP_STRING([--without-blkid], + [Ignore presence of libblkid and disable blkid support])) # Checks for programs. AC_PROG_CC @@ -74,6 +77,19 @@ AS_IF([test "x$have_selinux" = "xyes"], )] ) +AS_IF([test "x$with_blkid" != "xno"], + [PKG_CHECK_MODULES([libblkid], [blkid], + [have_blkid=yes], [have_blkid=no])], + [have_blkid=no] +) + +AS_IF([test "x$have_blkid" = "xyes"], + [AC_DEFINE([HAVE_LIBBLKID], [1], [Use blkid])], + [AS_IF([test "x$with_blkid" = "xyes"], + [AC_MSG_ERROR([blkid support requested but libblkid not found])] + )] +) + # Checks for header files. AC_CHECK_HEADERS([linux/fs.h linux/blkzoned.h fcntl.h mntent.h stdlib.h string.h \ sys/ioctl.h sys/mount.h unistd.h linux/falloc.h byteswap.h]) diff --git a/mkfs/Makefile.am b/mkfs/Makefile.am index 8b4c16c..162a0cf 100644 --- a/mkfs/Makefile.am +++ b/mkfs/Makefile.am @@ -1,10 +1,10 @@ ## Makefile.am -AM_CPPFLAGS = ${libuuid_CFLAGS} -I$(top_srcdir)/include +AM_CPPFLAGS = ${libuuid_CFLAGS} ${libblkid_CFLAGS} -I$(top_srcdir)/include AM_CFLAGS = -Wall -DWITH_BLKDISCARD sbin_PROGRAMS = mkfs.f2fs mkfs_f2fs_SOURCES = f2fs_format_main.c f2fs_format.c f2fs_format_utils.c f2fs_format_utils.h $(top_srcdir)/include/f2fs_fs.h -mkfs_f2fs_LDADD = ${libuuid_LIBS} $(top_builddir)/lib/libf2fs.la +mkfs_f2fs_LDADD = ${libuuid_LIBS} ${libblkid_LIBS} $(top_builddir)/lib/libf2fs.la lib_LTLIBRARIES = libf2fs_format.la libf2fs_format_la_SOURCES = f2fs_format_main.c f2fs_format.c f2fs_format_utils.c diff --git a/mkfs/f2fs_format_main.c b/mkfs/f2fs_format_main.c index 5bb1faf..b26256d 100644 --- a/mkfs/f2fs_format_main.c +++ b/mkfs/f2fs_format_main.c @@ -18,10 +18,16 @@ #include #include +#include "config.h" +#ifdef HAVE_LIBBLKID +# include +#endif + #include "f2fs_fs.h" #include "f2fs_format_utils.h" extern struct f2fs_configuration c; +static int force_overwrite = 0; static void mkfs_usage() { @@ -72,7 +78,7 @@ static void parse_feature(const char *features) static void f2fs_parse_options(int argc, char *argv[]) { - static const char *option_string = "qa:c:d:e:l:mo:O:s:z:t:"; + static const char *option_string = "qa:c:d:e:l:mo:O:s:z:t:f"; int32_t option=0; while ((option = getopt(argc,argv,option_string)) != EOF) { @@ -128,6 +134,9 @@ static void f2fs_parse_options(int argc, char *argv[]) case 't': c.trim = atoi(optarg); break; + case 'f': + force_overwrite = 1; + break; default: MSG(0, "\tError: Unknown option %c\n",option); mkfs_usage(); @@ -155,6 +164,79 @@ static void f2fs_parse_options(int argc, char *argv[]) c.feature |= cpu_to_le32(F2FS_FEATURE_BLKZONED); } +#ifdef HAVE_LIBBLKID +static int f2fs_dev_is_overwrite(const char *device) +{ + const char *type; + blkid_probe pr = NULL; + int ret = -1; + + if (!device || !*device) + return 0; + + pr = blkid_new_probe_from_filename(device); + if (!pr) + goto out; + + ret = blkid_probe_enable_partitions(pr, 1); + if (ret < 0) + goto out; + + ret = blkid_do_fullprobe(pr); + if (ret < 0) + goto out; + + /* +* Blkid returns 1 for nothing found and 0 when it finds a signature, +* but we want the exact opposite, so reverse the return value here. +* +* In addition print some useful diagnostics about what actually is +* on the device. +*/ + if (ret) { + ret = 0; + goto out; + } + + if (!blkid_probe_lookup_value(pr, "TYPE", , NULL)) { + MSG(0, "\t%s appears to contain an existing filesystem (%s).\n", + device, type); + } else if (!blkid_probe_lookup_value(pr, "PTTYPE", , NULL)) { + MSG(0, "\t%s appears to contain a partition table
[f2fs-dev] [PATCH] f2fs: use MAX_FREE_NIDS for the free nids target
F2FS has define MAX_FREE_NIDS for maximum of cached free nids target. #define MAX_FREE_NIDS (NAT_ENTRY_PER_BLOCK * FREE_NID_PAGES) Signed-off-by: Kinglong Mee--- fs/f2fs/node.c | 8 +++- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/fs/f2fs/node.c b/fs/f2fs/node.c index 6d43095..9284f65 100644 --- a/fs/f2fs/node.c +++ b/fs/f2fs/node.c @@ -1870,7 +1870,6 @@ static void scan_free_nid_bits(struct f2fs_sb_info *sbi) struct curseg_info *curseg = CURSEG_I(sbi, CURSEG_HOT_DATA); struct f2fs_journal *journal = curseg->journal; unsigned int i, idx; - unsigned int target = FREE_NID_PAGES * NAT_ENTRY_PER_BLOCK; down_read(_i->nat_tree_lock); @@ -1886,7 +1885,7 @@ static void scan_free_nid_bits(struct f2fs_sb_info *sbi) nid = i * NAT_ENTRY_PER_BLOCK + idx; add_free_nid(sbi, nid, true); - if (nm_i->nid_cnt[FREE_NID_LIST] >= target) + if (nm_i->nid_cnt[FREE_NID_LIST] >= MAX_FREE_NIDS) goto out; } } @@ -1912,7 +1911,6 @@ static int scan_nat_bits(struct f2fs_sb_info *sbi) struct f2fs_nm_info *nm_i = NM_I(sbi); struct page *page; unsigned int i = 0; - nid_t target = FREE_NID_PAGES * NAT_ENTRY_PER_BLOCK; nid_t nid; if (!enabled_nat_bits(sbi, NULL)) @@ -1933,7 +1931,7 @@ static int scan_nat_bits(struct f2fs_sb_info *sbi) add_free_nid(sbi, nid, true); } - if (nm_i->nid_cnt[FREE_NID_LIST] >= target) + if (nm_i->nid_cnt[FREE_NID_LIST] >= MAX_FREE_NIDS) goto out; i++; goto check_empty; @@ -1951,7 +1949,7 @@ static int scan_nat_bits(struct f2fs_sb_info *sbi) scan_nat_page(sbi, page, nid); f2fs_put_page(page, 1); - if (nm_i->nid_cnt[FREE_NID_LIST] < target) { + if (nm_i->nid_cnt[FREE_NID_LIST] < MAX_FREE_NIDS) { i++; goto check_partial; } -- 2.9.3 -- Check out the vibrant tech community on one of the world's most engaging tech sites, SlashDot.org! http://sdm.link/slashdot ___ Linux-f2fs-devel mailing list Linux-f2fs-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel