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/mdd/mdd_internal.h
33 * Author: Wang Di <wangdi@clusterfs.com>
36 #ifndef _MDD_INTERNAL_H
37 #define _MDD_INTERNAL_H
39 #include <lustre_acl.h>
40 #include <lustre_compat.h>
41 #include <md_object.h>
42 #include <dt_object.h>
43 #include <lustre_lfsck.h>
44 #include <lustre_fid.h>
45 #include <lprocfs_status.h>
46 #include <lustre_log.h>
47 #include <lustre_linkea.h>
49 /* ChangeLog params for automatic purge mechanism */
50 /* max time allowed for a user to stay idle in seconds */
51 #define CHLOG_MAX_IDLE_TIME 2592000 /* = 30 days */
52 /* max gap allowed for a user to stay idle in number of ChangeLog records
53 * this is an evaluation, assuming that chunk-size is LLOG_MIN_CHUNK_SIZE, of
54 * the indexes gap for half full changelogs */
55 #define CHLOG_MAX_IDLE_INDEXES (((LLOG_MIN_CHUNK_SIZE - \
56 offsetof(struct llog_log_hdr, \
58 sizeof(struct llog_rec_tail)) * 4) * \
59 ((LLOG_MIN_CHUNK_SIZE - \
60 offsetof(struct llog_log_hdr, \
62 sizeof(struct llog_rec_tail)) * 8))
63 /* min time in seconds between two gc thread runs if none already started */
64 #define CHLOG_MIN_GC_INTERVAL 3600
65 /* minimum number of free ChangeLog catalog entries (ie, between cur and
66 * last indexes) before starting garbage collect */
67 #define CHLOG_MIN_FREE_CAT_ENTRIES 2
70 /** changelog is recording */
71 #define CLM_ON 0x00001
72 /** internal error prevented changelogs from starting */
73 #define CLM_ERR 0x00002
75 /** changelogs turned on */
76 #define CLM_START 0x10000
77 /** changelogs turned off */
78 #define CLM_FINI 0x20000
79 /** some changelog records purged */
80 #define CLM_PURGE 0x40000
81 /** changelog cleanup done, to prevent double cleanup */
82 #define CLM_CLEANUP_DONE 0x80000
84 #define LLOG_CHANGELOG_HDR_SZ (sizeof(struct llog_changelog_rec) - \
85 sizeof(struct changelog_rec))
86 /* mc_gc_task values */
87 /** no GC thread to be started **/
88 #define MDD_CHLG_GC_NONE NULL
89 /** a GC thread need to be started **/
90 #define MDD_CHLG_GC_NEED (struct task_struct *)(-1)
91 /** a GC thread will be started now **/
92 #define MDD_CHLG_GC_START (struct task_struct *)(-2)
93 /** else the started task_struct address when running **/
95 struct mdd_changelog {
96 spinlock_t mc_lock; /* for index */
98 __u32 mc_proc_mask; /* per-server mask set via parameters */
99 __u32 mc_current_mask; /* combined global+users */
101 ktime_t mc_starttime;
102 spinlock_t mc_user_lock;
104 int mc_users; /* registered users number */
105 struct task_struct *mc_gc_task;
106 time64_t mc_gc_time; /* last GC check or run time */
107 unsigned int mc_deniednext; /* interval for recording denied
112 static inline __u64 cl_time(void)
114 struct timespec64 time;
116 ktime_get_real_ts64(&time);
117 return (((__u64)time.tv_sec) << 30) + time.tv_nsec;
120 /** Objects in .lustre dir */
121 struct mdd_dot_lustre_objs {
122 struct mdd_object *mdd_obf;
123 struct mdd_object *mdd_lpf;
126 struct mdd_generic_thread {
127 struct completion mgt_started;
128 struct completion mgt_finished;
135 struct md_device mdd_md_dev;
136 struct obd_export *mdd_child_exp;
137 struct dt_device *mdd_child;
138 struct dt_device *mdd_bottom;
139 struct lu_fid mdd_root_fid; /* /ROOT */
140 struct lu_fid mdd_local_root_fid;
141 struct dt_device_param mdd_dt_conf;
142 struct dt_object *mdd_orphans; /* PENDING directory */
143 struct mdd_changelog mdd_cl;
144 unsigned int mdd_changelog_gc;
145 time64_t mdd_changelog_max_idle_time;
146 unsigned long mdd_changelog_max_idle_indexes;
147 time64_t mdd_changelog_min_gc_interval;
148 unsigned int mdd_changelog_min_free_cat_entries;
149 time64_t mdd_atime_diff;
150 struct mdd_object *mdd_dot_lustre;
151 struct mdd_dot_lustre_objs mdd_dot_lustre_objs;
152 unsigned int mdd_sync_permission;
154 int mdd_append_stripe_count;
155 char mdd_append_pool[LOV_MAXPOOLNAME + 1];
156 struct local_oid_storage *mdd_los;
157 struct mdd_generic_thread mdd_orphan_cleanup_thread;
158 struct kobject mdd_kobj;
159 struct kobj_type mdd_ktype;
160 struct completion mdd_kobj_unregister;
164 /* The dir object has been unlinked */
167 VOLATILE_OBJ = BIT(4),
171 struct md_object mod_obj;
176 unsigned long mod_flags;
177 struct list_head mod_users; /**< unique user opens */
180 #define MTI_KEEP_KEY 0x01
182 struct mdd_thread_info {
183 struct lu_fid mti_fid;
184 struct lu_fid mti_fid2; /* used for be & cpu converting */
186 * only be used by MDD interfaces, can be passed into local MDD APIs.
188 struct lu_attr mti_pattr;
189 struct lu_attr mti_cattr;
190 struct lu_attr mti_tpattr;
191 struct lu_attr mti_tattr;
192 /** used to set c/mtime */
193 struct lu_attr mti_la_for_fix;
194 /* Only used in mdd_object_start */
195 struct lu_attr mti_la_for_start;
196 /* mti_ent and mti_key must be conjoint,
197 * then mti_ent::lde_name will be mti_key. */
198 struct lu_dirent mti_ent;
199 char mti_key[NAME_MAX + 16];
201 char mti_name[NAME_MAX + 1];
202 struct lu_buf mti_buf[4];
203 /* persistent buffers, must be handled with lu_buf_alloc/free */
204 struct lu_buf mti_big_buf;
205 struct lu_buf mti_chlg_buf;
206 struct lu_buf mti_link_buf; /* buf for link ea */
207 struct lu_buf mti_xattr_buf;
209 struct dt_allocation_hint mti_hint;
210 struct dt_object_format mti_dof;
211 struct linkea_data mti_link_data;
212 struct md_op_spec mti_spec;
213 struct dt_insert_rec mti_dt_rec;
214 struct lfsck_req_local mti_lrl;
215 struct lu_seq_range mti_range;
216 union lmv_mds_md mti_lmv;
217 struct md_layout_change mti_mlc;
220 int mdd_la_get(const struct lu_env *env, struct mdd_object *obj,
222 int mdd_attr_get(const struct lu_env *env, struct md_object *obj,
224 int mdd_attr_set(const struct lu_env *env, struct md_object *obj,
225 const struct md_attr *ma);
226 int mdd_attr_set_internal(const struct lu_env *env,
227 struct mdd_object *obj,
228 const struct lu_attr *attr,
229 struct thandle *handle,
231 int mdd_update_time(const struct lu_env *env, struct mdd_object *obj,
232 const struct lu_attr *oattr, struct lu_attr *attr,
233 struct thandle *handle);
234 int mdd_create_object_internal(const struct lu_env *env, struct mdd_object *p,
235 struct mdd_object *c, struct lu_attr *attr,
236 struct thandle *handle,
237 const struct md_op_spec *spec,
238 struct dt_allocation_hint *hint);
241 void mdd_write_lock(const struct lu_env *env, struct mdd_object *obj,
242 enum dt_object_role role);
243 void mdd_read_lock(const struct lu_env *env, struct mdd_object *obj,
244 enum dt_object_role role);
245 void mdd_write_unlock(const struct lu_env *env, struct mdd_object *obj);
246 void mdd_read_unlock(const struct lu_env *env, struct mdd_object *obj);
247 int mdd_write_locked(const struct lu_env *env, struct mdd_object *obj);
250 int mdd_may_create(const struct lu_env *env, struct mdd_object *pobj,
251 const struct lu_attr *pattr, struct mdd_object *cobj,
253 int mdd_may_unlink(const struct lu_env *env, struct mdd_object *pobj,
254 const struct lu_attr *pattr, const struct lu_attr *attr);
255 int mdd_may_delete(const struct lu_env *env, struct mdd_object *tpobj,
256 const struct lu_attr *tpattr, struct mdd_object *tobj,
257 const struct lu_attr *tattr, const struct lu_attr *cattr,
258 int check_perm, int check_empty);
259 int mdd_unlink_sanity_check(const struct lu_env *env, struct mdd_object *pobj,
260 const struct lu_attr *pattr,
261 struct mdd_object *cobj,
262 const struct lu_attr *cattr);
263 int mdd_finish_unlink(const struct lu_env *env, struct mdd_object *obj,
264 struct md_attr *ma, struct mdd_object *pobj,
265 const struct lu_name *lname, struct thandle *th);
267 int mdd_is_root(struct mdd_device *mdd, const struct lu_fid *fid);
268 int mdd_lookup(const struct lu_env *env,
269 struct md_object *pobj, const struct lu_name *lname,
270 struct lu_fid* fid, struct md_op_spec *spec);
271 int mdd_links_write(const struct lu_env *env, struct mdd_object *mdd_obj,
272 struct linkea_data *ldata, struct thandle *handle);
273 int mdd_links_read(const struct lu_env *env,
274 struct mdd_object *mdd_obj,
275 struct linkea_data *ldata);
276 struct lu_buf *mdd_links_get(const struct lu_env *env,
277 struct mdd_object *mdd_obj);
278 int mdd_links_rename(const struct lu_env *env,
279 struct mdd_object *mdd_obj,
280 const struct lu_fid *oldpfid,
281 const struct lu_name *oldlname,
282 const struct lu_fid *newpfid,
283 const struct lu_name *newlname,
284 struct thandle *handle,
285 struct linkea_data *ldata,
286 int first, int check);
287 int mdd_dir_layout_shrink(const struct lu_env *env,
288 struct md_object *md_obj,
289 struct md_layout_change *mlc);
290 int mdd_dir_layout_split(const struct lu_env *env, struct md_object *o,
291 struct md_layout_change *mlc);
293 int mdd_changelog_write_rec(const struct lu_env *env,
294 struct llog_handle *loghandle,
295 struct llog_rec_hdr *rec,
296 struct llog_cookie *cookie,
297 int idx, struct thandle *th);
299 struct mdd_thread_info *mdd_env_info(const struct lu_env *env);
301 #define MDD_ENV_VAR(env, var) (&mdd_env_info(env)->mti_##var)
303 struct lu_buf *mdd_buf_get(const struct lu_env *env, void *area, ssize_t len);
304 const struct lu_buf *mdd_buf_get_const(const struct lu_env *env,
305 const void *area, ssize_t len);
307 int mdd_orphan_cleanup(const struct lu_env *env, struct mdd_device *d);
308 int mdd_orphan_insert(const struct lu_env *env, struct mdd_object *obj,
309 struct thandle *thandle);
310 int mdd_orphan_delete(const struct lu_env *env, struct mdd_object *obj,
311 struct thandle *thandle);
312 int mdd_orphan_index_init(const struct lu_env *env, struct mdd_device *mdd);
313 void mdd_orphan_index_fini(const struct lu_env *env, struct mdd_device *mdd);
314 int mdd_orphan_declare_insert(const struct lu_env *env, struct mdd_object *obj,
315 umode_t mode, struct thandle *thandle);
316 int mdd_orphan_declare_delete(const struct lu_env *env, struct mdd_object *obj,
317 struct thandle *thandle);
318 int mdd_dir_is_empty(const struct lu_env *env, struct mdd_object *dir);
321 int mdd_procfs_init(struct mdd_device *mdd, const char *name);
322 void mdd_procfs_fini(struct mdd_device *mdd);
325 extern struct kmem_cache *mdd_object_kmem;
326 extern const struct md_dir_operations mdd_dir_ops;
327 extern const struct md_object_operations mdd_obj_ops;
328 int mdd_readlink(const struct lu_env *env, struct md_object *obj,
330 extern struct lu_context_key mdd_thread_key;
331 extern const struct lu_device_operations mdd_lu_ops;
333 struct mdd_object *mdd_object_find(const struct lu_env *env,
334 struct mdd_device *d,
335 const struct lu_fid *f);
336 int mdd_readpage(const struct lu_env *env, struct md_object *obj,
337 const struct lu_rdpg *rdpg);
338 int mdd_declare_changelog_store(const struct lu_env *env,
339 struct mdd_device *mdd,
340 enum changelog_rec_type type,
341 const struct lu_name *tname,
342 const struct lu_name *sname,
343 struct thandle *handle);
344 void mdd_changelog_rec_ext_jobid(struct changelog_rec *rec, const char *jobid);
345 void mdd_changelog_rec_ext_extra_flags(struct changelog_rec *rec, __u64 eflags);
346 void mdd_changelog_rec_extra_uidgid(struct changelog_rec *rec,
347 __u64 uid, __u64 gid);
348 void mdd_changelog_rec_extra_nid(struct changelog_rec *rec,
350 void mdd_changelog_rec_extra_omode(struct changelog_rec *rec, u32 flags);
351 void mdd_changelog_rec_extra_xattr(struct changelog_rec *rec,
352 const char *xattr_name);
353 int mdd_changelog_store(const struct lu_env *env, struct mdd_device *mdd,
354 struct llog_changelog_rec *rec, struct thandle *th);
355 int mdd_changelog_data_store(const struct lu_env *env, struct mdd_device *mdd,
356 enum changelog_rec_type type,
357 enum changelog_rec_flags clf_flags,
358 struct mdd_object *mdd_obj,
359 struct thandle *handle,
360 const struct lu_fid *pfid);
361 int mdd_changelog_ns_store(const struct lu_env *env, struct mdd_device *mdd,
362 enum changelog_rec_type type,
363 enum changelog_rec_flags clf_flags,
364 struct mdd_object *target,
365 const struct lu_fid *tpfid,
366 const struct lu_fid *sfid,
367 const struct lu_fid *spfid,
368 const struct lu_name *tname,
369 const struct lu_name *sname,
370 struct thandle *handle);
371 int mdd_invalidate(const struct lu_env *env, struct md_object *obj);
372 int mdd_declare_create_object_internal(const struct lu_env *env,
373 struct mdd_object *p,
374 struct mdd_object *c,
375 struct lu_attr *attr,
376 struct thandle *handle,
377 const struct md_op_spec *spec,
378 struct dt_allocation_hint *hint);
379 int mdd_stripe_get(const struct lu_env *env, struct mdd_object *obj,
380 struct lu_buf *lmm_buf, const char *name);
381 int mdd_changelog_data_store_xattr(const struct lu_env *env,
382 struct mdd_device *mdd,
383 enum changelog_rec_type type,
384 enum changelog_rec_flags clf_flags,
385 struct mdd_object *mdd_obj,
386 const char *xattr_name,
387 struct thandle *handle);
390 void mdd_object_make_hint(const struct lu_env *env, struct mdd_object *parent,
391 struct mdd_object *child, const struct lu_attr *attr,
392 const struct md_op_spec *spec,
393 struct dt_allocation_hint *hint);
395 static inline void mdd_object_get(struct mdd_object *o)
397 lu_object_get(&o->mod_obj.mo_lu);
400 static inline void mdd_object_put(const struct lu_env *env,
401 struct mdd_object *o)
403 lu_object_put(env, &o->mod_obj.mo_lu);
406 struct thandle *mdd_trans_create(const struct lu_env *env,
407 struct mdd_device *mdd);
408 int mdd_trans_start(const struct lu_env *env, struct mdd_device *mdd,
410 int mdd_trans_stop(const struct lu_env *env, struct mdd_device *mdd,
411 int rc, struct thandle *handle);
414 struct lu_object *mdd_object_alloc(const struct lu_env *env,
415 const struct lu_object_header *hdr,
416 struct lu_device *d);
417 int mdd_local_file_create(const struct lu_env *env, struct mdd_device *mdd,
418 const struct lu_fid *pfid, const char *name,
419 __u32 mode, struct lu_fid *fid);
421 int mdd_acl_chmod(const struct lu_env *env, struct mdd_object *o, __u32 mode,
422 struct thandle *handle);
423 int mdd_acl_set(const struct lu_env *env, struct mdd_object *obj,
424 struct lu_attr *attr, const struct lu_buf *buf, int fl);
425 int __mdd_fix_mode_acl(const struct lu_env *env, struct lu_buf *buf,
427 int __mdd_permission_internal(const struct lu_env *env, struct mdd_object *obj,
428 const struct lu_attr *la, unsigned int may_mask,
430 int mdd_permission(const struct lu_env *env, struct md_object *pobj,
431 struct md_object *cobj, struct md_attr *ma,
432 unsigned int may_mask);
433 int mdd_generic_thread_start(struct mdd_generic_thread *thread,
434 int (*func)(void *), void *data, char *name);
435 void mdd_generic_thread_stop(struct mdd_generic_thread *thread);
436 int mdd_changelog_user_purge(const struct lu_env *env, struct mdd_device *mdd,
438 char *mdd_chlg_username(struct llog_changelog_user_rec2 *rec, char *buf,
440 __u32 mdd_chlg_usermask(struct llog_changelog_user_rec2 *rec);
441 int mdd_changelog_recalc_mask(const struct lu_env *env, struct mdd_device *mdd);
444 int mdd_compat_fixes(const struct lu_env *env, struct mdd_device *mdd);
447 extern int lustre_posix_acl_permission(struct lu_ucred *mu,
448 const struct lu_attr *la,
449 unsigned int may_mask,
450 posix_acl_xattr_entry *entry,
452 extern int lustre_posix_acl_chmod_masq(posix_acl_xattr_entry *entry,
453 __u32 mode, int count);
454 extern int lustre_posix_acl_create_masq(posix_acl_xattr_entry *entry,
455 __u32 *pmode, int count);
456 extern int lustre_posix_acl_equiv_mode(posix_acl_xattr_entry *entry,
457 mode_t *mode_p, int count);
459 /* inline functions */
460 static inline int lu_device_is_mdd(struct lu_device *d)
462 return ergo(d != NULL && d->ld_ops != NULL, d->ld_ops == &mdd_lu_ops);
465 static inline struct mdd_device *lu2mdd_dev(struct lu_device *d)
467 LASSERT(lu_device_is_mdd(d));
468 return container_of_safe(d, struct mdd_device, mdd_md_dev.md_lu_dev);
471 static inline struct lu_device *mdd2lu_dev(struct mdd_device *mdd)
473 return &mdd->mdd_md_dev.md_lu_dev;
476 static inline struct mdd_object *lu2mdd_obj(struct lu_object *o)
478 LASSERT(ergo(o != NULL, lu_device_is_mdd(o->lo_dev)));
479 return container_of_safe(o, struct mdd_object,
483 static inline struct mdd_device *mdo2mdd(struct md_object *mdo)
485 return lu2mdd_dev(mdo->mo_lu.lo_dev);
488 static inline struct mdd_object *md2mdd_obj(struct md_object *mdo)
490 return container_of_safe(mdo, struct mdd_object, mod_obj);
494 struct dt_device_operations *mdd_child_ops(struct mdd_device *mdd)
496 return mdd->mdd_child->dd_ops;
499 static inline struct lu_object *mdd2lu_obj(struct mdd_object *obj)
501 return &obj->mod_obj.mo_lu;
504 static inline struct dt_object *mdd_object_child(struct mdd_object *obj)
506 return container_of(lu_object_next(mdd2lu_obj(obj)),
507 struct dt_object, do_lu);
510 static inline struct obd_device *mdd2obd_dev(struct mdd_device *mdd)
512 return (mdd->mdd_md_dev.md_lu_dev.ld_obd);
515 static inline struct mdd_device *mdd_obj2mdd_dev(struct mdd_object *obj)
517 return mdo2mdd(&obj->mod_obj);
520 static inline umode_t mdd_object_type(const struct mdd_object *mdd_obj)
522 return lu_object_attr(&mdd_obj->mod_obj.mo_lu);
525 static inline int mdd_is_dead_obj(struct mdd_object *mdd_obj)
527 return mdd_obj && mdd_obj->mod_flags & DEAD_OBJ;
530 static inline bool mdd_is_volatile_obj(struct mdd_object *mdd_obj)
532 return mdd_obj->mod_flags & VOLATILE_OBJ;
535 static inline bool mdd_is_orphan_obj(struct mdd_object *mdd_obj)
537 return mdd_obj->mod_flags & ORPHAN_OBJ;
540 static inline int mdd_object_exists(struct mdd_object *mdd_obj)
542 return lu_object_exists(mdd2lu_obj(mdd_obj));
545 static inline int mdd_object_remote(struct mdd_object *mdd_obj)
547 return lu_object_remote(mdd2lu_obj(mdd_obj));
550 static inline const struct lu_fid *mdd_object_fid(struct mdd_object *mdd_obj)
552 return lu_object_fid(mdd2lu_obj(mdd_obj));
555 static inline struct seq_server_site *mdd_seq_site(struct mdd_device *mdd)
557 return mdd2lu_dev(mdd)->ld_site->ld_seq_site;
560 static inline const char *mdd_obj_dev_name(const struct mdd_object *mdd_obj)
562 return lu_dev_name(mdd_obj->mod_obj.mo_lu.lo_dev);
565 #define MAX_ATIME_DIFF 60
567 static inline int mdd_permission_internal(const struct lu_env *env,
568 struct mdd_object *obj,
569 const struct lu_attr *la,
570 unsigned int may_mask)
572 return __mdd_permission_internal(env, obj, la, may_mask, -1);
575 static inline int mdd_permission_internal_locked(const struct lu_env *env,
576 struct mdd_object *obj,
577 const struct lu_attr *la,
578 unsigned int may_mask,
579 enum dt_object_role role)
581 return __mdd_permission_internal(env, obj, la, may_mask, role);
584 /* mdd inline func for calling osd_dt_object ops */
585 static inline int mdo_attr_get(const struct lu_env *env, struct mdd_object *obj,
588 struct dt_object *next = mdd_object_child(obj);
589 return dt_attr_get(env, next, la);
592 static inline int mdo_declare_attr_set(const struct lu_env *env,
593 struct mdd_object *obj,
594 const struct lu_attr *la,
595 struct thandle *handle)
597 struct dt_object *next = mdd_object_child(obj);
598 return dt_declare_attr_set(env, next, la, handle);
601 static inline int mdo_attr_set(const struct lu_env *env,
602 struct mdd_object *obj,
603 const struct lu_attr *la,
604 struct thandle *handle)
606 struct dt_object *next = mdd_object_child(obj);
608 if (!mdd_object_exists(obj))
611 return dt_attr_set(env, next, la, handle);
614 static inline int mdo_xattr_get(const struct lu_env *env,struct mdd_object *obj,
615 struct lu_buf *buf, const char *name)
617 struct dt_object *next = mdd_object_child(obj);
618 return dt_xattr_get(env, next, buf, name);
621 static inline int mdo_declare_xattr_set(const struct lu_env *env,
622 struct mdd_object *obj,
623 const struct lu_buf *buf,
625 int fl, struct thandle *handle)
627 struct dt_object *next = mdd_object_child(obj);
630 rc = dt_declare_xattr_set(env, next, buf, name, fl, handle);
631 if (rc >= 0 && strcmp(name, LL_XATTR_NAME_ENCRYPTION_CONTEXT) == 0) {
632 struct lu_attr la = { 0 };
634 la.la_valid = LA_FLAGS;
635 la.la_flags = LUSTRE_ENCRYPT_FL;
636 rc = dt_declare_attr_set(env, next, &la, handle);
641 static inline int mdo_xattr_set(const struct lu_env *env,struct mdd_object *obj,
642 const struct lu_buf *buf, const char *name,
643 int fl, struct thandle *handle)
645 struct dt_object *next = mdd_object_child(obj);
648 if (!mdd_object_exists(obj))
651 /* If we are about to set the LL_XATTR_NAME_ENCRYPTION_CONTEXT
652 * xattr, it means the file/dir is encrypted. In that case we want
653 * to set the LUSTRE_ENCRYPT_FL flag as well: it will be stored
654 * into the LMA, making it more efficient to recognise we are
655 * dealing with an encrypted file/dir, as LMA info is cached upon
657 * However, marking a dir as encrypted is only possible if it is
658 * being created or migrated (LU_XATTR_CREATE flag not set), or
661 if ((strcmp(name, LL_XATTR_NAME_ENCRYPTION_CONTEXT) == 0) &&
662 (!S_ISDIR(mdd_object_type(obj)) ||
663 !(fl & LU_XATTR_CREATE) ||
664 (rc = mdd_dir_is_empty(env, obj)) == 0)) {
665 struct lu_attr la = { 0 };
667 la.la_valid = LA_FLAGS;
668 la.la_flags = LUSTRE_ENCRYPT_FL;
669 rc = dt_attr_set(env, next, &la, handle);
672 rc = dt_xattr_set(env, next, buf, name, fl, handle);
677 static inline int mdo_declare_xattr_del(const struct lu_env *env,
678 struct mdd_object *obj,
680 struct thandle *handle)
682 struct dt_object *next = mdd_object_child(obj);
683 return dt_declare_xattr_del(env, next, name, handle);
686 static inline int mdo_xattr_del(const struct lu_env *env,struct mdd_object *obj,
687 const char *name, struct thandle *handle)
689 struct dt_object *next = mdd_object_child(obj);
691 if (!mdd_object_exists(obj))
694 return dt_xattr_del(env, next, name, handle);
698 mdo_xattr_list(const struct lu_env *env, struct mdd_object *obj,
701 struct dt_object *next = mdd_object_child(obj);
703 if (!mdd_object_exists(obj))
706 return dt_xattr_list(env, next, buf);
710 mdo_invalidate(const struct lu_env *env, struct mdd_object *obj)
712 return dt_invalidate(env, mdd_object_child(obj));
716 mdo_declare_layout_change(const struct lu_env *env, struct mdd_object *obj,
717 struct md_layout_change *mlc, struct thandle *handle)
719 return dt_declare_layout_change(env, mdd_object_child(obj),
724 mdo_layout_change(const struct lu_env *env, struct mdd_object *obj,
725 struct md_layout_change *mlc, struct thandle *handle)
727 return dt_layout_change(env, mdd_object_child(obj), mlc, handle);
731 int mdo_declare_index_insert(const struct lu_env *env, struct mdd_object *obj,
732 const struct lu_fid *fid, __u32 type,
733 const char *name, struct thandle *handle)
735 struct dt_object *next = mdd_object_child(obj);
739 * if the object doesn't exist yet, then it's supposed to be created
740 * and declaration of the creation should be enough to insert ./..
744 if (dt_try_as_dir(env, next)) {
745 struct dt_insert_rec *rec = &mdd_env_info(env)->mti_dt_rec;
748 rec->rec_type = type;
749 rc = dt_declare_insert(env, next, (const struct dt_rec *)rec,
750 (const struct dt_key *)name, handle);
757 int mdo_declare_index_delete(const struct lu_env *env, struct mdd_object *obj,
758 const char *name, struct thandle *handle)
760 struct dt_object *next = mdd_object_child(obj);
762 if (!dt_try_as_dir(env, next))
765 return dt_declare_delete(env, next, (const struct dt_key *)name,
769 static inline int mdo_declare_ref_add(const struct lu_env *env,
770 struct mdd_object *obj,
771 struct thandle *handle)
773 struct dt_object *next = mdd_object_child(obj);
774 return dt_declare_ref_add(env, next, handle);
777 static inline int mdo_ref_add(const struct lu_env *env, struct mdd_object *obj,
778 struct thandle *handle)
780 struct dt_object *next = mdd_object_child(obj);
782 if (!mdd_object_exists(obj))
785 return dt_ref_add(env, next, handle);
788 static inline int mdo_declare_ref_del(const struct lu_env *env,
789 struct mdd_object *obj,
790 struct thandle *handle)
792 struct dt_object *next = mdd_object_child(obj);
793 return dt_declare_ref_del(env, next, handle);
796 static inline int mdo_ref_del(const struct lu_env *env, struct mdd_object *obj,
797 struct thandle *handle)
799 struct dt_object *next = mdd_object_child(obj);
801 if (!mdd_object_exists(obj))
804 return dt_ref_del(env, next, handle);
808 mdo_declare_create_object(const struct lu_env *env, struct mdd_object *obj,
809 struct lu_attr *attr, struct dt_allocation_hint *hint,
810 struct dt_object_format *dof, struct thandle *handle)
812 struct dt_object *next = mdd_object_child(obj);
813 return dt_declare_create(env, next, attr, hint, dof, handle);
817 mdo_create_object(const struct lu_env *env, struct mdd_object *obj,
818 struct lu_attr *attr, struct dt_allocation_hint *hint,
819 struct dt_object_format *dof, struct thandle *handle)
821 struct dt_object *next = mdd_object_child(obj);
822 return dt_create(env, next, attr, hint, dof, handle);
826 int mdo_declare_destroy(const struct lu_env *env, struct mdd_object *o,
827 struct thandle *handle)
829 struct dt_object *next = mdd_object_child(o);
830 return dt_declare_destroy(env, next, handle);
834 int mdo_destroy(const struct lu_env *env, struct mdd_object *o,
835 struct thandle *handle)
837 struct dt_object *next = mdd_object_child(o);
838 return dt_destroy(env, next, handle);
841 static inline bool mdd_changelog_enabled(const struct lu_env *env,
842 struct mdd_device *mdd,
843 enum changelog_rec_type type)
845 const struct lu_ucred *uc;
847 if ((mdd->mdd_cl.mc_flags & CLM_ON) &&
848 (mdd->mdd_cl.mc_current_mask & BIT(type))) {
849 uc = lu_ucred_check(env);
851 return uc != NULL ? uc->uc_enable_audit : true;