This is the mail archive of the
cluster-cvs@sourceware.org
mailing list for the cluster.
STABLE2 - libgfs2: randomize creation of temporary directories formetafs mount
- From: "Fabio M. Di Nitto" <fabbione at fedoraproject dot org>
- To: cluster-cvs-relay at redhat dot com
- Date: Thu, 30 Oct 2008 11:28:37 +0000 (UTC)
- Subject: STABLE2 - libgfs2: randomize creation of temporary directories formetafs mount
Gitweb: http://git.fedorahosted.org/git/cluster.git?p=cluster.git;a=commitdiff;h=1be9adf2881ad22c264f6fda4fff7bb3c13e87f4
Commit: 1be9adf2881ad22c264f6fda4fff7bb3c13e87f4
Parent: 51bfd01ade6b21c0e78354c9ad1eca541e81b6ad
Author: Fabio M. Di Nitto <fdinitto@redhat.com>
AuthorDate: Wed Oct 22 11:30:06 2008 +0200
Committer: Fabio M. Di Nitto <fdinitto@redhat.com>
CommitterDate: Thu Oct 30 10:35:35 2008 +0100
libgfs2: randomize creation of temporary directories for metafs mount
by using a static path to /tmp, the operation can fail in different
ways.
randomize the path a bit by using the invoking pid. This will also allow
multiple simultaneous invokation of mount_gfs2_meta on different
mountpoints.
Similar to 18b24ae55c3e4abdc256a3b6c4f15ae0116a0f14 there is a small
race condition in this implentation.
Implementation:
- Fix return info from find_gfs2_meta to set TRUE when we find a
mountpoint in gfs2_sbd struct.
- Add metafs_created_mount to gfs2_sbd struct to propagate info if we
did create the mount point or not.
- Randomize sdp->metafs_path with pid info.
- Remove the metafs_path mount point if we did create it.
Signed-off-by: Fabio M. Di Nitto <fdinitto@redhat.com>
---
gfs2/libgfs2/libgfs2.h | 1 +
gfs2/libgfs2/misc.c | 17 ++++++++++++-----
2 files changed, 13 insertions(+), 5 deletions(-)
diff --git a/gfs2/libgfs2/libgfs2.h b/gfs2/libgfs2/libgfs2.h
index 6197b4a..acca5e7 100644
--- a/gfs2/libgfs2/libgfs2.h
+++ b/gfs2/libgfs2/libgfs2.h
@@ -232,6 +232,7 @@ struct gfs2_sbd {
unsigned int writes;
int metafs_fd;
int metafs_mounted; /* If metafs was already mounted */
+ int metafs_created_mount; /* TRUE if we created the mount point got metafs */
char metafs_path[PATH_MAX]; /* where metafs is mounted */
struct special_blocks bad_blocks;
struct special_blocks dup_blocks;
diff --git a/gfs2/libgfs2/misc.c b/gfs2/libgfs2/misc.c
index 4a6665c..7c414b1 100644
--- a/gfs2/libgfs2/misc.c
+++ b/gfs2/libgfs2/misc.c
@@ -125,11 +125,11 @@ find_gfs2_meta(struct gfs2_sbd *sdp)
meta_path, fstype,mfsoptions, &fsdump,
&fspass) != 6)
continue;
-
+
if (strcmp(meta_device, sdp->device_name) == 0 ||
strcmp(meta_device, sdp->path_name) == 0) {
fclose(fp);
- sdp->metafs_mounted = FALSE;
+ sdp->metafs_mounted = TRUE;
strcpy(sdp->metafs_path, meta_path);
return TRUE;
}
@@ -216,15 +216,20 @@ void
mount_gfs2_meta(struct gfs2_sbd *sdp)
{
int ret;
+
+ memset(sdp->metafs_path, 0, PATH_MAX);
+ snprintf(sdp->metafs_path, PATH_MAX - 1, "/tmp/.gfs2meta.%d", getpid());
+
/* mount the meta fs */
- strcpy(sdp->metafs_path, "/tmp/.gfs2meta");
if (!dir_exists(sdp->metafs_path)) {
ret = mkdir(sdp->metafs_path, 0700);
if (ret)
die("Couldn't create %s : %s\n", sdp->metafs_path,
strerror(errno));
- }
-
+ sdp->metafs_created_mount = TRUE;
+ } else
+ sdp->metafs_created_mount = FALSE;
+
ret = mount(sdp->path_name, sdp->metafs_path, "gfs2meta", 0, NULL);
if (ret)
die("Couldn't mount %s : %s\n", sdp->metafs_path,
@@ -266,6 +271,8 @@ cleanup_metafs(struct gfs2_sbd *sdp)
if (ret)
fprintf(stderr, "Couldn't unmount %s : %s\n",
sdp->metafs_path, strerror(errno));
+ if(sdp->metafs_created_mount) /* we created the directory */
+ rmdir(sdp->metafs_path);
}
}