1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Extention of lu_object.h for metadata objects
6 * Copyright (C) 2006 Cluster File Systems, Inc.
8 * This file is part of Lustre, http://www.lustre.org.
10 * Lustre is free software; you can redistribute it and/or
11 * modify it under the terms of version 2 of the GNU General Public
12 * License as published by the Free Software Foundation.
14 * Lustre is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with Lustre; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 #ifndef _LINUX_MD_OBJECT_H
26 #define _LINUX_MD_OBJECT_H
29 * Sub-class of lu_object with methods common for "meta-data" objects in MDT
32 * Meta-data objects implement namespace operations: you can link, unlink
33 * them, and treat them as directories.
35 * Examples: mdt, cmm, and mdt are implementations of md interface.
40 * super-class definitions.
42 #include <linux/lu_object.h>
45 struct md_device_operations;
49 * Operations implemented for each md object (both directory and leaf).
51 struct md_object_operations {
52 int (*moo_attr_get)(struct lu_context *ctxt, struct md_object *dt,
53 struct lu_attr *attr);
54 int (*moo_attr_set)(struct lu_context *ctxt, struct md_object *dt,
55 struct lu_attr *attr);
57 int (*moo_xattr_get)(struct lu_context *ctxt, struct md_object *obj,
58 void *buf, int buf_len, const char *name);
60 int (*moo_xattr_set)(struct lu_context *ctxt, struct md_object *obj,
61 void *buf, int buf_len, const char *name);
62 /* part of cross-ref operation */
63 int (*moo_object_create)(struct lu_context *,
64 struct md_object *, struct lu_attr *);
65 int (*moo_object_destroy)(struct lu_context *, struct md_object *);
70 * Operations implemented for each directory object.
72 struct md_dir_operations {
73 int (*mdo_mkdir)(struct lu_context *ctxt, struct lu_attr *attr,
74 struct md_object *obj,
75 const char *name, struct md_object *child);
77 int (*mdo_rename)(struct lu_context *ctxt, struct md_object *spobj,
78 struct md_object *tpobj, struct md_object *sobj,
79 const char *sname, struct md_object *tobj,
82 int (*mdo_link)(struct lu_context *ctxt, struct md_object *tobj,
83 struct md_object *sobj, const char *name);
85 /* partial ops for cross-ref case */
86 int (*mdo_name_insert)(struct lu_context *, struct md_object *,
87 const char *name, const struct lu_fid *,
89 int (*mdo_name_remove)(struct lu_context *, struct md_object *,
90 const char *name, struct lu_attr *);
93 struct md_device_operations {
94 /* method for getting/setting device wide back stored config data, like
95 * last used meta-sequence, etc. */
96 int (*mdo_config) (struct lu_context *ctx,
97 struct md_device *m, const char *name,
98 void *buf, int size, int mode);
100 /* meta-data device related handlers. */
101 int (*mdo_root_get)(struct lu_context *ctx,
102 struct md_device *m, struct lu_fid *f);
103 int (*mdo_statfs)(struct lu_context *ctx,
104 struct md_device *m, struct kstatfs *sfs);
109 struct lu_device md_lu_dev;
110 struct md_device_operations *md_ops;
114 struct lu_object mo_lu;
115 struct md_object_operations *mo_ops;
116 struct md_dir_operations *mo_dir_ops;
119 static inline int lu_device_is_md(const struct lu_device *d)
121 return ergo(d != NULL, d->ld_type->ldt_tags & LU_DEVICE_MD);
124 static inline struct md_device *lu2md_dev(const struct lu_device *d)
126 LASSERT(lu_device_is_md(d));
127 return container_of0(d, struct md_device, md_lu_dev);
130 static inline struct lu_device *md2lu_dev(struct md_device *d)
132 return &d->md_lu_dev;
135 static inline struct md_object *lu2md(const struct lu_object *o)
137 LASSERT(lu_device_is_md(o->lo_dev));
138 return container_of0(o, struct md_object, mo_lu);
141 static inline struct md_object *md_object_next(const struct md_object *obj)
143 return lu2md(lu_object_next(&obj->mo_lu));
146 static inline struct md_device *md_device_get(const struct md_object *o)
148 LASSERT(lu_device_is_md(o->mo_lu.lo_dev));
149 return container_of0(o->mo_lu.lo_dev, struct md_device, md_lu_dev);
152 static inline int md_device_init(struct md_device *md, struct lu_device_type *t)
154 return lu_device_init(&md->md_lu_dev, t);
157 static inline void md_device_fini(struct md_device *md)
159 lu_device_fini(&md->md_lu_dev);
162 #endif /* _LINUX_MD_OBJECT_H */