1 /* Copyright(C) 2005 Takuo Kitame <kitame @ valinux. co. jp>
2 
3   This library is free software; you can redistribute it and/or
4   modify it under the terms of the GNU Lesser General Public
5   License as published by the Free Software Foundation; either
6   version 2.1 of the License, or (at your option) any later version.
7 
8   This library is distributed in the hope that it will be useful,
9   but WITHOUT ANY WARRANTY; without even the implied warranty of
10   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11   Lesser General Public License for more details.
12 
13   You should have received a copy of the GNU Lesser General Public
14   License along with this library; if not, write to the Free Software
15   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16 */
17 
18 #ifdef USE_AIO
19 
20 #ifndef SEN_CACHE_H
21 #define SEN_CACHE_H
22 
23 /* feature switch */
24 extern int sen_aio_enabled;
25 extern int sen_debug_print;
26 extern int sen_cache_block;
27 
28 #include <aio.h>
29 
30 /* CacheData structure */
31 typedef struct _CacheData CacheData;
32 #pragma pack(1)
33 struct _CacheData {
34     int flag; /* status */
35     unsigned int stamp; /* global counter stamp */
36 
37     /* key */
38     dev_t dev;
39     ino_t inode;
40     unsigned int offset;
41     unsigned int size;
42     /* end key */
43 
44     /* number */
45     unsigned int num;
46     int next; /* -1 : no more next */
47 
48     /* number of references */
49     int ref;
50 };
51 #pragma pack()
52 
53 /* status of CacheData */
54 enum {
55     CACHE_INVALID, /* empty, unused  */
56     CACHE_VALID,   /* data in */
57     CACHE_READ,    /* reading */
58     CACHE_LOCKED   /* locked */
59 };
60 
61 /* Cache IO Operation */
62 typedef struct _CacheIOOper CacheIOOper;
63 struct _CacheIOOper {
64     CacheData *cd;
65     struct aiocb *iocb; /* AIO control block */
66     int read; /* real read() is reqired or not.*/
67 };
68 
69 /* open and initialize */
70 void sen_cache_open (void);
71 
72 /* read data via cache */
73 void *sen_cache_read (CacheIOOper *oper, dev_t dev, ino_t inode, size_t offset, size_t vsize);
74 
75 /* reference counter operations */
76 void sen_cache_data_unref (int number);
77 void sen_cache_data_ref (int number);
78 
79 
80 /* use when write a segment */
81 void
82 sen_cache_mark_invalid (dev_t dev, ino_t inode, off_t offset, size_t size);
83 
84 /* used for debug */
85 void sen_cache_dump (void);
86 
87 #include <stdarg.h>
88 
89 inline static void
dp(char * fmt,...)90 dp(char *fmt, ...)
91 {
92   if (sen_debug_print) {
93     va_list argp;
94     va_start(argp, fmt);
95     vfprintf(stderr, fmt, argp);
96     va_end(argp);
97   }
98 }
99 
100 #endif /* SEN_CACHE_H */
101 
102 #endif /* USE_AIO */
103