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