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