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_fsfilt.h>
49 #include <lustre/lustre_lfsck_user.h>
50 #include <lustre_fid.h>
51 #include <lustre_capa.h>
52 #include <lprocfs_status.h>
53 #include <lustre_log.h>
54 #include <lustre_linkea.h>
56 #include "mdd_lfsck.h"
58 /* PDO lock is unnecessary for current MDT stack because operations
59 * are already protected by ldlm lock */
60 #define MDD_DISABLE_PDO_LOCK 1
63 /** changelog is recording */
64 #define CLM_ON 0x00001
65 /** internal error prevented changelogs from starting */
66 #define CLM_ERR 0x00002
68 /** changelogs turned on */
69 #define CLM_START 0x10000
70 /** changelogs turned off */
71 #define CLM_FINI 0x20000
72 /** some changelog records purged */
73 #define CLM_PURGE 0x40000
75 struct mdd_changelog {
76 spinlock_t mc_lock; /* for index */
81 spinlock_t mc_user_lock;
85 static inline __u64 cl_time(void) {
88 cfs_fs_time_current(&time);
89 return (((__u64)time.tv_sec) << 30) + time.tv_nsec;
92 /** Objects in .lustre dir */
93 struct mdd_dot_lustre_objs {
94 struct mdd_object *mdd_obf;
97 extern const char lfsck_bookmark_name[];
98 extern const char lfsck_namespace_name[];
101 struct md_device mdd_md_dev;
102 struct obd_export *mdd_child_exp;
103 struct dt_device *mdd_child;
104 struct dt_device *mdd_bottom;
105 struct lu_fid mdd_root_fid; /* /ROOT */
106 struct lu_fid mdd_local_root_fid;
107 struct dt_device_param mdd_dt_conf;
108 struct dt_object *mdd_orphans; /* PENDING directory */
109 cfs_proc_dir_entry_t *mdd_proc_entry;
110 struct mdd_changelog mdd_cl;
111 unsigned long mdd_atime_diff;
112 struct mdd_object *mdd_dot_lustre;
113 struct mdd_dot_lustre_objs mdd_dot_lustre_objs;
114 struct md_lfsck mdd_lfsck;
115 unsigned int mdd_sync_permission;
117 struct local_oid_storage *mdd_los;
121 /* The dir object has been unlinked */
129 struct md_object mod_obj;
134 unsigned long mod_flags;
135 #ifndef MDD_DISABLE_PDO_LOCK
136 struct dynlock mod_pdlock;
138 #ifdef CONFIG_LOCKDEP
139 /* "dep_map" name is assumed by lockdep.h macros. */
140 struct lockdep_map dep_map;
144 struct mdd_thread_info {
145 struct lu_fid mti_fid;
146 struct lu_fid mti_fid2; /* used for be & cpu converting */
147 struct lu_attr mti_la;
148 struct lu_attr mti_la_for_fix;
149 struct lu_attr mti_pattr;
150 struct lu_attr mti_cattr;
151 struct md_attr mti_ma;
152 struct obd_info mti_oi;
153 /* mti_ent and mti_key must be conjoint,
154 * then mti_ent::lde_name will be mti_key. */
155 struct lu_dirent mti_ent;
156 char mti_key[NAME_MAX + 16];
157 struct obd_trans_info mti_oti;
158 struct lu_buf mti_buf;
159 struct lu_buf mti_big_buf; /* biggish persistent buf */
160 struct lu_buf mti_link_buf; /* buf for link ea */
161 struct lu_name mti_name;
162 struct lu_name mti_name2;
164 char mti_xattr_buf[LUSTRE_POSIX_ACL_MAX_SIZE];
165 struct dt_allocation_hint mti_hint;
166 struct lov_mds_md *mti_max_lmm;
167 int mti_max_lmm_size;
168 struct llog_cookie *mti_max_cookie;
169 int mti_max_cookie_size;
170 struct dt_object_format mti_dof;
171 struct obd_quotactl mti_oqctl;
172 struct linkea_data mti_link_data;
175 extern const char orph_index_name[];
177 extern const struct dt_index_features orph_index_features;
179 struct lov_mds_md *mdd_max_lmm_buffer(const struct lu_env *env, int size);
180 struct lov_mds_md *mdd_max_lmm_get(const struct lu_env *env,
181 struct mdd_device *mdd);
183 struct llog_cookie *mdd_max_cookie_get(const struct lu_env *env,
184 struct mdd_device *mdd);
186 int mdd_init_obd(const struct lu_env *env, struct mdd_device *mdd,
187 struct lustre_cfg *cfg);
188 int mdd_fini_obd(const struct lu_env *env, struct mdd_device *mdd,
189 struct lustre_cfg *lcfg);
190 int __mdd_xattr_set(const struct lu_env *env, struct mdd_object *obj,
191 const struct lu_buf *buf, const char *name,
192 int fl, struct thandle *handle);
193 int mdd_xattr_set_txn(const struct lu_env *env, struct mdd_object *obj,
194 const struct lu_buf *buf, const char *name, int fl,
195 struct thandle *txn);
196 int mdd_lsm_sanity_check(const struct lu_env *env, struct mdd_object *obj);
197 int mdd_lov_set_md(const struct lu_env *env, struct mdd_object *pobj,
198 struct mdd_object *child, struct lov_mds_md *lmm,
199 int lmm_size, struct thandle *handle, int set_stripe);
200 int mdd_lov_create(const struct lu_env *env, struct mdd_device *mdd,
201 struct mdd_object *parent, struct mdd_object *child,
202 struct lov_mds_md **lmm, int *lmm_size,
203 const struct md_op_spec *spec, struct md_attr *ma);
204 int mdd_lov_objid_prepare(struct mdd_device *mdd, struct lov_mds_md *lmm);
205 int mdd_declare_lov_objid_update(const struct lu_env *, struct mdd_device *,
207 void mdd_lov_objid_update(struct mdd_device *mdd, struct lov_mds_md *lmm);
208 void mdd_lov_create_finish(const struct lu_env *env, struct mdd_device *mdd,
209 struct lov_mds_md *lmm, int lmm_size,
210 const struct md_op_spec *spec);
211 int mdd_file_lock(const struct lu_env *env, struct md_object *obj,
212 struct lov_mds_md *lmm, struct ldlm_extent *extent,
213 struct lustre_handle *lockh);
214 int mdd_file_unlock(const struct lu_env *env, struct md_object *obj,
215 struct lov_mds_md *lmm, struct lustre_handle *lockh);
216 int mdd_lum_lmm_cmp(const struct lu_env *env, struct md_object *cobj,
217 const struct md_op_spec *spec, struct md_attr *ma);
218 int mdd_get_md(const struct lu_env *env, struct mdd_object *obj,
219 void *md, int *md_size, const char *name);
220 int mdd_get_md_locked(const struct lu_env *env, struct mdd_object *obj,
221 void *md, int *md_size, const char *name);
222 int mdd_data_get(const struct lu_env *env, struct mdd_object *obj, void **data);
223 int mdd_la_get(const struct lu_env *env, struct mdd_object *obj,
224 struct lu_attr *la, struct lustre_capa *capa);
225 int mdd_attr_get(const struct lu_env *env, struct md_object *obj,
227 int mdd_attr_set(const struct lu_env *env, struct md_object *obj,
228 const struct md_attr *ma);
229 int mdd_attr_set_internal(const struct lu_env *env,
230 struct mdd_object *obj,
231 const struct lu_attr *attr,
232 struct thandle *handle,
234 int mdd_attr_check_set_internal(const struct lu_env *env,
235 struct mdd_object *obj,
236 struct lu_attr *attr,
237 struct thandle *handle,
239 int mdd_declare_object_kill(const struct lu_env *env, struct mdd_object *obj,
240 struct md_attr *ma, struct thandle *handle);
241 int mdd_object_kill(const struct lu_env *env, struct mdd_object *obj,
242 struct md_attr *ma, struct thandle *handle);
243 int mdd_iattr_get(const struct lu_env *env, struct mdd_object *mdd_obj,
245 int mdd_object_create_internal(const struct lu_env *env, struct mdd_object *p,
246 struct mdd_object *c, struct lu_attr *attr,
247 struct thandle *handle,
248 const struct md_op_spec *spec);
249 int mdd_attr_check_set_internal_locked(const struct lu_env *env,
250 struct mdd_object *obj,
251 struct lu_attr *attr,
252 struct thandle *handle,
254 int mdd_lmm_get_locked(const struct lu_env *env, struct mdd_object *mdd_obj,
258 void mdd_write_lock(const struct lu_env *env, struct mdd_object *obj,
259 enum mdd_object_role role);
260 void mdd_read_lock(const struct lu_env *env, struct mdd_object *obj,
261 enum mdd_object_role role);
262 void mdd_write_unlock(const struct lu_env *env, struct mdd_object *obj);
263 void mdd_read_unlock(const struct lu_env *env, struct mdd_object *obj);
264 int mdd_write_locked(const struct lu_env *env, struct mdd_object *obj);
266 void mdd_pdlock_init(struct mdd_object *obj);
267 unsigned long mdd_name2hash(const char *name);
268 void *mdd_pdo_write_lock(const struct lu_env *env, struct mdd_object *obj,
269 const char *name, enum mdd_object_role role);
270 void *mdd_pdo_read_lock(const struct lu_env *env, struct mdd_object *obj,
271 const char *name, enum mdd_object_role role);
272 void mdd_pdo_write_unlock(const struct lu_env *env, struct mdd_object *obj,
274 void mdd_pdo_read_unlock(const struct lu_env *env, struct mdd_object *obj,
277 int mdd_parent_fid(const struct lu_env *env, struct mdd_object *obj,
279 int mdd_is_subdir(const struct lu_env *env, struct md_object *mo,
280 const struct lu_fid *fid, struct lu_fid *sfid);
281 int mdd_may_create(const struct lu_env *env, struct mdd_object *pobj,
282 struct mdd_object *cobj, int check_perm, int check_nlink);
283 int mdd_may_unlink(const struct lu_env *env, struct mdd_object *pobj,
284 const struct lu_attr *attr);
285 int mdd_may_delete(const struct lu_env *env, struct mdd_object *pobj,
286 struct mdd_object *cobj, struct lu_attr *cattr,
287 struct lu_attr *src_attr, int check_perm, int check_empty);
288 int mdd_unlink_sanity_check(const struct lu_env *env, struct mdd_object *pobj,
289 struct mdd_object *cobj, struct lu_attr *cattr);
290 int mdd_finish_unlink(const struct lu_env *env, struct mdd_object *obj,
291 struct md_attr *ma, struct thandle *th);
293 int mdd_link_sanity_check(const struct lu_env *env, struct mdd_object *tgt_obj,
294 const struct lu_name *lname, struct mdd_object *src_obj);
295 int mdd_is_root(struct mdd_device *mdd, const struct lu_fid *fid);
296 int mdd_lookup(const struct lu_env *env,
297 struct md_object *pobj, const struct lu_name *lname,
298 struct lu_fid* fid, struct md_op_spec *spec);
299 int mdd_links_read(const struct lu_env *env, struct mdd_object *mdd_obj,
300 struct linkea_data *ldata);
301 int mdd_declare_links_add(const struct lu_env *env, struct mdd_object *mdd_obj,
302 struct thandle *handle, struct linkea_data *ldata);
303 int mdd_links_write(const struct lu_env *env, struct mdd_object *mdd_obj,
304 struct linkea_data *ldata, struct thandle *handle);
305 struct lu_buf *mdd_links_get(const struct lu_env *env,
306 struct mdd_object *mdd_obj);
307 int mdd_links_rename(const struct lu_env *env,
308 struct mdd_object *mdd_obj,
309 const struct lu_fid *oldpfid,
310 const struct lu_name *oldlname,
311 const struct lu_fid *newpfid,
312 const struct lu_name *newlname,
313 struct thandle *handle,
314 struct linkea_data *ldata,
315 int first, int check);
316 int mdd_declare_links_add(const struct lu_env *env, struct mdd_object *mdd_obj,
317 struct thandle *handle, struct linkea_data *ldata);
320 int mdd_declare_unlink_log(const struct lu_env *env, struct mdd_object *obj,
321 struct md_attr *ma, struct thandle *handle);
322 int mdd_unlink_log(const struct lu_env *env, struct mdd_device *mdd,
323 struct mdd_object *mdd_cobj, struct md_attr *ma);
325 int mdd_setattr_log(const struct lu_env *env, struct mdd_device *mdd,
326 const struct md_attr *ma,
327 struct lov_mds_md *lmm, int lmm_size,
328 struct llog_cookie *logcookies, int cookies_size);
330 int mdd_get_cookie_size(const struct lu_env *env, struct mdd_device *mdd,
331 struct lov_mds_md *lmm);
333 int mdd_lov_setattr_async(const struct lu_env *env, struct mdd_object *obj,
334 struct lov_mds_md *lmm, int lmm_size,
335 struct llog_cookie *logcookies);
337 int mdd_lovobj_unlink(const struct lu_env *env, struct mdd_device *mdd,
338 struct mdd_object *obj, struct lu_attr *la,
339 struct md_attr *ma, int log_unlink);
341 struct mdd_thread_info *mdd_env_info(const struct lu_env *env);
343 const struct lu_name *mdd_name_get_const(const struct lu_env *env,
344 const void *area, ssize_t len);
345 struct lu_buf *mdd_buf_get(const struct lu_env *env, void *area, ssize_t len);
346 const struct lu_buf *mdd_buf_get_const(const struct lu_env *env,
347 const void *area, ssize_t len);
349 int __mdd_orphan_cleanup(const struct lu_env *env, struct mdd_device *d);
350 int __mdd_orphan_add(const struct lu_env *, struct mdd_object *,
352 int __mdd_orphan_del(const struct lu_env *, struct mdd_object *,
354 int orph_index_init(const struct lu_env *env, struct mdd_device *mdd);
355 void orph_index_fini(const struct lu_env *env, struct mdd_device *mdd);
356 int orph_declare_index_insert(const struct lu_env *, struct mdd_object *,
357 cfs_umode_t mode, struct thandle *);
358 int orph_declare_index_delete(const struct lu_env *, struct mdd_object *,
362 void lprocfs_mdd_init_vars(struct lprocfs_static_vars *lvars);
363 int mdd_procfs_init(struct mdd_device *mdd, const char *name);
364 int mdd_procfs_fini(struct mdd_device *mdd);
367 int mdd_get_flags(const struct lu_env *env, struct mdd_object *obj);
368 struct lu_buf *mdd_buf_alloc(const struct lu_env *env, ssize_t len);
369 int mdd_buf_grow(const struct lu_env *env, ssize_t len);
370 void mdd_buf_put(struct lu_buf *buf);
372 struct lu_buf *mdd_link_buf_alloc(const struct lu_env *env, ssize_t len);
373 int mdd_link_buf_grow(const struct lu_env *env, ssize_t len);
374 extern const struct md_dir_operations mdd_dir_ops;
375 extern const struct md_object_operations mdd_obj_ops;
377 int accmode(const struct lu_env *env, struct lu_attr *la, int flags);
378 extern struct lu_context_key mdd_thread_key;
379 extern const struct lu_device_operations mdd_lu_ops;
381 struct mdd_object *mdd_object_find(const struct lu_env *env,
382 struct mdd_device *d,
383 const struct lu_fid *f);
384 int mdd_get_default_md(struct mdd_object *mdd_obj, struct lov_mds_md *lmm);
385 int mdd_readpage(const struct lu_env *env, struct md_object *obj,
386 const struct lu_rdpg *rdpg);
387 int mdd_declare_changelog_store(const struct lu_env *env,
388 struct mdd_device *mdd,
389 const struct lu_name *fname,
390 struct thandle *handle);
391 int mdd_changelog_store(const struct lu_env *env, struct mdd_device *mdd,
392 struct llog_changelog_rec *rec, struct thandle *th);
393 int mdd_changelog_data_store(const struct lu_env *env, struct mdd_device *mdd,
394 enum changelog_rec_type type, int flags,
395 struct mdd_object *mdd_obj,
396 struct thandle *handle);
397 int mdd_changelog_ns_store(const struct lu_env *env, struct mdd_device *mdd,
398 enum changelog_rec_type type, unsigned flags,
399 struct mdd_object *target, struct mdd_object *parent,
400 const struct lu_name *tname, struct thandle *handle);
401 int mdd_declare_object_create_internal(const struct lu_env *env,
402 struct mdd_object *p,
403 struct mdd_object *c,
404 struct lu_attr *attr,
405 struct thandle *handle,
406 const struct md_op_spec *spec);
409 int mdd_lov_destroy(const struct lu_env *env, struct mdd_device *mdd,
410 struct mdd_object *obj, struct lu_attr *la);
412 void mdd_object_make_hint(const struct lu_env *env, struct mdd_object *parent,
413 struct mdd_object *child, struct lu_attr *attr);
415 static inline void mdd_object_get(struct mdd_object *o)
417 lu_object_get(&o->mod_obj.mo_lu);
420 static inline void mdd_object_put(const struct lu_env *env,
421 struct mdd_object *o)
423 lu_object_put(env, &o->mod_obj.mo_lu);
426 struct thandle *mdd_trans_create(const struct lu_env *env,
427 struct mdd_device *mdd);
428 int mdd_trans_start(const struct lu_env *env, struct mdd_device *mdd,
430 void mdd_trans_stop(const struct lu_env *env, struct mdd_device *mdd,
431 int rc, struct thandle *handle);
432 int mdd_txn_stop_cb(const struct lu_env *env, struct thandle *txn,
434 int mdd_txn_start_cb(const struct lu_env *env, struct thandle *,
438 int mdd_lfsck_set_speed(const struct lu_env *env, struct md_lfsck *lfsck,
440 int mdd_lfsck_start(const struct lu_env *env, struct md_lfsck *lfsck,
441 struct lfsck_start *start);
442 int mdd_lfsck_stop(const struct lu_env *env, struct md_lfsck *lfsck,
444 int mdd_lfsck_setup(const struct lu_env *env, struct mdd_device *mdd);
445 void mdd_lfsck_cleanup(const struct lu_env *env, struct mdd_device *mdd);
446 int mdd_lfsck_dump(const struct lu_env *env, struct md_lfsck *lfsck,
447 __u16 type, char *buf, int len);
450 struct lu_object *mdd_object_alloc(const struct lu_env *env,
451 const struct lu_object_header *hdr,
452 struct lu_device *d);
453 int mdd_local_file_create(const struct lu_env *env, struct mdd_device *mdd,
454 const struct lu_fid *pfid, const char *name,
455 __u32 mode, struct lu_fid *fid);
457 int mdd_acl_chmod(const struct lu_env *env, struct mdd_object *o, __u32 mode,
458 struct thandle *handle);
459 int __mdd_declare_acl_init(const struct lu_env *env, struct mdd_object *obj,
460 int is_dir, struct thandle *handle);
461 int mdd_acl_set(const struct lu_env *env, struct mdd_object *obj,
462 const struct lu_buf *buf, int fl);
463 int __mdd_fix_mode_acl(const struct lu_env *env, struct lu_buf *buf,
465 int __mdd_permission_internal(const struct lu_env *env, struct mdd_object *obj,
466 struct lu_attr *la, int mask, int role);
467 int mdd_permission(const struct lu_env *env,
468 struct md_object *pobj, struct md_object *cobj,
469 struct md_attr *ma, int mask);
470 int mdd_capa_get(const struct lu_env *env, struct md_object *obj,
471 struct lustre_capa *capa, int renewal);
474 int mdd_compat_fixes(const struct lu_env *env, struct mdd_device *mdd);
476 static inline int lu_device_is_mdd(struct lu_device *d)
478 return ergo(d != NULL && d->ld_ops != NULL, d->ld_ops == &mdd_lu_ops);
481 static inline struct mdd_device* lu2mdd_dev(struct lu_device *d)
483 LASSERT(lu_device_is_mdd(d));
484 return container_of0(d, struct mdd_device, mdd_md_dev.md_lu_dev);
487 static inline struct lu_device *mdd2lu_dev(struct mdd_device *d)
489 return (&d->mdd_md_dev.md_lu_dev);
492 static inline struct mdd_object *lu2mdd_obj(struct lu_object *o)
494 LASSERT(ergo(o != NULL, lu_device_is_mdd(o->lo_dev)));
495 return container_of0(o, struct mdd_object, mod_obj.mo_lu);
498 static inline struct mdd_device* mdo2mdd(struct md_object *mdo)
500 return lu2mdd_dev(mdo->mo_lu.lo_dev);
503 static inline struct mdd_object* md2mdd_obj(struct md_object *mdo)
505 return container_of0(mdo, struct mdd_object, mod_obj);
508 static inline const struct dt_device_operations *
509 mdd_child_ops(struct mdd_device *d)
511 return d->mdd_child->dd_ops;
514 static inline struct lu_object *mdd2lu_obj(struct mdd_object *obj)
516 return &obj->mod_obj.mo_lu;
519 static inline struct dt_object* mdd_object_child(struct mdd_object *o)
521 return container_of0(lu_object_next(mdd2lu_obj(o)),
522 struct dt_object, do_lu);
525 static inline struct obd_device *mdd2obd_dev(struct mdd_device *mdd)
527 return (mdd->mdd_md_dev.md_lu_dev.ld_obd);
530 static inline struct mdd_device *mdd_obj2mdd_dev(struct mdd_object *obj)
532 return mdo2mdd(&obj->mod_obj);
535 static inline const struct lu_fid *mdo2fid(const struct mdd_object *obj)
537 return lu_object_fid(&obj->mod_obj.mo_lu);
540 static inline int mdd_object_obf(const struct mdd_object *obj)
542 return lu_fid_eq(mdo2fid(obj), &LU_OBF_FID);
545 static inline cfs_umode_t mdd_object_type(const struct mdd_object *obj)
547 return lu_object_attr(&obj->mod_obj.mo_lu);
550 static inline int mdd_is_immutable(struct mdd_object *obj)
552 return obj->mod_flags & IMMUTE_OBJ;
555 static inline int mdd_is_dead_obj(struct mdd_object *obj)
557 return obj && obj->mod_flags & DEAD_OBJ;
560 static inline int mdd_is_append(struct mdd_object *obj)
562 return obj->mod_flags & APPEND_OBJ;
565 static inline int mdd_object_exists(struct mdd_object *obj)
567 return lu_object_exists(mdd2lu_obj(obj));
570 static inline int mdd_object_remote(struct mdd_object *obj)
572 return lu_object_remote(mdd2lu_obj(obj));
575 static inline const struct lu_fid *mdd_object_fid(struct mdd_object *obj)
577 return lu_object_fid(mdd2lu_obj(obj));
580 static inline struct seq_server_site *mdd_seq_site(struct mdd_device *mdd)
582 return mdd2lu_dev(mdd)->ld_site->ld_seq_site;
585 static inline struct lustre_capa *mdd_object_capa(const struct lu_env *env,
586 const struct mdd_object *obj)
588 struct md_capainfo *ci = md_capainfo(env);
589 const struct lu_fid *fid = mdo2fid(obj);
592 /* NB: in mdt_init0 */
595 for (i = 0; i < MD_CAPAINFO_MAX; i++)
596 if (lu_fid_eq(&ci->mc_fid[i], fid))
597 return ci->mc_capa[i];
601 static inline void mdd_set_capainfo(const struct lu_env *env, int offset,
602 const struct mdd_object *obj,
603 struct lustre_capa *capa)
605 struct md_capainfo *ci = md_capainfo(env);
606 const struct lu_fid *fid = mdo2fid(obj);
608 LASSERT(offset >= 0 && offset < MD_CAPAINFO_MAX);
609 /* NB: in mdt_init0 */
612 ci->mc_fid[offset] = *fid;
613 ci->mc_capa[offset] = capa;
616 static inline const char *mdd_obj_dev_name(const struct mdd_object *obj)
618 return lu_dev_name(obj->mod_obj.mo_lu.lo_dev);
621 #define MAX_ATIME_DIFF 60
627 static inline int mdd_permission_internal(const struct lu_env *env,
628 struct mdd_object *obj,
629 struct lu_attr *la, int mask)
631 return __mdd_permission_internal(env, obj, la, mask, -1);
634 static inline int mdd_permission_internal_locked(const struct lu_env *env,
635 struct mdd_object *obj,
636 struct lu_attr *la, int mask,
637 enum mdd_object_role role)
639 return __mdd_permission_internal(env, obj, la, mask, role);
642 static inline int mdo_data_get(const struct lu_env *env,
643 struct mdd_object *obj,
646 struct dt_object *next = mdd_object_child(obj);
647 next->do_ops->do_data_get(env, next, data);
651 /* mdd inline func for calling osd_dt_object ops */
652 static inline int mdo_attr_get(const struct lu_env *env, struct mdd_object *obj,
653 struct lu_attr *la, struct lustre_capa *capa)
655 struct dt_object *next = mdd_object_child(obj);
656 return next->do_ops->do_attr_get(env, next, la, capa);
659 static inline int mdo_declare_attr_set(const struct lu_env *env,
660 struct mdd_object *obj,
661 const struct lu_attr *la,
662 struct thandle *handle)
664 struct dt_object *next = mdd_object_child(obj);
665 return dt_declare_attr_set(env, next, la, handle);
668 static inline int mdo_attr_set(const struct lu_env *env,
669 struct mdd_object *obj,
670 const struct lu_attr *la,
671 struct thandle *handle,
672 struct lustre_capa *capa)
674 struct dt_object *next = mdd_object_child(obj);
675 if (mdd_object_exists(obj) == 0) {
676 CERROR("%s: object "DFID" not found: rc = -2\n",
677 mdd_obj_dev_name(obj), PFID(mdd_object_fid(obj)));
680 return next->do_ops->do_attr_set(env, next, la, handle, capa);
683 static inline int mdo_xattr_get(const struct lu_env *env,struct mdd_object *obj,
684 struct lu_buf *buf, const char *name,
685 struct lustre_capa *capa)
687 struct dt_object *next = mdd_object_child(obj);
688 return next->do_ops->do_xattr_get(env, next, buf, name, capa);
691 static inline int mdo_declare_xattr_set(const struct lu_env *env,
692 struct mdd_object *obj,
693 const struct lu_buf *buf,
695 int fl, struct thandle *handle)
697 struct dt_object *next = mdd_object_child(obj);
698 return dt_declare_xattr_set(env, next, buf, name, fl, handle);
701 static inline int mdo_xattr_set(const struct lu_env *env,struct mdd_object *obj,
702 const struct lu_buf *buf, const char *name,
703 int fl, struct thandle *handle,
704 struct lustre_capa *capa)
706 struct dt_object *next = mdd_object_child(obj);
707 if (mdd_object_exists(obj) == 0) {
708 CERROR("%s: object "DFID" not found: rc = -2\n",
709 mdd_obj_dev_name(obj), PFID(mdd_object_fid(obj)));
712 return next->do_ops->do_xattr_set(env, next, buf, name, fl, handle,
716 static inline int mdo_declare_xattr_del(const struct lu_env *env,
717 struct mdd_object *obj,
719 struct thandle *handle)
721 struct dt_object *next = mdd_object_child(obj);
722 return dt_declare_xattr_del(env, next, name, handle);
725 static inline int mdo_xattr_del(const struct lu_env *env,struct mdd_object *obj,
726 const char *name, struct thandle *handle,
727 struct lustre_capa *capa)
729 struct dt_object *next = mdd_object_child(obj);
730 if (mdd_object_exists(obj) == 0) {
731 CERROR("%s: object "DFID" not found: rc = -2\n",
732 mdd_obj_dev_name(obj), PFID(mdd_object_fid(obj)));
735 return next->do_ops->do_xattr_del(env, next, name, handle, capa);
739 int mdo_xattr_list(const struct lu_env *env, struct mdd_object *obj,
740 struct lu_buf *buf, struct lustre_capa *capa)
742 struct dt_object *next = mdd_object_child(obj);
743 if (mdd_object_exists(obj) == 0) {
744 CERROR("%s: object "DFID" not found: rc = -2\n",
745 mdd_obj_dev_name(obj), PFID(mdd_object_fid(obj)));
748 return next->do_ops->do_xattr_list(env, next, buf, capa);
752 int mdo_index_try(const struct lu_env *env, struct mdd_object *obj,
753 const struct dt_index_features *feat)
755 struct dt_object *next = mdd_object_child(obj);
756 return next->do_ops->do_index_try(env, next, feat);
760 int mdo_declare_index_insert(const struct lu_env *env, struct mdd_object *obj,
761 const struct lu_fid *fid, const char *name,
762 struct thandle *handle)
764 struct dt_object *next = mdd_object_child(obj);
768 * if the object doesn't exist yet, then it's supposed to be created
769 * and declaration of the creation should be enough to insert ./..
771 /* FIXME: remote object should not be awared by MDD layer, but local
772 * creation does not declare insert ./.. (comments above), which
773 * is required by remote directory creation.
774 * This remote check should be removed when mdd_object_exists check is
777 if (mdd_object_exists(obj) || mdd_object_remote(obj)) {
779 if (dt_try_as_dir(env, next))
780 rc = dt_declare_insert(env, next,
781 (struct dt_rec *)fid,
782 (const struct dt_key *)name,
790 int mdo_declare_index_delete(const struct lu_env *env, struct mdd_object *obj,
791 const char *name, struct thandle *handle)
793 struct dt_object *next = mdd_object_child(obj);
795 if (!dt_try_as_dir(env, next))
798 return dt_declare_delete(env, next, (const struct dt_key *)name,
802 static inline int mdo_declare_ref_add(const struct lu_env *env,
803 struct mdd_object *obj,
804 struct thandle *handle)
806 struct dt_object *next = mdd_object_child(obj);
807 return dt_declare_ref_add(env, next, handle);
810 static inline int mdo_ref_add(const struct lu_env *env, struct mdd_object *obj,
811 struct thandle *handle)
813 struct dt_object *next = mdd_object_child(obj);
814 if (mdd_object_exists(obj) == 0) {
815 CERROR("%s: object "DFID" not found: rc = -2\n",
816 mdd_obj_dev_name(obj), PFID(mdd_object_fid(obj)));
819 return next->do_ops->do_ref_add(env, next, handle);
822 static inline int mdo_declare_ref_del(const struct lu_env *env,
823 struct mdd_object *obj,
824 struct thandle *handle)
826 struct dt_object *next = mdd_object_child(obj);
827 return dt_declare_ref_del(env, next, handle);
830 static inline int mdo_ref_del(const struct lu_env *env, struct mdd_object *obj,
831 struct thandle *handle)
833 struct dt_object *next = mdd_object_child(obj);
834 if (mdd_object_exists(obj) == 0) {
835 CERROR("%s: object "DFID" not found: rc = -2\n",
836 mdd_obj_dev_name(obj), PFID(mdd_object_fid(obj)));
839 return next->do_ops->do_ref_del(env, next, handle);
843 int mdo_declare_create_obj(const struct lu_env *env, struct mdd_object *o,
844 struct lu_attr *attr,
845 struct dt_allocation_hint *hint,
846 struct dt_object_format *dof,
847 struct thandle *handle)
849 struct dt_object *next = mdd_object_child(o);
850 return next->do_ops->do_declare_create(env, next, attr, hint,
855 int mdo_create_obj(const struct lu_env *env, struct mdd_object *o,
856 struct lu_attr *attr,
857 struct dt_allocation_hint *hint,
858 struct dt_object_format *dof,
859 struct thandle *handle)
861 struct dt_object *next = mdd_object_child(o);
864 rc = next->do_ops->do_create(env, next, attr, hint, dof, handle);
870 int mdo_declare_destroy(const struct lu_env *env, struct mdd_object *o,
871 struct thandle *handle)
873 struct dt_object *next = mdd_object_child(o);
874 return dt_declare_destroy(env, next, handle);
878 int mdo_destroy(const struct lu_env *env, struct mdd_object *o,
879 struct thandle *handle)
881 struct dt_object *next = mdd_object_child(o);
882 return dt_destroy(env, next, handle);
885 static inline struct obd_capa *mdo_capa_get(const struct lu_env *env,
886 struct mdd_object *obj,
887 struct lustre_capa *old,
890 struct dt_object *next = mdd_object_child(obj);
891 if (mdd_object_exists(obj) == 0) {
892 CERROR("%s: object "DFID" not found: rc = -2\n",
893 mdd_obj_dev_name(obj), PFID(mdd_object_fid(obj)));
894 return ERR_PTR(-ENOENT);
896 return next->do_ops->do_capa_get(env, next, old, opc);