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