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.sun.com/software/products/lustre/docs/GPLv2.pdf
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
27 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2011, 2014, Intel Corporation.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * lustre/mdd/mdd_internal.h
38 * Author: Wang Di <wangdi@clusterfs.com>
41 #ifndef _MDD_INTERNAL_H
42 #define _MDD_INTERNAL_H
44 #include <lustre_acl.h>
45 #include <lustre_eacl.h>
46 #include <md_object.h>
47 #include <dt_object.h>
48 #include <lustre_lfsck.h>
49 #include <lustre_fid.h>
50 #include <lprocfs_status.h>
51 #include <lustre_log.h>
52 #include <lustre_linkea.h>
55 /** changelog is recording */
56 #define CLM_ON 0x00001
57 /** internal error prevented changelogs from starting */
58 #define CLM_ERR 0x00002
60 /** changelogs turned on */
61 #define CLM_START 0x10000
62 /** changelogs turned off */
63 #define CLM_FINI 0x20000
64 /** some changelog records purged */
65 #define CLM_PURGE 0x40000
67 struct mdd_changelog {
68 spinlock_t mc_lock; /* for index */
73 spinlock_t mc_user_lock;
77 static inline __u64 cl_time(void) {
80 cfs_fs_time_current(&time);
81 return (((__u64)time.tv_sec) << 30) + time.tv_nsec;
84 /** Objects in .lustre dir */
85 struct mdd_dot_lustre_objs {
86 struct mdd_object *mdd_obf;
87 struct mdd_object *mdd_lpf;
90 struct mdd_generic_thread {
91 struct completion mgt_started;
92 struct completion mgt_finished;
99 struct md_device mdd_md_dev;
100 struct obd_export *mdd_child_exp;
101 struct dt_device *mdd_child;
102 struct dt_device *mdd_bottom;
103 struct lu_fid mdd_root_fid; /* /ROOT */
104 struct lu_fid mdd_local_root_fid;
105 struct dt_device_param mdd_dt_conf;
106 struct dt_object *mdd_orphans; /* PENDING directory */
107 struct proc_dir_entry *mdd_proc_entry;
108 struct mdd_changelog mdd_cl;
109 unsigned long mdd_atime_diff;
110 struct mdd_object *mdd_dot_lustre;
111 struct mdd_dot_lustre_objs mdd_dot_lustre_objs;
112 unsigned int mdd_sync_permission;
114 struct local_oid_storage *mdd_los;
115 struct mdd_generic_thread mdd_orph_cleanup_thread;
119 /* The dir object has been unlinked */
125 struct md_object mod_obj;
130 unsigned long mod_flags;
133 struct mdd_thread_info {
134 struct lu_fid mti_fid;
135 struct lu_fid mti_fid2; /* used for be & cpu converting */
137 * only be used by MDD interfaces, can be passed into local MDD APIs.
139 struct lu_attr mti_pattr;
140 struct lu_attr mti_cattr;
141 struct lu_attr mti_tpattr;
142 struct lu_attr mti_tattr;
143 /** used to set c/mtime */
144 struct lu_attr mti_la_for_fix;
145 /* Only used in mdd_object_start */
146 struct lu_attr mti_la_for_start;
147 /* mti_ent and mti_key must be conjoint,
148 * then mti_ent::lde_name will be mti_key. */
149 struct lu_dirent mti_ent;
150 char mti_key[NAME_MAX + 16];
151 struct lu_buf mti_buf[4];
152 struct lu_buf mti_big_buf; /* biggish persistent buf */
153 struct lu_buf mti_link_buf; /* buf for link ea */
155 char mti_xattr_buf[LUSTRE_POSIX_ACL_MAX_SIZE];
156 struct dt_allocation_hint mti_hint;
157 struct dt_object_format mti_dof;
158 struct linkea_data mti_link_data;
159 struct md_op_spec mti_spec;
160 struct dt_insert_rec mti_dt_rec;
161 struct lfsck_request mti_lr;
162 struct lu_seq_range mti_range;
165 enum mdd_links_add_overflow {
170 extern const char orph_index_name[];
172 int mdd_la_get(const struct lu_env *env, struct mdd_object *obj,
174 int mdd_attr_get(const struct lu_env *env, struct md_object *obj,
176 int mdd_attr_set(const struct lu_env *env, struct md_object *obj,
177 const struct md_attr *ma);
178 int mdd_attr_set_internal(const struct lu_env *env,
179 struct mdd_object *obj,
180 const struct lu_attr *attr,
181 struct thandle *handle,
183 int mdd_update_time(const struct lu_env *env, struct mdd_object *obj,
184 const struct lu_attr *oattr, struct lu_attr *attr,
185 struct thandle *handle);
186 int mdd_object_create_internal(const struct lu_env *env, struct mdd_object *p,
187 struct mdd_object *c, struct lu_attr *attr,
188 struct thandle *handle,
189 const struct md_op_spec *spec,
190 struct dt_allocation_hint *hint);
193 void mdd_write_lock(const struct lu_env *env, struct mdd_object *obj,
194 enum mdd_object_role role);
195 void mdd_read_lock(const struct lu_env *env, struct mdd_object *obj,
196 enum mdd_object_role role);
197 void mdd_write_unlock(const struct lu_env *env, struct mdd_object *obj);
198 void mdd_read_unlock(const struct lu_env *env, struct mdd_object *obj);
199 int mdd_write_locked(const struct lu_env *env, struct mdd_object *obj);
202 int mdd_is_subdir(const struct lu_env *env, struct md_object *mo,
203 const struct lu_fid *fid, struct lu_fid *sfid);
204 int mdd_may_create(const struct lu_env *env, struct mdd_object *pobj,
205 const struct lu_attr *pattr, struct mdd_object *cobj,
207 int mdd_may_unlink(const struct lu_env *env, struct mdd_object *pobj,
208 const struct lu_attr *pattr, const struct lu_attr *attr);
209 int mdd_may_delete(const struct lu_env *env, struct mdd_object *tpobj,
210 const struct lu_attr *tpattr, struct mdd_object *tobj,
211 const struct lu_attr *tattr, const struct lu_attr *cattr,
212 int check_perm, int check_empty);
213 int mdd_unlink_sanity_check(const struct lu_env *env, struct mdd_object *pobj,
214 const struct lu_attr *pattr,
215 struct mdd_object *cobj,
216 const struct lu_attr *cattr);
217 int mdd_finish_unlink(const struct lu_env *env, struct mdd_object *obj,
218 struct md_attr *ma, const struct mdd_object *pobj,
219 const struct lu_name *lname, struct thandle *th);
221 int mdd_is_root(struct mdd_device *mdd, const struct lu_fid *fid);
222 int mdd_lookup(const struct lu_env *env,
223 struct md_object *pobj, const struct lu_name *lname,
224 struct lu_fid* fid, struct md_op_spec *spec);
225 int mdd_links_read(const struct lu_env *env, struct mdd_object *mdd_obj,
226 struct linkea_data *ldata);
227 int mdd_declare_links_add(const struct lu_env *env, struct mdd_object *mdd_obj,
228 struct thandle *handle, struct linkea_data *ldata,
229 enum mdd_links_add_overflow overflow);
230 int mdd_links_write(const struct lu_env *env, struct mdd_object *mdd_obj,
231 struct linkea_data *ldata, struct thandle *handle);
232 struct lu_buf *mdd_links_get(const struct lu_env *env,
233 struct mdd_object *mdd_obj);
234 int mdd_links_rename(const struct lu_env *env,
235 struct mdd_object *mdd_obj,
236 const struct lu_fid *oldpfid,
237 const struct lu_name *oldlname,
238 const struct lu_fid *newpfid,
239 const struct lu_name *newlname,
240 struct thandle *handle,
241 struct linkea_data *ldata,
242 int first, int check);
244 struct mdd_thread_info *mdd_env_info(const struct lu_env *env);
246 #define MDD_ENV_VAR(env, var) (&mdd_env_info(env)->mti_##var)
248 struct lu_buf *mdd_buf_get(const struct lu_env *env, void *area, ssize_t len);
249 const struct lu_buf *mdd_buf_get_const(const struct lu_env *env,
250 const void *area, ssize_t len);
252 int mdd_orphan_cleanup(const struct lu_env *env, struct mdd_device *d);
253 int __mdd_orphan_add(const struct lu_env *, struct mdd_object *,
255 int __mdd_orphan_del(const struct lu_env *, struct mdd_object *,
257 int orph_index_init(const struct lu_env *env, struct mdd_device *mdd);
258 void orph_index_fini(const struct lu_env *env, struct mdd_device *mdd);
259 int orph_declare_index_insert(const struct lu_env *, struct mdd_object *,
260 umode_t mode, struct thandle *);
261 int orph_declare_index_delete(const struct lu_env *, struct mdd_object *,
265 int mdd_procfs_init(struct mdd_device *mdd, const char *name);
266 void mdd_procfs_fini(struct mdd_device *mdd);
269 extern struct kmem_cache *mdd_object_kmem;
270 extern const struct md_dir_operations mdd_dir_ops;
271 extern const struct md_object_operations mdd_obj_ops;
272 int mdd_readlink(const struct lu_env *env, struct md_object *obj,
274 int accmode(const struct lu_env *env, const struct lu_attr *la, int flags);
275 extern struct lu_context_key mdd_thread_key;
276 extern const struct lu_device_operations mdd_lu_ops;
278 struct mdd_object *mdd_object_find(const struct lu_env *env,
279 struct mdd_device *d,
280 const struct lu_fid *f);
281 int mdd_readpage(const struct lu_env *env, struct md_object *obj,
282 const struct lu_rdpg *rdpg);
283 int mdd_declare_changelog_store(const struct lu_env *env,
284 struct mdd_device *mdd,
285 const struct lu_name *tname,
286 const struct lu_name *sname,
287 struct thandle *handle);
288 void mdd_changelog_rec_ext_jobid(struct changelog_rec *rec, const char *jobid);
289 int mdd_changelog_store(const struct lu_env *env, struct mdd_device *mdd,
290 struct llog_changelog_rec *rec, struct thandle *th);
291 int mdd_changelog_data_store(const struct lu_env *env, struct mdd_device *mdd,
292 enum changelog_rec_type type, int flags,
293 struct mdd_object *mdd_obj,
294 struct thandle *handle);
295 int mdd_changelog_ns_store(const struct lu_env *env, struct mdd_device *mdd,
296 enum changelog_rec_type type,
297 enum changelog_rec_flags crf,
298 struct mdd_object *target,
299 const struct lu_fid *tpfid,
300 const struct lu_fid *sfid,
301 const struct lu_fid *spfid,
302 const struct lu_name *tname,
303 const struct lu_name *sname,
304 struct thandle *handle);
305 int mdd_declare_object_create_internal(const struct lu_env *env,
306 struct mdd_object *p,
307 struct mdd_object *c,
308 struct lu_attr *attr,
309 struct thandle *handle,
310 const struct md_op_spec *spec,
311 struct dt_allocation_hint *hint);
312 int mdd_get_lov_ea(const struct lu_env *env, struct mdd_object *obj,
313 struct lu_buf *lmm_buf);
316 void mdd_object_make_hint(const struct lu_env *env, struct mdd_object *parent,
317 struct mdd_object *child, const struct lu_attr *attr,
318 const struct md_op_spec *spec,
319 struct dt_allocation_hint *hint);
321 static inline void mdd_object_get(struct mdd_object *o)
323 lu_object_get(&o->mod_obj.mo_lu);
326 static inline void mdd_object_put(const struct lu_env *env,
327 struct mdd_object *o)
329 lu_object_put(env, &o->mod_obj.mo_lu);
332 struct thandle *mdd_trans_create(const struct lu_env *env,
333 struct mdd_device *mdd);
334 int mdd_trans_start(const struct lu_env *env, struct mdd_device *mdd,
336 int mdd_trans_stop(const struct lu_env *env, struct mdd_device *mdd,
337 int rc, struct thandle *handle);
340 struct lu_object *mdd_object_alloc(const struct lu_env *env,
341 const struct lu_object_header *hdr,
342 struct lu_device *d);
343 int mdd_local_file_create(const struct lu_env *env, struct mdd_device *mdd,
344 const struct lu_fid *pfid, const char *name,
345 __u32 mode, struct lu_fid *fid);
347 int mdd_acl_chmod(const struct lu_env *env, struct mdd_object *o, __u32 mode,
348 struct thandle *handle);
349 int mdd_acl_set(const struct lu_env *env, struct mdd_object *obj,
350 struct lu_attr *attr, const struct lu_buf *buf, int fl);
351 int __mdd_fix_mode_acl(const struct lu_env *env, struct lu_buf *buf,
353 int __mdd_permission_internal(const struct lu_env *env, struct mdd_object *obj,
354 const struct lu_attr *la, int mask, int role);
355 int mdd_permission(const struct lu_env *env,
356 struct md_object *pobj, struct md_object *cobj,
357 struct md_attr *ma, int mask);
358 int mdd_generic_thread_start(struct mdd_generic_thread *thread,
359 int (*func)(void *), void *data, char *name);
360 void mdd_generic_thread_stop(struct mdd_generic_thread *thread);
363 int mdd_compat_fixes(const struct lu_env *env, struct mdd_device *mdd);
365 /* inline functions */
366 static inline int lu_device_is_mdd(struct lu_device *d)
368 return ergo(d != NULL && d->ld_ops != NULL, d->ld_ops == &mdd_lu_ops);
371 static inline struct mdd_device* lu2mdd_dev(struct lu_device *d)
373 LASSERT(lu_device_is_mdd(d));
374 return container_of0(d, struct mdd_device, mdd_md_dev.md_lu_dev);
377 static inline struct lu_device *mdd2lu_dev(struct mdd_device *d)
379 return (&d->mdd_md_dev.md_lu_dev);
382 static inline struct mdd_object *lu2mdd_obj(struct lu_object *o)
384 LASSERT(ergo(o != NULL, lu_device_is_mdd(o->lo_dev)));
385 return container_of0(o, struct mdd_object, mod_obj.mo_lu);
388 static inline struct mdd_device* mdo2mdd(struct md_object *mdo)
390 return lu2mdd_dev(mdo->mo_lu.lo_dev);
393 static inline struct mdd_object* md2mdd_obj(struct md_object *mdo)
395 return container_of0(mdo, struct mdd_object, mod_obj);
398 static inline const struct dt_device_operations *
399 mdd_child_ops(struct mdd_device *d)
401 return d->mdd_child->dd_ops;
404 static inline struct lu_object *mdd2lu_obj(struct mdd_object *obj)
406 return &obj->mod_obj.mo_lu;
409 static inline struct dt_object* mdd_object_child(struct mdd_object *o)
411 return container_of0(lu_object_next(mdd2lu_obj(o)),
412 struct dt_object, do_lu);
415 static inline struct obd_device *mdd2obd_dev(struct mdd_device *mdd)
417 return (mdd->mdd_md_dev.md_lu_dev.ld_obd);
420 static inline struct mdd_device *mdd_obj2mdd_dev(struct mdd_object *obj)
422 return mdo2mdd(&obj->mod_obj);
425 static inline const struct lu_fid *mdo2fid(const struct mdd_object *obj)
427 return lu_object_fid(&obj->mod_obj.mo_lu);
430 static inline umode_t mdd_object_type(const struct mdd_object *obj)
432 return lu_object_attr(&obj->mod_obj.mo_lu);
435 static inline int mdd_is_dead_obj(struct mdd_object *obj)
437 return obj && obj->mod_flags & DEAD_OBJ;
440 static inline int mdd_object_exists(struct mdd_object *obj)
442 return lu_object_exists(mdd2lu_obj(obj));
445 static inline int mdd_object_remote(struct mdd_object *obj)
447 return lu_object_remote(mdd2lu_obj(obj));
450 static inline const struct lu_fid *mdd_object_fid(struct mdd_object *obj)
452 return lu_object_fid(mdd2lu_obj(obj));
455 static inline struct seq_server_site *mdd_seq_site(struct mdd_device *mdd)
457 return mdd2lu_dev(mdd)->ld_site->ld_seq_site;
460 static inline const char *mdd_obj_dev_name(const struct mdd_object *obj)
462 return lu_dev_name(obj->mod_obj.mo_lu.lo_dev);
465 #define MAX_ATIME_DIFF 60
467 static inline int mdd_permission_internal(const struct lu_env *env,
468 struct mdd_object *obj,
469 const struct lu_attr *la, int mask)
471 return __mdd_permission_internal(env, obj, la, mask, -1);
474 static inline int mdd_permission_internal_locked(const struct lu_env *env,
475 struct mdd_object *obj,
476 const struct lu_attr *la,
478 enum mdd_object_role role)
480 return __mdd_permission_internal(env, obj, la, mask, role);
483 /* mdd inline func for calling osd_dt_object ops */
484 static inline int mdo_attr_get(const struct lu_env *env, struct mdd_object *obj,
487 struct dt_object *next = mdd_object_child(obj);
488 return dt_attr_get(env, next, la);
491 static inline int mdo_declare_attr_set(const struct lu_env *env,
492 struct mdd_object *obj,
493 const struct lu_attr *la,
494 struct thandle *handle)
496 struct dt_object *next = mdd_object_child(obj);
497 return dt_declare_attr_set(env, next, la, handle);
500 static inline int mdo_attr_set(const struct lu_env *env,
501 struct mdd_object *obj,
502 const struct lu_attr *la,
503 struct thandle *handle)
505 struct dt_object *next = mdd_object_child(obj);
507 if (!mdd_object_exists(obj))
510 return dt_attr_set(env, next, la, handle);
513 static inline int mdo_xattr_get(const struct lu_env *env,struct mdd_object *obj,
514 struct lu_buf *buf, const char *name)
516 struct dt_object *next = mdd_object_child(obj);
517 return dt_xattr_get(env, next, buf, name);
520 static inline int mdo_declare_xattr_set(const struct lu_env *env,
521 struct mdd_object *obj,
522 const struct lu_buf *buf,
524 int fl, struct thandle *handle)
526 struct dt_object *next = mdd_object_child(obj);
527 return dt_declare_xattr_set(env, next, buf, name, fl, handle);
530 static inline int mdo_xattr_set(const struct lu_env *env,struct mdd_object *obj,
531 const struct lu_buf *buf, const char *name,
532 int fl, struct thandle *handle)
534 struct dt_object *next = mdd_object_child(obj);
536 if (!mdd_object_exists(obj))
539 return dt_xattr_set(env, next, buf, name, fl, handle);
542 static inline int mdo_declare_xattr_del(const struct lu_env *env,
543 struct mdd_object *obj,
545 struct thandle *handle)
547 struct dt_object *next = mdd_object_child(obj);
548 return dt_declare_xattr_del(env, next, name, handle);
551 static inline int mdo_xattr_del(const struct lu_env *env,struct mdd_object *obj,
552 const char *name, struct thandle *handle)
554 struct dt_object *next = mdd_object_child(obj);
556 if (!mdd_object_exists(obj))
559 return dt_xattr_del(env, next, name, handle);
563 mdo_xattr_list(const struct lu_env *env, struct mdd_object *obj,
566 struct dt_object *next = mdd_object_child(obj);
568 if (!mdd_object_exists(obj))
571 return dt_xattr_list(env, next, buf);
575 int mdo_declare_index_insert(const struct lu_env *env, struct mdd_object *obj,
576 const struct lu_fid *fid, __u32 type,
577 const char *name, struct thandle *handle)
579 struct dt_object *next = mdd_object_child(obj);
583 * if the object doesn't exist yet, then it's supposed to be created
584 * and declaration of the creation should be enough to insert ./..
588 if (dt_try_as_dir(env, next)) {
589 struct dt_insert_rec *rec = &mdd_env_info(env)->mti_dt_rec;
592 rec->rec_type = type;
593 rc = dt_declare_insert(env, next, (const struct dt_rec *)rec,
594 (const struct dt_key *)name, handle);
601 int mdo_declare_index_delete(const struct lu_env *env, struct mdd_object *obj,
602 const char *name, struct thandle *handle)
604 struct dt_object *next = mdd_object_child(obj);
606 if (!dt_try_as_dir(env, next))
609 return dt_declare_delete(env, next, (const struct dt_key *)name,
613 static inline int mdo_declare_ref_add(const struct lu_env *env,
614 struct mdd_object *obj,
615 struct thandle *handle)
617 struct dt_object *next = mdd_object_child(obj);
618 return dt_declare_ref_add(env, next, handle);
621 static inline int mdo_ref_add(const struct lu_env *env, struct mdd_object *obj,
622 struct thandle *handle)
624 struct dt_object *next = mdd_object_child(obj);
626 if (!mdd_object_exists(obj))
629 return dt_ref_add(env, next, handle);
632 static inline int mdo_declare_ref_del(const struct lu_env *env,
633 struct mdd_object *obj,
634 struct thandle *handle)
636 struct dt_object *next = mdd_object_child(obj);
637 return dt_declare_ref_del(env, next, handle);
640 static inline int mdo_ref_del(const struct lu_env *env, struct mdd_object *obj,
641 struct thandle *handle)
643 struct dt_object *next = mdd_object_child(obj);
645 if (!mdd_object_exists(obj))
648 return dt_ref_del(env, next, handle);
652 mdo_declare_create_obj(const struct lu_env *env, struct mdd_object *o,
653 struct lu_attr *attr,
654 struct dt_allocation_hint *hint,
655 struct dt_object_format *dof,
656 struct thandle *handle)
658 struct dt_object *next = mdd_object_child(o);
659 return dt_declare_create(env, next, attr, hint, dof, handle);
663 mdo_create_obj(const struct lu_env *env, struct mdd_object *o,
664 struct lu_attr *attr,
665 struct dt_allocation_hint *hint,
666 struct dt_object_format *dof,
667 struct thandle *handle)
669 struct dt_object *next = mdd_object_child(o);
670 return dt_create(env, next, attr, hint, dof, handle);
674 int mdo_declare_destroy(const struct lu_env *env, struct mdd_object *o,
675 struct thandle *handle)
677 struct dt_object *next = mdd_object_child(o);
678 return dt_declare_destroy(env, next, handle);
682 int mdo_destroy(const struct lu_env *env, struct mdd_object *o,
683 struct thandle *handle)
685 struct dt_object *next = mdd_object_child(o);
686 return dt_destroy(env, next, handle);