Whamcloud - gitweb
the last two weeks' work
[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_UNUSED1     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 #define MAX_DEVICES 128
91 struct obd_conn_info {
92         unsigned int conn_id;
93         unsigned long conn_ino;
94         unsigned long conn_blocksize;
95         unsigned char conn_blocksize_bits;
96 };
97
98 struct obd_device {
99         int refcnt;
100         struct super_block * sb;
101         unsigned int last_id;
102         unsigned long prealloc_quota;
103         struct list_head clients;
104 };
105
106 struct obd_client {
107         struct list_head cli_chain;
108         kdev_t minor;
109         unsigned int cli_id;
110         unsigned long cli_prealloc_quota;
111         struct list_head cli_prealloc_inodes;
112 };
113
114 struct obd_prealloc_inode {
115         struct list_head obd_prealloc_chain;
116         unsigned long inode;
117 };
118
119 /*
120  * ioctl commands
121  */
122 struct oic_prealloc_s {
123         unsigned long cli_id;
124         unsigned long alloc; /* user sets it to the number of inodes requesting
125                      * to be preallocated.  kernel sets it to the actual number
126                      * of succesfully preallocated inodes */
127         long inodes[32]; /* actual inode numbers */
128 };
129 struct oic_attr_s {
130         unsigned int conn_id;
131         unsigned long inode;
132
133         struct iattr iattr;
134 };
135 struct oic_rw_s {
136         unsigned int conn_id;
137         unsigned long inode;
138         char * buf;
139         unsigned long count;
140         loff_t offset;
141 };
142
143 #define OBD_IOC_CREATE                 _IOR ('f',  3, long)
144 #define OBD_IOC_SETUP                  _IOW ('f',  4, long)
145 #define OBD_IOC_SYNC                   _IOR ('f',  5, long)
146 #define OBD_IOC_DESTROY                _IOW ('f',  6, long)
147 #define OBD_IOC_PREALLOCATE            _IOWR('f',  7, long)
148 #define OBD_IOC_DEC_USE_COUNT          _IO  ('f',  8      )
149 #define OBD_IOC_SETATTR                _IOW ('f',  9, long)
150 #define OBD_IOC_GETATTR                _IOR ('f', 10, long)
151 #define OBD_IOC_READ                   _IOWR('f', 11, long)
152 #define OBD_IOC_WRITE                  _IOWR('f', 12, long)
153 #define OBD_IOC_CONNECT                _IOR ('f', 13, long)
154 #define OBD_IOC_DISCONNECT             _IOW ('f', 14, long)
155 #define OBD_IOC_STATFS                 _IOWR('f', 15, long)
156 #define OBD_IOC_DEC_FS_USE_COUNT       _IO  ('f', 16      )
157
158 /* balloc.c */
159 int ext2_new_block (const struct inode * inode, unsigned long goal,
160                    u32 * prealloc_count, u32 * prealloc_block, int * err);
161 void ext2_free_blocks (const struct inode * inode, unsigned long block,
162                       unsigned long count);
163 unsigned long ext2_count_free_blocks (struct super_block * sb);
164 int ext2_group_sparse(int group);
165 struct ext2_group_desc * ext2_get_group_desc(struct super_block * sb,
166                                              unsigned int block_group,
167                                              struct buffer_head ** bh);
168
169
170 /* bitmap.c */
171 unsigned long ext2_count_free(struct buffer_head * map, unsigned int numchars);
172
173 /* fsync.c */
174 extern int obd_sync_file(struct file * file, struct dentry *dentry);
175
176 /* ialloc.c */
177 extern void ext2_free_inode (struct inode * inode);
178 extern struct inode * ext2_new_inode (const struct inode * dir, int mode,
179                                      int * err);
180 extern unsigned long ext2_count_free_inodes (struct super_block * sb);
181 extern void ext2_check_inodes_bitmap (struct super_block * sb);
182 extern int load_inode_bitmap (struct super_block * sb,
183                               unsigned int block_group);
184
185 /* inode.c */
186 void obd_read_inode (struct inode * inode);
187 void obd_write_inode (struct inode * inode);
188 void obd_put_inode (struct inode * inode);
189 void obd_delete_inode (struct inode * inode);
190 void obd_discard_prealloc_blocks (struct inode * inode);
191 int obd_sync_inode (struct inode *inode);
192 struct buffer_head * obd_bread (struct inode * inode, int block, 
193                                 int create, int *err);
194 struct buffer_head * obd_getblk (struct inode * inode, long block,
195                                  int create, int * err);
196
197 /* interface.c */
198 extern int obd_create (struct super_block * sb, int inode_hint, int * err);
199 extern void obd_unlink (struct inode * inode);
200 extern struct obd_client * obd_client(int cli_id);
201 extern void obd_cleanup_client (struct obd_device * obddev,
202                                 struct obd_client * cli);
203 void obd_cleanup_device(int dev);
204 long obd_preallocate_inodes(unsigned int conn_id,
205                             int req, long inodes[32], int * err);
206 long obd_preallocate_quota(struct super_block * sb, struct obd_client * cli,
207                            unsigned long req, int * err);
208 int obd_connect (int minor, struct obd_conn_info * conninfo);
209 int obd_disconnect (unsigned int conn_id);
210 int obd_setattr(unsigned int conn_id, unsigned long ino, struct iattr * iattr);
211 int obd_getattr(unsigned int conn_id, unsigned long ino, struct iattr * iattr);
212 int obd_destroy(unsigned int conn_id, unsigned long ino);
213 int obd_statfs(unsigned int conn_id, struct statfs * statfs);
214 unsigned long obd_read(unsigned int conn_id, unsigned long ino, char * buf,
215                        unsigned long count, loff_t offset, int * err);
216 unsigned long obd_write (unsigned int conn_id, unsigned long ino, char * buf,
217                          unsigned long count, loff_t offset, int * err);
218
219 /* ioctl.c */
220 int obd_ioctl (struct inode * inode, struct file * filp, unsigned int cmd,
221                unsigned long arg);
222
223 /* super.c */
224 #define ext2_warning obd_warning
225 #undef ext2_error
226 #define ext2_error obd_warning
227 #define ext2_panic obd_warning
228
229 #ifdef EXT2FS_DEBUG
230 #  undef ext2_debug
231 #  define ext2_debug(format, a...) CDEBUG(D_EXT2, format, ## a)
232 #endif
233
234 #define obd_error obd_warning
235 #define obd_panic obd_warning
236 #define obd_warning(sb, func, format, a...) CDEBUG(D_WARNING, format, ## a)
237
238 int obd_remount (struct super_block * sb, int * flags, char * data);
239 struct super_block * ext2_read_super (struct super_block * sb, void * data,
240                                       int silent);
241
242 /* sysctl.c */
243 extern void obd_sysctl_init (void);
244 extern void obd_sysctl_clean (void);
245
246 /* truncate.c */
247 void obd_truncate (struct inode * inode);
248
249 /* operations */
250 /* dir.c */
251 extern struct inode_operations ext2_dir_inode_operations;
252
253 /* file.c */
254 extern struct file_operations ext2_file_operations;
255 extern struct inode_operations ext2_file_inode_operations;
256
257 /* super.c */
258 extern struct super_operations ext2_sops;
259
260 #endif /* __LINUX_SIM_OBD_H */