[f2fs-dev] [PATCH] f2fs-tools: get kernel version via uname(2)

2018-05-01 Thread Jaegeuk Kim
This patch introduces uname(2) to get kernel version.

Signed-off-by: Jaegeuk Kim 
---
 fsck/mount.c   |  2 +-
 include/f2fs_fs.h  |  1 +
 lib/libf2fs.c  | 14 ++
 mkfs/f2fs_format.c |  2 +-
 4 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/fsck/mount.c b/fsck/mount.c
index e4ca0b8..61ea0ea 100644
--- a/fsck/mount.c
+++ b/fsck/mount.c
@@ -625,7 +625,7 @@ int validate_super_block(struct f2fs_sb_info *sbi, int 
block)
dev_read_version(c.version, 0, VERSION_LEN);
get_kernel_version(c.version);
} else {
-   memset(c.version, 0, VERSION_LEN);
+   get_kernel_uname_version(c.version);
}
 
/* build sb version */
diff --git a/include/f2fs_fs.h b/include/f2fs_fs.h
index 8ed9db1..e84 100644
--- a/include/f2fs_fs.h
+++ b/include/f2fs_fs.h
@@ -1118,6 +1118,7 @@ extern int dev_reada_block(__u64);
 
 extern int dev_read_version(void *, __u64, size_t);
 extern void get_kernel_version(__u8 *);
+extern void get_kernel_uname_version(__u8 *);
 f2fs_hash_t f2fs_dentry_hash(const unsigned char *, int);
 
 static inline bool f2fs_has_extra_isize(struct f2fs_inode *inode)
diff --git a/lib/libf2fs.c b/lib/libf2fs.c
index 19491b6..9410732 100644
--- a/lib/libf2fs.c
+++ b/lib/libf2fs.c
@@ -27,6 +27,7 @@
 #ifdef HAVE_SYS_SYSMACROS_H
 #include 
 #endif
+#include 
 #ifndef WITH_ANDROID
 #ifdef HAVE_SCSI_SG_H
 #include 
@@ -740,6 +741,17 @@ void get_kernel_version(__u8 *version)
memset(version + i, 0, VERSION_LEN + 1 - i);
 }
 
+void get_kernel_uname_version(__u8 *version)
+{
+   struct utsname buf;
+
+   memset(version, 0, VERSION_LEN);
+   if (uname(&buf))
+   return;
+
+   snprintf((char *)version,
+   VERSION_LEN, "%s %s", buf.release, buf.version);
+}
 
 #if defined(__linux__) && defined(_IO) && !defined(BLKGETSIZE)
 #define BLKGETSIZE _IO(0x12,96)
@@ -796,7 +808,9 @@ int get_device_info(int i)
}
 
if (c.kd == -1) {
+#if !defined(WITH_ANDROID) && defined(__linux__)
c.kd = open("/proc/version", O_RDONLY);
+#endif
if (c.kd < 0) {
MSG(0, "\tInfo: No support kernel version!\n");
c.kd = -2;
diff --git a/mkfs/f2fs_format.c b/mkfs/f2fs_format.c
index 0fc8b30..09886b4 100644
--- a/mkfs/f2fs_format.c
+++ b/mkfs/f2fs_format.c
@@ -442,7 +442,7 @@ static int f2fs_prepare_super_block(void)
get_kernel_version(c.version);
MSG(0, "Info: format version with\n  \"%s\"\n", c.version);
} else {
-   memset(c.version, 0, VERSION_LEN);
+   get_kernel_uname_version(c.version);
}
 
memcpy(sb->version, c.version, VERSION_LEN);
-- 
2.17.0.484.g0c8726318c-goog


--
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-tools: get kernel version via uname(2)

2018-05-01 Thread Jaegeuk Kim
Change log from v1:
 - fix build error by checking sys/utsname.h

This patch introduces uname(2) to get kernel version.

Signed-off-by: Jaegeuk Kim 
---
 configure.ac   |  1 +
 fsck/mount.c   |  2 +-
 include/f2fs_fs.h  |  1 +
 lib/libf2fs.c  | 20 
 mkfs/f2fs_format.c |  2 +-
 5 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/configure.ac b/configure.ac
index 64c156e..a3ff12b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -102,6 +102,7 @@ AC_CHECK_HEADERS(m4_flatten([
sys/syscall.h
sys/mount.h
sys/sysmacros.h
+   sys/utsname.h
sys/xattr.h
unistd.h
 ]))
diff --git a/fsck/mount.c b/fsck/mount.c
index e4ca0b8..61ea0ea 100644
--- a/fsck/mount.c
+++ b/fsck/mount.c
@@ -625,7 +625,7 @@ int validate_super_block(struct f2fs_sb_info *sbi, int 
block)
dev_read_version(c.version, 0, VERSION_LEN);
get_kernel_version(c.version);
} else {
-   memset(c.version, 0, VERSION_LEN);
+   get_kernel_uname_version(c.version);
}
 
/* build sb version */
diff --git a/include/f2fs_fs.h b/include/f2fs_fs.h
index 8ed9db1..e84 100644
--- a/include/f2fs_fs.h
+++ b/include/f2fs_fs.h
@@ -1118,6 +1118,7 @@ extern int dev_reada_block(__u64);
 
 extern int dev_read_version(void *, __u64, size_t);
 extern void get_kernel_version(__u8 *);
+extern void get_kernel_uname_version(__u8 *);
 f2fs_hash_t f2fs_dentry_hash(const unsigned char *, int);
 
 static inline bool f2fs_has_extra_isize(struct f2fs_inode *inode)
diff --git a/lib/libf2fs.c b/lib/libf2fs.c
index 19491b6..5ef0214 100644
--- a/lib/libf2fs.c
+++ b/lib/libf2fs.c
@@ -27,6 +27,9 @@
 #ifdef HAVE_SYS_SYSMACROS_H
 #include 
 #endif
+#ifdef HAVE_SYS_UTSNAME_H
+#include 
+#endif
 #ifndef WITH_ANDROID
 #ifdef HAVE_SCSI_SG_H
 #include 
@@ -740,6 +743,21 @@ void get_kernel_version(__u8 *version)
memset(version + i, 0, VERSION_LEN + 1 - i);
 }
 
+void get_kernel_uname_version(__u8 *version)
+{
+#ifdef HAVE_SYS_UTSNAME_H
+   struct utsname buf;
+
+   memset(version, 0, VERSION_LEN);
+   if (uname(&buf))
+   return;
+
+   snprintf((char *)version,
+   VERSION_LEN, "%s %s", buf.release, buf.version);
+#else
+   memset(version, 0, VERSION_LEN);
+#endif
+}
 
 #if defined(__linux__) && defined(_IO) && !defined(BLKGETSIZE)
 #define BLKGETSIZE _IO(0x12,96)
@@ -796,7 +814,9 @@ int get_device_info(int i)
}
 
if (c.kd == -1) {
+#if !defined(WITH_ANDROID) && defined(__linux__)
c.kd = open("/proc/version", O_RDONLY);
+#endif
if (c.kd < 0) {
MSG(0, "\tInfo: No support kernel version!\n");
c.kd = -2;
diff --git a/mkfs/f2fs_format.c b/mkfs/f2fs_format.c
index 0fc8b30..09886b4 100644
--- a/mkfs/f2fs_format.c
+++ b/mkfs/f2fs_format.c
@@ -442,7 +442,7 @@ static int f2fs_prepare_super_block(void)
get_kernel_version(c.version);
MSG(0, "Info: format version with\n  \"%s\"\n", c.version);
} else {
-   memset(c.version, 0, VERSION_LEN);
+   get_kernel_uname_version(c.version);
}
 
memcpy(sb->version, c.version, VERSION_LEN);
-- 
2.17.0.484.g0c8726318c-goog


--
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: avoid stucking GC due to atomic write

2018-05-01 Thread Chao Yu
On 2018/4/28 10:34, Jaegeuk Kim wrote:
> On 04/27, Chao Yu wrote:
>> On 2018/4/26 23:54, Jaegeuk Kim wrote:
>>> On 04/24, Chao Yu wrote:
 f2fs doesn't allow abuse on atomic write class interface, so except
 limiting in-mem pages' total memory usage capacity, we need to limit
 atomic-write usage as well when filesystem is seriously fragmented,
 otherwise we may run into infinite loop during foreground GC because
 target blocks in victim segment are belong to atomic opened file for
 long time.
>>>
>>> How about using fi->i_gc_failure likewise pin_file?
>>
>> OK, how about changing it to array fi->i_gc_failure[MAX_GC_FAILURE], and 
>> change
>> the type to unsigned long long to avoid overflow?
> 
> It'd be enough to share i_gc_failure between the types, IMO.

IMO, for atomic case, we don't need to persist the count into on-disk
i_gc_failure, as we only care about in-mem value instead of on-disk one.
Another concern is that if both functionalities are used, we can not decide to
drop atomic written data due to the failure value which may be only increased by
a pinned file.

Thanks,

> 
>>
>> enum {
>>  GC_FAILURE_PIN,
>>  GC_FAILURE_ATOMIC,
>>  MAX_GC_FAILURE
>> }
>>
>> Thanks,
>>
>>>

 Now, we will detect failure due to atomic write in foreground GC, if
 the count exceeds threshold, we will drop all atomic written data in
 cache, by this, I expect it can keep our system running safely to
 prevent Dos attack.

 In addition, his patch adds to show GC skip information in debugfs,
 now it just shows count of skipped caused by atomic write.

 Signed-off-by: Chao Yu 
 ---
 v2:
 - add to show skip info in debugfs.
  fs/f2fs/debug.c   |  8 
  fs/f2fs/f2fs.h|  2 ++
  fs/f2fs/file.c|  5 +
  fs/f2fs/gc.c  | 29 +
  fs/f2fs/gc.h  |  3 +++
  fs/f2fs/segment.c |  1 +
  fs/f2fs/segment.h |  2 ++
  7 files changed, 46 insertions(+), 4 deletions(-)

 diff --git a/fs/f2fs/debug.c b/fs/f2fs/debug.c
 index 0fbd674c66fb..607b258a9b61 100644
 --- a/fs/f2fs/debug.c
 +++ b/fs/f2fs/debug.c
 @@ -104,6 +104,10 @@ static void update_general_status(struct f2fs_sb_info 
 *sbi)
si->avail_nids = NM_I(sbi)->available_nids;
si->alloc_nids = NM_I(sbi)->nid_cnt[PREALLOC_NID];
si->bg_gc = sbi->bg_gc;
 +  si->skipped_atomic_files[BG_GC] =
 +  sbi->gc_thread->skipped_atomic_files[BG_GC];
 +  si->skipped_atomic_files[FG_GC] =
 +  sbi->gc_thread->skipped_atomic_files[FG_GC];
si->util_free = (int)(free_user_blocks(sbi) >> sbi->log_blocks_per_seg)
* 100 / (int)(sbi->user_block_count >> sbi->log_blocks_per_seg)
/ 2;
 @@ -341,6 +345,10 @@ static int stat_show(struct seq_file *s, void *v)
si->bg_data_blks);
seq_printf(s, "  - node blocks : %d (%d)\n", si->node_blks,
si->bg_node_blks);
 +  seq_printf(s, "Skipped : atomic write %llu (%llu)\n",
 +  si->skipped_atomic_files[BG_GC] +
 +  si->skipped_atomic_files[FG_GC],
 +  si->skipped_atomic_files[BG_GC]);
seq_puts(s, "\nExtent Cache:\n");
seq_printf(s, "  - Hit Count: L1-1:%llu L1-2:%llu L2:%llu\n",
si->hit_largest, si->hit_cached,
 diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
 index 75d3b4875429..c2b92cb377c6 100644
 --- a/fs/f2fs/f2fs.h
 +++ b/fs/f2fs/f2fs.h
 @@ -2254,6 +2254,7 @@ enum {
FI_EXTRA_ATTR,  /* indicate file has extra attribute */
FI_PROJ_INHERIT,/* indicate file inherits projectid */
FI_PIN_FILE,/* indicate file should not be gced */
 +  FI_ATOMIC_REVOKE_REQUEST,/* indicate atomic committed data has been 
 dropped */
  };
  
  static inline void __mark_inode_dirty_flag(struct inode *inode,
 @@ -3010,6 +3011,7 @@ struct f2fs_stat_info {
int bg_node_segs, bg_data_segs;
int tot_blks, data_blks, node_blks;
int bg_data_blks, bg_node_blks;
 +  unsigned long long skipped_atomic_files[2];
int curseg[NR_CURSEG_TYPE];
int cursec[NR_CURSEG_TYPE];
int curzone[NR_CURSEG_TYPE];
 diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
 index a352804af244..0cfa65c21d3f 100644
 --- a/fs/f2fs/file.c
 +++ b/fs/f2fs/file.c
 @@ -1702,6 +1702,7 @@ static int f2fs_ioc_start_atomic_write(struct file 
 *filp)
  skip_flush:
set_inode_flag(inode, FI_HOT_DATA);
set_inode_flag(inode, FI_ATOMIC_FILE);
 +  clear_inode_flag(inode, FI_ATOMIC_REVOKE_REQUEST);
f2fs_update_time(F2FS_I_SB(inode), REQ_TIME);
  
F2FS_I(inode)->inmem_task = current;
 @@ -1750,6 +1751,10 @@ static

Re: [f2fs-dev] [RFC PATCH] f2fs-tools: introduce tune.f2fs

2018-05-01 Thread Chao Yu
On 2018/4/28 10:49, Jaegeuk Kim wrote:
> On 04/27, Chao Yu wrote:
>> On 2018/4/27 0:13, Jaegeuk Kim wrote:
>>> On 04/26, Junling Zheng wrote:
 Ping...

 On 2018/4/23 15:32, Junling Zheng wrote:
> Introduce tune.f2fs tool to change the f2fs parameters.
> Currently this tool only supports adding or removing encrypt
> feature bit in superblock.
>>>
>>> What is the purpose of this empty tune.f2fs? How can we say we have this
>>> tool to users? You have to design what kind of things to support first.
>>
>> I checked very initial tune2fs.c, it only supports very few parameters tuning
>> functionality, but, can not say that is a bad start to introduce the misc 
>> tool.
>>
>> +   fprintf (stderr, "Usage: %s [-c max-mounts-count] [-e 
>> errors-behavior] "
>> +"[-i interval[d|m]]\n"
>> +"\t[-l] [-m reserved-blocks-percent] device\n", 
>> program_name);
> 
> I don't think We have to follow that.
> 
>>
>> Maybe tuning 1. extension list, 2. multi device name later? just guess.
> 
> First of all, does it make sense to unset feature bits? I don't think so.

Some features can be turned off in a initial image? like encrypted, extra_attr,
checksum...?

> 
> Agreed to your suggestion where:
> 1. feature set
>   - enable system quota
> 2. extension list
> 3. multi device name -- which may be really big trial

So what's our plan now? fill those features into fsck when we need them?

Thanks,

> 
>>
>> Using fsck.f2fs to tune parameter, IMO, maybe a little confuse for user to
>> understand the tool's functionality.
>>
>> 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