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