[Ocfs2-tools-commits] smushran commits r1359 - trunk/tunefs.ocfs2
svn-commits at oss.oracle.com
svn-commits at oss.oracle.com
Wed Jun 6 14:25:05 PDT 2007
Author: smushran
Date: 2007-06-06 14:25:04 -0700 (Wed, 06 Jun 2007)
New Revision: 1359
Added:
trunk/tunefs.ocfs2/query.c
trunk/tunefs.ocfs2/tunefs.h
Modified:
trunk/tunefs.ocfs2/Makefile
trunk/tunefs.ocfs2/tunefs.c
trunk/tunefs.ocfs2/tunefs.ocfs2.8.in
Log:
tunefs.ocfs2: Add query support
Tool now allows users to query blocksize, clustersize, label, uuid,
etc. The output can be formatted as per the query format provided.
Signed-off-by: jlbec
Signed-off-by: taoma
Modified: trunk/tunefs.ocfs2/Makefile
===================================================================
--- trunk/tunefs.ocfs2/Makefile 2007-06-06 21:20:09 UTC (rev 1358)
+++ trunk/tunefs.ocfs2/Makefile 2007-06-06 21:25:04 UTC (rev 1359)
@@ -25,12 +25,14 @@
sbindir = $(root_sbindir)
SBIN_PROGRAMS = tunefs.ocfs2
-INCLUDES = -I$(TOPDIR)/libocfs2/include -I$(TOPDIR)/libo2dlm/include -I$(TOPDIR)/libo2cb/include
+INCLUDES = -I$(TOPDIR)/libocfs2/include -I$(TOPDIR)/libo2dlm/include -I$(TOPDIR)/libo2cb/include -I.
DEFINES = -DOCFS2_FLAT_INCLUDES -DVERSION=\"$(VERSION)\" -DO2DLM_FLAT_INCLUDES -DO2CB_FLAT_INCLUDES
MANS = tunefs.ocfs2.8
-CFILES = tunefs.c
+CFILES = tunefs.c query.c
+HFILES = tunefs.h
+
OBJS = $(subst .c,.o,$(CFILES))
DIST_FILES = $(CFILES) tunefs.ocfs2.8.in
Added: trunk/tunefs.ocfs2/query.c
===================================================================
--- trunk/tunefs.ocfs2/query.c 2007-06-06 21:20:09 UTC (rev 1358)
+++ trunk/tunefs.ocfs2/query.c 2007-06-06 21:25:04 UTC (rev 1359)
@@ -0,0 +1,215 @@
+/*
+ * query.c
+ *
+ * ocfs2 tune utility - implements query
+ *
+ * Copyright (C) 2004, 2007 Oracle. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 021110-1307, USA.
+ *
+ */
+
+#include <tunefs.h>
+#include <printf.h>
+
+extern ocfs2_filesys *fs_gbl;
+extern ocfs2_tune_opts opts;
+
+static int print_ulong(FILE *stream, const struct printf_info *info,
+ const void *const *args, unsigned long val)
+{
+ char *buffer;
+ int len;
+
+ len = asprintf(&buffer, "%lu", val);
+ if (len == -1)
+ return -1;
+
+ len = fprintf(stream, "%*s", (info->left ? -info->width : info->width),
+ buffer);
+ free(buffer);
+ return len;
+}
+
+static int print_string(FILE *stream, const struct printf_info *info,
+ const void *const *args, char *val)
+{
+ char *buffer;
+ int len;
+
+ len = asprintf(&buffer, "%s", val);
+ if (len == -1)
+ return -1;
+
+ len = fprintf(stream, "%*s", (info->left ? -info->width : info->width),
+ buffer);
+ free(buffer);
+ return len;
+}
+
+static int handle_blocksize(FILE *stream, const struct printf_info *info,
+ const void *const *args)
+{
+ return print_ulong(stream, info, args, fs_gbl->fs_blocksize);
+}
+
+static int handle_clustersize(FILE *stream, const struct printf_info *info,
+ const void *const *args)
+{
+ return print_ulong(stream, info, args, fs_gbl->fs_clustersize);
+}
+
+static int handle_numslots(FILE *stream, const struct printf_info *info,
+ const void *const *args)
+{
+ return print_ulong(stream, info, args,
+ OCFS2_RAW_SB(fs_gbl->fs_super)->s_max_slots);
+}
+
+static int handle_rootdir(FILE *stream, const struct printf_info *info,
+ const void *const *args)
+{
+ return print_ulong(stream, info, args,
+ OCFS2_RAW_SB(fs_gbl->fs_super)->s_root_blkno);
+}
+
+static int handle_sysdir(FILE *stream, const struct printf_info *info,
+ const void *const *args)
+{
+ return print_ulong(stream, info, args,
+ OCFS2_RAW_SB(fs_gbl->fs_super)->s_system_dir_blkno);
+}
+
+static int handle_clustergroup(FILE *stream, const struct printf_info *info,
+ const void *const *args)
+{
+ return print_ulong(stream, info, args,
+ OCFS2_RAW_SB(fs_gbl->fs_super)->s_first_cluster_group);
+}
+
+static int handle_label(FILE *stream, const struct printf_info *info,
+ const void *const *args)
+{
+ char label[OCFS2_MAX_VOL_LABEL_LEN + 1];
+
+ snprintf(label, OCFS2_MAX_VOL_LABEL_LEN + 1,
+ OCFS2_RAW_SB(fs_gbl->fs_super)->s_label);
+
+ return print_string(stream, info, args, label);
+}
+
+static int handle_uuid(FILE *stream, const struct printf_info *info,
+ const void *const *args)
+{
+ char uuid[OCFS2_VOL_UUID_LEN * 2 + 1];
+
+ uuid_unparse(OCFS2_RAW_SB(fs_gbl->fs_super)->s_uuid, uuid);
+
+ return print_string(stream, info, args, uuid);
+}
+
+static int handle_arginfo(const struct printf_info *info, size_t n, int *types)
+{
+ return 0;
+}
+
+/*
+ * \a=0x07, \b=0x08, \t=0x09, \n=0x0a, \v=0x0b, \f=0x0c, \r=0x0d
+ */
+static char * process_escapes(char *queryfmt)
+{
+ char *fmt;
+ int i, j;
+ int len;
+
+ len = strlen(queryfmt);
+
+ fmt = malloc(len + 1);
+ if (!fmt)
+ return NULL;
+
+ for(i = 0, j = 0; i < len; ) {
+ if (queryfmt[i] != '\\')
+ fmt[j++] = queryfmt[i++];
+ else {
+ switch(queryfmt[i + 1]) {
+ case 'a':
+ fmt[j++] = 0x07;
+ break;
+ case 'b':
+ fmt[j++] = 0x08;
+ break;
+ case 't':
+ fmt[j++] = 0x09;
+ break;
+ case 'n':
+ fmt[j++] = 0x0A;
+ break;
+ case 'v':
+ fmt[j++] = 0x0B;
+ break;
+ case 'f':
+ fmt[j++] = 0x0C;
+ break;
+ case 'r':
+ fmt[j++] = 0x0D;
+ break;
+ default:
+ fmt[j++] = queryfmt[i];
+ fmt[j++] = queryfmt[i + 1];
+ break;
+ }
+ i += 2;
+ }
+ }
+
+ return fmt;
+}
+
+/*
+ * avoid standard type specifiers: E, F, G, A, C, S, X, L
+ */
+void print_query(char *queryfmt)
+{
+ char *fmt;
+ int argtype;
+
+ if (parse_printf_format(queryfmt, 1, &argtype)) {
+ com_err(opts.progname, 0,
+ "Unknown type specifier in the query format");
+ return;
+ }
+
+ fmt = process_escapes(queryfmt);
+ if (!fmt) {
+ com_err(opts.progname, OCFS2_ET_NO_MEMORY,
+ "while processing escapes in the query format");
+ return ;
+ }
+
+ register_printf_function('B', handle_blocksize, handle_arginfo);
+ register_printf_function('T', handle_clustersize, handle_arginfo);
+ register_printf_function('N', handle_numslots, handle_arginfo);
+ register_printf_function('R', handle_rootdir, handle_arginfo);
+ register_printf_function('Y', handle_sysdir, handle_arginfo);
+ register_printf_function('P', handle_clustergroup, handle_arginfo);
+
+ register_printf_function('V', handle_label, handle_arginfo);
+ register_printf_function('U', handle_uuid, handle_arginfo);
+
+ fprintf(stdout, fmt);
+ free(fmt);
+}
Modified: trunk/tunefs.ocfs2/tunefs.c
===================================================================
--- trunk/tunefs.ocfs2/tunefs.c 2007-06-06 21:20:09 UTC (rev 1358)
+++ trunk/tunefs.ocfs2/tunefs.c 2007-06-06 21:25:04 UTC (rev 1359)
@@ -23,82 +23,17 @@
* Authors: Sunil Mushran
*/
-#define _LARGEFILE64_SOURCE
-#define _GNU_SOURCE /* Because libc really doesn't want us using O_DIRECT? */
+#include <tunefs.h>
-#include <sys/types.h>
-#include <stdio.h>
-#include <unistd.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <linux/fd.h>
-#include <string.h>
-#include <sys/stat.h>
-#include <stdlib.h>
-#include <string.h>
-#include <getopt.h>
-#include <malloc.h>
-#include <time.h>
-#include <libgen.h>
-#include <netinet/in.h>
-#include <inttypes.h>
-#include <ctype.h>
-#include <signal.h>
-#include <uuid/uuid.h>
-
-#include <ocfs2.h>
-#include <ocfs2_fs.h>
-#include <ocfs1_fs_compat.h>
-#include <bitops.h>
-
-#include <jbd.h>
-
-#include <kernel-list.h>
-
-#define SYSTEM_FILE_NAME_MAX 40
-
-#ifndef MIN
-#define MIN(a, b) (((a) < (b)) ? (a) : (b))
-#endif
-#ifndef MAX
-#define MAX(a, b) (((a) > (b)) ? (a) : (b))
-#endif
-
-#define MOUNT_LOCAL 1
-#define MOUNT_CLUSTER 2
-#define MOUNT_LOCAL_STR "local"
-#define MOUNT_CLUSTER_STR "cluster"
-
-enum {
- BACKUP_SUPER_OPTION = CHAR_MAX + 1,
-};
-
-typedef struct _ocfs2_tune_opts {
- uint16_t num_slots;
- uint64_t num_blocks;
- uint64_t jrnl_size;
- char *vol_label;
- char *progname;
- char *device;
- char *vol_uuid;
- int mount;
- int verbose;
- int quiet;
- int prompt;
- int backup_super;
- time_t tune_time;
- int fd;
-} ocfs2_tune_opts;
-
-static ocfs2_tune_opts opts;
-static ocfs2_filesys *fs_gbl = NULL;
+ocfs2_tune_opts opts;
+ocfs2_filesys *fs_gbl = NULL;
static int cluster_locked = 0;
static int resize = 0;
static void usage(const char *progname)
{
fprintf(stderr, "usage: %s [-J journal-options] [-L volume-label]\n"
- "\t\t[-M mount-type] [-N number-of-node-slots]\n"
+ "\t\t[-M mount-type] [-N number-of-node-slots] [-Q query-fmt]\n"
"\t\t[-qSUvV] [--backup-super] device [blocks-count]\n",
progname);
exit(0);
@@ -253,6 +188,7 @@
{ "node-slots", 1, 0, 'N' },
{ "verbose", 0, 0, 'v' },
{ "quiet", 0, 0, 'q' },
+ { "query", 1, 0, 'Q' },
{ "version", 0, 0, 'V' },
{ "journal-options", 0, 0, 'J'},
{ "volume-size", 0, 0, 'S'},
@@ -270,7 +206,7 @@
opts.prompt = 1;
while (1) {
- c = getopt_long(argc, argv, "L:N:J:M:SUvqVxb", long_options,
+ c = getopt_long(argc, argv, "L:N:J:M:Q:SUvqVxb", long_options,
NULL);
if (c == -1)
@@ -320,6 +256,9 @@
exit(1);
}
break;
+ case 'Q':
+ opts.queryfmt = strdup(optarg);
+ break;
case 'J':
parse_journal_opts(opts.progname, optarg,
@@ -1288,6 +1227,18 @@
return ret;
}
+static void free_opts(void)
+{
+ if (opts.vol_uuid)
+ free(opts.vol_uuid);
+ if (opts.vol_label)
+ free(opts.vol_label);
+ if (opts.queryfmt)
+ free(opts.queryfmt);
+ if (opts.device)
+ free(opts.device);
+}
+
int main(int argc, char **argv)
{
errcode_t ret = 0;
@@ -1339,6 +1290,11 @@
}
fs_gbl = fs;
+ if (opts.queryfmt) {
+ print_query(opts.queryfmt);
+ goto close;
+ }
+
if (OCFS2_RAW_SB(fs->fs_super)->s_feature_incompat &
OCFS2_FEATURE_INCOMPAT_RESIZE_INPROG) {
fprintf(stderr, "Aborted resize detected. Run fsck.ocfs2 -f <device>.\n");
@@ -1623,12 +1579,8 @@
ocfs2_shutdown_dlm(fs);
block_signals(SIG_UNBLOCK);
- if (opts.vol_uuid)
- free(opts.vol_uuid);
- if (opts.vol_label)
- free(opts.vol_label);
- if (opts.device)
- free(opts.device);
+ free_opts();
+
if (fs)
ocfs2_close(fs);
Added: trunk/tunefs.ocfs2/tunefs.h
===================================================================
--- trunk/tunefs.ocfs2/tunefs.h 2007-06-06 21:20:09 UTC (rev 1358)
+++ trunk/tunefs.ocfs2/tunefs.h 2007-06-06 21:25:04 UTC (rev 1359)
@@ -0,0 +1,94 @@
+/*
+ * tune.h
+ *
+ * ocfs2 tune utility
+ *
+ * Copyright (C) 2004, 2007 Oracle. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 021110-1307, USA.
+ *
+ */
+
+#define _LARGEFILE64_SOURCE
+#define _GNU_SOURCE /* Because libc really doesn't want us using O_DIRECT? */
+
+#include <sys/types.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <linux/fd.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <stdlib.h>
+#include <string.h>
+#include <getopt.h>
+#include <malloc.h>
+#include <time.h>
+#include <libgen.h>
+#include <netinet/in.h>
+#include <inttypes.h>
+#include <ctype.h>
+#include <signal.h>
+#include <uuid/uuid.h>
+
+#include <ocfs2.h>
+#include <ocfs2_fs.h>
+#include <ocfs1_fs_compat.h>
+#include <bitops.h>
+
+#include <jbd.h>
+
+#include <kernel-list.h>
+
+#define SYSTEM_FILE_NAME_MAX 40
+
+#ifndef MIN
+#define MIN(a, b) (((a) < (b)) ? (a) : (b))
+#endif
+#ifndef MAX
+#define MAX(a, b) (((a) > (b)) ? (a) : (b))
+#endif
+
+#define MOUNT_LOCAL 1
+#define MOUNT_CLUSTER 2
+#define MOUNT_LOCAL_STR "local"
+#define MOUNT_CLUSTER_STR "cluster"
+
+enum {
+ BACKUP_SUPER_OPTION = CHAR_MAX + 1,
+};
+
+typedef struct _ocfs2_tune_opts {
+ uint16_t num_slots;
+ uint64_t num_blocks;
+ uint64_t jrnl_size;
+ char *vol_label;
+ char *progname;
+ char *device;
+ char *vol_uuid;
+ char *queryfmt;
+ int mount;
+ int verbose;
+ int quiet;
+ int prompt;
+ int backup_super;
+ time_t tune_time;
+ int fd;
+} ocfs2_tune_opts;
+
+void print_query(char *queryfmt);
+
Modified: trunk/tunefs.ocfs2/tunefs.ocfs2.8.in
===================================================================
--- trunk/tunefs.ocfs2/tunefs.ocfs2.8.in 2007-06-06 21:20:09 UTC (rev 1358)
+++ trunk/tunefs.ocfs2/tunefs.ocfs2.8.in 2007-06-06 21:25:04 UTC (rev 1359)
@@ -1,8 +1,8 @@
-.TH "tunefs.ocfs2" "8" "February 2007" "Version @VERSION@" "OCFS2 Manual Pages"
+.TH "tunefs.ocfs2" "8" "June 2007" "Version @VERSION@" "OCFS2 Manual Pages"
.SH "NAME"
tunefs.ocfs2 \- Change \fIOCFS2\fR file system parameters.
.SH "SYNOPSIS"
-\fBtunefs.ocfs2\fR [\fB\-J\fR \fIjournal-options\fR] [\fB\-L\fR \fIvolume-label\fR] [\fB\-M\fR \fImount-type\fR] [\fB\-N\fR \fInumber-of-node-slots\fR] [\fB\-qSUvV\fR] [\fB\-\-backup-super\fR] \fIdevice\fR [\fIblocks-count\fR]
+\fBtunefs.ocfs2\fR [\fB\-J\fR \fIjournal-options\fR] [\fB\-L\fR \fIvolume-label\fR] [\fB\-M\fR \fImount-type\fR] [\fB\-N\fR \fInumber-of-node-slots\fR] [\fB\-Q\fR \fIquery-format\fR] [\fB\-qSUvV\fR] [\fB\-\-backup-super\fR] \fIdevice\fR [\fIblocks-count\fR]
.SH "DESCRIPTION"
.PP
\fBtunefs.ocfs2\fR is used to adjust \fIOCFS2\fR file system parameters on disk.
@@ -46,6 +46,31 @@
the device.
.TP
+\fB\-Q, \-\-query\fR \fIquery\-format\fR
+Query the file system for its attributes like block size, label, etc. Query formats are modified
+versions of the standard printf(3) formatting. The format is made up of static strings (which may
+include standard C character escapes for newlines, tabs, and other special characters) and
+printf(3) type formatters. The list of type specifiers is as follows:
+.RS 1.2i
+.TP
+\fBB\fR Block size in bytes
+.TP
+\fBT\fR Cluster size in bytes
+.TP
+\fBN\fR Number of node slots
+.TP
+\fBR\fR Root directory block number
+.TP
+\fBY\fR System directory block number
+.TP
+\fBP\fR First cluster group block number
+.TP
+\fBV\fR Volume label
+.TP
+\fBU\fR Volume uuid
+.RE
+
+.TP
\fB\-q, \-\-quiet\fR
Quiet mode.
@@ -76,6 +101,14 @@
the device. This optional argument specifies that the file system should be
extended to consume only the given number of file system blocks on the device.
+.SH "EXAMPLES"
+[root at node1 ~]# tunefs.ocfs2 -q -Q "BS=%5B\\nUUID=%U\\n" /dev/sda1
+.br
+BS= 2048
+.br
+UUID=80d1adf4-3fde-40dd-9b56-d370462ace17
+.br
+
.SH "SEE ALSO"
.BR mkfs.ocfs2(8)
.BR fsck.ocfs2(8)
More information about the Ocfs2-tools-commits
mailing list