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;
91 #define MD_CAPAINFO_MAX 5
93 /** there are at most 5 fids in one operation, see rename, NOTE the last one
94 * is a temporary one used for is_subdir() */
96 const struct lu_fid *mc_fid[MD_CAPAINFO_MAX];
97 struct lustre_capa *mc_capa[MD_CAPAINFO_MAX];
101 * Implemented in mdd/mdd_handler.c.
103 * XXX should be moved into separate .h/.c together with all md security
104 * related definitions.
106 struct md_ucred *md_ucred(const struct lu_env *env);
107 struct md_capainfo *md_capainfo(const struct lu_env *env);
109 /** metadata attributes */
113 MA_COOKIE = (1 << 2),
116 MA_ACL_DEF = (1 << 5),
117 MA_LOV_DEF = (1 << 6)
134 MDT_REG_LOCK = (1 << 0),
135 MDT_PDO_LOCK = (1 << 1)
142 struct lu_attr ma_attr;
143 struct lov_mds_md *ma_lmm;
145 struct lmv_stripe_md *ma_lmv;
149 struct llog_cookie *ma_cookie;
151 struct lustre_capa *ma_capa;
154 /** Additional parameters for create */
157 /** symlink target */
158 const char *sp_symname;
159 /** parent FID for cross-ref mkdir */
160 const struct lu_fid *sp_pfid;
161 /** eadata for regular files */
163 /** lov objs exist already */
164 const struct lu_fid *fid;
171 /** Create flag from client: such as MDS_OPEN_CREAT, and others. */
174 /** Should mdd do lookup sanity check or not. */
177 /** Current lock mode for parent dir where create is performing. */
178 mdl_mode_t sp_cr_mode;
180 /** Check for split */
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 int (*moo_readpage)(const struct lu_env *env, struct md_object *obj,
212 const struct lu_rdpg *rdpg);
214 int (*moo_readlink)(const struct lu_env *env, struct md_object *obj,
217 /** part of cross-ref operation */
218 int (*moo_object_create)(const struct lu_env *env,
219 struct md_object *obj,
220 const struct md_op_spec *spec,
223 int (*moo_ref_add)(const struct lu_env *env,
224 struct md_object *obj,
225 const struct md_attr *ma);
227 int (*moo_ref_del)(const struct lu_env *env,
228 struct md_object *obj,
231 int (*moo_open)(const struct lu_env *env,
232 struct md_object *obj, int flag);
234 int (*moo_close)(const struct lu_env *env, struct md_object *obj,
237 int (*moo_capa_get)(const struct lu_env *, struct md_object *,
238 struct lustre_capa *, int renewal);
239 int (*moo_object_sync)(const struct lu_env *, struct md_object *);
243 * Operations implemented for each directory object.
245 struct md_dir_operations {
246 int (*mdo_is_subdir) (const struct lu_env *env, struct md_object *obj,
247 const struct lu_fid *fid, struct lu_fid *sfid);
249 int (*mdo_lookup)(const struct lu_env *env, struct md_object *obj,
250 const struct lu_name *lname, struct lu_fid *fid,
251 struct md_op_spec *spec);
253 mdl_mode_t (*mdo_lock_mode)(const struct lu_env *env,
254 struct md_object *obj,
257 int (*mdo_create)(const struct lu_env *env, struct md_object *pobj,
258 const struct lu_name *lname, struct md_object *child,
259 struct md_op_spec *spec,
262 /** This method is used for creating data object for this meta object*/
263 int (*mdo_create_data)(const struct lu_env *env, struct md_object *p,
265 const struct md_op_spec *spec,
268 int (*mdo_rename)(const struct lu_env *env, struct md_object *spobj,
269 struct md_object *tpobj, const struct lu_fid *lf,
270 const struct lu_name *lsname, struct md_object *tobj,
271 const struct lu_name *ltname, struct md_attr *ma);
273 int (*mdo_link)(const struct lu_env *env, struct md_object *tgt_obj,
274 struct md_object *src_obj, const struct lu_name *lname,
277 int (*mdo_unlink)(const struct lu_env *env, struct md_object *pobj,
278 struct md_object *cobj, const struct lu_name *lname,
281 /** partial ops for cross-ref case */
282 int (*mdo_name_insert)(const struct lu_env *env,
283 struct md_object *obj,
284 const struct lu_name *lname,
285 const struct lu_fid *fid,
286 const struct md_attr *ma);
288 int (*mdo_name_remove)(const struct lu_env *env,
289 struct md_object *obj,
290 const struct lu_name *lname,
291 const struct md_attr *ma);
293 int (*mdo_rename_tgt)(const struct lu_env *env, struct md_object *pobj,
294 struct md_object *tobj, const struct lu_fid *fid,
295 const struct lu_name *lname, struct md_attr *ma);
298 struct md_device_operations {
299 /** meta-data device related handlers. */
300 int (*mdo_root_get)(const struct lu_env *env, struct md_device *m,
303 int (*mdo_maxsize_get)(const struct lu_env *env, struct md_device *m,
304 int *md_size, int *cookie_size);
306 int (*mdo_statfs)(const struct lu_env *env, struct md_device *m,
307 struct kstatfs *sfs);
309 int (*mdo_init_capa_ctxt)(const struct lu_env *env, struct md_device *m,
310 int mode, unsigned long timeout, __u32 alg,
311 struct lustre_capa_key *keys);
313 int (*mdo_update_capa_key)(const struct lu_env *env,
315 struct lustre_capa_key *key);
318 enum md_upcall_event {
319 /**sync the md layer*/
320 MD_LOV_SYNC = (1 << 0),
321 /** Just for split, no need trans, for replay */
322 MD_NO_TRANS = (1 << 1),
323 MD_LOV_CONFIG = (1 << 2)
327 /** this lock protects upcall using against its removal
328 * read lock is for usage the upcall, write - for init/fini */
329 struct rw_semaphore mu_upcall_sem;
330 /** device to call, upper layer normally */
331 struct md_device *mu_upcall_dev;
332 /** upcall function */
333 int (*mu_upcall)(const struct lu_env *env, struct md_device *md,
334 enum md_upcall_event ev);
338 struct lu_device md_lu_dev;
339 struct md_device_operations *md_ops;
340 struct md_upcall md_upcall;
343 static inline void md_upcall_init(struct md_device *m, void *upcl)
345 init_rwsem(&m->md_upcall.mu_upcall_sem);
346 m->md_upcall.mu_upcall_dev = NULL;
347 m->md_upcall.mu_upcall = upcl;
350 static inline void md_upcall_dev_set(struct md_device *m, struct md_device *up)
352 down_write(&m->md_upcall.mu_upcall_sem);
353 m->md_upcall.mu_upcall_dev = up;
354 up_write(&m->md_upcall.mu_upcall_sem);
357 static inline void md_upcall_fini(struct md_device *m)
359 down_write(&m->md_upcall.mu_upcall_sem);
360 m->md_upcall.mu_upcall_dev = NULL;
361 m->md_upcall.mu_upcall = NULL;
362 up_write(&m->md_upcall.mu_upcall_sem);
365 static inline int md_do_upcall(const struct lu_env *env, struct md_device *m,
366 enum md_upcall_event ev)
369 down_read(&m->md_upcall.mu_upcall_sem);
370 if (m->md_upcall.mu_upcall_dev != NULL &&
371 m->md_upcall.mu_upcall_dev->md_upcall.mu_upcall != NULL) {
372 rc = m->md_upcall.mu_upcall_dev->md_upcall.mu_upcall(env,
373 m->md_upcall.mu_upcall_dev, ev);
375 up_read(&m->md_upcall.mu_upcall_sem);
380 struct lu_object mo_lu;
381 struct md_object_operations *mo_ops;
382 struct md_dir_operations *mo_dir_ops;
385 static inline int lu_device_is_md(const struct lu_device *d)
387 return ergo(d != NULL, d->ld_type->ldt_tags & LU_DEVICE_MD);
390 static inline struct md_device *lu2md_dev(const struct lu_device *d)
392 LASSERT(lu_device_is_md(d));
393 return container_of0(d, struct md_device, md_lu_dev);
396 static inline struct lu_device *md2lu_dev(struct md_device *d)
398 return &d->md_lu_dev;
401 static inline struct md_object *lu2md(const struct lu_object *o)
403 LASSERT(lu_device_is_md(o->lo_dev));
404 return container_of0(o, struct md_object, mo_lu);
407 static inline struct md_object *md_object_next(const struct md_object *obj)
409 return (obj ? lu2md(lu_object_next(&obj->mo_lu)) : NULL);
412 static inline struct md_device *md_obj2dev(const struct md_object *o)
414 LASSERT(lu_device_is_md(o->mo_lu.lo_dev));
415 return container_of0(o->mo_lu.lo_dev, struct md_device, md_lu_dev);
418 static inline int md_device_init(struct md_device *md, struct lu_device_type *t)
420 return lu_device_init(&md->md_lu_dev, t);
423 static inline void md_device_fini(struct md_device *md)
425 lu_device_fini(&md->md_lu_dev);
429 static inline int mo_permission(const struct lu_env *env,
435 LASSERT(c->mo_ops->moo_permission);
436 return c->mo_ops->moo_permission(env, p, c, at, mask);
439 static inline int mo_attr_get(const struct lu_env *env,
443 LASSERT(m->mo_ops->moo_attr_get);
444 return m->mo_ops->moo_attr_get(env, m, at);
447 static inline int mo_readlink(const struct lu_env *env,
451 LASSERT(m->mo_ops->moo_readlink);
452 return m->mo_ops->moo_readlink(env, m, buf);
455 static inline int mo_attr_set(const struct lu_env *env,
457 const struct md_attr *at)
459 LASSERT(m->mo_ops->moo_attr_set);
460 return m->mo_ops->moo_attr_set(env, m, at);
463 static inline int mo_xattr_get(const struct lu_env *env,
468 LASSERT(m->mo_ops->moo_xattr_get);
469 return m->mo_ops->moo_xattr_get(env, m, buf, name);
472 static inline int mo_xattr_del(const struct lu_env *env,
476 LASSERT(m->mo_ops->moo_xattr_del);
477 return m->mo_ops->moo_xattr_del(env, m, name);
480 static inline int mo_xattr_set(const struct lu_env *env,
482 const struct lu_buf *buf,
486 LASSERT(m->mo_ops->moo_xattr_set);
487 return m->mo_ops->moo_xattr_set(env, m, buf, name, flags);
490 static inline int mo_xattr_list(const struct lu_env *env,
494 LASSERT(m->mo_ops->moo_xattr_list);
495 return m->mo_ops->moo_xattr_list(env, m, buf);
498 static inline int mo_open(const struct lu_env *env,
502 LASSERT(m->mo_ops->moo_open);
503 return m->mo_ops->moo_open(env, m, flags);
506 static inline int mo_close(const struct lu_env *env,
510 LASSERT(m->mo_ops->moo_close);
511 return m->mo_ops->moo_close(env, m, ma);
514 static inline int mo_readpage(const struct lu_env *env,
516 const struct lu_rdpg *rdpg)
518 LASSERT(m->mo_ops->moo_readpage);
519 return m->mo_ops->moo_readpage(env, m, rdpg);
522 static inline int mo_object_create(const struct lu_env *env,
524 const struct md_op_spec *spc,
527 LASSERT(m->mo_ops->moo_object_create);
528 return m->mo_ops->moo_object_create(env, m, spc, at);
531 static inline int mo_ref_add(const struct lu_env *env,
533 const struct md_attr *ma)
535 LASSERT(m->mo_ops->moo_ref_add);
536 return m->mo_ops->moo_ref_add(env, m, ma);
539 static inline int mo_ref_del(const struct lu_env *env,
543 LASSERT(m->mo_ops->moo_ref_del);
544 return m->mo_ops->moo_ref_del(env, m, ma);
547 static inline int mo_capa_get(const struct lu_env *env,
549 struct lustre_capa *c,
552 LASSERT(m->mo_ops->moo_capa_get);
553 return m->mo_ops->moo_capa_get(env, m, c, renewal);
556 static inline int mo_object_sync(const struct lu_env *env, struct md_object *m)
558 LASSERT(m->mo_ops->moo_object_sync);
559 return m->mo_ops->moo_object_sync(env, m);
562 static inline int mdo_lookup(const struct lu_env *env,
564 const struct lu_name *lname,
566 struct md_op_spec *spec)
568 LASSERT(p->mo_dir_ops->mdo_lookup);
569 return p->mo_dir_ops->mdo_lookup(env, p, lname, f, spec);
572 static inline mdl_mode_t mdo_lock_mode(const struct lu_env *env,
573 struct md_object *mo,
576 if (mo->mo_dir_ops->mdo_lock_mode == NULL)
578 return mo->mo_dir_ops->mdo_lock_mode(env, mo, lm);
581 static inline int mdo_create(const struct lu_env *env,
583 const struct lu_name *lchild_name,
585 struct md_op_spec *spc,
588 LASSERT(c->mo_dir_ops->mdo_create);
589 return c->mo_dir_ops->mdo_create(env, p, lchild_name, c, spc, at);
592 static inline int mdo_create_data(const struct lu_env *env,
595 const struct md_op_spec *spec,
598 LASSERT(c->mo_dir_ops->mdo_create_data);
599 return c->mo_dir_ops->mdo_create_data(env, p, c, spec, ma);
602 static inline int mdo_rename(const struct lu_env *env,
603 struct md_object *sp,
604 struct md_object *tp,
605 const struct lu_fid *lf,
606 const struct lu_name *lsname,
608 const struct lu_name *ltname,
611 LASSERT(tp->mo_dir_ops->mdo_rename);
612 return tp->mo_dir_ops->mdo_rename(env, sp, tp, lf, lsname, t, ltname,
616 static inline int mdo_is_subdir(const struct lu_env *env,
617 struct md_object *mo,
618 const struct lu_fid *fid,
621 LASSERT(mo->mo_dir_ops->mdo_is_subdir);
622 return mo->mo_dir_ops->mdo_is_subdir(env, mo, fid, sfid);
625 static inline int mdo_link(const struct lu_env *env,
628 const struct lu_name *lname,
631 LASSERT(s->mo_dir_ops->mdo_link);
632 return s->mo_dir_ops->mdo_link(env, p, s, lname, ma);
635 static inline int mdo_unlink(const struct lu_env *env,
638 const struct lu_name *lname,
641 LASSERT(c->mo_dir_ops->mdo_unlink);
642 return c->mo_dir_ops->mdo_unlink(env, p, c, lname, ma);
645 static inline int mdo_name_insert(const struct lu_env *env,
647 const struct lu_name *lname,
648 const struct lu_fid *f,
649 const struct md_attr *ma)
651 LASSERT(p->mo_dir_ops->mdo_name_insert);
652 return p->mo_dir_ops->mdo_name_insert(env, p, lname, f, ma);
655 static inline int mdo_name_remove(const struct lu_env *env,
657 const struct lu_name *lname,
658 const struct md_attr *ma)
660 LASSERT(p->mo_dir_ops->mdo_name_remove);
661 return p->mo_dir_ops->mdo_name_remove(env, p, lname, ma);
664 static inline int mdo_rename_tgt(const struct lu_env *env,
667 const struct lu_fid *lf,
668 const struct lu_name *lname,
672 LASSERT(t->mo_dir_ops->mdo_rename_tgt);
673 return t->mo_dir_ops->mdo_rename_tgt(env, p, t, lf, lname, ma);
675 LASSERT(p->mo_dir_ops->mdo_rename_tgt);
676 return p->mo_dir_ops->mdo_rename_tgt(env, p, t, lf, lname, ma);
682 #endif /* _LINUX_MD_OBJECT_H */