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, 2016, 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 */
93 MDT_REG_LOCK = (1 << 0),
94 MDT_PDO_LOCK = (1 << 1)
97 /* lfs rgetfacl permission check */
98 #define MAY_RGETFACL (1 << 14)
100 /* memory structure for hsm attributes
101 * for fields description see the on disk structure hsm_attrs
102 * which is defined in lustre_idl.h
115 struct lu_attr ma_attr;
116 struct lu_fid ma_pfid;
117 struct md_hsm ma_hsm;
118 struct lov_mds_md *ma_lmm;
119 union lmv_mds_md *ma_lmv;
126 /** Additional parameters for create */
129 /** symlink target */
130 const char *sp_symname;
131 /** eadata for regular files */
138 /** Create flag from client: such as MDS_OPEN_CREAT, and others. */
141 /* File security context for creates. */
142 const char *sp_cr_file_secctx_name; /* (security) xattr name */
143 void *sp_cr_file_secctx; /* xattr value */
144 size_t sp_cr_file_secctx_size; /* xattr value size */
146 /** don't create lov objects or llog cookie - this replay */
147 unsigned int no_create:1,
148 sp_cr_lookup:1, /* do lookup sanity check or not. */
149 sp_rm_entry:1, /* only remove name entry */
150 sp_permitted:1, /* do not check permission */
151 sp_migrate_close:1; /* close the file during migrate */
152 /** Current lock mode for parent dir where create is performing. */
153 mdl_mode_t sp_cr_mode;
155 /** to create directory */
156 const struct dt_index_features *sp_feat;
159 union ldlm_policy_data;
161 * Operations implemented for each md object (both directory and leaf).
163 struct md_object_operations {
164 int (*moo_permission)(const struct lu_env *env,
165 struct md_object *pobj, struct md_object *cobj,
166 struct md_attr *attr, int mask);
168 int (*moo_attr_get)(const struct lu_env *env, struct md_object *obj,
169 struct md_attr *attr);
171 int (*moo_attr_set)(const struct lu_env *env, struct md_object *obj,
172 const struct md_attr *attr);
174 int (*moo_xattr_get)(const struct lu_env *env, struct md_object *obj,
175 struct lu_buf *buf, const char *name);
177 int (*moo_xattr_list)(const struct lu_env *env, struct md_object *obj,
180 int (*moo_xattr_set)(const struct lu_env *env, struct md_object *obj,
181 const struct lu_buf *buf, const char *name,
184 int (*moo_xattr_del)(const struct lu_env *env, struct md_object *obj,
187 /** This method is used to swap the layouts between 2 objects */
188 int (*moo_swap_layouts)(const struct lu_env *env,
189 struct md_object *obj1, struct md_object *obj2,
192 /** \retval number of bytes actually read upon success */
193 int (*moo_readpage)(const struct lu_env *env, struct md_object *obj,
194 const struct lu_rdpg *rdpg);
196 int (*moo_readlink)(const struct lu_env *env, struct md_object *obj,
198 int (*moo_changelog)(const struct lu_env *env,
199 enum changelog_rec_type type, int flags,
200 struct md_device *m, const struct lu_fid *fid);
202 int (*moo_open)(const struct lu_env *env,
203 struct md_object *obj, int flag);
205 int (*moo_close)(const struct lu_env *env, struct md_object *obj,
206 struct md_attr *ma, int mode);
208 int (*moo_object_sync)(const struct lu_env *, struct md_object *);
210 int (*moo_object_lock)(const struct lu_env *env, struct md_object *obj,
211 struct lustre_handle *lh,
212 struct ldlm_enqueue_info *einfo,
213 union ldlm_policy_data *policy);
214 int (*moo_object_unlock)(const struct lu_env *env,
215 struct md_object *obj,
216 struct ldlm_enqueue_info *einfo,
217 union ldlm_policy_data *policy);
219 int (*moo_invalidate)(const struct lu_env *env, struct md_object *obj);
223 * Operations implemented for each directory object.
225 struct md_dir_operations {
226 int (*mdo_is_subdir) (const struct lu_env *env, struct md_object *obj,
227 const struct lu_fid *fid, struct lu_fid *sfid);
229 int (*mdo_lookup)(const struct lu_env *env, struct md_object *obj,
230 const struct lu_name *lname, struct lu_fid *fid,
231 struct md_op_spec *spec);
233 mdl_mode_t (*mdo_lock_mode)(const struct lu_env *env,
234 struct md_object *obj,
237 int (*mdo_create)(const struct lu_env *env, struct md_object *pobj,
238 const struct lu_name *lname, struct md_object *child,
239 struct md_op_spec *spec,
242 /** This method is used for creating data object for this meta object*/
243 int (*mdo_create_data)(const struct lu_env *env, struct md_object *p,
245 const struct md_op_spec *spec,
248 int (*mdo_rename)(const struct lu_env *env, struct md_object *spobj,
249 struct md_object *tpobj, const struct lu_fid *lf,
250 const struct lu_name *lsname, struct md_object *tobj,
251 const struct lu_name *ltname, struct md_attr *ma);
253 int (*mdo_link)(const struct lu_env *env, struct md_object *tgt_obj,
254 struct md_object *src_obj, const struct lu_name *lname,
257 int (*mdo_unlink)(const struct lu_env *env, struct md_object *pobj,
258 struct md_object *cobj, const struct lu_name *lname,
259 struct md_attr *ma, int no_name);
261 int (*mdo_migrate)(const struct lu_env *env, struct md_object *pobj,
262 struct md_object *sobj, const struct lu_name *lname,
263 struct md_object *tobj, struct md_attr *ma);
266 struct md_device_operations {
267 /** meta-data device related handlers. */
268 int (*mdo_root_get)(const struct lu_env *env, struct md_device *m,
271 int (*mdo_maxeasize_get)(const struct lu_env *env, struct md_device *m,
274 int (*mdo_statfs)(const struct lu_env *env, struct md_device *m,
275 struct obd_statfs *sfs);
277 int (*mdo_llog_ctxt_get)(const struct lu_env *env,
278 struct md_device *m, int idx, void **h);
280 int (*mdo_iocontrol)(const struct lu_env *env, struct md_device *m,
281 unsigned int cmd, int len, void *data);
285 struct lu_device md_lu_dev;
286 const struct md_device_operations *md_ops;
290 struct lu_object mo_lu;
291 const struct md_object_operations *mo_ops;
292 const struct md_dir_operations *mo_dir_ops;
295 static inline struct md_device *lu2md_dev(const struct lu_device *d)
297 LASSERT(IS_ERR(d) || lu_device_is_md(d));
298 return container_of0(d, struct md_device, md_lu_dev);
301 static inline struct lu_device *md2lu_dev(struct md_device *d)
303 return &d->md_lu_dev;
306 static inline struct md_object *lu2md(const struct lu_object *o)
308 LASSERT(o == NULL || IS_ERR(o) || lu_device_is_md(o->lo_dev));
309 return container_of0(o, struct md_object, mo_lu);
312 static inline int md_device_init(struct md_device *md, struct lu_device_type *t)
314 return lu_device_init(&md->md_lu_dev, t);
317 static inline void md_device_fini(struct md_device *md)
319 lu_device_fini(&md->md_lu_dev);
322 static inline struct md_object *md_object_find_slice(const struct lu_env *env,
323 struct md_device *md,
324 const struct lu_fid *f)
326 return lu2md(lu_object_find_slice(env, md2lu_dev(md), f, NULL));
331 static inline int mo_permission(const struct lu_env *env,
337 LASSERT(c->mo_ops->moo_permission);
338 return c->mo_ops->moo_permission(env, p, c, at, mask);
341 static inline int mo_attr_get(const struct lu_env *env,
345 LASSERT(m->mo_ops->moo_attr_get);
346 return m->mo_ops->moo_attr_get(env, m, at);
349 static inline int mo_readlink(const struct lu_env *env,
353 LASSERT(m->mo_ops->moo_readlink);
354 return m->mo_ops->moo_readlink(env, m, buf);
357 static inline int mo_changelog(const struct lu_env *env,
358 enum changelog_rec_type type,
359 int flags, struct md_device *m,
360 const struct lu_fid *fid)
362 struct lu_fid rootfid;
363 struct md_object *root;
366 rc = m->md_ops->mdo_root_get(env, m, &rootfid);
370 root = md_object_find_slice(env, m, &rootfid);
372 RETURN(PTR_ERR(root));
374 LASSERT(root->mo_ops->moo_changelog);
375 rc = root->mo_ops->moo_changelog(env, type, flags, m, fid);
377 lu_object_put(env, &root->mo_lu);
382 static inline int mo_attr_set(const struct lu_env *env,
384 const struct md_attr *at)
386 LASSERT(m->mo_ops->moo_attr_set);
387 return m->mo_ops->moo_attr_set(env, m, at);
390 static inline int mo_xattr_get(const struct lu_env *env,
395 LASSERT(m->mo_ops->moo_xattr_get);
396 return m->mo_ops->moo_xattr_get(env, m, buf, name);
399 static inline int mo_xattr_del(const struct lu_env *env,
403 LASSERT(m->mo_ops->moo_xattr_del);
404 return m->mo_ops->moo_xattr_del(env, m, name);
407 static inline int mo_xattr_set(const struct lu_env *env,
409 const struct lu_buf *buf,
413 LASSERT(m->mo_ops->moo_xattr_set);
414 return m->mo_ops->moo_xattr_set(env, m, buf, name, flags);
417 static inline int mo_xattr_list(const struct lu_env *env,
421 LASSERT(m->mo_ops->moo_xattr_list);
422 return m->mo_ops->moo_xattr_list(env, m, buf);
425 static inline int mo_invalidate(const struct lu_env *env, struct md_object *m)
427 LASSERT(m->mo_ops->moo_invalidate);
428 return m->mo_ops->moo_invalidate(env, m);
431 static inline int mo_swap_layouts(const struct lu_env *env,
432 struct md_object *o1,
433 struct md_object *o2, __u64 flags)
435 LASSERT(o1->mo_ops->moo_swap_layouts);
436 LASSERT(o2->mo_ops->moo_swap_layouts);
437 if (o1->mo_ops->moo_swap_layouts != o2->mo_ops->moo_swap_layouts)
439 return o1->mo_ops->moo_swap_layouts(env, o1, o2, flags);
442 static inline int mo_open(const struct lu_env *env,
446 LASSERT(m->mo_ops->moo_open);
447 return m->mo_ops->moo_open(env, m, flags);
450 static inline int mo_close(const struct lu_env *env,
455 LASSERT(m->mo_ops->moo_close);
456 return m->mo_ops->moo_close(env, m, ma, mode);
459 static inline int mo_readpage(const struct lu_env *env,
461 const struct lu_rdpg *rdpg)
463 LASSERT(m->mo_ops->moo_readpage);
464 return m->mo_ops->moo_readpage(env, m, rdpg);
467 static inline int mo_object_sync(const struct lu_env *env, struct md_object *m)
469 LASSERT(m->mo_ops->moo_object_sync);
470 return m->mo_ops->moo_object_sync(env, m);
473 static inline int mo_object_lock(const struct lu_env *env,
475 struct lustre_handle *lh,
476 struct ldlm_enqueue_info *einfo,
477 union ldlm_policy_data *policy)
479 LASSERT(m->mo_ops->moo_object_lock);
480 return m->mo_ops->moo_object_lock(env, m, lh, einfo, policy);
483 static inline int mo_object_unlock(const struct lu_env *env,
485 struct ldlm_enqueue_info *einfo,
486 union ldlm_policy_data *policy)
488 LASSERT(m->mo_ops->moo_object_unlock);
489 return m->mo_ops->moo_object_unlock(env, m, einfo, policy);
492 static inline int mdo_lookup(const struct lu_env *env,
494 const struct lu_name *lname,
496 struct md_op_spec *spec)
498 LASSERT(p->mo_dir_ops->mdo_lookup);
499 return p->mo_dir_ops->mdo_lookup(env, p, lname, f, spec);
502 static inline mdl_mode_t mdo_lock_mode(const struct lu_env *env,
503 struct md_object *mo,
506 if (mo->mo_dir_ops->mdo_lock_mode == NULL)
508 return mo->mo_dir_ops->mdo_lock_mode(env, mo, lm);
511 static inline int mdo_create(const struct lu_env *env,
513 const struct lu_name *lchild_name,
515 struct md_op_spec *spc,
518 LASSERT(p->mo_dir_ops->mdo_create);
519 return p->mo_dir_ops->mdo_create(env, p, lchild_name, c, spc, at);
522 static inline int mdo_create_data(const struct lu_env *env,
525 const struct md_op_spec *spec,
528 LASSERT(c->mo_dir_ops->mdo_create_data);
529 return c->mo_dir_ops->mdo_create_data(env, p, c, spec, ma);
532 static inline int mdo_rename(const struct lu_env *env,
533 struct md_object *sp,
534 struct md_object *tp,
535 const struct lu_fid *lf,
536 const struct lu_name *lsname,
538 const struct lu_name *ltname,
541 LASSERT(tp->mo_dir_ops->mdo_rename);
542 return tp->mo_dir_ops->mdo_rename(env, sp, tp, lf, lsname, t, ltname,
546 static inline int mdo_migrate(const struct lu_env *env,
547 struct md_object *pobj,
548 struct md_object *sobj,
549 const struct lu_name *lname,
550 struct md_object *tobj,
553 LASSERT(pobj->mo_dir_ops->mdo_migrate);
554 return pobj->mo_dir_ops->mdo_migrate(env, pobj, sobj, lname, tobj, ma);
557 static inline int mdo_is_subdir(const struct lu_env *env,
558 struct md_object *mo,
559 const struct lu_fid *fid,
562 LASSERT(mo->mo_dir_ops->mdo_is_subdir);
563 return mo->mo_dir_ops->mdo_is_subdir(env, mo, fid, sfid);
566 static inline int mdo_link(const struct lu_env *env,
569 const struct lu_name *lname,
572 LASSERT(s->mo_dir_ops->mdo_link);
573 return s->mo_dir_ops->mdo_link(env, p, s, lname, ma);
576 static inline int mdo_unlink(const struct lu_env *env,
579 const struct lu_name *lname,
580 struct md_attr *ma, int no_name)
582 LASSERT(p->mo_dir_ops->mdo_unlink);
583 return p->mo_dir_ops->mdo_unlink(env, p, c, lname, ma, no_name);
587 * Used in MDD/OUT layer for object lock rule
589 enum mdd_object_role {
599 int lustre_buf2hsm(void *buf, int rc, struct md_hsm *mh);
600 void lustre_hsm2buf(void *buf, const struct md_hsm *mh);
619 __u32 uc_suppgids[2];
622 struct group_info *uc_ginfo;
623 struct md_identity *uc_identity;
624 char uc_jobid[LUSTRE_JOBID_SIZE];
627 struct lu_ucred *lu_ucred(const struct lu_env *env);
629 struct lu_ucred *lu_ucred_check(const struct lu_env *env);
631 struct lu_ucred *lu_ucred_assert(const struct lu_env *env);
633 int lu_ucred_global_init(void);
635 void lu_ucred_global_fini(void);
637 #define md_cap_t(x) (x)
639 #define MD_CAP_TO_MASK(x) (1 << (x))
641 #define md_cap_raised(c, flag) (md_cap_t(c) & MD_CAP_TO_MASK(flag))
643 /* capable() is copied from linux kernel! */
644 static inline int md_capable(struct lu_ucred *uc, cfs_cap_t cap)
646 if (md_cap_raised(uc->uc_cap, cap))
652 #endif /* _LINUX_MD_OBJECT_H */