gfs2-utils: master - gfs2_edit savemeta: save_inode_data backward for gfs1
by Bob Peterson
Gitweb: http://git.fedorahosted.org/git/gfs2-utils.git?p=gfs2-utils.git;a=commitd...
Commit: 3acf36d2b12572711ba83fea6fde7f7b7ffe8242
Parent: 7c7d17231dfbaf05e2c3eeec4a0d936d08c1de83
Author: Bob Peterson <rpeterso(a)redhat.com>
AuthorDate: Wed Aug 10 15:30:25 2011 -0500
Committer: Bob Peterson <rpeterso(a)redhat.com>
CommitterDate: Mon Aug 29 12:54:42 2011 -0500
gfs2_edit savemeta: save_inode_data backward for gfs1
The logic in "gfs2_edit savemeta" was wrong for saving inode blocks.
This patch fixes the logic.
rhbz#675723
---
gfs2/edit/savemeta.c | 8 ++++----
1 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/gfs2/edit/savemeta.c b/gfs2/edit/savemeta.c
index 081ad23..3423eae 100644
--- a/gfs2/edit/savemeta.c
+++ b/gfs2/edit/savemeta.c
@@ -123,9 +123,9 @@ static int get_gfs_struct_info(struct gfs2_buffer_head *lbh, int *block_type,
break;
case GFS2_METATYPE_DI: /* 4 (disk inode) */
if (sbd.gfs1)
- inode = inode_get(&sbd, lbh);
- else
inode = gfs_inode_get(&sbd, lbh);
+ else
+ inode = inode_get(&sbd, lbh);
if (S_ISDIR(inode->i_di.di_mode) ||
(sbd.gfs1 && inode->i_di.__pad1 == GFS_FILE_DIR))
*gstruct_len = sbd.bsize;
@@ -457,9 +457,9 @@ static void save_inode_data(struct metafd *mfd)
osi_list_init(&metalist[i]);
metabh = bread(&sbd, block);
if (sbd.gfs1)
- inode = inode_get(&sbd, metabh);
- else
inode = gfs_inode_get(&sbd, metabh);
+ else
+ inode = inode_get(&sbd, metabh);
height = inode->i_di.di_height;
/* If this is a user inode, we don't follow to the file height.
We stop one level less. That way we save off the indirect
12 years, 8 months
gfs2-utils: master - libgfs2: move gfs1 functions from edit to libgfs2
by Bob Peterson
Gitweb: http://git.fedorahosted.org/git/gfs2-utils.git?p=gfs2-utils.git;a=commitd...
Commit: 7c7d17231dfbaf05e2c3eeec4a0d936d08c1de83
Parent: cc7aa2adda675024936d49a28b847d63c9ac36b7
Author: Bob Peterson <rpeterso(a)redhat.com>
AuthorDate: Wed Aug 10 15:27:10 2011 -0500
Committer: Bob Peterson <rpeterso(a)redhat.com>
CommitterDate: Mon Aug 29 12:54:42 2011 -0500
libgfs2: move gfs1 functions from edit to libgfs2
This patch moves some gfs1-specific functions from gfs2_edit to
libgfs2 so that other utils can eventually operate on gfs1 file
systems.
rhbz#675723
---
gfs2/edit/hexedit.c | 47 -------------------------------------------
gfs2/edit/hexedit.h | 1 -
gfs2/libgfs2/gfs1.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++
gfs2/libgfs2/libgfs2.h | 3 ++
4 files changed, 55 insertions(+), 48 deletions(-)
diff --git a/gfs2/edit/hexedit.c b/gfs2/edit/hexedit.c
index 6f4c614..7d966a6 100644
--- a/gfs2/edit/hexedit.c
+++ b/gfs2/edit/hexedit.c
@@ -1500,40 +1500,6 @@ static uint64_t find_rgrp_block(struct gfs2_inode *dif, int rg)
}
/* ------------------------------------------------------------------------ */
-/* gfs_rgrp_in - Read in a resource group header */
-/* ------------------------------------------------------------------------ */
-void gfs_rgrp_in(struct gfs_rgrp *rgrp, struct gfs2_buffer_head *rbh)
-{
- struct gfs_rgrp *str = (struct gfs_rgrp *)rbh->b_data;
-
- gfs2_meta_header_in(&rgrp->rg_header, rbh);
- rgrp->rg_flags = be32_to_cpu(str->rg_flags);
- rgrp->rg_free = be32_to_cpu(str->rg_free);
- rgrp->rg_useddi = be32_to_cpu(str->rg_useddi);
- rgrp->rg_freedi = be32_to_cpu(str->rg_freedi);
- gfs2_inum_in(&rgrp->rg_freedi_list, (char *)&str->rg_freedi_list);
- rgrp->rg_usedmeta = be32_to_cpu(str->rg_usedmeta);
- rgrp->rg_freemeta = be32_to_cpu(str->rg_freemeta);
-}
-
-/* ------------------------------------------------------------------------ */
-/* gfs_rgrp_out */
-/* ------------------------------------------------------------------------ */
-static void gfs_rgrp_out(struct gfs_rgrp *rgrp, struct gfs2_buffer_head *rbh)
-{
- struct gfs_rgrp *str = (struct gfs_rgrp *)rbh->b_data;
-
- gfs2_meta_header_out(&rgrp->rg_header, rbh);
- str->rg_flags = cpu_to_be32(rgrp->rg_flags);
- str->rg_free = cpu_to_be32(rgrp->rg_free);
- str->rg_useddi = cpu_to_be32(rgrp->rg_useddi);
- str->rg_freedi = cpu_to_be32(rgrp->rg_freedi);
- gfs2_inum_out(&rgrp->rg_freedi_list, (char *)&str->rg_freedi_list);
- str->rg_usedmeta = cpu_to_be32(rgrp->rg_usedmeta);
- str->rg_freemeta = cpu_to_be32(rgrp->rg_freemeta);
-}
-
-/* ------------------------------------------------------------------------ */
/* gfs_rgrp_print - print a gfs1 resource group */
/* ------------------------------------------------------------------------ */
void gfs_rgrp_print(struct gfs_rgrp *rg)
@@ -1624,19 +1590,6 @@ static void set_rgrp_flags(int rgnum, uint32_t new_flags, int modify, int full)
}
/* ------------------------------------------------------------------------ */
-/* gfs_jindex_in - read in a gfs1 jindex structure. */
-/* ------------------------------------------------------------------------ */
-void gfs_jindex_in(struct gfs_jindex *jindex, char *jbuf)
-{
- struct gfs_jindex *str = (struct gfs_jindex *) jbuf;
-
- jindex->ji_addr = be64_to_cpu(str->ji_addr);
- jindex->ji_nsegment = be32_to_cpu(str->ji_nsegment);
- jindex->ji_pad = be32_to_cpu(str->ji_pad);
- memcpy(jindex->ji_reserved, str->ji_reserved, 64);
-}
-
-/* ------------------------------------------------------------------------ */
/* has_indirect_blocks */
/* ------------------------------------------------------------------------ */
int has_indirect_blocks(void)
diff --git a/gfs2/edit/hexedit.h b/gfs2/edit/hexedit.h
index f7b539e..07125bd 100644
--- a/gfs2/edit/hexedit.h
+++ b/gfs2/edit/hexedit.h
@@ -221,7 +221,6 @@ extern int display(int identify_only);
extern uint64_t check_keywords(const char *kword);
extern uint64_t masterblock(const char *fn);
extern void gfs_rgrp_print(struct gfs_rgrp *rg);
-extern void gfs_rgrp_in(struct gfs_rgrp *rgrp, struct gfs2_buffer_head *rbh);
extern int has_indirect_blocks(void);
#endif /* __HEXVIEW_DOT_H__ */
diff --git a/gfs2/libgfs2/gfs1.c b/gfs2/libgfs2/gfs1.c
index c807e80..394cc47 100644
--- a/gfs2/libgfs2/gfs1.c
+++ b/gfs2/libgfs2/gfs1.c
@@ -251,3 +251,55 @@ struct gfs2_inode *gfs_inode_read(struct gfs2_sbd *sdp, uint64_t di_addr)
{
return __gfs_inode_get(sdp, NULL, di_addr);
}
+
+/* ------------------------------------------------------------------------ */
+/* gfs_jindex_in - read in a gfs1 jindex structure. */
+/* ------------------------------------------------------------------------ */
+void gfs_jindex_in(struct gfs_jindex *jindex, char *jbuf)
+{
+ struct gfs_jindex *str = (struct gfs_jindex *) jbuf;
+
+ jindex->ji_addr = be64_to_cpu(str->ji_addr);
+ jindex->ji_nsegment = be32_to_cpu(str->ji_nsegment);
+ jindex->ji_pad = be32_to_cpu(str->ji_pad);
+ memcpy(jindex->ji_reserved, str->ji_reserved, 64);
+}
+
+/* ------------------------------------------------------------------------ */
+/* gfs_rgrp_in - Read in a resource group header */
+/* ------------------------------------------------------------------------ */
+void gfs_rgrp_in(struct gfs_rgrp *rgrp, struct gfs2_buffer_head *rbh)
+{
+ struct gfs_rgrp *str = (struct gfs_rgrp *)rbh->b_data;
+
+ gfs2_meta_header_in(&rgrp->rg_header, rbh);
+ rgrp->rg_flags = be32_to_cpu(str->rg_flags);
+ rgrp->rg_free = be32_to_cpu(str->rg_free);
+ rgrp->rg_useddi = be32_to_cpu(str->rg_useddi);
+ rgrp->rg_freedi = be32_to_cpu(str->rg_freedi);
+ gfs2_inum_in(&rgrp->rg_freedi_list, (char *)&str->rg_freedi_list);
+ rgrp->rg_usedmeta = be32_to_cpu(str->rg_usedmeta);
+ rgrp->rg_freemeta = be32_to_cpu(str->rg_freemeta);
+
+ memcpy(rgrp->rg_reserved, str->rg_reserved, 64);
+}
+
+/* ------------------------------------------------------------------------ */
+/* gfs_rgrp_out */
+/* ------------------------------------------------------------------------ */
+void gfs_rgrp_out(struct gfs_rgrp *rgrp, struct gfs2_buffer_head *rbh)
+{
+ struct gfs_rgrp *str = (struct gfs_rgrp *)rbh->b_data;
+
+ gfs2_meta_header_out(&rgrp->rg_header, rbh);
+ str->rg_flags = cpu_to_be32(rgrp->rg_flags);
+ str->rg_free = cpu_to_be32(rgrp->rg_free);
+ str->rg_useddi = cpu_to_be32(rgrp->rg_useddi);
+ str->rg_freedi = cpu_to_be32(rgrp->rg_freedi);
+ gfs2_inum_out(&rgrp->rg_freedi_list, (char *)&str->rg_freedi_list);
+ str->rg_usedmeta = cpu_to_be32(rgrp->rg_usedmeta);
+ str->rg_freemeta = cpu_to_be32(rgrp->rg_freemeta);
+
+ memcpy(str->rg_reserved, rgrp->rg_reserved, 64);
+ bmodified(rbh);
+}
diff --git a/gfs2/libgfs2/libgfs2.h b/gfs2/libgfs2/libgfs2.h
index 34b5cd5..c92781a 100644
--- a/gfs2/libgfs2/libgfs2.h
+++ b/gfs2/libgfs2/libgfs2.h
@@ -593,6 +593,9 @@ extern struct gfs2_inode *gfs_inode_get(struct gfs2_sbd *sdp,
struct gfs2_buffer_head *bh);
extern struct gfs2_inode *gfs_inode_read(struct gfs2_sbd *sdp,
uint64_t di_addr);
+extern void gfs_jindex_in(struct gfs_jindex *jindex, char *buf);
+extern void gfs_rgrp_in(struct gfs_rgrp *rg, struct gfs2_buffer_head *bh);
+extern void gfs_rgrp_out(struct gfs_rgrp *rg, struct gfs2_buffer_head *bh);
/* gfs2_log.c */
struct gfs2_options {
12 years, 8 months
gfs2-utils: master - libgfs2: combine gfs_inode_read and gfs_inode_get
by Bob Peterson
Gitweb: http://git.fedorahosted.org/git/gfs2-utils.git?p=gfs2-utils.git;a=commitd...
Commit: cc7aa2adda675024936d49a28b847d63c9ac36b7
Parent: 2fb06422de032da67fb1133e96898b6fed11c3d9
Author: Bob Peterson <rpeterso(a)redhat.com>
AuthorDate: Wed Aug 10 14:49:35 2011 -0500
Committer: Bob Peterson <rpeterso(a)redhat.com>
CommitterDate: Mon Aug 29 12:54:42 2011 -0500
libgfs2: combine gfs_inode_read and gfs_inode_get
Functions gfs_inode_read and gfs_inode_get were nearly identical.
They did the same exact thing, but one operated on a buffer passed in
while the other read the buffer from the media. This patch combines
the two into a common function and two replacement stubs.
rhbz#675723
---
gfs2/libgfs2/gfs1.c | 57 +++++++++++++-------------------------------------
1 files changed, 15 insertions(+), 42 deletions(-)
diff --git a/gfs2/libgfs2/gfs1.c b/gfs2/libgfs2/gfs1.c
index 91d3641..c807e80 100644
--- a/gfs2/libgfs2/gfs1.c
+++ b/gfs2/libgfs2/gfs1.c
@@ -193,8 +193,9 @@ static void gfs_dinode_in(struct gfs_dinode *di, struct gfs2_buffer_head *bh)
di->di_eattr = be64_to_cpu(str->di_eattr);
}
-struct gfs2_inode *gfs_inode_get(struct gfs2_sbd *sdp,
- struct gfs2_buffer_head *bh)
+static struct gfs2_inode *__gfs_inode_get(struct gfs2_sbd *sdp,
+ struct gfs2_buffer_head *bh,
+ uint64_t di_addr)
{
struct gfs_dinode gfs1_dinode;
struct gfs2_inode *ip;
@@ -205,6 +206,11 @@ struct gfs2_inode *gfs_inode_get(struct gfs2_sbd *sdp,
exit(-1);
}
+ ip->bh_owned = 0;
+ if (!bh) {
+ bh = bread(sdp, di_addr);
+ ip->bh_owned = 1;
+ }
gfs_dinode_in(&gfs1_dinode, bh);
memcpy(&ip->i_di.di_header, &gfs1_dinode.di_header,
sizeof(struct gfs2_meta_header));
@@ -232,49 +238,16 @@ struct gfs2_inode *gfs_inode_get(struct gfs2_sbd *sdp,
ip->i_di.di_eattr = gfs1_dinode.di_eattr;
ip->i_bh = bh;
ip->i_sbd = sdp;
- ip->bh_owned = 0;
return ip;
}
-struct gfs2_inode *gfs_inode_read(struct gfs2_sbd *sdp, uint64_t di_addr)
+struct gfs2_inode *gfs_inode_get(struct gfs2_sbd *sdp,
+ struct gfs2_buffer_head *bh)
{
- struct gfs_dinode gfs1_dinode;
- struct gfs2_inode *ip;
-
- ip = calloc(1, sizeof(struct gfs2_inode));
- if (ip == NULL) {
- fprintf(stderr, "Out of memory in %s\n", __FUNCTION__);
- exit(-1);
- }
-
- ip->i_bh = bread(sdp, di_addr);
- gfs_dinode_in(&gfs1_dinode, ip->i_bh);
- memcpy(&ip->i_di.di_header, &gfs1_dinode.di_header,
- sizeof(struct gfs2_meta_header));
- memcpy(&ip->i_di.di_num, &gfs1_dinode.di_num,
- sizeof(struct gfs2_inum));
- ip->i_di.di_mode = gfs1_dinode.di_mode;
- ip->i_di.di_uid = gfs1_dinode.di_uid;
- ip->i_di.di_gid = gfs1_dinode.di_gid;
- ip->i_di.di_nlink = gfs1_dinode.di_nlink;
- ip->i_di.di_size = gfs1_dinode.di_size;
- ip->i_di.di_blocks = gfs1_dinode.di_blocks;
- ip->i_di.di_atime = gfs1_dinode.di_atime;
- ip->i_di.di_mtime = gfs1_dinode.di_mtime;
- ip->i_di.di_ctime = gfs1_dinode.di_ctime;
- ip->i_di.di_major = gfs1_dinode.di_major;
- ip->i_di.di_minor = gfs1_dinode.di_minor;
- ip->i_di.di_goal_data = gfs1_dinode.di_goal_dblk;
- ip->i_di.di_goal_meta = gfs1_dinode.di_goal_mblk;
- ip->i_di.di_flags = gfs1_dinode.di_flags;
- ip->i_di.di_payload_format = gfs1_dinode.di_payload_format;
- ip->i_di.__pad1 = gfs1_dinode.di_type;
- ip->i_di.di_height = gfs1_dinode.di_height;
- ip->i_di.di_depth = gfs1_dinode.di_depth;
- ip->i_di.di_entries = gfs1_dinode.di_entries;
- ip->i_di.di_eattr = gfs1_dinode.di_eattr;
- ip->i_sbd = sdp;
- ip->bh_owned = 1;
- return ip;
+ return __gfs_inode_get(sdp, bh, 0);
}
+struct gfs2_inode *gfs_inode_read(struct gfs2_sbd *sdp, uint64_t di_addr)
+{
+ return __gfs_inode_get(sdp, NULL, di_addr);
+}
12 years, 8 months
gfs2-utils: master - libgfs2: combine ri_update and gfs1_ri_update
by Bob Peterson
Gitweb: http://git.fedorahosted.org/git/gfs2-utils.git?p=gfs2-utils.git;a=commitd...
Commit: 2fb06422de032da67fb1133e96898b6fed11c3d9
Parent: 75bc339ca91b5114303ea95e4353a872b0d349dd
Author: Bob Peterson <rpeterso(a)redhat.com>
AuthorDate: Wed Aug 10 14:20:11 2011 -0500
Committer: Bob Peterson <rpeterso(a)redhat.com>
CommitterDate: Mon Aug 29 12:54:42 2011 -0500
libgfs2: combine ri_update and gfs1_ri_update
Since gfs1_ri_update is nearly identical to ri_update, I decided to
combine the main logic into a common function. That simplifies the
code and if one gets fixed, they both get fixed automatically.
rhbz#675723
---
gfs2/libgfs2/gfs1.c | 49 -------------------------------------------------
gfs2/libgfs2/super.c | 33 ++++++++++++++++++++++++++++++---
2 files changed, 30 insertions(+), 52 deletions(-)
diff --git a/gfs2/libgfs2/gfs1.c b/gfs2/libgfs2/gfs1.c
index a0a6c6c..91d3641 100644
--- a/gfs2/libgfs2/gfs1.c
+++ b/gfs2/libgfs2/gfs1.c
@@ -161,55 +161,6 @@ void gfs1_block_map(struct gfs2_inode *ip, uint64_t lblock, int *new,
free(mp);
}
-/**
- * gfs1_ri_update - attach rgrps to the super block
- * Stolen from libgfs2/super.c, but modified to handle gfs1.
- * @sdp:
- *
- * Given the rgrp index inode, link in all rgrps into the super block
- * and be sure that they can be read.
- *
- * Returns: 0 on success, -1 on failure.
- */
-int gfs1_ri_update(struct gfs2_sbd *sdp, int fd, int *rgcount, int quiet)
-{
- struct rgrp_list *rgd;
- struct gfs2_rindex *ri;
- osi_list_t *tmp;
- int count1 = 0, count2 = 0;
- uint64_t errblock = 0;
- uint64_t rmax = 0;
- int sane;
-
- if (rindex_read(sdp, fd, &count1, &sane))
- goto fail;
- for (tmp = sdp->rglist.next; tmp != &sdp->rglist; tmp = tmp->next) {
- rgd = osi_list_entry(tmp, struct rgrp_list, list);
- errblock = gfs2_rgrp_read(sdp, rgd);
- if (errblock)
- return errblock;
- count2++;
- if (!quiet && count2 % 100 == 0) {
- printf(".");
- fflush(stdout);
- }
- ri = &rgd->ri;
- if (ri->ri_data0 + ri->ri_data - 1 > rmax)
- rmax = ri->ri_data0 + ri->ri_data - 1;
- }
-
- sdp->fssize = rmax;
- *rgcount = count1;
- if (count1 != count2)
- goto fail;
-
- return 0;
-
- fail:
- gfs2_rgrp_free(&sdp->rglist);
- return -1;
-}
-
/* ------------------------------------------------------------------------ */
/* gfs_dinode_in */
/* ------------------------------------------------------------------------ */
diff --git a/gfs2/libgfs2/super.c b/gfs2/libgfs2/super.c
index 693e547..277daf8 100644
--- a/gfs2/libgfs2/super.c
+++ b/gfs2/libgfs2/super.c
@@ -225,7 +225,8 @@ int rindex_read(struct gfs2_sbd *sdp, int fd, int *count1, int *sane)
*
* Returns: 0 on success, -1 on failure.
*/
-int ri_update(struct gfs2_sbd *sdp, int fd, int *rgcount, int *sane)
+static int __ri_update(struct gfs2_sbd *sdp, int fd, int *rgcount, int *sane,
+ int quiet)
{
struct rgrp_list *rgd;
struct gfs2_rindex *ri;
@@ -235,16 +236,20 @@ int ri_update(struct gfs2_sbd *sdp, int fd, int *rgcount, int *sane)
uint64_t rmax = 0;
if (rindex_read(sdp, fd, &count1, sane))
- goto fail;
+ goto fail;
for (tmp = sdp->rglist.next; tmp != &sdp->rglist; tmp = tmp->next) {
rgd = osi_list_entry(tmp, struct rgrp_list, list);
errblock = gfs2_rgrp_read(sdp, rgd);
if (errblock)
return errblock;
+ count2++;
+ if (!quiet && count2 % 100 == 0) {
+ printf(".");
+ fflush(stdout);
+ }
ri = &rgd->ri;
if (ri->ri_data0 + ri->ri_data - 1 > rmax)
rmax = ri->ri_data0 + ri->ri_data - 1;
- count2++;
}
sdp->fssize = rmax;
@@ -259,6 +264,28 @@ int ri_update(struct gfs2_sbd *sdp, int fd, int *rgcount, int *sane)
return -1;
}
+int ri_update(struct gfs2_sbd *sdp, int fd, int *rgcount, int *sane)
+{
+ return __ri_update(sdp, fd, rgcount, sane, 1);
+}
+
+/**
+ * gfs1_ri_update - attach rgrps to the super block
+ * Stolen from libgfs2/super.c, but modified to handle gfs1.
+ * @sdp:
+ *
+ * Given the rgrp index inode, link in all rgrps into the super block
+ * and be sure that they can be read.
+ *
+ * Returns: 0 on success, -1 on failure.
+ */
+int gfs1_ri_update(struct gfs2_sbd *sdp, int fd, int *rgcount, int quiet)
+{
+ int sane;
+
+ return __ri_update(sdp, fd, rgcount, &sane, quiet);
+}
+
int write_sb(struct gfs2_sbd *sbp)
{
struct gfs2_buffer_head *bh;
12 years, 8 months
gfs2-utils: master - libgfs2: eliminate gfs1_rindex_read
by Bob Peterson
Gitweb: http://git.fedorahosted.org/git/gfs2-utils.git?p=gfs2-utils.git;a=commitd...
Commit: 75bc339ca91b5114303ea95e4353a872b0d349dd
Parent: 164a681c8bff1be33f7524b394e6211477db8f85
Author: Bob Peterson <rpeterso(a)redhat.com>
AuthorDate: Wed Aug 10 14:07:45 2011 -0500
Committer: Bob Peterson <rpeterso(a)redhat.com>
CommitterDate: Mon Aug 29 12:54:42 2011 -0500
libgfs2: eliminate gfs1_rindex_read
Now that function rindex_read is able to handle gfs1 file reading,
this patch eliminates the gfs1-specific function gfs1_rindex_read.
rhbz#675723
---
gfs2/edit/hexedit.c | 13 +++-------
gfs2/libgfs2/gfs1.c | 62 +-------------------------------------------------
2 files changed, 6 insertions(+), 69 deletions(-)
diff --git a/gfs2/edit/hexedit.c b/gfs2/edit/hexedit.c
index 49971ef..6f4c614 100644
--- a/gfs2/edit/hexedit.c
+++ b/gfs2/edit/hexedit.c
@@ -1758,7 +1758,7 @@ static int block_has_extended_info(void)
/* ------------------------------------------------------------------------ */
static void read_superblock(int fd)
{
- int count;
+ int count, sane;
sbd1 = (struct gfs_sb *)&sbd.sd_sb;
ioctl(fd, BLKFLSBUF, 0);
@@ -1810,11 +1810,7 @@ static void read_superblock(int fd)
sbd.sd_diptrs = (sbd.bsize - sizeof(struct gfs_dinode)) /
sizeof(uint64_t);
sbd.md.riinode = inode_read(&sbd, sbd1->sb_rindex_di.no_addr);
- sbd.fssize = sbd.device.length;
- gfs1_rindex_read(&sbd, 0, &count);
} else {
- int sane;
-
sbd.sd_inptrs = (sbd.bsize - sizeof(struct gfs2_meta_header)) /
sizeof(uint64_t);
sbd.sd_diptrs = (sbd.bsize - sizeof(struct gfs2_dinode)) /
@@ -1822,11 +1818,10 @@ static void read_superblock(int fd)
sbd.master_dir = inode_read(&sbd,
sbd.sd_sb.sb_master_dir.no_addr);
gfs2_lookupi(sbd.master_dir, "rindex", 6, &sbd.md.riinode);
- sbd.fssize = sbd.device.length;
- if (sbd.md.riinode) /* If we found the rindex */
- rindex_read(&sbd, 0, &count, &sane);
}
-
+ sbd.fssize = sbd.device.length;
+ if (sbd.md.riinode) /* If we found the rindex */
+ rindex_read(&sbd, 0, &count, &sane);
}
/* ------------------------------------------------------------------------ */
diff --git a/gfs2/libgfs2/gfs1.c b/gfs2/libgfs2/gfs1.c
index 5304b56..a0a6c6c 100644
--- a/gfs2/libgfs2/gfs1.c
+++ b/gfs2/libgfs2/gfs1.c
@@ -162,65 +162,6 @@ void gfs1_block_map(struct gfs2_inode *ip, uint64_t lblock, int *new,
}
/**
- * gfs1_rindex_read - read in the rg index file
- * Stolen from libgfs2/super.c, but modified to handle gfs1.
- * @sdp: the incore superblock pointer
- * fd: optional file handle for rindex file (if meta_fs file system is mounted)
- * (if fd is <= zero, it will read from raw device)
- * @count1: return count of the rgs.
- *
- * Returns: 0 on success, -1 on failure
- */
-int gfs1_rindex_read(struct gfs2_sbd *sdp, int fd, int *count1)
-{
- unsigned int rg;
- int error;
- struct gfs2_rindex buf;
- struct rgrp_list *rgd, *prev_rgd;
- uint64_t prev_length = 0;
-
- *count1 = 0;
- prev_rgd = NULL;
- for (rg = 0; ; rg++) {
- if (fd > 0)
- error = read(fd, &buf, sizeof(struct gfs2_rindex));
- else
- error = gfs2_readi(sdp->md.riinode, (char *)&buf,
- (rg * sizeof(struct gfs2_rindex)),
- sizeof(struct gfs2_rindex));
- if (!error)
- break;
- if (error != sizeof(struct gfs2_rindex))
- return -1;
-
- rgd = (struct rgrp_list *)malloc(sizeof(struct rgrp_list));
- if (!rgd) {
- log_crit("Cannot allocate memory for rindex.\n");
- exit(-1);
- }
- memset(rgd, 0, sizeof(struct rgrp_list));
- osi_list_add_prev(&rgd->list, &sdp->rglist);
-
- gfs2_rindex_in(&rgd->ri, (char *)&buf);
-
- rgd->start = rgd->ri.ri_addr;
- if (prev_rgd) {
- prev_length = rgd->start - prev_rgd->start;
- prev_rgd->length = prev_length;
- }
-
- if(gfs2_compute_bitstructs(sdp, rgd))
- return -1;
-
- (*count1)++;
- prev_rgd = rgd;
- }
- if (prev_rgd)
- prev_rgd->length = prev_length;
- return 0;
-}
-
-/**
* gfs1_ri_update - attach rgrps to the super block
* Stolen from libgfs2/super.c, but modified to handle gfs1.
* @sdp:
@@ -238,8 +179,9 @@ int gfs1_ri_update(struct gfs2_sbd *sdp, int fd, int *rgcount, int quiet)
int count1 = 0, count2 = 0;
uint64_t errblock = 0;
uint64_t rmax = 0;
+ int sane;
- if (gfs1_rindex_read(sdp, fd, &count1))
+ if (rindex_read(sdp, fd, &count1, &sane))
goto fail;
for (tmp = sdp->rglist.next; tmp != &sdp->rglist; tmp = tmp->next) {
rgd = osi_list_entry(tmp, struct rgrp_list, list);
12 years, 8 months
gfs2-utils: master - libgfs2: move block_map functions to fsck.gfs2
by Bob Peterson
Gitweb: http://git.fedorahosted.org/git/gfs2-utils.git?p=gfs2-utils.git;a=commitd...
Commit: 164a681c8bff1be33f7524b394e6211477db8f85
Parent: d9cb12d1372ef5d62ad09509886ad8fcd29a0dd6
Author: Bob Peterson <rpeterso(a)redhat.com>
AuthorDate: Wed Aug 10 13:12:54 2011 -0500
Committer: Bob Peterson <rpeterso(a)redhat.com>
CommitterDate: Mon Aug 29 12:54:42 2011 -0500
libgfs2: move block_map functions to fsck.gfs2
Since the "blockmap" functions were only used in fsck.gfs2 they don't
have a place in libgfs2. This patch moves them to fsck.gfs2.
rhbz#675723
---
gfs2/fsck/metawalk.h | 2 +
gfs2/fsck/util.c | 72 ++++++++++++++++++++++++++++++++++++++
gfs2/fsck/util.h | 84 +++++++++++++++++++++++++++++++++++++++++++++
gfs2/libgfs2/block_list.c | 72 --------------------------------------
gfs2/libgfs2/libgfs2.h | 82 -------------------------------------------
5 files changed, 158 insertions(+), 154 deletions(-)
diff --git a/gfs2/fsck/metawalk.h b/gfs2/fsck/metawalk.h
index 719bbd9..e114427 100644
--- a/gfs2/fsck/metawalk.h
+++ b/gfs2/fsck/metawalk.h
@@ -4,6 +4,8 @@
#define DIR_LINEAR 1
#define DIR_EXHASH 2
+#include "util.h"
+
struct metawalk_fxns;
extern int check_inode_eattr(struct gfs2_inode *ip,
diff --git a/gfs2/fsck/util.c b/gfs2/fsck/util.c
index ab0a79f..f6dd292 100644
--- a/gfs2/fsck/util.c
+++ b/gfs2/fsck/util.c
@@ -383,3 +383,75 @@ void dirtree_delete(struct dir_info *b)
osi_erase(&b->node, &dirtree);
free(b);
}
+
+static int gfs2_blockmap_create(struct gfs2_bmap *bmap, uint64_t size)
+{
+ bmap->size = size;
+
+ /* Have to add 1 to BLOCKMAP_SIZE since it's 0-based and mallocs
+ * must be 1-based */
+ bmap->mapsize = BLOCKMAP_SIZE4(size);
+
+ if (!(bmap->map = malloc(sizeof(char) * bmap->mapsize)))
+ return -ENOMEM;
+ if (!memset(bmap->map, 0, sizeof(char) * bmap->mapsize)) {
+ free(bmap->map);
+ bmap->map = NULL;
+ return -ENOMEM;
+ }
+ return 0;
+}
+
+static void gfs2_blockmap_destroy(struct gfs2_bmap *bmap)
+{
+ if (bmap->map)
+ free(bmap->map);
+ bmap->size = 0;
+ bmap->mapsize = 0;
+}
+
+struct gfs2_bmap *gfs2_bmap_create(struct gfs2_sbd *sdp, uint64_t size,
+ uint64_t *addl_mem_needed)
+{
+ struct gfs2_bmap *il;
+
+ *addl_mem_needed = 0L;
+ il = malloc(sizeof(*il));
+ if (!il || !memset(il, 0, sizeof(*il)))
+ return NULL;
+
+ if (gfs2_blockmap_create(il, size)) {
+ *addl_mem_needed = il->mapsize;
+ free(il);
+ il = NULL;
+ }
+ osi_list_init(&sdp->eattr_blocks.list);
+ return il;
+}
+
+int gfs2_blockmap_set(struct gfs2_bmap *bmap, uint64_t bblock,
+ enum gfs2_mark_block mark)
+{
+ static unsigned char *byte;
+ static uint64_t b;
+
+ if (bblock > bmap->size)
+ return -1;
+
+ byte = bmap->map + BLOCKMAP_SIZE4(bblock);
+ b = BLOCKMAP_BYTE_OFFSET4(bblock);
+ *byte &= ~(BLOCKMAP_MASK4 << b);
+ *byte |= (mark & BLOCKMAP_MASK4) << b;
+ return 0;
+}
+
+void *gfs2_bmap_destroy(struct gfs2_sbd *sdp, struct gfs2_bmap *il)
+{
+ if (il) {
+ gfs2_blockmap_destroy(il);
+ free(il);
+ il = NULL;
+ }
+ gfs2_special_free(&sdp->eattr_blocks);
+ return il;
+}
diff --git a/gfs2/fsck/util.h b/gfs2/fsck/util.h
index 56b83fe..b26c123 100644
--- a/gfs2/fsck/util.h
+++ b/gfs2/fsck/util.h
@@ -33,4 +33,88 @@ static inline uint8_t block_type(uint64_t bblock)
return btype;
}
+/* blockmap declarations and functions */
+enum gfs2_mark_block {
+ gfs2_block_free = (0x0),
+ gfs2_block_used = (0x1),
+ gfs2_indir_blk = (0x2),
+ gfs2_inode_dir = (0x3),
+ gfs2_inode_file = (0x4),
+
+ gfs2_inode_lnk = (0x5),
+ gfs2_inode_blk = (0x6),
+ gfs2_inode_chr = (0x7),
+ gfs2_inode_fifo = (0x8),
+ gfs2_inode_sock = (0x9),
+
+ gfs2_inode_invalid = (0xa),
+ gfs2_meta_inval = (0xb),
+ gfs2_leaf_blk = (0xc),
+ gfs2_meta_rgrp = (0xd),
+ gfs2_meta_eattr = (0xe),
+
+ gfs2_bad_block = (0xf), /* Contains at least one bad block */
+};
+
+static const inline char *block_type_string(uint8_t q)
+{
+ const char *blktyp[] = {
+ "free",
+ "data",
+ "indirect data",
+ "directory",
+ "file",
+
+ "symlink",
+ "block device",
+ "char device",
+ "fifo",
+ "socket",
+
+ "invalid inode",
+ "invalid meta",
+ "dir leaf",
+ "rgrp meta",
+ "eattribute",
+
+ "bad"};
+ if (q < 16)
+ return (blktyp[q]);
+ return blktyp[15];
+}
+
+/* Must be kept in sync with gfs2_mark_block enum above. Blocks marked as
+ invalid or bad are considered metadata until actually freed. */
+static inline int blockmap_to_bitmap(enum gfs2_mark_block m)
+{
+ static int bitmap_states[16] = {
+ GFS2_BLKST_FREE,
+ GFS2_BLKST_USED,
+ GFS2_BLKST_USED,
+ GFS2_BLKST_DINODE,
+ GFS2_BLKST_DINODE,
+
+ GFS2_BLKST_DINODE,
+ GFS2_BLKST_DINODE,
+ GFS2_BLKST_DINODE,
+ GFS2_BLKST_DINODE,
+ GFS2_BLKST_DINODE,
+
+ GFS2_BLKST_FREE,
+ GFS2_BLKST_FREE,
+ GFS2_BLKST_USED,
+ GFS2_BLKST_USED,
+ GFS2_BLKST_USED,
+
+ GFS2_BLKST_USED
+ };
+ return bitmap_states[m];
+}
+
+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);
+extern int gfs2_blockmap_set(struct gfs2_bmap *il, uint64_t block,
+ enum gfs2_mark_block mark);
+
#endif /* __UTIL_H__ */
diff --git a/gfs2/libgfs2/block_list.c b/gfs2/libgfs2/block_list.c
index 9c5ad3b..4fb7f4b 100644
--- a/gfs2/libgfs2/block_list.c
+++ b/gfs2/libgfs2/block_list.c
@@ -10,51 +10,6 @@
#include "libgfs2.h"
-static int gfs2_blockmap_create(struct gfs2_bmap *bmap, uint64_t size)
-{
- bmap->size = size;
-
- /* Have to add 1 to BLOCKMAP_SIZE since it's 0-based and mallocs
- * must be 1-based */
- bmap->mapsize = BLOCKMAP_SIZE4(size);
-
- if(!(bmap->map = malloc(sizeof(char) * bmap->mapsize)))
- return -ENOMEM;
- if(!memset(bmap->map, 0, sizeof(char) * bmap->mapsize)) {
- free(bmap->map);
- bmap->map = NULL;
- return -ENOMEM;
- }
- return 0;
-}
-
-static void gfs2_blockmap_destroy(struct gfs2_bmap *bmap)
-{
- if(bmap->map)
- free(bmap->map);
- bmap->size = 0;
- bmap->mapsize = 0;
-}
-
-struct gfs2_bmap *gfs2_bmap_create(struct gfs2_sbd *sdp, uint64_t size,
- uint64_t *addl_mem_needed)
-{
- struct gfs2_bmap *il;
-
- *addl_mem_needed = 0L;
- il = malloc(sizeof(*il));
- if (!il || !memset(il, 0, sizeof(*il)))
- return NULL;
-
- if(gfs2_blockmap_create(il, size)) {
- *addl_mem_needed = il->mapsize;
- free(il);
- il = NULL;
- }
- osi_list_init(&sdp->eattr_blocks.list);
- return il;
-}
-
void gfs2_special_free(struct special_blocks *blist)
{
struct special_blocks *f;
@@ -110,30 +65,3 @@ void gfs2_special_clear(struct special_blocks *blocklist, uint64_t block)
free(b);
}
}
-
-int gfs2_blockmap_set(struct gfs2_bmap *bmap, uint64_t bblock,
- enum gfs2_mark_block mark)
-{
- static unsigned char *byte;
- static uint64_t b;
-
- if(bblock > bmap->size)
- return -1;
-
- byte = bmap->map + BLOCKMAP_SIZE4(bblock);
- b = BLOCKMAP_BYTE_OFFSET4(bblock);
- *byte &= ~(BLOCKMAP_MASK4 << b);
- *byte |= (mark & BLOCKMAP_MASK4) << b;
- return 0;
-}
-
-void *gfs2_bmap_destroy(struct gfs2_sbd *sdp, struct gfs2_bmap *il)
-{
- if(il) {
- gfs2_blockmap_destroy(il);
- free(il);
- il = NULL;
- }
- gfs2_special_free(&sdp->eattr_blocks);
- return il;
-}
diff --git a/gfs2/libgfs2/libgfs2.h b/gfs2/libgfs2/libgfs2.h
index 0ac5f3d..34b5cd5 100644
--- a/gfs2/libgfs2/libgfs2.h
+++ b/gfs2/libgfs2/libgfs2.h
@@ -277,94 +277,12 @@ struct gfs2_bmap {
/* block_list.c */
-enum gfs2_mark_block {
- gfs2_block_free = (0x0),
- gfs2_block_used = (0x1),
- gfs2_indir_blk = (0x2),
- gfs2_inode_dir = (0x3),
- gfs2_inode_file = (0x4),
-
- gfs2_inode_lnk = (0x5),
- gfs2_inode_blk = (0x6),
- gfs2_inode_chr = (0x7),
- gfs2_inode_fifo = (0x8),
- gfs2_inode_sock = (0x9),
-
- gfs2_inode_invalid = (0xa),
- gfs2_meta_inval = (0xb),
- gfs2_leaf_blk = (0xc),
- gfs2_meta_rgrp = (0xd),
- gfs2_meta_eattr = (0xe),
-
- gfs2_bad_block = (0xf), /* Contains at least one bad block */
-};
-
-static const inline char *block_type_string(uint8_t q)
-{
- const char *blktyp[] = {
- "free",
- "data",
- "indirect data",
- "directory",
- "file",
-
- "symlink",
- "block device",
- "char device",
- "fifo",
- "socket",
-
- "invalid inode",
- "invalid meta",
- "dir leaf",
- "rgrp meta",
- "eattribute",
-
- "bad"};
- if (q < 16)
- return (blktyp[q]);
- return blktyp[15];
-}
-
-/* Must be kept in sync with gfs2_mark_block enum above. Blocks marked as
- invalid or bad are considered metadata until actually freed. */
-static inline int blockmap_to_bitmap(enum gfs2_mark_block m)
-{
- static int bitmap_states[16] = {
- GFS2_BLKST_FREE,
- GFS2_BLKST_USED,
- GFS2_BLKST_USED,
- GFS2_BLKST_DINODE,
- GFS2_BLKST_DINODE,
-
- GFS2_BLKST_DINODE,
- GFS2_BLKST_DINODE,
- GFS2_BLKST_DINODE,
- GFS2_BLKST_DINODE,
- GFS2_BLKST_DINODE,
-
- GFS2_BLKST_FREE,
- GFS2_BLKST_FREE,
- GFS2_BLKST_USED,
- GFS2_BLKST_USED,
- GFS2_BLKST_USED,
-
- GFS2_BLKST_USED
- };
- return bitmap_states[m];
-}
-
-extern struct gfs2_bmap *gfs2_bmap_create(struct gfs2_sbd *sdp, uint64_t size,
- uint64_t *addl_mem_needed);
extern struct special_blocks *blockfind(struct special_blocks *blist, uint64_t num);
extern void gfs2_special_add(struct special_blocks *blocklist, uint64_t block);
extern void gfs2_special_set(struct special_blocks *blocklist, uint64_t block);
extern void gfs2_special_free(struct special_blocks *blist);
-extern int gfs2_blockmap_set(struct gfs2_bmap *il, uint64_t block,
- enum gfs2_mark_block mark);
extern void gfs2_special_clear(struct special_blocks *blocklist,
uint64_t block);
-extern void *gfs2_bmap_destroy(struct gfs2_sbd *sdp, struct gfs2_bmap *il);
/* buf.c */
extern struct gfs2_buffer_head *__bget_generic(struct gfs2_sbd *sdp,
12 years, 8 months
gfs2-utils: master - libgfs2: Use dinode buffer to map gfs1 dinode blocks
by Bob Peterson
Gitweb: http://git.fedorahosted.org/git/gfs2-utils.git?p=gfs2-utils.git;a=commitd...
Commit: d9cb12d1372ef5d62ad09509886ad8fcd29a0dd6
Parent: 178f6cabb4a425d456524df71d345302e88af18f
Author: Bob Peterson <rpeterso(a)redhat.com>
AuthorDate: Wed Aug 10 10:33:49 2011 -0500
Committer: Bob Peterson <rpeterso(a)redhat.com>
CommitterDate: Mon Aug 29 12:54:42 2011 -0500
libgfs2: Use dinode buffer to map gfs1 dinode blocks
When function gfs1_block_map found a block for a stuffed file it
wasn't returning the dinode buffer, it was returning the block as a
new buffer. The problem is, if changes are made to the block, they
will be overwritten by the dinode buffer when that is released.
The result is a fixed block that doesn't get fixed. This patch
changes the code to return the block properly like gfs2_block_map.
rhbz#675723
---
gfs2/libgfs2/gfs1.c | 5 ++++-
1 files changed, 4 insertions(+), 1 deletions(-)
diff --git a/gfs2/libgfs2/gfs1.c b/gfs2/libgfs2/gfs1.c
index d09a8ee..5304b56 100644
--- a/gfs2/libgfs2/gfs1.c
+++ b/gfs2/libgfs2/gfs1.c
@@ -120,7 +120,10 @@ void gfs1_block_map(struct gfs2_inode *ip, uint64_t lblock, int *new,
mh.mh_format = GFS2_FORMAT_IN;
gfs2_meta_header_out(&mh, bh);
} else {
- bh = bread(sdp, *dblock);
+ if (*dblock == ip->i_di.di_num.no_addr)
+ bh = ip->i_bh;
+ else
+ bh = bread(sdp, *dblock);
}
}
12 years, 8 months
gfs2-utils: master - libgfs2: Mark buffer modified adding a new GFS1 block
by Bob Peterson
Gitweb: http://git.fedorahosted.org/git/gfs2-utils.git?p=gfs2-utils.git;a=commitd...
Commit: 178f6cabb4a425d456524df71d345302e88af18f
Parent: f15fed66fc4dd14b35573903afd316405f50a933
Author: Bob Peterson <rpeterso(a)redhat.com>
AuthorDate: Wed Aug 10 10:25:19 2011 -0500
Committer: Bob Peterson <rpeterso(a)redhat.com>
CommitterDate: Mon Aug 29 12:54:42 2011 -0500
libgfs2: Mark buffer modified adding a new GFS1 block
When adding new blocks to the file system for GFS1, function
gfs1_lookup_block was not marking the buffer and dinode buffer
as modified like gfs2_lookup_block does. This patch fixes that.
rhbz#675723
---
gfs2/libgfs2/gfs1.c | 2 ++
1 files changed, 2 insertions(+), 0 deletions(-)
diff --git a/gfs2/libgfs2/gfs1.c b/gfs2/libgfs2/gfs1.c
index dc29006..d09a8ee 100644
--- a/gfs2/libgfs2/gfs1.c
+++ b/gfs2/libgfs2/gfs1.c
@@ -56,7 +56,9 @@ void gfs1_lookup_block(struct gfs2_inode *ip, struct gfs2_buffer_head *bh,
*block = meta_alloc(ip);
*ptr = cpu_to_be64(*block);
+ bmodified(bh);
ip->i_di.di_blocks++;
+ bmodified(ip->i_bh);
*new = 1;
}
12 years, 8 months
gfs2-utils: master - libgfs2: eliminate gfs1_readi in favor of gfs2_readi
by Bob Peterson
Gitweb: http://git.fedorahosted.org/git/gfs2-utils.git?p=gfs2-utils.git;a=commitd...
Commit: f15fed66fc4dd14b35573903afd316405f50a933
Parent: 4d75aa8523397f57bd3e8c1c9ef1c5b92e287caf
Author: Bob Peterson <rpeterso(a)redhat.com>
AuthorDate: Wed Aug 10 10:21:00 2011 -0500
Committer: Bob Peterson <rpeterso(a)redhat.com>
CommitterDate: Mon Aug 29 12:54:42 2011 -0500
libgfs2: eliminate gfs1_readi in favor of gfs2_readi
This patch eliminates function gfs1_readi because it's nearly
identical to gfs2_readi. The gfs1-specific bits have been made
generic in gfs2_readi based on the sdp->gfs1 setting.
rhbz#675723
---
gfs2/edit/extended.c | 8 +----
gfs2/libgfs2/fs_ops.c | 21 ++++++++++----
gfs2/libgfs2/gfs1.c | 68 +-----------------------------------------------
gfs2/libgfs2/libgfs2.h | 2 -
gfs2/libgfs2/super.c | 5 ---
5 files changed, 18 insertions(+), 86 deletions(-)
diff --git a/gfs2/edit/extended.c b/gfs2/edit/extended.c
index 792b724..071f589 100644
--- a/gfs2/edit/extended.c
+++ b/gfs2/edit/extended.c
@@ -516,12 +516,8 @@ static int parse_rindex(struct gfs2_inode *dip, int print_rindex)
roff = print_entry_ndx * sizeof(struct gfs2_rindex);
- if (sbd.gfs1)
- error = gfs1_readi(dip, (void *)&rbuf, roff,
- sizeof(struct gfs2_rindex));
- else
- error = gfs2_readi(dip, (void *)&rbuf, roff,
- sizeof(struct gfs2_rindex));
+ error = gfs2_readi(dip, (void *)&rbuf, roff,
+ sizeof(struct gfs2_rindex));
if (!error) /* end of file */
break;
gfs2_rindex_in(&ri, rbuf);
diff --git a/gfs2/libgfs2/fs_ops.c b/gfs2/libgfs2/fs_ops.c
index 60ee467..4c8d31e 100644
--- a/gfs2/libgfs2/fs_ops.c
+++ b/gfs2/libgfs2/fs_ops.c
@@ -510,6 +510,7 @@ int gfs2_readi(struct gfs2_inode *ip, void *buf,
unsigned int amount;
int not_new = 0;
int isdir = !!(S_ISDIR(ip->i_di.di_mode));
+ int journaled = ip->i_di.di_flags & GFS2_DIF_JDATA;
int copied = 0;
if (offset >= ip->i_di.di_size)
@@ -521,7 +522,7 @@ int gfs2_readi(struct gfs2_inode *ip, void *buf,
if (!size)
return 0;
- if (isdir) {
+ if ((sdp->gfs1 && journaled) || (!sdp->gfs1 && isdir)) {
lblock = offset;
o = lblock % sdp->sd_jbsize;
lblock /= sdp->sd_jbsize;
@@ -532,7 +533,7 @@ int gfs2_readi(struct gfs2_inode *ip, void *buf,
if (inode_is_stuffed(ip))
o += sizeof(struct gfs2_dinode);
- else if (isdir)
+ else if ((sdp->gfs1 && journaled) || (!sdp->gfs1 && isdir))
o += sizeof(struct gfs2_meta_header);
while (copied < size) {
@@ -540,9 +541,14 @@ int gfs2_readi(struct gfs2_inode *ip, void *buf,
if (amount > sdp->bsize - o)
amount = sdp->bsize - o;
- if (!extlen)
- block_map(ip, lblock, ¬_new, &dblock, &extlen,
- FALSE);
+ if (!extlen) {
+ if (sdp->gfs1)
+ gfs1_block_map(ip, lblock, ¬_new, &dblock,
+ &extlen, FALSE);
+ else
+ block_map(ip, lblock, ¬_new, &dblock,
+ &extlen, FALSE);
+ }
if (dblock) {
if (dblock == ip->i_di.di_num.no_addr)
@@ -561,7 +567,10 @@ int gfs2_readi(struct gfs2_inode *ip, void *buf,
copied += amount;
lblock++;
- o = (isdir) ? sizeof(struct gfs2_meta_header) : 0;
+ if (sdp->gfs1)
+ o = (journaled) ? sizeof(struct gfs2_meta_header) : 0;
+ else
+ o = (isdir) ? sizeof(struct gfs2_meta_header) : 0;
}
return copied;
diff --git a/gfs2/libgfs2/gfs1.c b/gfs2/libgfs2/gfs1.c
index 66e00ff..dc29006 100644
--- a/gfs2/libgfs2/gfs1.c
+++ b/gfs2/libgfs2/gfs1.c
@@ -156,72 +156,6 @@ void gfs1_block_map(struct gfs2_inode *ip, uint64_t lblock, int *new,
free(mp);
}
-int gfs1_readi(struct gfs2_inode *ip, void *bufin,
- uint64_t offset, unsigned int size)
-{
- struct gfs2_sbd *sdp = ip->i_sbd;
- struct gfs2_buffer_head *bh;
- uint64_t lblock, dblock = 0;
- uint32_t extlen = 0;
- unsigned int amount;
- int not_new = 0;
- int journaled = fs_is_jdata(ip);
- int copied = 0;
- char *buf = bufin;
-
- if (offset >= ip->i_di.di_size)
- return 0;
-
- if ((offset + size) > ip->i_di.di_size)
- size = ip->i_di.di_size - offset;
-
- if (!size)
- return 0;
-
- if (journaled) {
- lblock = offset / sdp->sd_jbsize;
- offset %= sdp->sd_jbsize;
- } else {
- lblock = offset >> sdp->sd_sb.sb_bsize_shift;
- offset &= sdp->sd_sb.sb_bsize - 1;
- }
-
- if (!ip->i_di.di_height) /* stuffed */
- offset += sizeof(struct gfs_dinode);
- else if (journaled)
- offset += sizeof(struct gfs2_meta_header);
-
- while (copied < size) {
- amount = size - copied;
- if (amount > sdp->bsize - offset)
- amount = sdp->bsize - offset;
-
- if (!extlen)
- gfs1_block_map(ip, lblock, ¬_new, &dblock,
- &extlen, FALSE);
-
- if (dblock) {
- bh = bread(sdp, dblock);
- dblock++;
- extlen--;
- } else
- bh = NULL;
-
-
- if (bh) {
- memcpy(buf+copied, bh->b_data + offset, amount);
- brelse(bh);
- } else
- memset(buf+copied, 0, amount);
- copied += amount;
- lblock++;
-
- offset = (journaled) ? sizeof(struct gfs2_meta_header) : 0;
- }
-
- return copied;
-}
-
/**
* gfs1_rindex_read - read in the rg index file
* Stolen from libgfs2/super.c, but modified to handle gfs1.
@@ -246,7 +180,7 @@ int gfs1_rindex_read(struct gfs2_sbd *sdp, int fd, int *count1)
if (fd > 0)
error = read(fd, &buf, sizeof(struct gfs2_rindex));
else
- error = gfs1_readi(sdp->md.riinode, (char *)&buf,
+ error = gfs2_readi(sdp->md.riinode, (char *)&buf,
(rg * sizeof(struct gfs2_rindex)),
sizeof(struct gfs2_rindex));
if (!error)
diff --git a/gfs2/libgfs2/libgfs2.h b/gfs2/libgfs2/libgfs2.h
index f8f55b1..0ac5f3d 100644
--- a/gfs2/libgfs2/libgfs2.h
+++ b/gfs2/libgfs2/libgfs2.h
@@ -669,8 +669,6 @@ extern void gfs1_lookup_block(struct gfs2_inode *ip,
int create, int *new, uint64_t *block);
extern void gfs1_block_map(struct gfs2_inode *ip, uint64_t lblock, int *new,
uint64_t *dblock, uint32_t *extlen, int prealloc);
-extern int gfs1_readi(struct gfs2_inode *ip, void *buf, uint64_t offset,
- unsigned int size);
extern int gfs1_rindex_read(struct gfs2_sbd *sdp, int fd, int *count1);
extern int gfs1_ri_update(struct gfs2_sbd *sdp, int fd, int *rgcount, int quiet);
extern struct gfs2_inode *gfs_inode_get(struct gfs2_sbd *sdp,
diff --git a/gfs2/libgfs2/super.c b/gfs2/libgfs2/super.c
index 9e8d079..693e547 100644
--- a/gfs2/libgfs2/super.c
+++ b/gfs2/libgfs2/super.c
@@ -160,11 +160,6 @@ int rindex_read(struct gfs2_sbd *sdp, int fd, int *count1, int *sane)
for (rg = 0; ; rg++) {
if (fd > 0)
error = read(fd, &buf, sizeof(struct gfs2_rindex));
- else if (sdp->gfs1)
- error = gfs1_readi(sdp->md.riinode,
- (char *)&buf.bufgfs1,
- rg * sizeof(struct gfs2_rindex),
- sizeof(struct gfs2_rindex));
else
error = gfs2_readi(sdp->md.riinode,
(char *)&buf.bufgfs2,
12 years, 8 months
gfs2-utils: master - fsck.gfs2: don't free prev rgrp list repairing rgrps
by Bob Peterson
Gitweb: http://git.fedorahosted.org/git/gfs2-utils.git?p=gfs2-utils.git;a=commitd...
Commit: 4d75aa8523397f57bd3e8c1c9ef1c5b92e287caf
Parent: e3bb6a63751dbe1f816030351f94b6d3de057514
Author: Bob Peterson <rpeterso(a)redhat.com>
AuthorDate: Tue Aug 9 15:51:34 2011 -0500
Committer: Bob Peterson <rpeterso(a)redhat.com>
CommitterDate: Mon Aug 29 12:54:42 2011 -0500
fsck.gfs2: don't free prev rgrp list repairing rgrps
In cases where fsck.gfs2 is trying to repair damaged resource groups or
rindex, it tries several levels of repair. Some of those levels build a
list of expected resource groups and check them against the actual ones,
and the previous list is freed before the next level is attempted.
However, in the case of minor damage, such as one bitmap block that was
overwritten, we can often repair the damage by reading in the resource
groups at the first level, then at the second level of repair (called
"ye_of_little_faith") use those values to compare against. This patch
allows the second level of repair to use the first level's list.
rhbz#675723
---
gfs2/fsck/rgrepair.c | 17 +++++++++++++----
1 files changed, 13 insertions(+), 4 deletions(-)
diff --git a/gfs2/fsck/rgrepair.c b/gfs2/fsck/rgrepair.c
index c91e4be..864b880 100644
--- a/gfs2/fsck/rgrepair.c
+++ b/gfs2/fsck/rgrepair.c
@@ -784,12 +784,12 @@ int rg_repair(struct gfs2_sbd *sdp, int trust_lvl, int *rg_count, int *sane)
osi_list_t *exp, *act; /* expected, actual */
struct gfs2_rindex buf;
- /* Free previous incarnations in memory, if any. */
- gfs2_rgrp_free(&sdp->rglist);
-
if (trust_lvl == blind_faith)
return 0;
- else if (trust_lvl == ye_of_little_faith) { /* if rindex seems sane */
+ if (trust_lvl == ye_of_little_faith) { /* if rindex seems sane */
+ /* Don't free previous incarnations in memory, if any.
+ * We need them to copy in the next function:
+ * gfs2_rgrp_free(&sdp->rglist); */
if (!(*sane)) {
log_err(_("The rindex file does not meet our "
"expectations.\n"));
@@ -802,6 +802,9 @@ int rg_repair(struct gfs2_sbd *sdp, int trust_lvl, int *rg_count, int *sane)
return error;
}
} else if (trust_lvl == open_minded) { /* If we can't trust RG index */
+ /* Free previous incarnations in memory, if any. */
+ gfs2_rgrp_free(&sdp->rglist);
+
/* Calculate our own RG index for comparison */
error = gfs2_rindex_calculate(sdp, &expected_rglist,
&calc_rg_count);
@@ -811,6 +814,9 @@ int rg_repair(struct gfs2_sbd *sdp, int trust_lvl, int *rg_count, int *sane)
}
}
else if (trust_lvl == distrust) { /* If we can't trust RG index */
+ /* Free previous incarnations in memory, if any. */
+ gfs2_rgrp_free(&sdp->rglist);
+
error = gfs2_rindex_rebuild(sdp, &expected_rglist,
&calc_rg_count, 0);
if (error) {
@@ -821,6 +827,9 @@ int rg_repair(struct gfs2_sbd *sdp, int trust_lvl, int *rg_count, int *sane)
sdp->rgrps = calc_rg_count;
}
else if (trust_lvl == indignation) { /* If we can't trust anything */
+ /* Free previous incarnations in memory, if any. */
+ gfs2_rgrp_free(&sdp->rglist);
+
error = gfs2_rindex_rebuild(sdp, &expected_rglist,
&calc_rg_count, 1);
if (error) {
12 years, 8 months