Whamcloud - gitweb
Now it really works again on 2.4.2! Yippeah. (No loop devices though.)
[fs/lustre-release.git] / lustre / include / linux / obdfs.h
1 /* object based disk file system
2  * 
3  * This software is licensed under the GPL.  See the file COPYING in the
4  * top directory of this distribution for details.
5  * 
6  * Copyright (C), 1999, Stelias Computing Inc
7  *
8  *
9  */
10
11
12 #ifndef _OBDFS_H
13 #define OBDFS_H
14 #include <linux/obd_class.h>
15 #include <linux/list.h>
16
17
18
19 struct obdfs_pgrq {
20         struct list_head         rq_plist;      /* linked list of req's */
21         unsigned long            rq_jiffies;
22         struct page             *rq_page;       /* page to be written */
23 };
24
25 struct list_head obdfs_super_list;       /* list of all OBDFS superblocks */
26
27 struct obdfs_sb_info {
28         struct list_head         osi_list;      /* list of supers */
29         struct obd_conn          osi_conn;
30         struct super_block      *osi_super;
31         struct obd_device       *osi_obd;
32         struct obd_ops          *osi_ops;
33         ino_t                    osi_rootino;   /* number of root inode */
34         int                      osi_minor;     /* minor of /dev/obdX */
35         struct list_head         osi_inodes;    /* list of dirty inodes */
36         unsigned long            osi_cache_count;
37         struct semaphore         osi_list_mutex;
38 };
39
40 struct obdfs_inode_info {
41         int              oi_flags;
42         struct list_head oi_inodes;
43         struct list_head oi_pages;
44         char             oi_inline[OBD_INLINESZ];
45 };
46
47 /* dir.c */
48 #define EXT2_DIR_PAD                    4
49 #define EXT2_DIR_ROUND                  (EXT2_DIR_PAD - 1)
50 #define EXT2_DIR_REC_LEN(name_len)      (((name_len) + 8 + EXT2_DIR_ROUND) & \
51                                          ~EXT2_DIR_ROUND)
52 #define EXT2_NAME_LEN 255
53 struct ext2_dir_entry_2 {
54         __u32   inode;                  /* Inode number */
55         __u16   rec_len;                /* Directory entry length */
56         __u8    name_len;               /* Name length */
57         __u8    file_type;
58         char    name[EXT2_NAME_LEN];    /* File name */
59 };
60 int obdfs_check_dir_entry (const char * function, struct inode * dir,
61                           struct ext2_dir_entry_2 * de, struct page * page,
62                           unsigned long offset);
63 extern struct file_operations obdfs_dir_operations;
64 extern struct inode_operations obdfs_dir_inode_operations;
65
66 /* file.c */
67 extern struct file_operations obdfs_file_operations;
68 extern struct inode_operations obdfs_file_inode_operations;
69
70 /* flush.c */
71 void obdfs_dequeue_pages(struct inode *inode);
72 int obdfs_flushd_init(void);
73 int obdfs_flushd_cleanup(void);
74 int obdfs_flush_reqs(struct list_head *inode_list, unsigned long check_time);
75 int obdfs_flush_dirty_pages(unsigned long check_time);
76
77 /* namei.c */
78 /*
79  * Structure of the super block
80  */
81 struct ext2_super_block {
82         __u32   s_inodes_count;         /* Inodes count */
83         __u32   s_blocks_count;         /* Blocks count */
84         __u32   s_r_blocks_count;       /* Reserved blocks count */
85         __u32   s_free_blocks_count;    /* Free blocks count */
86         __u32   s_free_inodes_count;    /* Free inodes count */
87         __u32   s_first_data_block;     /* First Data Block */
88         __u32   s_log_block_size;       /* Block size */
89         __s32   s_log_frag_size;        /* Fragment size */
90         __u32   s_blocks_per_group;     /* # Blocks per group */
91         __u32   s_frags_per_group;      /* # Fragments per group */
92         __u32   s_inodes_per_group;     /* # Inodes per group */
93         __u32   s_mtime;                /* Mount time */
94         __u32   s_wtime;                /* Write time */
95         __u16   s_mnt_count;            /* Mount count */
96         __s16   s_max_mnt_count;        /* Maximal mount count */
97         __u16   s_magic;                /* Magic signature */
98         __u16   s_state;                /* File system state */
99         __u16   s_errors;               /* Behaviour when detecting errors */
100         __u16   s_minor_rev_level;      /* minor revision level */
101         __u32   s_lastcheck;            /* time of last check */
102         __u32   s_checkinterval;        /* max. time between checks */
103         __u32   s_creator_os;           /* OS */
104         __u32   s_rev_level;            /* Revision level */
105         __u16   s_def_resuid;           /* Default uid for reserved blocks */
106         __u16   s_def_resgid;           /* Default gid for reserved blocks */
107         /*
108          * These fields are for EXT2_DYNAMIC_REV superblocks only.
109          *
110          * Note: the difference between the compatible feature set and
111          * the incompatible feature set is that if there is a bit set
112          * in the incompatible feature set that the kernel doesn't
113          * know about, it should refuse to mount the filesystem.
114          * 
115          * e2fsck's requirements are more strict; if it doesn't know
116          * about a feature in either the compatible or incompatible
117          * feature set, it must abort and not try to meddle with
118          * things it doesn't understand...
119          */
120         __u32   s_first_ino;            /* First non-reserved inode */
121         __u16   s_inode_size;           /* size of inode structure */
122         __u16   s_block_group_nr;       /* block group # of this superblock */
123         __u32   s_feature_compat;       /* compatible feature set */
124         __u32   s_feature_incompat;     /* incompatible feature set */
125         __u32   s_feature_ro_compat;    /* readonly-compatible feature set */
126         __u8    s_uuid[16];             /* 128-bit uuid for volume */
127         char    s_volume_name[16];      /* volume name */
128         char    s_last_mounted[64];     /* directory where last mounted */
129         __u32   s_algorithm_usage_bitmap; /* For compression */
130         /*
131          * Performance hints.  Directory preallocation should only
132          * happen if the EXT2_COMPAT_PREALLOC flag is on.
133          */
134         __u8    s_prealloc_blocks;      /* Nr of blocks to try to preallocate*/
135         __u8    s_prealloc_dir_blocks;  /* Nr to preallocate for dirs */
136         __u16   s_padding1;
137         __u32   s_reserved[204];        /* Padding to the end of the block */
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
169 struct dentry *obdfs_lookup(struct inode * dir, struct dentry *dentry);
170 int obdfs_create (struct inode * dir, struct dentry * dentry, int mode);
171 int obdfs_mkdir(struct inode *dir, struct dentry *dentry, int mode);
172 int obdfs_rmdir(struct inode *dir, struct dentry *dentry);
173 int obdfs_unlink(struct inode *dir, struct dentry *dentry);
174 int obdfs_mknod(struct inode *dir, struct dentry *dentry, int mode, int rdev);
175 int obdfs_symlink(struct inode *dir, struct dentry *dentry,
176                   const char *symname);
177 int obdfs_link(struct dentry *old_dentry, struct inode *dir,
178                struct dentry *dentry);
179 int obdfs_rename(struct inode *old_dir, struct dentry *old_dentry,
180                  struct inode *new_dir, struct dentry *new_dentry);
181
182 /* rw.c */
183 int obdfs_do_writepage(struct page *, int sync);
184 int obdfs_init_pgrqcache(void);
185 void obdfs_cleanup_pgrqcache(void);
186 inline void obdfs_pgrq_del(struct obdfs_pgrq *pgrq);
187 int obdfs_readpage(struct file *file, struct page *page);
188 int obdfs_prepare_write(struct file *file, struct page *page, unsigned from, unsigned to);
189 int obdfs_commit_write(struct file *file, struct page *page, unsigned from, unsigned to);
190 int obdfs_writepage(struct page *page);
191 struct page *obdfs_getpage(struct inode *inode, unsigned long offset,
192                            int create, int locked);
193 int obdfs_write_one_page(struct file *file, struct page *page,
194                          unsigned long offset, unsigned long bytes,
195                          const char * buf);
196 int obdfs_do_vec_wr(struct inode **inodes, obd_count num_io, obd_count num_oa,
197                     struct obdo **obdos, obd_count *oa_bufs,
198                     struct page **pages, char **bufs, obd_size *counts,
199                     obd_off *offsets, obd_flag *flags);
200 void obdfs_truncate(struct inode *inode);
201
202 /* super.c */
203 extern long obdfs_cache_count;
204 extern long obdfs_mutex_start;
205
206 /* symlink.c */
207 extern struct inode_operations obdfs_fast_symlink_inode_operations;
208 extern struct inode_operations obdfs_symlink_inode_operations;
209
210 /* sysctl.c */
211 void obdfs_sysctl_init(void);
212 void obdfs_sysctl_clean(void);
213
214
215 static inline struct obdfs_inode_info *obdfs_i2info(struct inode *inode)
216 {
217         return (struct obdfs_inode_info *)&(inode->u.generic_ip);
218 }
219
220 static inline struct obdfs_sb_info *obdfs_i2sbi(struct inode *inode)
221 {
222         return (struct obdfs_sb_info *) &(inode->i_sb->u.generic_sbp);
223 }
224
225 static inline struct list_head *obdfs_iplist(struct inode *inode) 
226 {
227         struct obdfs_inode_info *info = obdfs_i2info(inode);
228
229         return &info->oi_pages;
230 }
231
232 static inline struct list_head *obdfs_islist(struct inode *inode) 
233 {
234         struct obdfs_inode_info *info = obdfs_i2info(inode);
235
236         return &info->oi_inodes;
237 }
238
239 static inline struct list_head *obdfs_slist(struct inode *inode) 
240 {
241         struct obdfs_sb_info *sbi = obdfs_i2sbi(inode);
242
243         return &sbi->osi_inodes;
244 }
245
246 #define obd_down(mutex) {                                               \
247         /* CDEBUG(D_INFO, "get lock\n"); */                             \
248         obdfs_mutex_start = jiffies;                                    \
249         down(mutex);                                                    \
250         if (jiffies - obdfs_mutex_start)                                \
251                 CDEBUG(D_CACHE, "waited on mutex %ld jiffies\n",        \
252                        jiffies - obdfs_mutex_start);                    \
253 }
254
255 #define obd_up(mutex) {                                                 \
256         up(mutex);                                                      \
257         if (jiffies - obdfs_mutex_start > 1)                            \
258                 CDEBUG(D_CACHE, "held mutex for %ld jiffies\n",         \
259                        jiffies - obdfs_mutex_start);                    \
260         /* CDEBUG(D_INFO, "free lock\n"); */                            \
261 }
262
263 /* We track if a page has been added to the OBD page cache by stting a
264  * flag on the page.  We have chosen a bit that will hopefully not be
265  * used for a while.
266  */
267 #define PG_obdcache 29
268 #define OBDAddCachePage(page)   test_and_set_bit(PG_obdcache, &(page)->flags)
269 #define OBDClearCachePage(page) clear_bit(PG_obdcache, &(page)->flags)
270
271 static inline void obdfs_print_plist(struct inode *inode) 
272 {
273         struct list_head *page_list = obdfs_iplist(inode);
274         struct list_head *tmp;
275
276         CDEBUG(D_INFO, "inode %ld: page", inode->i_ino);
277         /* obd_down(&obdfs_i2sbi(inode)->osi_list_mutex); */
278         if (list_empty(page_list)) {
279                 CDEBUG(D_INFO, " list empty\n");
280                 obd_up(&obdfs_i2sbi(inode)->osi_list_mutex);
281                 return;
282         }
283
284         tmp = page_list;
285         while ( (tmp = tmp->next) != page_list) {
286                 struct obdfs_pgrq *pgrq;
287                 pgrq = list_entry(tmp, struct obdfs_pgrq, rq_plist);
288                 CDEBUG(D_INFO, " %p", pgrq->rq_page);
289         }
290         CDEBUG(D_INFO, "\n");
291         /* obd_up(&obdfs_i2sbi(inode)->osi_list_mutex); */
292 }
293
294 static inline int obdfs_has_inline(struct inode *inode)
295 {
296         return (obdfs_i2info(inode)->oi_flags & OBD_FL_INLINEDATA);
297 }
298
299 static void inline obdfs_from_inode(struct obdo *oa, struct inode *inode)
300 {
301         struct obdfs_inode_info *oinfo = obdfs_i2info(inode);
302
303         CDEBUG(D_INFO, "src inode %ld, dst obdo %ld valid 0x%08x\n",
304                inode->i_ino, (long)oa->o_id, oa->o_valid);
305         obdo_from_inode(oa, inode);
306         if (obdfs_has_inline(inode)) {
307                 CDEBUG(D_INODE, "copying inline data from inode to obdo\n");
308                 memcpy(oa->o_inline, oinfo->oi_inline, OBD_INLINESZ);
309                 oa->o_obdflags |= OBD_FL_INLINEDATA;
310                 oa->o_valid |= OBD_MD_FLINLINE;
311         }
312 } /* obdfs_from_inode */
313
314 static void inline obdfs_to_inode(struct inode *inode, struct obdo *oa)
315 {
316         struct obdfs_inode_info *oinfo = obdfs_i2info(inode);
317
318         CDEBUG(D_INFO, "src obdo %ld valid 0x%08x, dst inode %ld\n",
319                (long)oa->o_id, oa->o_valid, inode->i_ino);
320
321         obdo_to_inode(inode, oa);
322
323         if (obdo_has_inline(oa)) {
324                 CDEBUG(D_INODE, "copying inline data from obdo to inode\n");
325                 memcpy(oinfo->oi_inline, oa->o_inline, OBD_INLINESZ);
326                 oinfo->oi_flags |= OBD_FL_INLINEDATA;
327         }
328 } /* obdfs_to_inode */
329
330 #define NOLOCK 0
331 #define LOCKED 1
332
333 #ifdef OPS
334 #warning "*** WARNING redefining OPS"
335 #else
336 #define OPS(sb,op) ((struct obdfs_sb_info *)(& ## sb ## ->u.generic_sbp))->osi_ops->o_ ## op
337 #define IOPS(inode,op) ((struct obdfs_sb_info *)(& ## inode->i_sb ## ->u.generic_sbp))->osi_ops->o_ ## op
338 #endif
339
340 #ifdef ID
341 #warning "*** WARNING redefining ID"
342 #else
343 #define ID(sb) (&((struct obdfs_sb_info *)( & ## sb ## ->u.generic_sbp))->osi_conn)
344 #define IID(inode) (&((struct obdfs_sb_info *)( & ## inode->i_sb ## ->u.generic_sbp))->osi_conn)
345 #endif
346
347 #define OBDFS_SUPER_MAGIC 0x4711
348
349 #endif
350