Whamcloud - gitweb
A few missing files...
[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 void inline ll_to_inode(struct inode *inode, struct obdo *oa)
73 {
74         struct ll_inode_info *oinfo = ll_i2info(inode);
75
76         CDEBUG(D_INFO, "src obdo %ld valid 0x%08x, dst inode %ld\n",
77                (long)oa->o_id, oa->o_valid, inode->i_ino);
78
79         obdo_to_inode(inode, oa);
80
81         if (obdo_has_inline(oa)) {
82                 if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode) ||
83                     S_ISFIFO(inode->i_mode)) {
84                         obd_rdev rdev = *((obd_rdev *)oa->o_inline);
85                         CDEBUG(D_INODE,
86                                "copying device %x from obdo to inode\n", rdev);
87                         init_special_inode(inode, inode->i_mode, rdev);
88                 } else {
89                         CDEBUG(D_INFO, "copying inline from obdo to inode\n");
90                         memcpy(oinfo->lli_inline, oa->o_inline, OBD_INLINESZ);
91                 }
92                 oinfo->lli_flags |= OBD_FL_INLINEDATA;
93         }
94 } /* ll_to_inode */
95
96
97
98
99 /* super.c */ 
100 struct ll_pgrq {
101         struct list_head         rq_plist;      /* linked list of req's */
102         unsigned long            rq_jiffies;
103         struct page             *rq_page;       /* page to be written */
104 };
105
106 extern struct list_head ll_super_list;       /* list of all LL superblocks */
107
108
109
110 /* dir.c */
111 #define EXT2_DIR_PAD                    4
112 #define EXT2_DIR_ROUND                  (EXT2_DIR_PAD - 1)
113 #define EXT2_DIR_REC_LEN(name_len)      (((name_len) + 8 + EXT2_DIR_ROUND) & \
114                                          ~EXT2_DIR_ROUND)
115 #define EXT2_NAME_LEN 255
116
117 int ll_check_dir_entry (const char * function, struct inode * dir,
118                           struct ext2_dir_entry_2 * de, struct page * page,
119                           unsigned long offset);
120 extern struct file_operations ll_dir_operations;
121 extern struct inode_operations ll_dir_inode_operations;
122
123 /* file.c */
124 extern struct file_operations ll_file_operations;
125 extern struct inode_operations ll_file_inode_operations;
126
127 /* flush.c */
128 void ll_dequeue_pages(struct inode *inode);
129 int ll_flushd_init(void);
130 int ll_flushd_cleanup(void);
131 int ll_flush_reqs(struct list_head *inode_list, unsigned long check_time);
132 int ll_flush_dirty_pages(unsigned long check_time);
133
134 /* namei.c */
135 /*
136  * Structure of the super block
137  */
138
139
140 #define EXT2_SB(sb)     (&((sb)->u.ext2_sb))
141 /*
142  * Maximal count of links to a file
143  */
144 #define EXT2_LINK_MAX           32000
145 /*
146  * Ext2 directory file types.  Only the low 3 bits are used.  The
147  * other bits are reserved for now.
148  */
149 #define EXT2_FT_UNKNOWN         0
150 #define EXT2_FT_REG_FILE        1
151 #define EXT2_FT_DIR             2
152 #define EXT2_FT_CHRDEV          3
153 #define EXT2_FT_BLKDEV          4
154 #define EXT2_FT_FIFO            5
155 #define EXT2_FT_SOCK            6
156 #define EXT2_FT_SYMLINK         7
157
158 #define EXT2_FT_MAX             8
159
160 #define EXT2_BTREE_FL                   0x00001000 /* btree format dir */
161 #define EXT2_RESERVED_FL                0x80000000 /* reserved for ext2 lib */
162 #define EXT2_FEATURE_INCOMPAT_FILETYPE          0x0002
163 #define EXT2_HAS_COMPAT_FEATURE(sb,mask)                        \
164         ( EXT2_SB(sb)->s_es->s_feature_compat & cpu_to_le32(mask) )
165 #define EXT2_HAS_INCOMPAT_FEATURE(sb,mask)                      \
166         ( EXT2_SB(sb)->s_es->s_feature_incompat & cpu_to_le32(mask) )
167
168 /* rw.c */
169 int ll_do_writepage(struct page *, int sync);
170 int ll_init_pgrqcache(void);
171 void ll_cleanup_pgrqcache(void);
172 inline void ll_pgrq_del(struct ll_pgrq *pgrq);
173 int ll_readpage(struct file *file, struct page *page);
174 int ll_prepare_write(struct file *file, struct page *page, unsigned from, unsigned to);
175 int ll_commit_write(struct file *file, struct page *page, unsigned from, unsigned to);
176 int ll_writepage(struct page *page);
177 struct page *ll_getpage(struct inode *inode, unsigned long offset,
178                            int create, int locked);
179 int ll_write_one_page(struct file *file, struct page *page,
180                          unsigned long offset, unsigned long bytes,
181                          const char * buf);
182 int ll_do_vec_wr(struct inode **inodes, obd_count num_io, obd_count num_oa,
183                     struct obdo **obdos, obd_count *oa_bufs,
184                     struct page **pages, char **bufs, obd_size *counts,
185                     obd_off *offsets, obd_flag *flags);
186 void ll_truncate(struct inode *inode);
187
188 /* super.c */
189 extern long ll_cache_count;
190 extern long ll_mutex_start;
191
192 /* symlink.c */
193 extern struct inode_operations ll_fast_symlink_inode_operations;
194 extern struct inode_operations ll_symlink_inode_operations;
195
196 /* sysctl.c */
197 void ll_sysctl_init(void);
198 void ll_sysctl_clean(void);
199
200 static inline struct ll_sb_info *ll_i2sbi(struct inode *inode)
201 {
202         return (struct ll_sb_info *) &(inode->i_sb->u.generic_sbp);
203 }
204
205 static inline struct list_head *ll_iplist(struct inode *inode) 
206 {
207         struct ll_inode_info *info = ll_i2info(inode);
208
209         return &info->lli_pages;
210 }
211
212 static inline struct list_head *ll_islist(struct inode *inode) 
213 {
214         struct ll_inode_info *info = ll_i2info(inode);
215
216         return &info->lli_inodes;
217 }
218
219 static inline struct list_head *ll_slist(struct inode *inode) 
220 {
221         struct ll_sb_info *sbi = ll_i2sbi(inode);
222
223         return &sbi->ll_inodes;
224 }
225
226 static void inline ll_set_size (struct inode *inode, obd_size size)
227 {  
228        inode->i_size = size;
229        inode->i_blocks = (inode->i_size + inode->i_sb->s_blocksize - 1) >>
230                inode->i_sb->s_blocksize_bits;
231 } /* ll_set_size */
232
233
234
235 #define obd_down(mutex) {                                               \
236         /* CDEBUG(D_INFO, "get lock\n"); */                             \
237         ll_mutex_start = jiffies;                                    \
238         down(mutex);                                                    \
239         if (jiffies - ll_mutex_start)                                \
240                 CDEBUG(D_CACHE, "waited on mutex %ld jiffies\n",        \
241                        jiffies - ll_mutex_start);                    \
242 }
243
244 #define obd_up(mutex) {                                                 \
245         up(mutex);                                                      \
246         if (jiffies - ll_mutex_start > 1)                            \
247                 CDEBUG(D_CACHE, "held mutex for %ld jiffies\n",         \
248                        jiffies - ll_mutex_start);                    \
249         /* CDEBUG(D_INFO, "free lock\n"); */                            \
250 }
251
252 /* We track if a page has been added to the OBD page cache by stting a
253  * flag on the page.  We have chosen a bit that will hopefully not be
254  * used for a while.
255  */
256 #define PG_obdcache 29
257 #define OBDAddCachePage(page)   test_and_set_bit(PG_obdcache, &(page)->flags)
258 #define OBDClearCachePage(page) clear_bit(PG_obdcache, &(page)->flags)
259
260 static inline void ll_print_plist(struct inode *inode) 
261 {
262         struct list_head *page_list = ll_iplist(inode);
263         struct list_head *tmp;
264
265         CDEBUG(D_INFO, "inode %ld: page", inode->i_ino);
266         /* obd_down(&ll_i2sbi(inode)->ll_list_mutex); */
267         if (list_empty(page_list)) {
268                 CDEBUG(D_INFO, " list empty\n");
269                 obd_up(&ll_i2sbi(inode)->ll_list_mutex);
270                 return;
271         }
272
273         tmp = page_list;
274         while ( (tmp = tmp->next) != page_list) {
275                 struct ll_pgrq *pgrq;
276                 pgrq = list_entry(tmp, struct ll_pgrq, rq_plist);
277                 CDEBUG(D_INFO, " %p", pgrq->rq_page);
278         }
279         CDEBUG(D_INFO, "\n");
280         /* obd_up(&ll_i2sbi(inode)->ll_list_mutex); */
281 }
282 #include <linux/obdo.h>
283
284 #endif
285