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/mdd/mdd_internal.h
34 * Author: Wang Di <wangdi@clusterfs.com>
37 #ifndef _MDD_INTERNAL_H
38 #define _MDD_INTERNAL_H
40 #include <lustre_acl.h>
41 #include <lustre_compat.h>
42 #include <md_object.h>
43 #include <dt_object.h>
44 #include <lustre_lfsck.h>
45 #include <lustre_fid.h>
46 #include <lprocfs_status.h>
47 #include <lustre_log.h>
48 #include <lustre_linkea.h>
50 /* ChangeLog params for automatic purge mechanism */
51 /* max time allowed for a user to stay idle in seconds */
52 #define CHLOG_MAX_IDLE_TIME 2592000 /* = 30 days */
53 /* max gap allowed for a user to stay idle in number of ChangeLog records
54 * this is an evaluation, assuming that chunk-size is LLOG_MIN_CHUNK_SIZE, of
55 * the indexes gap for half full changelogs */
56 #define CHLOG_MAX_IDLE_INDEXES (((LLOG_MIN_CHUNK_SIZE - \
57 offsetof(struct llog_log_hdr, \
59 sizeof(struct llog_rec_tail)) * 4) * \
60 ((LLOG_MIN_CHUNK_SIZE - \
61 offsetof(struct llog_log_hdr, \
63 sizeof(struct llog_rec_tail)) * 8))
64 /* min time in seconds between two gc thread runs if none already started */
65 #define CHLOG_MIN_GC_INTERVAL 3600
66 /* minimum number of free ChangeLog catalog entries (ie, between cur and
67 * last indexes) before starting garbage collect */
68 #define CHLOG_MIN_FREE_CAT_ENTRIES 2
71 /** changelog is recording */
72 #define CLM_ON 0x00001
73 /** internal error prevented changelogs from starting */
74 #define CLM_ERR 0x00002
76 /** changelogs turned on */
77 #define CLM_START 0x10000
78 /** changelogs turned off */
79 #define CLM_FINI 0x20000
80 /** some changelog records purged */
81 #define CLM_PURGE 0x40000
82 /** changelog cleanup done, to prevent double cleanup */
83 #define CLM_CLEANUP_DONE 0x80000
85 #define LLOG_CHANGELOG_HDR_SZ (sizeof(struct llog_changelog_rec) - \
86 sizeof(struct changelog_rec))
87 /* mc_gc_task values */
88 /** no GC thread to be started **/
89 #define MDD_CHLG_GC_NONE NULL
90 /** a GC thread need to be started **/
91 #define MDD_CHLG_GC_NEED (struct task_struct *)(-1)
92 /** a GC thread will be started now **/
93 #define MDD_CHLG_GC_START (struct task_struct *)(-2)
94 /** else the started task_struct address when running **/
96 struct mdd_changelog {
97 spinlock_t mc_lock; /* for index */
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 struct lu_buf mti_big_buf; /* biggish persistent buf */
204 struct lu_buf mti_link_buf; /* buf for link ea */
205 struct lu_buf mti_xattr_buf;
207 struct dt_allocation_hint mti_hint;
208 struct dt_object_format mti_dof;
209 struct linkea_data mti_link_data;
210 struct md_op_spec mti_spec;
211 struct dt_insert_rec mti_dt_rec;
212 struct lfsck_req_local mti_lrl;
213 struct lu_seq_range mti_range;
214 union lmv_mds_md mti_lmv;
215 struct md_layout_change mti_mlc;
218 int mdd_la_get(const struct lu_env *env, struct mdd_object *obj,
220 int mdd_attr_get(const struct lu_env *env, struct md_object *obj,
222 int mdd_attr_set(const struct lu_env *env, struct md_object *obj,
223 const struct md_attr *ma);
224 int mdd_attr_set_internal(const struct lu_env *env,
225 struct mdd_object *obj,
226 const struct lu_attr *attr,
227 struct thandle *handle,
229 int mdd_update_time(const struct lu_env *env, struct mdd_object *obj,
230 const struct lu_attr *oattr, struct lu_attr *attr,
231 struct thandle *handle);
232 int mdd_create_object_internal(const struct lu_env *env, struct mdd_object *p,
233 struct mdd_object *c, struct lu_attr *attr,
234 struct thandle *handle,
235 const struct md_op_spec *spec,
236 struct dt_allocation_hint *hint);
239 void mdd_write_lock(const struct lu_env *env, struct mdd_object *obj,
240 enum dt_object_role role);
241 void mdd_read_lock(const struct lu_env *env, struct mdd_object *obj,
242 enum dt_object_role role);
243 void mdd_write_unlock(const struct lu_env *env, struct mdd_object *obj);
244 void mdd_read_unlock(const struct lu_env *env, struct mdd_object *obj);
245 int mdd_write_locked(const struct lu_env *env, struct mdd_object *obj);
248 int mdd_may_create(const struct lu_env *env, struct mdd_object *pobj,
249 const struct lu_attr *pattr, struct mdd_object *cobj,
251 int mdd_may_unlink(const struct lu_env *env, struct mdd_object *pobj,
252 const struct lu_attr *pattr, const struct lu_attr *attr);
253 int mdd_may_delete(const struct lu_env *env, struct mdd_object *tpobj,
254 const struct lu_attr *tpattr, struct mdd_object *tobj,
255 const struct lu_attr *tattr, const struct lu_attr *cattr,
256 int check_perm, int check_empty);
257 int mdd_unlink_sanity_check(const struct lu_env *env, struct mdd_object *pobj,
258 const struct lu_attr *pattr,
259 struct mdd_object *cobj,
260 const struct lu_attr *cattr);
261 int mdd_finish_unlink(const struct lu_env *env, struct mdd_object *obj,
262 struct md_attr *ma, struct mdd_object *pobj,
263 const struct lu_name *lname, struct thandle *th);
265 int mdd_is_root(struct mdd_device *mdd, const struct lu_fid *fid);
266 int mdd_lookup(const struct lu_env *env,
267 struct md_object *pobj, const struct lu_name *lname,
268 struct lu_fid* fid, struct md_op_spec *spec);
269 int mdd_links_write(const struct lu_env *env, struct mdd_object *mdd_obj,
270 struct linkea_data *ldata, struct thandle *handle);
271 int mdd_links_read(const struct lu_env *env,
272 struct mdd_object *mdd_obj,
273 struct linkea_data *ldata);
274 struct lu_buf *mdd_links_get(const struct lu_env *env,
275 struct mdd_object *mdd_obj);
276 int mdd_links_rename(const struct lu_env *env,
277 struct mdd_object *mdd_obj,
278 const struct lu_fid *oldpfid,
279 const struct lu_name *oldlname,
280 const struct lu_fid *newpfid,
281 const struct lu_name *newlname,
282 struct thandle *handle,
283 struct linkea_data *ldata,
284 int first, int check);
285 int mdd_dir_layout_shrink(const struct lu_env *env,
286 struct md_object *md_obj,
287 struct md_layout_change *mlc);
288 int mdd_dir_layout_split(const struct lu_env *env, struct md_object *o,
289 struct md_layout_change *mlc);
291 int mdd_changelog_write_rec(const struct lu_env *env,
292 struct llog_handle *loghandle,
293 struct llog_rec_hdr *rec,
294 struct llog_cookie *cookie,
295 int idx, struct thandle *th);
297 struct mdd_thread_info *mdd_env_info(const struct lu_env *env);
299 #define MDD_ENV_VAR(env, var) (&mdd_env_info(env)->mti_##var)
301 struct lu_buf *mdd_buf_get(const struct lu_env *env, void *area, ssize_t len);
302 const struct lu_buf *mdd_buf_get_const(const struct lu_env *env,
303 const void *area, ssize_t len);
305 int mdd_orphan_cleanup(const struct lu_env *env, struct mdd_device *d);
306 int mdd_orphan_insert(const struct lu_env *env, struct mdd_object *obj,
307 struct thandle *thandle);
308 int mdd_orphan_delete(const struct lu_env *env, struct mdd_object *obj,
309 struct thandle *thandle);
310 int mdd_orphan_index_init(const struct lu_env *env, struct mdd_device *mdd);
311 void mdd_orphan_index_fini(const struct lu_env *env, struct mdd_device *mdd);
312 int mdd_orphan_declare_insert(const struct lu_env *env, struct mdd_object *obj,
313 umode_t mode, struct thandle *thandle);
314 int mdd_orphan_declare_delete(const struct lu_env *env, struct mdd_object *obj,
315 struct thandle *thandle);
316 int mdd_dir_is_empty(const struct lu_env *env, struct mdd_object *dir);
319 int mdd_procfs_init(struct mdd_device *mdd, const char *name);
320 void mdd_procfs_fini(struct mdd_device *mdd);
323 extern struct kmem_cache *mdd_object_kmem;
324 extern const struct md_dir_operations mdd_dir_ops;
325 extern const struct md_object_operations mdd_obj_ops;
326 int mdd_readlink(const struct lu_env *env, struct md_object *obj,
328 extern struct lu_context_key mdd_thread_key;
329 extern const struct lu_device_operations mdd_lu_ops;
331 struct mdd_object *mdd_object_find(const struct lu_env *env,
332 struct mdd_device *d,
333 const struct lu_fid *f);
334 int mdd_readpage(const struct lu_env *env, struct md_object *obj,
335 const struct lu_rdpg *rdpg);
336 int mdd_declare_changelog_store(const struct lu_env *env,
337 struct mdd_device *mdd,
338 enum changelog_rec_type type,
339 const struct lu_name *tname,
340 const struct lu_name *sname,
341 struct thandle *handle);
342 void mdd_changelog_rec_ext_jobid(struct changelog_rec *rec, const char *jobid);
343 void mdd_changelog_rec_ext_extra_flags(struct changelog_rec *rec, __u64 eflags);
344 void mdd_changelog_rec_extra_uidgid(struct changelog_rec *rec,
345 __u64 uid, __u64 gid);
346 void mdd_changelog_rec_extra_nid(struct changelog_rec *rec,
348 void mdd_changelog_rec_extra_omode(struct changelog_rec *rec, u32 flags);
349 void mdd_changelog_rec_extra_xattr(struct changelog_rec *rec,
350 const char *xattr_name);
351 int mdd_changelog_store(const struct lu_env *env, struct mdd_device *mdd,
352 struct llog_changelog_rec *rec, struct thandle *th);
353 int mdd_changelog_data_store(const struct lu_env *env, struct mdd_device *mdd,
354 enum changelog_rec_type type,
355 enum changelog_rec_flags clf_flags,
356 struct mdd_object *mdd_obj,
357 struct thandle *handle,
358 const struct lu_fid *pfid);
359 int mdd_changelog_ns_store(const struct lu_env *env, struct mdd_device *mdd,
360 enum changelog_rec_type type,
361 enum changelog_rec_flags clf_flags,
362 struct mdd_object *target,
363 const struct lu_fid *tpfid,
364 const struct lu_fid *sfid,
365 const struct lu_fid *spfid,
366 const struct lu_name *tname,
367 const struct lu_name *sname,
368 struct thandle *handle);
369 int mdd_invalidate(const struct lu_env *env, struct md_object *obj);
370 int mdd_declare_create_object_internal(const struct lu_env *env,
371 struct mdd_object *p,
372 struct mdd_object *c,
373 struct lu_attr *attr,
374 struct thandle *handle,
375 const struct md_op_spec *spec,
376 struct dt_allocation_hint *hint);
377 int mdd_stripe_get(const struct lu_env *env, struct mdd_object *obj,
378 struct lu_buf *lmm_buf, const char *name);
379 int mdd_changelog_data_store_xattr(const struct lu_env *env,
380 struct mdd_device *mdd,
381 enum changelog_rec_type type,
382 enum changelog_rec_flags clf_flags,
383 struct mdd_object *mdd_obj,
384 const char *xattr_name,
385 struct thandle *handle);
388 void mdd_object_make_hint(const struct lu_env *env, struct mdd_object *parent,
389 struct mdd_object *child, const struct lu_attr *attr,
390 const struct md_op_spec *spec,
391 struct dt_allocation_hint *hint);
393 static inline void mdd_object_get(struct mdd_object *o)
395 lu_object_get(&o->mod_obj.mo_lu);
398 static inline void mdd_object_put(const struct lu_env *env,
399 struct mdd_object *o)
401 lu_object_put(env, &o->mod_obj.mo_lu);
404 struct thandle *mdd_trans_create(const struct lu_env *env,
405 struct mdd_device *mdd);
406 int mdd_trans_start(const struct lu_env *env, struct mdd_device *mdd,
408 int mdd_trans_stop(const struct lu_env *env, struct mdd_device *mdd,
409 int rc, struct thandle *handle);
412 struct lu_object *mdd_object_alloc(const struct lu_env *env,
413 const struct lu_object_header *hdr,
414 struct lu_device *d);
415 int mdd_local_file_create(const struct lu_env *env, struct mdd_device *mdd,
416 const struct lu_fid *pfid, const char *name,
417 __u32 mode, struct lu_fid *fid);
419 int mdd_acl_chmod(const struct lu_env *env, struct mdd_object *o, __u32 mode,
420 struct thandle *handle);
421 int mdd_acl_set(const struct lu_env *env, struct mdd_object *obj,
422 struct lu_attr *attr, const struct lu_buf *buf, int fl);
423 int __mdd_fix_mode_acl(const struct lu_env *env, struct lu_buf *buf,
425 int __mdd_permission_internal(const struct lu_env *env, struct mdd_object *obj,
426 const struct lu_attr *la, unsigned int may_mask,
428 int mdd_permission(const struct lu_env *env, struct md_object *pobj,
429 struct md_object *cobj, struct md_attr *ma,
430 unsigned int may_mask);
431 int mdd_generic_thread_start(struct mdd_generic_thread *thread,
432 int (*func)(void *), void *data, char *name);
433 void mdd_generic_thread_stop(struct mdd_generic_thread *thread);
434 int mdd_changelog_user_purge(const struct lu_env *env, struct mdd_device *mdd,
438 int mdd_compat_fixes(const struct lu_env *env, struct mdd_device *mdd);
441 extern int lustre_posix_acl_permission(struct lu_ucred *mu,
442 const struct lu_attr *la,
443 unsigned int may_mask,
444 posix_acl_xattr_entry *entry,
446 extern int lustre_posix_acl_chmod_masq(posix_acl_xattr_entry *entry,
447 __u32 mode, int count);
448 extern int lustre_posix_acl_create_masq(posix_acl_xattr_entry *entry,
449 __u32 *pmode, int count);
450 extern int lustre_posix_acl_equiv_mode(posix_acl_xattr_entry *entry,
451 mode_t *mode_p, int count);
453 /* inline functions */
454 static inline int lu_device_is_mdd(struct lu_device *d)
456 return ergo(d != NULL && d->ld_ops != NULL, d->ld_ops == &mdd_lu_ops);
459 static inline struct mdd_device *lu2mdd_dev(struct lu_device *d)
461 LASSERT(lu_device_is_mdd(d));
462 return container_of_safe(d, struct mdd_device, mdd_md_dev.md_lu_dev);
465 static inline struct lu_device *mdd2lu_dev(struct mdd_device *mdd)
467 return &mdd->mdd_md_dev.md_lu_dev;
470 static inline struct mdd_object *lu2mdd_obj(struct lu_object *o)
472 LASSERT(ergo(o != NULL, lu_device_is_mdd(o->lo_dev)));
473 return container_of_safe(o, struct mdd_object,
477 static inline struct mdd_device *mdo2mdd(struct md_object *mdo)
479 return lu2mdd_dev(mdo->mo_lu.lo_dev);
482 static inline struct mdd_object *md2mdd_obj(struct md_object *mdo)
484 return container_of_safe(mdo, struct mdd_object, mod_obj);
488 struct dt_device_operations *mdd_child_ops(struct mdd_device *mdd)
490 return mdd->mdd_child->dd_ops;
493 static inline struct lu_object *mdd2lu_obj(struct mdd_object *obj)
495 return &obj->mod_obj.mo_lu;
498 static inline struct dt_object *mdd_object_child(struct mdd_object *obj)
500 return container_of(lu_object_next(mdd2lu_obj(obj)),
501 struct dt_object, do_lu);
504 static inline struct obd_device *mdd2obd_dev(struct mdd_device *mdd)
506 return (mdd->mdd_md_dev.md_lu_dev.ld_obd);
509 static inline struct mdd_device *mdd_obj2mdd_dev(struct mdd_object *obj)
511 return mdo2mdd(&obj->mod_obj);
514 static inline umode_t mdd_object_type(const struct mdd_object *mdd_obj)
516 return lu_object_attr(&mdd_obj->mod_obj.mo_lu);
519 static inline int mdd_is_dead_obj(struct mdd_object *mdd_obj)
521 return mdd_obj && mdd_obj->mod_flags & DEAD_OBJ;
524 static inline bool mdd_is_volatile_obj(struct mdd_object *mdd_obj)
526 return mdd_obj->mod_flags & VOLATILE_OBJ;
529 static inline bool mdd_is_orphan_obj(struct mdd_object *mdd_obj)
531 return mdd_obj->mod_flags & ORPHAN_OBJ;
534 static inline int mdd_object_exists(struct mdd_object *mdd_obj)
536 return lu_object_exists(mdd2lu_obj(mdd_obj));
539 static inline int mdd_object_remote(struct mdd_object *mdd_obj)
541 return lu_object_remote(mdd2lu_obj(mdd_obj));
544 static inline const struct lu_fid *mdd_object_fid(struct mdd_object *mdd_obj)
546 return lu_object_fid(mdd2lu_obj(mdd_obj));
549 static inline struct seq_server_site *mdd_seq_site(struct mdd_device *mdd)
551 return mdd2lu_dev(mdd)->ld_site->ld_seq_site;
554 static inline const char *mdd_obj_dev_name(const struct mdd_object *mdd_obj)
556 return lu_dev_name(mdd_obj->mod_obj.mo_lu.lo_dev);
559 #define MAX_ATIME_DIFF 60
561 static inline int mdd_permission_internal(const struct lu_env *env,
562 struct mdd_object *obj,
563 const struct lu_attr *la,
564 unsigned int may_mask)
566 return __mdd_permission_internal(env, obj, la, may_mask, -1);
569 static inline int mdd_permission_internal_locked(const struct lu_env *env,
570 struct mdd_object *obj,
571 const struct lu_attr *la,
572 unsigned int may_mask,
573 enum dt_object_role role)
575 return __mdd_permission_internal(env, obj, la, may_mask, role);
578 /* mdd inline func for calling osd_dt_object ops */
579 static inline int mdo_attr_get(const struct lu_env *env, struct mdd_object *obj,
582 struct dt_object *next = mdd_object_child(obj);
583 return dt_attr_get(env, next, la);
586 static inline int mdo_declare_attr_set(const struct lu_env *env,
587 struct mdd_object *obj,
588 const struct lu_attr *la,
589 struct thandle *handle)
591 struct dt_object *next = mdd_object_child(obj);
592 return dt_declare_attr_set(env, next, la, handle);
595 static inline int mdo_attr_set(const struct lu_env *env,
596 struct mdd_object *obj,
597 const struct lu_attr *la,
598 struct thandle *handle)
600 struct dt_object *next = mdd_object_child(obj);
602 if (!mdd_object_exists(obj))
605 return dt_attr_set(env, next, la, handle);
608 static inline int mdo_xattr_get(const struct lu_env *env,struct mdd_object *obj,
609 struct lu_buf *buf, const char *name)
611 struct dt_object *next = mdd_object_child(obj);
612 return dt_xattr_get(env, next, buf, name);
615 static inline int mdo_declare_xattr_set(const struct lu_env *env,
616 struct mdd_object *obj,
617 const struct lu_buf *buf,
619 int fl, struct thandle *handle)
621 struct dt_object *next = mdd_object_child(obj);
624 rc = dt_declare_xattr_set(env, next, buf, name, fl, handle);
625 if (rc >= 0 && strcmp(name, LL_XATTR_NAME_ENCRYPTION_CONTEXT) == 0) {
626 struct lu_attr la = { 0 };
628 la.la_valid = LA_FLAGS;
629 la.la_flags = LUSTRE_ENCRYPT_FL;
630 rc = dt_declare_attr_set(env, next, &la, handle);
635 static inline int mdo_xattr_set(const struct lu_env *env,struct mdd_object *obj,
636 const struct lu_buf *buf, const char *name,
637 int fl, struct thandle *handle)
639 struct dt_object *next = mdd_object_child(obj);
642 if (!mdd_object_exists(obj))
645 /* If we are about to set the LL_XATTR_NAME_ENCRYPTION_CONTEXT
646 * xattr, it means the file/dir is encrypted. In that case we want
647 * to set the LUSTRE_ENCRYPT_FL flag as well: it will be stored
648 * into the LMA, making it more efficient to recognise we are
649 * dealing with an encrypted file/dir, as LMA info is cached upon
651 * However, marking a dir as encrypted is only possible if it is
652 * being created or migrated (LU_XATTR_CREATE flag not set), or
655 if ((strcmp(name, LL_XATTR_NAME_ENCRYPTION_CONTEXT) == 0) &&
656 (!S_ISDIR(mdd_object_type(obj)) ||
657 !(fl & LU_XATTR_CREATE) ||
658 (rc = mdd_dir_is_empty(env, obj)) == 0)) {
659 struct lu_attr la = { 0 };
661 la.la_valid = LA_FLAGS;
662 la.la_flags = LUSTRE_ENCRYPT_FL;
663 rc = dt_attr_set(env, next, &la, handle);
666 rc = dt_xattr_set(env, next, buf, name, fl, handle);
671 static inline int mdo_declare_xattr_del(const struct lu_env *env,
672 struct mdd_object *obj,
674 struct thandle *handle)
676 struct dt_object *next = mdd_object_child(obj);
677 return dt_declare_xattr_del(env, next, name, handle);
680 static inline int mdo_xattr_del(const struct lu_env *env,struct mdd_object *obj,
681 const char *name, struct thandle *handle)
683 struct dt_object *next = mdd_object_child(obj);
685 if (!mdd_object_exists(obj))
688 return dt_xattr_del(env, next, name, handle);
692 mdo_xattr_list(const struct lu_env *env, struct mdd_object *obj,
695 struct dt_object *next = mdd_object_child(obj);
697 if (!mdd_object_exists(obj))
700 return dt_xattr_list(env, next, buf);
704 mdo_invalidate(const struct lu_env *env, struct mdd_object *obj)
706 return dt_invalidate(env, mdd_object_child(obj));
710 mdo_declare_layout_change(const struct lu_env *env, struct mdd_object *obj,
711 struct md_layout_change *mlc, struct thandle *handle)
713 return dt_declare_layout_change(env, mdd_object_child(obj),
718 mdo_layout_change(const struct lu_env *env, struct mdd_object *obj,
719 struct md_layout_change *mlc, struct thandle *handle)
721 return dt_layout_change(env, mdd_object_child(obj), mlc, handle);
725 int mdo_declare_index_insert(const struct lu_env *env, struct mdd_object *obj,
726 const struct lu_fid *fid, __u32 type,
727 const char *name, struct thandle *handle)
729 struct dt_object *next = mdd_object_child(obj);
733 * if the object doesn't exist yet, then it's supposed to be created
734 * and declaration of the creation should be enough to insert ./..
738 if (dt_try_as_dir(env, next)) {
739 struct dt_insert_rec *rec = &mdd_env_info(env)->mti_dt_rec;
742 rec->rec_type = type;
743 rc = dt_declare_insert(env, next, (const struct dt_rec *)rec,
744 (const struct dt_key *)name, handle);
751 int mdo_declare_index_delete(const struct lu_env *env, struct mdd_object *obj,
752 const char *name, struct thandle *handle)
754 struct dt_object *next = mdd_object_child(obj);
756 if (!dt_try_as_dir(env, next))
759 return dt_declare_delete(env, next, (const struct dt_key *)name,
763 static inline int mdo_declare_ref_add(const struct lu_env *env,
764 struct mdd_object *obj,
765 struct thandle *handle)
767 struct dt_object *next = mdd_object_child(obj);
768 return dt_declare_ref_add(env, next, handle);
771 static inline int mdo_ref_add(const struct lu_env *env, struct mdd_object *obj,
772 struct thandle *handle)
774 struct dt_object *next = mdd_object_child(obj);
776 if (!mdd_object_exists(obj))
779 return dt_ref_add(env, next, handle);
782 static inline int mdo_declare_ref_del(const struct lu_env *env,
783 struct mdd_object *obj,
784 struct thandle *handle)
786 struct dt_object *next = mdd_object_child(obj);
787 return dt_declare_ref_del(env, next, handle);
790 static inline int mdo_ref_del(const struct lu_env *env, struct mdd_object *obj,
791 struct thandle *handle)
793 struct dt_object *next = mdd_object_child(obj);
795 if (!mdd_object_exists(obj))
798 return dt_ref_del(env, next, handle);
802 mdo_declare_create_object(const struct lu_env *env, struct mdd_object *obj,
803 struct lu_attr *attr, struct dt_allocation_hint *hint,
804 struct dt_object_format *dof, struct thandle *handle)
806 struct dt_object *next = mdd_object_child(obj);
807 return dt_declare_create(env, next, attr, hint, dof, handle);
811 mdo_create_object(const struct lu_env *env, struct mdd_object *obj,
812 struct lu_attr *attr, struct dt_allocation_hint *hint,
813 struct dt_object_format *dof, struct thandle *handle)
815 struct dt_object *next = mdd_object_child(obj);
816 return dt_create(env, next, attr, hint, dof, handle);
820 int mdo_declare_destroy(const struct lu_env *env, struct mdd_object *o,
821 struct thandle *handle)
823 struct dt_object *next = mdd_object_child(o);
824 return dt_declare_destroy(env, next, handle);
828 int mdo_destroy(const struct lu_env *env, struct mdd_object *o,
829 struct thandle *handle)
831 struct dt_object *next = mdd_object_child(o);
832 return dt_destroy(env, next, handle);
835 static inline bool mdd_changelog_enabled(const struct lu_env *env,
836 struct mdd_device *mdd,
837 enum changelog_rec_type type)
839 const struct lu_ucred *uc;
841 if ((mdd->mdd_cl.mc_flags & CLM_ON) &&
842 (mdd->mdd_cl.mc_mask & BIT(type))) {
843 uc = lu_ucred_check(env);
845 return uc != NULL ? uc->uc_enable_audit : true;