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-interface.c < prev    next >
C/C++ Source or Header  |  2004-09-21  |  7KB  |  253 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <errno.h>
  4.  
  5. #include "ncac-interface.h"
  6. #include "internal.h"
  7.  
  8. /* cache_read_post()
  9.  *
  10.  * post a read request to NCAC. A read request could be a single
  11.  * contiguous region, or a list of non-contiguous regions.   
  12.  * 
  13.  * Input:  desc:    read request descriptor
  14.  *     user_ptr:    some pointer used by the caller.
  15.  *
  16.  * Output: request: request handle
  17.  *         reply:   reply information.
  18.  *
  19.  * Return: 0: success, the request is submitted successfully. There is no
  20.  *             any further progress on this request.
  21.  *             request->status: NCAC_REQ_SUBMITTED
  22.  *
  23.  *         1: the request is submitted successfully. In addition, there is
  24.  *            parital or complete progress on this request. In this case,
  25.  *            there are two possible cases:
  26.  *
  27.  *                request->status: NCAC_REQ_BUF_PARTIAL
  28.  *                request->status: NCAC_REQ_BUF_COMPLETE
  29.  *            In either case, the "reply" parameter will return related
  30.  *            buffer information. 
  31.  *
  32.  *         <0: error code 
  33.  */
  34.  
  35. /* read request submit */
  36. int cache_read_post(cache_read_desc_t *desc, 
  37.                     cache_request_t *request,
  38.                     cache_reply_t *reply,
  39.                     void *user_ptr)
  40. {
  41.     int res;
  42.     NCAC_req_t *ncac_req;
  43.     
  44.     /* no check here. We push this check to Trove layer */ 
  45.  
  46.     /* build an interanl request */
  47.     ncac_req = NCAC_rwreq_build((NCAC_desc_t*)desc, NCAC_GEN_READ);
  48.     if ( ncac_req == NULL ) {
  49.         request->status = NCAC_REQ_BUILD_ERR;
  50.         return -ENOMEM;
  51.     }
  52.  
  53.     DPRINT("ncac_req=%p\n", ncac_req);
  54.  
  55.     /* ok. ready to submit a read request to NCAC */
  56.     res = NCAC_rwjob_prepare(ncac_req, reply );
  57.     if ( res < 0 ) {
  58.         request->status = NCAC_SUBMIT_ERR;
  59.         return res;
  60.     }
  61.  
  62.     request->internal_id  = ncac_req->id;
  63.     request->optype = ncac_req->optype;
  64.     request->status = ncac_req->status;
  65.  
  66.     reply->count = 0;
  67.  
  68.     if ( ncac_req->error ) return ncac_req->error;
  69.  
  70.     if ( ncac_req->status == NCAC_PARTIAL_PROCESS || 
  71.          ncac_req->status == NCAC_BUFFER_COMPLETE )
  72.     {
  73.  
  74.         /* buffer information  has been filled */
  75.         reply->cbuf_offset_array = ncac_req->cbufoff;
  76.         reply->cbuf_size_array   = ncac_req->cbufsize;
  77.         reply->cbuf_flag         = ncac_req->cbufflag;
  78.         reply->count             = ncac_req->cbufcnt;
  79.  
  80.         /* TODO:
  81.          * add colaesce buffers here to form bigger contiguous buffer
  82.          * if possible 
  83.          */
  84.  
  85.         return 1;
  86.     }
  87.  
  88.     /* the read request is submitted successfully. No further 
  89.      * progress on it yet.
  90.      */
  91.  
  92.     return 0;
  93. }
  94.  
  95.  
  96. /* cache_write_post()
  97.  *
  98.  * post a write request to NCAC. A write request could be a single
  99.  * contiguous region, or a list of non-contiguous regions.   
  100.  * 
  101.  * Input:  desc:    write request descriptor
  102.  *     user_ptr:    some pointer used by the caller.
  103.  *
  104.  * Output: request: request handle
  105.  *         reply:   reply information.
  106.  *
  107.  * Return: 0: success, the request is submitted successfully. There is no
  108.  *             any further progress on this request.
  109.  *             request->status: NCAC_REQ_SUBMITTED
  110.  * 
  111.  *         1: the request is submitted successfully. In addition, there is
  112.  *            parital or complete progress on this request. In this case,
  113.  *            there are three possible cases:
  114.  *
  115.  *                request->status: NCAC_REQ_BUF_PARTIAL
  116.  *                request->status: NCAC_REQ_BUF_COMPLETE
  117.  *            In either case, the "reply" parameter will return related
  118.  *            buffer information. 
  119.  *
  120.  *                request->status: NCAC_REQ_COMPLETE
  121.  *            The third case only happens when the caller supplies 
  122.  *            its temporary buffer to the cache. If the cache has already
  123.  *            copy all data from the temporary buffer to its buffers,
  124.  *            this flag is set.  The cache then
  125.  *            copy all  
  126.  *
  127.  *         <0: error code 
  128.  */
  129.  
  130. /* write request submit */
  131. int cache_write_post(cache_write_desc_t *desc,
  132.                      cache_request_t *request,
  133.                      cache_reply_t *reply,
  134.                      void *user_ptr)
  135. {
  136.     struct NCAC_req *ncac_req;
  137.     int res;
  138.  
  139.     /* no check here. We push this check to Trove layer */ 
  140.  
  141.     /* build an interanl request */
  142.     ncac_req= NCAC_rwreq_build((NCAC_desc_t*)desc, NCAC_GEN_WRITE);
  143.     if ( ncac_req == NULL ) {
  144.         request->status = NCAC_REQ_BUILD_ERR;
  145.         return -ENOMEM;
  146.     }
  147.  
  148.     /* ok. ready to submit a read request to NCAC */
  149.     res = NCAC_rwjob_prepare(ncac_req, reply );
  150.     if ( res < 0 ) {
  151.         request->status = NCAC_SUBMIT_ERR;
  152.         return res;
  153.     }
  154.  
  155.     request->internal_id  = ncac_req->id;
  156.     request->optype = ncac_req->optype;
  157.     request->status = ncac_req->status;
  158.  
  159.     reply->count = 0;
  160.  
  161.     if ( request->status == NCAC_PARTIAL_PROCESS || 
  162.          request->status == NCAC_BUFFER_COMPLETE ){
  163.  
  164.         /* buffer information  has been filled */
  165.         reply->cbuf_offset_array = ncac_req->cbufoff;
  166.         reply->cbuf_size_array   = ncac_req->cbufsize;
  167.         reply->cbuf_flag         = ncac_req->cbufflag;
  168.         reply->count             = ncac_req->cbufcnt;
  169.  
  170.         return 1;
  171.     }
  172.  
  173.     /* the read request is submitted successfully. No further
  174.      * progress on it yet.
  175.      */
  176.  
  177.     return 0;
  178.  
  179. }
  180.  
  181. /* sync request submit */
  182. int cache_sync_post(cache_sync_desc_t *desc,
  183.                     cache_request_t *request,
  184.             void *user_ptr)
  185. {
  186.  
  187.      fprintf(stderr, "not implemented yet\n");
  188.      return 0;
  189. }
  190.  
  191. /* controls on the request handle */
  192. /* test if a request is done */
  193. int cache_req_test(cache_request_t *request, 
  194.                    int *flag,
  195.                    cache_reply_t *reply,
  196.                    void *user_ptr)
  197. {
  198.     struct NCAC_req *ncac_req;
  199.     int ret;
  200.  
  201.     reply->count = 0;
  202.  
  203.     ret = NCAC_check_request(request->internal_id, &ncac_req);
  204.  
  205.     if ( ret < 0 ) {
  206.         return ret;
  207.     }
  208.  
  209.     request->status = ncac_req->status;
  210.     if ( request->status == NCAC_PARTIAL_PROCESS || 
  211.          request->status == NCAC_BUFFER_COMPLETE ){
  212.  
  213.         /* buffer information  has been filled */
  214.         reply->cbuf_offset_array = ncac_req->cbufoff;
  215.         reply->cbuf_size_array   = ncac_req->cbufsize;
  216.         reply->cbuf_flag         = ncac_req->cbufflag;
  217.         reply->count             = ncac_req->cbufcnt;
  218.     }
  219.  
  220.     if ( request->status == NCAC_BUFFER_COMPLETE || request->status == NCAC_COMPLETE )
  221.         *flag = 1;
  222.     else 
  223.         *flag = 0;
  224.  
  225.     return 0;
  226. }
  227.  
  228. int cache_req_testsome(int count, 
  229.                        cache_request_t *request, 
  230.                        int *outcount, int *indices, 
  231.                        cache_reply_t *reply,
  232.                        void *user_ptr)
  233. {
  234.  
  235.      fprintf(stderr, "not implemented yet\n");
  236.      return 0;
  237.  
  238. }
  239.  
  240.  
  241. int cache_req_done(cache_request_t *request)
  242. {
  243.     int ret;
  244.  
  245.     ret = NCAC_done_request(request->internal_id);
  246.     if ( ret < 0 ) {
  247.         return ret;
  248.     }
  249.     request->status = NCAC_COMPLETE;
  250.  
  251.     return 0;
  252. }
  253.