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>
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 */
26 struct list_head obdfs_super_list; /* list of all OBDFS superblocks */
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) & \
35 #define EXT2_NAME_LEN 255
37 struct ext2_dir_entry_2 {
38 __u32 inode; /* Inode number */
39 __u16 rec_len; /* Directory entry length */
40 __u8 name_len; /* Name length */
42 char name[EXT2_NAME_LEN]; /* File name */
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;
52 extern struct file_operations obdfs_file_operations;
53 extern struct inode_operations obdfs_file_inode_operations;
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);
64 * Structure of the super block
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 */
95 * These fields are for EXT2_DYNAMIC_REV superblocks only.
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.
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...
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 */
118 * Performance hints. Directory preallocation should only
119 * happen if the EXT2_COMPAT_PREALLOC flag is on.
121 __u8 s_prealloc_blocks; /* Nr of blocks to try to preallocate*/
122 __u8 s_prealloc_dir_blocks; /* Nr to preallocate for dirs */
124 __u32 s_reserved[204]; /* Padding to the end of the block */
128 #define EXT2_SB(sb) (&((sb)->u.ext2_sb))
130 * Maximal count of links to a file
132 #define EXT2_LINK_MAX 32000
134 * Ext2 directory file types. Only the low 3 bits are used. The
135 * other bits are reserved for now.
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
146 #define EXT2_FT_MAX 8
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) )
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,
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);
177 extern long obdfs_cache_count;
178 extern long obdfs_mutex_start;
181 extern struct inode_operations obdfs_fast_symlink_inode_operations;
182 extern struct inode_operations obdfs_symlink_inode_operations;
185 void obdfs_sysctl_init(void);
186 void obdfs_sysctl_clean(void);
188 static inline struct obdfs_sb_info *obdfs_i2sbi(struct inode *inode)
190 return (struct obdfs_sb_info *) &(inode->i_sb->u.generic_sbp);
193 static inline struct list_head *obdfs_iplist(struct inode *inode)
195 struct obdfs_inode_info *info = obdfs_i2info(inode);
197 return &info->oi_pages;
200 static inline struct list_head *obdfs_islist(struct inode *inode)
202 struct obdfs_inode_info *info = obdfs_i2info(inode);
204 return &info->oi_inodes;
207 static inline struct list_head *obdfs_slist(struct inode *inode)
209 struct obdfs_sb_info *sbi = obdfs_i2sbi(inode);
211 return &sbi->osi_inodes;
214 static void inline obdfs_set_size (struct inode *inode, obd_size size)
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 */
225 #define obd_down(mutex) { \
226 /* CDEBUG(D_INFO, "get lock\n"); */ \
227 obdfs_mutex_start = jiffies; \
229 if (jiffies - obdfs_mutex_start) \
230 CDEBUG(D_CACHE, "waited on mutex %ld jiffies\n", \
231 jiffies - obdfs_mutex_start); \
234 #define obd_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"); */ \
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
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)
250 static inline void obdfs_print_plist(struct inode *inode)
252 struct list_head *page_list = obdfs_iplist(inode);
253 struct list_head *tmp;
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);
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);
269 CDEBUG(D_INFO, "\n");
270 /* obd_up(&obdfs_i2sbi(inode)->osi_list_mutex); */
272 #include <linux/obdo.h>