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-28-2012, 03:36 PM
Andrew Price
 
Default libgfs2: Remove exit call from __gfs_inode_get

Return NULL instead of exiting on a failed calloc() and handle the error
at all call points. Also update the names of gfs_inode_{get,read} with
the lgfs2_ prefix.

Signed-off-by: Andrew Price <anprice@redhat.com>
---
gfs2/convert/gfs2_convert.c | 12 ++++++++++--
gfs2/edit/savemeta.c | 30 +++++++++++++++++-------------
gfs2/fsck/metawalk.c | 4 ++--
gfs2/libgfs2/gfs1.c | 7 +++----
gfs2/libgfs2/libgfs2.h | 4 ++--
5 files changed, 34 insertions(+), 23 deletions(-)

diff --git a/gfs2/convert/gfs2_convert.c b/gfs2/convert/gfs2_convert.c
index 51ec256..b5d993d 100644
--- a/gfs2/convert/gfs2_convert.c
+++ b/gfs2/convert/gfs2_convert.c
@@ -895,7 +895,11 @@ static int adjust_inode(struct gfs2_sbd *sbp, struct gfs2_buffer_head *bh)
struct inode_block *fixdir;
int inode_was_gfs1;

- inode = gfs_inode_get(sbp, bh);
+ inode = lgfs2_gfs_inode_get(sbp, bh);
+ if (inode == NULL) {
+ log_crit(_("Error reading inode: %s
"), strerror(errno));
+ return -1;
+ }

inode_was_gfs1 = (inode->i_di.di_num.no_formal_ino ==
inode->i_di.di_num.no_addr);
@@ -1591,7 +1595,11 @@ static int init(struct gfs2_sbd *sbp)
}
/* get gfs1 rindex inode - gfs1's rindex inode ptr became __pad2 */
gfs2_inum_in(&inum, (char *)&raw_gfs1_ondisk_sb.sb_rindex_di);
- sbp->md.riinode = gfs_inode_read(sbp, inum.no_addr);
+ sbp->md.riinode = lgfs2_gfs_inode_read(sbp, inum.no_addr);
+ if (sbp->md.riinode == NULL) {
+ log_crit(_("Could not read resource group index: %s
"), strerror(errno));
+ exit(-1);
+ }
/* get gfs1 jindex inode - gfs1's journal index inode ptr became master */
gfs2_inum_in(&inum, (char *)&raw_gfs1_ondisk_sb.sb_jindex_di);
sbp->md.jiinode = lgfs2_inode_read(sbp, inum.no_addr);
diff --git a/gfs2/edit/savemeta.c b/gfs2/edit/savemeta.c
index 77165a7..f35c35d 100644
--- a/gfs2/edit/savemeta.c
+++ b/gfs2/edit/savemeta.c
@@ -147,13 +147,13 @@ 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 = gfs_inode_get(&sbd, lbh);
+ inode = lgfs2_gfs_inode_get(&sbd, lbh);
} else {
inode = lgfs2_inode_get(&sbd, lbh);
- if (inode == NULL) {
- fprintf(stderr, "Out of memory
");
- exit(-1);
- }
+ }
+ if (inode == NULL) {
+ perror("Error reading inode");
+ exit(-1);
}
if (S_ISDIR(inode->i_di.di_mode) ||
(sbd.gfs1 && inode->i_di.__pad1 == GFS_FILE_DIR))
@@ -488,14 +488,14 @@ static void save_inode_data(struct metafd *mfd)
for (i = 0; i < GFS2_MAX_META_HEIGHT; i++)
osi_list_init(&metalist[i]);
metabh = bread(&sbd, block);
- if (sbd.gfs1)
- inode = gfs_inode_get(&sbd, metabh);
- else {
+ if (sbd.gfs1) {
+ inode = lgfs2_gfs_inode_get(&sbd, metabh);
+ } else {
inode = lgfs2_inode_get(&sbd, metabh);
- if (inode == NULL) {
- fprintf(stderr, "Failed to read inode: %s
", strerror(errno));
- exit(-1);
- }
+ }
+ if (inode == NULL) {
+ perror("Failed to read inode");
+ exit(-1);
}
height = inode->i_di.di_height;
/* If this is a user inode, we don't follow to the file height.
@@ -611,8 +611,12 @@ static void get_journal_inode_blocks(void)
struct gfs_jindex ji;
char jbuf[sizeof(struct gfs_jindex)];

- j_inode = gfs_inode_read(&sbd,
+ j_inode = lgfs2_gfs_inode_read(&sbd,
sbd1->sb_jindex_di.no_addr);
+ if (j_inode == NULL) {
+ fprintf(stderr, "Error reading journal inode: %s
", strerror(errno));
+ return;
+ }
amt = gfs2_readi(j_inode, (void *)&jbuf,
journal * sizeof(struct gfs_jindex),
sizeof(struct gfs_jindex));
diff --git a/gfs2/fsck/metawalk.c b/gfs2/fsck/metawalk.c
index aa4f0b5..24de901 100644
--- a/gfs2/fsck/metawalk.c
+++ b/gfs2/fsck/metawalk.c
@@ -226,7 +226,7 @@ struct gfs2_inode *fsck_load_inode(struct gfs2_sbd *sdp, uint64_t block)
if (ip)
return ip;
if (sdp->gfs1)
- return gfs_inode_read(sdp, block);
+ return lgfs2_gfs_inode_read(sdp, block);
return lgfs2_inode_read(sdp, block);
}

@@ -242,7 +242,7 @@ struct gfs2_inode *fsck_inode_get(struct gfs2_sbd *sdp,
return sysip;

if (sdp->gfs1)
- return gfs_inode_get(sdp, bh);
+ return lgfs2_gfs_inode_get(sdp, bh);
return lgfs2_inode_get(sdp, bh);
}

diff --git a/gfs2/libgfs2/gfs1.c b/gfs2/libgfs2/gfs1.c
index d6f8794..06fa98f 100644
--- a/gfs2/libgfs2/gfs1.c
+++ b/gfs2/libgfs2/gfs1.c
@@ -293,8 +293,7 @@ static struct gfs2_inode *__gfs_inode_get(struct gfs2_sbd *sdp,

ip = calloc(1, sizeof(struct gfs2_inode));
if (ip == NULL) {
- fprintf(stderr, "Out of memory in %s
", __FUNCTION__);
- exit(-1);
+ return NULL;
}

ip->bh_owned = 0;
@@ -332,13 +331,13 @@ static struct gfs2_inode *__gfs_inode_get(struct gfs2_sbd *sdp,
return ip;
}

-struct gfs2_inode *gfs_inode_get(struct gfs2_sbd *sdp,
+struct gfs2_inode *lgfs2_gfs_inode_get(struct gfs2_sbd *sdp,
struct gfs2_buffer_head *bh)
{
return __gfs_inode_get(sdp, bh, 0);
}

-struct gfs2_inode *gfs_inode_read(struct gfs2_sbd *sdp, uint64_t di_addr)
+struct gfs2_inode *lgfs2_gfs_inode_read(struct gfs2_sbd *sdp, uint64_t di_addr)
{
return __gfs_inode_get(sdp, NULL, di_addr);
}
diff --git a/gfs2/libgfs2/libgfs2.h b/gfs2/libgfs2/libgfs2.h
index 9b128ff..74ee2d0 100644
--- a/gfs2/libgfs2/libgfs2.h
+++ b/gfs2/libgfs2/libgfs2.h
@@ -646,9 +646,9 @@ extern void gfs1_block_map(struct gfs2_inode *ip, uint64_t lblock, int *new,
extern int gfs1_writei(struct gfs2_inode *ip, char *buf, uint64_t offset,
unsigned int size);
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,
+extern struct gfs2_inode *lgfs2_gfs_inode_get(struct gfs2_sbd *sdp,
struct gfs2_buffer_head *bh);
-extern struct gfs2_inode *gfs_inode_read(struct gfs2_sbd *sdp,
+extern struct gfs2_inode *lgfs2_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);
--
1.7.11.4
 

Thread Tools




All times are GMT. The time now is 04:26 PM.

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