Whamcloud - gitweb
fixes for deliverables.
[fs/lustre-release.git] / lustre / include / linux / sim_obd.h
1 #ifndef __LINUX_SIM_OBD_H
2 #define __LINUX_SIM_OBD_H
3
4 #include <linux/fs.h>
5 #include <linux/ext2_fs.h>
6 #include <linux/malloc.h>
7 #include <linux/vmalloc.h>
8
9 #define SIM_OBD_DEBUG
10
11 /*
12  * Debug code
13  */
14 /* global variables */
15 extern int obd_debug_level;
16 extern int obd_print_entry;
17
18 /* debugging masks */
19 #define D_PSDEV       1 /* debug information from psdev.c */
20 #define D_INODE       2
21 #define D_UNUSED2     4
22 #define D_UNUSED3     8
23 #define D_UNUSED4    16
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 */
31  
32 #ifdef SIM_OBD_DEBUG
33 #define CDEBUG(mask, format, a...)                                      \
34         do {                                                            \
35         if (obd_debug_level & mask) {                                   \
36                 printk("(%s,l. %d): ",  __FUNCTION__, __LINE__);        \
37                 printk(format, ## a); }                                 \
38         } while (0)
39
40 #define ENTRY                                                                 \
41         if (obd_print_entry)                                                  \
42                 printk("Process %d entered %s\n", current->pid, __FUNCTION__)
43
44 #define EXIT                                                                  \
45         if (obd_print_entry)                                                  \
46                 printk("Process %d leaving %s\n", current->pid, __FUNCTION__)
47
48 #else /* SIM_OBD_DEBUG */
49
50 #       define CDEBUG ;
51 #       define ENTRY ;
52 #       define EXIT ;
53
54 #endif /* SIM_OBD_DEBUG */
55
56
57
58 #define OBD_ALLOC(ptr, cast, size)                                      \
59 do {                                                                    \
60         if (size <= 4096) {                                             \
61                 ptr = (cast)kmalloc((unsigned long) size, GFP_KERNEL); \
62                 CDEBUG(D_MALLOC, "kmalloced: %x at %x.\n",              \
63                        (int) size, (int) ptr);                          \
64         } else {                                                        \
65                 ptr = (cast)vmalloc((unsigned long) size);              \
66                 CDEBUG(D_MALLOC, "vmalloced: %x at %x.\n",              \
67                        (int) size, (int) ptr);                          \
68         }                                                               \
69         if (ptr == 0) {                                                 \
70                 printk("kernel malloc returns 0 at %s:%d\n",            \
71                        __FILE__, __LINE__);                             \
72         }                                                               \
73         memset(ptr, 0, size);                                           \
74 } while (0)
75
76 #define OBD_FREE(ptr,size)                              \
77 do {                                                    \
78         if (size <= 4096) {                             \
79                 kfree_s((ptr), (size));                 \
80                 CDEBUG(D_MALLOC, "kfreed: %x at %x.\n", \
81                        (int) size, (int) ptr);          \
82         } else {                                        \
83                 vfree((ptr));                           \
84                 CDEBUG(D_MALLOC, "vfreed: %x at %x.\n", \
85                        (int) size, (int) ptr);          \
86         }                                               \
87 } while (0)
88
89
90
91
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;
98 };
99
100 struct obd_device {
101         int refcnt;
102         struct super_block * sb;
103         unsigned int last_id;
104         unsigned long prealloc_quota;
105         struct list_head clients;
106 };
107
108 struct obd_client {
109         struct list_head cli_chain;
110         kdev_t minor;
111         unsigned int cli_id;
112         unsigned long cli_prealloc_quota;
113         struct list_head cli_prealloc_inodes;
114 };
115
116 struct obd_prealloc_inode {
117         struct list_head obd_prealloc_chain;
118         unsigned long inode;
119 };
120
121 /*
122  * ioctl commands
123  */
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 */
130 };
131 struct oic_attr_s {
132         unsigned int conn_id;
133         unsigned long inode;
134
135         struct iattr iattr;
136 };
137 struct oic_rw_s {
138         unsigned int conn_id;
139         unsigned long inode;
140         char * buf;
141         unsigned long count;
142         loff_t offset;
143 };
144
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)
159
160
161
162 #define OBD_IOC_DEC_FS_USE_COUNT       _IO  ('f', 32      )
163
164 /* balloc.c */
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);
174
175
176 /* bitmap.c */
177 unsigned long ext2_count_free(struct buffer_head * map, unsigned int numchars);
178
179 /* fsync.c */
180 extern int obd_sync_file(struct file * file, struct dentry *dentry);
181
182 /* ialloc.c */
183 extern void ext2_free_inode (struct inode * inode);
184 extern struct inode * ext2_new_inode (const struct inode * dir, int mode,
185                                      int * err);
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);
190
191 /* inode.c */
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);
202
203 /* interface.c */
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);
227
228 /* ioctl.c */
229 int obd_ioctl (struct inode * inode, struct file * filp, unsigned int cmd,
230                unsigned long arg);
231
232 /* super.c */
233 #define ext2_warning obd_warning
234 #undef ext2_error
235 #define ext2_error obd_warning
236 #define ext2_panic obd_warning
237 #ifdef EXT2FS_DEBUG
238 #  undef ext2_debug
239 #  define ext2_debug(format, a...) CDEBUG(D_EXT2, format, ## a)
240 #endif
241
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)
245
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,
248                                       int silent);
249
250 /* sysctl.c */
251 extern void obd_sysctl_init (void);
252 extern void obd_sysctl_clean (void);
253
254 /* truncate.c */
255 void obd_truncate (struct inode * inode);
256
257 /* operations */
258 /* dir.c */
259 extern struct inode_operations ext2_dir_inode_operations;
260
261 /* file.c */
262 extern struct file_operations ext2_file_operations;
263 extern struct inode_operations ext2_file_inode_operations;
264
265 /* super.c */
266 extern struct super_operations ext2_sops;
267 #endif /* __LINUX_SIM_OBD_H */