4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
27 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2011, 2013, Intel Corporation.
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.
57 * super-class definitions.
59 #include <dt_object.h>
62 struct md_device_operations;
67 struct obd_export *mq_exp;
70 struct md_quota *md_quota(const struct lu_env *env);
72 /** metadata attributes */
79 MA_ACL_DEF = (1 << 5),
80 MA_LOV_DEF = (1 << 6),
81 MA_LAY_GEN = (1 << 7),
101 MDT_REG_LOCK = (1 << 0),
102 MDT_PDO_LOCK = (1 << 1)
105 /* memory structure for hsm attributes
106 * for fields description see the on disk structure hsm_attrs
107 * which is defined in lustre_idl.h
116 #define IOEPOCH_INVAL 0
118 /* memory structure for som attributes
119 * for fields description see the on disk structure som_attrs
120 * which is defined in lustre_idl.h
135 struct lu_attr ma_attr;
136 struct lu_fid ma_pfid;
137 struct md_hsm ma_hsm;
138 struct lov_mds_md *ma_lmm;
139 struct lmv_stripe_md *ma_lmv;
141 struct llog_cookie *ma_cookie;
142 struct lustre_capa *ma_capa;
143 struct md_som_data *ma_som;
151 /** Additional parameters for create */
154 /** symlink target */
155 const char *sp_symname;
156 /** parent FID for cross-ref mkdir */
157 const struct lu_fid *sp_pfid;
158 /** eadata for regular files */
160 /** lov objs exist already */
161 const struct lu_fid *fid;
167 /** Create flag from client: such as MDS_OPEN_CREAT, and others. */
170 /** don't create lov objects or llog cookie - this replay */
171 unsigned int no_create:1,
172 sp_cr_lookup:1, /* do lookup sanity check or not. */
173 sp_rm_entry:1; /* only remove name entry */
175 /** Current lock mode for parent dir where create is performing. */
176 mdl_mode_t sp_cr_mode;
178 /** to create directory */
179 const struct dt_index_features *sp_feat;
183 * Operations implemented for each md object (both directory and leaf).
185 struct md_object_operations {
186 int (*moo_permission)(const struct lu_env *env,
187 struct md_object *pobj, struct md_object *cobj,
188 struct md_attr *attr, int mask);
190 int (*moo_attr_get)(const struct lu_env *env, struct md_object *obj,
191 struct md_attr *attr);
193 int (*moo_attr_set)(const struct lu_env *env, struct md_object *obj,
194 const struct md_attr *attr);
196 int (*moo_xattr_get)(const struct lu_env *env, struct md_object *obj,
197 struct lu_buf *buf, const char *name);
199 int (*moo_xattr_list)(const struct lu_env *env, struct md_object *obj,
202 int (*moo_xattr_set)(const struct lu_env *env, struct md_object *obj,
203 const struct lu_buf *buf, const char *name,
206 int (*moo_xattr_del)(const struct lu_env *env, struct md_object *obj,
209 /** This method is used to swap the layouts between 2 objects */
210 int (*moo_swap_layouts)(const struct lu_env *env,
211 struct md_object *obj1, struct md_object *obj2,
214 /** \retval number of bytes actually read upon success */
215 int (*moo_readpage)(const struct lu_env *env, struct md_object *obj,
216 const struct lu_rdpg *rdpg);
218 int (*moo_readlink)(const struct lu_env *env, struct md_object *obj,
220 int (*moo_changelog)(const struct lu_env *env,
221 enum changelog_rec_type type, int flags,
222 struct md_object *obj);
223 /** part of cross-ref operation */
224 int (*moo_object_create)(const struct lu_env *env,
225 struct md_object *obj,
226 const struct md_op_spec *spec,
229 int (*moo_ref_add)(const struct lu_env *env,
230 struct md_object *obj,
231 const struct md_attr *ma);
233 int (*moo_ref_del)(const struct lu_env *env,
234 struct md_object *obj,
237 int (*moo_open)(const struct lu_env *env,
238 struct md_object *obj, int flag);
240 int (*moo_close)(const struct lu_env *env, struct md_object *obj,
241 struct md_attr *ma, int mode);
243 int (*moo_capa_get)(const struct lu_env *, struct md_object *,
244 struct lustre_capa *, int renewal);
246 int (*moo_object_sync)(const struct lu_env *, struct md_object *);
248 int (*moo_file_lock)(const struct lu_env *env, struct md_object *obj,
249 struct lov_mds_md *lmm, struct ldlm_extent *extent,
250 struct lustre_handle *lockh);
251 int (*moo_file_unlock)(const struct lu_env *env, struct md_object *obj,
252 struct lov_mds_md *lmm,
253 struct lustre_handle *lockh);
254 int (*moo_object_lock)(const struct lu_env *env, struct md_object *obj,
255 struct lustre_handle *lh,
256 struct ldlm_enqueue_info *einfo,
261 * Operations implemented for each directory object.
263 struct md_dir_operations {
264 int (*mdo_is_subdir) (const struct lu_env *env, struct md_object *obj,
265 const struct lu_fid *fid, struct lu_fid *sfid);
267 int (*mdo_lookup)(const struct lu_env *env, struct md_object *obj,
268 const struct lu_name *lname, struct lu_fid *fid,
269 struct md_op_spec *spec);
271 mdl_mode_t (*mdo_lock_mode)(const struct lu_env *env,
272 struct md_object *obj,
275 int (*mdo_create)(const struct lu_env *env, struct md_object *pobj,
276 const struct lu_name *lname, struct md_object *child,
277 struct md_op_spec *spec,
280 /** This method is used for creating data object for this meta object*/
281 int (*mdo_create_data)(const struct lu_env *env, struct md_object *p,
283 const struct md_op_spec *spec,
286 int (*mdo_rename)(const struct lu_env *env, struct md_object *spobj,
287 struct md_object *tpobj, const struct lu_fid *lf,
288 const struct lu_name *lsname, struct md_object *tobj,
289 const struct lu_name *ltname, struct md_attr *ma);
291 int (*mdo_link)(const struct lu_env *env, struct md_object *tgt_obj,
292 struct md_object *src_obj, const struct lu_name *lname,
295 int (*mdo_unlink)(const struct lu_env *env, struct md_object *pobj,
296 struct md_object *cobj, const struct lu_name *lname,
297 struct md_attr *ma, int no_name);
299 /** This method is used to compare a requested layout to an existing
300 * layout (struct lov_mds_md_v1/3 vs struct lov_mds_md_v1/3) */
301 int (*mdo_lum_lmm_cmp)(const struct lu_env *env,
302 struct md_object *cobj,
303 const struct md_op_spec *spec,
306 /** partial ops for cross-ref case */
307 int (*mdo_name_insert)(const struct lu_env *env,
308 struct md_object *obj,
309 const struct lu_name *lname,
310 const struct lu_fid *fid,
311 const struct md_attr *ma);
313 int (*mdo_name_remove)(const struct lu_env *env,
314 struct md_object *obj,
315 const struct lu_name *lname,
316 const struct md_attr *ma);
318 int (*mdo_rename_tgt)(const struct lu_env *env, struct md_object *pobj,
319 struct md_object *tobj, const struct lu_fid *fid,
320 const struct lu_name *lname, struct md_attr *ma);
323 struct md_device_operations {
324 /** meta-data device related handlers. */
325 int (*mdo_root_get)(const struct lu_env *env, struct md_device *m,
328 int (*mdo_maxeasize_get)(const struct lu_env *env, struct md_device *m,
331 int (*mdo_statfs)(const struct lu_env *env, struct md_device *m,
332 struct obd_statfs *sfs);
334 int (*mdo_init_capa_ctxt)(const struct lu_env *env, struct md_device *m,
335 int mode, unsigned long timeout, __u32 alg,
336 struct lustre_capa_key *keys);
338 int (*mdo_update_capa_key)(const struct lu_env *env,
340 struct lustre_capa_key *key);
342 int (*mdo_llog_ctxt_get)(const struct lu_env *env,
343 struct md_device *m, int idx, void **h);
345 int (*mdo_iocontrol)(const struct lu_env *env, struct md_device *m,
346 unsigned int cmd, int len, void *data);
349 enum md_upcall_event {
350 /** Sync the md layer*/
351 MD_LOV_SYNC = (1 << 0),
352 /** Just for split, no need trans, for replay */
353 MD_NO_TRANS = (1 << 1),
354 MD_LOV_CONFIG = (1 << 2),
355 /** Trigger quota recovery */
356 MD_LOV_QUOTA = (1 << 3)
360 /** this lock protects upcall using against its removal
361 * read lock is for usage the upcall, write - for init/fini */
362 struct rw_semaphore mu_upcall_sem;
363 /** device to call, upper layer normally */
364 struct md_device *mu_upcall_dev;
365 /** upcall function */
366 int (*mu_upcall)(const struct lu_env *env, struct md_device *md,
367 enum md_upcall_event ev, void *data);
371 struct lu_device md_lu_dev;
372 const struct md_device_operations *md_ops;
373 struct md_upcall md_upcall;
376 static inline void md_upcall_init(struct md_device *m, void *upcl)
378 init_rwsem(&m->md_upcall.mu_upcall_sem);
379 m->md_upcall.mu_upcall_dev = NULL;
380 m->md_upcall.mu_upcall = upcl;
383 static inline void md_upcall_dev_set(struct md_device *m, struct md_device *up)
385 down_write(&m->md_upcall.mu_upcall_sem);
386 m->md_upcall.mu_upcall_dev = up;
387 up_write(&m->md_upcall.mu_upcall_sem);
390 static inline void md_upcall_fini(struct md_device *m)
392 down_write(&m->md_upcall.mu_upcall_sem);
393 m->md_upcall.mu_upcall_dev = NULL;
394 m->md_upcall.mu_upcall = NULL;
395 up_write(&m->md_upcall.mu_upcall_sem);
398 static inline int md_do_upcall(const struct lu_env *env, struct md_device *m,
399 enum md_upcall_event ev, void *data)
402 down_read(&m->md_upcall.mu_upcall_sem);
403 if (m->md_upcall.mu_upcall_dev != NULL &&
404 m->md_upcall.mu_upcall_dev->md_upcall.mu_upcall != NULL) {
405 rc = m->md_upcall.mu_upcall_dev->md_upcall.mu_upcall(env,
406 m->md_upcall.mu_upcall_dev,
409 up_read(&m->md_upcall.mu_upcall_sem);
414 struct lu_object mo_lu;
415 const struct md_object_operations *mo_ops;
416 const struct md_dir_operations *mo_dir_ops;
422 struct seq_server_site {
423 struct lu_site *ss_lu;
425 * mds number of this site.
429 * Fid location database
431 struct lu_server_fld *ss_server_fld;
432 struct lu_client_fld *ss_client_fld;
437 struct lu_server_seq *ss_server_seq;
440 * Controller Seq Manager
442 struct lu_server_seq *ss_control_seq;
443 struct obd_export *ss_control_exp;
448 struct lu_client_seq *ss_client_seq;
451 static inline struct md_device *lu2md_dev(const struct lu_device *d)
453 LASSERT(IS_ERR(d) || lu_device_is_md(d));
454 return container_of0(d, struct md_device, md_lu_dev);
457 static inline struct lu_device *md2lu_dev(struct md_device *d)
459 return &d->md_lu_dev;
462 static inline struct md_object *lu2md(const struct lu_object *o)
464 LASSERT(o == NULL || IS_ERR(o) || lu_device_is_md(o->lo_dev));
465 return container_of0(o, struct md_object, mo_lu);
468 static inline struct md_object *md_object_next(const struct md_object *obj)
470 return (obj ? lu2md(lu_object_next(&obj->mo_lu)) : NULL);
473 static inline struct md_device *md_obj2dev(const struct md_object *o)
475 LASSERT(o == NULL || IS_ERR(o) || lu_device_is_md(o->mo_lu.lo_dev));
476 return container_of0(o->mo_lu.lo_dev, struct md_device, md_lu_dev);
479 static inline int md_device_init(struct md_device *md, struct lu_device_type *t)
481 return lu_device_init(&md->md_lu_dev, t);
484 static inline void md_device_fini(struct md_device *md)
486 lu_device_fini(&md->md_lu_dev);
489 static inline struct md_object *md_object_find_slice(const struct lu_env *env,
490 struct md_device *md,
491 const struct lu_fid *f)
493 return lu2md(lu_object_find_slice(env, md2lu_dev(md), f, NULL));
498 static inline int mo_permission(const struct lu_env *env,
504 LASSERT(c->mo_ops->moo_permission);
505 return c->mo_ops->moo_permission(env, p, c, at, mask);
508 static inline int mo_attr_get(const struct lu_env *env,
512 LASSERT(m->mo_ops->moo_attr_get);
513 return m->mo_ops->moo_attr_get(env, m, at);
516 static inline int mo_readlink(const struct lu_env *env,
520 LASSERT(m->mo_ops->moo_readlink);
521 return m->mo_ops->moo_readlink(env, m, buf);
524 static inline int mo_changelog(const struct lu_env *env,
525 enum changelog_rec_type type,
526 int flags, struct md_object *m)
528 LASSERT(m->mo_ops->moo_changelog);
529 return m->mo_ops->moo_changelog(env, type, flags, m);
532 static inline int mo_attr_set(const struct lu_env *env,
534 const struct md_attr *at)
536 LASSERT(m->mo_ops->moo_attr_set);
537 return m->mo_ops->moo_attr_set(env, m, at);
540 static inline int mo_xattr_get(const struct lu_env *env,
545 LASSERT(m->mo_ops->moo_xattr_get);
546 return m->mo_ops->moo_xattr_get(env, m, buf, name);
549 static inline int mo_xattr_del(const struct lu_env *env,
553 LASSERT(m->mo_ops->moo_xattr_del);
554 return m->mo_ops->moo_xattr_del(env, m, name);
557 static inline int mo_xattr_set(const struct lu_env *env,
559 const struct lu_buf *buf,
563 LASSERT(m->mo_ops->moo_xattr_set);
564 return m->mo_ops->moo_xattr_set(env, m, buf, name, flags);
567 static inline int mo_xattr_list(const struct lu_env *env,
571 LASSERT(m->mo_ops->moo_xattr_list);
572 return m->mo_ops->moo_xattr_list(env, m, buf);
575 static inline int mo_swap_layouts(const struct lu_env *env,
576 struct md_object *o1,
577 struct md_object *o2, __u64 flags)
579 LASSERT(o1->mo_ops->moo_swap_layouts);
580 LASSERT(o2->mo_ops->moo_swap_layouts);
581 if (o1->mo_ops->moo_swap_layouts != o2->mo_ops->moo_swap_layouts)
583 return o1->mo_ops->moo_swap_layouts(env, o1, o2, flags);
586 static inline int mo_open(const struct lu_env *env,
590 LASSERT(m->mo_ops->moo_open);
591 return m->mo_ops->moo_open(env, m, flags);
594 static inline int mo_close(const struct lu_env *env,
599 LASSERT(m->mo_ops->moo_close);
600 return m->mo_ops->moo_close(env, m, ma, mode);
603 static inline int mo_readpage(const struct lu_env *env,
605 const struct lu_rdpg *rdpg)
607 LASSERT(m->mo_ops->moo_readpage);
608 return m->mo_ops->moo_readpage(env, m, rdpg);
611 static inline int mo_object_create(const struct lu_env *env,
613 const struct md_op_spec *spc,
616 LASSERT(m->mo_ops->moo_object_create);
617 return m->mo_ops->moo_object_create(env, m, spc, at);
620 static inline int mo_ref_add(const struct lu_env *env,
622 const struct md_attr *ma)
624 LASSERT(m->mo_ops->moo_ref_add);
625 return m->mo_ops->moo_ref_add(env, m, ma);
628 static inline int mo_ref_del(const struct lu_env *env,
632 LASSERT(m->mo_ops->moo_ref_del);
633 return m->mo_ops->moo_ref_del(env, m, ma);
636 static inline int mo_capa_get(const struct lu_env *env,
638 struct lustre_capa *c,
641 LASSERT(m->mo_ops->moo_capa_get);
642 return m->mo_ops->moo_capa_get(env, m, c, renewal);
645 static inline int mo_object_sync(const struct lu_env *env, struct md_object *m)
647 LASSERT(m->mo_ops->moo_object_sync);
648 return m->mo_ops->moo_object_sync(env, m);
651 static inline int mo_file_lock(const struct lu_env *env, struct md_object *m,
652 struct lov_mds_md *lmm,
653 struct ldlm_extent *extent,
654 struct lustre_handle *lockh)
656 LASSERT(m->mo_ops->moo_file_lock);
657 return m->mo_ops->moo_file_lock(env, m, lmm, extent, lockh);
660 static inline int mo_file_unlock(const struct lu_env *env, struct md_object *m,
661 struct lov_mds_md *lmm,
662 struct lustre_handle *lockh)
664 LASSERT(m->mo_ops->moo_file_unlock);
665 return m->mo_ops->moo_file_unlock(env, m, lmm, lockh);
668 static inline int mo_object_lock(const struct lu_env *env,
670 struct lustre_handle *lh,
671 struct ldlm_enqueue_info *einfo,
674 LASSERT(m->mo_ops->moo_object_lock);
675 return m->mo_ops->moo_object_lock(env, m, lh, einfo, policy);
678 static inline int mdo_lookup(const struct lu_env *env,
680 const struct lu_name *lname,
682 struct md_op_spec *spec)
684 LASSERT(p->mo_dir_ops->mdo_lookup);
685 return p->mo_dir_ops->mdo_lookup(env, p, lname, f, spec);
688 static inline mdl_mode_t mdo_lock_mode(const struct lu_env *env,
689 struct md_object *mo,
692 if (mo->mo_dir_ops->mdo_lock_mode == NULL)
694 return mo->mo_dir_ops->mdo_lock_mode(env, mo, lm);
697 static inline int mdo_create(const struct lu_env *env,
699 const struct lu_name *lchild_name,
701 struct md_op_spec *spc,
704 LASSERT(p->mo_dir_ops->mdo_create);
705 return p->mo_dir_ops->mdo_create(env, p, lchild_name, c, spc, at);
708 static inline int mdo_create_data(const struct lu_env *env,
711 const struct md_op_spec *spec,
714 LASSERT(c->mo_dir_ops->mdo_create_data);
715 return c->mo_dir_ops->mdo_create_data(env, p, c, spec, ma);
718 static inline int mdo_rename(const struct lu_env *env,
719 struct md_object *sp,
720 struct md_object *tp,
721 const struct lu_fid *lf,
722 const struct lu_name *lsname,
724 const struct lu_name *ltname,
727 LASSERT(tp->mo_dir_ops->mdo_rename);
728 return tp->mo_dir_ops->mdo_rename(env, sp, tp, lf, lsname, t, ltname,
732 static inline int mdo_is_subdir(const struct lu_env *env,
733 struct md_object *mo,
734 const struct lu_fid *fid,
737 LASSERT(mo->mo_dir_ops->mdo_is_subdir);
738 return mo->mo_dir_ops->mdo_is_subdir(env, mo, fid, sfid);
741 static inline int mdo_link(const struct lu_env *env,
744 const struct lu_name *lname,
747 LASSERT(s->mo_dir_ops->mdo_link);
748 return s->mo_dir_ops->mdo_link(env, p, s, lname, ma);
751 static inline int mdo_unlink(const struct lu_env *env,
754 const struct lu_name *lname,
755 struct md_attr *ma, int no_name)
757 LASSERT(p->mo_dir_ops->mdo_unlink);
758 return p->mo_dir_ops->mdo_unlink(env, p, c, lname, ma, no_name);
761 static inline int mdo_lum_lmm_cmp(const struct lu_env *env,
763 const struct md_op_spec *spec,
766 LASSERT(c->mo_dir_ops->mdo_lum_lmm_cmp);
767 return c->mo_dir_ops->mdo_lum_lmm_cmp(env, c, spec, ma);
770 static inline int mdo_name_insert(const struct lu_env *env,
772 const struct lu_name *lname,
773 const struct lu_fid *f,
774 const struct md_attr *ma)
776 LASSERT(p->mo_dir_ops->mdo_name_insert);
777 return p->mo_dir_ops->mdo_name_insert(env, p, lname, f, ma);
780 static inline int mdo_name_remove(const struct lu_env *env,
782 const struct lu_name *lname,
783 const struct md_attr *ma)
785 LASSERT(p->mo_dir_ops->mdo_name_remove);
786 return p->mo_dir_ops->mdo_name_remove(env, p, lname, ma);
789 static inline int mdo_rename_tgt(const struct lu_env *env,
792 const struct lu_fid *lf,
793 const struct lu_name *lname,
797 LASSERT(t->mo_dir_ops->mdo_rename_tgt);
798 return t->mo_dir_ops->mdo_rename_tgt(env, p, t, lf, lname, ma);
800 LASSERT(p->mo_dir_ops->mdo_rename_tgt);
801 return p->mo_dir_ops->mdo_rename_tgt(env, p, t, lf, lname, ma);
806 * Used in MDD/OUT layer for object lock rule
808 enum mdd_object_role {
818 * Structure to hold object information. This is used to create object
819 * \pre llod_dir exist
821 struct lu_local_obj_desc {
822 const char *llod_dir;
823 const char *llod_name;
826 const struct dt_index_features *llod_feat;
827 cfs_list_t llod_linkage;
830 int lustre_buf2som(void *buf, int rc, struct md_som_data *msd);
831 int lustre_buf2hsm(void *buf, int rc, struct md_hsm *mh);
832 void lustre_hsm2buf(void *buf, const struct md_hsm *mh);
851 __u32 uc_suppgids[2];
854 cfs_group_info_t *uc_ginfo;
855 struct md_identity *uc_identity;
858 struct lu_ucred *lu_ucred(const struct lu_env *env);
860 struct lu_ucred *lu_ucred_check(const struct lu_env *env);
862 struct lu_ucred *lu_ucred_assert(const struct lu_env *env);
864 int lu_ucred_global_init(void);
866 void lu_ucred_global_fini(void);
868 #define md_cap_t(x) (x)
870 #define MD_CAP_TO_MASK(x) (1 << (x))
872 #define md_cap_raised(c, flag) (md_cap_t(c) & MD_CAP_TO_MASK(flag))
874 /* capable() is copied from linux kernel! */
875 static inline int md_capable(struct lu_ucred *uc, cfs_cap_t cap)
877 if (md_cap_raised(uc->uc_cap, cap))
883 #endif /* _LINUX_MD_OBJECT_H */