Whamcloud - gitweb
- small issues
[fs/lustre-release.git] / lustre / include / linux / obd_class.h
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  *  Copyright (C) 2001, 2002 Cluster File Systems, Inc.
5  *
6  *   This file is part of Lustre, http://www.lustre.org.
7  *
8  *   Lustre is free software; you can redistribute it and/or
9  *   modify it under the terms of version 2 of the GNU General Public
10  *   License as published by the Free Software Foundation.
11  *
12  *   Lustre is distributed in the hope that it will be useful,
13  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *   GNU General Public License for more details.
16  *
17  *   You should have received a copy of the GNU General Public License
18  *   along with Lustre; if not, write to the Free Software
19  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20  *
21  */
22
23 #ifndef __LINUX_CLASS_OBD_H
24 #define __LINUX_CLASS_OBD_H
25
26 #ifndef __KERNEL__
27 # include <stdint.h>
28 # define __KERNEL__
29 # include <linux/list.h>
30 # undef __KERNEL__
31 #else 
32 #include <asm/segment.h>
33 #include <asm/uaccess.h>
34 #include <linux/types.h>
35 #include <linux/fs.h>
36 #include <linux/time.h>
37
38 #include <linux/obd_support.h>
39 #include <linux/obd.h>
40 #include <linux/lustre_lib.h>
41 #include <linux/lustre_idl.h>
42 #endif
43
44 /*
45  *  ======== OBD Device Declarations ===========
46  */
47 #define MAX_OBD_DEVICES 128
48 extern struct obd_device obd_dev[MAX_OBD_DEVICES];
49
50 #define OBD_ATTACHED 0x1
51 #define OBD_SET_UP   0x2
52
53 extern struct proc_dir_entry *
54 proc_lustre_register_obd_device(struct obd_device *obd);
55 extern void proc_lustre_release_obd_device(struct obd_device *obd);
56 extern void proc_lustre_remove_obd_entry(const char* name,
57                                          struct obd_device *obd);
58
59 /*
60  *  ======== OBD Operations Declarations ===========
61  */
62
63 #define OBD_BRW_READ    1
64 #define OBD_BRW_WRITE   2
65 #define OBD_BRW_RWMASK  (OBD_BRW_READ | OBD_BRW_WRITE)
66 #define OBD_BRW_CREATE  4
67
68 #ifdef __KERNEL__
69 extern struct obd_export *gen_client(struct obd_conn *conn);
70 extern struct obd_device *gen_conn2obd(struct obd_conn *conn);
71 struct obd_export {
72         __u64 export_cookie;
73         struct lustre_handle export_import; /* client handle */ 
74         struct list_head export_chain;
75         struct obd_device *export_obd;
76         struct ptlrpc_connection *export_connection;
77         unsigned int export_id;
78         void *export_data; /* device specific data */
79 };
80
81 struct obd_import {
82         __u64 import_cookie;
83         struct lustre_handle import_export; /* client handle */ 
84         struct list_head import_chain;
85         struct obd_device *import_obd;
86         unsigned int import_id;
87         void *import_data; /* device specific data */
88 };
89
90
91 struct obd_request {
92         struct obdo *oa;
93         struct obd_conn *conn;
94         __u32 plen1;
95         char *pbuf1;
96 };
97
98
99 static inline int obd_check_conn(struct obd_conn *conn) 
100 {
101         struct obd_device *obd;
102         if (!conn) {
103                 CERROR("NULL conn\n");
104                 RETURN(-ENOTCONN);
105         }
106         obd = gen_conn2obd(conn);
107         if (!obd) {
108                 CERROR("NULL obd\n");
109                 RETURN(-ENODEV);
110         }
111
112         if (!obd->obd_flags & OBD_ATTACHED ) {
113                 CERROR("obd %d not attached\n", obd->obd_minor);
114                 RETURN(-ENODEV);
115         }
116
117         if (!obd->obd_flags & OBD_SET_UP) {
118                 CERROR("obd %d not setup\n", obd->obd_minor); 
119                 RETURN(-ENODEV);
120         }
121
122         if (!obd->obd_type) {
123                 CERROR("obd %d not typed\n", obd->obd_minor);
124                 RETURN(-ENODEV);
125         }
126
127         if (!obd->obd_type->typ_ops) {
128                 CERROR("obd_check_conn: obd %d no operations\n",
129                        obd->obd_minor);
130                 RETURN(-EOPNOTSUPP);
131         }
132         return 0;
133 }
134
135
136 #define OBT(dev)        (dev)->obd_type
137 #define OBP(dev,op)     (dev)->obd_type->typ_ops->o_ ## op
138
139 #define OBD_CHECK_SETUP(conn, export)                          \
140 do {                                                            \
141         if (!(conn)) {                                          \
142                 CERROR("NULL connection\n");                    \
143                 RETURN(-EINVAL);                                \
144         }                                                       \
145                                                                 \
146         export = gen_client(conn);\
147         if (!(export)) {                                \
148                 CERROR("No export\n");                        \
149                 RETURN(-EINVAL);                                \
150         }                                                       \
151                                                                 \
152         if ( !((export)->export_obd->obd_flags & OBD_SET_UP) ) {    \
153                 CERROR("Device %d not setup\n",                 \
154                        (export)->export_obd->obd_minor);        \
155                 RETURN(-EINVAL);                                \
156         }                                                       \
157 } while (0)
158
159 #define OBD_CHECK_DEVSETUP(obd)                                \
160 do {                                                            \
161         if (!(obd)) {                                          \
162                 CERROR("NULL device\n");                        \
163                 RETURN(-EINVAL);                                \
164         }                                                       \
165                                                                 \
166         if ( !((obd)->obd_flags & OBD_SET_UP) ) {               \
167                 CERROR("Device %d not setup\n",                 \
168                        (obd)->obd_minor);                       \
169                 RETURN(-EINVAL);                                \
170         }                                                       \
171 } while (0)
172
173 #define OBD_CHECK_OP(obd,op)                                   \
174 do {                                                            \
175         if (!OBP((obd),op)) {                                   \
176                 CERROR("obd_" #op ": dev %d no operation\n",    \
177                        obd->obd_minor);                         \
178                 RETURN(-EOPNOTSUPP);                            \
179         }                                                       \
180 } while (0)
181
182 static inline int obd_get_info(struct obd_conn *conn, obd_count keylen,
183                                void *key, obd_count *vallen, void **val)
184 {
185         int rc;
186         struct obd_export *export;
187         OBD_CHECK_SETUP(conn, export);
188         OBD_CHECK_OP(export->export_obd,get_info);
189
190         rc = OBP(export->export_obd, get_info)(conn, keylen, key, vallen, val);
191         RETURN(rc);
192 }
193
194 static inline int obd_set_info(struct obd_conn *conn, obd_count keylen,
195                                void *key, obd_count vallen, void *val)
196 {
197         int rc;
198         struct obd_export *export;
199         OBD_CHECK_SETUP(conn, export);
200         OBD_CHECK_OP(export->export_obd,set_info);
201
202         rc = OBP(export->export_obd, set_info)(conn, keylen, key, vallen, val);
203         RETURN(rc);
204 }
205
206 static inline int obd_setup(struct obd_device *obd, int datalen, void *data)
207 {
208         int rc;
209
210         OBD_CHECK_OP(obd,setup);
211
212         rc = OBP(obd, setup)(obd, datalen, data);
213         RETURN(rc);
214 }
215
216 static inline int obd_cleanup(struct obd_device *obd)
217 {
218         int rc;
219
220         OBD_CHECK_DEVSETUP(obd);
221         OBD_CHECK_OP(obd,cleanup);
222
223         rc = OBP(obd, cleanup)(obd);
224         RETURN(rc);
225 }
226
227 static inline int obd_create(struct obd_conn *conn, struct obdo *obdo)
228 {
229         int rc;
230         struct obd_export *export;
231         OBD_CHECK_SETUP(conn, export);
232         OBD_CHECK_OP(export->export_obd,create);
233
234         rc = OBP(export->export_obd, create)(conn, obdo);
235         RETURN(rc);
236 }
237
238 static inline int obd_destroy(struct obd_conn *conn, struct obdo *obdo)
239 {
240         int rc;
241         struct obd_export *export;
242         OBD_CHECK_SETUP(conn, export);
243         OBD_CHECK_OP(export->export_obd,destroy);
244
245         rc = OBP(export->export_obd, destroy)(conn, obdo);
246         RETURN(rc);
247 }
248
249 static inline int obd_getattr(struct obd_conn *conn, struct obdo *obdo)
250 {
251         int rc;
252         struct obd_export *export;
253         OBD_CHECK_SETUP(conn, export);
254         OBD_CHECK_OP(export->export_obd,getattr);
255
256         rc = OBP(export->export_obd, getattr)(conn, obdo);
257         RETURN(rc);
258 }
259
260 static inline int obd_close(struct obd_conn *conn, struct obdo *obdo)
261 {
262         int rc;
263         struct obd_export *export;
264         OBD_CHECK_SETUP(conn, export);
265         OBD_CHECK_OP(export->export_obd,close);
266
267         rc = OBP(export->export_obd, close)(conn, obdo);
268         RETURN(rc);
269 }
270 static inline int obd_open(struct obd_conn *conn, struct obdo *obdo)
271 {
272         int rc;
273         struct obd_export *export;
274         OBD_CHECK_SETUP(conn, export);
275         OBD_CHECK_OP(export->export_obd,open);
276
277         rc = OBP(export->export_obd, open) (conn, obdo);
278         RETURN(rc);
279 }
280
281 static inline int obd_setattr(struct obd_conn *conn, struct obdo *obdo)
282 {
283         int rc;
284         struct obd_export *export;
285         OBD_CHECK_SETUP(conn, export);
286         OBD_CHECK_OP(export->export_obd,setattr);
287
288         rc = OBP(export->export_obd, setattr)(conn, obdo);
289         RETURN(rc);
290 }
291
292 static inline int obd_connect(struct obd_conn *conn, struct obd_device *obd)
293 {
294         int rc;
295         OBD_CHECK_DEVSETUP(obd);
296         OBD_CHECK_OP(obd,connect);
297
298         rc = OBP(obd, connect)(conn, obd);
299         RETURN(rc);
300 }
301
302 static inline int obd_disconnect(struct obd_conn *conn)
303 {
304         int rc;
305         struct obd_export *export;
306         OBD_CHECK_SETUP(conn, export);
307         OBD_CHECK_OP(export->export_obd,disconnect);
308
309         rc = OBP(export->export_obd, disconnect)(conn);
310         RETURN(rc);
311 }
312
313 static inline int obd_statfs(struct obd_conn *conn, struct statfs *buf)
314 {
315         int rc;
316         struct obd_export *export;
317         OBD_CHECK_SETUP(conn, export);
318         OBD_CHECK_OP(export->export_obd,statfs);
319
320         rc = OBP(export->export_obd, statfs)(conn, buf);
321         RETURN(rc);
322 }
323
324 static inline int obd_punch(struct obd_conn *conn, struct obdo *tgt,
325                             obd_size count, obd_off offset)
326 {
327         int rc;
328         struct obd_export *export;
329         OBD_CHECK_SETUP(conn, export);
330         OBD_CHECK_OP(export->export_obd,punch);
331
332         rc = OBP(export->export_obd, punch)(conn, tgt, count, offset);
333         RETURN(rc);
334 }
335
336 static inline int obd_brw(int cmd, struct obd_conn *conn, obd_count num_oa,
337                           struct obdo **oa, obd_count *oa_bufs,
338                           struct page **buf, obd_size *count, obd_off *offset,
339                           obd_flag *flags, void *callback)
340 {
341         int rc;
342         struct obd_export *export;
343         OBD_CHECK_SETUP(conn, export);
344         OBD_CHECK_OP(export->export_obd,brw);
345
346         if (!(cmd & OBD_BRW_RWMASK)) {
347                 CERROR("obd_brw: cmd must be OBD_BRW_READ or OBD_BRW_WRITE\n");
348                 LBUG();
349         }
350
351         rc = OBP(export->export_obd, brw)(cmd, conn, num_oa, oa, oa_bufs, buf,
352                                     count, offset, flags, callback);
353         RETURN(rc);
354 }
355
356 static inline int obd_preprw(int cmd, struct obd_conn *conn,
357                              int objcount, struct obd_ioobj *obj,
358                              int niocount, struct niobuf_remote *remote,
359                              struct niobuf_local *local, void **desc_private)
360 {
361         int rc;
362         struct obd_export *export;
363         OBD_CHECK_SETUP(conn, export);
364         OBD_CHECK_OP(export->export_obd,preprw);
365
366         rc = OBP(export->export_obd, preprw)(cmd, conn, objcount, obj, niocount,
367                                        remote, local, desc_private);
368         RETURN(rc);
369 }
370
371 static inline int obd_commitrw(int cmd, struct obd_conn *conn,
372                                int objcount, struct obd_ioobj *obj,
373                                int niocount, struct niobuf_local *local,
374                                void *desc_private)
375 {
376         int rc;
377         struct obd_export *export;
378         OBD_CHECK_SETUP(conn, export);
379         OBD_CHECK_OP(export->export_obd,commitrw);
380
381         rc = OBP(export->export_obd, commitrw)(cmd, conn, objcount, obj, niocount,
382                                          local, desc_private);
383         RETURN(rc);
384 }
385
386 static inline int obd_iocontrol(int cmd, struct obd_conn *conn,
387                                 int len, void *karg, void *uarg)
388 {
389         int rc;
390         struct obd_export *export;
391         OBD_CHECK_SETUP(conn, export);
392         OBD_CHECK_OP(export->export_obd,iocontrol);
393
394         rc = OBP(export->export_obd, iocontrol)(cmd, conn, len, karg, uarg);
395         RETURN(rc);
396 }
397
398 static inline int obd_enqueue(struct obd_conn *conn,
399                               struct lustre_handle *parent_lock, __u64 *res_id,
400                               __u32 type, void *cookie, int cookielen,
401                               __u32 mode, int *flags, void *cb, void *data,
402                               int datalen, struct lustre_handle *lockh)
403 {
404         int rc;
405         struct obd_export *export;
406         OBD_CHECK_SETUP(conn, export);
407         OBD_CHECK_OP(export->export_obd,enqueue);
408
409         rc = OBP(export->export_obd, enqueue)(conn, parent_lock, res_id, type,
410                                         cookie, cookielen, mode, flags, cb,
411                                         data, datalen, lockh);
412         RETURN(rc);
413 }
414
415 static inline int obd_cancel(struct obd_conn *conn, __u32 mode,
416                              struct lustre_handle *lockh)
417 {
418         int rc;
419         struct obd_export *export;
420         OBD_CHECK_SETUP(conn, export);
421         OBD_CHECK_OP(export->export_obd,cancel);
422         
423         rc = OBP(export->export_obd, cancel)(conn, mode, lockh);
424         RETURN(rc);
425 }
426
427 #endif 
428
429 /*
430  *  ======== OBD Metadata Support  ===========
431  */
432
433 extern int obd_init_caches(void);
434 extern void obd_cleanup_caches(void);
435
436
437 static inline int obdo_has_inline(struct obdo *obdo)
438 {
439         return (obdo->o_valid & OBD_MD_FLINLINE &&
440                 obdo->o_obdflags & OBD_FL_INLINEDATA);
441 };
442
443 static inline int obdo_has_obdmd(struct obdo *obdo)
444 {
445         return (obdo->o_valid & OBD_MD_FLOBDMD &&
446                 obdo->o_obdflags & OBD_FL_OBDMDEXISTS);
447 };
448
449 #ifdef __KERNEL__
450 /* support routines */
451 extern kmem_cache_t *obdo_cachep;
452
453 static __inline__ struct obdo *obdo_alloc(void)
454 {
455         struct obdo *oa = NULL;
456
457         oa = kmem_cache_alloc(obdo_cachep, SLAB_KERNEL);
458         if (oa == NULL)
459                 LBUG();
460         memset(oa, 0, sizeof (*oa));
461
462         return oa;
463 }
464
465 static __inline__ void obdo_free(struct obdo *oa)
466 {
467         if (!oa)
468                 return;
469         kmem_cache_free(obdo_cachep, oa);
470 }
471
472 static __inline__ struct obdo *obdo_fromid(struct obd_conn *conn, obd_id id,
473                                            obd_mode mode, obd_flag valid)
474 {
475         struct obdo *oa;
476         int err;
477
478         ENTRY;
479         oa = obdo_alloc();
480         if ( !oa ) {
481                 RETURN(ERR_PTR(-ENOMEM));
482         }
483
484         oa->o_id = id;
485         oa->o_mode = mode;
486         oa->o_valid = valid;
487         if ((err = obd_getattr(conn, oa))) {
488                 obdo_free(oa);
489                 RETURN(ERR_PTR(err));
490         }
491         RETURN(oa);
492 }
493
494 static inline void obdo_from_iattr(struct obdo *oa, struct iattr *attr)
495 {
496         unsigned int ia_valid = attr->ia_valid;
497
498         if (ia_valid & ATTR_ATIME) {
499                 oa->o_atime = attr->ia_atime;
500                 oa->o_valid |= OBD_MD_FLATIME;
501         }
502         if (ia_valid & ATTR_MTIME) {
503                 oa->o_mtime = attr->ia_mtime;
504                 oa->o_valid |= OBD_MD_FLMTIME;
505         }
506         if (ia_valid & ATTR_CTIME) {
507                 oa->o_ctime = attr->ia_ctime;
508                 oa->o_valid |= OBD_MD_FLCTIME;
509         }
510         if (ia_valid & ATTR_SIZE) {
511                 oa->o_size = attr->ia_size;
512                 oa->o_valid |= OBD_MD_FLSIZE;
513         }
514         if (ia_valid & ATTR_MODE) {
515                 oa->o_mode = attr->ia_mode;
516                 oa->o_valid |= OBD_MD_FLMODE;
517                 if (!in_group_p(oa->o_gid) && !capable(CAP_FSETID))
518                         oa->o_mode &= ~S_ISGID;
519         }
520         if (ia_valid & ATTR_UID)
521         {
522                 oa->o_uid = attr->ia_uid;
523                 oa->o_valid |= OBD_MD_FLUID;
524         }
525         if (ia_valid & ATTR_GID) {
526                 oa->o_gid = attr->ia_gid;
527                 oa->o_valid |= OBD_MD_FLGID;
528         }
529 }
530
531
532 static inline void iattr_from_obdo(struct iattr *attr, struct obdo *oa)
533 {
534         unsigned int ia_valid = oa->o_valid;
535         
536         memset(attr, 0, sizeof(*attr));
537         if (ia_valid & OBD_MD_FLATIME) {
538                 attr->ia_atime = oa->o_atime;
539                 attr->ia_valid |= ATTR_ATIME;
540         }
541         if (ia_valid & OBD_MD_FLMTIME) {
542                 attr->ia_mtime = oa->o_mtime;
543                 attr->ia_valid |= ATTR_MTIME;
544         }
545         if (ia_valid & OBD_MD_FLCTIME) {
546                 attr->ia_ctime = oa->o_ctime;
547                 attr->ia_valid |= ATTR_CTIME;
548         }
549         if (ia_valid & OBD_MD_FLSIZE) {
550                 attr->ia_size = oa->o_size;
551                 attr->ia_valid |= ATTR_SIZE;
552         }
553         if (ia_valid & OBD_MD_FLMODE) {
554                 attr->ia_mode = oa->o_mode;
555                 attr->ia_valid |= ATTR_MODE;
556                 if (!in_group_p(oa->o_gid) && !capable(CAP_FSETID))
557                         attr->ia_mode &= ~S_ISGID;
558         }
559         if (ia_valid & OBD_MD_FLUID)
560         {
561                 attr->ia_uid = oa->o_uid;
562                 attr->ia_valid |= ATTR_UID;
563         }
564         if (ia_valid & OBD_MD_FLGID) {
565                 attr->ia_gid = oa->o_gid;
566                 attr->ia_valid |= ATTR_GID;
567         }
568 }
569
570
571 /* WARNING: the file systems must take care not to tinker with
572    attributes they don't manage (such as blocks). */
573
574 static __inline__ void obdo_from_inode(struct obdo *dst, struct inode *src)
575 {
576         if ( dst->o_valid & OBD_MD_FLID )
577                 dst->o_id = src->i_ino;
578         if ( dst->o_valid & OBD_MD_FLATIME )
579                 dst->o_atime = src->i_atime;
580         if ( dst->o_valid & OBD_MD_FLMTIME )
581                 dst->o_mtime = src->i_mtime;
582         if ( dst->o_valid & OBD_MD_FLCTIME )
583                 dst->o_ctime = src->i_ctime;
584         if ( dst->o_valid & OBD_MD_FLSIZE )
585                 dst->o_size = src->i_size;
586         if ( dst->o_valid & OBD_MD_FLBLOCKS )   /* allocation of space */
587                 dst->o_blocks = src->i_blocks;
588         if ( dst->o_valid & OBD_MD_FLBLKSZ )
589                 dst->o_blksize = src->i_blksize;
590         if ( dst->o_valid & OBD_MD_FLMODE )
591                 dst->o_mode = src->i_mode;
592         if ( dst->o_valid & OBD_MD_FLUID )
593                 dst->o_uid = src->i_uid;
594         if ( dst->o_valid & OBD_MD_FLGID )
595                 dst->o_gid = src->i_gid;
596         if ( dst->o_valid & OBD_MD_FLFLAGS )
597                 dst->o_flags = src->i_flags;
598         if ( dst->o_valid & OBD_MD_FLNLINK )
599                 dst->o_nlink = src->i_nlink;
600         if ( dst->o_valid & OBD_MD_FLGENER ) 
601                 dst->o_generation = src->i_generation;
602 }
603
604 static __inline__ void obdo_to_inode(struct inode *dst, struct obdo *src)
605 {
606
607         if ( src->o_valid & OBD_MD_FLID )
608                 dst->i_ino = src->o_id;
609         if ( src->o_valid & OBD_MD_FLATIME ) 
610                 dst->i_atime = src->o_atime;
611         if ( src->o_valid & OBD_MD_FLMTIME ) 
612                 dst->i_mtime = src->o_mtime;
613         if ( src->o_valid & OBD_MD_FLCTIME ) 
614                 dst->i_ctime = src->o_ctime;
615         if ( src->o_valid & OBD_MD_FLSIZE ) 
616                 dst->i_size = src->o_size;
617         if ( src->o_valid & OBD_MD_FLBLOCKS ) /* allocation of space */
618                 dst->i_blocks = src->o_blocks;
619         if ( src->o_valid & OBD_MD_FLBLKSZ )
620                 dst->i_blksize = src->o_blksize;
621         if ( src->o_valid & OBD_MD_FLMODE ) 
622                 dst->i_mode = src->o_mode;
623         if ( src->o_valid & OBD_MD_FLUID ) 
624                 dst->i_uid = src->o_uid;
625         if ( src->o_valid & OBD_MD_FLGID ) 
626                 dst->i_gid = src->o_gid;
627         if ( src->o_valid & OBD_MD_FLFLAGS ) 
628                 dst->i_flags = src->o_flags;
629         if ( src->o_valid & OBD_MD_FLNLINK )
630                 dst->i_nlink = src->o_nlink;
631         if ( src->o_valid & OBD_MD_FLGENER )
632                 dst->i_generation = src->o_generation;
633 }
634
635 #endif 
636
637 static __inline__ void obdo_cpy_md(struct obdo *dst, struct obdo *src)
638 {
639 #ifdef __KERNEL__
640         CDEBUG(D_INODE, "src obdo %Ld valid 0x%x, dst obdo %Ld\n",
641                (unsigned long long)src->o_id, src->o_valid,
642                (unsigned long long)dst->o_id);
643 #endif
644         if ( src->o_valid & OBD_MD_FLATIME ) 
645                 dst->o_atime = src->o_atime;
646         if ( src->o_valid & OBD_MD_FLMTIME ) 
647                 dst->o_mtime = src->o_mtime;
648         if ( src->o_valid & OBD_MD_FLCTIME ) 
649                 dst->o_ctime = src->o_ctime;
650         if ( src->o_valid & OBD_MD_FLSIZE ) 
651                 dst->o_size = src->o_size;
652         if ( src->o_valid & OBD_MD_FLBLOCKS ) /* allocation of space */
653                 dst->o_blocks = src->o_blocks;
654         if ( src->o_valid & OBD_MD_FLBLKSZ )
655                 dst->o_blksize = src->o_blksize;
656         if ( src->o_valid & OBD_MD_FLMODE ) 
657                 dst->o_mode = src->o_mode;
658         if ( src->o_valid & OBD_MD_FLUID ) 
659                 dst->o_uid = src->o_uid;
660         if ( src->o_valid & OBD_MD_FLGID ) 
661                 dst->o_gid = src->o_gid;
662         if ( src->o_valid & OBD_MD_FLFLAGS ) 
663                 dst->o_flags = src->o_flags;
664         /*
665         if ( src->o_valid & OBD_MD_FLOBDFLG ) 
666                 dst->o_obdflags = src->o_obdflags;
667         */
668         if ( src->o_valid & OBD_MD_FLNLINK ) 
669                 dst->o_nlink = src->o_nlink;
670         if ( src->o_valid & OBD_MD_FLGENER ) 
671                 dst->o_generation = src->o_generation;
672         if ( src->o_valid & OBD_MD_FLINLINE &&
673              src->o_obdflags & OBD_FL_INLINEDATA) {
674                 memcpy(dst->o_inline, src->o_inline, sizeof(src->o_inline));
675                 dst->o_obdflags |= OBD_FL_INLINEDATA;
676         }
677
678         dst->o_valid |= src->o_valid;
679 }
680
681
682 /* returns FALSE if comparison (by flags) is same, TRUE if changed */
683 static __inline__ int obdo_cmp_md(struct obdo *dst, struct obdo *src,
684                                   obd_flag compare)
685 {
686         int res = 0;
687
688         if ( compare & OBD_MD_FLATIME )
689                 res = (res || (dst->o_atime != src->o_atime));
690         if ( compare & OBD_MD_FLMTIME )
691                 res = (res || (dst->o_mtime != src->o_mtime));
692         if ( compare & OBD_MD_FLCTIME )
693                 res = (res || (dst->o_ctime != src->o_ctime));
694         if ( compare & OBD_MD_FLSIZE )
695                 res = (res || (dst->o_size != src->o_size));
696         if ( compare & OBD_MD_FLBLOCKS ) /* allocation of space */
697                 res = (res || (dst->o_blocks != src->o_blocks));
698         if ( compare & OBD_MD_FLBLKSZ )
699                 res = (res || (dst->o_blksize != src->o_blksize));
700         if ( compare & OBD_MD_FLMODE )
701                 res = (res || (dst->o_mode != src->o_mode));
702         if ( compare & OBD_MD_FLUID )
703                 res = (res || (dst->o_uid != src->o_uid));
704         if ( compare & OBD_MD_FLGID )
705                 res = (res || (dst->o_gid != src->o_gid));
706         if ( compare & OBD_MD_FLFLAGS ) 
707                 res = (res || (dst->o_flags != src->o_flags));
708         if ( compare & OBD_MD_FLNLINK )
709                 res = (res || (dst->o_nlink != src->o_nlink));
710         if ( compare & OBD_MD_FLGENER )
711                 res = (res || (dst->o_generation != src->o_generation));
712         /* XXX Don't know if thses should be included here - wasn't previously
713         if ( compare & OBD_MD_FLINLINE )
714                 res = (res || memcmp(dst->o_inline, src->o_inline));
715         if ( compare & OBD_MD_FLOBDMD )
716                 res = (res || memcmp(dst->o_obdmd, src->o_obdmd));
717         */
718         return res;
719 }
720
721
722 #ifdef __KERNEL__
723 int obd_register_type(struct obd_ops *ops, char *nm);
724 int obd_unregister_type(char *nm);
725 int obd_class_name2dev(char *name);
726 int obd_class_uuid2dev(char *name);
727
728
729 struct obd_prealloc_inode {
730         struct list_head obd_prealloc_chain;
731         unsigned long inode;
732 };
733
734 /* generic operations shared by various OBD types */
735 int gen_multi_setup(struct obd_device *obddev, uint32_t len, void *data);
736 int gen_multi_cleanup(struct obd_device *obddev);
737 int gen_multi_attach(struct obd_device *obddev, uint32_t len, void *data);
738 int gen_multi_detach(struct obd_device *obddev);
739 int gen_connect (struct obd_conn *conn, struct obd_device *obd);
740 int gen_disconnect(struct obd_conn *conn);
741 struct obd_export *gen_client(struct obd_conn *);
742 int gen_cleanup(struct obd_device *obddev);
743 int gen_copy_data(struct obd_conn *dst_conn, struct obdo *dst,
744                   struct obd_conn *src_conn, struct obdo *src,
745                   obd_size count, obd_off offset);
746
747 #endif
748
749 /* sysctl.c */
750 extern void obd_sysctl_init (void);
751 extern void obd_sysctl_clean (void);
752
753 #endif /* __LINUX_CLASS_OBD_H */