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, 2012, Whamcloud, Inc.
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 /* LU-1051, temperary solution to reduce llog credits */
63 #define DECLARE_LLOG_REWRITE 0
64 #define DECLARE_LLOG_WRITE INT_MAX
67 struct md_device_operations;
91 cfs_group_info_t *mu_ginfo;
92 struct md_identity *mu_identity;
99 /** there are at most 5 fids in one operation, see rename, NOTE the last one
100 * is a temporary one used for is_subdir() */
104 struct lu_fid mc_fid[MD_CAPAINFO_MAX];
105 struct lustre_capa *mc_capa[MD_CAPAINFO_MAX];
109 struct obd_export *mq_exp;
113 * Implemented in mdd/mdd_handler.c.
115 * XXX should be moved into separate .h/.c together with all md security
116 * related definitions.
118 struct md_ucred *md_ucred(const struct lu_env *env);
119 struct md_capainfo *md_capainfo(const struct lu_env *env);
120 struct md_quota *md_quota(const struct lu_env *env);
122 /** metadata attributes */
126 MA_COOKIE = (1 << 2),
129 MA_ACL_DEF = (1 << 5),
130 MA_LOV_DEF = (1 << 6),
131 MA_LAY_GEN = (1 << 7),
151 MDT_REG_LOCK = (1 << 0),
152 MDT_PDO_LOCK = (1 << 1)
157 __u32 mh_archive_number;
160 #define IOEPOCH_INVAL 0
173 struct lu_attr ma_attr;
174 struct lu_fid ma_pfid;
175 struct md_hsm ma_hsm;
176 struct lov_mds_md *ma_lmm;
177 struct lmv_stripe_md *ma_lmv;
179 struct llog_cookie *ma_cookie;
180 struct lustre_capa *ma_capa;
181 struct md_som_data *ma_som;
183 int ma_big_lmm_used:1;
190 /** Additional parameters for create */
193 /** symlink target */
194 const char *sp_symname;
195 /** parent FID for cross-ref mkdir */
196 const struct lu_fid *sp_pfid;
197 /** eadata for regular files */
199 /** lov objs exist already */
200 const struct lu_fid *fid;
205 /** don't create lov objects or llog cookie - this replay */
208 /** Create flag from client: such as MDS_OPEN_CREAT, and others. */
211 /** Should mdd do lookup sanity check or not. */
214 /** Current lock mode for parent dir where create is performing. */
215 mdl_mode_t sp_cr_mode;
217 /** Check for split */
220 /** to create directory */
221 const struct dt_index_features *sp_feat;
225 * Operations implemented for each md object (both directory and leaf).
227 struct md_object_operations {
228 int (*moo_permission)(const struct lu_env *env,
229 struct md_object *pobj, struct md_object *cobj,
230 struct md_attr *attr, int mask);
232 int (*moo_attr_get)(const struct lu_env *env, struct md_object *obj,
233 struct md_attr *attr);
235 int (*moo_attr_set)(const struct lu_env *env, struct md_object *obj,
236 const struct md_attr *attr);
238 int (*moo_xattr_get)(const struct lu_env *env, struct md_object *obj,
239 struct lu_buf *buf, const char *name);
241 int (*moo_xattr_list)(const struct lu_env *env, struct md_object *obj,
244 int (*moo_xattr_set)(const struct lu_env *env, struct md_object *obj,
245 const struct lu_buf *buf, const char *name,
248 int (*moo_xattr_del)(const struct lu_env *env, struct md_object *obj,
251 /** \retval number of bytes actually read upon success */
252 int (*moo_readpage)(const struct lu_env *env, struct md_object *obj,
253 const struct lu_rdpg *rdpg);
255 int (*moo_readlink)(const struct lu_env *env, struct md_object *obj,
257 int (*moo_changelog)(const struct lu_env *env,
258 enum changelog_rec_type type, int flags,
259 struct md_object *obj);
260 /** part of cross-ref operation */
261 int (*moo_object_create)(const struct lu_env *env,
262 struct md_object *obj,
263 const struct md_op_spec *spec,
266 int (*moo_ref_add)(const struct lu_env *env,
267 struct md_object *obj,
268 const struct md_attr *ma);
270 int (*moo_ref_del)(const struct lu_env *env,
271 struct md_object *obj,
274 int (*moo_open)(const struct lu_env *env,
275 struct md_object *obj, int flag);
277 int (*moo_close)(const struct lu_env *env, struct md_object *obj,
278 struct md_attr *ma, int mode);
280 int (*moo_capa_get)(const struct lu_env *, struct md_object *,
281 struct lustre_capa *, int renewal);
283 int (*moo_object_sync)(const struct lu_env *, struct md_object *);
284 int (*moo_path)(const struct lu_env *env, struct md_object *obj,
285 char *path, int pathlen, __u64 *recno, int *linkno);
286 int (*moo_file_lock)(const struct lu_env *env, struct md_object *obj,
287 struct lov_mds_md *lmm, struct ldlm_extent *extent,
288 struct lustre_handle *lockh);
289 int (*moo_file_unlock)(const struct lu_env *env, struct md_object *obj,
290 struct lov_mds_md *lmm,
291 struct lustre_handle *lockh);
295 * Operations implemented for each directory object.
297 struct md_dir_operations {
298 int (*mdo_is_subdir) (const struct lu_env *env, struct md_object *obj,
299 const struct lu_fid *fid, struct lu_fid *sfid);
301 int (*mdo_lookup)(const struct lu_env *env, struct md_object *obj,
302 const struct lu_name *lname, struct lu_fid *fid,
303 struct md_op_spec *spec);
305 mdl_mode_t (*mdo_lock_mode)(const struct lu_env *env,
306 struct md_object *obj,
309 int (*mdo_create)(const struct lu_env *env, struct md_object *pobj,
310 const struct lu_name *lname, struct md_object *child,
311 struct md_op_spec *spec,
314 /** This method is used for creating data object for this meta object*/
315 int (*mdo_create_data)(const struct lu_env *env, struct md_object *p,
317 const struct md_op_spec *spec,
320 int (*mdo_rename)(const struct lu_env *env, struct md_object *spobj,
321 struct md_object *tpobj, const struct lu_fid *lf,
322 const struct lu_name *lsname, struct md_object *tobj,
323 const struct lu_name *ltname, struct md_attr *ma);
325 int (*mdo_link)(const struct lu_env *env, struct md_object *tgt_obj,
326 struct md_object *src_obj, const struct lu_name *lname,
329 int (*mdo_unlink)(const struct lu_env *env, struct md_object *pobj,
330 struct md_object *cobj, const struct lu_name *lname,
333 /** This method is used to compare a requested layout to an existing
334 * layout (struct lov_mds_md_v1/3 vs struct lov_mds_md_v1/3) */
335 int (*mdo_lum_lmm_cmp)(const struct lu_env *env,
336 struct md_object *cobj,
337 const struct md_op_spec *spec,
340 /** partial ops for cross-ref case */
341 int (*mdo_name_insert)(const struct lu_env *env,
342 struct md_object *obj,
343 const struct lu_name *lname,
344 const struct lu_fid *fid,
345 const struct md_attr *ma);
347 int (*mdo_name_remove)(const struct lu_env *env,
348 struct md_object *obj,
349 const struct lu_name *lname,
350 const struct md_attr *ma);
352 int (*mdo_rename_tgt)(const struct lu_env *env, struct md_object *pobj,
353 struct md_object *tobj, const struct lu_fid *fid,
354 const struct lu_name *lname, struct md_attr *ma);
357 struct md_device_operations {
358 /** meta-data device related handlers. */
359 int (*mdo_root_get)(const struct lu_env *env, struct md_device *m,
362 int (*mdo_maxsize_get)(const struct lu_env *env, struct md_device *m,
363 int *md_size, int *cookie_size);
365 int (*mdo_statfs)(const struct lu_env *env, struct md_device *m,
366 struct obd_statfs *sfs);
368 int (*mdo_init_capa_ctxt)(const struct lu_env *env, struct md_device *m,
369 int mode, unsigned long timeout, __u32 alg,
370 struct lustre_capa_key *keys);
372 int (*mdo_update_capa_key)(const struct lu_env *env,
374 struct lustre_capa_key *key);
376 int (*mdo_llog_ctxt_get)(const struct lu_env *env,
377 struct md_device *m, int idx, void **h);
379 int (*mdo_iocontrol)(const struct lu_env *env, struct md_device *m,
380 unsigned int cmd, int len, void *data);
383 enum md_upcall_event {
384 /** Sync the md layer*/
385 MD_LOV_SYNC = (1 << 0),
386 /** Just for split, no need trans, for replay */
387 MD_NO_TRANS = (1 << 1),
388 MD_LOV_CONFIG = (1 << 2),
389 /** Trigger quota recovery */
390 MD_LOV_QUOTA = (1 << 3)
394 /** this lock protects upcall using against its removal
395 * read lock is for usage the upcall, write - for init/fini */
396 cfs_rw_semaphore_t mu_upcall_sem;
397 /** device to call, upper layer normally */
398 struct md_device *mu_upcall_dev;
399 /** upcall function */
400 int (*mu_upcall)(const struct lu_env *env, struct md_device *md,
401 enum md_upcall_event ev, void *data);
405 struct lu_device md_lu_dev;
406 const struct md_device_operations *md_ops;
407 struct md_upcall md_upcall;
410 static inline void md_upcall_init(struct md_device *m, void *upcl)
412 cfs_init_rwsem(&m->md_upcall.mu_upcall_sem);
413 m->md_upcall.mu_upcall_dev = NULL;
414 m->md_upcall.mu_upcall = upcl;
417 static inline void md_upcall_dev_set(struct md_device *m, struct md_device *up)
419 cfs_down_write(&m->md_upcall.mu_upcall_sem);
420 m->md_upcall.mu_upcall_dev = up;
421 cfs_up_write(&m->md_upcall.mu_upcall_sem);
424 static inline void md_upcall_fini(struct md_device *m)
426 cfs_down_write(&m->md_upcall.mu_upcall_sem);
427 m->md_upcall.mu_upcall_dev = NULL;
428 m->md_upcall.mu_upcall = NULL;
429 cfs_up_write(&m->md_upcall.mu_upcall_sem);
432 static inline int md_do_upcall(const struct lu_env *env, struct md_device *m,
433 enum md_upcall_event ev, void *data)
436 cfs_down_read(&m->md_upcall.mu_upcall_sem);
437 if (m->md_upcall.mu_upcall_dev != NULL &&
438 m->md_upcall.mu_upcall_dev->md_upcall.mu_upcall != NULL) {
439 rc = m->md_upcall.mu_upcall_dev->md_upcall.mu_upcall(env,
440 m->md_upcall.mu_upcall_dev,
443 cfs_up_read(&m->md_upcall.mu_upcall_sem);
448 struct lu_object mo_lu;
449 const struct md_object_operations *mo_ops;
450 const struct md_dir_operations *mo_dir_ops;
457 struct lu_site *ms_lu;
459 * mds number of this site.
463 * Fid location database
465 struct lu_server_fld *ms_server_fld;
466 struct lu_client_fld *ms_client_fld;
471 struct lu_server_seq *ms_server_seq;
474 * Controller Seq Manager
476 struct lu_server_seq *ms_control_seq;
477 struct obd_export *ms_control_exp;
482 struct lu_client_seq *ms_client_seq;
485 static inline int lu_device_is_md(const struct lu_device *d)
487 return ergo(d != NULL, d->ld_type->ldt_tags & LU_DEVICE_MD);
490 static inline struct md_device *lu2md_dev(const struct lu_device *d)
492 LASSERT(IS_ERR(d) || lu_device_is_md(d));
493 return container_of0(d, struct md_device, md_lu_dev);
496 static inline struct lu_device *md2lu_dev(struct md_device *d)
498 return &d->md_lu_dev;
501 static inline struct md_object *lu2md(const struct lu_object *o)
503 LASSERT(o == NULL || IS_ERR(o) || lu_device_is_md(o->lo_dev));
504 return container_of0(o, struct md_object, mo_lu);
507 static inline struct md_object *md_object_next(const struct md_object *obj)
509 return (obj ? lu2md(lu_object_next(&obj->mo_lu)) : NULL);
512 static inline struct md_device *md_obj2dev(const struct md_object *o)
514 LASSERT(o == NULL || IS_ERR(o) || lu_device_is_md(o->mo_lu.lo_dev));
515 return container_of0(o->mo_lu.lo_dev, struct md_device, md_lu_dev);
518 static inline struct md_site *lu_site2md(const struct lu_site *s)
520 return s->ld_md_site;
523 static inline int md_device_init(struct md_device *md, struct lu_device_type *t)
525 return lu_device_init(&md->md_lu_dev, t);
528 static inline void md_device_fini(struct md_device *md)
530 lu_device_fini(&md->md_lu_dev);
533 static inline struct md_object *md_object_find_slice(const struct lu_env *env,
534 struct md_device *md,
535 const struct lu_fid *f)
537 return lu2md(lu_object_find_slice(env, md2lu_dev(md), f, NULL));
542 static inline int mo_permission(const struct lu_env *env,
548 LASSERT(c->mo_ops->moo_permission);
549 return c->mo_ops->moo_permission(env, p, c, at, mask);
552 static inline int mo_attr_get(const struct lu_env *env,
556 LASSERT(m->mo_ops->moo_attr_get);
557 return m->mo_ops->moo_attr_get(env, m, at);
560 static inline int mo_readlink(const struct lu_env *env,
564 LASSERT(m->mo_ops->moo_readlink);
565 return m->mo_ops->moo_readlink(env, m, buf);
568 static inline int mo_changelog(const struct lu_env *env,
569 enum changelog_rec_type type,
570 int flags, struct md_object *m)
572 LASSERT(m->mo_ops->moo_changelog);
573 return m->mo_ops->moo_changelog(env, type, flags, m);
576 static inline int mo_attr_set(const struct lu_env *env,
578 const struct md_attr *at)
580 LASSERT(m->mo_ops->moo_attr_set);
581 return m->mo_ops->moo_attr_set(env, m, at);
584 static inline int mo_xattr_get(const struct lu_env *env,
589 LASSERT(m->mo_ops->moo_xattr_get);
590 return m->mo_ops->moo_xattr_get(env, m, buf, name);
593 static inline int mo_xattr_del(const struct lu_env *env,
597 LASSERT(m->mo_ops->moo_xattr_del);
598 return m->mo_ops->moo_xattr_del(env, m, name);
601 static inline int mo_xattr_set(const struct lu_env *env,
603 const struct lu_buf *buf,
607 LASSERT(m->mo_ops->moo_xattr_set);
608 return m->mo_ops->moo_xattr_set(env, m, buf, name, flags);
611 static inline int mo_xattr_list(const struct lu_env *env,
615 LASSERT(m->mo_ops->moo_xattr_list);
616 return m->mo_ops->moo_xattr_list(env, m, buf);
619 static inline int mo_open(const struct lu_env *env,
623 LASSERT(m->mo_ops->moo_open);
624 return m->mo_ops->moo_open(env, m, flags);
627 static inline int mo_close(const struct lu_env *env,
632 LASSERT(m->mo_ops->moo_close);
633 return m->mo_ops->moo_close(env, m, ma, mode);
636 static inline int mo_readpage(const struct lu_env *env,
638 const struct lu_rdpg *rdpg)
640 LASSERT(m->mo_ops->moo_readpage);
641 return m->mo_ops->moo_readpage(env, m, rdpg);
644 static inline int mo_object_create(const struct lu_env *env,
646 const struct md_op_spec *spc,
649 LASSERT(m->mo_ops->moo_object_create);
650 return m->mo_ops->moo_object_create(env, m, spc, at);
653 static inline int mo_ref_add(const struct lu_env *env,
655 const struct md_attr *ma)
657 LASSERT(m->mo_ops->moo_ref_add);
658 return m->mo_ops->moo_ref_add(env, m, ma);
661 static inline int mo_ref_del(const struct lu_env *env,
665 LASSERT(m->mo_ops->moo_ref_del);
666 return m->mo_ops->moo_ref_del(env, m, ma);
669 static inline int mo_capa_get(const struct lu_env *env,
671 struct lustre_capa *c,
674 LASSERT(m->mo_ops->moo_capa_get);
675 return m->mo_ops->moo_capa_get(env, m, c, renewal);
678 static inline int mo_path(const struct lu_env *env, struct md_object *m,
679 char *path, int pathlen, __u64 *recno, int *linkno)
681 if (m->mo_ops->moo_path == NULL)
683 return m->mo_ops->moo_path(env, m, path, pathlen, recno, linkno);
686 static inline int mo_object_sync(const struct lu_env *env, struct md_object *m)
688 LASSERT(m->mo_ops->moo_object_sync);
689 return m->mo_ops->moo_object_sync(env, m);
692 static inline int mo_file_lock(const struct lu_env *env, struct md_object *m,
693 struct lov_mds_md *lmm,
694 struct ldlm_extent *extent,
695 struct lustre_handle *lockh)
697 LASSERT(m->mo_ops->moo_file_lock);
698 return m->mo_ops->moo_file_lock(env, m, lmm, extent, lockh);
701 static inline int mo_file_unlock(const struct lu_env *env, struct md_object *m,
702 struct lov_mds_md *lmm,
703 struct lustre_handle *lockh)
705 LASSERT(m->mo_ops->moo_file_unlock);
706 return m->mo_ops->moo_file_unlock(env, m, lmm, lockh);
709 static inline int mdo_lookup(const struct lu_env *env,
711 const struct lu_name *lname,
713 struct md_op_spec *spec)
715 LASSERT(p->mo_dir_ops->mdo_lookup);
716 return p->mo_dir_ops->mdo_lookup(env, p, lname, f, spec);
719 static inline mdl_mode_t mdo_lock_mode(const struct lu_env *env,
720 struct md_object *mo,
723 if (mo->mo_dir_ops->mdo_lock_mode == NULL)
725 return mo->mo_dir_ops->mdo_lock_mode(env, mo, lm);
728 static inline int mdo_create(const struct lu_env *env,
730 const struct lu_name *lchild_name,
732 struct md_op_spec *spc,
735 LASSERT(p->mo_dir_ops->mdo_create);
736 return p->mo_dir_ops->mdo_create(env, p, lchild_name, c, spc, at);
739 static inline int mdo_create_data(const struct lu_env *env,
742 const struct md_op_spec *spec,
745 LASSERT(c->mo_dir_ops->mdo_create_data);
746 return c->mo_dir_ops->mdo_create_data(env, p, c, spec, ma);
749 static inline int mdo_rename(const struct lu_env *env,
750 struct md_object *sp,
751 struct md_object *tp,
752 const struct lu_fid *lf,
753 const struct lu_name *lsname,
755 const struct lu_name *ltname,
758 LASSERT(tp->mo_dir_ops->mdo_rename);
759 return tp->mo_dir_ops->mdo_rename(env, sp, tp, lf, lsname, t, ltname,
763 static inline int mdo_is_subdir(const struct lu_env *env,
764 struct md_object *mo,
765 const struct lu_fid *fid,
768 LASSERT(mo->mo_dir_ops->mdo_is_subdir);
769 return mo->mo_dir_ops->mdo_is_subdir(env, mo, fid, sfid);
772 static inline int mdo_link(const struct lu_env *env,
775 const struct lu_name *lname,
778 LASSERT(s->mo_dir_ops->mdo_link);
779 return s->mo_dir_ops->mdo_link(env, p, s, lname, ma);
782 static inline int mdo_unlink(const struct lu_env *env,
785 const struct lu_name *lname,
788 LASSERT(c->mo_dir_ops->mdo_unlink);
789 return c->mo_dir_ops->mdo_unlink(env, p, c, lname, ma);
792 static inline int mdo_lum_lmm_cmp(const struct lu_env *env,
794 const struct md_op_spec *spec,
797 LASSERT(c->mo_dir_ops->mdo_lum_lmm_cmp);
798 return c->mo_dir_ops->mdo_lum_lmm_cmp(env, c, spec, ma);
801 static inline int mdo_name_insert(const struct lu_env *env,
803 const struct lu_name *lname,
804 const struct lu_fid *f,
805 const struct md_attr *ma)
807 LASSERT(p->mo_dir_ops->mdo_name_insert);
808 return p->mo_dir_ops->mdo_name_insert(env, p, lname, f, ma);
811 static inline int mdo_name_remove(const struct lu_env *env,
813 const struct lu_name *lname,
814 const struct md_attr *ma)
816 LASSERT(p->mo_dir_ops->mdo_name_remove);
817 return p->mo_dir_ops->mdo_name_remove(env, p, lname, ma);
820 static inline int mdo_rename_tgt(const struct lu_env *env,
823 const struct lu_fid *lf,
824 const struct lu_name *lname,
828 LASSERT(t->mo_dir_ops->mdo_rename_tgt);
829 return t->mo_dir_ops->mdo_rename_tgt(env, p, t, lf, lname, ma);
831 LASSERT(p->mo_dir_ops->mdo_rename_tgt);
832 return p->mo_dir_ops->mdo_rename_tgt(env, p, t, lf, lname, ma);
838 * Structure to hold object information. This is used to create object
839 * \pre llod_dir exist
841 struct lu_local_obj_desc {
842 const char *llod_dir;
843 const char *llod_name;
846 const struct dt_index_features *llod_feat;
847 cfs_list_t llod_linkage;
850 struct md_object *llo_store_resolve(const struct lu_env *env,
851 struct md_device *md,
852 struct dt_device *dt,
856 struct md_object *llo_store_open(const struct lu_env *env,
857 struct md_device *md,
858 struct dt_device *dt,
863 struct md_object *llo_store_create_index(const struct lu_env *env,
864 struct md_device *md,
865 struct dt_device *dt,
868 const struct lu_fid *fid,
869 const struct dt_index_features *feat);
871 struct md_object *llo_store_create(const struct lu_env *env,
872 struct md_device *md,
873 struct dt_device *dt,
876 const struct lu_fid *fid);
878 void llo_local_obj_register(struct lu_local_obj_desc *);
879 void llo_local_obj_unregister(struct lu_local_obj_desc *);
881 int llo_local_objects_setup(const struct lu_env *env,
882 struct md_device * md,
883 struct dt_device * dt);
886 #endif /* _LINUX_MD_OBJECT_H */