[Cluster-devel] [PATCH] [GFS2 userland] New gfs2_grow command
Robert Peterson
rpeterso at redhat.com
Tue May 1 20:20:12 UTC 2007
Hi All,
Attached below is the long-awaited patch to add a gfs2_grow
command to extend gfs2 file systems. Please review and send
me your comments. This is for bugzilla:
https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=234844
(which now contains the patch as an attachment.)
It applies to the HEAD branch of CVS.
Note that a bunch of common code was moved from gfs2_jadd
to libgfs2's misc.c as part of this patch.
Regards,
Bob Peterson
Red Hat Cluster Suite
--
Signed-off-by: Bob Peterson <rpeterso at redhat.com>
--
Index: libgfs2/libgfs2.h
===================================================================
RCS file: /cvs/cluster/cluster/gfs2/libgfs2/libgfs2.h,v
retrieving revision 1.11
diff -w -u -p -p -u -r1.11 libgfs2.h
--- libgfs2/libgfs2.h 1 May 2007 16:43:39 -0000 1.11
+++ libgfs2/libgfs2.h 1 May 2007 20:06:13 -0000
@@ -165,7 +165,7 @@ struct gfs2_sbd {
int expert;
int override;
- char *device_name;
+ char device_name[PATH_MAX];
char *path_name;
/* Constants */
@@ -219,6 +219,9 @@ struct gfs2_sbd {
unsigned int spills;
unsigned int writes;
+ int metafs_fd;
+ int metafs_mounted; /* If metafs was already mounted */
+ char metafs_path[PATH_MAX]; /* where metafs is mounted */
};
extern char *prog_name;
@@ -343,7 +346,6 @@ void write_buffer(struct gfs2_sbd *sdp,
/* device_geometry.c */
void device_geometry(struct gfs2_sbd *sdp);
void fix_device_geometry(struct gfs2_sbd *sdp);
-void munge_device_geometry_for_grow(struct gfs2_sbd *sdp);
/* fs_bits.c */
#define BFITNOENT (0xFFFFFFFF)
@@ -497,6 +499,12 @@ int query(struct gfs2_options *opts, con
/* misc.c */
void compute_constants(struct gfs2_sbd *sdp);
+int find_gfs2_meta(struct gfs2_sbd *sdp);
+int dir_exists(const char *dir);
+void check_for_gfs2(struct gfs2_sbd *sdp);
+void mount_gfs2_meta(struct gfs2_sbd *sdp);
+void lock_for_admin(struct gfs2_sbd *sdp);
+void cleanup_metafs(struct gfs2_sbd *sdp);
/* rgrp.c */
int gfs2_compute_bitstructs(struct gfs2_sbd *sdp, struct rgrp_list *rgd);
Index: libgfs2/misc.c
===================================================================
RCS file: /cvs/cluster/cluster/gfs2/libgfs2/misc.c,v
retrieving revision 1.2
diff -w -u -p -p -u -r1.2 misc.c
--- libgfs2/misc.c 6 Jun 2006 14:20:41 -0000 1.2
+++ libgfs2/misc.c 1 May 2007 20:06:13 -0000
@@ -2,7 +2,7 @@
*******************************************************************************
**
** Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
-** Copyright (C) 2005 Red Hat, Inc. All rights reserved.
+** Copyright (C) 2005-2007 Red Hat, Inc. All rights reserved.
**
** This copyrighted material is made available to anyone wishing to use,
** modify, copy, or redistribute it subject to the terms and conditions
@@ -22,8 +22,10 @@
#include <unistd.h>
#include <time.h>
#include <errno.h>
-
+#include <sys/mount.h>
#include <linux/types.h>
+#include <sys/file.h>
+
#include "libgfs2.h"
void
@@ -102,3 +104,170 @@ compute_constants(struct gfs2_sbd *sdp)
die("bad constants (2)\n");
}
+int
+find_gfs2_meta(struct gfs2_sbd *sdp)
+{
+ FILE *fp = fopen("/proc/mounts", "r");
+ char name[] = "gfs2meta";
+ char buffer[PATH_MAX];
+ char fstype[80], mfsoptions[PATH_MAX];
+ char meta_device[PATH_MAX];
+ char meta_path[PATH_MAX];
+ int fsdump, fspass;
+
+ if (fp == NULL) {
+ perror("open: /proc/mounts");
+ exit(EXIT_FAILURE);
+ }
+ sdp->metafs_mounted = FALSE;
+ memset(sdp->metafs_path, 0, sizeof(sdp->metafs_path));
+ memset(meta_path, 0, sizeof(meta_path));
+ while ((fgets(buffer, PATH_MAX - 1, fp)) != NULL) {
+ buffer[PATH_MAX - 1] = '\0';
+ if (strstr(buffer, name) == 0)
+ continue;
+
+ if (sscanf(buffer, "%s %s %s %s %d %d", meta_device,
+ 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;
+ strcpy(sdp->metafs_path, meta_path);
+ return TRUE;
+ }
+ }
+ fclose(fp);
+ return FALSE;
+}
+
+int
+dir_exists(const char *dir)
+{
+ int fd, ret;
+ struct stat statbuf;
+ fd = open(dir, O_RDONLY);
+ if (fd<0) {
+ if (errno == ENOENT)
+ return 0;
+ die("Couldn't open %s : %s\n", dir, strerror(errno));
+ }
+ ret = fstat(fd, &statbuf);
+ if (ret)
+ die("stat failed on %s : %s\n", dir, strerror(errno));
+ if (S_ISDIR(statbuf.st_mode)) {
+ close(fd);
+ return 1;
+ }
+ close(fd);
+ die("%s exists, but is not a directory. Cannot mount metafs here\n", dir);
+}
+
+void
+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];
+
+ if (name[strlen(name) - 1] == '/')
+ name[strlen(name) - 1] = '\0';
+
+ if (fp == NULL) {
+ perror("open: /proc/mounts");
+ exit(EXIT_FAILURE);
+ }
+ while ((fgets(buffer, PATH_MAX - 1, fp)) != NULL) {
+ buffer[PATH_MAX - 1] = 0;
+
+ if (strstr(buffer, "0") == 0)
+ continue;
+
+ if ((ret = sscanf(buffer, "%s %s %s %s %d %d",
+ sdp->device_name, fspath,
+ fstype, fsoptions, &fsdump, &fspass)) != 6)
+ continue;
+
+ if (strcmp(fstype, "gfs2") != 0)
+ continue;
+
+ /* Check if they specified the device instead of mnt point */
+ if (strcmp(sdp->device_name, name) == 0)
+ strcpy(sdp->path_name, fspath); /* fix it */
+ else if (strcmp(fspath, name) != 0)
+ continue;
+
+ fclose(fp);
+ if (strncmp(sdp->device_name, "/dev/loop", 9) == 0)
+ die("Cannot perform this operation on a loopback GFS2 mount.\n");
+
+ return;
+ }
+ fclose(fp);
+ die("gfs2 Filesystem %s is not mounted.\n", name);
+}
+
+void
+mount_gfs2_meta(struct gfs2_sbd *sdp)
+{
+ int ret;
+ /* 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));
+ }
+
+ ret = mount(sdp->device_name, sdp->metafs_path, "gfs2meta", 0, NULL);
+ if (ret)
+ die("Couldn't mount %s : %s\n", sdp->metafs_path,
+ strerror(errno));
+}
+
+void
+lock_for_admin(struct gfs2_sbd *sdp)
+{
+ int error;
+
+ if (sdp->debug)
+ printf("\nTrying to get admin lock...\n");
+
+ sdp->metafs_fd = open(sdp->metafs_path, O_RDONLY | O_NOFOLLOW);
+ if (sdp->metafs_fd < 0)
+ die("can't open %s: %s\n",
+ sdp->metafs_path, strerror(errno));
+
+ error = flock(sdp->metafs_fd, LOCK_EX);
+ if (error)
+ die("can't flock %s: %s\n", sdp->metafs_path, strerror(errno));
+ if (sdp->debug)
+ printf("Got it.\n");
+}
+
+void
+cleanup_metafs(struct gfs2_sbd *sdp)
+{
+ int ret;
+
+ if (sdp->metafs_fd <= 0)
+ return;
+
+ fsync(sdp->metafs_fd);
+ close(sdp->metafs_fd);
+ if (!sdp->metafs_mounted) { /* was mounted by us */
+ ret = umount(sdp->metafs_path);
+ if (ret)
+ fprintf(stderr, "Couldn't unmount %s : %s\n",
+ sdp->metafs_path, strerror(errno));
+ }
+}
+
Index: mkfs/Makefile
===================================================================
RCS file: /cvs/cluster/cluster/gfs2/mkfs/Makefile,v
retrieving revision 1.14
diff -w -u -p -p -u -r1.14 Makefile
--- mkfs/Makefile 30 Apr 2007 11:22:16 -0000 1.14
+++ mkfs/Makefile 1 May 2007 20:06:13 -0000
@@ -7,9 +7,11 @@ include ../../make/defines.mk
TARGET1= mkfs.gfs2
TARGET2= gfs2_jadd
+TARGET3= gfs2_grow
OBJS= main.o \
main_mkfs.o \
+ main_grow.o \
main_jadd.o
CFLAGS += -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE
@@ -21,7 +23,7 @@ CFLAGS += -I../include/ -I../libgfs2/
LDFLAGS += -L${volidlibdir} -lvolume_id
LDFLAGS += -L../libgfs2 -lgfs2
-all: ${TARGET1} ${TARGET2}
+all: ${TARGET1} ${TARGET2} ${TARGET3}
${TARGET1}: ${OBJS}
$(CC) -o $@ $^ $(LDFLAGS)
@@ -29,16 +31,20 @@ ${TARGET1}: ${OBJS}
${TARGET2}: ${TARGET1}
ln -s ${TARGET1} ${TARGET2}
+${TARGET3}: ${TARGET1}
+ ln -s ${TARGET1} ${TARGET3}
+
%.o: %.c
$(CC) $(CFLAGS) -c -o $@ $^
install: all
install -m 0755 ${TARGET1} ${sbindir}
ln -f ${sbindir}/${TARGET1} ${sbindir}/${TARGET2}
+ ln -f ${sbindir}/${TARGET1} ${sbindir}/${TARGET3}
uninstall:
- ${UNINSTALL} ${TARGET1} ${TARGET2} ${sbindir}
+ ${UNINSTALL} ${TARGET1} ${TARGET2} ${TARGET3} ${sbindir}
clean:
- rm -f *.o ${TARGET1} ${TARGET2}
+ rm -f *.o ${TARGET1} ${TARGET2} ${TARGET3}
Index: mkfs/main_grow.c
===================================================================
RCS file: mkfs/main_grow.c
diff -N mkfs/main_grow.c
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ mkfs/main_grow.c 1 May 2007 20:06:13 -0000
@@ -0,0 +1,334 @@
+/******************************************************************************
+*******************************************************************************
+**
+** Copyright (C) 2007 Red Hat, Inc. All rights reserved.
+**
+** This copyrighted material is made available to anyone wishing to use,
+** modify, copy, or redistribute it subject to the terms and conditions
+** of the GNU General Public License v.2.
+**
+*******************************************************************************
+******************************************************************************/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdint.h>
+#include <inttypes.h>
+#include <sys/types.h>
+#include <dirent.h>
+#include <sys/stat.h>
+#include <sys/ioctl.h>
+#include <sys/file.h>
+#include <sys/vfs.h>
+#include <sys/mount.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <time.h>
+#include <errno.h>
+#include <stdarg.h>
+#include <linux/types.h>
+
+#include "libgfs2.h"
+#include "gfs2_mkfs.h"
+
+#define BUF_SIZE 4096
+#define MB (1024 * 1024)
+
+static uint64_t override_device_size = 0;
+static int test = 0;
+static uint64_t fssize = 0, fsgrowth;
+static unsigned int rgsize = 0;
+
+extern int create_new_inode(struct gfs2_sbd *sdp);
+extern int rename2system(struct gfs2_sbd *sdp, char *new_dir, char *new_name);
+
+/**
+ * usage - Print out the usage message
+ *
+ * This function does not include documentation for the -D option
+ * since normal users have no use for it at all. The -D option is
+ * only for developers. It intended use is in combination with the
+ * -T flag to find out what the result would be of trying different
+ * device sizes without actually having to try them manually.
+ */
+
+static void
+usage(void)
+{
+ fprintf(stdout,
+ "Usage:\n"
+ "\n"
+ "gfs2_grow [options] /path/to/filesystem\n"
+ "\n"
+ "Options:\n"
+ " -h Usage information\n"
+ " -q Quiet, reduce verbosity\n"
+ " -T Test, do everything except update FS\n"
+ " -V Version information\n"
+ " -v Verbose, increase verbosity\n");
+}
+
+void
+decode_arguments(int argc, char *argv[], struct gfs2_sbd *sdp)
+{
+ int opt;
+
+ while ((opt = getopt(argc, argv, "VD:hqTv?")) != EOF) {
+ switch (opt) {
+ case 'D': /* This option is for testing only */
+ override_device_size = atoi(optarg);
+ override_device_size <<= 20;
+ break;
+ case 'V':
+ printf("%s %s (built %s %s)\n", argv[0],
+ GFS2_RELEASE_NAME, __DATE__, __TIME__);
+ printf("%s\n", REDHAT_COPYRIGHT);
+ exit(0);
+ case 'h':
+ usage();
+ exit(0);
+ case 'q':
+ decrease_verbosity();
+ break;
+ case 'T':
+ test = 1;
+ break;
+ case 'v':
+ increase_verbosity();
+ break;
+ case ':':
+ case '?':
+ /* Unknown flag */
+ fprintf(stderr, "Please use '-h' for usage.\n");
+ exit(EXIT_FAILURE);
+ default:
+ fprintf(stderr, "Bad programmer! You forgot"
+ " to catch the %c flag\n", opt);
+ exit(EXIT_FAILURE);
+ break;
+ }
+ }
+
+ if (optind == argc) {
+ usage();
+ exit(EXIT_FAILURE);
+ }
+}
+
+/**
+ * figure_out_rgsize
+ */
+void figure_out_rgsize(struct gfs2_sbd *sdp, unsigned int *rgsize)
+{
+ osi_list_t *head = &sdp->rglist;
+ struct rgrp_list *r1, *r2;
+
+ sdp->rgsize = GFS2_DEFAULT_RGSIZE;
+ r1 = osi_list_entry(head->next->next, struct rgrp_list, list);
+ r2 = osi_list_entry(head->next->next->next, struct rgrp_list, list);
+
+ *rgsize = r2->ri.ri_addr - r1->ri.ri_addr;
+}
+
+/**
+ * filesystem_size - Calculate the size of the filesystem
+ *
+ * Reads the lists of resource groups in order to
+ * work out where the last block of the filesystem is located.
+ *
+ * Returns: The calculated size
+ */
+
+uint64_t
+filesystem_size(struct gfs2_sbd *sdp)
+{
+ osi_list_t *tmp;
+ struct rgrp_list *rgl;
+ uint64_t size = 0, extent;
+
+ tmp = &sdp->rglist;
+ for (;;) {
+ tmp = tmp->next;
+ if (tmp == &sdp->rglist)
+ break;
+ rgl = osi_list_entry(tmp, struct rgrp_list, list);
+ extent = rgl->ri.ri_addr + rgl->ri.ri_length + rgl->ri.ri_data;
+ if (extent > size)
+ size = extent;
+ }
+ return size;
+}
+
+/**
+ * initialize_new_portion - Write the new rg information to disk buffers.
+ */
+void initialize_new_portion(struct gfs2_sbd *sdp, int *old_rg_count)
+{
+ uint64_t rgrp = 0;
+ osi_list_t *head = &sdp->rglist;
+
+ *old_rg_count = 0;
+ /* Delete the old RGs from the rglist */
+ for (rgrp = 0; !osi_list_empty(head) &&
+ rgrp < (sdp->rgrps - sdp->new_rgrps); rgrp++) {
+ (*old_rg_count)++;
+ osi_list_del(head->next);
+ }
+ /* Build the remaining resource groups */
+ build_rgrps(sdp, TRUE);
+ /* We're done with the libgfs portion, so commit it to disk. */
+ /* Note: We do inode_put with not_updated because we only updated */
+ /* the new RGs/bitmaps themselves on disk. The rindex file must */
+ /* be updated through the meta_fs so the gfs2 kernel is informed. */
+ inode_put(sdp->md.riinode, not_updated);
+ inode_put(sdp->master_dir, not_updated);
+ bsync(sdp);
+}
+
+/**
+ * fix_rindex - Add the new entries to the end of the rindex file.
+ */
+void fix_rindex(struct gfs2_sbd *sdp, int rindex_fd, int old_rg_count)
+{
+ int count, rg;
+ struct rgrp_list *rl;
+ char *buf;
+ osi_list_t *tmp;
+
+ zalloc(buf, sdp->bsize);
+ if (!buf)
+ die("Unable to allocate memory for buffers.\n");
+ /* Now add the new rg entries to the rg index. Here we */
+ /* need to use the gfs2 kernel code rather than the libgfs2 */
+ /* code so we have a live update while mounted. */
+ lseek(rindex_fd, 0, SEEK_END);
+ /* Now write the new RGs to the rindex */
+ rg = old_rg_count;
+ osi_list_foreach(tmp, &sdp->rglist) {
+ rg++;
+ rl = osi_list_entry(tmp, struct rgrp_list, list);
+ gfs2_rindex_out(&rl->ri, buf);
+ count = write(rindex_fd, buf, sizeof(struct gfs2_rindex));
+ if (count != sizeof(struct gfs2_rindex)) {
+ log_crit("Error writing rindex entry #%d; aborted.\n",
+ rg);
+ break;
+ }
+ }
+ fsync(rindex_fd);
+ free(buf);
+}
+
+/**
+ * print_info - Print out various bits of (interesting?) information
+ *
+ */
+static void print_info(struct gfs2_sbd *sdp)
+{
+ log_notice("FS: Mount Point: %s\n", sdp->path_name);
+ log_notice("FS: Device: %s\n", sdp->device_name);
+ log_notice("FS: Size: %" PRIu64 " (0x%" PRIx64 ")\n",
+ fssize, fssize);
+ log_notice("FS: RG size: %u (0x%x)\n", rgsize, rgsize);
+ log_notice("DEV: Size: %"PRIu64" (0x%" PRIx64")\n",
+ sdp->device.length, sdp->device.length);
+ log_notice("The file system grew by %" PRIu64 "MB.\n",
+ fsgrowth / MB);
+}
+
+/**
+ * main_grow - do everything
+ * @argc:
+ * @argv:
+ */
+void
+main_grow(int argc, char *argv[])
+{
+ struct gfs2_sbd sbd, *sdp = &sbd;
+ int rgcount, i, rindex_fd;
+ char rindex_name[PATH_MAX];
+
+ memset(sdp, 0, sizeof(struct gfs2_sbd));
+ sdp->bsize = GFS2_DEFAULT_BSIZE;
+ sdp->rgsize = -1;
+ sdp->jsize = GFS2_DEFAULT_JSIZE;
+ sdp->qcsize = GFS2_DEFAULT_QCSIZE;
+ sdp->md.journals = 1;
+ decode_arguments(argc, argv, sdp);
+
+ while ((argc - optind) > 0) {
+ sdp->path_name = argv[optind++];
+ sdp->path_fd = open(sdp->path_name, O_RDONLY);
+ if (sdp->path_fd < 0)
+ die("can't open root directory %s: %s\n",
+ sdp->path_name, strerror(errno));
+
+ check_for_gfs2(sdp);
+ sdp->device_fd = open(sdp->device_name, O_RDWR);
+ if (sdp->device_fd < 0)
+ die("can't open device %s: %s\n",
+ sdp->device_name, strerror(errno));
+ device_geometry(sdp);
+ fix_device_geometry(sdp);
+ log_info("Initializing lists...\n");
+ osi_list_init(&sdp->rglist);
+ osi_list_init(&sdp->buf_list);
+ for(i = 0; i < BUF_HASH_SIZE; i++)
+ osi_list_init(&sdp->buf_hash[i]);
+
+ sdp->sd_sb.sb_bsize = GFS2_DEFAULT_BSIZE;
+ sdp->bsize = sdp->sd_sb.sb_bsize;
+ compute_constants(sdp);
+ if(read_sb(sdp) < 0)
+ die("gfs: Error reading superblock.\n");
+
+ if (!find_gfs2_meta(sdp))
+ mount_gfs2_meta(sdp);
+ lock_for_admin(sdp);
+
+ sprintf(rindex_name, "%s/rindex", sdp->metafs_path);
+ rindex_fd = open(rindex_name, O_RDWR);
+ if (rindex_fd < 0) {
+ cleanup_metafs(sdp);
+ die("GFS2 rindex not found. Please run gfs2_fsck.\n");
+ }
+ /* Get master dinode */
+ sdp->master_dir =
+ gfs2_load_inode(sdp, sdp->sd_sb.sb_master_dir.no_addr);
+ gfs2_lookupi(sdp->master_dir, "rindex", 6, &sdp->md.riinode);
+
+ /* Fetch the rindex from disk. This uses the gfs2 kernel, */
+ /* to get the latest cached data, but the bitmaps will use */
+ /* libgfs2 and not the gfs2 kernel. Therefore, the bitmaps */
+ /* may be out of date. However, it shouldn't matter because */
+ /* 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);
+ fssize = filesystem_size(sdp);
+ figure_out_rgsize(sdp, &rgsize);
+ fsgrowth = ((sdp->device.length - fssize) * sdp->bsize);
+ if (fsgrowth < rgsize * sdp->bsize) {
+ log_err("Error: The device has grown by less than "
+ "one Resource Group (RG).\n");
+ log_err("The device grew by %" PRIu64 "MB. ",
+ fsgrowth / MB);
+ log_err("One RG is %uMB for this file system.\n",
+ (rgsize * sdp->bsize) / MB);
+ }
+ else {
+ int old_rg_count;
+
+ compute_rgrp_layout(sdp, TRUE);
+ print_info(sdp);
+ initialize_new_portion(sdp, &old_rg_count);
+ fix_rindex(sdp, rindex_fd, old_rg_count);
+ }
+ close(rindex_fd);
+ cleanup_metafs(sdp);
+ close(sdp->device_fd);
+ }
+ close(sdp->path_fd);
+ sync();
+ log_notice("gfs2_grow complete.\n");
+}
Index: mkfs/main_jadd.c
===================================================================
RCS file: /cvs/cluster/cluster/gfs2/mkfs/main_jadd.c,v
retrieving revision 1.10
diff -w -u -p -p -u -r1.10 main_jadd.c
--- mkfs/main_jadd.c 26 Oct 2006 18:42:25 -0000 1.10
+++ mkfs/main_jadd.c 1 May 2007 20:06:13 -0000
@@ -1,3 +1,14 @@
+/*****************************************************************************
+******************************************************************************
+**
+** Copyright (C) 2006-2007 Red Hat, Inc. All rights reserved.
+**
+** This copyrighted material is made available to anyone wishing to use,
+** modify, copy, or redistribute it subject to the terms and conditions
+** of the GNU General Public License v.2.
+**
+******************************************************************************
+*****************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -23,15 +34,6 @@
#define BUF_SIZE 4096
-static char device_name[PATH_MAX];
-static char fspath[BUF_SIZE];
-static char fsoptions[BUF_SIZE];
-static char metafs_path[BUF_SIZE];
-static char lock_table[PATH_MAX];
-static char meta_mount[PATH_MAX] = "/tmp/.gfs2meta";
-static int metafs_fd;
-static int metafs_mounted = 0; /* If metafs was already mounted */
-
void
make_jdata(int fd, char *value)
{
@@ -56,45 +58,18 @@ rename2system(struct gfs2_sbd *sdp, char
char oldpath[PATH_MAX], newpath[PATH_MAX];
int error = 0;
error = snprintf(oldpath, PATH_MAX, "%s/new_inode",
- metafs_path);
+ sdp->metafs_path);
if (error >= PATH_MAX)
die("rename2system (1)\n");
error = snprintf(newpath, PATH_MAX, "%s/%s/%s",
- metafs_path, new_dir, new_name);
+ sdp->metafs_path, new_dir, new_name);
if (error >= PATH_MAX)
die("rename2system (2)\n");
return rename(oldpath, newpath);
}
-void
-lock_for_admin(struct gfs2_sbd *sdp)
-{
- int error;
-
- if (sdp->debug)
- printf("\nTrying to get admin lock...\n");
-
- for (;;) {
-
- metafs_fd = open(metafs_path, O_RDONLY | O_NOFOLLOW);
- if (metafs_fd < 0)
- die("can't open %s: %s\n",
- metafs_path, strerror(errno));
-
- error = flock(metafs_fd, LOCK_EX);
- if (error)
- die("can't flock %s: %s\n", metafs_path,
- strerror(errno));
-
- break;
- }
-
- if (sdp->debug)
- printf("Got it.\n");
-}
-
/**
* print_usage - print out usage information
*
@@ -238,7 +213,7 @@ create_new_inode(struct gfs2_sbd *sdp)
int fd;
int error;
- error = snprintf(name, PATH_MAX, "%s/new_inode", metafs_path);
+ error = snprintf(name, PATH_MAX, "%s/new_inode", sdp->metafs_path);
if (error >= PATH_MAX)
die("create_new_inode (1)\n");
@@ -377,7 +352,8 @@ read_superblock(struct gfs2_sbd *sdp)
gfs2_sb_in(&(sdp->sd_sb), buf);
sdp->bsize = sdp->sd_sb.sb_bsize;
strcpy(lock_table,sdp->sd_sb.sb_locktable);
- sprintf(meta_mount, "%s%s%s", "/sys/fs/gfs2/", lock_table, "/meta");
+ sprintf(sdp->meta_mount, "%s%s%s", "/sys/fs/gfs2/", lock_table,
+ "/meta");
close(fd);
}
@@ -408,7 +384,7 @@ find_current_journals(struct gfs2_sbd *s
DIR *dirp;
int existing_journals = 0;
- sprintf(jindex, "%s/jindex", metafs_path);
+ sprintf(jindex, "%s/jindex", sdp->metafs_path);
dirp = opendir(jindex);
if (!dirp) {
die("Could not find the jindex directory "
@@ -491,139 +467,6 @@ add_j(struct gfs2_sbd *sdp)
new_name, error, strerror(errno));
}
-static int
-find_gfs2_meta(struct gfs2_sbd *sdp)
-{
- FILE *fp = fopen("/proc/mounts", "r");
- char name[] = "gfs2meta";
- char buffer[BUF_SIZE];
- char fstype[80], mfsoptions[BUF_SIZE];
- char meta_device[BUF_SIZE];
- int fsdump, fspass;
-
- if (fp == NULL) {
- perror("open: /proc/mounts");
- exit(EXIT_FAILURE);
- }
- while ((fgets(buffer, 4095, fp)) != NULL) {
- buffer[4095] = 0;
- if (strstr(buffer, name) == 0)
- continue;
-
- if (sscanf(buffer, "%s %s %s %s %d %d", meta_device,
- metafs_path, fstype,mfsoptions, &fsdump,
- &fspass) != 6)
- continue;
-
- if (strcmp(meta_device, sdp->device_name) != 0
- && strcmp(meta_device, sdp->path_name) != 0)
- continue;
-
- metafs_mounted = 1;
-
- fclose(fp);
- return TRUE;
- }
- fclose(fp);
- return FALSE;
-}
-
-static int
-dir_exists(const char *dir)
-{
- int fd, ret;
- struct stat statbuf;
- fd = open(dir, O_RDONLY);
- if (fd<0) {
- if (errno == ENOENT)
- return 0;
- die("Couldn't open %s : %s\n", dir, strerror(errno));
- }
- ret = fstat(fd, &statbuf);
- if (ret)
- die("stat failed on %s : %s\n", dir, strerror(errno));
- if (S_ISDIR(statbuf.st_mode)) {
- close(fd);
- return 1;
- }
- close(fd);
- die("%s exists, but is not a directory. Cannot mount metafs here\n", dir);
-}
-
-static void
-mount_gfs2_meta(struct gfs2_sbd *sdp)
-{
- int ret;
- /* mount the meta fs */
- if (!dir_exists(meta_mount)) {
- ret = mkdir(meta_mount, 0700);
- if (ret)
- die("Couldn't create %s : %s\n", meta_mount,
- strerror(errno));
- }
-
- ret = mount(sdp->device_name, meta_mount, "gfs2meta", 0, NULL);
- if (ret)
- die("Couldn't mount %s : %s\n", meta_mount,
- strerror(errno));
- strcpy(metafs_path, meta_mount);
-}
-
-static void
-check_for_gfs2(struct gfs2_sbd *sdp)
-{
- FILE *fp = fopen("/proc/mounts", "r");
- char *name = sdp->path_name;
- char buffer[BUF_SIZE];
- char fstype[80];
- int fsdump, fspass, ret;
-
- if (name[strlen(name) - 1] == '/')
- name[strlen(name) - 1] = '\0';
-
- if (fp == NULL) {
- perror("open: /proc/mounts");
- exit(EXIT_FAILURE);
- }
- while ((fgets(buffer, 4095, fp)) != NULL) {
- buffer[4095] = 0;
-
- if (strstr(buffer, "0") == 0)
- continue;
-
- if ((ret = sscanf(buffer, "%s %s %s %s %d %d", device_name, fspath,
- fstype, fsoptions, &fsdump, &fspass)) != 6)
- continue;
- sdp->device_name = device_name;
-
- if (strcmp(fstype, "gfs2") != 0)
- continue;
-
- if (strcmp(fspath, name) != 0)
- continue;
-
- fclose(fp);
- if (strncmp(device_name, "/dev/loop", 9) == 0)
- die("Cannot add journal(s) to a loopback GFS mount\n");
-
- return;
- }
- fclose(fp);
- die("gfs2 Filesystem %s not found\n", name);
-}
-
-static void
-cleanup(struct gfs2_sbd *sdp)
-{
- int ret;
- if (!metafs_mounted) { /* was mounted by us */
- ret = umount(meta_mount);
- if (ret)
- fprintf(stderr, "Couldn't unmount %s : %s\n", meta_mount,
- strerror(errno));
- }
-}
-
/**
* main_jadd - do everything
* @argc:
@@ -654,7 +497,8 @@ main_jadd(int argc, char *argv[])
gather_info(sdp);
- if (!find_gfs2_meta(sdp))
+ find_gfs2_meta(sdp);
+ if (!sdp->metafs_mounted)
mount_gfs2_meta(sdp);
lock_for_admin(sdp);
@@ -671,12 +515,8 @@ main_jadd(int argc, char *argv[])
add_j(sdp);
}
- close(metafs_fd);
close(sdp->path_fd);
-
- cleanup(sdp);
-
+ cleanup_metafs(sdp);
sync();
-
print_results(sdp);
}
Index: mkfs/main_mkfs.c
===================================================================
RCS file: /cvs/cluster/cluster/gfs2/mkfs/main_mkfs.c,v
retrieving revision 1.12
diff -w -u -p -p -u -r1.12 main_mkfs.c
--- mkfs/main_mkfs.c 1 May 2007 16:43:39 -0000 1.12
+++ mkfs/main_mkfs.c 1 May 2007 20:06:13 -0000
@@ -86,7 +86,7 @@ decode_arguments(int argc, char *argv[],
int cont = TRUE;
int optchar;
- sdp->device_name = NULL;
+ memset(sdp->device_name, 0, sizeof(sdp->device_name));
sdp->md.journals = 1;
strcpy(sdp->lockproto, "lock_nolock");
@@ -169,10 +169,10 @@ decode_arguments(int argc, char *argv[],
case 1:
if (strcmp(optarg, "gfs2") == 0)
continue;
- if (sdp->device_name) {
+ if (sdp->device_name[0]) {
die("More than one device specified (try -h for help)");
}
- sdp->device_name = optarg;
+ strcpy(sdp->device_name, optarg);
break;
default:
@@ -181,11 +181,10 @@ decode_arguments(int argc, char *argv[],
};
}
- if ((sdp->device_name == NULL) && (optind < argc)) {
- sdp->device_name = argv[optind++];
- }
+ if ((sdp->device_name[0] == 0) && (optind < argc))
+ strcpy(sdp->device_name, argv[optind++]);
- if (sdp->device_name == NULL)
+ if (sdp->device_name[0] == '\0')
die("no device specified (try -h for help)\n");
if (optind < argc)
@@ -264,8 +263,7 @@ static void are_you_sure(struct gfs2_sbd
die("error identifying the contents of %s: %s\n",
sdp->device_name, strerror(errno));
- printf("This will destroy any data on %s.\n",
- sdp->device_name);
+ printf("This will destroy any data on %s.\n", sdp->device_name);
if (volume_id_probe_all(vid, 0, sdp->device_size) == 0)
printf(" It appears to contain a %s %s.\n", vid->type,
vid->usage_id == VOLUME_ID_OTHER? "partition" : vid->usage);
Index: quota/check.c
===================================================================
RCS file: /cvs/cluster/cluster/gfs2/quota/check.c,v
retrieving revision 1.3
diff -w -u -p -p -u -r1.3 check.c
--- quota/check.c 1 Dec 2006 21:28:06 -0000 1.3
+++ quota/check.c 1 May 2007 20:06:13 -0000
@@ -2,7 +2,7 @@
*******************************************************************************
**
** Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
-** Copyright (C) 2004 Red Hat, Inc. All rights reserved.
+** Copyright (C) 2004-2007 Red Hat, Inc. All rights reserved.
**
** This copyrighted material is made available to anyone wishing to use,
** modify, copy, or redistribute it subject to the terms and conditions
@@ -180,10 +180,10 @@ scan_fs(dev_t device, char *dirname,
*
*/
static void
-read_quota_file(commandline_t *comline, osi_list_t *uid, osi_list_t *gid)
+read_quota_file(struct gfs2_sbd *sdp, commandline_t *comline,
+ osi_list_t *uid, osi_list_t *gid)
{
int fd;
- struct gfs2_sb sb;
char buf[sizeof(struct gfs2_quota)];
struct gfs2_quota q;
uint64_t offset = 0;
@@ -191,11 +191,11 @@ read_quota_file(commandline_t *comline,
int error;
char quota_file[BUF_SIZE];
- check_for_gfs2(comline->filesystem);
- read_superblock(&sb);
- if (!find_gfs2_meta(comline->filesystem))
- mount_gfs2_meta();
- lock_for_admin();
+ check_for_gfs2(sdp);
+ read_superblock(&sdp->sd_sb);
+ if (!find_gfs2_meta(sdp))
+ mount_gfs2_meta(sdp);
+ lock_for_admin(sdp);
strcpy(quota_file, metafs_path);
strcat(quota_file, "/quota");
@@ -224,7 +224,7 @@ read_quota_file(commandline_t *comline,
gfs2_quota_in(&q, buf);
id = (offset / sizeof(struct gfs2_quota)) >> 1;
- q.qu_value <<= sb.sb_bsize_shift - 9;
+ q.qu_value <<= sdp->sd_sb.sb_bsize_shift - 9;
if (q.qu_value) {
if (id * sizeof(struct gfs2_quota) * 2 == offset)
@@ -383,7 +383,7 @@ verify_pathname(commandline_t *comline)
*/
void
-do_check(commandline_t *comline)
+do_check(struct gfs2_sbd *sdp, commandline_t *comline)
{
dev_t device;
osi_list_t fs_uid, fs_gid, qf_uid, qf_gid;
@@ -399,7 +399,7 @@ do_check(commandline_t *comline)
device = verify_pathname(comline);
scan_fs(device, comline->filesystem, &fs_uid, &fs_gid, &hl);
- read_quota_file(comline, &qf_uid, &qf_gid);
+ read_quota_file(sdp, comline, &qf_uid, &qf_gid);
print_list("fs user ", &fs_uid);
print_list("fs group", &fs_gid);
@@ -423,10 +423,10 @@ do_check(commandline_t *comline)
*/
static void
-set_list(commandline_t *comline, int user, osi_list_t *list, int64_t multiplier)
+set_list(struct gfs2_sbd *sdp, commandline_t *comline, int user,
+ osi_list_t *list, int64_t multiplier)
{
int fd, fd1;
- struct gfs2_sb sb;
osi_list_t *tmp;
values_t *v;
uint64_t offset;
@@ -435,11 +435,11 @@ set_list(commandline_t *comline, int use
char quota_file[BUF_SIZE];
char sys_q_refresh[BUF_SIZE];
- check_for_gfs2(comline->filesystem);
- read_superblock(&sb);
- if (!find_gfs2_meta(comline->filesystem))
- mount_gfs2_meta();
- lock_for_admin();
+ check_for_gfs2(sdp);
+ read_superblock(&sdp->sd_sb);
+ if (!find_gfs2_meta(sdp))
+ mount_gfs2_meta(sdp);
+ lock_for_admin(sdp);
strcpy(quota_file, metafs_path);
strcat(quota_file, "/quota");
@@ -460,7 +460,7 @@ set_list(commandline_t *comline, int use
offset += (unsigned long)(&((struct gfs2_quota *)NULL)->qu_value);
value = v->v_blocks * multiplier;
- value >>= sb.sb_bsize_shift - 9;
+ value >>= sdp->sd_sb.sb_bsize_shift - 9;
value = cpu_to_be64(value);
lseek(fd, offset, SEEK_SET);
@@ -472,8 +472,10 @@ set_list(commandline_t *comline, int use
}
/* Write "1" to sysfs quota refresh file to refresh gfs quotas */
- sprintf(sys_q_refresh, "%s%s%s", "/sys/fs/gfs2/", sb.sb_locktable,
- (user) ? "/quota_refresh_user" : "/quota_refresh_group");
+ 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) {
@@ -503,7 +505,7 @@ out:
*/
void
-do_quota_init(commandline_t *comline)
+do_quota_init(struct gfs2_sbd *sdp, commandline_t *comline)
{
dev_t device;
osi_list_t fs_uid, fs_gid, qf_uid, qf_gid;
@@ -519,7 +521,7 @@ do_quota_init(commandline_t *comline)
device = verify_pathname(comline);
scan_fs(device, comline->filesystem, &fs_uid, &fs_gid, &hl);
- read_quota_file(comline, &qf_uid, &qf_gid);
+ read_quota_file(sdp, comline, &qf_uid, &qf_gid);
type_zalloc(v, values_t, 1);
v->v_id = 0;
@@ -536,12 +538,12 @@ do_quota_init(commandline_t *comline)
print_list("qf user ", &qf_uid);
print_list("qf group", &qf_gid);
- set_list(comline, TRUE, &qf_uid, 0);
- set_list(comline, FALSE, &qf_gid, 0);
- set_list(comline, TRUE, &fs_uid, 1);
- set_list(comline, FALSE, &fs_gid, 1);
+ set_list(sdp, comline, TRUE, &qf_uid, 0);
+ set_list(sdp, comline, FALSE, &qf_gid, 0);
+ set_list(sdp, comline, TRUE, &fs_uid, 1);
+ set_list(sdp, comline, FALSE, &fs_gid, 1);
- do_sync(comline);
+ do_sync(sdp, comline);
- do_check(comline);
+ do_check(sdp, comline);
}
Index: quota/gfs2_quota.h
===================================================================
RCS file: /cvs/cluster/cluster/gfs2/quota/gfs2_quota.h,v
retrieving revision 1.2
diff -w -u -p -p -u -r1.2 gfs2_quota.h
--- quota/gfs2_quota.h 1 Dec 2006 21:28:06 -0000 1.2
+++ quota/gfs2_quota.h 1 May 2007 20:06:13 -0000
@@ -2,7 +2,7 @@
*******************************************************************************
**
** Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
-** Copyright (C) 2004 Red Hat, Inc. All rights reserved.
+** Copyright (C) 2004-2007 Red Hat, Inc. All rights reserved.
**
** This copyrighted material is made available to anyone wishing to use,
** modify, copy, or redistribute it subject to the terms and conditions
@@ -98,19 +98,17 @@ extern char *prog_name;
/* main.c */
-void check_for_gfs2(const char *path);
void do_get_super(int fd, struct gfs2_sb *sb);
-void do_sync(commandline_t *comline);
+void do_sync(struct gfs2_sbd *sdp, commandline_t *comline);
void lock_for_admin();
-int find_gfs2_meta(const char *mnt);
void mount_gfs2_meta();
void cleanup();
void read_superblock(struct gfs2_sb *sb);
/* check.c */
-void do_check(commandline_t *comline);
-void do_quota_init(commandline_t *comline);
+void do_check(struct gfs2_sbd *sdp, commandline_t *comline);
+void do_quota_init(struct gfs2_sbd *sdp, commandline_t *comline);
/* names.c */
Index: quota/main.c
===================================================================
RCS file: /cvs/cluster/cluster/gfs2/quota/main.c,v
retrieving revision 1.3
diff -w -u -p -p -u -r1.3 main.c
--- quota/main.c 1 Dec 2006 21:28:06 -0000 1.3
+++ quota/main.c 1 May 2007 20:06:13 -0000
@@ -2,7 +2,7 @@
*******************************************************************************
**
** Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
-** Copyright (C) 2004 Red Hat, Inc. All rights reserved.
+** Copyright (C) 2004-2007 Red Hat, Inc. All rights reserved.
**
** This copyrighted material is made available to anyone wishing to use,
** modify, copy, or redistribute it subject to the terms and conditions
@@ -93,13 +93,6 @@ print_usage()
}
/**
- * 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
- *
- */
-
-/**
* decode_arguments - parse command line arguments
* @argc: well, it's argc...
* @argv: well, it's argv...
@@ -287,107 +280,6 @@ print_quota(commandline_t *comline,
}
void
-lock_for_admin()
-{
- int error;
-
- for (;;) {
-
- metafs_fd = open(metafs_path, O_RDONLY | O_NOFOLLOW);
- if (metafs_fd < 0)
- die("can't open %s: %s\n",
- metafs_path, strerror(errno));
-
- error = flock(metafs_fd, LOCK_EX);
- if (error)
- die("can't flock %s: %s\n", metafs_path,
- strerror(errno));
-
- break;
- }
-}
-
-int
-find_gfs2_meta(const char *mnt)
-{
- FILE *fp = fopen("/proc/mounts", "r");
- char name[] = "gfs2meta";
- char buffer[BUF_SIZE];
- char fstype[80], mfsoptions[BUF_SIZE];
- char meta_device[BUF_SIZE];
- int fsdump, fspass;
-
- metafs_mounted = 0;
-
- if (fp == NULL) {
- perror("open: /proc/mounts");
- exit(EXIT_FAILURE);
- }
- while ((fgets(buffer, 4095, fp)) != NULL) {
- buffer[4095] = 0;
- if (strstr(buffer, name) == 0)
- continue;
-
- if (sscanf(buffer, "%s %s %s %s %d %d", meta_device,
- metafs_path, fstype,mfsoptions, &fsdump,
- &fspass) != 6)
- continue;
-
- if (strcmp(meta_device, device_name) != 0
- && strcmp(meta_device, mnt) != 0)
- continue;
-
- metafs_mounted = 1;
-
- fclose(fp);
- return TRUE;
- }
- fclose(fp);
- return FALSE;
-}
-
-static int
-dir_exists(const char *dir)
-{
- int fd, ret;
- struct stat statbuf;
- fd = open(dir, O_RDONLY);
- if (fd<0) {
- if (errno == ENOENT)
- return 0;
- die("Couldn't open %s : %s\n", dir, strerror(errno));
- }
- ret = fstat(fd, &statbuf);
- if (ret)
- die("stat failed on %s : %s\n", dir, strerror(errno));
- if (S_ISDIR(statbuf.st_mode)) {
- close(fd);
- return 1;
- }
- close(fd);
- die("%s exists, but is not a directory. Cannot mount metafs here\n", dir);
-}
-
-void
-mount_gfs2_meta()
-{
- int ret;
- /* mount the meta fs */
- if (!dir_exists(meta_mount)) {
- ret = mkdir(meta_mount, 0700);
- if (ret)
- die("Couldn't create %s : %s\n", meta_mount,
- strerror(errno));
- }
-
- ret = mount(device_name, meta_mount, "gfs2meta", 0, NULL);
- if (ret)
- die("Couldn't mount %s : %s\n", meta_mount,
- strerror(errno));
- strcpy(metafs_path, meta_mount);
-}
-
-void
cleanup()
{
int ret;
@@ -400,44 +292,6 @@ cleanup()
}
void
-check_for_gfs2(const char *mnt)
-{
- FILE *fp = fopen("/proc/mounts", "r");
- char buffer[4096];
- char fstype[80];
- int fsdump, fspass, ret;
-
- if (fp == NULL) {
- perror("open: /proc/mounts");
- exit(EXIT_FAILURE);
- }
- while ((fgets(buffer, 4095, fp)) != NULL) {
- buffer[4095] = 0;
-
- if (strstr(buffer, "0") == 0)
- continue;
-
- if ((ret = sscanf(buffer, "%s %s %s %s %d %d", device_name, fspath,
- fstype, fsoptions, &fsdump, &fspass)) != 6)
- continue;
-
- if (strcmp(fstype, "gfs2") != 0)
- continue;
-
- if (strcmp(fspath, mnt) != 0)
- continue;
-
- fclose(fp);
- if (strncmp(device_name, "/dev/loop", 9) == 0)
- die("Cannot add journal(s) to a loopback GFS mount\n");
-
- return;
- }
- fclose(fp);
- die("gfs2 Filesystem %s not found\n", mnt);
-}
-
-void
read_superblock(struct gfs2_sb *sb)
{
int fd;
@@ -462,10 +316,9 @@ read_superblock(struct gfs2_sb *sb)
*/
static void
-do_list(commandline_t *comline)
+do_list(struct gfs2_sbd *sdp, commandline_t *comline)
{
int fd;
- struct gfs2_sb sb;
struct gfs2_quota q;
char buf[sizeof(struct gfs2_quota)];
uint64_t offset;
@@ -477,11 +330,11 @@ do_list(commandline_t *comline)
if (!*comline->filesystem)
die("need a filesystem to work on\n");
- check_for_gfs2(comline->filesystem);
- read_superblock(&sb);
- if (!find_gfs2_meta(comline->filesystem))
- mount_gfs2_meta();
- lock_for_admin();
+ check_for_gfs2(sdp);
+ read_superblock(&sdp->sd_sb);
+ if (!find_gfs2_meta(sdp))
+ mount_gfs2_meta(sdp);
+ lock_for_admin(sdp);
strcpy(quota_file, metafs_path);
strcat(quota_file, "/quota");
@@ -512,7 +365,7 @@ do_list(commandline_t *comline)
if (q.qu_limit || q.qu_warn || q.qu_value)
print_quota(comline, (pass) ? FALSE : TRUE, id,
- &q, &sb);
+ &q, &sdp->sd_sb);
offset += 2 * sizeof(struct gfs2_quota);
} while (error == sizeof(struct gfs2_quota));
@@ -531,21 +384,20 @@ do_list(commandline_t *comline)
*/
static void
-do_get_one(commandline_t *comline, char *filesystem)
+do_get_one(struct gfs2_sbd *sdp, commandline_t *comline, char *filesystem)
{
int fd;
char buf[256];
struct gfs2_quota q;
- struct gfs2_sb sb;
uint64_t offset;
int error;
char quota_file[BUF_SIZE];
- check_for_gfs2(filesystem);
- read_superblock(&sb);
- if (!find_gfs2_meta(filesystem))
- mount_gfs2_meta();
- lock_for_admin();
+ check_for_gfs2(sdp);
+ read_superblock(&sdp->sd_sb);
+ if (!find_gfs2_meta(sdp))
+ mount_gfs2_meta(sdp);
+ lock_for_admin(sdp);
strcpy(quota_file, metafs_path);
strcat(quota_file, "/quota");
@@ -580,7 +432,7 @@ do_get_one(commandline_t *comline, char
print_quota(comline,
(comline->id_type == GQ_ID_USER), comline->id,
- &q, &sb);
+ &q, &sdp->sd_sb);
close(fd);
close(metafs_fd);
@@ -594,12 +446,12 @@ do_get_one(commandline_t *comline, char
*/
static void
-do_get(commandline_t *comline)
+do_get(struct gfs2_sbd *sdp, commandline_t *comline)
{
int first = TRUE;
if (*comline->filesystem)
- do_get_one(comline, comline->filesystem);
+ do_get_one(sdp, comline, comline->filesystem);
else {
char buf[256], device[256], path[256], type[256];
FILE *file;
@@ -620,7 +472,7 @@ do_get(commandline_t *comline)
printf("\n");
printf("%s\n", path);
- do_get_one(comline, path);
+ do_get_one(sdp, comline, path);
}
fclose(file);
@@ -633,16 +485,15 @@ do_get(commandline_t *comline)
*
*/
static void
-do_sync_one(char *filesystem)
+do_sync_one(struct gfs2_sbd *sdp, char *filesystem)
{
int fd;
- struct gfs2_sb sb;
char sys_quota_sync[PATH_MAX];
- check_for_gfs2(filesystem);
- read_superblock(&sb);
+ check_for_gfs2(sdp);
+ read_superblock(&sdp->sd_sb);
sprintf(sys_quota_sync, "%s%s%s",
- "/sys/fs/gfs2/", sb.sb_locktable, "/quota_sync");
+ "/sys/fs/gfs2/", sdp->sd_sb.sb_locktable, "/quota_sync");
fd = open(sys_quota_sync, O_WRONLY);
if (fd < 0)
@@ -662,12 +513,12 @@ do_sync_one(char *filesystem)
*/
void
-do_sync(commandline_t *comline)
+do_sync(struct gfs2_sbd *sdp, commandline_t *comline)
{
sync();
if (*comline->filesystem)
- do_sync_one(comline->filesystem);
+ do_sync_one(sdp, comline->filesystem);
else {
char buf[256], device[256], path[256], type[256];
FILE *file;
@@ -682,7 +533,7 @@ do_sync(commandline_t *comline)
if (strcmp(type, "gfs2") != 0)
continue;
- do_sync_one(path);
+ do_sync_one(sdp, path);
}
fclose(file);
@@ -696,11 +547,10 @@ do_sync(commandline_t *comline)
*/
static void
-do_set(commandline_t *comline)
+do_set(struct gfs2_sbd *sdp, commandline_t *comline)
{
int fd, fd1;
uint64_t offset;
- struct gfs2_sb sb;
uint64_t new_value;
int error;
char quota_file[BUF_SIZE];
@@ -711,11 +561,11 @@ do_set(commandline_t *comline)
if (!comline->new_value_set)
die("need a new value\n");
- check_for_gfs2(comline->filesystem);
- read_superblock(&sb);
- if (!find_gfs2_meta(comline->filesystem))
- mount_gfs2_meta();
- lock_for_admin();
+ check_for_gfs2(sdp);
+ read_superblock(&sdp->sd_sb);
+ if (!find_gfs2_meta(sdp))
+ mount_gfs2_meta(sdp);
+ lock_for_admin(sdp);
strcpy(quota_file, metafs_path);
strcat(quota_file, "/quota");
@@ -758,14 +608,16 @@ do_set(commandline_t *comline)
switch (comline->units) {
case GQ_UNITS_MEGABYTE:
- new_value = comline->new_value << (20 - sb.sb_bsize_shift);
+ new_value =
+ comline->new_value << (20 - sdp->sd_sb.sb_bsize_shift);
break;
case GQ_UNITS_KILOBYTE:
- if (sb.sb_bsize == 512)
+ if (sdp->sd_sb.sb_bsize == 512)
new_value = comline->new_value * 2;
else
- new_value = comline->new_value >> (sb.sb_bsize_shift - 10);
+ new_value = comline->new_value >>
+ (sdp->sd_sb.sb_bsize_shift - 10);
break;
case GQ_UNITS_FSBLOCK:
@@ -773,7 +625,8 @@ do_set(commandline_t *comline)
break;
case GQ_UNITS_BASICBLOCK:
- new_value = comline->new_value >> (sb.sb_bsize_shift - 9);
+ new_value = comline->new_value >>
+ (sdp->sd_sb.sb_bsize_shift - 9);
break;
default:
@@ -792,7 +645,8 @@ do_set(commandline_t *comline)
}
/* Write "1" to sysfs quota refresh file to refresh gfs quotas */
- sprintf(sys_q_refresh, "%s%s%s", "/sys/fs/gfs2/", sb.sb_locktable,
+ 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");
@@ -827,41 +681,44 @@ out:
int
main(int argc, char *argv[])
{
+ struct gfs2_sbd sbd, *sdp = &sbd;
commandline_t comline;
prog_name = argv[0];
metafs_mounted = 0;
+ memset(sdp, 0, sizeof(struct gfs2_sbd));
memset(&comline, 0, sizeof(commandline_t));
decode_arguments(argc, argv, &comline);
+ strcpy(sdp->path_name, comline.filesystem);
switch (comline.operation) {
case GQ_OP_LIST:
- do_list(&comline);
+ do_list(sdp, &comline);
break;
case GQ_OP_GET:
- do_get(&comline);
+ do_get(sdp, &comline);
break;
case GQ_OP_LIMIT:
case GQ_OP_WARN:
- do_set(&comline);
+ do_set(sdp, &comline);
break;
case GQ_OP_SYNC:
- do_sync(&comline);
+ do_sync(sdp, &comline);
break;
case GQ_OP_CHECK:
- do_sync(&comline);
- do_check(&comline);
+ do_sync(sdp, &comline);
+ do_check(sdp, &comline);
break;
case GQ_OP_INIT:
- do_sync(&comline);
- do_quota_init(&comline);
+ do_sync(sdp, &comline);
+ do_quota_init(sdp, &comline);
break;
default:
@@ -869,7 +726,7 @@ main(int argc, char *argv[])
comline.id_type = GQ_ID_USER;
comline.id = geteuid();
}
- do_get(&comline);
+ do_get(sdp, &comline);
break;
}
Index: tool/gfs2_tool.h
===================================================================
RCS file: /cvs/cluster/cluster/gfs2/tool/gfs2_tool.h,v
retrieving revision 1.5
diff -w -u -p -p -u -r1.5 gfs2_tool.h
--- tool/gfs2_tool.h 13 Oct 2005 16:39:19 -0000 1.5
+++ tool/gfs2_tool.h 1 May 2007 20:06:13 -0000
@@ -2,7 +2,7 @@
*******************************************************************************
**
** Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
-** Copyright (C) 2004 Red Hat, Inc. All rights reserved.
+** Copyright (C) 2004-2007 Red Hat, Inc. All rights reserved.
**
** This copyrighted material is made available to anyone wishing to use,
** modify, copy, or redistribute it subject to the terms and conditions
@@ -95,6 +95,7 @@ void set_tune(int argc, char **argv);
void check_for_gfs2(int fd, char *path);
char *get_list(void);
char **str2lines(char *str);
+const char *find_debugfs_mount(void);
char *mp2fsname(char *mp);
char *name2value(char *str, char *name);
uint32_t name2u32(char *str, char *name);
More information about the Cluster-devel
mailing list