4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
27 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2011, 2012, Whamcloud, Inc.
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>
41 * Pravin Shelar <pravin.shelar@sun.com> : Added fid in dirent
44 #define DEBUG_SUBSYSTEM S_MDS
46 #include <linux/module.h>
48 /* LUSTRE_VERSION_CODE */
49 #include <lustre_ver.h>
50 /* prerequisite for linux/xattr.h */
51 #include <linux/types.h>
52 /* prerequisite for linux/xattr.h */
54 /* XATTR_{REPLACE,CREATE} */
55 #include <linux/xattr.h>
60 * struct OBD_{ALLOC,FREE}*()
63 #include <obd_support.h>
64 /* struct ptlrpc_thread */
65 #include <lustre_net.h>
68 #include <lustre_fid.h>
70 #include "osd_internal.h"
73 /* llo_* api support */
74 #include <md_object.h>
75 #include <lustre_quota.h>
77 #ifdef HAVE_LDISKFS_PDO
79 CFS_MODULE_PARM(ldiskfs_pdo, "i", int, 0644,
80 "ldiskfs with parallel directory operations");
85 static const char dot[] = ".";
86 static const char dotdot[] = "..";
87 static const char remote_obj_dir[] = "REM_OBJ_DIR";
89 static const struct lu_object_operations osd_lu_obj_ops;
90 static const struct dt_object_operations osd_obj_ops;
91 static const struct dt_object_operations osd_obj_ea_ops;
92 static const struct dt_object_operations osd_obj_otable_it_ops;
93 static const struct dt_index_operations osd_index_iam_ops;
94 static const struct dt_index_operations osd_index_ea_ops;
96 static int osd_has_index(const struct osd_object *obj)
98 return obj->oo_dt.do_index_ops != NULL;
101 static int osd_object_invariant(const struct lu_object *l)
103 return osd_invariant(osd_obj(l));
107 * Concurrency: doesn't matter
109 static int osd_read_locked(const struct lu_env *env, struct osd_object *o)
111 return osd_oti_get(env)->oti_r_locks > 0;
115 * Concurrency: doesn't matter
117 static int osd_write_locked(const struct lu_env *env, struct osd_object *o)
119 struct osd_thread_info *oti = osd_oti_get(env);
120 return oti->oti_w_locks > 0 && o->oo_owner == env;
124 * Concurrency: doesn't access mutable data
126 static int osd_root_get(const struct lu_env *env,
127 struct dt_device *dev, struct lu_fid *f)
129 lu_local_obj_fid(f, OSD_FS_ROOT_OID);
134 * OSD object methods.
138 * Concurrency: no concurrent access is possible that early in object
141 static struct lu_object *osd_object_alloc(const struct lu_env *env,
142 const struct lu_object_header *hdr,
145 struct osd_object *mo;
151 l = &mo->oo_dt.do_lu;
152 dt_object_init(&mo->oo_dt, NULL, d);
153 if (osd_dev(d)->od_iop_mode)
154 mo->oo_dt.do_ops = &osd_obj_ea_ops;
156 mo->oo_dt.do_ops = &osd_obj_ops;
158 l->lo_ops = &osd_lu_obj_ops;
159 cfs_init_rwsem(&mo->oo_sem);
160 cfs_init_rwsem(&mo->oo_ext_idx_sem);
161 cfs_spin_lock_init(&mo->oo_guard);
168 static int osd_get_lma(struct inode *inode, struct dentry *dentry,
169 struct lustre_mdt_attrs *lma)
173 dentry->d_inode = inode;
174 rc = inode->i_op->getxattr(dentry, XATTR_NAME_LMA, (void *)lma,
177 /* Check LMA compatibility */
178 if (lma->lma_incompat & ~cpu_to_le32(LMA_INCOMPAT_SUPP)) {
179 CWARN("%.16s: unsupported incompat LMA feature(s) "
181 LDISKFS_SB(inode->i_sb)->s_es->s_volume_name,
182 inode->i_ino, le32_to_cpu(lma->lma_incompat) &
186 lustre_lma_swab(lma);
189 } else if (rc == 0) {
197 * retrieve object from backend ext fs.
199 struct inode *osd_iget(struct osd_thread_info *info, struct osd_device *dev,
200 struct osd_inode_id *id)
202 struct inode *inode = NULL;
204 inode = ldiskfs_iget(osd_sb(dev), id->oii_ino);
206 CDEBUG(D_INODE, "no inode: ino = %u, rc = %ld\n",
207 id->oii_ino, PTR_ERR(inode));
208 } else if (id->oii_gen != OSD_OII_NOGEN &&
209 inode->i_generation != id->oii_gen) {
210 CDEBUG(D_INODE, "unmatched inode: ino = %u, gen0 = %u, "
212 id->oii_ino, id->oii_gen, inode->i_generation);
214 inode = ERR_PTR(-ESTALE);
215 } else if (inode->i_nlink == 0) {
216 /* due to parallel readdir and unlink,
217 * we can have dead inode here. */
218 CDEBUG(D_INODE, "stale inode: ino = %u\n", id->oii_ino);
219 make_bad_inode(inode);
221 inode = ERR_PTR(-ESTALE);
222 } else if (is_bad_inode(inode)) {
223 CWARN("%.16s: bad inode: ino = %u\n",
224 LDISKFS_SB(osd_sb(dev))->s_es->s_volume_name, id->oii_ino);
226 inode = ERR_PTR(-ENOENT);
228 if (id->oii_gen == OSD_OII_NOGEN)
229 osd_id_gen(id, inode->i_ino, inode->i_generation);
231 /* Do not update file c/mtime in ldiskfs.
232 * NB: we don't have any lock to protect this because we don't
233 * have reference on osd_object now, but contention with
234 * another lookup + attr_set can't happen in the tiny window
235 * between if (...) and set S_NOCMTIME. */
236 if (!(inode->i_flags & S_NOCMTIME))
237 inode->i_flags |= S_NOCMTIME;
242 struct inode *osd_iget_fid(struct osd_thread_info *info, struct osd_device *dev,
243 struct osd_inode_id *id, struct lu_fid *fid)
245 struct lustre_mdt_attrs *lma = &info->oti_mdt_attrs;
249 inode = osd_iget(info, dev, id);
253 rc = osd_get_lma(inode, &info->oti_obj_dentry, lma);
255 *fid = lma->lma_self_fid;
256 } else if (rc == -ENODATA) {
257 LU_IGIF_BUILD(fid, inode->i_ino, inode->i_generation);
265 static struct inode *
266 osd_iget_verify(struct osd_thread_info *info, struct osd_device *dev,
267 struct osd_inode_id *id, const struct lu_fid *fid)
269 struct lustre_mdt_attrs *lma = &info->oti_mdt_attrs;
273 inode = osd_iget(info, dev, id);
277 rc = osd_get_lma(inode, &info->oti_obj_dentry, lma);
286 if (!lu_fid_eq(fid, &lma->lma_self_fid)) {
287 CDEBUG(D_LFSCK, "inconsistent obj: "DFID", %lu, "DFID"\n",
288 PFID(&lma->lma_self_fid), inode->i_ino, PFID(fid));
290 return ERR_PTR(-EREMCHG);
296 static int osd_fid_lookup(const struct lu_env *env, struct osd_object *obj,
297 const struct lu_fid *fid,
298 const struct lu_object_conf *conf)
300 struct osd_thread_info *info;
301 struct lu_device *ldev = obj->oo_dt.do_lu.lo_dev;
302 struct osd_device *dev;
303 struct osd_idmap_cache *oic;
304 struct osd_inode_id *id;
306 struct osd_scrub *scrub;
307 struct scrub_file *sf;
312 LINVRNT(osd_invariant(obj));
313 LASSERT(obj->oo_inode == NULL);
314 LASSERTF(fid_is_sane(fid) || fid_is_idif(fid), DFID, PFID(fid));
317 scrub = &dev->od_scrub;
318 sf = &scrub->os_file;
319 info = osd_oti_get(env);
321 oic = &info->oti_cache;
323 if (OBD_FAIL_CHECK(OBD_FAIL_OST_ENOENT))
326 /* Search order: 1. per-thread cache. */
327 if (lu_fid_eq(fid, &oic->oic_fid)) {
333 if (!cfs_list_empty(&scrub->os_inconsistent_items)) {
334 /* Search order: 2. OI scrub pending list. */
335 result = osd_oii_lookup(dev, fid, id);
340 if (sf->sf_flags & SF_INCONSISTENT)
344 * Objects are created as locking anchors or place holders for objects
345 * yet to be created. No need to osd_oi_lookup() at here because FID
346 * shouldn't never be re-used, if it's really a duplicate FID from
347 * unexpected reason, we should be able to detect it later by calling
348 * do_create->osd_oi_insert()
350 if (conf != NULL && (conf->loc_flags & LOC_F_NEW) != 0)
351 GOTO(out, result = 0);
353 /* Search order: 3. OI files. */
354 result = osd_oi_lookup(info, dev, fid, id);
355 if (result == -ENOENT) {
356 if (!fid_is_norm(fid) ||
357 !ldiskfs_test_bit(osd_oi_fid2idx(dev,fid),
359 GOTO(out, result = 0);
369 inode = osd_iget(info, dev, id);
371 inode = osd_iget_verify(info, dev, id, fid);
373 result = PTR_ERR(inode);
374 if (result == -ENOENT || result == -ESTALE) {
375 fid_zero(&oic->oic_fid);
377 } else if (result == -EREMCHG) {
380 if (thread_is_running(&scrub->os_thread)) {
381 result = -EINPROGRESS;
382 } else if (!dev->od_noscrub) {
383 result = osd_scrub_start(dev);
384 LCONSOLE_ERROR("%.16s: trigger OI scrub by RPC "
385 "for "DFID", rc = %d [1]\n",
386 LDISKFS_SB(osd_sb(dev))->s_es->\
387 s_volume_name,PFID(fid), result);
388 if (result == 0 || result == -EALREADY)
389 result = -EINPROGRESS;
398 obj->oo_inode = inode;
399 LASSERT(obj->oo_inode->i_sb == osd_sb(dev));
400 if (dev->od_iop_mode) {
401 obj->oo_compat_dot_created = 1;
402 obj->oo_compat_dotdot_created = 1;
405 if (!S_ISDIR(inode->i_mode) || !ldiskfs_pdo) /* done */
406 GOTO(out, result = 0);
408 LASSERT(obj->oo_hl_head == NULL);
409 obj->oo_hl_head = ldiskfs_htree_lock_head_alloc(HTREE_HBITS_DEF);
410 if (obj->oo_hl_head == NULL) {
411 obj->oo_inode = NULL;
413 GOTO(out, result = -ENOMEM);
415 GOTO(out, result = 0);
418 LINVRNT(osd_invariant(obj));
423 * Concurrency: shouldn't matter.
425 static void osd_object_init0(struct osd_object *obj)
427 LASSERT(obj->oo_inode != NULL);
428 obj->oo_dt.do_body_ops = &osd_body_ops;
429 obj->oo_dt.do_lu.lo_header->loh_attr |=
430 (LOHA_EXISTS | (obj->oo_inode->i_mode & S_IFMT));
434 * Concurrency: no concurrent access is possible that early in object
437 static int osd_object_init(const struct lu_env *env, struct lu_object *l,
438 const struct lu_object_conf *conf)
440 struct osd_object *obj = osd_obj(l);
443 LINVRNT(osd_invariant(obj));
445 result = osd_fid_lookup(env, obj, lu_object_fid(l), conf);
446 obj->oo_dt.do_body_ops = &osd_body_ops_new;
448 if (obj->oo_inode != NULL) {
449 osd_object_init0(obj);
450 } else if (fid_is_otable_it(&l->lo_header->loh_fid)) {
451 obj->oo_dt.do_ops = &osd_obj_otable_it_ops;
452 /* LFSCK iterator object is special without inode */
453 l->lo_header->loh_attr |= LOHA_EXISTS;
456 LINVRNT(osd_invariant(obj));
461 * Concurrency: no concurrent access is possible that late in object
464 static void osd_object_free(const struct lu_env *env, struct lu_object *l)
466 struct osd_object *obj = osd_obj(l);
468 LINVRNT(osd_invariant(obj));
470 dt_object_fini(&obj->oo_dt);
471 if (obj->oo_hl_head != NULL)
472 ldiskfs_htree_lock_head_free(obj->oo_hl_head);
477 * Concurrency: no concurrent access is possible that late in object
480 static void osd_index_fini(struct osd_object *o)
482 struct iam_container *bag;
484 if (o->oo_dir != NULL) {
485 bag = &o->oo_dir->od_container;
486 if (o->oo_inode != NULL) {
487 if (bag->ic_object == o->oo_inode)
488 iam_container_fini(bag);
490 OBD_FREE_PTR(o->oo_dir);
496 * Concurrency: no concurrent access is possible that late in object
497 * life-cycle (for all existing callers, that is. New callers have to provide
498 * their own locking.)
500 static int osd_inode_unlinked(const struct inode *inode)
502 return inode->i_nlink == 0;
506 OSD_TXN_OI_DELETE_CREDITS = 20,
507 OSD_TXN_INODE_DELETE_CREDITS = 20
514 #if OSD_THANDLE_STATS
516 * Set time when the handle is allocated
518 static void osd_th_alloced(struct osd_thandle *oth)
520 oth->oth_alloced = cfs_time_current();
524 * Set time when the handle started
526 static void osd_th_started(struct osd_thandle *oth)
528 oth->oth_started = cfs_time_current();
532 * Helper function to convert time interval to microseconds packed in
533 * long int (default time units for the counter in "stats" initialized
534 * by lu_time_init() )
536 static long interval_to_usec(cfs_time_t start, cfs_time_t end)
540 cfs_duration_usec(cfs_time_sub(end, start), &val);
541 return val.tv_sec * 1000000 + val.tv_usec;
545 * Check whether the we deal with this handle for too long.
547 static void __osd_th_check_slow(void *oth, struct osd_device *dev,
548 cfs_time_t alloced, cfs_time_t started,
551 cfs_time_t now = cfs_time_current();
553 LASSERT(dev != NULL);
555 lprocfs_counter_add(dev->od_stats, LPROC_OSD_THANDLE_STARTING,
556 interval_to_usec(alloced, started));
557 lprocfs_counter_add(dev->od_stats, LPROC_OSD_THANDLE_OPEN,
558 interval_to_usec(started, closed));
559 lprocfs_counter_add(dev->od_stats, LPROC_OSD_THANDLE_CLOSING,
560 interval_to_usec(closed, now));
562 if (cfs_time_before(cfs_time_add(alloced, cfs_time_seconds(30)), now)) {
563 CWARN("transaction handle %p was open for too long: "
565 "alloced "CFS_TIME_T" ,"
566 "started "CFS_TIME_T" ,"
567 "closed "CFS_TIME_T"\n",
568 oth, now, alloced, started, closed);
569 libcfs_debug_dumpstack(NULL);
573 #define OSD_CHECK_SLOW_TH(oth, dev, expr) \
575 cfs_time_t __closed = cfs_time_current(); \
576 cfs_time_t __alloced = oth->oth_alloced; \
577 cfs_time_t __started = oth->oth_started; \
580 __osd_th_check_slow(oth, dev, __alloced, __started, __closed); \
583 #else /* OSD_THANDLE_STATS */
585 #define osd_th_alloced(h) do {} while(0)
586 #define osd_th_started(h) do {} while(0)
587 #define OSD_CHECK_SLOW_TH(oth, dev, expr) expr
589 #endif /* OSD_THANDLE_STATS */
592 * Concurrency: doesn't access mutable data.
594 static int osd_param_is_not_sane(const struct osd_device *dev,
595 const struct thandle *th)
597 struct osd_thandle *oh = container_of(th, typeof(*oh), ot_super);
599 return oh->ot_credits > osd_journal(dev)->j_max_transaction_buffers;
603 * Concurrency: shouldn't matter.
605 #ifdef HAVE_LDISKFS_JOURNAL_CALLBACK_ADD
606 static void osd_trans_commit_cb(struct super_block *sb,
607 struct journal_callback *jcb, int error)
609 static void osd_trans_commit_cb(struct journal_callback *jcb, int error)
612 struct osd_thandle *oh = container_of0(jcb, struct osd_thandle, ot_jcb);
613 struct thandle *th = &oh->ot_super;
614 struct lu_device *lud = &th->th_dev->dd_lu_dev;
615 struct dt_txn_commit_cb *dcb, *tmp;
617 LASSERT(oh->ot_handle == NULL);
620 CERROR("transaction @0x%p commit error: %d\n", th, error);
622 dt_txn_hook_commit(th);
624 /* call per-transaction callbacks if any */
625 cfs_list_for_each_entry_safe(dcb, tmp, &oh->ot_dcb_list, dcb_linkage) {
626 LASSERTF(dcb->dcb_magic == TRANS_COMMIT_CB_MAGIC,
627 "commit callback entry: magic=%x name='%s'\n",
628 dcb->dcb_magic, dcb->dcb_name);
629 cfs_list_del_init(&dcb->dcb_linkage);
630 dcb->dcb_func(NULL, th, dcb, error);
633 lu_ref_del_at(&lud->ld_reference, oh->ot_dev_link, "osd-tx", th);
637 lu_context_exit(&th->th_ctx);
638 lu_context_fini(&th->th_ctx);
642 static struct thandle *osd_trans_create(const struct lu_env *env,
645 struct osd_thread_info *oti = osd_oti_get(env);
646 struct osd_iobuf *iobuf = &oti->oti_iobuf;
647 struct osd_thandle *oh;
651 /* on pending IO in this thread should left from prev. request */
652 LASSERT(cfs_atomic_read(&iobuf->dr_numreqs) == 0);
654 th = ERR_PTR(-ENOMEM);
655 OBD_ALLOC_GFP(oh, sizeof *oh, CFS_ALLOC_IO);
657 oh->ot_quota_trans = &oti->oti_quota_trans;
658 memset(oh->ot_quota_trans, 0, sizeof(*oh->ot_quota_trans));
662 th->th_tags = LCT_TX_HANDLE;
664 oti->oti_dev = osd_dt_dev(d);
665 CFS_INIT_LIST_HEAD(&oh->ot_dcb_list);
672 * Concurrency: shouldn't matter.
674 int osd_trans_start(const struct lu_env *env, struct dt_device *d,
677 struct osd_thread_info *oti = osd_oti_get(env);
678 struct osd_device *dev = osd_dt_dev(d);
680 struct osd_thandle *oh;
685 LASSERT(current->journal_info == NULL);
687 oh = container_of0(th, struct osd_thandle, ot_super);
689 LASSERT(oh->ot_handle == NULL);
691 rc = dt_txn_hook_start(env, d, th);
695 if (unlikely(osd_param_is_not_sane(dev, th))) {
696 static unsigned long last_printed;
697 static int last_credits;
699 CWARN("%.16s: too many transaction credits (%d > %d)\n",
700 LDISKFS_SB(osd_sb(dev))->s_es->s_volume_name,
702 osd_journal(dev)->j_max_transaction_buffers);
703 #ifdef OSD_TRACK_DECLARES
704 CWARN(" create: %u/%u, delete: %u/%u, destroy: %u/%u\n",
705 oh->ot_declare_create, oh->ot_declare_create_cred,
706 oh->ot_declare_delete, oh->ot_declare_delete_cred,
707 oh->ot_declare_destroy, oh->ot_declare_destroy_cred);
708 CWARN(" attr_set: %u/%u, xattr_set: %u/%u\n",
709 oh->ot_declare_attr_set, oh->ot_declare_attr_set_cred,
710 oh->ot_declare_xattr_set, oh->ot_declare_xattr_set_cred);
711 CWARN(" write: %u/%u, punch: %u/%u, quota %u/%u\n",
712 oh->ot_declare_write, oh->ot_declare_write_cred,
713 oh->ot_declare_punch, oh->ot_declare_punch_cred,
714 oh->ot_declare_quota, oh->ot_declare_quota_cred);
715 CWARN(" insert: %u/%u, delete: %u/%u\n",
716 oh->ot_declare_insert, oh->ot_declare_insert_cred,
717 oh->ot_declare_delete, oh->ot_declare_destroy_cred);
718 CWARN(" ref_add: %u/%u, ref_del: %u/%u\n",
719 oh->ot_declare_ref_add, oh->ot_declare_ref_add_cred,
720 oh->ot_declare_ref_del, oh->ot_declare_ref_del_cred);
722 if (last_credits != oh->ot_credits &&
723 time_after(jiffies, last_printed + 60 * HZ)) {
724 libcfs_debug_dumpstack(NULL);
725 last_credits = oh->ot_credits;
726 last_printed = jiffies;
729 /* XXX Limit the credits to 'max_transaction_buffers', and
730 * let the underlying filesystem to catch the error if
731 * we really need so many credits.
733 * This should be removed when we can calculate the
734 * credits precisely. */
735 oh->ot_credits = osd_journal(dev)->j_max_transaction_buffers;
739 * XXX temporary stuff. Some abstraction layer should
742 jh = ldiskfs_journal_start_sb(osd_sb(dev), oh->ot_credits);
746 LASSERT(oti->oti_txns == 0);
747 lu_context_init(&th->th_ctx, th->th_tags);
748 lu_context_enter(&th->th_ctx);
750 lu_device_get(&d->dd_lu_dev);
751 oh->ot_dev_link = lu_ref_add(&d->dd_lu_dev.ld_reference,
763 * Concurrency: shouldn't matter.
765 static int osd_trans_stop(const struct lu_env *env, struct thandle *th)
768 struct osd_thandle *oh;
769 struct osd_thread_info *oti = osd_oti_get(env);
770 struct osd_iobuf *iobuf = &oti->oti_iobuf;
771 struct qsd_instance *qsd = oti->oti_dev->od_quota_slave;
774 oh = container_of0(th, struct osd_thandle, ot_super);
777 /* inform the quota slave device that the transaction is
779 qsd_op_end(env, qsd, oh->ot_quota_trans);
780 oh->ot_quota_trans = NULL;
782 if (oh->ot_handle != NULL) {
783 handle_t *hdl = oh->ot_handle;
786 * add commit callback
787 * notice we don't do this in osd_trans_start()
788 * as underlying transaction can change during truncate
790 osd_journal_callback_set(hdl, osd_trans_commit_cb,
793 LASSERT(oti->oti_txns == 1);
795 rc = dt_txn_hook_stop(env, th);
797 CERROR("Failure in transaction hook: %d\n", rc);
799 /* hook functions might modify th_sync */
800 hdl->h_sync = th->th_sync;
802 oh->ot_handle = NULL;
803 OSD_CHECK_SLOW_TH(oh, oti->oti_dev,
804 rc = ldiskfs_journal_stop(hdl));
806 CERROR("Failure to stop transaction: %d\n", rc);
811 /* as we want IO to journal and data IO be concurrent, we don't block
812 * awaiting data IO completion in osd_do_bio(), instead we wait here
813 * once transaction is submitted to the journal. all reqular requests
814 * don't do direct IO (except read/write), thus this wait_event becomes
817 * IMPORTANT: we have to wait till any IO submited by the thread is
818 * completed otherwise iobuf may be corrupted by different request
820 cfs_wait_event(iobuf->dr_wait,
821 cfs_atomic_read(&iobuf->dr_numreqs) == 0);
823 rc = iobuf->dr_error;
828 static int osd_trans_cb_add(struct thandle *th, struct dt_txn_commit_cb *dcb)
830 struct osd_thandle *oh = container_of0(th, struct osd_thandle,
833 LASSERT(dcb->dcb_magic == TRANS_COMMIT_CB_MAGIC);
834 LASSERT(&dcb->dcb_func != NULL);
835 cfs_list_add(&dcb->dcb_linkage, &oh->ot_dcb_list);
841 * Called just before object is freed. Releases all resources except for
842 * object itself (that is released by osd_object_free()).
844 * Concurrency: no concurrent access is possible that late in object
847 static void osd_object_delete(const struct lu_env *env, struct lu_object *l)
849 struct osd_object *obj = osd_obj(l);
850 struct inode *inode = obj->oo_inode;
852 LINVRNT(osd_invariant(obj));
855 * If object is unlinked remove fid->ino mapping from object index.
860 struct qsd_instance *qsd = osd_obj2dev(obj)->od_quota_slave;
861 qid_t uid = inode->i_uid;
862 qid_t gid = inode->i_gid;
865 obj->oo_inode = NULL;
868 struct osd_thread_info *info = osd_oti_get(env);
869 struct lquota_id_info *qi = &info->oti_qi;
871 /* Release granted quota to master if necessary */
872 qi->lqi_id.qid_uid = uid;
873 qsd_adjust_quota(env, qsd, &qi->lqi_id, USRQUOTA);
875 qi->lqi_id.qid_uid = gid;
876 qsd_adjust_quota(env, qsd, &qi->lqi_id, GRPQUOTA);
882 * Concurrency: ->loo_object_release() is called under site spin-lock.
884 static void osd_object_release(const struct lu_env *env,
890 * Concurrency: shouldn't matter.
892 static int osd_object_print(const struct lu_env *env, void *cookie,
893 lu_printer_t p, const struct lu_object *l)
895 struct osd_object *o = osd_obj(l);
898 if (o->oo_dir != NULL)
899 d = o->oo_dir->od_container.ic_descr;
902 return (*p)(env, cookie,
903 LUSTRE_OSD_LDISKFS_NAME"-object@%p(i:%p:%lu/%u)[%s]",
905 o->oo_inode ? o->oo_inode->i_ino : 0UL,
906 o->oo_inode ? o->oo_inode->i_generation : 0,
907 d ? d->id_ops->id_name : "plain");
911 * Concurrency: shouldn't matter.
913 int osd_statfs(const struct lu_env *env, struct dt_device *d,
914 struct obd_statfs *sfs)
916 struct osd_device *osd = osd_dt_dev(d);
917 struct super_block *sb = osd_sb(osd);
918 struct kstatfs *ksfs;
921 if (unlikely(osd->od_mnt == NULL))
924 /* osd_lproc.c call this without env, allocate ksfs for that case */
925 if (unlikely(env == NULL)) {
930 ksfs = &osd_oti_get(env)->oti_ksfs;
933 cfs_spin_lock(&osd->od_osfs_lock);
935 if (cfs_time_before_64(osd->od_osfs_age, cfs_time_shift_64(-1))) {
936 result = sb->s_op->statfs(sb->s_root, ksfs);
937 if (likely(result == 0)) { /* N.B. statfs can't really fail */
938 osd->od_osfs_age = cfs_time_current_64();
939 statfs_pack(&osd->od_statfs, ksfs);
940 if (sb->s_flags & MS_RDONLY)
941 sfs->os_state = OS_STATE_READONLY;
945 if (likely(result == 0))
946 *sfs = osd->od_statfs;
947 cfs_spin_unlock(&osd->od_osfs_lock);
949 if (unlikely(env == NULL))
956 * Estimate space needed for file creations. We assume the largest filename
957 * which is 2^64 - 1, hence a filename of 20 chars.
958 * This is 28 bytes per object which is 28MB for 1M objects ... no so bad.
960 #ifdef __LDISKFS_DIR_REC_LEN
961 #define PER_OBJ_USAGE __LDISKFS_DIR_REC_LEN(20)
963 #define PER_OBJ_USAGE LDISKFS_DIR_REC_LEN(20)
967 * Concurrency: doesn't access mutable data.
969 static void osd_conf_get(const struct lu_env *env,
970 const struct dt_device *dev,
971 struct dt_device_param *param)
973 struct super_block *sb = osd_sb(osd_dt_dev(dev));
976 * XXX should be taken from not-yet-existing fs abstraction layer.
978 param->ddp_mnt = osd_dt_dev(dev)->od_mnt;
979 param->ddp_max_name_len = LDISKFS_NAME_LEN;
980 param->ddp_max_nlink = LDISKFS_LINK_MAX;
981 param->ddp_block_shift = sb->s_blocksize_bits;
982 param->ddp_mount_type = LDD_MT_LDISKFS;
983 param->ddp_maxbytes = sb->s_maxbytes;
984 /* Overhead estimate should be fairly accurate, so we really take a tiny
985 * error margin which also avoids fragmenting the filesystem too much */
986 param->ddp_grant_reserved = 2; /* end up to be 1.9% after conversion */
987 /* inode are statically allocated, so per-inode space consumption
988 * is the space consumed by the directory entry */
989 param->ddp_inodespace = PER_OBJ_USAGE;
990 /* per-fragment overhead to be used by the client code */
991 param->ddp_grant_frag = 6 * LDISKFS_BLOCK_SIZE(sb);
992 param->ddp_mntopts = 0;
993 if (test_opt(sb, XATTR_USER))
994 param->ddp_mntopts |= MNTOPT_USERXATTR;
995 if (test_opt(sb, POSIX_ACL))
996 param->ddp_mntopts |= MNTOPT_ACL;
998 #if defined(LDISKFS_FEATURE_INCOMPAT_EA_INODE)
999 if (LDISKFS_HAS_INCOMPAT_FEATURE(sb, LDISKFS_FEATURE_INCOMPAT_EA_INODE))
1000 param->ddp_max_ea_size = LDISKFS_XATTR_MAX_LARGE_EA_SIZE;
1003 param->ddp_max_ea_size = sb->s_blocksize;
1008 * Helper function to get and fill the buffer with input values.
1010 static struct lu_buf *osd_buf_get(const struct lu_env *env, void *area, ssize_t len)
1014 buf = &osd_oti_get(env)->oti_buf;
1021 * Concurrency: shouldn't matter.
1023 static int osd_sync(const struct lu_env *env, struct dt_device *d)
1025 CDEBUG(D_HA, "syncing OSD %s\n", LUSTRE_OSD_LDISKFS_NAME);
1026 return ldiskfs_force_commit(osd_sb(osd_dt_dev(d)));
1030 * Start commit for OSD device.
1032 * An implementation of dt_commit_async method for OSD device.
1033 * Asychronously starts underlayng fs sync and thereby a transaction
1036 * \param env environment
1037 * \param d dt device
1039 * \see dt_device_operations
1041 static int osd_commit_async(const struct lu_env *env,
1042 struct dt_device *d)
1044 struct super_block *s = osd_sb(osd_dt_dev(d));
1047 CDEBUG(D_HA, "async commit OSD %s\n", LUSTRE_OSD_LDISKFS_NAME);
1048 RETURN(s->s_op->sync_fs(s, 0));
1052 * Concurrency: shouldn't matter.
1055 static int osd_ro(const struct lu_env *env, struct dt_device *d)
1057 struct super_block *sb = osd_sb(osd_dt_dev(d));
1061 CERROR("*** setting %s read-only ***\n", osd_dt_dev(d)->od_svname);
1063 rc = __lvfs_set_rdonly(sb->s_bdev, LDISKFS_SB(sb)->journal_bdev);
1068 * Concurrency: serialization provided by callers.
1070 static int osd_init_capa_ctxt(const struct lu_env *env, struct dt_device *d,
1071 int mode, unsigned long timeout, __u32 alg,
1072 struct lustre_capa_key *keys)
1074 struct osd_device *dev = osd_dt_dev(d);
1077 dev->od_fl_capa = mode;
1078 dev->od_capa_timeout = timeout;
1079 dev->od_capa_alg = alg;
1080 dev->od_capa_keys = keys;
1085 * Note: we do not count into QUOTA here.
1086 * If we mount with --data_journal we may need more.
1088 const int osd_dto_credits_noquota[DTO_NR] = {
1091 * INDEX_EXTRA_TRANS_BLOCKS(8) +
1092 * SINGLEDATA_TRANS_BLOCKS(8)
1093 * XXX Note: maybe iam need more, since iam have more level than
1096 [DTO_INDEX_INSERT] = 16,
1097 [DTO_INDEX_DELETE] = 16,
1101 [DTO_INDEX_UPDATE] = 16,
1103 * Create a object. The same as create object in EXT3.
1104 * DATA_TRANS_BLOCKS(14) +
1105 * INDEX_EXTRA_BLOCKS(8) +
1106 * 3(inode bits, groups, GDT)
1108 [DTO_OBJECT_CREATE] = 25,
1110 * XXX: real credits to be fixed
1112 [DTO_OBJECT_DELETE] = 25,
1114 * Attr set credits (inode)
1116 [DTO_ATTR_SET_BASE] = 1,
1118 * Xattr set. The same as xattr of EXT3.
1119 * DATA_TRANS_BLOCKS(14)
1120 * XXX Note: in original MDS implmentation INDEX_EXTRA_TRANS_BLOCKS
1121 * are also counted in. Do not know why?
1123 [DTO_XATTR_SET] = 14,
1126 * credits for inode change during write.
1128 [DTO_WRITE_BASE] = 3,
1130 * credits for single block write.
1132 [DTO_WRITE_BLOCK] = 14,
1134 * Attr set credits for chown.
1135 * This is extra credits for setattr, and it is null without quota
1137 [DTO_ATTR_SET_CHOWN]= 0
1140 static const struct dt_device_operations osd_dt_ops = {
1141 .dt_root_get = osd_root_get,
1142 .dt_statfs = osd_statfs,
1143 .dt_trans_create = osd_trans_create,
1144 .dt_trans_start = osd_trans_start,
1145 .dt_trans_stop = osd_trans_stop,
1146 .dt_trans_cb_add = osd_trans_cb_add,
1147 .dt_conf_get = osd_conf_get,
1148 .dt_sync = osd_sync,
1150 .dt_commit_async = osd_commit_async,
1151 .dt_init_capa_ctxt = osd_init_capa_ctxt,
1154 static void osd_object_read_lock(const struct lu_env *env,
1155 struct dt_object *dt, unsigned role)
1157 struct osd_object *obj = osd_dt_obj(dt);
1158 struct osd_thread_info *oti = osd_oti_get(env);
1160 LINVRNT(osd_invariant(obj));
1162 LASSERT(obj->oo_owner != env);
1163 cfs_down_read_nested(&obj->oo_sem, role);
1165 LASSERT(obj->oo_owner == NULL);
1169 static void osd_object_write_lock(const struct lu_env *env,
1170 struct dt_object *dt, unsigned role)
1172 struct osd_object *obj = osd_dt_obj(dt);
1173 struct osd_thread_info *oti = osd_oti_get(env);
1175 LINVRNT(osd_invariant(obj));
1177 LASSERT(obj->oo_owner != env);
1178 cfs_down_write_nested(&obj->oo_sem, role);
1180 LASSERT(obj->oo_owner == NULL);
1181 obj->oo_owner = env;
1185 static void osd_object_read_unlock(const struct lu_env *env,
1186 struct dt_object *dt)
1188 struct osd_object *obj = osd_dt_obj(dt);
1189 struct osd_thread_info *oti = osd_oti_get(env);
1191 LINVRNT(osd_invariant(obj));
1193 LASSERT(oti->oti_r_locks > 0);
1195 cfs_up_read(&obj->oo_sem);
1198 static void osd_object_write_unlock(const struct lu_env *env,
1199 struct dt_object *dt)
1201 struct osd_object *obj = osd_dt_obj(dt);
1202 struct osd_thread_info *oti = osd_oti_get(env);
1204 LINVRNT(osd_invariant(obj));
1206 LASSERT(obj->oo_owner == env);
1207 LASSERT(oti->oti_w_locks > 0);
1209 obj->oo_owner = NULL;
1210 cfs_up_write(&obj->oo_sem);
1213 static int osd_object_write_locked(const struct lu_env *env,
1214 struct dt_object *dt)
1216 struct osd_object *obj = osd_dt_obj(dt);
1218 LINVRNT(osd_invariant(obj));
1220 return obj->oo_owner == env;
1223 static int capa_is_sane(const struct lu_env *env,
1224 struct osd_device *dev,
1225 struct lustre_capa *capa,
1226 struct lustre_capa_key *keys)
1228 struct osd_thread_info *oti = osd_oti_get(env);
1229 struct lustre_capa *tcapa = &oti->oti_capa;
1230 struct obd_capa *oc;
1234 oc = capa_lookup(dev->od_capa_hash, capa, 0);
1236 if (capa_is_expired(oc)) {
1237 DEBUG_CAPA(D_ERROR, capa, "expired");
1244 if (capa_is_expired_sec(capa)) {
1245 DEBUG_CAPA(D_ERROR, capa, "expired");
1249 cfs_spin_lock(&capa_lock);
1250 for (i = 0; i < 2; i++) {
1251 if (keys[i].lk_keyid == capa->lc_keyid) {
1252 oti->oti_capa_key = keys[i];
1256 cfs_spin_unlock(&capa_lock);
1259 DEBUG_CAPA(D_ERROR, capa, "no matched capa key");
1263 rc = capa_hmac(tcapa->lc_hmac, capa, oti->oti_capa_key.lk_key);
1267 if (memcmp(tcapa->lc_hmac, capa->lc_hmac, sizeof(capa->lc_hmac))) {
1268 DEBUG_CAPA(D_ERROR, capa, "HMAC mismatch");
1272 oc = capa_add(dev->od_capa_hash, capa);
1278 int osd_object_auth(const struct lu_env *env, struct dt_object *dt,
1279 struct lustre_capa *capa, __u64 opc)
1281 const struct lu_fid *fid = lu_object_fid(&dt->do_lu);
1282 struct osd_device *dev = osd_dev(dt->do_lu.lo_dev);
1283 struct md_capainfo *ci;
1286 if (!dev->od_fl_capa)
1289 if (capa == BYPASS_CAPA)
1292 ci = md_capainfo(env);
1296 if (ci->mc_auth == LC_ID_NONE)
1300 CERROR("no capability is provided for fid "DFID"\n", PFID(fid));
1304 if (!lu_fid_eq(fid, &capa->lc_fid)) {
1305 DEBUG_CAPA(D_ERROR, capa, "fid "DFID" mismatch with",
1310 if (!capa_opc_supported(capa, opc)) {
1311 DEBUG_CAPA(D_ERROR, capa, "opc "LPX64" not supported by", opc);
1315 if ((rc = capa_is_sane(env, dev, capa, dev->od_capa_keys))) {
1316 DEBUG_CAPA(D_ERROR, capa, "insane (rc %d)", rc);
1323 static struct timespec *osd_inode_time(const struct lu_env *env,
1324 struct inode *inode, __u64 seconds)
1326 struct osd_thread_info *oti = osd_oti_get(env);
1327 struct timespec *t = &oti->oti_time;
1329 t->tv_sec = seconds;
1331 *t = timespec_trunc(*t, inode->i_sb->s_time_gran);
1336 static void osd_inode_getattr(const struct lu_env *env,
1337 struct inode *inode, struct lu_attr *attr)
1339 attr->la_valid |= LA_ATIME | LA_MTIME | LA_CTIME | LA_MODE |
1340 LA_SIZE | LA_BLOCKS | LA_UID | LA_GID |
1341 LA_FLAGS | LA_NLINK | LA_RDEV | LA_BLKSIZE;
1343 attr->la_atime = LTIME_S(inode->i_atime);
1344 attr->la_mtime = LTIME_S(inode->i_mtime);
1345 attr->la_ctime = LTIME_S(inode->i_ctime);
1346 attr->la_mode = inode->i_mode;
1347 attr->la_size = i_size_read(inode);
1348 attr->la_blocks = inode->i_blocks;
1349 attr->la_uid = inode->i_uid;
1350 attr->la_gid = inode->i_gid;
1351 attr->la_flags = LDISKFS_I(inode)->i_flags;
1352 attr->la_nlink = inode->i_nlink;
1353 attr->la_rdev = inode->i_rdev;
1354 attr->la_blksize = 1 << inode->i_blkbits;
1355 attr->la_blkbits = inode->i_blkbits;
1358 static int osd_attr_get(const struct lu_env *env,
1359 struct dt_object *dt,
1360 struct lu_attr *attr,
1361 struct lustre_capa *capa)
1363 struct osd_object *obj = osd_dt_obj(dt);
1365 LASSERT(dt_object_exists(dt));
1366 LINVRNT(osd_invariant(obj));
1368 if (osd_object_auth(env, dt, capa, CAPA_OPC_META_READ))
1371 cfs_spin_lock(&obj->oo_guard);
1372 osd_inode_getattr(env, obj->oo_inode, attr);
1373 cfs_spin_unlock(&obj->oo_guard);
1377 static int osd_declare_attr_set(const struct lu_env *env,
1378 struct dt_object *dt,
1379 const struct lu_attr *attr,
1380 struct thandle *handle)
1382 struct osd_thandle *oh;
1383 struct osd_object *obj;
1384 struct osd_thread_info *info = osd_oti_get(env);
1385 struct lquota_id_info *qi = &info->oti_qi;
1391 LASSERT(dt != NULL);
1392 LASSERT(handle != NULL);
1394 obj = osd_dt_obj(dt);
1395 LASSERT(osd_invariant(obj));
1397 oh = container_of0(handle, struct osd_thandle, ot_super);
1398 LASSERT(oh->ot_handle == NULL);
1400 OSD_DECLARE_OP(oh, attr_set,
1401 osd_dto_credits_noquota[DTO_ATTR_SET_BASE]);
1403 if (attr == NULL || obj->oo_inode == NULL)
1406 bspace = obj->oo_inode->i_blocks;
1407 bspace <<= obj->oo_inode->i_sb->s_blocksize_bits;
1408 bspace = toqb(bspace);
1410 /* Changing ownership is always preformed by super user, it should not
1413 * We still need to call the osd_declare_qid() to calculate the journal
1414 * credits for updating quota accounting files and to trigger quota
1415 * space adjustment once the operation is completed.*/
1416 if ((attr->la_valid & LA_UID) != 0 &&
1417 attr->la_uid != obj->oo_inode->i_uid) {
1418 qi->lqi_type = USRQUOTA;
1420 /* inode accounting */
1421 qi->lqi_is_blk = false;
1423 /* one more inode for the new owner ... */
1424 qi->lqi_id.qid_uid = attr->la_uid;
1426 allocated = (attr->la_uid == 0) ? true : false;
1427 rc = osd_declare_qid(env, oh, qi, allocated, NULL);
1428 if (rc == -EDQUOT || rc == -EINPROGRESS)
1433 /* and one less inode for the current uid */
1434 qi->lqi_id.qid_uid = obj->oo_inode->i_uid;
1436 rc = osd_declare_qid(env, oh, qi, true, NULL);
1437 if (rc == -EDQUOT || rc == -EINPROGRESS)
1442 /* block accounting */
1443 qi->lqi_is_blk = true;
1445 /* more blocks for the new owner ... */
1446 qi->lqi_id.qid_uid = attr->la_uid;
1447 qi->lqi_space = bspace;
1448 allocated = (attr->la_uid == 0) ? true : false;
1449 rc = osd_declare_qid(env, oh, qi, allocated, NULL);
1450 if (rc == -EDQUOT || rc == -EINPROGRESS)
1455 /* and finally less blocks for the current owner */
1456 qi->lqi_id.qid_uid = obj->oo_inode->i_uid;
1457 qi->lqi_space = -bspace;
1458 rc = osd_declare_qid(env, oh, qi, true, NULL);
1459 if (rc == -EDQUOT || rc == -EINPROGRESS)
1465 if (attr->la_valid & LA_GID &&
1466 attr->la_gid != obj->oo_inode->i_gid) {
1467 qi->lqi_type = GRPQUOTA;
1469 /* inode accounting */
1470 qi->lqi_is_blk = false;
1472 /* one more inode for the new group owner ... */
1473 qi->lqi_id.qid_gid = attr->la_gid;
1475 allocated = (attr->la_gid == 0) ? true : false;
1476 rc = osd_declare_qid(env, oh, qi, allocated, NULL);
1477 if (rc == -EDQUOT || rc == -EINPROGRESS)
1482 /* and one less inode for the current gid */
1483 qi->lqi_id.qid_gid = obj->oo_inode->i_gid;
1485 rc = osd_declare_qid(env, oh, qi, true, NULL);
1486 if (rc == -EDQUOT || rc == -EINPROGRESS)
1491 /* block accounting */
1492 qi->lqi_is_blk = true;
1494 /* more blocks for the new owner ... */
1495 qi->lqi_id.qid_gid = attr->la_gid;
1496 qi->lqi_space = bspace;
1497 allocated = (attr->la_gid == 0) ? true : false;
1498 rc = osd_declare_qid(env, oh, qi, allocated, NULL);
1499 if (rc == -EDQUOT || rc == -EINPROGRESS)
1504 /* and finally less blocks for the current owner */
1505 qi->lqi_id.qid_gid = obj->oo_inode->i_gid;
1506 qi->lqi_space = -bspace;
1507 rc = osd_declare_qid(env, oh, qi, true, NULL);
1508 if (rc == -EDQUOT || rc == -EINPROGRESS)
1517 static int osd_inode_setattr(const struct lu_env *env,
1518 struct inode *inode, const struct lu_attr *attr)
1522 bits = attr->la_valid;
1524 LASSERT(!(bits & LA_TYPE)); /* Huh? You want too much. */
1526 if (bits & LA_ATIME)
1527 inode->i_atime = *osd_inode_time(env, inode, attr->la_atime);
1528 if (bits & LA_CTIME)
1529 inode->i_ctime = *osd_inode_time(env, inode, attr->la_ctime);
1530 if (bits & LA_MTIME)
1531 inode->i_mtime = *osd_inode_time(env, inode, attr->la_mtime);
1532 if (bits & LA_SIZE) {
1533 LDISKFS_I(inode)->i_disksize = attr->la_size;
1534 i_size_write(inode, attr->la_size);
1538 /* OSD should not change "i_blocks" which is used by quota.
1539 * "i_blocks" should be changed by ldiskfs only. */
1540 if (bits & LA_BLOCKS)
1541 inode->i_blocks = attr->la_blocks;
1544 inode->i_mode = (inode->i_mode & S_IFMT) |
1545 (attr->la_mode & ~S_IFMT);
1547 inode->i_uid = attr->la_uid;
1549 inode->i_gid = attr->la_gid;
1550 if (bits & LA_NLINK)
1551 inode->i_nlink = attr->la_nlink;
1553 inode->i_rdev = attr->la_rdev;
1555 if (bits & LA_FLAGS) {
1556 /* always keep S_NOCMTIME */
1557 inode->i_flags = ll_ext_to_inode_flags(attr->la_flags) |
1563 static int osd_quota_transfer(struct inode *inode, const struct lu_attr *attr)
1565 if ((attr->la_valid & LA_UID && attr->la_uid != inode->i_uid) ||
1566 (attr->la_valid & LA_GID && attr->la_gid != inode->i_gid)) {
1571 if (attr->la_valid & LA_UID)
1572 iattr.ia_valid |= ATTR_UID;
1573 if (attr->la_valid & LA_GID)
1574 iattr.ia_valid |= ATTR_GID;
1575 iattr.ia_uid = attr->la_uid;
1576 iattr.ia_gid = attr->la_gid;
1578 rc = ll_vfs_dq_transfer(inode, &iattr);
1580 CERROR("%s: quota transfer failed: rc = %d. Is quota "
1581 "enforcement enabled on the ldiskfs filesystem?",
1582 inode->i_sb->s_id, rc);
1589 static int osd_attr_set(const struct lu_env *env,
1590 struct dt_object *dt,
1591 const struct lu_attr *attr,
1592 struct thandle *handle,
1593 struct lustre_capa *capa)
1595 struct osd_object *obj = osd_dt_obj(dt);
1596 struct inode *inode;
1599 LASSERT(handle != NULL);
1600 LASSERT(dt_object_exists(dt));
1601 LASSERT(osd_invariant(obj));
1603 if (osd_object_auth(env, dt, capa, CAPA_OPC_META_WRITE))
1606 OSD_EXEC_OP(handle, attr_set);
1608 inode = obj->oo_inode;
1609 ll_vfs_dq_init(inode);
1611 rc = osd_quota_transfer(inode, attr);
1615 cfs_spin_lock(&obj->oo_guard);
1616 rc = osd_inode_setattr(env, inode, attr);
1617 cfs_spin_unlock(&obj->oo_guard);
1620 inode->i_sb->s_op->dirty_inode(inode);
1624 struct dentry *osd_child_dentry_get(const struct lu_env *env,
1625 struct osd_object *obj,
1626 const char *name, const int namelen)
1628 return osd_child_dentry_by_inode(env, obj->oo_inode, name, namelen);
1631 static int osd_mkfile(struct osd_thread_info *info, struct osd_object *obj,
1633 struct dt_allocation_hint *hint,
1637 struct osd_device *osd = osd_obj2dev(obj);
1638 struct osd_thandle *oth;
1639 struct dt_object *parent = NULL;
1640 struct inode *inode;
1642 LINVRNT(osd_invariant(obj));
1643 LASSERT(obj->oo_inode == NULL);
1644 LASSERT(obj->oo_hl_head == NULL);
1646 if (S_ISDIR(mode) && ldiskfs_pdo) {
1647 obj->oo_hl_head =ldiskfs_htree_lock_head_alloc(HTREE_HBITS_DEF);
1648 if (obj->oo_hl_head == NULL)
1652 oth = container_of(th, struct osd_thandle, ot_super);
1653 LASSERT(oth->ot_handle->h_transaction != NULL);
1655 if (hint && hint->dah_parent)
1656 parent = hint->dah_parent;
1658 inode = ldiskfs_create_inode(oth->ot_handle,
1659 parent ? osd_dt_obj(parent)->oo_inode :
1660 osd_sb(osd)->s_root->d_inode,
1662 if (!IS_ERR(inode)) {
1663 /* Do not update file c/mtime in ldiskfs.
1664 * NB: don't need any lock because no contention at this
1666 inode->i_flags |= S_NOCMTIME;
1667 inode->i_state |= I_LUSTRE_NOSCRUB;
1668 obj->oo_inode = inode;
1671 if (obj->oo_hl_head != NULL) {
1672 ldiskfs_htree_lock_head_free(obj->oo_hl_head);
1673 obj->oo_hl_head = NULL;
1675 result = PTR_ERR(inode);
1677 LINVRNT(osd_invariant(obj));
1685 static int osd_mkdir(struct osd_thread_info *info, struct osd_object *obj,
1686 struct lu_attr *attr,
1687 struct dt_allocation_hint *hint,
1688 struct dt_object_format *dof,
1692 struct osd_thandle *oth;
1693 struct osd_device *osd = osd_obj2dev(obj);
1694 __u32 mode = (attr->la_mode & (S_IFMT | S_IRWXUGO | S_ISVTX));
1696 LASSERT(S_ISDIR(attr->la_mode));
1698 oth = container_of(th, struct osd_thandle, ot_super);
1699 LASSERT(oth->ot_handle->h_transaction != NULL);
1700 result = osd_mkfile(info, obj, mode, hint, th);
1701 if (result == 0 && osd->od_iop_mode == 0) {
1702 LASSERT(obj->oo_inode != NULL);
1704 * XXX uh-oh... call low-level iam function directly.
1707 result = iam_lvar_create(obj->oo_inode, OSD_NAME_LEN, 4,
1708 sizeof (struct osd_fid_pack),
1714 static int osd_mk_index(struct osd_thread_info *info, struct osd_object *obj,
1715 struct lu_attr *attr,
1716 struct dt_allocation_hint *hint,
1717 struct dt_object_format *dof,
1721 struct osd_thandle *oth;
1722 const struct dt_index_features *feat = dof->u.dof_idx.di_feat;
1724 __u32 mode = (attr->la_mode & (S_IFMT | S_IALLUGO | S_ISVTX));
1726 LASSERT(S_ISREG(attr->la_mode));
1728 oth = container_of(th, struct osd_thandle, ot_super);
1729 LASSERT(oth->ot_handle->h_transaction != NULL);
1731 result = osd_mkfile(info, obj, mode, hint, th);
1733 LASSERT(obj->oo_inode != NULL);
1734 if (feat->dif_flags & DT_IND_VARKEY)
1735 result = iam_lvar_create(obj->oo_inode,
1736 feat->dif_keysize_max,
1738 feat->dif_recsize_max,
1741 result = iam_lfix_create(obj->oo_inode,
1742 feat->dif_keysize_max,
1744 feat->dif_recsize_max,
1751 static int osd_mkreg(struct osd_thread_info *info, struct osd_object *obj,
1752 struct lu_attr *attr,
1753 struct dt_allocation_hint *hint,
1754 struct dt_object_format *dof,
1757 LASSERT(S_ISREG(attr->la_mode));
1758 return osd_mkfile(info, obj, (attr->la_mode &
1759 (S_IFMT | S_IALLUGO | S_ISVTX)), hint, th);
1762 static int osd_mksym(struct osd_thread_info *info, struct osd_object *obj,
1763 struct lu_attr *attr,
1764 struct dt_allocation_hint *hint,
1765 struct dt_object_format *dof,
1768 LASSERT(S_ISLNK(attr->la_mode));
1769 return osd_mkfile(info, obj, (attr->la_mode &
1770 (S_IFMT | S_IALLUGO | S_ISVTX)), hint, th);
1773 static int osd_mknod(struct osd_thread_info *info, struct osd_object *obj,
1774 struct lu_attr *attr,
1775 struct dt_allocation_hint *hint,
1776 struct dt_object_format *dof,
1779 cfs_umode_t mode = attr->la_mode & (S_IFMT | S_IALLUGO | S_ISVTX);
1782 LINVRNT(osd_invariant(obj));
1783 LASSERT(obj->oo_inode == NULL);
1784 LASSERT(S_ISCHR(mode) || S_ISBLK(mode) ||
1785 S_ISFIFO(mode) || S_ISSOCK(mode));
1787 result = osd_mkfile(info, obj, mode, hint, th);
1789 LASSERT(obj->oo_inode != NULL);
1791 * This inode should be marked dirty for i_rdev. Currently
1792 * that is done in the osd_attr_init().
1794 init_special_inode(obj->oo_inode, mode, attr->la_rdev);
1796 LINVRNT(osd_invariant(obj));
1800 typedef int (*osd_obj_type_f)(struct osd_thread_info *, struct osd_object *,
1802 struct dt_allocation_hint *hint,
1803 struct dt_object_format *dof,
1806 static osd_obj_type_f osd_create_type_f(enum dt_format_type type)
1808 osd_obj_type_f result;
1824 result = osd_mk_index;
1835 static void osd_ah_init(const struct lu_env *env, struct dt_allocation_hint *ah,
1836 struct dt_object *parent, struct dt_object *child,
1837 cfs_umode_t child_mode)
1841 memset(ah, 0, sizeof(*ah));
1842 ah->dah_parent = parent;
1843 ah->dah_mode = child_mode;
1846 static void osd_attr_init(struct osd_thread_info *info, struct osd_object *obj,
1847 struct lu_attr *attr, struct dt_object_format *dof)
1849 struct inode *inode = obj->oo_inode;
1850 __u64 valid = attr->la_valid;
1853 attr->la_valid &= ~(LA_TYPE | LA_MODE);
1855 if (dof->dof_type != DFT_NODE)
1856 attr->la_valid &= ~LA_RDEV;
1857 if ((valid & LA_ATIME) && (attr->la_atime == LTIME_S(inode->i_atime)))
1858 attr->la_valid &= ~LA_ATIME;
1859 if ((valid & LA_CTIME) && (attr->la_ctime == LTIME_S(inode->i_ctime)))
1860 attr->la_valid &= ~LA_CTIME;
1861 if ((valid & LA_MTIME) && (attr->la_mtime == LTIME_S(inode->i_mtime)))
1862 attr->la_valid &= ~LA_MTIME;
1864 result = osd_quota_transfer(inode, attr);
1868 if (attr->la_valid != 0) {
1869 result = osd_inode_setattr(info->oti_env, inode, attr);
1871 * The osd_inode_setattr() should always succeed here. The
1872 * only error that could be returned is EDQUOT when we are
1873 * trying to change the UID or GID of the inode. However, this
1874 * should not happen since quota enforcement is no longer
1875 * enabled on ldiskfs (lquota takes care of it).
1877 LASSERTF(result == 0, "%d", result);
1878 inode->i_sb->s_op->dirty_inode(inode);
1881 attr->la_valid = valid;
1885 * Helper function for osd_object_create()
1887 * \retval 0, on success
1889 static int __osd_object_create(struct osd_thread_info *info,
1890 struct osd_object *obj, struct lu_attr *attr,
1891 struct dt_allocation_hint *hint,
1892 struct dt_object_format *dof,
1898 /* we drop umask so that permissions we pass are not affected */
1899 umask = current->fs->umask;
1900 current->fs->umask = 0;
1902 result = osd_create_type_f(dof->dof_type)(info, obj, attr, hint, dof,
1905 osd_attr_init(info, obj, attr, dof);
1906 osd_object_init0(obj);
1908 if (obj->oo_inode && (obj->oo_inode->i_state & I_NEW))
1909 unlock_new_inode(obj->oo_inode);
1912 /* restore previous umask value */
1913 current->fs->umask = umask;
1919 * Helper function for osd_object_create()
1921 * \retval 0, on success
1923 static int __osd_oi_insert(const struct lu_env *env, struct osd_object *obj,
1924 const struct lu_fid *fid, struct thandle *th)
1926 struct osd_thread_info *info = osd_oti_get(env);
1927 struct osd_inode_id *id = &info->oti_id;
1928 struct osd_device *osd = osd_obj2dev(obj);
1930 LASSERT(obj->oo_inode != NULL);
1932 osd_id_gen(id, obj->oo_inode->i_ino, obj->oo_inode->i_generation);
1933 return osd_oi_insert(info, osd, fid, id, th);
1936 static int osd_declare_object_create(const struct lu_env *env,
1937 struct dt_object *dt,
1938 struct lu_attr *attr,
1939 struct dt_allocation_hint *hint,
1940 struct dt_object_format *dof,
1941 struct thandle *handle)
1943 struct osd_thandle *oh;
1947 LASSERT(handle != NULL);
1949 oh = container_of0(handle, struct osd_thandle, ot_super);
1950 LASSERT(oh->ot_handle == NULL);
1952 OSD_DECLARE_OP(oh, create, osd_dto_credits_noquota[DTO_OBJECT_CREATE]);
1953 /* XXX: So far, only normal fid needs be inserted into the oi,
1954 * things could be changed later. Revise following code then. */
1955 if (fid_is_norm(lu_object_fid(&dt->do_lu))) {
1956 /* Reuse idle OI block may cause additional one OI block
1958 OSD_DECLARE_OP(oh, insert,
1959 osd_dto_credits_noquota[DTO_INDEX_INSERT] + 1);
1961 /* If this is directory, then we expect . and .. to be inserted as
1962 * well. The one directory block always needs to be created for the
1963 * directory, so we could use DTO_WRITE_BASE here (GDT, block bitmap,
1964 * block), there is no danger of needing a tree for the first block.
1966 if (attr && S_ISDIR(attr->la_mode)) {
1967 OSD_DECLARE_OP(oh, insert,
1968 osd_dto_credits_noquota[DTO_WRITE_BASE]);
1969 OSD_DECLARE_OP(oh, insert, 0);
1975 rc = osd_declare_inode_qid(env, attr->la_uid, attr->la_gid, 1, oh,
1976 false, false, NULL, false);
1980 static int osd_object_create(const struct lu_env *env, struct dt_object *dt,
1981 struct lu_attr *attr,
1982 struct dt_allocation_hint *hint,
1983 struct dt_object_format *dof,
1986 const struct lu_fid *fid = lu_object_fid(&dt->do_lu);
1987 struct osd_object *obj = osd_dt_obj(dt);
1988 struct osd_thread_info *info = osd_oti_get(env);
1993 LINVRNT(osd_invariant(obj));
1994 LASSERT(!dt_object_exists(dt));
1995 LASSERT(osd_write_locked(env, obj));
1996 LASSERT(th != NULL);
1998 if (unlikely(fid_is_acct(fid)))
1999 /* Quota files can't be created from the kernel any more,
2000 * 'tune2fs -O quota' will take care of creating them */
2003 OSD_EXEC_OP(th, create);
2005 result = __osd_object_create(info, obj, attr, hint, dof, th);
2007 result = __osd_oi_insert(env, obj, fid, th);
2009 LASSERT(ergo(result == 0, dt_object_exists(dt)));
2010 LASSERT(osd_invariant(obj));
2015 * Called to destroy on-disk representation of the object
2017 * Concurrency: must be locked
2019 static int osd_declare_object_destroy(const struct lu_env *env,
2020 struct dt_object *dt,
2023 struct osd_object *obj = osd_dt_obj(dt);
2024 struct inode *inode = obj->oo_inode;
2025 struct osd_thandle *oh;
2029 oh = container_of0(th, struct osd_thandle, ot_super);
2030 LASSERT(oh->ot_handle == NULL);
2033 OSD_DECLARE_OP(oh, delete, osd_dto_credits_noquota[DTO_OBJECT_DELETE]);
2034 /* XXX: So far, only normal fid needs to be inserted into the OI,
2035 * so only normal fid needs to be removed from the OI also.
2036 * Recycle idle OI leaf may cause additional three OI blocks
2038 OSD_DECLARE_OP(oh, destroy, fid_is_norm(lu_object_fid(&dt->do_lu)) ?
2039 osd_dto_credits_noquota[DTO_INDEX_DELETE] + 3 : 0);
2041 /* one less inode */
2042 rc = osd_declare_inode_qid(env, inode->i_uid, inode->i_gid, -1, oh,
2043 false, true, NULL, false);
2046 /* data to be truncated */
2047 rc = osd_declare_inode_qid(env, inode->i_uid, inode->i_gid, 0, oh,
2048 true, true, NULL, false);
2052 static int osd_object_destroy(const struct lu_env *env,
2053 struct dt_object *dt,
2056 const struct lu_fid *fid = lu_object_fid(&dt->do_lu);
2057 struct osd_object *obj = osd_dt_obj(dt);
2058 struct inode *inode = obj->oo_inode;
2059 struct osd_device *osd = osd_obj2dev(obj);
2060 struct osd_thandle *oh;
2064 oh = container_of0(th, struct osd_thandle, ot_super);
2065 LASSERT(oh->ot_handle);
2067 LASSERT(!lu_object_is_dying(dt->do_lu.lo_header));
2069 if (unlikely(fid_is_acct(fid)))
2072 /* Parallel control for OI scrub. For most of cases, there is no
2073 * lock contention. So it will not affect unlink performance. */
2074 cfs_mutex_lock(&inode->i_mutex);
2075 if (S_ISDIR(inode->i_mode)) {
2076 LASSERT(osd_inode_unlinked(inode) ||
2077 inode->i_nlink == 1);
2078 cfs_spin_lock(&obj->oo_guard);
2080 cfs_spin_unlock(&obj->oo_guard);
2081 inode->i_sb->s_op->dirty_inode(inode);
2083 LASSERT(osd_inode_unlinked(inode));
2086 OSD_EXEC_OP(th, destroy);
2088 result = osd_oi_delete(osd_oti_get(env), osd, fid, th);
2089 cfs_mutex_unlock(&inode->i_mutex);
2091 /* XXX: add to ext3 orphan list */
2092 /* rc = ext3_orphan_add(handle_t *handle, struct inode *inode) */
2094 /* not needed in the cache anymore */
2095 set_bit(LU_OBJECT_HEARD_BANSHEE, &dt->do_lu.lo_header->loh_flags);
2101 * Helper function for osd_xattr_set()
2103 static int __osd_xattr_set(const struct lu_env *env, struct dt_object *dt,
2104 const struct lu_buf *buf, const char *name, int fl)
2106 struct osd_object *obj = osd_dt_obj(dt);
2107 struct inode *inode = obj->oo_inode;
2108 struct osd_thread_info *info = osd_oti_get(env);
2109 struct dentry *dentry = &info->oti_child_dentry;
2113 LASSERT(dt_object_exists(dt));
2114 LASSERT(inode->i_op != NULL && inode->i_op->setxattr != NULL);
2116 if (fl & LU_XATTR_REPLACE)
2117 fs_flags |= XATTR_REPLACE;
2119 if (fl & LU_XATTR_CREATE)
2120 fs_flags |= XATTR_CREATE;
2122 ll_vfs_dq_init(inode);
2123 dentry->d_inode = inode;
2124 rc = inode->i_op->setxattr(dentry, name, buf->lb_buf,
2125 buf->lb_len, fs_flags);
2130 * Put the fid into lustre_mdt_attrs, and then place the structure
2131 * inode's ea. This fid should not be altered during the life time
2134 * \retval +ve, on success
2135 * \retval -ve, on error
2137 * FIXME: It is good to have/use ldiskfs_xattr_set_handle() here
2139 static int osd_ea_fid_set(const struct lu_env *env, struct dt_object *dt,
2140 const struct lu_fid *fid)
2142 struct osd_thread_info *info = osd_oti_get(env);
2143 struct lustre_mdt_attrs *mdt_attrs = &info->oti_mdt_attrs;
2145 lustre_lma_init(mdt_attrs, fid);
2146 lustre_lma_swab(mdt_attrs);
2147 return __osd_xattr_set(env, dt,
2148 osd_buf_get(env, mdt_attrs, sizeof *mdt_attrs),
2149 XATTR_NAME_LMA, LU_XATTR_CREATE);
2154 * ldiskfs supports fid in dirent, it is passed in dentry->d_fsdata.
2155 * lustre 1.8 also uses d_fsdata for passing other info to ldiskfs.
2156 * To have compatilibility with 1.8 ldiskfs driver we need to have
2157 * magic number at start of fid data.
2158 * \ldiskfs_dentry_param is used only to pass fid from osd to ldiskfs.
2161 void osd_get_ldiskfs_dirent_param(struct ldiskfs_dentry_param *param,
2162 const struct dt_rec *fid)
2164 param->edp_magic = LDISKFS_LUFID_MAGIC;
2165 param->edp_len = sizeof(struct lu_fid) + 1;
2167 fid_cpu_to_be((struct lu_fid *)param->edp_data,
2168 (struct lu_fid *)fid);
2172 * Try to read the fid from inode ea into dt_rec, if return value
2173 * i.e. rc is +ve, then we got fid, otherwise we will have to form igif
2175 * \param fid object fid.
2177 * \retval 0 on success
2179 static int osd_ea_fid_get(const struct lu_env *env, struct osd_object *obj,
2180 __u32 ino, struct lu_fid *fid,
2181 struct osd_inode_id *id)
2183 struct osd_thread_info *info = osd_oti_get(env);
2184 struct inode *inode;
2187 osd_id_gen(id, ino, OSD_OII_NOGEN);
2188 inode = osd_iget_fid(info, osd_obj2dev(obj), id, fid);
2190 RETURN(PTR_ERR(inode));
2197 * OSD layer object create function for interoperability mode (b11826).
2198 * This is mostly similar to osd_object_create(). Only difference being, fid is
2199 * inserted into inode ea here.
2201 * \retval 0, on success
2202 * \retval -ve, on error
2204 static int osd_object_ea_create(const struct lu_env *env, struct dt_object *dt,
2205 struct lu_attr *attr,
2206 struct dt_allocation_hint *hint,
2207 struct dt_object_format *dof,
2210 const struct lu_fid *fid = lu_object_fid(&dt->do_lu);
2211 struct osd_object *obj = osd_dt_obj(dt);
2212 struct osd_thread_info *info = osd_oti_get(env);
2217 LASSERT(osd_invariant(obj));
2218 LASSERT(!dt_object_exists(dt));
2219 LASSERT(osd_write_locked(env, obj));
2220 LASSERT(th != NULL);
2222 if (unlikely(fid_is_acct(fid)))
2223 /* Quota files can't be created from the kernel any more,
2224 * 'tune2fs -O quota' will take care of creating them */
2227 OSD_EXEC_OP(th, create);
2229 result = __osd_object_create(info, obj, attr, hint, dof, th);
2230 /* objects under osd root shld have igif fid, so dont add fid EA */
2231 if (result == 0 && fid_seq(fid) >= FID_SEQ_NORMAL)
2232 result = osd_ea_fid_set(env, dt, fid);
2235 result = __osd_oi_insert(env, obj, fid, th);
2237 LASSERT(ergo(result == 0, dt_object_exists(dt)));
2238 LINVRNT(osd_invariant(obj));
2242 static int osd_declare_object_ref_add(const struct lu_env *env,
2243 struct dt_object *dt,
2244 struct thandle *handle)
2246 struct osd_thandle *oh;
2248 /* it's possible that object doesn't exist yet */
2249 LASSERT(handle != NULL);
2251 oh = container_of0(handle, struct osd_thandle, ot_super);
2252 LASSERT(oh->ot_handle == NULL);
2254 OSD_DECLARE_OP(oh, ref_add, osd_dto_credits_noquota[DTO_ATTR_SET_BASE]);
2260 * Concurrency: @dt is write locked.
2262 static int osd_object_ref_add(const struct lu_env *env,
2263 struct dt_object *dt, struct thandle *th)
2265 struct osd_object *obj = osd_dt_obj(dt);
2266 struct inode *inode = obj->oo_inode;
2268 LINVRNT(osd_invariant(obj));
2269 LASSERT(dt_object_exists(dt));
2270 LASSERT(osd_write_locked(env, obj));
2271 LASSERT(th != NULL);
2273 OSD_EXEC_OP(th, ref_add);
2276 * DIR_NLINK feature is set for compatibility reasons if:
2277 * 1) nlinks > LDISKFS_LINK_MAX, or
2278 * 2) nlinks == 2, since this indicates i_nlink was previously 1.
2280 * It is easier to always set this flag (rather than check and set),
2281 * since it has less overhead, and the superblock will be dirtied
2282 * at some point. Both e2fsprogs and any Lustre-supported ldiskfs
2283 * do not actually care whether this flag is set or not.
2285 cfs_spin_lock(&obj->oo_guard);
2287 if (S_ISDIR(inode->i_mode) && inode->i_nlink > 1) {
2288 if (inode->i_nlink >= LDISKFS_LINK_MAX ||
2289 inode->i_nlink == 2)
2292 LASSERT(inode->i_nlink <= LDISKFS_LINK_MAX);
2293 cfs_spin_unlock(&obj->oo_guard);
2294 inode->i_sb->s_op->dirty_inode(inode);
2295 LINVRNT(osd_invariant(obj));
2300 static int osd_declare_object_ref_del(const struct lu_env *env,
2301 struct dt_object *dt,
2302 struct thandle *handle)
2304 struct osd_thandle *oh;
2306 LASSERT(dt_object_exists(dt));
2307 LASSERT(handle != NULL);
2309 oh = container_of0(handle, struct osd_thandle, ot_super);
2310 LASSERT(oh->ot_handle == NULL);
2312 OSD_DECLARE_OP(oh, ref_del, osd_dto_credits_noquota[DTO_ATTR_SET_BASE]);
2318 * Concurrency: @dt is write locked.
2320 static int osd_object_ref_del(const struct lu_env *env, struct dt_object *dt,
2323 struct osd_object *obj = osd_dt_obj(dt);
2324 struct inode *inode = obj->oo_inode;
2326 LINVRNT(osd_invariant(obj));
2327 LASSERT(dt_object_exists(dt));
2328 LASSERT(osd_write_locked(env, obj));
2329 LASSERT(th != NULL);
2331 OSD_EXEC_OP(th, ref_del);
2333 cfs_spin_lock(&obj->oo_guard);
2334 LASSERT(inode->i_nlink > 0);
2336 /* If this is/was a many-subdir directory (nlink > LDISKFS_LINK_MAX)
2337 * then the nlink count is 1. Don't let it be set to 0 or the directory
2338 * inode will be deleted incorrectly. */
2339 if (S_ISDIR(inode->i_mode) && inode->i_nlink == 0)
2341 cfs_spin_unlock(&obj->oo_guard);
2342 inode->i_sb->s_op->dirty_inode(inode);
2343 LINVRNT(osd_invariant(obj));
2349 * Get the 64-bit version for an inode.
2351 static int osd_object_version_get(const struct lu_env *env,
2352 struct dt_object *dt, dt_obj_version_t *ver)
2354 struct inode *inode = osd_dt_obj(dt)->oo_inode;
2356 CDEBUG(D_INODE, "Get version "LPX64" for inode %lu\n",
2357 LDISKFS_I(inode)->i_fs_version, inode->i_ino);
2358 *ver = LDISKFS_I(inode)->i_fs_version;
2363 * Concurrency: @dt is read locked.
2365 static int osd_xattr_get(const struct lu_env *env, struct dt_object *dt,
2366 struct lu_buf *buf, const char *name,
2367 struct lustre_capa *capa)
2369 struct osd_object *obj = osd_dt_obj(dt);
2370 struct inode *inode = obj->oo_inode;
2371 struct osd_thread_info *info = osd_oti_get(env);
2372 struct dentry *dentry = &info->oti_obj_dentry;
2374 /* version get is not real XATTR but uses xattr API */
2375 if (strcmp(name, XATTR_NAME_VERSION) == 0) {
2376 /* for version we are just using xattr API but change inode
2378 LASSERT(buf->lb_len == sizeof(dt_obj_version_t));
2379 osd_object_version_get(env, dt, buf->lb_buf);
2380 return sizeof(dt_obj_version_t);
2383 LASSERT(dt_object_exists(dt));
2384 LASSERT(inode->i_op != NULL && inode->i_op->getxattr != NULL);
2386 if (osd_object_auth(env, dt, capa, CAPA_OPC_META_READ))
2389 dentry->d_inode = inode;
2390 return inode->i_op->getxattr(dentry, name, buf->lb_buf, buf->lb_len);
2394 static int osd_declare_xattr_set(const struct lu_env *env,
2395 struct dt_object *dt,
2396 const struct lu_buf *buf, const char *name,
2397 int fl, struct thandle *handle)
2399 struct osd_thandle *oh;
2401 LASSERT(handle != NULL);
2403 oh = container_of0(handle, struct osd_thandle, ot_super);
2404 LASSERT(oh->ot_handle == NULL);
2406 OSD_DECLARE_OP(oh, xattr_set, strcmp(name, XATTR_NAME_VERSION) == 0 ?
2407 osd_dto_credits_noquota[DTO_ATTR_SET_BASE] :
2408 osd_dto_credits_noquota[DTO_XATTR_SET]);
2414 * Set the 64-bit version for object
2416 static void osd_object_version_set(const struct lu_env *env,
2417 struct dt_object *dt,
2418 dt_obj_version_t *new_version)
2420 struct inode *inode = osd_dt_obj(dt)->oo_inode;
2422 CDEBUG(D_INODE, "Set version "LPX64" (old "LPX64") for inode %lu\n",
2423 *new_version, LDISKFS_I(inode)->i_fs_version, inode->i_ino);
2425 LDISKFS_I(inode)->i_fs_version = *new_version;
2426 /** Version is set after all inode operations are finished,
2427 * so we should mark it dirty here */
2428 inode->i_sb->s_op->dirty_inode(inode);
2432 * Concurrency: @dt is write locked.
2434 static int osd_xattr_set(const struct lu_env *env, struct dt_object *dt,
2435 const struct lu_buf *buf, const char *name, int fl,
2436 struct thandle *handle, struct lustre_capa *capa)
2438 LASSERT(handle != NULL);
2440 /* version set is not real XATTR */
2441 if (strcmp(name, XATTR_NAME_VERSION) == 0) {
2442 /* for version we are just using xattr API but change inode
2444 LASSERT(buf->lb_len == sizeof(dt_obj_version_t));
2445 osd_object_version_set(env, dt, buf->lb_buf);
2446 return sizeof(dt_obj_version_t);
2449 if (osd_object_auth(env, dt, capa, CAPA_OPC_META_WRITE))
2452 OSD_EXEC_OP(handle, xattr_set);
2453 return __osd_xattr_set(env, dt, buf, name, fl);
2457 * Concurrency: @dt is read locked.
2459 static int osd_xattr_list(const struct lu_env *env, struct dt_object *dt,
2460 struct lu_buf *buf, struct lustre_capa *capa)
2462 struct osd_object *obj = osd_dt_obj(dt);
2463 struct inode *inode = obj->oo_inode;
2464 struct osd_thread_info *info = osd_oti_get(env);
2465 struct dentry *dentry = &info->oti_obj_dentry;
2467 LASSERT(dt_object_exists(dt));
2468 LASSERT(inode->i_op != NULL && inode->i_op->listxattr != NULL);
2469 LASSERT(osd_read_locked(env, obj) || osd_write_locked(env, obj));
2471 if (osd_object_auth(env, dt, capa, CAPA_OPC_META_READ))
2474 dentry->d_inode = inode;
2475 return inode->i_op->listxattr(dentry, buf->lb_buf, buf->lb_len);
2478 static int osd_declare_xattr_del(const struct lu_env *env,
2479 struct dt_object *dt, const char *name,
2480 struct thandle *handle)
2482 struct osd_thandle *oh;
2484 LASSERT(dt_object_exists(dt));
2485 LASSERT(handle != NULL);
2487 oh = container_of0(handle, struct osd_thandle, ot_super);
2488 LASSERT(oh->ot_handle == NULL);
2490 OSD_DECLARE_OP(oh, xattr_set, osd_dto_credits_noquota[DTO_XATTR_SET]);
2496 * Concurrency: @dt is write locked.
2498 static int osd_xattr_del(const struct lu_env *env, struct dt_object *dt,
2499 const char *name, struct thandle *handle,
2500 struct lustre_capa *capa)
2502 struct osd_object *obj = osd_dt_obj(dt);
2503 struct inode *inode = obj->oo_inode;
2504 struct osd_thread_info *info = osd_oti_get(env);
2505 struct dentry *dentry = &info->oti_obj_dentry;
2508 LASSERT(dt_object_exists(dt));
2509 LASSERT(inode->i_op != NULL && inode->i_op->removexattr != NULL);
2510 LASSERT(osd_write_locked(env, obj));
2511 LASSERT(handle != NULL);
2513 if (osd_object_auth(env, dt, capa, CAPA_OPC_META_WRITE))
2516 OSD_EXEC_OP(handle, xattr_set);
2518 ll_vfs_dq_init(inode);
2519 dentry->d_inode = inode;
2520 rc = inode->i_op->removexattr(dentry, name);
2524 static struct obd_capa *osd_capa_get(const struct lu_env *env,
2525 struct dt_object *dt,
2526 struct lustre_capa *old,
2529 struct osd_thread_info *info = osd_oti_get(env);
2530 const struct lu_fid *fid = lu_object_fid(&dt->do_lu);
2531 struct osd_object *obj = osd_dt_obj(dt);
2532 struct osd_device *dev = osd_obj2dev(obj);
2533 struct lustre_capa_key *key = &info->oti_capa_key;
2534 struct lustre_capa *capa = &info->oti_capa;
2535 struct obd_capa *oc;
2536 struct md_capainfo *ci;
2540 if (!dev->od_fl_capa)
2541 RETURN(ERR_PTR(-ENOENT));
2543 LASSERT(dt_object_exists(dt));
2544 LINVRNT(osd_invariant(obj));
2546 /* renewal sanity check */
2547 if (old && osd_object_auth(env, dt, old, opc))
2548 RETURN(ERR_PTR(-EACCES));
2550 ci = md_capainfo(env);
2552 RETURN(ERR_PTR(-ENOENT));
2554 switch (ci->mc_auth) {
2558 capa->lc_uid = obj->oo_inode->i_uid;
2559 capa->lc_gid = obj->oo_inode->i_gid;
2560 capa->lc_flags = LC_ID_PLAIN;
2562 case LC_ID_CONVERT: {
2565 s[0] = obj->oo_inode->i_uid;
2566 cfs_get_random_bytes(&(s[1]), sizeof(__u32));
2567 s[2] = obj->oo_inode->i_gid;
2568 cfs_get_random_bytes(&(s[3]), sizeof(__u32));
2569 rc = capa_encrypt_id(d, s, key->lk_key, CAPA_HMAC_KEY_MAX_LEN);
2571 RETURN(ERR_PTR(rc));
2573 capa->lc_uid = ((__u64)d[1] << 32) | d[0];
2574 capa->lc_gid = ((__u64)d[3] << 32) | d[2];
2575 capa->lc_flags = LC_ID_CONVERT;
2579 RETURN(ERR_PTR(-EINVAL));
2582 capa->lc_fid = *fid;
2584 capa->lc_flags |= dev->od_capa_alg << 24;
2585 capa->lc_timeout = dev->od_capa_timeout;
2586 capa->lc_expiry = 0;
2588 oc = capa_lookup(dev->od_capa_hash, capa, 1);
2590 LASSERT(!capa_is_expired(oc));
2594 cfs_spin_lock(&capa_lock);
2595 *key = dev->od_capa_keys[1];
2596 cfs_spin_unlock(&capa_lock);
2598 capa->lc_keyid = key->lk_keyid;
2599 capa->lc_expiry = cfs_time_current_sec() + dev->od_capa_timeout;
2601 rc = capa_hmac(capa->lc_hmac, capa, key->lk_key);
2603 DEBUG_CAPA(D_ERROR, capa, "HMAC failed: %d for", rc);
2604 RETURN(ERR_PTR(rc));
2607 oc = capa_add(dev->od_capa_hash, capa);
2611 static int osd_object_sync(const struct lu_env *env, struct dt_object *dt)
2613 struct osd_object *obj = osd_dt_obj(dt);
2614 struct inode *inode = obj->oo_inode;
2615 struct osd_thread_info *info = osd_oti_get(env);
2616 struct dentry *dentry = &info->oti_obj_dentry;
2617 struct file *file = &info->oti_file;
2622 dentry->d_inode = inode;
2623 file->f_dentry = dentry;
2624 file->f_mapping = inode->i_mapping;
2625 file->f_op = inode->i_fop;
2626 mutex_lock(&inode->i_mutex);
2627 rc = file->f_op->fsync(file, dentry, 0);
2628 mutex_unlock(&inode->i_mutex);
2632 static int osd_data_get(const struct lu_env *env, struct dt_object *dt,
2635 struct osd_object *obj = osd_dt_obj(dt);
2638 *data = (void *)obj->oo_inode;
2646 static int osd_iam_index_probe(const struct lu_env *env, struct osd_object *o,
2647 const struct dt_index_features *feat)
2649 struct iam_descr *descr;
2651 if (osd_object_is_root(o))
2652 return feat == &dt_directory_features;
2654 LASSERT(o->oo_dir != NULL);
2656 descr = o->oo_dir->od_container.ic_descr;
2657 if (feat == &dt_directory_features) {
2658 if (descr->id_rec_size == sizeof(struct osd_fid_pack))
2664 feat->dif_keysize_min <= descr->id_key_size &&
2665 descr->id_key_size <= feat->dif_keysize_max &&
2666 feat->dif_recsize_min <= descr->id_rec_size &&
2667 descr->id_rec_size <= feat->dif_recsize_max &&
2668 !(feat->dif_flags & (DT_IND_VARKEY |
2669 DT_IND_VARREC | DT_IND_NONUNQ)) &&
2670 ergo(feat->dif_flags & DT_IND_UPDATE,
2671 1 /* XXX check that object (and file system) is
2676 static int osd_iam_container_init(const struct lu_env *env,
2677 struct osd_object *obj,
2678 struct osd_directory *dir)
2680 struct iam_container *bag = &dir->od_container;
2683 result = iam_container_init(bag, &dir->od_descr, obj->oo_inode);
2687 result = iam_container_setup(bag);
2689 obj->oo_dt.do_index_ops = &osd_index_iam_ops;
2691 iam_container_fini(bag);
2698 * Concurrency: no external locking is necessary.
2700 static int osd_index_try(const struct lu_env *env, struct dt_object *dt,
2701 const struct dt_index_features *feat)
2705 struct osd_object *obj = osd_dt_obj(dt);
2706 struct osd_device *osd = osd_obj2dev(obj);
2708 LINVRNT(osd_invariant(obj));
2709 LASSERT(dt_object_exists(dt));
2711 if (osd_object_is_root(obj)) {
2712 dt->do_index_ops = &osd_index_ea_ops;
2714 } else if (feat == &dt_directory_features && osd->od_iop_mode) {
2715 dt->do_index_ops = &osd_index_ea_ops;
2716 if (S_ISDIR(obj->oo_inode->i_mode))
2721 } else if (unlikely(feat == &dt_otable_features)) {
2722 dt->do_index_ops = &osd_otable_ops;
2724 } else if (feat == &dt_acct_features) {
2725 dt->do_index_ops = &osd_acct_index_ops;
2728 } else if (!osd_has_index(obj)) {
2729 struct osd_directory *dir;
2734 cfs_spin_lock(&obj->oo_guard);
2735 if (obj->oo_dir == NULL)
2739 * Concurrent thread allocated container data.
2742 cfs_spin_unlock(&obj->oo_guard);
2744 * Now, that we have container data, serialize its
2747 cfs_down_write(&obj->oo_ext_idx_sem);
2749 * recheck under lock.
2751 if (!osd_has_index(obj))
2752 result = osd_iam_container_init(env, obj, dir);
2755 cfs_up_write(&obj->oo_ext_idx_sem);
2763 if (result == 0 && skip_iam == 0) {
2764 if (!osd_iam_index_probe(env, obj, feat))
2767 LINVRNT(osd_invariant(obj));
2769 if (is_quota_glb_feat(feat))
2770 result = osd_quota_migration(env, dt, feat);
2775 static int osd_otable_it_attr_get(const struct lu_env *env,
2776 struct dt_object *dt,
2777 struct lu_attr *attr,
2778 struct lustre_capa *capa)
2784 static const struct dt_object_operations osd_obj_ops = {
2785 .do_read_lock = osd_object_read_lock,
2786 .do_write_lock = osd_object_write_lock,
2787 .do_read_unlock = osd_object_read_unlock,
2788 .do_write_unlock = osd_object_write_unlock,
2789 .do_write_locked = osd_object_write_locked,
2790 .do_attr_get = osd_attr_get,
2791 .do_declare_attr_set = osd_declare_attr_set,
2792 .do_attr_set = osd_attr_set,
2793 .do_ah_init = osd_ah_init,
2794 .do_declare_create = osd_declare_object_create,
2795 .do_create = osd_object_create,
2796 .do_declare_destroy = osd_declare_object_destroy,
2797 .do_destroy = osd_object_destroy,
2798 .do_index_try = osd_index_try,
2799 .do_declare_ref_add = osd_declare_object_ref_add,
2800 .do_ref_add = osd_object_ref_add,
2801 .do_declare_ref_del = osd_declare_object_ref_del,
2802 .do_ref_del = osd_object_ref_del,
2803 .do_xattr_get = osd_xattr_get,
2804 .do_declare_xattr_set = osd_declare_xattr_set,
2805 .do_xattr_set = osd_xattr_set,
2806 .do_declare_xattr_del = osd_declare_xattr_del,
2807 .do_xattr_del = osd_xattr_del,
2808 .do_xattr_list = osd_xattr_list,
2809 .do_capa_get = osd_capa_get,
2810 .do_object_sync = osd_object_sync,
2811 .do_data_get = osd_data_get,
2815 * dt_object_operations for interoperability mode
2816 * (i.e. to run 2.0 mds on 1.8 disk) (b11826)
2818 static const struct dt_object_operations osd_obj_ea_ops = {
2819 .do_read_lock = osd_object_read_lock,
2820 .do_write_lock = osd_object_write_lock,
2821 .do_read_unlock = osd_object_read_unlock,
2822 .do_write_unlock = osd_object_write_unlock,
2823 .do_write_locked = osd_object_write_locked,
2824 .do_attr_get = osd_attr_get,
2825 .do_declare_attr_set = osd_declare_attr_set,
2826 .do_attr_set = osd_attr_set,
2827 .do_ah_init = osd_ah_init,
2828 .do_declare_create = osd_declare_object_create,
2829 .do_create = osd_object_ea_create,
2830 .do_declare_destroy = osd_declare_object_destroy,
2831 .do_destroy = osd_object_destroy,
2832 .do_index_try = osd_index_try,
2833 .do_declare_ref_add = osd_declare_object_ref_add,
2834 .do_ref_add = osd_object_ref_add,
2835 .do_declare_ref_del = osd_declare_object_ref_del,
2836 .do_ref_del = osd_object_ref_del,
2837 .do_xattr_get = osd_xattr_get,
2838 .do_declare_xattr_set = osd_declare_xattr_set,
2839 .do_xattr_set = osd_xattr_set,
2840 .do_declare_xattr_del = osd_declare_xattr_del,
2841 .do_xattr_del = osd_xattr_del,
2842 .do_xattr_list = osd_xattr_list,
2843 .do_capa_get = osd_capa_get,
2844 .do_object_sync = osd_object_sync,
2845 .do_data_get = osd_data_get,
2848 static const struct dt_object_operations osd_obj_otable_it_ops = {
2849 .do_attr_get = osd_otable_it_attr_get,
2850 .do_index_try = osd_index_try,
2853 static int osd_index_declare_iam_delete(const struct lu_env *env,
2854 struct dt_object *dt,
2855 const struct dt_key *key,
2856 struct thandle *handle)
2858 struct osd_thandle *oh;
2860 oh = container_of0(handle, struct osd_thandle, ot_super);
2861 LASSERT(oh->ot_handle == NULL);
2863 OSD_DECLARE_OP(oh, delete, osd_dto_credits_noquota[DTO_INDEX_DELETE]);
2869 * delete a (key, value) pair from index \a dt specified by \a key
2871 * \param dt osd index object
2872 * \param key key for index
2873 * \param rec record reference
2874 * \param handle transaction handler
2877 * \retval -ve failure
2880 static int osd_index_iam_delete(const struct lu_env *env, struct dt_object *dt,
2881 const struct dt_key *key,
2882 struct thandle *handle,
2883 struct lustre_capa *capa)
2885 struct osd_thread_info *oti = osd_oti_get(env);
2886 struct osd_object *obj = osd_dt_obj(dt);
2887 struct osd_thandle *oh;
2888 struct iam_path_descr *ipd;
2889 struct iam_container *bag = &obj->oo_dir->od_container;
2894 LINVRNT(osd_invariant(obj));
2895 LASSERT(dt_object_exists(dt));
2896 LASSERT(bag->ic_object == obj->oo_inode);
2897 LASSERT(handle != NULL);
2899 if (osd_object_auth(env, dt, capa, CAPA_OPC_INDEX_DELETE))
2902 OSD_EXEC_OP(handle, delete);
2904 ipd = osd_idx_ipd_get(env, bag);
2905 if (unlikely(ipd == NULL))
2908 oh = container_of0(handle, struct osd_thandle, ot_super);
2909 LASSERT(oh->ot_handle != NULL);
2910 LASSERT(oh->ot_handle->h_transaction != NULL);
2912 if (fid_is_quota(lu_object_fid(&dt->do_lu))) {
2913 /* swab quota uid/gid provided by caller */
2914 oti->oti_quota_id = cpu_to_le64(*((__u64 *)key));
2915 key = (const struct dt_key *)&oti->oti_quota_id;
2918 rc = iam_delete(oh->ot_handle, bag, (const struct iam_key *)key, ipd);
2919 osd_ipd_put(env, bag, ipd);
2920 LINVRNT(osd_invariant(obj));
2924 static int osd_index_declare_ea_delete(const struct lu_env *env,
2925 struct dt_object *dt,
2926 const struct dt_key *key,
2927 struct thandle *handle)
2929 struct osd_thandle *oh;
2930 struct inode *inode;
2934 LASSERT(dt_object_exists(dt));
2935 LASSERT(handle != NULL);
2937 oh = container_of0(handle, struct osd_thandle, ot_super);
2938 LASSERT(oh->ot_handle == NULL);
2940 OSD_DECLARE_OP(oh, delete, osd_dto_credits_noquota[DTO_INDEX_DELETE]);
2942 inode = osd_dt_obj(dt)->oo_inode;
2945 rc = osd_declare_inode_qid(env, inode->i_uid, inode->i_gid, 0, oh,
2946 true, true, NULL, false);
2950 static inline int osd_get_fid_from_dentry(struct ldiskfs_dir_entry_2 *de,
2953 struct osd_fid_pack *rec;
2956 if (de->file_type & LDISKFS_DIRENT_LUFID) {
2957 rec = (struct osd_fid_pack *) (de->name + de->name_len + 1);
2958 rc = osd_fid_unpack((struct lu_fid *)fid, rec);
2964 * Index delete function for interoperability mode (b11826).
2965 * It will remove the directory entry added by osd_index_ea_insert().
2966 * This entry is needed to maintain name->fid mapping.
2968 * \param key, key i.e. file entry to be deleted
2970 * \retval 0, on success
2971 * \retval -ve, on error
2973 static int osd_index_ea_delete(const struct lu_env *env, struct dt_object *dt,
2974 const struct dt_key *key,
2975 struct thandle *handle,
2976 struct lustre_capa *capa)
2978 struct osd_object *obj = osd_dt_obj(dt);
2979 struct inode *dir = obj->oo_inode;
2980 struct dentry *dentry;
2981 struct osd_thandle *oh;
2982 struct ldiskfs_dir_entry_2 *de;
2983 struct buffer_head *bh;
2984 struct htree_lock *hlock = NULL;
2989 LINVRNT(osd_invariant(obj));
2990 LASSERT(dt_object_exists(dt));
2991 LASSERT(handle != NULL);
2993 OSD_EXEC_OP(handle, delete);
2995 oh = container_of(handle, struct osd_thandle, ot_super);
2996 LASSERT(oh->ot_handle != NULL);
2997 LASSERT(oh->ot_handle->h_transaction != NULL);
2999 if (osd_object_auth(env, dt, capa, CAPA_OPC_INDEX_DELETE))
3002 ll_vfs_dq_init(dir);
3003 dentry = osd_child_dentry_get(env, obj,
3004 (char *)key, strlen((char *)key));
3006 if (obj->oo_hl_head != NULL) {
3007 hlock = osd_oti_get(env)->oti_hlock;
3008 ldiskfs_htree_lock(hlock, obj->oo_hl_head,
3009 dir, LDISKFS_HLOCK_DEL);
3011 cfs_down_write(&obj->oo_ext_idx_sem);
3014 bh = osd_ldiskfs_find_entry(dir, dentry, &de, hlock);
3016 rc = ldiskfs_delete_entry(oh->ot_handle,
3023 ldiskfs_htree_unlock(hlock);
3025 cfs_up_write(&obj->oo_ext_idx_sem);
3027 LASSERT(osd_invariant(obj));
3032 * Lookup index for \a key and copy record to \a rec.
3034 * \param dt osd index object
3035 * \param key key for index
3036 * \param rec record reference
3038 * \retval +ve success : exact mach
3039 * \retval 0 return record with key not greater than \a key
3040 * \retval -ve failure
3042 static int osd_index_iam_lookup(const struct lu_env *env, struct dt_object *dt,
3043 struct dt_rec *rec, const struct dt_key *key,
3044 struct lustre_capa *capa)
3046 struct osd_object *obj = osd_dt_obj(dt);
3047 struct iam_path_descr *ipd;
3048 struct iam_container *bag = &obj->oo_dir->od_container;
3049 struct osd_thread_info *oti = osd_oti_get(env);
3050 struct iam_iterator *it = &oti->oti_idx_it;
3051 struct iam_rec *iam_rec;
3056 LASSERT(osd_invariant(obj));
3057 LASSERT(dt_object_exists(dt));
3058 LASSERT(bag->ic_object == obj->oo_inode);
3060 if (osd_object_auth(env, dt, capa, CAPA_OPC_INDEX_LOOKUP))
3063 ipd = osd_idx_ipd_get(env, bag);
3067 /* got ipd now we can start iterator. */
3068 iam_it_init(it, bag, 0, ipd);
3070 if (fid_is_quota(lu_object_fid(&dt->do_lu))) {
3071 /* swab quota uid/gid provided by caller */
3072 oti->oti_quota_id = cpu_to_le64(*((__u64 *)key));
3073 key = (const struct dt_key *)&oti->oti_quota_id;
3076 rc = iam_it_get(it, (struct iam_key *)key);
3078 if (S_ISDIR(obj->oo_inode->i_mode))
3079 iam_rec = (struct iam_rec *)oti->oti_ldp;
3081 iam_rec = (struct iam_rec *) rec;
3083 iam_reccpy(&it->ii_path.ip_leaf, (struct iam_rec *)iam_rec);
3085 if (S_ISDIR(obj->oo_inode->i_mode))
3086 osd_fid_unpack((struct lu_fid *) rec,
3087 (struct osd_fid_pack *)iam_rec);
3088 else if (fid_is_quota(lu_object_fid(&dt->do_lu)))
3089 osd_quota_unpack(obj, rec);
3094 osd_ipd_put(env, bag, ipd);
3096 LINVRNT(osd_invariant(obj));
3101 static int osd_index_declare_iam_insert(const struct lu_env *env,
3102 struct dt_object *dt,
3103 const struct dt_rec *rec,
3104 const struct dt_key *key,
3105 struct thandle *handle)
3107 struct osd_thandle *oh;
3109 LASSERT(dt_object_exists(dt));
3110 LASSERT(handle != NULL);
3112 oh = container_of0(handle, struct osd_thandle, ot_super);
3113 LASSERT(oh->ot_handle == NULL);
3115 OSD_DECLARE_OP(oh, insert, osd_dto_credits_noquota[DTO_INDEX_INSERT]);
3121 * Inserts (key, value) pair in \a dt index object.
3123 * \param dt osd index object
3124 * \param key key for index
3125 * \param rec record reference
3126 * \param th transaction handler
3129 * \retval -ve failure
3131 static int osd_index_iam_insert(const struct lu_env *env, struct dt_object *dt,
3132 const struct dt_rec *rec,
3133 const struct dt_key *key, struct thandle *th,
3134 struct lustre_capa *capa, int ignore_quota)
3136 struct osd_object *obj = osd_dt_obj(dt);
3137 struct iam_path_descr *ipd;
3138 struct osd_thandle *oh;
3139 struct iam_container *bag = &obj->oo_dir->od_container;
3140 struct osd_thread_info *oti = osd_oti_get(env);
3141 struct iam_rec *iam_rec;
3146 LINVRNT(osd_invariant(obj));
3147 LASSERT(dt_object_exists(dt));
3148 LASSERT(bag->ic_object == obj->oo_inode);
3149 LASSERT(th != NULL);
3151 if (osd_object_auth(env, dt, capa, CAPA_OPC_INDEX_INSERT))
3154 OSD_EXEC_OP(th, insert);
3156 ipd = osd_idx_ipd_get(env, bag);
3157 if (unlikely(ipd == NULL))
3160 oh = container_of0(th, struct osd_thandle, ot_super);
3161 LASSERT(oh->ot_handle != NULL);
3162 LASSERT(oh->ot_handle->h_transaction != NULL);
3163 if (S_ISDIR(obj->oo_inode->i_mode)) {
3164 iam_rec = (struct iam_rec *)oti->oti_ldp;
3165 osd_fid_pack((struct osd_fid_pack *)iam_rec, rec, &oti->oti_fid);
3166 } else if (fid_is_quota(lu_object_fid(&dt->do_lu))) {
3167 /* pack quota uid/gid */
3168 oti->oti_quota_id = cpu_to_le64(*((__u64 *)key));
3169 key = (const struct dt_key *)&oti->oti_quota_id;
3170 /* pack quota record */
3171 rec = osd_quota_pack(obj, rec, &oti->oti_quota_rec);
3172 iam_rec = (struct iam_rec *)rec;
3174 iam_rec = (struct iam_rec *)rec;
3177 rc = iam_insert(oh->ot_handle, bag, (const struct iam_key *)key,
3179 osd_ipd_put(env, bag, ipd);
3180 LINVRNT(osd_invariant(obj));
3185 * Calls ldiskfs_add_entry() to add directory entry
3186 * into the directory. This is required for
3187 * interoperability mode (b11826)
3189 * \retval 0, on success
3190 * \retval -ve, on error
3192 static int __osd_ea_add_rec(struct osd_thread_info *info,
3193 struct osd_object *pobj, struct inode *cinode,
3194 const char *name, const struct dt_rec *fid,
3195 struct htree_lock *hlock, struct thandle *th)
3197 struct ldiskfs_dentry_param *ldp;
3198 struct dentry *child;
3199 struct osd_thandle *oth;
3202 oth = container_of(th, struct osd_thandle, ot_super);
3203 LASSERT(oth->ot_handle != NULL);
3204 LASSERT(oth->ot_handle->h_transaction != NULL);
3206 child = osd_child_dentry_get(info->oti_env, pobj, name, strlen(name));
3208 /* XXX: remove fid_is_igif() check here.
3209 * IGIF check is just to handle insertion of .. when it is 'ROOT',
3210 * it is IGIF now but needs FID in dir entry as well for readdir
3212 * LU-838 should fix that and remove fid_is_igif() check */
3213 if (fid_is_igif((struct lu_fid *)fid) ||
3214 fid_is_norm((struct lu_fid *)fid)) {
3215 ldp = (struct ldiskfs_dentry_param *)info->oti_ldp;
3216 osd_get_ldiskfs_dirent_param(ldp, fid);
3217 child->d_fsdata = (void *)ldp;
3219 child->d_fsdata = NULL;
3221 LASSERT(pobj->oo_inode);
3222 ll_vfs_dq_init(pobj->oo_inode);
3223 rc = osd_ldiskfs_add_entry(oth->ot_handle, child, cinode, hlock);
3229 * Calls ldiskfs_add_dot_dotdot() to add dot and dotdot entries
3230 * into the directory.Also sets flags into osd object to
3231 * indicate dot and dotdot are created. This is required for
3232 * interoperability mode (b11826)
3234 * \param dir directory for dot and dotdot fixup.
3235 * \param obj child object for linking
3237 * \retval 0, on success
3238 * \retval -ve, on error
3240 static int osd_add_dot_dotdot(struct osd_thread_info *info,
3241 struct osd_object *dir,
3242 struct inode *parent_dir, const char *name,
3243 const struct dt_rec *dot_fid,
3244 const struct dt_rec *dot_dot_fid,
3247 struct inode *inode = dir->oo_inode;
3248 struct ldiskfs_dentry_param *dot_ldp;
3249 struct ldiskfs_dentry_param *dot_dot_ldp;
3250 struct osd_thandle *oth;
3253 oth = container_of(th, struct osd_thandle, ot_super);
3254 LASSERT(oth->ot_handle->h_transaction != NULL);
3255 LASSERT(S_ISDIR(dir->oo_inode->i_mode));
3257 if (strcmp(name, dot) == 0) {
3258 if (dir->oo_compat_dot_created) {
3261 LASSERT(inode == parent_dir);
3262 dir->oo_compat_dot_created = 1;
3265 } else if(strcmp(name, dotdot) == 0) {
3266 dot_ldp = (struct ldiskfs_dentry_param *)info->oti_ldp;
3267 dot_dot_ldp = (struct ldiskfs_dentry_param *)info->oti_ldp2;
3269 if (!dir->oo_compat_dot_created)
3271 if (!fid_is_igif((struct lu_fid *)dot_fid)) {
3272 osd_get_ldiskfs_dirent_param(dot_ldp, dot_fid);
3273 osd_get_ldiskfs_dirent_param(dot_dot_ldp, dot_dot_fid);
3278 /* in case of rename, dotdot is already created */
3279 if (dir->oo_compat_dotdot_created) {
3280 return __osd_ea_add_rec(info, dir, parent_dir, name,
3281 dot_dot_fid, NULL, th);
3284 result = ldiskfs_add_dot_dotdot(oth->ot_handle, parent_dir,
3285 inode, dot_ldp, dot_dot_ldp);
3287 dir->oo_compat_dotdot_created = 1;
3295 * It will call the appropriate osd_add* function and return the
3296 * value, return by respective functions.
3298 static int osd_ea_add_rec(const struct lu_env *env, struct osd_object *pobj,
3299 struct inode *cinode, const char *name,
3300 const struct dt_rec *fid, struct thandle *th)
3302 struct osd_thread_info *info = osd_oti_get(env);
3303 struct htree_lock *hlock;
3306 hlock = pobj->oo_hl_head != NULL ? info->oti_hlock : NULL;
3308 if (name[0] == '.' && (name[1] == '\0' || (name[1] == '.' &&
3310 if (hlock != NULL) {
3311 ldiskfs_htree_lock(hlock, pobj->oo_hl_head,
3314 cfs_down_write(&pobj->oo_ext_idx_sem);
3316 rc = osd_add_dot_dotdot(info, pobj, cinode, name,
3317 (struct dt_rec *)lu_object_fid(&pobj->oo_dt.do_lu),
3320 if (hlock != NULL) {
3321 ldiskfs_htree_lock(hlock, pobj->oo_hl_head,
3322 pobj->oo_inode, LDISKFS_HLOCK_ADD);
3324 cfs_down_write(&pobj->oo_ext_idx_sem);
3327 rc = __osd_ea_add_rec(info, pobj, cinode, name, fid,
3331 ldiskfs_htree_unlock(hlock);
3333 cfs_up_write(&pobj->oo_ext_idx_sem);
3339 osd_consistency_check(struct osd_thread_info *oti, struct osd_device *dev,
3340 struct osd_idmap_cache *oic)
3342 struct osd_scrub *scrub = &dev->od_scrub;
3343 struct lu_fid *fid = &oic->oic_fid;
3344 struct osd_inode_id *id = &oti->oti_id;
3349 if (!fid_is_norm(fid) && !fid_is_igif(fid))
3353 rc = osd_oi_lookup(oti, dev, fid, id);
3354 if (rc != 0 && rc != -ENOENT)
3357 if (rc == 0 && osd_id_eq(id, &oic->oic_lid))
3360 if (thread_is_running(&scrub->os_thread)) {
3361 rc = osd_oii_insert(dev, oic, rc == -ENOENT);
3362 /* There is race condition between osd_oi_lookup and OI scrub.
3363 * The OI scrub finished just after osd_oi_lookup() failure.
3364 * Under such case, it is unnecessary to trigger OI scrub again,
3365 * but try to call osd_oi_lookup() again. */
3366 if (unlikely(rc == -EAGAIN))
3372 if (!dev->od_noscrub && ++once == 1) {
3373 CDEBUG(D_LFSCK, "Trigger OI scrub by RPC for "DFID"\n",
3375 rc = osd_scrub_start(dev);
3376 LCONSOLE_ERROR("%.16s: trigger OI scrub by RPC for "DFID
3378 LDISKFS_SB(osd_sb(dev))->s_es->s_volume_name,
3388 * Calls ->lookup() to find dentry. From dentry get inode and
3389 * read inode's ea to get fid. This is required for interoperability
3392 * \retval 0, on success
3393 * \retval -ve, on error
3395 static int osd_ea_lookup_rec(const struct lu_env *env, struct osd_object *obj,
3396 struct dt_rec *rec, const struct dt_key *key)
3398 struct inode *dir = obj->oo_inode;
3399 struct dentry *dentry;
3400 struct ldiskfs_dir_entry_2 *de;
3401 struct buffer_head *bh;
3402 struct lu_fid *fid = (struct lu_fid *) rec;
3403 struct htree_lock *hlock = NULL;
3407 LASSERT(dir->i_op != NULL && dir->i_op->lookup != NULL);
3409 dentry = osd_child_dentry_get(env, obj,
3410 (char *)key, strlen((char *)key));
3412 if (obj->oo_hl_head != NULL) {
3413 hlock = osd_oti_get(env)->oti_hlock;
3414 ldiskfs_htree_lock(hlock, obj->oo_hl_head,
3415 dir, LDISKFS_HLOCK_LOOKUP);
3417 cfs_down_read(&obj->oo_ext_idx_sem);
3420 bh = osd_ldiskfs_find_entry(dir, dentry, &de, hlock);
3422 struct osd_thread_info *oti = osd_oti_get(env);
3423 struct osd_idmap_cache *oic = &oti->oti_cache;
3424 struct osd_device *dev = osd_obj2dev(obj);
3425 struct osd_scrub *scrub = &dev->od_scrub;
3426 struct scrub_file *sf = &scrub->os_file;
3428 ino = le32_to_cpu(de->inode);
3429 rc = osd_get_fid_from_dentry(de, rec);
3431 /* done with de, release bh */
3434 rc = osd_ea_fid_get(env, obj, ino, fid, &oic->oic_lid);
3436 osd_id_gen(&oic->oic_lid, ino, OSD_OII_NOGEN);
3438 fid_zero(&oic->oic_fid);
3442 oic->oic_fid = *fid;
3443 if ((scrub->os_pos_current <= ino) &&
3444 (sf->sf_flags & SF_INCONSISTENT ||
3445 ldiskfs_test_bit(osd_oi_fid2idx(dev, fid),
3447 osd_consistency_check(oti, dev, oic);
3456 ldiskfs_htree_unlock(hlock);
3458 cfs_up_read(&obj->oo_ext_idx_sem);
3463 * Find the osd object for given fid.
3465 * \param fid need to find the osd object having this fid
3467 * \retval osd_object on success
3468 * \retval -ve on error
3470 struct osd_object *osd_object_find(const struct lu_env *env,
3471 struct dt_object *dt,
3472 const struct lu_fid *fid)
3474 struct lu_device *ludev = dt->do_lu.lo_dev;
3475 struct osd_object *child = NULL;
3476 struct lu_object *luch;
3477 struct lu_object *lo;
3480 * at this point topdev might not exist yet
3481 * (i.e. MGS is preparing profiles). so we can
3482 * not rely on topdev and instead lookup with
3483 * our device passed as topdev. this can't work
3484 * if the object isn't cached yet (as osd doesn't
3485 * allocate lu_header). IOW, the object must be
3486 * in the cache, otherwise lu_object_alloc() crashes
3489 luch = lu_object_find_at(env, ludev, fid, NULL);
3490 if (!IS_ERR(luch)) {
3491 if (lu_object_exists(luch)) {
3492 lo = lu_object_locate(luch->lo_header, ludev->ld_type);
3494 child = osd_obj(lo);
3496 LU_OBJECT_DEBUG(D_ERROR, env, luch,
3497 "lu_object can't be located"
3498 DFID"\n", PFID(fid));
3500 if (child == NULL) {
3501 lu_object_put(env, luch);
3502 CERROR("Unable to get osd_object\n");
3503 child = ERR_PTR(-ENOENT);
3506 LU_OBJECT_DEBUG(D_ERROR, env, luch,
3507 "lu_object does not exists "DFID"\n",
3509 lu_object_put(env, luch);
3510 child = ERR_PTR(-ENOENT);
3513 child = (void *)luch;
3519 * Put the osd object once done with it.
3521 * \param obj osd object that needs to be put
3523 static inline void osd_object_put(const struct lu_env *env,
3524 struct osd_object *obj)
3526 lu_object_put(env, &obj->oo_dt.do_lu);
3529 static int osd_index_declare_ea_insert(const struct lu_env *env,
3530 struct dt_object *dt,
3531 const struct dt_rec *rec,
3532 const struct dt_key *key,
3533 struct thandle *handle)
3535 struct osd_thandle *oh;
3536 struct inode *inode;
3540 LASSERT(dt_object_exists(dt));
3541 LASSERT(handle != NULL);
3543 oh = container_of0(handle, struct osd_thandle, ot_super);
3544 LASSERT(oh->ot_handle == NULL);
3546 OSD_DECLARE_OP(oh, insert, osd_dto_credits_noquota[DTO_INDEX_INSERT]);
3548 inode = osd_dt_obj(dt)->oo_inode;
3551 /* We ignore block quota on meta pool (MDTs), so needn't
3552 * calculate how many blocks will be consumed by this index
3554 rc = osd_declare_inode_qid(env, inode->i_uid, inode->i_gid, 0, oh,
3555 true, true, NULL, false);
3560 * Index add function for interoperability mode (b11826).
3561 * It will add the directory entry.This entry is needed to
3562 * maintain name->fid mapping.
3564 * \param key it is key i.e. file entry to be inserted
3565 * \param rec it is value of given key i.e. fid
3567 * \retval 0, on success
3568 * \retval -ve, on error
3570 static int osd_index_ea_insert(const struct lu_env *env, struct dt_object *dt,
3571 const struct dt_rec *rec,
3572 const struct dt_key *key, struct thandle *th,
3573 struct lustre_capa *capa, int ignore_quota)
3575 struct osd_object *obj = osd_dt_obj(dt);
3576 struct lu_fid *fid = (struct lu_fid *) rec;
3577 const char *name = (const char *)key;
3578 struct osd_object *child;
3583 LASSERT(osd_invariant(obj));
3584 LASSERT(dt_object_exists(dt));
3585 LASSERT(th != NULL);
3587 if (osd_object_auth(env, dt, capa, CAPA_OPC_INDEX_INSERT))
3590 child = osd_object_find(env, dt, fid);
3591 if (!IS_ERR(child)) {
3592 rc = osd_ea_add_rec(env, obj, child->oo_inode, name, rec, th);
3593 osd_object_put(env, child);
3595 rc = PTR_ERR(child);
3598 LASSERT(osd_invariant(obj));
3603 * Initialize osd Iterator for given osd index object.
3605 * \param dt osd index object
3608 static struct dt_it *osd_it_iam_init(const struct lu_env *env,
3609 struct dt_object *dt,
3611 struct lustre_capa *capa)
3613 struct osd_it_iam *it;
3614 struct osd_thread_info *oti = osd_oti_get(env);
3615 struct osd_object *obj = osd_dt_obj(dt);
3616 struct lu_object *lo = &dt->do_lu;
3617 struct iam_path_descr *ipd;
3618 struct iam_container *bag = &obj->oo_dir->od_container;
3620 LASSERT(lu_object_exists(lo));
3622 if (osd_object_auth(env, dt, capa, CAPA_OPC_BODY_READ))
3623 return ERR_PTR(-EACCES);
3626 ipd = osd_it_ipd_get(env, bag);
3627 if (likely(ipd != NULL)) {
3631 iam_it_init(&it->oi_it, bag, IAM_IT_MOVE, ipd);
3632 return (struct dt_it *)it;
3634 return ERR_PTR(-ENOMEM);
3638 * free given Iterator.
3641 static void osd_it_iam_fini(const struct lu_env *env, struct dt_it *di)
3643 struct osd_it_iam *it = (struct osd_it_iam *)di;
3644 struct osd_object *obj = it->oi_obj;
3646 iam_it_fini(&it->oi_it);
3647 osd_ipd_put(env, &obj->oo_dir->od_container, it->oi_ipd);
3648 lu_object_put(env, &obj->oo_dt.do_lu);
3652 * Move Iterator to record specified by \a key
3654 * \param di osd iterator
3655 * \param key key for index
3657 * \retval +ve di points to record with least key not larger than key
3658 * \retval 0 di points to exact matched key
3659 * \retval -ve failure
3662 static int osd_it_iam_get(const struct lu_env *env,
3663 struct dt_it *di, const struct dt_key *key)
3665 struct osd_thread_info *oti = osd_oti_get(env);
3666 struct osd_it_iam *it = (struct osd_it_iam *)di;
3668 if (fid_is_quota(lu_object_fid(&it->oi_obj->oo_dt.do_lu))) {
3669 /* swab quota uid/gid */
3670 oti->oti_quota_id = cpu_to_le64(*((__u64 *)key));
3671 key = (struct dt_key *)&oti->oti_quota_id;
3674 return iam_it_get(&it->oi_it, (const struct iam_key *)key);
3680 * \param di osd iterator
3683 static void osd_it_iam_put(const struct lu_env *env, struct dt_it *di)
3685 struct osd_it_iam *it = (struct osd_it_iam *)di;
3687 iam_it_put(&it->oi_it);
3691 * Move iterator by one record
3693 * \param di osd iterator
3695 * \retval +1 end of container reached
3697 * \retval -ve failure
3700 static int osd_it_iam_next(const struct lu_env *env, struct dt_it *di)
3702 struct osd_it_iam *it = (struct osd_it_iam *)di;
3704 return iam_it_next(&it->oi_it);
3708 * Return pointer to the key under iterator.
3711 static struct dt_key *osd_it_iam_key(const struct lu_env *env,
3712 const struct dt_it *di)
3714 struct osd_thread_info *oti = osd_oti_get(env);
3715 struct osd_it_iam *it = (struct osd_it_iam *)di;
3716 struct osd_object *obj = it->oi_obj;
3719 key = (struct dt_key *)iam_it_key_get(&it->oi_it);
3721 if (!IS_ERR(key) && fid_is_quota(lu_object_fid(&obj->oo_dt.do_lu))) {
3722 /* swab quota uid/gid */
3723 oti->oti_quota_id = le64_to_cpu(*((__u64 *)key));
3724 key = (struct dt_key *)&oti->oti_quota_id;
3731 * Return size of key under iterator (in bytes)
3734 static int osd_it_iam_key_size(const struct lu_env *env, const struct dt_it *di)
3736 struct osd_it_iam *it = (struct osd_it_iam *)di;
3738 return iam_it_key_size(&it->oi_it);
3741 static inline void osd_it_append_attrs(struct lu_dirent *ent, __u32 attr,
3742 int len, __u16 type)
3744 struct luda_type *lt;
3745 const unsigned align = sizeof(struct luda_type) - 1;
3747 /* check if file type is required */
3748 if (attr & LUDA_TYPE) {
3749 len = (len + align) & ~align;
3751 lt = (void *) ent->lde_name + len;
3752 lt->lt_type = cpu_to_le16(CFS_DTTOIF(type));
3753 ent->lde_attrs |= LUDA_TYPE;
3756 ent->lde_attrs = cpu_to_le32(ent->lde_attrs);
3760 * build lu direct from backend fs dirent.
3763 static inline void osd_it_pack_dirent(struct lu_dirent *ent,
3764 struct lu_fid *fid, __u64 offset,
3765 char *name, __u16 namelen,
3766 __u16 type, __u32 attr)
3768 fid_cpu_to_le(&ent->lde_fid, fid);
3769 ent->lde_attrs = LUDA_FID;
3771 ent->lde_hash = cpu_to_le64(offset);
3772 ent->lde_reclen = cpu_to_le16(lu_dirent_calc_size(namelen, attr));
3774 strncpy(ent->lde_name, name, namelen);
3775 ent->lde_namelen = cpu_to_le16(namelen);
3777 /* append lustre attributes */
3778 osd_it_append_attrs(ent, attr, namelen, type);
3782 * Return pointer to the record under iterator.
3784 static int osd_it_iam_rec(const struct lu_env *env,
3785 const struct dt_it *di,
3786 struct dt_rec *dtrec, __u32 attr)
3788 struct osd_it_iam *it = (struct osd_it_iam *)di;
3789 struct osd_thread_info *info = osd_oti_get(env);
3792 if (S_ISDIR(it->oi_obj->oo_inode->i_mode)) {
3793 const struct osd_fid_pack *rec;
3794 struct lu_fid *fid = &info->oti_fid;
3795 struct lu_dirent *lde = (struct lu_dirent *)dtrec;
3801 name = (char *)iam_it_key_get(&it->oi_it);
3803 RETURN(PTR_ERR(name));
3805 namelen = iam_it_key_size(&it->oi_it);
3807 rec = (const struct osd_fid_pack *)iam_it_rec_get(&it->oi_it);
3809 RETURN(PTR_ERR(rec));
3811 rc = osd_fid_unpack(fid, rec);
3815 hash = iam_it_store(&it->oi_it);
3817 /* IAM does not store object type in IAM index (dir) */
3818 osd_it_pack_dirent(lde, fid, hash, name, namelen,
3820 } else if (fid_is_quota(lu_object_fid(&it->oi_obj->oo_dt.do_lu))) {
3821 iam_reccpy(&it->oi_it.ii_path.ip_leaf,
3822 (struct iam_rec *)dtrec);
3823 osd_quota_unpack(it->oi_obj, dtrec);
3825 iam_reccpy(&it->oi_it.ii_path.ip_leaf,
3826 (struct iam_rec *)dtrec);
3833 * Returns cookie for current Iterator position.
3835 static __u64 osd_it_iam_store(const struct lu_env *env, const struct dt_it *di)
3837 struct osd_it_iam *it = (struct osd_it_iam *)di;
3839 return iam_it_store(&it->oi_it);
3843 * Restore iterator from cookie.
3845 * \param di osd iterator
3846 * \param hash Iterator location cookie
3848 * \retval +ve di points to record with least key not larger than key.
3849 * \retval 0 di points to exact matched key
3850 * \retval -ve failure
3853 static int osd_it_iam_load(const struct lu_env *env,
3854 const struct dt_it *di, __u64 hash)
3856 struct osd_it_iam *it = (struct osd_it_iam *)di;
3858 return iam_it_load(&it->oi_it, hash);
3861 static const struct dt_index_operations osd_index_iam_ops = {
3862 .dio_lookup = osd_index_iam_lookup,
3863 .dio_declare_insert = osd_index_declare_iam_insert,
3864 .dio_insert = osd_index_iam_insert,
3865 .dio_declare_delete = osd_index_declare_iam_delete,
3866 .dio_delete = osd_index_iam_delete,
3868 .init = osd_it_iam_init,
3869 .fini = osd_it_iam_fini,
3870 .get = osd_it_iam_get,
3871 .put = osd_it_iam_put,
3872 .next = osd_it_iam_next,
3873 .key = osd_it_iam_key,
3874 .key_size = osd_it_iam_key_size,
3875 .rec = osd_it_iam_rec,
3876 .store = osd_it_iam_store,
3877 .load = osd_it_iam_load
3882 * Creates or initializes iterator context.
3884 * \retval struct osd_it_ea, iterator structure on success
3887 static struct dt_it *osd_it_ea_init(const struct lu_env *env,
3888 struct dt_object *dt,
3890 struct lustre_capa *capa)
3892 struct osd_object *obj = osd_dt_obj(dt);
3893 struct osd_thread_info *info = osd_oti_get(env);
3894 struct osd_it_ea *it = &info->oti_it_ea;
3895 struct lu_object *lo = &dt->do_lu;
3896 struct dentry *obj_dentry = &info->oti_it_dentry;
3898 LASSERT(lu_object_exists(lo));
3900 obj_dentry->d_inode = obj->oo_inode;
3901 obj_dentry->d_sb = osd_sb(osd_obj2dev(obj));
3902 obj_dentry->d_name.hash = 0;
3904 it->oie_rd_dirent = 0;
3905 it->oie_it_dirent = 0;
3906 it->oie_dirent = NULL;
3907 it->oie_buf = info->oti_it_ea_buf;
3909 it->oie_file.f_pos = 0;
3910 it->oie_file.f_dentry = obj_dentry;
3911 if (attr & LUDA_64BITHASH)
3912 it->oie_file.f_mode |= FMODE_64BITHASH;
3914 it->oie_file.f_mode |= FMODE_32BITHASH;
3915 it->oie_file.f_mapping = obj->oo_inode->i_mapping;
3916 it->oie_file.f_op = obj->oo_inode->i_fop;
3917 it->oie_file.private_data = NULL;
3919 RETURN((struct dt_it *) it);
3923 * Destroy or finishes iterator context.
3925 * \param di iterator structure to be destroyed
3927 static void osd_it_ea_fini(const struct lu_env *env, struct dt_it *di)
3929 struct osd_it_ea *it = (struct osd_it_ea *)di;
3930 struct osd_object *obj = it->oie_obj;
3931 struct inode *inode = obj->oo_inode;
3934 it->oie_file.f_op->release(inode, &it->oie_file);
3935 lu_object_put(env, &obj->oo_dt.do_lu);
3940 * It position the iterator at given key, so that next lookup continues from
3941 * that key Or it is similar to dio_it->load() but based on a key,
3942 * rather than file position.
3944 * As a special convention, osd_it_ea_get(env, di, "") has to rewind iterator
3947 * TODO: Presently return +1 considering it is only used by mdd_dir_is_empty().
3949 static int osd_it_ea_get(const struct lu_env *env,
3950 struct dt_it *di, const struct dt_key *key)
3952 struct osd_it_ea *it = (struct osd_it_ea *)di;
3955 LASSERT(((const char *)key)[0] == '\0');
3956 it->oie_file.f_pos = 0;
3957 it->oie_rd_dirent = 0;
3958 it->oie_it_dirent = 0;
3959 it->oie_dirent = NULL;
3967 static void osd_it_ea_put(const struct lu_env *env, struct dt_it *di)
3972 * It is called internally by ->readdir(). It fills the
3973 * iterator's in-memory data structure with required
3974 * information i.e. name, namelen, rec_size etc.
3976 * \param buf in which information to be filled in.
3977 * \param name name of the file in given dir
3979 * \retval 0 on success
3980 * \retval 1 on buffer full
3982 static int osd_ldiskfs_filldir(char *buf, const char *name, int namelen,
3983 loff_t offset, __u64 ino,
3986 struct osd_it_ea *it = (struct osd_it_ea *)buf;
3987 struct osd_it_ea_dirent *ent = it->oie_dirent;
3988 struct lu_fid *fid = &ent->oied_fid;
3989 struct osd_fid_pack *rec;
3992 /* this should never happen */
3993 if (unlikely(namelen == 0 || namelen > LDISKFS_NAME_LEN)) {
3994 CERROR("ldiskfs return invalid namelen %d\n", namelen);
3998 if ((void *) ent - it->oie_buf + sizeof(*ent) + namelen >
4002 if (d_type & LDISKFS_DIRENT_LUFID) {
4003 rec = (struct osd_fid_pack*) (name + namelen + 1);
4005 if (osd_fid_unpack(fid, rec) != 0)
4008 d_type &= ~LDISKFS_DIRENT_LUFID;
4013 ent->oied_ino = ino;
4014 ent->oied_off = offset;
4015 ent->oied_namelen = namelen;
4016 ent->oied_type = d_type;
4018 memcpy(ent->oied_name, name, namelen);
4020 it->oie_rd_dirent++;
4021 it->oie_dirent = (void *) ent + cfs_size_round(sizeof(*ent) + namelen);
4026 * Calls ->readdir() to load a directory entry at a time
4027 * and stored it in iterator's in-memory data structure.
4029 * \param di iterator's in memory structure
4031 * \retval 0 on success
4032 * \retval -ve on error
4034 static int osd_ldiskfs_it_fill(const struct lu_env *env,
4035 const struct dt_it *di)
4037 struct osd_it_ea *it = (struct osd_it_ea *)di;
4038 struct osd_object *obj = it->oie_obj;
4039 struct inode *inode = obj->oo_inode;
4040 struct htree_lock *hlock = NULL;
4044 it->oie_dirent = it->oie_buf;
4045 it->oie_rd_dirent = 0;
4047 if (obj->oo_hl_head != NULL) {
4048 hlock = osd_oti_get(env)->oti_hlock;
4049 ldiskfs_htree_lock(hlock, obj->oo_hl_head,
4050 inode, LDISKFS_HLOCK_READDIR);
4052 cfs_down_read(&obj->oo_ext_idx_sem);
4055 result = inode->i_fop->readdir(&it->oie_file, it,
4056 (filldir_t) osd_ldiskfs_filldir);
4059 ldiskfs_htree_unlock(hlock);
4061 cfs_up_read(&obj->oo_ext_idx_sem);
4063 if (it->oie_rd_dirent == 0) {
4066 it->oie_dirent = it->oie_buf;
4067 it->oie_it_dirent = 1;
4074 * It calls osd_ldiskfs_it_fill() which will use ->readdir()
4075 * to load a directory entry at a time and stored it in
4076 * iterator's in-memory data structure.
4078 * \param di iterator's in memory structure
4080 * \retval +ve iterator reached to end
4081 * \retval 0 iterator not reached to end
4082 * \retval -ve on error
4084 static int osd_it_ea_next(const struct lu_env *env, struct dt_it *di)
4086 struct osd_it_ea *it = (struct osd_it_ea *)di;
4091 if (it->oie_it_dirent < it->oie_rd_dirent) {
4093 (void *) it->oie_dirent +
4094 cfs_size_round(sizeof(struct osd_it_ea_dirent) +
4095 it->oie_dirent->oied_namelen);
4096 it->oie_it_dirent++;
4099 if (it->oie_file.f_pos == ldiskfs_get_htree_eof(&it->oie_file))
4102 rc = osd_ldiskfs_it_fill(env, di);
4109 * Returns the key at current position from iterator's in memory structure.
4111 * \param di iterator's in memory structure
4113 * \retval key i.e. struct dt_key on success
4115 static struct dt_key *osd_it_ea_key(const struct lu_env *env,
4116 const struct dt_it *di)
4118 struct osd_it_ea *it = (struct osd_it_ea *)di;
4120 return (struct dt_key *)it->oie_dirent->oied_name;
4124 * Returns the key's size at current position from iterator's in memory structure.
4126 * \param di iterator's in memory structure
4128 * \retval key_size i.e. struct dt_key on success
4130 static int osd_it_ea_key_size(const struct lu_env *env, const struct dt_it *di)
4132 struct osd_it_ea *it = (struct osd_it_ea *)di;
4134 return it->oie_dirent->oied_namelen;
4139 * Returns the value (i.e. fid/igif) at current position from iterator's
4140 * in memory structure.
4142 * \param di struct osd_it_ea, iterator's in memory structure
4143 * \param attr attr requested for dirent.
4144 * \param lde lustre dirent
4146 * \retval 0 no error and \param lde has correct lustre dirent.
4147 * \retval -ve on error
4149 static inline int osd_it_ea_rec(const struct lu_env *env,
4150 const struct dt_it *di,
4151 struct dt_rec *dtrec, __u32 attr)
4153 struct osd_it_ea *it = (struct osd_it_ea *)di;
4154 struct osd_object *obj = it->oie_obj;
4155 struct osd_device *dev = osd_obj2dev(obj);
4156 struct osd_scrub *scrub = &dev->od_scrub;
4157 struct scrub_file *sf = &scrub->os_file;
4158 struct osd_thread_info *oti = osd_oti_get(env);
4159 struct osd_idmap_cache *oic = &oti->oti_cache;
4160 struct lu_fid *fid = &it->oie_dirent->oied_fid;
4161 struct lu_dirent *lde = (struct lu_dirent *)dtrec;
4162 __u32 ino = it->oie_dirent->oied_ino;
4166 if (!fid_is_sane(fid)) {
4167 rc = osd_ea_fid_get(env, obj, ino, fid, &oic->oic_lid);
4169 fid_zero(&oic->oic_fid);
4173 osd_id_gen(&oic->oic_lid, ino, OSD_OII_NOGEN);
4176 osd_it_pack_dirent(lde, fid, it->oie_dirent->oied_off,
4177 it->oie_dirent->oied_name,
4178 it->oie_dirent->oied_namelen,
4179 it->oie_dirent->oied_type, attr);
4180 oic->oic_fid = *fid;
4181 if ((scrub->os_pos_current <= ino) &&
4182 (sf->sf_flags & SF_INCONSISTENT ||
4183 ldiskfs_test_bit(osd_oi_fid2idx(dev, fid), sf->sf_oi_bitmap)))
4184 osd_consistency_check(oti, dev, oic);
4190 * Returns a cookie for current position of the iterator head, so that
4191 * user can use this cookie to load/start the iterator next time.
4193 * \param di iterator's in memory structure
4195 * \retval cookie for current position, on success
4197 static __u64 osd_it_ea_store(const struct lu_env *env, const struct dt_it *di)
4199 struct osd_it_ea *it = (struct osd_it_ea *)di;
4201 return it->oie_dirent->oied_off;
4205 * It calls osd_ldiskfs_it_fill() which will use ->readdir()
4206 * to load a directory entry at a time and stored it i inn,
4207 * in iterator's in-memory data structure.
4209 * \param di struct osd_it_ea, iterator's in memory structure
4211 * \retval +ve on success
4212 * \retval -ve on error
4214 static int osd_it_ea_load(const struct lu_env *env,
4215 const struct dt_it *di, __u64 hash)
4217 struct osd_it_ea *it = (struct osd_it_ea *)di;
4221 it->oie_file.f_pos = hash;
4223 rc = osd_ldiskfs_it_fill(env, di);
4231 * Index lookup function for interoperability mode (b11826).
4233 * \param key, key i.e. file name to be searched
4235 * \retval +ve, on success
4236 * \retval -ve, on error
4238 static int osd_index_ea_lookup(const struct lu_env *env, struct dt_object *dt,
4239 struct dt_rec *rec, const struct dt_key *key,
4240 struct lustre_capa *capa)
4242 struct osd_object *obj = osd_dt_obj(dt);
4247 LASSERT(S_ISDIR(obj->oo_inode->i_mode));
4248 LINVRNT(osd_invariant(obj));
4250 if (osd_object_auth(env, dt, capa, CAPA_OPC_INDEX_LOOKUP))
4253 rc = osd_ea_lookup_rec(env, obj, rec, key);
4260 * Index and Iterator operations for interoperability
4261 * mode (i.e. to run 2.0 mds on 1.8 disk) (b11826)
4263 static const struct dt_index_operations osd_index_ea_ops = {
4264 .dio_lookup = osd_index_ea_lookup,
4265 .dio_declare_insert = osd_index_declare_ea_insert,
4266 .dio_insert = osd_index_ea_insert,
4267 .dio_declare_delete = osd_index_declare_ea_delete,
4268 .dio_delete = osd_index_ea_delete,
4270 .init = osd_it_ea_init,
4271 .fini = osd_it_ea_fini,
4272 .get = osd_it_ea_get,
4273 .put = osd_it_ea_put,
4274 .next = osd_it_ea_next,
4275 .key = osd_it_ea_key,
4276 .key_size = osd_it_ea_key_size,
4277 .rec = osd_it_ea_rec,
4278 .store = osd_it_ea_store,
4279 .load = osd_it_ea_load
4283 static void *osd_key_init(const struct lu_context *ctx,
4284 struct lu_context_key *key)
4286 struct osd_thread_info *info;
4288 OBD_ALLOC_PTR(info);
4290 return ERR_PTR(-ENOMEM);
4292 OBD_ALLOC(info->oti_it_ea_buf, OSD_IT_EA_BUFSIZE);
4293 if (info->oti_it_ea_buf == NULL)
4296 info->oti_env = container_of(ctx, struct lu_env, le_ctx);
4298 info->oti_hlock = ldiskfs_htree_lock_alloc();
4299 if (info->oti_hlock == NULL)
4305 OBD_FREE(info->oti_it_ea_buf, OSD_IT_EA_BUFSIZE);
4308 return ERR_PTR(-ENOMEM);
4311 static void osd_key_fini(const struct lu_context *ctx,
4312 struct lu_context_key *key, void* data)
4314 struct osd_thread_info *info = data;
4316 if (info->oti_hlock != NULL)
4317 ldiskfs_htree_lock_free(info->oti_hlock);
4318 OBD_FREE(info->oti_it_ea_buf, OSD_IT_EA_BUFSIZE);
4322 static void osd_key_exit(const struct lu_context *ctx,
4323 struct lu_context_key *key, void *data)
4325 struct osd_thread_info *info = data;
4327 LASSERT(info->oti_r_locks == 0);
4328 LASSERT(info->oti_w_locks == 0);
4329 LASSERT(info->oti_txns == 0);
4332 /* type constructor/destructor: osd_type_init, osd_type_fini */
4333 LU_TYPE_INIT_FINI(osd, &osd_key);
4335 struct lu_context_key osd_key = {
4336 .lct_tags = LCT_DT_THREAD | LCT_MD_THREAD | LCT_MG_THREAD | LCT_LOCAL,
4337 .lct_init = osd_key_init,
4338 .lct_fini = osd_key_fini,
4339 .lct_exit = osd_key_exit
4343 static int osd_device_init(const struct lu_env *env, struct lu_device *d,
4344 const char *name, struct lu_device *next)
4346 struct osd_device *osd = osd_dev(d);
4348 strncpy(osd->od_svname, name, MAX_OBD_NAME);
4349 return osd_procfs_init(osd, name);
4352 static int osd_shutdown(const struct lu_env *env, struct osd_device *o)
4356 osd_scrub_cleanup(env, o);
4359 fsfilt_put_ops(o->od_fsops);
4363 /* shutdown quota slave instance associated with the device */
4364 if (o->od_quota_slave != NULL) {
4365 qsd_fini(env, o->od_quota_slave);
4366 o->od_quota_slave = NULL;
4372 static int osd_mount(const struct lu_env *env,
4373 struct osd_device *o, struct lustre_cfg *cfg)
4375 const char *name = lustre_cfg_string(cfg, 0);
4376 const char *dev = lustre_cfg_string(cfg, 1);
4378 unsigned long page, s_flags, lmd_flags = 0;
4379 struct page *__page;
4380 struct file_system_type *type;
4381 char *options = NULL;
4386 if (o->od_mnt != NULL)
4389 o->od_fsops = fsfilt_get_ops(mt_str(LDD_MT_LDISKFS));
4390 if (o->od_fsops == NULL) {
4391 CERROR("Can't find fsfilt_ldiskfs\n");
4395 OBD_PAGE_ALLOC(__page, CFS_ALLOC_STD);
4397 GOTO(out, rc = -ENOMEM);
4399 str = lustre_cfg_string(cfg, 2);
4400 s_flags = simple_strtoul(str, NULL, 0);
4401 str = strstr(str, ":");
4403 lmd_flags = simple_strtoul(str + 1, NULL, 0);
4404 opts = lustre_cfg_string(cfg, 3);
4405 page = (unsigned long)cfs_page_address(__page);
4406 options = (char *)page;
4409 strcat(options, "user_xattr,acl");
4411 strcat(options, opts);
4413 /* Glom up mount options */
4414 if (*options != '\0')
4415 strcat(options, ",");
4416 strlcat(options, "no_mbcache", CFS_PAGE_SIZE);
4418 type = get_fs_type("ldiskfs");
4420 CERROR("%s: cannot find ldiskfs module\n", name);
4421 GOTO(out, rc = -ENODEV);
4424 o->od_mnt = vfs_kern_mount(type, s_flags, dev, options);
4425 cfs_module_put(type->owner);
4427 if (IS_ERR(o->od_mnt)) {
4428 rc = PTR_ERR(o->od_mnt);
4429 CERROR("%s: can't mount %s: %d\n", name, dev, rc);
4434 if (lvfs_check_rdonly(o->od_mnt->mnt_sb->s_bdev)) {
4435 CERROR("%s: underlying device %s is marked as read-only. "
4436 "Setup failed\n", name, dev);
4439 GOTO(out, rc = -EROFS);
4442 if (!LDISKFS_HAS_COMPAT_FEATURE(o->od_mnt->mnt_sb,
4443 LDISKFS_FEATURE_COMPAT_HAS_JOURNAL)) {
4444 CERROR("%s: device %s is mounted w/o journal\n", name, dev);
4447 GOTO(out, rc = -EINVAL);
4450 if (lmd_flags & LMD_FLG_IAM) {
4452 LCONSOLE_WARN("%s: OSD: IAM mode enabled\n", name);
4455 if (lmd_flags & LMD_FLG_NOSCRUB)
4460 OBD_PAGE_FREE(__page);
4462 fsfilt_put_ops(o->od_fsops);
4467 static struct lu_device *osd_device_fini(const struct lu_env *env,
4468 struct lu_device *d)
4473 rc = osd_shutdown(env, osd_dev(d));
4475 osd_compat_fini(osd_dev(d));
4477 shrink_dcache_sb(osd_sb(osd_dev(d)));
4478 osd_sync(env, lu2dt_dev(d));
4480 rc = osd_procfs_fini(osd_dev(d));
4482 CERROR("proc fini error %d \n", rc);
4483 RETURN (ERR_PTR(rc));
4486 if (osd_dev(d)->od_mnt) {
4487 mntput(osd_dev(d)->od_mnt);
4488 osd_dev(d)->od_mnt = NULL;
4494 static int osd_device_init0(const struct lu_env *env,
4495 struct osd_device *o,
4496 struct lustre_cfg *cfg)
4498 struct lu_device *l = osd2lu_dev(o);
4499 struct osd_thread_info *info;
4502 /* if the module was re-loaded, env can loose its keys */
4503 rc = lu_env_refill((struct lu_env *) env);
4506 info = osd_oti_get(env);
4509 l->ld_ops = &osd_lu_ops;
4510 o->od_dt_dev.dd_ops = &osd_dt_ops;
4512 cfs_spin_lock_init(&o->od_osfs_lock);
4513 cfs_mutex_init(&o->od_otable_mutex);
4514 o->od_osfs_age = cfs_time_shift_64(-1000);
4516 o->od_capa_hash = init_capa_hash();
4517 if (o->od_capa_hash == NULL)
4518 GOTO(out, rc = -ENOMEM);
4520 o->od_read_cache = 1;
4521 o->od_writethrough_cache = 1;
4522 o->od_readcache_max_filesize = OSD_MAX_CACHE_SIZE;
4524 rc = osd_mount(env, o, cfg);
4528 /* setup scrub, including OI files initialization */
4529 rc = osd_scrub_setup(env, o);
4533 strncpy(o->od_svname, lustre_cfg_string(cfg, 4),
4534 sizeof(o->od_svname) - 1);
4536 rc = osd_compat_init(o);
4538 GOTO(out_scrub, rc);
4540 rc = lu_site_init(&o->od_site, l);
4542 GOTO(out_compat, rc);
4543 o->od_site.ls_bottom_dev = l;
4545 rc = lu_site_init_finish(&o->od_site);
4549 rc = osd_procfs_init(o, o->od_svname);
4551 CERROR("%s: can't initialize procfs: rc = %d\n",
4556 LASSERT(l->ld_site->ls_linkage.next && l->ld_site->ls_linkage.prev);
4558 /* initialize quota slave instance */
4559 o->od_quota_slave = qsd_init(env, o->od_svname, &o->od_dt_dev,
4561 if (IS_ERR(o->od_quota_slave)) {
4562 rc = PTR_ERR(o->od_quota_slave);
4563 o->od_quota_slave = NULL;
4564 GOTO(out_procfs, rc);
4571 lu_site_fini(&o->od_site);
4575 osd_scrub_cleanup(env, o);
4577 osd_oi_fini(info, o);
4578 osd_shutdown(env, o);
4582 cleanup_capa_hash(o->od_capa_hash);
4587 static struct lu_device *osd_device_alloc(const struct lu_env *env,
4588 struct lu_device_type *t,
4589 struct lustre_cfg *cfg)
4591 struct osd_device *o;
4596 return ERR_PTR(-ENOMEM);
4598 rc = dt_device_init(&o->od_dt_dev, t);
4600 rc = osd_device_init0(env, o, cfg);
4602 dt_device_fini(&o->od_dt_dev);
4605 if (unlikely(rc != 0))
4608 return rc == 0 ? osd2lu_dev(o) : ERR_PTR(rc);
4611 static struct lu_device *osd_device_free(const struct lu_env *env,
4612 struct lu_device *d)
4614 struct osd_device *o = osd_dev(d);
4617 cleanup_capa_hash(o->od_capa_hash);
4618 /* XXX: make osd top device in order to release reference */
4619 d->ld_site->ls_top_dev = d;
4620 lu_site_purge(env, d->ld_site, -1);
4621 if (!cfs_hash_is_empty(d->ld_site->ls_obj_hash)) {
4622 LIBCFS_DEBUG_MSG_DATA_DECL(msgdata, D_ERROR, NULL);
4623 lu_site_print(env, d->ld_site, &msgdata, lu_cdebug_printer);
4625 lu_site_fini(&o->od_site);
4626 dt_device_fini(&o->od_dt_dev);
4631 static int osd_process_config(const struct lu_env *env,
4632 struct lu_device *d, struct lustre_cfg *cfg)
4634 struct osd_device *o = osd_dev(d);
4638 switch(cfg->lcfg_command) {
4640 err = osd_mount(env, o, cfg);
4643 lu_dev_del_linkage(d->ld_site, d);
4644 err = osd_shutdown(env, o);
4653 static int osd_recovery_complete(const struct lu_env *env,
4654 struct lu_device *d)
4656 struct osd_device *osd = osd_dev(d);
4660 if (osd->od_quota_slave == NULL)
4663 /* start qsd instance on recovery completion, this notifies the quota
4664 * slave code that we are about to process new requests now */
4665 rc = qsd_start(env, osd->od_quota_slave);
4670 * we use exports to track all osd users
4672 static int osd_obd_connect(const struct lu_env *env, struct obd_export **exp,
4673 struct obd_device *obd, struct obd_uuid *cluuid,
4674 struct obd_connect_data *data, void *localdata)
4676 struct osd_device *osd = osd_dev(obd->obd_lu_dev);
4677 struct lustre_handle conn;
4681 CDEBUG(D_CONFIG, "connect #%d\n", osd->od_connects);
4683 rc = class_connect(&conn, obd, cluuid);
4687 *exp = class_conn2export(&conn);
4689 cfs_spin_lock(&osd->od_osfs_lock);
4691 cfs_spin_unlock(&osd->od_osfs_lock);
4697 * once last export (we don't count self-export) disappeared
4698 * osd can be released
4700 static int osd_obd_disconnect(struct obd_export *exp)
4702 struct obd_device *obd = exp->exp_obd;
4703 struct osd_device *osd = osd_dev(obd->obd_lu_dev);
4704 int rc, release = 0;
4707 /* Only disconnect the underlying layers on the final disconnect. */
4708 cfs_spin_lock(&osd->od_osfs_lock);
4710 if (osd->od_connects == 0)
4712 cfs_spin_unlock(&osd->od_osfs_lock);
4714 rc = class_disconnect(exp); /* bz 9811 */
4716 if (rc == 0 && release)
4717 class_manual_cleanup(obd);
4721 static int osd_prepare(const struct lu_env *env, struct lu_device *pdev,
4722 struct lu_device *dev)
4724 struct osd_device *osd = osd_dev(dev);
4728 if (dev->ld_site && lu_device_is_md(dev->ld_site->ls_top_dev)) {
4729 /* MDT/MDD still use old infrastructure to create
4731 result = llo_local_objects_setup(env, lu2md_dev(pdev),
4737 if (osd->od_quota_slave != NULL)
4738 /* set up quota slave objects */
4739 result = qsd_prepare(env, osd->od_quota_slave);
4744 static const struct lu_object_operations osd_lu_obj_ops = {
4745 .loo_object_init = osd_object_init,
4746 .loo_object_delete = osd_object_delete,
4747 .loo_object_release = osd_object_release,
4748 .loo_object_free = osd_object_free,
4749 .loo_object_print = osd_object_print,
4750 .loo_object_invariant = osd_object_invariant
4753 const struct lu_device_operations osd_lu_ops = {
4754 .ldo_object_alloc = osd_object_alloc,
4755 .ldo_process_config = osd_process_config,
4756 .ldo_recovery_complete = osd_recovery_complete,
4757 .ldo_prepare = osd_prepare,
4760 static const struct lu_device_type_operations osd_device_type_ops = {
4761 .ldto_init = osd_type_init,
4762 .ldto_fini = osd_type_fini,
4764 .ldto_start = osd_type_start,
4765 .ldto_stop = osd_type_stop,
4767 .ldto_device_alloc = osd_device_alloc,
4768 .ldto_device_free = osd_device_free,
4770 .ldto_device_init = osd_device_init,
4771 .ldto_device_fini = osd_device_fini
4774 struct lu_device_type osd_device_type = {
4775 .ldt_tags = LU_DEVICE_DT,
4776 .ldt_name = LUSTRE_OSD_LDISKFS_NAME,
4777 .ldt_ops = &osd_device_type_ops,
4778 .ldt_ctx_tags = LCT_LOCAL,
4782 * lprocfs legacy support.
4784 static struct obd_ops osd_obd_device_ops = {
4785 .o_owner = THIS_MODULE,
4786 .o_connect = osd_obd_connect,
4787 .o_disconnect = osd_obd_disconnect
4790 static int __init osd_mod_init(void)
4792 struct lprocfs_static_vars lvars;
4795 lprocfs_osd_init_vars(&lvars);
4796 return class_register_type(&osd_obd_device_ops, NULL, lvars.module_vars,
4797 LUSTRE_OSD_LDISKFS_NAME, &osd_device_type);
4800 static void __exit osd_mod_exit(void)
4802 class_unregister_type(LUSTRE_OSD_LDISKFS_NAME);
4805 MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");
4806 MODULE_DESCRIPTION("Lustre Object Storage Device ("LUSTRE_OSD_LDISKFS_NAME")");
4807 MODULE_LICENSE("GPL");
4809 cfs_module(osd, "0.1.0", osd_mod_init, osd_mod_exit);