Novell Home

Novell Cluster Services: NCS WherePools()

From Developer Community

Sample code for NCS_WherePools()

Sample Code

#ifdef __MWERKS__
#pragma ANSI_strict off
#pragma warn_padding off
#endif
#include <ncssdk.h>
#ifdef __MWERKS__
#pragma warn_padding reset
#pragma ANSI_strict reset
#endif

#include <nunicode.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define CASE_RET(id) case id: return #id;

static char const* strNCSError( NCS_RETURN error_code) {
  switch ( error_code) {
    CASE_RET( NCS_SUCCESS)
    CASE_RET( NCS_ERROR_INVALID_HANDLE)
    CASE_RET( NCS_ERROR_INVALID_PARAMETER)
    CASE_RET( NCS_FAILURE)
    CASE_RET( NCS_BUSY)
    CASE_RET( NCS_ERROR_TOO_MANY_HANDLES)
    CASE_RET( NCS_UNKNOWN)
    CASE_RET( NCS_BAD_PARAMETER)
    CASE_RET( NCS_ALLOC_ERROR)
    CASE_RET( NCS_NODE_NOT_FOUND)
    CASE_RET( NCS_IP_DUPLICATE)
    CASE_RET( NCS_RESOURCE_ONLINE)
    CASE_RET( NCS_RESOURCE_NOT_FOUND)
    CASE_RET( NCS_RESOURCE_FOUND)
    CASE_RET( NCS_ATTACH_CREATE)
    CASE_RET( NCS_ATTACH_EXISTS)
    CASE_RET( NCS_NOT_CLUSTER_MEMBER)
    CASE_RET( NCS_NO_RESOURCES)
    CASE_RET( NCS_TRYLOCK_HELD)
    CASE_RET( NCS_JOIN_LEAVE_PENDING)
    CASE_RET( NCS_JOIN_LEAVE_ALREADY_IN)
    CASE_RET( NCS_JOIN_LEAVE_NOT_IN)
    CASE_RET( NCS_JOIN_LEAVE_NO_GIPC)
    CASE_RET( NCS_JOIN_LEAVE_GIPC_ERROR)
    CASE_RET( NCS_JOIN_LEAVE_SBD_ERROR)
    CASE_RET( NCS_JOIN_LEAVE_TIMED_OUT)
    CASE_RET( NCS_JOIN_LEAVE_EVENT_EXIT)
    CASE_RET( NCS_NOT_SUPPORTED)
  }
  return "Unknown NCS code";
}
static void printUniCodeStr( UINT16* str) {
  if ( str == NULL) {
    printf( "<null>");
  }
  else {
    unsigned char buffer[ 256];
    size_t actual_len = 0;
    int ccode;
    ccode = NWUSUnicodeToByte( buffer, sizeof( buffer), /* ( unicode*) */ str, &actual_len);
    if ( ccode != 0) {
      printf( "NWUSUnicodeToByte failed, ccode = %x, actual_len = %u\n", ccode, actual_len);
    }
    else printf(( char*) buffer);
  }
}
int main( void) {
  NCS_HANDLE handle;
  UINT32 num_pools;
  NCS_POOL_INFO* pools;
  size_t i;
  NCS_RETURN ccode;
  NWUSStandardUnicodeInit();
  ccode = NCS_Register( NULL, NULL, NULL, NULL, NULL, &handle);
  if ( ccode != NCS_SUCCESS) {
    printf( "NCS_Register failed, ccode = %d (%s)\n", ccode, strNCSError( ccode));
    return EXIT_FAILURE;
  }
  ccode = NCS_NumPools( handle, &num_pools);
  if ( ccode != NCS_SUCCESS) {
    printf( "NCS_NumPools failed, ccode = %d (%s)\n", ccode, strNCSError( ccode));
    NCS_Deregister( handle);
    return EXIT_FAILURE;
  }
  printf( "num_pools = %u\n", num_pools);
  pools = malloc( sizeof( NCS_POOL_INFO) * num_pools);
  if ( pools == NULL) {
    puts( "Could not allocate NCS_POOL_INFO structures");
    NCS_Deregister( handle);
    return EXIT_FAILURE;
  }
  ccode = NCS_WherePools( handle, &num_pools, pools);
  if ( ccode != NCS_SUCCESS) {
    printf( "NCS_WherePools failed, ccode = %d (%s)\n", ccode, strNCSError( ccode));
    free( pools);
    NCS_Deregister( handle);
    return EXIT_FAILURE;
  }
  for ( i = 0; i < num_pools; ++i) {
    printf( "Pool #%u:\n", i);
    printf( "ResFDN = ");
    printUniCodeStr( pools[ i].ResFDN);
    puts( "");
    printf( "PoolFDN = ");
    printUniCodeStr( pools[ i].PoolFDN);
    puts( "");
    printf( "VirtServFDN = ");
    printUniCodeStr( pools[ i].VirtServFDN);
    puts( "");
    printf( "ResName = %s\n", pools[ i].ResName);
    printf( "PoolName = %s\n", pools[ i].PoolName);
    printf( "numVols = %u\n", pools[ i].numVols);
    printf( "WhichNode = %u\n", pools[ i].WhichNode);
    printf( "ResourceIP = %d.%d.%d.%d (%08x)\n", (( BYTE*) &( pools[ i].ResourceIP))[ 0], (( BYTE*) &( pools[ i].ResourceIP))[ 1], (( BYTE*) &( pools[ i].ResourceIP))[ 2], (( BYTE*) &( pools[ i].ResourceIP))[ 3], pools[ i].ResourceIP);
    printf( "otherHooks = %p\n", pools[ i].otherHooks);
    printf( "volArray = %p\n", pools[ i].volArray);
  }
  free( pools);
  ccode = NCS_Deregister( handle);
  if ( ccode != NCS_SUCCESS) {
    printf( "NCS_Deregister failed, ccode = %d (%s)\n", ccode, strNCSError( ccode));
    return EXIT_FAILURE;
  }
  return EXIT_SUCCESS;
}

--Dmitry Mityugov

Novell® Making IT Work As One

© 2008 Novell, Inc. All Rights Reserved.