Skip to contentSkip to conversation

cluster/gfs2 libgfs2/misc.c tool/Makefile tool ...

Cluster-devel [email protected] 1 participant 1 message Oct 25, 2007

lore
Share & tools
lore
#0 lore raw

CVSROOT: /cvs/cluster
Module name: cluster
Branch: RHEL5
Changes by: rpeterso at sourceware.org 2007-10-25 14:14:47

Modified files:
gfs2/libgfs2 : misc.c
gfs2/tool : Makefile counters.c df.c gfs2_tool.h layout.c
misc.c tune.c util.c

Log message:
Resolves: bz 345501: GFS2: gfs2 utils uses non-canonicalized names

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/gfs2/libgfs2/misc.c.diff?cvsroot=cluster&only_with_tag=RHEL5&r1=1.2.2.2&r2=1.2.2.3
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/gfs2/tool/Makefile.diff?cvsroot=cluster&only_with_tag=RHEL5&r1=1.5&r2=1.5.2.1
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/gfs2/tool/counters.c.diff?cvsroot=cluster&only_with_tag=RHEL5&r1=1.3&r2=1.3.2.1
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/gfs2/tool/df.c.diff?cvsroot=cluster&only_with_tag=RHEL5&r1=1.7&r2=1.7.2.1
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/gfs2/tool/gfs2_tool.h.diff?cvsroot=cluster&only_with_tag=RHEL5&r1=1.5.2.1&r2=1.5.2.2
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/gfs2/tool/layout.c.diff?cvsroot=cluster&only_with_tag=RHEL5&r1=1.3&r2=1.3.2.1
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/gfs2/tool/misc.c.diff?cvsroot=cluster&only_with_tag=RHEL5&r1=1.8&r2=1.8.2.1
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/gfs2/tool/tune.c.diff?cvsroot=cluster&only_with_tag=RHEL5&r1=1.3&r2=1.3.2.1
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/gfs2/tool/util.c.diff?cvsroot=cluster&only_with_tag=RHEL5&r1=1.5&r2=1.5.2.1

gfs2/libgfs2/misc.c +11 -7
@@ -170,16 +170,18 @@
 check_for_gfs2(struct gfs2_sbd *sdp)
 {
 	FILE *fp = fopen("/proc/mounts", "r");
-	char *name = sdp->path_name;
 	char buffer[PATH_MAX];
 	char fstype[80];
 	int fsdump, fspass, ret;
 	char fspath[PATH_MAX];
 	char fsoptions[PATH_MAX];
+	char *realname;
 
-	if (name[strlen(name) - 1] == '/')
-		name[strlen(name) - 1] = '\0';
-
+	realname = realpath(sdp->path_name, NULL);
+	if (!realname) {
+		perror(sdp->path_name);
+		return;
+	}
 	if (fp == NULL) {
 		perror("open: /proc/mounts");
 		exit(EXIT_FAILURE);
@@ -199,19 +201,21 @@
 			continue;
 
 		/* Check if they specified the device instead of mnt point */
-		if (strcmp(sdp->device_name, name) == 0)
+		if (strcmp(sdp->device_name, realname) == 0)
 			strcpy(sdp->path_name, fspath); /* fix it */
-		else if (strcmp(fspath, name) != 0)
+		else if (strcmp(fspath, realname) != 0)
 			continue;
 
 		fclose(fp);
 		if (strncmp(sdp->device_name, "/dev/loop", 9) == 0)
 			die("Cannot perform this operation on a loopback GFS2 mount.\n");
 
+		free(realname);
 		return;
 	}
+	free(realname);
 	fclose(fp);
-	die("gfs2 Filesystem %s is not mounted.\n", name);
+	die("gfs2 Filesystem %s is not mounted.\n", sdp->path_name);
 }
 
 void 
gfs2/tool/Makefile +1 -1
@@ -14,7 +14,7 @@
 
 include ${top_srcdir}/make/defines.mk
 
-INCLUDE= -I${top_srcdir}/include -I${top_srcdir}/config -I${gfs2kincdir}
+INCLUDE= -I${top_srcdir}/include -I${top_srcdir}/config -I${gfs2kincdir} -I../libgfs2/
 
 ifneq (${KERNEL_SRC}, )
 # Use the kernel tree if patched, otherwise, look where cluster headers
gfs2/tool/counters.c +6 -12
@@ -28,6 +28,7 @@
 #include "osi_list.h"
 
 #include "gfs2_tool.h"
+#include "libgfs2.h"
 
 #define SIZE (65536)
 
@@ -132,24 +133,19 @@
 print_counters(int argc, char **argv)
 {
 	unsigned int i = interval;
-	char *path, *fs;
-	int fd;
+	char *fs;
+	struct gfs2_sbd sbd;
 
 	interval = 1;
 
 	if (optind < argc)
-		path = argv[optind++];
+		sbd.path_name = argv[optind++];
 	else
 		die("Usage: gfs2_tool counters <mountpoint>\n");
 
-	fd = open(path, O_RDONLY);
-	if (fd < 0)
-		die("can't open file %s: %s\n", path, strerror(errno));
+	check_for_gfs2(&sbd);
 
-	check_for_gfs2(fd, path);
-	close(fd);
-
-	fs = mp2fsname(path);
+	fs = mp2fsname(sbd.path_name);
 
 	for (;;) {
 		print_line(fs, "glock_count", "locks", 0);
@@ -204,6 +200,4 @@
 			first = FALSE;
 		}
 	}
-
-	close(fd);
 }
gfs2/tool/df.c +10 -9
@@ -29,6 +29,7 @@
 #include <linux/gfs2_ondisk.h>
 
 #include "gfs2_tool.h"
+#include "libgfs2.h"
 
 #define SIZE (65536)
 
@@ -42,7 +43,6 @@
 static void
 do_df_one(char *path)
 {
-	int fd;
 	struct gfs2_ioctl gi;
 	/* char stat_gfs2[SIZE]; */
 	/* unsigned int percentage; */
@@ -53,14 +53,15 @@
 	unsigned int flags;
 	char *fs, *value;
  	int error;
+	struct gfs2_sbd sbd;
 
+	sbd.path_name = path;
+	check_for_gfs2(&sbd);
 
-	fd = open(path, O_RDONLY);
-	if (fd < 0)
+	sbd.device_fd = open(path, O_RDONLY);
+	if (sbd.device_fd < 0)
 		die("can't open %s: %s\n", path, strerror(errno));
 
-	check_for_gfs2(fd, path);
-
 	fs = mp2fsname(path);
 
 	/*
@@ -76,7 +77,7 @@
 		gi.gi_data = (char *)&sb;
 		gi.gi_size = sizeof(struct gfs2_sb);
 
-		error = ioctl(fd, GFS2_IOCTL_SUPER, &gi);
+		error = ioctl(sbd.device_fd, GFS2_IOCTL_SUPER, &gi);
 		if (error != gi.gi_size)
 			die("error doing get_super (%d): %s\n",
 			    error, strerror(errno));
@@ -90,7 +91,7 @@
 		gi.gi_data = (char *)&ji;
 		gi.gi_size = sizeof(struct gfs2_dinode);
 
-		error = ioctl(fd, GFS2_IOCTL_SUPER, &gi);
+		error = ioctl(sbd.device_fd, GFS2_IOCTL_SUPER, &gi);
 		if (error != gi.gi_size)
 			die("error doing get_hfile_stat for jindex (%d): %s\n",
 			    error, strerror(errno));
@@ -104,13 +105,13 @@
 		gi.gi_data = (char *)&ri;
 		gi.gi_size = sizeof(struct gfs2_dinode);
 
-		error = ioctl(fd, GFS2_IOCTL_SUPER, &gi);
+		error = ioctl(sbd.device_fd, GFS2_IOCTL_SUPER, &gi);
 		if (error != gi.gi_size)
 			die("error doing get_hfile_stat for rindex (%d): %s\n",
 			    error, strerror(errno));
 	}
 
-	close(fd);
+	close(sbd.device_fd);
 
 	journals = ji.di_entries - 2;
 
gfs2/tool/gfs2_tool.h +0 -1
@@ -92,7 +92,6 @@
 
 /* From util.c */
 
-void check_for_gfs2(int fd, char *path);
 char *get_list(void);
 char **str2lines(char *str);
 const char *find_debugfs_mount(void);
gfs2/tool/layout.c +10 -10
@@ -32,6 +32,7 @@
 #include "linux_endian.h"
 
 #include "gfs2_tool.h"
+#include "libgfs2.h"
 
 #define LAYOUT_DATA_QUANTUM (4194304)
 
@@ -765,11 +766,10 @@
 print_layout(int argc, char **argv)
 {
 	world_t w;
-	char *path;
-	int fd;
 	int retry = TRUE;
 	struct gfs2_ioctl gi;
 	int error;
+	struct gfs2_sbd sbd;
 
 	memset(&w, 0, sizeof(world_t));
 	w.buf_size = LAYOUT_DATA_QUANTUM;
@@ -779,17 +779,17 @@
 	if (optind == argc)
 		die("Usage: gfs2_tool layout <filename> [buffersize]\n");
 
-	path = argv[optind++];
+	sbd.path_name = argv[optind++];
 	if (optind < argc ) {
 		w.buf_size = atoi(argv[3]);
 		retry = FALSE;
 	}
 
-	fd = open(path, O_RDONLY);
-	if (fd < 0)
-		die("can't open %s: %s\n", path, strerror(errno));
+	sbd.device_fd = open(sbd.path_name, O_RDONLY);
+	if (sbd.device_fd < 0)
+		die("can't open %s: %s\n", sbd.path_name, strerror(errno));
 
-	check_for_gfs2(fd, path);
+	check_for_gfs2(&sbd);
 
 	{
 		char *argv[] = { "get_super" };
@@ -799,7 +799,7 @@
 		gi.gi_data = (char *)&w.sb;
 		gi.gi_size = sizeof(struct gfs2_sb);
 
-		error = ioctl(fd, GFS2_IOCTL_SUPER, &gi);
+		error = ioctl(sbd.device_fd, GFS2_IOCTL_SUPER, &gi);
 		if (error != gi.gi_size)
 			die("error doing get_super (%d): %s\n",
 			    error, strerror(errno));
@@ -825,7 +825,7 @@
 		gi.gi_data = w.buf_data;
 		gi.gi_size = w.buf_size;
 
-		w.buf_count = ioctl(fd, GFS2_IOCTL_SUPER, &gi);
+		w.buf_count = ioctl(sbd.device_fd, GFS2_IOCTL_SUPER, &gi);
 		if (w.buf_count >= 0)
 			break;
 
@@ -855,7 +855,7 @@
 
 	check_for_untouched_buffers(&w);
 
-	close(fd);
+	close(sbd.device_fd);
 }
 #endif /* #if GFS2_TOOL_FEATURE_IMPLEMENTED */
 
gfs2/tool/misc.c +51 -53

309 lines not on this page · raw message

gfs2/tool/tune.c +9 -19
@@ -29,6 +29,7 @@
 #define __user
 
 #include "gfs2_tool.h"
+#include "libgfs2.h"
 
 #define SIZE (65536)
 
@@ -42,24 +43,19 @@
 void
 get_tune(int argc, char **argv)
 {
-	int fd;
 	char path[PATH_MAX];
 	char *fs;
 	DIR *d;
 	struct dirent *de;
 	double ratio;
 	unsigned int num, den;
+	struct gfs2_sbd sbd;
 
 	if (optind == argc)
 		die("Usage: gfs2_tool gettune <mountpoint>\n");
 
-	fd = open(argv[optind], O_RDONLY);
-	if (fd < 0)
-		die("can't open file %s: %s\n",
-		    argv[optind], strerror(errno));
-
-	check_for_gfs2(fd, argv[optind]);
-	close(fd);
+	sbd.path_name = argv[optind];
+	check_for_gfs2(&sbd);
 	fs = mp2fsname(argv[optind]);
 	memset(path, 0, PATH_MAX);
 	snprintf(path, PATH_MAX - 1, "%s/%s/tune", SYS_BASE, fs);
@@ -94,15 +90,15 @@
 void
 set_tune(int argc, char **argv)
 {
-	char *mp, *param, *value;
-	int fd;
+	char *param, *value;
 	char tune_base[SIZE] = "tune/";
 	char buf[256];
 	char *fs;
+	struct gfs2_sbd sbd;
 
 	if (optind == argc)
 		die("Usage: gfs2_tool settune <mountpoint> <parameter> <value>\n");
-	mp = argv[optind++];
+	sbd.path_name = argv[optind++];
 	if (optind == argc)
 		die("Usage: gfs2_tool settune <mountpoint> <parameter> <value>\n");
 	param = argv[optind++];
@@ -110,14 +106,8 @@
 		die("Usage: gfs2_tool settune <mountpoint> <parameter> <value>\n");
 	value = argv[optind++];
 
-	fd = open(mp, O_RDONLY);
-	if (fd < 0)
-		die("can't open file %s: %s\n",
-		    mp, strerror(errno));
-
-	check_for_gfs2(fd, mp);
-	close(fd);
-	fs = mp2fsname(mp);
+	check_for_gfs2(&sbd);
+	fs = mp2fsname(sbd.path_name);
 
 	if (strcmp(param, "quota_scale") == 0) {
 		float s;
gfs2/tool/util.c +6 -29
@@ -168,34 +168,6 @@
 }
 
 /**
- * check_for_gfs2 - Check to see if a descriptor is a file on a GFS2 filesystem
- * @fd: the file descriptor
- * @path: the path used to open the descriptor
- *
- */
-
-/* 
- * FIXME check_for_gfs2() uses an ioctl that's not supported by gfs2.
- * This function is used as a sanity check before performing certain
- * operations.
- */
-#if 0
-void
-check_for_gfs2(int fd, char *path)
-{
-	unsigned int magic = 0;
-	int error = 0;
-	error = ioctl(fd, GFS2_IOCTL_IDENTIFY, &magic);
-	if (error || magic != GFS2_MAGIC)
-		die("%s is not a GFS2 file/filesystem\n",
-		    path);
-}
-#else
-void check_for_gfs2(int fd, char *path) {}
-#endif /* #if 0 */
-
-
-/**
  * str2lines - parse a string into lines
  * @list: the list
  *
@@ -280,7 +252,11 @@
 	char line[PATH_MAX];
 	static char device[PATH_MAX];
 	char *name = NULL;
+	char *realname;
 
+	realname = realpath(mp, NULL);
+	if (!realname)
+		die("Unable to allocate memory for name resolution.\n");
 	file = fopen("/proc/mounts", "r");
 	if (!file)
 		die("can't open /proc/mounts: %s\n", strerror(errno));
@@ -290,7 +266,7 @@
 
 		if (sscanf(line, "%s %s %s", device, path, type) != 3)
 			continue;
-		if (strcmp(path, mp))
+		if (strcmp(path, realname))
 			continue;
 		if (strcmp(type, "gfs2"))
 			die("%s is not a GFS2 filesystem\n", mp);
@@ -300,6 +276,7 @@
 		break;
 	}
 
+	free(realname);
 	fclose(file);
 
 	return name;