Whamcloud - gitweb
87c86b28034593d5ca6f9cf9377e5e133cf66d33
[fs/lustre-release.git] / lustre / include / linux / sym_obd.h
1 #ifndef __LINUX_SYM_OBD_H
2 #define __LINUX_SYM_OBD_H
3
4 #include <linux/fs.h>
5 #include <linux/ext2_fs.h>
6
7 #define SYM_OBD_DEBUG
8
9 /*
10  * Debug code
11  */
12 /* global variables */
13 extern int obd_debug_level;
14 extern int obd_print_entry;
15
16 /* debugging masks */
17 #define D_PSDEV       1 /* debug information from psdev.c */
18 #define D_UNUSED1     2
19 #define D_UNUSED2     4
20 #define D_UNUSED3     8
21 #define D_UNUSED4    16
22 #define D_UNUSED5    32
23 #define D_UNUSED6    64
24 #define D_MALLOC    128 /* print malloc, free information */
25 #define D_CACHE     256 /* cache-related items */
26 #define D_INFO      512 /* general information, especially from interface.c */
27 #define D_IOCTL    1024 /* ioctl related information */
28 #define D_BLOCKS   2048 /* ext2 block allocation */
29  
30 #ifdef SYM_OBD_DEBUG
31 #define CDEBUG(mask, format, a...)                                      \
32         do {                                                            \
33         if (obd_debug_level & mask) {                                   \
34                 printk("(%s,l. %d): ",  __FUNCTION__, __LINE__);        \
35                 printk(format, ## a); }                                 \
36         } while (0);
37
38 #define ENTRY                                                                 \
39         if (obd_print_entry)                                                  \
40                 printk("Process %d entered %s\n", current->pid, __FUNCTION__)
41
42 #define EXIT                                                                  \
43         if (obd_print_entry)                                                  \
44                 printk("Process %d leaving %s\n", current->pid, __FUNCTION__)
45
46 #else /* SYM_OBD_DEBUG */
47
48 #       define CDEBUG(mask, format, a...) ;
49 #       define ENTRY ;
50 #       define EXIT ;
51
52 #endif /* SYM_OBD_DEBUG */
53
54
55
56 #define OBD_ALLOC(ptr, cast, size)                                      \
57 do {                                                                    \
58         if (size <= 4096) {                                             \
59                 ptr = (cast)kmalloc((unsigned long) size, GFP_KERNEL);  \
60                 CDEBUG(D_MALLOC, "kmalloced: %x at %x.\n",              \
61                        (int) size, (int) ptr);                          \
62         } else {                                                        \
63                 ptr = (cast)vmalloc((unsigned long) size);              \
64                 CDEBUG(D_MALLOC, "vmalloced: %x at %x.\n",              \
65                        (int) size, (int) ptr);                          \
66         }                                                               \
67         if (ptr == 0) {                                                 \
68                 printk("kernel malloc returns 0 at %s:%d\n",            \
69                        __FILE__, __LINE__);                             \
70         }                                                               \
71         memset(ptr, 0, size);                                           \
72 } while (0)
73
74 #define OBD_FREE(ptr,size)                              \
75 do {                                                    \
76         if (size <= 4096) {                             \
77                 kfree_s((ptr), (size));                 \
78                 CDEBUG(D_MALLOC, "kfreed: %x at %x.\n", \
79                        (int) size, (int) ptr);          \
80         } else {                                        \
81                 vfree((ptr));                           \
82                 CDEBUG(D_MALLOC, "vfreed: %x at %x.\n", \
83                        (int) size, (int) ptr);          \
84         }                                               \
85 } while (0)
86
87
88 /*
89  * ioctl commands
90  */
91 struct ioc_prealloc {
92         long alloc; /* user sets it to the number of inodes requesting to be
93                      * preallocated.  kernel sets it to the actual number of
94                      * succesfully preallocate inodes */
95         long inodes[32]; /* actual inode numbers */
96 };
97
98 #define OBD_IOC_CREATE                 _IOR('f', 3, long)
99 #define OBD_IOC_SETUP                  _IOW('f', 4, long)
100 #define OBD_IOC_SYNC                   _IOR('f', 5, long)
101 #define OBD_IOC_DESTROY                _IOW('f', 6, long)
102
103 #define OBD_IOC_DEC_USE_COUNT          _IO('f', 8)
104
105
106 /* balloc.c */
107 int obd_new_block (const struct inode * inode, unsigned long goal,
108                    u32 * prealloc_count, u32 * prealloc_block, int * err);
109 void obd_free_blocks (const struct inode * inode, unsigned long block,
110                       unsigned long count);
111 unsigned long obd_count_free_blocks (struct super_block * sb);
112 int ext2_group_sparse(int group);
113 struct ext2_group_desc * ext2_get_group_desc(struct super_block * sb,
114                                             unsigned int block_group,
115                                             struct buffer_head ** bh);
116
117
118 /* bitmap.c */
119 unsigned long ext2_count_free(struct buffer_head * map, unsigned int numchars);
120
121 /* fsync.c */
122 extern int obd_sync_file(struct file * file, struct dentry *dentry);
123
124 /* ialloc.c */
125 extern void ext2_free_inode (struct inode * inode);
126 extern struct inode * ext2_new_inode (const struct inode * dir, int mode,
127                                      int * err);
128 extern unsigned long ext2_count_free_inodes (struct super_block * sb);
129 extern void ext2_check_inodes_bitmap (struct super_block * sb);
130
131 /* inode.c */
132 void obd_read_inode (struct inode * inode);
133 void obd_write_inode (struct inode * inode);
134 void obd_put_inode (struct inode * inode);
135 void obd_delete_inode (struct inode * inode);
136 void obd_discard_prealloc_blocks (struct inode * inode);
137 int obd_sync_inode (struct inode *inode);
138 struct buffer_head * obd_bread (struct inode * inode, int block, 
139                                 int create, int *err);
140 struct buffer_head * obd_getblk (struct inode * inode, long block,
141                                  int create, int * err);
142
143 /* interface.c */
144 extern int obd_create (struct super_block * sb, int inode_hint, int * err);
145 extern void obd_unlink (struct inode * inode);
146
147 /* ioctl.c */
148 int obd_ioctl (struct inode * inode, struct file * filp, unsigned int cmd,
149                unsigned long arg);
150
151 /* super.c */
152 #define obd_error obd_warning
153 #define obd_panic obd_warning
154 extern void obd_warning (struct super_block *, const char *, const char *, ...)
155         __attribute__ ((format (printf, 3, 4)));
156 int obd_remount (struct super_block * sb, int * flags, char * data);
157 struct super_block * obd_read_super (struct super_block * sb, void * data,
158                                      int silent);
159
160 /* sysctl.c */
161 extern void obd_sysctl_init (void);
162 extern void obd_sysctl_clean (void);
163
164 /* truncate.c */
165 void obd_truncate (struct inode * inode);
166
167 /* operations */
168 /* dir.c */
169 extern struct inode_operations obd_dir_inode_operations;
170
171 /* file.c */
172 extern struct inode_operations obd_file_inode_operations;
173
174 #endif /* __LINUX_SYM_OBD_H */