Operating System - Linux
1752861 Members
3948 Online
108791 Solutions
New Discussion

pstat_getdisk() call doesn’t work properly in HPUX 11.31 (11i V3)

 
SOLVED
Go to solution
sandiworld
New Member

pstat_getdisk() call doesn’t work properly in HPUX 11.31 (11i V3)

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

15 REPLIES 15
Laurent Menase
Honored Contributor

Re: pstat_getdisk() call doesn’t work properly in HPUX 11.31 (11i V3)

A return value on 0 means, no element returned, So it should be a sufficient condition to break the loop.

Else you should initialise any automatic variable before using it ( j for instance)
Hein van den Heuvel
Honored Contributor

Re: pstat_getdisk() call doesn’t work properly in HPUX 11.31 (11i V3)

Looks like it is a side-effect special case of just requesting 1 element.

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 printf("\n post j=%d, Ret Code : %d/%d , Device Name : %s %d",
j,ret,errno,sDiskData[i].psd_drv_name.psd_name,sDiskData[i].psd_instance);
}
j+=ret;
}
return 0;
}

sandiworld
New Member

Re: pstat_getdisk() call doesn’t work properly in HPUX 11.31 (11i V3)

ohh I m sorry, that is "int j = 0" only.

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?
Hein van den Heuvel
Honored Contributor
Solution

Re: pstat_getdisk() call doesn’t work properly in HPUX 11.31 (11i V3)

IMHO the confusion is rigth there.

The 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 printf("\nj=%d,i=%d, Ret Code : %d, Device Name : %s %d",
i, i, ret,sDiskData[i].psd_drv_name.psd_name,sDiskData[i].psd_instance);
}
j+=ret;
} else {
j++;
}
}
return 0;
}
Laurent Menase
Honored Contributor

Re: pstat_getdisk() call doesn’t work properly in HPUX 11.31 (11i V3)

The return is based on a link list of disks. So there is no holes.
sandiworld
New Member

Re: pstat_getdisk() call doesn’t work properly in HPUX 11.31 (11i V3)

Thanks a lot Hein, for your valuable comments. It is working now but I have few questions.

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?
Hein van den Heuvel
Honored Contributor

Re: pstat_getdisk() call doesn’t work properly in HPUX 11.31 (11i V3)

Dunno about the why for the different behaviour for a 1 element output array. It's just what I observed. I do know 'they' put that array output method in place for a reason
- 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.
sandiworld
New Member

Re: pstat_getdisk() call doesn’t work properly in HPUX 11.31 (11i V3)

Does anybody have idea why pstat_getdisk() call works with 2 elements and does not work with 1 element for HPUX 11.31 ?

Is there any change in this particular call for this version of HPUX?
Dennis Handly
Acclaimed Contributor

Re: pstat_getdisk() call doesn’t work properly in HPUX 11.31 (11i V3)

>Does anybody have idea why pstat_getdisk() call works with 2 elements and does not work with 1 element for HPUX 11.31?

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, ...