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;
88 struct mdd_object *mdd_lpf;
92 struct md_device mdd_md_dev;
93 struct obd_export *mdd_child_exp;
94 struct dt_device *mdd_child;
95 struct dt_device *mdd_bottom;
96 struct lu_fid mdd_root_fid; /* /ROOT */
97 struct lu_fid mdd_local_root_fid;
98 struct dt_device_param mdd_dt_conf;
99 struct dt_object *mdd_orphans; /* PENDING directory */
100 cfs_proc_dir_entry_t *mdd_proc_entry;
101 struct mdd_changelog mdd_cl;
102 unsigned long mdd_atime_diff;
103 struct mdd_object *mdd_dot_lustre;
104 struct mdd_dot_lustre_objs mdd_dot_lustre_objs;
105 unsigned int mdd_sync_permission;
107 struct local_oid_storage *mdd_los;
111 /* The dir object has been unlinked */
119 struct md_object mod_obj;
124 unsigned long mod_flags;
125 #ifdef CONFIG_LOCKDEP
126 /* "dep_map" name is assumed by lockdep.h macros. */
127 struct lockdep_map dep_map;
131 struct mdd_thread_info {
132 struct lu_fid mti_fid;
133 struct lu_fid mti_fid2; /* used for be & cpu converting */
135 * only be used by MDD interfaces, can be passed into local MDD APIs.
137 struct lu_attr mti_pattr;
138 struct lu_attr mti_cattr;
139 struct lu_attr mti_tpattr;
140 struct lu_attr mti_tattr;
141 /** used to set c/mtime */
142 struct lu_attr mti_la_for_fix;
143 /* Only used in mdd_object_start */
144 struct lu_attr mti_la_for_start;
145 struct md_attr mti_ma;
146 struct obd_info mti_oi;
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 obd_trans_info mti_oti;
152 struct lu_buf mti_buf[4];
153 struct lu_buf mti_big_buf; /* biggish persistent buf */
154 struct lu_buf mti_link_buf; /* buf for link ea */
155 struct lu_name mti_name;
156 struct lu_name mti_name2;
158 char mti_xattr_buf[LUSTRE_POSIX_ACL_MAX_SIZE];
159 struct dt_allocation_hint mti_hint;
160 struct lov_mds_md *mti_max_lmm;
161 int mti_max_lmm_size;
162 struct llog_cookie *mti_max_cookie;
163 int mti_max_cookie_size;
164 struct dt_object_format mti_dof;
165 struct obd_quotactl mti_oqctl;
166 struct linkea_data mti_link_data;
169 extern const char orph_index_name[];
171 extern const struct dt_index_features orph_index_features;
173 struct lov_mds_md *mdd_max_lmm_buffer(const struct lu_env *env, int size);
174 struct lov_mds_md *mdd_max_lmm_get(const struct lu_env *env,
175 struct mdd_device *mdd);
177 struct llog_cookie *mdd_max_cookie_get(const struct lu_env *env,
178 struct mdd_device *mdd);
180 int mdd_init_obd(const struct lu_env *env, struct mdd_device *mdd,
181 struct lustre_cfg *cfg);
182 int mdd_fini_obd(const struct lu_env *env, struct mdd_device *mdd,
183 struct lustre_cfg *lcfg);
184 int __mdd_xattr_set(const struct lu_env *env, struct mdd_object *obj,
185 const struct lu_buf *buf, const char *name,
186 int fl, struct thandle *handle);
187 int mdd_xattr_set_txn(const struct lu_env *env, struct mdd_object *obj,
188 const struct lu_buf *buf, const char *name, int fl,
189 struct thandle *txn);
190 int mdd_lsm_sanity_check(const struct lu_env *env, struct mdd_object *obj);
191 int mdd_lov_set_md(const struct lu_env *env, struct mdd_object *pobj,
192 struct mdd_object *child, struct lov_mds_md *lmm,
193 int lmm_size, struct thandle *handle, int set_stripe);
194 int mdd_lov_create(const struct lu_env *env, struct mdd_device *mdd,
195 struct mdd_object *parent, struct mdd_object *child,
196 struct lov_mds_md **lmm, int *lmm_size,
197 const struct md_op_spec *spec, struct md_attr *ma);
198 int mdd_lov_objid_prepare(struct mdd_device *mdd, struct lov_mds_md *lmm);
199 int mdd_declare_lov_objid_update(const struct lu_env *, struct mdd_device *,
201 void mdd_lov_objid_update(struct mdd_device *mdd, struct lov_mds_md *lmm);
202 void mdd_lov_create_finish(const struct lu_env *env, struct mdd_device *mdd,
203 struct lov_mds_md *lmm, int lmm_size,
204 const struct md_op_spec *spec);
205 int mdd_file_lock(const struct lu_env *env, struct md_object *obj,
206 struct lov_mds_md *lmm, struct ldlm_extent *extent,
207 struct lustre_handle *lockh);
208 int mdd_file_unlock(const struct lu_env *env, struct md_object *obj,
209 struct lov_mds_md *lmm, struct lustre_handle *lockh);
210 int mdd_lum_lmm_cmp(const struct lu_env *env, struct md_object *cobj,
211 const struct md_op_spec *spec, struct md_attr *ma);
212 int mdd_get_md(const struct lu_env *env, struct mdd_object *obj,
213 void *md, int *md_size, const char *name);
214 int mdd_get_md_locked(const struct lu_env *env, struct mdd_object *obj,
215 void *md, int *md_size, const char *name);
216 int mdd_data_get(const struct lu_env *env, struct mdd_object *obj, void **data);
217 int mdd_la_get(const struct lu_env *env, struct mdd_object *obj,
218 struct lu_attr *la, struct lustre_capa *capa);
219 int mdd_attr_get(const struct lu_env *env, struct md_object *obj,
221 int mdd_attr_set(const struct lu_env *env, struct md_object *obj,
222 const struct md_attr *ma);
223 int mdd_attr_set_internal(const struct lu_env *env,
224 struct mdd_object *obj,
225 const struct lu_attr *attr,
226 struct thandle *handle,
228 int mdd_update_time(const struct lu_env *env, struct mdd_object *obj,
229 const struct lu_attr *oattr, struct lu_attr *attr,
230 struct thandle *handle);
231 int mdd_declare_object_kill(const struct lu_env *env, struct mdd_object *obj,
232 struct md_attr *ma, struct thandle *handle);
233 int mdd_object_kill(const struct lu_env *env, struct mdd_object *obj,
234 struct md_attr *ma, struct thandle *handle);
235 int mdd_iattr_get(const struct lu_env *env, struct mdd_object *mdd_obj,
237 int mdd_object_create_internal(const struct lu_env *env, struct mdd_object *p,
238 struct mdd_object *c, struct lu_attr *attr,
239 struct thandle *handle,
240 const struct md_op_spec *spec);
241 int mdd_lmm_get_locked(const struct lu_env *env, struct mdd_object *mdd_obj,
245 void mdd_write_lock(const struct lu_env *env, struct mdd_object *obj,
246 enum mdd_object_role role);
247 void mdd_read_lock(const struct lu_env *env, struct mdd_object *obj,
248 enum mdd_object_role role);
249 void mdd_write_unlock(const struct lu_env *env, struct mdd_object *obj);
250 void mdd_read_unlock(const struct lu_env *env, struct mdd_object *obj);
251 int mdd_write_locked(const struct lu_env *env, struct mdd_object *obj);
253 unsigned long mdd_name2hash(const char *name);
254 void *mdd_pdo_write_lock(const struct lu_env *env, struct mdd_object *obj,
255 const char *name, enum mdd_object_role role);
256 void mdd_pdo_write_unlock(const struct lu_env *env, struct mdd_object *obj,
259 int mdd_is_subdir(const struct lu_env *env, struct md_object *mo,
260 const struct lu_fid *fid, struct lu_fid *sfid);
261 int mdd_may_create(const struct lu_env *env, struct mdd_object *pobj,
262 const struct lu_attr *pattr, struct mdd_object *cobj,
263 int check_perm, int check_nlink);
264 int mdd_may_unlink(const struct lu_env *env, struct mdd_object *pobj,
265 const struct lu_attr *pattr, const struct lu_attr *attr);
266 int mdd_may_delete(const struct lu_env *env, struct mdd_object *tpobj,
267 const struct lu_attr *tpattr, struct mdd_object *tobj,
268 const struct lu_attr *tattr, const struct lu_attr *cattr,
269 int check_perm, int check_empty);
270 int mdd_unlink_sanity_check(const struct lu_env *env, struct mdd_object *pobj,
271 const struct lu_attr *pattr,
272 struct mdd_object *cobj,
273 const struct lu_attr *cattr);
274 int mdd_finish_unlink(const struct lu_env *env, struct mdd_object *obj,
275 struct md_attr *ma, struct thandle *th);
277 int mdd_is_root(struct mdd_device *mdd, const struct lu_fid *fid);
278 int mdd_lookup(const struct lu_env *env,
279 struct md_object *pobj, const struct lu_name *lname,
280 struct lu_fid* fid, struct md_op_spec *spec);
281 int mdd_links_read(const struct lu_env *env, struct mdd_object *mdd_obj,
282 struct linkea_data *ldata);
283 int mdd_declare_links_add(const struct lu_env *env, struct mdd_object *mdd_obj,
284 struct thandle *handle, struct linkea_data *ldata);
285 int mdd_links_write(const struct lu_env *env, struct mdd_object *mdd_obj,
286 struct linkea_data *ldata, struct thandle *handle);
287 struct lu_buf *mdd_links_get(const struct lu_env *env,
288 struct mdd_object *mdd_obj);
289 int mdd_links_rename(const struct lu_env *env,
290 struct mdd_object *mdd_obj,
291 const struct lu_fid *oldpfid,
292 const struct lu_name *oldlname,
293 const struct lu_fid *newpfid,
294 const struct lu_name *newlname,
295 struct thandle *handle,
296 struct linkea_data *ldata,
297 int first, int check);
298 int mdd_declare_links_add(const struct lu_env *env, struct mdd_object *mdd_obj,
299 struct thandle *handle, struct linkea_data *ldata);
302 int mdd_declare_unlink_log(const struct lu_env *env, struct mdd_object *obj,
303 struct md_attr *ma, struct thandle *handle);
304 int mdd_unlink_log(const struct lu_env *env, struct mdd_device *mdd,
305 struct mdd_object *mdd_cobj, struct md_attr *ma);
307 int mdd_setattr_log(const struct lu_env *env, struct mdd_device *mdd,
308 const struct md_attr *ma,
309 struct lov_mds_md *lmm, int lmm_size,
310 struct llog_cookie *logcookies, int cookies_size);
312 int mdd_get_cookie_size(const struct lu_env *env, struct mdd_device *mdd,
313 struct lov_mds_md *lmm);
315 int mdd_lov_setattr_async(const struct lu_env *env, struct mdd_object *obj,
316 struct lov_mds_md *lmm, int lmm_size,
317 struct llog_cookie *logcookies);
319 int mdd_lovobj_unlink(const struct lu_env *env, struct mdd_device *mdd,
320 struct mdd_object *obj, struct lu_attr *la,
321 struct md_attr *ma, int log_unlink);
323 struct mdd_thread_info *mdd_env_info(const struct lu_env *env);
325 #define MDD_ENV_VAR(env, var) (&mdd_env_info(env)->mti_##var)
327 const struct lu_name *mdd_name_get_const(const struct lu_env *env,
328 const void *area, ssize_t len);
329 struct lu_buf *mdd_buf_get(const struct lu_env *env, void *area, ssize_t len);
330 const struct lu_buf *mdd_buf_get_const(const struct lu_env *env,
331 const void *area, ssize_t len);
333 int __mdd_orphan_cleanup(const struct lu_env *env, struct mdd_device *d);
334 int __mdd_orphan_add(const struct lu_env *, struct mdd_object *,
336 int __mdd_orphan_del(const struct lu_env *, struct mdd_object *,
338 int orph_index_init(const struct lu_env *env, struct mdd_device *mdd);
339 void orph_index_fini(const struct lu_env *env, struct mdd_device *mdd);
340 int orph_declare_index_insert(const struct lu_env *, struct mdd_object *,
341 umode_t mode, struct thandle *);
342 int orph_declare_index_delete(const struct lu_env *, struct mdd_object *,
346 void lprocfs_mdd_init_vars(struct lprocfs_static_vars *lvars);
347 int mdd_procfs_init(struct mdd_device *mdd, const char *name);
348 int mdd_procfs_fini(struct mdd_device *mdd);
351 struct lu_buf *mdd_buf_alloc(const struct lu_env *env, ssize_t len);
352 int mdd_buf_grow(const struct lu_env *env, ssize_t len);
353 void mdd_buf_put(struct lu_buf *buf);
355 struct lu_buf *mdd_link_buf_alloc(const struct lu_env *env, ssize_t len);
356 int mdd_link_buf_grow(const struct lu_env *env, ssize_t len);
357 extern const struct md_dir_operations mdd_dir_ops;
358 extern const struct md_object_operations mdd_obj_ops;
360 int accmode(const struct lu_env *env, const struct lu_attr *la, int flags);
361 extern struct lu_context_key mdd_thread_key;
362 extern const struct lu_device_operations mdd_lu_ops;
364 struct mdd_object *mdd_object_find(const struct lu_env *env,
365 struct mdd_device *d,
366 const struct lu_fid *f);
367 int mdd_get_default_md(struct mdd_object *mdd_obj, struct lov_mds_md *lmm);
368 int mdd_readpage(const struct lu_env *env, struct md_object *obj,
369 const struct lu_rdpg *rdpg);
370 int mdd_declare_changelog_store(const struct lu_env *env,
371 struct mdd_device *mdd,
372 const struct lu_name *fname,
373 struct thandle *handle);
374 int mdd_changelog_store(const struct lu_env *env, struct mdd_device *mdd,
375 struct llog_changelog_rec *rec, struct thandle *th);
376 int mdd_changelog_data_store(const struct lu_env *env, struct mdd_device *mdd,
377 enum changelog_rec_type type, int flags,
378 struct mdd_object *mdd_obj,
379 struct thandle *handle);
380 int mdd_changelog_ns_store(const struct lu_env *env, struct mdd_device *mdd,
381 enum changelog_rec_type type, unsigned flags,
382 struct mdd_object *target, struct mdd_object *parent,
383 const struct lu_name *tname, struct thandle *handle);
384 int mdd_declare_object_create_internal(const struct lu_env *env,
385 struct mdd_object *p,
386 struct mdd_object *c,
387 struct lu_attr *attr,
388 struct thandle *handle,
389 const struct md_op_spec *spec);
392 int mdd_lov_destroy(const struct lu_env *env, struct mdd_device *mdd,
393 struct mdd_object *obj, struct lu_attr *la);
395 void mdd_object_make_hint(const struct lu_env *env, struct mdd_object *parent,
396 struct mdd_object *child, const struct lu_attr *attr,
397 const struct md_op_spec *spec);
399 static inline void mdd_object_get(struct mdd_object *o)
401 lu_object_get(&o->mod_obj.mo_lu);
404 static inline void mdd_object_put(const struct lu_env *env,
405 struct mdd_object *o)
407 lu_object_put(env, &o->mod_obj.mo_lu);
410 struct thandle *mdd_trans_create(const struct lu_env *env,
411 struct mdd_device *mdd);
412 int mdd_trans_start(const struct lu_env *env, struct mdd_device *mdd,
414 void mdd_trans_stop(const struct lu_env *env, struct mdd_device *mdd,
415 int rc, struct thandle *handle);
416 int mdd_txn_stop_cb(const struct lu_env *env, struct thandle *txn,
418 int mdd_txn_start_cb(const struct lu_env *env, struct thandle *,
422 struct lu_object *mdd_object_alloc(const struct lu_env *env,
423 const struct lu_object_header *hdr,
424 struct lu_device *d);
425 int mdd_local_file_create(const struct lu_env *env, struct mdd_device *mdd,
426 const struct lu_fid *pfid, const char *name,
427 __u32 mode, struct lu_fid *fid);
429 int mdd_acl_chmod(const struct lu_env *env, struct mdd_object *o, __u32 mode,
430 struct thandle *handle);
431 int __mdd_declare_acl_init(const struct lu_env *env, struct mdd_object *obj,
432 int is_dir, struct thandle *handle);
433 int mdd_acl_set(const struct lu_env *env, struct mdd_object *obj,
434 struct lu_attr *attr, const struct lu_buf *buf, int fl);
435 int __mdd_fix_mode_acl(const struct lu_env *env, struct lu_buf *buf,
437 int __mdd_permission_internal(const struct lu_env *env, struct mdd_object *obj,
438 const struct lu_attr *la, int mask, int role);
439 int mdd_permission(const struct lu_env *env,
440 struct md_object *pobj, struct md_object *cobj,
441 struct md_attr *ma, int mask);
442 int mdd_capa_get(const struct lu_env *env, struct md_object *obj,
443 struct lustre_capa *capa, int renewal);
446 int mdd_compat_fixes(const struct lu_env *env, struct mdd_device *mdd);
448 /* inline functions */
449 static inline int lu_device_is_mdd(struct lu_device *d)
451 return ergo(d != NULL && d->ld_ops != NULL, d->ld_ops == &mdd_lu_ops);
454 static inline struct mdd_device* lu2mdd_dev(struct lu_device *d)
456 LASSERT(lu_device_is_mdd(d));
457 return container_of0(d, struct mdd_device, mdd_md_dev.md_lu_dev);
460 static inline struct lu_device *mdd2lu_dev(struct mdd_device *d)
462 return (&d->mdd_md_dev.md_lu_dev);
465 static inline struct mdd_object *lu2mdd_obj(struct lu_object *o)
467 LASSERT(ergo(o != NULL, lu_device_is_mdd(o->lo_dev)));
468 return container_of0(o, struct mdd_object, mod_obj.mo_lu);
471 static inline struct mdd_device* mdo2mdd(struct md_object *mdo)
473 return lu2mdd_dev(mdo->mo_lu.lo_dev);
476 static inline struct mdd_object* md2mdd_obj(struct md_object *mdo)
478 return container_of0(mdo, struct mdd_object, mod_obj);
481 static inline const struct dt_device_operations *
482 mdd_child_ops(struct mdd_device *d)
484 return d->mdd_child->dd_ops;
487 static inline struct lu_object *mdd2lu_obj(struct mdd_object *obj)
489 return &obj->mod_obj.mo_lu;
492 static inline struct dt_object* mdd_object_child(struct mdd_object *o)
494 return container_of0(lu_object_next(mdd2lu_obj(o)),
495 struct dt_object, do_lu);
498 static inline struct obd_device *mdd2obd_dev(struct mdd_device *mdd)
500 return (mdd->mdd_md_dev.md_lu_dev.ld_obd);
503 static inline struct mdd_device *mdd_obj2mdd_dev(struct mdd_object *obj)
505 return mdo2mdd(&obj->mod_obj);
508 static inline const struct lu_fid *mdo2fid(const struct mdd_object *obj)
510 return lu_object_fid(&obj->mod_obj.mo_lu);
513 static inline int mdd_object_obf(const struct mdd_object *obj)
515 return lu_fid_eq(mdo2fid(obj), &LU_OBF_FID);
518 static inline umode_t mdd_object_type(const struct mdd_object *obj)
520 return lu_object_attr(&obj->mod_obj.mo_lu);
523 static inline int mdd_is_immutable(struct mdd_object *obj)
525 return obj->mod_flags & IMMUTE_OBJ;
528 static inline int mdd_is_dead_obj(struct mdd_object *obj)
530 return obj && obj->mod_flags & DEAD_OBJ;
533 static inline int mdd_is_append(struct mdd_object *obj)
535 return obj->mod_flags & APPEND_OBJ;
538 static inline int mdd_object_exists(struct mdd_object *obj)
540 return lu_object_exists(mdd2lu_obj(obj));
543 static inline int mdd_object_remote(struct mdd_object *obj)
545 return lu_object_remote(mdd2lu_obj(obj));
548 static inline const struct lu_fid *mdd_object_fid(struct mdd_object *obj)
550 return lu_object_fid(mdd2lu_obj(obj));
553 static inline struct seq_server_site *mdd_seq_site(struct mdd_device *mdd)
555 return mdd2lu_dev(mdd)->ld_site->ld_seq_site;
558 static inline struct lustre_capa *mdd_object_capa(const struct lu_env *env,
559 const struct mdd_object *obj)
561 struct lu_capainfo *lci = lu_capainfo_get(env);
562 const struct lu_fid *fid = mdo2fid(obj);
565 /* NB: in mdt_init0 */
569 for (i = 0; i < LU_CAPAINFO_MAX; i++)
570 if (lu_fid_eq(&lci->lci_fid[i], fid))
571 return lci->lci_capa[i];
575 static inline void mdd_set_capainfo(const struct lu_env *env, int offset,
576 const struct mdd_object *obj,
577 struct lustre_capa *capa)
579 struct lu_capainfo *lci = lu_capainfo_get(env);
580 const struct lu_fid *fid = mdo2fid(obj);
582 LASSERT(offset >= 0 && offset < LU_CAPAINFO_MAX);
583 /* NB: in mdt_init0 */
587 lci->lci_fid[offset] = *fid;
588 lci->lci_capa[offset] = capa;
591 static inline const char *mdd_obj_dev_name(const struct mdd_object *obj)
593 return lu_dev_name(obj->mod_obj.mo_lu.lo_dev);
596 #define MAX_ATIME_DIFF 60
602 static inline int mdd_permission_internal(const struct lu_env *env,
603 struct mdd_object *obj,
604 const struct lu_attr *la, int mask)
606 return __mdd_permission_internal(env, obj, la, mask, -1);
609 static inline int mdd_permission_internal_locked(const struct lu_env *env,
610 struct mdd_object *obj,
611 const struct lu_attr *la,
613 enum mdd_object_role role)
615 return __mdd_permission_internal(env, obj, la, mask, role);
618 static inline int mdo_data_get(const struct lu_env *env,
619 struct mdd_object *obj,
622 struct dt_object *next = mdd_object_child(obj);
623 next->do_ops->do_data_get(env, next, data);
627 /* mdd inline func for calling osd_dt_object ops */
628 static inline int mdo_attr_get(const struct lu_env *env, struct mdd_object *obj,
629 struct lu_attr *la, struct lustre_capa *capa)
631 struct dt_object *next = mdd_object_child(obj);
632 return next->do_ops->do_attr_get(env, next, la, capa);
635 static inline int mdo_declare_attr_set(const struct lu_env *env,
636 struct mdd_object *obj,
637 const struct lu_attr *la,
638 struct thandle *handle)
640 struct dt_object *next = mdd_object_child(obj);
641 return dt_declare_attr_set(env, next, la, handle);
644 static inline int mdo_attr_set(const struct lu_env *env,
645 struct mdd_object *obj,
646 const struct lu_attr *la,
647 struct thandle *handle,
648 struct lustre_capa *capa)
650 struct dt_object *next = mdd_object_child(obj);
651 if (mdd_object_exists(obj) == 0) {
652 CERROR("%s: object "DFID" not found: rc = -2\n",
653 mdd_obj_dev_name(obj), PFID(mdd_object_fid(obj)));
656 return next->do_ops->do_attr_set(env, next, la, handle, capa);
659 static inline int mdo_xattr_get(const struct lu_env *env,struct mdd_object *obj,
660 struct lu_buf *buf, const char *name,
661 struct lustre_capa *capa)
663 struct dt_object *next = mdd_object_child(obj);
664 return next->do_ops->do_xattr_get(env, next, buf, name, capa);
667 static inline int mdo_declare_xattr_set(const struct lu_env *env,
668 struct mdd_object *obj,
669 const struct lu_buf *buf,
671 int fl, struct thandle *handle)
673 struct dt_object *next = mdd_object_child(obj);
674 return dt_declare_xattr_set(env, next, buf, name, fl, handle);
677 static inline int mdo_xattr_set(const struct lu_env *env,struct mdd_object *obj,
678 const struct lu_buf *buf, const char *name,
679 int fl, struct thandle *handle,
680 struct lustre_capa *capa)
682 struct dt_object *next = mdd_object_child(obj);
683 if (mdd_object_exists(obj) == 0) {
684 CERROR("%s: object "DFID" not found: rc = -2\n",
685 mdd_obj_dev_name(obj), PFID(mdd_object_fid(obj)));
688 return next->do_ops->do_xattr_set(env, next, buf, name, fl, handle,
692 static inline int mdo_declare_xattr_del(const struct lu_env *env,
693 struct mdd_object *obj,
695 struct thandle *handle)
697 struct dt_object *next = mdd_object_child(obj);
698 return dt_declare_xattr_del(env, next, name, handle);
701 static inline int mdo_xattr_del(const struct lu_env *env,struct mdd_object *obj,
702 const char *name, struct thandle *handle,
703 struct lustre_capa *capa)
705 struct dt_object *next = mdd_object_child(obj);
706 if (mdd_object_exists(obj) == 0) {
707 CERROR("%s: object "DFID" not found: rc = -2\n",
708 mdd_obj_dev_name(obj), PFID(mdd_object_fid(obj)));
711 return next->do_ops->do_xattr_del(env, next, name, handle, capa);
715 int mdo_xattr_list(const struct lu_env *env, struct mdd_object *obj,
716 struct lu_buf *buf, struct lustre_capa *capa)
718 struct dt_object *next = mdd_object_child(obj);
719 if (mdd_object_exists(obj) == 0) {
720 CERROR("%s: object "DFID" not found: rc = -2\n",
721 mdd_obj_dev_name(obj), PFID(mdd_object_fid(obj)));
724 return next->do_ops->do_xattr_list(env, next, buf, capa);
728 int mdo_index_try(const struct lu_env *env, struct mdd_object *obj,
729 const struct dt_index_features *feat)
731 struct dt_object *next = mdd_object_child(obj);
732 return next->do_ops->do_index_try(env, next, feat);
736 int mdo_declare_index_insert(const struct lu_env *env, struct mdd_object *obj,
737 const struct lu_fid *fid, const char *name,
738 struct thandle *handle)
740 struct dt_object *next = mdd_object_child(obj);
744 * if the object doesn't exist yet, then it's supposed to be created
745 * and declaration of the creation should be enough to insert ./..
747 /* FIXME: remote object should not be awared by MDD layer, but local
748 * creation does not declare insert ./.. (comments above), which
749 * is required by remote directory creation.
750 * This remote check should be removed when mdd_object_exists check is
753 if (mdd_object_exists(obj) || mdd_object_remote(obj)) {
755 if (dt_try_as_dir(env, next))
756 rc = dt_declare_insert(env, next,
757 (struct dt_rec *)fid,
758 (const struct dt_key *)name,
766 int mdo_declare_index_delete(const struct lu_env *env, struct mdd_object *obj,
767 const char *name, struct thandle *handle)
769 struct dt_object *next = mdd_object_child(obj);
771 if (!dt_try_as_dir(env, next))
774 return dt_declare_delete(env, next, (const struct dt_key *)name,
778 static inline int mdo_declare_ref_add(const struct lu_env *env,
779 struct mdd_object *obj,
780 struct thandle *handle)
782 struct dt_object *next = mdd_object_child(obj);
783 return dt_declare_ref_add(env, next, handle);
786 static inline int mdo_ref_add(const struct lu_env *env, struct mdd_object *obj,
787 struct thandle *handle)
789 struct dt_object *next = mdd_object_child(obj);
790 if (mdd_object_exists(obj) == 0) {
791 CERROR("%s: object "DFID" not found: rc = -2\n",
792 mdd_obj_dev_name(obj), PFID(mdd_object_fid(obj)));
795 return next->do_ops->do_ref_add(env, next, handle);
798 static inline int mdo_declare_ref_del(const struct lu_env *env,
799 struct mdd_object *obj,
800 struct thandle *handle)
802 struct dt_object *next = mdd_object_child(obj);
803 return dt_declare_ref_del(env, next, handle);
806 static inline int mdo_ref_del(const struct lu_env *env, struct mdd_object *obj,
807 struct thandle *handle)
809 struct dt_object *next = mdd_object_child(obj);
810 if (mdd_object_exists(obj) == 0) {
811 CERROR("%s: object "DFID" not found: rc = -2\n",
812 mdd_obj_dev_name(obj), PFID(mdd_object_fid(obj)));
815 return next->do_ops->do_ref_del(env, next, handle);
819 int mdo_declare_create_obj(const struct lu_env *env, struct mdd_object *o,
820 struct lu_attr *attr,
821 struct dt_allocation_hint *hint,
822 struct dt_object_format *dof,
823 struct thandle *handle)
825 struct dt_object *next = mdd_object_child(o);
826 return next->do_ops->do_declare_create(env, next, attr, hint,
831 int mdo_create_obj(const struct lu_env *env, struct mdd_object *o,
832 struct lu_attr *attr,
833 struct dt_allocation_hint *hint,
834 struct dt_object_format *dof,
835 struct thandle *handle)
837 struct dt_object *next = mdd_object_child(o);
840 rc = next->do_ops->do_create(env, next, attr, hint, dof, handle);
846 int mdo_declare_destroy(const struct lu_env *env, struct mdd_object *o,
847 struct thandle *handle)
849 struct dt_object *next = mdd_object_child(o);
850 return dt_declare_destroy(env, next, handle);
854 int mdo_destroy(const struct lu_env *env, struct mdd_object *o,
855 struct thandle *handle)
857 struct dt_object *next = mdd_object_child(o);
858 return dt_destroy(env, next, handle);
861 static inline struct obd_capa *mdo_capa_get(const struct lu_env *env,
862 struct mdd_object *obj,
863 struct lustre_capa *old,
866 struct dt_object *next = mdd_object_child(obj);
867 if (mdd_object_exists(obj) == 0) {
868 CERROR("%s: object "DFID" not found: rc = -2\n",
869 mdd_obj_dev_name(obj), PFID(mdd_object_fid(obj)));
870 return ERR_PTR(-ENOENT);
872 return next->do_ops->do_capa_get(env, next, old, opc);