[Ocfs2-tools-devel] [PATCH 5/6] O2info: Add running codes for '--volinfo'.
Tristan Ye
tristan.ye at oracle.com
Thu Apr 22 01:01:26 PDT 2010
Task of '--volinfo' will be capable of two approaches, including
libocfs2 and ioctl solutions.
Signed-off-by: Tristan Ye <tristan.ye at oracle.com>
---
o2info/o2info.c | 15 +++++
o2info/operations.c | 149 +++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 164 insertions(+), 0 deletions(-)
diff --git a/o2info/o2info.c b/o2info/o2info.c
index 1e281d9..0dff173 100644
--- a/o2info/o2info.c
+++ b/o2info/o2info.c
@@ -35,6 +35,7 @@
#include "utils.h"
extern struct o2info_operation fs_features_op;
+extern struct o2info_operation volinfo_op;
static LIST_HEAD(o2info_op_task_list);
static int o2info_op_task_count;
@@ -113,11 +114,25 @@ static struct o2info_option fs_features_option = {
.opt_private = NULL,
};
+static struct o2info_option volinfo_option = {
+ .opt_option = {
+ .name = "volinfo",
+ .val = CHAR_MAX,
+ .has_arg = 0,
+ .flag = NULL,
+ },
+ .opt_help = " --volinfo",
+ .opt_handler = NULL,
+ .opt_op = &volinfo_op,
+ .opt_private = NULL,
+};
+
static struct o2info_option *options[] = {
&help_option,
&version_option,
&coherency_option,
&fs_features_option,
+ &volinfo_option,
NULL,
};
diff --git a/o2info/operations.c b/o2info/operations.c
index d2a190c..1e3ac13 100644
--- a/o2info/operations.c
+++ b/o2info/operations.c
@@ -225,3 +225,152 @@ out:
DEFINE_O2INFO_OP(fs_features,
fs_features_run,
NULL);
+
+struct o2info_volinfo {
+ uint32_t blocksize;
+ uint32_t clustersize;
+ uint16_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)
+{
+ int rc = 0, flags = 0;
+
+ struct ocfs2_info_blocksize oib;
+ struct ocfs2_info_clustersize oic;
+ struct ocfs2_info_maxslots oim;
+ struct ocfs2_info_label oil;
+ struct ocfs2_info_uuid oiu;
+
+ memset(vf, 0, sizeof(*vf));
+ flags |= cluster_coherent;
+
+ o2info_fill_request((struct ocfs2_info_request *)&oib, sizeof(oib),
+ OCFS2_INFO_BLOCKSIZE, flags);
+ o2info_fill_request((struct ocfs2_info_request *)&oic, sizeof(oic),
+ OCFS2_INFO_CLUSTERSIZE, flags);
+ o2info_fill_request((struct ocfs2_info_request *)&oim, sizeof(oim),
+ OCFS2_INFO_MAXSLOTS, flags);
+ o2info_fill_request((struct ocfs2_info_request *)&oil, sizeof(oil),
+ OCFS2_INFO_LABEL, flags);
+ o2info_fill_request((struct ocfs2_info_request *)&oiu, sizeof(oiu),
+ OCFS2_INFO_UUID, flags);
+
+ uint64_t reqs[5] = {(unsigned long)&oib,
+ (unsigned long)&oic,
+ (unsigned long)&oim,
+ (unsigned long)&oil,
+ (unsigned long)&oiu};
+
+ struct ocfs2_info info = {
+ .oi_requests = (uint64_t)reqs,
+ .oi_count = 5,
+ };
+
+ rc = ioctl(fd, OCFS2_IOC_INFO, &info);
+ if (rc) {
+ rc = errno;
+ o2i_error(op, "ioctl failed: %s\n", strerror(rc));
+ goto out;
+ }
+
+ if (oib.ib_req.ir_flags & OCFS2_INFO_FL_FILLED)
+ vf->blocksize = oib.ib_blocksize;
+
+ if (oic.ic_req.ir_flags & OCFS2_INFO_FL_FILLED)
+ vf->clustersize = oic.ic_clustersize;
+
+ if (oim.im_req.ir_flags & OCFS2_INFO_FL_FILLED)
+ vf->maxslots = oim.im_max_slots;
+
+ if (oil.il_req.ir_flags & OCFS2_INFO_FL_FILLED)
+ memcpy(vf->label, oil.il_label, OCFS2_MAX_VOL_LABEL_LEN);
+
+ if (oiu.iu_req.ir_flags & OCFS2_INFO_FL_FILLED)
+ memcpy(vf->uuid_str, oiu.iu_uuid_str, OCFS2_TEXT_UUID_LEN + 1);
+
+ rc = get_fs_features_ioctl(op, fd, &(vf->ofs));
+
+out:
+ return rc;
+}
+
+static int volinfo_run(struct o2info_operation *op,
+ struct o2info_method *om,
+ void *arg)
+{
+ int rc = 0;
+ static struct o2info_volinfo vf;
+
+ char *compat = NULL;
+ char *incompat = NULL;
+ char *rocompat = NULL;
+ char *features = NULL;
+
+#define VOLINFO " Block Size: %u\n" \
+ "Cluster Size: %u\n" \
+ " Max Slots: %u\n" \
+ "Volume Label: %s\n" \
+ " Volume UUID: %s\n"
+
+ 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);
+ if (rc)
+ goto out;
+
+ rc = o2info_get_compat_flag(vf.ofs.compat, &compat);
+ if (rc)
+ goto out;
+
+ rc = o2info_get_incompat_flag(vf.ofs.incompat, &incompat);
+ if (rc)
+ goto out;
+
+ rc = o2info_get_rocompat_flag(vf.ofs.rocompat, &rocompat);
+ if (rc)
+ goto out;
+
+ features = malloc(strlen(compat) + strlen(incompat) +
+ strlen(rocompat) + 3);
+
+ sprintf(features, "%s %s %s", compat, incompat, rocompat);
+
+ fprintf(stdout, VOLINFO, vf.blocksize, vf.clustersize,
+ vf.maxslots, vf.label, vf.uuid_str);
+
+ o2info_print_line(" Features:", features, ' ');
+
+out:
+ return rc;
+}
+
+DEFINE_O2INFO_OP(volinfo,
+ volinfo_run,
+ NULL);
--
1.5.5
More information about the Ocfs2-tools-devel
mailing list