gfs2-utils: master - gfs2_edit: Add bounds checking for the journalN keyword
by Andrew Price
Gitweb: http://git.fedorahosted.org/git/?p=gfs2-utils.git;a=commitdiff;h=cf933671...
Commit: cf9336713097a5ba8487921bf5b8097462798dba
Parent: eb5d132a99dda1facef6448d9b86fdee98dcf7fa
Author: Andrew Price <anprice(a)redhat.com>
AuthorDate: Mon Oct 13 16:39:34 2014 +0100
Committer: Andrew Price <anprice(a)redhat.com>
CommitterDate: Mon Oct 13 16:39:34 2014 +0100
gfs2_edit: Add bounds checking for the journalN keyword
Spotted by coverity: "Using tainted variable "journal_num + 2" as an
index to array "indirect->ii[0].dirent""
Signed-off-by: Andrew Price <anprice(a)redhat.com>
---
gfs2/edit/journal.c | 5 +++++
1 files changed, 5 insertions(+), 0 deletions(-)
diff --git a/gfs2/edit/journal.c b/gfs2/edit/journal.c
index 81d7a90..a2aeb2c 100644
--- a/gfs2/edit/journal.c
+++ b/gfs2/edit/journal.c
@@ -41,6 +41,9 @@ uint64_t find_journal_block(const char *journal, uint64_t *j_size)
char jbuf[sbd.bsize];
journal_num = atoi(journal + 7);
+ if (journal_num < 0)
+ return 0;
+
/* Figure out the block of the jindex file */
if (sbd.gfs1)
jindex_block = sbd1->sb_jindex_di.no_addr;
@@ -73,6 +76,8 @@ uint64_t find_journal_block(const char *journal, uint64_t *j_size)
} else {
struct gfs2_dinode jdi;
+ if (journal_num > indirect->ii[0].dirents - 2)
+ return 0;
jblock = indirect->ii[0].dirent[journal_num + 2].block;
j_bh = bread(&sbd, jblock);
gfs2_dinode_in(&jdi, j_bh);/* parse dinode to struct */
9 years, 8 months
gfs2-utils: master - gfs2_convert: Don't use a fixed sized buffer for device path
by Andrew Price
Gitweb: http://git.fedorahosted.org/git/?p=gfs2-utils.git;a=commitdiff;h=eb5d132a...
Commit: eb5d132a99dda1facef6448d9b86fdee98dcf7fa
Parent: 7d5f1f6069e0b7b9df386175ca85d9d388407fbe
Author: Andrew Price <anprice(a)redhat.com>
AuthorDate: Mon Oct 13 16:10:18 2014 +0100
Committer: Andrew Price <anprice(a)redhat.com>
CommitterDate: Mon Oct 13 16:10:18 2014 +0100
gfs2_convert: Don't use a fixed sized buffer for device path
Previously gfs2_convert only allowed for a 255-char device path. Remove
the fixed-size buffer and use the existing device pointer in the options
struct instead.
Signed-off-by: Andrew Price <anprice(a)redhat.com>
---
gfs2/convert/gfs2_convert.c | 42 ++++++++++++++++--------------------------
1 files changed, 16 insertions(+), 26 deletions(-)
diff --git a/gfs2/convert/gfs2_convert.c b/gfs2/convert/gfs2_convert.c
index 750c4df..a92ee80 100644
--- a/gfs2/convert/gfs2_convert.c
+++ b/gfs2/convert/gfs2_convert.c
@@ -98,7 +98,6 @@ struct gfs2_options {
struct gfs_sb raw_gfs1_ondisk_sb;
struct gfs2_sbd sb2;
-char device[256];
struct inode_block dirs_to_fix; /* linked list of directories to fix */
struct inode_dir_block cdpns_to_fix; /* linked list of cdpn symlinks */
int seconds;
@@ -1536,15 +1535,15 @@ static int sanity_check(struct gfs2_sbd *sdp)
/* init - initialization code */
/* Returns: 0 on success, -1 on failure */
/* ------------------------------------------------------------------------- */
-static int init(struct gfs2_sbd *sbp)
+static int init(struct gfs2_sbd *sbp, struct gfs2_options *opts)
{
struct gfs2_buffer_head *bh;
int rgcount;
struct gfs2_inum inum;
memset(sbp, 0, sizeof(struct gfs2_sbd));
- if ((sbp->device_fd = open(device, O_RDWR)) < 0) {
- perror(device);
+ if ((sbp->device_fd = open(opts->device, O_RDWR)) < 0) {
+ perror(opts->device);
exit(-1);
}
/* --------------------------------- */
@@ -1626,8 +1625,7 @@ static int init(struct gfs2_sbd *sbp)
sbp->sd_sb.sb_header.mh_type != GFS_METATYPE_SB ||
sbp->sd_sb.sb_header.mh_format != GFS_FORMAT_SB ||
sbp->sd_sb.sb_multihost_format != GFS_FORMAT_MULTI) {
- log_crit(_("Error: %s does not look like a gfs1 filesystem.\n"),
- device);
+ log_crit(_("Error: %s does not look like a gfs1 filesystem.\n"), opts->device);
close(sbp->device_fd);
exit(-1);
}
@@ -1725,7 +1723,6 @@ static void process_parameters(int argc, char **argv, struct gfs2_options *opts)
usage(argv[0]);
exit(0);
}
- memset(device, 0, sizeof(device));
while((c = getopt(argc, argv, "hnqvyV")) != -1) {
switch(c) {
@@ -1754,12 +1751,7 @@ static void process_parameters(int argc, char **argv, struct gfs2_options *opts)
}
}
if(argc > optind) {
- strcpy(device, argv[optind]);
- opts->device = device;
- if(!opts->device) {
- fprintf(stderr, _("No device specified. Please use '-h' for help\n"));
- exit(1);
- }
+ opts->device = argv[optind];
} else {
fprintf(stderr, _("No device specified. Please use '-h' for help\n"));
exit(1);
@@ -2166,7 +2158,7 @@ int main(int argc, char **argv)
version();
process_parameters(argc, argv, &opts);
- error = init(&sb2);
+ error = init(&sb2, &opts);
/*
* Check for some common fs errors
@@ -2175,7 +2167,7 @@ int main(int argc, char **argv)
if (sanity_check(&sb2)) {
log_crit(_("%s is not a clean gfs filesytem. Please use the"
" fsck.gfs2 utility to correct these errors and"
- " try again.\n"), device);
+ " try again.\n"), opts.device);
exit(0);
}
}
@@ -2184,8 +2176,8 @@ int main(int argc, char **argv)
/* ---------------------------------------------- */
if (!error) {
give_warning();
- if (!gfs2_query(&opts, device)) {
- log_crit(_("%s not converted.\n"), device);
+ if (!gfs2_query(&opts, opts.device)) {
+ log_crit(_("%s not converted.\n"), opts.device);
close(sb2.device_fd);
exit(0);
}
@@ -2199,8 +2191,7 @@ int main(int argc, char **argv)
error = convert_rgs(&sb2);
log_notice("\n");
if (error)
- log_crit(_("%s: Unable to convert resource groups.\n"),
- device);
+ log_crit(_("%s: Unable to convert resource groups.\n"), opts.device);
fsync(sb2.device_fd); /* write the buffers to disk */
}
/* ---------------------------------------------- */
@@ -2211,7 +2202,7 @@ int main(int argc, char **argv)
error = inode_renumber(&sb2, sb2.sd_sb.sb_root_dir.no_addr,
(osi_list_t *)&cdpns_to_fix);
if (error)
- log_crit(_("\n%s: Error renumbering inodes.\n"), device);
+ log_crit(_("\n%s: Error renumbering inodes.\n"), opts.device);
fsync(sb2.device_fd); /* write the buffers to disk */
}
/* ---------------------------------------------- */
@@ -2224,7 +2215,7 @@ int main(int argc, char **argv)
(unsigned long long)dirents_fixed);
fflush(stdout);
if (error)
- log_crit(_("\n%s: Error fixing directories.\n"), device);
+ log_crit(_("\n%s: Error fixing directories.\n"), opts.device);
}
/* ---------------------------------------------- */
/* Convert cdpn symlinks to empty dirs */
@@ -2235,7 +2226,7 @@ int main(int argc, char **argv)
(unsigned long long)cdpns_fixed);
fflush(stdout);
if (error)
- log_crit(_("\n%s: Error fixing cdpn symlinks.\n"), device);
+ log_crit(_("\n%s: Error fixing cdpn symlinks.\n"), opts.device);
}
/* ---------------------------------------------- */
/* Convert journal space to rg space */
@@ -2244,7 +2235,7 @@ int main(int argc, char **argv)
log_notice(_("\nConverting journals.\n"));
error = journ_space_to_rg(&sb2);
if (error)
- log_crit(_("%s: Error converting journal space.\n"), device);
+ log_crit(_("%s: Error converting journal space.\n"), opts.device);
fsync(sb2.device_fd); /* write the buffers to disk */
}
/* ---------------------------------------------- */
@@ -2356,10 +2347,9 @@ int main(int argc, char **argv)
error = fsync(sb2.device_fd);
if (error)
- perror(device);
+ perror(opts.device);
else
- log_notice(_("%s: filesystem converted successfully to gfs2.\n"),
- device);
+ log_notice(_("%s: filesystem converted successfully to gfs2.\n"), opts.device);
}
close(sb2.device_fd);
if (sd_jindex)
9 years, 8 months
gfs2-utils: master - gfs2-utils configure: Remove checks for non-existent -W flags
by Andrew Price
Gitweb: http://git.fedorahosted.org/git/?p=gfs2-utils.git;a=commitdiff;h=7d5f1f60...
Commit: 7d5f1f6069e0b7b9df386175ca85d9d388407fbe
Parent: 456b884ac4ce75559b90a4d4fb197db813f7c327
Author: Andrew Price <anprice(a)redhat.com>
AuthorDate: Fri Oct 10 20:58:35 2014 +0100
Committer: Andrew Price <anprice(a)redhat.com>
CommitterDate: Fri Oct 10 20:58:35 2014 +0100
gfs2-utils configure: Remove checks for non-existent -W flags
checking whether gcc supports -Wunsigned-char... no
checking whether gcc supports -Wgnu89-inline... no
This has always been the case, as far as I can tell, and I can't find
any mention of a compiler which does support these flags. Remove the
checks for these flags from configure.ac.
Signed-off-by: Andrew Price <anprice(a)redhat.com>
---
configure.ac | 2 --
1 files changed, 0 insertions(+), 2 deletions(-)
diff --git a/configure.ac b/configure.ac
index 2269aba..e70409c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -197,8 +197,6 @@ WARNLIST="
format-security
format-nonliteral
no-long-long
- unsigned-char
- gnu89-inline
no-strict-aliasing
"
9 years, 8 months
gfs2-utils: master - gfs2-utils configure: Fix exit with failure condition
by Andrew Price
Gitweb: http://git.fedorahosted.org/git/?p=gfs2-utils.git;a=commitdiff;h=456b884a...
Commit: 456b884ac4ce75559b90a4d4fb197db813f7c327
Parent: 0ae4f708ee2fc2c8c246444a87d7cc1f14e96ae1
Author: Andrew Price <anprice(a)redhat.com>
AuthorDate: Fri Oct 10 20:53:48 2014 +0100
Committer: Andrew Price <anprice(a)redhat.com>
CommitterDate: Fri Oct 10 20:53:48 2014 +0100
gfs2-utils configure: Fix exit with failure condition
When gcov is disabled, the test at the end of the configure script would
cause the script to exit with status 1 despite succeeding. Restructure
the test to make sure its exit status is consumed in an if statement.
Signed-off-by: Andrew Price <anprice(a)redhat.com>
---
configure.ac | 8 ++++++--
1 files changed, 6 insertions(+), 2 deletions(-)
diff --git a/configure.ac b/configure.ac
index a978e52..2269aba 100644
--- a/configure.ac
+++ b/configure.ac
@@ -234,5 +234,9 @@ AC_CONFIG_FILES([Makefile
AC_OUTPUT
-test x"$have_check" = "xyes" || AC_MSG_NOTICE([package 'check' not found; unit tests will not be built])
-test x"${enable_gcov}" = "xyes" && AC_MSG_NOTICE([code coverage enabled; optimization will be disabled])
+if test x"${have_check}" != "xyes"; then
+ AC_MSG_NOTICE([package 'check' not found; unit tests will not be built])
+fi
+if test x"${enable_gcov}" = "xyes"; then
+ AC_MSG_NOTICE([code coverage enabled; optimization will be disabled])
+fi
9 years, 8 months
fence-agents: master - fence_pve: Add support for --ssl-secure and --ssl-insecure
by Marek Grác
Gitweb: http://git.fedorahosted.org/git/?p=fence-agents.git;a=commitdiff;h=43b6d6...
Commit: 43b6d69fe0ae104c7aecb2cbb8f7caba3091165c
Parent: d3d73eaa39dd49cc7fbc93b267daa7f51b1c5fff
Author: Marek 'marx' Grac <mgrac(a)redhat.com>
AuthorDate: Mon Oct 13 10:33:18 2014 +0200
Committer: Marek 'marx' Grac <mgrac(a)redhat.com>
CommitterDate: Mon Oct 13 10:33:18 2014 +0200
fence_pve: Add support for --ssl-secure and --ssl-insecure
Resolves: rhbz#1151515
---
fence/agents/pve/fence_pve.py | 9 +++++++--
1 files changed, 7 insertions(+), 2 deletions(-)
diff --git a/fence/agents/pve/fence_pve.py b/fence/agents/pve/fence_pve.py
index 132234e..bb59a9b 100644
--- a/fence/agents/pve/fence_pve.py
+++ b/fence/agents/pve/fence_pve.py
@@ -106,8 +106,13 @@ def send_cmd(options, cmd, post=None):
conn.setopt(pycurl.POSTFIELDS, urllib.urlencode(post))
conn.setopt(pycurl.WRITEFUNCTION, output_buffer.write)
conn.setopt(pycurl.TIMEOUT, int(options["--shell-timeout"]))
- conn.setopt(pycurl.SSL_VERIFYPEER, 0)
- conn.setopt(pycurl.SSL_VERIFYHOST, 0)
+ if opt.has_key("--ssl") or opt.has_key("--ssl-secure"):
+ conn.setopt(pycurl.SSL_VERIFYPEER, 1)
+ conn.setopt(pycurl.SSL_VERIFYHOST, 2)
+
+ if opt.has_key("--ssl-insecure"):
+ conn.setopt(pycurl.SSL_VERIFYPEER, 0)
+ conn.setopt(pycurl.SSL_VERIFYHOST, 0)
logging.debug("URL: " + url)
9 years, 8 months
gfs2-utils: master - gfs2l: Check unchecked returns in openfs
by Andrew Price
Gitweb: http://git.fedorahosted.org/git/?p=gfs2-utils.git;a=commitdiff;h=0ae4f708...
Commit: 0ae4f708ee2fc2c8c246444a87d7cc1f14e96ae1
Parent: f171e00058c706662b1e84567088ed3d9f1acbc6
Author: Andrew Price <anprice(a)redhat.com>
AuthorDate: Fri Oct 10 17:01:30 2014 +0100
Committer: Andrew Price <anprice(a)redhat.com>
CommitterDate: Fri Oct 10 17:01:30 2014 +0100
gfs2l: Check unchecked returns in openfs
Fix some coverity complaints that return values from compute_constants()
and lgfs2_get_dev_info() weren't being checked. Also avoid unnecessary
memory management for the gfs2_sbd.
Signed-off-by: Andrew Price <anprice(a)redhat.com>
---
gfs2/libgfs2/gfs2l.c | 45 ++++++++++++++++++++++-----------------------
1 files changed, 22 insertions(+), 23 deletions(-)
diff --git a/gfs2/libgfs2/gfs2l.c b/gfs2/libgfs2/gfs2l.c
index eda9531..5d9afd8 100644
--- a/gfs2/libgfs2/gfs2l.c
+++ b/gfs2/libgfs2/gfs2l.c
@@ -96,36 +96,38 @@ static int getopts(int argc, char *argv[], struct cmdopts *opts)
return 0;
}
-static struct gfs2_sbd *openfs(const char *path)
+static int openfs(const char *path, struct gfs2_sbd *sdp)
{
int fd;
int ret;
int sane;
int count;
- struct gfs2_sbd *sdp = calloc(1, sizeof(struct gfs2_sbd));
- if (sdp == NULL) {
- perror("calloc");
- return NULL;
- }
fd = open(path, O_RDWR);
if (fd < 0) {
fprintf(stderr, "Failed to open %s\n", path);
- free(sdp);
- return NULL;
+ return 1;
}
memset(sdp, 0, sizeof(*sdp));
sdp->bsize = GFS2_BASIC_BLOCK;
sdp->device_fd = fd;
- compute_constants(sdp);
- lgfs2_get_dev_info(fd, &sdp->dinfo);
+ ret = compute_constants(sdp);
+ if (ret != 0) {
+ perror("Bad constants");
+ return 1;
+ }
+ ret = lgfs2_get_dev_info(fd, &sdp->dinfo);
+ if (ret != 0) {
+ perror("Failed to gather device info");
+ return 1;
+ }
fix_device_geometry(sdp);
ret = read_sb(sdp);
if (ret != 0) {
perror("Could not read sb");
- return NULL;
+ return 1;
}
sdp->master_dir = lgfs2_inode_read(sdp, sdp->sd_sb.sb_master_dir.no_addr);
@@ -135,17 +137,16 @@ static struct gfs2_sbd *openfs(const char *path)
rindex_read(sdp, 0, &count, &sane);
} else {
perror("Failed to look up rindex");
- free(sdp);
- return NULL;
+ return 1;
}
- return sdp;
+ return 0;
}
int main(int argc, char *argv[])
{
int ret;
struct cmdopts opts = {NULL, NULL};
- struct gfs2_sbd *sdp;
+ struct gfs2_sbd sbd;
struct lgfs2_lang_result *result;
struct lgfs2_lang_state *state;
@@ -158,10 +159,8 @@ int main(int argc, char *argv[])
exit(0);
}
- sdp = openfs(argv[optind]);
- if (sdp == NULL) {
+ if (openfs(argv[optind], &sbd))
exit(1);
- }
state = lgfs2_lang_init();
if (state == NULL) {
@@ -176,9 +175,9 @@ int main(int argc, char *argv[])
return ret;
}
- for (result = lgfs2_lang_result_next(state, sdp);
+ for (result = lgfs2_lang_result_next(state, &sbd);
result != NULL;
- result = lgfs2_lang_result_next(state, sdp)) {
+ result = lgfs2_lang_result_next(state, &sbd)) {
if (result == NULL) {
fprintf(stderr, "Failed to interpret script\n");
return -1;
@@ -187,9 +186,9 @@ int main(int argc, char *argv[])
lgfs2_lang_result_free(&result);
}
- gfs2_rgrp_free(&sdp->rgtree);
- inode_put(&sdp->md.riinode);
- inode_put(&sdp->master_dir);
+ gfs2_rgrp_free(&sbd.rgtree);
+ inode_put(&sbd.md.riinode);
+ inode_put(&sbd.master_dir);
lgfs2_lang_free(&state);
free(opts.fspath);
return 0;
9 years, 8 months
gfs2-utils: master - libgfs2: Remove orig_journals from struct gfs2_sbd
by Andrew Price
Gitweb: http://git.fedorahosted.org/git/?p=gfs2-utils.git;a=commitdiff;h=f171e000...
Commit: f171e00058c706662b1e84567088ed3d9f1acbc6
Parent: 9d6c8308858d40e99cbd750ba4882f0239b2c1e4
Author: Andrew Price <anprice(a)redhat.com>
AuthorDate: Fri Oct 10 16:23:27 2014 +0100
Committer: Andrew Price <anprice(a)redhat.com>
CommitterDate: Fri Oct 10 16:23:27 2014 +0100
libgfs2: Remove orig_journals from struct gfs2_sbd
The last remaining user of this field is easily changed to use its own
orig_journals variable instead.
Signed-off-by: Andrew Price <anprice(a)redhat.com>
---
gfs2/convert/gfs2_convert.c | 5 +++--
gfs2/libgfs2/libgfs2.h | 2 --
2 files changed, 3 insertions(+), 4 deletions(-)
diff --git a/gfs2/convert/gfs2_convert.c b/gfs2/convert/gfs2_convert.c
index 16ec150..750c4df 100644
--- a/gfs2/convert/gfs2_convert.c
+++ b/gfs2/convert/gfs2_convert.c
@@ -114,6 +114,7 @@ uint32_t gfs2_max_height;
uint32_t gfs2_max_jheight;
uint64_t jindex_addr = 0, rindex_addr = 0;
int print_level = MSG_NOTICE;
+unsigned orig_journals = 0;
/* ------------------------------------------------------------------------- */
/* This function is for libgfs's sake. */
@@ -1505,7 +1506,7 @@ static int read_gfs1_jiindex(struct gfs2_sbd *sdp)
log_crit(_("journal inode size invalid\n"));
goto fail;
}
- sdp->md.journals = sdp->orig_journals = j;
+ sdp->md.journals = orig_journals = j;
return 0;
fail:
@@ -1813,7 +1814,7 @@ static int journ_space_to_rg(struct gfs2_sbd *sdp)
mh.mh_format = GFS2_FORMAT_RB;
log_notice(_("Converting journal space to rg space.\n"));
/* Go through each journal, converting them one by one */
- for (j = 0; j < sdp->orig_journals; j++) { /* for each journal */
+ for (j = 0; j < orig_journals; j++) { /* for each journal */
uint64_t size;
jndx = &sd_jindex[j];
diff --git a/gfs2/libgfs2/libgfs2.h b/gfs2/libgfs2/libgfs2.h
index 60c1989..58602c0 100644
--- a/gfs2/libgfs2/libgfs2.h
+++ b/gfs2/libgfs2/libgfs2.h
@@ -320,8 +320,6 @@ struct gfs2_sbd {
struct osi_root rgtree;
struct osi_root rgcalc;
- unsigned int orig_journals;
-
struct gfs2_inode *master_dir;
struct master_dir md;
9 years, 8 months
gfs2-utils: master - gfs2_jadd: Don't use fixed size buffers for paths
by Andrew Price
Gitweb: http://git.fedorahosted.org/git/?p=gfs2-utils.git;a=commitdiff;h=9d6c8308...
Commit: 9d6c8308858d40e99cbd750ba4882f0239b2c1e4
Parent: 4daadc09b2d0b6b83cee55451747486403343dc3
Author: Andrew Price <anprice(a)redhat.com>
AuthorDate: Fri Oct 10 12:04:40 2014 +0100
Committer: Andrew Price <anprice(a)redhat.com>
CommitterDate: Fri Oct 10 12:04:40 2014 +0100
gfs2_jadd: Don't use fixed size buffers for paths
This fixes some more PATH_MAX usages by dynamically allocating the space
to store metafs path strings. Previously the strings were rebuilt each
time they were required using sprintf and fixed size buffers. Remove the
sprintfs by storing the strings in the opts structure and pass around a
pointer to it instead of the gfs2_sbd where possible. This reduces the
number of uses of sbd.orig_journals which should be removed eventually
as it's application-specific.
Signed-off-by: Andrew Price <anprice(a)redhat.com>
---
gfs2/mkfs/main_jadd.c | 189 ++++++++++++++++++++++++++-----------------------
1 files changed, 99 insertions(+), 90 deletions(-)
diff --git a/gfs2/mkfs/main_jadd.c b/gfs2/mkfs/main_jadd.c
index 4968ec9..6507e03 100644
--- a/gfs2/mkfs/main_jadd.c
+++ b/gfs2/mkfs/main_jadd.c
@@ -24,11 +24,15 @@
#include "libgfs2.h"
#include "gfs2_mkfs.h"
-#define BUF_SIZE 4096
#define RANDOM(values) ((values) * (random() / (RAND_MAX + 1.0)))
struct jadd_opts {
char *path;
+ char *new_inode;
+ char *per_node;
+ char *jindex;
+ unsigned orig_journals;
+ unsigned journals;
unsigned quiet:1;
unsigned debug:1;
};
@@ -57,22 +61,45 @@ make_jdata(int fd, const char *value)
}
}
-static int
-rename2system(struct gfs2_sbd *sdp, const char *new_dir, const char *new_name)
+static int rename2system(struct jadd_opts *opts, const char *new_dir, const char *new_name)
{
- char oldpath[PATH_MAX], newpath[PATH_MAX];
- int error = 0;
- error = snprintf(oldpath, PATH_MAX, "%s/new_inode",
- sdp->metafs_path);
- if (error >= PATH_MAX)
- die("rename2system (1)\n");
-
- error = snprintf(newpath, PATH_MAX, "%s/%s/%s",
- sdp->metafs_path, new_dir, new_name);
- if (error >= PATH_MAX)
- die("rename2system (2)\n");
-
- return rename(oldpath, newpath);
+ char *newpath;
+ int ret;
+
+ if (asprintf(&newpath, "%s/%s", new_dir, new_name) < 0) {
+ perror(_("Failed to allocate new path"));
+ return -1;
+ }
+
+ ret = rename(opts->new_inode, newpath);
+ free(newpath);
+ return ret;
+}
+
+static int build_paths(const char *metafs_path, struct jadd_opts *opts)
+{
+ int i = 0;
+ struct {
+ char **path;
+ const char *tail;
+ } p[] = {
+ { &opts->new_inode, "new_inode" },
+ { &opts->per_node, "per_node" },
+ { &opts->jindex, "jindex" },
+ { NULL, NULL}
+ };
+
+ while (p[i].path != NULL) {
+ if (asprintf(p[i].path, "%s/%s", metafs_path, p[i].tail) < 0) {
+ while (i > 0)
+ free(*p[--i].path);
+ return 1;
+ }
+ if (opts->debug)
+ printf("%d: %s\n", i, *p[i].path);
+ i++;
+ }
+ return 0;
}
/**
@@ -143,7 +170,7 @@ static void decode_arguments(int argc, char *argv[], struct gfs2_sbd *sdp, struc
sdp->jsize = atoi(optarg);
break;
case 'j':
- sdp->md.journals = atoi(optarg);
+ opts->journals = atoi(optarg);
break;
case 'q':
opts->quiet = 1;
@@ -187,9 +214,9 @@ static void decode_arguments(int argc, char *argv[], struct gfs2_sbd *sdp, struc
}
}
-static void verify_arguments(struct gfs2_sbd *sdp)
+static void verify_arguments(struct gfs2_sbd *sdp, struct jadd_opts *opts)
{
- if (!sdp->md.journals)
+ if (!opts->journals)
die( _("no journals specified\n"));
if (sdp->jsize < 32 || sdp->jsize > 1024)
die( _("bad journal size\n"));
@@ -197,13 +224,7 @@ static void verify_arguments(struct gfs2_sbd *sdp)
die( _("bad quota change size\n"));
}
-/**
- * print_results - print out summary information
- * @sdp: the command line
- *
- */
-
-static void print_results(struct gfs2_sbd *sdp, struct jadd_opts *opts)
+static void print_results(struct jadd_opts *opts)
{
if (opts->debug)
printf("\n");
@@ -211,22 +232,16 @@ static void print_results(struct gfs2_sbd *sdp, struct jadd_opts *opts)
return;
printf( _("Filesystem: %s\n"), opts->path);
- printf( _("Old Journals: %u\n"), sdp->orig_journals);
- printf( _("New Journals: %u\n"), sdp->md.journals);
-
+ printf( _("Old Journals: %u\n"), opts->orig_journals);
+ printf( _("New Journals: %u\n"), opts->journals);
}
-static int
-create_new_inode(struct gfs2_sbd *sdp)
+static int create_new_inode(struct jadd_opts *opts)
{
- char name[PATH_MAX];
+ char *name = opts->new_inode;
int fd;
int error;
- error = snprintf(name, PATH_MAX, "%s/new_inode", sdp->metafs_path);
- if (error >= PATH_MAX)
- die("create_new_inode (1)\n");
-
for (;;) {
fd = open(name, O_WRONLY | O_CREAT | O_EXCL | O_NOFOLLOW | O_CLOEXEC, 0600);
if (fd >= 0)
@@ -242,18 +257,17 @@ create_new_inode(struct gfs2_sbd *sdp)
exit(EXIT_FAILURE);
}
}
-
+
return fd;
}
-static void
-add_ir(struct gfs2_sbd *sdp)
+static void add_ir(struct jadd_opts *opts)
{
int fd;
char new_name[256];
int error;
- fd = create_new_inode(sdp);
+ fd = create_new_inode(opts);
{
struct gfs2_inum_range ir;
@@ -265,26 +279,25 @@ add_ir(struct gfs2_sbd *sdp)
exit(EXIT_FAILURE);
}
}
-
+
close(fd);
-
- sprintf(new_name, "inum_range%u", sdp->md.journals);
- error = rename2system(sdp, "per_node", new_name);
+
+ sprintf(new_name, "inum_range%u", opts->journals);
+ error = rename2system(opts, opts->per_node, new_name);
if (error < 0 && errno != EEXIST){
perror("add_ir rename2system");
exit(EXIT_FAILURE);
}
}
-static void
-add_sc(struct gfs2_sbd *sdp)
+static void add_sc(struct jadd_opts *opts)
{
int fd;
char new_name[256];
int error;
-
- fd = create_new_inode(sdp);
-
+
+ fd = create_new_inode(opts);
+
{
struct gfs2_statfs_change sc;
make_jdata(fd, "set");
@@ -298,23 +311,22 @@ add_sc(struct gfs2_sbd *sdp)
}
close(fd);
-
- sprintf(new_name, "statfs_change%u", sdp->md.journals);
- error = rename2system(sdp, "per_node", new_name);
+
+ sprintf(new_name, "statfs_change%u", opts->journals);
+ error = rename2system(opts, opts->per_node, new_name);
if (error < 0 && errno != EEXIST){
perror("add_sc rename2system");
exit(EXIT_FAILURE);
}
}
-static void
-add_qc(struct gfs2_sbd *sdp)
+static void add_qc(struct gfs2_sbd *sdp, struct jadd_opts *opts)
{
int fd;
char new_name[256];
int error;
- fd = create_new_inode(sdp);
+ fd = create_new_inode(opts);
{
char buf[sdp->bsize];
@@ -359,8 +371,8 @@ add_qc(struct gfs2_sbd *sdp)
close(fd);
- sprintf(new_name, "quota_change%u", sdp->md.journals);
- error = rename2system(sdp, "per_node", new_name);
+ sprintf(new_name, "quota_change%u", opts->journals);
+ error = rename2system(opts, opts->per_node, new_name);
if (error < 0 && errno != EEXIST){
perror("add_qc rename2system");
exit(EXIT_FAILURE);
@@ -377,16 +389,13 @@ static void gather_info(struct gfs2_sbd *sdp, struct jadd_opts *opts)
sdp->bsize = statbuf.f_bsize;
}
-static void
-find_current_journals(struct gfs2_sbd *sdp)
+static void find_current_journals(struct jadd_opts *opts)
{
- char jindex[PATH_MAX];
struct dirent *dp;
DIR *dirp;
- int existing_journals = 0;
+ unsigned existing_journals = 0;
- sprintf(jindex, "%s/jindex", sdp->metafs_path);
- dirp = opendir(jindex);
+ dirp = opendir(opts->jindex);
if (!dirp) {
perror("jindex");
exit(EXIT_FAILURE);
@@ -400,21 +409,20 @@ find_current_journals(struct gfs2_sbd *sdp)
}
close:
closedir(dirp);
- if (existing_journals <= 0) {
+ if (existing_journals == 0) {
die( _("No journals found. Did you run mkfs.gfs2 correctly?\n"));
}
- sdp->orig_journals = existing_journals;
+ opts->orig_journals = existing_journals;
}
-static void
-add_j(struct gfs2_sbd *sdp)
+static void add_j(struct gfs2_sbd *sdp, struct jadd_opts *opts)
{
int fd;
char new_name[256];
int error;
- fd = create_new_inode(sdp);
+ fd = create_new_inode(opts);
{
char buf[sdp->bsize];
@@ -469,22 +477,15 @@ add_j(struct gfs2_sbd *sdp)
}
close(fd);
-
- sprintf(new_name, "journal%u", sdp->md.journals);
- error = rename2system(sdp, "jindex", new_name);
+
+ sprintf(new_name, "journal%u", opts->journals);
+ error = rename2system(opts, opts->jindex, new_name);
if (error < 0 && errno != EEXIST){
perror("add_j rename2system");
exit(EXIT_FAILURE);
}
}
-/**
- * main_jadd - do everything
- * @argc:
- * @argv:
- *
- */
-
void main_jadd(int argc, char *argv[])
{
struct jadd_opts opts = {0};
@@ -495,10 +496,10 @@ void main_jadd(int argc, char *argv[])
memset(sdp, 0, sizeof(struct gfs2_sbd));
sdp->jsize = GFS2_DEFAULT_JSIZE;
sdp->qcsize = GFS2_DEFAULT_QCSIZE;
- sdp->md.journals = 1;
+ opts.journals = 1;
decode_arguments(argc, argv, sdp, &opts);
- verify_arguments(sdp);
+ verify_arguments(sdp, &opts);
sbd.path_fd = lgfs2_open_mnt_dir(opts.path, O_RDONLY|O_CLOEXEC, &mnt);
if (sbd.path_fd < 0) {
@@ -516,28 +517,36 @@ void main_jadd(int argc, char *argv[])
exit(EXIT_FAILURE);
}
+ if (build_paths(sdp->metafs_path, &opts)) {
+ perror(_("Failed to build paths"));
+ exit(EXIT_FAILURE);
+ }
+
if (compute_constants(sdp)) {
perror(_("Bad constants (1)"));
exit(EXIT_FAILURE);
}
- find_current_journals(sdp);
+ find_current_journals(&opts);
- total = sdp->orig_journals + sdp->md.journals;
- for (sdp->md.journals = sdp->orig_journals;
- sdp->md.journals < total;
- sdp->md.journals++) {
+ total = opts.orig_journals + opts.journals;
+ for (opts.journals = opts.orig_journals;
+ opts.journals < total;
+ opts.journals++) {
if (metafs_interrupted) {
cleanup_metafs(&sbd);
exit(130);
}
- add_ir(sdp);
- add_sc(sdp);
- add_qc(sdp);
- add_j(sdp);
+ add_ir(&opts);
+ add_sc(&opts);
+ add_qc(sdp, &opts);
+ add_j(sdp, &opts);
}
+ free(opts.new_inode);
+ free(opts.per_node);
+ free(opts.jindex);
close(sdp->path_fd);
cleanup_metafs(sdp);
sync();
- print_results(sdp, &opts);
+ print_results(&opts);
}
9 years, 8 months
gfs2-utils: master - gfs2_grow: Don't use PATH_MAX in main_grow
by Andrew Price
Gitweb: http://git.fedorahosted.org/git/?p=gfs2-utils.git;a=commitdiff;h=4daadc09...
Commit: 4daadc09b2d0b6b83cee55451747486403343dc3
Parent: 89f0f242424a4cc23cd73f0288d17b52d04a900d
Author: Andrew Price <anprice(a)redhat.com>
AuthorDate: Thu Oct 9 23:35:23 2014 +0100
Committer: Andrew Price <anprice(a)redhat.com>
CommitterDate: Thu Oct 9 23:35:23 2014 +0100
gfs2_grow: Don't use PATH_MAX in main_grow
Although "large enough" for most cases, PATH_MAX is an arbitrary limit
for a file path and doesn't reflect reality. Use asprintf(3) to allocate
only as much memory as we need to hold the path to the rindex. open(2)
will tell us if it's too long.
Signed-off-by: Andrew Price <anprice(a)redhat.com>
---
gfs2/mkfs/main_grow.c | 24 +++++++++++++++++++-----
1 files changed, 19 insertions(+), 5 deletions(-)
diff --git a/gfs2/mkfs/main_grow.c b/gfs2/mkfs/main_grow.c
index 79ba56a..33618de 100644
--- a/gfs2/mkfs/main_grow.c
+++ b/gfs2/mkfs/main_grow.c
@@ -320,11 +320,28 @@ static void print_info(struct gfs2_sbd *sdp, char *device, char *mnt_path)
(unsigned long long)(fsgrowth * sdp->bsize) / MB);
}
+static int open_rindex(char *metafs_path, int mode)
+{
+ char *path;
+ int fd;
+
+ if (asprintf(&path, "%s/rindex", metafs_path) < 0) {
+ perror(_("Failed to open rindex"));
+ return -1;
+ }
+ fd = open(path, (mode | O_CLOEXEC));
+ if (fd < 0) {
+ perror(path);
+ fprintf(stderr, _("Please run fsck.gfs2\n"));
+ }
+ free(path);
+ return fd;
+}
+
void main_grow(int argc, char *argv[])
{
struct gfs2_sbd sbd, *sdp = &sbd;
int rindex_fd;
- char rindex_name[PATH_MAX];
int error = EXIT_SUCCESS;
int devflags = (test ? O_RDONLY : O_RDWR) | O_CLOEXEC;
@@ -376,12 +393,9 @@ void main_grow(int argc, char *argv[])
perror(_("Failed to mount GFS2 meta file system"));
exit(EXIT_FAILURE);
}
-
- sprintf(rindex_name, "%s/rindex", sdp->metafs_path);
- rindex_fd = open(rindex_name, (test ? O_RDONLY : O_RDWR) | O_CLOEXEC);
+ rindex_fd = open_rindex(sdp->metafs_path, (test ? O_RDONLY : O_RDWR));
if (rindex_fd < 0) {
cleanup_metafs(sdp);
- perror(_("GFS2 rindex not found. Please run fsck.gfs2.\n"));
exit(EXIT_FAILURE);
}
/* Get master dinode */
9 years, 8 months
gfs2-utils: master - libgfs2: metafs_path improvements
by Andrew Price
Gitweb: http://git.fedorahosted.org/git/?p=gfs2-utils.git;a=commitdiff;h=89f0f242...
Commit: 89f0f242424a4cc23cd73f0288d17b52d04a900d
Parent: ec2b6270b291a671b70a17a12389d8fecaabd61b
Author: Andrew Price <anprice(a)redhat.com>
AuthorDate: Tue Oct 7 23:23:21 2014 +0100
Committer: Andrew Price <anprice(a)redhat.com>
CommitterDate: Tue Oct 7 23:23:21 2014 +0100
libgfs2: metafs_path improvements
Switch the metafs_path field in struct gfs2_sbd to be a pointer instead
of a char[PATH_MAX] and use strdup to set it in mount_gfs2_meta. Also
rework the metafs mounting and cleanup code to back out more robustly on
errors and set/reset signal handlers through a single function.
Note the SIGSEGV handler has been removed: when a SIGSEGV handler
returns, execution restarts at the bad instruction which triggered it,
so handling it could only ever cause an infinite loop.
Signed-off-by: Andrew Price <anprice(a)redhat.com>
---
gfs2/libgfs2/libgfs2.h | 2 +-
gfs2/libgfs2/misc.c | 66 +++++++++++++++++++++++++++++-------------------
2 files changed, 41 insertions(+), 27 deletions(-)
diff --git a/gfs2/libgfs2/libgfs2.h b/gfs2/libgfs2/libgfs2.h
index 6509e9b..60c1989 100644
--- a/gfs2/libgfs2/libgfs2.h
+++ b/gfs2/libgfs2/libgfs2.h
@@ -326,7 +326,7 @@ struct gfs2_sbd {
struct master_dir md;
int metafs_fd;
- char metafs_path[PATH_MAX]; /* where metafs is mounted */
+ char *metafs_path; /* where metafs is mounted */
struct special_blocks eattr_blocks;
uint64_t rg_one_length;
diff --git a/gfs2/libgfs2/misc.c b/gfs2/libgfs2/misc.c
index 6feccad..c72af55 100644
--- a/gfs2/libgfs2/misc.c
+++ b/gfs2/libgfs2/misc.c
@@ -210,8 +210,10 @@ static int lock_for_admin(struct gfs2_sbd *sdp)
return -1;
error = flock(sdp->metafs_fd, LOCK_EX);
- if (error)
+ if (error) {
+ close(sdp->metafs_fd);
return -1;
+ }
if (cfg_debug)
printf("Got it.\n");
return 0;
@@ -222,40 +224,57 @@ static void sighandler(int error)
metafs_interrupted = 1;
}
-int mount_gfs2_meta(struct gfs2_sbd *sdp, const char *path)
+static void setsigs(void (*handler)(int))
{
- int ret;
- struct sigaction sa = { .sa_handler = &sighandler };
-
- memset(sdp->metafs_path, 0, PATH_MAX);
- snprintf(sdp->metafs_path, PATH_MAX - 1, "/tmp/.gfs2meta.XXXXXX");
-
- if(!mkdtemp(sdp->metafs_path))
- return -1;
+ struct sigaction sa = { .sa_handler = handler };
sigaction(SIGINT, &sa, NULL);
sigaction(SIGILL, &sa, NULL);
sigaction(SIGTERM, &sa, NULL);
sigaction(SIGHUP, &sa, NULL);
sigaction(SIGABRT, &sa, NULL);
- sigaction(SIGSEGV, &sa, NULL);
sigaction(SIGCONT, &sa, NULL);
sigaction(SIGUSR1, &sa, NULL);
sigaction(SIGUSR2, &sa, NULL);
- ret = mount(path, sdp->metafs_path, "gfs2meta", 0, NULL);
- if (ret) {
- rmdir(sdp->metafs_path);
+}
+
+int mount_gfs2_meta(struct gfs2_sbd *sdp, const char *path)
+{
+ int ret;
+
+ sdp->metafs_path = strdup("/tmp/.gfs2meta.XXXXXX");
+ if (sdp->metafs_path == NULL)
return -1;
- }
+
+ if(!mkdtemp(sdp->metafs_path))
+ goto err_free;
+
+ setsigs(sighandler);
+
+ ret = mount(path, sdp->metafs_path, "gfs2meta", 0, NULL);
+ if (ret)
+ goto err_rmdir;
+
if (lock_for_admin(sdp))
- return -1;
+ goto err_umount;
+
return 0;
+
+err_umount:
+ if (umount(sdp->metafs_path))
+ fprintf(stderr, "Could not unmount %s: %s\n", sdp->metafs_path, strerror(errno));
+ setsigs(SIG_DFL);
+err_rmdir:
+ rmdir(sdp->metafs_path);
+err_free:
+ free(sdp->metafs_path);
+ sdp->metafs_path = NULL;
+ return -1;
}
void cleanup_metafs(struct gfs2_sbd *sdp)
{
int ret;
- struct sigaction sa = { .sa_handler = SIG_DFL };
if (sdp->metafs_fd <= 0)
return;
@@ -268,14 +287,9 @@ void cleanup_metafs(struct gfs2_sbd *sdp)
sdp->metafs_path, strerror(errno));
else
rmdir(sdp->metafs_path);
- sigaction(SIGINT, &sa, NULL);
- sigaction(SIGILL, &sa, NULL);
- sigaction(SIGTERM, &sa, NULL);
- sigaction(SIGHUP, &sa, NULL);
- sigaction(SIGABRT, &sa, NULL);
- sigaction(SIGSEGV, &sa, NULL);
- sigaction(SIGCONT, &sa, NULL);
- sigaction(SIGUSR1, &sa, NULL);
- sigaction(SIGUSR2, &sa, NULL);
+
+ setsigs(SIG_DFL);
metafs_interrupted = 0;
+ free(sdp->metafs_path);
+ sdp->metafs_path = NULL;
}
9 years, 8 months