How can I get PAG number in AFS programically?

95 Views Asked by At

In AFS (Andrew File System), separate processes can be put into different PAGs, my question is: How can I get the PAG number of certain process programically? Thanks.

1

There are 1 best solutions below

1
adeason On

You can do this in a C program by calling the VIOC_GETPAG pioctl, originally posted by Russ Allbery here:

#include <stdio.h>
#include <afs/param.h>
#include <afs/afssyscalls.h>
#include <afs/vice.h>
#include <afs/vioc.h>

int
main(void)
{
    struct ViceIoctl iob;
    afs_uint32 pag;
    int code;

    iob.in = NULL;
    iob.in_size = 0;
    iob.out = (void *) &pag;
    iob.out_size = sizeof(pag);
    code = pioctl(NULL, VIOC_GETPAG, &iob, 0);
    if (code != 0) {
        fprintf(stderr, "Cannot get PAG\n");
        return 1;
    }
    printf("PAG number is: %lu\n", (unsigned long) pag);
    return 0;
}

There is no official interface (yet) for getting a PAG number outside of a C program; say, via running some command. Most of the time you can determine the PAG number by looking at the supplemental group list of the current process, and looking for very high-numbered groups. However, while this mostly "works" for now, there some cases where this information may be incorrect, and it is not guaranteed to work in the future for all platforms. Specifically, on modern Linux, the authoritative location of the PAG number is in a kernel keyring, and supplying the group id is just "best effort" and may go away in the future.