Memory allocation routines

These routines allocate or free memory used to store cluster or node map information.

You must call the appropriate memory allocation routines before the corresponding retrieval routine, and then call the free routine to release the storage when done.

Item Description
cl_alloc_clustermap Allocates storage for a list of four clusters of 32 nodes with 32 interfaces each.
cl_alloc_groupmap Allocates storage for a list of 64 resource groups.
cl_alloc_netmap Allocates storage for a list of networks.
cl_alloc_nodemap Allocates storage for a list of 32 nodes with 32 interfaces each.
cl_alloc_sitemap Allocates storage for a list of sites.
cl_free_clustermap Frees the storage for a list of clusters that was allocated by calling cl_alloc_clustermap.
cl_free_groupmap Frees storage for a list of resource groups allocated with cl_alloc_groupmap.
cl_free_netmap Frees the storage for a list of networks that was allocated by calling cl_alloc_netmap.
cl_free_nodemap Frees the storage for a list of nodes that was allocated by calling cl_alloc_nodemap.
cl_free_sitemap Frees the storage for a list of sites that was allocated by calling cl_alloc_sitemap.

The following example illustrates how to use these routines. Note that you no longer use CL_MAXNODES to allocate storage for the returned information on the nodes in the cluster. For additional examples, see the reference pages for the cl_getclusters and cl_getnodemap routines.

int status;
struct cl_cluster *clustermap;

cl_alloc_clustermap (&clustermap);
status = cl_getclusters(clustermap);
if (status < 0) {
    cl_perror(status, "Can't get cluster information");
} else { 
    printf("There are currently %d running clusters", status);
}
...
cl_free_clustermap (clustermap);

There is an additional new API cl_node_free() , which frees storage associated with a single cl_node struct. Consider the following example:

struct cl_node nodebuf;
    cl_getnode(clusterid, "ppstest5", &nodebuf);
    printf("Node %s is id %d\n", nodebuf.cln_nodename, nodebuf.cln_nodeid);
    cl_node_free(&nodebuf);
);

After the call to cl_getnode(), the cln_if field is completed with the list of network interface structs associated with the node. This list is dynamically allocated by cl_getnode() and must be freed to avoid a memory leak in a long-running program.

cl_node_free() frees the network interface storage field of the cl_node structure. See the subsequent API description for cl_node_free() for more information.