1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 only,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License version 2 for more details (a copy is included
16 * in the LICENSE file that accompanied this code).
18 * You should have received a copy of the GNU General Public License
19 * version 2 along with this program; If not, see
20 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
29 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
30 * Use is subject to license terms.
32 * Copyright (c) 2011 Whamcloud, Inc.
36 * Copyright (c) 2011 Whamcloud, Inc.
39 * This file is part of Lustre, http://www.lustre.org/
40 * Lustre is a trademark of Sun Microsystems, Inc.
42 * lustre/osd/osd_handler.c
44 * Top-level entry points into osd module
46 * Author: Nikita Danilov <nikita@clusterfs.com>
47 * Pravin Shelar <pravin.shelar@sun.com> : Added fid in dirent
51 # define EXPORT_SYMTAB
53 #define DEBUG_SUBSYSTEM S_MDS
55 #include <linux/module.h>
57 /* LUSTRE_VERSION_CODE */
58 #include <lustre_ver.h>
59 /* prerequisite for linux/xattr.h */
60 #include <linux/types.h>
61 /* prerequisite for linux/xattr.h */
63 /* XATTR_{REPLACE,CREATE} */
64 #include <linux/xattr.h>
69 * struct OBD_{ALLOC,FREE}*()
72 #include <obd_support.h>
73 /* struct ptlrpc_thread */
74 #include <lustre_net.h>
77 #include <lustre_fid.h>
79 #include "osd_internal.h"
82 /* llo_* api support */
83 #include <md_object.h>
85 #ifdef HAVE_LDISKFS_PDO
87 CFS_MODULE_PARM(ldiskfs_pdo, "i", int, 0644,
88 "ldiskfs with parallel directory operations");
93 static const char dot[] = ".";
94 static const char dotdot[] = "..";
95 static const char remote_obj_dir[] = "REM_OBJ_DIR";
97 struct osd_directory {
98 struct iam_container od_container;
99 struct iam_descr od_descr;
103 struct dt_object oo_dt;
105 * Inode for file system object represented by this osd_object. This
106 * inode is pinned for the whole duration of lu_object life.
108 * Not modified concurrently (either setup early during object
109 * creation, or assigned by osd_object_create() under write lock).
111 struct inode *oo_inode;
113 * to protect index ops.
115 struct htree_lock_head *oo_hl_head;
116 cfs_rw_semaphore_t oo_ext_idx_sem;
117 cfs_rw_semaphore_t oo_sem;
118 struct osd_directory *oo_dir;
119 /** protects inode attributes. */
120 cfs_spinlock_t oo_guard;
122 * Following two members are used to indicate the presence of dot and
123 * dotdot in the given directory. This is required for interop mode
126 int oo_compat_dot_created;
127 int oo_compat_dotdot_created;
129 const struct lu_env *oo_owner;
130 #ifdef CONFIG_LOCKDEP
131 struct lockdep_map oo_dep_map;
135 static const struct lu_object_operations osd_lu_obj_ops;
136 static const struct lu_device_operations osd_lu_ops;
137 static struct lu_context_key osd_key;
138 static const struct dt_object_operations osd_obj_ops;
139 static const struct dt_object_operations osd_obj_ea_ops;
140 static const struct dt_body_operations osd_body_ops;
141 static const struct dt_index_operations osd_index_iam_ops;
142 static const struct dt_index_operations osd_index_ea_ops;
145 struct thandle ot_super;
147 struct journal_callback ot_jcb;
148 cfs_list_t ot_dcb_list;
149 /* Link to the device, for debugging. */
150 struct lu_ref_link *ot_dev_link;
152 #if OSD_THANDLE_STATS
153 /** time when this handle was allocated */
154 cfs_time_t oth_alloced;
156 /** time when this thanle was started */
157 cfs_time_t oth_started;
164 static int lu_device_is_osd(const struct lu_device *d)
166 return ergo(d != NULL && d->ld_ops != NULL, d->ld_ops == &osd_lu_ops);
169 static struct osd_device *osd_dt_dev(const struct dt_device *d)
171 LASSERT(lu_device_is_osd(&d->dd_lu_dev));
172 return container_of0(d, struct osd_device, od_dt_dev);
175 static struct osd_device *osd_dev(const struct lu_device *d)
177 LASSERT(lu_device_is_osd(d));
178 return osd_dt_dev(container_of0(d, struct dt_device, dd_lu_dev));
181 static struct osd_device *osd_obj2dev(const struct osd_object *o)
183 return osd_dev(o->oo_dt.do_lu.lo_dev);
186 static struct super_block *osd_sb(const struct osd_device *dev)
188 return dev->od_mount->lmi_mnt->mnt_sb;
191 static int osd_object_is_root(const struct osd_object *obj)
193 return osd_sb(osd_obj2dev(obj))->s_root->d_inode == obj->oo_inode;
196 static struct osd_object *osd_obj(const struct lu_object *o)
198 LASSERT(lu_device_is_osd(o->lo_dev));
199 return container_of0(o, struct osd_object, oo_dt.do_lu);
202 static struct osd_object *osd_dt_obj(const struct dt_object *d)
204 return osd_obj(&d->do_lu);
207 static struct lu_device *osd2lu_dev(struct osd_device *osd)
209 return &osd->od_dt_dev.dd_lu_dev;
212 static journal_t *osd_journal(const struct osd_device *dev)
214 return LDISKFS_SB(osd_sb(dev))->s_journal;
217 static int osd_has_index(const struct osd_object *obj)
219 return obj->oo_dt.do_index_ops != NULL;
222 static int osd_object_invariant(const struct lu_object *l)
224 return osd_invariant(osd_obj(l));
227 #ifdef HAVE_QUOTA_SUPPORT
229 osd_push_ctxt(const struct lu_env *env, struct osd_ctxt *save)
231 struct md_ucred *uc = md_ucred(env);
236 save->oc_uid = current_fsuid();
237 save->oc_gid = current_fsgid();
238 save->oc_cap = current_cap();
239 if ((tc = prepare_creds())) {
240 tc->fsuid = uc->mu_fsuid;
241 tc->fsgid = uc->mu_fsgid;
244 /* XXX not suboptimal */
245 cfs_curproc_cap_unpack(uc->mu_cap);
249 osd_pop_ctxt(struct osd_ctxt *save)
253 if ((tc = prepare_creds())) {
254 tc->fsuid = save->oc_uid;
255 tc->fsgid = save->oc_gid;
256 tc->cap_effective = save->oc_cap;
262 static inline struct osd_thread_info *osd_oti_get(const struct lu_env *env)
264 return lu_context_key_get(&env->le_ctx, &osd_key);
268 * Concurrency: doesn't matter
270 static int osd_read_locked(const struct lu_env *env, struct osd_object *o)
272 return osd_oti_get(env)->oti_r_locks > 0;
276 * Concurrency: doesn't matter
278 static int osd_write_locked(const struct lu_env *env, struct osd_object *o)
280 struct osd_thread_info *oti = osd_oti_get(env);
281 return oti->oti_w_locks > 0 && o->oo_owner == env;
285 * Concurrency: doesn't access mutable data
287 static int osd_root_get(const struct lu_env *env,
288 struct dt_device *dev, struct lu_fid *f)
292 inode = osd_sb(osd_dt_dev(dev))->s_root->d_inode;
293 LU_IGIF_BUILD(f, inode->i_ino, inode->i_generation);
298 * OSD object methods.
302 * Concurrency: no concurrent access is possible that early in object
305 static struct lu_object *osd_object_alloc(const struct lu_env *env,
306 const struct lu_object_header *hdr,
309 struct osd_object *mo;
315 l = &mo->oo_dt.do_lu;
316 dt_object_init(&mo->oo_dt, NULL, d);
317 if (osd_dev(d)->od_iop_mode)
318 mo->oo_dt.do_ops = &osd_obj_ea_ops;
320 mo->oo_dt.do_ops = &osd_obj_ops;
322 l->lo_ops = &osd_lu_obj_ops;
323 cfs_init_rwsem(&mo->oo_sem);
324 cfs_init_rwsem(&mo->oo_ext_idx_sem);
325 cfs_spin_lock_init(&mo->oo_guard);
333 * retrieve object from backend ext fs.
335 static struct inode *osd_iget(struct osd_thread_info *info,
336 struct osd_device *dev,
337 const struct osd_inode_id *id)
339 struct inode *inode = NULL;
341 #ifdef HAVE_EXT4_LDISKFS
342 inode = ldiskfs_iget(osd_sb(dev), id->oii_ino);
344 /* Newer kernels return an error instead of a NULL pointer */
347 inode = iget(osd_sb(dev), id->oii_ino);
350 CERROR("no inode\n");
351 inode = ERR_PTR(-EACCES);
352 } else if (id->oii_gen != OSD_OII_NOGEN &&
353 inode->i_generation != id->oii_gen) {
355 inode = ERR_PTR(-ESTALE);
356 } else if (inode->i_nlink == 0) {
357 /* due to parallel readdir and unlink,
358 * we can have dead inode here. */
359 CWARN("stale inode\n");
360 make_bad_inode(inode);
362 inode = ERR_PTR(-ESTALE);
363 } else if (is_bad_inode(inode)) {
364 CERROR("bad inode %lx\n",inode->i_ino);
366 inode = ERR_PTR(-ENOENT);
368 /* Do not update file c/mtime in ldiskfs.
369 * NB: we don't have any lock to protect this because we don't
370 * have reference on osd_object now, but contention with
371 * another lookup + attr_set can't happen in the tiny window
372 * between if (...) and set S_NOCMTIME. */
373 if (!(inode->i_flags & S_NOCMTIME))
374 inode->i_flags |= S_NOCMTIME;
379 static int osd_fid_lookup(const struct lu_env *env,
380 struct osd_object *obj, const struct lu_fid *fid)
382 struct osd_thread_info *info;
383 struct lu_device *ldev = obj->oo_dt.do_lu.lo_dev;
384 struct osd_device *dev;
385 struct osd_inode_id *id;
390 LINVRNT(osd_invariant(obj));
391 LASSERT(obj->oo_inode == NULL);
392 LASSERT(fid_is_sane(fid) || osd_fid_is_root(fid));
394 * This assertion checks that osd layer sees only local
395 * fids. Unfortunately it is somewhat expensive (does a
396 * cache-lookup). Disabling it for production/acceptance-testing.
398 LASSERT(1 || fid_is_local(env, ldev->ld_site, fid));
402 info = osd_oti_get(env);
407 if (OBD_FAIL_CHECK(OBD_FAIL_OST_ENOENT))
410 result = osd_oi_lookup(info, oi, fid, id);
412 if (result == -ENOENT)
417 inode = osd_iget(info, dev, id);
420 * If fid wasn't found in oi, inode-less object is
421 * created, for which lu_object_exists() returns
422 * false. This is used in a (frequent) case when
423 * objects are created as locking anchors or
424 * place holders for objects yet to be created.
426 result = PTR_ERR(inode);
430 obj->oo_inode = inode;
431 LASSERT(obj->oo_inode->i_sb == osd_sb(dev));
432 if (dev->od_iop_mode) {
433 obj->oo_compat_dot_created = 1;
434 obj->oo_compat_dotdot_created = 1;
437 if (!S_ISDIR(inode->i_mode) || !ldiskfs_pdo) /* done */
440 LASSERT(obj->oo_hl_head == NULL);
441 obj->oo_hl_head = ldiskfs_htree_lock_head_alloc(HTREE_HBITS_DEF);
442 if (obj->oo_hl_head == NULL) {
443 obj->oo_inode = NULL;
448 LINVRNT(osd_invariant(obj));
454 * Concurrency: shouldn't matter.
456 static void osd_object_init0(struct osd_object *obj)
458 LASSERT(obj->oo_inode != NULL);
459 obj->oo_dt.do_body_ops = &osd_body_ops;
460 obj->oo_dt.do_lu.lo_header->loh_attr |=
461 (LOHA_EXISTS | (obj->oo_inode->i_mode & S_IFMT));
465 * Concurrency: no concurrent access is possible that early in object
468 static int osd_object_init(const struct lu_env *env, struct lu_object *l,
469 const struct lu_object_conf *unused)
471 struct osd_object *obj = osd_obj(l);
474 LINVRNT(osd_invariant(obj));
476 result = osd_fid_lookup(env, obj, lu_object_fid(l));
478 if (obj->oo_inode != NULL)
479 osd_object_init0(obj);
481 LINVRNT(osd_invariant(obj));
486 * Concurrency: no concurrent access is possible that late in object
489 static void osd_object_free(const struct lu_env *env, struct lu_object *l)
491 struct osd_object *obj = osd_obj(l);
493 LINVRNT(osd_invariant(obj));
495 dt_object_fini(&obj->oo_dt);
496 if (obj->oo_hl_head != NULL)
497 ldiskfs_htree_lock_head_free(obj->oo_hl_head);
504 static struct iam_path_descr *osd_it_ipd_get(const struct lu_env *env,
505 const struct iam_container *bag)
507 return bag->ic_descr->id_ops->id_ipd_alloc(bag,
508 osd_oti_get(env)->oti_it_ipd);
511 static struct iam_path_descr *osd_idx_ipd_get(const struct lu_env *env,
512 const struct iam_container *bag)
514 return bag->ic_descr->id_ops->id_ipd_alloc(bag,
515 osd_oti_get(env)->oti_idx_ipd);
518 static void osd_ipd_put(const struct lu_env *env,
519 const struct iam_container *bag,
520 struct iam_path_descr *ipd)
522 bag->ic_descr->id_ops->id_ipd_free(ipd);
526 * Concurrency: no concurrent access is possible that late in object
529 static void osd_index_fini(struct osd_object *o)
531 struct iam_container *bag;
533 if (o->oo_dir != NULL) {
534 bag = &o->oo_dir->od_container;
535 if (o->oo_inode != NULL) {
536 if (bag->ic_object == o->oo_inode)
537 iam_container_fini(bag);
539 OBD_FREE_PTR(o->oo_dir);
545 * Concurrency: no concurrent access is possible that late in object
546 * life-cycle (for all existing callers, that is. New callers have to provide
547 * their own locking.)
549 static int osd_inode_unlinked(const struct inode *inode)
551 return inode->i_nlink == 0;
555 OSD_TXN_OI_DELETE_CREDITS = 20,
556 OSD_TXN_INODE_DELETE_CREDITS = 20
563 #if OSD_THANDLE_STATS
565 * Set time when the handle is allocated
567 static void osd_th_alloced(struct osd_thandle *oth)
569 oth->oth_alloced = cfs_time_current();
573 * Set time when the handle started
575 static void osd_th_started(struct osd_thandle *oth)
577 oth->oth_started = cfs_time_current();
581 * Helper function to convert time interval to microseconds packed in
582 * long int (default time units for the counter in "stats" initialized
583 * by lu_time_init() )
585 static long interval_to_usec(cfs_time_t start, cfs_time_t end)
589 cfs_duration_usec(cfs_time_sub(end, start), &val);
590 return val.tv_sec * 1000000 + val.tv_usec;
594 * Check whether the we deal with this handle for too long.
596 static void __osd_th_check_slow(void *oth, struct osd_device *dev,
597 cfs_time_t alloced, cfs_time_t started,
600 cfs_time_t now = cfs_time_current();
602 LASSERT(dev != NULL);
604 lprocfs_counter_add(dev->od_stats, LPROC_OSD_THANDLE_STARTING,
605 interval_to_usec(alloced, started));
606 lprocfs_counter_add(dev->od_stats, LPROC_OSD_THANDLE_OPEN,
607 interval_to_usec(started, closed));
608 lprocfs_counter_add(dev->od_stats, LPROC_OSD_THANDLE_CLOSING,
609 interval_to_usec(closed, now));
611 if (cfs_time_before(cfs_time_add(alloced, cfs_time_seconds(30)), now)) {
612 CWARN("transaction handle %p was open for too long: "
614 "alloced "CFS_TIME_T" ,"
615 "started "CFS_TIME_T" ,"
616 "closed "CFS_TIME_T"\n",
617 oth, now, alloced, started, closed);
618 libcfs_debug_dumpstack(NULL);
622 #define OSD_CHECK_SLOW_TH(oth, dev, expr) \
624 cfs_time_t __closed = cfs_time_current(); \
625 cfs_time_t __alloced = oth->oth_alloced; \
626 cfs_time_t __started = oth->oth_started; \
629 __osd_th_check_slow(oth, dev, __alloced, __started, __closed); \
632 #else /* OSD_THANDLE_STATS */
634 #define osd_th_alloced(h) do {} while(0)
635 #define osd_th_started(h) do {} while(0)
636 #define OSD_CHECK_SLOW_TH(oth, dev, expr) expr
638 #endif /* OSD_THANDLE_STATS */
641 * Concurrency: doesn't access mutable data.
643 static int osd_param_is_sane(const struct osd_device *dev,
644 const struct txn_param *param)
646 return param->tp_credits <= osd_journal(dev)->j_max_transaction_buffers;
650 * Concurrency: shouldn't matter.
652 #ifdef HAVE_LDISKFS_JOURNAL_CALLBACK_ADD
653 static void osd_trans_commit_cb(struct super_block *sb,
654 struct journal_callback *jcb, int error)
656 static void osd_trans_commit_cb(struct journal_callback *jcb, int error)
659 struct osd_thandle *oh = container_of0(jcb, struct osd_thandle, ot_jcb);
660 struct thandle *th = &oh->ot_super;
661 struct lu_device *lud = &th->th_dev->dd_lu_dev;
662 struct dt_txn_commit_cb *dcb, *tmp;
664 LASSERT(oh->ot_handle == NULL);
667 CERROR("transaction @0x%p commit error: %d\n", th, error);
669 dt_txn_hook_commit(th);
671 /* call per-transaction callbacks if any */
672 cfs_list_for_each_entry_safe(dcb, tmp, &oh->ot_dcb_list, dcb_linkage)
673 dcb->dcb_func(NULL, th, dcb, error);
675 lu_ref_del_at(&lud->ld_reference, oh->ot_dev_link, "osd-tx", th);
679 lu_context_exit(&th->th_ctx);
680 lu_context_fini(&th->th_ctx);
685 * Concurrency: shouldn't matter.
687 static struct thandle *osd_trans_start(const struct lu_env *env,
691 struct osd_device *dev = osd_dt_dev(d);
693 struct osd_thandle *oh;
699 hook_res = dt_txn_hook_start(env, d, p);
701 RETURN(ERR_PTR(hook_res));
703 if (osd_param_is_sane(dev, p)) {
704 OBD_ALLOC_GFP(oh, sizeof *oh, CFS_ALLOC_IO);
706 struct osd_thread_info *oti = osd_oti_get(env);
709 * XXX temporary stuff. Some abstraction layer should
713 CFS_INIT_LIST_HEAD(&oh->ot_dcb_list);
715 jh = ldiskfs_journal_start_sb(osd_sb(dev), p->tp_credits);
723 lu_device_get(&d->dd_lu_dev);
724 oh->ot_dev_link = lu_ref_add
725 (&d->dd_lu_dev.ld_reference,
727 /* add commit callback */
728 lu_context_init(&th->th_ctx, LCT_TX_HANDLE);
729 lu_context_enter(&th->th_ctx);
730 LASSERT(oti->oti_txns == 0);
731 LASSERT(oti->oti_r_locks == 0);
732 LASSERT(oti->oti_w_locks == 0);
739 th = ERR_PTR(-ENOMEM);
741 CERROR("Invalid transaction parameters\n");
742 th = ERR_PTR(-EINVAL);
749 * Concurrency: shouldn't matter.
751 static void osd_trans_stop(const struct lu_env *env, struct thandle *th)
754 struct osd_thandle *oh;
755 struct osd_thread_info *oti = osd_oti_get(env);
759 oh = container_of0(th, struct osd_thandle, ot_super);
760 if (oh->ot_handle != NULL) {
761 handle_t *hdl = oh->ot_handle;
763 hdl->h_sync = th->th_sync;
765 * add commit callback
766 * notice we don't do this in osd_trans_start()
767 * as underlying transaction can change during truncate
769 osd_journal_callback_set(hdl, osd_trans_commit_cb,
772 LASSERT(oti->oti_txns == 1);
774 LASSERT(oti->oti_r_locks == 0);
775 LASSERT(oti->oti_w_locks == 0);
776 result = dt_txn_hook_stop(env, th);
778 CERROR("Failure in transaction hook: %d\n", result);
779 oh->ot_handle = NULL;
780 OSD_CHECK_SLOW_TH(oh, oti->oti_dev,
781 result = ldiskfs_journal_stop(hdl));
783 CERROR("Failure to stop transaction: %d\n", result);
790 static int osd_trans_cb_add(struct thandle *th, struct dt_txn_commit_cb *dcb)
792 struct osd_thandle *oh = container_of0(th, struct osd_thandle,
795 cfs_list_add(&dcb->dcb_linkage, &oh->ot_dcb_list);
801 * Concurrency: no concurrent access is possible that late in object
804 static int osd_inode_remove(const struct lu_env *env, struct osd_object *obj)
806 const struct lu_fid *fid = lu_object_fid(&obj->oo_dt.do_lu);
807 struct osd_device *osd = osd_obj2dev(obj);
808 struct osd_thread_info *oti = osd_oti_get(env);
809 struct txn_param *prm = &oti->oti_txn;
810 struct lu_env *env_del_obj = &oti->oti_obj_delete_tx_env;
814 lu_env_init(env_del_obj, LCT_DT_THREAD);
815 txn_param_init(prm, OSD_TXN_OI_DELETE_CREDITS +
816 OSD_TXN_INODE_DELETE_CREDITS);
817 th = osd_trans_start(env_del_obj, &osd->od_dt_dev, prm);
819 result = osd_oi_delete(osd_oti_get(env_del_obj),
820 &osd->od_oi, fid, th);
821 osd_trans_stop(env_del_obj, th);
823 result = PTR_ERR(th);
825 lu_env_fini(env_del_obj);
830 * Called just before object is freed. Releases all resources except for
831 * object itself (that is released by osd_object_free()).
833 * Concurrency: no concurrent access is possible that late in object
836 static void osd_object_delete(const struct lu_env *env, struct lu_object *l)
838 struct osd_object *obj = osd_obj(l);
839 struct inode *inode = obj->oo_inode;
841 LINVRNT(osd_invariant(obj));
844 * If object is unlinked remove fid->ino mapping from object index.
851 if (osd_inode_unlinked(inode)) {
852 result = osd_inode_remove(env, obj);
854 LU_OBJECT_DEBUG(D_ERROR, env, l,
855 "Failed to cleanup: %d\n",
860 obj->oo_inode = NULL;
865 * Concurrency: ->loo_object_release() is called under site spin-lock.
867 static void osd_object_release(const struct lu_env *env,
870 struct osd_object *o = osd_obj(l);
872 LASSERT(!lu_object_is_dying(l->lo_header));
873 if (o->oo_inode != NULL && osd_inode_unlinked(o->oo_inode))
874 cfs_set_bit(LU_OBJECT_HEARD_BANSHEE, &l->lo_header->loh_flags);
878 * Concurrency: shouldn't matter.
880 static int osd_object_print(const struct lu_env *env, void *cookie,
881 lu_printer_t p, const struct lu_object *l)
883 struct osd_object *o = osd_obj(l);
886 if (o->oo_dir != NULL)
887 d = o->oo_dir->od_container.ic_descr;
890 return (*p)(env, cookie, LUSTRE_OSD_NAME"-object@%p(i:%p:%lu/%u)[%s]",
892 o->oo_inode ? o->oo_inode->i_ino : 0UL,
893 o->oo_inode ? o->oo_inode->i_generation : 0,
894 d ? d->id_ops->id_name : "plain");
898 * Concurrency: shouldn't matter.
900 int osd_statfs(const struct lu_env *env, struct dt_device *d,
903 struct osd_device *osd = osd_dt_dev(d);
904 struct super_block *sb = osd_sb(osd);
907 cfs_spin_lock(&osd->od_osfs_lock);
909 if (cfs_time_before_64(osd->od_osfs_age, cfs_time_shift_64(-1))) {
910 result = ll_do_statfs(sb, &osd->od_kstatfs);
911 if (likely(result == 0)) /* N.B. statfs can't really fail */
912 osd->od_osfs_age = cfs_time_current_64();
915 if (likely(result == 0))
916 *sfs = osd->od_kstatfs;
917 cfs_spin_unlock(&osd->od_osfs_lock);
923 * Concurrency: doesn't access mutable data.
925 static void osd_conf_get(const struct lu_env *env,
926 const struct dt_device *dev,
927 struct dt_device_param *param)
929 struct super_block *sb = osd_sb(osd_dt_dev(dev));
932 * XXX should be taken from not-yet-existing fs abstraction layer.
934 param->ddp_max_name_len = LDISKFS_NAME_LEN;
935 param->ddp_max_nlink = LDISKFS_LINK_MAX;
936 param->ddp_block_shift = osd_sb(osd_dt_dev(dev))->s_blocksize_bits;
937 param->ddp_mntopts = 0;
938 if (test_opt(sb, XATTR_USER))
939 param->ddp_mntopts |= MNTOPT_USERXATTR;
940 if (test_opt(sb, POSIX_ACL))
941 param->ddp_mntopts |= MNTOPT_ACL;
945 * Helper function to get and fill the buffer with input values.
947 static struct lu_buf *osd_buf_get(const struct lu_env *env, void *area, ssize_t len)
951 buf = &osd_oti_get(env)->oti_buf;
958 * Concurrency: shouldn't matter.
960 static int osd_sync(const struct lu_env *env, struct dt_device *d)
962 CDEBUG(D_HA, "syncing OSD %s\n", LUSTRE_OSD_NAME);
963 return ldiskfs_force_commit(osd_sb(osd_dt_dev(d)));
967 * Start commit for OSD device.
969 * An implementation of dt_commit_async method for OSD device.
970 * Asychronously starts underlayng fs sync and thereby a transaction
973 * \param env environment
976 * \see dt_device_operations
978 static int osd_commit_async(const struct lu_env *env,
981 struct super_block *s = osd_sb(osd_dt_dev(d));
984 CDEBUG(D_HA, "async commit OSD %s\n", LUSTRE_OSD_NAME);
985 RETURN(s->s_op->sync_fs(s, 0));
989 * Concurrency: shouldn't matter.
991 lvfs_sbdev_type fsfilt_ldiskfs_journal_sbdev(struct super_block *);
993 static void osd_ro(const struct lu_env *env, struct dt_device *d)
997 CERROR("*** setting device %s read-only ***\n", LUSTRE_OSD_NAME);
999 __lvfs_set_rdonly(lvfs_sbdev(osd_sb(osd_dt_dev(d))),
1000 fsfilt_ldiskfs_journal_sbdev(osd_sb(osd_dt_dev(d))));
1006 * Concurrency: serialization provided by callers.
1008 static int osd_init_capa_ctxt(const struct lu_env *env, struct dt_device *d,
1009 int mode, unsigned long timeout, __u32 alg,
1010 struct lustre_capa_key *keys)
1012 struct osd_device *dev = osd_dt_dev(d);
1015 dev->od_fl_capa = mode;
1016 dev->od_capa_timeout = timeout;
1017 dev->od_capa_alg = alg;
1018 dev->od_capa_keys = keys;
1023 * Concurrency: serialization provided by callers.
1025 static void osd_init_quota_ctxt(const struct lu_env *env, struct dt_device *d,
1026 struct dt_quota_ctxt *ctxt, void *data)
1028 struct obd_device *obd = (void *)ctxt;
1029 struct vfsmount *mnt = (struct vfsmount *)data;
1032 obd->u.obt.obt_sb = mnt->mnt_root->d_inode->i_sb;
1033 OBD_SET_CTXT_MAGIC(&obd->obd_lvfs_ctxt);
1034 obd->obd_lvfs_ctxt.pwdmnt = mnt;
1035 obd->obd_lvfs_ctxt.pwd = mnt->mnt_root;
1036 obd->obd_lvfs_ctxt.fs = get_ds();
1042 * Note: we do not count into QUOTA here.
1043 * If we mount with --data_journal we may need more.
1045 static const int osd_dto_credits_noquota[DTO_NR] = {
1048 * INDEX_EXTRA_TRANS_BLOCKS(8) +
1049 * SINGLEDATA_TRANS_BLOCKS(8)
1050 * XXX Note: maybe iam need more, since iam have more level than
1053 [DTO_INDEX_INSERT] = 16,
1054 [DTO_INDEX_DELETE] = 16,
1058 [DTO_IDNEX_UPDATE] = 16,
1060 * Create a object. The same as create object in EXT3.
1061 * DATA_TRANS_BLOCKS(14) +
1062 * INDEX_EXTRA_BLOCKS(8) +
1063 * 3(inode bits, groups, GDT)
1065 [DTO_OBJECT_CREATE] = 25,
1069 [DTO_OBJECT_DELETE] = 25,
1072 * 3(inode bits, group, GDT)
1074 [DTO_ATTR_SET_BASE] = 3,
1076 * Xattr set. The same as xattr of EXT3.
1077 * DATA_TRANS_BLOCKS(14)
1078 * XXX Note: in original MDS implmentation INDEX_EXTRA_TRANS_BLOCKS
1079 * are also counted in. Do not know why?
1081 [DTO_XATTR_SET] = 14,
1084 * creadits for inode change during write.
1086 [DTO_WRITE_BASE] = 3,
1088 * credits for single block write.
1090 [DTO_WRITE_BLOCK] = 14,
1092 * Attr set credits for chown.
1093 * This is extra credits for setattr, and it is null without quota
1095 [DTO_ATTR_SET_CHOWN]= 0
1099 * Note: we count into QUOTA here.
1100 * If we mount with --data_journal we may need more.
1102 static const int osd_dto_credits_quota[DTO_NR] = {
1104 * INDEX_EXTRA_TRANS_BLOCKS(8) +
1105 * SINGLEDATA_TRANS_BLOCKS(8) +
1106 * 2 * QUOTA_TRANS_BLOCKS(2)
1108 [DTO_INDEX_INSERT] = 20,
1110 * INDEX_EXTRA_TRANS_BLOCKS(8) +
1111 * SINGLEDATA_TRANS_BLOCKS(8) +
1112 * 2 * QUOTA_TRANS_BLOCKS(2)
1114 [DTO_INDEX_DELETE] = 20,
1118 [DTO_IDNEX_UPDATE] = 16,
1120 * Create a object. Same as create object in EXT3 filesystem.
1121 * DATA_TRANS_BLOCKS(16) +
1122 * INDEX_EXTRA_BLOCKS(8) +
1123 * 3(inode bits, groups, GDT) +
1124 * 2 * QUOTA_INIT_BLOCKS(25)
1126 [DTO_OBJECT_CREATE] = 77,
1129 * DATA_TRANS_BLOCKS(16) +
1130 * INDEX_EXTRA_BLOCKS(8) +
1131 * 3(inode bits, groups, GDT) +
1134 [DTO_OBJECT_DELETE] = 27,
1137 * 3 (inode bit, group, GDT) +
1139 [DTO_ATTR_SET_BASE] = 3,
1141 * Xattr set. The same as xattr of EXT3.
1142 * DATA_TRANS_BLOCKS(16)
1143 * XXX Note: in original MDS implmentation INDEX_EXTRA_TRANS_BLOCKS are
1144 * also counted in. Do not know why?
1146 [DTO_XATTR_SET] = 16,
1149 * creadits for inode change during write.
1151 [DTO_WRITE_BASE] = 3,
1153 * credits for single block write.
1155 [DTO_WRITE_BLOCK] = 16,
1157 * Attr set credits for chown.
1158 * It is added to already set setattr credits
1159 * 2 * QUOTA_INIT_BLOCKS(25) +
1160 * 2 * QUOTA_DEL_BLOCKS(9)
1162 [DTO_ATTR_SET_CHOWN]= 68,
1165 static int osd_credit_get(const struct lu_env *env, struct dt_device *d,
1168 LASSERT(ARRAY_SIZE(osd_dto_credits_noquota) ==
1169 ARRAY_SIZE(osd_dto_credits_quota));
1170 LASSERT(0 <= op && op < ARRAY_SIZE(osd_dto_credits_noquota));
1171 #ifdef HAVE_QUOTA_SUPPORT
1172 if (test_opt(osd_sb(osd_dt_dev(d)), QUOTA))
1173 return osd_dto_credits_quota[op];
1176 return osd_dto_credits_noquota[op];
1179 static const struct dt_device_operations osd_dt_ops = {
1180 .dt_root_get = osd_root_get,
1181 .dt_statfs = osd_statfs,
1182 .dt_trans_start = osd_trans_start,
1183 .dt_trans_stop = osd_trans_stop,
1184 .dt_trans_cb_add = osd_trans_cb_add,
1185 .dt_conf_get = osd_conf_get,
1186 .dt_sync = osd_sync,
1188 .dt_commit_async = osd_commit_async,
1189 .dt_credit_get = osd_credit_get,
1190 .dt_init_capa_ctxt = osd_init_capa_ctxt,
1191 .dt_init_quota_ctxt= osd_init_quota_ctxt,
1194 static void osd_object_read_lock(const struct lu_env *env,
1195 struct dt_object *dt, unsigned role)
1197 struct osd_object *obj = osd_dt_obj(dt);
1198 struct osd_thread_info *oti = osd_oti_get(env);
1200 LINVRNT(osd_invariant(obj));
1202 LASSERT(obj->oo_owner != env);
1203 cfs_down_read_nested(&obj->oo_sem, role);
1205 LASSERT(obj->oo_owner == NULL);
1209 static void osd_object_write_lock(const struct lu_env *env,
1210 struct dt_object *dt, unsigned role)
1212 struct osd_object *obj = osd_dt_obj(dt);
1213 struct osd_thread_info *oti = osd_oti_get(env);
1215 LINVRNT(osd_invariant(obj));
1217 LASSERT(obj->oo_owner != env);
1218 cfs_down_write_nested(&obj->oo_sem, role);
1220 LASSERT(obj->oo_owner == NULL);
1221 obj->oo_owner = env;
1225 static void osd_object_read_unlock(const struct lu_env *env,
1226 struct dt_object *dt)
1228 struct osd_object *obj = osd_dt_obj(dt);
1229 struct osd_thread_info *oti = osd_oti_get(env);
1231 LINVRNT(osd_invariant(obj));
1233 LASSERT(oti->oti_r_locks > 0);
1235 cfs_up_read(&obj->oo_sem);
1238 static void osd_object_write_unlock(const struct lu_env *env,
1239 struct dt_object *dt)
1241 struct osd_object *obj = osd_dt_obj(dt);
1242 struct osd_thread_info *oti = osd_oti_get(env);
1244 LINVRNT(osd_invariant(obj));
1246 LASSERT(obj->oo_owner == env);
1247 LASSERT(oti->oti_w_locks > 0);
1249 obj->oo_owner = NULL;
1250 cfs_up_write(&obj->oo_sem);
1253 static int osd_object_write_locked(const struct lu_env *env,
1254 struct dt_object *dt)
1256 struct osd_object *obj = osd_dt_obj(dt);
1258 LINVRNT(osd_invariant(obj));
1260 return obj->oo_owner == env;
1263 static int capa_is_sane(const struct lu_env *env,
1264 struct osd_device *dev,
1265 struct lustre_capa *capa,
1266 struct lustre_capa_key *keys)
1268 struct osd_thread_info *oti = osd_oti_get(env);
1269 struct lustre_capa *tcapa = &oti->oti_capa;
1270 struct obd_capa *oc;
1274 oc = capa_lookup(dev->od_capa_hash, capa, 0);
1276 if (capa_is_expired(oc)) {
1277 DEBUG_CAPA(D_ERROR, capa, "expired");
1284 if (capa_is_expired_sec(capa)) {
1285 DEBUG_CAPA(D_ERROR, capa, "expired");
1289 cfs_spin_lock(&capa_lock);
1290 for (i = 0; i < 2; i++) {
1291 if (keys[i].lk_keyid == capa->lc_keyid) {
1292 oti->oti_capa_key = keys[i];
1296 cfs_spin_unlock(&capa_lock);
1299 DEBUG_CAPA(D_ERROR, capa, "no matched capa key");
1303 rc = capa_hmac(tcapa->lc_hmac, capa, oti->oti_capa_key.lk_key);
1307 if (memcmp(tcapa->lc_hmac, capa->lc_hmac, sizeof(capa->lc_hmac))) {
1308 DEBUG_CAPA(D_ERROR, capa, "HMAC mismatch");
1312 oc = capa_add(dev->od_capa_hash, capa);
1318 static int osd_object_auth(const struct lu_env *env, struct dt_object *dt,
1319 struct lustre_capa *capa, __u64 opc)
1321 const struct lu_fid *fid = lu_object_fid(&dt->do_lu);
1322 struct osd_device *dev = osd_dev(dt->do_lu.lo_dev);
1323 struct md_capainfo *ci;
1326 if (!dev->od_fl_capa)
1329 if (capa == BYPASS_CAPA)
1332 ci = md_capainfo(env);
1336 if (ci->mc_auth == LC_ID_NONE)
1340 CERROR("no capability is provided for fid "DFID"\n", PFID(fid));
1344 if (!lu_fid_eq(fid, &capa->lc_fid)) {
1345 DEBUG_CAPA(D_ERROR, capa, "fid "DFID" mismatch with",
1350 if (!capa_opc_supported(capa, opc)) {
1351 DEBUG_CAPA(D_ERROR, capa, "opc "LPX64" not supported by", opc);
1355 if ((rc = capa_is_sane(env, dev, capa, dev->od_capa_keys))) {
1356 DEBUG_CAPA(D_ERROR, capa, "insane (rc %d)", rc);
1363 static struct timespec *osd_inode_time(const struct lu_env *env,
1364 struct inode *inode, __u64 seconds)
1366 struct osd_thread_info *oti = osd_oti_get(env);
1367 struct timespec *t = &oti->oti_time;
1369 t->tv_sec = seconds;
1371 *t = timespec_trunc(*t, get_sb_time_gran(inode->i_sb));
1376 static void osd_inode_getattr(const struct lu_env *env,
1377 struct inode *inode, struct lu_attr *attr)
1379 attr->la_valid |= LA_ATIME | LA_MTIME | LA_CTIME | LA_MODE |
1380 LA_SIZE | LA_BLOCKS | LA_UID | LA_GID |
1381 LA_FLAGS | LA_NLINK | LA_RDEV | LA_BLKSIZE;
1383 attr->la_atime = LTIME_S(inode->i_atime);
1384 attr->la_mtime = LTIME_S(inode->i_mtime);
1385 attr->la_ctime = LTIME_S(inode->i_ctime);
1386 attr->la_mode = inode->i_mode;
1387 attr->la_size = i_size_read(inode);
1388 attr->la_blocks = inode->i_blocks;
1389 attr->la_uid = inode->i_uid;
1390 attr->la_gid = inode->i_gid;
1391 attr->la_flags = LDISKFS_I(inode)->i_flags;
1392 attr->la_nlink = inode->i_nlink;
1393 attr->la_rdev = inode->i_rdev;
1394 attr->la_blksize = ll_inode_blksize(inode);
1395 attr->la_blkbits = inode->i_blkbits;
1398 static int osd_attr_get(const struct lu_env *env,
1399 struct dt_object *dt,
1400 struct lu_attr *attr,
1401 struct lustre_capa *capa)
1403 struct osd_object *obj = osd_dt_obj(dt);
1405 LASSERT(dt_object_exists(dt));
1406 LINVRNT(osd_invariant(obj));
1408 if (osd_object_auth(env, dt, capa, CAPA_OPC_META_READ))
1411 cfs_spin_lock(&obj->oo_guard);
1412 osd_inode_getattr(env, obj->oo_inode, attr);
1413 cfs_spin_unlock(&obj->oo_guard);
1417 static int osd_inode_setattr(const struct lu_env *env,
1418 struct inode *inode, const struct lu_attr *attr)
1422 bits = attr->la_valid;
1424 LASSERT(!(bits & LA_TYPE)); /* Huh? You want too much. */
1426 #ifdef HAVE_QUOTA_SUPPORT
1427 if ((bits & LA_UID && attr->la_uid != inode->i_uid) ||
1428 (bits & LA_GID && attr->la_gid != inode->i_gid)) {
1429 struct osd_ctxt *save = &osd_oti_get(env)->oti_ctxt;
1435 iattr.ia_valid |= ATTR_UID;
1437 iattr.ia_valid |= ATTR_GID;
1438 iattr.ia_uid = attr->la_uid;
1439 iattr.ia_gid = attr->la_gid;
1440 osd_push_ctxt(env, save);
1441 rc = ll_vfs_dq_transfer(inode, &iattr) ? -EDQUOT : 0;
1448 if (bits & LA_ATIME)
1449 inode->i_atime = *osd_inode_time(env, inode, attr->la_atime);
1450 if (bits & LA_CTIME)
1451 inode->i_ctime = *osd_inode_time(env, inode, attr->la_ctime);
1452 if (bits & LA_MTIME)
1453 inode->i_mtime = *osd_inode_time(env, inode, attr->la_mtime);
1454 if (bits & LA_SIZE) {
1455 LDISKFS_I(inode)->i_disksize = attr->la_size;
1456 i_size_write(inode, attr->la_size);
1460 /* OSD should not change "i_blocks" which is used by quota.
1461 * "i_blocks" should be changed by ldiskfs only. */
1462 if (bits & LA_BLOCKS)
1463 inode->i_blocks = attr->la_blocks;
1466 inode->i_mode = (inode->i_mode & S_IFMT) |
1467 (attr->la_mode & ~S_IFMT);
1469 inode->i_uid = attr->la_uid;
1471 inode->i_gid = attr->la_gid;
1472 if (bits & LA_NLINK)
1473 inode->i_nlink = attr->la_nlink;
1475 inode->i_rdev = attr->la_rdev;
1477 if (bits & LA_FLAGS) {
1478 /* always keep S_NOCMTIME */
1479 inode->i_flags = ll_ext_to_inode_flags(attr->la_flags) |
1485 static int osd_attr_set(const struct lu_env *env,
1486 struct dt_object *dt,
1487 const struct lu_attr *attr,
1488 struct thandle *handle,
1489 struct lustre_capa *capa)
1491 struct osd_object *obj = osd_dt_obj(dt);
1494 LASSERT(handle != NULL);
1495 LASSERT(dt_object_exists(dt));
1496 LASSERT(osd_invariant(obj));
1498 if (osd_object_auth(env, dt, capa, CAPA_OPC_META_WRITE))
1501 cfs_spin_lock(&obj->oo_guard);
1502 rc = osd_inode_setattr(env, obj->oo_inode, attr);
1503 cfs_spin_unlock(&obj->oo_guard);
1506 obj->oo_inode->i_sb->s_op->dirty_inode(obj->oo_inode);
1513 * XXX temporary solution.
1515 static int osd_create_pre(struct osd_thread_info *info, struct osd_object *obj,
1516 struct lu_attr *attr, struct thandle *th)
1521 static int osd_create_post(struct osd_thread_info *info, struct osd_object *obj,
1522 struct lu_attr *attr, struct thandle *th)
1524 osd_object_init0(obj);
1525 if (obj->oo_inode && (obj->oo_inode->i_state & I_NEW))
1526 unlock_new_inode(obj->oo_inode);
1530 static struct dentry * osd_child_dentry_get(const struct lu_env *env,
1531 struct osd_object *obj,
1535 struct osd_thread_info *info = osd_oti_get(env);
1536 struct dentry *child_dentry = &info->oti_child_dentry;
1537 struct dentry *obj_dentry = &info->oti_obj_dentry;
1539 obj_dentry->d_inode = obj->oo_inode;
1540 obj_dentry->d_sb = osd_sb(osd_obj2dev(obj));
1541 obj_dentry->d_name.hash = 0;
1543 child_dentry->d_name.hash = 0;
1544 child_dentry->d_parent = obj_dentry;
1545 child_dentry->d_name.name = name;
1546 child_dentry->d_name.len = namelen;
1547 return child_dentry;
1551 static int osd_mkfile(struct osd_thread_info *info, struct osd_object *obj,
1553 struct dt_allocation_hint *hint,
1557 struct osd_device *osd = osd_obj2dev(obj);
1558 struct osd_thandle *oth;
1559 struct dt_object *parent;
1560 struct inode *inode;
1561 #ifdef HAVE_QUOTA_SUPPORT
1562 struct osd_ctxt *save = &info->oti_ctxt;
1565 LINVRNT(osd_invariant(obj));
1566 LASSERT(obj->oo_inode == NULL);
1567 LASSERT(obj->oo_hl_head == NULL);
1569 if (S_ISDIR(mode) && ldiskfs_pdo) {
1570 obj->oo_hl_head =ldiskfs_htree_lock_head_alloc(HTREE_HBITS_DEF);
1571 if (obj->oo_hl_head == NULL)
1575 oth = container_of(th, struct osd_thandle, ot_super);
1576 LASSERT(oth->ot_handle->h_transaction != NULL);
1578 if (hint && hint->dah_parent)
1579 parent = hint->dah_parent;
1581 parent = osd->od_obj_area;
1583 LASSERT(parent != NULL);
1584 LASSERT(osd_dt_obj(parent)->oo_inode->i_op != NULL);
1586 #ifdef HAVE_QUOTA_SUPPORT
1587 osd_push_ctxt(info->oti_env, save);
1589 inode = ldiskfs_create_inode(oth->ot_handle,
1590 osd_dt_obj(parent)->oo_inode, mode);
1591 #ifdef HAVE_QUOTA_SUPPORT
1594 if (!IS_ERR(inode)) {
1595 /* Do not update file c/mtime in ldiskfs.
1596 * NB: don't need any lock because no contention at this
1598 inode->i_flags |= S_NOCMTIME;
1599 obj->oo_inode = inode;
1602 if (obj->oo_hl_head != NULL) {
1603 ldiskfs_htree_lock_head_free(obj->oo_hl_head);
1604 obj->oo_hl_head = NULL;
1606 result = PTR_ERR(inode);
1608 LINVRNT(osd_invariant(obj));
1616 static int osd_mkdir(struct osd_thread_info *info, struct osd_object *obj,
1617 struct lu_attr *attr,
1618 struct dt_allocation_hint *hint,
1619 struct dt_object_format *dof,
1623 struct osd_thandle *oth;
1624 struct osd_device *osd = osd_obj2dev(obj);
1625 __u32 mode = (attr->la_mode & (S_IFMT | S_IRWXUGO | S_ISVTX));
1627 LASSERT(S_ISDIR(attr->la_mode));
1629 oth = container_of(th, struct osd_thandle, ot_super);
1630 LASSERT(oth->ot_handle->h_transaction != NULL);
1631 result = osd_mkfile(info, obj, mode, hint, th);
1632 if (result == 0 && osd->od_iop_mode == 0) {
1633 LASSERT(obj->oo_inode != NULL);
1635 * XXX uh-oh... call low-level iam function directly.
1638 result = iam_lvar_create(obj->oo_inode, OSD_NAME_LEN, 4,
1639 sizeof (struct osd_fid_pack),
1645 static int osd_mk_index(struct osd_thread_info *info, struct osd_object *obj,
1646 struct lu_attr *attr,
1647 struct dt_allocation_hint *hint,
1648 struct dt_object_format *dof,
1652 struct osd_thandle *oth;
1653 const struct dt_index_features *feat = dof->u.dof_idx.di_feat;
1655 __u32 mode = (attr->la_mode & (S_IFMT | S_IRWXUGO | S_ISVTX));
1657 LASSERT(S_ISREG(attr->la_mode));
1659 oth = container_of(th, struct osd_thandle, ot_super);
1660 LASSERT(oth->ot_handle->h_transaction != NULL);
1662 result = osd_mkfile(info, obj, mode, hint, th);
1664 LASSERT(obj->oo_inode != NULL);
1665 if (feat->dif_flags & DT_IND_VARKEY)
1666 result = iam_lvar_create(obj->oo_inode,
1667 feat->dif_keysize_max,
1669 feat->dif_recsize_max,
1672 result = iam_lfix_create(obj->oo_inode,
1673 feat->dif_keysize_max,
1675 feat->dif_recsize_max,
1682 static int osd_mkreg(struct osd_thread_info *info, struct osd_object *obj,
1683 struct lu_attr *attr,
1684 struct dt_allocation_hint *hint,
1685 struct dt_object_format *dof,
1688 LASSERT(S_ISREG(attr->la_mode));
1689 return osd_mkfile(info, obj, (attr->la_mode &
1690 (S_IFMT | S_IRWXUGO | S_ISVTX)), hint, th);
1693 static int osd_mksym(struct osd_thread_info *info, struct osd_object *obj,
1694 struct lu_attr *attr,
1695 struct dt_allocation_hint *hint,
1696 struct dt_object_format *dof,
1699 LASSERT(S_ISLNK(attr->la_mode));
1700 return osd_mkfile(info, obj, (attr->la_mode &
1701 (S_IFMT | S_IRWXUGO | S_ISVTX)), hint, th);
1704 static int osd_mknod(struct osd_thread_info *info, struct osd_object *obj,
1705 struct lu_attr *attr,
1706 struct dt_allocation_hint *hint,
1707 struct dt_object_format *dof,
1710 cfs_umode_t mode = attr->la_mode & (S_IFMT | S_IRWXUGO | S_ISVTX);
1713 LINVRNT(osd_invariant(obj));
1714 LASSERT(obj->oo_inode == NULL);
1715 LASSERT(S_ISCHR(mode) || S_ISBLK(mode) ||
1716 S_ISFIFO(mode) || S_ISSOCK(mode));
1718 result = osd_mkfile(info, obj, mode, hint, th);
1720 LASSERT(obj->oo_inode != NULL);
1721 init_special_inode(obj->oo_inode, mode, attr->la_rdev);
1723 LINVRNT(osd_invariant(obj));
1727 typedef int (*osd_obj_type_f)(struct osd_thread_info *, struct osd_object *,
1729 struct dt_allocation_hint *hint,
1730 struct dt_object_format *dof,
1733 static osd_obj_type_f osd_create_type_f(enum dt_format_type type)
1735 osd_obj_type_f result;
1751 result = osd_mk_index;
1762 static void osd_ah_init(const struct lu_env *env, struct dt_allocation_hint *ah,
1763 struct dt_object *parent, cfs_umode_t child_mode)
1767 memset(ah, 0, sizeof(*ah));
1768 ah->dah_parent = parent;
1769 ah->dah_mode = child_mode;
1773 * Helper function for osd_object_create()
1775 * \retval 0, on success
1777 static int __osd_object_create(struct osd_thread_info *info,
1778 struct osd_object *obj, struct lu_attr *attr,
1779 struct dt_allocation_hint *hint,
1780 struct dt_object_format *dof,
1786 result = osd_create_pre(info, obj, attr, th);
1788 result = osd_create_type_f(dof->dof_type)(info, obj,
1789 attr, hint, dof, th);
1791 result = osd_create_post(info, obj, attr, th);
1797 * Helper function for osd_object_create()
1799 * \retval 0, on success
1801 static int __osd_oi_insert(const struct lu_env *env, struct osd_object *obj,
1802 const struct lu_fid *fid, struct thandle *th)
1804 struct osd_thread_info *info = osd_oti_get(env);
1805 struct osd_inode_id *id = &info->oti_id;
1806 struct osd_device *osd = osd_obj2dev(obj);
1807 struct md_ucred *uc = md_ucred(env);
1809 LASSERT(obj->oo_inode != NULL);
1810 LASSERT(uc != NULL);
1812 id->oii_ino = obj->oo_inode->i_ino;
1813 id->oii_gen = obj->oo_inode->i_generation;
1815 return osd_oi_insert(info, &osd->od_oi, fid, id, th,
1816 uc->mu_cap & CFS_CAP_SYS_RESOURCE_MASK);
1819 static int osd_object_create(const struct lu_env *env, struct dt_object *dt,
1820 struct lu_attr *attr,
1821 struct dt_allocation_hint *hint,
1822 struct dt_object_format *dof,
1825 const struct lu_fid *fid = lu_object_fid(&dt->do_lu);
1826 struct osd_object *obj = osd_dt_obj(dt);
1827 struct osd_thread_info *info = osd_oti_get(env);
1832 LINVRNT(osd_invariant(obj));
1833 LASSERT(!dt_object_exists(dt));
1834 LASSERT(osd_write_locked(env, obj));
1835 LASSERT(th != NULL);
1837 result = __osd_object_create(info, obj, attr, hint, dof, th);
1839 result = __osd_oi_insert(env, obj, fid, th);
1841 LASSERT(ergo(result == 0, dt_object_exists(dt)));
1842 LASSERT(osd_invariant(obj));
1847 * Helper function for osd_xattr_set()
1849 static int __osd_xattr_set(const struct lu_env *env, struct dt_object *dt,
1850 const struct lu_buf *buf, const char *name, int fl)
1852 struct osd_object *obj = osd_dt_obj(dt);
1853 struct inode *inode = obj->oo_inode;
1854 struct osd_thread_info *info = osd_oti_get(env);
1855 struct dentry *dentry = &info->oti_child_dentry;
1859 LASSERT(dt_object_exists(dt));
1860 LASSERT(inode->i_op != NULL && inode->i_op->setxattr != NULL);
1861 LASSERT(osd_write_locked(env, obj));
1863 if (fl & LU_XATTR_REPLACE)
1864 fs_flags |= XATTR_REPLACE;
1866 if (fl & LU_XATTR_CREATE)
1867 fs_flags |= XATTR_CREATE;
1869 dentry->d_inode = inode;
1870 rc = inode->i_op->setxattr(dentry, name, buf->lb_buf,
1871 buf->lb_len, fs_flags);
1876 * Put the fid into lustre_mdt_attrs, and then place the structure
1877 * inode's ea. This fid should not be altered during the life time
1880 * \retval +ve, on success
1881 * \retval -ve, on error
1883 * FIXME: It is good to have/use ldiskfs_xattr_set_handle() here
1885 static int osd_ea_fid_set(const struct lu_env *env, struct dt_object *dt,
1886 const struct lu_fid *fid)
1888 struct osd_thread_info *info = osd_oti_get(env);
1889 struct lustre_mdt_attrs *mdt_attrs = &info->oti_mdt_attrs;
1891 lustre_lma_init(mdt_attrs, fid);
1892 lustre_lma_swab(mdt_attrs);
1893 return __osd_xattr_set(env, dt,
1894 osd_buf_get(env, mdt_attrs, sizeof *mdt_attrs),
1895 XATTR_NAME_LMA, LU_XATTR_CREATE);
1900 * Helper function to form igif
1902 static inline void osd_igif_get(const struct lu_env *env, struct inode *inode,
1905 LU_IGIF_BUILD(fid, inode->i_ino, inode->i_generation);
1909 * Helper function to pack the fid, ldiskfs stores fid in packed format.
1911 void osd_fid_pack(struct osd_fid_pack *pack, const struct dt_rec *fid,
1912 struct lu_fid *befider)
1914 fid_cpu_to_be(befider, (struct lu_fid *)fid);
1915 memcpy(pack->fp_area, befider, sizeof(*befider));
1916 pack->fp_len = sizeof(*befider) + 1;
1920 * ldiskfs supports fid in dirent, it is passed in dentry->d_fsdata.
1921 * lustre 1.8 also uses d_fsdata for passing other info to ldiskfs.
1922 * To have compatilibility with 1.8 ldiskfs driver we need to have
1923 * magic number at start of fid data.
1924 * \ldiskfs_dentry_param is used only to pass fid from osd to ldiskfs.
1927 void osd_get_ldiskfs_dirent_param(struct ldiskfs_dentry_param *param,
1928 const struct dt_rec *fid)
1930 param->edp_magic = LDISKFS_LUFID_MAGIC;
1931 param->edp_len = sizeof(struct lu_fid) + 1;
1933 fid_cpu_to_be((struct lu_fid *)param->edp_data,
1934 (struct lu_fid *)fid);
1937 int osd_fid_unpack(struct lu_fid *fid, const struct osd_fid_pack *pack)
1942 switch (pack->fp_len) {
1943 case sizeof *fid + 1:
1944 memcpy(fid, pack->fp_area, sizeof *fid);
1945 fid_be_to_cpu(fid, fid);
1948 CERROR("Unexpected packed fid size: %d\n", pack->fp_len);
1955 * Try to read the fid from inode ea into dt_rec, if return value
1956 * i.e. rc is +ve, then we got fid, otherwise we will have to form igif
1958 * \param fid object fid.
1960 * \retval 0 on success
1962 static int osd_ea_fid_get(const struct lu_env *env, struct osd_object *obj,
1963 __u32 ino, struct lu_fid *fid)
1965 struct osd_thread_info *info = osd_oti_get(env);
1966 struct lustre_mdt_attrs *mdt_attrs = &info->oti_mdt_attrs;
1967 struct lu_device *ldev = obj->oo_dt.do_lu.lo_dev;
1968 struct dentry *dentry = &info->oti_child_dentry;
1969 struct osd_inode_id *id = &info->oti_id;
1970 struct osd_device *dev;
1971 struct inode *inode;
1975 dev = osd_dev(ldev);
1978 id->oii_gen = OSD_OII_NOGEN;
1980 inode = osd_iget(info, dev, id);
1981 if (IS_ERR(inode)) {
1982 rc = PTR_ERR(inode);
1985 dentry->d_inode = inode;
1987 LASSERT(inode->i_op != NULL && inode->i_op->getxattr != NULL);
1988 rc = inode->i_op->getxattr(dentry, XATTR_NAME_LMA, (void *)mdt_attrs,
1991 /* Check LMA compatibility */
1993 (mdt_attrs->lma_incompat & ~cpu_to_le32(LMA_INCOMPAT_SUPP))) {
1994 CWARN("Inode %lx: Unsupported incompat LMA feature(s) %#x\n",
1995 inode->i_ino, le32_to_cpu(mdt_attrs->lma_incompat) &
1996 ~LMA_INCOMPAT_SUPP);
2001 lustre_lma_swab(mdt_attrs);
2002 memcpy(fid, &mdt_attrs->lma_self_fid, sizeof(*fid));
2004 } else if (rc == -ENODATA) {
2005 osd_igif_get(env, inode, fid);
2014 * OSD layer object create function for interoperability mode (b11826).
2015 * This is mostly similar to osd_object_create(). Only difference being, fid is
2016 * inserted into inode ea here.
2018 * \retval 0, on success
2019 * \retval -ve, on error
2021 static int osd_object_ea_create(const struct lu_env *env, struct dt_object *dt,
2022 struct lu_attr *attr,
2023 struct dt_allocation_hint *hint,
2024 struct dt_object_format *dof,
2027 const struct lu_fid *fid = lu_object_fid(&dt->do_lu);
2028 struct osd_object *obj = osd_dt_obj(dt);
2029 struct osd_thread_info *info = osd_oti_get(env);
2034 LASSERT(osd_invariant(obj));
2035 LASSERT(!dt_object_exists(dt));
2036 LASSERT(osd_write_locked(env, obj));
2037 LASSERT(th != NULL);
2039 result = __osd_object_create(info, obj, attr, hint, dof, th);
2041 /* objects under osd root shld have igif fid, so dont add fid EA */
2042 if (result == 0 && fid_seq(fid) >= FID_SEQ_NORMAL)
2043 result = osd_ea_fid_set(env, dt, fid);
2046 result = __osd_oi_insert(env, obj, fid, th);
2048 LASSERT(ergo(result == 0, dt_object_exists(dt)));
2049 LINVRNT(osd_invariant(obj));
2054 * Concurrency: @dt is write locked.
2056 static void osd_object_ref_add(const struct lu_env *env,
2057 struct dt_object *dt,
2060 struct osd_object *obj = osd_dt_obj(dt);
2061 struct inode *inode = obj->oo_inode;
2063 LINVRNT(osd_invariant(obj));
2064 LASSERT(dt_object_exists(dt));
2065 LASSERT(osd_write_locked(env, obj));
2066 LASSERT(th != NULL);
2068 cfs_spin_lock(&obj->oo_guard);
2069 LASSERT(inode->i_nlink < LDISKFS_LINK_MAX);
2071 cfs_spin_unlock(&obj->oo_guard);
2072 inode->i_sb->s_op->dirty_inode(inode);
2073 LINVRNT(osd_invariant(obj));
2077 * Concurrency: @dt is write locked.
2079 static void osd_object_ref_del(const struct lu_env *env,
2080 struct dt_object *dt,
2083 struct osd_object *obj = osd_dt_obj(dt);
2084 struct inode *inode = obj->oo_inode;
2086 LINVRNT(osd_invariant(obj));
2087 LASSERT(dt_object_exists(dt));
2088 LASSERT(osd_write_locked(env, obj));
2089 LASSERT(th != NULL);
2091 cfs_spin_lock(&obj->oo_guard);
2092 LASSERT(inode->i_nlink > 0);
2094 cfs_spin_unlock(&obj->oo_guard);
2095 inode->i_sb->s_op->dirty_inode(inode);
2096 LINVRNT(osd_invariant(obj));
2100 * Concurrency: @dt is read locked.
2102 static int osd_xattr_get(const struct lu_env *env,
2103 struct dt_object *dt,
2106 struct lustre_capa *capa)
2108 struct osd_object *obj = osd_dt_obj(dt);
2109 struct inode *inode = obj->oo_inode;
2110 struct osd_thread_info *info = osd_oti_get(env);
2111 struct dentry *dentry = &info->oti_obj_dentry;
2113 LASSERT(dt_object_exists(dt));
2114 LASSERT(inode->i_op != NULL && inode->i_op->getxattr != NULL);
2115 LASSERT(osd_read_locked(env, obj) || osd_write_locked(env, obj));
2117 if (osd_object_auth(env, dt, capa, CAPA_OPC_META_READ))
2120 dentry->d_inode = inode;
2121 return inode->i_op->getxattr(dentry, name, buf->lb_buf, buf->lb_len);
2125 * Concurrency: @dt is write locked.
2127 static int osd_xattr_set(const struct lu_env *env, struct dt_object *dt,
2128 const struct lu_buf *buf, const char *name, int fl,
2129 struct thandle *handle, struct lustre_capa *capa)
2131 LASSERT(handle != NULL);
2133 if (osd_object_auth(env, dt, capa, CAPA_OPC_META_WRITE))
2136 return __osd_xattr_set(env, dt, buf, name, fl);
2140 * Concurrency: @dt is read locked.
2142 static int osd_xattr_list(const struct lu_env *env,
2143 struct dt_object *dt,
2145 struct lustre_capa *capa)
2147 struct osd_object *obj = osd_dt_obj(dt);
2148 struct inode *inode = obj->oo_inode;
2149 struct osd_thread_info *info = osd_oti_get(env);
2150 struct dentry *dentry = &info->oti_obj_dentry;
2152 LASSERT(dt_object_exists(dt));
2153 LASSERT(inode->i_op != NULL && inode->i_op->listxattr != NULL);
2154 LASSERT(osd_read_locked(env, obj) || osd_write_locked(env, obj));
2156 if (osd_object_auth(env, dt, capa, CAPA_OPC_META_READ))
2159 dentry->d_inode = inode;
2160 return inode->i_op->listxattr(dentry, buf->lb_buf, buf->lb_len);
2164 * Concurrency: @dt is write locked.
2166 static int osd_xattr_del(const struct lu_env *env,
2167 struct dt_object *dt,
2169 struct thandle *handle,
2170 struct lustre_capa *capa)
2172 struct osd_object *obj = osd_dt_obj(dt);
2173 struct inode *inode = obj->oo_inode;
2174 struct osd_thread_info *info = osd_oti_get(env);
2175 struct dentry *dentry = &info->oti_obj_dentry;
2178 LASSERT(dt_object_exists(dt));
2179 LASSERT(inode->i_op != NULL && inode->i_op->removexattr != NULL);
2180 LASSERT(osd_write_locked(env, obj));
2181 LASSERT(handle != NULL);
2183 if (osd_object_auth(env, dt, capa, CAPA_OPC_META_WRITE))
2186 dentry->d_inode = inode;
2187 rc = inode->i_op->removexattr(dentry, name);
2191 static struct obd_capa *osd_capa_get(const struct lu_env *env,
2192 struct dt_object *dt,
2193 struct lustre_capa *old,
2196 struct osd_thread_info *info = osd_oti_get(env);
2197 const struct lu_fid *fid = lu_object_fid(&dt->do_lu);
2198 struct osd_object *obj = osd_dt_obj(dt);
2199 struct osd_device *dev = osd_obj2dev(obj);
2200 struct lustre_capa_key *key = &info->oti_capa_key;
2201 struct lustre_capa *capa = &info->oti_capa;
2202 struct obd_capa *oc;
2203 struct md_capainfo *ci;
2207 if (!dev->od_fl_capa)
2208 RETURN(ERR_PTR(-ENOENT));
2210 LASSERT(dt_object_exists(dt));
2211 LINVRNT(osd_invariant(obj));
2213 /* renewal sanity check */
2214 if (old && osd_object_auth(env, dt, old, opc))
2215 RETURN(ERR_PTR(-EACCES));
2217 ci = md_capainfo(env);
2219 RETURN(ERR_PTR(-ENOENT));
2221 switch (ci->mc_auth) {
2225 capa->lc_uid = obj->oo_inode->i_uid;
2226 capa->lc_gid = obj->oo_inode->i_gid;
2227 capa->lc_flags = LC_ID_PLAIN;
2229 case LC_ID_CONVERT: {
2232 s[0] = obj->oo_inode->i_uid;
2233 cfs_get_random_bytes(&(s[1]), sizeof(__u32));
2234 s[2] = obj->oo_inode->i_gid;
2235 cfs_get_random_bytes(&(s[3]), sizeof(__u32));
2236 rc = capa_encrypt_id(d, s, key->lk_key, CAPA_HMAC_KEY_MAX_LEN);
2238 RETURN(ERR_PTR(rc));
2240 capa->lc_uid = ((__u64)d[1] << 32) | d[0];
2241 capa->lc_gid = ((__u64)d[3] << 32) | d[2];
2242 capa->lc_flags = LC_ID_CONVERT;
2246 RETURN(ERR_PTR(-EINVAL));
2249 capa->lc_fid = *fid;
2251 capa->lc_flags |= dev->od_capa_alg << 24;
2252 capa->lc_timeout = dev->od_capa_timeout;
2253 capa->lc_expiry = 0;
2255 oc = capa_lookup(dev->od_capa_hash, capa, 1);
2257 LASSERT(!capa_is_expired(oc));
2261 cfs_spin_lock(&capa_lock);
2262 *key = dev->od_capa_keys[1];
2263 cfs_spin_unlock(&capa_lock);
2265 capa->lc_keyid = key->lk_keyid;
2266 capa->lc_expiry = cfs_time_current_sec() + dev->od_capa_timeout;
2268 rc = capa_hmac(capa->lc_hmac, capa, key->lk_key);
2270 DEBUG_CAPA(D_ERROR, capa, "HMAC failed: %d for", rc);
2271 RETURN(ERR_PTR(rc));
2274 oc = capa_add(dev->od_capa_hash, capa);
2278 static int osd_object_sync(const struct lu_env *env, struct dt_object *dt)
2281 struct osd_object *obj = osd_dt_obj(dt);
2282 struct inode *inode = obj->oo_inode;
2283 struct osd_thread_info *info = osd_oti_get(env);
2284 struct dentry *dentry = &info->oti_obj_dentry;
2285 struct file *file = &info->oti_file;
2288 dentry->d_inode = inode;
2289 file->f_dentry = dentry;
2290 file->f_mapping = inode->i_mapping;
2291 file->f_op = inode->i_fop;
2292 LOCK_INODE_MUTEX(inode);
2293 rc = file->f_op->fsync(file, dentry, 0);
2294 UNLOCK_INODE_MUTEX(inode);
2299 * Get the 64-bit version for an inode.
2301 static dt_obj_version_t osd_object_version_get(const struct lu_env *env,
2302 struct dt_object *dt)
2304 struct inode *inode = osd_dt_obj(dt)->oo_inode;
2306 CDEBUG(D_INFO, "Get version "LPX64" for inode %lu\n",
2307 LDISKFS_I(inode)->i_fs_version, inode->i_ino);
2308 return LDISKFS_I(inode)->i_fs_version;
2312 * Set the 64-bit version and return the old version.
2314 static void osd_object_version_set(const struct lu_env *env, struct dt_object *dt,
2315 dt_obj_version_t new_version)
2317 struct inode *inode = osd_dt_obj(dt)->oo_inode;
2319 CDEBUG(D_INFO, "Set version "LPX64" (old "LPX64") for inode %lu\n",
2320 new_version, LDISKFS_I(inode)->i_fs_version, inode->i_ino);
2321 LDISKFS_I(inode)->i_fs_version = new_version;
2322 /** Version is set after all inode operations are finished,
2323 * so we should mark it dirty here */
2324 inode->i_sb->s_op->dirty_inode(inode);
2327 static int osd_data_get(const struct lu_env *env, struct dt_object *dt,
2330 struct osd_object *obj = osd_dt_obj(dt);
2333 *data = (void *)obj->oo_inode;
2341 static int osd_iam_index_probe(const struct lu_env *env, struct osd_object *o,
2342 const struct dt_index_features *feat)
2344 struct iam_descr *descr;
2346 if (osd_object_is_root(o))
2347 return feat == &dt_directory_features;
2349 LASSERT(o->oo_dir != NULL);
2351 descr = o->oo_dir->od_container.ic_descr;
2352 if (feat == &dt_directory_features) {
2353 if (descr->id_rec_size == sizeof(struct osd_fid_pack))
2359 feat->dif_keysize_min <= descr->id_key_size &&
2360 descr->id_key_size <= feat->dif_keysize_max &&
2361 feat->dif_recsize_min <= descr->id_rec_size &&
2362 descr->id_rec_size <= feat->dif_recsize_max &&
2363 !(feat->dif_flags & (DT_IND_VARKEY |
2364 DT_IND_VARREC | DT_IND_NONUNQ)) &&
2365 ergo(feat->dif_flags & DT_IND_UPDATE,
2366 1 /* XXX check that object (and file system) is
2371 static int osd_iam_container_init(const struct lu_env *env,
2372 struct osd_object *obj,
2373 struct osd_directory *dir)
2375 struct iam_container *bag = &dir->od_container;
2378 result = iam_container_init(bag, &dir->od_descr, obj->oo_inode);
2382 result = iam_container_setup(bag);
2386 if (osd_obj2dev(obj)->od_iop_mode) {
2387 u32 ptr = bag->ic_descr->id_ops->id_root_ptr(bag);
2389 bag->ic_root_bh = ldiskfs_bread(NULL, obj->oo_inode,
2395 obj->oo_dt.do_index_ops = &osd_index_iam_ops;
2397 iam_container_fini(bag);
2404 * Concurrency: no external locking is necessary.
2406 static int osd_index_try(const struct lu_env *env, struct dt_object *dt,
2407 const struct dt_index_features *feat)
2411 struct osd_object *obj = osd_dt_obj(dt);
2412 struct osd_device *osd = osd_obj2dev(obj);
2414 LINVRNT(osd_invariant(obj));
2415 LASSERT(dt_object_exists(dt));
2417 if (osd_object_is_root(obj)) {
2418 dt->do_index_ops = &osd_index_ea_ops;
2420 } else if (feat == &dt_directory_features && osd->od_iop_mode) {
2421 dt->do_index_ops = &osd_index_ea_ops;
2422 if (S_ISDIR(obj->oo_inode->i_mode))
2427 } else if (!osd_has_index(obj)) {
2428 struct osd_directory *dir;
2433 cfs_spin_lock(&obj->oo_guard);
2434 if (obj->oo_dir == NULL)
2438 * Concurrent thread allocated container data.
2441 cfs_spin_unlock(&obj->oo_guard);
2443 * Now, that we have container data, serialize its
2446 cfs_down_write(&obj->oo_ext_idx_sem);
2448 * recheck under lock.
2450 if (!osd_has_index(obj))
2451 result = osd_iam_container_init(env, obj, dir);
2454 cfs_up_write(&obj->oo_ext_idx_sem);
2462 if (result == 0 && ea_dir == 0) {
2463 if (!osd_iam_index_probe(env, obj, feat))
2466 LINVRNT(osd_invariant(obj));
2471 static const struct dt_object_operations osd_obj_ops = {
2472 .do_read_lock = osd_object_read_lock,
2473 .do_write_lock = osd_object_write_lock,
2474 .do_read_unlock = osd_object_read_unlock,
2475 .do_write_unlock = osd_object_write_unlock,
2476 .do_write_locked = osd_object_write_locked,
2477 .do_attr_get = osd_attr_get,
2478 .do_attr_set = osd_attr_set,
2479 .do_ah_init = osd_ah_init,
2480 .do_create = osd_object_create,
2481 .do_index_try = osd_index_try,
2482 .do_ref_add = osd_object_ref_add,
2483 .do_ref_del = osd_object_ref_del,
2484 .do_xattr_get = osd_xattr_get,
2485 .do_xattr_set = osd_xattr_set,
2486 .do_xattr_del = osd_xattr_del,
2487 .do_xattr_list = osd_xattr_list,
2488 .do_capa_get = osd_capa_get,
2489 .do_object_sync = osd_object_sync,
2490 .do_version_get = osd_object_version_get,
2491 .do_version_set = osd_object_version_set,
2492 .do_data_get = osd_data_get,
2496 * dt_object_operations for interoperability mode
2497 * (i.e. to run 2.0 mds on 1.8 disk) (b11826)
2499 static const struct dt_object_operations osd_obj_ea_ops = {
2500 .do_read_lock = osd_object_read_lock,
2501 .do_write_lock = osd_object_write_lock,
2502 .do_read_unlock = osd_object_read_unlock,
2503 .do_write_unlock = osd_object_write_unlock,
2504 .do_write_locked = osd_object_write_locked,
2505 .do_attr_get = osd_attr_get,
2506 .do_attr_set = osd_attr_set,
2507 .do_ah_init = osd_ah_init,
2508 .do_create = osd_object_ea_create,
2509 .do_index_try = osd_index_try,
2510 .do_ref_add = osd_object_ref_add,
2511 .do_ref_del = osd_object_ref_del,
2512 .do_xattr_get = osd_xattr_get,
2513 .do_xattr_set = osd_xattr_set,
2514 .do_xattr_del = osd_xattr_del,
2515 .do_xattr_list = osd_xattr_list,
2516 .do_capa_get = osd_capa_get,
2517 .do_object_sync = osd_object_sync,
2518 .do_version_get = osd_object_version_get,
2519 .do_version_set = osd_object_version_set,
2520 .do_data_get = osd_data_get,
2528 * XXX: Another layering violation for now.
2530 * We don't want to use ->f_op->read methods, because generic file write
2532 * - serializes on ->i_sem, and
2534 * - does a lot of extra work like balance_dirty_pages(),
2536 * which doesn't work for globally shared files like /last-received.
2538 static int osd_ldiskfs_readlink(struct inode *inode, char *buffer, int buflen)
2540 struct ldiskfs_inode_info *ei = LDISKFS_I(inode);
2542 memcpy(buffer, (char*)ei->i_data, buflen);
2547 static int osd_ldiskfs_read(struct inode *inode, void *buf, int size,
2550 struct buffer_head *bh;
2551 unsigned long block;
2558 /* prevent reading after eof */
2559 spin_lock(&inode->i_lock);
2560 if (i_size_read(inode) < *offs + size) {
2561 size = i_size_read(inode) - *offs;
2562 spin_unlock(&inode->i_lock);
2564 CDEBUG(D_EXT2, "size %llu is too short to read @%llu\n",
2565 i_size_read(inode), *offs);
2567 } else if (size == 0) {
2571 spin_unlock(&inode->i_lock);
2574 blocksize = 1 << inode->i_blkbits;
2577 block = *offs >> inode->i_blkbits;
2578 boffs = *offs & (blocksize - 1);
2579 csize = min(blocksize - boffs, size);
2580 bh = ldiskfs_bread(NULL, inode, block, 0, &err);
2582 CERROR("can't read block: %d\n", err);
2586 memcpy(buf, bh->b_data + boffs, csize);
2596 static ssize_t osd_read(const struct lu_env *env, struct dt_object *dt,
2597 struct lu_buf *buf, loff_t *pos,
2598 struct lustre_capa *capa)
2600 struct osd_object *obj = osd_dt_obj(dt);
2601 struct inode *inode = obj->oo_inode;
2604 if (osd_object_auth(env, dt, capa, CAPA_OPC_BODY_READ))
2607 /* Read small symlink from inode body as we need to maintain correct
2608 * on-disk symlinks for ldiskfs.
2610 if (S_ISLNK(obj->oo_dt.do_lu.lo_header->loh_attr) &&
2611 (buf->lb_len <= sizeof (LDISKFS_I(inode)->i_data)))
2612 rc = osd_ldiskfs_readlink(inode, buf->lb_buf, buf->lb_len);
2614 rc = osd_ldiskfs_read(inode, buf->lb_buf, buf->lb_len, pos);
2619 static int osd_ldiskfs_writelink(struct inode *inode, char *buffer, int buflen)
2622 memcpy((char*)&LDISKFS_I(inode)->i_data, (char *)buffer,
2624 LDISKFS_I(inode)->i_disksize = buflen;
2625 i_size_write(inode, buflen);
2626 inode->i_sb->s_op->dirty_inode(inode);
2631 static int osd_ldiskfs_write_record(struct inode *inode, void *buf, int bufsize,
2632 loff_t *offs, handle_t *handle)
2634 struct buffer_head *bh = NULL;
2635 loff_t offset = *offs;
2636 loff_t new_size = i_size_read(inode);
2637 unsigned long block;
2638 int blocksize = 1 << inode->i_blkbits;
2642 int dirty_inode = 0;
2644 while (bufsize > 0) {
2648 block = offset >> inode->i_blkbits;
2649 boffs = offset & (blocksize - 1);
2650 size = min(blocksize - boffs, bufsize);
2651 bh = ldiskfs_bread(handle, inode, block, 1, &err);
2653 CERROR("can't read/create block: %d\n", err);
2657 err = ldiskfs_journal_get_write_access(handle, bh);
2659 CERROR("journal_get_write_access() returned error %d\n",
2663 LASSERTF(boffs + size <= bh->b_size,
2664 "boffs %d size %d bh->b_size %lu",
2665 boffs, size, (unsigned long)bh->b_size);
2666 memcpy(bh->b_data + boffs, buf, size);
2667 err = ldiskfs_journal_dirty_metadata(handle, bh);
2671 if (offset + size > new_size)
2672 new_size = offset + size;
2680 /* correct in-core and on-disk sizes */
2681 if (new_size > i_size_read(inode)) {
2682 spin_lock(&inode->i_lock);
2683 if (new_size > i_size_read(inode))
2684 i_size_write(inode, new_size);
2685 if (i_size_read(inode) > LDISKFS_I(inode)->i_disksize) {
2686 LDISKFS_I(inode)->i_disksize = i_size_read(inode);
2689 spin_unlock(&inode->i_lock);
2691 inode->i_sb->s_op->dirty_inode(inode);
2699 static ssize_t osd_write(const struct lu_env *env, struct dt_object *dt,
2700 const struct lu_buf *buf, loff_t *pos,
2701 struct thandle *handle, struct lustre_capa *capa,
2704 struct osd_object *obj = osd_dt_obj(dt);
2705 struct inode *inode = obj->oo_inode;
2706 struct osd_thandle *oh;
2708 #ifdef HAVE_QUOTA_SUPPORT
2709 cfs_cap_t save = cfs_curproc_cap_pack();
2712 LASSERT(handle != NULL);
2714 if (osd_object_auth(env, dt, capa, CAPA_OPC_BODY_WRITE))
2717 oh = container_of(handle, struct osd_thandle, ot_super);
2718 LASSERT(oh->ot_handle->h_transaction != NULL);
2719 #ifdef HAVE_QUOTA_SUPPORT
2721 cfs_cap_raise(CFS_CAP_SYS_RESOURCE);
2723 cfs_cap_lower(CFS_CAP_SYS_RESOURCE);
2725 /* Write small symlink to inode body as we need to maintain correct
2726 * on-disk symlinks for ldiskfs.
2728 if(S_ISLNK(obj->oo_dt.do_lu.lo_header->loh_attr) &&
2729 (buf->lb_len < sizeof (LDISKFS_I(inode)->i_data)))
2730 result = osd_ldiskfs_writelink(inode, buf->lb_buf, buf->lb_len);
2732 result = osd_ldiskfs_write_record(inode, buf->lb_buf,
2735 #ifdef HAVE_QUOTA_SUPPORT
2736 cfs_curproc_cap_unpack(save);
2739 result = buf->lb_len;
2743 static const struct dt_body_operations osd_body_ops = {
2744 .dbo_read = osd_read,
2745 .dbo_write = osd_write
2750 * delete a (key, value) pair from index \a dt specified by \a key
2752 * \param dt osd index object
2753 * \param key key for index
2754 * \param rec record reference
2755 * \param handle transaction handler
2758 * \retval -ve failure
2761 static int osd_index_iam_delete(const struct lu_env *env, struct dt_object *dt,
2762 const struct dt_key *key, struct thandle *handle,
2763 struct lustre_capa *capa)
2765 struct osd_object *obj = osd_dt_obj(dt);
2766 struct osd_thandle *oh;
2767 struct iam_path_descr *ipd;
2768 struct iam_container *bag = &obj->oo_dir->od_container;
2773 LINVRNT(osd_invariant(obj));
2774 LASSERT(dt_object_exists(dt));
2775 LASSERT(bag->ic_object == obj->oo_inode);
2776 LASSERT(handle != NULL);
2778 if (osd_object_auth(env, dt, capa, CAPA_OPC_INDEX_DELETE))
2781 ipd = osd_idx_ipd_get(env, bag);
2782 if (unlikely(ipd == NULL))
2785 oh = container_of0(handle, struct osd_thandle, ot_super);
2786 LASSERT(oh->ot_handle != NULL);
2787 LASSERT(oh->ot_handle->h_transaction != NULL);
2789 rc = iam_delete(oh->ot_handle, bag, (const struct iam_key *)key, ipd);
2790 osd_ipd_put(env, bag, ipd);
2791 LINVRNT(osd_invariant(obj));
2795 static inline int osd_get_fid_from_dentry(struct ldiskfs_dir_entry_2 *de,
2798 struct osd_fid_pack *rec;
2801 if (de->file_type & LDISKFS_DIRENT_LUFID) {
2802 rec = (struct osd_fid_pack *) (de->name + de->name_len + 1);
2803 rc = osd_fid_unpack((struct lu_fid *)fid, rec);
2809 * Index delete function for interoperability mode (b11826).
2810 * It will remove the directory entry added by osd_index_ea_insert().
2811 * This entry is needed to maintain name->fid mapping.
2813 * \param key, key i.e. file entry to be deleted
2815 * \retval 0, on success
2816 * \retval -ve, on error
2818 static int osd_index_ea_delete(const struct lu_env *env, struct dt_object *dt,
2819 const struct dt_key *key, struct thandle *handle,
2820 struct lustre_capa *capa)
2822 struct osd_object *obj = osd_dt_obj(dt);
2823 struct inode *dir = obj->oo_inode;
2824 struct dentry *dentry;
2825 struct osd_thandle *oh;
2826 struct ldiskfs_dir_entry_2 *de;
2827 struct buffer_head *bh;
2828 struct htree_lock *hlock = NULL;
2834 LINVRNT(osd_invariant(obj));
2835 LASSERT(dt_object_exists(dt));
2836 LASSERT(handle != NULL);
2838 oh = container_of(handle, struct osd_thandle, ot_super);
2839 LASSERT(oh->ot_handle != NULL);
2840 LASSERT(oh->ot_handle->h_transaction != NULL);
2842 if (osd_object_auth(env, dt, capa, CAPA_OPC_INDEX_DELETE))
2845 dentry = osd_child_dentry_get(env, obj,
2846 (char *)key, strlen((char *)key));
2848 if (obj->oo_hl_head != NULL) {
2849 hlock = osd_oti_get(env)->oti_hlock;
2850 ldiskfs_htree_lock(hlock, obj->oo_hl_head,
2851 dir, LDISKFS_HLOCK_DEL);
2853 cfs_down_write(&obj->oo_ext_idx_sem);
2856 bh = osd_ldiskfs_find_entry(dir, dentry, &de, hlock);
2858 rc = ldiskfs_delete_entry(oh->ot_handle,
2865 ldiskfs_htree_unlock(hlock);
2867 cfs_up_write(&obj->oo_ext_idx_sem);
2869 LASSERT(osd_invariant(obj));
2874 * Lookup index for \a key and copy record to \a rec.
2876 * \param dt osd index object
2877 * \param key key for index
2878 * \param rec record reference
2880 * \retval +ve success : exact mach
2881 * \retval 0 return record with key not greater than \a key
2882 * \retval -ve failure
2884 static int osd_index_iam_lookup(const struct lu_env *env, struct dt_object *dt,
2885 struct dt_rec *rec, const struct dt_key *key,
2886 struct lustre_capa *capa)
2888 struct osd_object *obj = osd_dt_obj(dt);
2889 struct iam_path_descr *ipd;
2890 struct iam_container *bag = &obj->oo_dir->od_container;
2891 struct osd_thread_info *oti = osd_oti_get(env);
2892 struct iam_iterator *it = &oti->oti_idx_it;
2893 struct iam_rec *iam_rec;
2897 LASSERT(osd_invariant(obj));
2898 LASSERT(dt_object_exists(dt));
2899 LASSERT(bag->ic_object == obj->oo_inode);
2901 if (osd_object_auth(env, dt, capa, CAPA_OPC_INDEX_LOOKUP))
2904 ipd = osd_idx_ipd_get(env, bag);
2908 /* got ipd now we can start iterator. */
2909 iam_it_init(it, bag, 0, ipd);
2911 rc = iam_it_get(it, (struct iam_key *)key);
2913 if (S_ISDIR(obj->oo_inode->i_mode))
2914 iam_rec = (struct iam_rec *)oti->oti_ldp;
2916 iam_rec = (struct iam_rec *) rec;
2918 iam_reccpy(&it->ii_path.ip_leaf, (struct iam_rec *)iam_rec);
2919 if (S_ISDIR(obj->oo_inode->i_mode))
2920 osd_fid_unpack((struct lu_fid *) rec,
2921 (struct osd_fid_pack *)iam_rec);
2925 osd_ipd_put(env, bag, ipd);
2927 LINVRNT(osd_invariant(obj));
2933 * Inserts (key, value) pair in \a dt index object.
2935 * \param dt osd index object
2936 * \param key key for index
2937 * \param rec record reference
2938 * \param th transaction handler
2941 * \retval -ve failure
2943 static int osd_index_iam_insert(const struct lu_env *env, struct dt_object *dt,
2944 const struct dt_rec *rec, const struct dt_key *key,
2945 struct thandle *th, struct lustre_capa *capa,
2948 struct osd_object *obj = osd_dt_obj(dt);
2949 struct iam_path_descr *ipd;
2950 struct osd_thandle *oh;
2951 struct iam_container *bag = &obj->oo_dir->od_container;
2952 #ifdef HAVE_QUOTA_SUPPORT
2953 cfs_cap_t save = cfs_curproc_cap_pack();
2955 struct osd_thread_info *oti = osd_oti_get(env);
2956 struct iam_rec *iam_rec = (struct iam_rec *)oti->oti_ldp;
2961 LINVRNT(osd_invariant(obj));
2962 LASSERT(dt_object_exists(dt));
2963 LASSERT(bag->ic_object == obj->oo_inode);
2964 LASSERT(th != NULL);
2966 if (osd_object_auth(env, dt, capa, CAPA_OPC_INDEX_INSERT))
2969 ipd = osd_idx_ipd_get(env, bag);
2970 if (unlikely(ipd == NULL))
2973 oh = container_of0(th, struct osd_thandle, ot_super);
2974 LASSERT(oh->ot_handle != NULL);
2975 LASSERT(oh->ot_handle->h_transaction != NULL);
2976 #ifdef HAVE_QUOTA_SUPPORT
2978 cfs_cap_raise(CFS_CAP_SYS_RESOURCE);
2980 cfs_cap_lower(CFS_CAP_SYS_RESOURCE);
2982 if (S_ISDIR(obj->oo_inode->i_mode))
2983 osd_fid_pack((struct osd_fid_pack *)iam_rec, rec, &oti->oti_fid);
2985 iam_rec = (struct iam_rec *) rec;
2986 rc = iam_insert(oh->ot_handle, bag, (const struct iam_key *)key,
2988 #ifdef HAVE_QUOTA_SUPPORT
2989 cfs_curproc_cap_unpack(save);
2991 osd_ipd_put(env, bag, ipd);
2992 LINVRNT(osd_invariant(obj));
2997 * Calls ldiskfs_add_entry() to add directory entry
2998 * into the directory. This is required for
2999 * interoperability mode (b11826)
3001 * \retval 0, on success
3002 * \retval -ve, on error
3004 static int __osd_ea_add_rec(struct osd_thread_info *info,
3005 struct osd_object *pobj,
3006 struct inode *cinode,
3008 const struct dt_rec *fid,
3009 struct htree_lock *hlock,
3012 struct ldiskfs_dentry_param *ldp;
3013 struct dentry *child;
3014 struct osd_thandle *oth;
3017 oth = container_of(th, struct osd_thandle, ot_super);
3018 LASSERT(oth->ot_handle != NULL);
3019 LASSERT(oth->ot_handle->h_transaction != NULL);
3021 child = osd_child_dentry_get(info->oti_env, pobj, name, strlen(name));
3023 if (fid_is_igif((struct lu_fid *)fid) ||
3024 fid_is_norm((struct lu_fid *)fid)) {
3025 ldp = (struct ldiskfs_dentry_param *)info->oti_ldp;
3026 osd_get_ldiskfs_dirent_param(ldp, fid);
3027 child->d_fsdata = (void*) ldp;
3029 child->d_fsdata = NULL;
3030 rc = osd_ldiskfs_add_entry(oth->ot_handle, child, cinode, hlock);
3036 * Calls ldiskfs_add_dot_dotdot() to add dot and dotdot entries
3037 * into the directory.Also sets flags into osd object to
3038 * indicate dot and dotdot are created. This is required for
3039 * interoperability mode (b11826)
3041 * \param dir directory for dot and dotdot fixup.
3042 * \param obj child object for linking
3044 * \retval 0, on success
3045 * \retval -ve, on error
3047 static int osd_add_dot_dotdot(struct osd_thread_info *info,
3048 struct osd_object *dir,
3049 struct inode *parent_dir, const char *name,
3050 const struct dt_rec *dot_fid,
3051 const struct dt_rec *dot_dot_fid,
3054 struct inode *inode = dir->oo_inode;
3055 struct ldiskfs_dentry_param *dot_ldp;
3056 struct ldiskfs_dentry_param *dot_dot_ldp;
3057 struct osd_thandle *oth;
3060 oth = container_of(th, struct osd_thandle, ot_super);
3061 LASSERT(oth->ot_handle->h_transaction != NULL);
3062 LASSERT(S_ISDIR(dir->oo_inode->i_mode));
3064 if (strcmp(name, dot) == 0) {
3065 if (dir->oo_compat_dot_created) {
3068 LASSERT(inode == parent_dir);
3069 dir->oo_compat_dot_created = 1;
3072 } else if(strcmp(name, dotdot) == 0) {
3073 dot_ldp = (struct ldiskfs_dentry_param *)info->oti_ldp;
3074 dot_dot_ldp = (struct ldiskfs_dentry_param *)info->oti_ldp2;
3076 if (!dir->oo_compat_dot_created)
3078 if (fid_seq((struct lu_fid *)dot_fid) >= FID_SEQ_NORMAL) {
3079 osd_get_ldiskfs_dirent_param(dot_ldp, dot_fid);
3080 osd_get_ldiskfs_dirent_param(dot_dot_ldp, dot_dot_fid);
3085 /* in case of rename, dotdot is already created */
3086 if (dir->oo_compat_dotdot_created) {
3087 return __osd_ea_add_rec(info, dir, parent_dir, name,
3088 dot_dot_fid, NULL, th);
3091 result = ldiskfs_add_dot_dotdot(oth->ot_handle, parent_dir,
3092 inode, dot_ldp, dot_dot_ldp);
3094 dir->oo_compat_dotdot_created = 1;
3102 * It will call the appropriate osd_add* function and return the
3103 * value, return by respective functions.
3105 static int osd_ea_add_rec(const struct lu_env *env,
3106 struct osd_object *pobj,
3107 struct inode *cinode,
3109 const struct dt_rec *fid,
3112 struct osd_thread_info *info = osd_oti_get(env);
3113 struct htree_lock *hlock;
3116 hlock = pobj->oo_hl_head != NULL ? info->oti_hlock : NULL;
3118 if (name[0] == '.' && (name[1] == '\0' || (name[1] == '.' &&
3120 if (hlock != NULL) {
3121 ldiskfs_htree_lock(hlock, pobj->oo_hl_head,
3124 cfs_down_write(&pobj->oo_ext_idx_sem);
3126 rc = osd_add_dot_dotdot(info, pobj, cinode, name,
3127 (struct dt_rec *)lu_object_fid(&pobj->oo_dt.do_lu),
3130 if (hlock != NULL) {
3131 ldiskfs_htree_lock(hlock, pobj->oo_hl_head,
3132 pobj->oo_inode, LDISKFS_HLOCK_ADD);
3134 cfs_down_write(&pobj->oo_ext_idx_sem);
3137 rc = __osd_ea_add_rec(info, pobj, cinode, name, fid,
3141 ldiskfs_htree_unlock(hlock);
3143 cfs_up_write(&pobj->oo_ext_idx_sem);
3149 * Calls ->lookup() to find dentry. From dentry get inode and
3150 * read inode's ea to get fid. This is required for interoperability
3153 * \retval 0, on success
3154 * \retval -ve, on error
3156 static int osd_ea_lookup_rec(const struct lu_env *env, struct osd_object *obj,
3157 struct dt_rec *rec, const struct dt_key *key)
3159 struct inode *dir = obj->oo_inode;
3160 struct dentry *dentry;
3161 struct ldiskfs_dir_entry_2 *de;
3162 struct buffer_head *bh;
3163 struct lu_fid *fid = (struct lu_fid *) rec;
3164 struct htree_lock *hlock = NULL;
3168 LASSERT(dir->i_op != NULL && dir->i_op->lookup != NULL);
3170 dentry = osd_child_dentry_get(env, obj,
3171 (char *)key, strlen((char *)key));
3173 if (obj->oo_hl_head != NULL) {
3174 hlock = osd_oti_get(env)->oti_hlock;
3175 ldiskfs_htree_lock(hlock, obj->oo_hl_head,
3176 dir, LDISKFS_HLOCK_LOOKUP);
3178 cfs_down_read(&obj->oo_ext_idx_sem);
3181 bh = osd_ldiskfs_find_entry(dir, dentry, &de, hlock);
3183 ino = le32_to_cpu(de->inode);
3184 rc = osd_get_fid_from_dentry(de, rec);
3186 /* done with de, release bh */
3189 rc = osd_ea_fid_get(env, obj, ino, fid);
3195 ldiskfs_htree_unlock(hlock);
3197 cfs_up_read(&obj->oo_ext_idx_sem);
3202 * Find the osd object for given fid.
3204 * \param fid need to find the osd object having this fid
3206 * \retval osd_object on success
3207 * \retval -ve on error
3209 struct osd_object *osd_object_find(const struct lu_env *env,
3210 struct dt_object *dt,
3211 const struct lu_fid *fid)
3213 struct lu_device *ludev = dt->do_lu.lo_dev;
3214 struct osd_object *child = NULL;
3215 struct lu_object *luch;
3216 struct lu_object *lo;
3218 luch = lu_object_find(env, ludev, fid, NULL);
3219 if (!IS_ERR(luch)) {
3220 if (lu_object_exists(luch)) {
3221 lo = lu_object_locate(luch->lo_header, ludev->ld_type);
3223 child = osd_obj(lo);
3225 LU_OBJECT_DEBUG(D_ERROR, env, luch,
3226 "lu_object can't be located"
3227 ""DFID"\n", PFID(fid));
3229 if (child == NULL) {
3230 lu_object_put(env, luch);
3231 CERROR("Unable to get osd_object\n");
3232 child = ERR_PTR(-ENOENT);
3235 LU_OBJECT_DEBUG(D_ERROR, env, luch,
3236 "lu_object does not exists "DFID"\n",
3238 child = ERR_PTR(-ENOENT);
3241 child = (void *)luch;
3247 * Put the osd object once done with it.
3249 * \param obj osd object that needs to be put
3251 static inline void osd_object_put(const struct lu_env *env,
3252 struct osd_object *obj)
3254 lu_object_put(env, &obj->oo_dt.do_lu);
3258 * Index add function for interoperability mode (b11826).
3259 * It will add the directory entry.This entry is needed to
3260 * maintain name->fid mapping.
3262 * \param key it is key i.e. file entry to be inserted
3263 * \param rec it is value of given key i.e. fid
3265 * \retval 0, on success
3266 * \retval -ve, on error
3268 static int osd_index_ea_insert(const struct lu_env *env, struct dt_object *dt,
3269 const struct dt_rec *rec,
3270 const struct dt_key *key, struct thandle *th,
3271 struct lustre_capa *capa, int ignore_quota)
3273 struct osd_object *obj = osd_dt_obj(dt);
3274 struct lu_fid *fid = (struct lu_fid *) rec;
3275 const char *name = (const char *)key;
3276 struct osd_object *child;
3277 #ifdef HAVE_QUOTA_SUPPORT
3278 cfs_cap_t save = cfs_curproc_cap_pack();
3284 LASSERT(osd_invariant(obj));
3285 LASSERT(dt_object_exists(dt));
3286 LASSERT(th != NULL);
3288 if (osd_object_auth(env, dt, capa, CAPA_OPC_INDEX_INSERT))
3291 child = osd_object_find(env, dt, fid);
3292 if (!IS_ERR(child)) {
3293 #ifdef HAVE_QUOTA_SUPPORT
3295 cfs_cap_raise(CFS_CAP_SYS_RESOURCE);
3297 cfs_cap_lower(CFS_CAP_SYS_RESOURCE);
3299 rc = osd_ea_add_rec(env, obj, child->oo_inode, name, rec, th);
3300 #ifdef HAVE_QUOTA_SUPPORT
3301 cfs_curproc_cap_unpack(save);
3303 osd_object_put(env, child);
3305 rc = PTR_ERR(child);
3308 LASSERT(osd_invariant(obj));
3313 * Initialize osd Iterator for given osd index object.
3315 * \param dt osd index object
3318 static struct dt_it *osd_it_iam_init(const struct lu_env *env,
3319 struct dt_object *dt,
3321 struct lustre_capa *capa)
3323 struct osd_it_iam *it;
3324 struct osd_thread_info *oti = osd_oti_get(env);
3325 struct osd_object *obj = osd_dt_obj(dt);
3326 struct lu_object *lo = &dt->do_lu;
3327 struct iam_path_descr *ipd;
3328 struct iam_container *bag = &obj->oo_dir->od_container;
3330 LASSERT(lu_object_exists(lo));
3332 if (osd_object_auth(env, dt, capa, CAPA_OPC_BODY_READ))
3333 return ERR_PTR(-EACCES);
3336 ipd = osd_it_ipd_get(env, bag);
3337 if (likely(ipd != NULL)) {
3341 iam_it_init(&it->oi_it, bag, IAM_IT_MOVE, ipd);
3342 return (struct dt_it *)it;
3344 return ERR_PTR(-ENOMEM);
3348 * free given Iterator.
3351 static void osd_it_iam_fini(const struct lu_env *env, struct dt_it *di)
3353 struct osd_it_iam *it = (struct osd_it_iam *)di;
3354 struct osd_object *obj = it->oi_obj;
3356 iam_it_fini(&it->oi_it);
3357 osd_ipd_put(env, &obj->oo_dir->od_container, it->oi_ipd);
3358 lu_object_put(env, &obj->oo_dt.do_lu);
3362 * Move Iterator to record specified by \a key
3364 * \param di osd iterator
3365 * \param key key for index
3367 * \retval +ve di points to record with least key not larger than key
3368 * \retval 0 di points to exact matched key
3369 * \retval -ve failure
3372 static int osd_it_iam_get(const struct lu_env *env,
3373 struct dt_it *di, const struct dt_key *key)
3375 struct osd_it_iam *it = (struct osd_it_iam *)di;
3377 return iam_it_get(&it->oi_it, (const struct iam_key *)key);
3383 * \param di osd iterator
3386 static void osd_it_iam_put(const struct lu_env *env, struct dt_it *di)
3388 struct osd_it_iam *it = (struct osd_it_iam *)di;
3390 iam_it_put(&it->oi_it);
3394 * Move iterator by one record
3396 * \param di osd iterator
3398 * \retval +1 end of container reached
3400 * \retval -ve failure
3403 static int osd_it_iam_next(const struct lu_env *env, struct dt_it *di)
3405 struct osd_it_iam *it = (struct osd_it_iam *)di;
3407 return iam_it_next(&it->oi_it);
3411 * Return pointer to the key under iterator.
3414 static struct dt_key *osd_it_iam_key(const struct lu_env *env,
3415 const struct dt_it *di)
3417 struct osd_it_iam *it = (struct osd_it_iam *)di;
3419 return (struct dt_key *)iam_it_key_get(&it->oi_it);
3423 * Return size of key under iterator (in bytes)
3426 static int osd_it_iam_key_size(const struct lu_env *env, const struct dt_it *di)
3428 struct osd_it_iam *it = (struct osd_it_iam *)di;
3430 return iam_it_key_size(&it->oi_it);
3433 static inline void osd_it_append_attrs(struct lu_dirent*ent,
3438 struct luda_type *lt;
3439 const unsigned align = sizeof(struct luda_type) - 1;
3441 /* check if file type is required */
3442 if (attr & LUDA_TYPE) {
3443 len = (len + align) & ~align;
3445 lt = (void *) ent->lde_name + len;
3446 lt->lt_type = cpu_to_le16(CFS_DTTOIF(type));
3447 ent->lde_attrs |= LUDA_TYPE;
3450 ent->lde_attrs = cpu_to_le32(ent->lde_attrs);
3454 * build lu direct from backend fs dirent.
3457 static inline void osd_it_pack_dirent(struct lu_dirent *ent,
3465 fid_cpu_to_le(&ent->lde_fid, fid);
3466 ent->lde_attrs = LUDA_FID;
3468 ent->lde_hash = cpu_to_le64(offset);
3469 ent->lde_reclen = cpu_to_le16(lu_dirent_calc_size(namelen, attr));
3471 strncpy(ent->lde_name, name, namelen);
3472 ent->lde_namelen = cpu_to_le16(namelen);
3474 /* append lustre attributes */
3475 osd_it_append_attrs(ent, attr, namelen, type);
3479 * Return pointer to the record under iterator.
3481 static int osd_it_iam_rec(const struct lu_env *env,
3482 const struct dt_it *di,
3483 struct lu_dirent *lde,
3486 struct osd_it_iam *it = (struct osd_it_iam *)di;
3487 struct osd_thread_info *info = osd_oti_get(env);
3488 struct lu_fid *fid = &info->oti_fid;
3489 const struct osd_fid_pack *rec;
3495 name = (char *)iam_it_key_get(&it->oi_it);
3497 RETURN(PTR_ERR(name));
3499 namelen = iam_it_key_size(&it->oi_it);
3501 rec = (const struct osd_fid_pack *) iam_it_rec_get(&it->oi_it);
3503 RETURN(PTR_ERR(rec));
3505 rc = osd_fid_unpack(fid, rec);
3509 hash = iam_it_store(&it->oi_it);
3511 /* IAM does not store object type in IAM index (dir) */
3512 osd_it_pack_dirent(lde, fid, hash, name, namelen,
3519 * Returns cookie for current Iterator position.
3521 static __u64 osd_it_iam_store(const struct lu_env *env, const struct dt_it *di)
3523 struct osd_it_iam *it = (struct osd_it_iam *)di;
3525 return iam_it_store(&it->oi_it);
3529 * Restore iterator from cookie.
3531 * \param di osd iterator
3532 * \param hash Iterator location cookie
3534 * \retval +ve di points to record with least key not larger than key.
3535 * \retval 0 di points to exact matched key
3536 * \retval -ve failure
3539 static int osd_it_iam_load(const struct lu_env *env,
3540 const struct dt_it *di, __u64 hash)
3542 struct osd_it_iam *it = (struct osd_it_iam *)di;
3544 return iam_it_load(&it->oi_it, hash);
3547 static const struct dt_index_operations osd_index_iam_ops = {
3548 .dio_lookup = osd_index_iam_lookup,
3549 .dio_insert = osd_index_iam_insert,
3550 .dio_delete = osd_index_iam_delete,
3552 .init = osd_it_iam_init,
3553 .fini = osd_it_iam_fini,
3554 .get = osd_it_iam_get,
3555 .put = osd_it_iam_put,
3556 .next = osd_it_iam_next,
3557 .key = osd_it_iam_key,
3558 .key_size = osd_it_iam_key_size,
3559 .rec = osd_it_iam_rec,
3560 .store = osd_it_iam_store,
3561 .load = osd_it_iam_load
3566 * Creates or initializes iterator context.
3568 * \retval struct osd_it_ea, iterator structure on success
3571 static struct dt_it *osd_it_ea_init(const struct lu_env *env,
3572 struct dt_object *dt,
3574 struct lustre_capa *capa)
3576 struct osd_object *obj = osd_dt_obj(dt);
3577 struct osd_thread_info *info = osd_oti_get(env);
3578 struct osd_it_ea *it = &info->oti_it_ea;
3579 struct lu_object *lo = &dt->do_lu;
3580 struct dentry *obj_dentry = &info->oti_it_dentry;
3582 LASSERT(lu_object_exists(lo));
3584 obj_dentry->d_inode = obj->oo_inode;
3585 obj_dentry->d_sb = osd_sb(osd_obj2dev(obj));
3586 obj_dentry->d_name.hash = 0;
3588 it->oie_rd_dirent = 0;
3589 it->oie_it_dirent = 0;
3590 it->oie_dirent = NULL;
3591 it->oie_buf = info->oti_it_ea_buf;
3593 it->oie_file.f_pos = 0;
3594 it->oie_file.f_dentry = obj_dentry;
3595 if (attr & LUDA_64BITHASH)
3596 it->oie_file.f_flags = O_64BITHASH;
3598 it->oie_file.f_flags = O_32BITHASH;
3599 it->oie_file.f_mapping = obj->oo_inode->i_mapping;
3600 it->oie_file.f_op = obj->oo_inode->i_fop;
3601 it->oie_file.private_data = NULL;
3603 RETURN((struct dt_it *) it);
3607 * Destroy or finishes iterator context.
3609 * \param di iterator structure to be destroyed
3611 static void osd_it_ea_fini(const struct lu_env *env, struct dt_it *di)
3613 struct osd_it_ea *it = (struct osd_it_ea *)di;
3614 struct osd_object *obj = it->oie_obj;
3615 struct inode *inode = obj->oo_inode;
3618 it->oie_file.f_op->release(inode, &it->oie_file);
3619 lu_object_put(env, &obj->oo_dt.do_lu);
3624 * It position the iterator at given key, so that next lookup continues from
3625 * that key Or it is similar to dio_it->load() but based on a key,
3626 * rather than file position.
3628 * As a special convention, osd_it_ea_get(env, di, "") has to rewind iterator
3631 * TODO: Presently return +1 considering it is only used by mdd_dir_is_empty().
3633 static int osd_it_ea_get(const struct lu_env *env,
3634 struct dt_it *di, const struct dt_key *key)
3636 struct osd_it_ea *it = (struct osd_it_ea *)di;
3639 LASSERT(((const char *)key)[0] == '\0');
3640 it->oie_file.f_pos = 0;
3641 it->oie_rd_dirent = 0;
3642 it->oie_it_dirent = 0;
3643 it->oie_dirent = NULL;
3651 static void osd_it_ea_put(const struct lu_env *env, struct dt_it *di)
3656 * It is called internally by ->readdir(). It fills the
3657 * iterator's in-memory data structure with required
3658 * information i.e. name, namelen, rec_size etc.
3660 * \param buf in which information to be filled in.
3661 * \param name name of the file in given dir
3663 * \retval 0 on success
3664 * \retval 1 on buffer full
3666 static int osd_ldiskfs_filldir(char *buf, const char *name, int namelen,
3667 loff_t offset, __u64 ino,
3670 struct osd_it_ea *it = (struct osd_it_ea *)buf;
3671 struct osd_it_ea_dirent *ent = it->oie_dirent;
3672 struct lu_fid *fid = &ent->oied_fid;
3673 struct osd_fid_pack *rec;
3676 /* this should never happen */
3677 if (unlikely(namelen == 0 || namelen > LDISKFS_NAME_LEN)) {
3678 CERROR("ldiskfs return invalid namelen %d\n", namelen);
3682 if ((void *) ent - it->oie_buf + sizeof(*ent) + namelen >
3686 if (d_type & LDISKFS_DIRENT_LUFID) {
3687 rec = (struct osd_fid_pack*) (name + namelen + 1);
3689 if (osd_fid_unpack(fid, rec) != 0)
3692 d_type &= ~LDISKFS_DIRENT_LUFID;
3697 ent->oied_ino = ino;
3698 ent->oied_off = offset;
3699 ent->oied_namelen = namelen;
3700 ent->oied_type = d_type;
3702 memcpy(ent->oied_name, name, namelen);
3704 it->oie_rd_dirent++;
3705 it->oie_dirent = (void *) ent + cfs_size_round(sizeof(*ent) + namelen);
3710 * Calls ->readdir() to load a directory entry at a time
3711 * and stored it in iterator's in-memory data structure.
3713 * \param di iterator's in memory structure
3715 * \retval 0 on success
3716 * \retval -ve on error
3718 static int osd_ldiskfs_it_fill(const struct lu_env *env,
3719 const struct dt_it *di)
3721 struct osd_it_ea *it = (struct osd_it_ea *)di;
3722 struct osd_object *obj = it->oie_obj;
3723 struct inode *inode = obj->oo_inode;
3724 struct htree_lock *hlock = NULL;
3728 it->oie_dirent = it->oie_buf;
3729 it->oie_rd_dirent = 0;
3731 if (obj->oo_hl_head != NULL) {
3732 hlock = osd_oti_get(env)->oti_hlock;
3733 ldiskfs_htree_lock(hlock, obj->oo_hl_head,
3734 inode, LDISKFS_HLOCK_READDIR);
3736 cfs_down_read(&obj->oo_ext_idx_sem);
3739 result = inode->i_fop->readdir(&it->oie_file, it,
3740 (filldir_t) osd_ldiskfs_filldir);
3743 ldiskfs_htree_unlock(hlock);
3745 cfs_up_read(&obj->oo_ext_idx_sem);
3747 if (it->oie_rd_dirent == 0) {
3750 it->oie_dirent = it->oie_buf;
3751 it->oie_it_dirent = 1;
3758 * It calls osd_ldiskfs_it_fill() which will use ->readdir()
3759 * to load a directory entry at a time and stored it in
3760 * iterator's in-memory data structure.
3762 * \param di iterator's in memory structure
3764 * \retval +ve iterator reached to end
3765 * \retval 0 iterator not reached to end
3766 * \retval -ve on error
3768 static int osd_it_ea_next(const struct lu_env *env, struct dt_it *di)
3770 struct osd_it_ea *it = (struct osd_it_ea *)di;
3775 if (it->oie_it_dirent < it->oie_rd_dirent) {
3777 (void *) it->oie_dirent +
3778 cfs_size_round(sizeof(struct osd_it_ea_dirent) +
3779 it->oie_dirent->oied_namelen);
3780 it->oie_it_dirent++;
3783 if (it->oie_file.f_pos == LDISKFS_HTREE_EOF)
3786 rc = osd_ldiskfs_it_fill(env, di);
3793 * Returns the key at current position from iterator's in memory structure.
3795 * \param di iterator's in memory structure
3797 * \retval key i.e. struct dt_key on success
3799 static struct dt_key *osd_it_ea_key(const struct lu_env *env,
3800 const struct dt_it *di)
3802 struct osd_it_ea *it = (struct osd_it_ea *)di;
3804 RETURN((struct dt_key *)it->oie_dirent->oied_name);
3808 * Returns the key's size at current position from iterator's in memory structure.
3810 * \param di iterator's in memory structure
3812 * \retval key_size i.e. struct dt_key on success
3814 static int osd_it_ea_key_size(const struct lu_env *env, const struct dt_it *di)
3816 struct osd_it_ea *it = (struct osd_it_ea *)di;
3818 RETURN(it->oie_dirent->oied_namelen);
3823 * Returns the value (i.e. fid/igif) at current position from iterator's
3824 * in memory structure.
3826 * \param di struct osd_it_ea, iterator's in memory structure
3827 * \param attr attr requested for dirent.
3828 * \param lde lustre dirent
3830 * \retval 0 no error and \param lde has correct lustre dirent.
3831 * \retval -ve on error
3833 static inline int osd_it_ea_rec(const struct lu_env *env,
3834 const struct dt_it *di,
3835 struct lu_dirent *lde,
3838 struct osd_it_ea *it = (struct osd_it_ea *)di;
3839 struct osd_object *obj = it->oie_obj;
3840 struct lu_fid *fid = &it->oie_dirent->oied_fid;
3845 if (!fid_is_sane(fid))
3846 rc = osd_ea_fid_get(env, obj, it->oie_dirent->oied_ino, fid);
3849 osd_it_pack_dirent(lde, fid, it->oie_dirent->oied_off,
3850 it->oie_dirent->oied_name,
3851 it->oie_dirent->oied_namelen,
3852 it->oie_dirent->oied_type,
3858 * Returns a cookie for current position of the iterator head, so that
3859 * user can use this cookie to load/start the iterator next time.
3861 * \param di iterator's in memory structure
3863 * \retval cookie for current position, on success
3865 static __u64 osd_it_ea_store(const struct lu_env *env, const struct dt_it *di)
3867 struct osd_it_ea *it = (struct osd_it_ea *)di;
3869 RETURN(it->oie_dirent->oied_off);
3873 * It calls osd_ldiskfs_it_fill() which will use ->readdir()
3874 * to load a directory entry at a time and stored it i inn,
3875 * in iterator's in-memory data structure.
3877 * \param di struct osd_it_ea, iterator's in memory structure
3879 * \retval +ve on success
3880 * \retval -ve on error
3882 static int osd_it_ea_load(const struct lu_env *env,
3883 const struct dt_it *di, __u64 hash)
3885 struct osd_it_ea *it = (struct osd_it_ea *)di;
3889 it->oie_file.f_pos = hash;
3891 rc = osd_ldiskfs_it_fill(env, di);
3899 * Index lookup function for interoperability mode (b11826).
3901 * \param key, key i.e. file name to be searched
3903 * \retval +ve, on success
3904 * \retval -ve, on error
3906 static int osd_index_ea_lookup(const struct lu_env *env, struct dt_object *dt,
3907 struct dt_rec *rec, const struct dt_key *key,
3908 struct lustre_capa *capa)
3910 struct osd_object *obj = osd_dt_obj(dt);
3915 LASSERT(S_ISDIR(obj->oo_inode->i_mode));
3916 LINVRNT(osd_invariant(obj));
3918 if (osd_object_auth(env, dt, capa, CAPA_OPC_INDEX_LOOKUP))
3921 rc = osd_ea_lookup_rec(env, obj, rec, key);
3929 * Index and Iterator operations for interoperability
3930 * mode (i.e. to run 2.0 mds on 1.8 disk) (b11826)
3932 static const struct dt_index_operations osd_index_ea_ops = {
3933 .dio_lookup = osd_index_ea_lookup,
3934 .dio_insert = osd_index_ea_insert,
3935 .dio_delete = osd_index_ea_delete,
3937 .init = osd_it_ea_init,
3938 .fini = osd_it_ea_fini,
3939 .get = osd_it_ea_get,
3940 .put = osd_it_ea_put,
3941 .next = osd_it_ea_next,
3942 .key = osd_it_ea_key,
3943 .key_size = osd_it_ea_key_size,
3944 .rec = osd_it_ea_rec,
3945 .store = osd_it_ea_store,
3946 .load = osd_it_ea_load
3950 static void *osd_key_init(const struct lu_context *ctx,
3951 struct lu_context_key *key)
3953 struct osd_thread_info *info;
3955 OBD_ALLOC_PTR(info);
3957 return ERR_PTR(-ENOMEM);
3959 OBD_ALLOC(info->oti_it_ea_buf, OSD_IT_EA_BUFSIZE);
3960 if (info->oti_it_ea_buf == NULL)
3963 info->oti_env = container_of(ctx, struct lu_env, le_ctx);
3965 info->oti_hlock = ldiskfs_htree_lock_alloc();
3966 if (info->oti_hlock == NULL)
3972 OBD_FREE(info->oti_it_ea_buf, OSD_IT_EA_BUFSIZE);
3975 return ERR_PTR(-ENOMEM);
3978 static void osd_key_fini(const struct lu_context *ctx,
3979 struct lu_context_key *key, void* data)
3981 struct osd_thread_info *info = data;
3983 if (info->oti_hlock != NULL)
3984 ldiskfs_htree_lock_free(info->oti_hlock);
3985 OBD_FREE(info->oti_it_ea_buf, OSD_IT_EA_BUFSIZE);
3989 static void osd_key_exit(const struct lu_context *ctx,
3990 struct lu_context_key *key, void *data)
3992 struct osd_thread_info *info = data;
3994 LASSERT(info->oti_r_locks == 0);
3995 LASSERT(info->oti_w_locks == 0);
3996 LASSERT(info->oti_txns == 0);
3999 /* type constructor/destructor: osd_type_init, osd_type_fini */
4000 LU_TYPE_INIT_FINI(osd, &osd_key);
4002 static struct lu_context_key osd_key = {
4003 .lct_tags = LCT_DT_THREAD | LCT_MD_THREAD,
4004 .lct_init = osd_key_init,
4005 .lct_fini = osd_key_fini,
4006 .lct_exit = osd_key_exit
4010 static int osd_device_init(const struct lu_env *env, struct lu_device *d,
4011 const char *name, struct lu_device *next)
4013 return osd_procfs_init(osd_dev(d), name);
4016 static int osd_shutdown(const struct lu_env *env, struct osd_device *o)
4018 struct osd_thread_info *info = osd_oti_get(env);
4020 if (o->od_obj_area != NULL) {
4021 lu_object_put(env, &o->od_obj_area->do_lu);
4022 o->od_obj_area = NULL;
4024 osd_oi_fini(info, &o->od_oi);
4029 static int osd_mount(const struct lu_env *env,
4030 struct osd_device *o, struct lustre_cfg *cfg)
4032 struct lustre_mount_info *lmi;
4033 const char *dev = lustre_cfg_string(cfg, 0);
4034 struct lustre_disk_data *ldd;
4035 struct lustre_sb_info *lsi;
4038 if (o->od_mount != NULL) {
4039 CERROR("Already mounted (%s)\n", dev);
4044 lmi = server_get_mount(dev);
4046 CERROR("Cannot get mount info for %s!\n", dev);
4050 LASSERT(lmi != NULL);
4051 /* save lustre_mount_info in dt_device */
4054 lsi = s2lsi(lmi->lmi_sb);
4057 if (ldd->ldd_flags & LDD_F_IAM_DIR) {
4059 LCONSOLE_WARN("OSD: IAM mode enabled\n");
4063 o->od_obj_area = NULL;
4067 static struct lu_device *osd_device_fini(const struct lu_env *env,
4068 struct lu_device *d)
4073 shrink_dcache_sb(osd_sb(osd_dev(d)));
4074 osd_sync(env, lu2dt_dev(d));
4076 rc = osd_procfs_fini(osd_dev(d));
4078 CERROR("proc fini error %d \n", rc);
4079 RETURN (ERR_PTR(rc));
4082 if (osd_dev(d)->od_mount)
4083 server_put_mount(osd_dev(d)->od_mount->lmi_name,
4084 osd_dev(d)->od_mount->lmi_mnt);
4085 osd_dev(d)->od_mount = NULL;
4090 static struct lu_device *osd_device_alloc(const struct lu_env *env,
4091 struct lu_device_type *t,
4092 struct lustre_cfg *cfg)
4094 struct lu_device *l;
4095 struct osd_device *o;
4101 result = dt_device_init(&o->od_dt_dev, t);
4104 l->ld_ops = &osd_lu_ops;
4105 o->od_dt_dev.dd_ops = &osd_dt_ops;
4106 cfs_spin_lock_init(&o->od_osfs_lock);
4107 o->od_osfs_age = cfs_time_shift_64(-1000);
4108 o->od_capa_hash = init_capa_hash();
4109 if (o->od_capa_hash == NULL) {
4110 dt_device_fini(&o->od_dt_dev);
4111 l = ERR_PTR(-ENOMEM);
4114 l = ERR_PTR(result);
4119 l = ERR_PTR(-ENOMEM);
4123 static struct lu_device *osd_device_free(const struct lu_env *env,
4124 struct lu_device *d)
4126 struct osd_device *o = osd_dev(d);
4129 cleanup_capa_hash(o->od_capa_hash);
4130 dt_device_fini(&o->od_dt_dev);
4135 static int osd_process_config(const struct lu_env *env,
4136 struct lu_device *d, struct lustre_cfg *cfg)
4138 struct osd_device *o = osd_dev(d);
4142 switch(cfg->lcfg_command) {
4144 err = osd_mount(env, o, cfg);
4147 err = osd_shutdown(env, o);
4156 static int osd_recovery_complete(const struct lu_env *env,
4157 struct lu_device *d)
4162 static int osd_prepare(const struct lu_env *env,
4163 struct lu_device *pdev,
4164 struct lu_device *dev)
4166 struct osd_device *osd = osd_dev(dev);
4167 struct lustre_sb_info *lsi;
4168 struct lustre_disk_data *ldd;
4169 struct lustre_mount_info *lmi;
4170 struct osd_thread_info *oti = osd_oti_get(env);
4171 struct dt_object *d;
4175 /* 1. initialize oi before any file create or file open */
4176 result = osd_oi_init(oti, &osd->od_oi,
4177 &osd->od_dt_dev, lu2md_dev(pdev));
4181 lmi = osd->od_mount;
4182 lsi = s2lsi(lmi->lmi_sb);
4185 /* 2. setup local objects */
4186 result = llo_local_objects_setup(env, lu2md_dev(pdev), lu2dt_dev(dev));
4190 /* 3. open remote object dir */
4191 d = dt_store_open(env, lu2dt_dev(dev), "",
4192 remote_obj_dir, &oti->oti_fid);
4194 osd->od_obj_area = d;
4197 result = PTR_ERR(d);
4198 osd->od_obj_area = NULL;
4205 static const struct lu_object_operations osd_lu_obj_ops = {
4206 .loo_object_init = osd_object_init,
4207 .loo_object_delete = osd_object_delete,
4208 .loo_object_release = osd_object_release,
4209 .loo_object_free = osd_object_free,
4210 .loo_object_print = osd_object_print,
4211 .loo_object_invariant = osd_object_invariant
4214 static const struct lu_device_operations osd_lu_ops = {
4215 .ldo_object_alloc = osd_object_alloc,
4216 .ldo_process_config = osd_process_config,
4217 .ldo_recovery_complete = osd_recovery_complete,
4218 .ldo_prepare = osd_prepare,
4221 static const struct lu_device_type_operations osd_device_type_ops = {
4222 .ldto_init = osd_type_init,
4223 .ldto_fini = osd_type_fini,
4225 .ldto_start = osd_type_start,
4226 .ldto_stop = osd_type_stop,
4228 .ldto_device_alloc = osd_device_alloc,
4229 .ldto_device_free = osd_device_free,
4231 .ldto_device_init = osd_device_init,
4232 .ldto_device_fini = osd_device_fini
4235 static struct lu_device_type osd_device_type = {
4236 .ldt_tags = LU_DEVICE_DT,
4237 .ldt_name = LUSTRE_OSD_NAME,
4238 .ldt_ops = &osd_device_type_ops,
4239 .ldt_ctx_tags = LCT_MD_THREAD|LCT_DT_THREAD
4243 * lprocfs legacy support.
4245 static struct obd_ops osd_obd_device_ops = {
4246 .o_owner = THIS_MODULE
4249 static struct lu_local_obj_desc llod_osd_rem_obj_dir = {
4250 .llod_name = remote_obj_dir,
4251 .llod_oid = OSD_REM_OBJ_DIR_OID,
4253 .llod_feat = &dt_directory_features,
4256 static int __init osd_mod_init(void)
4258 struct lprocfs_static_vars lvars;
4261 llo_local_obj_register(&llod_osd_rem_obj_dir);
4262 lprocfs_osd_init_vars(&lvars);
4263 return class_register_type(&osd_obd_device_ops, NULL, lvars.module_vars,
4264 LUSTRE_OSD_NAME, &osd_device_type);
4267 static void __exit osd_mod_exit(void)
4269 llo_local_obj_unregister(&llod_osd_rem_obj_dir);
4270 class_unregister_type(LUSTRE_OSD_NAME);
4273 MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");
4274 MODULE_DESCRIPTION("Lustre Object Storage Device ("LUSTRE_OSD_NAME")");
4275 MODULE_LICENSE("GPL");
4277 cfs_module(osd, "0.0.2", osd_mod_init, osd_mod_exit);