2009-04-07 09:01:38 +07:00
|
|
|
/*
|
|
|
|
* recovery.c - NILFS recovery logic
|
|
|
|
*
|
|
|
|
* Copyright (C) 2005-2008 Nippon Telegraph and Telephone Corporation.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
2016-05-24 06:23:09 +07:00
|
|
|
* Written by Ryusuke Konishi.
|
2009-04-07 09:01:38 +07:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/buffer_head.h>
|
|
|
|
#include <linux/blkdev.h>
|
|
|
|
#include <linux/swap.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 15:04:11 +07:00
|
|
|
#include <linux/slab.h>
|
2009-04-07 09:01:38 +07:00
|
|
|
#include <linux/crc32.h>
|
|
|
|
#include "nilfs.h"
|
|
|
|
#include "segment.h"
|
|
|
|
#include "sufile.h"
|
|
|
|
#include "page.h"
|
|
|
|
#include "segbuf.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Segment check result
|
|
|
|
*/
|
|
|
|
enum {
|
|
|
|
NILFS_SEG_VALID,
|
|
|
|
NILFS_SEG_NO_SUPER_ROOT,
|
|
|
|
NILFS_SEG_FAIL_IO,
|
|
|
|
NILFS_SEG_FAIL_MAGIC,
|
|
|
|
NILFS_SEG_FAIL_SEQ,
|
|
|
|
NILFS_SEG_FAIL_CHECKSUM_SUPER_ROOT,
|
|
|
|
NILFS_SEG_FAIL_CHECKSUM_FULL,
|
|
|
|
NILFS_SEG_FAIL_CONSISTENCY,
|
|
|
|
};
|
|
|
|
|
|
|
|
/* work structure for recovery */
|
|
|
|
struct nilfs_recovery_block {
|
2016-05-24 06:23:48 +07:00
|
|
|
ino_t ino; /*
|
|
|
|
* Inode number of the file that this block
|
|
|
|
* belongs to
|
|
|
|
*/
|
2009-04-07 09:01:38 +07:00
|
|
|
sector_t blocknr; /* block number */
|
|
|
|
__u64 vblocknr; /* virtual block number */
|
|
|
|
unsigned long blkoff; /* File offset of the data block (per block) */
|
|
|
|
struct list_head list;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2016-08-03 04:05:10 +07:00
|
|
|
static int nilfs_warn_segment_error(struct super_block *sb, int err)
|
2009-04-07 09:01:38 +07:00
|
|
|
{
|
2016-08-03 04:05:10 +07:00
|
|
|
const char *msg = NULL;
|
|
|
|
|
2009-04-07 09:01:38 +07:00
|
|
|
switch (err) {
|
|
|
|
case NILFS_SEG_FAIL_IO:
|
2016-08-03 04:05:10 +07:00
|
|
|
nilfs_msg(sb, KERN_ERR, "I/O error reading segment");
|
2009-04-07 09:01:38 +07:00
|
|
|
return -EIO;
|
|
|
|
case NILFS_SEG_FAIL_MAGIC:
|
2016-08-03 04:05:10 +07:00
|
|
|
msg = "Magic number mismatch";
|
2009-04-07 09:01:38 +07:00
|
|
|
break;
|
|
|
|
case NILFS_SEG_FAIL_SEQ:
|
2016-08-03 04:05:10 +07:00
|
|
|
msg = "Sequence number mismatch";
|
2009-04-07 09:01:38 +07:00
|
|
|
break;
|
|
|
|
case NILFS_SEG_FAIL_CHECKSUM_SUPER_ROOT:
|
2016-08-03 04:05:10 +07:00
|
|
|
msg = "Checksum error in super root";
|
2009-04-07 09:01:38 +07:00
|
|
|
break;
|
|
|
|
case NILFS_SEG_FAIL_CHECKSUM_FULL:
|
2016-08-03 04:05:10 +07:00
|
|
|
msg = "Checksum error in segment payload";
|
2009-04-07 09:01:38 +07:00
|
|
|
break;
|
|
|
|
case NILFS_SEG_FAIL_CONSISTENCY:
|
2016-08-03 04:05:10 +07:00
|
|
|
msg = "Inconsistency found";
|
2009-04-07 09:01:38 +07:00
|
|
|
break;
|
|
|
|
case NILFS_SEG_NO_SUPER_ROOT:
|
2016-08-03 04:05:10 +07:00
|
|
|
msg = "No super root in the last segment";
|
2009-04-07 09:01:38 +07:00
|
|
|
break;
|
2016-08-03 04:05:10 +07:00
|
|
|
default:
|
|
|
|
nilfs_msg(sb, KERN_ERR, "unrecognized segment error %d", err);
|
|
|
|
return -EINVAL;
|
2009-04-07 09:01:38 +07:00
|
|
|
}
|
2016-08-03 04:05:10 +07:00
|
|
|
nilfs_msg(sb, KERN_WARNING, "invalid segment: %s", msg);
|
2009-04-07 09:01:38 +07:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-05-22 23:39:02 +07:00
|
|
|
* nilfs_compute_checksum - compute checksum of blocks continuously
|
|
|
|
* @nilfs: nilfs object
|
2009-04-07 09:01:38 +07:00
|
|
|
* @bhs: buffer head of start block
|
|
|
|
* @sum: place to store result
|
|
|
|
* @offset: offset bytes in the first block
|
|
|
|
* @check_bytes: number of bytes to be checked
|
|
|
|
* @start: DBN of start block
|
|
|
|
* @nblock: number of blocks to be checked
|
|
|
|
*/
|
2010-05-22 23:39:02 +07:00
|
|
|
static int nilfs_compute_checksum(struct the_nilfs *nilfs,
|
|
|
|
struct buffer_head *bhs, u32 *sum,
|
|
|
|
unsigned long offset, u64 check_bytes,
|
|
|
|
sector_t start, unsigned long nblock)
|
2009-04-07 09:01:38 +07:00
|
|
|
{
|
2010-05-22 23:39:02 +07:00
|
|
|
unsigned int blocksize = nilfs->ns_blocksize;
|
2009-04-07 09:01:38 +07:00
|
|
|
unsigned long size;
|
|
|
|
u32 crc;
|
|
|
|
|
|
|
|
BUG_ON(offset >= blocksize);
|
|
|
|
check_bytes -= offset;
|
|
|
|
size = min_t(u64, check_bytes, blocksize - offset);
|
2010-05-22 23:39:02 +07:00
|
|
|
crc = crc32_le(nilfs->ns_crc_seed,
|
2009-04-07 09:01:38 +07:00
|
|
|
(unsigned char *)bhs->b_data + offset, size);
|
|
|
|
if (--nblock > 0) {
|
|
|
|
do {
|
2010-05-22 23:39:02 +07:00
|
|
|
struct buffer_head *bh;
|
|
|
|
|
|
|
|
bh = __bread(nilfs->ns_bdev, ++start, blocksize);
|
2009-04-07 09:01:38 +07:00
|
|
|
if (!bh)
|
|
|
|
return -EIO;
|
|
|
|
check_bytes -= size;
|
|
|
|
size = min_t(u64, check_bytes, blocksize);
|
|
|
|
crc = crc32_le(crc, bh->b_data, size);
|
|
|
|
brelse(bh);
|
|
|
|
} while (--nblock > 0);
|
|
|
|
}
|
|
|
|
*sum = crc;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* nilfs_read_super_root_block - read super root block
|
2010-05-22 23:39:02 +07:00
|
|
|
* @nilfs: nilfs object
|
2009-04-07 09:01:38 +07:00
|
|
|
* @sr_block: disk block number of the super root block
|
|
|
|
* @pbh: address of a buffer_head pointer to return super root buffer
|
|
|
|
* @check: CRC check flag
|
|
|
|
*/
|
2010-05-22 23:39:02 +07:00
|
|
|
int nilfs_read_super_root_block(struct the_nilfs *nilfs, sector_t sr_block,
|
2009-04-07 09:01:38 +07:00
|
|
|
struct buffer_head **pbh, int check)
|
|
|
|
{
|
|
|
|
struct buffer_head *bh_sr;
|
|
|
|
struct nilfs_super_root *sr;
|
|
|
|
u32 crc;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
*pbh = NULL;
|
2010-05-22 23:39:02 +07:00
|
|
|
bh_sr = __bread(nilfs->ns_bdev, sr_block, nilfs->ns_blocksize);
|
2009-04-07 09:01:38 +07:00
|
|
|
if (unlikely(!bh_sr)) {
|
|
|
|
ret = NILFS_SEG_FAIL_IO;
|
|
|
|
goto failed;
|
|
|
|
}
|
|
|
|
|
|
|
|
sr = (struct nilfs_super_root *)bh_sr->b_data;
|
|
|
|
if (check) {
|
2016-05-24 06:23:39 +07:00
|
|
|
unsigned int bytes = le16_to_cpu(sr->sr_bytes);
|
2009-04-07 09:01:38 +07:00
|
|
|
|
2010-05-22 23:39:02 +07:00
|
|
|
if (bytes == 0 || bytes > nilfs->ns_blocksize) {
|
2009-04-07 09:01:38 +07:00
|
|
|
ret = NILFS_SEG_FAIL_CHECKSUM_SUPER_ROOT;
|
|
|
|
goto failed_bh;
|
|
|
|
}
|
2010-05-22 23:39:02 +07:00
|
|
|
if (nilfs_compute_checksum(
|
|
|
|
nilfs, bh_sr, &crc, sizeof(sr->sr_sum), bytes,
|
|
|
|
sr_block, 1)) {
|
2009-04-07 09:01:38 +07:00
|
|
|
ret = NILFS_SEG_FAIL_IO;
|
|
|
|
goto failed_bh;
|
|
|
|
}
|
|
|
|
if (crc != le32_to_cpu(sr->sr_sum)) {
|
|
|
|
ret = NILFS_SEG_FAIL_CHECKSUM_SUPER_ROOT;
|
|
|
|
goto failed_bh;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*pbh = bh_sr;
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
failed_bh:
|
|
|
|
brelse(bh_sr);
|
|
|
|
|
|
|
|
failed:
|
2016-08-03 04:05:10 +07:00
|
|
|
return nilfs_warn_segment_error(nilfs->ns_sb, ret);
|
2009-04-07 09:01:38 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-05-23 17:21:49 +07:00
|
|
|
* nilfs_read_log_header - read summary header of the specified log
|
2010-05-22 23:39:02 +07:00
|
|
|
* @nilfs: nilfs object
|
2010-05-23 17:21:49 +07:00
|
|
|
* @start_blocknr: start block number of the log
|
|
|
|
* @sum: pointer to return segment summary structure
|
2009-04-07 09:01:38 +07:00
|
|
|
*/
|
2010-05-23 17:21:49 +07:00
|
|
|
static struct buffer_head *
|
|
|
|
nilfs_read_log_header(struct the_nilfs *nilfs, sector_t start_blocknr,
|
|
|
|
struct nilfs_segment_summary **sum)
|
2009-04-07 09:01:38 +07:00
|
|
|
{
|
|
|
|
struct buffer_head *bh_sum;
|
2010-05-23 17:21:49 +07:00
|
|
|
|
|
|
|
bh_sum = __bread(nilfs->ns_bdev, start_blocknr, nilfs->ns_blocksize);
|
|
|
|
if (bh_sum)
|
|
|
|
*sum = (struct nilfs_segment_summary *)bh_sum->b_data;
|
|
|
|
return bh_sum;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* nilfs_validate_log - verify consistency of log
|
|
|
|
* @nilfs: nilfs object
|
|
|
|
* @seg_seq: sequence number of segment
|
|
|
|
* @bh_sum: buffer head of summary block
|
|
|
|
* @sum: segment summary struct
|
|
|
|
*/
|
|
|
|
static int nilfs_validate_log(struct the_nilfs *nilfs, u64 seg_seq,
|
|
|
|
struct buffer_head *bh_sum,
|
|
|
|
struct nilfs_segment_summary *sum)
|
|
|
|
{
|
2010-02-18 17:11:35 +07:00
|
|
|
unsigned long nblock;
|
|
|
|
u32 crc;
|
2010-05-23 17:21:49 +07:00
|
|
|
int ret;
|
2009-04-07 09:01:38 +07:00
|
|
|
|
2010-05-23 17:21:49 +07:00
|
|
|
ret = NILFS_SEG_FAIL_MAGIC;
|
|
|
|
if (le32_to_cpu(sum->ss_magic) != NILFS_SEGSUM_MAGIC)
|
2009-04-07 09:01:38 +07:00
|
|
|
goto out;
|
|
|
|
|
2010-05-23 17:21:49 +07:00
|
|
|
ret = NILFS_SEG_FAIL_SEQ;
|
|
|
|
if (le64_to_cpu(sum->ss_seq) != seg_seq)
|
|
|
|
goto out;
|
2009-04-07 09:01:38 +07:00
|
|
|
|
2010-05-23 17:21:49 +07:00
|
|
|
nblock = le32_to_cpu(sum->ss_nblocks);
|
|
|
|
ret = NILFS_SEG_FAIL_CONSISTENCY;
|
|
|
|
if (unlikely(nblock == 0 || nblock > nilfs->ns_blocks_per_segment))
|
2009-04-07 09:01:38 +07:00
|
|
|
/* This limits the number of blocks read in the CRC check */
|
2010-05-23 17:21:49 +07:00
|
|
|
goto out;
|
|
|
|
|
|
|
|
ret = NILFS_SEG_FAIL_IO;
|
2010-05-22 23:39:02 +07:00
|
|
|
if (nilfs_compute_checksum(nilfs, bh_sum, &crc, sizeof(sum->ss_datasum),
|
|
|
|
((u64)nblock << nilfs->ns_blocksize_bits),
|
2010-05-23 17:21:49 +07:00
|
|
|
bh_sum->b_blocknr, nblock))
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
ret = NILFS_SEG_FAIL_CHECKSUM_FULL;
|
|
|
|
if (crc != le32_to_cpu(sum->ss_datasum))
|
|
|
|
goto out;
|
|
|
|
ret = 0;
|
|
|
|
out:
|
2009-04-07 09:01:38 +07:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-05-22 23:39:02 +07:00
|
|
|
/**
|
|
|
|
* nilfs_read_summary_info - read an item on summary blocks of a log
|
|
|
|
* @nilfs: nilfs object
|
|
|
|
* @pbh: the current buffer head on summary blocks [in, out]
|
|
|
|
* @offset: the current byte offset on summary blocks [in, out]
|
|
|
|
* @bytes: byte size of the item to be read
|
|
|
|
*/
|
|
|
|
static void *nilfs_read_summary_info(struct the_nilfs *nilfs,
|
|
|
|
struct buffer_head **pbh,
|
|
|
|
unsigned int *offset, unsigned int bytes)
|
2009-04-07 09:01:38 +07:00
|
|
|
{
|
|
|
|
void *ptr;
|
|
|
|
sector_t blocknr;
|
|
|
|
|
|
|
|
BUG_ON((*pbh)->b_size < *offset);
|
|
|
|
if (bytes > (*pbh)->b_size - *offset) {
|
|
|
|
blocknr = (*pbh)->b_blocknr;
|
|
|
|
brelse(*pbh);
|
2010-05-22 23:39:02 +07:00
|
|
|
*pbh = __bread(nilfs->ns_bdev, blocknr + 1,
|
|
|
|
nilfs->ns_blocksize);
|
2009-04-07 09:01:38 +07:00
|
|
|
if (unlikely(!*pbh))
|
|
|
|
return NULL;
|
|
|
|
*offset = 0;
|
|
|
|
}
|
|
|
|
ptr = (*pbh)->b_data + *offset;
|
|
|
|
*offset += bytes;
|
|
|
|
return ptr;
|
|
|
|
}
|
|
|
|
|
2010-05-22 23:39:02 +07:00
|
|
|
/**
|
|
|
|
* nilfs_skip_summary_info - skip items on summary blocks of a log
|
|
|
|
* @nilfs: nilfs object
|
|
|
|
* @pbh: the current buffer head on summary blocks [in, out]
|
|
|
|
* @offset: the current byte offset on summary blocks [in, out]
|
|
|
|
* @bytes: byte size of the item to be skipped
|
|
|
|
* @count: number of items to be skipped
|
|
|
|
*/
|
|
|
|
static void nilfs_skip_summary_info(struct the_nilfs *nilfs,
|
|
|
|
struct buffer_head **pbh,
|
|
|
|
unsigned int *offset, unsigned int bytes,
|
|
|
|
unsigned long count)
|
2009-04-07 09:01:38 +07:00
|
|
|
{
|
|
|
|
unsigned int rest_item_in_current_block
|
|
|
|
= ((*pbh)->b_size - *offset) / bytes;
|
|
|
|
|
|
|
|
if (count <= rest_item_in_current_block) {
|
|
|
|
*offset += bytes * count;
|
|
|
|
} else {
|
|
|
|
sector_t blocknr = (*pbh)->b_blocknr;
|
|
|
|
unsigned int nitem_per_block = (*pbh)->b_size / bytes;
|
|
|
|
unsigned int bcnt;
|
|
|
|
|
|
|
|
count -= rest_item_in_current_block;
|
|
|
|
bcnt = DIV_ROUND_UP(count, nitem_per_block);
|
|
|
|
*offset = bytes * (count - (bcnt - 1) * nitem_per_block);
|
|
|
|
|
|
|
|
brelse(*pbh);
|
2010-05-22 23:39:02 +07:00
|
|
|
*pbh = __bread(nilfs->ns_bdev, blocknr + bcnt,
|
|
|
|
nilfs->ns_blocksize);
|
2009-04-07 09:01:38 +07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-22 23:39:02 +07:00
|
|
|
/**
|
|
|
|
* nilfs_scan_dsync_log - get block information of a log written for data sync
|
|
|
|
* @nilfs: nilfs object
|
|
|
|
* @start_blocknr: start block number of the log
|
2010-05-23 17:46:44 +07:00
|
|
|
* @sum: log summary information
|
2010-05-22 23:39:02 +07:00
|
|
|
* @head: list head to add nilfs_recovery_block struct
|
|
|
|
*/
|
|
|
|
static int nilfs_scan_dsync_log(struct the_nilfs *nilfs, sector_t start_blocknr,
|
2010-05-23 17:46:44 +07:00
|
|
|
struct nilfs_segment_summary *sum,
|
2010-05-22 23:39:02 +07:00
|
|
|
struct list_head *head)
|
2009-04-07 09:01:38 +07:00
|
|
|
{
|
|
|
|
struct buffer_head *bh;
|
|
|
|
unsigned int offset;
|
2010-05-23 17:46:44 +07:00
|
|
|
u32 nfinfo, sumbytes;
|
|
|
|
sector_t blocknr;
|
2009-04-07 09:01:38 +07:00
|
|
|
ino_t ino;
|
|
|
|
int err = -EIO;
|
|
|
|
|
2010-05-23 17:46:44 +07:00
|
|
|
nfinfo = le32_to_cpu(sum->ss_nfinfo);
|
2009-04-07 09:01:38 +07:00
|
|
|
if (!nfinfo)
|
|
|
|
return 0;
|
|
|
|
|
2010-05-23 17:46:44 +07:00
|
|
|
sumbytes = le32_to_cpu(sum->ss_sumbytes);
|
|
|
|
blocknr = start_blocknr + DIV_ROUND_UP(sumbytes, nilfs->ns_blocksize);
|
2010-05-22 23:39:02 +07:00
|
|
|
bh = __bread(nilfs->ns_bdev, start_blocknr, nilfs->ns_blocksize);
|
2009-04-07 09:01:38 +07:00
|
|
|
if (unlikely(!bh))
|
|
|
|
goto out;
|
|
|
|
|
2010-05-23 17:46:44 +07:00
|
|
|
offset = le16_to_cpu(sum->ss_bytes);
|
2009-04-07 09:01:38 +07:00
|
|
|
for (;;) {
|
|
|
|
unsigned long nblocks, ndatablk, nnodeblk;
|
|
|
|
struct nilfs_finfo *finfo;
|
|
|
|
|
2010-05-22 23:39:02 +07:00
|
|
|
finfo = nilfs_read_summary_info(nilfs, &bh, &offset,
|
|
|
|
sizeof(*finfo));
|
2009-04-07 09:01:38 +07:00
|
|
|
if (unlikely(!finfo))
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
ino = le64_to_cpu(finfo->fi_ino);
|
|
|
|
nblocks = le32_to_cpu(finfo->fi_nblocks);
|
|
|
|
ndatablk = le32_to_cpu(finfo->fi_ndatablk);
|
|
|
|
nnodeblk = nblocks - ndatablk;
|
|
|
|
|
|
|
|
while (ndatablk-- > 0) {
|
|
|
|
struct nilfs_recovery_block *rb;
|
|
|
|
struct nilfs_binfo_v *binfo;
|
|
|
|
|
2010-05-22 23:39:02 +07:00
|
|
|
binfo = nilfs_read_summary_info(nilfs, &bh, &offset,
|
|
|
|
sizeof(*binfo));
|
2009-04-07 09:01:38 +07:00
|
|
|
if (unlikely(!binfo))
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
rb = kmalloc(sizeof(*rb), GFP_NOFS);
|
|
|
|
if (unlikely(!rb)) {
|
|
|
|
err = -ENOMEM;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
rb->ino = ino;
|
|
|
|
rb->blocknr = blocknr++;
|
|
|
|
rb->vblocknr = le64_to_cpu(binfo->bi_vblocknr);
|
|
|
|
rb->blkoff = le64_to_cpu(binfo->bi_blkoff);
|
|
|
|
/* INIT_LIST_HEAD(&rb->list); */
|
|
|
|
list_add_tail(&rb->list, head);
|
|
|
|
}
|
|
|
|
if (--nfinfo == 0)
|
|
|
|
break;
|
2010-05-22 23:39:02 +07:00
|
|
|
blocknr += nnodeblk; /* always 0 for data sync logs */
|
|
|
|
nilfs_skip_summary_info(nilfs, &bh, &offset, sizeof(__le64),
|
|
|
|
nnodeblk);
|
2009-04-07 09:01:38 +07:00
|
|
|
if (unlikely(!bh))
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
err = 0;
|
|
|
|
out:
|
|
|
|
brelse(bh); /* brelse(NULL) is just ignored */
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void dispose_recovery_list(struct list_head *head)
|
|
|
|
{
|
|
|
|
while (!list_empty(head)) {
|
2011-05-05 10:56:51 +07:00
|
|
|
struct nilfs_recovery_block *rb;
|
|
|
|
|
|
|
|
rb = list_first_entry(head, struct nilfs_recovery_block, list);
|
2009-04-07 09:01:38 +07:00
|
|
|
list_del(&rb->list);
|
|
|
|
kfree(rb);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-17 17:07:21 +07:00
|
|
|
struct nilfs_segment_entry {
|
|
|
|
struct list_head list;
|
|
|
|
__u64 segnum;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int nilfs_segment_list_add(struct list_head *head, __u64 segnum)
|
|
|
|
{
|
|
|
|
struct nilfs_segment_entry *ent = kmalloc(sizeof(*ent), GFP_NOFS);
|
|
|
|
|
|
|
|
if (unlikely(!ent))
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
ent->segnum = segnum;
|
|
|
|
INIT_LIST_HEAD(&ent->list);
|
|
|
|
list_add_tail(&ent->list, head);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-04-07 09:01:38 +07:00
|
|
|
void nilfs_dispose_segment_list(struct list_head *head)
|
|
|
|
{
|
|
|
|
while (!list_empty(head)) {
|
2011-05-05 10:56:51 +07:00
|
|
|
struct nilfs_segment_entry *ent;
|
|
|
|
|
|
|
|
ent = list_first_entry(head, struct nilfs_segment_entry, list);
|
2009-04-07 09:01:38 +07:00
|
|
|
list_del(&ent->list);
|
2009-05-17 17:07:21 +07:00
|
|
|
kfree(ent);
|
2009-04-07 09:01:38 +07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int nilfs_prepare_segment_for_recovery(struct the_nilfs *nilfs,
|
2011-03-09 09:05:08 +07:00
|
|
|
struct super_block *sb,
|
2009-04-07 09:01:38 +07:00
|
|
|
struct nilfs_recovery_info *ri)
|
|
|
|
{
|
|
|
|
struct list_head *head = &ri->ri_used_segments;
|
|
|
|
struct nilfs_segment_entry *ent, *n;
|
|
|
|
struct inode *sufile = nilfs->ns_sufile;
|
|
|
|
__u64 segnum[4];
|
|
|
|
int err;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
segnum[0] = nilfs->ns_segnum;
|
|
|
|
segnum[1] = nilfs->ns_nextnum;
|
|
|
|
segnum[2] = ri->ri_segnum;
|
|
|
|
segnum[3] = ri->ri_nextnum;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Releasing the next segment of the latest super root.
|
|
|
|
* The next segment is invalidated by this recovery.
|
|
|
|
*/
|
|
|
|
err = nilfs_sufile_free(sufile, segnum[1]);
|
|
|
|
if (unlikely(err))
|
|
|
|
goto failed;
|
|
|
|
|
|
|
|
for (i = 1; i < 4; i++) {
|
2009-05-17 17:07:21 +07:00
|
|
|
err = nilfs_segment_list_add(head, segnum[i]);
|
|
|
|
if (unlikely(err))
|
2009-04-07 09:01:38 +07:00
|
|
|
goto failed;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Collecting segments written after the latest super root.
|
2009-04-07 09:01:54 +07:00
|
|
|
* These are marked dirty to avoid being reallocated in the next write.
|
2009-04-07 09:01:38 +07:00
|
|
|
*/
|
|
|
|
list_for_each_entry_safe(ent, n, head, list) {
|
2009-04-05 16:30:58 +07:00
|
|
|
if (ent->segnum != segnum[0]) {
|
|
|
|
err = nilfs_sufile_scrap(sufile, ent->segnum);
|
|
|
|
if (unlikely(err))
|
|
|
|
goto failed;
|
2009-04-07 09:01:38 +07:00
|
|
|
}
|
2009-04-07 09:01:54 +07:00
|
|
|
list_del(&ent->list);
|
2009-05-17 17:07:21 +07:00
|
|
|
kfree(ent);
|
2009-04-07 09:01:38 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Allocate new segments for recovery */
|
|
|
|
err = nilfs_sufile_alloc(sufile, &segnum[0]);
|
|
|
|
if (unlikely(err))
|
|
|
|
goto failed;
|
|
|
|
|
|
|
|
nilfs->ns_pseg_offset = 0;
|
|
|
|
nilfs->ns_seg_seq = ri->ri_seq + 2;
|
|
|
|
nilfs->ns_nextnum = nilfs->ns_segnum = segnum[0];
|
|
|
|
|
|
|
|
failed:
|
|
|
|
/* No need to recover sufile because it will be destroyed on error */
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2010-05-22 23:39:02 +07:00
|
|
|
static int nilfs_recovery_copy_block(struct the_nilfs *nilfs,
|
2009-04-07 09:01:38 +07:00
|
|
|
struct nilfs_recovery_block *rb,
|
|
|
|
struct page *page)
|
|
|
|
{
|
|
|
|
struct buffer_head *bh_org;
|
|
|
|
void *kaddr;
|
|
|
|
|
2010-05-22 23:39:02 +07:00
|
|
|
bh_org = __bread(nilfs->ns_bdev, rb->blocknr, nilfs->ns_blocksize);
|
2009-04-07 09:01:38 +07:00
|
|
|
if (unlikely(!bh_org))
|
|
|
|
return -EIO;
|
|
|
|
|
2011-11-25 22:14:33 +07:00
|
|
|
kaddr = kmap_atomic(page);
|
2009-04-07 09:01:38 +07:00
|
|
|
memcpy(kaddr + bh_offset(bh_org), bh_org->b_data, bh_org->b_size);
|
2011-11-25 22:14:33 +07:00
|
|
|
kunmap_atomic(kaddr);
|
2009-04-07 09:01:38 +07:00
|
|
|
brelse(bh_org);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-05-22 23:39:02 +07:00
|
|
|
static int nilfs_recover_dsync_blocks(struct the_nilfs *nilfs,
|
2011-03-09 09:05:08 +07:00
|
|
|
struct super_block *sb,
|
2010-08-25 15:45:44 +07:00
|
|
|
struct nilfs_root *root,
|
2010-05-22 23:39:02 +07:00
|
|
|
struct list_head *head,
|
|
|
|
unsigned long *nr_salvaged_blocks)
|
2009-04-07 09:01:38 +07:00
|
|
|
{
|
|
|
|
struct inode *inode;
|
|
|
|
struct nilfs_recovery_block *rb, *n;
|
2016-05-24 06:23:39 +07:00
|
|
|
unsigned int blocksize = nilfs->ns_blocksize;
|
2009-04-07 09:01:38 +07:00
|
|
|
struct page *page;
|
|
|
|
loff_t pos;
|
|
|
|
int err = 0, err2 = 0;
|
|
|
|
|
|
|
|
list_for_each_entry_safe(rb, n, head, list) {
|
2011-03-09 09:05:08 +07:00
|
|
|
inode = nilfs_iget(sb, root, rb->ino);
|
2009-04-07 09:01:38 +07:00
|
|
|
if (IS_ERR(inode)) {
|
|
|
|
err = PTR_ERR(inode);
|
|
|
|
inode = NULL;
|
|
|
|
goto failed_inode;
|
|
|
|
}
|
|
|
|
|
|
|
|
pos = rb->blkoff << inode->i_blkbits;
|
2010-06-04 16:29:58 +07:00
|
|
|
err = block_write_begin(inode->i_mapping, pos, blocksize,
|
|
|
|
0, &page, nilfs_get_block);
|
|
|
|
if (unlikely(err)) {
|
|
|
|
loff_t isize = inode->i_size;
|
2016-05-24 06:23:25 +07:00
|
|
|
|
2010-06-04 16:29:58 +07:00
|
|
|
if (pos + blocksize > isize)
|
2012-12-15 17:57:37 +07:00
|
|
|
nilfs_write_failed(inode->i_mapping,
|
|
|
|
pos + blocksize);
|
2009-04-07 09:01:38 +07:00
|
|
|
goto failed_inode;
|
2010-06-04 16:29:58 +07:00
|
|
|
}
|
2009-04-07 09:01:38 +07:00
|
|
|
|
2010-05-22 23:39:02 +07:00
|
|
|
err = nilfs_recovery_copy_block(nilfs, rb, page);
|
2009-04-07 09:01:38 +07:00
|
|
|
if (unlikely(err))
|
|
|
|
goto failed_page;
|
|
|
|
|
2010-12-26 22:05:49 +07:00
|
|
|
err = nilfs_set_file_dirty(inode, 1);
|
2009-04-07 09:01:38 +07:00
|
|
|
if (unlikely(err))
|
|
|
|
goto failed_page;
|
|
|
|
|
|
|
|
block_write_end(NULL, inode->i_mapping, pos, blocksize,
|
|
|
|
blocksize, page, NULL);
|
|
|
|
|
|
|
|
unlock_page(page);
|
mm, fs: get rid of PAGE_CACHE_* and page_cache_{get,release} macros
PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} macros were introduced *long* time
ago with promise that one day it will be possible to implement page
cache with bigger chunks than PAGE_SIZE.
This promise never materialized. And unlikely will.
We have many places where PAGE_CACHE_SIZE assumed to be equal to
PAGE_SIZE. And it's constant source of confusion on whether
PAGE_CACHE_* or PAGE_* constant should be used in a particular case,
especially on the border between fs and mm.
Global switching to PAGE_CACHE_SIZE != PAGE_SIZE would cause to much
breakage to be doable.
Let's stop pretending that pages in page cache are special. They are
not.
The changes are pretty straight-forward:
- <foo> << (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- <foo> >> (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} -> PAGE_{SIZE,SHIFT,MASK,ALIGN};
- page_cache_get() -> get_page();
- page_cache_release() -> put_page();
This patch contains automated changes generated with coccinelle using
script below. For some reason, coccinelle doesn't patch header files.
I've called spatch for them manually.
The only adjustment after coccinelle is revert of changes to
PAGE_CAHCE_ALIGN definition: we are going to drop it later.
There are few places in the code where coccinelle didn't reach. I'll
fix them manually in a separate patch. Comments and documentation also
will be addressed with the separate patch.
virtual patch
@@
expression E;
@@
- E << (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
expression E;
@@
- E >> (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
@@
- PAGE_CACHE_SHIFT
+ PAGE_SHIFT
@@
@@
- PAGE_CACHE_SIZE
+ PAGE_SIZE
@@
@@
- PAGE_CACHE_MASK
+ PAGE_MASK
@@
expression E;
@@
- PAGE_CACHE_ALIGN(E)
+ PAGE_ALIGN(E)
@@
expression E;
@@
- page_cache_get(E)
+ get_page(E)
@@
expression E;
@@
- page_cache_release(E)
+ put_page(E)
Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Acked-by: Michal Hocko <mhocko@suse.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2016-04-01 19:29:47 +07:00
|
|
|
put_page(page);
|
2009-04-07 09:01:38 +07:00
|
|
|
|
|
|
|
(*nr_salvaged_blocks)++;
|
|
|
|
goto next;
|
|
|
|
|
|
|
|
failed_page:
|
|
|
|
unlock_page(page);
|
mm, fs: get rid of PAGE_CACHE_* and page_cache_{get,release} macros
PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} macros were introduced *long* time
ago with promise that one day it will be possible to implement page
cache with bigger chunks than PAGE_SIZE.
This promise never materialized. And unlikely will.
We have many places where PAGE_CACHE_SIZE assumed to be equal to
PAGE_SIZE. And it's constant source of confusion on whether
PAGE_CACHE_* or PAGE_* constant should be used in a particular case,
especially on the border between fs and mm.
Global switching to PAGE_CACHE_SIZE != PAGE_SIZE would cause to much
breakage to be doable.
Let's stop pretending that pages in page cache are special. They are
not.
The changes are pretty straight-forward:
- <foo> << (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- <foo> >> (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} -> PAGE_{SIZE,SHIFT,MASK,ALIGN};
- page_cache_get() -> get_page();
- page_cache_release() -> put_page();
This patch contains automated changes generated with coccinelle using
script below. For some reason, coccinelle doesn't patch header files.
I've called spatch for them manually.
The only adjustment after coccinelle is revert of changes to
PAGE_CAHCE_ALIGN definition: we are going to drop it later.
There are few places in the code where coccinelle didn't reach. I'll
fix them manually in a separate patch. Comments and documentation also
will be addressed with the separate patch.
virtual patch
@@
expression E;
@@
- E << (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
expression E;
@@
- E >> (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
@@
- PAGE_CACHE_SHIFT
+ PAGE_SHIFT
@@
@@
- PAGE_CACHE_SIZE
+ PAGE_SIZE
@@
@@
- PAGE_CACHE_MASK
+ PAGE_MASK
@@
expression E;
@@
- PAGE_CACHE_ALIGN(E)
+ PAGE_ALIGN(E)
@@
expression E;
@@
- page_cache_get(E)
+ get_page(E)
@@
expression E;
@@
- page_cache_release(E)
+ put_page(E)
Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Acked-by: Michal Hocko <mhocko@suse.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2016-04-01 19:29:47 +07:00
|
|
|
put_page(page);
|
2009-04-07 09:01:38 +07:00
|
|
|
|
|
|
|
failed_inode:
|
2016-08-03 04:05:10 +07:00
|
|
|
nilfs_msg(sb, KERN_WARNING,
|
|
|
|
"error %d recovering data block (ino=%lu, block-offset=%llu)",
|
|
|
|
err, (unsigned long)rb->ino,
|
|
|
|
(unsigned long long)rb->blkoff);
|
2009-04-07 09:01:38 +07:00
|
|
|
if (!err2)
|
|
|
|
err2 = err;
|
|
|
|
next:
|
|
|
|
iput(inode); /* iput(NULL) is just ignored */
|
|
|
|
list_del_init(&rb->list);
|
|
|
|
kfree(rb);
|
|
|
|
}
|
|
|
|
return err2;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* nilfs_do_roll_forward - salvage logical segments newer than the latest
|
|
|
|
* checkpoint
|
2010-05-22 23:39:02 +07:00
|
|
|
* @nilfs: nilfs object
|
2011-03-09 09:05:08 +07:00
|
|
|
* @sb: super block instance
|
2009-04-07 09:01:38 +07:00
|
|
|
* @ri: pointer to a nilfs_recovery_info
|
|
|
|
*/
|
|
|
|
static int nilfs_do_roll_forward(struct the_nilfs *nilfs,
|
2011-03-09 09:05:08 +07:00
|
|
|
struct super_block *sb,
|
2010-08-25 15:45:44 +07:00
|
|
|
struct nilfs_root *root,
|
2009-04-07 09:01:38 +07:00
|
|
|
struct nilfs_recovery_info *ri)
|
|
|
|
{
|
2010-05-23 17:21:49 +07:00
|
|
|
struct buffer_head *bh_sum = NULL;
|
2015-11-07 07:32:16 +07:00
|
|
|
struct nilfs_segment_summary *sum = NULL;
|
2009-04-07 09:01:38 +07:00
|
|
|
sector_t pseg_start;
|
|
|
|
sector_t seg_start, seg_end; /* Starting/ending DBN of full segment */
|
|
|
|
unsigned long nsalvaged_blocks = 0;
|
2010-05-23 17:46:44 +07:00
|
|
|
unsigned int flags;
|
2009-04-07 09:01:38 +07:00
|
|
|
u64 seg_seq;
|
|
|
|
__u64 segnum, nextnum = 0;
|
|
|
|
int empty_seg = 0;
|
|
|
|
int err = 0, ret;
|
|
|
|
LIST_HEAD(dsync_blocks); /* list of data blocks to be recovered */
|
|
|
|
enum {
|
|
|
|
RF_INIT_ST,
|
|
|
|
RF_DSYNC_ST, /* scanning data-sync segments */
|
|
|
|
};
|
|
|
|
int state = RF_INIT_ST;
|
|
|
|
|
|
|
|
pseg_start = ri->ri_lsegs_start;
|
|
|
|
seg_seq = ri->ri_lsegs_start_seq;
|
|
|
|
segnum = nilfs_get_segnum_of_block(nilfs, pseg_start);
|
|
|
|
nilfs_get_segment_range(nilfs, segnum, &seg_start, &seg_end);
|
|
|
|
|
|
|
|
while (segnum != ri->ri_segnum || pseg_start <= ri->ri_pseg_start) {
|
2010-05-23 17:21:49 +07:00
|
|
|
brelse(bh_sum);
|
|
|
|
bh_sum = nilfs_read_log_header(nilfs, pseg_start, &sum);
|
|
|
|
if (!bh_sum) {
|
|
|
|
err = -EIO;
|
|
|
|
goto failed;
|
|
|
|
}
|
2009-04-07 09:01:38 +07:00
|
|
|
|
2010-05-23 17:21:49 +07:00
|
|
|
ret = nilfs_validate_log(nilfs, seg_seq, bh_sum, sum);
|
2009-04-07 09:01:38 +07:00
|
|
|
if (ret) {
|
|
|
|
if (ret == NILFS_SEG_FAIL_IO) {
|
|
|
|
err = -EIO;
|
|
|
|
goto failed;
|
|
|
|
}
|
|
|
|
goto strayed;
|
|
|
|
}
|
2010-05-23 17:21:49 +07:00
|
|
|
|
2010-05-23 17:46:44 +07:00
|
|
|
flags = le16_to_cpu(sum->ss_flags);
|
|
|
|
if (flags & NILFS_SS_SR)
|
2009-04-07 09:01:38 +07:00
|
|
|
goto confused;
|
|
|
|
|
|
|
|
/* Found a valid partial segment; do recovery actions */
|
2010-05-23 17:46:44 +07:00
|
|
|
nextnum = nilfs_get_segnum_of_block(nilfs,
|
|
|
|
le64_to_cpu(sum->ss_next));
|
2009-04-07 09:01:38 +07:00
|
|
|
empty_seg = 0;
|
2010-05-23 17:46:44 +07:00
|
|
|
nilfs->ns_ctime = le64_to_cpu(sum->ss_create);
|
|
|
|
if (!(flags & NILFS_SS_GC))
|
|
|
|
nilfs->ns_nongc_ctime = nilfs->ns_ctime;
|
2009-04-07 09:01:38 +07:00
|
|
|
|
|
|
|
switch (state) {
|
|
|
|
case RF_INIT_ST:
|
2010-05-23 17:46:44 +07:00
|
|
|
if (!(flags & NILFS_SS_LOGBGN) ||
|
|
|
|
!(flags & NILFS_SS_SYNDT))
|
2009-04-07 09:01:38 +07:00
|
|
|
goto try_next_pseg;
|
|
|
|
state = RF_DSYNC_ST;
|
|
|
|
/* Fall through */
|
|
|
|
case RF_DSYNC_ST:
|
2010-05-23 17:46:44 +07:00
|
|
|
if (!(flags & NILFS_SS_SYNDT))
|
2009-04-07 09:01:38 +07:00
|
|
|
goto confused;
|
|
|
|
|
2010-05-23 17:46:44 +07:00
|
|
|
err = nilfs_scan_dsync_log(nilfs, pseg_start, sum,
|
2010-05-22 23:39:02 +07:00
|
|
|
&dsync_blocks);
|
2009-04-07 09:01:38 +07:00
|
|
|
if (unlikely(err))
|
|
|
|
goto failed;
|
2010-05-23 17:46:44 +07:00
|
|
|
if (flags & NILFS_SS_LOGEND) {
|
2010-05-22 23:39:02 +07:00
|
|
|
err = nilfs_recover_dsync_blocks(
|
2011-03-09 09:05:08 +07:00
|
|
|
nilfs, sb, root, &dsync_blocks,
|
2010-05-22 23:39:02 +07:00
|
|
|
&nsalvaged_blocks);
|
2009-04-07 09:01:38 +07:00
|
|
|
if (unlikely(err))
|
|
|
|
goto failed;
|
|
|
|
state = RF_INIT_ST;
|
|
|
|
}
|
|
|
|
break; /* Fall through to try_next_pseg */
|
|
|
|
}
|
|
|
|
|
|
|
|
try_next_pseg:
|
|
|
|
if (pseg_start == ri->ri_lsegs_end)
|
|
|
|
break;
|
2010-05-23 17:46:44 +07:00
|
|
|
pseg_start += le32_to_cpu(sum->ss_nblocks);
|
2009-04-07 09:01:38 +07:00
|
|
|
if (pseg_start < seg_end)
|
|
|
|
continue;
|
|
|
|
goto feed_segment;
|
|
|
|
|
|
|
|
strayed:
|
|
|
|
if (pseg_start == ri->ri_lsegs_end)
|
|
|
|
break;
|
|
|
|
|
|
|
|
feed_segment:
|
|
|
|
/* Looking to the next full segment */
|
|
|
|
if (empty_seg++)
|
|
|
|
break;
|
|
|
|
seg_seq++;
|
|
|
|
segnum = nextnum;
|
|
|
|
nilfs_get_segment_range(nilfs, segnum, &seg_start, &seg_end);
|
|
|
|
pseg_start = seg_start;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nsalvaged_blocks) {
|
2016-08-03 04:05:10 +07:00
|
|
|
nilfs_msg(sb, KERN_INFO, "salvaged %lu blocks",
|
|
|
|
nsalvaged_blocks);
|
2009-04-07 09:01:38 +07:00
|
|
|
ri->ri_need_recovery = NILFS_RECOVERY_ROLLFORWARD_DONE;
|
|
|
|
}
|
|
|
|
out:
|
2010-05-23 17:21:49 +07:00
|
|
|
brelse(bh_sum);
|
2009-04-07 09:01:38 +07:00
|
|
|
dispose_recovery_list(&dsync_blocks);
|
|
|
|
return err;
|
|
|
|
|
|
|
|
confused:
|
|
|
|
err = -EINVAL;
|
|
|
|
failed:
|
2016-08-03 04:05:10 +07:00
|
|
|
nilfs_msg(sb, KERN_ERR,
|
|
|
|
"error %d roll-forwarding partial segment at blocknr = %llu",
|
|
|
|
err, (unsigned long long)pseg_start);
|
2009-04-07 09:01:38 +07:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void nilfs_finish_roll_forward(struct the_nilfs *nilfs,
|
|
|
|
struct nilfs_recovery_info *ri)
|
|
|
|
{
|
|
|
|
struct buffer_head *bh;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
if (nilfs_get_segnum_of_block(nilfs, ri->ri_lsegs_start) !=
|
|
|
|
nilfs_get_segnum_of_block(nilfs, ri->ri_super_root))
|
|
|
|
return;
|
|
|
|
|
2010-05-22 23:39:02 +07:00
|
|
|
bh = __getblk(nilfs->ns_bdev, ri->ri_lsegs_start, nilfs->ns_blocksize);
|
2009-04-07 09:01:38 +07:00
|
|
|
BUG_ON(!bh);
|
|
|
|
memset(bh->b_data, 0, bh->b_size);
|
|
|
|
set_buffer_dirty(bh);
|
|
|
|
err = sync_dirty_buffer(bh);
|
|
|
|
if (unlikely(err))
|
2016-08-03 04:05:10 +07:00
|
|
|
nilfs_msg(nilfs->ns_sb, KERN_WARNING,
|
|
|
|
"buffer sync write failed during post-cleaning of recovery.");
|
2009-04-07 09:01:38 +07:00
|
|
|
brelse(bh);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-05-23 10:21:57 +07:00
|
|
|
* nilfs_salvage_orphan_logs - salvage logs written after the latest checkpoint
|
|
|
|
* @nilfs: nilfs object
|
2011-03-09 09:05:08 +07:00
|
|
|
* @sb: super block instance
|
2009-04-07 09:01:38 +07:00
|
|
|
* @ri: pointer to a nilfs_recovery_info struct to store search results.
|
|
|
|
*
|
|
|
|
* Return Value: On success, 0 is returned. On error, one of the following
|
|
|
|
* negative error code is returned.
|
|
|
|
*
|
|
|
|
* %-EINVAL - Inconsistent filesystem state.
|
|
|
|
*
|
|
|
|
* %-EIO - I/O error
|
|
|
|
*
|
|
|
|
* %-ENOSPC - No space left on device (only in a panic state).
|
|
|
|
*
|
|
|
|
* %-ERESTARTSYS - Interrupted.
|
|
|
|
*
|
|
|
|
* %-ENOMEM - Insufficient memory available.
|
|
|
|
*/
|
2010-05-23 10:21:57 +07:00
|
|
|
int nilfs_salvage_orphan_logs(struct the_nilfs *nilfs,
|
2011-03-09 09:05:08 +07:00
|
|
|
struct super_block *sb,
|
2010-05-23 10:21:57 +07:00
|
|
|
struct nilfs_recovery_info *ri)
|
2009-04-07 09:01:38 +07:00
|
|
|
{
|
2010-08-25 15:45:44 +07:00
|
|
|
struct nilfs_root *root;
|
2009-04-07 09:01:38 +07:00
|
|
|
int err;
|
|
|
|
|
|
|
|
if (ri->ri_lsegs_start == 0 || ri->ri_lsegs_end == 0)
|
|
|
|
return 0;
|
|
|
|
|
2011-03-09 09:05:08 +07:00
|
|
|
err = nilfs_attach_checkpoint(sb, ri->ri_cno, true, &root);
|
2009-04-07 09:01:38 +07:00
|
|
|
if (unlikely(err)) {
|
2016-08-03 04:05:10 +07:00
|
|
|
nilfs_msg(sb, KERN_ERR,
|
|
|
|
"error %d loading the latest checkpoint", err);
|
2009-04-07 09:01:38 +07:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2011-03-09 09:05:08 +07:00
|
|
|
err = nilfs_do_roll_forward(nilfs, sb, root, ri);
|
2009-04-07 09:01:38 +07:00
|
|
|
if (unlikely(err))
|
|
|
|
goto failed;
|
|
|
|
|
|
|
|
if (ri->ri_need_recovery == NILFS_RECOVERY_ROLLFORWARD_DONE) {
|
2011-03-09 09:05:08 +07:00
|
|
|
err = nilfs_prepare_segment_for_recovery(nilfs, sb, ri);
|
2009-04-07 09:01:38 +07:00
|
|
|
if (unlikely(err)) {
|
2016-08-03 04:05:10 +07:00
|
|
|
nilfs_msg(sb, KERN_ERR,
|
|
|
|
"error %d preparing segment for recovery",
|
|
|
|
err);
|
2009-04-07 09:01:38 +07:00
|
|
|
goto failed;
|
|
|
|
}
|
|
|
|
|
2011-03-09 09:05:08 +07:00
|
|
|
err = nilfs_attach_log_writer(sb, root);
|
2009-04-07 09:01:38 +07:00
|
|
|
if (unlikely(err))
|
|
|
|
goto failed;
|
|
|
|
|
|
|
|
set_nilfs_discontinued(nilfs);
|
2011-03-09 09:05:08 +07:00
|
|
|
err = nilfs_construct_segment(sb);
|
|
|
|
nilfs_detach_log_writer(sb);
|
2009-04-07 09:01:38 +07:00
|
|
|
|
|
|
|
if (unlikely(err)) {
|
2016-08-03 04:05:10 +07:00
|
|
|
nilfs_msg(sb, KERN_ERR,
|
|
|
|
"error %d writing segment for recovery",
|
|
|
|
err);
|
2009-04-07 09:01:38 +07:00
|
|
|
goto failed;
|
|
|
|
}
|
|
|
|
|
2010-05-22 23:39:02 +07:00
|
|
|
nilfs_finish_roll_forward(nilfs, ri);
|
2009-04-07 09:01:38 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
failed:
|
2010-08-25 15:45:44 +07:00
|
|
|
nilfs_put_root(root);
|
2009-04-07 09:01:38 +07:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* nilfs_search_super_root - search the latest valid super root
|
|
|
|
* @nilfs: the_nilfs
|
|
|
|
* @ri: pointer to a nilfs_recovery_info struct to store search results.
|
|
|
|
*
|
|
|
|
* nilfs_search_super_root() looks for the latest super-root from a partial
|
|
|
|
* segment pointed by the superblock. It sets up struct the_nilfs through
|
|
|
|
* this search. It fills nilfs_recovery_info (ri) required for recovery.
|
|
|
|
*
|
|
|
|
* Return Value: On success, 0 is returned. On error, one of the following
|
|
|
|
* negative error code is returned.
|
|
|
|
*
|
|
|
|
* %-EINVAL - No valid segment found
|
|
|
|
*
|
|
|
|
* %-EIO - I/O error
|
2010-06-28 17:15:25 +07:00
|
|
|
*
|
|
|
|
* %-ENOMEM - Insufficient memory available.
|
2009-04-07 09:01:38 +07:00
|
|
|
*/
|
2010-05-22 23:39:02 +07:00
|
|
|
int nilfs_search_super_root(struct the_nilfs *nilfs,
|
2009-04-07 09:01:38 +07:00
|
|
|
struct nilfs_recovery_info *ri)
|
|
|
|
{
|
2010-05-23 17:21:49 +07:00
|
|
|
struct buffer_head *bh_sum = NULL;
|
2015-11-07 07:32:16 +07:00
|
|
|
struct nilfs_segment_summary *sum = NULL;
|
2009-04-07 09:01:38 +07:00
|
|
|
sector_t pseg_start, pseg_end, sr_pseg_start = 0;
|
|
|
|
sector_t seg_start, seg_end; /* range of full segment (block number) */
|
2009-11-19 20:24:48 +07:00
|
|
|
sector_t b, end;
|
2010-05-23 17:46:44 +07:00
|
|
|
unsigned long nblocks;
|
|
|
|
unsigned int flags;
|
2009-04-07 09:01:38 +07:00
|
|
|
u64 seg_seq;
|
|
|
|
__u64 segnum, nextnum = 0;
|
|
|
|
__u64 cno;
|
|
|
|
LIST_HEAD(segments);
|
|
|
|
int empty_seg = 0, scan_newer = 0;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
pseg_start = nilfs->ns_last_pseg;
|
|
|
|
seg_seq = nilfs->ns_last_seq;
|
|
|
|
cno = nilfs->ns_last_cno;
|
|
|
|
segnum = nilfs_get_segnum_of_block(nilfs, pseg_start);
|
|
|
|
|
|
|
|
/* Calculate range of segment */
|
|
|
|
nilfs_get_segment_range(nilfs, segnum, &seg_start, &seg_end);
|
|
|
|
|
2009-11-19 20:24:48 +07:00
|
|
|
/* Read ahead segment */
|
|
|
|
b = seg_start;
|
|
|
|
while (b <= seg_end)
|
2010-05-22 23:39:02 +07:00
|
|
|
__breadahead(nilfs->ns_bdev, b++, nilfs->ns_blocksize);
|
2009-11-19 20:24:48 +07:00
|
|
|
|
2009-04-07 09:01:38 +07:00
|
|
|
for (;;) {
|
2010-05-23 17:21:49 +07:00
|
|
|
brelse(bh_sum);
|
|
|
|
ret = NILFS_SEG_FAIL_IO;
|
|
|
|
bh_sum = nilfs_read_log_header(nilfs, pseg_start, &sum);
|
|
|
|
if (!bh_sum)
|
|
|
|
goto failed;
|
|
|
|
|
|
|
|
ret = nilfs_validate_log(nilfs, seg_seq, bh_sum, sum);
|
2009-04-07 09:01:38 +07:00
|
|
|
if (ret) {
|
|
|
|
if (ret == NILFS_SEG_FAIL_IO)
|
|
|
|
goto failed;
|
|
|
|
goto strayed;
|
|
|
|
}
|
2010-05-23 17:21:49 +07:00
|
|
|
|
2010-05-23 17:46:44 +07:00
|
|
|
nblocks = le32_to_cpu(sum->ss_nblocks);
|
|
|
|
pseg_end = pseg_start + nblocks - 1;
|
2009-04-07 09:01:38 +07:00
|
|
|
if (unlikely(pseg_end > seg_end)) {
|
|
|
|
ret = NILFS_SEG_FAIL_CONSISTENCY;
|
|
|
|
goto strayed;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* A valid partial segment */
|
|
|
|
ri->ri_pseg_start = pseg_start;
|
|
|
|
ri->ri_seq = seg_seq;
|
|
|
|
ri->ri_segnum = segnum;
|
2010-05-23 17:46:44 +07:00
|
|
|
nextnum = nilfs_get_segnum_of_block(nilfs,
|
|
|
|
le64_to_cpu(sum->ss_next));
|
2009-04-07 09:01:38 +07:00
|
|
|
ri->ri_nextnum = nextnum;
|
|
|
|
empty_seg = 0;
|
|
|
|
|
2010-05-23 17:46:44 +07:00
|
|
|
flags = le16_to_cpu(sum->ss_flags);
|
|
|
|
if (!(flags & NILFS_SS_SR) && !scan_newer) {
|
2016-05-24 06:23:48 +07:00
|
|
|
/*
|
|
|
|
* This will never happen because a superblock
|
|
|
|
* (last_segment) always points to a pseg with
|
|
|
|
* a super root.
|
|
|
|
*/
|
2009-11-19 20:24:48 +07:00
|
|
|
ret = NILFS_SEG_FAIL_CONSISTENCY;
|
|
|
|
goto failed;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pseg_start == seg_start) {
|
|
|
|
nilfs_get_segment_range(nilfs, nextnum, &b, &end);
|
|
|
|
while (b <= end)
|
2010-05-22 23:39:02 +07:00
|
|
|
__breadahead(nilfs->ns_bdev, b++,
|
|
|
|
nilfs->ns_blocksize);
|
2009-11-19 20:24:48 +07:00
|
|
|
}
|
2010-05-23 17:46:44 +07:00
|
|
|
if (!(flags & NILFS_SS_SR)) {
|
|
|
|
if (!ri->ri_lsegs_start && (flags & NILFS_SS_LOGBGN)) {
|
2009-04-07 09:01:38 +07:00
|
|
|
ri->ri_lsegs_start = pseg_start;
|
|
|
|
ri->ri_lsegs_start_seq = seg_seq;
|
|
|
|
}
|
2010-05-23 17:46:44 +07:00
|
|
|
if (flags & NILFS_SS_LOGEND)
|
2009-04-07 09:01:38 +07:00
|
|
|
ri->ri_lsegs_end = pseg_start;
|
|
|
|
goto try_next_pseg;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* A valid super root was found. */
|
|
|
|
ri->ri_cno = cno++;
|
|
|
|
ri->ri_super_root = pseg_end;
|
|
|
|
ri->ri_lsegs_start = ri->ri_lsegs_end = 0;
|
|
|
|
|
|
|
|
nilfs_dispose_segment_list(&segments);
|
2010-05-23 17:46:44 +07:00
|
|
|
sr_pseg_start = pseg_start;
|
|
|
|
nilfs->ns_pseg_offset = pseg_start + nblocks - seg_start;
|
2009-04-07 09:01:38 +07:00
|
|
|
nilfs->ns_seg_seq = seg_seq;
|
|
|
|
nilfs->ns_segnum = segnum;
|
|
|
|
nilfs->ns_cno = cno; /* nilfs->ns_cno = ri->ri_cno + 1 */
|
2010-05-23 17:46:44 +07:00
|
|
|
nilfs->ns_ctime = le64_to_cpu(sum->ss_create);
|
2009-04-07 09:01:38 +07:00
|
|
|
nilfs->ns_nextnum = nextnum;
|
|
|
|
|
|
|
|
if (scan_newer)
|
|
|
|
ri->ri_need_recovery = NILFS_RECOVERY_SR_UPDATED;
|
2009-04-07 09:01:54 +07:00
|
|
|
else {
|
|
|
|
if (nilfs->ns_mount_state & NILFS_VALID_FS)
|
|
|
|
goto super_root_found;
|
|
|
|
scan_newer = 1;
|
|
|
|
}
|
2009-04-07 09:01:38 +07:00
|
|
|
|
|
|
|
try_next_pseg:
|
|
|
|
/* Standing on a course, or met an inconsistent state */
|
2010-05-23 17:46:44 +07:00
|
|
|
pseg_start += nblocks;
|
2009-04-07 09:01:38 +07:00
|
|
|
if (pseg_start < seg_end)
|
|
|
|
continue;
|
|
|
|
goto feed_segment;
|
|
|
|
|
|
|
|
strayed:
|
|
|
|
/* Off the trail */
|
|
|
|
if (!scan_newer)
|
|
|
|
/*
|
|
|
|
* This can happen if a checkpoint was written without
|
|
|
|
* barriers, or as a result of an I/O failure.
|
|
|
|
*/
|
|
|
|
goto failed;
|
|
|
|
|
|
|
|
feed_segment:
|
|
|
|
/* Looking to the next full segment */
|
|
|
|
if (empty_seg++)
|
|
|
|
goto super_root_found; /* found a valid super root */
|
|
|
|
|
2009-05-17 17:07:21 +07:00
|
|
|
ret = nilfs_segment_list_add(&segments, segnum);
|
|
|
|
if (unlikely(ret))
|
2009-04-07 09:01:38 +07:00
|
|
|
goto failed;
|
|
|
|
|
|
|
|
seg_seq++;
|
|
|
|
segnum = nextnum;
|
|
|
|
nilfs_get_segment_range(nilfs, segnum, &seg_start, &seg_end);
|
|
|
|
pseg_start = seg_start;
|
|
|
|
}
|
|
|
|
|
|
|
|
super_root_found:
|
|
|
|
/* Updating pointers relating to the latest checkpoint */
|
2010-05-23 17:21:49 +07:00
|
|
|
brelse(bh_sum);
|
2009-11-29 00:39:11 +07:00
|
|
|
list_splice_tail(&segments, &ri->ri_used_segments);
|
2009-04-07 09:01:38 +07:00
|
|
|
nilfs->ns_last_pseg = sr_pseg_start;
|
|
|
|
nilfs->ns_last_seq = nilfs->ns_seg_seq;
|
|
|
|
nilfs->ns_last_cno = ri->ri_cno;
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
failed:
|
2010-05-23 17:21:49 +07:00
|
|
|
brelse(bh_sum);
|
2009-04-07 09:01:38 +07:00
|
|
|
nilfs_dispose_segment_list(&segments);
|
2016-08-03 04:05:10 +07:00
|
|
|
return ret < 0 ? ret : nilfs_warn_segment_error(nilfs->ns_sb, ret);
|
2009-04-07 09:01:38 +07:00
|
|
|
}
|