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