home *** CD-ROM | disk | FTP | other *** search
/ ftp.parl.clemson.edu / 2015-02-07.ftp.parl.clemson.edu.tar / ftp.parl.clemson.edu / pub / pvfs2 / orangefs-2.8.3-20110323.tar.gz / orangefs-2.8.3-20110323.tar / orangefs / test / io / description / test-encode-twice-in.c < prev    next >
C/C++ Source or Header  |  2005-11-11  |  5KB  |  233 lines

  1. /*
  2.  * (C) 2002 Clemson University.
  3.  *
  4.  * See COPYING in top-level directory.
  5.  */       
  6.  
  7. #include <stdlib.h>
  8. #include <stdio.h>
  9. #include <string.h>
  10. #include <assert.h>
  11. #include <sys/types.h>
  12. #include <sys/stat.h>
  13. #include <fcntl.h>
  14. #include <unistd.h>
  15.  
  16. #include <pvfs2-types.h>
  17. #include <gossip.h>
  18. #include <pvfs2-debug.h>
  19. #include <pint-distribution.h>
  20. #include <pint-dist-utils.h>
  21. #include <pvfs2-request.h>
  22. #include <pint-request.h>
  23. #include "pvfs2-internal.h"
  24.  
  25. #define SEGMAX 16
  26. #define BYTEMAX (1024*1024)
  27.  
  28. void Dump_request(PVFS_Request req);
  29.  
  30. int main(int argc, char **argv)
  31. {
  32.     PINT_Request *r_dec;
  33.     int ret = -1;
  34.     int fd = -1;
  35.     PINT_Request_state *rs1;
  36.     PINT_request_file_data rf1;
  37.     PINT_Request_result seg1;
  38.     int retval;
  39.  
  40.     gossip_enable_stderr();
  41.     gossip_set_debug_mask(0,0);
  42.  
  43.     fd = open("enc_tmp.dat", O_RDONLY);
  44.     if(fd < 0)
  45.     {
  46.         perror("open");
  47.         return(-1);
  48.     }
  49.  
  50.     /* just make this kindof big, I dunno how large the type is */
  51.     r_dec = (PINT_Request*)malloc(16*1024);
  52.     assert(r_dec);
  53.  
  54.     ret = read(fd, r_dec, (16*1024));
  55.     if(ret < 0)
  56.     {
  57.         perror("read");
  58.         return(-1);
  59.     }
  60.     
  61.     ret = PINT_request_decode(r_dec);
  62.     if(ret < 0)
  63.     {
  64.         fprintf(stderr, "PINT_request_decode() failure.\n");
  65.         return(-1);
  66.     }
  67.     fprintf(stderr, "decode returns %d\n", ret);
  68.  
  69.     /* set up request state */
  70.     rs1 = PINT_new_request_state(r_dec);
  71.  
  72.     /* set up file data for request */
  73.     PINT_dist_initialize(NULL);
  74.     rf1.server_nr = 0;
  75.     rf1.server_ct = 1;
  76.     rf1.fsize = 508;
  77.     rf1.dist = PINT_dist_create("simple_stripe");
  78.     rf1.extend_flag = 1;
  79.     PINT_dist_lookup(rf1.dist);
  80.  
  81.     /* set up result struct */
  82.     seg1.offset_array = (int64_t *)malloc(SEGMAX * sizeof(int64_t));
  83.     seg1.size_array = (int64_t *)malloc(SEGMAX * sizeof(int64_t));
  84.     seg1.bytemax = BYTEMAX;
  85.     seg1.segmax = SEGMAX;
  86.     seg1.bytes = 0;
  87.     seg1.segs = 0;
  88.         
  89.     printf("\n************************************\n");
  90.     do
  91.     {
  92.         seg1.bytes = 0;
  93.         seg1.segs = 0;
  94.  
  95.         /* process request */
  96.         retval = PINT_process_request(rs1, NULL, &rf1, &seg1, PINT_CKSIZE_MODIFY_OFFSET);
  97.  
  98.         if(retval >= 0)
  99.         {
  100.             printf("results of PINT_process_request():\n");
  101.             printf("%d segments with %lld bytes\n", seg1.segs, lld(seg1.bytes));
  102. #if 0
  103.             for(i=0; i<seg1.segs; i++)
  104.             {
  105.                 printf("  segment %d: offset: %d size: %d\n",
  106.                     i, (int)seg1.offset_array[i], (int)seg1.size_array[i]);
  107.             }
  108. #endif
  109.         }
  110.  
  111.     } while(!PINT_REQUEST_DONE(rs1) && retval >= 0);
  112.     
  113.     if(retval < 0)
  114.     {
  115.         fprintf(stderr, "Error: PINT_process_request() failure.\n");
  116.         return(-1);
  117.     }
  118.     if(PINT_REQUEST_DONE(rs1))
  119.     {
  120.         printf("**** request done.\n");
  121.     }
  122.  
  123.     close(fd);
  124.  
  125.     /* do another one */
  126.  
  127.     fd = open("enc_tmp2.dat", O_RDONLY);
  128.     if(fd < 0)
  129.     {
  130.         perror("open");
  131.         return(-1);
  132.     }
  133.  
  134.     /* just make this kindof big, I dunno how large the type is */
  135.     r_dec = (PINT_Request*)malloc(16*1024);
  136.     assert(r_dec);
  137.  
  138.     ret = read(fd, r_dec, (16*1024));
  139.     if(ret < 0)
  140.     {
  141.         perror("read");
  142.         return(-1);
  143.     }
  144.     
  145.     ret = PINT_request_decode(r_dec);
  146.     if(ret < 0)
  147.     {
  148.         fprintf(stderr, "PINT_request_decode() failure.\n");
  149.         return(-1);
  150.     }
  151.     fprintf(stderr, "decode returns %d\n", ret);
  152.  
  153.     /* set up request state */
  154.     rs1 = PINT_new_request_state(r_dec);
  155.  
  156.     /* set up file data for request */
  157.     rf1.server_nr = 0;
  158.     rf1.server_ct = 1;
  159.     rf1.fsize = 508;
  160.     rf1.dist = PINT_dist_create("simple_stripe");
  161.     rf1.extend_flag = 1;
  162.     PINT_dist_lookup(rf1.dist);
  163.  
  164.     /* set up result struct */
  165.     seg1.offset_array = (int64_t *)malloc(SEGMAX * sizeof(int64_t));
  166.     seg1.size_array = (int64_t *)malloc(SEGMAX * sizeof(int64_t));
  167.     seg1.bytemax = BYTEMAX;
  168.     seg1.segmax = SEGMAX;
  169.     seg1.bytes = 0;
  170.     seg1.segs = 0;
  171.         
  172.     printf("\n************************************\n");
  173.     do
  174.     {
  175.         seg1.bytes = 0;
  176.         seg1.segs = 0;
  177.  
  178.         /* process request */
  179.         retval = PINT_process_request(rs1, NULL, &rf1, &seg1, PINT_CKSIZE_MODIFY_OFFSET);
  180.  
  181.         if(retval >= 0)
  182.         {
  183.             printf("results of PINT_process_request():\n");
  184.             printf("%d segments with %lld bytes\n", seg1.segs, lld(seg1.bytes));
  185. #if 0
  186.             for(i=0; i<seg1.segs; i++)
  187.             {
  188.                 printf("  segment %d: offset: %d size: %d\n",
  189.                     i, (int)seg1.offset_array[i], (int)seg1.size_array[i]);
  190.             }
  191. #endif
  192.         }
  193.  
  194.     } while(!PINT_REQUEST_DONE(rs1) && retval >= 0);
  195.     
  196.     if(retval < 0)
  197.     {
  198.         fprintf(stderr, "Error: PINT_process_request() failure.\n");
  199.         return(-1);
  200.     }
  201.     if(PINT_REQUEST_DONE(rs1))
  202.     {
  203.         printf("**** request done.\n");
  204.     }
  205.  
  206.     close(fd);
  207.  
  208.  
  209.     return 0;
  210. }
  211.  
  212. void Dump_request(PVFS_Request req)
  213. {
  214.     fprintf(stderr,"**********************\n");
  215.     fprintf(stderr,"address:\t%p\n",req);
  216.     fprintf(stderr,"offset:\t\t%d\n",(int)req->offset);
  217.     fprintf(stderr,"num_ereqs:\t%d\n",(int)req->num_ereqs);
  218.     fprintf(stderr,"num_blocks:\t%d\n",(int)req->num_blocks);
  219.     fprintf(stderr,"stride:\t\t%d\n",(int)req->stride);
  220.     fprintf(stderr,"ub:\t\t%d\n",(int)req->ub);
  221.     fprintf(stderr,"lb:\t\t%d\n",(int)req->lb);
  222.     fprintf(stderr,"agg_size:\t%d\n",(int)req->aggregate_size);
  223.     fprintf(stderr,"num_chunk:\t%d\n",(int)req->num_contig_chunks);
  224.     fprintf(stderr,"depth:\t\t%d\n",(int)req->depth);
  225.     fprintf(stderr,"num_nest:\t%d\n",(int)req->num_nested_req);
  226.     fprintf(stderr,"commit:\t\t%d\n",(int)req->committed);
  227.     fprintf(stderr,"refcount:\t\t%d\n",(int)req->refcount);
  228.     fprintf(stderr,"ereq:\t\t%p\n",req->ereq);
  229.     fprintf(stderr,"sreq:\t\t%p\n",req->sreq);
  230.     fprintf(stderr,"**********************\n");
  231. }
  232.  
  233.