cluster: RHEL6 - libgfs2: Set umask before calling mkstemp
by Andrew Price
Gitweb: http://git.fedorahosted.org/git/?p=cluster.git;a=commitdiff;h=136be5fd39f...
Commit: 136be5fd39fc6a2f1a277e5f8c9be542e514a538
Parent: 6ab6b7c93a8868f5f95eea67fc3588af9e8c2a52
Author: Andrew Price <anprice(a)redhat.com>
AuthorDate: Fri Aug 16 10:37:40 2013 +0100
Committer: Andrew Price <anprice(a)redhat.com>
CommitterDate: Fri Aug 16 10:40:01 2013 +0100
libgfs2: Set umask before calling mkstemp
Coverity highlighted a case where mkstemp() was being called without the
umask being set. This sets the umask to create the file with 0600
permissions and then restores it after mkstemp() is called.
rhbz#996233
Signed-off-by: Andrew Price <anprice(a)redhat.com>
---
gfs2/libgfs2/misc.c | 3 +++
1 files changed, 3 insertions(+), 0 deletions(-)
diff --git a/gfs2/libgfs2/misc.c b/gfs2/libgfs2/misc.c
index 6807f60..3989bf1 100644
--- a/gfs2/libgfs2/misc.c
+++ b/gfs2/libgfs2/misc.c
@@ -219,13 +219,16 @@ static void remove_mtab_entry(struct gfs2_sbd *sdp)
struct mntent *mountent;
char mtab_tmpfn[PATH_MAX];
int error, fd;
+ mode_t mask;
mtab = setmntent("/etc/mtab", "rt");
if (mtab == NULL)
die("Couldn't open /etc/mtab for writing: %s\n",
strerror(errno));
strcpy(mtab_tmpfn, "/etc/mtab.XXXXXX");
+ mask = umask(S_IXUSR | S_IRWXG | S_IRWXO);
fd = mkstemp(mtab_tmpfn);
+ umask(mask);
if (fd < 0)
die("Couldn't open temporary mtab file for writing: %s\n",
strerror(errno));
10 years, 8 months
cluster: RHEL6 - libgfs2: Correct error message in mtab update code
by Bob Peterson
Gitweb: http://git.fedorahosted.org/git/?p=cluster.git;a=commitdiff;h=6ab6b7c93a8...
Commit: 6ab6b7c93a8868f5f95eea67fc3588af9e8c2a52
Parent: cac6df6f85e0fe776ef53750d93708223c6534d1
Author: Bob Peterson <rpeterso(a)redhat.com>
AuthorDate: Thu Aug 15 07:41:56 2013 -0500
Committer: Bob Peterson <rpeterso(a)redhat.com>
CommitterDate: Thu Aug 15 07:41:56 2013 -0500
libgfs2: Correct error message in mtab update code
If we encounter an error while trying to update the /etc/mtab file
the code was reporting that the problem in adding an entry. The
problem is, it's really trying to add the entries to the temp file,
which will be renamed to /etc/mtab, for the sake of removing an
entry from mtab. Therefore, I'm correcting the error message so that
it makes more sense.
rhbz#996233
---
gfs2/libgfs2/misc.c | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/gfs2/libgfs2/misc.c b/gfs2/libgfs2/misc.c
index f7fab7e..6807f60 100644
--- a/gfs2/libgfs2/misc.c
+++ b/gfs2/libgfs2/misc.c
@@ -240,14 +240,14 @@ static void remove_mtab_entry(struct gfs2_sbd *sdp)
continue;
error = addmntent(mtabnew, mountent);
if (error)
- die("Unable to add mount entry to mtab.\n");
+ die("Unable to remove mount entry from mtab.\n");
}
endmntent(mtab);
fclose(mtabnew);
close(fd);
if (rename(mtab_tmpfn, "/etc/mtab"))
- fprintf(stderr, "Unable to add mount entry to mtab.\n");
+ fprintf(stderr, "Unable to remove mount entry from mtab.\n");
}
void cleanup_metafs(struct gfs2_sbd *sdp)
10 years, 8 months
cluster: RHEL6 - libgfs2: check return code of rename
by Bob Peterson
Gitweb: http://git.fedorahosted.org/git/?p=cluster.git;a=commitdiff;h=cac6df6f85e...
Commit: cac6df6f85e0fe776ef53750d93708223c6534d1
Parent: e4d17cb18e35f4d070cdbafe16cede304270e6cd
Author: Bob Peterson <rpeterso(a)redhat.com>
AuthorDate: Thu Aug 15 07:34:26 2013 -0500
Committer: Bob Peterson <rpeterso(a)redhat.com>
CommitterDate: Thu Aug 15 07:34:26 2013 -0500
libgfs2: check return code of rename
This patch adds code to check the return code of 'rename' while
trying to update /etc/mtab.
rhbz#996233
---
gfs2/libgfs2/misc.c | 3 ++-
1 files changed, 2 insertions(+), 1 deletions(-)
diff --git a/gfs2/libgfs2/misc.c b/gfs2/libgfs2/misc.c
index a6738b6..f7fab7e 100644
--- a/gfs2/libgfs2/misc.c
+++ b/gfs2/libgfs2/misc.c
@@ -246,7 +246,8 @@ static void remove_mtab_entry(struct gfs2_sbd *sdp)
endmntent(mtab);
fclose(mtabnew);
close(fd);
- rename(mtab_tmpfn, "/etc/mtab");
+ if (rename(mtab_tmpfn, "/etc/mtab"))
+ fprintf(stderr, "Unable to add mount entry to mtab.\n");
}
void cleanup_metafs(struct gfs2_sbd *sdp)
10 years, 8 months
cluster: RHEL6 - gfs2_tool: Update /etc/mtab with metafs mounts, handle interrupts
by Bob Peterson
Gitweb: http://git.fedorahosted.org/git/?p=cluster.git;a=commitdiff;h=e4d17cb18e3...
Commit: e4d17cb18e35f4d070cdbafe16cede304270e6cd
Parent: 364c3cca8a4ea092b49af95c9babb15e10271661
Author: Bob Peterson <rpeterso(a)redhat.com>
AuthorDate: Thu Aug 8 14:50:04 2013 -0500
Committer: Bob Peterson <rpeterso(a)redhat.com>
CommitterDate: Wed Aug 14 09:48:14 2013 -0500
gfs2_tool: Update /etc/mtab with metafs mounts, handle interrupts
This patch gives libgfs2 the ability to add the metafs to the
/etc/mtab file, so that a "mount" will show it and "umount -a -tgfs2"
will unmount it. At the same time, it also catches interrupt signals
while gfs2_tool df is running, and if interrupted, it unmounts the
metafs.
rhbz#996233
---
gfs2/libgfs2/libgfs2.h | 2 +
gfs2/libgfs2/misc.c | 110 +++++++++++++++++++++++++++++++++++++++++-------
gfs2/mkfs/main_grow.c | 11 ++++-
gfs2/mkfs/main_jadd.c | 4 ++
gfs2/quota/check.c | 4 ++
gfs2/quota/main.c | 32 ++++++++------
gfs2/tool/misc.c | 8 ++++
7 files changed, 141 insertions(+), 30 deletions(-)
diff --git a/gfs2/libgfs2/libgfs2.h b/gfs2/libgfs2/libgfs2.h
index d5de337..375327f 100644
--- a/gfs2/libgfs2/libgfs2.h
+++ b/gfs2/libgfs2/libgfs2.h
@@ -673,6 +673,8 @@ extern int gfs2_query(int *setonabort, struct gfs2_options *opts,
/* misc.c */
+extern int metafs_interrupted;
+
extern int compute_heightsize(struct gfs2_sbd *sdp, uint64_t *heightsize,
uint32_t *maxheight, uint32_t bsize1, int diptrs, int inptrs);
extern int compute_constants(struct gfs2_sbd *sdp);
diff --git a/gfs2/libgfs2/misc.c b/gfs2/libgfs2/misc.c
index 31fc665..a6738b6 100644
--- a/gfs2/libgfs2/misc.c
+++ b/gfs2/libgfs2/misc.c
@@ -17,6 +17,7 @@
#include <sys/sysmacros.h>
#include <mntent.h>
#include <sys/time.h>
+#include <signal.h>
#include "libgfs2.h"
@@ -25,6 +26,7 @@
#define DIV_RU(x, y) (((x) + (y) - 1) / (y))
static char sysfs_buf[PAGE_SIZE];
+int metafs_interrupted = 0;
int compute_heightsize(struct gfs2_sbd *sdp, uint64_t *heightsize,
uint32_t *maxheight, uint32_t bsize1, int diptrs, int inptrs)
@@ -211,30 +213,46 @@ static int lock_for_admin(struct gfs2_sbd *sdp)
return 0;
}
-
-int mount_gfs2_meta(struct gfs2_sbd *sdp)
+static void remove_mtab_entry(struct gfs2_sbd *sdp)
{
- int ret;
-
- memset(sdp->metafs_path, 0, PATH_MAX);
- snprintf(sdp->metafs_path, PATH_MAX - 1, "/tmp/.gfs2meta.XXXXXX");
+ FILE *mtab, *mtabnew;
+ struct mntent *mountent;
+ char mtab_tmpfn[PATH_MAX];
+ int error, fd;
+
+ mtab = setmntent("/etc/mtab", "rt");
+ if (mtab == NULL)
+ die("Couldn't open /etc/mtab for writing: %s\n",
+ strerror(errno));
+ strcpy(mtab_tmpfn, "/etc/mtab.XXXXXX");
+ fd = mkstemp(mtab_tmpfn);
+ if (fd < 0)
+ die("Couldn't open temporary mtab file for writing: %s\n",
+ strerror(errno));
- if(!mkdtemp(sdp->metafs_path))
- return -1;
+ mtabnew = fdopen(fd, "wt");
+ if (mtabnew == NULL)
+ die("Couldn't open %s for writing : %s\n", mtab_tmpfn,
+ strerror(errno));
- ret = mount(sdp->path_name, sdp->metafs_path, "gfs2meta", 0, NULL);
- if (ret) {
- rmdir(sdp->metafs_path);
- return -1;
+ while ((mountent = getmntent(mtab)) != NULL) {
+ if (!strcmp(mountent->mnt_dir, sdp->metafs_path))
+ continue;
+ error = addmntent(mtabnew, mountent);
+ if (error)
+ die("Unable to add mount entry to mtab.\n");
}
- if (lock_for_admin(sdp))
- return -1;
- return 0;
+
+ endmntent(mtab);
+ fclose(mtabnew);
+ close(fd);
+ rename(mtab_tmpfn, "/etc/mtab");
}
void cleanup_metafs(struct gfs2_sbd *sdp)
{
int ret;
+ struct sigaction sa = { .sa_handler = SIG_DFL };
if (sdp->metafs_fd <= 0)
return;
@@ -247,6 +265,68 @@ 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);
+ metafs_interrupted = 0;
+ remove_mtab_entry(sdp);
+}
+
+static void sighandler(int error)
+{
+ metafs_interrupted = 1;
+}
+
+int mount_gfs2_meta(struct gfs2_sbd *sdp)
+{
+ int ret;
+ struct mntent ment;
+ char mnt_type[5] = "gfs2";
+ char mnt_opts[9] = "gfs2meta";
+ FILE *mtab;
+ 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;
+
+ mtab = setmntent("/etc/mtab", "at");
+ if (mtab == NULL) {
+ rmdir(sdp->metafs_path);
+ return -1;
+ }
+
+ 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(sdp->path_name, sdp->metafs_path, "gfs2meta", 0, NULL);
+ if (ret) {
+ rmdir(sdp->metafs_path);
+ return -1;
+ }
+ ment.mnt_fsname = sdp->path_name;
+ ment.mnt_dir = sdp->metafs_path;
+ ment.mnt_type = mnt_type;
+ ment.mnt_opts = mnt_opts;
+ addmntent(mtab, &ment);
+ endmntent(mtab);
+ if (lock_for_admin(sdp))
+ return -1;
+ return 0;
}
static char *__get_sysfs(const char *fsname, const char *filename)
diff --git a/gfs2/mkfs/main_grow.c b/gfs2/mkfs/main_grow.c
index 8839953..831239e 100644
--- a/gfs2/mkfs/main_grow.c
+++ b/gfs2/mkfs/main_grow.c
@@ -373,6 +373,8 @@ main_grow(int argc, char *argv[])
/* we're only going to write out new RG information after */
/* the existing RGs, and only write to the index at EOF. */
ri_update(sdp, rindex_fd, &rgcount, &sane);
+ if (metafs_interrupted)
+ goto out;
fssize = filesystem_size(sdp);
if (!sdp->rgtree.osi_node) {
log_err(_("Error: No resource groups found.\n"));
@@ -395,9 +397,15 @@ main_grow(int argc, char *argv[])
} else {
int old_rg_count;
+ if (metafs_interrupted)
+ goto out;
compute_rgrp_layout(sdp, &sdp->rgtree, TRUE);
+ if (metafs_interrupted)
+ goto out;
print_info(sdp);
initialize_new_portion(sdp, &old_rg_count);
+ if (metafs_interrupted)
+ goto out;
fix_rindex(sdp, rindex_fd, old_rg_count);
}
out:
@@ -409,6 +417,7 @@ main_grow(int argc, char *argv[])
}
close(sdp->path_fd);
sync();
- log_notice( _("gfs2_grow complete.\n"));
+ if (!metafs_interrupted)
+ log_notice( _("gfs2_grow complete.\n"));
exit(error);
}
diff --git a/gfs2/mkfs/main_jadd.c b/gfs2/mkfs/main_jadd.c
index be13271..3e44fca 100644
--- a/gfs2/mkfs/main_jadd.c
+++ b/gfs2/mkfs/main_jadd.c
@@ -523,6 +523,10 @@ void main_jadd(int argc, char *argv[])
for (sdp->md.journals = sdp->orig_journals;
sdp->md.journals < total;
sdp->md.journals++) {
+ if (metafs_interrupted) {
+ cleanup_metafs(&sbd);
+ exit(130);
+ }
add_ir(sdp);
add_sc(sdp);
add_qc(sdp);
diff --git a/gfs2/quota/check.c b/gfs2/quota/check.c
index 81a4364..2208d2a 100644
--- a/gfs2/quota/check.c
+++ b/gfs2/quota/check.c
@@ -247,6 +247,8 @@ read_quota_file(struct gfs2_sbd *sdp, commandline_t *comline,
uint64_t end = fe->fe_logical + fe->fe_length, val_off;
unsigned int v_off;
+ if (metafs_interrupted)
+ break;
end = end > quota_file_size ? quota_file_size : end;
/* we only need to get the value fields, not the whole quota
* This also works when struct gfs2_quota straddle page
@@ -497,6 +499,8 @@ set_list(struct gfs2_sbd *sdp, commandline_t *comline, int user,
}
for (tmp = list->next; tmp != list; tmp = tmp->next) {
+ if (metafs_interrupted)
+ goto out;
v = osi_list_entry(tmp, values_t, v_list);
offset = (2 * (uint64_t)v->v_id + ((user) ? 0 : 1)) *
diff --git a/gfs2/quota/main.c b/gfs2/quota/main.c
index 0625b7d..d9f56ab 100644
--- a/gfs2/quota/main.c
+++ b/gfs2/quota/main.c
@@ -401,18 +401,20 @@ do_reset(struct gfs2_sbd *sdp, commandline_t *comline)
strerror(errno));
}
- read_quota_internal(fd, 0, GQ_ID_USER, &q);
- write_quota_internal(fd, 0, GQ_ID_USER, &q);
+ if (!metafs_interrupted) {
+ read_quota_internal(fd, 0, GQ_ID_USER, &q);
+ write_quota_internal(fd, 0, GQ_ID_USER, &q);
- read_quota_internal(fd, 0, GQ_ID_GROUP, &q);
- write_quota_internal(fd, 0, GQ_ID_GROUP, &q);
+ read_quota_internal(fd, 0, GQ_ID_GROUP, &q);
+ write_quota_internal(fd, 0, GQ_ID_GROUP, &q);
- /* truncate the quota file such that only the first
- * two quotas(uid=0 and gid=0) remain.
- */
- if (ftruncate(fd, (sizeof(struct gfs2_quota)) * 2))
- die("couldn't truncate quota file %s\n", strerror(errno));
-
+ /* truncate the quota file such that only the first
+ * two quotas(uid=0 and gid=0) remain.
+ */
+ if (ftruncate(fd, (sizeof(struct gfs2_quota)) * 2))
+ die("couldn't truncate quota file %s\n",
+ strerror(errno));
+ }
close(fd);
close(sdp->metafs_fd);
cleanup_metafs(sdp);
@@ -508,6 +510,8 @@ do_list(struct gfs2_sbd *sdp, commandline_t *comline)
struct fiemap_extent *fe = &fmap2->fm_extents[i];
uint64_t end = fe->fe_logical + fe->fe_length;
+ if (metafs_interrupted)
+ goto fmap2_free;
end = end > quota_file_size ? quota_file_size : end;
startid = DIV_RU(fe->fe_logical, sizeof(struct gfs2_quota));
if (startid % 2 != pass)
@@ -582,7 +586,7 @@ do_get_one(struct gfs2_sbd *sdp, commandline_t *comline, char *filesystem)
strcat(quota_file, "/quota");
fd = open(quota_file, O_RDONLY);
- if (fd < 0) {
+ if (fd < 0 || metafs_interrupted) {
close(sdp->metafs_fd);
cleanup_metafs(sdp);
die("can't open file %s: %s\n", quota_file,
@@ -756,7 +760,7 @@ do_set(struct gfs2_sbd *sdp, commandline_t *comline)
strcat(quota_file, "/quota");
fd = open(quota_file, O_RDWR);
- if (fd < 0) {
+ if (fd < 0 || metafs_interrupted) {
close(sdp->metafs_fd);
cleanup_metafs(sdp);
die("can't open file %s: %s\n", quota_file,
diff --git a/gfs2/tool/misc.c b/gfs2/tool/misc.c
index 359567c..37c81cd 100644
--- a/gfs2/tool/misc.c
+++ b/gfs2/tool/misc.c
@@ -276,11 +276,19 @@ void print_journals(int argc, char **argv)
sprintf(jindex_name, "%s/jindex", sbd.metafs_path);
jindex = opendir(jindex_name);
+ if (metafs_interrupted) {
+ cleanup_metafs(&sbd);
+ exit(130);
+ }
if (!jindex) {
die( _("Can't open %s\n"), jindex_name);
} else {
jcount = 0;
while ((journal = readdir(jindex))) {
+ if (metafs_interrupted) {
+ cleanup_metafs(&sbd);
+ exit(130);
+ }
if (journal->d_name[0] == '.')
continue;
sprintf(jname, "%s/%s", jindex_name, journal->d_name);
10 years, 8 months
gfs2-utils: RHEL7 - gfs2_tool: catch interrupts while the metafs is mounted
by Bob Peterson
Gitweb: http://git.fedorahosted.org/git/?p=gfs2-utils.git;a=commitdiff;h=12604ad3...
Commit: 12604ad33b41eca2b7c6511da8d519a299787ef5
Parent: 43da4b0b6a55cfad8f78a703fb3359cac0c4968a
Author: Bob Peterson <rpeterso(a)redhat.com>
AuthorDate: Mon Aug 12 15:08:55 2013 -0500
Committer: Bob Peterson <rpeterso(a)redhat.com>
CommitterDate: Tue Aug 13 14:38:06 2013 -0500
gfs2_tool: catch interrupts while the metafs is mounted
This patch catches interrupt signals while the metafs is mounted,
and if interrupted, sets a flag. Later, if the caller sees the flag,
they will unmount the metafs. That way, the metafs is never left
mounted by accident if a gfs2_grow or gfs2_jadd is interrupted or
killed.
---
gfs2/libgfs2/libgfs2.h | 2 ++
gfs2/libgfs2/misc.c | 28 ++++++++++++++++++++++++++++
gfs2/mkfs/main_grow.c | 23 ++++++++++++++++++-----
gfs2/mkfs/main_jadd.c | 4 ++++
4 files changed, 52 insertions(+), 5 deletions(-)
diff --git a/gfs2/libgfs2/libgfs2.h b/gfs2/libgfs2/libgfs2.h
index e994d3b..dd7420b 100644
--- a/gfs2/libgfs2/libgfs2.h
+++ b/gfs2/libgfs2/libgfs2.h
@@ -713,6 +713,8 @@ extern void increase_verbosity(void);
extern void decrease_verbosity(void);
/* misc.c */
+extern int metafs_interrupted;
+
extern int compute_heightsize(struct gfs2_sbd *sdp, uint64_t *heightsize,
uint32_t *maxheight, uint32_t bsize1, int diptrs, int inptrs);
extern int compute_constants(struct gfs2_sbd *sdp);
diff --git a/gfs2/libgfs2/misc.c b/gfs2/libgfs2/misc.c
index 6f2dbdb..7f500e6 100644
--- a/gfs2/libgfs2/misc.c
+++ b/gfs2/libgfs2/misc.c
@@ -18,6 +18,7 @@
#include <sys/sysmacros.h>
#include <mntent.h>
#include <sys/time.h>
+#include <signal.h>
#include "libgfs2.h"
@@ -25,6 +26,8 @@
#define SYS_BASE "/sys/fs/gfs2" /* FIXME: Look in /proc/mounts to find this */
#define DIV_RU(x, y) (((x) + (y) - 1) / (y))
+int metafs_interrupted = 0;
+
int compute_heightsize(struct gfs2_sbd *sdp, uint64_t *heightsize,
uint32_t *maxheight, uint32_t bsize1, int diptrs, int inptrs)
{
@@ -179,10 +182,15 @@ static int lock_for_admin(struct gfs2_sbd *sdp)
return 0;
}
+static void sighandler(int error)
+{
+ metafs_interrupted = 1;
+}
int mount_gfs2_meta(struct gfs2_sbd *sdp)
{
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");
@@ -190,6 +198,15 @@ int mount_gfs2_meta(struct gfs2_sbd *sdp)
if(!mkdtemp(sdp->metafs_path))
return -1;
+ 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(sdp->path_name, sdp->metafs_path, "gfs2meta", 0, NULL);
if (ret) {
rmdir(sdp->metafs_path);
@@ -203,6 +220,7 @@ int mount_gfs2_meta(struct gfs2_sbd *sdp)
void cleanup_metafs(struct gfs2_sbd *sdp)
{
int ret;
+ struct sigaction sa = { .sa_handler = SIG_DFL };
if (sdp->metafs_fd <= 0)
return;
@@ -215,6 +233,16 @@ 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);
+ metafs_interrupted = 0;
}
int set_sysfs(const char *fsname, const char *filename, const char *val)
diff --git a/gfs2/mkfs/main_grow.c b/gfs2/mkfs/main_grow.c
index d324af9..5db91d9 100644
--- a/gfs2/mkfs/main_grow.c
+++ b/gfs2/mkfs/main_grow.c
@@ -372,10 +372,13 @@ main_grow(int argc, char *argv[])
perror(_("Bad constants (1)"));
exit(EXIT_FAILURE);
}
- if (read_sb(sdp) < 0)
- die( _("Error reading superblock.\n"));
+ if (read_sb(sdp) < 0) {
+ fprintf(stderr, _("Error reading superblock.\n"));
+ exit(EXIT_FAILURE);
+ }
if (sdp->gfs1) {
- die( _("cannot grow gfs1 filesystem\n"));
+ fprintf(stderr, _("cannot grow gfs1 filesystem\n"));
+ exit(EXIT_FAILURE);
}
fix_device_geometry(sdp);
if (mount_gfs2_meta(sdp)) {
@@ -387,7 +390,8 @@ main_grow(int argc, char *argv[])
rindex_fd = open(rindex_name, (test ? O_RDONLY : O_RDWR) | O_CLOEXEC);
if (rindex_fd < 0) {
cleanup_metafs(sdp);
- die( _("GFS2 rindex not found. Please run fsck.gfs2.\n"));
+ perror(_("GFS2 rindex not found. Please run fsck.gfs2.\n"));
+ exit(EXIT_FAILURE);
}
/* Get master dinode */
sdp->master_dir = lgfs2_inode_read(sdp, sdp->sd_sb.sb_master_dir.no_addr);
@@ -402,6 +406,8 @@ main_grow(int argc, char *argv[])
/* we're only going to write out new RG information after */
/* the existing RGs, and only write to the index at EOF. */
ri_update(sdp, rindex_fd, &rgcount, &sane);
+ if (metafs_interrupted)
+ goto out;
fssize = filesystem_size(sdp);
if (!sdp->rgtree.osi_node) {
log_err(_("Error: No resource groups found.\n"));
@@ -424,10 +430,16 @@ main_grow(int argc, char *argv[])
} else {
int old_rg_count;
+ if (metafs_interrupted)
+ goto out;
compute_rgrp_layout(sdp, &sdp->rgtree, TRUE);
+ if (metafs_interrupted)
+ goto out;
debug_print_rgrps(sdp, &sdp->rgtree);
print_info(sdp);
initialize_new_portion(sdp, &old_rg_count);
+ if (metafs_interrupted)
+ goto out;
fix_rindex(sdp, rindex_fd, old_rg_count);
}
out:
@@ -439,6 +451,7 @@ main_grow(int argc, char *argv[])
}
close(sdp->path_fd);
sync();
- log_notice( _("gfs2_grow complete.\n"));
+ if (!metafs_interrupted)
+ log_notice( _("gfs2_grow complete.\n"));
exit(error);
}
diff --git a/gfs2/mkfs/main_jadd.c b/gfs2/mkfs/main_jadd.c
index 2646829..b6cd8e4 100644
--- a/gfs2/mkfs/main_jadd.c
+++ b/gfs2/mkfs/main_jadd.c
@@ -529,6 +529,10 @@ void main_jadd(int argc, char *argv[])
for (sdp->md.journals = sdp->orig_journals;
sdp->md.journals < total;
sdp->md.journals++) {
+ if (metafs_interrupted) {
+ cleanup_metafs(&sbd);
+ exit(130);
+ }
add_ir(sdp);
add_sc(sdp);
add_qc(sdp);
10 years, 8 months
gfs2-utils: master - gfs2_tool: catch interrupts while the metafs is mounted
by Bob Peterson
Gitweb: http://git.fedorahosted.org/git/?p=gfs2-utils.git;a=commitdiff;h=367ccdb5...
Commit: 367ccdb51bee574edcf269ba5ea1d730b004e742
Parent: 23bcbc3512a6609216b6884a3bf088684d1e7c72
Author: Bob Peterson <rpeterso(a)redhat.com>
AuthorDate: Mon Aug 12 15:08:55 2013 -0500
Committer: Bob Peterson <rpeterso(a)redhat.com>
CommitterDate: Tue Aug 13 14:35:56 2013 -0500
gfs2_tool: catch interrupts while the metafs is mounted
This patch catches interrupt signals while the metafs is mounted,
and if interrupted, sets a flag. Later, if the caller sees the flag,
they will unmount the metafs. That way, the metafs is never left
mounted by accident if a gfs2_grow or gfs2_jadd is interrupted or
killed.
---
gfs2/libgfs2/libgfs2.h | 2 ++
gfs2/libgfs2/misc.c | 28 ++++++++++++++++++++++++++++
gfs2/mkfs/main_grow.c | 23 ++++++++++++++++++-----
gfs2/mkfs/main_jadd.c | 4 ++++
4 files changed, 52 insertions(+), 5 deletions(-)
diff --git a/gfs2/libgfs2/libgfs2.h b/gfs2/libgfs2/libgfs2.h
index e994d3b..dd7420b 100644
--- a/gfs2/libgfs2/libgfs2.h
+++ b/gfs2/libgfs2/libgfs2.h
@@ -713,6 +713,8 @@ extern void increase_verbosity(void);
extern void decrease_verbosity(void);
/* misc.c */
+extern int metafs_interrupted;
+
extern int compute_heightsize(struct gfs2_sbd *sdp, uint64_t *heightsize,
uint32_t *maxheight, uint32_t bsize1, int diptrs, int inptrs);
extern int compute_constants(struct gfs2_sbd *sdp);
diff --git a/gfs2/libgfs2/misc.c b/gfs2/libgfs2/misc.c
index 6f2dbdb..7f500e6 100644
--- a/gfs2/libgfs2/misc.c
+++ b/gfs2/libgfs2/misc.c
@@ -18,6 +18,7 @@
#include <sys/sysmacros.h>
#include <mntent.h>
#include <sys/time.h>
+#include <signal.h>
#include "libgfs2.h"
@@ -25,6 +26,8 @@
#define SYS_BASE "/sys/fs/gfs2" /* FIXME: Look in /proc/mounts to find this */
#define DIV_RU(x, y) (((x) + (y) - 1) / (y))
+int metafs_interrupted = 0;
+
int compute_heightsize(struct gfs2_sbd *sdp, uint64_t *heightsize,
uint32_t *maxheight, uint32_t bsize1, int diptrs, int inptrs)
{
@@ -179,10 +182,15 @@ static int lock_for_admin(struct gfs2_sbd *sdp)
return 0;
}
+static void sighandler(int error)
+{
+ metafs_interrupted = 1;
+}
int mount_gfs2_meta(struct gfs2_sbd *sdp)
{
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");
@@ -190,6 +198,15 @@ int mount_gfs2_meta(struct gfs2_sbd *sdp)
if(!mkdtemp(sdp->metafs_path))
return -1;
+ 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(sdp->path_name, sdp->metafs_path, "gfs2meta", 0, NULL);
if (ret) {
rmdir(sdp->metafs_path);
@@ -203,6 +220,7 @@ int mount_gfs2_meta(struct gfs2_sbd *sdp)
void cleanup_metafs(struct gfs2_sbd *sdp)
{
int ret;
+ struct sigaction sa = { .sa_handler = SIG_DFL };
if (sdp->metafs_fd <= 0)
return;
@@ -215,6 +233,16 @@ 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);
+ metafs_interrupted = 0;
}
int set_sysfs(const char *fsname, const char *filename, const char *val)
diff --git a/gfs2/mkfs/main_grow.c b/gfs2/mkfs/main_grow.c
index d324af9..5db91d9 100644
--- a/gfs2/mkfs/main_grow.c
+++ b/gfs2/mkfs/main_grow.c
@@ -372,10 +372,13 @@ main_grow(int argc, char *argv[])
perror(_("Bad constants (1)"));
exit(EXIT_FAILURE);
}
- if (read_sb(sdp) < 0)
- die( _("Error reading superblock.\n"));
+ if (read_sb(sdp) < 0) {
+ fprintf(stderr, _("Error reading superblock.\n"));
+ exit(EXIT_FAILURE);
+ }
if (sdp->gfs1) {
- die( _("cannot grow gfs1 filesystem\n"));
+ fprintf(stderr, _("cannot grow gfs1 filesystem\n"));
+ exit(EXIT_FAILURE);
}
fix_device_geometry(sdp);
if (mount_gfs2_meta(sdp)) {
@@ -387,7 +390,8 @@ main_grow(int argc, char *argv[])
rindex_fd = open(rindex_name, (test ? O_RDONLY : O_RDWR) | O_CLOEXEC);
if (rindex_fd < 0) {
cleanup_metafs(sdp);
- die( _("GFS2 rindex not found. Please run fsck.gfs2.\n"));
+ perror(_("GFS2 rindex not found. Please run fsck.gfs2.\n"));
+ exit(EXIT_FAILURE);
}
/* Get master dinode */
sdp->master_dir = lgfs2_inode_read(sdp, sdp->sd_sb.sb_master_dir.no_addr);
@@ -402,6 +406,8 @@ main_grow(int argc, char *argv[])
/* we're only going to write out new RG information after */
/* the existing RGs, and only write to the index at EOF. */
ri_update(sdp, rindex_fd, &rgcount, &sane);
+ if (metafs_interrupted)
+ goto out;
fssize = filesystem_size(sdp);
if (!sdp->rgtree.osi_node) {
log_err(_("Error: No resource groups found.\n"));
@@ -424,10 +430,16 @@ main_grow(int argc, char *argv[])
} else {
int old_rg_count;
+ if (metafs_interrupted)
+ goto out;
compute_rgrp_layout(sdp, &sdp->rgtree, TRUE);
+ if (metafs_interrupted)
+ goto out;
debug_print_rgrps(sdp, &sdp->rgtree);
print_info(sdp);
initialize_new_portion(sdp, &old_rg_count);
+ if (metafs_interrupted)
+ goto out;
fix_rindex(sdp, rindex_fd, old_rg_count);
}
out:
@@ -439,6 +451,7 @@ main_grow(int argc, char *argv[])
}
close(sdp->path_fd);
sync();
- log_notice( _("gfs2_grow complete.\n"));
+ if (!metafs_interrupted)
+ log_notice( _("gfs2_grow complete.\n"));
exit(error);
}
diff --git a/gfs2/mkfs/main_jadd.c b/gfs2/mkfs/main_jadd.c
index 2646829..b6cd8e4 100644
--- a/gfs2/mkfs/main_jadd.c
+++ b/gfs2/mkfs/main_jadd.c
@@ -529,6 +529,10 @@ void main_jadd(int argc, char *argv[])
for (sdp->md.journals = sdp->orig_journals;
sdp->md.journals < total;
sdp->md.journals++) {
+ if (metafs_interrupted) {
+ cleanup_metafs(&sbd);
+ exit(130);
+ }
add_ir(sdp);
add_sc(sdp);
add_qc(sdp);
10 years, 8 months
cluster: STABLE32 - qdisk: Check that all nodes are running qdiskd and warn if not
by Christine Caulfield
Gitweb: http://git.fedorahosted.org/git/?p=cluster.git;a=commitdiff;h=b4408e05096...
Commit: b4408e050960c35793afb33b6c589bf579252609
Parent: 3e4cddfa54bf3e5dcc2e94343df54dc15539138c
Author: Christine Caulfield <ccaulfie(a)redhat.com>
AuthorDate: Tue Aug 13 16:32:38 2013 +0100
Committer: Christine Caulfield <ccaulfie(a)redhat.com>
CommitterDate: Tue Aug 13 16:32:38 2013 +0100
qdisk: Check that all nodes are running qdiskd and warn if not
At every cman poll, qdiskd now asks cman not only whether the
node is up, but also whether it it running a qdiskd. (more
accurately, it asks if anything is bound to the qdiskd
cman port). If any node is active in cman but NOT running
qdiskd then a warning is printed to syslog every 5 seconds.
rhbz#994187
Signed-off-by: Christine Caulfield <ccaulfie(a)redhat.com>
Acked-By: Fabio M. Di Nitto <fdinitto(a)redhat.com>
---
cman/qdisk/main.c | 13 +++++++++++++
1 files changed, 13 insertions(+), 0 deletions(-)
diff --git a/cman/qdisk/main.c b/cman/qdisk/main.c
index 4d4397a..9dee134 100644
--- a/cman/qdisk/main.c
+++ b/cman/qdisk/main.c
@@ -632,6 +632,7 @@ check_cman(qd_ctx *ctx, memb_mask_t mask, memb_mask_t master_mask)
{
cman_node_t nodes[MAX_NODES_DISK];
int retnodes, x;
+ static unsigned int check_cycle = 0;
if (cman_get_nodes(ctx->qc_cman_admin, MAX_NODES_DISK,
&retnodes, nodes) <0 )
@@ -639,6 +640,18 @@ check_cman(qd_ctx *ctx, memb_mask_t mask, memb_mask_t master_mask)
memset(master_mask, 0, sizeof(memb_mask_t));
for (x = 0; x < retnodes; x++) {
+ /* See if the other node is running cman and not qdiskd.
+ Just to this every 4 times (seconds) so we don't spam syslog
+ too much. cman_is_listening() can return EBUSY which means
+ "I don't know". We don't worry about this, and just report
+ at the next check by which time it will.
+ */
+ check_cycle = (check_cycle + 1) % 4;
+ if ((check_cycle == 1) &&
+ (cman_is_listening(ctx->qc_cman_admin, nodes[x].cn_nodeid,
+ CLUSTER_PORT_QDISKD) == 0)) {
+ logt_print(LOG_NOTICE, "node %s is up but not running qdiskd", nodes[x].cn_name);
+ }
if (is_bit_set(mask, nodes[x].cn_nodeid-1, sizeof(memb_mask_t)) &&
nodes[x].cn_member) {
set_bit(master_mask, nodes[x].cn_nodeid-1,
10 years, 8 months
gfs2-utils: RHEL7 - gfs2_grow: Don't try to open an empty string
by Andrew Price
Gitweb: http://git.fedorahosted.org/git/?p=gfs2-utils.git;a=commitdiff;h=43da4b0b...
Commit: 43da4b0b6a55cfad8f78a703fb3359cac0c4968a
Parent: 83f0041621aa8abf112ae5c89d0f129cf00d8905
Author: Andrew Price <anprice(a)redhat.com>
AuthorDate: Thu Aug 8 17:50:47 2013 +0100
Committer: Andrew Price <anprice(a)redhat.com>
CommitterDate: Tue Aug 13 10:24:53 2013 +0100
gfs2_grow: Don't try to open an empty string
sdp->device_name wasn't getting set in gfs2_grow so is_gfs2() (called
via check_for_gfs2()) fails to open "" and so we get an ENOENT.
This fixes the open("") by setting sdp->device_name before passing it to
is_pathname_mounted(), which has been updated to make it more clear
which args will be modified by it.
is_gfs2() and check_for_gfs2() have also been removed from libgfs2 as
these were the only places they were being called and they aren't
needed: superblock checking is done further along via other functions
calling check_sb().
Resolves: rhbz#991204
Signed-off-by: Andrew Price <anprice(a)redhat.com>
---
gfs2/fsck/initialize.c | 2 +-
gfs2/libgfs2/libgfs2.h | 4 +---
gfs2/libgfs2/misc.c | 42 ++++++------------------------------------
gfs2/mkfs/main_grow.c | 10 +++++++---
gfs2/mkfs/main_jadd.c | 3 ++-
5 files changed, 17 insertions(+), 44 deletions(-)
diff --git a/gfs2/fsck/initialize.c b/gfs2/fsck/initialize.c
index b45ae08..6612fe7 100644
--- a/gfs2/fsck/initialize.c
+++ b/gfs2/fsck/initialize.c
@@ -1491,7 +1491,7 @@ int initialize(struct gfs2_sbd *sdp, int force_check, int preen,
strncpy(sdp->device_name, opts.device,
sizeof(sdp->device_name));
sdp->path_name = sdp->device_name; /* This gets overwritten */
- is_mounted = is_pathname_mounted(sdp, &ro);
+ is_mounted = is_pathname_mounted(sdp->path_name, sdp->device_name, &ro);
/* If the device is busy, but not because it's mounted, fail.
This protects against cases where the file system is LVM
and perhaps mounted on a different node. */
diff --git a/gfs2/libgfs2/libgfs2.h b/gfs2/libgfs2/libgfs2.h
index fe7129a..e994d3b 100644
--- a/gfs2/libgfs2/libgfs2.h
+++ b/gfs2/libgfs2/libgfs2.h
@@ -716,11 +716,9 @@ extern void decrease_verbosity(void);
extern int compute_heightsize(struct gfs2_sbd *sdp, uint64_t *heightsize,
uint32_t *maxheight, uint32_t bsize1, int diptrs, int inptrs);
extern int compute_constants(struct gfs2_sbd *sdp);
-extern int is_pathname_mounted(struct gfs2_sbd *sdp, int *ro_mount);
-extern int is_gfs2(struct gfs2_sbd *sdp);
+extern int is_pathname_mounted(char *path_name, char *device_name, int *ro_mount);
extern int find_gfs2_meta(struct gfs2_sbd *sdp);
extern int dir_exists(const char *dir);
-extern int check_for_gfs2(struct gfs2_sbd *sdp);
extern int mount_gfs2_meta(struct gfs2_sbd *sdp);
extern void cleanup_metafs(struct gfs2_sbd *sdp);
extern int set_sysfs(const char *fsname, const char *filename, const char *val);
diff --git a/gfs2/libgfs2/misc.c b/gfs2/libgfs2/misc.c
index c05a770..6f2dbdb 100644
--- a/gfs2/libgfs2/misc.c
+++ b/gfs2/libgfs2/misc.c
@@ -99,7 +99,7 @@ int compute_constants(struct gfs2_sbd *sdp)
return 0;
}
-int is_pathname_mounted(struct gfs2_sbd *sdp, int *ro_mount)
+int is_pathname_mounted(char *path_name, char *device_name, int *ro_mount)
{
FILE *fp;
struct mntent *mnt;
@@ -112,7 +112,7 @@ int is_pathname_mounted(struct gfs2_sbd *sdp, int *ro_mount)
perror("open: /proc/mounts");
return 0;
}
- if (stat(sdp->path_name, &st_buf) == 0) {
+ if (stat(path_name, &st_buf) == 0) {
if (S_ISBLK(st_buf.st_mode)) {
#ifndef __GNU__ /* The GNU hurd is broken with respect to stat devices */
file_rdev = st_buf.st_rdev;
@@ -124,12 +124,12 @@ int is_pathname_mounted(struct gfs2_sbd *sdp, int *ro_mount)
}
while ((mnt = getmntent (fp)) != NULL) {
/* Check if they specified the device instead of mnt point */
- if (strcmp(sdp->device_name, mnt->mnt_fsname) == 0) {
- strcpy(sdp->path_name, mnt->mnt_dir); /* fix it */
+ if (strcmp(device_name, mnt->mnt_fsname) == 0) {
+ strcpy(path_name, mnt->mnt_dir); /* fix it */
break;
}
- if (strcmp(sdp->path_name, mnt->mnt_dir) == 0) {
- strcpy(sdp->device_name, mnt->mnt_fsname); /* fix it */
+ if (strcmp(path_name, mnt->mnt_dir) == 0) {
+ strcpy(device_name, mnt->mnt_fsname); /* fix it */
break;
}
if (stat(mnt->mnt_fsname, &st_buf) == 0) {
@@ -160,36 +160,6 @@ int is_pathname_mounted(struct gfs2_sbd *sdp, int *ro_mount)
return 1; /* mounted */
}
-int is_gfs2(struct gfs2_sbd *sdp)
-{
- int fd, rc;
- struct gfs2_sb sb;
-
- fd = open(sdp->device_name, O_RDWR);
- if (fd < 0)
- return 0;
-
- rc = 0;
- if (lseek(fd, GFS2_SB_ADDR * GFS2_BASIC_BLOCK, SEEK_SET) >= 0 &&
- read(fd, &sb, sizeof(sb)) == sizeof(sb) &&
- be32_to_cpu(sb.sb_header.mh_magic) == GFS2_MAGIC &&
- be32_to_cpu(sb.sb_header.mh_type) == GFS2_METATYPE_SB)
- rc = 1;
- close(fd);
- return rc;
-}
-
-int check_for_gfs2(struct gfs2_sbd *sdp)
-{
- int ro;
-
- if (!is_pathname_mounted(sdp, &ro))
- return -1;
- if (!is_gfs2(sdp))
- return -1;
- return 0;
-}
-
static int lock_for_admin(struct gfs2_sbd *sdp)
{
int error;
diff --git a/gfs2/mkfs/main_grow.c b/gfs2/mkfs/main_grow.c
index 73c7f84..d324af9 100644
--- a/gfs2/mkfs/main_grow.c
+++ b/gfs2/mkfs/main_grow.c
@@ -323,6 +323,7 @@ main_grow(int argc, char *argv[])
int rgcount, rindex_fd;
char rindex_name[PATH_MAX];
int error = EXIT_SUCCESS;
+ int ro_mnt = 0;
memset(sdp, 0, sizeof(struct gfs2_sbd));
sdp->bsize = GFS2_DEFAULT_BSIZE;
@@ -336,17 +337,20 @@ main_grow(int argc, char *argv[])
int sane;
struct rgrp_tree *last_rgrp;
+ strncpy(sdp->device_name, argv[optind], PATH_MAX - 1);
sdp->path_name = argv[optind++];
- sdp->path_fd = open(sdp->path_name, O_RDONLY | O_CLOEXEC);
- if (sdp->path_fd < 0){
+
+ if ((!is_pathname_mounted(sdp->path_name, sdp->device_name, &ro_mnt))) {
perror(sdp->path_name);
exit(EXIT_FAILURE);
}
- if (check_for_gfs2(sdp)) {
+ sdp->path_fd = open(sdp->path_name, O_RDONLY | O_CLOEXEC);
+ if (sdp->path_fd < 0){
perror(sdp->path_name);
exit(EXIT_FAILURE);
}
+
sdp->device_fd = open(sdp->device_name,
(test ? O_RDONLY : O_RDWR) | O_CLOEXEC);
if (sdp->device_fd < 0){
diff --git a/gfs2/mkfs/main_jadd.c b/gfs2/mkfs/main_jadd.c
index 58fb046..2646829 100644
--- a/gfs2/mkfs/main_jadd.c
+++ b/gfs2/mkfs/main_jadd.c
@@ -491,6 +491,7 @@ void main_jadd(int argc, char *argv[])
{
struct gfs2_sbd sbd, *sdp = &sbd;
unsigned int total;
+ int ro_mnt = 0;
memset(sdp, 0, sizeof(struct gfs2_sbd));
sdp->jsize = GFS2_DEFAULT_JSIZE;
@@ -506,7 +507,7 @@ void main_jadd(int argc, char *argv[])
exit(EXIT_FAILURE);
}
- if (check_for_gfs2(sdp)) {
+ if (!is_pathname_mounted(sdp->path_name, sdp->device_name, &ro_mnt)) {
perror(sdp->path_name);
exit(EXIT_FAILURE);
}
10 years, 9 months
gfs2-utils: master - gfs2_grow: Don't try to open an empty string
by Andrew Price
Gitweb: http://git.fedorahosted.org/git/?p=gfs2-utils.git;a=commitdiff;h=23bcbc35...
Commit: 23bcbc3512a6609216b6884a3bf088684d1e7c72
Parent: 8deeb914420558e90a6ec27e97af7980f6a973ae
Author: Andrew Price <anprice(a)redhat.com>
AuthorDate: Thu Aug 8 17:50:47 2013 +0100
Committer: Andrew Price <anprice(a)redhat.com>
CommitterDate: Thu Aug 8 17:59:14 2013 +0100
gfs2_grow: Don't try to open an empty string
sdp->device_name wasn't getting set in gfs2_grow so is_gfs2() (called
via check_for_gfs2()) fails to open "" and so we get an ENOENT.
This fixes the open("") by setting sdp->device_name before passing it to
is_pathname_mounted(), which has been updated to make it more clear
which args will be modified by it.
is_gfs2() and check_for_gfs2() have also been removed from libgfs2 as
these were the only places they were being called and they aren't
needed: superblock checking is done further along via other functions
calling check_sb().
Signed-off-by: Andrew Price <anprice(a)redhat.com>
---
gfs2/fsck/initialize.c | 2 +-
gfs2/libgfs2/libgfs2.h | 4 +---
gfs2/libgfs2/misc.c | 42 ++++++------------------------------------
gfs2/mkfs/main_grow.c | 10 +++++++---
gfs2/mkfs/main_jadd.c | 3 ++-
5 files changed, 17 insertions(+), 44 deletions(-)
diff --git a/gfs2/fsck/initialize.c b/gfs2/fsck/initialize.c
index b45ae08..6612fe7 100644
--- a/gfs2/fsck/initialize.c
+++ b/gfs2/fsck/initialize.c
@@ -1491,7 +1491,7 @@ int initialize(struct gfs2_sbd *sdp, int force_check, int preen,
strncpy(sdp->device_name, opts.device,
sizeof(sdp->device_name));
sdp->path_name = sdp->device_name; /* This gets overwritten */
- is_mounted = is_pathname_mounted(sdp, &ro);
+ is_mounted = is_pathname_mounted(sdp->path_name, sdp->device_name, &ro);
/* If the device is busy, but not because it's mounted, fail.
This protects against cases where the file system is LVM
and perhaps mounted on a different node. */
diff --git a/gfs2/libgfs2/libgfs2.h b/gfs2/libgfs2/libgfs2.h
index fe7129a..e994d3b 100644
--- a/gfs2/libgfs2/libgfs2.h
+++ b/gfs2/libgfs2/libgfs2.h
@@ -716,11 +716,9 @@ extern void decrease_verbosity(void);
extern int compute_heightsize(struct gfs2_sbd *sdp, uint64_t *heightsize,
uint32_t *maxheight, uint32_t bsize1, int diptrs, int inptrs);
extern int compute_constants(struct gfs2_sbd *sdp);
-extern int is_pathname_mounted(struct gfs2_sbd *sdp, int *ro_mount);
-extern int is_gfs2(struct gfs2_sbd *sdp);
+extern int is_pathname_mounted(char *path_name, char *device_name, int *ro_mount);
extern int find_gfs2_meta(struct gfs2_sbd *sdp);
extern int dir_exists(const char *dir);
-extern int check_for_gfs2(struct gfs2_sbd *sdp);
extern int mount_gfs2_meta(struct gfs2_sbd *sdp);
extern void cleanup_metafs(struct gfs2_sbd *sdp);
extern int set_sysfs(const char *fsname, const char *filename, const char *val);
diff --git a/gfs2/libgfs2/misc.c b/gfs2/libgfs2/misc.c
index c05a770..6f2dbdb 100644
--- a/gfs2/libgfs2/misc.c
+++ b/gfs2/libgfs2/misc.c
@@ -99,7 +99,7 @@ int compute_constants(struct gfs2_sbd *sdp)
return 0;
}
-int is_pathname_mounted(struct gfs2_sbd *sdp, int *ro_mount)
+int is_pathname_mounted(char *path_name, char *device_name, int *ro_mount)
{
FILE *fp;
struct mntent *mnt;
@@ -112,7 +112,7 @@ int is_pathname_mounted(struct gfs2_sbd *sdp, int *ro_mount)
perror("open: /proc/mounts");
return 0;
}
- if (stat(sdp->path_name, &st_buf) == 0) {
+ if (stat(path_name, &st_buf) == 0) {
if (S_ISBLK(st_buf.st_mode)) {
#ifndef __GNU__ /* The GNU hurd is broken with respect to stat devices */
file_rdev = st_buf.st_rdev;
@@ -124,12 +124,12 @@ int is_pathname_mounted(struct gfs2_sbd *sdp, int *ro_mount)
}
while ((mnt = getmntent (fp)) != NULL) {
/* Check if they specified the device instead of mnt point */
- if (strcmp(sdp->device_name, mnt->mnt_fsname) == 0) {
- strcpy(sdp->path_name, mnt->mnt_dir); /* fix it */
+ if (strcmp(device_name, mnt->mnt_fsname) == 0) {
+ strcpy(path_name, mnt->mnt_dir); /* fix it */
break;
}
- if (strcmp(sdp->path_name, mnt->mnt_dir) == 0) {
- strcpy(sdp->device_name, mnt->mnt_fsname); /* fix it */
+ if (strcmp(path_name, mnt->mnt_dir) == 0) {
+ strcpy(device_name, mnt->mnt_fsname); /* fix it */
break;
}
if (stat(mnt->mnt_fsname, &st_buf) == 0) {
@@ -160,36 +160,6 @@ int is_pathname_mounted(struct gfs2_sbd *sdp, int *ro_mount)
return 1; /* mounted */
}
-int is_gfs2(struct gfs2_sbd *sdp)
-{
- int fd, rc;
- struct gfs2_sb sb;
-
- fd = open(sdp->device_name, O_RDWR);
- if (fd < 0)
- return 0;
-
- rc = 0;
- if (lseek(fd, GFS2_SB_ADDR * GFS2_BASIC_BLOCK, SEEK_SET) >= 0 &&
- read(fd, &sb, sizeof(sb)) == sizeof(sb) &&
- be32_to_cpu(sb.sb_header.mh_magic) == GFS2_MAGIC &&
- be32_to_cpu(sb.sb_header.mh_type) == GFS2_METATYPE_SB)
- rc = 1;
- close(fd);
- return rc;
-}
-
-int check_for_gfs2(struct gfs2_sbd *sdp)
-{
- int ro;
-
- if (!is_pathname_mounted(sdp, &ro))
- return -1;
- if (!is_gfs2(sdp))
- return -1;
- return 0;
-}
-
static int lock_for_admin(struct gfs2_sbd *sdp)
{
int error;
diff --git a/gfs2/mkfs/main_grow.c b/gfs2/mkfs/main_grow.c
index 73c7f84..d324af9 100644
--- a/gfs2/mkfs/main_grow.c
+++ b/gfs2/mkfs/main_grow.c
@@ -323,6 +323,7 @@ main_grow(int argc, char *argv[])
int rgcount, rindex_fd;
char rindex_name[PATH_MAX];
int error = EXIT_SUCCESS;
+ int ro_mnt = 0;
memset(sdp, 0, sizeof(struct gfs2_sbd));
sdp->bsize = GFS2_DEFAULT_BSIZE;
@@ -336,17 +337,20 @@ main_grow(int argc, char *argv[])
int sane;
struct rgrp_tree *last_rgrp;
+ strncpy(sdp->device_name, argv[optind], PATH_MAX - 1);
sdp->path_name = argv[optind++];
- sdp->path_fd = open(sdp->path_name, O_RDONLY | O_CLOEXEC);
- if (sdp->path_fd < 0){
+
+ if ((!is_pathname_mounted(sdp->path_name, sdp->device_name, &ro_mnt))) {
perror(sdp->path_name);
exit(EXIT_FAILURE);
}
- if (check_for_gfs2(sdp)) {
+ sdp->path_fd = open(sdp->path_name, O_RDONLY | O_CLOEXEC);
+ if (sdp->path_fd < 0){
perror(sdp->path_name);
exit(EXIT_FAILURE);
}
+
sdp->device_fd = open(sdp->device_name,
(test ? O_RDONLY : O_RDWR) | O_CLOEXEC);
if (sdp->device_fd < 0){
diff --git a/gfs2/mkfs/main_jadd.c b/gfs2/mkfs/main_jadd.c
index 58fb046..2646829 100644
--- a/gfs2/mkfs/main_jadd.c
+++ b/gfs2/mkfs/main_jadd.c
@@ -491,6 +491,7 @@ void main_jadd(int argc, char *argv[])
{
struct gfs2_sbd sbd, *sdp = &sbd;
unsigned int total;
+ int ro_mnt = 0;
memset(sdp, 0, sizeof(struct gfs2_sbd));
sdp->jsize = GFS2_DEFAULT_JSIZE;
@@ -506,7 +507,7 @@ void main_jadd(int argc, char *argv[])
exit(EXIT_FAILURE);
}
- if (check_for_gfs2(sdp)) {
+ if (!is_pathname_mounted(sdp->path_name, sdp->device_name, &ro_mnt)) {
perror(sdp->path_name);
exit(EXIT_FAILURE);
}
10 years, 9 months
fence-agents: RHEL6 - fence_apc: Improve detection of EOL during login
by Marek Grác
Gitweb: http://git.fedorahosted.org/git/?p=fence-agents.git;a=commitdiff;h=e91f58...
Commit: e91f58c8a4a69f0a13b0fd388f90458ec91c68df
Parent: 56804537d2153c22e7ee9a7fede3c20e4e19d20a
Author: Marek 'marx' Grac <mgrac(a)redhat.com>
AuthorDate: Mon Aug 12 16:32:29 2013 +0200
Committer: Marek 'marx' Grac <mgrac(a)redhat.com>
CommitterDate: Mon Aug 12 16:32:29 2013 +0200
fence_apc: Improve detection of EOL during login
Resolves: rhbz#886614
---
fence/agents/lib/fencing.py.py | 18 ++++++++++++++++--
1 files changed, 16 insertions(+), 2 deletions(-)
diff --git a/fence/agents/lib/fencing.py.py b/fence/agents/lib/fencing.py.py
index ad5f4db..0316b58 100644
--- a/fence/agents/lib/fencing.py.py
+++ b/fence/agents/lib/fencing.py.py
@@ -879,7 +879,8 @@ def fence_login(options):
time.sleep(int(options["-f"]))
try:
- re_login = re.compile("(login\s*: )|(Login Name: )|(username: )|(User Name :)", re.IGNORECASE)
+ re_login_string = "(login\s*: )|(Login Name: )|(username: )|(User Name :)"
+ re_login = re.compile(re_login_string, re.IGNORECASE)
re_pass = re.compile("(password)|(pass phrase)", re.IGNORECASE)
if options.has_key("-z"):
@@ -966,7 +967,20 @@ def fence_login(options):
try:
conn.send_eol(options["-p"])
- conn.log_expect(options, options["-c"], int(options["-Y"]))
+
+ if type(options["-c"]) is not list:
+ options["-c"] = [ options["-c"] ]
+
+ valid_password = conn.log_expect(options, [ re_login_string ] + options["-c"], int(options["-Y"]))
+ if valid_password == 0:
+ ## password is invalid or we have to change EOL separator
+ options["eol"] = "\r"
+ conn.send_eol("")
+ conn.send_eol("")
+ conn.send_eol(options["-l"])
+ conn.log_expect(options, re_pass, int(options["-y"]))
+ conn.send_eol(options["-p"])
+ conn.log_expect(options, options["-c"], int(options["-y"]))
except KeyError:
fail(EC_PASSWORD_MISSING)
except pexpect.EOF:
10 years, 9 months