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, Intel Corporation.
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>
78 CFS_MODULE_PARM(ldiskfs_pdo, "i", int, 0644,
79 "ldiskfs with parallel directory operations");
81 static const char dot[] = ".";
82 static const char dotdot[] = "..";
83 static const char remote_obj_dir[] = "REM_OBJ_DIR";
85 static const struct lu_object_operations osd_lu_obj_ops;
86 static const struct dt_object_operations osd_obj_ops;
87 static const struct dt_object_operations osd_obj_ea_ops;
88 static const struct dt_object_operations osd_obj_otable_it_ops;
89 static const struct dt_index_operations osd_index_iam_ops;
90 static const struct dt_index_operations osd_index_ea_ops;
92 static int osd_has_index(const struct osd_object *obj)
94 return obj->oo_dt.do_index_ops != NULL;
97 static int osd_object_invariant(const struct lu_object *l)
99 return osd_invariant(osd_obj(l));
103 * Concurrency: doesn't matter
105 static int osd_read_locked(const struct lu_env *env, struct osd_object *o)
107 return osd_oti_get(env)->oti_r_locks > 0;
111 * Concurrency: doesn't matter
113 static int osd_write_locked(const struct lu_env *env, struct osd_object *o)
115 struct osd_thread_info *oti = osd_oti_get(env);
116 return oti->oti_w_locks > 0 && o->oo_owner == env;
120 * Concurrency: doesn't access mutable data
122 static int osd_root_get(const struct lu_env *env,
123 struct dt_device *dev, struct lu_fid *f)
125 lu_local_obj_fid(f, OSD_FS_ROOT_OID);
130 * OSD object methods.
134 * Concurrency: no concurrent access is possible that early in object
137 static struct lu_object *osd_object_alloc(const struct lu_env *env,
138 const struct lu_object_header *hdr,
141 struct osd_object *mo;
147 l = &mo->oo_dt.do_lu;
148 dt_object_init(&mo->oo_dt, NULL, d);
149 mo->oo_dt.do_ops = &osd_obj_ea_ops;
150 l->lo_ops = &osd_lu_obj_ops;
151 init_rwsem(&mo->oo_sem);
152 init_rwsem(&mo->oo_ext_idx_sem);
153 spin_lock_init(&mo->oo_guard);
160 static int osd_get_lma(struct osd_thread_info *info, struct inode *inode,
161 struct dentry *dentry, struct lustre_mdt_attrs *lma)
165 dentry->d_inode = inode;
166 rc = inode->i_op->getxattr(dentry, XATTR_NAME_LMA, (void *)lma,
169 /* try with old lma size */
170 rc = inode->i_op->getxattr(dentry, XATTR_NAME_LMA,
171 info->oti_mdt_attrs_old,
174 memcpy(lma, info->oti_mdt_attrs_old, sizeof(*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(info, 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(info, 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));
401 obj->oo_compat_dot_created = 1;
402 obj->oo_compat_dotdot_created = 1;
404 if (!S_ISDIR(inode->i_mode) || !ldiskfs_pdo) /* done */
405 GOTO(out, result = 0);
407 LASSERT(obj->oo_hl_head == NULL);
408 obj->oo_hl_head = ldiskfs_htree_lock_head_alloc(HTREE_HBITS_DEF);
409 if (obj->oo_hl_head == NULL) {
410 obj->oo_inode = NULL;
412 GOTO(out, result = -ENOMEM);
414 GOTO(out, result = 0);
417 LINVRNT(osd_invariant(obj));
422 * Concurrency: shouldn't matter.
424 static void osd_object_init0(struct osd_object *obj)
426 LASSERT(obj->oo_inode != NULL);
427 obj->oo_dt.do_body_ops = &osd_body_ops;
428 obj->oo_dt.do_lu.lo_header->loh_attr |=
429 (LOHA_EXISTS | (obj->oo_inode->i_mode & S_IFMT));
433 * Concurrency: no concurrent access is possible that early in object
436 static int osd_object_init(const struct lu_env *env, struct lu_object *l,
437 const struct lu_object_conf *conf)
439 struct osd_object *obj = osd_obj(l);
442 LINVRNT(osd_invariant(obj));
444 result = osd_fid_lookup(env, obj, lu_object_fid(l), conf);
445 obj->oo_dt.do_body_ops = &osd_body_ops_new;
447 if (obj->oo_inode != NULL) {
448 osd_object_init0(obj);
449 } else if (fid_is_otable_it(&l->lo_header->loh_fid)) {
450 obj->oo_dt.do_ops = &osd_obj_otable_it_ops;
451 /* LFSCK iterator object is special without inode */
452 l->lo_header->loh_attr |= LOHA_EXISTS;
455 LINVRNT(osd_invariant(obj));
460 * Concurrency: no concurrent access is possible that late in object
463 static void osd_object_free(const struct lu_env *env, struct lu_object *l)
465 struct osd_object *obj = osd_obj(l);
467 LINVRNT(osd_invariant(obj));
469 dt_object_fini(&obj->oo_dt);
470 if (obj->oo_hl_head != NULL)
471 ldiskfs_htree_lock_head_free(obj->oo_hl_head);
476 * Concurrency: no concurrent access is possible that late in object
479 static void osd_index_fini(struct osd_object *o)
481 struct iam_container *bag;
483 if (o->oo_dir != NULL) {
484 bag = &o->oo_dir->od_container;
485 if (o->oo_inode != NULL) {
486 if (bag->ic_object == o->oo_inode)
487 iam_container_fini(bag);
489 OBD_FREE_PTR(o->oo_dir);
495 * Concurrency: no concurrent access is possible that late in object
496 * life-cycle (for all existing callers, that is. New callers have to provide
497 * their own locking.)
499 static int osd_inode_unlinked(const struct inode *inode)
501 return inode->i_nlink == 0;
505 OSD_TXN_OI_DELETE_CREDITS = 20,
506 OSD_TXN_INODE_DELETE_CREDITS = 20
513 #if OSD_THANDLE_STATS
515 * Set time when the handle is allocated
517 static void osd_th_alloced(struct osd_thandle *oth)
519 oth->oth_alloced = cfs_time_current();
523 * Set time when the handle started
525 static void osd_th_started(struct osd_thandle *oth)
527 oth->oth_started = cfs_time_current();
531 * Helper function to convert time interval to microseconds packed in
534 static long interval_to_usec(cfs_time_t start, cfs_time_t end)
538 cfs_duration_usec(cfs_time_sub(end, start), &val);
539 return val.tv_sec * 1000000 + val.tv_usec;
543 * Check whether the we deal with this handle for too long.
545 static void __osd_th_check_slow(void *oth, struct osd_device *dev,
546 cfs_time_t alloced, cfs_time_t started,
549 cfs_time_t now = cfs_time_current();
551 LASSERT(dev != NULL);
553 lprocfs_counter_add(dev->od_stats, LPROC_OSD_THANDLE_STARTING,
554 interval_to_usec(alloced, started));
555 lprocfs_counter_add(dev->od_stats, LPROC_OSD_THANDLE_OPEN,
556 interval_to_usec(started, closed));
557 lprocfs_counter_add(dev->od_stats, LPROC_OSD_THANDLE_CLOSING,
558 interval_to_usec(closed, now));
560 if (cfs_time_before(cfs_time_add(alloced, cfs_time_seconds(30)), now)) {
561 CWARN("transaction handle %p was open for too long: "
563 "alloced "CFS_TIME_T" ,"
564 "started "CFS_TIME_T" ,"
565 "closed "CFS_TIME_T"\n",
566 oth, now, alloced, started, closed);
567 libcfs_debug_dumpstack(NULL);
571 #define OSD_CHECK_SLOW_TH(oth, dev, expr) \
573 cfs_time_t __closed = cfs_time_current(); \
574 cfs_time_t __alloced = oth->oth_alloced; \
575 cfs_time_t __started = oth->oth_started; \
578 __osd_th_check_slow(oth, dev, __alloced, __started, __closed); \
581 #else /* OSD_THANDLE_STATS */
583 #define osd_th_alloced(h) do {} while(0)
584 #define osd_th_started(h) do {} while(0)
585 #define OSD_CHECK_SLOW_TH(oth, dev, expr) expr
587 #endif /* OSD_THANDLE_STATS */
590 * Concurrency: doesn't access mutable data.
592 static int osd_param_is_not_sane(const struct osd_device *dev,
593 const struct thandle *th)
595 struct osd_thandle *oh = container_of(th, typeof(*oh), ot_super);
597 return oh->ot_credits > osd_journal(dev)->j_max_transaction_buffers;
601 * Concurrency: shouldn't matter.
603 #ifdef HAVE_LDISKFS_JOURNAL_CALLBACK_ADD
604 static void osd_trans_commit_cb(struct super_block *sb,
605 struct journal_callback *jcb, int error)
607 static void osd_trans_commit_cb(struct journal_callback *jcb, int error)
610 struct osd_thandle *oh = container_of0(jcb, struct osd_thandle, ot_jcb);
611 struct thandle *th = &oh->ot_super;
612 struct lu_device *lud = &th->th_dev->dd_lu_dev;
613 struct dt_txn_commit_cb *dcb, *tmp;
615 LASSERT(oh->ot_handle == NULL);
618 CERROR("transaction @0x%p commit error: %d\n", th, error);
620 dt_txn_hook_commit(th);
622 /* call per-transaction callbacks if any */
623 cfs_list_for_each_entry_safe(dcb, tmp, &oh->ot_dcb_list, dcb_linkage) {
624 LASSERTF(dcb->dcb_magic == TRANS_COMMIT_CB_MAGIC,
625 "commit callback entry: magic=%x name='%s'\n",
626 dcb->dcb_magic, dcb->dcb_name);
627 cfs_list_del_init(&dcb->dcb_linkage);
628 dcb->dcb_func(NULL, th, dcb, error);
631 lu_ref_del_at(&lud->ld_reference, oh->ot_dev_link, "osd-tx", th);
635 lu_context_exit(&th->th_ctx);
636 lu_context_fini(&th->th_ctx);
640 static struct thandle *osd_trans_create(const struct lu_env *env,
643 struct osd_thread_info *oti = osd_oti_get(env);
644 struct osd_iobuf *iobuf = &oti->oti_iobuf;
645 struct osd_thandle *oh;
649 /* on pending IO in this thread should left from prev. request */
650 LASSERT(cfs_atomic_read(&iobuf->dr_numreqs) == 0);
652 th = ERR_PTR(-ENOMEM);
653 OBD_ALLOC_GFP(oh, sizeof *oh, CFS_ALLOC_IO);
655 oh->ot_quota_trans = &oti->oti_quota_trans;
656 memset(oh->ot_quota_trans, 0, sizeof(*oh->ot_quota_trans));
660 th->th_tags = LCT_TX_HANDLE;
662 oti->oti_dev = osd_dt_dev(d);
663 CFS_INIT_LIST_HEAD(&oh->ot_dcb_list);
670 * Concurrency: shouldn't matter.
672 int osd_trans_start(const struct lu_env *env, struct dt_device *d,
675 struct osd_thread_info *oti = osd_oti_get(env);
676 struct osd_device *dev = osd_dt_dev(d);
678 struct osd_thandle *oh;
683 LASSERT(current->journal_info == NULL);
685 oh = container_of0(th, struct osd_thandle, ot_super);
687 LASSERT(oh->ot_handle == NULL);
689 rc = dt_txn_hook_start(env, d, th);
693 if (unlikely(osd_param_is_not_sane(dev, th))) {
694 static unsigned long last_printed;
695 static int last_credits;
697 CWARN("%.16s: too many transaction credits (%d > %d)\n",
698 LDISKFS_SB(osd_sb(dev))->s_es->s_volume_name,
700 osd_journal(dev)->j_max_transaction_buffers);
701 #ifdef OSD_TRACK_DECLARES
702 CWARN(" create: %u/%u, delete: %u/%u, destroy: %u/%u\n",
703 oh->ot_declare_create, oh->ot_declare_create_cred,
704 oh->ot_declare_delete, oh->ot_declare_delete_cred,
705 oh->ot_declare_destroy, oh->ot_declare_destroy_cred);
706 CWARN(" attr_set: %u/%u, xattr_set: %u/%u\n",
707 oh->ot_declare_attr_set, oh->ot_declare_attr_set_cred,
708 oh->ot_declare_xattr_set, oh->ot_declare_xattr_set_cred);
709 CWARN(" write: %u/%u, punch: %u/%u, quota %u/%u\n",
710 oh->ot_declare_write, oh->ot_declare_write_cred,
711 oh->ot_declare_punch, oh->ot_declare_punch_cred,
712 oh->ot_declare_quota, oh->ot_declare_quota_cred);
713 CWARN(" insert: %u/%u, delete: %u/%u\n",
714 oh->ot_declare_insert, oh->ot_declare_insert_cred,
715 oh->ot_declare_delete, oh->ot_declare_destroy_cred);
716 CWARN(" ref_add: %u/%u, ref_del: %u/%u\n",
717 oh->ot_declare_ref_add, oh->ot_declare_ref_add_cred,
718 oh->ot_declare_ref_del, oh->ot_declare_ref_del_cred);
720 if (last_credits != oh->ot_credits &&
721 time_after(jiffies, last_printed + 60 * HZ)) {
722 libcfs_debug_dumpstack(NULL);
723 last_credits = oh->ot_credits;
724 last_printed = jiffies;
727 /* XXX Limit the credits to 'max_transaction_buffers', and
728 * let the underlying filesystem to catch the error if
729 * we really need so many credits.
731 * This should be removed when we can calculate the
732 * credits precisely. */
733 oh->ot_credits = osd_journal(dev)->j_max_transaction_buffers;
737 * XXX temporary stuff. Some abstraction layer should
740 jh = ldiskfs_journal_start_sb(osd_sb(dev), oh->ot_credits);
744 LASSERT(oti->oti_txns == 0);
745 lu_context_init(&th->th_ctx, th->th_tags);
746 lu_context_enter(&th->th_ctx);
748 lu_device_get(&d->dd_lu_dev);
749 oh->ot_dev_link = lu_ref_add(&d->dd_lu_dev.ld_reference,
761 * Concurrency: shouldn't matter.
763 static int osd_trans_stop(const struct lu_env *env, struct thandle *th)
766 struct osd_thandle *oh;
767 struct osd_thread_info *oti = osd_oti_get(env);
768 struct osd_iobuf *iobuf = &oti->oti_iobuf;
769 struct qsd_instance *qsd = oti->oti_dev->od_quota_slave;
772 oh = container_of0(th, struct osd_thandle, ot_super);
775 /* inform the quota slave device that the transaction is
777 qsd_op_end(env, qsd, oh->ot_quota_trans);
778 oh->ot_quota_trans = NULL;
780 if (oh->ot_handle != NULL) {
781 handle_t *hdl = oh->ot_handle;
784 * add commit callback
785 * notice we don't do this in osd_trans_start()
786 * as underlying transaction can change during truncate
788 osd_journal_callback_set(hdl, osd_trans_commit_cb,
791 LASSERT(oti->oti_txns == 1);
793 rc = dt_txn_hook_stop(env, th);
795 CERROR("Failure in transaction hook: %d\n", rc);
797 /* hook functions might modify th_sync */
798 hdl->h_sync = th->th_sync;
800 oh->ot_handle = NULL;
801 OSD_CHECK_SLOW_TH(oh, oti->oti_dev,
802 rc = ldiskfs_journal_stop(hdl));
804 CERROR("Failure to stop transaction: %d\n", rc);
809 /* as we want IO to journal and data IO be concurrent, we don't block
810 * awaiting data IO completion in osd_do_bio(), instead we wait here
811 * once transaction is submitted to the journal. all reqular requests
812 * don't do direct IO (except read/write), thus this wait_event becomes
815 * IMPORTANT: we have to wait till any IO submited by the thread is
816 * completed otherwise iobuf may be corrupted by different request
818 cfs_wait_event(iobuf->dr_wait,
819 cfs_atomic_read(&iobuf->dr_numreqs) == 0);
821 rc = iobuf->dr_error;
826 static int osd_trans_cb_add(struct thandle *th, struct dt_txn_commit_cb *dcb)
828 struct osd_thandle *oh = container_of0(th, struct osd_thandle,
831 LASSERT(dcb->dcb_magic == TRANS_COMMIT_CB_MAGIC);
832 LASSERT(&dcb->dcb_func != NULL);
833 cfs_list_add(&dcb->dcb_linkage, &oh->ot_dcb_list);
839 * Called just before object is freed. Releases all resources except for
840 * object itself (that is released by osd_object_free()).
842 * Concurrency: no concurrent access is possible that late in object
845 static void osd_object_delete(const struct lu_env *env, struct lu_object *l)
847 struct osd_object *obj = osd_obj(l);
848 struct inode *inode = obj->oo_inode;
850 LINVRNT(osd_invariant(obj));
853 * If object is unlinked remove fid->ino mapping from object index.
858 struct qsd_instance *qsd = osd_obj2dev(obj)->od_quota_slave;
859 qid_t uid = inode->i_uid;
860 qid_t gid = inode->i_gid;
863 obj->oo_inode = NULL;
866 struct osd_thread_info *info = osd_oti_get(env);
867 struct lquota_id_info *qi = &info->oti_qi;
869 /* Release granted quota to master if necessary */
870 qi->lqi_id.qid_uid = uid;
871 qsd_op_adjust(env, qsd, &qi->lqi_id, USRQUOTA);
873 qi->lqi_id.qid_uid = gid;
874 qsd_op_adjust(env, qsd, &qi->lqi_id, GRPQUOTA);
880 * Concurrency: ->loo_object_release() is called under site spin-lock.
882 static void osd_object_release(const struct lu_env *env,
888 * Concurrency: shouldn't matter.
890 static int osd_object_print(const struct lu_env *env, void *cookie,
891 lu_printer_t p, const struct lu_object *l)
893 struct osd_object *o = osd_obj(l);
896 if (o->oo_dir != NULL)
897 d = o->oo_dir->od_container.ic_descr;
900 return (*p)(env, cookie,
901 LUSTRE_OSD_LDISKFS_NAME"-object@%p(i:%p:%lu/%u)[%s]",
903 o->oo_inode ? o->oo_inode->i_ino : 0UL,
904 o->oo_inode ? o->oo_inode->i_generation : 0,
905 d ? d->id_ops->id_name : "plain");
909 * Concurrency: shouldn't matter.
911 int osd_statfs(const struct lu_env *env, struct dt_device *d,
912 struct obd_statfs *sfs)
914 struct osd_device *osd = osd_dt_dev(d);
915 struct super_block *sb = osd_sb(osd);
916 struct kstatfs *ksfs;
919 if (unlikely(osd->od_mnt == NULL))
922 /* osd_lproc.c call this without env, allocate ksfs for that case */
923 if (unlikely(env == NULL)) {
928 ksfs = &osd_oti_get(env)->oti_ksfs;
931 spin_lock(&osd->od_osfs_lock);
933 if (cfs_time_before_64(osd->od_osfs_age, cfs_time_shift_64(-1))) {
934 result = sb->s_op->statfs(sb->s_root, ksfs);
935 if (likely(result == 0)) { /* N.B. statfs can't really fail */
936 osd->od_osfs_age = cfs_time_current_64();
937 statfs_pack(&osd->od_statfs, ksfs);
938 if (sb->s_flags & MS_RDONLY)
939 sfs->os_state = OS_STATE_READONLY;
943 if (likely(result == 0))
944 *sfs = osd->od_statfs;
945 spin_unlock(&osd->od_osfs_lock);
947 if (unlikely(env == NULL))
954 * Estimate space needed for file creations. We assume the largest filename
955 * which is 2^64 - 1, hence a filename of 20 chars.
956 * This is 28 bytes per object which is 28MB for 1M objects ... no so bad.
958 #ifdef __LDISKFS_DIR_REC_LEN
959 #define PER_OBJ_USAGE __LDISKFS_DIR_REC_LEN(20)
961 #define PER_OBJ_USAGE LDISKFS_DIR_REC_LEN(20)
965 * Concurrency: doesn't access mutable data.
967 static void osd_conf_get(const struct lu_env *env,
968 const struct dt_device *dev,
969 struct dt_device_param *param)
971 struct super_block *sb = osd_sb(osd_dt_dev(dev));
974 * XXX should be taken from not-yet-existing fs abstraction layer.
976 param->ddp_mnt = osd_dt_dev(dev)->od_mnt;
977 param->ddp_max_name_len = LDISKFS_NAME_LEN;
978 param->ddp_max_nlink = LDISKFS_LINK_MAX;
979 param->ddp_block_shift = sb->s_blocksize_bits;
980 param->ddp_mount_type = LDD_MT_LDISKFS;
981 param->ddp_maxbytes = sb->s_maxbytes;
982 /* Overhead estimate should be fairly accurate, so we really take a tiny
983 * error margin which also avoids fragmenting the filesystem too much */
984 param->ddp_grant_reserved = 2; /* end up to be 1.9% after conversion */
985 /* inode are statically allocated, so per-inode space consumption
986 * is the space consumed by the directory entry */
987 param->ddp_inodespace = PER_OBJ_USAGE;
988 /* per-fragment overhead to be used by the client code */
989 param->ddp_grant_frag = 6 * LDISKFS_BLOCK_SIZE(sb);
990 param->ddp_mntopts = 0;
991 if (test_opt(sb, XATTR_USER))
992 param->ddp_mntopts |= MNTOPT_USERXATTR;
993 if (test_opt(sb, POSIX_ACL))
994 param->ddp_mntopts |= MNTOPT_ACL;
996 #if defined(LDISKFS_FEATURE_INCOMPAT_EA_INODE)
997 if (LDISKFS_HAS_INCOMPAT_FEATURE(sb, LDISKFS_FEATURE_INCOMPAT_EA_INODE))
998 param->ddp_max_ea_size = LDISKFS_XATTR_MAX_LARGE_EA_SIZE;
1001 param->ddp_max_ea_size = sb->s_blocksize;
1006 * Helper function to get and fill the buffer with input values.
1008 static struct lu_buf *osd_buf_get(const struct lu_env *env, void *area, ssize_t len)
1012 buf = &osd_oti_get(env)->oti_buf;
1019 * Concurrency: shouldn't matter.
1021 static int osd_sync(const struct lu_env *env, struct dt_device *d)
1023 CDEBUG(D_HA, "syncing OSD %s\n", LUSTRE_OSD_LDISKFS_NAME);
1024 return ldiskfs_force_commit(osd_sb(osd_dt_dev(d)));
1028 * Start commit for OSD device.
1030 * An implementation of dt_commit_async method for OSD device.
1031 * Asychronously starts underlayng fs sync and thereby a transaction
1034 * \param env environment
1035 * \param d dt device
1037 * \see dt_device_operations
1039 static int osd_commit_async(const struct lu_env *env,
1040 struct dt_device *d)
1042 struct super_block *s = osd_sb(osd_dt_dev(d));
1045 CDEBUG(D_HA, "async commit OSD %s\n", LUSTRE_OSD_LDISKFS_NAME);
1046 RETURN(s->s_op->sync_fs(s, 0));
1050 * Concurrency: shouldn't matter.
1053 static int osd_ro(const struct lu_env *env, struct dt_device *d)
1055 struct super_block *sb = osd_sb(osd_dt_dev(d));
1059 CERROR("*** setting %s read-only ***\n", osd_dt_dev(d)->od_svname);
1061 rc = __lvfs_set_rdonly(sb->s_bdev, LDISKFS_SB(sb)->journal_bdev);
1066 * Concurrency: serialization provided by callers.
1068 static int osd_init_capa_ctxt(const struct lu_env *env, struct dt_device *d,
1069 int mode, unsigned long timeout, __u32 alg,
1070 struct lustre_capa_key *keys)
1072 struct osd_device *dev = osd_dt_dev(d);
1075 dev->od_fl_capa = mode;
1076 dev->od_capa_timeout = timeout;
1077 dev->od_capa_alg = alg;
1078 dev->od_capa_keys = keys;
1083 * Note: we do not count into QUOTA here.
1084 * If we mount with --data_journal we may need more.
1086 const int osd_dto_credits_noquota[DTO_NR] = {
1089 * INDEX_EXTRA_TRANS_BLOCKS(8) +
1090 * SINGLEDATA_TRANS_BLOCKS(8)
1091 * XXX Note: maybe iam need more, since iam have more level than
1094 [DTO_INDEX_INSERT] = 16,
1095 [DTO_INDEX_DELETE] = 16,
1099 [DTO_INDEX_UPDATE] = 16,
1101 * Create a object. The same as create object in EXT3.
1102 * DATA_TRANS_BLOCKS(14) +
1103 * INDEX_EXTRA_BLOCKS(8) +
1104 * 3(inode bits, groups, GDT)
1106 [DTO_OBJECT_CREATE] = 25,
1108 * XXX: real credits to be fixed
1110 [DTO_OBJECT_DELETE] = 25,
1112 * Attr set credits (inode)
1114 [DTO_ATTR_SET_BASE] = 1,
1116 * Xattr set. The same as xattr of EXT3.
1117 * DATA_TRANS_BLOCKS(14)
1118 * XXX Note: in original MDS implmentation INDEX_EXTRA_TRANS_BLOCKS
1119 * are also counted in. Do not know why?
1121 [DTO_XATTR_SET] = 14,
1124 * credits for inode change during write.
1126 [DTO_WRITE_BASE] = 3,
1128 * credits for single block write.
1130 [DTO_WRITE_BLOCK] = 14,
1132 * Attr set credits for chown.
1133 * This is extra credits for setattr, and it is null without quota
1135 [DTO_ATTR_SET_CHOWN]= 0
1138 static const struct dt_device_operations osd_dt_ops = {
1139 .dt_root_get = osd_root_get,
1140 .dt_statfs = osd_statfs,
1141 .dt_trans_create = osd_trans_create,
1142 .dt_trans_start = osd_trans_start,
1143 .dt_trans_stop = osd_trans_stop,
1144 .dt_trans_cb_add = osd_trans_cb_add,
1145 .dt_conf_get = osd_conf_get,
1146 .dt_sync = osd_sync,
1148 .dt_commit_async = osd_commit_async,
1149 .dt_init_capa_ctxt = osd_init_capa_ctxt,
1152 static void osd_object_read_lock(const struct lu_env *env,
1153 struct dt_object *dt, unsigned role)
1155 struct osd_object *obj = osd_dt_obj(dt);
1156 struct osd_thread_info *oti = osd_oti_get(env);
1158 LINVRNT(osd_invariant(obj));
1160 LASSERT(obj->oo_owner != env);
1161 down_read_nested(&obj->oo_sem, role);
1163 LASSERT(obj->oo_owner == NULL);
1167 static void osd_object_write_lock(const struct lu_env *env,
1168 struct dt_object *dt, unsigned role)
1170 struct osd_object *obj = osd_dt_obj(dt);
1171 struct osd_thread_info *oti = osd_oti_get(env);
1173 LINVRNT(osd_invariant(obj));
1175 LASSERT(obj->oo_owner != env);
1176 down_write_nested(&obj->oo_sem, role);
1178 LASSERT(obj->oo_owner == NULL);
1179 obj->oo_owner = env;
1183 static void osd_object_read_unlock(const struct lu_env *env,
1184 struct dt_object *dt)
1186 struct osd_object *obj = osd_dt_obj(dt);
1187 struct osd_thread_info *oti = osd_oti_get(env);
1189 LINVRNT(osd_invariant(obj));
1191 LASSERT(oti->oti_r_locks > 0);
1193 up_read(&obj->oo_sem);
1196 static void osd_object_write_unlock(const struct lu_env *env,
1197 struct dt_object *dt)
1199 struct osd_object *obj = osd_dt_obj(dt);
1200 struct osd_thread_info *oti = osd_oti_get(env);
1202 LINVRNT(osd_invariant(obj));
1204 LASSERT(obj->oo_owner == env);
1205 LASSERT(oti->oti_w_locks > 0);
1207 obj->oo_owner = NULL;
1208 up_write(&obj->oo_sem);
1211 static int osd_object_write_locked(const struct lu_env *env,
1212 struct dt_object *dt)
1214 struct osd_object *obj = osd_dt_obj(dt);
1216 LINVRNT(osd_invariant(obj));
1218 return obj->oo_owner == env;
1221 static int capa_is_sane(const struct lu_env *env,
1222 struct osd_device *dev,
1223 struct lustre_capa *capa,
1224 struct lustre_capa_key *keys)
1226 struct osd_thread_info *oti = osd_oti_get(env);
1227 struct lustre_capa *tcapa = &oti->oti_capa;
1228 struct obd_capa *oc;
1232 oc = capa_lookup(dev->od_capa_hash, capa, 0);
1234 if (capa_is_expired(oc)) {
1235 DEBUG_CAPA(D_ERROR, capa, "expired");
1242 if (capa_is_expired_sec(capa)) {
1243 DEBUG_CAPA(D_ERROR, capa, "expired");
1247 spin_lock(&capa_lock);
1248 for (i = 0; i < 2; i++) {
1249 if (keys[i].lk_keyid == capa->lc_keyid) {
1250 oti->oti_capa_key = keys[i];
1254 spin_unlock(&capa_lock);
1257 DEBUG_CAPA(D_ERROR, capa, "no matched capa key");
1261 rc = capa_hmac(tcapa->lc_hmac, capa, oti->oti_capa_key.lk_key);
1265 if (memcmp(tcapa->lc_hmac, capa->lc_hmac, sizeof(capa->lc_hmac))) {
1266 DEBUG_CAPA(D_ERROR, capa, "HMAC mismatch");
1270 oc = capa_add(dev->od_capa_hash, capa);
1276 int osd_object_auth(const struct lu_env *env, struct dt_object *dt,
1277 struct lustre_capa *capa, __u64 opc)
1279 const struct lu_fid *fid = lu_object_fid(&dt->do_lu);
1280 struct osd_device *dev = osd_dev(dt->do_lu.lo_dev);
1281 struct md_capainfo *ci;
1284 if (!dev->od_fl_capa)
1287 if (capa == BYPASS_CAPA)
1290 ci = md_capainfo(env);
1294 if (ci->mc_auth == LC_ID_NONE)
1298 CERROR("no capability is provided for fid "DFID"\n", PFID(fid));
1302 if (!lu_fid_eq(fid, &capa->lc_fid)) {
1303 DEBUG_CAPA(D_ERROR, capa, "fid "DFID" mismatch with",
1308 if (!capa_opc_supported(capa, opc)) {
1309 DEBUG_CAPA(D_ERROR, capa, "opc "LPX64" not supported by", opc);
1313 if ((rc = capa_is_sane(env, dev, capa, dev->od_capa_keys))) {
1314 DEBUG_CAPA(D_ERROR, capa, "insane (rc %d)", rc);
1321 static struct timespec *osd_inode_time(const struct lu_env *env,
1322 struct inode *inode, __u64 seconds)
1324 struct osd_thread_info *oti = osd_oti_get(env);
1325 struct timespec *t = &oti->oti_time;
1327 t->tv_sec = seconds;
1329 *t = timespec_trunc(*t, inode->i_sb->s_time_gran);
1334 static void osd_inode_getattr(const struct lu_env *env,
1335 struct inode *inode, struct lu_attr *attr)
1337 attr->la_valid |= LA_ATIME | LA_MTIME | LA_CTIME | LA_MODE |
1338 LA_SIZE | LA_BLOCKS | LA_UID | LA_GID |
1339 LA_FLAGS | LA_NLINK | LA_RDEV | LA_BLKSIZE;
1341 attr->la_atime = LTIME_S(inode->i_atime);
1342 attr->la_mtime = LTIME_S(inode->i_mtime);
1343 attr->la_ctime = LTIME_S(inode->i_ctime);
1344 attr->la_mode = inode->i_mode;
1345 attr->la_size = i_size_read(inode);
1346 attr->la_blocks = inode->i_blocks;
1347 attr->la_uid = inode->i_uid;
1348 attr->la_gid = inode->i_gid;
1349 attr->la_flags = LDISKFS_I(inode)->i_flags;
1350 attr->la_nlink = inode->i_nlink;
1351 attr->la_rdev = inode->i_rdev;
1352 attr->la_blksize = 1 << inode->i_blkbits;
1353 attr->la_blkbits = inode->i_blkbits;
1356 static int osd_attr_get(const struct lu_env *env,
1357 struct dt_object *dt,
1358 struct lu_attr *attr,
1359 struct lustre_capa *capa)
1361 struct osd_object *obj = osd_dt_obj(dt);
1363 LASSERT(dt_object_exists(dt));
1364 LINVRNT(osd_invariant(obj));
1366 if (osd_object_auth(env, dt, capa, CAPA_OPC_META_READ))
1369 spin_lock(&obj->oo_guard);
1370 osd_inode_getattr(env, obj->oo_inode, attr);
1371 spin_unlock(&obj->oo_guard);
1375 static int osd_declare_attr_set(const struct lu_env *env,
1376 struct dt_object *dt,
1377 const struct lu_attr *attr,
1378 struct thandle *handle)
1380 struct osd_thandle *oh;
1381 struct osd_object *obj;
1382 struct osd_thread_info *info = osd_oti_get(env);
1383 struct lquota_id_info *qi = &info->oti_qi;
1389 LASSERT(dt != NULL);
1390 LASSERT(handle != NULL);
1392 obj = osd_dt_obj(dt);
1393 LASSERT(osd_invariant(obj));
1395 oh = container_of0(handle, struct osd_thandle, ot_super);
1396 LASSERT(oh->ot_handle == NULL);
1398 OSD_DECLARE_OP(oh, attr_set,
1399 osd_dto_credits_noquota[DTO_ATTR_SET_BASE]);
1401 if (attr == NULL || obj->oo_inode == NULL)
1404 bspace = obj->oo_inode->i_blocks;
1405 bspace <<= obj->oo_inode->i_sb->s_blocksize_bits;
1406 bspace = toqb(bspace);
1408 /* Changing ownership is always preformed by super user, it should not
1411 * We still need to call the osd_declare_qid() to calculate the journal
1412 * credits for updating quota accounting files and to trigger quota
1413 * space adjustment once the operation is completed.*/
1414 if ((attr->la_valid & LA_UID) != 0 &&
1415 attr->la_uid != obj->oo_inode->i_uid) {
1416 qi->lqi_type = USRQUOTA;
1418 /* inode accounting */
1419 qi->lqi_is_blk = false;
1421 /* one more inode for the new owner ... */
1422 qi->lqi_id.qid_uid = attr->la_uid;
1424 allocated = (attr->la_uid == 0) ? true : false;
1425 rc = osd_declare_qid(env, oh, qi, allocated, NULL);
1426 if (rc == -EDQUOT || rc == -EINPROGRESS)
1431 /* and one less inode for the current uid */
1432 qi->lqi_id.qid_uid = obj->oo_inode->i_uid;
1434 rc = osd_declare_qid(env, oh, qi, true, NULL);
1435 if (rc == -EDQUOT || rc == -EINPROGRESS)
1440 /* block accounting */
1441 qi->lqi_is_blk = true;
1443 /* more blocks for the new owner ... */
1444 qi->lqi_id.qid_uid = attr->la_uid;
1445 qi->lqi_space = bspace;
1446 allocated = (attr->la_uid == 0) ? true : false;
1447 rc = osd_declare_qid(env, oh, qi, allocated, NULL);
1448 if (rc == -EDQUOT || rc == -EINPROGRESS)
1453 /* and finally less blocks for the current owner */
1454 qi->lqi_id.qid_uid = obj->oo_inode->i_uid;
1455 qi->lqi_space = -bspace;
1456 rc = osd_declare_qid(env, oh, qi, true, NULL);
1457 if (rc == -EDQUOT || rc == -EINPROGRESS)
1463 if (attr->la_valid & LA_GID &&
1464 attr->la_gid != obj->oo_inode->i_gid) {
1465 qi->lqi_type = GRPQUOTA;
1467 /* inode accounting */
1468 qi->lqi_is_blk = false;
1470 /* one more inode for the new group owner ... */
1471 qi->lqi_id.qid_gid = attr->la_gid;
1473 allocated = (attr->la_gid == 0) ? true : false;
1474 rc = osd_declare_qid(env, oh, qi, allocated, NULL);
1475 if (rc == -EDQUOT || rc == -EINPROGRESS)
1480 /* and one less inode for the current gid */
1481 qi->lqi_id.qid_gid = obj->oo_inode->i_gid;
1483 rc = osd_declare_qid(env, oh, qi, true, NULL);
1484 if (rc == -EDQUOT || rc == -EINPROGRESS)
1489 /* block accounting */
1490 qi->lqi_is_blk = true;
1492 /* more blocks for the new owner ... */
1493 qi->lqi_id.qid_gid = attr->la_gid;
1494 qi->lqi_space = bspace;
1495 allocated = (attr->la_gid == 0) ? true : false;
1496 rc = osd_declare_qid(env, oh, qi, allocated, NULL);
1497 if (rc == -EDQUOT || rc == -EINPROGRESS)
1502 /* and finally less blocks for the current owner */
1503 qi->lqi_id.qid_gid = obj->oo_inode->i_gid;
1504 qi->lqi_space = -bspace;
1505 rc = osd_declare_qid(env, oh, qi, true, NULL);
1506 if (rc == -EDQUOT || rc == -EINPROGRESS)
1515 static int osd_inode_setattr(const struct lu_env *env,
1516 struct inode *inode, const struct lu_attr *attr)
1520 bits = attr->la_valid;
1522 LASSERT(!(bits & LA_TYPE)); /* Huh? You want too much. */
1524 if (bits & LA_ATIME)
1525 inode->i_atime = *osd_inode_time(env, inode, attr->la_atime);
1526 if (bits & LA_CTIME)
1527 inode->i_ctime = *osd_inode_time(env, inode, attr->la_ctime);
1528 if (bits & LA_MTIME)
1529 inode->i_mtime = *osd_inode_time(env, inode, attr->la_mtime);
1530 if (bits & LA_SIZE) {
1531 LDISKFS_I(inode)->i_disksize = attr->la_size;
1532 i_size_write(inode, attr->la_size);
1536 /* OSD should not change "i_blocks" which is used by quota.
1537 * "i_blocks" should be changed by ldiskfs only. */
1538 if (bits & LA_BLOCKS)
1539 inode->i_blocks = attr->la_blocks;
1542 inode->i_mode = (inode->i_mode & S_IFMT) |
1543 (attr->la_mode & ~S_IFMT);
1545 inode->i_uid = attr->la_uid;
1547 inode->i_gid = attr->la_gid;
1548 if (bits & LA_NLINK)
1549 set_nlink(inode, attr->la_nlink);
1551 inode->i_rdev = attr->la_rdev;
1553 if (bits & LA_FLAGS) {
1554 /* always keep S_NOCMTIME */
1555 inode->i_flags = ll_ext_to_inode_flags(attr->la_flags) |
1561 static int osd_quota_transfer(struct inode *inode, const struct lu_attr *attr)
1563 if ((attr->la_valid & LA_UID && attr->la_uid != inode->i_uid) ||
1564 (attr->la_valid & LA_GID && attr->la_gid != inode->i_gid)) {
1569 if (attr->la_valid & LA_UID)
1570 iattr.ia_valid |= ATTR_UID;
1571 if (attr->la_valid & LA_GID)
1572 iattr.ia_valid |= ATTR_GID;
1573 iattr.ia_uid = attr->la_uid;
1574 iattr.ia_gid = attr->la_gid;
1576 rc = ll_vfs_dq_transfer(inode, &iattr);
1578 CERROR("%s: quota transfer failed: rc = %d. Is quota "
1579 "enforcement enabled on the ldiskfs filesystem?",
1580 inode->i_sb->s_id, rc);
1587 static int osd_attr_set(const struct lu_env *env,
1588 struct dt_object *dt,
1589 const struct lu_attr *attr,
1590 struct thandle *handle,
1591 struct lustre_capa *capa)
1593 struct osd_object *obj = osd_dt_obj(dt);
1594 struct inode *inode;
1597 LASSERT(handle != NULL);
1598 LASSERT(dt_object_exists(dt));
1599 LASSERT(osd_invariant(obj));
1601 if (osd_object_auth(env, dt, capa, CAPA_OPC_META_WRITE))
1604 OSD_EXEC_OP(handle, attr_set);
1606 inode = obj->oo_inode;
1607 ll_vfs_dq_init(inode);
1609 rc = osd_quota_transfer(inode, attr);
1613 spin_lock(&obj->oo_guard);
1614 rc = osd_inode_setattr(env, inode, attr);
1615 spin_unlock(&obj->oo_guard);
1618 inode->i_sb->s_op->dirty_inode(inode);
1622 struct dentry *osd_child_dentry_get(const struct lu_env *env,
1623 struct osd_object *obj,
1624 const char *name, const int namelen)
1626 return osd_child_dentry_by_inode(env, obj->oo_inode, name, namelen);
1629 static int osd_mkfile(struct osd_thread_info *info, struct osd_object *obj,
1631 struct dt_allocation_hint *hint,
1635 struct osd_device *osd = osd_obj2dev(obj);
1636 struct osd_thandle *oth;
1637 struct dt_object *parent = NULL;
1638 struct inode *inode;
1640 LINVRNT(osd_invariant(obj));
1641 LASSERT(obj->oo_inode == NULL);
1642 LASSERT(obj->oo_hl_head == NULL);
1644 if (S_ISDIR(mode) && ldiskfs_pdo) {
1645 obj->oo_hl_head =ldiskfs_htree_lock_head_alloc(HTREE_HBITS_DEF);
1646 if (obj->oo_hl_head == NULL)
1650 oth = container_of(th, struct osd_thandle, ot_super);
1651 LASSERT(oth->ot_handle->h_transaction != NULL);
1653 if (hint && hint->dah_parent)
1654 parent = hint->dah_parent;
1656 inode = ldiskfs_create_inode(oth->ot_handle,
1657 parent ? osd_dt_obj(parent)->oo_inode :
1658 osd_sb(osd)->s_root->d_inode,
1660 if (!IS_ERR(inode)) {
1661 /* Do not update file c/mtime in ldiskfs.
1662 * NB: don't need any lock because no contention at this
1664 inode->i_flags |= S_NOCMTIME;
1665 inode->i_state |= I_LUSTRE_NOSCRUB;
1666 obj->oo_inode = inode;
1669 if (obj->oo_hl_head != NULL) {
1670 ldiskfs_htree_lock_head_free(obj->oo_hl_head);
1671 obj->oo_hl_head = NULL;
1673 result = PTR_ERR(inode);
1675 LINVRNT(osd_invariant(obj));
1683 static int osd_mkdir(struct osd_thread_info *info, struct osd_object *obj,
1684 struct lu_attr *attr,
1685 struct dt_allocation_hint *hint,
1686 struct dt_object_format *dof,
1690 struct osd_thandle *oth;
1691 __u32 mode = (attr->la_mode & (S_IFMT | S_IRWXUGO | S_ISVTX));
1693 LASSERT(S_ISDIR(attr->la_mode));
1695 oth = container_of(th, struct osd_thandle, ot_super);
1696 LASSERT(oth->ot_handle->h_transaction != NULL);
1697 result = osd_mkfile(info, obj, mode, hint, th);
1702 static int osd_mk_index(struct osd_thread_info *info, struct osd_object *obj,
1703 struct lu_attr *attr,
1704 struct dt_allocation_hint *hint,
1705 struct dt_object_format *dof,
1709 struct osd_thandle *oth;
1710 const struct dt_index_features *feat = dof->u.dof_idx.di_feat;
1712 __u32 mode = (attr->la_mode & (S_IFMT | S_IALLUGO | S_ISVTX));
1714 LASSERT(S_ISREG(attr->la_mode));
1716 oth = container_of(th, struct osd_thandle, ot_super);
1717 LASSERT(oth->ot_handle->h_transaction != NULL);
1719 result = osd_mkfile(info, obj, mode, hint, th);
1721 LASSERT(obj->oo_inode != NULL);
1722 if (feat->dif_flags & DT_IND_VARKEY)
1723 result = iam_lvar_create(obj->oo_inode,
1724 feat->dif_keysize_max,
1726 feat->dif_recsize_max,
1729 result = iam_lfix_create(obj->oo_inode,
1730 feat->dif_keysize_max,
1732 feat->dif_recsize_max,
1739 static int osd_mkreg(struct osd_thread_info *info, struct osd_object *obj,
1740 struct lu_attr *attr,
1741 struct dt_allocation_hint *hint,
1742 struct dt_object_format *dof,
1745 LASSERT(S_ISREG(attr->la_mode));
1746 return osd_mkfile(info, obj, (attr->la_mode &
1747 (S_IFMT | S_IALLUGO | S_ISVTX)), hint, th);
1750 static int osd_mksym(struct osd_thread_info *info, struct osd_object *obj,
1751 struct lu_attr *attr,
1752 struct dt_allocation_hint *hint,
1753 struct dt_object_format *dof,
1756 LASSERT(S_ISLNK(attr->la_mode));
1757 return osd_mkfile(info, obj, (attr->la_mode &
1758 (S_IFMT | S_IALLUGO | S_ISVTX)), hint, th);
1761 static int osd_mknod(struct osd_thread_info *info, struct osd_object *obj,
1762 struct lu_attr *attr,
1763 struct dt_allocation_hint *hint,
1764 struct dt_object_format *dof,
1767 cfs_umode_t mode = attr->la_mode & (S_IFMT | S_IALLUGO | S_ISVTX);
1770 LINVRNT(osd_invariant(obj));
1771 LASSERT(obj->oo_inode == NULL);
1772 LASSERT(S_ISCHR(mode) || S_ISBLK(mode) ||
1773 S_ISFIFO(mode) || S_ISSOCK(mode));
1775 result = osd_mkfile(info, obj, mode, hint, th);
1777 LASSERT(obj->oo_inode != NULL);
1779 * This inode should be marked dirty for i_rdev. Currently
1780 * that is done in the osd_attr_init().
1782 init_special_inode(obj->oo_inode, obj->oo_inode->i_mode,
1785 LINVRNT(osd_invariant(obj));
1789 typedef int (*osd_obj_type_f)(struct osd_thread_info *, struct osd_object *,
1791 struct dt_allocation_hint *hint,
1792 struct dt_object_format *dof,
1795 static osd_obj_type_f osd_create_type_f(enum dt_format_type type)
1797 osd_obj_type_f result;
1813 result = osd_mk_index;
1824 static void osd_ah_init(const struct lu_env *env, struct dt_allocation_hint *ah,
1825 struct dt_object *parent, struct dt_object *child,
1826 cfs_umode_t child_mode)
1830 memset(ah, 0, sizeof(*ah));
1831 ah->dah_parent = parent;
1832 ah->dah_mode = child_mode;
1835 static void osd_attr_init(struct osd_thread_info *info, struct osd_object *obj,
1836 struct lu_attr *attr, struct dt_object_format *dof)
1838 struct inode *inode = obj->oo_inode;
1839 __u64 valid = attr->la_valid;
1842 attr->la_valid &= ~(LA_TYPE | LA_MODE);
1844 if (dof->dof_type != DFT_NODE)
1845 attr->la_valid &= ~LA_RDEV;
1846 if ((valid & LA_ATIME) && (attr->la_atime == LTIME_S(inode->i_atime)))
1847 attr->la_valid &= ~LA_ATIME;
1848 if ((valid & LA_CTIME) && (attr->la_ctime == LTIME_S(inode->i_ctime)))
1849 attr->la_valid &= ~LA_CTIME;
1850 if ((valid & LA_MTIME) && (attr->la_mtime == LTIME_S(inode->i_mtime)))
1851 attr->la_valid &= ~LA_MTIME;
1853 result = osd_quota_transfer(inode, attr);
1857 if (attr->la_valid != 0) {
1858 result = osd_inode_setattr(info->oti_env, inode, attr);
1860 * The osd_inode_setattr() should always succeed here. The
1861 * only error that could be returned is EDQUOT when we are
1862 * trying to change the UID or GID of the inode. However, this
1863 * should not happen since quota enforcement is no longer
1864 * enabled on ldiskfs (lquota takes care of it).
1866 LASSERTF(result == 0, "%d", result);
1867 inode->i_sb->s_op->dirty_inode(inode);
1870 attr->la_valid = valid;
1874 * Helper function for osd_object_create()
1876 * \retval 0, on success
1878 static int __osd_object_create(struct osd_thread_info *info,
1879 struct osd_object *obj, struct lu_attr *attr,
1880 struct dt_allocation_hint *hint,
1881 struct dt_object_format *dof,
1886 result = osd_create_type_f(dof->dof_type)(info, obj, attr, hint, dof,
1889 osd_attr_init(info, obj, attr, dof);
1890 osd_object_init0(obj);
1892 if (obj->oo_inode && (obj->oo_inode->i_state & I_NEW))
1893 unlock_new_inode(obj->oo_inode);
1900 * Helper function for osd_object_create()
1902 * \retval 0, on success
1904 static int __osd_oi_insert(const struct lu_env *env, struct osd_object *obj,
1905 const struct lu_fid *fid, struct thandle *th)
1907 struct osd_thread_info *info = osd_oti_get(env);
1908 struct osd_inode_id *id = &info->oti_id;
1909 struct osd_device *osd = osd_obj2dev(obj);
1911 LASSERT(obj->oo_inode != NULL);
1913 osd_id_gen(id, obj->oo_inode->i_ino, obj->oo_inode->i_generation);
1914 return osd_oi_insert(info, osd, fid, id, th);
1917 int osd_fld_lookup(const struct lu_env *env, struct osd_device *osd,
1918 const struct lu_fid *fid, struct lu_seq_range *range)
1920 struct seq_server_site *ss = osd_seq_site(osd);
1923 if (fid_is_igif(fid)) {
1924 range->lsr_flags = LU_SEQ_RANGE_MDT;
1925 range->lsr_index = 0;
1929 if (fid_is_idif(fid)) {
1930 range->lsr_flags = LU_SEQ_RANGE_OST;
1931 range->lsr_index = fid_idif_ost_idx(fid);
1935 if (!fid_is_norm(fid)) {
1936 range->lsr_flags = LU_SEQ_RANGE_MDT;
1938 /* FIXME: If ss is NULL, it suppose not get lsr_index
1940 range->lsr_index = ss->ss_node_id;
1944 LASSERT(ss != NULL);
1945 range->lsr_flags = -1;
1946 rc = fld_server_lookup(env, ss->ss_server_fld, fid_seq(fid), range);
1948 CERROR("%s can not find "DFID": rc = %d\n",
1949 osd2lu_dev(osd)->ld_obd->obd_name, PFID(fid), rc);
1955 static int osd_declare_object_create(const struct lu_env *env,
1956 struct dt_object *dt,
1957 struct lu_attr *attr,
1958 struct dt_allocation_hint *hint,
1959 struct dt_object_format *dof,
1960 struct thandle *handle)
1962 struct lu_seq_range *range = &osd_oti_get(env)->oti_seq_range;
1963 struct osd_thandle *oh;
1967 LASSERT(handle != NULL);
1969 oh = container_of0(handle, struct osd_thandle, ot_super);
1970 LASSERT(oh->ot_handle == NULL);
1972 OSD_DECLARE_OP(oh, create, osd_dto_credits_noquota[DTO_OBJECT_CREATE]);
1973 /* XXX: So far, only normal fid needs be inserted into the oi,
1974 * things could be changed later. Revise following code then. */
1975 if (fid_is_norm(lu_object_fid(&dt->do_lu)) &&
1976 !fid_is_on_ost(osd_oti_get(env), osd_dt_dev(handle->th_dev),
1977 lu_object_fid(&dt->do_lu))) {
1978 /* Reuse idle OI block may cause additional one OI block
1980 OSD_DECLARE_OP(oh, insert,
1981 osd_dto_credits_noquota[DTO_INDEX_INSERT] + 1);
1983 /* If this is directory, then we expect . and .. to be inserted as
1984 * well. The one directory block always needs to be created for the
1985 * directory, so we could use DTO_WRITE_BASE here (GDT, block bitmap,
1986 * block), there is no danger of needing a tree for the first block.
1988 if (attr && S_ISDIR(attr->la_mode)) {
1989 OSD_DECLARE_OP(oh, insert,
1990 osd_dto_credits_noquota[DTO_WRITE_BASE]);
1991 OSD_DECLARE_OP(oh, insert, 0);
1997 rc = osd_declare_inode_qid(env, attr->la_uid, attr->la_gid, 1, oh,
1998 false, false, NULL, false);
2002 /* It does fld look up inside declare, and the result will be
2003 * added to fld cache, so the following fld lookup inside insert
2004 * does not need send RPC anymore, so avoid send rpc with holding
2006 if (fid_is_norm(lu_object_fid(&dt->do_lu)) &&
2007 !fid_is_last_id(lu_object_fid(&dt->do_lu)))
2008 osd_fld_lookup(env, osd_dt_dev(handle->th_dev),
2009 lu_object_fid(&dt->do_lu), range);
2015 static int osd_object_create(const struct lu_env *env, struct dt_object *dt,
2016 struct lu_attr *attr,
2017 struct dt_allocation_hint *hint,
2018 struct dt_object_format *dof,
2021 const struct lu_fid *fid = lu_object_fid(&dt->do_lu);
2022 struct osd_object *obj = osd_dt_obj(dt);
2023 struct osd_thread_info *info = osd_oti_get(env);
2028 LINVRNT(osd_invariant(obj));
2029 LASSERT(!dt_object_exists(dt));
2030 LASSERT(osd_write_locked(env, obj));
2031 LASSERT(th != NULL);
2033 if (unlikely(fid_is_acct(fid)))
2034 /* Quota files can't be created from the kernel any more,
2035 * 'tune2fs -O quota' will take care of creating them */
2038 OSD_EXEC_OP(th, create);
2040 result = __osd_object_create(info, obj, attr, hint, dof, th);
2042 result = __osd_oi_insert(env, obj, fid, th);
2044 LASSERT(ergo(result == 0, dt_object_exists(dt)));
2045 LASSERT(osd_invariant(obj));
2050 * Called to destroy on-disk representation of the object
2052 * Concurrency: must be locked
2054 static int osd_declare_object_destroy(const struct lu_env *env,
2055 struct dt_object *dt,
2058 struct osd_object *obj = osd_dt_obj(dt);
2059 struct inode *inode = obj->oo_inode;
2060 struct osd_thandle *oh;
2064 oh = container_of0(th, struct osd_thandle, ot_super);
2065 LASSERT(oh->ot_handle == NULL);
2068 OSD_DECLARE_OP(oh, delete, osd_dto_credits_noquota[DTO_OBJECT_DELETE]);
2069 /* XXX: So far, only normal fid needs to be inserted into the OI,
2070 * so only normal fid needs to be removed from the OI also.
2071 * Recycle idle OI leaf may cause additional three OI blocks
2073 OSD_DECLARE_OP(oh, destroy, fid_is_norm(lu_object_fid(&dt->do_lu)) ?
2074 osd_dto_credits_noquota[DTO_INDEX_DELETE] + 3 : 0);
2076 /* one less inode */
2077 rc = osd_declare_inode_qid(env, inode->i_uid, inode->i_gid, -1, oh,
2078 false, true, NULL, false);
2081 /* data to be truncated */
2082 rc = osd_declare_inode_qid(env, inode->i_uid, inode->i_gid, 0, oh,
2083 true, true, NULL, false);
2087 static int osd_object_destroy(const struct lu_env *env,
2088 struct dt_object *dt,
2091 const struct lu_fid *fid = lu_object_fid(&dt->do_lu);
2092 struct osd_object *obj = osd_dt_obj(dt);
2093 struct inode *inode = obj->oo_inode;
2094 struct osd_device *osd = osd_obj2dev(obj);
2095 struct osd_thandle *oh;
2099 oh = container_of0(th, struct osd_thandle, ot_super);
2100 LASSERT(oh->ot_handle);
2102 LASSERT(!lu_object_is_dying(dt->do_lu.lo_header));
2104 if (unlikely(fid_is_acct(fid)))
2107 /* Parallel control for OI scrub. For most of cases, there is no
2108 * lock contention. So it will not affect unlink performance. */
2109 mutex_lock(&inode->i_mutex);
2110 if (S_ISDIR(inode->i_mode)) {
2111 LASSERT(osd_inode_unlinked(inode) ||
2112 inode->i_nlink == 1);
2113 spin_lock(&obj->oo_guard);
2115 spin_unlock(&obj->oo_guard);
2116 inode->i_sb->s_op->dirty_inode(inode);
2118 LASSERT(osd_inode_unlinked(inode));
2121 OSD_EXEC_OP(th, destroy);
2123 result = osd_oi_delete(osd_oti_get(env), osd, fid, th);
2124 mutex_unlock(&inode->i_mutex);
2126 /* XXX: add to ext3 orphan list */
2127 /* rc = ext3_orphan_add(handle_t *handle, struct inode *inode) */
2129 /* not needed in the cache anymore */
2130 set_bit(LU_OBJECT_HEARD_BANSHEE, &dt->do_lu.lo_header->loh_flags);
2136 * Helper function for osd_xattr_set()
2138 static int __osd_xattr_set(const struct lu_env *env, struct dt_object *dt,
2139 const struct lu_buf *buf, const char *name, int fl)
2141 struct osd_object *obj = osd_dt_obj(dt);
2142 struct inode *inode = obj->oo_inode;
2143 struct osd_thread_info *info = osd_oti_get(env);
2144 struct dentry *dentry = &info->oti_child_dentry;
2148 LASSERT(dt_object_exists(dt));
2149 LASSERT(inode->i_op != NULL && inode->i_op->setxattr != NULL);
2151 if (fl & LU_XATTR_REPLACE)
2152 fs_flags |= XATTR_REPLACE;
2154 if (fl & LU_XATTR_CREATE)
2155 fs_flags |= XATTR_CREATE;
2157 ll_vfs_dq_init(inode);
2158 dentry->d_inode = inode;
2159 rc = inode->i_op->setxattr(dentry, name, buf->lb_buf,
2160 buf->lb_len, fs_flags);
2165 * Put the fid into lustre_mdt_attrs, and then place the structure
2166 * inode's ea. This fid should not be altered during the life time
2169 * \retval +ve, on success
2170 * \retval -ve, on error
2172 * FIXME: It is good to have/use ldiskfs_xattr_set_handle() here
2174 static int osd_ea_fid_set(const struct lu_env *env, struct dt_object *dt,
2175 const struct lu_fid *fid)
2177 struct osd_thread_info *info = osd_oti_get(env);
2178 struct lustre_mdt_attrs *mdt_attrs = &info->oti_mdt_attrs;
2180 lustre_lma_init(mdt_attrs, fid);
2181 lustre_lma_swab(mdt_attrs);
2182 return __osd_xattr_set(env, dt,
2183 osd_buf_get(env, mdt_attrs, sizeof *mdt_attrs),
2184 XATTR_NAME_LMA, LU_XATTR_CREATE);
2189 * ldiskfs supports fid in dirent, it is passed in dentry->d_fsdata.
2190 * lustre 1.8 also uses d_fsdata for passing other info to ldiskfs.
2191 * To have compatilibility with 1.8 ldiskfs driver we need to have
2192 * magic number at start of fid data.
2193 * \ldiskfs_dentry_param is used only to pass fid from osd to ldiskfs.
2196 void osd_get_ldiskfs_dirent_param(struct ldiskfs_dentry_param *param,
2197 const struct dt_rec *fid)
2199 param->edp_magic = LDISKFS_LUFID_MAGIC;
2200 param->edp_len = sizeof(struct lu_fid) + 1;
2202 fid_cpu_to_be((struct lu_fid *)param->edp_data,
2203 (struct lu_fid *)fid);
2207 * Try to read the fid from inode ea into dt_rec, if return value
2208 * i.e. rc is +ve, then we got fid, otherwise we will have to form igif
2210 * \param fid object fid.
2212 * \retval 0 on success
2214 static int osd_ea_fid_get(const struct lu_env *env, struct osd_object *obj,
2215 __u32 ino, struct lu_fid *fid,
2216 struct osd_inode_id *id)
2218 struct osd_thread_info *info = osd_oti_get(env);
2219 struct inode *inode;
2222 osd_id_gen(id, ino, OSD_OII_NOGEN);
2223 inode = osd_iget_fid(info, osd_obj2dev(obj), id, fid);
2225 RETURN(PTR_ERR(inode));
2232 * OSD layer object create function for interoperability mode (b11826).
2233 * This is mostly similar to osd_object_create(). Only difference being, fid is
2234 * inserted into inode ea here.
2236 * \retval 0, on success
2237 * \retval -ve, on error
2239 static int osd_object_ea_create(const struct lu_env *env, struct dt_object *dt,
2240 struct lu_attr *attr,
2241 struct dt_allocation_hint *hint,
2242 struct dt_object_format *dof,
2245 const struct lu_fid *fid = lu_object_fid(&dt->do_lu);
2246 struct osd_object *obj = osd_dt_obj(dt);
2247 struct osd_thread_info *info = osd_oti_get(env);
2252 LASSERT(osd_invariant(obj));
2253 LASSERT(!dt_object_exists(dt));
2254 LASSERT(osd_write_locked(env, obj));
2255 LASSERT(th != NULL);
2257 if (unlikely(fid_is_acct(fid)))
2258 /* Quota files can't be created from the kernel any more,
2259 * 'tune2fs -O quota' will take care of creating them */
2262 OSD_EXEC_OP(th, create);
2264 result = __osd_object_create(info, obj, attr, hint, dof, th);
2265 /* objects under osd root shld have igif fid, so dont add fid EA */
2266 /* For ost object, the fid will be stored during first write */
2267 if (result == 0 && fid_seq(fid) >= FID_SEQ_NORMAL &&
2268 !fid_is_on_ost(info, osd_dt_dev(th->th_dev), fid))
2269 result = osd_ea_fid_set(env, dt, fid);
2272 result = __osd_oi_insert(env, obj, fid, th);
2274 LASSERT(ergo(result == 0, dt_object_exists(dt)));
2275 LINVRNT(osd_invariant(obj));
2279 static int osd_declare_object_ref_add(const struct lu_env *env,
2280 struct dt_object *dt,
2281 struct thandle *handle)
2283 struct osd_thandle *oh;
2285 /* it's possible that object doesn't exist yet */
2286 LASSERT(handle != NULL);
2288 oh = container_of0(handle, struct osd_thandle, ot_super);
2289 LASSERT(oh->ot_handle == NULL);
2291 OSD_DECLARE_OP(oh, ref_add, osd_dto_credits_noquota[DTO_ATTR_SET_BASE]);
2297 * Concurrency: @dt is write locked.
2299 static int osd_object_ref_add(const struct lu_env *env,
2300 struct dt_object *dt, struct thandle *th)
2302 struct osd_object *obj = osd_dt_obj(dt);
2303 struct inode *inode = obj->oo_inode;
2305 LINVRNT(osd_invariant(obj));
2306 LASSERT(dt_object_exists(dt));
2307 LASSERT(osd_write_locked(env, obj));
2308 LASSERT(th != NULL);
2310 OSD_EXEC_OP(th, ref_add);
2313 * DIR_NLINK feature is set for compatibility reasons if:
2314 * 1) nlinks > LDISKFS_LINK_MAX, or
2315 * 2) nlinks == 2, since this indicates i_nlink was previously 1.
2317 * It is easier to always set this flag (rather than check and set),
2318 * since it has less overhead, and the superblock will be dirtied
2319 * at some point. Both e2fsprogs and any Lustre-supported ldiskfs
2320 * do not actually care whether this flag is set or not.
2322 spin_lock(&obj->oo_guard);
2323 /* inc_nlink from 0 may cause WARN_ON */
2324 if(inode->i_nlink == 0)
2325 set_nlink(inode, 1);
2328 if (S_ISDIR(inode->i_mode) && inode->i_nlink > 1) {
2329 if (inode->i_nlink >= LDISKFS_LINK_MAX ||
2330 inode->i_nlink == 2)
2331 set_nlink(inode, 1);
2333 LASSERT(inode->i_nlink <= LDISKFS_LINK_MAX);
2334 spin_unlock(&obj->oo_guard);
2335 inode->i_sb->s_op->dirty_inode(inode);
2336 LINVRNT(osd_invariant(obj));
2341 static int osd_declare_object_ref_del(const struct lu_env *env,
2342 struct dt_object *dt,
2343 struct thandle *handle)
2345 struct osd_thandle *oh;
2347 LASSERT(dt_object_exists(dt));
2348 LASSERT(handle != NULL);
2350 oh = container_of0(handle, struct osd_thandle, ot_super);
2351 LASSERT(oh->ot_handle == NULL);
2353 OSD_DECLARE_OP(oh, ref_del, osd_dto_credits_noquota[DTO_ATTR_SET_BASE]);
2359 * Concurrency: @dt is write locked.
2361 static int osd_object_ref_del(const struct lu_env *env, struct dt_object *dt,
2364 struct osd_object *obj = osd_dt_obj(dt);
2365 struct inode *inode = obj->oo_inode;
2367 LINVRNT(osd_invariant(obj));
2368 LASSERT(dt_object_exists(dt));
2369 LASSERT(osd_write_locked(env, obj));
2370 LASSERT(th != NULL);
2372 OSD_EXEC_OP(th, ref_del);
2374 spin_lock(&obj->oo_guard);
2375 LASSERT(inode->i_nlink > 0);
2377 /* If this is/was a many-subdir directory (nlink > LDISKFS_LINK_MAX)
2378 * then the nlink count is 1. Don't let it be set to 0 or the directory
2379 * inode will be deleted incorrectly. */
2380 if (S_ISDIR(inode->i_mode) && inode->i_nlink == 0)
2381 set_nlink(inode, 1);
2382 spin_unlock(&obj->oo_guard);
2383 inode->i_sb->s_op->dirty_inode(inode);
2384 LINVRNT(osd_invariant(obj));
2390 * Get the 64-bit version for an inode.
2392 static int osd_object_version_get(const struct lu_env *env,
2393 struct dt_object *dt, dt_obj_version_t *ver)
2395 struct inode *inode = osd_dt_obj(dt)->oo_inode;
2397 CDEBUG(D_INODE, "Get version "LPX64" for inode %lu\n",
2398 LDISKFS_I(inode)->i_fs_version, inode->i_ino);
2399 *ver = LDISKFS_I(inode)->i_fs_version;
2404 * Concurrency: @dt is read locked.
2406 static int osd_xattr_get(const struct lu_env *env, struct dt_object *dt,
2407 struct lu_buf *buf, const char *name,
2408 struct lustre_capa *capa)
2410 struct osd_object *obj = osd_dt_obj(dt);
2411 struct inode *inode = obj->oo_inode;
2412 struct osd_thread_info *info = osd_oti_get(env);
2413 struct dentry *dentry = &info->oti_obj_dentry;
2415 /* version get is not real XATTR but uses xattr API */
2416 if (strcmp(name, XATTR_NAME_VERSION) == 0) {
2417 /* for version we are just using xattr API but change inode
2419 LASSERT(buf->lb_len == sizeof(dt_obj_version_t));
2420 osd_object_version_get(env, dt, buf->lb_buf);
2421 return sizeof(dt_obj_version_t);
2424 LASSERT(dt_object_exists(dt));
2425 LASSERT(inode->i_op != NULL && inode->i_op->getxattr != NULL);
2427 if (osd_object_auth(env, dt, capa, CAPA_OPC_META_READ))
2430 dentry->d_inode = inode;
2431 return inode->i_op->getxattr(dentry, name, buf->lb_buf, buf->lb_len);
2435 static int osd_declare_xattr_set(const struct lu_env *env,
2436 struct dt_object *dt,
2437 const struct lu_buf *buf, const char *name,
2438 int fl, struct thandle *handle)
2440 struct osd_thandle *oh;
2442 LASSERT(handle != NULL);
2444 oh = container_of0(handle, struct osd_thandle, ot_super);
2445 LASSERT(oh->ot_handle == NULL);
2447 OSD_DECLARE_OP(oh, xattr_set, strcmp(name, XATTR_NAME_VERSION) == 0 ?
2448 osd_dto_credits_noquota[DTO_ATTR_SET_BASE] :
2449 osd_dto_credits_noquota[DTO_XATTR_SET]);
2455 * Set the 64-bit version for object
2457 static void osd_object_version_set(const struct lu_env *env,
2458 struct dt_object *dt,
2459 dt_obj_version_t *new_version)
2461 struct inode *inode = osd_dt_obj(dt)->oo_inode;
2463 CDEBUG(D_INODE, "Set version "LPX64" (old "LPX64") for inode %lu\n",
2464 *new_version, LDISKFS_I(inode)->i_fs_version, inode->i_ino);
2466 LDISKFS_I(inode)->i_fs_version = *new_version;
2467 /** Version is set after all inode operations are finished,
2468 * so we should mark it dirty here */
2469 inode->i_sb->s_op->dirty_inode(inode);
2473 * Concurrency: @dt is write locked.
2475 static int osd_xattr_set(const struct lu_env *env, struct dt_object *dt,
2476 const struct lu_buf *buf, const char *name, int fl,
2477 struct thandle *handle, struct lustre_capa *capa)
2479 LASSERT(handle != NULL);
2481 /* version set is not real XATTR */
2482 if (strcmp(name, XATTR_NAME_VERSION) == 0) {
2483 /* for version we are just using xattr API but change inode
2485 LASSERT(buf->lb_len == sizeof(dt_obj_version_t));
2486 osd_object_version_set(env, dt, buf->lb_buf);
2487 return sizeof(dt_obj_version_t);
2490 if (osd_object_auth(env, dt, capa, CAPA_OPC_META_WRITE))
2493 OSD_EXEC_OP(handle, xattr_set);
2494 return __osd_xattr_set(env, dt, buf, name, fl);
2498 * Concurrency: @dt is read locked.
2500 static int osd_xattr_list(const struct lu_env *env, struct dt_object *dt,
2501 struct lu_buf *buf, struct lustre_capa *capa)
2503 struct osd_object *obj = osd_dt_obj(dt);
2504 struct inode *inode = obj->oo_inode;
2505 struct osd_thread_info *info = osd_oti_get(env);
2506 struct dentry *dentry = &info->oti_obj_dentry;
2508 LASSERT(dt_object_exists(dt));
2509 LASSERT(inode->i_op != NULL && inode->i_op->listxattr != NULL);
2510 LASSERT(osd_read_locked(env, obj) || osd_write_locked(env, obj));
2512 if (osd_object_auth(env, dt, capa, CAPA_OPC_META_READ))
2515 dentry->d_inode = inode;
2516 return inode->i_op->listxattr(dentry, buf->lb_buf, buf->lb_len);
2519 static int osd_declare_xattr_del(const struct lu_env *env,
2520 struct dt_object *dt, const char *name,
2521 struct thandle *handle)
2523 struct osd_thandle *oh;
2525 LASSERT(dt_object_exists(dt));
2526 LASSERT(handle != NULL);
2528 oh = container_of0(handle, struct osd_thandle, ot_super);
2529 LASSERT(oh->ot_handle == NULL);
2531 OSD_DECLARE_OP(oh, xattr_set, osd_dto_credits_noquota[DTO_XATTR_SET]);
2537 * Concurrency: @dt is write locked.
2539 static int osd_xattr_del(const struct lu_env *env, struct dt_object *dt,
2540 const char *name, struct thandle *handle,
2541 struct lustre_capa *capa)
2543 struct osd_object *obj = osd_dt_obj(dt);
2544 struct inode *inode = obj->oo_inode;
2545 struct osd_thread_info *info = osd_oti_get(env);
2546 struct dentry *dentry = &info->oti_obj_dentry;
2549 LASSERT(dt_object_exists(dt));
2550 LASSERT(inode->i_op != NULL && inode->i_op->removexattr != NULL);
2551 LASSERT(osd_write_locked(env, obj));
2552 LASSERT(handle != NULL);
2554 if (osd_object_auth(env, dt, capa, CAPA_OPC_META_WRITE))
2557 OSD_EXEC_OP(handle, xattr_set);
2559 ll_vfs_dq_init(inode);
2560 dentry->d_inode = inode;
2561 rc = inode->i_op->removexattr(dentry, name);
2565 static struct obd_capa *osd_capa_get(const struct lu_env *env,
2566 struct dt_object *dt,
2567 struct lustre_capa *old,
2570 struct osd_thread_info *info = osd_oti_get(env);
2571 const struct lu_fid *fid = lu_object_fid(&dt->do_lu);
2572 struct osd_object *obj = osd_dt_obj(dt);
2573 struct osd_device *dev = osd_obj2dev(obj);
2574 struct lustre_capa_key *key = &info->oti_capa_key;
2575 struct lustre_capa *capa = &info->oti_capa;
2576 struct obd_capa *oc;
2577 struct md_capainfo *ci;
2581 if (!dev->od_fl_capa)
2582 RETURN(ERR_PTR(-ENOENT));
2584 LASSERT(dt_object_exists(dt));
2585 LINVRNT(osd_invariant(obj));
2587 /* renewal sanity check */
2588 if (old && osd_object_auth(env, dt, old, opc))
2589 RETURN(ERR_PTR(-EACCES));
2591 ci = md_capainfo(env);
2593 RETURN(ERR_PTR(-ENOENT));
2595 switch (ci->mc_auth) {
2599 capa->lc_uid = obj->oo_inode->i_uid;
2600 capa->lc_gid = obj->oo_inode->i_gid;
2601 capa->lc_flags = LC_ID_PLAIN;
2603 case LC_ID_CONVERT: {
2606 s[0] = obj->oo_inode->i_uid;
2607 cfs_get_random_bytes(&(s[1]), sizeof(__u32));
2608 s[2] = obj->oo_inode->i_gid;
2609 cfs_get_random_bytes(&(s[3]), sizeof(__u32));
2610 rc = capa_encrypt_id(d, s, key->lk_key, CAPA_HMAC_KEY_MAX_LEN);
2612 RETURN(ERR_PTR(rc));
2614 capa->lc_uid = ((__u64)d[1] << 32) | d[0];
2615 capa->lc_gid = ((__u64)d[3] << 32) | d[2];
2616 capa->lc_flags = LC_ID_CONVERT;
2620 RETURN(ERR_PTR(-EINVAL));
2623 capa->lc_fid = *fid;
2625 capa->lc_flags |= dev->od_capa_alg << 24;
2626 capa->lc_timeout = dev->od_capa_timeout;
2627 capa->lc_expiry = 0;
2629 oc = capa_lookup(dev->od_capa_hash, capa, 1);
2631 LASSERT(!capa_is_expired(oc));
2635 spin_lock(&capa_lock);
2636 *key = dev->od_capa_keys[1];
2637 spin_unlock(&capa_lock);
2639 capa->lc_keyid = key->lk_keyid;
2640 capa->lc_expiry = cfs_time_current_sec() + dev->od_capa_timeout;
2642 rc = capa_hmac(capa->lc_hmac, capa, key->lk_key);
2644 DEBUG_CAPA(D_ERROR, capa, "HMAC failed: %d for", rc);
2645 RETURN(ERR_PTR(rc));
2648 oc = capa_add(dev->od_capa_hash, capa);
2652 static int osd_object_sync(const struct lu_env *env, struct dt_object *dt)
2654 struct osd_object *obj = osd_dt_obj(dt);
2655 struct inode *inode = obj->oo_inode;
2656 struct osd_thread_info *info = osd_oti_get(env);
2657 struct dentry *dentry = &info->oti_obj_dentry;
2658 struct file *file = &info->oti_file;
2663 dentry->d_inode = inode;
2664 file->f_dentry = dentry;
2665 file->f_mapping = inode->i_mapping;
2666 file->f_op = inode->i_fop;
2667 mutex_lock(&inode->i_mutex);
2668 rc = file->f_op->fsync(file, dentry, 0);
2669 mutex_unlock(&inode->i_mutex);
2673 static int osd_data_get(const struct lu_env *env, struct dt_object *dt,
2676 struct osd_object *obj = osd_dt_obj(dt);
2679 *data = (void *)obj->oo_inode;
2687 static int osd_iam_index_probe(const struct lu_env *env, struct osd_object *o,
2688 const struct dt_index_features *feat)
2690 struct iam_descr *descr;
2692 if (osd_object_is_root(o))
2693 return feat == &dt_directory_features;
2695 LASSERT(o->oo_dir != NULL);
2697 descr = o->oo_dir->od_container.ic_descr;
2698 if (feat == &dt_directory_features) {
2699 if (descr->id_rec_size == sizeof(struct osd_fid_pack))
2705 feat->dif_keysize_min <= descr->id_key_size &&
2706 descr->id_key_size <= feat->dif_keysize_max &&
2707 feat->dif_recsize_min <= descr->id_rec_size &&
2708 descr->id_rec_size <= feat->dif_recsize_max &&
2709 !(feat->dif_flags & (DT_IND_VARKEY |
2710 DT_IND_VARREC | DT_IND_NONUNQ)) &&
2711 ergo(feat->dif_flags & DT_IND_UPDATE,
2712 1 /* XXX check that object (and file system) is
2717 static int osd_iam_container_init(const struct lu_env *env,
2718 struct osd_object *obj,
2719 struct osd_directory *dir)
2721 struct iam_container *bag = &dir->od_container;
2724 result = iam_container_init(bag, &dir->od_descr, obj->oo_inode);
2728 result = iam_container_setup(bag);
2730 obj->oo_dt.do_index_ops = &osd_index_iam_ops;
2732 iam_container_fini(bag);
2739 * Concurrency: no external locking is necessary.
2741 static int osd_index_try(const struct lu_env *env, struct dt_object *dt,
2742 const struct dt_index_features *feat)
2746 struct osd_object *obj = osd_dt_obj(dt);
2748 LINVRNT(osd_invariant(obj));
2749 LASSERT(dt_object_exists(dt));
2751 if (osd_object_is_root(obj)) {
2752 dt->do_index_ops = &osd_index_ea_ops;
2754 } else if (feat == &dt_directory_features) {
2755 dt->do_index_ops = &osd_index_ea_ops;
2756 if (S_ISDIR(obj->oo_inode->i_mode))
2761 } else if (unlikely(feat == &dt_otable_features)) {
2762 dt->do_index_ops = &osd_otable_ops;
2764 } else if (feat == &dt_acct_features) {
2765 dt->do_index_ops = &osd_acct_index_ops;
2768 } else if (!osd_has_index(obj)) {
2769 struct osd_directory *dir;
2774 spin_lock(&obj->oo_guard);
2775 if (obj->oo_dir == NULL)
2779 * Concurrent thread allocated container data.
2782 spin_unlock(&obj->oo_guard);
2784 * Now, that we have container data, serialize its
2787 down_write(&obj->oo_ext_idx_sem);
2789 * recheck under lock.
2791 if (!osd_has_index(obj))
2792 result = osd_iam_container_init(env, obj, dir);
2795 up_write(&obj->oo_ext_idx_sem);
2803 if (result == 0 && skip_iam == 0) {
2804 if (!osd_iam_index_probe(env, obj, feat))
2807 LINVRNT(osd_invariant(obj));
2809 if (is_quota_glb_feat(feat))
2810 result = osd_quota_migration(env, dt, feat);
2815 static int osd_otable_it_attr_get(const struct lu_env *env,
2816 struct dt_object *dt,
2817 struct lu_attr *attr,
2818 struct lustre_capa *capa)
2824 static const struct dt_object_operations osd_obj_ops = {
2825 .do_read_lock = osd_object_read_lock,
2826 .do_write_lock = osd_object_write_lock,
2827 .do_read_unlock = osd_object_read_unlock,
2828 .do_write_unlock = osd_object_write_unlock,
2829 .do_write_locked = osd_object_write_locked,
2830 .do_attr_get = osd_attr_get,
2831 .do_declare_attr_set = osd_declare_attr_set,
2832 .do_attr_set = osd_attr_set,
2833 .do_ah_init = osd_ah_init,
2834 .do_declare_create = osd_declare_object_create,
2835 .do_create = osd_object_create,
2836 .do_declare_destroy = osd_declare_object_destroy,
2837 .do_destroy = osd_object_destroy,
2838 .do_index_try = osd_index_try,
2839 .do_declare_ref_add = osd_declare_object_ref_add,
2840 .do_ref_add = osd_object_ref_add,
2841 .do_declare_ref_del = osd_declare_object_ref_del,
2842 .do_ref_del = osd_object_ref_del,
2843 .do_xattr_get = osd_xattr_get,
2844 .do_declare_xattr_set = osd_declare_xattr_set,
2845 .do_xattr_set = osd_xattr_set,
2846 .do_declare_xattr_del = osd_declare_xattr_del,
2847 .do_xattr_del = osd_xattr_del,
2848 .do_xattr_list = osd_xattr_list,
2849 .do_capa_get = osd_capa_get,
2850 .do_object_sync = osd_object_sync,
2851 .do_data_get = osd_data_get,
2855 * dt_object_operations for interoperability mode
2856 * (i.e. to run 2.0 mds on 1.8 disk) (b11826)
2858 static const struct dt_object_operations osd_obj_ea_ops = {
2859 .do_read_lock = osd_object_read_lock,
2860 .do_write_lock = osd_object_write_lock,
2861 .do_read_unlock = osd_object_read_unlock,
2862 .do_write_unlock = osd_object_write_unlock,
2863 .do_write_locked = osd_object_write_locked,
2864 .do_attr_get = osd_attr_get,
2865 .do_declare_attr_set = osd_declare_attr_set,
2866 .do_attr_set = osd_attr_set,
2867 .do_ah_init = osd_ah_init,
2868 .do_declare_create = osd_declare_object_create,
2869 .do_create = osd_object_ea_create,
2870 .do_declare_destroy = osd_declare_object_destroy,
2871 .do_destroy = osd_object_destroy,
2872 .do_index_try = osd_index_try,
2873 .do_declare_ref_add = osd_declare_object_ref_add,
2874 .do_ref_add = osd_object_ref_add,
2875 .do_declare_ref_del = osd_declare_object_ref_del,
2876 .do_ref_del = osd_object_ref_del,
2877 .do_xattr_get = osd_xattr_get,
2878 .do_declare_xattr_set = osd_declare_xattr_set,
2879 .do_xattr_set = osd_xattr_set,
2880 .do_declare_xattr_del = osd_declare_xattr_del,
2881 .do_xattr_del = osd_xattr_del,
2882 .do_xattr_list = osd_xattr_list,
2883 .do_capa_get = osd_capa_get,
2884 .do_object_sync = osd_object_sync,
2885 .do_data_get = osd_data_get,
2888 static const struct dt_object_operations osd_obj_otable_it_ops = {
2889 .do_attr_get = osd_otable_it_attr_get,
2890 .do_index_try = osd_index_try,
2893 static int osd_index_declare_iam_delete(const struct lu_env *env,
2894 struct dt_object *dt,
2895 const struct dt_key *key,
2896 struct thandle *handle)
2898 struct osd_thandle *oh;
2900 oh = container_of0(handle, struct osd_thandle, ot_super);
2901 LASSERT(oh->ot_handle == NULL);
2903 OSD_DECLARE_OP(oh, delete, osd_dto_credits_noquota[DTO_INDEX_DELETE]);
2909 * delete a (key, value) pair from index \a dt specified by \a key
2911 * \param dt osd index object
2912 * \param key key for index
2913 * \param rec record reference
2914 * \param handle transaction handler
2917 * \retval -ve failure
2920 static int osd_index_iam_delete(const struct lu_env *env, struct dt_object *dt,
2921 const struct dt_key *key,
2922 struct thandle *handle,
2923 struct lustre_capa *capa)
2925 struct osd_thread_info *oti = osd_oti_get(env);
2926 struct osd_object *obj = osd_dt_obj(dt);
2927 struct osd_thandle *oh;
2928 struct iam_path_descr *ipd;
2929 struct iam_container *bag = &obj->oo_dir->od_container;
2934 LINVRNT(osd_invariant(obj));
2935 LASSERT(dt_object_exists(dt));
2936 LASSERT(bag->ic_object == obj->oo_inode);
2937 LASSERT(handle != NULL);
2939 if (osd_object_auth(env, dt, capa, CAPA_OPC_INDEX_DELETE))
2942 OSD_EXEC_OP(handle, delete);
2944 ipd = osd_idx_ipd_get(env, bag);
2945 if (unlikely(ipd == NULL))
2948 oh = container_of0(handle, struct osd_thandle, ot_super);
2949 LASSERT(oh->ot_handle != NULL);
2950 LASSERT(oh->ot_handle->h_transaction != NULL);
2952 if (fid_is_quota(lu_object_fid(&dt->do_lu))) {
2953 /* swab quota uid/gid provided by caller */
2954 oti->oti_quota_id = cpu_to_le64(*((__u64 *)key));
2955 key = (const struct dt_key *)&oti->oti_quota_id;
2958 rc = iam_delete(oh->ot_handle, bag, (const struct iam_key *)key, ipd);
2959 osd_ipd_put(env, bag, ipd);
2960 LINVRNT(osd_invariant(obj));
2964 static int osd_index_declare_ea_delete(const struct lu_env *env,
2965 struct dt_object *dt,
2966 const struct dt_key *key,
2967 struct thandle *handle)
2969 struct osd_thandle *oh;
2970 struct inode *inode;
2974 LASSERT(dt_object_exists(dt));
2975 LASSERT(handle != NULL);
2977 oh = container_of0(handle, struct osd_thandle, ot_super);
2978 LASSERT(oh->ot_handle == NULL);
2980 OSD_DECLARE_OP(oh, delete, osd_dto_credits_noquota[DTO_INDEX_DELETE]);
2982 inode = osd_dt_obj(dt)->oo_inode;
2985 rc = osd_declare_inode_qid(env, inode->i_uid, inode->i_gid, 0, oh,
2986 true, true, NULL, false);
2990 static inline int osd_get_fid_from_dentry(struct ldiskfs_dir_entry_2 *de,
2993 struct osd_fid_pack *rec;
2996 if (de->file_type & LDISKFS_DIRENT_LUFID) {
2997 rec = (struct osd_fid_pack *) (de->name + de->name_len + 1);
2998 rc = osd_fid_unpack((struct lu_fid *)fid, rec);
3004 * Index delete function for interoperability mode (b11826).
3005 * It will remove the directory entry added by osd_index_ea_insert().
3006 * This entry is needed to maintain name->fid mapping.
3008 * \param key, key i.e. file entry to be deleted
3010 * \retval 0, on success
3011 * \retval -ve, on error
3013 static int osd_index_ea_delete(const struct lu_env *env, struct dt_object *dt,
3014 const struct dt_key *key,
3015 struct thandle *handle,
3016 struct lustre_capa *capa)
3018 struct osd_object *obj = osd_dt_obj(dt);
3019 struct inode *dir = obj->oo_inode;
3020 struct dentry *dentry;
3021 struct osd_thandle *oh;
3022 struct ldiskfs_dir_entry_2 *de;
3023 struct buffer_head *bh;
3024 struct htree_lock *hlock = NULL;
3029 LINVRNT(osd_invariant(obj));
3030 LASSERT(dt_object_exists(dt));
3031 LASSERT(handle != NULL);
3033 OSD_EXEC_OP(handle, delete);
3035 oh = container_of(handle, struct osd_thandle, ot_super);
3036 LASSERT(oh->ot_handle != NULL);
3037 LASSERT(oh->ot_handle->h_transaction != NULL);
3039 if (osd_object_auth(env, dt, capa, CAPA_OPC_INDEX_DELETE))
3042 ll_vfs_dq_init(dir);
3043 dentry = osd_child_dentry_get(env, obj,
3044 (char *)key, strlen((char *)key));
3046 if (obj->oo_hl_head != NULL) {
3047 hlock = osd_oti_get(env)->oti_hlock;
3048 ldiskfs_htree_lock(hlock, obj->oo_hl_head,
3049 dir, LDISKFS_HLOCK_DEL);
3051 down_write(&obj->oo_ext_idx_sem);
3054 bh = osd_ldiskfs_find_entry(dir, dentry, &de, hlock);
3056 rc = ldiskfs_delete_entry(oh->ot_handle,
3063 ldiskfs_htree_unlock(hlock);
3065 up_write(&obj->oo_ext_idx_sem);
3067 LASSERT(osd_invariant(obj));
3072 * Lookup index for \a key and copy record to \a rec.
3074 * \param dt osd index object
3075 * \param key key for index
3076 * \param rec record reference
3078 * \retval +ve success : exact mach
3079 * \retval 0 return record with key not greater than \a key
3080 * \retval -ve failure
3082 static int osd_index_iam_lookup(const struct lu_env *env, struct dt_object *dt,
3083 struct dt_rec *rec, const struct dt_key *key,
3084 struct lustre_capa *capa)
3086 struct osd_object *obj = osd_dt_obj(dt);
3087 struct iam_path_descr *ipd;
3088 struct iam_container *bag = &obj->oo_dir->od_container;
3089 struct osd_thread_info *oti = osd_oti_get(env);
3090 struct iam_iterator *it = &oti->oti_idx_it;
3091 struct iam_rec *iam_rec;
3096 LASSERT(osd_invariant(obj));
3097 LASSERT(dt_object_exists(dt));
3098 LASSERT(bag->ic_object == obj->oo_inode);
3100 if (osd_object_auth(env, dt, capa, CAPA_OPC_INDEX_LOOKUP))
3103 ipd = osd_idx_ipd_get(env, bag);
3107 /* got ipd now we can start iterator. */
3108 iam_it_init(it, bag, 0, ipd);
3110 if (fid_is_quota(lu_object_fid(&dt->do_lu))) {
3111 /* swab quota uid/gid provided by caller */
3112 oti->oti_quota_id = cpu_to_le64(*((__u64 *)key));
3113 key = (const struct dt_key *)&oti->oti_quota_id;
3116 rc = iam_it_get(it, (struct iam_key *)key);
3118 if (S_ISDIR(obj->oo_inode->i_mode))
3119 iam_rec = (struct iam_rec *)oti->oti_ldp;
3121 iam_rec = (struct iam_rec *) rec;
3123 iam_reccpy(&it->ii_path.ip_leaf, (struct iam_rec *)iam_rec);
3125 if (S_ISDIR(obj->oo_inode->i_mode))
3126 osd_fid_unpack((struct lu_fid *) rec,
3127 (struct osd_fid_pack *)iam_rec);
3128 else if (fid_is_quota(lu_object_fid(&dt->do_lu)))
3129 osd_quota_unpack(obj, rec);
3134 osd_ipd_put(env, bag, ipd);
3136 LINVRNT(osd_invariant(obj));
3141 static int osd_index_declare_iam_insert(const struct lu_env *env,
3142 struct dt_object *dt,
3143 const struct dt_rec *rec,
3144 const struct dt_key *key,
3145 struct thandle *handle)
3147 struct osd_thandle *oh;
3149 LASSERT(dt_object_exists(dt));
3150 LASSERT(handle != NULL);
3152 oh = container_of0(handle, struct osd_thandle, ot_super);
3153 LASSERT(oh->ot_handle == NULL);
3155 OSD_DECLARE_OP(oh, insert, osd_dto_credits_noquota[DTO_INDEX_INSERT]);
3161 * Inserts (key, value) pair in \a dt index object.
3163 * \param dt osd index object
3164 * \param key key for index
3165 * \param rec record reference
3166 * \param th transaction handler
3169 * \retval -ve failure
3171 static int osd_index_iam_insert(const struct lu_env *env, struct dt_object *dt,
3172 const struct dt_rec *rec,
3173 const struct dt_key *key, struct thandle *th,
3174 struct lustre_capa *capa, int ignore_quota)
3176 struct osd_object *obj = osd_dt_obj(dt);
3177 struct iam_path_descr *ipd;
3178 struct osd_thandle *oh;
3179 struct iam_container *bag = &obj->oo_dir->od_container;
3180 struct osd_thread_info *oti = osd_oti_get(env);
3181 struct iam_rec *iam_rec;
3186 LINVRNT(osd_invariant(obj));
3187 LASSERT(dt_object_exists(dt));
3188 LASSERT(bag->ic_object == obj->oo_inode);
3189 LASSERT(th != NULL);
3191 if (osd_object_auth(env, dt, capa, CAPA_OPC_INDEX_INSERT))
3194 OSD_EXEC_OP(th, insert);
3196 ipd = osd_idx_ipd_get(env, bag);
3197 if (unlikely(ipd == NULL))
3200 oh = container_of0(th, struct osd_thandle, ot_super);
3201 LASSERT(oh->ot_handle != NULL);
3202 LASSERT(oh->ot_handle->h_transaction != NULL);
3203 if (S_ISDIR(obj->oo_inode->i_mode)) {
3204 iam_rec = (struct iam_rec *)oti->oti_ldp;
3205 osd_fid_pack((struct osd_fid_pack *)iam_rec, rec, &oti->oti_fid);
3206 } else if (fid_is_quota(lu_object_fid(&dt->do_lu))) {
3207 /* pack quota uid/gid */
3208 oti->oti_quota_id = cpu_to_le64(*((__u64 *)key));
3209 key = (const struct dt_key *)&oti->oti_quota_id;
3210 /* pack quota record */
3211 rec = osd_quota_pack(obj, rec, &oti->oti_quota_rec);
3212 iam_rec = (struct iam_rec *)rec;
3214 iam_rec = (struct iam_rec *)rec;
3217 rc = iam_insert(oh->ot_handle, bag, (const struct iam_key *)key,
3219 osd_ipd_put(env, bag, ipd);
3220 LINVRNT(osd_invariant(obj));
3225 * Calls ldiskfs_add_entry() to add directory entry
3226 * into the directory. This is required for
3227 * interoperability mode (b11826)
3229 * \retval 0, on success
3230 * \retval -ve, on error
3232 static int __osd_ea_add_rec(struct osd_thread_info *info,
3233 struct osd_object *pobj, struct inode *cinode,
3234 const char *name, const struct dt_rec *fid,
3235 struct htree_lock *hlock, struct thandle *th)
3237 struct ldiskfs_dentry_param *ldp;
3238 struct dentry *child;
3239 struct osd_thandle *oth;
3242 oth = container_of(th, struct osd_thandle, ot_super);
3243 LASSERT(oth->ot_handle != NULL);
3244 LASSERT(oth->ot_handle->h_transaction != NULL);
3246 child = osd_child_dentry_get(info->oti_env, pobj, name, strlen(name));
3248 /* XXX: remove fid_is_igif() check here.
3249 * IGIF check is just to handle insertion of .. when it is 'ROOT',
3250 * it is IGIF now but needs FID in dir entry as well for readdir
3252 * LU-838 should fix that and remove fid_is_igif() check */
3253 if (fid_is_igif((struct lu_fid *)fid) ||
3254 fid_is_norm((struct lu_fid *)fid)) {
3255 ldp = (struct ldiskfs_dentry_param *)info->oti_ldp;
3256 osd_get_ldiskfs_dirent_param(ldp, fid);
3257 child->d_fsdata = (void *)ldp;
3259 child->d_fsdata = NULL;
3261 LASSERT(pobj->oo_inode);
3262 ll_vfs_dq_init(pobj->oo_inode);
3263 rc = osd_ldiskfs_add_entry(oth->ot_handle, child, cinode, hlock);
3269 * Calls ldiskfs_add_dot_dotdot() to add dot and dotdot entries
3270 * into the directory.Also sets flags into osd object to
3271 * indicate dot and dotdot are created. This is required for
3272 * interoperability mode (b11826)
3274 * \param dir directory for dot and dotdot fixup.
3275 * \param obj child object for linking
3277 * \retval 0, on success
3278 * \retval -ve, on error
3280 static int osd_add_dot_dotdot(struct osd_thread_info *info,
3281 struct osd_object *dir,
3282 struct inode *parent_dir, const char *name,
3283 const struct dt_rec *dot_fid,
3284 const struct dt_rec *dot_dot_fid,
3287 struct inode *inode = dir->oo_inode;
3288 struct ldiskfs_dentry_param *dot_ldp;
3289 struct ldiskfs_dentry_param *dot_dot_ldp;
3290 struct osd_thandle *oth;
3293 oth = container_of(th, struct osd_thandle, ot_super);
3294 LASSERT(oth->ot_handle->h_transaction != NULL);
3295 LASSERT(S_ISDIR(dir->oo_inode->i_mode));
3297 if (strcmp(name, dot) == 0) {
3298 if (dir->oo_compat_dot_created) {
3301 LASSERT(inode == parent_dir);
3302 dir->oo_compat_dot_created = 1;
3305 } else if(strcmp(name, dotdot) == 0) {
3306 dot_ldp = (struct ldiskfs_dentry_param *)info->oti_ldp;
3307 dot_dot_ldp = (struct ldiskfs_dentry_param *)info->oti_ldp2;
3309 if (!dir->oo_compat_dot_created)
3311 if (!fid_is_igif((struct lu_fid *)dot_fid)) {
3312 osd_get_ldiskfs_dirent_param(dot_ldp, dot_fid);
3313 osd_get_ldiskfs_dirent_param(dot_dot_ldp, dot_dot_fid);
3318 /* in case of rename, dotdot is already created */
3319 if (dir->oo_compat_dotdot_created) {
3320 return __osd_ea_add_rec(info, dir, parent_dir, name,
3321 dot_dot_fid, NULL, th);
3324 result = ldiskfs_add_dot_dotdot(oth->ot_handle, parent_dir,
3325 inode, dot_ldp, dot_dot_ldp);
3327 dir->oo_compat_dotdot_created = 1;
3335 * It will call the appropriate osd_add* function and return the
3336 * value, return by respective functions.
3338 static int osd_ea_add_rec(const struct lu_env *env, struct osd_object *pobj,
3339 struct inode *cinode, const char *name,
3340 const struct dt_rec *fid, struct thandle *th)
3342 struct osd_thread_info *info = osd_oti_get(env);
3343 struct htree_lock *hlock;
3346 hlock = pobj->oo_hl_head != NULL ? info->oti_hlock : NULL;
3348 if (name[0] == '.' && (name[1] == '\0' || (name[1] == '.' &&
3350 if (hlock != NULL) {
3351 ldiskfs_htree_lock(hlock, pobj->oo_hl_head,
3354 down_write(&pobj->oo_ext_idx_sem);
3356 rc = osd_add_dot_dotdot(info, pobj, cinode, name,
3357 (struct dt_rec *)lu_object_fid(&pobj->oo_dt.do_lu),
3360 if (hlock != NULL) {
3361 ldiskfs_htree_lock(hlock, pobj->oo_hl_head,
3362 pobj->oo_inode, LDISKFS_HLOCK_ADD);
3364 down_write(&pobj->oo_ext_idx_sem);
3367 rc = __osd_ea_add_rec(info, pobj, cinode, name, fid,
3371 ldiskfs_htree_unlock(hlock);
3373 up_write(&pobj->oo_ext_idx_sem);
3379 osd_consistency_check(struct osd_thread_info *oti, struct osd_device *dev,
3380 struct osd_idmap_cache *oic)
3382 struct osd_scrub *scrub = &dev->od_scrub;
3383 struct lu_fid *fid = &oic->oic_fid;
3384 struct osd_inode_id *id = &oti->oti_id;
3389 if (!fid_is_norm(fid) && !fid_is_igif(fid))
3393 rc = osd_oi_lookup(oti, dev, fid, id);
3394 if (rc != 0 && rc != -ENOENT)
3397 if (rc == 0 && osd_id_eq(id, &oic->oic_lid))
3400 if (thread_is_running(&scrub->os_thread)) {
3401 rc = osd_oii_insert(dev, oic, rc == -ENOENT);
3402 /* There is race condition between osd_oi_lookup and OI scrub.
3403 * The OI scrub finished just after osd_oi_lookup() failure.
3404 * Under such case, it is unnecessary to trigger OI scrub again,
3405 * but try to call osd_oi_lookup() again. */
3406 if (unlikely(rc == -EAGAIN))
3412 if (!dev->od_noscrub && ++once == 1) {
3413 CDEBUG(D_LFSCK, "Trigger OI scrub by RPC for "DFID"\n",
3415 rc = osd_scrub_start(dev);
3416 LCONSOLE_ERROR("%.16s: trigger OI scrub by RPC for "DFID
3418 LDISKFS_SB(osd_sb(dev))->s_es->s_volume_name,
3428 * Calls ->lookup() to find dentry. From dentry get inode and
3429 * read inode's ea to get fid. This is required for interoperability
3432 * \retval 0, on success
3433 * \retval -ve, on error
3435 static int osd_ea_lookup_rec(const struct lu_env *env, struct osd_object *obj,
3436 struct dt_rec *rec, const struct dt_key *key)
3438 struct inode *dir = obj->oo_inode;
3439 struct dentry *dentry;
3440 struct ldiskfs_dir_entry_2 *de;
3441 struct buffer_head *bh;
3442 struct lu_fid *fid = (struct lu_fid *) rec;
3443 struct htree_lock *hlock = NULL;
3447 LASSERT(dir->i_op != NULL && dir->i_op->lookup != NULL);
3449 dentry = osd_child_dentry_get(env, obj,
3450 (char *)key, strlen((char *)key));
3452 if (obj->oo_hl_head != NULL) {
3453 hlock = osd_oti_get(env)->oti_hlock;
3454 ldiskfs_htree_lock(hlock, obj->oo_hl_head,
3455 dir, LDISKFS_HLOCK_LOOKUP);
3457 down_read(&obj->oo_ext_idx_sem);
3460 bh = osd_ldiskfs_find_entry(dir, dentry, &de, hlock);
3462 struct osd_thread_info *oti = osd_oti_get(env);
3463 struct osd_idmap_cache *oic = &oti->oti_cache;
3464 struct osd_device *dev = osd_obj2dev(obj);
3465 struct osd_scrub *scrub = &dev->od_scrub;
3466 struct scrub_file *sf = &scrub->os_file;
3468 ino = le32_to_cpu(de->inode);
3469 rc = osd_get_fid_from_dentry(de, rec);
3471 /* done with de, release bh */
3474 rc = osd_ea_fid_get(env, obj, ino, fid, &oic->oic_lid);
3476 osd_id_gen(&oic->oic_lid, ino, OSD_OII_NOGEN);
3478 fid_zero(&oic->oic_fid);
3482 oic->oic_fid = *fid;
3483 if ((scrub->os_pos_current <= ino) &&
3484 (sf->sf_flags & SF_INCONSISTENT ||
3485 ldiskfs_test_bit(osd_oi_fid2idx(dev, fid),
3487 osd_consistency_check(oti, dev, oic);
3496 ldiskfs_htree_unlock(hlock);
3498 up_read(&obj->oo_ext_idx_sem);
3503 * Find the osd object for given fid.
3505 * \param fid need to find the osd object having this fid
3507 * \retval osd_object on success
3508 * \retval -ve on error
3510 struct osd_object *osd_object_find(const struct lu_env *env,
3511 struct dt_object *dt,
3512 const struct lu_fid *fid)
3514 struct lu_device *ludev = dt->do_lu.lo_dev;
3515 struct osd_object *child = NULL;
3516 struct lu_object *luch;
3517 struct lu_object *lo;
3520 * at this point topdev might not exist yet
3521 * (i.e. MGS is preparing profiles). so we can
3522 * not rely on topdev and instead lookup with
3523 * our device passed as topdev. this can't work
3524 * if the object isn't cached yet (as osd doesn't
3525 * allocate lu_header). IOW, the object must be
3526 * in the cache, otherwise lu_object_alloc() crashes
3529 luch = lu_object_find_at(env, ludev, fid, NULL);
3530 if (!IS_ERR(luch)) {
3531 if (lu_object_exists(luch)) {
3532 lo = lu_object_locate(luch->lo_header, ludev->ld_type);
3534 child = osd_obj(lo);
3536 LU_OBJECT_DEBUG(D_ERROR, env, luch,
3537 "lu_object can't be located"
3538 DFID"\n", PFID(fid));
3540 if (child == NULL) {
3541 lu_object_put(env, luch);
3542 CERROR("Unable to get osd_object\n");
3543 child = ERR_PTR(-ENOENT);
3546 LU_OBJECT_DEBUG(D_ERROR, env, luch,
3547 "lu_object does not exists "DFID"\n",
3549 lu_object_put(env, luch);
3550 child = ERR_PTR(-ENOENT);
3553 child = (void *)luch;
3559 * Put the osd object once done with it.
3561 * \param obj osd object that needs to be put
3563 static inline void osd_object_put(const struct lu_env *env,
3564 struct osd_object *obj)
3566 lu_object_put(env, &obj->oo_dt.do_lu);
3569 static int osd_index_declare_ea_insert(const struct lu_env *env,
3570 struct dt_object *dt,
3571 const struct dt_rec *rec,
3572 const struct dt_key *key,
3573 struct thandle *handle)
3575 struct osd_thandle *oh;
3576 struct inode *inode;
3577 struct lu_fid *fid = (struct lu_fid *)rec;
3581 LASSERT(dt_object_exists(dt));
3582 LASSERT(handle != NULL);
3584 oh = container_of0(handle, struct osd_thandle, ot_super);
3585 LASSERT(oh->ot_handle == NULL);
3587 OSD_DECLARE_OP(oh, insert, osd_dto_credits_noquota[DTO_INDEX_INSERT]);
3589 inode = osd_dt_obj(dt)->oo_inode;
3592 /* We ignore block quota on meta pool (MDTs), so needn't
3593 * calculate how many blocks will be consumed by this index
3595 rc = osd_declare_inode_qid(env, inode->i_uid, inode->i_gid, 0, oh,
3596 true, true, NULL, false);
3600 /* It does fld look up inside declare, and the result will be
3601 * added to fld cache, so the following fld lookup inside insert
3602 * does not need send RPC anymore, so avoid send rpc with holding
3604 LASSERTF(fid_is_sane(fid), "fid is insane"DFID"\n", PFID(fid));
3605 osd_fld_lookup(env, osd_dt_dev(handle->th_dev), fid,
3606 &osd_oti_get(env)->oti_seq_range);
3612 * Index add function for interoperability mode (b11826).
3613 * It will add the directory entry.This entry is needed to
3614 * maintain name->fid mapping.
3616 * \param key it is key i.e. file entry to be inserted
3617 * \param rec it is value of given key i.e. fid
3619 * \retval 0, on success
3620 * \retval -ve, on error
3622 static int osd_index_ea_insert(const struct lu_env *env, struct dt_object *dt,
3623 const struct dt_rec *rec,
3624 const struct dt_key *key, struct thandle *th,
3625 struct lustre_capa *capa, int ignore_quota)
3627 struct osd_object *obj = osd_dt_obj(dt);
3628 struct lu_fid *fid = (struct lu_fid *) rec;
3629 const char *name = (const char *)key;
3630 struct osd_object *child;
3635 LASSERT(osd_invariant(obj));
3636 LASSERT(dt_object_exists(dt));
3637 LASSERT(th != NULL);
3639 if (osd_object_auth(env, dt, capa, CAPA_OPC_INDEX_INSERT))
3642 child = osd_object_find(env, dt, fid);
3643 if (!IS_ERR(child)) {
3644 rc = osd_ea_add_rec(env, obj, child->oo_inode, name, rec, th);
3645 osd_object_put(env, child);
3647 rc = PTR_ERR(child);
3650 LASSERT(osd_invariant(obj));
3655 * Initialize osd Iterator for given osd index object.
3657 * \param dt osd index object
3660 static struct dt_it *osd_it_iam_init(const struct lu_env *env,
3661 struct dt_object *dt,
3663 struct lustre_capa *capa)
3665 struct osd_it_iam *it;
3666 struct osd_thread_info *oti = osd_oti_get(env);
3667 struct osd_object *obj = osd_dt_obj(dt);
3668 struct lu_object *lo = &dt->do_lu;
3669 struct iam_path_descr *ipd;
3670 struct iam_container *bag = &obj->oo_dir->od_container;
3672 LASSERT(lu_object_exists(lo));
3674 if (osd_object_auth(env, dt, capa, CAPA_OPC_BODY_READ))
3675 return ERR_PTR(-EACCES);
3678 ipd = osd_it_ipd_get(env, bag);
3679 if (likely(ipd != NULL)) {
3683 iam_it_init(&it->oi_it, bag, IAM_IT_MOVE, ipd);
3684 return (struct dt_it *)it;
3686 return ERR_PTR(-ENOMEM);
3690 * free given Iterator.
3693 static void osd_it_iam_fini(const struct lu_env *env, struct dt_it *di)
3695 struct osd_it_iam *it = (struct osd_it_iam *)di;
3696 struct osd_object *obj = it->oi_obj;
3698 iam_it_fini(&it->oi_it);
3699 osd_ipd_put(env, &obj->oo_dir->od_container, it->oi_ipd);
3700 lu_object_put(env, &obj->oo_dt.do_lu);
3704 * Move Iterator to record specified by \a key
3706 * \param di osd iterator
3707 * \param key key for index
3709 * \retval +ve di points to record with least key not larger than key
3710 * \retval 0 di points to exact matched key
3711 * \retval -ve failure
3714 static int osd_it_iam_get(const struct lu_env *env,
3715 struct dt_it *di, const struct dt_key *key)
3717 struct osd_thread_info *oti = osd_oti_get(env);
3718 struct osd_it_iam *it = (struct osd_it_iam *)di;
3720 if (fid_is_quota(lu_object_fid(&it->oi_obj->oo_dt.do_lu))) {
3721 /* swab quota uid/gid */
3722 oti->oti_quota_id = cpu_to_le64(*((__u64 *)key));
3723 key = (struct dt_key *)&oti->oti_quota_id;
3726 return iam_it_get(&it->oi_it, (const struct iam_key *)key);
3732 * \param di osd iterator
3735 static void osd_it_iam_put(const struct lu_env *env, struct dt_it *di)
3737 struct osd_it_iam *it = (struct osd_it_iam *)di;
3739 iam_it_put(&it->oi_it);
3743 * Move iterator by one record
3745 * \param di osd iterator
3747 * \retval +1 end of container reached
3749 * \retval -ve failure
3752 static int osd_it_iam_next(const struct lu_env *env, struct dt_it *di)
3754 struct osd_it_iam *it = (struct osd_it_iam *)di;
3756 return iam_it_next(&it->oi_it);
3760 * Return pointer to the key under iterator.
3763 static struct dt_key *osd_it_iam_key(const struct lu_env *env,
3764 const struct dt_it *di)
3766 struct osd_thread_info *oti = osd_oti_get(env);
3767 struct osd_it_iam *it = (struct osd_it_iam *)di;
3768 struct osd_object *obj = it->oi_obj;
3771 key = (struct dt_key *)iam_it_key_get(&it->oi_it);
3773 if (!IS_ERR(key) && fid_is_quota(lu_object_fid(&obj->oo_dt.do_lu))) {
3774 /* swab quota uid/gid */
3775 oti->oti_quota_id = le64_to_cpu(*((__u64 *)key));
3776 key = (struct dt_key *)&oti->oti_quota_id;
3783 * Return size of key under iterator (in bytes)
3786 static int osd_it_iam_key_size(const struct lu_env *env, const struct dt_it *di)
3788 struct osd_it_iam *it = (struct osd_it_iam *)di;
3790 return iam_it_key_size(&it->oi_it);
3793 static inline void osd_it_append_attrs(struct lu_dirent *ent, __u32 attr,
3794 int len, __u16 type)
3796 struct luda_type *lt;
3797 const unsigned align = sizeof(struct luda_type) - 1;
3799 /* check if file type is required */
3800 if (attr & LUDA_TYPE) {
3801 len = (len + align) & ~align;
3803 lt = (void *) ent->lde_name + len;
3804 lt->lt_type = cpu_to_le16(CFS_DTTOIF(type));
3805 ent->lde_attrs |= LUDA_TYPE;
3808 ent->lde_attrs = cpu_to_le32(ent->lde_attrs);
3812 * build lu direct from backend fs dirent.
3815 static inline void osd_it_pack_dirent(struct lu_dirent *ent,
3816 struct lu_fid *fid, __u64 offset,
3817 char *name, __u16 namelen,
3818 __u16 type, __u32 attr)
3820 fid_cpu_to_le(&ent->lde_fid, fid);
3821 ent->lde_attrs = LUDA_FID;
3823 ent->lde_hash = cpu_to_le64(offset);
3824 ent->lde_reclen = cpu_to_le16(lu_dirent_calc_size(namelen, attr));
3826 strncpy(ent->lde_name, name, namelen);
3827 ent->lde_namelen = cpu_to_le16(namelen);
3829 /* append lustre attributes */
3830 osd_it_append_attrs(ent, attr, namelen, type);
3834 * Return pointer to the record under iterator.
3836 static int osd_it_iam_rec(const struct lu_env *env,
3837 const struct dt_it *di,
3838 struct dt_rec *dtrec, __u32 attr)
3840 struct osd_it_iam *it = (struct osd_it_iam *)di;
3841 struct osd_thread_info *info = osd_oti_get(env);
3844 if (S_ISDIR(it->oi_obj->oo_inode->i_mode)) {
3845 const struct osd_fid_pack *rec;
3846 struct lu_fid *fid = &info->oti_fid;
3847 struct lu_dirent *lde = (struct lu_dirent *)dtrec;
3853 name = (char *)iam_it_key_get(&it->oi_it);
3855 RETURN(PTR_ERR(name));
3857 namelen = iam_it_key_size(&it->oi_it);
3859 rec = (const struct osd_fid_pack *)iam_it_rec_get(&it->oi_it);
3861 RETURN(PTR_ERR(rec));
3863 rc = osd_fid_unpack(fid, rec);
3867 hash = iam_it_store(&it->oi_it);
3869 /* IAM does not store object type in IAM index (dir) */
3870 osd_it_pack_dirent(lde, fid, hash, name, namelen,
3872 } else if (fid_is_quota(lu_object_fid(&it->oi_obj->oo_dt.do_lu))) {
3873 iam_reccpy(&it->oi_it.ii_path.ip_leaf,
3874 (struct iam_rec *)dtrec);
3875 osd_quota_unpack(it->oi_obj, dtrec);
3877 iam_reccpy(&it->oi_it.ii_path.ip_leaf,
3878 (struct iam_rec *)dtrec);
3885 * Returns cookie for current Iterator position.
3887 static __u64 osd_it_iam_store(const struct lu_env *env, const struct dt_it *di)
3889 struct osd_it_iam *it = (struct osd_it_iam *)di;
3891 return iam_it_store(&it->oi_it);
3895 * Restore iterator from cookie.
3897 * \param di osd iterator
3898 * \param hash Iterator location cookie
3900 * \retval +ve di points to record with least key not larger than key.
3901 * \retval 0 di points to exact matched key
3902 * \retval -ve failure
3905 static int osd_it_iam_load(const struct lu_env *env,
3906 const struct dt_it *di, __u64 hash)
3908 struct osd_it_iam *it = (struct osd_it_iam *)di;
3910 return iam_it_load(&it->oi_it, hash);
3913 static const struct dt_index_operations osd_index_iam_ops = {
3914 .dio_lookup = osd_index_iam_lookup,
3915 .dio_declare_insert = osd_index_declare_iam_insert,
3916 .dio_insert = osd_index_iam_insert,
3917 .dio_declare_delete = osd_index_declare_iam_delete,
3918 .dio_delete = osd_index_iam_delete,
3920 .init = osd_it_iam_init,
3921 .fini = osd_it_iam_fini,
3922 .get = osd_it_iam_get,
3923 .put = osd_it_iam_put,
3924 .next = osd_it_iam_next,
3925 .key = osd_it_iam_key,
3926 .key_size = osd_it_iam_key_size,
3927 .rec = osd_it_iam_rec,
3928 .store = osd_it_iam_store,
3929 .load = osd_it_iam_load
3935 * Creates or initializes iterator context.
3937 * \retval struct osd_it_ea, iterator structure on success
3940 static struct dt_it *osd_it_ea_init(const struct lu_env *env,
3941 struct dt_object *dt,
3943 struct lustre_capa *capa)
3945 struct osd_object *obj = osd_dt_obj(dt);
3946 struct osd_thread_info *info = osd_oti_get(env);
3947 struct osd_it_ea *it = &info->oti_it_ea;
3948 struct lu_object *lo = &dt->do_lu;
3949 struct dentry *obj_dentry = &info->oti_it_dentry;
3951 LASSERT(lu_object_exists(lo));
3953 obj_dentry->d_inode = obj->oo_inode;
3954 obj_dentry->d_sb = osd_sb(osd_obj2dev(obj));
3955 obj_dentry->d_name.hash = 0;
3957 it->oie_rd_dirent = 0;
3958 it->oie_it_dirent = 0;
3959 it->oie_dirent = NULL;
3960 it->oie_buf = info->oti_it_ea_buf;
3962 it->oie_file.f_pos = 0;
3963 it->oie_file.f_dentry = obj_dentry;
3964 if (attr & LUDA_64BITHASH)
3965 it->oie_file.f_mode |= FMODE_64BITHASH;
3967 it->oie_file.f_mode |= FMODE_32BITHASH;
3968 it->oie_file.f_mapping = obj->oo_inode->i_mapping;
3969 it->oie_file.f_op = obj->oo_inode->i_fop;
3970 it->oie_file.private_data = NULL;
3972 RETURN((struct dt_it *) it);
3976 * Destroy or finishes iterator context.
3978 * \param di iterator structure to be destroyed
3980 static void osd_it_ea_fini(const struct lu_env *env, struct dt_it *di)
3982 struct osd_it_ea *it = (struct osd_it_ea *)di;
3983 struct osd_object *obj = it->oie_obj;
3984 struct inode *inode = obj->oo_inode;
3987 it->oie_file.f_op->release(inode, &it->oie_file);
3988 lu_object_put(env, &obj->oo_dt.do_lu);
3993 * It position the iterator at given key, so that next lookup continues from
3994 * that key Or it is similar to dio_it->load() but based on a key,
3995 * rather than file position.
3997 * As a special convention, osd_it_ea_get(env, di, "") has to rewind iterator
4000 * TODO: Presently return +1 considering it is only used by mdd_dir_is_empty().
4002 static int osd_it_ea_get(const struct lu_env *env,
4003 struct dt_it *di, const struct dt_key *key)
4005 struct osd_it_ea *it = (struct osd_it_ea *)di;
4008 LASSERT(((const char *)key)[0] == '\0');
4009 it->oie_file.f_pos = 0;
4010 it->oie_rd_dirent = 0;
4011 it->oie_it_dirent = 0;
4012 it->oie_dirent = NULL;
4020 static void osd_it_ea_put(const struct lu_env *env, struct dt_it *di)
4025 * It is called internally by ->readdir(). It fills the
4026 * iterator's in-memory data structure with required
4027 * information i.e. name, namelen, rec_size etc.
4029 * \param buf in which information to be filled in.
4030 * \param name name of the file in given dir
4032 * \retval 0 on success
4033 * \retval 1 on buffer full
4035 static int osd_ldiskfs_filldir(char *buf, const char *name, int namelen,
4036 loff_t offset, __u64 ino,
4039 struct osd_it_ea *it = (struct osd_it_ea *)buf;
4040 struct osd_it_ea_dirent *ent = it->oie_dirent;
4041 struct lu_fid *fid = &ent->oied_fid;
4042 struct osd_fid_pack *rec;
4045 /* this should never happen */
4046 if (unlikely(namelen == 0 || namelen > LDISKFS_NAME_LEN)) {
4047 CERROR("ldiskfs return invalid namelen %d\n", namelen);
4051 if ((void *) ent - it->oie_buf + sizeof(*ent) + namelen >
4055 if (d_type & LDISKFS_DIRENT_LUFID) {
4056 rec = (struct osd_fid_pack*) (name + namelen + 1);
4058 if (osd_fid_unpack(fid, rec) != 0)
4061 d_type &= ~LDISKFS_DIRENT_LUFID;
4066 ent->oied_ino = ino;
4067 ent->oied_off = offset;
4068 ent->oied_namelen = namelen;
4069 ent->oied_type = d_type;
4071 memcpy(ent->oied_name, name, namelen);
4073 it->oie_rd_dirent++;
4074 it->oie_dirent = (void *) ent + cfs_size_round(sizeof(*ent) + namelen);
4079 * Calls ->readdir() to load a directory entry at a time
4080 * and stored it in iterator's in-memory data structure.
4082 * \param di iterator's in memory structure
4084 * \retval 0 on success
4085 * \retval -ve on error
4087 static int osd_ldiskfs_it_fill(const struct lu_env *env,
4088 const struct dt_it *di)
4090 struct osd_it_ea *it = (struct osd_it_ea *)di;
4091 struct osd_object *obj = it->oie_obj;
4092 struct inode *inode = obj->oo_inode;
4093 struct htree_lock *hlock = NULL;
4097 it->oie_dirent = it->oie_buf;
4098 it->oie_rd_dirent = 0;
4100 if (obj->oo_hl_head != NULL) {
4101 hlock = osd_oti_get(env)->oti_hlock;
4102 ldiskfs_htree_lock(hlock, obj->oo_hl_head,
4103 inode, LDISKFS_HLOCK_READDIR);
4105 down_read(&obj->oo_ext_idx_sem);
4108 result = inode->i_fop->readdir(&it->oie_file, it,
4109 (filldir_t) osd_ldiskfs_filldir);
4112 ldiskfs_htree_unlock(hlock);
4114 up_read(&obj->oo_ext_idx_sem);
4116 if (it->oie_rd_dirent == 0) {
4119 it->oie_dirent = it->oie_buf;
4120 it->oie_it_dirent = 1;
4127 * It calls osd_ldiskfs_it_fill() which will use ->readdir()
4128 * to load a directory entry at a time and stored it in
4129 * iterator's in-memory data structure.
4131 * \param di iterator's in memory structure
4133 * \retval +ve iterator reached to end
4134 * \retval 0 iterator not reached to end
4135 * \retval -ve on error
4137 static int osd_it_ea_next(const struct lu_env *env, struct dt_it *di)
4139 struct osd_it_ea *it = (struct osd_it_ea *)di;
4144 if (it->oie_it_dirent < it->oie_rd_dirent) {
4146 (void *) it->oie_dirent +
4147 cfs_size_round(sizeof(struct osd_it_ea_dirent) +
4148 it->oie_dirent->oied_namelen);
4149 it->oie_it_dirent++;
4152 if (it->oie_file.f_pos == ldiskfs_get_htree_eof(&it->oie_file))
4155 rc = osd_ldiskfs_it_fill(env, di);
4162 * Returns the key at current position from iterator's in memory structure.
4164 * \param di iterator's in memory structure
4166 * \retval key i.e. struct dt_key on success
4168 static struct dt_key *osd_it_ea_key(const struct lu_env *env,
4169 const struct dt_it *di)
4171 struct osd_it_ea *it = (struct osd_it_ea *)di;
4173 return (struct dt_key *)it->oie_dirent->oied_name;
4177 * Returns the key's size at current position from iterator's in memory structure.
4179 * \param di iterator's in memory structure
4181 * \retval key_size i.e. struct dt_key on success
4183 static int osd_it_ea_key_size(const struct lu_env *env, const struct dt_it *di)
4185 struct osd_it_ea *it = (struct osd_it_ea *)di;
4187 return it->oie_dirent->oied_namelen;
4192 * Returns the value (i.e. fid/igif) at current position from iterator's
4193 * in memory structure.
4195 * \param di struct osd_it_ea, iterator's in memory structure
4196 * \param attr attr requested for dirent.
4197 * \param lde lustre dirent
4199 * \retval 0 no error and \param lde has correct lustre dirent.
4200 * \retval -ve on error
4202 static inline int osd_it_ea_rec(const struct lu_env *env,
4203 const struct dt_it *di,
4204 struct dt_rec *dtrec, __u32 attr)
4206 struct osd_it_ea *it = (struct osd_it_ea *)di;
4207 struct osd_object *obj = it->oie_obj;
4208 struct osd_device *dev = osd_obj2dev(obj);
4209 struct osd_scrub *scrub = &dev->od_scrub;
4210 struct scrub_file *sf = &scrub->os_file;
4211 struct osd_thread_info *oti = osd_oti_get(env);
4212 struct osd_idmap_cache *oic = &oti->oti_cache;
4213 struct lu_fid *fid = &it->oie_dirent->oied_fid;
4214 struct lu_dirent *lde = (struct lu_dirent *)dtrec;
4215 __u32 ino = it->oie_dirent->oied_ino;
4219 if (!fid_is_sane(fid)) {
4220 rc = osd_ea_fid_get(env, obj, ino, fid, &oic->oic_lid);
4222 fid_zero(&oic->oic_fid);
4226 osd_id_gen(&oic->oic_lid, ino, OSD_OII_NOGEN);
4229 osd_it_pack_dirent(lde, fid, it->oie_dirent->oied_off,
4230 it->oie_dirent->oied_name,
4231 it->oie_dirent->oied_namelen,
4232 it->oie_dirent->oied_type, attr);
4233 oic->oic_fid = *fid;
4234 if ((scrub->os_pos_current <= ino) &&
4235 (sf->sf_flags & SF_INCONSISTENT ||
4236 ldiskfs_test_bit(osd_oi_fid2idx(dev, fid), sf->sf_oi_bitmap)))
4237 osd_consistency_check(oti, dev, oic);
4243 * Returns a cookie for current position of the iterator head, so that
4244 * user can use this cookie to load/start the iterator next time.
4246 * \param di iterator's in memory structure
4248 * \retval cookie for current position, on success
4250 static __u64 osd_it_ea_store(const struct lu_env *env, const struct dt_it *di)
4252 struct osd_it_ea *it = (struct osd_it_ea *)di;
4254 return it->oie_dirent->oied_off;
4258 * It calls osd_ldiskfs_it_fill() which will use ->readdir()
4259 * to load a directory entry at a time and stored it i inn,
4260 * in iterator's in-memory data structure.
4262 * \param di struct osd_it_ea, iterator's in memory structure
4264 * \retval +ve on success
4265 * \retval -ve on error
4267 static int osd_it_ea_load(const struct lu_env *env,
4268 const struct dt_it *di, __u64 hash)
4270 struct osd_it_ea *it = (struct osd_it_ea *)di;
4274 it->oie_file.f_pos = hash;
4276 rc = osd_ldiskfs_it_fill(env, di);
4284 * Index lookup function for interoperability mode (b11826).
4286 * \param key, key i.e. file name to be searched
4288 * \retval +ve, on success
4289 * \retval -ve, on error
4291 static int osd_index_ea_lookup(const struct lu_env *env, struct dt_object *dt,
4292 struct dt_rec *rec, const struct dt_key *key,
4293 struct lustre_capa *capa)
4295 struct osd_object *obj = osd_dt_obj(dt);
4300 LASSERT(S_ISDIR(obj->oo_inode->i_mode));
4301 LINVRNT(osd_invariant(obj));
4303 if (osd_object_auth(env, dt, capa, CAPA_OPC_INDEX_LOOKUP))
4306 rc = osd_ea_lookup_rec(env, obj, rec, key);
4313 * Index and Iterator operations for interoperability
4314 * mode (i.e. to run 2.0 mds on 1.8 disk) (b11826)
4316 static const struct dt_index_operations osd_index_ea_ops = {
4317 .dio_lookup = osd_index_ea_lookup,
4318 .dio_declare_insert = osd_index_declare_ea_insert,
4319 .dio_insert = osd_index_ea_insert,
4320 .dio_declare_delete = osd_index_declare_ea_delete,
4321 .dio_delete = osd_index_ea_delete,
4323 .init = osd_it_ea_init,
4324 .fini = osd_it_ea_fini,
4325 .get = osd_it_ea_get,
4326 .put = osd_it_ea_put,
4327 .next = osd_it_ea_next,
4328 .key = osd_it_ea_key,
4329 .key_size = osd_it_ea_key_size,
4330 .rec = osd_it_ea_rec,
4331 .store = osd_it_ea_store,
4332 .load = osd_it_ea_load
4336 static void *osd_key_init(const struct lu_context *ctx,
4337 struct lu_context_key *key)
4339 struct osd_thread_info *info;
4341 OBD_ALLOC_PTR(info);
4343 return ERR_PTR(-ENOMEM);
4345 OBD_ALLOC(info->oti_it_ea_buf, OSD_IT_EA_BUFSIZE);
4346 if (info->oti_it_ea_buf == NULL)
4349 info->oti_env = container_of(ctx, struct lu_env, le_ctx);
4351 info->oti_hlock = ldiskfs_htree_lock_alloc();
4352 if (info->oti_hlock == NULL)
4358 OBD_FREE(info->oti_it_ea_buf, OSD_IT_EA_BUFSIZE);
4361 return ERR_PTR(-ENOMEM);
4364 static void osd_key_fini(const struct lu_context *ctx,
4365 struct lu_context_key *key, void* data)
4367 struct osd_thread_info *info = data;
4369 if (info->oti_hlock != NULL)
4370 ldiskfs_htree_lock_free(info->oti_hlock);
4371 OBD_FREE(info->oti_it_ea_buf, OSD_IT_EA_BUFSIZE);
4375 static void osd_key_exit(const struct lu_context *ctx,
4376 struct lu_context_key *key, void *data)
4378 struct osd_thread_info *info = data;
4380 LASSERT(info->oti_r_locks == 0);
4381 LASSERT(info->oti_w_locks == 0);
4382 LASSERT(info->oti_txns == 0);
4385 /* type constructor/destructor: osd_type_init, osd_type_fini */
4386 LU_TYPE_INIT_FINI(osd, &osd_key);
4388 struct lu_context_key osd_key = {
4389 .lct_tags = LCT_DT_THREAD | LCT_MD_THREAD | LCT_MG_THREAD | LCT_LOCAL,
4390 .lct_init = osd_key_init,
4391 .lct_fini = osd_key_fini,
4392 .lct_exit = osd_key_exit
4396 static int osd_device_init(const struct lu_env *env, struct lu_device *d,
4397 const char *name, struct lu_device *next)
4399 struct osd_device *osd = osd_dev(d);
4401 strncpy(osd->od_svname, name, MAX_OBD_NAME);
4402 return osd_procfs_init(osd, name);
4405 static int osd_shutdown(const struct lu_env *env, struct osd_device *o)
4409 osd_scrub_cleanup(env, o);
4412 fsfilt_put_ops(o->od_fsops);
4416 /* shutdown quota slave instance associated with the device */
4417 if (o->od_quota_slave != NULL) {
4418 qsd_fini(env, o->od_quota_slave);
4419 o->od_quota_slave = NULL;
4425 static int osd_mount(const struct lu_env *env,
4426 struct osd_device *o, struct lustre_cfg *cfg)
4428 const char *name = lustre_cfg_string(cfg, 0);
4429 const char *dev = lustre_cfg_string(cfg, 1);
4431 unsigned long page, s_flags, lmd_flags = 0;
4432 struct page *__page;
4433 struct file_system_type *type;
4434 char *options = NULL;
4439 if (o->od_mnt != NULL)
4442 if (strlen(dev) >= sizeof(o->od_mntdev))
4444 strcpy(o->od_mntdev, dev);
4446 o->od_fsops = fsfilt_get_ops(mt_str(LDD_MT_LDISKFS));
4447 if (o->od_fsops == NULL) {
4448 CERROR("Can't find fsfilt_ldiskfs\n");
4452 OBD_PAGE_ALLOC(__page, CFS_ALLOC_STD);
4454 GOTO(out, rc = -ENOMEM);
4456 str = lustre_cfg_string(cfg, 2);
4457 s_flags = simple_strtoul(str, NULL, 0);
4458 str = strstr(str, ":");
4460 lmd_flags = simple_strtoul(str + 1, NULL, 0);
4461 opts = lustre_cfg_string(cfg, 3);
4462 page = (unsigned long)cfs_page_address(__page);
4463 options = (char *)page;
4466 strcat(options, "user_xattr,acl");
4468 strcat(options, opts);
4470 /* Glom up mount options */
4471 if (*options != '\0')
4472 strcat(options, ",");
4473 strlcat(options, "no_mbcache", CFS_PAGE_SIZE);
4475 type = get_fs_type("ldiskfs");
4477 CERROR("%s: cannot find ldiskfs module\n", name);
4478 GOTO(out, rc = -ENODEV);
4481 o->od_mnt = vfs_kern_mount(type, s_flags, dev, options);
4482 cfs_module_put(type->owner);
4484 if (IS_ERR(o->od_mnt)) {
4485 rc = PTR_ERR(o->od_mnt);
4486 CERROR("%s: can't mount %s: %d\n", name, dev, rc);
4491 if (lvfs_check_rdonly(o->od_mnt->mnt_sb->s_bdev)) {
4492 CERROR("%s: underlying device %s is marked as read-only. "
4493 "Setup failed\n", name, dev);
4496 GOTO(out, rc = -EROFS);
4499 if (!LDISKFS_HAS_COMPAT_FEATURE(o->od_mnt->mnt_sb,
4500 LDISKFS_FEATURE_COMPAT_HAS_JOURNAL)) {
4501 CERROR("%s: device %s is mounted w/o journal\n", name, dev);
4504 GOTO(out, rc = -EINVAL);
4507 if (lmd_flags & LMD_FLG_NOSCRUB)
4512 OBD_PAGE_FREE(__page);
4514 fsfilt_put_ops(o->od_fsops);
4519 static struct lu_device *osd_device_fini(const struct lu_env *env,
4520 struct lu_device *d)
4525 rc = osd_shutdown(env, osd_dev(d));
4527 osd_obj_map_fini(osd_dev(d));
4529 shrink_dcache_sb(osd_sb(osd_dev(d)));
4530 osd_sync(env, lu2dt_dev(d));
4532 rc = osd_procfs_fini(osd_dev(d));
4534 CERROR("proc fini error %d \n", rc);
4535 RETURN (ERR_PTR(rc));
4538 if (osd_dev(d)->od_mnt) {
4539 mntput(osd_dev(d)->od_mnt);
4540 osd_dev(d)->od_mnt = NULL;
4546 static int osd_device_init0(const struct lu_env *env,
4547 struct osd_device *o,
4548 struct lustre_cfg *cfg)
4550 struct lu_device *l = osd2lu_dev(o);
4551 struct osd_thread_info *info;
4554 /* if the module was re-loaded, env can loose its keys */
4555 rc = lu_env_refill((struct lu_env *) env);
4558 info = osd_oti_get(env);
4561 l->ld_ops = &osd_lu_ops;
4562 o->od_dt_dev.dd_ops = &osd_dt_ops;
4564 spin_lock_init(&o->od_osfs_lock);
4565 mutex_init(&o->od_otable_mutex);
4566 o->od_osfs_age = cfs_time_shift_64(-1000);
4568 o->od_capa_hash = init_capa_hash();
4569 if (o->od_capa_hash == NULL)
4570 GOTO(out, rc = -ENOMEM);
4572 o->od_read_cache = 1;
4573 o->od_writethrough_cache = 1;
4574 o->od_readcache_max_filesize = OSD_MAX_CACHE_SIZE;
4576 rc = osd_mount(env, o, cfg);
4580 /* setup scrub, including OI files initialization */
4581 rc = osd_scrub_setup(env, o);
4585 strncpy(o->od_svname, lustre_cfg_string(cfg, 4),
4586 sizeof(o->od_svname) - 1);
4588 rc = osd_obj_map_init(o);
4590 GOTO(out_scrub, rc);
4592 rc = lu_site_init(&o->od_site, l);
4594 GOTO(out_compat, rc);
4595 o->od_site.ls_bottom_dev = l;
4597 rc = lu_site_init_finish(&o->od_site);
4601 rc = osd_procfs_init(o, o->od_svname);
4603 CERROR("%s: can't initialize procfs: rc = %d\n",
4608 LASSERT(l->ld_site->ls_linkage.next && l->ld_site->ls_linkage.prev);
4610 /* initialize quota slave instance */
4611 o->od_quota_slave = qsd_init(env, o->od_svname, &o->od_dt_dev,
4613 if (IS_ERR(o->od_quota_slave)) {
4614 rc = PTR_ERR(o->od_quota_slave);
4615 o->od_quota_slave = NULL;
4616 GOTO(out_procfs, rc);
4623 lu_site_fini(&o->od_site);
4625 osd_obj_map_fini(o);
4627 osd_scrub_cleanup(env, o);
4629 osd_oi_fini(info, o);
4630 osd_shutdown(env, o);
4634 cleanup_capa_hash(o->od_capa_hash);
4639 static struct lu_device *osd_device_alloc(const struct lu_env *env,
4640 struct lu_device_type *t,
4641 struct lustre_cfg *cfg)
4643 struct osd_device *o;
4648 return ERR_PTR(-ENOMEM);
4650 rc = dt_device_init(&o->od_dt_dev, t);
4652 /* Because the ctx might be revived in dt_device_init,
4653 * refill the env here */
4654 lu_env_refill((struct lu_env *)env);
4655 rc = osd_device_init0(env, o, cfg);
4657 dt_device_fini(&o->od_dt_dev);
4660 if (unlikely(rc != 0))
4663 return rc == 0 ? osd2lu_dev(o) : ERR_PTR(rc);
4666 static struct lu_device *osd_device_free(const struct lu_env *env,
4667 struct lu_device *d)
4669 struct osd_device *o = osd_dev(d);
4672 cleanup_capa_hash(o->od_capa_hash);
4673 /* XXX: make osd top device in order to release reference */
4674 d->ld_site->ls_top_dev = d;
4675 lu_site_purge(env, d->ld_site, -1);
4676 if (!cfs_hash_is_empty(d->ld_site->ls_obj_hash)) {
4677 LIBCFS_DEBUG_MSG_DATA_DECL(msgdata, D_ERROR, NULL);
4678 lu_site_print(env, d->ld_site, &msgdata, lu_cdebug_printer);
4680 lu_site_fini(&o->od_site);
4681 dt_device_fini(&o->od_dt_dev);
4686 static int osd_process_config(const struct lu_env *env,
4687 struct lu_device *d, struct lustre_cfg *cfg)
4689 struct osd_device *o = osd_dev(d);
4693 switch(cfg->lcfg_command) {
4695 err = osd_mount(env, o, cfg);
4698 lu_dev_del_linkage(d->ld_site, d);
4699 err = osd_shutdown(env, o);
4708 static int osd_recovery_complete(const struct lu_env *env,
4709 struct lu_device *d)
4711 struct osd_device *osd = osd_dev(d);
4715 if (osd->od_quota_slave == NULL)
4718 /* start qsd instance on recovery completion, this notifies the quota
4719 * slave code that we are about to process new requests now */
4720 rc = qsd_start(env, osd->od_quota_slave);
4725 * we use exports to track all osd users
4727 static int osd_obd_connect(const struct lu_env *env, struct obd_export **exp,
4728 struct obd_device *obd, struct obd_uuid *cluuid,
4729 struct obd_connect_data *data, void *localdata)
4731 struct osd_device *osd = osd_dev(obd->obd_lu_dev);
4732 struct lustre_handle conn;
4736 CDEBUG(D_CONFIG, "connect #%d\n", osd->od_connects);
4738 rc = class_connect(&conn, obd, cluuid);
4742 *exp = class_conn2export(&conn);
4744 spin_lock(&osd->od_osfs_lock);
4746 spin_unlock(&osd->od_osfs_lock);
4752 * once last export (we don't count self-export) disappeared
4753 * osd can be released
4755 static int osd_obd_disconnect(struct obd_export *exp)
4757 struct obd_device *obd = exp->exp_obd;
4758 struct osd_device *osd = osd_dev(obd->obd_lu_dev);
4759 int rc, release = 0;
4762 /* Only disconnect the underlying layers on the final disconnect. */
4763 spin_lock(&osd->od_osfs_lock);
4765 if (osd->od_connects == 0)
4767 spin_unlock(&osd->od_osfs_lock);
4769 rc = class_disconnect(exp); /* bz 9811 */
4771 if (rc == 0 && release)
4772 class_manual_cleanup(obd);
4776 static int osd_prepare(const struct lu_env *env, struct lu_device *pdev,
4777 struct lu_device *dev)
4779 struct osd_device *osd = osd_dev(dev);
4783 if (dev->ld_site && lu_device_is_md(dev->ld_site->ls_top_dev)) {
4784 /* MDT/MDD still use old infrastructure to create
4786 result = llo_local_objects_setup(env, lu2md_dev(pdev),
4792 if (osd->od_quota_slave != NULL)
4793 /* set up quota slave objects */
4794 result = qsd_prepare(env, osd->od_quota_slave);
4799 static const struct lu_object_operations osd_lu_obj_ops = {
4800 .loo_object_init = osd_object_init,
4801 .loo_object_delete = osd_object_delete,
4802 .loo_object_release = osd_object_release,
4803 .loo_object_free = osd_object_free,
4804 .loo_object_print = osd_object_print,
4805 .loo_object_invariant = osd_object_invariant
4808 const struct lu_device_operations osd_lu_ops = {
4809 .ldo_object_alloc = osd_object_alloc,
4810 .ldo_process_config = osd_process_config,
4811 .ldo_recovery_complete = osd_recovery_complete,
4812 .ldo_prepare = osd_prepare,
4815 static const struct lu_device_type_operations osd_device_type_ops = {
4816 .ldto_init = osd_type_init,
4817 .ldto_fini = osd_type_fini,
4819 .ldto_start = osd_type_start,
4820 .ldto_stop = osd_type_stop,
4822 .ldto_device_alloc = osd_device_alloc,
4823 .ldto_device_free = osd_device_free,
4825 .ldto_device_init = osd_device_init,
4826 .ldto_device_fini = osd_device_fini
4829 struct lu_device_type osd_device_type = {
4830 .ldt_tags = LU_DEVICE_DT,
4831 .ldt_name = LUSTRE_OSD_LDISKFS_NAME,
4832 .ldt_ops = &osd_device_type_ops,
4833 .ldt_ctx_tags = LCT_LOCAL,
4837 * lprocfs legacy support.
4839 static struct obd_ops osd_obd_device_ops = {
4840 .o_owner = THIS_MODULE,
4841 .o_connect = osd_obd_connect,
4842 .o_disconnect = osd_obd_disconnect
4845 static int __init osd_mod_init(void)
4847 struct lprocfs_static_vars lvars;
4850 lprocfs_osd_init_vars(&lvars);
4851 return class_register_type(&osd_obd_device_ops, NULL, lvars.module_vars,
4852 LUSTRE_OSD_LDISKFS_NAME, &osd_device_type);
4855 static void __exit osd_mod_exit(void)
4857 class_unregister_type(LUSTRE_OSD_LDISKFS_NAME);
4860 MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");
4861 MODULE_DESCRIPTION("Lustre Object Storage Device ("LUSTRE_OSD_LDISKFS_NAME")");
4862 MODULE_LICENSE("GPL");
4864 cfs_module(osd, "0.1.0", osd_mod_init, osd_mod_exit);