Whamcloud - gitweb
ed3eb991a9aa79c91fdedbd404221f1e98da2812
[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 #include <linux/lprocfs_status.h>
45 #endif
46
47
48 /* OBD Device Declarations */
49 #define MAX_OBD_DEVICES 128
50 extern struct obd_device obd_dev[MAX_OBD_DEVICES];
51
52 #define OBD_ATTACHED 0x1
53 #define OBD_SET_UP   0x2
54
55 /* OBD Operations Declarations */
56
57 #ifdef __KERNEL__
58 static inline int obd_check_conn(struct lustre_handle *conn)
59 {
60         struct obd_device *obd;
61         if (!conn) {
62                 CERROR("NULL conn\n");
63                 RETURN(-ENOTCONN);
64         }
65         obd = class_conn2obd(conn);
66         if (!obd) {
67                 CERROR("NULL obd\n");
68                 RETURN(-ENODEV);
69         }
70
71         if (!obd->obd_flags & OBD_ATTACHED ) {
72                 CERROR("obd %d not attached\n", obd->obd_minor);
73                 RETURN(-ENODEV);
74         }
75
76         if (!obd->obd_flags & OBD_SET_UP) {
77                 CERROR("obd %d not setup\n", obd->obd_minor);
78                 RETURN(-ENODEV);
79         }
80
81         if (!obd->obd_type) {
82                 CERROR("obd %d not typed\n", obd->obd_minor);
83                 RETURN(-ENODEV);
84         }
85
86         if (!obd->obd_type->typ_ops) {
87                 CERROR("obd_check_conn: obd %d no operations\n",
88                        obd->obd_minor);
89                 RETURN(-EOPNOTSUPP);
90         }
91         return 0;
92 }
93
94
95 #define OBT(dev)        (dev)->obd_type
96 #define OBP(dev, op)    (dev)->obd_type->typ_ops->o_ ## op
97
98 #define OBD_CHECK_SETUP(conn, exp)                              \
99 do {                                                            \
100         if (!(conn)) {                                          \
101                 CERROR("NULL connection\n");                    \
102                 RETURN(-EINVAL);                                \
103         }                                                       \
104                                                                 \
105         exp = class_conn2export(conn);                          \
106         if (!(exp)) {                                           \
107                 CERROR("No export\n");                          \
108                 RETURN(-EINVAL);                                \
109         }                                                       \
110                                                                 \
111         if (!((exp)->exp_obd->obd_flags & OBD_SET_UP)) {        \
112                 CERROR("Device %d not setup\n",                 \
113                        (exp)->exp_obd->obd_minor);              \
114                 RETURN(-EINVAL);                                \
115         }                                                       \
116 } while (0)
117
118 #define OBD_CHECK_DEVSETUP(obd)                                 \
119 do {                                                            \
120         if (!(obd)) {                                           \
121                 CERROR("NULL device\n");                        \
122                 RETURN(-EINVAL);                                \
123         }                                                       \
124                                                                 \
125         if (!((obd)->obd_flags & OBD_SET_UP)) {                 \
126                 CERROR("Device %d not setup\n",                 \
127                        (obd)->obd_minor);                       \
128                 RETURN(-EINVAL);                                \
129         }                                                       \
130 } while (0)
131
132 #define OBD_CHECK_OP(obd, op)                                   \
133 do {                                                            \
134         if (!OBP((obd), op)) {                                  \
135                 CERROR("obd_" #op ": dev %d no operation\n",    \
136                        obd->obd_minor);                         \
137                 RETURN(-EOPNOTSUPP);                            \
138         }                                                       \
139 } while (0)
140
141 static inline int obd_get_info(struct lustre_handle *conn, obd_count keylen,
142                                void *key, obd_count *vallen, void **val)
143 {
144         struct obd_export *exp;
145         int rc;
146         ENTRY;
147
148         OBD_CHECK_SETUP(conn, exp);
149         OBD_CHECK_OP(exp->exp_obd, get_info);
150
151         rc = OBP(exp->exp_obd, get_info)(conn, keylen, key, vallen, val);
152         RETURN(rc);
153 }
154
155 static inline int obd_set_info(struct lustre_handle *conn, obd_count keylen,
156                                void *key, obd_count vallen, void *val)
157 {
158         struct obd_export *exp;
159         int rc;
160         ENTRY;
161
162         OBD_CHECK_SETUP(conn, exp);
163         OBD_CHECK_OP(exp->exp_obd, set_info);
164
165         rc = OBP(exp->exp_obd, set_info)(conn, keylen, key, vallen, val);
166         RETURN(rc);
167 }
168
169 static inline int obd_setup(struct obd_device *obd, int datalen, void *data)
170 {
171         int rc;
172         ENTRY;
173
174         OBD_CHECK_OP(obd, setup);
175
176         rc = OBP(obd, setup)(obd, datalen, data);
177         RETURN(rc);
178 }
179
180 static inline int obd_cleanup(struct obd_device *obd)
181 {
182         int rc;
183         ENTRY;
184
185         OBD_CHECK_DEVSETUP(obd);
186         OBD_CHECK_OP(obd, cleanup);
187
188         rc = OBP(obd, cleanup)(obd);
189         RETURN(rc);
190 }
191
192 /* Pack an in-memory MD struct for sending to the MDS and/or disk.
193  * Returns +ve size of packed MD (0 for free), or -ve error.
194  *
195  * If @wire_tgt == NULL, MD size is returned (max size if @mem_src == NULL).
196  * If @*wire_tgt != NULL and @mem_src == NULL, @*wire_tgt will be freed.
197  * If @*wire_tgt == NULL, it will be allocated
198  */
199 static inline int obd_packmd(struct lustre_handle *conn,
200                              struct lov_mds_md **wire_tgt,
201                              struct lov_stripe_md *mem_src)
202 {
203         struct obd_export *exp;
204         ENTRY;
205
206         OBD_CHECK_SETUP(conn, exp);
207         OBD_CHECK_OP(exp->exp_obd, packmd);
208
209         RETURN(OBP(exp->exp_obd, packmd)(conn, wire_tgt, mem_src));
210 }
211
212 static inline int obd_size_wiremd(struct lustre_handle *conn,
213                                   struct lov_stripe_md *mem_src)
214 {
215         return obd_packmd(conn, NULL, mem_src);
216 }
217
218 /* helper functions */
219 static inline int obd_alloc_wiremd(struct lustre_handle *conn,
220                                    struct lov_mds_md **wire_tgt)
221 {
222         LASSERT(wire_tgt);
223         LASSERT(*wire_tgt == NULL);
224         return obd_packmd(conn, wire_tgt, NULL);
225 }
226
227 static inline int obd_free_wiremd(struct lustre_handle *conn,
228                                   struct lov_mds_md **wire_tgt)
229 {
230         LASSERT(wire_tgt);
231         LASSERT(*wire_tgt);
232         return obd_packmd(conn, wire_tgt, NULL);
233 }
234
235 /* Unpack an MD struct from the MDS and/or disk to in-memory format.
236  * Returns +ve size of unpacked MD (0 for free), or -ve error.
237  *
238  * If @mem_tgt == NULL, MD size is returned (max size if @wire_src == NULL).
239  * If @*mem_tgt != NULL and @wire_src == NULL, @*mem_tgt will be freed.
240  * If @*mem_tgt == NULL, it will be allocated
241  */
242 static inline int obd_unpackmd(struct lustre_handle *conn,
243                                struct lov_stripe_md **mem_tgt,
244                                struct lov_mds_md *wire_src)
245 {
246         struct obd_export *exp;
247         ENTRY;
248
249         OBD_CHECK_SETUP(conn, exp);
250         OBD_CHECK_OP(exp->exp_obd, unpackmd);
251
252         RETURN(OBP(exp->exp_obd, unpackmd)(conn, mem_tgt, wire_src));
253 }
254
255 static inline int obd_size_memmd(struct lustre_handle *conn,
256                                  struct lov_mds_md *wire_src)
257 {
258         return obd_unpackmd(conn, NULL, wire_src);
259 }
260
261 /* helper functions */
262 static inline int obd_alloc_memmd(struct lustre_handle *conn,
263                                   struct lov_stripe_md **mem_tgt)
264 {
265         LASSERT(mem_tgt);
266         LASSERT(*mem_tgt == NULL);
267         return obd_unpackmd(conn, mem_tgt, NULL);
268 }
269
270 static inline int obd_free_memmd(struct lustre_handle *conn,
271                                  struct lov_stripe_md **mem_tgt)
272 {
273         LASSERT(mem_tgt);
274         LASSERT(*mem_tgt);
275         return obd_unpackmd(conn, mem_tgt, NULL);
276 }
277
278 static inline int obd_create(struct lustre_handle *conn, struct obdo *obdo,
279                              struct lov_stripe_md **ea)
280 {
281         struct obd_export *exp;
282         int rc;
283         ENTRY;
284
285         OBD_CHECK_SETUP(conn, exp);
286         OBD_CHECK_OP(exp->exp_obd, create);
287
288         rc = OBP(exp->exp_obd, create)(conn, obdo, ea);
289         RETURN(rc);
290 }
291
292 static inline int obd_destroy(struct lustre_handle *conn, struct obdo *obdo,
293                               struct lov_stripe_md *ea)
294 {
295         struct obd_export *exp;
296         int rc;
297         ENTRY;
298
299         OBD_CHECK_SETUP(conn, exp);
300         OBD_CHECK_OP(exp->exp_obd, destroy);
301
302         rc = OBP(exp->exp_obd, destroy)(conn, obdo, ea);
303         RETURN(rc);
304 }
305
306 static inline int obd_getattr(struct lustre_handle *conn, struct obdo *obdo,
307                               struct lov_stripe_md *ea)
308 {
309         struct obd_export *exp;
310         int rc;
311         ENTRY;
312
313         OBD_CHECK_SETUP(conn, exp);
314         OBD_CHECK_OP(exp->exp_obd, getattr);
315
316         rc = OBP(exp->exp_obd, getattr)(conn, obdo, ea);
317         RETURN(rc);
318 }
319
320 static inline int obd_close(struct lustre_handle *conn, struct obdo *obdo,
321                             struct lov_stripe_md *ea)
322 {
323         struct obd_export *exp;
324         int rc;
325         ENTRY;
326
327         OBD_CHECK_SETUP(conn, exp);
328         OBD_CHECK_OP(exp->exp_obd, close);
329
330         rc = OBP(exp->exp_obd, close)(conn, obdo, ea);
331         RETURN(rc);
332 }
333
334 static inline int obd_open(struct lustre_handle *conn, struct obdo *obdo,
335                            struct lov_stripe_md *ea)
336 {
337         struct obd_export *exp;
338         int rc;
339         ENTRY;
340
341         OBD_CHECK_SETUP(conn, exp);
342         OBD_CHECK_OP(exp->exp_obd, open);
343
344         rc = OBP(exp->exp_obd, open)(conn, obdo, ea);
345         RETURN(rc);
346 }
347
348 static inline int obd_setattr(struct lustre_handle *conn, struct obdo *obdo,
349                               struct lov_stripe_md *ea)
350 {
351         struct obd_export *exp;
352         int rc;
353         ENTRY;
354
355         OBD_CHECK_SETUP(conn, exp);
356         OBD_CHECK_OP(exp->exp_obd, setattr);
357
358         rc = OBP(exp->exp_obd, setattr)(conn, obdo, ea);
359         RETURN(rc);
360 }
361
362 static inline int obd_connect(struct lustre_handle *conn,
363                               struct obd_device *obd, obd_uuid_t cluuid,
364                               struct recovd_obd *recovd,
365                               ptlrpc_recovery_cb_t recover)
366 {
367         int rc;
368         ENTRY;
369
370         OBD_CHECK_DEVSETUP(obd);
371         OBD_CHECK_OP(obd, connect);
372
373         rc = OBP(obd, connect)(conn, obd, cluuid, recovd, recover);
374         RETURN(rc);
375 }
376
377 static inline int obd_disconnect(struct lustre_handle *conn)
378 {
379         struct obd_export *exp;
380         int rc;
381         ENTRY;
382
383         OBD_CHECK_SETUP(conn, exp);
384         OBD_CHECK_OP(exp->exp_obd, disconnect);
385
386         rc = OBP(exp->exp_obd, disconnect)(conn);
387         RETURN(rc);
388 }
389
390 static inline int obd_statfs(struct lustre_handle *conn,struct obd_statfs *osfs)
391 {
392         struct obd_export *exp;
393         int rc;
394         ENTRY;
395
396         OBD_CHECK_SETUP(conn, exp);
397         OBD_CHECK_OP(exp->exp_obd, statfs);
398
399         rc = OBP(exp->exp_obd, statfs)(conn, osfs);
400         RETURN(rc);
401 }
402
403 static inline int obd_punch(struct lustre_handle *conn, struct obdo *oa,
404                             struct lov_stripe_md *ea,
405                             obd_size start, obd_size end)
406 {
407         struct obd_export *exp;
408         int rc;
409         ENTRY;
410
411         OBD_CHECK_SETUP(conn, exp);
412         OBD_CHECK_OP(exp->exp_obd, punch);
413
414         rc = OBP(exp->exp_obd, punch)(conn, oa, ea, start, end);
415         RETURN(rc);
416 }
417
418 static inline int obd_brw(int cmd, struct lustre_handle *conn,
419                           struct lov_stripe_md *ea, obd_count oa_bufs,
420                           struct brw_page *pg, struct obd_brw_set *set)
421 {
422         struct obd_export *exp;
423         int rc;
424         ENTRY;
425
426         OBD_CHECK_SETUP(conn, exp);
427         OBD_CHECK_OP(exp->exp_obd, brw);
428
429         if (!(cmd & OBD_BRW_RWMASK)) {
430                 CERROR("obd_brw: cmd must be OBD_BRW_READ or OBD_BRW_WRITE\n");
431                 LBUG();
432         }
433
434         rc = OBP(exp->exp_obd, brw)(cmd, conn, ea, oa_bufs, pg, set);
435         RETURN(rc);
436 }
437
438 static inline int obd_preprw(int cmd, struct lustre_handle *conn,
439                              int objcount, struct obd_ioobj *obj,
440                              int niocount, struct niobuf_remote *remote,
441                              struct niobuf_local *local, void **desc_private)
442 {
443         struct obd_export *exp;
444         int rc;
445         ENTRY;
446
447         OBD_CHECK_SETUP(conn, exp);
448         OBD_CHECK_OP(exp->exp_obd, preprw);
449
450         rc = OBP(exp->exp_obd, preprw)(cmd, conn, objcount, obj, niocount,
451                                        remote, local, desc_private);
452         RETURN(rc);
453 }
454
455 static inline int obd_commitrw(int cmd, struct lustre_handle *conn,
456                                int objcount, struct obd_ioobj *obj,
457                                int niocount, struct niobuf_local *local,
458                                void *desc_private)
459 {
460         struct obd_export *exp;
461         int rc;
462         ENTRY;
463
464         OBD_CHECK_SETUP(conn, exp);
465         OBD_CHECK_OP(exp->exp_obd, commitrw);
466
467         rc = OBP(exp->exp_obd, commitrw)(cmd, conn, objcount, obj, niocount,
468                                          local, desc_private);
469         RETURN(rc);
470 }
471
472 static inline int obd_iocontrol(unsigned int cmd, struct lustre_handle *conn,
473                                 int len, void *karg, void *uarg)
474 {
475         struct obd_export *exp;
476         int rc;
477         ENTRY;
478
479         OBD_CHECK_SETUP(conn, exp);
480         OBD_CHECK_OP(exp->exp_obd, iocontrol);
481
482         rc = OBP(exp->exp_obd, iocontrol)(cmd, conn, len, karg, uarg);
483         RETURN(rc);
484 }
485
486 static inline int obd_enqueue(struct lustre_handle *conn,
487                               struct lov_stripe_md *ea,
488                               struct lustre_handle *parent_lock,
489                               __u32 type, void *cookie, int cookielen,
490                               __u32 mode, int *flags, void *cb, void *data,
491                               int datalen, struct lustre_handle *lockh)
492 {
493         struct obd_export *exp;
494         int rc;
495         ENTRY;
496
497         OBD_CHECK_SETUP(conn, exp);
498         OBD_CHECK_OP(exp->exp_obd, enqueue);
499
500         rc = OBP(exp->exp_obd, enqueue)(conn, ea, parent_lock, type,
501                                         cookie, cookielen, mode, flags, cb,
502                                         data, datalen, lockh);
503         RETURN(rc);
504 }
505
506 static inline int obd_cancel(struct lustre_handle *conn,
507                              struct lov_stripe_md *ea, __u32 mode,
508                              struct lustre_handle *lockh)
509 {
510         struct obd_export *exp;
511         int rc;
512         ENTRY;
513
514         OBD_CHECK_SETUP(conn, exp);
515         OBD_CHECK_OP(exp->exp_obd, cancel);
516
517         rc = OBP(exp->exp_obd, cancel)(conn, ea, mode, lockh);
518         RETURN(rc);
519 }
520
521 static inline int obd_cancel_unused(struct lustre_handle *conn,
522                                     struct lov_stripe_md *ea, int local)
523 {
524         struct obd_export *exp;
525         int rc;
526         ENTRY;
527
528         OBD_CHECK_SETUP(conn, exp);
529         OBD_CHECK_OP(exp->exp_obd, cancel_unused);
530
531         rc = OBP(exp->exp_obd, cancel_unused)(conn, ea, local);
532         RETURN(rc);
533 }
534
535 #endif
536
537 /* OBD Metadata Support */
538
539 extern int obd_init_caches(void);
540 extern void obd_cleanup_caches(void);
541
542 static inline struct lustre_handle *obdo_handle(struct obdo *oa)
543 {
544         return (struct lustre_handle *)&oa->o_inline;
545 }
546
547 static inline void obd_oa2handle(struct lustre_handle *handle, struct obdo *oa)
548 {
549         if (oa->o_valid |= OBD_MD_FLHANDLE) {
550                 struct lustre_handle *oa_handle = obdo_handle(oa);
551                 memcpy(handle, oa_handle, sizeof(*handle));
552         }
553 }
554
555 static inline void obd_handle2oa(struct obdo *oa, struct lustre_handle *handle)
556 {
557         if (handle->addr) {
558                 struct lustre_handle *oa_handle = obdo_handle(oa);
559                 memcpy(oa_handle, handle, sizeof(*handle));
560                 oa->o_valid |= OBD_MD_FLHANDLE;
561         }
562 }
563
564 #ifdef __KERNEL__
565 /* support routines */
566 extern kmem_cache_t *obdo_cachep;
567 static inline struct obdo *obdo_alloc(void)
568 {
569         struct obdo *oa;
570
571         oa = kmem_cache_alloc(obdo_cachep, SLAB_KERNEL);
572         if (oa == NULL)
573                 LBUG();
574         memset(oa, 0, sizeof (*oa));
575
576         return oa;
577 }
578
579 static inline void obdo_free(struct obdo *oa)
580 {
581         if (!oa)
582                 return;
583         kmem_cache_free(obdo_cachep, oa);
584 }
585
586 static inline void obdo_from_iattr(struct obdo *oa, struct iattr *attr)
587 {
588         unsigned int ia_valid = attr->ia_valid;
589
590         if (ia_valid & ATTR_ATIME) {
591                 oa->o_atime = attr->ia_atime;
592                 oa->o_valid |= OBD_MD_FLATIME;
593         }
594         if (ia_valid & ATTR_MTIME) {
595                 oa->o_mtime = attr->ia_mtime;
596                 oa->o_valid |= OBD_MD_FLMTIME;
597         }
598         if (ia_valid & ATTR_CTIME) {
599                 oa->o_ctime = attr->ia_ctime;
600                 oa->o_valid |= OBD_MD_FLCTIME;
601         }
602         if (ia_valid & ATTR_SIZE) {
603                 oa->o_size = attr->ia_size;
604                 oa->o_valid |= OBD_MD_FLSIZE;
605         }
606         if (ia_valid & ATTR_MODE) {
607                 oa->o_mode = attr->ia_mode;
608                 oa->o_valid |= OBD_MD_FLTYPE | OBD_MD_FLMODE;
609                 if (!in_group_p(oa->o_gid) && !capable(CAP_FSETID))
610                         oa->o_mode &= ~S_ISGID;
611         }
612         if (ia_valid & ATTR_UID) {
613                 oa->o_uid = attr->ia_uid;
614                 oa->o_valid |= OBD_MD_FLUID;
615         }
616         if (ia_valid & ATTR_GID) {
617                 oa->o_gid = attr->ia_gid;
618                 oa->o_valid |= OBD_MD_FLGID;
619         }
620 }
621
622
623 static inline void iattr_from_obdo(struct iattr *attr, struct obdo *oa,
624                                    obd_flag valid)
625 {
626         memset(attr, 0, sizeof(*attr));
627         if (valid & OBD_MD_FLATIME) {
628                 attr->ia_atime = oa->o_atime;
629                 attr->ia_valid |= ATTR_ATIME;
630         }
631         if (valid & OBD_MD_FLMTIME) {
632                 attr->ia_mtime = oa->o_mtime;
633                 attr->ia_valid |= ATTR_MTIME;
634         }
635         if (valid & OBD_MD_FLCTIME) {
636                 attr->ia_ctime = oa->o_ctime;
637                 attr->ia_valid |= ATTR_CTIME;
638         }
639         if (valid & OBD_MD_FLSIZE) {
640                 attr->ia_size = oa->o_size;
641                 attr->ia_valid |= ATTR_SIZE;
642         }
643         if (valid & OBD_MD_FLTYPE) {
644                 attr->ia_mode = (attr->ia_mode & ~S_IFMT)|(oa->o_mode & S_IFMT);
645                 attr->ia_valid |= ATTR_MODE;
646         }
647         if (valid & OBD_MD_FLMODE) {
648                 attr->ia_mode = (attr->ia_mode & S_IFMT)|(oa->o_mode & ~S_IFMT);
649                 attr->ia_valid |= ATTR_MODE;
650                 if (!in_group_p(oa->o_gid) && !capable(CAP_FSETID))
651                         attr->ia_mode &= ~S_ISGID;
652         }
653         if (valid & OBD_MD_FLUID)
654         {
655                 attr->ia_uid = oa->o_uid;
656                 attr->ia_valid |= ATTR_UID;
657         }
658         if (valid & OBD_MD_FLGID) {
659                 attr->ia_gid = oa->o_gid;
660                 attr->ia_valid |= ATTR_GID;
661         }
662 }
663
664
665 /* WARNING: the file systems must take care not to tinker with
666    attributes they don't manage (such as blocks). */
667
668 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
669 #define to_kdev_t(dev) dev
670 #define kdev_t_to_nr(dev) dev
671 #endif
672
673 static inline void obdo_from_inode(struct obdo *dst, struct inode *src,
674                                    obd_flag valid)
675 {
676         if (valid & OBD_MD_FLATIME)
677                 dst->o_atime = src->i_atime;
678         if (valid & OBD_MD_FLMTIME)
679                 dst->o_mtime = src->i_mtime;
680         if (valid & OBD_MD_FLCTIME)
681                 dst->o_ctime = src->i_ctime;
682         if (valid & OBD_MD_FLSIZE)
683                 dst->o_size = src->i_size;
684         if (valid & OBD_MD_FLBLOCKS)   /* allocation of space */
685                 dst->o_blocks = src->i_blocks;
686         if (valid & OBD_MD_FLBLKSZ)
687                 dst->o_blksize = src->i_blksize;
688         if (valid & OBD_MD_FLTYPE)
689                 dst->o_mode = (dst->o_mode & ~S_IFMT) | (src->i_mode & S_IFMT);
690         if (valid & OBD_MD_FLMODE)
691                 dst->o_mode = (dst->o_mode & S_IFMT) | (src->i_mode & ~S_IFMT);
692         if (valid & OBD_MD_FLUID)
693                 dst->o_uid = src->i_uid;
694         if (valid & OBD_MD_FLGID)
695                 dst->o_gid = src->i_gid;
696         if (valid & OBD_MD_FLFLAGS)
697                 dst->o_flags = src->i_flags;
698         if (valid & OBD_MD_FLNLINK)
699                 dst->o_nlink = src->i_nlink;
700         if (valid & OBD_MD_FLGENER)
701                 dst->o_generation = src->i_generation;
702         if (valid & OBD_MD_FLRDEV)
703                 dst->o_rdev = (__u32)kdev_t_to_nr(src->i_rdev);
704
705         dst->o_valid |= (valid & ~OBD_MD_FLID);
706 }
707
708 static inline void obdo_to_inode(struct inode *dst, struct obdo *src,
709                                  obd_flag valid)
710 {
711         valid &= src->o_valid;
712
713         if (valid & OBD_MD_FLATIME)
714                 dst->i_atime = src->o_atime;
715         if (valid & OBD_MD_FLMTIME)
716                 dst->i_mtime = src->o_mtime;
717         if (valid & OBD_MD_FLCTIME)
718                 dst->i_ctime = src->o_ctime;
719         if (valid & OBD_MD_FLSIZE)
720                 dst->i_size = src->o_size;
721         if (valid & OBD_MD_FLBLOCKS) /* allocation of space */
722                 dst->i_blocks = src->o_blocks;
723         if (valid & OBD_MD_FLBLKSZ)
724                 dst->i_blksize = src->o_blksize;
725         if (valid & OBD_MD_FLTYPE)
726                 dst->i_mode = (dst->i_mode & ~S_IFMT) | (src->o_mode & S_IFMT);
727         if (valid & OBD_MD_FLMODE)
728                 dst->i_mode = (dst->i_mode & S_IFMT) | (src->o_mode & ~S_IFMT);
729         if (valid & OBD_MD_FLUID)
730                 dst->i_uid = src->o_uid;
731         if (valid & OBD_MD_FLGID)
732                 dst->i_gid = src->o_gid;
733         if (valid & OBD_MD_FLFLAGS)
734                 dst->i_flags = src->o_flags;
735         if (valid & OBD_MD_FLNLINK)
736                 dst->i_nlink = src->o_nlink;
737         if (valid & OBD_MD_FLGENER)
738                 dst->i_generation = src->o_generation;
739         if (valid & OBD_MD_FLRDEV)
740                 dst->i_rdev = to_kdev_t(src->o_rdev);
741 }
742 #endif
743
744 static inline void obdo_cpy_md(struct obdo *dst, struct obdo *src,
745                                obd_flag valid)
746 {
747 #ifdef __KERNEL__
748         CDEBUG(D_INODE, "src obdo %Ld valid 0x%x, dst obdo %Ld\n",
749                (unsigned long long)src->o_id, src->o_valid,
750                (unsigned long long)dst->o_id);
751 #endif
752         if (valid & OBD_MD_FLATIME)
753                 dst->o_atime = src->o_atime;
754         if (valid & OBD_MD_FLMTIME)
755                 dst->o_mtime = src->o_mtime;
756         if (valid & OBD_MD_FLCTIME)
757                 dst->o_ctime = src->o_ctime;
758         if (valid & OBD_MD_FLSIZE)
759                 dst->o_size = src->o_size;
760         if (valid & OBD_MD_FLBLOCKS) /* allocation of space */
761                 dst->o_blocks = src->o_blocks;
762         if (valid & OBD_MD_FLBLKSZ)
763                 dst->o_blksize = src->o_blksize;
764         if (valid & OBD_MD_FLTYPE)
765                 dst->o_mode = (dst->o_mode & ~S_IFMT) | (src->o_mode & S_IFMT);
766         if (valid & OBD_MD_FLMODE)
767                 dst->o_mode = (dst->o_mode & S_IFMT) | (src->o_mode & ~S_IFMT);
768         if (valid & OBD_MD_FLUID)
769                 dst->o_uid = src->o_uid;
770         if (valid & OBD_MD_FLGID)
771                 dst->o_gid = src->o_gid;
772         if (valid & OBD_MD_FLFLAGS)
773                 dst->o_flags = src->o_flags;
774         /*
775         if (valid & OBD_MD_FLOBDFLG)
776                 dst->o_obdflags = src->o_obdflags;
777         */
778         if (valid & OBD_MD_FLNLINK)
779                 dst->o_nlink = src->o_nlink;
780         if (valid & OBD_MD_FLGENER)
781                 dst->o_generation = src->o_generation;
782         if (valid & OBD_MD_FLRDEV)
783                 dst->o_rdev = src->o_rdev;
784         if (valid & OBD_MD_FLINLINE &&
785              src->o_obdflags & OBD_FL_INLINEDATA) {
786                 memcpy(dst->o_inline, src->o_inline, sizeof(src->o_inline));
787                 dst->o_obdflags |= OBD_FL_INLINEDATA;
788         }
789
790         dst->o_valid |= valid;
791 }
792
793
794 /* returns FALSE if comparison (by flags) is same, TRUE if changed */
795 static inline int obdo_cmp_md(struct obdo *dst, struct obdo *src,
796                               obd_flag compare)
797 {
798         int res = 0;
799
800         if ( compare & OBD_MD_FLATIME )
801                 res = (res || (dst->o_atime != src->o_atime));
802         if ( compare & OBD_MD_FLMTIME )
803                 res = (res || (dst->o_mtime != src->o_mtime));
804         if ( compare & OBD_MD_FLCTIME )
805                 res = (res || (dst->o_ctime != src->o_ctime));
806         if ( compare & OBD_MD_FLSIZE )
807                 res = (res || (dst->o_size != src->o_size));
808         if ( compare & OBD_MD_FLBLOCKS ) /* allocation of space */
809                 res = (res || (dst->o_blocks != src->o_blocks));
810         if ( compare & OBD_MD_FLBLKSZ )
811                 res = (res || (dst->o_blksize != src->o_blksize));
812         if ( compare & OBD_MD_FLTYPE )
813                 res = (res || (((dst->o_mode ^ src->o_mode) & S_IFMT) != 0));
814         if ( compare & OBD_MD_FLMODE )
815                 res = (res || (((dst->o_mode ^ src->o_mode) & ~S_IFMT) != 0));
816         if ( compare & OBD_MD_FLUID )
817                 res = (res || (dst->o_uid != src->o_uid));
818         if ( compare & OBD_MD_FLGID )
819                 res = (res || (dst->o_gid != src->o_gid));
820         if ( compare & OBD_MD_FLFLAGS )
821                 res = (res || (dst->o_flags != src->o_flags));
822         if ( compare & OBD_MD_FLNLINK )
823                 res = (res || (dst->o_nlink != src->o_nlink));
824         if ( compare & OBD_MD_FLGENER )
825                 res = (res || (dst->o_generation != src->o_generation));
826         /* XXX Don't know if thses should be included here - wasn't previously
827         if ( compare & OBD_MD_FLINLINE )
828                 res = (res || memcmp(dst->o_inline, src->o_inline));
829         */
830         return res;
831 }
832
833
834 #ifdef __KERNEL__
835 /* I'm as embarrassed about this as you are.
836  *
837  * <shaver> // XXX do not look into _superhack with remaining eye
838  * <shaver> // XXX if this were any uglier, I'd get my own show on MTV */ 
839 extern int (*ptlrpc_put_connection_superhack)(struct ptlrpc_connection *c);
840
841 int class_register_type(struct obd_ops *ops, struct lprocfs_vars* vars, 
842                         char *nm);
843 int class_unregister_type(char *nm);
844 int class_name2dev(char *name);
845 int class_uuid2dev(char *uuid);
846 struct obd_device *class_uuid2obd(char *uuid);
847 struct obd_export *class_new_export(struct obd_device *obddev);
848 struct obd_type *class_get_type(char *name);
849 void class_put_type(struct obd_type *type);
850 void class_destroy_export(struct obd_export *exp);
851 int class_connect(struct lustre_handle *conn, struct obd_device *obd,
852                   obd_uuid_t cluuid);
853 int class_disconnect(struct lustre_handle *conn);
854 void class_disconnect_all(struct obd_device *obddev);
855
856 /* generic operations shared by various OBD types */
857 int class_multi_setup(struct obd_device *obddev, uint32_t len, void *data);
858 int class_multi_cleanup(struct obd_device *obddev);
859
860 extern void (*class_signal_connection_failure)(struct ptlrpc_connection *);
861
862 static inline struct ptlrpc_connection *class_rd2conn(struct recovd_data *rd)
863 {
864         /* reuse list_entry's member-pointer offset stuff */
865         return list_entry(rd, struct ptlrpc_connection, c_recovd_data);
866 }
867
868 struct obd_statfs;
869 struct statfs;
870 void statfs_pack(struct obd_statfs *osfs, struct statfs *sfs);
871 void statfs_unpack(struct statfs *sfs, struct obd_statfs *osfs);
872 void obd_statfs_pack(struct obd_statfs *tgt, struct obd_statfs *src);
873 void obd_statfs_unpack(struct obd_statfs *tgt, struct obd_statfs *src);
874
875 #endif
876
877 /* sysctl.c */
878 extern void obd_sysctl_init (void);
879 extern void obd_sysctl_clean (void);
880
881 /* uuid.c  */
882 typedef __u8 class_uuid_t[16];
883 //int class_uuid_parse(obd_uuid_t in, class_uuid_t out);
884 void class_uuid_unparse(class_uuid_t in, obd_uuid_t out);
885 #endif /* __LINUX_CLASS_OBD_H */