aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--fs/f2fs/node.c13
1 files changed, 7 insertions, 6 deletions
diff --git a/fs/f2fs/node.c b/fs/f2fs/node.c
index 9405a17a671e..0230326be495 100644
--- a/fs/f2fs/node.c
+++ b/fs/f2fs/node.c
@@ -633,19 +633,19 @@ static int truncate_partial_nodes(struct dnode_of_data *dn,
633 return 0; 633 return 0;
634 634
635 /* get indirect nodes in the path */ 635 /* get indirect nodes in the path */
636 for (i = 0; i < depth - 1; i++) { 636 for (i = 0; i < idx + 1; i++) {
637 /* refernece count'll be increased */ 637 /* refernece count'll be increased */
638 pages[i] = get_node_page(sbi, nid[i]); 638 pages[i] = get_node_page(sbi, nid[i]);
639 if (IS_ERR(pages[i])) { 639 if (IS_ERR(pages[i])) {
640 depth = i + 1;
641 err = PTR_ERR(pages[i]); 640 err = PTR_ERR(pages[i]);
641 idx = i - 1;
642 goto fail; 642 goto fail;
643 } 643 }
644 nid[i + 1] = get_nid(pages[i], offset[i + 1], false); 644 nid[i + 1] = get_nid(pages[i], offset[i + 1], false);
645 } 645 }
646 646
647 /* free direct nodes linked to a partial indirect node */ 647 /* free direct nodes linked to a partial indirect node */
648 for (i = offset[depth - 1]; i < NIDS_PER_BLOCK; i++) { 648 for (i = offset[idx + 1]; i < NIDS_PER_BLOCK; i++) {
649 child_nid = get_nid(pages[idx], i, false); 649 child_nid = get_nid(pages[idx], i, false);
650 if (!child_nid) 650 if (!child_nid)
651 continue; 651 continue;
@@ -656,7 +656,7 @@ static int truncate_partial_nodes(struct dnode_of_data *dn,
656 set_nid(pages[idx], i, 0, false); 656 set_nid(pages[idx], i, 0, false);
657 } 657 }
658 658
659 if (offset[depth - 1] == 0) { 659 if (offset[idx + 1] == 0) {
660 dn->node_page = pages[idx]; 660 dn->node_page = pages[idx];
661 dn->nid = nid[idx]; 661 dn->nid = nid[idx];
662 truncate_node(dn); 662 truncate_node(dn);
@@ -664,9 +664,10 @@ static int truncate_partial_nodes(struct dnode_of_data *dn,
664 f2fs_put_page(pages[idx], 1); 664 f2fs_put_page(pages[idx], 1);
665 } 665 }
666 offset[idx]++; 666 offset[idx]++;
667 offset[depth - 1] = 0; 667 offset[idx + 1] = 0;
668 idx--;
668fail: 669fail:
669 for (i = depth - 3; i >= 0; i--) 670 for (i = idx; i >= 0; i--)
670 f2fs_put_page(pages[i], 1); 671 f2fs_put_page(pages[i], 1);
671 672
672 trace_f2fs_truncate_partial_nodes(dn->inode, nid, depth, err); 673 trace_f2fs_truncate_partial_nodes(dn->inode, nid, depth, err);