[Ocfs2-tools-devel] [PATCH 1/3] O2info: Make parts of o2info routines public.
Tristan Ye
tristan.ye at oracle.com
Wed Nov 3 04:08:58 PDT 2010
The idea here is to make parts of o2info operations public, a very original
intention is driven by the thoughts of having some o2info functions sharable
with debugfs.ocfs2, so that we'll be able to do 'freefrag'/'freeinode' things
in debugfs as well.
While such kind of o2info funcs were not that friendly/common enough to become
sharable globally. that's the reason why we keep these under o2info in terms of
libo2info instead of libocfs2.
Further patches about 'freefrag' and 'freeinode' of o2info/debugfs.ocfs2 is going
to be posted, being based on this patch.
Signed-off-by: Tristan Ye <tristan.ye at oracle.com>
---
o2info/Makefile | 20 +++++++--
o2info/libo2info.c | 97 ++++++++++++++++++++++++++++++++++++++++++++++
o2info/libo2info.h | 47 ++++++++++++++++++++++
o2info/operations.c | 106 ++-------------------------------------------------
4 files changed, 163 insertions(+), 107 deletions(-)
create mode 100644 o2info/libo2info.c
create mode 100644 o2info/libo2info.h
diff --git a/o2info/Makefile b/o2info/Makefile
index 70d9cac..ec14313 100644
--- a/o2info/Makefile
+++ b/o2info/Makefile
@@ -21,18 +21,28 @@ DEFINES = -DVERSION=\"$(VERSION)\"
MANS = o2info.1
HFILES = o2info.h \
- utils.h
+ utils.h \
+ libo2info.h
CFILES = \
o2info.c \
- operations.c \
+ operations.c \
utils.c
+LIBO2INFO_CFILES = libo2info.c
+
OBJS = $(subst .c,.o,$(CFILES))
-DIST_FILES = $(CFILES) $(HFILES) o2info.1.in
+LIBO2INFO_OBJS = $(subst .c,.o,$(LIBO2INFO_CFILES))
+
+DIST_FILES = $(CFILES) $(LIBO2INFO_CFILES) $(HFILES) o2info.1.in
+
+libo2info.a: $(LIBO2INFO_OBJS)
+ rm -f $@
+ $(AR) r $@ $^
+ $(RANLIB) $@
-o2info: $(OBJS) $(LIBOCFS2_DEPS)
- $(LINK) $(LIBOCFS2_LIBS) $(LIBTOOLS_INTERNAL_LIBS) $(COM_ERR_LIBS)
+o2info: $(OBJS) $(LIBOCFS2_DEPS) libo2info.a
+ $(LINK) $(LIBOCFS2_LIBS) $(LIBTOOLS_INTERNAL_LIBS) $(COM_ERR_LIBS) libo2info.a
include $(TOPDIR)/Postamble.make
diff --git a/o2info/libo2info.c b/o2info/libo2info.c
new file mode 100644
index 0000000..6db04d0
--- /dev/null
+++ b/o2info/libo2info.c
@@ -0,0 +1,97 @@
+/* -*- mode: c; c-basic-offset: 8; -*-
+ * vim: noexpandtab sw=8 ts=8 sts=0:
+ *
+ * libo2info.c
+ *
+ * Shared routines for the ocfs2 o2info utility
+ *
+ * Copyright (C) 2010 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 version 2 as published by the Free Software Foundation.
+ *
+ * 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.
+ */
+
+#define _XOPEN_SOURCE 600
+#define _LARGEFILE64_SOURCE
+#define _GNU_SOURCE
+
+#include "ocfs2/ocfs2.h"
+#include "tools-internal/verbose.h"
+#include "libo2info.h"
+
+int o2info_get_fs_features(ocfs2_filesys *fs, struct o2info_fs_features *ofs)
+{
+ int rc = 0;
+ struct ocfs2_super_block *sb = NULL;
+
+ memset(ofs, 0, sizeof(*ofs));
+
+ sb = OCFS2_RAW_SB(fs->fs_super);
+ ofs->compat = sb->s_feature_compat;
+ ofs->incompat = sb->s_feature_incompat;
+ ofs->rocompat = sb->s_feature_ro_compat;
+
+ return rc;
+}
+
+int o2info_get_volinfo(ocfs2_filesys *fs, struct o2info_volinfo *vf)
+{
+ int rc = 0;
+ struct ocfs2_super_block *sb = NULL;
+
+ memset(vf, 0, sizeof(*vf));
+
+ sb = OCFS2_RAW_SB(fs->fs_super);
+ vf->blocksize = fs->fs_blocksize;
+ vf->clustersize = fs->fs_clustersize;
+ vf->maxslots = sb->s_max_slots;
+ memcpy(vf->label, sb->s_label, OCFS2_MAX_VOL_LABEL_LEN);
+ memcpy(vf->uuid_str, fs->uuid_str, OCFS2_TEXT_UUID_LEN + 1);
+ rc = o2info_get_fs_features(fs, &(vf->ofs));
+
+ return rc;
+}
+
+int o2info_get_mkfs(ocfs2_filesys *fs, struct o2info_mkfs *oms)
+{
+ errcode_t err;
+ uint64_t blkno;
+ char *buf = NULL;
+ struct ocfs2_dinode *di = NULL;
+
+ memset(oms, 0, sizeof(*oms));
+
+ err = ocfs2_malloc_block(fs->fs_io, &buf);
+ if (err) {
+ tcom_err(err, "while allocating buffer");
+ goto out;
+ }
+
+ err = ocfs2_lookup_system_inode(fs, JOURNAL_SYSTEM_INODE, 0, &blkno);
+ if (err) {
+ tcom_err(err, "while looking up journal system inode");
+ goto out;
+ }
+
+ err = ocfs2_read_inode(fs, blkno, buf);
+ if (err) {
+ tcom_err(err, "while reading journal system inode");
+ goto out;
+ }
+
+ di = (struct ocfs2_dinode *)buf;
+ oms->journal_size = di->i_size;
+ err = o2info_get_volinfo(fs, &(oms->ovf));
+
+out:
+ if (buf)
+ ocfs2_free(&buf);
+
+ return err;
+}
diff --git a/o2info/libo2info.h b/o2info/libo2info.h
new file mode 100644
index 0000000..081eace
--- /dev/null
+++ b/o2info/libo2info.h
@@ -0,0 +1,47 @@
+/* -*- mode: c; c-basic-offset: 8; -*-
+ * vim: noexpandtab sw=8 ts=8 sts=0:
+ *
+ * libo2info.h
+ *
+ * o2info helper library prototypes.
+ *
+ * Copyright (C) 2010 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 version 2 as published by the Free Software Foundation.
+ *
+ * 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.
+ */
+
+#ifndef __LIBO2INFO_H__
+#define __LIBO2INFO_H__
+
+struct o2info_fs_features {
+ uint32_t compat;
+ uint32_t incompat;
+ uint32_t rocompat;
+};
+
+struct o2info_volinfo {
+ uint32_t blocksize;
+ uint32_t clustersize;
+ uint32_t maxslots;
+ uint8_t label[OCFS2_MAX_VOL_LABEL_LEN];
+ uint8_t uuid_str[OCFS2_TEXT_UUID_LEN + 1];
+ struct o2info_fs_features ofs;
+};
+
+struct o2info_mkfs {
+ struct o2info_volinfo ovf;
+ uint64_t journal_size;
+};
+
+int o2info_get_fs_features(ocfs2_filesys *fs, struct o2info_fs_features *ofs);
+int o2info_get_volinfo(ocfs2_filesys *fs, struct o2info_volinfo *vf);
+int o2info_get_mkfs(ocfs2_filesys *fs, struct o2info_mkfs *oms);
+
+#endif
diff --git a/o2info/operations.c b/o2info/operations.c
index 39038bf..f7216d8 100644
--- a/o2info/operations.c
+++ b/o2info/operations.c
@@ -32,6 +32,7 @@
#include "tools-internal/verbose.h"
#include "utils.h"
+#include "libo2info.h"
extern void print_usage(int rc);
extern int cluster_coherent;
@@ -114,12 +115,6 @@ static void o2i_scan_requests(struct o2info_operation *op,
*fills = num_filled;
}
-struct o2info_fs_features {
- uint32_t compat;
- uint32_t incompat;
- uint32_t rocompat;
-};
-
static int get_fs_features_ioctl(struct o2info_operation *op,
int fd,
struct o2info_fs_features *ofs)
@@ -161,23 +156,6 @@ out:
return rc;
}
-static int get_fs_features_libocfs2(struct o2info_operation *op,
- ocfs2_filesys *fs,
- struct o2info_fs_features *ofs)
-{
- int rc = 0;
- struct ocfs2_super_block *sb = NULL;
-
- memset(ofs, 0, sizeof(*ofs));
-
- sb = OCFS2_RAW_SB(fs->fs_super);
- ofs->compat = sb->s_feature_compat;
- ofs->incompat = sb->s_feature_incompat;
- ofs->rocompat = sb->s_feature_ro_compat;
-
- return rc;
-}
-
static void o2info_print_line(char const *qualifier, char *content,
char splitter)
{
@@ -242,7 +220,7 @@ static int fs_features_run(struct o2info_operation *op,
if (om->om_method == O2INFO_USE_IOCTL)
rc = get_fs_features_ioctl(op, om->om_fd, &ofs);
else
- rc = get_fs_features_libocfs2(op, om->om_fs, &ofs);
+ rc = o2info_get_fs_features(om->om_fs, &ofs);
if (rc)
goto out;
@@ -285,35 +263,6 @@ DEFINE_O2INFO_OP(fs_features,
fs_features_run,
NULL);
-struct o2info_volinfo {
- uint32_t blocksize;
- uint32_t clustersize;
- uint32_t maxslots;
- uint8_t label[OCFS2_MAX_VOL_LABEL_LEN];
- uint8_t uuid_str[OCFS2_TEXT_UUID_LEN + 1];
- struct o2info_fs_features ofs;
-};
-
-static int get_volinfo_libocfs2(struct o2info_operation *op,
- ocfs2_filesys *fs,
- struct o2info_volinfo *vf)
-{
- int rc = 0;
- struct ocfs2_super_block *sb = NULL;
-
- memset(vf, 0, sizeof(*vf));
-
- sb = OCFS2_RAW_SB(fs->fs_super);
- vf->blocksize = fs->fs_blocksize;
- vf->clustersize = fs->fs_clustersize;
- vf->maxslots = sb->s_max_slots;
- memcpy(vf->label, sb->s_label, OCFS2_MAX_VOL_LABEL_LEN);
- memcpy(vf->uuid_str, fs->uuid_str, OCFS2_TEXT_UUID_LEN + 1);
- rc = get_fs_features_libocfs2(op, fs, &(vf->ofs));
-
- return rc;
-}
-
static int get_volinfo_ioctl(struct o2info_operation *op,
int fd,
struct o2info_volinfo *vf)
@@ -403,7 +352,7 @@ static int volinfo_run(struct o2info_operation *op,
if (om->om_method == O2INFO_USE_IOCTL)
rc = get_volinfo_ioctl(op, om->om_fd, &vf);
else
- rc = get_volinfo_libocfs2(op, om->om_fs, &vf);
+ rc = o2info_get_volinfo(om->om_fs, &vf);
if (rc)
goto out;
@@ -449,53 +398,6 @@ DEFINE_O2INFO_OP(volinfo,
volinfo_run,
NULL);
-struct o2info_mkfs {
- struct o2info_volinfo ovf;
- uint64_t journal_size;
-};
-
-static int get_mkfs_libocfs2(struct o2info_operation *op,
- ocfs2_filesys *fs,
- struct o2info_mkfs *oms)
-{
- errcode_t err;
- uint64_t blkno;
- char *buf = NULL;
- struct ocfs2_dinode *di = NULL;
-
- memset(oms, 0, sizeof(*oms));
-
- err = ocfs2_malloc_block(fs->fs_io, &buf);
- if (err) {
- tcom_err(err, "while allocating buffer");
- goto out;
- }
-
- err = ocfs2_lookup_system_inode(fs, JOURNAL_SYSTEM_INODE, 0, &blkno);
- if (err) {
- tcom_err(err, "while looking up journal system inode");
- goto out;
- } else
-
- err = ocfs2_read_inode(fs, blkno, buf);
- if (err) {
- tcom_err(err, "while reading journal system inode");
- goto out;
- }
-
- di = (struct ocfs2_dinode *)buf;
-
- oms->journal_size = di->i_size;
-
- err = get_volinfo_libocfs2(op, fs, &(oms->ovf));
-
-out:
- if (buf)
- ocfs2_free(&buf);
-
- return err;
-}
-
static int get_mkfs_ioctl(struct o2info_operation *op, int fd,
struct o2info_mkfs *oms)
{
@@ -618,7 +520,7 @@ static int mkfs_run(struct o2info_operation *op, struct o2info_method *om,
if (om->om_method == O2INFO_USE_IOCTL)
rc = get_mkfs_ioctl(op, om->om_fd, &oms);
else
- rc = get_mkfs_libocfs2(op, om->om_fs, &oms);
+ rc = o2info_get_mkfs(om->om_fs, &oms);
if (rc)
goto out;
--
1.5.5
More information about the Ocfs2-tools-devel
mailing list