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/slab.h>
27 #include <linux/crc32.h>
35 * Segment check result
39 NILFS_SEG_NO_SUPER_ROOT,
43 NILFS_SEG_FAIL_CHECKSUM_SUPER_ROOT,
44 NILFS_SEG_FAIL_CHECKSUM_FULL,
45 NILFS_SEG_FAIL_CONSISTENCY,
48 /* work structure for recovery */
49 struct nilfs_recovery_block {
50 ino_t ino; /* Inode number of the file that this block
52 sector_t blocknr; /* block number */
53 __u64 vblocknr; /* virtual block number */
54 unsigned long blkoff; /* File offset of the data block (per block) */
55 struct list_head list;
59 static int nilfs_warn_segment_error(int err)
62 case NILFS_SEG_FAIL_IO:
64 "NILFS warning: I/O error on loading last segment\n");
66 case NILFS_SEG_FAIL_MAGIC:
68 "NILFS warning: Segment magic number invalid\n");
70 case NILFS_SEG_FAIL_SEQ:
72 "NILFS warning: Sequence number mismatch\n");
74 case NILFS_SEG_FAIL_CHECKSUM_SUPER_ROOT:
76 "NILFS warning: Checksum error in super root\n");
78 case NILFS_SEG_FAIL_CHECKSUM_FULL:
80 "NILFS warning: Checksum error in segment payload\n");
82 case NILFS_SEG_FAIL_CONSISTENCY:
84 "NILFS warning: Inconsistent segment\n");
86 case NILFS_SEG_NO_SUPER_ROOT:
88 "NILFS warning: No super root in the last segment\n");
94 static void store_segsum_info(struct nilfs_segsum_info *ssi,
95 struct nilfs_segment_summary *sum,
96 unsigned int blocksize)
98 ssi->flags = le16_to_cpu(sum->ss_flags);
99 ssi->seg_seq = le64_to_cpu(sum->ss_seq);
100 ssi->ctime = le64_to_cpu(sum->ss_create);
101 ssi->next = le64_to_cpu(sum->ss_next);
102 ssi->nblocks = le32_to_cpu(sum->ss_nblocks);
103 ssi->nfinfo = le32_to_cpu(sum->ss_nfinfo);
104 ssi->sumbytes = le32_to_cpu(sum->ss_sumbytes);
106 ssi->nsumblk = DIV_ROUND_UP(ssi->sumbytes, blocksize);
107 ssi->nfileblk = ssi->nblocks - ssi->nsumblk - !!NILFS_SEG_HAS_SR(ssi);
109 /* need to verify ->ss_bytes field if read ->ss_cno */
113 * nilfs_compute_checksum - compute checksum of blocks continuously
114 * @nilfs: nilfs object
115 * @bhs: buffer head of start block
116 * @sum: place to store result
117 * @offset: offset bytes in the first block
118 * @check_bytes: number of bytes to be checked
119 * @start: DBN of start block
120 * @nblock: number of blocks to be checked
122 static int nilfs_compute_checksum(struct the_nilfs *nilfs,
123 struct buffer_head *bhs, u32 *sum,
124 unsigned long offset, u64 check_bytes,
125 sector_t start, unsigned long nblock)
127 unsigned int blocksize = nilfs->ns_blocksize;
131 BUG_ON(offset >= blocksize);
132 check_bytes -= offset;
133 size = min_t(u64, check_bytes, blocksize - offset);
134 crc = crc32_le(nilfs->ns_crc_seed,
135 (unsigned char *)bhs->b_data + offset, size);
138 struct buffer_head *bh;
140 bh = __bread(nilfs->ns_bdev, ++start, blocksize);
144 size = min_t(u64, check_bytes, blocksize);
145 crc = crc32_le(crc, bh->b_data, size);
147 } while (--nblock > 0);
154 * nilfs_read_super_root_block - read super root block
155 * @nilfs: nilfs object
156 * @sr_block: disk block number of the super root block
157 * @pbh: address of a buffer_head pointer to return super root buffer
158 * @check: CRC check flag
160 int nilfs_read_super_root_block(struct the_nilfs *nilfs, sector_t sr_block,
161 struct buffer_head **pbh, int check)
163 struct buffer_head *bh_sr;
164 struct nilfs_super_root *sr;
169 bh_sr = __bread(nilfs->ns_bdev, sr_block, nilfs->ns_blocksize);
170 if (unlikely(!bh_sr)) {
171 ret = NILFS_SEG_FAIL_IO;
175 sr = (struct nilfs_super_root *)bh_sr->b_data;
177 unsigned bytes = le16_to_cpu(sr->sr_bytes);
179 if (bytes == 0 || bytes > nilfs->ns_blocksize) {
180 ret = NILFS_SEG_FAIL_CHECKSUM_SUPER_ROOT;
183 if (nilfs_compute_checksum(
184 nilfs, bh_sr, &crc, sizeof(sr->sr_sum), bytes,
186 ret = NILFS_SEG_FAIL_IO;
189 if (crc != le32_to_cpu(sr->sr_sum)) {
190 ret = NILFS_SEG_FAIL_CHECKSUM_SUPER_ROOT;
201 return nilfs_warn_segment_error(ret);
205 * load_segment_summary - read segment summary of the specified partial segment
206 * @nilfs: nilfs object
207 * @pseg_start: start disk block number of partial segment
208 * @seg_seq: sequence number requested
209 * @ssi: pointer to nilfs_segsum_info struct to store information
212 load_segment_summary(struct the_nilfs *nilfs, sector_t pseg_start,
213 u64 seg_seq, struct nilfs_segsum_info *ssi)
215 struct buffer_head *bh_sum;
216 struct nilfs_segment_summary *sum;
217 unsigned long nblock;
219 int ret = NILFS_SEG_FAIL_IO;
221 bh_sum = __bread(nilfs->ns_bdev, pseg_start, nilfs->ns_blocksize);
225 sum = (struct nilfs_segment_summary *)bh_sum->b_data;
227 /* Check consistency of segment summary */
228 if (le32_to_cpu(sum->ss_magic) != NILFS_SEGSUM_MAGIC) {
229 ret = NILFS_SEG_FAIL_MAGIC;
232 store_segsum_info(ssi, sum, nilfs->ns_blocksize);
233 if (seg_seq != ssi->seg_seq) {
234 ret = NILFS_SEG_FAIL_SEQ;
238 nblock = ssi->nblocks;
239 if (unlikely(nblock == 0 || nblock > nilfs->ns_blocks_per_segment)) {
240 /* This limits the number of blocks read in the CRC check */
241 ret = NILFS_SEG_FAIL_CONSISTENCY;
244 if (nilfs_compute_checksum(nilfs, bh_sum, &crc, sizeof(sum->ss_datasum),
245 ((u64)nblock << nilfs->ns_blocksize_bits),
246 pseg_start, nblock)) {
247 ret = NILFS_SEG_FAIL_IO;
250 if (crc == le32_to_cpu(sum->ss_datasum))
253 ret = NILFS_SEG_FAIL_CHECKSUM_FULL;
261 * nilfs_read_summary_info - read an item on summary blocks of a log
262 * @nilfs: nilfs object
263 * @pbh: the current buffer head on summary blocks [in, out]
264 * @offset: the current byte offset on summary blocks [in, out]
265 * @bytes: byte size of the item to be read
267 static void *nilfs_read_summary_info(struct the_nilfs *nilfs,
268 struct buffer_head **pbh,
269 unsigned int *offset, unsigned int bytes)
274 BUG_ON((*pbh)->b_size < *offset);
275 if (bytes > (*pbh)->b_size - *offset) {
276 blocknr = (*pbh)->b_blocknr;
278 *pbh = __bread(nilfs->ns_bdev, blocknr + 1,
279 nilfs->ns_blocksize);
284 ptr = (*pbh)->b_data + *offset;
290 * nilfs_skip_summary_info - skip items on summary blocks of a log
291 * @nilfs: nilfs object
292 * @pbh: the current buffer head on summary blocks [in, out]
293 * @offset: the current byte offset on summary blocks [in, out]
294 * @bytes: byte size of the item to be skipped
295 * @count: number of items to be skipped
297 static void nilfs_skip_summary_info(struct the_nilfs *nilfs,
298 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 = __bread(nilfs->ns_bdev, blocknr + bcnt,
318 nilfs->ns_blocksize);
323 * nilfs_scan_dsync_log - get block information of a log written for data sync
324 * @nilfs: nilfs object
325 * @start_blocknr: start block number of the log
326 * @ssi: log summary information
327 * @head: list head to add nilfs_recovery_block struct
329 static int nilfs_scan_dsync_log(struct the_nilfs *nilfs, sector_t start_blocknr,
330 struct nilfs_segsum_info *ssi,
331 struct list_head *head)
333 struct buffer_head *bh;
335 unsigned long nfinfo = ssi->nfinfo;
336 sector_t blocknr = start_blocknr + ssi->nsumblk;
343 bh = __bread(nilfs->ns_bdev, start_blocknr, nilfs->ns_blocksize);
347 offset = le16_to_cpu(
348 ((struct nilfs_segment_summary *)bh->b_data)->ss_bytes);
350 unsigned long nblocks, ndatablk, nnodeblk;
351 struct nilfs_finfo *finfo;
353 finfo = nilfs_read_summary_info(nilfs, &bh, &offset,
355 if (unlikely(!finfo))
358 ino = le64_to_cpu(finfo->fi_ino);
359 nblocks = le32_to_cpu(finfo->fi_nblocks);
360 ndatablk = le32_to_cpu(finfo->fi_ndatablk);
361 nnodeblk = nblocks - ndatablk;
363 while (ndatablk-- > 0) {
364 struct nilfs_recovery_block *rb;
365 struct nilfs_binfo_v *binfo;
367 binfo = nilfs_read_summary_info(nilfs, &bh, &offset,
369 if (unlikely(!binfo))
372 rb = kmalloc(sizeof(*rb), GFP_NOFS);
378 rb->blocknr = blocknr++;
379 rb->vblocknr = le64_to_cpu(binfo->bi_vblocknr);
380 rb->blkoff = le64_to_cpu(binfo->bi_blkoff);
381 /* INIT_LIST_HEAD(&rb->list); */
382 list_add_tail(&rb->list, head);
386 blocknr += nnodeblk; /* always 0 for data sync logs */
387 nilfs_skip_summary_info(nilfs, &bh, &offset, sizeof(__le64),
394 brelse(bh); /* brelse(NULL) is just ignored */
398 static void dispose_recovery_list(struct list_head *head)
400 while (!list_empty(head)) {
401 struct nilfs_recovery_block *rb
402 = list_entry(head->next,
403 struct nilfs_recovery_block, list);
409 struct nilfs_segment_entry {
410 struct list_head list;
414 static int nilfs_segment_list_add(struct list_head *head, __u64 segnum)
416 struct nilfs_segment_entry *ent = kmalloc(sizeof(*ent), GFP_NOFS);
421 ent->segnum = segnum;
422 INIT_LIST_HEAD(&ent->list);
423 list_add_tail(&ent->list, head);
427 void nilfs_dispose_segment_list(struct list_head *head)
429 while (!list_empty(head)) {
430 struct nilfs_segment_entry *ent
431 = list_entry(head->next,
432 struct nilfs_segment_entry, list);
433 list_del(&ent->list);
438 static int nilfs_prepare_segment_for_recovery(struct the_nilfs *nilfs,
439 struct nilfs_sb_info *sbi,
440 struct nilfs_recovery_info *ri)
442 struct list_head *head = &ri->ri_used_segments;
443 struct nilfs_segment_entry *ent, *n;
444 struct inode *sufile = nilfs->ns_sufile;
449 segnum[0] = nilfs->ns_segnum;
450 segnum[1] = nilfs->ns_nextnum;
451 segnum[2] = ri->ri_segnum;
452 segnum[3] = ri->ri_nextnum;
454 nilfs_attach_writer(nilfs, sbi);
456 * Releasing the next segment of the latest super root.
457 * The next segment is invalidated by this recovery.
459 err = nilfs_sufile_free(sufile, segnum[1]);
463 for (i = 1; i < 4; i++) {
464 err = nilfs_segment_list_add(head, segnum[i]);
470 * Collecting segments written after the latest super root.
471 * These are marked dirty to avoid being reallocated in the next write.
473 list_for_each_entry_safe(ent, n, head, list) {
474 if (ent->segnum != segnum[0]) {
475 err = nilfs_sufile_scrap(sufile, ent->segnum);
479 list_del(&ent->list);
483 /* Allocate new segments for recovery */
484 err = nilfs_sufile_alloc(sufile, &segnum[0]);
488 nilfs->ns_pseg_offset = 0;
489 nilfs->ns_seg_seq = ri->ri_seq + 2;
490 nilfs->ns_nextnum = nilfs->ns_segnum = segnum[0];
493 /* No need to recover sufile because it will be destroyed on error */
494 nilfs_detach_writer(nilfs, sbi);
498 static int nilfs_recovery_copy_block(struct the_nilfs *nilfs,
499 struct nilfs_recovery_block *rb,
502 struct buffer_head *bh_org;
505 bh_org = __bread(nilfs->ns_bdev, rb->blocknr, nilfs->ns_blocksize);
506 if (unlikely(!bh_org))
509 kaddr = kmap_atomic(page, KM_USER0);
510 memcpy(kaddr + bh_offset(bh_org), bh_org->b_data, bh_org->b_size);
511 kunmap_atomic(kaddr, KM_USER0);
516 static int nilfs_recover_dsync_blocks(struct the_nilfs *nilfs,
517 struct nilfs_sb_info *sbi,
518 struct list_head *head,
519 unsigned long *nr_salvaged_blocks)
522 struct nilfs_recovery_block *rb, *n;
523 unsigned blocksize = nilfs->ns_blocksize;
526 int err = 0, err2 = 0;
528 list_for_each_entry_safe(rb, n, head, list) {
529 inode = nilfs_iget(sbi->s_super, rb->ino);
531 err = PTR_ERR(inode);
536 pos = rb->blkoff << inode->i_blkbits;
538 err = block_write_begin(NULL, inode->i_mapping, pos, blocksize,
539 0, &page, NULL, nilfs_get_block);
543 err = nilfs_recovery_copy_block(nilfs, rb, page);
547 err = nilfs_set_file_dirty(sbi, inode, 1);
551 block_write_end(NULL, inode->i_mapping, pos, blocksize,
552 blocksize, page, NULL);
555 page_cache_release(page);
557 (*nr_salvaged_blocks)++;
562 page_cache_release(page);
566 "NILFS warning: error recovering data block "
567 "(err=%d, ino=%lu, block-offset=%llu)\n",
568 err, (unsigned long)rb->ino,
569 (unsigned long long)rb->blkoff);
573 iput(inode); /* iput(NULL) is just ignored */
574 list_del_init(&rb->list);
581 * nilfs_do_roll_forward - salvage logical segments newer than the latest
583 * @nilfs: nilfs object
584 * @sbi: nilfs_sb_info
585 * @ri: pointer to a nilfs_recovery_info
587 static int nilfs_do_roll_forward(struct the_nilfs *nilfs,
588 struct nilfs_sb_info *sbi,
589 struct nilfs_recovery_info *ri)
591 struct nilfs_segsum_info ssi;
593 sector_t seg_start, seg_end; /* Starting/ending DBN of full segment */
594 unsigned long nsalvaged_blocks = 0;
596 __u64 segnum, nextnum = 0;
599 LIST_HEAD(dsync_blocks); /* list of data blocks to be recovered */
602 RF_DSYNC_ST, /* scanning data-sync segments */
604 int state = RF_INIT_ST;
606 nilfs_attach_writer(nilfs, sbi);
607 pseg_start = ri->ri_lsegs_start;
608 seg_seq = ri->ri_lsegs_start_seq;
609 segnum = nilfs_get_segnum_of_block(nilfs, pseg_start);
610 nilfs_get_segment_range(nilfs, segnum, &seg_start, &seg_end);
612 while (segnum != ri->ri_segnum || pseg_start <= ri->ri_pseg_start) {
614 ret = load_segment_summary(nilfs, pseg_start, seg_seq, &ssi);
616 if (ret == NILFS_SEG_FAIL_IO) {
622 if (unlikely(NILFS_SEG_HAS_SR(&ssi)))
625 /* Found a valid partial segment; do recovery actions */
626 nextnum = nilfs_get_segnum_of_block(nilfs, ssi.next);
628 nilfs->ns_ctime = ssi.ctime;
629 if (!(ssi.flags & NILFS_SS_GC))
630 nilfs->ns_nongc_ctime = ssi.ctime;
634 if (!NILFS_SEG_LOGBGN(&ssi) || !NILFS_SEG_DSYNC(&ssi))
639 if (!NILFS_SEG_DSYNC(&ssi))
642 err = nilfs_scan_dsync_log(nilfs, pseg_start, &ssi,
646 if (NILFS_SEG_LOGEND(&ssi)) {
647 err = nilfs_recover_dsync_blocks(
648 nilfs, sbi, &dsync_blocks,
654 break; /* Fall through to try_next_pseg */
658 if (pseg_start == ri->ri_lsegs_end)
660 pseg_start += ssi.nblocks;
661 if (pseg_start < seg_end)
666 if (pseg_start == ri->ri_lsegs_end)
670 /* Looking to the next full segment */
675 nilfs_get_segment_range(nilfs, segnum, &seg_start, &seg_end);
676 pseg_start = seg_start;
679 if (nsalvaged_blocks) {
680 printk(KERN_INFO "NILFS (device %s): salvaged %lu blocks\n",
681 sbi->s_super->s_id, nsalvaged_blocks);
682 ri->ri_need_recovery = NILFS_RECOVERY_ROLLFORWARD_DONE;
685 dispose_recovery_list(&dsync_blocks);
686 nilfs_detach_writer(nilfs, sbi);
693 "NILFS (device %s): Error roll-forwarding "
694 "(err=%d, pseg block=%llu). ",
695 sbi->s_super->s_id, err, (unsigned long long)pseg_start);
699 static void nilfs_finish_roll_forward(struct the_nilfs *nilfs,
700 struct nilfs_recovery_info *ri)
702 struct buffer_head *bh;
705 if (nilfs_get_segnum_of_block(nilfs, ri->ri_lsegs_start) !=
706 nilfs_get_segnum_of_block(nilfs, ri->ri_super_root))
709 bh = __getblk(nilfs->ns_bdev, ri->ri_lsegs_start, nilfs->ns_blocksize);
711 memset(bh->b_data, 0, bh->b_size);
712 set_buffer_dirty(bh);
713 err = sync_dirty_buffer(bh);
716 "NILFS warning: buffer sync write failed during "
717 "post-cleaning of recovery.\n");
722 * nilfs_recover_logical_segments - salvage logical segments written after
723 * the latest super root
725 * @sbi: nilfs_sb_info
726 * @ri: pointer to a nilfs_recovery_info struct to store search results.
728 * Return Value: On success, 0 is returned. On error, one of the following
729 * negative error code is returned.
731 * %-EINVAL - Inconsistent filesystem state.
735 * %-ENOSPC - No space left on device (only in a panic state).
737 * %-ERESTARTSYS - Interrupted.
739 * %-ENOMEM - Insufficient memory available.
741 int nilfs_recover_logical_segments(struct the_nilfs *nilfs,
742 struct nilfs_sb_info *sbi,
743 struct nilfs_recovery_info *ri)
747 if (ri->ri_lsegs_start == 0 || ri->ri_lsegs_end == 0)
750 err = nilfs_attach_checkpoint(sbi, ri->ri_cno);
753 "NILFS: error loading the latest checkpoint.\n");
757 err = nilfs_do_roll_forward(nilfs, sbi, ri);
761 if (ri->ri_need_recovery == NILFS_RECOVERY_ROLLFORWARD_DONE) {
762 err = nilfs_prepare_segment_for_recovery(nilfs, sbi, ri);
764 printk(KERN_ERR "NILFS: Error preparing segments for "
769 err = nilfs_attach_segment_constructor(sbi);
773 set_nilfs_discontinued(nilfs);
774 err = nilfs_construct_segment(sbi->s_super);
775 nilfs_detach_segment_constructor(sbi);
778 printk(KERN_ERR "NILFS: Oops! recovery failed. "
783 nilfs_finish_roll_forward(nilfs, ri);
787 nilfs_detach_checkpoint(sbi);
792 * nilfs_search_super_root - search the latest valid super root
794 * @ri: pointer to a nilfs_recovery_info struct to store search results.
796 * nilfs_search_super_root() looks for the latest super-root from a partial
797 * segment pointed by the superblock. It sets up struct the_nilfs through
798 * this search. It fills nilfs_recovery_info (ri) required for recovery.
800 * Return Value: On success, 0 is returned. On error, one of the following
801 * negative error code is returned.
803 * %-EINVAL - No valid segment found
807 int nilfs_search_super_root(struct the_nilfs *nilfs,
808 struct nilfs_recovery_info *ri)
810 struct nilfs_segsum_info ssi;
811 sector_t pseg_start, pseg_end, sr_pseg_start = 0;
812 sector_t seg_start, seg_end; /* range of full segment (block number) */
815 __u64 segnum, nextnum = 0;
818 int empty_seg = 0, scan_newer = 0;
821 pseg_start = nilfs->ns_last_pseg;
822 seg_seq = nilfs->ns_last_seq;
823 cno = nilfs->ns_last_cno;
824 segnum = nilfs_get_segnum_of_block(nilfs, pseg_start);
826 /* Calculate range of segment */
827 nilfs_get_segment_range(nilfs, segnum, &seg_start, &seg_end);
829 /* Read ahead segment */
832 __breadahead(nilfs->ns_bdev, b++, nilfs->ns_blocksize);
835 ret = load_segment_summary(nilfs, pseg_start, seg_seq, &ssi);
837 if (ret == NILFS_SEG_FAIL_IO)
841 pseg_end = pseg_start + ssi.nblocks - 1;
842 if (unlikely(pseg_end > seg_end)) {
843 ret = NILFS_SEG_FAIL_CONSISTENCY;
847 /* A valid partial segment */
848 ri->ri_pseg_start = pseg_start;
849 ri->ri_seq = seg_seq;
850 ri->ri_segnum = segnum;
851 nextnum = nilfs_get_segnum_of_block(nilfs, ssi.next);
852 ri->ri_nextnum = nextnum;
855 if (!NILFS_SEG_HAS_SR(&ssi) && !scan_newer) {
856 /* This will never happen because a superblock
857 (last_segment) always points to a pseg
858 having a super root. */
859 ret = NILFS_SEG_FAIL_CONSISTENCY;
863 if (pseg_start == seg_start) {
864 nilfs_get_segment_range(nilfs, nextnum, &b, &end);
866 __breadahead(nilfs->ns_bdev, b++,
867 nilfs->ns_blocksize);
869 if (!NILFS_SEG_HAS_SR(&ssi)) {
870 if (!ri->ri_lsegs_start && NILFS_SEG_LOGBGN(&ssi)) {
871 ri->ri_lsegs_start = pseg_start;
872 ri->ri_lsegs_start_seq = seg_seq;
874 if (NILFS_SEG_LOGEND(&ssi))
875 ri->ri_lsegs_end = pseg_start;
879 /* A valid super root was found. */
881 ri->ri_super_root = pseg_end;
882 ri->ri_lsegs_start = ri->ri_lsegs_end = 0;
884 nilfs_dispose_segment_list(&segments);
885 nilfs->ns_pseg_offset = (sr_pseg_start = pseg_start)
886 + ssi.nblocks - seg_start;
887 nilfs->ns_seg_seq = seg_seq;
888 nilfs->ns_segnum = segnum;
889 nilfs->ns_cno = cno; /* nilfs->ns_cno = ri->ri_cno + 1 */
890 nilfs->ns_ctime = ssi.ctime;
891 nilfs->ns_nextnum = nextnum;
894 ri->ri_need_recovery = NILFS_RECOVERY_SR_UPDATED;
896 if (nilfs->ns_mount_state & NILFS_VALID_FS)
897 goto super_root_found;
901 /* reset region for roll-forward */
902 pseg_start += ssi.nblocks;
903 if (pseg_start < seg_end)
908 /* Standing on a course, or met an inconsistent state */
909 pseg_start += ssi.nblocks;
910 if (pseg_start < seg_end)
918 * This can happen if a checkpoint was written without
919 * barriers, or as a result of an I/O failure.
924 /* Looking to the next full segment */
926 goto super_root_found; /* found a valid super root */
928 ret = nilfs_segment_list_add(&segments, segnum);
934 nilfs_get_segment_range(nilfs, segnum, &seg_start, &seg_end);
935 pseg_start = seg_start;
939 /* Updating pointers relating to the latest checkpoint */
940 list_splice_tail(&segments, &ri->ri_used_segments);
941 nilfs->ns_last_pseg = sr_pseg_start;
942 nilfs->ns_last_seq = nilfs->ns_seg_seq;
943 nilfs->ns_last_cno = ri->ri_cno;
947 nilfs_dispose_segment_list(&segments);
948 return (ret < 0) ? ret : nilfs_warn_segment_error(ret);