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 */
94 MDT_REG_LOCK = (1 << 0),
95 MDT_PDO_LOCK = (1 << 1)
98 /* lfs rgetfacl permission check */
99 #define MAY_RGETFACL (1 << 14)
101 /* memory structure for hsm attributes
102 * for fields description see the on disk structure hsm_attrs
103 * which is defined in lustre_idl.h
113 /* memory structure for SOM attributes
114 * for fields description see the on disk structure som_attrs
115 * which is defined in lustre_idl.h
127 struct lu_attr ma_attr;
128 struct lu_fid ma_pfid;
129 struct md_hsm ma_hsm;
130 struct md_som ma_som;
131 struct lov_mds_md *ma_lmm;
132 union lmv_mds_md *ma_lmv;
139 /** Additional parameters for create */
142 /** symlink target */
143 const char *sp_symname;
144 /** eadata for regular files */
151 /** Create flag from client: such as MDS_OPEN_CREAT, and others. */
154 /* File security context for creates. */
155 const char *sp_cr_file_secctx_name; /* (security) xattr name */
156 void *sp_cr_file_secctx; /* xattr value */
157 size_t sp_cr_file_secctx_size; /* xattr value size */
159 /** don't create lov objects or llog cookie - this replay */
160 unsigned int no_create:1,
161 sp_cr_lookup:1, /* do lookup sanity check or not. */
162 sp_rm_entry:1, /* only remove name entry */
163 sp_permitted:1, /* do not check permission */
164 sp_migrate_close:1; /* close the file during migrate */
165 /** Current lock mode for parent dir where create is performing. */
166 mdl_mode_t sp_cr_mode;
168 /** to create directory */
169 const struct dt_index_features *sp_feat;
174 MD_LAYOUT_WRITE, /* FLR: write the file */
175 MD_LAYOUT_RESYNC, /* FLR: resync starts */
176 MD_LAYOUT_RESYNC_DONE, /* FLR: resync done */
180 * Parameters for layout change API.
182 struct md_layout_change {
183 enum md_layout_opc mlc_opc;
184 struct layout_intent *mlc_intent;
185 struct lu_buf mlc_buf;
186 struct lustre_som_attrs mlc_som;
187 size_t mlc_resync_count;
188 __u32 *mlc_resync_ids;
191 union ldlm_policy_data;
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 /** This method is used to swap the layouts between 2 objects */
220 int (*moo_swap_layouts)(const struct lu_env *env,
221 struct md_object *obj1, struct md_object *obj2,
224 /** \retval number of bytes actually read upon success */
225 int (*moo_readpage)(const struct lu_env *env, struct md_object *obj,
226 const struct lu_rdpg *rdpg);
228 int (*moo_readlink)(const struct lu_env *env, struct md_object *obj,
230 int (*moo_changelog)(const struct lu_env *env,
231 enum changelog_rec_type type, int flags,
232 struct md_device *m, const struct lu_fid *fid);
234 int (*moo_open)(const struct lu_env *env,
235 struct md_object *obj, int flag);
237 int (*moo_close)(const struct lu_env *env, struct md_object *obj,
238 struct md_attr *ma, int mode);
240 int (*moo_object_sync)(const struct lu_env *, struct md_object *);
242 int (*moo_object_lock)(const struct lu_env *env, struct md_object *obj,
243 struct lustre_handle *lh,
244 struct ldlm_enqueue_info *einfo,
245 union ldlm_policy_data *policy);
246 int (*moo_object_unlock)(const struct lu_env *env,
247 struct md_object *obj,
248 struct ldlm_enqueue_info *einfo,
249 union ldlm_policy_data *policy);
251 int (*moo_invalidate)(const struct lu_env *env, struct md_object *obj);
253 * Trying to write to un-instantiated layout component.
255 * The caller should have held layout lock.
257 * This API can be extended to support every other layout changing
258 * operations, such as component {add,del,change}, layout swap,
259 * layout merge, etc. One of the benefits by doing this is that the MDT
260 * no longer needs to understand layout.
262 * However, layout creation, removal, and fetch should still use
263 * xattr_{get,set}() because they don't interpret layout on the
266 * \param[in] env execution environment
267 * \param[in] obj MD object
268 * \param[in] layout data structure to describe the changes to
269 * the MD object's layout
272 * \retval -ne error code
274 int (*moo_layout_change)(const struct lu_env *env,
275 struct md_object *obj,
276 struct md_layout_change *layout);
280 * Operations implemented for each directory object.
282 struct md_dir_operations {
283 int (*mdo_is_subdir)(const struct lu_env *env, struct md_object *obj,
284 const struct lu_fid *fid);
286 int (*mdo_lookup)(const struct lu_env *env, struct md_object *obj,
287 const struct lu_name *lname, struct lu_fid *fid,
288 struct md_op_spec *spec);
290 mdl_mode_t (*mdo_lock_mode)(const struct lu_env *env,
291 struct md_object *obj,
294 int (*mdo_create)(const struct lu_env *env, struct md_object *pobj,
295 const struct lu_name *lname, struct md_object *child,
296 struct md_op_spec *spec,
299 /** This method is used for creating data object for this meta object*/
300 int (*mdo_create_data)(const struct lu_env *env, struct md_object *p,
302 const struct md_op_spec *spec,
305 int (*mdo_rename)(const struct lu_env *env, struct md_object *spobj,
306 struct md_object *tpobj, const struct lu_fid *lf,
307 const struct lu_name *lsname, struct md_object *tobj,
308 const struct lu_name *ltname, struct md_attr *ma);
310 int (*mdo_link)(const struct lu_env *env, struct md_object *tgt_obj,
311 struct md_object *src_obj, const struct lu_name *lname,
314 int (*mdo_unlink)(const struct lu_env *env, struct md_object *pobj,
315 struct md_object *cobj, const struct lu_name *lname,
316 struct md_attr *ma, int no_name);
318 int (*mdo_migrate)(const struct lu_env *env, struct md_object *pobj,
319 struct md_object *sobj, const struct lu_name *lname,
320 struct md_object *tobj, struct md_op_spec *spec,
324 struct md_device_operations {
325 /** meta-data device related handlers. */
326 int (*mdo_root_get)(const struct lu_env *env, struct md_device *m,
329 const struct dt_device_param *(*mdo_dtconf_get)(const struct lu_env *e,
330 struct md_device *m);
332 int (*mdo_statfs)(const struct lu_env *env, struct md_device *m,
333 struct obd_statfs *sfs);
335 int (*mdo_llog_ctxt_get)(const struct lu_env *env,
336 struct md_device *m, int idx, void **h);
338 int (*mdo_iocontrol)(const struct lu_env *env, struct md_device *m,
339 unsigned int cmd, int len, void *data);
343 struct lu_device md_lu_dev;
344 const struct md_device_operations *md_ops;
348 struct lu_object mo_lu;
349 const struct md_object_operations *mo_ops;
350 const struct md_dir_operations *mo_dir_ops;
353 static inline struct md_device *lu2md_dev(const struct lu_device *d)
355 LASSERT(IS_ERR(d) || lu_device_is_md(d));
356 return container_of0(d, struct md_device, md_lu_dev);
359 static inline struct lu_device *md2lu_dev(struct md_device *d)
361 return &d->md_lu_dev;
364 static inline struct md_object *lu2md(const struct lu_object *o)
366 LASSERT(o == NULL || IS_ERR(o) || lu_device_is_md(o->lo_dev));
367 return container_of0(o, struct md_object, mo_lu);
370 static inline int md_device_init(struct md_device *md, struct lu_device_type *t)
372 return lu_device_init(&md->md_lu_dev, t);
375 static inline void md_device_fini(struct md_device *md)
377 lu_device_fini(&md->md_lu_dev);
380 static inline struct md_object *md_object_find_slice(const struct lu_env *env,
381 struct md_device *md,
382 const struct lu_fid *f)
384 return lu2md(lu_object_find_slice(env, md2lu_dev(md), f, NULL));
389 static inline int mo_permission(const struct lu_env *env,
395 LASSERT(c->mo_ops->moo_permission);
396 return c->mo_ops->moo_permission(env, p, c, at, mask);
399 static inline int mo_attr_get(const struct lu_env *env,
403 LASSERT(m->mo_ops->moo_attr_get);
404 return m->mo_ops->moo_attr_get(env, m, at);
407 static inline int mo_readlink(const struct lu_env *env,
411 LASSERT(m->mo_ops->moo_readlink);
412 return m->mo_ops->moo_readlink(env, m, buf);
415 static inline int mo_changelog(const struct lu_env *env,
416 enum changelog_rec_type type,
417 int flags, struct md_device *m,
418 const struct lu_fid *fid)
420 struct lu_fid rootfid;
421 struct md_object *root;
424 rc = m->md_ops->mdo_root_get(env, m, &rootfid);
428 root = md_object_find_slice(env, m, &rootfid);
430 RETURN(PTR_ERR(root));
432 LASSERT(root->mo_ops->moo_changelog);
433 rc = root->mo_ops->moo_changelog(env, type, flags, m, fid);
435 lu_object_put(env, &root->mo_lu);
440 static inline int mo_attr_set(const struct lu_env *env,
442 const struct md_attr *at)
444 LASSERT(m->mo_ops->moo_attr_set);
445 return m->mo_ops->moo_attr_set(env, m, at);
448 static inline int mo_xattr_get(const struct lu_env *env,
453 LASSERT(m->mo_ops->moo_xattr_get);
454 return m->mo_ops->moo_xattr_get(env, m, buf, name);
457 static inline int mo_xattr_del(const struct lu_env *env,
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,
467 const struct lu_buf *buf,
471 LASSERT(m->mo_ops->moo_xattr_set);
472 return m->mo_ops->moo_xattr_set(env, m, buf, name, flags);
475 static inline int mo_xattr_list(const struct lu_env *env,
479 LASSERT(m->mo_ops->moo_xattr_list);
480 return m->mo_ops->moo_xattr_list(env, m, buf);
483 static inline int mo_invalidate(const struct lu_env *env, struct md_object *m)
485 LASSERT(m->mo_ops->moo_invalidate);
486 return m->mo_ops->moo_invalidate(env, m);
489 static inline int mo_layout_change(const struct lu_env *env,
491 struct md_layout_change *layout)
493 /* need instantiate objects which in the access range */
494 LASSERT(m->mo_ops->moo_layout_change);
495 return m->mo_ops->moo_layout_change(env, m, layout);
498 static inline int mo_swap_layouts(const struct lu_env *env,
499 struct md_object *o1,
500 struct md_object *o2, __u64 flags)
502 LASSERT(o1->mo_ops->moo_swap_layouts);
503 LASSERT(o2->mo_ops->moo_swap_layouts);
504 if (o1->mo_ops->moo_swap_layouts != o2->mo_ops->moo_swap_layouts)
506 return o1->mo_ops->moo_swap_layouts(env, o1, o2, flags);
509 static inline int mo_open(const struct lu_env *env,
513 LASSERT(m->mo_ops->moo_open);
514 return m->mo_ops->moo_open(env, m, flags);
517 static inline int mo_close(const struct lu_env *env,
522 LASSERT(m->mo_ops->moo_close);
523 return m->mo_ops->moo_close(env, m, ma, mode);
526 static inline int mo_readpage(const struct lu_env *env,
528 const struct lu_rdpg *rdpg)
530 LASSERT(m->mo_ops->moo_readpage);
531 return m->mo_ops->moo_readpage(env, m, rdpg);
534 static inline int mo_object_sync(const struct lu_env *env, struct md_object *m)
536 LASSERT(m->mo_ops->moo_object_sync);
537 return m->mo_ops->moo_object_sync(env, m);
540 static inline int mo_object_lock(const struct lu_env *env,
542 struct lustre_handle *lh,
543 struct ldlm_enqueue_info *einfo,
544 union ldlm_policy_data *policy)
546 LASSERT(m->mo_ops->moo_object_lock);
547 return m->mo_ops->moo_object_lock(env, m, lh, einfo, policy);
550 static inline int mo_object_unlock(const struct lu_env *env,
552 struct ldlm_enqueue_info *einfo,
553 union ldlm_policy_data *policy)
555 LASSERT(m->mo_ops->moo_object_unlock);
556 return m->mo_ops->moo_object_unlock(env, m, einfo, policy);
559 static inline int mdo_lookup(const struct lu_env *env,
561 const struct lu_name *lname,
563 struct md_op_spec *spec)
565 LASSERT(p->mo_dir_ops->mdo_lookup);
566 return p->mo_dir_ops->mdo_lookup(env, p, lname, f, spec);
569 static inline mdl_mode_t mdo_lock_mode(const struct lu_env *env,
570 struct md_object *mo,
573 if (mo->mo_dir_ops->mdo_lock_mode == NULL)
575 return mo->mo_dir_ops->mdo_lock_mode(env, mo, lm);
578 static inline int mdo_create(const struct lu_env *env,
580 const struct lu_name *lchild_name,
582 struct md_op_spec *spc,
585 LASSERT(p->mo_dir_ops->mdo_create);
586 return p->mo_dir_ops->mdo_create(env, p, lchild_name, c, spc, at);
589 static inline int mdo_create_data(const struct lu_env *env,
592 const struct md_op_spec *spec,
595 LASSERT(c->mo_dir_ops->mdo_create_data);
596 return c->mo_dir_ops->mdo_create_data(env, p, c, spec, ma);
599 static inline int mdo_rename(const struct lu_env *env,
600 struct md_object *sp,
601 struct md_object *tp,
602 const struct lu_fid *lf,
603 const struct lu_name *lsname,
605 const struct lu_name *ltname,
608 LASSERT(tp->mo_dir_ops->mdo_rename);
609 return tp->mo_dir_ops->mdo_rename(env, sp, tp, lf, lsname, t, ltname,
613 static inline int mdo_migrate(const struct lu_env *env,
614 struct md_object *pobj,
615 struct md_object *sobj,
616 const struct lu_name *lname,
617 struct md_object *tobj,
618 struct md_op_spec *spec,
621 LASSERT(pobj->mo_dir_ops->mdo_migrate);
622 return pobj->mo_dir_ops->mdo_migrate(env, pobj, sobj, lname, tobj, spec,
626 static inline int mdo_is_subdir(const struct lu_env *env,
627 struct md_object *mo,
628 const struct lu_fid *fid)
630 LASSERT(mo->mo_dir_ops->mdo_is_subdir);
631 return mo->mo_dir_ops->mdo_is_subdir(env, mo, fid);
634 static inline int mdo_link(const struct lu_env *env,
637 const struct lu_name *lname,
640 LASSERT(s->mo_dir_ops->mdo_link);
641 return s->mo_dir_ops->mdo_link(env, p, s, lname, ma);
644 static inline int mdo_unlink(const struct lu_env *env,
647 const struct lu_name *lname,
648 struct md_attr *ma, int no_name)
650 LASSERT(p->mo_dir_ops->mdo_unlink);
651 return p->mo_dir_ops->mdo_unlink(env, p, c, lname, ma, no_name);
654 static inline int mdo_statfs(const struct lu_env *env,
656 struct obd_statfs *sfs)
658 LASSERT(m->md_ops->mdo_statfs);
659 return m->md_ops->mdo_statfs(env, m, sfs);
663 * Used in MDD/OUT layer for object lock rule
665 enum mdd_object_role {
675 void lustre_som_swab(struct lustre_som_attrs *attrs);
676 int lustre_buf2hsm(void *buf, int rc, struct md_hsm *mh);
677 void lustre_hsm2buf(void *buf, const struct md_hsm *mh);
696 __u32 uc_suppgids[2];
699 struct group_info *uc_ginfo;
700 struct md_identity *uc_identity;
701 char uc_jobid[LUSTRE_JOBID_SIZE];
703 bool uc_enable_audit;
706 struct lu_ucred *lu_ucred(const struct lu_env *env);
708 struct lu_ucred *lu_ucred_check(const struct lu_env *env);
710 struct lu_ucred *lu_ucred_assert(const struct lu_env *env);
712 int lu_ucred_global_init(void);
714 void lu_ucred_global_fini(void);
716 #define md_cap_t(x) (x)
718 #define MD_CAP_TO_MASK(x) (1 << (x))
720 #define md_cap_raised(c, flag) (md_cap_t(c) & MD_CAP_TO_MASK(flag))
722 /* capable() is copied from linux kernel! */
723 static inline int md_capable(struct lu_ucred *uc, cfs_cap_t cap)
725 if (md_cap_raised(uc->uc_cap, cap))
731 #endif /* _LINUX_MD_OBJECT_H */