Whamcloud - gitweb
639d221d4fe16ed1672a6ae343696d6dfe0c4e5e
[fs/lustre-release.git] / lustre / include / linux / obd_class.h
1 #ifndef __LINUX_CLASS_OBD_H
2 #define __LINUX_CLASS_OBD_H
3
4 #include <linux/fs.h>
5 #include <linux/ext2_fs.h>
6 #include <linux/time.h>
7 #include <linux/obd.h>
8
9 #include <linux/obd_ext2.h>
10 #include <linux/obd_snap.h>
11 /* #include <linux/obd_fc.h> */
12 #include <linux/obd_raid1.h>
13 #include <linux/obd_rpc.h>
14
15
16 #define OBD_PSDEV_MAJOR 186
17 #define MAX_OBD_DEVICES 8
18 #define MAX_MULTI 16
19
20 typedef unsigned long   objid;
21 typedef struct inode obdattr;
22 #if 0
23 struct obdattr {
24         objid                   oa_id;
25         umode_t                 oa_mode;
26         nlink_t                 oa_nlink;
27         uid_t                   oa_uid;
28         gid_t                   oa_gid;
29         off_t                   oa_size;
30         time_t                  oa_atime;
31         time_t                  oa_mtime;
32         time_t                  oa_ctime;
33         unsigned long           oa_blksize;
34         unsigned long           oa_blocks;
35         char                    oa_data[116];
36         struct obd_ops         *oa_op;
37 };
38
39 #endif
40
41 extern struct obd_device obd_dev[MAX_OBD_DEVICES];
42
43         
44
45
46
47 #define OBD_ATTACHED 0x1
48 #define OBD_SET_UP   0x2
49
50 struct obd_conn {
51         struct obd_device *oc_dev;
52         unsigned int oc_id;
53 };
54
55 /* corresponds to one of the obdx */
56 struct obd_device {
57         struct obd_type *obd_type;
58         int obd_minor;
59         int obd_flags;
60         int obd_refcnt; 
61         int obd_multi_count;
62         struct obd_conn obd_multi_conn[MAX_MULTI];
63         unsigned int obd_gen_last_id;
64         unsigned long obd_gen_prealloc_quota;
65         struct list_head obd_gen_clients;
66         union {
67                 struct ext2_obd ext2;
68                 struct raid1_obd raid1;
69                 struct snap_obd snap;
70                 struct rpc_obd rpc;
71                 /* struct fc_obd fc; */
72         } u;
73 };
74
75 struct obd_ops {
76         int (*o_attach)(struct obd_device *, int len, void *);
77         int (*o_detach)(struct obd_device *);
78         int (*o_format)(struct obd_device *, int len, void *);
79         int (*o_partition)(struct obd_device *, int len, void *);
80         int (*o_connect)(struct obd_conn *conn);
81         int (*o_disconnect)(struct obd_conn *);
82         int (*o_setup) (struct obd_device *dev, int len, void *data);
83         int (*o_cleanup)(struct obd_device *dev);
84         int (*o_setattr)(struct obd_conn *, obdattr *oa);
85         int (*o_getattr)(struct obd_conn *, obdattr *oa);
86         int (*o_statfs)(struct obd_conn *, struct statfs *statfs);
87         int (*o_create)(struct obd_conn *, int prealloc_ino, int *er);
88         int (*o_destroy)(struct obd_conn *, obdattr *oa);
89         int (*o_read)(struct obd_conn *, obdattr *ino, char *buf, unsigned long *count, loff_t offset);
90         int (*o_read2)(struct obd_conn *, obdattr *oa, char *buf, unsigned long *count, loff_t offset);
91         int (*o_write)(struct obd_conn *, obdattr *oa, char *buf, unsigned long *count, loff_t offset);
92         int (*o_brw)(int rw, struct obd_conn * conn, obdattr *obj, struct page *page, int create);
93         int (*o_preallocate)(struct obd_conn *, unsigned long *req, long inodes[32]);
94         int  (*o_get_info)(struct obd_conn *, int keylen, void *key, int *vallen, void **val);
95         int  (*o_set_info)(struct obd_conn *, int keylen, void *key, int vallen, void *val);
96         int (*o_migrate)(struct obd_conn *, obdattr *src, obdattr *dst);
97         int (*o_copy)(struct obd_conn *dev, obdattr *source, obdattr *target);
98         int (*o_iocontrol)(int cmd, struct obd_conn *, int len, void *karg, void *uarg);
99         int (*o_iterate)(struct obd_conn *, int (*)(objid, void *), objid, void *);
100
101 };
102
103 #define OBT(dev)        dev->obd_type->typ_ops
104 #define OBP(dev,op)     dev->obd_type->typ_ops->o_ ## op
105
106 int obd_register_type(struct obd_ops *ops, char *nm);
107 int obd_unregister_type(char *nm);
108
109 struct obd_client {
110         struct list_head cli_chain;
111         struct obd_device *cli_obd;
112         unsigned int cli_id;
113         unsigned long cli_prealloc_quota;
114         struct list_head cli_prealloc_inodes;
115 };
116
117
118 struct obd_prealloc_inode {
119         struct list_head obd_prealloc_chain;
120         unsigned long inode;
121 };
122
123 /* generic operations shared by various OBD types */
124 int gen_connect (struct obd_conn *conn);
125 int gen_disconnect(struct obd_conn *conn);
126 int gen_multi_setup(struct obd_device *obddev, int len, void *data);
127 int gen_multi_cleanup(struct obd_device *obddev);
128 int gen_multi_attach(struct obd_device *obddev, int len, void *data);
129 struct obd_client *gen_client(struct obd_conn *);
130 int gen_multi_detach(struct obd_device *obddev);
131 int gen_cleanup(struct obd_device *obddev);
132 int gen_copy_data(struct obd_conn *, obdattr *source, obdattr *target);
133
134
135
136 /*
137  * ioctl commands
138  */
139 struct oic_generic {
140         int  att_connid;
141         int  att_typelen;
142         void *att_type;
143         int  att_datalen;
144         void *att_data;
145 };
146
147 struct oic_prealloc_s {
148         unsigned long cli_id;
149         unsigned long alloc; /* user sets it to the number of inodes requesting
150                      * to be preallocated.  kernel sets it to the actual number
151                      * of succesfully preallocated inodes */
152         long inodes[32]; /* actual inode numbers */
153 };
154
155 struct oic_create_s {
156         unsigned int conn_id;
157         unsigned long prealloc;
158 };
159
160 struct oic_attr_s {
161         unsigned int conn_id;
162         unsigned long ino;
163         struct iattr iattr;
164 };
165
166 struct ioc_mv_s {
167         unsigned int conn_id;
168         objid  src;
169         objid  tgt;
170 };
171
172 struct oic_rw_s {
173         unsigned int conn_id;
174         unsigned long id;
175         char * buf;
176         unsigned long count;
177         loff_t offset;
178 };
179
180 struct oic_partition {
181         int partition;
182         unsigned int size;
183 };
184
185
186 #define OBD_IOC_CREATE                 _IOR ('f',  3, long)
187 #define OBD_IOC_SETUP                  _IOW ('f',  4, long)
188 #define OBD_IOC_CLEANUP                _IO  ('f',  5      )
189 #define OBD_IOC_DESTROY                _IOW ('f',  6, long)
190 #define OBD_IOC_PREALLOCATE            _IOWR('f',  7, long)
191 #define OBD_IOC_DEC_USE_COUNT          _IO  ('f',  8      )
192 #define OBD_IOC_SETATTR                _IOW ('f',  9, long)
193 #define OBD_IOC_GETATTR                _IOR ('f', 10, long)
194 #define OBD_IOC_READ                   _IOWR('f', 11, long)
195 #define OBD_IOC_WRITE                  _IOWR('f', 12, long)
196 #define OBD_IOC_CONNECT                _IOR ('f', 13, long)
197 #define OBD_IOC_DISCONNECT             _IOW ('f', 14, long)
198 #define OBD_IOC_STATFS                 _IOWR('f', 15, long)
199 #define OBD_IOC_SYNC                   _IOR ('f',  16, long)
200 #define OBD_IOC_READ2                  _IOWR('f', 17, long)
201 #define OBD_IOC_FORMAT                 _IOWR('f', 18, long)
202 #define OBD_IOC_PARTITION              _IOWR('f', 19, long)
203 #define OBD_IOC_ATTACH                 _IOWR('f', 20, long)
204 #define OBD_IOC_DETACH                 _IOWR('f', 21, long)
205 #define OBD_IOC_COPY                   _IOWR('f', 22, long)
206 #define OBD_IOC_MIGR                   _IOWR('f', 23, long)
207
208 #define OBD_IOC_DEC_FS_USE_COUNT       _IO  ('f', 32      )
209
210
211 /* sysctl.c */
212 extern void obd_sysctl_init (void);
213 extern void obd_sysctl_clean (void);
214
215 #define CHKCONN(conn)   do { if (!gen_client(conn)) {\
216                 printk("%s %d invalid client %u\n", __FILE__, __LINE__, \
217                        conn->oc_id);\
218                 return -EINVAL; }} while (0) 
219
220
221 /* support routines */
222 static __inline__ obdattr *obd_empty_oa(void)
223 {
224         obdattr *res = NULL;
225         OBD_ALLOC(res, obdattr *, sizeof(*res));
226         memset(res, 0, sizeof (*res));
227         return res;
228 }
229
230 static __inline__ void obd_free_oa(obdattr *oa)
231 {
232         if ( !oa ) 
233                 return;
234         OBD_FREE(oa,sizeof(*oa));
235 }
236
237
238
239 static __inline__ obdattr *obd_oa_fromid(struct obd_conn *conn,  objid id)
240 {
241         obdattr *res = NULL;
242
243         OBD_ALLOC(res, obdattr *, sizeof(*res));
244         if ( !res ) {
245                 EXIT;
246                 return NULL;
247         }
248         memset(res, 0, sizeof(*res));
249         res->i_ino = id;
250         if (conn->oc_dev->obd_type->typ_ops->o_getattr(conn, res)) {
251                 OBD_FREE(res, sizeof(*res));
252                 EXIT;
253                 return NULL;
254         }
255         EXIT;
256         return res;
257 }
258
259 #define OBD_MD_NO       (1UL)       /* negates meaning of all flags */
260 #define OBD_MD_ALL      (OBD_MD_NO) /* passing NO with no other flags == ALL */
261 #define OBD_MD_FLMODE   (1UL<<1)
262 #define OBD_MD_FLUID    (1UL<<2)
263 #define OBD_MD_FLGID    (1UL<<3)
264 #define OBD_MD_FLSIZE   (1UL<<4)
265 #define OBD_MD_FLATIME  (1UL<<5)
266 #define OBD_MD_FLMTIME  (1UL<<6)
267 #define OBD_MD_FLCTIME  (1UL<<7)
268 #define OBD_MD_FLFLAGS  (1UL<<8)
269 #define OBD_MD_FLBLOCKS (1UL<<9)
270 #define OBD_MD_FLOBDMD  (1UL<<10)
271
272
273 static __inline__ void obdo_cpy_md(obdattr *dst, obdattr *src, int mask)
274 {
275         /* If the OBD_MD_NO flag is set, then we copy all EXCEPT those
276          * fields given by the flags.  The default is to copy the field
277          * given by the flags.
278          */
279         if (mask & OBD_MD_NO)
280                 mask = ~mask;
281
282         CDEBUG(D_INODE, "flags %x\n", mask);
283         if ( mask & OBD_MD_FLMODE ) 
284                 dst->i_mode = src->i_mode;
285         if ( mask & OBD_MD_FLUID ) 
286                 dst->i_uid = src->i_uid;
287         if ( mask & OBD_MD_FLGID ) 
288                 dst->i_gid = src->i_gid;
289         if ( mask & OBD_MD_FLSIZE ) 
290                 dst->i_size = src->i_size;
291         if ( mask & OBD_MD_FLATIME ) 
292                 dst->i_atime = src->i_atime;
293         if ( mask & OBD_MD_FLMTIME ) 
294                 dst->i_mtime = src->i_mtime;
295         if ( mask & OBD_MD_FLCTIME ) 
296                 dst->i_ctime = src->i_ctime;
297         if ( mask & OBD_MD_FLFLAGS ) 
298                 dst->i_flags = src->i_flags;
299         /* allocation of space */
300         if ( mask & OBD_MD_FLBLOCKS ) 
301                 dst->i_blocks = src->i_blocks;
302         if ( mask & OBD_MD_FLOBDMD  &&  src->i_blocks == 0 ) {
303                 CDEBUG(D_IOCTL, "copying inline data: ino %ld\n", dst->i_ino);
304                 memcpy(&dst->u.ext2_i.i_data, &src->u.ext2_i.i_data, 
305                        sizeof(src->u.ext2_i.i_data));
306         } else {
307                 CDEBUG(D_INODE, "XXXX cpy_obdmd: ino %ld iblocks not 0!\n",
308                        src->i_ino);
309         }
310 }
311
312
313 static __inline__ int obdo_cmp_md(obdattr *dst, obdattr *src, int mask)
314 {
315         int res = 1;
316
317         /* If the OBD_MD_NO flag is set, then we copy all EXCEPT those
318          * fields given by the flags.  The default is to copy the field
319          * given by the flags.
320          */
321         if (mask & OBD_MD_NO)
322                 mask = ~mask;
323
324         if ( mask & OBD_MD_FLMODE )
325                 res = (res && (dst->i_mode == src->i_mode));
326         if ( mask & OBD_MD_FLUID )
327                 res = (res && (dst->i_uid == src->i_uid));
328         if ( mask & OBD_MD_FLGID )
329                 res = (res && (dst->i_gid == src->i_gid));
330         if ( mask & OBD_MD_FLSIZE )
331                 res = (res && (dst->i_size == src->i_size));
332         if ( mask & OBD_MD_FLATIME )
333                 res = (res && (dst->i_atime == src->i_atime));
334         if ( mask & OBD_MD_FLMTIME )
335                 res = (res && (dst->i_mtime == src->i_mtime));
336         if ( mask & OBD_MD_FLCTIME )
337                 res = (res && (dst->i_ctime == src->i_ctime));
338         if ( mask & OBD_MD_FLFLAGS )
339                 res = (res && (dst->i_flags == src->i_flags));
340         /* allocation of space */
341         if ( mask & OBD_MD_FLBLOCKS )
342                 res = (res && (dst->i_blocks == src->i_blocks));
343         return res;
344 }
345
346
347 static __inline__ void obd_cpy_appmd(obdattr *dst, obdattr *src)
348 {
349         dst->i_mode = src->i_mode;
350         dst->i_uid = src->i_uid;
351         dst->i_gid = src->i_gid;
352         dst->i_size = src->i_size;
353         dst->i_atime = src->i_atime;
354         dst->i_mtime = src->i_mtime;
355         dst->i_ctime = src->i_ctime;
356         dst->i_flags = src->i_flags;
357         /* allocation of space */
358         dst->i_blocks = src->i_blocks;
359 }
360
361 #endif /* __LINUX_CLASS_OBD_H */