[Ocfs2-tools-devel] [PATCH 10/19] Ocfs2-tools: Add running codes for '--fs-features' in operation.c
Sunil Mushran
sunil.mushran at oracle.com
Fri Apr 16 16:16:05 PDT 2010
So we want to hide terms like compat, incompat from the user.
As far as the user is concerned, these are features.
#define FEATURES "Features : %s %s %s\n"
fprintf(stdout, FEATURES, compat, incompat, rocompat);
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/operations.c | 118 +++++++++++++++++++++++++++++++++++++++++++++++++++
> 1 files changed, 118 insertions(+), 0 deletions(-)
>
> diff --git a/o2info/operations.c b/o2info/operations.c
> index 6f2c9c7..cd134e5 100644
> --- a/o2info/operations.c
> +++ b/o2info/operations.c
> @@ -201,3 +201,121 @@ 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 frq;
> +
> + memset(ofs, 0, sizeof(*ofs));
> +
> + o2info_fill_request(&frq, OCFS2_INFO_FS_FEATURES, no_coherency);
> +
> + uint64_t reqs[1] = {(unsigned long)&frq};
> +
> + struct ocfs2_info info = {
> + .info_requests = (uint64_t)reqs,
> + .info_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 (frq.ir_request.ir_flags & OCFS2_INFO_FL_FILLED) {
> + ofs->compat = frq.ir_compat_features;
> + ofs->incompat = frq.ir_incompat_features;
> + ofs->rocompat = frq.ir_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;
> +
> + const char *items[] = {
> + "Feature Compat:",
> + "Feature Incompat:",
> + "Feature RO compat:"
> + };
> +
> + 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, " %s %u %s\n", items[0], ofs.compat,
> + compat);
> + fprintf(stdout, " %s %u %s\n", items[1], ofs.incompat,
> + incompat);
> + fprintf(stdout, "%s %u %s\n", items[2], ofs.rocompat,
> + 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);
>
More information about the Ocfs2-tools-devel
mailing list