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 _LUSTRE_MD_OBJECT_H
26 #define _LUSTRE_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 <lu_object.h>
45 struct md_device_operations;
49 /* metadata attributes */
62 struct lu_attr ma_attr;
63 struct lov_mds_md *ma_lmm;
65 struct lmv_stripe_md *ma_lmv;
67 struct llog_cookie *ma_cookie;
71 /* additional parameters for create */
72 struct md_create_spec {
75 const char *sp_symname;
76 /* parent FID for cross-ref mkdir */
77 const struct lu_fid *sp_pfid;
78 /* eadata for regular files */
80 /* lov objs exist already */
81 const struct lu_fid *fid;
87 /* create flag from client: such as MDS_OPEN_CREAT, and others */
92 * Operations implemented for each md object (both directory and leaf).
94 struct md_object_operations {
95 int (*moo_attr_get)(const struct lu_context *ctxt, struct md_object *dt,
96 struct md_attr *attr);
98 int (*moo_attr_set)(const struct lu_context *ctxt, struct md_object *dt,
99 const struct md_attr *attr);
101 int (*moo_xattr_get)(const struct lu_context *ctxt,
102 struct md_object *obj,
103 void *buf, int buf_len, const char *name);
105 int (*moo_xattr_list)(const struct lu_context *ctxt,
106 struct md_object *obj,
107 void *buf, int buf_len);
109 int (*moo_xattr_set)(const struct lu_context *ctxt,
110 struct md_object *obj, const void *buf,
111 int buf_len, const char *name, int fl);
112 int (*moo_xattr_del)(const struct lu_context *ctxt,
113 struct md_object *obj, const char *name);
115 int (*moo_readpage)(const struct lu_context *, struct md_object *,
116 const struct lu_rdpg *);
118 int (*moo_readlink)(const struct lu_context *ctxt,
119 struct md_object *obj,
120 void *buf, int buf_len);
122 /* part of cross-ref operation */
123 int (*moo_object_create)(const struct lu_context *,
125 const struct md_create_spec *spec,
127 int (*moo_ref_add)(const struct lu_context *, struct md_object *);
128 int (*moo_ref_del)(const struct lu_context *, struct md_object *,
130 int (*moo_open)(const struct lu_context *, struct md_object *, int flags);
131 int (*moo_close)(const struct lu_context *, struct md_object *,
136 * Operations implemented for each directory object.
138 struct md_dir_operations {
139 int (*mdo_lookup)(const struct lu_context *, struct md_object *,
140 const char *, struct lu_fid *);
142 int (*mdo_create)(const struct lu_context *, struct md_object *,
143 const char *child_name, struct md_object *,
144 const struct md_create_spec *spec,
146 /* This method is used for creating data object for this meta object*/
147 int (*mdo_create_data)(const struct lu_context *cx, struct md_object *p,
149 const struct md_create_spec *spec,
151 int (*mdo_rename)(const struct lu_context *ctxt,
152 struct md_object *spobj, struct md_object *tpobj,
153 const struct lu_fid *lf, const char *sname,
154 struct md_object *tobj, const char *tname,
157 int (*mdo_link)(const struct lu_context *, struct md_object *,
158 struct md_object *, const char *, struct md_attr *);
160 int (*mdo_unlink)(const struct lu_context *, struct md_object *,
161 struct md_object *, const char *, struct md_attr *);
163 /* partial ops for cross-ref case */
164 int (*mdo_name_insert)(const struct lu_context *, struct md_object *,
165 const char *, const struct lu_fid *, int);
166 int (*mdo_name_remove)(const struct lu_context *, struct md_object *,
168 int (*mdo_rename_tgt)(const struct lu_context *, struct md_object *,
169 struct md_object *, const struct lu_fid *,
170 const char *, struct md_attr *);
173 struct md_device_operations {
174 /* meta-data device related handlers. */
175 int (*mdo_root_get)(const struct lu_context *ctx,
176 struct md_device *m, struct lu_fid *f);
177 int (*mdo_maxsize_get)(const struct lu_context *ctx,
178 struct md_device *m, int *md_size,
180 int (*mdo_statfs)(const struct lu_context *ctx,
181 struct md_device *m, struct kstatfs *sfs);
184 enum md_upcall_event {
185 /*sync the md layer*/
190 struct md_device *mu_upcall_dev;
191 int (*mu_upcall)(const struct lu_context *ctxt, struct md_device *md,
192 enum md_upcall_event ev);
196 struct lu_device md_lu_dev;
197 struct md_device_operations *md_ops;
198 struct md_upcall md_upcall;
202 struct lu_object mo_lu;
203 struct md_object_operations *mo_ops;
204 struct md_dir_operations *mo_dir_ops;
207 static inline int lu_device_is_md(const struct lu_device *d)
209 return ergo(d != NULL, d->ld_type->ldt_tags & LU_DEVICE_MD);
212 static inline struct md_device *lu2md_dev(const struct lu_device *d)
214 LASSERT(lu_device_is_md(d));
215 return container_of0(d, struct md_device, md_lu_dev);
218 static inline struct lu_device *md2lu_dev(struct md_device *d)
220 return &d->md_lu_dev;
223 static inline struct md_object *lu2md(const struct lu_object *o)
225 LASSERT(lu_device_is_md(o->lo_dev));
226 return container_of0(o, struct md_object, mo_lu);
229 static inline struct md_object *md_object_next(const struct md_object *obj)
231 return (obj ? lu2md(lu_object_next(&obj->mo_lu)) : NULL);
234 static inline struct md_device *md_obj2dev(const struct md_object *o)
236 LASSERT(lu_device_is_md(o->mo_lu.lo_dev));
237 return container_of0(o->mo_lu.lo_dev, struct md_device, md_lu_dev);
240 static inline int md_device_init(struct md_device *md, struct lu_device_type *t)
242 return lu_device_init(&md->md_lu_dev, t);
245 static inline void md_device_fini(struct md_device *md)
247 lu_device_fini(&md->md_lu_dev);
251 static inline int mo_attr_get(const struct lu_context *cx, struct md_object *m,
254 LASSERT(m->mo_ops->moo_attr_get);
255 return m->mo_ops->moo_attr_get(cx, m, at);
258 static inline int mo_readlink(const struct lu_context *cx, struct md_object *m,
259 void *buf, int buf_len)
261 LASSERT(m->mo_ops->moo_attr_get);
262 return m->mo_ops->moo_readlink(cx, m, buf, buf_len);
265 static inline int mo_attr_set(const struct lu_context *cx, struct md_object *m,
266 const struct md_attr *at)
268 LASSERT(m->mo_ops->moo_attr_set);
269 return m->mo_ops->moo_attr_set(cx, m, at);
272 static inline int mo_xattr_get(const struct lu_context *cx,
274 void *buf, int buf_len, const char *name)
276 LASSERT(m->mo_ops->moo_xattr_get);
277 return m->mo_ops->moo_xattr_get(cx, m, buf, buf_len, name);
280 static inline int mo_xattr_del(const struct lu_context *cx,
284 LASSERT(m->mo_ops->moo_xattr_set);
285 return m->mo_ops->moo_xattr_del(cx, m, name);
288 static inline int mo_xattr_set(const struct lu_context *cx,
289 struct md_object *m, const void *buf,
290 int buf_len, const char *name, int flags)
292 LASSERT(m->mo_ops->moo_xattr_set);
293 return m->mo_ops->moo_xattr_set(cx, m, buf, buf_len, name, flags);
296 static inline int mo_xattr_list(const struct lu_context *cx,
298 void *buf, int buf_len)
300 LASSERT(m->mo_ops->moo_xattr_get);
301 return m->mo_ops->moo_xattr_list(cx, m, buf, buf_len);
304 static inline int mo_open(const struct lu_context *cx, struct md_object *m,
307 LASSERT(m->mo_ops->moo_open);
308 return m->mo_ops->moo_open(cx, m, flags);
311 static inline int mo_close(const struct lu_context *cx, struct md_object *m,
314 LASSERT(m->mo_ops->moo_close);
315 return m->mo_ops->moo_close(cx, m, ma);
318 static inline int mo_readpage(const struct lu_context *cx, struct md_object *m,
319 const struct lu_rdpg *rdpg)
321 LASSERT(m->mo_ops->moo_readpage);
322 return m->mo_ops->moo_readpage(cx, m, rdpg);
325 static inline int mo_object_create(const struct lu_context *cx,
327 const struct md_create_spec *spc,
330 LASSERT(m->mo_ops->moo_object_create);
331 return m->mo_ops->moo_object_create(cx, m, spc, at);
334 static inline int mo_ref_add(const struct lu_context *cx,
337 LASSERT(m->mo_ops->moo_ref_add);
338 return m->mo_ops->moo_ref_add(cx, m);
341 static inline int mo_ref_del(const struct lu_context *cx,
342 struct md_object *m, struct md_attr *ma)
344 LASSERT(m->mo_ops->moo_ref_del);
345 return m->mo_ops->moo_ref_del(cx, m, ma);
348 static inline int mdo_lookup(const struct lu_context *cx, struct md_object *p,
349 const char *name, struct lu_fid *f)
351 LASSERT(p->mo_dir_ops->mdo_lookup);
352 return p->mo_dir_ops->mdo_lookup(cx, p, name, f);
355 static inline int mdo_create(const struct lu_context *cx, struct md_object *p,
356 const char *child_name, struct md_object *c,
357 const struct md_create_spec *spc,
360 LASSERT(c->mo_dir_ops->mdo_create);
361 return c->mo_dir_ops->mdo_create(cx, p, child_name, c, spc, at);
363 static inline int mdo_create_data(const struct lu_context *cx,
364 struct md_object *p, struct md_object *c,
365 const struct md_create_spec *spec,
368 LASSERT(c->mo_dir_ops->mdo_create_data);
369 return c->mo_dir_ops->mdo_create_data(cx, p, c, spec, ma);
372 static inline int mdo_rename(const struct lu_context *cx,
373 struct md_object *sp, struct md_object *tp,
374 const struct lu_fid *lf, const char *sname,
375 struct md_object *t, const char *tname,
378 LASSERT(tp->mo_dir_ops->mdo_rename);
379 return tp->mo_dir_ops->mdo_rename(cx, sp, tp, lf, sname, t, tname, ma);
382 static inline int mdo_link(const struct lu_context *cx, struct md_object *p,
383 struct md_object *s, const char *name,
386 LASSERT(s->mo_dir_ops->mdo_link);
387 return s->mo_dir_ops->mdo_link(cx, p, s, name, ma);
390 static inline int mdo_unlink(const struct lu_context *cx, struct md_object *p,
391 struct md_object *c, const char *name,
394 LASSERT(c->mo_dir_ops->mdo_unlink);
395 return c->mo_dir_ops->mdo_unlink(cx, p, c, name, ma);
398 static inline int mdo_name_insert(const struct lu_context *cx,
399 struct md_object *p, const char *name,
400 const struct lu_fid *f, int isdir)
402 LASSERT(p->mo_dir_ops->mdo_name_insert);
403 return p->mo_dir_ops->mdo_name_insert(cx, p, name, f, isdir);
406 static inline int mdo_name_remove(const struct lu_context *cx,
410 LASSERT(p->mo_dir_ops->mdo_name_remove);
411 return p->mo_dir_ops->mdo_name_remove(cx, p, name);
414 static inline int mdo_rename_tgt(const struct lu_context *cx,
415 struct md_object *p, struct md_object *t,
416 const struct lu_fid *lf, const char *name,
420 LASSERT(t->mo_dir_ops->mdo_rename_tgt);
421 return t->mo_dir_ops->mdo_rename_tgt(cx, p, t, lf, name, ma);
423 LASSERT(p->mo_dir_ops->mdo_rename_tgt);
424 return p->mo_dir_ops->mdo_rename_tgt(cx, p, t, lf, name, ma);
428 #endif /* _LINUX_MD_OBJECT_H */