AutoXDR - NFSv4 Test Example


This is a brief example extracted from a prototype implementation for NFSv4.


#include <stdio.h>
#include "nfsv4.h"
#include "nfsv4-clhdr.h"

int command_was_sent = 0;

void
finish_access4(
    void*               user_cookie,
    nfs4_compound_res*  p_cp_res,
    nfs4_status         final_status,
    uint32_t            requested /*  in */,
    ACCESS4res*         p_res     /* out */ )
{
  fputs( "finish_access4 called\n", stderr );
  if (command_was_sent == 0) {
    fputs( "command completed out of sequence\n", stderr );
    exit( 1 );
  }

  if (p_res == NULL) {
    /* no deallocations to do */
    return;
  }

  if (p_res->status != NFS4_STATUS_OK) {
    fputs( "I could not access what I wanted  >:-(\n", stderr );
    return;
  }

  if (  (requested != p_res->ACCESS4res_u.resok4.supported)
     || (requested != p_res->ACCESS4res_u.resok4.access)) {
    fputs( "I did not get the access I wanted  >:-(\n", stderr );
    return;
  }

  command_was_sent--;
}


nfs4_status
nfs4_access4_svc(
    nfs4_compound_args* p_cpd_args,
    ACCESS4res*         p_res,
    ACCESS4args*        p_args )
{
  uint32_t req = p_args->requested;
  if (req == 0)
    req = ~0;

  if (p_res != NULL)
    p_res->ACCESS4res_u.resok4.access =
    p_res->ACCESS4res_u.resok4.supported = p_args->requested;

  fputs( "nfs4_access4_svc called\n", stderr );
  return NFS4_STATUS_OK;
}


int
main( int    argc,
      char** argv )
{
  int res = 0;
  t_nfs_cookie  nfs_cookie;
  static utf8string tag = { sizeof( "mytag" ), "mytag" };

  int fail_test = 0;

  if (argc > 1)
    fail_test = atoi( argv[1] );

  fprintf( stderr, "Hello, NFS world!\n" );

  if (nfs4_null_4( NULL, NULL ) == (void*)NULL) {
    fprintf( stderr, "nfs4_null_4 failed\n" );
    res++;
  }

  if (--fail_test == 0) {
    fputs( "We are about to die horribly.  Expect it.\n", stderr );
    do_nfs4_access4( nfs_cookie, finish_access4, ACCESS4_LOOKUP );
    fputs( "WORSE YET!!  We did *not* die  :-(\n", stderr );
  }

  if (init_nfs4_compound( &nfs_cookie, &tag, NULL ) != RPC_SUCCESS) {
    fprintf( stderr, "init_nfs4_compound failed\n" );
    res++;
  }

  {
    uint32_t mode = ACCESS4_EXECUTE << 1;
    int    cmd_ct = 0;

    do {
      mode >>= 1;

      if (do_nfs4_access4( nfs_cookie, finish_access4, mode ) != 0) {
        fprintf( stderr, "do_nfs4_access4 for %d failed\n", mode );
        res++;
      }
      cmd_ct++;
    } while (mode != 0);

    command_was_sent = cmd_ct;
  }

  if (send_nfs4_compound( nfs_cookie, NULL ) != 0) {
    fprintf( stderr, "send_nfs4_compound failed\n" );
    res++;
  }

  if (--fail_test == 0) {
    fputs( "We are about to die horribly.  Expect it.\n", stderr );
    do_nfs4_access4( nfs_cookie, finish_access4, ACCESS4_LOOKUP );
    fputs( "WORSE YET!!  We did *not* die  :-(\n", stderr );
  }

  if (command_was_sent)
    res++;

  if (res != 0)
    fprintf( stderr, "%d FAILURES\n", res );
  else
    fprintf( stderr, "SUCCESSFUL!\n" );

  return res;
}


Viewable With Any Browser


AutoGen, AutoOpts, columns, getdefs, AutoFSM, AutoXDR and these web pages copyright (c) 1999, 2000, 2001 Bruce Korb, all rights reserved.

AutoXDR copyright (c) 2000 Bruce Korb, all rights reserved.