Whamcloud - gitweb
Add missing files, cleanup .cvsignore's
[fs/lustre-release.git] / lustre / include / linux / lustre_light.h
1 /* object based disk file system
2  * 
3  * This code is issued under the GNU General Public License.
4  * See the file COPYING in this distribution
5  * 
6  * Copyright (C), 1999, Stelias Computing Inc
7  *
8  *
9  */
10
11
12 #ifndef _LL_H
13 #define _LL_H
14 #include <linux/obd_class.h>
15 #include <linux/obdo.h>
16 #include <linux/list.h>
17
18 #define LL_SUPER_MAGIC 0x0BD00BD0;
19
20 struct ll_inode_info {
21         int              lli_flags;
22         struct list_head lli_inodes;
23         struct list_head lli_pages;
24         char             lli_inline[OBD_INLINESZ];
25 };
26
27 struct ll_sb_info {
28         struct list_head         ll_list;      /* list of supers */
29         struct obd_conn          ll_conn;
30         struct super_block      *ll_super;
31         //        struct obd_device       *ll_obd;
32         //struct obd_ops          *ll_ops;
33         ino_t                    ll_rootino;   /* number of root inode */
34         int                      ll_minor;     /* minor of /dev/obdX */
35         struct list_head         ll_inodes;    /* list of dirty inodes */
36         unsigned long            ll_cache_count;
37         struct semaphore         ll_list_mutex;
38 };
39
40
41 static inline struct ll_inode_info *ll_i2info(struct inode *inode)
42 {
43         return (struct ll_inode_info *)&(inode->u.generic_ip);
44 }
45
46 static inline int ll_has_inline(struct inode *inode)
47 {
48         return (ll_i2info(inode)->lli_flags & OBD_FL_INLINEDATA);
49 }
50
51 static void inline ll_from_inode(struct obdo *oa, struct inode *inode)
52 {
53         struct ll_inode_info *oinfo = ll_i2info(inode);
54
55         CDEBUG(D_INFO, "src inode %ld, dst obdo %ld valid 0x%08x\n",
56                inode->i_ino, (long)oa->o_id, oa->o_valid);
57         obdo_from_inode(oa, inode);
58         if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode)) {
59                 CDEBUG(D_INODE, "copying device %x from inode to obdo\n",
60                        inode->i_rdev);
61                 *((obd_rdev *)oa->o_inline) = kdev_t_to_nr(inode->i_rdev);
62                 oa->o_obdflags |= OBD_FL_INLINEDATA;
63                 oa->o_valid |= OBD_MD_FLINLINE;
64         } else if (ll_has_inline(inode)) {
65                 CDEBUG(D_INODE, "copying inline data from inode to obdo\n");
66                 memcpy(oa->o_inline, oinfo->lli_inline, OBD_INLINESZ);
67                 oa->o_obdflags |= OBD_FL_INLINEDATA;
68                 oa->o_valid |= OBD_MD_FLINLINE;
69         }
70 } /* ll_from_inode */
71
72 static __inline__ void mds_rep_to_inode(struct inode *dst, struct mds_rep *rep)
73 {
74
75         if ( rep->valid & OBD_MD_FLID )
76                 dst->i_ino = rep->ino;
77         if ( rep->valid & OBD_MD_FLATIME ) 
78                 dst->i_atime = rep->atime;
79         if ( rep->valid & OBD_MD_FLMTIME ) 
80                 dst->i_mtime = rep->mtime;
81         if ( rep->valid & OBD_MD_FLCTIME ) 
82                 dst->i_ctime = rep->ctime;
83         if ( rep->valid & OBD_MD_FLSIZE ) 
84                 dst->i_size = rep->size;
85         if ( rep->valid & OBD_MD_FLMODE ) 
86                 dst->i_mode = rep->mode;
87         if ( rep->valid & OBD_MD_FLUID ) 
88                 dst->i_uid = rep->uid;
89         if ( rep->valid & OBD_MD_FLGID ) 
90                 dst->i_gid = rep->gid;
91         if ( rep->valid & OBD_MD_FLFLAGS ) 
92                 dst->i_flags = rep->flags;
93         if ( rep->valid & OBD_MD_FLNLINK )
94                 dst->i_nlink = rep->nlink;
95         if ( rep->valid & OBD_MD_FLGENER )
96                 dst->i_generation = rep->generation;
97 }
98
99 static void inline ll_to_inode(struct inode *inode, struct mds_rep *rep)
100 {
101         CDEBUG(D_INFO, "src obdo %d valid 0x%08x, dst inode %ld\n",
102                rep->ino, rep->valid, inode->i_ino);
103
104         mds_rep_to_inode(inode, rep);
105
106 #if 0
107         if (obdo_has_inline(oa)) {
108                 if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode) ||
109                     S_ISFIFO(inode->i_mode)) {
110                         obd_rdev rdev = *((obd_rdev *)oa->o_inline);
111                         CDEBUG(D_INODE,
112                                "copying device %x from obdo to inode\n", rdev);
113                         init_special_inode(inode, inode->i_mode, rdev);
114                 } else {
115                         CDEBUG(D_INFO, "copying inline from obdo to inode\n");
116                         memcpy(oinfo->lli_inline, oa->o_inline, OBD_INLINESZ);
117                 }
118                 oinfo->lli_flags |= OBD_FL_INLINEDATA;
119         }
120 #endif 
121 } /* ll_to_inode */
122
123
124
125
126 /* super.c */ 
127 struct ll_pgrq {
128         struct list_head         rq_plist;      /* linked list of req's */
129         unsigned long            rq_jiffies;
130         struct page             *rq_page;       /* page to be written */
131 };
132
133 extern struct list_head ll_super_list;       /* list of all LL superblocks */
134
135
136
137 /* dir.c */
138 #define EXT2_DIR_PAD                    4
139 #define EXT2_DIR_ROUND                  (EXT2_DIR_PAD - 1)
140 #define EXT2_DIR_REC_LEN(name_len)      (((name_len) + 8 + EXT2_DIR_ROUND) & \
141                                          ~EXT2_DIR_ROUND)
142 #define EXT2_NAME_LEN 255
143
144 int ll_check_dir_entry (const char * function, struct inode * dir,
145                           struct ext2_dir_entry_2 * de, struct page * page,
146                           unsigned long offset);
147 extern struct file_operations ll_dir_operations;
148 extern struct inode_operations ll_dir_inode_operations;
149
150 /* file.c */
151 extern struct file_operations ll_file_operations;
152 extern struct inode_operations ll_file_inode_operations;
153
154 /* flush.c */
155 void ll_dequeue_pages(struct inode *inode);
156 int ll_flushd_init(void);
157 int ll_flushd_cleanup(void);
158 int ll_flush_reqs(struct list_head *inode_list, unsigned long check_time);
159 int ll_flush_dirty_pages(unsigned long check_time);
160
161 /* namei.c */
162 /*
163  * Structure of the super block
164  */
165
166
167 #define EXT2_SB(sb)     (&((sb)->u.ext2_sb))
168 /*
169  * Maximal count of links to a file
170  */
171 #define EXT2_LINK_MAX           32000
172 /*
173  * Ext2 directory file types.  Only the low 3 bits are used.  The
174  * other bits are reserved for now.
175  */
176 #define EXT2_FT_UNKNOWN         0
177 #define EXT2_FT_REG_FILE        1
178 #define EXT2_FT_DIR             2
179 #define EXT2_FT_CHRDEV          3
180 #define EXT2_FT_BLKDEV          4
181 #define EXT2_FT_FIFO            5
182 #define EXT2_FT_SOCK            6
183 #define EXT2_FT_SYMLINK         7
184
185 #define EXT2_FT_MAX             8
186
187 #define EXT2_BTREE_FL                   0x00001000 /* btree format dir */
188 #define EXT2_RESERVED_FL                0x80000000 /* reserved for ext2 lib */
189 #define EXT2_FEATURE_INCOMPAT_FILETYPE          0x0002
190 #define EXT2_HAS_COMPAT_FEATURE(sb,mask)                        \
191         ( EXT2_SB(sb)->s_es->s_feature_compat & cpu_to_le32(mask) )
192 #define EXT2_HAS_INCOMPAT_FEATURE(sb,mask)                      \
193         ( EXT2_SB(sb)->s_es->s_feature_incompat & cpu_to_le32(mask) )
194
195 /* rw.c */
196 int ll_do_writepage(struct page *, int sync);
197 int ll_init_pgrqcache(void);
198 void ll_cleanup_pgrqcache(void);
199 inline void ll_pgrq_del(struct ll_pgrq *pgrq);
200 int ll_readpage(struct file *file, struct page *page);
201 int ll_prepare_write(struct file *file, struct page *page, unsigned from, unsigned to);
202 int ll_commit_write(struct file *file, struct page *page, unsigned from, unsigned to);
203 int ll_writepage(struct page *page);
204 struct page *ll_getpage(struct inode *inode, unsigned long offset,
205                            int create, int locked);
206 int ll_write_one_page(struct file *file, struct page *page,
207                          unsigned long offset, unsigned long bytes,
208                          const char * buf);
209 int ll_do_vec_wr(struct inode **inodes, obd_count num_io, obd_count num_oa,
210                     struct obdo **obdos, obd_count *oa_bufs,
211                     struct page **pages, char **bufs, obd_size *counts,
212                     obd_off *offsets, obd_flag *flags);
213 void ll_truncate(struct inode *inode);
214
215 /* super.c */
216 extern long ll_cache_count;
217 extern long ll_mutex_start;
218
219 /* symlink.c */
220 extern struct inode_operations ll_fast_symlink_inode_operations;
221 extern struct inode_operations ll_symlink_inode_operations;
222
223 /* sysctl.c */
224 void ll_sysctl_init(void);
225 void ll_sysctl_clean(void);
226
227 static inline struct ll_sb_info *ll_i2sbi(struct inode *inode)
228 {
229         return (struct ll_sb_info *) &(inode->i_sb->u.generic_sbp);
230 }
231
232 static inline struct list_head *ll_iplist(struct inode *inode) 
233 {
234         struct ll_inode_info *info = ll_i2info(inode);
235
236         return &info->lli_pages;
237 }
238
239 static inline struct list_head *ll_islist(struct inode *inode) 
240 {
241         struct ll_inode_info *info = ll_i2info(inode);
242
243         return &info->lli_inodes;
244 }
245
246 static inline struct list_head *ll_slist(struct inode *inode) 
247 {
248         struct ll_sb_info *sbi = ll_i2sbi(inode);
249
250         return &sbi->ll_inodes;
251 }
252
253 static void inline ll_set_size (struct inode *inode, obd_size size)
254 {  
255        inode->i_size = size;
256        inode->i_blocks = (inode->i_size + inode->i_sb->s_blocksize - 1) >>
257                inode->i_sb->s_blocksize_bits;
258 } /* ll_set_size */
259
260
261
262 #define obd_down(mutex) {                                               \
263         /* CDEBUG(D_INFO, "get lock\n"); */                             \
264         ll_mutex_start = jiffies;                                    \
265         down(mutex);                                                    \
266         if (jiffies - ll_mutex_start)                                \
267                 CDEBUG(D_CACHE, "waited on mutex %ld jiffies\n",        \
268                        jiffies - ll_mutex_start);                    \
269 }
270
271 #define obd_up(mutex) {                                                 \
272         up(mutex);                                                      \
273         if (jiffies - ll_mutex_start > 1)                            \
274                 CDEBUG(D_CACHE, "held mutex for %ld jiffies\n",         \
275                        jiffies - ll_mutex_start);                    \
276         /* CDEBUG(D_INFO, "free lock\n"); */                            \
277 }
278
279 /* We track if a page has been added to the OBD page cache by stting a
280  * flag on the page.  We have chosen a bit that will hopefully not be
281  * used for a while.
282  */
283 #define PG_obdcache 29
284 #define OBDAddCachePage(page)   test_and_set_bit(PG_obdcache, &(page)->flags)
285 #define OBDClearCachePage(page) clear_bit(PG_obdcache, &(page)->flags)
286
287 static inline void ll_print_plist(struct inode *inode) 
288 {
289         struct list_head *page_list = ll_iplist(inode);
290         struct list_head *tmp;
291
292         CDEBUG(D_INFO, "inode %ld: page", inode->i_ino);
293         /* obd_down(&ll_i2sbi(inode)->ll_list_mutex); */
294         if (list_empty(page_list)) {
295                 CDEBUG(D_INFO, " list empty\n");
296                 obd_up(&ll_i2sbi(inode)->ll_list_mutex);
297                 return;
298         }
299
300         tmp = page_list;
301         while ( (tmp = tmp->next) != page_list) {
302                 struct ll_pgrq *pgrq;
303                 pgrq = list_entry(tmp, struct ll_pgrq, rq_plist);
304                 CDEBUG(D_INFO, " %p", pgrq->rq_page);
305         }
306         CDEBUG(D_INFO, "\n");
307         /* obd_up(&ll_i2sbi(inode)->ll_list_mutex); */
308 }
309 #include <linux/obdo.h>
310
311 #endif
312