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>
46 struct md_device_operations;
57 #define SQUASH_NONE 0x00
58 #define SQUASH_UID 0x01
59 #define SQUASH_GID 0x02
75 struct group_info *mu_ginfo;
76 struct mdt_identity *mu_identity;
79 /* there are at most 4 fid in one operation, see rename */
81 const struct lu_fid *mc_fid[4];
82 struct lustre_capa *mc_capa[4];
86 * Implemented in mdd/mdd_handler.c.
88 * XXX should be moved into separate .h/.c together with all md security
89 * related definitions.
91 struct md_ucred *md_ucred(const struct lu_env *env);
92 struct md_capainfo *md_capainfo(const struct lu_env *env);
94 /* metadata attributes */
101 MA_ACL_DEF = (1 << 5)
108 struct lu_attr ma_attr;
109 struct lov_mds_md *ma_lmm;
111 struct lmv_stripe_md *ma_lmv;
115 struct llog_cookie *ma_cookie;
119 /* additional parameters for create */
120 struct md_create_spec {
123 const char *sp_symname;
124 /* parent FID for cross-ref mkdir */
125 const struct lu_fid *sp_pfid;
126 /* eadata for regular files */
128 /* lov objs exist already */
129 const struct lu_fid *fid;
135 /* create flag from client: such as MDS_OPEN_CREAT, and others */
140 * Operations implemented for each md object (both directory and leaf).
142 struct md_object_operations {
143 int (*moo_permission)(const struct lu_env *env,
144 struct md_object *obj, int mask);
146 int (*moo_attr_get)(const struct lu_env *env, struct md_object *obj,
147 struct md_attr *attr);
149 int (*moo_attr_set)(const struct lu_env *env, struct md_object *obj,
150 const struct md_attr *attr);
152 int (*moo_xattr_get)(const struct lu_env *env, struct md_object *obj,
153 struct lu_buf *buf, const char *name);
155 int (*moo_xattr_list)(const struct lu_env *env, struct md_object *obj,
158 int (*moo_xattr_set)(const struct lu_env *env, struct md_object *obj,
159 const struct lu_buf *buf, const char *name,
162 int (*moo_xattr_del)(const struct lu_env *env, struct md_object *obj,
165 int (*moo_readpage)(const struct lu_env *env, struct md_object *obj,
166 const struct lu_rdpg *rdpg);
168 int (*moo_readlink)(const struct lu_env *env, struct md_object *obj,
171 /* part of cross-ref operation */
172 int (*moo_object_create)(const struct lu_env *env,
173 struct md_object *obj,
174 const struct md_create_spec *spec,
177 int (*moo_ref_add)(const struct lu_env *env, struct md_object *obj);
179 int (*moo_ref_del)(const struct lu_env *env,
180 struct md_object *obj, struct md_attr *ma);
182 int (*moo_open)(const struct lu_env *env,
183 struct md_object *obj, int flag);
185 int (*moo_close)(const struct lu_env *env, struct md_object *obj,
187 int (*moo_capa_get)(const struct lu_env *, struct md_object *,
188 struct lustre_capa *, int renewal);
192 * Operations implemented for each directory object.
194 struct md_dir_operations {
195 int (*mdo_is_subdir) (const struct lu_env *env, struct md_object *obj,
196 const struct lu_fid *fid, struct lu_fid *sfid);
198 int (*mdo_lookup)(const struct lu_env *env, struct md_object *obj,
199 const char *name, struct lu_fid *fid);
201 lu_mode_t (*mdo_lock_mode)(const struct lu_env *env, struct md_object *obj,
204 int (*mdo_create)(const struct lu_env *env, struct md_object *pobj,
205 const char *name, struct md_object *child,
206 struct md_create_spec *spec,
209 /* This method is used for creating data object for this meta object*/
210 int (*mdo_create_data)(const struct lu_env *env, struct md_object *p,
212 const struct md_create_spec *spec,
215 int (*mdo_rename)(const struct lu_env *env, struct md_object *spobj,
216 struct md_object *tpobj, const struct lu_fid *lf,
217 const char *sname, struct md_object *tobj,
218 const char *tname, struct md_attr *ma);
220 int (*mdo_link)(const struct lu_env *env, struct md_object *tgt_obj,
221 struct md_object *src_obj, const char *name,
224 int (*mdo_unlink)(const struct lu_env *env, struct md_object *pobj,
225 struct md_object *cobj, const char *name,
228 /* partial ops for cross-ref case */
229 int (*mdo_name_insert)(const struct lu_env *env, struct md_object *obj,
230 const char *name, const struct lu_fid *fid,
233 int (*mdo_name_remove)(const struct lu_env *env, struct md_object *obj,
234 const char *name, int is_dir);
236 int (*mdo_rename_tgt)(const struct lu_env *env, struct md_object *pobj,
237 struct md_object *tobj, const struct lu_fid *fid,
238 const char *name, struct md_attr *ma);
241 struct md_device_operations {
242 /* meta-data device related handlers. */
243 int (*mdo_root_get)(const struct lu_env *env, struct md_device *m,
246 int (*mdo_maxsize_get)(const struct lu_env *env, struct md_device *m,
247 int *md_size, int *cookie_size);
249 int (*mdo_statfs)(const struct lu_env *env, struct md_device *m,
250 struct kstatfs *sfs);
252 int (*mdo_init_capa_ctxt)(const struct lu_env *env, struct md_device *m,
253 int mode, unsigned long timeout, __u32 alg,
254 struct lustre_capa_key *keys);
256 int (*mdo_update_capa_key)(const struct lu_env *env,
258 struct lustre_capa_key *key);
261 enum md_upcall_event {
262 /*sync the md layer*/
263 MD_LOV_SYNC = (1 << 0),
264 MD_NO_TRANS = (1 << 1), /* Just for split, no need trans, for replay */
268 struct md_device *mu_upcall_dev;
269 int (*mu_upcall)(const struct lu_env *env, struct md_device *md,
270 enum md_upcall_event ev);
274 struct lu_device md_lu_dev;
275 struct md_device_operations *md_ops;
276 struct md_upcall md_upcall;
280 struct lu_object mo_lu;
281 struct md_object_operations *mo_ops;
282 struct md_dir_operations *mo_dir_ops;
285 static inline int lu_device_is_md(const struct lu_device *d)
287 return ergo(d != NULL, d->ld_type->ldt_tags & LU_DEVICE_MD);
290 static inline struct md_device *lu2md_dev(const struct lu_device *d)
292 LASSERT(lu_device_is_md(d));
293 return container_of0(d, struct md_device, md_lu_dev);
296 static inline struct lu_device *md2lu_dev(struct md_device *d)
298 return &d->md_lu_dev;
301 static inline struct md_object *lu2md(const struct lu_object *o)
303 LASSERT(lu_device_is_md(o->lo_dev));
304 return container_of0(o, struct md_object, mo_lu);
307 static inline struct md_object *md_object_next(const struct md_object *obj)
309 return (obj ? lu2md(lu_object_next(&obj->mo_lu)) : NULL);
312 static inline struct md_device *md_obj2dev(const struct md_object *o)
314 LASSERT(lu_device_is_md(o->mo_lu.lo_dev));
315 return container_of0(o->mo_lu.lo_dev, struct md_device, md_lu_dev);
318 static inline int md_device_init(struct md_device *md, struct lu_device_type *t)
320 return lu_device_init(&md->md_lu_dev, t);
323 static inline void md_device_fini(struct md_device *md)
325 lu_device_fini(&md->md_lu_dev);
329 static inline int mo_permission(const struct lu_env *env,
333 LASSERT(m->mo_ops->moo_permission);
334 return m->mo_ops->moo_permission(env, m, mask);
337 static inline int mo_attr_get(const struct lu_env *env,
341 LASSERT(m->mo_ops->moo_attr_get);
342 return m->mo_ops->moo_attr_get(env, m, at);
345 static inline int mo_readlink(const struct lu_env *env,
349 LASSERT(m->mo_ops->moo_readlink);
350 return m->mo_ops->moo_readlink(env, m, buf);
353 static inline int mo_attr_set(const struct lu_env *env,
355 const struct md_attr *at)
357 LASSERT(m->mo_ops->moo_attr_set);
358 return m->mo_ops->moo_attr_set(env, m, at);
361 static inline int mo_xattr_get(const struct lu_env *env,
366 LASSERT(m->mo_ops->moo_xattr_get);
367 return m->mo_ops->moo_xattr_get(env, m, buf, name);
370 static inline int mo_xattr_del(const struct lu_env *env,
374 LASSERT(m->mo_ops->moo_xattr_del);
375 return m->mo_ops->moo_xattr_del(env, m, name);
378 static inline int mo_xattr_set(const struct lu_env *env,
380 const struct lu_buf *buf,
384 LASSERT(m->mo_ops->moo_xattr_set);
385 return m->mo_ops->moo_xattr_set(env, m, buf, name, flags);
388 static inline int mo_xattr_list(const struct lu_env *env,
392 LASSERT(m->mo_ops->moo_xattr_list);
393 return m->mo_ops->moo_xattr_list(env, m, buf);
396 static inline int mo_open(const struct lu_env *env,
400 LASSERT(m->mo_ops->moo_open);
401 return m->mo_ops->moo_open(env, m, flags);
404 static inline int mo_close(const struct lu_env *env,
408 LASSERT(m->mo_ops->moo_close);
409 return m->mo_ops->moo_close(env, m, ma);
412 static inline int mo_readpage(const struct lu_env *env,
414 const struct lu_rdpg *rdpg)
416 LASSERT(m->mo_ops->moo_readpage);
417 return m->mo_ops->moo_readpage(env, m, rdpg);
420 static inline int mo_object_create(const struct lu_env *env,
422 const struct md_create_spec *spc,
425 LASSERT(m->mo_ops->moo_object_create);
426 return m->mo_ops->moo_object_create(env, m, spc, at);
429 static inline int mo_ref_add(const struct lu_env *env,
432 LASSERT(m->mo_ops->moo_ref_add);
433 return m->mo_ops->moo_ref_add(env, m);
436 static inline int mo_ref_del(const struct lu_env *env,
440 LASSERT(m->mo_ops->moo_ref_del);
441 return m->mo_ops->moo_ref_del(env, m, ma);
444 static inline int mo_capa_get(const struct lu_env *env,
446 struct lustre_capa *c,
449 LASSERT(m->mo_ops->moo_capa_get);
450 return m->mo_ops->moo_capa_get(env, m, c, renewal);
453 static inline int mdo_lookup(const struct lu_env *env,
458 LASSERT(p->mo_dir_ops->mdo_lookup);
459 return p->mo_dir_ops->mdo_lookup(env, p, name, f);
462 static inline lu_mode_t mdo_lock_mode(const struct lu_env *env,
463 struct md_object *mo,
466 if (mo->mo_dir_ops->mdo_lock_mode == NULL)
468 return mo->mo_dir_ops->mdo_lock_mode(env, mo, lm);
471 static inline int mdo_create(const struct lu_env *env,
473 const char *child_name,
475 struct md_create_spec *spc,
478 LASSERT(c->mo_dir_ops->mdo_create);
479 return c->mo_dir_ops->mdo_create(env, p, child_name, c, spc, at);
482 static inline int mdo_create_data(const struct lu_env *env,
485 const struct md_create_spec *spec,
488 LASSERT(c->mo_dir_ops->mdo_create_data);
489 return c->mo_dir_ops->mdo_create_data(env, p, c, spec, ma);
492 static inline int mdo_rename(const struct lu_env *env,
493 struct md_object *sp,
494 struct md_object *tp,
495 const struct lu_fid *lf,
501 LASSERT(tp->mo_dir_ops->mdo_rename);
502 return tp->mo_dir_ops->mdo_rename(env, sp, tp, lf, sname, t, tname, ma);
505 static inline int mdo_is_subdir(const struct lu_env *env,
506 struct md_object *mo,
507 const struct lu_fid *fid,
510 LASSERT(mo->mo_dir_ops->mdo_is_subdir);
511 return mo->mo_dir_ops->mdo_is_subdir(env, mo, fid, sfid);
514 static inline int mdo_link(const struct lu_env *env,
520 LASSERT(s->mo_dir_ops->mdo_link);
521 return s->mo_dir_ops->mdo_link(env, p, s, name, ma);
524 static inline int mdo_unlink(const struct lu_env *env,
530 LASSERT(c->mo_dir_ops->mdo_unlink);
531 return c->mo_dir_ops->mdo_unlink(env, p, c, name, ma);
534 static inline int mdo_name_insert(const struct lu_env *env,
537 const struct lu_fid *f,
540 LASSERT(p->mo_dir_ops->mdo_name_insert);
541 return p->mo_dir_ops->mdo_name_insert(env, p, name, f, isdir);
544 static inline int mdo_name_remove(const struct lu_env *env,
546 const char *name, int is_dir)
548 LASSERT(p->mo_dir_ops->mdo_name_remove);
549 return p->mo_dir_ops->mdo_name_remove(env, p, name, is_dir);
552 static inline int mdo_rename_tgt(const struct lu_env *env,
555 const struct lu_fid *lf,
560 LASSERT(t->mo_dir_ops->mdo_rename_tgt);
561 return t->mo_dir_ops->mdo_rename_tgt(env, p, t, lf, name, ma);
563 LASSERT(p->mo_dir_ops->mdo_rename_tgt);
564 return p->mo_dir_ops->mdo_rename_tgt(env, p, t, lf, name, ma);
568 #endif /* _LINUX_MD_OBJECT_H */