Operating System - HP-UX
1753632 Members
5670 Online
108798 Solutions
New Discussion юеВ

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

 
Rebecca Callan
Occasional Advisor

How to get LVM info from inside a C program?

Hi,

I need to get info on LVM configuration from inside a C/C++ program - just basic stuff, a list of volume groups and what disks are in each group, and a list of logical volumes in each group and the size of each if these. I can't use system commands from inside the program as it can cause blocking issues. This info may be available from an ioctl() but I am not sure which command to pass it. I can't find any documentation about this at all.

Does anyone know how I can get this info? Any info or ideas on this would be much appreciated.

Thanks,
Rebecca
12 REPLIES 12
Andy Monks
Honored Contributor

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

The safest way is to use the pstat() system call. It has lvm info available to it.

After that it's called reading the headers from the disk and working out what's going on.

The advantage pstat() has is that you don't need to be root to run it and your program will be release independant.
Rebecca Callan
Occasional Advisor

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

pstat doesn't provide the name of the logical volume (only the device number- Is there a way to determine the volume name from the device number),it doesn't specify which volume group the logical volume is in and it doesn't give size info.
Also for disks same thing - it doesn't give the name of the disk only the device number and it doesn't specify which volume group (if any) it is in, or any size info.

This is what I still need to find out. As for reading the disk labels is there any standard way of doing this - an ioctl() or other call to retrieve this info.

Thanks alot for your help,
Rebecca
James A. Donovan
Honored Contributor

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

I'm not 100% sure, but I don't think HP provides any user callable functions to get that information. Commands like vgdisplay and lvdisplay come statically compiled, located under /sbin. They are provided this way, so that they can be used when the system is in single-user mode.

If you absolutely must use function calls, you may need to install Veritas VxFS for HP-UX.
Remember, wherever you go, there you are...
Andy Monks
Honored Contributor

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

The system only knows about the major/minor number.

The best thing to do, would be to traverse the /dev directory using fstat(). Then you could match up the lvol name to the major/minor number.
James A. Donovan
Honored Contributor

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

hmmm...yes, I guess pstat_getlv() will get you some info on logical volumes, but it doesn't look easy to decipher.
Remember, wherever you go, there you are...
Andy Monks
Honored Contributor

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

It doesn't really tell you that much about the lvol using pstat, and looking at discs isn't any better.

Therefore I would suggest just running the 'lvm' program attached (for hp-ux 11). Written by a colleague with the source code for lvm!.
Andy Monks
Honored Contributor

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

hmmm, it didn't attach.
Rebecca Callan
Occasional Advisor

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

Thanks alot for your help so far:

I ran the executable you sent and it does help a bit - the main problem here is how to do I map the Volume Group ID which looks like this: 565706537 964590021 to either a device number or the volume group name (ie vg00).
Andy Monks
Honored Contributor

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

basically you don't.

If the vg is on an array for example, it's possible you might import the vg onto multiple systems (at different times) under different names.

None of the lvm structures know the names of anything. The lvol's are all lvol minor number only (which usually ties up with the lvol name, but not always).

The machine id (from uname) is in the output from the 'lvm' command, so at least see the last machine that had the vg.