This is the mail archive of the
cluster-cvs@sourceware.org
mailing list for the cluster.
cluster: STABLE3 - libgfs2: First go at cutting the number of "die"s
- From: "Fabio M. Di Nitto" <fabbione at fedoraproject dot org>
- To: cluster-cvs-relay at redhat dot com
- Date: Thu, 19 Feb 2009 10:09:03 +0000 (UTC)
- Subject: cluster: STABLE3 - libgfs2: First go at cutting the number of "die"s
Gitweb: http://git.fedorahosted.org/git/cluster.git?p=cluster.git;a=commitdiff;h=ab6bd3fac2fc94a8189df82ae3df7c4ec17fa77e
Commit: ab6bd3fac2fc94a8189df82ae3df7c4ec17fa77e
Parent: 032266fae599c38074a1de918067c9186bb0119b
Author: Steven Whitehouse <swhiteho@redhat.com>
AuthorDate: Mon Jan 26 16:00:12 2009 +0000
Committer: Fabio M. Di Nitto <fdinitto@redhat.com>
CommitterDate: Thu Feb 19 10:59:56 2009 +0100
libgfs2: First go at cutting the number of "die"s
This is a start towards cutting down the number of die() calls
and actually having some better error handling.
Signed-off-by: Steven Whitehouse <swhiteho@redhat.com>
---
gfs2/edit/savemeta.c | 5 +++-
gfs2/fsck/rgrepair.c | 5 +++-
gfs2/libgfs2/buf.c | 28 +++++++++++++-------------
gfs2/libgfs2/device_geometry.c | 6 ++--
gfs2/libgfs2/libgfs2.h | 14 ++++++------
gfs2/libgfs2/structures.c | 41 ++++++++++++++++++++++++---------------
gfs2/mkfs/main_grow.c | 5 +++-
gfs2/mkfs/main_mkfs.c | 5 +++-
8 files changed, 65 insertions(+), 44 deletions(-)
diff --git a/gfs2/edit/savemeta.c b/gfs2/edit/savemeta.c
index 3587c4b..4932a9e 100644
--- a/gfs2/edit/savemeta.c
+++ b/gfs2/edit/savemeta.c
@@ -439,7 +439,10 @@ void savemeta(char *out_fn, int saveoption)
if (!gfs1)
sbd.bsize = BUFSIZE;
if (!slow) {
- device_geometry(&sbd);
+ if (device_geometry(&sbd)) {
+ fprintf(stderr, "Geometery error\n");
+ exit(-1);
+ }
fix_device_geometry(&sbd);
osi_list_init(&sbd.rglist);
init_buf_list(&sbd, &sbd.buf_list, 128 << 20);
diff --git a/gfs2/fsck/rgrepair.c b/gfs2/fsck/rgrepair.c
index fce2f17..9298b10 100644
--- a/gfs2/fsck/rgrepair.c
+++ b/gfs2/fsck/rgrepair.c
@@ -339,7 +339,10 @@ int gfs2_rindex_calculate(struct gfs2_sbd *sdp, osi_list_t *ret_list,
{
osi_list_init(ret_list);
sdp->rgsize = GFS2_DEFAULT_RGSIZE; /* compute_rgrp_layout adjusts */
- device_geometry(sdp);
+ if (device_geometry(sdp)) {
+ fprintf(stderr, "Geometry error\n");
+ exit(-1);
+ }
fix_device_geometry(sdp);
/* Compute the default resource group layout as mkfs would have done */
compute_rgrp_layout(sdp, FALSE);
diff --git a/gfs2/libgfs2/buf.c b/gfs2/libgfs2/buf.c
index 7187492..d20a7bd 100644
--- a/gfs2/libgfs2/buf.c
+++ b/gfs2/libgfs2/buf.c
@@ -47,8 +47,7 @@ void init_buf_list(struct gfs2_sbd *sdp, struct buf_list *bl, uint32_t limit)
osi_list_init(&bl->buf_hash[i]);
}
-static void
-add_buffer(struct buf_list *bl, struct gfs2_buffer_head *bh)
+static void add_buffer(struct buf_list *bl, struct gfs2_buffer_head *bh)
{
osi_list_t *head = blkno2head(bl, bh->b_blocknr);
@@ -108,10 +107,8 @@ struct gfs2_buffer_head *bget_generic(struct buf_list *bl, uint64_t num,
return bh;
}
bh = calloc(1, sizeof(struct gfs2_buffer_head) + sdp->bsize);
- if (bh == NULL) {
- fprintf(stderr, "Out of memory in %s\n", __FUNCTION__);
- exit(-1);
- }
+ if (bh == NULL)
+ return NULL;
bh->b_count = 1;
bh->b_blocknr = num;
@@ -139,8 +136,7 @@ struct gfs2_buffer_head *bread(struct buf_list *bl, uint64_t num)
struct gfs2_buffer_head *bhold(struct gfs2_buffer_head *bh)
{
if (!bh->b_count)
- die("buffer hold error for block %" PRIu64 " (0x%" PRIx64")\n",
- bh->b_blocknr, bh->b_blocknr);
+ return NULL;
bh->b_count++;
return bh;
}
@@ -151,9 +147,11 @@ void brelse(struct gfs2_buffer_head *bh, enum update_flags updated)
/* set it FALSE if it's TRUE until we write the changed data to disk. */
if (updated)
bh->b_changed = TRUE;
- if (!bh->b_count)
- die("buffer count underflow for block %" PRIu64 " (0x%" PRIx64")\n",
- bh->b_blocknr, bh->b_blocknr);
+ if (!bh->b_count) {
+ fprintf(stderr, "buffer count underflow for block %" PRIu64
+ " (0x%" PRIx64")\n", bh->b_blocknr, bh->b_blocknr);
+ exit(-1);
+ }
bh->b_count--;
}
@@ -164,9 +162,11 @@ void bsync(struct buf_list *bl)
while (!osi_list_empty(&bl->list)) {
bh = osi_list_entry(bl->list.prev, struct gfs2_buffer_head,
b_list);
- if (bh->b_count)
- die("buffer still held for block: %" PRIu64 " (0x%" PRIx64")\n",
- bh->b_blocknr, bh->b_blocknr);
+ if (bh->b_count) {
+ fprintf(stderr, "buffer still held for block: %" PRIu64
+ " (0x%" PRIx64")\n", bh->b_blocknr, bh->b_blocknr);
+ exit(-1);
+ }
write_buffer(bl, bh);
}
}
diff --git a/gfs2/libgfs2/device_geometry.c b/gfs2/libgfs2/device_geometry.c
index 1ad3d91..f37defa 100644
--- a/gfs2/libgfs2/device_geometry.c
+++ b/gfs2/libgfs2/device_geometry.c
@@ -18,7 +18,7 @@
*
*/
-void device_geometry(struct gfs2_sbd *sdp)
+int device_geometry(struct gfs2_sbd *sdp)
{
struct device *device = &sdp->device;
uint64_t bytes;
@@ -26,8 +26,7 @@ void device_geometry(struct gfs2_sbd *sdp)
error = device_size(sdp->device_fd, &bytes);
if (error)
- die("can't determine size of %s: %s\n",
- sdp->device_name, strerror(errno));
+ return error;
if (sdp->debug)
printf("\nPartition size = %"PRIu64"\n",
@@ -35,6 +34,7 @@ void device_geometry(struct gfs2_sbd *sdp)
device->start = 0;
device->length = bytes >> GFS2_BASIC_BLOCK_SHIFT;
+ return 0;
}
/**
diff --git a/gfs2/libgfs2/libgfs2.h b/gfs2/libgfs2/libgfs2.h
index 1f397d7..9d38e41 100644
--- a/gfs2/libgfs2/libgfs2.h
+++ b/gfs2/libgfs2/libgfs2.h
@@ -418,7 +418,7 @@ extern void bsync(struct buf_list *bl);
extern void bcommit(struct buf_list *bl);
/* device_geometry.c */
-extern void device_geometry(struct gfs2_sbd *sdp);
+extern int device_geometry(struct gfs2_sbd *sdp);
extern void fix_device_geometry(struct gfs2_sbd *sdp);
/* fs_bits.c */
@@ -494,8 +494,8 @@ extern int gfs2_dirent_next(struct gfs2_inode *dip, struct gfs2_buffer_head *bh,
struct gfs2_dirent **dent);
extern void build_height(struct gfs2_inode *ip, int height);
extern unsigned int calc_tree_height(struct gfs2_inode *ip, uint64_t size);
-extern void write_journal(struct gfs2_sbd *sdp, struct gfs2_inode *ip,
- unsigned int j, unsigned int blocks);
+extern int write_journal(struct gfs2_sbd *sdp, struct gfs2_inode *ip,
+ unsigned int j, unsigned int blocks);
/**
* device_size - figure out a device's size
@@ -688,14 +688,14 @@ extern void gfs2_rgrp_free(osi_list_t *rglist, enum update_flags updated);
/* structures.c */
extern void build_master(struct gfs2_sbd *sdp);
extern void build_sb(struct gfs2_sbd *sdp);
-extern void build_jindex(struct gfs2_sbd *sdp);
+extern int build_jindex(struct gfs2_sbd *sdp);
extern void build_per_node(struct gfs2_sbd *sdp);
extern void build_inum(struct gfs2_sbd *sdp);
extern void build_statfs(struct gfs2_sbd *sdp);
-extern void build_rindex(struct gfs2_sbd *sdp);
-extern void build_quota(struct gfs2_sbd *sdp);
+extern int build_rindex(struct gfs2_sbd *sdp);
+extern int build_quota(struct gfs2_sbd *sdp);
extern void build_root(struct gfs2_sbd *sdp);
-extern void do_init(struct gfs2_sbd *sdp);
+extern int do_init(struct gfs2_sbd *sdp);
extern int gfs2_check_meta(struct gfs2_buffer_head *bh, int type);
extern int gfs2_next_rg_meta(struct rgrp_list *rgd, uint64_t *block, int first);
extern int gfs2_next_rg_metatype(struct gfs2_sbd *sdp, struct rgrp_list *rgd,
diff --git a/gfs2/libgfs2/structures.c b/gfs2/libgfs2/structures.c
index 05beeb9..dbe35ab 100644
--- a/gfs2/libgfs2/structures.c
+++ b/gfs2/libgfs2/structures.c
@@ -78,8 +78,8 @@ void build_sb(struct gfs2_sbd *sdp)
}
}
-void write_journal(struct gfs2_sbd *sdp, struct gfs2_inode *ip, unsigned int j,
- unsigned int blocks)
+int write_journal(struct gfs2_sbd *sdp, struct gfs2_inode *ip, unsigned int j,
+ unsigned int blocks)
{
struct gfs2_log_header lh;
unsigned int x;
@@ -101,13 +101,13 @@ void write_journal(struct gfs2_sbd *sdp, struct gfs2_inode *ip, unsigned int j,
for (x = 0; x < blocks; x++) {
struct gfs2_buffer_head *bh = get_file_buf(ip, x, TRUE);
if (!bh)
- die("write_journal\n");
+ return -1;
brelse(bh, updated);
}
for (x = 0; x < blocks; x++) {
struct gfs2_buffer_head *bh = get_file_buf(ip, x, FALSE);
if (!bh)
- die("write_journal\n");
+ return -1;
lh.lh_sequence = seq;
lh.lh_blkno = x;
@@ -125,12 +125,14 @@ void write_journal(struct gfs2_sbd *sdp, struct gfs2_inode *ip, unsigned int j,
printf("\nJournal %u:\n", j);
gfs2_dinode_print(&ip->i_di);
}
+ return 0;
}
-void build_jindex(struct gfs2_sbd *sdp)
+int build_jindex(struct gfs2_sbd *sdp)
{
struct gfs2_inode *jindex;
unsigned int j;
+ int ret;
jindex = createi(sdp->master_dir, "jindex", S_IFDIR | 0700,
GFS2_DIF_SYSTEM);
@@ -141,8 +143,10 @@ void build_jindex(struct gfs2_sbd *sdp)
sprintf(name, "journal%u", j);
ip = createi(jindex, name, S_IFREG | 0600, GFS2_DIF_SYSTEM);
- write_journal(sdp, ip, j,
+ ret = write_journal(sdp, ip, j,
sdp->jsize << 20 >> sdp->sd_sb.sb_bsize_shift);
+ if (ret)
+ return ret;
inode_put(ip, updated);
}
@@ -152,6 +156,7 @@ void build_jindex(struct gfs2_sbd *sdp)
}
inode_put(jindex, updated);
+ return 0;
}
static void build_inum_range(struct gfs2_inode *per_node, unsigned int j)
@@ -192,7 +197,7 @@ static void build_statfs_change(struct gfs2_inode *per_node, unsigned int j)
inode_put(ip, updated);
}
-static void build_quota_change(struct gfs2_inode *per_node, unsigned int j)
+static int build_quota_change(struct gfs2_inode *per_node, unsigned int j)
{
struct gfs2_sbd *sdp = per_node->i_sbd;
struct gfs2_meta_header mh;
@@ -213,7 +218,7 @@ static void build_quota_change(struct gfs2_inode *per_node, unsigned int j)
for (x = 0; x < blocks; x++) {
struct gfs2_buffer_head *bh = get_file_buf(ip, ip->i_di.di_size >> sdp->sd_sb.sb_bsize_shift, FALSE);
if (!bh)
- die("build_quota_change\n");
+ return -1;
gfs2_meta_header_out(&mh, bh->b_data);
@@ -226,6 +231,7 @@ static void build_quota_change(struct gfs2_inode *per_node, unsigned int j)
}
inode_put(ip, updated);
+ return 0;
}
void build_per_node(struct gfs2_sbd *sdp)
@@ -280,7 +286,7 @@ void build_statfs(struct gfs2_sbd *sdp)
sdp->md.statfs = ip;
}
-void build_rindex(struct gfs2_sbd *sdp)
+int build_rindex(struct gfs2_sbd *sdp)
{
struct gfs2_inode *ip;
osi_list_t *tmp, *head;
@@ -302,7 +308,7 @@ void build_rindex(struct gfs2_sbd *sdp)
count = gfs2_writei(ip, buf, ip->i_di.di_size,
sizeof(struct gfs2_rindex));
if (count != sizeof(struct gfs2_rindex))
- die("build_rindex\n");
+ return -1;
}
if (sdp->debug) {
@@ -311,9 +317,10 @@ void build_rindex(struct gfs2_sbd *sdp)
}
inode_put(ip, updated);
+ return 0;
}
-void build_quota(struct gfs2_sbd *sdp)
+int build_quota(struct gfs2_sbd *sdp)
{
struct gfs2_inode *ip;
struct gfs2_quota qu;
@@ -330,10 +337,10 @@ void build_quota(struct gfs2_sbd *sdp)
count = gfs2_writei(ip, buf, ip->i_di.di_size, sizeof(struct gfs2_quota));
if (count != sizeof(struct gfs2_quota))
- die("do_init (2)\n");
+ return -1;
count = gfs2_writei(ip, buf, ip->i_di.di_size, sizeof(struct gfs2_quota));
if (count != sizeof(struct gfs2_quota))
- die("do_init (3)\n");
+ return -1;
if (sdp->debug) {
printf("\nRoot quota:\n");
@@ -341,6 +348,7 @@ void build_quota(struct gfs2_sbd *sdp)
}
inode_put(ip, updated);
+ return 0;
}
void build_root(struct gfs2_sbd *sdp)
@@ -362,7 +370,7 @@ void build_root(struct gfs2_sbd *sdp)
}
}
-void do_init(struct gfs2_sbd *sdp)
+int do_init(struct gfs2_sbd *sdp)
{
{
struct gfs2_inode *ip = sdp->md.inum;
@@ -372,7 +380,7 @@ void do_init(struct gfs2_sbd *sdp)
buf = cpu_to_be64(sdp->md.next_inum);
count = gfs2_writei(ip, &buf, 0, sizeof(uint64_t));
if (count != sizeof(uint64_t))
- die("do_init (1)\n");
+ return -1;
if (sdp->debug)
printf("\nNext Inum: %"PRIu64"\n",
@@ -392,13 +400,14 @@ void do_init(struct gfs2_sbd *sdp)
gfs2_statfs_change_out(&sc, buf);
count = gfs2_writei(ip, buf, 0, sizeof(struct gfs2_statfs_change));
if (count != sizeof(struct gfs2_statfs_change))
- die("do_init (2)\n");
+ return -1;
if (sdp->debug) {
printf("\nStatfs:\n");
gfs2_statfs_change_print(&sc);
}
}
+ return 0;
}
struct gfs2_inode *gfs2_load_inode(struct gfs2_sbd *sbp, uint64_t block)
diff --git a/gfs2/mkfs/main_grow.c b/gfs2/mkfs/main_grow.c
index f363b54..5ae40e8 100644
--- a/gfs2/mkfs/main_grow.c
+++ b/gfs2/mkfs/main_grow.c
@@ -271,7 +271,10 @@ main_grow(int argc, char *argv[])
if (sdp->device_fd < 0)
die("can't open device %s: %s\n",
sdp->device_name, strerror(errno));
- device_geometry(sdp);
+ if (device_geometry(sdp)) {
+ fprintf(stderr, "Geometry error\n");
+ exit(-1);
+ }
log_info("Initializing lists...\n");
osi_list_init(&sdp->rglist);
init_buf_list(sdp, &sdp->buf_list, 128 << 20);
diff --git a/gfs2/mkfs/main_mkfs.c b/gfs2/mkfs/main_mkfs.c
index f650163..aaa9a2e 100644
--- a/gfs2/mkfs/main_mkfs.c
+++ b/gfs2/mkfs/main_mkfs.c
@@ -419,7 +419,10 @@ main_mkfs(int argc, char *argv[])
/* Get the device geometry */
device_size(sdp->device_fd, &real_device_size);
- device_geometry(sdp);
+ if (device_geometry(sdp)) {
+ fprintf(stderr, "Geometry error\n");
+ exit(-1);
+ }
/* Convert optional block-count to basic blocks */
if (sdp->orig_fssize) {
sdp->orig_fssize *= sdp->bsize;