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.gnu.org/licenses/gpl-2.0.html
23 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2011, 2017, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
30 * Lustre is a trademark of Sun Microsystems, Inc.
32 * lustre/include/md_object.h
34 * Extention of lu_object.h for metadata objects
37 #ifndef _LUSTRE_MD_OBJECT_H
38 #define _LUSTRE_MD_OBJECT_H
40 #ifndef HAVE_SERVER_SUPPORT
41 # error "client code should not depend on md_object.h"
42 #endif /* !HAVE_SERVER_SUPPORT */
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 struct md_device_operations;
66 /** metadata attributes */
78 MA_FORCE_LOG = BIT(10), /* forced close logged in mdt_mfd_close */
95 MDT_REG_LOCK = BIT(0),
96 MDT_PDO_LOCK = BIT(1),
99 /* lfs rgetfacl permission check */
100 #define MAY_RGETFACL BIT(14)
102 /* memory structure for hsm attributes
103 * for fields description see the on disk structure hsm_attrs
104 * which is defined in lustre_idl.h
114 /* memory structure for SOM attributes
115 * for fields description see the on disk structure som_attrs
116 * which is defined in lustre_idl.h
128 struct lu_attr ma_attr;
129 struct lu_fid ma_pfid;
130 struct md_hsm ma_hsm;
131 struct md_som ma_som;
132 struct lov_mds_md *ma_lmm;
133 union lmv_mds_md *ma_lmv;
134 struct lmv_user_md *ma_default_lmv;
138 int ma_default_lmv_size;
140 int ma_enable_chprojid_gid;
143 /** Additional parameters for create */
146 /** symlink target */
147 const char *sp_symname;
148 /** eadata for regular files */
155 /** Open flags from client: such as MDS_OPEN_CREAT, and others. */
158 /* File security context for creates. */
159 const char *sp_cr_file_secctx_name; /* (security) xattr name */
160 void *sp_cr_file_secctx; /* xattr value */
161 size_t sp_cr_file_secctx_size; /* xattr value size */
163 /* File encryption context for creates. */
164 void *sp_cr_file_encctx; /* enc ctx value */
165 size_t sp_cr_file_encctx_size; /* enc ctx size */
167 /* Archive ID used for auto PCC attach when create newly files. */
170 /** don't create lov objects or llog cookie - this replay */
171 unsigned int no_create:1,
172 sp_cr_lookup:1, /* do lookup sanity check or not. */
173 sp_rm_entry:1, /* only remove name entry */
174 sp_permitted:1, /* do not check permission */
175 sp_migrate_close:1, /* close the file during migrate */
176 sp_migrate_nsonly:1; /* migrate dirent only */
177 /** Current lock mode for parent dir where create is performing. */
178 mdl_mode_t sp_cr_mode;
180 /** to create directory */
181 const struct dt_index_features *sp_feat;
186 MD_LAYOUT_WRITE, /* FLR: write the file */
187 MD_LAYOUT_RESYNC, /* FLR: resync starts */
188 MD_LAYOUT_RESYNC_DONE, /* FLR: resync done */
189 MD_LAYOUT_ATTACH, /* attach stripes */
190 MD_LAYOUT_DETACH, /* detach stripes */
191 MD_LAYOUT_SHRINK, /* shrink striped directory (destroy stripes) */
192 MD_LAYOUT_SPLIT, /* split directory (allocate new stripes) */
197 * Parameters for layout change API.
199 struct md_layout_change {
200 enum md_layout_opc mlc_opc;
201 struct lu_buf mlc_buf;
205 struct layout_intent *mlc_intent;
206 struct lustre_som_attrs mlc_som;
207 size_t mlc_resync_count;
208 __u32 *mlc_resync_ids;
211 /* parent obj in plain dir split */
212 struct md_object *mlc_parent;
213 /* target obj in plain dir split */
214 struct md_object *mlc_target;
215 /* target attr in plain dir split */
216 struct lu_attr *mlc_attr;
217 /* target name in plain dir split */
218 const struct lu_name *mlc_name;
220 struct md_op_spec *mlc_spec;
225 union ldlm_policy_data;
227 * Operations implemented for each md object (both directory and leaf).
229 struct md_object_operations {
230 int (*moo_permission)(const struct lu_env *env,
231 struct md_object *pobj, struct md_object *cobj,
232 struct md_attr *attr, int mask);
234 int (*moo_attr_get)(const struct lu_env *env, struct md_object *obj,
235 struct md_attr *attr);
237 int (*moo_attr_set)(const struct lu_env *env, struct md_object *obj,
238 const struct md_attr *attr);
240 int (*moo_xattr_get)(const struct lu_env *env, struct md_object *obj,
241 struct lu_buf *buf, const char *name);
243 int (*moo_xattr_list)(const struct lu_env *env, struct md_object *obj,
246 int (*moo_xattr_set)(const struct lu_env *env, struct md_object *obj,
247 const struct lu_buf *buf, const char *name,
250 int (*moo_xattr_del)(const struct lu_env *env, struct md_object *obj,
253 /** This method is used to swap the layouts between 2 objects */
254 int (*moo_swap_layouts)(const struct lu_env *env,
255 struct md_object *obj1, struct md_object *obj2,
258 /** \retval number of bytes actually read upon success */
259 int (*moo_readpage)(const struct lu_env *env, struct md_object *obj,
260 const struct lu_rdpg *rdpg);
262 int (*moo_readlink)(const struct lu_env *env, struct md_object *obj,
265 int (*moo_changelog)(const struct lu_env *env,
266 enum changelog_rec_type type,
267 enum changelog_rec_flags clf_flags,
268 struct md_device *m, const struct lu_fid *fid);
270 int (*moo_open)(const struct lu_env *env, struct md_object *obj,
271 u64 open_flags, struct md_op_spec*);
273 int (*moo_close)(const struct lu_env *env, struct md_object *obj,
274 struct md_attr *ma, u64 open_flags);
276 int (*moo_object_sync)(const struct lu_env *, struct md_object *);
278 int (*moo_object_lock)(const struct lu_env *env, struct md_object *obj,
279 struct lustre_handle *lh,
280 struct ldlm_enqueue_info *einfo,
281 union ldlm_policy_data *policy);
282 int (*moo_object_unlock)(const struct lu_env *env,
283 struct md_object *obj,
284 struct ldlm_enqueue_info *einfo,
285 union ldlm_policy_data *policy);
287 int (*moo_invalidate)(const struct lu_env *env, struct md_object *obj);
289 * Trying to write to un-instantiated layout component.
291 * The caller should have held layout lock.
293 * This API can be extended to support every other layout changing
294 * operations, such as component {add,del,change}, layout swap,
295 * layout merge, etc. One of the benefits by doing this is that the MDT
296 * no longer needs to understand layout.
298 * However, layout creation, removal, and fetch should still use
299 * xattr_{get,set}() because they don't interpret layout on the
302 * \param[in] env execution environment
303 * \param[in] obj MD object
304 * \param[in] layout data structure to describe the changes to
305 * the MD object's layout
308 * \retval -ne error code
310 int (*moo_layout_change)(const struct lu_env *env,
311 struct md_object *obj,
312 struct md_layout_change *layout);
316 * Operations implemented for each directory object.
318 struct md_dir_operations {
319 int (*mdo_is_subdir)(const struct lu_env *env, struct md_object *obj,
320 const struct lu_fid *fid);
322 int (*mdo_lookup)(const struct lu_env *env, struct md_object *obj,
323 const struct lu_name *lname, struct lu_fid *fid,
324 struct md_op_spec *spec);
326 mdl_mode_t (*mdo_lock_mode)(const struct lu_env *env,
327 struct md_object *obj,
330 int (*mdo_create)(const struct lu_env *env, struct md_object *pobj,
331 const struct lu_name *lname, struct md_object *child,
332 struct md_op_spec *spec,
335 /** This method is used for creating data object for this meta object*/
336 int (*mdo_create_data)(const struct lu_env *env, struct md_object *p,
338 const struct md_op_spec *spec,
341 int (*mdo_rename)(const struct lu_env *env, struct md_object *spobj,
342 struct md_object *tpobj, const struct lu_fid *lf,
343 const struct lu_name *lsname, struct md_object *tobj,
344 const struct lu_name *ltname, struct md_attr *ma);
346 int (*mdo_link)(const struct lu_env *env, struct md_object *tgt_obj,
347 struct md_object *src_obj, const struct lu_name *lname,
350 int (*mdo_unlink)(const struct lu_env *env, struct md_object *pobj,
351 struct md_object *cobj, const struct lu_name *lname,
352 struct md_attr *ma, int no_name);
354 int (*mdo_migrate)(const struct lu_env *env, struct md_object *pobj,
355 struct md_object *sobj, const struct lu_name *lname,
356 struct md_object *tobj, struct md_op_spec *spec,
360 struct md_device_operations {
361 /** meta-data device related handlers. */
362 int (*mdo_root_get)(const struct lu_env *env, struct md_device *m,
365 const struct dt_device_param *(*mdo_dtconf_get)(const struct lu_env *e,
366 struct md_device *m);
368 int (*mdo_statfs)(const struct lu_env *env, struct md_device *m,
369 struct obd_statfs *sfs);
371 int (*mdo_llog_ctxt_get)(const struct lu_env *env,
372 struct md_device *m, int idx, void **h);
374 int (*mdo_iocontrol)(const struct lu_env *env, struct md_device *m,
375 unsigned int cmd, int len, void *data);
379 struct lu_device md_lu_dev;
380 const struct md_device_operations *md_ops;
384 struct lu_object mo_lu;
385 const struct md_object_operations *mo_ops;
386 const struct md_dir_operations *mo_dir_ops;
389 static inline struct md_device *lu2md_dev(const struct lu_device *d)
391 LASSERT(IS_ERR(d) || lu_device_is_md(d));
392 return container_of_safe(d, struct md_device, md_lu_dev);
395 static inline struct lu_device *md2lu_dev(struct md_device *d)
397 return &d->md_lu_dev;
400 static inline struct md_object *lu2md(const struct lu_object *o)
402 LASSERT(o == NULL || IS_ERR(o) || lu_device_is_md(o->lo_dev));
403 return container_of_safe(o, struct md_object, mo_lu);
406 static inline int md_device_init(struct md_device *md, struct lu_device_type *t)
408 return lu_device_init(&md->md_lu_dev, t);
411 static inline void md_device_fini(struct md_device *md)
413 lu_device_fini(&md->md_lu_dev);
416 static inline struct md_object *md_object_find_slice(const struct lu_env *env,
417 struct md_device *md,
418 const struct lu_fid *f)
420 return lu2md(lu_object_find_slice(env, md2lu_dev(md), f, NULL));
425 static inline int mo_permission(const struct lu_env *env, struct md_object *p,
426 struct md_object *c, struct md_attr *at,
429 LASSERT(c->mo_ops->moo_permission);
430 return c->mo_ops->moo_permission(env, p, c, at, mask);
433 static inline int mo_attr_get(const struct lu_env *env, struct md_object *m,
436 LASSERT(m->mo_ops->moo_attr_get);
437 return m->mo_ops->moo_attr_get(env, m, at);
440 static inline int mo_readlink(const struct lu_env *env,
444 LASSERT(m->mo_ops->moo_readlink);
445 return m->mo_ops->moo_readlink(env, m, buf);
448 static inline int mo_changelog(const struct lu_env *env,
449 enum changelog_rec_type type,
450 enum changelog_rec_flags clf_flags,
451 struct md_device *m, const struct lu_fid *fid)
453 struct lu_fid rootfid;
454 struct md_object *root;
457 rc = m->md_ops->mdo_root_get(env, m, &rootfid);
461 root = md_object_find_slice(env, m, &rootfid);
463 RETURN(PTR_ERR(root));
465 LASSERT(root->mo_ops->moo_changelog);
466 rc = root->mo_ops->moo_changelog(env, type, clf_flags, m, fid);
468 lu_object_put(env, &root->mo_lu);
473 static inline int mo_attr_set(const struct lu_env *env,
475 const struct md_attr *at)
477 LASSERT(m->mo_ops->moo_attr_set);
478 return m->mo_ops->moo_attr_set(env, m, at);
481 static inline int mo_xattr_get(const struct lu_env *env,
486 LASSERT(m->mo_ops->moo_xattr_get);
487 return m->mo_ops->moo_xattr_get(env, m, buf, name);
490 static inline int mo_xattr_del(const struct lu_env *env,
494 LASSERT(m->mo_ops->moo_xattr_del);
495 return m->mo_ops->moo_xattr_del(env, m, name);
498 static inline int mo_xattr_set(const struct lu_env *env,
500 const struct lu_buf *buf,
504 LASSERT(m->mo_ops->moo_xattr_set);
505 return m->mo_ops->moo_xattr_set(env, m, buf, name, flags);
508 static inline int mo_xattr_list(const struct lu_env *env,
512 LASSERT(m->mo_ops->moo_xattr_list);
513 return m->mo_ops->moo_xattr_list(env, m, buf);
516 static inline int mo_invalidate(const struct lu_env *env, struct md_object *m)
518 LASSERT(m->mo_ops->moo_invalidate);
519 return m->mo_ops->moo_invalidate(env, m);
522 static inline int mo_layout_change(const struct lu_env *env,
524 struct md_layout_change *layout)
526 /* need instantiate objects which in the access range */
527 LASSERT(m->mo_ops->moo_layout_change);
528 return m->mo_ops->moo_layout_change(env, m, layout);
531 static inline int mo_swap_layouts(const struct lu_env *env,
532 struct md_object *o1,
533 struct md_object *o2, __u64 flags)
535 LASSERT(o1->mo_ops->moo_swap_layouts);
536 LASSERT(o2->mo_ops->moo_swap_layouts);
537 if (o1->mo_ops->moo_swap_layouts != o2->mo_ops->moo_swap_layouts)
539 return o1->mo_ops->moo_swap_layouts(env, o1, o2, flags);
542 static inline int mo_open(const struct lu_env *env, struct md_object *m,
543 u64 open_flags, struct md_op_spec *spec)
545 LASSERT(m->mo_ops->moo_open);
546 return m->mo_ops->moo_open(env, m, open_flags, spec);
549 static inline int mo_close(const struct lu_env *env, struct md_object *m,
550 struct md_attr *ma, u64 open_flags)
552 LASSERT(m->mo_ops->moo_close);
553 return m->mo_ops->moo_close(env, m, ma, open_flags);
556 static inline int mo_readpage(const struct lu_env *env,
558 const struct lu_rdpg *rdpg)
560 LASSERT(m->mo_ops->moo_readpage);
561 return m->mo_ops->moo_readpage(env, m, rdpg);
564 static inline int mo_object_sync(const struct lu_env *env, struct md_object *m)
566 LASSERT(m->mo_ops->moo_object_sync);
567 return m->mo_ops->moo_object_sync(env, m);
570 static inline int mo_object_lock(const struct lu_env *env,
572 struct lustre_handle *lh,
573 struct ldlm_enqueue_info *einfo,
574 union ldlm_policy_data *policy)
576 LASSERT(m->mo_ops->moo_object_lock);
577 return m->mo_ops->moo_object_lock(env, m, lh, einfo, policy);
580 static inline int mo_object_unlock(const struct lu_env *env,
582 struct ldlm_enqueue_info *einfo,
583 union ldlm_policy_data *policy)
585 LASSERT(m->mo_ops->moo_object_unlock);
586 return m->mo_ops->moo_object_unlock(env, m, einfo, policy);
589 static inline int mdo_lookup(const struct lu_env *env,
591 const struct lu_name *lname,
593 struct md_op_spec *spec)
595 LASSERT(p->mo_dir_ops->mdo_lookup);
596 return p->mo_dir_ops->mdo_lookup(env, p, lname, f, spec);
599 static inline mdl_mode_t mdo_lock_mode(const struct lu_env *env,
600 struct md_object *mo,
603 if (mo->mo_dir_ops->mdo_lock_mode == NULL)
605 return mo->mo_dir_ops->mdo_lock_mode(env, mo, lm);
608 static inline int mdo_create(const struct lu_env *env,
610 const struct lu_name *lchild_name,
612 struct md_op_spec *spc,
615 LASSERT(p->mo_dir_ops->mdo_create);
616 return p->mo_dir_ops->mdo_create(env, p, lchild_name, c, spc, at);
619 static inline int mdo_create_data(const struct lu_env *env,
622 const struct md_op_spec *spec,
625 LASSERT(c->mo_dir_ops->mdo_create_data);
626 return c->mo_dir_ops->mdo_create_data(env, p, c, spec, ma);
629 static inline int mdo_rename(const struct lu_env *env,
630 struct md_object *sp,
631 struct md_object *tp,
632 const struct lu_fid *lf,
633 const struct lu_name *lsname,
635 const struct lu_name *ltname,
638 LASSERT(tp->mo_dir_ops->mdo_rename);
639 return tp->mo_dir_ops->mdo_rename(env, sp, tp, lf, lsname, t, ltname,
643 static inline int mdo_migrate(const struct lu_env *env,
644 struct md_object *pobj,
645 struct md_object *sobj,
646 const struct lu_name *lname,
647 struct md_object *tobj,
648 struct md_op_spec *spec,
651 LASSERT(pobj->mo_dir_ops->mdo_migrate);
652 return pobj->mo_dir_ops->mdo_migrate(env, pobj, sobj, lname, tobj, spec,
656 static inline int mdo_is_subdir(const struct lu_env *env,
657 struct md_object *mo,
658 const struct lu_fid *fid)
660 LASSERT(mo->mo_dir_ops->mdo_is_subdir);
661 return mo->mo_dir_ops->mdo_is_subdir(env, mo, fid);
664 static inline int mdo_link(const struct lu_env *env,
667 const struct lu_name *lname,
670 LASSERT(s->mo_dir_ops->mdo_link);
671 return s->mo_dir_ops->mdo_link(env, p, s, lname, ma);
674 static inline int mdo_unlink(const struct lu_env *env,
677 const struct lu_name *lname,
678 struct md_attr *ma, int no_name)
680 LASSERT(p->mo_dir_ops->mdo_unlink);
681 return p->mo_dir_ops->mdo_unlink(env, p, c, lname, ma, no_name);
684 static inline int mdo_statfs(const struct lu_env *env,
686 struct obd_statfs *sfs)
688 LASSERT(m->md_ops->mdo_statfs);
689 return m->md_ops->mdo_statfs(env, m, sfs);
694 void lustre_som_swab(struct lustre_som_attrs *attrs);
695 int lustre_buf2hsm(void *buf, int rc, struct md_hsm *mh);
696 void lustre_hsm2buf(void *buf, const struct md_hsm *mh);
715 __u32 uc_suppgids[2];
718 struct group_info *uc_ginfo;
719 struct md_identity *uc_identity;
720 char uc_jobid[LUSTRE_JOBID_SIZE];
722 bool uc_enable_audit;
725 struct lu_ucred *lu_ucred(const struct lu_env *env);
727 struct lu_ucred *lu_ucred_check(const struct lu_env *env);
729 struct lu_ucred *lu_ucred_assert(const struct lu_env *env);
731 int lu_ucred_global_init(void);
733 void lu_ucred_global_fini(void);
735 #define md_cap_t(x) (x)
737 #define MD_CAP_TO_MASK(x) BIT(x)
739 #define md_cap_raised(c, flag) (md_cap_t(c) & MD_CAP_TO_MASK(flag))
741 /* capable() is copied from linux kernel! */
742 static inline int md_capable(struct lu_ucred *uc, cfs_cap_t cap)
744 if (md_cap_raised(uc->uc_cap, cap))
750 #endif /* _LINUX_MD_OBJECT_H */