Re: [f2fs-dev] [PATCH] f2fs: copy all valid xattr data includes the last zero

2017-03-22 Thread Kinglong Mee
On 3/22/2017 18:16, Chao Yu wrote:
> On 2017/3/22 16:42, Chao Yu wrote:
>> On 2017/3/22 0:18, Jaegeuk Kim wrote:
>>> On 03/20, Kinglong Mee wrote:
>>>> On 3/20/2017 11:08, Jaegeuk Kim wrote:
>>>>> Hi Kinglong,
>>>>>
>>>>> On 03/18, Kinglong Mee wrote:
>>>>>> It's better coping all valid xattr data includes the last zero. 
>>>>>
>>>>> Why do we need this?
>>>>>
>>>>> The size of txattr_addr would be larger than the space we need.
>>>>>
>>>>> Thanks,
>>>>>
>>>>>>
>>>>>> Signed-off-by: Kinglong Mee <kinglong...@gmail.com>
>>>>>> ---
>>>>>>  fs/f2fs/xattr.c | 4 ++--
>>>>>>  fs/f2fs/xattr.h | 4 ++--
>>>>>>  2 files changed, 4 insertions(+), 4 deletions(-)
>>>>>>
>>>>>> diff --git a/fs/f2fs/xattr.c b/fs/f2fs/xattr.c
>>>>>> index aff7619..41785c9 100644
>>>>>> --- a/fs/f2fs/xattr.c
>>>>>> +++ b/fs/f2fs/xattr.c
>>>>>> @@ -249,7 +249,7 @@ static int lookup_all_xattrs(struct inode *inode, 
>>>>>> struct page *ipage,
>>>>>>  struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
>>>>>>  void *cur_addr, *txattr_addr, *last_addr = NULL;
>>>>>>  nid_t xnid = F2FS_I(inode)->i_xattr_nid;
>>>>>> -unsigned int size = xnid ? VALID_XATTR_BLOCK_SIZE : 0;
>>>>
>>>> Here maybe does not copy the last zero.
>>>
>>> The below kzalloc() will make it zero. Any problem?
>>
>> There is no problem without this change, but anyway, IMO, it needs to do 
>> cleanup
>> as it can provider better readability making allocated size and copied size 
>> be
>> consistent among lookup_all_xattrs, read_all_xattrs and write_all_xattrs.
>>
>> And since during allocation we have initialize memory with zero, so I prefer 
>> to
>> not copy extra reserved xattr space.
>>
>> Jaegeuk, Kinglong, how about changing like below:
>>
>> ---
>>  fs/f2fs/xattr.c | 27 ---
>>  fs/f2fs/xattr.h |  3 ++-
>>  2 files changed, 14 insertions(+), 16 deletions(-)
>>
>> diff --git a/fs/f2fs/xattr.c b/fs/f2fs/xattr.c
>> index aff7619e3f96..308b06664068 100644
>> --- a/fs/f2fs/xattr.c
>> +++ b/fs/f2fs/xattr.c
>> @@ -250,15 +250,13 @@ static int lookup_all_xattrs(struct inode *inode, 
>> struct
>> page *ipage,
>>  void *cur_addr, *txattr_addr, *last_addr = NULL;
>>  nid_t xnid = F2FS_I(inode)->i_xattr_nid;
>>  unsigned int size = xnid ? VALID_XATTR_BLOCK_SIZE : 0;
>> -unsigned int inline_size = 0;
>> +unsigned int inline_size = inline_xattr_size(inode);
>>  int err = 0;
>>
>> -inline_size = inline_xattr_size(inode);
>> -
>>  if (!size && !inline_size)
>>  return -ENODATA;
>>
>> -txattr_addr = kzalloc(inline_size + size + sizeof(__u32),
>> +txattr_addr = kzalloc(inline_size + size + RESERVED_XATTR_SIZE,
>>  GFP_F2FS_ZERO);
>>  if (!txattr_addr)
>>  return -ENOMEM;
>> @@ -328,13 +326,14 @@ static int read_all_xattrs(struct inode *inode, struct
>> page *ipage,
>>  {
>>  struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
>>  struct f2fs_xattr_header *header;
>> -size_t size = PAGE_SIZE, inline_size = 0;
>> +nid_t xnid = F2FS_I(inode)->i_xattr_nid;
>> +unsigned int size = xnid ? VALID_XATTR_BLOCK_SIZE : 0;
> 
> Here, always should assign size with VALID_XATTR_BLOCK_SIZE for enospc case in
> inline xattr space while adding new xattr entry.
> 
> unsigned int size = VALID_XATTR_BLOCK_SIZE;

It's better that mine.

Reviewed-by: Kinglong Mee <kinglong...@gmail.com>

Thanks,
Kinglong Mee

> 
> Thanks,
> 
>> +unsigned int inline_size = inline_xattr_size(inode);
>>  void *txattr_addr;
>>  int err;
>>
>> -inline_size = inline_xattr_size(inode);
>> -
>> -txattr_addr = kzalloc(inline_size + size, GFP_F2FS_ZERO);
>> +txattr_addr = kzalloc(inline_size + size + RESERVED_XATTR_SIZE,
>> +GFP_F2FS_ZERO);
>>  if (!txattr_addr)
>>  return -ENOMEM;
>>
>> @@ -358,19 +357,19 @@ static int read_all_xattrs(struct inode *inode, struct
>> page *ipage,
>>   

Re: [f2fs-dev] [PATCH] f2fs: copy all valid xattr data includes the last zero

2017-03-20 Thread Kinglong Mee
On 3/20/2017 11:08, Jaegeuk Kim wrote:
> Hi Kinglong,
> 
> On 03/18, Kinglong Mee wrote:
>> It's better coping all valid xattr data includes the last zero. 
> 
> Why do we need this?
> 
> The size of txattr_addr would be larger than the space we need.
> 
> Thanks,
> 
>>
>> Signed-off-by: Kinglong Mee <kinglong...@gmail.com>
>> ---
>>  fs/f2fs/xattr.c | 4 ++--
>>  fs/f2fs/xattr.h | 4 ++--
>>  2 files changed, 4 insertions(+), 4 deletions(-)
>>
>> diff --git a/fs/f2fs/xattr.c b/fs/f2fs/xattr.c
>> index aff7619..41785c9 100644
>> --- a/fs/f2fs/xattr.c
>> +++ b/fs/f2fs/xattr.c
>> @@ -249,7 +249,7 @@ static int lookup_all_xattrs(struct inode *inode, struct 
>> page *ipage,
>>  struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
>>  void *cur_addr, *txattr_addr, *last_addr = NULL;
>>  nid_t xnid = F2FS_I(inode)->i_xattr_nid;
>> -unsigned int size = xnid ? VALID_XATTR_BLOCK_SIZE : 0;

Here maybe does not copy the last zero.

>> +unsigned int size = xnid ? MAX_XATTR_BLOCK_SIZE : 0;
>>  unsigned int inline_size = 0;
>>  int err = 0;
>>  
>> @@ -328,7 +328,7 @@ static int read_all_xattrs(struct inode *inode, struct 
>> page *ipage,
>>  {
>>  struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
>>  struct f2fs_xattr_header *header;
>> -size_t size = PAGE_SIZE, inline_size = 0;

Yes, it's larger.
It's for consistent with the above.

thanks,
Kinglong Mee

>> +size_t size = MAX_XATTR_BLOCK_SIZE, inline_size = 0;
>>  void *txattr_addr;
>>  int err;
>>  
>> diff --git a/fs/f2fs/xattr.h b/fs/f2fs/xattr.h
>> index d5a9492..629c8ae 100644
>> --- a/fs/f2fs/xattr.h
>> +++ b/fs/f2fs/xattr.h
>> @@ -73,9 +73,9 @@ struct f2fs_xattr_entry {
>>  !IS_XATTR_LAST_ENTRY(entry);\
>>  entry = XATTR_NEXT_ENTRY(entry))
>>  #define MAX_XATTR_BLOCK_SIZE(PAGE_SIZE - sizeof(struct node_footer))
>> -#define VALID_XATTR_BLOCK_SIZE  (MAX_XATTR_BLOCK_SIZE - sizeof(__u32))
>> +/* A __u32 is reserved for the last entry as zero */
>>  #define MIN_OFFSET(i)   XATTR_ALIGN(inline_xattr_size(i) +  
>> \
>> -VALID_XATTR_BLOCK_SIZE)
>> +MAX_XATTR_BLOCK_SIZE - sizeof(__u32))
>>  
>>  #define MAX_VALUE_LEN(i)(MIN_OFFSET(i) -\
>>  sizeof(struct f2fs_xattr_header) -  \
>> -- 
>> 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


[f2fs-dev] [PATCH] libf2fs: avoid overwrite the c.start_sector by non-root device

2017-03-18 Thread Kinglong Mee
For multiple devices, the c.start_sector will be overwrite by the non-root 
devices.

Signed-off-by: Kinglong Mee <kinglong...@gmail.com>
---
 lib/libf2fs.c | 10 ++
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/lib/libf2fs.c b/lib/libf2fs.c
index 93d3da9..bb32df8 100644
--- a/lib/libf2fs.c
+++ b/lib/libf2fs.c
@@ -730,10 +730,12 @@ int get_device_info(int i)
 #endif
dev->total_sectors /= dev->sector_size;
 
-   if (ioctl(fd, HDIO_GETGEO, ) < 0)
-   c.start_sector = 0;
-   else
-   c.start_sector = geom.start;
+   if (i == 0) {
+   if (ioctl(fd, HDIO_GETGEO, ) < 0)
+   c.start_sector = 0;
+   else
+   c.start_sector = geom.start;
+   }
 
 #ifndef WITH_ANDROID
/* Send INQUIRY command */
-- 
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


Re: [f2fs-dev] About the superblock and checkpoint

2017-03-18 Thread Kinglong Mee
Please ignore the warning messages, maybe there are some wrong steps when 
testing.
So sorry!

On 3/18/2017 14:49, Kinglong Mee wrote:
> When I make a filesystem on a disk partition (eg. /dev/sdd1), 
> but I mount the filesystem from /dev/sdd by mistake,
> f2fs print the following WARNING. I don't think user want them.
> 
> I have no idea to avoid or fix it?
> Should f2fs check both super block? or both checkpoint? 
> 
> Any comments are welcome.
> 
> [12456.030051] F2FS-fs (sdd): Magic Mismatch, valid(0xf2f52010) - read(0x0)
> [12456.031270] F2FS-fs (sdd): Can't find valid F2FS filesystem in 1th 
> superblock
> [12456.046173] F2FS-fs (sdd): Mount Device [ 0]: /dev/sdd, 
> 1023,0 -7
> [12456.047112] F2FS-fs (sdd): Mount Device [ 1]: /dev/sde, 
> 1024,8 -f
> [12456.048012] F2FS-fs (sdd): Mount Device [ 2]: /dev/sdf, 
> 1024,   10 -   17
> [12456.048856] F2FS-fs (sdd): IO Block Size:4 KB
> [12456.084157] F2FS-fs (sdd): Found nat_bits in checkpoint
> [12456.138799] [ cut here ]
> [12456.139303] WARNING: CPU: 0 PID: 8146 at fs/f2fs/node.c:1162 
> __get_node_page.part.34+0x1e9/0x330 [f2fs]
> [12456.140313] Modules linked in: f2fs(E) tun bridge stp llc fuse ip_set 
> nfnetlink vmw_vsock_vmci_transport vsock snd_seq_midi snd_seq_midi_event 
> snd_ens1371 gameport coretemp ppdev snd_ac97_codec crct10dif_pclmul ac97_bus 
> crc32_pclmul snd_seq ghash_clmulni_intel intel_rapl_perf snd_pcm vmw_balloon 
> joydev snd_rawmidi snd_timer snd_seq_device snd soundcore nfit parport_pc 
> parport acpi_cpufreq tpm_tis tpm_tis_core shpchp tpm i2c_piix4 vmw_vmci nfsd 
> auth_rpcgss nfs_acl lockd grace sunrpc xfs libcrc32c vmwgfx drm_kms_helper 
> ttm drm crc32c_intel serio_raw e1000 mptspi scsi_transport_spi mptscsih 
> mptbase ata_generic fjes pata_acpi
> [12456.144180] CPU: 0 PID: 8146 Comm: mount Tainted: GW   E   
> 4.10.0-f2fs+ #25
> [12456.144733] Hardware name: VMware, Inc. VMware Virtual Platform/440BX 
> Desktop Reference Platform, BIOS 6.00 07/02/2015
> [12456.145835] Call Trace:
> [12456.146391]  dump_stack+0x63/0x86
> [12456.146929]  __warn+0xcb/0xf0
> [12456.147466]  warn_slowpath_null+0x1d/0x20
> [12456.148013]  __get_node_page.part.34+0x1e9/0x330 [f2fs]
> [12456.148573]  get_node_page.part.35+0x12/0x20 [f2fs]
> [12456.149121]  get_node_page+0x1b/0x20 [f2fs]
> [12456.149677]  f2fs_iget+0x8f/0x7f0 [f2fs]
> [12456.150210]  f2fs_fill_super+0xb27/0x17c0 [f2fs]
> [12456.150744]  ? vsnprintf+0x274/0x500
> [12456.151255]  mount_bdev+0x178/0x1b0
> [12456.151770]  ? f2fs_commit_super+0xf0/0xf0 [f2fs]
> [12456.152267]  f2fs_mount+0x15/0x20 [f2fs]
> [12456.152780]  mount_fs+0x38/0x150
> [12456.153257]  ? __alloc_percpu+0x15/0x20
> [12456.153749]  vfs_kern_mount+0x67/0x130
> [12456.154223]  do_mount+0x1dd/0xc50
> [12456.154701]  ? _copy_from_user+0x4e/0x80
> [12456.155167]  ? memdup_user+0x4f/0x70
> [12456.155633]  SyS_mount+0x83/0xd0
> [12456.156139]  entry_SYSCALL_64_fastpath+0x1a/0xa9
> [12456.156617] RIP: 0033:0x7f01d30856fa
> [12456.157088] RSP: 002b:7ffc63bcf718 EFLAGS: 0246 ORIG_RAX: 
> 00a5
> [12456.157576] RAX: ffda RBX: 55e03b143050 RCX: 
> 7f01d30856fa
> [12456.158055] RDX: 55e03b146730 RSI: 55e03b145f40 RDI: 
> 55e03b143230
> [12456.158535] RBP: 55e03b146050 R08:  R09: 
> 0013
> [12456.158993] R10: c0ed8000 R11: 0246 R12: 
> 55e03b145f80
> [12456.159449] R13:  R14: 7f01d3bf4a2e R15: 
> 
> [12456.159910] ---[ end trace cac510ee4c757c87 ]---
> [12456.160699] F2FS-fs (sdd): Failed to read root inode
> [12456.164960] F2FS-fs (sdd): Magic Mismatch, valid(0xf2f52010) - read(0x0)
> [12456.165389] F2FS-fs (sdd): Can't find valid F2FS filesystem in 1th 
> superblock
> [12456.167452] F2FS-fs (sdd): Mount Device [ 0]: /dev/sdd, 
> 1023,0 -7
> [12456.167855] F2FS-fs (sdd): Mount Device [ 1]: /dev/sde, 
> 1024,8 -f
> [12456.168238] F2FS-fs (sdd): Mount Device [ 2]: /dev/sdf, 
> 1024,   10 -   17
> [12456.168625] F2FS-fs (sdd): IO Block Size:4 KB
> [12456.178226] F2FS-fs (sdd): Found nat_bits in checkpoint
> [12456.193698] [ cut here ]
> [12456.194057] WARNING: CPU: 0 PID: 8146 at fs/f2fs/node.c:1162 
> __get_node_page.part.34+0x1e9/0x330 [f2fs]
> [12456.194758] Modules linked in: f2fs(E) tun bridge stp llc fuse ip_set 
> nfnetlink vmw_vsock_vmci_transport vsock snd_seq_midi snd_seq_midi_event 
> snd_ens1371 gameport coretemp ppdev snd_ac97_codec crct10dif_pclmul ac97_bus 
>

[f2fs-dev] About the superblock and checkpoint

2017-03-18 Thread Kinglong Mee
When I make a filesystem on a disk partition (eg. /dev/sdd1), 
but I mount the filesystem from /dev/sdd by mistake,
f2fs print the following WARNING. I don't think user want them.

I have no idea to avoid or fix it?
Should f2fs check both super block? or both checkpoint? 

Any comments are welcome.

[12456.030051] F2FS-fs (sdd): Magic Mismatch, valid(0xf2f52010) - read(0x0)
[12456.031270] F2FS-fs (sdd): Can't find valid F2FS filesystem in 1th superblock
[12456.046173] F2FS-fs (sdd): Mount Device [ 0]: /dev/sdd, 
1023,0 -7
[12456.047112] F2FS-fs (sdd): Mount Device [ 1]: /dev/sde, 
1024,8 -f
[12456.048012] F2FS-fs (sdd): Mount Device [ 2]: /dev/sdf, 
1024,   10 -   17
[12456.048856] F2FS-fs (sdd): IO Block Size:4 KB
[12456.084157] F2FS-fs (sdd): Found nat_bits in checkpoint
[12456.138799] [ cut here ]
[12456.139303] WARNING: CPU: 0 PID: 8146 at fs/f2fs/node.c:1162 
__get_node_page.part.34+0x1e9/0x330 [f2fs]
[12456.140313] Modules linked in: f2fs(E) tun bridge stp llc fuse ip_set 
nfnetlink vmw_vsock_vmci_transport vsock snd_seq_midi snd_seq_midi_event 
snd_ens1371 gameport coretemp ppdev snd_ac97_codec crct10dif_pclmul ac97_bus 
crc32_pclmul snd_seq ghash_clmulni_intel intel_rapl_perf snd_pcm vmw_balloon 
joydev snd_rawmidi snd_timer snd_seq_device snd soundcore nfit parport_pc 
parport acpi_cpufreq tpm_tis tpm_tis_core shpchp tpm i2c_piix4 vmw_vmci nfsd 
auth_rpcgss nfs_acl lockd grace sunrpc xfs libcrc32c vmwgfx drm_kms_helper ttm 
drm crc32c_intel serio_raw e1000 mptspi scsi_transport_spi mptscsih mptbase 
ata_generic fjes pata_acpi
[12456.144180] CPU: 0 PID: 8146 Comm: mount Tainted: GW   E   
4.10.0-f2fs+ #25
[12456.144733] Hardware name: VMware, Inc. VMware Virtual Platform/440BX 
Desktop Reference Platform, BIOS 6.00 07/02/2015
[12456.145835] Call Trace:
[12456.146391]  dump_stack+0x63/0x86
[12456.146929]  __warn+0xcb/0xf0
[12456.147466]  warn_slowpath_null+0x1d/0x20
[12456.148013]  __get_node_page.part.34+0x1e9/0x330 [f2fs]
[12456.148573]  get_node_page.part.35+0x12/0x20 [f2fs]
[12456.149121]  get_node_page+0x1b/0x20 [f2fs]
[12456.149677]  f2fs_iget+0x8f/0x7f0 [f2fs]
[12456.150210]  f2fs_fill_super+0xb27/0x17c0 [f2fs]
[12456.150744]  ? vsnprintf+0x274/0x500
[12456.151255]  mount_bdev+0x178/0x1b0
[12456.151770]  ? f2fs_commit_super+0xf0/0xf0 [f2fs]
[12456.152267]  f2fs_mount+0x15/0x20 [f2fs]
[12456.152780]  mount_fs+0x38/0x150
[12456.153257]  ? __alloc_percpu+0x15/0x20
[12456.153749]  vfs_kern_mount+0x67/0x130
[12456.154223]  do_mount+0x1dd/0xc50
[12456.154701]  ? _copy_from_user+0x4e/0x80
[12456.155167]  ? memdup_user+0x4f/0x70
[12456.155633]  SyS_mount+0x83/0xd0
[12456.156139]  entry_SYSCALL_64_fastpath+0x1a/0xa9
[12456.156617] RIP: 0033:0x7f01d30856fa
[12456.157088] RSP: 002b:7ffc63bcf718 EFLAGS: 0246 ORIG_RAX: 
00a5
[12456.157576] RAX: ffda RBX: 55e03b143050 RCX: 7f01d30856fa
[12456.158055] RDX: 55e03b146730 RSI: 55e03b145f40 RDI: 55e03b143230
[12456.158535] RBP: 55e03b146050 R08:  R09: 0013
[12456.158993] R10: c0ed8000 R11: 0246 R12: 55e03b145f80
[12456.159449] R13:  R14: 7f01d3bf4a2e R15: 
[12456.159910] ---[ end trace cac510ee4c757c87 ]---
[12456.160699] F2FS-fs (sdd): Failed to read root inode
[12456.164960] F2FS-fs (sdd): Magic Mismatch, valid(0xf2f52010) - read(0x0)
[12456.165389] F2FS-fs (sdd): Can't find valid F2FS filesystem in 1th superblock
[12456.167452] F2FS-fs (sdd): Mount Device [ 0]: /dev/sdd, 
1023,0 -7
[12456.167855] F2FS-fs (sdd): Mount Device [ 1]: /dev/sde, 
1024,8 -f
[12456.168238] F2FS-fs (sdd): Mount Device [ 2]: /dev/sdf, 
1024,   10 -   17
[12456.168625] F2FS-fs (sdd): IO Block Size:4 KB
[12456.178226] F2FS-fs (sdd): Found nat_bits in checkpoint
[12456.193698] [ cut here ]
[12456.194057] WARNING: CPU: 0 PID: 8146 at fs/f2fs/node.c:1162 
__get_node_page.part.34+0x1e9/0x330 [f2fs]
[12456.194758] Modules linked in: f2fs(E) tun bridge stp llc fuse ip_set 
nfnetlink vmw_vsock_vmci_transport vsock snd_seq_midi snd_seq_midi_event 
snd_ens1371 gameport coretemp ppdev snd_ac97_codec crct10dif_pclmul ac97_bus 
crc32_pclmul snd_seq ghash_clmulni_intel intel_rapl_perf snd_pcm vmw_balloon 
joydev snd_rawmidi snd_timer snd_seq_device snd soundcore nfit parport_pc 
parport acpi_cpufreq tpm_tis tpm_tis_core shpchp tpm i2c_piix4 vmw_vmci nfsd 
auth_rpcgss nfs_acl lockd grace sunrpc xfs libcrc32c vmwgfx drm_kms_helper ttm 
drm crc32c_intel serio_raw e1000 mptspi scsi_transport_spi mptscsih mptbase 
ata_generic fjes pata_acpi
[12456.197471] CPU: 0 PID: 8146 Comm: mount Tainted: GW   E   
4.10.0-f2fs+ #25
[12456.197863] Hardware name: VMware, Inc. VMware Virtual Platform/440BX 
Desktop Reference 

[f2fs-dev] [PATCH] f2fs: calculate the f2fs_stat_info into base_mem

2017-03-17 Thread Kinglong Mee
The memory size of f2fs_stat_info also should be calculated.

Signed-off-by: Kinglong Mee <kinglong...@gmail.com>
---
 fs/f2fs/debug.c | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/fs/f2fs/debug.c b/fs/f2fs/debug.c
index ee2d0a4..cf102d1 100644
--- a/fs/f2fs/debug.c
+++ b/fs/f2fs/debug.c
@@ -156,7 +156,11 @@ static void update_mem_info(struct f2fs_sb_info *sbi)
if (si->base_mem)
goto get_cache;
 
-   si->base_mem = sizeof(struct f2fs_sb_info) + sbi->sb->s_blocksize;
+   /* build stat */
+   si->base_mem = sizeof(struct f2fs_stat_info);
+
+   /* build superb lock*/
+   si->base_mem += sizeof(struct f2fs_sb_info) + sbi->sb->s_blocksize;
si->base_mem += 2 * sizeof(struct f2fs_inode_info);
si->base_mem += sizeof(*sbi->ckpt);
si->base_mem += sizeof(struct percpu_counter) * NR_COUNT_TYPE;
-- 
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


[f2fs-dev] [PATCH] f2fs: copy all valid xattr data includes the last zero

2017-03-17 Thread Kinglong Mee
It's better coping all valid xattr data includes the last zero. 

Signed-off-by: Kinglong Mee <kinglong...@gmail.com>
---
 fs/f2fs/xattr.c | 4 ++--
 fs/f2fs/xattr.h | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/fs/f2fs/xattr.c b/fs/f2fs/xattr.c
index aff7619..41785c9 100644
--- a/fs/f2fs/xattr.c
+++ b/fs/f2fs/xattr.c
@@ -249,7 +249,7 @@ static int lookup_all_xattrs(struct inode *inode, struct 
page *ipage,
struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
void *cur_addr, *txattr_addr, *last_addr = NULL;
nid_t xnid = F2FS_I(inode)->i_xattr_nid;
-   unsigned int size = xnid ? VALID_XATTR_BLOCK_SIZE : 0;
+   unsigned int size = xnid ? MAX_XATTR_BLOCK_SIZE : 0;
unsigned int inline_size = 0;
int err = 0;
 
@@ -328,7 +328,7 @@ static int read_all_xattrs(struct inode *inode, struct page 
*ipage,
 {
struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
struct f2fs_xattr_header *header;
-   size_t size = PAGE_SIZE, inline_size = 0;
+   size_t size = MAX_XATTR_BLOCK_SIZE, inline_size = 0;
void *txattr_addr;
int err;
 
diff --git a/fs/f2fs/xattr.h b/fs/f2fs/xattr.h
index d5a9492..629c8ae 100644
--- a/fs/f2fs/xattr.h
+++ b/fs/f2fs/xattr.h
@@ -73,9 +73,9 @@ struct f2fs_xattr_entry {
!IS_XATTR_LAST_ENTRY(entry);\
entry = XATTR_NEXT_ENTRY(entry))
 #define MAX_XATTR_BLOCK_SIZE   (PAGE_SIZE - sizeof(struct node_footer))
-#define VALID_XATTR_BLOCK_SIZE (MAX_XATTR_BLOCK_SIZE - sizeof(__u32))
+/* A __u32 is reserved for the last entry as zero */
 #define MIN_OFFSET(i)  XATTR_ALIGN(inline_xattr_size(i) +  \
-   VALID_XATTR_BLOCK_SIZE)
+   MAX_XATTR_BLOCK_SIZE - sizeof(__u32))
 
 #define MAX_VALUE_LEN(i)   (MIN_OFFSET(i) -\
sizeof(struct f2fs_xattr_header) -  \
-- 
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


[f2fs-dev] [PATCH] f2fs: avoid stat_inc_atomic_write for non-atomic file

2017-03-17 Thread Kinglong Mee
After filemap_write_and_wait_range fail, the FI_ATOMIC_FILE flags is removed,
so that f2fs should not increase the stat of atomic_write.

Signed-off-by: Kinglong Mee <kinglong...@gmail.com>
---
 fs/f2fs/file.c | 10 +++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
index d486e02..54cfcaa 100644
--- a/fs/f2fs/file.c
+++ b/fs/f2fs/file.c
@@ -1533,17 +1533,21 @@ static int f2fs_ioc_start_atomic_write(struct file 
*filp)
f2fs_update_time(F2FS_I_SB(inode), REQ_TIME);
 
if (!get_dirty_pages(inode))
-   goto out;
+   goto inc_stat;
 
f2fs_msg(F2FS_I_SB(inode)->sb, KERN_WARNING,
"Unexpected flush for atomic writes: ino=%lu, npages=%u",
inode->i_ino, get_dirty_pages(inode));
ret = filemap_write_and_wait_range(inode->i_mapping, 0, LLONG_MAX);
-   if (ret)
+   if (ret) {
clear_inode_flag(inode, FI_ATOMIC_FILE);
-out:
+   goto out;
+   }
+
+inc_stat:
stat_inc_atomic_write(inode);
stat_update_max_atomic_write(inode);
+out:
inode_unlock(inode);
mnt_drop_write_file(filp);
return ret;
-- 
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


[f2fs-dev] [PATCH 1/2] sload.f2fs: let dir_buckets/dir_block_index supports dir_level

2017-03-17 Thread Kinglong Mee
The dir_level in the filesystem maybe larger than zero,
supports it.

Signed-off-by: Kinglong Mee <kinglong...@gmail.com>
---
 fsck/dir.c  | 38 ++
 fsck/f2fs.h | 37 +
 fsck/fsck.c | 27 ---
 3 files changed, 43 insertions(+), 59 deletions(-)

diff --git a/fsck/dir.c b/fsck/dir.c
index d817d27..d684b5d 100644
--- a/fsck/dir.c
+++ b/fsck/dir.c
@@ -16,34 +16,6 @@
 #include "fsck.h"
 #include "node.h"
 
-static unsigned int dir_buckets(unsigned int level)
-{
-   if (level < MAX_DIR_HASH_DEPTH / 2)
-   return 1 << level;
-   else
-   return MAX_DIR_BUCKETS;
-}
-
-static unsigned int bucket_blocks(unsigned int level)
-{
-   if (level < MAX_DIR_HASH_DEPTH / 2)
-   return 2;
-   else
-   return 4;
-}
-
-static unsigned long dir_block_index(unsigned int level,
-   int dir_level, unsigned int idx)
-{
-   unsigned long i;
-   unsigned long bidx = 0;
-
-   for (i = 0; i < level; i++)
-   bidx += dir_buckets(i + dir_level) * bucket_blocks(i);
-   bidx += idx * bucket_blocks(level);
-   return bidx;
-}
-
 static int room_for_filename(const u8 *bitmap, int slots, int max_slots)
 {
int bit_start = 0;
@@ -136,14 +108,15 @@ static int find_in_level(struct f2fs_sb_info *sbi,struct 
f2fs_node *dir,
int max_slots = 214;
nid_t ino = le32_to_cpu(dir->footer.ino);
f2fs_hash_t namehash;
+   unsigned int dir_level = dir->i.i_dir_level;
int ret = 0;
 
namehash = f2fs_dentry_hash(de->name, de->len);
 
-   nbucket = dir_buckets(level);
+   nbucket = dir_buckets(level, dir_level);
nblock = bucket_blocks(level);
 
-   bidx = dir_block_index(level, 0, le32_to_cpu(namehash) % nbucket);
+   bidx = dir_block_index(level, dir_level, le32_to_cpu(namehash) % 
nbucket);
end_block = bidx + nblock;
 
dentry_blk = calloc(BLOCK_SZ, 1);
@@ -237,6 +210,7 @@ static int f2fs_add_link(struct f2fs_sb_info *sbi, struct 
f2fs_node *parent,
nid_t pino = le32_to_cpu(parent->footer.ino);
nid_t ino = le32_to_cpu(child->footer.ino);
umode_t mode = le16_to_cpu(child->i.i_mode);
+   unsigned int dir_level = parent->i.i_dir_level;
int ret;
 
if (parent == NULL || child == NULL)
@@ -262,9 +236,9 @@ start:
if (level == current_depth)
++current_depth;
 
-   nbucket = dir_buckets(level);
+   nbucket = dir_buckets(level, dir_level);
nblock = bucket_blocks(level);
-   bidx = dir_block_index(level, 0, le32_to_cpu(dentry_hash) % nbucket);
+   bidx = dir_block_index(level, dir_level, le32_to_cpu(dentry_hash) % 
nbucket);
 
for (block = bidx; block <= (bidx + nblock - 1); block++) {
 
diff --git a/fsck/f2fs.h b/fsck/f2fs.h
index 5c8eea5..b621912 100644
--- a/fsck/f2fs.h
+++ b/fsck/f2fs.h
@@ -465,4 +465,41 @@ extern int lookup_nat_in_journal(struct f2fs_sb_info *sbi, 
u32 nid, struct f2fs_
 #define IS_SUM_NODE_SEG(footer)(footer.entry_type == 
SUM_TYPE_NODE)
 #define IS_SUM_DATA_SEG(footer)(footer.entry_type == 
SUM_TYPE_DATA)
 
+static inline unsigned int dir_buckets(unsigned int level, int dir_level)
+{
+   if (level + dir_level < MAX_DIR_HASH_DEPTH / 2)
+   return 1 << (level + dir_level);
+   else
+   return MAX_DIR_BUCKETS;
+}
+
+static inline unsigned int bucket_blocks(unsigned int level)
+{
+   if (level < MAX_DIR_HASH_DEPTH / 2)
+   return 2;
+   else
+   return 4;
+}
+
+static inline unsigned long dir_block_index(unsigned int level,
+   int dir_level, unsigned int idx)
+{
+   unsigned long i;
+   unsigned long bidx = 0;
+
+   for (i = 0; i < level; i++)
+   bidx += dir_buckets(i, dir_level) * bucket_blocks(i);
+   bidx += idx * bucket_blocks(level);
+   return bidx;
+}
+
+static inline int is_dot_dotdot(const unsigned char *name, const int len)
+{
+   if (len == 1 && name[0] == '.')
+   return 1;
+   if (len == 2 && name[0] == '.' && name[1] == '.')
+   return 1;
+   return 0;
+}
+
 #endif /* _F2FS_H_ */
diff --git a/fsck/fsck.c b/fsck/fsck.c
index cbd29cc..afd83e5 100644
--- a/fsck/fsck.c
+++ b/fsck/fsck.c
@@ -1084,33 +1084,6 @@ static int f2fs_check_hash_code(struct f2fs_dir_entry 
*dentry,
return 0;
 }
 
-static unsigned int dir_buckets(unsigned int level, int dir_level)
-{
-   if (level + dir_level < MAX_DIR_HASH_DEPTH / 2)
-   return 1 << (level + dir_level);
-   else
-   return MAX_DIR_BUCKETS;
-}
-
-static unsigned int bucket_blocks(unsigned int level)
-{
-   if (level < MAX_DIR_HASH_DEPTH / 2)
-  

[f2fs-dev] [PATCH 2/2] sload.f2fs: support sload files into directory includes inline dentry

2017-03-17 Thread Kinglong Mee
It seems the new created directory always includes inline dentries,
let sload.f2fs supporting it. 

Signed-off-by: Kinglong Mee <kinglong...@gmail.com>
---
 fsck/dir.c  | 139 +---
 fsck/f2fs.h |   4 +-
 2 files changed, 117 insertions(+), 26 deletions(-)

diff --git a/fsck/dir.c b/fsck/dir.c
index d684b5d..57b7f9b 100644
--- a/fsck/dir.c
+++ b/fsck/dir.c
@@ -158,12 +158,6 @@ static int f2fs_find_entry(struct f2fs_sb_info *sbi,
unsigned int max_depth;
unsigned int level;
 
-   if (dir->i.i_inline & F2FS_INLINE_DENTRY) {
-   ERR_MSG("Not support to find \"%s\" in inline_dir pino=%x\n",
-   de->name, de->pino);
-   return 0;
-   }
-
max_depth = le32_to_cpu(dir->i.i_current_depth);
for (level = 0; level < max_depth; level ++) {
if (find_in_level(sbi, dir, level, de))
@@ -172,7 +166,7 @@ static int f2fs_find_entry(struct f2fs_sb_info *sbi,
return 0;
 }
 
-static void f2fs_update_dentry(nid_t ino, umode_t mode,
+static void f2fs_update_dentry(nid_t ino, int file_type,
struct f2fs_dentry_ptr *d,
const unsigned char *name, int len, f2fs_hash_t name_hash,
unsigned int bit_pos)
@@ -187,7 +181,7 @@ static void f2fs_update_dentry(nid_t ino, umode_t mode,
memcpy(d->filename[bit_pos], name, len);
d->filename[bit_pos][len] = 0;
de->ino = cpu_to_le32(ino);
-   set_de_type(de, mode);
+   de->file_type = file_type;
for (i = 0; i < slots; i++)
test_and_set_bit_le(bit_pos + i, d->bitmap);
 }
@@ -196,24 +190,21 @@ static void f2fs_update_dentry(nid_t ino, umode_t mode,
  * f2fs_add_link - Add a new file(dir) to parent dir.
  */
 static int f2fs_add_link(struct f2fs_sb_info *sbi, struct f2fs_node *parent,
-   struct f2fs_node *child, block_t p_blkaddr)
+   const unsigned char *name, int name_len, nid_t ino,
+   int file_type, block_t p_blkaddr, int inc_link)
 {
int level = 0, current_depth, bit_pos;
int nbucket, nblock, bidx, block;
-   const unsigned char *name = child->i.i_name;
-   int name_len = le32_to_cpu(child->i.i_namelen);
int slots = GET_DENTRY_SLOTS(name_len);
f2fs_hash_t dentry_hash = f2fs_dentry_hash(name, name_len);
struct f2fs_dentry_block *dentry_blk;
struct f2fs_dentry_ptr d;
struct dnode_of_data dn = {0};
nid_t pino = le32_to_cpu(parent->footer.ino);
-   nid_t ino = le32_to_cpu(child->footer.ino);
-   umode_t mode = le16_to_cpu(child->i.i_mode);
unsigned int dir_level = parent->i.i_dir_level;
int ret;
 
-   if (parent == NULL || child == NULL)
+   if (parent == NULL)
return -EINVAL;
 
if (!pino) {
@@ -266,7 +257,7 @@ start:
 
 add_dentry:
make_dentry_ptr(, (void *)dentry_blk, 1);
-   f2fs_update_dentry(ino, mode, , name, name_len, dentry_hash, bit_pos);
+   f2fs_update_dentry(ino, file_type, , name, name_len, dentry_hash, 
bit_pos);
 
ret = dev_write_block(dentry_blk, dn.data_blkaddr);
ASSERT(ret >= 0);
@@ -281,7 +272,7 @@ add_dentry:
}
 
/* Update parent's i_links info*/
-   if (S_ISDIR(mode)) {
+   if (inc_link && (file_type == F2FS_FT_DIR)){
u32 links = le32_to_cpu(parent->i.i_links);
parent->i.i_links = cpu_to_le32(links + 1);
dn.idirty = 1;
@@ -445,6 +436,102 @@ static void init_inode_block(struct f2fs_sb_info *sbi,
page_symlink(sbi, node_blk, de->link, size);
 }
 
+int convert_inline_dentry(struct f2fs_sb_info *sbi, struct f2fs_node *node,
+   block_t p_blkaddr)
+{
+   struct f2fs_inode *inode = &(node->i);
+   unsigned int dir_level = node->i.i_dir_level;
+   nid_t ino = le32_to_cpu(node->footer.ino);
+   char inline_data[MAX_INLINE_DATA];
+   struct dnode_of_data dn = {0};
+   struct f2fs_dentry_ptr d;
+   unsigned long bit_pos = 0;
+   int ret = 0;
+
+   if (!(inode->i_inline & F2FS_INLINE_DENTRY))
+   return 0;
+
+   memcpy(inline_data, inline_data_addr(node), MAX_INLINE_DATA);
+   memset(inline_data_addr(node), 0, MAX_INLINE_DATA);
+   inode->i_inline &= ~F2FS_INLINE_DENTRY;
+
+   ret = dev_write_block(node, p_blkaddr);
+   ASSERT(ret >= 0);
+
+   if (!dir_level) {
+   struct f2fs_inline_dentry *inline_dentry;
+   struct f2fs_dentry_block *dentry_blk;
+
+   dentry_blk = calloc(BLOCK_SZ, 1);
+   ASSERT(dentry_blk);
+
+   set_new_dnode(, node, NULL, ino);
+   get_dnode_of_data(sbi, , 0, ALLOC

[f2fs-dev] [PATCH 1/2] fsck.f2fs: fix bad notice of missing device

2017-03-17 Thread Kinglong Mee
The following messages is better than before.

Before,
# fsck.f2fs -d 1
Error: Need argument for -d

Now,
# fsck.f2fs -d 1
Info: Debug level = 1
Error: Device not specified

Signed-off-by: Kinglong Mee <kinglong...@gmail.com>
---
 fsck/main.c | 11 ---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/fsck/main.c b/fsck/main.c
index cf1e8af..88fe5f8 100644
--- a/fsck/main.c
+++ b/fsck/main.c
@@ -114,8 +114,6 @@ void f2fs_parse_options(int argc, char *argv[])
MSG(0, "\tError: Device not specified\n");
error_out(prog);
}
-   c.devices[0].path = strdup(argv[argc - 1]);
-   argv[argc-- - 1] = 0;
 
if (!strcmp("fsck.f2fs", prog)) {
const char *option_string = ":ad:fp:t";
@@ -372,7 +370,14 @@ void f2fs_parse_options(int argc, char *argv[])
break;
}
}
-   if (argc > optind) {
+
+   if (optind >= argc) {
+   MSG(0, "\tError: Device not specified\n");
+   error_out(prog);
+   }
+
+   c.devices[0].path = strdup(argv[optind]);
+   if (argc > (optind + 1)) {
c.dbg_lv = 0;
err = EUNKNOWN_ARG;
}
-- 
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


[f2fs-dev] [PATCH] sload.f2fs: fix missing SSA updates

2017-03-17 Thread Kinglong Mee
If sload many larger files to disk, the SSA that doesn't cached will be missed.

Mar 17 12:04:39 localhost kernel: [ cut here ]
Mar 17 12:04:39 localhost kernel: kernel BUG at fs/f2fs/gc.c:899!
Mar 17 12:04:39 localhost kernel: invalid opcode:  [#1] SMP
Mar 17 12:04:39 localhost kernel: Modules linked in: f2fs tun bridge stp llc 
fuse ip_set nfnetlink vmw_vsock_vmci_transport vsock snd_seq_midi 
snd_seq_midi_event snd_ens1371 gameport snd_ac97_codec coretemp ac97_bus 
crct10dif_pclmul crc32_pclmul ppdev snd_seq snd_pcm ghash_clmulni_intel 
intel_rapl_perf vmw_balloon snd_rawmidi joydev snd_timer snd_seq_device snd 
soundcore parport_pc parport nfit acpi_cpufreq tpm_tis tpm_tis_core shpchp 
vmw_vmci tpm i2c_piix4 nfsd auth_rpcgss nfs_acl lockd grace sunrpc xfs 
libcrc32c vmwgfx drm_kms_helper ttm drm e1000 crc32c_intel mptspi 
scsi_transport_spi serio_raw mptscsih mptbase ata_generic pata_acpi fjes
Mar 17 12:04:39 localhost kernel: CPU: 0 PID: 6427 Comm: f2fs_gc-8:33 Tainted: 
GW   4.10.0-f2fs+ #25
Mar 17 12:04:39 localhost kernel: Hardware name: VMware, Inc. VMware Virtual 
Platform/440BX Desktop Reference Platform, BIOS 6.00 07/02/2015
Mar 17 12:04:39 localhost kernel: task: 94ba7d998000 task.stack: 
b6e4c2e5
Mar 17 12:04:39 localhost kernel: RIP: 0010:do_garbage_collect+0xa39/0xb60 
[f2fs]
Mar 17 12:04:39 localhost kernel: RSP: 0018:b6e4c2e53cc0 EFLAGS: 00010213
Mar 17 12:04:39 localhost kernel: RAX: 94baa0427000 RBX: 0001 
RCX: 0002
Mar 17 12:04:39 localhost kernel: RDX:  RSI: f5e2c28109c0 
RDI: f5e2c28109c0
Mar 17 12:04:39 localhost kernel: RBP: b6e4c2e53dc0 R08: 94ba7dfc72f0 
R09: f5e2c28109dc
Mar 17 12:04:39 localhost kernel: R10: 0040 R11: 94ba7dfc7238 
R12: 0418
Mar 17 12:04:39 localhost kernel: R13: f5e2c28109c0 R14: 0417 
R15: 94ba3c021000
Mar 17 12:04:39 localhost kernel: FS:  () 
GS:94babb60() knlGS:
Mar 17 12:04:39 localhost kernel: CS:  0010 DS:  ES:  CR0: 
80050033
Mar 17 12:04:39 localhost kernel: CR2: 7fc42a0d7000 CR3: a7e94000 
CR4: 001406f0
Mar 17 12:04:39 localhost kernel: Call Trace:
Mar 17 12:04:39 localhost kernel: ? find_next_bit+0xb/0x10
Mar 17 12:04:39 localhost kernel: f2fs_gc+0x111/0x480 [f2fs]
Mar 17 12:04:39 localhost kernel: ? prepare_to_wait_event+0x79/0x160
Mar 17 12:04:39 localhost kernel: gc_thread_func+0x2d0/0x3f0 [f2fs]
Mar 17 12:04:39 localhost kernel: ? __schedule+0x273/0x860
Mar 17 12:04:39 localhost kernel: ? remove_wait_queue+0x70/0x70
Mar 17 12:04:39 localhost kernel: kthread+0x101/0x140
Mar 17 12:04:39 localhost kernel: ? f2fs_gc+0x480/0x480 [f2fs]
Mar 17 12:04:39 localhost kernel: ? kthread_park+0x90/0x90
Mar 17 12:04:39 localhost kernel: ret_from_fork+0x2c/0x40
Mar 17 12:04:39 localhost kernel: Code: 48 8d 84 24 90 00 00 00 48 89 c7 48 89 
44 24 28 e8 7d cc ba e6 e9 17 fa ff ff 48 c7 c6 48 3f 84 c0 48 89 c7 e8 59 8d 
9d e6 0f 0b <0f> 0b 48 c7 c6 48 3f 84 c0 4c 89 ff e8 46 8d 9d e6 0f 0b 8b b4
Mar 17 12:04:39 localhost kernel: RIP: do_garbage_collect+0xa39/0xb60 [f2fs] 
RSP: b6e4c2e53cc0
Mar 17 12:04:39 localhost kernel: ---[ end trace 926d61b064ed1f2d ]---

Fixes: 767a93ea8b ("defrag.f2fs: fix missing SSA updates")
Signed-off-by: Kinglong Mee <kinglong...@gmail.com>
---
 fsck/mount.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fsck/mount.c b/fsck/mount.c
index c54bb95..b19b91a 100644
--- a/fsck/mount.c
+++ b/fsck/mount.c
@@ -1076,7 +1076,7 @@ void update_sum_entry(struct f2fs_sb_info *sbi, block_t 
blk_addr,
SUM_TYPE_DATA;
 
/* write SSA all the time */
-   if (type < SEG_TYPE_MAX) {
+   if (type <= SEG_TYPE_MAX) {
u64 ssa_blk = GET_SUM_BLKADDR(sbi, segno);
ret = dev_write_block(sum_blk, ssa_blk);
ASSERT(ret >= 0);
-- 
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


Re: [f2fs-dev] [PATCH v3] f2fs: cleanup the disk level filename updating

2017-03-17 Thread Kinglong Mee
On 3/17/2017 15:04, Chao Yu wrote:
> On 2017/3/10 16:28, Kinglong Mee wrote:
>> As discuss with Jaegeuk and Chao,
>> "Once checkpoint is done, f2fs doesn't need to update there-in filename at 
>> all."
>>
>> The disk-level filename is used only one case,
>> 1. create a file A under a dir
>> 2. sync A
>> 3. godown
>> 4. umount
>> 5. mount (roll_forward)
>>
>> Only the rename/cross_rename changes the filename, if it happens,
>> a. between step 1 and 2, the sync A will caused checkpoint, so that,
>>the roll_forward at step 5 never happens.
>> b. after step 2, the roll_forward happens, file A will roll forward
>>to the result as after step 1.
>>
>> So that, any updating the disk filename is useless, just cleanup it.
>>
>> Signed-off-by: Kinglong Mee <kinglong...@gmail.com>
>> ---
>>  fs/f2fs/dir.c| 25 -
>>  fs/f2fs/f2fs.h   |  2 --
>>  fs/f2fs/file.c   |  8 
>>  fs/f2fs/inline.c |  2 --
>>  fs/f2fs/namei.c  | 29 -
>>  5 files changed, 4 insertions(+), 62 deletions(-)
>>
>> diff --git a/fs/f2fs/dir.c b/fs/f2fs/dir.c
>> index 8d5c62b..058c4f3 100644
>> --- a/fs/f2fs/dir.c
>> +++ b/fs/f2fs/dir.c
>> @@ -337,24 +337,6 @@ static void init_dent_inode(const struct qstr *name, 
>> struct page *ipage)
>>  set_page_dirty(ipage);
>>  }
>>  
>> -int update_dent_inode(struct inode *inode, struct inode *to,
>> -const struct qstr *name)
>> -{
>> -struct page *page;
>> -
>> -if (file_enc_name(to))
>> -return 0;
>> -
>> -page = get_node_page(F2FS_I_SB(inode), inode->i_ino);
>> -if (IS_ERR(page))
>> -return PTR_ERR(page);
>> -
>> -init_dent_inode(name, page);
>> -f2fs_put_page(page, 1);
>> -
>> -return 0;
>> -}
>> -
>>  void do_make_empty_dir(struct inode *inode, struct inode *parent,
>>  struct f2fs_dentry_ptr *d)
>>  {
>> @@ -438,8 +420,11 @@ struct page *init_inode_metadata(struct inode *inode, 
>> struct inode *dir,
>>  set_cold_node(inode, page);
>>  }
>>  
>> -if (new_name)
>> +if (new_name) {
>>  init_dent_inode(new_name, page);
>> +if (f2fs_encrypted_inode(dir))
>> +file_set_enc_name(inode);
> 
> Please check tmpfile path, we will skip here since new_name will be null, so 
> if
> we do not set enc_name flag in add_link, we will lose the flag for tmpfile 
> which
> will be linked to dents later.

f2fs calls init_inode_metadata() without filename initialize in 
f2fs_do_tmpfile(),
the filename is NULL and without the enc_name flag.

For whiteout, f2fs links it to dents by f2fs_add_link(), and 
init_inode_metadata()
will be called again with the dentry.name, so it's okay.

Any requirements for the normal tmpfile?

thanks,
Kinglong Mee

> 
> Other parts look good to me.
> 
> Thanks,
> 
>> +}
>>  
>>  /*
>>   * This file should be checkpointed during fsync.
>> @@ -599,8 +584,6 @@ int f2fs_add_regular_entry(struct inode *dir, const 
>> struct qstr *new_name,
>>  err = PTR_ERR(page);
>>  goto fail;
>>  }
>> -if (f2fs_encrypted_inode(dir))
>> -file_set_enc_name(inode);
>>  }
>>  
>>  make_dentry_ptr(NULL, , (void *)dentry_blk, 1);
>> diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
>> index 7edb3be..5dbc0c0 100644
>> --- a/fs/f2fs/f2fs.h
>> +++ b/fs/f2fs/f2fs.h
>> @@ -2093,8 +2093,6 @@ ino_t f2fs_inode_by_name(struct inode *dir, const 
>> struct qstr *qstr,
>>  struct page **page);
>>  void f2fs_set_link(struct inode *dir, struct f2fs_dir_entry *de,
>>  struct page *page, struct inode *inode);
>> -int update_dent_inode(struct inode *inode, struct inode *to,
>> -const struct qstr *name);
>>  void f2fs_update_dentry(nid_t ino, umode_t mode, struct f2fs_dentry_ptr *d,
>>  const struct qstr *name, f2fs_hash_t name_hash,
>>  unsigned int bit_pos);
>> diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
>> index 4ec764e..8c7923f 100644
>> --- a/fs/f2fs/file.c
>> +++ b/fs/f2fs/file.c
>> @@ -110,20 +110,12 @@ static int get_parent_ino(struct inode *inode, nid_t 
>> *pino)
>>  {
>>  struct dentry *dentry;
>

[f2fs-dev] [PATCH] fsck.f2fs: a separate option for showing directory tree

2017-03-15 Thread Kinglong Mee
Showing directory tree reuses dbg_lv that if setting "-t", 
fsck.f2fs does not show any others.
Users may want much information include the debug info and directory tree.

Signed-off-by: Kinglong Mee <kinglong...@gmail.com>
---
 fsck/fsck.c   | 2 +-
 fsck/main.c   | 4 ++--
 include/f2fs_fs.h | 1 +
 3 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/fsck/fsck.c b/fsck/fsck.c
index 116eae5..1c23199 100644
--- a/fsck/fsck.c
+++ b/fsck/fsck.c
@@ -1028,7 +1028,7 @@ static void print_dentry(__u32 depth, __u8 *name,
int bit_offset;
unsigned char new[F2FS_NAME_LEN + 1];
 
-   if (c.dbg_lv != -1)
+   if (!c.show_dentry)
return;
 
name_len = le16_to_cpu(dentry[idx].name_len);
diff --git a/fsck/main.c b/fsck/main.c
index 8bf5cd9..cf1e8af 100644
--- a/fsck/main.c
+++ b/fsck/main.c
@@ -29,7 +29,7 @@ void fsck_usage()
MSG(0, "  -d debug level [default:0]\n");
MSG(0, "  -f check/fix entire partition\n");
MSG(0, "  -p preen mode [default:0 the same as -a [0|1]]\n");
-   MSG(0, "  -t show directory tree [-d -1]\n");
+   MSG(0, "  -t show directory tree\n");
exit(1);
 }
 
@@ -166,7 +166,7 @@ void f2fs_parse_options(int argc, char *argv[])
MSG(0, "Info: Force to fix corruption\n");
break;
case 't':
-   c.dbg_lv = -1;
+   c.show_dentry = 1;
break;
 
 
diff --git a/include/f2fs_fs.h b/include/f2fs_fs.h
index 164315b..789bce1 100644
--- a/include/f2fs_fs.h
+++ b/include/f2fs_fs.h
@@ -285,6 +285,7 @@ struct f2fs_configuration {
char *extension_list;
const char *rootdev_name;
int dbg_lv;
+   int show_dentry;
int trim;
int func;
void *private;
-- 
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


[f2fs-dev] [PATCH v3] f2fscrypt: add a tool for encryption management in the f2fs filesystem

2017-03-15 Thread Kinglong Mee
It's migrated from e4crypt.
Adds an example to the f2fscrypt manpages.

v3, add /tools/f2fscrypt to .gitignore
v2, migrate those micro defines for encrypt to f2fs internal,
drop unless of libsha etc.

Signed-off-by: Kinglong Mee <kinglong...@gmail.com>
---
 .gitignore|   1 +
 tools/Makefile.am |   5 +-
 tools/f2fscrypt.8 | 102 ++
 tools/f2fscrypt.c | 916 ++
 tools/sha512.c| 323 +++
 5 files changed, 1346 insertions(+), 1 deletion(-)
 create mode 100644 tools/f2fscrypt.8
 create mode 100644 tools/f2fscrypt.c
 create mode 100644 tools/sha512.c

diff --git a/.gitignore b/.gitignore
index debeffb..abe1336 100644
--- a/.gitignore
+++ b/.gitignore
@@ -49,3 +49,4 @@ stamp-h1
 /tools/f2fstat
 /tools/fibmap.f2fs
 /tools/parse.f2fs
+/tools/f2fscrypt
diff --git a/tools/Makefile.am b/tools/Makefile.am
index 69a0bb1..5a9303f 100644
--- a/tools/Makefile.am
+++ b/tools/Makefile.am
@@ -2,7 +2,10 @@
 
 AM_CPPFLAGS = ${libuuid_CFLAGS} -I$(top_srcdir)/include
 AM_CFLAGS = -Wall
-sbin_PROGRAMS = f2fstat fibmap.f2fs parse.f2fs
+sbin_PROGRAMS = f2fstat fibmap.f2fs parse.f2fs f2fscrypt
 f2fstat_SOURCES = f2fstat.c
 fibmap_f2fs_SOURCES = fibmap.c
 parse_f2fs_SOURCES = f2fs_io_parse.c
+f2fscrypt_SOURCES = f2fscrypt.c sha512.c
+f2fscrypt_LDFLAGS = -luuid
+dist_man_MANS = f2fscrypt.8
diff --git a/tools/f2fscrypt.8 b/tools/f2fscrypt.8
new file mode 100644
index 000..a60adc8
--- /dev/null
+++ b/tools/f2fscrypt.8
@@ -0,0 +1,102 @@
+.TH F2FSCRYPT 8
+.SH NAME
+f2fscrypt \- f2fs filesystem encryption utility
+.SH SYNOPSIS
+.B f2fscrypt add_key -S \fR[\fB -k \fIkeyring\fR ] [\fB-v\fR] [\fB-q\fR] [ \fI 
path\fR ... ]
+.br
+.B f2fscrypt new_session
+.br
+.B f2fscrypt get_policy \fIpath\fR ...
+.br
+.B f2fscrypt set_policy \fIpolicy path\fR ...
+.SH DESCRIPTION
+.B f2fscrypt
+performs encryption management for f2fs file systems.
+.SH COMMANDS
+.TP
+.B f2fscrypt add_key -S \fR[\fB -k \fIkeyring\fR ] [\fB-v\fR] [\fB-q\fR] [ \fI 
path\fR ... ]
+Prompts the user for a passphrase and inserts it into the specified
+keyring.  If no keyring is specified, f2fscrypt will use the session
+keyring if it exists or the user session keyring if it does not.
+.IP
+If one or more directory paths are specified, f2fscrypt will try to
+set the policy of those directories to use the key just entered by
+the user.
+.TP
+.B f2fscrypt get_policy \fIpath\fR ...
+Print the policy for the directories specified on the command line.
+.TP
+.B f2fscrypt new_session
+Give the invoking process (typically a shell) a new session keyring,
+discarding its old session keyring.
+.TP
+.B f2fscrypt set_policy \fIpolicy path\fR ...
+Sets the policy for the directories specified on the command line.
+All directories must be empty to set the policy; if the directory
+already has a policy established, f2fscrypt will validate that the
+policy matches what was specified.  A policy is an encryption key
+identifier consisting of 16 hexadecimal characters.
+.SH NOTES
+The target directory must be empty.
+.SH EXAMPLE
+.nf
+Formats a f2fs filesytem that supports encrypt.
+
+.ft R
+# mkfs.f2fs -O encrypt /dev/sdxx
+# mount /dev/sdxx /encrypted/
+# mkdir /encrypted/dir
+
+.nf
+First create the key in the keyring use an simple salt
+(or generate a random salt).
+Then use it to set the policy for the directory to be encrypted.
+
+.ft R
+# f2fscrypt add_key -S 0x1234
+  Enter passphrase (echo disabled):
+  Added key with descriptor [28e21cc0c4393da1]
+
+# f2fscrypt set_policy 28e21cc0c4393da1 /encrypted/dir
+  Key with descriptor [28e21cc0c4393da1] applied to /encrypted/dir.
+
+# touch /encrypted/dir/test.txt
+# ls -l /encrypted/dir/
+  -rw-r--r--. 1 root root 0 Mar  5 21:41 test.txt
+
+.nf
+After each reboot, the same command can be used set the key for
+decryption of the directory and its descendants.
+
+.ft R
+# ls -l /encrypted/dir/
+  -rw-r--r--. 1 root root 0 Mar  5 21:41 zbx7tsUEMLzh+AUVMkQcnB
+
+# f2fscrypt get_policy /encrypted/dir/
+  /encrypted/dir/: 28e21cc0c4393da1
+
+# f2fscrypt add_key -S 0x1234
+  Enter passphrase (echo disabled):
+  Added key with descriptor [28e21cc0c4393da1]
+
+# ls -l /encrypted/dir/
+  -rw-r--r--. 1 root root 0 Mar  5 21:41 test.txt
+
+.nf
+Show process keyrings.
+
+.ft R
+# keyctl show
+  Session Keyring
+84022412 --alswrv  0 0  keyring: _ses
+   204615789 --alswrv  0 65534   \\_ keyring: _uid.0
+   529474961 --alsw-v  0 0   \\_ logon: f2fs:28e21cc0c4393da1
+
+.SH AUTHOR
+Written by Kinglong Mee <kinglong...@gmail.com>,
+Migrated from e4crypt that Written by Michael Halcrow <mhalc...@google.com>,
+Ildar Muslukhov <muslukh...@gmail.com>, and Theodore Ts'o <ty...@mit.edu>
+.SH SEE ALSO
+.BR keyctl (1),
+.BR mkfs.f2fs (8),
+.BR mount (8).
diff --git a/tools/f2fscrypt.c b/tools/f2fscrypt.c
new file mode 100644
index 000..48ea5f6
--- /dev/null
+++ b/tools/f2fscrypt.c
@@ -0,0 +1,916 @@
+/*
+ * f2fscrypt.c - f2fs

[f2fs-dev] [PATCH] f2fs: sanity check of crc_offset from raw checkpoint

2017-03-15 Thread Kinglong Mee
The crc_offset towards or beyond the end of block is wrong,
sanity check it.

Signed-off-by: Kinglong Mee <kinglong...@gmail.com>
---
 fs/f2fs/checkpoint.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/f2fs/checkpoint.c b/fs/f2fs/checkpoint.c
index bd75546..f146700 100644
--- a/fs/f2fs/checkpoint.c
+++ b/fs/f2fs/checkpoint.c
@@ -678,7 +678,7 @@ static int get_checkpoint_version(struct f2fs_sb_info *sbi, 
block_t cp_addr,
*cp_block = (struct f2fs_checkpoint *)page_address(*cp_page);
 
crc_offset = le32_to_cpu((*cp_block)->checksum_offset);
-   if (crc_offset >= blk_size) {
+   if (crc_offset > (blk_size - sizeof(__le32))) {
f2fs_msg(sbi->sb, KERN_WARNING,
"invalid crc_offset: %zu", crc_offset);
return -EINVAL;
-- 
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


[f2fs-dev] [PATCH] fsck.f2fs: sanity check of crc_offset from raw checkpoint

2017-03-15 Thread Kinglong Mee
The crc_offset towards or beyond the end of block is wrong,
sanity check it.

Signed-off-by: Kinglong Mee <kinglong...@gmail.com>
---
 fsck/mount.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/fsck/mount.c b/fsck/mount.c
index fc4cca8..c54bb95 100644
--- a/fsck/mount.c
+++ b/fsck/mount.c
@@ -545,7 +545,7 @@ void *validate_checkpoint(struct f2fs_sb_info *sbi, block_t 
cp_addr,
 
cp = (struct f2fs_checkpoint *)cp_page_1;
crc_offset = get_cp(checksum_offset);
-   if (crc_offset >= blk_size)
+   if (crc_offset > (blk_size - sizeof(__le32)))
goto invalid_cp1;
 
crc = le32_to_cpu(*(__le32 *)((unsigned char *)cp + crc_offset));
@@ -563,7 +563,7 @@ void *validate_checkpoint(struct f2fs_sb_info *sbi, block_t 
cp_addr,
 
cp = (struct f2fs_checkpoint *)cp_page_2;
crc_offset = get_cp(checksum_offset);
-   if (crc_offset >= blk_size)
+   if (crc_offset > (blk_size - sizeof(__le32)))
goto invalid_cp2;
 
crc = le32_to_cpu(*(__le32 *)((unsigned char *)cp + crc_offset));
-- 
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


Re: [f2fs-dev] [PATCH v3] f2fs: cleanup the disk level filename updating

2017-03-13 Thread Kinglong Mee
On 3/14/2017 02:23, Jaegeuk Kim wrote:
> On 03/10, Kinglong Mee wrote:
>> As discuss with Jaegeuk and Chao,
>> "Once checkpoint is done, f2fs doesn't need to update there-in filename at 
>> all."
>>
>> The disk-level filename is used only one case,
>> 1. create a file A under a dir
>> 2. sync A
>> 3. godown
>> 4. umount
>> 5. mount (roll_forward)
>>
>> Only the rename/cross_rename changes the filename, if it happens,
>> a. between step 1 and 2, the sync A will caused checkpoint, so that,
>>the roll_forward at step 5 never happens.
>> b. after step 2, the roll_forward happens, file A will roll forward
>>to the result as after step 1.
> 
> I've checked the roll-forward recovery again and found, if pino is recovered,
> it tries to recover dentry with the written filename.
> 
> So,
> 1. create a
> 2. rename a b
> 3. fsync b, will trigger checkpoint and recover pino
> 4. fsync b
> 5. godown
> 
> Then, roll-forward recovery will do recover_dentry with "a". So, correct pino
> should have valid filename.

Is it the right operation? but the f2fs code doesn't do like that, see below.

> 
> Thoughts?

If b isn't exist when renaming, f2fs creates a new directory entry
(f2fs_add_link with name "b"), but no new inode or nid created.

The recover_dentry depends on FSYNC_BIT_SHIFT and DENT_BIT_SHIFT, as your 
procedures,
a roll-forward recovery will do, but no recover_dentry happens.

[ 3607.068713] do_read_inode: ino 3, name (0:0)
[ 3607.090464] do_read_inode: ino 56398, name (0:1) b
[ 3607.110743] F2FS-fs (sdb1): recover_inode: ino = dc4e, name = b
[ 3607.111802] F2FS-fs (sdb1): recover_data: ino = dc4e (i_size: recover) 
recovered = 0, err = 0
[ 3607.117374] F2FS-fs (sdb1): checkpoint: version = 31d5d90f
[ 3607.118384] F2FS-fs (sdb1): Mounted with checkpoint version = 31d5d90f
[ 3607.288552] NFSD: starting 90-second grace period (net beefd140)

After the first fsync at step 3, the IS_CHECKPOINTED is set, after that,
IS_CHECKPOINTED will exist in the nat entry forever, so DENT_BIT_SHIFT never be 
set.

1397 int fsync_node_pages(struct f2fs_sb_info *sbi, struct inode *inode,
1398 struct writeback_control *wbc, bool atomic)

1460 if (!atomic || page == last_page) {
1461 set_fsync_mark(page, 1);
1462 if (IS_INODE(page)) {
1463 if (is_inode_flag_set(inode,
1464 
FI_DIRTY_INODE))
1465 update_inode(inode, page);
1466 set_dentry_mark(page,
1467 need_dentry_mark(sbi, 
ino));
1468 }
1469 /*  may be written by other thread */
1470 if (!PageDirty(page))
1471 set_page_dirty(page);
1472 }

 195 int need_dentry_mark(struct f2fs_sb_info *sbi, nid_t nid)
 196 {
 197 struct f2fs_nm_info *nm_i = NM_I(sbi);
 198 struct nat_entry *e;
 199 bool need = false;
 200
 201 down_read(_i->nat_tree_lock);
 202 e = __lookup_nat_cache(nm_i, nid);
 203 if (e) {
 204 if (!get_nat_flag(e, IS_CHECKPOINTED) &&
 205 !get_nat_flag(e, HAS_FSYNCED_INODE))
 206 need = true;
 207 }
 208 up_read(_i->nat_tree_lock);
 209 return need;
 210 }

thanks,
Kinglong Mee

> 
> Thanks,
> 
>>
>> So that, any updating the disk filename is useless, just cleanup it.
>>
>> Signed-off-by: Kinglong Mee <kinglong...@gmail.com>
>> ---
>>  fs/f2fs/dir.c| 25 -
>>  fs/f2fs/f2fs.h   |  2 --
>>  fs/f2fs/file.c   |  8 
>>  fs/f2fs/inline.c |  2 --
>>  fs/f2fs/namei.c  | 29 -
>>  5 files changed, 4 insertions(+), 62 deletions(-)
>>
>> diff --git a/fs/f2fs/dir.c b/fs/f2fs/dir.c
>> index 8d5c62b..058c4f3 100644
>> --- a/fs/f2fs/dir.c
>> +++ b/fs/f2fs/dir.c
>> @@ -337,24 +337,6 @@ static void init_dent_inode(const struct qstr *name, 
>> struct page *ipage)
>>  set_page_dirty(ipage);
>>  }
>>  
>> -int update_dent_inode(struct inode *inode, struct inode *to,
>> -const struct qstr *name)
>> -{
>> -struct page *page;
>> -
>> -if (file_enc_name(to))
>> -return 0;
>> -
>> -page = get_node_page(F2FS_I_SB(inode), inode->i_ino);
>&

Re: [f2fs-dev] [PATCH v2] f2fs: restrict write IO alignment condition

2017-03-13 Thread Kinglong Mee
On 3/13/2017 21:02, Chao Yu wrote:
> We should only align start offset of bio with defined IO_SIZE for below
> conditions:
> a. mode=lfs mount option
> b. write IOs
> c. Out-place-update
> d. non-meta pages
> 
> Signed-off-by: Chao Yu <yuch...@huawei.com>
> ---
>  fs/f2fs/data.c | 10 +++---
>  1 file changed, 7 insertions(+), 3 deletions(-)
> 
> diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
> index 1375fef11146..53fe79c70406 100644
> --- a/fs/f2fs/data.c
> +++ b/fs/f2fs/data.c
> @@ -190,6 +190,9 @@ static inline void __submit_bio(struct f2fs_sb_info *sbi,
>   current->plug && (type == DATA || type == NODE))
>   blk_finish_plug(current->plug);
>  
> + if (!test_opt(sbi, LFS))
> + goto submit_io;
> +
>   if (type != DATA && type != NODE)
>   goto submit_io;

Is the position of checking LFS here right?

I have a plan of change the code order as, 
diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
index 2ab5ca0..698dbf3 100644
--- a/fs/f2fs/data.c
+++ b/fs/f2fs/data.c
@@ -186,13 +186,12 @@ static inline void __submit_bio(struct f2fs_sb_info *sbi,
if (!is_read_io(bio_op(bio))) {
unsigned int start;

-   if (f2fs_sb_mounted_blkzoned(sbi->sb) &&
-   current->plug && (type == DATA || type == NODE))
-   blk_finish_plug(current->plug);
-
if (type != DATA && type != NODE)
goto submit_io;

+   if (f2fs_sb_mounted_blkzoned(sbi->sb) && current->plug)
+   blk_finish_plug(current->plug);
+
start = bio->bi_iter.bi_size >> F2FS_BLKSIZE_BITS;
start %= F2FS_IO_SIZE(sbi);

thanks,
Kinglong Mee

>  
> @@ -395,11 +398,12 @@ int f2fs_submit_page_mbio(struct f2fs_io_info *fio)
>   __submit_merged_bio(io);
>  alloc_new:
>   if (io->bio == NULL) {
> - if ((fio->type == DATA || fio->type == NODE) &&
> + if (test_opt(sbi, LFS) &&
> + !is_read && (fio->type == DATA || fio->type == NODE) &&
>   fio->new_blkaddr & F2FS_IO_SIZE_MASK(sbi)) {
>   err = -EAGAIN;
> - if (!is_read)
> - dec_page_count(sbi, WB_DATA_TYPE(bio_page));
> + f2fs_bug_on(sbi, fio->new_blkaddr == fio->old_blkaddr);
> + dec_page_count(sbi, WB_DATA_TYPE(bio_page));
>   goto out_fail;
>   }
>   io->bio = __bio_alloc(sbi, fio->new_blkaddr,
> 

--
Announcing the Oxford Dictionaries API! The API offers world-renowned
dictionary content that is easy and intuitive to access. Sign up for an
account today to start using our lexical data to power your apps and
projects. Get started today and enter our developer competition.
http://sdm.link/oxford
___
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: cover update_free_nid_bitmap with free_list_lock

2017-03-13 Thread Kinglong Mee
On 3/13/2017 20:10, Chao Yu wrote:
> free_nid_bitmap and free_nid_count in update_free_nid_bitmap should be
> updated atomically, use free_list_lock cover them to avoid race in

nid_list_lock?

Reviewed-by: Kinglong Mee <kinglong...@gmail.com>

> concurrent scenario.
> 
> Signed-off-by: Chao Yu <yuch...@huawei.com>
> ---
>  fs/f2fs/f2fs.h |  1 -
>  fs/f2fs/node.c | 27 +++
>  2 files changed, 11 insertions(+), 17 deletions(-)
> 
> diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
> index 843ce39502bc..d905e53ba524 100644
> --- a/fs/f2fs/f2fs.h
> +++ b/fs/f2fs/f2fs.h
> @@ -561,7 +561,6 @@ struct f2fs_nm_info {
>   unsigned char (*free_nid_bitmap)[NAT_ENTRY_BITMAP_SIZE];
>   unsigned char *nat_block_bitmap;
>   unsigned short *free_nid_count; /* free nid count of NAT block */
> - spinlock_t free_nid_lock;   /* protect updating of nid count */
>  
>   /* for checkpoint */
>   char *nat_bitmap;   /* NAT bitmap pointer */
> diff --git a/fs/f2fs/node.c b/fs/f2fs/node.c
> index 11df8ab32478..3bfffd744f87 100644
> --- a/fs/f2fs/node.c
> +++ b/fs/f2fs/node.c
> @@ -1815,7 +1815,7 @@ static void remove_free_nid(struct f2fs_sb_info *sbi, 
> nid_t nid)
>  }
>  
>  static void update_free_nid_bitmap(struct f2fs_sb_info *sbi, nid_t nid,
> - bool set, bool build, bool locked)
> + bool set, bool build)
>  {
>   struct f2fs_nm_info *nm_i = NM_I(sbi);
>   unsigned int nat_ofs = NAT_BLOCK_OFFSET(nid);
> @@ -1829,14 +1829,10 @@ static void update_free_nid_bitmap(struct 
> f2fs_sb_info *sbi, nid_t nid,
>   else
>   __clear_bit_le(nid_ofs, nm_i->free_nid_bitmap[nat_ofs]);
>  
> - if (!locked)
> - spin_lock(_i->free_nid_lock);
>   if (set)
>   nm_i->free_nid_count[nat_ofs]++;
>   else if (!build)
>   nm_i->free_nid_count[nat_ofs]--;
> - if (!locked)
> - spin_unlock(_i->free_nid_lock);
>  }
>  
>  static void scan_nat_page(struct f2fs_sb_info *sbi,
> @@ -1865,7 +1861,9 @@ static void scan_nat_page(struct f2fs_sb_info *sbi,
>   f2fs_bug_on(sbi, blk_addr == NEW_ADDR);
>   if (blk_addr == NULL_ADDR)
>   freed = add_free_nid(sbi, start_nid, true);
> - update_free_nid_bitmap(sbi, start_nid, freed, true, false);
> + spin_lock(_I(sbi)->nid_list_lock);
> + update_free_nid_bitmap(sbi, start_nid, freed, true);
> + spin_unlock(_I(sbi)->nid_list_lock);
>   }
>  }
>  
> @@ -2020,7 +2018,7 @@ bool alloc_nid(struct f2fs_sb_info *sbi, nid_t *nid)
>   __insert_nid_to_list(sbi, i, ALLOC_NID_LIST, false);
>   nm_i->available_nids--;
>  
> - update_free_nid_bitmap(sbi, *nid, false, false, false);
> + update_free_nid_bitmap(sbi, *nid, false, false);
>  
>   spin_unlock(_i->nid_list_lock);
>   return true;
> @@ -2076,7 +2074,7 @@ void alloc_nid_failed(struct f2fs_sb_info *sbi, nid_t 
> nid)
>  
>   nm_i->available_nids++;
>  
> - update_free_nid_bitmap(sbi, nid, true, false, false);
> + update_free_nid_bitmap(sbi, nid, true, false);
>  
>   spin_unlock(_i->nid_list_lock);
>  
> @@ -2406,11 +2404,11 @@ static void __flush_nat_entry_set(struct f2fs_sb_info 
> *sbi,
>   add_free_nid(sbi, nid, false);
>   spin_lock(_I(sbi)->nid_list_lock);
>   NM_I(sbi)->available_nids++;
> - update_free_nid_bitmap(sbi, nid, true, false, false);
> + update_free_nid_bitmap(sbi, nid, true, false);
>   spin_unlock(_I(sbi)->nid_list_lock);
>   } else {
>   spin_lock(_I(sbi)->nid_list_lock);
> - update_free_nid_bitmap(sbi, nid, false, false, false);
> + update_free_nid_bitmap(sbi, nid, false, false);
>   spin_unlock(_I(sbi)->nid_list_lock);
>   }
>   }
> @@ -2535,10 +2533,10 @@ inline void load_free_nid_bitmap(struct f2fs_sb_info 
> *sbi)
>   nid = i * NAT_ENTRY_PER_BLOCK;
>   last_nid = (i + 1) * NAT_ENTRY_PER_BLOCK;
>  
> - spin_lock(_i->free_nid_lock);
> + spin_lock(_I(sbi)->nid_list_lock);
>   for (; nid < last_nid; nid++)
> - update_free_nid_bitmap(sbi, nid, true, true, true);
> - spin_unlock(_i->free_nid_lock);
> + update_free_nid_bitmap(sbi, nid, tr

[f2fs-dev] [PATCH] f2fs: fix bad prefetchw of NULL page

2017-03-13 Thread Kinglong Mee
For f2fs_read_data_pages, the f2fs_mpage_readpages gets "page == NULL",
so that, the prefetchw(>flags) is operated on NULL.

Fixes: f1e8866016 ("f2fs: expose f2fs_mpage_readpages")
Signed-off-by: Kinglong Mee <kinglong...@gmail.com>
---
 fs/f2fs/data.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
index 1375fef..2ab5ca0 100644
--- a/fs/f2fs/data.c
+++ b/fs/f2fs/data.c
@@ -1150,9 +1150,10 @@ static int f2fs_mpage_readpages(struct address_space 
*mapping,
 
for (page_idx = 0; nr_pages; page_idx++, nr_pages--) {
 
-   prefetchw(>flags);
if (pages) {
page = list_last_entry(pages, struct page, lru);
+
+   prefetchw(>flags);
list_del(>lru);
if (add_to_page_cache_lru(page, mapping,
  page->index,
-- 
2.9.3


--
Announcing the Oxford Dictionaries API! The API offers world-renowned
dictionary content that is easy and intuitive to access. Sign up for an
account today to start using our lexical data to power your apps and
projects. Get started today and enter our developer competition.
http://sdm.link/oxford
___
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel


[f2fs-dev] [PATCH] f2fs: le32_to_cpu for ckpt->cp_pack_total_block_count

2017-03-11 Thread Kinglong Mee
Fixes: 22ad0b6ab4 ("f2fs: add bitmaps for empty or full NAT blocks")
Signed-off-by: Kinglong Mee <kinglong...@gmail.com>
---
 fs/f2fs/checkpoint.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/fs/f2fs/checkpoint.c b/fs/f2fs/checkpoint.c
index 4db995c..41f6a42 100644
--- a/fs/f2fs/checkpoint.c
+++ b/fs/f2fs/checkpoint.c
@@ -1025,7 +1025,8 @@ static void update_ckpt_flags(struct f2fs_sb_info *sbi, 
struct cp_control *cpc)
 
spin_lock(>cp_lock);
 
-   if (cpc->reason == CP_UMOUNT && ckpt->cp_pack_total_block_count >
+   if (cpc->reason == CP_UMOUNT &&
+   le32_to_cpu(ckpt->cp_pack_total_block_count) >
sbi->blocks_per_seg - NM_I(sbi)->nat_bits_blocks)
disable_nat_bits(sbi, false);
 
-- 
2.9.3


--
Announcing the Oxford Dictionaries API! The API offers world-renowned
dictionary content that is easy and intuitive to access. Sign up for an
account today to start using our lexical data to power your apps and
projects. Get started today and enter our developer competition.
http://sdm.link/oxford
___
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel


[f2fs-dev] [PATCH] f2fs: clear FI_DATA_EXIST flag in truncate_inline_inode

2017-03-10 Thread Kinglong Mee
Clear FI_DATA_EXIST flag atomically in truncate_inline_inode, and
the return value from truncate_inline_inode isn't used, remove it.

Signed-off-by: Kinglong Mee <kinglong...@gmail.com>
---
 fs/f2fs/f2fs.h   |  8 +---
 fs/f2fs/file.c   |  4 +---
 fs/f2fs/inline.c | 21 +++--
 3 files changed, 13 insertions(+), 20 deletions(-)

diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
index 5dbc0c0..ee68144 100644
--- a/fs/f2fs/f2fs.h
+++ b/fs/f2fs/f2fs.h
@@ -1872,12 +1872,6 @@ static inline int f2fs_has_inline_data(struct inode 
*inode)
return is_inode_flag_set(inode, FI_INLINE_DATA);
 }
 
-static inline void f2fs_clear_inline_inode(struct inode *inode)
-{
-   clear_inode_flag(inode, FI_INLINE_DATA);
-   clear_inode_flag(inode, FI_DATA_EXIST);
-}
-
 static inline int f2fs_exist_data(struct inode *inode)
 {
return is_inode_flag_set(inode, FI_DATA_EXIST);
@@ -2504,7 +2498,7 @@ extern struct kmem_cache *inode_entry_slab;
 bool f2fs_may_inline_data(struct inode *inode);
 bool f2fs_may_inline_dentry(struct inode *inode);
 void read_inline_data(struct page *page, struct page *ipage);
-bool truncate_inline_inode(struct page *ipage, u64 from);
+void truncate_inline_inode(struct inode *inode, struct page *ipage, u64 from);
 int f2fs_read_inline_data(struct inode *inode, struct page *page);
 int f2fs_convert_inline_page(struct dnode_of_data *dn, struct page *page);
 int f2fs_convert_inline_inode(struct inode *inode);
diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
index c407fa6..da6d33d1 100644
--- a/fs/f2fs/file.c
+++ b/fs/f2fs/file.c
@@ -561,9 +561,7 @@ int truncate_blocks(struct inode *inode, u64 from, bool 
lock)
}
 
if (f2fs_has_inline_data(inode)) {
-   truncate_inline_inode(ipage, from);
-   if (from == 0)
-   clear_inode_flag(inode, FI_DATA_EXIST);
+   truncate_inline_inode(inode, ipage, from);
f2fs_put_page(ipage, 1);
truncate_page = true;
goto out;
diff --git a/fs/f2fs/inline.c b/fs/f2fs/inline.c
index 41fe27d..701bbd8 100644
--- a/fs/f2fs/inline.c
+++ b/fs/f2fs/inline.c
@@ -63,19 +63,21 @@ void read_inline_data(struct page *page, struct page *ipage)
SetPageUptodate(page);
 }
 
-bool truncate_inline_inode(struct page *ipage, u64 from)
+void truncate_inline_inode(struct inode *inode, struct page *ipage, u64 from)
 {
void *addr;
 
if (from >= MAX_INLINE_DATA)
-   return false;
+   return;
 
addr = inline_data_addr(ipage);
 
f2fs_wait_on_page_writeback(ipage, NODE, true);
memset(addr + from, 0, MAX_INLINE_DATA - from);
set_page_dirty(ipage);
-   return true;
+
+   if (from == 0)
+   clear_inode_flag(inode, FI_DATA_EXIST);
 }
 
 int f2fs_read_inline_data(struct inode *inode, struct page *page)
@@ -146,11 +148,11 @@ int f2fs_convert_inline_page(struct dnode_of_data *dn, 
struct page *page)
set_inode_flag(dn->inode, FI_APPEND_WRITE);
 
/* clear inline data and flag after data writeback */
-   truncate_inline_inode(dn->inode_page, 0);
+   truncate_inline_inode(dn->inode, dn->inode_page, 0);
clear_inline_node(dn->inode_page);
 clear_out:
stat_dec_inline_inode(dn->inode);
-   f2fs_clear_inline_inode(dn->inode);
+   clear_inode_flag(dn->inode, FI_INLINE_DATA);
f2fs_put_dnode(dn);
return 0;
 }
@@ -267,9 +269,8 @@ bool recover_inline_data(struct inode *inode, struct page 
*npage)
if (f2fs_has_inline_data(inode)) {
ipage = get_node_page(sbi, inode->i_ino);
f2fs_bug_on(sbi, IS_ERR(ipage));
-   if (!truncate_inline_inode(ipage, 0))
-   return false;
-   f2fs_clear_inline_inode(inode);
+   truncate_inline_inode(inode, ipage, 0);
+   clear_inode_flag(inode, FI_INLINE_DATA);
f2fs_put_page(ipage, 1);
} else if (ri && (ri->i_inline & F2FS_INLINE_DATA)) {
if (truncate_blocks(inode, 0, false))
@@ -380,7 +381,7 @@ static int f2fs_move_inline_dirents(struct inode *dir, 
struct page *ipage,
set_page_dirty(page);
 
/* clear inline dir and flag after data writeback */
-   truncate_inline_inode(ipage, 0);
+   truncate_inline_inode(dir, ipage, 0);
 
stat_dec_inline_dir(dir);
clear_inode_flag(dir, FI_INLINE_DENTRY);
@@ -455,7 +456,7 @@ static int f2fs_move_rehashed_dirents(struct inode *dir, 
struct page *ipage,
}
 
memcpy(backup_dentry, inline_dentry, MAX_INLINE_DATA);
-   truncate_inline_inode(ipage, 0);
+   truncate_inline_inode(dir, ipage, 0);
 
unlock_page(ipage);
 
-- 
2.9.3


--
Announcing the Oxford Dictionaries API! The API offers world-renowned
dictionary co

[f2fs-dev] [PATCH 4/4] f2fs: move mnt_want_write_file after arguments checking

2017-03-10 Thread Kinglong Mee
It's needless of mnt_want_write_file for arguments checking.

Signed-off-by: Kinglong Mee <kinglong...@gmail.com>
---
 fs/f2fs/file.c | 44 ++--
 1 file changed, 18 insertions(+), 26 deletions(-)

diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
index 08bfab3..c407fa6 100644
--- a/fs/f2fs/file.c
+++ b/fs/f2fs/file.c
@@ -2023,45 +2023,37 @@ static int f2fs_ioc_defragment(struct file *filp, 
unsigned long arg)
if (!S_ISREG(inode->i_mode))
return -EINVAL;
 
-   err = mnt_want_write_file(filp);
-   if (err)
-   return err;
-
-   if (f2fs_readonly(sbi->sb)) {
-   err = -EROFS;
-   goto out;
-   }
+   if (f2fs_readonly(sbi->sb))
+   return -EROFS;
 
if (copy_from_user(, (struct f2fs_defragment __user *)arg,
-   sizeof(range))) {
-   err = -EFAULT;
-   goto out;
-   }
+   sizeof(range)))
+   return -EFAULT;
 
/* verify alignment of offset & size */
-   if (range.start & (F2FS_BLKSIZE - 1) ||
-   range.len & (F2FS_BLKSIZE - 1)) {
-   err = -EINVAL;
-   goto out;
-   }
+   if (range.start & (F2FS_BLKSIZE - 1) || range.len & (F2FS_BLKSIZE - 1))
+   return -EINVAL;
 
if (unlikely((range.start + range.len) >> PAGE_SHIFT >
-   sbi->max_file_blocks)) {
-   err = -EINVAL;
-   goto out;
-   }
+   sbi->max_file_blocks))
+   return -EINVAL;
+
+   err = mnt_want_write_file(filp);
+   if (err)
+   return err;
 
err = f2fs_defragment_range(sbi, filp, );
+   mnt_drop_write_file(filp);
+
f2fs_update_time(sbi, REQ_TIME);
if (err < 0)
-   goto out;
+   return err;
 
if (copy_to_user((struct f2fs_defragment __user *)arg, ,
sizeof(range)))
-   err = -EFAULT;
-out:
-   mnt_drop_write_file(filp);
-   return err;
+   return -EFAULT;
+
+   return 0;
 }
 
 static int f2fs_move_file_range(struct file *file_in, loff_t pos_in,
-- 
2.9.3


--
Announcing the Oxford Dictionaries API! The API offers world-renowned
dictionary content that is easy and intuitive to access. Sign up for an
account today to start using our lexical data to power your apps and
projects. Get started today and enter our developer competition.
http://sdm.link/oxford
___
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel


[f2fs-dev] [PATCH 2/4] f2fs: avoid copy date to user-space if move file range fail

2017-03-10 Thread Kinglong Mee
If move file range return error, the data copied to user-space is duplicate.

Signed-off-by: Kinglong Mee <kinglong...@gmail.com>
---
 fs/f2fs/file.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
index 5f8d600..88afe0f 100644
--- a/fs/f2fs/file.c
+++ b/fs/f2fs/file.c
@@ -2194,6 +2194,8 @@ static int f2fs_ioc_move_range(struct file *filp, 
unsigned long arg)
range.pos_out, range.len);
 
mnt_drop_write_file(filp);
+   if (err)
+   goto err_out;
 
if (copy_to_user((struct f2fs_move_range __user *)arg,
, sizeof(range)))
-- 
2.9.3


--
Announcing the Oxford Dictionaries API! The API offers world-renowned
dictionary content that is easy and intuitive to access. Sign up for an
account today to start using our lexical data to power your apps and
projects. Get started today and enter our developer competition.
http://sdm.link/oxford
___
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel


[f2fs-dev] [PATCH 1/4] f2fs: drop duplicate new_size assign in f2fs_zero_range

2017-03-10 Thread Kinglong Mee
Signed-off-by: Kinglong Mee <kinglong...@gmail.com>
---
 fs/f2fs/file.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
index 8c7923f..5f8d600 100644
--- a/fs/f2fs/file.c
+++ b/fs/f2fs/file.c
@@ -1189,8 +1189,6 @@ static int f2fs_zero_range(struct inode *inode, loff_t 
offset, loff_t len,
if (ret)
return ret;
 
-   if (offset + len > new_size)
-   new_size = offset + len;
new_size = max_t(loff_t, new_size, offset + len);
} else {
if (off_start) {
-- 
2.9.3


--
Announcing the Oxford Dictionaries API! The API offers world-renowned
dictionary content that is easy and intuitive to access. Sign up for an
account today to start using our lexical data to power your apps and
projects. Get started today and enter our developer competition.
http://sdm.link/oxford
___
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel


[f2fs-dev] [PATCH v3] f2fs: cleanup the disk level filename updating

2017-03-10 Thread Kinglong Mee
As discuss with Jaegeuk and Chao,
"Once checkpoint is done, f2fs doesn't need to update there-in filename at all."

The disk-level filename is used only one case,
1. create a file A under a dir
2. sync A
3. godown
4. umount
5. mount (roll_forward)

Only the rename/cross_rename changes the filename, if it happens,
a. between step 1 and 2, the sync A will caused checkpoint, so that,
   the roll_forward at step 5 never happens.
b. after step 2, the roll_forward happens, file A will roll forward
   to the result as after step 1.

So that, any updating the disk filename is useless, just cleanup it.

Signed-off-by: Kinglong Mee <kinglong...@gmail.com>
---
 fs/f2fs/dir.c| 25 -
 fs/f2fs/f2fs.h   |  2 --
 fs/f2fs/file.c   |  8 
 fs/f2fs/inline.c |  2 --
 fs/f2fs/namei.c  | 29 -
 5 files changed, 4 insertions(+), 62 deletions(-)

diff --git a/fs/f2fs/dir.c b/fs/f2fs/dir.c
index 8d5c62b..058c4f3 100644
--- a/fs/f2fs/dir.c
+++ b/fs/f2fs/dir.c
@@ -337,24 +337,6 @@ static void init_dent_inode(const struct qstr *name, 
struct page *ipage)
set_page_dirty(ipage);
 }
 
-int update_dent_inode(struct inode *inode, struct inode *to,
-   const struct qstr *name)
-{
-   struct page *page;
-
-   if (file_enc_name(to))
-   return 0;
-
-   page = get_node_page(F2FS_I_SB(inode), inode->i_ino);
-   if (IS_ERR(page))
-   return PTR_ERR(page);
-
-   init_dent_inode(name, page);
-   f2fs_put_page(page, 1);
-
-   return 0;
-}
-
 void do_make_empty_dir(struct inode *inode, struct inode *parent,
struct f2fs_dentry_ptr *d)
 {
@@ -438,8 +420,11 @@ struct page *init_inode_metadata(struct inode *inode, 
struct inode *dir,
set_cold_node(inode, page);
}
 
-   if (new_name)
+   if (new_name) {
init_dent_inode(new_name, page);
+   if (f2fs_encrypted_inode(dir))
+   file_set_enc_name(inode);
+   }
 
/*
 * This file should be checkpointed during fsync.
@@ -599,8 +584,6 @@ int f2fs_add_regular_entry(struct inode *dir, const struct 
qstr *new_name,
err = PTR_ERR(page);
goto fail;
}
-   if (f2fs_encrypted_inode(dir))
-   file_set_enc_name(inode);
}
 
make_dentry_ptr(NULL, , (void *)dentry_blk, 1);
diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
index 7edb3be..5dbc0c0 100644
--- a/fs/f2fs/f2fs.h
+++ b/fs/f2fs/f2fs.h
@@ -2093,8 +2093,6 @@ ino_t f2fs_inode_by_name(struct inode *dir, const struct 
qstr *qstr,
struct page **page);
 void f2fs_set_link(struct inode *dir, struct f2fs_dir_entry *de,
struct page *page, struct inode *inode);
-int update_dent_inode(struct inode *inode, struct inode *to,
-   const struct qstr *name);
 void f2fs_update_dentry(nid_t ino, umode_t mode, struct f2fs_dentry_ptr *d,
const struct qstr *name, f2fs_hash_t name_hash,
unsigned int bit_pos);
diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
index 4ec764e..8c7923f 100644
--- a/fs/f2fs/file.c
+++ b/fs/f2fs/file.c
@@ -110,20 +110,12 @@ static int get_parent_ino(struct inode *inode, nid_t 
*pino)
 {
struct dentry *dentry;
 
-   if (file_enc_name(inode))
-   return 0;
-
inode = igrab(inode);
dentry = d_find_any_alias(inode);
iput(inode);
if (!dentry)
return 0;
 
-   if (update_dent_inode(inode, inode, >d_name)) {
-   dput(dentry);
-   return 0;
-   }
-
*pino = parent_ino(dentry);
dput(dentry);
return 1;
diff --git a/fs/f2fs/inline.c b/fs/f2fs/inline.c
index e32a9e5..41fe27d 100644
--- a/fs/f2fs/inline.c
+++ b/fs/f2fs/inline.c
@@ -527,8 +527,6 @@ int f2fs_add_inline_entry(struct inode *dir, const struct 
qstr *new_name,
err = PTR_ERR(page);
goto fail;
}
-   if (f2fs_encrypted_inode(dir))
-   file_set_enc_name(inode);
}
 
f2fs_wait_on_page_writeback(ipage, NODE, true);
diff --git a/fs/f2fs/namei.c b/fs/f2fs/namei.c
index 25c073f..8906c9f 100644
--- a/fs/f2fs/namei.c
+++ b/fs/f2fs/namei.c
@@ -720,13 +720,6 @@ static int f2fs_rename(struct inode *old_dir, struct 
dentry *old_dentry,
if (err)
goto put_out_dir;
 
-   err = update_dent_inode(old_inode, new_inode,
-   _dentry->d_name);
-   if (err) {
-   release_orphan_inode(sbi);
-   goto put_out_dir;
-   }
-
f2fs_set_link(new_dir, new_entry, new_page, old_inode);
 
new_inod

Re: [f2fs-dev] [PATCH] f2fs: skip scanning free nid bitmap of full NAT blocks

2017-03-09 Thread Kinglong Mee
On 3/1/2017 17:09, Chao Yu wrote:
> This patch adds to account free nids for each NAT blocks, and while
> scanning all free nid bitmap, do check count and skip lookuping in
> full NAT block.
> 
> Signed-off-by: Chao Yu <yuch...@huawei.com>
> ---
>  fs/f2fs/debug.c |  1 +
>  fs/f2fs/f2fs.h  |  2 ++
>  fs/f2fs/node.c  | 34 --
>  3 files changed, 31 insertions(+), 6 deletions(-)
> 
> diff --git a/fs/f2fs/debug.c b/fs/f2fs/debug.c
> index a77df377e2e8..ee2d0a485fc3 100644
> --- a/fs/f2fs/debug.c
> +++ b/fs/f2fs/debug.c
> @@ -196,6 +196,7 @@ static void update_mem_info(struct f2fs_sb_info *sbi)
>   si->base_mem += (NM_I(sbi)->nat_bits_blocks << F2FS_BLKSIZE_BITS);
>   si->base_mem += NM_I(sbi)->nat_blocks * NAT_ENTRY_BITMAP_SIZE;
>   si->base_mem += NM_I(sbi)->nat_blocks / 8;
> + si->base_mem += NM_I(sbi)->nat_blocks * sizeof(unsigned short);
>  
>  get_cache:
>   si->cache_mem = 0;
> diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
> index 7e2924981eeb..c0b33719dfa9 100644
> --- a/fs/f2fs/f2fs.h
> +++ b/fs/f2fs/f2fs.h
> @@ -557,6 +557,8 @@ struct f2fs_nm_info {
>   struct mutex build_lock;/* lock for build free nids */
>   unsigned char (*free_nid_bitmap)[NAT_ENTRY_BITMAP_SIZE];
>   unsigned char *nat_block_bitmap;
> + unsigned short *free_nid_count; /* free nid count of NAT block */
> + spinlock_t free_nid_lock;   /* protect updating of nid count */
>  

Sorry for my reply so late.

Is the free_nid_lock needed here?
The free_nid_count should be protected as free_nid_bitmap,
but there isn't any lock for free_nid_bitmap.

How about atomic? 
The free node ids management seems a little complex now.

thanks,
Kinglong Mee

>   /* for checkpoint */
>   char *nat_bitmap;   /* NAT bitmap pointer */
> diff --git a/fs/f2fs/node.c b/fs/f2fs/node.c
> index 94967171dee8..1a759d45b7e4 100644
> --- a/fs/f2fs/node.c
> +++ b/fs/f2fs/node.c
> @@ -1823,7 +1823,8 @@ static void remove_free_nid(struct f2fs_sb_info *sbi, 
> nid_t nid)
>   kmem_cache_free(free_nid_slab, i);
>  }
>  
> -void update_free_nid_bitmap(struct f2fs_sb_info *sbi, nid_t nid, bool set)
> +void update_free_nid_bitmap(struct f2fs_sb_info *sbi, nid_t nid,
> + bool set, bool build)
>  {
>   struct f2fs_nm_info *nm_i = NM_I(sbi);
>   unsigned int nat_ofs = NAT_BLOCK_OFFSET(nid);
> @@ -1836,6 +1837,13 @@ void update_free_nid_bitmap(struct f2fs_sb_info *sbi, 
> nid_t nid, bool set)
>   set_bit_le(nid_ofs, nm_i->free_nid_bitmap[nat_ofs]);
>   else
>   clear_bit_le(nid_ofs, nm_i->free_nid_bitmap[nat_ofs]);
> +
> + spin_lock(_i->free_nid_lock);
> + if (set)
> + nm_i->free_nid_count[nat_ofs]++;
> + else if (!build)
> + nm_i->free_nid_count[nat_ofs]--;
> + spin_unlock(_i->free_nid_lock);
>  }
>  
>  static void scan_nat_page(struct f2fs_sb_info *sbi,
> @@ -1847,6 +1855,9 @@ static void scan_nat_page(struct f2fs_sb_info *sbi,
>   unsigned int nat_ofs = NAT_BLOCK_OFFSET(start_nid);
>   int i;
>  
> + if (test_bit_le(nat_ofs, nm_i->nat_block_bitmap))
> + return;
> +
>   set_bit_le(nat_ofs, nm_i->nat_block_bitmap);
>  
>   i = start_nid % NAT_ENTRY_PER_BLOCK;
> @@ -1861,7 +1872,7 @@ static void scan_nat_page(struct f2fs_sb_info *sbi,
>   f2fs_bug_on(sbi, blk_addr == NEW_ADDR);
>   if (blk_addr == NULL_ADDR)
>   freed = add_free_nid(sbi, start_nid, true);
> - update_free_nid_bitmap(sbi, start_nid, freed);
> + update_free_nid_bitmap(sbi, start_nid, freed, true);
>   }
>  }
>  
> @@ -1877,6 +1888,8 @@ static void scan_free_nid_bits(struct f2fs_sb_info *sbi)
>   for (i = 0; i < nm_i->nat_blocks; i++) {
>   if (!test_bit_le(i, nm_i->nat_block_bitmap))
>   continue;
> + if (!nm_i->free_nid_count[i])
> + continue;
>   for (idx = 0; idx < NAT_ENTRY_PER_BLOCK; idx++) {
>   nid_t nid;
>  
> @@ -2081,7 +2094,7 @@ bool alloc_nid(struct f2fs_sb_info *sbi, nid_t *nid)
>   __insert_nid_to_list(sbi, i, ALLOC_NID_LIST, false);
>   nm_i->available_nids--;
>  
> - update_free_nid_bitmap(sbi, *nid, false);
> + update_free_nid_bitmap(sbi, *nid, false, false);
>  
>   spin_unlock(_i->nid_list_lock);
>   return true;
> @@ -2137,7 +2150,7 @@ void alloc_nid_failed(struct f2fs_sb_info *sbi, nid_t 
&g

Re: [f2fs-dev] [PATCH v2] f2fs: sync the enc name flags with disk level filename

2017-03-09 Thread Kinglong Mee
On 3/8/2017 18:56, Kinglong Mee wrote:
> On 3/8/2017 03:30, Jaegeuk Kim wrote:
>> Hi Kinglong,
>>
>> Can we make a testcase in xfstests to check this clearly?
>> 1. creat A under encrypted dir
>> 2. rename A to B
>> 3. fsync B
>> 4. power-cut
>>
>> Is this your concern?
> 
> Yes, it is.
> If B isn't exist, rename A to B means create a new A (unlink the old).
> B is exist, the inode (include disk node) will be replace by A, but,
> for the file_enc_name, the disk i_name/i_namelen isn't updated.
> 
> For the rename, A and B lost there parent, so the 3 step will cause 
> checkpoint, 
> after that, everything is updated to disk (with the unchanged filename), 
> so that the 4 step of power-cut can't cause a roll_forward.
> 
> If fsync A for flags the inode and then rename as,
> 1. creat A and B under encrypted dir
> 2. fsync A  (after rename, B will be unlink)
> 3. rename A to B
> 4. godown 
> 5. umount/mount
> 
> A roll_forward (recover_dentry) happens, the result is same as after setp1,
> that's not my needs.
> 
> For the IS_CHECKPOINTED flag, after a new created file sync to the disk,
> it's cleared, and never appears again, after that a roll_forward of 
> recover_dentry will never happen (it means the disk i_name will not be
> used forever). Am I right?
> 
> If that's right, next update_dent_inode after file created is useless,
> we can remove them include the FADVISE_ENC_NAME_BIT.

Hi Jaegeuk, 

What's your opinion?
If you agree that they are useless of the disk-level filename updating, 
I will cleanup them.

thanks,
Kinglong Mee

> 
>>
>> Hmm, on-disk filename is used when doing roll-forward recovery, and it seems
>> there is a hole in try_to_fix_pino() to recover its pino without filename.
>>
>> Like this?
>>
>> >From 7efde035d9f930fc63c30b25327e870b021750f3 Mon Sep 17 00:00:00 2001
>> From: Jaegeuk Kim <jaeg...@kernel.org>
>> Date: Tue, 7 Mar 2017 11:22:45 -0800
>> Subject: [PATCH] f2fS: don't allow to get pino when filename is encrypted
>>
>> After renaming an encrypted file, we have no way to get its
>> encrypted filename from its dentry.
>>
>> Signed-off-by: Jaegeuk Kim <jaeg...@kernel.org>
>> ---
>>  fs/f2fs/file.c | 3 +++
>>  1 file changed, 3 insertions(+)
>>
>> diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
>> index e0b2378f8519..852195b3bcce 100644
>> --- a/fs/f2fs/file.c
>> +++ b/fs/f2fs/file.c
>> @@ -110,6 +110,9 @@ static int get_parent_ino(struct inode *inode, nid_t 
>> *pino)
>>  {
>>  struct dentry *dentry;
>>  
>> +if (file_enc_name(inode))
>> +return 0;
>> +
>>  inode = igrab(inode);
>>  dentry = d_find_any_alias(inode);
>>  iput(inode);
>>

Yes, this patch is needed, but it causes the following problem of 
the forever lost parent inode flags for encrypted files after rename.

thanks,
Kinglong Mee

> 
> The renamed inode will lost their parent ino, and try to fix it when fsync.
> With the file_enc_name checking, get_parent_ino return 0 without parent ino
> for encrypted inode, after that the FADVISE_COLD_BIT will exist forever, 
> fsync the encrypted inode causing do_checkpoint every time.
> 
> static void try_to_fix_pino(struct inode *inode)
> {
> struct f2fs_inode_info *fi = F2FS_I(inode);
> nid_t pino;
> 
> down_write(>i_sem);
> if (file_wrong_pino(inode) && inode->i_nlink == 1 &&
> get_parent_ino(inode, )) {
> f2fs_i_pino_write(inode, pino);
> file_got_pino(inode);
> }
> up_write(>i_sem);
> }
> 
> thanks,
> Kinglong Mee
> 

--
Announcing the Oxford Dictionaries API! The API offers world-renowned
dictionary content that is easy and intuitive to access. Sign up for an
account today to start using our lexical data to power your apps and
projects. Get started today and enter our developer competition.
http://sdm.link/oxford
___
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: don't allow rename unencrypted file to encrypted directory

2017-03-08 Thread Kinglong Mee
On 3/8/2017 20:08, Chao Yu wrote:
> In commit d9cdc9033181 ("ext4 crypto: enforce context consistency") we
> declared that:
> 
> 2) All files or directories in a directory must be protected using the
> same key as their containing directory.
> 
> But in f2fs_cross_rename there is a vulnerability that allow to cross
> rename unencrypted file into encrypted directory, it needs to be refused.

fscrypt_has_permitted_context has do the checking as this patch,

168 /* no restrictions if the parent directory is not encrypted */
169 if (!parent->i_sb->s_cop->is_encrypted(parent))
170 return 1;
171 /* if the child directory is not encrypted, this is always a 
problem */
172 if (!parent->i_sb->s_cop->is_encrypted(child))
173 return 0;

So, the cross rename unencrypted file into encrypted directory is permitted 
right now. 

I have a encrypted directory "ncry",  "new" is unencrypted file.

[root@nfstestnic f2fs]# renameat2 -x encry/hello new
Operation not permitted
[root@nfstestnic f2fs]# renameat2 -x encry/hello new
Operation not permitted

How do you test it? 

thanks,
Kinglong Mee
> 
> Signed-off-by: Chao Yu <yuch...@huawei.com>
> ---
>  fs/f2fs/namei.c | 4 
>  1 file changed, 4 insertions(+)
> 
> diff --git a/fs/f2fs/namei.c b/fs/f2fs/namei.c
> index 25c073f6c7d4..8de684b84cb9 100644
> --- a/fs/f2fs/namei.c
> +++ b/fs/f2fs/namei.c
> @@ -855,6 +855,10 @@ static int f2fs_cross_rename(struct inode *old_dir, 
> struct dentry *old_dentry,
>   !fscrypt_has_encryption_key(new_dir)))
>   return -ENOKEY;
>  
> + if (f2fs_encrypted_inode(old_dir) && !f2fs_encrypted_inode(new_inode) ||
> + f2fs_encrypted_inode(new_dir) && 
> !f2fs_encrypted_inode(old_inode))
> + return -EPERM;
> +
>   if ((f2fs_encrypted_inode(old_dir) || f2fs_encrypted_inode(new_dir)) &&
>   (old_dir != new_dir) &&
>   (!fscrypt_has_permitted_context(new_dir, old_inode) ||
> 

--
Announcing the Oxford Dictionaries API! The API offers world-renowned
dictionary content that is easy and intuitive to access. Sign up for an
account today to start using our lexical data to power your apps and
projects. Get started today and enter our developer competition.
http://sdm.link/oxford
___
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: sync the enc name flags with disk level filename

2017-03-08 Thread Kinglong Mee
On 3/8/2017 20:14, Chao Yu wrote:
> On 2017/3/6 16:11, Kinglong Mee wrote:
>> A cross rename between two encrypted files, the disk level filenames
>> aren't updated for the file_enc_name(to) checking.
>>
>> Also, cross rename between encrypted file and non-encrypted file under
>> a non-encrypted file, the enc name flags should update at same time
>> as the disk level filename.
>>
>> This patch,
>> 1. make sure update the disk level filename in update_dent_inode,
> 
> Doesn't need to do this since tagging lost_pino is enough, later, fsync will
> trigger checkpoint, and then nodes and dents will be persistent with 
> checkpoint,
> so after abnormal power off, roll-forward doesn't need to recover dent from
> inode::filename.

Yes, that's right.
So the update_dent_inode update the disk level is useless, 
the disk level filename will never be used forever? right?

thanks,
Kinglong Mee

> 
> Thanks,
> 
>> 2. a new function exchange_dent_inode for the disk-level filename update,
>> 3. only set the enc name flags in init_inode_metadata.
>>
>> v2, add the missing function define of exchange_dent_inode in f2fs.h
>>
>> Fixes: e7d5545285ed ("f2fs crypto: add filename encryption for roll-forward 
>> recovery")
>> Signed-off-by: Kinglong Mee <kinglong...@gmail.com>
>> ---
>>  fs/f2fs/dir.c| 91 
>> 
>>  fs/f2fs/f2fs.h   |  3 ++
>>  fs/f2fs/inline.c |  2 --
>>  fs/f2fs/namei.c  | 19 ++--
>>  4 files changed, 90 insertions(+), 25 deletions(-)
>>
>> diff --git a/fs/f2fs/dir.c b/fs/f2fs/dir.c
>> index 295a223..b1bb0b1 100644
>> --- a/fs/f2fs/dir.c
>> +++ b/fs/f2fs/dir.c
>> @@ -337,17 +337,93 @@ static void init_dent_inode(const struct qstr *name, 
>> struct page *ipage)
>>  int update_dent_inode(struct inode *inode, struct inode *to,
>>  const struct qstr *name)
>>  {
>> -struct page *page;
>> +struct page *topage = NULL, *page;
>> +struct f2fs_inode *tori;
>> +struct qstr newname = *name;
>> +int err = 0;
>>  
>> -if (file_enc_name(to))
>> +if (file_enc_name(to) && (inode == to))
>>  return 0;
>>  
>>  page = get_node_page(F2FS_I_SB(inode), inode->i_ino);
>>  if (IS_ERR(page))
>>  return PTR_ERR(page);
>>  
>> -init_dent_inode(name, page);
>> +file_clear_enc_name(inode);
>> +if (file_enc_name(to)) {
>> +topage = get_node_page(F2FS_I_SB(to), to->i_ino);
>> +if (IS_ERR(topage)) {
>> +f2fs_put_page(page, 1);
>> +return PTR_ERR(topage);
>> +}
>> +
>> +tori = F2FS_INODE(topage);
>> +newname.name = tori->i_name;
>> +newname.len = tori->i_namelen;
>> +
>> +file_set_enc_name(inode);
>> +}
>> +
>> +init_dent_inode(, page);
>> +
>>  f2fs_put_page(page, 1);
>> +if (file_enc_name(to))
>> +f2fs_put_page(topage, 1);
>> +
>> +return err;
>> +}
>> +
>> +int exchange_dent_inode(struct inode *src, struct inode *dst,
>> +const struct qstr *srcname, const struct qstr *dstname)
>> +{
>> +struct page *srcpage = NULL, *dstpage = NULL;
>> +char tmp_srcname[F2FS_NAME_LEN], tmp_dstname[F2FS_NAME_LEN];
>> +struct qstr new_srcname = *srcname;
>> +struct qstr new_dstname = *dstname;
>> +
>> +if (src == dst)
>> +return 0;
>> +
>> +srcpage = get_node_page(F2FS_I_SB(src), src->i_ino);
>> +if (IS_ERR(srcpage))
>> +return PTR_ERR(srcpage);
>> +
>> +dstpage = get_node_page(F2FS_I_SB(dst), dst->i_ino);
>> +if (IS_ERR(dstpage)) {
>> +f2fs_put_page(srcpage, 1);
>> +return PTR_ERR(dstpage);
>> +}
>> +
>> +f2fs_wait_on_page_writeback(srcpage, NODE, true);
>> +f2fs_wait_on_page_writeback(dstpage, NODE, true);
>> +
>> +file_clear_enc_name(dst);
>> +if (file_enc_name(src)) {
>> +struct f2fs_inode *srcri = F2FS_INODE(srcpage);
>> +
>> +memcpy(tmp_srcname, srcri->i_name, srcri->i_namelen);
>> +new_srcname.name = tmp_srcname;
>> +new_srcname.len = srcri->i_namelen;
>> +
>> +file_set_enc_name(dst);
>> +}
>> +
>> +file_clear_enc_nam

Re: [f2fs-dev] [PATCH v2] f2fs: sync the enc name flags with disk level filename

2017-03-08 Thread Kinglong Mee
On 3/8/2017 03:30, Jaegeuk Kim wrote:
> Hi Kinglong,
> 
> Can we make a testcase in xfstests to check this clearly?
> 1. creat A under encrypted dir
> 2. rename A to B
> 3. fsync B
> 4. power-cut
> 
> Is this your concern?

Yes, it is.
If B isn't exist, rename A to B means create a new A (unlink the old).
B is exist, the inode (include disk node) will be replace by A, but,
for the file_enc_name, the disk i_name/i_namelen isn't updated.

For the rename, A and B lost there parent, so the 3 step will cause checkpoint, 
after that, everything is updated to disk (with the unchanged filename), 
so that the 4 step of power-cut can't cause a roll_forward.

If fsync A for flags the inode and then rename as,
1. creat A and B under encrypted dir
2. fsync A  (after rename, B will be unlink)
3. rename A to B
4. godown 
5. umount/mount

A roll_forward (recover_dentry) happens, the result is same as after setp1,
that's not my needs.

For the IS_CHECKPOINTED flag, after a new created file sync to the disk,
it's cleared, and never appears again, after that a roll_forward of 
recover_dentry will never happen (it means the disk i_name will not be
used forever). Am I right?

If that's right, next update_dent_inode after file created is useless,
we can remove them include the FADVISE_ENC_NAME_BIT.

> 
> Hmm, on-disk filename is used when doing roll-forward recovery, and it seems
> there is a hole in try_to_fix_pino() to recover its pino without filename.
> 
> Like this?
> 
>>From 7efde035d9f930fc63c30b25327e870b021750f3 Mon Sep 17 00:00:00 2001
> From: Jaegeuk Kim <jaeg...@kernel.org>
> Date: Tue, 7 Mar 2017 11:22:45 -0800
> Subject: [PATCH] f2fS: don't allow to get pino when filename is encrypted
> 
> After renaming an encrypted file, we have no way to get its
> encrypted filename from its dentry.
> 
> Signed-off-by: Jaegeuk Kim <jaeg...@kernel.org>
> ---
>  fs/f2fs/file.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
> index e0b2378f8519..852195b3bcce 100644
> --- a/fs/f2fs/file.c
> +++ b/fs/f2fs/file.c
> @@ -110,6 +110,9 @@ static int get_parent_ino(struct inode *inode, nid_t 
> *pino)
>  {
>   struct dentry *dentry;
>  
> + if (file_enc_name(inode))
> + return 0;
> +
>   inode = igrab(inode);
>   dentry = d_find_any_alias(inode);
>   iput(inode);
> 

The renamed inode will lost their parent ino, and try to fix it when fsync.
With the file_enc_name checking, get_parent_ino return 0 without parent ino
for encrypted inode, after that the FADVISE_COLD_BIT will exist forever, 
fsync the encrypted inode causing do_checkpoint every time.

static void try_to_fix_pino(struct inode *inode)
{
struct f2fs_inode_info *fi = F2FS_I(inode);
nid_t pino;

down_write(>i_sem);
if (file_wrong_pino(inode) && inode->i_nlink == 1 &&
    get_parent_ino(inode, )) {
f2fs_i_pino_write(inode, pino);
file_got_pino(inode);
}
up_write(>i_sem);
}

thanks,
Kinglong Mee

--
Announcing the Oxford Dictionaries API! The API offers world-renowned
dictionary content that is easy and intuitive to access. Sign up for an
account today to start using our lexical data to power your apps and
projects. Get started today and enter our developer competition.
http://sdm.link/oxford
___
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: fix the fault of calculating blkstart twice

2017-03-07 Thread Kinglong Mee
On 3/8/2017 09:11, Jaegeuk Kim wrote:
> Hi,
> 
> On 03/04, Kinglong Mee wrote:
>> When the zone type is BLK_ZONE_TYPE_CONVENTIONAL, the blkstart is 
>> calculated twice.
>>
>> Signed-off-by: Kinglong Mee <kinglong...@gmail.com>
>> ---
>>  fs/f2fs/segment.c | 22 +-
>>  1 file changed, 9 insertions(+), 13 deletions(-)
>>
>> diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
>> index 4bd7a8b..ed181d1 100644
>> --- a/fs/f2fs/segment.c
>> +++ b/fs/f2fs/segment.c
>> @@ -772,11 +772,6 @@ static int __f2fs_issue_discard_async(struct 
>> f2fs_sb_info *sbi,
>>  
>>  trace_f2fs_issue_discard(bdev, blkstart, blklen);
>>  
>> -if (sbi->s_ndevs) {
>> -int devi = f2fs_target_device_index(sbi, blkstart);
>> -
>> -blkstart -= FDEV(devi).start_blk;
>> -}
> 
> No, you can't do this, since the blkstart will be used for dc->lstart.
> So, it needs to do like this?

Sorry, I miss that.

But, get_blkz_type() needs the new blkaddr for blkz_type as
"FDEV(i).blkz_type[zno]", so that, the blkaddr must be calculated
in front of __f2fs_issue_discard_zone, just like this?

>From efd182428830898cc31d49f74d4bd2ab7455cec4 Mon Sep 17 00:00:00 2001
From: Kinglong Mee <kinglong...@gmail.com>
Date: Wed, 8 Mar 2017 09:49:53 +0800
Subject: [PATCH] f2fs: fix the fault of calculating blkstart twice

When the zone type is BLK_ZONE_TYPE_CONVENTIONAL, the blkstart is
calculated twice.

Signed-off-by: Kinglong Mee <kinglong...@gmail.com>
Signed-off-by: Jaegeuk Kim <jaeg...@kernel.org>
---
 fs/f2fs/segment.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
index 401f25d..dbd2e7a 100644
--- a/fs/f2fs/segment.c
+++ b/fs/f2fs/segment.c
@@ -816,6 +816,7 @@ static int __f2fs_issue_discard_zone(struct f2fs_sb_info 
*sbi,
struct block_device *bdev, block_t blkstart, block_t blklen)
 {
sector_t sector, nr_sects;
+   block_t lblkstart = blkstart;
int devi = 0;
 
if (sbi->s_ndevs) {
@@ -833,7 +834,7 @@ static int __f2fs_issue_discard_zone(struct f2fs_sb_info 
*sbi,
case BLK_ZONE_TYPE_CONVENTIONAL:
if (!blk_queue_discard(bdev_get_queue(bdev)))
return 0;
-   return __f2fs_issue_discard_async(sbi, bdev, blkstart, blklen);
+   return __f2fs_issue_discard_async(sbi, bdev, lblkstart, blklen);
case BLK_ZONE_TYPE_SEQWRITE_REQ:
case BLK_ZONE_TYPE_SEQWRITE_PREF:
sector = SECTOR_FROM_BLOCK(blkstart);
-- 
2.9.3



--
Announcing the Oxford Dictionaries API! The API offers world-renowned
dictionary content that is easy and intuitive to access. Sign up for an
account today to start using our lexical data to power your apps and
projects. Get started today and enter our developer competition.
http://sdm.link/oxford
___
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel


[f2fs-dev] [PATCH v2] f2fscrypt: add a tool for encryption management in the f2fs filesystem

2017-03-06 Thread Kinglong Mee
It's migrated from e4crypt.
Adds an example to the f2fscrypt manpages.

v2,
1. migrate those micro defines for encrypt to f2fs internal
2. drop unless of libsha etc.

Signed-off-by: Kinglong Mee <kinglong...@gmail.com>
---
 tools/Makefile.am |   5 +-
 tools/f2fscrypt.8 | 102 ++
 tools/f2fscrypt.c | 916 ++
 tools/sha512.c| 323 +++
 4 files changed, 1345 insertions(+), 1 deletion(-)
 create mode 100644 tools/f2fscrypt.8
 create mode 100644 tools/f2fscrypt.c
 create mode 100644 tools/sha512.c

diff --git a/tools/Makefile.am b/tools/Makefile.am
index 69a0bb1..5a9303f 100644
--- a/tools/Makefile.am
+++ b/tools/Makefile.am
@@ -2,7 +2,10 @@
 
 AM_CPPFLAGS = ${libuuid_CFLAGS} -I$(top_srcdir)/include
 AM_CFLAGS = -Wall
-sbin_PROGRAMS = f2fstat fibmap.f2fs parse.f2fs
+sbin_PROGRAMS = f2fstat fibmap.f2fs parse.f2fs f2fscrypt
 f2fstat_SOURCES = f2fstat.c
 fibmap_f2fs_SOURCES = fibmap.c
 parse_f2fs_SOURCES = f2fs_io_parse.c
+f2fscrypt_SOURCES = f2fscrypt.c sha512.c
+f2fscrypt_LDFLAGS = -luuid
+dist_man_MANS = f2fscrypt.8
diff --git a/tools/f2fscrypt.8 b/tools/f2fscrypt.8
new file mode 100644
index 000..a60adc8
--- /dev/null
+++ b/tools/f2fscrypt.8
@@ -0,0 +1,102 @@
+.TH F2FSCRYPT 8
+.SH NAME
+f2fscrypt \- f2fs filesystem encryption utility
+.SH SYNOPSIS
+.B f2fscrypt add_key -S \fR[\fB -k \fIkeyring\fR ] [\fB-v\fR] [\fB-q\fR] [ \fI 
path\fR ... ]
+.br
+.B f2fscrypt new_session
+.br
+.B f2fscrypt get_policy \fIpath\fR ...
+.br
+.B f2fscrypt set_policy \fIpolicy path\fR ...
+.SH DESCRIPTION
+.B f2fscrypt
+performs encryption management for f2fs file systems.
+.SH COMMANDS
+.TP
+.B f2fscrypt add_key -S \fR[\fB -k \fIkeyring\fR ] [\fB-v\fR] [\fB-q\fR] [ \fI 
path\fR ... ]
+Prompts the user for a passphrase and inserts it into the specified
+keyring.  If no keyring is specified, f2fscrypt will use the session
+keyring if it exists or the user session keyring if it does not.
+.IP
+If one or more directory paths are specified, f2fscrypt will try to
+set the policy of those directories to use the key just entered by
+the user.
+.TP
+.B f2fscrypt get_policy \fIpath\fR ...
+Print the policy for the directories specified on the command line.
+.TP
+.B f2fscrypt new_session
+Give the invoking process (typically a shell) a new session keyring,
+discarding its old session keyring.
+.TP
+.B f2fscrypt set_policy \fIpolicy path\fR ...
+Sets the policy for the directories specified on the command line.
+All directories must be empty to set the policy; if the directory
+already has a policy established, f2fscrypt will validate that the
+policy matches what was specified.  A policy is an encryption key
+identifier consisting of 16 hexadecimal characters.
+.SH NOTES
+The target directory must be empty.
+.SH EXAMPLE
+.nf
+Formats a f2fs filesytem that supports encrypt.
+
+.ft R
+# mkfs.f2fs -O encrypt /dev/sdxx
+# mount /dev/sdxx /encrypted/
+# mkdir /encrypted/dir
+
+.nf
+First create the key in the keyring use an simple salt
+(or generate a random salt).
+Then use it to set the policy for the directory to be encrypted.
+
+.ft R
+# f2fscrypt add_key -S 0x1234
+  Enter passphrase (echo disabled):
+  Added key with descriptor [28e21cc0c4393da1]
+
+# f2fscrypt set_policy 28e21cc0c4393da1 /encrypted/dir
+  Key with descriptor [28e21cc0c4393da1] applied to /encrypted/dir.
+
+# touch /encrypted/dir/test.txt
+# ls -l /encrypted/dir/
+  -rw-r--r--. 1 root root 0 Mar  5 21:41 test.txt
+
+.nf
+After each reboot, the same command can be used set the key for
+decryption of the directory and its descendants.
+
+.ft R
+# ls -l /encrypted/dir/
+  -rw-r--r--. 1 root root 0 Mar  5 21:41 zbx7tsUEMLzh+AUVMkQcnB
+
+# f2fscrypt get_policy /encrypted/dir/
+  /encrypted/dir/: 28e21cc0c4393da1
+
+# f2fscrypt add_key -S 0x1234
+  Enter passphrase (echo disabled):
+  Added key with descriptor [28e21cc0c4393da1]
+
+# ls -l /encrypted/dir/
+  -rw-r--r--. 1 root root 0 Mar  5 21:41 test.txt
+
+.nf
+Show process keyrings.
+
+.ft R
+# keyctl show
+  Session Keyring
+84022412 --alswrv  0 0  keyring: _ses
+   204615789 --alswrv  0 65534   \\_ keyring: _uid.0
+   529474961 --alsw-v  0 0   \\_ logon: f2fs:28e21cc0c4393da1
+
+.SH AUTHOR
+Written by Kinglong Mee <kinglong...@gmail.com>,
+Migrated from e4crypt that Written by Michael Halcrow <mhalc...@google.com>,
+Ildar Muslukhov <muslukh...@gmail.com>, and Theodore Ts'o <ty...@mit.edu>
+.SH SEE ALSO
+.BR keyctl (1),
+.BR mkfs.f2fs (8),
+.BR mount (8).
diff --git a/tools/f2fscrypt.c b/tools/f2fscrypt.c
new file mode 100644
index 000..48ea5f6
--- /dev/null
+++ b/tools/f2fscrypt.c
@@ -0,0 +1,916 @@
+/*
+ * f2fscrypt.c - f2fs encryption management utility
+ *
+ * Authors: Kinglong Mee <kinglong...@gmail.com>
+ *
+ * Copied from e4crypt that for ext4 filesystem.
+ * Authors: Michael Halcrow <mhalc...@google.com>,
+ * Ildar Muslukhov <ild...@google.com>
+ */
+
+#ifn

Re: [f2fs-dev] [PATCH] f2fscrypt: add a tool for encryption management in the f2fs filesystem

2017-03-06 Thread Kinglong Mee
On 3/7/2017 09:39, Jaegeuk Kim wrote:
> Hi,
> 
> There are several build errors.
> 
> f2fscrypt.c:90:37: error: ‘FS_KEY_DESCRIPTOR_SIZE’ undeclared here (not in a 
> function)
> #define F2FS_KEY_REF_STR_BUF_SIZE ((FS_KEY_DESCRIPTOR_SIZE * 2) + 1)
> ^
> f2fscrypt.c:206:19: note: in expansion of macro ‘F2FS_KEY_REF_STR_BUF_SIZE’
> char key_ref_str[F2FS_KEY_REF_STR_BUF_SIZE];
> ^
> f2fscrypt.c: In function ‘parse_salt’:
> f2fscrypt.c:319:19: error: ‘FS_IOC_GET_ENCRYPTION_PWSALT’ undeclared (first 
> use in this function)
> ret = ioctl(fd, FS_IOC_GET_ENCRYPTION_PWSALT, );
> 

The kernel-headers on my test is kernel-headers-4.9.13-200.fc25.x86_64, 
the /usr/include/linux/fs.h contains those macro define for ENCRYPTION.

I will migrate those defines for f2fs internal.

thanks,
Kinglong Mee

> and so on.
> 
> On 03/06, Kinglong Mee wrote:
>> It's migrated from e4crypt.
>> Adds an example to the f2fscrypt manpages.
>>
>> Signed-off-by: Kinglong Mee <kinglong...@gmail.com>
>> ---
>>  tools/Makefile.am |   5 +-
>>  tools/f2fscrypt.8 | 102 +++
>>  tools/f2fscrypt.c | 898 
>> ++
>>  tools/sha512.c| 323 
>>  4 files changed, 1327 insertions(+), 1 deletion(-)
>>  create mode 100644 tools/f2fscrypt.8
>>  create mode 100644 tools/f2fscrypt.c
>>  create mode 100644 tools/sha512.c
>>
>> diff --git a/tools/Makefile.am b/tools/Makefile.am
>> index 69a0bb1..7b786db 100644
>> --- a/tools/Makefile.am
>> +++ b/tools/Makefile.am
>> @@ -2,7 +2,10 @@
>>  
>>  AM_CPPFLAGS = ${libuuid_CFLAGS} -I$(top_srcdir)/include
>>  AM_CFLAGS = -Wall
>> -sbin_PROGRAMS = f2fstat fibmap.f2fs parse.f2fs
>> +sbin_PROGRAMS = f2fstat fibmap.f2fs parse.f2fs f2fscrypt
>>  f2fstat_SOURCES = f2fstat.c
>>  fibmap_f2fs_SOURCES = fibmap.c
>>  parse_f2fs_SOURCES = f2fs_io_parse.c
>> +f2fscrypt_SOURCES = f2fscrypt.c sha512.c
>> +f2fscrypt_LDFLAGS = -luuid -lcrypto -lssl
>> +dist_man_MANS = f2fscrypt.8
>> diff --git a/tools/f2fscrypt.8 b/tools/f2fscrypt.8
>> new file mode 100644
>> index 000..a60adc8
>> --- /dev/null
>> +++ b/tools/f2fscrypt.8
>> @@ -0,0 +1,102 @@
>> +.TH F2FSCRYPT 8
>> +.SH NAME
>> +f2fscrypt \- f2fs filesystem encryption utility
>> +.SH SYNOPSIS
>> +.B f2fscrypt add_key -S \fR[\fB -k \fIkeyring\fR ] [\fB-v\fR] [\fB-q\fR] [ 
>> \fI path\fR ... ]
>> +.br
>> +.B f2fscrypt new_session
>> +.br
>> +.B f2fscrypt get_policy \fIpath\fR ...
>> +.br
>> +.B f2fscrypt set_policy \fIpolicy path\fR ...
>> +.SH DESCRIPTION
>> +.B f2fscrypt
>> +performs encryption management for f2fs file systems.
>> +.SH COMMANDS
>> +.TP
>> +.B f2fscrypt add_key -S \fR[\fB -k \fIkeyring\fR ] [\fB-v\fR] [\fB-q\fR] [ 
>> \fI path\fR ... ]
>> +Prompts the user for a passphrase and inserts it into the specified
>> +keyring.  If no keyring is specified, f2fscrypt will use the session
>> +keyring if it exists or the user session keyring if it does not.
>> +.IP
>> +If one or more directory paths are specified, f2fscrypt will try to
>> +set the policy of those directories to use the key just entered by
>> +the user.
>> +.TP
>> +.B f2fscrypt get_policy \fIpath\fR ...
>> +Print the policy for the directories specified on the command line.
>> +.TP
>> +.B f2fscrypt new_session
>> +Give the invoking process (typically a shell) a new session keyring,
>> +discarding its old session keyring.
>> +.TP
>> +.B f2fscrypt set_policy \fIpolicy path\fR ...
>> +Sets the policy for the directories specified on the command line.
>> +All directories must be empty to set the policy; if the directory
>> +already has a policy established, f2fscrypt will validate that the
>> +policy matches what was specified.  A policy is an encryption key
>> +identifier consisting of 16 hexadecimal characters.
>> +.SH NOTES
>> +The target directory must be empty.
>> +.SH EXAMPLE
>> +.nf
>> +Formats a f2fs filesytem that supports encrypt.
>> +
>> +.ft R
>> +# mkfs.f2fs -O encrypt /dev/sdxx
>> +# mount /dev/sdxx /encrypted/
>> +# mkdir /encrypted/dir
>> +
>> +.nf
>> +First create the key in the keyring use an simple salt
>> +(or generate a random salt).
>> +Then use it to set the policy for the directory to be encrypted.
>> +
>> +.ft R
>> +# f2fscrypt add_key -S 0x1234
>> +  Enter passphrase (echo disabled):
>> +  Added key with descriptor [28e21cc0c4393da1]
>> +
>> +# f2fscrypt set_poli

Re: [f2fs-dev] [PATCH 2/2] f2fs: avoid new_inode's flags overwrite the old_node

2017-03-06 Thread Kinglong Mee
On 3/6/2017 19:06, Chao Yu wrote:
> On 2017/3/4 21:44, Kinglong Mee wrote:
>> Note, rename with old_inode (enc_name) and new_inode (no_enc_name),
>> the result will be old_indoe(enc_name) and new_inode(enc_name).
> 
> IIRC, we don't allow rename files in different dirs that:
> 1. One dir is encrypted, another is not encrypted;
> 2. or src/dst dir has different encryption policy.
> 
> So that will not happen, right?

Yes, you are right.
This patch is bad one, please ignore this and check my latest fix, 
[PATCH v2] f2fs: sync the enc name flags with disk level filename

thanks,
Kinglong Mee
> 
> Thanks,
> 
>>
>> Needs swap the enc_name flags?
>> If needed, this patch needs update of clear the flags.
>> otherwise, this patch only fix the logic with any result changing.
>>
>> Signed-off-by: Kinglong Mee <kinglong...@gmail.com>
>> ---
>>  fs/f2fs/namei.c | 12 
>>  1 file changed, 8 insertions(+), 4 deletions(-)
>>
>> diff --git a/fs/f2fs/namei.c b/fs/f2fs/namei.c
>> index 3231a0a..db2ab7f 100644
>> --- a/fs/f2fs/namei.c
>> +++ b/fs/f2fs/namei.c
>> @@ -846,6 +846,7 @@ static int f2fs_cross_rename(struct inode *old_dir, 
>> struct dentry *old_dentry,
>>  struct page *old_page, *new_page;
>>  struct f2fs_dir_entry *old_dir_entry = NULL, *new_dir_entry = NULL;
>>  struct f2fs_dir_entry *old_entry, *new_entry;
>> +bool old_inode_enc = false, new_inode_enc = false;
>>  int old_nlink = 0, new_nlink = 0;
>>  int err = -ENOENT;
>>  
>> @@ -917,17 +918,16 @@ static int f2fs_cross_rename(struct inode *old_dir, 
>> struct dentry *old_dentry,
>>  
>>  f2fs_lock_op(sbi);
>>  
>> +old_inode_enc = file_enc_name(old_inode);
>> +new_inode_enc = file_enc_name(new_inode);
>> +
>>  err = update_dent_inode(old_inode, new_inode, _dentry->d_name);
>>  if (err)
>>  goto out_unlock;
>> -if (file_enc_name(new_inode))
>> -file_set_enc_name(old_inode);
>>  
>>  err = update_dent_inode(new_inode, old_inode, _dentry->d_name);
>>  if (err)
>>  goto out_undo;
>> -if (file_enc_name(old_inode))
>> -file_set_enc_name(new_inode);
>>  
>>  /* update ".." directory entry info of old dentry */
>>  if (old_dir_entry)
>> @@ -942,6 +942,8 @@ static int f2fs_cross_rename(struct inode *old_dir, 
>> struct dentry *old_dentry,
>>  
>>  down_write(_I(old_inode)->i_sem);
>>  file_lost_pino(old_inode);
>> +if (new_inode_enc)
>> +file_set_enc_name(old_inode);
>>  up_write(_I(old_inode)->i_sem);
>>  
>>  old_dir->i_ctime = current_time(old_dir);
>> @@ -957,6 +959,8 @@ static int f2fs_cross_rename(struct inode *old_dir, 
>> struct dentry *old_dentry,
>>  
>>  down_write(_I(new_inode)->i_sem);
>>  file_lost_pino(new_inode);
>> +if (old_inode_enc)
>> +file_set_enc_name(new_inode);
>>  up_write(_I(new_inode)->i_sem);
>>  
>>  new_dir->i_ctime = current_time(new_dir);
>>
> 
> 

--
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 v2] f2fs: sync the enc name flags with disk level filename

2017-03-06 Thread Kinglong Mee
A cross rename between two encrypted files, the disk level filenames
aren't updated for the file_enc_name(to) checking.

Also, cross rename between encrypted file and non-encrypted file under
a non-encrypted file, the enc name flags should update at same time
as the disk level filename.

This patch,
1. make sure update the disk level filename in update_dent_inode,
2. a new function exchange_dent_inode for the disk-level filename update,
3. only set the enc name flags in init_inode_metadata.

v2, add the missing function define of exchange_dent_inode in f2fs.h

Fixes: e7d5545285ed ("f2fs crypto: add filename encryption for roll-forward 
recovery")
Signed-off-by: Kinglong Mee <kinglong...@gmail.com>
---
 fs/f2fs/dir.c| 91 
 fs/f2fs/f2fs.h   |  3 ++
 fs/f2fs/inline.c |  2 --
 fs/f2fs/namei.c  | 19 ++--
 4 files changed, 90 insertions(+), 25 deletions(-)

diff --git a/fs/f2fs/dir.c b/fs/f2fs/dir.c
index 295a223..b1bb0b1 100644
--- a/fs/f2fs/dir.c
+++ b/fs/f2fs/dir.c
@@ -337,17 +337,93 @@ static void init_dent_inode(const struct qstr *name, 
struct page *ipage)
 int update_dent_inode(struct inode *inode, struct inode *to,
const struct qstr *name)
 {
-   struct page *page;
+   struct page *topage = NULL, *page;
+   struct f2fs_inode *tori;
+   struct qstr newname = *name;
+   int err = 0;
 
-   if (file_enc_name(to))
+   if (file_enc_name(to) && (inode == to))
return 0;
 
page = get_node_page(F2FS_I_SB(inode), inode->i_ino);
if (IS_ERR(page))
return PTR_ERR(page);
 
-   init_dent_inode(name, page);
+   file_clear_enc_name(inode);
+   if (file_enc_name(to)) {
+   topage = get_node_page(F2FS_I_SB(to), to->i_ino);
+   if (IS_ERR(topage)) {
+   f2fs_put_page(page, 1);
+   return PTR_ERR(topage);
+   }
+
+   tori = F2FS_INODE(topage);
+   newname.name = tori->i_name;
+   newname.len = tori->i_namelen;
+
+   file_set_enc_name(inode);
+   }
+
+   init_dent_inode(, page);
+
f2fs_put_page(page, 1);
+   if (file_enc_name(to))
+   f2fs_put_page(topage, 1);
+
+   return err;
+}
+
+int exchange_dent_inode(struct inode *src, struct inode *dst,
+   const struct qstr *srcname, const struct qstr *dstname)
+{
+   struct page *srcpage = NULL, *dstpage = NULL;
+   char tmp_srcname[F2FS_NAME_LEN], tmp_dstname[F2FS_NAME_LEN];
+   struct qstr new_srcname = *srcname;
+   struct qstr new_dstname = *dstname;
+
+   if (src == dst)
+   return 0;
+
+   srcpage = get_node_page(F2FS_I_SB(src), src->i_ino);
+   if (IS_ERR(srcpage))
+   return PTR_ERR(srcpage);
+
+   dstpage = get_node_page(F2FS_I_SB(dst), dst->i_ino);
+   if (IS_ERR(dstpage)) {
+   f2fs_put_page(srcpage, 1);
+   return PTR_ERR(dstpage);
+   }
+
+   f2fs_wait_on_page_writeback(srcpage, NODE, true);
+   f2fs_wait_on_page_writeback(dstpage, NODE, true);
+
+   file_clear_enc_name(dst);
+   if (file_enc_name(src)) {
+   struct f2fs_inode *srcri = F2FS_INODE(srcpage);
+
+   memcpy(tmp_srcname, srcri->i_name, srcri->i_namelen);
+   new_srcname.name = tmp_srcname;
+   new_srcname.len = srcri->i_namelen;
+
+   file_set_enc_name(dst);
+   }
+
+   file_clear_enc_name(src);
+   if (file_enc_name(dst)) {
+   struct f2fs_inode *dstri = F2FS_INODE(dstpage);
+
+   memcpy(tmp_dstname, dstri->i_name, dstri->i_namelen);
+   new_dstname.name = tmp_dstname;
+   new_dstname.len = dstri->i_namelen;
+
+   file_set_enc_name(src);
+   }
+
+   init_dent_inode(_dstname, srcpage);
+   init_dent_inode(_srcname, dstpage);
+
+   f2fs_put_page(srcpage, 1);
+   f2fs_put_page(dstpage, 1);
 
return 0;
 }
@@ -435,9 +511,14 @@ struct page *init_inode_metadata(struct inode *inode, 
struct inode *dir,
set_cold_node(inode, page);
}
 
-   if (new_name)
+   if (new_name) {
init_dent_inode(new_name, page);
 
+   file_clear_enc_name(inode);
+   if (f2fs_encrypted_inode(dir))
+   file_set_enc_name(inode);
+   }
+
/*
 * This file should be checkpointed during fsync.
 * We lost i_pino from now on.
@@ -596,8 +677,6 @@ int f2fs_add_regular_entry(struct inode *dir, const struct 
qstr *new_name,
err = PTR_ERR(page);
goto fail;
}
-   if (f2fs_encrypted_inode(dir))
-   file_set_enc_name(inode);
}
 
make_dentry_ptr

[f2fs-dev] [PATCH] f2fscrypt: add a tool for encryption management in the f2fs filesystem

2017-03-05 Thread Kinglong Mee
It's migrated from e4crypt.
Adds an example to the f2fscrypt manpages.

Signed-off-by: Kinglong Mee <kinglong...@gmail.com>
---
 tools/Makefile.am |   5 +-
 tools/f2fscrypt.8 | 102 +++
 tools/f2fscrypt.c | 898 ++
 tools/sha512.c| 323 
 4 files changed, 1327 insertions(+), 1 deletion(-)
 create mode 100644 tools/f2fscrypt.8
 create mode 100644 tools/f2fscrypt.c
 create mode 100644 tools/sha512.c

diff --git a/tools/Makefile.am b/tools/Makefile.am
index 69a0bb1..7b786db 100644
--- a/tools/Makefile.am
+++ b/tools/Makefile.am
@@ -2,7 +2,10 @@
 
 AM_CPPFLAGS = ${libuuid_CFLAGS} -I$(top_srcdir)/include
 AM_CFLAGS = -Wall
-sbin_PROGRAMS = f2fstat fibmap.f2fs parse.f2fs
+sbin_PROGRAMS = f2fstat fibmap.f2fs parse.f2fs f2fscrypt
 f2fstat_SOURCES = f2fstat.c
 fibmap_f2fs_SOURCES = fibmap.c
 parse_f2fs_SOURCES = f2fs_io_parse.c
+f2fscrypt_SOURCES = f2fscrypt.c sha512.c
+f2fscrypt_LDFLAGS = -luuid -lcrypto -lssl
+dist_man_MANS = f2fscrypt.8
diff --git a/tools/f2fscrypt.8 b/tools/f2fscrypt.8
new file mode 100644
index 000..a60adc8
--- /dev/null
+++ b/tools/f2fscrypt.8
@@ -0,0 +1,102 @@
+.TH F2FSCRYPT 8
+.SH NAME
+f2fscrypt \- f2fs filesystem encryption utility
+.SH SYNOPSIS
+.B f2fscrypt add_key -S \fR[\fB -k \fIkeyring\fR ] [\fB-v\fR] [\fB-q\fR] [ \fI 
path\fR ... ]
+.br
+.B f2fscrypt new_session
+.br
+.B f2fscrypt get_policy \fIpath\fR ...
+.br
+.B f2fscrypt set_policy \fIpolicy path\fR ...
+.SH DESCRIPTION
+.B f2fscrypt
+performs encryption management for f2fs file systems.
+.SH COMMANDS
+.TP
+.B f2fscrypt add_key -S \fR[\fB -k \fIkeyring\fR ] [\fB-v\fR] [\fB-q\fR] [ \fI 
path\fR ... ]
+Prompts the user for a passphrase and inserts it into the specified
+keyring.  If no keyring is specified, f2fscrypt will use the session
+keyring if it exists or the user session keyring if it does not.
+.IP
+If one or more directory paths are specified, f2fscrypt will try to
+set the policy of those directories to use the key just entered by
+the user.
+.TP
+.B f2fscrypt get_policy \fIpath\fR ...
+Print the policy for the directories specified on the command line.
+.TP
+.B f2fscrypt new_session
+Give the invoking process (typically a shell) a new session keyring,
+discarding its old session keyring.
+.TP
+.B f2fscrypt set_policy \fIpolicy path\fR ...
+Sets the policy for the directories specified on the command line.
+All directories must be empty to set the policy; if the directory
+already has a policy established, f2fscrypt will validate that the
+policy matches what was specified.  A policy is an encryption key
+identifier consisting of 16 hexadecimal characters.
+.SH NOTES
+The target directory must be empty.
+.SH EXAMPLE
+.nf
+Formats a f2fs filesytem that supports encrypt.
+
+.ft R
+# mkfs.f2fs -O encrypt /dev/sdxx
+# mount /dev/sdxx /encrypted/
+# mkdir /encrypted/dir
+
+.nf
+First create the key in the keyring use an simple salt
+(or generate a random salt).
+Then use it to set the policy for the directory to be encrypted.
+
+.ft R
+# f2fscrypt add_key -S 0x1234
+  Enter passphrase (echo disabled):
+  Added key with descriptor [28e21cc0c4393da1]
+
+# f2fscrypt set_policy 28e21cc0c4393da1 /encrypted/dir
+  Key with descriptor [28e21cc0c4393da1] applied to /encrypted/dir.
+
+# touch /encrypted/dir/test.txt
+# ls -l /encrypted/dir/
+  -rw-r--r--. 1 root root 0 Mar  5 21:41 test.txt
+
+.nf
+After each reboot, the same command can be used set the key for
+decryption of the directory and its descendants.
+
+.ft R
+# ls -l /encrypted/dir/
+  -rw-r--r--. 1 root root 0 Mar  5 21:41 zbx7tsUEMLzh+AUVMkQcnB
+
+# f2fscrypt get_policy /encrypted/dir/
+  /encrypted/dir/: 28e21cc0c4393da1
+
+# f2fscrypt add_key -S 0x1234
+  Enter passphrase (echo disabled):
+  Added key with descriptor [28e21cc0c4393da1]
+
+# ls -l /encrypted/dir/
+  -rw-r--r--. 1 root root 0 Mar  5 21:41 test.txt
+
+.nf
+Show process keyrings.
+
+.ft R
+# keyctl show
+  Session Keyring
+84022412 --alswrv  0 0  keyring: _ses
+   204615789 --alswrv  0 65534   \\_ keyring: _uid.0
+   529474961 --alsw-v  0 0   \\_ logon: f2fs:28e21cc0c4393da1
+
+.SH AUTHOR
+Written by Kinglong Mee <kinglong...@gmail.com>,
+Migrated from e4crypt that Written by Michael Halcrow <mhalc...@google.com>,
+Ildar Muslukhov <muslukh...@gmail.com>, and Theodore Ts'o <ty...@mit.edu>
+.SH SEE ALSO
+.BR keyctl (1),
+.BR mkfs.f2fs (8),
+.BR mount (8).
diff --git a/tools/f2fscrypt.c b/tools/f2fscrypt.c
new file mode 100644
index 000..3467446
--- /dev/null
+++ b/tools/f2fscrypt.c
@@ -0,0 +1,898 @@
+/*
+ * f2fscrypt.c - f2fs encryption management utility
+ *
+ * Authors: Kinglong Mee <kinglong...@gmail.com>
+ *
+ * Copied from e4crypt that for ext4 filesystem.
+ * Authors: Michael Halcrow <mhalc...@google.com>,
+ * Ildar Muslukhov <ild...@google.com>
+ */
+
+#ifndef _LARGEFILE_SOURCE
+#define _LARGEFILE_SOURCE
+#endif
+
+#ifndef _LARGEFI

[f2fs-dev] [PATCH] f2fs: sync the enc name flags with disk level filename

2017-03-05 Thread Kinglong Mee
A cross rename between two encrypted files, the disk level filenames 
aren't updated for the file_enc_name(to) checking.

Also, cross rename between encrypted file and non-encrypted file under
a non-encrypted file, the enc name flags should update at same time
as the disk level filename.

This patch,
1. make sure update the disk level filename in update_dent_inode,
2. a new function exchange_dent_inode for the disk-level filename update,
3. only set the enc name flags in init_inode_metadata.

Fixes: e7d5545285ed ("f2fs crypto: add filename encryption for roll-forward 
recovery")
Signed-off-by: Kinglong Mee <kinglong...@gmail.com>
---
 fs/f2fs/dir.c| 91 
 fs/f2fs/f2fs.h   |  1 +
 fs/f2fs/inline.c |  2 --
 fs/f2fs/namei.c  | 19 ++--
 4 files changed, 88 insertions(+), 25 deletions(-)

diff --git a/fs/f2fs/dir.c b/fs/f2fs/dir.c
index 295a223..b1bb0b1 100644
--- a/fs/f2fs/dir.c
+++ b/fs/f2fs/dir.c
@@ -337,17 +337,93 @@ static void init_dent_inode(const struct qstr *name, 
struct page *ipage)
 int update_dent_inode(struct inode *inode, struct inode *to,
const struct qstr *name)
 {
-   struct page *page;
+   struct page *topage = NULL, *page;
+   struct f2fs_inode *tori;
+   struct qstr newname = *name;
+   int err = 0;
 
-   if (file_enc_name(to))
+   if (file_enc_name(to) && (inode == to))
return 0;
 
page = get_node_page(F2FS_I_SB(inode), inode->i_ino);
if (IS_ERR(page))
return PTR_ERR(page);
 
-   init_dent_inode(name, page);
+   file_clear_enc_name(inode);
+   if (file_enc_name(to)) {
+   topage = get_node_page(F2FS_I_SB(to), to->i_ino);
+   if (IS_ERR(topage)) {
+   f2fs_put_page(page, 1);
+   return PTR_ERR(topage);
+   }
+
+   tori = F2FS_INODE(topage);
+   newname.name = tori->i_name;
+   newname.len = tori->i_namelen;
+
+   file_set_enc_name(inode);
+   }
+
+   init_dent_inode(, page);
+
f2fs_put_page(page, 1);
+   if (file_enc_name(to))
+   f2fs_put_page(topage, 1);
+
+   return err;
+}
+
+int exchange_dent_inode(struct inode *src, struct inode *dst,
+   const struct qstr *srcname, const struct qstr *dstname)
+{
+   struct page *srcpage = NULL, *dstpage = NULL;
+   char tmp_srcname[F2FS_NAME_LEN], tmp_dstname[F2FS_NAME_LEN];
+   struct qstr new_srcname = *srcname;
+   struct qstr new_dstname = *dstname;
+
+   if (src == dst)
+   return 0;
+
+   srcpage = get_node_page(F2FS_I_SB(src), src->i_ino);
+   if (IS_ERR(srcpage))
+   return PTR_ERR(srcpage);
+
+   dstpage = get_node_page(F2FS_I_SB(dst), dst->i_ino);
+   if (IS_ERR(dstpage)) {
+   f2fs_put_page(srcpage, 1);
+   return PTR_ERR(dstpage);
+   }
+
+   f2fs_wait_on_page_writeback(srcpage, NODE, true);
+   f2fs_wait_on_page_writeback(dstpage, NODE, true);
+
+   file_clear_enc_name(dst);
+   if (file_enc_name(src)) {
+   struct f2fs_inode *srcri = F2FS_INODE(srcpage);
+
+   memcpy(tmp_srcname, srcri->i_name, srcri->i_namelen);
+   new_srcname.name = tmp_srcname;
+   new_srcname.len = srcri->i_namelen;
+
+   file_set_enc_name(dst);
+   }
+
+   file_clear_enc_name(src);
+   if (file_enc_name(dst)) {
+   struct f2fs_inode *dstri = F2FS_INODE(dstpage);
+
+   memcpy(tmp_dstname, dstri->i_name, dstri->i_namelen);
+   new_dstname.name = tmp_dstname;
+   new_dstname.len = dstri->i_namelen;
+
+   file_set_enc_name(src);
+   }
+
+   init_dent_inode(_dstname, srcpage);
+   init_dent_inode(_srcname, dstpage);
+
+   f2fs_put_page(srcpage, 1);
+   f2fs_put_page(dstpage, 1);
 
return 0;
 }
@@ -435,9 +511,14 @@ struct page *init_inode_metadata(struct inode *inode, 
struct inode *dir,
set_cold_node(inode, page);
}
 
-   if (new_name)
+   if (new_name) {
init_dent_inode(new_name, page);
 
+   file_clear_enc_name(inode);
+   if (f2fs_encrypted_inode(dir))
+   file_set_enc_name(inode);
+   }
+
/*
 * This file should be checkpointed during fsync.
 * We lost i_pino from now on.
@@ -596,8 +677,6 @@ int f2fs_add_regular_entry(struct inode *dir, const struct 
qstr *new_name,
err = PTR_ERR(page);
goto fail;
}
-   if (f2fs_encrypted_inode(dir))
-   file_set_enc_name(inode);
}
 
make_dentry_ptr(NULL, , (void *)dentry_blk, 1);
diff --git a/fs/f2fs/f2fs.h b/fs/f2

[f2fs-dev] [PATCH v3 2/2] mkfs.f2fs: check overwrite before make filesystem

2017-03-05 Thread Kinglong Mee
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.

v3, add the missing update of SYNOPSIS
v2, add the manpages description of -f.

Signed-off-by: Kinglong Mee <kinglong...@gmail.com>
---
 configure.ac| 20 +--
 man/mkfs.f2fs.8 |  8 +
 mkfs/Makefile.am|  4 +--
 mkfs/f2fs_format_main.c | 90 -
 4 files changed, 117 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/man/mkfs.f2fs.8 b/man/mkfs.f2fs.8
index 3ae9f3a..c2f9c86 100644
--- a/man/mkfs.f2fs.8
+++ b/man/mkfs.f2fs.8
@@ -24,6 +24,9 @@ mkfs.f2fs \- create an F2FS file system
 .I extension-list
 ]
 [
+.B \-f
+]
+[
 .B \-l
 .I volume-label
 ]
@@ -87,6 +90,11 @@ The data of files having those extensions will be stored to 
the cold log.
 The default list includes most of multimedia file extensions such as jpg, gif,
 mpeg, mkv, and so on.
 .TP
+.BI \-f
+Force overwrite when an existing filesystem is detected on the device.
+By default, mkfs.f2fs will not write to the device if it suspects that
+there is a filesystem or partition table on the device already.
+.TP
 .BI \-l " volume-label"
 Specify the volume label to the partition mounted as F2FS.
 .TP
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 0ac87ed..482506a 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()
 {
@@ -31,6 +37,7 @@ static void mkfs_usage()
MSG(0, "  -c [device path] up to 7 devices excepts meta device\n");
MSG(0, "  -d debug level [default:0]\n");
MSG(0, "  -e [extension list] e.g. \"mp3,gif,mov\"\n");
+   MSG(0, "  -f force overwrite the exist filesystem\n");
MSG(0, "  -l label\n");
MSG(0, "  -m support zoned block device [default:0]\n");
MSG(0, "  -o overprovision ratio [default:5]\n");
@@ -72,7 +79,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 +135,9 @@ static void f2fs_parse_options(int argc, char *argv[])
case 't':
c.trim = atoi(optarg);
break;
+   case 'f':
+   

[f2fs-dev] [PATCH v3 1/2] mkfs.f2fs: clearfiy the help message and manpages

2017-03-05 Thread Kinglong Mee
Add some missing options in manpages, also order those options.

v3, add the missing update of SYNOPSIS

Signed-off-by: Kinglong Mee <kinglong...@gmail.com>
---
 man/mkfs.f2fs.8 | 67 -
 mkfs/f2fs_format_main.c |  6 ++---
 2 files changed, 52 insertions(+), 21 deletions(-)

diff --git a/man/mkfs.f2fs.8 b/man/mkfs.f2fs.8
index bdb9755..3ae9f3a 100644
--- a/man/mkfs.f2fs.8
+++ b/man/mkfs.f2fs.8
@@ -16,28 +16,42 @@ mkfs.f2fs \- create an F2FS file system
 .I device
 ]
 [
+.B \-d
+.I debugging-level
+]
+[
+.B \-e
+.I extension-list
+]
+[
 .B \-l
 .I volume-label
 ]
 [
+.B \-m
+]
+[
 .B \-o
 .I overprovision-ratio-percentage
 ]
 [
-.B \-s
-.I #-of-segments-per-section
+.B \-O
+.I feature-list
 ]
 [
-.B \-z
-.I #-of-sections-per-zone
+.B \-q
 ]
 [
-.B \-e
-.I extenstion-list
+.B \-s
+.I #-of-segments-per-section
 ]
 [
-.B \-d
-.I debugging-level
+.B \-t
+.I nodiscard/discard
+]
+[
+.B \-z
+.I #-of-sections-per-zone
 ]
 .I device
 .I [sectors]
@@ -63,34 +77,51 @@ The default value is 1.
 Build f2fs with this device additionally, so that user can see all
 the devices as one big volume.
 .TP
+.BI \-d " debug-level"
+Specify the level of debugging options.
+The default number is 0, which shows basic debugging messages.
+.TP
+.BI \-e " extension-list"
+Specify a file extension list in order f2fs to treat them as cold files.
+The data of files having those extensions will be stored to the cold log.
+The default list includes most of multimedia file extensions such as jpg, gif,
+mpeg, mkv, and so on.
+.TP
 .BI \-l " volume-label"
 Specify the volume label to the partition mounted as F2FS.
 .TP
+.BI \-m
+Specify f2fs filesystem to supports the block zoned feature.
+Without it, the filesystem isn't supports the feature.
+.TP
 .BI \-o " overprovision-ratio-percentage"
 Specify the percentage over the volume size for overprovision area. This area
 is hidden to users, and utilized by F2FS cleaner. If not specified, the best
 number will be assigned automatically accoring to the partition size.
 .TP
+.BI \-O " feature-list"
+Specify a feature list in order f2fs filesystem will supports.
+e.g "encrypt" and so on.
+.TP
+.BI \-q
+Quiet mode.
+With it, mkfs.f2fs does not show any messages include the basic messages.
+.TP
 .BI \-s " #-of-segments-per-section"
 Specify the number of segments per section. A section consists of
 multiple consecutive segments, and is the unit of garbage collection.
 The default number is 1, which means one segment is assigned to a section.
 .TP
+.BI \-t " nodiscard/discard"
+Specify 1 or 0 to enable/disable discard policy.
+If the value is equal to 1, discard policy is enabled, otherwise is disable.
+The default value is 1.
+.TP
 .BI \-z " #-of-sections-per-zone"
 Specify the number of sections per zone. A zone consists of multiple sections.
 F2FS allocates segments for active logs with separated zones as much as 
possible.
 The default number is 1, which means a zone consists of one section.
 .TP
-.BI \-e " extension-list"
-Specify a file extension list in order f2fs to treat them as cold files.
-The data of files having those extensions will be stored to the cold log.
-The default list includes most of multimedia file extensions such as jpg, gif,
-mpeg, mkv, and so on.
-.TP
-.BI \-d " debug-level"
-Specify the level of debugging options.
-The default number is 0, which shows basic debugging messages.
-.TP
 .SH AUTHOR
 This version of
 .B mkfs.f2fs
diff --git a/mkfs/f2fs_format_main.c b/mkfs/f2fs_format_main.c
index 5bb1faf..0ac87ed 100644
--- a/mkfs/f2fs_format_main.c
+++ b/mkfs/f2fs_format_main.c
@@ -32,13 +32,13 @@ static void mkfs_usage()
MSG(0, "  -d debug level [default:0]\n");
MSG(0, "  -e [extension list] e.g. \"mp3,gif,mov\"\n");
MSG(0, "  -l label\n");
+   MSG(0, "  -m support zoned block device [default:0]\n");
MSG(0, "  -o overprovision ratio [default:5]\n");
-   MSG(0, "  -O set feature\n");
+   MSG(0, "  -O [feature list] e.g. \"encrypt\"\n");
MSG(0, "  -q quiet mode\n");
MSG(0, "  -s # of segments per section [default:1]\n");
-   MSG(0, "  -z # of sections per zone [default:1]\n");
MSG(0, "  -t 0: nodiscard, 1: discard [default:1]\n");
-   MSG(0, "  -m support zoned block device [default:0]\n");
+   MSG(0, "  -z # of sections per zone [default:1]\n");
MSG(0, "sectors: number of sectors. [default: determined by device 
size]\n");
exit(1);
 }
-- 
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


Re: [f2fs-dev] [PATCH 2/2] f2fs: avoid new_inode's flags overwrite the old_node

2017-03-05 Thread Kinglong Mee
On 3/4/2017 21:44, Kinglong Mee wrote:
> Note, rename with old_inode (enc_name) and new_inode (no_enc_name),
> the result will be old_indoe(enc_name) and new_inode(enc_name).
> 
> Needs swap the enc_name flags?
> If needed, this patch needs update of clear the flags.
> otherwise, this patch only fix the logic with any result changing.

In fscrypt_has_permitted_context(), 

187 /* no restrictions if the parent directory is not encrypted */
188 if (!parent->i_sb->s_cop->is_encrypted(parent))
189 return 1;
190 /* if the child directory is not encrypted, this is always a 
problem */
191 if (!parent->i_sb->s_cop->is_encrypted(child))
192 return 0;

Move an encrypted file to an non-encrypted directory is allowed, but,
move an non-encrypted file to an encrypted directory is not allowed.

So that, the cross rename between an encrypted file and an non-encrypted file
is not allowed, is it right?

If that's right, the flags setting should be removed here (cross rename), it's 
needless.
And, only update the flags for normal rename in f2fs_rename().

Also, after commit e7d5545285ed
("f2fs crypto: add filename encryption for roll-forward recovery") the cross 
rename of
encrypted file don't change they filename in raw inode.

Please ignore this patch, I will resolve the above problem and resend new patch.

thanks,
Kinglong Mee

> 
> Signed-off-by: Kinglong Mee <kinglong...@gmail.com>
> ---
>  fs/f2fs/namei.c | 12 
>  1 file changed, 8 insertions(+), 4 deletions(-)
> 
> diff --git a/fs/f2fs/namei.c b/fs/f2fs/namei.c
> index 3231a0a..db2ab7f 100644
> --- a/fs/f2fs/namei.c
> +++ b/fs/f2fs/namei.c
> @@ -846,6 +846,7 @@ static int f2fs_cross_rename(struct inode *old_dir, 
> struct dentry *old_dentry,
>   struct page *old_page, *new_page;
>   struct f2fs_dir_entry *old_dir_entry = NULL, *new_dir_entry = NULL;
>   struct f2fs_dir_entry *old_entry, *new_entry;
> + bool old_inode_enc = false, new_inode_enc = false;
>   int old_nlink = 0, new_nlink = 0;
>   int err = -ENOENT;
>  
> @@ -917,17 +918,16 @@ static int f2fs_cross_rename(struct inode *old_dir, 
> struct dentry *old_dentry,
>  
>   f2fs_lock_op(sbi);
>  
> + old_inode_enc = file_enc_name(old_inode);
> + new_inode_enc = file_enc_name(new_inode);
> +
>   err = update_dent_inode(old_inode, new_inode, _dentry->d_name);
>   if (err)
>   goto out_unlock;
> - if (file_enc_name(new_inode))
> - file_set_enc_name(old_inode);
>  
>   err = update_dent_inode(new_inode, old_inode, _dentry->d_name);
>   if (err)
>   goto out_undo;
> - if (file_enc_name(old_inode))
> - file_set_enc_name(new_inode);
>  
>   /* update ".." directory entry info of old dentry */
>   if (old_dir_entry)
> @@ -942,6 +942,8 @@ static int f2fs_cross_rename(struct inode *old_dir, 
> struct dentry *old_dentry,
>  
>   down_write(_I(old_inode)->i_sem);
>   file_lost_pino(old_inode);
> + if (new_inode_enc)
> + file_set_enc_name(old_inode);
>   up_write(_I(old_inode)->i_sem);
>  
>   old_dir->i_ctime = current_time(old_dir);
> @@ -957,6 +959,8 @@ static int f2fs_cross_rename(struct inode *old_dir, 
> struct dentry *old_dentry,
>  
>   down_write(_I(new_inode)->i_sem);
>   file_lost_pino(new_inode);
> + if (old_inode_enc)
> + file_set_enc_name(new_inode);
>   up_write(_I(new_inode)->i_sem);
>  
>   new_dir->i_ctime = current_time(new_dir);
> 

--
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] f2fs: make sure trace all f2fs_issue_flush

2017-03-04 Thread Kinglong Mee
The root device's issue flush trace is missing,
add it and tracing the result from submit.

Fixes d50aaeec90 ("f2fs: show actual device info in tracepoints")
Signed-off-by: Kinglong Mee <kinglong...@gmail.com>
---
 fs/f2fs/segment.c   | 24 +---
 include/trace/events/f2fs.h | 11 +++
 2 files changed, 20 insertions(+), 15 deletions(-)

diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
index ed181d1..94bc8ac 100644
--- a/fs/f2fs/segment.c
+++ b/fs/f2fs/segment.c
@@ -411,7 +411,8 @@ void f2fs_balance_fs_bg(struct f2fs_sb_info *sbi)
}
 }
 
-static int __submit_flush_wait(struct block_device *bdev)
+static int __submit_flush_wait(struct f2fs_sb_info *sbi,
+   struct block_device *bdev)
 {
struct bio *bio = f2fs_bio_alloc(0);
int ret;
@@ -420,23 +421,24 @@ static int __submit_flush_wait(struct block_device *bdev)
bio->bi_bdev = bdev;
ret = submit_bio_wait(bio);
bio_put(bio);
+
+   trace_f2fs_issue_flush(bdev, test_opt(sbi, NOBARRIER),
+   test_opt(sbi, FLUSH_MERGE), ret);
return ret;
 }
 
 static int submit_flush_wait(struct f2fs_sb_info *sbi)
 {
-   int ret = __submit_flush_wait(sbi->sb->s_bdev);
+   int ret = __submit_flush_wait(sbi, sbi->sb->s_bdev);
int i;
 
-   if (sbi->s_ndevs && !ret) {
-   for (i = 1; i < sbi->s_ndevs; i++) {
-   trace_f2fs_issue_flush(FDEV(i).bdev,
-   test_opt(sbi, NOBARRIER),
-   test_opt(sbi, FLUSH_MERGE));
-   ret = __submit_flush_wait(FDEV(i).bdev);
-   if (ret)
-   break;
-   }
+   if (!sbi->s_ndevs || ret)
+   return ret;
+
+   for (i = 1; i < sbi->s_ndevs; i++) {
+   ret = __submit_flush_wait(sbi, FDEV(i).bdev);
+   if (ret)
+   break;
}
return ret;
 }
diff --git a/include/trace/events/f2fs.h b/include/trace/events/f2fs.h
index c80fcad0..d799ca7 100644
--- a/include/trace/events/f2fs.h
+++ b/include/trace/events/f2fs.h
@@ -1174,26 +1174,29 @@ TRACE_EVENT(f2fs_issue_reset_zone,
 TRACE_EVENT(f2fs_issue_flush,
 
TP_PROTO(struct block_device *dev, unsigned int nobarrier,
-   unsigned int flush_merge),
+   unsigned int flush_merge, int ret),
 
-   TP_ARGS(dev, nobarrier, flush_merge),
+   TP_ARGS(dev, nobarrier, flush_merge, ret),
 
TP_STRUCT__entry(
__field(dev_t,  dev)
__field(unsigned int, nobarrier)
__field(unsigned int, flush_merge)
+   __field(int,  ret)
),
 
TP_fast_assign(
__entry->dev= dev->bd_dev;
__entry->nobarrier = nobarrier;
__entry->flush_merge = flush_merge;
+   __entry->ret = ret;
),
 
-   TP_printk("dev = (%d,%d), %s %s",
+   TP_printk("dev = (%d,%d), %s %s, ret = %d",
show_dev(__entry->dev),
__entry->nobarrier ? "skip (nobarrier)" : "issue",
-   __entry->flush_merge ? " with flush_merge" : "")
+   __entry->flush_merge ? " with flush_merge" : "",
+   __entry->ret)
 );
 
 TRACE_EVENT(f2fs_lookup_extent_tree_start,
-- 
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


[f2fs-dev] [PATCH 1/2] f2fs: fix the fault of checking F2FS_LINK_MAX for rename inode

2017-03-04 Thread Kinglong Mee
The parent directory's nlink will change, not the inode.

Signed-off-by: Kinglong Mee <kinglong...@gmail.com>
---
 fs/f2fs/namei.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/fs/f2fs/namei.c b/fs/f2fs/namei.c
index 0eda022..3231a0a 100644
--- a/fs/f2fs/namei.c
+++ b/fs/f2fs/namei.c
@@ -908,8 +908,8 @@ static int f2fs_cross_rename(struct inode *old_dir, struct 
dentry *old_dentry,
old_nlink = old_dir_entry ? -1 : 1;
new_nlink = -old_nlink;
err = -EMLINK;
-   if ((old_nlink > 0 && old_inode->i_nlink >= F2FS_LINK_MAX) ||
-   (new_nlink > 0 && new_inode->i_nlink >= F2FS_LINK_MAX))
+   if ((old_nlink > 0 && old_dir->i_nlink >= F2FS_LINK_MAX) ||
+   (new_nlink > 0 && new_dir->i_nlink >= F2FS_LINK_MAX))
goto out_new_dir;
}
 
-- 
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


[f2fs-dev] [PATCH 2/2] f2fs: avoid new_inode's flags overwrite the old_node

2017-03-04 Thread Kinglong Mee
Note, rename with old_inode (enc_name) and new_inode (no_enc_name),
the result will be old_indoe(enc_name) and new_inode(enc_name).

Needs swap the enc_name flags?
If needed, this patch needs update of clear the flags.
otherwise, this patch only fix the logic with any result changing.

Signed-off-by: Kinglong Mee <kinglong...@gmail.com>
---
 fs/f2fs/namei.c | 12 
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/fs/f2fs/namei.c b/fs/f2fs/namei.c
index 3231a0a..db2ab7f 100644
--- a/fs/f2fs/namei.c
+++ b/fs/f2fs/namei.c
@@ -846,6 +846,7 @@ static int f2fs_cross_rename(struct inode *old_dir, struct 
dentry *old_dentry,
struct page *old_page, *new_page;
struct f2fs_dir_entry *old_dir_entry = NULL, *new_dir_entry = NULL;
struct f2fs_dir_entry *old_entry, *new_entry;
+   bool old_inode_enc = false, new_inode_enc = false;
int old_nlink = 0, new_nlink = 0;
int err = -ENOENT;
 
@@ -917,17 +918,16 @@ static int f2fs_cross_rename(struct inode *old_dir, 
struct dentry *old_dentry,
 
f2fs_lock_op(sbi);
 
+   old_inode_enc = file_enc_name(old_inode);
+   new_inode_enc = file_enc_name(new_inode);
+
err = update_dent_inode(old_inode, new_inode, _dentry->d_name);
if (err)
goto out_unlock;
-   if (file_enc_name(new_inode))
-   file_set_enc_name(old_inode);
 
err = update_dent_inode(new_inode, old_inode, _dentry->d_name);
if (err)
goto out_undo;
-   if (file_enc_name(old_inode))
-   file_set_enc_name(new_inode);
 
/* update ".." directory entry info of old dentry */
if (old_dir_entry)
@@ -942,6 +942,8 @@ static int f2fs_cross_rename(struct inode *old_dir, struct 
dentry *old_dentry,
 
down_write(_I(old_inode)->i_sem);
file_lost_pino(old_inode);
+   if (new_inode_enc)
+   file_set_enc_name(old_inode);
up_write(_I(old_inode)->i_sem);
 
old_dir->i_ctime = current_time(old_dir);
@@ -957,6 +959,8 @@ static int f2fs_cross_rename(struct inode *old_dir, struct 
dentry *old_dentry,
 
down_write(_I(new_inode)->i_sem);
file_lost_pino(new_inode);
+   if (old_inode_enc)
+   file_set_enc_name(new_inode);
up_write(_I(new_inode)->i_sem);
 
new_dir->i_ctime = current_time(new_dir);
-- 
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


[f2fs-dev] [PATCH v2 1/2] mkfs.f2fs: make the help messages and manpages clearer

2017-03-04 Thread Kinglong Mee
Add some missing options in manpages, also order those options.

Signed-off-by: Kinglong Mee <kinglong...@gmail.com>
---
 man/mkfs.f2fs.8 | 37 +++--
 mkfs/f2fs_format_main.c |  6 +++---
 2 files changed, 30 insertions(+), 13 deletions(-)

diff --git a/man/mkfs.f2fs.8 b/man/mkfs.f2fs.8
index bdb9755..f7bcad4 100644
--- a/man/mkfs.f2fs.8
+++ b/man/mkfs.f2fs.8
@@ -63,34 +63,51 @@ The default value is 1.
 Build f2fs with this device additionally, so that user can see all
 the devices as one big volume.
 .TP
+.BI \-d " debug-level"
+Specify the level of debugging options.
+The default number is 0, which shows basic debugging messages.
+.TP
+.BI \-e " extension-list"
+Specify a file extension list in order f2fs to treat them as cold files.
+The data of files having those extensions will be stored to the cold log.
+The default list includes most of multimedia file extensions such as jpg, gif,
+mpeg, mkv, and so on.
+.TP
 .BI \-l " volume-label"
 Specify the volume label to the partition mounted as F2FS.
 .TP
+.BI \-m
+Specify f2fs filesystem to supports the block zoned feature.
+Without it, the filesystem isn't supports the feature.
+.TP
 .BI \-o " overprovision-ratio-percentage"
 Specify the percentage over the volume size for overprovision area. This area
 is hidden to users, and utilized by F2FS cleaner. If not specified, the best
 number will be assigned automatically accoring to the partition size.
 .TP
+.BI \-O " feature-list"
+Specify a feature list in order f2fs filesystem will supports.
+e.g "encrypt" and so on.
+.TP
+.BI \-q
+Quiet mode.
+With it, mkfs.f2fs does not show any messages include the basic messages.
+.TP
 .BI \-s " #-of-segments-per-section"
 Specify the number of segments per section. A section consists of
 multiple consecutive segments, and is the unit of garbage collection.
 The default number is 1, which means one segment is assigned to a section.
 .TP
+.BI \-t " nodiscard/discard"
+Specify 1 or 0 to enable/disable discard policy.
+If the value is equal to 1, discard policy is enabled, otherwise is disable.
+The default value is 1.
+.TP
 .BI \-z " #-of-sections-per-zone"
 Specify the number of sections per zone. A zone consists of multiple sections.
 F2FS allocates segments for active logs with separated zones as much as 
possible.
 The default number is 1, which means a zone consists of one section.
 .TP
-.BI \-e " extension-list"
-Specify a file extension list in order f2fs to treat them as cold files.
-The data of files having those extensions will be stored to the cold log.
-The default list includes most of multimedia file extensions such as jpg, gif,
-mpeg, mkv, and so on.
-.TP
-.BI \-d " debug-level"
-Specify the level of debugging options.
-The default number is 0, which shows basic debugging messages.
-.TP
 .SH AUTHOR
 This version of
 .B mkfs.f2fs
diff --git a/mkfs/f2fs_format_main.c b/mkfs/f2fs_format_main.c
index 5bb1faf..0ac87ed 100644
--- a/mkfs/f2fs_format_main.c
+++ b/mkfs/f2fs_format_main.c
@@ -32,13 +32,13 @@ static void mkfs_usage()
MSG(0, "  -d debug level [default:0]\n");
MSG(0, "  -e [extension list] e.g. \"mp3,gif,mov\"\n");
MSG(0, "  -l label\n");
+   MSG(0, "  -m support zoned block device [default:0]\n");
MSG(0, "  -o overprovision ratio [default:5]\n");
-   MSG(0, "  -O set feature\n");
+   MSG(0, "  -O [feature list] e.g. \"encrypt\"\n");
MSG(0, "  -q quiet mode\n");
MSG(0, "  -s # of segments per section [default:1]\n");
-   MSG(0, "  -z # of sections per zone [default:1]\n");
MSG(0, "  -t 0: nodiscard, 1: discard [default:1]\n");
-   MSG(0, "  -m support zoned block device [default:0]\n");
+   MSG(0, "  -z # of sections per zone [default:1]\n");
MSG(0, "sectors: number of sectors. [default: determined by device 
size]\n");
exit(1);
 }
-- 
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


[f2fs-dev] [PATCH v2 2/2] mkfs.f2fs: check overwrite before make filesystem

2017-03-04 Thread Kinglong Mee
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.

v2, add the manpages description of -f.

Signed-off-by: Kinglong Mee <kinglong...@gmail.com>
---
 configure.ac| 20 +--
 man/mkfs.f2fs.8 |  5 +++
 mkfs/Makefile.am|  4 +--
 mkfs/f2fs_format_main.c | 90 -
 4 files changed, 114 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/man/mkfs.f2fs.8 b/man/mkfs.f2fs.8
index f7bcad4..9c87541 100644
--- a/man/mkfs.f2fs.8
+++ b/man/mkfs.f2fs.8
@@ -73,6 +73,11 @@ The data of files having those extensions will be stored to 
the cold log.
 The default list includes most of multimedia file extensions such as jpg, gif,
 mpeg, mkv, and so on.
 .TP
+.BI \-f
+Force overwrite when an existing filesystem is detected on the device.
+By default, mkfs.f2fs will not write to the device if it suspects that
+there is a filesystem or partition table on the device already.
+.TP
 .BI \-l " volume-label"
 Specify the volume label to the partition mounted as F2FS.
 .TP
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 0ac87ed..482506a 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()
 {
@@ -31,6 +37,7 @@ static void mkfs_usage()
MSG(0, "  -c [device path] up to 7 devices excepts meta device\n");
MSG(0, "  -d debug level [default:0]\n");
MSG(0, "  -e [extension list] e.g. \"mp3,gif,mov\"\n");
+   MSG(0, "  -f force overwrite the exist filesystem\n");
MSG(0, "  -l label\n");
MSG(0, "  -m support zoned block device [default:0]\n");
MSG(0, "  -o overprovision ratio [default:5]\n");
@@ -72,7 +79,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 +135,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 %

[f2fs-dev] [PATCH] f2fs: fix the fault of calculating blkstart twice

2017-03-03 Thread Kinglong Mee
When the zone type is BLK_ZONE_TYPE_CONVENTIONAL, the blkstart is 
calculated twice.

Signed-off-by: Kinglong Mee <kinglong...@gmail.com>
---
 fs/f2fs/segment.c | 22 +-
 1 file changed, 9 insertions(+), 13 deletions(-)

diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
index 4bd7a8b..ed181d1 100644
--- a/fs/f2fs/segment.c
+++ b/fs/f2fs/segment.c
@@ -772,11 +772,6 @@ static int __f2fs_issue_discard_async(struct f2fs_sb_info 
*sbi,
 
trace_f2fs_issue_discard(bdev, blkstart, blklen);
 
-   if (sbi->s_ndevs) {
-   int devi = f2fs_target_device_index(sbi, blkstart);
-
-   blkstart -= FDEV(devi).start_blk;
-   }
err = __blkdev_issue_discard(bdev,
SECTOR_FROM_BLOCK(blkstart),
SECTOR_FROM_BLOCK(blklen),
@@ -796,12 +791,6 @@ static int __f2fs_issue_discard_zone(struct f2fs_sb_info 
*sbi,
struct block_device *bdev, block_t blkstart, block_t blklen)
 {
sector_t sector, nr_sects;
-   int devi = 0;
-
-   if (sbi->s_ndevs) {
-   devi = f2fs_target_device_index(sbi, blkstart);
-   blkstart -= FDEV(devi).start_blk;
-   }
 
/*
 * We need to know the type of the zone: for conventional zones,
@@ -822,8 +811,8 @@ static int __f2fs_issue_discard_zone(struct f2fs_sb_info 
*sbi,
if (sector & (bdev_zone_sectors(bdev) - 1) ||
nr_sects != bdev_zone_sectors(bdev)) {
f2fs_msg(sbi->sb, KERN_INFO,
-   "(%d) %s: Unaligned discard attempted (block %x 
+ %x)",
-   devi, sbi->s_ndevs ? FDEV(devi).path: "",
+   "Dev(%u:%u): Unaligned discard attempted (block 
%x + %x)",
+   MAJOR(bdev->bd_dev), MINOR(bdev->bd_dev),
blkstart, blklen);
return -EIO;
}
@@ -840,6 +829,13 @@ static int __f2fs_issue_discard_zone(struct f2fs_sb_info 
*sbi,
 static int __issue_discard_async(struct f2fs_sb_info *sbi,
struct block_device *bdev, block_t blkstart, block_t blklen)
 {
+   int devi = 0;
+
+   if (sbi->s_ndevs) {
+   devi = f2fs_target_device_index(sbi, blkstart);
+   blkstart -= FDEV(devi).start_blk;
+   }
+
 #ifdef CONFIG_BLK_DEV_ZONED
if (f2fs_sb_mounted_blkzoned(sbi->sb) &&
bdev_zoned_model(bdev) != BLK_ZONED_NONE)
-- 
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


Re: [f2fs-dev] [PATCH RFC] f2fs: combine nat_bits and free_nid_bitmap cache

2017-03-01 Thread Kinglong Mee
On 3/2/2017 09:35, Chao Yu wrote:
> On 2017/3/1 21:09, Kinglong Mee wrote:
>> On 3/1/2017 17:10, Chao Yu wrote:
>>> Both nat_bits cache and free_nid_bitmap cache provide same functionality
>>> as a intermediate cache between free nid cache and disk, but with
>>> different granularity of indicating free nid range, and different
>>> persistence policy. nat_bits cache provides better persistence ability,
>>> and free_nid_bitmap provides better granularity.
>>>
>>> In this patch we combine advantage of both caches, so finally policy of
>>> the intermediate cache would be:
>>> - init: load free nid status from nat_bits into free_nid_bitmap
>>> - lookup: scan free_nid_bitmap before load NAT blocks
>>
>> Why not scan the full_nat_bits/empty_nat_bits before load NAT blocks here?
>> If after an objects shrinker, the cached free nid will be empty quickly.
> 
> Since after this patch, all nids status (free or used) of
> full_nat_bits/empty_nat_bits will be loaded into free_nid_bitmap, so we can 
> just
> check free_nid_bitmap instead of both cache before loading NAT blocks.

Yes, you are right.
I forgot f2fs also updates update_free_nid_bitmap in __flush_nat_entry_set.

thanks,
Kinglong Mee

>>> - update: update free_nid_bitmap in real-time
>>> - persistence: udpate and persist nat_bits in checkpoint
>>>
>>> Signed-off-by: Chao Yu <yuch...@huawei.com>
>>> ---
>>>  fs/f2fs/node.c | 109 
>>> +
>>>  1 file changed, 39 insertions(+), 70 deletions(-)
>>>
>>> diff --git a/fs/f2fs/node.c b/fs/f2fs/node.c
>>> index 1a759d45b7e4..6c027b6833f4 100644
>>> --- a/fs/f2fs/node.c
>>> +++ b/fs/f2fs/node.c
>>> @@ -338,9 +338,6 @@ static void set_node_addr(struct f2fs_sb_info *sbi, 
>>> struct node_info *ni,
>>> set_nat_flag(e, IS_CHECKPOINTED, false);
>>> __set_nat_cache_dirty(nm_i, e);
>>>  
>>> -   if (enabled_nat_bits(sbi, NULL) && new_blkaddr == NEW_ADDR)
>>> -   clear_bit_le(NAT_BLOCK_OFFSET(ni->nid), nm_i->empty_nat_bits);
>>> -
>>> /* update fsync_mark if its inode nat entry is still alive */
>>> if (ni->nid != ni->ino)
>>> e = __lookup_nat_cache(nm_i, ni->ino);
>>> @@ -1920,58 +1917,6 @@ static void scan_free_nid_bits(struct f2fs_sb_info 
>>> *sbi)
>>> up_read(_i->nat_tree_lock);
>>>  }
>>>  
>>> -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 nid;
>>> -
>>> -   if (!enabled_nat_bits(sbi, NULL))
>>> -   return -EAGAIN;
>>> -
>>> -   down_read(_i->nat_tree_lock);
>>> -check_empty:
>>> -   i = find_next_bit_le(nm_i->empty_nat_bits, nm_i->nat_blocks, i);
>>> -   if (i >= nm_i->nat_blocks) {
>>> -   i = 0;
>>> -   goto check_partial;
>>> -   }
>>> -
>>> -   for (nid = i * NAT_ENTRY_PER_BLOCK; nid < (i + 1) * NAT_ENTRY_PER_BLOCK;
>>> -   nid++) {
>>> -   if (unlikely(nid >= nm_i->max_nid))
>>> -   break;
>>> -   add_free_nid(sbi, nid, true);
>>> -   }
>>> -
>>> -   if (nm_i->nid_cnt[FREE_NID_LIST] >= MAX_FREE_NIDS)
>>> -   goto out;
>>> -   i++;
>>> -   goto check_empty;
>>> -
>>> -check_partial:
>>> -   i = find_next_zero_bit_le(nm_i->full_nat_bits, nm_i->nat_blocks, i);
>>> -   if (i >= nm_i->nat_blocks) {
>>> -   disable_nat_bits(sbi, true);
>>> -   up_read(_i->nat_tree_lock);
>>> -   return -EINVAL;
>>> -   }
>>> -
>>> -   nid = i * NAT_ENTRY_PER_BLOCK;
>>> -   page = get_current_nat_page(sbi, nid);
>>> -   scan_nat_page(sbi, page, nid);
>>> -   f2fs_put_page(page, 1);
>>> -
>>> -   if (nm_i->nid_cnt[FREE_NID_LIST] < MAX_FREE_NIDS) {
>>> -   i++;
>>> -   goto check_partial;
>>> -   }
>>> -out:
>>> -   up_read(_i->nat_tree_lock);
>>> -   return 0;
>>> -}
>>> -
>>>  static void __build_free_nids(struct f2fs_sb_info *sbi, bool sync, bool 
>>> mount)
>>>  {
>>> struct f

Re: [f2fs-dev] [PATCH RFC] f2fs: combine nat_bits and free_nid_bitmap cache

2017-03-01 Thread Kinglong Mee
On 3/1/2017 17:10, Chao Yu wrote:
> Both nat_bits cache and free_nid_bitmap cache provide same functionality
> as a intermediate cache between free nid cache and disk, but with
> different granularity of indicating free nid range, and different
> persistence policy. nat_bits cache provides better persistence ability,
> and free_nid_bitmap provides better granularity.
> 
> In this patch we combine advantage of both caches, so finally policy of
> the intermediate cache would be:
> - init: load free nid status from nat_bits into free_nid_bitmap
> - lookup: scan free_nid_bitmap before load NAT blocks

Why not scan the full_nat_bits/empty_nat_bits before load NAT blocks here?
If after an objects shrinker, the cached free nid will be empty quickly.

thanks,
Kinglong Mee

> - update: update free_nid_bitmap in real-time
> - persistence: udpate and persist nat_bits in checkpoint
> 
> Signed-off-by: Chao Yu <yuch...@huawei.com>
> ---
>  fs/f2fs/node.c | 109 
> +
>  1 file changed, 39 insertions(+), 70 deletions(-)
> 
> diff --git a/fs/f2fs/node.c b/fs/f2fs/node.c
> index 1a759d45b7e4..6c027b6833f4 100644
> --- a/fs/f2fs/node.c
> +++ b/fs/f2fs/node.c
> @@ -338,9 +338,6 @@ static void set_node_addr(struct f2fs_sb_info *sbi, 
> struct node_info *ni,
>   set_nat_flag(e, IS_CHECKPOINTED, false);
>   __set_nat_cache_dirty(nm_i, e);
>  
> - if (enabled_nat_bits(sbi, NULL) && new_blkaddr == NEW_ADDR)
> - clear_bit_le(NAT_BLOCK_OFFSET(ni->nid), nm_i->empty_nat_bits);
> -
>   /* update fsync_mark if its inode nat entry is still alive */
>   if (ni->nid != ni->ino)
>   e = __lookup_nat_cache(nm_i, ni->ino);
> @@ -1920,58 +1917,6 @@ static void scan_free_nid_bits(struct f2fs_sb_info 
> *sbi)
>   up_read(_i->nat_tree_lock);
>  }
>  
> -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 nid;
> -
> - if (!enabled_nat_bits(sbi, NULL))
> - return -EAGAIN;
> -
> - down_read(_i->nat_tree_lock);
> -check_empty:
> - i = find_next_bit_le(nm_i->empty_nat_bits, nm_i->nat_blocks, i);
> - if (i >= nm_i->nat_blocks) {
> - i = 0;
> - goto check_partial;
> - }
> -
> - for (nid = i * NAT_ENTRY_PER_BLOCK; nid < (i + 1) * NAT_ENTRY_PER_BLOCK;
> - nid++) {
> - if (unlikely(nid >= nm_i->max_nid))
> - break;
> - add_free_nid(sbi, nid, true);
> - }
> -
> - if (nm_i->nid_cnt[FREE_NID_LIST] >= MAX_FREE_NIDS)
> - goto out;
> - i++;
> - goto check_empty;
> -
> -check_partial:
> - i = find_next_zero_bit_le(nm_i->full_nat_bits, nm_i->nat_blocks, i);
> - if (i >= nm_i->nat_blocks) {
> - disable_nat_bits(sbi, true);
> - up_read(_i->nat_tree_lock);
> - return -EINVAL;
> - }
> -
> - nid = i * NAT_ENTRY_PER_BLOCK;
> - page = get_current_nat_page(sbi, nid);
> - scan_nat_page(sbi, page, nid);
> - f2fs_put_page(page, 1);
> -
> - if (nm_i->nid_cnt[FREE_NID_LIST] < MAX_FREE_NIDS) {
> - i++;
> - goto check_partial;
> - }
> -out:
> - up_read(_i->nat_tree_lock);
> - return 0;
> -}
> -
>  static void __build_free_nids(struct f2fs_sb_info *sbi, bool sync, bool 
> mount)
>  {
>   struct f2fs_nm_info *nm_i = NM_I(sbi);
> @@ -1993,21 +1938,6 @@ static void __build_free_nids(struct f2fs_sb_info 
> *sbi, bool sync, bool mount)
>  
>   if (nm_i->nid_cnt[FREE_NID_LIST])
>   return;
> -
> - /* try to find free nids with nat_bits */
> - if (!scan_nat_bits(sbi) && nm_i->nid_cnt[FREE_NID_LIST])
> - return;
> - }
> -
> - /* find next valid candidate */
> - if (enabled_nat_bits(sbi, NULL)) {
> - int idx = find_next_zero_bit_le(nm_i->full_nat_bits,
> - nm_i->nat_blocks, 0);
> -
> - if (idx >= nm_i->nat_blocks)
> - set_sbi_flag(sbi, SBI_NEED_FSCK);
> - else
> - nid = idx * NAT_ENTRY_PER_BLOCK;
>   }
>  
>   /* readahead nat pages to be scanned */
> @@ -2590,6 +2520,41 @@ static int __get_nat_bitmaps(struct f2fs_sb_info *sbi)
>   return 0;
>  }
>  
> +inl

Re: [f2fs-dev] [PATCH] f2fs: skip filesystem level truncate when size isn't changed

2017-02-28 Thread Kinglong Mee
On 3/1/2017 10:08, Chao Yu wrote:
> On 2017/2/28 21:34, Kinglong Mee wrote:
>> When size isn't changed, it's needless to do f2fs level truncate.
> 
> I think it needs to do this.
> 
> Please take a look at commit 3c4541452748 ("f2fs: do not trim preallocated
> blocks when truncating after i_size") and generic/092 of fstests.
 
Got it, thanks!

thanks,
Kinglong Mee

> Thanks,
> 
>>
>> Signed-off-by: Kinglong Mee <kinglong...@gmail.com>
>> ---
>>  fs/f2fs/file.c | 9 +
>>  1 file changed, 5 insertions(+), 4 deletions(-)
>>
>> diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
>> index c6ca00c..d144aa3 100644
>> --- a/fs/f2fs/file.c
>> +++ b/fs/f2fs/file.c
>> @@ -676,6 +676,7 @@ static void __setattr_copy(struct inode *inode, const 
>> struct iattr *attr)
>>  int f2fs_setattr(struct dentry *dentry, struct iattr *attr)
>>  {
>>  struct inode *inode = d_inode(dentry);
>> +loff_t old_size = i_size_read(inode);
>>  int err;
>>  bool size_changed = false;
>>  
>> @@ -688,12 +689,13 @@ int f2fs_setattr(struct dentry *dentry, struct iattr 
>> *attr)
>>  fscrypt_get_encryption_info(inode))
>>  return -EACCES;
>>  
>> -if (attr->ia_size <= i_size_read(inode)) {
>> +if (attr->ia_size < old_size) {
>>  truncate_setsize(inode, attr->ia_size);
>>  err = f2fs_truncate(inode);
>>  if (err)
>>  return err;
>> -} else {
>> +size_changed = true;
>> +} else if (attr->ia_size > old_size) {
>>  /*
>>   * do not trim all blocks after i_size if target size is
>>   * larger than i_size.
>> @@ -707,9 +709,8 @@ int f2fs_setattr(struct dentry *dentry, struct iattr 
>> *attr)
>>  return err;
>>  }
>>  inode->i_mtime = inode->i_ctime = current_time(inode);
>> +size_changed = true;
>>  }
>> -
>> -size_changed = true;
>>  }
>>  
>>  __setattr_copy(inode, attr);
>>
> 
> 

--
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] f2fs: drop duplicate radix tree lookup of nat_entry_set

2017-02-28 Thread Kinglong Mee
The nat entry is listed from the set list for freeing, 
it's duplicate to do radix tree lookup again.

Signed-off-by: Kinglong Mee <kinglong...@gmail.com>
---
 fs/f2fs/node.c | 19 +++
 1 file changed, 7 insertions(+), 12 deletions(-)

diff --git a/fs/f2fs/node.c b/fs/f2fs/node.c
index b3aead4..a0854d3 100644
--- a/fs/f2fs/node.c
+++ b/fs/f2fs/node.c
@@ -177,18 +177,13 @@ static void __set_nat_cache_dirty(struct f2fs_nm_info 
*nm_i,
 }
 
 static void __clear_nat_cache_dirty(struct f2fs_nm_info *nm_i,
-   struct nat_entry *ne)
+   struct nat_entry_set *set, struct nat_entry *ne)
 {
-   nid_t set = NAT_BLOCK_OFFSET(ne->ni.nid);
-   struct nat_entry_set *head;
-
-   head = radix_tree_lookup(_i->nat_set_root, set);
-   if (head) {
-   list_move_tail(>list, _i->nat_entries);
-   set_nat_flag(ne, IS_DIRTY, false);
-   head->entry_cnt--;
-   nm_i->dirty_nat_cnt--;
-   }
+   f2fs_bug_on(sbi, set == NULL);
+   list_move_tail(>list, _i->nat_entries);
+   set_nat_flag(ne, IS_DIRTY, false);
+   set->entry_cnt--;
+   nm_i->dirty_nat_cnt--;
 }
 
 static unsigned int __gang_lookup_nat_set(struct f2fs_nm_info *nm_i,
@@ -2462,7 +2457,7 @@ static void __flush_nat_entry_set(struct f2fs_sb_info 
*sbi,
}
raw_nat_from_node_info(raw_ne, >ni);
nat_reset_flag(ne);
-   __clear_nat_cache_dirty(NM_I(sbi), ne);
+   __clear_nat_cache_dirty(NM_I(sbi), set, ne);
if (nat_get_blkaddr(ne) == NULL_ADDR) {
add_free_nid(sbi, nid, false);
spin_lock(_I(sbi)->nid_list_lock);
-- 
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


[f2fs-dev] [PATCH] f2fs: remove dead macro PGOFS_OF_NEXT_DNODE

2017-02-28 Thread Kinglong Mee
Fixes: 3cf4574705 ("f2fs: introduce get_next_page_offset to speed up SEEK_DATA")
Signed-off-by: Kinglong Mee <kinglong...@gmail.com>
---
 fs/f2fs/f2fs.h | 6 --
 1 file changed, 6 deletions(-)

diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
index 7e29249..da738c8 100644
--- a/fs/f2fs/f2fs.h
+++ b/fs/f2fs/f2fs.h
@@ -2032,12 +2032,6 @@ static inline void *f2fs_kvzalloc(size_t size, gfp_t 
flags)
((is_inode_flag_set(i, FI_ACL_MODE)) ? \
 (F2FS_I(i)->i_acl_mode) : ((i)->i_mode))
 
-/* get offset of first page in next direct node */
-#define PGOFS_OF_NEXT_DNODE(pgofs, inode)  \
-   ((pgofs < ADDRS_PER_INODE(inode)) ? ADDRS_PER_INODE(inode) :\
-   (pgofs - ADDRS_PER_INODE(inode) + ADDRS_PER_BLOCK) /\
-   ADDRS_PER_BLOCK * ADDRS_PER_BLOCK + ADDRS_PER_INODE(inode))
-
 /*
  * file.c
  */
-- 
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


[f2fs-dev] [PATCH] f2fs: skip filesystem level truncate when size isn't changed

2017-02-28 Thread Kinglong Mee
When size isn't changed, it's needless to do f2fs level truncate.

Signed-off-by: Kinglong Mee <kinglong...@gmail.com>
---
 fs/f2fs/file.c | 9 +
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
index c6ca00c..d144aa3 100644
--- a/fs/f2fs/file.c
+++ b/fs/f2fs/file.c
@@ -676,6 +676,7 @@ static void __setattr_copy(struct inode *inode, const 
struct iattr *attr)
 int f2fs_setattr(struct dentry *dentry, struct iattr *attr)
 {
struct inode *inode = d_inode(dentry);
+   loff_t old_size = i_size_read(inode);
int err;
bool size_changed = false;
 
@@ -688,12 +689,13 @@ int f2fs_setattr(struct dentry *dentry, struct iattr 
*attr)
fscrypt_get_encryption_info(inode))
return -EACCES;
 
-   if (attr->ia_size <= i_size_read(inode)) {
+   if (attr->ia_size < old_size) {
truncate_setsize(inode, attr->ia_size);
err = f2fs_truncate(inode);
if (err)
return err;
-   } else {
+   size_changed = true;
+   } else if (attr->ia_size > old_size) {
/*
 * do not trim all blocks after i_size if target size is
 * larger than i_size.
@@ -707,9 +709,8 @@ int f2fs_setattr(struct dentry *dentry, struct iattr *attr)
return err;
}
inode->i_mtime = inode->i_ctime = current_time(inode);
+   size_changed = true;
}
-
-   size_changed = true;
}
 
__setattr_copy(inode, attr);
-- 
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


Re: [f2fs-dev] [PATCH 1/3] f2fs: fix a memleak issue

2017-02-27 Thread Kinglong Mee
On 2/27/2017 21:02, Hou Pengyang wrote:
> [fix: ae75f0ca76 f2fs: introduce free nid bitmap]
> Signed-off-by: Hou Pengyang <houpengy...@huawei.com>
> ---
>  fs/f2fs/node.c | 5 -
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/fs/f2fs/node.c b/fs/f2fs/node.c
> index 6d43095..353c01d 100644
> --- a/fs/f2fs/node.c
> +++ b/fs/f2fs/node.c
> @@ -2650,8 +2650,11 @@ int init_free_nid_cache(struct f2fs_sb_info *sbi)
>  
>   nm_i->nat_block_bitmap = f2fs_kvzalloc(nm_i->nat_blocks / 8,
>   GFP_KERNEL);
> - if (!nm_i->nat_block_bitmap)
> + if (!nm_i->nat_block_bitmap) {
> + kvfree(nm_i->free_nid_bitmap);
>   return -ENOMEM;
> + }
> +
>   return 0;
>  }

If building node manager fail, destroy_node_manager will be called,
I think there isn't any memory leak exist, right?

err = build_node_manager(sbi);
if (err) {
f2fs_msg(sb, KERN_ERR,
"Failed to initialize F2FS node manager");
goto free_nm;
}


thanks,
Kinglong Mee

--
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

2017-02-26 Thread Kinglong Mee
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 <kinglong...@gmail.com>
>> ---
>>  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


[f2fs-dev] [PATCH] mkfs.f2fs: check filesystem overwrite before formatting

2017-02-26 Thread Kinglong Mee
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 <kinglong...@gmail.com>
---
 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",
+ 

[f2fs-dev] [PATCH] f2fs: use MAX_FREE_NIDS for the free nids target

2017-02-26 Thread Kinglong Mee
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 <kinglong...@gmail.com>
---
 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


[f2fs-dev] [PATCH] f2fs: new helper cur_cp_crc() getting crc in f2fs_checkpoint

2017-02-25 Thread Kinglong Mee
There are four places that getting the crc value in f2fs_checkpoint,
just add a new helper cur_cp_crc for them.

Signed-off-by: Kinglong Mee <kinglong...@gmail.com>
---
 fs/f2fs/checkpoint.c |  3 +--
 fs/f2fs/f2fs.h   |  6 ++
 fs/f2fs/node.c   |  5 +
 fs/f2fs/node.h   | 20 +++-
 4 files changed, 15 insertions(+), 19 deletions(-)

diff --git a/fs/f2fs/checkpoint.c b/fs/f2fs/checkpoint.c
index cd71321..37a216b 100644
--- a/fs/f2fs/checkpoint.c
+++ b/fs/f2fs/checkpoint.c
@@ -682,8 +682,7 @@ static int get_checkpoint_version(struct f2fs_sb_info *sbi, 
block_t cp_addr,
return -EINVAL;
}
 
-   crc = le32_to_cpu(*((__le32 *)((unsigned char *)*cp_block
-   + crc_offset)));
+   crc = cur_cp_crc(*cp_block);
if (!f2fs_crc_valid(sbi, crc, *cp_block, crc_offset)) {
f2fs_msg(sbi->sb, KERN_WARNING, "invalid crc value");
return -EINVAL;
diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
index 8b6d496..79da17e 100644
--- a/fs/f2fs/f2fs.h
+++ b/fs/f2fs/f2fs.h
@@ -1135,6 +1135,12 @@ static inline unsigned long long cur_cp_version(struct 
f2fs_checkpoint *cp)
return le64_to_cpu(cp->checkpoint_ver);
 }
 
+static inline __u64 cur_cp_crc(struct f2fs_checkpoint *cp)
+{
+   size_t crc_offset = le32_to_cpu(cp->checksum_offset);
+   return le32_to_cpu(*((__le32 *)((unsigned char *)cp + crc_offset)));
+}
+
 static inline bool __is_set_ckpt_flags(struct f2fs_checkpoint *cp, unsigned 
int f)
 {
unsigned int ckpt_flags = le32_to_cpu(cp->ckpt_flags);
diff --git a/fs/f2fs/node.c b/fs/f2fs/node.c
index 8190329..1876288 100644
--- a/fs/f2fs/node.c
+++ b/fs/f2fs/node.c
@@ -2540,9 +2540,6 @@ static int __get_nat_bitmaps(struct f2fs_sb_info *sbi)
unsigned int nat_bits_bytes = nm_i->nat_blocks / BITS_PER_BYTE;
unsigned int i;
__u64 cp_ver = cur_cp_version(ckpt);
-   size_t crc_offset = le32_to_cpu(ckpt->checksum_offset);
-   __u64 crc = le32_to_cpu(*((__le32 *)
-   ((unsigned char *)ckpt + crc_offset)));
block_t nat_bits_addr;
 
if (!enabled_nat_bits(sbi, NULL))
@@ -2565,7 +2562,7 @@ static int __get_nat_bitmaps(struct f2fs_sb_info *sbi)
f2fs_put_page(page, 1);
}
 
-   cp_ver |= (crc << 32);
+   cp_ver |= (cur_cp_crc(ckpt) << 32);
if (cpu_to_le64(cp_ver) != *(__le64 *)nm_i->nat_bits) {
disable_nat_bits(sbi, true);
return 0;
diff --git a/fs/f2fs/node.h b/fs/f2fs/node.h
index 3fc9c4b..2f9603f 100644
--- a/fs/f2fs/node.h
+++ b/fs/f2fs/node.h
@@ -300,14 +300,11 @@ static inline void fill_node_footer_blkaddr(struct page 
*page, block_t blkaddr)
 {
struct f2fs_checkpoint *ckpt = F2FS_CKPT(F2FS_P_SB(page));
struct f2fs_node *rn = F2FS_NODE(page);
-   size_t crc_offset = le32_to_cpu(ckpt->checksum_offset);
-   __u64 cp_ver = le64_to_cpu(ckpt->checkpoint_ver);
+   __u64 cp_ver = cur_cp_version(ckpt);
+
+   if (__is_set_ckpt_flags(ckpt, CP_CRC_RECOVERY_FLAG))
+   cp_ver |= (cur_cp_crc(ckpt) << 32);
 
-   if (__is_set_ckpt_flags(ckpt, CP_CRC_RECOVERY_FLAG)) {
-   __u64 crc = le32_to_cpu(*((__le32 *)
-   ((unsigned char *)ckpt + crc_offset)));
-   cp_ver |= (crc << 32);
-   }
rn->footer.cp_ver = cpu_to_le64(cp_ver);
rn->footer.next_blkaddr = cpu_to_le32(blkaddr);
 }
@@ -315,14 +312,11 @@ static inline void fill_node_footer_blkaddr(struct page 
*page, block_t blkaddr)
 static inline bool is_recoverable_dnode(struct page *page)
 {
struct f2fs_checkpoint *ckpt = F2FS_CKPT(F2FS_P_SB(page));
-   size_t crc_offset = le32_to_cpu(ckpt->checksum_offset);
__u64 cp_ver = cur_cp_version(ckpt);
 
-   if (__is_set_ckpt_flags(ckpt, CP_CRC_RECOVERY_FLAG)) {
-   __u64 crc = le32_to_cpu(*((__le32 *)
-   ((unsigned char *)ckpt + crc_offset)));
-   cp_ver |= (crc << 32);
-   }
+   if (__is_set_ckpt_flags(ckpt, CP_CRC_RECOVERY_FLAG))
+   cp_ver |= (cur_cp_crc(ckpt) << 32);
+
return cp_ver == cpver_of_node(page);
 }
 
-- 
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


[f2fs-dev] [PATCH] f2fs: update the comment of default nr_pages to skipping

2017-02-25 Thread Kinglong Mee
Fixes: 2c237ebaa4 ("f2fs: avoid writing node/metapages during writes")
Signed-off-by: Kinglong Mee <kinglong...@gmail.com>
---
 fs/f2fs/segment.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/fs/f2fs/segment.h b/fs/f2fs/segment.h
index f4020f1..5e8ad42 100644
--- a/fs/f2fs/segment.h
+++ b/fs/f2fs/segment.h
@@ -736,8 +736,8 @@ static inline bool sec_usage_check(struct f2fs_sb_info 
*sbi, unsigned int secno)
  * It is very important to gather dirty pages and write at once, so that we can
  * submit a big bio without interfering other data writes.
  * By default, 512 pages for directory data,
- * 512 pages (2MB) * 3 for three types of nodes, and
- * max_bio_blocks for meta are set.
+ * 512 pages (2MB) * 8 for nodes, and
+ * 256 pages * 8 for meta are set.
  */
 static inline int nr_pages_to_skip(struct f2fs_sb_info *sbi, int type)
 {
-- 
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


[f2fs-dev] [PATCH 3/3] f2fs: drop calling alloc_nid_failed when no nid is allocated

2017-02-25 Thread Kinglong Mee
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 <kinglong...@gmail.com>
---
 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);
+   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);
+
f2fs_wait_on_page_writeback(xpage, NODE, true);
} else {
struct dnode_of_data dn;
-- 
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


[f2fs-dev] [PATCH 2/3] f2fs: drop the duplicate pval in f2fs_getxattr

2017-02-25 Thread Kinglong Mee
Fixes: ba38c27eb9 ("f2fs: enhance lookup xattr")
Signed-off-by: Kinglong Mee <kinglong...@gmail.com>
---
 fs/f2fs/xattr.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/fs/f2fs/xattr.c b/fs/f2fs/xattr.c
index dbfd5cb..7298a44 100644
--- a/fs/f2fs/xattr.c
+++ b/fs/f2fs/xattr.c
@@ -467,7 +467,6 @@ int f2fs_getxattr(struct inode *inode, int index, const 
char *name,
struct f2fs_xattr_entry *entry = NULL;
int error = 0;
unsigned int size, len;
-   char *pval;
void *base_addr = NULL;
 
if (name == NULL)
@@ -489,8 +488,6 @@ int f2fs_getxattr(struct inode *inode, int index, const 
char *name,
goto out;
}
 
-   pval = entry->e_name + entry->e_name_len;
-
if (buffer) {
char *pval = entry->e_name + entry->e_name_len;
memcpy(buffer, pval, size);
-- 
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


[f2fs-dev] [PATCH 1/3] f2fs: Don't update the xattr data that same as the exist

2017-02-25 Thread Kinglong Mee
f2fs removes the old xattr data and appends the new data although
the new data is same as the exist.

Signed-off-by: Kinglong Mee <kinglong...@gmail.com>
---
 fs/f2fs/xattr.c | 20 
 1 file changed, 16 insertions(+), 4 deletions(-)

diff --git a/fs/f2fs/xattr.c b/fs/f2fs/xattr.c
index b50f6b5..dbfd5cb 100644
--- a/fs/f2fs/xattr.c
+++ b/fs/f2fs/xattr.c
@@ -545,6 +545,13 @@ ssize_t f2fs_listxattr(struct dentry *dentry, char 
*buffer, size_t buffer_size)
return error;
 }
 
+static bool f2fs_xattr_value_same(struct f2fs_xattr_entry *entry,
+   const void *value, size_t size)
+{
+   void *pval = entry->e_name + entry->e_name_len;
+   return (entry->e_value_size == size) && !memcmp(pval, value, size);
+}
+
 static int __f2fs_setxattr(struct inode *inode, int index,
const char *name, const void *value, size_t size,
struct page *ipage, int flags)
@@ -579,12 +586,17 @@ static int __f2fs_setxattr(struct inode *inode, int index,
 
found = IS_XATTR_LAST_ENTRY(here) ? 0 : 1;
 
-   if ((flags & XATTR_REPLACE) && !found) {
+   if (found) {
+   if ((flags & XATTR_CREATE)) {
+   error = -EEXIST;
+   goto exit;
+   }
+
+   if (f2fs_xattr_value_same(here, value, size))
+   goto exit;
+   } else if ((flags & XATTR_REPLACE)) {
error = -ENODATA;
goto exit;
-   } else if ((flags & XATTR_CREATE) && found) {
-   error = -EEXIST;
-   goto exit;
}
 
last = here;
-- 
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


[f2fs-dev] [PATCH] f2fs: avoid m_flags overlay when allocating more data blocks

2017-02-23 Thread Kinglong Mee
When more than one data blocks are allocated, the F2FS_MAP_UNWRITTEN/MAPPED
flags will be overlapped by F2FS_MAP_NEW at the later times.

Signed-off-by: Kinglong Mee <kinglong...@gmail.com>
---
 fs/f2fs/data.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
index 5f3bc98..5618ae8 100644
--- a/fs/f2fs/data.c
+++ b/fs/f2fs/data.c
@@ -867,7 +867,7 @@ int f2fs_map_blocks(struct inode *inode, struct 
f2fs_map_blocks *map,
}
if (err)
goto sync_out;
-   map->m_flags = F2FS_MAP_NEW;
+   map->m_flags |= F2FS_MAP_NEW;
blkaddr = dn.data_blkaddr;
} else {
if (flag == F2FS_GET_BLOCK_BMAP) {
-- 
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


[f2fs-dev] [PATCH] mkfs.f2fs: check the c.overprovision with zero before using it

2017-02-06 Thread Kinglong Mee
The using of c.overprovision when it equal zero as, 

c.reserved_segments =
(2 * (100 / c.overprovision + 1) + 6)
* c.segs_per_sec;

may cause problem, although it doesn't happen.

Signed-off-by: Kinglong Mee <kinglong...@gmail.com>
---
 mkfs/f2fs_format.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/mkfs/f2fs_format.c b/mkfs/f2fs_format.c
index 3c13026..2e0a4e5 100644
--- a/mkfs/f2fs_format.c
+++ b/mkfs/f2fs_format.c
@@ -337,10 +337,6 @@ static int f2fs_prepare_super_block(void)
if (c.overprovision == 0)
c.overprovision = get_best_overprovision(sb);
 
-   c.reserved_segments =
-   (2 * (100 / c.overprovision + 1) + 6)
-   * c.segs_per_sec;
-
if (c.overprovision == 0 || c.total_segments < F2FS_MIN_SEGMENTS ||
(c.devices[0].total_sectors *
c.sector_size < zone_align_start_offset) ||
@@ -349,6 +345,10 @@ static int f2fs_prepare_super_block(void)
return -1;
}
 
+   c.reserved_segments =
+   (2 * (100 / c.overprovision + 1) + 6)
+   * c.segs_per_sec;
+
uuid_generate(sb->uuid);
 
utf8_to_utf16(sb->volume_name, (const char *)c.vol_label,
-- 
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


Re: [f2fs-dev] [PATCH] mkfs.f2fs: fix bad assignment of total_sectors for f2fs_configuration

2017-02-03 Thread Kinglong Mee
On 1/24/2017 11:06, Sheng Yong wrote:
> Hi, Kinglong
> 
> On 1/24/2017 10:42 AM, Kinglong Mee wrote:
>> wanted_total_sectors is introduced instead total_sectors,
>> so that, the initialize is a fault, drop it.
>>
>> Signed-off-by: Kinglong Mee <kinglong...@gmail.com>
>> ---
>>  mkfs/f2fs_format_main.c | 3 ---
>>  1 file changed, 3 deletions(-)
>>
>> diff --git a/mkfs/f2fs_format_main.c b/mkfs/f2fs_format_main.c
>> index db1dc94..5bb1faf 100644
>> --- a/mkfs/f2fs_format_main.c
>> +++ b/mkfs/f2fs_format_main.c
>> @@ -151,9 +151,6 @@ static void f2fs_parse_options(int argc, char *argv[])
>>  c.wanted_total_sectors = atoll(argv[optind+1]);
>>  }
>>  
>> -if ((optind + 1) < argc)
>> -c.total_sectors = atoll(argv[optind+1]);
>> -
> Here we get the number of sectors specified by user, so that we could
> create an image based on a specific size. There seems no fault. Could
> you please give more detail :)

Sorry for the late reply.

Commit de7e07e011 "f2fs-tools: support multiple devices" changes the using of
c.total_sectors, adds wanted_total_sectors instead it. 
c.total_sectors must be initialized as zero (drop the fault assignment).

Used as, 
int get_device_info(struct device_info *dev)
...
c.total_sectors += dev->total_sectors;

After that, mkfs.f2fs will fail with specified lager size than disk.
# fdisk -ls /dev/sdb1
20970496
# mkfs.f2fs /dev/sdb1 209704961

F2FS-tools: mkfs.f2fs Ver: 1.7.0 (2017-01-13)

Info: Debug level = 0
Info: Trim is enabled
Info: [/dev/sdb1] Disk Model: VMware Virtual S1.0
Info: total device sectors = 251645953 (in 512 bytes)
Info: Segments per section = 1
Info: Sections per zone = 1
Info: sector size = 512
Info: total sectors = 209704961 (102395 MB)
Info: zone aligned segment0 blkaddr: 256
Info: format version with
  "Linux version 4.10.0-rc6+ (root@localhost) (gcc version 6.3.1 20161221 (Red 
Hat 6.3.1-1) (GCC) ) #483 SMP Fri Feb 3 13:58:56 CST 2017"
Info: [/dev/sdb1] Discarding device
Info: This device doesn't support BLKSECDISCARD
Info: This device doesn't support BLKDISCARD
Error: Failed to create the root directory!!!
Error: Could not format the device!!!

With this patch, mkfs.f2fs success as,
#  mkfs.f2fs /dev/sdb1 209704961

F2FS-tools: mkfs.f2fs Ver: 1.7.0 (2017-01-13)

Info: Debug level = 0
Info: Trim is enabled
Info: [/dev/sdb1] Disk Model: VMware Virtual S1.0
Info: Segments per section = 1
Info: Sections per zone = 1
Info: sector size = 512
Info: total sectors = 41940992 (20479 MB)
Info: zone aligned segment0 blkaddr: 256
Info: format version with
  "Linux version 4.10.0-rc6+ (root@localhost) (gcc version 6.3.1 20161221 (Red 
Hat 6.3.1-1) (GCC) ) #483 SMP Fri Feb 3 13:58:56 CST 2017"
Info: [/dev/sdb1] Discarding device
Info: This device doesn't support BLKSECDISCARD
Info: This device doesn't support BLKDISCARD
Info: Overprovision ratio = 1.400%
Info: Overprovision segments = 290 (GC reserved = 150)
Info: format successful

thanks,
Kinglong Mee

> thanks,
> Sheng
>>  if (c.zoned_mode)
>>  c.feature |= cpu_to_le32(F2FS_FEATURE_BLKZONED);
>>  }
>>
> 
> 

--
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] [f2fs-dev PATCH] mkfs.f2fs: fix a segfault when setting more than 7 devices

2017-01-22 Thread Kinglong Mee
[root@localhost f2fs-tools]# mkfs.f2fs -c /dev/sdb1 -c /dev/sdb1 -c /dev/sdb1 
-c /dev/sdb1 -c /dev/sdb1 -c /dev/sdb1 -c /dev/sdb1 -c /dev/sdb1 -c /dev/sdb1 
/dev/sdb1 

kernel: mkfs.f2fs[9047]: segfault at 2b78a60f ip 00401356 sp 
7fffde05c9c0 error 6 in mkfs.f2fs[40+5000]

Signed-off-by: Kinglong Mee <kinglong...@gmail.com>
---
 mkfs/f2fs_format_main.c | 13 +++--
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/mkfs/f2fs_format_main.c b/mkfs/f2fs_format_main.c
index 70ed77a..db1dc94 100644
--- a/mkfs/f2fs_format_main.c
+++ b/mkfs/f2fs_format_main.c
@@ -28,7 +28,7 @@ static void mkfs_usage()
MSG(0, "\nUsage: mkfs.f2fs [options] device [sectors]\n");
MSG(0, "[options]:\n");
MSG(0, "  -a heap-based allocation [default:1]\n");
-   MSG(0, "  -c [device path]\n");
+   MSG(0, "  -c [device path] up to 7 devices excepts meta device\n");
MSG(0, "  -d debug level [default:0]\n");
MSG(0, "  -e [extension list] e.g. \"mp3,gif,mov\"\n");
MSG(0, "  -l label\n");
@@ -84,6 +84,11 @@ static void f2fs_parse_options(int argc, char *argv[])
c.heap = atoi(optarg);
break;
case 'c':
+   if (c.ndevs >= MAX_DEVICES) {
+   MSG(0, "Error: Too many devices\n");
+   mkfs_usage();
+   }
+
if (strlen(optarg) > MAX_PATH_LEN) {
MSG(0, "Error: device path should be less than "
"%d characters\n", MAX_PATH_LEN);
@@ -135,12 +140,8 @@ static void f2fs_parse_options(int argc, char *argv[])
mkfs_usage();
}
 
-   /* [0] : META, [1 to MAX_DEVICES + 1] : NODE/DATA */
+   /* [0] : META, [1 to MAX_DEVICES - 1] : NODE/DATA */
c.devices[0].path = strdup(argv[optind]);
-   if (c.ndevs > MAX_DEVICES) {
-   MSG(0, "\tError: Too many devices\n");
-   mkfs_usage();
-   }
 
if ((optind + 1) < argc) {
if (c.ndevs > 1) {
-- 
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


[f2fs-dev] [PATCH] f2fs: don't reserve block for empty file when convert inline, page

2017-01-02 Thread Kinglong Mee
A test program gets the SEEK_DATA with two values between
a new created file and the exist file on f2fs filesystem. 

F2FS filesystem,  (the first "test1" is a new file)
# ./lseektest /f2fs/test1
SEEK_DATA size != 0 (offset = 8192)
# ./lseektest /f2fs/test1
SEEK_DATA size != 0 (offset = 4096)

PNFS filesystem, (the first "test1" is a new file)
# ./lseektest /pnfs/test1
SEEK_DATA size != 0 (offset = 4096)
# ./lseektest /pnfs/test1
SEEK_DATA size != 0 (offset = 4096)

# cat lseektest.c

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

#ifndef SEEK_DATA
#define SEEK_DATA  3
#define SEEK_HOLE  4
#endif

int main(int argc, char **argv)
{
char *filename = argv[1];
int offset = 1, i = 0, fd = -1;

if (argc < 2) {
printf("Usage: %s f2fsfilename\n", argv[0]);
return -1;
}

/*
if (!access(filename, F_OK) || errno != ENOENT) {
printf("Needs a new file for test, %m\n");
return -1;
}*/

fd = open(filename, O_RDWR | O_CREAT, 0777);
if (fd < 0) {
printf("Create test file %s failed, %m\n", filename);
return -1;
}

for (i = 0; i < 20; i++) {
offset = 1 << i;
ftruncate(fd, 0);
lseek(fd, offset, SEEK_SET);
write(fd, "test", 5);
/* Get the alloc size by seek data equal zero*/
if (lseek(fd, 0, SEEK_DATA)) {
printf("SEEK_DATA size != 0 (offset = %d)\n", offset);
break;
        }
}

close(fd);
return 0;
}

Signed-off-by: Kinglong Mee <kinglong...@gmail.com>
---
 fs/f2fs/inline.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/f2fs/inline.c b/fs/f2fs/inline.c
index e32a9e5..6c8d099 100644
--- a/fs/f2fs/inline.c
+++ b/fs/f2fs/inline.c
@@ -117,7 +117,7 @@ int f2fs_convert_inline_page(struct dnode_of_data *dn, 
struct page *page)
};
int dirty, err;
 
-   if (!f2fs_exist_data(dn->inode))
+   if (!f2fs_exist_data(dn->inode) || !i_size_read(dn->inode))
goto clear_out;
 
err = f2fs_reserve_block(dn, 0);
-- 
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


Re: [f2fs-dev] [PATCH RESEND 1/2] mkfs.f2fs: support large sector size

2015-02-05 Thread Kinglong Mee
On Thu, Feb 5, 2015 at 5:36 PM, Chao Yu chao2...@samsung.com wrote:
 Since f2fs support large sector size in commit 55cf9cb63f0e f2fs: support 
 large
 sector size, block device with sector size of 512/1024/2048/4096 bytes can be
 supported.

 But mkfs.f2fs still use default sector size: 512 bytes as sector size, let's 
 fix
 this issue in this patch.

 v2:
  o remove unneeded printed message when sector size is large than 512 bytes
suggested by Kinglong.
  o show correct sector size in printed message.
  o use config.sectors_per_blk instead of DEFAULT_SECTORS_PER_BLOCK suggested 
 by
Kinglong.
 v3:
  o remove another unneeded printed message when sector size is large than 512
bytes suggested by Kinglong.

 Signed-off-by: Chao Yu chao2...@samsung.com

Reviewed-by: Kinglong Mee kinglong...@gmail.com

thanks,
Kinglong Mee

--
Dive into the World of Parallel Programming. The Go Parallel Website,
sponsored by Intel and developed in partnership with Slashdot Media, is your
hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials and more. Take a
look and join the conversation now. http://goparallel.sourceforge.net/
___
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/2] mkfs.f2fs: support large sector size

2015-02-04 Thread Kinglong Mee
Hi Chao,

On Wed, Feb 4, 2015 at 11:30 AM, Chao Yu chao2...@samsung.com wrote:
 Since f2fs support large sector size in commit 55cf9cb63f0e f2fs: support 
 large
 sector size, block device with sector size of 512/1024/2048/4096 bytes can be
 supported.

 But mkfs.f2fs still use default sector size: 512 bytes as sector size, let's 
 fix
 this issue in this patch.

 v2:
  o remove unneeded printed message when sector size is large than 512 bytes
suggested by Kinglong.
  o show correct sector size in printed message.
  o use config.sectors_per_blk instead of DEFAULT_SECTORS_PER_BLOCK suggested 
 by
Kinglong.

 Signed-off-by: Chao Yu chao2...@samsung.com
 ---
  lib/libf2fs.c| 10 +++---
  mkfs/f2fs_format.c   | 12 ++--
  mkfs/f2fs_format_utils.c |  2 +-
  3 files changed, 10 insertions(+), 14 deletions(-)

 diff --git a/lib/libf2fs.c b/lib/libf2fs.c
 index 8123528..d2942f0 100644
 --- a/lib/libf2fs.c
 +++ b/lib/libf2fs.c
 @@ -463,10 +463,6 @@ int f2fs_get_device_info(struct f2fs_configuration *c)
 MSG(0, \tError: Using the default sector size\n);
 } else {
 if (c-sector_size  sector_size) {
 -   MSG(0, \tError: Cannot set the sector size 
 to:
 -%d as the device does not support
 -   \nSetting the sector size to : %d\n,
 -   c-sector_size, sector_size);
 c-sector_size = sector_size;
 c-sectors_per_blk = PAGE_SIZE / sector_size;
 }
 @@ -495,8 +491,8 @@ int f2fs_get_device_info(struct f2fs_configuration *c)
 return -1;
 }
 if (wanted_total_sectors  wanted_total_sectors  c-total_sectors) {
 -   MSG(0, Info: total device sectors = %PRIu64 (in 
 512bytes)\n,
 -   c-total_sectors);
 +   MSG(0, Info: total device sectors = %PRIu64 (in %u 
 bytes)\n,
 +   c-total_sectors, c-sector_size);
 c-total_sectors = wanted_total_sectors;

 }
 @@ -504,7 +500,7 @@ int f2fs_get_device_info(struct f2fs_configuration *c)
 MSG(0, Info: total sectors = %PRIu64 (in 512bytes)\n,

This 512bytes should be modified as above too.

thanks,
Kinglong Mee

--
Dive into the World of Parallel Programming. The Go Parallel Website,
sponsored by Intel and developed in partnership with Slashdot Media, is your
hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials and more. Take a
look and join the conversation now. http://goparallel.sourceforge.net/
___
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel


Re: [f2fs-dev] [PATCH] mkfs.f2fs: support large sector size

2015-01-30 Thread Kinglong Mee
On Fri, Jan 30, 2015 at 3:49 PM, Chao Yu chao2...@samsung.com wrote:
 Since f2fs support large sector size in commit 55cf9cb63f0e f2fs: support 
 large
 sector size, block device with sector size of 512/1024/2048/4096 bytes can be
 supported.

 But mkfs.f2fs still use default sector size: 512 bytes as sector size, let's 
 fix
 this issue in this patch.

 Signed-off-by: Chao Yu chao2...@samsung.com
 ---
  lib/libf2fs.c| 2 +-
  mkfs/f2fs_format.c   | 6 +++---
  mkfs/f2fs_format_utils.c | 2 +-
  3 files changed, 5 insertions(+), 5 deletions(-)

 diff --git a/lib/libf2fs.c b/lib/libf2fs.c
 index 8123528..9b9578b 100644
 --- a/lib/libf2fs.c
 +++ b/lib/libf2fs.c
 @@ -504,7 +504,7 @@ int f2fs_get_device_info(struct f2fs_configuration *c)
 MSG(0, Info: total sectors = %PRIu64 (in 512bytes)\n,

Should using c-sector_size instead 512bytes here ?

 c-total_sectors);
 if (c-total_sectors 
 -   (F2FS_MIN_VOLUME_SIZE / DEFAULT_SECTOR_SIZE)) {
 +   (F2FS_MIN_VOLUME_SIZE / c-sector_size)) {
 MSG(0, Error: Min volume size supported is %d\n,
 F2FS_MIN_VOLUME_SIZE);
 return -1;
 diff --git a/mkfs/f2fs_format.c b/mkfs/f2fs_format.c
 index a8d2db6..861fe2f 100644
 --- a/mkfs/f2fs_format.c
 +++ b/mkfs/f2fs_format.c
 @@ -198,10 +198,10 @@ static int f2fs_prepare_super_block(void)
 set_sb(block_count, config.total_sectors  log_sectors_per_block);

 zone_align_start_offset =
 -   (config.start_sector * DEFAULT_SECTOR_SIZE +
 +   (config.start_sector * config.sector_size +
 2 * F2FS_BLKSIZE + zone_size_bytes - 1) /
 zone_size_bytes * zone_size_bytes -
 -   config.start_sector * DEFAULT_SECTOR_SIZE;
 +   config.start_sector * config.sector_size;

 if (config.start_sector % DEFAULT_SECTORS_PER_BLOCK) {

and,
DEFAULT_SECTORS_PER_BLOCK should be instead by config.sectors_per_blk
at the same patch ?

thanks,
Kinglong Mee

--
Dive into the World of Parallel Programming. The Go Parallel Website,
sponsored by Intel and developed in partnership with Slashdot Media, is your
hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials and more. Take a
look and join the conversation now. http://goparallel.sourceforge.net/
___
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel


[f2fs-dev] [PATCH] f2fs: fix a bug of inheriting default ACL from parent

2015-01-24 Thread Kinglong Mee
Introduced by a6dda0e63e97122ce9e0ba04367e37cca28315fa
f2fs: use generic posix ACL infrastructure.

When testing default acl, gets in recent kernel (3.19.0-rc5),
# setfacl -dm g:root:rwx test/
# getfacl test/
# file: test/
# owner: root
# group: root
user::rwx
group::r-x
other::r-x
default:user::rwx
default:group::r-x
default:group:root:rwx
default:mask::rwx
default:other::r-x

# cd test/
# mkdir testdir
]# getfacl testdir/
# file: testdir/
# owner: root
# group: root
user::rwx
group::rwx
// missing an acl group:root:rwx inherited from parent
other::r-x
default:user::rwx
default:group::r-x
default:group:root:rwx
default:mask::rwx
default:other::r-x

Signed-off-by: Kinglong Mee kinglong...@gmail.com
---
 fs/f2fs/acl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/f2fs/acl.c b/fs/f2fs/acl.c
index 1ccb26b..b0b23578 100644
--- a/fs/f2fs/acl.c
+++ b/fs/f2fs/acl.c
@@ -396,7 +396,7 @@ int f2fs_init_acl(struct inode *inode, struct inode 
*dir, struct page *ipage,
posix_acl_release(default_acl);
}
if (acl) {
-   if (error)
+   if (!error)
error = __f2fs_set_acl(inode, ACL_TYPE_ACCESS, acl,
   ipage);
posix_acl_release(acl);
-- 
2.1.0


--
New Year. New Location. New Benefits. New Data Center in Ashburn, VA.
GigeNET is offering a free month of service with a new server in Ashburn.
Choose from 2 high performing configs, both with 100TB of bandwidth.
Higher redundancy.Lower latency.Increased capacity.Completely compliant.
http://p.sf.net/sfu/gigenet
___
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel