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),
85 MA_LMV_DEF = (1 << 11)
102 MDT_REG_LOCK = (1 << 0),
103 MDT_PDO_LOCK = (1 << 1)
106 /* memory structure for hsm attributes
107 * for fields description see the on disk structure hsm_attrs
108 * which is defined in lustre_idl.h
117 #define IOEPOCH_INVAL 0
119 /* memory structure for som attributes
120 * for fields description see the on disk structure som_attrs
121 * which is defined in lustre_idl.h
136 struct lu_attr ma_attr;
137 struct lu_fid ma_pfid;
138 struct md_hsm ma_hsm;
139 struct lov_mds_md *ma_lmm;
140 union lmv_mds_md *ma_lmv;
142 struct llog_cookie *ma_cookie;
143 struct lustre_capa *ma_capa;
144 struct md_som_data *ma_som;
152 /** Additional parameters for create */
155 /** symlink target */
156 const char *sp_symname;
157 /** parent FID for cross-ref mkdir */
158 const struct lu_fid *sp_pfid;
159 /** eadata for regular files */
161 /** lov objs exist already */
162 const struct lu_fid *fid;
168 /** Create flag from client: such as MDS_OPEN_CREAT, and others. */
171 /** don't create lov objects or llog cookie - this replay */
172 unsigned int no_create:1,
173 sp_cr_lookup:1, /* do lookup sanity check or not. */
174 sp_rm_entry:1; /* only remove name entry */
176 /** Current lock mode for parent dir where create is performing. */
177 mdl_mode_t sp_cr_mode;
179 /** to create directory */
180 const struct dt_index_features *sp_feat;
183 union ldlm_policy_data;
185 * Operations implemented for each md object (both directory and leaf).
187 struct md_object_operations {
188 int (*moo_permission)(const struct lu_env *env,
189 struct md_object *pobj, struct md_object *cobj,
190 struct md_attr *attr, int mask);
192 int (*moo_attr_get)(const struct lu_env *env, struct md_object *obj,
193 struct md_attr *attr);
195 int (*moo_attr_set)(const struct lu_env *env, struct md_object *obj,
196 const struct md_attr *attr);
198 int (*moo_xattr_get)(const struct lu_env *env, struct md_object *obj,
199 struct lu_buf *buf, const char *name);
201 int (*moo_xattr_list)(const struct lu_env *env, struct md_object *obj,
204 int (*moo_xattr_set)(const struct lu_env *env, struct md_object *obj,
205 const struct lu_buf *buf, const char *name,
208 int (*moo_xattr_del)(const struct lu_env *env, struct md_object *obj,
211 /** This method is used to swap the layouts between 2 objects */
212 int (*moo_swap_layouts)(const struct lu_env *env,
213 struct md_object *obj1, struct md_object *obj2,
216 /** \retval number of bytes actually read upon success */
217 int (*moo_readpage)(const struct lu_env *env, struct md_object *obj,
218 const struct lu_rdpg *rdpg);
220 int (*moo_readlink)(const struct lu_env *env, struct md_object *obj,
222 int (*moo_changelog)(const struct lu_env *env,
223 enum changelog_rec_type type, int flags,
224 struct md_object *obj);
225 /** part of cross-ref operation */
226 int (*moo_object_create)(const struct lu_env *env,
227 struct md_object *obj,
228 const struct md_op_spec *spec,
231 int (*moo_ref_add)(const struct lu_env *env,
232 struct md_object *obj,
233 const struct md_attr *ma);
235 int (*moo_ref_del)(const struct lu_env *env,
236 struct md_object *obj,
239 int (*moo_open)(const struct lu_env *env,
240 struct md_object *obj, int flag);
242 int (*moo_close)(const struct lu_env *env, struct md_object *obj,
243 struct md_attr *ma, int mode);
245 int (*moo_capa_get)(const struct lu_env *, struct md_object *,
246 struct lustre_capa *, int renewal);
248 int (*moo_object_sync)(const struct lu_env *, struct md_object *);
250 int (*moo_file_lock)(const struct lu_env *env, struct md_object *obj,
251 struct lov_mds_md *lmm, struct ldlm_extent *extent,
252 struct lustre_handle *lockh);
253 int (*moo_file_unlock)(const struct lu_env *env, struct md_object *obj,
254 struct lov_mds_md *lmm,
255 struct lustre_handle *lockh);
256 int (*moo_object_lock)(const struct lu_env *env, struct md_object *obj,
257 struct lustre_handle *lh,
258 struct ldlm_enqueue_info *einfo,
259 union ldlm_policy_data *policy);
260 int (*moo_object_unlock)(const struct lu_env *env,
261 struct md_object *obj,
262 struct ldlm_enqueue_info *einfo,
263 union ldlm_policy_data *policy);
267 * Operations implemented for each directory object.
269 struct md_dir_operations {
270 int (*mdo_is_subdir) (const struct lu_env *env, struct md_object *obj,
271 const struct lu_fid *fid, struct lu_fid *sfid);
273 int (*mdo_lookup)(const struct lu_env *env, struct md_object *obj,
274 const struct lu_name *lname, struct lu_fid *fid,
275 struct md_op_spec *spec);
277 mdl_mode_t (*mdo_lock_mode)(const struct lu_env *env,
278 struct md_object *obj,
281 int (*mdo_create)(const struct lu_env *env, struct md_object *pobj,
282 const struct lu_name *lname, struct md_object *child,
283 struct md_op_spec *spec,
286 /** This method is used for creating data object for this meta object*/
287 int (*mdo_create_data)(const struct lu_env *env, struct md_object *p,
289 const struct md_op_spec *spec,
292 int (*mdo_rename)(const struct lu_env *env, struct md_object *spobj,
293 struct md_object *tpobj, const struct lu_fid *lf,
294 const struct lu_name *lsname, struct md_object *tobj,
295 const struct lu_name *ltname, struct md_attr *ma);
297 int (*mdo_link)(const struct lu_env *env, struct md_object *tgt_obj,
298 struct md_object *src_obj, const struct lu_name *lname,
301 int (*mdo_unlink)(const struct lu_env *env, struct md_object *pobj,
302 struct md_object *cobj, const struct lu_name *lname,
303 struct md_attr *ma, int no_name);
305 /** This method is used to compare a requested layout to an existing
306 * layout (struct lov_mds_md_v1/3 vs struct lov_mds_md_v1/3) */
307 int (*mdo_lum_lmm_cmp)(const struct lu_env *env,
308 struct md_object *cobj,
309 const struct md_op_spec *spec,
312 /** partial ops for cross-ref case */
313 int (*mdo_name_insert)(const struct lu_env *env,
314 struct md_object *obj,
315 const struct lu_name *lname,
316 const struct lu_fid *fid,
317 const struct md_attr *ma);
319 int (*mdo_name_remove)(const struct lu_env *env,
320 struct md_object *obj,
321 const struct lu_name *lname,
322 const struct md_attr *ma);
324 int (*mdo_rename_tgt)(const struct lu_env *env, struct md_object *pobj,
325 struct md_object *tobj, const struct lu_fid *fid,
326 const struct lu_name *lname, struct md_attr *ma);
329 struct md_device_operations {
330 /** meta-data device related handlers. */
331 int (*mdo_root_get)(const struct lu_env *env, struct md_device *m,
334 int (*mdo_maxeasize_get)(const struct lu_env *env, struct md_device *m,
337 int (*mdo_statfs)(const struct lu_env *env, struct md_device *m,
338 struct obd_statfs *sfs);
340 int (*mdo_init_capa_ctxt)(const struct lu_env *env, struct md_device *m,
341 int mode, unsigned long timeout, __u32 alg,
342 struct lustre_capa_key *keys);
344 int (*mdo_update_capa_key)(const struct lu_env *env,
346 struct lustre_capa_key *key);
348 int (*mdo_llog_ctxt_get)(const struct lu_env *env,
349 struct md_device *m, int idx, void **h);
351 int (*mdo_iocontrol)(const struct lu_env *env, struct md_device *m,
352 unsigned int cmd, int len, void *data);
355 enum md_upcall_event {
356 /** Sync the md layer*/
357 MD_LOV_SYNC = (1 << 0),
358 /** Just for split, no need trans, for replay */
359 MD_NO_TRANS = (1 << 1),
360 MD_LOV_CONFIG = (1 << 2),
361 /** Trigger quota recovery */
362 MD_LOV_QUOTA = (1 << 3)
366 /** this lock protects upcall using against its removal
367 * read lock is for usage the upcall, write - for init/fini */
368 struct rw_semaphore mu_upcall_sem;
369 /** device to call, upper layer normally */
370 struct md_device *mu_upcall_dev;
371 /** upcall function */
372 int (*mu_upcall)(const struct lu_env *env, struct md_device *md,
373 enum md_upcall_event ev, void *data);
377 struct lu_device md_lu_dev;
378 const struct md_device_operations *md_ops;
379 struct md_upcall md_upcall;
382 static inline void md_upcall_init(struct md_device *m, void *upcl)
384 init_rwsem(&m->md_upcall.mu_upcall_sem);
385 m->md_upcall.mu_upcall_dev = NULL;
386 m->md_upcall.mu_upcall = upcl;
389 static inline void md_upcall_dev_set(struct md_device *m, struct md_device *up)
391 down_write(&m->md_upcall.mu_upcall_sem);
392 m->md_upcall.mu_upcall_dev = up;
393 up_write(&m->md_upcall.mu_upcall_sem);
396 static inline void md_upcall_fini(struct md_device *m)
398 down_write(&m->md_upcall.mu_upcall_sem);
399 m->md_upcall.mu_upcall_dev = NULL;
400 m->md_upcall.mu_upcall = NULL;
401 up_write(&m->md_upcall.mu_upcall_sem);
404 static inline int md_do_upcall(const struct lu_env *env, struct md_device *m,
405 enum md_upcall_event ev, void *data)
408 down_read(&m->md_upcall.mu_upcall_sem);
409 if (m->md_upcall.mu_upcall_dev != NULL &&
410 m->md_upcall.mu_upcall_dev->md_upcall.mu_upcall != NULL) {
411 rc = m->md_upcall.mu_upcall_dev->md_upcall.mu_upcall(env,
412 m->md_upcall.mu_upcall_dev,
415 up_read(&m->md_upcall.mu_upcall_sem);
420 struct lu_object mo_lu;
421 const struct md_object_operations *mo_ops;
422 const struct md_dir_operations *mo_dir_ops;
428 struct seq_server_site {
429 struct lu_site *ss_lu;
431 * mds number of this site.
435 * Fid location database
437 struct lu_server_fld *ss_server_fld;
438 struct lu_client_fld *ss_client_fld;
443 struct lu_server_seq *ss_server_seq;
446 * Controller Seq Manager
448 struct lu_server_seq *ss_control_seq;
449 struct obd_export *ss_control_exp;
454 struct lu_client_seq *ss_client_seq;
457 static inline struct md_device *lu2md_dev(const struct lu_device *d)
459 LASSERT(IS_ERR(d) || lu_device_is_md(d));
460 return container_of0(d, struct md_device, md_lu_dev);
463 static inline struct lu_device *md2lu_dev(struct md_device *d)
465 return &d->md_lu_dev;
468 static inline struct md_object *lu2md(const struct lu_object *o)
470 LASSERT(o == NULL || IS_ERR(o) || lu_device_is_md(o->lo_dev));
471 return container_of0(o, struct md_object, mo_lu);
474 static inline struct md_object *md_object_next(const struct md_object *obj)
476 return (obj ? lu2md(lu_object_next(&obj->mo_lu)) : NULL);
479 static inline struct md_device *md_obj2dev(const struct md_object *o)
481 LASSERT(o == NULL || IS_ERR(o) || lu_device_is_md(o->mo_lu.lo_dev));
482 return container_of0(o->mo_lu.lo_dev, struct md_device, md_lu_dev);
485 static inline int md_device_init(struct md_device *md, struct lu_device_type *t)
487 return lu_device_init(&md->md_lu_dev, t);
490 static inline void md_device_fini(struct md_device *md)
492 lu_device_fini(&md->md_lu_dev);
495 static inline struct md_object *md_object_find_slice(const struct lu_env *env,
496 struct md_device *md,
497 const struct lu_fid *f)
499 return lu2md(lu_object_find_slice(env, md2lu_dev(md), f, NULL));
504 static inline int mo_permission(const struct lu_env *env,
510 LASSERT(c->mo_ops->moo_permission);
511 return c->mo_ops->moo_permission(env, p, c, at, mask);
514 static inline int mo_attr_get(const struct lu_env *env,
518 LASSERT(m->mo_ops->moo_attr_get);
519 return m->mo_ops->moo_attr_get(env, m, at);
522 static inline int mo_readlink(const struct lu_env *env,
526 LASSERT(m->mo_ops->moo_readlink);
527 return m->mo_ops->moo_readlink(env, m, buf);
530 static inline int mo_changelog(const struct lu_env *env,
531 enum changelog_rec_type type,
532 int flags, struct md_object *m)
534 LASSERT(m->mo_ops->moo_changelog);
535 return m->mo_ops->moo_changelog(env, type, flags, m);
538 static inline int mo_attr_set(const struct lu_env *env,
540 const struct md_attr *at)
542 LASSERT(m->mo_ops->moo_attr_set);
543 return m->mo_ops->moo_attr_set(env, m, at);
546 static inline int mo_xattr_get(const struct lu_env *env,
551 LASSERT(m->mo_ops->moo_xattr_get);
552 return m->mo_ops->moo_xattr_get(env, m, buf, name);
555 static inline int mo_xattr_del(const struct lu_env *env,
559 LASSERT(m->mo_ops->moo_xattr_del);
560 return m->mo_ops->moo_xattr_del(env, m, name);
563 static inline int mo_xattr_set(const struct lu_env *env,
565 const struct lu_buf *buf,
569 LASSERT(m->mo_ops->moo_xattr_set);
570 return m->mo_ops->moo_xattr_set(env, m, buf, name, flags);
573 static inline int mo_xattr_list(const struct lu_env *env,
577 LASSERT(m->mo_ops->moo_xattr_list);
578 return m->mo_ops->moo_xattr_list(env, m, buf);
581 static inline int mo_swap_layouts(const struct lu_env *env,
582 struct md_object *o1,
583 struct md_object *o2, __u64 flags)
585 LASSERT(o1->mo_ops->moo_swap_layouts);
586 LASSERT(o2->mo_ops->moo_swap_layouts);
587 if (o1->mo_ops->moo_swap_layouts != o2->mo_ops->moo_swap_layouts)
589 return o1->mo_ops->moo_swap_layouts(env, o1, o2, flags);
592 static inline int mo_open(const struct lu_env *env,
596 LASSERT(m->mo_ops->moo_open);
597 return m->mo_ops->moo_open(env, m, flags);
600 static inline int mo_close(const struct lu_env *env,
605 LASSERT(m->mo_ops->moo_close);
606 return m->mo_ops->moo_close(env, m, ma, mode);
609 static inline int mo_readpage(const struct lu_env *env,
611 const struct lu_rdpg *rdpg)
613 LASSERT(m->mo_ops->moo_readpage);
614 return m->mo_ops->moo_readpage(env, m, rdpg);
617 static inline int mo_object_create(const struct lu_env *env,
619 const struct md_op_spec *spc,
622 LASSERT(m->mo_ops->moo_object_create);
623 return m->mo_ops->moo_object_create(env, m, spc, at);
626 static inline int mo_ref_add(const struct lu_env *env,
628 const struct md_attr *ma)
630 LASSERT(m->mo_ops->moo_ref_add);
631 return m->mo_ops->moo_ref_add(env, m, ma);
634 static inline int mo_ref_del(const struct lu_env *env,
638 LASSERT(m->mo_ops->moo_ref_del);
639 return m->mo_ops->moo_ref_del(env, m, ma);
642 static inline int mo_capa_get(const struct lu_env *env,
644 struct lustre_capa *c,
647 LASSERT(m->mo_ops->moo_capa_get);
648 return m->mo_ops->moo_capa_get(env, m, c, renewal);
651 static inline int mo_object_sync(const struct lu_env *env, struct md_object *m)
653 LASSERT(m->mo_ops->moo_object_sync);
654 return m->mo_ops->moo_object_sync(env, m);
657 static inline int mo_file_lock(const struct lu_env *env, struct md_object *m,
658 struct lov_mds_md *lmm,
659 struct ldlm_extent *extent,
660 struct lustre_handle *lockh)
662 LASSERT(m->mo_ops->moo_file_lock);
663 return m->mo_ops->moo_file_lock(env, m, lmm, extent, lockh);
666 static inline int mo_file_unlock(const struct lu_env *env, struct md_object *m,
667 struct lov_mds_md *lmm,
668 struct lustre_handle *lockh)
670 LASSERT(m->mo_ops->moo_file_unlock);
671 return m->mo_ops->moo_file_unlock(env, m, lmm, lockh);
674 static inline int mo_object_lock(const struct lu_env *env,
676 struct lustre_handle *lh,
677 struct ldlm_enqueue_info *einfo,
678 union ldlm_policy_data *policy)
680 LASSERT(m->mo_ops->moo_object_lock);
681 return m->mo_ops->moo_object_lock(env, m, lh, einfo, policy);
684 static inline int mo_object_unlock(const struct lu_env *env,
686 struct ldlm_enqueue_info *einfo,
687 union ldlm_policy_data *policy)
689 LASSERT(m->mo_ops->moo_object_unlock);
690 return m->mo_ops->moo_object_unlock(env, m, einfo, policy);
693 static inline int mdo_lookup(const struct lu_env *env,
695 const struct lu_name *lname,
697 struct md_op_spec *spec)
699 LASSERT(p->mo_dir_ops->mdo_lookup);
700 return p->mo_dir_ops->mdo_lookup(env, p, lname, f, spec);
703 static inline mdl_mode_t mdo_lock_mode(const struct lu_env *env,
704 struct md_object *mo,
707 if (mo->mo_dir_ops->mdo_lock_mode == NULL)
709 return mo->mo_dir_ops->mdo_lock_mode(env, mo, lm);
712 static inline int mdo_create(const struct lu_env *env,
714 const struct lu_name *lchild_name,
716 struct md_op_spec *spc,
719 LASSERT(p->mo_dir_ops->mdo_create);
720 return p->mo_dir_ops->mdo_create(env, p, lchild_name, c, spc, at);
723 static inline int mdo_create_data(const struct lu_env *env,
726 const struct md_op_spec *spec,
729 LASSERT(c->mo_dir_ops->mdo_create_data);
730 return c->mo_dir_ops->mdo_create_data(env, p, c, spec, ma);
733 static inline int mdo_rename(const struct lu_env *env,
734 struct md_object *sp,
735 struct md_object *tp,
736 const struct lu_fid *lf,
737 const struct lu_name *lsname,
739 const struct lu_name *ltname,
742 LASSERT(tp->mo_dir_ops->mdo_rename);
743 return tp->mo_dir_ops->mdo_rename(env, sp, tp, lf, lsname, t, ltname,
747 static inline int mdo_is_subdir(const struct lu_env *env,
748 struct md_object *mo,
749 const struct lu_fid *fid,
752 LASSERT(mo->mo_dir_ops->mdo_is_subdir);
753 return mo->mo_dir_ops->mdo_is_subdir(env, mo, fid, sfid);
756 static inline int mdo_link(const struct lu_env *env,
759 const struct lu_name *lname,
762 LASSERT(s->mo_dir_ops->mdo_link);
763 return s->mo_dir_ops->mdo_link(env, p, s, lname, ma);
766 static inline int mdo_unlink(const struct lu_env *env,
769 const struct lu_name *lname,
770 struct md_attr *ma, int no_name)
772 LASSERT(p->mo_dir_ops->mdo_unlink);
773 return p->mo_dir_ops->mdo_unlink(env, p, c, lname, ma, no_name);
776 static inline int mdo_lum_lmm_cmp(const struct lu_env *env,
778 const struct md_op_spec *spec,
781 LASSERT(c->mo_dir_ops->mdo_lum_lmm_cmp);
782 return c->mo_dir_ops->mdo_lum_lmm_cmp(env, c, spec, ma);
785 static inline int mdo_name_insert(const struct lu_env *env,
787 const struct lu_name *lname,
788 const struct lu_fid *f,
789 const struct md_attr *ma)
791 LASSERT(p->mo_dir_ops->mdo_name_insert);
792 return p->mo_dir_ops->mdo_name_insert(env, p, lname, f, ma);
795 static inline int mdo_name_remove(const struct lu_env *env,
797 const struct lu_name *lname,
798 const struct md_attr *ma)
800 LASSERT(p->mo_dir_ops->mdo_name_remove);
801 return p->mo_dir_ops->mdo_name_remove(env, p, lname, ma);
804 static inline int mdo_rename_tgt(const struct lu_env *env,
807 const struct lu_fid *lf,
808 const struct lu_name *lname,
812 LASSERT(t->mo_dir_ops->mdo_rename_tgt);
813 return t->mo_dir_ops->mdo_rename_tgt(env, p, t, lf, lname, ma);
815 LASSERT(p->mo_dir_ops->mdo_rename_tgt);
816 return p->mo_dir_ops->mdo_rename_tgt(env, p, t, lf, lname, ma);
821 * Used in MDD/OUT layer for object lock rule
823 enum mdd_object_role {
833 * Structure to hold object information. This is used to create object
834 * \pre llod_dir exist
836 struct lu_local_obj_desc {
837 const char *llod_dir;
838 const char *llod_name;
841 const struct dt_index_features *llod_feat;
842 cfs_list_t llod_linkage;
845 int lustre_buf2som(void *buf, int rc, struct md_som_data *msd);
846 int lustre_buf2hsm(void *buf, int rc, struct md_hsm *mh);
847 void lustre_hsm2buf(void *buf, const struct md_hsm *mh);
866 __u32 uc_suppgids[2];
869 struct group_info *uc_ginfo;
870 struct md_identity *uc_identity;
873 struct lu_ucred *lu_ucred(const struct lu_env *env);
875 struct lu_ucred *lu_ucred_check(const struct lu_env *env);
877 struct lu_ucred *lu_ucred_assert(const struct lu_env *env);
879 int lu_ucred_global_init(void);
881 void lu_ucred_global_fini(void);
883 #define md_cap_t(x) (x)
885 #define MD_CAP_TO_MASK(x) (1 << (x))
887 #define md_cap_raised(c, flag) (md_cap_t(c) & MD_CAP_TO_MASK(flag))
889 /* capable() is copied from linux kernel! */
890 static inline int md_capable(struct lu_ucred *uc, cfs_cap_t cap)
892 if (md_cap_raised(uc->uc_cap, cap))
898 #endif /* _LINUX_MD_OBJECT_H */