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 10-04-2011, 05:44 PM
Carlos Maiolino
 
Default gfs2_jadd: Fix error handlers

This patch fixes some error handlers, taking
advantage of glic on most places where an error
check is needed.

Signed-off-by: Carlos Maiolino <cmaiolino@redhat.com>
---
gfs2/mkfs/main_jadd.c | 141 +++++++++++++++++++++---------------------------
1 files changed, 62 insertions(+), 79 deletions(-)

diff --git a/gfs2/mkfs/main_jadd.c b/gfs2/mkfs/main_jadd.c
index d722d52..6773384 100644
--- a/gfs2/mkfs/main_jadd.c
+++ b/gfs2/mkfs/main_jadd.c
@@ -34,15 +34,21 @@ make_jdata(int fd, const char *value)
uint32_t val;

err = ioctl(fd, FS_IOC_GETFLAGS, &val);
- if (err)
- die( _("error doing get flags (%d): %s
"), err, strerror(errno));
+ if (err){
+ perror("GETFLAGS");
+ exit(EXIT_FAILURE);
+ }
+
if (strcmp(value, "set") == 0)
val |= FS_JOURNAL_DATA_FL;
if (strcmp(value, "clear") == 0)
val &= ~FS_JOURNAL_DATA_FL;
err = ioctl(fd, FS_IOC_SETFLAGS, &val);
- if (err)
- die( _("error doing set flags (%d): %s
"), err, strerror(errno));
+
+ if (err){
+ perror("SETFLAGS");
+ exit(EXIT_FAILURE);
+ }
}

static int
@@ -212,10 +218,9 @@ create_new_inode(struct gfs2_sbd *sdp)
if (errno == EEXIST) {
error = unlink(name);
if (error)
- die( _("can't unlink %s: %s
"),
- name, strerror(errno));
+ perror("unlink");
} else
- die( _("can't create %s: %s
"), name, strerror(errno));
+ perror("create");
}

return fd;
@@ -236,10 +241,8 @@ add_ir(struct gfs2_sbd *sdp)
memset(&ir, 0, sizeof(struct gfs2_inum_range));
if (write(fd, (void*)&ir, sizeof(struct gfs2_inum_range)) !=
sizeof(struct gfs2_inum_range)) {
- fprintf(stderr, _( "write error: %s from %s:%d: "
- "offset 0
"), strerror(errno),
- __FUNCTION__, __LINE__);
- exit(-1);
+ perror("add_ir");
+ exit(EXIT_FAILURE);
}
}

@@ -247,9 +250,10 @@ add_ir(struct gfs2_sbd *sdp)

sprintf(new_name, "inum_range%u", sdp->md.journals);
error = rename2system(sdp, "per_node", new_name);
- if (error < 0 && errno != EEXIST)
- die( _("can't rename2system %s (%d): %s
"),
- new_name, error, strerror(errno));
+ if (error < 0 && errno != EEXIST){
+ perror("add_ir rename2system");
+ exit(EXIT_FAILURE);
+ }
}

static void
@@ -268,10 +272,8 @@ add_sc(struct gfs2_sbd *sdp)
memset(&sc, 0, sizeof(struct gfs2_statfs_change));
if (write(fd, (void*)&sc, sizeof(struct gfs2_statfs_change)) !=
sizeof(struct gfs2_statfs_change)) {
- fprintf(stderr, _("write error: %s from %s:%d: "
- "offset 0
"), strerror(errno),
- __FUNCTION__, __LINE__);
- exit(-1);
+ perror("add_sc");
+ exit(EXIT_FAILURE);
}
}

@@ -279,9 +281,10 @@ add_sc(struct gfs2_sbd *sdp)

sprintf(new_name, "statfs_change%u", sdp->md.journals);
error = rename2system(sdp, "per_node", new_name);
- if (error < 0 && errno != EEXIST)
- die( _("can't rename2system %s (%d): %s
"),
- new_name, error, strerror(errno));
+ if (error < 0 && errno != EEXIST){
+ perror("add_sc rename2system");
+ exit(EXIT_FAILURE);
+ }
}

static void
@@ -307,13 +310,8 @@ add_qc(struct gfs2_sbd *sdp)

for (x=0; x<blocks; x++) {
if (write(fd, buf, sdp->bsize) != sdp->bsize) {
- fprintf(stderr, _("write error: %s from %s:%d: "
- "block %lld (0x%llx)
"),
- strerror(errno),
- __FUNCTION__, __LINE__,
- (unsigned long long)x,
- (unsigned long long)x);
- exit(-1);
+ perror("add_qc");
+ exit(EXIT_FAILURE);
}
}

@@ -327,29 +325,26 @@ add_qc(struct gfs2_sbd *sdp)

for (x=0; x<blocks; x++) {
if (write(fd, buf, sdp->bsize) != sdp->bsize) {
- fprintf(stderr, _("write error: %s from %s:%d: "
- "block %lld (0x%llx)
"),
- strerror(errno),
- __FUNCTION__, __LINE__,
- (unsigned long long)x,
- (unsigned long long)x);
- exit(-1);
+ perror("add_qc");
+ exit(EXIT_FAILURE);
}
}

error = fsync(fd);
- if (error)
- die( _("can't fsync: %s
"),
- strerror(errno));
+ if (error){
+ perror("add_qc fsync");
+ exit(EXIT_FAILURE);
+ }
}

close(fd);

sprintf(new_name, "quota_change%u", sdp->md.journals);
error = rename2system(sdp, "per_node", new_name);
- if (error < 0 && errno != EEXIST)
- die( _("can't rename2system %s (%d): %s
"),
- new_name, error, strerror(errno));
+ if (error < 0 && errno != EEXIST){
+ perror("add_qc rename2system");
+ exit(EXIT_FAILURE);
+ }
}

static void
@@ -357,8 +352,8 @@ gather_info(struct gfs2_sbd *sdp)
{
struct statfs statbuf;
if (statfs(sdp->path_name, &statbuf) < 0) {
- die( _("Could not statfs the filesystem %s: %s
"),
- sdp->path_name, strerror(errno));
+ perror(sdp->path_name);
+ exit(EXIT_FAILURE);
}
sdp->bsize = statbuf.f_bsize;
}
@@ -374,8 +369,8 @@ find_current_journals(struct gfs2_sbd *sdp)
sprintf(jindex, "%s/jindex", sdp->metafs_path);
dirp = opendir(jindex);
if (!dirp) {
- die( _("Could not find the jindex directory "
- "in gfs2meta mount! error: %s
"), strerror(errno));
+ perror("jindex");
+ exit(EXIT_FAILURE);
}
while (dirp) {
if ((dp = readdir(dirp)) != NULL) {
@@ -415,13 +410,8 @@ add_j(struct gfs2_sbd *sdp)
memset(buf, 0, sdp->bsize);
for (x=0; x<blocks; x++) {
if (write(fd, buf, sdp->bsize) != sdp->bsize) {
- fprintf(stderr, _("write error: %s from %s:%d: "
- "block %lld (0x%llx)
"),
- strerror(errno),
- __FUNCTION__, __LINE__,
- (unsigned long long)x,
- (unsigned long long)x);
- exit(-1);
+ perror("add_j");
+ exit(EXIT_FAILURE);
}
}

@@ -445,13 +435,8 @@ add_j(struct gfs2_sbd *sdp)
((struct gfs2_log_header *)buf)->lh_hash = cpu_to_be32(hash);

if (write(fd, buf, sdp->bsize) != sdp->bsize) {
- fprintf(stderr, _("write error: %s from %s:%d: "
- "block %lld (0x%llx)
"),
- strerror(errno),
- __FUNCTION__, __LINE__,
- (unsigned long long)x,
- (unsigned long long)x);
- exit(-1);
+ perror("add_j");
+ exit(EXIT_FAILURE);
}

if (++seq == blocks)
@@ -459,18 +444,20 @@ add_j(struct gfs2_sbd *sdp)
}

error = fsync(fd);
- if (error)
- die( _("can't fsync: %s
"),
- strerror(errno));
+ if (error){
+ perror("add_j fsync");
+ exit(EXIT_FAILURE);
+ }
}

close(fd);

sprintf(new_name, "journal%u", sdp->md.journals);
error = rename2system(sdp, "jindex", new_name);
- if (error < 0 && errno != EEXIST)
- die( _("can't rename2system %s (%d): %s
"),
- new_name, error, strerror(errno));
+ if (error < 0 && errno != EEXIST){
+ perror("add_j rename2system");
+ exit(EXIT_FAILURE);
+ }
}

/**
@@ -494,30 +481,26 @@ void main_jadd(int argc, char *argv[])
verify_arguments(sdp);

sdp->path_fd = open(sdp->path_name, O_RDONLY | O_CLOEXEC);
- if (sdp->path_fd < 0)
- die( _("can't open root directory %s: %s
"),
- sdp->path_name, strerror(errno));
+ if (sdp->path_fd < 0){
+ perror(sdp->path_name);
+ exit(EXIT_FAILURE);
+ }

if (check_for_gfs2(sdp)) {
- if (errno == EINVAL)
- fprintf(stderr, _("Not a valid GFS2 mount point: %s
"),
- sdp->path_name);
- else
- fprintf(stderr, "%s
", strerror(errno));
- exit(-1);
+ perror(sdp->path_name);
+ exit(EXIT_FAILURE);
}

gather_info(sdp);

if (mount_gfs2_meta(sdp)) {
- fprintf(stderr, _("Error mounting GFS2 metafs: %s
"),
- strerror(errno));
- exit(-1);
+ perror("GFS2 metafs");
+ exit(EXIT_FAILURE);
}

if (compute_constants(sdp)) {
- fprintf(stderr, _("Bad constants (1)
"));
- exit(-1);
+ perror(_("Bad constants (1)"));
+ exit(EXIT_FAILURE);
}
find_current_journals(sdp);

--
1.7.6.2
 
Old 10-04-2011, 06:16 PM
Carlos Maiolino
 
Default gfs2_jadd: Fix error handlers

This patch fixes some error handlers, taking
advantage of glic on most places where an error
check is needed.
Also, it adds some exit() calls missing in mkfs
and gfs2_grow

Signed-off-by: Carlos Maiolino <cmaiolino@redhat.com>
---
gfs2/mkfs/main_grow.c | 8 ++-
gfs2/mkfs/main_jadd.c | 149 ++++++++++++++++++++++--------------------------
gfs2/mkfs/main_mkfs.c | 8 ++-
3 files changed, 80 insertions(+), 85 deletions(-)

diff --git a/gfs2/mkfs/main_grow.c b/gfs2/mkfs/main_grow.c
index c48497f..f6d7bf0 100644
--- a/gfs2/mkfs/main_grow.c
+++ b/gfs2/mkfs/main_grow.c
@@ -310,8 +310,10 @@ main_grow(int argc, char *argv[])

sdp->path_name = argv[optind++];
sdp->path_fd = open(sdp->path_name, O_RDONLY | O_CLOEXEC);
- if (sdp->path_fd < 0)
+ if (sdp->path_fd < 0){
perror(sdp->path_name);
+ exit(EXIT_FAILURE);
+ }

if (check_for_gfs2(sdp)) {
perror(sdp->path_name);
@@ -319,8 +321,10 @@ main_grow(int argc, char *argv[])
}
sdp->device_fd = open(sdp->device_name,
(test ? O_RDONLY : O_RDWR) | O_CLOEXEC);
- if (sdp->device_fd < 0)
+ if (sdp->device_fd < 0){
perror(sdp->device_name);
+ exit(EXIT_FAILURE);
+ }

if (device_geometry(sdp)) {
perror(_("Device geometry error"));
diff --git a/gfs2/mkfs/main_jadd.c b/gfs2/mkfs/main_jadd.c
index d722d52..e060cc2 100644
--- a/gfs2/mkfs/main_jadd.c
+++ b/gfs2/mkfs/main_jadd.c
@@ -34,15 +34,21 @@ make_jdata(int fd, const char *value)
uint32_t val;

err = ioctl(fd, FS_IOC_GETFLAGS, &val);
- if (err)
- die( _("error doing get flags (%d): %s
"), err, strerror(errno));
+ if (err){
+ perror("GETFLAGS");
+ exit(EXIT_FAILURE);
+ }
+
if (strcmp(value, "set") == 0)
val |= FS_JOURNAL_DATA_FL;
if (strcmp(value, "clear") == 0)
val &= ~FS_JOURNAL_DATA_FL;
err = ioctl(fd, FS_IOC_SETFLAGS, &val);
- if (err)
- die( _("error doing set flags (%d): %s
"), err, strerror(errno));
+
+ if (err){
+ perror("SETFLAGS");
+ exit(EXIT_FAILURE);
+ }
}

static int
@@ -211,11 +217,14 @@ create_new_inode(struct gfs2_sbd *sdp)
break;
if (errno == EEXIST) {
error = unlink(name);
- if (error)
- die( _("can't unlink %s: %s
"),
- name, strerror(errno));
- } else
- die( _("can't create %s: %s
"), name, strerror(errno));
+ if (error){
+ perror("unlink");
+ exit(EXIT_FAILURE);
+ }
+ } else{
+ perror("create");
+ exit(EXIT_FAILURE);
+ }
}

return fd;
@@ -236,10 +245,8 @@ add_ir(struct gfs2_sbd *sdp)
memset(&ir, 0, sizeof(struct gfs2_inum_range));
if (write(fd, (void*)&ir, sizeof(struct gfs2_inum_range)) !=
sizeof(struct gfs2_inum_range)) {
- fprintf(stderr, _( "write error: %s from %s:%d: "
- "offset 0
"), strerror(errno),
- __FUNCTION__, __LINE__);
- exit(-1);
+ perror("add_ir");
+ exit(EXIT_FAILURE);
}
}

@@ -247,9 +254,10 @@ add_ir(struct gfs2_sbd *sdp)

sprintf(new_name, "inum_range%u", sdp->md.journals);
error = rename2system(sdp, "per_node", new_name);
- if (error < 0 && errno != EEXIST)
- die( _("can't rename2system %s (%d): %s
"),
- new_name, error, strerror(errno));
+ if (error < 0 && errno != EEXIST){
+ perror("add_ir rename2system");
+ exit(EXIT_FAILURE);
+ }
}

static void
@@ -268,10 +276,8 @@ add_sc(struct gfs2_sbd *sdp)
memset(&sc, 0, sizeof(struct gfs2_statfs_change));
if (write(fd, (void*)&sc, sizeof(struct gfs2_statfs_change)) !=
sizeof(struct gfs2_statfs_change)) {
- fprintf(stderr, _("write error: %s from %s:%d: "
- "offset 0
"), strerror(errno),
- __FUNCTION__, __LINE__);
- exit(-1);
+ perror("add_sc");
+ exit(EXIT_FAILURE);
}
}

@@ -279,9 +285,10 @@ add_sc(struct gfs2_sbd *sdp)

sprintf(new_name, "statfs_change%u", sdp->md.journals);
error = rename2system(sdp, "per_node", new_name);
- if (error < 0 && errno != EEXIST)
- die( _("can't rename2system %s (%d): %s
"),
- new_name, error, strerror(errno));
+ if (error < 0 && errno != EEXIST){
+ perror("add_sc rename2system");
+ exit(EXIT_FAILURE);
+ }
}

static void
@@ -307,13 +314,8 @@ add_qc(struct gfs2_sbd *sdp)

for (x=0; x<blocks; x++) {
if (write(fd, buf, sdp->bsize) != sdp->bsize) {
- fprintf(stderr, _("write error: %s from %s:%d: "
- "block %lld (0x%llx)
"),
- strerror(errno),
- __FUNCTION__, __LINE__,
- (unsigned long long)x,
- (unsigned long long)x);
- exit(-1);
+ perror("add_qc");
+ exit(EXIT_FAILURE);
}
}

@@ -327,29 +329,26 @@ add_qc(struct gfs2_sbd *sdp)

for (x=0; x<blocks; x++) {
if (write(fd, buf, sdp->bsize) != sdp->bsize) {
- fprintf(stderr, _("write error: %s from %s:%d: "
- "block %lld (0x%llx)
"),
- strerror(errno),
- __FUNCTION__, __LINE__,
- (unsigned long long)x,
- (unsigned long long)x);
- exit(-1);
+ perror("add_qc");
+ exit(EXIT_FAILURE);
}
}

error = fsync(fd);
- if (error)
- die( _("can't fsync: %s
"),
- strerror(errno));
+ if (error){
+ perror("add_qc fsync");
+ exit(EXIT_FAILURE);
+ }
}

close(fd);

sprintf(new_name, "quota_change%u", sdp->md.journals);
error = rename2system(sdp, "per_node", new_name);
- if (error < 0 && errno != EEXIST)
- die( _("can't rename2system %s (%d): %s
"),
- new_name, error, strerror(errno));
+ if (error < 0 && errno != EEXIST){
+ perror("add_qc rename2system");
+ exit(EXIT_FAILURE);
+ }
}

static void
@@ -357,8 +356,8 @@ gather_info(struct gfs2_sbd *sdp)
{
struct statfs statbuf;
if (statfs(sdp->path_name, &statbuf) < 0) {
- die( _("Could not statfs the filesystem %s: %s
"),
- sdp->path_name, strerror(errno));
+ perror(sdp->path_name);
+ exit(EXIT_FAILURE);
}
sdp->bsize = statbuf.f_bsize;
}
@@ -374,8 +373,8 @@ find_current_journals(struct gfs2_sbd *sdp)
sprintf(jindex, "%s/jindex", sdp->metafs_path);
dirp = opendir(jindex);
if (!dirp) {
- die( _("Could not find the jindex directory "
- "in gfs2meta mount! error: %s
"), strerror(errno));
+ perror("jindex");
+ exit(EXIT_FAILURE);
}
while (dirp) {
if ((dp = readdir(dirp)) != NULL) {
@@ -415,13 +414,8 @@ add_j(struct gfs2_sbd *sdp)
memset(buf, 0, sdp->bsize);
for (x=0; x<blocks; x++) {
if (write(fd, buf, sdp->bsize) != sdp->bsize) {
- fprintf(stderr, _("write error: %s from %s:%d: "
- "block %lld (0x%llx)
"),
- strerror(errno),
- __FUNCTION__, __LINE__,
- (unsigned long long)x,
- (unsigned long long)x);
- exit(-1);
+ perror("add_j");
+ exit(EXIT_FAILURE);
}
}

@@ -445,13 +439,8 @@ add_j(struct gfs2_sbd *sdp)
((struct gfs2_log_header *)buf)->lh_hash = cpu_to_be32(hash);

if (write(fd, buf, sdp->bsize) != sdp->bsize) {
- fprintf(stderr, _("write error: %s from %s:%d: "
- "block %lld (0x%llx)
"),
- strerror(errno),
- __FUNCTION__, __LINE__,
- (unsigned long long)x,
- (unsigned long long)x);
- exit(-1);
+ perror("add_j");
+ exit(EXIT_FAILURE);
}

if (++seq == blocks)
@@ -459,18 +448,20 @@ add_j(struct gfs2_sbd *sdp)
}

error = fsync(fd);
- if (error)
- die( _("can't fsync: %s
"),
- strerror(errno));
+ if (error){
+ perror("add_j fsync");
+ exit(EXIT_FAILURE);
+ }
}

close(fd);

sprintf(new_name, "journal%u", sdp->md.journals);
error = rename2system(sdp, "jindex", new_name);
- if (error < 0 && errno != EEXIST)
- die( _("can't rename2system %s (%d): %s
"),
- new_name, error, strerror(errno));
+ if (error < 0 && errno != EEXIST){
+ perror("add_j rename2system");
+ exit(EXIT_FAILURE);
+ }
}

/**
@@ -494,30 +485,26 @@ void main_jadd(int argc, char *argv[])
verify_arguments(sdp);

sdp->path_fd = open(sdp->path_name, O_RDONLY | O_CLOEXEC);
- if (sdp->path_fd < 0)
- die( _("can't open root directory %s: %s
"),
- sdp->path_name, strerror(errno));
+ if (sdp->path_fd < 0){
+ perror(sdp->path_name);
+ exit(EXIT_FAILURE);
+ }

if (check_for_gfs2(sdp)) {
- if (errno == EINVAL)
- fprintf(stderr, _("Not a valid GFS2 mount point: %s
"),
- sdp->path_name);
- else
- fprintf(stderr, "%s
", strerror(errno));
- exit(-1);
+ perror(sdp->path_name);
+ exit(EXIT_FAILURE);
}

gather_info(sdp);

if (mount_gfs2_meta(sdp)) {
- fprintf(stderr, _("Error mounting GFS2 metafs: %s
"),
- strerror(errno));
- exit(-1);
+ perror("GFS2 metafs");
+ exit(EXIT_FAILURE);
}

if (compute_constants(sdp)) {
- fprintf(stderr, _("Bad constants (1)
"));
- exit(-1);
+ perror(_("Bad constants (1)"));
+ exit(EXIT_FAILURE);
}
find_current_journals(sdp);

diff --git a/gfs2/mkfs/main_mkfs.c b/gfs2/mkfs/main_mkfs.c
index 771feba..6de1d12 100644
--- a/gfs2/mkfs/main_mkfs.c
+++ b/gfs2/mkfs/main_mkfs.c
@@ -683,13 +683,17 @@ void main_mkfs(int argc, char *argv[])
gfs2_rgrp_free(&sdp->rgtree);
error = fsync(sdp->device_fd);

- if (error)
+ if (error){
perror(sdp->device_name);
+ exit(EXIT_FAILURE);
+ }

error = close(sdp->device_fd);

- if (error)
+ if (error){
perror(sdp->device_name);
+ exit(EXIT_FAILURE);
+ }

print_results(sdp, real_device_size, uuid);
}
--
1.7.6.2
 
Old 10-04-2011, 06:23 PM
Bob Peterson
 
Default gfs2_jadd: Fix error handlers

----- Original Message -----
| This patch fixes some error handlers, taking
| advantage of glic on most places where an error
| check is needed.
| Also, it adds some exit() calls missing in mkfs
| and gfs2_grow
|
| Signed-off-by: Carlos Maiolino <cmaiolino@redhat.com>
| ---

Hi,

ACK. Looks good. Go ahead and push it.

Regards,

Bob Peterson
Red Hat File Systems
 
Old 10-04-2011, 07:05 PM
Steven Whitehouse
 
Default gfs2_jadd: Fix error handlers

Hi,

On Tue, 2011-10-04 at 14:44 -0300, Carlos Maiolino wrote:
> This patch fixes some error handlers, taking
> advantage of glic on most places where an error
> check is needed.
>
> Signed-off-by: Carlos Maiolino <cmaiolino@redhat.com>
> ---
> gfs2/mkfs/main_jadd.c | 141 +++++++++++++++++++++---------------------------
> 1 files changed, 62 insertions(+), 79 deletions(-)
>
> diff --git a/gfs2/mkfs/main_jadd.c b/gfs2/mkfs/main_jadd.c
> index d722d52..6773384 100644
> --- a/gfs2/mkfs/main_jadd.c
> +++ b/gfs2/mkfs/main_jadd.c
> @@ -34,15 +34,21 @@ make_jdata(int fd, const char *value)
> uint32_t val;
>
> err = ioctl(fd, FS_IOC_GETFLAGS, &val);
> - if (err)
> - die( _("error doing get flags (%d): %s
"), err, strerror(errno));
> + if (err){
> + perror("GETFLAGS");
> + exit(EXIT_FAILURE);
> + }
> +
> if (strcmp(value, "set") == 0)
> val |= FS_JOURNAL_DATA_FL;
> if (strcmp(value, "clear") == 0)
> val &= ~FS_JOURNAL_DATA_FL;
> err = ioctl(fd, FS_IOC_SETFLAGS, &val);
> - if (err)
> - die( _("error doing set flags (%d): %s
"), err, strerror(errno));
> +
> + if (err){
> + perror("SETFLAGS");
> + exit(EXIT_FAILURE);
> + }
> }
>
> static int
> @@ -212,10 +218,9 @@ create_new_inode(struct gfs2_sbd *sdp)
> if (errno == EEXIST) {
> error = unlink(name);
> if (error)
> - die( _("can't unlink %s: %s
"),
> - name, strerror(errno));
> + perror("unlink");
> } else
> - die( _("can't create %s: %s
"), name, strerror(errno));
> + perror("create");
> }
In this case you should be passing the name that couldn't be created
rather than the string "create" to perror. Otherwise the user won't know
what the message refers to,

Steve.

>
> return fd;
> @@ -236,10 +241,8 @@ add_ir(struct gfs2_sbd *sdp)
> memset(&ir, 0, sizeof(struct gfs2_inum_range));
> if (write(fd, (void*)&ir, sizeof(struct gfs2_inum_range)) !=
> sizeof(struct gfs2_inum_range)) {
> - fprintf(stderr, _( "write error: %s from %s:%d: "
> - "offset 0
"), strerror(errno),
> - __FUNCTION__, __LINE__);
> - exit(-1);
> + perror("add_ir");
> + exit(EXIT_FAILURE);
> }
> }
>
> @@ -247,9 +250,10 @@ add_ir(struct gfs2_sbd *sdp)
>
> sprintf(new_name, "inum_range%u", sdp->md.journals);
> error = rename2system(sdp, "per_node", new_name);
> - if (error < 0 && errno != EEXIST)
> - die( _("can't rename2system %s (%d): %s
"),
> - new_name, error, strerror(errno));
> + if (error < 0 && errno != EEXIST){
> + perror("add_ir rename2system");
> + exit(EXIT_FAILURE);
> + }
> }
>
> static void
> @@ -268,10 +272,8 @@ add_sc(struct gfs2_sbd *sdp)
> memset(&sc, 0, sizeof(struct gfs2_statfs_change));
> if (write(fd, (void*)&sc, sizeof(struct gfs2_statfs_change)) !=
> sizeof(struct gfs2_statfs_change)) {
> - fprintf(stderr, _("write error: %s from %s:%d: "
> - "offset 0
"), strerror(errno),
> - __FUNCTION__, __LINE__);
> - exit(-1);
> + perror("add_sc");
> + exit(EXIT_FAILURE);
> }
> }
>
> @@ -279,9 +281,10 @@ add_sc(struct gfs2_sbd *sdp)
>
> sprintf(new_name, "statfs_change%u", sdp->md.journals);
> error = rename2system(sdp, "per_node", new_name);
> - if (error < 0 && errno != EEXIST)
> - die( _("can't rename2system %s (%d): %s
"),
> - new_name, error, strerror(errno));
> + if (error < 0 && errno != EEXIST){
> + perror("add_sc rename2system");
> + exit(EXIT_FAILURE);
> + }
> }
>
> static void
> @@ -307,13 +310,8 @@ add_qc(struct gfs2_sbd *sdp)
>
> for (x=0; x<blocks; x++) {
> if (write(fd, buf, sdp->bsize) != sdp->bsize) {
> - fprintf(stderr, _("write error: %s from %s:%d: "
> - "block %lld (0x%llx)
"),
> - strerror(errno),
> - __FUNCTION__, __LINE__,
> - (unsigned long long)x,
> - (unsigned long long)x);
> - exit(-1);
> + perror("add_qc");
> + exit(EXIT_FAILURE);
> }
> }
>
> @@ -327,29 +325,26 @@ add_qc(struct gfs2_sbd *sdp)
>
> for (x=0; x<blocks; x++) {
> if (write(fd, buf, sdp->bsize) != sdp->bsize) {
> - fprintf(stderr, _("write error: %s from %s:%d: "
> - "block %lld (0x%llx)
"),
> - strerror(errno),
> - __FUNCTION__, __LINE__,
> - (unsigned long long)x,
> - (unsigned long long)x);
> - exit(-1);
> + perror("add_qc");
> + exit(EXIT_FAILURE);
> }
> }
>
> error = fsync(fd);
> - if (error)
> - die( _("can't fsync: %s
"),
> - strerror(errno));
> + if (error){
> + perror("add_qc fsync");
> + exit(EXIT_FAILURE);
> + }
> }
>
> close(fd);
>
> sprintf(new_name, "quota_change%u", sdp->md.journals);
> error = rename2system(sdp, "per_node", new_name);
> - if (error < 0 && errno != EEXIST)
> - die( _("can't rename2system %s (%d): %s
"),
> - new_name, error, strerror(errno));
> + if (error < 0 && errno != EEXIST){
> + perror("add_qc rename2system");
> + exit(EXIT_FAILURE);
> + }
> }
>
> static void
> @@ -357,8 +352,8 @@ gather_info(struct gfs2_sbd *sdp)
> {
> struct statfs statbuf;
> if (statfs(sdp->path_name, &statbuf) < 0) {
> - die( _("Could not statfs the filesystem %s: %s
"),
> - sdp->path_name, strerror(errno));
> + perror(sdp->path_name);
> + exit(EXIT_FAILURE);
> }
> sdp->bsize = statbuf.f_bsize;
> }
> @@ -374,8 +369,8 @@ find_current_journals(struct gfs2_sbd *sdp)
> sprintf(jindex, "%s/jindex", sdp->metafs_path);
> dirp = opendir(jindex);
> if (!dirp) {
> - die( _("Could not find the jindex directory "
> - "in gfs2meta mount! error: %s
"), strerror(errno));
> + perror("jindex");
> + exit(EXIT_FAILURE);
> }
> while (dirp) {
> if ((dp = readdir(dirp)) != NULL) {
> @@ -415,13 +410,8 @@ add_j(struct gfs2_sbd *sdp)
> memset(buf, 0, sdp->bsize);
> for (x=0; x<blocks; x++) {
> if (write(fd, buf, sdp->bsize) != sdp->bsize) {
> - fprintf(stderr, _("write error: %s from %s:%d: "
> - "block %lld (0x%llx)
"),
> - strerror(errno),
> - __FUNCTION__, __LINE__,
> - (unsigned long long)x,
> - (unsigned long long)x);
> - exit(-1);
> + perror("add_j");
> + exit(EXIT_FAILURE);
> }
> }
>
> @@ -445,13 +435,8 @@ add_j(struct gfs2_sbd *sdp)
> ((struct gfs2_log_header *)buf)->lh_hash = cpu_to_be32(hash);
>
> if (write(fd, buf, sdp->bsize) != sdp->bsize) {
> - fprintf(stderr, _("write error: %s from %s:%d: "
> - "block %lld (0x%llx)
"),
> - strerror(errno),
> - __FUNCTION__, __LINE__,
> - (unsigned long long)x,
> - (unsigned long long)x);
> - exit(-1);
> + perror("add_j");
> + exit(EXIT_FAILURE);
> }
>
> if (++seq == blocks)
> @@ -459,18 +444,20 @@ add_j(struct gfs2_sbd *sdp)
> }
>
> error = fsync(fd);
> - if (error)
> - die( _("can't fsync: %s
"),
> - strerror(errno));
> + if (error){
> + perror("add_j fsync");
> + exit(EXIT_FAILURE);
> + }
> }
>
> close(fd);
>
> sprintf(new_name, "journal%u", sdp->md.journals);
> error = rename2system(sdp, "jindex", new_name);
> - if (error < 0 && errno != EEXIST)
> - die( _("can't rename2system %s (%d): %s
"),
> - new_name, error, strerror(errno));
> + if (error < 0 && errno != EEXIST){
> + perror("add_j rename2system");
> + exit(EXIT_FAILURE);
> + }
> }
>
> /**
> @@ -494,30 +481,26 @@ void main_jadd(int argc, char *argv[])
> verify_arguments(sdp);
>
> sdp->path_fd = open(sdp->path_name, O_RDONLY | O_CLOEXEC);
> - if (sdp->path_fd < 0)
> - die( _("can't open root directory %s: %s
"),
> - sdp->path_name, strerror(errno));
> + if (sdp->path_fd < 0){
> + perror(sdp->path_name);
> + exit(EXIT_FAILURE);
> + }
>
> if (check_for_gfs2(sdp)) {
> - if (errno == EINVAL)
> - fprintf(stderr, _("Not a valid GFS2 mount point: %s
"),
> - sdp->path_name);
> - else
> - fprintf(stderr, "%s
", strerror(errno));
> - exit(-1);
> + perror(sdp->path_name);
> + exit(EXIT_FAILURE);
> }
>
> gather_info(sdp);
>
> if (mount_gfs2_meta(sdp)) {
> - fprintf(stderr, _("Error mounting GFS2 metafs: %s
"),
> - strerror(errno));
> - exit(-1);
> + perror("GFS2 metafs");
> + exit(EXIT_FAILURE);
> }
>
> if (compute_constants(sdp)) {
> - fprintf(stderr, _("Bad constants (1)
"));
> - exit(-1);
> + perror(_("Bad constants (1)"));
> + exit(EXIT_FAILURE);
> }
> find_current_journals(sdp);
>
 
Old 10-04-2011, 07:26 PM
Carlos Maiolino
 
Default gfs2_jadd: Fix error handlers

> > @@ -212,10 +218,9 @@ create_new_inode(struct gfs2_sbd *sdp)
> > if (errno == EEXIST) {
> > error = unlink(name);
> > if (error)
> > - die( _("can't unlink %s: %s
"),
> > - name, strerror(errno));
> > + perror("unlink");
> > } else
> > - die( _("can't create %s: %s
"), name, strerror(errno));
> > + perror("create");
> > }
> In this case you should be passing the name that couldn't be created
> rather than the string "create" to perror. Otherwise the user won't know
> what the message refers to,
>
> Steve.
>
Gotcha, thanks Steve, I'll fix that on my next patch

--
--Carlos
 

Thread Tools




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

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