1 /* SPDX-License-Identifier: GPL-2.0 */
4 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
5 * Use is subject to license terms.
7 * Copyright (c) 2011, 2017, Intel Corporation.
11 * This file is part of Lustre, http://www.lustre.org/
13 * Extention of lu_object.h for metadata objects
16 #ifndef _LUSTRE_MD_OBJECT_H
17 #define _LUSTRE_MD_OBJECT_H
19 #ifndef HAVE_SERVER_SUPPORT
20 # error "client code should not depend on md_object.h"
21 #endif /* !HAVE_SERVER_SUPPORT */
23 /* md Sub-class of lu_object with methods common for "meta-data" objects in MDT
26 * Meta-data objects implement namespace operations: you can link, unlink
27 * them, and treat them as directories.
29 * Examples: mdt, cmm, and mdt are implementations of md interface.
33 * super-class definitions.
35 #include <dt_object.h>
38 struct md_device_operations;
42 /** metadata attributes */
54 MA_FORCE_LOG = BIT(10), /* forced close logged in mdt_mfd_close */
55 MA_DIRENT_CNT = BIT(11),
60 MDT_REG_LOCK = BIT(0),
61 MDT_PDO_LOCK = BIT(1),
64 /* lfs rgetfacl permission check */
65 #define MAY_RGETFACL BIT(14)
67 /* memory structure for hsm attributes
68 * for fields description see the on disk structure hsm_attrs
69 * which is defined in lustre_idl.h
79 /* memory structure for SOM attributes
80 * for fields description see the on disk structure som_attrs
81 * which is defined in lustre_idl.h
93 struct lu_attr ma_attr;
94 struct lu_fid ma_pfid;
97 struct lov_mds_md *ma_lmm;
98 union lmv_mds_md *ma_lmv;
99 struct lmv_user_md *ma_default_lmv;
103 int ma_default_lmv_size;
105 int ma_enable_chprojid_gid;
108 /** Additional parameters for create */
111 /** symlink target */
112 struct lu_name sp_symname;
113 /** eadata for regular files */
120 /** Open flags from client: such as MDS_OPEN_CREAT, and others. */
121 enum mds_open_flags sp_cr_flags;
123 /* File security context for creates. */
124 const char *sp_cr_file_secctx_name; /* (security) xattr name */
125 void *sp_cr_file_secctx; /* xattr value */
126 size_t sp_cr_file_secctx_size; /* xattr value size */
128 /* File encryption context for creates. */
129 void *sp_cr_file_encctx; /* enc ctx value */
130 size_t sp_cr_file_encctx_size; /* enc ctx size */
132 /* Archive ID used for auto PCC attach when create newly files. */
135 /** don't create lov objects or llog cookie - this replay */
136 unsigned int no_create:1,
137 sp_cr_lookup:1, /* do lookup sanity check or not. */
138 sp_rm_entry:1, /* only remove name entry */
139 sp_permitted:1, /* do not check permission */
140 sp_migrate_close:1, /* close the file during migrate */
141 sp_migrate_nsonly:1, /* migrate dirent only */
142 sp_dmv_imp_inherit:1, /* implicit default LMV inherit */
143 sp_replay:1; /* replay, op may be partially executed */
145 /** to create directory */
146 const struct dt_index_features *sp_feat;
148 /* name of xattr used to store jobid in inode, or empty if disabled */
149 char sp_cr_job_xattr[XATTR_JOB_MAX_LEN];
154 MD_LAYOUT_WRITE, /* FLR: write the file */
155 MD_LAYOUT_RESYNC, /* FLR: resync starts */
156 MD_LAYOUT_RESYNC_DONE, /* FLR: resync done */
157 MD_LAYOUT_ATTACH, /* attach stripes */
158 MD_LAYOUT_DETACH, /* detach stripes */
159 MD_LAYOUT_SHRINK, /* shrink striped directory (destroy stripes) */
160 MD_LAYOUT_SPLIT, /* split directory (allocate new stripes) */
165 * Parameters for layout change API.
167 struct md_layout_change {
168 enum md_layout_opc mlc_opc;
169 struct lu_buf mlc_buf;
173 struct layout_intent *mlc_intent;
174 struct lustre_som_attrs mlc_som;
175 size_t mlc_resync_count;
176 __u32 *mlc_resync_ids;
179 /* parent obj in plain dir split */
180 struct md_object *mlc_parent;
181 /* target obj in plain dir split */
182 struct md_object *mlc_target;
183 /* target attr in plain dir split */
184 struct lu_attr *mlc_attr;
185 /* target name in plain dir split */
186 const struct lu_name *mlc_name;
188 struct md_op_spec *mlc_spec;
193 union ldlm_policy_data;
195 * Operations implemented for each md object (both directory and leaf).
197 struct md_object_operations {
198 int (*moo_permission)(const struct lu_env *env,
199 struct md_object *pobj, struct md_object *cobj,
200 struct md_attr *attr, unsigned int may_mask);
202 int (*moo_attr_get)(const struct lu_env *env, struct md_object *obj,
203 struct md_attr *attr);
205 int (*moo_attr_set)(const struct lu_env *env, struct md_object *obj,
206 const struct md_attr *attr);
208 int (*moo_xattr_get)(const struct lu_env *env, struct md_object *obj,
209 struct lu_buf *buf, const char *name);
211 int (*moo_xattr_list)(const struct lu_env *env, struct md_object *obj,
214 int (*moo_xattr_set)(const struct lu_env *env, struct md_object *obj,
215 const struct lu_buf *buf, const char *name,
218 int (*moo_xattr_del)(const struct lu_env *env, struct md_object *obj,
221 /** This method is used to swap the layouts between 2 objects */
222 int (*moo_swap_layouts)(const struct lu_env *env,
223 struct md_object *obj1, struct md_object *obj2,
224 __u64 dv1, __u64 dv2, __u64 flags);
226 /** \retval number of bytes actually read upon success */
227 int (*moo_readpage)(const struct lu_env *env, struct md_object *obj,
228 const struct lu_rdpg *rdpg);
230 int (*moo_readlink)(const struct lu_env *env, struct md_object *obj,
233 int (*moo_changelog)(const struct lu_env *env,
234 enum changelog_rec_type type,
235 enum changelog_rec_flags clf_flags,
236 struct md_device *m, const struct lu_fid *fid);
238 int (*moo_open)(const struct lu_env *env, struct md_object *obj,
239 enum mds_open_flags open_flags, struct md_op_spec *spc);
241 int (*moo_close)(const struct lu_env *env, struct md_object *obj,
242 struct md_attr *ma, u64 open_flags);
244 int (*moo_object_sync)(const struct lu_env *env, struct md_object *obj);
246 int (*moo_object_lock)(const struct lu_env *env, struct md_object *obj,
247 struct lustre_handle *lh,
248 struct ldlm_enqueue_info *einfo,
249 union ldlm_policy_data *policy);
250 int (*moo_object_unlock)(const struct lu_env *env,
251 struct md_object *obj,
252 struct ldlm_enqueue_info *einfo,
253 union ldlm_policy_data *policy);
255 int (*moo_invalidate)(const struct lu_env *env, struct md_object *obj);
257 * Trying to write to un-instantiated layout component.
259 * The caller should have held layout lock.
261 * This API can be extended to support every other layout changing
262 * operations, such as component {add,del,change}, layout swap,
263 * layout merge, etc. One of the benefits by doing this is that the MDT
264 * no longer needs to understand layout.
266 * However, layout creation, removal, and fetch should still use
267 * xattr_{get,set}() because they don't interpret layout on the
270 * \param[in] env execution environment
271 * \param[in] obj MD object
272 * \param[in] layout data structure to describe the changes to
273 * the MD object's layout
276 * \retval -ne error code
278 int (*moo_layout_change)(const struct lu_env *env,
279 struct md_object *obj,
280 struct md_layout_change *layout);
282 * Additonal layout checks
284 int (*moo_layout_check)(const struct lu_env *env,
285 struct md_object *obj,
286 struct md_layout_change *layout);
290 * Operations implemented for each directory object.
292 struct md_dir_operations {
293 int (*mdo_is_subdir)(const struct lu_env *env, struct md_object *obj,
294 const struct lu_fid *fid);
296 int (*mdo_lookup)(const struct lu_env *env, struct md_object *obj,
297 const struct lu_name *lname, struct lu_fid *fid,
298 struct md_op_spec *spec);
300 enum ldlm_mode (*mdo_lock_mode)(const struct lu_env *env,
301 struct md_object *obj, enum ldlm_mode mode);
303 int (*mdo_create)(const struct lu_env *env, struct md_object *pobj,
304 const struct lu_name *lname, struct md_object *child,
305 struct md_op_spec *spec,
308 /** This method is used for creating data object for this meta object*/
309 int (*mdo_create_data)(const struct lu_env *env, struct md_object *p,
310 struct md_object *o, const struct md_op_spec *spec,
313 int (*mdo_rename)(const struct lu_env *env, struct md_object *spobj,
314 struct md_object *tpobj, const struct lu_fid *lf,
315 const struct lu_name *lsname, struct md_object *tobj,
316 const struct lu_name *ltname, struct md_attr *ma);
318 int (*mdo_link)(const struct lu_env *env, struct md_object *tgt_obj,
319 struct md_object *src_obj, const struct lu_name *lname,
322 int (*mdo_unlink)(const struct lu_env *env, struct md_object *pobj,
323 struct md_object *cobj, const struct lu_name *lname,
324 struct md_attr *ma, int no_name);
326 int (*mdo_migrate)(const struct lu_env *env, struct md_object *spobj,
327 struct md_object *tpobj, struct md_object *sobj,
328 struct md_object *tobj, const struct lu_name *lname,
329 struct md_op_spec *spec, struct md_attr *ma);
332 struct md_device_operations {
333 /* meta-data device related handlers. */
334 int (*mdo_root_get)(const struct lu_env *env, struct md_device *m,
337 const struct dt_device_param *(*mdo_dtconf_get)(const struct lu_env *e,
338 struct md_device *m);
340 int (*mdo_statfs)(const struct lu_env *env, struct md_device *m,
341 struct obd_statfs *sfs);
343 int (*mdo_llog_ctxt_get)(const struct lu_env *env,
344 struct md_device *m, int idx, void **h);
346 int (*mdo_iocontrol)(const struct lu_env *env, struct md_device *m,
347 unsigned int cmd, int len, void *data);
351 struct lu_device md_lu_dev;
352 const struct md_device_operations *md_ops;
356 struct lu_object mo_lu;
357 const struct md_object_operations *mo_ops;
358 const struct md_dir_operations *mo_dir_ops;
361 static inline struct md_device *lu2md_dev(const struct lu_device *d)
363 LASSERT(IS_ERR(d) || lu_device_is_md(d));
364 return container_of_safe(d, struct md_device, md_lu_dev);
367 static inline struct lu_device *md2lu_dev(struct md_device *d)
369 return &d->md_lu_dev;
372 static inline struct md_object *lu2md(const struct lu_object *o)
374 LASSERT(o == NULL || IS_ERR(o) || lu_device_is_md(o->lo_dev));
375 return container_of_safe(o, struct md_object, mo_lu);
378 static inline int md_device_init(struct md_device *md, struct lu_device_type *t)
380 return lu_device_init(&md->md_lu_dev, t);
383 static inline void md_device_fini(struct md_device *md)
385 lu_device_fini(&md->md_lu_dev);
388 static inline struct md_object *md_object_find_slice(const struct lu_env *env,
389 struct md_device *md,
390 const struct lu_fid *f)
392 return lu2md(lu_object_find_slice(env, md2lu_dev(md), f, NULL));
397 static inline int mo_permission(const struct lu_env *env, struct md_object *p,
398 struct md_object *c, struct md_attr *at,
399 unsigned int may_mask)
401 LASSERT(c->mo_ops->moo_permission);
402 return c->mo_ops->moo_permission(env, p, c, at, may_mask);
405 static inline int mo_attr_get(const struct lu_env *env, struct md_object *m,
408 LASSERT(m->mo_ops->moo_attr_get);
409 return m->mo_ops->moo_attr_get(env, m, at);
412 static inline int mo_readlink(const struct lu_env *env, struct md_object *m,
415 LASSERT(m->mo_ops->moo_readlink);
416 return m->mo_ops->moo_readlink(env, m, buf);
419 static inline int mo_changelog(const struct lu_env *env,
420 enum changelog_rec_type type,
421 enum changelog_rec_flags clf_flags,
422 struct md_device *m, const struct lu_fid *fid)
424 struct lu_fid rootfid;
425 struct md_object *root;
428 rc = m->md_ops->mdo_root_get(env, m, &rootfid);
432 root = md_object_find_slice(env, m, &rootfid);
434 RETURN(PTR_ERR(root));
436 LASSERT(root->mo_ops->moo_changelog);
437 rc = root->mo_ops->moo_changelog(env, type, clf_flags, m, fid);
439 lu_object_put(env, &root->mo_lu);
444 static inline int mo_attr_set(const struct lu_env *env, struct md_object *m,
445 const struct md_attr *at)
447 LASSERT(m->mo_ops->moo_attr_set);
448 return m->mo_ops->moo_attr_set(env, m, at);
451 static inline int mo_xattr_get(const struct lu_env *env, struct md_object *m,
452 struct lu_buf *buf, const char *name)
454 LASSERT(m->mo_ops->moo_xattr_get);
455 return m->mo_ops->moo_xattr_get(env, m, buf, name);
458 static inline int mo_xattr_del(const struct lu_env *env, struct md_object *m,
461 LASSERT(m->mo_ops->moo_xattr_del);
462 return m->mo_ops->moo_xattr_del(env, m, name);
465 static inline int mo_xattr_set(const struct lu_env *env, struct md_object *m,
466 const struct lu_buf *buf, const char *name,
469 LASSERT(m->mo_ops->moo_xattr_set);
470 return m->mo_ops->moo_xattr_set(env, m, buf, name, flags);
473 static inline int mo_xattr_list(const struct lu_env *env, struct md_object *m,
476 LASSERT(m->mo_ops->moo_xattr_list);
477 return m->mo_ops->moo_xattr_list(env, m, buf);
480 static inline int mo_invalidate(const struct lu_env *env, struct md_object *m)
482 LASSERT(m->mo_ops->moo_invalidate);
483 return m->mo_ops->moo_invalidate(env, m);
486 static inline int mo_layout_change(const struct lu_env *env,
488 struct md_layout_change *layout)
490 /* need instantiate objects which in the access range */
491 LASSERT(m->mo_ops->moo_layout_change);
492 return m->mo_ops->moo_layout_change(env, m, layout);
495 static inline int mo_layout_check(const struct lu_env *env,
497 struct md_layout_change *layout)
499 LASSERT(m->mo_ops->moo_layout_check);
500 return m->mo_ops->moo_layout_check(env, m, layout);
503 static inline int mo_swap_layouts(const struct lu_env *env,
504 struct md_object *o1, struct md_object *o2,
505 __u64 dv1, __u64 dv2, __u64 flags)
507 LASSERT(o1->mo_ops->moo_swap_layouts);
508 LASSERT(o2->mo_ops->moo_swap_layouts);
509 if (o1->mo_ops->moo_swap_layouts != o2->mo_ops->moo_swap_layouts)
511 return o1->mo_ops->moo_swap_layouts(env, o1, o2, dv1, dv2, flags);
514 static inline int mo_open(const struct lu_env *env, struct md_object *m,
515 u64 open_flags, struct md_op_spec *spec)
517 LASSERT(m->mo_ops->moo_open);
518 return m->mo_ops->moo_open(env, m, open_flags, spec);
521 static inline int mo_close(const struct lu_env *env, struct md_object *m,
522 struct md_attr *ma, u64 open_flags)
524 LASSERT(m->mo_ops->moo_close);
525 return m->mo_ops->moo_close(env, m, ma, open_flags);
528 static inline int mo_readpage(const struct lu_env *env, struct md_object *m,
529 const struct lu_rdpg *rdpg)
531 LASSERT(m->mo_ops->moo_readpage);
532 return m->mo_ops->moo_readpage(env, m, rdpg);
535 static inline int mo_object_sync(const struct lu_env *env, struct md_object *m)
537 LASSERT(m->mo_ops->moo_object_sync);
538 return m->mo_ops->moo_object_sync(env, m);
541 static inline int mo_object_lock(const struct lu_env *env,
543 struct lustre_handle *lh,
544 struct ldlm_enqueue_info *einfo,
545 union ldlm_policy_data *policy)
547 LASSERT(m->mo_ops->moo_object_lock);
548 return m->mo_ops->moo_object_lock(env, m, lh, einfo, policy);
551 static inline int mo_object_unlock(const struct lu_env *env,
553 struct ldlm_enqueue_info *einfo,
554 union ldlm_policy_data *policy)
556 LASSERT(m->mo_ops->moo_object_unlock);
557 return m->mo_ops->moo_object_unlock(env, m, einfo, policy);
560 static inline int mdo_lookup(const struct lu_env *env, struct md_object *p,
561 const struct lu_name *lname, struct lu_fid *f,
562 struct md_op_spec *spec)
564 LASSERT(p->mo_dir_ops->mdo_lookup);
565 return p->mo_dir_ops->mdo_lookup(env, p, lname, f, spec);
568 static inline enum ldlm_mode mdo_lock_mode(const struct lu_env *env,
569 struct md_object *mo,
572 if (mo->mo_dir_ops->mdo_lock_mode == NULL)
574 return mo->mo_dir_ops->mdo_lock_mode(env, mo, lm);
577 static inline int mdo_create(const struct lu_env *env, struct md_object *p,
578 const struct lu_name *lchild_name,
579 struct md_object *c, struct md_op_spec *spc,
582 LASSERT(p->mo_dir_ops->mdo_create);
583 return p->mo_dir_ops->mdo_create(env, p, lchild_name, c, spc, at);
586 static inline int mdo_create_data(const struct lu_env *env, struct md_object *p,
588 const struct md_op_spec *spec,
591 LASSERT(c->mo_dir_ops->mdo_create_data);
592 return c->mo_dir_ops->mdo_create_data(env, p, c, spec, ma);
595 static inline int mdo_rename(const struct lu_env *env, struct md_object *sp,
596 struct md_object *tp, const struct lu_fid *lf,
597 const struct lu_name *lsname, struct md_object *t,
598 const struct lu_name *ltname, struct md_attr *ma)
600 LASSERT(tp->mo_dir_ops->mdo_rename);
601 return tp->mo_dir_ops->mdo_rename(env, sp, tp, lf, lsname, t, ltname,
605 static inline int mdo_migrate(const struct lu_env *env,
606 struct md_object *spobj,
607 struct md_object *tpobj,
608 struct md_object *sobj,
609 struct md_object *tobj,
610 const struct lu_name *lname,
611 struct md_op_spec *spec,
614 LASSERT(spobj->mo_dir_ops->mdo_migrate);
615 return spobj->mo_dir_ops->mdo_migrate(env, spobj, tpobj, sobj, tobj,
619 static inline int mdo_is_subdir(const struct lu_env *env,
620 struct md_object *mo,
621 const struct lu_fid *fid)
623 LASSERT(mo->mo_dir_ops->mdo_is_subdir);
624 return mo->mo_dir_ops->mdo_is_subdir(env, mo, fid);
627 static inline int mdo_link(const struct lu_env *env, struct md_object *p,
628 struct md_object *s, 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,
639 struct md_attr *ma, int no_name)
641 LASSERT(p->mo_dir_ops->mdo_unlink);
642 return p->mo_dir_ops->mdo_unlink(env, p, c, lname, ma, no_name);
645 static inline int mdo_statfs(const struct lu_env *env,
647 struct obd_statfs *sfs)
649 LASSERT(m->md_ops->mdo_statfs);
650 return m->md_ops->mdo_statfs(env, m, sfs);
655 void lustre_som_swab(struct lustre_som_attrs *attrs);
656 int lustre_buf2hsm(void *buf, int rc, struct md_hsm *mh);
657 void lustre_hsm2buf(void *buf, const struct md_hsm *mh);
676 __u32 uc_suppgids[2];
679 struct group_info *uc_ginfo;
680 struct md_identity *uc_identity;
681 char uc_jobid[LUSTRE_JOBID_SIZE];
682 struct lnet_nid uc_nid;
683 bool uc_enable_audit;
684 unsigned int uc_rbac_file_perms:1;
685 unsigned int uc_rbac_dne_ops:1;
686 unsigned int uc_rbac_quota_ops:1;
687 unsigned int uc_rbac_byfid_ops:1;
688 unsigned int uc_rbac_chlg_ops:1;
689 unsigned int uc_rbac_fscrypt_admin:1;
690 unsigned int uc_rbac_server_upcall:1;
691 unsigned int uc_rbac_ignore_root_prjquota:1;
692 unsigned int uc_rbac_hsm_ops:1;
693 unsigned int uc_rbac_local_admin:1;
696 struct lu_ucred *lu_ucred(const struct lu_env *env);
698 struct lu_ucred *lu_ucred_check(const struct lu_env *env);
700 struct lu_ucred *lu_ucred_assert(const struct lu_env *env);
702 int lu_ucred_global_init(void);
704 void lu_ucred_global_fini(void);
706 #endif /* _LINUX_MD_OBJECT_H */