From mboxrd@z Thu Jan 1 00:00:00 1970 From: rpeterso@sourceware.org Date: 11 May 2007 16:53:38 -0000 Subject: [Cluster-devel] cluster/gfs2 libgfs2/libgfs2.h libgfs2/misc.c ... Message-ID: <20070511165338.28338.qmail@sourceware.org> List-Id: To: cluster-devel.redhat.com MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit CVSROOT: /cvs/cluster Module name: cluster Branch: RHEL5 Changes by: rpeterso at sourceware.org 2007-05-11 16:53:33 Modified files: gfs2/libgfs2 : libgfs2.h misc.c gfs2/mkfs : Makefile main.c main_jadd.c main_mkfs.c gfs2/quota : check.c gfs2_quota.h main.c gfs2/tool : gfs2_tool.h Added files: gfs2/mkfs : main_grow.c Log message: Resolves: Bugzilla Bug 234844: Need to add a "gfs2_grow" command Patches: http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/gfs2/libgfs2/libgfs2.h.diff?cvsroot=cluster&only_with_tag=RHEL5&r1=1.7.2.4&r2=1.7.2.5 http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/gfs2/libgfs2/misc.c.diff?cvsroot=cluster&only_with_tag=RHEL5&r1=1.2&r2=1.2.2.1 http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/gfs2/mkfs/main_grow.c.diff?cvsroot=cluster&only_with_tag=RHEL5&r1=NONE&r2=1.4.2.1 http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/gfs2/mkfs/Makefile.diff?cvsroot=cluster&only_with_tag=RHEL5&r1=1.12.2.1&r2=1.12.2.2 http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/gfs2/mkfs/main.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/mkfs/main_jadd.c.diff?cvsroot=cluster&only_with_tag=RHEL5&r1=1.10&r2=1.10.2.1 http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/gfs2/mkfs/main_mkfs.c.diff?cvsroot=cluster&only_with_tag=RHEL5&r1=1.8.2.4&r2=1.8.2.5 http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/gfs2/quota/check.c.diff?cvsroot=cluster&only_with_tag=RHEL5&r1=1.2.2.1&r2=1.2.2.2 http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/gfs2/quota/gfs2_quota.h.diff?cvsroot=cluster&only_with_tag=RHEL5&r1=1.1.2.1&r2=1.1.2.2 http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/gfs2/quota/main.c.diff?cvsroot=cluster&only_with_tag=RHEL5&r1=1.2.2.1&r2=1.2.2.2 http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/gfs2/tool/gfs2_tool.h.diff?cvsroot=cluster&only_with_tag=RHEL5&r1=1.5&r2=1.5.2.1 --- cluster/gfs2/libgfs2/libgfs2.h 2007/05/01 18:20:50 1.7.2.4 +++ cluster/gfs2/libgfs2/libgfs2.h 2007/05/11 16:53:32 1.7.2.5 @@ -165,7 +165,7 @@ int expert; int override; - char *device_name; + char device_name[PATH_MAX]; char *path_name; /* Constants */ @@ -219,6 +219,9 @@ 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 @@ /* 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 @@ /* 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); --- cluster/gfs2/libgfs2/misc.c 2006/06/06 14:20:41 1.2 +++ cluster/gfs2/libgfs2/misc.c 2007/05/11 16:53:32 1.2.2.1 @@ -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 #include #include - +#include #include +#include + #include "libgfs2.h" void @@ -102,3 +104,170 @@ 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)); + } +} + /cvs/cluster/cluster/gfs2/mkfs/main_grow.c,v --> standard output revision 1.4.2.1 --- cluster/gfs2/mkfs/main_grow.c +++ - 2007-05-11 16:53:34.528188000 +0000 @@ -0,0 +1,346 @@ +/****************************************************************************** +******************************************************************************* +** +** 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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#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': + printf("(Test mode--File system will not " + "be changed)\n"); + 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, !test); + + /* 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); + + /* We're done with the libgfs portion, so commit it to disk. */ + 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, *bufptr; + osi_list_t *tmp; + ssize_t writelen; + + /* Count the number of new RGs. */ + rg = 0; + osi_list_foreach(tmp, &sdp->rglist) + rg++; + log_info("%d new rindex entries.\n", rg); + writelen = rg * sizeof(struct gfs2_rindex); + zalloc(buf, writelen); + 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. */ + bufptr = buf; + osi_list_foreach(tmp, &sdp->rglist) { + rg++; + rl = osi_list_entry(tmp, struct rgrp_list, list); + gfs2_rindex_out(&rl->ri, bufptr); + bufptr += sizeof(struct gfs2_rindex); + } + if (!test) { + /* Now write the new RGs to the end of the rindex */ + lseek(rindex_fd, 0, SEEK_END); + count = write(rindex_fd, buf, writelen); + if (count != writelen) + log_crit("Error writing new rindex entries;" + "aborted.\n"); + 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]; + osi_list_t *head = &sdp->rglist; + + 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, + (test ? O_RDONLY : 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, (test ? O_RDONLY : 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. We aren't using gfs2 here, */ + /* which means that the bitmaps will most likely be cached */ + /* and therefore out of date. 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); + } + /* Delete the remaining RGs from the rglist */ + while (!osi_list_empty(head)) + osi_list_del(head->next); + close(rindex_fd); + cleanup_metafs(sdp); + close(sdp->device_fd); + } + close(sdp->path_fd); + sync(); + log_notice("gfs2_grow complete.\n"); +} --- cluster/gfs2/mkfs/Makefile 2007/03/26 19:42:09 1.12.2.1 +++ cluster/gfs2/mkfs/Makefile 2007/05/11 16:53:32 1.12.2.2 @@ -9,6 +9,7 @@ MKFS=mkfs.gfs2 JADD=gfs2_jadd +GROW=gfs2_grow INCLUDEPATH=-I${KERNEL_SRC}/include/ -I${top_srcdir}/include/ -I${top_srcdir}/libgfs2/ -I${top_srcdir}/config/ INSTALL=install @@ -19,10 +20,10 @@ LDFLAGS=-L${top_srcdir}/libgfs2 -L${libdir} H=gfs2_disk_hash.h gfs2_mkfs.h linux_endian.h ondisk.h osi_list.h -C=main.c main_mkfs.c main_jadd.c +C=main.c main_mkfs.c main_jadd.c main_grow.c O=$(subst .c,.o,${C}) -all: ${MKFS} ${JADD} +all: ${MKFS} ${JADD} ${GROW} ${MKFS}: ${O} ${top_srcdir}/libgfs2/libgfs2.a ${LD} ${LDFLAGS} ${O} -o ${@} -lgfs2 -lvolume_id @@ -30,13 +31,16 @@ ${JADD}: ${MKFS} ln -s ${MKFS} ${JADD} +${GROW}: ${MKFS} + ln -s ${MKFS} ${GROW} + .c.o: $< ${CC} ${CFLAGS} -o $@ $^ install: all ${INSTALL} -m 0755 ${MKFS} ${sbindir} ln -f ${sbindir}/${MKFS} ${sbindir}/${JADD} + ln -f ${sbindir}/${MKFS} ${sbindir}/${GROW} clean: - rm -f *.o ${MKFS} ${JADD} - + rm -f *.o ${MKFS} ${JADD} ${GROW} --- cluster/gfs2/mkfs/main.c 2006/07/10 22:51:10 1.7 +++ cluster/gfs2/mkfs/main.c 2007/05/11 16:53:32 1.7.2.1 @@ -53,14 +53,15 @@ main_jadd(argc, argv); else if (!strcmp(whoami, "gfs2_mkfs") || !strcmp(whoami, "mkfs.gfs2")) main_mkfs(argc, argv); -#if 0 - if (!strcmp(whoami, "gfs2_grow")) + else if (!strcmp(whoami, "gfs2_grow")) main_grow(argc, argv); +#if 0 else if (!strcmp(whoami, "gfs2_shrink")) main_shrink(argc, argv); +#endif else die("I don't know who I am!\n"); -#endif + free(p); return EXIT_SUCCESS; --- cluster/gfs2/mkfs/main_jadd.c 2006/10/26 18:42:25 1.10 +++ cluster/gfs2/mkfs/main_jadd.c 2007/05/11 16:53:32 1.10.2.1 @@ -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 #include #include @@ -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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ add_j(sdp); } - close(metafs_fd); close(sdp->path_fd); - - cleanup(sdp); - + cleanup_metafs(sdp); sync(); - print_results(sdp); } --- cluster/gfs2/mkfs/main_mkfs.c 2007/05/01 18:20:50 1.8.2.4 +++ cluster/gfs2/mkfs/main_mkfs.c 2007/05/11 16:53:32 1.8.2.5 @@ -86,7 +86,7 @@ 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 @@ 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 @@ }; } - 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 @@ 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); --- cluster/gfs2/quota/check.c 2007/05/10 22:43:12 1.2.2.1 +++ cluster/gfs2/quota/check.c 2007/05/11 16:53:33 1.2.2.2 @@ -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 @@ * */ 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 @@ 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 @@ 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 @@ */ 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 @@ 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 @@ */ 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 @@ 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 @@ 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 @@ } /* 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 @@ */ 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 @@ 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 @@ 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); } --- cluster/gfs2/quota/gfs2_quota.h 2007/05/10 22:43:12 1.1.2.1 +++ cluster/gfs2/quota/gfs2_quota.h 2007/05/11 16:53:33 1.1.2.2 @@ -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 @@ /* 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 */ --- cluster/gfs2/quota/main.c 2007/05/10 22:43:12 1.2.2.1 +++ cluster/gfs2/quota/main.c 2007/05/11 16:53:33 1.2.2.2 @@ -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 @@ } /** - * 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 @@ } 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; @@ -399,44 +291,6 @@ } } -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) { @@ -462,10 +316,9 @@ */ 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 @@ 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 @@ 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 @@ */ 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 @@ 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 @@ */ 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 @@ printf("\n"); printf("%s\n", path); - do_get_one(comline, path); + do_get_one(sdp, comline, path); } fclose(file); @@ -633,16 +485,15 @@ * */ 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 @@ */ 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 @@ if (strcmp(type, "gfs2") != 0) continue; - do_sync_one(path); + do_sync_one(sdp, path); } fclose(file); @@ -696,11 +547,10 @@ */ 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 @@ 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 @@ 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 @@ 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 @@ } /* 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 @@ 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 @@ comline.id_type = GQ_ID_USER; comline.id = geteuid(); } - do_get(&comline); + do_get(sdp, &comline); break; } --- cluster/gfs2/tool/gfs2_tool.h 2005/10/13 16:39:19 1.5 +++ cluster/gfs2/tool/gfs2_tool.h 2007/05/11 16:53:33 1.5.2.1 @@ -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 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);