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 const struct lu_device_type_operations osd_device_type_ops;
220 static struct lu_device_type osd_device_type;
221 static const struct lu_object_operations osd_lu_obj_ops;
222 static struct obd_ops osd_obd_device_ops;
223 static const struct lu_device_operations osd_lu_ops;
224 static struct lu_context_key osd_key;
225 static const struct dt_object_operations osd_obj_ops;
226 static const struct dt_body_operations osd_body_ops;
227 static const struct dt_index_operations osd_index_ops;
228 static const struct dt_index_operations osd_index_compat_ops;
231 struct thandle ot_super;
233 struct journal_callback ot_jcb;
234 /* Link to the device, for debugging. */
235 struct lu_ref_link *ot_dev_link;
240 * Invariants, assertions.
244 * XXX: do not enable this, until invariant checking code is made thread safe
245 * in the face of pdirops locking.
247 #define OSD_INVARIANT_CHECKS (0)
249 #if OSD_INVARIANT_CHECKS
250 static int osd_invariant(const struct osd_object *obj)
254 ergo(obj->oo_inode != NULL,
255 obj->oo_inode->i_sb == osd_sb(osd_obj2dev(obj)) &&
256 atomic_read(&obj->oo_inode->i_count) > 0) &&
257 ergo(obj->oo_dir != NULL &&
258 obj->oo_dir->od_conationer.ic_object != NULL,
259 obj->oo_dir->od_conationer.ic_object == obj->oo_inode);
262 #define osd_invariant(obj) (1)
265 static inline struct osd_thread_info *osd_oti_get(const struct lu_env *env)
267 return lu_context_key_get(&env->le_ctx, &osd_key);
271 * Concurrency: doesn't matter
273 static int osd_read_locked(const struct lu_env *env, struct osd_object *o)
275 return osd_oti_get(env)->oti_r_locks > 0;
279 * Concurrency: doesn't matter
281 static int osd_write_locked(const struct lu_env *env, struct osd_object *o)
283 struct osd_thread_info *oti = osd_oti_get(env);
284 return oti->oti_w_locks > 0 && o->oo_owner == env;
288 * Concurrency: doesn't access mutable data
290 static int osd_root_get(const struct lu_env *env,
291 struct dt_device *dev, struct lu_fid *f)
295 inode = osd_sb(osd_dt_dev(dev))->s_root->d_inode;
296 lu_igif_build(f, inode->i_ino, inode->i_generation);
301 * OSD object methods.
305 * Concurrency: no concurrent access is possible that early in object
308 static struct lu_object *osd_object_alloc(const struct lu_env *env,
309 const struct lu_object_header *hdr,
312 struct osd_object *mo;
318 l = &mo->oo_dt.do_lu;
319 dt_object_init(&mo->oo_dt, NULL, d);
320 mo->oo_dt.do_ops = &osd_obj_ops;
321 l->lo_ops = &osd_lu_obj_ops;
322 init_rwsem(&mo->oo_sem);
323 spin_lock_init(&mo->oo_guard);
330 * Concurrency: shouldn't matter.
332 static void osd_object_init0(struct osd_object *obj)
334 LASSERT(obj->oo_inode != NULL);
335 obj->oo_dt.do_body_ops = &osd_body_ops;
336 obj->oo_dt.do_lu.lo_header->loh_attr |=
337 (LOHA_EXISTS | (obj->oo_inode->i_mode & S_IFMT));
341 * Concurrency: no concurrent access is possible that early in object
344 static int osd_object_init(const struct lu_env *env, struct lu_object *l,
345 const struct lu_object_conf *_)
347 struct osd_object *obj = osd_obj(l);
350 LINVRNT(osd_invariant(obj));
352 result = osd_fid_lookup(env, obj, lu_object_fid(l));
354 if (obj->oo_inode != NULL)
355 osd_object_init0(obj);
357 LINVRNT(osd_invariant(obj));
362 * Concurrency: no concurrent access is possible that late in object
365 static void osd_object_free(const struct lu_env *env, struct lu_object *l)
367 struct osd_object *obj = osd_obj(l);
369 LINVRNT(osd_invariant(obj));
371 dt_object_fini(&obj->oo_dt);
375 static struct iam_path_descr *osd_ipd_get(const struct lu_env *env,
376 const struct iam_container *bag)
378 return bag->ic_descr->id_ops->id_ipd_alloc(bag,
379 osd_oti_get(env)->oti_ipd);
382 static void osd_ipd_put(const struct lu_env *env,
383 const struct iam_container *bag,
384 struct iam_path_descr *ipd)
386 bag->ic_descr->id_ops->id_ipd_free(ipd);
390 * Concurrency: no concurrent access is possible that late in object
393 static void osd_index_fini(struct osd_object *o)
395 struct iam_container *bag;
397 if (o->oo_dir != NULL) {
398 bag = &o->oo_dir->od_container;
399 if (o->oo_inode != NULL) {
400 if (bag->ic_object == o->oo_inode)
401 iam_container_fini(bag);
403 OBD_FREE_PTR(o->oo_dir);
409 * Concurrency: no concurrent access is possible that late in object
410 * life-cycle (for all existing callers, that is. New callers have to provide
411 * their own locking.)
413 static int osd_inode_unlinked(const struct inode *inode)
415 return inode->i_nlink == 0;
419 OSD_TXN_OI_DELETE_CREDITS = 20,
420 OSD_TXN_INODE_DELETE_CREDITS = 20
424 * Concurrency: no concurrent access is possible that late in object
427 static int osd_inode_remove(const struct lu_env *env, struct osd_object *obj)
429 const struct lu_fid *fid = lu_object_fid(&obj->oo_dt.do_lu);
430 struct osd_device *osd = osd_obj2dev(obj);
431 struct osd_thread_info *oti = osd_oti_get(env);
432 struct txn_param *prm = &oti->oti_txn;
436 txn_param_init(prm, OSD_TXN_OI_DELETE_CREDITS +
437 OSD_TXN_INODE_DELETE_CREDITS);
438 th = osd_trans_start(env, &osd->od_dt_dev, prm);
440 result = osd_oi_delete(oti, &osd->od_oi, fid, th);
441 osd_trans_stop(env, th);
443 result = PTR_ERR(th);
448 * Called just before object is freed. Releases all resources except for
449 * object itself (that is released by osd_object_free()).
451 * Concurrency: no concurrent access is possible that late in object
454 static void osd_object_delete(const struct lu_env *env, struct lu_object *l)
456 struct osd_object *obj = osd_obj(l);
457 struct inode *inode = obj->oo_inode;
459 LINVRNT(osd_invariant(obj));
462 * If object is unlinked remove fid->ino mapping from object index.
464 * File body will be deleted by iput().
471 if (osd_inode_unlinked(inode)) {
472 result = osd_inode_remove(env, obj);
474 LU_OBJECT_DEBUG(D_ERROR, env, l,
475 "Failed to cleanup: %d\n",
479 obj->oo_inode = NULL;
484 * Concurrency: ->loo_object_release() is called under site spin-lock.
486 static void osd_object_release(const struct lu_env *env,
489 struct osd_object *o = osd_obj(l);
491 LASSERT(!lu_object_is_dying(l->lo_header));
492 if (o->oo_inode != NULL && osd_inode_unlinked(o->oo_inode))
493 set_bit(LU_OBJECT_HEARD_BANSHEE, &l->lo_header->loh_flags);
497 * Concurrency: shouldn't matter.
499 static int osd_object_print(const struct lu_env *env, void *cookie,
500 lu_printer_t p, const struct lu_object *l)
502 struct osd_object *o = osd_obj(l);
505 if (o->oo_dir != NULL)
506 d = o->oo_dir->od_container.ic_descr;
509 return (*p)(env, cookie, LUSTRE_OSD_NAME"-object@%p(i:%p:%lu/%u)[%s]",
511 o->oo_inode ? o->oo_inode->i_ino : 0UL,
512 o->oo_inode ? o->oo_inode->i_generation : 0,
513 d ? d->id_ops->id_name : "plain");
517 * Concurrency: shouldn't matter.
519 int osd_statfs(const struct lu_env *env, struct dt_device *d,
522 struct osd_device *osd = osd_dt_dev(d);
523 struct super_block *sb = osd_sb(osd);
526 spin_lock(&osd->od_osfs_lock);
528 if (cfs_time_before_64(osd->od_osfs_age, cfs_time_shift_64(-1))) {
529 result = ll_do_statfs(sb, &osd->od_kstatfs);
530 if (likely(result == 0)) /* N.B. statfs can't really fail */
531 osd->od_osfs_age = cfs_time_current_64();
534 if (likely(result == 0))
535 *sfs = osd->od_kstatfs;
536 spin_unlock(&osd->od_osfs_lock);
542 * Concurrency: doesn't access mutable data.
544 static void osd_conf_get(const struct lu_env *env,
545 const struct dt_device *dev,
546 struct dt_device_param *param)
549 * XXX should be taken from not-yet-existing fs abstraction layer.
551 param->ddp_max_name_len = LDISKFS_NAME_LEN;
552 param->ddp_max_nlink = LDISKFS_LINK_MAX;
553 param->ddp_block_shift = osd_sb(osd_dt_dev(dev))->s_blocksize_bits;
561 * Concurrency: doesn't access mutable data.
563 static int osd_param_is_sane(const struct osd_device *dev,
564 const struct txn_param *param)
566 return param->tp_credits <= osd_journal(dev)->j_max_transaction_buffers;
570 * Concurrency: shouldn't matter.
572 static void osd_trans_commit_cb(struct journal_callback *jcb, int error)
574 struct osd_thandle *oh = container_of0(jcb, struct osd_thandle, ot_jcb);
575 struct thandle *th = &oh->ot_super;
576 struct dt_device *dev = th->th_dev;
577 struct lu_device *lud = &dev->dd_lu_dev;
579 LASSERT(dev != NULL);
580 LASSERT(oh->ot_handle == NULL);
583 CERROR("transaction @0x%p commit error: %d\n", th, error);
585 struct lu_env *env = &osd_dt_dev(dev)->od_env_for_commit;
587 * This od_env_for_commit is only for commit usage. see
590 lu_context_enter(&env->le_ctx);
591 dt_txn_hook_commit(env, th);
592 lu_context_exit(&env->le_ctx);
595 lu_ref_del_at(&lud->ld_reference, oh->ot_dev_link, "osd-tx", th);
599 lu_context_exit(&th->th_ctx);
600 lu_context_fini(&th->th_ctx);
605 * Concurrency: shouldn't matter.
607 static struct thandle *osd_trans_start(const struct lu_env *env,
611 struct osd_device *dev = osd_dt_dev(d);
613 struct osd_thandle *oh;
619 hook_res = dt_txn_hook_start(env, d, p);
621 RETURN(ERR_PTR(hook_res));
623 if (osd_param_is_sane(dev, p)) {
624 OBD_ALLOC_GFP(oh, sizeof *oh, CFS_ALLOC_IO);
626 struct osd_thread_info *oti = osd_oti_get(env);
629 * XXX temporary stuff. Some abstraction layer should
633 jh = journal_start(osd_journal(dev), p->tp_credits);
639 jh->h_sync = p->tp_sync;
640 lu_device_get(&d->dd_lu_dev);
641 oh->ot_dev_link = lu_ref_add
642 (&d->dd_lu_dev.ld_reference,
644 /* add commit callback */
645 lu_context_init(&th->th_ctx, LCT_TX_HANDLE);
646 lu_context_enter(&th->th_ctx);
647 journal_callback_set(jh, osd_trans_commit_cb,
648 (struct journal_callback *)&oh->ot_jcb);
649 LASSERT(oti->oti_txns == 0);
650 LASSERT(oti->oti_r_locks == 0);
651 LASSERT(oti->oti_w_locks == 0);
658 th = ERR_PTR(-ENOMEM);
660 CERROR("Invalid transaction parameters\n");
661 th = ERR_PTR(-EINVAL);
668 * Concurrency: shouldn't matter.
670 static void osd_trans_stop(const struct lu_env *env, struct thandle *th)
673 struct osd_thandle *oh;
674 struct osd_thread_info *oti = osd_oti_get(env);
678 oh = container_of0(th, struct osd_thandle, ot_super);
679 if (oh->ot_handle != NULL) {
680 handle_t *hdl = oh->ot_handle;
682 LASSERT(oti->oti_txns == 1);
684 LASSERT(oti->oti_r_locks == 0);
685 LASSERT(oti->oti_w_locks == 0);
686 result = dt_txn_hook_stop(env, th);
688 CERROR("Failure in transaction hook: %d\n", result);
689 oh->ot_handle = NULL;
690 result = journal_stop(hdl);
692 CERROR("Failure to stop transaction: %d\n", result);
698 * Concurrency: shouldn't matter.
700 static int osd_sync(const struct lu_env *env, struct dt_device *d)
702 CDEBUG(D_HA, "syncing OSD %s\n", LUSTRE_OSD_NAME);
703 return ldiskfs_force_commit(osd_sb(osd_dt_dev(d)));
707 * Start commit for OSD device.
709 * An implementation of dt_commit_async method for OSD device.
710 * Asychronously starts underlayng fs sync and thereby a transaction
713 * \param env environment
716 * \see dt_device_operations
718 static int osd_commit_async(const struct lu_env *env,
721 struct super_block *s = osd_sb(osd_dt_dev(d));
724 CDEBUG(D_HA, "async commit OSD %s\n", LUSTRE_OSD_NAME);
725 RETURN(s->s_op->sync_fs(s, 0));
729 * Concurrency: shouldn't matter.
731 lvfs_sbdev_type fsfilt_ldiskfs_journal_sbdev(struct super_block *);
733 static void osd_ro(const struct lu_env *env, struct dt_device *d)
737 CERROR("*** setting device %s read-only ***\n", LUSTRE_OSD_NAME);
739 __lvfs_set_rdonly(lvfs_sbdev(osd_sb(osd_dt_dev(d))),
740 fsfilt_ldiskfs_journal_sbdev(osd_sb(osd_dt_dev(d))));
745 * Concurrency: serialization provided by callers.
747 static int osd_init_capa_ctxt(const struct lu_env *env, struct dt_device *d,
748 int mode, unsigned long timeout, __u32 alg,
749 struct lustre_capa_key *keys)
751 struct osd_device *dev = osd_dt_dev(d);
754 dev->od_fl_capa = mode;
755 dev->od_capa_timeout = timeout;
756 dev->od_capa_alg = alg;
757 dev->od_capa_keys = keys;
761 /* Note: we did not count into QUOTA here, If we mount with --data_journal
763 static const int osd_dto_credits[DTO_NR] = {
765 * Insert/Delete. IAM EXT3_INDEX_EXTRA_TRANS_BLOCKS(8) +
766 * EXT3_SINGLEDATA_TRANS_BLOCKS 8 XXX Note: maybe iam need more,since
767 * iam have more level than Ext3 htree
769 [DTO_INDEX_INSERT] = 16,
770 [DTO_INDEX_DELETE] = 16,
771 [DTO_IDNEX_UPDATE] = 16,
773 * Create a object. Same as create object in Ext3 filesystem, but did
774 * not count QUOTA i EXT3_DATA_TRANS_BLOCKS(12) +
775 * INDEX_EXTRA_BLOCKS(8) + 3(inode bits,groups, GDT)
777 [DTO_OBJECT_CREATE] = 23,
778 [DTO_OBJECT_DELETE] = 23,
780 * Attr set credits 3 inode, group, GDT
784 * XATTR_SET. SAME AS XATTR of EXT3 EXT3_DATA_TRANS_BLOCKS XXX Note:
785 * in original MDS implmentation EXT3_INDEX_EXTRA_TRANS_BLOCKS are
786 * also counted in. Do not know why?
788 [DTO_XATTR_SET] = 16,
790 /* creadits for inode change during write */
791 [DTO_WRITE_BASE] = 3,
792 /* credits for single block write */
793 [DTO_WRITE_BLOCK] = 12
796 static int osd_credit_get(const struct lu_env *env, struct dt_device *d,
799 LASSERT(0 <= op && op < ARRAY_SIZE(osd_dto_credits));
800 return osd_dto_credits[op];
803 static const struct dt_device_operations osd_dt_ops = {
804 .dt_root_get = osd_root_get,
805 .dt_statfs = osd_statfs,
806 .dt_trans_start = osd_trans_start,
807 .dt_trans_stop = osd_trans_stop,
808 .dt_conf_get = osd_conf_get,
811 .dt_commit_async = osd_commit_async,
812 .dt_credit_get = osd_credit_get,
813 .dt_init_capa_ctxt = osd_init_capa_ctxt,
816 static void osd_object_read_lock(const struct lu_env *env,
817 struct dt_object *dt, unsigned role)
819 struct osd_object *obj = osd_dt_obj(dt);
820 struct osd_thread_info *oti = osd_oti_get(env);
822 LINVRNT(osd_invariant(obj));
824 LASSERT(obj->oo_owner != env);
825 down_read_nested(&obj->oo_sem, role);
827 LASSERT(obj->oo_owner == NULL);
831 static void osd_object_write_lock(const struct lu_env *env,
832 struct dt_object *dt, unsigned role)
834 struct osd_object *obj = osd_dt_obj(dt);
835 struct osd_thread_info *oti = osd_oti_get(env);
837 LINVRNT(osd_invariant(obj));
839 LASSERT(obj->oo_owner != env);
840 down_write_nested(&obj->oo_sem, role);
842 LASSERT(obj->oo_owner == NULL);
847 static void osd_object_read_unlock(const struct lu_env *env,
848 struct dt_object *dt)
850 struct osd_object *obj = osd_dt_obj(dt);
851 struct osd_thread_info *oti = osd_oti_get(env);
853 LINVRNT(osd_invariant(obj));
855 LASSERT(oti->oti_r_locks > 0);
857 up_read(&obj->oo_sem);
860 static void osd_object_write_unlock(const struct lu_env *env,
861 struct dt_object *dt)
863 struct osd_object *obj = osd_dt_obj(dt);
864 struct osd_thread_info *oti = osd_oti_get(env);
866 LINVRNT(osd_invariant(obj));
868 LASSERT(obj->oo_owner == env);
869 LASSERT(oti->oti_w_locks > 0);
871 obj->oo_owner = NULL;
872 up_write(&obj->oo_sem);
875 static int capa_is_sane(const struct lu_env *env,
876 struct osd_device *dev,
877 struct lustre_capa *capa,
878 struct lustre_capa_key *keys)
880 struct osd_thread_info *oti = osd_oti_get(env);
885 oc = capa_lookup(dev->od_capa_hash, capa, 0);
887 if (capa_is_expired(oc)) {
888 DEBUG_CAPA(D_ERROR, capa, "expired");
895 spin_lock(&capa_lock);
896 for (i = 0; i < 2; i++) {
897 if (keys[i].lk_keyid == capa->lc_keyid) {
898 oti->oti_capa_key = keys[i];
902 spin_unlock(&capa_lock);
905 DEBUG_CAPA(D_ERROR, capa, "no matched capa key");
909 rc = capa_hmac(oti->oti_capa.lc_hmac, capa, oti->oti_capa_key.lk_key);
912 if (memcmp(oti->oti_capa.lc_hmac, capa->lc_hmac, sizeof(capa->lc_hmac)))
914 DEBUG_CAPA(D_ERROR, capa, "HMAC mismatch");
918 oc = capa_add(dev->od_capa_hash, capa);
924 static int osd_object_auth(const struct lu_env *env, struct dt_object *dt,
925 struct lustre_capa *capa, __u64 opc)
927 const struct lu_fid *fid = lu_object_fid(&dt->do_lu);
928 struct osd_device *dev = osd_dev(dt->do_lu.lo_dev);
931 if (!dev->od_fl_capa)
934 if (capa == BYPASS_CAPA)
938 CERROR("no capability is provided for fid "DFID"\n", PFID(fid));
942 if (!lu_fid_eq(fid, &capa->lc_fid)) {
943 DEBUG_CAPA(D_ERROR, capa, "fid "DFID" mismatch with",
948 if (!capa_opc_supported(capa, opc)) {
949 DEBUG_CAPA(D_ERROR, capa, "opc "LPX64" not supported by", opc);
953 if ((rc = capa_is_sane(env, dev, capa, dev->od_capa_keys))) {
954 DEBUG_CAPA(D_ERROR, capa, "insane (rc %d)", rc);
961 static int osd_attr_get(const struct lu_env *env,
962 struct dt_object *dt,
963 struct lu_attr *attr,
964 struct lustre_capa *capa)
966 struct osd_object *obj = osd_dt_obj(dt);
968 LASSERT(dt_object_exists(dt));
969 LINVRNT(osd_invariant(obj));
971 if (osd_object_auth(env, dt, capa, CAPA_OPC_META_READ))
974 spin_lock(&obj->oo_guard);
975 osd_inode_getattr(env, obj->oo_inode, attr);
976 spin_unlock(&obj->oo_guard);
980 static int osd_attr_set(const struct lu_env *env,
981 struct dt_object *dt,
982 const struct lu_attr *attr,
983 struct thandle *handle,
984 struct lustre_capa *capa)
986 struct osd_object *obj = osd_dt_obj(dt);
988 LASSERT(handle != NULL);
989 LASSERT(dt_object_exists(dt));
990 LASSERT(osd_invariant(obj));
992 if (osd_object_auth(env, dt, capa, CAPA_OPC_META_WRITE))
995 spin_lock(&obj->oo_guard);
996 osd_inode_setattr(env, obj->oo_inode, attr);
997 spin_unlock(&obj->oo_guard);
999 mark_inode_dirty(obj->oo_inode);
1003 static struct timespec *osd_inode_time(const struct lu_env *env,
1004 struct inode *inode, __u64 seconds)
1006 struct osd_thread_info *oti = osd_oti_get(env);
1007 struct timespec *t = &oti->oti_time;
1009 t->tv_sec = seconds;
1011 *t = timespec_trunc(*t, get_sb_time_gran(inode->i_sb));
1015 static void osd_inode_setattr(const struct lu_env *env,
1016 struct inode *inode, const struct lu_attr *attr)
1020 bits = attr->la_valid;
1022 LASSERT(!(bits & LA_TYPE)); /* Huh? You want too much. */
1024 if (bits & LA_ATIME)
1025 inode->i_atime = *osd_inode_time(env, inode, attr->la_atime);
1026 if (bits & LA_CTIME)
1027 inode->i_ctime = *osd_inode_time(env, inode, attr->la_ctime);
1028 if (bits & LA_MTIME)
1029 inode->i_mtime = *osd_inode_time(env, inode, attr->la_mtime);
1030 if (bits & LA_SIZE) {
1031 LDISKFS_I(inode)->i_disksize = attr->la_size;
1032 i_size_write(inode, attr->la_size);
1034 if (bits & LA_BLOCKS)
1035 inode->i_blocks = attr->la_blocks;
1037 inode->i_mode = (inode->i_mode & S_IFMT) |
1038 (attr->la_mode & ~S_IFMT);
1040 inode->i_uid = attr->la_uid;
1042 inode->i_gid = attr->la_gid;
1043 if (bits & LA_NLINK)
1044 inode->i_nlink = attr->la_nlink;
1046 inode->i_rdev = attr->la_rdev;
1048 if (bits & LA_FLAGS) {
1049 struct ldiskfs_inode_info *li = LDISKFS_I(inode);
1051 li->i_flags = (li->i_flags & ~LDISKFS_FL_USER_MODIFIABLE) |
1052 (attr->la_flags & LDISKFS_FL_USER_MODIFIABLE);
1059 * XXX temporary solution.
1062 static int osd_create_pre(struct osd_thread_info *info, struct osd_object *obj,
1063 struct lu_attr *attr, struct thandle *th)
1068 static int osd_create_post(struct osd_thread_info *info, struct osd_object *obj,
1069 struct lu_attr *attr, struct thandle *th)
1071 LASSERT(obj->oo_inode != NULL);
1073 osd_object_init0(obj);
1077 extern struct inode *ldiskfs_create_inode(handle_t *handle,
1078 struct inode * dir, int mode);
1080 static int osd_mkfile(struct osd_thread_info *info, struct osd_object *obj,
1082 struct dt_allocation_hint *hint,
1086 struct osd_device *osd = osd_obj2dev(obj);
1087 struct osd_thandle *oth;
1088 struct inode *parent;
1089 struct inode *inode;
1091 LINVRNT(osd_invariant(obj));
1092 LASSERT(obj->oo_inode == NULL);
1093 LASSERT(osd->od_obj_area != NULL);
1095 oth = container_of(th, struct osd_thandle, ot_super);
1096 LASSERT(oth->ot_handle->h_transaction != NULL);
1098 if (hint && hint->dah_parent)
1099 parent = osd_dt_obj(hint->dah_parent)->oo_inode;
1101 parent = osd->od_obj_area->d_inode;
1102 LASSERT(parent->i_op != NULL);
1104 inode = ldiskfs_create_inode(oth->ot_handle, parent, mode);
1105 if (!IS_ERR(inode)) {
1106 obj->oo_inode = inode;
1109 result = PTR_ERR(inode);
1110 LINVRNT(osd_invariant(obj));
1115 extern int iam_lvar_create(struct inode *obj, int keysize, int ptrsize,
1116 int recsize, handle_t *handle);
1122 static int osd_mkdir(struct osd_thread_info *info, struct osd_object *obj,
1123 struct lu_attr *attr,
1124 struct dt_allocation_hint *hint,
1128 struct osd_thandle *oth;
1130 LASSERT(S_ISDIR(attr->la_mode));
1132 oth = container_of(th, struct osd_thandle, ot_super);
1133 LASSERT(oth->ot_handle->h_transaction != NULL);
1134 result = osd_mkfile(info, obj, (attr->la_mode &
1135 (S_IFMT | S_IRWXUGO | S_ISVTX)), hint, th);
1137 LASSERT(obj->oo_inode != NULL);
1139 * XXX uh-oh... call low-level iam function directly.
1141 result = iam_lvar_create(obj->oo_inode, OSD_NAME_LEN, 4,
1142 sizeof (struct lu_fid_pack),
1148 static int osd_mkreg(struct osd_thread_info *info, struct osd_object *obj,
1149 struct lu_attr *attr,
1150 struct dt_allocation_hint *hint,
1153 LASSERT(S_ISREG(attr->la_mode));
1154 return osd_mkfile(info, obj, (attr->la_mode &
1155 (S_IFMT | S_IRWXUGO | S_ISVTX)), hint, th);
1158 static int osd_mksym(struct osd_thread_info *info, struct osd_object *obj,
1159 struct lu_attr *attr,
1160 struct dt_allocation_hint *hint,
1163 LASSERT(S_ISLNK(attr->la_mode));
1164 return osd_mkfile(info, obj, (attr->la_mode &
1165 (S_IFMT | S_IRWXUGO | S_ISVTX)), hint, th);
1168 static int osd_mknod(struct osd_thread_info *info, struct osd_object *obj,
1169 struct lu_attr *attr,
1170 struct dt_allocation_hint *hint,
1174 struct osd_device *osd = osd_obj2dev(obj);
1176 umode_t mode = attr->la_mode & (S_IFMT | S_IRWXUGO | S_ISVTX);
1178 LINVRNT(osd_invariant(obj));
1179 LASSERT(obj->oo_inode == NULL);
1180 LASSERT(osd->od_obj_area != NULL);
1181 LASSERT(S_ISCHR(mode) || S_ISBLK(mode) ||
1182 S_ISFIFO(mode) || S_ISSOCK(mode));
1184 dir = osd->od_obj_area->d_inode;
1185 LASSERT(dir->i_op != NULL);
1187 result = osd_mkfile(info, obj, mode, hint, th);
1189 LASSERT(obj->oo_inode != NULL);
1190 init_special_inode(obj->oo_inode, mode, attr->la_rdev);
1192 LINVRNT(osd_invariant(obj));
1196 typedef int (*osd_obj_type_f)(struct osd_thread_info *, struct osd_object *,
1198 struct dt_allocation_hint *hint,
1201 static osd_obj_type_f osd_create_type_f(__u32 mode)
1203 osd_obj_type_f result;
1229 static void osd_ah_init(const struct lu_env *env, struct dt_allocation_hint *ah,
1230 struct dt_object *parent, umode_t child_mode)
1234 memset(ah, 0, sizeof(*ah));
1235 ah->dah_parent = parent;
1236 ah->dah_mode = child_mode;
1241 * Concurrency: @dt is write locked.
1243 static int osd_object_create(const struct lu_env *env, struct dt_object *dt,
1244 struct lu_attr *attr,
1245 struct dt_allocation_hint *hint,
1248 const struct lu_fid *fid = lu_object_fid(&dt->do_lu);
1249 struct osd_object *obj = osd_dt_obj(dt);
1250 struct osd_device *osd = osd_obj2dev(obj);
1251 struct osd_thread_info *info = osd_oti_get(env);
1256 LINVRNT(osd_invariant(obj));
1257 LASSERT(!dt_object_exists(dt));
1258 LASSERT(osd_write_locked(env, obj));
1259 LASSERT(th != NULL);
1262 * XXX missing: Quote handling.
1265 result = osd_create_pre(info, obj, attr, th);
1267 result = osd_create_type_f(attr->la_mode & S_IFMT)(info, obj,
1270 result = osd_create_post(info, obj, attr, th);
1273 struct osd_inode_id *id = &info->oti_id;
1275 LASSERT(obj->oo_inode != NULL);
1277 id->oii_ino = obj->oo_inode->i_ino;
1278 id->oii_gen = obj->oo_inode->i_generation;
1280 result = osd_oi_insert(info, &osd->od_oi, fid, id, th);
1283 LASSERT(ergo(result == 0, dt_object_exists(dt)));
1284 LINVRNT(osd_invariant(obj));
1289 * Concurrency: @dt is write locked.
1291 static void osd_object_ref_add(const struct lu_env *env,
1292 struct dt_object *dt,
1295 struct osd_object *obj = osd_dt_obj(dt);
1296 struct inode *inode = obj->oo_inode;
1298 LINVRNT(osd_invariant(obj));
1299 LASSERT(dt_object_exists(dt));
1300 LASSERT(osd_write_locked(env, obj));
1301 LASSERT(th != NULL);
1303 spin_lock(&obj->oo_guard);
1304 LASSERT(inode->i_nlink < LDISKFS_LINK_MAX);
1306 spin_unlock(&obj->oo_guard);
1307 mark_inode_dirty(inode);
1308 LINVRNT(osd_invariant(obj));
1312 * Concurrency: @dt is write locked.
1314 static void osd_object_ref_del(const struct lu_env *env,
1315 struct dt_object *dt,
1318 struct osd_object *obj = osd_dt_obj(dt);
1319 struct inode *inode = obj->oo_inode;
1321 LINVRNT(osd_invariant(obj));
1322 LASSERT(dt_object_exists(dt));
1323 LASSERT(osd_write_locked(env, obj));
1324 LASSERT(th != NULL);
1326 spin_lock(&obj->oo_guard);
1327 LASSERT(inode->i_nlink > 0);
1329 spin_unlock(&obj->oo_guard);
1330 mark_inode_dirty(inode);
1331 LINVRNT(osd_invariant(obj));
1335 * Concurrency: @dt is read locked.
1337 static int osd_xattr_get(const struct lu_env *env,
1338 struct dt_object *dt,
1341 struct lustre_capa *capa)
1343 struct osd_object *obj = osd_dt_obj(dt);
1344 struct inode *inode = obj->oo_inode;
1345 struct osd_thread_info *info = osd_oti_get(env);
1346 struct dentry *dentry = &info->oti_dentry;
1348 LASSERT(dt_object_exists(dt));
1349 LASSERT(inode->i_op != NULL && inode->i_op->getxattr != NULL);
1350 LASSERT(osd_read_locked(env, obj) || osd_write_locked(env, obj));
1352 if (osd_object_auth(env, dt, capa, CAPA_OPC_META_READ))
1355 dentry->d_inode = inode;
1356 return inode->i_op->getxattr(dentry, name, buf->lb_buf, buf->lb_len);
1360 * Concurrency: @dt is write locked.
1362 static int osd_xattr_set(const struct lu_env *env, struct dt_object *dt,
1363 const struct lu_buf *buf, const char *name, int fl,
1364 struct thandle *handle, struct lustre_capa *capa)
1366 struct osd_object *obj = osd_dt_obj(dt);
1367 struct inode *inode = obj->oo_inode;
1368 struct osd_thread_info *info = osd_oti_get(env);
1369 struct dentry *dentry = &info->oti_dentry;
1370 struct timespec *t = &info->oti_time;
1371 int fs_flags = 0, rc;
1373 LASSERT(dt_object_exists(dt));
1374 LASSERT(inode->i_op != NULL && inode->i_op->setxattr != NULL);
1375 LASSERT(osd_write_locked(env, obj));
1376 LASSERT(handle != NULL);
1378 if (osd_object_auth(env, dt, capa, CAPA_OPC_META_WRITE))
1381 if (fl & LU_XATTR_REPLACE)
1382 fs_flags |= XATTR_REPLACE;
1384 if (fl & LU_XATTR_CREATE)
1385 fs_flags |= XATTR_CREATE;
1387 dentry->d_inode = inode;
1388 *t = inode->i_ctime;
1389 rc = inode->i_op->setxattr(dentry, name,
1390 buf->lb_buf, buf->lb_len, fs_flags);
1391 if (likely(rc == 0)) {
1392 /* ctime should not be updated with server-side time. */
1393 spin_lock(&obj->oo_guard);
1394 inode->i_ctime = *t;
1395 spin_unlock(&obj->oo_guard);
1396 mark_inode_dirty(inode);
1402 * Concurrency: @dt is read locked.
1404 static int osd_xattr_list(const struct lu_env *env,
1405 struct dt_object *dt,
1407 struct lustre_capa *capa)
1409 struct osd_object *obj = osd_dt_obj(dt);
1410 struct inode *inode = obj->oo_inode;
1411 struct osd_thread_info *info = osd_oti_get(env);
1412 struct dentry *dentry = &info->oti_dentry;
1414 LASSERT(dt_object_exists(dt));
1415 LASSERT(inode->i_op != NULL && inode->i_op->listxattr != NULL);
1416 LASSERT(osd_read_locked(env, obj) || osd_write_locked(env, obj));
1418 if (osd_object_auth(env, dt, capa, CAPA_OPC_META_READ))
1421 dentry->d_inode = inode;
1422 return inode->i_op->listxattr(dentry, buf->lb_buf, buf->lb_len);
1426 * Concurrency: @dt is write locked.
1428 static int osd_xattr_del(const struct lu_env *env,
1429 struct dt_object *dt,
1431 struct thandle *handle,
1432 struct lustre_capa *capa)
1434 struct osd_object *obj = osd_dt_obj(dt);
1435 struct inode *inode = obj->oo_inode;
1436 struct osd_thread_info *info = osd_oti_get(env);
1437 struct dentry *dentry = &info->oti_dentry;
1438 struct timespec *t = &info->oti_time;
1441 LASSERT(dt_object_exists(dt));
1442 LASSERT(inode->i_op != NULL && inode->i_op->removexattr != NULL);
1443 LASSERT(osd_write_locked(env, obj));
1444 LASSERT(handle != NULL);
1446 if (osd_object_auth(env, dt, capa, CAPA_OPC_META_WRITE))
1449 dentry->d_inode = inode;
1450 *t = inode->i_ctime;
1451 rc = inode->i_op->removexattr(dentry, name);
1452 if (likely(rc == 0)) {
1453 /* ctime should not be updated with server-side time. */
1454 spin_lock(&obj->oo_guard);
1455 inode->i_ctime = *t;
1456 spin_unlock(&obj->oo_guard);
1457 mark_inode_dirty(inode);
1462 static struct obd_capa *osd_capa_get(const struct lu_env *env,
1463 struct dt_object *dt,
1464 struct lustre_capa *old,
1467 struct osd_thread_info *info = osd_oti_get(env);
1468 const struct lu_fid *fid = lu_object_fid(&dt->do_lu);
1469 struct osd_object *obj = osd_dt_obj(dt);
1470 struct osd_device *dev = osd_obj2dev(obj);
1471 struct lustre_capa_key *key = &info->oti_capa_key;
1472 struct lustre_capa *capa = &info->oti_capa;
1473 struct obd_capa *oc;
1477 if (!dev->od_fl_capa)
1478 RETURN(ERR_PTR(-ENOENT));
1480 LASSERT(dt_object_exists(dt));
1481 LINVRNT(osd_invariant(obj));
1483 /* renewal sanity check */
1484 if (old && osd_object_auth(env, dt, old, opc))
1485 RETURN(ERR_PTR(-EACCES));
1487 capa->lc_fid = *fid;
1490 capa->lc_flags = dev->od_capa_alg << 24;
1491 capa->lc_timeout = dev->od_capa_timeout;
1492 capa->lc_expiry = 0;
1494 oc = capa_lookup(dev->od_capa_hash, capa, 1);
1496 LASSERT(!capa_is_expired(oc));
1500 spin_lock(&capa_lock);
1501 *key = dev->od_capa_keys[1];
1502 spin_unlock(&capa_lock);
1504 capa->lc_keyid = key->lk_keyid;
1505 capa->lc_expiry = cfs_time_current_sec() + dev->od_capa_timeout;
1507 rc = capa_hmac(capa->lc_hmac, capa, key->lk_key);
1509 DEBUG_CAPA(D_ERROR, capa, "HMAC failed: %d for", rc);
1510 RETURN(ERR_PTR(rc));
1513 oc = capa_add(dev->od_capa_hash, capa);
1517 static int osd_object_sync(const struct lu_env *env, struct dt_object *dt)
1520 struct osd_object *obj = osd_dt_obj(dt);
1521 struct inode *inode = obj->oo_inode;
1522 struct osd_thread_info *info = osd_oti_get(env);
1523 struct dentry *dentry = &info->oti_dentry;
1524 struct file *file = &info->oti_file;
1527 dentry->d_inode = inode;
1528 file->f_dentry = dentry;
1529 file->f_mapping = inode->i_mapping;
1530 file->f_op = inode->i_fop;
1531 LOCK_INODE_MUTEX(inode);
1532 rc = file->f_op->fsync(file, dentry, 0);
1533 UNLOCK_INODE_MUTEX(inode);
1537 static const struct dt_object_operations osd_obj_ops = {
1538 .do_read_lock = osd_object_read_lock,
1539 .do_write_lock = osd_object_write_lock,
1540 .do_read_unlock = osd_object_read_unlock,
1541 .do_write_unlock = osd_object_write_unlock,
1542 .do_attr_get = osd_attr_get,
1543 .do_attr_set = osd_attr_set,
1544 .do_ah_init = osd_ah_init,
1545 .do_create = osd_object_create,
1546 .do_index_try = osd_index_try,
1547 .do_ref_add = osd_object_ref_add,
1548 .do_ref_del = osd_object_ref_del,
1549 .do_xattr_get = osd_xattr_get,
1550 .do_xattr_set = osd_xattr_set,
1551 .do_xattr_del = osd_xattr_del,
1552 .do_xattr_list = osd_xattr_list,
1553 .do_capa_get = osd_capa_get,
1554 .do_object_sync = osd_object_sync,
1562 * XXX: Another layering violation for now.
1564 * We don't want to use ->f_op->read methods, because generic file write
1566 * - serializes on ->i_sem, and
1568 * - does a lot of extra work like balance_dirty_pages(),
1570 * which doesn't work for globally shared files like /last-received.
1572 int fsfilt_ldiskfs_read(struct inode *inode, void *buf, int size, loff_t *offs);
1573 int fsfilt_ldiskfs_write_handle(struct inode *inode, void *buf, int bufsize,
1574 loff_t *offs, handle_t *handle);
1576 static ssize_t osd_read(const struct lu_env *env, struct dt_object *dt,
1577 struct lu_buf *buf, loff_t *pos,
1578 struct lustre_capa *capa)
1580 struct inode *inode = osd_dt_obj(dt)->oo_inode;
1582 if (osd_object_auth(env, dt, capa, CAPA_OPC_BODY_READ))
1585 return fsfilt_ldiskfs_read(inode, buf->lb_buf, buf->lb_len, pos);
1588 static ssize_t osd_write(const struct lu_env *env, struct dt_object *dt,
1589 const struct lu_buf *buf, loff_t *pos,
1590 struct thandle *handle, struct lustre_capa *capa)
1592 struct inode *inode = osd_dt_obj(dt)->oo_inode;
1593 struct osd_thandle *oh;
1596 LASSERT(handle != NULL);
1598 if (osd_object_auth(env, dt, capa, CAPA_OPC_BODY_WRITE))
1601 oh = container_of(handle, struct osd_thandle, ot_super);
1602 LASSERT(oh->ot_handle->h_transaction != NULL);
1603 result = fsfilt_ldiskfs_write_handle(inode, buf->lb_buf, buf->lb_len,
1604 pos, oh->ot_handle);
1606 result = buf->lb_len;
1610 static const struct dt_body_operations osd_body_ops = {
1611 .dbo_read = osd_read,
1612 .dbo_write = osd_write
1619 static int osd_object_is_root(const struct osd_object *obj)
1621 return osd_sb(osd_obj2dev(obj))->s_root->d_inode == obj->oo_inode;
1624 static int osd_index_probe(const struct lu_env *env, struct osd_object *o,
1625 const struct dt_index_features *feat)
1627 struct iam_descr *descr;
1629 if (osd_object_is_root(o))
1630 return feat == &dt_directory_features;
1632 LASSERT(o->oo_dir != NULL);
1634 descr = o->oo_dir->od_container.ic_descr;
1635 if (feat == &dt_directory_features)
1636 return descr == &iam_htree_compat_param ||
1637 (descr->id_rec_size == sizeof(struct lu_fid_pack) &&
1639 * XXX check that index looks like directory.
1644 feat->dif_keysize_min <= descr->id_key_size &&
1645 descr->id_key_size <= feat->dif_keysize_max &&
1646 feat->dif_recsize_min <= descr->id_rec_size &&
1647 descr->id_rec_size <= feat->dif_recsize_max &&
1648 !(feat->dif_flags & (DT_IND_VARKEY |
1649 DT_IND_VARREC | DT_IND_NONUNQ)) &&
1650 ergo(feat->dif_flags & DT_IND_UPDATE,
1651 1 /* XXX check that object (and file system) is
1655 static int osd_container_init(const struct lu_env *env,
1656 struct osd_object *obj,
1657 struct osd_directory *dir)
1660 struct iam_container *bag;
1662 bag = &dir->od_container;
1663 result = iam_container_init(bag, &dir->od_descr, obj->oo_inode);
1665 result = iam_container_setup(bag);
1667 obj->oo_dt.do_index_ops = &osd_index_ops;
1669 iam_container_fini(bag);
1675 * Concurrency: no external locking is necessary.
1677 static int osd_index_try(const struct lu_env *env, struct dt_object *dt,
1678 const struct dt_index_features *feat)
1681 struct osd_object *obj = osd_dt_obj(dt);
1683 LINVRNT(osd_invariant(obj));
1684 LASSERT(dt_object_exists(dt));
1686 if (osd_object_is_root(obj)) {
1687 dt->do_index_ops = &osd_index_compat_ops;
1689 } else if (!osd_has_index(obj)) {
1690 struct osd_directory *dir;
1694 sema_init(&dir->od_sem, 1);
1696 spin_lock(&obj->oo_guard);
1697 if (obj->oo_dir == NULL)
1701 * Concurrent thread allocated container data.
1704 spin_unlock(&obj->oo_guard);
1706 * Now, that we have container data, serialize its
1709 down(&obj->oo_dir->od_sem);
1711 * recheck under lock.
1713 if (!osd_has_index(obj))
1714 result = osd_container_init(env, obj, dir);
1717 up(&obj->oo_dir->od_sem);
1724 if (!osd_index_probe(env, obj, feat))
1727 LINVRNT(osd_invariant(obj));
1732 static int osd_index_delete(const struct lu_env *env, struct dt_object *dt,
1733 const struct dt_key *key, struct thandle *handle,
1734 struct lustre_capa *capa)
1736 struct osd_object *obj = osd_dt_obj(dt);
1737 struct osd_thandle *oh;
1738 struct iam_path_descr *ipd;
1739 struct iam_container *bag = &obj->oo_dir->od_container;
1744 LINVRNT(osd_invariant(obj));
1745 LASSERT(dt_object_exists(dt));
1746 LASSERT(bag->ic_object == obj->oo_inode);
1747 LASSERT(handle != NULL);
1749 if (osd_object_auth(env, dt, capa, CAPA_OPC_INDEX_DELETE))
1752 ipd = osd_ipd_get(env, bag);
1753 if (unlikely(ipd == NULL))
1756 oh = container_of0(handle, struct osd_thandle, ot_super);
1757 LASSERT(oh->ot_handle != NULL);
1758 LASSERT(oh->ot_handle->h_transaction != NULL);
1760 rc = iam_delete(oh->ot_handle, bag, (const struct iam_key *)key, ipd);
1761 osd_ipd_put(env, bag, ipd);
1762 LINVRNT(osd_invariant(obj));
1766 static int osd_index_lookup(const struct lu_env *env, struct dt_object *dt,
1767 struct dt_rec *rec, const struct dt_key *key,
1768 struct lustre_capa *capa)
1770 struct osd_object *obj = osd_dt_obj(dt);
1771 struct iam_path_descr *ipd;
1772 struct iam_container *bag = &obj->oo_dir->od_container;
1777 LINVRNT(osd_invariant(obj));
1778 LASSERT(dt_object_exists(dt));
1779 LASSERT(bag->ic_object == obj->oo_inode);
1781 if (osd_object_auth(env, dt, capa, CAPA_OPC_INDEX_LOOKUP))
1784 ipd = osd_ipd_get(env, bag);
1785 if (unlikely(ipd == NULL))
1788 rc = iam_lookup(bag, (const struct iam_key *)key,
1789 (struct iam_rec *)rec, ipd);
1790 osd_ipd_put(env, bag, ipd);
1791 LINVRNT(osd_invariant(obj));
1796 static int osd_index_insert(const struct lu_env *env, struct dt_object *dt,
1797 const struct dt_rec *rec, const struct dt_key *key,
1798 struct thandle *th, struct lustre_capa *capa)
1800 struct osd_object *obj = osd_dt_obj(dt);
1801 struct iam_path_descr *ipd;
1802 struct osd_thandle *oh;
1803 struct iam_container *bag = &obj->oo_dir->od_container;
1808 LINVRNT(osd_invariant(obj));
1809 LASSERT(dt_object_exists(dt));
1810 LASSERT(bag->ic_object == obj->oo_inode);
1811 LASSERT(th != NULL);
1813 if (osd_object_auth(env, dt, capa, CAPA_OPC_INDEX_INSERT))
1816 ipd = osd_ipd_get(env, bag);
1817 if (unlikely(ipd == NULL))
1820 oh = container_of0(th, struct osd_thandle, ot_super);
1821 LASSERT(oh->ot_handle != NULL);
1822 LASSERT(oh->ot_handle->h_transaction != NULL);
1823 rc = iam_insert(oh->ot_handle, bag, (const struct iam_key *)key,
1824 (struct iam_rec *)rec, ipd);
1825 osd_ipd_put(env, bag, ipd);
1826 LINVRNT(osd_invariant(obj));
1831 * Iterator operations.
1834 struct osd_object *oi_obj;
1835 struct iam_path_descr *oi_ipd;
1836 struct iam_iterator oi_it;
1839 static struct dt_it *osd_it_init(const struct lu_env *env,
1840 struct dt_object *dt, int writable,
1841 struct lustre_capa *capa)
1844 struct osd_object *obj = osd_dt_obj(dt);
1845 struct lu_object *lo = &dt->do_lu;
1846 struct iam_path_descr *ipd;
1847 struct iam_container *bag = &obj->oo_dir->od_container;
1850 LASSERT(lu_object_exists(lo));
1852 if (osd_object_auth(env, dt, capa, writable ? CAPA_OPC_BODY_WRITE :
1853 CAPA_OPC_BODY_READ))
1854 return ERR_PTR(-EACCES);
1856 flags = writable ? IAM_IT_MOVE|IAM_IT_WRITE : IAM_IT_MOVE;
1860 * XXX: as ipd is allocated within osd_thread_info, assignment
1861 * below implies that iterator usage is confined within single
1864 ipd = osd_ipd_get(env, bag);
1865 if (likely(ipd != NULL)) {
1869 iam_it_init(&it->oi_it, bag, flags, ipd);
1870 return (struct dt_it *)it;
1874 return ERR_PTR(-ENOMEM);
1877 static void osd_it_fini(const struct lu_env *env, struct dt_it *di)
1879 struct osd_it *it = (struct osd_it *)di;
1880 struct osd_object *obj = it->oi_obj;
1882 iam_it_fini(&it->oi_it);
1883 osd_ipd_put(env, &obj->oo_dir->od_container, it->oi_ipd);
1884 lu_object_put(env, &obj->oo_dt.do_lu);
1888 static int osd_it_get(const struct lu_env *env,
1889 struct dt_it *di, const struct dt_key *key)
1891 struct osd_it *it = (struct osd_it *)di;
1893 return iam_it_get(&it->oi_it, (const struct iam_key *)key);
1896 static void osd_it_put(const struct lu_env *env, struct dt_it *di)
1898 struct osd_it *it = (struct osd_it *)di;
1900 iam_it_put(&it->oi_it);
1903 static int osd_it_next(const struct lu_env *env, struct dt_it *di)
1905 struct osd_it *it = (struct osd_it *)di;
1907 return iam_it_next(&it->oi_it);
1910 static int osd_it_del(const struct lu_env *env, struct dt_it *di,
1913 struct osd_it *it = (struct osd_it *)di;
1914 struct osd_thandle *oh;
1916 LASSERT(th != NULL);
1918 oh = container_of0(th, struct osd_thandle, ot_super);
1919 LASSERT(oh->ot_handle != NULL);
1920 LASSERT(oh->ot_handle->h_transaction != NULL);
1922 return iam_it_rec_delete(oh->ot_handle, &it->oi_it);
1925 static struct dt_key *osd_it_key(const struct lu_env *env,
1926 const struct dt_it *di)
1928 struct osd_it *it = (struct osd_it *)di;
1930 return (struct dt_key *)iam_it_key_get(&it->oi_it);
1933 static int osd_it_key_size(const struct lu_env *env, const struct dt_it *di)
1935 struct osd_it *it = (struct osd_it *)di;
1937 return iam_it_key_size(&it->oi_it);
1940 static struct dt_rec *osd_it_rec(const struct lu_env *env,
1941 const struct dt_it *di)
1943 struct osd_it *it = (struct osd_it *)di;
1945 return (struct dt_rec *)iam_it_rec_get(&it->oi_it);
1948 static __u64 osd_it_store(const struct lu_env *env, const struct dt_it *di)
1950 struct osd_it *it = (struct osd_it *)di;
1952 return iam_it_store(&it->oi_it);
1955 static int osd_it_load(const struct lu_env *env,
1956 const struct dt_it *di, __u64 hash)
1958 struct osd_it *it = (struct osd_it *)di;
1960 return iam_it_load(&it->oi_it, hash);
1963 static const struct dt_index_operations osd_index_ops = {
1964 .dio_lookup = osd_index_lookup,
1965 .dio_insert = osd_index_insert,
1966 .dio_delete = osd_index_delete,
1968 .init = osd_it_init,
1969 .fini = osd_it_fini,
1973 .next = osd_it_next,
1975 .key_size = osd_it_key_size,
1977 .store = osd_it_store,
1982 static int osd_index_compat_delete(const struct lu_env *env,
1983 struct dt_object *dt,
1984 const struct dt_key *key,
1985 struct thandle *handle,
1986 struct lustre_capa *capa)
1988 struct osd_object *obj = osd_dt_obj(dt);
1990 LASSERT(handle != NULL);
1991 LASSERT(S_ISDIR(obj->oo_inode->i_mode));
1995 if (osd_object_auth(env, dt, capa, CAPA_OPC_INDEX_DELETE))
1999 RETURN(-EOPNOTSUPP);
2003 * Compatibility index operations.
2007 static void osd_build_pack(const struct lu_env *env, struct osd_device *osd,
2008 struct dentry *dentry, struct lu_fid_pack *pack)
2010 struct inode *inode = dentry->d_inode;
2011 struct lu_fid *fid = &osd_oti_get(env)->oti_fid;
2013 lu_igif_build(fid, inode->i_ino, inode->i_generation);
2014 fid_cpu_to_be(fid, fid);
2015 pack->fp_len = sizeof *fid + 1;
2016 memcpy(pack->fp_area, fid, sizeof *fid);
2019 static int osd_index_compat_lookup(const struct lu_env *env,
2020 struct dt_object *dt,
2021 struct dt_rec *rec, const struct dt_key *key,
2022 struct lustre_capa *capa)
2024 struct osd_object *obj = osd_dt_obj(dt);
2026 struct osd_device *osd = osd_obj2dev(obj);
2027 struct osd_thread_info *info = osd_oti_get(env);
2033 * XXX temporary solution.
2035 struct dentry *dentry;
2036 struct dentry *parent;
2038 LINVRNT(osd_invariant(obj));
2039 LASSERT(S_ISDIR(obj->oo_inode->i_mode));
2040 LASSERT(osd_has_index(obj));
2042 if (osd_object_auth(env, dt, capa, CAPA_OPC_INDEX_LOOKUP))
2045 info->oti_str.name = (const char *)key;
2046 info->oti_str.len = strlen((const char *)key);
2048 dir = obj->oo_inode;
2049 LASSERT(dir->i_op != NULL && dir->i_op->lookup != NULL);
2051 parent = d_alloc_root(dir);
2055 dentry = d_alloc(parent, &info->oti_str);
2056 if (dentry != NULL) {
2060 * XXX passing NULL for nameidata should work for
2063 d = dir->i_op->lookup(dir, dentry, NULL);
2066 * normal case, result is in @dentry.
2068 if (dentry->d_inode != NULL) {
2069 osd_build_pack(env, osd, dentry,
2070 (struct lu_fid_pack *)rec);
2075 /* What? Disconnected alias? Ppheeeww... */
2076 CERROR("Aliasing where not expected\n");
2084 LINVRNT(osd_invariant(obj));
2088 static int osd_add_rec(struct osd_thread_info *info, struct osd_device *dev,
2089 struct inode *dir, struct inode *inode, const char *name)
2093 struct dentry *parent;
2097 info->oti_str.name = name;
2098 info->oti_str.len = strlen(name);
2100 LASSERT(atomic_read(&dir->i_count) > 0);
2102 old = d_alloc(dev->od_obj_area, &info->oti_str);
2104 d_instantiate(old, inode);
2106 LASSERT(atomic_read(&dir->i_count) > 0);
2107 parent = d_alloc_root(dir);
2108 if (parent != NULL) {
2110 LASSERT(atomic_read(&dir->i_count) > 1);
2111 new = d_alloc(parent, &info->oti_str);
2112 LASSERT(atomic_read(&dir->i_count) > 1);
2114 LASSERT(atomic_read(&dir->i_count) > 1);
2115 result = dir->i_op->link(old, dir, new);
2116 LASSERT(atomic_read(&dir->i_count) > 1);
2118 LASSERT(atomic_read(&dir->i_count) > 1);
2120 LASSERT(atomic_read(&dir->i_count) > 1);
2122 LASSERT(atomic_read(&dir->i_count) > 0);
2126 LASSERT(atomic_read(&dir->i_count) > 0);
2132 * XXX Temporary stuff.
2134 static int osd_index_compat_insert(const struct lu_env *env,
2135 struct dt_object *dt,
2136 const struct dt_rec *rec,
2137 const struct dt_key *key, struct thandle *th,
2138 struct lustre_capa *capa)
2140 struct osd_object *obj = osd_dt_obj(dt);
2142 const char *name = (const char *)key;
2144 struct lu_device *ludev = dt->do_lu.lo_dev;
2145 struct lu_object *luch;
2147 struct osd_thread_info *info = osd_oti_get(env);
2148 const struct lu_fid_pack *pack = (const struct lu_fid_pack *)rec;
2149 struct lu_fid *fid = &osd_oti_get(env)->oti_fid;
2153 LASSERT(S_ISDIR(obj->oo_inode->i_mode));
2154 LINVRNT(osd_invariant(obj));
2155 LASSERT(th != NULL);
2157 if (osd_object_auth(env, dt, capa, CAPA_OPC_INDEX_INSERT))
2160 result = fid_unpack(pack, fid);
2164 luch = lu_object_find(env, ludev, fid, NULL);
2165 if (!IS_ERR(luch)) {
2166 if (lu_object_exists(luch)) {
2167 struct osd_object *child;
2169 child = osd_obj(lu_object_locate(luch->lo_header,
2172 result = osd_add_rec(info, osd_obj2dev(obj),
2174 child->oo_inode, name);
2176 CERROR("No osd slice.\n");
2179 LINVRNT(osd_invariant(obj));
2180 LINVRNT(osd_invariant(child));
2185 lu_object_put(env, luch);
2187 result = PTR_ERR(luch);
2188 LINVRNT(osd_invariant(obj));
2192 static const struct dt_index_operations osd_index_compat_ops = {
2193 .dio_lookup = osd_index_compat_lookup,
2194 .dio_insert = osd_index_compat_insert,
2195 .dio_delete = osd_index_compat_delete
2198 /* type constructor/destructor: osd_type_init, osd_type_fini */
2199 LU_TYPE_INIT_FINI(osd, &osd_key);
2201 static struct lu_context_key osd_key = {
2202 .lct_tags = LCT_DT_THREAD | LCT_MD_THREAD,
2203 .lct_init = osd_key_init,
2204 .lct_fini = osd_key_fini,
2205 .lct_exit = osd_key_exit
2208 static void *osd_key_init(const struct lu_context *ctx,
2209 struct lu_context_key *key)
2211 struct osd_thread_info *info;
2213 OBD_ALLOC_PTR(info);
2215 info->oti_env = container_of(ctx, struct lu_env, le_ctx);
2217 info = ERR_PTR(-ENOMEM);
2221 /* context key destructor: osd_key_fini */
2222 LU_KEY_FINI(osd, struct osd_thread_info);
2224 static void osd_key_exit(const struct lu_context *ctx,
2225 struct lu_context_key *key, void *data)
2227 struct osd_thread_info *info = data;
2229 LASSERT(info->oti_r_locks == 0);
2230 LASSERT(info->oti_w_locks == 0);
2231 LASSERT(info->oti_txns == 0);
2234 static int osd_device_init(const struct lu_env *env, struct lu_device *d,
2235 const char *name, struct lu_device *next)
2238 /* context for commit hooks */
2239 rc = lu_context_init(&osd_dev(d)->od_env_for_commit.le_ctx,
2242 rc = osd_procfs_init(osd_dev(d), name);
2246 static int osd_shutdown(const struct lu_env *env, struct osd_device *o)
2248 struct osd_thread_info *info = osd_oti_get(env);
2250 if (o->od_obj_area != NULL) {
2251 dput(o->od_obj_area);
2252 o->od_obj_area = NULL;
2254 osd_oi_fini(info, &o->od_oi);
2259 static int osd_mount(const struct lu_env *env,
2260 struct osd_device *o, struct lustre_cfg *cfg)
2262 struct lustre_mount_info *lmi;
2263 const char *dev = lustre_cfg_string(cfg, 0);
2264 struct osd_thread_info *info = osd_oti_get(env);
2269 if (o->od_mount != NULL) {
2270 CERROR("Already mounted (%s)\n", dev);
2275 lmi = server_get_mount(dev);
2277 CERROR("Cannot get mount info for %s!\n", dev);
2281 LASSERT(lmi != NULL);
2282 /* save lustre_mount_info in dt_device */
2285 result = osd_oi_init(info, &o->od_oi, &o->od_dt_dev);
2289 d = simple_mkdir(osd_sb(o)->s_root, lmi->lmi_mnt, "*OBJ-TEMP*",
2294 result = PTR_ERR(d);
2297 osd_shutdown(env, o);
2301 static struct lu_device *osd_device_fini(const struct lu_env *env,
2302 struct lu_device *d)
2307 shrink_dcache_sb(osd_sb(osd_dev(d)));
2308 osd_sync(env, lu2dt_dev(d));
2310 rc = osd_procfs_fini(osd_dev(d));
2312 CERROR("proc fini error %d \n", rc);
2313 RETURN (ERR_PTR(rc));
2316 if (osd_dev(d)->od_mount)
2317 server_put_mount(osd_dev(d)->od_mount->lmi_name,
2318 osd_dev(d)->od_mount->lmi_mnt);
2319 osd_dev(d)->od_mount = NULL;
2321 lu_context_fini(&osd_dev(d)->od_env_for_commit.le_ctx);
2325 static struct lu_device *osd_device_alloc(const struct lu_env *env,
2326 struct lu_device_type *t,
2327 struct lustre_cfg *cfg)
2329 struct lu_device *l;
2330 struct osd_device *o;
2336 result = dt_device_init(&o->od_dt_dev, t);
2339 l->ld_ops = &osd_lu_ops;
2340 o->od_dt_dev.dd_ops = &osd_dt_ops;
2341 spin_lock_init(&o->od_osfs_lock);
2342 o->od_osfs_age = cfs_time_shift_64(-1000);
2343 o->od_capa_hash = init_capa_hash();
2344 if (o->od_capa_hash == NULL) {
2345 dt_device_fini(&o->od_dt_dev);
2346 l = ERR_PTR(-ENOMEM);
2349 l = ERR_PTR(result);
2354 l = ERR_PTR(-ENOMEM);
2358 static struct lu_device *osd_device_free(const struct lu_env *env,
2359 struct lu_device *d)
2361 struct osd_device *o = osd_dev(d);
2364 cleanup_capa_hash(o->od_capa_hash);
2365 dt_device_fini(&o->od_dt_dev);
2370 static int osd_process_config(const struct lu_env *env,
2371 struct lu_device *d, struct lustre_cfg *cfg)
2373 struct osd_device *o = osd_dev(d);
2377 switch(cfg->lcfg_command) {
2379 err = osd_mount(env, o, cfg);
2382 err = osd_shutdown(env, o);
2390 extern void ldiskfs_orphan_cleanup (struct super_block * sb,
2391 struct ldiskfs_super_block * es);
2393 static int osd_recovery_complete(const struct lu_env *env,
2394 struct lu_device *d)
2396 struct osd_device *o = osd_dev(d);
2398 /* TODO: orphans handling */
2399 ldiskfs_orphan_cleanup(osd_sb(o), LDISKFS_SB(osd_sb(o))->s_es);
2403 static struct inode *osd_iget(struct osd_thread_info *info,
2404 struct osd_device *dev,
2405 const struct osd_inode_id *id)
2407 struct inode *inode;
2409 inode = iget(osd_sb(dev), id->oii_ino);
2410 if (inode == NULL) {
2411 CERROR("no inode\n");
2412 inode = ERR_PTR(-EACCES);
2413 } else if (is_bad_inode(inode)) {
2414 CERROR("bad inode\n");
2416 inode = ERR_PTR(-ENOENT);
2417 } else if (inode->i_generation != id->oii_gen) {
2418 CERROR("stale inode\n");
2420 inode = ERR_PTR(-ESTALE);
2427 static int osd_fid_lookup(const struct lu_env *env,
2428 struct osd_object *obj, const struct lu_fid *fid)
2430 struct osd_thread_info *info;
2431 struct lu_device *ldev = obj->oo_dt.do_lu.lo_dev;
2432 struct osd_device *dev;
2433 struct osd_inode_id *id;
2435 struct inode *inode;
2438 LINVRNT(osd_invariant(obj));
2439 LASSERT(obj->oo_inode == NULL);
2440 LASSERT(fid_is_sane(fid));
2442 * This assertion checks that osd layer sees only local
2443 * fids. Unfortunately it is somewhat expensive (does a
2444 * cache-lookup). Disabling it for production/acceptance-testing.
2446 LASSERT(1 || fid_is_local(ldev->ld_site, fid));
2450 info = osd_oti_get(env);
2451 dev = osd_dev(ldev);
2455 if (OBD_FAIL_CHECK(OBD_FAIL_OST_ENOENT))
2458 result = osd_oi_lookup(info, oi, fid, id);
2460 inode = osd_iget(info, dev, id);
2461 if (!IS_ERR(inode)) {
2462 obj->oo_inode = inode;
2463 LASSERT(obj->oo_inode->i_sb == osd_sb(dev));
2467 * If fid wasn't found in oi, inode-less object is
2468 * created, for which lu_object_exists() returns
2469 * false. This is used in a (frequent) case when
2470 * objects are created as locking anchors or
2471 * place holders for objects yet to be created.
2473 result = PTR_ERR(inode);
2474 } else if (result == -ENOENT)
2476 LINVRNT(osd_invariant(obj));
2480 static void osd_inode_getattr(const struct lu_env *env,
2481 struct inode *inode, struct lu_attr *attr)
2483 attr->la_valid |= LA_ATIME | LA_MTIME | LA_CTIME | LA_MODE |
2484 LA_SIZE | LA_BLOCKS | LA_UID | LA_GID |
2485 LA_FLAGS | LA_NLINK | LA_RDEV | LA_BLKSIZE;
2487 attr->la_atime = LTIME_S(inode->i_atime);
2488 attr->la_mtime = LTIME_S(inode->i_mtime);
2489 attr->la_ctime = LTIME_S(inode->i_ctime);
2490 attr->la_mode = inode->i_mode;
2491 attr->la_size = i_size_read(inode);
2492 attr->la_blocks = inode->i_blocks;
2493 attr->la_uid = inode->i_uid;
2494 attr->la_gid = inode->i_gid;
2495 attr->la_flags = LDISKFS_I(inode)->i_flags;
2496 attr->la_nlink = inode->i_nlink;
2497 attr->la_rdev = inode->i_rdev;
2498 attr->la_blksize = ll_inode_blksize(inode);
2499 attr->la_blkbits = inode->i_blkbits;
2506 static int lu_device_is_osd(const struct lu_device *d)
2508 return ergo(d != NULL && d->ld_ops != NULL, d->ld_ops == &osd_lu_ops);
2511 static struct osd_object *osd_obj(const struct lu_object *o)
2513 LASSERT(lu_device_is_osd(o->lo_dev));
2514 return container_of0(o, struct osd_object, oo_dt.do_lu);
2517 static struct osd_device *osd_dt_dev(const struct dt_device *d)
2519 LASSERT(lu_device_is_osd(&d->dd_lu_dev));
2520 return container_of0(d, struct osd_device, od_dt_dev);
2523 static struct osd_device *osd_dev(const struct lu_device *d)
2525 LASSERT(lu_device_is_osd(d));
2526 return osd_dt_dev(container_of0(d, struct dt_device, dd_lu_dev));
2529 static struct osd_object *osd_dt_obj(const struct dt_object *d)
2531 return osd_obj(&d->do_lu);
2534 static struct osd_device *osd_obj2dev(const struct osd_object *o)
2536 return osd_dev(o->oo_dt.do_lu.lo_dev);
2539 static struct lu_device *osd2lu_dev(struct osd_device *osd)
2541 return &osd->od_dt_dev.dd_lu_dev;
2544 static struct super_block *osd_sb(const struct osd_device *dev)
2546 return dev->od_mount->lmi_mnt->mnt_sb;
2549 static journal_t *osd_journal(const struct osd_device *dev)
2551 return LDISKFS_SB(osd_sb(dev))->s_journal;
2554 static int osd_has_index(const struct osd_object *obj)
2556 return obj->oo_dt.do_index_ops != NULL;
2559 static int osd_object_invariant(const struct lu_object *l)
2561 return osd_invariant(osd_obj(l));
2564 static const struct lu_object_operations osd_lu_obj_ops = {
2565 .loo_object_init = osd_object_init,
2566 .loo_object_delete = osd_object_delete,
2567 .loo_object_release = osd_object_release,
2568 .loo_object_free = osd_object_free,
2569 .loo_object_print = osd_object_print,
2570 .loo_object_invariant = osd_object_invariant
2573 static const struct lu_device_operations osd_lu_ops = {
2574 .ldo_object_alloc = osd_object_alloc,
2575 .ldo_process_config = osd_process_config,
2576 .ldo_recovery_complete = osd_recovery_complete
2579 static const struct lu_device_type_operations osd_device_type_ops = {
2580 .ldto_init = osd_type_init,
2581 .ldto_fini = osd_type_fini,
2583 .ldto_start = osd_type_start,
2584 .ldto_stop = osd_type_stop,
2586 .ldto_device_alloc = osd_device_alloc,
2587 .ldto_device_free = osd_device_free,
2589 .ldto_device_init = osd_device_init,
2590 .ldto_device_fini = osd_device_fini
2593 static struct lu_device_type osd_device_type = {
2594 .ldt_tags = LU_DEVICE_DT,
2595 .ldt_name = LUSTRE_OSD_NAME,
2596 .ldt_ops = &osd_device_type_ops,
2597 .ldt_ctx_tags = LCT_MD_THREAD|LCT_DT_THREAD
2601 * lprocfs legacy support.
2603 static struct obd_ops osd_obd_device_ops = {
2604 .o_owner = THIS_MODULE
2607 static int __init osd_mod_init(void)
2609 struct lprocfs_static_vars lvars;
2611 lprocfs_osd_init_vars(&lvars);
2612 return class_register_type(&osd_obd_device_ops, NULL, lvars.module_vars,
2613 LUSTRE_OSD_NAME, &osd_device_type);
2616 static void __exit osd_mod_exit(void)
2618 class_unregister_type(LUSTRE_OSD_NAME);
2621 MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");
2622 MODULE_DESCRIPTION("Lustre Object Storage Device ("LUSTRE_OSD_NAME")");
2623 MODULE_LICENSE("GPL");
2625 cfs_module(osd, "0.0.2", osd_mod_init, osd_mod_exit);