1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 only,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License version 2 for more details (a copy is included
16 * in the LICENSE file that accompanied this code).
18 * You should have received a copy of the GNU General Public License
19 * version 2 along with this program; If not, see [sun.com URL with a
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
29 * Copyright 2008 Sun Microsystems, Inc. All rights reserved
30 * Use is subject to license terms.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * lustre/include/md_object.h
38 * Extention of lu_object.h for metadata objects
41 #ifndef _LUSTRE_MD_OBJECT_H
42 #define _LUSTRE_MD_OBJECT_H
45 * Sub-class of lu_object with methods common for "meta-data" objects in MDT
48 * Meta-data objects implement namespace operations: you can link, unlink
49 * them, and treat them as directories.
51 * Examples: mdt, cmm, and mdt are implementations of md interface.
56 * super-class definitions.
58 #include <lu_object.h>
62 struct md_device_operations;
86 struct group_info *mu_ginfo;
87 struct md_identity *mu_identity;
90 #define MD_CAPAINFO_MAX 5
92 /* there are at most 5 fids in one operation, see rename, NOTE the last one
93 * is a temporary one used for is_subdir() */
95 const struct lu_fid *mc_fid[MD_CAPAINFO_MAX];
96 struct lustre_capa *mc_capa[MD_CAPAINFO_MAX];
100 * Implemented in mdd/mdd_handler.c.
102 * XXX should be moved into separate .h/.c together with all md security
103 * related definitions.
105 struct md_ucred *md_ucred(const struct lu_env *env);
106 struct md_capainfo *md_capainfo(const struct lu_env *env);
108 /* metadata attributes */
112 MA_COOKIE = (1 << 2),
115 MA_ACL_DEF = (1 << 5),
116 MA_LOV_DEF = (1 << 6)
133 MDT_REG_LOCK = (1 << 0),
134 MDT_PDO_LOCK = (1 << 1)
141 struct lu_attr ma_attr;
142 struct lov_mds_md *ma_lmm;
144 struct lmv_stripe_md *ma_lmv;
148 struct llog_cookie *ma_cookie;
150 struct lustre_capa *ma_capa;
153 /* Additional parameters for create */
157 const char *sp_symname;
158 /* parent FID for cross-ref mkdir */
159 const struct lu_fid *sp_pfid;
160 /* eadata for regular files */
162 /* lov objs exist already */
163 const struct lu_fid *fid;
170 /* Create flag from client: such as MDS_OPEN_CREAT, and others. */
173 /* Should mdd do lookup sanity check or not. */
176 /* Current lock mode for parent dir where create is performing. */
177 mdl_mode_t sp_cr_mode;
179 /* Check for split */
184 * Operations implemented for each md object (both directory and leaf).
186 struct md_object_operations {
187 int (*moo_permission)(const struct lu_env *env,
188 struct md_object *pobj, struct md_object *cobj,
189 struct md_attr *attr, int mask);
191 int (*moo_attr_get)(const struct lu_env *env, struct md_object *obj,
192 struct md_attr *attr);
194 int (*moo_attr_set)(const struct lu_env *env, struct md_object *obj,
195 const struct md_attr *attr);
197 int (*moo_xattr_get)(const struct lu_env *env, struct md_object *obj,
198 struct lu_buf *buf, const char *name);
200 int (*moo_xattr_list)(const struct lu_env *env, struct md_object *obj,
203 int (*moo_xattr_set)(const struct lu_env *env, struct md_object *obj,
204 const struct lu_buf *buf, const char *name,
207 int (*moo_xattr_del)(const struct lu_env *env, struct md_object *obj,
210 int (*moo_readpage)(const struct lu_env *env, struct md_object *obj,
211 const struct lu_rdpg *rdpg);
213 int (*moo_readlink)(const struct lu_env *env, struct md_object *obj,
216 /* part of cross-ref operation */
217 int (*moo_object_create)(const struct lu_env *env,
218 struct md_object *obj,
219 const struct md_op_spec *spec,
222 int (*moo_ref_add)(const struct lu_env *env,
223 struct md_object *obj,
224 const struct md_attr *ma);
226 int (*moo_ref_del)(const struct lu_env *env,
227 struct md_object *obj,
230 int (*moo_open)(const struct lu_env *env,
231 struct md_object *obj, int flag);
233 int (*moo_close)(const struct lu_env *env, struct md_object *obj,
236 int (*moo_capa_get)(const struct lu_env *, struct md_object *,
237 struct lustre_capa *, int renewal);
241 * Operations implemented for each directory object.
243 struct md_dir_operations {
244 int (*mdo_is_subdir) (const struct lu_env *env, struct md_object *obj,
245 const struct lu_fid *fid, struct lu_fid *sfid);
247 int (*mdo_lookup)(const struct lu_env *env, struct md_object *obj,
248 const struct lu_name *lname, struct lu_fid *fid,
249 struct md_op_spec *spec);
251 mdl_mode_t (*mdo_lock_mode)(const struct lu_env *env,
252 struct md_object *obj,
255 int (*mdo_create)(const struct lu_env *env, struct md_object *pobj,
256 const struct lu_name *lname, struct md_object *child,
257 struct md_op_spec *spec,
260 /* This method is used for creating data object for this meta object*/
261 int (*mdo_create_data)(const struct lu_env *env, struct md_object *p,
263 const struct md_op_spec *spec,
266 int (*mdo_rename)(const struct lu_env *env, struct md_object *spobj,
267 struct md_object *tpobj, const struct lu_fid *lf,
268 const struct lu_name *lsname, struct md_object *tobj,
269 const struct lu_name *ltname, struct md_attr *ma);
271 int (*mdo_link)(const struct lu_env *env, struct md_object *tgt_obj,
272 struct md_object *src_obj, const struct lu_name *lname,
275 int (*mdo_unlink)(const struct lu_env *env, struct md_object *pobj,
276 struct md_object *cobj, const struct lu_name *lname,
279 /* partial ops for cross-ref case */
280 int (*mdo_name_insert)(const struct lu_env *env,
281 struct md_object *obj,
282 const struct lu_name *lname,
283 const struct lu_fid *fid,
284 const struct md_attr *ma);
286 int (*mdo_name_remove)(const struct lu_env *env,
287 struct md_object *obj,
288 const struct lu_name *lname,
289 const struct md_attr *ma);
291 int (*mdo_rename_tgt)(const struct lu_env *env, struct md_object *pobj,
292 struct md_object *tobj, const struct lu_fid *fid,
293 const struct lu_name *lname, struct md_attr *ma);
296 struct md_device_operations {
297 /* meta-data device related handlers. */
298 int (*mdo_root_get)(const struct lu_env *env, struct md_device *m,
301 int (*mdo_maxsize_get)(const struct lu_env *env, struct md_device *m,
302 int *md_size, int *cookie_size);
304 int (*mdo_statfs)(const struct lu_env *env, struct md_device *m,
305 struct kstatfs *sfs);
307 int (*mdo_init_capa_ctxt)(const struct lu_env *env, struct md_device *m,
308 int mode, unsigned long timeout, __u32 alg,
309 struct lustre_capa_key *keys);
311 int (*mdo_update_capa_key)(const struct lu_env *env,
313 struct lustre_capa_key *key);
316 enum md_upcall_event {
317 /*sync the md layer*/
318 MD_LOV_SYNC = (1 << 0),
319 MD_NO_TRANS = (1 << 1), /* Just for split, no need trans, for replay */
320 MD_LOV_CONFIG = (1 << 2)
324 /* this lock protects upcall using against its removal
325 * read lock is for usage the upcall, write - for init/fini */
326 struct rw_semaphore mu_upcall_sem;
327 /* device to call, upper layer normally */
328 struct md_device *mu_upcall_dev;
329 /* upcall function */
330 int (*mu_upcall)(const struct lu_env *env, struct md_device *md,
331 enum md_upcall_event ev);
335 struct lu_device md_lu_dev;
336 struct md_device_operations *md_ops;
337 struct md_upcall md_upcall;
340 static inline void md_upcall_init(struct md_device *m, void *upcl)
342 init_rwsem(&m->md_upcall.mu_upcall_sem);
343 m->md_upcall.mu_upcall_dev = NULL;
344 m->md_upcall.mu_upcall = upcl;
347 static inline void md_upcall_dev_set(struct md_device *m, struct md_device *up)
349 down_write(&m->md_upcall.mu_upcall_sem);
350 m->md_upcall.mu_upcall_dev = up;
351 up_write(&m->md_upcall.mu_upcall_sem);
354 static inline void md_upcall_fini(struct md_device *m)
356 down_write(&m->md_upcall.mu_upcall_sem);
357 m->md_upcall.mu_upcall_dev = NULL;
358 m->md_upcall.mu_upcall = NULL;
359 up_write(&m->md_upcall.mu_upcall_sem);
362 static inline int md_do_upcall(const struct lu_env *env, struct md_device *m,
363 enum md_upcall_event ev)
366 down_read(&m->md_upcall.mu_upcall_sem);
367 if (m->md_upcall.mu_upcall_dev != NULL &&
368 m->md_upcall.mu_upcall_dev->md_upcall.mu_upcall != NULL) {
369 rc = m->md_upcall.mu_upcall_dev->md_upcall.mu_upcall(env,
370 m->md_upcall.mu_upcall_dev, ev);
372 up_read(&m->md_upcall.mu_upcall_sem);
377 struct lu_object mo_lu;
378 struct md_object_operations *mo_ops;
379 struct md_dir_operations *mo_dir_ops;
382 static inline int lu_device_is_md(const struct lu_device *d)
384 return ergo(d != NULL, d->ld_type->ldt_tags & LU_DEVICE_MD);
387 static inline struct md_device *lu2md_dev(const struct lu_device *d)
389 LASSERT(lu_device_is_md(d));
390 return container_of0(d, struct md_device, md_lu_dev);
393 static inline struct lu_device *md2lu_dev(struct md_device *d)
395 return &d->md_lu_dev;
398 static inline struct md_object *lu2md(const struct lu_object *o)
400 LASSERT(lu_device_is_md(o->lo_dev));
401 return container_of0(o, struct md_object, mo_lu);
404 static inline struct md_object *md_object_next(const struct md_object *obj)
406 return (obj ? lu2md(lu_object_next(&obj->mo_lu)) : NULL);
409 static inline struct md_device *md_obj2dev(const struct md_object *o)
411 LASSERT(lu_device_is_md(o->mo_lu.lo_dev));
412 return container_of0(o->mo_lu.lo_dev, struct md_device, md_lu_dev);
415 static inline int md_device_init(struct md_device *md, struct lu_device_type *t)
417 return lu_device_init(&md->md_lu_dev, t);
420 static inline void md_device_fini(struct md_device *md)
422 lu_device_fini(&md->md_lu_dev);
426 static inline int mo_permission(const struct lu_env *env,
432 LASSERT(c->mo_ops->moo_permission);
433 return c->mo_ops->moo_permission(env, p, c, at, mask);
436 static inline int mo_attr_get(const struct lu_env *env,
440 LASSERT(m->mo_ops->moo_attr_get);
441 return m->mo_ops->moo_attr_get(env, m, at);
444 static inline int mo_readlink(const struct lu_env *env,
448 LASSERT(m->mo_ops->moo_readlink);
449 return m->mo_ops->moo_readlink(env, m, buf);
452 static inline int mo_attr_set(const struct lu_env *env,
454 const struct md_attr *at)
456 LASSERT(m->mo_ops->moo_attr_set);
457 return m->mo_ops->moo_attr_set(env, m, at);
460 static inline int mo_xattr_get(const struct lu_env *env,
465 LASSERT(m->mo_ops->moo_xattr_get);
466 return m->mo_ops->moo_xattr_get(env, m, buf, name);
469 static inline int mo_xattr_del(const struct lu_env *env,
473 LASSERT(m->mo_ops->moo_xattr_del);
474 return m->mo_ops->moo_xattr_del(env, m, name);
477 static inline int mo_xattr_set(const struct lu_env *env,
479 const struct lu_buf *buf,
483 LASSERT(m->mo_ops->moo_xattr_set);
484 return m->mo_ops->moo_xattr_set(env, m, buf, name, flags);
487 static inline int mo_xattr_list(const struct lu_env *env,
491 LASSERT(m->mo_ops->moo_xattr_list);
492 return m->mo_ops->moo_xattr_list(env, m, buf);
495 static inline int mo_open(const struct lu_env *env,
499 LASSERT(m->mo_ops->moo_open);
500 return m->mo_ops->moo_open(env, m, flags);
503 static inline int mo_close(const struct lu_env *env,
507 LASSERT(m->mo_ops->moo_close);
508 return m->mo_ops->moo_close(env, m, ma);
511 static inline int mo_readpage(const struct lu_env *env,
513 const struct lu_rdpg *rdpg)
515 LASSERT(m->mo_ops->moo_readpage);
516 return m->mo_ops->moo_readpage(env, m, rdpg);
519 static inline int mo_object_create(const struct lu_env *env,
521 const struct md_op_spec *spc,
524 LASSERT(m->mo_ops->moo_object_create);
525 return m->mo_ops->moo_object_create(env, m, spc, at);
528 static inline int mo_ref_add(const struct lu_env *env,
530 const struct md_attr *ma)
532 LASSERT(m->mo_ops->moo_ref_add);
533 return m->mo_ops->moo_ref_add(env, m, ma);
536 static inline int mo_ref_del(const struct lu_env *env,
540 LASSERT(m->mo_ops->moo_ref_del);
541 return m->mo_ops->moo_ref_del(env, m, ma);
544 static inline int mo_capa_get(const struct lu_env *env,
546 struct lustre_capa *c,
549 LASSERT(m->mo_ops->moo_capa_get);
550 return m->mo_ops->moo_capa_get(env, m, c, renewal);
553 static inline int mdo_lookup(const struct lu_env *env,
555 const struct lu_name *lname,
557 struct md_op_spec *spec)
559 LASSERT(p->mo_dir_ops->mdo_lookup);
560 return p->mo_dir_ops->mdo_lookup(env, p, lname, f, spec);
563 static inline mdl_mode_t mdo_lock_mode(const struct lu_env *env,
564 struct md_object *mo,
567 if (mo->mo_dir_ops->mdo_lock_mode == NULL)
569 return mo->mo_dir_ops->mdo_lock_mode(env, mo, lm);
572 static inline int mdo_create(const struct lu_env *env,
574 const struct lu_name *lchild_name,
576 struct md_op_spec *spc,
579 LASSERT(c->mo_dir_ops->mdo_create);
580 return c->mo_dir_ops->mdo_create(env, p, lchild_name, c, spc, at);
583 static inline int mdo_create_data(const struct lu_env *env,
586 const struct md_op_spec *spec,
589 LASSERT(c->mo_dir_ops->mdo_create_data);
590 return c->mo_dir_ops->mdo_create_data(env, p, c, spec, ma);
593 static inline int mdo_rename(const struct lu_env *env,
594 struct md_object *sp,
595 struct md_object *tp,
596 const struct lu_fid *lf,
597 const struct lu_name *lsname,
599 const struct lu_name *ltname,
602 LASSERT(tp->mo_dir_ops->mdo_rename);
603 return tp->mo_dir_ops->mdo_rename(env, sp, tp, lf, lsname, t, ltname,
607 static inline int mdo_is_subdir(const struct lu_env *env,
608 struct md_object *mo,
609 const struct lu_fid *fid,
612 LASSERT(mo->mo_dir_ops->mdo_is_subdir);
613 return mo->mo_dir_ops->mdo_is_subdir(env, mo, fid, sfid);
616 static inline int mdo_link(const struct lu_env *env,
619 const struct lu_name *lname,
622 LASSERT(s->mo_dir_ops->mdo_link);
623 return s->mo_dir_ops->mdo_link(env, p, s, lname, ma);
626 static inline int mdo_unlink(const struct lu_env *env,
629 const struct lu_name *lname,
632 LASSERT(c->mo_dir_ops->mdo_unlink);
633 return c->mo_dir_ops->mdo_unlink(env, p, c, lname, ma);
636 static inline int mdo_name_insert(const struct lu_env *env,
638 const struct lu_name *lname,
639 const struct lu_fid *f,
640 const struct md_attr *ma)
642 LASSERT(p->mo_dir_ops->mdo_name_insert);
643 return p->mo_dir_ops->mdo_name_insert(env, p, lname, f, ma);
646 static inline int mdo_name_remove(const struct lu_env *env,
648 const struct lu_name *lname,
649 const struct md_attr *ma)
651 LASSERT(p->mo_dir_ops->mdo_name_remove);
652 return p->mo_dir_ops->mdo_name_remove(env, p, lname, ma);
655 static inline int mdo_rename_tgt(const struct lu_env *env,
658 const struct lu_fid *lf,
659 const struct lu_name *lname,
663 LASSERT(t->mo_dir_ops->mdo_rename_tgt);
664 return t->mo_dir_ops->mdo_rename_tgt(env, p, t, lf, lname, ma);
666 LASSERT(p->mo_dir_ops->mdo_rename_tgt);
667 return p->mo_dir_ops->mdo_rename_tgt(env, p, t, lf, lname, ma);
671 #endif /* _LINUX_MD_OBJECT_H */