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>
56 /** changelog is recording */
57 #define CLM_ON 0x00001
58 /** internal error prevented changelogs from starting */
59 #define CLM_ERR 0x00002
61 /** changelogs turned on */
62 #define CLM_START 0x10000
63 /** changelogs turned off */
64 #define CLM_FINI 0x20000
65 /** some changelog records purged */
66 #define CLM_PURGE 0x40000
68 struct mdd_changelog {
69 spinlock_t mc_lock; /* for index */
74 spinlock_t mc_user_lock;
78 static inline __u64 cl_time(void) {
81 cfs_fs_time_current(&time);
82 return (((__u64)time.tv_sec) << 30) + time.tv_nsec;
85 /** Objects in .lustre dir */
86 struct mdd_dot_lustre_objs {
87 struct mdd_object *mdd_obf;
91 struct md_device mdd_md_dev;
92 struct obd_export *mdd_child_exp;
93 struct dt_device *mdd_child;
94 struct dt_device *mdd_bottom;
95 struct lu_fid mdd_root_fid; /* /ROOT */
96 struct lu_fid mdd_local_root_fid;
97 struct dt_device_param mdd_dt_conf;
98 struct dt_object *mdd_orphans; /* PENDING directory */
99 cfs_proc_dir_entry_t *mdd_proc_entry;
100 struct mdd_changelog mdd_cl;
101 unsigned long mdd_atime_diff;
102 struct mdd_object *mdd_dot_lustre;
103 struct mdd_dot_lustre_objs mdd_dot_lustre_objs;
104 unsigned int mdd_sync_permission;
106 struct local_oid_storage *mdd_los;
110 /* The dir object has been unlinked */
118 struct md_object mod_obj;
123 unsigned long mod_flags;
124 #ifdef CONFIG_LOCKDEP
125 /* "dep_map" name is assumed by lockdep.h macros. */
126 struct lockdep_map dep_map;
130 struct mdd_thread_info {
131 struct lu_fid mti_fid;
132 struct lu_fid mti_fid2; /* used for be & cpu converting */
134 * only be used by MDD interfaces, can be passed into local MDD APIs.
136 struct lu_attr mti_pattr;
137 struct lu_attr mti_cattr;
138 struct lu_attr mti_tpattr;
139 struct lu_attr mti_tattr;
140 /** used to set c/mtime */
141 struct lu_attr mti_la_for_fix;
142 struct md_attr mti_ma;
143 struct obd_info mti_oi;
144 /* mti_ent and mti_key must be conjoint,
145 * then mti_ent::lde_name will be mti_key. */
146 struct lu_dirent mti_ent;
147 char mti_key[NAME_MAX + 16];
148 struct obd_trans_info mti_oti;
149 struct lu_buf mti_buf[4];
150 struct lu_buf mti_big_buf; /* biggish persistent buf */
151 struct lu_buf mti_link_buf; /* buf for link ea */
152 struct lu_name mti_name;
153 struct lu_name mti_name2;
155 char mti_xattr_buf[LUSTRE_POSIX_ACL_MAX_SIZE];
156 struct dt_allocation_hint mti_hint;
157 struct lov_mds_md *mti_max_lmm;
158 int mti_max_lmm_size;
159 struct llog_cookie *mti_max_cookie;
160 int mti_max_cookie_size;
161 struct dt_object_format mti_dof;
162 struct obd_quotactl mti_oqctl;
163 struct linkea_data mti_link_data;
166 extern const char orph_index_name[];
168 extern const struct dt_index_features orph_index_features;
170 struct lov_mds_md *mdd_max_lmm_buffer(const struct lu_env *env, int size);
171 struct lov_mds_md *mdd_max_lmm_get(const struct lu_env *env,
172 struct mdd_device *mdd);
174 struct llog_cookie *mdd_max_cookie_get(const struct lu_env *env,
175 struct mdd_device *mdd);
177 int mdd_init_obd(const struct lu_env *env, struct mdd_device *mdd,
178 struct lustre_cfg *cfg);
179 int mdd_fini_obd(const struct lu_env *env, struct mdd_device *mdd,
180 struct lustre_cfg *lcfg);
181 int __mdd_xattr_set(const struct lu_env *env, struct mdd_object *obj,
182 const struct lu_buf *buf, const char *name,
183 int fl, struct thandle *handle);
184 int mdd_xattr_set_txn(const struct lu_env *env, struct mdd_object *obj,
185 const struct lu_buf *buf, const char *name, int fl,
186 struct thandle *txn);
187 int mdd_lsm_sanity_check(const struct lu_env *env, struct mdd_object *obj);
188 int mdd_lov_set_md(const struct lu_env *env, struct mdd_object *pobj,
189 struct mdd_object *child, struct lov_mds_md *lmm,
190 int lmm_size, struct thandle *handle, int set_stripe);
191 int mdd_lov_create(const struct lu_env *env, struct mdd_device *mdd,
192 struct mdd_object *parent, struct mdd_object *child,
193 struct lov_mds_md **lmm, int *lmm_size,
194 const struct md_op_spec *spec, struct md_attr *ma);
195 int mdd_lov_objid_prepare(struct mdd_device *mdd, struct lov_mds_md *lmm);
196 int mdd_declare_lov_objid_update(const struct lu_env *, struct mdd_device *,
198 void mdd_lov_objid_update(struct mdd_device *mdd, struct lov_mds_md *lmm);
199 void mdd_lov_create_finish(const struct lu_env *env, struct mdd_device *mdd,
200 struct lov_mds_md *lmm, int lmm_size,
201 const struct md_op_spec *spec);
202 int mdd_file_lock(const struct lu_env *env, struct md_object *obj,
203 struct lov_mds_md *lmm, struct ldlm_extent *extent,
204 struct lustre_handle *lockh);
205 int mdd_file_unlock(const struct lu_env *env, struct md_object *obj,
206 struct lov_mds_md *lmm, struct lustre_handle *lockh);
207 int mdd_lum_lmm_cmp(const struct lu_env *env, struct md_object *cobj,
208 const struct md_op_spec *spec, struct md_attr *ma);
209 int mdd_get_md(const struct lu_env *env, struct mdd_object *obj,
210 void *md, int *md_size, const char *name);
211 int mdd_get_md_locked(const struct lu_env *env, struct mdd_object *obj,
212 void *md, int *md_size, const char *name);
213 int mdd_data_get(const struct lu_env *env, struct mdd_object *obj, void **data);
214 int mdd_la_get(const struct lu_env *env, struct mdd_object *obj,
215 struct lu_attr *la, struct lustre_capa *capa);
216 int mdd_attr_get(const struct lu_env *env, struct md_object *obj,
218 int mdd_attr_set(const struct lu_env *env, struct md_object *obj,
219 const struct md_attr *ma);
220 int mdd_attr_set_internal(const struct lu_env *env,
221 struct mdd_object *obj,
222 const struct lu_attr *attr,
223 struct thandle *handle,
225 int mdd_update_time(const struct lu_env *env, struct mdd_object *obj,
226 const struct lu_attr *oattr, struct lu_attr *attr,
227 struct thandle *handle);
228 int mdd_declare_object_kill(const struct lu_env *env, struct mdd_object *obj,
229 struct md_attr *ma, struct thandle *handle);
230 int mdd_object_kill(const struct lu_env *env, struct mdd_object *obj,
231 struct md_attr *ma, struct thandle *handle);
232 int mdd_iattr_get(const struct lu_env *env, struct mdd_object *mdd_obj,
234 int mdd_object_create_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 int mdd_lmm_get_locked(const struct lu_env *env, struct mdd_object *mdd_obj,
242 void mdd_write_lock(const struct lu_env *env, struct mdd_object *obj,
243 enum mdd_object_role role);
244 void mdd_read_lock(const struct lu_env *env, struct mdd_object *obj,
245 enum mdd_object_role role);
246 void mdd_write_unlock(const struct lu_env *env, struct mdd_object *obj);
247 void mdd_read_unlock(const struct lu_env *env, struct mdd_object *obj);
248 int mdd_write_locked(const struct lu_env *env, struct mdd_object *obj);
250 unsigned long mdd_name2hash(const char *name);
251 void *mdd_pdo_write_lock(const struct lu_env *env, struct mdd_object *obj,
252 const char *name, enum mdd_object_role role);
253 void mdd_pdo_write_unlock(const struct lu_env *env, struct mdd_object *obj,
256 int mdd_is_subdir(const struct lu_env *env, struct md_object *mo,
257 const struct lu_fid *fid, struct lu_fid *sfid);
258 int mdd_may_create(const struct lu_env *env, struct mdd_object *pobj,
259 const struct lu_attr *pattr, struct mdd_object *cobj,
260 int check_perm, int check_nlink);
261 int mdd_may_unlink(const struct lu_env *env, struct mdd_object *pobj,
262 const struct lu_attr *pattr, const struct lu_attr *attr);
263 int mdd_may_delete(const struct lu_env *env, struct mdd_object *tpobj,
264 const struct lu_attr *tpattr, struct mdd_object *tobj,
265 const struct lu_attr *tattr, const struct lu_attr *cattr,
266 int check_perm, int check_empty);
267 int mdd_unlink_sanity_check(const struct lu_env *env, struct mdd_object *pobj,
268 const struct lu_attr *pattr,
269 struct mdd_object *cobj,
270 const struct lu_attr *cattr);
271 int mdd_finish_unlink(const struct lu_env *env, struct mdd_object *obj,
272 struct md_attr *ma, struct thandle *th);
274 int mdd_is_root(struct mdd_device *mdd, const struct lu_fid *fid);
275 int mdd_lookup(const struct lu_env *env,
276 struct md_object *pobj, const struct lu_name *lname,
277 struct lu_fid* fid, struct md_op_spec *spec);
278 int mdd_links_read(const struct lu_env *env, struct mdd_object *mdd_obj,
279 struct linkea_data *ldata);
280 int mdd_declare_links_add(const struct lu_env *env, struct mdd_object *mdd_obj,
281 struct thandle *handle, struct linkea_data *ldata);
282 int mdd_links_write(const struct lu_env *env, struct mdd_object *mdd_obj,
283 struct linkea_data *ldata, struct thandle *handle);
284 struct lu_buf *mdd_links_get(const struct lu_env *env,
285 struct mdd_object *mdd_obj);
286 int mdd_links_rename(const struct lu_env *env,
287 struct mdd_object *mdd_obj,
288 const struct lu_fid *oldpfid,
289 const struct lu_name *oldlname,
290 const struct lu_fid *newpfid,
291 const struct lu_name *newlname,
292 struct thandle *handle,
293 struct linkea_data *ldata,
294 int first, int check);
295 int mdd_declare_links_add(const struct lu_env *env, struct mdd_object *mdd_obj,
296 struct thandle *handle, struct linkea_data *ldata);
299 int mdd_declare_unlink_log(const struct lu_env *env, struct mdd_object *obj,
300 struct md_attr *ma, struct thandle *handle);
301 int mdd_unlink_log(const struct lu_env *env, struct mdd_device *mdd,
302 struct mdd_object *mdd_cobj, struct md_attr *ma);
304 int mdd_setattr_log(const struct lu_env *env, struct mdd_device *mdd,
305 const struct md_attr *ma,
306 struct lov_mds_md *lmm, int lmm_size,
307 struct llog_cookie *logcookies, int cookies_size);
309 int mdd_get_cookie_size(const struct lu_env *env, struct mdd_device *mdd,
310 struct lov_mds_md *lmm);
312 int mdd_lov_setattr_async(const struct lu_env *env, struct mdd_object *obj,
313 struct lov_mds_md *lmm, int lmm_size,
314 struct llog_cookie *logcookies);
316 int mdd_lovobj_unlink(const struct lu_env *env, struct mdd_device *mdd,
317 struct mdd_object *obj, struct lu_attr *la,
318 struct md_attr *ma, int log_unlink);
320 struct mdd_thread_info *mdd_env_info(const struct lu_env *env);
322 #define MDD_ENV_VAR(env, var) (&mdd_env_info(env)->mti_##var)
324 const struct lu_name *mdd_name_get_const(const struct lu_env *env,
325 const void *area, ssize_t len);
326 struct lu_buf *mdd_buf_get(const struct lu_env *env, void *area, ssize_t len);
327 const struct lu_buf *mdd_buf_get_const(const struct lu_env *env,
328 const void *area, ssize_t len);
330 int __mdd_orphan_cleanup(const struct lu_env *env, struct mdd_device *d);
331 int __mdd_orphan_add(const struct lu_env *, struct mdd_object *,
333 int __mdd_orphan_del(const struct lu_env *, struct mdd_object *,
335 int orph_index_init(const struct lu_env *env, struct mdd_device *mdd);
336 void orph_index_fini(const struct lu_env *env, struct mdd_device *mdd);
337 int orph_declare_index_insert(const struct lu_env *, struct mdd_object *,
338 umode_t mode, struct thandle *);
339 int orph_declare_index_delete(const struct lu_env *, struct mdd_object *,
343 void lprocfs_mdd_init_vars(struct lprocfs_static_vars *lvars);
344 int mdd_procfs_init(struct mdd_device *mdd, const char *name);
345 int mdd_procfs_fini(struct mdd_device *mdd);
348 struct lu_buf *mdd_buf_alloc(const struct lu_env *env, ssize_t len);
349 int mdd_buf_grow(const struct lu_env *env, ssize_t len);
350 void mdd_buf_put(struct lu_buf *buf);
352 struct lu_buf *mdd_link_buf_alloc(const struct lu_env *env, ssize_t len);
353 int mdd_link_buf_grow(const struct lu_env *env, ssize_t len);
354 extern const struct md_dir_operations mdd_dir_ops;
355 extern const struct md_object_operations mdd_obj_ops;
357 int accmode(const struct lu_env *env, const struct lu_attr *la, int flags);
358 extern struct lu_context_key mdd_thread_key;
359 extern const struct lu_device_operations mdd_lu_ops;
361 struct mdd_object *mdd_object_find(const struct lu_env *env,
362 struct mdd_device *d,
363 const struct lu_fid *f);
364 int mdd_get_default_md(struct mdd_object *mdd_obj, struct lov_mds_md *lmm);
365 int mdd_readpage(const struct lu_env *env, struct md_object *obj,
366 const struct lu_rdpg *rdpg);
367 int mdd_declare_changelog_store(const struct lu_env *env,
368 struct mdd_device *mdd,
369 const struct lu_name *fname,
370 struct thandle *handle);
371 int mdd_changelog_store(const struct lu_env *env, struct mdd_device *mdd,
372 struct llog_changelog_rec *rec, struct thandle *th);
373 int mdd_changelog_data_store(const struct lu_env *env, struct mdd_device *mdd,
374 enum changelog_rec_type type, int flags,
375 struct mdd_object *mdd_obj,
376 struct thandle *handle);
377 int mdd_changelog_ns_store(const struct lu_env *env, struct mdd_device *mdd,
378 enum changelog_rec_type type, unsigned flags,
379 struct mdd_object *target, struct mdd_object *parent,
380 const struct lu_name *tname, struct thandle *handle);
381 int mdd_declare_object_create_internal(const struct lu_env *env,
382 struct mdd_object *p,
383 struct mdd_object *c,
384 struct lu_attr *attr,
385 struct thandle *handle,
386 const struct md_op_spec *spec);
389 int mdd_lov_destroy(const struct lu_env *env, struct mdd_device *mdd,
390 struct mdd_object *obj, struct lu_attr *la);
392 void mdd_object_make_hint(const struct lu_env *env, struct mdd_object *parent,
393 struct mdd_object *child, struct lu_attr *attr);
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 void mdd_trans_stop(const struct lu_env *env, struct mdd_device *mdd,
411 int rc, struct thandle *handle);
412 int mdd_txn_stop_cb(const struct lu_env *env, struct thandle *txn,
414 int mdd_txn_start_cb(const struct lu_env *env, struct thandle *,
418 struct lu_object *mdd_object_alloc(const struct lu_env *env,
419 const struct lu_object_header *hdr,
420 struct lu_device *d);
421 int mdd_local_file_create(const struct lu_env *env, struct mdd_device *mdd,
422 const struct lu_fid *pfid, const char *name,
423 __u32 mode, struct lu_fid *fid);
425 int mdd_acl_chmod(const struct lu_env *env, struct mdd_object *o, __u32 mode,
426 struct thandle *handle);
427 int __mdd_declare_acl_init(const struct lu_env *env, struct mdd_object *obj,
428 int is_dir, struct thandle *handle);
429 int mdd_acl_set(const struct lu_env *env, struct mdd_object *obj,
430 struct lu_attr *attr, const struct lu_buf *buf, int fl);
431 int __mdd_fix_mode_acl(const struct lu_env *env, struct lu_buf *buf,
433 int __mdd_permission_internal(const struct lu_env *env, struct mdd_object *obj,
434 const struct lu_attr *la, int mask, int role);
435 int mdd_permission(const struct lu_env *env,
436 struct md_object *pobj, struct md_object *cobj,
437 struct md_attr *ma, int mask);
438 int mdd_capa_get(const struct lu_env *env, struct md_object *obj,
439 struct lustre_capa *capa, int renewal);
442 int mdd_compat_fixes(const struct lu_env *env, struct mdd_device *mdd);
444 /* inline functions */
445 static inline int lu_device_is_mdd(struct lu_device *d)
447 return ergo(d != NULL && d->ld_ops != NULL, d->ld_ops == &mdd_lu_ops);
450 static inline struct mdd_device* lu2mdd_dev(struct lu_device *d)
452 LASSERT(lu_device_is_mdd(d));
453 return container_of0(d, struct mdd_device, mdd_md_dev.md_lu_dev);
456 static inline struct lu_device *mdd2lu_dev(struct mdd_device *d)
458 return (&d->mdd_md_dev.md_lu_dev);
461 static inline struct mdd_object *lu2mdd_obj(struct lu_object *o)
463 LASSERT(ergo(o != NULL, lu_device_is_mdd(o->lo_dev)));
464 return container_of0(o, struct mdd_object, mod_obj.mo_lu);
467 static inline struct mdd_device* mdo2mdd(struct md_object *mdo)
469 return lu2mdd_dev(mdo->mo_lu.lo_dev);
472 static inline struct mdd_object* md2mdd_obj(struct md_object *mdo)
474 return container_of0(mdo, struct mdd_object, mod_obj);
477 static inline const struct dt_device_operations *
478 mdd_child_ops(struct mdd_device *d)
480 return d->mdd_child->dd_ops;
483 static inline struct lu_object *mdd2lu_obj(struct mdd_object *obj)
485 return &obj->mod_obj.mo_lu;
488 static inline struct dt_object* mdd_object_child(struct mdd_object *o)
490 return container_of0(lu_object_next(mdd2lu_obj(o)),
491 struct dt_object, do_lu);
494 static inline struct obd_device *mdd2obd_dev(struct mdd_device *mdd)
496 return (mdd->mdd_md_dev.md_lu_dev.ld_obd);
499 static inline struct mdd_device *mdd_obj2mdd_dev(struct mdd_object *obj)
501 return mdo2mdd(&obj->mod_obj);
504 static inline const struct lu_fid *mdo2fid(const struct mdd_object *obj)
506 return lu_object_fid(&obj->mod_obj.mo_lu);
509 static inline int mdd_object_obf(const struct mdd_object *obj)
511 return lu_fid_eq(mdo2fid(obj), &LU_OBF_FID);
514 static inline umode_t mdd_object_type(const struct mdd_object *obj)
516 return lu_object_attr(&obj->mod_obj.mo_lu);
519 static inline int mdd_is_immutable(struct mdd_object *obj)
521 return obj->mod_flags & IMMUTE_OBJ;
524 static inline int mdd_is_dead_obj(struct mdd_object *obj)
526 return obj && obj->mod_flags & DEAD_OBJ;
529 static inline int mdd_is_append(struct mdd_object *obj)
531 return obj->mod_flags & APPEND_OBJ;
534 static inline int mdd_object_exists(struct mdd_object *obj)
536 return lu_object_exists(mdd2lu_obj(obj));
539 static inline int mdd_object_remote(struct mdd_object *obj)
541 return lu_object_remote(mdd2lu_obj(obj));
544 static inline const struct lu_fid *mdd_object_fid(struct mdd_object *obj)
546 return lu_object_fid(mdd2lu_obj(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 struct lustre_capa *mdd_object_capa(const struct lu_env *env,
555 const struct mdd_object *obj)
557 struct lu_capainfo *lci = lu_capainfo_get(env);
558 const struct lu_fid *fid = mdo2fid(obj);
561 /* NB: in mdt_init0 */
565 for (i = 0; i < LU_CAPAINFO_MAX; i++)
566 if (lu_fid_eq(&lci->lci_fid[i], fid))
567 return lci->lci_capa[i];
571 static inline void mdd_set_capainfo(const struct lu_env *env, int offset,
572 const struct mdd_object *obj,
573 struct lustre_capa *capa)
575 struct lu_capainfo *lci = lu_capainfo_get(env);
576 const struct lu_fid *fid = mdo2fid(obj);
578 LASSERT(offset >= 0 && offset < LU_CAPAINFO_MAX);
579 /* NB: in mdt_init0 */
583 lci->lci_fid[offset] = *fid;
584 lci->lci_capa[offset] = capa;
587 static inline const char *mdd_obj_dev_name(const struct mdd_object *obj)
589 return lu_dev_name(obj->mod_obj.mo_lu.lo_dev);
592 #define MAX_ATIME_DIFF 60
598 static inline int mdd_permission_internal(const struct lu_env *env,
599 struct mdd_object *obj,
600 const struct lu_attr *la, int mask)
602 return __mdd_permission_internal(env, obj, la, mask, -1);
605 static inline int mdd_permission_internal_locked(const struct lu_env *env,
606 struct mdd_object *obj,
607 const struct lu_attr *la,
609 enum mdd_object_role role)
611 return __mdd_permission_internal(env, obj, la, mask, role);
614 static inline int mdo_data_get(const struct lu_env *env,
615 struct mdd_object *obj,
618 struct dt_object *next = mdd_object_child(obj);
619 next->do_ops->do_data_get(env, next, data);
623 /* mdd inline func for calling osd_dt_object ops */
624 static inline int mdo_attr_get(const struct lu_env *env, struct mdd_object *obj,
625 struct lu_attr *la, struct lustre_capa *capa)
627 struct dt_object *next = mdd_object_child(obj);
628 return next->do_ops->do_attr_get(env, next, la, capa);
631 static inline int mdo_declare_attr_set(const struct lu_env *env,
632 struct mdd_object *obj,
633 const struct lu_attr *la,
634 struct thandle *handle)
636 struct dt_object *next = mdd_object_child(obj);
637 return dt_declare_attr_set(env, next, la, handle);
640 static inline int mdo_attr_set(const struct lu_env *env,
641 struct mdd_object *obj,
642 const struct lu_attr *la,
643 struct thandle *handle,
644 struct lustre_capa *capa)
646 struct dt_object *next = mdd_object_child(obj);
647 if (mdd_object_exists(obj) == 0) {
648 CERROR("%s: object "DFID" not found: rc = -2\n",
649 mdd_obj_dev_name(obj), PFID(mdd_object_fid(obj)));
652 return next->do_ops->do_attr_set(env, next, la, handle, capa);
655 static inline int mdo_xattr_get(const struct lu_env *env,struct mdd_object *obj,
656 struct lu_buf *buf, const char *name,
657 struct lustre_capa *capa)
659 struct dt_object *next = mdd_object_child(obj);
660 return next->do_ops->do_xattr_get(env, next, buf, name, capa);
663 static inline int mdo_declare_xattr_set(const struct lu_env *env,
664 struct mdd_object *obj,
665 const struct lu_buf *buf,
667 int fl, struct thandle *handle)
669 struct dt_object *next = mdd_object_child(obj);
670 return dt_declare_xattr_set(env, next, buf, name, fl, handle);
673 static inline int mdo_xattr_set(const struct lu_env *env,struct mdd_object *obj,
674 const struct lu_buf *buf, const char *name,
675 int fl, struct thandle *handle,
676 struct lustre_capa *capa)
678 struct dt_object *next = mdd_object_child(obj);
679 if (mdd_object_exists(obj) == 0) {
680 CERROR("%s: object "DFID" not found: rc = -2\n",
681 mdd_obj_dev_name(obj), PFID(mdd_object_fid(obj)));
684 return next->do_ops->do_xattr_set(env, next, buf, name, fl, handle,
688 static inline int mdo_declare_xattr_del(const struct lu_env *env,
689 struct mdd_object *obj,
691 struct thandle *handle)
693 struct dt_object *next = mdd_object_child(obj);
694 return dt_declare_xattr_del(env, next, name, handle);
697 static inline int mdo_xattr_del(const struct lu_env *env,struct mdd_object *obj,
698 const char *name, struct thandle *handle,
699 struct lustre_capa *capa)
701 struct dt_object *next = mdd_object_child(obj);
702 if (mdd_object_exists(obj) == 0) {
703 CERROR("%s: object "DFID" not found: rc = -2\n",
704 mdd_obj_dev_name(obj), PFID(mdd_object_fid(obj)));
707 return next->do_ops->do_xattr_del(env, next, name, handle, capa);
711 int mdo_xattr_list(const struct lu_env *env, struct mdd_object *obj,
712 struct lu_buf *buf, struct lustre_capa *capa)
714 struct dt_object *next = mdd_object_child(obj);
715 if (mdd_object_exists(obj) == 0) {
716 CERROR("%s: object "DFID" not found: rc = -2\n",
717 mdd_obj_dev_name(obj), PFID(mdd_object_fid(obj)));
720 return next->do_ops->do_xattr_list(env, next, buf, capa);
724 int mdo_index_try(const struct lu_env *env, struct mdd_object *obj,
725 const struct dt_index_features *feat)
727 struct dt_object *next = mdd_object_child(obj);
728 return next->do_ops->do_index_try(env, next, feat);
732 int mdo_declare_index_insert(const struct lu_env *env, struct mdd_object *obj,
733 const struct lu_fid *fid, const char *name,
734 struct thandle *handle)
736 struct dt_object *next = mdd_object_child(obj);
740 * if the object doesn't exist yet, then it's supposed to be created
741 * and declaration of the creation should be enough to insert ./..
743 /* FIXME: remote object should not be awared by MDD layer, but local
744 * creation does not declare insert ./.. (comments above), which
745 * is required by remote directory creation.
746 * This remote check should be removed when mdd_object_exists check is
749 if (mdd_object_exists(obj) || mdd_object_remote(obj)) {
751 if (dt_try_as_dir(env, next))
752 rc = dt_declare_insert(env, next,
753 (struct dt_rec *)fid,
754 (const struct dt_key *)name,
762 int mdo_declare_index_delete(const struct lu_env *env, struct mdd_object *obj,
763 const char *name, struct thandle *handle)
765 struct dt_object *next = mdd_object_child(obj);
767 if (!dt_try_as_dir(env, next))
770 return dt_declare_delete(env, next, (const struct dt_key *)name,
774 static inline int mdo_declare_ref_add(const struct lu_env *env,
775 struct mdd_object *obj,
776 struct thandle *handle)
778 struct dt_object *next = mdd_object_child(obj);
779 return dt_declare_ref_add(env, next, handle);
782 static inline int mdo_ref_add(const struct lu_env *env, struct mdd_object *obj,
783 struct thandle *handle)
785 struct dt_object *next = mdd_object_child(obj);
786 if (mdd_object_exists(obj) == 0) {
787 CERROR("%s: object "DFID" not found: rc = -2\n",
788 mdd_obj_dev_name(obj), PFID(mdd_object_fid(obj)));
791 return next->do_ops->do_ref_add(env, next, handle);
794 static inline int mdo_declare_ref_del(const struct lu_env *env,
795 struct mdd_object *obj,
796 struct thandle *handle)
798 struct dt_object *next = mdd_object_child(obj);
799 return dt_declare_ref_del(env, next, handle);
802 static inline int mdo_ref_del(const struct lu_env *env, struct mdd_object *obj,
803 struct thandle *handle)
805 struct dt_object *next = mdd_object_child(obj);
806 if (mdd_object_exists(obj) == 0) {
807 CERROR("%s: object "DFID" not found: rc = -2\n",
808 mdd_obj_dev_name(obj), PFID(mdd_object_fid(obj)));
811 return next->do_ops->do_ref_del(env, next, handle);
815 int mdo_declare_create_obj(const struct lu_env *env, struct mdd_object *o,
816 struct lu_attr *attr,
817 struct dt_allocation_hint *hint,
818 struct dt_object_format *dof,
819 struct thandle *handle)
821 struct dt_object *next = mdd_object_child(o);
822 return next->do_ops->do_declare_create(env, next, attr, hint,
827 int mdo_create_obj(const struct lu_env *env, struct mdd_object *o,
828 struct lu_attr *attr,
829 struct dt_allocation_hint *hint,
830 struct dt_object_format *dof,
831 struct thandle *handle)
833 struct dt_object *next = mdd_object_child(o);
836 rc = next->do_ops->do_create(env, next, attr, hint, dof, handle);
842 int mdo_declare_destroy(const struct lu_env *env, struct mdd_object *o,
843 struct thandle *handle)
845 struct dt_object *next = mdd_object_child(o);
846 return dt_declare_destroy(env, next, handle);
850 int mdo_destroy(const struct lu_env *env, struct mdd_object *o,
851 struct thandle *handle)
853 struct dt_object *next = mdd_object_child(o);
854 return dt_destroy(env, next, handle);
857 static inline struct obd_capa *mdo_capa_get(const struct lu_env *env,
858 struct mdd_object *obj,
859 struct lustre_capa *old,
862 struct dt_object *next = mdd_object_child(obj);
863 if (mdd_object_exists(obj) == 0) {
864 CERROR("%s: object "DFID" not found: rc = -2\n",
865 mdd_obj_dev_name(obj), PFID(mdd_object_fid(obj)));
866 return ERR_PTR(-ENOENT);
868 return next->do_ops->do_capa_get(env, next, old, opc);