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. */
105 const struct lu_env *oo_owner;
106 #ifdef CONFIG_LOCKDEP
107 struct lockdep_map oo_dep_map;
111 static int osd_root_get (const struct lu_env *env,
112 struct dt_device *dev, struct lu_fid *f);
114 static int lu_device_is_osd (const struct lu_device *d);
115 static void osd_mod_exit (void) __exit;
116 static int osd_mod_init (void) __init;
117 static int osd_type_init (struct lu_device_type *t);
118 static void osd_type_fini (struct lu_device_type *t);
119 static int osd_object_init (const struct lu_env *env,
121 const struct lu_object_conf *_);
122 static void osd_object_release(const struct lu_env *env,
123 struct lu_object *l);
124 static int osd_object_print (const struct lu_env *env, void *cookie,
125 lu_printer_t p, const struct lu_object *o);
126 static struct lu_device *osd_device_free (const struct lu_env *env,
127 struct lu_device *m);
128 static void *osd_key_init (const struct lu_context *ctx,
129 struct lu_context_key *key);
130 static void osd_key_fini (const struct lu_context *ctx,
131 struct lu_context_key *key, void *data);
132 static void osd_key_exit (const struct lu_context *ctx,
133 struct lu_context_key *key, void *data);
134 static int osd_has_index (const struct osd_object *obj);
135 static void osd_object_init0 (struct osd_object *obj);
136 static int osd_device_init (const struct lu_env *env,
137 struct lu_device *d, const char *,
139 static int osd_fid_lookup (const struct lu_env *env,
140 struct osd_object *obj,
141 const struct lu_fid *fid);
142 static void osd_inode_getattr (const struct lu_env *env,
143 struct inode *inode, struct lu_attr *attr);
144 static void osd_inode_setattr (const struct lu_env *env,
145 struct inode *inode, const struct lu_attr *attr);
146 static int osd_param_is_sane (const struct osd_device *dev,
147 const struct txn_param *param);
148 static int osd_index_lookup (const struct lu_env *env,
149 struct dt_object *dt,
150 struct dt_rec *rec, const struct dt_key *key,
151 struct lustre_capa *capa);
152 static int osd_index_insert (const struct lu_env *env,
153 struct dt_object *dt,
154 const struct dt_rec *rec,
155 const struct dt_key *key,
156 struct thandle *handle,
157 struct lustre_capa *capa);
158 static int osd_index_delete (const struct lu_env *env,
159 struct dt_object *dt, const struct dt_key *key,
160 struct thandle *handle,
161 struct lustre_capa *capa);
162 static int osd_index_probe (const struct lu_env *env,
163 struct osd_object *o,
164 const struct dt_index_features *feat);
165 static int osd_index_try (const struct lu_env *env,
166 struct dt_object *dt,
167 const struct dt_index_features *feat);
168 static void osd_index_fini (struct osd_object *o);
170 static void osd_it_fini (const struct lu_env *env, struct dt_it *di);
171 static int osd_it_get (const struct lu_env *env,
172 struct dt_it *di, const struct dt_key *key);
173 static void osd_it_put (const struct lu_env *env, struct dt_it *di);
174 static int osd_it_next (const struct lu_env *env, struct dt_it *di);
175 static int osd_it_del (const struct lu_env *env, struct dt_it *di,
177 static int osd_it_key_size (const struct lu_env *env,
178 const struct dt_it *di);
179 static void osd_conf_get (const struct lu_env *env,
180 const struct dt_device *dev,
181 struct dt_device_param *param);
182 static void osd_trans_stop (const struct lu_env *env,
184 static int osd_object_is_root(const struct osd_object *obj);
186 static struct osd_object *osd_obj (const struct lu_object *o);
187 static struct osd_device *osd_dev (const struct lu_device *d);
188 static struct osd_device *osd_dt_dev (const struct dt_device *d);
189 static struct osd_object *osd_dt_obj (const struct dt_object *d);
190 static struct osd_device *osd_obj2dev (const struct osd_object *o);
191 static struct lu_device *osd2lu_dev (struct osd_device *osd);
192 static struct lu_device *osd_device_fini (const struct lu_env *env,
193 struct lu_device *d);
194 static struct lu_device *osd_device_alloc (const struct lu_env *env,
195 struct lu_device_type *t,
196 struct lustre_cfg *cfg);
197 static struct lu_object *osd_object_alloc (const struct lu_env *env,
198 const struct lu_object_header *hdr,
199 struct lu_device *d);
200 static struct inode *osd_iget (struct osd_thread_info *info,
201 struct osd_device *dev,
202 const struct osd_inode_id *id);
203 static struct super_block *osd_sb (const struct osd_device *dev);
204 static struct dt_it *osd_it_init (const struct lu_env *env,
205 struct dt_object *dt, int wable,
206 struct lustre_capa *capa);
207 static struct dt_key *osd_it_key (const struct lu_env *env,
208 const struct dt_it *di);
209 static struct dt_rec *osd_it_rec (const struct lu_env *env,
210 const struct dt_it *di);
211 static struct timespec *osd_inode_time (const struct lu_env *env,
214 static struct thandle *osd_trans_start (const struct lu_env *env,
216 struct txn_param *p);
217 static journal_t *osd_journal (const struct osd_device *dev);
219 static struct lu_device_type_operations osd_device_type_ops;
220 static struct lu_device_type osd_device_type;
221 static struct lu_object_operations osd_lu_obj_ops;
222 static struct obd_ops osd_obd_device_ops;
223 static struct lu_device_operations osd_lu_ops;
224 static struct lu_context_key osd_key;
225 static struct dt_object_operations osd_obj_ops;
226 static struct dt_body_operations osd_body_ops;
227 static struct dt_index_operations osd_index_ops;
228 static struct dt_index_operations osd_index_compat_ops;
231 struct thandle ot_super;
233 struct journal_callback ot_jcb;
237 * Invariants, assertions.
241 * XXX: do not enable this, until invariant checking code is made thread safe
242 * in the face of pdirops locking.
244 #define OSD_INVARIANT_CHECKS (0)
246 #if OSD_INVARIANT_CHECKS
247 static int osd_invariant(const struct osd_object *obj)
251 ergo(obj->oo_inode != NULL,
252 obj->oo_inode->i_sb == osd_sb(osd_obj2dev(obj)) &&
253 atomic_read(&obj->oo_inode->i_count) > 0) &&
254 ergo(obj->oo_dir != NULL &&
255 obj->oo_dir->od_conationer.ic_object != NULL,
256 obj->oo_dir->od_conationer.ic_object == obj->oo_inode);
259 #define osd_invariant(obj) (1)
262 static inline struct osd_thread_info *osd_oti_get(const struct lu_env *env)
264 return lu_context_key_get(&env->le_ctx, &osd_key);
268 * Concurrency: doesn't matter
270 static int osd_read_locked(const struct lu_env *env, struct osd_object *o)
272 return osd_oti_get(env)->oti_r_locks > 0;
276 * Concurrency: doesn't matter
278 static int osd_write_locked(const struct lu_env *env, struct osd_object *o)
280 struct osd_thread_info *oti = osd_oti_get(env);
281 return oti->oti_w_locks > 0 && o->oo_owner == env;
285 * Concurrency: doesn't access mutable data
287 static int osd_root_get(const struct lu_env *env,
288 struct dt_device *dev, struct lu_fid *f)
292 inode = osd_sb(osd_dt_dev(dev))->s_root->d_inode;
293 lu_igif_build(f, inode->i_ino, inode->i_generation);
298 * OSD object methods.
302 * Concurrency: no concurrent access is possible that early in object
305 static struct lu_object *osd_object_alloc(const struct lu_env *env,
306 const struct lu_object_header *hdr,
309 struct osd_object *mo;
315 l = &mo->oo_dt.do_lu;
316 dt_object_init(&mo->oo_dt, NULL, d);
317 mo->oo_dt.do_ops = &osd_obj_ops;
318 l->lo_ops = &osd_lu_obj_ops;
319 init_rwsem(&mo->oo_sem);
320 spin_lock_init(&mo->oo_guard);
327 * Concurrency: shouldn't matter.
329 static void osd_object_init0(struct osd_object *obj)
331 LASSERT(obj->oo_inode != NULL);
332 obj->oo_dt.do_body_ops = &osd_body_ops;
333 obj->oo_dt.do_lu.lo_header->loh_attr |=
334 (LOHA_EXISTS | (obj->oo_inode->i_mode & S_IFMT));
338 * Concurrency: no concurrent access is possible that early in object
341 static int osd_object_init(const struct lu_env *env, struct lu_object *l,
342 const struct lu_object_conf *_)
344 struct osd_object *obj = osd_obj(l);
347 LINVRNT(osd_invariant(obj));
349 result = osd_fid_lookup(env, obj, lu_object_fid(l));
351 if (obj->oo_inode != NULL)
352 osd_object_init0(obj);
354 LINVRNT(osd_invariant(obj));
359 * Concurrency: no concurrent access is possible that late in object
362 static void osd_object_free(const struct lu_env *env, struct lu_object *l)
364 struct osd_object *obj = osd_obj(l);
366 LINVRNT(osd_invariant(obj));
368 dt_object_fini(&obj->oo_dt);
372 static struct iam_path_descr *osd_ipd_get(const struct lu_env *env,
373 const struct iam_container *bag)
375 return bag->ic_descr->id_ops->id_ipd_alloc(bag,
376 osd_oti_get(env)->oti_ipd);
379 static void osd_ipd_put(const struct lu_env *env,
380 const struct iam_container *bag,
381 struct iam_path_descr *ipd)
383 bag->ic_descr->id_ops->id_ipd_free(ipd);
387 * Concurrency: no concurrent access is possible that late in object
390 static void osd_index_fini(struct osd_object *o)
392 struct iam_container *bag;
394 if (o->oo_dir != NULL) {
395 bag = &o->oo_dir->od_container;
396 if (o->oo_inode != NULL) {
397 if (bag->ic_object == o->oo_inode)
398 iam_container_fini(bag);
400 OBD_FREE_PTR(o->oo_dir);
406 * Concurrency: no concurrent access is possible that late in object
407 * life-cycle (for all existing callers, that is. New callers have to provide
408 * their own locking.)
410 static int osd_inode_unlinked(const struct inode *inode)
412 return inode->i_nlink == 0;
416 OSD_TXN_OI_DELETE_CREDITS = 20,
417 OSD_TXN_INODE_DELETE_CREDITS = 20
421 * Concurrency: no concurrent access is possible that late in object
424 static int osd_inode_remove(const struct lu_env *env, struct osd_object *obj)
426 const struct lu_fid *fid = lu_object_fid(&obj->oo_dt.do_lu);
427 struct osd_device *osd = osd_obj2dev(obj);
428 struct osd_thread_info *oti = osd_oti_get(env);
429 struct txn_param *prm = &oti->oti_txn;
433 txn_param_init(prm, OSD_TXN_OI_DELETE_CREDITS +
434 OSD_TXN_INODE_DELETE_CREDITS);
435 th = osd_trans_start(env, &osd->od_dt_dev, prm);
437 result = osd_oi_delete(oti, &osd->od_oi, fid, th);
438 osd_trans_stop(env, th);
440 result = PTR_ERR(th);
445 * Called just before object is freed. Releases all resources except for
446 * object itself (that is released by osd_object_free()).
448 * Concurrency: no concurrent access is possible that late in object
451 static void osd_object_delete(const struct lu_env *env, struct lu_object *l)
453 struct osd_object *obj = osd_obj(l);
454 struct inode *inode = obj->oo_inode;
456 LINVRNT(osd_invariant(obj));
459 * If object is unlinked remove fid->ino mapping from object index.
461 * File body will be deleted by iput().
468 if (osd_inode_unlinked(inode)) {
469 result = osd_inode_remove(env, obj);
471 LU_OBJECT_DEBUG(D_ERROR, env, l,
472 "Failed to cleanup: %d\n",
476 obj->oo_inode = NULL;
481 * Concurrency: ->loo_object_release() is called under site spin-lock.
483 static void osd_object_release(const struct lu_env *env,
486 struct osd_object *o = osd_obj(l);
488 LASSERT(!lu_object_is_dying(l->lo_header));
489 if (o->oo_inode != NULL && osd_inode_unlinked(o->oo_inode))
490 set_bit(LU_OBJECT_HEARD_BANSHEE, &l->lo_header->loh_flags);
494 * Concurrency: shouldn't matter.
496 static int osd_object_print(const struct lu_env *env, void *cookie,
497 lu_printer_t p, const struct lu_object *l)
499 struct osd_object *o = osd_obj(l);
502 if (o->oo_dir != NULL)
503 d = o->oo_dir->od_container.ic_descr;
506 return (*p)(env, cookie, LUSTRE_OSD_NAME"-object@%p(i:%p:%lu/%u)[%s]",
508 o->oo_inode ? o->oo_inode->i_ino : 0UL,
509 o->oo_inode ? o->oo_inode->i_generation : 0,
510 d ? d->id_ops->id_name : "plain");
514 * Concurrency: shouldn't matter.
516 int osd_statfs(const struct lu_env *env, struct dt_device *d,
519 struct osd_device *osd = osd_dt_dev(d);
520 struct super_block *sb = osd_sb(osd);
523 spin_lock(&osd->od_osfs_lock);
525 if (cfs_time_before_64(osd->od_osfs_age, cfs_time_shift_64(-1))) {
526 result = ll_do_statfs(sb, &osd->od_kstatfs);
527 if (likely(result == 0)) /* N.B. statfs can't really fail */
528 osd->od_osfs_age = cfs_time_current_64();
531 if (likely(result == 0))
532 *sfs = osd->od_kstatfs;
533 spin_unlock(&osd->od_osfs_lock);
539 * Concurrency: doesn't access mutable data.
541 static void osd_conf_get(const struct lu_env *env,
542 const struct dt_device *dev,
543 struct dt_device_param *param)
546 * XXX should be taken from not-yet-existing fs abstraction layer.
548 param->ddp_max_name_len = LDISKFS_NAME_LEN;
549 param->ddp_max_nlink = LDISKFS_LINK_MAX;
550 param->ddp_block_shift = osd_sb(osd_dt_dev(dev))->s_blocksize_bits;
558 * Concurrency: doesn't access mutable data.
560 static int osd_param_is_sane(const struct osd_device *dev,
561 const struct txn_param *param)
563 return param->tp_credits <= osd_journal(dev)->j_max_transaction_buffers;
567 * Concurrency: shouldn't matter.
569 static void osd_trans_commit_cb(struct journal_callback *jcb, int error)
571 struct osd_thandle *oh = container_of0(jcb, struct osd_thandle, ot_jcb);
572 struct thandle *th = &oh->ot_super;
573 struct dt_device *dev = th->th_dev;
575 LASSERT(dev != NULL);
576 LASSERT(oh->ot_handle == NULL);
579 CERROR("transaction @0x%p commit error: %d\n", th, error);
581 struct lu_env *env = &osd_dt_dev(dev)->od_env_for_commit;
583 * This od_env_for_commit is only for commit usage. see
586 lu_context_enter(&env->le_ctx);
587 dt_txn_hook_commit(env, th);
588 lu_context_exit(&env->le_ctx);
591 lu_device_put(&dev->dd_lu_dev);
594 lu_context_exit(&th->th_ctx);
595 lu_context_fini(&th->th_ctx);
600 * Concurrency: shouldn't matter.
602 static struct thandle *osd_trans_start(const struct lu_env *env,
606 struct osd_device *dev = osd_dt_dev(d);
608 struct osd_thandle *oh;
614 hook_res = dt_txn_hook_start(env, d, p);
616 RETURN(ERR_PTR(hook_res));
618 if (osd_param_is_sane(dev, p)) {
619 OBD_ALLOC_GFP(oh, sizeof *oh, CFS_ALLOC_IO);
622 * XXX temporary stuff. Some abstraction layer should
626 jh = journal_start(osd_journal(dev), p->tp_credits);
632 jh->h_sync = p->tp_sync;
633 lu_device_get(&d->dd_lu_dev);
634 /* add commit callback */
635 lu_context_init(&th->th_ctx, LCT_TX_HANDLE);
636 lu_context_enter(&th->th_ctx);
637 journal_callback_set(jh, osd_trans_commit_cb,
638 (struct journal_callback *)&oh->ot_jcb);
641 struct osd_thread_info *oti =
644 LASSERT(oti->oti_txns == 0);
645 LASSERT(oti->oti_r_locks == 0);
646 LASSERT(oti->oti_w_locks == 0);
655 th = ERR_PTR(-ENOMEM);
657 CERROR("Invalid transaction parameters\n");
658 th = ERR_PTR(-EINVAL);
665 * Concurrency: shouldn't matter.
667 static void osd_trans_stop(const struct lu_env *env, struct thandle *th)
670 struct osd_thandle *oh;
671 struct osd_thread_info *oti = osd_oti_get(env);
675 oh = container_of0(th, struct osd_thandle, ot_super);
676 if (oh->ot_handle != NULL) {
677 handle_t *hdl = oh->ot_handle;
679 LASSERT(oti->oti_txns == 1);
681 LASSERT(oti->oti_r_locks == 0);
682 LASSERT(oti->oti_w_locks == 0);
683 result = dt_txn_hook_stop(env, th);
685 CERROR("Failure in transaction hook: %d\n", result);
686 oh->ot_handle = NULL;
687 result = journal_stop(hdl);
689 CERROR("Failure to stop transaction: %d\n", result);
695 * Concurrency: shouldn't matter.
697 static int osd_sync(const struct lu_env *env, struct dt_device *d)
699 CDEBUG(D_HA, "syncing OSD %s\n", LUSTRE_OSD_NAME);
700 return ldiskfs_force_commit(osd_sb(osd_dt_dev(d)));
704 * Concurrency: shouldn't matter.
706 lvfs_sbdev_type fsfilt_ldiskfs_journal_sbdev(struct super_block *);
708 static void osd_ro(const struct lu_env *env, struct dt_device *d)
712 CERROR("*** setting device %s read-only ***\n", LUSTRE_OSD_NAME);
714 __lvfs_set_rdonly(lvfs_sbdev(osd_sb(osd_dt_dev(d))),
715 fsfilt_ldiskfs_journal_sbdev(osd_sb(osd_dt_dev(d))));
720 * Concurrency: serialization provided by callers.
722 static int osd_init_capa_ctxt(const struct lu_env *env, struct dt_device *d,
723 int mode, unsigned long timeout, __u32 alg,
724 struct lustre_capa_key *keys)
726 struct osd_device *dev = osd_dt_dev(d);
729 dev->od_fl_capa = mode;
730 dev->od_capa_timeout = timeout;
731 dev->od_capa_alg = alg;
732 dev->od_capa_keys = keys;
736 /* Note: we did not count into QUOTA here, If we mount with --data_journal
738 static const int osd_dto_credits[DTO_NR] = {
740 * Insert/Delete. IAM EXT3_INDEX_EXTRA_TRANS_BLOCKS(8) +
741 * EXT3_SINGLEDATA_TRANS_BLOCKS 8 XXX Note: maybe iam need more,since
742 * iam have more level than Ext3 htree
744 [DTO_INDEX_INSERT] = 16,
745 [DTO_INDEX_DELETE] = 16,
746 [DTO_IDNEX_UPDATE] = 16,
748 * Create a object. Same as create object in Ext3 filesystem, but did
749 * not count QUOTA i EXT3_DATA_TRANS_BLOCKS(12) +
750 * INDEX_EXTRA_BLOCKS(8) + 3(inode bits,groups, GDT)
752 [DTO_OBJECT_CREATE] = 23,
753 [DTO_OBJECT_DELETE] = 23,
755 * Attr set credits 3 inode, group, GDT
759 * XATTR_SET. SAME AS XATTR of EXT3 EXT3_DATA_TRANS_BLOCKS XXX Note:
760 * in original MDS implmentation EXT3_INDEX_EXTRA_TRANS_BLOCKS are
761 * also counted in. Do not know why?
763 [DTO_XATTR_SET] = 16,
765 /* creadits for inode change during write */
766 [DTO_WRITE_BASE] = 3,
767 /* credits for single block write */
768 [DTO_WRITE_BLOCK] = 12
771 static int osd_credit_get(const struct lu_env *env, struct dt_device *d,
774 LASSERT(0 <= op && op < ARRAY_SIZE(osd_dto_credits));
775 return osd_dto_credits[op];
778 static struct dt_device_operations osd_dt_ops = {
779 .dt_root_get = osd_root_get,
780 .dt_statfs = osd_statfs,
781 .dt_trans_start = osd_trans_start,
782 .dt_trans_stop = osd_trans_stop,
783 .dt_conf_get = osd_conf_get,
786 .dt_credit_get = osd_credit_get,
787 .dt_init_capa_ctxt = osd_init_capa_ctxt,
790 static void osd_object_read_lock(const struct lu_env *env,
791 struct dt_object *dt, unsigned role)
793 struct osd_object *obj = osd_dt_obj(dt);
794 struct osd_thread_info *oti = osd_oti_get(env);
796 LINVRNT(osd_invariant(obj));
798 LASSERT(obj->oo_owner != env);
799 down_read_nested(&obj->oo_sem, role);
801 LASSERT(obj->oo_owner == NULL);
805 static void osd_object_write_lock(const struct lu_env *env,
806 struct dt_object *dt, unsigned role)
808 struct osd_object *obj = osd_dt_obj(dt);
809 struct osd_thread_info *oti = osd_oti_get(env);
811 LINVRNT(osd_invariant(obj));
813 LASSERT(obj->oo_owner != env);
814 down_write_nested(&obj->oo_sem, role);
816 LASSERT(obj->oo_owner == NULL);
821 static void osd_object_read_unlock(const struct lu_env *env,
822 struct dt_object *dt)
824 struct osd_object *obj = osd_dt_obj(dt);
825 struct osd_thread_info *oti = osd_oti_get(env);
827 LINVRNT(osd_invariant(obj));
829 LASSERT(oti->oti_r_locks > 0);
831 up_read(&obj->oo_sem);
834 static void osd_object_write_unlock(const struct lu_env *env,
835 struct dt_object *dt)
837 struct osd_object *obj = osd_dt_obj(dt);
838 struct osd_thread_info *oti = osd_oti_get(env);
840 LINVRNT(osd_invariant(obj));
842 LASSERT(obj->oo_owner == env);
843 LASSERT(oti->oti_w_locks > 0);
845 obj->oo_owner = NULL;
846 up_write(&obj->oo_sem);
849 static int capa_is_sane(const struct lu_env *env,
850 struct osd_device *dev,
851 struct lustre_capa *capa,
852 struct lustre_capa_key *keys)
854 struct osd_thread_info *oti = osd_oti_get(env);
859 oc = capa_lookup(dev->od_capa_hash, capa, 0);
861 if (capa_is_expired(oc)) {
862 DEBUG_CAPA(D_ERROR, capa, "expired");
869 spin_lock(&capa_lock);
870 for (i = 0; i < 2; i++) {
871 if (keys[i].lk_keyid == capa->lc_keyid) {
872 oti->oti_capa_key = keys[i];
876 spin_unlock(&capa_lock);
879 DEBUG_CAPA(D_ERROR, capa, "no matched capa key");
883 rc = capa_hmac(oti->oti_capa.lc_hmac, capa, oti->oti_capa_key.lk_key);
886 if (memcmp(oti->oti_capa.lc_hmac, capa->lc_hmac, sizeof(capa->lc_hmac)))
888 DEBUG_CAPA(D_ERROR, capa, "HMAC mismatch");
892 oc = capa_add(dev->od_capa_hash, capa);
898 static int osd_object_auth(const struct lu_env *env, struct dt_object *dt,
899 struct lustre_capa *capa, __u64 opc)
901 const struct lu_fid *fid = lu_object_fid(&dt->do_lu);
902 struct osd_device *dev = osd_dev(dt->do_lu.lo_dev);
905 if (!dev->od_fl_capa)
908 if (capa == BYPASS_CAPA)
912 CERROR("no capability is provided for fid "DFID"\n", PFID(fid));
916 if (!lu_fid_eq(fid, &capa->lc_fid)) {
917 DEBUG_CAPA(D_ERROR, capa, "fid "DFID" mismatch with",
922 if (!capa_opc_supported(capa, opc)) {
923 DEBUG_CAPA(D_ERROR, capa, "opc "LPX64" not supported by", opc);
927 if ((rc = capa_is_sane(env, dev, capa, dev->od_capa_keys))) {
928 DEBUG_CAPA(D_ERROR, capa, "insane (rc %d)", rc);
935 static int osd_attr_get(const struct lu_env *env,
936 struct dt_object *dt,
937 struct lu_attr *attr,
938 struct lustre_capa *capa)
940 struct osd_object *obj = osd_dt_obj(dt);
942 LASSERT(dt_object_exists(dt));
943 LINVRNT(osd_invariant(obj));
945 if (osd_object_auth(env, dt, capa, CAPA_OPC_META_READ))
948 spin_lock(&obj->oo_guard);
949 osd_inode_getattr(env, obj->oo_inode, attr);
950 spin_unlock(&obj->oo_guard);
954 static int osd_attr_set(const struct lu_env *env,
955 struct dt_object *dt,
956 const struct lu_attr *attr,
957 struct thandle *handle,
958 struct lustre_capa *capa)
960 struct osd_object *obj = osd_dt_obj(dt);
962 LASSERT(handle != NULL);
963 LASSERT(dt_object_exists(dt));
964 LASSERT(osd_invariant(obj));
966 if (osd_object_auth(env, dt, capa, CAPA_OPC_META_WRITE))
969 spin_lock(&obj->oo_guard);
970 osd_inode_setattr(env, obj->oo_inode, attr);
971 spin_unlock(&obj->oo_guard);
973 mark_inode_dirty(obj->oo_inode);
977 static struct timespec *osd_inode_time(const struct lu_env *env,
978 struct inode *inode, __u64 seconds)
980 struct osd_thread_info *oti = osd_oti_get(env);
981 struct timespec *t = &oti->oti_time;
985 *t = timespec_trunc(*t, get_sb_time_gran(inode->i_sb));
989 static void osd_inode_setattr(const struct lu_env *env,
990 struct inode *inode, const struct lu_attr *attr)
994 bits = attr->la_valid;
996 LASSERT(!(bits & LA_TYPE)); /* Huh? You want too much. */
999 inode->i_atime = *osd_inode_time(env, inode, attr->la_atime);
1000 if (bits & LA_CTIME)
1001 inode->i_ctime = *osd_inode_time(env, inode, attr->la_ctime);
1002 if (bits & LA_MTIME)
1003 inode->i_mtime = *osd_inode_time(env, inode, attr->la_mtime);
1004 if (bits & LA_SIZE) {
1005 LDISKFS_I(inode)->i_disksize = attr->la_size;
1006 i_size_write(inode, attr->la_size);
1008 if (bits & LA_BLOCKS)
1009 inode->i_blocks = attr->la_blocks;
1011 inode->i_mode = (inode->i_mode & S_IFMT) |
1012 (attr->la_mode & ~S_IFMT);
1014 inode->i_uid = attr->la_uid;
1016 inode->i_gid = attr->la_gid;
1017 if (bits & LA_NLINK)
1018 inode->i_nlink = attr->la_nlink;
1020 inode->i_rdev = attr->la_rdev;
1022 if (bits & LA_FLAGS) {
1023 struct ldiskfs_inode_info *li = LDISKFS_I(inode);
1025 li->i_flags = (li->i_flags & ~LDISKFS_FL_USER_MODIFIABLE) |
1026 (attr->la_flags & LDISKFS_FL_USER_MODIFIABLE);
1033 * XXX temporary solution.
1036 static int osd_create_pre(struct osd_thread_info *info, struct osd_object *obj,
1037 struct lu_attr *attr, struct thandle *th)
1042 static int osd_create_post(struct osd_thread_info *info, struct osd_object *obj,
1043 struct lu_attr *attr, struct thandle *th)
1045 LASSERT(obj->oo_inode != NULL);
1047 osd_object_init0(obj);
1051 extern struct inode *ldiskfs_create_inode(handle_t *handle,
1052 struct inode * dir, int mode);
1054 static int osd_mkfile(struct osd_thread_info *info, struct osd_object *obj,
1056 struct dt_allocation_hint *hint,
1060 struct osd_device *osd = osd_obj2dev(obj);
1061 struct osd_thandle *oth;
1062 struct inode *parent;
1063 struct inode *inode;
1065 LINVRNT(osd_invariant(obj));
1066 LASSERT(obj->oo_inode == NULL);
1067 LASSERT(osd->od_obj_area != NULL);
1069 oth = container_of(th, struct osd_thandle, ot_super);
1070 LASSERT(oth->ot_handle->h_transaction != NULL);
1072 if (hint && hint->dah_parent)
1073 parent = osd_dt_obj(hint->dah_parent)->oo_inode;
1075 parent = osd->od_obj_area->d_inode;
1076 LASSERT(parent->i_op != NULL);
1078 inode = ldiskfs_create_inode(oth->ot_handle, parent, mode);
1079 if (!IS_ERR(inode)) {
1080 obj->oo_inode = inode;
1083 result = PTR_ERR(inode);
1084 LINVRNT(osd_invariant(obj));
1089 extern int iam_lvar_create(struct inode *obj, int keysize, int ptrsize,
1090 int recsize, handle_t *handle);
1096 static int osd_mkdir(struct osd_thread_info *info, struct osd_object *obj,
1097 struct lu_attr *attr,
1098 struct dt_allocation_hint *hint,
1102 struct osd_thandle *oth;
1104 LASSERT(S_ISDIR(attr->la_mode));
1106 oth = container_of(th, struct osd_thandle, ot_super);
1107 LASSERT(oth->ot_handle->h_transaction != NULL);
1108 result = osd_mkfile(info, obj, (attr->la_mode &
1109 (S_IFMT | S_IRWXUGO | S_ISVTX)), hint, th);
1111 LASSERT(obj->oo_inode != NULL);
1113 * XXX uh-oh... call low-level iam function directly.
1115 result = iam_lvar_create(obj->oo_inode, OSD_NAME_LEN, 4,
1116 sizeof (struct lu_fid_pack),
1122 static int osd_mkreg(struct osd_thread_info *info, struct osd_object *obj,
1123 struct lu_attr *attr,
1124 struct dt_allocation_hint *hint,
1127 LASSERT(S_ISREG(attr->la_mode));
1128 return osd_mkfile(info, obj, (attr->la_mode &
1129 (S_IFMT | S_IRWXUGO | S_ISVTX)), hint, th);
1132 static int osd_mksym(struct osd_thread_info *info, struct osd_object *obj,
1133 struct lu_attr *attr,
1134 struct dt_allocation_hint *hint,
1137 LASSERT(S_ISLNK(attr->la_mode));
1138 return osd_mkfile(info, obj, (attr->la_mode &
1139 (S_IFMT | S_IRWXUGO | S_ISVTX)), hint, th);
1142 static int osd_mknod(struct osd_thread_info *info, struct osd_object *obj,
1143 struct lu_attr *attr,
1144 struct dt_allocation_hint *hint,
1148 struct osd_device *osd = osd_obj2dev(obj);
1150 umode_t mode = attr->la_mode & (S_IFMT | S_IRWXUGO | S_ISVTX);
1152 LINVRNT(osd_invariant(obj));
1153 LASSERT(obj->oo_inode == NULL);
1154 LASSERT(osd->od_obj_area != NULL);
1155 LASSERT(S_ISCHR(mode) || S_ISBLK(mode) ||
1156 S_ISFIFO(mode) || S_ISSOCK(mode));
1158 dir = osd->od_obj_area->d_inode;
1159 LASSERT(dir->i_op != NULL);
1161 result = osd_mkfile(info, obj, mode, hint, th);
1163 LASSERT(obj->oo_inode != NULL);
1164 init_special_inode(obj->oo_inode, mode, attr->la_rdev);
1166 LINVRNT(osd_invariant(obj));
1170 typedef int (*osd_obj_type_f)(struct osd_thread_info *, struct osd_object *,
1172 struct dt_allocation_hint *hint,
1175 static osd_obj_type_f osd_create_type_f(__u32 mode)
1177 osd_obj_type_f result;
1203 static void osd_ah_init(const struct lu_env *env, struct dt_allocation_hint *ah,
1204 struct dt_object *parent, umode_t child_mode)
1208 memset(ah, 0, sizeof(*ah));
1209 ah->dah_parent = parent;
1210 ah->dah_mode = child_mode;
1215 * Concurrency: @dt is write locked.
1217 static int osd_object_create(const struct lu_env *env, struct dt_object *dt,
1218 struct lu_attr *attr,
1219 struct dt_allocation_hint *hint,
1222 const struct lu_fid *fid = lu_object_fid(&dt->do_lu);
1223 struct osd_object *obj = osd_dt_obj(dt);
1224 struct osd_device *osd = osd_obj2dev(obj);
1225 struct osd_thread_info *info = osd_oti_get(env);
1230 LINVRNT(osd_invariant(obj));
1231 LASSERT(!dt_object_exists(dt));
1232 LASSERT(osd_write_locked(env, obj));
1233 LASSERT(th != NULL);
1236 * XXX missing: Quote handling.
1239 result = osd_create_pre(info, obj, attr, th);
1241 result = osd_create_type_f(attr->la_mode & S_IFMT)(info, obj,
1244 result = osd_create_post(info, obj, attr, th);
1247 struct osd_inode_id *id = &info->oti_id;
1249 LASSERT(obj->oo_inode != NULL);
1251 id->oii_ino = obj->oo_inode->i_ino;
1252 id->oii_gen = obj->oo_inode->i_generation;
1254 result = osd_oi_insert(info, &osd->od_oi, fid, id, th);
1257 LASSERT(ergo(result == 0, dt_object_exists(dt)));
1258 LINVRNT(osd_invariant(obj));
1263 * Concurrency: @dt is write locked.
1265 static void osd_object_ref_add(const struct lu_env *env,
1266 struct dt_object *dt,
1269 struct osd_object *obj = osd_dt_obj(dt);
1270 struct inode *inode = obj->oo_inode;
1272 LINVRNT(osd_invariant(obj));
1273 LASSERT(dt_object_exists(dt));
1274 LASSERT(osd_write_locked(env, obj));
1275 LASSERT(th != NULL);
1277 spin_lock(&obj->oo_guard);
1278 LASSERT(inode->i_nlink < LDISKFS_LINK_MAX);
1280 spin_unlock(&obj->oo_guard);
1281 mark_inode_dirty(inode);
1282 LINVRNT(osd_invariant(obj));
1286 * Concurrency: @dt is write locked.
1288 static void osd_object_ref_del(const struct lu_env *env,
1289 struct dt_object *dt,
1292 struct osd_object *obj = osd_dt_obj(dt);
1293 struct inode *inode = obj->oo_inode;
1295 LINVRNT(osd_invariant(obj));
1296 LASSERT(dt_object_exists(dt));
1297 LASSERT(osd_write_locked(env, obj));
1298 LASSERT(th != NULL);
1300 spin_lock(&obj->oo_guard);
1301 LASSERT(inode->i_nlink > 0);
1303 spin_unlock(&obj->oo_guard);
1304 mark_inode_dirty(inode);
1305 LINVRNT(osd_invariant(obj));
1309 * Concurrency: @dt is read locked.
1311 static int osd_xattr_get(const struct lu_env *env,
1312 struct dt_object *dt,
1315 struct lustre_capa *capa)
1317 struct osd_object *obj = osd_dt_obj(dt);
1318 struct inode *inode = obj->oo_inode;
1319 struct osd_thread_info *info = osd_oti_get(env);
1320 struct dentry *dentry = &info->oti_dentry;
1322 LASSERT(dt_object_exists(dt));
1323 LASSERT(inode->i_op != NULL && inode->i_op->getxattr != NULL);
1324 LASSERT(osd_read_locked(env, obj) || osd_write_locked(env, obj));
1326 if (osd_object_auth(env, dt, capa, CAPA_OPC_META_READ))
1329 dentry->d_inode = inode;
1330 return inode->i_op->getxattr(dentry, name, buf->lb_buf, buf->lb_len);
1334 * Concurrency: @dt is write locked.
1336 static int osd_xattr_set(const struct lu_env *env, struct dt_object *dt,
1337 const struct lu_buf *buf, const char *name, int fl,
1338 struct thandle *handle, struct lustre_capa *capa)
1340 struct osd_object *obj = osd_dt_obj(dt);
1341 struct inode *inode = obj->oo_inode;
1342 struct osd_thread_info *info = osd_oti_get(env);
1343 struct dentry *dentry = &info->oti_dentry;
1344 struct timespec *t = &info->oti_time;
1345 int fs_flags = 0, rc;
1347 LASSERT(dt_object_exists(dt));
1348 LASSERT(inode->i_op != NULL && inode->i_op->setxattr != NULL);
1349 LASSERT(osd_write_locked(env, obj));
1350 LASSERT(handle != NULL);
1352 if (osd_object_auth(env, dt, capa, CAPA_OPC_META_WRITE))
1355 if (fl & LU_XATTR_REPLACE)
1356 fs_flags |= XATTR_REPLACE;
1358 if (fl & LU_XATTR_CREATE)
1359 fs_flags |= XATTR_CREATE;
1361 dentry->d_inode = inode;
1362 *t = inode->i_ctime;
1363 rc = inode->i_op->setxattr(dentry, name,
1364 buf->lb_buf, buf->lb_len, fs_flags);
1365 if (likely(rc == 0)) {
1366 /* ctime should not be updated with server-side time. */
1367 spin_lock(&obj->oo_guard);
1368 inode->i_ctime = *t;
1369 spin_unlock(&obj->oo_guard);
1370 mark_inode_dirty(inode);
1376 * Concurrency: @dt is read locked.
1378 static int osd_xattr_list(const struct lu_env *env,
1379 struct dt_object *dt,
1381 struct lustre_capa *capa)
1383 struct osd_object *obj = osd_dt_obj(dt);
1384 struct inode *inode = obj->oo_inode;
1385 struct osd_thread_info *info = osd_oti_get(env);
1386 struct dentry *dentry = &info->oti_dentry;
1388 LASSERT(dt_object_exists(dt));
1389 LASSERT(inode->i_op != NULL && inode->i_op->listxattr != NULL);
1390 LASSERT(osd_read_locked(env, obj) || osd_write_locked(env, obj));
1392 if (osd_object_auth(env, dt, capa, CAPA_OPC_META_READ))
1395 dentry->d_inode = inode;
1396 return inode->i_op->listxattr(dentry, buf->lb_buf, buf->lb_len);
1400 * Concurrency: @dt is write locked.
1402 static int osd_xattr_del(const struct lu_env *env,
1403 struct dt_object *dt,
1405 struct thandle *handle,
1406 struct lustre_capa *capa)
1408 struct osd_object *obj = osd_dt_obj(dt);
1409 struct inode *inode = obj->oo_inode;
1410 struct osd_thread_info *info = osd_oti_get(env);
1411 struct dentry *dentry = &info->oti_dentry;
1412 struct timespec *t = &info->oti_time;
1415 LASSERT(dt_object_exists(dt));
1416 LASSERT(inode->i_op != NULL && inode->i_op->removexattr != NULL);
1417 LASSERT(osd_write_locked(env, obj));
1418 LASSERT(handle != NULL);
1420 if (osd_object_auth(env, dt, capa, CAPA_OPC_META_WRITE))
1423 dentry->d_inode = inode;
1424 *t = inode->i_ctime;
1425 rc = inode->i_op->removexattr(dentry, name);
1426 if (likely(rc == 0)) {
1427 /* ctime should not be updated with server-side time. */
1428 spin_lock(&obj->oo_guard);
1429 inode->i_ctime = *t;
1430 spin_unlock(&obj->oo_guard);
1431 mark_inode_dirty(inode);
1436 static struct obd_capa *osd_capa_get(const struct lu_env *env,
1437 struct dt_object *dt,
1438 struct lustre_capa *old,
1441 struct osd_thread_info *info = osd_oti_get(env);
1442 const struct lu_fid *fid = lu_object_fid(&dt->do_lu);
1443 struct osd_object *obj = osd_dt_obj(dt);
1444 struct osd_device *dev = osd_obj2dev(obj);
1445 struct lustre_capa_key *key = &info->oti_capa_key;
1446 struct lustre_capa *capa = &info->oti_capa;
1447 struct obd_capa *oc;
1451 if (!dev->od_fl_capa)
1452 RETURN(ERR_PTR(-ENOENT));
1454 LASSERT(dt_object_exists(dt));
1455 LINVRNT(osd_invariant(obj));
1457 /* renewal sanity check */
1458 if (old && osd_object_auth(env, dt, old, opc))
1459 RETURN(ERR_PTR(-EACCES));
1461 capa->lc_fid = *fid;
1464 capa->lc_flags = dev->od_capa_alg << 24;
1465 capa->lc_timeout = dev->od_capa_timeout;
1466 capa->lc_expiry = 0;
1468 oc = capa_lookup(dev->od_capa_hash, capa, 1);
1470 LASSERT(!capa_is_expired(oc));
1474 spin_lock(&capa_lock);
1475 *key = dev->od_capa_keys[1];
1476 spin_unlock(&capa_lock);
1478 capa->lc_keyid = key->lk_keyid;
1479 capa->lc_expiry = cfs_time_current_sec() + dev->od_capa_timeout;
1481 rc = capa_hmac(capa->lc_hmac, capa, key->lk_key);
1483 DEBUG_CAPA(D_ERROR, capa, "HMAC failed: %d for", rc);
1484 RETURN(ERR_PTR(rc));
1487 oc = capa_add(dev->od_capa_hash, capa);
1491 static int osd_object_sync(const struct lu_env *env, struct dt_object *dt)
1494 struct osd_object *obj = osd_dt_obj(dt);
1495 struct inode *inode = obj->oo_inode;
1496 struct osd_thread_info *info = osd_oti_get(env);
1497 struct dentry *dentry = &info->oti_dentry;
1498 struct file *file = &info->oti_file;
1501 dentry->d_inode = inode;
1502 file->f_dentry = dentry;
1503 file->f_mapping = inode->i_mapping;
1504 file->f_op = inode->i_fop;
1505 LOCK_INODE_MUTEX(inode);
1506 rc = file->f_op->fsync(file, dentry, 0);
1507 UNLOCK_INODE_MUTEX(inode);
1511 static struct dt_object_operations osd_obj_ops = {
1512 .do_read_lock = osd_object_read_lock,
1513 .do_write_lock = osd_object_write_lock,
1514 .do_read_unlock = osd_object_read_unlock,
1515 .do_write_unlock = osd_object_write_unlock,
1516 .do_attr_get = osd_attr_get,
1517 .do_attr_set = osd_attr_set,
1518 .do_ah_init = osd_ah_init,
1519 .do_create = osd_object_create,
1520 .do_index_try = osd_index_try,
1521 .do_ref_add = osd_object_ref_add,
1522 .do_ref_del = osd_object_ref_del,
1523 .do_xattr_get = osd_xattr_get,
1524 .do_xattr_set = osd_xattr_set,
1525 .do_xattr_del = osd_xattr_del,
1526 .do_xattr_list = osd_xattr_list,
1527 .do_capa_get = osd_capa_get,
1528 .do_object_sync = osd_object_sync,
1536 * XXX: Another layering violation for now.
1538 * We don't want to use ->f_op->read methods, because generic file write
1540 * - serializes on ->i_sem, and
1542 * - does a lot of extra work like balance_dirty_pages(),
1544 * which doesn't work for globally shared files like /last-received.
1546 int fsfilt_ldiskfs_read(struct inode *inode, void *buf, int size, loff_t *offs);
1547 int fsfilt_ldiskfs_write_handle(struct inode *inode, void *buf, int bufsize,
1548 loff_t *offs, handle_t *handle);
1550 static ssize_t osd_read(const struct lu_env *env, struct dt_object *dt,
1551 struct lu_buf *buf, loff_t *pos,
1552 struct lustre_capa *capa)
1554 struct inode *inode = osd_dt_obj(dt)->oo_inode;
1556 if (osd_object_auth(env, dt, capa, CAPA_OPC_BODY_READ))
1559 return fsfilt_ldiskfs_read(inode, buf->lb_buf, buf->lb_len, pos);
1562 static ssize_t osd_write(const struct lu_env *env, struct dt_object *dt,
1563 const struct lu_buf *buf, loff_t *pos,
1564 struct thandle *handle, struct lustre_capa *capa)
1566 struct inode *inode = osd_dt_obj(dt)->oo_inode;
1567 struct osd_thandle *oh;
1570 LASSERT(handle != NULL);
1572 if (osd_object_auth(env, dt, capa, CAPA_OPC_BODY_WRITE))
1575 oh = container_of(handle, struct osd_thandle, ot_super);
1576 LASSERT(oh->ot_handle->h_transaction != NULL);
1577 result = fsfilt_ldiskfs_write_handle(inode, buf->lb_buf, buf->lb_len,
1578 pos, oh->ot_handle);
1580 result = buf->lb_len;
1584 static struct dt_body_operations osd_body_ops = {
1585 .dbo_read = osd_read,
1586 .dbo_write = osd_write
1593 static int osd_object_is_root(const struct osd_object *obj)
1595 return osd_sb(osd_obj2dev(obj))->s_root->d_inode == obj->oo_inode;
1598 static int osd_index_probe(const struct lu_env *env, struct osd_object *o,
1599 const struct dt_index_features *feat)
1601 struct iam_descr *descr;
1603 if (osd_object_is_root(o))
1604 return feat == &dt_directory_features;
1606 LASSERT(o->oo_dir != NULL);
1608 descr = o->oo_dir->od_container.ic_descr;
1609 if (feat == &dt_directory_features)
1610 return descr == &iam_htree_compat_param ||
1611 (descr->id_rec_size == sizeof(struct lu_fid_pack) &&
1613 * XXX check that index looks like directory.
1618 feat->dif_keysize_min <= descr->id_key_size &&
1619 descr->id_key_size <= feat->dif_keysize_max &&
1620 feat->dif_recsize_min <= descr->id_rec_size &&
1621 descr->id_rec_size <= feat->dif_recsize_max &&
1622 !(feat->dif_flags & (DT_IND_VARKEY |
1623 DT_IND_VARREC | DT_IND_NONUNQ)) &&
1624 ergo(feat->dif_flags & DT_IND_UPDATE,
1625 1 /* XXX check that object (and file system) is
1629 static int osd_container_init(const struct lu_env *env,
1630 struct osd_object *obj,
1631 struct osd_directory *dir)
1634 struct iam_container *bag;
1636 bag = &dir->od_container;
1637 result = iam_container_init(bag, &dir->od_descr, obj->oo_inode);
1639 result = iam_container_setup(bag);
1641 obj->oo_dt.do_index_ops = &osd_index_ops;
1643 iam_container_fini(bag);
1649 * Concurrency: no external locking is necessary.
1651 static int osd_index_try(const struct lu_env *env, struct dt_object *dt,
1652 const struct dt_index_features *feat)
1655 struct osd_object *obj = osd_dt_obj(dt);
1657 LINVRNT(osd_invariant(obj));
1658 LASSERT(dt_object_exists(dt));
1660 if (osd_object_is_root(obj)) {
1661 dt->do_index_ops = &osd_index_compat_ops;
1663 } else if (!osd_has_index(obj)) {
1664 struct osd_directory *dir;
1668 sema_init(&dir->od_sem, 1);
1670 spin_lock(&obj->oo_guard);
1671 if (obj->oo_dir == NULL)
1675 * Concurrent thread allocated container data.
1678 spin_unlock(&obj->oo_guard);
1680 * Now, that we have container data, serialize its
1683 down(&obj->oo_dir->od_sem);
1685 * recheck under lock.
1687 if (!osd_has_index(obj))
1688 result = osd_container_init(env, obj, dir);
1691 up(&obj->oo_dir->od_sem);
1698 if (!osd_index_probe(env, obj, feat))
1701 LINVRNT(osd_invariant(obj));
1706 static int osd_index_delete(const struct lu_env *env, struct dt_object *dt,
1707 const struct dt_key *key, struct thandle *handle,
1708 struct lustre_capa *capa)
1710 struct osd_object *obj = osd_dt_obj(dt);
1711 struct osd_thandle *oh;
1712 struct iam_path_descr *ipd;
1713 struct iam_container *bag = &obj->oo_dir->od_container;
1718 LINVRNT(osd_invariant(obj));
1719 LASSERT(dt_object_exists(dt));
1720 LASSERT(bag->ic_object == obj->oo_inode);
1721 LASSERT(handle != NULL);
1723 if (osd_object_auth(env, dt, capa, CAPA_OPC_INDEX_DELETE))
1726 ipd = osd_ipd_get(env, bag);
1727 if (unlikely(ipd == NULL))
1730 oh = container_of0(handle, struct osd_thandle, ot_super);
1731 LASSERT(oh->ot_handle != NULL);
1732 LASSERT(oh->ot_handle->h_transaction != NULL);
1734 rc = iam_delete(oh->ot_handle, bag, (const struct iam_key *)key, ipd);
1735 osd_ipd_put(env, bag, ipd);
1736 LINVRNT(osd_invariant(obj));
1740 static int osd_index_lookup(const struct lu_env *env, struct dt_object *dt,
1741 struct dt_rec *rec, const struct dt_key *key,
1742 struct lustre_capa *capa)
1744 struct osd_object *obj = osd_dt_obj(dt);
1745 struct iam_path_descr *ipd;
1746 struct iam_container *bag = &obj->oo_dir->od_container;
1751 LINVRNT(osd_invariant(obj));
1752 LASSERT(dt_object_exists(dt));
1753 LASSERT(bag->ic_object == obj->oo_inode);
1755 if (osd_object_auth(env, dt, capa, CAPA_OPC_INDEX_LOOKUP))
1758 ipd = osd_ipd_get(env, bag);
1759 if (unlikely(ipd == NULL))
1762 rc = iam_lookup(bag, (const struct iam_key *)key,
1763 (struct iam_rec *)rec, ipd);
1764 osd_ipd_put(env, bag, ipd);
1765 LINVRNT(osd_invariant(obj));
1770 static int osd_index_insert(const struct lu_env *env, struct dt_object *dt,
1771 const struct dt_rec *rec, const struct dt_key *key,
1772 struct thandle *th, struct lustre_capa *capa)
1774 struct osd_object *obj = osd_dt_obj(dt);
1775 struct iam_path_descr *ipd;
1776 struct osd_thandle *oh;
1777 struct iam_container *bag = &obj->oo_dir->od_container;
1782 LINVRNT(osd_invariant(obj));
1783 LASSERT(dt_object_exists(dt));
1784 LASSERT(bag->ic_object == obj->oo_inode);
1785 LASSERT(th != NULL);
1787 if (osd_object_auth(env, dt, capa, CAPA_OPC_INDEX_INSERT))
1790 ipd = osd_ipd_get(env, bag);
1791 if (unlikely(ipd == NULL))
1794 oh = container_of0(th, struct osd_thandle, ot_super);
1795 LASSERT(oh->ot_handle != NULL);
1796 LASSERT(oh->ot_handle->h_transaction != NULL);
1797 rc = iam_insert(oh->ot_handle, bag, (const struct iam_key *)key,
1798 (struct iam_rec *)rec, ipd);
1799 osd_ipd_put(env, bag, ipd);
1800 LINVRNT(osd_invariant(obj));
1805 * Iterator operations.
1808 struct osd_object *oi_obj;
1809 struct iam_path_descr *oi_ipd;
1810 struct iam_iterator oi_it;
1813 static struct dt_it *osd_it_init(const struct lu_env *env,
1814 struct dt_object *dt, int writable,
1815 struct lustre_capa *capa)
1818 struct osd_object *obj = osd_dt_obj(dt);
1819 struct lu_object *lo = &dt->do_lu;
1820 struct iam_path_descr *ipd;
1821 struct iam_container *bag = &obj->oo_dir->od_container;
1824 LASSERT(lu_object_exists(lo));
1826 if (osd_object_auth(env, dt, capa, writable ? CAPA_OPC_BODY_WRITE :
1827 CAPA_OPC_BODY_READ))
1828 return ERR_PTR(-EACCES);
1830 flags = writable ? IAM_IT_MOVE|IAM_IT_WRITE : IAM_IT_MOVE;
1834 * XXX: as ipd is allocated within osd_thread_info, assignment
1835 * below implies that iterator usage is confined within single
1838 ipd = osd_ipd_get(env, bag);
1839 if (likely(ipd != NULL)) {
1843 iam_it_init(&it->oi_it, bag, flags, ipd);
1844 return (struct dt_it *)it;
1848 return ERR_PTR(-ENOMEM);
1851 static void osd_it_fini(const struct lu_env *env, struct dt_it *di)
1853 struct osd_it *it = (struct osd_it *)di;
1854 struct osd_object *obj = it->oi_obj;
1856 iam_it_fini(&it->oi_it);
1857 osd_ipd_put(env, &obj->oo_dir->od_container, it->oi_ipd);
1858 lu_object_put(env, &obj->oo_dt.do_lu);
1862 static int osd_it_get(const struct lu_env *env,
1863 struct dt_it *di, const struct dt_key *key)
1865 struct osd_it *it = (struct osd_it *)di;
1867 return iam_it_get(&it->oi_it, (const struct iam_key *)key);
1870 static void osd_it_put(const struct lu_env *env, struct dt_it *di)
1872 struct osd_it *it = (struct osd_it *)di;
1874 iam_it_put(&it->oi_it);
1877 static int osd_it_next(const struct lu_env *env, struct dt_it *di)
1879 struct osd_it *it = (struct osd_it *)di;
1881 return iam_it_next(&it->oi_it);
1884 static int osd_it_del(const struct lu_env *env, struct dt_it *di,
1887 struct osd_it *it = (struct osd_it *)di;
1888 struct osd_thandle *oh;
1890 LASSERT(th != NULL);
1892 oh = container_of0(th, struct osd_thandle, ot_super);
1893 LASSERT(oh->ot_handle != NULL);
1894 LASSERT(oh->ot_handle->h_transaction != NULL);
1896 return iam_it_rec_delete(oh->ot_handle, &it->oi_it);
1899 static struct dt_key *osd_it_key(const struct lu_env *env,
1900 const struct dt_it *di)
1902 struct osd_it *it = (struct osd_it *)di;
1904 return (struct dt_key *)iam_it_key_get(&it->oi_it);
1907 static int osd_it_key_size(const struct lu_env *env, const struct dt_it *di)
1909 struct osd_it *it = (struct osd_it *)di;
1911 return iam_it_key_size(&it->oi_it);
1914 static struct dt_rec *osd_it_rec(const struct lu_env *env,
1915 const struct dt_it *di)
1917 struct osd_it *it = (struct osd_it *)di;
1919 return (struct dt_rec *)iam_it_rec_get(&it->oi_it);
1922 static __u64 osd_it_store(const struct lu_env *env, const struct dt_it *di)
1924 struct osd_it *it = (struct osd_it *)di;
1926 return iam_it_store(&it->oi_it);
1929 static int osd_it_load(const struct lu_env *env,
1930 const struct dt_it *di, __u64 hash)
1932 struct osd_it *it = (struct osd_it *)di;
1934 return iam_it_load(&it->oi_it, hash);
1937 static struct dt_index_operations osd_index_ops = {
1938 .dio_lookup = osd_index_lookup,
1939 .dio_insert = osd_index_insert,
1940 .dio_delete = osd_index_delete,
1942 .init = osd_it_init,
1943 .fini = osd_it_fini,
1947 .next = osd_it_next,
1949 .key_size = osd_it_key_size,
1951 .store = osd_it_store,
1956 static int osd_index_compat_delete(const struct lu_env *env,
1957 struct dt_object *dt,
1958 const struct dt_key *key,
1959 struct thandle *handle,
1960 struct lustre_capa *capa)
1962 struct osd_object *obj = osd_dt_obj(dt);
1964 LASSERT(handle != NULL);
1965 LASSERT(S_ISDIR(obj->oo_inode->i_mode));
1969 if (osd_object_auth(env, dt, capa, CAPA_OPC_INDEX_DELETE))
1973 RETURN(-EOPNOTSUPP);
1977 * Compatibility index operations.
1981 static void osd_build_pack(const struct lu_env *env, struct osd_device *osd,
1982 struct dentry *dentry, struct lu_fid_pack *pack)
1984 struct inode *inode = dentry->d_inode;
1985 struct lu_fid *fid = &osd_oti_get(env)->oti_fid;
1987 lu_igif_build(fid, inode->i_ino, inode->i_generation);
1988 fid_cpu_to_be(fid, fid);
1989 pack->fp_len = sizeof *fid + 1;
1990 memcpy(pack->fp_area, fid, sizeof *fid);
1993 static int osd_index_compat_lookup(const struct lu_env *env,
1994 struct dt_object *dt,
1995 struct dt_rec *rec, const struct dt_key *key,
1996 struct lustre_capa *capa)
1998 struct osd_object *obj = osd_dt_obj(dt);
2000 struct osd_device *osd = osd_obj2dev(obj);
2001 struct osd_thread_info *info = osd_oti_get(env);
2007 * XXX temporary solution.
2009 struct dentry *dentry;
2010 struct dentry *parent;
2012 LINVRNT(osd_invariant(obj));
2013 LASSERT(S_ISDIR(obj->oo_inode->i_mode));
2014 LASSERT(osd_has_index(obj));
2016 if (osd_object_auth(env, dt, capa, CAPA_OPC_INDEX_LOOKUP))
2019 info->oti_str.name = (const char *)key;
2020 info->oti_str.len = strlen((const char *)key);
2022 dir = obj->oo_inode;
2023 LASSERT(dir->i_op != NULL && dir->i_op->lookup != NULL);
2025 parent = d_alloc_root(dir);
2029 dentry = d_alloc(parent, &info->oti_str);
2030 if (dentry != NULL) {
2034 * XXX passing NULL for nameidata should work for
2037 d = dir->i_op->lookup(dir, dentry, NULL);
2040 * normal case, result is in @dentry.
2042 if (dentry->d_inode != NULL) {
2043 osd_build_pack(env, osd, dentry,
2044 (struct lu_fid_pack *)rec);
2049 /* What? Disconnected alias? Ppheeeww... */
2050 CERROR("Aliasing where not expected\n");
2058 LINVRNT(osd_invariant(obj));
2062 static int osd_add_rec(struct osd_thread_info *info, struct osd_device *dev,
2063 struct inode *dir, struct inode *inode, const char *name)
2067 struct dentry *parent;
2071 info->oti_str.name = name;
2072 info->oti_str.len = strlen(name);
2074 LASSERT(atomic_read(&dir->i_count) > 0);
2076 old = d_alloc(dev->od_obj_area, &info->oti_str);
2078 d_instantiate(old, inode);
2080 LASSERT(atomic_read(&dir->i_count) > 0);
2081 parent = d_alloc_root(dir);
2082 if (parent != NULL) {
2084 LASSERT(atomic_read(&dir->i_count) > 1);
2085 new = d_alloc(parent, &info->oti_str);
2086 LASSERT(atomic_read(&dir->i_count) > 1);
2088 LASSERT(atomic_read(&dir->i_count) > 1);
2089 result = dir->i_op->link(old, dir, new);
2090 LASSERT(atomic_read(&dir->i_count) > 1);
2092 LASSERT(atomic_read(&dir->i_count) > 1);
2094 LASSERT(atomic_read(&dir->i_count) > 1);
2096 LASSERT(atomic_read(&dir->i_count) > 0);
2100 LASSERT(atomic_read(&dir->i_count) > 0);
2106 * XXX Temporary stuff.
2108 static int osd_index_compat_insert(const struct lu_env *env,
2109 struct dt_object *dt,
2110 const struct dt_rec *rec,
2111 const struct dt_key *key, struct thandle *th,
2112 struct lustre_capa *capa)
2114 struct osd_object *obj = osd_dt_obj(dt);
2116 const char *name = (const char *)key;
2118 struct lu_device *ludev = dt->do_lu.lo_dev;
2119 struct lu_object *luch;
2121 struct osd_thread_info *info = osd_oti_get(env);
2122 const struct lu_fid_pack *pack = (const struct lu_fid_pack *)rec;
2123 struct lu_fid *fid = &osd_oti_get(env)->oti_fid;
2127 LASSERT(S_ISDIR(obj->oo_inode->i_mode));
2128 LINVRNT(osd_invariant(obj));
2129 LASSERT(th != NULL);
2131 if (osd_object_auth(env, dt, capa, CAPA_OPC_INDEX_INSERT))
2134 result = fid_unpack(pack, fid);
2138 luch = lu_object_find(env, ludev, fid, NULL);
2139 if (!IS_ERR(luch)) {
2140 if (lu_object_exists(luch)) {
2141 struct osd_object *child;
2143 child = osd_obj(lu_object_locate(luch->lo_header,
2146 result = osd_add_rec(info, osd_obj2dev(obj),
2148 child->oo_inode, name);
2150 CERROR("No osd slice.\n");
2153 LINVRNT(osd_invariant(obj));
2154 LINVRNT(osd_invariant(child));
2159 lu_object_put(env, luch);
2161 result = PTR_ERR(luch);
2162 LINVRNT(osd_invariant(obj));
2166 static const struct dt_index_operations osd_index_compat_ops = {
2167 .dio_lookup = osd_index_compat_lookup,
2168 .dio_insert = osd_index_compat_insert,
2169 .dio_delete = osd_index_compat_delete
2172 /* type constructor/destructor: osd_type_init, osd_type_fini */
2173 LU_TYPE_INIT_FINI(osd, &osd_key);
2175 static struct lu_context_key osd_key = {
2176 .lct_tags = LCT_DT_THREAD | LCT_MD_THREAD,
2177 .lct_init = osd_key_init,
2178 .lct_fini = osd_key_fini,
2179 .lct_exit = osd_key_exit
2182 static void *osd_key_init(const struct lu_context *ctx,
2183 struct lu_context_key *key)
2185 struct osd_thread_info *info;
2187 OBD_ALLOC_PTR(info);
2189 info->oti_env = container_of(ctx, struct lu_env, le_ctx);
2191 info = ERR_PTR(-ENOMEM);
2195 /* context key destructor: osd_key_fini */
2196 LU_KEY_FINI(osd, struct osd_thread_info);
2198 static void osd_key_exit(const struct lu_context *ctx,
2199 struct lu_context_key *key, void *data)
2201 struct osd_thread_info *info = data;
2203 LASSERT(info->oti_r_locks == 0);
2204 LASSERT(info->oti_w_locks == 0);
2205 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, lmi->lmi_mnt, "*OBJ-TEMP*",
2268 result = PTR_ERR(d);
2271 osd_shutdown(env, o);
2275 static struct lu_device *osd_device_fini(const struct lu_env *env,
2276 struct lu_device *d)
2281 shrink_dcache_sb(osd_sb(osd_dev(d)));
2282 osd_sync(env, lu2dt_dev(d));
2284 rc = osd_procfs_fini(osd_dev(d));
2286 CERROR("proc fini error %d \n", rc);
2287 RETURN (ERR_PTR(rc));
2290 if (osd_dev(d)->od_mount)
2291 server_put_mount(osd_dev(d)->od_mount->lmi_name,
2292 osd_dev(d)->od_mount->lmi_mnt);
2293 osd_dev(d)->od_mount = NULL;
2295 lu_context_fini(&osd_dev(d)->od_env_for_commit.le_ctx);
2299 static struct lu_device *osd_device_alloc(const struct lu_env *env,
2300 struct lu_device_type *t,
2301 struct lustre_cfg *cfg)
2303 struct lu_device *l;
2304 struct osd_device *o;
2310 result = dt_device_init(&o->od_dt_dev, t);
2313 l->ld_ops = &osd_lu_ops;
2314 o->od_dt_dev.dd_ops = &osd_dt_ops;
2315 spin_lock_init(&o->od_osfs_lock);
2316 o->od_osfs_age = cfs_time_shift_64(-1000);
2317 o->od_capa_hash = init_capa_hash();
2318 if (o->od_capa_hash == NULL) {
2319 dt_device_fini(&o->od_dt_dev);
2320 l = ERR_PTR(-ENOMEM);
2323 l = ERR_PTR(result);
2328 l = ERR_PTR(-ENOMEM);
2332 static struct lu_device *osd_device_free(const struct lu_env *env,
2333 struct lu_device *d)
2335 struct osd_device *o = osd_dev(d);
2338 cleanup_capa_hash(o->od_capa_hash);
2339 dt_device_fini(&o->od_dt_dev);
2344 static int osd_process_config(const struct lu_env *env,
2345 struct lu_device *d, struct lustre_cfg *cfg)
2347 struct osd_device *o = osd_dev(d);
2351 switch(cfg->lcfg_command) {
2353 err = osd_mount(env, o, cfg);
2356 err = osd_shutdown(env, o);
2364 extern void ldiskfs_orphan_cleanup (struct super_block * sb,
2365 struct ldiskfs_super_block * es);
2367 static int osd_recovery_complete(const struct lu_env *env,
2368 struct lu_device *d)
2370 struct osd_device *o = osd_dev(d);
2372 /* TODO: orphans handling */
2373 ldiskfs_orphan_cleanup(osd_sb(o), LDISKFS_SB(osd_sb(o))->s_es);
2377 static struct inode *osd_iget(struct osd_thread_info *info,
2378 struct osd_device *dev,
2379 const struct osd_inode_id *id)
2381 struct inode *inode;
2383 inode = iget(osd_sb(dev), id->oii_ino);
2384 if (inode == NULL) {
2385 CERROR("no inode\n");
2386 inode = ERR_PTR(-EACCES);
2387 } else if (is_bad_inode(inode)) {
2388 CERROR("bad inode\n");
2390 inode = ERR_PTR(-ENOENT);
2391 } else if (inode->i_generation != id->oii_gen) {
2392 CERROR("stale inode\n");
2394 inode = ERR_PTR(-ESTALE);
2401 static int osd_fid_lookup(const struct lu_env *env,
2402 struct osd_object *obj, const struct lu_fid *fid)
2404 struct osd_thread_info *info;
2405 struct lu_device *ldev = obj->oo_dt.do_lu.lo_dev;
2406 struct osd_device *dev;
2407 struct osd_inode_id *id;
2409 struct inode *inode;
2412 LINVRNT(osd_invariant(obj));
2413 LASSERT(obj->oo_inode == NULL);
2414 LASSERT(fid_is_sane(fid));
2416 * This assertion checks that osd layer sees only local
2417 * fids. Unfortunately it is somewhat expensive (does a
2418 * cache-lookup). Disabling it for production/acceptance-testing.
2420 LASSERT(1 || fid_is_local(ldev->ld_site, fid));
2424 info = osd_oti_get(env);
2425 dev = osd_dev(ldev);
2429 if (OBD_FAIL_CHECK(OBD_FAIL_OST_ENOENT))
2432 result = osd_oi_lookup(info, oi, fid, id);
2434 inode = osd_iget(info, dev, id);
2435 if (!IS_ERR(inode)) {
2436 obj->oo_inode = inode;
2437 LASSERT(obj->oo_inode->i_sb == osd_sb(dev));
2441 * If fid wasn't found in oi, inode-less object is
2442 * created, for which lu_object_exists() returns
2443 * false. This is used in a (frequent) case when
2444 * objects are created as locking anchors or
2445 * place holders for objects yet to be created.
2447 result = PTR_ERR(inode);
2448 } else if (result == -ENOENT)
2450 LINVRNT(osd_invariant(obj));
2454 static void osd_inode_getattr(const struct lu_env *env,
2455 struct inode *inode, struct lu_attr *attr)
2457 attr->la_valid |= LA_ATIME | LA_MTIME | LA_CTIME | LA_MODE |
2458 LA_SIZE | LA_BLOCKS | LA_UID | LA_GID |
2459 LA_FLAGS | LA_NLINK | LA_RDEV | LA_BLKSIZE;
2461 attr->la_atime = LTIME_S(inode->i_atime);
2462 attr->la_mtime = LTIME_S(inode->i_mtime);
2463 attr->la_ctime = LTIME_S(inode->i_ctime);
2464 attr->la_mode = inode->i_mode;
2465 attr->la_size = i_size_read(inode);
2466 attr->la_blocks = inode->i_blocks;
2467 attr->la_uid = inode->i_uid;
2468 attr->la_gid = inode->i_gid;
2469 attr->la_flags = LDISKFS_I(inode)->i_flags;
2470 attr->la_nlink = inode->i_nlink;
2471 attr->la_rdev = inode->i_rdev;
2472 attr->la_blksize = ll_inode_blksize(inode);
2473 attr->la_blkbits = inode->i_blkbits;
2480 static int lu_device_is_osd(const struct lu_device *d)
2482 return ergo(d != NULL && d->ld_ops != NULL, d->ld_ops == &osd_lu_ops);
2485 static struct osd_object *osd_obj(const struct lu_object *o)
2487 LASSERT(lu_device_is_osd(o->lo_dev));
2488 return container_of0(o, struct osd_object, oo_dt.do_lu);
2491 static struct osd_device *osd_dt_dev(const struct dt_device *d)
2493 LASSERT(lu_device_is_osd(&d->dd_lu_dev));
2494 return container_of0(d, struct osd_device, od_dt_dev);
2497 static struct osd_device *osd_dev(const struct lu_device *d)
2499 LASSERT(lu_device_is_osd(d));
2500 return osd_dt_dev(container_of0(d, struct dt_device, dd_lu_dev));
2503 static struct osd_object *osd_dt_obj(const struct dt_object *d)
2505 return osd_obj(&d->do_lu);
2508 static struct osd_device *osd_obj2dev(const struct osd_object *o)
2510 return osd_dev(o->oo_dt.do_lu.lo_dev);
2513 static struct lu_device *osd2lu_dev(struct osd_device *osd)
2515 return &osd->od_dt_dev.dd_lu_dev;
2518 static struct super_block *osd_sb(const struct osd_device *dev)
2520 return dev->od_mount->lmi_mnt->mnt_sb;
2523 static journal_t *osd_journal(const struct osd_device *dev)
2525 return LDISKFS_SB(osd_sb(dev))->s_journal;
2528 static int osd_has_index(const struct osd_object *obj)
2530 return obj->oo_dt.do_index_ops != NULL;
2533 static int osd_object_invariant(const struct lu_object *l)
2535 return osd_invariant(osd_obj(l));
2538 static struct lu_object_operations osd_lu_obj_ops = {
2539 .loo_object_init = osd_object_init,
2540 .loo_object_delete = osd_object_delete,
2541 .loo_object_release = osd_object_release,
2542 .loo_object_free = osd_object_free,
2543 .loo_object_print = osd_object_print,
2544 .loo_object_invariant = osd_object_invariant
2547 static struct lu_device_operations osd_lu_ops = {
2548 .ldo_object_alloc = osd_object_alloc,
2549 .ldo_process_config = osd_process_config,
2550 .ldo_recovery_complete = osd_recovery_complete
2553 static struct lu_device_type_operations osd_device_type_ops = {
2554 .ldto_init = osd_type_init,
2555 .ldto_fini = osd_type_fini,
2557 .ldto_device_alloc = osd_device_alloc,
2558 .ldto_device_free = osd_device_free,
2560 .ldto_device_init = osd_device_init,
2561 .ldto_device_fini = osd_device_fini
2564 static struct lu_device_type osd_device_type = {
2565 .ldt_tags = LU_DEVICE_DT,
2566 .ldt_name = LUSTRE_OSD_NAME,
2567 .ldt_ops = &osd_device_type_ops,
2568 .ldt_ctx_tags = LCT_MD_THREAD|LCT_DT_THREAD
2572 * lprocfs legacy support.
2574 static struct obd_ops osd_obd_device_ops = {
2575 .o_owner = THIS_MODULE
2578 static int __init osd_mod_init(void)
2580 struct lprocfs_static_vars lvars;
2582 lprocfs_osd_init_vars(&lvars);
2583 return class_register_type(&osd_obd_device_ops, NULL, lvars.module_vars,
2584 LUSTRE_OSD_NAME, &osd_device_type);
2587 static void __exit osd_mod_exit(void)
2589 class_unregister_type(LUSTRE_OSD_NAME);
2592 MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");
2593 MODULE_DESCRIPTION("Lustre Object Storage Device ("LUSTRE_OSD_NAME")");
2594 MODULE_LICENSE("GPL");
2596 cfs_module(osd, "0.0.2", osd_mod_init, osd_mod_exit);