- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- pstat_getdisk() call doesn’t work properly in HPUX...
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-15-2007 01:20 AM - last edited on 01-01-2013 07:52 PM by Cathy_xu
10-15-2007 01:20 AM - last edited on 01-01-2013 07:52 PM by Cathy_xu
As per the man page, pstat_getdisk() call returns the number of instances, which could be 0 upon successful completion, otherwise a value of -1 is returned.
Please have a look at this sample program ->
#include <stdio.h>
#include
int main()
{
int j, ret;
struct pst_diskinfo sDiskData;
while(1)
{
ret = pstat_getdisk(&sDiskData, sizeof(sDiskData), 1, j);
if(ret<0)
{
printf("\nReturned with code %d \n",ret);
break;
}
printf("\n Ret Code : %d , Device Name : %s %d",ret,sDiskData.psd_drv_name.psd_name,sDiskData.psd_instance);
j++;
}
return 0;
}
On HP-UX 11.11 and 11.23, the call pstat_getdisk() returns series of ‘1’s then single ‘0’ and finally ‘-1’ and the program terminates successfully.
On HP-UX 11.31 the call pstat_getdisk() returns series of ‘1’s followed by series of ‘0’s and never returns ‘-1’, so the same program never terminates.
The workaround would be to replace the condition
if(ret<0)
with
if(ret==0)
But, will this call always returns ‘1’s followed by ‘0’s or there can be a case in which the call will return ‘0’ in between?
In another way, can we get an invalid index in between or all the valid disks are in sequence only?
P.S.This thread has been moved from HP-UX>System Administration to HP-UX > languages- HP Forums Moderator
Solved! Go to Solution.
- Tags:
- pstat
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-15-2007 01:48 AM
10-15-2007 01:48 AM
Re: pstat_getdisk() call doesn’t work properly in HPUX 11.31 (11i V3)
Else you should initialise any automatic variable before using it ( j for instance)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-15-2007 02:14 AM
10-15-2007 02:14 AM
Re: pstat_getdisk() call doesn’t work properly in HPUX 11.31 (11i V3)
You should ask for more.
I tried it just changing to ask for 2 elements (and providing 2 :-), but leaving the j++ in place. Then you get:
$ ./a.out
post j=0, Ret Code : 2/0 , Device Name : sdisk 1
post j=1, Ret Code : 2/0 , Device Name : sdisk 0
post j=2, Ret Code : 2/0 , Device Name : esdisk 2
post j=3, Ret Code : 1/0 , Device Name : esdisk 3
post j=4, Ret Code : 0/0 , Device Name : esdisk 3
Returned with code -1
But you should not blindly increment j, but rather add the number of returned elements, and stop when no more returned (ret=0)
fwiw... I dont' like the coding where j is not explicitly initialized to 0 and:
"ret = pstat_getdisk(&sDiskData, sizeof(sDiskData)...
Should be:
"ret = pstat_getdisk(&sDiskData[0], sizeof(struct pst_diskinfo)...
Corrected program, still a little crude/sloppy below.
hth,
Hein.
#define MAXDISK 2
#include
#include
#include
int main()
{
int j=1, ret, i=0, stopper=0;
struct pst_diskinfo sDiskData[MAXDISK];
while(stopper++<20)
{
ret = pstat_getdisk(&sDiskData[0], sizeof(struct pst_diskinfo), MAXDISK, j);
if(ret<0)
{
printf("\nReturned with code %d \n",ret);
break;
}
for (i=0;i
j,ret,errno,sDiskData[i].psd_drv_name.psd_name,sDiskData[i].psd_instance);
}
j+=ret;
}
return 0;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-15-2007 02:20 AM
10-15-2007 02:20 AM
Re: pstat_getdisk() call doesn’t work properly in HPUX 11.31 (11i V3)
The same program returns -1 on HPUX 11.11 and 11.23 after the end of disk list. In case of HPUX 11.31 it returns 0 continuously for the same disk (in this case, it gives a valid disk name).
My question is, what if the call returns â 0â for some intermediate disk and after that there are few more valid disks (for which it returns 1 again). Is it possible or not?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-15-2007 02:44 AM
10-15-2007 02:44 AM
SolutionThe call does not return a 'status = 0'
It returns: 0 elements returned.
It does not return the same value again,
it returns no value and you are looking at the now old context.
Looks like I posted an intermediate version of the test I did. Sorry. Below a re-try with the (silly!) addition of incrementing j after 0 elements are returned. For MAXDISK=2 it returns:
j=0,i=0, Ret Code : 2, Device Name : sdisk 1
j=1,i=1, Ret Code : 2, Device Name : sdisk 0
j=0,i=0, Ret Code : 2, Device Name : esdisk 2
j=1,i=1, Ret Code : 2, Device Name : esdisk 3
Returned with code -1, errno=0
For MAXDISK=3 it returns:
j=0,i=0, Ret Code : 3, Device Name : sdisk 1
j=1,i=1, Ret Code : 3, Device Name : sdisk 0
j=2,i=2, Ret Code : 3, Device Name : esdisk 2
j=0,i=0, Ret Code : 1, Device Name : esdisk 3
Returned with code -1, errno=0
Enjoy!
Hein.
$ cat tmp2.c
#define MAXDISK 2
#include
#include
#include
int main()
{
int j=0, ret, i=0, stopper=0;
struct pst_diskinfo sDiskData[MAXDISK];
while(stopper++<20)
{
ret = pstat_getdisk(&sDiskData[0], sizeof(struct pst_diskinfo), MAXDISK, j);
if(ret<0)
{
printf("\nReturned with code %d, errno=%d \n",ret,errno);
break;
}
if (ret) {
for (i=0;i
i, i, ret,sDiskData[i].psd_drv_name.psd_name,sDiskData[i].psd_instance);
}
j+=ret;
} else {
j++;
}
}
return 0;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-15-2007 03:20 AM
10-15-2007 03:20 AM
Re: pstat_getdisk() call doesn’t work properly in HPUX 11.31 (11i V3)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-15-2007 10:43 PM
10-15-2007 10:43 PM
Re: pstat_getdisk() call doesn’t work properly in HPUX 11.31 (11i V3)
1> Why this call, pstat_getdisk() is not working with 1 element for HPUX 11.31 whereas it works fine on older versions.
2> It doesnâ t give device sdisk0 on HPUX 11.11 and 11.23.
3>My program returns with errno=22. What does errno 22 stand for?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-15-2007 11:42 PM
10-15-2007 11:42 PM
Re: pstat_getdisk() call doesn’t work properly in HPUX 11.31 (11i V3)
- fewer system calls / locks
- more efficient in inner mode, user mode is cheaper
- this are dynamic lists, the closer you get to a 'snapshot' the better... allthough admittedly the diskinfo, unlike process info, is not going to change all that quickly!
If this bothers you much, and/or you think other processes mig break, then by all means please raise an official support call to HP
disk 0? I tried my test on td194, one of the HP testdrive system. As you can see in my output above "disk 0" came in out of order so to speak, but it was there. The documentation warns explicitly about stuff potentially appearign out of order.
$ grep EINVAL /usr/include/*/*err*
/usr/include/sys/errno.h:#define EINVAL 22 /* Invalid argument */
hth,
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-21-2007 05:21 PM
10-21-2007 05:21 PM
Re: pstat_getdisk() call doesn’t work properly in HPUX 11.31 (11i V3)
Is there any change in this particular call for this version of HPUX?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-22-2007 06:33 PM
10-22-2007 06:33 PM
Re: pstat_getdisk() call doesn’t work properly in HPUX 11.31 (11i V3)
It works perfectly fine on 11.31. You need to stop your loop on <= 0.
Ret Code: 1, Device Name: sdisk 0
Ret Code: 1, Device Name: sdisk 1
Ret Code: 1, Device Name: sdisk 2
Ret Code: 1, Device Name: esdisk 3
Ret Code: 1, Device Name: esdisk 4
Ret Code: 1, Device Name: esdisk 5
Returned with code 0
>Hein: i, i, ret,sDiskData...
That should be: j, i, ...