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