[Ocfs2-tools-devel] [PATCH 1/1] tunefs: Allow query of compat,
incompat and ro compat flags
Sunil Mushran
sunil.mushran at oracle.com
Tue Sep 25 11:14:58 PDT 2007
Tunefs query option supports showing the filesystem features.
Signed-off-by: Sunil Mushran <sunil.mushran at oracle.com>
---
libocfs2/include/ocfs2_fs.h | 8 +++
tunefs.ocfs2/Makefile | 3 +-
tunefs.ocfs2/query.c | 116 ++++++++++++++++++++++++++++++++++++++++
tunefs.ocfs2/tunefs.ocfs2.8.in | 8 +++-
4 files changed, 133 insertions(+), 2 deletions(-)
diff --git a/libocfs2/include/ocfs2_fs.h b/libocfs2/include/ocfs2_fs.h
index 1d5a318..cb0e9c1 100644
--- a/libocfs2/include/ocfs2_fs.h
+++ b/libocfs2/include/ocfs2_fs.h
@@ -96,6 +96,7 @@
* this in OCFS2_FEATURE_INCOMPAT_SUPP, *ever*.
*/
#define OCFS2_FEATURE_INCOMPAT_HEARTBEAT_DEV 0x0002
+#define OCFS2_FEATURE_INCOMPAT_HEARTBEAT_DEV_STR "Heartbeat"
/*
* tunefs sets this incompat flag before starting the resize and clears it
@@ -103,12 +104,15 @@
* after an aborted run without fsck-ing.
*/
#define OCFS2_FEATURE_INCOMPAT_RESIZE_INPROG 0x0004
+#define OCFS2_FEATURE_INCOMPAT_RESIZE_INPROG_STR "AbortedResize"
/* Used to denote a non-clustered volume */
#define OCFS2_FEATURE_INCOMPAT_LOCAL_MOUNT 0x0008
+#define OCFS2_FEATURE_INCOMPAT_LOCAL_MOUNT_STR "Local"
/* Support for sparse allocation in b-trees */
#define OCFS2_FEATURE_INCOMPAT_SPARSE_ALLOC 0x0010
+#define OCFS2_FEATURE_INCOMPAT_SPARSE_ALLOC_STR "SparseAlloc"
/*
* Tunefs sets this incompat flag before starting an operation which
@@ -120,17 +124,20 @@
* operations were in progress.
*/
#define OCFS2_FEATURE_INCOMPAT_TUNEFS_INPROG 0x0020
+#define OCFS2_FEATURE_INCOMPAT_TUNEFS_INPROG_STR "TunefsAbort"
/*
* backup superblock flag is used to indicate that this volume
* has backup superblocks.
*/
#define OCFS2_FEATURE_COMPAT_BACKUP_SB 0x0001
+#define OCFS2_FEATURE_COMPAT_BACKUP_SB_STR "BackupSuper"
/*
* Unwritten extents support.
*/
#define OCFS2_FEATURE_RO_COMPAT_UNWRITTEN 0x0001
+#define OCFS2_FEATURE_RO_COMPAT_UNWRITTEN_STR "UnwrittenExtents"
/* The byte offset of the first backup block will be 1G.
* The following will be 4G, 16G, 64G, 256G and 1T.
@@ -144,6 +151,7 @@
* Flags on ocfs2_super_block.s_tunefs_flags
*/
#define OCFS2_TUNEFS_INPROG_REMOVE_SLOT 0x0001 /* Removing slots */
+#define OCFS2_TUNEFS_INPROG_REMOVE_SLOT_STR "RemoveSlot"
/*
* Flags on ocfs2_dinode.i_flags
diff --git a/tunefs.ocfs2/Makefile b/tunefs.ocfs2/Makefile
index 067b824..6bbdbd4 100644
--- a/tunefs.ocfs2/Makefile
+++ b/tunefs.ocfs2/Makefile
@@ -26,6 +26,7 @@ sbindir = $(root_sbindir)
SBIN_PROGRAMS = tunefs.ocfs2
INCLUDES = -I$(TOPDIR)/libocfs2/include -I$(TOPDIR)/libo2dlm/include -I$(TOPDIR)/libo2cb/include -I.
+INCLUDES += $(GLIB_CFLAGS)
DEFINES = -DOCFS2_FLAT_INCLUDES -DVERSION=\"$(VERSION)\" -DO2DLM_FLAT_INCLUDES -DO2CB_FLAT_INCLUDES
MANS = tunefs.ocfs2.8
@@ -38,6 +39,6 @@ OBJS = $(subst .c,.o,$(CFILES))
DIST_FILES = $(CFILES) $(HFILES) tunefs.ocfs2.8.in
tunefs.ocfs2: $(OBJS) $(LIBOCFS2_DEPS) $(LIBO2DLM_DEPS) $(LIBO2CB_DEPS)
- $(LINK) $(LIBOCFS2_LIBS) $(UUID_LIBS) $(LIBO2DLM_LIBS) $(LIBO2CB_LIBS) $(COM_ERR_LIBS)
+ $(LINK) $(GLIB_LIBS) $(LIBOCFS2_LIBS) $(UUID_LIBS) $(LIBO2DLM_LIBS) $(LIBO2CB_LIBS) $(COM_ERR_LIBS)
include $(TOPDIR)/Postamble.make
diff --git a/tunefs.ocfs2/query.c b/tunefs.ocfs2/query.c
index c98ce24..ca79930 100644
--- a/tunefs.ocfs2/query.c
+++ b/tunefs.ocfs2/query.c
@@ -24,10 +24,59 @@
#include <tunefs.h>
#include <printf.h>
+#include <glib.h>
extern ocfs2_filesys *fs_gbl;
extern ocfs2_tune_opts opts;
+#define prepend_flgstr(_flag, _FLAG, _str, _sep) \
+ do { \
+ if ((_flag) & (_FLAG)) { \
+ g_string_prepend((_str), (_sep)); \
+ g_string_prepend((_str), _FLAG##_STR); \
+ } \
+ } while (0)
+
+static void tunefs_inprog_flag_in_str(uint32_t flag, GString *str)
+{
+ prepend_flgstr(flag, OCFS2_TUNEFS_INPROG_REMOVE_SLOT, str, " ");
+
+ if (flag & ~(OCFS2_TUNEFS_INPROG_REMOVE_SLOT))
+ g_string_prepend(str, "Unknown ");
+}
+
+static void incompat_flag_in_str(uint32_t flag, GString *str)
+{
+ prepend_flgstr(flag, OCFS2_FEATURE_INCOMPAT_HEARTBEAT_DEV, str, " ");
+ prepend_flgstr(flag, OCFS2_FEATURE_INCOMPAT_RESIZE_INPROG, str, " ");
+ prepend_flgstr(flag, OCFS2_FEATURE_INCOMPAT_LOCAL_MOUNT, str, " ");
+ prepend_flgstr(flag, OCFS2_FEATURE_INCOMPAT_SPARSE_ALLOC, str, " ");
+
+ if (flag & ~(OCFS2_FEATURE_INCOMPAT_HEARTBEAT_DEV |
+ OCFS2_FEATURE_INCOMPAT_RESIZE_INPROG |
+ OCFS2_FEATURE_INCOMPAT_LOCAL_MOUNT |
+ OCFS2_FEATURE_INCOMPAT_SPARSE_ALLOC |
+ OCFS2_FEATURE_INCOMPAT_TUNEFS_INPROG)) {
+ g_string_prepend(str, "Unknown ");
+ }
+}
+
+static void compat_flag_in_str(uint32_t flag, GString *str)
+{
+ prepend_flgstr(flag, OCFS2_FEATURE_COMPAT_BACKUP_SB, str, " ");
+
+ if (flag & ~(OCFS2_FEATURE_COMPAT_BACKUP_SB))
+ g_string_prepend(str, "Unknown ");
+}
+
+static void ro_compat_flag_in_str(uint32_t flag, GString *str)
+{
+ prepend_flgstr(flag, OCFS2_FEATURE_RO_COMPAT_UNWRITTEN, str, " ");
+
+ if (flag & ~(OCFS2_FEATURE_RO_COMPAT_UNWRITTEN))
+ g_string_prepend(str, "Unknown ");
+}
+
static int print_ulong(FILE *stream, const struct printf_info *info,
const void *const *args, unsigned long val)
{
@@ -121,6 +170,69 @@ static int handle_uuid(FILE *stream, const struct printf_info *info,
return print_string(stream, info, args, uuid);
}
+static int handle_flag(FILE *stream, const struct printf_info *info,
+ const void *const *args, uint32_t flag,
+ void(*flag_func)(uint32_t flag, GString *str))
+{
+ GString *str = NULL;
+ int len = 0;
+
+ str = g_string_new(NULL);
+
+ (flag_func)(flag, str);
+
+ if (str->len)
+ len = print_string(stream, info, args, str->str);
+
+ g_string_free(str, 1);
+
+ return len;
+}
+
+static int handle_compat(FILE *stream, const struct printf_info *info,
+ const void *const *args)
+{
+ int len;
+ len = handle_flag(stream, info, args,
+ OCFS2_RAW_SB(fs_gbl->fs_super)->s_feature_compat,
+ compat_flag_in_str);
+ if (!len)
+ len = print_string(stream, info, args, "None");
+ return len;
+}
+
+static int handle_incompat(FILE *stream, const struct printf_info *info,
+ const void *const *args)
+{
+ int len;
+
+ len = handle_flag(stream, info, args,
+ OCFS2_RAW_SB(fs_gbl->fs_super)->s_feature_incompat,
+ incompat_flag_in_str);
+
+ if (OCFS2_RAW_SB(fs_gbl->fs_super)->s_tunefs_flag)
+ len += handle_flag(stream, info, args,
+ OCFS2_RAW_SB(fs_gbl->fs_super)->s_tunefs_flag,
+ tunefs_inprog_flag_in_str);
+
+ if (!len)
+ len = print_string(stream, info, args, "None");
+ return len;
+}
+
+static int handle_ro_compat(FILE *stream, const struct printf_info *info,
+ const void *const *args)
+{
+ int len;
+
+ len = handle_flag(stream, info, args,
+ OCFS2_RAW_SB(fs_gbl->fs_super)->s_feature_ro_compat,
+ ro_compat_flag_in_str);
+ if (!len)
+ len = print_string(stream, info, args, "None");
+ return len;
+}
+
static int handle_arginfo(const struct printf_info *info, size_t n, int *types)
{
return 0;
@@ -210,6 +322,10 @@ void print_query(char *queryfmt)
register_printf_function('V', handle_label, handle_arginfo);
register_printf_function('U', handle_uuid, handle_arginfo);
+ register_printf_function('M', handle_compat, handle_arginfo);
+ register_printf_function('H', handle_incompat, handle_arginfo);
+ register_printf_function('O', handle_ro_compat, handle_arginfo);
+
fprintf(stdout, fmt);
free(fmt);
}
diff --git a/tunefs.ocfs2/tunefs.ocfs2.8.in b/tunefs.ocfs2/tunefs.ocfs2.8.in
index 5531e54..5fe2268 100644
--- a/tunefs.ocfs2/tunefs.ocfs2.8.in
+++ b/tunefs.ocfs2/tunefs.ocfs2.8.in
@@ -1,4 +1,4 @@
-.TH "tunefs.ocfs2" "8" "June 2007" "Version @VERSION@" "OCFS2 Manual Pages"
+.TH "tunefs.ocfs2" "8" "September 2007" "Version @VERSION@" "OCFS2 Manual Pages"
.SH "NAME"
tunefs.ocfs2 \- Change \fIOCFS2\fR file system parameters.
.SH "SYNOPSIS"
@@ -68,6 +68,12 @@ printf(3) type formatters. The list of type specifiers is as follows:
\fBV\fR Volume label
.TP
\fBU\fR Volume uuid
+.TP
+\fBM\fR Compat flags
+.TP
+\fBH\fR Incompat flags
+.TP
+\fBO\fR RO Compat flags
.RE
.TP
--
1.5.2.5
More information about the Ocfs2-tools-devel
mailing list