Gitweb: http://git.fedorahosted.org/git/?p=gfs2-utils.git;a=commitdiff;h=98544a4b3a…
Commit: 98544a4b3a1a7251a8230a24e7efdcce306c99bb
Parent: 390b7b663762b32a68fff13c214ec6361f63f3bf
Author: Bob Peterson <rpeterso(a)redhat.com>
AuthorDate: Wed Apr 3 10:50:24 2013 -0700
Committer: Bob Peterson <rpeterso(a)redhat.com>
CommitterDate: Mon May 20 11:12:47 2013 -0500
fsck.gfs2: major duplicate reference reform
This patch is a large set of changes designed to rework how pass1b
resolves duplicate block references. There are basically two major
changes with this patch:
First, the metawalk functions were trying to attribute too much
information to the return codes of its callback functions: (1) Was
there an error? (2) Was the inode valid? (3) Was a duplicate block
reference encountered? (4) Should we keep going and process more of
its metadata? This often led to bad decisions made by metawalk:
For example, it would stop processing metadata when it should have
continued, thereby forgetting to mark blocks free that were no longer
in use. This patch introduces two new variables to the metatree
functions, *is_valid and *was_duplicate. The first one indicates
whether the dinode was valid or whether there is good cause to
delete it. The second indicates whether a duplicate block reference
was encountered. With this patch, the return code indicates simply
whether metadata processing should be skipped or not, and nothing
more. This is especially useful in pass1. For example, if it
encounters major corruption in a dinode, it doesn't do any good to
mark all its blocks as duplicates and have the undo functions try
to reverse all those decisions.
The second major change with this patch has to do with the
philosophy of how duplicate references are resolved. Before, pass1
would flag the duplicates and pass1b would try to resolve them all,
marking dinodes that should be deleted as "bad", and pass2 would
delete the bad dinodes. This becomes very problematic and messy
in pass1b, especially in cases where you have a number of duplicate
references that are common between multiple dinodes. For example,
suppose files A, B and C share some of the same blocks, but not
others:
A - 0x3000 0x3001 0x1233 0x1234 0x3004
B - 0x4000 0x4001 0x4002 0x1234 0x1235
C - 0x1231 0x1232 0x1233 0x1234 0x1235
The old strategy that got us into trouble was to log the three
duplicate blocks, delete invalid dinodes A and B, but leave the
duplicate reference structure around for 0x1233, 0x1234 and 0x1235
so that C would be left intact with the only references to all five
blocks. But in cleaning up the leftover duplicate structure often
led to bad decisions where C wouldn't have all its blocks marked
as referenced. Often, you would end up with blocks that were marked
as free which were still in use, and blocks that were marked as
in use that should have been freed, and it was all due to the
existence of those duplicate structures that were still on the list
until pass2.
The new strategy is to resolve-as-you-go. In other words, pass1b
considers the three duplicate blocks, but when it decides that
file A should be deleted, it removes all its references from the
list, thereby making the decision between B and C easier: it no
longer has to worry about block 1233, and there's only one thing
to consider about block 0x1234 and 0x1235. When B is deleted, it
removes all its duplicate references, so block 0x1235 is no longer
considered to be in conflict. Once a file is deleted, all its
duplicate reference structures are removed so as not to confuse
other duplicates being resolved. The duplicate handler structure,
struct dup_handler, is revised with every reference that's resolved
so it's not working off a long list of possibles, most of
which were already taken care of by previous actions.
---
gfs2/fsck/fsck.h | 2 -
gfs2/fsck/initialize.c | 2 +-
gfs2/fsck/metawalk.c | 217 +++++++++----
gfs2/fsck/metawalk.h | 31 ++-
gfs2/fsck/pass1.c | 101 ++++---
gfs2/fsck/pass1b.c | 810 ++++++++++++++++++++----------------------------
gfs2/fsck/pass2.c | 60 ----
gfs2/fsck/util.c | 37 ++-
gfs2/fsck/util.h | 3 +-
9 files changed, 611 insertions(+), 652 deletions(-)
diff --git a/gfs2/fsck/fsck.h b/gfs2/fsck/fsck.h
index b21a670..6d888af 100644
--- a/gfs2/fsck/fsck.h
+++ b/gfs2/fsck/fsck.h
@@ -112,11 +112,9 @@ extern int pass4(struct gfs2_sbd *sdp);
extern int pass5(struct gfs2_sbd *sdp);
extern int rg_repair(struct gfs2_sbd *sdp, int trust_lvl, int *rg_count,
int *sane);
-extern void gfs2_dup_free(void);
extern int fsck_query(const char *format, ...)
__attribute__((format(printf,1,2)));
extern struct dir_info *dirtree_find(uint64_t block);
-extern void dup_listent_delete(struct inode_with_dups *id);
extern void dup_delete(struct duptree *dt);
extern void dirtree_delete(struct dir_info *b);
diff --git a/gfs2/fsck/initialize.c b/gfs2/fsck/initialize.c
index 7d64b0a..b01b240 100644
--- a/gfs2/fsck/initialize.c
+++ b/gfs2/fsck/initialize.c
@@ -66,7 +66,7 @@ static int block_mounters(struct gfs2_sbd *sdp, int block_em)
return 0;
}
-void gfs2_dup_free(void)
+static void gfs2_dup_free(void)
{
struct osi_node *n;
struct duptree *dt;
diff --git a/gfs2/fsck/metawalk.c b/gfs2/fsck/metawalk.c
index dc585ae..22b16ee 100644
--- a/gfs2/fsck/metawalk.c
+++ b/gfs2/fsck/metawalk.c
@@ -950,7 +950,8 @@ int delete_block(struct gfs2_inode *ip, uint64_t block,
/**
* find_remove_dup - find out if this is a duplicate ref. If so, remove it.
- * Returns: 0 if not a duplicate reference, 1 if it is.
+ *
+ * Returns: 1 if there are any remaining references to this block, else 0.
*/
int find_remove_dup(struct gfs2_inode *ip, uint64_t block, const char *btype)
{
@@ -964,41 +965,18 @@ int find_remove_dup(struct gfs2_inode *ip, uint64_t block, const char *btype)
/* remove the inode reference id structure for this reference. */
id = find_dup_ref_inode(dt, ip);
if (!id)
- return 0;
+ goto more_refs;
- dup_listent_delete(id);
- log_err( _("Removing duplicate status of block %llu (0x%llx) "
- "referenced as %s by dinode %llu (0x%llx)\n"),
- (unsigned long long)block, (unsigned long long)block,
- btype, (unsigned long long)ip->i_di.di_num.no_addr,
- (unsigned long long)ip->i_di.di_num.no_addr);
- dt->refs--; /* one less reference */
- if (dt->refs == 1) {
- log_info( _("This leaves only one reference: it's "
- "no longer a duplicate.\n"));
+ dup_listent_delete(dt, id);
+ if (dt->refs == 0) {
+ log_info( _("This was the last reference: it's no longer a "
+ "duplicate.\n"));
dup_delete(dt); /* not duplicate now */
- } else
- log_info( _("%d block reference(s) remain.\n"),
- dt->refs);
- return 1; /* but the original ref still exists so do not free it. */
-}
-
-/**
- * free_block_if_notdup - free blocks associated with an inode, but if it's a
- * duplicate, just remove that designation instead.
- * Returns: 1 if the block was freed, 0 if a duplicate reference was removed
- * Note: The return code is handled this way because there are places in
- * metawalk.c that assume "1" means "change was made" and "0" means
- * change was not made.
- */
-int free_block_if_notdup(struct gfs2_inode *ip, uint64_t block,
- const char *btype)
-{
- if (!find_remove_dup(ip, block, btype)) { /* not a dup */
- fsck_blockmap_set(ip, block, btype, gfs2_block_free);
- return meta_skip_further;
+ return 0;
}
- return meta_is_good;
+more_refs:
+ log_info( _("%d block reference(s) remain.\n"), dt->refs);
+ return 1; /* references still exist so do not free the block. */
}
/**
@@ -1010,7 +988,8 @@ int free_block_if_notdup(struct gfs2_inode *ip, uint64_t block,
*/
static int delete_block_if_notdup(struct gfs2_inode *ip, uint64_t block,
struct gfs2_buffer_head **bh,
- const char *btype, void *private)
+ const char *btype, int *was_duplicate,
+ void *private)
{
uint8_t q;
@@ -1027,7 +1006,19 @@ static int delete_block_if_notdup(struct gfs2_inode *ip, uint64_t block,
(unsigned long long)ip->i_di.di_num.no_addr);
return meta_is_good;
}
- return free_block_if_notdup(ip, block, btype);
+ if (find_remove_dup(ip, block, btype)) { /* a dup */
+ if (was_duplicate)
+ *was_duplicate = 1;
+ log_err( _("Not clearing duplicate reference in inode "
+ "at block #%llu (0x%llx) to block #%llu (0x%llx) "
+ "because it's referenced by another inode.\n"),
+ (unsigned long long)ip->i_di.di_num.no_addr,
+ (unsigned long long)ip->i_di.di_num.no_addr,
+ (unsigned long long)block, (unsigned long long)block);
+ } else {
+ fsck_blockmap_set(ip, block, btype, gfs2_block_free);
+ }
+ return meta_is_good;
}
/**
@@ -1197,7 +1188,7 @@ static int build_and_check_metalist(struct gfs2_inode *ip, osi_list_t *mlp,
osi_list_t *prev_list, *cur_list, *tmp;
int h, head_size, iblk_type;
uint64_t *ptr, block;
- int error = 0, err;
+ int error, was_duplicate, is_valid;
osi_list_add(&metabh->b_altlist, &mlp[0]);
@@ -1211,7 +1202,7 @@ static int build_and_check_metalist(struct gfs2_inode *ip, osi_list_t *mlp,
/* if (<there are no indirect blocks to check>) */
if (height < 2)
- return 0;
+ return meta_is_good;
for (h = 1; h < height; h++) {
if (h > 1) {
if (is_dir(&ip->i_di, ip->i_sbd->gfs1) &&
@@ -1243,7 +1234,7 @@ static int build_and_check_metalist(struct gfs2_inode *ip, osi_list_t *mlp,
ptr++) {
if (skip_this_pass || fsck_abort) {
free_metalist(ip, mlp);
- return FSCK_OK;
+ return meta_is_good;
}
nbh = NULL;
@@ -1251,19 +1242,41 @@ static int build_and_check_metalist(struct gfs2_inode *ip, osi_list_t *mlp,
continue;
block = be64_to_cpu(*ptr);
- err = pass->check_metalist(ip, block, &nbh, h,
- pass->private);
+ was_duplicate = 0;
+ error = pass->check_metalist(ip, block, &nbh,
+ h, &is_valid,
+ &was_duplicate,
+ pass->private);
/* check_metalist should hold any buffers
it gets with "bread". */
- if (err == meta_error) {
+ if (error == meta_error) {
stack;
- error = err;
+ log_info(_("\nSerious metadata "
+ "error on block %llu "
+ "(0x%llx).\n"),
+ (unsigned long long)block,
+ (unsigned long long)block);
return error;
}
- if (err == meta_skip_further) {
- if (!error)
- error = err;
- log_debug( _("Skipping block %llu (0x%llx)\n"),
+ if (error == meta_skip_further) {
+ log_info(_("\nUnrecoverable metadata "
+ "error on block %llu "
+ "(0x%llx). Further metadata"
+ " will be skipped.\n"),
+ (unsigned long long)block,
+ (unsigned long long)block);
+ return error;
+ }
+ if (!is_valid) {
+ log_debug( _("Skipping rejected block "
+ "%llu (0x%llx)\n"),
+ (unsigned long long)block,
+ (unsigned long long)block);
+ continue;
+ }
+ if (was_duplicate) {
+ log_debug( _("Skipping duplicate %llu "
+ "(0x%llx)\n"),
(unsigned long long)block,
(unsigned long long)block);
continue;
@@ -1590,34 +1603,52 @@ int remove_dentry_from_dir(struct gfs2_sbd *sdp, uint64_t dir,
}
int delete_metadata(struct gfs2_inode *ip, uint64_t block,
- struct gfs2_buffer_head **bh, int h, void *private)
+ struct gfs2_buffer_head **bh, int h, int *is_valid,
+ int *was_duplicate, void *private)
{
- return delete_block_if_notdup(ip, block, bh, _("metadata"), private);
+ *is_valid = 1;
+ *was_duplicate = 0;
+ return delete_block_if_notdup(ip, block, bh, _("metadata"),
+ was_duplicate, private);
}
int delete_leaf(struct gfs2_inode *ip, uint64_t block, void *private)
{
- return delete_block_if_notdup(ip, block, NULL, _("leaf"), private);
+ return delete_block_if_notdup(ip, block, NULL, _("leaf"), NULL,
+ private);
}
int delete_data(struct gfs2_inode *ip, uint64_t metablock,
uint64_t block, void *private)
{
- return delete_block_if_notdup(ip, block, NULL, _("data"), private);
+ return delete_block_if_notdup(ip, block, NULL, _("data"), NULL,
+ private);
}
-int delete_eattr_indir(struct gfs2_inode *ip, uint64_t block, uint64_t parent,
- struct gfs2_buffer_head **bh, void *private)
+static int del_eattr_generic(struct gfs2_inode *ip, uint64_t block,
+ uint64_t parent, struct gfs2_buffer_head **bh,
+ void *private, const char *eatype)
{
- int ret;
+ int ret = 0;
+ int was_free = 0;
+ uint8_t q;
- ret = delete_block_if_notdup(ip, block, NULL,
- _("indirect extended attribute"),
- private);
+ if (valid_block(ip->i_sbd, block)) {
+ q = block_type(block);
+ if (q == gfs2_block_free)
+ was_free = 1;
+ ret = delete_block_if_notdup(ip, block, NULL, eatype,
+ NULL, private);
+ if (!ret) {
+ *bh = bread(ip->i_sbd, block);
+ if (!was_free)
+ ip->i_di.di_blocks--;
+ bmodified(ip->i_bh);
+ }
+ }
/* Even if it's a duplicate reference, we want to eliminate the
reference itself, and adjust di_blocks accordingly. */
if (ip->i_di.di_eattr) {
- ip->i_di.di_blocks--;
if (block == ip->i_di.di_eattr)
ip->i_di.di_eattr = 0;
bmodified(ip->i_bh);
@@ -1625,24 +1656,74 @@ int delete_eattr_indir(struct gfs2_inode *ip, uint64_t block, uint64_t parent,
return ret;
}
+int delete_eattr_indir(struct gfs2_inode *ip, uint64_t block, uint64_t parent,
+ struct gfs2_buffer_head **bh, void *private)
+{
+ return del_eattr_generic(ip, block, parent, bh, private,
+ _("extended attribute"));
+}
+
int delete_eattr_leaf(struct gfs2_inode *ip, uint64_t block, uint64_t parent,
struct gfs2_buffer_head **bh, void *private)
{
- int ret;
+ return del_eattr_generic(ip, block, parent, bh, private,
+ _("indirect extended attribute"));
+}
- ret = delete_block_if_notdup(ip, block, NULL, _("extended attribute"),
- private);
- if (ip->i_di.di_eattr) {
- ip->i_di.di_blocks--;
- if (block == ip->i_di.di_eattr)
- ip->i_di.di_eattr = 0;
- bmodified(ip->i_bh);
+int delete_eattr_entry(struct gfs2_inode *ip, struct gfs2_buffer_head *leaf_bh,
+ struct gfs2_ea_header *ea_hdr,
+ struct gfs2_ea_header *ea_hdr_prev, void *private)
+{
+ struct gfs2_sbd *sdp = ip->i_sbd;
+ char ea_name[256];
+ uint32_t avail_size;
+ int max_ptrs;
+
+ if (!ea_hdr->ea_name_len){
+ /* Skip this entry for now */
+ return 1;
}
- return ret;
+
+ memset(ea_name, 0, sizeof(ea_name));
+ strncpy(ea_name, (char *)ea_hdr + sizeof(struct gfs2_ea_header),
+ ea_hdr->ea_name_len);
+
+ if (!GFS2_EATYPE_VALID(ea_hdr->ea_type) &&
+ ((ea_hdr_prev) || (!ea_hdr_prev && ea_hdr->ea_type))){
+ /* Skip invalid entry */
+ return 1;
+ }
+
+ if (!ea_hdr->ea_num_ptrs)
+ return 0;
+
+ avail_size = sdp->sd_sb.sb_bsize - sizeof(struct gfs2_meta_header);
+ max_ptrs = (be32_to_cpu(ea_hdr->ea_data_len) + avail_size - 1) /
+ avail_size;
+
+ if (max_ptrs > ea_hdr->ea_num_ptrs)
+ return 1;
+
+ log_debug( _(" Pointers Required: %d\n Pointers Reported: %d\n"),
+ max_ptrs, ea_hdr->ea_num_ptrs);
+
+ return 0;
+}
+
+int delete_eattr_extentry(struct gfs2_inode *ip, uint64_t *ea_data_ptr,
+ struct gfs2_buffer_head *leaf_bh,
+ struct gfs2_ea_header *ea_hdr,
+ struct gfs2_ea_header *ea_hdr_prev, void *private)
+{
+ uint64_t block = be64_to_cpu(*ea_data_ptr);
+
+ return delete_block_if_notdup(ip, block, NULL, _("extended attribute"),
+ NULL, private);
}
static int alloc_metalist(struct gfs2_inode *ip, uint64_t block,
- struct gfs2_buffer_head **bh, int h, void *private)
+ struct gfs2_buffer_head **bh, int h, int *is_valid,
+ int *was_duplicate, void *private)
{
uint8_t q;
const char *desc = (const char *)private;
@@ -1650,6 +1731,8 @@ static int alloc_metalist(struct gfs2_inode *ip, uint64_t block,
/* No need to range_check here--if it was added, it's in range. */
/* We can't check the bitmap here because this function is called
after the bitmap has been set but before the blockmap has. */
+ *is_valid = 1;
+ *was_duplicate = 0;
*bh = bread(ip->i_sbd, block);
q = block_type(block);
if (blockmap_to_bitmap(q, ip->i_sbd->gfs1) == GFS2_BLKST_FREE) {
diff --git a/gfs2/fsck/metawalk.h b/gfs2/fsck/metawalk.h
index 49217cc..56f57d9 100644
--- a/gfs2/fsck/metawalk.h
+++ b/gfs2/fsck/metawalk.h
@@ -24,7 +24,8 @@ extern int delete_block(struct gfs2_inode *ip, uint64_t block,
struct gfs2_buffer_head **bh, const char *btype,
void *private);
extern int delete_metadata(struct gfs2_inode *ip, uint64_t block,
- struct gfs2_buffer_head **bh, int h, void *private);
+ struct gfs2_buffer_head **bh, int h, int *is_valid,
+ int *was_duplicate, void *private);
extern int delete_leaf(struct gfs2_inode *ip, uint64_t block, void *private);
extern int delete_data(struct gfs2_inode *ip, uint64_t metablock,
uint64_t block, void *private);
@@ -32,6 +33,17 @@ extern int delete_eattr_indir(struct gfs2_inode *ip, uint64_t block, uint64_t pa
struct gfs2_buffer_head **bh, void *private);
extern int delete_eattr_leaf(struct gfs2_inode *ip, uint64_t block, uint64_t parent,
struct gfs2_buffer_head **bh, void *private);
+extern int delete_eattr_entry(struct gfs2_inode *ip,
+ struct gfs2_buffer_head *leaf_bh,
+ struct gfs2_ea_header *ea_hdr,
+ struct gfs2_ea_header *ea_hdr_prev,
+ void *private);
+extern int delete_eattr_extentry(struct gfs2_inode *ip, uint64_t *ea_data_ptr,
+ struct gfs2_buffer_head *leaf_bh,
+ struct gfs2_ea_header *ea_hdr,
+ struct gfs2_ea_header *ea_hdr_prev,
+ void *private);
+
extern int _fsck_blockmap_set(struct gfs2_inode *ip, uint64_t bblock,
const char *btype, enum gfs2_mark_block mark,
const char *caller, int line);
@@ -48,8 +60,6 @@ extern int write_new_leaf(struct gfs2_inode *dip, int start_lindex,
uint64_t *bn);
extern int repair_leaf(struct gfs2_inode *ip, uint64_t *leaf_no, int lindex,
int ref_count, const char *msg);
-extern int free_block_if_notdup(struct gfs2_inode *ip, uint64_t block,
- const char *btype);
#define is_duplicate(dblock) ((dupfind(dblock)) ? 1 : 0)
@@ -83,8 +93,23 @@ struct metawalk_fxns {
int ref_count, struct gfs2_buffer_head *lbh);
int (*check_leaf) (struct gfs2_inode *ip, uint64_t block,
void *private);
+ /* parameters to the check_metalist sub-functions:
+ ip: incore inode pointer
+ block: block number of the metadata block to be checked
+ bh: buffer_head to be returned
+ h: height
+ is_valid: returned as 1 if the metadata block is valid and should
+ be added to the metadata list for further processing.
+ was_duplicate: returns as 1 if the metadata block was determined
+ to be a duplicate reference, in which case we want to
+ skip adding it to the metadata list.
+ private: Pointer to pass-specific data
+ returns: 0 - everything is good, but there may be duplicates
+ 1 - skip further processing
+ */
int (*check_metalist) (struct gfs2_inode *ip, uint64_t block,
struct gfs2_buffer_head **bh, int h,
+ int *is_valid, int *was_duplicate,
void *private);
int (*check_data) (struct gfs2_inode *ip, uint64_t metablock,
uint64_t block, void *private);
diff --git a/gfs2/fsck/pass1.c b/gfs2/fsck/pass1.c
index df10089..ee7e2c5 100644
--- a/gfs2/fsck/pass1.c
+++ b/gfs2/fsck/pass1.c
@@ -37,7 +37,8 @@ struct block_count {
static int p1check_leaf(struct gfs2_inode *ip, uint64_t block, void *private);
static int check_metalist(struct gfs2_inode *ip, uint64_t block,
- struct gfs2_buffer_head **bh, int h, void *private);
+ struct gfs2_buffer_head **bh, int h, int *is_valid,
+ int *was_duplicate, void *private);
static int undo_check_metalist(struct gfs2_inode *ip, uint64_t block,
int h, void *private);
static int check_data(struct gfs2_inode *ip, uint64_t metablock,
@@ -64,6 +65,7 @@ static int finish_eattr_indir(struct gfs2_inode *ip, int leaf_pointers,
int leaf_pointer_errors, void *private);
static int invalidate_metadata(struct gfs2_inode *ip, uint64_t block,
struct gfs2_buffer_head **bh, int h,
+ int *is_valid, int *was_duplicate,
void *private);
static int invalidate_leaf(struct gfs2_inode *ip, uint64_t block,
void *private);
@@ -127,10 +129,13 @@ struct metawalk_fxns invalidate_fxns = {
*/
static int resuscitate_metalist(struct gfs2_inode *ip, uint64_t block,
struct gfs2_buffer_head **bh, int h,
+ int *is_valid, int *was_duplicate,
void *private)
{
struct block_count *bc = (struct block_count *)private;
+ *is_valid = 1;
+ *was_duplicate = 0;
*bh = NULL;
if (!valid_block(ip->i_sbd, block)){ /* blk outside of FS */
fsck_blockmap_set(ip, ip->i_di.di_num.no_addr,
@@ -139,7 +144,8 @@ static int resuscitate_metalist(struct gfs2_inode *ip, uint64_t block,
"range) found in system inode %lld (0x%llx).\n"),
(unsigned long long)ip->i_di.di_num.no_addr,
(unsigned long long)ip->i_di.di_num.no_addr);
- return meta_skip_further;
+ *is_valid = 0;
+ return meta_is_good;
}
if (fsck_system_inode(ip->i_sbd, block))
fsck_blockmap_set(ip, block, _("system file"), gfs2_indir_blk);
@@ -241,16 +247,19 @@ static int p1check_leaf(struct gfs2_inode *ip, uint64_t block, void *private)
}
static int check_metalist(struct gfs2_inode *ip, uint64_t block,
- struct gfs2_buffer_head **bh, int h, void *private)
+ struct gfs2_buffer_head **bh, int h, int *is_valid,
+ int *was_duplicate, void *private)
{
uint8_t q;
- int found_dup = 0, iblk_type;
+ int iblk_type;
struct gfs2_buffer_head *nbh;
struct block_count *bc = (struct block_count *)private;
const char *blktypedesc;
*bh = NULL;
+ *was_duplicate = 0;
+ *is_valid = 0;
if (!valid_block(ip->i_sbd, block)) { /* blk outside of FS */
/* The bad dinode should be invalidated later due to
"unrecoverable" errors. The inode itself should be
@@ -282,12 +291,13 @@ static int check_metalist(struct gfs2_inode *ip, uint64_t block,
(unsigned long long)ip->i_di.di_num.no_addr,
(unsigned long long)ip->i_di.di_num.no_addr, q,
block_type_string(q));
- add_duplicate_ref(ip, block, ref_as_meta, 0, INODE_VALID);
- found_dup = 1;
+ *was_duplicate = 1;
}
nbh = bread(ip->i_sbd, block);
- if (gfs2_check_meta(nbh, iblk_type)){
+ *is_valid = (gfs2_check_meta(nbh, iblk_type) == 0);
+
+ if (!(*is_valid)) {
log_err( _("Inode %lld (0x%llx) has a bad indirect block "
"pointer %lld (0x%llx) (points to something "
"that is not %s).\n"),
@@ -295,31 +305,23 @@ static int check_metalist(struct gfs2_inode *ip, uint64_t block,
(unsigned long long)ip->i_di.di_num.no_addr,
(unsigned long long)block,
(unsigned long long)block, blktypedesc);
- if (!found_dup) {
- fsck_blockmap_set(ip, block, _("bad indirect"),
- gfs2_meta_inval);
- brelse(nbh);
- nbh = NULL;
- return meta_skip_further;
- }
brelse(nbh);
- nbh = NULL;
- } else /* blk check ok */
- *bh = nbh;
+ return meta_skip_further;
+ }
bc->indir_count++;
- if (found_dup) {
- if (nbh) {
- brelse(nbh);
- nbh = NULL;
- *bh = NULL;
- }
- return meta_skip_further; /* don't process the metadata again */
- } else
- fsck_blockmap_set(ip, block, _("indirect"),
- gfs2_indir_blk);
+ if (*was_duplicate) {
+ add_duplicate_ref(ip, block, ref_as_meta, 0,
+ *is_valid ? INODE_VALID : INODE_INVALID);
+ brelse(nbh);
+ } else {
+ *bh = nbh;
+ fsck_blockmap_set(ip, block, _("indirect"), gfs2_indir_blk);
+ }
- return meta_is_good;
+ if (*is_valid)
+ return meta_is_good;
+ return meta_skip_further;
}
/* undo_reference - undo previously processed data or metadata
@@ -354,7 +356,7 @@ static int undo_reference(struct gfs2_inode *ip, uint64_t block, int meta,
if (!id)
break;
- dup_listent_delete(id);
+ dup_listent_delete(dt, id);
} while (id);
if (dt->refs) {
@@ -827,7 +829,8 @@ static int check_eattr_entries(struct gfs2_inode *ip,
* delete_block_if_notdup.
*/
static int mark_block_invalid(struct gfs2_inode *ip, uint64_t block,
- enum dup_ref_type reftype, const char *btype)
+ enum dup_ref_type reftype, const char *btype,
+ int *is_valid, int *was_duplicate)
{
uint8_t q;
@@ -838,11 +841,20 @@ static int mark_block_invalid(struct gfs2_inode *ip, uint64_t block,
* referenced elsewhere (duplicates) won't be flagged as such,
* and as a result, they'll be freed when this dinode is deleted,
* despite being used by another dinode as a valid block. */
- if (!valid_block(ip->i_sbd, block))
+ if (is_valid)
+ *is_valid = 1;
+ if (was_duplicate)
+ *was_duplicate = 0;
+ if (!valid_block(ip->i_sbd, block)) {
+ if (is_valid)
+ *is_valid = 0;
return meta_is_good;
+ }
q = block_type(block);
if (q != gfs2_block_free) {
+ if (was_duplicate)
+ *was_duplicate = 1;
add_duplicate_ref(ip, block, reftype, 0, INODE_INVALID);
log_info( _("%s block %lld (0x%llx), part of inode "
"%lld (0x%llx), was previously referenced so "
@@ -859,21 +871,27 @@ static int mark_block_invalid(struct gfs2_inode *ip, uint64_t block,
static int invalidate_metadata(struct gfs2_inode *ip, uint64_t block,
struct gfs2_buffer_head **bh, int h,
+ int *is_valid, int *was_duplicate,
void *private)
{
- return mark_block_invalid(ip, block, ref_as_meta, _("metadata"));
+ *is_valid = 1;
+ *was_duplicate = 0;
+ return mark_block_invalid(ip, block, ref_as_meta, _("metadata"),
+ is_valid, was_duplicate);
}
static int invalidate_leaf(struct gfs2_inode *ip, uint64_t block,
void *private)
{
- return mark_block_invalid(ip, block, ref_as_meta, _("leaf"));
+ return mark_block_invalid(ip, block, ref_as_meta, _("leaf"),
+ NULL, NULL);
}
static int invalidate_data(struct gfs2_inode *ip, uint64_t metablock,
uint64_t block, void *private)
{
- return mark_block_invalid(ip, block, ref_as_data, _("data"));
+ return mark_block_invalid(ip, block, ref_as_data, _("data"),
+ NULL, NULL);
}
static int invalidate_eattr_indir(struct gfs2_inode *ip, uint64_t block,
@@ -881,7 +899,8 @@ static int invalidate_eattr_indir(struct gfs2_inode *ip, uint64_t block,
struct gfs2_buffer_head **bh, void *private)
{
return mark_block_invalid(ip, block, ref_as_ea,
- _("indirect extended attribute"));
+ _("indirect extended attribute"),
+ NULL, NULL);
}
static int invalidate_eattr_leaf(struct gfs2_inode *ip, uint64_t block,
@@ -889,7 +908,8 @@ static int invalidate_eattr_leaf(struct gfs2_inode *ip, uint64_t block,
void *private)
{
return mark_block_invalid(ip, block, ref_as_ea,
- _("extended attribute"));
+ _("extended attribute"),
+ NULL, NULL);
}
/**
@@ -924,7 +944,7 @@ static int rangecheck_block(struct gfs2_inode *ip, uint64_t block,
(unsigned long long)ip->i_di.di_num.no_addr,
(unsigned long long)ip->i_di.di_num.no_addr);
if ((*bad_pointers) <= BAD_POINTER_TOLERANCE)
- return meta_skip_further;
+ return meta_is_good;
else
return meta_error; /* Exits check_metatree quicker */
}
@@ -939,7 +959,7 @@ static int rangecheck_block(struct gfs2_inode *ip, uint64_t block,
(unsigned long long)ip->i_di.di_num.no_addr,
(unsigned long long)ip->i_di.di_num.no_addr);
if ((*bad_pointers) <= BAD_POINTER_TOLERANCE)
- return meta_skip_further;
+ return meta_is_good;
else
return meta_error; /* Exits check_metatree quicker */
}
@@ -948,8 +968,11 @@ static int rangecheck_block(struct gfs2_inode *ip, uint64_t block,
static int rangecheck_metadata(struct gfs2_inode *ip, uint64_t block,
struct gfs2_buffer_head **bh, int h,
+ int *is_valid, int *was_duplicate,
void *private)
{
+ *is_valid = 1;
+ *was_duplicate = 0;
return rangecheck_block(ip, block, bh, btype_meta, private);
}
@@ -1048,7 +1071,7 @@ static int handle_ip(struct gfs2_sbd *sdp, struct gfs2_inode *ip)
/* We there was an error, we return 0 because we want fsck to continue
and analyze the other dinodes as well. */
- if (fsck_abort || error != 0)
+ if (fsck_abort)
return 0;
error = check_inode_eattr(ip, &pass1_fxns);
diff --git a/gfs2/fsck/pass1b.c b/gfs2/fsck/pass1b.c
index b5da200..15a3f3a 100644
--- a/gfs2/fsck/pass1b.c
+++ b/gfs2/fsck/pass1b.c
@@ -23,386 +23,10 @@ struct fxn_info {
struct dup_handler {
struct duptree *dt;
- struct inode_with_dups *id;
int ref_inode_count;
int ref_count;
};
-static int check_leaf_refs(struct gfs2_inode *ip, uint64_t block, void *private);
-static int check_metalist(struct gfs2_inode *ip, uint64_t block,
- struct gfs2_buffer_head **bh, int h, void *private);
-static int check_data(struct gfs2_inode *ip, uint64_t metablock,
- uint64_t block, void *private);
-static int check_eattr_indir(struct gfs2_inode *ip, uint64_t block,
- uint64_t parent, struct gfs2_buffer_head **bh,
- void *private);
-static int check_eattr_leaf(struct gfs2_inode *ip, uint64_t block,
- uint64_t parent, struct gfs2_buffer_head **bh,
- void *private);
-static int check_eattr_entry(struct gfs2_inode *ip,
- struct gfs2_buffer_head *leaf_bh,
- struct gfs2_ea_header *ea_hdr,
- struct gfs2_ea_header *ea_hdr_prev,
- void *private);
-static int check_eattr_extentry(struct gfs2_inode *ip, uint64_t *ea_data_ptr,
- struct gfs2_buffer_head *leaf_bh,
- struct gfs2_ea_header *ea_hdr,
- struct gfs2_ea_header *ea_hdr_prev,
- void *private);
-static int find_dentry(struct gfs2_inode *ip, struct gfs2_dirent *de,
- struct gfs2_dirent *prev, struct gfs2_buffer_head *bh,
- char *filename, uint32_t *count, int lindex,
- void *priv);
-
-struct metawalk_fxns find_refs = {
- .private = NULL,
- .check_leaf = check_leaf_refs,
- .check_metalist = check_metalist,
- .check_data = check_data,
- .check_eattr_indir = check_eattr_indir,
- .check_eattr_leaf = check_eattr_leaf,
- .check_dentry = NULL,
- .check_eattr_entry = check_eattr_entry,
- .check_eattr_extentry = check_eattr_extentry,
-};
-
-struct metawalk_fxns find_dirents = {
- .private = NULL,
- .check_leaf = NULL,
- .check_metalist = NULL,
- .check_data = NULL,
- .check_eattr_indir = NULL,
- .check_eattr_leaf = NULL,
- .check_dentry = find_dentry,
- .check_eattr_entry = NULL,
- .check_eattr_extentry = NULL,
-};
-
-static int check_leaf_refs(struct gfs2_inode *ip, uint64_t block, void *private)
-{
- return add_duplicate_ref(ip, block, ref_as_meta, 1, INODE_VALID);
-}
-
-static int check_metalist(struct gfs2_inode *ip, uint64_t block,
- struct gfs2_buffer_head **bh, int h, void *private)
-{
- return add_duplicate_ref(ip, block, ref_as_meta, 1, INODE_VALID);
-}
-
-static int check_data(struct gfs2_inode *ip, uint64_t metablock,
- uint64_t block, void *private)
-{
- return add_duplicate_ref(ip, block, ref_as_data, 1, INODE_VALID);
-}
-
-static int check_eattr_indir(struct gfs2_inode *ip, uint64_t block,
- uint64_t parent, struct gfs2_buffer_head **bh,
- void *private)
-{
- struct gfs2_sbd *sdp = ip->i_sbd;
- int error;
-
- error = add_duplicate_ref(ip, block, ref_as_ea, 1, INODE_VALID);
- if (!error)
- *bh = bread(sdp, block);
-
- return error;
-}
-
-static int check_eattr_leaf(struct gfs2_inode *ip, uint64_t block,
- uint64_t parent, struct gfs2_buffer_head **bh,
- void *private)
-{
- struct gfs2_sbd *sdp = ip->i_sbd;
- int error;
-
- error = add_duplicate_ref(ip, block, ref_as_ea, 1, INODE_VALID);
- if (!error)
- *bh = bread(sdp, block);
- return error;
-}
-
-static int check_eattr_entry(struct gfs2_inode *ip,
- struct gfs2_buffer_head *leaf_bh,
- struct gfs2_ea_header *ea_hdr,
- struct gfs2_ea_header *ea_hdr_prev, void *private)
-{
- return 0;
-}
-
-static int check_eattr_extentry(struct gfs2_inode *ip, uint64_t *ea_data_ptr,
- struct gfs2_buffer_head *leaf_bh,
- struct gfs2_ea_header *ea_hdr,
- struct gfs2_ea_header *ea_hdr_prev,
- void *private)
-{
- uint64_t block = be64_to_cpu(*ea_data_ptr);
-
- return add_duplicate_ref(ip, block, ref_as_ea, 1, INODE_VALID);
-}
-
-/*
- * check_dir_dup_ref - check for a directory entry duplicate reference
- * and if found, set the name into the id.
- * Returns: 1 if filename was found, otherwise 0
- */
-static int check_dir_dup_ref(struct gfs2_inode *ip, struct gfs2_dirent *de,
- osi_list_t *tmp2, char *filename)
-{
- struct inode_with_dups *id;
-
- id = osi_list_entry(tmp2, struct inode_with_dups, list);
- if (id->name)
- /* We can only have one parent of inodes that contain duplicate
- * blocks...no need to keep looking for this one. */
- return 1;
- if (id->block_no == de->de_inum.no_addr) {
- id->name = strdup(filename);
- id->parent = ip->i_di.di_num.no_addr;
- log_debug( _("Duplicate block %llu (0x%llx"
- ") is in file or directory %llu"
- " (0x%llx) named %s\n"),
- (unsigned long long)id->block_no,
- (unsigned long long)id->block_no,
- (unsigned long long)ip->i_di.di_num.no_addr,
- (unsigned long long)ip->i_di.di_num.no_addr,
- filename);
- /* If there are duplicates of duplicates, I guess we'll miss
- them here. */
- return 1;
- }
- return 0;
-}
-
-static int find_dentry(struct gfs2_inode *ip, struct gfs2_dirent *de,
- struct gfs2_dirent *prev,
- struct gfs2_buffer_head *bh, char *filename,
- uint32_t *count, int lindex, void *priv)
-{
- struct osi_node *n, *next = NULL;
- osi_list_t *tmp2;
- struct duptree *dt;
- int found;
-
- for (n = osi_first(&dup_blocks); n; n = next) {
- next = osi_next(n);
- dt = (struct duptree *)n;
- found = 0;
- osi_list_foreach(tmp2, &dt->ref_invinode_list) {
- if (check_dir_dup_ref(ip, de, tmp2, filename)) {
- found = 1;
- break;
- }
- }
- if (!found) {
- osi_list_foreach(tmp2, &dt->ref_inode_list) {
- if (check_dir_dup_ref(ip, de, tmp2, filename))
- break;
- }
- }
- }
- /* Return the number of leaf entries so metawalk doesn't flag this
- leaf as having none. */
- *count = be16_to_cpu(((struct gfs2_leaf *)bh->b_data)->lf_entries);
- return 0;
-}
-
-static int clear_dup_metalist(struct gfs2_inode *ip, uint64_t block,
- struct gfs2_buffer_head **bh, int h,
- void *private)
-{
- struct dup_handler *dh = (struct dup_handler *) private;
- struct duptree *dt;
-
- if (!valid_block(ip->i_sbd, block))
- return meta_is_good;
-
- /* This gets tricky. We're traversing a metadata tree trying to
- delete an inode based on it having a duplicate block reference
- somewhere in its metadata. We know this block is listed as data
- or metadata for this inode, but it may or may not be one of the
- actual duplicate references that caused the problem. If it's not
- a duplicate, it's normal metadata that isn't referenced anywhere
- else, but we're deleting the inode out from under it, so we need
- to delete it altogether. If the block is a duplicate referenced
- block, we need to keep its type intact and let the caller sort
- it out once we're down to a single reference. */
- dt = dupfind(block);
- if (!dt) {
- fsck_blockmap_set(ip, block, _("no longer valid"),
- gfs2_block_free);
- return meta_is_good;
- }
- /* This block, having failed the above test, is duplicated somewhere */
- if (block == dh->dt->block) {
- log_err( _("Not clearing duplicate reference in inode \"%s\" "
- "at block #%llu (0x%llx) to block #%llu (0x%llx) "
- "because it's valid for another inode.\n"),
- dh->id->name ? dh->id->name : _("unknown name"),
- (unsigned long long)ip->i_di.di_num.no_addr,
- (unsigned long long)ip->i_di.di_num.no_addr,
- (unsigned long long)block, (unsigned long long)block);
- log_err( _("Inode %s is in directory %llu (0x%llx)\n"),
- dh->id->name ? dh->id->name : "",
- (unsigned long long)dh->id->parent,
- (unsigned long long)dh->id->parent);
- }
- /* We return 1 not 0 because we need build_and_check_metalist to
- bypass adding the metadata below it to the metalist. If that
- were to happen, all the indirect blocks pointed to by the
- duplicate block would be processed twice, which means it might
- be mistakenly freed as "no longer valid" (in this function above)
- even though it's valid metadata for a different inode. Returning
- 1 ensures that the metadata isn't processed again. */
- return meta_skip_further;
-}
-
-static int clear_dup_data(struct gfs2_inode *ip, uint64_t metablock,
- uint64_t block, void *private)
-{
- return clear_dup_metalist(ip, block, NULL, 0, private);
-}
-
-static int clear_leaf(struct gfs2_inode *ip, uint64_t block, void *private)
-{
- return clear_dup_metalist(ip, block, NULL, 0, private);
-}
-
-static int clear_dup_eattr_indir(struct gfs2_inode *ip, uint64_t block,
- uint64_t parent, struct gfs2_buffer_head **bh,
- void *private)
-{
- return clear_dup_metalist(ip, block, NULL, 0, private);
-}
-
-static int clear_dup_eattr_leaf(struct gfs2_inode *ip, uint64_t block,
- uint64_t parent, struct gfs2_buffer_head **bh,
- void *private)
-{
- return clear_dup_metalist(ip, block, NULL, 0, private);
-}
-
-static int clear_eattr_entry (struct gfs2_inode *ip,
- struct gfs2_buffer_head *leaf_bh,
- struct gfs2_ea_header *ea_hdr,
- struct gfs2_ea_header *ea_hdr_prev,
- void *private)
-{
- struct gfs2_sbd *sdp = ip->i_sbd;
- char ea_name[256];
-
- if (!ea_hdr->ea_name_len){
- /* Skip this entry for now */
- return 1;
- }
-
- memset(ea_name, 0, sizeof(ea_name));
- strncpy(ea_name, (char *)ea_hdr + sizeof(struct gfs2_ea_header),
- ea_hdr->ea_name_len);
-
- if (!GFS2_EATYPE_VALID(ea_hdr->ea_type) &&
- ((ea_hdr_prev) || (!ea_hdr_prev && ea_hdr->ea_type))){
- /* Skip invalid entry */
- return 1;
- }
-
- if (ea_hdr->ea_num_ptrs){
- uint32_t avail_size;
- int max_ptrs;
-
- avail_size = sdp->sd_sb.sb_bsize - sizeof(struct gfs2_meta_header);
- max_ptrs = (be32_to_cpu(ea_hdr->ea_data_len) + avail_size - 1) /
- avail_size;
-
- if (max_ptrs > ea_hdr->ea_num_ptrs)
- return 1;
- else {
- log_debug( _(" Pointers Required: %d\n Pointers Reported: %d\n"),
- max_ptrs, ea_hdr->ea_num_ptrs);
- }
- }
- return 0;
-}
-
-static int clear_eattr_extentry(struct gfs2_inode *ip, uint64_t *ea_data_ptr,
- struct gfs2_buffer_head *leaf_bh,
- struct gfs2_ea_header *ea_hdr,
- struct gfs2_ea_header *ea_hdr_prev,
- void *private)
-{
- uint64_t block = be64_to_cpu(*ea_data_ptr);
-
- return clear_dup_metalist(ip, block, NULL, 0, private);
-}
-
-/* Finds all references to duplicate blocks in the metadata */
-static int find_block_ref(struct gfs2_sbd *sdp, uint64_t inode)
-{
- struct gfs2_inode *ip;
- int error = 0;
-
- ip = fsck_load_inode(sdp, inode); /* bread, inode_get */
- /* double-check the meta header just to be sure it's metadata */
- if (ip->i_di.di_header.mh_magic != GFS2_MAGIC ||
- ip->i_di.di_header.mh_type != GFS2_METATYPE_DI) {
- log_debug( _("Block %lld (0x%llx) is not gfs2 metadata.\n"),
- (unsigned long long)inode,
- (unsigned long long)inode);
- fsck_inode_put(&ip);
- return 1;
- }
- /* Check to see if this inode was referenced by another by mistake */
- add_duplicate_ref(ip, inode, ref_is_inode, 1, INODE_VALID);
-
- /* Check this dinode's metadata for references to known duplicates */
- error = check_metatree(ip, &find_refs);
- if (error < 0) {
- stack;
- fsck_inode_put(&ip); /* out, brelse, free */
- return error;
- }
-
- /* Exhash dir leafs will be checked by check_metatree (right after
- the "end:" label.) But if this is a linear directory we need to
- check the dir with check_linear_dir. */
- if (is_dir(&ip->i_di, sdp->gfs1) &&
- !(ip->i_di.di_flags & GFS2_DIF_EXHASH))
- error = check_linear_dir(ip, ip->i_bh, &find_dirents);
-
- /* Check for ea references in the inode */
- if (!error)
- error = check_inode_eattr(ip, &find_refs);
-
- fsck_inode_put(&ip); /* out, brelse, free */
-
- return error;
-}
-
-/* get_ref_type - figure out if all duplicate references from this inode
- are the same type, and if so, return the type. */
-static enum dup_ref_type get_ref_type(struct inode_with_dups *id)
-{
- enum dup_ref_type t, i;
- int found_type_with_ref;
- int found_other_types;
-
- for (t = ref_as_data; t < ref_types; t++) {
- found_type_with_ref = 0;
- found_other_types = 0;
- for (i = ref_as_data; i < ref_types; i++) {
- if (id->reftypecount[i]) {
- if (t == i)
- found_type_with_ref = 1;
- else
- found_other_types = 1;
- }
- }
- if (found_type_with_ref)
- return found_other_types ? ref_types : t;
- }
- return ref_types;
-}
-
static void log_inode_reference(struct duptree *dt, osi_list_t *tmp, int inval)
{
char reftypestring[32];
@@ -426,12 +50,74 @@ static void log_inode_reference(struct duptree *dt, osi_list_t *tmp, int inval)
(unsigned long long)dt->block,
(unsigned long long)dt->block, reftypestring);
}
+
+/* delete_all_dups - delete all duplicate records for a given inode */
+static void delete_all_dups(struct gfs2_inode *ip)
+{
+ struct osi_node *n, *next;
+ struct duptree *dt;
+ osi_list_t *tmp, *x;
+ struct inode_with_dups *id;
+ int found;
+
+ for (n = osi_first(&dup_blocks); n; n = next) {
+ next = osi_next(n);
+ dt = (struct duptree *)n;
+
+ found = 0;
+ id = NULL;
+
+ osi_list_foreach_safe(tmp, &dt->ref_invinode_list, x) {
+ id = osi_list_entry(tmp, struct inode_with_dups, list);
+ if (id->block_no == ip->i_di.di_num.no_addr) {
+ dup_listent_delete(dt, id);
+ found = 1;
+ }
+ }
+ osi_list_foreach_safe(tmp, &dt->ref_inode_list, x) {
+ id = osi_list_entry(tmp, struct inode_with_dups, list);
+ if (id->block_no == ip->i_di.di_num.no_addr) {
+ dup_listent_delete(dt, id);
+ found = 1;
+ }
+ }
+ if (!found)
+ continue;
+
+ if (dt->refs == 0) {
+ log_debug(_("This was the last reference: 0x%llx is "
+ "no longer a duplicate.\n"),
+ (unsigned long long)dt->block);
+ dup_delete(dt); /* not duplicate now */
+ } else {
+ log_debug(_("%d references remain to 0x%llx\n"),
+ dt->refs, (unsigned long long)dt->block);
+ if (dt->refs > 1)
+ continue;
+
+ id = NULL;
+ osi_list_foreach(tmp, &dt->ref_invinode_list)
+ id = osi_list_entry(tmp,
+ struct inode_with_dups,
+ list);
+ osi_list_foreach(tmp, &dt->ref_inode_list)
+ id = osi_list_entry(tmp,
+ struct inode_with_dups,
+ list);
+ if (id)
+ log_debug("Last reference is from inode "
+ "0x%llx\n",
+ (unsigned long long)id->block_no);
+ }
+ }
+}
+
/*
* resolve_dup_references - resolve all but the last dinode that has a
* duplicate reference to a given block.
*
* @sdp - pointer to the superblock structure
- * @b - pointer to the duplicate reference rbtree to use
+ * @dt - pointer to the duplicate reference rbtree to use
* @ref_list - list of duplicate references to be resolved (invalid or valid)
* @dh - duplicate handler
* inval - The references on this ref_list are invalid. We prefer to delete
@@ -439,40 +125,42 @@ static void log_inode_reference(struct duptree *dt, osi_list_t *tmp, int inval)
* acceptable_ref - Delete dinodes that reference the given block as anything
* _but_ this type. Try to save references as this type.
*/
-static int resolve_dup_references(struct gfs2_sbd *sdp, struct duptree *dt,
- osi_list_t *ref_list, struct dup_handler *dh,
- int inval, int acceptable_ref)
+static void resolve_dup_references(struct gfs2_sbd *sdp, struct duptree *dt,
+ osi_list_t *ref_list,
+ struct dup_handler *dh,
+ int inval, int acceptable_ref)
{
struct gfs2_inode *ip;
struct inode_with_dups *id;
osi_list_t *tmp, *x;
- struct metawalk_fxns clear_dup_fxns = {
+ struct metawalk_fxns pass1b_fxns_delete = {
.private = NULL,
- .check_leaf = clear_leaf,
- .check_metalist = clear_dup_metalist,
- .check_data = clear_dup_data,
- .check_eattr_indir = clear_dup_eattr_indir,
- .check_eattr_leaf = clear_dup_eattr_leaf,
- .check_dentry = NULL,
- .check_eattr_entry = clear_eattr_entry,
- .check_eattr_extentry = clear_eattr_extentry,
+ .check_metalist = delete_metadata,
+ .check_data = delete_data,
+ .check_leaf = delete_leaf,
+ .check_eattr_indir = delete_eattr_indir,
+ .check_eattr_leaf = delete_eattr_leaf,
+ .check_eattr_entry = delete_eattr_entry,
+ .check_eattr_extentry = delete_eattr_extentry,
};
enum dup_ref_type this_ref;
struct inode_info *ii;
int found_good_ref = 0;
+ uint64_t dup_block;
+ uint8_t q;
osi_list_foreach_safe(tmp, ref_list, x) {
if (skip_this_pass || fsck_abort)
- return FSCK_OK;
+ return;
id = osi_list_entry(tmp, struct inode_with_dups, list);
dh->dt = dt;
- dh->id = id;
if (dh->ref_inode_count == 1) /* down to the last reference */
- return 1;
+ return;
this_ref = get_ref_type(id);
+ q = block_type(id->block_no);
if (inval)
log_warn( _("Invalid "));
/* FIXME: If we already found an acceptable reference to this
@@ -484,11 +172,8 @@ static int resolve_dup_references(struct gfs2_sbd *sdp, struct duptree *dt,
type and */
this_ref == acceptable_ref && /* this ref is acceptable */
!found_good_ref) { /* We haven't found a good reference */
- uint8_t q;
-
/* If this is an invalid inode, but not on the invalid
list, it's better to delete it. */
- q = block_type(id->block_no);
if (q != gfs2_inode_invalid) {
found_good_ref = 1;
log_warn( _("Inode %s (%lld/0x%llx)'s "
@@ -526,69 +211,124 @@ static int resolve_dup_references(struct gfs2_sbd *sdp, struct duptree *dt,
(unsigned long long)id->block_no))) {
log_warn( _("The bad inode was not cleared."));
/* delete the list entry so we don't leak memory but
- leave the reference count. If the decrement the
+ leave the reference count. If we decrement the
ref count, we could get down to 1 and the dinode
would be changed without a 'Yes' answer. */
/* (dh->ref_inode_count)--;*/
- dup_listent_delete(id);
+ dup_listent_delete(dt, id);
continue;
}
- log_warn( _("Clearing inode %lld (0x%llx)...\n"),
- (unsigned long long)id->block_no,
- (unsigned long long)id->block_no);
-
+ if (q == gfs2_block_free)
+ log_warn( _("Inode %lld (0x%llx) was previously "
+ "deleted.\n"),
+ (unsigned long long)id->block_no,
+ (unsigned long long)id->block_no);
+ else
+ log_warn(_("Pass1b is deleting inode %lld (0x%llx).\n"),
+ (unsigned long long)id->block_no,
+ (unsigned long long)id->block_no);
+
+ dup_block = id->block_no;
ip = fsck_load_inode(sdp, id->block_no);
- if (id->reftypecount[ref_as_data] ||
- id->reftypecount[ref_as_meta]) {
- ii = inodetree_find(ip->i_di.di_num.no_addr);
- if (ii)
- inodetree_delete(ii);
- }
- clear_dup_fxns.private = (void *) dh;
- /* Clear the EAs for the inode first */
- check_inode_eattr(ip, &clear_dup_fxns);
- /* If the dup was in data or metadata, clear the dinode */
- if (id->reftypecount[ref_as_data] ||
- id->reftypecount[ref_as_meta]) {
- check_metatree(ip, &clear_dup_fxns);
- fsck_blockmap_set(ip, ip->i_di.di_num.no_addr,
- _("duplicate referencing bad"),
- gfs2_inode_invalid);
+ /* If we've already deleted this dinode, don't try to delete
+ it again. That could free blocks that used to be duplicate
+ references that are now resolved (and gone). */
+ if (q != gfs2_block_free) {
+ /* Clear the EAs for the inode first */
+ check_inode_eattr(ip, &pass1b_fxns_delete);
+ /* If the reference was as metadata or data, we've got
+ a corrupt dinode that will be deleted. */
+ if (inval || id->reftypecount[ref_as_data] ||
+ id->reftypecount[ref_as_meta]) {
+ /* Remove the inode from the inode tree */
+ ii = inodetree_find(ip->i_di.di_num.no_addr);
+ if (ii)
+ inodetree_delete(ii);
+ fsck_blockmap_set(ip, ip->i_di.di_num.no_addr,
+ _("duplicate referencing bad"),
+ gfs2_inode_invalid);
+ /* We delete the dup_handler inode count and
+ duplicate id BEFORE clearing the metadata,
+ because if this is the last reference to
+ this metadata block, we need to traverse the
+ tree and free the data blocks it references.
+ However, we don't want to delete other
+ duplicates that may be used by other
+ dinodes. */
+ (dh->ref_inode_count)--;
+ /* FIXME: other option should be to duplicate
+ the block for each duplicate and point the
+ metadata at the cloned blocks */
+ check_metatree(ip, &pass1b_fxns_delete);
+ }
}
+ /* Now we've got to go through an delete any other duplicate
+ references from this dinode we're deleting. If we don't,
+ pass1b will discover the other duplicate record, try to
+ delete this dinode a second time, and this time its earlier
+ duplicate references won't be seen as duplicates anymore
+ (because they were eliminated earlier in pass1b). And so
+ the blocks will be mistakenly freed, when, in fact, they're
+ still being referenced by a valid dinode. */
+ delete_all_dups(ip);
fsck_inode_put(&ip); /* out, brelse, free */
- (dh->ref_inode_count)--;
- /* FIXME: other option should be to duplicate the
- * block for each duplicate and point the metadata at
- * the cloned blocks */
- dup_listent_delete(id);
}
- if (dh->ref_inode_count == 1) /* down to the last reference */
- return 1;
- return 0;
+ return;
}
-static int handle_dup_blk(struct gfs2_sbd *sdp, struct duptree *dt)
+/* revise_dup_handler - get current information about a duplicate reference
+ *
+ * Function resolve_dup_references can delete dinodes that reference blocks
+ * which may have duplicate references. Therefore, the duplicate tree is
+ * constantly being changed. This function revises the duplicate handler so
+ * that it accurately matches what's in the duplicate tree regarding this block
+ */
+static void revise_dup_handler(uint64_t dup_blk, struct dup_handler *dh)
{
- struct gfs2_inode *ip;
osi_list_t *tmp;
+ struct duptree *dt;
struct inode_with_dups *id;
- struct dup_handler dh = {0};
- int last_reference = 0;
- struct gfs2_buffer_head *bh;
- uint32_t cmagic, ctype;
- enum dup_ref_type acceptable_ref;
+ dh->ref_inode_count = 0;
+ dh->ref_count = 0;
+ dh->dt = NULL;
+
+ dt = dupfind(dup_blk);
+ if (!dt)
+ return;
+
+ dh->dt = dt;
/* Count the duplicate references, both valid and invalid */
osi_list_foreach(tmp, &dt->ref_invinode_list) {
id = osi_list_entry(tmp, struct inode_with_dups, list);
- dh.ref_inode_count++;
- dh.ref_count += id->dup_count;
+ dh->ref_inode_count++;
+ dh->ref_count += id->dup_count;
}
osi_list_foreach(tmp, &dt->ref_inode_list) {
id = osi_list_entry(tmp, struct inode_with_dups, list);
- dh.ref_inode_count++;
- dh.ref_count += id->dup_count;
+ dh->ref_inode_count++;
+ dh->ref_count += id->dup_count;
}
+}
+
+/* handle_dup_blk - handle a duplicate block reference.
+ *
+ * This function should resolve and delete the duplicate block reference given,
+ * iow dt.
+ */
+static int handle_dup_blk(struct gfs2_sbd *sdp, struct duptree *dt)
+{
+ osi_list_t *tmp;
+ struct gfs2_inode *ip;
+ struct inode_with_dups *id;
+ struct dup_handler dh = {0};
+ struct gfs2_buffer_head *bh;
+ uint32_t cmagic, ctype;
+ enum dup_ref_type acceptable_ref;
+ uint64_t dup_blk;
+
+ dup_blk = dt->block;
+ revise_dup_handler(dup_blk, &dh);
/* Log the duplicate references */
log_notice( _("Block %llu (0x%llx) has %d inodes referencing it"
@@ -642,77 +382,67 @@ static int handle_dup_blk(struct gfs2_sbd *sdp, struct duptree *dt)
invalidated for other reasons, such as bad pointers. So we need to
make sure at this point that any inode deletes reverse out any
duplicate reference before we get to this point. */
- if (dh.ref_count == 1)
- last_reference = 1;
/* Step 1 - eliminate references from inodes that are not valid.
* This may be because they were deleted due to corruption.
* All block types are unacceptable, so we use ref_types.
*/
- if (!last_reference) {
+ if (dh.ref_count > 1) {
log_debug( _("----------------------------------------------\n"
"Step 1: Eliminate references to block %llu "
"(0x%llx) that were previously marked "
"invalid.\n"),
(unsigned long long)dt->block,
(unsigned long long)dt->block);
- last_reference = resolve_dup_references(sdp, dt,
- &dt->ref_invinode_list,
- &dh, 1, ref_types);
+ resolve_dup_references(sdp, dt, &dt->ref_invinode_list,
+ &dh, 1, ref_types);
+ revise_dup_handler(dup_blk, &dh);
}
/* Step 2 - eliminate reference from inodes that reference it as the
* wrong type. For example, a data file referencing it as
* a data block, but it's really a metadata block. Or a
* directory inode referencing a data block as a leaf block.
*/
- if (!last_reference) {
+ if (dh.ref_count > 1) {
log_debug( _("----------------------------------------------\n"
"Step 2: Eliminate references to block %llu "
"(0x%llx) that need the wrong block type.\n"),
(unsigned long long)dt->block,
(unsigned long long)dt->block);
- last_reference = resolve_dup_references(sdp, dt,
- &dt->ref_inode_list,
- &dh, 0,
- acceptable_ref);
+ resolve_dup_references(sdp, dt, &dt->ref_inode_list, &dh, 0,
+ acceptable_ref);
+ revise_dup_handler(dup_blk, &dh);
}
/* Step 3 - We have multiple dinodes referencing it as the correct
* type. Just blast one of them.
* All block types are fair game, so we use ref_types.
*/
- if (!last_reference) {
+ if (dh.ref_count > 1) {
log_debug( _("----------------------------------------------\n"
"Step 3: Choose one reference to block %llu "
"(0x%llx) to keep.\n"),
(unsigned long long)dt->block,
(unsigned long long)dt->block);
- last_reference = resolve_dup_references(sdp, dt,
- &dt->ref_inode_list,
- &dh, 0, ref_types);
- }
- /* Now fix the block type of the block in question. */
- if (osi_list_empty(&dt->ref_inode_list)) {
- log_notice( _("Block %llu (0x%llx) has no more references; "
- "Marking as 'free'.\n"),
- (unsigned long long)dt->block,
- (unsigned long long)dt->block);
- gfs2_blockmap_set(bl, dt->block, gfs2_block_free);
- check_n_fix_bitmap(sdp, dt->block, gfs2_block_free);
- return 0;
+ resolve_dup_references(sdp, dt, &dt->ref_inode_list, &dh, 0,
+ ref_types);
+ revise_dup_handler(dup_blk, &dh);
}
- if (last_reference) {
+ /* If there's still a last remaining reference, and it's a valid
+ reference, use it to determine the correct block type for our
+ blockmap and bitmap. */
+ if (dh.ref_count == 1 && !osi_list_empty(&dt->ref_inode_list)) {
uint8_t q;
log_notice( _("Block %llu (0x%llx) has only one remaining "
- "reference.\n"),
- (unsigned long long)dt->block,
- (unsigned long long)dt->block);
+ "valid reference.\n"),
+ (unsigned long long)dup_blk,
+ (unsigned long long)dup_blk);
/* If we're down to a single reference (and not all references
deleted, which may be the case of an inode that has only
itself and a reference), we need to reset the block type
from invalid to data or metadata. Start at the first one
in the list, not the structure's place holder. */
- tmp = (&dt->ref_inode_list)->next;
+ tmp = dt->ref_inode_list.next;
id = osi_list_entry(tmp, struct inode_with_dups, list);
log_debug( _("----------------------------------------------\n"
"Step 4. Set block type based on the remaining "
@@ -753,13 +483,147 @@ static int handle_dup_blk(struct gfs2_sbd *sdp, struct duptree *dt)
"attribute"),
gfs2_meta_eattr);
fsck_inode_put(&ip); /* out, brelse, free */
+ log_debug(_("Done with duplicate reference to block 0x%llx\n"),
+ (unsigned long long)dt->block);
+ dup_delete(dt);
} else {
/* They may have answered no and not fixed all references. */
- log_debug( _("All duplicate references were processed.\n"));
+ log_debug( _("All duplicate references to block 0x%llx were "
+ "processed.\n"), (unsigned long long)dup_blk);
+ if (dh.ref_count) {
+ log_debug(_("Done with duplicate reference to block "
+ "0x%llx, but %d references remain.\n"),
+ (unsigned long long)dup_blk, dh.ref_count);
+ } else {
+ log_notice( _("Block %llu (0x%llx) has no more "
+ "references; Marking as 'free'.\n"),
+ (unsigned long long)dup_blk,
+ (unsigned long long)dup_blk);
+ if (dh.dt)
+ dup_delete(dh.dt);
+ /* Now fix the block type of the block in question. */
+ gfs2_blockmap_set(bl, dup_blk, gfs2_block_free);
+ check_n_fix_bitmap(sdp, dup_blk, gfs2_block_free);
+ }
}
return 0;
}
+static int check_leaf_refs(struct gfs2_inode *ip, uint64_t block,
+ void *private)
+{
+ return add_duplicate_ref(ip, block, ref_as_meta, 1, INODE_VALID);
+}
+
+static int check_metalist_refs(struct gfs2_inode *ip, uint64_t block,
+ struct gfs2_buffer_head **bh, int h,
+ int *is_valid, int *was_duplicate,
+ void *private)
+{
+ *was_duplicate = 0;
+ *is_valid = 1;
+ return add_duplicate_ref(ip, block, ref_as_meta, 1, INODE_VALID);
+}
+
+static int check_data_refs(struct gfs2_inode *ip, uint64_t metablock,
+ uint64_t block, void *private)
+{
+ return add_duplicate_ref(ip, block, ref_as_data, 1, INODE_VALID);
+}
+
+static int check_eattr_indir_refs(struct gfs2_inode *ip, uint64_t block,
+ uint64_t parent,
+ struct gfs2_buffer_head **bh, void *private)
+{
+ struct gfs2_sbd *sdp = ip->i_sbd;
+ int error;
+
+ error = add_duplicate_ref(ip, block, ref_as_ea, 1, INODE_VALID);
+ if (!error)
+ *bh = bread(sdp, block);
+
+ return error;
+}
+
+static int check_eattr_leaf_refs(struct gfs2_inode *ip, uint64_t block,
+ uint64_t parent, struct gfs2_buffer_head **bh,
+ void *private)
+{
+ struct gfs2_sbd *sdp = ip->i_sbd;
+ int error;
+
+ error = add_duplicate_ref(ip, block, ref_as_ea, 1, INODE_VALID);
+ if (!error)
+ *bh = bread(sdp, block);
+ return error;
+}
+
+static int check_eattr_entry_refs(struct gfs2_inode *ip,
+ struct gfs2_buffer_head *leaf_bh,
+ struct gfs2_ea_header *ea_hdr,
+ struct gfs2_ea_header *ea_hdr_prev,
+ void *private)
+{
+ return 0;
+}
+
+static int check_eattr_extentry_refs(struct gfs2_inode *ip,
+ uint64_t *ea_data_ptr,
+ struct gfs2_buffer_head *leaf_bh,
+ struct gfs2_ea_header *ea_hdr,
+ struct gfs2_ea_header *ea_hdr_prev,
+ void *private)
+{
+ uint64_t block = be64_to_cpu(*ea_data_ptr);
+
+ return add_duplicate_ref(ip, block, ref_as_ea, 1, INODE_VALID);
+}
+
+/* Finds all references to duplicate blocks in the metadata */
+/* Finds all references to duplicate blocks in the metadata */
+static int find_block_ref(struct gfs2_sbd *sdp, uint64_t inode)
+{
+ struct gfs2_inode *ip;
+ int error = 0;
+ struct metawalk_fxns find_refs = {
+ .private = NULL,
+ .check_leaf = check_leaf_refs,
+ .check_metalist = check_metalist_refs,
+ .check_data = check_data_refs,
+ .check_eattr_indir = check_eattr_indir_refs,
+ .check_eattr_leaf = check_eattr_leaf_refs,
+ .check_eattr_entry = check_eattr_entry_refs,
+ .check_eattr_extentry = check_eattr_extentry_refs,
+ };
+
+ ip = fsck_load_inode(sdp, inode); /* bread, inode_get */
+
+ /* double-check the meta header just to be sure it's metadata */
+ if (ip->i_di.di_header.mh_magic != GFS2_MAGIC ||
+ ip->i_di.di_header.mh_type != GFS2_METATYPE_DI) {
+ log_debug( _("Block %lld (0x%llx) is not gfs2 metadata.\n"),
+ (unsigned long long)inode,
+ (unsigned long long)inode);
+ error = 1;
+ goto out;
+ }
+ /* Check to see if this inode was referenced by another by mistake */
+ add_duplicate_ref(ip, inode, ref_is_inode, 1, INODE_VALID);
+
+ /* Check this dinode's metadata for references to known duplicates */
+ error = check_metatree(ip, &find_refs);
+ if (error < 0)
+ stack;
+
+ /* Check for ea references in the inode */
+ if (!error)
+ error = check_inode_eattr(ip, &find_refs);
+
+out:
+ fsck_inode_put(&ip); /* out, brelse, free */
+ return error;
+}
+
/* Pass 1b handles finding the previous inode for a duplicate block
* When found, store the inodes pointing to the duplicate block for
* use in pass2 */
@@ -768,7 +632,7 @@ int pass1b(struct gfs2_sbd *sdp)
struct duptree *dt;
uint64_t i;
uint8_t q;
- struct osi_node *n, *next = NULL;
+ struct osi_node *n;
int rc = FSCK_OK;
log_info( _("Looking for duplicate blocks...\n"));
@@ -819,17 +683,11 @@ int pass1b(struct gfs2_sbd *sdp)
* it later */
log_info( _("Handling duplicate blocks\n"));
out:
- for (n = osi_first(&dup_blocks); n; n = next) {
- next = osi_next(n);
+ /* Resolve all duplicates by clearing out the dup tree */
+ while ((n = osi_first(&dup_blocks))) {
dt = (struct duptree *)n;
if (!skip_this_pass && !rc) /* no error & not asked to skip the rest */
handle_dup_blk(sdp, dt);
- /* Do not attempt to free the dup_blocks list or its parts
- here because any func that calls check_metatree needs
- to check duplicate status based on this linked list.
- This is especially true for pass2 where it may delete "bad"
- inodes, and we can't delete an inode's indirect block if
- it was a duplicate (therefore in use by another dinode). */
}
return rc;
}
diff --git a/gfs2/fsck/pass2.c b/gfs2/fsck/pass2.c
index 77718be..b79e999 100644
--- a/gfs2/fsck/pass2.c
+++ b/gfs2/fsck/pass2.c
@@ -169,59 +169,6 @@ static int check_file_type(uint8_t de_type, uint8_t blk_type, int gfs1)
return 0;
}
-static int delete_eattr_entry (struct gfs2_inode *ip,
- struct gfs2_buffer_head *leaf_bh,
- struct gfs2_ea_header *ea_hdr,
- struct gfs2_ea_header *ea_hdr_prev,
- void *private)
-{
- struct gfs2_sbd *sdp = ip->i_sbd;
- char ea_name[256];
-
- if (!ea_hdr->ea_name_len){
- /* Skip this entry for now */
- return 1;
- }
-
- memset(ea_name, 0, sizeof(ea_name));
- strncpy(ea_name, (char *)ea_hdr + sizeof(struct gfs2_ea_header),
- ea_hdr->ea_name_len);
-
- if (!GFS2_EATYPE_VALID(ea_hdr->ea_type) &&
- ((ea_hdr_prev) || (!ea_hdr_prev && ea_hdr->ea_type))){
- /* Skip invalid entry */
- return 1;
- }
-
- if (ea_hdr->ea_num_ptrs){
- uint32_t avail_size;
- int max_ptrs;
-
- avail_size = sdp->sd_sb.sb_bsize - sizeof(struct gfs2_meta_header);
- max_ptrs = (be32_to_cpu(ea_hdr->ea_data_len) + avail_size - 1) /
- avail_size;
-
- if (max_ptrs > ea_hdr->ea_num_ptrs)
- return 1;
- else {
- log_debug( _(" Pointers Required: %d\n Pointers Reported: %d\n"),
- max_ptrs, ea_hdr->ea_num_ptrs);
- }
- }
- return 0;
-}
-
-static int delete_eattr_extentry(struct gfs2_inode *ip, uint64_t *ea_data_ptr,
- struct gfs2_buffer_head *leaf_bh,
- struct gfs2_ea_header *ea_hdr,
- struct gfs2_ea_header *ea_hdr_prev,
- void *private)
-{
- uint64_t block = be64_to_cpu(*ea_data_ptr);
-
- return delete_metadata(ip, block, NULL, 0, private);
-}
-
struct metawalk_fxns pass2_fxns_delete = {
.private = NULL,
.check_metalist = delete_metadata,
@@ -1836,12 +1783,5 @@ int pass2(struct gfs2_sbd *sdp)
}
fsck_inode_put(&ip); /* does a gfs2_dinode_out, brelse */
}
- /* Now that we've deleted the inodes marked "bad" we can safely
- get rid of the duplicate block list. If we do it any sooner,
- we won't discover that a given block is a duplicate and avoid
- deleting it from both inodes referencing it. Note: The other
- returns from this function are premature exits of the program
- and gfs2_block_list_destroy should get rid of the list for us. */
- gfs2_dup_free();
return FSCK_OK;
}
diff --git a/gfs2/fsck/util.c b/gfs2/fsck/util.c
index ef59e6e..9d6f163 100644
--- a/gfs2/fsck/util.c
+++ b/gfs2/fsck/util.c
@@ -466,8 +466,39 @@ struct dir_info *dirtree_find(uint64_t block)
return NULL;
}
-void dup_listent_delete(struct inode_with_dups *id)
+/* get_ref_type - figure out if all duplicate references from this inode
+ are the same type, and if so, return the type. */
+enum dup_ref_type get_ref_type(struct inode_with_dups *id)
{
+ enum dup_ref_type t, i;
+ int found_type_with_ref;
+ int found_other_types;
+
+ for (t = ref_as_data; t < ref_types; t++) {
+ found_type_with_ref = 0;
+ found_other_types = 0;
+ for (i = ref_as_data; i < ref_types; i++) {
+ if (id->reftypecount[i]) {
+ if (t == i)
+ found_type_with_ref = 1;
+ else
+ found_other_types = 1;
+ }
+ }
+ if (found_type_with_ref)
+ return found_other_types ? ref_types : t;
+ }
+ return ref_types;
+}
+
+void dup_listent_delete(struct duptree *dt, struct inode_with_dups *id)
+{
+ log_err( _("Removing duplicate reference to block %llu (0x%llx) "
+ "referenced as %s by dinode %llu (0x%llx)\n"),
+ (unsigned long long)dt->block, (unsigned long long)dt->block,
+ reftypes[get_ref_type(id)], (unsigned long long)id->block_no,
+ (unsigned long long)id->block_no);
+ dt->refs--; /* one less reference */
if (id->name)
free(id->name);
osi_list_del(&id->list);
@@ -482,12 +513,12 @@ void dup_delete(struct duptree *dt)
while (!osi_list_empty(&dt->ref_invinode_list)) {
tmp = (&dt->ref_invinode_list)->next;
id = osi_list_entry(tmp, struct inode_with_dups, list);
- dup_listent_delete(id);
+ dup_listent_delete(dt, id);
}
while (!osi_list_empty(&dt->ref_inode_list)) {
tmp = (&dt->ref_inode_list)->next;
id = osi_list_entry(tmp, struct inode_with_dups, list);
- dup_listent_delete(id);
+ dup_listent_delete(dt, id);
}
osi_erase(&dt->node, &dup_blocks);
free(dt);
diff --git a/gfs2/fsck/util.h b/gfs2/fsck/util.h
index 00c2239..361b1a2 100644
--- a/gfs2/fsck/util.h
+++ b/gfs2/fsck/util.h
@@ -19,7 +19,7 @@ int add_duplicate_ref(struct gfs2_inode *ip, uint64_t block,
enum dup_ref_type reftype, int first, int inode_valid);
extern struct inode_with_dups *find_dup_ref_inode(struct duptree *dt,
struct gfs2_inode *ip);
-extern void dup_listent_delete(struct inode_with_dups *id);
+extern void dup_listent_delete(struct duptree *dt, struct inode_with_dups *id);
extern const char *reftypes[ref_types + 1];
@@ -174,6 +174,7 @@ static inline uint32_t gfs_to_gfs2_mode(struct gfs2_inode *ip)
}
}
+extern enum dup_ref_type get_ref_type(struct inode_with_dups *id);
extern struct gfs2_bmap *gfs2_bmap_create(struct gfs2_sbd *sdp, uint64_t size,
uint64_t *addl_mem_needed);
extern void *gfs2_bmap_destroy(struct gfs2_sbd *sdp, struct gfs2_bmap *il);
Gitweb: http://git.fedorahosted.org/git/?p=gfs2-utils.git;a=commitdiff;h=390b7b6637…
Commit: 390b7b663762b32a68fff13c214ec6361f63f3bf
Parent: 37480679e413e503de72d873021ce2c808f0d8cc
Author: Bob Peterson <rpeterso(a)redhat.com>
AuthorDate: Wed Apr 3 10:03:49 2013 -0700
Committer: Bob Peterson <rpeterso(a)redhat.com>
CommitterDate: Mon May 20 11:12:47 2013 -0500
fsck.gfs2: When flagging a duplicate reference, show valid or invalid
This patch changes the logging when duplicate block references are
flagged. The idea is to print whether or not the inode with the reference
is valid or invalid, which helps in diagnosing problems when duplicate
block references are resolved.
---
gfs2/fsck/util.c | 3 ++-
1 files changed, 2 insertions(+), 1 deletions(-)
diff --git a/gfs2/fsck/util.c b/gfs2/fsck/util.c
index fc3a0ec..ef59e6e 100644
--- a/gfs2/fsck/util.c
+++ b/gfs2/fsck/util.c
@@ -399,9 +399,10 @@ int add_duplicate_ref(struct gfs2_inode *ip, uint64_t block,
id->reftypecount[reftype]++;
id->dup_count++;
log_info( _("Found %d reference(s) to block %llu"
- " (0x%llx) as %s in inode #%llu (0x%llx)\n"),
+ " (0x%llx) as %s in %s inode #%llu (0x%llx)\n"),
id->dup_count, (unsigned long long)block,
(unsigned long long)block, reftypes[reftype],
+ inode_valid ? _("valid") : _("invalid"),
(unsigned long long)ip->i_di.di_num.no_addr,
(unsigned long long)ip->i_di.di_num.no_addr);
if (first)
Gitweb: http://git.fedorahosted.org/git/?p=gfs2-utils.git;a=commitdiff;h=37480679e4…
Commit: 37480679e413e503de72d873021ce2c808f0d8cc
Parent: 5c93311761c14819ed20087d23fe23f9a9ab2c21
Author: Bob Peterson <rpeterso(a)redhat.com>
AuthorDate: Wed Apr 3 09:47:31 2013 -0700
Committer: Bob Peterson <rpeterso(a)redhat.com>
CommitterDate: Mon May 20 11:12:47 2013 -0500
fsck.gfs2: check for duplicate first references
Before this patch, fsck.gfs2 could get into situations where it's
in pass1b searching for the first reference to a block that it knows
has been referenced twice. However, for one reason or another, the
first reference has been deleted. It may seem unlikely because pass1
tries to "undo" its references when it deletes a bad dinode. But
it can still happen, for example, when pass1b decides to delete a
dinode because of a _different_ duplicate reference within the same
dinode. If the first reference was deleted prior to searching for the
original reference, pass1b won't find the original reference. So
prior to this patch, it would just keep on looking, until it found
the second reference. In other words, it would mistake the second
reference for the first reference. Then it would get confused and
treat the reference as a duplicate of itself. Later, it would choose
which reference to delete, and delete its dinode. But since they're
the same reference, it could delete a dinode with a perfectly good
reference (the first invalid reference having already been deleted).
The solution that this patch implements is to check if the first
reference we found is actually the second reference, and if so,
treat it as a first reference. That way, it avoids creating a
second duplicate reference structure, and later when it resolves
the references, it finds there's only one, and it doesn't need to
delete the valid dinode.
---
gfs2/fsck/util.c | 24 ++++++++++++++++++++++--
1 files changed, 22 insertions(+), 2 deletions(-)
diff --git a/gfs2/fsck/util.c b/gfs2/fsck/util.c
index 078d5f6..fc3a0ec 100644
--- a/gfs2/fsck/util.c
+++ b/gfs2/fsck/util.c
@@ -330,6 +330,28 @@ int add_duplicate_ref(struct gfs2_inode *ip, uint64_t block,
if (dt->first_ref_found)
return meta_is_good;
+ /* Check for a previous reference to this duplicate */
+ id = find_dup_ref_inode(dt, ip);
+
+ /* We have to be careful here. The original referencing dinode may have
+ deemed to be bad and deleted/freed in pass1. In that case, pass1b
+ wouldn't discover the correct [deleted] original reference. In
+ that case, we don't want to be confused and consider this second
+ reference the same as the first. If we do, we'll never be able to
+ resolve it. The first reference can't be the second reference. */
+ if (id && first && !dt->first_ref_found) {
+ log_info(_("Original reference to block %llu (0x%llx) was "
+ "previously found to be bad and deleted.\n"),
+ (unsigned long long)block,
+ (unsigned long long)block);
+ log_info(_("I'll consider the reference from inode %llu "
+ "(0x%llx) the first reference.\n"),
+ (unsigned long long)ip->i_di.di_num.no_addr,
+ (unsigned long long)ip->i_di.di_num.no_addr);
+ dt->first_ref_found = 1;
+ return meta_is_good;
+ }
+
/* The first time this is called from pass1 is actually the second
reference. When we go back in pass1b looking for the original
reference, we don't want to increment the reference count because
@@ -341,8 +363,6 @@ int add_duplicate_ref(struct gfs2_inode *ip, uint64_t block,
dt->refs++;
}
- /* Check for a previous reference to this duplicate */
- id = find_dup_ref_inode(dt, ip);
if (id == NULL) {
/* Check for the inode on the invalid inode reference list. */
uint8_t q;
Gitweb: http://git.fedorahosted.org/git/?p=gfs2-utils.git;a=commitdiff;h=5c93311761…
Commit: 5c93311761c14819ed20087d23fe23f9a9ab2c21
Parent: df909ed72b1c31663c75a72fd1080b2f10e98a13
Author: Bob Peterson <rpeterso(a)redhat.com>
AuthorDate: Wed Apr 3 09:28:09 2013 -0700
Committer: Bob Peterson <rpeterso(a)redhat.com>
CommitterDate: Mon May 20 11:12:47 2013 -0500
fsck.gfs2: don't invalidate files with duplicate data block refs
Before this patch, whenever pass1 encountered a duplicated data block
pointer, it would mark the file as invalid. But if reason the block
was duplicated was due to a different bad inode, the inode with the
valid data block reference was still punished and deleted.
This patch adds an additional check to see if the previous reference
to the data block was as a _valid_ metadata block. If the previous
reference was as metadata, and the metadata checked out okay, then
it can't possibly be a data block for the second reference. In that
case, we know for a fact that the second reference is invalid. But
if the previous reference was also as data, the inode might be okay
and duplicate resolving in pass1b might sort it out and leave this
inode as the only valid reference. In that case, we should treat the
inode as valid, not invalid. So this patch basically treats duplicate
data block references as "innocent until proven guilty" rather than
just the opposite.
---
gfs2/fsck/pass1.c | 20 +++++++++++++++++---
1 files changed, 17 insertions(+), 3 deletions(-)
diff --git a/gfs2/fsck/pass1.c b/gfs2/fsck/pass1.c
index 3c4dc89..df10089 100644
--- a/gfs2/fsck/pass1.c
+++ b/gfs2/fsck/pass1.c
@@ -425,18 +425,32 @@ static int check_data(struct gfs2_inode *ip, uint64_t metablock,
log_err(_("from metadata block %llu (0x%llx)\n"),
(unsigned long long)metablock,
(unsigned long long)metablock);
-
+
+ if (q >= gfs2_indir_blk && q <= gfs2_jdata) {
+ log_info(_("The block was processed earlier as valid "
+ "metadata, so it can't possibly be "
+ "data.\n"));
+ /* We still need to add a duplicate record here because
+ when check_metatree tries to delete the inode, we
+ can't have the "undo" functions freeing the block
+ out from other the original referencing inode. */
+ add_duplicate_ref(ip, block, ref_as_data, 0,
+ INODE_VALID);
+ return 1;
+ }
if (q != gfs2_meta_inval) {
log_info( _("Seems to be a normal duplicate; I'll "
"sort it out in pass1b.\n"));
add_duplicate_ref(ip, block, ref_as_data, 0,
INODE_VALID);
- return 1;
+ /* This inode references the block as data. So if this
+ all is validated, we want to keep this count. */
+ return 0;
}
log_info( _("The block was invalid as metadata but might be "
"okay as data. I'll sort it out in pass1b.\n"));
add_duplicate_ref(ip, block, ref_as_data, 0, INODE_VALID);
- return 1;
+ return 0;
}
/* In gfs1, rgrp indirect blocks are marked in the bitmap as "meta".
In gfs2, "meta" is only for dinodes. So here we dummy up the
Gitweb: http://git.fedorahosted.org/git/?p=gfs2-utils.git;a=commitdiff;h=df909ed72b…
Commit: df909ed72b1c31663c75a72fd1080b2f10e98a13
Parent: 88a7654d148bb81e2c8da36d5fc882ba4575e10a
Author: Bob Peterson <rpeterso(a)redhat.com>
AuthorDate: Wed Apr 3 08:55:00 2013 -0700
Committer: Bob Peterson <rpeterso(a)redhat.com>
CommitterDate: Mon May 20 11:12:47 2013 -0500
fsck.gfs2: standardize check_metatree return codes
This patch aims to not change functionality at all. What it does is
adds a standard set of three return codes with the following meanings:
meta_is_good - all is well, keep processing metadata normally
meta_skip_further - an non-fatal error occurred, so further metadata
processing for this inode should be skipped.
meta_error - a fatal error occurred in this metadata, so we need to
abort processing.
---
gfs2/fsck/metawalk.c | 14 +++++++-------
gfs2/fsck/metawalk.h | 6 ++++++
gfs2/fsck/pass1.c | 28 ++++++++++++++--------------
gfs2/fsck/pass1b.c | 6 +++---
gfs2/fsck/util.c | 12 ++++++------
5 files changed, 36 insertions(+), 30 deletions(-)
diff --git a/gfs2/fsck/metawalk.c b/gfs2/fsck/metawalk.c
index 135d8fa..dc585ae 100644
--- a/gfs2/fsck/metawalk.c
+++ b/gfs2/fsck/metawalk.c
@@ -996,9 +996,9 @@ int free_block_if_notdup(struct gfs2_inode *ip, uint64_t block,
{
if (!find_remove_dup(ip, block, btype)) { /* not a dup */
fsck_blockmap_set(ip, block, btype, gfs2_block_free);
- return 1;
+ return meta_skip_further;
}
- return 0;
+ return meta_is_good;
}
/**
@@ -1015,7 +1015,7 @@ static int delete_block_if_notdup(struct gfs2_inode *ip, uint64_t block,
uint8_t q;
if (!valid_block(ip->i_sbd, block))
- return -EFAULT;
+ return meta_error;
q = block_type(block);
if (q == gfs2_block_free) {
@@ -1025,7 +1025,7 @@ static int delete_block_if_notdup(struct gfs2_inode *ip, uint64_t block,
(unsigned long long)block,
(unsigned long long)ip->i_di.di_num.no_addr,
(unsigned long long)ip->i_di.di_num.no_addr);
- return 0;
+ return meta_is_good;
}
return free_block_if_notdup(ip, block, btype);
}
@@ -1255,12 +1255,12 @@ static int build_and_check_metalist(struct gfs2_inode *ip, osi_list_t *mlp,
pass->private);
/* check_metalist should hold any buffers
it gets with "bread". */
- if (err < 0) {
+ if (err == meta_error) {
stack;
error = err;
return error;
}
- if (err > 0) {
+ if (err == meta_skip_further) {
if (!error)
error = err;
log_debug( _("Skipping block %llu (0x%llx)\n"),
@@ -1659,7 +1659,7 @@ static int alloc_metalist(struct gfs2_inode *ip, uint64_t block,
(unsigned long long)block);
gfs2_blockmap_set(bl, block, gfs2_indir_blk);
}
- return 0;
+ return meta_is_good;
}
static int alloc_data(struct gfs2_inode *ip, uint64_t metablock,
diff --git a/gfs2/fsck/metawalk.h b/gfs2/fsck/metawalk.h
index 2ba0d72..49217cc 100644
--- a/gfs2/fsck/metawalk.h
+++ b/gfs2/fsck/metawalk.h
@@ -56,6 +56,12 @@ extern int free_block_if_notdup(struct gfs2_inode *ip, uint64_t block,
#define fsck_blockmap_set(ip, b, bt, m) _fsck_blockmap_set(ip, b, bt, m, \
__FUNCTION__, __LINE__)
+enum meta_check_rc {
+ meta_error = -1,
+ meta_is_good = 0,
+ meta_skip_further = 1,
+};
+
/* metawalk_fxns: function pointers to check various parts of the fs
*
* The functions should return -1 on fatal errors, 1 if the block
diff --git a/gfs2/fsck/pass1.c b/gfs2/fsck/pass1.c
index a6fe9a7..3c4dc89 100644
--- a/gfs2/fsck/pass1.c
+++ b/gfs2/fsck/pass1.c
@@ -139,14 +139,14 @@ static int resuscitate_metalist(struct gfs2_inode *ip, uint64_t block,
"range) found in system inode %lld (0x%llx).\n"),
(unsigned long long)ip->i_di.di_num.no_addr,
(unsigned long long)ip->i_di.di_num.no_addr);
- return 1;
+ return meta_skip_further;
}
if (fsck_system_inode(ip->i_sbd, block))
fsck_blockmap_set(ip, block, _("system file"), gfs2_indir_blk);
else
check_n_fix_bitmap(ip->i_sbd, block, gfs2_indir_blk);
bc->indir_count++;
- return 0;
+ return meta_is_good;
}
/*
@@ -263,7 +263,7 @@ static int check_metalist(struct gfs2_inode *ip, uint64_t block,
(unsigned long long)ip->i_di.di_num.no_addr,
(unsigned long long)ip->i_di.di_num.no_addr);
- return 1;
+ return meta_skip_further;
}
if (is_dir(&ip->i_di, ip->i_sbd->gfs1) && h == ip->i_di.di_height) {
iblk_type = GFS2_METATYPE_JD;
@@ -300,7 +300,7 @@ static int check_metalist(struct gfs2_inode *ip, uint64_t block,
gfs2_meta_inval);
brelse(nbh);
nbh = NULL;
- return 1;
+ return meta_skip_further;
}
brelse(nbh);
nbh = NULL;
@@ -314,12 +314,12 @@ static int check_metalist(struct gfs2_inode *ip, uint64_t block,
nbh = NULL;
*bh = NULL;
}
- return 1; /* don't process the metadata again */
+ return meta_skip_further; /* don't process the metadata again */
} else
fsck_blockmap_set(ip, block, _("indirect"),
gfs2_indir_blk);
- return 0;
+ return meta_is_good;
}
/* undo_reference - undo previously processed data or metadata
@@ -825,7 +825,7 @@ static int mark_block_invalid(struct gfs2_inode *ip, uint64_t block,
* and as a result, they'll be freed when this dinode is deleted,
* despite being used by another dinode as a valid block. */
if (!valid_block(ip->i_sbd, block))
- return 0;
+ return meta_is_good;
q = block_type(block);
if (q != gfs2_block_free) {
@@ -837,10 +837,10 @@ static int mark_block_invalid(struct gfs2_inode *ip, uint64_t block,
(unsigned long long)block,
(unsigned long long)ip->i_di.di_num.no_addr,
(unsigned long long)ip->i_di.di_num.no_addr);
- return 0;
+ return meta_is_good;
}
fsck_blockmap_set(ip, block, btype, gfs2_meta_inval);
- return 0;
+ return meta_is_good;
}
static int invalidate_metadata(struct gfs2_inode *ip, uint64_t block,
@@ -910,9 +910,9 @@ static int rangecheck_block(struct gfs2_inode *ip, uint64_t block,
(unsigned long long)ip->i_di.di_num.no_addr,
(unsigned long long)ip->i_di.di_num.no_addr);
if ((*bad_pointers) <= BAD_POINTER_TOLERANCE)
- return ENOENT;
+ return meta_skip_further;
else
- return -ENOENT; /* Exits check_metatree quicker */
+ return meta_error; /* Exits check_metatree quicker */
}
/* See how many duplicate blocks it has */
q = block_type(block);
@@ -925,11 +925,11 @@ static int rangecheck_block(struct gfs2_inode *ip, uint64_t block,
(unsigned long long)ip->i_di.di_num.no_addr,
(unsigned long long)ip->i_di.di_num.no_addr);
if ((*bad_pointers) <= BAD_POINTER_TOLERANCE)
- return ENOENT;
+ return meta_skip_further;
else
- return -ENOENT; /* Exits check_metatree quicker */
+ return meta_error; /* Exits check_metatree quicker */
}
- return 0;
+ return meta_is_good;
}
static int rangecheck_metadata(struct gfs2_inode *ip, uint64_t block,
diff --git a/gfs2/fsck/pass1b.c b/gfs2/fsck/pass1b.c
index b2532fd..b5da200 100644
--- a/gfs2/fsck/pass1b.c
+++ b/gfs2/fsck/pass1b.c
@@ -215,7 +215,7 @@ static int clear_dup_metalist(struct gfs2_inode *ip, uint64_t block,
struct duptree *dt;
if (!valid_block(ip->i_sbd, block))
- return 0;
+ return meta_is_good;
/* This gets tricky. We're traversing a metadata tree trying to
delete an inode based on it having a duplicate block reference
@@ -231,7 +231,7 @@ static int clear_dup_metalist(struct gfs2_inode *ip, uint64_t block,
if (!dt) {
fsck_blockmap_set(ip, block, _("no longer valid"),
gfs2_block_free);
- return 0;
+ return meta_is_good;
}
/* This block, having failed the above test, is duplicated somewhere */
if (block == dh->dt->block) {
@@ -254,7 +254,7 @@ static int clear_dup_metalist(struct gfs2_inode *ip, uint64_t block,
be mistakenly freed as "no longer valid" (in this function above)
even though it's valid metadata for a different inode. Returning
1 ensures that the metadata isn't processed again. */
- return 1;
+ return meta_skip_further;
}
static int clear_dup_data(struct gfs2_inode *ip, uint64_t metablock,
diff --git a/gfs2/fsck/util.c b/gfs2/fsck/util.c
index c11768f..078d5f6 100644
--- a/gfs2/fsck/util.c
+++ b/gfs2/fsck/util.c
@@ -316,19 +316,19 @@ int add_duplicate_ref(struct gfs2_inode *ip, uint64_t block,
struct duptree *dt;
if (!valid_block(ip->i_sbd, block))
- return 0;
+ return meta_is_good;
/* If this is not the first reference (i.e. all calls from pass1) we
need to create the duplicate reference. If this is pass1b, we want
to ignore references that aren't found. */
dt = gfs2_dup_set(block, !first);
if (!dt) /* If this isn't a duplicate */
- return 0;
+ return meta_is_good;
/* If we found the duplicate reference but we've already discovered
the first reference (in pass1b) and the other references in pass1,
we don't need to count it, so just return. */
if (dt->first_ref_found)
- return 0;
+ return meta_is_good;
/* The first time this is called from pass1 is actually the second
reference. When we go back in pass1b looking for the original
@@ -350,12 +350,12 @@ int add_duplicate_ref(struct gfs2_inode *ip, uint64_t block,
if (!(id = malloc(sizeof(*id)))) {
log_crit( _("Unable to allocate "
"inode_with_dups structure\n"));
- return -1;
+ return meta_error;
}
if (!(memset(id, 0, sizeof(*id)))) {
log_crit( _("Unable to zero inode_with_dups "
"structure\n"));
- return -1;
+ return meta_error;
}
id->block_no = ip->i_di.di_num.no_addr;
q = block_type(ip->i_di.di_num.no_addr);
@@ -389,7 +389,7 @@ int add_duplicate_ref(struct gfs2_inode *ip, uint64_t block,
else
log_info( _("This brings the total to: %d duplicate "
"references\n"), dt->refs);
- return 0;
+ return meta_is_good;
}
struct dir_info *dirtree_insert(struct gfs2_inum inum)
Gitweb: http://git.fedorahosted.org/git/?p=gfs2-utils.git;a=commitdiff;h=88a7654d14…
Commit: 88a7654d148bb81e2c8da36d5fc882ba4575e10a
Parent: 5ec85b9f58354868eef23e15ade1be74e751eca0
Author: Bob Peterson <rpeterso(a)redhat.com>
AuthorDate: Wed Apr 3 07:25:00 2013 -0700
Committer: Bob Peterson <rpeterso(a)redhat.com>
CommitterDate: Mon May 20 11:12:47 2013 -0500
fsck.gfs2: pass2: check leaf blocks when fixing hash table
Before this patch, pass2 would attempt to fix the hash table without
first checking the basic integrity of the leaf blocks it was checking.
A misplaced leaf might have its entries relocated as a matter of course.
But if that leaf block had a problem, it could cause all kinds of
errors, including segfaults. This patch gives the hash table repair
function the ability to do basic integrity checks on the leaf block,
and perform repairs if necessary.
---
gfs2/fsck/pass2.c | 100 +++++++++++++++++++++++++++++++++++++++++-----------
1 files changed, 79 insertions(+), 21 deletions(-)
diff --git a/gfs2/fsck/pass2.c b/gfs2/fsck/pass2.c
index 2336aa5..77718be 100644
--- a/gfs2/fsck/pass2.c
+++ b/gfs2/fsck/pass2.c
@@ -1050,6 +1050,66 @@ static int lost_leaf(struct gfs2_inode *ip, uint64_t *tbl, uint64_t leafno,
return 1;
}
+static int basic_check_dentry(struct gfs2_inode *ip, struct gfs2_dirent *dent,
+ struct gfs2_dirent *prev_de,
+ struct gfs2_buffer_head *bh, char *filename,
+ uint32_t *count, int lindex, void *priv)
+{
+ uint8_t q = 0;
+ char tmp_name[MAX_FILENAME];
+ struct gfs2_inum entry;
+ struct dir_status *ds = (struct dir_status *) priv;
+ struct gfs2_dirent dentry, *de;
+ int error;
+
+ memset(&dentry, 0, sizeof(struct gfs2_dirent));
+ gfs2_dirent_in(&dentry, (char *)dent);
+ de = &dentry;
+
+ entry.no_addr = de->de_inum.no_addr;
+ entry.no_formal_ino = de->de_inum.no_formal_ino;
+
+ /* Start of checks */
+ memset(tmp_name, 0, MAX_FILENAME);
+ if (de->de_name_len < MAX_FILENAME)
+ strncpy(tmp_name, filename, de->de_name_len);
+ else
+ strncpy(tmp_name, filename, MAX_FILENAME - 1);
+
+ error = basic_dentry_checks(ip, dent, &entry, tmp_name, count, de,
+ ds, &q, bh);
+ if (error) {
+ dirent2_del(ip, bh, prev_de, dent);
+ log_err( _("Bad directory entry '%s' cleared.\n"), tmp_name);
+ return 1;
+ } else {
+ return 0;
+ }
+}
+
+static int pass2_repair_leaf(struct gfs2_inode *ip, uint64_t *leaf_no,
+ int lindex, int ref_count, const char *msg,
+ void *private)
+{
+ return repair_leaf(ip, leaf_no, lindex, ref_count, msg);
+}
+
+/* The purpose of leafck_fxns is to provide a means for function fix_hashtable
+ * to do basic sanity checks on leaf blocks before manipulating them, for
+ * example, splitting them. If they're corrupt, splitting them or trying to
+ * move their contents can cause a segfault. We can't really use the standard
+ * pass2_fxns because that will do things we don't want. For example, it will
+ * find '.' and '..' and increment the directory link count, which would be
+ * done a second time when the dirent is really checked in pass2_fxns.
+ * We don't want it to do the "wrong leaf" thing, or set_parent_dir either.
+ * We just want a basic sanity check on pointers and lengths.
+ */
+struct metawalk_fxns leafck_fxns = {
+ .check_leaf_depth = check_leaf_depth,
+ .check_dentry = basic_check_dentry,
+ .repair_leaf = pass2_repair_leaf,
+};
+
/* fix_hashtable - fix a corrupt hash table
*
* The main intent of this function is to sort out hash table problems.
@@ -1079,10 +1139,11 @@ static int fix_hashtable(struct gfs2_inode *ip, uint64_t *tbl, unsigned hsize,
int len, int *proper_len, int factor)
{
struct gfs2_buffer_head *lbh;
- struct gfs2_leaf *leaf;
+ struct gfs2_leaf leaf;
struct gfs2_dirent dentry, *de;
int changes = 0, error, i, extras, hash_index;
uint64_t new_leaf_blk;
+ uint64_t leaf_no;
uint32_t leaf_proper_start;
*proper_len = len;
@@ -1096,14 +1157,20 @@ static int fix_hashtable(struct gfs2_inode *ip, uint64_t *tbl, unsigned hsize,
return 0;
}
+ memset(&leaf, 0, sizeof(leaf));
+ leaf_no = leafblk;
+ error = check_leaf(ip, lindex, &leafck_fxns, &leaf_no, &leaf, &len);
+ if (error) {
+ log_debug("Leaf repaired while fixing the hash table.\n");
+ error = 0;
+ }
lbh = bread(ip->i_sbd, leafblk);
- leaf = (struct gfs2_leaf *)lbh->b_data;
/* If the leaf's depth is out of range for this dinode, it's obviously
attached to the wrong dinode. Move the dirents to lost+found. */
- if (be16_to_cpu(leaf->lf_depth) > ip->i_di.di_depth) {
+ if (leaf.lf_depth > ip->i_di.di_depth) {
log_err(_("This leaf block's depth (%d) is too big for this "
"dinode's depth (%d)\n"),
- be16_to_cpu(leaf->lf_depth), ip->i_di.di_depth);
+ leaf.lf_depth, ip->i_di.di_depth);
error = lost_leaf(ip, tbl, leafblk, len, lindex, lbh);
brelse(lbh);
return error;
@@ -1129,7 +1196,7 @@ static int fix_hashtable(struct gfs2_inode *ip, uint64_t *tbl, unsigned hsize,
}
/* Calculate the proper number of pointers based on the leaf depth. */
- *proper_len = 1 << (ip->i_di.di_depth - be16_to_cpu(leaf->lf_depth));
+ *proper_len = 1 << (ip->i_di.di_depth - leaf.lf_depth);
/* Look at the first dirent and check its hash value to see if it's
at the proper starting offset. */
@@ -1162,7 +1229,7 @@ static int fix_hashtable(struct gfs2_inode *ip, uint64_t *tbl, unsigned hsize,
already at its maximum depth. */
if ((leaf_proper_start < proper_start) ||
((*proper_len > len || lindex > leaf_proper_start) &&
- be16_to_cpu(leaf->lf_depth) == ip->i_di.di_depth)) {
+ leaf.lf_depth == ip->i_di.di_depth)) {
log_err(_("Leaf block should start at 0x%x, but it appears at "
"0x%x in the hash table.\n"), leaf_proper_start,
proper_start);
@@ -1177,24 +1244,22 @@ static int fix_hashtable(struct gfs2_inode *ip, uint64_t *tbl, unsigned hsize,
later than they should, we can split the leaf to give it a smaller
footprint in the hash table. */
if ((*proper_len > len || lindex > leaf_proper_start) &&
- ip->i_di.di_depth > be16_to_cpu(leaf->lf_depth)) {
+ ip->i_di.di_depth > leaf.lf_depth) {
log_err(_("For depth %d, length %d, the proper start is: "
"0x%x.\n"), factor, len, proper_start);
changes++;
new_leaf_blk = find_free_blk(ip->i_sbd);
dir_split_leaf(ip, lindex, leafblk, lbh);
/* re-read the leaf to pick up dir_split_leaf's changes */
- gfs2_leaf_in(leaf, lbh);
- *proper_len = 1 << (ip->i_di.di_depth -
- be16_to_cpu(leaf->lf_depth));
+ gfs2_leaf_in(&leaf, lbh);
+ *proper_len = 1 << (ip->i_di.di_depth - leaf.lf_depth);
log_err(_("Leaf block %llu (0x%llx) was split from length "
"%d to %d\n"), (unsigned long long)leafblk,
(unsigned long long)leafblk, len, *proper_len);
if (*proper_len < 0) {
log_err(_("Programming error: proper_len=%d, "
"di_depth = %d, lf_depth = %d.\n"),
- *proper_len, ip->i_di.di_depth,
- be16_to_cpu(leaf->lf_depth));
+ *proper_len, ip->i_di.di_depth, leaf.lf_depth);
exit(FSCK_ERROR);
}
log_err(_("New split-off leaf block was allocated at %lld "
@@ -1219,8 +1284,8 @@ static int fix_hashtable(struct gfs2_inode *ip, uint64_t *tbl, unsigned hsize,
if (*proper_len < len) {
log_err(_("There are %d pointers, but leaf 0x%llx's "
"depth, %d, only allows %d\n"),
- len, (unsigned long long)leafblk,
- be16_to_cpu(leaf->lf_depth), *proper_len);
+ len, (unsigned long long)leafblk, leaf.lf_depth,
+ *proper_len);
}
brelse(lbh);
/* At this point, lindex should be at the proper end of the pointers.
@@ -1422,13 +1487,6 @@ static int check_hash_tbl(struct gfs2_inode *ip, uint64_t *tbl,
return error;
}
-static int pass2_repair_leaf(struct gfs2_inode *ip, uint64_t *leaf_no,
- int lindex, int ref_count, const char *msg,
- void *private)
-{
- return repair_leaf(ip, leaf_no, lindex, ref_count, msg);
-}
-
struct metawalk_fxns pass2_fxns = {
.private = NULL,
.check_leaf_depth = check_leaf_depth,
Gitweb: http://git.fedorahosted.org/git/?p=gfs2-utils.git;a=commitdiff;h=5befaedc6b…
Commit: 5befaedc6b7f8cea80989994ec1934953f4db404
Parent: bbb17b6bc32e8006afbf199f98555283c453ce05
Author: Bob Peterson <rpeterso(a)redhat.com>
AuthorDate: Tue Apr 2 13:19:35 2013 -0700
Committer: Bob Peterson <rpeterso(a)redhat.com>
CommitterDate: Mon May 20 11:12:46 2013 -0500
fsck.gfs2: Don't flag GFS1 non-dinode blocks as duplicates
Before this patch, fsck.gfs2 could get into problems when processing
a GFS1 file system. The issue goes back to the fact that all GFS1
metadata is marked as "Meta" in the bitmap, whereas that bitmap
designation is reserved for dinodes in GFS2. For example, take a
GFS1 file of height 2, which looks like this:
Block
------
0x1234 dinode
0x1235 |----> indirect meta
0x1236 |---->data at offset 0 of the file
Before this patch, fsck.gfs2 would:
1. Encounter the dinode at 0x1234 and mark it as "dinode" in the
blockmap.
2. Process its metadata, see block 0x1235, mark it as "indirect meta"
in the blockmap.
3. Process the metadata's data, see block 0x1236, mark it as "data".
4. When it's done with the dinode, it moves on to the next dinode.
But since GFS1 doesn't distinguish dinodes from other metadata,
the next block in the bitmap that has that designation is block
0x1235.
5. Since block 0x1235 was previously marked "indirect meta" pass1
gets confused and thinks the block is a duplicate reference,
and it's invalid as a dinode. This is a non-problem that's
treated as a problem, and it makes bad decisions based on it,
deleting what it perceives to be corruption.
This patch adds special checks for this problem and assumes the block
is just normal GFS1 non-dinode metadata.
---
gfs2/fsck/pass1.c | 69 ++++++++++++++++++++++++++++++++++------------------
1 files changed, 45 insertions(+), 24 deletions(-)
diff --git a/gfs2/fsck/pass1.c b/gfs2/fsck/pass1.c
index 0f3adfe..004ca78 100644
--- a/gfs2/fsck/pass1.c
+++ b/gfs2/fsck/pass1.c
@@ -1084,22 +1084,11 @@ bad_dinode:
*/
static int handle_di(struct gfs2_sbd *sdp, struct gfs2_buffer_head *bh)
{
- uint8_t q;
int error = 0;
uint64_t block = bh->b_blocknr;
struct gfs2_inode *ip;
ip = fsck_inode_get(sdp, bh);
- q = block_type(block);
- if (q != gfs2_block_free) {
- log_err( _("Found a duplicate inode block at #%llu"
- " (0x%llx) previously marked as a %s\n"),
- (unsigned long long)block,
- (unsigned long long)block, block_type_string(q));
- add_duplicate_ref(ip, block, ref_as_meta, 0, INODE_VALID);
- fsck_inode_put(&ip);
- return 0;
- }
if (ip->i_di.di_num.no_addr != block) {
log_err( _("Inode #%llu (0x%llx): Bad inode address found: %llu "
@@ -1359,8 +1348,13 @@ static int pass1_process_bitmap(struct gfs2_sbd *sdp, struct rgrp_tree *rgd, uin
struct gfs2_buffer_head *bh;
unsigned i;
uint64_t block;
+ struct gfs2_inode *ip;
+ uint8_t q;
for (i = 0; i < n; i++) {
+ int is_inode;
+ uint32_t check_magic;
+
block = ibuf[i];
/* skip gfs1 rindex indirect blocks */
@@ -1389,9 +1383,47 @@ static int pass1_process_bitmap(struct gfs2_sbd *sdp, struct rgrp_tree *rgd, uin
(unsigned long long)block);
continue;
}
+
bh = bread(sdp, block);
- if (gfs2_check_meta(bh, GFS2_METATYPE_DI)) {
+ is_inode = 0;
+ if (gfs2_check_meta(bh, GFS2_METATYPE_DI) == 0)
+ is_inode = 1;
+
+ check_magic = ((struct gfs2_meta_header *)
+ (bh->b_data))->mh_magic;
+
+ q = block_type(block);
+ if (q != gfs2_block_free) {
+ if (be32_to_cpu(check_magic) == GFS2_MAGIC &&
+ sdp->gfs1 && !is_inode) {
+ log_debug("Block 0x%llx assumed to be "
+ "previously processed GFS1 "
+ "non-dinode metadata.\n",
+ (unsigned long long)block);
+ brelse(bh);
+ continue;
+ }
+ log_err( _("Found a duplicate inode block at #%llu "
+ "(0x%llx) previously marked as a %s\n"),
+ (unsigned long long)block,
+ (unsigned long long)block,
+ block_type_string(q));
+ ip = fsck_inode_get(sdp, bh);
+ if (is_inode && ip->i_di.di_num.no_addr == block)
+ add_duplicate_ref(ip, block, ref_is_inode, 0,
+ INODE_VALID);
+ else
+ log_info(_("dinum.no_addr is wrong, so I "
+ "assume the bitmap is just "
+ "wrong.\n"));
+ fsck_inode_put(&ip);
+ brelse(bh);
+ continue;
+ }
+
+ if (!is_inode) {
+ if (be32_to_cpu(check_magic) == GFS2_MAGIC) {
/* In gfs2, a bitmap mark of 2 means an inode,
but in gfs1 it means any metadata. So if
this is gfs1 and not an inode, it may be
@@ -1399,12 +1431,7 @@ static int pass1_process_bitmap(struct gfs2_sbd *sdp, struct rgrp_tree *rgd, uin
be referenced by an inode, so we need to
skip it here and it will be sorted out
when the referencing inode is checked. */
- if (sdp->gfs1) {
- uint32_t check_magic;
-
- check_magic = ((struct gfs2_meta_header *)
- (bh->b_data))->mh_magic;
- if (be32_to_cpu(check_magic) == GFS2_MAGIC) {
+ if (sdp->gfs1) {
log_debug( _("Deferring GFS1 "
"metadata block #"
"%" PRIu64" (0x%"
@@ -1418,12 +1445,6 @@ static int pass1_process_bitmap(struct gfs2_sbd *sdp, struct rgrp_tree *rgd, uin
"%llu (0x%llx)\n"),
(unsigned long long)block,
(unsigned long long)block);
- if (gfs2_blockmap_set(bl, block, gfs2_block_free)) {
- stack;
- brelse(bh);
- gfs2_special_free(&gfs1_rindex_blks);
- return FSCK_ERROR;
- }
check_n_fix_bitmap(sdp, block, gfs2_block_free);
} else if (handle_di(sdp, bh) < 0) {
stack;