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
20 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
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 (c) 2007, 2010, Oracle and/or its affiliates. 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.
57 * super-class definitions.
59 #include <dt_object.h>
63 struct md_device_operations;
87 cfs_group_info_t *mu_ginfo;
88 struct md_identity *mu_identity;
95 /** there are at most 5 fids in one operation, see rename, NOTE the last one
96 * is a temporary one used for is_subdir() */
100 const struct lu_fid *mc_fid[MD_CAPAINFO_MAX];
101 struct lustre_capa *mc_capa[MD_CAPAINFO_MAX];
105 struct obd_export *mq_exp;
109 * Implemented in mdd/mdd_handler.c.
111 * XXX should be moved into separate .h/.c together with all md security
112 * related definitions.
114 struct md_ucred *md_ucred(const struct lu_env *env);
115 struct md_capainfo *md_capainfo(const struct lu_env *env);
116 struct md_quota *md_quota(const struct lu_env *env);
118 /** metadata attributes */
122 MA_COOKIE = (1 << 2),
125 MA_ACL_DEF = (1 << 5),
126 MA_LOV_DEF = (1 << 6),
127 /* (Layout lock will used #7 here) */
146 MDT_REG_LOCK = (1 << 0),
147 MDT_PDO_LOCK = (1 << 1)
152 __u32 mh_archive_number;
155 #define IOEPOCH_INVAL 0
168 struct lu_attr ma_attr;
169 struct lov_mds_md *ma_lmm;
171 struct lmv_stripe_md *ma_lmv;
175 struct llog_cookie *ma_cookie;
177 struct lustre_capa *ma_capa;
178 struct md_hsm ma_hsm;
179 struct md_som_data *ma_som;
182 /** Additional parameters for create */
185 /** symlink target */
186 const char *sp_symname;
187 /** parent FID for cross-ref mkdir */
188 const struct lu_fid *sp_pfid;
189 /** eadata for regular files */
191 /** lov objs exist already */
192 const struct lu_fid *fid;
197 /** don't create lov objects or llog cookie - this replay */
200 /** Create flag from client: such as MDS_OPEN_CREAT, and others. */
203 /** Should mdd do lookup sanity check or not. */
206 /** Current lock mode for parent dir where create is performing. */
207 mdl_mode_t sp_cr_mode;
209 /** Check for split */
212 /** to create directory */
213 const struct dt_index_features *sp_feat;
217 * Operations implemented for each md object (both directory and leaf).
219 struct md_object_operations {
220 int (*moo_permission)(const struct lu_env *env,
221 struct md_object *pobj, struct md_object *cobj,
222 struct md_attr *attr, int mask);
224 int (*moo_attr_get)(const struct lu_env *env, struct md_object *obj,
225 struct md_attr *attr);
227 int (*moo_attr_set)(const struct lu_env *env, struct md_object *obj,
228 const struct md_attr *attr);
230 int (*moo_xattr_get)(const struct lu_env *env, struct md_object *obj,
231 struct lu_buf *buf, const char *name);
233 int (*moo_xattr_list)(const struct lu_env *env, struct md_object *obj,
236 int (*moo_xattr_set)(const struct lu_env *env, struct md_object *obj,
237 const struct lu_buf *buf, const char *name,
240 int (*moo_xattr_del)(const struct lu_env *env, struct md_object *obj,
243 int (*moo_readpage)(const struct lu_env *env, struct md_object *obj,
244 const struct lu_rdpg *rdpg);
246 int (*moo_readlink)(const struct lu_env *env, struct md_object *obj,
248 int (*moo_changelog)(const struct lu_env *env,
249 enum changelog_rec_type type, int flags,
250 struct md_object *obj);
251 /** part of cross-ref operation */
252 int (*moo_object_create)(const struct lu_env *env,
253 struct md_object *obj,
254 const struct md_op_spec *spec,
257 int (*moo_ref_add)(const struct lu_env *env,
258 struct md_object *obj,
259 const struct md_attr *ma);
261 int (*moo_ref_del)(const struct lu_env *env,
262 struct md_object *obj,
265 int (*moo_open)(const struct lu_env *env,
266 struct md_object *obj, int flag);
268 int (*moo_close)(const struct lu_env *env, struct md_object *obj,
271 int (*moo_capa_get)(const struct lu_env *, struct md_object *,
272 struct lustre_capa *, int renewal);
274 int (*moo_object_sync)(const struct lu_env *, struct md_object *);
275 dt_obj_version_t (*moo_version_get)(const struct lu_env *,
277 void (*moo_version_set)(const struct lu_env *, struct md_object *,
279 int (*moo_path)(const struct lu_env *env, struct md_object *obj,
280 char *path, int pathlen, __u64 *recno, int *linkno);
284 * Operations implemented for each directory object.
286 struct md_dir_operations {
287 int (*mdo_is_subdir) (const struct lu_env *env, struct md_object *obj,
288 const struct lu_fid *fid, struct lu_fid *sfid);
290 int (*mdo_lookup)(const struct lu_env *env, struct md_object *obj,
291 const struct lu_name *lname, struct lu_fid *fid,
292 struct md_op_spec *spec);
294 mdl_mode_t (*mdo_lock_mode)(const struct lu_env *env,
295 struct md_object *obj,
298 int (*mdo_create)(const struct lu_env *env, struct md_object *pobj,
299 const struct lu_name *lname, struct md_object *child,
300 struct md_op_spec *spec,
303 /** This method is used for creating data object for this meta object*/
304 int (*mdo_create_data)(const struct lu_env *env, struct md_object *p,
306 const struct md_op_spec *spec,
309 int (*mdo_rename)(const struct lu_env *env, struct md_object *spobj,
310 struct md_object *tpobj, const struct lu_fid *lf,
311 const struct lu_name *lsname, struct md_object *tobj,
312 const struct lu_name *ltname, struct md_attr *ma);
314 int (*mdo_link)(const struct lu_env *env, struct md_object *tgt_obj,
315 struct md_object *src_obj, const struct lu_name *lname,
318 int (*mdo_unlink)(const struct lu_env *env, struct md_object *pobj,
319 struct md_object *cobj, const struct lu_name *lname,
322 /** partial ops for cross-ref case */
323 int (*mdo_name_insert)(const struct lu_env *env,
324 struct md_object *obj,
325 const struct lu_name *lname,
326 const struct lu_fid *fid,
327 const struct md_attr *ma);
329 int (*mdo_name_remove)(const struct lu_env *env,
330 struct md_object *obj,
331 const struct lu_name *lname,
332 const struct md_attr *ma);
334 int (*mdo_rename_tgt)(const struct lu_env *env, struct md_object *pobj,
335 struct md_object *tobj, const struct lu_fid *fid,
336 const struct lu_name *lname, struct md_attr *ma);
339 struct md_device_operations {
340 /** meta-data device related handlers. */
341 int (*mdo_root_get)(const struct lu_env *env, struct md_device *m,
344 int (*mdo_maxsize_get)(const struct lu_env *env, struct md_device *m,
345 int *md_size, int *cookie_size);
347 int (*mdo_statfs)(const struct lu_env *env, struct md_device *m,
350 int (*mdo_init_capa_ctxt)(const struct lu_env *env, struct md_device *m,
351 int mode, unsigned long timeout, __u32 alg,
352 struct lustre_capa_key *keys);
354 int (*mdo_update_capa_key)(const struct lu_env *env,
356 struct lustre_capa_key *key);
358 int (*mdo_llog_ctxt_get)(const struct lu_env *env,
359 struct md_device *m, int idx, void **h);
361 int (*mdo_iocontrol)(const struct lu_env *env, struct md_device *m,
362 unsigned int cmd, int len, void *data);
364 #ifdef HAVE_QUOTA_SUPPORT
365 struct md_quota_operations {
366 int (*mqo_notify)(const struct lu_env *env,
367 struct md_device *m);
369 int (*mqo_setup)(const struct lu_env *env,
373 int (*mqo_cleanup)(const struct lu_env *env,
374 struct md_device *m);
376 int (*mqo_recovery)(const struct lu_env *env,
377 struct md_device *m);
379 int (*mqo_check)(const struct lu_env *env,
383 int (*mqo_on)(const struct lu_env *env,
387 int (*mqo_off)(const struct lu_env *env,
391 int (*mqo_setinfo)(const struct lu_env *env,
395 struct obd_dqinfo *dqinfo);
397 int (*mqo_getinfo)(const struct lu_env *env,
398 const struct md_device *m,
401 struct obd_dqinfo *dqinfo);
403 int (*mqo_setquota)(const struct lu_env *env,
407 struct obd_dqblk *dqblk);
409 int (*mqo_getquota)(const struct lu_env *env,
410 const struct md_device *m,
413 struct obd_dqblk *dqblk);
415 int (*mqo_getoinfo)(const struct lu_env *env,
416 const struct md_device *m,
419 struct obd_dqinfo *dqinfo);
421 int (*mqo_getoquota)(const struct lu_env *env,
422 const struct md_device *m,
425 struct obd_dqblk *dqblk);
427 int (*mqo_invalidate)(const struct lu_env *env,
431 int (*mqo_finvalidate)(const struct lu_env *env,
438 enum md_upcall_event {
439 /** Sync the md layer*/
440 MD_LOV_SYNC = (1 << 0),
441 /** Just for split, no need trans, for replay */
442 MD_NO_TRANS = (1 << 1),
443 MD_LOV_CONFIG = (1 << 2),
444 /** Trigger quota recovery */
445 MD_LOV_QUOTA = (1 << 3)
449 /** this lock protects upcall using against its removal
450 * read lock is for usage the upcall, write - for init/fini */
451 cfs_rw_semaphore_t mu_upcall_sem;
452 /** device to call, upper layer normally */
453 struct md_device *mu_upcall_dev;
454 /** upcall function */
455 int (*mu_upcall)(const struct lu_env *env, struct md_device *md,
456 enum md_upcall_event ev, void *data);
460 struct lu_device md_lu_dev;
461 const struct md_device_operations *md_ops;
462 struct md_upcall md_upcall;
465 static inline void md_upcall_init(struct md_device *m, void *upcl)
467 cfs_init_rwsem(&m->md_upcall.mu_upcall_sem);
468 m->md_upcall.mu_upcall_dev = NULL;
469 m->md_upcall.mu_upcall = upcl;
472 static inline void md_upcall_dev_set(struct md_device *m, struct md_device *up)
474 cfs_down_write(&m->md_upcall.mu_upcall_sem);
475 m->md_upcall.mu_upcall_dev = up;
476 cfs_up_write(&m->md_upcall.mu_upcall_sem);
479 static inline void md_upcall_fini(struct md_device *m)
481 cfs_down_write(&m->md_upcall.mu_upcall_sem);
482 m->md_upcall.mu_upcall_dev = NULL;
483 m->md_upcall.mu_upcall = NULL;
484 cfs_up_write(&m->md_upcall.mu_upcall_sem);
487 static inline int md_do_upcall(const struct lu_env *env, struct md_device *m,
488 enum md_upcall_event ev, void *data)
491 cfs_down_read(&m->md_upcall.mu_upcall_sem);
492 if (m->md_upcall.mu_upcall_dev != NULL &&
493 m->md_upcall.mu_upcall_dev->md_upcall.mu_upcall != NULL) {
494 rc = m->md_upcall.mu_upcall_dev->md_upcall.mu_upcall(env,
495 m->md_upcall.mu_upcall_dev,
498 cfs_up_read(&m->md_upcall.mu_upcall_sem);
503 struct lu_object mo_lu;
504 const struct md_object_operations *mo_ops;
505 const struct md_dir_operations *mo_dir_ops;
512 struct lu_site ms_lu;
514 * mds number of this site.
518 * Fid location database
520 struct lu_server_fld *ms_server_fld;
521 struct lu_client_fld *ms_client_fld;
526 struct lu_server_seq *ms_server_seq;
529 * Controller Seq Manager
531 struct lu_server_seq *ms_control_seq;
532 struct obd_export *ms_control_exp;
537 struct lu_client_seq *ms_client_seq;
540 static inline int lu_device_is_md(const struct lu_device *d)
542 return ergo(d != NULL, d->ld_type->ldt_tags & LU_DEVICE_MD);
545 static inline struct md_device *lu2md_dev(const struct lu_device *d)
547 LASSERT(IS_ERR(d) || lu_device_is_md(d));
548 return container_of0(d, struct md_device, md_lu_dev);
551 static inline struct lu_device *md2lu_dev(struct md_device *d)
553 return &d->md_lu_dev;
556 static inline struct md_object *lu2md(const struct lu_object *o)
558 LASSERT(o == NULL || IS_ERR(o) || lu_device_is_md(o->lo_dev));
559 return container_of0(o, struct md_object, mo_lu);
562 static inline struct md_object *md_object_next(const struct md_object *obj)
564 return (obj ? lu2md(lu_object_next(&obj->mo_lu)) : NULL);
567 static inline struct md_device *md_obj2dev(const struct md_object *o)
569 LASSERT(o == NULL || IS_ERR(o) || lu_device_is_md(o->mo_lu.lo_dev));
570 return container_of0(o->mo_lu.lo_dev, struct md_device, md_lu_dev);
573 static inline struct md_site *lu_site2md(const struct lu_site *s)
575 return container_of0(s, struct md_site, ms_lu);
578 static inline int md_device_init(struct md_device *md, struct lu_device_type *t)
580 return lu_device_init(&md->md_lu_dev, t);
583 static inline void md_device_fini(struct md_device *md)
585 lu_device_fini(&md->md_lu_dev);
588 static inline struct md_object *md_object_find_slice(const struct lu_env *env,
589 struct md_device *md,
590 const struct lu_fid *f)
592 return lu2md(lu_object_find_slice(env, md2lu_dev(md), f, NULL));
597 static inline int mo_permission(const struct lu_env *env,
603 LASSERT(c->mo_ops->moo_permission);
604 return c->mo_ops->moo_permission(env, p, c, at, mask);
607 static inline int mo_attr_get(const struct lu_env *env,
611 LASSERT(m->mo_ops->moo_attr_get);
612 return m->mo_ops->moo_attr_get(env, m, at);
615 static inline int mo_readlink(const struct lu_env *env,
619 LASSERT(m->mo_ops->moo_readlink);
620 return m->mo_ops->moo_readlink(env, m, buf);
623 static inline int mo_changelog(const struct lu_env *env,
624 enum changelog_rec_type type,
625 int flags, struct md_object *m)
627 LASSERT(m->mo_ops->moo_changelog);
628 return m->mo_ops->moo_changelog(env, type, flags, m);
631 static inline int mo_attr_set(const struct lu_env *env,
633 const struct md_attr *at)
635 LASSERT(m->mo_ops->moo_attr_set);
636 return m->mo_ops->moo_attr_set(env, m, at);
639 static inline int mo_xattr_get(const struct lu_env *env,
644 LASSERT(m->mo_ops->moo_xattr_get);
645 return m->mo_ops->moo_xattr_get(env, m, buf, name);
648 static inline int mo_xattr_del(const struct lu_env *env,
652 LASSERT(m->mo_ops->moo_xattr_del);
653 return m->mo_ops->moo_xattr_del(env, m, name);
656 static inline int mo_xattr_set(const struct lu_env *env,
658 const struct lu_buf *buf,
662 LASSERT(m->mo_ops->moo_xattr_set);
663 return m->mo_ops->moo_xattr_set(env, m, buf, name, flags);
666 static inline int mo_xattr_list(const struct lu_env *env,
670 LASSERT(m->mo_ops->moo_xattr_list);
671 return m->mo_ops->moo_xattr_list(env, m, buf);
674 static inline int mo_open(const struct lu_env *env,
678 LASSERT(m->mo_ops->moo_open);
679 return m->mo_ops->moo_open(env, m, flags);
682 static inline int mo_close(const struct lu_env *env,
686 LASSERT(m->mo_ops->moo_close);
687 return m->mo_ops->moo_close(env, m, ma);
690 static inline int mo_readpage(const struct lu_env *env,
692 const struct lu_rdpg *rdpg)
694 LASSERT(m->mo_ops->moo_readpage);
695 return m->mo_ops->moo_readpage(env, m, rdpg);
698 static inline int mo_object_create(const struct lu_env *env,
700 const struct md_op_spec *spc,
703 LASSERT(m->mo_ops->moo_object_create);
704 return m->mo_ops->moo_object_create(env, m, spc, at);
707 static inline int mo_ref_add(const struct lu_env *env,
709 const struct md_attr *ma)
711 LASSERT(m->mo_ops->moo_ref_add);
712 return m->mo_ops->moo_ref_add(env, m, ma);
715 static inline int mo_ref_del(const struct lu_env *env,
719 LASSERT(m->mo_ops->moo_ref_del);
720 return m->mo_ops->moo_ref_del(env, m, ma);
723 static inline int mo_capa_get(const struct lu_env *env,
725 struct lustre_capa *c,
728 LASSERT(m->mo_ops->moo_capa_get);
729 return m->mo_ops->moo_capa_get(env, m, c, renewal);
732 static inline int mo_path(const struct lu_env *env, struct md_object *m,
733 char *path, int pathlen, __u64 *recno, int *linkno)
735 if (m->mo_ops->moo_path == NULL)
737 return m->mo_ops->moo_path(env, m, path, pathlen, recno, linkno);
740 static inline int mo_object_sync(const struct lu_env *env, struct md_object *m)
742 LASSERT(m->mo_ops->moo_object_sync);
743 return m->mo_ops->moo_object_sync(env, m);
746 static inline dt_obj_version_t mo_version_get(const struct lu_env *env,
749 LASSERT(m->mo_ops->moo_version_get);
750 return m->mo_ops->moo_version_get(env, m);
753 static inline void mo_version_set(const struct lu_env *env,
754 struct md_object *m, dt_obj_version_t ver)
756 LASSERT(m->mo_ops->moo_version_set);
757 return m->mo_ops->moo_version_set(env, m, ver);
760 static inline int mdo_lookup(const struct lu_env *env,
762 const struct lu_name *lname,
764 struct md_op_spec *spec)
766 LASSERT(p->mo_dir_ops->mdo_lookup);
767 return p->mo_dir_ops->mdo_lookup(env, p, lname, f, spec);
770 static inline mdl_mode_t mdo_lock_mode(const struct lu_env *env,
771 struct md_object *mo,
774 if (mo->mo_dir_ops->mdo_lock_mode == NULL)
776 return mo->mo_dir_ops->mdo_lock_mode(env, mo, lm);
779 static inline int mdo_create(const struct lu_env *env,
781 const struct lu_name *lchild_name,
783 struct md_op_spec *spc,
786 LASSERT(c->mo_dir_ops->mdo_create);
787 return c->mo_dir_ops->mdo_create(env, p, lchild_name, c, spc, at);
790 static inline int mdo_create_data(const struct lu_env *env,
793 const struct md_op_spec *spec,
796 LASSERT(c->mo_dir_ops->mdo_create_data);
797 return c->mo_dir_ops->mdo_create_data(env, p, c, spec, ma);
800 static inline int mdo_rename(const struct lu_env *env,
801 struct md_object *sp,
802 struct md_object *tp,
803 const struct lu_fid *lf,
804 const struct lu_name *lsname,
806 const struct lu_name *ltname,
809 LASSERT(tp->mo_dir_ops->mdo_rename);
810 return tp->mo_dir_ops->mdo_rename(env, sp, tp, lf, lsname, t, ltname,
814 static inline int mdo_is_subdir(const struct lu_env *env,
815 struct md_object *mo,
816 const struct lu_fid *fid,
819 LASSERT(mo->mo_dir_ops->mdo_is_subdir);
820 return mo->mo_dir_ops->mdo_is_subdir(env, mo, fid, sfid);
823 static inline int mdo_link(const struct lu_env *env,
826 const struct lu_name *lname,
829 LASSERT(s->mo_dir_ops->mdo_link);
830 return s->mo_dir_ops->mdo_link(env, p, s, lname, ma);
833 static inline int mdo_unlink(const struct lu_env *env,
836 const struct lu_name *lname,
839 LASSERT(c->mo_dir_ops->mdo_unlink);
840 return c->mo_dir_ops->mdo_unlink(env, p, c, lname, ma);
843 static inline int mdo_name_insert(const struct lu_env *env,
845 const struct lu_name *lname,
846 const struct lu_fid *f,
847 const struct md_attr *ma)
849 LASSERT(p->mo_dir_ops->mdo_name_insert);
850 return p->mo_dir_ops->mdo_name_insert(env, p, lname, f, ma);
853 static inline int mdo_name_remove(const struct lu_env *env,
855 const struct lu_name *lname,
856 const struct md_attr *ma)
858 LASSERT(p->mo_dir_ops->mdo_name_remove);
859 return p->mo_dir_ops->mdo_name_remove(env, p, lname, ma);
862 static inline int mdo_rename_tgt(const struct lu_env *env,
865 const struct lu_fid *lf,
866 const struct lu_name *lname,
870 LASSERT(t->mo_dir_ops->mdo_rename_tgt);
871 return t->mo_dir_ops->mdo_rename_tgt(env, p, t, lf, lname, ma);
873 LASSERT(p->mo_dir_ops->mdo_rename_tgt);
874 return p->mo_dir_ops->mdo_rename_tgt(env, p, t, lf, lname, ma);
880 * Structure to hold object information. This is used to create object
881 * \pre llod_dir exist
883 struct lu_local_obj_desc {
884 const char *llod_dir;
885 const char *llod_name;
888 const struct dt_index_features *llod_feat;
889 cfs_list_t llod_linkage;
892 struct md_object *llo_store_resolve(const struct lu_env *env,
893 struct md_device *md,
894 struct dt_device *dt,
898 struct md_object *llo_store_open(const struct lu_env *env,
899 struct md_device *md,
900 struct dt_device *dt,
905 struct md_object *llo_store_create_index(const struct lu_env *env,
906 struct md_device *md,
907 struct dt_device *dt,
910 const struct lu_fid *fid,
911 const struct dt_index_features *feat);
913 struct md_object *llo_store_create(const struct lu_env *env,
914 struct md_device *md,
915 struct dt_device *dt,
918 const struct lu_fid *fid);
920 void llo_local_obj_register(struct lu_local_obj_desc *);
921 void llo_local_obj_unregister(struct lu_local_obj_desc *);
923 int llo_local_objects_setup(const struct lu_env *env,
924 struct md_device * md,
925 struct dt_device * dt);
928 #endif /* _LINUX_MD_OBJECT_H */