[Ocfs2-tools-devel] [PATCH 5/8] O2info: Add running codes for '--fs-features'.
Sunil Mushran
sunil.mushran at oracle.com
Tue Apr 20 16:53:55 PDT 2010
Tristan Ye wrote:
> Task of dumping fs features will also be capable of two approaches,
> including libocfs2 and ioctl methods.
>
> Signed-off-by: Tristan Ye <tristan.ye at oracle.com>
> ---
> o2info/main.c | 15 +++++++
> o2info/operations.c | 108 +++++++++++++++++++++++++++++++++++++++++++++++++++
> o2info/utils.c | 66 +++++++++++++++++++++++++++++++
> o2info/utils.h | 4 ++
> 4 files changed, 193 insertions(+), 0 deletions(-)
>
> diff --git a/o2info/main.c b/o2info/main.c
> index bda7dce..879eba5 100644
> --- a/o2info/main.c
> +++ b/o2info/main.c
> @@ -35,6 +35,7 @@
> #include "utils.h"
>
> extern struct o2info_operation volinfo_op;
> +extern struct o2info_operation fs_features_op;
>
> static LIST_HEAD(o2info_op_task_list);
> static int o2info_op_task_count;
> @@ -92,10 +93,24 @@ static struct o2info_option volinfo_option = {
> .opt_private = NULL,
> };
>
> +static struct o2info_option fs_features_option = {
> + .opt_option = {
> + .name = "fs-features",
> + .val = CHAR_MAX,
> + .has_arg = 0,
> + .flag = NULL,
> + },
> + .opt_help = " --fs-features",
> + .opt_handler = NULL,
> + .opt_op = &fs_features_op,
> + .opt_private = NULL,
> +};
> +
> static struct o2info_option *options[] = {
> &help_option,
> &version_option,
> &volinfo_option,
> + &fs_features_option,
> NULL,
> };
>
> diff --git a/o2info/operations.c b/o2info/operations.c
> index f2abf9f..1e79bec 100644
> --- a/o2info/operations.c
> +++ b/o2info/operations.c
> @@ -180,3 +180,111 @@ out:
> DEFINE_O2INFO_OP(volinfo,
> volinfo_run,
> NULL);
> +
> +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)
> +{
> + int rc = 0;
> + struct ocfs2_info_fs_features oif;
> +
> + memset(ofs, 0, sizeof(*ofs));
> +
> + o2info_fill_request(&oif, OCFS2_INFO_FS_FEATURES, no_coherency);
> +
> + uint64_t reqs[1] = {(unsigned long)&oif};
> +
> + struct ocfs2_info info = {
> + .oi_requests = (uint64_t)reqs,
> + .oi_count = 1,
> + };
> +
> + rc = ioctl(fd, OCFS2_IOC_INFO, &info);
> + if (rc) {
> + rc = errno;
> + o2i_error(op, "ioctl failed: %s\n", strerror(rc));
> + goto out;
> + }
> +
> + if (oif.if_req.ir_flags & OCFS2_INFO_FL_FILLED) {
> + ofs->compat = oif.if_compat_features;
> + ofs->incompat = oif.if_incompat_features;
> + ofs->rocompat = oif.if_ro_compat_features;
> + }
> +
> +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 int fs_features_run(struct o2info_operation *op,
> + struct o2info_method *om,
> + void *arg)
> +{
> + int rc = 0;
> + static struct o2info_fs_features ofs;
> +
> + char *compat = NULL;
> + char *incompat = NULL;
> + char *rocompat = NULL;
> +
> +#define FEATURES "Features: %s %s %s\n"
>
I know I suggested that. But can you change it to:
+#define FEATURES "%s %s %s\n"
The "Features: " is redundant.
> +
> + 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);
> + if (rc)
> + goto out;
> +
> + rc = o2info_get_compat_flag(ofs.compat, &compat);
> + if (rc)
> + goto out;
> +
> + rc = o2info_get_incompat_flag(ofs.incompat, &incompat);
> + if (rc)
> + goto out;
> +
> + rc = o2info_get_rocompat_flag(ofs.rocompat, &rocompat);
> + if (rc)
> + goto out;
> +
> + fprintf(stdout, FEATURES, compat, incompat, rocompat);
> +out:
> + if (compat)
> + ocfs2_free(&compat);
> +
> + if (incompat)
> + ocfs2_free(&incompat);
> +
> + if (rocompat)
> + ocfs2_free(&rocompat);
> +
> + return rc;
> +}
> +
> +DEFINE_O2INFO_OP(fs_features,
> + fs_features_run,
> + NULL);
> diff --git a/o2info/utils.c b/o2info/utils.c
> index b24c408..c10f25b 100644
> --- a/o2info/utils.c
> +++ b/o2info/utils.c
> @@ -31,6 +31,72 @@
>
> #include "utils.h"
>
> +int o2info_get_compat_flag(uint32_t flag, char **compat)
> +{
> + errcode_t err;
> + char buf[PATH_MAX];
> + ocfs2_fs_options flags = {
> + .opt_compat = flag,
> + };
> +
> + *buf = '\0';
> + err = ocfs2_snprint_feature_flags(buf, PATH_MAX, &flags);
> + if (!err) {
> + *compat = strdup(buf);
> + if (!*compat) {
> + errorf("No memory for allocation\n");
> + err = -1;
> + }
> + } else
> + tcom_err(err, "while processing feature flags");
> +
> + return err;
> +}
> +
> +int o2info_get_incompat_flag(uint32_t flag, char **incompat)
> +{
> + errcode_t err;
> + char buf[PATH_MAX];
> + ocfs2_fs_options flags = {
> + .opt_incompat = flag,
> + };
> +
> + *buf = '\0';
> + err = ocfs2_snprint_feature_flags(buf, PATH_MAX, &flags);
> + if (!err) {
> + *incompat = strdup(buf);
> + if (!*incompat) {
> + errorf("No memory for allocation\n");
> + err = -1;
> + }
> + } else
> + tcom_err(err, "while processing feature flags");
> +
> + return err;
> +}
> +
> +int o2info_get_rocompat_flag(uint32_t flag, char **rocompat)
> +{
> + errcode_t err;
> + char buf[PATH_MAX];
> + ocfs2_fs_options flags = {
> + .opt_ro_compat = flag,
> + };
> +
> + *buf = '\0';
> + err = ocfs2_snprint_feature_flags(buf, PATH_MAX, &flags);
> + if (!err) {
> + *rocompat = strdup(buf);
> + if (!*rocompat) {
> + errorf("No memory for allocation\n");
> + err = -1;
> + }
> + } else
> + tcom_err(err, "while processing feature flags");
> +
> + return err;
> +}
> +
> errcode_t o2info_open(struct o2info_method *om, int flags)
> {
> errcode_t err = 0;
> diff --git a/o2info/utils.h b/o2info/utils.h
> index 3cdbd50..93040e6 100644
> --- a/o2info/utils.h
> +++ b/o2info/utils.h
> @@ -22,6 +22,10 @@
>
> #include "o2info.h"
>
> +int o2info_get_compat_flag(uint32_t flag, char **compat);
> +int o2info_get_incompat_flag(uint32_t flag, char **incompat);
> +int o2info_get_rocompat_flag(uint32_t flag, char **rocompat);
> +
> int o2info_is_device(const char *path);
>
> errcode_t o2info_open(struct o2info_method *om, int flags);
>
More information about the Ocfs2-tools-devel
mailing list