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-out.c < prev    next >
C/C++ Source or Header  |  2005-11-11  |  6KB  |  277 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;
  33.     PINT_Request *r1;
  34.     PINT_Request *r_enc;
  35.     int ret = -1;
  36.     int pack_size = 0;
  37.     int fd = -1;
  38.     PINT_Request_state *rs1;
  39.     PINT_request_file_data rf1;
  40.     PINT_Request_result seg1;
  41.     int retval;
  42.     int i;
  43.     int count = 64;
  44.     int32_t* len_array;
  45.     PVFS_offset* disp_array;
  46.  
  47.     len_array = (int32_t*)malloc(count*sizeof(int32_t));
  48.     assert(len_array);
  49.     disp_array = (PVFS_offset*)malloc(count*sizeof(PVFS_offset));
  50.     assert(disp_array);
  51.  
  52.     for(i=0; i<count; i++)
  53.     {
  54.         len_array[i] = 4;
  55.         disp_array[i] = 512 + i*8;
  56.     }
  57.  
  58.     fd = open("enc_tmp.dat", O_WRONLY|O_CREAT|O_TRUNC, S_IRWXU);
  59.     if(fd < 0)
  60.     {
  61.         perror("open");
  62.         return(-1);
  63.     }
  64.     
  65.     r = PVFS_BYTE;
  66.  
  67.     PVFS_Request_hindexed(64, len_array, disp_array, r, &r1);
  68.  
  69.     /* set up request state */
  70.     rs1 = PINT_new_request_state(r1);
  71.  
  72.     /* set up file data for request */
  73.     PINT_dist_initialize(NULL);
  74.     rf1.server_nr = 0;
  75.     rf1.server_ct = 2;
  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.  
  124.     
  125.  
  126.     /* allocate a new request and pack the original one into it */
  127.     pack_size = PINT_REQUEST_PACK_SIZE(r1);
  128.     fprintf(stderr, "pack size is %d\n",pack_size);
  129.     r_enc = (PINT_Request*)malloc(pack_size);
  130.     assert(r_enc != NULL);
  131.  
  132.     ret = PINT_request_commit(r_enc, r1);
  133.     if(ret < 0)
  134.     {
  135.         fprintf(stderr, "PINT_Request_commit() failure.\n");
  136.         return(-1);
  137.     }
  138.     fprintf(stderr, "commit returns %d\n", ret);
  139.     ret = PINT_request_encode(r_enc);
  140.     if(ret < 0)
  141.     {
  142.         fprintf(stderr, "PINT_Request_encode() failure.\n");
  143.         return(-1);
  144.     }
  145.     fprintf(stderr, "encode returns %d\n", ret);
  146.  
  147.     ret = write(fd, r_enc, pack_size);
  148.     if(ret < 0)
  149.     {
  150.         perror("write");
  151.         return(-1);
  152.     }
  153.  
  154.     close(fd);
  155.  
  156.     /* do another one */
  157.     fd = open("enc_tmp2.dat", O_WRONLY|O_CREAT|O_TRUNC, S_IRWXU);
  158.     if(fd < 0)
  159.     {
  160.         perror("open");
  161.         return(-1);
  162.     }
  163.     
  164.     r = PVFS_BYTE;
  165.  
  166.     PVFS_Request_hindexed(64, len_array, disp_array, r, &r1);
  167.  
  168.     /* set up request state */
  169.     rs1 = PINT_new_request_state(r1);
  170.  
  171.     /* set up file data for request */
  172.     rf1.server_nr = 0;
  173.     rf1.server_ct = 2;
  174.     rf1.fsize = 508;
  175.     rf1.dist = PINT_dist_create("simple_stripe");
  176.     rf1.extend_flag = 1;
  177.     PINT_dist_lookup(rf1.dist);
  178.  
  179.     /* set up result struct */
  180.     seg1.offset_array = (int64_t *)malloc(SEGMAX * sizeof(int64_t));
  181.     seg1.size_array = (int64_t *)malloc(SEGMAX * sizeof(int64_t));
  182.     seg1.bytemax = BYTEMAX;
  183.     seg1.segmax = SEGMAX;
  184.     seg1.bytes = 0;
  185.     seg1.segs = 0;
  186.         
  187.     printf("\n************************************\n");
  188.     do
  189.     {
  190.         seg1.bytes = 0;
  191.         seg1.segs = 0;
  192.  
  193.         /* process request */
  194.         retval = PINT_process_request(rs1, NULL, &rf1, &seg1, PINT_CKSIZE_MODIFY_OFFSET);
  195.  
  196.         if(retval >= 0)
  197.         {
  198.             printf("results of PINT_process_request():\n");
  199.             printf("%d segments with %lld bytes\n", seg1.segs, lld(seg1.bytes));
  200. #if 0
  201.             for(i=0; i<seg1.segs; i++)
  202.             {
  203.                 printf("  segment %d: offset: %d size: %d\n",
  204.                     i, (int)seg1.offset_array[i], (int)seg1.size_array[i]);
  205.             }
  206. #endif
  207.         }
  208.  
  209.     } while(!PINT_REQUEST_DONE(rs1) && retval >= 0);
  210.     
  211.     if(retval < 0)
  212.     {
  213.         fprintf(stderr, "Error: PINT_process_request() failure.\n");
  214.         return(-1);
  215.     }
  216.     if(PINT_REQUEST_DONE(rs1))
  217.     {
  218.         printf("**** request done.\n");
  219.     }
  220.  
  221.  
  222.  
  223.     /* allocate a new request and pack the original one into it */
  224.     pack_size = PINT_REQUEST_PACK_SIZE(r1);
  225.     fprintf(stderr, "pack size is %d\n",pack_size);
  226.     r_enc = (PINT_Request*)malloc(pack_size);
  227.     assert(r_enc != NULL);
  228.  
  229.     ret = PINT_request_commit(r_enc, r1);
  230.     if(ret < 0)
  231.     {
  232.         fprintf(stderr, "PINT_Request_commit() failure.\n");
  233.         return(-1);
  234.     }
  235.     fprintf(stderr, "commit returns %d\n", ret);
  236.     ret = PINT_request_encode(r_enc);
  237.     if(ret < 0)
  238.     {
  239.         fprintf(stderr, "PINT_Request_encode() failure.\n");
  240.         return(-1);
  241.     }
  242.     fprintf(stderr, "encode returns %d\n", ret);
  243.  
  244.     ret = write(fd, r_enc, pack_size);
  245.     if(ret < 0)
  246.     {
  247.         perror("write");
  248.         return(-1);
  249.     }
  250.  
  251.     close(fd);
  252.  
  253.     return 0;
  254. }
  255.  
  256. void Dump_request(PVFS_Request req)
  257. {
  258.     fprintf(stderr,"**********************\n");
  259.     fprintf(stderr,"address:\t%p\n",req);
  260.     fprintf(stderr,"offset:\t\t%d\n",(int)req->offset);
  261.     fprintf(stderr,"num_ereqs:\t%d\n",(int)req->num_ereqs);
  262.     fprintf(stderr,"num_blocks:\t%d\n",(int)req->num_blocks);
  263.     fprintf(stderr,"stride:\t\t%d\n",(int)req->stride);
  264.     fprintf(stderr,"ub:\t\t%d\n",(int)req->ub);
  265.     fprintf(stderr,"lb:\t\t%d\n",(int)req->lb);
  266.     fprintf(stderr,"agg_size:\t%d\n",(int)req->aggregate_size);
  267.     fprintf(stderr,"num_chunk:\t%d\n",(int)req->num_contig_chunks);
  268.     fprintf(stderr,"depth:\t\t%d\n",(int)req->depth);
  269.     fprintf(stderr,"num_nest:\t%d\n",(int)req->num_nested_req);
  270.     fprintf(stderr,"commit:\t\t%d\n",(int)req->committed);
  271.     fprintf(stderr,"refcount:\t\t%d\n",(int)req->refcount);
  272.     fprintf(stderr,"ereq:\t\t%p\n",req->ereq);
  273.     fprintf(stderr,"sreq:\t\t%p\n",req->sreq);
  274.     fprintf(stderr,"**********************\n");
  275. }
  276.  
  277.