|
|
9257a6 |
commit d4fd26e60017a3a13391364f938588a3096b0971
|
|
|
9257a6 |
Author: Abhi Das <adas@redhat.com>
|
|
|
9257a6 |
Date: Mon May 11 14:41:06 2020 -0500
|
|
|
9257a6 |
|
|
|
9257a6 |
gfs2_jadd: error handling overhaul
|
|
|
9257a6 |
|
|
|
9257a6 |
Handle error conditions better and fail gracefully.
|
|
|
9257a6 |
|
|
|
9257a6 |
Resolves: rhbz#1837640
|
|
|
9257a6 |
|
|
|
9257a6 |
Signed-off-by: Abhi Das <adas@redhat.com>
|
|
|
9257a6 |
|
|
|
9257a6 |
diff --git a/gfs2/mkfs/main_jadd.c b/gfs2/mkfs/main_jadd.c
|
|
|
9257a6 |
index 948f67a1..12325be3 100644
|
|
|
9257a6 |
--- a/gfs2/mkfs/main_jadd.c
|
|
|
9257a6 |
+++ b/gfs2/mkfs/main_jadd.c
|
|
|
9257a6 |
@@ -40,15 +40,13 @@ struct jadd_opts {
|
|
|
9257a6 |
|
|
|
9257a6 |
#define JA_FL_SET 0
|
|
|
9257a6 |
#define JA_FL_CLEAR 1
|
|
|
9257a6 |
-static void set_flags(int fd, int op, uint32_t flags)
|
|
|
9257a6 |
+static int set_flags(int fd, int op, uint32_t flags)
|
|
|
9257a6 |
{
|
|
|
9257a6 |
- int err;
|
|
|
9257a6 |
uint32_t val;
|
|
|
9257a6 |
|
|
|
9257a6 |
- err = ioctl(fd, FS_IOC_GETFLAGS, &val;;
|
|
|
9257a6 |
- if (err) {
|
|
|
9257a6 |
+ if (ioctl(fd, FS_IOC_GETFLAGS, &val)) {
|
|
|
9257a6 |
perror("GETFLAGS");
|
|
|
9257a6 |
- exit(EXIT_FAILURE);
|
|
|
9257a6 |
+ return -1;
|
|
|
9257a6 |
}
|
|
|
9257a6 |
|
|
|
9257a6 |
if (op == JA_FL_SET)
|
|
|
9257a6 |
@@ -56,11 +54,11 @@ static void set_flags(int fd, int op, uint32_t flags)
|
|
|
9257a6 |
else if (op == JA_FL_CLEAR)
|
|
|
9257a6 |
val &= ~flags;
|
|
|
9257a6 |
|
|
|
9257a6 |
- err = ioctl(fd, FS_IOC_SETFLAGS, &val;;
|
|
|
9257a6 |
- if (err) {
|
|
|
9257a6 |
+ if (ioctl(fd, FS_IOC_SETFLAGS, &val)) {
|
|
|
9257a6 |
perror("SETFLAGS");
|
|
|
9257a6 |
- exit(EXIT_FAILURE);
|
|
|
9257a6 |
+ return -1;
|
|
|
9257a6 |
}
|
|
|
9257a6 |
+ return 0;
|
|
|
9257a6 |
}
|
|
|
9257a6 |
|
|
|
9257a6 |
static int rename2system(struct jadd_opts *opts, const char *new_dir, const char *new_name)
|
|
|
9257a6 |
@@ -242,115 +240,126 @@ static int create_new_inode(struct jadd_opts *opts)
|
|
|
9257a6 |
{
|
|
|
9257a6 |
char *name = opts->new_inode;
|
|
|
9257a6 |
int fd;
|
|
|
9257a6 |
- int error;
|
|
|
9257a6 |
|
|
|
9257a6 |
for (;;) {
|
|
|
9257a6 |
fd = open(name, O_WRONLY | O_CREAT | O_EXCL | O_NOFOLLOW | O_CLOEXEC, 0600);
|
|
|
9257a6 |
if (fd >= 0)
|
|
|
9257a6 |
break;
|
|
|
9257a6 |
if (errno == EEXIST) {
|
|
|
9257a6 |
- error = unlink(name);
|
|
|
9257a6 |
- if (error){
|
|
|
9257a6 |
+ if (unlink(name)) {
|
|
|
9257a6 |
perror("unlink");
|
|
|
9257a6 |
- exit(EXIT_FAILURE);
|
|
|
9257a6 |
+ return -1;
|
|
|
9257a6 |
}
|
|
|
9257a6 |
- } else{
|
|
|
9257a6 |
- perror("create");
|
|
|
9257a6 |
- exit(EXIT_FAILURE);
|
|
|
9257a6 |
+ continue;
|
|
|
9257a6 |
}
|
|
|
9257a6 |
+ perror("create");
|
|
|
9257a6 |
+ return -1;
|
|
|
9257a6 |
}
|
|
|
9257a6 |
|
|
|
9257a6 |
return fd;
|
|
|
9257a6 |
}
|
|
|
9257a6 |
|
|
|
9257a6 |
-static void add_ir(struct jadd_opts *opts)
|
|
|
9257a6 |
+static int add_ir(struct jadd_opts *opts)
|
|
|
9257a6 |
{
|
|
|
9257a6 |
- int fd;
|
|
|
9257a6 |
+ int fd, error = 0;
|
|
|
9257a6 |
char new_name[256];
|
|
|
9257a6 |
- int error;
|
|
|
9257a6 |
+ struct gfs2_inum_range ir;
|
|
|
9257a6 |
|
|
|
9257a6 |
- fd = create_new_inode(opts);
|
|
|
9257a6 |
+ if ((fd = create_new_inode(opts)) < 0)
|
|
|
9257a6 |
+ return fd;
|
|
|
9257a6 |
|
|
|
9257a6 |
- {
|
|
|
9257a6 |
- struct gfs2_inum_range ir;
|
|
|
9257a6 |
+ if ((error = set_flags(fd, JA_FL_SET, FS_JOURNAL_DATA_FL)))
|
|
|
9257a6 |
+ goto close_fd;
|
|
|
9257a6 |
|
|
|
9257a6 |
- set_flags(fd, JA_FL_SET, FS_JOURNAL_DATA_FL);
|
|
|
9257a6 |
memset(&ir, 0, sizeof(struct gfs2_inum_range));
|
|
|
9257a6 |
if (write(fd, (void*)&ir, sizeof(struct gfs2_inum_range)) !=
|
|
|
9257a6 |
sizeof(struct gfs2_inum_range)) {
|
|
|
9257a6 |
- perror("add_ir");
|
|
|
9257a6 |
- exit(EXIT_FAILURE);
|
|
|
9257a6 |
- }
|
|
|
9257a6 |
+ perror("add_ir write");
|
|
|
9257a6 |
+ error = -1;
|
|
|
9257a6 |
+ goto close_fd;
|
|
|
9257a6 |
}
|
|
|
9257a6 |
|
|
|
9257a6 |
- close(fd);
|
|
|
9257a6 |
+ if ((error = fsync(fd))) {
|
|
|
9257a6 |
+ perror("add_ir fsync");
|
|
|
9257a6 |
+ goto close_fd;
|
|
|
9257a6 |
+ }
|
|
|
9257a6 |
|
|
|
9257a6 |
sprintf(new_name, "inum_range%u", opts->journals);
|
|
|
9257a6 |
error = rename2system(opts, opts->per_node, new_name);
|
|
|
9257a6 |
if (error < 0 && errno != EEXIST){
|
|
|
9257a6 |
perror("add_ir rename2system");
|
|
|
9257a6 |
- exit(EXIT_FAILURE);
|
|
|
9257a6 |
+ goto close_fd;
|
|
|
9257a6 |
}
|
|
|
9257a6 |
+close_fd:
|
|
|
9257a6 |
+ return close(fd) || error;
|
|
|
9257a6 |
}
|
|
|
9257a6 |
|
|
|
9257a6 |
-static void add_sc(struct jadd_opts *opts)
|
|
|
9257a6 |
+static int add_sc(struct jadd_opts *opts)
|
|
|
9257a6 |
{
|
|
|
9257a6 |
- int fd;
|
|
|
9257a6 |
+ int fd, error = 0;
|
|
|
9257a6 |
char new_name[256];
|
|
|
9257a6 |
- int error;
|
|
|
9257a6 |
+ struct gfs2_statfs_change sc;
|
|
|
9257a6 |
|
|
|
9257a6 |
- fd = create_new_inode(opts);
|
|
|
9257a6 |
+ if ((fd = create_new_inode(opts)) < 0)
|
|
|
9257a6 |
+ return fd;
|
|
|
9257a6 |
|
|
|
9257a6 |
- {
|
|
|
9257a6 |
- struct gfs2_statfs_change sc;
|
|
|
9257a6 |
- set_flags(fd, JA_FL_SET, FS_JOURNAL_DATA_FL);
|
|
|
9257a6 |
+ if ((error = set_flags(fd, JA_FL_SET, FS_JOURNAL_DATA_FL)))
|
|
|
9257a6 |
+ goto close_fd;
|
|
|
9257a6 |
|
|
|
9257a6 |
memset(&sc, 0, sizeof(struct gfs2_statfs_change));
|
|
|
9257a6 |
if (write(fd, (void*)&sc, sizeof(struct gfs2_statfs_change)) !=
|
|
|
9257a6 |
sizeof(struct gfs2_statfs_change)) {
|
|
|
9257a6 |
- perror("add_sc");
|
|
|
9257a6 |
- exit(EXIT_FAILURE);
|
|
|
9257a6 |
- }
|
|
|
9257a6 |
+ perror("add_sc write");
|
|
|
9257a6 |
+ error = -1;
|
|
|
9257a6 |
+ goto close_fd;
|
|
|
9257a6 |
}
|
|
|
9257a6 |
|
|
|
9257a6 |
- close(fd);
|
|
|
9257a6 |
+ if ((error = fsync(fd))) {
|
|
|
9257a6 |
+ perror("add_sc fsync");
|
|
|
9257a6 |
+ goto close_fd;
|
|
|
9257a6 |
+ }
|
|
|
9257a6 |
|
|
|
9257a6 |
sprintf(new_name, "statfs_change%u", opts->journals);
|
|
|
9257a6 |
error = rename2system(opts, opts->per_node, new_name);
|
|
|
9257a6 |
if (error < 0 && errno != EEXIST){
|
|
|
9257a6 |
perror("add_sc rename2system");
|
|
|
9257a6 |
- exit(EXIT_FAILURE);
|
|
|
9257a6 |
+ goto close_fd;
|
|
|
9257a6 |
}
|
|
|
9257a6 |
+close_fd:
|
|
|
9257a6 |
+ return close(fd) || error;
|
|
|
9257a6 |
}
|
|
|
9257a6 |
|
|
|
9257a6 |
-static void add_qc(struct gfs2_sbd *sdp, struct jadd_opts *opts)
|
|
|
9257a6 |
-{
|
|
|
9257a6 |
- int fd;
|
|
|
9257a6 |
- char new_name[256];
|
|
|
9257a6 |
- int error;
|
|
|
9257a6 |
-
|
|
|
9257a6 |
- fd = create_new_inode(opts);
|
|
|
9257a6 |
-
|
|
|
9257a6 |
+static int add_qc(struct gfs2_sbd *sdp, struct jadd_opts *opts)
|
|
|
9257a6 |
{
|
|
|
9257a6 |
- char buf[sdp->bsize];
|
|
|
9257a6 |
+ int fd, error = 0;
|
|
|
9257a6 |
+ char new_name[256], buf[sdp->bsize];
|
|
|
9257a6 |
unsigned int blocks =
|
|
|
9257a6 |
sdp->qcsize << (20 - sdp->sd_sb.sb_bsize_shift);
|
|
|
9257a6 |
unsigned int x;
|
|
|
9257a6 |
struct gfs2_meta_header mh;
|
|
|
9257a6 |
struct gfs2_buffer_head dummy_bh;
|
|
|
9257a6 |
|
|
|
9257a6 |
+ if ((fd = create_new_inode(opts)) < 0)
|
|
|
9257a6 |
+ return fd;
|
|
|
9257a6 |
+
|
|
|
9257a6 |
dummy_bh.b_data = buf;
|
|
|
9257a6 |
- set_flags(fd, JA_FL_CLEAR, FS_JOURNAL_DATA_FL);
|
|
|
9257a6 |
- memset(buf, 0, sdp->bsize);
|
|
|
9257a6 |
|
|
|
9257a6 |
+ if ((error = set_flags(fd, JA_FL_CLEAR, FS_JOURNAL_DATA_FL)))
|
|
|
9257a6 |
+ goto close_fd;
|
|
|
9257a6 |
+
|
|
|
9257a6 |
+ memset(buf, 0, sdp->bsize);
|
|
|
9257a6 |
for (x=0; x
|
|
|
9257a6 |
if (write(fd, buf, sdp->bsize) != sdp->bsize) {
|
|
|
9257a6 |
- perror("add_qc");
|
|
|
9257a6 |
- exit(EXIT_FAILURE);
|
|
|
9257a6 |
+ perror("add_qc write");
|
|
|
9257a6 |
+ error = -1;
|
|
|
9257a6 |
+ goto close_fd;
|
|
|
9257a6 |
}
|
|
|
9257a6 |
}
|
|
|
9257a6 |
|
|
|
9257a6 |
- lseek(fd, 0, SEEK_SET);
|
|
|
9257a6 |
+ if ((error = lseek(fd, 0, SEEK_SET)) < 0) {
|
|
|
9257a6 |
+ perror("add_qc lseek");
|
|
|
9257a6 |
+ goto close_fd;
|
|
|
9257a6 |
+ }
|
|
|
9257a6 |
|
|
|
9257a6 |
memset(&mh, 0, sizeof(struct gfs2_meta_header));
|
|
|
9257a6 |
mh.mh_magic = GFS2_MAGIC;
|
|
|
9257a6 |
@@ -360,100 +369,114 @@ static void add_qc(struct gfs2_sbd *sdp, struct jadd_opts *opts)
|
|
|
9257a6 |
|
|
|
9257a6 |
for (x=0; x
|
|
|
9257a6 |
if (write(fd, buf, sdp->bsize) != sdp->bsize) {
|
|
|
9257a6 |
- perror("add_qc");
|
|
|
9257a6 |
- exit(EXIT_FAILURE);
|
|
|
9257a6 |
- }
|
|
|
9257a6 |
+ perror("add_qc write");
|
|
|
9257a6 |
+ error = -1;
|
|
|
9257a6 |
+ goto close_fd;
|
|
|
9257a6 |
}
|
|
|
9257a6 |
|
|
|
9257a6 |
- error = fsync(fd);
|
|
|
9257a6 |
- if (error){
|
|
|
9257a6 |
+ if ((error = fsync(fd))) {
|
|
|
9257a6 |
perror("add_qc fsync");
|
|
|
9257a6 |
- exit(EXIT_FAILURE);
|
|
|
9257a6 |
+ goto close_fd;
|
|
|
9257a6 |
}
|
|
|
9257a6 |
}
|
|
|
9257a6 |
|
|
|
9257a6 |
- close(fd);
|
|
|
9257a6 |
-
|
|
|
9257a6 |
sprintf(new_name, "quota_change%u", opts->journals);
|
|
|
9257a6 |
error = rename2system(opts, opts->per_node, new_name);
|
|
|
9257a6 |
if (error < 0 && errno != EEXIST){
|
|
|
9257a6 |
perror("add_qc rename2system");
|
|
|
9257a6 |
- exit(EXIT_FAILURE);
|
|
|
9257a6 |
+ goto close_fd;
|
|
|
9257a6 |
}
|
|
|
9257a6 |
+close_fd:
|
|
|
9257a6 |
+ return close(fd) || error;
|
|
|
9257a6 |
}
|
|
|
9257a6 |
|
|
|
9257a6 |
-static void gather_info(struct gfs2_sbd *sdp, struct jadd_opts *opts)
|
|
|
9257a6 |
+static int gather_info(struct gfs2_sbd *sdp, struct jadd_opts *opts)
|
|
|
9257a6 |
{
|
|
|
9257a6 |
struct statfs statbuf;
|
|
|
9257a6 |
+
|
|
|
9257a6 |
if (statfs(opts->path, &statbuf) < 0) {
|
|
|
9257a6 |
perror(opts->path);
|
|
|
9257a6 |
- exit(EXIT_FAILURE);
|
|
|
9257a6 |
+ return -1;
|
|
|
9257a6 |
}
|
|
|
9257a6 |
+
|
|
|
9257a6 |
sdp->bsize = statbuf.f_bsize;
|
|
|
9257a6 |
sdp->blks_total = statbuf.f_blocks;
|
|
|
9257a6 |
sdp->blks_alloced = sdp->blks_total - statbuf.f_bfree;
|
|
|
9257a6 |
+
|
|
|
9257a6 |
+ return 0;
|
|
|
9257a6 |
}
|
|
|
9257a6 |
|
|
|
9257a6 |
-static void find_current_journals(struct jadd_opts *opts)
|
|
|
9257a6 |
+static int find_current_journals(struct jadd_opts *opts)
|
|
|
9257a6 |
{
|
|
|
9257a6 |
struct dirent *dp;
|
|
|
9257a6 |
DIR *dirp;
|
|
|
9257a6 |
unsigned existing_journals = 0;
|
|
|
9257a6 |
+ int ret = 0;
|
|
|
9257a6 |
|
|
|
9257a6 |
dirp = opendir(opts->jindex);
|
|
|
9257a6 |
if (!dirp) {
|
|
|
9257a6 |
perror("jindex");
|
|
|
9257a6 |
- exit(EXIT_FAILURE);
|
|
|
9257a6 |
+ ret = -1;
|
|
|
9257a6 |
+ goto out;
|
|
|
9257a6 |
}
|
|
|
9257a6 |
while (dirp) {
|
|
|
9257a6 |
if ((dp = readdir(dirp)) != NULL) {
|
|
|
9257a6 |
if (strncmp(dp->d_name, "journal", 7) == 0)
|
|
|
9257a6 |
existing_journals++;
|
|
|
9257a6 |
} else
|
|
|
9257a6 |
- goto close;
|
|
|
9257a6 |
+ goto close_fd;
|
|
|
9257a6 |
}
|
|
|
9257a6 |
-close:
|
|
|
9257a6 |
- closedir(dirp);
|
|
|
9257a6 |
+close_fd:
|
|
|
9257a6 |
+ if ((ret = closedir(dirp)))
|
|
|
9257a6 |
+ goto out;
|
|
|
9257a6 |
+
|
|
|
9257a6 |
if (existing_journals == 0) {
|
|
|
9257a6 |
- die( _("No journals found. Did you run mkfs.gfs2 correctly?\n"));
|
|
|
9257a6 |
+ errno = EINVAL;
|
|
|
9257a6 |
+ perror("No journals found. Did you run mkfs.gfs2 correctly?\n");
|
|
|
9257a6 |
+ ret = -1;
|
|
|
9257a6 |
+ goto out;
|
|
|
9257a6 |
}
|
|
|
9257a6 |
|
|
|
9257a6 |
opts->orig_journals = existing_journals;
|
|
|
9257a6 |
+out:
|
|
|
9257a6 |
+ return ret;
|
|
|
9257a6 |
}
|
|
|
9257a6 |
|
|
|
9257a6 |
-static void add_j(struct gfs2_sbd *sdp, struct jadd_opts *opts)
|
|
|
9257a6 |
-{
|
|
|
9257a6 |
- int fd;
|
|
|
9257a6 |
- char new_name[256];
|
|
|
9257a6 |
- int error;
|
|
|
9257a6 |
-
|
|
|
9257a6 |
- fd = create_new_inode(opts);
|
|
|
9257a6 |
-
|
|
|
9257a6 |
+static int add_j(struct gfs2_sbd *sdp, struct jadd_opts *opts)
|
|
|
9257a6 |
{
|
|
|
9257a6 |
- char buf[sdp->bsize];
|
|
|
9257a6 |
+ int fd, error = 0;
|
|
|
9257a6 |
+ char new_name[256], buf[sdp->bsize];
|
|
|
9257a6 |
unsigned int blocks =
|
|
|
9257a6 |
sdp->jsize << (20 - sdp->sd_sb.sb_bsize_shift);
|
|
|
9257a6 |
unsigned int x;
|
|
|
9257a6 |
struct gfs2_log_header lh;
|
|
|
9257a6 |
- uint64_t seq = RANDOM(blocks);
|
|
|
9257a6 |
+ uint64_t seq = RANDOM(blocks);;
|
|
|
9257a6 |
+
|
|
|
9257a6 |
+ if ((fd = create_new_inode(opts)) < 0)
|
|
|
9257a6 |
+ return fd;
|
|
|
9257a6 |
+
|
|
|
9257a6 |
+ if ((error = set_flags(fd, JA_FL_CLEAR, FS_JOURNAL_DATA_FL)))
|
|
|
9257a6 |
+ goto close_fd;
|
|
|
9257a6 |
|
|
|
9257a6 |
- set_flags(fd, JA_FL_CLEAR, FS_JOURNAL_DATA_FL);
|
|
|
9257a6 |
memset(buf, 0, sdp->bsize);
|
|
|
9257a6 |
for (x=0; x
|
|
|
9257a6 |
if (write(fd, buf, sdp->bsize) != sdp->bsize) {
|
|
|
9257a6 |
- perror("add_j");
|
|
|
9257a6 |
- exit(EXIT_FAILURE);
|
|
|
9257a6 |
+ perror("add_j write");
|
|
|
9257a6 |
+ error = -1;
|
|
|
9257a6 |
+ goto close_fd;
|
|
|
9257a6 |
}
|
|
|
9257a6 |
}
|
|
|
9257a6 |
|
|
|
9257a6 |
- lseek(fd, 0, SEEK_SET);
|
|
|
9257a6 |
+ if ((error = lseek(fd, 0, SEEK_SET)) < 0) {
|
|
|
9257a6 |
+ perror("add_j lseek");
|
|
|
9257a6 |
+ goto close_fd;
|
|
|
9257a6 |
+ }
|
|
|
9257a6 |
|
|
|
9257a6 |
memset(&lh, 0, sizeof(struct gfs2_log_header));
|
|
|
9257a6 |
lh.lh_header.mh_magic = GFS2_MAGIC;
|
|
|
9257a6 |
lh.lh_header.mh_type = GFS2_METATYPE_LH;
|
|
|
9257a6 |
lh.lh_header.mh_format = GFS2_FORMAT_LH;
|
|
|
9257a6 |
lh.lh_flags = GFS2_LOG_HEAD_UNMOUNT;
|
|
|
9257a6 |
-
|
|
|
9257a6 |
for (x=0; x
|
|
|
9257a6 |
uint32_t hash;
|
|
|
9257a6 |
struct gfs2_buffer_head dummy_bh;
|
|
|
9257a6 |
@@ -467,28 +490,27 @@ static void add_j(struct gfs2_sbd *sdp, struct jadd_opts *opts)
|
|
|
9257a6 |
|
|
|
9257a6 |
if (write(fd, buf, sdp->bsize) != sdp->bsize) {
|
|
|
9257a6 |
perror("add_j");
|
|
|
9257a6 |
- exit(EXIT_FAILURE);
|
|
|
9257a6 |
+ error = -1;
|
|
|
9257a6 |
+ goto close_fd;
|
|
|
9257a6 |
}
|
|
|
9257a6 |
|
|
|
9257a6 |
if (++seq == blocks)
|
|
|
9257a6 |
seq = 0;
|
|
|
9257a6 |
- }
|
|
|
9257a6 |
|
|
|
9257a6 |
- error = fsync(fd);
|
|
|
9257a6 |
- if (error){
|
|
|
9257a6 |
+ if ((error = fsync(fd))){
|
|
|
9257a6 |
perror("add_j fsync");
|
|
|
9257a6 |
- exit(EXIT_FAILURE);
|
|
|
9257a6 |
+ goto close_fd;
|
|
|
9257a6 |
}
|
|
|
9257a6 |
}
|
|
|
9257a6 |
|
|
|
9257a6 |
- close(fd);
|
|
|
9257a6 |
-
|
|
|
9257a6 |
sprintf(new_name, "journal%u", opts->journals);
|
|
|
9257a6 |
error = rename2system(opts, opts->jindex, new_name);
|
|
|
9257a6 |
if (error < 0 && errno != EEXIST){
|
|
|
9257a6 |
perror("add_j rename2system");
|
|
|
9257a6 |
- exit(EXIT_FAILURE);
|
|
|
9257a6 |
+ goto close_fd;
|
|
|
9257a6 |
}
|
|
|
9257a6 |
+close_fd:
|
|
|
9257a6 |
+ return close(fd) || error;
|
|
|
9257a6 |
}
|
|
|
9257a6 |
|
|
|
9257a6 |
static int check_fit(struct gfs2_sbd *sdp, struct jadd_opts *opts)
|
|
|
9257a6 |
@@ -516,7 +538,7 @@ static int check_fit(struct gfs2_sbd *sdp, struct jadd_opts *opts)
|
|
|
9257a6 |
printf( _("Available space : %*lu blks\n\n"), 10,
|
|
|
9257a6 |
sdp->blks_total - sdp->blks_alloced);
|
|
|
9257a6 |
errno = ENOSPC;
|
|
|
9257a6 |
- return 1;
|
|
|
9257a6 |
+ return -1;
|
|
|
9257a6 |
}
|
|
|
9257a6 |
return 0;
|
|
|
9257a6 |
}
|
|
|
9257a6 |
@@ -543,35 +565,43 @@ int main(int argc, char *argv[])
|
|
|
9257a6 |
|
|
|
9257a6 |
sbd.path_fd = lgfs2_open_mnt_dir(opts.path, O_RDONLY|O_CLOEXEC, &mnt;;
|
|
|
9257a6 |
if (sbd.path_fd < 0) {
|
|
|
9257a6 |
- fprintf(stderr, _("Error looking up mount '%s': %s\n"), opts.path, strerror(errno));
|
|
|
9257a6 |
- exit(EXIT_FAILURE);
|
|
|
9257a6 |
+ fprintf(stderr, "Error looking up mount '%s': %s\n",
|
|
|
9257a6 |
+ opts.path, strerror(errno));
|
|
|
9257a6 |
+ ret = -1;
|
|
|
9257a6 |
+ goto out;
|
|
|
9257a6 |
}
|
|
|
9257a6 |
if (mnt == NULL) {
|
|
|
9257a6 |
- fprintf(stderr, _("%s: not a mounted gfs2 file system\n"), opts.path);
|
|
|
9257a6 |
- exit(EXIT_FAILURE);
|
|
|
9257a6 |
+ fprintf(stderr, "%s: not a mounted gfs2 file system: %s\n",
|
|
|
9257a6 |
+ opts.path, strerror(EINVAL));
|
|
|
9257a6 |
+ ret = -1;
|
|
|
9257a6 |
+ goto close_sb;
|
|
|
9257a6 |
}
|
|
|
9257a6 |
- gather_info(sdp, &opts);
|
|
|
9257a6 |
+
|
|
|
9257a6 |
+ if ((ret = gather_info(sdp, &opts)))
|
|
|
9257a6 |
+ goto close_sb;
|
|
|
9257a6 |
+
|
|
|
9257a6 |
mfs.context = copy_context_opt(mnt);
|
|
|
9257a6 |
- if (mount_gfs2_meta(&mfs, mnt->mnt_dir, opts.debug)) {
|
|
|
9257a6 |
+ if ((ret = mount_gfs2_meta(&mfs, mnt->mnt_dir, opts.debug))) {
|
|
|
9257a6 |
perror("GFS2 metafs");
|
|
|
9257a6 |
- exit(EXIT_FAILURE);
|
|
|
9257a6 |
+ goto close_sb;
|
|
|
9257a6 |
}
|
|
|
9257a6 |
|
|
|
9257a6 |
- if (build_paths(mfs.path, &opts)) {
|
|
|
9257a6 |
+ if ((ret = build_paths(mfs.path, &opts))) {
|
|
|
9257a6 |
perror(_("Failed to build paths"));
|
|
|
9257a6 |
- exit(EXIT_FAILURE);
|
|
|
9257a6 |
+ goto umount_meta;
|
|
|
9257a6 |
}
|
|
|
9257a6 |
|
|
|
9257a6 |
- if (compute_constants(sdp)) {
|
|
|
9257a6 |
+ if ((ret = compute_constants(sdp))) {
|
|
|
9257a6 |
perror(_("Failed to compute file system constants"));
|
|
|
9257a6 |
- exit(EXIT_FAILURE);
|
|
|
9257a6 |
+ goto free_paths;
|
|
|
9257a6 |
}
|
|
|
9257a6 |
- find_current_journals(&opts);
|
|
|
9257a6 |
|
|
|
9257a6 |
- ret = check_fit(sdp, &opts);
|
|
|
9257a6 |
- if (ret) {
|
|
|
9257a6 |
+ if ((ret = find_current_journals(&opts)))
|
|
|
9257a6 |
+ goto free_paths;
|
|
|
9257a6 |
+
|
|
|
9257a6 |
+ if ((ret = check_fit(sdp, &opts))) {
|
|
|
9257a6 |
perror(_("Failed to add journals"));
|
|
|
9257a6 |
- goto out;
|
|
|
9257a6 |
+ goto free_paths;
|
|
|
9257a6 |
}
|
|
|
9257a6 |
|
|
|
9257a6 |
total = opts.orig_journals + opts.journals;
|
|
|
9257a6 |
@@ -579,23 +609,29 @@ int main(int argc, char *argv[])
|
|
|
9257a6 |
opts.journals < total;
|
|
|
9257a6 |
opts.journals++) {
|
|
|
9257a6 |
if (metafs_interrupted) {
|
|
|
9257a6 |
- cleanup_metafs(&mfs;;
|
|
|
9257a6 |
- exit(130);
|
|
|
9257a6 |
+ errno = 130;
|
|
|
9257a6 |
+ goto free_paths;
|
|
|
9257a6 |
}
|
|
|
9257a6 |
- add_ir(&opts);
|
|
|
9257a6 |
- add_sc(&opts);
|
|
|
9257a6 |
- add_qc(sdp, &opts);
|
|
|
9257a6 |
- add_j(sdp, &opts);
|
|
|
9257a6 |
+ if ((ret = add_ir(&opts)))
|
|
|
9257a6 |
+ goto free_paths;
|
|
|
9257a6 |
+ if ((ret = add_sc(&opts)))
|
|
|
9257a6 |
+ goto free_paths;
|
|
|
9257a6 |
+ if ((ret = add_qc(sdp, &opts)))
|
|
|
9257a6 |
+ goto free_paths;
|
|
|
9257a6 |
+ if ((ret = add_j(sdp, &opts)))
|
|
|
9257a6 |
+ goto free_paths;
|
|
|
9257a6 |
}
|
|
|
9257a6 |
|
|
|
9257a6 |
-out:
|
|
|
9257a6 |
+free_paths:
|
|
|
9257a6 |
free(opts.new_inode);
|
|
|
9257a6 |
free(opts.per_node);
|
|
|
9257a6 |
free(opts.jindex);
|
|
|
9257a6 |
- close(sdp->path_fd);
|
|
|
9257a6 |
- cleanup_metafs(&mfs;;
|
|
|
9257a6 |
+umount_meta:
|
|
|
9257a6 |
sync();
|
|
|
9257a6 |
-
|
|
|
9257a6 |
+ cleanup_metafs(&mfs;;
|
|
|
9257a6 |
+close_sb:
|
|
|
9257a6 |
+ close(sdp->path_fd);
|
|
|
9257a6 |
+out:
|
|
|
9257a6 |
if (!ret)
|
|
|
9257a6 |
print_results(&opts);
|
|
|
9257a6 |
|