1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * lustre/osd/osd_handler.c
5 * Top-level entry points into osd module
7 * Copyright (c) 2006 Cluster File Systems, Inc.
8 * Author: Nikita Danilov <nikita@clusterfs.com>
10 * This file is part of the Lustre file system, http://www.lustre.org
11 * Lustre is a trademark of Cluster File Systems, Inc.
13 * You may have signed or agreed to another license before downloading
14 * this software. If so, you are bound by the terms and conditions
15 * of that agreement, and the following does not apply to you. See the
16 * LICENSE file included with this distribution for more information.
18 * If you did not agree to a different license, then this copy of Lustre
19 * is open source software; you can redistribute it and/or modify it
20 * under the terms of version 2 of the GNU General Public License as
21 * published by the Free Software Foundation.
23 * In either case, Lustre is distributed in the hope that it will be
24 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
25 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * license text for more details.
30 # define EXPORT_SYMTAB
32 #define DEBUG_SUBSYSTEM S_MDS
34 #include <linux/module.h>
36 /* LUSTRE_VERSION_CODE */
37 #include <lustre_ver.h>
38 /* prerequisite for linux/xattr.h */
39 #include <linux/types.h>
40 /* prerequisite for linux/xattr.h */
42 /* XATTR_{REPLACE,CREATE} */
43 #include <linux/xattr.h>
45 * XXX temporary stuff: direct access to ldiskfs/jdb. Interface between osd
46 * and file system is not yet specified.
48 /* handle_t, journal_start(), journal_stop() */
49 #include <linux/jbd.h>
51 #include <linux/ldiskfs_fs.h>
52 #include <linux/ldiskfs_jbd.h>
57 * struct OBD_{ALLOC,FREE}*()
60 #include <obd_support.h>
61 /* struct ptlrpc_thread */
62 #include <lustre_net.h>
65 /* class_register_type(), class_unregister_type(), class_get_type() */
66 #include <obd_class.h>
67 #include <lustre_disk.h>
70 #include <lustre_fid.h>
71 #include <linux/lustre_iam.h>
73 #include "osd_internal.h"
76 struct osd_directory {
77 struct iam_container od_container;
78 struct iam_descr od_descr;
79 struct semaphore od_sem;
83 struct dt_object oo_dt;
85 * Inode for file system object represented by this osd_object. This
86 * inode is pinned for the whole duration of lu_object life.
88 * Not modified concurrently (either setup early during object
89 * creation, or assigned by osd_object_create() under write lock).
91 struct inode *oo_inode;
92 struct rw_semaphore oo_sem;
93 struct osd_directory *oo_dir;
94 /* protects inode attributes. */
97 const struct lu_env *oo_owner;
106 struct dt_device od_dt_dev;
107 /* information about underlying file system */
108 struct lustre_mount_info *od_mount;
112 * XXX temporary stuff for object index: directory where every object
113 * is named by its fid.
115 struct dentry *od_obj_area;
117 /* Environment for transaction commit callback.
118 * Currently, OSD is based on ext3/JBD. Transaction commit in ext3/JBD
119 * is serialized, that is there is no more than one transaction commit
120 * at a time (JBD journal_commit_transaction() is serialized).
121 * This means that it's enough to have _one_ lu_context.
123 struct lu_env od_env_for_commit;
128 unsigned int od_fl_capa:1;
129 unsigned long od_capa_timeout;
131 struct lustre_capa_key *od_capa_keys;
132 struct hlist_head *od_capa_hash;
135 * statfs optimization: we cache a bit.
137 cfs_time_t od_osfs_age;
138 struct kstatfs od_kstatfs;
139 spinlock_t od_osfs_lock;
142 static int osd_root_get (const struct lu_env *env,
143 struct dt_device *dev, struct lu_fid *f);
144 static int osd_statfs (const struct lu_env *env,
145 struct dt_device *dev, struct kstatfs *sfs);
147 static int lu_device_is_osd (const struct lu_device *d);
148 static void osd_mod_exit (void) __exit;
149 static int osd_mod_init (void) __init;
150 static int osd_type_init (struct lu_device_type *t);
151 static void osd_type_fini (struct lu_device_type *t);
152 static int osd_object_init (const struct lu_env *env,
153 struct lu_object *l);
154 static void osd_object_release(const struct lu_env *env,
155 struct lu_object *l);
156 static int osd_object_print (const struct lu_env *env, void *cookie,
157 lu_printer_t p, const struct lu_object *o);
158 static void osd_device_free (const struct lu_env *env,
159 struct lu_device *m);
160 static void *osd_key_init (const struct lu_context *ctx,
161 struct lu_context_key *key);
162 static void osd_key_fini (const struct lu_context *ctx,
163 struct lu_context_key *key, void *data);
164 static void osd_key_exit (const struct lu_context *ctx,
165 struct lu_context_key *key, void *data);
166 static int osd_has_index (const struct osd_object *obj);
167 static void osd_object_init0 (struct osd_object *obj);
168 static int osd_device_init (const struct lu_env *env,
169 struct lu_device *d, const char *,
171 static int osd_fid_lookup (const struct lu_env *env,
172 struct osd_object *obj,
173 const struct lu_fid *fid);
174 static void osd_inode_getattr (const struct lu_env *env,
175 struct inode *inode, struct lu_attr *attr);
176 static void osd_inode_setattr (const struct lu_env *env,
177 struct inode *inode, const struct lu_attr *attr);
178 static int osd_param_is_sane (const struct osd_device *dev,
179 const struct txn_param *param);
180 static int osd_index_lookup (const struct lu_env *env,
181 struct dt_object *dt,
182 struct dt_rec *rec, const struct dt_key *key,
183 struct lustre_capa *capa);
184 static int osd_index_insert (const struct lu_env *env,
185 struct dt_object *dt,
186 const struct dt_rec *rec,
187 const struct dt_key *key,
188 struct thandle *handle,
189 struct lustre_capa *capa);
190 static int osd_index_delete (const struct lu_env *env,
191 struct dt_object *dt, const struct dt_key *key,
192 struct thandle *handle,
193 struct lustre_capa *capa);
194 static int osd_index_probe (const struct lu_env *env,
195 struct osd_object *o,
196 const struct dt_index_features *feat);
197 static int osd_index_try (const struct lu_env *env,
198 struct dt_object *dt,
199 const struct dt_index_features *feat);
200 static void osd_index_fini (struct osd_object *o);
202 static void osd_it_fini (const struct lu_env *env, struct dt_it *di);
203 static int osd_it_get (const struct lu_env *env,
204 struct dt_it *di, const struct dt_key *key);
205 static void osd_it_put (const struct lu_env *env, struct dt_it *di);
206 static int osd_it_next (const struct lu_env *env, struct dt_it *di);
207 static int osd_it_del (const struct lu_env *env, struct dt_it *di,
209 static int osd_it_key_size (const struct lu_env *env,
210 const struct dt_it *di);
211 static void osd_conf_get (const struct lu_env *env,
212 const struct dt_device *dev,
213 struct dt_device_param *param);
214 static void osd_trans_stop (const struct lu_env *env,
216 static int osd_object_is_root(const struct osd_object *obj);
218 static struct osd_object *osd_obj (const struct lu_object *o);
219 static struct osd_device *osd_dev (const struct lu_device *d);
220 static struct osd_device *osd_dt_dev (const struct dt_device *d);
221 static struct osd_object *osd_dt_obj (const struct dt_object *d);
222 static struct osd_device *osd_obj2dev (const struct osd_object *o);
223 static struct lu_device *osd2lu_dev (struct osd_device *osd);
224 static struct lu_device *osd_device_fini (const struct lu_env *env,
225 struct lu_device *d);
226 static struct lu_device *osd_device_alloc (const struct lu_env *env,
227 struct lu_device_type *t,
228 struct lustre_cfg *cfg);
229 static struct lu_object *osd_object_alloc (const struct lu_env *env,
230 const struct lu_object_header *hdr,
231 struct lu_device *d);
232 static struct inode *osd_iget (struct osd_thread_info *info,
233 struct osd_device *dev,
234 const struct osd_inode_id *id);
235 static struct super_block *osd_sb (const struct osd_device *dev);
236 static struct dt_it *osd_it_init (const struct lu_env *env,
237 struct dt_object *dt, int wable,
238 struct lustre_capa *capa);
239 static struct dt_key *osd_it_key (const struct lu_env *env,
240 const struct dt_it *di);
241 static struct dt_rec *osd_it_rec (const struct lu_env *env,
242 const struct dt_it *di);
243 static struct timespec *osd_inode_time (const struct lu_env *env,
246 static struct thandle *osd_trans_start (const struct lu_env *env,
248 struct txn_param *p);
249 static journal_t *osd_journal (const struct osd_device *dev);
251 static struct lu_device_type_operations osd_device_type_ops;
252 static struct lu_device_type osd_device_type;
253 static struct lu_object_operations osd_lu_obj_ops;
254 static struct obd_ops osd_obd_device_ops;
255 static struct lprocfs_vars lprocfs_osd_module_vars[];
256 static struct lprocfs_vars lprocfs_osd_obd_vars[];
257 static struct lu_device_operations osd_lu_ops;
258 static struct lu_context_key osd_key;
259 static struct dt_object_operations osd_obj_ops;
260 static struct dt_body_operations osd_body_ops;
261 static struct dt_index_operations osd_index_ops;
262 static struct dt_index_operations osd_index_compat_ops;
265 struct thandle ot_super;
267 struct journal_callback ot_jcb;
271 * Invariants, assertions.
275 * XXX: do not enable this, until invariant checking code is made thread safe
276 * in the face of pdirops locking.
278 #define OSD_INVARIANT_CHECKS (0)
280 #if OSD_INVARIANT_CHECKS
281 static int osd_invariant(const struct osd_object *obj)
285 ergo(obj->oo_inode != NULL,
286 obj->oo_inode->i_sb == osd_sb(osd_obj2dev(obj)) &&
287 atomic_read(&obj->oo_inode->i_count) > 0) &&
288 ergo(obj->oo_dir != NULL &&
289 obj->oo_dir->od_conationer.ic_object != NULL,
290 obj->oo_dir->od_conationer.ic_object == obj->oo_inode);
293 #define osd_invariant(obj) (1)
296 static inline struct osd_thread_info *osd_oti_get(const struct lu_env *env)
298 return lu_context_key_get(&env->le_ctx, &osd_key);
303 * Concurrency: doesn't matter
305 static int osd_read_locked(const struct lu_env *env, struct osd_object *o)
307 return osd_oti_get(env)->oti_r_locks > 0;
311 * Concurrency: doesn't matter
313 static int osd_write_locked(const struct lu_env *env, struct osd_object *o)
315 struct osd_thread_info *oti = osd_oti_get(env);
316 return oti->oti_w_locks > 0 && o->oo_owner == env;
319 #define OSD_COUNTERS_DO(exp) exp
323 #define osd_read_locked(env, o) (1)
324 #define osd_write_locked(env, o) (1)
325 #define OSD_COUNTERS_DO(exp) ((void)0)
329 * Concurrency: doesn't access mutable data
331 static int osd_root_get(const struct lu_env *env,
332 struct dt_device *dev, struct lu_fid *f)
336 inode = osd_sb(osd_dt_dev(dev))->s_root->d_inode;
337 lu_igif_build(f, inode->i_ino, inode->i_generation);
342 * OSD object methods.
346 * Concurrency: no concurrent access is possible that early in object
349 static struct lu_object *osd_object_alloc(const struct lu_env *env,
350 const struct lu_object_header *hdr,
353 struct osd_object *mo;
359 l = &mo->oo_dt.do_lu;
360 dt_object_init(&mo->oo_dt, NULL, d);
361 mo->oo_dt.do_ops = &osd_obj_ops;
362 l->lo_ops = &osd_lu_obj_ops;
363 init_rwsem(&mo->oo_sem);
364 spin_lock_init(&mo->oo_guard);
371 * Concurrency: shouldn't matter.
373 static void osd_object_init0(struct osd_object *obj)
375 LASSERT(obj->oo_inode != NULL);
376 obj->oo_dt.do_body_ops = &osd_body_ops;
377 obj->oo_dt.do_lu.lo_header->loh_attr |=
378 (LOHA_EXISTS | (obj->oo_inode->i_mode & S_IFMT));
382 * Concurrency: no concurrent access is possible that early in object
385 static int osd_object_init(const struct lu_env *env, struct lu_object *l)
387 struct osd_object *obj = osd_obj(l);
390 LASSERT(osd_invariant(obj));
392 result = osd_fid_lookup(env, obj, lu_object_fid(l));
394 if (obj->oo_inode != NULL)
395 osd_object_init0(obj);
397 LASSERT(osd_invariant(obj));
402 * Concurrency: no concurrent access is possible that late in object
405 static void osd_object_free(const struct lu_env *env, struct lu_object *l)
407 struct osd_object *obj = osd_obj(l);
409 LASSERT(osd_invariant(obj));
411 dt_object_fini(&obj->oo_dt);
415 static struct iam_path_descr *osd_ipd_get(const struct lu_env *env,
416 const struct iam_container *bag)
418 return bag->ic_descr->id_ops->id_ipd_alloc(bag,
419 osd_oti_get(env)->oti_ipd);
422 static void osd_ipd_put(const struct lu_env *env,
423 const struct iam_container *bag,
424 struct iam_path_descr *ipd)
426 bag->ic_descr->id_ops->id_ipd_free(ipd);
430 * Concurrency: no concurrent access is possible that late in object
433 static void osd_index_fini(struct osd_object *o)
435 struct iam_container *bag;
437 if (o->oo_dir != NULL) {
438 bag = &o->oo_dir->od_container;
439 if (o->oo_inode != NULL) {
440 if (bag->ic_object == o->oo_inode)
441 iam_container_fini(bag);
443 OBD_FREE_PTR(o->oo_dir);
449 * Concurrency: no concurrent access is possible that late in object
450 * life-cycle (for all existing callers, that is. New callers have to provide
451 * their own locking.)
453 static int osd_inode_unlinked(const struct inode *inode)
455 return inode->i_nlink == 0;
459 OSD_TXN_OI_DELETE_CREDITS = 20,
460 OSD_TXN_INODE_DELETE_CREDITS = 20
464 * Concurrency: no concurrent access is possible that late in object
467 static int osd_inode_remove(const struct lu_env *env, struct osd_object *obj)
469 const struct lu_fid *fid = lu_object_fid(&obj->oo_dt.do_lu);
470 struct osd_device *osd = osd_obj2dev(obj);
471 struct osd_thread_info *oti = osd_oti_get(env);
472 struct txn_param *prm = &oti->oti_txn;
476 txn_param_init(prm, OSD_TXN_OI_DELETE_CREDITS +
477 OSD_TXN_INODE_DELETE_CREDITS);
478 th = osd_trans_start(env, &osd->od_dt_dev, prm);
480 result = osd_oi_delete(oti, &osd->od_oi, fid, th);
481 osd_trans_stop(env, th);
483 result = PTR_ERR(th);
488 * Called just before object is freed. Releases all resources except for
489 * object itself (that is released by osd_object_free()).
491 * Concurrency: no concurrent access is possible that late in object
494 static void osd_object_delete(const struct lu_env *env, struct lu_object *l)
496 struct osd_object *obj = osd_obj(l);
497 struct inode *inode = obj->oo_inode;
499 LASSERT(osd_invariant(obj));
502 * If object is unlinked remove fid->ino mapping from object index.
504 * File body will be deleted by iput().
511 if (osd_inode_unlinked(inode)) {
512 result = osd_inode_remove(env, obj);
514 LU_OBJECT_DEBUG(D_ERROR, env, l,
515 "Failed to cleanup: %d\n",
519 obj->oo_inode = NULL;
524 * Concurrency: ->loo_object_release() is called under site spin-lock.
526 static void osd_object_release(const struct lu_env *env,
529 struct osd_object *o = osd_obj(l);
531 LASSERT(!lu_object_is_dying(l->lo_header));
532 if (o->oo_inode != NULL && osd_inode_unlinked(o->oo_inode))
533 set_bit(LU_OBJECT_HEARD_BANSHEE, &l->lo_header->loh_flags);
537 * Concurrency: shouldn't matter.
539 static int osd_object_print(const struct lu_env *env, void *cookie,
540 lu_printer_t p, const struct lu_object *l)
542 struct osd_object *o = osd_obj(l);
545 if (o->oo_dir != NULL)
546 d = o->oo_dir->od_container.ic_descr;
549 return (*p)(env, cookie, LUSTRE_OSD_NAME"-object@%p(i:%p:%lu/%u)[%s]",
551 o->oo_inode ? o->oo_inode->i_ino : 0UL,
552 o->oo_inode ? o->oo_inode->i_generation : 0,
553 d ? d->id_ops->id_name : "plain");
557 * Concurrency: shouldn't matter.
559 static int osd_statfs(const struct lu_env *env,
560 struct dt_device *d, struct kstatfs *sfs)
562 struct osd_device *osd = osd_dt_dev(d);
563 struct super_block *sb = osd_sb(osd);
566 spin_lock(&osd->od_osfs_lock);
568 if (cfs_time_before_64(osd->od_osfs_age, cfs_time_shift_64(-1))) {
569 result = sb->s_op->statfs(sb, &osd->od_kstatfs);
570 if (likely(result == 0)) /* N.B. statfs can't really fail */
571 osd->od_osfs_age = cfs_time_current_64();
574 if (likely(result == 0))
575 *sfs = osd->od_kstatfs;
576 spin_unlock(&osd->od_osfs_lock);
582 * Concurrency: doesn't access mutable data.
584 static void osd_conf_get(const struct lu_env *env,
585 const struct dt_device *dev,
586 struct dt_device_param *param)
589 * XXX should be taken from not-yet-existing fs abstraction layer.
591 param->ddp_max_name_len = LDISKFS_NAME_LEN;
592 param->ddp_max_nlink = LDISKFS_LINK_MAX;
593 param->ddp_block_shift = osd_sb(osd_dt_dev(dev))->s_blocksize_bits;
601 * Concurrency: doesn't access mutable data.
603 static int osd_param_is_sane(const struct osd_device *dev,
604 const struct txn_param *param)
606 return param->tp_credits <= osd_journal(dev)->j_max_transaction_buffers;
610 * Concurrency: shouldn't matter.
612 static void osd_trans_commit_cb(struct journal_callback *jcb, int error)
614 struct osd_thandle *oh = container_of0(jcb, struct osd_thandle, ot_jcb);
615 struct thandle *th = &oh->ot_super;
616 struct dt_device *dev = th->th_dev;
618 LASSERT(dev != NULL);
619 LASSERT(oh->ot_handle == NULL);
622 CERROR("transaction @0x%p commit error: %d\n", th, error);
625 * This od_env_for_commit is only for commit usage. see
628 dt_txn_hook_commit(&osd_dt_dev(dev)->od_env_for_commit, th);
631 lu_device_put(&dev->dd_lu_dev);
634 lu_context_exit(&th->th_ctx);
635 lu_context_fini(&th->th_ctx);
640 * Concurrency: shouldn't matter.
642 static struct thandle *osd_trans_start(const struct lu_env *env,
646 struct osd_device *dev = osd_dt_dev(d);
648 struct osd_thandle *oh;
654 hook_res = dt_txn_hook_start(env, d, p);
656 RETURN(ERR_PTR(hook_res));
658 if (osd_param_is_sane(dev, p)) {
659 OBD_ALLOC_GFP(oh, sizeof *oh, CFS_ALLOC_IO);
662 * XXX temporary stuff. Some abstraction layer should
666 jh = journal_start(osd_journal(dev), p->tp_credits);
672 jh->h_sync = p->tp_sync;
673 lu_device_get(&d->dd_lu_dev);
674 /* add commit callback */
675 lu_context_init(&th->th_ctx, LCT_TX_HANDLE);
676 lu_context_enter(&th->th_ctx);
677 journal_callback_set(jh, osd_trans_commit_cb,
678 (struct journal_callback *)&oh->ot_jcb);
681 struct osd_thread_info *oti =
684 LASSERT(oti->oti_txns == 0);
685 LASSERT(oti->oti_r_locks == 0);
686 LASSERT(oti->oti_w_locks == 0);
695 th = ERR_PTR(-ENOMEM);
697 CERROR("Invalid transaction parameters\n");
698 th = ERR_PTR(-EINVAL);
705 * Concurrency: shouldn't matter.
707 static void osd_trans_stop(const struct lu_env *env, struct thandle *th)
710 struct osd_thandle *oh;
714 oh = container_of0(th, struct osd_thandle, ot_super);
715 if (oh->ot_handle != NULL) {
716 handle_t *hdl = oh->ot_handle;
718 * XXX temporary stuff. Some abstraction layer should be used.
720 result = dt_txn_hook_stop(env, th);
722 CERROR("Failure in transaction hook: %d\n", result);
725 oh->ot_handle = NULL;
726 result = journal_stop(hdl);
728 CERROR("Failure to stop transaction: %d\n", result);
732 struct osd_thread_info *oti = osd_oti_get(env);
734 LASSERT(oti->oti_txns == 1);
735 LASSERT(oti->oti_r_locks == 0);
736 LASSERT(oti->oti_w_locks == 0);
745 * Concurrency: shouldn't matter.
747 static int osd_sync(const struct lu_env *env, struct dt_device *d)
749 CDEBUG(D_HA, "syncing OSD %s\n", LUSTRE_OSD_NAME);
750 return ldiskfs_force_commit(osd_sb(osd_dt_dev(d)));
754 * Concurrency: shouldn't matter.
756 lvfs_sbdev_type fsfilt_ldiskfs_journal_sbdev(struct super_block *);
758 static void osd_ro(const struct lu_env *env, struct dt_device *d)
762 CERROR("*** setting device %s read-only ***\n", LUSTRE_OSD_NAME);
764 __lvfs_set_rdonly(lvfs_sbdev(osd_sb(osd_dt_dev(d))),
765 fsfilt_ldiskfs_journal_sbdev(osd_sb(osd_dt_dev(d))));
770 * Concurrency: serialization provided by callers.
772 static int osd_init_capa_ctxt(const struct lu_env *env, struct dt_device *d,
773 int mode, unsigned long timeout, __u32 alg,
774 struct lustre_capa_key *keys)
776 struct osd_device *dev = osd_dt_dev(d);
779 dev->od_fl_capa = mode;
780 dev->od_capa_timeout = timeout;
781 dev->od_capa_alg = alg;
782 dev->od_capa_keys = keys;
786 /* Note: we did not count into QUOTA here, If we mount with --data_journal
788 static const int osd_dto_credits[DTO_NR] = {
790 * Insert/Delete. IAM EXT3_INDEX_EXTRA_TRANS_BLOCKS(8) +
791 * EXT3_SINGLEDATA_TRANS_BLOCKS 8 XXX Note: maybe iam need more,since
792 * iam have more level than Ext3 htree
794 [DTO_INDEX_INSERT] = 16,
795 [DTO_INDEX_DELETE] = 16,
796 [DTO_IDNEX_UPDATE] = 16,
798 * Create a object. Same as create object in Ext3 filesystem, but did
799 * not count QUOTA i EXT3_DATA_TRANS_BLOCKS(12) +
800 * INDEX_EXTRA_BLOCKS(8) + 3(inode bits,groups, GDT)
802 [DTO_OBJECT_CREATE] = 23,
803 [DTO_OBJECT_DELETE] = 23,
805 * Attr set credits 3 inode, group, GDT
809 * XATTR_SET. SAME AS XATTR of EXT3 EXT3_DATA_TRANS_BLOCKS XXX Note:
810 * in original MDS implmentation EXT3_INDEX_EXTRA_TRANS_BLOCKS are
811 * also counted in. Do not know why?
813 [DTO_XATTR_SET] = 16,
817 static int osd_credit_get(const struct lu_env *env, struct dt_device *d,
820 LASSERT(0 <= op && op < ARRAY_SIZE(osd_dto_credits));
821 return osd_dto_credits[op];
824 static struct dt_device_operations osd_dt_ops = {
825 .dt_root_get = osd_root_get,
826 .dt_statfs = osd_statfs,
827 .dt_trans_start = osd_trans_start,
828 .dt_trans_stop = osd_trans_stop,
829 .dt_conf_get = osd_conf_get,
832 .dt_credit_get = osd_credit_get,
833 .dt_init_capa_ctxt = osd_init_capa_ctxt,
836 static void osd_object_read_lock(const struct lu_env *env,
837 struct dt_object *dt)
839 struct osd_object *obj = osd_dt_obj(dt);
841 LASSERT(osd_invariant(obj));
843 OSD_COUNTERS_DO(LASSERT(obj->oo_owner != env));
844 down_read(&obj->oo_sem);
847 struct osd_thread_info *oti = osd_oti_get(env);
849 LASSERT(obj->oo_owner == NULL);
855 static void osd_object_write_lock(const struct lu_env *env,
856 struct dt_object *dt)
858 struct osd_object *obj = osd_dt_obj(dt);
860 LASSERT(osd_invariant(obj));
862 OSD_COUNTERS_DO(LASSERT(obj->oo_owner != env));
863 down_write(&obj->oo_sem);
866 struct osd_thread_info *oti = osd_oti_get(env);
868 LASSERT(obj->oo_owner == NULL);
875 static void osd_object_read_unlock(const struct lu_env *env,
876 struct dt_object *dt)
878 struct osd_object *obj = osd_dt_obj(dt);
880 LASSERT(osd_invariant(obj));
883 struct osd_thread_info *oti = osd_oti_get(env);
885 LASSERT(oti->oti_r_locks > 0);
889 up_read(&obj->oo_sem);
892 static void osd_object_write_unlock(const struct lu_env *env,
893 struct dt_object *dt)
895 struct osd_object *obj = osd_dt_obj(dt);
897 LASSERT(osd_invariant(obj));
900 struct osd_thread_info *oti = osd_oti_get(env);
902 LASSERT(obj->oo_owner == env);
903 LASSERT(oti->oti_w_locks > 0);
905 obj->oo_owner = NULL;
908 up_write(&obj->oo_sem);
911 static int capa_is_sane(const struct lu_env *env,
912 struct osd_device *dev,
913 struct lustre_capa *capa,
914 struct lustre_capa_key *keys)
916 struct osd_thread_info *oti = osd_oti_get(env);
921 oc = capa_lookup(dev->od_capa_hash, capa, 0);
923 if (capa_is_expired(oc)) {
924 DEBUG_CAPA(D_ERROR, capa, "expired");
931 spin_lock(&capa_lock);
932 for (i = 0; i < 2; i++) {
933 if (keys[i].lk_keyid == capa->lc_keyid) {
934 oti->oti_capa_key = keys[i];
938 spin_unlock(&capa_lock);
941 DEBUG_CAPA(D_ERROR, capa, "no matched capa key");
945 rc = capa_hmac(oti->oti_capa.lc_hmac, capa, oti->oti_capa_key.lk_key);
948 if (memcmp(oti->oti_capa.lc_hmac, capa->lc_hmac, sizeof(capa->lc_hmac)))
950 DEBUG_CAPA(D_ERROR, capa, "HMAC mismatch");
954 oc = capa_add(dev->od_capa_hash, capa);
960 static int osd_object_auth(const struct lu_env *env, struct dt_object *dt,
961 struct lustre_capa *capa, __u64 opc)
963 const struct lu_fid *fid = lu_object_fid(&dt->do_lu);
964 struct osd_device *dev = osd_dev(dt->do_lu.lo_dev);
967 if (!dev->od_fl_capa)
970 if (capa == BYPASS_CAPA)
974 CERROR("no capability is provided for fid "DFID"\n", PFID(fid));
978 if (!lu_fid_eq(fid, &capa->lc_fid)) {
979 DEBUG_CAPA(D_ERROR, capa, "fid "DFID" mismatch with",
984 if (!capa_opc_supported(capa, opc)) {
985 DEBUG_CAPA(D_ERROR, capa, "opc "LPX64" not supported by", opc);
989 if ((rc = capa_is_sane(env, dev, capa, dev->od_capa_keys))) {
990 DEBUG_CAPA(D_ERROR, capa, "insane (rc %d)", rc);
997 static int osd_attr_get(const struct lu_env *env,
998 struct dt_object *dt,
999 struct lu_attr *attr,
1000 struct lustre_capa *capa)
1002 struct osd_object *obj = osd_dt_obj(dt);
1004 LASSERT(dt_object_exists(dt));
1005 LASSERT(osd_invariant(obj));
1007 if (osd_object_auth(env, dt, capa, CAPA_OPC_META_READ))
1010 spin_lock(&obj->oo_guard);
1011 osd_inode_getattr(env, obj->oo_inode, attr);
1012 spin_unlock(&obj->oo_guard);
1016 static int osd_attr_set(const struct lu_env *env,
1017 struct dt_object *dt,
1018 const struct lu_attr *attr,
1019 struct thandle *handle,
1020 struct lustre_capa *capa)
1022 struct osd_object *obj = osd_dt_obj(dt);
1024 LASSERT(handle != NULL);
1025 LASSERT(dt_object_exists(dt));
1026 LASSERT(osd_invariant(obj));
1028 if (osd_object_auth(env, dt, capa, CAPA_OPC_META_WRITE))
1031 spin_lock(&obj->oo_guard);
1032 osd_inode_setattr(env, obj->oo_inode, attr);
1033 spin_unlock(&obj->oo_guard);
1035 mark_inode_dirty(obj->oo_inode);
1039 static struct timespec *osd_inode_time(const struct lu_env *env,
1040 struct inode *inode, __u64 seconds)
1042 struct osd_thread_info *oti = osd_oti_get(env);
1043 struct timespec *t = &oti->oti_time;
1045 t->tv_sec = seconds;
1047 *t = timespec_trunc(*t, get_sb_time_gran(inode->i_sb));
1051 static void osd_inode_setattr(const struct lu_env *env,
1052 struct inode *inode, const struct lu_attr *attr)
1056 bits = attr->la_valid;
1058 LASSERT(!(bits & LA_TYPE)); /* Huh? You want too much. */
1060 if (bits & LA_ATIME)
1061 inode->i_atime = *osd_inode_time(env, inode, attr->la_atime);
1062 if (bits & LA_CTIME)
1063 inode->i_ctime = *osd_inode_time(env, inode, attr->la_ctime);
1064 if (bits & LA_MTIME)
1065 inode->i_mtime = *osd_inode_time(env, inode, attr->la_mtime);
1067 LDISKFS_I(inode)->i_disksize = inode->i_size = attr->la_size;
1068 if (bits & LA_BLOCKS)
1069 inode->i_blocks = attr->la_blocks;
1071 inode->i_mode = (inode->i_mode & S_IFMT) |
1072 (attr->la_mode & ~S_IFMT);
1074 inode->i_uid = attr->la_uid;
1076 inode->i_gid = attr->la_gid;
1077 if (bits & LA_NLINK)
1078 inode->i_nlink = attr->la_nlink;
1080 inode->i_rdev = attr->la_rdev;
1081 if (bits & LA_BLKSIZE)
1082 inode->i_blksize = attr->la_blksize;
1084 if (bits & LA_FLAGS) {
1085 struct ldiskfs_inode_info *li = LDISKFS_I(inode);
1087 li->i_flags = (li->i_flags & ~LDISKFS_FL_USER_MODIFIABLE) |
1088 (attr->la_flags & LDISKFS_FL_USER_MODIFIABLE);
1095 * XXX temporary solution.
1098 static int osd_create_pre(struct osd_thread_info *info, struct osd_object *obj,
1099 struct lu_attr *attr, struct thandle *th)
1104 static int osd_create_post(struct osd_thread_info *info, struct osd_object *obj,
1105 struct lu_attr *attr, struct thandle *th)
1107 LASSERT(obj->oo_inode != NULL);
1109 osd_object_init0(obj);
1113 extern struct inode *ldiskfs_create_inode(handle_t *handle,
1114 struct inode * dir, int mode);
1116 static int osd_mkfile(struct osd_thread_info *info, struct osd_object *obj,
1118 struct dt_allocation_hint *hint,
1122 struct osd_device *osd = osd_obj2dev(obj);
1123 struct osd_thandle *oth;
1124 struct inode *parent;
1125 struct inode *inode;
1127 LASSERT(osd_invariant(obj));
1128 LASSERT(obj->oo_inode == NULL);
1129 LASSERT(osd->od_obj_area != NULL);
1131 oth = container_of(th, struct osd_thandle, ot_super);
1132 LASSERT(oth->ot_handle->h_transaction != NULL);
1134 if (hint && hint->dah_parent)
1135 parent = osd_dt_obj(hint->dah_parent)->oo_inode;
1137 parent = osd->od_obj_area->d_inode;
1138 LASSERT(parent->i_op != NULL);
1140 inode = ldiskfs_create_inode(oth->ot_handle, parent, mode);
1141 if (!IS_ERR(inode)) {
1142 obj->oo_inode = inode;
1145 result = PTR_ERR(inode);
1146 LASSERT(osd_invariant(obj));
1151 extern int iam_lvar_create(struct inode *obj, int keysize, int ptrsize,
1152 int recsize, handle_t *handle);
1158 static int osd_mkdir(struct osd_thread_info *info, struct osd_object *obj,
1159 struct lu_attr *attr,
1160 struct dt_allocation_hint *hint,
1164 struct osd_thandle *oth;
1166 LASSERT(S_ISDIR(attr->la_mode));
1168 oth = container_of(th, struct osd_thandle, ot_super);
1169 LASSERT(oth->ot_handle->h_transaction != NULL);
1170 result = osd_mkfile(info, obj, (attr->la_mode &
1171 (S_IFMT | S_IRWXUGO | S_ISVTX)), hint, th);
1173 LASSERT(obj->oo_inode != NULL);
1175 * XXX uh-oh... call low-level iam function directly.
1177 result = iam_lvar_create(obj->oo_inode, OSD_NAME_LEN, 4,
1178 sizeof (struct lu_fid_pack),
1184 static int osd_mkreg(struct osd_thread_info *info, struct osd_object *obj,
1185 struct lu_attr *attr,
1186 struct dt_allocation_hint *hint,
1189 LASSERT(S_ISREG(attr->la_mode));
1190 return osd_mkfile(info, obj, (attr->la_mode &
1191 (S_IFMT | S_IRWXUGO | S_ISVTX)), hint, th);
1194 static int osd_mksym(struct osd_thread_info *info, struct osd_object *obj,
1195 struct lu_attr *attr,
1196 struct dt_allocation_hint *hint,
1199 LASSERT(S_ISLNK(attr->la_mode));
1200 return osd_mkfile(info, obj, (attr->la_mode &
1201 (S_IFMT | S_IRWXUGO | S_ISVTX)), hint, th);
1204 static int osd_mknod(struct osd_thread_info *info, struct osd_object *obj,
1205 struct lu_attr *attr,
1206 struct dt_allocation_hint *hint,
1210 struct osd_device *osd = osd_obj2dev(obj);
1212 umode_t mode = attr->la_mode & (S_IFMT | S_IRWXUGO | S_ISVTX);
1214 LASSERT(osd_invariant(obj));
1215 LASSERT(obj->oo_inode == NULL);
1216 LASSERT(osd->od_obj_area != NULL);
1217 LASSERT(S_ISCHR(mode) || S_ISBLK(mode) ||
1218 S_ISFIFO(mode) || S_ISSOCK(mode));
1220 dir = osd->od_obj_area->d_inode;
1221 LASSERT(dir->i_op != NULL);
1223 result = osd_mkfile(info, obj, mode, hint, th);
1225 LASSERT(obj->oo_inode != NULL);
1226 init_special_inode(obj->oo_inode, mode, attr->la_rdev);
1228 LASSERT(osd_invariant(obj));
1232 typedef int (*osd_obj_type_f)(struct osd_thread_info *, struct osd_object *,
1234 struct dt_allocation_hint *hint,
1237 static osd_obj_type_f osd_create_type_f(__u32 mode)
1239 osd_obj_type_f result;
1265 static void osd_ah_init(const struct lu_env *env, struct dt_allocation_hint *ah,
1266 struct dt_object *parent, umode_t child_mode)
1270 memset(ah, 0, sizeof(*ah));
1271 ah->dah_parent = parent;
1272 ah->dah_mode = child_mode;
1277 * Concurrency: @dt is write locked.
1279 static int osd_object_create(const struct lu_env *env, struct dt_object *dt,
1280 struct lu_attr *attr,
1281 struct dt_allocation_hint *hint,
1284 const struct lu_fid *fid = lu_object_fid(&dt->do_lu);
1285 struct osd_object *obj = osd_dt_obj(dt);
1286 struct osd_device *osd = osd_obj2dev(obj);
1287 struct osd_thread_info *info = osd_oti_get(env);
1292 LASSERT(osd_invariant(obj));
1293 LASSERT(!dt_object_exists(dt));
1294 LASSERT(osd_write_locked(env, obj));
1295 LASSERT(th != NULL);
1298 * XXX missing: Quote handling.
1301 result = osd_create_pre(info, obj, attr, th);
1303 result = osd_create_type_f(attr->la_mode & S_IFMT)(info, obj,
1306 result = osd_create_post(info, obj, attr, th);
1309 struct osd_inode_id *id = &info->oti_id;
1311 LASSERT(obj->oo_inode != NULL);
1313 id->oii_ino = obj->oo_inode->i_ino;
1314 id->oii_gen = obj->oo_inode->i_generation;
1316 result = osd_oi_insert(info, &osd->od_oi, fid, id, th);
1319 LASSERT(ergo(result == 0, dt_object_exists(dt)));
1320 LASSERT(osd_invariant(obj));
1325 * Concurrency: @dt is write locked.
1327 static void osd_object_ref_add(const struct lu_env *env,
1328 struct dt_object *dt,
1331 struct osd_object *obj = osd_dt_obj(dt);
1332 struct inode *inode = obj->oo_inode;
1334 LASSERT(osd_invariant(obj));
1335 LASSERT(dt_object_exists(dt));
1336 LASSERT(osd_write_locked(env, obj));
1337 LASSERT(th != NULL);
1339 spin_lock(&obj->oo_guard);
1340 if (inode->i_nlink < LDISKFS_LINK_MAX) {
1342 spin_unlock(&obj->oo_guard);
1343 mark_inode_dirty(inode);
1345 spin_unlock(&obj->oo_guard);
1346 LU_OBJECT_DEBUG(D_ERROR, env, &dt->do_lu,
1347 "Overflowed nlink\n");
1349 LASSERT(osd_invariant(obj));
1353 * Concurrency: @dt is write locked.
1355 static void osd_object_ref_del(const struct lu_env *env,
1356 struct dt_object *dt,
1359 struct osd_object *obj = osd_dt_obj(dt);
1360 struct inode *inode = obj->oo_inode;
1362 LASSERT(osd_invariant(obj));
1363 LASSERT(dt_object_exists(dt));
1364 LASSERT(osd_write_locked(env, obj));
1365 LASSERT(th != NULL);
1367 spin_lock(&obj->oo_guard);
1368 if (inode->i_nlink > 0) {
1370 spin_unlock(&obj->oo_guard);
1371 mark_inode_dirty(inode);
1373 spin_unlock(&obj->oo_guard);
1374 LU_OBJECT_DEBUG(D_ERROR, env, &dt->do_lu,
1375 "Underflowed nlink\n");
1377 LASSERT(osd_invariant(obj));
1381 * Concurrency: @dt is read locked.
1383 static int osd_xattr_get(const struct lu_env *env,
1384 struct dt_object *dt,
1387 struct lustre_capa *capa)
1389 struct osd_object *obj = osd_dt_obj(dt);
1390 struct inode *inode = obj->oo_inode;
1391 struct osd_thread_info *info = osd_oti_get(env);
1392 struct dentry *dentry = &info->oti_dentry;
1394 LASSERT(dt_object_exists(dt));
1395 LASSERT(inode->i_op != NULL && inode->i_op->getxattr != NULL);
1396 LASSERT(osd_read_locked(env, obj) || osd_write_locked(env, obj));
1398 if (osd_object_auth(env, dt, capa, CAPA_OPC_META_READ))
1401 dentry->d_inode = inode;
1402 return inode->i_op->getxattr(dentry, name, buf->lb_buf, buf->lb_len);
1406 * Concurrency: @dt is write locked.
1408 static int osd_xattr_set(const struct lu_env *env, struct dt_object *dt,
1409 const struct lu_buf *buf, const char *name, int fl,
1410 struct thandle *handle, struct lustre_capa *capa)
1414 struct osd_object *obj = osd_dt_obj(dt);
1415 struct inode *inode = obj->oo_inode;
1416 struct osd_thread_info *info = osd_oti_get(env);
1417 struct dentry *dentry = &info->oti_dentry;
1419 LASSERT(dt_object_exists(dt));
1420 LASSERT(inode->i_op != NULL && inode->i_op->setxattr != NULL);
1421 LASSERT(osd_write_locked(env, obj));
1422 LASSERT(handle != NULL);
1424 if (osd_object_auth(env, dt, capa, CAPA_OPC_META_WRITE))
1427 dentry->d_inode = inode;
1430 if (fl & LU_XATTR_REPLACE)
1431 fs_flags |= XATTR_REPLACE;
1433 if (fl & LU_XATTR_CREATE)
1434 fs_flags |= XATTR_CREATE;
1436 return inode->i_op->setxattr(dentry, name,
1437 buf->lb_buf, buf->lb_len, fs_flags);
1441 * Concurrency: @dt is read locked.
1443 static int osd_xattr_list(const struct lu_env *env,
1444 struct dt_object *dt,
1446 struct lustre_capa *capa)
1448 struct osd_object *obj = osd_dt_obj(dt);
1449 struct inode *inode = obj->oo_inode;
1450 struct osd_thread_info *info = osd_oti_get(env);
1451 struct dentry *dentry = &info->oti_dentry;
1453 LASSERT(dt_object_exists(dt));
1454 LASSERT(inode->i_op != NULL && inode->i_op->listxattr != NULL);
1455 LASSERT(osd_read_locked(env, obj) || osd_write_locked(env, obj));
1457 if (osd_object_auth(env, dt, capa, CAPA_OPC_META_READ))
1460 dentry->d_inode = inode;
1461 return inode->i_op->listxattr(dentry, buf->lb_buf, buf->lb_len);
1465 * Concurrency: @dt is write locked.
1467 static int osd_xattr_del(const struct lu_env *env,
1468 struct dt_object *dt,
1470 struct thandle *handle,
1471 struct lustre_capa *capa)
1473 struct osd_object *obj = osd_dt_obj(dt);
1474 struct inode *inode = obj->oo_inode;
1475 struct osd_thread_info *info = osd_oti_get(env);
1476 struct dentry *dentry = &info->oti_dentry;
1478 LASSERT(dt_object_exists(dt));
1479 LASSERT(inode->i_op != NULL && inode->i_op->removexattr != NULL);
1480 LASSERT(osd_write_locked(env, obj));
1481 LASSERT(handle != NULL);
1483 if (osd_object_auth(env, dt, capa, CAPA_OPC_META_WRITE))
1486 dentry->d_inode = inode;
1487 return inode->i_op->removexattr(dentry, name);
1490 static struct obd_capa *osd_capa_get(const struct lu_env *env,
1491 struct dt_object *dt,
1492 struct lustre_capa *old,
1493 __u32 uid, __u64 opc)
1495 struct osd_thread_info *info = osd_oti_get(env);
1496 const struct lu_fid *fid = lu_object_fid(&dt->do_lu);
1497 struct osd_object *obj = osd_dt_obj(dt);
1498 struct osd_device *dev = osd_obj2dev(obj);
1499 struct lustre_capa_key *key = &info->oti_capa_key;
1500 struct lustre_capa *capa = &info->oti_capa;
1501 struct obd_capa *oc;
1505 if (!dev->od_fl_capa)
1506 RETURN(ERR_PTR(-ENOENT));
1508 LASSERT(dt_object_exists(dt));
1509 LASSERT(osd_invariant(obj));
1511 /* renewal sanity check */
1512 if (old && osd_object_auth(env, dt, old, opc))
1513 RETURN(ERR_PTR(-EACCES));
1515 capa->lc_fid = *fid;
1518 capa->lc_flags = dev->od_capa_alg << 24;
1519 capa->lc_timeout = dev->od_capa_timeout;
1520 capa->lc_expiry = 0;
1522 oc = capa_lookup(dev->od_capa_hash, capa, 1);
1524 LASSERT(!capa_is_expired(oc));
1528 spin_lock(&capa_lock);
1529 *key = dev->od_capa_keys[1];
1530 spin_unlock(&capa_lock);
1532 capa->lc_keyid = key->lk_keyid;
1533 capa->lc_expiry = CURRENT_SECONDS + dev->od_capa_timeout;
1535 rc = capa_hmac(capa->lc_hmac, capa, key->lk_key);
1537 DEBUG_CAPA(D_ERROR, capa, "HMAC failed: %d for", rc);
1538 RETURN(ERR_PTR(rc));
1541 oc = capa_add(dev->od_capa_hash, capa);
1545 static struct dt_object_operations osd_obj_ops = {
1546 .do_read_lock = osd_object_read_lock,
1547 .do_write_lock = osd_object_write_lock,
1548 .do_read_unlock = osd_object_read_unlock,
1549 .do_write_unlock = osd_object_write_unlock,
1550 .do_attr_get = osd_attr_get,
1551 .do_attr_set = osd_attr_set,
1552 .do_ah_init = osd_ah_init,
1553 .do_create = osd_object_create,
1554 .do_index_try = osd_index_try,
1555 .do_ref_add = osd_object_ref_add,
1556 .do_ref_del = osd_object_ref_del,
1557 .do_xattr_get = osd_xattr_get,
1558 .do_xattr_set = osd_xattr_set,
1559 .do_xattr_del = osd_xattr_del,
1560 .do_xattr_list = osd_xattr_list,
1561 .do_capa_get = osd_capa_get,
1569 * XXX: Another layering violation for now.
1571 * We don't want to use ->f_op->read methods, because generic file write
1573 * - serializes on ->i_sem, and
1575 * - does a lot of extra work like balance_dirty_pages(),
1577 * which doesn't work for globally shared files like /last-received.
1579 int fsfilt_ldiskfs_read(struct inode *inode, void *buf, int size, loff_t *offs);
1580 int fsfilt_ldiskfs_write_handle(struct inode *inode, void *buf, int bufsize,
1581 loff_t *offs, handle_t *handle);
1583 static ssize_t osd_read(const struct lu_env *env, struct dt_object *dt,
1584 struct lu_buf *buf, loff_t *pos,
1585 struct lustre_capa *capa)
1587 struct inode *inode = osd_dt_obj(dt)->oo_inode;
1589 if (osd_object_auth(env, dt, capa, CAPA_OPC_BODY_READ))
1592 return fsfilt_ldiskfs_read(inode, buf->lb_buf, buf->lb_len, pos);
1595 static ssize_t osd_write(const struct lu_env *env, struct dt_object *dt,
1596 const struct lu_buf *buf, loff_t *pos,
1597 struct thandle *handle, struct lustre_capa *capa)
1599 struct inode *inode = osd_dt_obj(dt)->oo_inode;
1600 struct osd_thandle *oh;
1603 LASSERT(handle != NULL);
1605 if (osd_object_auth(env, dt, capa, CAPA_OPC_BODY_WRITE))
1608 oh = container_of(handle, struct osd_thandle, ot_super);
1609 LASSERT(oh->ot_handle->h_transaction != NULL);
1610 result = fsfilt_ldiskfs_write_handle(inode, buf->lb_buf, buf->lb_len,
1611 pos, oh->ot_handle);
1613 result = buf->lb_len;
1617 static struct dt_body_operations osd_body_ops = {
1618 .dbo_read = osd_read,
1619 .dbo_write = osd_write
1626 static int osd_object_is_root(const struct osd_object *obj)
1628 return osd_sb(osd_obj2dev(obj))->s_root->d_inode == obj->oo_inode;
1631 static int osd_index_probe(const struct lu_env *env, struct osd_object *o,
1632 const struct dt_index_features *feat)
1634 struct iam_descr *descr;
1636 if (osd_object_is_root(o))
1637 return feat == &dt_directory_features;
1639 LASSERT(o->oo_dir != NULL);
1641 descr = o->oo_dir->od_container.ic_descr;
1642 if (feat == &dt_directory_features)
1643 return descr == &iam_htree_compat_param ||
1644 (descr->id_rec_size == sizeof(struct lu_fid_pack) &&
1646 * XXX check that index looks like directory.
1651 feat->dif_keysize_min <= descr->id_key_size &&
1652 descr->id_key_size <= feat->dif_keysize_max &&
1653 feat->dif_recsize_min <= descr->id_rec_size &&
1654 descr->id_rec_size <= feat->dif_recsize_max &&
1655 !(feat->dif_flags & (DT_IND_VARKEY |
1656 DT_IND_VARREC | DT_IND_NONUNQ)) &&
1657 ergo(feat->dif_flags & DT_IND_UPDATE,
1658 1 /* XXX check that object (and file system) is
1662 static int osd_container_init(const struct lu_env *env,
1663 struct osd_object *obj,
1664 struct osd_directory *dir)
1667 struct iam_container *bag;
1669 bag = &dir->od_container;
1670 result = iam_container_init(bag, &dir->od_descr, obj->oo_inode);
1672 result = iam_container_setup(bag);
1674 obj->oo_dt.do_index_ops = &osd_index_ops;
1676 iam_container_fini(bag);
1682 * Concurrency: no external locking is necessary.
1684 static int osd_index_try(const struct lu_env *env, struct dt_object *dt,
1685 const struct dt_index_features *feat)
1688 struct osd_object *obj = osd_dt_obj(dt);
1690 LASSERT(osd_invariant(obj));
1691 LASSERT(dt_object_exists(dt));
1693 if (osd_object_is_root(obj)) {
1694 dt->do_index_ops = &osd_index_compat_ops;
1696 } else if (!osd_has_index(obj)) {
1697 struct osd_directory *dir;
1701 sema_init(&dir->od_sem, 1);
1703 spin_lock(&obj->oo_guard);
1704 if (obj->oo_dir == NULL)
1708 * Concurrent thread allocated container data.
1711 spin_unlock(&obj->oo_guard);
1713 * Now, that we have container data, serialize its
1716 down(&obj->oo_dir->od_sem);
1718 * recheck under lock.
1720 if (!osd_has_index(obj))
1721 result = osd_container_init(env, obj, dir);
1724 up(&obj->oo_dir->od_sem);
1731 if (!osd_index_probe(env, obj, feat))
1734 LASSERT(osd_invariant(obj));
1739 static int osd_index_delete(const struct lu_env *env, struct dt_object *dt,
1740 const struct dt_key *key, struct thandle *handle,
1741 struct lustre_capa *capa)
1743 struct osd_object *obj = osd_dt_obj(dt);
1744 struct osd_thandle *oh;
1745 struct iam_path_descr *ipd;
1746 struct iam_container *bag = &obj->oo_dir->od_container;
1751 LASSERT(osd_invariant(obj));
1752 LASSERT(dt_object_exists(dt));
1753 LASSERT(bag->ic_object == obj->oo_inode);
1754 LASSERT(handle != NULL);
1756 if (osd_object_auth(env, dt, capa, CAPA_OPC_INDEX_DELETE))
1759 ipd = osd_ipd_get(env, bag);
1760 if (unlikely(ipd == NULL))
1763 oh = container_of0(handle, struct osd_thandle, ot_super);
1764 LASSERT(oh->ot_handle != NULL);
1765 LASSERT(oh->ot_handle->h_transaction != NULL);
1767 rc = iam_delete(oh->ot_handle, bag, (const struct iam_key *)key, ipd);
1768 osd_ipd_put(env, bag, ipd);
1769 LASSERT(osd_invariant(obj));
1773 static int osd_index_lookup(const struct lu_env *env, struct dt_object *dt,
1774 struct dt_rec *rec, const struct dt_key *key,
1775 struct lustre_capa *capa)
1777 struct osd_object *obj = osd_dt_obj(dt);
1778 struct iam_path_descr *ipd;
1779 struct iam_container *bag = &obj->oo_dir->od_container;
1784 LASSERT(osd_invariant(obj));
1785 LASSERT(dt_object_exists(dt));
1786 LASSERT(bag->ic_object == obj->oo_inode);
1788 if (osd_object_auth(env, dt, capa, CAPA_OPC_INDEX_LOOKUP))
1791 ipd = osd_ipd_get(env, bag);
1792 if (unlikely(ipd == NULL))
1795 rc = iam_lookup(bag, (const struct iam_key *)key,
1796 (struct iam_rec *)rec, ipd);
1797 osd_ipd_put(env, bag, ipd);
1798 LASSERT(osd_invariant(obj));
1803 static int osd_index_insert(const struct lu_env *env, struct dt_object *dt,
1804 const struct dt_rec *rec, const struct dt_key *key,
1805 struct thandle *th, struct lustre_capa *capa)
1807 struct osd_object *obj = osd_dt_obj(dt);
1808 struct iam_path_descr *ipd;
1809 struct osd_thandle *oh;
1810 struct iam_container *bag = &obj->oo_dir->od_container;
1815 LASSERT(osd_invariant(obj));
1816 LASSERT(dt_object_exists(dt));
1817 LASSERT(bag->ic_object == obj->oo_inode);
1818 LASSERT(th != NULL);
1820 if (osd_object_auth(env, dt, capa, CAPA_OPC_INDEX_INSERT))
1823 ipd = osd_ipd_get(env, bag);
1824 if (unlikely(ipd == NULL))
1827 oh = container_of0(th, struct osd_thandle, ot_super);
1828 LASSERT(oh->ot_handle != NULL);
1829 LASSERT(oh->ot_handle->h_transaction != NULL);
1830 rc = iam_insert(oh->ot_handle, bag, (const struct iam_key *)key,
1831 (struct iam_rec *)rec, ipd);
1832 osd_ipd_put(env, bag, ipd);
1833 LASSERT(osd_invariant(obj));
1838 * Iterator operations.
1841 struct osd_object *oi_obj;
1842 struct iam_path_descr *oi_ipd;
1843 struct iam_iterator oi_it;
1846 static struct dt_it *osd_it_init(const struct lu_env *env,
1847 struct dt_object *dt, int writable,
1848 struct lustre_capa *capa)
1851 struct osd_object *obj = osd_dt_obj(dt);
1852 struct lu_object *lo = &dt->do_lu;
1853 struct iam_path_descr *ipd;
1854 struct iam_container *bag = &obj->oo_dir->od_container;
1857 LASSERT(lu_object_exists(lo));
1859 if (osd_object_auth(env, dt, capa, writable ? CAPA_OPC_BODY_WRITE :
1860 CAPA_OPC_BODY_READ))
1861 return ERR_PTR(-EACCES);
1863 flags = writable ? IAM_IT_MOVE|IAM_IT_WRITE : IAM_IT_MOVE;
1867 * XXX: as ipd is allocated within osd_thread_info, assignment
1868 * below implies that iterator usage is confined within single
1871 ipd = osd_ipd_get(env, bag);
1872 if (likely(ipd != NULL)) {
1876 iam_it_init(&it->oi_it, bag, flags, ipd);
1877 return (struct dt_it *)it;
1881 return ERR_PTR(-ENOMEM);
1884 static void osd_it_fini(const struct lu_env *env, struct dt_it *di)
1886 struct osd_it *it = (struct osd_it *)di;
1887 struct osd_object *obj = it->oi_obj;
1889 iam_it_fini(&it->oi_it);
1890 osd_ipd_put(env, &obj->oo_dir->od_container, it->oi_ipd);
1891 lu_object_put(env, &obj->oo_dt.do_lu);
1895 static int osd_it_get(const struct lu_env *env,
1896 struct dt_it *di, const struct dt_key *key)
1898 struct osd_it *it = (struct osd_it *)di;
1900 return iam_it_get(&it->oi_it, (const struct iam_key *)key);
1903 static void osd_it_put(const struct lu_env *env, struct dt_it *di)
1905 struct osd_it *it = (struct osd_it *)di;
1907 iam_it_put(&it->oi_it);
1910 static int osd_it_next(const struct lu_env *env, struct dt_it *di)
1912 struct osd_it *it = (struct osd_it *)di;
1914 return iam_it_next(&it->oi_it);
1917 static int osd_it_del(const struct lu_env *env, struct dt_it *di,
1920 struct osd_it *it = (struct osd_it *)di;
1921 struct osd_thandle *oh;
1923 LASSERT(th != NULL);
1925 oh = container_of0(th, struct osd_thandle, ot_super);
1926 LASSERT(oh->ot_handle != NULL);
1927 LASSERT(oh->ot_handle->h_transaction != NULL);
1929 return iam_it_rec_delete(oh->ot_handle, &it->oi_it);
1932 static struct dt_key *osd_it_key(const struct lu_env *env,
1933 const struct dt_it *di)
1935 struct osd_it *it = (struct osd_it *)di;
1937 return (struct dt_key *)iam_it_key_get(&it->oi_it);
1940 static int osd_it_key_size(const struct lu_env *env, const struct dt_it *di)
1942 struct osd_it *it = (struct osd_it *)di;
1944 return iam_it_key_size(&it->oi_it);
1947 static struct dt_rec *osd_it_rec(const struct lu_env *env,
1948 const struct dt_it *di)
1950 struct osd_it *it = (struct osd_it *)di;
1952 return (struct dt_rec *)iam_it_rec_get(&it->oi_it);
1955 static __u32 osd_it_store(const struct lu_env *env, const struct dt_it *di)
1957 struct osd_it *it = (struct osd_it *)di;
1959 return iam_it_store(&it->oi_it);
1962 static int osd_it_load(const struct lu_env *env,
1963 const struct dt_it *di, __u32 hash)
1965 struct osd_it *it = (struct osd_it *)di;
1967 return iam_it_load(&it->oi_it, hash);
1970 static struct dt_index_operations osd_index_ops = {
1971 .dio_lookup = osd_index_lookup,
1972 .dio_insert = osd_index_insert,
1973 .dio_delete = osd_index_delete,
1975 .init = osd_it_init,
1976 .fini = osd_it_fini,
1980 .next = osd_it_next,
1982 .key_size = osd_it_key_size,
1984 .store = osd_it_store,
1989 static int osd_index_compat_delete(const struct lu_env *env,
1990 struct dt_object *dt,
1991 const struct dt_key *key,
1992 struct thandle *handle,
1993 struct lustre_capa *capa)
1995 struct osd_object *obj = osd_dt_obj(dt);
1997 LASSERT(handle != NULL);
1998 LASSERT(S_ISDIR(obj->oo_inode->i_mode));
2002 if (osd_object_auth(env, dt, capa, CAPA_OPC_INDEX_DELETE))
2006 RETURN(-EOPNOTSUPP);
2010 * Compatibility index operations.
2014 static void osd_build_pack(const struct lu_env *env, struct osd_device *osd,
2015 struct dentry *dentry, struct lu_fid_pack *pack)
2017 struct inode *inode = dentry->d_inode;
2018 struct lu_fid *fid = &osd_oti_get(env)->oti_fid;
2020 lu_igif_build(fid, inode->i_ino, inode->i_generation);
2021 fid_cpu_to_be(fid, fid);
2022 pack->fp_len = sizeof *fid + 1;
2023 memcpy(pack->fp_area, fid, sizeof *fid);
2026 static int osd_index_compat_lookup(const struct lu_env *env,
2027 struct dt_object *dt,
2028 struct dt_rec *rec, const struct dt_key *key,
2029 struct lustre_capa *capa)
2031 struct osd_object *obj = osd_dt_obj(dt);
2033 struct osd_device *osd = osd_obj2dev(obj);
2034 struct osd_thread_info *info = osd_oti_get(env);
2040 * XXX temporary solution.
2042 struct dentry *dentry;
2043 struct dentry *parent;
2045 LASSERT(osd_invariant(obj));
2046 LASSERT(S_ISDIR(obj->oo_inode->i_mode));
2047 LASSERT(osd_has_index(obj));
2049 if (osd_object_auth(env, dt, capa, CAPA_OPC_INDEX_LOOKUP))
2052 info->oti_str.name = (const char *)key;
2053 info->oti_str.len = strlen((const char *)key);
2055 dir = obj->oo_inode;
2056 LASSERT(dir->i_op != NULL && dir->i_op->lookup != NULL);
2058 parent = d_alloc_root(dir);
2062 dentry = d_alloc(parent, &info->oti_str);
2063 if (dentry != NULL) {
2067 * XXX passing NULL for nameidata should work for
2070 d = dir->i_op->lookup(dir, dentry, NULL);
2073 * normal case, result is in @dentry.
2075 if (dentry->d_inode != NULL) {
2076 osd_build_pack(env, osd, dentry,
2077 (struct lu_fid_pack *)rec);
2082 /* What? Disconnected alias? Ppheeeww... */
2083 CERROR("Aliasing where not expected\n");
2091 LASSERT(osd_invariant(obj));
2095 static int osd_add_rec(struct osd_thread_info *info, struct osd_device *dev,
2096 struct inode *dir, struct inode *inode, const char *name)
2100 struct dentry *parent;
2104 info->oti_str.name = name;
2105 info->oti_str.len = strlen(name);
2107 LASSERT(atomic_read(&dir->i_count) > 0);
2109 old = d_alloc(dev->od_obj_area, &info->oti_str);
2111 d_instantiate(old, inode);
2113 LASSERT(atomic_read(&dir->i_count) > 0);
2114 parent = d_alloc_root(dir);
2115 if (parent != NULL) {
2117 LASSERT(atomic_read(&dir->i_count) > 1);
2118 new = d_alloc(parent, &info->oti_str);
2119 LASSERT(atomic_read(&dir->i_count) > 1);
2121 LASSERT(atomic_read(&dir->i_count) > 1);
2122 result = dir->i_op->link(old, dir, new);
2123 LASSERT(atomic_read(&dir->i_count) > 1);
2125 LASSERT(atomic_read(&dir->i_count) > 1);
2127 LASSERT(atomic_read(&dir->i_count) > 1);
2129 LASSERT(atomic_read(&dir->i_count) > 0);
2133 LASSERT(atomic_read(&dir->i_count) > 0);
2139 * XXX Temporary stuff.
2141 static int osd_index_compat_insert(const struct lu_env *env,
2142 struct dt_object *dt,
2143 const struct dt_rec *rec,
2144 const struct dt_key *key, struct thandle *th,
2145 struct lustre_capa *capa)
2147 struct osd_object *obj = osd_dt_obj(dt);
2149 const char *name = (const char *)key;
2151 struct lu_device *ludev = dt->do_lu.lo_dev;
2152 struct lu_object *luch;
2154 struct osd_thread_info *info = osd_oti_get(env);
2155 const struct lu_fid_pack *pack = (const struct lu_fid_pack *)rec;
2156 struct lu_fid *fid = &osd_oti_get(env)->oti_fid;
2160 LASSERT(S_ISDIR(obj->oo_inode->i_mode));
2161 LASSERT(osd_invariant(obj));
2162 LASSERT(th != NULL);
2164 if (osd_object_auth(env, dt, capa, CAPA_OPC_INDEX_INSERT))
2167 fid_unpack(pack, fid);
2168 luch = lu_object_find(env, ludev->ld_site, fid);
2169 if (!IS_ERR(luch)) {
2170 if (lu_object_exists(luch)) {
2171 struct osd_object *child;
2173 child = osd_obj(lu_object_locate(luch->lo_header,
2176 result = osd_add_rec(info, osd_obj2dev(obj),
2178 child->oo_inode, name);
2180 CERROR("No osd slice.\n");
2183 LASSERT(osd_invariant(obj));
2184 LASSERT(osd_invariant(child));
2189 lu_object_put(env, luch);
2191 result = PTR_ERR(luch);
2192 LASSERT(osd_invariant(obj));
2196 static struct dt_index_operations osd_index_compat_ops = {
2197 .dio_lookup = osd_index_compat_lookup,
2198 .dio_insert = osd_index_compat_insert,
2199 .dio_delete = osd_index_compat_delete
2203 * OSD device type methods
2205 static int osd_type_init(struct lu_device_type *t)
2207 LU_CONTEXT_KEY_INIT(&osd_key);
2208 return lu_context_key_register(&osd_key);
2211 static void osd_type_fini(struct lu_device_type *t)
2213 lu_context_key_degister(&osd_key);
2216 static struct lu_context_key osd_key = {
2217 .lct_tags = LCT_DT_THREAD | LCT_MD_THREAD,
2218 .lct_init = osd_key_init,
2219 .lct_fini = osd_key_fini,
2220 .lct_exit = osd_key_exit
2223 static void *osd_key_init(const struct lu_context *ctx,
2224 struct lu_context_key *key)
2226 struct osd_thread_info *info;
2228 OBD_ALLOC_PTR(info);
2230 info->oti_env = container_of(ctx, struct lu_env, le_ctx);
2232 info = ERR_PTR(-ENOMEM);
2236 static void osd_key_fini(const struct lu_context *ctx,
2237 struct lu_context_key *key, void *data)
2239 struct osd_thread_info *info = data;
2243 static void osd_key_exit(const struct lu_context *ctx,
2244 struct lu_context_key *key, void *data)
2247 struct osd_thread_info *info = data;
2249 LASSERT(info->oti_r_locks == 0);
2250 LASSERT(info->oti_w_locks == 0);
2251 LASSERT(info->oti_txns == 0);
2255 static int osd_device_init(const struct lu_env *env, struct lu_device *d,
2256 const char *name, struct lu_device *next)
2258 return lu_env_init(&osd_dev(d)->od_env_for_commit, NULL, LCT_MD_THREAD);
2261 static int osd_shutdown(const struct lu_env *env, struct osd_device *o)
2263 struct osd_thread_info *info = osd_oti_get(env);
2265 if (o->od_obj_area != NULL) {
2266 dput(o->od_obj_area);
2267 o->od_obj_area = NULL;
2269 osd_oi_fini(info, &o->od_oi);
2274 static int osd_mount(const struct lu_env *env,
2275 struct osd_device *o, struct lustre_cfg *cfg)
2277 struct lustre_mount_info *lmi;
2278 const char *dev = lustre_cfg_string(cfg, 0);
2279 struct osd_thread_info *info = osd_oti_get(env);
2284 if (o->od_mount != NULL) {
2285 CERROR("Already mounted (%s)\n", dev);
2290 lmi = server_get_mount(dev);
2292 CERROR("Cannot get mount info for %s!\n", dev);
2296 LASSERT(lmi != NULL);
2297 /* save lustre_mount_info in dt_device */
2300 result = osd_oi_init(info, &o->od_oi, &o->od_dt_dev);
2304 d = simple_mkdir(osd_sb(o)->s_root, "*OBJ-TEMP*", 0777, 1);
2308 result = PTR_ERR(d);
2311 osd_shutdown(env, o);
2315 static struct lu_device *osd_device_fini(const struct lu_env *env,
2316 struct lu_device *d)
2320 shrink_dcache_sb(osd_sb(osd_dev(d)));
2321 osd_sync(env, lu2dt_dev(d));
2323 if (osd_dev(d)->od_mount)
2324 server_put_mount(osd_dev(d)->od_mount->lmi_name,
2325 osd_dev(d)->od_mount->lmi_mnt);
2326 osd_dev(d)->od_mount = NULL;
2328 lu_env_fini(&osd_dev(d)->od_env_for_commit);
2332 static struct lu_device *osd_device_alloc(const struct lu_env *env,
2333 struct lu_device_type *t,
2334 struct lustre_cfg *cfg)
2336 struct lu_device *l;
2337 struct osd_device *o;
2343 result = dt_device_init(&o->od_dt_dev, t);
2346 l->ld_ops = &osd_lu_ops;
2347 o->od_dt_dev.dd_ops = &osd_dt_ops;
2348 spin_lock_init(&o->od_osfs_lock);
2349 o->od_osfs_age = cfs_time_shift_64(-1000);
2350 o->od_capa_hash = init_capa_hash();
2351 if (o->od_capa_hash == NULL)
2352 l = ERR_PTR(-ENOMEM);
2354 l = ERR_PTR(result);
2356 l = ERR_PTR(-ENOMEM);
2360 static void osd_device_free(const struct lu_env *env, struct lu_device *d)
2362 struct osd_device *o = osd_dev(d);
2364 cleanup_capa_hash(o->od_capa_hash);
2365 dt_device_fini(&o->od_dt_dev);
2369 static int osd_process_config(const struct lu_env *env,
2370 struct lu_device *d, struct lustre_cfg *cfg)
2372 struct osd_device *o = osd_dev(d);
2376 switch(cfg->lcfg_command) {
2378 err = osd_mount(env, o, cfg);
2381 err = osd_shutdown(env, o);
2389 extern void ldiskfs_orphan_cleanup (struct super_block * sb,
2390 struct ldiskfs_super_block * es);
2392 static int osd_recovery_complete(const struct lu_env *env,
2393 struct lu_device *d)
2395 struct osd_device *o = osd_dev(d);
2397 /* TODO: orphans handling */
2398 ldiskfs_orphan_cleanup(osd_sb(o), LDISKFS_SB(osd_sb(o))->s_es);
2402 static struct inode *osd_iget(struct osd_thread_info *info,
2403 struct osd_device *dev,
2404 const struct osd_inode_id *id)
2406 struct inode *inode;
2408 inode = iget(osd_sb(dev), id->oii_ino);
2409 if (inode == NULL) {
2410 CERROR("no inode\n");
2411 inode = ERR_PTR(-EACCES);
2412 } else if (is_bad_inode(inode)) {
2413 CERROR("bad inode\n");
2415 inode = ERR_PTR(-ENOENT);
2416 } else if (inode->i_generation != id->oii_gen) {
2417 CERROR("stale inode\n");
2419 inode = ERR_PTR(-ESTALE);
2426 static int osd_fid_lookup(const struct lu_env *env,
2427 struct osd_object *obj, const struct lu_fid *fid)
2429 struct osd_thread_info *info;
2430 struct lu_device *ldev = obj->oo_dt.do_lu.lo_dev;
2431 struct osd_device *dev;
2432 struct osd_inode_id *id;
2434 struct inode *inode;
2437 LASSERT(osd_invariant(obj));
2438 LASSERT(obj->oo_inode == NULL);
2439 LASSERT(fid_is_sane(fid));
2441 * This assertion checks that osd layer sees only local
2442 * fids. Unfortunately it is somewhat expensive (does a
2443 * cache-lookup). Disabling it for production/acceptance-testing.
2445 LASSERT(1 || fid_is_local(ldev->ld_site, fid));
2449 info = osd_oti_get(env);
2450 dev = osd_dev(ldev);
2454 if (OBD_FAIL_CHECK(OBD_FAIL_OST_ENOENT))
2457 result = osd_oi_lookup(info, oi, fid, id);
2459 inode = osd_iget(info, dev, id);
2460 if (!IS_ERR(inode)) {
2461 obj->oo_inode = inode;
2462 LASSERT(obj->oo_inode->i_sb == osd_sb(dev));
2466 * If fid wasn't found in oi, inode-less object is
2467 * created, for which lu_object_exists() returns
2468 * false. This is used in a (frequent) case when
2469 * objects are created as locking anchors or
2470 * place holders for objects yet to be created.
2472 result = PTR_ERR(inode);
2473 } else if (result == -ENOENT)
2475 LASSERT(osd_invariant(obj));
2479 static void osd_inode_getattr(const struct lu_env *env,
2480 struct inode *inode, struct lu_attr *attr)
2482 attr->la_valid |= LA_ATIME | LA_MTIME | LA_CTIME | LA_MODE |
2483 LA_SIZE | LA_BLOCKS | LA_UID | LA_GID |
2484 LA_FLAGS | LA_NLINK | LA_RDEV | LA_BLKSIZE;
2486 attr->la_atime = LTIME_S(inode->i_atime);
2487 attr->la_mtime = LTIME_S(inode->i_mtime);
2488 attr->la_ctime = LTIME_S(inode->i_ctime);
2489 attr->la_mode = inode->i_mode;
2490 attr->la_size = inode->i_size;
2491 attr->la_blocks = inode->i_blocks;
2492 attr->la_uid = inode->i_uid;
2493 attr->la_gid = inode->i_gid;
2494 attr->la_flags = LDISKFS_I(inode)->i_flags;
2495 attr->la_nlink = inode->i_nlink;
2496 attr->la_rdev = inode->i_rdev;
2497 attr->la_blksize = inode->i_blksize;
2504 static int lu_device_is_osd(const struct lu_device *d)
2506 return ergo(d != NULL && d->ld_ops != NULL, d->ld_ops == &osd_lu_ops);
2509 static struct osd_object *osd_obj(const struct lu_object *o)
2511 LASSERT(lu_device_is_osd(o->lo_dev));
2512 return container_of0(o, struct osd_object, oo_dt.do_lu);
2515 static struct osd_device *osd_dt_dev(const struct dt_device *d)
2517 LASSERT(lu_device_is_osd(&d->dd_lu_dev));
2518 return container_of0(d, struct osd_device, od_dt_dev);
2521 static struct osd_device *osd_dev(const struct lu_device *d)
2523 LASSERT(lu_device_is_osd(d));
2524 return osd_dt_dev(container_of0(d, struct dt_device, dd_lu_dev));
2527 static struct osd_object *osd_dt_obj(const struct dt_object *d)
2529 return osd_obj(&d->do_lu);
2532 static struct osd_device *osd_obj2dev(const struct osd_object *o)
2534 return osd_dev(o->oo_dt.do_lu.lo_dev);
2537 static struct lu_device *osd2lu_dev(struct osd_device *osd)
2539 return &osd->od_dt_dev.dd_lu_dev;
2542 static struct super_block *osd_sb(const struct osd_device *dev)
2544 return dev->od_mount->lmi_mnt->mnt_sb;
2547 static journal_t *osd_journal(const struct osd_device *dev)
2549 return LDISKFS_SB(osd_sb(dev))->s_journal;
2552 static int osd_has_index(const struct osd_object *obj)
2554 return obj->oo_dt.do_index_ops != NULL;
2557 static int osd_object_invariant(const struct lu_object *l)
2559 return osd_invariant(osd_obj(l));
2562 static struct lu_object_operations osd_lu_obj_ops = {
2563 .loo_object_init = osd_object_init,
2564 .loo_object_delete = osd_object_delete,
2565 .loo_object_release = osd_object_release,
2566 .loo_object_free = osd_object_free,
2567 .loo_object_print = osd_object_print,
2568 .loo_object_invariant = osd_object_invariant
2571 static struct lu_device_operations osd_lu_ops = {
2572 .ldo_object_alloc = osd_object_alloc,
2573 .ldo_process_config = osd_process_config,
2574 .ldo_recovery_complete = osd_recovery_complete
2577 static struct lu_device_type_operations osd_device_type_ops = {
2578 .ldto_init = osd_type_init,
2579 .ldto_fini = osd_type_fini,
2581 .ldto_device_alloc = osd_device_alloc,
2582 .ldto_device_free = osd_device_free,
2584 .ldto_device_init = osd_device_init,
2585 .ldto_device_fini = osd_device_fini
2588 static struct lu_device_type osd_device_type = {
2589 .ldt_tags = LU_DEVICE_DT,
2590 .ldt_name = LUSTRE_OSD_NAME,
2591 .ldt_ops = &osd_device_type_ops,
2592 .ldt_ctx_tags = LCT_MD_THREAD|LCT_DT_THREAD
2596 * lprocfs legacy support.
2598 static struct lprocfs_vars lprocfs_osd_obd_vars[] = {
2602 static struct lprocfs_vars lprocfs_osd_module_vars[] = {
2606 static struct obd_ops osd_obd_device_ops = {
2607 .o_owner = THIS_MODULE
2610 LPROCFS_INIT_VARS(osd, lprocfs_osd_module_vars, lprocfs_osd_obd_vars);
2612 static int __init osd_mod_init(void)
2614 struct lprocfs_static_vars lvars;
2616 lprocfs_init_vars(osd, &lvars);
2617 return class_register_type(&osd_obd_device_ops, NULL, lvars.module_vars,
2618 LUSTRE_OSD_NAME, &osd_device_type);
2621 static void __exit osd_mod_exit(void)
2623 class_unregister_type(LUSTRE_OSD_NAME);
2626 MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
2627 MODULE_DESCRIPTION("Lustre Object Storage Device ("LUSTRE_OSD_NAME")");
2628 MODULE_LICENSE("GPL");
2630 cfs_module(osd, "0.0.2", osd_mod_init, osd_mod_exit);