Whamcloud - gitweb
include/linux/obdfs.h: handle block special devices,
[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 struct obdfs_pgrq {
18         struct list_head         rq_plist;      /* linked list of req's */
19         unsigned long            rq_jiffies;
20         struct page             *rq_page;       /* page to be written */
21 };
22
23 struct list_head obdfs_super_list;       /* list of all OBDFS superblocks */
24
25 struct obdfs_sb_info {
26         struct list_head         osi_list;      /* list of supers */
27         struct obd_conn          osi_conn;
28         struct super_block      *osi_super;
29         struct obd_device       *osi_obd;
30         struct obd_ops          *osi_ops;
31         ino_t                    osi_rootino;   /* number of root inode */
32         int                      osi_minor;     /* minor of /dev/obdX */
33         struct list_head         osi_inodes;    /* list of dirty inodes */
34         unsigned long            osi_cache_count;
35         struct semaphore         osi_list_mutex;
36 };
37
38 struct obdfs_inode_info {
39         int              oi_flags;
40         struct list_head oi_inodes;
41         struct list_head oi_pages;
42         char             oi_inline[OBD_INLINESZ];
43 };
44
45 /* dir.c */
46 int obdfs_check_dir_entry (const char * function, struct inode * dir,
47                           struct ext2_dir_entry_2 * de, struct page * page,
48                           unsigned long offset);
49 extern struct file_operations obdfs_dir_operations;
50 extern struct inode_operations obdfs_dir_inode_operations;
51
52 /* file.c */
53 extern struct file_operations obdfs_file_operations;
54 extern struct inode_operations obdfs_file_inode_operations;
55
56 /* flush.c */
57 void obdfs_dequeue_pages(struct inode *inode);
58 int obdfs_flushd_init(void);
59 int obdfs_flushd_cleanup(void);
60 int obdfs_flush_reqs(struct list_head *inode_list, unsigned long check_time);
61 int obdfs_flush_dirty_pages(unsigned long check_time);
62
63 /* namei.c */
64 struct dentry *obdfs_lookup(struct inode * dir, struct dentry *dentry);
65 int obdfs_create (struct inode * dir, struct dentry * dentry, int mode);
66 int obdfs_mkdir(struct inode *dir, struct dentry *dentry, int mode);
67 int obdfs_rmdir(struct inode *dir, struct dentry *dentry);
68 int obdfs_unlink(struct inode *dir, struct dentry *dentry);
69 int obdfs_mknod(struct inode *dir, struct dentry *dentry, int mode, int rdev);
70 int obdfs_symlink(struct inode *dir, struct dentry *dentry,
71                   const char *symname);
72 int obdfs_link(struct dentry *old_dentry, struct inode *dir,
73                struct dentry *dentry);
74 int obdfs_rename(struct inode *old_dir, struct dentry *old_dentry,
75                  struct inode *new_dir, struct dentry *new_dentry);
76
77 /* rw.c */
78 int obdfs_do_writepage(struct inode *, struct page *, int sync);
79 int obdfs_init_pgrqcache(void);
80 void obdfs_cleanup_pgrqcache(void);
81 inline void obdfs_pgrq_del(struct obdfs_pgrq *pgrq);
82 int obdfs_readpage(struct dentry *dentry, struct page *page);
83 int obdfs_writepage(struct dentry *dentry, struct page *page);
84 struct page *obdfs_getpage(struct inode *inode, unsigned long offset,
85                            int create, int locked);
86 int obdfs_write_one_page(struct file *file, struct page *page,
87                          unsigned long offset, unsigned long bytes,
88                          const char * buf);
89 int obdfs_do_vec_wr(struct inode **inodes, obd_count num_io, obd_count num_oa,
90                     struct obdo **obdos, obd_count *oa_bufs,
91                     struct page **pages, char **bufs, obd_size *counts,
92                     obd_off *offsets, obd_flag *flags);
93 void obdfs_truncate(struct inode *inode);
94
95 /* super.c */
96 extern long obdfs_cache_count;
97 extern long obdfs_mutex_start;
98
99 /* symlink.c */
100 extern struct inode_operations obdfs_fast_symlink_inode_operations;
101 extern struct inode_operations obdfs_symlink_inode_operations;
102
103 /* sysctl.c */
104 void obdfs_sysctl_init(void);
105 void obdfs_sysctl_clean(void);
106
107
108 static inline struct obdfs_inode_info *obdfs_i2info(struct inode *inode)
109 {
110         return (struct obdfs_inode_info *)&(inode->u.generic_ip);
111 }
112
113 static inline struct obdfs_sb_info *obdfs_i2sbi(struct inode *inode)
114 {
115         return (struct obdfs_sb_info *) &(inode->i_sb->u.generic_sbp);
116 }
117
118 static inline struct list_head *obdfs_iplist(struct inode *inode) 
119 {
120         struct obdfs_inode_info *info = obdfs_i2info(inode);
121
122         return &info->oi_pages;
123 }
124
125 static inline struct list_head *obdfs_islist(struct inode *inode) 
126 {
127         struct obdfs_inode_info *info = obdfs_i2info(inode);
128
129         return &info->oi_inodes;
130 }
131
132 static inline struct list_head *obdfs_slist(struct inode *inode) 
133 {
134         struct obdfs_sb_info *sbi = obdfs_i2sbi(inode);
135
136         return &sbi->osi_inodes;
137 }
138
139 #define obd_down(mutex) {                                               \
140         /* CDEBUG(D_INFO, "get lock\n"); */                             \
141         obdfs_mutex_start = jiffies;                                    \
142         down(mutex);                                                    \
143         if (jiffies - obdfs_mutex_start)                                \
144                 CDEBUG(D_CACHE, "waited on mutex %ld jiffies\n",        \
145                        jiffies - obdfs_mutex_start);                    \
146 }
147
148 #define obd_up(mutex) {                                                 \
149         up(mutex);                                                      \
150         if (jiffies - obdfs_mutex_start > 1)                            \
151                 CDEBUG(D_CACHE, "held mutex for %ld jiffies\n",         \
152                        jiffies - obdfs_mutex_start);                    \
153         /* CDEBUG(D_INFO, "free lock\n"); */                            \
154 }
155
156 /* We track if a page has been added to the OBD page cache by stting a
157  * flag on the page.  We have chosen a bit that will hopefully not be
158  * used for a while.
159  */
160 #define PG_obdcache 29
161 #define OBDAddCachePage(page)   test_and_set_bit(PG_obdcache, &(page)->flags)
162 #define OBDClearCachePage(page) clear_bit(PG_obdcache, &(page)->flags)
163
164 static inline void obdfs_print_plist(struct inode *inode) 
165 {
166         struct list_head *page_list = obdfs_iplist(inode);
167         struct list_head *tmp;
168
169         CDEBUG(D_INFO, "inode %ld: page", inode->i_ino);
170         /* obd_down(&obdfs_i2sbi(inode)->osi_list_mutex); */
171         if (list_empty(page_list)) {
172                 CDEBUG(D_INFO, " list empty\n");
173                 obd_up(&obdfs_i2sbi(inode)->osi_list_mutex);
174                 return;
175         }
176
177         tmp = page_list;
178         while ( (tmp = tmp->next) != page_list) {
179                 struct obdfs_pgrq *pgrq;
180                 pgrq = list_entry(tmp, struct obdfs_pgrq, rq_plist);
181                 CDEBUG(D_INFO, " %p", pgrq->rq_page);
182         }
183         CDEBUG(D_INFO, "\n");
184         /* obd_up(&obdfs_i2sbi(inode)->osi_list_mutex); */
185 }
186
187 static inline int obdfs_has_inline(struct inode *inode)
188 {
189         return (obdfs_i2info(inode)->oi_flags & OBD_FL_INLINEDATA);
190 }
191
192 static void inline obdfs_from_inode(struct obdo *oa, struct inode *inode)
193 {
194         struct obdfs_inode_info *oinfo = obdfs_i2info(inode);
195
196         CDEBUG(D_INFO, "src inode %ld, dst obdo %ld valid 0x%08x\n",
197                inode->i_ino, (long)oa->o_id, oa->o_valid);
198         obdo_from_inode(oa, inode);
199         if (obdfs_has_inline(inode)) {
200                 CDEBUG(D_INODE, "copying inline data from inode to obdo\n");
201                 memcpy(oa->o_inline, oinfo->oi_inline, OBD_INLINESZ);
202                 oa->o_obdflags |= OBD_FL_INLINEDATA;
203                 oa->o_valid |= OBD_MD_FLINLINE;
204         }
205 } /* obdfs_from_inode */
206
207 static void inline obdfs_to_inode(struct inode *inode, struct obdo *oa)
208 {
209         struct obdfs_inode_info *oinfo = obdfs_i2info(inode);
210
211         CDEBUG(D_INFO, "src obdo %ld valid 0x%08x, dst inode %ld\n",
212                (long)oa->o_id, oa->o_valid, inode->i_ino);
213
214         obdo_to_inode(inode, oa);
215
216         if (obdo_has_inline(oa)) {
217                 CDEBUG(D_INODE, "copying inline data from obdo to inode\n");
218                 memcpy(oinfo->oi_inline, oa->o_inline, OBD_INLINESZ);
219                 oinfo->oi_flags |= OBD_FL_INLINEDATA;
220         }
221 } /* obdfs_to_inode */
222
223 #define NOLOCK 0
224 #define LOCKED 1
225
226 #ifdef OPS
227 #warning "*** WARNING redefining OPS"
228 #else
229 #define OPS(sb,op) ((struct obdfs_sb_info *)(& ## sb ## ->u.generic_sbp))->osi_ops->o_ ## op
230 #define IOPS(inode,op) ((struct obdfs_sb_info *)(& ## inode->i_sb ## ->u.generic_sbp))->osi_ops->o_ ## op
231 #endif
232
233 #ifdef ID
234 #warning "*** WARNING redefining ID"
235 #else
236 #define ID(sb) (&((struct obdfs_sb_info *)( & ## sb ## ->u.generic_sbp))->osi_conn)
237 #define IID(inode) (&((struct obdfs_sb_info *)( & ## inode->i_sb ## ->u.generic_sbp))->osi_conn)
238 #endif
239
240 #define OBDFS_SUPER_MAGIC 0x4711
241
242 #endif
243