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;
70 struct group_info *mu_ginfo;
71 struct md_identity *mu_identity;
74 #define MD_CAPAINFO_MAX 5
76 /* there are at most 5 fids in one operation, see rename, NOTE the last one
77 * is a temporary one used for is_subdir() */
79 const struct lu_fid *mc_fid[MD_CAPAINFO_MAX];
80 struct lustre_capa *mc_capa[MD_CAPAINFO_MAX];
84 * Implemented in mdd/mdd_handler.c.
86 * XXX should be moved into separate .h/.c together with all md security
87 * related definitions.
89 struct md_ucred *md_ucred(const struct lu_env *env);
90 struct md_capainfo *md_capainfo(const struct lu_env *env);
92 /* metadata attributes */
99 MA_ACL_DEF = (1 << 5),
100 MA_LOV_DEF = (1 << 6)
117 MDT_REG_LOCK = (1 << 0),
118 MDT_PDO_LOCK = (1 << 1)
125 struct lu_attr ma_attr;
126 struct lov_mds_md *ma_lmm;
128 struct lmv_stripe_md *ma_lmv;
132 struct llog_cookie *ma_cookie;
134 struct lustre_capa *ma_capa;
137 /* Additional parameters for create */
141 const char *sp_symname;
142 /* parent FID for cross-ref mkdir */
143 const struct lu_fid *sp_pfid;
144 /* eadata for regular files */
146 /* lov objs exist already */
147 const struct lu_fid *fid;
154 /* Create flag from client: such as MDS_OPEN_CREAT, and others. */
157 /* Should mdd do lookup sanity check or not. */
160 /* Current lock mode for parent dir where create is performing. */
161 mdl_mode_t sp_cr_mode;
163 /* Check for split */
168 * Operations implemented for each md object (both directory and leaf).
170 struct md_object_operations {
171 int (*moo_permission)(const struct lu_env *env,
172 struct md_object *pobj, struct md_object *cobj,
173 struct md_attr *attr, int mask);
175 int (*moo_attr_get)(const struct lu_env *env, struct md_object *obj,
176 struct md_attr *attr);
178 int (*moo_attr_set)(const struct lu_env *env, struct md_object *obj,
179 const struct md_attr *attr);
181 int (*moo_xattr_get)(const struct lu_env *env, struct md_object *obj,
182 struct lu_buf *buf, const char *name);
184 int (*moo_xattr_list)(const struct lu_env *env, struct md_object *obj,
187 int (*moo_xattr_set)(const struct lu_env *env, struct md_object *obj,
188 const struct lu_buf *buf, const char *name,
189 int fl, const struct lu_attr *la);
191 int (*moo_xattr_del)(const struct lu_env *env, struct md_object *obj,
192 const char *name, const struct lu_attr *la);
194 int (*moo_readpage)(const struct lu_env *env, struct md_object *obj,
195 const struct lu_rdpg *rdpg);
197 int (*moo_readlink)(const struct lu_env *env, struct md_object *obj,
200 /* part of cross-ref operation */
201 int (*moo_object_create)(const struct lu_env *env,
202 struct md_object *obj,
203 const struct md_op_spec *spec,
206 int (*moo_ref_add)(const struct lu_env *env,
207 struct md_object *obj,
208 const struct md_attr *ma);
210 int (*moo_ref_del)(const struct lu_env *env,
211 struct md_object *obj,
214 int (*moo_open)(const struct lu_env *env,
215 struct md_object *obj, int flag);
217 int (*moo_close)(const struct lu_env *env, struct md_object *obj,
220 int (*moo_capa_get)(const struct lu_env *, struct md_object *,
221 struct lustre_capa *, int renewal);
225 * Operations implemented for each directory object.
227 struct md_dir_operations {
228 int (*mdo_is_subdir) (const struct lu_env *env, struct md_object *obj,
229 const struct lu_fid *fid, struct lu_fid *sfid);
231 int (*mdo_lookup)(const struct lu_env *env, struct md_object *obj,
232 const struct lu_name *lname, struct lu_fid *fid,
233 struct md_op_spec *spec);
235 mdl_mode_t (*mdo_lock_mode)(const struct lu_env *env,
236 struct md_object *obj,
239 int (*mdo_create)(const struct lu_env *env, struct md_object *pobj,
240 const struct lu_name *lname, struct md_object *child,
241 struct md_op_spec *spec,
244 /* This method is used for creating data object for this meta object*/
245 int (*mdo_create_data)(const struct lu_env *env, struct md_object *p,
247 const struct md_op_spec *spec,
250 int (*mdo_rename)(const struct lu_env *env, struct md_object *spobj,
251 struct md_object *tpobj, const struct lu_fid *lf,
252 const struct lu_name *lsname, struct md_object *tobj,
253 const struct lu_name *ltname, struct md_attr *ma);
255 int (*mdo_link)(const struct lu_env *env, struct md_object *tgt_obj,
256 struct md_object *src_obj, const struct lu_name *lname,
259 int (*mdo_unlink)(const struct lu_env *env, struct md_object *pobj,
260 struct md_object *cobj, const struct lu_name *lname,
263 /* partial ops for cross-ref case */
264 int (*mdo_name_insert)(const struct lu_env *env,
265 struct md_object *obj,
266 const struct lu_name *lname,
267 const struct lu_fid *fid,
268 const struct md_attr *ma);
270 int (*mdo_name_remove)(const struct lu_env *env,
271 struct md_object *obj,
272 const struct lu_name *lname,
273 const struct md_attr *ma);
275 int (*mdo_rename_tgt)(const struct lu_env *env, struct md_object *pobj,
276 struct md_object *tobj, const struct lu_fid *fid,
277 const struct lu_name *lname, struct md_attr *ma);
280 struct md_device_operations {
281 /* meta-data device related handlers. */
282 int (*mdo_root_get)(const struct lu_env *env, struct md_device *m,
285 int (*mdo_maxsize_get)(const struct lu_env *env, struct md_device *m,
286 int *md_size, int *cookie_size);
288 int (*mdo_statfs)(const struct lu_env *env, struct md_device *m,
289 struct kstatfs *sfs);
291 int (*mdo_init_capa_ctxt)(const struct lu_env *env, struct md_device *m,
292 int mode, unsigned long timeout, __u32 alg,
293 struct lustre_capa_key *keys);
295 int (*mdo_update_capa_key)(const struct lu_env *env,
297 struct lustre_capa_key *key);
300 enum md_upcall_event {
301 /*sync the md layer*/
302 MD_LOV_SYNC = (1 << 0),
303 MD_NO_TRANS = (1 << 1), /* Just for split, no need trans, for replay */
304 MD_LOV_CONFIG = (1 << 2)
308 /* this lock protects upcall using against its removal
309 * read lock is for usage the upcall, write - for init/fini */
310 struct rw_semaphore mu_upcall_sem;
311 /* device to call, upper layer normally */
312 struct md_device *mu_upcall_dev;
313 /* upcall function */
314 int (*mu_upcall)(const struct lu_env *env, struct md_device *md,
315 enum md_upcall_event ev);
319 struct lu_device md_lu_dev;
320 struct md_device_operations *md_ops;
321 struct md_upcall md_upcall;
324 static inline void md_upcall_init(struct md_device *m, void *upcl)
326 init_rwsem(&m->md_upcall.mu_upcall_sem);
327 m->md_upcall.mu_upcall_dev = NULL;
328 m->md_upcall.mu_upcall = upcl;
331 static inline void md_upcall_dev_set(struct md_device *m, struct md_device *up)
333 down_write(&m->md_upcall.mu_upcall_sem);
334 m->md_upcall.mu_upcall_dev = up;
335 up_write(&m->md_upcall.mu_upcall_sem);
338 static inline void md_upcall_fini(struct md_device *m)
340 down_write(&m->md_upcall.mu_upcall_sem);
341 m->md_upcall.mu_upcall_dev = NULL;
342 m->md_upcall.mu_upcall = NULL;
343 up_write(&m->md_upcall.mu_upcall_sem);
346 static inline int md_do_upcall(const struct lu_env *env, struct md_device *m,
347 enum md_upcall_event ev)
350 down_read(&m->md_upcall.mu_upcall_sem);
351 if (m->md_upcall.mu_upcall_dev != NULL &&
352 m->md_upcall.mu_upcall_dev->md_upcall.mu_upcall != NULL) {
353 rc = m->md_upcall.mu_upcall_dev->md_upcall.mu_upcall(env,
354 m->md_upcall.mu_upcall_dev, ev);
356 up_read(&m->md_upcall.mu_upcall_sem);
361 struct lu_object mo_lu;
362 struct md_object_operations *mo_ops;
363 struct md_dir_operations *mo_dir_ops;
366 static inline int lu_device_is_md(const struct lu_device *d)
368 return ergo(d != NULL, d->ld_type->ldt_tags & LU_DEVICE_MD);
371 static inline struct md_device *lu2md_dev(const struct lu_device *d)
373 LASSERT(lu_device_is_md(d));
374 return container_of0(d, struct md_device, md_lu_dev);
377 static inline struct lu_device *md2lu_dev(struct md_device *d)
379 return &d->md_lu_dev;
382 static inline struct md_object *lu2md(const struct lu_object *o)
384 LASSERT(lu_device_is_md(o->lo_dev));
385 return container_of0(o, struct md_object, mo_lu);
388 static inline struct md_object *md_object_next(const struct md_object *obj)
390 return (obj ? lu2md(lu_object_next(&obj->mo_lu)) : NULL);
393 static inline struct md_device *md_obj2dev(const struct md_object *o)
395 LASSERT(lu_device_is_md(o->mo_lu.lo_dev));
396 return container_of0(o->mo_lu.lo_dev, struct md_device, md_lu_dev);
399 static inline int md_device_init(struct md_device *md, struct lu_device_type *t)
401 return lu_device_init(&md->md_lu_dev, t);
404 static inline void md_device_fini(struct md_device *md)
406 lu_device_fini(&md->md_lu_dev);
410 static inline int mo_permission(const struct lu_env *env,
416 LASSERT(c->mo_ops->moo_permission);
417 return c->mo_ops->moo_permission(env, p, c, at, mask);
420 static inline int mo_attr_get(const struct lu_env *env,
424 LASSERT(m->mo_ops->moo_attr_get);
425 return m->mo_ops->moo_attr_get(env, m, at);
428 static inline int mo_readlink(const struct lu_env *env,
432 LASSERT(m->mo_ops->moo_readlink);
433 return m->mo_ops->moo_readlink(env, m, buf);
436 static inline int mo_attr_set(const struct lu_env *env,
438 const struct md_attr *at)
440 LASSERT(m->mo_ops->moo_attr_set);
441 return m->mo_ops->moo_attr_set(env, m, at);
444 static inline int mo_xattr_get(const struct lu_env *env,
449 LASSERT(m->mo_ops->moo_xattr_get);
450 return m->mo_ops->moo_xattr_get(env, m, buf, name);
453 static inline int mo_xattr_del(const struct lu_env *env,
456 const struct lu_attr *la)
458 LASSERT(m->mo_ops->moo_xattr_del);
459 return m->mo_ops->moo_xattr_del(env, m, name, la);
462 static inline int mo_xattr_set(const struct lu_env *env,
464 const struct lu_buf *buf,
467 const struct lu_attr *la)
469 LASSERT(m->mo_ops->moo_xattr_set);
470 return m->mo_ops->moo_xattr_set(env, m, buf, name, flags, la);
473 static inline int mo_xattr_list(const struct lu_env *env,
477 LASSERT(m->mo_ops->moo_xattr_list);
478 return m->mo_ops->moo_xattr_list(env, m, buf);
481 static inline int mo_open(const struct lu_env *env,
485 LASSERT(m->mo_ops->moo_open);
486 return m->mo_ops->moo_open(env, m, flags);
489 static inline int mo_close(const struct lu_env *env,
493 LASSERT(m->mo_ops->moo_close);
494 return m->mo_ops->moo_close(env, m, ma);
497 static inline int mo_readpage(const struct lu_env *env,
499 const struct lu_rdpg *rdpg)
501 LASSERT(m->mo_ops->moo_readpage);
502 return m->mo_ops->moo_readpage(env, m, rdpg);
505 static inline int mo_object_create(const struct lu_env *env,
507 const struct md_op_spec *spc,
510 LASSERT(m->mo_ops->moo_object_create);
511 return m->mo_ops->moo_object_create(env, m, spc, at);
514 static inline int mo_ref_add(const struct lu_env *env,
516 const struct md_attr *ma)
518 LASSERT(m->mo_ops->moo_ref_add);
519 return m->mo_ops->moo_ref_add(env, m, ma);
522 static inline int mo_ref_del(const struct lu_env *env,
526 LASSERT(m->mo_ops->moo_ref_del);
527 return m->mo_ops->moo_ref_del(env, m, ma);
530 static inline int mo_capa_get(const struct lu_env *env,
532 struct lustre_capa *c,
535 LASSERT(m->mo_ops->moo_capa_get);
536 return m->mo_ops->moo_capa_get(env, m, c, renewal);
539 static inline int mdo_lookup(const struct lu_env *env,
541 const struct lu_name *lname,
543 struct md_op_spec *spec)
545 LASSERT(p->mo_dir_ops->mdo_lookup);
546 return p->mo_dir_ops->mdo_lookup(env, p, lname, f, spec);
549 static inline mdl_mode_t mdo_lock_mode(const struct lu_env *env,
550 struct md_object *mo,
553 if (mo->mo_dir_ops->mdo_lock_mode == NULL)
555 return mo->mo_dir_ops->mdo_lock_mode(env, mo, lm);
558 static inline int mdo_create(const struct lu_env *env,
560 const struct lu_name *lchild_name,
562 struct md_op_spec *spc,
565 LASSERT(c->mo_dir_ops->mdo_create);
566 return c->mo_dir_ops->mdo_create(env, p, lchild_name, c, spc, at);
569 static inline int mdo_create_data(const struct lu_env *env,
572 const struct md_op_spec *spec,
575 LASSERT(c->mo_dir_ops->mdo_create_data);
576 return c->mo_dir_ops->mdo_create_data(env, p, c, spec, ma);
579 static inline int mdo_rename(const struct lu_env *env,
580 struct md_object *sp,
581 struct md_object *tp,
582 const struct lu_fid *lf,
583 const struct lu_name *lsname,
585 const struct lu_name *ltname,
588 LASSERT(tp->mo_dir_ops->mdo_rename);
589 return tp->mo_dir_ops->mdo_rename(env, sp, tp, lf, lsname, t, ltname,
593 static inline int mdo_is_subdir(const struct lu_env *env,
594 struct md_object *mo,
595 const struct lu_fid *fid,
598 LASSERT(mo->mo_dir_ops->mdo_is_subdir);
599 return mo->mo_dir_ops->mdo_is_subdir(env, mo, fid, sfid);
602 static inline int mdo_link(const struct lu_env *env,
605 const struct lu_name *lname,
608 LASSERT(s->mo_dir_ops->mdo_link);
609 return s->mo_dir_ops->mdo_link(env, p, s, lname, ma);
612 static inline int mdo_unlink(const struct lu_env *env,
615 const struct lu_name *lname,
618 LASSERT(c->mo_dir_ops->mdo_unlink);
619 return c->mo_dir_ops->mdo_unlink(env, p, c, lname, ma);
622 static inline int mdo_name_insert(const struct lu_env *env,
624 const struct lu_name *lname,
625 const struct lu_fid *f,
626 const struct md_attr *ma)
628 LASSERT(p->mo_dir_ops->mdo_name_insert);
629 return p->mo_dir_ops->mdo_name_insert(env, p, lname, f, ma);
632 static inline int mdo_name_remove(const struct lu_env *env,
634 const struct lu_name *lname,
635 const struct md_attr *ma)
637 LASSERT(p->mo_dir_ops->mdo_name_remove);
638 return p->mo_dir_ops->mdo_name_remove(env, p, lname, ma);
641 static inline int mdo_rename_tgt(const struct lu_env *env,
644 const struct lu_fid *lf,
645 const struct lu_name *lname,
649 LASSERT(t->mo_dir_ops->mdo_rename_tgt);
650 return t->mo_dir_ops->mdo_rename_tgt(env, p, t, lf, lname, ma);
652 LASSERT(p->mo_dir_ops->mdo_rename_tgt);
653 return p->mo_dir_ops->mdo_rename_tgt(env, p, t, lf, lname, ma);
657 #endif /* _LINUX_MD_OBJECT_H */