[Ocfs2-tools-devel] [PATCH 09/19] Ocfs2-tools: Add running codes for '--volinfo' in operation.c

tristan tristan.ye at oracle.com
Sun Apr 18 20:12:41 PDT 2010


Sunil Mushran wrote:
>
> 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/operations.c | 134 
>> +++++++++++++++++++++++++++++++++++++++++++++++++++
>> 1 files changed, 134 insertions(+), 0 deletions(-)
>>
>> diff --git a/o2info/operations.c b/o2info/operations.c
>> index fbb9d18..6f2c9c7 100644
>> --- a/o2info/operations.c
>> +++ b/o2info/operations.c
>> @@ -67,3 +67,137 @@ static void o2i_error(struct o2info_operation 
>> *op, const char *fmt, ...)
>>
>> return;
>> }
>> +
>> +struct o2info_volinfo {
>> + uint32_t blocksize;
>> + uint32_t clustersize;
>> + uint16_t slotnum;
>> + uint8_t label[OCFS2_INFO_MAX_VOL_LABEL_LEN];
>> + union {
>> + uint8_t uuid_str[OCFS2_INFO_VOL_UUIDSTR_LEN];
>> + uint8_t uuid[OCFS2_INFO_VOL_UUID_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->slotnum = sb->s_max_slots;
>> + memcpy(vf->label, sb->s_label, OCFS2_INFO_MAX_VOL_LABEL_LEN);
>> + memcpy(vf->uuid, sb->s_uuid, OCFS2_INFO_VOL_UUID_LEN);
>
> Why not use fs->uuid_str?

Good catch.

>
>> +
>> + return rc;
>> +}
>> +
>> +static int get_volinfo_ioctl(struct o2info_operation *op,
>> + int fd,
>> + struct o2info_volinfo *vf)
>> +{
>> + int rc = 0;
>> +
>> + struct ocfs2_info_blocksize brq;
>> + struct ocfs2_info_clustersize crq;
>> + struct ocfs2_info_slotnum srq;
>> + struct ocfs2_info_label lrq;
>> + struct ocfs2_info_uuid urq;
>> +
>> + memset(vf, 0, sizeof(*vf));
>> +
>> + o2info_fill_request(&brq, OCFS2_INFO_BLOCKSIZE, no_coherency);
>> + o2info_fill_request(&crq, OCFS2_INFO_CLUSTERSIZE, no_coherency);
>> + o2info_fill_request(&srq, OCFS2_INFO_SLOTNUM, no_coherency);
>> + o2info_fill_request(&lrq, OCFS2_INFO_LABEL, no_coherency);
>> + o2info_fill_request(&urq, OCFS2_INFO_UUID, no_coherency);
>> +
>> + uint64_t reqs[5] = {(unsigned long)&brq,
>> + (unsigned long)&crq,
>> + (unsigned long)&srq,
>> + (unsigned long)&lrq,
>> + (unsigned long)&urq};
>> +
>> + struct ocfs2_info info = {
>> + .info_requests = (uint64_t)reqs,
>> + .info_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 (brq.ir_request.ir_flags & OCFS2_INFO_FL_FILLED)
>> + vf->blocksize = brq.ir_blocksize;
>> +
>> + if (crq.ir_request.ir_flags & OCFS2_INFO_FL_FILLED)
>> + vf->clustersize = crq.ir_clustersize;
>> +
>> + if (srq.ir_request.ir_flags & OCFS2_INFO_FL_FILLED)
>> + vf->slotnum = srq.ir_slotnum;
>> +
>> + if (lrq.ir_request.ir_flags & OCFS2_INFO_FL_FILLED)
>> + memcpy(vf->label, lrq.ir_label, OCFS2_INFO_MAX_VOL_LABEL_LEN);
>> +
>> + if (urq.ir_request.ir_flags & OCFS2_INFO_FL_FILLED)
>> + memcpy(vf->uuid_str, urq.ir_uuid_str,
>> + OCFS2_INFO_VOL_UUIDSTR_LEN);
>> +
>> +out:
>> + return rc;
>> +}
>> +
>> +static int volinfo_run(struct o2info_operation *op,
>> + struct o2info_method *om,
>> + void *arg)
>> +{
>> + int i, rc = 0;
>> + static struct o2info_volinfo vf;
>> +
>> + const char *items[] = {
>> + "Block Size:",
>> + "Cluster Size:",
>> + "Node Slots:",
>> + "Label:",
>> + "UUID:"
>> + };
>
>
> #define VOLINFO \
> "Block Size : %u\n"
> "Cluster Size: %u\n"
> "Max Slots : %u\n"
> "Volume Label: %s\n"
> "Volume UUID : %s\n";
>
> fprintf(stdout, VOLINFO, vf.blocksize, ...);

Good idea.

>
>
>
>> +
>> + 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, " %s %u\n", items[0], vf.blocksize);
>> + fprintf(stdout, "%s %u\n", items[1], vf.clustersize);
>> + fprintf(stdout, " %s %u\n", items[2], vf.slotnum);
>> + fprintf(stdout, " %s %.*s\n", items[3],
>> + OCFS2_INFO_MAX_VOL_LABEL_LEN, vf.label);
>> + fprintf(stdout, " %s ", items[4]);
>> + if (om->om_method == O2INFO_USE_IOCTL) {
>> + for (i = 0; i < OCFS2_INFO_VOL_UUIDSTR_LEN; i++)
>> + fprintf(stdout, "%c", vf.uuid_str[i]);
>> + } else {
>> + for (i = 0; i < OCFS2_INFO_VOL_UUID_LEN; i++)
>> + fprintf(stdout, "%02X", vf.uuid[i]);
>> + }
>> +
>> + fprintf(stdout, "\n");
>> +
>> +out:
>> + return rc;
>> +}
>> +
>> +DEFINE_O2INFO_OP(volinfo,
>> + volinfo_run,
>> + NULL);
>




More information about the Ocfs2-tools-devel mailing list