Whamcloud - gitweb
Numerous changes:
[fs/lustre-release.git] / lustre / include / linux / obdfs.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 _OBDFS_H
13 #define _OBDFS_H
14 #include <linux/obd_class.h>
15 #include <linux/obdo.h>
16 #include <linux/list.h>
17
18
19 /* super.c */ 
20 struct obdfs_pgrq {
21         struct list_head         rq_plist;      /* linked list of req's */
22         unsigned long            rq_jiffies;
23         struct page             *rq_page;       /* page to be written */
24 };
25
26 struct list_head obdfs_super_list;       /* list of all OBDFS superblocks */
27
28
29
30 /* dir.c */
31 #define EXT2_DIR_PAD                    4
32 #define EXT2_DIR_ROUND                  (EXT2_DIR_PAD - 1)
33 #define EXT2_DIR_REC_LEN(name_len)      (((name_len) + 8 + EXT2_DIR_ROUND) & \
34                                          ~EXT2_DIR_ROUND)
35 #define EXT2_NAME_LEN 255
36 #if 0
37 struct ext2_dir_entry_2 {
38         __u32   inode;                  /* Inode number */
39         __u16   rec_len;                /* Directory entry length */
40         __u8    name_len;               /* Name length */
41         __u8    file_type;
42         char    name[EXT2_NAME_LEN];    /* File name */
43 };
44 #endif
45 int obdfs_check_dir_entry (const char * function, struct inode * dir,
46                           struct ext2_dir_entry_2 * de, struct page * page,
47                           unsigned long offset);
48 extern struct file_operations obdfs_dir_operations;
49 extern struct inode_operations obdfs_dir_inode_operations;
50
51 /* file.c */
52 extern struct file_operations obdfs_file_operations;
53 extern struct inode_operations obdfs_file_inode_operations;
54
55 /* flush.c */
56 void obdfs_dequeue_pages(struct inode *inode);
57 int obdfs_flushd_init(void);
58 int obdfs_flushd_cleanup(void);
59 int obdfs_flush_reqs(struct list_head *inode_list, unsigned long check_time);
60 int obdfs_flush_dirty_pages(unsigned long check_time);
61
62 /* namei.c */
63 /*
64  * Structure of the super block
65  */
66
67 #if 0
68 struct ext2_super_block {
69         __u32   s_inodes_count;         /* Inodes count */
70         __u32   s_blocks_count;         /* Blocks count */
71         __u32   s_r_blocks_count;       /* Reserved blocks count */
72         __u32   s_free_blocks_count;    /* Free blocks count */
73         __u32   s_free_inodes_count;    /* Free inodes count */
74         __u32   s_first_data_block;     /* First Data Block */
75         __u32   s_log_block_size;       /* Block size */
76         __s32   s_log_frag_size;        /* Fragment size */
77         __u32   s_blocks_per_group;     /* # Blocks per group */
78         __u32   s_frags_per_group;      /* # Fragments per group */
79         __u32   s_inodes_per_group;     /* # Inodes per group */
80         __u32   s_mtime;                /* Mount time */
81         __u32   s_wtime;                /* Write time */
82         __u16   s_mnt_count;            /* Mount count */
83         __s16   s_max_mnt_count;        /* Maximal mount count */
84         __u16   s_magic;                /* Magic signature */
85         __u16   s_state;                /* File system state */
86         __u16   s_errors;               /* Behaviour when detecting errors */
87         __u16   s_minor_rev_level;      /* minor revision level */
88         __u32   s_lastcheck;            /* time of last check */
89         __u32   s_checkinterval;        /* max. time between checks */
90         __u32   s_creator_os;           /* OS */
91         __u32   s_rev_level;            /* Revision level */
92         __u16   s_def_resuid;           /* Default uid for reserved blocks */
93         __u16   s_def_resgid;           /* Default gid for reserved blocks */
94         /*
95          * These fields are for EXT2_DYNAMIC_REV superblocks only.
96          *
97          * Note: the difference between the compatible feature set and
98          * the incompatible feature set is that if there is a bit set
99          * in the incompatible feature set that the kernel doesn't
100          * know about, it should refuse to mount the filesystem.
101          * 
102          * e2fsck's requirements are more strict; if it doesn't know
103          * about a feature in either the compatible or incompatible
104          * feature set, it must abort and not try to meddle with
105          * things it doesn't understand...
106          */
107         __u32   s_first_ino;            /* First non-reserved inode */
108         __u16   s_inode_size;           /* size of inode structure */
109         __u16   s_block_group_nr;       /* block group # of this superblock */
110         __u32   s_feature_compat;       /* compatible feature set */
111         __u32   s_feature_incompat;     /* incompatible feature set */
112         __u32   s_feature_ro_compat;    /* readonly-compatible feature set */
113         __u8    s_uuid[16];             /* 128-bit uuid for volume */
114         char    s_volume_name[16];      /* volume name */
115         char    s_last_mounted[64];     /* directory where last mounted */
116         __u32   s_algorithm_usage_bitmap; /* For compression */
117         /*
118          * Performance hints.  Directory preallocation should only
119          * happen if the EXT2_COMPAT_PREALLOC flag is on.
120          */
121         __u8    s_prealloc_blocks;      /* Nr of blocks to try to preallocate*/
122         __u8    s_prealloc_dir_blocks;  /* Nr to preallocate for dirs */
123         __u16   s_padding1;
124         __u32   s_reserved[204];        /* Padding to the end of the block */
125 };
126 #endif
127
128 #define EXT2_SB(sb)     (&((sb)->u.ext2_sb))
129 /*
130  * Maximal count of links to a file
131  */
132 #define EXT2_LINK_MAX           32000
133 /*
134  * Ext2 directory file types.  Only the low 3 bits are used.  The
135  * other bits are reserved for now.
136  */
137 #define EXT2_FT_UNKNOWN         0
138 #define EXT2_FT_REG_FILE        1
139 #define EXT2_FT_DIR             2
140 #define EXT2_FT_CHRDEV          3
141 #define EXT2_FT_BLKDEV          4
142 #define EXT2_FT_FIFO            5
143 #define EXT2_FT_SOCK            6
144 #define EXT2_FT_SYMLINK         7
145
146 #define EXT2_FT_MAX             8
147
148 #define EXT2_BTREE_FL                   0x00001000 /* btree format dir */
149 #define EXT2_RESERVED_FL                0x80000000 /* reserved for ext2 lib */
150 #define EXT2_FEATURE_INCOMPAT_FILETYPE          0x0002
151 #define EXT2_HAS_COMPAT_FEATURE(sb,mask)                        \
152         ( EXT2_SB(sb)->s_es->s_feature_compat & cpu_to_le32(mask) )
153 #define EXT2_HAS_INCOMPAT_FEATURE(sb,mask)                      \
154         ( EXT2_SB(sb)->s_es->s_feature_incompat & cpu_to_le32(mask) )
155
156 /* rw.c */
157 int obdfs_do_writepage(struct page *, int sync);
158 int obdfs_init_pgrqcache(void);
159 void obdfs_cleanup_pgrqcache(void);
160 inline void obdfs_pgrq_del(struct obdfs_pgrq *pgrq);
161 int obdfs_readpage(struct file *file, struct page *page);
162 int obdfs_prepare_write(struct file *file, struct page *page, unsigned from, unsigned to);
163 int obdfs_commit_write(struct file *file, struct page *page, unsigned from, unsigned to);
164 int obdfs_writepage(struct page *page);
165 struct page *obdfs_getpage(struct inode *inode, unsigned long offset,
166                            int create, int locked);
167 int obdfs_write_one_page(struct file *file, struct page *page,
168                          unsigned long offset, unsigned long bytes,
169                          const char * buf);
170 int obdfs_do_vec_wr(struct inode **inodes, obd_count num_io, obd_count num_oa,
171                     struct obdo **obdos, obd_count *oa_bufs,
172                     struct page **pages, char **bufs, obd_size *counts,
173                     obd_off *offsets, obd_flag *flags);
174 void obdfs_truncate(struct inode *inode);
175
176 /* super.c */
177 extern long obdfs_cache_count;
178 extern long obdfs_mutex_start;
179
180 /* symlink.c */
181 extern struct inode_operations obdfs_fast_symlink_inode_operations;
182 extern struct inode_operations obdfs_symlink_inode_operations;
183
184 /* sysctl.c */
185 void obdfs_sysctl_init(void);
186 void obdfs_sysctl_clean(void);
187
188 static inline struct obdfs_sb_info *obdfs_i2sbi(struct inode *inode)
189 {
190         return (struct obdfs_sb_info *) &(inode->i_sb->u.generic_sbp);
191 }
192
193 static inline struct list_head *obdfs_iplist(struct inode *inode) 
194 {
195         struct obdfs_inode_info *info = obdfs_i2info(inode);
196
197         return &info->oi_pages;
198 }
199
200 static inline struct list_head *obdfs_islist(struct inode *inode) 
201 {
202         struct obdfs_inode_info *info = obdfs_i2info(inode);
203
204         return &info->oi_inodes;
205 }
206
207 static inline struct list_head *obdfs_slist(struct inode *inode) 
208 {
209         struct obdfs_sb_info *sbi = obdfs_i2sbi(inode);
210
211         return &sbi->osi_inodes;
212 }
213
214 static void inline obdfs_set_size (struct inode *inode, obd_size size)
215 {  
216        inode->i_size = size;
217        inode->i_blocks = (inode->i_size + inode->i_sb->s_blocksize - 1) >>
218                inode->i_sb->s_blocksize_bits;
219        inode->i_bytes = inode->i_size &
220                ((1 << inode->i_sb->s_blocksize_bits) - 1);
221 } /* obdfs_set_size */
222
223
224
225 #define obd_down(mutex) {                                               \
226         /* CDEBUG(D_INFO, "get lock\n"); */                             \
227         obdfs_mutex_start = jiffies;                                    \
228         down(mutex);                                                    \
229         if (jiffies - obdfs_mutex_start)                                \
230                 CDEBUG(D_CACHE, "waited on mutex %ld jiffies\n",        \
231                        jiffies - obdfs_mutex_start);                    \
232 }
233
234 #define obd_up(mutex) {                                                 \
235         up(mutex);                                                      \
236         if (jiffies - obdfs_mutex_start > 1)                            \
237                 CDEBUG(D_CACHE, "held mutex for %ld jiffies\n",         \
238                        jiffies - obdfs_mutex_start);                    \
239         /* CDEBUG(D_INFO, "free lock\n"); */                            \
240 }
241
242 /* We track if a page has been added to the OBD page cache by stting a
243  * flag on the page.  We have chosen a bit that will hopefully not be
244  * used for a while.
245  */
246 #define PG_obdcache 29
247 #define OBDAddCachePage(page)   test_and_set_bit(PG_obdcache, &(page)->flags)
248 #define OBDClearCachePage(page) clear_bit(PG_obdcache, &(page)->flags)
249
250 static inline void obdfs_print_plist(struct inode *inode) 
251 {
252         struct list_head *page_list = obdfs_iplist(inode);
253         struct list_head *tmp;
254
255         CDEBUG(D_INFO, "inode %ld: page", inode->i_ino);
256         /* obd_down(&obdfs_i2sbi(inode)->osi_list_mutex); */
257         if (list_empty(page_list)) {
258                 CDEBUG(D_INFO, " list empty\n");
259                 obd_up(&obdfs_i2sbi(inode)->osi_list_mutex);
260                 return;
261         }
262
263         tmp = page_list;
264         while ( (tmp = tmp->next) != page_list) {
265                 struct obdfs_pgrq *pgrq;
266                 pgrq = list_entry(tmp, struct obdfs_pgrq, rq_plist);
267                 CDEBUG(D_INFO, " %p", pgrq->rq_page);
268         }
269         CDEBUG(D_INFO, "\n");
270         /* obd_up(&obdfs_i2sbi(inode)->osi_list_mutex); */
271 }
272 #include <linux/obdo.h>
273
274 #endif
275