Linux Archive

Linux Archive (http://www.linux-archive.org/)
-   Cluster Development (http://www.linux-archive.org/cluster-development/)
-   -   libgfs2: Expand out calls to die() (http://www.linux-archive.org/cluster-development/610119-libgfs2-expand-out-calls-die.html)

Andrew Price 12-14-2011 03:20 PM

libgfs2: Expand out calls to die()
 
Expand out the calls to die() to prepare for the removal of the function
from libgfs2.h

Signed-off-by: Andrew Price <anprice@redhat.com>
---
gfs2/libgfs2/fs_ops.c | 67 ++++++++++++++++++++++++++++++++-----------------
gfs2/libgfs2/gfs1.c | 12 ++++++---
2 files changed, 52 insertions(+), 27 deletions(-)

diff --git a/gfs2/libgfs2/fs_ops.c b/gfs2/libgfs2/fs_ops.c
index e2e64d6..befa25a 100644
--- a/gfs2/libgfs2/fs_ops.c
+++ b/gfs2/libgfs2/fs_ops.c
@@ -136,8 +136,10 @@ static uint64_t blk_alloc_i(struct gfs2_sbd *sdp, unsigned int type)
break;
}

- if (n == NULL)
- die("out of space
");
+ if (n == NULL) {
+ fprintf(stderr, "out of space
");
+ exit(1);
+ }

ri = &rl->ri;
rg = &rl->rg;
@@ -155,15 +157,18 @@ static uint64_t blk_alloc_i(struct gfs2_sbd *sdp, unsigned int type)
}
}

- die("allocation is broken (1): %"PRIu64" %u
",
+ fprintf(stderr, "allocation is broken (1): %"PRIu64" %u
",
(uint64_t)rl->ri.ri_addr, rl->rg.rg_free);
+ exit(1);

found:
- if (bn >= ri->ri_bitbytes * GFS2_NBBY)
- die("allocation is broken (2): bn: %u %u rgrp: %"PRIu64
+ if (bn >= ri->ri_bitbytes * GFS2_NBBY) {
+ fprintf(stderr, "allocation is broken (2): bn: %u %u rgrp: %"PRIu64
" (0x%" PRIx64 ") Free:%u
",
bn, ri->ri_bitbytes * GFS2_NBBY, (uint64_t)rl->ri.ri_addr,
(uint64_t)rl->ri.ri_addr, rl->rg.rg_free);
+ exit(1);
+ }

switch (type) {
case DATA:
@@ -175,7 +180,8 @@ found:
rg->rg_dinodes++;
break;
default:
- die("bad state
");
+ fprintf(stderr, "bad state
");
+ exit(1);
}

bh->b_data[x] &= ~(0x03 << (GFS2_BIT_SIZE * y));
@@ -684,8 +690,10 @@ struct gfs2_buffer_head *get_file_buf(struct gfs2_inode *ip, uint64_t lbn,
unstuff_dinode(ip);

block_map(ip, lbn, &new, &dbn, NULL, prealloc);
- if (!dbn)
- die("get_file_buf
");
+ if (!dbn) {
+ fprintf(stderr, "get_file_buf
");
+ exit(1);
+ }

if (!prealloc && new &&
ip->i_di.di_size < (lbn + 1) << sdp->sd_sb.sb_bsize_shift) {
@@ -841,8 +849,10 @@ void gfs2_get_leaf_nr(struct gfs2_inode *dip, uint32_t lindex,
return gfs_get_leaf_nr(dip, lindex, leaf_out);
count = gfs2_readi(dip, (char *)&leaf_no, lindex * sizeof(uint64_t),
sizeof(uint64_t));
- if (count != sizeof(uint64_t))
- die("gfs2_get_leaf_nr: Bad internal read.
");
+ if (count != sizeof(uint64_t)) {
+ fprintf(stderr, "gfs2_get_leaf_nr: Bad internal read.
");
+ exit(1);
+ }

*leaf_out = be64_to_cpu(leaf_no);
}
@@ -859,8 +869,10 @@ void gfs2_put_leaf_nr(struct gfs2_inode *dip, uint32_t inx, uint64_t leaf_out)
leaf_no = cpu_to_be64(leaf_out);
count = gfs2_writei(dip, (char *)&leaf_no, inx * sizeof(uint64_t),
sizeof(uint64_t));
- if (count != sizeof(uint64_t))
- die("gfs2_put_leaf_nr: Bad internal write.
");
+ if (count != sizeof(uint64_t)) {
+ fprintf(stderr, "gfs2_put_leaf_nr: Bad internal write.
");
+ exit(1);
+ }
}

static void dir_split_leaf(struct gfs2_inode *dip, uint32_t lindex,
@@ -912,8 +924,10 @@ static void dir_split_leaf(struct gfs2_inode *dip, uint32_t lindex,
else
count = gfs2_writei(dip, (char *)lp, start * sizeof(uint64_t),
half_len * sizeof(uint64_t));
- if (count != half_len * sizeof(uint64_t))
- die("dir_split_leaf (2)
");
+ if (count != half_len * sizeof(uint64_t)) {
+ fprintf(stderr, "dir_split_leaf (2)
");
+ exit(1);
+ }

free(lp);

@@ -930,8 +944,10 @@ static void dir_split_leaf(struct gfs2_inode *dip, uint32_t lindex,
be32_to_cpu(dent->de_hash) < divider) {
name_len = be16_to_cpu(dent->de_name_len);

- if (dirent_alloc(dip, nbh, name_len, &new))
- die("dir_split_leaf (3)
");
+ if (dirent_alloc(dip, nbh, name_len, &new)) {
+ fprintf(stderr, "dir_split_leaf (3)
");
+ exit(1);
+ }

new->de_inum = dent->de_inum;
new->de_hash = dent->de_hash;
@@ -954,8 +970,10 @@ static void dir_split_leaf(struct gfs2_inode *dip, uint32_t lindex,
} while (dent);

if (!moved) {
- if (dirent_alloc(dip, nbh, 0, &new))
- die("dir_split_leaf (4)
");
+ if (dirent_alloc(dip, nbh, 0, &new)) {
+ fprintf(stderr, "dir_split_leaf (4)
");
+ exit(1);
+ }
new->de_inum.no_formal_ino = 0;
/* Don't count the sentinel dirent as an entry */
dip->i_di.di_entries--;
@@ -993,8 +1011,10 @@ static void dir_double_exhash(struct gfs2_inode *dip)
count = gfs2_readi(dip, (char *)buf,
block * sdp->sd_hash_bsize,
sdp->sd_hash_bsize);
- if (count != sdp->sd_hash_bsize)
- die("dir_double_exhash (1)
");
+ if (count != sdp->sd_hash_bsize) {
+ fprintf(stderr, "dir_double_exhash (1)
");
+ exit(1);
+ }

from = buf;
to = (uint64_t *)((char *)buf + sdp->sd_hash_bsize);
@@ -1012,9 +1032,10 @@ static void dir_double_exhash(struct gfs2_inode *dip)
count = gfs2_writei(dip, (char *)buf +
sdp->sd_hash_bsize,
block * sdp->bsize, sdp->bsize);
- if (count != sdp->bsize)
- die("dir_double_exhash (2)
");
-
+ if (count != sdp->bsize) {
+ fprintf(stderr, "dir_double_exhash (2)
");
+ exit(1);
+ }
}

free(buf);
diff --git a/gfs2/libgfs2/gfs1.c b/gfs2/libgfs2/gfs1.c
index 4549959..8e3fc93 100644
--- a/gfs2/libgfs2/gfs1.c
+++ b/gfs2/libgfs2/gfs1.c
@@ -403,8 +403,10 @@ void gfs_get_leaf_nr(struct gfs2_inode *dip, uint32_t lindex,

count = gfs2_readi(dip, (char *)&leaf_no, lindex * sizeof(uint64_t),
sizeof(uint64_t));
- if (count != sizeof(uint64_t))
- die("gfs_get_leaf_nr: Bad internal read.
");
+ if (count != sizeof(uint64_t)) {
+ fprintf(stderr, "gfs_get_leaf_nr: Bad internal read.
");
+ exit(1);
+ }

*leaf_out = be64_to_cpu(leaf_no);
}
@@ -417,6 +419,8 @@ void gfs_put_leaf_nr(struct gfs2_inode *dip, uint32_t inx, uint64_t leaf_out)
leaf_no = cpu_to_be64(leaf_out);
count = gfs1_writei(dip, (char *)&leaf_no, inx * sizeof(uint64_t),
sizeof(uint64_t));
- if (count != sizeof(uint64_t))
- die("gfs_put_leaf_nr: Bad internal write.
");
+ if (count != sizeof(uint64_t)) {
+ fprintf(stderr, "gfs_put_leaf_nr: Bad internal write.
");
+ exit(1);
+ }
}
--
1.7.6.4

Bob Peterson 12-14-2011 03:23 PM

libgfs2: Expand out calls to die()
 
----- Original Message -----
| Expand out the calls to die() to prepare for the removal of the
| function
| from libgfs2.h
|
| Signed-off-by: Andrew Price <anprice@redhat.com>
| ---

Hi,

ACK

Bob Peterson
Red Hat File Systems

Steven Whitehouse 12-14-2011 03:41 PM

libgfs2: Expand out calls to die()
 
Hi,

Those look like a good start, but we also need to figure out how to push
the error handling back into the apps too,

Steve.

On Wed, 2011-12-14 at 16:20 +0000, Andrew Price wrote:
> Expand out the calls to die() to prepare for the removal of the function
> from libgfs2.h
>
> Signed-off-by: Andrew Price <anprice@redhat.com>
> ---
> gfs2/libgfs2/fs_ops.c | 67 ++++++++++++++++++++++++++++++++-----------------
> gfs2/libgfs2/gfs1.c | 12 ++++++---
> 2 files changed, 52 insertions(+), 27 deletions(-)
>
> diff --git a/gfs2/libgfs2/fs_ops.c b/gfs2/libgfs2/fs_ops.c
> index e2e64d6..befa25a 100644
> --- a/gfs2/libgfs2/fs_ops.c
> +++ b/gfs2/libgfs2/fs_ops.c
> @@ -136,8 +136,10 @@ static uint64_t blk_alloc_i(struct gfs2_sbd *sdp, unsigned int type)
> break;
> }
>
> - if (n == NULL)
> - die("out of space
");
> + if (n == NULL) {
> + fprintf(stderr, "out of space
");
> + exit(1);
> + }
>
> ri = &rl->ri;
> rg = &rl->rg;
> @@ -155,15 +157,18 @@ static uint64_t blk_alloc_i(struct gfs2_sbd *sdp, unsigned int type)
> }
> }
>
> - die("allocation is broken (1): %"PRIu64" %u
",
> + fprintf(stderr, "allocation is broken (1): %"PRIu64" %u
",
> (uint64_t)rl->ri.ri_addr, rl->rg.rg_free);
> + exit(1);
>
> found:
> - if (bn >= ri->ri_bitbytes * GFS2_NBBY)
> - die("allocation is broken (2): bn: %u %u rgrp: %"PRIu64
> + if (bn >= ri->ri_bitbytes * GFS2_NBBY) {
> + fprintf(stderr, "allocation is broken (2): bn: %u %u rgrp: %"PRIu64
> " (0x%" PRIx64 ") Free:%u
",
> bn, ri->ri_bitbytes * GFS2_NBBY, (uint64_t)rl->ri.ri_addr,
> (uint64_t)rl->ri.ri_addr, rl->rg.rg_free);
> + exit(1);
> + }
>
> switch (type) {
> case DATA:
> @@ -175,7 +180,8 @@ found:
> rg->rg_dinodes++;
> break;
> default:
> - die("bad state
");
> + fprintf(stderr, "bad state
");
> + exit(1);
> }
>
> bh->b_data[x] &= ~(0x03 << (GFS2_BIT_SIZE * y));
> @@ -684,8 +690,10 @@ struct gfs2_buffer_head *get_file_buf(struct gfs2_inode *ip, uint64_t lbn,
> unstuff_dinode(ip);
>
> block_map(ip, lbn, &new, &dbn, NULL, prealloc);
> - if (!dbn)
> - die("get_file_buf
");
> + if (!dbn) {
> + fprintf(stderr, "get_file_buf
");
> + exit(1);
> + }
>
> if (!prealloc && new &&
> ip->i_di.di_size < (lbn + 1) << sdp->sd_sb.sb_bsize_shift) {
> @@ -841,8 +849,10 @@ void gfs2_get_leaf_nr(struct gfs2_inode *dip, uint32_t lindex,
> return gfs_get_leaf_nr(dip, lindex, leaf_out);
> count = gfs2_readi(dip, (char *)&leaf_no, lindex * sizeof(uint64_t),
> sizeof(uint64_t));
> - if (count != sizeof(uint64_t))
> - die("gfs2_get_leaf_nr: Bad internal read.
");
> + if (count != sizeof(uint64_t)) {
> + fprintf(stderr, "gfs2_get_leaf_nr: Bad internal read.
");
> + exit(1);
> + }
>
> *leaf_out = be64_to_cpu(leaf_no);
> }
> @@ -859,8 +869,10 @@ void gfs2_put_leaf_nr(struct gfs2_inode *dip, uint32_t inx, uint64_t leaf_out)
> leaf_no = cpu_to_be64(leaf_out);
> count = gfs2_writei(dip, (char *)&leaf_no, inx * sizeof(uint64_t),
> sizeof(uint64_t));
> - if (count != sizeof(uint64_t))
> - die("gfs2_put_leaf_nr: Bad internal write.
");
> + if (count != sizeof(uint64_t)) {
> + fprintf(stderr, "gfs2_put_leaf_nr: Bad internal write.
");
> + exit(1);
> + }
> }
>
> static void dir_split_leaf(struct gfs2_inode *dip, uint32_t lindex,
> @@ -912,8 +924,10 @@ static void dir_split_leaf(struct gfs2_inode *dip, uint32_t lindex,
> else
> count = gfs2_writei(dip, (char *)lp, start * sizeof(uint64_t),
> half_len * sizeof(uint64_t));
> - if (count != half_len * sizeof(uint64_t))
> - die("dir_split_leaf (2)
");
> + if (count != half_len * sizeof(uint64_t)) {
> + fprintf(stderr, "dir_split_leaf (2)
");
> + exit(1);
> + }
>
> free(lp);
>
> @@ -930,8 +944,10 @@ static void dir_split_leaf(struct gfs2_inode *dip, uint32_t lindex,
> be32_to_cpu(dent->de_hash) < divider) {
> name_len = be16_to_cpu(dent->de_name_len);
>
> - if (dirent_alloc(dip, nbh, name_len, &new))
> - die("dir_split_leaf (3)
");
> + if (dirent_alloc(dip, nbh, name_len, &new)) {
> + fprintf(stderr, "dir_split_leaf (3)
");
> + exit(1);
> + }
>
> new->de_inum = dent->de_inum;
> new->de_hash = dent->de_hash;
> @@ -954,8 +970,10 @@ static void dir_split_leaf(struct gfs2_inode *dip, uint32_t lindex,
> } while (dent);
>
> if (!moved) {
> - if (dirent_alloc(dip, nbh, 0, &new))
> - die("dir_split_leaf (4)
");
> + if (dirent_alloc(dip, nbh, 0, &new)) {
> + fprintf(stderr, "dir_split_leaf (4)
");
> + exit(1);
> + }
> new->de_inum.no_formal_ino = 0;
> /* Don't count the sentinel dirent as an entry */
> dip->i_di.di_entries--;
> @@ -993,8 +1011,10 @@ static void dir_double_exhash(struct gfs2_inode *dip)
> count = gfs2_readi(dip, (char *)buf,
> block * sdp->sd_hash_bsize,
> sdp->sd_hash_bsize);
> - if (count != sdp->sd_hash_bsize)
> - die("dir_double_exhash (1)
");
> + if (count != sdp->sd_hash_bsize) {
> + fprintf(stderr, "dir_double_exhash (1)
");
> + exit(1);
> + }
>
> from = buf;
> to = (uint64_t *)((char *)buf + sdp->sd_hash_bsize);
> @@ -1012,9 +1032,10 @@ static void dir_double_exhash(struct gfs2_inode *dip)
> count = gfs2_writei(dip, (char *)buf +
> sdp->sd_hash_bsize,
> block * sdp->bsize, sdp->bsize);
> - if (count != sdp->bsize)
> - die("dir_double_exhash (2)
");
> -
> + if (count != sdp->bsize) {
> + fprintf(stderr, "dir_double_exhash (2)
");
> + exit(1);
> + }
> }
>
> free(buf);
> diff --git a/gfs2/libgfs2/gfs1.c b/gfs2/libgfs2/gfs1.c
> index 4549959..8e3fc93 100644
> --- a/gfs2/libgfs2/gfs1.c
> +++ b/gfs2/libgfs2/gfs1.c
> @@ -403,8 +403,10 @@ void gfs_get_leaf_nr(struct gfs2_inode *dip, uint32_t lindex,
>
> count = gfs2_readi(dip, (char *)&leaf_no, lindex * sizeof(uint64_t),
> sizeof(uint64_t));
> - if (count != sizeof(uint64_t))
> - die("gfs_get_leaf_nr: Bad internal read.
");
> + if (count != sizeof(uint64_t)) {
> + fprintf(stderr, "gfs_get_leaf_nr: Bad internal read.
");
> + exit(1);
> + }
>
> *leaf_out = be64_to_cpu(leaf_no);
> }
> @@ -417,6 +419,8 @@ void gfs_put_leaf_nr(struct gfs2_inode *dip, uint32_t inx, uint64_t leaf_out)
> leaf_no = cpu_to_be64(leaf_out);
> count = gfs1_writei(dip, (char *)&leaf_no, inx * sizeof(uint64_t),
> sizeof(uint64_t));
> - if (count != sizeof(uint64_t))
> - die("gfs_put_leaf_nr: Bad internal write.
");
> + if (count != sizeof(uint64_t)) {
> + fprintf(stderr, "gfs_put_leaf_nr: Bad internal write.
");
> + exit(1);
> + }
> }

Andrew Price 12-14-2011 04:14 PM

libgfs2: Expand out calls to die()
 
On 14/12/11 16:41, Steven Whitehouse wrote:

Hi,

Those look like a good start, but we also need to figure out how to push
the error handling back into the apps too,


Yes, I made a tentative start on this a while ago. Each libgfs2 function
which calls exit() will need all of its callers (and their callers, and
their...) updating so it's going to take a fair deal more work.


If we're agreed on the convention of setting errno and returning
non-zero (or non-valid values) to flag errors, then the way forward is
reasonably clear.


Andy

Steven Whitehouse 12-14-2011 04:22 PM

libgfs2: Expand out calls to die()
 
Hi,

On Wed, 2011-12-14 at 17:14 +0000, Andrew Price wrote:
> On 14/12/11 16:41, Steven Whitehouse wrote:
> > Hi,
> >
> > Those look like a good start, but we also need to figure out how to push
> > the error handling back into the apps too,
>
> Yes, I made a tentative start on this a while ago. Each libgfs2 function
> which calls exit() will need all of its callers (and their callers, and
> their...) updating so it's going to take a fair deal more work.
>
> If we're agreed on the convention of setting errno and returning
> non-zero (or non-valid values) to flag errors, then the way forward is
> reasonably clear.
>
> Andy

Yes, I think that is a good way to do it. The only issues are likely to
arise when it is not obvious from this method exactly what has gone
wrong. In some cases this is due to doing the checks in the wrong place,
or there is some other complication. So its just a case of converting
things bit by bit and checking each place individually, which does make
it a rather slow job, but I'm not sure there is much alternative,

Steve.


All times are GMT. The time now is 09:07 AM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.