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