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 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.
57 * super-class definitions.
59 #include <lu_object.h>
63 struct md_device_operations;
87 struct group_info *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 * Implemented in mdd/mdd_handler.c.
107 * XXX should be moved into separate .h/.c together with all md security
108 * related definitions.
110 struct md_ucred *md_ucred(const struct lu_env *env);
111 struct md_capainfo *md_capainfo(const struct lu_env *env);
113 /** metadata attributes */
117 MA_COOKIE = (1 << 2),
120 MA_ACL_DEF = (1 << 5),
121 MA_LOV_DEF = (1 << 6)
138 MDT_REG_LOCK = (1 << 0),
139 MDT_PDO_LOCK = (1 << 1)
146 struct lu_attr ma_attr;
147 struct lov_mds_md *ma_lmm;
149 struct lmv_stripe_md *ma_lmv;
153 struct llog_cookie *ma_cookie;
155 struct lustre_capa *ma_capa;
158 /** Additional parameters for create */
161 /** symlink target */
162 const char *sp_symname;
163 /** parent FID for cross-ref mkdir */
164 const struct lu_fid *sp_pfid;
165 /** eadata for regular files */
167 /** lov objs exist already */
168 const struct lu_fid *fid;
173 /** don't create lov objects or llog cookie - this replay */
176 /** Create flag from client: such as MDS_OPEN_CREAT, and others. */
179 /** Should mdd do lookup sanity check or not. */
182 /** Current lock mode for parent dir where create is performing. */
183 mdl_mode_t sp_cr_mode;
185 /** Check for split */
188 /** to create directory */
189 const struct dt_index_features *sp_feat;
193 * Operations implemented for each md object (both directory and leaf).
195 struct md_object_operations {
196 int (*moo_permission)(const struct lu_env *env,
197 struct md_object *pobj, struct md_object *cobj,
198 struct md_attr *attr, int mask);
200 int (*moo_attr_get)(const struct lu_env *env, struct md_object *obj,
201 struct md_attr *attr);
203 int (*moo_attr_set)(const struct lu_env *env, struct md_object *obj,
204 const struct md_attr *attr);
206 int (*moo_xattr_get)(const struct lu_env *env, struct md_object *obj,
207 struct lu_buf *buf, const char *name);
209 int (*moo_xattr_list)(const struct lu_env *env, struct md_object *obj,
212 int (*moo_xattr_set)(const struct lu_env *env, struct md_object *obj,
213 const struct lu_buf *buf, const char *name,
216 int (*moo_xattr_del)(const struct lu_env *env, struct md_object *obj,
219 int (*moo_readpage)(const struct lu_env *env, struct md_object *obj,
220 const struct lu_rdpg *rdpg);
222 int (*moo_readlink)(const struct lu_env *env, 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,
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_path)(const struct lu_env *env, struct md_object *obj,
251 char *path, int pathlen, __u64 *recno, int *linkno);
255 * Operations implemented for each directory object.
257 struct md_dir_operations {
258 int (*mdo_is_subdir) (const struct lu_env *env, struct md_object *obj,
259 const struct lu_fid *fid, struct lu_fid *sfid);
261 int (*mdo_lookup)(const struct lu_env *env, struct md_object *obj,
262 const struct lu_name *lname, struct lu_fid *fid,
263 struct md_op_spec *spec);
265 mdl_mode_t (*mdo_lock_mode)(const struct lu_env *env,
266 struct md_object *obj,
269 int (*mdo_create)(const struct lu_env *env, struct md_object *pobj,
270 const struct lu_name *lname, struct md_object *child,
271 struct md_op_spec *spec,
274 /** This method is used for creating data object for this meta object*/
275 int (*mdo_create_data)(const struct lu_env *env, struct md_object *p,
277 const struct md_op_spec *spec,
280 int (*mdo_rename)(const struct lu_env *env, struct md_object *spobj,
281 struct md_object *tpobj, const struct lu_fid *lf,
282 const struct lu_name *lsname, struct md_object *tobj,
283 const struct lu_name *ltname, struct md_attr *ma);
285 int (*mdo_link)(const struct lu_env *env, struct md_object *tgt_obj,
286 struct md_object *src_obj, const struct lu_name *lname,
289 int (*mdo_unlink)(const struct lu_env *env, struct md_object *pobj,
290 struct md_object *cobj, const struct lu_name *lname,
293 /** partial ops for cross-ref case */
294 int (*mdo_name_insert)(const struct lu_env *env,
295 struct md_object *obj,
296 const struct lu_name *lname,
297 const struct lu_fid *fid,
298 const struct md_attr *ma);
300 int (*mdo_name_remove)(const struct lu_env *env,
301 struct md_object *obj,
302 const struct lu_name *lname,
303 const struct md_attr *ma);
305 int (*mdo_rename_tgt)(const struct lu_env *env, struct md_object *pobj,
306 struct md_object *tobj, const struct lu_fid *fid,
307 const struct lu_name *lname, struct md_attr *ma);
310 struct md_device_operations {
311 /** meta-data device related handlers. */
312 int (*mdo_root_get)(const struct lu_env *env, struct md_device *m,
315 int (*mdo_maxsize_get)(const struct lu_env *env, struct md_device *m,
316 int *md_size, int *cookie_size);
318 int (*mdo_statfs)(const struct lu_env *env, struct md_device *m,
319 struct kstatfs *sfs);
321 int (*mdo_init_capa_ctxt)(const struct lu_env *env, struct md_device *m,
322 int mode, unsigned long timeout, __u32 alg,
323 struct lustre_capa_key *keys);
325 int (*mdo_update_capa_key)(const struct lu_env *env,
327 struct lustre_capa_key *key);
329 int (*mdo_llog_ctxt_get)(const struct lu_env *env,
330 struct md_device *m, int idx, void **h);
332 int (*mdo_iocontrol)(const struct lu_env *env, struct md_device *m,
333 unsigned int cmd, int len, void *data);
335 #ifdef HAVE_QUOTA_SUPPORT
336 struct md_quota_operations {
337 int (*mqo_notify)(const struct lu_env *env,
338 struct md_device *m);
340 int (*mqo_setup)(const struct lu_env *env,
344 int (*mqo_cleanup)(const struct lu_env *env,
345 struct md_device *m);
347 int (*mqo_recovery)(const struct lu_env *env,
348 struct md_device *m);
350 int (*mqo_check)(const struct lu_env *env,
352 struct obd_export *exp,
355 int (*mqo_on)(const struct lu_env *env,
359 int (*mqo_off)(const struct lu_env *env,
363 int (*mqo_setinfo)(const struct lu_env *env,
367 struct obd_dqinfo *dqinfo);
369 int (*mqo_getinfo)(const struct lu_env *env,
370 const struct md_device *m,
373 struct obd_dqinfo *dqinfo);
375 int (*mqo_setquota)(const struct lu_env *env,
379 struct obd_dqblk *dqblk);
381 int (*mqo_getquota)(const struct lu_env *env,
382 const struct md_device *m,
385 struct obd_dqblk *dqblk);
387 int (*mqo_getoinfo)(const struct lu_env *env,
388 const struct md_device *m,
391 struct obd_dqinfo *dqinfo);
393 int (*mqo_getoquota)(const struct lu_env *env,
394 const struct md_device *m,
397 struct obd_dqblk *dqblk);
399 int (*mqo_invalidate)(const struct lu_env *env,
403 int (*mqo_finvalidate)(const struct lu_env *env,
410 enum md_upcall_event {
411 /**sync the md layer*/
412 MD_LOV_SYNC = (1 << 0),
413 /** Just for split, no need trans, for replay */
414 MD_NO_TRANS = (1 << 1),
415 MD_LOV_CONFIG = (1 << 2)
419 /** this lock protects upcall using against its removal
420 * read lock is for usage the upcall, write - for init/fini */
421 struct rw_semaphore mu_upcall_sem;
422 /** device to call, upper layer normally */
423 struct md_device *mu_upcall_dev;
424 /** upcall function */
425 int (*mu_upcall)(const struct lu_env *env, struct md_device *md,
426 enum md_upcall_event ev);
430 struct lu_device md_lu_dev;
431 const struct md_device_operations *md_ops;
432 struct md_upcall md_upcall;
435 static inline void md_upcall_init(struct md_device *m, void *upcl)
437 init_rwsem(&m->md_upcall.mu_upcall_sem);
438 m->md_upcall.mu_upcall_dev = NULL;
439 m->md_upcall.mu_upcall = upcl;
442 static inline void md_upcall_dev_set(struct md_device *m, struct md_device *up)
444 down_write(&m->md_upcall.mu_upcall_sem);
445 m->md_upcall.mu_upcall_dev = up;
446 up_write(&m->md_upcall.mu_upcall_sem);
449 static inline void md_upcall_fini(struct md_device *m)
451 down_write(&m->md_upcall.mu_upcall_sem);
452 m->md_upcall.mu_upcall_dev = NULL;
453 m->md_upcall.mu_upcall = NULL;
454 up_write(&m->md_upcall.mu_upcall_sem);
457 static inline int md_do_upcall(const struct lu_env *env, struct md_device *m,
458 enum md_upcall_event ev)
461 down_read(&m->md_upcall.mu_upcall_sem);
462 if (m->md_upcall.mu_upcall_dev != NULL &&
463 m->md_upcall.mu_upcall_dev->md_upcall.mu_upcall != NULL) {
464 rc = m->md_upcall.mu_upcall_dev->md_upcall.mu_upcall(env,
465 m->md_upcall.mu_upcall_dev, ev);
467 up_read(&m->md_upcall.mu_upcall_sem);
472 struct lu_object mo_lu;
473 const struct md_object_operations *mo_ops;
474 const struct md_dir_operations *mo_dir_ops;
481 struct lu_site ms_lu;
483 * mds number of this site.
487 * Fid location database
489 struct lu_server_fld *ms_server_fld;
490 struct lu_client_fld *ms_client_fld;
495 struct lu_server_seq *ms_server_seq;
498 * Controller Seq Manager
500 struct lu_server_seq *ms_control_seq;
501 struct obd_export *ms_control_exp;
506 struct lu_client_seq *ms_client_seq;
509 static inline int lu_device_is_md(const struct lu_device *d)
511 return ergo(d != NULL, d->ld_type->ldt_tags & LU_DEVICE_MD);
514 static inline struct md_device *lu2md_dev(const struct lu_device *d)
516 LASSERT(IS_ERR(d) || lu_device_is_md(d));
517 return container_of0(d, struct md_device, md_lu_dev);
520 static inline struct lu_device *md2lu_dev(struct md_device *d)
522 return &d->md_lu_dev;
525 static inline struct md_object *lu2md(const struct lu_object *o)
527 LASSERT(o == NULL || IS_ERR(o) || lu_device_is_md(o->lo_dev));
528 return container_of0(o, struct md_object, mo_lu);
531 static inline struct md_object *md_object_next(const struct md_object *obj)
533 return (obj ? lu2md(lu_object_next(&obj->mo_lu)) : NULL);
536 static inline struct md_device *md_obj2dev(const struct md_object *o)
538 LASSERT(o == NULL || IS_ERR(o) || lu_device_is_md(o->mo_lu.lo_dev));
539 return container_of0(o->mo_lu.lo_dev, struct md_device, md_lu_dev);
542 static inline struct md_site *lu_site2md(const struct lu_site *s)
544 return container_of0(s, struct md_site, ms_lu);
547 static inline int md_device_init(struct md_device *md, struct lu_device_type *t)
549 return lu_device_init(&md->md_lu_dev, t);
552 static inline void md_device_fini(struct md_device *md)
554 lu_device_fini(&md->md_lu_dev);
557 static inline struct md_object *md_object_find_slice(const struct lu_env *env,
558 struct md_device *md,
559 const struct lu_fid *f)
561 return lu2md(lu_object_find_slice(env, md2lu_dev(md), f, NULL));
566 static inline int mo_permission(const struct lu_env *env,
572 LASSERT(c->mo_ops->moo_permission);
573 return c->mo_ops->moo_permission(env, p, c, at, mask);
576 static inline int mo_attr_get(const struct lu_env *env,
580 LASSERT(m->mo_ops->moo_attr_get);
581 return m->mo_ops->moo_attr_get(env, m, at);
584 static inline int mo_readlink(const struct lu_env *env,
588 LASSERT(m->mo_ops->moo_readlink);
589 return m->mo_ops->moo_readlink(env, m, buf);
592 static inline int mo_attr_set(const struct lu_env *env,
594 const struct md_attr *at)
596 LASSERT(m->mo_ops->moo_attr_set);
597 return m->mo_ops->moo_attr_set(env, m, at);
600 static inline int mo_xattr_get(const struct lu_env *env,
605 LASSERT(m->mo_ops->moo_xattr_get);
606 return m->mo_ops->moo_xattr_get(env, m, buf, name);
609 static inline int mo_xattr_del(const struct lu_env *env,
613 LASSERT(m->mo_ops->moo_xattr_del);
614 return m->mo_ops->moo_xattr_del(env, m, name);
617 static inline int mo_xattr_set(const struct lu_env *env,
619 const struct lu_buf *buf,
623 LASSERT(m->mo_ops->moo_xattr_set);
624 return m->mo_ops->moo_xattr_set(env, m, buf, name, flags);
627 static inline int mo_xattr_list(const struct lu_env *env,
631 LASSERT(m->mo_ops->moo_xattr_list);
632 return m->mo_ops->moo_xattr_list(env, m, buf);
635 static inline int mo_open(const struct lu_env *env,
639 LASSERT(m->mo_ops->moo_open);
640 return m->mo_ops->moo_open(env, m, flags);
643 static inline int mo_close(const struct lu_env *env,
647 LASSERT(m->mo_ops->moo_close);
648 return m->mo_ops->moo_close(env, m, ma);
651 static inline int mo_readpage(const struct lu_env *env,
653 const struct lu_rdpg *rdpg)
655 LASSERT(m->mo_ops->moo_readpage);
656 return m->mo_ops->moo_readpage(env, m, rdpg);
659 static inline int mo_object_create(const struct lu_env *env,
661 const struct md_op_spec *spc,
664 LASSERT(m->mo_ops->moo_object_create);
665 return m->mo_ops->moo_object_create(env, m, spc, at);
668 static inline int mo_ref_add(const struct lu_env *env,
670 const struct md_attr *ma)
672 LASSERT(m->mo_ops->moo_ref_add);
673 return m->mo_ops->moo_ref_add(env, m, ma);
676 static inline int mo_ref_del(const struct lu_env *env,
680 LASSERT(m->mo_ops->moo_ref_del);
681 return m->mo_ops->moo_ref_del(env, m, ma);
684 static inline int mo_capa_get(const struct lu_env *env,
686 struct lustre_capa *c,
689 LASSERT(m->mo_ops->moo_capa_get);
690 return m->mo_ops->moo_capa_get(env, m, c, renewal);
693 static inline int mo_path(const struct lu_env *env, struct md_object *m,
694 char *path, int pathlen, __u64 *recno, int *linkno)
696 if (m->mo_ops->moo_path == NULL)
698 return m->mo_ops->moo_path(env, m, path, pathlen, recno, linkno);
701 static inline int mo_object_sync(const struct lu_env *env, struct md_object *m)
703 LASSERT(m->mo_ops->moo_object_sync);
704 return m->mo_ops->moo_object_sync(env, m);
707 static inline int mdo_lookup(const struct lu_env *env,
709 const struct lu_name *lname,
711 struct md_op_spec *spec)
713 LASSERT(p->mo_dir_ops->mdo_lookup);
714 return p->mo_dir_ops->mdo_lookup(env, p, lname, f, spec);
717 static inline mdl_mode_t mdo_lock_mode(const struct lu_env *env,
718 struct md_object *mo,
721 if (mo->mo_dir_ops->mdo_lock_mode == NULL)
723 return mo->mo_dir_ops->mdo_lock_mode(env, mo, lm);
726 static inline int mdo_create(const struct lu_env *env,
728 const struct lu_name *lchild_name,
730 struct md_op_spec *spc,
733 LASSERT(c->mo_dir_ops->mdo_create);
734 return c->mo_dir_ops->mdo_create(env, p, lchild_name, c, spc, at);
737 static inline int mdo_create_data(const struct lu_env *env,
740 const struct md_op_spec *spec,
743 LASSERT(c->mo_dir_ops->mdo_create_data);
744 return c->mo_dir_ops->mdo_create_data(env, p, c, spec, ma);
747 static inline int mdo_rename(const struct lu_env *env,
748 struct md_object *sp,
749 struct md_object *tp,
750 const struct lu_fid *lf,
751 const struct lu_name *lsname,
753 const struct lu_name *ltname,
756 LASSERT(tp->mo_dir_ops->mdo_rename);
757 return tp->mo_dir_ops->mdo_rename(env, sp, tp, lf, lsname, t, ltname,
761 static inline int mdo_is_subdir(const struct lu_env *env,
762 struct md_object *mo,
763 const struct lu_fid *fid,
766 LASSERT(mo->mo_dir_ops->mdo_is_subdir);
767 return mo->mo_dir_ops->mdo_is_subdir(env, mo, fid, sfid);
770 static inline int mdo_link(const struct lu_env *env,
773 const struct lu_name *lname,
776 LASSERT(s->mo_dir_ops->mdo_link);
777 return s->mo_dir_ops->mdo_link(env, p, s, lname, ma);
780 static inline int mdo_unlink(const struct lu_env *env,
783 const struct lu_name *lname,
786 LASSERT(c->mo_dir_ops->mdo_unlink);
787 return c->mo_dir_ops->mdo_unlink(env, p, c, lname, ma);
790 static inline int mdo_name_insert(const struct lu_env *env,
792 const struct lu_name *lname,
793 const struct lu_fid *f,
794 const struct md_attr *ma)
796 LASSERT(p->mo_dir_ops->mdo_name_insert);
797 return p->mo_dir_ops->mdo_name_insert(env, p, lname, f, ma);
800 static inline int mdo_name_remove(const struct lu_env *env,
802 const struct lu_name *lname,
803 const struct md_attr *ma)
805 LASSERT(p->mo_dir_ops->mdo_name_remove);
806 return p->mo_dir_ops->mdo_name_remove(env, p, lname, ma);
809 static inline int mdo_rename_tgt(const struct lu_env *env,
812 const struct lu_fid *lf,
813 const struct lu_name *lname,
817 LASSERT(t->mo_dir_ops->mdo_rename_tgt);
818 return t->mo_dir_ops->mdo_rename_tgt(env, p, t, lf, lname, ma);
820 LASSERT(p->mo_dir_ops->mdo_rename_tgt);
821 return p->mo_dir_ops->mdo_rename_tgt(env, p, t, lf, lname, ma);
827 * Structure to hold object information. This is used to create object
828 * \pre llod_dir exist
830 struct lu_local_obj_desc {
831 const char *llod_dir;
832 const char *llod_name;
835 const struct dt_index_features * llod_feat;
836 struct list_head llod_linkage;
839 struct md_object *llo_store_resolve(const struct lu_env *env,
840 struct md_device *md,
841 struct dt_device *dt,
845 struct md_object *llo_store_open(const struct lu_env *env,
846 struct md_device *md,
847 struct dt_device *dt,
852 struct md_object *llo_store_create_index(const struct lu_env *env,
853 struct md_device *md,
854 struct dt_device *dt,
857 const struct lu_fid *fid,
858 const struct dt_index_features *feat);
860 struct md_object *llo_store_create(const struct lu_env *env,
861 struct md_device *md,
862 struct dt_device *dt,
865 const struct lu_fid *fid);
867 void llo_local_obj_register(struct lu_local_obj_desc *);
868 void llo_local_obj_unregister(struct lu_local_obj_desc *);
870 int llo_local_objects_setup(const struct lu_env *env,
871 struct md_device * md,
872 struct dt_device * dt);
875 #endif /* _LINUX_MD_OBJECT_H */