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 / src / io / buffer / ncac-buf-job.c < prev    next >
C/C++ Source or Header  |  2005-10-25  |  6KB  |  196 lines

  1. /* This file contains functions to perform reads/writes with
  2.  * the caller supplied buffers.
  3.  * For read, the data is copied from the cache to the caller
  4.  * supplied buffers.
  5.  * For write, the data is copied into the cache from the caller
  6.  * supplied bufers.
  7.  * In both cases, the cache buffer will not be used for 
  8.  * communication.
  9.  *
  10.  */
  11.  
  12. #include <stdio.h>
  13. #include <stdlib.h>
  14. #include "internal.h"
  15. #include "state.h"
  16. #include "ncac-job.h"
  17.  
  18. int NCAC_do_a_bufread_job(struct NCAC_req *ncac_req)
  19. {
  20.  
  21. #if 0
  22.     int ret;
  23.     int seg, cnt;
  24.     int rcomm=0;
  25.  
  26.     int i;
  27.     unsigned long total_len, copied_len, len;
  28.     char * copied_buf;
  29.  
  30.     /* only one contiguous segment */
  31.     if ( !ncac_req->offcnt ) { 
  32.         ret = NCAC_do_one_piece_read( ncac_req, ncac_req->pos, 
  33.                                       ncac_req->size, 
  34.                                       ncac_req->foff, 
  35.                                         ncac_req->cbufoff, 
  36.                                       ncac_req->cbufsize, ncac_req->cbufhash,
  37.                                        ncac_req->cbufflag, 
  38.                                       ncac_req->cbufrcnt,
  39.                                       ncac_req->cbufwcnt,
  40.                                       &cnt);
  41.         if ( ret < 0) {
  42.             ncac_req->error = NCAC_JOB_PROCESS_ERR;
  43.             ncac_req->status = NCAC_ERR_STATUS;
  44.             return ret;
  45.         }
  46.     }else{
  47.  
  48.         /* Handle each contiguous piece one by one. */
  49.         
  50.         cnt = 0;
  51.         for (seg = 0; seg < ncac_req->offcnt; seg ++) {
  52.             ret = NCAC_do_one_piece_read( ncac_req, ncac_req->offvec[seg],
  53.                                           ncac_req->sizevec[seg],
  54.                                             ncac_req->foff + cnt, 
  55.                                           ncac_req->cbufoff + cnt, 
  56.                                           ncac_req->cbufsize + cnt, 
  57.                                           ncac_req->cbufhash + cnt, 
  58.                                           ncac_req->cbufflag + cnt,
  59.                                           ncac_req->cbufrcnt + cnt,
  60.                                           ncac_req->cbufwcnt + cnt, 
  61.                                           &seg );
  62.             if ( ret < 0) {
  63.                 ncac_req->error = NCAC_JOB_PROCESS_ERR;
  64.                 ncac_req->status = NCAC_ERR_STATUS;
  65.                 return ret;
  66.             }
  67.             cnt += seg;
  68.         }
  69.     }
  70.  
  71.     for (seg = 0; seg < ncac_req->cbufcnt; seg ++)
  72.          if (ncac_req->cbufflag[seg] == 1) rcomm++;
  73.          
  74.     if (rcomm == ncac_req->cbufcnt) ncac_req->status = NCAC_COMPLETE;
  75.     else if (!rcomm) ncac_req->status = NCAC_REQ_SUBMITTED;
  76.     else ncac_req->status = NCAC_PARTIAL_PROCESS;
  77.  
  78.     if ( ncac_req->status == NCAC_COMPLETE && ncac_req->usrlen ){
  79.  
  80.         /* copy data into the caller supplied buffers. */
  81.          total_len = ncac_req->usrlen;
  82.         copied_len = 0;
  83.         copied_buf = ncac_req->usrbuf;
  84.         
  85.         for ( i = 0; i < ncac_req->cbufcnt; i ++ ) {
  86.             len = ncac_req->cbufsize[i];
  87.             if ( len > total_len - copied_len ) 
  88.                 len = total_len - copied_len;
  89.             memcpy( copied_buf + copied_len, ncac_req->cbufoff[i], len);
  90.             copied_len += len;
  91.             if ( copied_len == total_len ) break;
  92.         }
  93.  
  94.         /* release all cache extents */
  95.         ret = NCAC_extent_done_access( ncac_req );
  96.         if ( ret < 0 ) {
  97.             ncac_req->error = NCAC_REQ_DONE_ERR;
  98.             ncac_req->status = NCAC_ERR_STATUS;
  99.             return ret;
  100.         }
  101.         
  102.     }
  103. #endif
  104.  
  105.     return 0;
  106.  
  107. }
  108.  
  109. int NCAC_do_a_bufwrite_job(struct NCAC_req *ncac_req)
  110. {
  111.     
  112. #if 0
  113.     int ret;
  114.     int seg, cnt;
  115.     int rcomm=0;
  116.  
  117.     int i;
  118.     unsigned long total_len, copied_len, len;
  119.     char * copied_buf;
  120.  
  121.     /* only one contiguous segment */
  122.     if ( !ncac_req->offcnt ) { 
  123.         ret = NCAC_do_one_piece_write(  ncac_req, ncac_req->pos, 
  124.                                         ncac_req->size, 
  125.                                         ncac_req->cbufoff, ncac_req->cbufsize, 
  126.                                         ncac_req->cbufhash, ncac_req->cbufflag, 
  127.                                         ncac_req->cbufrcnt,
  128.                                         ncac_req->cbufwcnt,
  129.                                         &cnt );
  130.         if ( ret < 0) {
  131.             ncac_req->error = NCAC_JOB_PROCESS_ERR;
  132.             ncac_req->status = NCAC_ERR_STATUS;
  133.             return ret;
  134.         }
  135.     }else{
  136.  
  137.         /* Handle each contiguous piece one by one. */
  138.         
  139.         cnt = 0;
  140.         for (seg = 0; seg < ncac_req->offcnt; seg ++) {
  141.             ret = NCAC_do_one_piece_write( ncac_req, ncac_req->offvec[seg],
  142.                                            ncac_req->sizevec[seg],
  143.                                            ncac_req->cbufoff + cnt, 
  144.                                            ncac_req->cbufsize + cnt, 
  145.                                            ncac_req->cbufhash + cnt, 
  146.                                            ncac_req->cbufflag + cnt, 
  147.                                            ncac_req->cbufrcnt + cnt,
  148.                                            ncac_req->cbufwcnt + cnt,
  149.                                            &seg );
  150.             if ( ret < 0) {
  151.                 ncac_req->error = NCAC_JOB_PROCESS_ERR;
  152.                 ncac_req->status = NCAC_ERR_STATUS;
  153.                 return ret;
  154.             }
  155.             cnt += seg;
  156.         }
  157.     }
  158.  
  159.     for (seg = 0; seg < ncac_req->cbufcnt; seg ++)
  160.          if (ncac_req->cbufflag[seg] == 1 ) rcomm++;
  161.          
  162.     if (rcomm == ncac_req->cbufcnt) ncac_req->status = NCAC_COMPLETE;
  163.     else if (!rcomm) ncac_req->status = NCAC_REQ_SUBMITTED;
  164.     else ncac_req->status = NCAC_PARTIAL_PROCESS;
  165.  
  166.     if ( ncac_req->status == NCAC_COMPLETE && ncac_req->usrlen ){
  167.  
  168.         /* copy data from the caller supplied buffers to the extent buffers. */
  169.          total_len = ncac_req->usrlen;
  170.         copied_len = 0;
  171.         copied_buf = ncac_req->usrbuf;
  172.         
  173.         for ( i = 0; i < ncac_req->cbufcnt; i ++ ) {
  174.             len = ncac_req->cbufsize[i];
  175.             if ( len > total_len - copied_len ) 
  176.                 len = total_len - copied_len;
  177.             memcpy( ncac_req->cbufoff[i], copied_buf + copied_len, len);
  178.             copied_len += len;
  179.             if ( copied_len == total_len ) break;
  180.         }
  181.  
  182.         /* release all cache extents */
  183.         ret = NCAC_extent_done_access( ncac_req );
  184.         if ( ret < 0 ) {
  185.             ncac_req->error = NCAC_REQ_DONE_ERR;
  186.             ncac_req->status = NCAC_ERR_STATUS;
  187.             return ret;
  188.         }
  189.         
  190.     }
  191. #endif
  192.  
  193.     return 0;
  194. }
  195.  
  196.