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 / description / pint-request.h < prev    next >
C/C++ Source or Header  |  2008-11-19  |  9KB  |  259 lines

  1. /*
  2.  * (C) 2002 Clemson University and The University of Chicago.
  3.  *
  4.  * See COPYING in top-level directory.
  5.  */
  6.  
  7. #ifndef __PINT_REQUEST_H
  8. #define __PINT_REQUEST_H
  9.  
  10. #include "pvfs2-types.h"
  11.  
  12. /* Forward declarations */
  13. struct PINT_dist_s;
  14.  
  15. /* modes for PINT_Process_request  and PINT_distribute */
  16. #define PINT_SERVER                000001
  17. #define PINT_CLIENT                000002
  18. #define PINT_CKSIZE                000004
  19. #define PINT_MODIFY_OFFSET         000010
  20. #define PINT_CKSIZE_MODIFY_OFFSET  000014
  21. #define PINT_LOGICAL_SKIP          000020
  22. #define PINT_CKSIZE_LOGICAL_SKIP   000024
  23. #define PINT_SEEKING               000040
  24. #define PINT_MEMREQ                000100
  25.  
  26. #define PINT_IS_SERVER(x)          ((x) & PINT_SERVER)
  27. #define PINT_EQ_SERVER(x)          ((x) == PINT_SERVER)
  28. #define PINT_IS_CLIENT(x)          ((x) & PINT_CLIENT)
  29. #define PINT_EQ_CLIENT(x)          ((x) == PINT_CLIENT)
  30. #define PINT_IS_CKSIZE(x)          ((x) & PINT_CKSIZE)
  31. #define PINT_EQ_CKSIZE(x)          ((x) == PINT_CKSIZE)
  32. #define PINT_IS_LOGICAL_SKIP(x)    ((x) & PINT_LOGICAL_SKIP)
  33. #define PINT_EQ_LOGICAL_SKIP(x)    ((x) == PINT_LOGICAL_SKIP)
  34. #define PINT_IS_SEEKING(x)         ((x) & PINT_SEEKING)
  35. #define PINT_EQ_SEEKING(x)         ((x) == PINT_SEEKING)
  36. #define PINT_IS_MEMREQ(x)          ((x) & PINT_MEMREQ)
  37. #define PINT_EQ_MEMREQ(x)          ((x) == PINT_MEMREQ)
  38. #define PINT_SET_SEEKING(x)        ((x) |= PINT_SEEKING)
  39. #define PINT_CLR_SEEKING(x)        ((x) &= ~(PINT_SEEKING))
  40. #define PINT_SET_LOGICAL_SKIP(x)   ((x) |= PINT_LOGICAL_SKIP)
  41. #define PINT_CLR_LOGICAL_SKIP(x)   ((x) &= ~(PINT_LOGICAL_SKIP))
  42.  
  43. /* PVFS Request Processing Stuff */
  44.  
  45. /**
  46.  * NOTE: The encoding/decoding functions must be updated
  47.  * with changes to this struct.  See pint-request-encode.h.
  48.  */
  49. typedef struct PINT_Request {
  50.     PVFS_offset  offset;        /* offset from start of last set of elements */
  51.     int32_t      num_ereqs;     /* number of ereqs in a block */
  52.     int32_t      num_blocks;    /* number of blocks */
  53.     PVFS_size    stride;        /* stride between blocks in bytes */
  54.     PVFS_offset  ub;            /* upper bound of the type in bytes */
  55.     PVFS_offset  lb;            /* lower bound of the type in bytes */
  56.     PVFS_size    aggregate_size; /* amount of aggregate data in bytes */
  57.     int32_t      num_contig_chunks; /* number of contiguous data chunks */
  58.     int32_t      depth;            /* number of levels of nesting */
  59.     int32_t      num_nested_req;/* number of requests nested under this one */
  60.     int32_t      committed;     /* indicates if request has been commited */
  61.     int32_t      refcount;      /* number of references to this request struct */
  62.     struct PINT_Request *ereq;  /* element type */
  63.     struct PINT_Request *sreq;  /* sequence type */
  64. } PINT_Request;
  65.  
  66. #define PVFS_REQUEST_ENCODED_SIZE \
  67.     ((sizeof(PVFS_offset) * 3) + (sizeof(PVFS_size) * 2) + \
  68.      (sizeof(int32_t) * 6) + (sizeof(uint32_t) * 2) + (sizeof(uint64_t)) + 4)
  69.  
  70. typedef struct PINT_reqstack {
  71.     int64_t      el;           /* number of element being processed */
  72.     int64_t      maxel;        /* total number of these elements to process */
  73.     PINT_Request *rq;            /* pointer to request structure */
  74.     PINT_Request *rqbase;         /* pointer to first request is sequence chain */
  75.     int32_t      blk;          /* number of block being processed */
  76.     PVFS_offset  chunk_offset; /* offset of beginning of current contiguous chunk */
  77. } PINT_reqstack;           
  78.           
  79. typedef struct PINT_Request_state { 
  80.     struct PINT_reqstack *cur; /* request element chain stack */
  81.     int32_t      lvl;          /* level in element chain */
  82.     PVFS_size    bytes;        /* bytes in current contiguous chunk processed */
  83.     PVFS_offset  type_offset;  /* logical offset within request type */
  84.     PVFS_offset  target_offset;/* first type offset to process */
  85.     PVFS_offset  final_offset; /* last type offset to process */
  86.     PVFS_boolean eof_flag;     /* is file at end of flile */
  87. } PINT_Request_state;           
  88. /* NOTE - I think buf_offset is superceded by type_offset
  89.  * and start_offset can be completely replced with last_offset
  90.  * at which point target_offset could be renamed start_offset
  91.  * and last_offset could be renamed file_offset
  92.  */
  93.  
  94. typedef struct PINT_Request_result {
  95.     PVFS_offset  *offset_array;/* array of offsets for each segment output */
  96.     PVFS_size    *size_array;  /* array of sizes for each segment output */
  97.     int32_t      segmax;       /* maximum number of segments to output */
  98.     int32_t      segs;         /* number of segments output */
  99.     PVFS_size    bytemax;      /* maximum number of bytes to output */
  100.     PVFS_size    bytes;        /* number of bytes output */
  101. } PINT_Request_result;
  102.  
  103. typedef struct PINT_request_file_data_s {
  104.     PVFS_size    fsize;         /* actual size of local storage object */
  105.     uint32_t     server_nr;     /* ordinal number of THIS server for this file */
  106.     uint32_t     server_ct;     /* number of servers for this file */
  107.     struct PINT_dist_s *dist;   /* dist struct for the file */
  108.     PVFS_boolean extend_flag;   /* if zero, file will not be extended */
  109. } PINT_request_file_data;
  110.  
  111. struct PINT_Request_state *PINT_new_request_state(PINT_Request *request);
  112. void PINT_free_request_state(PINT_Request_state *req);
  113. struct PINT_Request_state *PINT_new_request_states(PINT_Request *request,
  114.                                                    int n);
  115. void PINT_free_request_states(PINT_Request_state *reqs);
  116.  
  117. /* generate offset length pairs from request and dist */
  118. int PINT_process_request(PINT_Request_state *req,
  119.         PINT_Request_state *mem,
  120.         PINT_request_file_data *rfdata,
  121.         PINT_Request_result *result,
  122.         int mode);
  123.  
  124. /* internal function */
  125. PVFS_size PINT_distribute(PVFS_offset offset,
  126.                           PVFS_size size,
  127.                           PINT_request_file_data *rfdata,
  128.                           PINT_Request_state *mem,
  129.                           PINT_Request_result *result,
  130.                           PVFS_boolean *eof_flag,
  131.                           int mode);
  132.  
  133. /* pack request from node into a contiguous buffer pointed to by region */
  134. int PINT_request_commit(PINT_Request *region, PINT_Request *node);
  135. PINT_Request *PINT_do_request_commit(PINT_Request *region, PINT_Request *node,
  136.         int32_t *index, int32_t depth);
  137. int PINT_do_clear_commit(PINT_Request *node, int32_t depth);
  138.  
  139. /* encode packed request in place for sending over wire */
  140. int PINT_request_encode(struct PINT_Request *req);
  141.  
  142. /* decode packed request in place after receiving from wire */
  143. int PINT_request_decode(struct PINT_Request *req);
  144.  
  145. void PINT_dump_packed_request(struct PINT_Request *req);
  146. void PINT_dump_request(struct PINT_Request *req);
  147.  
  148. #ifdef __PINT_REQPROTO_ENCODE_FUNCS_C
  149. #include "pint-request-encode.h"
  150. #endif
  151.  
  152. /********* macros for accessing key fields in a request *********/
  153.  
  154. #define PINT_REQUEST_NEST_SIZE(reqp)\
  155.         ((reqp)->num_nested_req)
  156.  
  157. /* returns the number of bytes used by a contiguous packing of the
  158.  * request struct pointed to by reqp
  159.  */
  160. #define PINT_REQUEST_PACK_SIZE(reqp)\
  161.     ((PINT_REQUEST_NEST_SIZE(reqp) + 1) * sizeof(struct PINT_Request))
  162.  
  163. /* returns true if the request struct pointed to by reqp is a packed
  164.  * struct
  165.  */
  166. #define PINT_REQUEST_IS_PACKED(reqp)\
  167.     ((reqp)->committed < 0)
  168.  
  169. /* returns the number of contiguous memory regions referenced by the
  170.  * request struct pointed to by reqp
  171.  */
  172. #define PINT_REQUEST_NUM_CONTIG(reqp)\
  173.     ((reqp)->num_contig_chunks)
  174.  
  175. /* returns the total number of bytes referenced by the struct pointed to
  176.  * by reqp - bytes might not be contiguous
  177.  */
  178. #define PINT_REQUEST_TOTAL_BYTES(reqp)\
  179.     ((reqp)->aggregate_size)
  180.  
  181. /* sets the target_offset to the given value */
  182. #define PINT_REQUEST_STATE_SET_TARGET(reqp,val)\
  183.     ((reqp)->target_offset) = (val)
  184.  
  185. /* sets the final_offset to the given value */
  186. #define PINT_REQUEST_STATE_SET_FINAL(reqp,val)\
  187.     ((reqp)->final_offset) = (val)
  188.  
  189. /* this one does not zero the start_offset 
  190.  * mainly used inside of process_request */
  191. #define PINT_REQUEST_STATE_RST(reqp)\
  192.     do {\
  193.     ((reqp)->lvl) = 0;\
  194.     ((reqp)->bytes) = 0;\
  195.     ((reqp)->type_offset) = 0;\
  196.     ((reqp)->eof_flag) = 0;\
  197.     ((reqp)->cur[0].el) = 0;\
  198.     ((reqp)->cur[0].rq) = ((reqp)->cur[0].rqbase);\
  199.     ((reqp)->cur[0].blk) = 0;\
  200.     ((reqp)->cur[0].chunk_offset) = 0;\
  201.     }while(0)
  202.  
  203. /* this one DOES zero the start_offset 
  204.  * intended for flow code to reset a request to the beginning */
  205. #define PINT_REQUEST_STATE_RESET(reqp)\
  206.     do {\
  207.     PINT_REQUEST_STATE_RST(reqp);\
  208.     }while(0)
  209.  
  210. /* checks to see if you have run out of request */
  211. #define PINT_REQUEST_DONE(reqp)\
  212.     (((reqp)->type_offset >= (reqp)->final_offset) ||\
  213.      ((reqp)->eof_flag))
  214.  
  215. /* checks to see if you have hit EOF */
  216. #define PINT_REQUEST_EOF(reqp)\
  217.       (reqp)->eof_flag
  218.  
  219. /* set ref count of request to 1
  220.  * never modify a refcount below zero
  221.  */
  222. #define PINT_REQUEST_REFSET(reqp)\
  223.     do { \
  224.         if ((reqp)->refcount >= 0) \
  225.             (reqp)->refcount = 1; \
  226.     } while(0)
  227.  
  228. /* increments ref count of request 
  229.  * never modify a refcount below zero
  230.  */
  231. #define PINT_REQUEST_REFINC(reqp)\
  232.     do { \
  233.         if ((reqp)->refcount >= 0) \
  234.             (reqp)->refcount++; \
  235.     } while(0)
  236.  
  237. /* decrements ref count of request 
  238.  * never decrement below zero
  239.  * need to add function to recursively free request
  240.  */
  241. #define PINT_REQUEST_REFDEC(reqp)\
  242.     do { \
  243.         if ((reqp)->refcount > 0) \
  244.             (reqp)->refcount--; \
  245.     } while(0)
  246.  
  247. #endif /* __PINT_REQUEST_H */
  248.  
  249.  
  250. /*
  251.  * Local variables:
  252.  *  mode: c
  253.  *  c-indent-level: 4
  254.  *  c-basic-offset: 4
  255.  * End:
  256.  *
  257.  * vim: ft=c ts=8 sts=4 sw=4 expandtab
  258.  */
  259.