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, 2013, 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 <lustre_capa.h>
51 #include <lprocfs_status.h>
52 #include <lustre_log.h>
53 #include <lustre_linkea.h>
55 /* PDO lock is unnecessary for current MDT stack because operations
56 * are already protected by ldlm lock */
57 #define MDD_DISABLE_PDO_LOCK 1
60 /** changelog is recording */
61 #define CLM_ON 0x00001
62 /** internal error prevented changelogs from starting */
63 #define CLM_ERR 0x00002
65 /** changelogs turned on */
66 #define CLM_START 0x10000
67 /** changelogs turned off */
68 #define CLM_FINI 0x20000
69 /** some changelog records purged */
70 #define CLM_PURGE 0x40000
72 struct mdd_changelog {
73 spinlock_t mc_lock; /* for index */
78 spinlock_t mc_user_lock;
82 static inline __u64 cl_time(void) {
85 cfs_fs_time_current(&time);
86 return (((__u64)time.tv_sec) << 30) + time.tv_nsec;
89 /** Objects in .lustre dir */
90 struct mdd_dot_lustre_objs {
91 struct mdd_object *mdd_obf;
95 struct md_device mdd_md_dev;
96 struct obd_export *mdd_child_exp;
97 struct dt_device *mdd_child;
98 struct dt_device *mdd_bottom;
99 struct lu_fid mdd_root_fid; /* /ROOT */
100 struct lu_fid mdd_local_root_fid;
101 struct dt_device_param mdd_dt_conf;
102 struct dt_object *mdd_orphans; /* PENDING directory */
103 cfs_proc_dir_entry_t *mdd_proc_entry;
104 struct mdd_changelog mdd_cl;
105 unsigned long mdd_atime_diff;
106 struct mdd_object *mdd_dot_lustre;
107 struct mdd_dot_lustre_objs mdd_dot_lustre_objs;
108 unsigned int mdd_sync_permission;
110 struct local_oid_storage *mdd_los;
114 /* The dir object has been unlinked */
122 struct md_object mod_obj;
127 unsigned long mod_flags;
128 #ifndef MDD_DISABLE_PDO_LOCK
129 struct dynlock mod_pdlock;
131 #ifdef CONFIG_LOCKDEP
132 /* "dep_map" name is assumed by lockdep.h macros. */
133 struct lockdep_map dep_map;
137 struct mdd_thread_info {
138 struct lu_fid mti_fid;
139 struct lu_fid mti_fid2; /* used for be & cpu converting */
140 struct lu_attr mti_la;
141 struct lu_attr mti_la_for_fix;
142 struct lu_attr mti_pattr;
143 struct lu_attr mti_cattr;
144 struct md_attr mti_ma;
145 struct obd_info mti_oi;
146 /* mti_ent and mti_key must be conjoint,
147 * then mti_ent::lde_name will be mti_key. */
148 struct lu_dirent mti_ent;
149 char mti_key[NAME_MAX + 16];
150 struct obd_trans_info mti_oti;
151 struct lu_buf mti_buf;
152 struct lu_buf mti_big_buf; /* biggish persistent buf */
153 struct lu_buf mti_link_buf; /* buf for link ea */
154 struct lu_name mti_name;
155 struct lu_name mti_name2;
157 char mti_xattr_buf[LUSTRE_POSIX_ACL_MAX_SIZE];
158 struct dt_allocation_hint mti_hint;
159 struct lov_mds_md *mti_max_lmm;
160 int mti_max_lmm_size;
161 struct llog_cookie *mti_max_cookie;
162 int mti_max_cookie_size;
163 struct dt_object_format mti_dof;
164 struct obd_quotactl mti_oqctl;
165 struct linkea_data mti_link_data;
168 extern const char orph_index_name[];
170 extern const struct dt_index_features orph_index_features;
172 struct lov_mds_md *mdd_max_lmm_buffer(const struct lu_env *env, int size);
173 struct lov_mds_md *mdd_max_lmm_get(const struct lu_env *env,
174 struct mdd_device *mdd);
176 struct llog_cookie *mdd_max_cookie_get(const struct lu_env *env,
177 struct mdd_device *mdd);
179 int mdd_init_obd(const struct lu_env *env, struct mdd_device *mdd,
180 struct lustre_cfg *cfg);
181 int mdd_fini_obd(const struct lu_env *env, struct mdd_device *mdd,
182 struct lustre_cfg *lcfg);
183 int __mdd_xattr_set(const struct lu_env *env, struct mdd_object *obj,
184 const struct lu_buf *buf, const char *name,
185 int fl, struct thandle *handle);
186 int mdd_xattr_set_txn(const struct lu_env *env, struct mdd_object *obj,
187 const struct lu_buf *buf, const char *name, int fl,
188 struct thandle *txn);
189 int mdd_lsm_sanity_check(const struct lu_env *env, struct mdd_object *obj);
190 int mdd_lov_set_md(const struct lu_env *env, struct mdd_object *pobj,
191 struct mdd_object *child, struct lov_mds_md *lmm,
192 int lmm_size, struct thandle *handle, int set_stripe);
193 int mdd_lov_create(const struct lu_env *env, struct mdd_device *mdd,
194 struct mdd_object *parent, struct mdd_object *child,
195 struct lov_mds_md **lmm, int *lmm_size,
196 const struct md_op_spec *spec, struct md_attr *ma);
197 int mdd_lov_objid_prepare(struct mdd_device *mdd, struct lov_mds_md *lmm);
198 int mdd_declare_lov_objid_update(const struct lu_env *, struct mdd_device *,
200 void mdd_lov_objid_update(struct mdd_device *mdd, struct lov_mds_md *lmm);
201 void mdd_lov_create_finish(const struct lu_env *env, struct mdd_device *mdd,
202 struct lov_mds_md *lmm, int lmm_size,
203 const struct md_op_spec *spec);
204 int mdd_file_lock(const struct lu_env *env, struct md_object *obj,
205 struct lov_mds_md *lmm, struct ldlm_extent *extent,
206 struct lustre_handle *lockh);
207 int mdd_file_unlock(const struct lu_env *env, struct md_object *obj,
208 struct lov_mds_md *lmm, struct lustre_handle *lockh);
209 int mdd_lum_lmm_cmp(const struct lu_env *env, struct md_object *cobj,
210 const struct md_op_spec *spec, struct md_attr *ma);
211 int mdd_get_md(const struct lu_env *env, struct mdd_object *obj,
212 void *md, int *md_size, const char *name);
213 int mdd_get_md_locked(const struct lu_env *env, struct mdd_object *obj,
214 void *md, int *md_size, const char *name);
215 int mdd_data_get(const struct lu_env *env, struct mdd_object *obj, void **data);
216 int mdd_la_get(const struct lu_env *env, struct mdd_object *obj,
217 struct lu_attr *la, struct lustre_capa *capa);
218 int mdd_attr_get(const struct lu_env *env, struct md_object *obj,
220 int mdd_attr_set(const struct lu_env *env, struct md_object *obj,
221 const struct md_attr *ma);
222 int mdd_attr_set_internal(const struct lu_env *env,
223 struct mdd_object *obj,
224 const struct lu_attr *attr,
225 struct thandle *handle,
227 int mdd_attr_check_set_internal(const struct lu_env *env,
228 struct mdd_object *obj,
229 struct lu_attr *attr,
230 struct thandle *handle,
232 int mdd_declare_object_kill(const struct lu_env *env, struct mdd_object *obj,
233 struct md_attr *ma, struct thandle *handle);
234 int mdd_object_kill(const struct lu_env *env, struct mdd_object *obj,
235 struct md_attr *ma, struct thandle *handle);
236 int mdd_iattr_get(const struct lu_env *env, struct mdd_object *mdd_obj,
238 int mdd_object_create_internal(const struct lu_env *env, struct mdd_object *p,
239 struct mdd_object *c, struct lu_attr *attr,
240 struct thandle *handle,
241 const struct md_op_spec *spec);
242 int mdd_attr_check_set_internal_locked(const struct lu_env *env,
243 struct mdd_object *obj,
244 struct lu_attr *attr,
245 struct thandle *handle,
247 int mdd_lmm_get_locked(const struct lu_env *env, struct mdd_object *mdd_obj,
251 void mdd_write_lock(const struct lu_env *env, struct mdd_object *obj,
252 enum mdd_object_role role);
253 void mdd_read_lock(const struct lu_env *env, struct mdd_object *obj,
254 enum mdd_object_role role);
255 void mdd_write_unlock(const struct lu_env *env, struct mdd_object *obj);
256 void mdd_read_unlock(const struct lu_env *env, struct mdd_object *obj);
257 int mdd_write_locked(const struct lu_env *env, struct mdd_object *obj);
259 void mdd_pdlock_init(struct mdd_object *obj);
260 unsigned long mdd_name2hash(const char *name);
261 void *mdd_pdo_write_lock(const struct lu_env *env, struct mdd_object *obj,
262 const char *name, enum mdd_object_role role);
263 void *mdd_pdo_read_lock(const struct lu_env *env, struct mdd_object *obj,
264 const char *name, enum mdd_object_role role);
265 void mdd_pdo_write_unlock(const struct lu_env *env, struct mdd_object *obj,
267 void mdd_pdo_read_unlock(const struct lu_env *env, struct mdd_object *obj,
270 int mdd_parent_fid(const struct lu_env *env, struct mdd_object *obj,
272 int mdd_is_subdir(const struct lu_env *env, struct md_object *mo,
273 const struct lu_fid *fid, struct lu_fid *sfid);
274 int mdd_may_create(const struct lu_env *env, struct mdd_object *pobj,
275 struct mdd_object *cobj, int check_perm, int check_nlink);
276 int mdd_may_unlink(const struct lu_env *env, struct mdd_object *pobj,
277 const struct lu_attr *attr);
278 int mdd_may_delete(const struct lu_env *env, struct mdd_object *pobj,
279 struct mdd_object *cobj, struct lu_attr *cattr,
280 struct lu_attr *src_attr, int check_perm, int check_empty);
281 int mdd_unlink_sanity_check(const struct lu_env *env, struct mdd_object *pobj,
282 struct mdd_object *cobj, struct lu_attr *cattr);
283 int mdd_finish_unlink(const struct lu_env *env, struct mdd_object *obj,
284 struct md_attr *ma, struct thandle *th);
286 int mdd_link_sanity_check(const struct lu_env *env, struct mdd_object *tgt_obj,
287 const struct lu_name *lname, struct mdd_object *src_obj);
288 int mdd_is_root(struct mdd_device *mdd, const struct lu_fid *fid);
289 int mdd_lookup(const struct lu_env *env,
290 struct md_object *pobj, const struct lu_name *lname,
291 struct lu_fid* fid, struct md_op_spec *spec);
292 int mdd_links_read(const struct lu_env *env, struct mdd_object *mdd_obj,
293 struct linkea_data *ldata);
294 int mdd_declare_links_add(const struct lu_env *env, struct mdd_object *mdd_obj,
295 struct thandle *handle, struct linkea_data *ldata);
296 int mdd_links_write(const struct lu_env *env, struct mdd_object *mdd_obj,
297 struct linkea_data *ldata, struct thandle *handle);
298 struct lu_buf *mdd_links_get(const struct lu_env *env,
299 struct mdd_object *mdd_obj);
300 int mdd_links_rename(const struct lu_env *env,
301 struct mdd_object *mdd_obj,
302 const struct lu_fid *oldpfid,
303 const struct lu_name *oldlname,
304 const struct lu_fid *newpfid,
305 const struct lu_name *newlname,
306 struct thandle *handle,
307 struct linkea_data *ldata,
308 int first, int check);
309 int mdd_declare_links_add(const struct lu_env *env, struct mdd_object *mdd_obj,
310 struct thandle *handle, struct linkea_data *ldata);
313 int mdd_declare_unlink_log(const struct lu_env *env, struct mdd_object *obj,
314 struct md_attr *ma, struct thandle *handle);
315 int mdd_unlink_log(const struct lu_env *env, struct mdd_device *mdd,
316 struct mdd_object *mdd_cobj, struct md_attr *ma);
318 int mdd_setattr_log(const struct lu_env *env, struct mdd_device *mdd,
319 const struct md_attr *ma,
320 struct lov_mds_md *lmm, int lmm_size,
321 struct llog_cookie *logcookies, int cookies_size);
323 int mdd_get_cookie_size(const struct lu_env *env, struct mdd_device *mdd,
324 struct lov_mds_md *lmm);
326 int mdd_lov_setattr_async(const struct lu_env *env, struct mdd_object *obj,
327 struct lov_mds_md *lmm, int lmm_size,
328 struct llog_cookie *logcookies);
330 int mdd_lovobj_unlink(const struct lu_env *env, struct mdd_device *mdd,
331 struct mdd_object *obj, struct lu_attr *la,
332 struct md_attr *ma, int log_unlink);
334 struct mdd_thread_info *mdd_env_info(const struct lu_env *env);
336 const struct lu_name *mdd_name_get_const(const struct lu_env *env,
337 const void *area, ssize_t len);
338 struct lu_buf *mdd_buf_get(const struct lu_env *env, void *area, ssize_t len);
339 const struct lu_buf *mdd_buf_get_const(const struct lu_env *env,
340 const void *area, ssize_t len);
342 int __mdd_orphan_cleanup(const struct lu_env *env, struct mdd_device *d);
343 int __mdd_orphan_add(const struct lu_env *, struct mdd_object *,
345 int __mdd_orphan_del(const struct lu_env *, struct mdd_object *,
347 int orph_index_init(const struct lu_env *env, struct mdd_device *mdd);
348 void orph_index_fini(const struct lu_env *env, struct mdd_device *mdd);
349 int orph_declare_index_insert(const struct lu_env *, struct mdd_object *,
350 cfs_umode_t mode, struct thandle *);
351 int orph_declare_index_delete(const struct lu_env *, struct mdd_object *,
355 void lprocfs_mdd_init_vars(struct lprocfs_static_vars *lvars);
356 int mdd_procfs_init(struct mdd_device *mdd, const char *name);
357 int mdd_procfs_fini(struct mdd_device *mdd);
360 int mdd_get_flags(const struct lu_env *env, struct mdd_object *obj);
361 struct lu_buf *mdd_buf_alloc(const struct lu_env *env, ssize_t len);
362 int mdd_buf_grow(const struct lu_env *env, ssize_t len);
363 void mdd_buf_put(struct lu_buf *buf);
365 struct lu_buf *mdd_link_buf_alloc(const struct lu_env *env, ssize_t len);
366 int mdd_link_buf_grow(const struct lu_env *env, ssize_t len);
367 extern const struct md_dir_operations mdd_dir_ops;
368 extern const struct md_object_operations mdd_obj_ops;
370 int accmode(const struct lu_env *env, struct lu_attr *la, int flags);
371 extern struct lu_context_key mdd_thread_key;
372 extern const struct lu_device_operations mdd_lu_ops;
374 struct mdd_object *mdd_object_find(const struct lu_env *env,
375 struct mdd_device *d,
376 const struct lu_fid *f);
377 int mdd_get_default_md(struct mdd_object *mdd_obj, struct lov_mds_md *lmm);
378 int mdd_readpage(const struct lu_env *env, struct md_object *obj,
379 const struct lu_rdpg *rdpg);
380 int mdd_declare_changelog_store(const struct lu_env *env,
381 struct mdd_device *mdd,
382 const struct lu_name *fname,
383 struct thandle *handle);
384 int mdd_changelog_store(const struct lu_env *env, struct mdd_device *mdd,
385 struct llog_changelog_rec *rec, struct thandle *th);
386 int mdd_changelog_data_store(const struct lu_env *env, struct mdd_device *mdd,
387 enum changelog_rec_type type, int flags,
388 struct mdd_object *mdd_obj,
389 struct thandle *handle);
390 int mdd_changelog_ns_store(const struct lu_env *env, struct mdd_device *mdd,
391 enum changelog_rec_type type, unsigned flags,
392 struct mdd_object *target, struct mdd_object *parent,
393 const struct lu_name *tname, struct thandle *handle);
394 int mdd_declare_object_create_internal(const struct lu_env *env,
395 struct mdd_object *p,
396 struct mdd_object *c,
397 struct lu_attr *attr,
398 struct thandle *handle,
399 const struct md_op_spec *spec);
402 int mdd_lov_destroy(const struct lu_env *env, struct mdd_device *mdd,
403 struct mdd_object *obj, struct lu_attr *la);
405 void mdd_object_make_hint(const struct lu_env *env, struct mdd_object *parent,
406 struct mdd_object *child, struct lu_attr *attr);
408 static inline void mdd_object_get(struct mdd_object *o)
410 lu_object_get(&o->mod_obj.mo_lu);
413 static inline void mdd_object_put(const struct lu_env *env,
414 struct mdd_object *o)
416 lu_object_put(env, &o->mod_obj.mo_lu);
419 struct thandle *mdd_trans_create(const struct lu_env *env,
420 struct mdd_device *mdd);
421 int mdd_trans_start(const struct lu_env *env, struct mdd_device *mdd,
423 void mdd_trans_stop(const struct lu_env *env, struct mdd_device *mdd,
424 int rc, struct thandle *handle);
425 int mdd_txn_stop_cb(const struct lu_env *env, struct thandle *txn,
427 int mdd_txn_start_cb(const struct lu_env *env, struct thandle *,
431 struct lu_object *mdd_object_alloc(const struct lu_env *env,
432 const struct lu_object_header *hdr,
433 struct lu_device *d);
434 int mdd_local_file_create(const struct lu_env *env, struct mdd_device *mdd,
435 const struct lu_fid *pfid, const char *name,
436 __u32 mode, struct lu_fid *fid);
438 int mdd_acl_chmod(const struct lu_env *env, struct mdd_object *o, __u32 mode,
439 struct thandle *handle);
440 int __mdd_declare_acl_init(const struct lu_env *env, struct mdd_object *obj,
441 int is_dir, struct thandle *handle);
442 int mdd_acl_set(const struct lu_env *env, struct mdd_object *obj,
443 const struct lu_buf *buf, int fl);
444 int __mdd_fix_mode_acl(const struct lu_env *env, struct lu_buf *buf,
446 int __mdd_permission_internal(const struct lu_env *env, struct mdd_object *obj,
447 struct lu_attr *la, int mask, int role);
448 int mdd_permission(const struct lu_env *env,
449 struct md_object *pobj, struct md_object *cobj,
450 struct md_attr *ma, int mask);
451 int mdd_capa_get(const struct lu_env *env, struct md_object *obj,
452 struct lustre_capa *capa, int renewal);
455 int mdd_compat_fixes(const struct lu_env *env, struct mdd_device *mdd);
457 static inline int lu_device_is_mdd(struct lu_device *d)
459 return ergo(d != NULL && d->ld_ops != NULL, d->ld_ops == &mdd_lu_ops);
462 static inline struct mdd_device* lu2mdd_dev(struct lu_device *d)
464 LASSERT(lu_device_is_mdd(d));
465 return container_of0(d, struct mdd_device, mdd_md_dev.md_lu_dev);
468 static inline struct lu_device *mdd2lu_dev(struct mdd_device *d)
470 return (&d->mdd_md_dev.md_lu_dev);
473 static inline struct mdd_object *lu2mdd_obj(struct lu_object *o)
475 LASSERT(ergo(o != NULL, lu_device_is_mdd(o->lo_dev)));
476 return container_of0(o, struct mdd_object, mod_obj.mo_lu);
479 static inline struct mdd_device* mdo2mdd(struct md_object *mdo)
481 return lu2mdd_dev(mdo->mo_lu.lo_dev);
484 static inline struct mdd_object* md2mdd_obj(struct md_object *mdo)
486 return container_of0(mdo, struct mdd_object, mod_obj);
489 static inline const struct dt_device_operations *
490 mdd_child_ops(struct mdd_device *d)
492 return d->mdd_child->dd_ops;
495 static inline struct lu_object *mdd2lu_obj(struct mdd_object *obj)
497 return &obj->mod_obj.mo_lu;
500 static inline struct dt_object* mdd_object_child(struct mdd_object *o)
502 return container_of0(lu_object_next(mdd2lu_obj(o)),
503 struct dt_object, do_lu);
506 static inline struct obd_device *mdd2obd_dev(struct mdd_device *mdd)
508 return (mdd->mdd_md_dev.md_lu_dev.ld_obd);
511 static inline struct mdd_device *mdd_obj2mdd_dev(struct mdd_object *obj)
513 return mdo2mdd(&obj->mod_obj);
516 static inline const struct lu_fid *mdo2fid(const struct mdd_object *obj)
518 return lu_object_fid(&obj->mod_obj.mo_lu);
521 static inline int mdd_object_obf(const struct mdd_object *obj)
523 return lu_fid_eq(mdo2fid(obj), &LU_OBF_FID);
526 static inline cfs_umode_t mdd_object_type(const struct mdd_object *obj)
528 return lu_object_attr(&obj->mod_obj.mo_lu);
531 static inline int mdd_is_immutable(struct mdd_object *obj)
533 return obj->mod_flags & IMMUTE_OBJ;
536 static inline int mdd_is_dead_obj(struct mdd_object *obj)
538 return obj && obj->mod_flags & DEAD_OBJ;
541 static inline int mdd_is_append(struct mdd_object *obj)
543 return obj->mod_flags & APPEND_OBJ;
546 static inline int mdd_object_exists(struct mdd_object *obj)
548 return lu_object_exists(mdd2lu_obj(obj));
551 static inline int mdd_object_remote(struct mdd_object *obj)
553 return lu_object_remote(mdd2lu_obj(obj));
556 static inline const struct lu_fid *mdd_object_fid(struct mdd_object *obj)
558 return lu_object_fid(mdd2lu_obj(obj));
561 static inline struct seq_server_site *mdd_seq_site(struct mdd_device *mdd)
563 return mdd2lu_dev(mdd)->ld_site->ld_seq_site;
566 static inline struct lustre_capa *mdd_object_capa(const struct lu_env *env,
567 const struct mdd_object *obj)
569 struct md_capainfo *ci = md_capainfo(env);
570 const struct lu_fid *fid = mdo2fid(obj);
573 /* NB: in mdt_init0 */
576 for (i = 0; i < MD_CAPAINFO_MAX; i++)
577 if (lu_fid_eq(&ci->mc_fid[i], fid))
578 return ci->mc_capa[i];
582 static inline void mdd_set_capainfo(const struct lu_env *env, int offset,
583 const struct mdd_object *obj,
584 struct lustre_capa *capa)
586 struct md_capainfo *ci = md_capainfo(env);
587 const struct lu_fid *fid = mdo2fid(obj);
589 LASSERT(offset >= 0 && offset < MD_CAPAINFO_MAX);
590 /* NB: in mdt_init0 */
593 ci->mc_fid[offset] = *fid;
594 ci->mc_capa[offset] = capa;
597 static inline const char *mdd_obj_dev_name(const struct mdd_object *obj)
599 return lu_dev_name(obj->mod_obj.mo_lu.lo_dev);
602 #define MAX_ATIME_DIFF 60
608 static inline int mdd_permission_internal(const struct lu_env *env,
609 struct mdd_object *obj,
610 struct lu_attr *la, int mask)
612 return __mdd_permission_internal(env, obj, la, mask, -1);
615 static inline int mdd_permission_internal_locked(const struct lu_env *env,
616 struct mdd_object *obj,
617 struct lu_attr *la, int mask,
618 enum mdd_object_role role)
620 return __mdd_permission_internal(env, obj, la, mask, role);
623 static inline int mdo_data_get(const struct lu_env *env,
624 struct mdd_object *obj,
627 struct dt_object *next = mdd_object_child(obj);
628 next->do_ops->do_data_get(env, next, data);
632 /* mdd inline func for calling osd_dt_object ops */
633 static inline int mdo_attr_get(const struct lu_env *env, struct mdd_object *obj,
634 struct lu_attr *la, struct lustre_capa *capa)
636 struct dt_object *next = mdd_object_child(obj);
637 return next->do_ops->do_attr_get(env, next, la, capa);
640 static inline int mdo_declare_attr_set(const struct lu_env *env,
641 struct mdd_object *obj,
642 const struct lu_attr *la,
643 struct thandle *handle)
645 struct dt_object *next = mdd_object_child(obj);
646 return dt_declare_attr_set(env, next, la, handle);
649 static inline int mdo_attr_set(const struct lu_env *env,
650 struct mdd_object *obj,
651 const struct lu_attr *la,
652 struct thandle *handle,
653 struct lustre_capa *capa)
655 struct dt_object *next = mdd_object_child(obj);
656 if (mdd_object_exists(obj) == 0) {
657 CERROR("%s: object "DFID" not found: rc = -2\n",
658 mdd_obj_dev_name(obj), PFID(mdd_object_fid(obj)));
661 return next->do_ops->do_attr_set(env, next, la, handle, capa);
664 static inline int mdo_xattr_get(const struct lu_env *env,struct mdd_object *obj,
665 struct lu_buf *buf, const char *name,
666 struct lustre_capa *capa)
668 struct dt_object *next = mdd_object_child(obj);
669 return next->do_ops->do_xattr_get(env, next, buf, name, capa);
672 static inline int mdo_declare_xattr_set(const struct lu_env *env,
673 struct mdd_object *obj,
674 const struct lu_buf *buf,
676 int fl, struct thandle *handle)
678 struct dt_object *next = mdd_object_child(obj);
679 return dt_declare_xattr_set(env, next, buf, name, fl, handle);
682 static inline int mdo_xattr_set(const struct lu_env *env,struct mdd_object *obj,
683 const struct lu_buf *buf, const char *name,
684 int fl, struct thandle *handle,
685 struct lustre_capa *capa)
687 struct dt_object *next = mdd_object_child(obj);
688 if (mdd_object_exists(obj) == 0) {
689 CERROR("%s: object "DFID" not found: rc = -2\n",
690 mdd_obj_dev_name(obj), PFID(mdd_object_fid(obj)));
693 return next->do_ops->do_xattr_set(env, next, buf, name, fl, handle,
697 static inline int mdo_declare_xattr_del(const struct lu_env *env,
698 struct mdd_object *obj,
700 struct thandle *handle)
702 struct dt_object *next = mdd_object_child(obj);
703 return dt_declare_xattr_del(env, next, name, handle);
706 static inline int mdo_xattr_del(const struct lu_env *env,struct mdd_object *obj,
707 const char *name, struct thandle *handle,
708 struct lustre_capa *capa)
710 struct dt_object *next = mdd_object_child(obj);
711 if (mdd_object_exists(obj) == 0) {
712 CERROR("%s: object "DFID" not found: rc = -2\n",
713 mdd_obj_dev_name(obj), PFID(mdd_object_fid(obj)));
716 return next->do_ops->do_xattr_del(env, next, name, handle, capa);
720 int mdo_xattr_list(const struct lu_env *env, struct mdd_object *obj,
721 struct lu_buf *buf, struct lustre_capa *capa)
723 struct dt_object *next = mdd_object_child(obj);
724 if (mdd_object_exists(obj) == 0) {
725 CERROR("%s: object "DFID" not found: rc = -2\n",
726 mdd_obj_dev_name(obj), PFID(mdd_object_fid(obj)));
729 return next->do_ops->do_xattr_list(env, next, buf, capa);
733 int mdo_index_try(const struct lu_env *env, struct mdd_object *obj,
734 const struct dt_index_features *feat)
736 struct dt_object *next = mdd_object_child(obj);
737 return next->do_ops->do_index_try(env, next, feat);
741 int mdo_declare_index_insert(const struct lu_env *env, struct mdd_object *obj,
742 const struct lu_fid *fid, const char *name,
743 struct thandle *handle)
745 struct dt_object *next = mdd_object_child(obj);
749 * if the object doesn't exist yet, then it's supposed to be created
750 * and declaration of the creation should be enough to insert ./..
752 /* FIXME: remote object should not be awared by MDD layer, but local
753 * creation does not declare insert ./.. (comments above), which
754 * is required by remote directory creation.
755 * This remote check should be removed when mdd_object_exists check is
758 if (mdd_object_exists(obj) || mdd_object_remote(obj)) {
760 if (dt_try_as_dir(env, next))
761 rc = dt_declare_insert(env, next,
762 (struct dt_rec *)fid,
763 (const struct dt_key *)name,
771 int mdo_declare_index_delete(const struct lu_env *env, struct mdd_object *obj,
772 const char *name, struct thandle *handle)
774 struct dt_object *next = mdd_object_child(obj);
776 if (!dt_try_as_dir(env, next))
779 return dt_declare_delete(env, next, (const struct dt_key *)name,
783 static inline int mdo_declare_ref_add(const struct lu_env *env,
784 struct mdd_object *obj,
785 struct thandle *handle)
787 struct dt_object *next = mdd_object_child(obj);
788 return dt_declare_ref_add(env, next, handle);
791 static inline int mdo_ref_add(const struct lu_env *env, struct mdd_object *obj,
792 struct thandle *handle)
794 struct dt_object *next = mdd_object_child(obj);
795 if (mdd_object_exists(obj) == 0) {
796 CERROR("%s: object "DFID" not found: rc = -2\n",
797 mdd_obj_dev_name(obj), PFID(mdd_object_fid(obj)));
800 return next->do_ops->do_ref_add(env, next, handle);
803 static inline int mdo_declare_ref_del(const struct lu_env *env,
804 struct mdd_object *obj,
805 struct thandle *handle)
807 struct dt_object *next = mdd_object_child(obj);
808 return dt_declare_ref_del(env, next, handle);
811 static inline int mdo_ref_del(const struct lu_env *env, struct mdd_object *obj,
812 struct thandle *handle)
814 struct dt_object *next = mdd_object_child(obj);
815 if (mdd_object_exists(obj) == 0) {
816 CERROR("%s: object "DFID" not found: rc = -2\n",
817 mdd_obj_dev_name(obj), PFID(mdd_object_fid(obj)));
820 return next->do_ops->do_ref_del(env, next, handle);
824 int mdo_declare_create_obj(const struct lu_env *env, struct mdd_object *o,
825 struct lu_attr *attr,
826 struct dt_allocation_hint *hint,
827 struct dt_object_format *dof,
828 struct thandle *handle)
830 struct dt_object *next = mdd_object_child(o);
831 return next->do_ops->do_declare_create(env, next, attr, hint,
836 int mdo_create_obj(const struct lu_env *env, struct mdd_object *o,
837 struct lu_attr *attr,
838 struct dt_allocation_hint *hint,
839 struct dt_object_format *dof,
840 struct thandle *handle)
842 struct dt_object *next = mdd_object_child(o);
845 rc = next->do_ops->do_create(env, next, attr, hint, dof, handle);
851 int mdo_declare_destroy(const struct lu_env *env, struct mdd_object *o,
852 struct thandle *handle)
854 struct dt_object *next = mdd_object_child(o);
855 return dt_declare_destroy(env, next, handle);
859 int mdo_destroy(const struct lu_env *env, struct mdd_object *o,
860 struct thandle *handle)
862 struct dt_object *next = mdd_object_child(o);
863 return dt_destroy(env, next, handle);
866 static inline struct obd_capa *mdo_capa_get(const struct lu_env *env,
867 struct mdd_object *obj,
868 struct lustre_capa *old,
871 struct dt_object *next = mdd_object_child(obj);
872 if (mdd_object_exists(obj) == 0) {
873 CERROR("%s: object "DFID" not found: rc = -2\n",
874 mdd_obj_dev_name(obj), PFID(mdd_object_fid(obj)));
875 return ERR_PTR(-ENOENT);
877 return next->do_ops->do_capa_get(env, next, old, opc);