Whamcloud - gitweb
* Pass the connecting client's UUID (NB: not the _connection_'s UUID, the
[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 #include <linux/lustre_mds.h>
43 #endif
44
45
46 /*
47  *  ======== OBD Device Declarations ===========
48  */
49 #define MAX_OBD_DEVICES 128
50 extern struct obd_device obd_dev[MAX_OBD_DEVICES];
51
52 #define OBD_ATTACHED 0x1
53 #define OBD_SET_UP   0x2
54
55 extern struct proc_dir_entry *
56 proc_lustre_register_obd_device(struct obd_device *obd);
57 extern void proc_lustre_release_obd_device(struct obd_device *obd);
58 extern void proc_lustre_remove_obd_entry(const char* name,
59                                          struct obd_device *obd);
60
61 /*
62  *  ======== OBD Operations Declarations ===========
63  */
64
65 #ifdef __KERNEL__
66 extern struct obd_export *class_conn2export(struct lustre_handle *conn);
67 extern struct obd_device *class_conn2obd(struct lustre_handle *conn);
68 extern int class_rconn2export(struct lustre_handle *conn,
69                               struct lustre_handle *rconn);
70
71 struct obd_export {
72         __u64 exp_cookie;
73         struct lustre_handle      exp_rconnh;     /* remote connection handle */
74         struct lustre_handle      exp_impconnh;
75         struct list_head          exp_chain;
76         struct obd_device        *exp_obd;
77         struct ptlrpc_connection *exp_connection;
78         struct mds_export_data    exp_mds_data;
79 #if NOTYET && 0
80         struct ldlm_export_data   exp_ldlm_data;
81         struct ost_export_data    exp_ost_data;
82 #endif
83         void                     *exp_data; /* device specific data */
84         int                       exp_desclen;
85         char                     *exp_desc;
86         uuid_t                    exp_uuid;
87 };
88
89 struct obd_import {
90         __u64 imp_cookie;
91         struct lustre_handle imp_expconnh;
92         struct list_head imp_chain;
93         struct obd_device *imp_obd;
94         unsigned int imp_id;
95         void *imp_data; /* device specific data */
96 };
97
98 static inline int obd_check_conn(struct lustre_handle *conn) 
99 {
100         struct obd_device *obd;
101         if (!conn) {
102                 CERROR("NULL conn\n");
103                 RETURN(-ENOTCONN);
104         }
105         obd = class_conn2obd(conn);
106         if (!obd) {
107                 CERROR("NULL obd\n");
108                 RETURN(-ENODEV);
109         }
110
111         if (!obd->obd_flags & OBD_ATTACHED ) {
112                 CERROR("obd %d not attached\n", obd->obd_minor);
113                 RETURN(-ENODEV);
114         }
115
116         if (!obd->obd_flags & OBD_SET_UP) {
117                 CERROR("obd %d not setup\n", obd->obd_minor); 
118                 RETURN(-ENODEV);
119         }
120
121         if (!obd->obd_type) {
122                 CERROR("obd %d not typed\n", obd->obd_minor);
123                 RETURN(-ENODEV);
124         }
125
126         if (!obd->obd_type->typ_ops) {
127                 CERROR("obd_check_conn: obd %d no operations\n",
128                        obd->obd_minor);
129                 RETURN(-EOPNOTSUPP);
130         }
131         return 0;
132 }
133
134
135 #define OBT(dev)        (dev)->obd_type
136 #define OBP(dev,op)     (dev)->obd_type->typ_ops->o_ ## op
137
138 #define OBD_CHECK_SETUP(conn, export)                           \
139 do {                                                            \
140         if (!(conn)) {                                          \
141                 CERROR("NULL connection\n");                    \
142                 RETURN(-EINVAL);                                \
143         }                                                       \
144                                                                 \
145         export = class_conn2export(conn);                       \
146         if (!(export)) {                                        \
147                 CERROR("No export\n");                          \
148                 RETURN(-EINVAL);                                \
149         }                                                       \
150                                                                 \
151         if (!((export)->exp_obd->obd_flags & OBD_SET_UP)) {     \
152                 CERROR("Device %d not setup\n",                 \
153                        (export)->exp_obd->obd_minor);           \
154                 RETURN(-EINVAL);                                \
155         }                                                       \
156 } while (0)
157
158 #define OBD_CHECK_DEVSETUP(obd)                                 \
159 do {                                                            \
160         if (!(obd)) {                                           \
161                 CERROR("NULL device\n");                        \
162                 RETURN(-EINVAL);                                \
163         }                                                       \
164                                                                 \
165         if ( !((obd)->obd_flags & OBD_SET_UP) ) {               \
166                 CERROR("Device %d not setup\n",                 \
167                        (obd)->obd_minor);                       \
168                 RETURN(-EINVAL);                                \
169         }                                                       \
170 } while (0)
171
172 #define OBD_CHECK_OP(obd,op)                                   \
173 do {                                                            \
174         if (!OBP((obd),op)) {                                   \
175                 CERROR("obd_" #op ": dev %d no operation\n",    \
176                        obd->obd_minor);                         \
177                 RETURN(-EOPNOTSUPP);                            \
178         }                                                       \
179 } while (0)
180
181 static inline int obd_get_info(struct lustre_handle *conn, obd_count keylen,
182                                void *key, obd_count *vallen, void **val)
183 {
184         int rc;
185         struct obd_export *export;
186         OBD_CHECK_SETUP(conn, export);
187         OBD_CHECK_OP(export->exp_obd,get_info);
188
189         rc = OBP(export->exp_obd, get_info)(conn, keylen, key, vallen, val);
190         RETURN(rc);
191 }
192
193 static inline int obd_set_info(struct lustre_handle *conn, obd_count keylen,
194                                void *key, obd_count vallen, void *val)
195 {
196         int rc;
197         struct obd_export *export;
198         OBD_CHECK_SETUP(conn, export);
199         OBD_CHECK_OP(export->exp_obd,set_info);
200
201         rc = OBP(export->exp_obd, set_info)(conn, keylen, key, vallen, val);
202         RETURN(rc);
203 }
204
205 static inline int obd_setup(struct obd_device *obd, int datalen, void *data)
206 {
207         int rc;
208
209         OBD_CHECK_OP(obd,setup);
210
211         rc = OBP(obd, setup)(obd, datalen, data);
212         RETURN(rc);
213 }
214
215 static inline int obd_cleanup(struct obd_device *obd)
216 {
217         int rc;
218
219         OBD_CHECK_DEVSETUP(obd);
220         OBD_CHECK_OP(obd,cleanup);
221
222         rc = OBP(obd, cleanup)(obd);
223         RETURN(rc);
224 }
225
226 static inline int obd_create(struct lustre_handle *conn, struct obdo *obdo, struct lov_stripe_md **ea)
227 {
228         int rc;
229         struct obd_export *export;
230         OBD_CHECK_SETUP(conn, export);
231         OBD_CHECK_OP(export->exp_obd,create);
232
233         rc = OBP(export->exp_obd, create)(conn, obdo, ea);
234         RETURN(rc);
235 }
236
237 static inline int obd_destroy(struct lustre_handle *conn, struct obdo *obdo, struct lov_stripe_md *ea)
238 {
239         int rc;
240         struct obd_export *export;
241         OBD_CHECK_SETUP(conn, export);
242         OBD_CHECK_OP(export->exp_obd,destroy);
243
244         rc = OBP(export->exp_obd, destroy)(conn, obdo, ea);
245         RETURN(rc);
246 }
247
248 static inline int obd_getattr(struct lustre_handle *conn, 
249                               struct obdo *obdo,
250                               struct lov_stripe_md *ea)
251 {
252         int rc;
253         struct obd_export *export;
254         OBD_CHECK_SETUP(conn, export);
255         OBD_CHECK_OP(export->exp_obd,getattr);
256
257         rc = OBP(export->exp_obd, getattr)(conn, obdo, ea);
258         RETURN(rc);
259 }
260
261 static inline int obd_close(struct lustre_handle *conn, struct obdo *obdo, struct lov_stripe_md *md)
262 {
263         int rc;
264         struct obd_export *export;
265         OBD_CHECK_SETUP(conn, export);
266         OBD_CHECK_OP(export->exp_obd,close);
267
268         rc = OBP(export->exp_obd, close)(conn, obdo, md);
269         RETURN(rc);
270 }
271 static inline int obd_open(struct lustre_handle *conn, struct obdo *obdo, 
272                            struct lov_stripe_md *md)
273 {
274         int rc;
275         struct obd_export *export;
276         OBD_CHECK_SETUP(conn, export);
277         OBD_CHECK_OP(export->exp_obd,open);
278
279         rc = OBP(export->exp_obd, open) (conn, obdo, md);
280         RETURN(rc);
281 }
282
283 static inline int obd_setattr(struct lustre_handle *conn, 
284                               struct obdo *obdo,
285                               struct lov_stripe_md *ea)
286 {
287         int rc;
288         struct obd_export *export;
289         OBD_CHECK_SETUP(conn, export);
290         OBD_CHECK_OP(export->exp_obd,setattr);
291
292         rc = OBP(export->exp_obd, setattr)(conn, obdo, ea);
293         RETURN(rc);
294 }
295
296 static inline int obd_connect(struct lustre_handle *conn, struct obd_device *obd,
297                               char *cluuid)
298 {
299         int rc;
300         OBD_CHECK_DEVSETUP(obd);
301         OBD_CHECK_OP(obd,connect);
302
303         rc = OBP(obd, connect)(conn, obd, cluuid);
304         RETURN(rc);
305 }
306
307 static inline int obd_disconnect(struct lustre_handle *conn)
308 {
309         int rc;
310         struct obd_export *export;
311         OBD_CHECK_SETUP(conn, export);
312         OBD_CHECK_OP(export->exp_obd,disconnect);
313
314         rc = OBP(export->exp_obd, disconnect)(conn);
315         RETURN(rc);
316 }
317
318 static inline int obd_statfs(struct lustre_handle *conn, struct statfs *buf)
319 {
320         int rc;
321         struct obd_export *export;
322         OBD_CHECK_SETUP(conn, export);
323         OBD_CHECK_OP(export->exp_obd,statfs);
324
325         rc = OBP(export->exp_obd, statfs)(conn, buf);
326         RETURN(rc);
327 }
328
329 static inline int obd_punch(struct lustre_handle *conn, struct obdo *tgt,
330                             struct lov_stripe_md *md, 
331                             obd_size count, obd_off offset)
332 {
333         int rc;
334         struct obd_export *export;
335         OBD_CHECK_SETUP(conn, export);
336         OBD_CHECK_OP(export->exp_obd,punch);
337
338         rc = OBP(export->exp_obd, punch)(conn, tgt, md, count, offset);
339         RETURN(rc);
340 }
341
342 static inline int obd_brw(int cmd, struct lustre_handle *conn, 
343                           struct lov_stripe_md *md, 
344                           obd_count oa_bufs,
345                           struct page **buf, 
346                           obd_size *count, 
347                           obd_off *offset,
348                           obd_flag *flags, 
349                           brw_callback_t callback, void *data)
350 {
351         int rc;
352         struct obd_export *export;
353         OBD_CHECK_SETUP(conn, export);
354         OBD_CHECK_OP(export->exp_obd,brw);
355
356         if (!(cmd & OBD_BRW_RWMASK)) {
357                 CERROR("obd_brw: cmd must be OBD_BRW_READ or OBD_BRW_WRITE\n");
358                 LBUG();
359         }
360
361         rc = OBP(export->exp_obd, brw)(cmd, conn, md, oa_bufs, buf,
362                                        count, offset, flags, callback, data);
363         RETURN(rc);
364 }
365
366 static inline int obd_preprw(int cmd, struct lustre_handle *conn,
367                              int objcount, struct obd_ioobj *obj,
368                              int niocount, struct niobuf_remote *remote,
369                              struct niobuf_local *local, void **desc_private)
370 {
371         int rc;
372         struct obd_export *export;
373         OBD_CHECK_SETUP(conn, export);
374         OBD_CHECK_OP(export->exp_obd,preprw);
375
376         rc = OBP(export->exp_obd, preprw)(cmd, conn, objcount, obj, niocount,
377                                        remote, local, desc_private);
378         RETURN(rc);
379 }
380
381 static inline int obd_commitrw(int cmd, struct lustre_handle *conn,
382                                int objcount, struct obd_ioobj *obj,
383                                int niocount, struct niobuf_local *local,
384                                void *desc_private)
385 {
386         int rc;
387         struct obd_export *export;
388         OBD_CHECK_SETUP(conn, export);
389         OBD_CHECK_OP(export->exp_obd,commitrw);
390
391         rc = OBP(export->exp_obd, commitrw)(cmd, conn, objcount, obj, niocount,
392                                          local, desc_private);
393         RETURN(rc);
394 }
395
396 static inline int obd_iocontrol(int cmd, struct lustre_handle *conn,
397                                 int len, void *karg, void *uarg)
398 {
399         int rc;
400         struct obd_export *export;
401         OBD_CHECK_SETUP(conn, export);
402         OBD_CHECK_OP(export->exp_obd,iocontrol);
403
404         rc = OBP(export->exp_obd, iocontrol)(cmd, conn, len, karg, uarg);
405         RETURN(rc);
406 }
407
408 static inline int obd_enqueue(struct lustre_handle *conn,
409                               struct lustre_handle *parent_lock, __u64 *res_id,
410                               __u32 type, void *cookie, int cookielen,
411                               __u32 mode, int *flags, void *cb, void *data,
412                               int datalen, struct lustre_handle *lockh)
413 {
414         int rc;
415         struct obd_export *export;
416         OBD_CHECK_SETUP(conn, export);
417         OBD_CHECK_OP(export->exp_obd,enqueue);
418
419         rc = OBP(export->exp_obd, enqueue)(conn, parent_lock, res_id, type,
420                                         cookie, cookielen, mode, flags, cb,
421                                         data, datalen, lockh);
422         RETURN(rc);
423 }
424
425 static inline int obd_cancel(struct lustre_handle *conn, __u32 mode,
426                              struct lustre_handle *lockh)
427 {
428         int rc;
429         struct obd_export *export;
430         OBD_CHECK_SETUP(conn, export);
431         OBD_CHECK_OP(export->exp_obd,cancel);
432
433         rc = OBP(export->exp_obd, cancel)(conn, mode, lockh);
434         RETURN(rc);
435 }
436
437 #endif 
438
439 /*
440  *  ======== OBD Metadata Support  ===========
441  */
442
443 extern int obd_init_caches(void);
444 extern void obd_cleanup_caches(void);
445
446 static inline int obdo_has_inline(struct obdo *obdo)
447 {
448         return (obdo->o_valid & OBD_MD_FLINLINE &&
449                 obdo->o_obdflags & OBD_FL_INLINEDATA);
450 };
451
452 #ifdef __KERNEL__
453 /* support routines */
454 extern kmem_cache_t *obdo_cachep;
455 static inline struct obdo *obdo_alloc(void)
456 {
457         struct obdo *oa = NULL;
458
459         oa = kmem_cache_alloc(obdo_cachep, SLAB_KERNEL);
460         if (oa == NULL)
461                 LBUG();
462         memset(oa, 0, sizeof (*oa));
463
464         return oa;
465 }
466 static inline void obdo_free(struct obdo *oa)
467 {
468         if (!oa)
469                 return;
470         kmem_cache_free(obdo_cachep, oa);
471 }
472
473
474 static inline void obdo_from_iattr(struct obdo *oa, struct iattr *attr)
475 {
476         unsigned int ia_valid = attr->ia_valid;
477
478         if (ia_valid & ATTR_ATIME) {
479                 oa->o_atime = attr->ia_atime;
480                 oa->o_valid |= OBD_MD_FLATIME;
481         }
482         if (ia_valid & ATTR_MTIME) {
483                 oa->o_mtime = attr->ia_mtime;
484                 oa->o_valid |= OBD_MD_FLMTIME;
485         }
486         if (ia_valid & ATTR_CTIME) {
487                 oa->o_ctime = attr->ia_ctime;
488                 oa->o_valid |= OBD_MD_FLCTIME;
489         }
490         if (ia_valid & ATTR_SIZE) {
491                 oa->o_size = attr->ia_size;
492                 oa->o_valid |= OBD_MD_FLSIZE;
493         }
494         if (ia_valid & ATTR_MODE) {
495                 oa->o_mode = attr->ia_mode;
496                 oa->o_valid |= OBD_MD_FLMODE;
497                 if (!in_group_p(oa->o_gid) && !capable(CAP_FSETID))
498                         oa->o_mode &= ~S_ISGID;
499         }
500         if (ia_valid & ATTR_UID)
501         {
502                 oa->o_uid = attr->ia_uid;
503                 oa->o_valid |= OBD_MD_FLUID;
504         }
505         if (ia_valid & ATTR_GID) {
506                 oa->o_gid = attr->ia_gid;
507                 oa->o_valid |= OBD_MD_FLGID;
508         }
509 }
510
511
512 static inline void iattr_from_obdo(struct iattr *attr, struct obdo *oa)
513 {
514         unsigned int ia_valid = oa->o_valid;
515
516         memset(attr, 0, sizeof(*attr));
517         if (ia_valid & OBD_MD_FLATIME) {
518                 attr->ia_atime = oa->o_atime;
519                 attr->ia_valid |= ATTR_ATIME;
520         }
521         if (ia_valid & OBD_MD_FLMTIME) {
522                 attr->ia_mtime = oa->o_mtime;
523                 attr->ia_valid |= ATTR_MTIME;
524         }
525         if (ia_valid & OBD_MD_FLCTIME) {
526                 attr->ia_ctime = oa->o_ctime;
527                 attr->ia_valid |= ATTR_CTIME;
528         }
529         if (ia_valid & OBD_MD_FLSIZE) {
530                 attr->ia_size = oa->o_size;
531                 attr->ia_valid |= ATTR_SIZE;
532         }
533         if (ia_valid & OBD_MD_FLMODE) {
534                 attr->ia_mode = oa->o_mode;
535                 attr->ia_valid |= ATTR_MODE;
536                 if (!in_group_p(oa->o_gid) && !capable(CAP_FSETID))
537                         attr->ia_mode &= ~S_ISGID;
538         }
539         if (ia_valid & OBD_MD_FLUID)
540         {
541                 attr->ia_uid = oa->o_uid;
542                 attr->ia_valid |= ATTR_UID;
543         }
544         if (ia_valid & OBD_MD_FLGID) {
545                 attr->ia_gid = oa->o_gid;
546                 attr->ia_valid |= ATTR_GID;
547         }
548 }
549
550
551 /* WARNING: the file systems must take care not to tinker with
552    attributes they don't manage (such as blocks). */
553
554 static inline void obdo_from_inode(struct obdo *dst, struct inode *src)
555 {
556         if ( dst->o_valid & OBD_MD_FLID )
557                 dst->o_id = src->i_ino;
558         if ( dst->o_valid & OBD_MD_FLATIME )
559                 dst->o_atime = src->i_atime;
560         if ( dst->o_valid & OBD_MD_FLMTIME )
561                 dst->o_mtime = src->i_mtime;
562         if ( dst->o_valid & OBD_MD_FLCTIME )
563                 dst->o_ctime = src->i_ctime;
564         if ( dst->o_valid & OBD_MD_FLSIZE )
565                 dst->o_size = src->i_size;
566         if ( dst->o_valid & OBD_MD_FLBLOCKS )   /* allocation of space */
567                 dst->o_blocks = src->i_blocks;
568         if ( dst->o_valid & OBD_MD_FLBLKSZ )
569                 dst->o_blksize = src->i_blksize;
570         if ( dst->o_valid & OBD_MD_FLMODE )
571                 dst->o_mode = src->i_mode;
572         if ( dst->o_valid & OBD_MD_FLUID )
573                 dst->o_uid = src->i_uid;
574         if ( dst->o_valid & OBD_MD_FLGID )
575                 dst->o_gid = src->i_gid;
576         if ( dst->o_valid & OBD_MD_FLFLAGS )
577                 dst->o_flags = src->i_flags;
578         if ( dst->o_valid & OBD_MD_FLNLINK )
579                 dst->o_nlink = src->i_nlink;
580         if ( dst->o_valid & OBD_MD_FLGENER ) 
581                 dst->o_generation = src->i_generation;
582         if ( dst->o_valid & OBD_MD_FLRDEV ) 
583                 dst->o_rdev = src->i_rdev;
584 }
585
586 static inline void obdo_to_inode(struct inode *dst, struct obdo *src)
587 {
588
589         if ( src->o_valid & OBD_MD_FLID )
590                 dst->i_ino = src->o_id;
591         if ( src->o_valid & OBD_MD_FLATIME ) 
592                 dst->i_atime = src->o_atime;
593         if ( src->o_valid & OBD_MD_FLMTIME ) 
594                 dst->i_mtime = src->o_mtime;
595         if ( src->o_valid & OBD_MD_FLCTIME ) 
596                 dst->i_ctime = src->o_ctime;
597         if ( src->o_valid & OBD_MD_FLSIZE ) 
598                 dst->i_size = src->o_size;
599         if ( src->o_valid & OBD_MD_FLBLOCKS ) /* allocation of space */
600                 dst->i_blocks = src->o_blocks;
601         if ( src->o_valid & OBD_MD_FLBLKSZ )
602                 dst->i_blksize = src->o_blksize;
603         if ( src->o_valid & OBD_MD_FLMODE ) 
604                 dst->i_mode = src->o_mode;
605         if ( src->o_valid & OBD_MD_FLUID ) 
606                 dst->i_uid = src->o_uid;
607         if ( src->o_valid & OBD_MD_FLGID ) 
608                 dst->i_gid = src->o_gid;
609         if ( src->o_valid & OBD_MD_FLFLAGS ) 
610                 dst->i_flags = src->o_flags;
611         if ( src->o_valid & OBD_MD_FLNLINK )
612                 dst->i_nlink = src->o_nlink;
613         if ( src->o_valid & OBD_MD_FLGENER )
614                 dst->i_generation = src->o_generation;
615         if ( src->o_valid & OBD_MD_FLRDEV )
616                 dst->i_rdev = src->o_rdev;
617 }
618
619 #endif 
620
621 static inline void obdo_cpy_md(struct obdo *dst, struct obdo *src)
622 {
623 #ifdef __KERNEL__
624         CDEBUG(D_INODE, "src obdo %Ld valid 0x%x, dst obdo %Ld\n",
625                (unsigned long long)src->o_id, src->o_valid,
626                (unsigned long long)dst->o_id);
627 #endif
628         if ( src->o_valid & OBD_MD_FLATIME ) 
629                 dst->o_atime = src->o_atime;
630         if ( src->o_valid & OBD_MD_FLMTIME ) 
631                 dst->o_mtime = src->o_mtime;
632         if ( src->o_valid & OBD_MD_FLCTIME ) 
633                 dst->o_ctime = src->o_ctime;
634         if ( src->o_valid & OBD_MD_FLSIZE ) 
635                 dst->o_size = src->o_size;
636         if ( src->o_valid & OBD_MD_FLBLOCKS ) /* allocation of space */
637                 dst->o_blocks = src->o_blocks;
638         if ( src->o_valid & OBD_MD_FLBLKSZ )
639                 dst->o_blksize = src->o_blksize;
640         if ( src->o_valid & OBD_MD_FLMODE ) 
641                 dst->o_mode = src->o_mode;
642         if ( src->o_valid & OBD_MD_FLUID ) 
643                 dst->o_uid = src->o_uid;
644         if ( src->o_valid & OBD_MD_FLGID ) 
645                 dst->o_gid = src->o_gid;
646         if ( src->o_valid & OBD_MD_FLFLAGS ) 
647                 dst->o_flags = src->o_flags;
648         /*
649         if ( src->o_valid & OBD_MD_FLOBDFLG ) 
650                 dst->o_obdflags = src->o_obdflags;
651         */
652         if ( src->o_valid & OBD_MD_FLNLINK ) 
653                 dst->o_nlink = src->o_nlink;
654         if ( src->o_valid & OBD_MD_FLGENER ) 
655                 dst->o_generation = src->o_generation;
656         if ( src->o_valid & OBD_MD_FLRDEV ) 
657                 dst->o_rdev = src->o_rdev;
658         if ( src->o_valid & OBD_MD_FLINLINE &&
659              src->o_obdflags & OBD_FL_INLINEDATA) {
660                 memcpy(dst->o_inline, src->o_inline, sizeof(src->o_inline));
661                 dst->o_obdflags |= OBD_FL_INLINEDATA;
662         }
663
664         dst->o_valid |= src->o_valid;
665 }
666
667
668 /* returns FALSE if comparison (by flags) is same, TRUE if changed */
669 static inline int obdo_cmp_md(struct obdo *dst, struct obdo *src,
670                               obd_flag compare)
671 {
672         int res = 0;
673
674         if ( compare & OBD_MD_FLATIME )
675                 res = (res || (dst->o_atime != src->o_atime));
676         if ( compare & OBD_MD_FLMTIME )
677                 res = (res || (dst->o_mtime != src->o_mtime));
678         if ( compare & OBD_MD_FLCTIME )
679                 res = (res || (dst->o_ctime != src->o_ctime));
680         if ( compare & OBD_MD_FLSIZE )
681                 res = (res || (dst->o_size != src->o_size));
682         if ( compare & OBD_MD_FLBLOCKS ) /* allocation of space */
683                 res = (res || (dst->o_blocks != src->o_blocks));
684         if ( compare & OBD_MD_FLBLKSZ )
685                 res = (res || (dst->o_blksize != src->o_blksize));
686         if ( compare & OBD_MD_FLMODE )
687                 res = (res || (dst->o_mode != src->o_mode));
688         if ( compare & OBD_MD_FLUID )
689                 res = (res || (dst->o_uid != src->o_uid));
690         if ( compare & OBD_MD_FLGID )
691                 res = (res || (dst->o_gid != src->o_gid));
692         if ( compare & OBD_MD_FLFLAGS ) 
693                 res = (res || (dst->o_flags != src->o_flags));
694         if ( compare & OBD_MD_FLNLINK )
695                 res = (res || (dst->o_nlink != src->o_nlink));
696         if ( compare & OBD_MD_FLGENER )
697                 res = (res || (dst->o_generation != src->o_generation));
698         /* XXX Don't know if thses should be included here - wasn't previously
699         if ( compare & OBD_MD_FLINLINE )
700                 res = (res || memcmp(dst->o_inline, src->o_inline));
701         */
702         return res;
703 }
704
705
706 #ifdef __KERNEL__
707 int class_register_type(struct obd_ops *ops, char *nm);
708 int class_unregister_type(char *nm);
709 int class_name2dev(char *name);
710 int class_uuid2dev(char *name);
711 struct obd_device *class_uuid2obd(char *name);
712 struct obd_export *class_new_export(struct obd_device *obddev);
713 int class_connect(struct lustre_handle *conn, struct obd_device *obd,
714                   char *cluuid);
715 int class_disconnect(struct lustre_handle *conn);
716 struct obd_export *class_conn2export(struct lustre_handle *);
717
718 /* generic operations shared by various OBD types */
719 int class_multi_setup(struct obd_device *obddev, uint32_t len, void *data);
720 int class_multi_cleanup(struct obd_device *obddev);
721
722
723 #endif
724
725 /* sysctl.c */
726 extern void obd_sysctl_init (void);
727 extern void obd_sysctl_clean (void);
728
729 #endif /* __LINUX_CLASS_OBD_H */