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