Gitweb: http://git.fedorahosted.org/git/?p=cluster.git;a=commitdiff;h=89e2e4a2f24f5…
Commit: 89e2e4a2f24f54c14cf7b241daea375324a0a5eb
Parent: 872b99e0a2569404c49f4483260b5a1b8023d372
Author: Bob Peterson <rpeterso(a)redhat.com>
AuthorDate: Wed Mar 6 10:29:38 2013 -0700
Committer: Bob Peterson <rpeterso(a)redhat.com>
CommitterDate: Fri May 17 14:56:50 2013 -0500
fsck.gfs2: shorten some debug messages in lost+found
This patch changes the debug output of lost+found such that it
only prints the block number in hexadecimal. This shortens the output
and makes debug output easier to read.
rhbz#902920
---
gfs2/fsck/lost_n_found.c | 12 ++++--------
1 files changed, 4 insertions(+), 8 deletions(-)
diff --git a/gfs2/fsck/lost_n_found.c b/gfs2/fsck/lost_n_found.c
index 42d97ee..388787d 100644
--- a/gfs2/fsck/lost_n_found.c
+++ b/gfs2/fsck/lost_n_found.c
@@ -32,11 +32,9 @@ static void add_dotdot(struct gfs2_inode *ip)
if (di && valid_block(sdp, di->dotdot_parent.no_addr)) {
struct gfs2_inode *dip;
- log_debug(_("Directory %lld (0x%llx) already had a "
- "\"..\" link to %lld (0x%llx).\n"),
+ log_debug(_("Directory (0x%llx) already had a "
+ "\"..\" link to (0x%llx).\n"),
(unsigned long long)ip->i_di.di_num.no_addr,
- (unsigned long long)ip->i_di.di_num.no_addr,
- (unsigned long long)di->dotdot_parent.no_addr,
(unsigned long long)di->dotdot_parent.no_addr);
dip = fsck_load_inode(sdp, di->dotdot_parent.no_addr);
if (dip->i_di.di_num.no_formal_ino ==
@@ -74,15 +72,13 @@ static void add_dotdot(struct gfs2_inode *ip)
} else {
if (di)
log_debug(_("Couldn't find a valid \"..\" entry "
- "for orphan directory %lld (0x%llx): "
+ "for orphan directory (0x%llx): "
"'..' = 0x%llx\n"),
(unsigned long long)ip->i_di.di_num.no_addr,
- (unsigned long long)ip->i_di.di_num.no_addr,
(unsigned long long)di->dotdot_parent.no_addr);
else
- log_debug(_("Couldn't find directory %lld (0x%llx) "
+ log_debug(_("Couldn't find directory (0x%llx) "
"in directory tree.\n"),
- (unsigned long long)ip->i_di.di_num.no_addr,
(unsigned long long)ip->i_di.di_num.no_addr);
}
if (gfs2_dirent_del(ip, "..", 2))
Gitweb: http://git.fedorahosted.org/git/?p=cluster.git;a=commitdiff;h=1325bb4d27bff…
Commit: 1325bb4d27bffbcaa5c2170bb1300d8e2c3a9807
Parent: 82558210e8ef16821170bb9787c0b46a1abf9bfd
Author: Bob Peterson <rpeterso(a)redhat.com>
AuthorDate: Mon Feb 25 10:18:55 2013 -0700
Committer: Bob Peterson <rpeterso(a)redhat.com>
CommitterDate: Fri May 17 14:56:33 2013 -0500
fsck.gfs2: Split out function to make sure lost+found exists
This patch extracts a section of code from the lost+found functions
and makes a new make_sure_lf_exists function that can be called
from more places.
rhbz#902920
---
gfs2/fsck/lost_n_found.c | 129 +++++++++++++++++++++++-----------------------
gfs2/fsck/lost_n_found.h | 1 +
2 files changed, 66 insertions(+), 64 deletions(-)
diff --git a/gfs2/fsck/lost_n_found.c b/gfs2/fsck/lost_n_found.c
index 282d673..751cbd8 100644
--- a/gfs2/fsck/lost_n_found.c
+++ b/gfs2/fsck/lost_n_found.c
@@ -86,6 +86,70 @@ static void add_dotdot(struct gfs2_inode *ip)
}
}
+void make_sure_lf_exists(struct gfs2_inode *ip)
+{
+ uint8_t q;
+ struct dir_info *di;
+ struct gfs2_sbd *sdp = ip->i_sbd;
+ uint32_t mode;
+
+ if (lf_dip)
+ return;
+
+ log_info( _("Locating/Creating lost+found directory\n"));
+
+ /* if this is gfs1, we have to trick createi into using
+ no_formal_ino = no_addr, so we set next_inum to the
+ free block we're about to allocate. */
+ if (sdp->gfs1)
+ sdp->md.next_inum = find_free_blk(sdp);
+ mode = (sdp->gfs1 ? DT2IF(GFS_FILE_DIR) : S_IFDIR) | 0700;
+ if (sdp->gfs1)
+ lf_dip = gfs_createi(sdp->md.rooti, "lost+found", mode, 0);
+ else
+ lf_dip = createi(sdp->md.rooti, "lost+found",
+ S_IFDIR | 0700, 0);
+ if (lf_dip == NULL) {
+ log_crit(_("Error creating lost+found: %s\n"),
+ strerror(errno));
+ exit(FSCK_ERROR);
+ }
+
+ /* createi will have incremented the di_nlink link count for the root
+ directory. We must set the nlink value in the hash table to keep
+ them in sync so that pass4 can detect and fix any descrepancies. */
+ set_di_nlink(sdp->md.rooti);
+
+ q = block_type(lf_dip->i_di.di_num.no_addr);
+ if (q != gfs2_inode_dir) {
+ /* This is a new lost+found directory, so set its block type
+ and increment link counts for the directories */
+ /* FIXME: i'd feel better about this if fs_mkdir returned
+ whether it created a new directory or just found an old one,
+ and we used that instead of the block_type to run this */
+ fsck_blockmap_set(ip, lf_dip->i_di.di_num.no_addr,
+ _("lost+found dinode"), gfs2_inode_dir);
+ dirtree_insert(lf_dip->i_di.di_num);
+ /* root inode links to lost+found */
+ incr_link_count(sdp->md.rooti->i_di.di_num, lf_dip, _("root"));
+ /* lost+found link for '.' from itself */
+ incr_link_count(lf_dip->i_di.di_num, lf_dip, "\".\"");
+ /* lost+found link for '..' back to root */
+ incr_link_count(lf_dip->i_di.di_num, sdp->md.rooti, "\"..\"");
+ if (sdp->gfs1)
+ lf_dip->i_di.__pad1 = GFS_FILE_DIR;
+ }
+ log_info( _("lost+found directory is dinode %lld (0x%llx)\n"),
+ (unsigned long long)lf_dip->i_di.di_num.no_addr,
+ (unsigned long long)lf_dip->i_di.di_num.no_addr);
+ di = dirtree_find(lf_dip->i_di.di_num.no_addr);
+ if (di) {
+ log_info( _("Marking lost+found inode connected\n"));
+ di->checked = 1;
+ di = NULL;
+ }
+}
+
/* add_inode_to_lf - Add dir entry to lost+found for the inode
* @ip: inode to add to lost + found
*
@@ -100,73 +164,10 @@ int add_inode_to_lf(struct gfs2_inode *ip){
__be32 inode_type;
uint64_t lf_blocks;
struct gfs2_sbd *sdp = ip->i_sbd;
- struct dir_info *di;
int err = 0;
uint32_t mode;
- if (!lf_dip) {
- uint8_t q;
-
- log_info( _("Locating/Creating lost+found directory\n"));
-
- /* if this is gfs1, we have to trick createi into using
- no_formal_ino = no_addr, so we set next_inum to the
- free block we're about to allocate. */
- if (sdp->gfs1)
- sdp->md.next_inum = find_free_blk(sdp);
- mode = (sdp->gfs1 ? DT2IF(GFS_FILE_DIR) : S_IFDIR) | 0700;
- if (sdp->gfs1)
- lf_dip = gfs_createi(sdp->md.rooti, "lost+found",
- mode, 0);
- else
- lf_dip = createi(sdp->md.rooti, "lost+found",
- S_IFDIR | 0700, 0);
- if (lf_dip == NULL) {
- log_crit(_("Error %d creating lost+found\n"), errno);
- exit(FSCK_ERROR);
- }
-
- /* createi will have incremented the di_nlink link count for
- the root directory. We must set the nlink value
- in the hash table to keep them in sync so that pass4 can
- detect and fix any descrepancies. */
- set_di_nlink(sdp->md.rooti);
-
- q = block_type(lf_dip->i_di.di_num.no_addr);
- if (q != gfs2_inode_dir) {
- /* This is a new lost+found directory, so set its
- * block type and increment link counts for
- * the directories */
- /* FIXME: i'd feel better about this if
- * fs_mkdir returned whether it created a new
- * directory or just found an old one, and we
- * used that instead of the block_type to run
- * this */
- fsck_blockmap_set(ip, lf_dip->i_di.di_num.no_addr,
- _("lost+found dinode"),
- gfs2_inode_dir);
- /* root inode links to lost+found */
- incr_link_count(sdp->md.rooti->i_di.di_num,
- lf_dip, _("root"));
- /* lost+found link for '.' from itself */
- incr_link_count(lf_dip->i_di.di_num,
- lf_dip, "\".\"");
- /* lost+found link for '..' back to root */
- incr_link_count(lf_dip->i_di.di_num, sdp->md.rooti,
- "\"..\"");
- if (sdp->gfs1)
- lf_dip->i_di.__pad1 = GFS_FILE_DIR;
- }
- log_info( _("lost+found directory is dinode %lld (0x%llx)\n"),
- (unsigned long long)lf_dip->i_di.di_num.no_addr,
- (unsigned long long)lf_dip->i_di.di_num.no_addr);
- di = dirtree_find(lf_dip->i_di.di_num.no_addr);
- if (di) {
- log_info( _("Marking lost+found inode connected\n"));
- di->checked = 1;
- di = NULL;
- }
- }
+ make_sure_lf_exists(ip);
if (ip->i_di.di_num.no_addr == lf_dip->i_di.di_num.no_addr) {
log_err( _("Trying to add lost+found to itself...skipping"));
return 0;
diff --git a/gfs2/fsck/lost_n_found.h b/gfs2/fsck/lost_n_found.h
index f28a1d9..2b76cc2 100644
--- a/gfs2/fsck/lost_n_found.h
+++ b/gfs2/fsck/lost_n_found.h
@@ -4,5 +4,6 @@
#include "libgfs2.h"
int add_inode_to_lf(struct gfs2_inode *ip);
+void make_sure_lf_exists(struct gfs2_inode *ip);
#endif /* __LOST_N_FOUND_H__ */
Gitweb: http://git.fedorahosted.org/git/?p=cluster.git;a=commitdiff;h=c361fd8d3d7b1…
Commit: c361fd8d3d7b1074107f0800fdae79820574b81d
Parent: 0cf2544edfa377c47b0e904ecdce00194590593e
Author: Steven Whitehouse <swhiteho(a)redhat.com>
AuthorDate: Mon Feb 18 17:06:58 2013 +0000
Committer: Bob Peterson <rpeterso(a)redhat.com>
CommitterDate: Fri May 17 14:29:20 2013 -0500
fsck: Speed up reading of dir leaf blocks
This patch adds readahead for directory leaf blocks. It gives me a speed
up of only around one second on my test filesystem, however that only
has one directory with a reasonable number of files in it. So that is
actually pretty good going for that small a filesystem.
Due to the reading of the dir hash table in a single sweep, this reduces
the number of calls to read dir hash table blocks considerably.
The patch takes all the valid leaf block pointers, sorts them into disk
block order and then issues readahead requests for the blocks in order
that they are read in, in good time before they are needed.
rhbz#902920
---
gfs2/fsck/metawalk.c | 86 ++++++++++++++++++++++++++++++++++++++++++++++---
1 files changed, 80 insertions(+), 6 deletions(-)
diff --git a/gfs2/fsck/metawalk.c b/gfs2/fsck/metawalk.c
index fb461ae..ce80738 100644
--- a/gfs2/fsck/metawalk.c
+++ b/gfs2/fsck/metawalk.c
@@ -7,6 +7,7 @@
#include <unistd.h>
#include <libintl.h>
#include <ctype.h>
+#include <fcntl.h>
#define _(String) gettext(String)
#include "libgfs2.h"
@@ -640,24 +641,87 @@ out_copy_old_leaf:
return 1;
}
+static uint64_t *get_dir_hash(struct gfs2_inode *ip)
+{
+ unsigned hsize = (1 << ip->i_di.di_depth) * sizeof(uint64_t);
+ int ret;
+ uint64_t *tbl = malloc(hsize);
+
+ if (tbl == NULL)
+ return NULL;
+
+ ret = gfs2_readi(ip, tbl, 0, hsize);
+ if (ret != hsize) {
+ free(tbl);
+ return NULL;
+ }
+
+ return tbl;
+}
+
+static int u64cmp(const void *p1, const void *p2)
+{
+ uint64_t a = *(uint64_t *)p1;
+ uint64_t b = *(uint64_t *)p2;
+
+ if (a > b)
+ return 1;
+ if (b < b)
+ return -1;
+
+ return 0;
+}
+
+static void dir_leaf_reada(struct gfs2_inode *ip, uint64_t *tbl, unsigned hsize)
+{
+ uint64_t *t = alloca(hsize * sizeof(uint64_t));
+ uint64_t leaf_no;
+ struct gfs2_sbd *sdp = ip->i_sbd;
+ unsigned n = 0;
+ unsigned i;
+
+ for (i = 0; i < hsize; i++) {
+ leaf_no = be64_to_cpu(tbl[i]);
+ if (valid_block(ip->i_sbd, leaf_no))
+ t[n++] = leaf_no * sdp->bsize;
+ }
+ qsort(t, n, sizeof(uint64_t), u64cmp);
+ for (i = 0; i < n; i++)
+ posix_fadvise(sdp->device_fd, t[i], sdp->bsize, POSIX_FADV_WILLNEED);
+}
+
/* Checks exhash directory entries */
static int check_leaf_blks(struct gfs2_inode *ip, struct metawalk_fxns *pass)
{
int error;
struct gfs2_leaf leaf, oldleaf;
+ unsigned hsize = (1 << ip->i_di.di_depth);
uint64_t leaf_no, old_leaf, bad_leaf = -1;
uint64_t first_ok_leaf;
struct gfs2_buffer_head *lbh;
int lindex;
struct gfs2_sbd *sdp = ip->i_sbd;
int ref_count = 0, old_was_dup;
+ uint64_t *tbl;
+
+ tbl = get_dir_hash(ip);
+ if (tbl == NULL) {
+ perror("get_dir_hash");
+ return -1;
+ }
+
+ /* Turn off system readahead */
+ posix_fadvise(sdp->device_fd, 0, 0, POSIX_FADV_RANDOM);
+
+ /* Readahead */
+ dir_leaf_reada(ip, tbl, hsize);
/* Find the first valid leaf pointer in range and use it as our "old"
leaf. That way, bad blocks at the beginning will be overwritten
with the first valid leaf. */
first_ok_leaf = leaf_no = -1;
- for (lindex = 0; lindex < (1 << ip->i_di.di_depth); lindex++) {
- gfs2_get_leaf_nr(ip, lindex, &leaf_no);
+ for (lindex = 0; lindex < hsize; lindex++) {
+ leaf_no = be64_to_cpu(tbl[lindex]);
if (valid_block(ip->i_sbd, leaf_no)) {
lbh = bread(sdp, leaf_no);
/* Make sure it's really a valid leaf block. */
@@ -674,19 +738,22 @@ static int check_leaf_blks(struct gfs2_inode *ip, struct metawalk_fxns *pass)
"blocks\n"),
(unsigned long long)ip->i_di.di_num.no_addr,
(unsigned long long)ip->i_di.di_num.no_addr);
+ free(tbl);
+ posix_fadvise(sdp->device_fd, 0, 0, POSIX_FADV_NORMAL);
return 1;
}
old_leaf = -1;
memset(&oldleaf, 0, sizeof(oldleaf));
old_was_dup = 0;
- for (lindex = 0; lindex < (1 << ip->i_di.di_depth); lindex++) {
+ for (lindex = 0; lindex < hsize; lindex++) {
if (fsck_abort)
break;
- gfs2_get_leaf_nr(ip, lindex, &leaf_no);
+ leaf_no = be64_to_cpu(tbl[lindex]);
/* GFS has multiple indirect pointers to the same leaf
* until those extra pointers are needed, so skip the dups */
if (leaf_no == bad_leaf) {
+ tbl[lindex] = cpu_to_be64(old_leaf);
gfs2_put_leaf_nr(ip, lindex, old_leaf);
ref_count++;
continue;
@@ -696,8 +763,11 @@ static int check_leaf_blks(struct gfs2_inode *ip, struct metawalk_fxns *pass)
}
do {
- if (fsck_abort)
+ if (fsck_abort) {
+ free(tbl);
+ posix_fadvise(sdp->device_fd, 0, 0, POSIX_FADV_NORMAL);
return 0;
+ }
/* If the old leaf was a duplicate referenced by a
previous dinode, we can't check the number of
pointers because the number of pointers may be for
@@ -708,8 +778,10 @@ static int check_leaf_blks(struct gfs2_inode *ip, struct metawalk_fxns *pass)
&ref_count,
&lindex,
&oldleaf);
- if (error)
+ if (error) {
+ free(tbl);
return error;
+ }
}
error = check_leaf(ip, lindex, pass, &ref_count,
&leaf_no, old_leaf, &bad_leaf,
@@ -724,6 +796,8 @@ static int check_leaf_blks(struct gfs2_inode *ip, struct metawalk_fxns *pass)
(unsigned long long)leaf_no);
} while (1); /* while we have chained leaf blocks */
} /* for every leaf block */
+ free(tbl);
+ posix_fadvise(sdp->device_fd, 0, 0, POSIX_FADV_NORMAL);
return 0;
}
Gitweb: http://git.fedorahosted.org/git/?p=cluster.git;a=commitdiff;h=d45a4fe2fa265…
Commit: d45a4fe2fa265a19a4130161caa4ce92367f9072
Parent: 1d7a0335016cae0246f455a707f78bfc5d1ff880
Author: John Ruemker <jruemker(a)redhat.com>
AuthorDate: Tue May 14 15:19:19 2013 -0500
Committer: Ryan McCabe <rmccabe(a)redhat.com>
CommitterDate: Mon May 20 23:46:49 2013 -0400
HA LVM should only remove missing PVs on stop when they belong to mirrors
This adds --mirrorsonly to the 3 'vgreduce --removemissing' calls in the
LVM agents.
You'll also notice that it adds another self_fence check after we fail to
remove tags. In my previous comment, I pointed out that in the case of
single-host by_lv, after we vgreduce we then can't deactivate the logical
volume again because it doesn't exist. This results in us executing
self_fence, which may have just been a happy accident. But when we avoid
making metadata changes by adding --mirrorsonly, the subsequent deactivation
is still successful, and thus we miss the self_fence logic. So, I added
another check so we still catch the failure and fence ourselves in this
situation.
Resolves: rhbz#962376
Signed-off-by: John Ruemker <jruemker(a)redhat.com>
Signed-off-by: Jonthan Brassow <jbrassow(a)redhat.com>
Signed-off-by: Ryan McCabe <rmccabe(a)redhat.com>
---
rgmanager/src/resources/lvm_by_lv.sh | 14 ++++++++++----
rgmanager/src/resources/lvm_by_vg.sh | 4 ++--
2 files changed, 12 insertions(+), 6 deletions(-)
diff --git a/rgmanager/src/resources/lvm_by_lv.sh b/rgmanager/src/resources/lvm_by_lv.sh
index 4971173..7140076 100644
--- a/rgmanager/src/resources/lvm_by_lv.sh
+++ b/rgmanager/src/resources/lvm_by_lv.sh
@@ -243,13 +243,19 @@ lv_activate_and_tag()
# be removed from the VG via a separate call before
# the tag can be removed.
ocf_log err "Attempting volume group clean-up and retry"
- vgreduce --removemissing --force $OCF_RESKEY_vg_name
+ vgreduce --removemissing --mirrorsonly --force $OCF_RESKEY_vg_name
# Retry tag deletion
lvchange --deltag $tag $lv_path
if [ $? -ne 0 ]; then
- ocf_log err "Failed to delete tag from $lv_path"
- return $OCF_ERR_GENERIC
+ if [ "$self_fence" ]; then
+ ocf_log err "Failed to delete tag from $lv_path: REBOOTING"
+ sync
+ reboot -fn
+ else
+ ocf_log err "Failed to delete tag from $lv_path"
+ fi
+ return $OCF_ERR_GENERIC
fi
fi
@@ -322,7 +328,7 @@ lv_activate()
ocf_log notice "Attempting cleanup of $OCF_RESKEY_vg_name"
- if vgreduce --removemissing --force --config \
+ if vgreduce --removemissing --mirrorsonly --force --config \
"activation { volume_list = \"$OCF_RESKEY_vg_name\" }" \
$OCF_RESKEY_vg_name; then
ocf_log notice "$OCF_RESKEY_vg_name now consistent"
diff --git a/rgmanager/src/resources/lvm_by_vg.sh b/rgmanager/src/resources/lvm_by_vg.sh
index 0dd2aaa..819d0b8 100755
--- a/rgmanager/src/resources/lvm_by_vg.sh
+++ b/rgmanager/src/resources/lvm_by_vg.sh
@@ -202,7 +202,7 @@ function vg_start_clustered
ocf_log err "Failed to activate volume group, $OCF_RESKEY_vg_name"
ocf_log notice "Attempting cleanup of $OCF_RESKEY_vg_name"
- if ! vgreduce --removemissing --force $OCF_RESKEY_vg_name; then
+ if ! vgreduce --removemissing --mirrorsonly --force $OCF_RESKEY_vg_name; then
ocf_log err "Failed to make $OCF_RESKEY_vg_name consistent"
return $OCF_ERR_GENERIC
fi
@@ -398,7 +398,7 @@ function vg_stop_single
# Shut down the volume group
# Do we need to make this resilient?
- vgchange -an $OCF_RESKEY_vg_name
+ vgchange -aln $OCF_RESKEY_vg_name
# Make sure all the logical volumes are inactive
results=(`lvs -o name,attr --noheadings $OCF_RESKEY_vg_name 2> /dev/null`)
Gitweb: http://git.fedorahosted.org/git/?p=cluster.git;a=commitdiff;h=d45a4fe2fa265…
Commit: d45a4fe2fa265a19a4130161caa4ce92367f9072
Parent: 1d7a0335016cae0246f455a707f78bfc5d1ff880
Author: John Ruemker <jruemker(a)redhat.com>
AuthorDate: Tue May 14 15:19:19 2013 -0500
Committer: Ryan McCabe <rmccabe(a)redhat.com>
CommitterDate: Mon May 20 23:46:49 2013 -0400
HA LVM should only remove missing PVs on stop when they belong to mirrors
This adds --mirrorsonly to the 3 'vgreduce --removemissing' calls in the
LVM agents.
You'll also notice that it adds another self_fence check after we fail to
remove tags. In my previous comment, I pointed out that in the case of
single-host by_lv, after we vgreduce we then can't deactivate the logical
volume again because it doesn't exist. This results in us executing
self_fence, which may have just been a happy accident. But when we avoid
making metadata changes by adding --mirrorsonly, the subsequent deactivation
is still successful, and thus we miss the self_fence logic. So, I added
another check so we still catch the failure and fence ourselves in this
situation.
Resolves: rhbz#962376
Signed-off-by: John Ruemker <jruemker(a)redhat.com>
Signed-off-by: Jonthan Brassow <jbrassow(a)redhat.com>
Signed-off-by: Ryan McCabe <rmccabe(a)redhat.com>
---
rgmanager/src/resources/lvm_by_lv.sh | 14 ++++++++++----
rgmanager/src/resources/lvm_by_vg.sh | 4 ++--
2 files changed, 12 insertions(+), 6 deletions(-)
diff --git a/rgmanager/src/resources/lvm_by_lv.sh b/rgmanager/src/resources/lvm_by_lv.sh
index 4971173..7140076 100644
--- a/rgmanager/src/resources/lvm_by_lv.sh
+++ b/rgmanager/src/resources/lvm_by_lv.sh
@@ -243,13 +243,19 @@ lv_activate_and_tag()
# be removed from the VG via a separate call before
# the tag can be removed.
ocf_log err "Attempting volume group clean-up and retry"
- vgreduce --removemissing --force $OCF_RESKEY_vg_name
+ vgreduce --removemissing --mirrorsonly --force $OCF_RESKEY_vg_name
# Retry tag deletion
lvchange --deltag $tag $lv_path
if [ $? -ne 0 ]; then
- ocf_log err "Failed to delete tag from $lv_path"
- return $OCF_ERR_GENERIC
+ if [ "$self_fence" ]; then
+ ocf_log err "Failed to delete tag from $lv_path: REBOOTING"
+ sync
+ reboot -fn
+ else
+ ocf_log err "Failed to delete tag from $lv_path"
+ fi
+ return $OCF_ERR_GENERIC
fi
fi
@@ -322,7 +328,7 @@ lv_activate()
ocf_log notice "Attempting cleanup of $OCF_RESKEY_vg_name"
- if vgreduce --removemissing --force --config \
+ if vgreduce --removemissing --mirrorsonly --force --config \
"activation { volume_list = \"$OCF_RESKEY_vg_name\" }" \
$OCF_RESKEY_vg_name; then
ocf_log notice "$OCF_RESKEY_vg_name now consistent"
diff --git a/rgmanager/src/resources/lvm_by_vg.sh b/rgmanager/src/resources/lvm_by_vg.sh
index 0dd2aaa..819d0b8 100755
--- a/rgmanager/src/resources/lvm_by_vg.sh
+++ b/rgmanager/src/resources/lvm_by_vg.sh
@@ -202,7 +202,7 @@ function vg_start_clustered
ocf_log err "Failed to activate volume group, $OCF_RESKEY_vg_name"
ocf_log notice "Attempting cleanup of $OCF_RESKEY_vg_name"
- if ! vgreduce --removemissing --force $OCF_RESKEY_vg_name; then
+ if ! vgreduce --removemissing --mirrorsonly --force $OCF_RESKEY_vg_name; then
ocf_log err "Failed to make $OCF_RESKEY_vg_name consistent"
return $OCF_ERR_GENERIC
fi
@@ -398,7 +398,7 @@ function vg_stop_single
# Shut down the volume group
# Do we need to make this resilient?
- vgchange -an $OCF_RESKEY_vg_name
+ vgchange -aln $OCF_RESKEY_vg_name
# Make sure all the logical volumes are inactive
results=(`lvs -o name,attr --noheadings $OCF_RESKEY_vg_name 2> /dev/null`)
Gitweb: http://git.fedorahosted.org/git/?p=gfs2-utils.git;a=commitdiff;h=e8d58780c4…
Commit: e8d58780c43e0befeacab299c6d099e196bc83b9
Parent: 58a213659fb8afd5d25fa25d7ec3ec0a8d5e21dd
Author: Bob Peterson <rpeterso(a)redhat.com>
AuthorDate: Fri Apr 19 09:25:51 2013 -0700
Committer: Bob Peterson <rpeterso(a)redhat.com>
CommitterDate: Mon May 20 11:12:47 2013 -0500
fsck.gfs2: take hash table start boundaries into account
When checking the hash table in pass2, we can't just keep doubling
the length for each consecutive check because the number of pointer
copies (aka length) is also tied to the starting offset. If the
starting offset is invalid for the length, it might treat a chunk of
the hash table as bigger than it should, eventually overwriting good
entries. Along the same lines, while we're trying to determine the
length, it's not good enough to double the length and check if the
hash table entry matches. The reason is: there can be several values
overwritten with the same value, 0x00, that indicates places where
pass1 found an invalid leaf block pointer. To avoid that, we need to
check intermediate values as well, and stop if we find a gap.
---
gfs2/fsck/metawalk.c | 5 +++--
gfs2/fsck/pass2.c | 43 ++++++++++++++++++++++++++++++++++---------
2 files changed, 37 insertions(+), 11 deletions(-)
diff --git a/gfs2/fsck/metawalk.c b/gfs2/fsck/metawalk.c
index ffc3555..44b5c66 100644
--- a/gfs2/fsck/metawalk.c
+++ b/gfs2/fsck/metawalk.c
@@ -473,11 +473,12 @@ static int check_entries(struct gfs2_inode *ip, struct gfs2_buffer_head *bh,
if ((char *)dent + de.de_rec_len >= bh_end){
log_debug( _("Last entry processed for %lld->%lld "
- "(0x%llx->0x%llx).\n"),
+ "(0x%llx->0x%llx), di_blocks=%llu.\n"),
(unsigned long long)ip->i_di.di_num.no_addr,
(unsigned long long)bh->b_blocknr,
(unsigned long long)ip->i_di.di_num.no_addr,
- (unsigned long long)bh->b_blocknr);
+ (unsigned long long)bh->b_blocknr,
+ (unsigned long long)ip->i_di.di_blocks);
break;
}
diff --git a/gfs2/fsck/pass2.c b/gfs2/fsck/pass2.c
index a24edbe..3d0bb49 100644
--- a/gfs2/fsck/pass2.c
+++ b/gfs2/fsck/pass2.c
@@ -370,9 +370,10 @@ static int wrong_leaf(struct gfs2_inode *ip, struct gfs2_inum *entry,
gfs2_get_leaf_nr(ip, hash_index, &real_leaf);
if (real_leaf != planned_leaf) {
log_err(_("The planned leaf was split. The new leaf "
- "is: %llu (0x%llx)"),
+ "is: %llu (0x%llx). di_blocks=%llu\n"),
(unsigned long long)real_leaf,
- (unsigned long long)real_leaf);
+ (unsigned long long)real_leaf,
+ (unsigned long long)ip->i_di.di_blocks);
fsck_blockmap_set(ip, real_leaf, _("split leaf"),
gfs2_indir_blk);
}
@@ -1032,6 +1033,7 @@ static int basic_check_dentry(struct gfs2_inode *ip, struct gfs2_dirent *dent,
log_err( _("Bad directory entry '%s' cleared.\n"), tmp_name);
return 1;
} else {
+ (*count)++;
return 0;
}
}
@@ -1150,11 +1152,13 @@ static int fix_hashtable(struct gfs2_inode *ip, uint64_t *tbl, unsigned hsize,
/* Look at the first dirent and check its hash value to see if it's
at the proper starting offset. */
hash_index = hash_table_index(dentry.de_hash, ip);
+ /* Need to use len here, not *proper_len because the leaf block may
+ be valid within the range, but starts too soon in the hash table. */
if (hash_index < lindex || hash_index > lindex + len) {
log_err(_("This leaf block has hash index %d, which is out of "
"bounds for where it appears in the hash table "
"(%d - %d)\n"),
- hash_index, lindex, lindex + len);
+ hash_index, lindex, lindex + *proper_len);
error = lost_leaf(ip, tbl, leafblk, len, lindex, lbh);
brelse(lbh);
return error;
@@ -1291,6 +1295,8 @@ static int check_hash_tbl(struct gfs2_inode *ip, uint64_t *tbl,
struct gfs2_buffer_head *lbh;
int factor;
uint32_t proper_start;
+ uint32_t next_proper_start;
+ int anomaly;
lindex = 0;
while (lindex < hsize) {
@@ -1299,10 +1305,23 @@ static int check_hash_tbl(struct gfs2_inode *ip, uint64_t *tbl,
len = 1;
factor = 0;
leafblk = be64_to_cpu(tbl[lindex]);
+ next_proper_start = lindex;
+ anomaly = 0;
while (lindex + (len << 1) - 1 < hsize) {
if (be64_to_cpu(tbl[lindex + (len << 1) - 1]) !=
leafblk)
break;
+ next_proper_start = (lindex & ~((len << 1) - 1));
+ if (lindex != next_proper_start)
+ anomaly = 1;
+ /* Check if there are other values written between
+ here and the next factor. */
+ for (i = len; !anomaly && i + lindex < hsize &&
+ i < (len << 1); i++)
+ if (be64_to_cpu(tbl[lindex + i]) != leafblk)
+ anomaly = 1;
+ if (anomaly)
+ break;
len <<= 1;
factor++;
}
@@ -1344,8 +1363,10 @@ static int check_hash_tbl(struct gfs2_inode *ip, uint64_t *tbl,
proper_start = (lindex & ~(proper_len - 1));
if (lindex != proper_start) {
log_debug(_("lindex 0x%llx is not a proper starting "
- "point for this leaf: 0x%llx\n"),
+ "point for leaf %llu (0x%llx): 0x%llx\n"),
(unsigned long long)lindex,
+ (unsigned long long)leafblk,
+ (unsigned long long)leafblk,
(unsigned long long)proper_start);
changes = fix_hashtable(ip, tbl, hsize, leafblk,
lindex, proper_start, len,
@@ -1368,9 +1389,11 @@ static int check_hash_tbl(struct gfs2_inode *ip, uint64_t *tbl,
depth, and adjust the hash table accordingly. */
if (len != proper_len) {
log_err(_("Length %d (0x%x) is not a proper length "
- "for this leaf. Valid boundary assumed to "
- "be %d (0x%x).\n"),
- len, len, proper_len, proper_len);
+ "for leaf %llu (0x%llx). Valid boundary "
+ "assumed to be %d (0x%x).\n"), len, len,
+ (unsigned long long)leafblk,
+ (unsigned long long)leafblk,
+ proper_len, proper_len);
lbh = bread(ip->i_sbd, leafblk);
gfs2_leaf_in(&leaf, lbh);
if (gfs2_check_meta(lbh, GFS2_METATYPE_LF) ||
@@ -1419,8 +1442,10 @@ static int check_hash_tbl(struct gfs2_inode *ip, uint64_t *tbl,
proper_len = 1 << (ip->i_di.di_depth - leaf.lf_depth);
if (proper_len != len) {
log_debug(_("Length 0x%x is not proper for "
- "this leaf: 0x%x"),
- len, proper_len);
+ "leaf %llu (0x%llx): 0x%x"),
+ len, (unsigned long long)leafblk,
+ (unsigned long long)leafblk,
+ proper_len);
changes = fix_hashtable(ip, tbl, hsize,
leafblk, lindex,
lindex, len,
Gitweb: http://git.fedorahosted.org/git/?p=gfs2-utils.git;a=commitdiff;h=58a213659f…
Commit: 58a213659fb8afd5d25fa25d7ec3ec0a8d5e21dd
Parent: c2a39034d9f2888dc0a9431cea86998a929c30ba
Author: Bob Peterson <rpeterso(a)redhat.com>
AuthorDate: Wed Apr 17 14:09:30 2013 -0700
Committer: Bob Peterson <rpeterso(a)redhat.com>
CommitterDate: Mon May 20 11:12:47 2013 -0500
fsck.gfs2: Don't allocate leaf blocks in pass1
Before this patch, if leaf blocks were found to be corrupt, pass1
tried to fix them by allocating new leaf blocks in place of the bad
ones. That's a bad idea, because pass1 populates the blockmap and
sets the bitmap accordingly. In other words, it's dynamically changing.
Say, for example, that you're checking a directory a dinode 0x1234, and
it has a corrupt hash table, and needs new leaf blocks inserted.
Now suppose you have a second directory that occurs later in the bitmap,
say at block 0x2345, and it references leaf block 0x2346, but for some
reason that block (0x2346) is improperly set to "free" in the bitmap.
If pass1 goes out looking for a free block in order to allocate a new
leaf for 0x1234, it will naturally find block 0x2346, because it's
marked free. It writes a new leaf at that block and adds a new
reference in the hash table of 0x1234. Later, when pass1 processes
directory 0x2345, it discovers the reference to 0x2346. Not only has
it wiped out the perfectly good leaf block, it has also created a
duplicate block reference that it needs to sort out in pass1b, which
will likely keep the replaced reference and throw the good one we
had. Thus, we introduced corruption into the file system when we
should have kept the only good reference to 0x2346 and fixed the
bitmap.
The solution provided by this patch is to simply zero out the bad
hash table entries when pass1 comes across them. Later, when pass2
discovers the zero leaf blocks, it can safely allocate new blocks
(since pass1 synced the bitmap according to the blockmap) for the new
leaf blocks and replace the zeros with valid block references.
---
gfs2/fsck/metawalk.c | 31 ++++++++++++++++++++++++++++++-
gfs2/fsck/metawalk.h | 2 +-
gfs2/fsck/pass1.c | 9 ++-------
gfs2/fsck/pass2.c | 2 +-
4 files changed, 34 insertions(+), 10 deletions(-)
diff --git a/gfs2/fsck/metawalk.c b/gfs2/fsck/metawalk.c
index 161c183..ffc3555 100644
--- a/gfs2/fsck/metawalk.c
+++ b/gfs2/fsck/metawalk.c
@@ -1955,7 +1955,7 @@ int write_new_leaf(struct gfs2_inode *dip, int start_lindex, int num_copies,
* leaf a bit, but it's better than deleting the whole directory,
* which is what used to happen before. */
int repair_leaf(struct gfs2_inode *ip, uint64_t *leaf_no, int lindex,
- int ref_count, const char *msg)
+ int ref_count, const char *msg, int allow_alloc)
{
int new_leaf_blks = 0, error, refs;
uint64_t bn = 0;
@@ -1970,6 +1970,35 @@ int repair_leaf(struct gfs2_inode *ip, uint64_t *leaf_no, int lindex,
log_err( _("Bad leaf left in place.\n"));
goto out;
}
+ if (!allow_alloc) {
+ uint64_t *cpyptr;
+ char *padbuf;
+ int pad_size, i;
+
+ padbuf = malloc(ref_count * sizeof(uint64_t));
+ cpyptr = (uint64_t *)padbuf;
+ for (i = 0; i < ref_count; i++) {
+ *cpyptr = 0;
+ cpyptr++;
+ }
+ pad_size = ref_count * sizeof(uint64_t);
+ log_err(_("Writing zeros to the hash table of directory %lld "
+ "(0x%llx) at index: 0x%x for 0x%x pointers.\n"),
+ (unsigned long long)ip->i_di.di_num.no_addr,
+ (unsigned long long)ip->i_di.di_num.no_addr,
+ lindex, ref_count);
+ if (ip->i_sbd->gfs1)
+ gfs1_writei(ip, padbuf, lindex * sizeof(uint64_t),
+ pad_size);
+ else
+ gfs2_writei(ip, padbuf, lindex * sizeof(uint64_t),
+ pad_size);
+ free(padbuf);
+ log_err( _("Directory Inode %llu (0x%llx) patched.\n"),
+ (unsigned long long)ip->i_di.di_num.no_addr,
+ (unsigned long long)ip->i_di.di_num.no_addr);
+ goto out;
+ }
/* We can only write leafs in quantities that are factors of
two, since leaves are doubled, not added sequentially.
So if we have a hole that's not a factor of 2, we have to
diff --git a/gfs2/fsck/metawalk.h b/gfs2/fsck/metawalk.h
index aacb962..a5a51c2 100644
--- a/gfs2/fsck/metawalk.h
+++ b/gfs2/fsck/metawalk.h
@@ -61,7 +61,7 @@ extern int write_new_leaf(struct gfs2_inode *dip, int start_lindex,
int num_copies, const char *before_or_after,
uint64_t *bn);
extern int repair_leaf(struct gfs2_inode *ip, uint64_t *leaf_no, int lindex,
- int ref_count, const char *msg);
+ int ref_count, const char *msg, int allow_alloc);
#define is_duplicate(dblock) ((dupfind(dblock)) ? 1 : 0)
diff --git a/gfs2/fsck/pass1.c b/gfs2/fsck/pass1.c
index 2c1c046..df778ef 100644
--- a/gfs2/fsck/pass1.c
+++ b/gfs2/fsck/pass1.c
@@ -84,13 +84,8 @@ static int pass1_repair_leaf(struct gfs2_inode *ip, uint64_t *leaf_no,
int lindex, int ref_count, const char *msg,
void *private)
{
- struct block_count *bc = (struct block_count *)private;
- int new_leaf_blks;
-
- new_leaf_blks = repair_leaf(ip, leaf_no, lindex, ref_count, msg);
- bc->indir_count += new_leaf_blks;
-
- return new_leaf_blks;
+ repair_leaf(ip, leaf_no, lindex, ref_count, msg, 0);
+ return 0;
}
struct metawalk_fxns pass1_fxns = {
diff --git a/gfs2/fsck/pass2.c b/gfs2/fsck/pass2.c
index 5767c4d..a24edbe 100644
--- a/gfs2/fsck/pass2.c
+++ b/gfs2/fsck/pass2.c
@@ -1040,7 +1040,7 @@ 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);
+ return repair_leaf(ip, leaf_no, lindex, ref_count, msg, 1);
}
/* The purpose of leafck_fxns is to provide a means for function fix_hashtable
Gitweb: http://git.fedorahosted.org/git/?p=gfs2-utils.git;a=commitdiff;h=fb2ef82d8d…
Commit: fb2ef82d8dd9b4c5304d377b9d2fa1ad3da1a82c
Parent: a3c643a9c98dd68138ff6b623fd86923a16fc626
Author: Bob Peterson <rpeterso(a)redhat.com>
AuthorDate: Thu Apr 11 07:22:33 2013 -0700
Committer: Bob Peterson <rpeterso(a)redhat.com>
CommitterDate: Mon May 20 11:12:47 2013 -0500
fsck.gfs2: double-check transitions from dinode to data
If a corrupt dinode references a bunch of blocks as data blocks,
and those blocks occur later in the bitmap (as is usually the case)
but they're really dinodes, we have a problem. Before it finds the
corruption, it can change the bitmap markings from 'dinode' to 'data'
blocks. Later, when it determines the dinode is corrupt. It tries
to "undo" all those data blocks, but since pass1 hasn't processed
them yet, it marks them as 'free' in the bitmap, and we've lost the
fact that they're dinodes. The result is that the files/dinodes
being improperly referenced are deleted by mistake.
This patch adds a check for bitmap transitions in pass1 from 'dinode'
to 'data', where the block hasn't been checked yet. We don't care about
transitions from dinode to free because that's a normal delete of a
dinode. We also don't care about transitions between dinode to
metadata, because all those checks validate that the metadata type is
the correct type of metadata, so we know we're making the right
decision. So the only issue are data blocks referencing dinodes.
What this patch does is: when the bitmap is making a transition from
'dinode' to 'data' in pass1, it basically puts up a red flag.
The block is read in and checked to see if it really looks like a
dinode. We have to be careful here, because customer data is allowed
to look like a dinode. If the block really seems to be a dinode, we
DO NOT want to treat it as a data block and assume the duplicate
reference handler in pass1b will handle it, because the dinode's
metadata blocks will not have been checked in pass1.
Instead, we want to flag it as corruption in the referencing file
dinode, not change the bitmap or blockmap, and allow pass1 to treat
it properly as a dinode when it gets there. The corrupt dinode
referencing the dinode as 'data' should be deleted and the work done
thusfar should be backed out by the pass1 'undo' functions.
---
gfs2/fsck/metawalk.c | 21 +++++++++++++---
gfs2/fsck/metawalk.h | 14 +++++++----
gfs2/fsck/pass1.c | 65 +++++++++++++++++++++++++++++++++++++++++++++----
gfs2/fsck/pass1b.c | 2 +-
gfs2/fsck/pass2.c | 2 +-
gfs2/fsck/pass3.c | 4 +-
6 files changed, 89 insertions(+), 19 deletions(-)
diff --git a/gfs2/fsck/metawalk.c b/gfs2/fsck/metawalk.c
index 22b16ee..6e9e593 100644
--- a/gfs2/fsck/metawalk.c
+++ b/gfs2/fsck/metawalk.c
@@ -27,7 +27,7 @@
is used to set the latter. The two must be kept in sync, otherwise
you'll get bitmap mismatches. This function checks the status of the
bitmap whenever the blockmap changes, and fixes it accordingly. */
-int check_n_fix_bitmap(struct gfs2_sbd *sdp, uint64_t blk,
+int check_n_fix_bitmap(struct gfs2_sbd *sdp, uint64_t blk, int error_on_dinode,
enum gfs2_mark_block new_blockmap_state)
{
int old_bitmap_state, new_bitmap_state;
@@ -49,6 +49,16 @@ int check_n_fix_bitmap(struct gfs2_sbd *sdp, uint64_t blk,
/* gfs1 descriptions: */
{"free", "data", "free meta", "metadata", "reserved"}};
+ if (error_on_dinode && old_bitmap_state == GFS2_BLKST_DINODE &&
+ new_bitmap_state != GFS2_BLKST_FREE) {
+ log_debug(_("Reference as '%s' to block %llu (0x%llx) "
+ "which was marked as dinode. Needs "
+ "further investigation.\n"),
+ allocdesc[sdp->gfs1][new_bitmap_state],
+ (unsigned long long)blk,
+ (unsigned long long)blk);
+ return 1;
+ }
/* Keep these messages as short as possible, or the output
gets to be huge and unmanageable. */
log_err( _("Block %llu (0x%llx) was '%s', should be %s.\n"),
@@ -106,6 +116,7 @@ int check_n_fix_bitmap(struct gfs2_sbd *sdp, uint64_t blk,
*/
int _fsck_blockmap_set(struct gfs2_inode *ip, uint64_t bblock,
const char *btype, enum gfs2_mark_block mark,
+ int error_on_dinode,
const char *caller, int fline)
{
int error;
@@ -164,9 +175,11 @@ int _fsck_blockmap_set(struct gfs2_inode *ip, uint64_t bblock,
/* First, check the rgrp bitmap against what we think it should be.
If that fails, it's an invalid block--part of an rgrp. */
- error = check_n_fix_bitmap(ip->i_sbd, bblock, mark);
+ error = check_n_fix_bitmap(ip->i_sbd, bblock, error_on_dinode, mark);
if (error) {
- log_err( _("This block is not represented in the bitmap.\n"));
+ if (error < 0)
+ log_err( _("This block is not represented in the "
+ "bitmap.\n"));
return error;
}
@@ -517,7 +530,7 @@ int check_leaf(struct gfs2_inode *ip, int lindex, struct metawalk_fxns *pass,
if (pass->check_leaf) {
error = pass->check_leaf(ip, *leaf_no, pass->private);
- if (error) {
+ if (error == -EEXIST) {
log_info(_("Previous reference to leaf %lld (0x%llx) "
"has already checked it; skipping.\n"),
(unsigned long long)*leaf_no,
diff --git a/gfs2/fsck/metawalk.h b/gfs2/fsck/metawalk.h
index 56f57d9..aacb962 100644
--- a/gfs2/fsck/metawalk.h
+++ b/gfs2/fsck/metawalk.h
@@ -45,10 +45,12 @@ extern int delete_eattr_extentry(struct gfs2_inode *ip, uint64_t *ea_data_ptr,
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);
+ const char *btype, enum gfs2_mark_block mark,
+ int error_on_dinode,
+ const char *caller, int line);
extern int check_n_fix_bitmap(struct gfs2_sbd *sdp, uint64_t blk,
- enum gfs2_mark_block new_blockmap_state);
+ int error_on_dinode,
+ enum gfs2_mark_block new_blockmap_state);
extern void reprocess_inode(struct gfs2_inode *ip, const char *desc);
extern struct duptree *dupfind(uint64_t block);
extern struct gfs2_inode *fsck_system_inode(struct gfs2_sbd *sdp,
@@ -63,8 +65,10 @@ extern int repair_leaf(struct gfs2_inode *ip, uint64_t *leaf_no, int lindex,
#define is_duplicate(dblock) ((dupfind(dblock)) ? 1 : 0)
-#define fsck_blockmap_set(ip, b, bt, m) _fsck_blockmap_set(ip, b, bt, m, \
- __FUNCTION__, __LINE__)
+#define fsck_blockmap_set(ip, b, bt, m) \
+ _fsck_blockmap_set(ip, b, bt, m, 0, __FUNCTION__, __LINE__)
+#define fsck_blkmap_set_noino(ip, b, bt, m) \
+ _fsck_blockmap_set(ip, b, bt, m, 1, __FUNCTION__, __LINE__)
enum meta_check_rc {
meta_error = -1,
diff --git a/gfs2/fsck/pass1.c b/gfs2/fsck/pass1.c
index ad6690b..ee828d8 100644
--- a/gfs2/fsck/pass1.c
+++ b/gfs2/fsck/pass1.c
@@ -150,7 +150,7 @@ static int resuscitate_metalist(struct gfs2_inode *ip, uint64_t block,
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);
+ check_n_fix_bitmap(ip->i_sbd, block, 0, gfs2_indir_blk);
bc->indir_count++;
return meta_is_good;
}
@@ -204,7 +204,7 @@ static int resuscitate_dentry(struct gfs2_inode *ip, struct gfs2_dirent *dent,
if (fsck_system_inode(sdp, block))
fsck_blockmap_set(ip, block, _("system file"), dinode_type);
else
- check_n_fix_bitmap(sdp, block, dinode_type);
+ check_n_fix_bitmap(sdp, block, 0, dinode_type);
/* 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);
@@ -339,6 +339,8 @@ static int undo_reference(struct gfs2_inode *ip, uint64_t block, int meta,
struct block_count *bc = (struct block_count *)private;
struct duptree *dt;
struct inode_with_dups *id;
+ int old_bitmap_state = 0;
+ struct rgrp_tree *rgd;
if (!valid_block(ip->i_sbd, block)) { /* blk outside of FS */
fsck_blockmap_set(ip, ip->i_di.di_num.no_addr,
@@ -367,6 +369,12 @@ static int undo_reference(struct gfs2_inode *ip, uint64_t block, int meta,
return 1;
}
}
+ if (!meta) {
+ rgd = gfs2_blk2rgrpd(ip->i_sbd, block);
+ old_bitmap_state = lgfs2_get_bitmap(ip->i_sbd, block, rgd);
+ if (old_bitmap_state == GFS2_BLKST_DINODE)
+ return -1;
+ }
fsck_blockmap_set(ip, block,
meta ? _("bad indirect") : _("referenced data"),
gfs2_block_free);
@@ -385,6 +393,51 @@ static int undo_check_data(struct gfs2_inode *ip, uint64_t block,
return undo_reference(ip, block, 0, private);
}
+/* blockmap_set_as_data - set block as 'data' in the blockmap, if not dinode
+ *
+ * This function tries to set a block that's referenced as data as 'data'
+ * in the fsck blockmap. But if that block is marked as 'dinode' in the
+ * rgrp bitmap, it does additional checks to see if it looks like a dinode.
+ * Note that previous checks were done for duplicate references, so this
+ * is checking for dinodes that we haven't processed yet.
+ */
+static int blockmap_set_as_data(struct gfs2_inode *ip, uint64_t block)
+{
+ int error;
+ struct gfs2_buffer_head *bh;
+ struct gfs2_dinode *di;
+
+ error = fsck_blkmap_set_noino(ip, block, _("data"), gfs2_block_used);
+ if (!error)
+ return 0;
+
+ error = 0;
+ /* The bitmap says it's a dinode, but a block reference begs to differ.
+ So which is it? */
+ bh = bread(ip->i_sbd, block);
+ if (gfs2_check_meta(bh, GFS2_METATYPE_DI) != 0)
+ goto out;
+
+ /* The meta header agrees it's a dinode. But it might be data in
+ disguise, so do some extra checks. */
+ di = (struct gfs2_dinode *)bh->b_data;
+ if (be64_to_cpu(di->di_num.no_addr) != block)
+ goto out;
+
+ log_err(_("Inode %lld (0x%llx) has a reference to block %lld (0x%llx) "
+ "as a data block, but it appears to be a dinode we "
+ "haven't checked yet.\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);
+ error = -1;
+out:
+ if (!error)
+ fsck_blockmap_set(ip, block, _("data"), gfs2_block_used);
+ brelse(bh);
+ return error;
+}
+
static int check_data(struct gfs2_inode *ip, uint64_t metablock,
uint64_t block, void *private)
{
@@ -469,7 +522,7 @@ static int check_data(struct gfs2_inode *ip, uint64_t metablock,
(unsigned long long)block, (unsigned long long)block);
fsck_blockmap_set(ip, block, _("jdata"), gfs2_jdata);
} else
- fsck_blockmap_set(ip, block, _("data"), gfs2_block_used);
+ return blockmap_set_as_data(ip, block);
return 0;
}
@@ -1199,7 +1252,7 @@ static int check_system_inode(struct gfs2_sbd *sdp,
(unsigned long long)iblock,
(unsigned long long)iblock);
gfs2_blockmap_set(bl, iblock, gfs2_block_free);
- check_n_fix_bitmap(sdp, iblock, gfs2_block_free);
+ check_n_fix_bitmap(sdp, iblock, 0, gfs2_block_free);
inode_put(sysinode);
}
}
@@ -1486,7 +1539,7 @@ 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);
- check_n_fix_bitmap(sdp, block, gfs2_block_free);
+ check_n_fix_bitmap(sdp, block, 0, gfs2_block_free);
} else if (handle_di(sdp, bh) < 0) {
stack;
brelse(bh);
@@ -1596,7 +1649,7 @@ int pass1(struct gfs2_sbd *sdp)
}
/* rgrps and bitmaps don't have bits to represent
their blocks, so don't do this:
- check_n_fix_bitmap(sdp, rgd->ri.ri_addr + i,
+ check_n_fix_bitmap(sdp, rgd->ri.ri_addr + i, 0,
gfs2_meta_rgrp);*/
}
diff --git a/gfs2/fsck/pass1b.c b/gfs2/fsck/pass1b.c
index 9c76eda..9a23197 100644
--- a/gfs2/fsck/pass1b.c
+++ b/gfs2/fsck/pass1b.c
@@ -501,7 +501,7 @@ static int handle_dup_blk(struct gfs2_sbd *sdp, struct duptree *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);
+ check_n_fix_bitmap(sdp, dup_blk, 0, gfs2_block_free);
}
}
return 0;
diff --git a/gfs2/fsck/pass2.c b/gfs2/fsck/pass2.c
index dc99869..5767c4d 100644
--- a/gfs2/fsck/pass2.c
+++ b/gfs2/fsck/pass2.c
@@ -1713,7 +1713,7 @@ int pass2(struct gfs2_sbd *sdp)
/* Can't use fsck_blockmap_set here because we don't
have an inode in memory. */
gfs2_blockmap_set(bl, dirblk, gfs2_inode_invalid);
- check_n_fix_bitmap(sdp, dirblk, gfs2_inode_invalid);
+ check_n_fix_bitmap(sdp, dirblk, 0, gfs2_inode_invalid);
}
ip = fsck_load_inode(sdp, dirblk);
if (!ds.dotdir) {
diff --git a/gfs2/fsck/pass3.c b/gfs2/fsck/pass3.c
index 53052b6..4894d8c 100644
--- a/gfs2/fsck/pass3.c
+++ b/gfs2/fsck/pass3.c
@@ -275,7 +275,7 @@ int pass3(struct gfs2_sbd *sdp)
gfs2_blockmap_set(bl, di->dinode.no_addr,
gfs2_block_free);
check_n_fix_bitmap(sdp, di->dinode.no_addr,
- gfs2_block_free);
+ 0, gfs2_block_free);
break;
} else
log_err( _("Unlinked directory with bad block remains\n"));
@@ -299,7 +299,7 @@ int pass3(struct gfs2_sbd *sdp)
because we don't have ip */
gfs2_blockmap_set(bl, di->dinode.no_addr,
gfs2_block_free);
- check_n_fix_bitmap(sdp, di->dinode.no_addr,
+ check_n_fix_bitmap(sdp, di->dinode.no_addr, 0,
gfs2_block_free);
log_err( _("The block was cleared\n"));
break;
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;