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 / internal.h < prev    next >
C/C++ Source or Header  |  2006-12-05  |  8KB  |  346 lines

  1. #ifndef CACHE_INTERNAL_H
  2. #define CACHE_INTERNAL_H
  3.  
  4. #include <string.h>
  5. #include <pthread.h>
  6. #include "ncac-interface.h"
  7. #include "ncac-list.h"
  8. #include "radix.h"
  9. #include "aiovec.h"
  10. #include "flags.h"
  11. #include "ncac-locks.h"
  12.  
  13.  
  14. typedef cache_desc_t NCAC_desc_t;
  15. typedef int          NCAC_optype;
  16. typedef cache_reply_t NCAC_reply_t;
  17.  
  18. typedef gen_mutex_t NCAC_lock;
  19.  
  20. struct NCAC_cache_info{
  21.     int max_req_num;
  22.     int extsize;
  23.     int cachesize;
  24.     void *cachespace;
  25. };
  26.  
  27. struct cache_stack {
  28.     struct list_head list;
  29.     NCAC_lock           lock;
  30.     unsigned long    nr_inactive;
  31.     unsigned long    nr_active;
  32.     struct list_head active_list;
  33.     struct list_head inactive_list;
  34.  
  35.     unsigned long      nr_free;
  36.     struct list_head free_extent_list;
  37.     unsigned long    nr_dirty;
  38.     unsigned long    nr_writeback;
  39.     unsigned long    ratelimits;
  40. };
  41.  
  42. typedef struct NCAC_cache_info NCAC_info_t;
  43.  
  44. struct NCAC_dev{
  45.     unsigned long extsize;
  46.     unsigned long extlog2;
  47.  
  48.     unsigned long cachesize;
  49.     unsigned long extcnt;
  50.     char *cachemem;
  51.  
  52.     unsigned long mrwusize;
  53.  
  54.     /* free req list */
  55.     struct list_head free_req_list;
  56.     struct NCAC_req  *free_req_src;
  57.     unsigned int     free_req_num;
  58.  
  59.     /* a non-free request could be in one of the three lists */
  60.     struct list_head prepare_list;
  61.     struct list_head bufcomp_list;
  62.     struct list_head comp_list;
  63.     
  64.     /* lock to manage requests in different lists */
  65.     NCAC_lock        req_list_lock;
  66.  
  67.     /* extent list */
  68.     struct extent *free_extent_src;
  69.     NCAC_lock  extent_list_lock;
  70.     
  71.  
  72.     /* cache stack */
  73.     struct cache_stack cache_stack;
  74.  
  75.     /* for radix tree if LINUX radix tree is not used */
  76.     unsigned long (* get_value)(const void *);
  77.     int max_b;
  78.     
  79. };
  80.  
  81. typedef struct NCAC_dev NCAC_dev_t;
  82.  
  83.  
  84. struct NCAC_req{
  85.    int              id;
  86.    int              optype;
  87.    int              status;
  88.    int              error;
  89.    PVFS_fs_id       coll_id;
  90.    PVFS_handle      handle;
  91.    PVFS_context_id  context_id;
  92.  
  93.    PVFS_size        usrlen;
  94.    PVFS_size        written;
  95.    char             *usrbuf;
  96.  
  97.    PVFS_offset *foff;
  98.    char ** cbufoff;
  99.    PVFS_size *cbufsize;
  100.    int *cbufflag;
  101.    struct extent **cbufhash;
  102.    int *cbufrcnt;
  103.    int *cbufwcnt; 
  104.    
  105.    int  cbufcnt;
  106.    int reserved_cbufcnt;
  107.  
  108.    PVFS_offset pos;
  109.    PVFS_size   size;
  110.  
  111.    PVFS_offset *offvec;
  112.    PVFS_size   *sizevec;
  113.    int         offcnt;
  114.  
  115.  
  116.    struct inode *mapping;
  117.    struct aiovec *aiovec;
  118.    PVFS_id_gen_t ioreq;
  119.  
  120.    int read_out;
  121.    struct list_head list;
  122.  
  123.    int nr_dirty;
  124.    //struct list_head dirty_list;
  125. };
  126.  
  127. typedef struct NCAC_req NCAC_req_t;
  128.  
  129.  
  130. #define  NCAC_READ_PENDING 1
  131. #define  NCAC_WRITE_PENDING 2 
  132. #define  NCAC_COMM_READ_PENDING  3 
  133. #define  NCAC_COMM_WRITE_PENDING 4 
  134. #define  NCAC_BLANK          5 
  135. #define  NCAC_CLEAN          6 
  136. #define  NCAC_UPTODATE          7
  137.  
  138. /* this is an inode-like structure for each
  139.  * object <coll_id, handle>
  140.  */
  141. #define MAX_INODE_NUM     10000
  142.  
  143. struct inode
  144. {
  145.     NCAC_lock  lock;
  146.  
  147.     PVFS_fs_id        coll_id;
  148.     PVFS_handle      handle;
  149.     PVFS_context_id  context_id;
  150.  
  151.     struct radix_tree_root page_tree;
  152.  
  153.     struct list_head clean_pages;
  154.     struct list_head dirty_pages;
  155.     unsigned long nrpages;
  156.     int  nr_dirty;
  157.  
  158.     struct aiovec aiovec;
  159.     struct cache_stack *cache_stack;
  160.     struct inode *next;
  161. };
  162.  
  163. extern struct inode *inode_arr[MAX_INODE_NUM];
  164.  
  165.  
  166. struct extent {
  167.    unsigned long   flags;
  168.    int         status;
  169.    char     *addr;
  170.    int      id;
  171.    unsigned long index;
  172.  
  173.    struct list_head  list;
  174.    struct list_head  lru;
  175.  
  176.    unsigned int writes;
  177.    unsigned int reads;
  178.    unsigned int rcmp;
  179.    unsigned int wcmp;
  180.  
  181.    struct extent *next;
  182.    struct inode *mapping;
  183.  
  184.    PVFS_id_gen_t      ioreq;
  185.  
  186.    /* for optimization. We can initiate one trove request for
  187.     * a list of extents. For doing that, all extents will share
  188.     * the same ioreq. If the ioreq is done, we follow ioreq_next
  189.     * to mark all other extents.
  190.     */
  191.    struct extent    *ioreq_next; 
  192. };
  193.  
  194.  
  195. #define MAX_DELT_REQ_NUM 10000
  196.  
  197.  
  198.  
  199. #define NCAC_OK            0
  200. #define NCAC_REQ_BUILD_ERR    -1000
  201. #define NCAC_SUBMIT_ERR     -1001
  202. #define NCAC_NO_REQ        -1002
  203. #define NCAC_NO_MEM        -1003
  204. #define NCAC_JOB_PREPARE_ERR        -1004
  205. #define NCAC_JOB_PUT_ERR    -1005
  206. #define NCAC_JOB_DO_ERR     -1006
  207. #define NCAC_JOB_OPTYPE_ERR -1007
  208. #define NCAC_JOB_PROCESS_ERR  -1008
  209. #define NCAC_NO_EXT_ERR     -1009
  210. #define NCAC_CACHE_ERR      -1010
  211. #define NCAC_TROVE_AIO_REQ_ERR -1011
  212. #define NCAC_CBUF_CNT_ERR     -1012
  213. #define NCAC_REQ_STATUS_ERR     -1013
  214. #define NCAC_REQ_DONE_ERR     -1014
  215. #define NCAC_INVAL_FLAGS    -1021
  216.  
  217.  
  218. /* request status */
  219. #define  NCAC_ERR_STATUS    -1
  220. #define  NCAC_REQ_UNUSED    0
  221. #define  NCAC_REQ_SUBMITTED      1 
  222. #define  NCAC_PARTIAL_PROCESS     2
  223. #define  NCAC_BUFFER_COMPLETE   3 
  224. #define  NCAC_COMPLETE           4 
  225.  
  226.  
  227. #define NCAC_GEN_READ   1 
  228. #define NCAC_GEN_WRITE  2 
  229.  
  230.  
  231. #define INVAL_IOREQ    -1
  232.  
  233.  
  234.  
  235. extern NCAC_dev_t NCAC_dev;
  236.  
  237.  
  238. int cache_init(NCAC_info_t *info);
  239. NCAC_req_t *NCAC_rwreq_build(NCAC_desc_t*desc, NCAC_optype optype);
  240. int NCAC_rwjob_prepare(NCAC_req_t *ncac_req, NCAC_reply_t *reply );
  241.  
  242. int NCAC_do_jobs(struct list_head *list, struct list_head *bufcomp_list, struct list_head * comp_list, NCAC_lock *lock);
  243. int NCAC_do_a_job(NCAC_req_t *req, struct list_head *list, struct list_head *bufcomp_list, struct list_head * comp_list, NCAC_lock *lock);
  244.  
  245. #define NCAC_COMM_NOT_READY    0
  246. #define NCAC_READ_PREPARE   1
  247. #define NCAC_READING        2
  248. #define NCAC_READ_READY     3
  249.  
  250. int NCAC_do_one_piece_read(NCAC_req_t *ncac_req, PVFS_offset pos,
  251.                            PVFS_size size, 
  252.                             PVFS_offset *foff,
  253.                             char **cbufoff,
  254.                            PVFS_size *cbufsize, struct extent *cbufhash[],
  255.                            int *cbufflag, int *cbufrcnt, int *cbufwcnt, int *cnt);
  256.  
  257. int NCAC_do_one_piece_write(NCAC_req_t *ncac_req, PVFS_offset pos,
  258.                            PVFS_size size, char **cbufoff,
  259.                            PVFS_size *cbufsize, struct extent *cbufhash[],
  260.                            int *cbufflag, int *cbufrcnt, int *cbufwcnt, int *cnt);
  261.  
  262. int NCAC_check_request(int id, struct NCAC_req **ncac_req);
  263. int NCAC_done_request( int id );
  264.  
  265.  
  266. static inline struct aiovec *get_aiovec(struct NCAC_req *ncac_req)
  267. {
  268.     return &(ncac_req->mapping->aiovec);
  269. }
  270.  
  271.  
  272. /*get_extent_cache_stack():
  273.  * extent ---> inode ---> cache stack
  274.  */
  275. static inline struct cache_stack *get_extent_cache_stack(struct extent *page)
  276. {
  277.     if (page==NULL) return NULL;
  278.     return (page->mapping->cache_stack);
  279. }
  280.  
  281.  
  282. static inline void
  283. add_page_to_active_list(struct cache_stack  *cache_stack, struct extent *page)
  284. {
  285.         list_add(&page->lru, &cache_stack->active_list);
  286.         cache_stack->nr_active++;
  287. }
  288.  
  289. static inline void
  290. add_page_to_inactive_list(struct cache_stack *cache_stack, struct extent *page)
  291. {
  292.         list_add(&page->lru, &cache_stack->inactive_list);
  293.         cache_stack->nr_inactive++;
  294. }
  295.  
  296. static inline void
  297. del_page_from_active_list(struct cache_stack *cache_stack, struct extent *page)
  298. {
  299.         list_del(&page->lru);
  300.         cache_stack->nr_active--;
  301. }
  302.  
  303. static inline void
  304. del_page_from_inactive_list(struct cache_stack *cache_stack, struct extent *page)
  305. {
  306.         list_del(&page->lru);
  307.         cache_stack->nr_inactive--;
  308. }
  309.  
  310. static inline void
  311. del_page_from_lru(struct cache_stack *cache_stack, struct extent *page)
  312. {
  313.         list_del(&page->lru);
  314.         if (PageActive(page)) {
  315.                 ClearPageActive(page);
  316.                 cache_stack->nr_active--;
  317.         } else {
  318.                 cache_stack->nr_inactive--;
  319.         }
  320. }
  321.  
  322. #define get_cache_stack()  (&NCAC_dev.cache_stack)
  323.  
  324.  
  325.  
  326. #if defined(DEBUG) 
  327.  
  328. #define DPRINT(fmt, args...) { fprintf(stderr, "[%s:%d]", __FILE__, __LINE__ ); fprintf(stderr, fmt, ## args); fprintf(stderr, "\n"); }
  329.  
  330. #else
  331.  
  332. #define DPRINT(fmt, args...)
  333.  
  334. #endif
  335.  
  336.  
  337. #define NCAC_error(fmt, args...) { fprintf(stderr, "[%s:%d]", __FILE__, __LINE__); fprintf(stderr, fmt, ## args); fprintf(stderr, "\n");}
  338.  
  339. /* gets defined in internal.c.  This needs a declaration so
  340.  * that tests can call it without warnings.
  341.  */
  342. void cache_dump_active_list(void);
  343. void cache_dump_inactive_list(void);
  344.  
  345. #endif
  346.