4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
27 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2011, 2012, Whamcloud, Inc.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * lustre/osd/osd_handler.c
38 * Top-level entry points into osd module
40 * Author: Nikita Danilov <nikita@clusterfs.com>
41 * Pravin Shelar <pravin.shelar@sun.com> : Added fid in dirent
44 #define DEBUG_SUBSYSTEM S_MDS
46 #include <linux/module.h>
48 /* LUSTRE_VERSION_CODE */
49 #include <lustre_ver.h>
50 /* prerequisite for linux/xattr.h */
51 #include <linux/types.h>
52 /* prerequisite for linux/xattr.h */
54 /* XATTR_{REPLACE,CREATE} */
55 #include <linux/xattr.h>
60 * struct OBD_{ALLOC,FREE}*()
63 #include <obd_support.h>
64 /* struct ptlrpc_thread */
65 #include <lustre_net.h>
68 #include <lustre_fid.h>
70 #include "osd_internal.h"
73 /* llo_* api support */
74 #include <md_object.h>
75 #include <lustre_quota.h>
77 #ifdef HAVE_LDISKFS_PDO
79 CFS_MODULE_PARM(ldiskfs_pdo, "i", int, 0644,
80 "ldiskfs with parallel directory operations");
85 static const char dot[] = ".";
86 static const char dotdot[] = "..";
87 static const char remote_obj_dir[] = "REM_OBJ_DIR";
89 static const struct lu_object_operations osd_lu_obj_ops;
90 static const struct dt_object_operations osd_obj_ops;
91 static const struct dt_object_operations osd_obj_ea_ops;
92 static const struct dt_object_operations osd_obj_otable_it_ops;
93 static const struct dt_index_operations osd_index_iam_ops;
94 static const struct dt_index_operations osd_index_ea_ops;
96 static int osd_has_index(const struct osd_object *obj)
98 return obj->oo_dt.do_index_ops != NULL;
101 static int osd_object_invariant(const struct lu_object *l)
103 return osd_invariant(osd_obj(l));
107 * Concurrency: doesn't matter
109 static int osd_read_locked(const struct lu_env *env, struct osd_object *o)
111 return osd_oti_get(env)->oti_r_locks > 0;
115 * Concurrency: doesn't matter
117 static int osd_write_locked(const struct lu_env *env, struct osd_object *o)
119 struct osd_thread_info *oti = osd_oti_get(env);
120 return oti->oti_w_locks > 0 && o->oo_owner == env;
124 * Concurrency: doesn't access mutable data
126 static int osd_root_get(const struct lu_env *env,
127 struct dt_device *dev, struct lu_fid *f)
129 lu_local_obj_fid(f, OSD_FS_ROOT_OID);
134 * OSD object methods.
138 * Concurrency: no concurrent access is possible that early in object
141 static struct lu_object *osd_object_alloc(const struct lu_env *env,
142 const struct lu_object_header *hdr,
145 struct osd_object *mo;
151 l = &mo->oo_dt.do_lu;
152 dt_object_init(&mo->oo_dt, NULL, d);
153 mo->oo_dt.do_ops = &osd_obj_ea_ops;
154 l->lo_ops = &osd_lu_obj_ops;
155 cfs_init_rwsem(&mo->oo_sem);
156 cfs_init_rwsem(&mo->oo_ext_idx_sem);
157 cfs_spin_lock_init(&mo->oo_guard);
164 static int osd_get_lma(struct inode *inode, struct dentry *dentry,
165 struct lustre_mdt_attrs *lma)
169 dentry->d_inode = inode;
170 rc = inode->i_op->getxattr(dentry, XATTR_NAME_LMA, (void *)lma,
173 /* Check LMA compatibility */
174 if (lma->lma_incompat & ~cpu_to_le32(LMA_INCOMPAT_SUPP)) {
175 CWARN("%.16s: unsupported incompat LMA feature(s) "
177 LDISKFS_SB(inode->i_sb)->s_es->s_volume_name,
178 inode->i_ino, le32_to_cpu(lma->lma_incompat) &
182 lustre_lma_swab(lma);
185 } else if (rc == 0) {
193 * retrieve object from backend ext fs.
195 struct inode *osd_iget(struct osd_thread_info *info, struct osd_device *dev,
196 struct osd_inode_id *id)
198 struct inode *inode = NULL;
200 inode = ldiskfs_iget(osd_sb(dev), id->oii_ino);
202 CDEBUG(D_INODE, "no inode: ino = %u, rc = %ld\n",
203 id->oii_ino, PTR_ERR(inode));
204 } else if (id->oii_gen != OSD_OII_NOGEN &&
205 inode->i_generation != id->oii_gen) {
206 CDEBUG(D_INODE, "unmatched inode: ino = %u, gen0 = %u, "
208 id->oii_ino, id->oii_gen, inode->i_generation);
210 inode = ERR_PTR(-ESTALE);
211 } else if (inode->i_nlink == 0) {
212 /* due to parallel readdir and unlink,
213 * we can have dead inode here. */
214 CDEBUG(D_INODE, "stale inode: ino = %u\n", id->oii_ino);
215 make_bad_inode(inode);
217 inode = ERR_PTR(-ESTALE);
218 } else if (is_bad_inode(inode)) {
219 CWARN("%.16s: bad inode: ino = %u\n",
220 LDISKFS_SB(osd_sb(dev))->s_es->s_volume_name, id->oii_ino);
222 inode = ERR_PTR(-ENOENT);
224 if (id->oii_gen == OSD_OII_NOGEN)
225 osd_id_gen(id, inode->i_ino, inode->i_generation);
227 /* Do not update file c/mtime in ldiskfs.
228 * NB: we don't have any lock to protect this because we don't
229 * have reference on osd_object now, but contention with
230 * another lookup + attr_set can't happen in the tiny window
231 * between if (...) and set S_NOCMTIME. */
232 if (!(inode->i_flags & S_NOCMTIME))
233 inode->i_flags |= S_NOCMTIME;
238 struct inode *osd_iget_fid(struct osd_thread_info *info, struct osd_device *dev,
239 struct osd_inode_id *id, struct lu_fid *fid)
241 struct lustre_mdt_attrs *lma = &info->oti_mdt_attrs;
245 inode = osd_iget(info, dev, id);
249 rc = osd_get_lma(inode, &info->oti_obj_dentry, lma);
251 *fid = lma->lma_self_fid;
252 } else if (rc == -ENODATA) {
253 LU_IGIF_BUILD(fid, inode->i_ino, inode->i_generation);
261 static struct inode *
262 osd_iget_verify(struct osd_thread_info *info, struct osd_device *dev,
263 struct osd_inode_id *id, const struct lu_fid *fid)
265 struct lustre_mdt_attrs *lma = &info->oti_mdt_attrs;
269 inode = osd_iget(info, dev, id);
273 rc = osd_get_lma(inode, &info->oti_obj_dentry, lma);
282 if (!lu_fid_eq(fid, &lma->lma_self_fid)) {
283 CDEBUG(D_LFSCK, "inconsistent obj: "DFID", %lu, "DFID"\n",
284 PFID(&lma->lma_self_fid), inode->i_ino, PFID(fid));
286 return ERR_PTR(-EREMCHG);
292 static int osd_fid_lookup(const struct lu_env *env, struct osd_object *obj,
293 const struct lu_fid *fid,
294 const struct lu_object_conf *conf)
296 struct osd_thread_info *info;
297 struct lu_device *ldev = obj->oo_dt.do_lu.lo_dev;
298 struct osd_device *dev;
299 struct osd_idmap_cache *oic;
300 struct osd_inode_id *id;
302 struct osd_scrub *scrub;
303 struct scrub_file *sf;
308 LINVRNT(osd_invariant(obj));
309 LASSERT(obj->oo_inode == NULL);
310 LASSERTF(fid_is_sane(fid) || fid_is_idif(fid), DFID, PFID(fid));
313 scrub = &dev->od_scrub;
314 sf = &scrub->os_file;
315 info = osd_oti_get(env);
317 oic = &info->oti_cache;
319 if (OBD_FAIL_CHECK(OBD_FAIL_OST_ENOENT))
322 /* Search order: 1. per-thread cache. */
323 if (lu_fid_eq(fid, &oic->oic_fid)) {
329 if (!cfs_list_empty(&scrub->os_inconsistent_items)) {
330 /* Search order: 2. OI scrub pending list. */
331 result = osd_oii_lookup(dev, fid, id);
336 if (sf->sf_flags & SF_INCONSISTENT)
340 * Objects are created as locking anchors or place holders for objects
341 * yet to be created. No need to osd_oi_lookup() at here because FID
342 * shouldn't never be re-used, if it's really a duplicate FID from
343 * unexpected reason, we should be able to detect it later by calling
344 * do_create->osd_oi_insert()
346 if (conf != NULL && (conf->loc_flags & LOC_F_NEW) != 0)
347 GOTO(out, result = 0);
349 /* Search order: 3. OI files. */
350 result = osd_oi_lookup(info, dev, fid, id);
351 if (result == -ENOENT) {
352 if (!fid_is_norm(fid) ||
353 !ldiskfs_test_bit(osd_oi_fid2idx(dev,fid),
355 GOTO(out, result = 0);
365 inode = osd_iget(info, dev, id);
367 inode = osd_iget_verify(info, dev, id, fid);
369 result = PTR_ERR(inode);
370 if (result == -ENOENT || result == -ESTALE) {
371 fid_zero(&oic->oic_fid);
373 } else if (result == -EREMCHG) {
376 if (thread_is_running(&scrub->os_thread)) {
377 result = -EINPROGRESS;
378 } else if (!dev->od_noscrub) {
379 result = osd_scrub_start(dev);
380 LCONSOLE_ERROR("%.16s: trigger OI scrub by RPC "
381 "for "DFID", rc = %d [1]\n",
382 LDISKFS_SB(osd_sb(dev))->s_es->\
383 s_volume_name,PFID(fid), result);
384 if (result == 0 || result == -EALREADY)
385 result = -EINPROGRESS;
394 obj->oo_inode = inode;
395 LASSERT(obj->oo_inode->i_sb == osd_sb(dev));
397 obj->oo_compat_dot_created = 1;
398 obj->oo_compat_dotdot_created = 1;
400 if (!S_ISDIR(inode->i_mode) || !ldiskfs_pdo) /* done */
401 GOTO(out, result = 0);
403 LASSERT(obj->oo_hl_head == NULL);
404 obj->oo_hl_head = ldiskfs_htree_lock_head_alloc(HTREE_HBITS_DEF);
405 if (obj->oo_hl_head == NULL) {
406 obj->oo_inode = NULL;
408 GOTO(out, result = -ENOMEM);
410 GOTO(out, result = 0);
413 LINVRNT(osd_invariant(obj));
418 * Concurrency: shouldn't matter.
420 static void osd_object_init0(struct osd_object *obj)
422 LASSERT(obj->oo_inode != NULL);
423 obj->oo_dt.do_body_ops = &osd_body_ops;
424 obj->oo_dt.do_lu.lo_header->loh_attr |=
425 (LOHA_EXISTS | (obj->oo_inode->i_mode & S_IFMT));
429 * Concurrency: no concurrent access is possible that early in object
432 static int osd_object_init(const struct lu_env *env, struct lu_object *l,
433 const struct lu_object_conf *conf)
435 struct osd_object *obj = osd_obj(l);
438 LINVRNT(osd_invariant(obj));
440 result = osd_fid_lookup(env, obj, lu_object_fid(l), conf);
441 obj->oo_dt.do_body_ops = &osd_body_ops_new;
443 if (obj->oo_inode != NULL) {
444 osd_object_init0(obj);
445 } else if (fid_is_otable_it(&l->lo_header->loh_fid)) {
446 obj->oo_dt.do_ops = &osd_obj_otable_it_ops;
447 /* LFSCK iterator object is special without inode */
448 l->lo_header->loh_attr |= LOHA_EXISTS;
451 LINVRNT(osd_invariant(obj));
456 * Concurrency: no concurrent access is possible that late in object
459 static void osd_object_free(const struct lu_env *env, struct lu_object *l)
461 struct osd_object *obj = osd_obj(l);
463 LINVRNT(osd_invariant(obj));
465 dt_object_fini(&obj->oo_dt);
466 if (obj->oo_hl_head != NULL)
467 ldiskfs_htree_lock_head_free(obj->oo_hl_head);
472 * Concurrency: no concurrent access is possible that late in object
475 static void osd_index_fini(struct osd_object *o)
477 struct iam_container *bag;
479 if (o->oo_dir != NULL) {
480 bag = &o->oo_dir->od_container;
481 if (o->oo_inode != NULL) {
482 if (bag->ic_object == o->oo_inode)
483 iam_container_fini(bag);
485 OBD_FREE_PTR(o->oo_dir);
491 * Concurrency: no concurrent access is possible that late in object
492 * life-cycle (for all existing callers, that is. New callers have to provide
493 * their own locking.)
495 static int osd_inode_unlinked(const struct inode *inode)
497 return inode->i_nlink == 0;
501 OSD_TXN_OI_DELETE_CREDITS = 20,
502 OSD_TXN_INODE_DELETE_CREDITS = 20
509 #if OSD_THANDLE_STATS
511 * Set time when the handle is allocated
513 static void osd_th_alloced(struct osd_thandle *oth)
515 oth->oth_alloced = cfs_time_current();
519 * Set time when the handle started
521 static void osd_th_started(struct osd_thandle *oth)
523 oth->oth_started = cfs_time_current();
527 * Helper function to convert time interval to microseconds packed in
528 * long int (default time units for the counter in "stats" initialized
529 * by lu_time_init() )
531 static long interval_to_usec(cfs_time_t start, cfs_time_t end)
535 cfs_duration_usec(cfs_time_sub(end, start), &val);
536 return val.tv_sec * 1000000 + val.tv_usec;
540 * Check whether the we deal with this handle for too long.
542 static void __osd_th_check_slow(void *oth, struct osd_device *dev,
543 cfs_time_t alloced, cfs_time_t started,
546 cfs_time_t now = cfs_time_current();
548 LASSERT(dev != NULL);
550 lprocfs_counter_add(dev->od_stats, LPROC_OSD_THANDLE_STARTING,
551 interval_to_usec(alloced, started));
552 lprocfs_counter_add(dev->od_stats, LPROC_OSD_THANDLE_OPEN,
553 interval_to_usec(started, closed));
554 lprocfs_counter_add(dev->od_stats, LPROC_OSD_THANDLE_CLOSING,
555 interval_to_usec(closed, now));
557 if (cfs_time_before(cfs_time_add(alloced, cfs_time_seconds(30)), now)) {
558 CWARN("transaction handle %p was open for too long: "
560 "alloced "CFS_TIME_T" ,"
561 "started "CFS_TIME_T" ,"
562 "closed "CFS_TIME_T"\n",
563 oth, now, alloced, started, closed);
564 libcfs_debug_dumpstack(NULL);
568 #define OSD_CHECK_SLOW_TH(oth, dev, expr) \
570 cfs_time_t __closed = cfs_time_current(); \
571 cfs_time_t __alloced = oth->oth_alloced; \
572 cfs_time_t __started = oth->oth_started; \
575 __osd_th_check_slow(oth, dev, __alloced, __started, __closed); \
578 #else /* OSD_THANDLE_STATS */
580 #define osd_th_alloced(h) do {} while(0)
581 #define osd_th_started(h) do {} while(0)
582 #define OSD_CHECK_SLOW_TH(oth, dev, expr) expr
584 #endif /* OSD_THANDLE_STATS */
587 * Concurrency: doesn't access mutable data.
589 static int osd_param_is_not_sane(const struct osd_device *dev,
590 const struct thandle *th)
592 struct osd_thandle *oh = container_of(th, typeof(*oh), ot_super);
594 return oh->ot_credits > osd_journal(dev)->j_max_transaction_buffers;
598 * Concurrency: shouldn't matter.
600 #ifdef HAVE_LDISKFS_JOURNAL_CALLBACK_ADD
601 static void osd_trans_commit_cb(struct super_block *sb,
602 struct journal_callback *jcb, int error)
604 static void osd_trans_commit_cb(struct journal_callback *jcb, int error)
607 struct osd_thandle *oh = container_of0(jcb, struct osd_thandle, ot_jcb);
608 struct thandle *th = &oh->ot_super;
609 struct lu_device *lud = &th->th_dev->dd_lu_dev;
610 struct dt_txn_commit_cb *dcb, *tmp;
612 LASSERT(oh->ot_handle == NULL);
615 CERROR("transaction @0x%p commit error: %d\n", th, error);
617 dt_txn_hook_commit(th);
619 /* call per-transaction callbacks if any */
620 cfs_list_for_each_entry_safe(dcb, tmp, &oh->ot_dcb_list, dcb_linkage) {
621 LASSERTF(dcb->dcb_magic == TRANS_COMMIT_CB_MAGIC,
622 "commit callback entry: magic=%x name='%s'\n",
623 dcb->dcb_magic, dcb->dcb_name);
624 cfs_list_del_init(&dcb->dcb_linkage);
625 dcb->dcb_func(NULL, th, dcb, error);
628 lu_ref_del_at(&lud->ld_reference, oh->ot_dev_link, "osd-tx", th);
632 lu_context_exit(&th->th_ctx);
633 lu_context_fini(&th->th_ctx);
637 static struct thandle *osd_trans_create(const struct lu_env *env,
640 struct osd_thread_info *oti = osd_oti_get(env);
641 struct osd_iobuf *iobuf = &oti->oti_iobuf;
642 struct osd_thandle *oh;
646 /* on pending IO in this thread should left from prev. request */
647 LASSERT(cfs_atomic_read(&iobuf->dr_numreqs) == 0);
649 th = ERR_PTR(-ENOMEM);
650 OBD_ALLOC_GFP(oh, sizeof *oh, CFS_ALLOC_IO);
652 oh->ot_quota_trans = &oti->oti_quota_trans;
653 memset(oh->ot_quota_trans, 0, sizeof(*oh->ot_quota_trans));
657 th->th_tags = LCT_TX_HANDLE;
659 oti->oti_dev = osd_dt_dev(d);
660 CFS_INIT_LIST_HEAD(&oh->ot_dcb_list);
667 * Concurrency: shouldn't matter.
669 int osd_trans_start(const struct lu_env *env, struct dt_device *d,
672 struct osd_thread_info *oti = osd_oti_get(env);
673 struct osd_device *dev = osd_dt_dev(d);
675 struct osd_thandle *oh;
680 LASSERT(current->journal_info == NULL);
682 oh = container_of0(th, struct osd_thandle, ot_super);
684 LASSERT(oh->ot_handle == NULL);
686 rc = dt_txn_hook_start(env, d, th);
690 if (unlikely(osd_param_is_not_sane(dev, th))) {
691 static unsigned long last_printed;
692 static int last_credits;
694 CWARN("%.16s: too many transaction credits (%d > %d)\n",
695 LDISKFS_SB(osd_sb(dev))->s_es->s_volume_name,
697 osd_journal(dev)->j_max_transaction_buffers);
698 #ifdef OSD_TRACK_DECLARES
699 CWARN(" create: %u/%u, delete: %u/%u, destroy: %u/%u\n",
700 oh->ot_declare_create, oh->ot_declare_create_cred,
701 oh->ot_declare_delete, oh->ot_declare_delete_cred,
702 oh->ot_declare_destroy, oh->ot_declare_destroy_cred);
703 CWARN(" attr_set: %u/%u, xattr_set: %u/%u\n",
704 oh->ot_declare_attr_set, oh->ot_declare_attr_set_cred,
705 oh->ot_declare_xattr_set, oh->ot_declare_xattr_set_cred);
706 CWARN(" write: %u/%u, punch: %u/%u, quota %u/%u\n",
707 oh->ot_declare_write, oh->ot_declare_write_cred,
708 oh->ot_declare_punch, oh->ot_declare_punch_cred,
709 oh->ot_declare_quota, oh->ot_declare_quota_cred);
710 CWARN(" insert: %u/%u, delete: %u/%u\n",
711 oh->ot_declare_insert, oh->ot_declare_insert_cred,
712 oh->ot_declare_delete, oh->ot_declare_destroy_cred);
713 CWARN(" ref_add: %u/%u, ref_del: %u/%u\n",
714 oh->ot_declare_ref_add, oh->ot_declare_ref_add_cred,
715 oh->ot_declare_ref_del, oh->ot_declare_ref_del_cred);
717 if (last_credits != oh->ot_credits &&
718 time_after(jiffies, last_printed + 60 * HZ)) {
719 libcfs_debug_dumpstack(NULL);
720 last_credits = oh->ot_credits;
721 last_printed = jiffies;
724 /* XXX Limit the credits to 'max_transaction_buffers', and
725 * let the underlying filesystem to catch the error if
726 * we really need so many credits.
728 * This should be removed when we can calculate the
729 * credits precisely. */
730 oh->ot_credits = osd_journal(dev)->j_max_transaction_buffers;
734 * XXX temporary stuff. Some abstraction layer should
737 jh = ldiskfs_journal_start_sb(osd_sb(dev), oh->ot_credits);
741 LASSERT(oti->oti_txns == 0);
742 lu_context_init(&th->th_ctx, th->th_tags);
743 lu_context_enter(&th->th_ctx);
745 lu_device_get(&d->dd_lu_dev);
746 oh->ot_dev_link = lu_ref_add(&d->dd_lu_dev.ld_reference,
758 * Concurrency: shouldn't matter.
760 static int osd_trans_stop(const struct lu_env *env, struct thandle *th)
763 struct osd_thandle *oh;
764 struct osd_thread_info *oti = osd_oti_get(env);
765 struct osd_iobuf *iobuf = &oti->oti_iobuf;
766 struct qsd_instance *qsd = oti->oti_dev->od_quota_slave;
769 oh = container_of0(th, struct osd_thandle, ot_super);
772 /* inform the quota slave device that the transaction is
774 qsd_op_end(env, qsd, oh->ot_quota_trans);
775 oh->ot_quota_trans = NULL;
777 if (oh->ot_handle != NULL) {
778 handle_t *hdl = oh->ot_handle;
781 * add commit callback
782 * notice we don't do this in osd_trans_start()
783 * as underlying transaction can change during truncate
785 osd_journal_callback_set(hdl, osd_trans_commit_cb,
788 LASSERT(oti->oti_txns == 1);
790 rc = dt_txn_hook_stop(env, th);
792 CERROR("Failure in transaction hook: %d\n", rc);
794 /* hook functions might modify th_sync */
795 hdl->h_sync = th->th_sync;
797 oh->ot_handle = NULL;
798 OSD_CHECK_SLOW_TH(oh, oti->oti_dev,
799 rc = ldiskfs_journal_stop(hdl));
801 CERROR("Failure to stop transaction: %d\n", rc);
806 /* as we want IO to journal and data IO be concurrent, we don't block
807 * awaiting data IO completion in osd_do_bio(), instead we wait here
808 * once transaction is submitted to the journal. all reqular requests
809 * don't do direct IO (except read/write), thus this wait_event becomes
812 * IMPORTANT: we have to wait till any IO submited by the thread is
813 * completed otherwise iobuf may be corrupted by different request
815 cfs_wait_event(iobuf->dr_wait,
816 cfs_atomic_read(&iobuf->dr_numreqs) == 0);
818 rc = iobuf->dr_error;
823 static int osd_trans_cb_add(struct thandle *th, struct dt_txn_commit_cb *dcb)
825 struct osd_thandle *oh = container_of0(th, struct osd_thandle,
828 LASSERT(dcb->dcb_magic == TRANS_COMMIT_CB_MAGIC);
829 LASSERT(&dcb->dcb_func != NULL);
830 cfs_list_add(&dcb->dcb_linkage, &oh->ot_dcb_list);
836 * Called just before object is freed. Releases all resources except for
837 * object itself (that is released by osd_object_free()).
839 * Concurrency: no concurrent access is possible that late in object
842 static void osd_object_delete(const struct lu_env *env, struct lu_object *l)
844 struct osd_object *obj = osd_obj(l);
845 struct inode *inode = obj->oo_inode;
847 LINVRNT(osd_invariant(obj));
850 * If object is unlinked remove fid->ino mapping from object index.
855 struct qsd_instance *qsd = osd_obj2dev(obj)->od_quota_slave;
856 qid_t uid = inode->i_uid;
857 qid_t gid = inode->i_gid;
860 obj->oo_inode = NULL;
863 struct osd_thread_info *info = osd_oti_get(env);
864 struct lquota_id_info *qi = &info->oti_qi;
866 /* Release granted quota to master if necessary */
867 qi->lqi_id.qid_uid = uid;
868 qsd_op_adjust(env, qsd, &qi->lqi_id, USRQUOTA);
870 qi->lqi_id.qid_uid = gid;
871 qsd_op_adjust(env, qsd, &qi->lqi_id, GRPQUOTA);
877 * Concurrency: ->loo_object_release() is called under site spin-lock.
879 static void osd_object_release(const struct lu_env *env,
885 * Concurrency: shouldn't matter.
887 static int osd_object_print(const struct lu_env *env, void *cookie,
888 lu_printer_t p, const struct lu_object *l)
890 struct osd_object *o = osd_obj(l);
893 if (o->oo_dir != NULL)
894 d = o->oo_dir->od_container.ic_descr;
897 return (*p)(env, cookie,
898 LUSTRE_OSD_LDISKFS_NAME"-object@%p(i:%p:%lu/%u)[%s]",
900 o->oo_inode ? o->oo_inode->i_ino : 0UL,
901 o->oo_inode ? o->oo_inode->i_generation : 0,
902 d ? d->id_ops->id_name : "plain");
906 * Concurrency: shouldn't matter.
908 int osd_statfs(const struct lu_env *env, struct dt_device *d,
909 struct obd_statfs *sfs)
911 struct osd_device *osd = osd_dt_dev(d);
912 struct super_block *sb = osd_sb(osd);
913 struct kstatfs *ksfs;
916 if (unlikely(osd->od_mnt == NULL))
919 /* osd_lproc.c call this without env, allocate ksfs for that case */
920 if (unlikely(env == NULL)) {
925 ksfs = &osd_oti_get(env)->oti_ksfs;
928 cfs_spin_lock(&osd->od_osfs_lock);
930 if (cfs_time_before_64(osd->od_osfs_age, cfs_time_shift_64(-1))) {
931 result = sb->s_op->statfs(sb->s_root, ksfs);
932 if (likely(result == 0)) { /* N.B. statfs can't really fail */
933 osd->od_osfs_age = cfs_time_current_64();
934 statfs_pack(&osd->od_statfs, ksfs);
935 if (sb->s_flags & MS_RDONLY)
936 sfs->os_state = OS_STATE_READONLY;
940 if (likely(result == 0))
941 *sfs = osd->od_statfs;
942 cfs_spin_unlock(&osd->od_osfs_lock);
944 if (unlikely(env == NULL))
951 * Estimate space needed for file creations. We assume the largest filename
952 * which is 2^64 - 1, hence a filename of 20 chars.
953 * This is 28 bytes per object which is 28MB for 1M objects ... no so bad.
955 #ifdef __LDISKFS_DIR_REC_LEN
956 #define PER_OBJ_USAGE __LDISKFS_DIR_REC_LEN(20)
958 #define PER_OBJ_USAGE LDISKFS_DIR_REC_LEN(20)
962 * Concurrency: doesn't access mutable data.
964 static void osd_conf_get(const struct lu_env *env,
965 const struct dt_device *dev,
966 struct dt_device_param *param)
968 struct super_block *sb = osd_sb(osd_dt_dev(dev));
971 * XXX should be taken from not-yet-existing fs abstraction layer.
973 param->ddp_mnt = osd_dt_dev(dev)->od_mnt;
974 param->ddp_max_name_len = LDISKFS_NAME_LEN;
975 param->ddp_max_nlink = LDISKFS_LINK_MAX;
976 param->ddp_block_shift = sb->s_blocksize_bits;
977 param->ddp_mount_type = LDD_MT_LDISKFS;
978 param->ddp_maxbytes = sb->s_maxbytes;
979 /* Overhead estimate should be fairly accurate, so we really take a tiny
980 * error margin which also avoids fragmenting the filesystem too much */
981 param->ddp_grant_reserved = 2; /* end up to be 1.9% after conversion */
982 /* inode are statically allocated, so per-inode space consumption
983 * is the space consumed by the directory entry */
984 param->ddp_inodespace = PER_OBJ_USAGE;
985 /* per-fragment overhead to be used by the client code */
986 param->ddp_grant_frag = 6 * LDISKFS_BLOCK_SIZE(sb);
987 param->ddp_mntopts = 0;
988 if (test_opt(sb, XATTR_USER))
989 param->ddp_mntopts |= MNTOPT_USERXATTR;
990 if (test_opt(sb, POSIX_ACL))
991 param->ddp_mntopts |= MNTOPT_ACL;
993 #if defined(LDISKFS_FEATURE_INCOMPAT_EA_INODE)
994 if (LDISKFS_HAS_INCOMPAT_FEATURE(sb, LDISKFS_FEATURE_INCOMPAT_EA_INODE))
995 param->ddp_max_ea_size = LDISKFS_XATTR_MAX_LARGE_EA_SIZE;
998 param->ddp_max_ea_size = sb->s_blocksize;
1003 * Helper function to get and fill the buffer with input values.
1005 static struct lu_buf *osd_buf_get(const struct lu_env *env, void *area, ssize_t len)
1009 buf = &osd_oti_get(env)->oti_buf;
1016 * Concurrency: shouldn't matter.
1018 static int osd_sync(const struct lu_env *env, struct dt_device *d)
1020 CDEBUG(D_HA, "syncing OSD %s\n", LUSTRE_OSD_LDISKFS_NAME);
1021 return ldiskfs_force_commit(osd_sb(osd_dt_dev(d)));
1025 * Start commit for OSD device.
1027 * An implementation of dt_commit_async method for OSD device.
1028 * Asychronously starts underlayng fs sync and thereby a transaction
1031 * \param env environment
1032 * \param d dt device
1034 * \see dt_device_operations
1036 static int osd_commit_async(const struct lu_env *env,
1037 struct dt_device *d)
1039 struct super_block *s = osd_sb(osd_dt_dev(d));
1042 CDEBUG(D_HA, "async commit OSD %s\n", LUSTRE_OSD_LDISKFS_NAME);
1043 RETURN(s->s_op->sync_fs(s, 0));
1047 * Concurrency: shouldn't matter.
1050 static int osd_ro(const struct lu_env *env, struct dt_device *d)
1052 struct super_block *sb = osd_sb(osd_dt_dev(d));
1056 CERROR("*** setting %s read-only ***\n", osd_dt_dev(d)->od_svname);
1058 rc = __lvfs_set_rdonly(sb->s_bdev, LDISKFS_SB(sb)->journal_bdev);
1063 * Concurrency: serialization provided by callers.
1065 static int osd_init_capa_ctxt(const struct lu_env *env, struct dt_device *d,
1066 int mode, unsigned long timeout, __u32 alg,
1067 struct lustre_capa_key *keys)
1069 struct osd_device *dev = osd_dt_dev(d);
1072 dev->od_fl_capa = mode;
1073 dev->od_capa_timeout = timeout;
1074 dev->od_capa_alg = alg;
1075 dev->od_capa_keys = keys;
1080 * Note: we do not count into QUOTA here.
1081 * If we mount with --data_journal we may need more.
1083 const int osd_dto_credits_noquota[DTO_NR] = {
1086 * INDEX_EXTRA_TRANS_BLOCKS(8) +
1087 * SINGLEDATA_TRANS_BLOCKS(8)
1088 * XXX Note: maybe iam need more, since iam have more level than
1091 [DTO_INDEX_INSERT] = 16,
1092 [DTO_INDEX_DELETE] = 16,
1096 [DTO_INDEX_UPDATE] = 16,
1098 * Create a object. The same as create object in EXT3.
1099 * DATA_TRANS_BLOCKS(14) +
1100 * INDEX_EXTRA_BLOCKS(8) +
1101 * 3(inode bits, groups, GDT)
1103 [DTO_OBJECT_CREATE] = 25,
1105 * XXX: real credits to be fixed
1107 [DTO_OBJECT_DELETE] = 25,
1109 * Attr set credits (inode)
1111 [DTO_ATTR_SET_BASE] = 1,
1113 * Xattr set. The same as xattr of EXT3.
1114 * DATA_TRANS_BLOCKS(14)
1115 * XXX Note: in original MDS implmentation INDEX_EXTRA_TRANS_BLOCKS
1116 * are also counted in. Do not know why?
1118 [DTO_XATTR_SET] = 14,
1121 * credits for inode change during write.
1123 [DTO_WRITE_BASE] = 3,
1125 * credits for single block write.
1127 [DTO_WRITE_BLOCK] = 14,
1129 * Attr set credits for chown.
1130 * This is extra credits for setattr, and it is null without quota
1132 [DTO_ATTR_SET_CHOWN]= 0
1135 static const struct dt_device_operations osd_dt_ops = {
1136 .dt_root_get = osd_root_get,
1137 .dt_statfs = osd_statfs,
1138 .dt_trans_create = osd_trans_create,
1139 .dt_trans_start = osd_trans_start,
1140 .dt_trans_stop = osd_trans_stop,
1141 .dt_trans_cb_add = osd_trans_cb_add,
1142 .dt_conf_get = osd_conf_get,
1143 .dt_sync = osd_sync,
1145 .dt_commit_async = osd_commit_async,
1146 .dt_init_capa_ctxt = osd_init_capa_ctxt,
1149 static void osd_object_read_lock(const struct lu_env *env,
1150 struct dt_object *dt, unsigned role)
1152 struct osd_object *obj = osd_dt_obj(dt);
1153 struct osd_thread_info *oti = osd_oti_get(env);
1155 LINVRNT(osd_invariant(obj));
1157 LASSERT(obj->oo_owner != env);
1158 cfs_down_read_nested(&obj->oo_sem, role);
1160 LASSERT(obj->oo_owner == NULL);
1164 static void osd_object_write_lock(const struct lu_env *env,
1165 struct dt_object *dt, unsigned role)
1167 struct osd_object *obj = osd_dt_obj(dt);
1168 struct osd_thread_info *oti = osd_oti_get(env);
1170 LINVRNT(osd_invariant(obj));
1172 LASSERT(obj->oo_owner != env);
1173 cfs_down_write_nested(&obj->oo_sem, role);
1175 LASSERT(obj->oo_owner == NULL);
1176 obj->oo_owner = env;
1180 static void osd_object_read_unlock(const struct lu_env *env,
1181 struct dt_object *dt)
1183 struct osd_object *obj = osd_dt_obj(dt);
1184 struct osd_thread_info *oti = osd_oti_get(env);
1186 LINVRNT(osd_invariant(obj));
1188 LASSERT(oti->oti_r_locks > 0);
1190 cfs_up_read(&obj->oo_sem);
1193 static void osd_object_write_unlock(const struct lu_env *env,
1194 struct dt_object *dt)
1196 struct osd_object *obj = osd_dt_obj(dt);
1197 struct osd_thread_info *oti = osd_oti_get(env);
1199 LINVRNT(osd_invariant(obj));
1201 LASSERT(obj->oo_owner == env);
1202 LASSERT(oti->oti_w_locks > 0);
1204 obj->oo_owner = NULL;
1205 cfs_up_write(&obj->oo_sem);
1208 static int osd_object_write_locked(const struct lu_env *env,
1209 struct dt_object *dt)
1211 struct osd_object *obj = osd_dt_obj(dt);
1213 LINVRNT(osd_invariant(obj));
1215 return obj->oo_owner == env;
1218 static int capa_is_sane(const struct lu_env *env,
1219 struct osd_device *dev,
1220 struct lustre_capa *capa,
1221 struct lustre_capa_key *keys)
1223 struct osd_thread_info *oti = osd_oti_get(env);
1224 struct lustre_capa *tcapa = &oti->oti_capa;
1225 struct obd_capa *oc;
1229 oc = capa_lookup(dev->od_capa_hash, capa, 0);
1231 if (capa_is_expired(oc)) {
1232 DEBUG_CAPA(D_ERROR, capa, "expired");
1239 if (capa_is_expired_sec(capa)) {
1240 DEBUG_CAPA(D_ERROR, capa, "expired");
1244 cfs_spin_lock(&capa_lock);
1245 for (i = 0; i < 2; i++) {
1246 if (keys[i].lk_keyid == capa->lc_keyid) {
1247 oti->oti_capa_key = keys[i];
1251 cfs_spin_unlock(&capa_lock);
1254 DEBUG_CAPA(D_ERROR, capa, "no matched capa key");
1258 rc = capa_hmac(tcapa->lc_hmac, capa, oti->oti_capa_key.lk_key);
1262 if (memcmp(tcapa->lc_hmac, capa->lc_hmac, sizeof(capa->lc_hmac))) {
1263 DEBUG_CAPA(D_ERROR, capa, "HMAC mismatch");
1267 oc = capa_add(dev->od_capa_hash, capa);
1273 int osd_object_auth(const struct lu_env *env, struct dt_object *dt,
1274 struct lustre_capa *capa, __u64 opc)
1276 const struct lu_fid *fid = lu_object_fid(&dt->do_lu);
1277 struct osd_device *dev = osd_dev(dt->do_lu.lo_dev);
1278 struct md_capainfo *ci;
1281 if (!dev->od_fl_capa)
1284 if (capa == BYPASS_CAPA)
1287 ci = md_capainfo(env);
1291 if (ci->mc_auth == LC_ID_NONE)
1295 CERROR("no capability is provided for fid "DFID"\n", PFID(fid));
1299 if (!lu_fid_eq(fid, &capa->lc_fid)) {
1300 DEBUG_CAPA(D_ERROR, capa, "fid "DFID" mismatch with",
1305 if (!capa_opc_supported(capa, opc)) {
1306 DEBUG_CAPA(D_ERROR, capa, "opc "LPX64" not supported by", opc);
1310 if ((rc = capa_is_sane(env, dev, capa, dev->od_capa_keys))) {
1311 DEBUG_CAPA(D_ERROR, capa, "insane (rc %d)", rc);
1318 static struct timespec *osd_inode_time(const struct lu_env *env,
1319 struct inode *inode, __u64 seconds)
1321 struct osd_thread_info *oti = osd_oti_get(env);
1322 struct timespec *t = &oti->oti_time;
1324 t->tv_sec = seconds;
1326 *t = timespec_trunc(*t, inode->i_sb->s_time_gran);
1331 static void osd_inode_getattr(const struct lu_env *env,
1332 struct inode *inode, struct lu_attr *attr)
1334 attr->la_valid |= LA_ATIME | LA_MTIME | LA_CTIME | LA_MODE |
1335 LA_SIZE | LA_BLOCKS | LA_UID | LA_GID |
1336 LA_FLAGS | LA_NLINK | LA_RDEV | LA_BLKSIZE;
1338 attr->la_atime = LTIME_S(inode->i_atime);
1339 attr->la_mtime = LTIME_S(inode->i_mtime);
1340 attr->la_ctime = LTIME_S(inode->i_ctime);
1341 attr->la_mode = inode->i_mode;
1342 attr->la_size = i_size_read(inode);
1343 attr->la_blocks = inode->i_blocks;
1344 attr->la_uid = inode->i_uid;
1345 attr->la_gid = inode->i_gid;
1346 attr->la_flags = LDISKFS_I(inode)->i_flags;
1347 attr->la_nlink = inode->i_nlink;
1348 attr->la_rdev = inode->i_rdev;
1349 attr->la_blksize = 1 << inode->i_blkbits;
1350 attr->la_blkbits = inode->i_blkbits;
1353 static int osd_attr_get(const struct lu_env *env,
1354 struct dt_object *dt,
1355 struct lu_attr *attr,
1356 struct lustre_capa *capa)
1358 struct osd_object *obj = osd_dt_obj(dt);
1360 LASSERT(dt_object_exists(dt));
1361 LINVRNT(osd_invariant(obj));
1363 if (osd_object_auth(env, dt, capa, CAPA_OPC_META_READ))
1366 cfs_spin_lock(&obj->oo_guard);
1367 osd_inode_getattr(env, obj->oo_inode, attr);
1368 cfs_spin_unlock(&obj->oo_guard);
1372 static int osd_declare_attr_set(const struct lu_env *env,
1373 struct dt_object *dt,
1374 const struct lu_attr *attr,
1375 struct thandle *handle)
1377 struct osd_thandle *oh;
1378 struct osd_object *obj;
1379 struct osd_thread_info *info = osd_oti_get(env);
1380 struct lquota_id_info *qi = &info->oti_qi;
1386 LASSERT(dt != NULL);
1387 LASSERT(handle != NULL);
1389 obj = osd_dt_obj(dt);
1390 LASSERT(osd_invariant(obj));
1392 oh = container_of0(handle, struct osd_thandle, ot_super);
1393 LASSERT(oh->ot_handle == NULL);
1395 OSD_DECLARE_OP(oh, attr_set,
1396 osd_dto_credits_noquota[DTO_ATTR_SET_BASE]);
1398 if (attr == NULL || obj->oo_inode == NULL)
1401 bspace = obj->oo_inode->i_blocks;
1402 bspace <<= obj->oo_inode->i_sb->s_blocksize_bits;
1403 bspace = toqb(bspace);
1405 /* Changing ownership is always preformed by super user, it should not
1408 * We still need to call the osd_declare_qid() to calculate the journal
1409 * credits for updating quota accounting files and to trigger quota
1410 * space adjustment once the operation is completed.*/
1411 if ((attr->la_valid & LA_UID) != 0 &&
1412 attr->la_uid != obj->oo_inode->i_uid) {
1413 qi->lqi_type = USRQUOTA;
1415 /* inode accounting */
1416 qi->lqi_is_blk = false;
1418 /* one more inode for the new owner ... */
1419 qi->lqi_id.qid_uid = attr->la_uid;
1421 allocated = (attr->la_uid == 0) ? true : false;
1422 rc = osd_declare_qid(env, oh, qi, allocated, NULL);
1423 if (rc == -EDQUOT || rc == -EINPROGRESS)
1428 /* and one less inode for the current uid */
1429 qi->lqi_id.qid_uid = obj->oo_inode->i_uid;
1431 rc = osd_declare_qid(env, oh, qi, true, NULL);
1432 if (rc == -EDQUOT || rc == -EINPROGRESS)
1437 /* block accounting */
1438 qi->lqi_is_blk = true;
1440 /* more blocks for the new owner ... */
1441 qi->lqi_id.qid_uid = attr->la_uid;
1442 qi->lqi_space = bspace;
1443 allocated = (attr->la_uid == 0) ? true : false;
1444 rc = osd_declare_qid(env, oh, qi, allocated, NULL);
1445 if (rc == -EDQUOT || rc == -EINPROGRESS)
1450 /* and finally less blocks for the current owner */
1451 qi->lqi_id.qid_uid = obj->oo_inode->i_uid;
1452 qi->lqi_space = -bspace;
1453 rc = osd_declare_qid(env, oh, qi, true, NULL);
1454 if (rc == -EDQUOT || rc == -EINPROGRESS)
1460 if (attr->la_valid & LA_GID &&
1461 attr->la_gid != obj->oo_inode->i_gid) {
1462 qi->lqi_type = GRPQUOTA;
1464 /* inode accounting */
1465 qi->lqi_is_blk = false;
1467 /* one more inode for the new group owner ... */
1468 qi->lqi_id.qid_gid = attr->la_gid;
1470 allocated = (attr->la_gid == 0) ? true : false;
1471 rc = osd_declare_qid(env, oh, qi, allocated, NULL);
1472 if (rc == -EDQUOT || rc == -EINPROGRESS)
1477 /* and one less inode for the current gid */
1478 qi->lqi_id.qid_gid = obj->oo_inode->i_gid;
1480 rc = osd_declare_qid(env, oh, qi, true, NULL);
1481 if (rc == -EDQUOT || rc == -EINPROGRESS)
1486 /* block accounting */
1487 qi->lqi_is_blk = true;
1489 /* more blocks for the new owner ... */
1490 qi->lqi_id.qid_gid = attr->la_gid;
1491 qi->lqi_space = bspace;
1492 allocated = (attr->la_gid == 0) ? true : false;
1493 rc = osd_declare_qid(env, oh, qi, allocated, NULL);
1494 if (rc == -EDQUOT || rc == -EINPROGRESS)
1499 /* and finally less blocks for the current owner */
1500 qi->lqi_id.qid_gid = obj->oo_inode->i_gid;
1501 qi->lqi_space = -bspace;
1502 rc = osd_declare_qid(env, oh, qi, true, NULL);
1503 if (rc == -EDQUOT || rc == -EINPROGRESS)
1512 static int osd_inode_setattr(const struct lu_env *env,
1513 struct inode *inode, const struct lu_attr *attr)
1517 bits = attr->la_valid;
1519 LASSERT(!(bits & LA_TYPE)); /* Huh? You want too much. */
1521 if (bits & LA_ATIME)
1522 inode->i_atime = *osd_inode_time(env, inode, attr->la_atime);
1523 if (bits & LA_CTIME)
1524 inode->i_ctime = *osd_inode_time(env, inode, attr->la_ctime);
1525 if (bits & LA_MTIME)
1526 inode->i_mtime = *osd_inode_time(env, inode, attr->la_mtime);
1527 if (bits & LA_SIZE) {
1528 LDISKFS_I(inode)->i_disksize = attr->la_size;
1529 i_size_write(inode, attr->la_size);
1533 /* OSD should not change "i_blocks" which is used by quota.
1534 * "i_blocks" should be changed by ldiskfs only. */
1535 if (bits & LA_BLOCKS)
1536 inode->i_blocks = attr->la_blocks;
1539 inode->i_mode = (inode->i_mode & S_IFMT) |
1540 (attr->la_mode & ~S_IFMT);
1542 inode->i_uid = attr->la_uid;
1544 inode->i_gid = attr->la_gid;
1545 if (bits & LA_NLINK)
1546 set_nlink(inode, attr->la_nlink);
1548 inode->i_rdev = attr->la_rdev;
1550 if (bits & LA_FLAGS) {
1551 /* always keep S_NOCMTIME */
1552 inode->i_flags = ll_ext_to_inode_flags(attr->la_flags) |
1558 static int osd_quota_transfer(struct inode *inode, const struct lu_attr *attr)
1560 if ((attr->la_valid & LA_UID && attr->la_uid != inode->i_uid) ||
1561 (attr->la_valid & LA_GID && attr->la_gid != inode->i_gid)) {
1566 if (attr->la_valid & LA_UID)
1567 iattr.ia_valid |= ATTR_UID;
1568 if (attr->la_valid & LA_GID)
1569 iattr.ia_valid |= ATTR_GID;
1570 iattr.ia_uid = attr->la_uid;
1571 iattr.ia_gid = attr->la_gid;
1573 rc = ll_vfs_dq_transfer(inode, &iattr);
1575 CERROR("%s: quota transfer failed: rc = %d. Is quota "
1576 "enforcement enabled on the ldiskfs filesystem?",
1577 inode->i_sb->s_id, rc);
1584 static int osd_attr_set(const struct lu_env *env,
1585 struct dt_object *dt,
1586 const struct lu_attr *attr,
1587 struct thandle *handle,
1588 struct lustre_capa *capa)
1590 struct osd_object *obj = osd_dt_obj(dt);
1591 struct inode *inode;
1594 LASSERT(handle != NULL);
1595 LASSERT(dt_object_exists(dt));
1596 LASSERT(osd_invariant(obj));
1598 if (osd_object_auth(env, dt, capa, CAPA_OPC_META_WRITE))
1601 OSD_EXEC_OP(handle, attr_set);
1603 inode = obj->oo_inode;
1604 ll_vfs_dq_init(inode);
1606 rc = osd_quota_transfer(inode, attr);
1610 cfs_spin_lock(&obj->oo_guard);
1611 rc = osd_inode_setattr(env, inode, attr);
1612 cfs_spin_unlock(&obj->oo_guard);
1615 inode->i_sb->s_op->dirty_inode(inode);
1619 struct dentry *osd_child_dentry_get(const struct lu_env *env,
1620 struct osd_object *obj,
1621 const char *name, const int namelen)
1623 return osd_child_dentry_by_inode(env, obj->oo_inode, name, namelen);
1626 static int osd_mkfile(struct osd_thread_info *info, struct osd_object *obj,
1628 struct dt_allocation_hint *hint,
1632 struct osd_device *osd = osd_obj2dev(obj);
1633 struct osd_thandle *oth;
1634 struct dt_object *parent = NULL;
1635 struct inode *inode;
1637 LINVRNT(osd_invariant(obj));
1638 LASSERT(obj->oo_inode == NULL);
1639 LASSERT(obj->oo_hl_head == NULL);
1641 if (S_ISDIR(mode) && ldiskfs_pdo) {
1642 obj->oo_hl_head =ldiskfs_htree_lock_head_alloc(HTREE_HBITS_DEF);
1643 if (obj->oo_hl_head == NULL)
1647 oth = container_of(th, struct osd_thandle, ot_super);
1648 LASSERT(oth->ot_handle->h_transaction != NULL);
1650 if (hint && hint->dah_parent)
1651 parent = hint->dah_parent;
1653 inode = ldiskfs_create_inode(oth->ot_handle,
1654 parent ? osd_dt_obj(parent)->oo_inode :
1655 osd_sb(osd)->s_root->d_inode,
1657 if (!IS_ERR(inode)) {
1658 /* Do not update file c/mtime in ldiskfs.
1659 * NB: don't need any lock because no contention at this
1661 inode->i_flags |= S_NOCMTIME;
1662 inode->i_state |= I_LUSTRE_NOSCRUB;
1663 obj->oo_inode = inode;
1666 if (obj->oo_hl_head != NULL) {
1667 ldiskfs_htree_lock_head_free(obj->oo_hl_head);
1668 obj->oo_hl_head = NULL;
1670 result = PTR_ERR(inode);
1672 LINVRNT(osd_invariant(obj));
1680 static int osd_mkdir(struct osd_thread_info *info, struct osd_object *obj,
1681 struct lu_attr *attr,
1682 struct dt_allocation_hint *hint,
1683 struct dt_object_format *dof,
1687 struct osd_thandle *oth;
1688 __u32 mode = (attr->la_mode & (S_IFMT | S_IRWXUGO | S_ISVTX));
1690 LASSERT(S_ISDIR(attr->la_mode));
1692 oth = container_of(th, struct osd_thandle, ot_super);
1693 LASSERT(oth->ot_handle->h_transaction != NULL);
1694 result = osd_mkfile(info, obj, mode, hint, th);
1699 static int osd_mk_index(struct osd_thread_info *info, struct osd_object *obj,
1700 struct lu_attr *attr,
1701 struct dt_allocation_hint *hint,
1702 struct dt_object_format *dof,
1706 struct osd_thandle *oth;
1707 const struct dt_index_features *feat = dof->u.dof_idx.di_feat;
1709 __u32 mode = (attr->la_mode & (S_IFMT | S_IALLUGO | S_ISVTX));
1711 LASSERT(S_ISREG(attr->la_mode));
1713 oth = container_of(th, struct osd_thandle, ot_super);
1714 LASSERT(oth->ot_handle->h_transaction != NULL);
1716 result = osd_mkfile(info, obj, mode, hint, th);
1718 LASSERT(obj->oo_inode != NULL);
1719 if (feat->dif_flags & DT_IND_VARKEY)
1720 result = iam_lvar_create(obj->oo_inode,
1721 feat->dif_keysize_max,
1723 feat->dif_recsize_max,
1726 result = iam_lfix_create(obj->oo_inode,
1727 feat->dif_keysize_max,
1729 feat->dif_recsize_max,
1736 static int osd_mkreg(struct osd_thread_info *info, struct osd_object *obj,
1737 struct lu_attr *attr,
1738 struct dt_allocation_hint *hint,
1739 struct dt_object_format *dof,
1742 LASSERT(S_ISREG(attr->la_mode));
1743 return osd_mkfile(info, obj, (attr->la_mode &
1744 (S_IFMT | S_IALLUGO | S_ISVTX)), hint, th);
1747 static int osd_mksym(struct osd_thread_info *info, struct osd_object *obj,
1748 struct lu_attr *attr,
1749 struct dt_allocation_hint *hint,
1750 struct dt_object_format *dof,
1753 LASSERT(S_ISLNK(attr->la_mode));
1754 return osd_mkfile(info, obj, (attr->la_mode &
1755 (S_IFMT | S_IALLUGO | S_ISVTX)), hint, th);
1758 static int osd_mknod(struct osd_thread_info *info, struct osd_object *obj,
1759 struct lu_attr *attr,
1760 struct dt_allocation_hint *hint,
1761 struct dt_object_format *dof,
1764 cfs_umode_t mode = attr->la_mode & (S_IFMT | S_IALLUGO | S_ISVTX);
1767 LINVRNT(osd_invariant(obj));
1768 LASSERT(obj->oo_inode == NULL);
1769 LASSERT(S_ISCHR(mode) || S_ISBLK(mode) ||
1770 S_ISFIFO(mode) || S_ISSOCK(mode));
1772 result = osd_mkfile(info, obj, mode, hint, th);
1774 LASSERT(obj->oo_inode != NULL);
1776 * This inode should be marked dirty for i_rdev. Currently
1777 * that is done in the osd_attr_init().
1779 init_special_inode(obj->oo_inode, mode, attr->la_rdev);
1781 LINVRNT(osd_invariant(obj));
1785 typedef int (*osd_obj_type_f)(struct osd_thread_info *, struct osd_object *,
1787 struct dt_allocation_hint *hint,
1788 struct dt_object_format *dof,
1791 static osd_obj_type_f osd_create_type_f(enum dt_format_type type)
1793 osd_obj_type_f result;
1809 result = osd_mk_index;
1820 static void osd_ah_init(const struct lu_env *env, struct dt_allocation_hint *ah,
1821 struct dt_object *parent, struct dt_object *child,
1822 cfs_umode_t child_mode)
1826 memset(ah, 0, sizeof(*ah));
1827 ah->dah_parent = parent;
1828 ah->dah_mode = child_mode;
1831 static void osd_attr_init(struct osd_thread_info *info, struct osd_object *obj,
1832 struct lu_attr *attr, struct dt_object_format *dof)
1834 struct inode *inode = obj->oo_inode;
1835 __u64 valid = attr->la_valid;
1838 attr->la_valid &= ~(LA_TYPE | LA_MODE);
1840 if (dof->dof_type != DFT_NODE)
1841 attr->la_valid &= ~LA_RDEV;
1842 if ((valid & LA_ATIME) && (attr->la_atime == LTIME_S(inode->i_atime)))
1843 attr->la_valid &= ~LA_ATIME;
1844 if ((valid & LA_CTIME) && (attr->la_ctime == LTIME_S(inode->i_ctime)))
1845 attr->la_valid &= ~LA_CTIME;
1846 if ((valid & LA_MTIME) && (attr->la_mtime == LTIME_S(inode->i_mtime)))
1847 attr->la_valid &= ~LA_MTIME;
1849 result = osd_quota_transfer(inode, attr);
1853 if (attr->la_valid != 0) {
1854 result = osd_inode_setattr(info->oti_env, inode, attr);
1856 * The osd_inode_setattr() should always succeed here. The
1857 * only error that could be returned is EDQUOT when we are
1858 * trying to change the UID or GID of the inode. However, this
1859 * should not happen since quota enforcement is no longer
1860 * enabled on ldiskfs (lquota takes care of it).
1862 LASSERTF(result == 0, "%d", result);
1863 inode->i_sb->s_op->dirty_inode(inode);
1866 attr->la_valid = valid;
1870 * Helper function for osd_object_create()
1872 * \retval 0, on success
1874 static int __osd_object_create(struct osd_thread_info *info,
1875 struct osd_object *obj, struct lu_attr *attr,
1876 struct dt_allocation_hint *hint,
1877 struct dt_object_format *dof,
1882 result = osd_create_type_f(dof->dof_type)(info, obj, attr, hint, dof,
1885 osd_attr_init(info, obj, attr, dof);
1886 osd_object_init0(obj);
1888 if (obj->oo_inode && (obj->oo_inode->i_state & I_NEW))
1889 unlock_new_inode(obj->oo_inode);
1896 * Helper function for osd_object_create()
1898 * \retval 0, on success
1900 static int __osd_oi_insert(const struct lu_env *env, struct osd_object *obj,
1901 const struct lu_fid *fid, struct thandle *th)
1903 struct osd_thread_info *info = osd_oti_get(env);
1904 struct osd_inode_id *id = &info->oti_id;
1905 struct osd_device *osd = osd_obj2dev(obj);
1907 LASSERT(obj->oo_inode != NULL);
1909 osd_id_gen(id, obj->oo_inode->i_ino, obj->oo_inode->i_generation);
1910 return osd_oi_insert(info, osd, fid, id, th);
1913 static int osd_declare_object_create(const struct lu_env *env,
1914 struct dt_object *dt,
1915 struct lu_attr *attr,
1916 struct dt_allocation_hint *hint,
1917 struct dt_object_format *dof,
1918 struct thandle *handle)
1920 struct osd_thandle *oh;
1924 LASSERT(handle != NULL);
1926 oh = container_of0(handle, struct osd_thandle, ot_super);
1927 LASSERT(oh->ot_handle == NULL);
1929 OSD_DECLARE_OP(oh, create, osd_dto_credits_noquota[DTO_OBJECT_CREATE]);
1930 /* XXX: So far, only normal fid needs be inserted into the oi,
1931 * things could be changed later. Revise following code then. */
1932 if (fid_is_norm(lu_object_fid(&dt->do_lu))) {
1933 /* Reuse idle OI block may cause additional one OI block
1935 OSD_DECLARE_OP(oh, insert,
1936 osd_dto_credits_noquota[DTO_INDEX_INSERT] + 1);
1938 /* If this is directory, then we expect . and .. to be inserted as
1939 * well. The one directory block always needs to be created for the
1940 * directory, so we could use DTO_WRITE_BASE here (GDT, block bitmap,
1941 * block), there is no danger of needing a tree for the first block.
1943 if (attr && S_ISDIR(attr->la_mode)) {
1944 OSD_DECLARE_OP(oh, insert,
1945 osd_dto_credits_noquota[DTO_WRITE_BASE]);
1946 OSD_DECLARE_OP(oh, insert, 0);
1952 rc = osd_declare_inode_qid(env, attr->la_uid, attr->la_gid, 1, oh,
1953 false, false, NULL, false);
1957 static int osd_object_create(const struct lu_env *env, struct dt_object *dt,
1958 struct lu_attr *attr,
1959 struct dt_allocation_hint *hint,
1960 struct dt_object_format *dof,
1963 const struct lu_fid *fid = lu_object_fid(&dt->do_lu);
1964 struct osd_object *obj = osd_dt_obj(dt);
1965 struct osd_thread_info *info = osd_oti_get(env);
1970 LINVRNT(osd_invariant(obj));
1971 LASSERT(!dt_object_exists(dt));
1972 LASSERT(osd_write_locked(env, obj));
1973 LASSERT(th != NULL);
1975 if (unlikely(fid_is_acct(fid)))
1976 /* Quota files can't be created from the kernel any more,
1977 * 'tune2fs -O quota' will take care of creating them */
1980 OSD_EXEC_OP(th, create);
1982 result = __osd_object_create(info, obj, attr, hint, dof, th);
1984 result = __osd_oi_insert(env, obj, fid, th);
1986 LASSERT(ergo(result == 0, dt_object_exists(dt)));
1987 LASSERT(osd_invariant(obj));
1992 * Called to destroy on-disk representation of the object
1994 * Concurrency: must be locked
1996 static int osd_declare_object_destroy(const struct lu_env *env,
1997 struct dt_object *dt,
2000 struct osd_object *obj = osd_dt_obj(dt);
2001 struct inode *inode = obj->oo_inode;
2002 struct osd_thandle *oh;
2006 oh = container_of0(th, struct osd_thandle, ot_super);
2007 LASSERT(oh->ot_handle == NULL);
2010 OSD_DECLARE_OP(oh, delete, osd_dto_credits_noquota[DTO_OBJECT_DELETE]);
2011 /* XXX: So far, only normal fid needs to be inserted into the OI,
2012 * so only normal fid needs to be removed from the OI also.
2013 * Recycle idle OI leaf may cause additional three OI blocks
2015 OSD_DECLARE_OP(oh, destroy, fid_is_norm(lu_object_fid(&dt->do_lu)) ?
2016 osd_dto_credits_noquota[DTO_INDEX_DELETE] + 3 : 0);
2018 /* one less inode */
2019 rc = osd_declare_inode_qid(env, inode->i_uid, inode->i_gid, -1, oh,
2020 false, true, NULL, false);
2023 /* data to be truncated */
2024 rc = osd_declare_inode_qid(env, inode->i_uid, inode->i_gid, 0, oh,
2025 true, true, NULL, false);
2029 static int osd_object_destroy(const struct lu_env *env,
2030 struct dt_object *dt,
2033 const struct lu_fid *fid = lu_object_fid(&dt->do_lu);
2034 struct osd_object *obj = osd_dt_obj(dt);
2035 struct inode *inode = obj->oo_inode;
2036 struct osd_device *osd = osd_obj2dev(obj);
2037 struct osd_thandle *oh;
2041 oh = container_of0(th, struct osd_thandle, ot_super);
2042 LASSERT(oh->ot_handle);
2044 LASSERT(!lu_object_is_dying(dt->do_lu.lo_header));
2046 if (unlikely(fid_is_acct(fid)))
2049 /* Parallel control for OI scrub. For most of cases, there is no
2050 * lock contention. So it will not affect unlink performance. */
2051 cfs_mutex_lock(&inode->i_mutex);
2052 if (S_ISDIR(inode->i_mode)) {
2053 LASSERT(osd_inode_unlinked(inode) ||
2054 inode->i_nlink == 1);
2055 cfs_spin_lock(&obj->oo_guard);
2057 cfs_spin_unlock(&obj->oo_guard);
2058 inode->i_sb->s_op->dirty_inode(inode);
2060 LASSERT(osd_inode_unlinked(inode));
2063 OSD_EXEC_OP(th, destroy);
2065 result = osd_oi_delete(osd_oti_get(env), osd, fid, th);
2066 cfs_mutex_unlock(&inode->i_mutex);
2068 /* XXX: add to ext3 orphan list */
2069 /* rc = ext3_orphan_add(handle_t *handle, struct inode *inode) */
2071 /* not needed in the cache anymore */
2072 set_bit(LU_OBJECT_HEARD_BANSHEE, &dt->do_lu.lo_header->loh_flags);
2078 * Helper function for osd_xattr_set()
2080 static int __osd_xattr_set(const struct lu_env *env, struct dt_object *dt,
2081 const struct lu_buf *buf, const char *name, int fl)
2083 struct osd_object *obj = osd_dt_obj(dt);
2084 struct inode *inode = obj->oo_inode;
2085 struct osd_thread_info *info = osd_oti_get(env);
2086 struct dentry *dentry = &info->oti_child_dentry;
2090 LASSERT(dt_object_exists(dt));
2091 LASSERT(inode->i_op != NULL && inode->i_op->setxattr != NULL);
2093 if (fl & LU_XATTR_REPLACE)
2094 fs_flags |= XATTR_REPLACE;
2096 if (fl & LU_XATTR_CREATE)
2097 fs_flags |= XATTR_CREATE;
2099 ll_vfs_dq_init(inode);
2100 dentry->d_inode = inode;
2101 rc = inode->i_op->setxattr(dentry, name, buf->lb_buf,
2102 buf->lb_len, fs_flags);
2107 * Put the fid into lustre_mdt_attrs, and then place the structure
2108 * inode's ea. This fid should not be altered during the life time
2111 * \retval +ve, on success
2112 * \retval -ve, on error
2114 * FIXME: It is good to have/use ldiskfs_xattr_set_handle() here
2116 static int osd_ea_fid_set(const struct lu_env *env, struct dt_object *dt,
2117 const struct lu_fid *fid)
2119 struct osd_thread_info *info = osd_oti_get(env);
2120 struct lustre_mdt_attrs *mdt_attrs = &info->oti_mdt_attrs;
2122 lustre_lma_init(mdt_attrs, fid);
2123 lustre_lma_swab(mdt_attrs);
2124 return __osd_xattr_set(env, dt,
2125 osd_buf_get(env, mdt_attrs, sizeof *mdt_attrs),
2126 XATTR_NAME_LMA, LU_XATTR_CREATE);
2131 * ldiskfs supports fid in dirent, it is passed in dentry->d_fsdata.
2132 * lustre 1.8 also uses d_fsdata for passing other info to ldiskfs.
2133 * To have compatilibility with 1.8 ldiskfs driver we need to have
2134 * magic number at start of fid data.
2135 * \ldiskfs_dentry_param is used only to pass fid from osd to ldiskfs.
2138 void osd_get_ldiskfs_dirent_param(struct ldiskfs_dentry_param *param,
2139 const struct dt_rec *fid)
2141 param->edp_magic = LDISKFS_LUFID_MAGIC;
2142 param->edp_len = sizeof(struct lu_fid) + 1;
2144 fid_cpu_to_be((struct lu_fid *)param->edp_data,
2145 (struct lu_fid *)fid);
2149 * Try to read the fid from inode ea into dt_rec, if return value
2150 * i.e. rc is +ve, then we got fid, otherwise we will have to form igif
2152 * \param fid object fid.
2154 * \retval 0 on success
2156 static int osd_ea_fid_get(const struct lu_env *env, struct osd_object *obj,
2157 __u32 ino, struct lu_fid *fid,
2158 struct osd_inode_id *id)
2160 struct osd_thread_info *info = osd_oti_get(env);
2161 struct inode *inode;
2164 osd_id_gen(id, ino, OSD_OII_NOGEN);
2165 inode = osd_iget_fid(info, osd_obj2dev(obj), id, fid);
2167 RETURN(PTR_ERR(inode));
2174 * OSD layer object create function for interoperability mode (b11826).
2175 * This is mostly similar to osd_object_create(). Only difference being, fid is
2176 * inserted into inode ea here.
2178 * \retval 0, on success
2179 * \retval -ve, on error
2181 static int osd_object_ea_create(const struct lu_env *env, struct dt_object *dt,
2182 struct lu_attr *attr,
2183 struct dt_allocation_hint *hint,
2184 struct dt_object_format *dof,
2187 const struct lu_fid *fid = lu_object_fid(&dt->do_lu);
2188 struct osd_object *obj = osd_dt_obj(dt);
2189 struct osd_thread_info *info = osd_oti_get(env);
2194 LASSERT(osd_invariant(obj));
2195 LASSERT(!dt_object_exists(dt));
2196 LASSERT(osd_write_locked(env, obj));
2197 LASSERT(th != NULL);
2199 if (unlikely(fid_is_acct(fid)))
2200 /* Quota files can't be created from the kernel any more,
2201 * 'tune2fs -O quota' will take care of creating them */
2204 OSD_EXEC_OP(th, create);
2206 result = __osd_object_create(info, obj, attr, hint, dof, th);
2207 /* objects under osd root shld have igif fid, so dont add fid EA */
2208 if (result == 0 && fid_seq(fid) >= FID_SEQ_NORMAL)
2209 result = osd_ea_fid_set(env, dt, fid);
2212 result = __osd_oi_insert(env, obj, fid, th);
2214 LASSERT(ergo(result == 0, dt_object_exists(dt)));
2215 LINVRNT(osd_invariant(obj));
2219 static int osd_declare_object_ref_add(const struct lu_env *env,
2220 struct dt_object *dt,
2221 struct thandle *handle)
2223 struct osd_thandle *oh;
2225 /* it's possible that object doesn't exist yet */
2226 LASSERT(handle != NULL);
2228 oh = container_of0(handle, struct osd_thandle, ot_super);
2229 LASSERT(oh->ot_handle == NULL);
2231 OSD_DECLARE_OP(oh, ref_add, osd_dto_credits_noquota[DTO_ATTR_SET_BASE]);
2237 * Concurrency: @dt is write locked.
2239 static int osd_object_ref_add(const struct lu_env *env,
2240 struct dt_object *dt, struct thandle *th)
2242 struct osd_object *obj = osd_dt_obj(dt);
2243 struct inode *inode = obj->oo_inode;
2245 LINVRNT(osd_invariant(obj));
2246 LASSERT(dt_object_exists(dt));
2247 LASSERT(osd_write_locked(env, obj));
2248 LASSERT(th != NULL);
2250 OSD_EXEC_OP(th, ref_add);
2253 * DIR_NLINK feature is set for compatibility reasons if:
2254 * 1) nlinks > LDISKFS_LINK_MAX, or
2255 * 2) nlinks == 2, since this indicates i_nlink was previously 1.
2257 * It is easier to always set this flag (rather than check and set),
2258 * since it has less overhead, and the superblock will be dirtied
2259 * at some point. Both e2fsprogs and any Lustre-supported ldiskfs
2260 * do not actually care whether this flag is set or not.
2262 cfs_spin_lock(&obj->oo_guard);
2263 /* inc_nlink from 0 may cause WARN_ON */
2264 if(inode->i_nlink == 0)
2265 set_nlink(inode, 1);
2268 if (S_ISDIR(inode->i_mode) && inode->i_nlink > 1) {
2269 if (inode->i_nlink >= LDISKFS_LINK_MAX ||
2270 inode->i_nlink == 2)
2271 set_nlink(inode, 1);
2273 LASSERT(inode->i_nlink <= LDISKFS_LINK_MAX);
2274 cfs_spin_unlock(&obj->oo_guard);
2275 inode->i_sb->s_op->dirty_inode(inode);
2276 LINVRNT(osd_invariant(obj));
2281 static int osd_declare_object_ref_del(const struct lu_env *env,
2282 struct dt_object *dt,
2283 struct thandle *handle)
2285 struct osd_thandle *oh;
2287 LASSERT(dt_object_exists(dt));
2288 LASSERT(handle != NULL);
2290 oh = container_of0(handle, struct osd_thandle, ot_super);
2291 LASSERT(oh->ot_handle == NULL);
2293 OSD_DECLARE_OP(oh, ref_del, osd_dto_credits_noquota[DTO_ATTR_SET_BASE]);
2299 * Concurrency: @dt is write locked.
2301 static int osd_object_ref_del(const struct lu_env *env, struct dt_object *dt,
2304 struct osd_object *obj = osd_dt_obj(dt);
2305 struct inode *inode = obj->oo_inode;
2307 LINVRNT(osd_invariant(obj));
2308 LASSERT(dt_object_exists(dt));
2309 LASSERT(osd_write_locked(env, obj));
2310 LASSERT(th != NULL);
2312 OSD_EXEC_OP(th, ref_del);
2314 cfs_spin_lock(&obj->oo_guard);
2315 LASSERT(inode->i_nlink > 0);
2317 /* If this is/was a many-subdir directory (nlink > LDISKFS_LINK_MAX)
2318 * then the nlink count is 1. Don't let it be set to 0 or the directory
2319 * inode will be deleted incorrectly. */
2320 if (S_ISDIR(inode->i_mode) && inode->i_nlink == 0)
2321 set_nlink(inode, 1);
2322 cfs_spin_unlock(&obj->oo_guard);
2323 inode->i_sb->s_op->dirty_inode(inode);
2324 LINVRNT(osd_invariant(obj));
2330 * Get the 64-bit version for an inode.
2332 static int osd_object_version_get(const struct lu_env *env,
2333 struct dt_object *dt, dt_obj_version_t *ver)
2335 struct inode *inode = osd_dt_obj(dt)->oo_inode;
2337 CDEBUG(D_INODE, "Get version "LPX64" for inode %lu\n",
2338 LDISKFS_I(inode)->i_fs_version, inode->i_ino);
2339 *ver = LDISKFS_I(inode)->i_fs_version;
2344 * Concurrency: @dt is read locked.
2346 static int osd_xattr_get(const struct lu_env *env, struct dt_object *dt,
2347 struct lu_buf *buf, const char *name,
2348 struct lustre_capa *capa)
2350 struct osd_object *obj = osd_dt_obj(dt);
2351 struct inode *inode = obj->oo_inode;
2352 struct osd_thread_info *info = osd_oti_get(env);
2353 struct dentry *dentry = &info->oti_obj_dentry;
2355 /* version get is not real XATTR but uses xattr API */
2356 if (strcmp(name, XATTR_NAME_VERSION) == 0) {
2357 /* for version we are just using xattr API but change inode
2359 LASSERT(buf->lb_len == sizeof(dt_obj_version_t));
2360 osd_object_version_get(env, dt, buf->lb_buf);
2361 return sizeof(dt_obj_version_t);
2364 LASSERT(dt_object_exists(dt));
2365 LASSERT(inode->i_op != NULL && inode->i_op->getxattr != NULL);
2367 if (osd_object_auth(env, dt, capa, CAPA_OPC_META_READ))
2370 dentry->d_inode = inode;
2371 return inode->i_op->getxattr(dentry, name, buf->lb_buf, buf->lb_len);
2375 static int osd_declare_xattr_set(const struct lu_env *env,
2376 struct dt_object *dt,
2377 const struct lu_buf *buf, const char *name,
2378 int fl, struct thandle *handle)
2380 struct osd_thandle *oh;
2382 LASSERT(handle != NULL);
2384 oh = container_of0(handle, struct osd_thandle, ot_super);
2385 LASSERT(oh->ot_handle == NULL);
2387 OSD_DECLARE_OP(oh, xattr_set, strcmp(name, XATTR_NAME_VERSION) == 0 ?
2388 osd_dto_credits_noquota[DTO_ATTR_SET_BASE] :
2389 osd_dto_credits_noquota[DTO_XATTR_SET]);
2395 * Set the 64-bit version for object
2397 static void osd_object_version_set(const struct lu_env *env,
2398 struct dt_object *dt,
2399 dt_obj_version_t *new_version)
2401 struct inode *inode = osd_dt_obj(dt)->oo_inode;
2403 CDEBUG(D_INODE, "Set version "LPX64" (old "LPX64") for inode %lu\n",
2404 *new_version, LDISKFS_I(inode)->i_fs_version, inode->i_ino);
2406 LDISKFS_I(inode)->i_fs_version = *new_version;
2407 /** Version is set after all inode operations are finished,
2408 * so we should mark it dirty here */
2409 inode->i_sb->s_op->dirty_inode(inode);
2413 * Concurrency: @dt is write locked.
2415 static int osd_xattr_set(const struct lu_env *env, struct dt_object *dt,
2416 const struct lu_buf *buf, const char *name, int fl,
2417 struct thandle *handle, struct lustre_capa *capa)
2419 LASSERT(handle != NULL);
2421 /* version set is not real XATTR */
2422 if (strcmp(name, XATTR_NAME_VERSION) == 0) {
2423 /* for version we are just using xattr API but change inode
2425 LASSERT(buf->lb_len == sizeof(dt_obj_version_t));
2426 osd_object_version_set(env, dt, buf->lb_buf);
2427 return sizeof(dt_obj_version_t);
2430 if (osd_object_auth(env, dt, capa, CAPA_OPC_META_WRITE))
2433 OSD_EXEC_OP(handle, xattr_set);
2434 return __osd_xattr_set(env, dt, buf, name, fl);
2438 * Concurrency: @dt is read locked.
2440 static int osd_xattr_list(const struct lu_env *env, struct dt_object *dt,
2441 struct lu_buf *buf, struct lustre_capa *capa)
2443 struct osd_object *obj = osd_dt_obj(dt);
2444 struct inode *inode = obj->oo_inode;
2445 struct osd_thread_info *info = osd_oti_get(env);
2446 struct dentry *dentry = &info->oti_obj_dentry;
2448 LASSERT(dt_object_exists(dt));
2449 LASSERT(inode->i_op != NULL && inode->i_op->listxattr != NULL);
2450 LASSERT(osd_read_locked(env, obj) || osd_write_locked(env, obj));
2452 if (osd_object_auth(env, dt, capa, CAPA_OPC_META_READ))
2455 dentry->d_inode = inode;
2456 return inode->i_op->listxattr(dentry, buf->lb_buf, buf->lb_len);
2459 static int osd_declare_xattr_del(const struct lu_env *env,
2460 struct dt_object *dt, const char *name,
2461 struct thandle *handle)
2463 struct osd_thandle *oh;
2465 LASSERT(dt_object_exists(dt));
2466 LASSERT(handle != NULL);
2468 oh = container_of0(handle, struct osd_thandle, ot_super);
2469 LASSERT(oh->ot_handle == NULL);
2471 OSD_DECLARE_OP(oh, xattr_set, osd_dto_credits_noquota[DTO_XATTR_SET]);
2477 * Concurrency: @dt is write locked.
2479 static int osd_xattr_del(const struct lu_env *env, struct dt_object *dt,
2480 const char *name, struct thandle *handle,
2481 struct lustre_capa *capa)
2483 struct osd_object *obj = osd_dt_obj(dt);
2484 struct inode *inode = obj->oo_inode;
2485 struct osd_thread_info *info = osd_oti_get(env);
2486 struct dentry *dentry = &info->oti_obj_dentry;
2489 LASSERT(dt_object_exists(dt));
2490 LASSERT(inode->i_op != NULL && inode->i_op->removexattr != NULL);
2491 LASSERT(osd_write_locked(env, obj));
2492 LASSERT(handle != NULL);
2494 if (osd_object_auth(env, dt, capa, CAPA_OPC_META_WRITE))
2497 OSD_EXEC_OP(handle, xattr_set);
2499 ll_vfs_dq_init(inode);
2500 dentry->d_inode = inode;
2501 rc = inode->i_op->removexattr(dentry, name);
2505 static struct obd_capa *osd_capa_get(const struct lu_env *env,
2506 struct dt_object *dt,
2507 struct lustre_capa *old,
2510 struct osd_thread_info *info = osd_oti_get(env);
2511 const struct lu_fid *fid = lu_object_fid(&dt->do_lu);
2512 struct osd_object *obj = osd_dt_obj(dt);
2513 struct osd_device *dev = osd_obj2dev(obj);
2514 struct lustre_capa_key *key = &info->oti_capa_key;
2515 struct lustre_capa *capa = &info->oti_capa;
2516 struct obd_capa *oc;
2517 struct md_capainfo *ci;
2521 if (!dev->od_fl_capa)
2522 RETURN(ERR_PTR(-ENOENT));
2524 LASSERT(dt_object_exists(dt));
2525 LINVRNT(osd_invariant(obj));
2527 /* renewal sanity check */
2528 if (old && osd_object_auth(env, dt, old, opc))
2529 RETURN(ERR_PTR(-EACCES));
2531 ci = md_capainfo(env);
2533 RETURN(ERR_PTR(-ENOENT));
2535 switch (ci->mc_auth) {
2539 capa->lc_uid = obj->oo_inode->i_uid;
2540 capa->lc_gid = obj->oo_inode->i_gid;
2541 capa->lc_flags = LC_ID_PLAIN;
2543 case LC_ID_CONVERT: {
2546 s[0] = obj->oo_inode->i_uid;
2547 cfs_get_random_bytes(&(s[1]), sizeof(__u32));
2548 s[2] = obj->oo_inode->i_gid;
2549 cfs_get_random_bytes(&(s[3]), sizeof(__u32));
2550 rc = capa_encrypt_id(d, s, key->lk_key, CAPA_HMAC_KEY_MAX_LEN);
2552 RETURN(ERR_PTR(rc));
2554 capa->lc_uid = ((__u64)d[1] << 32) | d[0];
2555 capa->lc_gid = ((__u64)d[3] << 32) | d[2];
2556 capa->lc_flags = LC_ID_CONVERT;
2560 RETURN(ERR_PTR(-EINVAL));
2563 capa->lc_fid = *fid;
2565 capa->lc_flags |= dev->od_capa_alg << 24;
2566 capa->lc_timeout = dev->od_capa_timeout;
2567 capa->lc_expiry = 0;
2569 oc = capa_lookup(dev->od_capa_hash, capa, 1);
2571 LASSERT(!capa_is_expired(oc));
2575 cfs_spin_lock(&capa_lock);
2576 *key = dev->od_capa_keys[1];
2577 cfs_spin_unlock(&capa_lock);
2579 capa->lc_keyid = key->lk_keyid;
2580 capa->lc_expiry = cfs_time_current_sec() + dev->od_capa_timeout;
2582 rc = capa_hmac(capa->lc_hmac, capa, key->lk_key);
2584 DEBUG_CAPA(D_ERROR, capa, "HMAC failed: %d for", rc);
2585 RETURN(ERR_PTR(rc));
2588 oc = capa_add(dev->od_capa_hash, capa);
2592 static int osd_object_sync(const struct lu_env *env, struct dt_object *dt)
2594 struct osd_object *obj = osd_dt_obj(dt);
2595 struct inode *inode = obj->oo_inode;
2596 struct osd_thread_info *info = osd_oti_get(env);
2597 struct dentry *dentry = &info->oti_obj_dentry;
2598 struct file *file = &info->oti_file;
2603 dentry->d_inode = inode;
2604 file->f_dentry = dentry;
2605 file->f_mapping = inode->i_mapping;
2606 file->f_op = inode->i_fop;
2607 mutex_lock(&inode->i_mutex);
2608 rc = file->f_op->fsync(file, dentry, 0);
2609 mutex_unlock(&inode->i_mutex);
2613 static int osd_data_get(const struct lu_env *env, struct dt_object *dt,
2616 struct osd_object *obj = osd_dt_obj(dt);
2619 *data = (void *)obj->oo_inode;
2627 static int osd_iam_index_probe(const struct lu_env *env, struct osd_object *o,
2628 const struct dt_index_features *feat)
2630 struct iam_descr *descr;
2632 if (osd_object_is_root(o))
2633 return feat == &dt_directory_features;
2635 LASSERT(o->oo_dir != NULL);
2637 descr = o->oo_dir->od_container.ic_descr;
2638 if (feat == &dt_directory_features) {
2639 if (descr->id_rec_size == sizeof(struct osd_fid_pack))
2645 feat->dif_keysize_min <= descr->id_key_size &&
2646 descr->id_key_size <= feat->dif_keysize_max &&
2647 feat->dif_recsize_min <= descr->id_rec_size &&
2648 descr->id_rec_size <= feat->dif_recsize_max &&
2649 !(feat->dif_flags & (DT_IND_VARKEY |
2650 DT_IND_VARREC | DT_IND_NONUNQ)) &&
2651 ergo(feat->dif_flags & DT_IND_UPDATE,
2652 1 /* XXX check that object (and file system) is
2657 static int osd_iam_container_init(const struct lu_env *env,
2658 struct osd_object *obj,
2659 struct osd_directory *dir)
2661 struct iam_container *bag = &dir->od_container;
2664 result = iam_container_init(bag, &dir->od_descr, obj->oo_inode);
2668 result = iam_container_setup(bag);
2670 obj->oo_dt.do_index_ops = &osd_index_iam_ops;
2672 iam_container_fini(bag);
2679 * Concurrency: no external locking is necessary.
2681 static int osd_index_try(const struct lu_env *env, struct dt_object *dt,
2682 const struct dt_index_features *feat)
2686 struct osd_object *obj = osd_dt_obj(dt);
2688 LINVRNT(osd_invariant(obj));
2689 LASSERT(dt_object_exists(dt));
2691 if (osd_object_is_root(obj)) {
2692 dt->do_index_ops = &osd_index_ea_ops;
2694 } else if (feat == &dt_directory_features) {
2695 dt->do_index_ops = &osd_index_ea_ops;
2696 if (S_ISDIR(obj->oo_inode->i_mode))
2701 } else if (unlikely(feat == &dt_otable_features)) {
2702 dt->do_index_ops = &osd_otable_ops;
2704 } else if (feat == &dt_acct_features) {
2705 dt->do_index_ops = &osd_acct_index_ops;
2708 } else if (!osd_has_index(obj)) {
2709 struct osd_directory *dir;
2714 cfs_spin_lock(&obj->oo_guard);
2715 if (obj->oo_dir == NULL)
2719 * Concurrent thread allocated container data.
2722 cfs_spin_unlock(&obj->oo_guard);
2724 * Now, that we have container data, serialize its
2727 cfs_down_write(&obj->oo_ext_idx_sem);
2729 * recheck under lock.
2731 if (!osd_has_index(obj))
2732 result = osd_iam_container_init(env, obj, dir);
2735 cfs_up_write(&obj->oo_ext_idx_sem);
2743 if (result == 0 && skip_iam == 0) {
2744 if (!osd_iam_index_probe(env, obj, feat))
2747 LINVRNT(osd_invariant(obj));
2749 if (is_quota_glb_feat(feat))
2750 result = osd_quota_migration(env, dt, feat);
2755 static int osd_otable_it_attr_get(const struct lu_env *env,
2756 struct dt_object *dt,
2757 struct lu_attr *attr,
2758 struct lustre_capa *capa)
2764 static const struct dt_object_operations osd_obj_ops = {
2765 .do_read_lock = osd_object_read_lock,
2766 .do_write_lock = osd_object_write_lock,
2767 .do_read_unlock = osd_object_read_unlock,
2768 .do_write_unlock = osd_object_write_unlock,
2769 .do_write_locked = osd_object_write_locked,
2770 .do_attr_get = osd_attr_get,
2771 .do_declare_attr_set = osd_declare_attr_set,
2772 .do_attr_set = osd_attr_set,
2773 .do_ah_init = osd_ah_init,
2774 .do_declare_create = osd_declare_object_create,
2775 .do_create = osd_object_create,
2776 .do_declare_destroy = osd_declare_object_destroy,
2777 .do_destroy = osd_object_destroy,
2778 .do_index_try = osd_index_try,
2779 .do_declare_ref_add = osd_declare_object_ref_add,
2780 .do_ref_add = osd_object_ref_add,
2781 .do_declare_ref_del = osd_declare_object_ref_del,
2782 .do_ref_del = osd_object_ref_del,
2783 .do_xattr_get = osd_xattr_get,
2784 .do_declare_xattr_set = osd_declare_xattr_set,
2785 .do_xattr_set = osd_xattr_set,
2786 .do_declare_xattr_del = osd_declare_xattr_del,
2787 .do_xattr_del = osd_xattr_del,
2788 .do_xattr_list = osd_xattr_list,
2789 .do_capa_get = osd_capa_get,
2790 .do_object_sync = osd_object_sync,
2791 .do_data_get = osd_data_get,
2795 * dt_object_operations for interoperability mode
2796 * (i.e. to run 2.0 mds on 1.8 disk) (b11826)
2798 static const struct dt_object_operations osd_obj_ea_ops = {
2799 .do_read_lock = osd_object_read_lock,
2800 .do_write_lock = osd_object_write_lock,
2801 .do_read_unlock = osd_object_read_unlock,
2802 .do_write_unlock = osd_object_write_unlock,
2803 .do_write_locked = osd_object_write_locked,
2804 .do_attr_get = osd_attr_get,
2805 .do_declare_attr_set = osd_declare_attr_set,
2806 .do_attr_set = osd_attr_set,
2807 .do_ah_init = osd_ah_init,
2808 .do_declare_create = osd_declare_object_create,
2809 .do_create = osd_object_ea_create,
2810 .do_declare_destroy = osd_declare_object_destroy,
2811 .do_destroy = osd_object_destroy,
2812 .do_index_try = osd_index_try,
2813 .do_declare_ref_add = osd_declare_object_ref_add,
2814 .do_ref_add = osd_object_ref_add,
2815 .do_declare_ref_del = osd_declare_object_ref_del,
2816 .do_ref_del = osd_object_ref_del,
2817 .do_xattr_get = osd_xattr_get,
2818 .do_declare_xattr_set = osd_declare_xattr_set,
2819 .do_xattr_set = osd_xattr_set,
2820 .do_declare_xattr_del = osd_declare_xattr_del,
2821 .do_xattr_del = osd_xattr_del,
2822 .do_xattr_list = osd_xattr_list,
2823 .do_capa_get = osd_capa_get,
2824 .do_object_sync = osd_object_sync,
2825 .do_data_get = osd_data_get,
2828 static const struct dt_object_operations osd_obj_otable_it_ops = {
2829 .do_attr_get = osd_otable_it_attr_get,
2830 .do_index_try = osd_index_try,
2833 static int osd_index_declare_iam_delete(const struct lu_env *env,
2834 struct dt_object *dt,
2835 const struct dt_key *key,
2836 struct thandle *handle)
2838 struct osd_thandle *oh;
2840 oh = container_of0(handle, struct osd_thandle, ot_super);
2841 LASSERT(oh->ot_handle == NULL);
2843 OSD_DECLARE_OP(oh, delete, osd_dto_credits_noquota[DTO_INDEX_DELETE]);
2849 * delete a (key, value) pair from index \a dt specified by \a key
2851 * \param dt osd index object
2852 * \param key key for index
2853 * \param rec record reference
2854 * \param handle transaction handler
2857 * \retval -ve failure
2860 static int osd_index_iam_delete(const struct lu_env *env, struct dt_object *dt,
2861 const struct dt_key *key,
2862 struct thandle *handle,
2863 struct lustre_capa *capa)
2865 struct osd_thread_info *oti = osd_oti_get(env);
2866 struct osd_object *obj = osd_dt_obj(dt);
2867 struct osd_thandle *oh;
2868 struct iam_path_descr *ipd;
2869 struct iam_container *bag = &obj->oo_dir->od_container;
2874 LINVRNT(osd_invariant(obj));
2875 LASSERT(dt_object_exists(dt));
2876 LASSERT(bag->ic_object == obj->oo_inode);
2877 LASSERT(handle != NULL);
2879 if (osd_object_auth(env, dt, capa, CAPA_OPC_INDEX_DELETE))
2882 OSD_EXEC_OP(handle, delete);
2884 ipd = osd_idx_ipd_get(env, bag);
2885 if (unlikely(ipd == NULL))
2888 oh = container_of0(handle, struct osd_thandle, ot_super);
2889 LASSERT(oh->ot_handle != NULL);
2890 LASSERT(oh->ot_handle->h_transaction != NULL);
2892 if (fid_is_quota(lu_object_fid(&dt->do_lu))) {
2893 /* swab quota uid/gid provided by caller */
2894 oti->oti_quota_id = cpu_to_le64(*((__u64 *)key));
2895 key = (const struct dt_key *)&oti->oti_quota_id;
2898 rc = iam_delete(oh->ot_handle, bag, (const struct iam_key *)key, ipd);
2899 osd_ipd_put(env, bag, ipd);
2900 LINVRNT(osd_invariant(obj));
2904 static int osd_index_declare_ea_delete(const struct lu_env *env,
2905 struct dt_object *dt,
2906 const struct dt_key *key,
2907 struct thandle *handle)
2909 struct osd_thandle *oh;
2910 struct inode *inode;
2914 LASSERT(dt_object_exists(dt));
2915 LASSERT(handle != NULL);
2917 oh = container_of0(handle, struct osd_thandle, ot_super);
2918 LASSERT(oh->ot_handle == NULL);
2920 OSD_DECLARE_OP(oh, delete, osd_dto_credits_noquota[DTO_INDEX_DELETE]);
2922 inode = osd_dt_obj(dt)->oo_inode;
2925 rc = osd_declare_inode_qid(env, inode->i_uid, inode->i_gid, 0, oh,
2926 true, true, NULL, false);
2930 static inline int osd_get_fid_from_dentry(struct ldiskfs_dir_entry_2 *de,
2933 struct osd_fid_pack *rec;
2936 if (de->file_type & LDISKFS_DIRENT_LUFID) {
2937 rec = (struct osd_fid_pack *) (de->name + de->name_len + 1);
2938 rc = osd_fid_unpack((struct lu_fid *)fid, rec);
2944 * Index delete function for interoperability mode (b11826).
2945 * It will remove the directory entry added by osd_index_ea_insert().
2946 * This entry is needed to maintain name->fid mapping.
2948 * \param key, key i.e. file entry to be deleted
2950 * \retval 0, on success
2951 * \retval -ve, on error
2953 static int osd_index_ea_delete(const struct lu_env *env, struct dt_object *dt,
2954 const struct dt_key *key,
2955 struct thandle *handle,
2956 struct lustre_capa *capa)
2958 struct osd_object *obj = osd_dt_obj(dt);
2959 struct inode *dir = obj->oo_inode;
2960 struct dentry *dentry;
2961 struct osd_thandle *oh;
2962 struct ldiskfs_dir_entry_2 *de;
2963 struct buffer_head *bh;
2964 struct htree_lock *hlock = NULL;
2969 LINVRNT(osd_invariant(obj));
2970 LASSERT(dt_object_exists(dt));
2971 LASSERT(handle != NULL);
2973 OSD_EXEC_OP(handle, delete);
2975 oh = container_of(handle, struct osd_thandle, ot_super);
2976 LASSERT(oh->ot_handle != NULL);
2977 LASSERT(oh->ot_handle->h_transaction != NULL);
2979 if (osd_object_auth(env, dt, capa, CAPA_OPC_INDEX_DELETE))
2982 ll_vfs_dq_init(dir);
2983 dentry = osd_child_dentry_get(env, obj,
2984 (char *)key, strlen((char *)key));
2986 if (obj->oo_hl_head != NULL) {
2987 hlock = osd_oti_get(env)->oti_hlock;
2988 ldiskfs_htree_lock(hlock, obj->oo_hl_head,
2989 dir, LDISKFS_HLOCK_DEL);
2991 cfs_down_write(&obj->oo_ext_idx_sem);
2994 bh = osd_ldiskfs_find_entry(dir, dentry, &de, hlock);
2996 rc = ldiskfs_delete_entry(oh->ot_handle,
3003 ldiskfs_htree_unlock(hlock);
3005 cfs_up_write(&obj->oo_ext_idx_sem);
3007 LASSERT(osd_invariant(obj));
3012 * Lookup index for \a key and copy record to \a rec.
3014 * \param dt osd index object
3015 * \param key key for index
3016 * \param rec record reference
3018 * \retval +ve success : exact mach
3019 * \retval 0 return record with key not greater than \a key
3020 * \retval -ve failure
3022 static int osd_index_iam_lookup(const struct lu_env *env, struct dt_object *dt,
3023 struct dt_rec *rec, const struct dt_key *key,
3024 struct lustre_capa *capa)
3026 struct osd_object *obj = osd_dt_obj(dt);
3027 struct iam_path_descr *ipd;
3028 struct iam_container *bag = &obj->oo_dir->od_container;
3029 struct osd_thread_info *oti = osd_oti_get(env);
3030 struct iam_iterator *it = &oti->oti_idx_it;
3031 struct iam_rec *iam_rec;
3036 LASSERT(osd_invariant(obj));
3037 LASSERT(dt_object_exists(dt));
3038 LASSERT(bag->ic_object == obj->oo_inode);
3040 if (osd_object_auth(env, dt, capa, CAPA_OPC_INDEX_LOOKUP))
3043 ipd = osd_idx_ipd_get(env, bag);
3047 /* got ipd now we can start iterator. */
3048 iam_it_init(it, bag, 0, ipd);
3050 if (fid_is_quota(lu_object_fid(&dt->do_lu))) {
3051 /* swab quota uid/gid provided by caller */
3052 oti->oti_quota_id = cpu_to_le64(*((__u64 *)key));
3053 key = (const struct dt_key *)&oti->oti_quota_id;
3056 rc = iam_it_get(it, (struct iam_key *)key);
3058 if (S_ISDIR(obj->oo_inode->i_mode))
3059 iam_rec = (struct iam_rec *)oti->oti_ldp;
3061 iam_rec = (struct iam_rec *) rec;
3063 iam_reccpy(&it->ii_path.ip_leaf, (struct iam_rec *)iam_rec);
3065 if (S_ISDIR(obj->oo_inode->i_mode))
3066 osd_fid_unpack((struct lu_fid *) rec,
3067 (struct osd_fid_pack *)iam_rec);
3068 else if (fid_is_quota(lu_object_fid(&dt->do_lu)))
3069 osd_quota_unpack(obj, rec);
3074 osd_ipd_put(env, bag, ipd);
3076 LINVRNT(osd_invariant(obj));
3081 static int osd_index_declare_iam_insert(const struct lu_env *env,
3082 struct dt_object *dt,
3083 const struct dt_rec *rec,
3084 const struct dt_key *key,
3085 struct thandle *handle)
3087 struct osd_thandle *oh;
3089 LASSERT(dt_object_exists(dt));
3090 LASSERT(handle != NULL);
3092 oh = container_of0(handle, struct osd_thandle, ot_super);
3093 LASSERT(oh->ot_handle == NULL);
3095 OSD_DECLARE_OP(oh, insert, osd_dto_credits_noquota[DTO_INDEX_INSERT]);
3101 * Inserts (key, value) pair in \a dt index object.
3103 * \param dt osd index object
3104 * \param key key for index
3105 * \param rec record reference
3106 * \param th transaction handler
3109 * \retval -ve failure
3111 static int osd_index_iam_insert(const struct lu_env *env, struct dt_object *dt,
3112 const struct dt_rec *rec,
3113 const struct dt_key *key, struct thandle *th,
3114 struct lustre_capa *capa, int ignore_quota)
3116 struct osd_object *obj = osd_dt_obj(dt);
3117 struct iam_path_descr *ipd;
3118 struct osd_thandle *oh;
3119 struct iam_container *bag = &obj->oo_dir->od_container;
3120 struct osd_thread_info *oti = osd_oti_get(env);
3121 struct iam_rec *iam_rec;
3126 LINVRNT(osd_invariant(obj));
3127 LASSERT(dt_object_exists(dt));
3128 LASSERT(bag->ic_object == obj->oo_inode);
3129 LASSERT(th != NULL);
3131 if (osd_object_auth(env, dt, capa, CAPA_OPC_INDEX_INSERT))
3134 OSD_EXEC_OP(th, insert);
3136 ipd = osd_idx_ipd_get(env, bag);
3137 if (unlikely(ipd == NULL))
3140 oh = container_of0(th, struct osd_thandle, ot_super);
3141 LASSERT(oh->ot_handle != NULL);
3142 LASSERT(oh->ot_handle->h_transaction != NULL);
3143 if (S_ISDIR(obj->oo_inode->i_mode)) {
3144 iam_rec = (struct iam_rec *)oti->oti_ldp;
3145 osd_fid_pack((struct osd_fid_pack *)iam_rec, rec, &oti->oti_fid);
3146 } else if (fid_is_quota(lu_object_fid(&dt->do_lu))) {
3147 /* pack quota uid/gid */
3148 oti->oti_quota_id = cpu_to_le64(*((__u64 *)key));
3149 key = (const struct dt_key *)&oti->oti_quota_id;
3150 /* pack quota record */
3151 rec = osd_quota_pack(obj, rec, &oti->oti_quota_rec);
3152 iam_rec = (struct iam_rec *)rec;
3154 iam_rec = (struct iam_rec *)rec;
3157 rc = iam_insert(oh->ot_handle, bag, (const struct iam_key *)key,
3159 osd_ipd_put(env, bag, ipd);
3160 LINVRNT(osd_invariant(obj));
3165 * Calls ldiskfs_add_entry() to add directory entry
3166 * into the directory. This is required for
3167 * interoperability mode (b11826)
3169 * \retval 0, on success
3170 * \retval -ve, on error
3172 static int __osd_ea_add_rec(struct osd_thread_info *info,
3173 struct osd_object *pobj, struct inode *cinode,
3174 const char *name, const struct dt_rec *fid,
3175 struct htree_lock *hlock, struct thandle *th)
3177 struct ldiskfs_dentry_param *ldp;
3178 struct dentry *child;
3179 struct osd_thandle *oth;
3182 oth = container_of(th, struct osd_thandle, ot_super);
3183 LASSERT(oth->ot_handle != NULL);
3184 LASSERT(oth->ot_handle->h_transaction != NULL);
3186 child = osd_child_dentry_get(info->oti_env, pobj, name, strlen(name));
3188 /* XXX: remove fid_is_igif() check here.
3189 * IGIF check is just to handle insertion of .. when it is 'ROOT',
3190 * it is IGIF now but needs FID in dir entry as well for readdir
3192 * LU-838 should fix that and remove fid_is_igif() check */
3193 if (fid_is_igif((struct lu_fid *)fid) ||
3194 fid_is_norm((struct lu_fid *)fid)) {
3195 ldp = (struct ldiskfs_dentry_param *)info->oti_ldp;
3196 osd_get_ldiskfs_dirent_param(ldp, fid);
3197 child->d_fsdata = (void *)ldp;
3199 child->d_fsdata = NULL;
3201 LASSERT(pobj->oo_inode);
3202 ll_vfs_dq_init(pobj->oo_inode);
3203 rc = osd_ldiskfs_add_entry(oth->ot_handle, child, cinode, hlock);
3209 * Calls ldiskfs_add_dot_dotdot() to add dot and dotdot entries
3210 * into the directory.Also sets flags into osd object to
3211 * indicate dot and dotdot are created. This is required for
3212 * interoperability mode (b11826)
3214 * \param dir directory for dot and dotdot fixup.
3215 * \param obj child object for linking
3217 * \retval 0, on success
3218 * \retval -ve, on error
3220 static int osd_add_dot_dotdot(struct osd_thread_info *info,
3221 struct osd_object *dir,
3222 struct inode *parent_dir, const char *name,
3223 const struct dt_rec *dot_fid,
3224 const struct dt_rec *dot_dot_fid,
3227 struct inode *inode = dir->oo_inode;
3228 struct ldiskfs_dentry_param *dot_ldp;
3229 struct ldiskfs_dentry_param *dot_dot_ldp;
3230 struct osd_thandle *oth;
3233 oth = container_of(th, struct osd_thandle, ot_super);
3234 LASSERT(oth->ot_handle->h_transaction != NULL);
3235 LASSERT(S_ISDIR(dir->oo_inode->i_mode));
3237 if (strcmp(name, dot) == 0) {
3238 if (dir->oo_compat_dot_created) {
3241 LASSERT(inode == parent_dir);
3242 dir->oo_compat_dot_created = 1;
3245 } else if(strcmp(name, dotdot) == 0) {
3246 dot_ldp = (struct ldiskfs_dentry_param *)info->oti_ldp;
3247 dot_dot_ldp = (struct ldiskfs_dentry_param *)info->oti_ldp2;
3249 if (!dir->oo_compat_dot_created)
3251 if (!fid_is_igif((struct lu_fid *)dot_fid)) {
3252 osd_get_ldiskfs_dirent_param(dot_ldp, dot_fid);
3253 osd_get_ldiskfs_dirent_param(dot_dot_ldp, dot_dot_fid);
3258 /* in case of rename, dotdot is already created */
3259 if (dir->oo_compat_dotdot_created) {
3260 return __osd_ea_add_rec(info, dir, parent_dir, name,
3261 dot_dot_fid, NULL, th);
3264 result = ldiskfs_add_dot_dotdot(oth->ot_handle, parent_dir,
3265 inode, dot_ldp, dot_dot_ldp);
3267 dir->oo_compat_dotdot_created = 1;
3275 * It will call the appropriate osd_add* function and return the
3276 * value, return by respective functions.
3278 static int osd_ea_add_rec(const struct lu_env *env, struct osd_object *pobj,
3279 struct inode *cinode, const char *name,
3280 const struct dt_rec *fid, struct thandle *th)
3282 struct osd_thread_info *info = osd_oti_get(env);
3283 struct htree_lock *hlock;
3286 hlock = pobj->oo_hl_head != NULL ? info->oti_hlock : NULL;
3288 if (name[0] == '.' && (name[1] == '\0' || (name[1] == '.' &&
3290 if (hlock != NULL) {
3291 ldiskfs_htree_lock(hlock, pobj->oo_hl_head,
3294 cfs_down_write(&pobj->oo_ext_idx_sem);
3296 rc = osd_add_dot_dotdot(info, pobj, cinode, name,
3297 (struct dt_rec *)lu_object_fid(&pobj->oo_dt.do_lu),
3300 if (hlock != NULL) {
3301 ldiskfs_htree_lock(hlock, pobj->oo_hl_head,
3302 pobj->oo_inode, LDISKFS_HLOCK_ADD);
3304 cfs_down_write(&pobj->oo_ext_idx_sem);
3307 rc = __osd_ea_add_rec(info, pobj, cinode, name, fid,
3311 ldiskfs_htree_unlock(hlock);
3313 cfs_up_write(&pobj->oo_ext_idx_sem);
3319 osd_consistency_check(struct osd_thread_info *oti, struct osd_device *dev,
3320 struct osd_idmap_cache *oic)
3322 struct osd_scrub *scrub = &dev->od_scrub;
3323 struct lu_fid *fid = &oic->oic_fid;
3324 struct osd_inode_id *id = &oti->oti_id;
3329 if (!fid_is_norm(fid) && !fid_is_igif(fid))
3333 rc = osd_oi_lookup(oti, dev, fid, id);
3334 if (rc != 0 && rc != -ENOENT)
3337 if (rc == 0 && osd_id_eq(id, &oic->oic_lid))
3340 if (thread_is_running(&scrub->os_thread)) {
3341 rc = osd_oii_insert(dev, oic, rc == -ENOENT);
3342 /* There is race condition between osd_oi_lookup and OI scrub.
3343 * The OI scrub finished just after osd_oi_lookup() failure.
3344 * Under such case, it is unnecessary to trigger OI scrub again,
3345 * but try to call osd_oi_lookup() again. */
3346 if (unlikely(rc == -EAGAIN))
3352 if (!dev->od_noscrub && ++once == 1) {
3353 CDEBUG(D_LFSCK, "Trigger OI scrub by RPC for "DFID"\n",
3355 rc = osd_scrub_start(dev);
3356 LCONSOLE_ERROR("%.16s: trigger OI scrub by RPC for "DFID
3358 LDISKFS_SB(osd_sb(dev))->s_es->s_volume_name,
3368 * Calls ->lookup() to find dentry. From dentry get inode and
3369 * read inode's ea to get fid. This is required for interoperability
3372 * \retval 0, on success
3373 * \retval -ve, on error
3375 static int osd_ea_lookup_rec(const struct lu_env *env, struct osd_object *obj,
3376 struct dt_rec *rec, const struct dt_key *key)
3378 struct inode *dir = obj->oo_inode;
3379 struct dentry *dentry;
3380 struct ldiskfs_dir_entry_2 *de;
3381 struct buffer_head *bh;
3382 struct lu_fid *fid = (struct lu_fid *) rec;
3383 struct htree_lock *hlock = NULL;
3387 LASSERT(dir->i_op != NULL && dir->i_op->lookup != NULL);
3389 dentry = osd_child_dentry_get(env, obj,
3390 (char *)key, strlen((char *)key));
3392 if (obj->oo_hl_head != NULL) {
3393 hlock = osd_oti_get(env)->oti_hlock;
3394 ldiskfs_htree_lock(hlock, obj->oo_hl_head,
3395 dir, LDISKFS_HLOCK_LOOKUP);
3397 cfs_down_read(&obj->oo_ext_idx_sem);
3400 bh = osd_ldiskfs_find_entry(dir, dentry, &de, hlock);
3402 struct osd_thread_info *oti = osd_oti_get(env);
3403 struct osd_idmap_cache *oic = &oti->oti_cache;
3404 struct osd_device *dev = osd_obj2dev(obj);
3405 struct osd_scrub *scrub = &dev->od_scrub;
3406 struct scrub_file *sf = &scrub->os_file;
3408 ino = le32_to_cpu(de->inode);
3409 rc = osd_get_fid_from_dentry(de, rec);
3411 /* done with de, release bh */
3414 rc = osd_ea_fid_get(env, obj, ino, fid, &oic->oic_lid);
3416 osd_id_gen(&oic->oic_lid, ino, OSD_OII_NOGEN);
3418 fid_zero(&oic->oic_fid);
3422 oic->oic_fid = *fid;
3423 if ((scrub->os_pos_current <= ino) &&
3424 (sf->sf_flags & SF_INCONSISTENT ||
3425 ldiskfs_test_bit(osd_oi_fid2idx(dev, fid),
3427 osd_consistency_check(oti, dev, oic);
3436 ldiskfs_htree_unlock(hlock);
3438 cfs_up_read(&obj->oo_ext_idx_sem);
3443 * Find the osd object for given fid.
3445 * \param fid need to find the osd object having this fid
3447 * \retval osd_object on success
3448 * \retval -ve on error
3450 struct osd_object *osd_object_find(const struct lu_env *env,
3451 struct dt_object *dt,
3452 const struct lu_fid *fid)
3454 struct lu_device *ludev = dt->do_lu.lo_dev;
3455 struct osd_object *child = NULL;
3456 struct lu_object *luch;
3457 struct lu_object *lo;
3460 * at this point topdev might not exist yet
3461 * (i.e. MGS is preparing profiles). so we can
3462 * not rely on topdev and instead lookup with
3463 * our device passed as topdev. this can't work
3464 * if the object isn't cached yet (as osd doesn't
3465 * allocate lu_header). IOW, the object must be
3466 * in the cache, otherwise lu_object_alloc() crashes
3469 luch = lu_object_find_at(env, ludev, fid, NULL);
3470 if (!IS_ERR(luch)) {
3471 if (lu_object_exists(luch)) {
3472 lo = lu_object_locate(luch->lo_header, ludev->ld_type);
3474 child = osd_obj(lo);
3476 LU_OBJECT_DEBUG(D_ERROR, env, luch,
3477 "lu_object can't be located"
3478 DFID"\n", PFID(fid));
3480 if (child == NULL) {
3481 lu_object_put(env, luch);
3482 CERROR("Unable to get osd_object\n");
3483 child = ERR_PTR(-ENOENT);
3486 LU_OBJECT_DEBUG(D_ERROR, env, luch,
3487 "lu_object does not exists "DFID"\n",
3489 lu_object_put(env, luch);
3490 child = ERR_PTR(-ENOENT);
3493 child = (void *)luch;
3499 * Put the osd object once done with it.
3501 * \param obj osd object that needs to be put
3503 static inline void osd_object_put(const struct lu_env *env,
3504 struct osd_object *obj)
3506 lu_object_put(env, &obj->oo_dt.do_lu);
3509 static int osd_index_declare_ea_insert(const struct lu_env *env,
3510 struct dt_object *dt,
3511 const struct dt_rec *rec,
3512 const struct dt_key *key,
3513 struct thandle *handle)
3515 struct osd_thandle *oh;
3516 struct inode *inode;
3520 LASSERT(dt_object_exists(dt));
3521 LASSERT(handle != NULL);
3523 oh = container_of0(handle, struct osd_thandle, ot_super);
3524 LASSERT(oh->ot_handle == NULL);
3526 OSD_DECLARE_OP(oh, insert, osd_dto_credits_noquota[DTO_INDEX_INSERT]);
3528 inode = osd_dt_obj(dt)->oo_inode;
3531 /* We ignore block quota on meta pool (MDTs), so needn't
3532 * calculate how many blocks will be consumed by this index
3534 rc = osd_declare_inode_qid(env, inode->i_uid, inode->i_gid, 0, oh,
3535 true, true, NULL, false);
3540 * Index add function for interoperability mode (b11826).
3541 * It will add the directory entry.This entry is needed to
3542 * maintain name->fid mapping.
3544 * \param key it is key i.e. file entry to be inserted
3545 * \param rec it is value of given key i.e. fid
3547 * \retval 0, on success
3548 * \retval -ve, on error
3550 static int osd_index_ea_insert(const struct lu_env *env, struct dt_object *dt,
3551 const struct dt_rec *rec,
3552 const struct dt_key *key, struct thandle *th,
3553 struct lustre_capa *capa, int ignore_quota)
3555 struct osd_object *obj = osd_dt_obj(dt);
3556 struct lu_fid *fid = (struct lu_fid *) rec;
3557 const char *name = (const char *)key;
3558 struct osd_object *child;
3563 LASSERT(osd_invariant(obj));
3564 LASSERT(dt_object_exists(dt));
3565 LASSERT(th != NULL);
3567 if (osd_object_auth(env, dt, capa, CAPA_OPC_INDEX_INSERT))
3570 child = osd_object_find(env, dt, fid);
3571 if (!IS_ERR(child)) {
3572 rc = osd_ea_add_rec(env, obj, child->oo_inode, name, rec, th);
3573 osd_object_put(env, child);
3575 rc = PTR_ERR(child);
3578 LASSERT(osd_invariant(obj));
3583 * Initialize osd Iterator for given osd index object.
3585 * \param dt osd index object
3588 static struct dt_it *osd_it_iam_init(const struct lu_env *env,
3589 struct dt_object *dt,
3591 struct lustre_capa *capa)
3593 struct osd_it_iam *it;
3594 struct osd_thread_info *oti = osd_oti_get(env);
3595 struct osd_object *obj = osd_dt_obj(dt);
3596 struct lu_object *lo = &dt->do_lu;
3597 struct iam_path_descr *ipd;
3598 struct iam_container *bag = &obj->oo_dir->od_container;
3600 LASSERT(lu_object_exists(lo));
3602 if (osd_object_auth(env, dt, capa, CAPA_OPC_BODY_READ))
3603 return ERR_PTR(-EACCES);
3606 ipd = osd_it_ipd_get(env, bag);
3607 if (likely(ipd != NULL)) {
3611 iam_it_init(&it->oi_it, bag, IAM_IT_MOVE, ipd);
3612 return (struct dt_it *)it;
3614 return ERR_PTR(-ENOMEM);
3618 * free given Iterator.
3621 static void osd_it_iam_fini(const struct lu_env *env, struct dt_it *di)
3623 struct osd_it_iam *it = (struct osd_it_iam *)di;
3624 struct osd_object *obj = it->oi_obj;
3626 iam_it_fini(&it->oi_it);
3627 osd_ipd_put(env, &obj->oo_dir->od_container, it->oi_ipd);
3628 lu_object_put(env, &obj->oo_dt.do_lu);
3632 * Move Iterator to record specified by \a key
3634 * \param di osd iterator
3635 * \param key key for index
3637 * \retval +ve di points to record with least key not larger than key
3638 * \retval 0 di points to exact matched key
3639 * \retval -ve failure
3642 static int osd_it_iam_get(const struct lu_env *env,
3643 struct dt_it *di, const struct dt_key *key)
3645 struct osd_thread_info *oti = osd_oti_get(env);
3646 struct osd_it_iam *it = (struct osd_it_iam *)di;
3648 if (fid_is_quota(lu_object_fid(&it->oi_obj->oo_dt.do_lu))) {
3649 /* swab quota uid/gid */
3650 oti->oti_quota_id = cpu_to_le64(*((__u64 *)key));
3651 key = (struct dt_key *)&oti->oti_quota_id;
3654 return iam_it_get(&it->oi_it, (const struct iam_key *)key);
3660 * \param di osd iterator
3663 static void osd_it_iam_put(const struct lu_env *env, struct dt_it *di)
3665 struct osd_it_iam *it = (struct osd_it_iam *)di;
3667 iam_it_put(&it->oi_it);
3671 * Move iterator by one record
3673 * \param di osd iterator
3675 * \retval +1 end of container reached
3677 * \retval -ve failure
3680 static int osd_it_iam_next(const struct lu_env *env, struct dt_it *di)
3682 struct osd_it_iam *it = (struct osd_it_iam *)di;
3684 return iam_it_next(&it->oi_it);
3688 * Return pointer to the key under iterator.
3691 static struct dt_key *osd_it_iam_key(const struct lu_env *env,
3692 const struct dt_it *di)
3694 struct osd_thread_info *oti = osd_oti_get(env);
3695 struct osd_it_iam *it = (struct osd_it_iam *)di;
3696 struct osd_object *obj = it->oi_obj;
3699 key = (struct dt_key *)iam_it_key_get(&it->oi_it);
3701 if (!IS_ERR(key) && fid_is_quota(lu_object_fid(&obj->oo_dt.do_lu))) {
3702 /* swab quota uid/gid */
3703 oti->oti_quota_id = le64_to_cpu(*((__u64 *)key));
3704 key = (struct dt_key *)&oti->oti_quota_id;
3711 * Return size of key under iterator (in bytes)
3714 static int osd_it_iam_key_size(const struct lu_env *env, const struct dt_it *di)
3716 struct osd_it_iam *it = (struct osd_it_iam *)di;
3718 return iam_it_key_size(&it->oi_it);
3721 static inline void osd_it_append_attrs(struct lu_dirent *ent, __u32 attr,
3722 int len, __u16 type)
3724 struct luda_type *lt;
3725 const unsigned align = sizeof(struct luda_type) - 1;
3727 /* check if file type is required */
3728 if (attr & LUDA_TYPE) {
3729 len = (len + align) & ~align;
3731 lt = (void *) ent->lde_name + len;
3732 lt->lt_type = cpu_to_le16(CFS_DTTOIF(type));
3733 ent->lde_attrs |= LUDA_TYPE;
3736 ent->lde_attrs = cpu_to_le32(ent->lde_attrs);
3740 * build lu direct from backend fs dirent.
3743 static inline void osd_it_pack_dirent(struct lu_dirent *ent,
3744 struct lu_fid *fid, __u64 offset,
3745 char *name, __u16 namelen,
3746 __u16 type, __u32 attr)
3748 fid_cpu_to_le(&ent->lde_fid, fid);
3749 ent->lde_attrs = LUDA_FID;
3751 ent->lde_hash = cpu_to_le64(offset);
3752 ent->lde_reclen = cpu_to_le16(lu_dirent_calc_size(namelen, attr));
3754 strncpy(ent->lde_name, name, namelen);
3755 ent->lde_namelen = cpu_to_le16(namelen);
3757 /* append lustre attributes */
3758 osd_it_append_attrs(ent, attr, namelen, type);
3762 * Return pointer to the record under iterator.
3764 static int osd_it_iam_rec(const struct lu_env *env,
3765 const struct dt_it *di,
3766 struct dt_rec *dtrec, __u32 attr)
3768 struct osd_it_iam *it = (struct osd_it_iam *)di;
3769 struct osd_thread_info *info = osd_oti_get(env);
3772 if (S_ISDIR(it->oi_obj->oo_inode->i_mode)) {
3773 const struct osd_fid_pack *rec;
3774 struct lu_fid *fid = &info->oti_fid;
3775 struct lu_dirent *lde = (struct lu_dirent *)dtrec;
3781 name = (char *)iam_it_key_get(&it->oi_it);
3783 RETURN(PTR_ERR(name));
3785 namelen = iam_it_key_size(&it->oi_it);
3787 rec = (const struct osd_fid_pack *)iam_it_rec_get(&it->oi_it);
3789 RETURN(PTR_ERR(rec));
3791 rc = osd_fid_unpack(fid, rec);
3795 hash = iam_it_store(&it->oi_it);
3797 /* IAM does not store object type in IAM index (dir) */
3798 osd_it_pack_dirent(lde, fid, hash, name, namelen,
3800 } else if (fid_is_quota(lu_object_fid(&it->oi_obj->oo_dt.do_lu))) {
3801 iam_reccpy(&it->oi_it.ii_path.ip_leaf,
3802 (struct iam_rec *)dtrec);
3803 osd_quota_unpack(it->oi_obj, dtrec);
3805 iam_reccpy(&it->oi_it.ii_path.ip_leaf,
3806 (struct iam_rec *)dtrec);
3813 * Returns cookie for current Iterator position.
3815 static __u64 osd_it_iam_store(const struct lu_env *env, const struct dt_it *di)
3817 struct osd_it_iam *it = (struct osd_it_iam *)di;
3819 return iam_it_store(&it->oi_it);
3823 * Restore iterator from cookie.
3825 * \param di osd iterator
3826 * \param hash Iterator location cookie
3828 * \retval +ve di points to record with least key not larger than key.
3829 * \retval 0 di points to exact matched key
3830 * \retval -ve failure
3833 static int osd_it_iam_load(const struct lu_env *env,
3834 const struct dt_it *di, __u64 hash)
3836 struct osd_it_iam *it = (struct osd_it_iam *)di;
3838 return iam_it_load(&it->oi_it, hash);
3841 static const struct dt_index_operations osd_index_iam_ops = {
3842 .dio_lookup = osd_index_iam_lookup,
3843 .dio_declare_insert = osd_index_declare_iam_insert,
3844 .dio_insert = osd_index_iam_insert,
3845 .dio_declare_delete = osd_index_declare_iam_delete,
3846 .dio_delete = osd_index_iam_delete,
3848 .init = osd_it_iam_init,
3849 .fini = osd_it_iam_fini,
3850 .get = osd_it_iam_get,
3851 .put = osd_it_iam_put,
3852 .next = osd_it_iam_next,
3853 .key = osd_it_iam_key,
3854 .key_size = osd_it_iam_key_size,
3855 .rec = osd_it_iam_rec,
3856 .store = osd_it_iam_store,
3857 .load = osd_it_iam_load
3863 * Creates or initializes iterator context.
3865 * \retval struct osd_it_ea, iterator structure on success
3868 static struct dt_it *osd_it_ea_init(const struct lu_env *env,
3869 struct dt_object *dt,
3871 struct lustre_capa *capa)
3873 struct osd_object *obj = osd_dt_obj(dt);
3874 struct osd_thread_info *info = osd_oti_get(env);
3875 struct osd_it_ea *it = &info->oti_it_ea;
3876 struct lu_object *lo = &dt->do_lu;
3877 struct dentry *obj_dentry = &info->oti_it_dentry;
3879 LASSERT(lu_object_exists(lo));
3881 obj_dentry->d_inode = obj->oo_inode;
3882 obj_dentry->d_sb = osd_sb(osd_obj2dev(obj));
3883 obj_dentry->d_name.hash = 0;
3885 it->oie_rd_dirent = 0;
3886 it->oie_it_dirent = 0;
3887 it->oie_dirent = NULL;
3888 it->oie_buf = info->oti_it_ea_buf;
3890 it->oie_file.f_pos = 0;
3891 it->oie_file.f_dentry = obj_dentry;
3892 if (attr & LUDA_64BITHASH)
3893 it->oie_file.f_mode |= FMODE_64BITHASH;
3895 it->oie_file.f_mode |= FMODE_32BITHASH;
3896 it->oie_file.f_mapping = obj->oo_inode->i_mapping;
3897 it->oie_file.f_op = obj->oo_inode->i_fop;
3898 it->oie_file.private_data = NULL;
3900 RETURN((struct dt_it *) it);
3904 * Destroy or finishes iterator context.
3906 * \param di iterator structure to be destroyed
3908 static void osd_it_ea_fini(const struct lu_env *env, struct dt_it *di)
3910 struct osd_it_ea *it = (struct osd_it_ea *)di;
3911 struct osd_object *obj = it->oie_obj;
3912 struct inode *inode = obj->oo_inode;
3915 it->oie_file.f_op->release(inode, &it->oie_file);
3916 lu_object_put(env, &obj->oo_dt.do_lu);
3921 * It position the iterator at given key, so that next lookup continues from
3922 * that key Or it is similar to dio_it->load() but based on a key,
3923 * rather than file position.
3925 * As a special convention, osd_it_ea_get(env, di, "") has to rewind iterator
3928 * TODO: Presently return +1 considering it is only used by mdd_dir_is_empty().
3930 static int osd_it_ea_get(const struct lu_env *env,
3931 struct dt_it *di, const struct dt_key *key)
3933 struct osd_it_ea *it = (struct osd_it_ea *)di;
3936 LASSERT(((const char *)key)[0] == '\0');
3937 it->oie_file.f_pos = 0;
3938 it->oie_rd_dirent = 0;
3939 it->oie_it_dirent = 0;
3940 it->oie_dirent = NULL;
3948 static void osd_it_ea_put(const struct lu_env *env, struct dt_it *di)
3953 * It is called internally by ->readdir(). It fills the
3954 * iterator's in-memory data structure with required
3955 * information i.e. name, namelen, rec_size etc.
3957 * \param buf in which information to be filled in.
3958 * \param name name of the file in given dir
3960 * \retval 0 on success
3961 * \retval 1 on buffer full
3963 static int osd_ldiskfs_filldir(char *buf, const char *name, int namelen,
3964 loff_t offset, __u64 ino,
3967 struct osd_it_ea *it = (struct osd_it_ea *)buf;
3968 struct osd_it_ea_dirent *ent = it->oie_dirent;
3969 struct lu_fid *fid = &ent->oied_fid;
3970 struct osd_fid_pack *rec;
3973 /* this should never happen */
3974 if (unlikely(namelen == 0 || namelen > LDISKFS_NAME_LEN)) {
3975 CERROR("ldiskfs return invalid namelen %d\n", namelen);
3979 if ((void *) ent - it->oie_buf + sizeof(*ent) + namelen >
3983 if (d_type & LDISKFS_DIRENT_LUFID) {
3984 rec = (struct osd_fid_pack*) (name + namelen + 1);
3986 if (osd_fid_unpack(fid, rec) != 0)
3989 d_type &= ~LDISKFS_DIRENT_LUFID;
3994 ent->oied_ino = ino;
3995 ent->oied_off = offset;
3996 ent->oied_namelen = namelen;
3997 ent->oied_type = d_type;
3999 memcpy(ent->oied_name, name, namelen);
4001 it->oie_rd_dirent++;
4002 it->oie_dirent = (void *) ent + cfs_size_round(sizeof(*ent) + namelen);
4007 * Calls ->readdir() to load a directory entry at a time
4008 * and stored it in iterator's in-memory data structure.
4010 * \param di iterator's in memory structure
4012 * \retval 0 on success
4013 * \retval -ve on error
4015 static int osd_ldiskfs_it_fill(const struct lu_env *env,
4016 const struct dt_it *di)
4018 struct osd_it_ea *it = (struct osd_it_ea *)di;
4019 struct osd_object *obj = it->oie_obj;
4020 struct inode *inode = obj->oo_inode;
4021 struct htree_lock *hlock = NULL;
4025 it->oie_dirent = it->oie_buf;
4026 it->oie_rd_dirent = 0;
4028 if (obj->oo_hl_head != NULL) {
4029 hlock = osd_oti_get(env)->oti_hlock;
4030 ldiskfs_htree_lock(hlock, obj->oo_hl_head,
4031 inode, LDISKFS_HLOCK_READDIR);
4033 cfs_down_read(&obj->oo_ext_idx_sem);
4036 result = inode->i_fop->readdir(&it->oie_file, it,
4037 (filldir_t) osd_ldiskfs_filldir);
4040 ldiskfs_htree_unlock(hlock);
4042 cfs_up_read(&obj->oo_ext_idx_sem);
4044 if (it->oie_rd_dirent == 0) {
4047 it->oie_dirent = it->oie_buf;
4048 it->oie_it_dirent = 1;
4055 * It calls osd_ldiskfs_it_fill() which will use ->readdir()
4056 * to load a directory entry at a time and stored it in
4057 * iterator's in-memory data structure.
4059 * \param di iterator's in memory structure
4061 * \retval +ve iterator reached to end
4062 * \retval 0 iterator not reached to end
4063 * \retval -ve on error
4065 static int osd_it_ea_next(const struct lu_env *env, struct dt_it *di)
4067 struct osd_it_ea *it = (struct osd_it_ea *)di;
4072 if (it->oie_it_dirent < it->oie_rd_dirent) {
4074 (void *) it->oie_dirent +
4075 cfs_size_round(sizeof(struct osd_it_ea_dirent) +
4076 it->oie_dirent->oied_namelen);
4077 it->oie_it_dirent++;
4080 if (it->oie_file.f_pos == ldiskfs_get_htree_eof(&it->oie_file))
4083 rc = osd_ldiskfs_it_fill(env, di);
4090 * Returns the key at current position from iterator's in memory structure.
4092 * \param di iterator's in memory structure
4094 * \retval key i.e. struct dt_key on success
4096 static struct dt_key *osd_it_ea_key(const struct lu_env *env,
4097 const struct dt_it *di)
4099 struct osd_it_ea *it = (struct osd_it_ea *)di;
4101 return (struct dt_key *)it->oie_dirent->oied_name;
4105 * Returns the key's size at current position from iterator's in memory structure.
4107 * \param di iterator's in memory structure
4109 * \retval key_size i.e. struct dt_key on success
4111 static int osd_it_ea_key_size(const struct lu_env *env, const struct dt_it *di)
4113 struct osd_it_ea *it = (struct osd_it_ea *)di;
4115 return it->oie_dirent->oied_namelen;
4120 * Returns the value (i.e. fid/igif) at current position from iterator's
4121 * in memory structure.
4123 * \param di struct osd_it_ea, iterator's in memory structure
4124 * \param attr attr requested for dirent.
4125 * \param lde lustre dirent
4127 * \retval 0 no error and \param lde has correct lustre dirent.
4128 * \retval -ve on error
4130 static inline int osd_it_ea_rec(const struct lu_env *env,
4131 const struct dt_it *di,
4132 struct dt_rec *dtrec, __u32 attr)
4134 struct osd_it_ea *it = (struct osd_it_ea *)di;
4135 struct osd_object *obj = it->oie_obj;
4136 struct osd_device *dev = osd_obj2dev(obj);
4137 struct osd_scrub *scrub = &dev->od_scrub;
4138 struct scrub_file *sf = &scrub->os_file;
4139 struct osd_thread_info *oti = osd_oti_get(env);
4140 struct osd_idmap_cache *oic = &oti->oti_cache;
4141 struct lu_fid *fid = &it->oie_dirent->oied_fid;
4142 struct lu_dirent *lde = (struct lu_dirent *)dtrec;
4143 __u32 ino = it->oie_dirent->oied_ino;
4147 if (!fid_is_sane(fid)) {
4148 rc = osd_ea_fid_get(env, obj, ino, fid, &oic->oic_lid);
4150 fid_zero(&oic->oic_fid);
4154 osd_id_gen(&oic->oic_lid, ino, OSD_OII_NOGEN);
4157 osd_it_pack_dirent(lde, fid, it->oie_dirent->oied_off,
4158 it->oie_dirent->oied_name,
4159 it->oie_dirent->oied_namelen,
4160 it->oie_dirent->oied_type, attr);
4161 oic->oic_fid = *fid;
4162 if ((scrub->os_pos_current <= ino) &&
4163 (sf->sf_flags & SF_INCONSISTENT ||
4164 ldiskfs_test_bit(osd_oi_fid2idx(dev, fid), sf->sf_oi_bitmap)))
4165 osd_consistency_check(oti, dev, oic);
4171 * Returns a cookie for current position of the iterator head, so that
4172 * user can use this cookie to load/start the iterator next time.
4174 * \param di iterator's in memory structure
4176 * \retval cookie for current position, on success
4178 static __u64 osd_it_ea_store(const struct lu_env *env, const struct dt_it *di)
4180 struct osd_it_ea *it = (struct osd_it_ea *)di;
4182 return it->oie_dirent->oied_off;
4186 * It calls osd_ldiskfs_it_fill() which will use ->readdir()
4187 * to load a directory entry at a time and stored it i inn,
4188 * in iterator's in-memory data structure.
4190 * \param di struct osd_it_ea, iterator's in memory structure
4192 * \retval +ve on success
4193 * \retval -ve on error
4195 static int osd_it_ea_load(const struct lu_env *env,
4196 const struct dt_it *di, __u64 hash)
4198 struct osd_it_ea *it = (struct osd_it_ea *)di;
4202 it->oie_file.f_pos = hash;
4204 rc = osd_ldiskfs_it_fill(env, di);
4212 * Index lookup function for interoperability mode (b11826).
4214 * \param key, key i.e. file name to be searched
4216 * \retval +ve, on success
4217 * \retval -ve, on error
4219 static int osd_index_ea_lookup(const struct lu_env *env, struct dt_object *dt,
4220 struct dt_rec *rec, const struct dt_key *key,
4221 struct lustre_capa *capa)
4223 struct osd_object *obj = osd_dt_obj(dt);
4228 LASSERT(S_ISDIR(obj->oo_inode->i_mode));
4229 LINVRNT(osd_invariant(obj));
4231 if (osd_object_auth(env, dt, capa, CAPA_OPC_INDEX_LOOKUP))
4234 rc = osd_ea_lookup_rec(env, obj, rec, key);
4241 * Index and Iterator operations for interoperability
4242 * mode (i.e. to run 2.0 mds on 1.8 disk) (b11826)
4244 static const struct dt_index_operations osd_index_ea_ops = {
4245 .dio_lookup = osd_index_ea_lookup,
4246 .dio_declare_insert = osd_index_declare_ea_insert,
4247 .dio_insert = osd_index_ea_insert,
4248 .dio_declare_delete = osd_index_declare_ea_delete,
4249 .dio_delete = osd_index_ea_delete,
4251 .init = osd_it_ea_init,
4252 .fini = osd_it_ea_fini,
4253 .get = osd_it_ea_get,
4254 .put = osd_it_ea_put,
4255 .next = osd_it_ea_next,
4256 .key = osd_it_ea_key,
4257 .key_size = osd_it_ea_key_size,
4258 .rec = osd_it_ea_rec,
4259 .store = osd_it_ea_store,
4260 .load = osd_it_ea_load
4264 static void *osd_key_init(const struct lu_context *ctx,
4265 struct lu_context_key *key)
4267 struct osd_thread_info *info;
4269 OBD_ALLOC_PTR(info);
4271 return ERR_PTR(-ENOMEM);
4273 OBD_ALLOC(info->oti_it_ea_buf, OSD_IT_EA_BUFSIZE);
4274 if (info->oti_it_ea_buf == NULL)
4277 info->oti_env = container_of(ctx, struct lu_env, le_ctx);
4279 info->oti_hlock = ldiskfs_htree_lock_alloc();
4280 if (info->oti_hlock == NULL)
4286 OBD_FREE(info->oti_it_ea_buf, OSD_IT_EA_BUFSIZE);
4289 return ERR_PTR(-ENOMEM);
4292 static void osd_key_fini(const struct lu_context *ctx,
4293 struct lu_context_key *key, void* data)
4295 struct osd_thread_info *info = data;
4297 if (info->oti_hlock != NULL)
4298 ldiskfs_htree_lock_free(info->oti_hlock);
4299 OBD_FREE(info->oti_it_ea_buf, OSD_IT_EA_BUFSIZE);
4303 static void osd_key_exit(const struct lu_context *ctx,
4304 struct lu_context_key *key, void *data)
4306 struct osd_thread_info *info = data;
4308 LASSERT(info->oti_r_locks == 0);
4309 LASSERT(info->oti_w_locks == 0);
4310 LASSERT(info->oti_txns == 0);
4313 /* type constructor/destructor: osd_type_init, osd_type_fini */
4314 LU_TYPE_INIT_FINI(osd, &osd_key);
4316 struct lu_context_key osd_key = {
4317 .lct_tags = LCT_DT_THREAD | LCT_MD_THREAD | LCT_MG_THREAD | LCT_LOCAL,
4318 .lct_init = osd_key_init,
4319 .lct_fini = osd_key_fini,
4320 .lct_exit = osd_key_exit
4324 static int osd_device_init(const struct lu_env *env, struct lu_device *d,
4325 const char *name, struct lu_device *next)
4327 struct osd_device *osd = osd_dev(d);
4329 strncpy(osd->od_svname, name, MAX_OBD_NAME);
4330 return osd_procfs_init(osd, name);
4333 static int osd_shutdown(const struct lu_env *env, struct osd_device *o)
4337 osd_scrub_cleanup(env, o);
4340 fsfilt_put_ops(o->od_fsops);
4344 /* shutdown quota slave instance associated with the device */
4345 if (o->od_quota_slave != NULL) {
4346 qsd_fini(env, o->od_quota_slave);
4347 o->od_quota_slave = NULL;
4353 static int osd_mount(const struct lu_env *env,
4354 struct osd_device *o, struct lustre_cfg *cfg)
4356 const char *name = lustre_cfg_string(cfg, 0);
4357 const char *dev = lustre_cfg_string(cfg, 1);
4359 unsigned long page, s_flags, lmd_flags = 0;
4360 struct page *__page;
4361 struct file_system_type *type;
4362 char *options = NULL;
4367 if (o->od_mnt != NULL)
4370 o->od_fsops = fsfilt_get_ops(mt_str(LDD_MT_LDISKFS));
4371 if (o->od_fsops == NULL) {
4372 CERROR("Can't find fsfilt_ldiskfs\n");
4376 OBD_PAGE_ALLOC(__page, CFS_ALLOC_STD);
4378 GOTO(out, rc = -ENOMEM);
4380 str = lustre_cfg_string(cfg, 2);
4381 s_flags = simple_strtoul(str, NULL, 0);
4382 str = strstr(str, ":");
4384 lmd_flags = simple_strtoul(str + 1, NULL, 0);
4385 opts = lustre_cfg_string(cfg, 3);
4386 page = (unsigned long)cfs_page_address(__page);
4387 options = (char *)page;
4390 strcat(options, "user_xattr,acl");
4392 strcat(options, opts);
4394 /* Glom up mount options */
4395 if (*options != '\0')
4396 strcat(options, ",");
4397 strlcat(options, "no_mbcache", CFS_PAGE_SIZE);
4399 type = get_fs_type("ldiskfs");
4401 CERROR("%s: cannot find ldiskfs module\n", name);
4402 GOTO(out, rc = -ENODEV);
4405 o->od_mnt = vfs_kern_mount(type, s_flags, dev, options);
4406 cfs_module_put(type->owner);
4408 if (IS_ERR(o->od_mnt)) {
4409 rc = PTR_ERR(o->od_mnt);
4410 CERROR("%s: can't mount %s: %d\n", name, dev, rc);
4415 if (lvfs_check_rdonly(o->od_mnt->mnt_sb->s_bdev)) {
4416 CERROR("%s: underlying device %s is marked as read-only. "
4417 "Setup failed\n", name, dev);
4420 GOTO(out, rc = -EROFS);
4423 if (!LDISKFS_HAS_COMPAT_FEATURE(o->od_mnt->mnt_sb,
4424 LDISKFS_FEATURE_COMPAT_HAS_JOURNAL)) {
4425 CERROR("%s: device %s is mounted w/o journal\n", name, dev);
4428 GOTO(out, rc = -EINVAL);
4431 if (lmd_flags & LMD_FLG_NOSCRUB)
4436 OBD_PAGE_FREE(__page);
4438 fsfilt_put_ops(o->od_fsops);
4443 static struct lu_device *osd_device_fini(const struct lu_env *env,
4444 struct lu_device *d)
4449 rc = osd_shutdown(env, osd_dev(d));
4451 osd_compat_fini(osd_dev(d));
4453 shrink_dcache_sb(osd_sb(osd_dev(d)));
4454 osd_sync(env, lu2dt_dev(d));
4456 rc = osd_procfs_fini(osd_dev(d));
4458 CERROR("proc fini error %d \n", rc);
4459 RETURN (ERR_PTR(rc));
4462 if (osd_dev(d)->od_mnt) {
4463 mntput(osd_dev(d)->od_mnt);
4464 osd_dev(d)->od_mnt = NULL;
4470 static int osd_device_init0(const struct lu_env *env,
4471 struct osd_device *o,
4472 struct lustre_cfg *cfg)
4474 struct lu_device *l = osd2lu_dev(o);
4475 struct osd_thread_info *info;
4478 /* if the module was re-loaded, env can loose its keys */
4479 rc = lu_env_refill((struct lu_env *) env);
4482 info = osd_oti_get(env);
4485 l->ld_ops = &osd_lu_ops;
4486 o->od_dt_dev.dd_ops = &osd_dt_ops;
4488 cfs_spin_lock_init(&o->od_osfs_lock);
4489 cfs_mutex_init(&o->od_otable_mutex);
4490 o->od_osfs_age = cfs_time_shift_64(-1000);
4492 o->od_capa_hash = init_capa_hash();
4493 if (o->od_capa_hash == NULL)
4494 GOTO(out, rc = -ENOMEM);
4496 o->od_read_cache = 1;
4497 o->od_writethrough_cache = 1;
4498 o->od_readcache_max_filesize = OSD_MAX_CACHE_SIZE;
4500 rc = osd_mount(env, o, cfg);
4504 /* setup scrub, including OI files initialization */
4505 rc = osd_scrub_setup(env, o);
4509 strncpy(o->od_svname, lustre_cfg_string(cfg, 4),
4510 sizeof(o->od_svname) - 1);
4512 rc = osd_compat_init(o);
4514 GOTO(out_scrub, rc);
4516 rc = lu_site_init(&o->od_site, l);
4518 GOTO(out_compat, rc);
4519 o->od_site.ls_bottom_dev = l;
4521 rc = lu_site_init_finish(&o->od_site);
4525 rc = osd_procfs_init(o, o->od_svname);
4527 CERROR("%s: can't initialize procfs: rc = %d\n",
4532 LASSERT(l->ld_site->ls_linkage.next && l->ld_site->ls_linkage.prev);
4534 /* initialize quota slave instance */
4535 o->od_quota_slave = qsd_init(env, o->od_svname, &o->od_dt_dev,
4537 if (IS_ERR(o->od_quota_slave)) {
4538 rc = PTR_ERR(o->od_quota_slave);
4539 o->od_quota_slave = NULL;
4540 GOTO(out_procfs, rc);
4547 lu_site_fini(&o->od_site);
4551 osd_scrub_cleanup(env, o);
4553 osd_oi_fini(info, o);
4554 osd_shutdown(env, o);
4558 cleanup_capa_hash(o->od_capa_hash);
4563 static struct lu_device *osd_device_alloc(const struct lu_env *env,
4564 struct lu_device_type *t,
4565 struct lustre_cfg *cfg)
4567 struct osd_device *o;
4572 return ERR_PTR(-ENOMEM);
4574 rc = dt_device_init(&o->od_dt_dev, t);
4576 rc = osd_device_init0(env, o, cfg);
4578 dt_device_fini(&o->od_dt_dev);
4581 if (unlikely(rc != 0))
4584 return rc == 0 ? osd2lu_dev(o) : ERR_PTR(rc);
4587 static struct lu_device *osd_device_free(const struct lu_env *env,
4588 struct lu_device *d)
4590 struct osd_device *o = osd_dev(d);
4593 cleanup_capa_hash(o->od_capa_hash);
4594 /* XXX: make osd top device in order to release reference */
4595 d->ld_site->ls_top_dev = d;
4596 lu_site_purge(env, d->ld_site, -1);
4597 if (!cfs_hash_is_empty(d->ld_site->ls_obj_hash)) {
4598 LIBCFS_DEBUG_MSG_DATA_DECL(msgdata, D_ERROR, NULL);
4599 lu_site_print(env, d->ld_site, &msgdata, lu_cdebug_printer);
4601 lu_site_fini(&o->od_site);
4602 dt_device_fini(&o->od_dt_dev);
4607 static int osd_process_config(const struct lu_env *env,
4608 struct lu_device *d, struct lustre_cfg *cfg)
4610 struct osd_device *o = osd_dev(d);
4614 switch(cfg->lcfg_command) {
4616 err = osd_mount(env, o, cfg);
4619 lu_dev_del_linkage(d->ld_site, d);
4620 err = osd_shutdown(env, o);
4629 static int osd_recovery_complete(const struct lu_env *env,
4630 struct lu_device *d)
4632 struct osd_device *osd = osd_dev(d);
4636 if (osd->od_quota_slave == NULL)
4639 /* start qsd instance on recovery completion, this notifies the quota
4640 * slave code that we are about to process new requests now */
4641 rc = qsd_start(env, osd->od_quota_slave);
4646 * we use exports to track all osd users
4648 static int osd_obd_connect(const struct lu_env *env, struct obd_export **exp,
4649 struct obd_device *obd, struct obd_uuid *cluuid,
4650 struct obd_connect_data *data, void *localdata)
4652 struct osd_device *osd = osd_dev(obd->obd_lu_dev);
4653 struct lustre_handle conn;
4657 CDEBUG(D_CONFIG, "connect #%d\n", osd->od_connects);
4659 rc = class_connect(&conn, obd, cluuid);
4663 *exp = class_conn2export(&conn);
4665 cfs_spin_lock(&osd->od_osfs_lock);
4667 cfs_spin_unlock(&osd->od_osfs_lock);
4673 * once last export (we don't count self-export) disappeared
4674 * osd can be released
4676 static int osd_obd_disconnect(struct obd_export *exp)
4678 struct obd_device *obd = exp->exp_obd;
4679 struct osd_device *osd = osd_dev(obd->obd_lu_dev);
4680 int rc, release = 0;
4683 /* Only disconnect the underlying layers on the final disconnect. */
4684 cfs_spin_lock(&osd->od_osfs_lock);
4686 if (osd->od_connects == 0)
4688 cfs_spin_unlock(&osd->od_osfs_lock);
4690 rc = class_disconnect(exp); /* bz 9811 */
4692 if (rc == 0 && release)
4693 class_manual_cleanup(obd);
4697 static int osd_prepare(const struct lu_env *env, struct lu_device *pdev,
4698 struct lu_device *dev)
4700 struct osd_device *osd = osd_dev(dev);
4704 if (dev->ld_site && lu_device_is_md(dev->ld_site->ls_top_dev)) {
4705 /* MDT/MDD still use old infrastructure to create
4707 result = llo_local_objects_setup(env, lu2md_dev(pdev),
4713 if (osd->od_quota_slave != NULL)
4714 /* set up quota slave objects */
4715 result = qsd_prepare(env, osd->od_quota_slave);
4720 static const struct lu_object_operations osd_lu_obj_ops = {
4721 .loo_object_init = osd_object_init,
4722 .loo_object_delete = osd_object_delete,
4723 .loo_object_release = osd_object_release,
4724 .loo_object_free = osd_object_free,
4725 .loo_object_print = osd_object_print,
4726 .loo_object_invariant = osd_object_invariant
4729 const struct lu_device_operations osd_lu_ops = {
4730 .ldo_object_alloc = osd_object_alloc,
4731 .ldo_process_config = osd_process_config,
4732 .ldo_recovery_complete = osd_recovery_complete,
4733 .ldo_prepare = osd_prepare,
4736 static const struct lu_device_type_operations osd_device_type_ops = {
4737 .ldto_init = osd_type_init,
4738 .ldto_fini = osd_type_fini,
4740 .ldto_start = osd_type_start,
4741 .ldto_stop = osd_type_stop,
4743 .ldto_device_alloc = osd_device_alloc,
4744 .ldto_device_free = osd_device_free,
4746 .ldto_device_init = osd_device_init,
4747 .ldto_device_fini = osd_device_fini
4750 struct lu_device_type osd_device_type = {
4751 .ldt_tags = LU_DEVICE_DT,
4752 .ldt_name = LUSTRE_OSD_LDISKFS_NAME,
4753 .ldt_ops = &osd_device_type_ops,
4754 .ldt_ctx_tags = LCT_LOCAL,
4758 * lprocfs legacy support.
4760 static struct obd_ops osd_obd_device_ops = {
4761 .o_owner = THIS_MODULE,
4762 .o_connect = osd_obd_connect,
4763 .o_disconnect = osd_obd_disconnect
4766 static int __init osd_mod_init(void)
4768 struct lprocfs_static_vars lvars;
4771 lprocfs_osd_init_vars(&lvars);
4772 return class_register_type(&osd_obd_device_ops, NULL, lvars.module_vars,
4773 LUSTRE_OSD_LDISKFS_NAME, &osd_device_type);
4776 static void __exit osd_mod_exit(void)
4778 class_unregister_type(LUSTRE_OSD_LDISKFS_NAME);
4781 MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");
4782 MODULE_DESCRIPTION("Lustre Object Storage Device ("LUSTRE_OSD_LDISKFS_NAME")");
4783 MODULE_LICENSE("GPL");
4785 cfs_module(osd, "0.1.0", osd_mod_init, osd_mod_exit);