Re: [f2fs-dev] [PATCH] resize.f2fs: fix an error in migrate_ssa

2016-11-24 Thread Junling Zheng
Sorry, I forget to get the return value of dev_write_block :(
Please review the following patch :)

---
 fsck/resize.c | 25 ++---
 1 file changed, 14 insertions(+), 11 deletions(-)

diff --git a/fsck/resize.c b/fsck/resize.c
index 46aa30e..9f9c7a6 100644
--- a/fsck/resize.c
+++ b/fsck/resize.c
@@ -207,30 +207,33 @@ static void migrate_ssa(struct f2fs_sb_info *sbi,
block_t old_sum_blkaddr = get_sb(ssa_blkaddr);
block_t new_sum_blkaddr = get_newsb(ssa_blkaddr);
block_t end_sum_blkaddr = get_newsb(main_blkaddr);
+   block_t expand_sum_blkaddr = new_sum_blkaddr +
+   TOTAL_SEGS(sbi) - offset;
block_t blkaddr;
+   int ret;
void *zero_block = calloc(BLOCK_SZ, 1);
-
ASSERT(zero_block);

if (offset && new_sum_blkaddr < old_sum_blkaddr + offset) {
blkaddr = new_sum_blkaddr;
while (blkaddr < end_sum_blkaddr) {
-   if (blkaddr - new_sum_blkaddr < TOTAL_SEGS(sbi))
-   move_ssa(sbi, offset, blkaddr);
-   else
-   dev_write_block(zero_block, blkaddr);
-   offset++;
-   blkaddr++;
+   if (blkaddr < expand_sum_blkaddr)
+   move_ssa(sbi, offset++, blkaddr++);
+   else {
+   ret = dev_write_block(zero_block, blkaddr++);
+   ASSERT(ret >=0);
+   }
}
} else {
blkaddr = end_sum_blkaddr - 1;
offset = TOTAL_SEGS(sbi) - 1;
while (blkaddr >= new_sum_blkaddr) {
-   if (blkaddr >= TOTAL_SEGS(sbi) + new_sum_blkaddr)
-   dev_write_block(zero_block, blkaddr);
+   if (blkaddr >= expand_sum_blkaddr) {
+   ret = dev_write_block(zero_block, blkaddr--);
+   ASSERT(ret >=0);
+   }
else
-   move_ssa(sbi, offset--, blkaddr);
-   blkaddr--;
+   move_ssa(sbi, offset--, blkaddr--);
}
}


On 2016/11/25 11:32, Junling Zheng wrote:
> How about the following patch, which I think would be a little better :)
> 
> diff --git a/fsck/resize.c b/fsck/resize.c
> index 46aa30e..c295a06 100644
> --- a/fsck/resize.c
> +++ b/fsck/resize.c
> @@ -207,30 +207,33 @@ static void migrate_ssa(struct f2fs_sb_info *sbi,
>   block_t old_sum_blkaddr = get_sb(ssa_blkaddr);
>   block_t new_sum_blkaddr = get_newsb(ssa_blkaddr);
>   block_t end_sum_blkaddr = get_newsb(main_blkaddr);
> + block_t expand_sum_blkaddr = new_sum_blkaddr +
> + TOTAL_SEGS(sbi) - offset;
>   block_t blkaddr;
> + int ret;
>   void *zero_block = calloc(BLOCK_SZ, 1);
> -
>   ASSERT(zero_block);
> 
>   if (offset && new_sum_blkaddr < old_sum_blkaddr + offset) {
>   blkaddr = new_sum_blkaddr;
>   while (blkaddr < end_sum_blkaddr) {
> - if (blkaddr - new_sum_blkaddr < TOTAL_SEGS(sbi))
> - move_ssa(sbi, offset, blkaddr);
> - else
> - dev_write_block(zero_block, blkaddr);
> - offset++;
> - blkaddr++;
> + if (blkaddr < expand_sum_blkaddr)
> + move_ssa(sbi, offset++, blkaddr++);
> + else {
> + dev_write_block(zero_block, blkaddr++);
> + ASSERT(ret >=0);

forget to get the return value of dev_write_block :(

> + }
>   }
>   } else {
>   blkaddr = end_sum_blkaddr - 1;
>   offset = TOTAL_SEGS(sbi) - 1;
>   while (blkaddr >= new_sum_blkaddr) {
> - if (blkaddr >= TOTAL_SEGS(sbi) + new_sum_blkaddr)
> - dev_write_block(zero_block, blkaddr);
> + if (blkaddr >= expand_sum_blkaddr) {
> + dev_write_block(zero_block, blkaddr--);
> + ASSERT(ret >=0);
> + }
>   else
> - move_ssa(sbi, offset--, blkaddr);
> - blkaddr--;
> + move_ssa(sbi, offset--, blkaddr--);
>   }
>   }
> 
> 
> On 2016/11/24 15:33, Yunlei He wrote:
>> This patch fix an error in migrate_ssa when resize with condition
>> that offset is not zero && new_sum_blkaddr > old_sum_blkaddr + offset
>>
>> Signed-off-by: Yunlei He 
>> ---
>>  fsck/resize.c | 37 +++--
>>  1 file changed, 27 insertions(+), 10 delet

Re: [f2fs-dev] [PATCH] resize.f2fs: fix an error in migrate_ssa

2016-11-24 Thread Junling Zheng
How about the following patch, which I think would be a little better :)

diff --git a/fsck/resize.c b/fsck/resize.c
index 46aa30e..c295a06 100644
--- a/fsck/resize.c
+++ b/fsck/resize.c
@@ -207,30 +207,33 @@ static void migrate_ssa(struct f2fs_sb_info *sbi,
block_t old_sum_blkaddr = get_sb(ssa_blkaddr);
block_t new_sum_blkaddr = get_newsb(ssa_blkaddr);
block_t end_sum_blkaddr = get_newsb(main_blkaddr);
+   block_t expand_sum_blkaddr = new_sum_blkaddr +
+   TOTAL_SEGS(sbi) - offset;
block_t blkaddr;
+   int ret;
void *zero_block = calloc(BLOCK_SZ, 1);
-
ASSERT(zero_block);

if (offset && new_sum_blkaddr < old_sum_blkaddr + offset) {
blkaddr = new_sum_blkaddr;
while (blkaddr < end_sum_blkaddr) {
-   if (blkaddr - new_sum_blkaddr < TOTAL_SEGS(sbi))
-   move_ssa(sbi, offset, blkaddr);
-   else
-   dev_write_block(zero_block, blkaddr);
-   offset++;
-   blkaddr++;
+   if (blkaddr < expand_sum_blkaddr)
+   move_ssa(sbi, offset++, blkaddr++);
+   else {
+   dev_write_block(zero_block, blkaddr++);
+   ASSERT(ret >=0);
+   }
}
} else {
blkaddr = end_sum_blkaddr - 1;
offset = TOTAL_SEGS(sbi) - 1;
while (blkaddr >= new_sum_blkaddr) {
-   if (blkaddr >= TOTAL_SEGS(sbi) + new_sum_blkaddr)
-   dev_write_block(zero_block, blkaddr);
+   if (blkaddr >= expand_sum_blkaddr) {
+   dev_write_block(zero_block, blkaddr--);
+   ASSERT(ret >=0);
+   }
else
-   move_ssa(sbi, offset--, blkaddr);
-   blkaddr--;
+   move_ssa(sbi, offset--, blkaddr--);
}
}


On 2016/11/24 15:33, Yunlei He wrote:
> This patch fix an error in migrate_ssa when resize with condition
> that offset is not zero && new_sum_blkaddr > old_sum_blkaddr + offset
> 
> Signed-off-by: Yunlei He 
> ---
>  fsck/resize.c | 37 +++--
>  1 file changed, 27 insertions(+), 10 deletions(-)
> 
> diff --git a/fsck/resize.c b/fsck/resize.c
> index 46aa30e..70dbef5 100644
> --- a/fsck/resize.c
> +++ b/fsck/resize.c
> @@ -208,28 +208,45 @@ static void migrate_ssa(struct f2fs_sb_info *sbi,
>   block_t new_sum_blkaddr = get_newsb(ssa_blkaddr);
>   block_t end_sum_blkaddr = get_newsb(main_blkaddr);
>   block_t blkaddr;
> + unsigned int offset1 = offset;
> + int ret = 1;
>   void *zero_block = calloc(BLOCK_SZ, 1);
>  
>   ASSERT(zero_block);
>  
> - if (offset && new_sum_blkaddr < old_sum_blkaddr + offset) {
> - blkaddr = new_sum_blkaddr;
> - while (blkaddr < end_sum_blkaddr) {
> - if (blkaddr - new_sum_blkaddr < TOTAL_SEGS(sbi))
> - move_ssa(sbi, offset, blkaddr);
> - else
> - dev_write_block(zero_block, blkaddr);
> - offset++;
> - blkaddr++;
> + if (offset) {
> + if (new_sum_blkaddr < old_sum_blkaddr + offset) {
> + blkaddr = new_sum_blkaddr;
> + while (blkaddr < end_sum_blkaddr) {
> + if (blkaddr - new_sum_blkaddr < TOTAL_SEGS(sbi) 
> - offset1)
> + move_ssa(sbi, offset, blkaddr);
> + else
> + ret = dev_write_block(zero_block, 
> blkaddr);
> + ASSERT(ret >= 0);
> + offset++;
> + blkaddr++;
> + }
> + } else {
> + blkaddr = end_sum_blkaddr - 1;
> + offset = TOTAL_SEGS(sbi)-1;
> + while (blkaddr >= new_sum_blkaddr) {
> + if (blkaddr >= TOTAL_SEGS(sbi) - offset1 + 
> new_sum_blkaddr)
> + ret = dev_write_block(zero_block, 
> blkaddr);
> + else
> + move_ssa(sbi, offset--, blkaddr);
> + ASSERT(ret >= 0);
> + blkaddr--;
> + }
>   }
>   } else {
>   blkaddr = end_sum_blkaddr - 1;
>   offset = TOTAL_SEGS(sbi) - 1;
>   while (blkaddr >= new_sum_blkaddr) {
>   if (blkaddr >= TOTAL_SEGS(sbi) + new_sum_blkaddr)
> -

[f2fs-dev] [PATCH] mkfs.f2fs: give random checkpoint version

2016-11-24 Thread Jaegeuk Kim
This is to avoid wrong recovery during xfstests.

Signed-off-by: Jaegeuk Kim 
---
 mkfs/f2fs_format.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mkfs/f2fs_format.c b/mkfs/f2fs_format.c
index 9a536f0..d2254e7 100644
--- a/mkfs/f2fs_format.c
+++ b/mkfs/f2fs_format.c
@@ -507,7 +507,7 @@ static int f2fs_write_check_point_pack(void)
}
 
/* 1. cp page 1 of checkpoint pack 1 */
-   set_cp(checkpoint_ver, 1);
+   cp->checkpoint_ver = rand();
set_cp(cur_node_segno[0], c.cur_seg[CURSEG_HOT_NODE]);
set_cp(cur_node_segno[1], c.cur_seg[CURSEG_WARM_NODE]);
set_cp(cur_node_segno[2], c.cur_seg[CURSEG_COLD_NODE]);
-- 
2.8.3


--
___
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 to determine start_cp_addr by sbi->cur_cp_pack

2016-11-24 Thread Jaegeuk Kim
We don't guarantee cp_addr is fixed by cp_version.
This is to sync with f2fs-tools.

Cc: sta...@vger.kernel.org
Signed-off-by: Jaegeuk Kim 
---
 fs/f2fs/checkpoint.c |  5 +
 fs/f2fs/f2fs.h   | 14 +++---
 2 files changed, 8 insertions(+), 11 deletions(-)

diff --git a/fs/f2fs/checkpoint.c b/fs/f2fs/checkpoint.c
index 54cc6a9..bf2f44c 100644
--- a/fs/f2fs/checkpoint.c
+++ b/fs/f2fs/checkpoint.c
@@ -789,6 +789,11 @@ int get_valid_checkpoint(struct f2fs_sb_info *sbi)
f2fs_put_page(cur_page, 1);
}
 done:
+   if (cur_page == cp1)
+   sbi->cur_cp_pack = 1;
+   else
+   sbi->cur_cp_pack = 2;
+
f2fs_put_page(cp1, 1);
f2fs_put_page(cp2, 1);
return 0;
diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
index 62383d2..e22e7e1 100644
--- a/fs/f2fs/f2fs.h
+++ b/fs/f2fs/f2fs.h
@@ -792,6 +792,7 @@ struct f2fs_sb_info {
 
/* for checkpoint */
struct f2fs_checkpoint *ckpt;   /* raw checkpoint pointer */
+   int cur_cp_pack;/* remain current cp pack */
spinlock_t cp_lock; /* for flag in ckpt */
struct inode *meta_inode;   /* cache meta blocks */
struct mutex cp_mutex;  /* checkpoint procedure lock */
@@ -1352,19 +1353,10 @@ static inline void *__bitmap_ptr(struct f2fs_sb_info 
*sbi, int flag)
 
 static inline block_t __start_cp_addr(struct f2fs_sb_info *sbi)
 {
-   block_t start_addr;
-   struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi);
-   unsigned long long ckpt_version = cur_cp_version(ckpt);
-
-   start_addr = le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_blkaddr);
+   block_t start_addr = le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_blkaddr);
 
-   /*
-* odd numbered checkpoint should at cp segment 0
-* and even segment must be at cp segment 1
-*/
-   if (!(ckpt_version & 1))
+   if (sbi->cur_cp_pack == 2)
start_addr += sbi->blocks_per_seg;
-
return start_addr;
 }
 
-- 
2.8.3


--
___
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel


Re: [f2fs-dev] fsck is broken on mips32 platform

2016-11-24 Thread Sheng Yong
Hi,

On 11/25/2016 6:30 AM, k...@vodka.home.kg wrote:
> Hi !
> 
> I'm using f2fs on router Dlink dir-825 with openwrt/LEDE firmware.
> Its mips32 rel 2 big endian cpu.
> 
> mkfs.f2fs - works
> mount - works
> fsck.f2fs - corrupts filesystem
> 
> # i'm  trying  to fsck valid empty mountable f2fs partition i have just 
> mkfs'ed
> fsck.f2fs /dev/sda2
> Info: Segments per section = 1
> Info: Sections per zone = 1
> Info: sector size = 512
> Info: total sectors = 6508544 (3178 MB)
> Info: MKFS version
>   "Linux version 4.4.0-21-generic (buildd@lgw01-21) (gcc version 5.3.1 
> 20160413 (Ubuntu 5.3.1-14ubuntu2) ) #37-Ubuntu SMP Mon Apr 18 18:33:37 UTC 
> 2016"
> Info: FSCK version
>   from "Linux version 4.4.0-21-generic (buildd@lgw01-21) (gcc version 5.3.1 
> 20160413 (Ubuntu 5.3.1-14ubuntu2) ) #37-Ubuntu SMP Mon Apr 18 18:33:37 UTC 
> 2016"
> to "Linux version 4.4.30 (vasya@nowhere) (gcc version 5.4.0 (LEDE GCC 
> 5.4.0 r2084) ) #0 PREEMPT Thu Nov 3 07:34:38 2016"
> Info: superblock features = 0 : 
> Info: superblock encrypt level = 0, salt = 
> Info: total FS sectors = 6508544 (3178 MB)
> Info: CKPT version = 1
> Info: checkpoint state = 5 :  compacted_summary unmount
> [ASSERT] (sanity_check_nid: 356)  --> nid is not valid. [0x3]
It seems that sanity_check_nid does not switch little endian value to big 
endian.
I'm not sure if it is caused by this and if there are any other places have this
endian switch issue, could you please test this.

thanks,
Sheng

==

diff --git a/fsck/f2fs.h b/fsck/f2fs.h
index 39ff161..9dc832c 100644
--- a/fsck/f2fs.h
+++ b/fsck/f2fs.h
@@ -370,7 +370,7 @@ static inline block_t sum_blk_addr(struct f2fs_sb_info 
*sbi, int base, int type)
 static inline bool IS_VALID_NID(struct f2fs_sb_info *sbi, u32 nid)
 {
return (nid <= (NAT_ENTRY_PER_BLOCK *
-   F2FS_RAW_SUPER(sbi)->segment_count_nat
+   le32_to_cpu(F2FS_RAW_SUPER(sbi)->segment_count_nat)
<< (sbi->log_blocks_per_seg - 1)));
 }

@@ -378,7 +378,7 @@ static inline bool IS_VALID_BLK_ADDR(struct f2fs_sb_info 
*sbi, u32 addr)
 {
int i;

-   if (addr >= F2FS_RAW_SUPER(sbi)->block_count ||
+   if (addr >= le64_to_cpu(F2FS_RAW_SUPER(sbi)->block_count) ||
addr < SM_I(sbi)->main_blkaddr) {
DBG(1, "block addr [0x%x]\n", addr);
return 0;
> 
> NID[0x3] is unreachable
> [FSCK] Unreachable nat entries[Fail] [0x1]
> [FSCK] SIT valid block bitmap checking[Fail]
> [FSCK] Hard link checking for regular file[Ok..] [0x0]
> [FSCK] valid_block_count matching with CP [Fail] [0x0]
> [FSCK] valid_node_count matcing with CP (de lookup)   [Fail] [0x0]
> [FSCK] valid_node_count matcing with CP (nat lookup)  [Ok..] [0x1]
> [FSCK] valid_inode_count matched with CP  [Fail] [0x0]
> [FSCK] free segment_count matched with CP [Fail] [0x621]
> [FSCK] next block offset is free  [Ok..]
> [FSCK] fixing SIT types
> [FSCK] other corrupted bugs   [Fail]
> [FIX] (nullify_nat_entry:1688)  --> Remove nid [0x3] in nat journal
> 
> After failed mount attempt :
> 
> dmesg
> F2FS-fs (sda2): Failed to read root inode
> 
> On x86 and ARM everything is ok
> 
> f2fs-tools 1.7.0
> kernel 4.4.30
> 
> 
> --
> ___
> Linux-f2fs-devel mailing list
> Linux-f2fs-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
> 
> .
> 


--
___
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel


[f2fs-dev] fsck is broken on mips32 platform

2016-11-24 Thread k
Hi !

I'm using f2fs on router Dlink dir-825 with openwrt/LEDE firmware.
Its mips32 rel 2 big endian cpu.

mkfs.f2fs - works
mount - works
fsck.f2fs - corrupts filesystem

# i'm  trying  to fsck valid empty mountable f2fs partition i have just mkfs'ed
fsck.f2fs /dev/sda2
Info: Segments per section = 1
Info: Sections per zone = 1
Info: sector size = 512
Info: total sectors = 6508544 (3178 MB)
Info: MKFS version
  "Linux version 4.4.0-21-generic (buildd@lgw01-21) (gcc version 5.3.1 20160413 
(Ubuntu 5.3.1-14ubuntu2) ) #37-Ubuntu SMP Mon Apr 18 18:33:37 UTC 2016"
Info: FSCK version
  from "Linux version 4.4.0-21-generic (buildd@lgw01-21) (gcc version 5.3.1 
20160413 (Ubuntu 5.3.1-14ubuntu2) ) #37-Ubuntu SMP Mon Apr 18 18:33:37 UTC 2016"
to "Linux version 4.4.30 (vasya@nowhere) (gcc version 5.4.0 (LEDE GCC 5.4.0 
r2084) ) #0 PREEMPT Thu Nov 3 07:34:38 2016"
Info: superblock features = 0 : 
Info: superblock encrypt level = 0, salt = 
Info: total FS sectors = 6508544 (3178 MB)
Info: CKPT version = 1
Info: checkpoint state = 5 :  compacted_summary unmount
[ASSERT] (sanity_check_nid: 356)  --> nid is not valid. [0x3]

NID[0x3] is unreachable
[FSCK] Unreachable nat entries[Fail] [0x1]
[FSCK] SIT valid block bitmap checking[Fail]
[FSCK] Hard link checking for regular file[Ok..] [0x0]
[FSCK] valid_block_count matching with CP [Fail] [0x0]
[FSCK] valid_node_count matcing with CP (de lookup)   [Fail] [0x0]
[FSCK] valid_node_count matcing with CP (nat lookup)  [Ok..] [0x1]
[FSCK] valid_inode_count matched with CP  [Fail] [0x0]
[FSCK] free segment_count matched with CP [Fail] [0x621]
[FSCK] next block offset is free  [Ok..]
[FSCK] fixing SIT types
[FSCK] other corrupted bugs   [Fail]
[FIX] (nullify_nat_entry:1688)  --> Remove nid [0x3] in nat journal

After failed mount attempt :

dmesg
F2FS-fs (sda2): Failed to read root inode

On x86 and ARM everything is ok

f2fs-tools 1.7.0
kernel 4.4.30


--
___
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel