2 * recovery.c - NILFS recovery logic
4 * Copyright (C) 2005-2008 Nippon Telegraph and Telephone Corporation.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 * Written by Ryusuke Konishi <ryusuke@osrg.net>
23 #include <linux/buffer_head.h>
24 #include <linux/blkdev.h>
25 #include <linux/swap.h>
26 #include <linux/crc32.h>
35 * Segment check result
39 NILFS_SEG_NO_SUPER_ROOT,
43 NILFS_SEG_FAIL_CHECKSUM_SEGSUM,
44 NILFS_SEG_FAIL_CHECKSUM_SUPER_ROOT,
45 NILFS_SEG_FAIL_CHECKSUM_FULL,
46 NILFS_SEG_FAIL_CONSISTENCY,
49 /* work structure for recovery */
50 struct nilfs_recovery_block {
51 ino_t ino; /* Inode number of the file that this block
53 sector_t blocknr; /* block number */
54 __u64 vblocknr; /* virtual block number */
55 unsigned long blkoff; /* File offset of the data block (per block) */
56 struct list_head list;
60 static int nilfs_warn_segment_error(int err)
63 case NILFS_SEG_FAIL_IO:
65 "NILFS warning: I/O error on loading last segment\n");
67 case NILFS_SEG_FAIL_MAGIC:
69 "NILFS warning: Segment magic number invalid\n");
71 case NILFS_SEG_FAIL_SEQ:
73 "NILFS warning: Sequence number mismatch\n");
75 case NILFS_SEG_FAIL_CHECKSUM_SEGSUM:
77 "NILFS warning: Checksum error in segment summary\n");
79 case NILFS_SEG_FAIL_CHECKSUM_SUPER_ROOT:
81 "NILFS warning: Checksum error in super root\n");
83 case NILFS_SEG_FAIL_CHECKSUM_FULL:
85 "NILFS warning: Checksum error in segment payload\n");
87 case NILFS_SEG_FAIL_CONSISTENCY:
89 "NILFS warning: Inconsistent segment\n");
91 case NILFS_SEG_NO_SUPER_ROOT:
93 "NILFS warning: No super root in the last segment\n");
102 static void store_segsum_info(struct nilfs_segsum_info *ssi,
103 struct nilfs_segment_summary *sum,
104 unsigned int blocksize)
106 ssi->flags = le16_to_cpu(sum->ss_flags);
107 ssi->seg_seq = le64_to_cpu(sum->ss_seq);
108 ssi->ctime = le64_to_cpu(sum->ss_create);
109 ssi->next = le64_to_cpu(sum->ss_next);
110 ssi->nblocks = le32_to_cpu(sum->ss_nblocks);
111 ssi->nfinfo = le32_to_cpu(sum->ss_nfinfo);
112 ssi->sumbytes = le32_to_cpu(sum->ss_sumbytes);
114 ssi->nsumblk = DIV_ROUND_UP(ssi->sumbytes, blocksize);
115 ssi->nfileblk = ssi->nblocks - ssi->nsumblk - !!NILFS_SEG_HAS_SR(ssi);
119 * calc_crc_cont - check CRC of blocks continuously
120 * @sbi: nilfs_sb_info
121 * @bhs: buffer head of start block
122 * @sum: place to store result
123 * @offset: offset bytes in the first block
124 * @check_bytes: number of bytes to be checked
125 * @start: DBN of start block
126 * @nblock: number of blocks to be checked
128 static int calc_crc_cont(struct nilfs_sb_info *sbi, struct buffer_head *bhs,
129 u32 *sum, unsigned long offset, u64 check_bytes,
130 sector_t start, unsigned long nblock)
132 unsigned long blocksize = sbi->s_super->s_blocksize;
136 BUG_ON(offset >= blocksize);
137 check_bytes -= offset;
138 size = min_t(u64, check_bytes, blocksize - offset);
139 crc = crc32_le(sbi->s_nilfs->ns_crc_seed,
140 (unsigned char *)bhs->b_data + offset, size);
143 struct buffer_head *bh
144 = sb_bread(sbi->s_super, ++start);
148 size = min_t(u64, check_bytes, blocksize);
149 crc = crc32_le(crc, bh->b_data, size);
151 } while (--nblock > 0);
158 * nilfs_read_super_root_block - read super root block
160 * @sr_block: disk block number of the super root block
161 * @pbh: address of a buffer_head pointer to return super root buffer
162 * @check: CRC check flag
164 int nilfs_read_super_root_block(struct super_block *sb, sector_t sr_block,
165 struct buffer_head **pbh, int check)
167 struct buffer_head *bh_sr;
168 struct nilfs_super_root *sr;
173 bh_sr = sb_bread(sb, sr_block);
174 if (unlikely(!bh_sr)) {
175 ret = NILFS_SEG_FAIL_IO;
179 sr = (struct nilfs_super_root *)bh_sr->b_data;
181 unsigned bytes = le16_to_cpu(sr->sr_bytes);
183 if (bytes == 0 || bytes > sb->s_blocksize) {
184 ret = NILFS_SEG_FAIL_CHECKSUM_SUPER_ROOT;
187 if (calc_crc_cont(NILFS_SB(sb), bh_sr, &crc,
188 sizeof(sr->sr_sum), bytes, sr_block, 1)) {
189 ret = NILFS_SEG_FAIL_IO;
192 if (crc != le32_to_cpu(sr->sr_sum)) {
193 ret = NILFS_SEG_FAIL_CHECKSUM_SUPER_ROOT;
204 return nilfs_warn_segment_error(ret);
208 * load_segment_summary - read segment summary of the specified partial segment
209 * @sbi: nilfs_sb_info
210 * @pseg_start: start disk block number of partial segment
211 * @seg_seq: sequence number requested
212 * @ssi: pointer to nilfs_segsum_info struct to store information
213 * @full_check: full check flag
214 * (0: only checks segment summary CRC, 1: data CRC)
217 load_segment_summary(struct nilfs_sb_info *sbi, sector_t pseg_start,
218 u64 seg_seq, struct nilfs_segsum_info *ssi,
221 struct buffer_head *bh_sum;
222 struct nilfs_segment_summary *sum;
223 unsigned long offset, nblock;
226 int ret = NILFS_SEG_FAIL_IO;
228 bh_sum = sb_bread(sbi->s_super, pseg_start);
232 sum = (struct nilfs_segment_summary *)bh_sum->b_data;
234 /* Check consistency of segment summary */
235 if (le32_to_cpu(sum->ss_magic) != NILFS_SEGSUM_MAGIC) {
236 ret = NILFS_SEG_FAIL_MAGIC;
239 store_segsum_info(ssi, sum, sbi->s_super->s_blocksize);
240 if (seg_seq != ssi->seg_seq) {
241 ret = NILFS_SEG_FAIL_SEQ;
245 offset = sizeof(sum->ss_datasum);
247 ((u64)ssi->nblocks << sbi->s_super->s_blocksize_bits);
248 nblock = ssi->nblocks;
249 crc_sum = le32_to_cpu(sum->ss_datasum);
250 ret = NILFS_SEG_FAIL_CHECKSUM_FULL;
251 } else { /* only checks segment summary */
252 offset = sizeof(sum->ss_datasum) + sizeof(sum->ss_sumsum);
253 check_bytes = ssi->sumbytes;
254 nblock = ssi->nsumblk;
255 crc_sum = le32_to_cpu(sum->ss_sumsum);
256 ret = NILFS_SEG_FAIL_CHECKSUM_SEGSUM;
259 if (unlikely(nblock == 0 ||
260 nblock > sbi->s_nilfs->ns_blocks_per_segment)) {
261 /* This limits the number of blocks read in the CRC check */
262 ret = NILFS_SEG_FAIL_CONSISTENCY;
265 if (calc_crc_cont(sbi, bh_sum, &crc, offset, check_bytes,
266 pseg_start, nblock)) {
267 ret = NILFS_SEG_FAIL_IO;
278 static void *segsum_get(struct super_block *sb, struct buffer_head **pbh,
279 unsigned int *offset, unsigned int bytes)
284 BUG_ON((*pbh)->b_size < *offset);
285 if (bytes > (*pbh)->b_size - *offset) {
286 blocknr = (*pbh)->b_blocknr;
288 *pbh = sb_bread(sb, blocknr + 1);
293 ptr = (*pbh)->b_data + *offset;
298 static void segsum_skip(struct super_block *sb, struct buffer_head **pbh,
299 unsigned int *offset, unsigned int bytes,
302 unsigned int rest_item_in_current_block
303 = ((*pbh)->b_size - *offset) / bytes;
305 if (count <= rest_item_in_current_block) {
306 *offset += bytes * count;
308 sector_t blocknr = (*pbh)->b_blocknr;
309 unsigned int nitem_per_block = (*pbh)->b_size / bytes;
312 count -= rest_item_in_current_block;
313 bcnt = DIV_ROUND_UP(count, nitem_per_block);
314 *offset = bytes * (count - (bcnt - 1) * nitem_per_block);
317 *pbh = sb_bread(sb, blocknr + bcnt);
322 collect_blocks_from_segsum(struct nilfs_sb_info *sbi, sector_t sum_blocknr,
323 struct nilfs_segsum_info *ssi,
324 struct list_head *head)
326 struct buffer_head *bh;
328 unsigned long nfinfo = ssi->nfinfo;
329 sector_t blocknr = sum_blocknr + ssi->nsumblk;
336 bh = sb_bread(sbi->s_super, sum_blocknr);
340 offset = le16_to_cpu(
341 ((struct nilfs_segment_summary *)bh->b_data)->ss_bytes);
343 unsigned long nblocks, ndatablk, nnodeblk;
344 struct nilfs_finfo *finfo;
346 finfo = segsum_get(sbi->s_super, &bh, &offset, sizeof(*finfo));
347 if (unlikely(!finfo))
350 ino = le64_to_cpu(finfo->fi_ino);
351 nblocks = le32_to_cpu(finfo->fi_nblocks);
352 ndatablk = le32_to_cpu(finfo->fi_ndatablk);
353 nnodeblk = nblocks - ndatablk;
355 while (ndatablk-- > 0) {
356 struct nilfs_recovery_block *rb;
357 struct nilfs_binfo_v *binfo;
359 binfo = segsum_get(sbi->s_super, &bh, &offset,
361 if (unlikely(!binfo))
364 rb = kmalloc(sizeof(*rb), GFP_NOFS);
370 rb->blocknr = blocknr++;
371 rb->vblocknr = le64_to_cpu(binfo->bi_vblocknr);
372 rb->blkoff = le64_to_cpu(binfo->bi_blkoff);
373 /* INIT_LIST_HEAD(&rb->list); */
374 list_add_tail(&rb->list, head);
378 blocknr += nnodeblk; /* always 0 for the data sync segments */
379 segsum_skip(sbi->s_super, &bh, &offset, sizeof(__le64),
386 brelse(bh); /* brelse(NULL) is just ignored */
390 static void dispose_recovery_list(struct list_head *head)
392 while (!list_empty(head)) {
393 struct nilfs_recovery_block *rb
394 = list_entry(head->next,
395 struct nilfs_recovery_block, list);
401 void nilfs_dispose_segment_list(struct list_head *head)
403 while (!list_empty(head)) {
404 struct nilfs_segment_entry *ent
405 = list_entry(head->next,
406 struct nilfs_segment_entry, list);
407 list_del(&ent->list);
408 nilfs_free_segment_entry(ent);
412 static int nilfs_prepare_segment_for_recovery(struct the_nilfs *nilfs,
413 struct nilfs_recovery_info *ri)
415 struct list_head *head = &ri->ri_used_segments;
416 struct nilfs_segment_entry *ent, *n;
417 struct inode *sufile = nilfs->ns_sufile;
422 segnum[0] = nilfs->ns_segnum;
423 segnum[1] = nilfs->ns_nextnum;
424 segnum[2] = ri->ri_segnum;
425 segnum[3] = ri->ri_nextnum;
428 * Releasing the next segment of the latest super root.
429 * The next segment is invalidated by this recovery.
431 err = nilfs_sufile_free(sufile, segnum[1]);
436 for (i = 1; i < 4; i++) {
437 ent = nilfs_alloc_segment_entry(segnum[i]);
440 list_add_tail(&ent->list, head);
444 * Collecting segments written after the latest super root.
445 * These are marked volatile active, and won't be reallocated in
446 * the next construction.
448 list_for_each_entry_safe(ent, n, head, list) {
449 if (ent->segnum == segnum[0]) {
450 list_del(&ent->list);
451 nilfs_free_segment_entry(ent);
454 err = nilfs_open_segment_entry(ent, sufile);
457 if (nilfs_segment_usage_clean(ent->raw_su)) {
458 nilfs_segment_usage_set_volatile_active(ent->raw_su);
461 /* Removing duplicated entries */
462 list_del(&ent->list);
463 nilfs_close_segment_entry(ent, sufile);
464 nilfs_free_segment_entry(ent);
467 list_splice_init(head, nilfs->ns_used_segments.prev);
470 * The segment having the latest super root is active, and
471 * should be deactivated on the next construction for recovery.
474 ent = nilfs_alloc_segment_entry(segnum[0]);
477 list_add_tail(&ent->list, &ri->ri_used_segments);
479 /* Allocate new segments for recovery */
480 err = nilfs_sufile_alloc(sufile, &segnum[0]);
484 nilfs->ns_pseg_offset = 0;
485 nilfs->ns_seg_seq = ri->ri_seq + 2;
486 nilfs->ns_nextnum = nilfs->ns_segnum = segnum[0];
490 /* No need to recover sufile because it will be destroyed on error */
494 static int nilfs_recovery_copy_block(struct nilfs_sb_info *sbi,
495 struct nilfs_recovery_block *rb,
498 struct buffer_head *bh_org;
501 bh_org = sb_bread(sbi->s_super, rb->blocknr);
502 if (unlikely(!bh_org))
505 kaddr = kmap_atomic(page, KM_USER0);
506 memcpy(kaddr + bh_offset(bh_org), bh_org->b_data, bh_org->b_size);
507 kunmap_atomic(kaddr, KM_USER0);
512 static int recover_dsync_blocks(struct nilfs_sb_info *sbi,
513 struct list_head *head,
514 unsigned long *nr_salvaged_blocks)
517 struct nilfs_recovery_block *rb, *n;
518 unsigned blocksize = sbi->s_super->s_blocksize;
521 int err = 0, err2 = 0;
523 list_for_each_entry_safe(rb, n, head, list) {
524 inode = nilfs_iget(sbi->s_super, rb->ino);
526 err = PTR_ERR(inode);
531 pos = rb->blkoff << inode->i_blkbits;
533 err = block_write_begin(NULL, inode->i_mapping, pos, blocksize,
534 0, &page, NULL, nilfs_get_block);
538 err = nilfs_recovery_copy_block(sbi, rb, page);
542 err = nilfs_set_file_dirty(sbi, inode, 1);
546 block_write_end(NULL, inode->i_mapping, pos, blocksize,
547 blocksize, page, NULL);
550 page_cache_release(page);
552 (*nr_salvaged_blocks)++;
557 page_cache_release(page);
561 "NILFS warning: error recovering data block "
562 "(err=%d, ino=%lu, block-offset=%llu)\n",
563 err, rb->ino, (unsigned long long)rb->blkoff);
567 iput(inode); /* iput(NULL) is just ignored */
568 list_del_init(&rb->list);
575 * nilfs_do_roll_forward - salvage logical segments newer than the latest
577 * @sbi: nilfs_sb_info
579 * @ri: pointer to a nilfs_recovery_info
581 static int nilfs_do_roll_forward(struct the_nilfs *nilfs,
582 struct nilfs_sb_info *sbi,
583 struct nilfs_recovery_info *ri)
585 struct nilfs_segsum_info ssi;
587 sector_t seg_start, seg_end; /* Starting/ending DBN of full segment */
588 unsigned long nsalvaged_blocks = 0;
590 __u64 segnum, nextnum = 0;
593 LIST_HEAD(dsync_blocks); /* list of data blocks to be recovered */
596 RF_DSYNC_ST, /* scanning data-sync segments */
598 int state = RF_INIT_ST;
600 nilfs_attach_writer(nilfs, sbi);
601 pseg_start = ri->ri_lsegs_start;
602 seg_seq = ri->ri_lsegs_start_seq;
603 segnum = nilfs_get_segnum_of_block(nilfs, pseg_start);
604 nilfs_get_segment_range(nilfs, segnum, &seg_start, &seg_end);
606 while (segnum != ri->ri_segnum || pseg_start <= ri->ri_pseg_start) {
608 ret = load_segment_summary(sbi, pseg_start, seg_seq, &ssi, 1);
610 if (ret == NILFS_SEG_FAIL_IO) {
616 if (unlikely(NILFS_SEG_HAS_SR(&ssi)))
619 /* Found a valid partial segment; do recovery actions */
620 nextnum = nilfs_get_segnum_of_block(nilfs, ssi.next);
622 nilfs->ns_ctime = ssi.ctime;
623 if (!(ssi.flags & NILFS_SS_GC))
624 nilfs->ns_nongc_ctime = ssi.ctime;
628 if (!NILFS_SEG_LOGBGN(&ssi) || !NILFS_SEG_DSYNC(&ssi))
633 if (!NILFS_SEG_DSYNC(&ssi))
636 err = collect_blocks_from_segsum(
637 sbi, pseg_start, &ssi, &dsync_blocks);
640 if (NILFS_SEG_LOGEND(&ssi)) {
641 err = recover_dsync_blocks(
642 sbi, &dsync_blocks, &nsalvaged_blocks);
647 break; /* Fall through to try_next_pseg */
651 if (pseg_start == ri->ri_lsegs_end)
653 pseg_start += ssi.nblocks;
654 if (pseg_start < seg_end)
659 if (pseg_start == ri->ri_lsegs_end)
663 /* Looking to the next full segment */
668 nilfs_get_segment_range(nilfs, segnum, &seg_start, &seg_end);
669 pseg_start = seg_start;
672 if (nsalvaged_blocks) {
673 printk(KERN_INFO "NILFS (device %s): salvaged %lu blocks\n",
674 sbi->s_super->s_id, nsalvaged_blocks);
675 ri->ri_need_recovery = NILFS_RECOVERY_ROLLFORWARD_DONE;
678 dispose_recovery_list(&dsync_blocks);
679 nilfs_detach_writer(sbi->s_nilfs, sbi);
686 "NILFS (device %s): Error roll-forwarding "
687 "(err=%d, pseg block=%llu). ",
688 sbi->s_super->s_id, err, (unsigned long long)pseg_start);
692 static void nilfs_finish_roll_forward(struct the_nilfs *nilfs,
693 struct nilfs_sb_info *sbi,
694 struct nilfs_recovery_info *ri)
696 struct buffer_head *bh;
699 if (nilfs_get_segnum_of_block(nilfs, ri->ri_lsegs_start) !=
700 nilfs_get_segnum_of_block(nilfs, ri->ri_super_root))
703 bh = sb_getblk(sbi->s_super, ri->ri_lsegs_start);
705 memset(bh->b_data, 0, bh->b_size);
706 set_buffer_dirty(bh);
707 err = sync_dirty_buffer(bh);
710 "NILFS warning: buffer sync write failed during "
711 "post-cleaning of recovery.\n");
716 * nilfs_recover_logical_segments - salvage logical segments written after
717 * the latest super root
719 * @sbi: nilfs_sb_info
720 * @ri: pointer to a nilfs_recovery_info struct to store search results.
722 * Return Value: On success, 0 is returned. On error, one of the following
723 * negative error code is returned.
725 * %-EINVAL - Inconsistent filesystem state.
729 * %-ENOSPC - No space left on device (only in a panic state).
731 * %-ERESTARTSYS - Interrupted.
733 * %-ENOMEM - Insufficient memory available.
735 int nilfs_recover_logical_segments(struct the_nilfs *nilfs,
736 struct nilfs_sb_info *sbi,
737 struct nilfs_recovery_info *ri)
741 if (ri->ri_lsegs_start == 0 || ri->ri_lsegs_end == 0)
744 err = nilfs_attach_checkpoint(sbi, ri->ri_cno);
747 "NILFS: error loading the latest checkpoint.\n");
751 err = nilfs_do_roll_forward(nilfs, sbi, ri);
755 if (ri->ri_need_recovery == NILFS_RECOVERY_ROLLFORWARD_DONE) {
756 err = nilfs_prepare_segment_for_recovery(nilfs, ri);
758 printk(KERN_ERR "NILFS: Error preparing segments for "
763 err = nilfs_attach_segment_constructor(sbi, ri);
767 set_nilfs_discontinued(nilfs);
768 err = nilfs_construct_segment(sbi->s_super);
769 nilfs_detach_segment_constructor(sbi);
772 printk(KERN_ERR "NILFS: Oops! recovery failed. "
777 nilfs_finish_roll_forward(nilfs, sbi, ri);
780 nilfs_detach_checkpoint(sbi);
784 nilfs_detach_checkpoint(sbi);
785 nilfs_mdt_clear(nilfs->ns_cpfile);
786 nilfs_mdt_clear(nilfs->ns_sufile);
787 nilfs_mdt_clear(nilfs->ns_dat);
792 * nilfs_search_super_root - search the latest valid super root
794 * @sbi: nilfs_sb_info
795 * @ri: pointer to a nilfs_recovery_info struct to store search results.
797 * nilfs_search_super_root() looks for the latest super-root from a partial
798 * segment pointed by the superblock. It sets up struct the_nilfs through
799 * this search. It fills nilfs_recovery_info (ri) required for recovery.
801 * Return Value: On success, 0 is returned. On error, one of the following
802 * negative error code is returned.
804 * %-EINVAL - No valid segment found
808 int nilfs_search_super_root(struct the_nilfs *nilfs, struct nilfs_sb_info *sbi,
809 struct nilfs_recovery_info *ri)
811 struct nilfs_segsum_info ssi;
812 sector_t pseg_start, pseg_end, sr_pseg_start = 0;
813 sector_t seg_start, seg_end; /* range of full segment (block number) */
815 __u64 segnum, nextnum = 0;
817 struct nilfs_segment_entry *ent;
819 int empty_seg = 0, scan_newer = 0;
822 pseg_start = nilfs->ns_last_pseg;
823 seg_seq = nilfs->ns_last_seq;
824 cno = nilfs->ns_last_cno;
825 segnum = nilfs_get_segnum_of_block(nilfs, pseg_start);
827 /* Calculate range of segment */
828 nilfs_get_segment_range(nilfs, segnum, &seg_start, &seg_end);
831 /* Load segment summary */
832 ret = load_segment_summary(sbi, pseg_start, seg_seq, &ssi, 1);
834 if (ret == NILFS_SEG_FAIL_IO)
838 pseg_end = pseg_start + ssi.nblocks - 1;
839 if (unlikely(pseg_end > seg_end)) {
840 ret = NILFS_SEG_FAIL_CONSISTENCY;
844 /* A valid partial segment */
845 ri->ri_pseg_start = pseg_start;
846 ri->ri_seq = seg_seq;
847 ri->ri_segnum = segnum;
848 nextnum = nilfs_get_segnum_of_block(nilfs, ssi.next);
849 ri->ri_nextnum = nextnum;
852 if (!NILFS_SEG_HAS_SR(&ssi)) {
854 /* This will never happen because a superblock
855 (last_segment) always points to a pseg
856 having a super root. */
857 ret = NILFS_SEG_FAIL_CONSISTENCY;
860 if (!ri->ri_lsegs_start && NILFS_SEG_LOGBGN(&ssi)) {
861 ri->ri_lsegs_start = pseg_start;
862 ri->ri_lsegs_start_seq = seg_seq;
864 if (NILFS_SEG_LOGEND(&ssi))
865 ri->ri_lsegs_end = pseg_start;
869 /* A valid super root was found. */
871 ri->ri_super_root = pseg_end;
872 ri->ri_lsegs_start = ri->ri_lsegs_end = 0;
874 nilfs_dispose_segment_list(&segments);
875 nilfs->ns_pseg_offset = (sr_pseg_start = pseg_start)
876 + ssi.nblocks - seg_start;
877 nilfs->ns_seg_seq = seg_seq;
878 nilfs->ns_segnum = segnum;
879 nilfs->ns_cno = cno; /* nilfs->ns_cno = ri->ri_cno + 1 */
880 nilfs->ns_ctime = ssi.ctime;
881 nilfs->ns_nextnum = nextnum;
884 ri->ri_need_recovery = NILFS_RECOVERY_SR_UPDATED;
885 else if (nilfs->ns_mount_state & NILFS_VALID_FS)
886 goto super_root_found;
890 /* reset region for roll-forward */
891 pseg_start += ssi.nblocks;
892 if (pseg_start < seg_end)
897 /* Standing on a course, or met an inconsistent state */
898 pseg_start += ssi.nblocks;
899 if (pseg_start < seg_end)
907 * This can happen if a checkpoint was written without
908 * barriers, or as a result of an I/O failure.
913 /* Looking to the next full segment */
915 goto super_root_found; /* found a valid super root */
917 ent = nilfs_alloc_segment_entry(segnum);
918 if (unlikely(!ent)) {
922 list_add_tail(&ent->list, &segments);
926 nilfs_get_segment_range(nilfs, segnum, &seg_start, &seg_end);
927 pseg_start = seg_start;
931 /* Updating pointers relating to the latest checkpoint */
932 list_splice(&segments, ri->ri_used_segments.prev);
933 nilfs->ns_last_pseg = sr_pseg_start;
934 nilfs->ns_last_seq = nilfs->ns_seg_seq;
935 nilfs->ns_last_cno = ri->ri_cno;
939 nilfs_dispose_segment_list(&segments);
940 return (ret < 0) ? ret : nilfs_warn_segment_error(ret);