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 * Concurrency: shouldn't matter.
709 lvfs_sbdev_type fsfilt_ldiskfs_journal_sbdev(struct super_block *);
711 static void osd_ro(const struct lu_env *env, struct dt_device *d)
715 CERROR("*** setting device %s read-only ***\n", LUSTRE_OSD_NAME);
717 __lvfs_set_rdonly(lvfs_sbdev(osd_sb(osd_dt_dev(d))),
718 fsfilt_ldiskfs_journal_sbdev(osd_sb(osd_dt_dev(d))));
723 * Concurrency: serialization provided by callers.
725 static int osd_init_capa_ctxt(const struct lu_env *env, struct dt_device *d,
726 int mode, unsigned long timeout, __u32 alg,
727 struct lustre_capa_key *keys)
729 struct osd_device *dev = osd_dt_dev(d);
732 dev->od_fl_capa = mode;
733 dev->od_capa_timeout = timeout;
734 dev->od_capa_alg = alg;
735 dev->od_capa_keys = keys;
739 /* Note: we did not count into QUOTA here, If we mount with --data_journal
741 static const int osd_dto_credits[DTO_NR] = {
743 * Insert/Delete. IAM EXT3_INDEX_EXTRA_TRANS_BLOCKS(8) +
744 * EXT3_SINGLEDATA_TRANS_BLOCKS 8 XXX Note: maybe iam need more,since
745 * iam have more level than Ext3 htree
747 [DTO_INDEX_INSERT] = 16,
748 [DTO_INDEX_DELETE] = 16,
749 [DTO_IDNEX_UPDATE] = 16,
751 * Create a object. Same as create object in Ext3 filesystem, but did
752 * not count QUOTA i EXT3_DATA_TRANS_BLOCKS(12) +
753 * INDEX_EXTRA_BLOCKS(8) + 3(inode bits,groups, GDT)
755 [DTO_OBJECT_CREATE] = 23,
756 [DTO_OBJECT_DELETE] = 23,
758 * Attr set credits 3 inode, group, GDT
762 * XATTR_SET. SAME AS XATTR of EXT3 EXT3_DATA_TRANS_BLOCKS XXX Note:
763 * in original MDS implmentation EXT3_INDEX_EXTRA_TRANS_BLOCKS are
764 * also counted in. Do not know why?
766 [DTO_XATTR_SET] = 16,
768 /* creadits for inode change during write */
769 [DTO_WRITE_BASE] = 3,
770 /* credits for single block write */
771 [DTO_WRITE_BLOCK] = 12
774 static int osd_credit_get(const struct lu_env *env, struct dt_device *d,
777 LASSERT(0 <= op && op < ARRAY_SIZE(osd_dto_credits));
778 return osd_dto_credits[op];
781 static const struct dt_device_operations osd_dt_ops = {
782 .dt_root_get = osd_root_get,
783 .dt_statfs = osd_statfs,
784 .dt_trans_start = osd_trans_start,
785 .dt_trans_stop = osd_trans_stop,
786 .dt_conf_get = osd_conf_get,
789 .dt_credit_get = osd_credit_get,
790 .dt_init_capa_ctxt = osd_init_capa_ctxt,
793 static void osd_object_read_lock(const struct lu_env *env,
794 struct dt_object *dt, unsigned role)
796 struct osd_object *obj = osd_dt_obj(dt);
797 struct osd_thread_info *oti = osd_oti_get(env);
799 LINVRNT(osd_invariant(obj));
801 LASSERT(obj->oo_owner != env);
802 down_read_nested(&obj->oo_sem, role);
804 LASSERT(obj->oo_owner == NULL);
808 static void osd_object_write_lock(const struct lu_env *env,
809 struct dt_object *dt, unsigned role)
811 struct osd_object *obj = osd_dt_obj(dt);
812 struct osd_thread_info *oti = osd_oti_get(env);
814 LINVRNT(osd_invariant(obj));
816 LASSERT(obj->oo_owner != env);
817 down_write_nested(&obj->oo_sem, role);
819 LASSERT(obj->oo_owner == NULL);
824 static void osd_object_read_unlock(const struct lu_env *env,
825 struct dt_object *dt)
827 struct osd_object *obj = osd_dt_obj(dt);
828 struct osd_thread_info *oti = osd_oti_get(env);
830 LINVRNT(osd_invariant(obj));
832 LASSERT(oti->oti_r_locks > 0);
834 up_read(&obj->oo_sem);
837 static void osd_object_write_unlock(const struct lu_env *env,
838 struct dt_object *dt)
840 struct osd_object *obj = osd_dt_obj(dt);
841 struct osd_thread_info *oti = osd_oti_get(env);
843 LINVRNT(osd_invariant(obj));
845 LASSERT(obj->oo_owner == env);
846 LASSERT(oti->oti_w_locks > 0);
848 obj->oo_owner = NULL;
849 up_write(&obj->oo_sem);
852 static int capa_is_sane(const struct lu_env *env,
853 struct osd_device *dev,
854 struct lustre_capa *capa,
855 struct lustre_capa_key *keys)
857 struct osd_thread_info *oti = osd_oti_get(env);
862 oc = capa_lookup(dev->od_capa_hash, capa, 0);
864 if (capa_is_expired(oc)) {
865 DEBUG_CAPA(D_ERROR, capa, "expired");
872 spin_lock(&capa_lock);
873 for (i = 0; i < 2; i++) {
874 if (keys[i].lk_keyid == capa->lc_keyid) {
875 oti->oti_capa_key = keys[i];
879 spin_unlock(&capa_lock);
882 DEBUG_CAPA(D_ERROR, capa, "no matched capa key");
886 rc = capa_hmac(oti->oti_capa.lc_hmac, capa, oti->oti_capa_key.lk_key);
889 if (memcmp(oti->oti_capa.lc_hmac, capa->lc_hmac, sizeof(capa->lc_hmac)))
891 DEBUG_CAPA(D_ERROR, capa, "HMAC mismatch");
895 oc = capa_add(dev->od_capa_hash, capa);
901 static int osd_object_auth(const struct lu_env *env, struct dt_object *dt,
902 struct lustre_capa *capa, __u64 opc)
904 const struct lu_fid *fid = lu_object_fid(&dt->do_lu);
905 struct osd_device *dev = osd_dev(dt->do_lu.lo_dev);
908 if (!dev->od_fl_capa)
911 if (capa == BYPASS_CAPA)
915 CERROR("no capability is provided for fid "DFID"\n", PFID(fid));
919 if (!lu_fid_eq(fid, &capa->lc_fid)) {
920 DEBUG_CAPA(D_ERROR, capa, "fid "DFID" mismatch with",
925 if (!capa_opc_supported(capa, opc)) {
926 DEBUG_CAPA(D_ERROR, capa, "opc "LPX64" not supported by", opc);
930 if ((rc = capa_is_sane(env, dev, capa, dev->od_capa_keys))) {
931 DEBUG_CAPA(D_ERROR, capa, "insane (rc %d)", rc);
938 static int osd_attr_get(const struct lu_env *env,
939 struct dt_object *dt,
940 struct lu_attr *attr,
941 struct lustre_capa *capa)
943 struct osd_object *obj = osd_dt_obj(dt);
945 LASSERT(dt_object_exists(dt));
946 LINVRNT(osd_invariant(obj));
948 if (osd_object_auth(env, dt, capa, CAPA_OPC_META_READ))
951 spin_lock(&obj->oo_guard);
952 osd_inode_getattr(env, obj->oo_inode, attr);
953 spin_unlock(&obj->oo_guard);
957 static int osd_attr_set(const struct lu_env *env,
958 struct dt_object *dt,
959 const struct lu_attr *attr,
960 struct thandle *handle,
961 struct lustre_capa *capa)
963 struct osd_object *obj = osd_dt_obj(dt);
965 LASSERT(handle != NULL);
966 LASSERT(dt_object_exists(dt));
967 LASSERT(osd_invariant(obj));
969 if (osd_object_auth(env, dt, capa, CAPA_OPC_META_WRITE))
972 spin_lock(&obj->oo_guard);
973 osd_inode_setattr(env, obj->oo_inode, attr);
974 spin_unlock(&obj->oo_guard);
976 mark_inode_dirty(obj->oo_inode);
980 static struct timespec *osd_inode_time(const struct lu_env *env,
981 struct inode *inode, __u64 seconds)
983 struct osd_thread_info *oti = osd_oti_get(env);
984 struct timespec *t = &oti->oti_time;
988 *t = timespec_trunc(*t, get_sb_time_gran(inode->i_sb));
992 static void osd_inode_setattr(const struct lu_env *env,
993 struct inode *inode, const struct lu_attr *attr)
997 bits = attr->la_valid;
999 LASSERT(!(bits & LA_TYPE)); /* Huh? You want too much. */
1001 if (bits & LA_ATIME)
1002 inode->i_atime = *osd_inode_time(env, inode, attr->la_atime);
1003 if (bits & LA_CTIME)
1004 inode->i_ctime = *osd_inode_time(env, inode, attr->la_ctime);
1005 if (bits & LA_MTIME)
1006 inode->i_mtime = *osd_inode_time(env, inode, attr->la_mtime);
1007 if (bits & LA_SIZE) {
1008 LDISKFS_I(inode)->i_disksize = attr->la_size;
1009 i_size_write(inode, attr->la_size);
1011 if (bits & LA_BLOCKS)
1012 inode->i_blocks = attr->la_blocks;
1014 inode->i_mode = (inode->i_mode & S_IFMT) |
1015 (attr->la_mode & ~S_IFMT);
1017 inode->i_uid = attr->la_uid;
1019 inode->i_gid = attr->la_gid;
1020 if (bits & LA_NLINK)
1021 inode->i_nlink = attr->la_nlink;
1023 inode->i_rdev = attr->la_rdev;
1025 if (bits & LA_FLAGS) {
1026 struct ldiskfs_inode_info *li = LDISKFS_I(inode);
1028 li->i_flags = (li->i_flags & ~LDISKFS_FL_USER_MODIFIABLE) |
1029 (attr->la_flags & LDISKFS_FL_USER_MODIFIABLE);
1036 * XXX temporary solution.
1039 static int osd_create_pre(struct osd_thread_info *info, struct osd_object *obj,
1040 struct lu_attr *attr, struct thandle *th)
1045 static int osd_create_post(struct osd_thread_info *info, struct osd_object *obj,
1046 struct lu_attr *attr, struct thandle *th)
1048 LASSERT(obj->oo_inode != NULL);
1050 osd_object_init0(obj);
1054 extern struct inode *ldiskfs_create_inode(handle_t *handle,
1055 struct inode * dir, int mode);
1057 static int osd_mkfile(struct osd_thread_info *info, struct osd_object *obj,
1059 struct dt_allocation_hint *hint,
1063 struct osd_device *osd = osd_obj2dev(obj);
1064 struct osd_thandle *oth;
1065 struct inode *parent;
1066 struct inode *inode;
1068 LINVRNT(osd_invariant(obj));
1069 LASSERT(obj->oo_inode == NULL);
1070 LASSERT(osd->od_obj_area != NULL);
1072 oth = container_of(th, struct osd_thandle, ot_super);
1073 LASSERT(oth->ot_handle->h_transaction != NULL);
1075 if (hint && hint->dah_parent)
1076 parent = osd_dt_obj(hint->dah_parent)->oo_inode;
1078 parent = osd->od_obj_area->d_inode;
1079 LASSERT(parent->i_op != NULL);
1081 inode = ldiskfs_create_inode(oth->ot_handle, parent, mode);
1082 if (!IS_ERR(inode)) {
1083 obj->oo_inode = inode;
1086 result = PTR_ERR(inode);
1087 LINVRNT(osd_invariant(obj));
1092 extern int iam_lvar_create(struct inode *obj, int keysize, int ptrsize,
1093 int recsize, handle_t *handle);
1099 static int osd_mkdir(struct osd_thread_info *info, struct osd_object *obj,
1100 struct lu_attr *attr,
1101 struct dt_allocation_hint *hint,
1105 struct osd_thandle *oth;
1107 LASSERT(S_ISDIR(attr->la_mode));
1109 oth = container_of(th, struct osd_thandle, ot_super);
1110 LASSERT(oth->ot_handle->h_transaction != NULL);
1111 result = osd_mkfile(info, obj, (attr->la_mode &
1112 (S_IFMT | S_IRWXUGO | S_ISVTX)), hint, th);
1114 LASSERT(obj->oo_inode != NULL);
1116 * XXX uh-oh... call low-level iam function directly.
1118 result = iam_lvar_create(obj->oo_inode, OSD_NAME_LEN, 4,
1119 sizeof (struct lu_fid_pack),
1125 static int osd_mkreg(struct osd_thread_info *info, struct osd_object *obj,
1126 struct lu_attr *attr,
1127 struct dt_allocation_hint *hint,
1130 LASSERT(S_ISREG(attr->la_mode));
1131 return osd_mkfile(info, obj, (attr->la_mode &
1132 (S_IFMT | S_IRWXUGO | S_ISVTX)), hint, th);
1135 static int osd_mksym(struct osd_thread_info *info, struct osd_object *obj,
1136 struct lu_attr *attr,
1137 struct dt_allocation_hint *hint,
1140 LASSERT(S_ISLNK(attr->la_mode));
1141 return osd_mkfile(info, obj, (attr->la_mode &
1142 (S_IFMT | S_IRWXUGO | S_ISVTX)), hint, th);
1145 static int osd_mknod(struct osd_thread_info *info, struct osd_object *obj,
1146 struct lu_attr *attr,
1147 struct dt_allocation_hint *hint,
1151 struct osd_device *osd = osd_obj2dev(obj);
1153 umode_t mode = attr->la_mode & (S_IFMT | S_IRWXUGO | S_ISVTX);
1155 LINVRNT(osd_invariant(obj));
1156 LASSERT(obj->oo_inode == NULL);
1157 LASSERT(osd->od_obj_area != NULL);
1158 LASSERT(S_ISCHR(mode) || S_ISBLK(mode) ||
1159 S_ISFIFO(mode) || S_ISSOCK(mode));
1161 dir = osd->od_obj_area->d_inode;
1162 LASSERT(dir->i_op != NULL);
1164 result = osd_mkfile(info, obj, mode, hint, th);
1166 LASSERT(obj->oo_inode != NULL);
1167 init_special_inode(obj->oo_inode, mode, attr->la_rdev);
1169 LINVRNT(osd_invariant(obj));
1173 typedef int (*osd_obj_type_f)(struct osd_thread_info *, struct osd_object *,
1175 struct dt_allocation_hint *hint,
1178 static osd_obj_type_f osd_create_type_f(__u32 mode)
1180 osd_obj_type_f result;
1206 static void osd_ah_init(const struct lu_env *env, struct dt_allocation_hint *ah,
1207 struct dt_object *parent, umode_t child_mode)
1211 memset(ah, 0, sizeof(*ah));
1212 ah->dah_parent = parent;
1213 ah->dah_mode = child_mode;
1218 * Concurrency: @dt is write locked.
1220 static int osd_object_create(const struct lu_env *env, struct dt_object *dt,
1221 struct lu_attr *attr,
1222 struct dt_allocation_hint *hint,
1225 const struct lu_fid *fid = lu_object_fid(&dt->do_lu);
1226 struct osd_object *obj = osd_dt_obj(dt);
1227 struct osd_device *osd = osd_obj2dev(obj);
1228 struct osd_thread_info *info = osd_oti_get(env);
1233 LINVRNT(osd_invariant(obj));
1234 LASSERT(!dt_object_exists(dt));
1235 LASSERT(osd_write_locked(env, obj));
1236 LASSERT(th != NULL);
1239 * XXX missing: Quote handling.
1242 result = osd_create_pre(info, obj, attr, th);
1244 result = osd_create_type_f(attr->la_mode & S_IFMT)(info, obj,
1247 result = osd_create_post(info, obj, attr, th);
1250 struct osd_inode_id *id = &info->oti_id;
1252 LASSERT(obj->oo_inode != NULL);
1254 id->oii_ino = obj->oo_inode->i_ino;
1255 id->oii_gen = obj->oo_inode->i_generation;
1257 result = osd_oi_insert(info, &osd->od_oi, fid, id, th);
1260 LASSERT(ergo(result == 0, dt_object_exists(dt)));
1261 LINVRNT(osd_invariant(obj));
1266 * Concurrency: @dt is write locked.
1268 static void osd_object_ref_add(const struct lu_env *env,
1269 struct dt_object *dt,
1272 struct osd_object *obj = osd_dt_obj(dt);
1273 struct inode *inode = obj->oo_inode;
1275 LINVRNT(osd_invariant(obj));
1276 LASSERT(dt_object_exists(dt));
1277 LASSERT(osd_write_locked(env, obj));
1278 LASSERT(th != NULL);
1280 spin_lock(&obj->oo_guard);
1281 LASSERT(inode->i_nlink < LDISKFS_LINK_MAX);
1283 spin_unlock(&obj->oo_guard);
1284 mark_inode_dirty(inode);
1285 LINVRNT(osd_invariant(obj));
1289 * Concurrency: @dt is write locked.
1291 static void osd_object_ref_del(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 > 0);
1306 spin_unlock(&obj->oo_guard);
1307 mark_inode_dirty(inode);
1308 LINVRNT(osd_invariant(obj));
1312 * Concurrency: @dt is read locked.
1314 static int osd_xattr_get(const struct lu_env *env,
1315 struct dt_object *dt,
1318 struct lustre_capa *capa)
1320 struct osd_object *obj = osd_dt_obj(dt);
1321 struct inode *inode = obj->oo_inode;
1322 struct osd_thread_info *info = osd_oti_get(env);
1323 struct dentry *dentry = &info->oti_dentry;
1325 LASSERT(dt_object_exists(dt));
1326 LASSERT(inode->i_op != NULL && inode->i_op->getxattr != NULL);
1327 LASSERT(osd_read_locked(env, obj) || osd_write_locked(env, obj));
1329 if (osd_object_auth(env, dt, capa, CAPA_OPC_META_READ))
1332 dentry->d_inode = inode;
1333 return inode->i_op->getxattr(dentry, name, buf->lb_buf, buf->lb_len);
1337 * Concurrency: @dt is write locked.
1339 static int osd_xattr_set(const struct lu_env *env, struct dt_object *dt,
1340 const struct lu_buf *buf, const char *name, int fl,
1341 struct thandle *handle, 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;
1347 struct timespec *t = &info->oti_time;
1348 int fs_flags = 0, rc;
1350 LASSERT(dt_object_exists(dt));
1351 LASSERT(inode->i_op != NULL && inode->i_op->setxattr != NULL);
1352 LASSERT(osd_write_locked(env, obj));
1353 LASSERT(handle != NULL);
1355 if (osd_object_auth(env, dt, capa, CAPA_OPC_META_WRITE))
1358 if (fl & LU_XATTR_REPLACE)
1359 fs_flags |= XATTR_REPLACE;
1361 if (fl & LU_XATTR_CREATE)
1362 fs_flags |= XATTR_CREATE;
1364 dentry->d_inode = inode;
1365 *t = inode->i_ctime;
1366 rc = inode->i_op->setxattr(dentry, name,
1367 buf->lb_buf, buf->lb_len, fs_flags);
1368 if (likely(rc == 0)) {
1369 /* ctime should not be updated with server-side time. */
1370 spin_lock(&obj->oo_guard);
1371 inode->i_ctime = *t;
1372 spin_unlock(&obj->oo_guard);
1373 mark_inode_dirty(inode);
1379 * Concurrency: @dt is read locked.
1381 static int osd_xattr_list(const struct lu_env *env,
1382 struct dt_object *dt,
1384 struct lustre_capa *capa)
1386 struct osd_object *obj = osd_dt_obj(dt);
1387 struct inode *inode = obj->oo_inode;
1388 struct osd_thread_info *info = osd_oti_get(env);
1389 struct dentry *dentry = &info->oti_dentry;
1391 LASSERT(dt_object_exists(dt));
1392 LASSERT(inode->i_op != NULL && inode->i_op->listxattr != NULL);
1393 LASSERT(osd_read_locked(env, obj) || osd_write_locked(env, obj));
1395 if (osd_object_auth(env, dt, capa, CAPA_OPC_META_READ))
1398 dentry->d_inode = inode;
1399 return inode->i_op->listxattr(dentry, buf->lb_buf, buf->lb_len);
1403 * Concurrency: @dt is write locked.
1405 static int osd_xattr_del(const struct lu_env *env,
1406 struct dt_object *dt,
1408 struct thandle *handle,
1409 struct lustre_capa *capa)
1411 struct osd_object *obj = osd_dt_obj(dt);
1412 struct inode *inode = obj->oo_inode;
1413 struct osd_thread_info *info = osd_oti_get(env);
1414 struct dentry *dentry = &info->oti_dentry;
1415 struct timespec *t = &info->oti_time;
1418 LASSERT(dt_object_exists(dt));
1419 LASSERT(inode->i_op != NULL && inode->i_op->removexattr != NULL);
1420 LASSERT(osd_write_locked(env, obj));
1421 LASSERT(handle != NULL);
1423 if (osd_object_auth(env, dt, capa, CAPA_OPC_META_WRITE))
1426 dentry->d_inode = inode;
1427 *t = inode->i_ctime;
1428 rc = inode->i_op->removexattr(dentry, name);
1429 if (likely(rc == 0)) {
1430 /* ctime should not be updated with server-side time. */
1431 spin_lock(&obj->oo_guard);
1432 inode->i_ctime = *t;
1433 spin_unlock(&obj->oo_guard);
1434 mark_inode_dirty(inode);
1439 static struct obd_capa *osd_capa_get(const struct lu_env *env,
1440 struct dt_object *dt,
1441 struct lustre_capa *old,
1444 struct osd_thread_info *info = osd_oti_get(env);
1445 const struct lu_fid *fid = lu_object_fid(&dt->do_lu);
1446 struct osd_object *obj = osd_dt_obj(dt);
1447 struct osd_device *dev = osd_obj2dev(obj);
1448 struct lustre_capa_key *key = &info->oti_capa_key;
1449 struct lustre_capa *capa = &info->oti_capa;
1450 struct obd_capa *oc;
1454 if (!dev->od_fl_capa)
1455 RETURN(ERR_PTR(-ENOENT));
1457 LASSERT(dt_object_exists(dt));
1458 LINVRNT(osd_invariant(obj));
1460 /* renewal sanity check */
1461 if (old && osd_object_auth(env, dt, old, opc))
1462 RETURN(ERR_PTR(-EACCES));
1464 capa->lc_fid = *fid;
1467 capa->lc_flags = dev->od_capa_alg << 24;
1468 capa->lc_timeout = dev->od_capa_timeout;
1469 capa->lc_expiry = 0;
1471 oc = capa_lookup(dev->od_capa_hash, capa, 1);
1473 LASSERT(!capa_is_expired(oc));
1477 spin_lock(&capa_lock);
1478 *key = dev->od_capa_keys[1];
1479 spin_unlock(&capa_lock);
1481 capa->lc_keyid = key->lk_keyid;
1482 capa->lc_expiry = cfs_time_current_sec() + dev->od_capa_timeout;
1484 rc = capa_hmac(capa->lc_hmac, capa, key->lk_key);
1486 DEBUG_CAPA(D_ERROR, capa, "HMAC failed: %d for", rc);
1487 RETURN(ERR_PTR(rc));
1490 oc = capa_add(dev->od_capa_hash, capa);
1494 static int osd_object_sync(const struct lu_env *env, struct dt_object *dt)
1497 struct osd_object *obj = osd_dt_obj(dt);
1498 struct inode *inode = obj->oo_inode;
1499 struct osd_thread_info *info = osd_oti_get(env);
1500 struct dentry *dentry = &info->oti_dentry;
1501 struct file *file = &info->oti_file;
1504 dentry->d_inode = inode;
1505 file->f_dentry = dentry;
1506 file->f_mapping = inode->i_mapping;
1507 file->f_op = inode->i_fop;
1508 LOCK_INODE_MUTEX(inode);
1509 rc = file->f_op->fsync(file, dentry, 0);
1510 UNLOCK_INODE_MUTEX(inode);
1514 static const struct dt_object_operations osd_obj_ops = {
1515 .do_read_lock = osd_object_read_lock,
1516 .do_write_lock = osd_object_write_lock,
1517 .do_read_unlock = osd_object_read_unlock,
1518 .do_write_unlock = osd_object_write_unlock,
1519 .do_attr_get = osd_attr_get,
1520 .do_attr_set = osd_attr_set,
1521 .do_ah_init = osd_ah_init,
1522 .do_create = osd_object_create,
1523 .do_index_try = osd_index_try,
1524 .do_ref_add = osd_object_ref_add,
1525 .do_ref_del = osd_object_ref_del,
1526 .do_xattr_get = osd_xattr_get,
1527 .do_xattr_set = osd_xattr_set,
1528 .do_xattr_del = osd_xattr_del,
1529 .do_xattr_list = osd_xattr_list,
1530 .do_capa_get = osd_capa_get,
1531 .do_object_sync = osd_object_sync,
1539 * XXX: Another layering violation for now.
1541 * We don't want to use ->f_op->read methods, because generic file write
1543 * - serializes on ->i_sem, and
1545 * - does a lot of extra work like balance_dirty_pages(),
1547 * which doesn't work for globally shared files like /last-received.
1549 int fsfilt_ldiskfs_read(struct inode *inode, void *buf, int size, loff_t *offs);
1550 int fsfilt_ldiskfs_write_handle(struct inode *inode, void *buf, int bufsize,
1551 loff_t *offs, handle_t *handle);
1553 static ssize_t osd_read(const struct lu_env *env, struct dt_object *dt,
1554 struct lu_buf *buf, loff_t *pos,
1555 struct lustre_capa *capa)
1557 struct inode *inode = osd_dt_obj(dt)->oo_inode;
1559 if (osd_object_auth(env, dt, capa, CAPA_OPC_BODY_READ))
1562 return fsfilt_ldiskfs_read(inode, buf->lb_buf, buf->lb_len, pos);
1565 static ssize_t osd_write(const struct lu_env *env, struct dt_object *dt,
1566 const struct lu_buf *buf, loff_t *pos,
1567 struct thandle *handle, struct lustre_capa *capa)
1569 struct inode *inode = osd_dt_obj(dt)->oo_inode;
1570 struct osd_thandle *oh;
1573 LASSERT(handle != NULL);
1575 if (osd_object_auth(env, dt, capa, CAPA_OPC_BODY_WRITE))
1578 oh = container_of(handle, struct osd_thandle, ot_super);
1579 LASSERT(oh->ot_handle->h_transaction != NULL);
1580 result = fsfilt_ldiskfs_write_handle(inode, buf->lb_buf, buf->lb_len,
1581 pos, oh->ot_handle);
1583 result = buf->lb_len;
1587 static const struct dt_body_operations osd_body_ops = {
1588 .dbo_read = osd_read,
1589 .dbo_write = osd_write
1596 static int osd_object_is_root(const struct osd_object *obj)
1598 return osd_sb(osd_obj2dev(obj))->s_root->d_inode == obj->oo_inode;
1601 static int osd_index_probe(const struct lu_env *env, struct osd_object *o,
1602 const struct dt_index_features *feat)
1604 struct iam_descr *descr;
1606 if (osd_object_is_root(o))
1607 return feat == &dt_directory_features;
1609 LASSERT(o->oo_dir != NULL);
1611 descr = o->oo_dir->od_container.ic_descr;
1612 if (feat == &dt_directory_features)
1613 return descr == &iam_htree_compat_param ||
1614 (descr->id_rec_size == sizeof(struct lu_fid_pack) &&
1616 * XXX check that index looks like directory.
1621 feat->dif_keysize_min <= descr->id_key_size &&
1622 descr->id_key_size <= feat->dif_keysize_max &&
1623 feat->dif_recsize_min <= descr->id_rec_size &&
1624 descr->id_rec_size <= feat->dif_recsize_max &&
1625 !(feat->dif_flags & (DT_IND_VARKEY |
1626 DT_IND_VARREC | DT_IND_NONUNQ)) &&
1627 ergo(feat->dif_flags & DT_IND_UPDATE,
1628 1 /* XXX check that object (and file system) is
1632 static int osd_container_init(const struct lu_env *env,
1633 struct osd_object *obj,
1634 struct osd_directory *dir)
1637 struct iam_container *bag;
1639 bag = &dir->od_container;
1640 result = iam_container_init(bag, &dir->od_descr, obj->oo_inode);
1642 result = iam_container_setup(bag);
1644 obj->oo_dt.do_index_ops = &osd_index_ops;
1646 iam_container_fini(bag);
1652 * Concurrency: no external locking is necessary.
1654 static int osd_index_try(const struct lu_env *env, struct dt_object *dt,
1655 const struct dt_index_features *feat)
1658 struct osd_object *obj = osd_dt_obj(dt);
1660 LINVRNT(osd_invariant(obj));
1661 LASSERT(dt_object_exists(dt));
1663 if (osd_object_is_root(obj)) {
1664 dt->do_index_ops = &osd_index_compat_ops;
1666 } else if (!osd_has_index(obj)) {
1667 struct osd_directory *dir;
1671 sema_init(&dir->od_sem, 1);
1673 spin_lock(&obj->oo_guard);
1674 if (obj->oo_dir == NULL)
1678 * Concurrent thread allocated container data.
1681 spin_unlock(&obj->oo_guard);
1683 * Now, that we have container data, serialize its
1686 down(&obj->oo_dir->od_sem);
1688 * recheck under lock.
1690 if (!osd_has_index(obj))
1691 result = osd_container_init(env, obj, dir);
1694 up(&obj->oo_dir->od_sem);
1701 if (!osd_index_probe(env, obj, feat))
1704 LINVRNT(osd_invariant(obj));
1709 static int osd_index_delete(const struct lu_env *env, struct dt_object *dt,
1710 const struct dt_key *key, struct thandle *handle,
1711 struct lustre_capa *capa)
1713 struct osd_object *obj = osd_dt_obj(dt);
1714 struct osd_thandle *oh;
1715 struct iam_path_descr *ipd;
1716 struct iam_container *bag = &obj->oo_dir->od_container;
1721 LINVRNT(osd_invariant(obj));
1722 LASSERT(dt_object_exists(dt));
1723 LASSERT(bag->ic_object == obj->oo_inode);
1724 LASSERT(handle != NULL);
1726 if (osd_object_auth(env, dt, capa, CAPA_OPC_INDEX_DELETE))
1729 ipd = osd_ipd_get(env, bag);
1730 if (unlikely(ipd == NULL))
1733 oh = container_of0(handle, struct osd_thandle, ot_super);
1734 LASSERT(oh->ot_handle != NULL);
1735 LASSERT(oh->ot_handle->h_transaction != NULL);
1737 rc = iam_delete(oh->ot_handle, bag, (const struct iam_key *)key, ipd);
1738 osd_ipd_put(env, bag, ipd);
1739 LINVRNT(osd_invariant(obj));
1743 static int osd_index_lookup(const struct lu_env *env, struct dt_object *dt,
1744 struct dt_rec *rec, const struct dt_key *key,
1745 struct lustre_capa *capa)
1747 struct osd_object *obj = osd_dt_obj(dt);
1748 struct iam_path_descr *ipd;
1749 struct iam_container *bag = &obj->oo_dir->od_container;
1754 LINVRNT(osd_invariant(obj));
1755 LASSERT(dt_object_exists(dt));
1756 LASSERT(bag->ic_object == obj->oo_inode);
1758 if (osd_object_auth(env, dt, capa, CAPA_OPC_INDEX_LOOKUP))
1761 ipd = osd_ipd_get(env, bag);
1762 if (unlikely(ipd == NULL))
1765 rc = iam_lookup(bag, (const struct iam_key *)key,
1766 (struct iam_rec *)rec, ipd);
1767 osd_ipd_put(env, bag, ipd);
1768 LINVRNT(osd_invariant(obj));
1773 static int osd_index_insert(const struct lu_env *env, struct dt_object *dt,
1774 const struct dt_rec *rec, const struct dt_key *key,
1775 struct thandle *th, struct lustre_capa *capa)
1777 struct osd_object *obj = osd_dt_obj(dt);
1778 struct iam_path_descr *ipd;
1779 struct osd_thandle *oh;
1780 struct iam_container *bag = &obj->oo_dir->od_container;
1785 LINVRNT(osd_invariant(obj));
1786 LASSERT(dt_object_exists(dt));
1787 LASSERT(bag->ic_object == obj->oo_inode);
1788 LASSERT(th != NULL);
1790 if (osd_object_auth(env, dt, capa, CAPA_OPC_INDEX_INSERT))
1793 ipd = osd_ipd_get(env, bag);
1794 if (unlikely(ipd == NULL))
1797 oh = container_of0(th, struct osd_thandle, ot_super);
1798 LASSERT(oh->ot_handle != NULL);
1799 LASSERT(oh->ot_handle->h_transaction != NULL);
1800 rc = iam_insert(oh->ot_handle, bag, (const struct iam_key *)key,
1801 (struct iam_rec *)rec, ipd);
1802 osd_ipd_put(env, bag, ipd);
1803 LINVRNT(osd_invariant(obj));
1808 * Iterator operations.
1811 struct osd_object *oi_obj;
1812 struct iam_path_descr *oi_ipd;
1813 struct iam_iterator oi_it;
1816 static struct dt_it *osd_it_init(const struct lu_env *env,
1817 struct dt_object *dt, int writable,
1818 struct lustre_capa *capa)
1821 struct osd_object *obj = osd_dt_obj(dt);
1822 struct lu_object *lo = &dt->do_lu;
1823 struct iam_path_descr *ipd;
1824 struct iam_container *bag = &obj->oo_dir->od_container;
1827 LASSERT(lu_object_exists(lo));
1829 if (osd_object_auth(env, dt, capa, writable ? CAPA_OPC_BODY_WRITE :
1830 CAPA_OPC_BODY_READ))
1831 return ERR_PTR(-EACCES);
1833 flags = writable ? IAM_IT_MOVE|IAM_IT_WRITE : IAM_IT_MOVE;
1837 * XXX: as ipd is allocated within osd_thread_info, assignment
1838 * below implies that iterator usage is confined within single
1841 ipd = osd_ipd_get(env, bag);
1842 if (likely(ipd != NULL)) {
1846 iam_it_init(&it->oi_it, bag, flags, ipd);
1847 return (struct dt_it *)it;
1851 return ERR_PTR(-ENOMEM);
1854 static void osd_it_fini(const struct lu_env *env, struct dt_it *di)
1856 struct osd_it *it = (struct osd_it *)di;
1857 struct osd_object *obj = it->oi_obj;
1859 iam_it_fini(&it->oi_it);
1860 osd_ipd_put(env, &obj->oo_dir->od_container, it->oi_ipd);
1861 lu_object_put(env, &obj->oo_dt.do_lu);
1865 static int osd_it_get(const struct lu_env *env,
1866 struct dt_it *di, const struct dt_key *key)
1868 struct osd_it *it = (struct osd_it *)di;
1870 return iam_it_get(&it->oi_it, (const struct iam_key *)key);
1873 static void osd_it_put(const struct lu_env *env, struct dt_it *di)
1875 struct osd_it *it = (struct osd_it *)di;
1877 iam_it_put(&it->oi_it);
1880 static int osd_it_next(const struct lu_env *env, struct dt_it *di)
1882 struct osd_it *it = (struct osd_it *)di;
1884 return iam_it_next(&it->oi_it);
1887 static int osd_it_del(const struct lu_env *env, struct dt_it *di,
1890 struct osd_it *it = (struct osd_it *)di;
1891 struct osd_thandle *oh;
1893 LASSERT(th != NULL);
1895 oh = container_of0(th, struct osd_thandle, ot_super);
1896 LASSERT(oh->ot_handle != NULL);
1897 LASSERT(oh->ot_handle->h_transaction != NULL);
1899 return iam_it_rec_delete(oh->ot_handle, &it->oi_it);
1902 static struct dt_key *osd_it_key(const struct lu_env *env,
1903 const struct dt_it *di)
1905 struct osd_it *it = (struct osd_it *)di;
1907 return (struct dt_key *)iam_it_key_get(&it->oi_it);
1910 static int osd_it_key_size(const struct lu_env *env, const struct dt_it *di)
1912 struct osd_it *it = (struct osd_it *)di;
1914 return iam_it_key_size(&it->oi_it);
1917 static struct dt_rec *osd_it_rec(const struct lu_env *env,
1918 const struct dt_it *di)
1920 struct osd_it *it = (struct osd_it *)di;
1922 return (struct dt_rec *)iam_it_rec_get(&it->oi_it);
1925 static __u64 osd_it_store(const struct lu_env *env, const struct dt_it *di)
1927 struct osd_it *it = (struct osd_it *)di;
1929 return iam_it_store(&it->oi_it);
1932 static int osd_it_load(const struct lu_env *env,
1933 const struct dt_it *di, __u64 hash)
1935 struct osd_it *it = (struct osd_it *)di;
1937 return iam_it_load(&it->oi_it, hash);
1940 static const struct dt_index_operations osd_index_ops = {
1941 .dio_lookup = osd_index_lookup,
1942 .dio_insert = osd_index_insert,
1943 .dio_delete = osd_index_delete,
1945 .init = osd_it_init,
1946 .fini = osd_it_fini,
1950 .next = osd_it_next,
1952 .key_size = osd_it_key_size,
1954 .store = osd_it_store,
1959 static int osd_index_compat_delete(const struct lu_env *env,
1960 struct dt_object *dt,
1961 const struct dt_key *key,
1962 struct thandle *handle,
1963 struct lustre_capa *capa)
1965 struct osd_object *obj = osd_dt_obj(dt);
1967 LASSERT(handle != NULL);
1968 LASSERT(S_ISDIR(obj->oo_inode->i_mode));
1972 if (osd_object_auth(env, dt, capa, CAPA_OPC_INDEX_DELETE))
1976 RETURN(-EOPNOTSUPP);
1980 * Compatibility index operations.
1984 static void osd_build_pack(const struct lu_env *env, struct osd_device *osd,
1985 struct dentry *dentry, struct lu_fid_pack *pack)
1987 struct inode *inode = dentry->d_inode;
1988 struct lu_fid *fid = &osd_oti_get(env)->oti_fid;
1990 lu_igif_build(fid, inode->i_ino, inode->i_generation);
1991 fid_cpu_to_be(fid, fid);
1992 pack->fp_len = sizeof *fid + 1;
1993 memcpy(pack->fp_area, fid, sizeof *fid);
1996 static int osd_index_compat_lookup(const struct lu_env *env,
1997 struct dt_object *dt,
1998 struct dt_rec *rec, const struct dt_key *key,
1999 struct lustre_capa *capa)
2001 struct osd_object *obj = osd_dt_obj(dt);
2003 struct osd_device *osd = osd_obj2dev(obj);
2004 struct osd_thread_info *info = osd_oti_get(env);
2010 * XXX temporary solution.
2012 struct dentry *dentry;
2013 struct dentry *parent;
2015 LINVRNT(osd_invariant(obj));
2016 LASSERT(S_ISDIR(obj->oo_inode->i_mode));
2017 LASSERT(osd_has_index(obj));
2019 if (osd_object_auth(env, dt, capa, CAPA_OPC_INDEX_LOOKUP))
2022 info->oti_str.name = (const char *)key;
2023 info->oti_str.len = strlen((const char *)key);
2025 dir = obj->oo_inode;
2026 LASSERT(dir->i_op != NULL && dir->i_op->lookup != NULL);
2028 parent = d_alloc_root(dir);
2032 dentry = d_alloc(parent, &info->oti_str);
2033 if (dentry != NULL) {
2037 * XXX passing NULL for nameidata should work for
2040 d = dir->i_op->lookup(dir, dentry, NULL);
2043 * normal case, result is in @dentry.
2045 if (dentry->d_inode != NULL) {
2046 osd_build_pack(env, osd, dentry,
2047 (struct lu_fid_pack *)rec);
2052 /* What? Disconnected alias? Ppheeeww... */
2053 CERROR("Aliasing where not expected\n");
2061 LINVRNT(osd_invariant(obj));
2065 static int osd_add_rec(struct osd_thread_info *info, struct osd_device *dev,
2066 struct inode *dir, struct inode *inode, const char *name)
2070 struct dentry *parent;
2074 info->oti_str.name = name;
2075 info->oti_str.len = strlen(name);
2077 LASSERT(atomic_read(&dir->i_count) > 0);
2079 old = d_alloc(dev->od_obj_area, &info->oti_str);
2081 d_instantiate(old, inode);
2083 LASSERT(atomic_read(&dir->i_count) > 0);
2084 parent = d_alloc_root(dir);
2085 if (parent != NULL) {
2087 LASSERT(atomic_read(&dir->i_count) > 1);
2088 new = d_alloc(parent, &info->oti_str);
2089 LASSERT(atomic_read(&dir->i_count) > 1);
2091 LASSERT(atomic_read(&dir->i_count) > 1);
2092 result = dir->i_op->link(old, dir, new);
2093 LASSERT(atomic_read(&dir->i_count) > 1);
2095 LASSERT(atomic_read(&dir->i_count) > 1);
2097 LASSERT(atomic_read(&dir->i_count) > 1);
2099 LASSERT(atomic_read(&dir->i_count) > 0);
2103 LASSERT(atomic_read(&dir->i_count) > 0);
2109 * XXX Temporary stuff.
2111 static int osd_index_compat_insert(const struct lu_env *env,
2112 struct dt_object *dt,
2113 const struct dt_rec *rec,
2114 const struct dt_key *key, struct thandle *th,
2115 struct lustre_capa *capa)
2117 struct osd_object *obj = osd_dt_obj(dt);
2119 const char *name = (const char *)key;
2121 struct lu_device *ludev = dt->do_lu.lo_dev;
2122 struct lu_object *luch;
2124 struct osd_thread_info *info = osd_oti_get(env);
2125 const struct lu_fid_pack *pack = (const struct lu_fid_pack *)rec;
2126 struct lu_fid *fid = &osd_oti_get(env)->oti_fid;
2130 LASSERT(S_ISDIR(obj->oo_inode->i_mode));
2131 LINVRNT(osd_invariant(obj));
2132 LASSERT(th != NULL);
2134 if (osd_object_auth(env, dt, capa, CAPA_OPC_INDEX_INSERT))
2137 result = fid_unpack(pack, fid);
2141 luch = lu_object_find(env, ludev, fid, NULL);
2142 if (!IS_ERR(luch)) {
2143 if (lu_object_exists(luch)) {
2144 struct osd_object *child;
2146 child = osd_obj(lu_object_locate(luch->lo_header,
2149 result = osd_add_rec(info, osd_obj2dev(obj),
2151 child->oo_inode, name);
2153 CERROR("No osd slice.\n");
2156 LINVRNT(osd_invariant(obj));
2157 LINVRNT(osd_invariant(child));
2162 lu_object_put(env, luch);
2164 result = PTR_ERR(luch);
2165 LINVRNT(osd_invariant(obj));
2169 static const struct dt_index_operations osd_index_compat_ops = {
2170 .dio_lookup = osd_index_compat_lookup,
2171 .dio_insert = osd_index_compat_insert,
2172 .dio_delete = osd_index_compat_delete
2175 /* type constructor/destructor: osd_type_init, osd_type_fini */
2176 LU_TYPE_INIT_FINI(osd, &osd_key);
2178 static struct lu_context_key osd_key = {
2179 .lct_tags = LCT_DT_THREAD | LCT_MD_THREAD,
2180 .lct_init = osd_key_init,
2181 .lct_fini = osd_key_fini,
2182 .lct_exit = osd_key_exit
2185 static void *osd_key_init(const struct lu_context *ctx,
2186 struct lu_context_key *key)
2188 struct osd_thread_info *info;
2190 OBD_ALLOC_PTR(info);
2192 info->oti_env = container_of(ctx, struct lu_env, le_ctx);
2194 info = ERR_PTR(-ENOMEM);
2198 /* context key destructor: osd_key_fini */
2199 LU_KEY_FINI(osd, struct osd_thread_info);
2201 static void osd_key_exit(const struct lu_context *ctx,
2202 struct lu_context_key *key, void *data)
2204 struct osd_thread_info *info = data;
2206 LASSERT(info->oti_r_locks == 0);
2207 LASSERT(info->oti_w_locks == 0);
2208 LASSERT(info->oti_txns == 0);
2211 static int osd_device_init(const struct lu_env *env, struct lu_device *d,
2212 const char *name, struct lu_device *next)
2215 /* context for commit hooks */
2216 rc = lu_context_init(&osd_dev(d)->od_env_for_commit.le_ctx,
2219 rc = osd_procfs_init(osd_dev(d), name);
2223 static int osd_shutdown(const struct lu_env *env, struct osd_device *o)
2225 struct osd_thread_info *info = osd_oti_get(env);
2227 if (o->od_obj_area != NULL) {
2228 dput(o->od_obj_area);
2229 o->od_obj_area = NULL;
2231 osd_oi_fini(info, &o->od_oi);
2236 static int osd_mount(const struct lu_env *env,
2237 struct osd_device *o, struct lustre_cfg *cfg)
2239 struct lustre_mount_info *lmi;
2240 const char *dev = lustre_cfg_string(cfg, 0);
2241 struct osd_thread_info *info = osd_oti_get(env);
2246 if (o->od_mount != NULL) {
2247 CERROR("Already mounted (%s)\n", dev);
2252 lmi = server_get_mount(dev);
2254 CERROR("Cannot get mount info for %s!\n", dev);
2258 LASSERT(lmi != NULL);
2259 /* save lustre_mount_info in dt_device */
2262 result = osd_oi_init(info, &o->od_oi, &o->od_dt_dev);
2266 d = simple_mkdir(osd_sb(o)->s_root, lmi->lmi_mnt, "*OBJ-TEMP*",
2271 result = PTR_ERR(d);
2274 osd_shutdown(env, o);
2278 static struct lu_device *osd_device_fini(const struct lu_env *env,
2279 struct lu_device *d)
2284 shrink_dcache_sb(osd_sb(osd_dev(d)));
2285 osd_sync(env, lu2dt_dev(d));
2287 rc = osd_procfs_fini(osd_dev(d));
2289 CERROR("proc fini error %d \n", rc);
2290 RETURN (ERR_PTR(rc));
2293 if (osd_dev(d)->od_mount)
2294 server_put_mount(osd_dev(d)->od_mount->lmi_name,
2295 osd_dev(d)->od_mount->lmi_mnt);
2296 osd_dev(d)->od_mount = NULL;
2298 lu_context_fini(&osd_dev(d)->od_env_for_commit.le_ctx);
2302 static struct lu_device *osd_device_alloc(const struct lu_env *env,
2303 struct lu_device_type *t,
2304 struct lustre_cfg *cfg)
2306 struct lu_device *l;
2307 struct osd_device *o;
2313 result = dt_device_init(&o->od_dt_dev, t);
2316 l->ld_ops = &osd_lu_ops;
2317 o->od_dt_dev.dd_ops = &osd_dt_ops;
2318 spin_lock_init(&o->od_osfs_lock);
2319 o->od_osfs_age = cfs_time_shift_64(-1000);
2320 o->od_capa_hash = init_capa_hash();
2321 if (o->od_capa_hash == NULL) {
2322 dt_device_fini(&o->od_dt_dev);
2323 l = ERR_PTR(-ENOMEM);
2326 l = ERR_PTR(result);
2331 l = ERR_PTR(-ENOMEM);
2335 static struct lu_device *osd_device_free(const struct lu_env *env,
2336 struct lu_device *d)
2338 struct osd_device *o = osd_dev(d);
2341 cleanup_capa_hash(o->od_capa_hash);
2342 dt_device_fini(&o->od_dt_dev);
2347 static int osd_process_config(const struct lu_env *env,
2348 struct lu_device *d, struct lustre_cfg *cfg)
2350 struct osd_device *o = osd_dev(d);
2354 switch(cfg->lcfg_command) {
2356 err = osd_mount(env, o, cfg);
2359 err = osd_shutdown(env, o);
2367 extern void ldiskfs_orphan_cleanup (struct super_block * sb,
2368 struct ldiskfs_super_block * es);
2370 static int osd_recovery_complete(const struct lu_env *env,
2371 struct lu_device *d)
2373 struct osd_device *o = osd_dev(d);
2375 /* TODO: orphans handling */
2376 ldiskfs_orphan_cleanup(osd_sb(o), LDISKFS_SB(osd_sb(o))->s_es);
2380 static struct inode *osd_iget(struct osd_thread_info *info,
2381 struct osd_device *dev,
2382 const struct osd_inode_id *id)
2384 struct inode *inode;
2386 inode = iget(osd_sb(dev), id->oii_ino);
2387 if (inode == NULL) {
2388 CERROR("no inode\n");
2389 inode = ERR_PTR(-EACCES);
2390 } else if (is_bad_inode(inode)) {
2391 CERROR("bad inode\n");
2393 inode = ERR_PTR(-ENOENT);
2394 } else if (inode->i_generation != id->oii_gen) {
2395 CERROR("stale inode\n");
2397 inode = ERR_PTR(-ESTALE);
2404 static int osd_fid_lookup(const struct lu_env *env,
2405 struct osd_object *obj, const struct lu_fid *fid)
2407 struct osd_thread_info *info;
2408 struct lu_device *ldev = obj->oo_dt.do_lu.lo_dev;
2409 struct osd_device *dev;
2410 struct osd_inode_id *id;
2412 struct inode *inode;
2415 LINVRNT(osd_invariant(obj));
2416 LASSERT(obj->oo_inode == NULL);
2417 LASSERT(fid_is_sane(fid));
2419 * This assertion checks that osd layer sees only local
2420 * fids. Unfortunately it is somewhat expensive (does a
2421 * cache-lookup). Disabling it for production/acceptance-testing.
2423 LASSERT(1 || fid_is_local(ldev->ld_site, fid));
2427 info = osd_oti_get(env);
2428 dev = osd_dev(ldev);
2432 if (OBD_FAIL_CHECK(OBD_FAIL_OST_ENOENT))
2435 result = osd_oi_lookup(info, oi, fid, id);
2437 inode = osd_iget(info, dev, id);
2438 if (!IS_ERR(inode)) {
2439 obj->oo_inode = inode;
2440 LASSERT(obj->oo_inode->i_sb == osd_sb(dev));
2444 * If fid wasn't found in oi, inode-less object is
2445 * created, for which lu_object_exists() returns
2446 * false. This is used in a (frequent) case when
2447 * objects are created as locking anchors or
2448 * place holders for objects yet to be created.
2450 result = PTR_ERR(inode);
2451 } else if (result == -ENOENT)
2453 LINVRNT(osd_invariant(obj));
2457 static void osd_inode_getattr(const struct lu_env *env,
2458 struct inode *inode, struct lu_attr *attr)
2460 attr->la_valid |= LA_ATIME | LA_MTIME | LA_CTIME | LA_MODE |
2461 LA_SIZE | LA_BLOCKS | LA_UID | LA_GID |
2462 LA_FLAGS | LA_NLINK | LA_RDEV | LA_BLKSIZE;
2464 attr->la_atime = LTIME_S(inode->i_atime);
2465 attr->la_mtime = LTIME_S(inode->i_mtime);
2466 attr->la_ctime = LTIME_S(inode->i_ctime);
2467 attr->la_mode = inode->i_mode;
2468 attr->la_size = i_size_read(inode);
2469 attr->la_blocks = inode->i_blocks;
2470 attr->la_uid = inode->i_uid;
2471 attr->la_gid = inode->i_gid;
2472 attr->la_flags = LDISKFS_I(inode)->i_flags;
2473 attr->la_nlink = inode->i_nlink;
2474 attr->la_rdev = inode->i_rdev;
2475 attr->la_blksize = ll_inode_blksize(inode);
2476 attr->la_blkbits = inode->i_blkbits;
2483 static int lu_device_is_osd(const struct lu_device *d)
2485 return ergo(d != NULL && d->ld_ops != NULL, d->ld_ops == &osd_lu_ops);
2488 static struct osd_object *osd_obj(const struct lu_object *o)
2490 LASSERT(lu_device_is_osd(o->lo_dev));
2491 return container_of0(o, struct osd_object, oo_dt.do_lu);
2494 static struct osd_device *osd_dt_dev(const struct dt_device *d)
2496 LASSERT(lu_device_is_osd(&d->dd_lu_dev));
2497 return container_of0(d, struct osd_device, od_dt_dev);
2500 static struct osd_device *osd_dev(const struct lu_device *d)
2502 LASSERT(lu_device_is_osd(d));
2503 return osd_dt_dev(container_of0(d, struct dt_device, dd_lu_dev));
2506 static struct osd_object *osd_dt_obj(const struct dt_object *d)
2508 return osd_obj(&d->do_lu);
2511 static struct osd_device *osd_obj2dev(const struct osd_object *o)
2513 return osd_dev(o->oo_dt.do_lu.lo_dev);
2516 static struct lu_device *osd2lu_dev(struct osd_device *osd)
2518 return &osd->od_dt_dev.dd_lu_dev;
2521 static struct super_block *osd_sb(const struct osd_device *dev)
2523 return dev->od_mount->lmi_mnt->mnt_sb;
2526 static journal_t *osd_journal(const struct osd_device *dev)
2528 return LDISKFS_SB(osd_sb(dev))->s_journal;
2531 static int osd_has_index(const struct osd_object *obj)
2533 return obj->oo_dt.do_index_ops != NULL;
2536 static int osd_object_invariant(const struct lu_object *l)
2538 return osd_invariant(osd_obj(l));
2541 static const struct lu_object_operations osd_lu_obj_ops = {
2542 .loo_object_init = osd_object_init,
2543 .loo_object_delete = osd_object_delete,
2544 .loo_object_release = osd_object_release,
2545 .loo_object_free = osd_object_free,
2546 .loo_object_print = osd_object_print,
2547 .loo_object_invariant = osd_object_invariant
2550 static const struct lu_device_operations osd_lu_ops = {
2551 .ldo_object_alloc = osd_object_alloc,
2552 .ldo_process_config = osd_process_config,
2553 .ldo_recovery_complete = osd_recovery_complete
2556 static const struct lu_device_type_operations osd_device_type_ops = {
2557 .ldto_init = osd_type_init,
2558 .ldto_fini = osd_type_fini,
2560 .ldto_start = osd_type_start,
2561 .ldto_stop = osd_type_stop,
2563 .ldto_device_alloc = osd_device_alloc,
2564 .ldto_device_free = osd_device_free,
2566 .ldto_device_init = osd_device_init,
2567 .ldto_device_fini = osd_device_fini
2570 static struct lu_device_type osd_device_type = {
2571 .ldt_tags = LU_DEVICE_DT,
2572 .ldt_name = LUSTRE_OSD_NAME,
2573 .ldt_ops = &osd_device_type_ops,
2574 .ldt_ctx_tags = LCT_MD_THREAD|LCT_DT_THREAD
2578 * lprocfs legacy support.
2580 static struct obd_ops osd_obd_device_ops = {
2581 .o_owner = THIS_MODULE
2584 static int __init osd_mod_init(void)
2586 struct lprocfs_static_vars lvars;
2588 lprocfs_osd_init_vars(&lvars);
2589 return class_register_type(&osd_obd_device_ops, NULL, lvars.module_vars,
2590 LUSTRE_OSD_NAME, &osd_device_type);
2593 static void __exit osd_mod_exit(void)
2595 class_unregister_type(LUSTRE_OSD_NAME);
2598 MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");
2599 MODULE_DESCRIPTION("Lustre Object Storage Device ("LUSTRE_OSD_NAME")");
2600 MODULE_LICENSE("GPL");
2602 cfs_module(osd, "0.0.2", osd_mod_init, osd_mod_exit);