[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[Cluster-devel] cluster/gfs2 edit/hexedit.h fsck/initialize.c ...



CVSROOT:	/cvs/cluster
Module name:	cluster
Changes by:	rpeterso sourceware org	2007-11-13 17:03:41

Modified files:
	gfs2/edit      : hexedit.h 
	gfs2/fsck      : initialize.c util.h 
	gfs2/libgfs2   : buf.c libgfs2.h misc.c 
	gfs2/mkfs      : gfs2_mkfs.h 
	gfs2/quota     : check.c gfs2_quota.h main.c 
	gfs2/tool      : Makefile gfs2_tool.h main.c sb.c 
Removed files:
	gfs2/tool      : util.c 

Log message:
	Resolves: bz 364741: GFS2: gfs2_quota doesn't work unless lock
	table specified

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/gfs2/edit/hexedit.h.diff?cvsroot=cluster&r1=1.12&r2=1.13
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/gfs2/fsck/initialize.c.diff?cvsroot=cluster&r1=1.10&r2=1.11
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/gfs2/fsck/util.h.diff?cvsroot=cluster&r1=1.2&r2=1.3
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/gfs2/libgfs2/buf.c.diff?cvsroot=cluster&r1=1.3&r2=1.4
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/gfs2/libgfs2/libgfs2.h.diff?cvsroot=cluster&r1=1.21&r2=1.22
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/gfs2/libgfs2/misc.c.diff?cvsroot=cluster&r1=1.5&r2=1.6
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/gfs2/mkfs/gfs2_mkfs.h.diff?cvsroot=cluster&r1=1.9&r2=1.10
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/gfs2/quota/check.c.diff?cvsroot=cluster&r1=1.6&r2=1.7
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/gfs2/quota/gfs2_quota.h.diff?cvsroot=cluster&r1=1.5&r2=1.6
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/gfs2/quota/main.c.diff?cvsroot=cluster&r1=1.9&r2=1.10
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/gfs2/tool/Makefile.diff?cvsroot=cluster&r1=1.14&r2=1.15
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/gfs2/tool/gfs2_tool.h.diff?cvsroot=cluster&r1=1.9&r2=1.10
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/gfs2/tool/main.c.diff?cvsroot=cluster&r1=1.7&r2=1.8
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/gfs2/tool/sb.c.diff?cvsroot=cluster&r1=1.3&r2=1.4
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/gfs2/tool/util.c.diff?cvsroot=cluster&r1=1.8&r2=NONE

--- cluster/gfs2/edit/hexedit.h	2007/10/18 19:56:41	1.12
+++ cluster/gfs2/edit/hexedit.h	2007/11/13 17:03:39	1.13
@@ -197,31 +197,6 @@
 #define SCREEN_HEIGHT   (16)
 #define SCREEN_WIDTH    (16)
 
-/*  I/O macros  */
-
-#define do_lseek(fd, off) \
-{ \
-  if (lseek((fd), (off), SEEK_SET) != (off)) \
-    die("bad seek: %s on line %d of file %s\n", \
-	strerror(errno),__LINE__, __FILE__); \
-}
-
-#define do_read(fd, buff, len) \
-{ \
-  if (read((fd), (buff), (len)) != (len)) \
-    die("bad read: %s on line %d of file %s\n", \
-	strerror(errno), __LINE__, __FILE__); \
-}
-
-#define do_write(fd, buff, len) \
-{ \
-  if (write((fd), (buff), (len)) != (len)) \
-    die("bad write: %s on line %d of file %s\n", \
-	strerror(errno), __LINE__, __FILE__); \
-}
-
-
-
 /*  Memory macros  */
 
 #define type_zalloc(ptr, type, count) \
--- cluster/gfs2/fsck/initialize.c	2007/10/19 15:06:56	1.10
+++ cluster/gfs2/fsck/initialize.c	2007/11/13 17:03:40	1.11
@@ -169,7 +169,7 @@
 	last_data_block = rmax;
 	first_data_block = rmin;
 
-	if(do_lseek(sdp->device_fd, (last_fs_block * sdp->sd_sb.sb_bsize))){
+	if(fsck_lseek(sdp->device_fd, (last_fs_block * sdp->sd_sb.sb_bsize))){
 		log_crit("Can't seek to last block in file system: %"
 				 PRIu64" (0x%" PRIx64 ")\n", last_fs_block, last_fs_block);
 		goto fail;
--- cluster/gfs2/fsck/util.h	2006/06/06 14:49:31	1.2
+++ cluster/gfs2/fsck/util.h	2007/11/13 17:03:40	1.3
@@ -16,16 +16,9 @@
 
 #include "libgfs2.h"
 
-#define do_lseek(fd, off) \
+#define fsck_lseek(fd, off) \
   ((lseek((fd), (off), SEEK_SET) == (off)) ? 0 : -1)
 
-#define do_read(fd, buff, len) \
-  ((read((fd), (buff), (len)) == (len)) ? 0 : -1)
-
-#define do_write(fd, buff, len) \
-  ((write((fd), (buff), (len)) == (len)) ? 0 : -1)
-
-
 int compute_height(struct gfs2_sbd *sdp, uint64_t sz);
 struct di_info *search_list(osi_list_t *list, uint64_t addr);
 void warm_fuzzy_stuff(uint64_t block);
--- cluster/gfs2/libgfs2/buf.c	2006/06/08 21:02:15	1.3
+++ cluster/gfs2/libgfs2/buf.c	2007/11/13 17:03:40	1.4
@@ -25,27 +25,6 @@
 
 #include "libgfs2.h"
 
-#define do_lseek(sdp, off) \
-do { \
-	if (lseek((sdp)->device_fd, (off), SEEK_SET) != (off)) \
-		die("bad seek: %s on line %d of file %s\n", \
-		    strerror(errno), __LINE__, __FILE__); \
-} while (0)
-
-#define do_read(sdp, buf, len) \
-do { \
-	if (read((sdp)->device_fd, (buf), (len)) != (len)) \
-		die("bad read: %s on line %d of file %s\n", \
-		    strerror(errno), __LINE__, __FILE__); \
-} while (0)
-
-#define do_write(sdp, buf, len) \
-do { \
-	if (write((sdp)->device_fd, (buf), (len)) != (len)) \
-		die("bad write: %s on line %d of file %s\n", \
-		    strerror(errno), __LINE__, __FILE__); \
-} while (0)
-
 static __inline__ osi_list_t *
 blkno2head(struct gfs2_sbd *sdp, uint64_t blkno)
 {
@@ -59,8 +38,8 @@
 	osi_list_del(&bh->b_hash);
 	sdp->num_bufs--;
 	if (bh->b_changed) {
-		do_lseek(sdp, bh->b_blocknr * sdp->bsize);
-		do_write(sdp, bh->b_data, sdp->bsize);
+		do_lseek(sdp->device_fd, bh->b_blocknr * sdp->bsize);
+		do_write(sdp->device_fd, bh->b_data, sdp->bsize);
 		sdp->writes++;
 	}
 	free(bh);
@@ -126,8 +105,8 @@
 	bh->b_data = (char *)bh + sizeof(struct gfs2_buffer_head);
 	bh->b_size = sdp->bsize;
 	if (read_disk) {
-		do_lseek(sdp, num * sdp->bsize);
-		do_read(sdp, bh->b_data, sdp->bsize);
+		do_lseek(sdp->device_fd, num * sdp->bsize);
+		do_read(sdp->device_fd, bh->b_data, sdp->bsize);
 	}
 	add_buffer(sdp, bh);
 	bh->b_changed = FALSE;
@@ -196,8 +175,8 @@
 		if (!bh->b_count)             /* if not reserved for later */
 			write_buffer(sdp, bh);    /* write the data, free the memory */
 		else if (bh->b_changed) {     /* if buffer has changed */
-			do_lseek(sdp, bh->b_blocknr * sdp->bsize);
-			do_write(sdp, bh->b_data, sdp->bsize); /* write it out */
+			do_lseek(sdp->device_fd, bh->b_blocknr * sdp->bsize);
+			do_write(sdp->device_fd, bh->b_data, sdp->bsize); /* write it out */
 			bh->b_changed = FALSE;    /* no longer changed */
 		}
 	}
--- cluster/gfs2/libgfs2/libgfs2.h	2007/10/19 15:06:56	1.21
+++ cluster/gfs2/libgfs2/libgfs2.h	2007/11/13 17:03:40	1.22
@@ -40,6 +40,27 @@
 	exit(EXIT_FAILURE); \
 } while (0)
 
+#define do_lseek(fd, off) \
+{ \
+  if (lseek((fd), (off), SEEK_SET) != (off)) \
+    die("bad seek: %s on line %d of file %s\n", \
+	strerror(errno),__LINE__, __FILE__); \
+}
+
+#define do_read(fd, buff, len) \
+{ \
+  if (read((fd), (buff), (len)) < 0) \
+    die("bad read: %s on line %d of file %s\n", \
+	strerror(errno), __LINE__, __FILE__); \
+}
+
+#define do_write(fd, buff, len) \
+{ \
+  if (write((fd), (buff), (len)) != (len)) \
+    die("bad write: %s on line %d of file %s\n", \
+	strerror(errno), __LINE__, __FILE__); \
+}
+
 #define zalloc(ptr, size) \
 do { \
 	(ptr) = malloc((size)); \
@@ -507,6 +528,8 @@
 	       const char *format, ...);
 
 /* misc.c */
+#define SYS_BASE "/sys/fs/gfs2"
+
 void compute_constants(struct gfs2_sbd *sdp);
 int find_gfs2_meta(struct gfs2_sbd *sdp);
 int dir_exists(const char *dir);
@@ -514,6 +537,20 @@
 void mount_gfs2_meta(struct gfs2_sbd *sdp);
 void lock_for_admin(struct gfs2_sbd *sdp);
 void cleanup_metafs(struct gfs2_sbd *sdp);
+char *get_list(void);
+char **str2lines(char *str);
+char *find_debugfs_mount(void);
+char *mp2fsname(char *mp);
+char *name2value(char *str, char *name);
+uint32_t name2u32(char *str, char *name);
+uint64_t name2u64(char *str, char *name);
+char *__get_sysfs(char *fsname, char *filename);
+char *get_sysfs(char *fsname, char *filename);
+unsigned int get_sysfs_uint(char *fsname, char *filename);
+void set_sysfs(char *fsname, char *filename, char *val);
+char *do_basename(char *device);
+char *mp2devname(char *mp);
+int is_fsname(char *name);
 
 /* recovery.c */
 void gfs2_replay_incr_blk(struct gfs2_inode *ip, unsigned int *blk);
--- cluster/gfs2/libgfs2/misc.c	2007/10/25 14:14:32	1.5
+++ cluster/gfs2/libgfs2/misc.c	2007/11/13 17:03:40	1.6
@@ -25,9 +25,15 @@
 #include <sys/mount.h>
 #include <linux/types.h>
 #include <sys/file.h>
+#include <dirent.h>
+#include <linux/kdev_t.h>
 
 #include "libgfs2.h"
 
+#define PAGE_SIZE (4096)
+
+static char sysfs_buf[PAGE_SIZE];
+
 void
 compute_constants(struct gfs2_sbd *sdp)
 {
@@ -275,3 +281,432 @@
 	}
 }
 
+char *__get_sysfs(char *fsname, char *filename)
+{
+	char path[PATH_MAX];
+	int fd, rv;
+
+	memset(path, 0, PATH_MAX);
+	memset(sysfs_buf, 0, PAGE_SIZE);
+	snprintf(path, PATH_MAX - 1, "%s/%s/%s", SYS_BASE, fsname, filename);
+
+	fd = open(path, O_RDONLY);
+	if (fd < 0)
+		die("can't open %s: %s\n", path, strerror(errno));
+	rv = read(fd, sysfs_buf, PAGE_SIZE);
+	if (rv < 0)
+		die("can't read from %s: %s\n", path, strerror(errno));
+
+	close(fd);
+	return sysfs_buf;
+}
+
+char *
+get_sysfs(char *fsname, char *filename)
+{
+	char *p = strchr(__get_sysfs(fsname, filename), '\n');
+	if (p)
+		*p = '\0';
+	return sysfs_buf;
+}
+
+unsigned int
+get_sysfs_uint(char *fsname, char *filename)
+{
+	unsigned int x;
+	sscanf(__get_sysfs(fsname, filename), "%u", &x);
+	return x;
+}
+
+void
+set_sysfs(char *fsname, char *filename, char *val)
+{
+	char path[PATH_MAX];
+	int fd, rv, len;
+
+	len = strlen(val) + 1;
+	if (len > PAGE_SIZE)
+		die("value for %s is too larger for sysfs\n", path);
+
+	memset(path, 0, PATH_MAX);
+	snprintf(path, PATH_MAX - 1, "%s/%s/%s", SYS_BASE, fsname, filename);
+
+	fd = open(path, O_WRONLY);
+	if (fd < 0)
+		die("can't open %s: %s\n", path, strerror(errno));
+
+	rv = write(fd, val, len);
+	if (rv != len){
+		if (rv < 0)
+			die("can't write to %s: %s", path, strerror(errno));
+		else
+			die("tried to write %d bytes to path, wrote %d\n",
+			    len, rv);
+	}
+	close(fd);
+}
+
+/**
+ * get_list - Get the list of GFS2 filesystems
+ *
+ * Returns: a NULL terminated string
+ */
+
+#define LIST_SIZE 1048576
+
+char *
+get_list(void)
+{
+	char path[PATH_MAX];
+	char s_id[PATH_MAX];
+	char *list, *p;
+	int rv, fd, x = 0, total = 0;
+	DIR *d;
+	struct dirent *de;
+
+	list = malloc(LIST_SIZE);
+	if (!list)
+		die("out of memory\n");
+
+	memset(path, 0, PATH_MAX);
+	snprintf(path, PATH_MAX, "%s", SYS_BASE);
+
+	d = opendir(path);
+	if (!d)
+		die("can't open %s: %s\n", SYS_BASE, strerror(errno));
+
+	while ((de = readdir(d))) {
+		if (de->d_name[0] == '.')
+			continue;
+
+		memset(path, 0, PATH_MAX);
+		snprintf(path, PATH_MAX, "%s/%s/id", SYS_BASE, de->d_name);
+
+		fd = open(path, O_RDONLY);
+		if (fd < 0)
+			die("can't open %s: %s\n", path, strerror(errno));
+
+		memset(s_id, 0, PATH_MAX);
+
+		rv = read(fd, s_id, sizeof(s_id));
+		if (rv < 0)
+			die("can't read %s: %s\n", path, strerror(errno));
+
+		close(fd);
+
+		p = strstr(s_id, "\n");
+		if (p)
+			*p = '\0';
+
+		total += strlen(s_id) + strlen(de->d_name) + 2;
+		if (total > LIST_SIZE)
+			break;
+
+		x += sprintf(list + x, "%s %s\n", s_id, de->d_name);
+
+	}
+
+	closedir(d);
+
+	return list;
+}
+
+/**
+ * str2lines - parse a string into lines
+ * @list: the list
+ *
+ * Returns: An array of character pointers
+ */
+
+char **
+str2lines(char *str)
+{
+	char *p;
+	unsigned int n = 0;
+	char **lines;
+	unsigned int x = 0;
+
+	for (p = str; *p; p++)
+		if (*p == '\n')
+			n++;
+
+	lines = malloc((n + 1) * sizeof(char *));
+	if (!lines)
+		die("out of memory\n");
+
+	for (lines[x] = p = str; *p; p++)
+		if (*p == '\n') {
+			*p = 0;
+			lines[++x] = p + 1;
+		}
+
+	return lines;
+}
+
+/**
+ * do_basename - Create dm-N style name for the device
+ * @device:
+ *
+ * Returns: Pointer to dm name or basename
+ */
+
+char *
+do_basename(char *device)
+{
+	FILE *file;
+	int found = FALSE;
+	char line[PATH_MAX], major_name[PATH_MAX];
+	unsigned int major_number;
+	struct stat st;
+
+	file = fopen("/proc/devices", "r");
+	if (!file)
+		goto punt;
+
+	while (fgets(line, PATH_MAX, file)) {
+		if (sscanf(line, "%u %s", &major_number, major_name) != 2)
+			continue;
+		if (strcmp(major_name, "device-mapper") != 0)
+			continue;
+		found = TRUE;
+		break;
+	}
+
+	fclose(file);
+
+	if (!found)
+		goto punt;
+
+	if (stat(device, &st))
+		goto punt;
+	if (major(st.st_rdev) == major_number) {
+		static char realname[16];
+		snprintf(realname, 16, "dm-%u", minor(st.st_rdev));
+		return realname;
+	}
+
+ punt:
+	return basename(device);
+}
+
+char *
+mp2devname(char *mp)
+{
+	FILE *file;
+	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));
+
+	while (fgets(line, PATH_MAX, file)) {
+		char path[PATH_MAX], type[PATH_MAX];
+
+		if (sscanf(line, "%s %s %s", device, path, type) != 3)
+			continue;
+		if (strcmp(path, realname))
+			continue;
+		if (strcmp(type, "gfs2"))
+			die("%s is not a GFS2 filesystem\n", mp);
+
+		name = do_basename(device);
+
+		break;
+	}
+
+	free(realname);
+	fclose(file);
+
+	return name;
+}
+
+char *
+find_debugfs_mount(void)
+{
+	FILE *file;
+	char line[PATH_MAX];
+	char device[PATH_MAX], type[PATH_MAX];
+	char *path;
+
+	file = fopen("/proc/mounts", "rt");
+	if (!file)
+		die("can't open /proc/mounts: %s\n", strerror(errno));
+
+	path = malloc(PATH_MAX);
+	if (!path)
+		die("Can't allocate memory for debugfs.\n");
+	while (fgets(line, PATH_MAX, file)) {
+
+		if (sscanf(line, "%s %s %s", device, path, type) != 3)
+			continue;
+		if (!strcmp(type, "debugfs")) {
+			fclose(file);
+			return path;
+		}
+	}
+
+	free(path);
+	fclose(file);
+	return NULL;
+}
+
+/* The fsname can be substituted for the mountpoint on the command line.
+   This is necessary when we can't resolve a devname from /proc/mounts
+   to a fsname. */
+
+int is_fsname(char *name)
+{
+	int rv = 0;
+	DIR *d;
+	struct dirent *de;
+
+	d = opendir(SYS_BASE);
+	if (!d)
+		die("can't open %s: %s\n", SYS_BASE, strerror(errno));
+
+	while ((de = readdir(d))) {
+		if (de->d_name[0] == '.')
+			continue;
+
+		if (strcmp(de->d_name, name) == 0) {
+			rv = 1;
+			break;
+		}
+	}
+
+	closedir(d);
+
+	return rv;
+}
+
+/**
+ * mp2fsname - Find the name for a filesystem given its mountpoint
+ *
+ * We do this by iterating through gfs2 dirs in /sys/fs/gfs2/ looking for
+ * one where the "id" attribute matches the device id returned by stat for
+ * the mount point.  The reason we go through all this is simple: the
+ * kernel's sysfs is named after the VFS s_id, not the device name.
+ * So it's perfectly legal to do something like this to simulate user
+ * conditions without the proper hardware:
+ *    # rm /dev/sdb1
+ *    # mkdir /dev/cciss
+ *    # mknod /dev/cciss/c0d0p1 b 8 17
+ *    # mount -tgfs2 /dev/cciss/c0d0p1 /mnt/gfs2
+ *    # gfs2_tool gettune /mnt/gfs2
+ * In this example the tuning variables are in a directory named after the
+ * VFS s_id, which in this case would be /sys/fs/gfs2/sdb1/
+ *
+ * Returns: the fsname
+ */
+
+char *
+mp2fsname(char *mp)
+{
+	char device_id[PATH_MAX], *fsname = NULL;
+	struct stat statbuf;
+	DIR *d;
+	struct dirent *de;
+
+	if (stat(mp, &statbuf))
+		return NULL;
+
+	memset(device_id, 0, sizeof(device_id));
+	sprintf(device_id, "%u:%u", (uint32_t)MAJOR(statbuf.st_dev),
+		(uint32_t)MINOR(statbuf.st_dev));
+
+	d = opendir(SYS_BASE);
+	if (!d)
+		die("can't open %s: %s\n", SYS_BASE, strerror(errno));
+
+	while ((de = readdir(d))) {
+		if (de->d_name[0] == '.')
+			continue;
+
+		if (strcmp(get_sysfs(de->d_name, "id"), device_id) == 0) {
+			fsname = strdup(de->d_name);
+			break;
+		}
+	}
+
+	closedir(d);
+
+	return fsname;
+}
+
+/**
+ * name2value - find the value of a name-value pair in a string
+ * @str_in:
+ * @name:
+ *
+ * Returns: the value string in a static buffer
+ */
+
+char *
+name2value(char *str_in, char *name)
+{
+	char str[strlen(str_in) + 1];
+	static char value[PATH_MAX];
+	char **lines;
+	unsigned int x;
+	unsigned int len = strlen(name);
+
+	strcpy(str, str_in);
+	value[0] = 0;
+
+	lines = str2lines(str);
+
+	for (x = 0; *lines[x]; x++)
+		if (memcmp(lines[x], name, len) == 0 &&
+		    lines[x][len] == ' ') {
+			strcpy(value, lines[x] + len + 1);
+			break;
+		}
+
+	free(lines);
+
+	return value;
+}
+
+/**
+ * name2u32 - find the value of a name-value pair in a string
+ * @str_in:
+ * @name:
+ *
+ * Returns: the value uint32
+ */
+
+uint32_t
+name2u32(char *str, char *name)
+{
+	char *value = name2value(str, name);
+	uint32_t x = 0;
+
+	sscanf(value, "%u", &x);
+
+	return x;
+}
+
+/**
+ * name2u64 - find the value of a name-value pair in a string
+ * @str_in:
+ * @name:
+ *
+ * Returns: the value uint64
+ */
+
+uint64_t
+name2u64(char *str, char *name)
+{
+	char *value = name2value(str, name);
+	uint64_t x = 0;
+
+	sscanf(value, "%"SCNu64, &x);
+
+	return x;
+}
--- cluster/gfs2/mkfs/gfs2_mkfs.h	2006/10/26 18:42:25	1.9
+++ cluster/gfs2/mkfs/gfs2_mkfs.h	2007/11/13 17:03:40	1.10
@@ -35,46 +35,6 @@
 /* main_shrink */
 void main_shrink(int argc, char *argv[]);
 
-static inline int __do_read(int fd, char *buff, size_t len, 
-			    const char *file, int line)
-{
-	int ret = read(fd, buff, len);
-	if (ret < 0) {
-		die("bad read: %s on line %d of file %s\n", 
-		    strerror(errno), line, file);
-	}
-	return ret;
-}
-
-#define do_read(fd, buf, len) \
-	__do_read((fd), (buf), (len), __FILE__, __LINE__)
-
-static inline int __do_write(int fd, char *buff, size_t len,
-			     const char *file, int line)
-{
-	int ret = write(fd, buff, len);
-	if (ret != len) {
-		die("bad write: %s on line %d of file %s\n",
-		    strerror(errno), line, file);
-	}
-	return ret;
-}
-
-#define do_write(fd, buf, len) \
-	__do_write((fd), (buf), (len), __FILE__, __LINE__)
-
-static inline int __do_lseek(int fd, off_t off, const char *file, int line)
-{
-	if (lseek(fd, off, SEEK_SET) != off) {
-		die("bad seek: %s on line %d of file %s\n",
-		    strerror(errno), line, file);
-	}
-	return 0;
-}
-
-#define do_lseek(fd, off) \
-	__do_lseek((fd), (off), __FILE__, __LINE__)
-
 /*
  * The following inode IOCTL macros and inode flags 
  * are copied from linux/fs.h, because we have duplicate 
--- cluster/gfs2/quota/check.c	2007/08/24 06:08:26	1.6
+++ cluster/gfs2/quota/check.c	2007/11/13 17:03:40	1.7
@@ -455,15 +455,15 @@
 set_list(struct gfs2_sbd *sdp, commandline_t *comline, int user, 
 	 osi_list_t *list, int64_t multiplier)
 {
-	int fd, fd1;
+	int fd;
 	osi_list_t *tmp;
 	values_t *v;
 	uint64_t offset;
 	int64_t value;
 	int error;
 	char quota_file[BUF_SIZE];
-	char sys_q_refresh[BUF_SIZE];
 	char id_str[16];
+	char *fs;
 
 	strcpy(sdp->path_name, comline->filesystem);
 	check_for_gfs2(sdp);
@@ -503,27 +503,10 @@
 		}
 
 		/* Write the id to sysfs quota refresh file to refresh gfs quotas */
-		sprintf(sys_q_refresh, "%s%s%s", "/sys/fs/gfs2/",
-			sdp->sd_sb.sb_locktable, 
-			(user) ? "/quota_refresh_user" :
-			"/quota_refresh_group");
-		
-		fd1 = open(sys_q_refresh, O_WRONLY);
-		if (fd1 < 0) {
-			fprintf(stderr, "can't open file %s: %s\n", 
-				sys_q_refresh, strerror(errno));
-			goto out;
-		}
-
+		fs = mp2fsname(comline->filesystem);
 		sprintf(id_str, "%d", comline->id);
-		
-		if (write(fd1,(void*)id_str, strlen(id_str)) != strlen(id_str)) {
-			close(fd1);
-			fprintf(stderr, "failed to write to %s: %s\n", 
-				sys_q_refresh, strerror(errno));
-			goto out;
-		}
-		close(fd1);
+		set_sysfs(fs, (user) ? "quota_refresh_user" :
+			  "quota_refresh_group", id_str);
 	}
 
 out:
--- cluster/gfs2/quota/gfs2_quota.h	2007/08/24 06:08:26	1.5
+++ cluster/gfs2/quota/gfs2_quota.h	2007/11/13 17:03:40	1.6
@@ -18,21 +18,6 @@
 #include "linux_endian.h"
 #include <linux/gfs2_ondisk.h>
 
-#ifndef TRUE
-#define TRUE (1)
-#endif
-
-#ifndef FALSE
-#define FALSE (0)
-#endif
-
-#define die(fmt, args...) \
-do { \
-	fprintf(stderr, "%s: ", prog_name); \
-	fprintf(stderr, fmt, ##args); \
-	exit(EXIT_FAILURE); \
-} while (0)
-
 #define type_zalloc(ptr, type, count) \
 do { \
 	(ptr) = (type *)malloc(sizeof(type) * (count)); \
@@ -116,45 +101,4 @@
 uint32_t name_to_id(int user, char *name, int numbers);
 char *id_to_name(int user, uint32_t id, int numbers);
 
-
-static inline int __do_read(int fd, char *buff, size_t len, 
-			    const char *file, int line)
-{
-	int ret = read(fd, buff, len);
-	if (ret < 0) {
-		die("bad read: %s on line %d of file %s\n", 
-		    strerror(errno), line, file);
-	}
-	return ret;
-}
-
-#define do_read(fd, buf, len) \
-	__do_read((fd), (buf), (len), __FILE__, __LINE__)
-
-static inline int __do_write(int fd, char *buff, size_t len,
-			     const char *file, int line)
-{
-	int ret = write(fd, buff, len);
-	if (ret != len) {
-		die("bad write: %s on line %d of file %s\n",
-		    strerror(errno), line, file);
-	}
-	return ret;
-}
-
-#define do_write(fd, buf, len) \
-	__do_write((fd), (buf), (len), __FILE__, __LINE__)
-
-static inline int __do_lseek(int fd, off_t off, const char *file, int line)
-{
-	if (lseek(fd, off, SEEK_SET) != off) {
-		die("bad seek: %s on line %d of file %s\n",
-		    strerror(errno), line, file);
-	}
-	return 0;
-}
-
-#define do_lseek(fd, off) \
-	__do_lseek((fd), (off), __FILE__, __LINE__)
-
 #endif /* __GFS2_QUOTA_DOT_H__ */
--- cluster/gfs2/quota/main.c	2007/10/11 20:27:49	1.9
+++ cluster/gfs2/quota/main.c	2007/11/13 17:03:40	1.10
@@ -746,24 +746,10 @@
 static void 
 do_sync_one(struct gfs2_sbd *sdp, char *filesystem)
 {
-	int fd;
-	char sys_quota_sync[PATH_MAX];
+	char *fsname;
 
-	strcpy(sdp->path_name, filesystem);
-	check_for_gfs2(sdp);
-	read_superblock(&sdp->sd_sb, sdp);
-	sprintf(sys_quota_sync, "%s%s%s", 
-		"/sys/fs/gfs2/", sdp->sd_sb.sb_locktable, "/quota_sync");
-	
-	fd = open(sys_quota_sync, O_WRONLY);
-	if (fd < 0)
-		die("can't open file %s: %s\n", sys_quota_sync, strerror(errno));
-	
-	if (write(fd,(void*)"1", 1) != 1)
-		die("failed to write to %s: %s\n", 
-		    sys_quota_sync, strerror(errno));
-	
-	close(fd);
+	fsname = mp2fsname(filesystem);
+	set_sysfs(fsname, "quota_sync", "1");
 }
 
 /**
@@ -809,14 +795,14 @@
 static void
 do_set(struct gfs2_sbd *sdp, commandline_t *comline)
 {
-	int fd, fd1;
+	int fd;
 	uint64_t offset;
 	uint64_t new_value;
 	int error, adj_flag = 0;;
 	char quota_file[BUF_SIZE];
-	char sys_q_refresh[BUF_SIZE];
 	char id_str[16];
 	struct stat stat_buf;
+	char *fs;
 	
 	if (!*comline->filesystem)
 		die("need a filesystem to work on\n");
@@ -958,28 +944,11 @@
 		}
 	}
 
-	/* Write the id to sysfs quota refresh file to refresh gfs quotas */
-	sprintf(sys_q_refresh, "%s%s%s", "/sys/fs/gfs2/",
-		sdp->sd_sb.sb_locktable, 
-		comline->id_type == GQ_ID_USER ? "/quota_refresh_user" : 
-		"/quota_refresh_group");
-	
-	fd1 = open(sys_q_refresh, O_WRONLY);
-	if (fd1 < 0) {
-		fprintf(stderr, "can't open file %s: %s\n", sys_q_refresh, 
-			strerror(errno));
-		goto out;
-	}
-
+	fs = mp2fsname(comline->filesystem);
 	sprintf(id_str, "%d", comline->id);
+	set_sysfs(fs, comline->id_type == GQ_ID_USER ?
+		  "quota_refresh_user" : "quota_refresh_group", id_str);
 	
-	if (write(fd1,(void*)id_str, strlen(id_str)) != strlen(id_str)) {
-		close(fd1);
-		fprintf(stderr, "failed to write to %s: %s\n", 
-			sys_q_refresh, strerror(errno));
-		goto out;
-	}
-	close(fd1);
 	if (adj_flag)
 		adjust_quota_list(fd, comline);
 out:
--- cluster/gfs2/tool/Makefile	2007/10/25 14:14:33	1.14
+++ cluster/gfs2/tool/Makefile	2007/11/13 17:03:41	1.15
@@ -22,8 +22,7 @@
 	misc.o \
 	ondisk.o \
 	sb.o \
-	tune.o \
-	util.o
+	tune.o
 
 CFLAGS += -D_FILE_OFFSET_BITS=64
 CFLAGS += -I${KERNEL_SRC}/fs/gfs2/ -I${KERNEL_SRC}/include/
--- cluster/gfs2/tool/gfs2_tool.h	2007/11/07 14:57:59	1.9
+++ cluster/gfs2/tool/gfs2_tool.h	2007/11/13 17:03:41	1.10
@@ -15,23 +15,6 @@
 #define __GFS2_TOOL_DOT_H__
 
 
-#ifndef TRUE
-#define TRUE (1)
-#endif
-
-#ifndef FALSE
-#define FALSE (0)
-#endif
-
-#define die(fmt, args...) \
-do { \
-	fprintf(stderr, "%s: ", prog_name); \
-	fprintf(stderr, fmt, ##args); \
-	exit(EXIT_FAILURE); \
-} while (0)
-
-#define SYS_BASE "/sys/fs/gfs2"
-
 extern char *prog_name;
 extern char *action;
 extern int override;
@@ -90,20 +73,4 @@
 void get_tune(int argc, char **argv);
 void set_tune(int argc, char **argv);
 
-
-/* From util.c */
-
-char *get_list(void);
-char **str2lines(char *str);
-char *find_debugfs_mount(void);
-char *mp2fsname(char *mp);
-char *name2value(char *str, char *name);
-uint32_t name2u32(char *str, char *name);
-uint64_t name2u64(char *str, char *name);
-char *__get_sysfs(char *fsname, char *filename);
-char *get_sysfs(char *fsname, char *filename);
-unsigned int get_sysfs_uint(char *fsname, char *filename);
-void set_sysfs(char *fsname, char *filename, char *val);
-
-
 #endif /* __GFS2_TOOL_DOT_H__ */
--- cluster/gfs2/tool/main.c	2007/10/30 14:06:06	1.7
+++ cluster/gfs2/tool/main.c	2007/11/13 17:03:41	1.8
@@ -28,6 +28,7 @@
 #include "copyright.cf"
 
 #include "gfs2_tool.h"
+#include "libgfs2.h"
 
 char *prog_name;
 char *action = NULL;
--- cluster/gfs2/tool/sb.c	2007/06/18 21:35:58	1.3
+++ cluster/gfs2/tool/sb.c	2007/11/13 17:03:41	1.4
@@ -29,12 +29,7 @@
 #include <linux/gfs2_ondisk.h>
 
 #include "gfs2_tool.h"
-
-/* From libgfs2 */
-extern int gfs2_sb_in(struct gfs2_sb *sb, char *buf);
-extern void gfs2_sb_print(struct gfs2_sb *sb);
-extern int gfs2_sb_out(struct gfs2_sb *sb, char *buf);
-
+#include "libgfs2.h"
 
 void print_it(const char *label, const char *fmt, const char *fmt2, ...)
 {
@@ -47,27 +42,6 @@
 	va_end(args);
 }
 
-#define do_lseek(fd, off) \
-do { \
-	if (lseek((fd), (off), SEEK_SET) != (off)) \
-		die("bad seek: %s on line %d of file %s\n", \
-		    strerror(errno),__LINE__, __FILE__); \
-} while (0)
-
-#define do_read(fd, buff, len) \
-do { \
-	if (read((fd), (buff), (len)) != (len)) \
-		die("bad read: %s on line %d of file %s\n", \
-		    strerror(errno), __LINE__, __FILE__); \
-} while (0)
-
-#define do_write(fd, buff, len) \
-do { \
-	if (write((fd), (buff), (len)) != (len)) \
-		die("bad write: %s on line %d of file %s\n", \
-		    strerror(errno), __LINE__, __FILE__); \
-} while (0)
-
 /**
  * do_sb - examine/modify a unmounted FS' superblock
  * @argc:


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]