Operating System - HP-UX
1753659 Members
5908 Online
108798 Solutions
New Discussion юеВ

Re: How to get LVM info from inside a C program?

 
Rebecca Callan
Occasional Advisor

Re: How to get LVM info from inside a C program?

What I really need to know is the names of the volume groups on the system and which disks belong to the group. I did a strings on the /etc/lvmtab file and this did give somoe useful info. I can use a similar algorithm to strings inside my program. But is this a reliable method of getting this information. Is /etc/lvmtab automatically updated to reflect changes in the system or is it only updated under certain conditions?

I have also done the same on the files under /etc/lvmconf which also give this information but from what I read these files are not updated automatically but only by the user - if the user doesn't do it they won't be updated - is this correct? Is ths the same for the lvmtab file?
Andy Monks
Honored Contributor

Re: How to get LVM info from inside a C program?

/etc/lvmtab 'should' always be correct, and by default will be.

lvmtab is a binary file, and therefore working out the file format wouldn't be difficult to achieve. Just dump it out in hex and compare a few machines, it's pretty simple.
Rebecca Callan
Occasional Advisor

Re: How to get LVM info from inside a C program?

Thanks for your help I have quite alot of what I need. The main info missing now is the size info. I can find out the size of a disk and a logical volume using ioctl() with the DIOC_CAPACITY cmd on the character special file ie /dev/rdsk/c1t2d0 or /dev/vg00/rlvol1. Is there a character special file for the volume group (that I could use to determine the vg size) I tried the /dev/vg00/group file but it didn't work (ioctl failed with errno = 22 (bad argument)). Is there any other way to determine the size of the volume group?

I would also like to get alloc/unalloc MB for the disks and the volume groups. This can be determined from the output of the executable you sent so I guess I can do this the same way - by reading the lvmrec, VGDA, etc from the disk character special file - but I don't know the format of the structures to read this info into. Do you know the structure definitions or can you point me to some documentation on this?