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 #include <lustre_fid.h>
66 #include <linux/lustre_iam.h>
68 #include "osd_internal.h"
71 struct osd_directory {
72 struct iam_container od_container;
73 struct iam_descr od_descr;
74 struct semaphore od_sem;
78 struct dt_object oo_dt;
80 * Inode for file system object represented by this osd_object. This
81 * inode is pinned for the whole duration of lu_object life.
83 * Not modified concurrently (either setup early during object
84 * creation, or assigned by osd_object_create() under write lock).
86 struct inode *oo_inode;
87 struct rw_semaphore oo_sem;
88 struct osd_directory *oo_dir;
89 /* protects inode attributes. */
92 const struct lu_env *oo_owner;
96 static int osd_root_get (const struct lu_env *env,
97 struct dt_device *dev, struct lu_fid *f);
99 static int lu_device_is_osd (const struct lu_device *d);
100 static void osd_mod_exit (void) __exit;
101 static int osd_mod_init (void) __init;
102 static int osd_type_init (struct lu_device_type *t);
103 static void osd_type_fini (struct lu_device_type *t);
104 static int osd_object_init (const struct lu_env *env,
105 struct lu_object *l);
106 static void osd_object_release(const struct lu_env *env,
107 struct lu_object *l);
108 static int osd_object_print (const struct lu_env *env, void *cookie,
109 lu_printer_t p, const struct lu_object *o);
110 static struct lu_device *osd_device_free (const struct lu_env *env,
111 struct lu_device *m);
112 static void *osd_key_init (const struct lu_context *ctx,
113 struct lu_context_key *key);
114 static void osd_key_fini (const struct lu_context *ctx,
115 struct lu_context_key *key, void *data);
116 static void osd_key_exit (const struct lu_context *ctx,
117 struct lu_context_key *key, void *data);
118 static int osd_has_index (const struct osd_object *obj);
119 static void osd_object_init0 (struct osd_object *obj);
120 static int osd_device_init (const struct lu_env *env,
121 struct lu_device *d, const char *,
123 static int osd_fid_lookup (const struct lu_env *env,
124 struct osd_object *obj,
125 const struct lu_fid *fid);
126 static void osd_inode_getattr (const struct lu_env *env,
127 struct inode *inode, struct lu_attr *attr);
128 static void osd_inode_setattr (const struct lu_env *env,
129 struct inode *inode, const struct lu_attr *attr);
130 static int osd_param_is_sane (const struct osd_device *dev,
131 const struct txn_param *param);
132 static int osd_index_lookup (const struct lu_env *env,
133 struct dt_object *dt,
134 struct dt_rec *rec, const struct dt_key *key,
135 struct lustre_capa *capa);
136 static int osd_index_insert (const struct lu_env *env,
137 struct dt_object *dt,
138 const struct dt_rec *rec,
139 const struct dt_key *key,
140 struct thandle *handle,
141 struct lustre_capa *capa);
142 static int osd_index_delete (const struct lu_env *env,
143 struct dt_object *dt, const struct dt_key *key,
144 struct thandle *handle,
145 struct lustre_capa *capa);
146 static int osd_index_probe (const struct lu_env *env,
147 struct osd_object *o,
148 const struct dt_index_features *feat);
149 static int osd_index_try (const struct lu_env *env,
150 struct dt_object *dt,
151 const struct dt_index_features *feat);
152 static void osd_index_fini (struct osd_object *o);
154 static void osd_it_fini (const struct lu_env *env, struct dt_it *di);
155 static int osd_it_get (const struct lu_env *env,
156 struct dt_it *di, const struct dt_key *key);
157 static void osd_it_put (const struct lu_env *env, struct dt_it *di);
158 static int osd_it_next (const struct lu_env *env, struct dt_it *di);
159 static int osd_it_del (const struct lu_env *env, struct dt_it *di,
161 static int osd_it_key_size (const struct lu_env *env,
162 const struct dt_it *di);
163 static void osd_conf_get (const struct lu_env *env,
164 const struct dt_device *dev,
165 struct dt_device_param *param);
166 static void osd_trans_stop (const struct lu_env *env,
168 static int osd_object_is_root(const struct osd_object *obj);
170 static struct osd_object *osd_obj (const struct lu_object *o);
171 static struct osd_device *osd_dev (const struct lu_device *d);
172 static struct osd_device *osd_dt_dev (const struct dt_device *d);
173 static struct osd_object *osd_dt_obj (const struct dt_object *d);
174 static struct osd_device *osd_obj2dev (const struct osd_object *o);
175 static struct lu_device *osd2lu_dev (struct osd_device *osd);
176 static struct lu_device *osd_device_fini (const struct lu_env *env,
177 struct lu_device *d);
178 static struct lu_device *osd_device_alloc (const struct lu_env *env,
179 struct lu_device_type *t,
180 struct lustre_cfg *cfg);
181 static struct lu_object *osd_object_alloc (const struct lu_env *env,
182 const struct lu_object_header *hdr,
183 struct lu_device *d);
184 static struct inode *osd_iget (struct osd_thread_info *info,
185 struct osd_device *dev,
186 const struct osd_inode_id *id);
187 static struct super_block *osd_sb (const struct osd_device *dev);
188 static struct dt_it *osd_it_init (const struct lu_env *env,
189 struct dt_object *dt, int wable,
190 struct lustre_capa *capa);
191 static struct dt_key *osd_it_key (const struct lu_env *env,
192 const struct dt_it *di);
193 static struct dt_rec *osd_it_rec (const struct lu_env *env,
194 const struct dt_it *di);
195 static struct timespec *osd_inode_time (const struct lu_env *env,
198 static struct thandle *osd_trans_start (const struct lu_env *env,
200 struct txn_param *p);
201 static journal_t *osd_journal (const struct osd_device *dev);
203 static struct lu_device_type_operations osd_device_type_ops;
204 static struct lu_device_type osd_device_type;
205 static struct lu_object_operations osd_lu_obj_ops;
206 static struct obd_ops osd_obd_device_ops;
207 static struct lu_device_operations osd_lu_ops;
208 static struct lu_context_key osd_key;
209 static struct dt_object_operations osd_obj_ops;
210 static struct dt_body_operations osd_body_ops;
211 static struct dt_index_operations osd_index_ops;
212 static struct dt_index_operations osd_index_compat_ops;
215 struct thandle ot_super;
217 struct journal_callback ot_jcb;
221 * Invariants, assertions.
225 * XXX: do not enable this, until invariant checking code is made thread safe
226 * in the face of pdirops locking.
228 #define OSD_INVARIANT_CHECKS (0)
230 #if OSD_INVARIANT_CHECKS
231 static int osd_invariant(const struct osd_object *obj)
235 ergo(obj->oo_inode != NULL,
236 obj->oo_inode->i_sb == osd_sb(osd_obj2dev(obj)) &&
237 atomic_read(&obj->oo_inode->i_count) > 0) &&
238 ergo(obj->oo_dir != NULL &&
239 obj->oo_dir->od_conationer.ic_object != NULL,
240 obj->oo_dir->od_conationer.ic_object == obj->oo_inode);
243 #define osd_invariant(obj) (1)
246 static inline struct osd_thread_info *osd_oti_get(const struct lu_env *env)
248 return lu_context_key_get(&env->le_ctx, &osd_key);
253 * Concurrency: doesn't matter
255 static int osd_read_locked(const struct lu_env *env, struct osd_object *o)
257 return osd_oti_get(env)->oti_r_locks > 0;
261 * Concurrency: doesn't matter
263 static int osd_write_locked(const struct lu_env *env, struct osd_object *o)
265 struct osd_thread_info *oti = osd_oti_get(env);
266 return oti->oti_w_locks > 0 && o->oo_owner == env;
269 #define OSD_COUNTERS_DO(exp) exp
273 #define osd_read_locked(env, o) (1)
274 #define osd_write_locked(env, o) (1)
275 #define OSD_COUNTERS_DO(exp) ((void)0)
279 * Concurrency: doesn't access mutable data
281 static int osd_root_get(const struct lu_env *env,
282 struct dt_device *dev, struct lu_fid *f)
286 inode = osd_sb(osd_dt_dev(dev))->s_root->d_inode;
287 lu_igif_build(f, inode->i_ino, inode->i_generation);
292 * OSD object methods.
296 * Concurrency: no concurrent access is possible that early in object
299 static struct lu_object *osd_object_alloc(const struct lu_env *env,
300 const struct lu_object_header *hdr,
303 struct osd_object *mo;
309 l = &mo->oo_dt.do_lu;
310 dt_object_init(&mo->oo_dt, NULL, d);
311 mo->oo_dt.do_ops = &osd_obj_ops;
312 l->lo_ops = &osd_lu_obj_ops;
313 init_rwsem(&mo->oo_sem);
314 spin_lock_init(&mo->oo_guard);
321 * Concurrency: shouldn't matter.
323 static void osd_object_init0(struct osd_object *obj)
325 LASSERT(obj->oo_inode != NULL);
326 obj->oo_dt.do_body_ops = &osd_body_ops;
327 obj->oo_dt.do_lu.lo_header->loh_attr |=
328 (LOHA_EXISTS | (obj->oo_inode->i_mode & S_IFMT));
332 * Concurrency: no concurrent access is possible that early in object
335 static int osd_object_init(const struct lu_env *env, struct lu_object *l)
337 struct osd_object *obj = osd_obj(l);
340 LASSERT(osd_invariant(obj));
342 result = osd_fid_lookup(env, obj, lu_object_fid(l));
344 if (obj->oo_inode != NULL)
345 osd_object_init0(obj);
347 LASSERT(osd_invariant(obj));
352 * Concurrency: no concurrent access is possible that late in object
355 static void osd_object_free(const struct lu_env *env, struct lu_object *l)
357 struct osd_object *obj = osd_obj(l);
359 LASSERT(osd_invariant(obj));
361 dt_object_fini(&obj->oo_dt);
365 static struct iam_path_descr *osd_ipd_get(const struct lu_env *env,
366 const struct iam_container *bag)
368 return bag->ic_descr->id_ops->id_ipd_alloc(bag,
369 osd_oti_get(env)->oti_ipd);
372 static void osd_ipd_put(const struct lu_env *env,
373 const struct iam_container *bag,
374 struct iam_path_descr *ipd)
376 bag->ic_descr->id_ops->id_ipd_free(ipd);
380 * Concurrency: no concurrent access is possible that late in object
383 static void osd_index_fini(struct osd_object *o)
385 struct iam_container *bag;
387 if (o->oo_dir != NULL) {
388 bag = &o->oo_dir->od_container;
389 if (o->oo_inode != NULL) {
390 if (bag->ic_object == o->oo_inode)
391 iam_container_fini(bag);
393 OBD_FREE_PTR(o->oo_dir);
399 * Concurrency: no concurrent access is possible that late in object
400 * life-cycle (for all existing callers, that is. New callers have to provide
401 * their own locking.)
403 static int osd_inode_unlinked(const struct inode *inode)
405 return inode->i_nlink == 0;
409 OSD_TXN_OI_DELETE_CREDITS = 20,
410 OSD_TXN_INODE_DELETE_CREDITS = 20
414 * Concurrency: no concurrent access is possible that late in object
417 static int osd_inode_remove(const struct lu_env *env, struct osd_object *obj)
419 const struct lu_fid *fid = lu_object_fid(&obj->oo_dt.do_lu);
420 struct osd_device *osd = osd_obj2dev(obj);
421 struct osd_thread_info *oti = osd_oti_get(env);
422 struct txn_param *prm = &oti->oti_txn;
426 txn_param_init(prm, OSD_TXN_OI_DELETE_CREDITS +
427 OSD_TXN_INODE_DELETE_CREDITS);
428 th = osd_trans_start(env, &osd->od_dt_dev, prm);
430 result = osd_oi_delete(oti, &osd->od_oi, fid, th);
431 osd_trans_stop(env, th);
433 result = PTR_ERR(th);
438 * Called just before object is freed. Releases all resources except for
439 * object itself (that is released by osd_object_free()).
441 * Concurrency: no concurrent access is possible that late in object
444 static void osd_object_delete(const struct lu_env *env, struct lu_object *l)
446 struct osd_object *obj = osd_obj(l);
447 struct inode *inode = obj->oo_inode;
449 LASSERT(osd_invariant(obj));
452 * If object is unlinked remove fid->ino mapping from object index.
454 * File body will be deleted by iput().
461 if (osd_inode_unlinked(inode)) {
462 result = osd_inode_remove(env, obj);
464 LU_OBJECT_DEBUG(D_ERROR, env, l,
465 "Failed to cleanup: %d\n",
469 obj->oo_inode = NULL;
474 * Concurrency: ->loo_object_release() is called under site spin-lock.
476 static void osd_object_release(const struct lu_env *env,
479 struct osd_object *o = osd_obj(l);
481 LASSERT(!lu_object_is_dying(l->lo_header));
482 if (o->oo_inode != NULL && osd_inode_unlinked(o->oo_inode))
483 set_bit(LU_OBJECT_HEARD_BANSHEE, &l->lo_header->loh_flags);
487 * Concurrency: shouldn't matter.
489 static int osd_object_print(const struct lu_env *env, void *cookie,
490 lu_printer_t p, const struct lu_object *l)
492 struct osd_object *o = osd_obj(l);
495 if (o->oo_dir != NULL)
496 d = o->oo_dir->od_container.ic_descr;
499 return (*p)(env, cookie, LUSTRE_OSD_NAME"-object@%p(i:%p:%lu/%u)[%s]",
501 o->oo_inode ? o->oo_inode->i_ino : 0UL,
502 o->oo_inode ? o->oo_inode->i_generation : 0,
503 d ? d->id_ops->id_name : "plain");
507 * Concurrency: shouldn't matter.
509 int osd_statfs(const struct lu_env *env, struct dt_device *d,
512 struct osd_device *osd = osd_dt_dev(d);
513 struct super_block *sb = osd_sb(osd);
516 spin_lock(&osd->od_osfs_lock);
518 if (cfs_time_before_64(osd->od_osfs_age, cfs_time_shift_64(-1))) {
519 result = ll_do_statfs(sb, &osd->od_kstatfs);
520 if (likely(result == 0)) /* N.B. statfs can't really fail */
521 osd->od_osfs_age = cfs_time_current_64();
524 if (likely(result == 0))
525 *sfs = osd->od_kstatfs;
526 spin_unlock(&osd->od_osfs_lock);
532 * Concurrency: doesn't access mutable data.
534 static void osd_conf_get(const struct lu_env *env,
535 const struct dt_device *dev,
536 struct dt_device_param *param)
539 * XXX should be taken from not-yet-existing fs abstraction layer.
541 param->ddp_max_name_len = LDISKFS_NAME_LEN;
542 param->ddp_max_nlink = LDISKFS_LINK_MAX;
543 param->ddp_block_shift = osd_sb(osd_dt_dev(dev))->s_blocksize_bits;
551 * Concurrency: doesn't access mutable data.
553 static int osd_param_is_sane(const struct osd_device *dev,
554 const struct txn_param *param)
556 return param->tp_credits <= osd_journal(dev)->j_max_transaction_buffers;
560 * Concurrency: shouldn't matter.
562 static void osd_trans_commit_cb(struct journal_callback *jcb, int error)
564 struct osd_thandle *oh = container_of0(jcb, struct osd_thandle, ot_jcb);
565 struct thandle *th = &oh->ot_super;
566 struct dt_device *dev = th->th_dev;
568 LASSERT(dev != NULL);
569 LASSERT(oh->ot_handle == NULL);
572 CERROR("transaction @0x%p commit error: %d\n", th, error);
574 struct lu_env *env = &osd_dt_dev(dev)->od_env_for_commit;
576 * This od_env_for_commit is only for commit usage. see
579 lu_context_enter(&env->le_ctx);
580 dt_txn_hook_commit(env, th);
581 lu_context_exit(&env->le_ctx);
584 lu_device_put(&dev->dd_lu_dev);
587 lu_context_exit(&th->th_ctx);
588 lu_context_fini(&th->th_ctx);
593 * Concurrency: shouldn't matter.
595 static struct thandle *osd_trans_start(const struct lu_env *env,
599 struct osd_device *dev = osd_dt_dev(d);
601 struct osd_thandle *oh;
607 hook_res = dt_txn_hook_start(env, d, p);
609 RETURN(ERR_PTR(hook_res));
611 if (osd_param_is_sane(dev, p)) {
612 OBD_ALLOC_GFP(oh, sizeof *oh, CFS_ALLOC_IO);
615 * XXX temporary stuff. Some abstraction layer should
619 jh = journal_start(osd_journal(dev), p->tp_credits);
625 jh->h_sync = p->tp_sync;
626 lu_device_get(&d->dd_lu_dev);
627 /* add commit callback */
628 lu_context_init(&th->th_ctx, LCT_TX_HANDLE);
629 lu_context_enter(&th->th_ctx);
630 journal_callback_set(jh, osd_trans_commit_cb,
631 (struct journal_callback *)&oh->ot_jcb);
634 struct osd_thread_info *oti =
637 LASSERT(oti->oti_txns == 0);
638 LASSERT(oti->oti_r_locks == 0);
639 LASSERT(oti->oti_w_locks == 0);
648 th = ERR_PTR(-ENOMEM);
650 CERROR("Invalid transaction parameters\n");
651 th = ERR_PTR(-EINVAL);
658 * Concurrency: shouldn't matter.
660 static void osd_trans_stop(const struct lu_env *env, struct thandle *th)
663 struct osd_thandle *oh;
667 oh = container_of0(th, struct osd_thandle, ot_super);
668 if (oh->ot_handle != NULL) {
669 handle_t *hdl = oh->ot_handle;
671 * XXX temporary stuff. Some abstraction layer should be used.
673 result = dt_txn_hook_stop(env, th);
675 CERROR("Failure in transaction hook: %d\n", result);
678 oh->ot_handle = NULL;
679 result = journal_stop(hdl);
681 CERROR("Failure to stop transaction: %d\n", result);
685 struct osd_thread_info *oti = osd_oti_get(env);
687 LASSERT(oti->oti_txns == 1);
688 LASSERT(oti->oti_r_locks == 0);
689 LASSERT(oti->oti_w_locks == 0);
698 * Concurrency: shouldn't matter.
700 static int osd_sync(const struct lu_env *env, struct dt_device *d)
702 CDEBUG(D_HA, "syncing OSD %s\n", LUSTRE_OSD_NAME);
703 return ldiskfs_force_commit(osd_sb(osd_dt_dev(d)));
707 * Concurrency: shouldn't matter.
709 lvfs_sbdev_type fsfilt_ldiskfs_journal_sbdev(struct super_block *);
711 static void osd_ro(const struct lu_env *env, struct dt_device *d)
715 CERROR("*** setting device %s read-only ***\n", LUSTRE_OSD_NAME);
717 __lvfs_set_rdonly(lvfs_sbdev(osd_sb(osd_dt_dev(d))),
718 fsfilt_ldiskfs_journal_sbdev(osd_sb(osd_dt_dev(d))));
723 * Concurrency: serialization provided by callers.
725 static int osd_init_capa_ctxt(const struct lu_env *env, struct dt_device *d,
726 int mode, unsigned long timeout, __u32 alg,
727 struct lustre_capa_key *keys)
729 struct osd_device *dev = osd_dt_dev(d);
732 dev->od_fl_capa = mode;
733 dev->od_capa_timeout = timeout;
734 dev->od_capa_alg = alg;
735 dev->od_capa_keys = keys;
739 /* Note: we did not count into QUOTA here, If we mount with --data_journal
741 static const int osd_dto_credits[DTO_NR] = {
743 * Insert/Delete. IAM EXT3_INDEX_EXTRA_TRANS_BLOCKS(8) +
744 * EXT3_SINGLEDATA_TRANS_BLOCKS 8 XXX Note: maybe iam need more,since
745 * iam have more level than Ext3 htree
747 [DTO_INDEX_INSERT] = 16,
748 [DTO_INDEX_DELETE] = 16,
749 [DTO_IDNEX_UPDATE] = 16,
751 * Create a object. Same as create object in Ext3 filesystem, but did
752 * not count QUOTA i EXT3_DATA_TRANS_BLOCKS(12) +
753 * INDEX_EXTRA_BLOCKS(8) + 3(inode bits,groups, GDT)
755 [DTO_OBJECT_CREATE] = 23,
756 [DTO_OBJECT_DELETE] = 23,
758 * Attr set credits 3 inode, group, GDT
762 * XATTR_SET. SAME AS XATTR of EXT3 EXT3_DATA_TRANS_BLOCKS XXX Note:
763 * in original MDS implmentation EXT3_INDEX_EXTRA_TRANS_BLOCKS are
764 * also counted in. Do not know why?
766 [DTO_XATTR_SET] = 16,
768 /* creadits for inode change during write */
769 [DTO_WRITE_BASE] = 3,
770 /* credits for single block write */
771 [DTO_WRITE_BLOCK] = 12
774 static int osd_credit_get(const struct lu_env *env, struct dt_device *d,
777 LASSERT(0 <= op && op < ARRAY_SIZE(osd_dto_credits));
778 return osd_dto_credits[op];
781 static struct dt_device_operations osd_dt_ops = {
782 .dt_root_get = osd_root_get,
783 .dt_statfs = osd_statfs,
784 .dt_trans_start = osd_trans_start,
785 .dt_trans_stop = osd_trans_stop,
786 .dt_conf_get = osd_conf_get,
789 .dt_credit_get = osd_credit_get,
790 .dt_init_capa_ctxt = osd_init_capa_ctxt,
793 static void osd_object_read_lock(const struct lu_env *env,
794 struct dt_object *dt)
796 struct osd_object *obj = osd_dt_obj(dt);
798 LASSERT(osd_invariant(obj));
800 OSD_COUNTERS_DO(LASSERT(obj->oo_owner != env));
801 down_read(&obj->oo_sem);
804 struct osd_thread_info *oti = osd_oti_get(env);
806 LASSERT(obj->oo_owner == NULL);
812 static void osd_object_write_lock(const struct lu_env *env,
813 struct dt_object *dt)
815 struct osd_object *obj = osd_dt_obj(dt);
817 LASSERT(osd_invariant(obj));
819 OSD_COUNTERS_DO(LASSERT(obj->oo_owner != env));
820 down_write(&obj->oo_sem);
823 struct osd_thread_info *oti = osd_oti_get(env);
825 LASSERT(obj->oo_owner == NULL);
832 static void osd_object_read_unlock(const struct lu_env *env,
833 struct dt_object *dt)
835 struct osd_object *obj = osd_dt_obj(dt);
837 LASSERT(osd_invariant(obj));
840 struct osd_thread_info *oti = osd_oti_get(env);
842 LASSERT(oti->oti_r_locks > 0);
846 up_read(&obj->oo_sem);
849 static void osd_object_write_unlock(const struct lu_env *env,
850 struct dt_object *dt)
852 struct osd_object *obj = osd_dt_obj(dt);
854 LASSERT(osd_invariant(obj));
857 struct osd_thread_info *oti = osd_oti_get(env);
859 LASSERT(obj->oo_owner == env);
860 LASSERT(oti->oti_w_locks > 0);
862 obj->oo_owner = NULL;
865 up_write(&obj->oo_sem);
868 static int capa_is_sane(const struct lu_env *env,
869 struct osd_device *dev,
870 struct lustre_capa *capa,
871 struct lustre_capa_key *keys)
873 struct osd_thread_info *oti = osd_oti_get(env);
878 oc = capa_lookup(dev->od_capa_hash, capa, 0);
880 if (capa_is_expired(oc)) {
881 DEBUG_CAPA(D_ERROR, capa, "expired");
888 spin_lock(&capa_lock);
889 for (i = 0; i < 2; i++) {
890 if (keys[i].lk_keyid == capa->lc_keyid) {
891 oti->oti_capa_key = keys[i];
895 spin_unlock(&capa_lock);
898 DEBUG_CAPA(D_ERROR, capa, "no matched capa key");
902 rc = capa_hmac(oti->oti_capa.lc_hmac, capa, oti->oti_capa_key.lk_key);
905 if (memcmp(oti->oti_capa.lc_hmac, capa->lc_hmac, sizeof(capa->lc_hmac)))
907 DEBUG_CAPA(D_ERROR, capa, "HMAC mismatch");
911 oc = capa_add(dev->od_capa_hash, capa);
917 static int osd_object_auth(const struct lu_env *env, struct dt_object *dt,
918 struct lustre_capa *capa, __u64 opc)
920 const struct lu_fid *fid = lu_object_fid(&dt->do_lu);
921 struct osd_device *dev = osd_dev(dt->do_lu.lo_dev);
924 if (!dev->od_fl_capa)
927 if (capa == BYPASS_CAPA)
931 CERROR("no capability is provided for fid "DFID"\n", PFID(fid));
935 if (!lu_fid_eq(fid, &capa->lc_fid)) {
936 DEBUG_CAPA(D_ERROR, capa, "fid "DFID" mismatch with",
941 if (!capa_opc_supported(capa, opc)) {
942 DEBUG_CAPA(D_ERROR, capa, "opc "LPX64" not supported by", opc);
946 if ((rc = capa_is_sane(env, dev, capa, dev->od_capa_keys))) {
947 DEBUG_CAPA(D_ERROR, capa, "insane (rc %d)", rc);
954 static int osd_attr_get(const struct lu_env *env,
955 struct dt_object *dt,
956 struct lu_attr *attr,
957 struct lustre_capa *capa)
959 struct osd_object *obj = osd_dt_obj(dt);
961 LASSERT(dt_object_exists(dt));
962 LASSERT(osd_invariant(obj));
964 if (osd_object_auth(env, dt, capa, CAPA_OPC_META_READ))
967 spin_lock(&obj->oo_guard);
968 osd_inode_getattr(env, obj->oo_inode, attr);
969 spin_unlock(&obj->oo_guard);
973 static int osd_attr_set(const struct lu_env *env,
974 struct dt_object *dt,
975 const struct lu_attr *attr,
976 struct thandle *handle,
977 struct lustre_capa *capa)
979 struct osd_object *obj = osd_dt_obj(dt);
981 LASSERT(handle != NULL);
982 LASSERT(dt_object_exists(dt));
983 LASSERT(osd_invariant(obj));
985 if (osd_object_auth(env, dt, capa, CAPA_OPC_META_WRITE))
988 spin_lock(&obj->oo_guard);
989 osd_inode_setattr(env, obj->oo_inode, attr);
990 spin_unlock(&obj->oo_guard);
992 mark_inode_dirty(obj->oo_inode);
996 static struct timespec *osd_inode_time(const struct lu_env *env,
997 struct inode *inode, __u64 seconds)
999 struct osd_thread_info *oti = osd_oti_get(env);
1000 struct timespec *t = &oti->oti_time;
1002 t->tv_sec = seconds;
1004 *t = timespec_trunc(*t, get_sb_time_gran(inode->i_sb));
1008 static void osd_inode_setattr(const struct lu_env *env,
1009 struct inode *inode, const struct lu_attr *attr)
1013 bits = attr->la_valid;
1015 LASSERT(!(bits & LA_TYPE)); /* Huh? You want too much. */
1017 if (bits & LA_ATIME)
1018 inode->i_atime = *osd_inode_time(env, inode, attr->la_atime);
1019 if (bits & LA_CTIME)
1020 inode->i_ctime = *osd_inode_time(env, inode, attr->la_ctime);
1021 if (bits & LA_MTIME)
1022 inode->i_mtime = *osd_inode_time(env, inode, attr->la_mtime);
1023 if (bits & LA_SIZE) {
1024 LDISKFS_I(inode)->i_disksize = attr->la_size;
1025 i_size_write(inode, attr->la_size);
1027 if (bits & LA_BLOCKS)
1028 inode->i_blocks = attr->la_blocks;
1030 inode->i_mode = (inode->i_mode & S_IFMT) |
1031 (attr->la_mode & ~S_IFMT);
1033 inode->i_uid = attr->la_uid;
1035 inode->i_gid = attr->la_gid;
1036 if (bits & LA_NLINK)
1037 inode->i_nlink = attr->la_nlink;
1039 inode->i_rdev = attr->la_rdev;
1041 if (bits & LA_FLAGS) {
1042 struct ldiskfs_inode_info *li = LDISKFS_I(inode);
1044 li->i_flags = (li->i_flags & ~LDISKFS_FL_USER_MODIFIABLE) |
1045 (attr->la_flags & LDISKFS_FL_USER_MODIFIABLE);
1052 * XXX temporary solution.
1055 static int osd_create_pre(struct osd_thread_info *info, struct osd_object *obj,
1056 struct lu_attr *attr, struct thandle *th)
1061 static int osd_create_post(struct osd_thread_info *info, struct osd_object *obj,
1062 struct lu_attr *attr, struct thandle *th)
1064 LASSERT(obj->oo_inode != NULL);
1066 osd_object_init0(obj);
1070 extern struct inode *ldiskfs_create_inode(handle_t *handle,
1071 struct inode * dir, int mode);
1073 static int osd_mkfile(struct osd_thread_info *info, struct osd_object *obj,
1075 struct dt_allocation_hint *hint,
1079 struct osd_device *osd = osd_obj2dev(obj);
1080 struct osd_thandle *oth;
1081 struct inode *parent;
1082 struct inode *inode;
1084 LASSERT(osd_invariant(obj));
1085 LASSERT(obj->oo_inode == NULL);
1086 LASSERT(osd->od_obj_area != NULL);
1088 oth = container_of(th, struct osd_thandle, ot_super);
1089 LASSERT(oth->ot_handle->h_transaction != NULL);
1091 if (hint && hint->dah_parent)
1092 parent = osd_dt_obj(hint->dah_parent)->oo_inode;
1094 parent = osd->od_obj_area->d_inode;
1095 LASSERT(parent->i_op != NULL);
1097 inode = ldiskfs_create_inode(oth->ot_handle, parent, mode);
1098 if (!IS_ERR(inode)) {
1099 obj->oo_inode = inode;
1102 result = PTR_ERR(inode);
1103 LASSERT(osd_invariant(obj));
1108 extern int iam_lvar_create(struct inode *obj, int keysize, int ptrsize,
1109 int recsize, handle_t *handle);
1115 static int osd_mkdir(struct osd_thread_info *info, struct osd_object *obj,
1116 struct lu_attr *attr,
1117 struct dt_allocation_hint *hint,
1121 struct osd_thandle *oth;
1123 LASSERT(S_ISDIR(attr->la_mode));
1125 oth = container_of(th, struct osd_thandle, ot_super);
1126 LASSERT(oth->ot_handle->h_transaction != NULL);
1127 result = osd_mkfile(info, obj, (attr->la_mode &
1128 (S_IFMT | S_IRWXUGO | S_ISVTX)), hint, th);
1130 LASSERT(obj->oo_inode != NULL);
1132 * XXX uh-oh... call low-level iam function directly.
1134 result = iam_lvar_create(obj->oo_inode, OSD_NAME_LEN, 4,
1135 sizeof (struct lu_fid_pack),
1141 static int osd_mkreg(struct osd_thread_info *info, struct osd_object *obj,
1142 struct lu_attr *attr,
1143 struct dt_allocation_hint *hint,
1146 LASSERT(S_ISREG(attr->la_mode));
1147 return osd_mkfile(info, obj, (attr->la_mode &
1148 (S_IFMT | S_IRWXUGO | S_ISVTX)), hint, th);
1151 static int osd_mksym(struct osd_thread_info *info, struct osd_object *obj,
1152 struct lu_attr *attr,
1153 struct dt_allocation_hint *hint,
1156 LASSERT(S_ISLNK(attr->la_mode));
1157 return osd_mkfile(info, obj, (attr->la_mode &
1158 (S_IFMT | S_IRWXUGO | S_ISVTX)), hint, th);
1161 static int osd_mknod(struct osd_thread_info *info, struct osd_object *obj,
1162 struct lu_attr *attr,
1163 struct dt_allocation_hint *hint,
1167 struct osd_device *osd = osd_obj2dev(obj);
1169 umode_t mode = attr->la_mode & (S_IFMT | S_IRWXUGO | S_ISVTX);
1171 LASSERT(osd_invariant(obj));
1172 LASSERT(obj->oo_inode == NULL);
1173 LASSERT(osd->od_obj_area != NULL);
1174 LASSERT(S_ISCHR(mode) || S_ISBLK(mode) ||
1175 S_ISFIFO(mode) || S_ISSOCK(mode));
1177 dir = osd->od_obj_area->d_inode;
1178 LASSERT(dir->i_op != NULL);
1180 result = osd_mkfile(info, obj, mode, hint, th);
1182 LASSERT(obj->oo_inode != NULL);
1183 init_special_inode(obj->oo_inode, mode, attr->la_rdev);
1185 LASSERT(osd_invariant(obj));
1189 typedef int (*osd_obj_type_f)(struct osd_thread_info *, struct osd_object *,
1191 struct dt_allocation_hint *hint,
1194 static osd_obj_type_f osd_create_type_f(__u32 mode)
1196 osd_obj_type_f result;
1222 static void osd_ah_init(const struct lu_env *env, struct dt_allocation_hint *ah,
1223 struct dt_object *parent, umode_t child_mode)
1227 memset(ah, 0, sizeof(*ah));
1228 ah->dah_parent = parent;
1229 ah->dah_mode = child_mode;
1234 * Concurrency: @dt is write locked.
1236 static int osd_object_create(const struct lu_env *env, struct dt_object *dt,
1237 struct lu_attr *attr,
1238 struct dt_allocation_hint *hint,
1241 const struct lu_fid *fid = lu_object_fid(&dt->do_lu);
1242 struct osd_object *obj = osd_dt_obj(dt);
1243 struct osd_device *osd = osd_obj2dev(obj);
1244 struct osd_thread_info *info = osd_oti_get(env);
1249 LASSERT(osd_invariant(obj));
1250 LASSERT(!dt_object_exists(dt));
1251 LASSERT(osd_write_locked(env, obj));
1252 LASSERT(th != NULL);
1255 * XXX missing: Quote handling.
1258 result = osd_create_pre(info, obj, attr, th);
1260 result = osd_create_type_f(attr->la_mode & S_IFMT)(info, obj,
1263 result = osd_create_post(info, obj, attr, th);
1266 struct osd_inode_id *id = &info->oti_id;
1268 LASSERT(obj->oo_inode != NULL);
1270 id->oii_ino = obj->oo_inode->i_ino;
1271 id->oii_gen = obj->oo_inode->i_generation;
1273 result = osd_oi_insert(info, &osd->od_oi, fid, id, th);
1276 LASSERT(ergo(result == 0, dt_object_exists(dt)));
1277 LASSERT(osd_invariant(obj));
1282 * Concurrency: @dt is write locked.
1284 static void osd_object_ref_add(const struct lu_env *env,
1285 struct dt_object *dt,
1288 struct osd_object *obj = osd_dt_obj(dt);
1289 struct inode *inode = obj->oo_inode;
1291 LASSERT(osd_invariant(obj));
1292 LASSERT(dt_object_exists(dt));
1293 LASSERT(osd_write_locked(env, obj));
1294 LASSERT(th != NULL);
1296 spin_lock(&obj->oo_guard);
1297 LASSERT(inode->i_nlink < LDISKFS_LINK_MAX);
1299 spin_unlock(&obj->oo_guard);
1300 mark_inode_dirty(inode);
1301 LASSERT(osd_invariant(obj));
1305 * Concurrency: @dt is write locked.
1307 static void osd_object_ref_del(const struct lu_env *env,
1308 struct dt_object *dt,
1311 struct osd_object *obj = osd_dt_obj(dt);
1312 struct inode *inode = obj->oo_inode;
1314 LASSERT(osd_invariant(obj));
1315 LASSERT(dt_object_exists(dt));
1316 LASSERT(osd_write_locked(env, obj));
1317 LASSERT(th != NULL);
1319 spin_lock(&obj->oo_guard);
1320 LASSERT(inode->i_nlink > 0);
1322 spin_unlock(&obj->oo_guard);
1323 mark_inode_dirty(inode);
1324 LASSERT(osd_invariant(obj));
1328 * Concurrency: @dt is read locked.
1330 static int osd_xattr_get(const struct lu_env *env,
1331 struct dt_object *dt,
1334 struct lustre_capa *capa)
1336 struct osd_object *obj = osd_dt_obj(dt);
1337 struct inode *inode = obj->oo_inode;
1338 struct osd_thread_info *info = osd_oti_get(env);
1339 struct dentry *dentry = &info->oti_dentry;
1341 LASSERT(dt_object_exists(dt));
1342 LASSERT(inode->i_op != NULL && inode->i_op->getxattr != NULL);
1343 LASSERT(osd_read_locked(env, obj) || osd_write_locked(env, obj));
1345 if (osd_object_auth(env, dt, capa, CAPA_OPC_META_READ))
1348 dentry->d_inode = inode;
1349 return inode->i_op->getxattr(dentry, name, buf->lb_buf, buf->lb_len);
1353 * Concurrency: @dt is write locked.
1355 static int osd_xattr_set(const struct lu_env *env, struct dt_object *dt,
1356 const struct lu_buf *buf, const char *name, int fl,
1357 struct thandle *handle, struct lustre_capa *capa)
1359 struct osd_object *obj = osd_dt_obj(dt);
1360 struct inode *inode = obj->oo_inode;
1361 struct osd_thread_info *info = osd_oti_get(env);
1362 struct dentry *dentry = &info->oti_dentry;
1363 struct timespec *t = &info->oti_time;
1364 int fs_flags = 0, rc;
1366 LASSERT(dt_object_exists(dt));
1367 LASSERT(inode->i_op != NULL && inode->i_op->setxattr != NULL);
1368 LASSERT(osd_write_locked(env, obj));
1369 LASSERT(handle != NULL);
1371 if (osd_object_auth(env, dt, capa, CAPA_OPC_META_WRITE))
1374 if (fl & LU_XATTR_REPLACE)
1375 fs_flags |= XATTR_REPLACE;
1377 if (fl & LU_XATTR_CREATE)
1378 fs_flags |= XATTR_CREATE;
1380 dentry->d_inode = inode;
1381 *t = inode->i_ctime;
1382 rc = inode->i_op->setxattr(dentry, name,
1383 buf->lb_buf, buf->lb_len, fs_flags);
1384 if (likely(rc == 0)) {
1385 /* ctime should not be updated with server-side time. */
1386 spin_lock(&obj->oo_guard);
1387 inode->i_ctime = *t;
1388 spin_unlock(&obj->oo_guard);
1389 mark_inode_dirty(inode);
1395 * Concurrency: @dt is read locked.
1397 static int osd_xattr_list(const struct lu_env *env,
1398 struct dt_object *dt,
1400 struct lustre_capa *capa)
1402 struct osd_object *obj = osd_dt_obj(dt);
1403 struct inode *inode = obj->oo_inode;
1404 struct osd_thread_info *info = osd_oti_get(env);
1405 struct dentry *dentry = &info->oti_dentry;
1407 LASSERT(dt_object_exists(dt));
1408 LASSERT(inode->i_op != NULL && inode->i_op->listxattr != NULL);
1409 LASSERT(osd_read_locked(env, obj) || osd_write_locked(env, obj));
1411 if (osd_object_auth(env, dt, capa, CAPA_OPC_META_READ))
1414 dentry->d_inode = inode;
1415 return inode->i_op->listxattr(dentry, buf->lb_buf, buf->lb_len);
1419 * Concurrency: @dt is write locked.
1421 static int osd_xattr_del(const struct lu_env *env,
1422 struct dt_object *dt,
1424 struct thandle *handle,
1425 struct lustre_capa *capa)
1427 struct osd_object *obj = osd_dt_obj(dt);
1428 struct inode *inode = obj->oo_inode;
1429 struct osd_thread_info *info = osd_oti_get(env);
1430 struct dentry *dentry = &info->oti_dentry;
1431 struct timespec *t = &info->oti_time;
1434 LASSERT(dt_object_exists(dt));
1435 LASSERT(inode->i_op != NULL && inode->i_op->removexattr != NULL);
1436 LASSERT(osd_write_locked(env, obj));
1437 LASSERT(handle != NULL);
1439 if (osd_object_auth(env, dt, capa, CAPA_OPC_META_WRITE))
1442 dentry->d_inode = inode;
1443 *t = inode->i_ctime;
1444 rc = inode->i_op->removexattr(dentry, name);
1445 if (likely(rc == 0)) {
1446 /* ctime should not be updated with server-side time. */
1447 spin_lock(&obj->oo_guard);
1448 inode->i_ctime = *t;
1449 spin_unlock(&obj->oo_guard);
1450 mark_inode_dirty(inode);
1455 static struct obd_capa *osd_capa_get(const struct lu_env *env,
1456 struct dt_object *dt,
1457 struct lustre_capa *old,
1460 struct osd_thread_info *info = osd_oti_get(env);
1461 const struct lu_fid *fid = lu_object_fid(&dt->do_lu);
1462 struct osd_object *obj = osd_dt_obj(dt);
1463 struct osd_device *dev = osd_obj2dev(obj);
1464 struct lustre_capa_key *key = &info->oti_capa_key;
1465 struct lustre_capa *capa = &info->oti_capa;
1466 struct obd_capa *oc;
1470 if (!dev->od_fl_capa)
1471 RETURN(ERR_PTR(-ENOENT));
1473 LASSERT(dt_object_exists(dt));
1474 LASSERT(osd_invariant(obj));
1476 /* renewal sanity check */
1477 if (old && osd_object_auth(env, dt, old, opc))
1478 RETURN(ERR_PTR(-EACCES));
1480 capa->lc_fid = *fid;
1483 capa->lc_flags = dev->od_capa_alg << 24;
1484 capa->lc_timeout = dev->od_capa_timeout;
1485 capa->lc_expiry = 0;
1487 oc = capa_lookup(dev->od_capa_hash, capa, 1);
1489 LASSERT(!capa_is_expired(oc));
1493 spin_lock(&capa_lock);
1494 *key = dev->od_capa_keys[1];
1495 spin_unlock(&capa_lock);
1497 capa->lc_keyid = key->lk_keyid;
1498 capa->lc_expiry = cfs_time_current_sec() + dev->od_capa_timeout;
1500 rc = capa_hmac(capa->lc_hmac, capa, key->lk_key);
1502 DEBUG_CAPA(D_ERROR, capa, "HMAC failed: %d for", rc);
1503 RETURN(ERR_PTR(rc));
1506 oc = capa_add(dev->od_capa_hash, capa);
1510 static struct dt_object_operations osd_obj_ops = {
1511 .do_read_lock = osd_object_read_lock,
1512 .do_write_lock = osd_object_write_lock,
1513 .do_read_unlock = osd_object_read_unlock,
1514 .do_write_unlock = osd_object_write_unlock,
1515 .do_attr_get = osd_attr_get,
1516 .do_attr_set = osd_attr_set,
1517 .do_ah_init = osd_ah_init,
1518 .do_create = osd_object_create,
1519 .do_index_try = osd_index_try,
1520 .do_ref_add = osd_object_ref_add,
1521 .do_ref_del = osd_object_ref_del,
1522 .do_xattr_get = osd_xattr_get,
1523 .do_xattr_set = osd_xattr_set,
1524 .do_xattr_del = osd_xattr_del,
1525 .do_xattr_list = osd_xattr_list,
1526 .do_capa_get = osd_capa_get,
1534 * XXX: Another layering violation for now.
1536 * We don't want to use ->f_op->read methods, because generic file write
1538 * - serializes on ->i_sem, and
1540 * - does a lot of extra work like balance_dirty_pages(),
1542 * which doesn't work for globally shared files like /last-received.
1544 int fsfilt_ldiskfs_read(struct inode *inode, void *buf, int size, loff_t *offs);
1545 int fsfilt_ldiskfs_write_handle(struct inode *inode, void *buf, int bufsize,
1546 loff_t *offs, handle_t *handle);
1548 static ssize_t osd_read(const struct lu_env *env, struct dt_object *dt,
1549 struct lu_buf *buf, loff_t *pos,
1550 struct lustre_capa *capa)
1552 struct inode *inode = osd_dt_obj(dt)->oo_inode;
1554 if (osd_object_auth(env, dt, capa, CAPA_OPC_BODY_READ))
1557 return fsfilt_ldiskfs_read(inode, buf->lb_buf, buf->lb_len, pos);
1560 static ssize_t osd_write(const struct lu_env *env, struct dt_object *dt,
1561 const struct lu_buf *buf, loff_t *pos,
1562 struct thandle *handle, struct lustre_capa *capa)
1564 struct inode *inode = osd_dt_obj(dt)->oo_inode;
1565 struct osd_thandle *oh;
1568 LASSERT(handle != NULL);
1570 if (osd_object_auth(env, dt, capa, CAPA_OPC_BODY_WRITE))
1573 oh = container_of(handle, struct osd_thandle, ot_super);
1574 LASSERT(oh->ot_handle->h_transaction != NULL);
1575 result = fsfilt_ldiskfs_write_handle(inode, buf->lb_buf, buf->lb_len,
1576 pos, oh->ot_handle);
1578 result = buf->lb_len;
1582 static struct dt_body_operations osd_body_ops = {
1583 .dbo_read = osd_read,
1584 .dbo_write = osd_write
1591 static int osd_object_is_root(const struct osd_object *obj)
1593 return osd_sb(osd_obj2dev(obj))->s_root->d_inode == obj->oo_inode;
1596 static int osd_index_probe(const struct lu_env *env, struct osd_object *o,
1597 const struct dt_index_features *feat)
1599 struct iam_descr *descr;
1601 if (osd_object_is_root(o))
1602 return feat == &dt_directory_features;
1604 LASSERT(o->oo_dir != NULL);
1606 descr = o->oo_dir->od_container.ic_descr;
1607 if (feat == &dt_directory_features)
1608 return descr == &iam_htree_compat_param ||
1609 (descr->id_rec_size == sizeof(struct lu_fid_pack) &&
1611 * XXX check that index looks like directory.
1616 feat->dif_keysize_min <= descr->id_key_size &&
1617 descr->id_key_size <= feat->dif_keysize_max &&
1618 feat->dif_recsize_min <= descr->id_rec_size &&
1619 descr->id_rec_size <= feat->dif_recsize_max &&
1620 !(feat->dif_flags & (DT_IND_VARKEY |
1621 DT_IND_VARREC | DT_IND_NONUNQ)) &&
1622 ergo(feat->dif_flags & DT_IND_UPDATE,
1623 1 /* XXX check that object (and file system) is
1627 static int osd_container_init(const struct lu_env *env,
1628 struct osd_object *obj,
1629 struct osd_directory *dir)
1632 struct iam_container *bag;
1634 bag = &dir->od_container;
1635 result = iam_container_init(bag, &dir->od_descr, obj->oo_inode);
1637 result = iam_container_setup(bag);
1639 obj->oo_dt.do_index_ops = &osd_index_ops;
1641 iam_container_fini(bag);
1647 * Concurrency: no external locking is necessary.
1649 static int osd_index_try(const struct lu_env *env, struct dt_object *dt,
1650 const struct dt_index_features *feat)
1653 struct osd_object *obj = osd_dt_obj(dt);
1655 LASSERT(osd_invariant(obj));
1656 LASSERT(dt_object_exists(dt));
1658 if (osd_object_is_root(obj)) {
1659 dt->do_index_ops = &osd_index_compat_ops;
1661 } else if (!osd_has_index(obj)) {
1662 struct osd_directory *dir;
1666 sema_init(&dir->od_sem, 1);
1668 spin_lock(&obj->oo_guard);
1669 if (obj->oo_dir == NULL)
1673 * Concurrent thread allocated container data.
1676 spin_unlock(&obj->oo_guard);
1678 * Now, that we have container data, serialize its
1681 down(&obj->oo_dir->od_sem);
1683 * recheck under lock.
1685 if (!osd_has_index(obj))
1686 result = osd_container_init(env, obj, dir);
1689 up(&obj->oo_dir->od_sem);
1696 if (!osd_index_probe(env, obj, feat))
1699 LASSERT(osd_invariant(obj));
1704 static int osd_index_delete(const struct lu_env *env, struct dt_object *dt,
1705 const struct dt_key *key, struct thandle *handle,
1706 struct lustre_capa *capa)
1708 struct osd_object *obj = osd_dt_obj(dt);
1709 struct osd_thandle *oh;
1710 struct iam_path_descr *ipd;
1711 struct iam_container *bag = &obj->oo_dir->od_container;
1716 LASSERT(osd_invariant(obj));
1717 LASSERT(dt_object_exists(dt));
1718 LASSERT(bag->ic_object == obj->oo_inode);
1719 LASSERT(handle != NULL);
1721 if (osd_object_auth(env, dt, capa, CAPA_OPC_INDEX_DELETE))
1724 ipd = osd_ipd_get(env, bag);
1725 if (unlikely(ipd == NULL))
1728 oh = container_of0(handle, struct osd_thandle, ot_super);
1729 LASSERT(oh->ot_handle != NULL);
1730 LASSERT(oh->ot_handle->h_transaction != NULL);
1732 rc = iam_delete(oh->ot_handle, bag, (const struct iam_key *)key, ipd);
1733 osd_ipd_put(env, bag, ipd);
1734 LASSERT(osd_invariant(obj));
1738 static int osd_index_lookup(const struct lu_env *env, struct dt_object *dt,
1739 struct dt_rec *rec, const struct dt_key *key,
1740 struct lustre_capa *capa)
1742 struct osd_object *obj = osd_dt_obj(dt);
1743 struct iam_path_descr *ipd;
1744 struct iam_container *bag = &obj->oo_dir->od_container;
1749 LASSERT(osd_invariant(obj));
1750 LASSERT(dt_object_exists(dt));
1751 LASSERT(bag->ic_object == obj->oo_inode);
1753 if (osd_object_auth(env, dt, capa, CAPA_OPC_INDEX_LOOKUP))
1756 ipd = osd_ipd_get(env, bag);
1757 if (unlikely(ipd == NULL))
1760 rc = iam_lookup(bag, (const struct iam_key *)key,
1761 (struct iam_rec *)rec, ipd);
1762 osd_ipd_put(env, bag, ipd);
1763 LASSERT(osd_invariant(obj));
1768 static int osd_index_insert(const struct lu_env *env, struct dt_object *dt,
1769 const struct dt_rec *rec, const struct dt_key *key,
1770 struct thandle *th, struct lustre_capa *capa)
1772 struct osd_object *obj = osd_dt_obj(dt);
1773 struct iam_path_descr *ipd;
1774 struct osd_thandle *oh;
1775 struct iam_container *bag = &obj->oo_dir->od_container;
1780 LASSERT(osd_invariant(obj));
1781 LASSERT(dt_object_exists(dt));
1782 LASSERT(bag->ic_object == obj->oo_inode);
1783 LASSERT(th != NULL);
1785 if (osd_object_auth(env, dt, capa, CAPA_OPC_INDEX_INSERT))
1788 ipd = osd_ipd_get(env, bag);
1789 if (unlikely(ipd == NULL))
1792 oh = container_of0(th, struct osd_thandle, ot_super);
1793 LASSERT(oh->ot_handle != NULL);
1794 LASSERT(oh->ot_handle->h_transaction != NULL);
1795 rc = iam_insert(oh->ot_handle, 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 * Iterator operations.
1806 struct osd_object *oi_obj;
1807 struct iam_path_descr *oi_ipd;
1808 struct iam_iterator oi_it;
1811 static struct dt_it *osd_it_init(const struct lu_env *env,
1812 struct dt_object *dt, int writable,
1813 struct lustre_capa *capa)
1816 struct osd_object *obj = osd_dt_obj(dt);
1817 struct lu_object *lo = &dt->do_lu;
1818 struct iam_path_descr *ipd;
1819 struct iam_container *bag = &obj->oo_dir->od_container;
1822 LASSERT(lu_object_exists(lo));
1824 if (osd_object_auth(env, dt, capa, writable ? CAPA_OPC_BODY_WRITE :
1825 CAPA_OPC_BODY_READ))
1826 return ERR_PTR(-EACCES);
1828 flags = writable ? IAM_IT_MOVE|IAM_IT_WRITE : IAM_IT_MOVE;
1832 * XXX: as ipd is allocated within osd_thread_info, assignment
1833 * below implies that iterator usage is confined within single
1836 ipd = osd_ipd_get(env, bag);
1837 if (likely(ipd != NULL)) {
1841 iam_it_init(&it->oi_it, bag, flags, ipd);
1842 return (struct dt_it *)it;
1846 return ERR_PTR(-ENOMEM);
1849 static void osd_it_fini(const struct lu_env *env, struct dt_it *di)
1851 struct osd_it *it = (struct osd_it *)di;
1852 struct osd_object *obj = it->oi_obj;
1854 iam_it_fini(&it->oi_it);
1855 osd_ipd_put(env, &obj->oo_dir->od_container, it->oi_ipd);
1856 lu_object_put(env, &obj->oo_dt.do_lu);
1860 static int osd_it_get(const struct lu_env *env,
1861 struct dt_it *di, const struct dt_key *key)
1863 struct osd_it *it = (struct osd_it *)di;
1865 return iam_it_get(&it->oi_it, (const struct iam_key *)key);
1868 static void osd_it_put(const struct lu_env *env, struct dt_it *di)
1870 struct osd_it *it = (struct osd_it *)di;
1872 iam_it_put(&it->oi_it);
1875 static int osd_it_next(const struct lu_env *env, struct dt_it *di)
1877 struct osd_it *it = (struct osd_it *)di;
1879 return iam_it_next(&it->oi_it);
1882 static int osd_it_del(const struct lu_env *env, struct dt_it *di,
1885 struct osd_it *it = (struct osd_it *)di;
1886 struct osd_thandle *oh;
1888 LASSERT(th != NULL);
1890 oh = container_of0(th, struct osd_thandle, ot_super);
1891 LASSERT(oh->ot_handle != NULL);
1892 LASSERT(oh->ot_handle->h_transaction != NULL);
1894 return iam_it_rec_delete(oh->ot_handle, &it->oi_it);
1897 static struct dt_key *osd_it_key(const struct lu_env *env,
1898 const struct dt_it *di)
1900 struct osd_it *it = (struct osd_it *)di;
1902 return (struct dt_key *)iam_it_key_get(&it->oi_it);
1905 static int osd_it_key_size(const struct lu_env *env, const struct dt_it *di)
1907 struct osd_it *it = (struct osd_it *)di;
1909 return iam_it_key_size(&it->oi_it);
1912 static struct dt_rec *osd_it_rec(const struct lu_env *env,
1913 const struct dt_it *di)
1915 struct osd_it *it = (struct osd_it *)di;
1917 return (struct dt_rec *)iam_it_rec_get(&it->oi_it);
1920 static __u64 osd_it_store(const struct lu_env *env, const struct dt_it *di)
1922 struct osd_it *it = (struct osd_it *)di;
1924 return iam_it_store(&it->oi_it);
1927 static int osd_it_load(const struct lu_env *env,
1928 const struct dt_it *di, __u64 hash)
1930 struct osd_it *it = (struct osd_it *)di;
1932 return iam_it_load(&it->oi_it, hash);
1935 static struct dt_index_operations osd_index_ops = {
1936 .dio_lookup = osd_index_lookup,
1937 .dio_insert = osd_index_insert,
1938 .dio_delete = osd_index_delete,
1940 .init = osd_it_init,
1941 .fini = osd_it_fini,
1945 .next = osd_it_next,
1947 .key_size = osd_it_key_size,
1949 .store = osd_it_store,
1954 static int osd_index_compat_delete(const struct lu_env *env,
1955 struct dt_object *dt,
1956 const struct dt_key *key,
1957 struct thandle *handle,
1958 struct lustre_capa *capa)
1960 struct osd_object *obj = osd_dt_obj(dt);
1962 LASSERT(handle != NULL);
1963 LASSERT(S_ISDIR(obj->oo_inode->i_mode));
1967 if (osd_object_auth(env, dt, capa, CAPA_OPC_INDEX_DELETE))
1971 RETURN(-EOPNOTSUPP);
1975 * Compatibility index operations.
1979 static void osd_build_pack(const struct lu_env *env, struct osd_device *osd,
1980 struct dentry *dentry, struct lu_fid_pack *pack)
1982 struct inode *inode = dentry->d_inode;
1983 struct lu_fid *fid = &osd_oti_get(env)->oti_fid;
1985 lu_igif_build(fid, inode->i_ino, inode->i_generation);
1986 fid_cpu_to_be(fid, fid);
1987 pack->fp_len = sizeof *fid + 1;
1988 memcpy(pack->fp_area, fid, sizeof *fid);
1991 static int osd_index_compat_lookup(const struct lu_env *env,
1992 struct dt_object *dt,
1993 struct dt_rec *rec, const struct dt_key *key,
1994 struct lustre_capa *capa)
1996 struct osd_object *obj = osd_dt_obj(dt);
1998 struct osd_device *osd = osd_obj2dev(obj);
1999 struct osd_thread_info *info = osd_oti_get(env);
2005 * XXX temporary solution.
2007 struct dentry *dentry;
2008 struct dentry *parent;
2010 LASSERT(osd_invariant(obj));
2011 LASSERT(S_ISDIR(obj->oo_inode->i_mode));
2012 LASSERT(osd_has_index(obj));
2014 if (osd_object_auth(env, dt, capa, CAPA_OPC_INDEX_LOOKUP))
2017 info->oti_str.name = (const char *)key;
2018 info->oti_str.len = strlen((const char *)key);
2020 dir = obj->oo_inode;
2021 LASSERT(dir->i_op != NULL && dir->i_op->lookup != NULL);
2023 parent = d_alloc_root(dir);
2027 dentry = d_alloc(parent, &info->oti_str);
2028 if (dentry != NULL) {
2032 * XXX passing NULL for nameidata should work for
2035 d = dir->i_op->lookup(dir, dentry, NULL);
2038 * normal case, result is in @dentry.
2040 if (dentry->d_inode != NULL) {
2041 osd_build_pack(env, osd, dentry,
2042 (struct lu_fid_pack *)rec);
2047 /* What? Disconnected alias? Ppheeeww... */
2048 CERROR("Aliasing where not expected\n");
2056 LASSERT(osd_invariant(obj));
2060 static int osd_add_rec(struct osd_thread_info *info, struct osd_device *dev,
2061 struct inode *dir, struct inode *inode, const char *name)
2065 struct dentry *parent;
2069 info->oti_str.name = name;
2070 info->oti_str.len = strlen(name);
2072 LASSERT(atomic_read(&dir->i_count) > 0);
2074 old = d_alloc(dev->od_obj_area, &info->oti_str);
2076 d_instantiate(old, inode);
2078 LASSERT(atomic_read(&dir->i_count) > 0);
2079 parent = d_alloc_root(dir);
2080 if (parent != NULL) {
2082 LASSERT(atomic_read(&dir->i_count) > 1);
2083 new = d_alloc(parent, &info->oti_str);
2084 LASSERT(atomic_read(&dir->i_count) > 1);
2086 LASSERT(atomic_read(&dir->i_count) > 1);
2087 result = dir->i_op->link(old, dir, new);
2088 LASSERT(atomic_read(&dir->i_count) > 1);
2090 LASSERT(atomic_read(&dir->i_count) > 1);
2092 LASSERT(atomic_read(&dir->i_count) > 1);
2094 LASSERT(atomic_read(&dir->i_count) > 0);
2098 LASSERT(atomic_read(&dir->i_count) > 0);
2104 * XXX Temporary stuff.
2106 static int osd_index_compat_insert(const struct lu_env *env,
2107 struct dt_object *dt,
2108 const struct dt_rec *rec,
2109 const struct dt_key *key, struct thandle *th,
2110 struct lustre_capa *capa)
2112 struct osd_object *obj = osd_dt_obj(dt);
2114 const char *name = (const char *)key;
2116 struct lu_device *ludev = dt->do_lu.lo_dev;
2117 struct lu_object *luch;
2119 struct osd_thread_info *info = osd_oti_get(env);
2120 const struct lu_fid_pack *pack = (const struct lu_fid_pack *)rec;
2121 struct lu_fid *fid = &osd_oti_get(env)->oti_fid;
2125 LASSERT(S_ISDIR(obj->oo_inode->i_mode));
2126 LASSERT(osd_invariant(obj));
2127 LASSERT(th != NULL);
2129 if (osd_object_auth(env, dt, capa, CAPA_OPC_INDEX_INSERT))
2132 result = fid_unpack(pack, fid);
2136 luch = lu_object_find(env, ludev->ld_site, fid);
2137 if (!IS_ERR(luch)) {
2138 if (lu_object_exists(luch)) {
2139 struct osd_object *child;
2141 child = osd_obj(lu_object_locate(luch->lo_header,
2144 result = osd_add_rec(info, osd_obj2dev(obj),
2146 child->oo_inode, name);
2148 CERROR("No osd slice.\n");
2151 LASSERT(osd_invariant(obj));
2152 LASSERT(osd_invariant(child));
2157 lu_object_put(env, luch);
2159 result = PTR_ERR(luch);
2160 LASSERT(osd_invariant(obj));
2164 static struct dt_index_operations osd_index_compat_ops = {
2165 .dio_lookup = osd_index_compat_lookup,
2166 .dio_insert = osd_index_compat_insert,
2167 .dio_delete = osd_index_compat_delete
2170 /* type constructor/destructor: osd_type_init, osd_type_fini */
2171 LU_TYPE_INIT_FINI(osd, &osd_key);
2173 static struct lu_context_key osd_key = {
2174 .lct_tags = LCT_DT_THREAD | LCT_MD_THREAD,
2175 .lct_init = osd_key_init,
2176 .lct_fini = osd_key_fini,
2177 .lct_exit = osd_key_exit
2180 static void *osd_key_init(const struct lu_context *ctx,
2181 struct lu_context_key *key)
2183 struct osd_thread_info *info;
2185 OBD_ALLOC_PTR(info);
2187 info->oti_env = container_of(ctx, struct lu_env, le_ctx);
2189 info = ERR_PTR(-ENOMEM);
2193 /* context key destructor: osd_key_fini */
2194 LU_KEY_FINI(osd, struct osd_thread_info);
2196 static void osd_key_exit(const struct lu_context *ctx,
2197 struct lu_context_key *key, void *data)
2200 struct osd_thread_info *info = data;
2202 LASSERT(info->oti_r_locks == 0);
2203 LASSERT(info->oti_w_locks == 0);
2204 LASSERT(info->oti_txns == 0);
2208 static int osd_device_init(const struct lu_env *env, struct lu_device *d,
2209 const char *name, struct lu_device *next)
2212 /* context for commit hooks */
2213 rc = lu_context_init(&osd_dev(d)->od_env_for_commit.le_ctx,
2216 rc = osd_procfs_init(osd_dev(d), name);
2220 static int osd_shutdown(const struct lu_env *env, struct osd_device *o)
2222 struct osd_thread_info *info = osd_oti_get(env);
2224 if (o->od_obj_area != NULL) {
2225 dput(o->od_obj_area);
2226 o->od_obj_area = NULL;
2228 osd_oi_fini(info, &o->od_oi);
2233 static int osd_mount(const struct lu_env *env,
2234 struct osd_device *o, struct lustre_cfg *cfg)
2236 struct lustre_mount_info *lmi;
2237 const char *dev = lustre_cfg_string(cfg, 0);
2238 struct osd_thread_info *info = osd_oti_get(env);
2243 if (o->od_mount != NULL) {
2244 CERROR("Already mounted (%s)\n", dev);
2249 lmi = server_get_mount(dev);
2251 CERROR("Cannot get mount info for %s!\n", dev);
2255 LASSERT(lmi != NULL);
2256 /* save lustre_mount_info in dt_device */
2259 result = osd_oi_init(info, &o->od_oi, &o->od_dt_dev);
2263 d = simple_mkdir(osd_sb(o)->s_root, "*OBJ-TEMP*", 0777, 1);
2267 result = PTR_ERR(d);
2270 osd_shutdown(env, o);
2274 static struct lu_device *osd_device_fini(const struct lu_env *env,
2275 struct lu_device *d)
2280 shrink_dcache_sb(osd_sb(osd_dev(d)));
2281 osd_sync(env, lu2dt_dev(d));
2283 rc = osd_procfs_fini(osd_dev(d));
2285 CERROR("proc fini error %d \n", rc);
2286 RETURN (ERR_PTR(rc));
2289 if (osd_dev(d)->od_mount)
2290 server_put_mount(osd_dev(d)->od_mount->lmi_name,
2291 osd_dev(d)->od_mount->lmi_mnt);
2292 osd_dev(d)->od_mount = NULL;
2294 lu_context_fini(&osd_dev(d)->od_env_for_commit.le_ctx);
2298 static struct lu_device *osd_device_alloc(const struct lu_env *env,
2299 struct lu_device_type *t,
2300 struct lustre_cfg *cfg)
2302 struct lu_device *l;
2303 struct osd_device *o;
2309 result = dt_device_init(&o->od_dt_dev, t);
2312 l->ld_ops = &osd_lu_ops;
2313 o->od_dt_dev.dd_ops = &osd_dt_ops;
2314 spin_lock_init(&o->od_osfs_lock);
2315 o->od_osfs_age = cfs_time_shift_64(-1000);
2316 o->od_capa_hash = init_capa_hash();
2317 if (o->od_capa_hash == NULL)
2318 l = ERR_PTR(-ENOMEM);
2320 l = ERR_PTR(result);
2322 l = ERR_PTR(-ENOMEM);
2326 static struct lu_device *osd_device_free(const struct lu_env *env,
2327 struct lu_device *d)
2329 struct osd_device *o = osd_dev(d);
2332 cleanup_capa_hash(o->od_capa_hash);
2333 dt_device_fini(&o->od_dt_dev);
2338 static int osd_process_config(const struct lu_env *env,
2339 struct lu_device *d, struct lustre_cfg *cfg)
2341 struct osd_device *o = osd_dev(d);
2345 switch(cfg->lcfg_command) {
2347 err = osd_mount(env, o, cfg);
2350 err = osd_shutdown(env, o);
2358 extern void ldiskfs_orphan_cleanup (struct super_block * sb,
2359 struct ldiskfs_super_block * es);
2361 static int osd_recovery_complete(const struct lu_env *env,
2362 struct lu_device *d)
2364 struct osd_device *o = osd_dev(d);
2366 /* TODO: orphans handling */
2367 ldiskfs_orphan_cleanup(osd_sb(o), LDISKFS_SB(osd_sb(o))->s_es);
2371 static struct inode *osd_iget(struct osd_thread_info *info,
2372 struct osd_device *dev,
2373 const struct osd_inode_id *id)
2375 struct inode *inode;
2377 inode = iget(osd_sb(dev), id->oii_ino);
2378 if (inode == NULL) {
2379 CERROR("no inode\n");
2380 inode = ERR_PTR(-EACCES);
2381 } else if (is_bad_inode(inode)) {
2382 CERROR("bad inode\n");
2384 inode = ERR_PTR(-ENOENT);
2385 } else if (inode->i_generation != id->oii_gen) {
2386 CERROR("stale inode\n");
2388 inode = ERR_PTR(-ESTALE);
2395 static int osd_fid_lookup(const struct lu_env *env,
2396 struct osd_object *obj, const struct lu_fid *fid)
2398 struct osd_thread_info *info;
2399 struct lu_device *ldev = obj->oo_dt.do_lu.lo_dev;
2400 struct osd_device *dev;
2401 struct osd_inode_id *id;
2403 struct inode *inode;
2406 LASSERT(osd_invariant(obj));
2407 LASSERT(obj->oo_inode == NULL);
2408 LASSERT(fid_is_sane(fid));
2410 * This assertion checks that osd layer sees only local
2411 * fids. Unfortunately it is somewhat expensive (does a
2412 * cache-lookup). Disabling it for production/acceptance-testing.
2414 LASSERT(1 || fid_is_local(ldev->ld_site, fid));
2418 info = osd_oti_get(env);
2419 dev = osd_dev(ldev);
2423 if (OBD_FAIL_CHECK(OBD_FAIL_OST_ENOENT))
2426 result = osd_oi_lookup(info, oi, fid, id);
2428 inode = osd_iget(info, dev, id);
2429 if (!IS_ERR(inode)) {
2430 obj->oo_inode = inode;
2431 LASSERT(obj->oo_inode->i_sb == osd_sb(dev));
2435 * If fid wasn't found in oi, inode-less object is
2436 * created, for which lu_object_exists() returns
2437 * false. This is used in a (frequent) case when
2438 * objects are created as locking anchors or
2439 * place holders for objects yet to be created.
2441 result = PTR_ERR(inode);
2442 } else if (result == -ENOENT)
2444 LASSERT(osd_invariant(obj));
2448 static void osd_inode_getattr(const struct lu_env *env,
2449 struct inode *inode, struct lu_attr *attr)
2451 attr->la_valid |= LA_ATIME | LA_MTIME | LA_CTIME | LA_MODE |
2452 LA_SIZE | LA_BLOCKS | LA_UID | LA_GID |
2453 LA_FLAGS | LA_NLINK | LA_RDEV | LA_BLKSIZE;
2455 attr->la_atime = LTIME_S(inode->i_atime);
2456 attr->la_mtime = LTIME_S(inode->i_mtime);
2457 attr->la_ctime = LTIME_S(inode->i_ctime);
2458 attr->la_mode = inode->i_mode;
2459 attr->la_size = i_size_read(inode);
2460 attr->la_blocks = inode->i_blocks;
2461 attr->la_uid = inode->i_uid;
2462 attr->la_gid = inode->i_gid;
2463 attr->la_flags = LDISKFS_I(inode)->i_flags;
2464 attr->la_nlink = inode->i_nlink;
2465 attr->la_rdev = inode->i_rdev;
2466 attr->la_blksize = ll_inode_blksize(inode);
2467 attr->la_blkbits = inode->i_blkbits;
2474 static int lu_device_is_osd(const struct lu_device *d)
2476 return ergo(d != NULL && d->ld_ops != NULL, d->ld_ops == &osd_lu_ops);
2479 static struct osd_object *osd_obj(const struct lu_object *o)
2481 LASSERT(lu_device_is_osd(o->lo_dev));
2482 return container_of0(o, struct osd_object, oo_dt.do_lu);
2485 static struct osd_device *osd_dt_dev(const struct dt_device *d)
2487 LASSERT(lu_device_is_osd(&d->dd_lu_dev));
2488 return container_of0(d, struct osd_device, od_dt_dev);
2491 static struct osd_device *osd_dev(const struct lu_device *d)
2493 LASSERT(lu_device_is_osd(d));
2494 return osd_dt_dev(container_of0(d, struct dt_device, dd_lu_dev));
2497 static struct osd_object *osd_dt_obj(const struct dt_object *d)
2499 return osd_obj(&d->do_lu);
2502 static struct osd_device *osd_obj2dev(const struct osd_object *o)
2504 return osd_dev(o->oo_dt.do_lu.lo_dev);
2507 static struct lu_device *osd2lu_dev(struct osd_device *osd)
2509 return &osd->od_dt_dev.dd_lu_dev;
2512 static struct super_block *osd_sb(const struct osd_device *dev)
2514 return dev->od_mount->lmi_mnt->mnt_sb;
2517 static journal_t *osd_journal(const struct osd_device *dev)
2519 return LDISKFS_SB(osd_sb(dev))->s_journal;
2522 static int osd_has_index(const struct osd_object *obj)
2524 return obj->oo_dt.do_index_ops != NULL;
2527 static int osd_object_invariant(const struct lu_object *l)
2529 return osd_invariant(osd_obj(l));
2532 static struct lu_object_operations osd_lu_obj_ops = {
2533 .loo_object_init = osd_object_init,
2534 .loo_object_delete = osd_object_delete,
2535 .loo_object_release = osd_object_release,
2536 .loo_object_free = osd_object_free,
2537 .loo_object_print = osd_object_print,
2538 .loo_object_invariant = osd_object_invariant
2541 static struct lu_device_operations osd_lu_ops = {
2542 .ldo_object_alloc = osd_object_alloc,
2543 .ldo_process_config = osd_process_config,
2544 .ldo_recovery_complete = osd_recovery_complete
2547 static struct lu_device_type_operations osd_device_type_ops = {
2548 .ldto_init = osd_type_init,
2549 .ldto_fini = osd_type_fini,
2551 .ldto_device_alloc = osd_device_alloc,
2552 .ldto_device_free = osd_device_free,
2554 .ldto_device_init = osd_device_init,
2555 .ldto_device_fini = osd_device_fini
2558 static struct lu_device_type osd_device_type = {
2559 .ldt_tags = LU_DEVICE_DT,
2560 .ldt_name = LUSTRE_OSD_NAME,
2561 .ldt_ops = &osd_device_type_ops,
2562 .ldt_ctx_tags = LCT_MD_THREAD|LCT_DT_THREAD
2566 * lprocfs legacy support.
2568 static struct obd_ops osd_obd_device_ops = {
2569 .o_owner = THIS_MODULE
2572 static int __init osd_mod_init(void)
2574 struct lprocfs_static_vars lvars;
2576 lprocfs_osd_init_vars(&lvars);
2577 return class_register_type(&osd_obd_device_ops, NULL, lvars.module_vars,
2578 LUSTRE_OSD_NAME, &osd_device_type);
2581 static void __exit osd_mod_exit(void)
2583 class_unregister_type(LUSTRE_OSD_NAME);
2586 MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
2587 MODULE_DESCRIPTION("Lustre Object Storage Device ("LUSTRE_OSD_NAME")");
2588 MODULE_LICENSE("GPL");
2590 cfs_module(osd, "0.0.2", osd_mod_init, osd_mod_exit);