1 /* object based disk file system
3 * This code is issued under the GNU General Public License.
4 * See the file COPYING in this distribution
6 * Copyright (C), 1999, Stelias Computing Inc
14 #include <linux/obd_class.h>
15 #include <linux/obdo.h>
16 #include <linux/list.h>
18 #define LL_SUPER_MAGIC 0x0BD00BD0;
20 struct ll_inode_info {
22 struct list_head lli_inodes;
23 struct list_head lli_pages;
24 char lli_inline[OBD_INLINESZ];
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;
41 static inline struct ll_inode_info *ll_i2info(struct inode *inode)
43 return (struct ll_inode_info *)&(inode->u.generic_ip);
46 static inline int ll_has_inline(struct inode *inode)
48 return (ll_i2info(inode)->lli_flags & OBD_FL_INLINEDATA);
51 static void inline ll_from_inode(struct obdo *oa, struct inode *inode)
53 struct ll_inode_info *oinfo = ll_i2info(inode);
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",
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;
72 static void inline ll_to_inode(struct inode *inode, struct obdo *oa)
74 struct ll_inode_info *oinfo = ll_i2info(inode);
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);
79 obdo_to_inode(inode, oa);
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);
86 "copying device %x from obdo to inode\n", rdev);
87 init_special_inode(inode, inode->i_mode, rdev);
89 CDEBUG(D_INFO, "copying inline from obdo to inode\n");
90 memcpy(oinfo->lli_inline, oa->o_inline, OBD_INLINESZ);
92 oinfo->lli_flags |= OBD_FL_INLINEDATA;
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 */
106 extern struct list_head ll_super_list; /* list of all LL superblocks */
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) & \
115 #define EXT2_NAME_LEN 255
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;
124 extern struct file_operations ll_file_operations;
125 extern struct inode_operations ll_file_inode_operations;
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);
136 * Structure of the super block
140 #define EXT2_SB(sb) (&((sb)->u.ext2_sb))
142 * Maximal count of links to a file
144 #define EXT2_LINK_MAX 32000
146 * Ext2 directory file types. Only the low 3 bits are used. The
147 * other bits are reserved for now.
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
158 #define EXT2_FT_MAX 8
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) )
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,
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);
189 extern long ll_cache_count;
190 extern long ll_mutex_start;
193 extern struct inode_operations ll_fast_symlink_inode_operations;
194 extern struct inode_operations ll_symlink_inode_operations;
197 void ll_sysctl_init(void);
198 void ll_sysctl_clean(void);
200 static inline struct ll_sb_info *ll_i2sbi(struct inode *inode)
202 return (struct ll_sb_info *) &(inode->i_sb->u.generic_sbp);
205 static inline struct list_head *ll_iplist(struct inode *inode)
207 struct ll_inode_info *info = ll_i2info(inode);
209 return &info->lli_pages;
212 static inline struct list_head *ll_islist(struct inode *inode)
214 struct ll_inode_info *info = ll_i2info(inode);
216 return &info->lli_inodes;
219 static inline struct list_head *ll_slist(struct inode *inode)
221 struct ll_sb_info *sbi = ll_i2sbi(inode);
223 return &sbi->ll_inodes;
226 static void inline ll_set_size (struct inode *inode, obd_size size)
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;
235 #define obd_down(mutex) { \
236 /* CDEBUG(D_INFO, "get lock\n"); */ \
237 ll_mutex_start = jiffies; \
239 if (jiffies - ll_mutex_start) \
240 CDEBUG(D_CACHE, "waited on mutex %ld jiffies\n", \
241 jiffies - ll_mutex_start); \
244 #define obd_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"); */ \
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
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)
260 static inline void ll_print_plist(struct inode *inode)
262 struct list_head *page_list = ll_iplist(inode);
263 struct list_head *tmp;
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);
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);
279 CDEBUG(D_INFO, "\n");
280 /* obd_up(&ll_i2sbi(inode)->ll_list_mutex); */
282 #include <linux/obdo.h>