1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 only,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License version 2 for more details (a copy is included
16 * in the LICENSE file that accompanied this code).
18 * You should have received a copy of the GNU General Public License
19 * version 2 along with this program; If not, see
20 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
29 * Copyright 2008 Sun Microsystems, Inc. All rights reserved
30 * Use is subject to license terms.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * lustre/osd/osd_handler.c
38 * Top-level entry points into osd module
40 * Author: Nikita Danilov <nikita@clusterfs.com>
44 # define EXPORT_SYMTAB
46 #define DEBUG_SUBSYSTEM S_MDS
48 #include <linux/module.h>
50 /* LUSTRE_VERSION_CODE */
51 #include <lustre_ver.h>
52 /* prerequisite for linux/xattr.h */
53 #include <linux/types.h>
54 /* prerequisite for linux/xattr.h */
56 /* XATTR_{REPLACE,CREATE} */
57 #include <linux/xattr.h>
59 * XXX temporary stuff: direct access to ldiskfs/jdb. Interface between osd
60 * and file system is not yet specified.
62 /* handle_t, journal_start(), journal_stop() */
63 #include <linux/jbd.h>
65 #include <linux/ldiskfs_fs.h>
66 #include <linux/ldiskfs_jbd.h>
71 * struct OBD_{ALLOC,FREE}*()
74 #include <obd_support.h>
75 /* struct ptlrpc_thread */
76 #include <lustre_net.h>
79 #include <lustre_fid.h>
80 #include <linux/lustre_iam.h>
82 #include "osd_internal.h"
85 struct osd_directory {
86 struct iam_container od_container;
87 struct iam_descr od_descr;
88 struct semaphore od_sem;
92 struct dt_object oo_dt;
94 * Inode for file system object represented by this osd_object. This
95 * inode is pinned for the whole duration of lu_object life.
97 * Not modified concurrently (either setup early during object
98 * creation, or assigned by osd_object_create() under write lock).
100 struct inode *oo_inode;
101 struct rw_semaphore oo_sem;
102 struct osd_directory *oo_dir;
103 /* protects inode attributes. */
106 const struct lu_env *oo_owner;
110 static int osd_root_get (const struct lu_env *env,
111 struct dt_device *dev, struct lu_fid *f);
113 static int lu_device_is_osd (const struct lu_device *d);
114 static void osd_mod_exit (void) __exit;
115 static int osd_mod_init (void) __init;
116 static int osd_type_init (struct lu_device_type *t);
117 static void osd_type_fini (struct lu_device_type *t);
118 static int osd_object_init (const struct lu_env *env,
119 struct lu_object *l);
120 static void osd_object_release(const struct lu_env *env,
121 struct lu_object *l);
122 static int osd_object_print (const struct lu_env *env, void *cookie,
123 lu_printer_t p, const struct lu_object *o);
124 static struct lu_device *osd_device_free (const struct lu_env *env,
125 struct lu_device *m);
126 static void *osd_key_init (const struct lu_context *ctx,
127 struct lu_context_key *key);
128 static void osd_key_fini (const struct lu_context *ctx,
129 struct lu_context_key *key, void *data);
130 static void osd_key_exit (const struct lu_context *ctx,
131 struct lu_context_key *key, void *data);
132 static int osd_has_index (const struct osd_object *obj);
133 static void osd_object_init0 (struct osd_object *obj);
134 static int osd_device_init (const struct lu_env *env,
135 struct lu_device *d, const char *,
137 static int osd_fid_lookup (const struct lu_env *env,
138 struct osd_object *obj,
139 const struct lu_fid *fid);
140 static void osd_inode_getattr (const struct lu_env *env,
141 struct inode *inode, struct lu_attr *attr);
142 static void osd_inode_setattr (const struct lu_env *env,
143 struct inode *inode, const struct lu_attr *attr);
144 static int osd_param_is_sane (const struct osd_device *dev,
145 const struct txn_param *param);
146 static int osd_index_lookup (const struct lu_env *env,
147 struct dt_object *dt,
148 struct dt_rec *rec, const struct dt_key *key,
149 struct lustre_capa *capa);
150 static int osd_index_insert (const struct lu_env *env,
151 struct dt_object *dt,
152 const struct dt_rec *rec,
153 const struct dt_key *key,
154 struct thandle *handle,
155 struct lustre_capa *capa);
156 static int osd_index_delete (const struct lu_env *env,
157 struct dt_object *dt, const struct dt_key *key,
158 struct thandle *handle,
159 struct lustre_capa *capa);
160 static int osd_index_probe (const struct lu_env *env,
161 struct osd_object *o,
162 const struct dt_index_features *feat);
163 static int osd_index_try (const struct lu_env *env,
164 struct dt_object *dt,
165 const struct dt_index_features *feat);
166 static void osd_index_fini (struct osd_object *o);
168 static void osd_it_fini (const struct lu_env *env, struct dt_it *di);
169 static int osd_it_get (const struct lu_env *env,
170 struct dt_it *di, const struct dt_key *key);
171 static void osd_it_put (const struct lu_env *env, struct dt_it *di);
172 static int osd_it_next (const struct lu_env *env, struct dt_it *di);
173 static int osd_it_del (const struct lu_env *env, struct dt_it *di,
175 static int osd_it_key_size (const struct lu_env *env,
176 const struct dt_it *di);
177 static void osd_conf_get (const struct lu_env *env,
178 const struct dt_device *dev,
179 struct dt_device_param *param);
180 static void osd_trans_stop (const struct lu_env *env,
182 static int osd_object_is_root(const struct osd_object *obj);
184 static struct osd_object *osd_obj (const struct lu_object *o);
185 static struct osd_device *osd_dev (const struct lu_device *d);
186 static struct osd_device *osd_dt_dev (const struct dt_device *d);
187 static struct osd_object *osd_dt_obj (const struct dt_object *d);
188 static struct osd_device *osd_obj2dev (const struct osd_object *o);
189 static struct lu_device *osd2lu_dev (struct osd_device *osd);
190 static struct lu_device *osd_device_fini (const struct lu_env *env,
191 struct lu_device *d);
192 static struct lu_device *osd_device_alloc (const struct lu_env *env,
193 struct lu_device_type *t,
194 struct lustre_cfg *cfg);
195 static struct lu_object *osd_object_alloc (const struct lu_env *env,
196 const struct lu_object_header *hdr,
197 struct lu_device *d);
198 static struct inode *osd_iget (struct osd_thread_info *info,
199 struct osd_device *dev,
200 const struct osd_inode_id *id);
201 static struct super_block *osd_sb (const struct osd_device *dev);
202 static struct dt_it *osd_it_init (const struct lu_env *env,
203 struct dt_object *dt, int wable,
204 struct lustre_capa *capa);
205 static struct dt_key *osd_it_key (const struct lu_env *env,
206 const struct dt_it *di);
207 static struct dt_rec *osd_it_rec (const struct lu_env *env,
208 const struct dt_it *di);
209 static struct timespec *osd_inode_time (const struct lu_env *env,
212 static struct thandle *osd_trans_start (const struct lu_env *env,
214 struct txn_param *p);
215 static journal_t *osd_journal (const struct osd_device *dev);
217 static struct lu_device_type_operations osd_device_type_ops;
218 static struct lu_device_type osd_device_type;
219 static struct lu_object_operations osd_lu_obj_ops;
220 static struct obd_ops osd_obd_device_ops;
221 static struct lu_device_operations osd_lu_ops;
222 static struct lu_context_key osd_key;
223 static struct dt_object_operations osd_obj_ops;
224 static struct dt_body_operations osd_body_ops;
225 static struct dt_index_operations osd_index_ops;
226 static struct dt_index_operations osd_index_compat_ops;
229 struct thandle ot_super;
231 struct journal_callback ot_jcb;
235 * Invariants, assertions.
239 * XXX: do not enable this, until invariant checking code is made thread safe
240 * in the face of pdirops locking.
242 #define OSD_INVARIANT_CHECKS (0)
244 #if OSD_INVARIANT_CHECKS
245 static int osd_invariant(const struct osd_object *obj)
249 ergo(obj->oo_inode != NULL,
250 obj->oo_inode->i_sb == osd_sb(osd_obj2dev(obj)) &&
251 atomic_read(&obj->oo_inode->i_count) > 0) &&
252 ergo(obj->oo_dir != NULL &&
253 obj->oo_dir->od_conationer.ic_object != NULL,
254 obj->oo_dir->od_conationer.ic_object == obj->oo_inode);
257 #define osd_invariant(obj) (1)
260 static inline struct osd_thread_info *osd_oti_get(const struct lu_env *env)
262 return lu_context_key_get(&env->le_ctx, &osd_key);
266 * Concurrency: doesn't matter
268 static int osd_read_locked(const struct lu_env *env, struct osd_object *o)
270 return osd_oti_get(env)->oti_r_locks > 0;
274 * Concurrency: doesn't matter
276 static int osd_write_locked(const struct lu_env *env, struct osd_object *o)
278 struct osd_thread_info *oti = osd_oti_get(env);
279 return oti->oti_w_locks > 0 && o->oo_owner == env;
283 * Concurrency: doesn't access mutable data
285 static int osd_root_get(const struct lu_env *env,
286 struct dt_device *dev, struct lu_fid *f)
290 inode = osd_sb(osd_dt_dev(dev))->s_root->d_inode;
291 lu_igif_build(f, inode->i_ino, inode->i_generation);
296 * OSD object methods.
300 * Concurrency: no concurrent access is possible that early in object
303 static struct lu_object *osd_object_alloc(const struct lu_env *env,
304 const struct lu_object_header *hdr,
307 struct osd_object *mo;
313 l = &mo->oo_dt.do_lu;
314 dt_object_init(&mo->oo_dt, NULL, d);
315 mo->oo_dt.do_ops = &osd_obj_ops;
316 l->lo_ops = &osd_lu_obj_ops;
317 init_rwsem(&mo->oo_sem);
318 spin_lock_init(&mo->oo_guard);
325 * Concurrency: shouldn't matter.
327 static void osd_object_init0(struct osd_object *obj)
329 LASSERT(obj->oo_inode != NULL);
330 obj->oo_dt.do_body_ops = &osd_body_ops;
331 obj->oo_dt.do_lu.lo_header->loh_attr |=
332 (LOHA_EXISTS | (obj->oo_inode->i_mode & S_IFMT));
336 * Concurrency: no concurrent access is possible that early in object
339 static int osd_object_init(const struct lu_env *env, struct lu_object *l)
341 struct osd_object *obj = osd_obj(l);
344 LASSERT(osd_invariant(obj));
346 result = osd_fid_lookup(env, obj, lu_object_fid(l));
348 if (obj->oo_inode != NULL)
349 osd_object_init0(obj);
351 LASSERT(osd_invariant(obj));
356 * Concurrency: no concurrent access is possible that late in object
359 static void osd_object_free(const struct lu_env *env, struct lu_object *l)
361 struct osd_object *obj = osd_obj(l);
363 LASSERT(osd_invariant(obj));
365 dt_object_fini(&obj->oo_dt);
369 static struct iam_path_descr *osd_ipd_get(const struct lu_env *env,
370 const struct iam_container *bag)
372 return bag->ic_descr->id_ops->id_ipd_alloc(bag,
373 osd_oti_get(env)->oti_ipd);
376 static void osd_ipd_put(const struct lu_env *env,
377 const struct iam_container *bag,
378 struct iam_path_descr *ipd)
380 bag->ic_descr->id_ops->id_ipd_free(ipd);
384 * Concurrency: no concurrent access is possible that late in object
387 static void osd_index_fini(struct osd_object *o)
389 struct iam_container *bag;
391 if (o->oo_dir != NULL) {
392 bag = &o->oo_dir->od_container;
393 if (o->oo_inode != NULL) {
394 if (bag->ic_object == o->oo_inode)
395 iam_container_fini(bag);
397 OBD_FREE_PTR(o->oo_dir);
403 * Concurrency: no concurrent access is possible that late in object
404 * life-cycle (for all existing callers, that is. New callers have to provide
405 * their own locking.)
407 static int osd_inode_unlinked(const struct inode *inode)
409 return inode->i_nlink == 0;
413 OSD_TXN_OI_DELETE_CREDITS = 20,
414 OSD_TXN_INODE_DELETE_CREDITS = 20
418 * Concurrency: no concurrent access is possible that late in object
421 static int osd_inode_remove(const struct lu_env *env, struct osd_object *obj)
423 const struct lu_fid *fid = lu_object_fid(&obj->oo_dt.do_lu);
424 struct osd_device *osd = osd_obj2dev(obj);
425 struct osd_thread_info *oti = osd_oti_get(env);
426 struct txn_param *prm = &oti->oti_txn;
430 txn_param_init(prm, OSD_TXN_OI_DELETE_CREDITS +
431 OSD_TXN_INODE_DELETE_CREDITS);
432 th = osd_trans_start(env, &osd->od_dt_dev, prm);
434 result = osd_oi_delete(oti, &osd->od_oi, fid, th);
435 osd_trans_stop(env, th);
437 result = PTR_ERR(th);
442 * Called just before object is freed. Releases all resources except for
443 * object itself (that is released by osd_object_free()).
445 * Concurrency: no concurrent access is possible that late in object
448 static void osd_object_delete(const struct lu_env *env, struct lu_object *l)
450 struct osd_object *obj = osd_obj(l);
451 struct inode *inode = obj->oo_inode;
453 LASSERT(osd_invariant(obj));
456 * If object is unlinked remove fid->ino mapping from object index.
458 * File body will be deleted by iput().
465 if (osd_inode_unlinked(inode)) {
466 result = osd_inode_remove(env, obj);
468 LU_OBJECT_DEBUG(D_ERROR, env, l,
469 "Failed to cleanup: %d\n",
473 obj->oo_inode = NULL;
478 * Concurrency: ->loo_object_release() is called under site spin-lock.
480 static void osd_object_release(const struct lu_env *env,
483 struct osd_object *o = osd_obj(l);
485 LASSERT(!lu_object_is_dying(l->lo_header));
486 if (o->oo_inode != NULL && osd_inode_unlinked(o->oo_inode))
487 set_bit(LU_OBJECT_HEARD_BANSHEE, &l->lo_header->loh_flags);
491 * Concurrency: shouldn't matter.
493 static int osd_object_print(const struct lu_env *env, void *cookie,
494 lu_printer_t p, const struct lu_object *l)
496 struct osd_object *o = osd_obj(l);
499 if (o->oo_dir != NULL)
500 d = o->oo_dir->od_container.ic_descr;
503 return (*p)(env, cookie, LUSTRE_OSD_NAME"-object@%p(i:%p:%lu/%u)[%s]",
505 o->oo_inode ? o->oo_inode->i_ino : 0UL,
506 o->oo_inode ? o->oo_inode->i_generation : 0,
507 d ? d->id_ops->id_name : "plain");
511 * Concurrency: shouldn't matter.
513 int osd_statfs(const struct lu_env *env, struct dt_device *d,
516 struct osd_device *osd = osd_dt_dev(d);
517 struct super_block *sb = osd_sb(osd);
520 spin_lock(&osd->od_osfs_lock);
522 if (cfs_time_before_64(osd->od_osfs_age, cfs_time_shift_64(-1))) {
523 result = ll_do_statfs(sb, &osd->od_kstatfs);
524 if (likely(result == 0)) /* N.B. statfs can't really fail */
525 osd->od_osfs_age = cfs_time_current_64();
528 if (likely(result == 0))
529 *sfs = osd->od_kstatfs;
530 spin_unlock(&osd->od_osfs_lock);
536 * Concurrency: doesn't access mutable data.
538 static void osd_conf_get(const struct lu_env *env,
539 const struct dt_device *dev,
540 struct dt_device_param *param)
543 * XXX should be taken from not-yet-existing fs abstraction layer.
545 param->ddp_max_name_len = LDISKFS_NAME_LEN;
546 param->ddp_max_nlink = LDISKFS_LINK_MAX;
547 param->ddp_block_shift = osd_sb(osd_dt_dev(dev))->s_blocksize_bits;
555 * Concurrency: doesn't access mutable data.
557 static int osd_param_is_sane(const struct osd_device *dev,
558 const struct txn_param *param)
560 return param->tp_credits <= osd_journal(dev)->j_max_transaction_buffers;
564 * Concurrency: shouldn't matter.
566 static void osd_trans_commit_cb(struct journal_callback *jcb, int error)
568 struct osd_thandle *oh = container_of0(jcb, struct osd_thandle, ot_jcb);
569 struct thandle *th = &oh->ot_super;
570 struct dt_device *dev = th->th_dev;
572 LASSERT(dev != NULL);
573 LASSERT(oh->ot_handle == NULL);
576 CERROR("transaction @0x%p commit error: %d\n", th, error);
578 struct lu_env *env = &osd_dt_dev(dev)->od_env_for_commit;
580 * This od_env_for_commit is only for commit usage. see
583 lu_context_enter(&env->le_ctx);
584 dt_txn_hook_commit(env, th);
585 lu_context_exit(&env->le_ctx);
588 lu_device_put(&dev->dd_lu_dev);
591 lu_context_exit(&th->th_ctx);
592 lu_context_fini(&th->th_ctx);
597 * Concurrency: shouldn't matter.
599 static struct thandle *osd_trans_start(const struct lu_env *env,
603 struct osd_device *dev = osd_dt_dev(d);
605 struct osd_thandle *oh;
611 hook_res = dt_txn_hook_start(env, d, p);
613 RETURN(ERR_PTR(hook_res));
615 if (osd_param_is_sane(dev, p)) {
616 OBD_ALLOC_GFP(oh, sizeof *oh, CFS_ALLOC_IO);
619 * XXX temporary stuff. Some abstraction layer should
623 jh = journal_start(osd_journal(dev), p->tp_credits);
629 jh->h_sync = p->tp_sync;
630 lu_device_get(&d->dd_lu_dev);
631 /* add commit callback */
632 lu_context_init(&th->th_ctx, LCT_TX_HANDLE);
633 lu_context_enter(&th->th_ctx);
634 journal_callback_set(jh, osd_trans_commit_cb,
635 (struct journal_callback *)&oh->ot_jcb);
638 struct osd_thread_info *oti =
641 LASSERT(oti->oti_txns == 0);
642 LASSERT(oti->oti_r_locks == 0);
643 LASSERT(oti->oti_w_locks == 0);
652 th = ERR_PTR(-ENOMEM);
654 CERROR("Invalid transaction parameters\n");
655 th = ERR_PTR(-EINVAL);
662 * Concurrency: shouldn't matter.
664 static void osd_trans_stop(const struct lu_env *env, struct thandle *th)
667 struct osd_thandle *oh;
668 struct osd_thread_info *oti = osd_oti_get(env);
672 oh = container_of0(th, struct osd_thandle, ot_super);
673 if (oh->ot_handle != NULL) {
674 handle_t *hdl = oh->ot_handle;
676 LASSERT(oti->oti_txns == 1);
678 LASSERT(oti->oti_r_locks == 0);
679 LASSERT(oti->oti_w_locks == 0);
680 result = dt_txn_hook_stop(env, th);
682 CERROR("Failure in transaction hook: %d\n", result);
683 oh->ot_handle = NULL;
684 result = journal_stop(hdl);
686 CERROR("Failure to stop transaction: %d\n", result);
692 * Concurrency: shouldn't matter.
694 static int osd_sync(const struct lu_env *env, struct dt_device *d)
696 CDEBUG(D_HA, "syncing OSD %s\n", LUSTRE_OSD_NAME);
697 return ldiskfs_force_commit(osd_sb(osd_dt_dev(d)));
701 * Concurrency: shouldn't matter.
703 lvfs_sbdev_type fsfilt_ldiskfs_journal_sbdev(struct super_block *);
705 static void osd_ro(const struct lu_env *env, struct dt_device *d)
709 CERROR("*** setting device %s read-only ***\n", LUSTRE_OSD_NAME);
711 __lvfs_set_rdonly(lvfs_sbdev(osd_sb(osd_dt_dev(d))),
712 fsfilt_ldiskfs_journal_sbdev(osd_sb(osd_dt_dev(d))));
717 * Concurrency: serialization provided by callers.
719 static int osd_init_capa_ctxt(const struct lu_env *env, struct dt_device *d,
720 int mode, unsigned long timeout, __u32 alg,
721 struct lustre_capa_key *keys)
723 struct osd_device *dev = osd_dt_dev(d);
726 dev->od_fl_capa = mode;
727 dev->od_capa_timeout = timeout;
728 dev->od_capa_alg = alg;
729 dev->od_capa_keys = keys;
733 /* Note: we did not count into QUOTA here, If we mount with --data_journal
735 static const int osd_dto_credits[DTO_NR] = {
737 * Insert/Delete. IAM EXT3_INDEX_EXTRA_TRANS_BLOCKS(8) +
738 * EXT3_SINGLEDATA_TRANS_BLOCKS 8 XXX Note: maybe iam need more,since
739 * iam have more level than Ext3 htree
741 [DTO_INDEX_INSERT] = 16,
742 [DTO_INDEX_DELETE] = 16,
743 [DTO_IDNEX_UPDATE] = 16,
745 * Create a object. Same as create object in Ext3 filesystem, but did
746 * not count QUOTA i EXT3_DATA_TRANS_BLOCKS(12) +
747 * INDEX_EXTRA_BLOCKS(8) + 3(inode bits,groups, GDT)
749 [DTO_OBJECT_CREATE] = 23,
750 [DTO_OBJECT_DELETE] = 23,
752 * Attr set credits 3 inode, group, GDT
756 * XATTR_SET. SAME AS XATTR of EXT3 EXT3_DATA_TRANS_BLOCKS XXX Note:
757 * in original MDS implmentation EXT3_INDEX_EXTRA_TRANS_BLOCKS are
758 * also counted in. Do not know why?
760 [DTO_XATTR_SET] = 16,
762 /* creadits for inode change during write */
763 [DTO_WRITE_BASE] = 3,
764 /* credits for single block write */
765 [DTO_WRITE_BLOCK] = 12
768 static int osd_credit_get(const struct lu_env *env, struct dt_device *d,
771 LASSERT(0 <= op && op < ARRAY_SIZE(osd_dto_credits));
772 return osd_dto_credits[op];
775 static struct dt_device_operations osd_dt_ops = {
776 .dt_root_get = osd_root_get,
777 .dt_statfs = osd_statfs,
778 .dt_trans_start = osd_trans_start,
779 .dt_trans_stop = osd_trans_stop,
780 .dt_conf_get = osd_conf_get,
783 .dt_credit_get = osd_credit_get,
784 .dt_init_capa_ctxt = osd_init_capa_ctxt,
787 static void osd_object_read_lock(const struct lu_env *env,
788 struct dt_object *dt)
790 struct osd_object *obj = osd_dt_obj(dt);
792 LASSERT(osd_invariant(obj));
794 OSD_COUNTERS_DO(LASSERT(obj->oo_owner != env));
795 down_read(&obj->oo_sem);
798 struct osd_thread_info *oti = osd_oti_get(env);
800 LASSERT(obj->oo_owner == NULL);
806 static void osd_object_write_lock(const struct lu_env *env,
807 struct dt_object *dt)
809 struct osd_object *obj = osd_dt_obj(dt);
811 LASSERT(osd_invariant(obj));
813 OSD_COUNTERS_DO(LASSERT(obj->oo_owner != env));
814 down_write(&obj->oo_sem);
817 struct osd_thread_info *oti = osd_oti_get(env);
819 LASSERT(obj->oo_owner == NULL);
826 static void osd_object_read_unlock(const struct lu_env *env,
827 struct dt_object *dt)
829 struct osd_object *obj = osd_dt_obj(dt);
831 LASSERT(osd_invariant(obj));
834 struct osd_thread_info *oti = osd_oti_get(env);
836 LASSERT(oti->oti_r_locks > 0);
840 up_read(&obj->oo_sem);
843 static void osd_object_write_unlock(const struct lu_env *env,
844 struct dt_object *dt)
846 struct osd_object *obj = osd_dt_obj(dt);
848 LASSERT(osd_invariant(obj));
851 struct osd_thread_info *oti = osd_oti_get(env);
853 LASSERT(obj->oo_owner == env);
854 LASSERT(oti->oti_w_locks > 0);
856 obj->oo_owner = NULL;
859 up_write(&obj->oo_sem);
862 static int capa_is_sane(const struct lu_env *env,
863 struct osd_device *dev,
864 struct lustre_capa *capa,
865 struct lustre_capa_key *keys)
867 struct osd_thread_info *oti = osd_oti_get(env);
872 oc = capa_lookup(dev->od_capa_hash, capa, 0);
874 if (capa_is_expired(oc)) {
875 DEBUG_CAPA(D_ERROR, capa, "expired");
882 spin_lock(&capa_lock);
883 for (i = 0; i < 2; i++) {
884 if (keys[i].lk_keyid == capa->lc_keyid) {
885 oti->oti_capa_key = keys[i];
889 spin_unlock(&capa_lock);
892 DEBUG_CAPA(D_ERROR, capa, "no matched capa key");
896 rc = capa_hmac(oti->oti_capa.lc_hmac, capa, oti->oti_capa_key.lk_key);
899 if (memcmp(oti->oti_capa.lc_hmac, capa->lc_hmac, sizeof(capa->lc_hmac)))
901 DEBUG_CAPA(D_ERROR, capa, "HMAC mismatch");
905 oc = capa_add(dev->od_capa_hash, capa);
911 static int osd_object_auth(const struct lu_env *env, struct dt_object *dt,
912 struct lustre_capa *capa, __u64 opc)
914 const struct lu_fid *fid = lu_object_fid(&dt->do_lu);
915 struct osd_device *dev = osd_dev(dt->do_lu.lo_dev);
918 if (!dev->od_fl_capa)
921 if (capa == BYPASS_CAPA)
925 CERROR("no capability is provided for fid "DFID"\n", PFID(fid));
929 if (!lu_fid_eq(fid, &capa->lc_fid)) {
930 DEBUG_CAPA(D_ERROR, capa, "fid "DFID" mismatch with",
935 if (!capa_opc_supported(capa, opc)) {
936 DEBUG_CAPA(D_ERROR, capa, "opc "LPX64" not supported by", opc);
940 if ((rc = capa_is_sane(env, dev, capa, dev->od_capa_keys))) {
941 DEBUG_CAPA(D_ERROR, capa, "insane (rc %d)", rc);
948 static int osd_attr_get(const struct lu_env *env,
949 struct dt_object *dt,
950 struct lu_attr *attr,
951 struct lustre_capa *capa)
953 struct osd_object *obj = osd_dt_obj(dt);
955 LASSERT(dt_object_exists(dt));
956 LASSERT(osd_invariant(obj));
958 if (osd_object_auth(env, dt, capa, CAPA_OPC_META_READ))
961 spin_lock(&obj->oo_guard);
962 osd_inode_getattr(env, obj->oo_inode, attr);
963 spin_unlock(&obj->oo_guard);
967 static int osd_attr_set(const struct lu_env *env,
968 struct dt_object *dt,
969 const struct lu_attr *attr,
970 struct thandle *handle,
971 struct lustre_capa *capa)
973 struct osd_object *obj = osd_dt_obj(dt);
975 LASSERT(handle != NULL);
976 LASSERT(dt_object_exists(dt));
977 LASSERT(osd_invariant(obj));
979 if (osd_object_auth(env, dt, capa, CAPA_OPC_META_WRITE))
982 spin_lock(&obj->oo_guard);
983 osd_inode_setattr(env, obj->oo_inode, attr);
984 spin_unlock(&obj->oo_guard);
986 mark_inode_dirty(obj->oo_inode);
990 static struct timespec *osd_inode_time(const struct lu_env *env,
991 struct inode *inode, __u64 seconds)
993 struct osd_thread_info *oti = osd_oti_get(env);
994 struct timespec *t = &oti->oti_time;
998 *t = timespec_trunc(*t, get_sb_time_gran(inode->i_sb));
1002 static void osd_inode_setattr(const struct lu_env *env,
1003 struct inode *inode, const struct lu_attr *attr)
1007 bits = attr->la_valid;
1009 LASSERT(!(bits & LA_TYPE)); /* Huh? You want too much. */
1011 if (bits & LA_ATIME)
1012 inode->i_atime = *osd_inode_time(env, inode, attr->la_atime);
1013 if (bits & LA_CTIME)
1014 inode->i_ctime = *osd_inode_time(env, inode, attr->la_ctime);
1015 if (bits & LA_MTIME)
1016 inode->i_mtime = *osd_inode_time(env, inode, attr->la_mtime);
1017 if (bits & LA_SIZE) {
1018 LDISKFS_I(inode)->i_disksize = attr->la_size;
1019 i_size_write(inode, attr->la_size);
1021 if (bits & LA_BLOCKS)
1022 inode->i_blocks = attr->la_blocks;
1024 inode->i_mode = (inode->i_mode & S_IFMT) |
1025 (attr->la_mode & ~S_IFMT);
1027 inode->i_uid = attr->la_uid;
1029 inode->i_gid = attr->la_gid;
1030 if (bits & LA_NLINK)
1031 inode->i_nlink = attr->la_nlink;
1033 inode->i_rdev = attr->la_rdev;
1035 if (bits & LA_FLAGS) {
1036 struct ldiskfs_inode_info *li = LDISKFS_I(inode);
1038 li->i_flags = (li->i_flags & ~LDISKFS_FL_USER_MODIFIABLE) |
1039 (attr->la_flags & LDISKFS_FL_USER_MODIFIABLE);
1046 * XXX temporary solution.
1049 static int osd_create_pre(struct osd_thread_info *info, struct osd_object *obj,
1050 struct lu_attr *attr, struct thandle *th)
1055 static int osd_create_post(struct osd_thread_info *info, struct osd_object *obj,
1056 struct lu_attr *attr, struct thandle *th)
1058 LASSERT(obj->oo_inode != NULL);
1060 osd_object_init0(obj);
1064 extern struct inode *ldiskfs_create_inode(handle_t *handle,
1065 struct inode * dir, int mode);
1067 static int osd_mkfile(struct osd_thread_info *info, struct osd_object *obj,
1069 struct dt_allocation_hint *hint,
1073 struct osd_device *osd = osd_obj2dev(obj);
1074 struct osd_thandle *oth;
1075 struct inode *parent;
1076 struct inode *inode;
1078 LASSERT(osd_invariant(obj));
1079 LASSERT(obj->oo_inode == NULL);
1080 LASSERT(osd->od_obj_area != NULL);
1082 oth = container_of(th, struct osd_thandle, ot_super);
1083 LASSERT(oth->ot_handle->h_transaction != NULL);
1085 if (hint && hint->dah_parent)
1086 parent = osd_dt_obj(hint->dah_parent)->oo_inode;
1088 parent = osd->od_obj_area->d_inode;
1089 LASSERT(parent->i_op != NULL);
1091 inode = ldiskfs_create_inode(oth->ot_handle, parent, mode);
1092 if (!IS_ERR(inode)) {
1093 obj->oo_inode = inode;
1096 result = PTR_ERR(inode);
1097 LASSERT(osd_invariant(obj));
1102 extern int iam_lvar_create(struct inode *obj, int keysize, int ptrsize,
1103 int recsize, handle_t *handle);
1109 static int osd_mkdir(struct osd_thread_info *info, struct osd_object *obj,
1110 struct lu_attr *attr,
1111 struct dt_allocation_hint *hint,
1115 struct osd_thandle *oth;
1117 LASSERT(S_ISDIR(attr->la_mode));
1119 oth = container_of(th, struct osd_thandle, ot_super);
1120 LASSERT(oth->ot_handle->h_transaction != NULL);
1121 result = osd_mkfile(info, obj, (attr->la_mode &
1122 (S_IFMT | S_IRWXUGO | S_ISVTX)), hint, th);
1124 LASSERT(obj->oo_inode != NULL);
1126 * XXX uh-oh... call low-level iam function directly.
1128 result = iam_lvar_create(obj->oo_inode, OSD_NAME_LEN, 4,
1129 sizeof (struct lu_fid_pack),
1135 static int osd_mkreg(struct osd_thread_info *info, struct osd_object *obj,
1136 struct lu_attr *attr,
1137 struct dt_allocation_hint *hint,
1140 LASSERT(S_ISREG(attr->la_mode));
1141 return osd_mkfile(info, obj, (attr->la_mode &
1142 (S_IFMT | S_IRWXUGO | S_ISVTX)), hint, th);
1145 static int osd_mksym(struct osd_thread_info *info, struct osd_object *obj,
1146 struct lu_attr *attr,
1147 struct dt_allocation_hint *hint,
1150 LASSERT(S_ISLNK(attr->la_mode));
1151 return osd_mkfile(info, obj, (attr->la_mode &
1152 (S_IFMT | S_IRWXUGO | S_ISVTX)), hint, th);
1155 static int osd_mknod(struct osd_thread_info *info, struct osd_object *obj,
1156 struct lu_attr *attr,
1157 struct dt_allocation_hint *hint,
1161 struct osd_device *osd = osd_obj2dev(obj);
1163 umode_t mode = attr->la_mode & (S_IFMT | S_IRWXUGO | S_ISVTX);
1165 LASSERT(osd_invariant(obj));
1166 LASSERT(obj->oo_inode == NULL);
1167 LASSERT(osd->od_obj_area != NULL);
1168 LASSERT(S_ISCHR(mode) || S_ISBLK(mode) ||
1169 S_ISFIFO(mode) || S_ISSOCK(mode));
1171 dir = osd->od_obj_area->d_inode;
1172 LASSERT(dir->i_op != NULL);
1174 result = osd_mkfile(info, obj, mode, hint, th);
1176 LASSERT(obj->oo_inode != NULL);
1177 init_special_inode(obj->oo_inode, mode, attr->la_rdev);
1179 LASSERT(osd_invariant(obj));
1183 typedef int (*osd_obj_type_f)(struct osd_thread_info *, struct osd_object *,
1185 struct dt_allocation_hint *hint,
1188 static osd_obj_type_f osd_create_type_f(__u32 mode)
1190 osd_obj_type_f result;
1216 static void osd_ah_init(const struct lu_env *env, struct dt_allocation_hint *ah,
1217 struct dt_object *parent, umode_t child_mode)
1221 memset(ah, 0, sizeof(*ah));
1222 ah->dah_parent = parent;
1223 ah->dah_mode = child_mode;
1228 * Concurrency: @dt is write locked.
1230 static int osd_object_create(const struct lu_env *env, struct dt_object *dt,
1231 struct lu_attr *attr,
1232 struct dt_allocation_hint *hint,
1235 const struct lu_fid *fid = lu_object_fid(&dt->do_lu);
1236 struct osd_object *obj = osd_dt_obj(dt);
1237 struct osd_device *osd = osd_obj2dev(obj);
1238 struct osd_thread_info *info = osd_oti_get(env);
1243 LASSERT(osd_invariant(obj));
1244 LASSERT(!dt_object_exists(dt));
1245 LASSERT(osd_write_locked(env, obj));
1246 LASSERT(th != NULL);
1249 * XXX missing: Quote handling.
1252 result = osd_create_pre(info, obj, attr, th);
1254 result = osd_create_type_f(attr->la_mode & S_IFMT)(info, obj,
1257 result = osd_create_post(info, obj, attr, th);
1260 struct osd_inode_id *id = &info->oti_id;
1262 LASSERT(obj->oo_inode != NULL);
1264 id->oii_ino = obj->oo_inode->i_ino;
1265 id->oii_gen = obj->oo_inode->i_generation;
1267 result = osd_oi_insert(info, &osd->od_oi, fid, id, th);
1270 LASSERT(ergo(result == 0, dt_object_exists(dt)));
1271 LASSERT(osd_invariant(obj));
1276 * Concurrency: @dt is write locked.
1278 static void osd_object_ref_add(const struct lu_env *env,
1279 struct dt_object *dt,
1282 struct osd_object *obj = osd_dt_obj(dt);
1283 struct inode *inode = obj->oo_inode;
1285 LASSERT(osd_invariant(obj));
1286 LASSERT(dt_object_exists(dt));
1287 LASSERT(osd_write_locked(env, obj));
1288 LASSERT(th != NULL);
1290 spin_lock(&obj->oo_guard);
1291 LASSERT(inode->i_nlink < LDISKFS_LINK_MAX);
1293 spin_unlock(&obj->oo_guard);
1294 mark_inode_dirty(inode);
1295 LASSERT(osd_invariant(obj));
1299 * Concurrency: @dt is write locked.
1301 static void osd_object_ref_del(const struct lu_env *env,
1302 struct dt_object *dt,
1305 struct osd_object *obj = osd_dt_obj(dt);
1306 struct inode *inode = obj->oo_inode;
1308 LASSERT(osd_invariant(obj));
1309 LASSERT(dt_object_exists(dt));
1310 LASSERT(osd_write_locked(env, obj));
1311 LASSERT(th != NULL);
1313 spin_lock(&obj->oo_guard);
1314 LASSERT(inode->i_nlink > 0);
1316 spin_unlock(&obj->oo_guard);
1317 mark_inode_dirty(inode);
1318 LASSERT(osd_invariant(obj));
1322 * Concurrency: @dt is read locked.
1324 static int osd_xattr_get(const struct lu_env *env,
1325 struct dt_object *dt,
1328 struct lustre_capa *capa)
1330 struct osd_object *obj = osd_dt_obj(dt);
1331 struct inode *inode = obj->oo_inode;
1332 struct osd_thread_info *info = osd_oti_get(env);
1333 struct dentry *dentry = &info->oti_dentry;
1335 LASSERT(dt_object_exists(dt));
1336 LASSERT(inode->i_op != NULL && inode->i_op->getxattr != NULL);
1337 LASSERT(osd_read_locked(env, obj) || osd_write_locked(env, obj));
1339 if (osd_object_auth(env, dt, capa, CAPA_OPC_META_READ))
1342 dentry->d_inode = inode;
1343 return inode->i_op->getxattr(dentry, name, buf->lb_buf, buf->lb_len);
1347 * Concurrency: @dt is write locked.
1349 static int osd_xattr_set(const struct lu_env *env, struct dt_object *dt,
1350 const struct lu_buf *buf, const char *name, int fl,
1351 struct thandle *handle, struct lustre_capa *capa)
1353 struct osd_object *obj = osd_dt_obj(dt);
1354 struct inode *inode = obj->oo_inode;
1355 struct osd_thread_info *info = osd_oti_get(env);
1356 struct dentry *dentry = &info->oti_dentry;
1357 struct timespec *t = &info->oti_time;
1358 int fs_flags = 0, rc;
1360 LASSERT(dt_object_exists(dt));
1361 LASSERT(inode->i_op != NULL && inode->i_op->setxattr != NULL);
1362 LASSERT(osd_write_locked(env, obj));
1363 LASSERT(handle != NULL);
1365 if (osd_object_auth(env, dt, capa, CAPA_OPC_META_WRITE))
1368 if (fl & LU_XATTR_REPLACE)
1369 fs_flags |= XATTR_REPLACE;
1371 if (fl & LU_XATTR_CREATE)
1372 fs_flags |= XATTR_CREATE;
1374 dentry->d_inode = inode;
1375 *t = inode->i_ctime;
1376 rc = inode->i_op->setxattr(dentry, name,
1377 buf->lb_buf, buf->lb_len, fs_flags);
1378 if (likely(rc == 0)) {
1379 /* ctime should not be updated with server-side time. */
1380 spin_lock(&obj->oo_guard);
1381 inode->i_ctime = *t;
1382 spin_unlock(&obj->oo_guard);
1383 mark_inode_dirty(inode);
1389 * Concurrency: @dt is read locked.
1391 static int osd_xattr_list(const struct lu_env *env,
1392 struct dt_object *dt,
1394 struct lustre_capa *capa)
1396 struct osd_object *obj = osd_dt_obj(dt);
1397 struct inode *inode = obj->oo_inode;
1398 struct osd_thread_info *info = osd_oti_get(env);
1399 struct dentry *dentry = &info->oti_dentry;
1401 LASSERT(dt_object_exists(dt));
1402 LASSERT(inode->i_op != NULL && inode->i_op->listxattr != NULL);
1403 LASSERT(osd_read_locked(env, obj) || osd_write_locked(env, obj));
1405 if (osd_object_auth(env, dt, capa, CAPA_OPC_META_READ))
1408 dentry->d_inode = inode;
1409 return inode->i_op->listxattr(dentry, buf->lb_buf, buf->lb_len);
1413 * Concurrency: @dt is write locked.
1415 static int osd_xattr_del(const struct lu_env *env,
1416 struct dt_object *dt,
1418 struct thandle *handle,
1419 struct lustre_capa *capa)
1421 struct osd_object *obj = osd_dt_obj(dt);
1422 struct inode *inode = obj->oo_inode;
1423 struct osd_thread_info *info = osd_oti_get(env);
1424 struct dentry *dentry = &info->oti_dentry;
1425 struct timespec *t = &info->oti_time;
1428 LASSERT(dt_object_exists(dt));
1429 LASSERT(inode->i_op != NULL && inode->i_op->removexattr != NULL);
1430 LASSERT(osd_write_locked(env, obj));
1431 LASSERT(handle != NULL);
1433 if (osd_object_auth(env, dt, capa, CAPA_OPC_META_WRITE))
1436 dentry->d_inode = inode;
1437 *t = inode->i_ctime;
1438 rc = inode->i_op->removexattr(dentry, name);
1439 if (likely(rc == 0)) {
1440 /* ctime should not be updated with server-side time. */
1441 spin_lock(&obj->oo_guard);
1442 inode->i_ctime = *t;
1443 spin_unlock(&obj->oo_guard);
1444 mark_inode_dirty(inode);
1449 static struct obd_capa *osd_capa_get(const struct lu_env *env,
1450 struct dt_object *dt,
1451 struct lustre_capa *old,
1454 struct osd_thread_info *info = osd_oti_get(env);
1455 const struct lu_fid *fid = lu_object_fid(&dt->do_lu);
1456 struct osd_object *obj = osd_dt_obj(dt);
1457 struct osd_device *dev = osd_obj2dev(obj);
1458 struct lustre_capa_key *key = &info->oti_capa_key;
1459 struct lustre_capa *capa = &info->oti_capa;
1460 struct obd_capa *oc;
1464 if (!dev->od_fl_capa)
1465 RETURN(ERR_PTR(-ENOENT));
1467 LASSERT(dt_object_exists(dt));
1468 LASSERT(osd_invariant(obj));
1470 /* renewal sanity check */
1471 if (old && osd_object_auth(env, dt, old, opc))
1472 RETURN(ERR_PTR(-EACCES));
1474 capa->lc_fid = *fid;
1477 capa->lc_flags = dev->od_capa_alg << 24;
1478 capa->lc_timeout = dev->od_capa_timeout;
1479 capa->lc_expiry = 0;
1481 oc = capa_lookup(dev->od_capa_hash, capa, 1);
1483 LASSERT(!capa_is_expired(oc));
1487 spin_lock(&capa_lock);
1488 *key = dev->od_capa_keys[1];
1489 spin_unlock(&capa_lock);
1491 capa->lc_keyid = key->lk_keyid;
1492 capa->lc_expiry = cfs_time_current_sec() + dev->od_capa_timeout;
1494 rc = capa_hmac(capa->lc_hmac, capa, key->lk_key);
1496 DEBUG_CAPA(D_ERROR, capa, "HMAC failed: %d for", rc);
1497 RETURN(ERR_PTR(rc));
1500 oc = capa_add(dev->od_capa_hash, capa);
1504 static int osd_object_sync(const struct lu_env *env, struct dt_object *dt)
1507 struct osd_object *obj = osd_dt_obj(dt);
1508 struct inode *inode = obj->oo_inode;
1509 struct osd_thread_info *info = osd_oti_get(env);
1510 struct dentry *dentry = &info->oti_dentry;
1511 struct file *file = &info->oti_file;
1514 dentry->d_inode = inode;
1515 file->f_dentry = dentry;
1516 file->f_mapping = inode->i_mapping;
1517 file->f_op = inode->i_fop;
1518 LOCK_INODE_MUTEX(inode);
1519 rc = file->f_op->fsync(file, dentry, 0);
1520 UNLOCK_INODE_MUTEX(inode);
1524 static struct dt_object_operations osd_obj_ops = {
1525 .do_read_lock = osd_object_read_lock,
1526 .do_write_lock = osd_object_write_lock,
1527 .do_read_unlock = osd_object_read_unlock,
1528 .do_write_unlock = osd_object_write_unlock,
1529 .do_attr_get = osd_attr_get,
1530 .do_attr_set = osd_attr_set,
1531 .do_ah_init = osd_ah_init,
1532 .do_create = osd_object_create,
1533 .do_index_try = osd_index_try,
1534 .do_ref_add = osd_object_ref_add,
1535 .do_ref_del = osd_object_ref_del,
1536 .do_xattr_get = osd_xattr_get,
1537 .do_xattr_set = osd_xattr_set,
1538 .do_xattr_del = osd_xattr_del,
1539 .do_xattr_list = osd_xattr_list,
1540 .do_capa_get = osd_capa_get,
1541 .do_object_sync = osd_object_sync,
1549 * XXX: Another layering violation for now.
1551 * We don't want to use ->f_op->read methods, because generic file write
1553 * - serializes on ->i_sem, and
1555 * - does a lot of extra work like balance_dirty_pages(),
1557 * which doesn't work for globally shared files like /last-received.
1559 int fsfilt_ldiskfs_read(struct inode *inode, void *buf, int size, loff_t *offs);
1560 int fsfilt_ldiskfs_write_handle(struct inode *inode, void *buf, int bufsize,
1561 loff_t *offs, handle_t *handle);
1563 static ssize_t osd_read(const struct lu_env *env, struct dt_object *dt,
1564 struct lu_buf *buf, loff_t *pos,
1565 struct lustre_capa *capa)
1567 struct inode *inode = osd_dt_obj(dt)->oo_inode;
1569 if (osd_object_auth(env, dt, capa, CAPA_OPC_BODY_READ))
1572 return fsfilt_ldiskfs_read(inode, buf->lb_buf, buf->lb_len, pos);
1575 static ssize_t osd_write(const struct lu_env *env, struct dt_object *dt,
1576 const struct lu_buf *buf, loff_t *pos,
1577 struct thandle *handle, struct lustre_capa *capa)
1579 struct inode *inode = osd_dt_obj(dt)->oo_inode;
1580 struct osd_thandle *oh;
1583 LASSERT(handle != NULL);
1585 if (osd_object_auth(env, dt, capa, CAPA_OPC_BODY_WRITE))
1588 oh = container_of(handle, struct osd_thandle, ot_super);
1589 LASSERT(oh->ot_handle->h_transaction != NULL);
1590 result = fsfilt_ldiskfs_write_handle(inode, buf->lb_buf, buf->lb_len,
1591 pos, oh->ot_handle);
1593 result = buf->lb_len;
1597 static struct dt_body_operations osd_body_ops = {
1598 .dbo_read = osd_read,
1599 .dbo_write = osd_write
1606 static int osd_object_is_root(const struct osd_object *obj)
1608 return osd_sb(osd_obj2dev(obj))->s_root->d_inode == obj->oo_inode;
1611 static int osd_index_probe(const struct lu_env *env, struct osd_object *o,
1612 const struct dt_index_features *feat)
1614 struct iam_descr *descr;
1616 if (osd_object_is_root(o))
1617 return feat == &dt_directory_features;
1619 LASSERT(o->oo_dir != NULL);
1621 descr = o->oo_dir->od_container.ic_descr;
1622 if (feat == &dt_directory_features)
1623 return descr == &iam_htree_compat_param ||
1624 (descr->id_rec_size == sizeof(struct lu_fid_pack) &&
1626 * XXX check that index looks like directory.
1631 feat->dif_keysize_min <= descr->id_key_size &&
1632 descr->id_key_size <= feat->dif_keysize_max &&
1633 feat->dif_recsize_min <= descr->id_rec_size &&
1634 descr->id_rec_size <= feat->dif_recsize_max &&
1635 !(feat->dif_flags & (DT_IND_VARKEY |
1636 DT_IND_VARREC | DT_IND_NONUNQ)) &&
1637 ergo(feat->dif_flags & DT_IND_UPDATE,
1638 1 /* XXX check that object (and file system) is
1642 static int osd_container_init(const struct lu_env *env,
1643 struct osd_object *obj,
1644 struct osd_directory *dir)
1647 struct iam_container *bag;
1649 bag = &dir->od_container;
1650 result = iam_container_init(bag, &dir->od_descr, obj->oo_inode);
1652 result = iam_container_setup(bag);
1654 obj->oo_dt.do_index_ops = &osd_index_ops;
1656 iam_container_fini(bag);
1662 * Concurrency: no external locking is necessary.
1664 static int osd_index_try(const struct lu_env *env, struct dt_object *dt,
1665 const struct dt_index_features *feat)
1668 struct osd_object *obj = osd_dt_obj(dt);
1670 LASSERT(osd_invariant(obj));
1671 LASSERT(dt_object_exists(dt));
1673 if (osd_object_is_root(obj)) {
1674 dt->do_index_ops = &osd_index_compat_ops;
1676 } else if (!osd_has_index(obj)) {
1677 struct osd_directory *dir;
1681 sema_init(&dir->od_sem, 1);
1683 spin_lock(&obj->oo_guard);
1684 if (obj->oo_dir == NULL)
1688 * Concurrent thread allocated container data.
1691 spin_unlock(&obj->oo_guard);
1693 * Now, that we have container data, serialize its
1696 down(&obj->oo_dir->od_sem);
1698 * recheck under lock.
1700 if (!osd_has_index(obj))
1701 result = osd_container_init(env, obj, dir);
1704 up(&obj->oo_dir->od_sem);
1711 if (!osd_index_probe(env, obj, feat))
1714 LASSERT(osd_invariant(obj));
1719 static int osd_index_delete(const struct lu_env *env, struct dt_object *dt,
1720 const struct dt_key *key, struct thandle *handle,
1721 struct lustre_capa *capa)
1723 struct osd_object *obj = osd_dt_obj(dt);
1724 struct osd_thandle *oh;
1725 struct iam_path_descr *ipd;
1726 struct iam_container *bag = &obj->oo_dir->od_container;
1731 LASSERT(osd_invariant(obj));
1732 LASSERT(dt_object_exists(dt));
1733 LASSERT(bag->ic_object == obj->oo_inode);
1734 LASSERT(handle != NULL);
1736 if (osd_object_auth(env, dt, capa, CAPA_OPC_INDEX_DELETE))
1739 ipd = osd_ipd_get(env, bag);
1740 if (unlikely(ipd == NULL))
1743 oh = container_of0(handle, struct osd_thandle, ot_super);
1744 LASSERT(oh->ot_handle != NULL);
1745 LASSERT(oh->ot_handle->h_transaction != NULL);
1747 rc = iam_delete(oh->ot_handle, bag, (const struct iam_key *)key, ipd);
1748 osd_ipd_put(env, bag, ipd);
1749 LASSERT(osd_invariant(obj));
1753 static int osd_index_lookup(const struct lu_env *env, struct dt_object *dt,
1754 struct dt_rec *rec, const struct dt_key *key,
1755 struct lustre_capa *capa)
1757 struct osd_object *obj = osd_dt_obj(dt);
1758 struct iam_path_descr *ipd;
1759 struct iam_container *bag = &obj->oo_dir->od_container;
1764 LASSERT(osd_invariant(obj));
1765 LASSERT(dt_object_exists(dt));
1766 LASSERT(bag->ic_object == obj->oo_inode);
1768 if (osd_object_auth(env, dt, capa, CAPA_OPC_INDEX_LOOKUP))
1771 ipd = osd_ipd_get(env, bag);
1772 if (unlikely(ipd == NULL))
1775 rc = iam_lookup(bag, (const struct iam_key *)key,
1776 (struct iam_rec *)rec, ipd);
1777 osd_ipd_put(env, bag, ipd);
1778 LASSERT(osd_invariant(obj));
1783 static int osd_index_insert(const struct lu_env *env, struct dt_object *dt,
1784 const struct dt_rec *rec, const struct dt_key *key,
1785 struct thandle *th, struct lustre_capa *capa)
1787 struct osd_object *obj = osd_dt_obj(dt);
1788 struct iam_path_descr *ipd;
1789 struct osd_thandle *oh;
1790 struct iam_container *bag = &obj->oo_dir->od_container;
1795 LASSERT(osd_invariant(obj));
1796 LASSERT(dt_object_exists(dt));
1797 LASSERT(bag->ic_object == obj->oo_inode);
1798 LASSERT(th != NULL);
1800 if (osd_object_auth(env, dt, capa, CAPA_OPC_INDEX_INSERT))
1803 ipd = osd_ipd_get(env, bag);
1804 if (unlikely(ipd == NULL))
1807 oh = container_of0(th, struct osd_thandle, ot_super);
1808 LASSERT(oh->ot_handle != NULL);
1809 LASSERT(oh->ot_handle->h_transaction != NULL);
1810 rc = iam_insert(oh->ot_handle, bag, (const struct iam_key *)key,
1811 (struct iam_rec *)rec, ipd);
1812 osd_ipd_put(env, bag, ipd);
1813 LASSERT(osd_invariant(obj));
1818 * Iterator operations.
1821 struct osd_object *oi_obj;
1822 struct iam_path_descr *oi_ipd;
1823 struct iam_iterator oi_it;
1826 static struct dt_it *osd_it_init(const struct lu_env *env,
1827 struct dt_object *dt, int writable,
1828 struct lustre_capa *capa)
1831 struct osd_object *obj = osd_dt_obj(dt);
1832 struct lu_object *lo = &dt->do_lu;
1833 struct iam_path_descr *ipd;
1834 struct iam_container *bag = &obj->oo_dir->od_container;
1837 LASSERT(lu_object_exists(lo));
1839 if (osd_object_auth(env, dt, capa, writable ? CAPA_OPC_BODY_WRITE :
1840 CAPA_OPC_BODY_READ))
1841 return ERR_PTR(-EACCES);
1843 flags = writable ? IAM_IT_MOVE|IAM_IT_WRITE : IAM_IT_MOVE;
1847 * XXX: as ipd is allocated within osd_thread_info, assignment
1848 * below implies that iterator usage is confined within single
1851 ipd = osd_ipd_get(env, bag);
1852 if (likely(ipd != NULL)) {
1856 iam_it_init(&it->oi_it, bag, flags, ipd);
1857 return (struct dt_it *)it;
1861 return ERR_PTR(-ENOMEM);
1864 static void osd_it_fini(const struct lu_env *env, struct dt_it *di)
1866 struct osd_it *it = (struct osd_it *)di;
1867 struct osd_object *obj = it->oi_obj;
1869 iam_it_fini(&it->oi_it);
1870 osd_ipd_put(env, &obj->oo_dir->od_container, it->oi_ipd);
1871 lu_object_put(env, &obj->oo_dt.do_lu);
1875 static int osd_it_get(const struct lu_env *env,
1876 struct dt_it *di, const struct dt_key *key)
1878 struct osd_it *it = (struct osd_it *)di;
1880 return iam_it_get(&it->oi_it, (const struct iam_key *)key);
1883 static void osd_it_put(const struct lu_env *env, struct dt_it *di)
1885 struct osd_it *it = (struct osd_it *)di;
1887 iam_it_put(&it->oi_it);
1890 static int osd_it_next(const struct lu_env *env, struct dt_it *di)
1892 struct osd_it *it = (struct osd_it *)di;
1894 return iam_it_next(&it->oi_it);
1897 static int osd_it_del(const struct lu_env *env, struct dt_it *di,
1900 struct osd_it *it = (struct osd_it *)di;
1901 struct osd_thandle *oh;
1903 LASSERT(th != NULL);
1905 oh = container_of0(th, struct osd_thandle, ot_super);
1906 LASSERT(oh->ot_handle != NULL);
1907 LASSERT(oh->ot_handle->h_transaction != NULL);
1909 return iam_it_rec_delete(oh->ot_handle, &it->oi_it);
1912 static struct dt_key *osd_it_key(const struct lu_env *env,
1913 const struct dt_it *di)
1915 struct osd_it *it = (struct osd_it *)di;
1917 return (struct dt_key *)iam_it_key_get(&it->oi_it);
1920 static int osd_it_key_size(const struct lu_env *env, const struct dt_it *di)
1922 struct osd_it *it = (struct osd_it *)di;
1924 return iam_it_key_size(&it->oi_it);
1927 static struct dt_rec *osd_it_rec(const struct lu_env *env,
1928 const struct dt_it *di)
1930 struct osd_it *it = (struct osd_it *)di;
1932 return (struct dt_rec *)iam_it_rec_get(&it->oi_it);
1935 static __u64 osd_it_store(const struct lu_env *env, const struct dt_it *di)
1937 struct osd_it *it = (struct osd_it *)di;
1939 return iam_it_store(&it->oi_it);
1942 static int osd_it_load(const struct lu_env *env,
1943 const struct dt_it *di, __u64 hash)
1945 struct osd_it *it = (struct osd_it *)di;
1947 return iam_it_load(&it->oi_it, hash);
1950 static struct dt_index_operations osd_index_ops = {
1951 .dio_lookup = osd_index_lookup,
1952 .dio_insert = osd_index_insert,
1953 .dio_delete = osd_index_delete,
1955 .init = osd_it_init,
1956 .fini = osd_it_fini,
1960 .next = osd_it_next,
1962 .key_size = osd_it_key_size,
1964 .store = osd_it_store,
1969 static int osd_index_compat_delete(const struct lu_env *env,
1970 struct dt_object *dt,
1971 const struct dt_key *key,
1972 struct thandle *handle,
1973 struct lustre_capa *capa)
1975 struct osd_object *obj = osd_dt_obj(dt);
1977 LASSERT(handle != NULL);
1978 LASSERT(S_ISDIR(obj->oo_inode->i_mode));
1982 if (osd_object_auth(env, dt, capa, CAPA_OPC_INDEX_DELETE))
1986 RETURN(-EOPNOTSUPP);
1990 * Compatibility index operations.
1994 static void osd_build_pack(const struct lu_env *env, struct osd_device *osd,
1995 struct dentry *dentry, struct lu_fid_pack *pack)
1997 struct inode *inode = dentry->d_inode;
1998 struct lu_fid *fid = &osd_oti_get(env)->oti_fid;
2000 lu_igif_build(fid, inode->i_ino, inode->i_generation);
2001 fid_cpu_to_be(fid, fid);
2002 pack->fp_len = sizeof *fid + 1;
2003 memcpy(pack->fp_area, fid, sizeof *fid);
2006 static int osd_index_compat_lookup(const struct lu_env *env,
2007 struct dt_object *dt,
2008 struct dt_rec *rec, const struct dt_key *key,
2009 struct lustre_capa *capa)
2011 struct osd_object *obj = osd_dt_obj(dt);
2013 struct osd_device *osd = osd_obj2dev(obj);
2014 struct osd_thread_info *info = osd_oti_get(env);
2020 * XXX temporary solution.
2022 struct dentry *dentry;
2023 struct dentry *parent;
2025 LASSERT(osd_invariant(obj));
2026 LASSERT(S_ISDIR(obj->oo_inode->i_mode));
2027 LASSERT(osd_has_index(obj));
2029 if (osd_object_auth(env, dt, capa, CAPA_OPC_INDEX_LOOKUP))
2032 info->oti_str.name = (const char *)key;
2033 info->oti_str.len = strlen((const char *)key);
2035 dir = obj->oo_inode;
2036 LASSERT(dir->i_op != NULL && dir->i_op->lookup != NULL);
2038 parent = d_alloc_root(dir);
2042 dentry = d_alloc(parent, &info->oti_str);
2043 if (dentry != NULL) {
2047 * XXX passing NULL for nameidata should work for
2050 d = dir->i_op->lookup(dir, dentry, NULL);
2053 * normal case, result is in @dentry.
2055 if (dentry->d_inode != NULL) {
2056 osd_build_pack(env, osd, dentry,
2057 (struct lu_fid_pack *)rec);
2062 /* What? Disconnected alias? Ppheeeww... */
2063 CERROR("Aliasing where not expected\n");
2071 LASSERT(osd_invariant(obj));
2075 static int osd_add_rec(struct osd_thread_info *info, struct osd_device *dev,
2076 struct inode *dir, struct inode *inode, const char *name)
2080 struct dentry *parent;
2084 info->oti_str.name = name;
2085 info->oti_str.len = strlen(name);
2087 LASSERT(atomic_read(&dir->i_count) > 0);
2089 old = d_alloc(dev->od_obj_area, &info->oti_str);
2091 d_instantiate(old, inode);
2093 LASSERT(atomic_read(&dir->i_count) > 0);
2094 parent = d_alloc_root(dir);
2095 if (parent != NULL) {
2097 LASSERT(atomic_read(&dir->i_count) > 1);
2098 new = d_alloc(parent, &info->oti_str);
2099 LASSERT(atomic_read(&dir->i_count) > 1);
2101 LASSERT(atomic_read(&dir->i_count) > 1);
2102 result = dir->i_op->link(old, dir, new);
2103 LASSERT(atomic_read(&dir->i_count) > 1);
2105 LASSERT(atomic_read(&dir->i_count) > 1);
2107 LASSERT(atomic_read(&dir->i_count) > 1);
2109 LASSERT(atomic_read(&dir->i_count) > 0);
2113 LASSERT(atomic_read(&dir->i_count) > 0);
2119 * XXX Temporary stuff.
2121 static int osd_index_compat_insert(const struct lu_env *env,
2122 struct dt_object *dt,
2123 const struct dt_rec *rec,
2124 const struct dt_key *key, struct thandle *th,
2125 struct lustre_capa *capa)
2127 struct osd_object *obj = osd_dt_obj(dt);
2129 const char *name = (const char *)key;
2131 struct lu_device *ludev = dt->do_lu.lo_dev;
2132 struct lu_object *luch;
2134 struct osd_thread_info *info = osd_oti_get(env);
2135 const struct lu_fid_pack *pack = (const struct lu_fid_pack *)rec;
2136 struct lu_fid *fid = &osd_oti_get(env)->oti_fid;
2140 LASSERT(S_ISDIR(obj->oo_inode->i_mode));
2141 LASSERT(osd_invariant(obj));
2142 LASSERT(th != NULL);
2144 if (osd_object_auth(env, dt, capa, CAPA_OPC_INDEX_INSERT))
2147 result = fid_unpack(pack, fid);
2151 luch = lu_object_find(env, ludev->ld_site, fid);
2152 if (!IS_ERR(luch)) {
2153 if (lu_object_exists(luch)) {
2154 struct osd_object *child;
2156 child = osd_obj(lu_object_locate(luch->lo_header,
2159 result = osd_add_rec(info, osd_obj2dev(obj),
2161 child->oo_inode, name);
2163 CERROR("No osd slice.\n");
2166 LASSERT(osd_invariant(obj));
2167 LASSERT(osd_invariant(child));
2172 lu_object_put(env, luch);
2174 result = PTR_ERR(luch);
2175 LASSERT(osd_invariant(obj));
2179 static struct dt_index_operations osd_index_compat_ops = {
2180 .dio_lookup = osd_index_compat_lookup,
2181 .dio_insert = osd_index_compat_insert,
2182 .dio_delete = osd_index_compat_delete
2185 /* type constructor/destructor: osd_type_init, osd_type_fini */
2186 LU_TYPE_INIT_FINI(osd, &osd_key);
2188 static struct lu_context_key osd_key = {
2189 .lct_tags = LCT_DT_THREAD | LCT_MD_THREAD,
2190 .lct_init = osd_key_init,
2191 .lct_fini = osd_key_fini,
2192 .lct_exit = osd_key_exit
2195 static void *osd_key_init(const struct lu_context *ctx,
2196 struct lu_context_key *key)
2198 struct osd_thread_info *info;
2200 OBD_ALLOC_PTR(info);
2202 info->oti_env = container_of(ctx, struct lu_env, le_ctx);
2204 info = ERR_PTR(-ENOMEM);
2208 /* context key destructor: osd_key_fini */
2209 LU_KEY_FINI(osd, struct osd_thread_info);
2211 static void osd_key_exit(const struct lu_context *ctx,
2212 struct lu_context_key *key, void *data)
2214 struct osd_thread_info *info = data;
2216 LASSERT(info->oti_r_locks == 0);
2217 LASSERT(info->oti_w_locks == 0);
2218 LASSERT(info->oti_txns == 0);
2221 static int osd_device_init(const struct lu_env *env, struct lu_device *d,
2222 const char *name, struct lu_device *next)
2225 /* context for commit hooks */
2226 rc = lu_context_init(&osd_dev(d)->od_env_for_commit.le_ctx,
2229 rc = osd_procfs_init(osd_dev(d), name);
2233 static int osd_shutdown(const struct lu_env *env, struct osd_device *o)
2235 struct osd_thread_info *info = osd_oti_get(env);
2237 if (o->od_obj_area != NULL) {
2238 dput(o->od_obj_area);
2239 o->od_obj_area = NULL;
2241 osd_oi_fini(info, &o->od_oi);
2246 static int osd_mount(const struct lu_env *env,
2247 struct osd_device *o, struct lustre_cfg *cfg)
2249 struct lustre_mount_info *lmi;
2250 const char *dev = lustre_cfg_string(cfg, 0);
2251 struct osd_thread_info *info = osd_oti_get(env);
2256 if (o->od_mount != NULL) {
2257 CERROR("Already mounted (%s)\n", dev);
2262 lmi = server_get_mount(dev);
2264 CERROR("Cannot get mount info for %s!\n", dev);
2268 LASSERT(lmi != NULL);
2269 /* save lustre_mount_info in dt_device */
2272 result = osd_oi_init(info, &o->od_oi, &o->od_dt_dev);
2276 d = simple_mkdir(osd_sb(o)->s_root, lmi->lmi_mnt, "*OBJ-TEMP*",
2281 result = PTR_ERR(d);
2284 osd_shutdown(env, o);
2288 static struct lu_device *osd_device_fini(const struct lu_env *env,
2289 struct lu_device *d)
2294 shrink_dcache_sb(osd_sb(osd_dev(d)));
2295 osd_sync(env, lu2dt_dev(d));
2297 rc = osd_procfs_fini(osd_dev(d));
2299 CERROR("proc fini error %d \n", rc);
2300 RETURN (ERR_PTR(rc));
2303 if (osd_dev(d)->od_mount)
2304 server_put_mount(osd_dev(d)->od_mount->lmi_name,
2305 osd_dev(d)->od_mount->lmi_mnt);
2306 osd_dev(d)->od_mount = NULL;
2308 lu_context_fini(&osd_dev(d)->od_env_for_commit.le_ctx);
2312 static struct lu_device *osd_device_alloc(const struct lu_env *env,
2313 struct lu_device_type *t,
2314 struct lustre_cfg *cfg)
2316 struct lu_device *l;
2317 struct osd_device *o;
2323 result = dt_device_init(&o->od_dt_dev, t);
2326 l->ld_ops = &osd_lu_ops;
2327 o->od_dt_dev.dd_ops = &osd_dt_ops;
2328 spin_lock_init(&o->od_osfs_lock);
2329 o->od_osfs_age = cfs_time_shift_64(-1000);
2330 o->od_capa_hash = init_capa_hash();
2331 if (o->od_capa_hash == NULL) {
2332 dt_device_fini(&o->od_dt_dev);
2333 l = ERR_PTR(-ENOMEM);
2336 l = ERR_PTR(result);
2341 l = ERR_PTR(-ENOMEM);
2345 static struct lu_device *osd_device_free(const struct lu_env *env,
2346 struct lu_device *d)
2348 struct osd_device *o = osd_dev(d);
2351 cleanup_capa_hash(o->od_capa_hash);
2352 dt_device_fini(&o->od_dt_dev);
2357 static int osd_process_config(const struct lu_env *env,
2358 struct lu_device *d, struct lustre_cfg *cfg)
2360 struct osd_device *o = osd_dev(d);
2364 switch(cfg->lcfg_command) {
2366 err = osd_mount(env, o, cfg);
2369 err = osd_shutdown(env, o);
2377 extern void ldiskfs_orphan_cleanup (struct super_block * sb,
2378 struct ldiskfs_super_block * es);
2380 static int osd_recovery_complete(const struct lu_env *env,
2381 struct lu_device *d)
2383 struct osd_device *o = osd_dev(d);
2385 /* TODO: orphans handling */
2386 ldiskfs_orphan_cleanup(osd_sb(o), LDISKFS_SB(osd_sb(o))->s_es);
2390 static struct inode *osd_iget(struct osd_thread_info *info,
2391 struct osd_device *dev,
2392 const struct osd_inode_id *id)
2394 struct inode *inode;
2396 inode = iget(osd_sb(dev), id->oii_ino);
2397 if (inode == NULL) {
2398 CERROR("no inode\n");
2399 inode = ERR_PTR(-EACCES);
2400 } else if (is_bad_inode(inode)) {
2401 CERROR("bad inode\n");
2403 inode = ERR_PTR(-ENOENT);
2404 } else if (inode->i_generation != id->oii_gen) {
2405 CERROR("stale inode\n");
2407 inode = ERR_PTR(-ESTALE);
2414 static int osd_fid_lookup(const struct lu_env *env,
2415 struct osd_object *obj, const struct lu_fid *fid)
2417 struct osd_thread_info *info;
2418 struct lu_device *ldev = obj->oo_dt.do_lu.lo_dev;
2419 struct osd_device *dev;
2420 struct osd_inode_id *id;
2422 struct inode *inode;
2425 LASSERT(osd_invariant(obj));
2426 LASSERT(obj->oo_inode == NULL);
2427 LASSERT(fid_is_sane(fid));
2429 * This assertion checks that osd layer sees only local
2430 * fids. Unfortunately it is somewhat expensive (does a
2431 * cache-lookup). Disabling it for production/acceptance-testing.
2433 LASSERT(1 || fid_is_local(ldev->ld_site, fid));
2437 info = osd_oti_get(env);
2438 dev = osd_dev(ldev);
2442 if (OBD_FAIL_CHECK(OBD_FAIL_OST_ENOENT))
2445 result = osd_oi_lookup(info, oi, fid, id);
2447 inode = osd_iget(info, dev, id);
2448 if (!IS_ERR(inode)) {
2449 obj->oo_inode = inode;
2450 LASSERT(obj->oo_inode->i_sb == osd_sb(dev));
2454 * If fid wasn't found in oi, inode-less object is
2455 * created, for which lu_object_exists() returns
2456 * false. This is used in a (frequent) case when
2457 * objects are created as locking anchors or
2458 * place holders for objects yet to be created.
2460 result = PTR_ERR(inode);
2461 } else if (result == -ENOENT)
2463 LASSERT(osd_invariant(obj));
2467 static void osd_inode_getattr(const struct lu_env *env,
2468 struct inode *inode, struct lu_attr *attr)
2470 attr->la_valid |= LA_ATIME | LA_MTIME | LA_CTIME | LA_MODE |
2471 LA_SIZE | LA_BLOCKS | LA_UID | LA_GID |
2472 LA_FLAGS | LA_NLINK | LA_RDEV | LA_BLKSIZE;
2474 attr->la_atime = LTIME_S(inode->i_atime);
2475 attr->la_mtime = LTIME_S(inode->i_mtime);
2476 attr->la_ctime = LTIME_S(inode->i_ctime);
2477 attr->la_mode = inode->i_mode;
2478 attr->la_size = i_size_read(inode);
2479 attr->la_blocks = inode->i_blocks;
2480 attr->la_uid = inode->i_uid;
2481 attr->la_gid = inode->i_gid;
2482 attr->la_flags = LDISKFS_I(inode)->i_flags;
2483 attr->la_nlink = inode->i_nlink;
2484 attr->la_rdev = inode->i_rdev;
2485 attr->la_blksize = ll_inode_blksize(inode);
2486 attr->la_blkbits = inode->i_blkbits;
2493 static int lu_device_is_osd(const struct lu_device *d)
2495 return ergo(d != NULL && d->ld_ops != NULL, d->ld_ops == &osd_lu_ops);
2498 static struct osd_object *osd_obj(const struct lu_object *o)
2500 LASSERT(lu_device_is_osd(o->lo_dev));
2501 return container_of0(o, struct osd_object, oo_dt.do_lu);
2504 static struct osd_device *osd_dt_dev(const struct dt_device *d)
2506 LASSERT(lu_device_is_osd(&d->dd_lu_dev));
2507 return container_of0(d, struct osd_device, od_dt_dev);
2510 static struct osd_device *osd_dev(const struct lu_device *d)
2512 LASSERT(lu_device_is_osd(d));
2513 return osd_dt_dev(container_of0(d, struct dt_device, dd_lu_dev));
2516 static struct osd_object *osd_dt_obj(const struct dt_object *d)
2518 return osd_obj(&d->do_lu);
2521 static struct osd_device *osd_obj2dev(const struct osd_object *o)
2523 return osd_dev(o->oo_dt.do_lu.lo_dev);
2526 static struct lu_device *osd2lu_dev(struct osd_device *osd)
2528 return &osd->od_dt_dev.dd_lu_dev;
2531 static struct super_block *osd_sb(const struct osd_device *dev)
2533 return dev->od_mount->lmi_mnt->mnt_sb;
2536 static journal_t *osd_journal(const struct osd_device *dev)
2538 return LDISKFS_SB(osd_sb(dev))->s_journal;
2541 static int osd_has_index(const struct osd_object *obj)
2543 return obj->oo_dt.do_index_ops != NULL;
2546 static int osd_object_invariant(const struct lu_object *l)
2548 return osd_invariant(osd_obj(l));
2551 static struct lu_object_operations osd_lu_obj_ops = {
2552 .loo_object_init = osd_object_init,
2553 .loo_object_delete = osd_object_delete,
2554 .loo_object_release = osd_object_release,
2555 .loo_object_free = osd_object_free,
2556 .loo_object_print = osd_object_print,
2557 .loo_object_invariant = osd_object_invariant
2560 static struct lu_device_operations osd_lu_ops = {
2561 .ldo_object_alloc = osd_object_alloc,
2562 .ldo_process_config = osd_process_config,
2563 .ldo_recovery_complete = osd_recovery_complete
2566 static struct lu_device_type_operations osd_device_type_ops = {
2567 .ldto_init = osd_type_init,
2568 .ldto_fini = osd_type_fini,
2570 .ldto_device_alloc = osd_device_alloc,
2571 .ldto_device_free = osd_device_free,
2573 .ldto_device_init = osd_device_init,
2574 .ldto_device_fini = osd_device_fini
2577 static struct lu_device_type osd_device_type = {
2578 .ldt_tags = LU_DEVICE_DT,
2579 .ldt_name = LUSTRE_OSD_NAME,
2580 .ldt_ops = &osd_device_type_ops,
2581 .ldt_ctx_tags = LCT_MD_THREAD|LCT_DT_THREAD
2585 * lprocfs legacy support.
2587 static struct obd_ops osd_obd_device_ops = {
2588 .o_owner = THIS_MODULE
2591 static int __init osd_mod_init(void)
2593 struct lprocfs_static_vars lvars;
2595 lprocfs_osd_init_vars(&lvars);
2596 return class_register_type(&osd_obd_device_ops, NULL, lvars.module_vars,
2597 LUSTRE_OSD_NAME, &osd_device_type);
2600 static void __exit osd_mod_exit(void)
2602 class_unregister_type(LUSTRE_OSD_NAME);
2605 MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");
2606 MODULE_DESCRIPTION("Lustre Object Storage Device ("LUSTRE_OSD_NAME")");
2607 MODULE_LICENSE("GPL");
2609 cfs_module(osd, "0.0.2", osd_mod_init, osd_mod_exit);