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 #define MD_CAPAINFO_MAX 5
81 /* there are at most 5 fids in one operation, see rename, NOTE the last one
82 * is a temporary one used for is_subdir() */
84 const struct lu_fid *mc_fid[MD_CAPAINFO_MAX];
85 struct lustre_capa *mc_capa[MD_CAPAINFO_MAX];
89 * Implemented in mdd/mdd_handler.c.
91 * XXX should be moved into separate .h/.c together with all md security
92 * related definitions.
94 struct md_ucred *md_ucred(const struct lu_env *env);
95 struct md_capainfo *md_capainfo(const struct lu_env *env);
97 /* metadata attributes */
101 MA_COOKIE = (1 << 2),
104 MA_ACL_DEF = (1 << 5)
121 MDT_REG_LOCK = (1 << 0),
122 MDT_PDO_LOCK = (1 << 1)
129 struct lu_attr ma_attr;
130 struct lov_mds_md *ma_lmm;
132 struct lmv_stripe_md *ma_lmv;
136 struct llog_cookie *ma_cookie;
138 struct lustre_capa *ma_capa;
141 /* Additional parameters for create */
145 const char *sp_symname;
146 /* parent FID for cross-ref mkdir */
147 const struct lu_fid *sp_pfid;
148 /* eadata for regular files */
150 /* lov objs exist already */
151 const struct lu_fid *fid;
158 /* Create flag from client: such as MDS_OPEN_CREAT, and others. */
161 /* Should mdd do lookup sanity check or not. */
164 /* Current lock mode for parent dir where create is performing. */
165 mdl_mode_t sp_cr_mode;
167 /* Check for split */
172 * Operations implemented for each md object (both directory and leaf).
174 struct md_object_operations {
175 int (*moo_permission)(const struct lu_env *env,
176 struct md_object *pobj, struct md_object *cobj,
177 struct md_attr *attr, int mask);
179 int (*moo_attr_get)(const struct lu_env *env, struct md_object *obj,
180 struct md_attr *attr);
182 int (*moo_attr_set)(const struct lu_env *env, struct md_object *obj,
183 const struct md_attr *attr);
185 int (*moo_xattr_get)(const struct lu_env *env, struct md_object *obj,
186 struct lu_buf *buf, const char *name);
188 int (*moo_xattr_list)(const struct lu_env *env, struct md_object *obj,
191 int (*moo_xattr_set)(const struct lu_env *env, struct md_object *obj,
192 const struct lu_buf *buf, const char *name,
195 int (*moo_xattr_del)(const struct lu_env *env, struct md_object *obj,
198 int (*moo_readpage)(const struct lu_env *env, struct md_object *obj,
199 const struct lu_rdpg *rdpg);
201 int (*moo_readlink)(const struct lu_env *env, struct md_object *obj,
204 /* part of cross-ref operation */
205 int (*moo_object_create)(const struct lu_env *env,
206 struct md_object *obj,
207 const struct md_op_spec *spec,
210 int (*moo_ref_add)(const struct lu_env *env,
211 struct md_object *obj,
212 const struct md_attr *ma);
214 int (*moo_ref_del)(const struct lu_env *env,
215 struct md_object *obj,
218 int (*moo_open)(const struct lu_env *env,
219 struct md_object *obj, int flag);
221 int (*moo_close)(const struct lu_env *env, struct md_object *obj,
224 int (*moo_capa_get)(const struct lu_env *, struct md_object *,
225 struct lustre_capa *, int renewal);
229 * Operations implemented for each directory object.
231 struct md_dir_operations {
232 int (*mdo_is_subdir) (const struct lu_env *env, struct md_object *obj,
233 const struct lu_fid *fid, struct lu_fid *sfid);
235 int (*mdo_lookup)(const struct lu_env *env, struct md_object *obj,
236 const struct lu_name *lname, struct lu_fid *fid,
237 struct md_op_spec *spec);
239 mdl_mode_t (*mdo_lock_mode)(const struct lu_env *env,
240 struct md_object *obj,
243 int (*mdo_create)(const struct lu_env *env, struct md_object *pobj,
244 const struct lu_name *lname, struct md_object *child,
245 struct md_op_spec *spec,
248 /* This method is used for creating data object for this meta object*/
249 int (*mdo_create_data)(const struct lu_env *env, struct md_object *p,
251 const struct md_op_spec *spec,
254 int (*mdo_rename)(const struct lu_env *env, struct md_object *spobj,
255 struct md_object *tpobj, const struct lu_fid *lf,
256 const struct lu_name *lsname, struct md_object *tobj,
257 const struct lu_name *ltname, struct md_attr *ma);
259 int (*mdo_link)(const struct lu_env *env, struct md_object *tgt_obj,
260 struct md_object *src_obj, const struct lu_name *lname,
263 int (*mdo_unlink)(const struct lu_env *env, struct md_object *pobj,
264 struct md_object *cobj, const struct lu_name *lname,
267 /* partial ops for cross-ref case */
268 int (*mdo_name_insert)(const struct lu_env *env,
269 struct md_object *obj,
270 const struct lu_name *lname,
271 const struct lu_fid *fid,
272 const struct md_attr *ma);
274 int (*mdo_name_remove)(const struct lu_env *env,
275 struct md_object *obj,
276 const struct lu_name *lname,
277 const struct md_attr *ma);
279 int (*mdo_rename_tgt)(const struct lu_env *env, struct md_object *pobj,
280 struct md_object *tobj, const struct lu_fid *fid,
281 const struct lu_name *lname, struct md_attr *ma);
284 struct md_device_operations {
285 /* meta-data device related handlers. */
286 int (*mdo_root_get)(const struct lu_env *env, struct md_device *m,
289 int (*mdo_maxsize_get)(const struct lu_env *env, struct md_device *m,
290 int *md_size, int *cookie_size);
292 int (*mdo_statfs)(const struct lu_env *env, struct md_device *m,
293 struct kstatfs *sfs);
295 int (*mdo_init_capa_ctxt)(const struct lu_env *env, struct md_device *m,
296 int mode, unsigned long timeout, __u32 alg,
297 struct lustre_capa_key *keys);
299 int (*mdo_update_capa_key)(const struct lu_env *env,
301 struct lustre_capa_key *key);
304 enum md_upcall_event {
305 /*sync the md layer*/
306 MD_LOV_SYNC = (1 << 0),
307 MD_NO_TRANS = (1 << 1), /* Just for split, no need trans, for replay */
311 /* this lock protects upcall using against its removal
312 * read lock is for usage the upcall, write - for init/fini */
313 struct rw_semaphore mu_upcall_sem;
314 /* device to call, upper layer normally */
315 struct md_device *mu_upcall_dev;
316 /* upcall function */
317 int (*mu_upcall)(const struct lu_env *env, struct md_device *md,
318 enum md_upcall_event ev);
322 struct lu_device md_lu_dev;
323 struct md_device_operations *md_ops;
324 struct md_upcall md_upcall;
327 static inline void md_upcall_init(struct md_device *m, void *upcl)
329 init_rwsem(&m->md_upcall.mu_upcall_sem);
330 m->md_upcall.mu_upcall_dev = NULL;
331 m->md_upcall.mu_upcall = upcl;
334 static inline void md_upcall_dev_set(struct md_device *m, struct md_device *up)
336 down_write(&m->md_upcall.mu_upcall_sem);
337 m->md_upcall.mu_upcall_dev = up;
338 up_write(&m->md_upcall.mu_upcall_sem);
341 static inline void md_upcall_fini(struct md_device *m)
343 down_write(&m->md_upcall.mu_upcall_sem);
344 m->md_upcall.mu_upcall_dev = NULL;
345 m->md_upcall.mu_upcall = NULL;
346 up_write(&m->md_upcall.mu_upcall_sem);
349 static inline int md_do_upcall(const struct lu_env *env, struct md_device *m,
350 enum md_upcall_event ev)
353 down_read(&m->md_upcall.mu_upcall_sem);
354 if (m->md_upcall.mu_upcall_dev != NULL &&
355 m->md_upcall.mu_upcall_dev->md_upcall.mu_upcall != NULL) {
356 rc = m->md_upcall.mu_upcall_dev->md_upcall.mu_upcall(env,
357 m->md_upcall.mu_upcall_dev, ev);
359 up_read(&m->md_upcall.mu_upcall_sem);
364 struct lu_object mo_lu;
365 struct md_object_operations *mo_ops;
366 struct md_dir_operations *mo_dir_ops;
369 static inline int lu_device_is_md(const struct lu_device *d)
371 return ergo(d != NULL, d->ld_type->ldt_tags & LU_DEVICE_MD);
374 static inline struct md_device *lu2md_dev(const struct lu_device *d)
376 LASSERT(lu_device_is_md(d));
377 return container_of0(d, struct md_device, md_lu_dev);
380 static inline struct lu_device *md2lu_dev(struct md_device *d)
382 return &d->md_lu_dev;
385 static inline struct md_object *lu2md(const struct lu_object *o)
387 LASSERT(lu_device_is_md(o->lo_dev));
388 return container_of0(o, struct md_object, mo_lu);
391 static inline struct md_object *md_object_next(const struct md_object *obj)
393 return (obj ? lu2md(lu_object_next(&obj->mo_lu)) : NULL);
396 static inline struct md_device *md_obj2dev(const struct md_object *o)
398 LASSERT(lu_device_is_md(o->mo_lu.lo_dev));
399 return container_of0(o->mo_lu.lo_dev, struct md_device, md_lu_dev);
402 static inline int md_device_init(struct md_device *md, struct lu_device_type *t)
404 return lu_device_init(&md->md_lu_dev, t);
407 static inline void md_device_fini(struct md_device *md)
409 lu_device_fini(&md->md_lu_dev);
413 static inline int mo_permission(const struct lu_env *env,
419 LASSERT(c->mo_ops->moo_permission);
420 return c->mo_ops->moo_permission(env, p, c, at, mask);
423 static inline int mo_attr_get(const struct lu_env *env,
427 LASSERT(m->mo_ops->moo_attr_get);
428 return m->mo_ops->moo_attr_get(env, m, at);
431 static inline int mo_readlink(const struct lu_env *env,
435 LASSERT(m->mo_ops->moo_readlink);
436 return m->mo_ops->moo_readlink(env, m, buf);
439 static inline int mo_attr_set(const struct lu_env *env,
441 const struct md_attr *at)
443 LASSERT(m->mo_ops->moo_attr_set);
444 return m->mo_ops->moo_attr_set(env, m, at);
447 static inline int mo_xattr_get(const struct lu_env *env,
452 LASSERT(m->mo_ops->moo_xattr_get);
453 return m->mo_ops->moo_xattr_get(env, m, buf, name);
456 static inline int mo_xattr_del(const struct lu_env *env,
460 LASSERT(m->mo_ops->moo_xattr_del);
461 return m->mo_ops->moo_xattr_del(env, m, name);
464 static inline int mo_xattr_set(const struct lu_env *env,
466 const struct lu_buf *buf,
470 LASSERT(m->mo_ops->moo_xattr_set);
471 return m->mo_ops->moo_xattr_set(env, m, buf, name, flags);
474 static inline int mo_xattr_list(const struct lu_env *env,
478 LASSERT(m->mo_ops->moo_xattr_list);
479 return m->mo_ops->moo_xattr_list(env, m, buf);
482 static inline int mo_open(const struct lu_env *env,
486 LASSERT(m->mo_ops->moo_open);
487 return m->mo_ops->moo_open(env, m, flags);
490 static inline int mo_close(const struct lu_env *env,
494 LASSERT(m->mo_ops->moo_close);
495 return m->mo_ops->moo_close(env, m, ma);
498 static inline int mo_readpage(const struct lu_env *env,
500 const struct lu_rdpg *rdpg)
502 LASSERT(m->mo_ops->moo_readpage);
503 return m->mo_ops->moo_readpage(env, m, rdpg);
506 static inline int mo_object_create(const struct lu_env *env,
508 const struct md_op_spec *spc,
511 LASSERT(m->mo_ops->moo_object_create);
512 return m->mo_ops->moo_object_create(env, m, spc, at);
515 static inline int mo_ref_add(const struct lu_env *env,
517 const struct md_attr *ma)
519 LASSERT(m->mo_ops->moo_ref_add);
520 return m->mo_ops->moo_ref_add(env, m, ma);
523 static inline int mo_ref_del(const struct lu_env *env,
527 LASSERT(m->mo_ops->moo_ref_del);
528 return m->mo_ops->moo_ref_del(env, m, ma);
531 static inline int mo_capa_get(const struct lu_env *env,
533 struct lustre_capa *c,
536 LASSERT(m->mo_ops->moo_capa_get);
537 return m->mo_ops->moo_capa_get(env, m, c, renewal);
540 static inline int mdo_lookup(const struct lu_env *env,
542 const struct lu_name *lname,
544 struct md_op_spec *spec)
546 LASSERT(p->mo_dir_ops->mdo_lookup);
547 return p->mo_dir_ops->mdo_lookup(env, p, lname, f, spec);
550 static inline mdl_mode_t mdo_lock_mode(const struct lu_env *env,
551 struct md_object *mo,
554 if (mo->mo_dir_ops->mdo_lock_mode == NULL)
556 return mo->mo_dir_ops->mdo_lock_mode(env, mo, lm);
559 static inline int mdo_create(const struct lu_env *env,
561 const struct lu_name *lchild_name,
563 struct md_op_spec *spc,
566 LASSERT(c->mo_dir_ops->mdo_create);
567 return c->mo_dir_ops->mdo_create(env, p, lchild_name, c, spc, at);
570 static inline int mdo_create_data(const struct lu_env *env,
573 const struct md_op_spec *spec,
576 LASSERT(c->mo_dir_ops->mdo_create_data);
577 return c->mo_dir_ops->mdo_create_data(env, p, c, spec, ma);
580 static inline int mdo_rename(const struct lu_env *env,
581 struct md_object *sp,
582 struct md_object *tp,
583 const struct lu_fid *lf,
584 const struct lu_name *lsname,
586 const struct lu_name *ltname,
589 LASSERT(tp->mo_dir_ops->mdo_rename);
590 return tp->mo_dir_ops->mdo_rename(env, sp, tp, lf, lsname, t, ltname,
594 static inline int mdo_is_subdir(const struct lu_env *env,
595 struct md_object *mo,
596 const struct lu_fid *fid,
599 LASSERT(mo->mo_dir_ops->mdo_is_subdir);
600 return mo->mo_dir_ops->mdo_is_subdir(env, mo, fid, sfid);
603 static inline int mdo_link(const struct lu_env *env,
606 const struct lu_name *lname,
609 LASSERT(s->mo_dir_ops->mdo_link);
610 return s->mo_dir_ops->mdo_link(env, p, s, lname, ma);
613 static inline int mdo_unlink(const struct lu_env *env,
616 const struct lu_name *lname,
619 LASSERT(c->mo_dir_ops->mdo_unlink);
620 return c->mo_dir_ops->mdo_unlink(env, p, c, lname, ma);
623 static inline int mdo_name_insert(const struct lu_env *env,
625 const struct lu_name *lname,
626 const struct lu_fid *f,
627 const struct md_attr *ma)
629 LASSERT(p->mo_dir_ops->mdo_name_insert);
630 return p->mo_dir_ops->mdo_name_insert(env, p, lname, f, ma);
633 static inline int mdo_name_remove(const struct lu_env *env,
635 const struct lu_name *lname,
636 const struct md_attr *ma)
638 LASSERT(p->mo_dir_ops->mdo_name_remove);
639 return p->mo_dir_ops->mdo_name_remove(env, p, lname, ma);
642 static inline int mdo_rename_tgt(const struct lu_env *env,
645 const struct lu_fid *lf,
646 const struct lu_name *lname,
650 LASSERT(t->mo_dir_ops->mdo_rename_tgt);
651 return t->mo_dir_ops->mdo_rename_tgt(env, p, t, lf, lname, ma);
653 LASSERT(p->mo_dir_ops->mdo_rename_tgt);
654 return p->mo_dir_ops->mdo_rename_tgt(env, p, t, lf, lname, ma);
658 #endif /* _LINUX_MD_OBJECT_H */