FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Redhat > Cluster Development

 
 
LinkBack Thread Tools
 
Old 08-25-2011, 04:58 PM
Bob Peterson
 
Default libgfs2: Make rebuild functions not re-read ip

>From c93beb4367027f52979297dafae5728093f6a5d6 Mon Sep 17 00:00:00 2001
From: Bob Peterson <rpeterso@redhat.com>
Date: Fri, 19 Aug 2011 15:57:03 -0500
Subject: [PATCH 48/56] libgfs2: Make rebuild functions not re-read ip

Before this patch, the libgfs2 rebuild functions in structures.c
were not consistent about reading in the gfs2_inode in-core struct.
Some of the functions did and some didn't. The previous patch to
make fsck.gfs2 operate on gfs1 introduced a problem because the code
was changed to re-read the inum and statfs files if they were rebuilt.
But since the functions already did the read, it was a double-read.
A double-read is a bad thing because inode writes are now done on
the last inode put, and the double-read messed up the counter.
(Number of inode gets should match puts). This patch makes all the
build functions consistent: they all put the inode after building,
except for root and master which have no parent inodes.

There was also a minor problem whereby leaf searches were getting
the number of entries from the directory buffer rather than from
the dinode itself. (The buffer may be out of date, but the dinode
should always be current). So there were circumstances where you
could add a new dirent to "master" but the count of entries was not
correct in the buffer, which caused the search to stop prematurely.

rhbz#675723
---
gfs2/convert/gfs2_convert.c | 3 +++
gfs2/fsck/initialize.c | 7 ++++++-
gfs2/libgfs2/fs_ops.c | 10 +++++-----
gfs2/libgfs2/structures.c | 4 ++--
gfs2/mkfs/main_mkfs.c | 2 ++
5 files changed, 18 insertions(+), 8 deletions(-)

diff --git a/gfs2/convert/gfs2_convert.c b/gfs2/convert/gfs2_convert.c
index c255874..bef2ccd 100644
--- a/gfs2/convert/gfs2_convert.c
+++ b/gfs2/convert/gfs2_convert.c
@@ -2246,6 +2246,7 @@ int main(int argc, char **argv)
strerror(error));
exit(-1);
}
+ gfs2_lookupi(sb2.master_dir, "inum", 4, &sb2.md.inum);
/* Create the statfs file */
error = build_statfs(&sb2); /* Does not do inode_put */
if (error) {
@@ -2253,6 +2254,8 @@ int main(int argc, char **argv)
strerror(error));
exit(-1);
}
+ gfs2_lookupi(sb2.master_dir, "statfs", 6, &sb2.md.statfs);
+ do_init_statfs(&sb2);

/* Create the resource group index file */
error = build_rindex(&sb2);
diff --git a/gfs2/fsck/initialize.c b/gfs2/fsck/initialize.c
index e2b1e63..8910103 100644
--- a/gfs2/fsck/initialize.c
+++ b/gfs2/fsck/initialize.c
@@ -422,13 +422,14 @@ static int rebuild_master(struct gfs2_sbd *sdp)
strerror(err));
exit(-1);
}
+ gfs2_lookupi(sdp->master_dir, "inum", 4, &sdp->md.inum);
}

if (fix_md.statfs) {
inum.no_formal_ino = sdp->md.next_inum++;
inum.no_addr = fix_md.statfs->i_di.di_num.no_addr;
err = dir_add(sdp->master_dir, "statfs", 6, &inum,
- IF2DT(S_IFREG | 0600));
+ IF2DT(S_IFREG | 0600));
if (err) {
log_crit(_("Error adding statfs inode: %s
"), strerror(err));
exit(-1);
@@ -440,6 +441,7 @@ static int rebuild_master(struct gfs2_sbd *sdp)
strerror(err));
exit(-1);
}
+ gfs2_lookupi(sdp->master_dir, "statfs", 6, &sdp->md.statfs);
}

if (fix_md.riinode) {
@@ -479,6 +481,8 @@ static int rebuild_master(struct gfs2_sbd *sdp)
}

log_err(_("Master directory rebuilt.
"));
+ inode_put(&sdp->md.inum);
+ inode_put(&sdp->md.statfs);
inode_put(&sdp->master_dir);
return 0;
}
@@ -704,6 +708,7 @@ static int init_system_inodes(struct gfs2_sbd *sdp)
"a valid statfs file; aborting.
"));
goto fail;
}
+ do_init_statfs(sdp);
}
buf = malloc(sdp->md.statfs->i_di.di_size);
// FIXME: handle failed malloc
diff --git a/gfs2/libgfs2/fs_ops.c b/gfs2/libgfs2/fs_ops.c
index 629729d..84cd895 100644
--- a/gfs2/libgfs2/fs_ops.c
+++ b/gfs2/libgfs2/fs_ops.c
@@ -1246,6 +1246,7 @@ static int dir_l_add(struct gfs2_inode *dip, const char *filename, int len,
dent->de_hash = cpu_to_be32(dent->de_hash);
dent->de_type = cpu_to_be16(type);
memcpy((char *)(dent + 1), filename, len);
+ bmodified(dip->i_bh);
return err;
}

@@ -1448,10 +1449,9 @@ static int leaf_search(struct gfs2_inode *dip, struct gfs2_buffer_head *bh,
if (type == IS_LEAF){
struct gfs2_leaf *leaf = (struct gfs2_leaf *)bh->b_data;
entries = be16_to_cpu(leaf->lf_entries);
- } else if (type == IS_DINODE) {
- struct gfs2_dinode *dinode = (struct gfs2_dinode *)bh->b_data;
- entries = be32_to_cpu(dinode->di_entries);
- } else
+ } else if (type == IS_DINODE)
+ entries = dip->i_di.di_entries;
+ else
return -1;

hash = gfs2_disk_hash(filename, len);
@@ -1464,7 +1464,7 @@ static int leaf_search(struct gfs2_inode *dip, struct gfs2_buffer_head *bh,

if (be32_to_cpu(dent->de_hash) == hash &&
gfs2_filecmp(filename, (char *)(dent + 1),
- be16_to_cpu(dent->de_name_len))){
+ be16_to_cpu(dent->de_name_len))) {
*dent_out = dent;
if (dent_prev)
*dent_prev = prev;
diff --git a/gfs2/libgfs2/structures.c b/gfs2/libgfs2/structures.c
index e8a8c65..7f21ad6 100644
--- a/gfs2/libgfs2/structures.c
+++ b/gfs2/libgfs2/structures.c
@@ -318,7 +318,7 @@ int build_inum(struct gfs2_sbd *sdp)
gfs2_dinode_print(&ip->i_di);
}

- sdp->md.inum = ip;
+ inode_put(&ip);
return 0;
}

@@ -337,7 +337,7 @@ int build_statfs(struct gfs2_sbd *sdp)
gfs2_dinode_print(&ip->i_di);
}

- sdp->md.statfs = ip;
+ inode_put(&ip);
return 0;
}

diff --git a/gfs2/mkfs/main_mkfs.c b/gfs2/mkfs/main_mkfs.c
index 0da3bc5..d841daa 100644
--- a/gfs2/mkfs/main_mkfs.c
+++ b/gfs2/mkfs/main_mkfs.c
@@ -652,11 +652,13 @@ void main_mkfs(int argc, char *argv[])
fprintf(stderr, _("Error building inum inode: %s
"), strerror(error));
exit(-1);
}
+ gfs2_lookupi(sdp->master_dir, "inum", 4, &sdp->md.inum);
error = build_statfs(sdp);
if (error) {
fprintf(stderr, _("Error building statfs inode: %s
"), strerror(error));
exit(-1);
}
+ gfs2_lookupi(sdp->master_dir, "statfs", 6, &sdp->md.statfs);
error = build_rindex(sdp);
if (error) {
fprintf(stderr, _("Error building rindex inode: %s
"), strerror(error));
--
1.7.4.4
 
Old 01-20-2012, 02:10 PM
 
Default libgfs2: Make rebuild functions not re-read ip

From: Bob Peterson <rpeterso@redhat.com>

Before this patch, the libgfs2 rebuild functions in structures.c
were not consistent about reading in the gfs2_inode in-core struct.
Some of the functions did and some didn't. The previous patch to
make fsck.gfs2 operate on gfs1 introduced a problem because the code
was changed to re-read the inum and statfs files if they were rebuilt.
But since the functions already did the read, it was a double-read.
A double-read is a bad thing because inode writes are now done on
the last inode put, and the double-read messed up the counter.
(Number of inode gets should match puts). This patch makes all the
build functions consistent: they all put the inode after building,
except for root and master which have no parent inodes.

There was also a minor problem whereby leaf searches were getting
the number of entries from the directory buffer rather than from
the dinode itself. (The buffer may be out of date, but the dinode
should always be current). So there were circumstances where you
could add a new dirent to "master" but the count of entries was not
correct in the buffer, which caused the search to stop prematurely.

rhbz#675723
---
gfs2/convert/gfs2_convert.c | 3 +++
gfs2/fsck/initialize.c | 5 +++++
gfs2/libgfs2/fs_ops.c | 10 +++++-----
gfs2/libgfs2/structures.c | 4 ++--
gfs2/mkfs/main_mkfs.c | 2 ++
5 files changed, 17 insertions(+), 7 deletions(-)

diff --git a/gfs2/convert/gfs2_convert.c b/gfs2/convert/gfs2_convert.c
index 9cc3258..43d0093 100644
--- a/gfs2/convert/gfs2_convert.c
+++ b/gfs2/convert/gfs2_convert.c
@@ -2158,9 +2158,12 @@ int main(int argc, char **argv)
build_per_node(&sb2);
/* Create the empty inode number file */
build_inum(&sb2); /* Does not do inode_put */
+ gfs2_lookupi(sb2.master_dir, "inum", 4, &sb2.md.inum);
/* Create the statfs file */
build_statfs(&sb2); /* Does not do inode_put */

+ gfs2_lookupi(sb2.master_dir, "statfs", 6, &sb2.md.statfs);
+ do_init_statfs(&sb2);
/* Create the resource group index file */
build_rindex(&sb2);
/* Create the quota file */
diff --git a/gfs2/fsck/initialize.c b/gfs2/fsck/initialize.c
index cee1f49..75b363b 100644
--- a/gfs2/fsck/initialize.c
+++ b/gfs2/fsck/initialize.c
@@ -392,6 +392,7 @@ static int rebuild_master(struct gfs2_sbd *sdp)
IF2DT(S_IFREG | 0600));
} else {
build_inum(sdp);
+ gfs2_lookupi(sdp->master_dir, "inum", 4, &sdp->md.inum);
}

if (fix_md.statfs) {
@@ -401,6 +402,7 @@ static int rebuild_master(struct gfs2_sbd *sdp)
IF2DT(S_IFREG | 0600));
} else {
build_statfs(sdp);
+ gfs2_lookupi(sdp->master_dir, "statfs", 6, &sdp->md.statfs);
}

if (fix_md.riinode) {
@@ -422,6 +424,8 @@ static int rebuild_master(struct gfs2_sbd *sdp)
}

log_err(_("Master directory rebuilt.
"));
+ inode_put(&sdp->md.inum);
+ inode_put(&sdp->md.statfs);
inode_put(&sdp->master_dir);
return 0;
}
@@ -635,6 +639,7 @@ static int init_system_inodes(struct gfs2_sbd *sdp)
"a valid statfs file; aborting.
"));
goto fail;
}
+ do_init_statfs(sdp);
}
buf = malloc(sdp->md.statfs->i_di.di_size);
// FIXME: handle failed malloc
diff --git a/gfs2/libgfs2/fs_ops.c b/gfs2/libgfs2/fs_ops.c
index e99cc2a..0163371 100644
--- a/gfs2/libgfs2/fs_ops.c
+++ b/gfs2/libgfs2/fs_ops.c
@@ -1243,6 +1243,7 @@ static void dir_l_add(struct gfs2_inode *dip, const char *filename, int len,
dent->de_hash = cpu_to_be32(dent->de_hash);
dent->de_type = cpu_to_be16(type);
memcpy((char *)(dent + 1), filename, len);
+ bmodified(dip->i_bh);
}

void dir_add(struct gfs2_inode *dip, const char *filename, int len,
@@ -1437,10 +1438,9 @@ static int leaf_search(struct gfs2_inode *dip, struct gfs2_buffer_head *bh,
if (type == IS_LEAF){
struct gfs2_leaf *leaf = (struct gfs2_leaf *)bh->b_data;
entries = be16_to_cpu(leaf->lf_entries);
- } else if (type == IS_DINODE) {
- struct gfs2_dinode *dinode = (struct gfs2_dinode *)bh->b_data;
- entries = be32_to_cpu(dinode->di_entries);
- } else
+ } else if (type == IS_DINODE)
+ entries = dip->i_di.di_entries;
+ else
return -1;

hash = gfs2_disk_hash(filename, len);
@@ -1453,7 +1453,7 @@ static int leaf_search(struct gfs2_inode *dip, struct gfs2_buffer_head *bh,

if (be32_to_cpu(dent->de_hash) == hash &&
gfs2_filecmp(filename, (char *)(dent + 1),
- be16_to_cpu(dent->de_name_len))){
+ be16_to_cpu(dent->de_name_len))) {
*dent_out = dent;
if (dent_prev)
*dent_prev = prev;
diff --git a/gfs2/libgfs2/structures.c b/gfs2/libgfs2/structures.c
index f53b4af..b998f2d 100644
--- a/gfs2/libgfs2/structures.c
+++ b/gfs2/libgfs2/structures.c
@@ -284,7 +284,7 @@ int build_inum(struct gfs2_sbd *sdp)
gfs2_dinode_print(&ip->i_di);
}

- sdp->md.inum = ip;
+ inode_put(&ip);
return 0;
}

@@ -300,7 +300,7 @@ int build_statfs(struct gfs2_sbd *sdp)
gfs2_dinode_print(&ip->i_di);
}

- sdp->md.statfs = ip;
+ inode_put(&ip);
return 0;
}

diff --git a/gfs2/mkfs/main_mkfs.c b/gfs2/mkfs/main_mkfs.c
index 3db3b14..ee2a5da 100644
--- a/gfs2/mkfs/main_mkfs.c
+++ b/gfs2/mkfs/main_mkfs.c
@@ -650,7 +650,9 @@ void main_mkfs(int argc, char *argv[])
build_jindex(sdp);
build_per_node(sdp);
build_inum(sdp);
+ gfs2_lookupi(sdp->master_dir, "inum", 4, &sdp->md.inum);
build_statfs(sdp);
+ gfs2_lookupi(sdp->master_dir, "statfs", 6, &sdp->md.statfs);
build_rindex(sdp);
build_quota(sdp);

--
1.7.7.5
 

Thread Tools




All times are GMT. The time now is 11:29 AM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org