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),
105 MA_LOV_DEF = (1 << 6)
122 MDT_REG_LOCK = (1 << 0),
123 MDT_PDO_LOCK = (1 << 1)
130 struct lu_attr ma_attr;
131 struct lov_mds_md *ma_lmm;
133 struct lmv_stripe_md *ma_lmv;
137 struct llog_cookie *ma_cookie;
139 struct lustre_capa *ma_capa;
142 /* Additional parameters for create */
146 const char *sp_symname;
147 /* parent FID for cross-ref mkdir */
148 const struct lu_fid *sp_pfid;
149 /* eadata for regular files */
151 /* lov objs exist already */
152 const struct lu_fid *fid;
159 /* Create flag from client: such as MDS_OPEN_CREAT, and others. */
162 /* Should mdd do lookup sanity check or not. */
165 /* Current lock mode for parent dir where create is performing. */
166 mdl_mode_t sp_cr_mode;
168 /* Check for split */
173 * Operations implemented for each md object (both directory and leaf).
175 struct md_object_operations {
176 int (*moo_permission)(const struct lu_env *env,
177 struct md_object *pobj, struct md_object *cobj,
178 struct md_attr *attr, int mask);
180 int (*moo_attr_get)(const struct lu_env *env, struct md_object *obj,
181 struct md_attr *attr);
183 int (*moo_attr_set)(const struct lu_env *env, struct md_object *obj,
184 const struct md_attr *attr);
186 int (*moo_xattr_get)(const struct lu_env *env, struct md_object *obj,
187 struct lu_buf *buf, const char *name);
189 int (*moo_xattr_list)(const struct lu_env *env, struct md_object *obj,
192 int (*moo_xattr_set)(const struct lu_env *env, struct md_object *obj,
193 const struct lu_buf *buf, const char *name,
196 int (*moo_xattr_del)(const struct lu_env *env, struct md_object *obj,
199 int (*moo_readpage)(const struct lu_env *env, struct md_object *obj,
200 const struct lu_rdpg *rdpg);
202 int (*moo_readlink)(const struct lu_env *env, struct md_object *obj,
205 /* part of cross-ref operation */
206 int (*moo_object_create)(const struct lu_env *env,
207 struct md_object *obj,
208 const struct md_op_spec *spec,
211 int (*moo_ref_add)(const struct lu_env *env,
212 struct md_object *obj,
213 const struct md_attr *ma);
215 int (*moo_ref_del)(const struct lu_env *env,
216 struct md_object *obj,
219 int (*moo_open)(const struct lu_env *env,
220 struct md_object *obj, int flag);
222 int (*moo_close)(const struct lu_env *env, struct md_object *obj,
225 int (*moo_capa_get)(const struct lu_env *, struct md_object *,
226 struct lustre_capa *, int renewal);
230 * Operations implemented for each directory object.
232 struct md_dir_operations {
233 int (*mdo_is_subdir) (const struct lu_env *env, struct md_object *obj,
234 const struct lu_fid *fid, struct lu_fid *sfid);
236 int (*mdo_lookup)(const struct lu_env *env, struct md_object *obj,
237 const struct lu_name *lname, struct lu_fid *fid,
238 struct md_op_spec *spec);
240 mdl_mode_t (*mdo_lock_mode)(const struct lu_env *env,
241 struct md_object *obj,
244 int (*mdo_create)(const struct lu_env *env, struct md_object *pobj,
245 const struct lu_name *lname, struct md_object *child,
246 struct md_op_spec *spec,
249 /* This method is used for creating data object for this meta object*/
250 int (*mdo_create_data)(const struct lu_env *env, struct md_object *p,
252 const struct md_op_spec *spec,
255 int (*mdo_rename)(const struct lu_env *env, struct md_object *spobj,
256 struct md_object *tpobj, const struct lu_fid *lf,
257 const struct lu_name *lsname, struct md_object *tobj,
258 const struct lu_name *ltname, struct md_attr *ma);
260 int (*mdo_link)(const struct lu_env *env, struct md_object *tgt_obj,
261 struct md_object *src_obj, const struct lu_name *lname,
264 int (*mdo_unlink)(const struct lu_env *env, struct md_object *pobj,
265 struct md_object *cobj, const struct lu_name *lname,
268 /* partial ops for cross-ref case */
269 int (*mdo_name_insert)(const struct lu_env *env,
270 struct md_object *obj,
271 const struct lu_name *lname,
272 const struct lu_fid *fid,
273 const struct md_attr *ma);
275 int (*mdo_name_remove)(const struct lu_env *env,
276 struct md_object *obj,
277 const struct lu_name *lname,
278 const struct md_attr *ma);
280 int (*mdo_rename_tgt)(const struct lu_env *env, struct md_object *pobj,
281 struct md_object *tobj, const struct lu_fid *fid,
282 const struct lu_name *lname, struct md_attr *ma);
285 struct md_device_operations {
286 /* meta-data device related handlers. */
287 int (*mdo_root_get)(const struct lu_env *env, struct md_device *m,
290 int (*mdo_maxsize_get)(const struct lu_env *env, struct md_device *m,
291 int *md_size, int *cookie_size);
293 int (*mdo_statfs)(const struct lu_env *env, struct md_device *m,
294 struct kstatfs *sfs);
296 int (*mdo_init_capa_ctxt)(const struct lu_env *env, struct md_device *m,
297 int mode, unsigned long timeout, __u32 alg,
298 struct lustre_capa_key *keys);
300 int (*mdo_update_capa_key)(const struct lu_env *env,
302 struct lustre_capa_key *key);
305 enum md_upcall_event {
306 /*sync the md layer*/
307 MD_LOV_SYNC = (1 << 0),
308 MD_NO_TRANS = (1 << 1), /* Just for split, no need trans, for replay */
309 MD_LOV_CONFIG = (1 << 2)
313 /* this lock protects upcall using against its removal
314 * read lock is for usage the upcall, write - for init/fini */
315 struct rw_semaphore mu_upcall_sem;
316 /* device to call, upper layer normally */
317 struct md_device *mu_upcall_dev;
318 /* upcall function */
319 int (*mu_upcall)(const struct lu_env *env, struct md_device *md,
320 enum md_upcall_event ev);
324 struct lu_device md_lu_dev;
325 struct md_device_operations *md_ops;
326 struct md_upcall md_upcall;
329 static inline void md_upcall_init(struct md_device *m, void *upcl)
331 init_rwsem(&m->md_upcall.mu_upcall_sem);
332 m->md_upcall.mu_upcall_dev = NULL;
333 m->md_upcall.mu_upcall = upcl;
336 static inline void md_upcall_dev_set(struct md_device *m, struct md_device *up)
338 down_write(&m->md_upcall.mu_upcall_sem);
339 m->md_upcall.mu_upcall_dev = up;
340 up_write(&m->md_upcall.mu_upcall_sem);
343 static inline void md_upcall_fini(struct md_device *m)
345 down_write(&m->md_upcall.mu_upcall_sem);
346 m->md_upcall.mu_upcall_dev = NULL;
347 m->md_upcall.mu_upcall = NULL;
348 up_write(&m->md_upcall.mu_upcall_sem);
351 static inline int md_do_upcall(const struct lu_env *env, struct md_device *m,
352 enum md_upcall_event ev)
355 down_read(&m->md_upcall.mu_upcall_sem);
356 if (m->md_upcall.mu_upcall_dev != NULL &&
357 m->md_upcall.mu_upcall_dev->md_upcall.mu_upcall != NULL) {
358 rc = m->md_upcall.mu_upcall_dev->md_upcall.mu_upcall(env,
359 m->md_upcall.mu_upcall_dev, ev);
361 up_read(&m->md_upcall.mu_upcall_sem);
366 struct lu_object mo_lu;
367 struct md_object_operations *mo_ops;
368 struct md_dir_operations *mo_dir_ops;
371 static inline int lu_device_is_md(const struct lu_device *d)
373 return ergo(d != NULL, d->ld_type->ldt_tags & LU_DEVICE_MD);
376 static inline struct md_device *lu2md_dev(const struct lu_device *d)
378 LASSERT(lu_device_is_md(d));
379 return container_of0(d, struct md_device, md_lu_dev);
382 static inline struct lu_device *md2lu_dev(struct md_device *d)
384 return &d->md_lu_dev;
387 static inline struct md_object *lu2md(const struct lu_object *o)
389 LASSERT(lu_device_is_md(o->lo_dev));
390 return container_of0(o, struct md_object, mo_lu);
393 static inline struct md_object *md_object_next(const struct md_object *obj)
395 return (obj ? lu2md(lu_object_next(&obj->mo_lu)) : NULL);
398 static inline struct md_device *md_obj2dev(const struct md_object *o)
400 LASSERT(lu_device_is_md(o->mo_lu.lo_dev));
401 return container_of0(o->mo_lu.lo_dev, struct md_device, md_lu_dev);
404 static inline int md_device_init(struct md_device *md, struct lu_device_type *t)
406 return lu_device_init(&md->md_lu_dev, t);
409 static inline void md_device_fini(struct md_device *md)
411 lu_device_fini(&md->md_lu_dev);
415 static inline int mo_permission(const struct lu_env *env,
421 LASSERT(c->mo_ops->moo_permission);
422 return c->mo_ops->moo_permission(env, p, c, at, mask);
425 static inline int mo_attr_get(const struct lu_env *env,
429 LASSERT(m->mo_ops->moo_attr_get);
430 return m->mo_ops->moo_attr_get(env, m, at);
433 static inline int mo_readlink(const struct lu_env *env,
437 LASSERT(m->mo_ops->moo_readlink);
438 return m->mo_ops->moo_readlink(env, m, buf);
441 static inline int mo_attr_set(const struct lu_env *env,
443 const struct md_attr *at)
445 LASSERT(m->mo_ops->moo_attr_set);
446 return m->mo_ops->moo_attr_set(env, m, at);
449 static inline int mo_xattr_get(const struct lu_env *env,
454 LASSERT(m->mo_ops->moo_xattr_get);
455 return m->mo_ops->moo_xattr_get(env, m, buf, name);
458 static inline int mo_xattr_del(const struct lu_env *env,
462 LASSERT(m->mo_ops->moo_xattr_del);
463 return m->mo_ops->moo_xattr_del(env, m, name);
466 static inline int mo_xattr_set(const struct lu_env *env,
468 const struct lu_buf *buf,
472 LASSERT(m->mo_ops->moo_xattr_set);
473 return m->mo_ops->moo_xattr_set(env, m, buf, name, flags);
476 static inline int mo_xattr_list(const struct lu_env *env,
480 LASSERT(m->mo_ops->moo_xattr_list);
481 return m->mo_ops->moo_xattr_list(env, m, buf);
484 static inline int mo_open(const struct lu_env *env,
488 LASSERT(m->mo_ops->moo_open);
489 return m->mo_ops->moo_open(env, m, flags);
492 static inline int mo_close(const struct lu_env *env,
496 LASSERT(m->mo_ops->moo_close);
497 return m->mo_ops->moo_close(env, m, ma);
500 static inline int mo_readpage(const struct lu_env *env,
502 const struct lu_rdpg *rdpg)
504 LASSERT(m->mo_ops->moo_readpage);
505 return m->mo_ops->moo_readpage(env, m, rdpg);
508 static inline int mo_object_create(const struct lu_env *env,
510 const struct md_op_spec *spc,
513 LASSERT(m->mo_ops->moo_object_create);
514 return m->mo_ops->moo_object_create(env, m, spc, at);
517 static inline int mo_ref_add(const struct lu_env *env,
519 const struct md_attr *ma)
521 LASSERT(m->mo_ops->moo_ref_add);
522 return m->mo_ops->moo_ref_add(env, m, ma);
525 static inline int mo_ref_del(const struct lu_env *env,
529 LASSERT(m->mo_ops->moo_ref_del);
530 return m->mo_ops->moo_ref_del(env, m, ma);
533 static inline int mo_capa_get(const struct lu_env *env,
535 struct lustre_capa *c,
538 LASSERT(m->mo_ops->moo_capa_get);
539 return m->mo_ops->moo_capa_get(env, m, c, renewal);
542 static inline int mdo_lookup(const struct lu_env *env,
544 const struct lu_name *lname,
546 struct md_op_spec *spec)
548 LASSERT(p->mo_dir_ops->mdo_lookup);
549 return p->mo_dir_ops->mdo_lookup(env, p, lname, f, spec);
552 static inline mdl_mode_t mdo_lock_mode(const struct lu_env *env,
553 struct md_object *mo,
556 if (mo->mo_dir_ops->mdo_lock_mode == NULL)
558 return mo->mo_dir_ops->mdo_lock_mode(env, mo, lm);
561 static inline int mdo_create(const struct lu_env *env,
563 const struct lu_name *lchild_name,
565 struct md_op_spec *spc,
568 LASSERT(c->mo_dir_ops->mdo_create);
569 return c->mo_dir_ops->mdo_create(env, p, lchild_name, c, spc, at);
572 static inline int mdo_create_data(const struct lu_env *env,
575 const struct md_op_spec *spec,
578 LASSERT(c->mo_dir_ops->mdo_create_data);
579 return c->mo_dir_ops->mdo_create_data(env, p, c, spec, ma);
582 static inline int mdo_rename(const struct lu_env *env,
583 struct md_object *sp,
584 struct md_object *tp,
585 const struct lu_fid *lf,
586 const struct lu_name *lsname,
588 const struct lu_name *ltname,
591 LASSERT(tp->mo_dir_ops->mdo_rename);
592 return tp->mo_dir_ops->mdo_rename(env, sp, tp, lf, lsname, t, ltname,
596 static inline int mdo_is_subdir(const struct lu_env *env,
597 struct md_object *mo,
598 const struct lu_fid *fid,
601 LASSERT(mo->mo_dir_ops->mdo_is_subdir);
602 return mo->mo_dir_ops->mdo_is_subdir(env, mo, fid, sfid);
605 static inline int mdo_link(const struct lu_env *env,
608 const struct lu_name *lname,
611 LASSERT(s->mo_dir_ops->mdo_link);
612 return s->mo_dir_ops->mdo_link(env, p, s, lname, ma);
615 static inline int mdo_unlink(const struct lu_env *env,
618 const struct lu_name *lname,
621 LASSERT(c->mo_dir_ops->mdo_unlink);
622 return c->mo_dir_ops->mdo_unlink(env, p, c, lname, ma);
625 static inline int mdo_name_insert(const struct lu_env *env,
627 const struct lu_name *lname,
628 const struct lu_fid *f,
629 const struct md_attr *ma)
631 LASSERT(p->mo_dir_ops->mdo_name_insert);
632 return p->mo_dir_ops->mdo_name_insert(env, p, lname, f, ma);
635 static inline int mdo_name_remove(const struct lu_env *env,
637 const struct lu_name *lname,
638 const struct md_attr *ma)
640 LASSERT(p->mo_dir_ops->mdo_name_remove);
641 return p->mo_dir_ops->mdo_name_remove(env, p, lname, ma);
644 static inline int mdo_rename_tgt(const struct lu_env *env,
647 const struct lu_fid *lf,
648 const struct lu_name *lname,
652 LASSERT(t->mo_dir_ops->mdo_rename_tgt);
653 return t->mo_dir_ops->mdo_rename_tgt(env, p, t, lf, lname, ma);
655 LASSERT(p->mo_dir_ops->mdo_rename_tgt);
656 return p->mo_dir_ops->mdo_rename_tgt(env, p, t, lf, lname, ma);
660 #endif /* _LINUX_MD_OBJECT_H */