Whamcloud - gitweb
- fix rdev stuff
[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;
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
484 static inline void obdo_free(struct obdo *oa)
485 {
486         if (!oa)
487                 return;
488         kmem_cache_free(obdo_cachep, oa);
489 }
490
491 extern kmem_cache_t *handle_cachep;
492 static inline struct lustre_handle *handle_alloc(void)
493 {
494         struct lustre_handle *handle;
495
496         handle = kmem_cache_alloc(handle_cachep, SLAB_KERNEL);
497         memset(handle, 0, sizeof (*handle));
498
499         return handle;
500 }
501
502 static inline void handle_free(struct lustre_handle *handle)
503 {
504         if (!handle)
505                 return;
506         kmem_cache_free(handle_cachep, handle);
507 }
508
509
510 static inline void obdo_from_iattr(struct obdo *oa, struct iattr *attr)
511 {
512         unsigned int ia_valid = attr->ia_valid;
513
514         if (ia_valid & ATTR_ATIME) {
515                 oa->o_atime = attr->ia_atime;
516                 oa->o_valid |= OBD_MD_FLATIME;
517         }
518         if (ia_valid & ATTR_MTIME) {
519                 oa->o_mtime = attr->ia_mtime;
520                 oa->o_valid |= OBD_MD_FLMTIME;
521         }
522         if (ia_valid & ATTR_CTIME) {
523                 oa->o_ctime = attr->ia_ctime;
524                 oa->o_valid |= OBD_MD_FLCTIME;
525         }
526         if (ia_valid & ATTR_SIZE) {
527                 oa->o_size = attr->ia_size;
528                 oa->o_valid |= OBD_MD_FLSIZE;
529         }
530         if (ia_valid & ATTR_MODE) {
531                 oa->o_mode = attr->ia_mode;
532                 oa->o_valid |= OBD_MD_FLTYPE | OBD_MD_FLMODE;
533                 if (!in_group_p(oa->o_gid) && !capable(CAP_FSETID))
534                         oa->o_mode &= ~S_ISGID;
535         }
536         if (ia_valid & ATTR_UID) {
537                 oa->o_uid = attr->ia_uid;
538                 oa->o_valid |= OBD_MD_FLUID;
539         }
540         if (ia_valid & ATTR_GID) {
541                 oa->o_gid = attr->ia_gid;
542                 oa->o_valid |= OBD_MD_FLGID;
543         }
544 }
545
546
547 static inline void iattr_from_obdo(struct iattr *attr, struct obdo *oa,
548                                    obd_flag valid)
549 {
550         memset(attr, 0, sizeof(*attr));
551         if (valid & OBD_MD_FLATIME) {
552                 attr->ia_atime = oa->o_atime;
553                 attr->ia_valid |= ATTR_ATIME;
554         }
555         if (valid & OBD_MD_FLMTIME) {
556                 attr->ia_mtime = oa->o_mtime;
557                 attr->ia_valid |= ATTR_MTIME;
558         }
559         if (valid & OBD_MD_FLCTIME) {
560                 attr->ia_ctime = oa->o_ctime;
561                 attr->ia_valid |= ATTR_CTIME;
562         }
563         if (valid & OBD_MD_FLSIZE) {
564                 attr->ia_size = oa->o_size;
565                 attr->ia_valid |= ATTR_SIZE;
566         }
567         if (valid & OBD_MD_FLTYPE) {
568                 attr->ia_mode = (attr->ia_mode & ~S_IFMT)|(oa->o_mode & S_IFMT);
569                 attr->ia_valid |= ATTR_MODE;
570         }
571         if (valid & OBD_MD_FLMODE) {
572                 attr->ia_mode = (attr->ia_mode & S_IFMT)|(oa->o_mode & ~S_IFMT);
573                 attr->ia_valid |= ATTR_MODE;
574                 if (!in_group_p(oa->o_gid) && !capable(CAP_FSETID))
575                         attr->ia_mode &= ~S_ISGID;
576         }
577         if (valid & OBD_MD_FLUID)
578         {
579                 attr->ia_uid = oa->o_uid;
580                 attr->ia_valid |= ATTR_UID;
581         }
582         if (valid & OBD_MD_FLGID) {
583                 attr->ia_gid = oa->o_gid;
584                 attr->ia_valid |= ATTR_GID;
585         }
586 }
587
588
589 /* WARNING: the file systems must take care not to tinker with
590    attributes they don't manage (such as blocks). */
591
592 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
593 #define to_kdev_t(dev) dev
594 #define kdev_t_to_nr(dev) dev
595 #endif
596
597 static inline void obdo_from_inode(struct obdo *dst, struct inode *src,
598                                    obd_flag valid)
599 {
600 //        if (valid & OBD_MD_FLID)
601 //                dst->o_id = src->i_ino;
602         if (valid & OBD_MD_FLATIME)
603                 dst->o_atime = src->i_atime;
604         if (valid & OBD_MD_FLMTIME)
605                 dst->o_mtime = src->i_mtime;
606         if (valid & OBD_MD_FLCTIME)
607                 dst->o_ctime = src->i_ctime;
608         if (valid & OBD_MD_FLSIZE)
609                 dst->o_size = src->i_size;
610         if (valid & OBD_MD_FLBLOCKS)   /* allocation of space */
611                 dst->o_blocks = src->i_blocks;
612         if (valid & OBD_MD_FLBLKSZ)
613                 dst->o_blksize = src->i_blksize;
614         if (valid & OBD_MD_FLTYPE)
615                 dst->o_mode = (dst->o_mode & ~S_IFMT) | (src->i_mode & S_IFMT);
616         if (valid & OBD_MD_FLMODE)
617                 dst->o_mode = (dst->o_mode & S_IFMT) | (src->i_mode & ~S_IFMT);
618         if (valid & OBD_MD_FLUID)
619                 dst->o_uid = src->i_uid;
620         if (valid & OBD_MD_FLGID)
621                 dst->o_gid = src->i_gid;
622         if (valid & OBD_MD_FLFLAGS)
623                 dst->o_flags = src->i_flags;
624         if (valid & OBD_MD_FLNLINK)
625                 dst->o_nlink = src->i_nlink;
626         if (valid & OBD_MD_FLGENER)
627                 dst->o_generation = src->i_generation;
628         if (valid & OBD_MD_FLRDEV)
629                 dst->o_rdev = (__u32)kdev_t_to_nr(src->i_rdev);
630
631         dst->o_valid |= (valid & ~OBD_MD_FLID);
632 }
633
634 static inline void obdo_to_inode(struct inode *dst, struct obdo *src,
635                                  obd_flag valid)
636 {
637 //        if (valid & OBD_MD_FLID)
638 //                dst->i_ino = src->o_id;
639         if (valid & OBD_MD_FLATIME)
640                 dst->i_atime = src->o_atime;
641         if (valid & OBD_MD_FLMTIME)
642                 dst->i_mtime = src->o_mtime;
643         if (valid & OBD_MD_FLCTIME)
644                 dst->i_ctime = src->o_ctime;
645         if (valid & OBD_MD_FLSIZE)
646                 dst->i_size = src->o_size;
647         if (valid & OBD_MD_FLBLOCKS) /* allocation of space */
648                 dst->i_blocks = src->o_blocks;
649         if (valid & OBD_MD_FLBLKSZ)
650                 dst->i_blksize = src->o_blksize;
651         if (valid & OBD_MD_FLTYPE)
652                 dst->i_mode = (dst->i_mode & ~S_IFMT) | (src->o_mode & S_IFMT);
653         if (valid & OBD_MD_FLMODE)
654                 dst->i_mode = (dst->i_mode & S_IFMT) | (src->o_mode & ~S_IFMT);
655         if (valid & OBD_MD_FLUID)
656                 dst->i_uid = src->o_uid;
657         if (valid & OBD_MD_FLGID)
658                 dst->i_gid = src->o_gid;
659         if (valid & OBD_MD_FLFLAGS)
660                 dst->i_flags = src->o_flags;
661         if (valid & OBD_MD_FLNLINK)
662                 dst->i_nlink = src->o_nlink;
663         if (valid & OBD_MD_FLGENER)
664                 dst->i_generation = src->o_generation;
665         if (valid & OBD_MD_FLRDEV)
666                 dst->i_rdev = to_kdev_t(src->o_rdev);
667 }
668 #endif
669
670 static inline void obdo_cpy_md(struct obdo *dst, struct obdo *src,
671                                obd_flag valid)
672 {
673 #ifdef __KERNEL__
674         CDEBUG(D_INODE, "src obdo %Ld valid 0x%x, dst obdo %Ld\n",
675                (unsigned long long)src->o_id, src->o_valid,
676                (unsigned long long)dst->o_id);
677 #endif
678         if (valid & OBD_MD_FLATIME)
679                 dst->o_atime = src->o_atime;
680         if (valid & OBD_MD_FLMTIME)
681                 dst->o_mtime = src->o_mtime;
682         if (valid & OBD_MD_FLCTIME)
683                 dst->o_ctime = src->o_ctime;
684         if (valid & OBD_MD_FLSIZE)
685                 dst->o_size = src->o_size;
686         if (valid & OBD_MD_FLBLOCKS) /* allocation of space */
687                 dst->o_blocks = src->o_blocks;
688         if (valid & OBD_MD_FLBLKSZ)
689                 dst->o_blksize = src->o_blksize;
690         if (valid & OBD_MD_FLTYPE)
691                 dst->o_mode = (dst->o_mode & ~S_IFMT) | (src->o_mode & S_IFMT);
692         if (valid & OBD_MD_FLMODE)
693                 dst->o_mode = (dst->o_mode & S_IFMT) | (src->o_mode & ~S_IFMT);
694         if (valid & OBD_MD_FLUID)
695                 dst->o_uid = src->o_uid;
696         if (valid & OBD_MD_FLGID)
697                 dst->o_gid = src->o_gid;
698         if (valid & OBD_MD_FLFLAGS)
699                 dst->o_flags = src->o_flags;
700         /*
701         if (valid & OBD_MD_FLOBDFLG)
702                 dst->o_obdflags = src->o_obdflags;
703         */
704         if (valid & OBD_MD_FLNLINK)
705                 dst->o_nlink = src->o_nlink;
706         if (valid & OBD_MD_FLGENER)
707                 dst->o_generation = src->o_generation;
708         if (valid & OBD_MD_FLRDEV)
709                 dst->o_rdev = src->o_rdev;
710         if (valid & OBD_MD_FLINLINE &&
711              src->o_obdflags & OBD_FL_INLINEDATA) {
712                 memcpy(dst->o_inline, src->o_inline, sizeof(src->o_inline));
713                 dst->o_obdflags |= OBD_FL_INLINEDATA;
714         }
715
716         dst->o_valid |= valid;
717 }
718
719
720 /* returns FALSE if comparison (by flags) is same, TRUE if changed */
721 static inline int obdo_cmp_md(struct obdo *dst, struct obdo *src,
722                               obd_flag compare)
723 {
724         int res = 0;
725
726         if ( compare & OBD_MD_FLATIME )
727                 res = (res || (dst->o_atime != src->o_atime));
728         if ( compare & OBD_MD_FLMTIME )
729                 res = (res || (dst->o_mtime != src->o_mtime));
730         if ( compare & OBD_MD_FLCTIME )
731                 res = (res || (dst->o_ctime != src->o_ctime));
732         if ( compare & OBD_MD_FLSIZE )
733                 res = (res || (dst->o_size != src->o_size));
734         if ( compare & OBD_MD_FLBLOCKS ) /* allocation of space */
735                 res = (res || (dst->o_blocks != src->o_blocks));
736         if ( compare & OBD_MD_FLBLKSZ )
737                 res = (res || (dst->o_blksize != src->o_blksize));
738         if ( compare & OBD_MD_FLTYPE )
739                 res = (res || (((dst->o_mode ^ src->o_mode) & S_IFMT) != 0));
740         if ( compare & OBD_MD_FLMODE )
741                 res = (res || (((dst->o_mode ^ src->o_mode) & ~S_IFMT) != 0));
742         if ( compare & OBD_MD_FLUID )
743                 res = (res || (dst->o_uid != src->o_uid));
744         if ( compare & OBD_MD_FLGID )
745                 res = (res || (dst->o_gid != src->o_gid));
746         if ( compare & OBD_MD_FLFLAGS )
747                 res = (res || (dst->o_flags != src->o_flags));
748         if ( compare & OBD_MD_FLNLINK )
749                 res = (res || (dst->o_nlink != src->o_nlink));
750         if ( compare & OBD_MD_FLGENER )
751                 res = (res || (dst->o_generation != src->o_generation));
752         /* XXX Don't know if thses should be included here - wasn't previously
753         if ( compare & OBD_MD_FLINLINE )
754                 res = (res || memcmp(dst->o_inline, src->o_inline));
755         */
756         return res;
757 }
758
759
760 #ifdef __KERNEL__
761 /* I'm as embarrassed about this as you are.
762  *
763  * <shaver> // XXX do not look into _superhack with remaining eye
764  * <shaver> // XXX if this were any uglier, I'd get my own show on MTV */ 
765 extern int (*ptlrpc_put_connection_superhack)(struct ptlrpc_connection *c);
766
767 int class_register_type(struct obd_ops *ops, char *nm);
768 int class_unregister_type(char *nm);
769 int class_name2dev(char *name);
770 int class_uuid2dev(char *uuid);
771 struct obd_device *class_uuid2obd(char *uuid);
772 struct obd_export *class_new_export(struct obd_device *obddev);
773 void class_destroy_export(struct obd_export *exp);
774 int class_connect(struct lustre_handle *conn, struct obd_device *obd,
775                   obd_uuid_t cluuid);
776 int class_disconnect(struct lustre_handle *conn);
777 void class_disconnect_all(struct obd_device *obddev);
778
779 /* generic operations shared by various OBD types */
780 int class_multi_setup(struct obd_device *obddev, uint32_t len, void *data);
781 int class_multi_cleanup(struct obd_device *obddev);
782
783 extern void (*class_signal_connection_failure)(struct ptlrpc_connection *);
784
785 static inline struct ptlrpc_connection *class_rd2conn(struct recovd_data *rd)
786 {
787         /* reuse list_entry's member-pointer offset stuff */
788         return list_entry(rd, struct ptlrpc_connection, c_recovd_data);
789 }
790
791 #endif
792
793 /* sysctl.c */
794 extern void obd_sysctl_init (void);
795 extern void obd_sysctl_clean (void);
796
797 /* uuid.c  */
798 typedef __u8 class_uuid_t[16];
799 //int class_uuid_parse(obd_uuid_t in, class_uuid_t out);
800 void class_uuid_unparse(class_uuid_t in, obd_uuid_t out);
801 #endif /* __LINUX_CLASS_OBD_H */