1 #ifndef __LINUX_SIM_OBD_H
2 #define __LINUX_SIM_OBD_H
5 #include <linux/ext2_fs.h>
6 #include <linux/malloc.h>
7 #include <linux/vmalloc.h>
14 /* global variables */
15 extern int obd_debug_level;
16 extern int obd_print_entry;
19 #define D_PSDEV 1 /* debug information from psdev.c */
24 #define D_WARNING 32 /* misc warnings */
25 #define D_EXT2 64 /* anything from ext2_debug */
26 #define D_MALLOC 128 /* print malloc, free information */
27 #define D_CACHE 256 /* cache-related items */
28 #define D_INFO 512 /* general information, especially from interface.c */
29 #define D_IOCTL 1024 /* ioctl related information */
30 #define D_BLOCKS 2048 /* ext2 block allocation */
33 #define CDEBUG(mask, format, a...) \
35 if (obd_debug_level & mask) { \
36 printk("(%s,l. %d): ", __FUNCTION__, __LINE__); \
37 printk(format, ## a); } \
41 if (obd_print_entry) \
42 printk("Process %d entered %s\n", current->pid, __FUNCTION__)
45 if (obd_print_entry) \
46 printk("Process %d leaving %s\n", current->pid, __FUNCTION__)
48 #else /* SIM_OBD_DEBUG */
54 #endif /* SIM_OBD_DEBUG */
58 #define OBD_ALLOC(ptr, cast, size) \
61 ptr = (cast)kmalloc((unsigned long) size, GFP_KERNEL); \
62 CDEBUG(D_MALLOC, "kmalloced: %x at %x.\n", \
63 (int) size, (int) ptr); \
65 ptr = (cast)vmalloc((unsigned long) size); \
66 CDEBUG(D_MALLOC, "vmalloced: %x at %x.\n", \
67 (int) size, (int) ptr); \
70 printk("kernel malloc returns 0 at %s:%d\n", \
71 __FILE__, __LINE__); \
73 memset(ptr, 0, size); \
76 #define OBD_FREE(ptr,size) \
79 kfree_s((ptr), (size)); \
80 CDEBUG(D_MALLOC, "kfreed: %x at %x.\n", \
81 (int) size, (int) ptr); \
84 CDEBUG(D_MALLOC, "vfreed: %x at %x.\n", \
85 (int) size, (int) ptr); \
92 #define MAX_OBD_DEVICES 2
93 struct obd_conn_info {
94 unsigned int conn_id; /* handle */
95 unsigned long conn_ino; /* root inode number */
96 unsigned long conn_blocksize;
97 unsigned char conn_blocksize_bits;
102 struct super_block * sb;
103 unsigned int last_id;
104 unsigned long prealloc_quota;
105 struct list_head clients;
109 struct list_head cli_chain;
112 unsigned long cli_prealloc_quota;
113 struct list_head cli_prealloc_inodes;
116 struct obd_prealloc_inode {
117 struct list_head obd_prealloc_chain;
124 struct oic_prealloc_s {
125 unsigned long cli_id;
126 unsigned long alloc; /* user sets it to the number of inodes requesting
127 * to be preallocated. kernel sets it to the actual number
128 * of succesfully preallocated inodes */
129 long inodes[32]; /* actual inode numbers */
132 unsigned int conn_id;
138 unsigned int conn_id;
145 #define OBD_IOC_CREATE _IOR ('f', 3, long)
146 #define OBD_IOC_SETUP_SUPER _IOW ('f', 4, long)
147 #define OBD_IOC_CLEANUP_SUPER _IO ('f', 5 )
148 #define OBD_IOC_DESTROY _IOW ('f', 6, long)
149 #define OBD_IOC_PREALLOCATE _IOWR('f', 7, long)
150 #define OBD_IOC_DEC_USE_COUNT _IO ('f', 8 )
151 #define OBD_IOC_SETATTR _IOW ('f', 9, long)
152 #define OBD_IOC_GETATTR _IOR ('f', 10, long)
153 #define OBD_IOC_READ _IOWR('f', 11, long)
154 #define OBD_IOC_WRITE _IOWR('f', 12, long)
155 #define OBD_IOC_CONNECT _IOR ('f', 13, long)
156 #define OBD_IOC_DISCONNECT _IOW ('f', 14, long)
157 #define OBD_IOC_STATFS _IOWR('f', 15, long)
158 #define OBD_IOC_SYNC _IOR ('f', 16, long)
162 #define OBD_IOC_DEC_FS_USE_COUNT _IO ('f', 32 )
165 int ext2_new_block (const struct inode * inode, unsigned long goal,
166 u32 * prealloc_count, u32 * prealloc_block, int * err);
167 void ext2_free_blocks (const struct inode * inode, unsigned long block,
168 unsigned long count);
169 unsigned long ext2_count_free_blocks (struct super_block * sb);
170 int ext2_group_sparse(int group);
171 struct ext2_group_desc * ext2_get_group_desc(struct super_block * sb,
172 unsigned int block_group,
173 struct buffer_head ** bh);
177 unsigned long ext2_count_free(struct buffer_head * map, unsigned int numchars);
180 extern int obd_sync_file(struct file * file, struct dentry *dentry);
183 extern void ext2_free_inode (struct inode * inode);
184 extern struct inode * ext2_new_inode (const struct inode * dir, int mode,
186 extern unsigned long ext2_count_free_inodes (struct super_block * sb);
187 extern void ext2_check_inodes_bitmap (struct super_block * sb);
188 extern int load_inode_bitmap (struct super_block * sb,
189 unsigned int block_group);
192 void obd_read_inode (struct inode * inode);
193 void obd_write_inode (struct inode * inode);
194 void obd_put_inode (struct inode * inode);
195 void obd_delete_inode (struct inode * inode);
196 void obd_discard_prealloc_blocks (struct inode * inode);
197 int obd_sync_inode (struct inode *inode);
198 struct buffer_head * obd_bread (struct inode * inode, int block,
199 int create, int *err);
200 struct buffer_head * obd_getblk (struct inode * inode, long block,
201 int create, int * err);
204 void obd_cleanup_device(int dev);
205 extern int obd_create (struct super_block * sb, int inode_hint, int * err);
206 extern void obd_unlink (struct inode * inode);
207 extern struct obd_client * obd_client(int cli_id);
208 extern void obd_cleanup_client (struct obd_device * obddev,
209 struct obd_client * cli);
210 void obd_cleanup_device(int dev);
211 int obd_cleanup_super(struct obd_device * obddev);
212 int obd_setup_super(struct obd_device * obddev, int sbdev);
213 long obd_preallocate_inodes(unsigned int conn_id,
214 int req, long inodes[32], int * err);
215 long obd_preallocate_quota(struct super_block * sb, struct obd_client * cli,
216 unsigned long req, int * err);
217 int obd_connect (int minor, struct obd_conn_info * conninfo);
218 int obd_disconnect (unsigned int conn_id);
219 int obd_setattr(unsigned int conn_id, unsigned long ino, struct iattr * iattr);
220 int obd_getattr(unsigned int conn_id, unsigned long ino, struct iattr * iattr);
221 int obd_destroy(unsigned int conn_id, unsigned long ino);
222 int obd_statfs(unsigned int conn_id, struct statfs * statfs);
223 unsigned long obd_read(unsigned int conn_id, unsigned long ino, char * buf,
224 unsigned long count, loff_t offset, int * err);
225 unsigned long obd_write (unsigned int conn_id, unsigned long ino, char * buf,
226 unsigned long count, loff_t offset, int * err);
229 int obd_ioctl (struct inode * inode, struct file * filp, unsigned int cmd,
233 #define ext2_warning obd_warning
235 #define ext2_error obd_warning
236 #define ext2_panic obd_warning
239 # define ext2_debug(format, a...) CDEBUG(D_EXT2, format, ## a)
242 #define obd_error obd_warning
243 #define obd_panic obd_warning
244 #define obd_warning(sb, func, format, a...) CDEBUG(D_WARNING, format, ## a)
246 int obd_remount (struct super_block * sb, int * flags, char * data);
247 struct super_block * ext2_read_super (struct super_block * sb, void * data,
251 extern void obd_sysctl_init (void);
252 extern void obd_sysctl_clean (void);
255 void obd_truncate (struct inode * inode);
259 extern struct inode_operations ext2_dir_inode_operations;
262 extern struct file_operations ext2_file_operations;
263 extern struct inode_operations ext2_file_inode_operations;
266 extern struct super_operations ext2_sops;
267 #endif /* __LINUX_SIM_OBD_H */