[Ocfs2-tools-devel] [PATCH 19/32] debugfs.ocfs2: Feature flag printing cleanup
Sunil Mushran
sunil.mushran at oracle.com
Tue Sep 14 15:54:49 PDT 2010
Cleaned up double allocations in the feature flag print helpers.
Signed-off-by: Sunil Mushran <sunil.mushran at oracle.com>
Signed-off-by: Joel Becker <joel.becker at oracle.com>
---
debugfs.ocfs2/dump.c | 35 +++------
debugfs.ocfs2/include/utils.h | 10 +--
debugfs.ocfs2/utils.c | 168 +++++------------------------------------
3 files changed, 34 insertions(+), 179 deletions(-)
diff --git a/debugfs.ocfs2/dump.c b/debugfs.ocfs2/dump.c
index bada657..90e8fe1 100644
--- a/debugfs.ocfs2/dump.c
+++ b/debugfs.ocfs2/dump.c
@@ -40,17 +40,9 @@ void dump_super_block(FILE *out, struct ocfs2_super_block *sb)
{
int i;
char *str;
- GString *compat = NULL;
- GString *incompat = NULL;
- GString *rocompat = NULL;
- GString *tunefs_flag = NULL;
+ char buf[PATH_MAX];
time_t lastcheck;
- compat = g_string_new(NULL);
- incompat = g_string_new(NULL);
- rocompat = g_string_new(NULL);
- tunefs_flag = g_string_new(NULL);
-
fprintf(out, "\tRevision: %u.%u\n", sb->s_major_rev_level, sb->s_minor_rev_level);
fprintf(out, "\tMount Count: %u Max Mount Count: %u\n", sb->s_mnt_count,
sb->s_max_mnt_count);
@@ -63,20 +55,19 @@ void dump_super_block(FILE *out, struct ocfs2_super_block *sb)
fprintf(out, "\tCreator OS: %u\n", sb->s_creator_os);
- get_compat_flag(sb->s_feature_compat, compat);
- get_incompat_flag(sb->s_feature_incompat, incompat);
- get_tunefs_flag(sb->s_feature_incompat,
- sb->s_tunefs_flag, tunefs_flag);
- get_rocompat_flag(sb->s_feature_ro_compat, rocompat);
+ get_compat_flag(sb, buf, sizeof(buf));
+ fprintf(out, "\tFeature Compat: %u %s\n", sb->s_feature_compat, buf);
- fprintf(out, "\tFeature Compat: %u %s\n", sb->s_feature_compat,
- compat->str);
+ get_incompat_flag(sb, buf, sizeof(buf));
fprintf(out, "\tFeature Incompat: %u %s\n", sb->s_feature_incompat,
- incompat->str);
- fprintf(out, "\tTunefs Incomplete: %u %s\n", sb->s_tunefs_flag,
- tunefs_flag->str);
+ buf);
+
+ get_tunefs_flag(sb, buf, sizeof(buf));
+ fprintf(out, "\tTunefs Incomplete: %u %s\n", sb->s_tunefs_flag, buf);
+
+ get_rocompat_flag(sb, buf, sizeof(buf));
fprintf(out, "\tFeature RO compat: %u %s\n", sb->s_feature_ro_compat,
- rocompat->str);
+ buf);
fprintf(out, "\tRoot Blknum: %"PRIu64" System Dir Blknum: %"PRIu64"\n",
(uint64_t)sb->s_root_blkno,
@@ -111,10 +102,6 @@ void dump_super_block(FILE *out, struct ocfs2_super_block *sb)
else
fprintf(out, "\tCluster stack: classic o2cb\n");
- g_string_free(compat, 1);
- g_string_free(incompat, 1);
- g_string_free(rocompat, 1);
-
return ;
}
diff --git a/debugfs.ocfs2/include/utils.h b/debugfs.ocfs2/include/utils.h
index 7b0da94..96de0cf 100644
--- a/debugfs.ocfs2/include/utils.h
+++ b/debugfs.ocfs2/include/utils.h
@@ -37,12 +37,10 @@ struct strings {
struct list_head s_list;
};
-void get_incompat_flag(uint32_t flag, GString *str);
-void get_tunefs_flag(uint32_t incompat_flag, uint16_t flag, GString *str);
-void get_compat_flag(uint32_t flag, GString *str);
-void get_rocompat_flag(uint32_t flag, GString *str);
-void get_vote_flag (uint32_t flag, GString *str);
-void get_publish_flag (uint32_t flag, GString *str);
+void get_incompat_flag(struct ocfs2_super_block *sb, char *buf, size_t count);
+void get_tunefs_flag(struct ocfs2_super_block *sb, char *buf, size_t count);
+void get_compat_flag(struct ocfs2_super_block *sb, char *buf, size_t count);
+void get_rocompat_flag(struct ocfs2_super_block *sb, char *buf, size_t count);
void get_journal_block_type (uint32_t jtype, GString *str);
void get_tag_flag (uint32_t flags, GString *str);
FILE *open_pager(int interactive);
diff --git a/debugfs.ocfs2/utils.c b/debugfs.ocfs2/utils.c
index 2c5b588..38b4f6d 100644
--- a/debugfs.ocfs2/utils.c
+++ b/debugfs.ocfs2/utils.c
@@ -29,183 +29,53 @@
extern dbgfs_gbls gbls;
-void get_incompat_flag(uint32_t flag, GString *str)
+void get_incompat_flag(struct ocfs2_super_block *sb, char *buf, size_t count)
{
errcode_t err;
- char buf[PATH_MAX];
ocfs2_fs_options flags = {
- .opt_incompat = flag,
+ .opt_incompat = sb->s_feature_incompat,
};
*buf = '\0';
- err = ocfs2_snprint_feature_flags(buf, PATH_MAX, &flags);
- if (!err)
- g_string_append(str, buf);
- else
- com_err(gbls.cmd, err, "while processing feature flags");
+ err = ocfs2_snprint_feature_flags(buf, count, &flags);
+ if (err)
+ com_err(gbls.cmd, err, "while processing incompat flags");
}
-void get_tunefs_flag(uint32_t incompat_flag, uint16_t flag, GString *str)
+void get_tunefs_flag(struct ocfs2_super_block *sb, char *buf, size_t count)
{
errcode_t err;
- char buf[PATH_MAX];
*buf = '\0';
- err = ocfs2_snprint_tunefs_flags(buf, PATH_MAX, flag);
- if (!err)
- g_string_append(str, buf);
- else
- com_err(gbls.cmd, err, "while processing inprog flags");
+ err = ocfs2_snprint_tunefs_flags(buf, count, sb->s_tunefs_flag);
+ if (err)
+ com_err(gbls.cmd, err, "while processing tunefs flags");
}
-void get_compat_flag(uint32_t flag, GString *str)
+void get_compat_flag(struct ocfs2_super_block *sb, char *buf, size_t count)
{
errcode_t err;
- char buf[PATH_MAX];
ocfs2_fs_options flags = {
- .opt_compat = flag,
+ .opt_compat = sb->s_feature_compat,
};
*buf = '\0';
- err = ocfs2_snprint_feature_flags(buf, PATH_MAX, &flags);
- if (!err)
- g_string_append(str, buf);
- else
- com_err(gbls.cmd, err, "while processing feature flags");
+ err = ocfs2_snprint_feature_flags(buf, count, &flags);
+ if (err)
+ com_err(gbls.cmd, err, "while processing compat flags");
}
-void get_rocompat_flag(uint32_t flag, GString *str)
+void get_rocompat_flag(struct ocfs2_super_block *sb, char *buf, size_t count)
{
errcode_t err;
- char buf[PATH_MAX];
ocfs2_fs_options flags = {
- .opt_ro_compat = flag,
+ .opt_ro_compat = sb->s_feature_ro_compat,
};
*buf = '\0';
- err = ocfs2_snprint_feature_flags(buf, PATH_MAX, &flags);
- if (!err)
- g_string_append(str, buf);
- else
- com_err(gbls.cmd, err, "while processing feature flags");
-}
-
-/*
- * get_vote_flag()
- *
- */
-void get_vote_flag (uint32_t flag, GString *str)
-{
- if (flag & FLAG_VOTE_NODE)
- g_string_append (str, "ok ");
-
- if (flag & FLAG_VOTE_OIN_UPDATED)
- g_string_append (str, "oin_upd ");
-
- if (flag & FLAG_VOTE_OIN_ALREADY_INUSE)
- g_string_append (str, "inuse ");
-
- if (flag & FLAG_VOTE_UPDATE_RETRY)
- g_string_append (str, "retry ");
-
- if (flag & FLAG_VOTE_FILE_DEL)
- g_string_append (str, "del ");
-
- if (flag & ~(FLAG_VOTE_NODE | FLAG_VOTE_OIN_UPDATED |
- FLAG_VOTE_OIN_ALREADY_INUSE |
- FLAG_VOTE_UPDATE_RETRY | FLAG_VOTE_FILE_DEL))
- g_string_append (str, "unknown");
-
- if (!str->len)
- g_string_append (str, "none");
-
- return ;
-}
-
-/*
- * get_publish_flag()
- *
- */
-void get_publish_flag (uint32_t flag, GString *str)
-{
- if (flag & FLAG_FILE_CREATE)
- g_string_append (str, "create ");
-
- if (flag & FLAG_FILE_EXTEND)
- g_string_append (str, "extend ");
-
- if (flag & FLAG_FILE_DELETE)
- g_string_append (str, "delete ");
-
- if (flag & FLAG_FILE_RENAME)
- g_string_append (str, "rename ");
-
- if (flag & FLAG_FILE_UPDATE)
- g_string_append (str, "update ");
-
- if (flag & FLAG_FILE_RECOVERY)
- g_string_append (str, "recovery ");
-
- if (flag & FLAG_FILE_CREATE_DIR)
- g_string_append (str, "createdir ");
-
- if (flag & FLAG_FILE_UPDATE_OIN)
- g_string_append (str, "upd_oin ");
-
- if (flag & FLAG_FILE_RELEASE_MASTER)
- g_string_append (str, "rls_mstr ");
-
- if (flag & FLAG_RELEASE_DENTRY)
- g_string_append (str, "rls_dntry ");
-
- if (flag & FLAG_CHANGE_MASTER)
- g_string_append (str, "chng_mstr ");
-
- if (flag & FLAG_ADD_OIN_MAP)
- g_string_append (str, "add_oin ");
-
- if (flag & FLAG_DIR)
- g_string_append (str, "dir ");
-
- if (flag & FLAG_REMASTER)
- g_string_append (str, "re_mstr ");
-
- if (flag & FLAG_FAST_PATH_LOCK)
- g_string_append (str, "fast_path");
-
- if (flag & FLAG_FILE_RELEASE_CACHE)
- g_string_append (str, "rls_cache ");
-
- if (flag & FLAG_FILE_TRUNCATE)
- g_string_append (str, "trunc ");
-
- if (flag & FLAG_DROP_READONLY)
- g_string_append (str, "drop_ro ");
-
- if (flag & FLAG_READDIR)
- g_string_append (str, "rddir ");
-
- if (flag & FLAG_ACQUIRE_LOCK)
- g_string_append (str, "acq ");
-
- if (flag & FLAG_RELEASE_LOCK)
- g_string_append (str, "rls ");
-
- if (flag & ~(FLAG_FILE_CREATE | FLAG_FILE_EXTEND | FLAG_FILE_DELETE |
- FLAG_FILE_RENAME | FLAG_FILE_UPDATE | FLAG_FILE_RECOVERY |
- FLAG_FILE_CREATE_DIR | FLAG_FILE_UPDATE_OIN |
- FLAG_FILE_RELEASE_MASTER | FLAG_RELEASE_DENTRY |
- FLAG_CHANGE_MASTER | FLAG_ADD_OIN_MAP | FLAG_DIR |
- FLAG_REMASTER | FLAG_FAST_PATH_LOCK |
- FLAG_FILE_RELEASE_CACHE | FLAG_FILE_TRUNCATE |
- FLAG_DROP_READONLY | FLAG_READDIR | FLAG_ACQUIRE_LOCK |
- FLAG_RELEASE_LOCK))
- g_string_append (str, "unknown");
-
- if (!str->len)
- g_string_append (str, "none");
-
- return ;
+ err = ocfs2_snprint_feature_flags(buf, count, &flags);
+ if (err)
+ com_err(gbls.cmd, err, "while processing ro compat flags");
}
/*
--
1.7.0.4
More information about the Ocfs2-tools-devel
mailing list