[Ocfs2-tools-devel] [PATCH 4/8] O2info: Add running codes for '--volinfo'.

Sunil Mushran sunil.mushran at oracle.com
Tue Apr 20 16:50:14 PDT 2010


I see no reason why the features is also not part of volinfo. We can have
a separate fs-features option too. I like this because we get all the info
in one place.

The output should look like this.

Label : label-max1
UUID : 81AC29CCF77C4F16A49022AE20A56D8B
Block Size : 4096
Cluster Size : 4096
Node Slots : 8
Features : backup-super strict-journal-super sparse extended-slotmap
Features : metaecc xattr refcount unwritten

Notice the multiple lines for Features. This is not only readable but also
grep-able, awk-able, etc. Keep the Features to 70-80 chars max.

Sunil

Tristan Ye wrote:
> 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/main.c       |   16 +++++++
>  o2info/operations.c |  114 +++++++++++++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 130 insertions(+), 0 deletions(-)
>
> diff --git a/o2info/main.c b/o2info/main.c
> index 2ccc6b0..bda7dce 100644
> --- a/o2info/main.c
> +++ b/o2info/main.c
> @@ -34,6 +34,8 @@
>  
>  #include "utils.h"
>  
> +extern struct o2info_operation volinfo_op;
> +
>  static LIST_HEAD(o2info_op_task_list);
>  static int o2info_op_task_count;
>  int no_coherency;
> @@ -77,9 +79,23 @@ static struct o2info_option version_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,
> +	&volinfo_option,
>  	NULL,
>  };
>  
> diff --git a/o2info/operations.c b/o2info/operations.c
> index 1162f5e..f2abf9f 100644
> --- a/o2info/operations.c
> +++ b/o2info/operations.c
> @@ -66,3 +66,117 @@ static void o2i_error(struct o2info_operation *op, const char *fmt, ...)
>  
>  	return;
>  }
> +
> +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_VOL_UUIDSTR_LEN];
> +};
> +
> +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_VOL_UUIDSTR_LEN);
> +
> +	return rc;
> +}
> +
> +static int get_volinfo_ioctl(struct o2info_operation *op,
> +			     int fd,
> +			     struct o2info_volinfo *vf)
> +{
> +	int rc = 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));
> +
> +	o2info_fill_request(&oib, OCFS2_INFO_BLOCKSIZE, no_coherency);
> +	o2info_fill_request(&oic, OCFS2_INFO_CLUSTERSIZE, no_coherency);
> +	o2info_fill_request(&oim, OCFS2_INFO_MAXSLOTS, no_coherency);
> +	o2info_fill_request(&oil, OCFS2_INFO_LABEL, no_coherency);
> +	o2info_fill_request(&oiu, OCFS2_INFO_UUID, no_coherency);
> +
> +	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_VOL_UUIDSTR_LEN);
> +
> +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;
> +
> +#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;
> +
> +	fprintf(stdout, VOLINFO, vf.blocksize, vf.clustersize,
> +		vf.maxslots, vf.label, vf.uuid_str);
> +out:
> +	return rc;
> +}
> +
> +DEFINE_O2INFO_OP(volinfo,
> +		 volinfo_run,
> +		 NULL);
>   




More information about the Ocfs2-tools-devel mailing list