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
44 #ifndef HAVE_SERVER_SUPPORT
45 # error "client code should not depend on md_object.h"
46 #endif /* !HAVE_SERVER_SUPPORT */
49 * Sub-class of lu_object with methods common for "meta-data" objects in MDT
52 * Meta-data objects implement namespace operations: you can link, unlink
53 * them, and treat them as directories.
55 * Examples: mdt, cmm, and mdt are implementations of md interface.
61 * super-class definitions.
63 #include <dt_object.h>
66 struct md_device_operations;
70 /** metadata attributes */
77 MA_ACL_DEF = (1 << 5),
78 MA_LOV_DEF = (1 << 6),
82 MA_LMV_DEF = (1 << 10)
99 MDT_REG_LOCK = (1 << 0),
100 MDT_PDO_LOCK = (1 << 1)
103 /* memory structure for hsm attributes
104 * for fields description see the on disk structure hsm_attrs
105 * which is defined in lustre_idl.h
114 #define IOEPOCH_INVAL 0
116 /* memory structure for som attributes
117 * for fields description see the on disk structure som_attrs
118 * which is defined in lustre_idl.h
133 struct lu_attr ma_attr;
134 struct lu_fid ma_pfid;
135 struct md_hsm ma_hsm;
136 struct lov_mds_md *ma_lmm;
137 union lmv_mds_md *ma_lmv;
139 struct lustre_capa *ma_capa;
140 struct md_som_data *ma_som;
146 /** Additional parameters for create */
149 /** symlink target */
150 const char *sp_symname;
151 /** eadata for regular files */
158 /** Create flag from client: such as MDS_OPEN_CREAT, and others. */
161 /** don't create lov objects or llog cookie - this replay */
162 unsigned int no_create:1,
163 sp_cr_lookup:1, /* do lookup sanity check or not. */
164 sp_rm_entry:1; /* only remove name entry */
166 /** Current lock mode for parent dir where create is performing. */
167 mdl_mode_t sp_cr_mode;
169 /** to create directory */
170 const struct dt_index_features *sp_feat;
173 union ldlm_policy_data;
175 * Operations implemented for each md object (both directory and leaf).
177 struct md_object_operations {
178 int (*moo_permission)(const struct lu_env *env,
179 struct md_object *pobj, struct md_object *cobj,
180 struct md_attr *attr, int mask);
182 int (*moo_attr_get)(const struct lu_env *env, struct md_object *obj,
183 struct md_attr *attr);
185 int (*moo_attr_set)(const struct lu_env *env, struct md_object *obj,
186 const struct md_attr *attr);
188 int (*moo_xattr_get)(const struct lu_env *env, struct md_object *obj,
189 struct lu_buf *buf, const char *name);
191 int (*moo_xattr_list)(const struct lu_env *env, struct md_object *obj,
194 int (*moo_xattr_set)(const struct lu_env *env, struct md_object *obj,
195 const struct lu_buf *buf, const char *name,
198 int (*moo_xattr_del)(const struct lu_env *env, struct md_object *obj,
201 /** This method is used to swap the layouts between 2 objects */
202 int (*moo_swap_layouts)(const struct lu_env *env,
203 struct md_object *obj1, struct md_object *obj2,
206 /** \retval number of bytes actually read upon success */
207 int (*moo_readpage)(const struct lu_env *env, struct md_object *obj,
208 const struct lu_rdpg *rdpg);
210 int (*moo_readlink)(const struct lu_env *env, struct md_object *obj,
212 int (*moo_changelog)(const struct lu_env *env,
213 enum changelog_rec_type type, int flags,
214 struct md_object *obj);
216 int (*moo_open)(const struct lu_env *env,
217 struct md_object *obj, int flag);
219 int (*moo_close)(const struct lu_env *env, struct md_object *obj,
220 struct md_attr *ma, int mode);
222 int (*moo_capa_get)(const struct lu_env *, struct md_object *,
223 struct lustre_capa *, int renewal);
225 int (*moo_object_sync)(const struct lu_env *, struct md_object *);
227 int (*moo_object_lock)(const struct lu_env *env, struct md_object *obj,
228 struct lustre_handle *lh,
229 struct ldlm_enqueue_info *einfo,
230 union ldlm_policy_data *policy);
231 int (*moo_object_unlock)(const struct lu_env *env,
232 struct md_object *obj,
233 struct ldlm_enqueue_info *einfo,
234 union ldlm_policy_data *policy);
238 * Operations implemented for each directory object.
240 struct md_dir_operations {
241 int (*mdo_is_subdir) (const struct lu_env *env, struct md_object *obj,
242 const struct lu_fid *fid, struct lu_fid *sfid);
244 int (*mdo_lookup)(const struct lu_env *env, struct md_object *obj,
245 const struct lu_name *lname, struct lu_fid *fid,
246 struct md_op_spec *spec);
248 mdl_mode_t (*mdo_lock_mode)(const struct lu_env *env,
249 struct md_object *obj,
252 int (*mdo_create)(const struct lu_env *env, struct md_object *pobj,
253 const struct lu_name *lname, struct md_object *child,
254 struct md_op_spec *spec,
257 /** This method is used for creating data object for this meta object*/
258 int (*mdo_create_data)(const struct lu_env *env, struct md_object *p,
260 const struct md_op_spec *spec,
263 int (*mdo_rename)(const struct lu_env *env, struct md_object *spobj,
264 struct md_object *tpobj, const struct lu_fid *lf,
265 const struct lu_name *lsname, struct md_object *tobj,
266 const struct lu_name *ltname, struct md_attr *ma);
268 int (*mdo_link)(const struct lu_env *env, struct md_object *tgt_obj,
269 struct md_object *src_obj, const struct lu_name *lname,
272 int (*mdo_unlink)(const struct lu_env *env, struct md_object *pobj,
273 struct md_object *cobj, const struct lu_name *lname,
274 struct md_attr *ma, int no_name);
276 int (*mdo_migrate)(const struct lu_env *env, struct md_object *pobj,
277 struct md_object *sobj, const struct lu_name *lname,
278 struct md_object *tobj, struct md_attr *ma);
281 struct md_device_operations {
282 /** meta-data device related handlers. */
283 int (*mdo_root_get)(const struct lu_env *env, struct md_device *m,
286 int (*mdo_maxeasize_get)(const struct lu_env *env, struct md_device *m,
289 int (*mdo_statfs)(const struct lu_env *env, struct md_device *m,
290 struct obd_statfs *sfs);
292 int (*mdo_init_capa_ctxt)(const struct lu_env *env, struct md_device *m,
293 int mode, unsigned long timeout, __u32 alg,
294 struct lustre_capa_key *keys);
296 int (*mdo_update_capa_key)(const struct lu_env *env,
298 struct lustre_capa_key *key);
300 int (*mdo_llog_ctxt_get)(const struct lu_env *env,
301 struct md_device *m, int idx, void **h);
303 int (*mdo_iocontrol)(const struct lu_env *env, struct md_device *m,
304 unsigned int cmd, int len, void *data);
308 struct lu_device md_lu_dev;
309 const struct md_device_operations *md_ops;
313 struct lu_object mo_lu;
314 const struct md_object_operations *mo_ops;
315 const struct md_dir_operations *mo_dir_ops;
318 /* Mark the object to be dead, and can not be accessed anymore.
319 * XXX, right now, it will only be used for striped directory to
320 * mark the slave stripes dead, when deleting master object. It will be
321 * stored in slave LMV EA (see lod_mark_dead_object), which is only
322 * temporary, and will be removed later when we have proper way to mark
323 * the dead object. */
324 #define LUSTRE_SLAVE_DEAD_FL 0x80000000
326 static inline struct md_device *lu2md_dev(const struct lu_device *d)
328 LASSERT(IS_ERR(d) || lu_device_is_md(d));
329 return container_of0(d, struct md_device, md_lu_dev);
332 static inline struct lu_device *md2lu_dev(struct md_device *d)
334 return &d->md_lu_dev;
337 static inline struct md_object *lu2md(const struct lu_object *o)
339 LASSERT(o == NULL || IS_ERR(o) || lu_device_is_md(o->lo_dev));
340 return container_of0(o, struct md_object, mo_lu);
343 static inline int md_device_init(struct md_device *md, struct lu_device_type *t)
345 return lu_device_init(&md->md_lu_dev, t);
348 static inline void md_device_fini(struct md_device *md)
350 lu_device_fini(&md->md_lu_dev);
353 static inline struct md_object *md_object_find_slice(const struct lu_env *env,
354 struct md_device *md,
355 const struct lu_fid *f)
357 return lu2md(lu_object_find_slice(env, md2lu_dev(md), f, NULL));
362 static inline int mo_permission(const struct lu_env *env,
368 LASSERT(c->mo_ops->moo_permission);
369 return c->mo_ops->moo_permission(env, p, c, at, mask);
372 static inline int mo_attr_get(const struct lu_env *env,
376 LASSERT(m->mo_ops->moo_attr_get);
377 return m->mo_ops->moo_attr_get(env, m, at);
380 static inline int mo_readlink(const struct lu_env *env,
384 LASSERT(m->mo_ops->moo_readlink);
385 return m->mo_ops->moo_readlink(env, m, buf);
388 static inline int mo_changelog(const struct lu_env *env,
389 enum changelog_rec_type type,
390 int flags, struct md_object *m)
392 LASSERT(m->mo_ops->moo_changelog);
393 return m->mo_ops->moo_changelog(env, type, flags, m);
396 static inline int mo_attr_set(const struct lu_env *env,
398 const struct md_attr *at)
400 LASSERT(m->mo_ops->moo_attr_set);
401 return m->mo_ops->moo_attr_set(env, m, at);
404 static inline int mo_xattr_get(const struct lu_env *env,
409 LASSERT(m->mo_ops->moo_xattr_get);
410 return m->mo_ops->moo_xattr_get(env, m, buf, name);
413 static inline int mo_xattr_del(const struct lu_env *env,
417 LASSERT(m->mo_ops->moo_xattr_del);
418 return m->mo_ops->moo_xattr_del(env, m, name);
421 static inline int mo_xattr_set(const struct lu_env *env,
423 const struct lu_buf *buf,
427 LASSERT(m->mo_ops->moo_xattr_set);
428 return m->mo_ops->moo_xattr_set(env, m, buf, name, flags);
431 static inline int mo_xattr_list(const struct lu_env *env,
435 LASSERT(m->mo_ops->moo_xattr_list);
436 return m->mo_ops->moo_xattr_list(env, m, buf);
439 static inline int mo_swap_layouts(const struct lu_env *env,
440 struct md_object *o1,
441 struct md_object *o2, __u64 flags)
443 LASSERT(o1->mo_ops->moo_swap_layouts);
444 LASSERT(o2->mo_ops->moo_swap_layouts);
445 if (o1->mo_ops->moo_swap_layouts != o2->mo_ops->moo_swap_layouts)
447 return o1->mo_ops->moo_swap_layouts(env, o1, o2, flags);
450 static inline int mo_open(const struct lu_env *env,
454 LASSERT(m->mo_ops->moo_open);
455 return m->mo_ops->moo_open(env, m, flags);
458 static inline int mo_close(const struct lu_env *env,
463 LASSERT(m->mo_ops->moo_close);
464 return m->mo_ops->moo_close(env, m, ma, mode);
467 static inline int mo_readpage(const struct lu_env *env,
469 const struct lu_rdpg *rdpg)
471 LASSERT(m->mo_ops->moo_readpage);
472 return m->mo_ops->moo_readpage(env, m, rdpg);
475 static inline int mo_capa_get(const struct lu_env *env,
477 struct lustre_capa *c,
480 LASSERT(m->mo_ops->moo_capa_get);
481 return m->mo_ops->moo_capa_get(env, m, c, renewal);
484 static inline int mo_object_sync(const struct lu_env *env, struct md_object *m)
486 LASSERT(m->mo_ops->moo_object_sync);
487 return m->mo_ops->moo_object_sync(env, m);
490 static inline int mo_object_lock(const struct lu_env *env,
492 struct lustre_handle *lh,
493 struct ldlm_enqueue_info *einfo,
494 union ldlm_policy_data *policy)
496 LASSERT(m->mo_ops->moo_object_lock);
497 return m->mo_ops->moo_object_lock(env, m, lh, einfo, policy);
500 static inline int mo_object_unlock(const struct lu_env *env,
502 struct ldlm_enqueue_info *einfo,
503 union ldlm_policy_data *policy)
505 LASSERT(m->mo_ops->moo_object_unlock);
506 return m->mo_ops->moo_object_unlock(env, m, einfo, policy);
509 static inline int mdo_lookup(const struct lu_env *env,
511 const struct lu_name *lname,
513 struct md_op_spec *spec)
515 LASSERT(p->mo_dir_ops->mdo_lookup);
516 return p->mo_dir_ops->mdo_lookup(env, p, lname, f, spec);
519 static inline mdl_mode_t mdo_lock_mode(const struct lu_env *env,
520 struct md_object *mo,
523 if (mo->mo_dir_ops->mdo_lock_mode == NULL)
525 return mo->mo_dir_ops->mdo_lock_mode(env, mo, lm);
528 static inline int mdo_create(const struct lu_env *env,
530 const struct lu_name *lchild_name,
532 struct md_op_spec *spc,
535 LASSERT(p->mo_dir_ops->mdo_create);
536 return p->mo_dir_ops->mdo_create(env, p, lchild_name, c, spc, at);
539 static inline int mdo_create_data(const struct lu_env *env,
542 const struct md_op_spec *spec,
545 LASSERT(c->mo_dir_ops->mdo_create_data);
546 return c->mo_dir_ops->mdo_create_data(env, p, c, spec, ma);
549 static inline int mdo_rename(const struct lu_env *env,
550 struct md_object *sp,
551 struct md_object *tp,
552 const struct lu_fid *lf,
553 const struct lu_name *lsname,
555 const struct lu_name *ltname,
558 LASSERT(tp->mo_dir_ops->mdo_rename);
559 return tp->mo_dir_ops->mdo_rename(env, sp, tp, lf, lsname, t, ltname,
563 static inline int mdo_migrate(const struct lu_env *env,
564 struct md_object *pobj,
565 struct md_object *sobj,
566 const struct lu_name *lname,
567 struct md_object *tobj,
570 LASSERT(pobj->mo_dir_ops->mdo_migrate);
571 return pobj->mo_dir_ops->mdo_migrate(env, pobj, sobj, lname, tobj, ma);
574 static inline int mdo_is_subdir(const struct lu_env *env,
575 struct md_object *mo,
576 const struct lu_fid *fid,
579 LASSERT(mo->mo_dir_ops->mdo_is_subdir);
580 return mo->mo_dir_ops->mdo_is_subdir(env, mo, fid, sfid);
583 static inline int mdo_link(const struct lu_env *env,
586 const struct lu_name *lname,
589 LASSERT(s->mo_dir_ops->mdo_link);
590 return s->mo_dir_ops->mdo_link(env, p, s, lname, ma);
593 static inline int mdo_unlink(const struct lu_env *env,
596 const struct lu_name *lname,
597 struct md_attr *ma, int no_name)
599 LASSERT(p->mo_dir_ops->mdo_unlink);
600 return p->mo_dir_ops->mdo_unlink(env, p, c, lname, ma, no_name);
604 * Used in MDD/OUT layer for object lock rule
606 enum mdd_object_role {
616 int lustre_buf2som(void *buf, int rc, struct md_som_data *msd);
617 int lustre_buf2hsm(void *buf, int rc, struct md_hsm *mh);
618 void lustre_hsm2buf(void *buf, const struct md_hsm *mh);
637 __u32 uc_suppgids[2];
640 struct group_info *uc_ginfo;
641 struct md_identity *uc_identity;
642 char uc_jobid[LUSTRE_JOBID_SIZE];
645 struct lu_ucred *lu_ucred(const struct lu_env *env);
647 struct lu_ucred *lu_ucred_check(const struct lu_env *env);
649 struct lu_ucred *lu_ucred_assert(const struct lu_env *env);
651 int lu_ucred_global_init(void);
653 void lu_ucred_global_fini(void);
655 #define md_cap_t(x) (x)
657 #define MD_CAP_TO_MASK(x) (1 << (x))
659 #define md_cap_raised(c, flag) (md_cap_t(c) & MD_CAP_TO_MASK(flag))
661 /* capable() is copied from linux kernel! */
662 static inline int md_capable(struct lu_ucred *uc, cfs_cap_t cap)
664 if (md_cap_raised(uc->uc_cap, cap))
670 #endif /* _LINUX_MD_OBJECT_H */