ITEM: R0842L

Samples of C code using the 'lvm_queryvg' subroutine


NOTE:  Information in this document is correct to the best of our
       knowledge at the time of this writing.  

       Please use this information with care.  IBM will not be
       responsible for damages of any kind resulting from its use.
       The use of this information is the sole responsibility of
       the customer and depends on the customer's ability to eval-
       uate and integrate this information into the customer's
       operational environment.

Here are a couple of code samples that use the lvm_queryvg command.
Please note that these are samples only and IBM does not provide
technical support for this code.  These program will need to be 
modified to provide a higher level of error checking and also to
provide any other functionality that you need.  These modifications
would be up to you.

The first example uses the lvm_queryvg subroutine.  It requires
two arguments to run: the volume group id and the name of a disk
in the volume group.  The name of a disk in the volume group is
optional, but must be specified if the volume group is not varied
on.

The second example also demonstrates accessing the ODM in order to
get the VGID of the specified volume group.  getvg requires two
arguments to run: the volume group name and the name of a disk in
the volume group.  Again, the pv name is optional...

Note the use of sscanf in order to setup the VGID in the appropriate
format for the lvm_queryvg subroutine.

Here are the samples:

\#include\
\#include\
\#include\
/**************************************************/
/* myqueryvg -- Calls lvm_queryvg.                */
/*                                                */
/* To compile:  cc -o myqueryvg myqueryvg.c -llvm */
/*                                                */
/* To run: myqueryvg VGID [DISK_IN_VG]            */
/*                                                */
/**************************************************/
main(int argc, char **argv)
{struct queryvg *query;
struct unique_id vg_id;
char sstring[40];
int rc=0, i;

sscanf(argv[1], "%8x", &vg_id.word1);
sscanf(argv[1]+8, "%8x", &vg_id.word2);
rc = lvm_queryvg(&vg_id, &query, argv[2]);
if (rc != 0)
{  printf("errno = %d\\n", errno);
  perror ("myqueryvg: lvm_queryvg ");
}printf("vg_id = %08x%8x\\n", vg_id.word1, vg_id.word2);
printf("pvname = %s\\n", argv[2]);
printf("maxlvs = %d\\n", query->maxlvs);
printf("ppsize = %d\\n", query->ppsize);
printf("freespace = %d\\n", query->freespace);
printf("num_lvs = %d\\n", query->num_lvs);
printf("num_pvs = %d\\n", query->num_pvs);
printf("total_vgdas = %d\\n", query->total_vgdas);
}
\#include\
\#include\
\#include\
\#include\
/**************************************************/
/* getvg -- Calls odm_get_first and lvm_queryvg.  */
/*                                                */
/* To compile:  cc -o getvg getvg.c -lodm -llvm   */
/*                                                */
/* To run: getvg VGNAME [DISK_IN_VG]              */
/*                                                */
/**************************************************/
main(int argc, char **argv)
{FILE *odmfile = fopen("./odmfile", "w");
struct CuAt CuAt, CuAt1;
struct queryvg *query;
struct unique_id vg_id;
struct Class *my_CLASS;
char sstring[40], odmtype[20];
int rc=0, i;

odm_initialize();

my_CLASS = odm_mount_class("CuAt");
if ((int) my_CLASS == -1 || my_CLASS == NULL)
{  printf("odmerrno = %d\\n", odmerrno);
  perror("getpdata: odm_mount_class"), exit(-1);
}
sprintf(sstring,"name='%s' and attribute='vgserial_id'", argv[1]);
rc = (int)odm_get_first(my_CLASS, sstring, &CuAt1);
if (rc==0)
{  printf("odmerrno = %d\\n", odmerrno);
  printf("errno = %d\\n", errno);
  perror("getpdata: odm_get_first");
}printf("name = %s\\n", CuAt1.name);
printf("attribute = %s\\n", CuAt1.attribute);
printf("value = %s\\n", CuAt1.value);
sscanf(CuAt1.value, "%8x", &vg_id.word1);
sscanf(CuAt1.value+8, "%8x", &vg_id.word2);
odm_terminate();
printf("vg_id = %08x%8x\\n", vg_id.word1, vg_id.word2);

rc = lvm_queryvg(&vg_id, &query, argv[2]);
if ( rc != 0 )
{  printf("errno = %d\\n", errno);
  perror ("getvg: lvm_queryvg ");
}
printf("vgname = %s\\n", argv[1]);
printf("vg_id = %08x%8x\\n", vg_id.word1, vg_id.word2);
printf("pvname = %s\\n", argv[2]);
printf("maxlvs = %d\\n", query->maxlvs);
printf("ppsize = %d\\n", query->ppsize);
printf("freespace = %d\\n", query->freespace);
printf("num_lvs = %d\\n", query->num_lvs);
printf("num_pvs = %d\\n", query->num_pvs);
printf("total_vgdas = %d\\n", query->total_vgdas);


Support Line: Samples of C code using the 'lvm_queryvg' subroutine ITEM: R0842L
Dated: January 1995 Category: N/A
This HTML file was generated 99/06/24~13:30:37
Comments or suggestions? Contact us