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/
31 * lustre/include/md_object.h
33 * Extention of lu_object.h for metadata objects
36 #ifndef _LUSTRE_MD_OBJECT_H
37 #define _LUSTRE_MD_OBJECT_H
39 #ifndef HAVE_SERVER_SUPPORT
40 # error "client code should not depend on md_object.h"
41 #endif /* !HAVE_SERVER_SUPPORT */
44 * Sub-class of lu_object with methods common for "meta-data" objects in MDT
47 * Meta-data objects implement namespace operations: you can link, unlink
48 * them, and treat them as directories.
50 * Examples: mdt, cmm, and mdt are implementations of md interface.
56 * super-class definitions.
58 #include <dt_object.h>
61 struct md_device_operations;
65 /** metadata attributes */
77 MA_FORCE_LOG = BIT(10), /* forced close logged in mdt_mfd_close */
94 MDT_REG_LOCK = BIT(0),
95 MDT_PDO_LOCK = BIT(1),
98 /* lfs rgetfacl permission check */
99 #define MAY_RGETFACL BIT(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;
133 struct lmv_user_md *ma_default_lmv;
137 int ma_default_lmv_size;
139 int ma_enable_chprojid_gid;
142 /** Additional parameters for create */
145 /** symlink target */
146 const char *sp_symname;
147 /** eadata for regular files */
154 /** Open flags from client: such as MDS_OPEN_CREAT, and others. */
157 /* File security context for creates. */
158 const char *sp_cr_file_secctx_name; /* (security) xattr name */
159 void *sp_cr_file_secctx; /* xattr value */
160 size_t sp_cr_file_secctx_size; /* xattr value size */
162 /* File encryption context for creates. */
163 void *sp_cr_file_encctx; /* enc ctx value */
164 size_t sp_cr_file_encctx_size; /* enc ctx size */
166 /* Archive ID used for auto PCC attach when create newly files. */
169 /** don't create lov objects or llog cookie - this replay */
170 unsigned int no_create:1,
171 sp_cr_lookup:1, /* do lookup sanity check or not. */
172 sp_rm_entry:1, /* only remove name entry */
173 sp_permitted:1, /* do not check permission */
174 sp_migrate_close:1, /* close the file during migrate */
175 sp_migrate_nsonly:1; /* migrate dirent only */
176 /** Current lock mode for parent dir where create is performing. */
177 mdl_mode_t sp_cr_mode;
179 /** to create directory */
180 const struct dt_index_features *sp_feat;
185 MD_LAYOUT_WRITE, /* FLR: write the file */
186 MD_LAYOUT_RESYNC, /* FLR: resync starts */
187 MD_LAYOUT_RESYNC_DONE, /* FLR: resync done */
188 MD_LAYOUT_ATTACH, /* attach stripes */
189 MD_LAYOUT_DETACH, /* detach stripes */
190 MD_LAYOUT_SHRINK, /* shrink striped directory (destroy stripes) */
191 MD_LAYOUT_SPLIT, /* split directory (allocate new stripes) */
196 * Parameters for layout change API.
198 struct md_layout_change {
199 enum md_layout_opc mlc_opc;
200 struct lu_buf mlc_buf;
204 struct layout_intent *mlc_intent;
205 struct lustre_som_attrs mlc_som;
206 size_t mlc_resync_count;
207 __u32 *mlc_resync_ids;
210 /* parent obj in plain dir split */
211 struct md_object *mlc_parent;
212 /* target obj in plain dir split */
213 struct md_object *mlc_target;
214 /* target attr in plain dir split */
215 struct lu_attr *mlc_attr;
216 /* target name in plain dir split */
217 const struct lu_name *mlc_name;
219 struct md_op_spec *mlc_spec;
224 union ldlm_policy_data;
226 * Operations implemented for each md object (both directory and leaf).
228 struct md_object_operations {
229 int (*moo_permission)(const struct lu_env *env,
230 struct md_object *pobj, struct md_object *cobj,
231 struct md_attr *attr, unsigned int may_mask);
233 int (*moo_attr_get)(const struct lu_env *env, struct md_object *obj,
234 struct md_attr *attr);
236 int (*moo_attr_set)(const struct lu_env *env, struct md_object *obj,
237 const struct md_attr *attr);
239 int (*moo_xattr_get)(const struct lu_env *env, struct md_object *obj,
240 struct lu_buf *buf, const char *name);
242 int (*moo_xattr_list)(const struct lu_env *env, struct md_object *obj,
245 int (*moo_xattr_set)(const struct lu_env *env, struct md_object *obj,
246 const struct lu_buf *buf, const char *name,
249 int (*moo_xattr_del)(const struct lu_env *env, struct md_object *obj,
252 /** This method is used to swap the layouts between 2 objects */
253 int (*moo_swap_layouts)(const struct lu_env *env,
254 struct md_object *obj1, struct md_object *obj2,
257 /** \retval number of bytes actually read upon success */
258 int (*moo_readpage)(const struct lu_env *env, struct md_object *obj,
259 const struct lu_rdpg *rdpg);
261 int (*moo_readlink)(const struct lu_env *env, struct md_object *obj,
264 int (*moo_changelog)(const struct lu_env *env,
265 enum changelog_rec_type type,
266 enum changelog_rec_flags clf_flags,
267 struct md_device *m, const struct lu_fid *fid);
269 int (*moo_open)(const struct lu_env *env, struct md_object *obj,
270 u64 open_flags, struct md_op_spec*);
272 int (*moo_close)(const struct lu_env *env, struct md_object *obj,
273 struct md_attr *ma, u64 open_flags);
275 int (*moo_object_sync)(const struct lu_env *, struct md_object *);
277 int (*moo_object_lock)(const struct lu_env *env, struct md_object *obj,
278 struct lustre_handle *lh,
279 struct ldlm_enqueue_info *einfo,
280 union ldlm_policy_data *policy);
281 int (*moo_object_unlock)(const struct lu_env *env,
282 struct md_object *obj,
283 struct ldlm_enqueue_info *einfo,
284 union ldlm_policy_data *policy);
286 int (*moo_invalidate)(const struct lu_env *env, struct md_object *obj);
288 * Trying to write to un-instantiated layout component.
290 * The caller should have held layout lock.
292 * This API can be extended to support every other layout changing
293 * operations, such as component {add,del,change}, layout swap,
294 * layout merge, etc. One of the benefits by doing this is that the MDT
295 * no longer needs to understand layout.
297 * However, layout creation, removal, and fetch should still use
298 * xattr_{get,set}() because they don't interpret layout on the
301 * \param[in] env execution environment
302 * \param[in] obj MD object
303 * \param[in] layout data structure to describe the changes to
304 * the MD object's layout
307 * \retval -ne error code
309 int (*moo_layout_change)(const struct lu_env *env,
310 struct md_object *obj,
311 struct md_layout_change *layout);
315 * Operations implemented for each directory object.
317 struct md_dir_operations {
318 int (*mdo_is_subdir)(const struct lu_env *env, struct md_object *obj,
319 const struct lu_fid *fid);
321 int (*mdo_lookup)(const struct lu_env *env, struct md_object *obj,
322 const struct lu_name *lname, struct lu_fid *fid,
323 struct md_op_spec *spec);
325 mdl_mode_t (*mdo_lock_mode)(const struct lu_env *env,
326 struct md_object *obj,
329 int (*mdo_create)(const struct lu_env *env, struct md_object *pobj,
330 const struct lu_name *lname, struct md_object *child,
331 struct md_op_spec *spec,
334 /** This method is used for creating data object for this meta object*/
335 int (*mdo_create_data)(const struct lu_env *env, struct md_object *p,
337 const struct md_op_spec *spec,
340 int (*mdo_rename)(const struct lu_env *env, struct md_object *spobj,
341 struct md_object *tpobj, const struct lu_fid *lf,
342 const struct lu_name *lsname, struct md_object *tobj,
343 const struct lu_name *ltname, struct md_attr *ma);
345 int (*mdo_link)(const struct lu_env *env, struct md_object *tgt_obj,
346 struct md_object *src_obj, const struct lu_name *lname,
349 int (*mdo_unlink)(const struct lu_env *env, struct md_object *pobj,
350 struct md_object *cobj, const struct lu_name *lname,
351 struct md_attr *ma, int no_name);
353 int (*mdo_migrate)(const struct lu_env *env, struct md_object *pobj,
354 struct md_object *sobj, const struct lu_name *lname,
355 struct md_object *tobj, struct md_op_spec *spec,
359 struct md_device_operations {
360 /** meta-data device related handlers. */
361 int (*mdo_root_get)(const struct lu_env *env, struct md_device *m,
364 const struct dt_device_param *(*mdo_dtconf_get)(const struct lu_env *e,
365 struct md_device *m);
367 int (*mdo_statfs)(const struct lu_env *env, struct md_device *m,
368 struct obd_statfs *sfs);
370 int (*mdo_llog_ctxt_get)(const struct lu_env *env,
371 struct md_device *m, int idx, void **h);
373 int (*mdo_iocontrol)(const struct lu_env *env, struct md_device *m,
374 unsigned int cmd, int len, void *data);
378 struct lu_device md_lu_dev;
379 const struct md_device_operations *md_ops;
383 struct lu_object mo_lu;
384 const struct md_object_operations *mo_ops;
385 const struct md_dir_operations *mo_dir_ops;
388 static inline struct md_device *lu2md_dev(const struct lu_device *d)
390 LASSERT(IS_ERR(d) || lu_device_is_md(d));
391 return container_of_safe(d, struct md_device, md_lu_dev);
394 static inline struct lu_device *md2lu_dev(struct md_device *d)
396 return &d->md_lu_dev;
399 static inline struct md_object *lu2md(const struct lu_object *o)
401 LASSERT(o == NULL || IS_ERR(o) || lu_device_is_md(o->lo_dev));
402 return container_of_safe(o, struct md_object, mo_lu);
405 static inline int md_device_init(struct md_device *md, struct lu_device_type *t)
407 return lu_device_init(&md->md_lu_dev, t);
410 static inline void md_device_fini(struct md_device *md)
412 lu_device_fini(&md->md_lu_dev);
415 static inline struct md_object *md_object_find_slice(const struct lu_env *env,
416 struct md_device *md,
417 const struct lu_fid *f)
419 return lu2md(lu_object_find_slice(env, md2lu_dev(md), f, NULL));
424 static inline int mo_permission(const struct lu_env *env, struct md_object *p,
425 struct md_object *c, struct md_attr *at,
426 unsigned int may_mask)
428 LASSERT(c->mo_ops->moo_permission);
429 return c->mo_ops->moo_permission(env, p, c, at, may_mask);
432 static inline int mo_attr_get(const struct lu_env *env, struct md_object *m,
435 LASSERT(m->mo_ops->moo_attr_get);
436 return m->mo_ops->moo_attr_get(env, m, at);
439 static inline int mo_readlink(const struct lu_env *env,
443 LASSERT(m->mo_ops->moo_readlink);
444 return m->mo_ops->moo_readlink(env, m, buf);
447 static inline int mo_changelog(const struct lu_env *env,
448 enum changelog_rec_type type,
449 enum changelog_rec_flags clf_flags,
450 struct md_device *m, const struct lu_fid *fid)
452 struct lu_fid rootfid;
453 struct md_object *root;
456 rc = m->md_ops->mdo_root_get(env, m, &rootfid);
460 root = md_object_find_slice(env, m, &rootfid);
462 RETURN(PTR_ERR(root));
464 LASSERT(root->mo_ops->moo_changelog);
465 rc = root->mo_ops->moo_changelog(env, type, clf_flags, m, fid);
467 lu_object_put(env, &root->mo_lu);
472 static inline int mo_attr_set(const struct lu_env *env,
474 const struct md_attr *at)
476 LASSERT(m->mo_ops->moo_attr_set);
477 return m->mo_ops->moo_attr_set(env, m, at);
480 static inline int mo_xattr_get(const struct lu_env *env,
485 LASSERT(m->mo_ops->moo_xattr_get);
486 return m->mo_ops->moo_xattr_get(env, m, buf, name);
489 static inline int mo_xattr_del(const struct lu_env *env,
493 LASSERT(m->mo_ops->moo_xattr_del);
494 return m->mo_ops->moo_xattr_del(env, m, name);
497 static inline int mo_xattr_set(const struct lu_env *env,
499 const struct lu_buf *buf,
503 LASSERT(m->mo_ops->moo_xattr_set);
504 return m->mo_ops->moo_xattr_set(env, m, buf, name, flags);
507 static inline int mo_xattr_list(const struct lu_env *env,
511 LASSERT(m->mo_ops->moo_xattr_list);
512 return m->mo_ops->moo_xattr_list(env, m, buf);
515 static inline int mo_invalidate(const struct lu_env *env, struct md_object *m)
517 LASSERT(m->mo_ops->moo_invalidate);
518 return m->mo_ops->moo_invalidate(env, m);
521 static inline int mo_layout_change(const struct lu_env *env,
523 struct md_layout_change *layout)
525 /* need instantiate objects which in the access range */
526 LASSERT(m->mo_ops->moo_layout_change);
527 return m->mo_ops->moo_layout_change(env, m, layout);
530 static inline int mo_swap_layouts(const struct lu_env *env,
531 struct md_object *o1,
532 struct md_object *o2, __u64 flags)
534 LASSERT(o1->mo_ops->moo_swap_layouts);
535 LASSERT(o2->mo_ops->moo_swap_layouts);
536 if (o1->mo_ops->moo_swap_layouts != o2->mo_ops->moo_swap_layouts)
538 return o1->mo_ops->moo_swap_layouts(env, o1, o2, flags);
541 static inline int mo_open(const struct lu_env *env, struct md_object *m,
542 u64 open_flags, struct md_op_spec *spec)
544 LASSERT(m->mo_ops->moo_open);
545 return m->mo_ops->moo_open(env, m, open_flags, spec);
548 static inline int mo_close(const struct lu_env *env, struct md_object *m,
549 struct md_attr *ma, u64 open_flags)
551 LASSERT(m->mo_ops->moo_close);
552 return m->mo_ops->moo_close(env, m, ma, open_flags);
555 static inline int mo_readpage(const struct lu_env *env,
557 const struct lu_rdpg *rdpg)
559 LASSERT(m->mo_ops->moo_readpage);
560 return m->mo_ops->moo_readpage(env, m, rdpg);
563 static inline int mo_object_sync(const struct lu_env *env, struct md_object *m)
565 LASSERT(m->mo_ops->moo_object_sync);
566 return m->mo_ops->moo_object_sync(env, m);
569 static inline int mo_object_lock(const struct lu_env *env,
571 struct lustre_handle *lh,
572 struct ldlm_enqueue_info *einfo,
573 union ldlm_policy_data *policy)
575 LASSERT(m->mo_ops->moo_object_lock);
576 return m->mo_ops->moo_object_lock(env, m, lh, einfo, policy);
579 static inline int mo_object_unlock(const struct lu_env *env,
581 struct ldlm_enqueue_info *einfo,
582 union ldlm_policy_data *policy)
584 LASSERT(m->mo_ops->moo_object_unlock);
585 return m->mo_ops->moo_object_unlock(env, m, einfo, policy);
588 static inline int mdo_lookup(const struct lu_env *env,
590 const struct lu_name *lname,
592 struct md_op_spec *spec)
594 LASSERT(p->mo_dir_ops->mdo_lookup);
595 return p->mo_dir_ops->mdo_lookup(env, p, lname, f, spec);
598 static inline mdl_mode_t mdo_lock_mode(const struct lu_env *env,
599 struct md_object *mo,
602 if (mo->mo_dir_ops->mdo_lock_mode == NULL)
604 return mo->mo_dir_ops->mdo_lock_mode(env, mo, lm);
607 static inline int mdo_create(const struct lu_env *env,
609 const struct lu_name *lchild_name,
611 struct md_op_spec *spc,
614 LASSERT(p->mo_dir_ops->mdo_create);
615 return p->mo_dir_ops->mdo_create(env, p, lchild_name, c, spc, at);
618 static inline int mdo_create_data(const struct lu_env *env,
621 const struct md_op_spec *spec,
624 LASSERT(c->mo_dir_ops->mdo_create_data);
625 return c->mo_dir_ops->mdo_create_data(env, p, c, spec, ma);
628 static inline int mdo_rename(const struct lu_env *env,
629 struct md_object *sp,
630 struct md_object *tp,
631 const struct lu_fid *lf,
632 const struct lu_name *lsname,
634 const struct lu_name *ltname,
637 LASSERT(tp->mo_dir_ops->mdo_rename);
638 return tp->mo_dir_ops->mdo_rename(env, sp, tp, lf, lsname, t, ltname,
642 static inline int mdo_migrate(const struct lu_env *env,
643 struct md_object *pobj,
644 struct md_object *sobj,
645 const struct lu_name *lname,
646 struct md_object *tobj,
647 struct md_op_spec *spec,
650 LASSERT(pobj->mo_dir_ops->mdo_migrate);
651 return pobj->mo_dir_ops->mdo_migrate(env, pobj, sobj, lname, tobj, spec,
655 static inline int mdo_is_subdir(const struct lu_env *env,
656 struct md_object *mo,
657 const struct lu_fid *fid)
659 LASSERT(mo->mo_dir_ops->mdo_is_subdir);
660 return mo->mo_dir_ops->mdo_is_subdir(env, mo, fid);
663 static inline int mdo_link(const struct lu_env *env,
666 const struct lu_name *lname,
669 LASSERT(s->mo_dir_ops->mdo_link);
670 return s->mo_dir_ops->mdo_link(env, p, s, lname, ma);
673 static inline int mdo_unlink(const struct lu_env *env,
676 const struct lu_name *lname,
677 struct md_attr *ma, int no_name)
679 LASSERT(p->mo_dir_ops->mdo_unlink);
680 return p->mo_dir_ops->mdo_unlink(env, p, c, lname, ma, no_name);
683 static inline int mdo_statfs(const struct lu_env *env,
685 struct obd_statfs *sfs)
687 LASSERT(m->md_ops->mdo_statfs);
688 return m->md_ops->mdo_statfs(env, m, sfs);
693 void lustre_som_swab(struct lustre_som_attrs *attrs);
694 int lustre_buf2hsm(void *buf, int rc, struct md_hsm *mh);
695 void lustre_hsm2buf(void *buf, const struct md_hsm *mh);
714 __u32 uc_suppgids[2];
717 struct group_info *uc_ginfo;
718 struct md_identity *uc_identity;
719 char uc_jobid[LUSTRE_JOBID_SIZE];
721 bool uc_enable_audit;
724 struct lu_ucred *lu_ucred(const struct lu_env *env);
726 struct lu_ucred *lu_ucred_check(const struct lu_env *env);
728 struct lu_ucred *lu_ucred_assert(const struct lu_env *env);
730 int lu_ucred_global_init(void);
732 void lu_ucred_global_fini(void);
734 #define md_cap_t(x) (x)
736 #define MD_CAP_TO_MASK(x) BIT(x)
738 #define md_cap_raised(c, flag) (md_cap_t(c) & MD_CAP_TO_MASK(flag))
740 /* capable() is copied from linux kernel! */
741 static inline int md_capable(struct lu_ucred *uc, cfs_cap_t cap)
743 if (md_cap_raised(uc->uc_cap, cap))
749 #endif /* _LINUX_MD_OBJECT_H */