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_adjust_quota(env, qsd, &qi->lqi_id, USRQUOTA);
870 qi->lqi_id.qid_uid = gid;
871 qsd_adjust_quota(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 inode->i_nlink = 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,
1883 /* we drop umask so that permissions we pass are not affected */
1884 umask = current->fs->umask;
1885 current->fs->umask = 0;
1887 result = osd_create_type_f(dof->dof_type)(info, obj, attr, hint, dof,
1890 osd_attr_init(info, obj, attr, dof);
1891 osd_object_init0(obj);
1893 if (obj->oo_inode && (obj->oo_inode->i_state & I_NEW))
1894 unlock_new_inode(obj->oo_inode);
1897 /* restore previous umask value */
1898 current->fs->umask = umask;
1904 * Helper function for osd_object_create()
1906 * \retval 0, on success
1908 static int __osd_oi_insert(const struct lu_env *env, struct osd_object *obj,
1909 const struct lu_fid *fid, struct thandle *th)
1911 struct osd_thread_info *info = osd_oti_get(env);
1912 struct osd_inode_id *id = &info->oti_id;
1913 struct osd_device *osd = osd_obj2dev(obj);
1915 LASSERT(obj->oo_inode != NULL);
1917 osd_id_gen(id, obj->oo_inode->i_ino, obj->oo_inode->i_generation);
1918 return osd_oi_insert(info, osd, fid, id, th);
1921 static int osd_declare_object_create(const struct lu_env *env,
1922 struct dt_object *dt,
1923 struct lu_attr *attr,
1924 struct dt_allocation_hint *hint,
1925 struct dt_object_format *dof,
1926 struct thandle *handle)
1928 struct osd_thandle *oh;
1932 LASSERT(handle != NULL);
1934 oh = container_of0(handle, struct osd_thandle, ot_super);
1935 LASSERT(oh->ot_handle == NULL);
1937 OSD_DECLARE_OP(oh, create, osd_dto_credits_noquota[DTO_OBJECT_CREATE]);
1938 /* XXX: So far, only normal fid needs be inserted into the oi,
1939 * things could be changed later. Revise following code then. */
1940 if (fid_is_norm(lu_object_fid(&dt->do_lu))) {
1941 /* Reuse idle OI block may cause additional one OI block
1943 OSD_DECLARE_OP(oh, insert,
1944 osd_dto_credits_noquota[DTO_INDEX_INSERT] + 1);
1946 /* If this is directory, then we expect . and .. to be inserted as
1947 * well. The one directory block always needs to be created for the
1948 * directory, so we could use DTO_WRITE_BASE here (GDT, block bitmap,
1949 * block), there is no danger of needing a tree for the first block.
1951 if (attr && S_ISDIR(attr->la_mode)) {
1952 OSD_DECLARE_OP(oh, insert,
1953 osd_dto_credits_noquota[DTO_WRITE_BASE]);
1954 OSD_DECLARE_OP(oh, insert, 0);
1960 rc = osd_declare_inode_qid(env, attr->la_uid, attr->la_gid, 1, oh,
1961 false, false, NULL, false);
1965 static int osd_object_create(const struct lu_env *env, struct dt_object *dt,
1966 struct lu_attr *attr,
1967 struct dt_allocation_hint *hint,
1968 struct dt_object_format *dof,
1971 const struct lu_fid *fid = lu_object_fid(&dt->do_lu);
1972 struct osd_object *obj = osd_dt_obj(dt);
1973 struct osd_thread_info *info = osd_oti_get(env);
1978 LINVRNT(osd_invariant(obj));
1979 LASSERT(!dt_object_exists(dt));
1980 LASSERT(osd_write_locked(env, obj));
1981 LASSERT(th != NULL);
1983 if (unlikely(fid_is_acct(fid)))
1984 /* Quota files can't be created from the kernel any more,
1985 * 'tune2fs -O quota' will take care of creating them */
1988 OSD_EXEC_OP(th, create);
1990 result = __osd_object_create(info, obj, attr, hint, dof, th);
1992 result = __osd_oi_insert(env, obj, fid, th);
1994 LASSERT(ergo(result == 0, dt_object_exists(dt)));
1995 LASSERT(osd_invariant(obj));
2000 * Called to destroy on-disk representation of the object
2002 * Concurrency: must be locked
2004 static int osd_declare_object_destroy(const struct lu_env *env,
2005 struct dt_object *dt,
2008 struct osd_object *obj = osd_dt_obj(dt);
2009 struct inode *inode = obj->oo_inode;
2010 struct osd_thandle *oh;
2014 oh = container_of0(th, struct osd_thandle, ot_super);
2015 LASSERT(oh->ot_handle == NULL);
2018 OSD_DECLARE_OP(oh, delete, osd_dto_credits_noquota[DTO_OBJECT_DELETE]);
2019 /* XXX: So far, only normal fid needs to be inserted into the OI,
2020 * so only normal fid needs to be removed from the OI also.
2021 * Recycle idle OI leaf may cause additional three OI blocks
2023 OSD_DECLARE_OP(oh, destroy, fid_is_norm(lu_object_fid(&dt->do_lu)) ?
2024 osd_dto_credits_noquota[DTO_INDEX_DELETE] + 3 : 0);
2026 /* one less inode */
2027 rc = osd_declare_inode_qid(env, inode->i_uid, inode->i_gid, -1, oh,
2028 false, true, NULL, false);
2031 /* data to be truncated */
2032 rc = osd_declare_inode_qid(env, inode->i_uid, inode->i_gid, 0, oh,
2033 true, true, NULL, false);
2037 static int osd_object_destroy(const struct lu_env *env,
2038 struct dt_object *dt,
2041 const struct lu_fid *fid = lu_object_fid(&dt->do_lu);
2042 struct osd_object *obj = osd_dt_obj(dt);
2043 struct inode *inode = obj->oo_inode;
2044 struct osd_device *osd = osd_obj2dev(obj);
2045 struct osd_thandle *oh;
2049 oh = container_of0(th, struct osd_thandle, ot_super);
2050 LASSERT(oh->ot_handle);
2052 LASSERT(!lu_object_is_dying(dt->do_lu.lo_header));
2054 if (unlikely(fid_is_acct(fid)))
2057 /* Parallel control for OI scrub. For most of cases, there is no
2058 * lock contention. So it will not affect unlink performance. */
2059 cfs_mutex_lock(&inode->i_mutex);
2060 if (S_ISDIR(inode->i_mode)) {
2061 LASSERT(osd_inode_unlinked(inode) ||
2062 inode->i_nlink == 1);
2063 cfs_spin_lock(&obj->oo_guard);
2065 cfs_spin_unlock(&obj->oo_guard);
2066 inode->i_sb->s_op->dirty_inode(inode);
2068 LASSERT(osd_inode_unlinked(inode));
2071 OSD_EXEC_OP(th, destroy);
2073 result = osd_oi_delete(osd_oti_get(env), osd, fid, th);
2074 cfs_mutex_unlock(&inode->i_mutex);
2076 /* XXX: add to ext3 orphan list */
2077 /* rc = ext3_orphan_add(handle_t *handle, struct inode *inode) */
2079 /* not needed in the cache anymore */
2080 set_bit(LU_OBJECT_HEARD_BANSHEE, &dt->do_lu.lo_header->loh_flags);
2086 * Helper function for osd_xattr_set()
2088 static int __osd_xattr_set(const struct lu_env *env, struct dt_object *dt,
2089 const struct lu_buf *buf, const char *name, int fl)
2091 struct osd_object *obj = osd_dt_obj(dt);
2092 struct inode *inode = obj->oo_inode;
2093 struct osd_thread_info *info = osd_oti_get(env);
2094 struct dentry *dentry = &info->oti_child_dentry;
2098 LASSERT(dt_object_exists(dt));
2099 LASSERT(inode->i_op != NULL && inode->i_op->setxattr != NULL);
2101 if (fl & LU_XATTR_REPLACE)
2102 fs_flags |= XATTR_REPLACE;
2104 if (fl & LU_XATTR_CREATE)
2105 fs_flags |= XATTR_CREATE;
2107 ll_vfs_dq_init(inode);
2108 dentry->d_inode = inode;
2109 rc = inode->i_op->setxattr(dentry, name, buf->lb_buf,
2110 buf->lb_len, fs_flags);
2115 * Put the fid into lustre_mdt_attrs, and then place the structure
2116 * inode's ea. This fid should not be altered during the life time
2119 * \retval +ve, on success
2120 * \retval -ve, on error
2122 * FIXME: It is good to have/use ldiskfs_xattr_set_handle() here
2124 static int osd_ea_fid_set(const struct lu_env *env, struct dt_object *dt,
2125 const struct lu_fid *fid)
2127 struct osd_thread_info *info = osd_oti_get(env);
2128 struct lustre_mdt_attrs *mdt_attrs = &info->oti_mdt_attrs;
2130 lustre_lma_init(mdt_attrs, fid);
2131 lustre_lma_swab(mdt_attrs);
2132 return __osd_xattr_set(env, dt,
2133 osd_buf_get(env, mdt_attrs, sizeof *mdt_attrs),
2134 XATTR_NAME_LMA, LU_XATTR_CREATE);
2139 * ldiskfs supports fid in dirent, it is passed in dentry->d_fsdata.
2140 * lustre 1.8 also uses d_fsdata for passing other info to ldiskfs.
2141 * To have compatilibility with 1.8 ldiskfs driver we need to have
2142 * magic number at start of fid data.
2143 * \ldiskfs_dentry_param is used only to pass fid from osd to ldiskfs.
2146 void osd_get_ldiskfs_dirent_param(struct ldiskfs_dentry_param *param,
2147 const struct dt_rec *fid)
2149 param->edp_magic = LDISKFS_LUFID_MAGIC;
2150 param->edp_len = sizeof(struct lu_fid) + 1;
2152 fid_cpu_to_be((struct lu_fid *)param->edp_data,
2153 (struct lu_fid *)fid);
2157 * Try to read the fid from inode ea into dt_rec, if return value
2158 * i.e. rc is +ve, then we got fid, otherwise we will have to form igif
2160 * \param fid object fid.
2162 * \retval 0 on success
2164 static int osd_ea_fid_get(const struct lu_env *env, struct osd_object *obj,
2165 __u32 ino, struct lu_fid *fid,
2166 struct osd_inode_id *id)
2168 struct osd_thread_info *info = osd_oti_get(env);
2169 struct inode *inode;
2172 osd_id_gen(id, ino, OSD_OII_NOGEN);
2173 inode = osd_iget_fid(info, osd_obj2dev(obj), id, fid);
2175 RETURN(PTR_ERR(inode));
2182 * OSD layer object create function for interoperability mode (b11826).
2183 * This is mostly similar to osd_object_create(). Only difference being, fid is
2184 * inserted into inode ea here.
2186 * \retval 0, on success
2187 * \retval -ve, on error
2189 static int osd_object_ea_create(const struct lu_env *env, struct dt_object *dt,
2190 struct lu_attr *attr,
2191 struct dt_allocation_hint *hint,
2192 struct dt_object_format *dof,
2195 const struct lu_fid *fid = lu_object_fid(&dt->do_lu);
2196 struct osd_object *obj = osd_dt_obj(dt);
2197 struct osd_thread_info *info = osd_oti_get(env);
2202 LASSERT(osd_invariant(obj));
2203 LASSERT(!dt_object_exists(dt));
2204 LASSERT(osd_write_locked(env, obj));
2205 LASSERT(th != NULL);
2207 if (unlikely(fid_is_acct(fid)))
2208 /* Quota files can't be created from the kernel any more,
2209 * 'tune2fs -O quota' will take care of creating them */
2212 OSD_EXEC_OP(th, create);
2214 result = __osd_object_create(info, obj, attr, hint, dof, th);
2215 /* objects under osd root shld have igif fid, so dont add fid EA */
2216 if (result == 0 && fid_seq(fid) >= FID_SEQ_NORMAL)
2217 result = osd_ea_fid_set(env, dt, fid);
2220 result = __osd_oi_insert(env, obj, fid, th);
2222 LASSERT(ergo(result == 0, dt_object_exists(dt)));
2223 LINVRNT(osd_invariant(obj));
2227 static int osd_declare_object_ref_add(const struct lu_env *env,
2228 struct dt_object *dt,
2229 struct thandle *handle)
2231 struct osd_thandle *oh;
2233 /* it's possible that object doesn't exist yet */
2234 LASSERT(handle != NULL);
2236 oh = container_of0(handle, struct osd_thandle, ot_super);
2237 LASSERT(oh->ot_handle == NULL);
2239 OSD_DECLARE_OP(oh, ref_add, osd_dto_credits_noquota[DTO_ATTR_SET_BASE]);
2245 * Concurrency: @dt is write locked.
2247 static int osd_object_ref_add(const struct lu_env *env,
2248 struct dt_object *dt, struct thandle *th)
2250 struct osd_object *obj = osd_dt_obj(dt);
2251 struct inode *inode = obj->oo_inode;
2253 LINVRNT(osd_invariant(obj));
2254 LASSERT(dt_object_exists(dt));
2255 LASSERT(osd_write_locked(env, obj));
2256 LASSERT(th != NULL);
2258 OSD_EXEC_OP(th, ref_add);
2261 * DIR_NLINK feature is set for compatibility reasons if:
2262 * 1) nlinks > LDISKFS_LINK_MAX, or
2263 * 2) nlinks == 2, since this indicates i_nlink was previously 1.
2265 * It is easier to always set this flag (rather than check and set),
2266 * since it has less overhead, and the superblock will be dirtied
2267 * at some point. Both e2fsprogs and any Lustre-supported ldiskfs
2268 * do not actually care whether this flag is set or not.
2270 cfs_spin_lock(&obj->oo_guard);
2272 if (S_ISDIR(inode->i_mode) && inode->i_nlink > 1) {
2273 if (inode->i_nlink >= LDISKFS_LINK_MAX ||
2274 inode->i_nlink == 2)
2277 LASSERT(inode->i_nlink <= LDISKFS_LINK_MAX);
2278 cfs_spin_unlock(&obj->oo_guard);
2279 inode->i_sb->s_op->dirty_inode(inode);
2280 LINVRNT(osd_invariant(obj));
2285 static int osd_declare_object_ref_del(const struct lu_env *env,
2286 struct dt_object *dt,
2287 struct thandle *handle)
2289 struct osd_thandle *oh;
2291 LASSERT(dt_object_exists(dt));
2292 LASSERT(handle != NULL);
2294 oh = container_of0(handle, struct osd_thandle, ot_super);
2295 LASSERT(oh->ot_handle == NULL);
2297 OSD_DECLARE_OP(oh, ref_del, osd_dto_credits_noquota[DTO_ATTR_SET_BASE]);
2303 * Concurrency: @dt is write locked.
2305 static int osd_object_ref_del(const struct lu_env *env, struct dt_object *dt,
2308 struct osd_object *obj = osd_dt_obj(dt);
2309 struct inode *inode = obj->oo_inode;
2311 LINVRNT(osd_invariant(obj));
2312 LASSERT(dt_object_exists(dt));
2313 LASSERT(osd_write_locked(env, obj));
2314 LASSERT(th != NULL);
2316 OSD_EXEC_OP(th, ref_del);
2318 cfs_spin_lock(&obj->oo_guard);
2319 LASSERT(inode->i_nlink > 0);
2321 /* If this is/was a many-subdir directory (nlink > LDISKFS_LINK_MAX)
2322 * then the nlink count is 1. Don't let it be set to 0 or the directory
2323 * inode will be deleted incorrectly. */
2324 if (S_ISDIR(inode->i_mode) && inode->i_nlink == 0)
2326 cfs_spin_unlock(&obj->oo_guard);
2327 inode->i_sb->s_op->dirty_inode(inode);
2328 LINVRNT(osd_invariant(obj));
2334 * Get the 64-bit version for an inode.
2336 static int osd_object_version_get(const struct lu_env *env,
2337 struct dt_object *dt, dt_obj_version_t *ver)
2339 struct inode *inode = osd_dt_obj(dt)->oo_inode;
2341 CDEBUG(D_INODE, "Get version "LPX64" for inode %lu\n",
2342 LDISKFS_I(inode)->i_fs_version, inode->i_ino);
2343 *ver = LDISKFS_I(inode)->i_fs_version;
2348 * Concurrency: @dt is read locked.
2350 static int osd_xattr_get(const struct lu_env *env, struct dt_object *dt,
2351 struct lu_buf *buf, const char *name,
2352 struct lustre_capa *capa)
2354 struct osd_object *obj = osd_dt_obj(dt);
2355 struct inode *inode = obj->oo_inode;
2356 struct osd_thread_info *info = osd_oti_get(env);
2357 struct dentry *dentry = &info->oti_obj_dentry;
2359 /* version get is not real XATTR but uses xattr API */
2360 if (strcmp(name, XATTR_NAME_VERSION) == 0) {
2361 /* for version we are just using xattr API but change inode
2363 LASSERT(buf->lb_len == sizeof(dt_obj_version_t));
2364 osd_object_version_get(env, dt, buf->lb_buf);
2365 return sizeof(dt_obj_version_t);
2368 LASSERT(dt_object_exists(dt));
2369 LASSERT(inode->i_op != NULL && inode->i_op->getxattr != NULL);
2371 if (osd_object_auth(env, dt, capa, CAPA_OPC_META_READ))
2374 dentry->d_inode = inode;
2375 return inode->i_op->getxattr(dentry, name, buf->lb_buf, buf->lb_len);
2379 static int osd_declare_xattr_set(const struct lu_env *env,
2380 struct dt_object *dt,
2381 const struct lu_buf *buf, const char *name,
2382 int fl, struct thandle *handle)
2384 struct osd_thandle *oh;
2386 LASSERT(handle != NULL);
2388 oh = container_of0(handle, struct osd_thandle, ot_super);
2389 LASSERT(oh->ot_handle == NULL);
2391 OSD_DECLARE_OP(oh, xattr_set, strcmp(name, XATTR_NAME_VERSION) == 0 ?
2392 osd_dto_credits_noquota[DTO_ATTR_SET_BASE] :
2393 osd_dto_credits_noquota[DTO_XATTR_SET]);
2399 * Set the 64-bit version for object
2401 static void osd_object_version_set(const struct lu_env *env,
2402 struct dt_object *dt,
2403 dt_obj_version_t *new_version)
2405 struct inode *inode = osd_dt_obj(dt)->oo_inode;
2407 CDEBUG(D_INODE, "Set version "LPX64" (old "LPX64") for inode %lu\n",
2408 *new_version, LDISKFS_I(inode)->i_fs_version, inode->i_ino);
2410 LDISKFS_I(inode)->i_fs_version = *new_version;
2411 /** Version is set after all inode operations are finished,
2412 * so we should mark it dirty here */
2413 inode->i_sb->s_op->dirty_inode(inode);
2417 * Concurrency: @dt is write locked.
2419 static int osd_xattr_set(const struct lu_env *env, struct dt_object *dt,
2420 const struct lu_buf *buf, const char *name, int fl,
2421 struct thandle *handle, struct lustre_capa *capa)
2423 LASSERT(handle != NULL);
2425 /* version set is not real XATTR */
2426 if (strcmp(name, XATTR_NAME_VERSION) == 0) {
2427 /* for version we are just using xattr API but change inode
2429 LASSERT(buf->lb_len == sizeof(dt_obj_version_t));
2430 osd_object_version_set(env, dt, buf->lb_buf);
2431 return sizeof(dt_obj_version_t);
2434 if (osd_object_auth(env, dt, capa, CAPA_OPC_META_WRITE))
2437 OSD_EXEC_OP(handle, xattr_set);
2438 return __osd_xattr_set(env, dt, buf, name, fl);
2442 * Concurrency: @dt is read locked.
2444 static int osd_xattr_list(const struct lu_env *env, struct dt_object *dt,
2445 struct lu_buf *buf, struct lustre_capa *capa)
2447 struct osd_object *obj = osd_dt_obj(dt);
2448 struct inode *inode = obj->oo_inode;
2449 struct osd_thread_info *info = osd_oti_get(env);
2450 struct dentry *dentry = &info->oti_obj_dentry;
2452 LASSERT(dt_object_exists(dt));
2453 LASSERT(inode->i_op != NULL && inode->i_op->listxattr != NULL);
2454 LASSERT(osd_read_locked(env, obj) || osd_write_locked(env, obj));
2456 if (osd_object_auth(env, dt, capa, CAPA_OPC_META_READ))
2459 dentry->d_inode = inode;
2460 return inode->i_op->listxattr(dentry, buf->lb_buf, buf->lb_len);
2463 static int osd_declare_xattr_del(const struct lu_env *env,
2464 struct dt_object *dt, const char *name,
2465 struct thandle *handle)
2467 struct osd_thandle *oh;
2469 LASSERT(dt_object_exists(dt));
2470 LASSERT(handle != NULL);
2472 oh = container_of0(handle, struct osd_thandle, ot_super);
2473 LASSERT(oh->ot_handle == NULL);
2475 OSD_DECLARE_OP(oh, xattr_set, osd_dto_credits_noquota[DTO_XATTR_SET]);
2481 * Concurrency: @dt is write locked.
2483 static int osd_xattr_del(const struct lu_env *env, struct dt_object *dt,
2484 const char *name, struct thandle *handle,
2485 struct lustre_capa *capa)
2487 struct osd_object *obj = osd_dt_obj(dt);
2488 struct inode *inode = obj->oo_inode;
2489 struct osd_thread_info *info = osd_oti_get(env);
2490 struct dentry *dentry = &info->oti_obj_dentry;
2493 LASSERT(dt_object_exists(dt));
2494 LASSERT(inode->i_op != NULL && inode->i_op->removexattr != NULL);
2495 LASSERT(osd_write_locked(env, obj));
2496 LASSERT(handle != NULL);
2498 if (osd_object_auth(env, dt, capa, CAPA_OPC_META_WRITE))
2501 OSD_EXEC_OP(handle, xattr_set);
2503 ll_vfs_dq_init(inode);
2504 dentry->d_inode = inode;
2505 rc = inode->i_op->removexattr(dentry, name);
2509 static struct obd_capa *osd_capa_get(const struct lu_env *env,
2510 struct dt_object *dt,
2511 struct lustre_capa *old,
2514 struct osd_thread_info *info = osd_oti_get(env);
2515 const struct lu_fid *fid = lu_object_fid(&dt->do_lu);
2516 struct osd_object *obj = osd_dt_obj(dt);
2517 struct osd_device *dev = osd_obj2dev(obj);
2518 struct lustre_capa_key *key = &info->oti_capa_key;
2519 struct lustre_capa *capa = &info->oti_capa;
2520 struct obd_capa *oc;
2521 struct md_capainfo *ci;
2525 if (!dev->od_fl_capa)
2526 RETURN(ERR_PTR(-ENOENT));
2528 LASSERT(dt_object_exists(dt));
2529 LINVRNT(osd_invariant(obj));
2531 /* renewal sanity check */
2532 if (old && osd_object_auth(env, dt, old, opc))
2533 RETURN(ERR_PTR(-EACCES));
2535 ci = md_capainfo(env);
2537 RETURN(ERR_PTR(-ENOENT));
2539 switch (ci->mc_auth) {
2543 capa->lc_uid = obj->oo_inode->i_uid;
2544 capa->lc_gid = obj->oo_inode->i_gid;
2545 capa->lc_flags = LC_ID_PLAIN;
2547 case LC_ID_CONVERT: {
2550 s[0] = obj->oo_inode->i_uid;
2551 cfs_get_random_bytes(&(s[1]), sizeof(__u32));
2552 s[2] = obj->oo_inode->i_gid;
2553 cfs_get_random_bytes(&(s[3]), sizeof(__u32));
2554 rc = capa_encrypt_id(d, s, key->lk_key, CAPA_HMAC_KEY_MAX_LEN);
2556 RETURN(ERR_PTR(rc));
2558 capa->lc_uid = ((__u64)d[1] << 32) | d[0];
2559 capa->lc_gid = ((__u64)d[3] << 32) | d[2];
2560 capa->lc_flags = LC_ID_CONVERT;
2564 RETURN(ERR_PTR(-EINVAL));
2567 capa->lc_fid = *fid;
2569 capa->lc_flags |= dev->od_capa_alg << 24;
2570 capa->lc_timeout = dev->od_capa_timeout;
2571 capa->lc_expiry = 0;
2573 oc = capa_lookup(dev->od_capa_hash, capa, 1);
2575 LASSERT(!capa_is_expired(oc));
2579 cfs_spin_lock(&capa_lock);
2580 *key = dev->od_capa_keys[1];
2581 cfs_spin_unlock(&capa_lock);
2583 capa->lc_keyid = key->lk_keyid;
2584 capa->lc_expiry = cfs_time_current_sec() + dev->od_capa_timeout;
2586 rc = capa_hmac(capa->lc_hmac, capa, key->lk_key);
2588 DEBUG_CAPA(D_ERROR, capa, "HMAC failed: %d for", rc);
2589 RETURN(ERR_PTR(rc));
2592 oc = capa_add(dev->od_capa_hash, capa);
2596 static int osd_object_sync(const struct lu_env *env, struct dt_object *dt)
2598 struct osd_object *obj = osd_dt_obj(dt);
2599 struct inode *inode = obj->oo_inode;
2600 struct osd_thread_info *info = osd_oti_get(env);
2601 struct dentry *dentry = &info->oti_obj_dentry;
2602 struct file *file = &info->oti_file;
2607 dentry->d_inode = inode;
2608 file->f_dentry = dentry;
2609 file->f_mapping = inode->i_mapping;
2610 file->f_op = inode->i_fop;
2611 mutex_lock(&inode->i_mutex);
2612 rc = file->f_op->fsync(file, dentry, 0);
2613 mutex_unlock(&inode->i_mutex);
2617 static int osd_data_get(const struct lu_env *env, struct dt_object *dt,
2620 struct osd_object *obj = osd_dt_obj(dt);
2623 *data = (void *)obj->oo_inode;
2631 static int osd_iam_index_probe(const struct lu_env *env, struct osd_object *o,
2632 const struct dt_index_features *feat)
2634 struct iam_descr *descr;
2636 if (osd_object_is_root(o))
2637 return feat == &dt_directory_features;
2639 LASSERT(o->oo_dir != NULL);
2641 descr = o->oo_dir->od_container.ic_descr;
2642 if (feat == &dt_directory_features) {
2643 if (descr->id_rec_size == sizeof(struct osd_fid_pack))
2649 feat->dif_keysize_min <= descr->id_key_size &&
2650 descr->id_key_size <= feat->dif_keysize_max &&
2651 feat->dif_recsize_min <= descr->id_rec_size &&
2652 descr->id_rec_size <= feat->dif_recsize_max &&
2653 !(feat->dif_flags & (DT_IND_VARKEY |
2654 DT_IND_VARREC | DT_IND_NONUNQ)) &&
2655 ergo(feat->dif_flags & DT_IND_UPDATE,
2656 1 /* XXX check that object (and file system) is
2661 static int osd_iam_container_init(const struct lu_env *env,
2662 struct osd_object *obj,
2663 struct osd_directory *dir)
2665 struct iam_container *bag = &dir->od_container;
2668 result = iam_container_init(bag, &dir->od_descr, obj->oo_inode);
2672 result = iam_container_setup(bag);
2674 obj->oo_dt.do_index_ops = &osd_index_iam_ops;
2676 iam_container_fini(bag);
2683 * Concurrency: no external locking is necessary.
2685 static int osd_index_try(const struct lu_env *env, struct dt_object *dt,
2686 const struct dt_index_features *feat)
2690 struct osd_object *obj = osd_dt_obj(dt);
2692 LINVRNT(osd_invariant(obj));
2693 LASSERT(dt_object_exists(dt));
2695 if (osd_object_is_root(obj)) {
2696 dt->do_index_ops = &osd_index_ea_ops;
2698 } else if (feat == &dt_directory_features) {
2699 dt->do_index_ops = &osd_index_ea_ops;
2700 if (S_ISDIR(obj->oo_inode->i_mode))
2705 } else if (unlikely(feat == &dt_otable_features)) {
2706 dt->do_index_ops = &osd_otable_ops;
2708 } else if (feat == &dt_acct_features) {
2709 dt->do_index_ops = &osd_acct_index_ops;
2712 } else if (!osd_has_index(obj)) {
2713 struct osd_directory *dir;
2718 cfs_spin_lock(&obj->oo_guard);
2719 if (obj->oo_dir == NULL)
2723 * Concurrent thread allocated container data.
2726 cfs_spin_unlock(&obj->oo_guard);
2728 * Now, that we have container data, serialize its
2731 cfs_down_write(&obj->oo_ext_idx_sem);
2733 * recheck under lock.
2735 if (!osd_has_index(obj))
2736 result = osd_iam_container_init(env, obj, dir);
2739 cfs_up_write(&obj->oo_ext_idx_sem);
2747 if (result == 0 && skip_iam == 0) {
2748 if (!osd_iam_index_probe(env, obj, feat))
2751 LINVRNT(osd_invariant(obj));
2753 if (is_quota_glb_feat(feat))
2754 result = osd_quota_migration(env, dt, feat);
2759 static int osd_otable_it_attr_get(const struct lu_env *env,
2760 struct dt_object *dt,
2761 struct lu_attr *attr,
2762 struct lustre_capa *capa)
2768 static const struct dt_object_operations osd_obj_ops = {
2769 .do_read_lock = osd_object_read_lock,
2770 .do_write_lock = osd_object_write_lock,
2771 .do_read_unlock = osd_object_read_unlock,
2772 .do_write_unlock = osd_object_write_unlock,
2773 .do_write_locked = osd_object_write_locked,
2774 .do_attr_get = osd_attr_get,
2775 .do_declare_attr_set = osd_declare_attr_set,
2776 .do_attr_set = osd_attr_set,
2777 .do_ah_init = osd_ah_init,
2778 .do_declare_create = osd_declare_object_create,
2779 .do_create = osd_object_create,
2780 .do_declare_destroy = osd_declare_object_destroy,
2781 .do_destroy = osd_object_destroy,
2782 .do_index_try = osd_index_try,
2783 .do_declare_ref_add = osd_declare_object_ref_add,
2784 .do_ref_add = osd_object_ref_add,
2785 .do_declare_ref_del = osd_declare_object_ref_del,
2786 .do_ref_del = osd_object_ref_del,
2787 .do_xattr_get = osd_xattr_get,
2788 .do_declare_xattr_set = osd_declare_xattr_set,
2789 .do_xattr_set = osd_xattr_set,
2790 .do_declare_xattr_del = osd_declare_xattr_del,
2791 .do_xattr_del = osd_xattr_del,
2792 .do_xattr_list = osd_xattr_list,
2793 .do_capa_get = osd_capa_get,
2794 .do_object_sync = osd_object_sync,
2795 .do_data_get = osd_data_get,
2799 * dt_object_operations for interoperability mode
2800 * (i.e. to run 2.0 mds on 1.8 disk) (b11826)
2802 static const struct dt_object_operations osd_obj_ea_ops = {
2803 .do_read_lock = osd_object_read_lock,
2804 .do_write_lock = osd_object_write_lock,
2805 .do_read_unlock = osd_object_read_unlock,
2806 .do_write_unlock = osd_object_write_unlock,
2807 .do_write_locked = osd_object_write_locked,
2808 .do_attr_get = osd_attr_get,
2809 .do_declare_attr_set = osd_declare_attr_set,
2810 .do_attr_set = osd_attr_set,
2811 .do_ah_init = osd_ah_init,
2812 .do_declare_create = osd_declare_object_create,
2813 .do_create = osd_object_ea_create,
2814 .do_declare_destroy = osd_declare_object_destroy,
2815 .do_destroy = osd_object_destroy,
2816 .do_index_try = osd_index_try,
2817 .do_declare_ref_add = osd_declare_object_ref_add,
2818 .do_ref_add = osd_object_ref_add,
2819 .do_declare_ref_del = osd_declare_object_ref_del,
2820 .do_ref_del = osd_object_ref_del,
2821 .do_xattr_get = osd_xattr_get,
2822 .do_declare_xattr_set = osd_declare_xattr_set,
2823 .do_xattr_set = osd_xattr_set,
2824 .do_declare_xattr_del = osd_declare_xattr_del,
2825 .do_xattr_del = osd_xattr_del,
2826 .do_xattr_list = osd_xattr_list,
2827 .do_capa_get = osd_capa_get,
2828 .do_object_sync = osd_object_sync,
2829 .do_data_get = osd_data_get,
2832 static const struct dt_object_operations osd_obj_otable_it_ops = {
2833 .do_attr_get = osd_otable_it_attr_get,
2834 .do_index_try = osd_index_try,
2837 static int osd_index_declare_iam_delete(const struct lu_env *env,
2838 struct dt_object *dt,
2839 const struct dt_key *key,
2840 struct thandle *handle)
2842 struct osd_thandle *oh;
2844 oh = container_of0(handle, struct osd_thandle, ot_super);
2845 LASSERT(oh->ot_handle == NULL);
2847 OSD_DECLARE_OP(oh, delete, osd_dto_credits_noquota[DTO_INDEX_DELETE]);
2853 * delete a (key, value) pair from index \a dt specified by \a key
2855 * \param dt osd index object
2856 * \param key key for index
2857 * \param rec record reference
2858 * \param handle transaction handler
2861 * \retval -ve failure
2864 static int osd_index_iam_delete(const struct lu_env *env, struct dt_object *dt,
2865 const struct dt_key *key,
2866 struct thandle *handle,
2867 struct lustre_capa *capa)
2869 struct osd_thread_info *oti = osd_oti_get(env);
2870 struct osd_object *obj = osd_dt_obj(dt);
2871 struct osd_thandle *oh;
2872 struct iam_path_descr *ipd;
2873 struct iam_container *bag = &obj->oo_dir->od_container;
2878 LINVRNT(osd_invariant(obj));
2879 LASSERT(dt_object_exists(dt));
2880 LASSERT(bag->ic_object == obj->oo_inode);
2881 LASSERT(handle != NULL);
2883 if (osd_object_auth(env, dt, capa, CAPA_OPC_INDEX_DELETE))
2886 OSD_EXEC_OP(handle, delete);
2888 ipd = osd_idx_ipd_get(env, bag);
2889 if (unlikely(ipd == NULL))
2892 oh = container_of0(handle, struct osd_thandle, ot_super);
2893 LASSERT(oh->ot_handle != NULL);
2894 LASSERT(oh->ot_handle->h_transaction != NULL);
2896 if (fid_is_quota(lu_object_fid(&dt->do_lu))) {
2897 /* swab quota uid/gid provided by caller */
2898 oti->oti_quota_id = cpu_to_le64(*((__u64 *)key));
2899 key = (const struct dt_key *)&oti->oti_quota_id;
2902 rc = iam_delete(oh->ot_handle, bag, (const struct iam_key *)key, ipd);
2903 osd_ipd_put(env, bag, ipd);
2904 LINVRNT(osd_invariant(obj));
2908 static int osd_index_declare_ea_delete(const struct lu_env *env,
2909 struct dt_object *dt,
2910 const struct dt_key *key,
2911 struct thandle *handle)
2913 struct osd_thandle *oh;
2914 struct inode *inode;
2918 LASSERT(dt_object_exists(dt));
2919 LASSERT(handle != NULL);
2921 oh = container_of0(handle, struct osd_thandle, ot_super);
2922 LASSERT(oh->ot_handle == NULL);
2924 OSD_DECLARE_OP(oh, delete, osd_dto_credits_noquota[DTO_INDEX_DELETE]);
2926 inode = osd_dt_obj(dt)->oo_inode;
2929 rc = osd_declare_inode_qid(env, inode->i_uid, inode->i_gid, 0, oh,
2930 true, true, NULL, false);
2934 static inline int osd_get_fid_from_dentry(struct ldiskfs_dir_entry_2 *de,
2937 struct osd_fid_pack *rec;
2940 if (de->file_type & LDISKFS_DIRENT_LUFID) {
2941 rec = (struct osd_fid_pack *) (de->name + de->name_len + 1);
2942 rc = osd_fid_unpack((struct lu_fid *)fid, rec);
2948 * Index delete function for interoperability mode (b11826).
2949 * It will remove the directory entry added by osd_index_ea_insert().
2950 * This entry is needed to maintain name->fid mapping.
2952 * \param key, key i.e. file entry to be deleted
2954 * \retval 0, on success
2955 * \retval -ve, on error
2957 static int osd_index_ea_delete(const struct lu_env *env, struct dt_object *dt,
2958 const struct dt_key *key,
2959 struct thandle *handle,
2960 struct lustre_capa *capa)
2962 struct osd_object *obj = osd_dt_obj(dt);
2963 struct inode *dir = obj->oo_inode;
2964 struct dentry *dentry;
2965 struct osd_thandle *oh;
2966 struct ldiskfs_dir_entry_2 *de;
2967 struct buffer_head *bh;
2968 struct htree_lock *hlock = NULL;
2973 LINVRNT(osd_invariant(obj));
2974 LASSERT(dt_object_exists(dt));
2975 LASSERT(handle != NULL);
2977 OSD_EXEC_OP(handle, delete);
2979 oh = container_of(handle, struct osd_thandle, ot_super);
2980 LASSERT(oh->ot_handle != NULL);
2981 LASSERT(oh->ot_handle->h_transaction != NULL);
2983 if (osd_object_auth(env, dt, capa, CAPA_OPC_INDEX_DELETE))
2986 ll_vfs_dq_init(dir);
2987 dentry = osd_child_dentry_get(env, obj,
2988 (char *)key, strlen((char *)key));
2990 if (obj->oo_hl_head != NULL) {
2991 hlock = osd_oti_get(env)->oti_hlock;
2992 ldiskfs_htree_lock(hlock, obj->oo_hl_head,
2993 dir, LDISKFS_HLOCK_DEL);
2995 cfs_down_write(&obj->oo_ext_idx_sem);
2998 bh = osd_ldiskfs_find_entry(dir, dentry, &de, hlock);
3000 rc = ldiskfs_delete_entry(oh->ot_handle,
3007 ldiskfs_htree_unlock(hlock);
3009 cfs_up_write(&obj->oo_ext_idx_sem);
3011 LASSERT(osd_invariant(obj));
3016 * Lookup index for \a key and copy record to \a rec.
3018 * \param dt osd index object
3019 * \param key key for index
3020 * \param rec record reference
3022 * \retval +ve success : exact mach
3023 * \retval 0 return record with key not greater than \a key
3024 * \retval -ve failure
3026 static int osd_index_iam_lookup(const struct lu_env *env, struct dt_object *dt,
3027 struct dt_rec *rec, const struct dt_key *key,
3028 struct lustre_capa *capa)
3030 struct osd_object *obj = osd_dt_obj(dt);
3031 struct iam_path_descr *ipd;
3032 struct iam_container *bag = &obj->oo_dir->od_container;
3033 struct osd_thread_info *oti = osd_oti_get(env);
3034 struct iam_iterator *it = &oti->oti_idx_it;
3035 struct iam_rec *iam_rec;
3040 LASSERT(osd_invariant(obj));
3041 LASSERT(dt_object_exists(dt));
3042 LASSERT(bag->ic_object == obj->oo_inode);
3044 if (osd_object_auth(env, dt, capa, CAPA_OPC_INDEX_LOOKUP))
3047 ipd = osd_idx_ipd_get(env, bag);
3051 /* got ipd now we can start iterator. */
3052 iam_it_init(it, bag, 0, ipd);
3054 if (fid_is_quota(lu_object_fid(&dt->do_lu))) {
3055 /* swab quota uid/gid provided by caller */
3056 oti->oti_quota_id = cpu_to_le64(*((__u64 *)key));
3057 key = (const struct dt_key *)&oti->oti_quota_id;
3060 rc = iam_it_get(it, (struct iam_key *)key);
3062 if (S_ISDIR(obj->oo_inode->i_mode))
3063 iam_rec = (struct iam_rec *)oti->oti_ldp;
3065 iam_rec = (struct iam_rec *) rec;
3067 iam_reccpy(&it->ii_path.ip_leaf, (struct iam_rec *)iam_rec);
3069 if (S_ISDIR(obj->oo_inode->i_mode))
3070 osd_fid_unpack((struct lu_fid *) rec,
3071 (struct osd_fid_pack *)iam_rec);
3072 else if (fid_is_quota(lu_object_fid(&dt->do_lu)))
3073 osd_quota_unpack(obj, rec);
3078 osd_ipd_put(env, bag, ipd);
3080 LINVRNT(osd_invariant(obj));
3085 static int osd_index_declare_iam_insert(const struct lu_env *env,
3086 struct dt_object *dt,
3087 const struct dt_rec *rec,
3088 const struct dt_key *key,
3089 struct thandle *handle)
3091 struct osd_thandle *oh;
3093 LASSERT(dt_object_exists(dt));
3094 LASSERT(handle != NULL);
3096 oh = container_of0(handle, struct osd_thandle, ot_super);
3097 LASSERT(oh->ot_handle == NULL);
3099 OSD_DECLARE_OP(oh, insert, osd_dto_credits_noquota[DTO_INDEX_INSERT]);
3105 * Inserts (key, value) pair in \a dt index object.
3107 * \param dt osd index object
3108 * \param key key for index
3109 * \param rec record reference
3110 * \param th transaction handler
3113 * \retval -ve failure
3115 static int osd_index_iam_insert(const struct lu_env *env, struct dt_object *dt,
3116 const struct dt_rec *rec,
3117 const struct dt_key *key, struct thandle *th,
3118 struct lustre_capa *capa, int ignore_quota)
3120 struct osd_object *obj = osd_dt_obj(dt);
3121 struct iam_path_descr *ipd;
3122 struct osd_thandle *oh;
3123 struct iam_container *bag = &obj->oo_dir->od_container;
3124 struct osd_thread_info *oti = osd_oti_get(env);
3125 struct iam_rec *iam_rec;
3130 LINVRNT(osd_invariant(obj));
3131 LASSERT(dt_object_exists(dt));
3132 LASSERT(bag->ic_object == obj->oo_inode);
3133 LASSERT(th != NULL);
3135 if (osd_object_auth(env, dt, capa, CAPA_OPC_INDEX_INSERT))
3138 OSD_EXEC_OP(th, insert);
3140 ipd = osd_idx_ipd_get(env, bag);
3141 if (unlikely(ipd == NULL))
3144 oh = container_of0(th, struct osd_thandle, ot_super);
3145 LASSERT(oh->ot_handle != NULL);
3146 LASSERT(oh->ot_handle->h_transaction != NULL);
3147 if (S_ISDIR(obj->oo_inode->i_mode)) {
3148 iam_rec = (struct iam_rec *)oti->oti_ldp;
3149 osd_fid_pack((struct osd_fid_pack *)iam_rec, rec, &oti->oti_fid);
3150 } else if (fid_is_quota(lu_object_fid(&dt->do_lu))) {
3151 /* pack quota uid/gid */
3152 oti->oti_quota_id = cpu_to_le64(*((__u64 *)key));
3153 key = (const struct dt_key *)&oti->oti_quota_id;
3154 /* pack quota record */
3155 rec = osd_quota_pack(obj, rec, &oti->oti_quota_rec);
3156 iam_rec = (struct iam_rec *)rec;
3158 iam_rec = (struct iam_rec *)rec;
3161 rc = iam_insert(oh->ot_handle, bag, (const struct iam_key *)key,
3163 osd_ipd_put(env, bag, ipd);
3164 LINVRNT(osd_invariant(obj));
3169 * Calls ldiskfs_add_entry() to add directory entry
3170 * into the directory. This is required for
3171 * interoperability mode (b11826)
3173 * \retval 0, on success
3174 * \retval -ve, on error
3176 static int __osd_ea_add_rec(struct osd_thread_info *info,
3177 struct osd_object *pobj, struct inode *cinode,
3178 const char *name, const struct dt_rec *fid,
3179 struct htree_lock *hlock, struct thandle *th)
3181 struct ldiskfs_dentry_param *ldp;
3182 struct dentry *child;
3183 struct osd_thandle *oth;
3186 oth = container_of(th, struct osd_thandle, ot_super);
3187 LASSERT(oth->ot_handle != NULL);
3188 LASSERT(oth->ot_handle->h_transaction != NULL);
3190 child = osd_child_dentry_get(info->oti_env, pobj, name, strlen(name));
3192 /* XXX: remove fid_is_igif() check here.
3193 * IGIF check is just to handle insertion of .. when it is 'ROOT',
3194 * it is IGIF now but needs FID in dir entry as well for readdir
3196 * LU-838 should fix that and remove fid_is_igif() check */
3197 if (fid_is_igif((struct lu_fid *)fid) ||
3198 fid_is_norm((struct lu_fid *)fid)) {
3199 ldp = (struct ldiskfs_dentry_param *)info->oti_ldp;
3200 osd_get_ldiskfs_dirent_param(ldp, fid);
3201 child->d_fsdata = (void *)ldp;
3203 child->d_fsdata = NULL;
3205 LASSERT(pobj->oo_inode);
3206 ll_vfs_dq_init(pobj->oo_inode);
3207 rc = osd_ldiskfs_add_entry(oth->ot_handle, child, cinode, hlock);
3213 * Calls ldiskfs_add_dot_dotdot() to add dot and dotdot entries
3214 * into the directory.Also sets flags into osd object to
3215 * indicate dot and dotdot are created. This is required for
3216 * interoperability mode (b11826)
3218 * \param dir directory for dot and dotdot fixup.
3219 * \param obj child object for linking
3221 * \retval 0, on success
3222 * \retval -ve, on error
3224 static int osd_add_dot_dotdot(struct osd_thread_info *info,
3225 struct osd_object *dir,
3226 struct inode *parent_dir, const char *name,
3227 const struct dt_rec *dot_fid,
3228 const struct dt_rec *dot_dot_fid,
3231 struct inode *inode = dir->oo_inode;
3232 struct ldiskfs_dentry_param *dot_ldp;
3233 struct ldiskfs_dentry_param *dot_dot_ldp;
3234 struct osd_thandle *oth;
3237 oth = container_of(th, struct osd_thandle, ot_super);
3238 LASSERT(oth->ot_handle->h_transaction != NULL);
3239 LASSERT(S_ISDIR(dir->oo_inode->i_mode));
3241 if (strcmp(name, dot) == 0) {
3242 if (dir->oo_compat_dot_created) {
3245 LASSERT(inode == parent_dir);
3246 dir->oo_compat_dot_created = 1;
3249 } else if(strcmp(name, dotdot) == 0) {
3250 dot_ldp = (struct ldiskfs_dentry_param *)info->oti_ldp;
3251 dot_dot_ldp = (struct ldiskfs_dentry_param *)info->oti_ldp2;
3253 if (!dir->oo_compat_dot_created)
3255 if (!fid_is_igif((struct lu_fid *)dot_fid)) {
3256 osd_get_ldiskfs_dirent_param(dot_ldp, dot_fid);
3257 osd_get_ldiskfs_dirent_param(dot_dot_ldp, dot_dot_fid);
3262 /* in case of rename, dotdot is already created */
3263 if (dir->oo_compat_dotdot_created) {
3264 return __osd_ea_add_rec(info, dir, parent_dir, name,
3265 dot_dot_fid, NULL, th);
3268 result = ldiskfs_add_dot_dotdot(oth->ot_handle, parent_dir,
3269 inode, dot_ldp, dot_dot_ldp);
3271 dir->oo_compat_dotdot_created = 1;
3279 * It will call the appropriate osd_add* function and return the
3280 * value, return by respective functions.
3282 static int osd_ea_add_rec(const struct lu_env *env, struct osd_object *pobj,
3283 struct inode *cinode, const char *name,
3284 const struct dt_rec *fid, struct thandle *th)
3286 struct osd_thread_info *info = osd_oti_get(env);
3287 struct htree_lock *hlock;
3290 hlock = pobj->oo_hl_head != NULL ? info->oti_hlock : NULL;
3292 if (name[0] == '.' && (name[1] == '\0' || (name[1] == '.' &&
3294 if (hlock != NULL) {
3295 ldiskfs_htree_lock(hlock, pobj->oo_hl_head,
3298 cfs_down_write(&pobj->oo_ext_idx_sem);
3300 rc = osd_add_dot_dotdot(info, pobj, cinode, name,
3301 (struct dt_rec *)lu_object_fid(&pobj->oo_dt.do_lu),
3304 if (hlock != NULL) {
3305 ldiskfs_htree_lock(hlock, pobj->oo_hl_head,
3306 pobj->oo_inode, LDISKFS_HLOCK_ADD);
3308 cfs_down_write(&pobj->oo_ext_idx_sem);
3311 rc = __osd_ea_add_rec(info, pobj, cinode, name, fid,
3315 ldiskfs_htree_unlock(hlock);
3317 cfs_up_write(&pobj->oo_ext_idx_sem);
3323 osd_consistency_check(struct osd_thread_info *oti, struct osd_device *dev,
3324 struct osd_idmap_cache *oic)
3326 struct osd_scrub *scrub = &dev->od_scrub;
3327 struct lu_fid *fid = &oic->oic_fid;
3328 struct osd_inode_id *id = &oti->oti_id;
3333 if (!fid_is_norm(fid) && !fid_is_igif(fid))
3337 rc = osd_oi_lookup(oti, dev, fid, id);
3338 if (rc != 0 && rc != -ENOENT)
3341 if (rc == 0 && osd_id_eq(id, &oic->oic_lid))
3344 if (thread_is_running(&scrub->os_thread)) {
3345 rc = osd_oii_insert(dev, oic, rc == -ENOENT);
3346 /* There is race condition between osd_oi_lookup and OI scrub.
3347 * The OI scrub finished just after osd_oi_lookup() failure.
3348 * Under such case, it is unnecessary to trigger OI scrub again,
3349 * but try to call osd_oi_lookup() again. */
3350 if (unlikely(rc == -EAGAIN))
3356 if (!dev->od_noscrub && ++once == 1) {
3357 CDEBUG(D_LFSCK, "Trigger OI scrub by RPC for "DFID"\n",
3359 rc = osd_scrub_start(dev);
3360 LCONSOLE_ERROR("%.16s: trigger OI scrub by RPC for "DFID
3362 LDISKFS_SB(osd_sb(dev))->s_es->s_volume_name,
3372 * Calls ->lookup() to find dentry. From dentry get inode and
3373 * read inode's ea to get fid. This is required for interoperability
3376 * \retval 0, on success
3377 * \retval -ve, on error
3379 static int osd_ea_lookup_rec(const struct lu_env *env, struct osd_object *obj,
3380 struct dt_rec *rec, const struct dt_key *key)
3382 struct inode *dir = obj->oo_inode;
3383 struct dentry *dentry;
3384 struct ldiskfs_dir_entry_2 *de;
3385 struct buffer_head *bh;
3386 struct lu_fid *fid = (struct lu_fid *) rec;
3387 struct htree_lock *hlock = NULL;
3391 LASSERT(dir->i_op != NULL && dir->i_op->lookup != NULL);
3393 dentry = osd_child_dentry_get(env, obj,
3394 (char *)key, strlen((char *)key));
3396 if (obj->oo_hl_head != NULL) {
3397 hlock = osd_oti_get(env)->oti_hlock;
3398 ldiskfs_htree_lock(hlock, obj->oo_hl_head,
3399 dir, LDISKFS_HLOCK_LOOKUP);
3401 cfs_down_read(&obj->oo_ext_idx_sem);
3404 bh = osd_ldiskfs_find_entry(dir, dentry, &de, hlock);
3406 struct osd_thread_info *oti = osd_oti_get(env);
3407 struct osd_idmap_cache *oic = &oti->oti_cache;
3408 struct osd_device *dev = osd_obj2dev(obj);
3409 struct osd_scrub *scrub = &dev->od_scrub;
3410 struct scrub_file *sf = &scrub->os_file;
3412 ino = le32_to_cpu(de->inode);
3413 rc = osd_get_fid_from_dentry(de, rec);
3415 /* done with de, release bh */
3418 rc = osd_ea_fid_get(env, obj, ino, fid, &oic->oic_lid);
3420 osd_id_gen(&oic->oic_lid, ino, OSD_OII_NOGEN);
3422 fid_zero(&oic->oic_fid);
3426 oic->oic_fid = *fid;
3427 if ((scrub->os_pos_current <= ino) &&
3428 (sf->sf_flags & SF_INCONSISTENT ||
3429 ldiskfs_test_bit(osd_oi_fid2idx(dev, fid),
3431 osd_consistency_check(oti, dev, oic);
3440 ldiskfs_htree_unlock(hlock);
3442 cfs_up_read(&obj->oo_ext_idx_sem);
3447 * Find the osd object for given fid.
3449 * \param fid need to find the osd object having this fid
3451 * \retval osd_object on success
3452 * \retval -ve on error
3454 struct osd_object *osd_object_find(const struct lu_env *env,
3455 struct dt_object *dt,
3456 const struct lu_fid *fid)
3458 struct lu_device *ludev = dt->do_lu.lo_dev;
3459 struct osd_object *child = NULL;
3460 struct lu_object *luch;
3461 struct lu_object *lo;
3464 * at this point topdev might not exist yet
3465 * (i.e. MGS is preparing profiles). so we can
3466 * not rely on topdev and instead lookup with
3467 * our device passed as topdev. this can't work
3468 * if the object isn't cached yet (as osd doesn't
3469 * allocate lu_header). IOW, the object must be
3470 * in the cache, otherwise lu_object_alloc() crashes
3473 luch = lu_object_find_at(env, ludev, fid, NULL);
3474 if (!IS_ERR(luch)) {
3475 if (lu_object_exists(luch)) {
3476 lo = lu_object_locate(luch->lo_header, ludev->ld_type);
3478 child = osd_obj(lo);
3480 LU_OBJECT_DEBUG(D_ERROR, env, luch,
3481 "lu_object can't be located"
3482 DFID"\n", PFID(fid));
3484 if (child == NULL) {
3485 lu_object_put(env, luch);
3486 CERROR("Unable to get osd_object\n");
3487 child = ERR_PTR(-ENOENT);
3490 LU_OBJECT_DEBUG(D_ERROR, env, luch,
3491 "lu_object does not exists "DFID"\n",
3493 lu_object_put(env, luch);
3494 child = ERR_PTR(-ENOENT);
3497 child = (void *)luch;
3503 * Put the osd object once done with it.
3505 * \param obj osd object that needs to be put
3507 static inline void osd_object_put(const struct lu_env *env,
3508 struct osd_object *obj)
3510 lu_object_put(env, &obj->oo_dt.do_lu);
3513 static int osd_index_declare_ea_insert(const struct lu_env *env,
3514 struct dt_object *dt,
3515 const struct dt_rec *rec,
3516 const struct dt_key *key,
3517 struct thandle *handle)
3519 struct osd_thandle *oh;
3520 struct inode *inode;
3524 LASSERT(dt_object_exists(dt));
3525 LASSERT(handle != NULL);
3527 oh = container_of0(handle, struct osd_thandle, ot_super);
3528 LASSERT(oh->ot_handle == NULL);
3530 OSD_DECLARE_OP(oh, insert, osd_dto_credits_noquota[DTO_INDEX_INSERT]);
3532 inode = osd_dt_obj(dt)->oo_inode;
3535 /* We ignore block quota on meta pool (MDTs), so needn't
3536 * calculate how many blocks will be consumed by this index
3538 rc = osd_declare_inode_qid(env, inode->i_uid, inode->i_gid, 0, oh,
3539 true, true, NULL, false);
3544 * Index add function for interoperability mode (b11826).
3545 * It will add the directory entry.This entry is needed to
3546 * maintain name->fid mapping.
3548 * \param key it is key i.e. file entry to be inserted
3549 * \param rec it is value of given key i.e. fid
3551 * \retval 0, on success
3552 * \retval -ve, on error
3554 static int osd_index_ea_insert(const struct lu_env *env, struct dt_object *dt,
3555 const struct dt_rec *rec,
3556 const struct dt_key *key, struct thandle *th,
3557 struct lustre_capa *capa, int ignore_quota)
3559 struct osd_object *obj = osd_dt_obj(dt);
3560 struct lu_fid *fid = (struct lu_fid *) rec;
3561 const char *name = (const char *)key;
3562 struct osd_object *child;
3567 LASSERT(osd_invariant(obj));
3568 LASSERT(dt_object_exists(dt));
3569 LASSERT(th != NULL);
3571 if (osd_object_auth(env, dt, capa, CAPA_OPC_INDEX_INSERT))
3574 child = osd_object_find(env, dt, fid);
3575 if (!IS_ERR(child)) {
3576 rc = osd_ea_add_rec(env, obj, child->oo_inode, name, rec, th);
3577 osd_object_put(env, child);
3579 rc = PTR_ERR(child);
3582 LASSERT(osd_invariant(obj));
3587 * Initialize osd Iterator for given osd index object.
3589 * \param dt osd index object
3592 static struct dt_it *osd_it_iam_init(const struct lu_env *env,
3593 struct dt_object *dt,
3595 struct lustre_capa *capa)
3597 struct osd_it_iam *it;
3598 struct osd_thread_info *oti = osd_oti_get(env);
3599 struct osd_object *obj = osd_dt_obj(dt);
3600 struct lu_object *lo = &dt->do_lu;
3601 struct iam_path_descr *ipd;
3602 struct iam_container *bag = &obj->oo_dir->od_container;
3604 LASSERT(lu_object_exists(lo));
3606 if (osd_object_auth(env, dt, capa, CAPA_OPC_BODY_READ))
3607 return ERR_PTR(-EACCES);
3610 ipd = osd_it_ipd_get(env, bag);
3611 if (likely(ipd != NULL)) {
3615 iam_it_init(&it->oi_it, bag, IAM_IT_MOVE, ipd);
3616 return (struct dt_it *)it;
3618 return ERR_PTR(-ENOMEM);
3622 * free given Iterator.
3625 static void osd_it_iam_fini(const struct lu_env *env, struct dt_it *di)
3627 struct osd_it_iam *it = (struct osd_it_iam *)di;
3628 struct osd_object *obj = it->oi_obj;
3630 iam_it_fini(&it->oi_it);
3631 osd_ipd_put(env, &obj->oo_dir->od_container, it->oi_ipd);
3632 lu_object_put(env, &obj->oo_dt.do_lu);
3636 * Move Iterator to record specified by \a key
3638 * \param di osd iterator
3639 * \param key key for index
3641 * \retval +ve di points to record with least key not larger than key
3642 * \retval 0 di points to exact matched key
3643 * \retval -ve failure
3646 static int osd_it_iam_get(const struct lu_env *env,
3647 struct dt_it *di, const struct dt_key *key)
3649 struct osd_thread_info *oti = osd_oti_get(env);
3650 struct osd_it_iam *it = (struct osd_it_iam *)di;
3652 if (fid_is_quota(lu_object_fid(&it->oi_obj->oo_dt.do_lu))) {
3653 /* swab quota uid/gid */
3654 oti->oti_quota_id = cpu_to_le64(*((__u64 *)key));
3655 key = (struct dt_key *)&oti->oti_quota_id;
3658 return iam_it_get(&it->oi_it, (const struct iam_key *)key);
3664 * \param di osd iterator
3667 static void osd_it_iam_put(const struct lu_env *env, struct dt_it *di)
3669 struct osd_it_iam *it = (struct osd_it_iam *)di;
3671 iam_it_put(&it->oi_it);
3675 * Move iterator by one record
3677 * \param di osd iterator
3679 * \retval +1 end of container reached
3681 * \retval -ve failure
3684 static int osd_it_iam_next(const struct lu_env *env, struct dt_it *di)
3686 struct osd_it_iam *it = (struct osd_it_iam *)di;
3688 return iam_it_next(&it->oi_it);
3692 * Return pointer to the key under iterator.
3695 static struct dt_key *osd_it_iam_key(const struct lu_env *env,
3696 const struct dt_it *di)
3698 struct osd_thread_info *oti = osd_oti_get(env);
3699 struct osd_it_iam *it = (struct osd_it_iam *)di;
3700 struct osd_object *obj = it->oi_obj;
3703 key = (struct dt_key *)iam_it_key_get(&it->oi_it);
3705 if (!IS_ERR(key) && fid_is_quota(lu_object_fid(&obj->oo_dt.do_lu))) {
3706 /* swab quota uid/gid */
3707 oti->oti_quota_id = le64_to_cpu(*((__u64 *)key));
3708 key = (struct dt_key *)&oti->oti_quota_id;
3715 * Return size of key under iterator (in bytes)
3718 static int osd_it_iam_key_size(const struct lu_env *env, const struct dt_it *di)
3720 struct osd_it_iam *it = (struct osd_it_iam *)di;
3722 return iam_it_key_size(&it->oi_it);
3725 static inline void osd_it_append_attrs(struct lu_dirent *ent, __u32 attr,
3726 int len, __u16 type)
3728 struct luda_type *lt;
3729 const unsigned align = sizeof(struct luda_type) - 1;
3731 /* check if file type is required */
3732 if (attr & LUDA_TYPE) {
3733 len = (len + align) & ~align;
3735 lt = (void *) ent->lde_name + len;
3736 lt->lt_type = cpu_to_le16(CFS_DTTOIF(type));
3737 ent->lde_attrs |= LUDA_TYPE;
3740 ent->lde_attrs = cpu_to_le32(ent->lde_attrs);
3744 * build lu direct from backend fs dirent.
3747 static inline void osd_it_pack_dirent(struct lu_dirent *ent,
3748 struct lu_fid *fid, __u64 offset,
3749 char *name, __u16 namelen,
3750 __u16 type, __u32 attr)
3752 fid_cpu_to_le(&ent->lde_fid, fid);
3753 ent->lde_attrs = LUDA_FID;
3755 ent->lde_hash = cpu_to_le64(offset);
3756 ent->lde_reclen = cpu_to_le16(lu_dirent_calc_size(namelen, attr));
3758 strncpy(ent->lde_name, name, namelen);
3759 ent->lde_namelen = cpu_to_le16(namelen);
3761 /* append lustre attributes */
3762 osd_it_append_attrs(ent, attr, namelen, type);
3766 * Return pointer to the record under iterator.
3768 static int osd_it_iam_rec(const struct lu_env *env,
3769 const struct dt_it *di,
3770 struct dt_rec *dtrec, __u32 attr)
3772 struct osd_it_iam *it = (struct osd_it_iam *)di;
3773 struct osd_thread_info *info = osd_oti_get(env);
3776 if (S_ISDIR(it->oi_obj->oo_inode->i_mode)) {
3777 const struct osd_fid_pack *rec;
3778 struct lu_fid *fid = &info->oti_fid;
3779 struct lu_dirent *lde = (struct lu_dirent *)dtrec;
3785 name = (char *)iam_it_key_get(&it->oi_it);
3787 RETURN(PTR_ERR(name));
3789 namelen = iam_it_key_size(&it->oi_it);
3791 rec = (const struct osd_fid_pack *)iam_it_rec_get(&it->oi_it);
3793 RETURN(PTR_ERR(rec));
3795 rc = osd_fid_unpack(fid, rec);
3799 hash = iam_it_store(&it->oi_it);
3801 /* IAM does not store object type in IAM index (dir) */
3802 osd_it_pack_dirent(lde, fid, hash, name, namelen,
3804 } else if (fid_is_quota(lu_object_fid(&it->oi_obj->oo_dt.do_lu))) {
3805 iam_reccpy(&it->oi_it.ii_path.ip_leaf,
3806 (struct iam_rec *)dtrec);
3807 osd_quota_unpack(it->oi_obj, dtrec);
3809 iam_reccpy(&it->oi_it.ii_path.ip_leaf,
3810 (struct iam_rec *)dtrec);
3817 * Returns cookie for current Iterator position.
3819 static __u64 osd_it_iam_store(const struct lu_env *env, const struct dt_it *di)
3821 struct osd_it_iam *it = (struct osd_it_iam *)di;
3823 return iam_it_store(&it->oi_it);
3827 * Restore iterator from cookie.
3829 * \param di osd iterator
3830 * \param hash Iterator location cookie
3832 * \retval +ve di points to record with least key not larger than key.
3833 * \retval 0 di points to exact matched key
3834 * \retval -ve failure
3837 static int osd_it_iam_load(const struct lu_env *env,
3838 const struct dt_it *di, __u64 hash)
3840 struct osd_it_iam *it = (struct osd_it_iam *)di;
3842 return iam_it_load(&it->oi_it, hash);
3845 static const struct dt_index_operations osd_index_iam_ops = {
3846 .dio_lookup = osd_index_iam_lookup,
3847 .dio_declare_insert = osd_index_declare_iam_insert,
3848 .dio_insert = osd_index_iam_insert,
3849 .dio_declare_delete = osd_index_declare_iam_delete,
3850 .dio_delete = osd_index_iam_delete,
3852 .init = osd_it_iam_init,
3853 .fini = osd_it_iam_fini,
3854 .get = osd_it_iam_get,
3855 .put = osd_it_iam_put,
3856 .next = osd_it_iam_next,
3857 .key = osd_it_iam_key,
3858 .key_size = osd_it_iam_key_size,
3859 .rec = osd_it_iam_rec,
3860 .store = osd_it_iam_store,
3861 .load = osd_it_iam_load
3867 * Creates or initializes iterator context.
3869 * \retval struct osd_it_ea, iterator structure on success
3872 static struct dt_it *osd_it_ea_init(const struct lu_env *env,
3873 struct dt_object *dt,
3875 struct lustre_capa *capa)
3877 struct osd_object *obj = osd_dt_obj(dt);
3878 struct osd_thread_info *info = osd_oti_get(env);
3879 struct osd_it_ea *it = &info->oti_it_ea;
3880 struct lu_object *lo = &dt->do_lu;
3881 struct dentry *obj_dentry = &info->oti_it_dentry;
3883 LASSERT(lu_object_exists(lo));
3885 obj_dentry->d_inode = obj->oo_inode;
3886 obj_dentry->d_sb = osd_sb(osd_obj2dev(obj));
3887 obj_dentry->d_name.hash = 0;
3889 it->oie_rd_dirent = 0;
3890 it->oie_it_dirent = 0;
3891 it->oie_dirent = NULL;
3892 it->oie_buf = info->oti_it_ea_buf;
3894 it->oie_file.f_pos = 0;
3895 it->oie_file.f_dentry = obj_dentry;
3896 if (attr & LUDA_64BITHASH)
3897 it->oie_file.f_mode |= FMODE_64BITHASH;
3899 it->oie_file.f_mode |= FMODE_32BITHASH;
3900 it->oie_file.f_mapping = obj->oo_inode->i_mapping;
3901 it->oie_file.f_op = obj->oo_inode->i_fop;
3902 it->oie_file.private_data = NULL;
3904 RETURN((struct dt_it *) it);
3908 * Destroy or finishes iterator context.
3910 * \param di iterator structure to be destroyed
3912 static void osd_it_ea_fini(const struct lu_env *env, struct dt_it *di)
3914 struct osd_it_ea *it = (struct osd_it_ea *)di;
3915 struct osd_object *obj = it->oie_obj;
3916 struct inode *inode = obj->oo_inode;
3919 it->oie_file.f_op->release(inode, &it->oie_file);
3920 lu_object_put(env, &obj->oo_dt.do_lu);
3925 * It position the iterator at given key, so that next lookup continues from
3926 * that key Or it is similar to dio_it->load() but based on a key,
3927 * rather than file position.
3929 * As a special convention, osd_it_ea_get(env, di, "") has to rewind iterator
3932 * TODO: Presently return +1 considering it is only used by mdd_dir_is_empty().
3934 static int osd_it_ea_get(const struct lu_env *env,
3935 struct dt_it *di, const struct dt_key *key)
3937 struct osd_it_ea *it = (struct osd_it_ea *)di;
3940 LASSERT(((const char *)key)[0] == '\0');
3941 it->oie_file.f_pos = 0;
3942 it->oie_rd_dirent = 0;
3943 it->oie_it_dirent = 0;
3944 it->oie_dirent = NULL;
3952 static void osd_it_ea_put(const struct lu_env *env, struct dt_it *di)
3957 * It is called internally by ->readdir(). It fills the
3958 * iterator's in-memory data structure with required
3959 * information i.e. name, namelen, rec_size etc.
3961 * \param buf in which information to be filled in.
3962 * \param name name of the file in given dir
3964 * \retval 0 on success
3965 * \retval 1 on buffer full
3967 static int osd_ldiskfs_filldir(char *buf, const char *name, int namelen,
3968 loff_t offset, __u64 ino,
3971 struct osd_it_ea *it = (struct osd_it_ea *)buf;
3972 struct osd_it_ea_dirent *ent = it->oie_dirent;
3973 struct lu_fid *fid = &ent->oied_fid;
3974 struct osd_fid_pack *rec;
3977 /* this should never happen */
3978 if (unlikely(namelen == 0 || namelen > LDISKFS_NAME_LEN)) {
3979 CERROR("ldiskfs return invalid namelen %d\n", namelen);
3983 if ((void *) ent - it->oie_buf + sizeof(*ent) + namelen >
3987 if (d_type & LDISKFS_DIRENT_LUFID) {
3988 rec = (struct osd_fid_pack*) (name + namelen + 1);
3990 if (osd_fid_unpack(fid, rec) != 0)
3993 d_type &= ~LDISKFS_DIRENT_LUFID;
3998 ent->oied_ino = ino;
3999 ent->oied_off = offset;
4000 ent->oied_namelen = namelen;
4001 ent->oied_type = d_type;
4003 memcpy(ent->oied_name, name, namelen);
4005 it->oie_rd_dirent++;
4006 it->oie_dirent = (void *) ent + cfs_size_round(sizeof(*ent) + namelen);
4011 * Calls ->readdir() to load a directory entry at a time
4012 * and stored it in iterator's in-memory data structure.
4014 * \param di iterator's in memory structure
4016 * \retval 0 on success
4017 * \retval -ve on error
4019 static int osd_ldiskfs_it_fill(const struct lu_env *env,
4020 const struct dt_it *di)
4022 struct osd_it_ea *it = (struct osd_it_ea *)di;
4023 struct osd_object *obj = it->oie_obj;
4024 struct inode *inode = obj->oo_inode;
4025 struct htree_lock *hlock = NULL;
4029 it->oie_dirent = it->oie_buf;
4030 it->oie_rd_dirent = 0;
4032 if (obj->oo_hl_head != NULL) {
4033 hlock = osd_oti_get(env)->oti_hlock;
4034 ldiskfs_htree_lock(hlock, obj->oo_hl_head,
4035 inode, LDISKFS_HLOCK_READDIR);
4037 cfs_down_read(&obj->oo_ext_idx_sem);
4040 result = inode->i_fop->readdir(&it->oie_file, it,
4041 (filldir_t) osd_ldiskfs_filldir);
4044 ldiskfs_htree_unlock(hlock);
4046 cfs_up_read(&obj->oo_ext_idx_sem);
4048 if (it->oie_rd_dirent == 0) {
4051 it->oie_dirent = it->oie_buf;
4052 it->oie_it_dirent = 1;
4059 * It calls osd_ldiskfs_it_fill() which will use ->readdir()
4060 * to load a directory entry at a time and stored it in
4061 * iterator's in-memory data structure.
4063 * \param di iterator's in memory structure
4065 * \retval +ve iterator reached to end
4066 * \retval 0 iterator not reached to end
4067 * \retval -ve on error
4069 static int osd_it_ea_next(const struct lu_env *env, struct dt_it *di)
4071 struct osd_it_ea *it = (struct osd_it_ea *)di;
4076 if (it->oie_it_dirent < it->oie_rd_dirent) {
4078 (void *) it->oie_dirent +
4079 cfs_size_round(sizeof(struct osd_it_ea_dirent) +
4080 it->oie_dirent->oied_namelen);
4081 it->oie_it_dirent++;
4084 if (it->oie_file.f_pos == ldiskfs_get_htree_eof(&it->oie_file))
4087 rc = osd_ldiskfs_it_fill(env, di);
4094 * Returns the key at current position from iterator's in memory structure.
4096 * \param di iterator's in memory structure
4098 * \retval key i.e. struct dt_key on success
4100 static struct dt_key *osd_it_ea_key(const struct lu_env *env,
4101 const struct dt_it *di)
4103 struct osd_it_ea *it = (struct osd_it_ea *)di;
4105 return (struct dt_key *)it->oie_dirent->oied_name;
4109 * Returns the key's size at current position from iterator's in memory structure.
4111 * \param di iterator's in memory structure
4113 * \retval key_size i.e. struct dt_key on success
4115 static int osd_it_ea_key_size(const struct lu_env *env, const struct dt_it *di)
4117 struct osd_it_ea *it = (struct osd_it_ea *)di;
4119 return it->oie_dirent->oied_namelen;
4124 * Returns the value (i.e. fid/igif) at current position from iterator's
4125 * in memory structure.
4127 * \param di struct osd_it_ea, iterator's in memory structure
4128 * \param attr attr requested for dirent.
4129 * \param lde lustre dirent
4131 * \retval 0 no error and \param lde has correct lustre dirent.
4132 * \retval -ve on error
4134 static inline int osd_it_ea_rec(const struct lu_env *env,
4135 const struct dt_it *di,
4136 struct dt_rec *dtrec, __u32 attr)
4138 struct osd_it_ea *it = (struct osd_it_ea *)di;
4139 struct osd_object *obj = it->oie_obj;
4140 struct osd_device *dev = osd_obj2dev(obj);
4141 struct osd_scrub *scrub = &dev->od_scrub;
4142 struct scrub_file *sf = &scrub->os_file;
4143 struct osd_thread_info *oti = osd_oti_get(env);
4144 struct osd_idmap_cache *oic = &oti->oti_cache;
4145 struct lu_fid *fid = &it->oie_dirent->oied_fid;
4146 struct lu_dirent *lde = (struct lu_dirent *)dtrec;
4147 __u32 ino = it->oie_dirent->oied_ino;
4151 if (!fid_is_sane(fid)) {
4152 rc = osd_ea_fid_get(env, obj, ino, fid, &oic->oic_lid);
4154 fid_zero(&oic->oic_fid);
4158 osd_id_gen(&oic->oic_lid, ino, OSD_OII_NOGEN);
4161 osd_it_pack_dirent(lde, fid, it->oie_dirent->oied_off,
4162 it->oie_dirent->oied_name,
4163 it->oie_dirent->oied_namelen,
4164 it->oie_dirent->oied_type, attr);
4165 oic->oic_fid = *fid;
4166 if ((scrub->os_pos_current <= ino) &&
4167 (sf->sf_flags & SF_INCONSISTENT ||
4168 ldiskfs_test_bit(osd_oi_fid2idx(dev, fid), sf->sf_oi_bitmap)))
4169 osd_consistency_check(oti, dev, oic);
4175 * Returns a cookie for current position of the iterator head, so that
4176 * user can use this cookie to load/start the iterator next time.
4178 * \param di iterator's in memory structure
4180 * \retval cookie for current position, on success
4182 static __u64 osd_it_ea_store(const struct lu_env *env, const struct dt_it *di)
4184 struct osd_it_ea *it = (struct osd_it_ea *)di;
4186 return it->oie_dirent->oied_off;
4190 * It calls osd_ldiskfs_it_fill() which will use ->readdir()
4191 * to load a directory entry at a time and stored it i inn,
4192 * in iterator's in-memory data structure.
4194 * \param di struct osd_it_ea, iterator's in memory structure
4196 * \retval +ve on success
4197 * \retval -ve on error
4199 static int osd_it_ea_load(const struct lu_env *env,
4200 const struct dt_it *di, __u64 hash)
4202 struct osd_it_ea *it = (struct osd_it_ea *)di;
4206 it->oie_file.f_pos = hash;
4208 rc = osd_ldiskfs_it_fill(env, di);
4216 * Index lookup function for interoperability mode (b11826).
4218 * \param key, key i.e. file name to be searched
4220 * \retval +ve, on success
4221 * \retval -ve, on error
4223 static int osd_index_ea_lookup(const struct lu_env *env, struct dt_object *dt,
4224 struct dt_rec *rec, const struct dt_key *key,
4225 struct lustre_capa *capa)
4227 struct osd_object *obj = osd_dt_obj(dt);
4232 LASSERT(S_ISDIR(obj->oo_inode->i_mode));
4233 LINVRNT(osd_invariant(obj));
4235 if (osd_object_auth(env, dt, capa, CAPA_OPC_INDEX_LOOKUP))
4238 rc = osd_ea_lookup_rec(env, obj, rec, key);
4245 * Index and Iterator operations for interoperability
4246 * mode (i.e. to run 2.0 mds on 1.8 disk) (b11826)
4248 static const struct dt_index_operations osd_index_ea_ops = {
4249 .dio_lookup = osd_index_ea_lookup,
4250 .dio_declare_insert = osd_index_declare_ea_insert,
4251 .dio_insert = osd_index_ea_insert,
4252 .dio_declare_delete = osd_index_declare_ea_delete,
4253 .dio_delete = osd_index_ea_delete,
4255 .init = osd_it_ea_init,
4256 .fini = osd_it_ea_fini,
4257 .get = osd_it_ea_get,
4258 .put = osd_it_ea_put,
4259 .next = osd_it_ea_next,
4260 .key = osd_it_ea_key,
4261 .key_size = osd_it_ea_key_size,
4262 .rec = osd_it_ea_rec,
4263 .store = osd_it_ea_store,
4264 .load = osd_it_ea_load
4268 static void *osd_key_init(const struct lu_context *ctx,
4269 struct lu_context_key *key)
4271 struct osd_thread_info *info;
4273 OBD_ALLOC_PTR(info);
4275 return ERR_PTR(-ENOMEM);
4277 OBD_ALLOC(info->oti_it_ea_buf, OSD_IT_EA_BUFSIZE);
4278 if (info->oti_it_ea_buf == NULL)
4281 info->oti_env = container_of(ctx, struct lu_env, le_ctx);
4283 info->oti_hlock = ldiskfs_htree_lock_alloc();
4284 if (info->oti_hlock == NULL)
4290 OBD_FREE(info->oti_it_ea_buf, OSD_IT_EA_BUFSIZE);
4293 return ERR_PTR(-ENOMEM);
4296 static void osd_key_fini(const struct lu_context *ctx,
4297 struct lu_context_key *key, void* data)
4299 struct osd_thread_info *info = data;
4301 if (info->oti_hlock != NULL)
4302 ldiskfs_htree_lock_free(info->oti_hlock);
4303 OBD_FREE(info->oti_it_ea_buf, OSD_IT_EA_BUFSIZE);
4307 static void osd_key_exit(const struct lu_context *ctx,
4308 struct lu_context_key *key, void *data)
4310 struct osd_thread_info *info = data;
4312 LASSERT(info->oti_r_locks == 0);
4313 LASSERT(info->oti_w_locks == 0);
4314 LASSERT(info->oti_txns == 0);
4317 /* type constructor/destructor: osd_type_init, osd_type_fini */
4318 LU_TYPE_INIT_FINI(osd, &osd_key);
4320 struct lu_context_key osd_key = {
4321 .lct_tags = LCT_DT_THREAD | LCT_MD_THREAD | LCT_MG_THREAD | LCT_LOCAL,
4322 .lct_init = osd_key_init,
4323 .lct_fini = osd_key_fini,
4324 .lct_exit = osd_key_exit
4328 static int osd_device_init(const struct lu_env *env, struct lu_device *d,
4329 const char *name, struct lu_device *next)
4331 struct osd_device *osd = osd_dev(d);
4333 strncpy(osd->od_svname, name, MAX_OBD_NAME);
4334 return osd_procfs_init(osd, name);
4337 static int osd_shutdown(const struct lu_env *env, struct osd_device *o)
4341 osd_scrub_cleanup(env, o);
4344 fsfilt_put_ops(o->od_fsops);
4348 /* shutdown quota slave instance associated with the device */
4349 if (o->od_quota_slave != NULL) {
4350 qsd_fini(env, o->od_quota_slave);
4351 o->od_quota_slave = NULL;
4357 static int osd_mount(const struct lu_env *env,
4358 struct osd_device *o, struct lustre_cfg *cfg)
4360 const char *name = lustre_cfg_string(cfg, 0);
4361 const char *dev = lustre_cfg_string(cfg, 1);
4363 unsigned long page, s_flags, lmd_flags = 0;
4364 struct page *__page;
4365 struct file_system_type *type;
4366 char *options = NULL;
4371 if (o->od_mnt != NULL)
4374 o->od_fsops = fsfilt_get_ops(mt_str(LDD_MT_LDISKFS));
4375 if (o->od_fsops == NULL) {
4376 CERROR("Can't find fsfilt_ldiskfs\n");
4380 OBD_PAGE_ALLOC(__page, CFS_ALLOC_STD);
4382 GOTO(out, rc = -ENOMEM);
4384 str = lustre_cfg_string(cfg, 2);
4385 s_flags = simple_strtoul(str, NULL, 0);
4386 str = strstr(str, ":");
4388 lmd_flags = simple_strtoul(str + 1, NULL, 0);
4389 opts = lustre_cfg_string(cfg, 3);
4390 page = (unsigned long)cfs_page_address(__page);
4391 options = (char *)page;
4394 strcat(options, "user_xattr,acl");
4396 strcat(options, opts);
4398 /* Glom up mount options */
4399 if (*options != '\0')
4400 strcat(options, ",");
4401 strlcat(options, "no_mbcache", CFS_PAGE_SIZE);
4403 type = get_fs_type("ldiskfs");
4405 CERROR("%s: cannot find ldiskfs module\n", name);
4406 GOTO(out, rc = -ENODEV);
4409 o->od_mnt = vfs_kern_mount(type, s_flags, dev, options);
4410 cfs_module_put(type->owner);
4412 if (IS_ERR(o->od_mnt)) {
4413 rc = PTR_ERR(o->od_mnt);
4414 CERROR("%s: can't mount %s: %d\n", name, dev, rc);
4419 if (lvfs_check_rdonly(o->od_mnt->mnt_sb->s_bdev)) {
4420 CERROR("%s: underlying device %s is marked as read-only. "
4421 "Setup failed\n", name, dev);
4424 GOTO(out, rc = -EROFS);
4427 if (!LDISKFS_HAS_COMPAT_FEATURE(o->od_mnt->mnt_sb,
4428 LDISKFS_FEATURE_COMPAT_HAS_JOURNAL)) {
4429 CERROR("%s: device %s is mounted w/o journal\n", name, dev);
4432 GOTO(out, rc = -EINVAL);
4435 if (lmd_flags & LMD_FLG_NOSCRUB)
4440 OBD_PAGE_FREE(__page);
4442 fsfilt_put_ops(o->od_fsops);
4447 static struct lu_device *osd_device_fini(const struct lu_env *env,
4448 struct lu_device *d)
4453 rc = osd_shutdown(env, osd_dev(d));
4455 osd_compat_fini(osd_dev(d));
4457 shrink_dcache_sb(osd_sb(osd_dev(d)));
4458 osd_sync(env, lu2dt_dev(d));
4460 rc = osd_procfs_fini(osd_dev(d));
4462 CERROR("proc fini error %d \n", rc);
4463 RETURN (ERR_PTR(rc));
4466 if (osd_dev(d)->od_mnt) {
4467 mntput(osd_dev(d)->od_mnt);
4468 osd_dev(d)->od_mnt = NULL;
4474 static int osd_device_init0(const struct lu_env *env,
4475 struct osd_device *o,
4476 struct lustre_cfg *cfg)
4478 struct lu_device *l = osd2lu_dev(o);
4479 struct osd_thread_info *info;
4482 /* if the module was re-loaded, env can loose its keys */
4483 rc = lu_env_refill((struct lu_env *) env);
4486 info = osd_oti_get(env);
4489 l->ld_ops = &osd_lu_ops;
4490 o->od_dt_dev.dd_ops = &osd_dt_ops;
4492 cfs_spin_lock_init(&o->od_osfs_lock);
4493 cfs_mutex_init(&o->od_otable_mutex);
4494 o->od_osfs_age = cfs_time_shift_64(-1000);
4496 o->od_capa_hash = init_capa_hash();
4497 if (o->od_capa_hash == NULL)
4498 GOTO(out, rc = -ENOMEM);
4500 o->od_read_cache = 1;
4501 o->od_writethrough_cache = 1;
4502 o->od_readcache_max_filesize = OSD_MAX_CACHE_SIZE;
4504 rc = osd_mount(env, o, cfg);
4508 /* setup scrub, including OI files initialization */
4509 rc = osd_scrub_setup(env, o);
4513 strncpy(o->od_svname, lustre_cfg_string(cfg, 4),
4514 sizeof(o->od_svname) - 1);
4516 rc = osd_compat_init(o);
4518 GOTO(out_scrub, rc);
4520 rc = lu_site_init(&o->od_site, l);
4522 GOTO(out_compat, rc);
4523 o->od_site.ls_bottom_dev = l;
4525 rc = lu_site_init_finish(&o->od_site);
4529 rc = osd_procfs_init(o, o->od_svname);
4531 CERROR("%s: can't initialize procfs: rc = %d\n",
4536 LASSERT(l->ld_site->ls_linkage.next && l->ld_site->ls_linkage.prev);
4538 /* initialize quota slave instance */
4539 o->od_quota_slave = qsd_init(env, o->od_svname, &o->od_dt_dev,
4541 if (IS_ERR(o->od_quota_slave)) {
4542 rc = PTR_ERR(o->od_quota_slave);
4543 o->od_quota_slave = NULL;
4544 GOTO(out_procfs, rc);
4551 lu_site_fini(&o->od_site);
4555 osd_scrub_cleanup(env, o);
4557 osd_oi_fini(info, o);
4558 osd_shutdown(env, o);
4562 cleanup_capa_hash(o->od_capa_hash);
4567 static struct lu_device *osd_device_alloc(const struct lu_env *env,
4568 struct lu_device_type *t,
4569 struct lustre_cfg *cfg)
4571 struct osd_device *o;
4576 return ERR_PTR(-ENOMEM);
4578 rc = dt_device_init(&o->od_dt_dev, t);
4580 rc = osd_device_init0(env, o, cfg);
4582 dt_device_fini(&o->od_dt_dev);
4585 if (unlikely(rc != 0))
4588 return rc == 0 ? osd2lu_dev(o) : ERR_PTR(rc);
4591 static struct lu_device *osd_device_free(const struct lu_env *env,
4592 struct lu_device *d)
4594 struct osd_device *o = osd_dev(d);
4597 cleanup_capa_hash(o->od_capa_hash);
4598 /* XXX: make osd top device in order to release reference */
4599 d->ld_site->ls_top_dev = d;
4600 lu_site_purge(env, d->ld_site, -1);
4601 if (!cfs_hash_is_empty(d->ld_site->ls_obj_hash)) {
4602 LIBCFS_DEBUG_MSG_DATA_DECL(msgdata, D_ERROR, NULL);
4603 lu_site_print(env, d->ld_site, &msgdata, lu_cdebug_printer);
4605 lu_site_fini(&o->od_site);
4606 dt_device_fini(&o->od_dt_dev);
4611 static int osd_process_config(const struct lu_env *env,
4612 struct lu_device *d, struct lustre_cfg *cfg)
4614 struct osd_device *o = osd_dev(d);
4618 switch(cfg->lcfg_command) {
4620 err = osd_mount(env, o, cfg);
4623 lu_dev_del_linkage(d->ld_site, d);
4624 err = osd_shutdown(env, o);
4633 static int osd_recovery_complete(const struct lu_env *env,
4634 struct lu_device *d)
4636 struct osd_device *osd = osd_dev(d);
4640 if (osd->od_quota_slave == NULL)
4643 /* start qsd instance on recovery completion, this notifies the quota
4644 * slave code that we are about to process new requests now */
4645 rc = qsd_start(env, osd->od_quota_slave);
4650 * we use exports to track all osd users
4652 static int osd_obd_connect(const struct lu_env *env, struct obd_export **exp,
4653 struct obd_device *obd, struct obd_uuid *cluuid,
4654 struct obd_connect_data *data, void *localdata)
4656 struct osd_device *osd = osd_dev(obd->obd_lu_dev);
4657 struct lustre_handle conn;
4661 CDEBUG(D_CONFIG, "connect #%d\n", osd->od_connects);
4663 rc = class_connect(&conn, obd, cluuid);
4667 *exp = class_conn2export(&conn);
4669 cfs_spin_lock(&osd->od_osfs_lock);
4671 cfs_spin_unlock(&osd->od_osfs_lock);
4677 * once last export (we don't count self-export) disappeared
4678 * osd can be released
4680 static int osd_obd_disconnect(struct obd_export *exp)
4682 struct obd_device *obd = exp->exp_obd;
4683 struct osd_device *osd = osd_dev(obd->obd_lu_dev);
4684 int rc, release = 0;
4687 /* Only disconnect the underlying layers on the final disconnect. */
4688 cfs_spin_lock(&osd->od_osfs_lock);
4690 if (osd->od_connects == 0)
4692 cfs_spin_unlock(&osd->od_osfs_lock);
4694 rc = class_disconnect(exp); /* bz 9811 */
4696 if (rc == 0 && release)
4697 class_manual_cleanup(obd);
4701 static int osd_prepare(const struct lu_env *env, struct lu_device *pdev,
4702 struct lu_device *dev)
4704 struct osd_device *osd = osd_dev(dev);
4708 if (dev->ld_site && lu_device_is_md(dev->ld_site->ls_top_dev)) {
4709 /* MDT/MDD still use old infrastructure to create
4711 result = llo_local_objects_setup(env, lu2md_dev(pdev),
4717 if (osd->od_quota_slave != NULL)
4718 /* set up quota slave objects */
4719 result = qsd_prepare(env, osd->od_quota_slave);
4724 static const struct lu_object_operations osd_lu_obj_ops = {
4725 .loo_object_init = osd_object_init,
4726 .loo_object_delete = osd_object_delete,
4727 .loo_object_release = osd_object_release,
4728 .loo_object_free = osd_object_free,
4729 .loo_object_print = osd_object_print,
4730 .loo_object_invariant = osd_object_invariant
4733 const struct lu_device_operations osd_lu_ops = {
4734 .ldo_object_alloc = osd_object_alloc,
4735 .ldo_process_config = osd_process_config,
4736 .ldo_recovery_complete = osd_recovery_complete,
4737 .ldo_prepare = osd_prepare,
4740 static const struct lu_device_type_operations osd_device_type_ops = {
4741 .ldto_init = osd_type_init,
4742 .ldto_fini = osd_type_fini,
4744 .ldto_start = osd_type_start,
4745 .ldto_stop = osd_type_stop,
4747 .ldto_device_alloc = osd_device_alloc,
4748 .ldto_device_free = osd_device_free,
4750 .ldto_device_init = osd_device_init,
4751 .ldto_device_fini = osd_device_fini
4754 struct lu_device_type osd_device_type = {
4755 .ldt_tags = LU_DEVICE_DT,
4756 .ldt_name = LUSTRE_OSD_LDISKFS_NAME,
4757 .ldt_ops = &osd_device_type_ops,
4758 .ldt_ctx_tags = LCT_LOCAL,
4762 * lprocfs legacy support.
4764 static struct obd_ops osd_obd_device_ops = {
4765 .o_owner = THIS_MODULE,
4766 .o_connect = osd_obd_connect,
4767 .o_disconnect = osd_obd_disconnect
4770 static int __init osd_mod_init(void)
4772 struct lprocfs_static_vars lvars;
4775 lprocfs_osd_init_vars(&lvars);
4776 return class_register_type(&osd_obd_device_ops, NULL, lvars.module_vars,
4777 LUSTRE_OSD_LDISKFS_NAME, &osd_device_type);
4780 static void __exit osd_mod_exit(void)
4782 class_unregister_type(LUSTRE_OSD_LDISKFS_NAME);
4785 MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");
4786 MODULE_DESCRIPTION("Lustre Object Storage Device ("LUSTRE_OSD_LDISKFS_NAME")");
4787 MODULE_LICENSE("GPL");
4789 cfs_module(osd, "0.1.0", osd_mod_init, osd_mod_exit);