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 /* dt_acct_features */
78 #ifdef HAVE_LDISKFS_PDO
80 CFS_MODULE_PARM(ldiskfs_pdo, "i", int, 0644,
81 "ldiskfs with parallel directory operations");
86 static const char dot[] = ".";
87 static const char dotdot[] = "..";
88 static const char remote_obj_dir[] = "REM_OBJ_DIR";
90 static const struct lu_object_operations osd_lu_obj_ops;
91 static const struct dt_object_operations osd_obj_ops;
92 static const struct dt_object_operations osd_obj_ea_ops;
93 static const struct dt_object_operations osd_obj_otable_it_ops;
94 static const struct dt_index_operations osd_index_iam_ops;
95 static const struct dt_index_operations osd_index_ea_ops;
97 static int osd_has_index(const struct osd_object *obj)
99 return obj->oo_dt.do_index_ops != NULL;
102 static int osd_object_invariant(const struct lu_object *l)
104 return osd_invariant(osd_obj(l));
107 #ifdef HAVE_QUOTA_SUPPORT
109 osd_push_ctxt(const struct lu_env *env, struct osd_ctxt *save, bool is_md)
122 save->oc_uid = current_fsuid();
123 save->oc_gid = current_fsgid();
124 save->oc_cap = current_cap();
125 if ((tc = prepare_creds())) {
126 tc->fsuid = uc->mu_fsuid;
127 tc->fsgid = uc->mu_fsgid;
130 /* XXX not suboptimal */
131 cfs_curproc_cap_unpack(uc->mu_cap);
135 osd_pop_ctxt(struct osd_ctxt *save, bool is_md)
143 if ((tc = prepare_creds())) {
144 tc->fsuid = save->oc_uid;
145 tc->fsgid = save->oc_gid;
146 tc->cap_effective = save->oc_cap;
153 * Concurrency: doesn't matter
155 static int osd_read_locked(const struct lu_env *env, struct osd_object *o)
157 return osd_oti_get(env)->oti_r_locks > 0;
161 * Concurrency: doesn't matter
163 static int osd_write_locked(const struct lu_env *env, struct osd_object *o)
165 struct osd_thread_info *oti = osd_oti_get(env);
166 return oti->oti_w_locks > 0 && o->oo_owner == env;
170 * Concurrency: doesn't access mutable data
172 static int osd_root_get(const struct lu_env *env,
173 struct dt_device *dev, struct lu_fid *f)
175 lu_local_obj_fid(f, OSD_FS_ROOT_OID);
180 * OSD object methods.
184 * Concurrency: no concurrent access is possible that early in object
187 static struct lu_object *osd_object_alloc(const struct lu_env *env,
188 const struct lu_object_header *hdr,
191 struct osd_object *mo;
197 l = &mo->oo_dt.do_lu;
198 dt_object_init(&mo->oo_dt, NULL, d);
199 if (osd_dev(d)->od_iop_mode)
200 mo->oo_dt.do_ops = &osd_obj_ea_ops;
202 mo->oo_dt.do_ops = &osd_obj_ops;
204 l->lo_ops = &osd_lu_obj_ops;
205 cfs_init_rwsem(&mo->oo_sem);
206 cfs_init_rwsem(&mo->oo_ext_idx_sem);
207 cfs_spin_lock_init(&mo->oo_guard);
214 static int osd_get_lma(struct inode *inode, struct dentry *dentry,
215 struct lustre_mdt_attrs *lma)
219 dentry->d_inode = inode;
220 rc = inode->i_op->getxattr(dentry, XATTR_NAME_LMA, (void *)lma,
223 /* Check LMA compatibility */
224 if (lma->lma_incompat & ~cpu_to_le32(LMA_INCOMPAT_SUPP)) {
225 CWARN("%.16s: unsupported incompat LMA feature(s) "
227 LDISKFS_SB(inode->i_sb)->s_es->s_volume_name,
228 inode->i_ino, le32_to_cpu(lma->lma_incompat) &
232 lustre_lma_swab(lma);
235 } else if (rc == 0) {
243 * retrieve object from backend ext fs.
245 struct inode *osd_iget(struct osd_thread_info *info, struct osd_device *dev,
246 struct osd_inode_id *id)
248 struct inode *inode = NULL;
250 inode = ldiskfs_iget(osd_sb(dev), id->oii_ino);
252 CDEBUG(D_INODE, "no inode: ino = %u, rc = %ld\n",
253 id->oii_ino, PTR_ERR(inode));
254 } else if (id->oii_gen != OSD_OII_NOGEN &&
255 inode->i_generation != id->oii_gen) {
256 CDEBUG(D_INODE, "unmatched inode: ino = %u, gen0 = %u, "
258 id->oii_ino, id->oii_gen, inode->i_generation);
260 inode = ERR_PTR(-ESTALE);
261 } else if (inode->i_nlink == 0) {
262 /* due to parallel readdir and unlink,
263 * we can have dead inode here. */
264 CDEBUG(D_INODE, "stale inode: ino = %u\n", id->oii_ino);
265 make_bad_inode(inode);
267 inode = ERR_PTR(-ESTALE);
268 } else if (is_bad_inode(inode)) {
269 CWARN("%.16s: bad inode: ino = %u\n",
270 LDISKFS_SB(osd_sb(dev))->s_es->s_volume_name, id->oii_ino);
272 inode = ERR_PTR(-ENOENT);
274 if (id->oii_gen == OSD_OII_NOGEN)
275 osd_id_gen(id, inode->i_ino, inode->i_generation);
277 /* Do not update file c/mtime in ldiskfs.
278 * NB: we don't have any lock to protect this because we don't
279 * have reference on osd_object now, but contention with
280 * another lookup + attr_set can't happen in the tiny window
281 * between if (...) and set S_NOCMTIME. */
282 if (!(inode->i_flags & S_NOCMTIME))
283 inode->i_flags |= S_NOCMTIME;
288 struct inode *osd_iget_fid(struct osd_thread_info *info, struct osd_device *dev,
289 struct osd_inode_id *id, struct lu_fid *fid)
291 struct lustre_mdt_attrs *lma = &info->oti_mdt_attrs;
295 inode = osd_iget(info, dev, id);
299 rc = osd_get_lma(inode, &info->oti_obj_dentry, lma);
301 *fid = lma->lma_self_fid;
302 } else if (rc == -ENODATA) {
303 LU_IGIF_BUILD(fid, inode->i_ino, inode->i_generation);
311 static struct inode *
312 osd_iget_verify(struct osd_thread_info *info, struct osd_device *dev,
313 struct osd_inode_id *id, const struct lu_fid *fid)
315 struct lustre_mdt_attrs *lma = &info->oti_mdt_attrs;
319 inode = osd_iget(info, dev, id);
323 rc = osd_get_lma(inode, &info->oti_obj_dentry, lma);
325 if (rc == -ENODATA) {
326 CDEBUG(D_LFSCK, "inconsistent obj: NULL, %lu, "DFID"\n",
327 inode->i_ino, PFID(fid));
334 if (!lu_fid_eq(fid, &lma->lma_self_fid)) {
335 CDEBUG(D_LFSCK, "inconsistent obj: "DFID", %lu, "DFID"\n",
336 PFID(&lma->lma_self_fid), inode->i_ino, PFID(fid));
338 return ERR_PTR(EREMCHG);
343 static int osd_fid_lookup(const struct lu_env *env, struct osd_object *obj,
344 const struct lu_fid *fid,
345 const struct lu_object_conf *conf)
347 struct osd_thread_info *info;
348 struct lu_device *ldev = obj->oo_dt.do_lu.lo_dev;
349 struct osd_device *dev;
350 struct osd_idmap_cache *oic;
351 struct osd_inode_id *id;
353 struct osd_scrub *scrub;
354 struct scrub_file *sf;
359 LINVRNT(osd_invariant(obj));
360 LASSERT(obj->oo_inode == NULL);
361 LASSERTF(fid_is_sane(fid) || fid_is_idif(fid), DFID, PFID(fid));
364 scrub = &dev->od_scrub;
365 sf = &scrub->os_file;
366 info = osd_oti_get(env);
368 oic = &info->oti_cache;
371 if (OBD_FAIL_CHECK(OBD_FAIL_OST_ENOENT))
374 if (fid_is_norm(fid)) {
375 /* Search order: 1. per-thread cache. */
376 if (lu_fid_eq(fid, &oic->oic_fid)) {
378 } else if (!cfs_list_empty(&scrub->os_inconsistent_items)) {
379 /* Search order: 2. OI scrub pending list. */
380 result = osd_oii_lookup(dev, fid, id);
385 if (sf->sf_flags & SF_INCONSISTENT)
390 * Objects are created as locking anchors or place holders for objects
391 * yet to be created. No need to osd_oi_lookup() at here because FID
392 * shouldn't never be re-used, if it's really a duplicate FID from
393 * unexpected reason, we should be able to detect it later by calling
394 * do_create->osd_oi_insert()
396 if (conf != NULL && (conf->loc_flags & LOC_F_NEW) != 0)
397 GOTO(out, result = 0);
399 /* Search order: 3. OI files. */
400 result = osd_oi_lookup(info, dev, fid, id);
401 if (result == -ENOENT) {
402 if (!fid_is_norm(fid) ||
403 !ldiskfs_test_bit(osd_oi_fid2idx(dev,fid),
405 GOTO(out, result = 0);
415 inode = osd_iget(info, dev, id);
417 inode = osd_iget_verify(info, dev, id, fid);
419 result = PTR_ERR(inode);
420 if (result == -ENOENT || result == -ESTALE) {
421 fid_zero(&oic->oic_fid);
423 } else if (result == -EREMCHG) {
426 if (thread_is_running(&scrub->os_thread)) {
427 result = -EINPROGRESS;
428 } else if (!scrub->os_no_scrub) {
429 result = osd_scrub_start(dev);
430 LCONSOLE_ERROR("%.16s: trigger OI scrub by RPC "
431 "for "DFID", rc = %d [1]\n",
432 LDISKFS_SB(osd_sb(dev))->s_es->\
433 s_volume_name,PFID(fid), result);
434 if (result == 0 || result == -EALREADY)
435 result = -EINPROGRESS;
444 obj->oo_inode = inode;
445 LASSERT(obj->oo_inode->i_sb == osd_sb(dev));
446 if (dev->od_iop_mode) {
447 obj->oo_compat_dot_created = 1;
448 obj->oo_compat_dotdot_created = 1;
451 if (!S_ISDIR(inode->i_mode) || !ldiskfs_pdo) /* done */
452 GOTO(out, result = 0);
454 LASSERT(obj->oo_hl_head == NULL);
455 obj->oo_hl_head = ldiskfs_htree_lock_head_alloc(HTREE_HBITS_DEF);
456 if (obj->oo_hl_head == NULL) {
457 obj->oo_inode = NULL;
459 GOTO(out, result = -ENOMEM);
461 GOTO(out, result = 0);
464 LINVRNT(osd_invariant(obj));
469 * Concurrency: shouldn't matter.
471 static void osd_object_init0(struct osd_object *obj)
473 LASSERT(obj->oo_inode != NULL);
474 obj->oo_dt.do_body_ops = &osd_body_ops;
475 obj->oo_dt.do_lu.lo_header->loh_attr |=
476 (LOHA_EXISTS | (obj->oo_inode->i_mode & S_IFMT));
480 * Concurrency: no concurrent access is possible that early in object
483 static int osd_object_init(const struct lu_env *env, struct lu_object *l,
484 const struct lu_object_conf *conf)
486 struct osd_object *obj = osd_obj(l);
489 LINVRNT(osd_invariant(obj));
491 result = osd_fid_lookup(env, obj, lu_object_fid(l), conf);
492 obj->oo_dt.do_body_ops = &osd_body_ops_new;
494 if (obj->oo_inode != NULL) {
495 osd_object_init0(obj);
496 } else if (fid_is_otable_it(&l->lo_header->loh_fid)) {
497 obj->oo_dt.do_ops = &osd_obj_otable_it_ops;
498 /* LFSCK iterator object is special without inode */
499 l->lo_header->loh_attr |= LOHA_EXISTS;
502 LINVRNT(osd_invariant(obj));
507 * Concurrency: no concurrent access is possible that late in object
510 static void osd_object_free(const struct lu_env *env, struct lu_object *l)
512 struct osd_object *obj = osd_obj(l);
514 LINVRNT(osd_invariant(obj));
516 dt_object_fini(&obj->oo_dt);
517 if (obj->oo_hl_head != NULL)
518 ldiskfs_htree_lock_head_free(obj->oo_hl_head);
523 * Concurrency: no concurrent access is possible that late in object
526 static void osd_index_fini(struct osd_object *o)
528 struct iam_container *bag;
530 if (o->oo_dir != NULL) {
531 bag = &o->oo_dir->od_container;
532 if (o->oo_inode != NULL) {
533 if (bag->ic_object == o->oo_inode)
534 iam_container_fini(bag);
536 OBD_FREE_PTR(o->oo_dir);
542 * Concurrency: no concurrent access is possible that late in object
543 * life-cycle (for all existing callers, that is. New callers have to provide
544 * their own locking.)
546 static int osd_inode_unlinked(const struct inode *inode)
548 return inode->i_nlink == 0;
552 OSD_TXN_OI_DELETE_CREDITS = 20,
553 OSD_TXN_INODE_DELETE_CREDITS = 20
560 #if OSD_THANDLE_STATS
562 * Set time when the handle is allocated
564 static void osd_th_alloced(struct osd_thandle *oth)
566 oth->oth_alloced = cfs_time_current();
570 * Set time when the handle started
572 static void osd_th_started(struct osd_thandle *oth)
574 oth->oth_started = cfs_time_current();
578 * Helper function to convert time interval to microseconds packed in
579 * long int (default time units for the counter in "stats" initialized
580 * by lu_time_init() )
582 static long interval_to_usec(cfs_time_t start, cfs_time_t end)
586 cfs_duration_usec(cfs_time_sub(end, start), &val);
587 return val.tv_sec * 1000000 + val.tv_usec;
591 * Check whether the we deal with this handle for too long.
593 static void __osd_th_check_slow(void *oth, struct osd_device *dev,
594 cfs_time_t alloced, cfs_time_t started,
597 cfs_time_t now = cfs_time_current();
599 LASSERT(dev != NULL);
601 lprocfs_counter_add(dev->od_stats, LPROC_OSD_THANDLE_STARTING,
602 interval_to_usec(alloced, started));
603 lprocfs_counter_add(dev->od_stats, LPROC_OSD_THANDLE_OPEN,
604 interval_to_usec(started, closed));
605 lprocfs_counter_add(dev->od_stats, LPROC_OSD_THANDLE_CLOSING,
606 interval_to_usec(closed, now));
608 if (cfs_time_before(cfs_time_add(alloced, cfs_time_seconds(30)), now)) {
609 CWARN("transaction handle %p was open for too long: "
611 "alloced "CFS_TIME_T" ,"
612 "started "CFS_TIME_T" ,"
613 "closed "CFS_TIME_T"\n",
614 oth, now, alloced, started, closed);
615 libcfs_debug_dumpstack(NULL);
619 #define OSD_CHECK_SLOW_TH(oth, dev, expr) \
621 cfs_time_t __closed = cfs_time_current(); \
622 cfs_time_t __alloced = oth->oth_alloced; \
623 cfs_time_t __started = oth->oth_started; \
626 __osd_th_check_slow(oth, dev, __alloced, __started, __closed); \
629 #else /* OSD_THANDLE_STATS */
631 #define osd_th_alloced(h) do {} while(0)
632 #define osd_th_started(h) do {} while(0)
633 #define OSD_CHECK_SLOW_TH(oth, dev, expr) expr
635 #endif /* OSD_THANDLE_STATS */
638 * Concurrency: doesn't access mutable data.
640 static int osd_param_is_sane(const struct osd_device *dev,
641 const struct thandle *th)
643 struct osd_thandle *oh;
644 oh = container_of0(th, struct osd_thandle, ot_super);
645 return oh->ot_credits <= osd_journal(dev)->j_max_transaction_buffers;
649 * Concurrency: shouldn't matter.
651 #ifdef HAVE_LDISKFS_JOURNAL_CALLBACK_ADD
652 static void osd_trans_commit_cb(struct super_block *sb,
653 struct journal_callback *jcb, int error)
655 static void osd_trans_commit_cb(struct journal_callback *jcb, int error)
658 struct osd_thandle *oh = container_of0(jcb, struct osd_thandle, ot_jcb);
659 struct thandle *th = &oh->ot_super;
660 struct lu_device *lud = &th->th_dev->dd_lu_dev;
661 struct dt_txn_commit_cb *dcb, *tmp;
663 LASSERT(oh->ot_handle == NULL);
666 CERROR("transaction @0x%p commit error: %d\n", th, error);
668 dt_txn_hook_commit(th);
670 /* call per-transaction callbacks if any */
671 cfs_list_for_each_entry_safe(dcb, tmp, &oh->ot_dcb_list, dcb_linkage) {
672 LASSERTF(dcb->dcb_magic == TRANS_COMMIT_CB_MAGIC,
673 "commit callback entry: magic=%x name='%s'\n",
674 dcb->dcb_magic, dcb->dcb_name);
675 cfs_list_del_init(&dcb->dcb_linkage);
676 dcb->dcb_func(NULL, th, dcb, error);
679 lu_ref_del_at(&lud->ld_reference, oh->ot_dev_link, "osd-tx", th);
683 lu_context_exit(&th->th_ctx);
684 lu_context_fini(&th->th_ctx);
688 static struct thandle *osd_trans_create(const struct lu_env *env,
691 struct osd_thread_info *oti = osd_oti_get(env);
692 struct osd_iobuf *iobuf = &oti->oti_iobuf;
693 struct osd_thandle *oh;
697 /* on pending IO in this thread should left from prev. request */
698 LASSERT(cfs_atomic_read(&iobuf->dr_numreqs) == 0);
700 th = ERR_PTR(-ENOMEM);
701 OBD_ALLOC_GFP(oh, sizeof *oh, CFS_ALLOC_IO);
703 oh->ot_quota_trans = &oti->oti_quota_trans;
704 memset(oh->ot_quota_trans, 0, sizeof(*oh->ot_quota_trans));
708 th->th_tags = LCT_TX_HANDLE;
710 oti->oti_dev = osd_dt_dev(d);
711 CFS_INIT_LIST_HEAD(&oh->ot_dcb_list);
718 * Concurrency: shouldn't matter.
720 int osd_trans_start(const struct lu_env *env, struct dt_device *d,
723 struct osd_thread_info *oti = osd_oti_get(env);
724 struct osd_device *dev = osd_dt_dev(d);
726 struct osd_thandle *oh;
731 LASSERT(current->journal_info == NULL);
733 oh = container_of0(th, struct osd_thandle, ot_super);
735 LASSERT(oh->ot_handle == NULL);
737 rc = dt_txn_hook_start(env, d, th);
741 if (!osd_param_is_sane(dev, th)) {
742 CWARN("%.16s: too many transaction credits (%d > %d)\n",
743 LDISKFS_SB(osd_sb(dev))->s_es->s_volume_name,
745 osd_journal(dev)->j_max_transaction_buffers);
746 /* XXX Limit the credits to 'max_transaction_buffers', and
747 * let the underlying filesystem to catch the error if
748 * we really need so many credits.
750 * This should be removed when we can calculate the
751 * credits precisely. */
752 oh->ot_credits = osd_journal(dev)->j_max_transaction_buffers;
753 #ifdef OSD_TRACK_DECLARES
754 CERROR(" attr_set: %d, punch: %d, xattr_set: %d,\n",
755 oh->ot_declare_attr_set, oh->ot_declare_punch,
756 oh->ot_declare_xattr_set);
757 CERROR(" create: %d, ref_add: %d, ref_del: %d, write: %d\n",
758 oh->ot_declare_create, oh->ot_declare_ref_add,
759 oh->ot_declare_ref_del, oh->ot_declare_write);
760 CERROR(" insert: %d, delete: %d, destroy: %d\n",
761 oh->ot_declare_insert, oh->ot_declare_delete,
762 oh->ot_declare_destroy);
767 * XXX temporary stuff. Some abstraction layer should
770 jh = ldiskfs_journal_start_sb(osd_sb(dev), oh->ot_credits);
774 LASSERT(oti->oti_txns == 0);
775 lu_context_init(&th->th_ctx, th->th_tags);
776 lu_context_enter(&th->th_ctx);
778 lu_device_get(&d->dd_lu_dev);
779 oh->ot_dev_link = lu_ref_add(&d->dd_lu_dev.ld_reference,
783 * XXX: current rule is that we first start tx,
784 * then lock object(s), but we can't use
785 * this rule for data (due to locking specifics
786 * in ldiskfs). also in long-term we'd like to
787 * use usually-used (locks;tx) ordering. so,
788 * UGLY thing is that we'll use one ordering for
789 * data (ofd) and reverse ordering for metadata
790 * (mdd). then at some point we'll fix the latter
793 LASSERT(oti->oti_r_locks == 0);
794 LASSERT(oti->oti_w_locks == 0);
807 * Concurrency: shouldn't matter.
809 static int osd_trans_stop(const struct lu_env *env, struct thandle *th)
812 struct osd_thandle *oh;
813 struct osd_thread_info *oti = osd_oti_get(env);
814 struct osd_iobuf *iobuf = &oti->oti_iobuf;
815 struct qsd_instance *qsd = oti->oti_dev->od_quota_slave;
818 oh = container_of0(th, struct osd_thandle, ot_super);
821 /* inform the quota slave device that the transaction is
823 qsd_op_end(env, qsd, oh->ot_quota_trans);
824 oh->ot_quota_trans = NULL;
826 if (oh->ot_handle != NULL) {
827 handle_t *hdl = oh->ot_handle;
829 hdl->h_sync = th->th_sync;
832 * add commit callback
833 * notice we don't do this in osd_trans_start()
834 * as underlying transaction can change during truncate
836 osd_journal_callback_set(hdl, osd_trans_commit_cb,
839 LASSERT(oti->oti_txns == 1);
842 * XXX: current rule is that we first start tx,
843 * then lock object(s), but we can't use
844 * this rule for data (due to locking specifics
845 * in ldiskfs). also in long-term we'd like to
846 * use usually-used (locks;tx) ordering. so,
847 * UGLY thing is that we'll use one ordering for
848 * data (ofd) and reverse ordering for metadata
849 * (mdd). then at some point we'll fix the latter
851 if (osd_dt_dev(th->th_dev)->od_is_md) {
852 LASSERT(oti->oti_r_locks == 0);
853 LASSERT(oti->oti_w_locks == 0);
855 rc = dt_txn_hook_stop(env, th);
857 CERROR("Failure in transaction hook: %d\n", rc);
858 oh->ot_handle = NULL;
859 OSD_CHECK_SLOW_TH(oh, oti->oti_dev,
860 rc = ldiskfs_journal_stop(hdl));
862 CERROR("Failure to stop transaction: %d\n", rc);
867 /* as we want IO to journal and data IO be concurrent, we don't block
868 * awaiting data IO completion in osd_do_bio(), instead we wait here
869 * once transaction is submitted to the journal. all reqular requests
870 * don't do direct IO (except read/write), thus this wait_event becomes
873 * IMPORTANT: we have to wait till any IO submited by the thread is
874 * completed otherwise iobuf may be corrupted by different request
876 cfs_wait_event(iobuf->dr_wait,
877 cfs_atomic_read(&iobuf->dr_numreqs) == 0);
879 rc = iobuf->dr_error;
884 static int osd_trans_cb_add(struct thandle *th, struct dt_txn_commit_cb *dcb)
886 struct osd_thandle *oh = container_of0(th, struct osd_thandle,
889 LASSERT(dcb->dcb_magic == TRANS_COMMIT_CB_MAGIC);
890 LASSERT(&dcb->dcb_func != NULL);
891 cfs_list_add(&dcb->dcb_linkage, &oh->ot_dcb_list);
897 * Called just before object is freed. Releases all resources except for
898 * object itself (that is released by osd_object_free()).
900 * Concurrency: no concurrent access is possible that late in object
903 static void osd_object_delete(const struct lu_env *env, struct lu_object *l)
905 struct osd_object *obj = osd_obj(l);
906 struct inode *inode = obj->oo_inode;
908 LINVRNT(osd_invariant(obj));
911 * If object is unlinked remove fid->ino mapping from object index.
917 obj->oo_inode = NULL;
922 * Concurrency: ->loo_object_release() is called under site spin-lock.
924 static void osd_object_release(const struct lu_env *env,
930 * Concurrency: shouldn't matter.
932 static int osd_object_print(const struct lu_env *env, void *cookie,
933 lu_printer_t p, const struct lu_object *l)
935 struct osd_object *o = osd_obj(l);
938 if (o->oo_dir != NULL)
939 d = o->oo_dir->od_container.ic_descr;
942 return (*p)(env, cookie,
943 LUSTRE_OSD_LDISKFS_NAME"-object@%p(i:%p:%lu/%u)[%s]",
945 o->oo_inode ? o->oo_inode->i_ino : 0UL,
946 o->oo_inode ? o->oo_inode->i_generation : 0,
947 d ? d->id_ops->id_name : "plain");
951 * Concurrency: shouldn't matter.
953 int osd_statfs(const struct lu_env *env, struct dt_device *d,
954 struct obd_statfs *sfs)
956 struct osd_device *osd = osd_dt_dev(d);
957 struct super_block *sb = osd_sb(osd);
958 struct kstatfs *ksfs;
961 if (unlikely(osd->od_mnt == NULL))
964 /* osd_lproc.c call this without env, allocate ksfs for that case */
965 if (unlikely(env == NULL)) {
970 ksfs = &osd_oti_get(env)->oti_ksfs;
973 cfs_spin_lock(&osd->od_osfs_lock);
975 if (cfs_time_before_64(osd->od_osfs_age, cfs_time_shift_64(-1))) {
976 result = sb->s_op->statfs(sb->s_root, ksfs);
977 if (likely(result == 0)) { /* N.B. statfs can't really fail */
978 osd->od_osfs_age = cfs_time_current_64();
979 statfs_pack(&osd->od_statfs, ksfs);
983 if (likely(result == 0))
984 *sfs = osd->od_statfs;
985 cfs_spin_unlock(&osd->od_osfs_lock);
987 if (unlikely(env == NULL))
994 * Concurrency: doesn't access mutable data.
996 static void osd_conf_get(const struct lu_env *env,
997 const struct dt_device *dev,
998 struct dt_device_param *param)
1000 struct super_block *sb = osd_sb(osd_dt_dev(dev));
1003 * XXX should be taken from not-yet-existing fs abstraction layer.
1005 param->ddp_mnt = osd_dt_dev(dev)->od_mnt;
1006 param->ddp_max_name_len = LDISKFS_NAME_LEN;
1007 param->ddp_max_nlink = LDISKFS_LINK_MAX;
1008 param->ddp_block_shift = sb->s_blocksize_bits;
1009 param->ddp_mntopts = 0;
1010 if (test_opt(sb, XATTR_USER))
1011 param->ddp_mntopts |= MNTOPT_USERXATTR;
1012 if (test_opt(sb, POSIX_ACL))
1013 param->ddp_mntopts |= MNTOPT_ACL;
1015 #if defined(LDISKFS_FEATURE_INCOMPAT_EA_INODE)
1016 if (LDISKFS_HAS_INCOMPAT_FEATURE(sb, LDISKFS_FEATURE_INCOMPAT_EA_INODE))
1017 param->ddp_max_ea_size = LDISKFS_XATTR_MAX_LARGE_EA_SIZE;
1020 param->ddp_max_ea_size = sb->s_blocksize;
1025 * Helper function to get and fill the buffer with input values.
1027 static struct lu_buf *osd_buf_get(const struct lu_env *env, void *area, ssize_t len)
1031 buf = &osd_oti_get(env)->oti_buf;
1038 * Concurrency: shouldn't matter.
1040 static int osd_sync(const struct lu_env *env, struct dt_device *d)
1042 CDEBUG(D_HA, "syncing OSD %s\n", LUSTRE_OSD_LDISKFS_NAME);
1043 return ldiskfs_force_commit(osd_sb(osd_dt_dev(d)));
1047 * Start commit for OSD device.
1049 * An implementation of dt_commit_async method for OSD device.
1050 * Asychronously starts underlayng fs sync and thereby a transaction
1053 * \param env environment
1054 * \param d dt device
1056 * \see dt_device_operations
1058 static int osd_commit_async(const struct lu_env *env,
1059 struct dt_device *d)
1061 struct super_block *s = osd_sb(osd_dt_dev(d));
1064 CDEBUG(D_HA, "async commit OSD %s\n", LUSTRE_OSD_LDISKFS_NAME);
1065 RETURN(s->s_op->sync_fs(s, 0));
1069 * Concurrency: shouldn't matter.
1072 static int osd_ro(const struct lu_env *env, struct dt_device *d)
1074 struct super_block *sb = osd_sb(osd_dt_dev(d));
1078 CERROR("*** setting %s read-only ***\n", osd_dt_dev(d)->od_svname);
1080 rc = __lvfs_set_rdonly(sb->s_bdev, LDISKFS_SB(sb)->journal_bdev);
1085 * Concurrency: serialization provided by callers.
1087 static int osd_init_capa_ctxt(const struct lu_env *env, struct dt_device *d,
1088 int mode, unsigned long timeout, __u32 alg,
1089 struct lustre_capa_key *keys)
1091 struct osd_device *dev = osd_dt_dev(d);
1094 dev->od_fl_capa = mode;
1095 dev->od_capa_timeout = timeout;
1096 dev->od_capa_alg = alg;
1097 dev->od_capa_keys = keys;
1102 * Concurrency: serialization provided by callers.
1104 static void osd_init_quota_ctxt(const struct lu_env *env, struct dt_device *d,
1105 struct dt_quota_ctxt *ctxt, void *data)
1107 struct obd_device *obd = (void *)ctxt;
1108 struct vfsmount *mnt = (struct vfsmount *)data;
1111 obd->u.obt.obt_sb = mnt->mnt_root->d_inode->i_sb;
1112 OBD_SET_CTXT_MAGIC(&obd->obd_lvfs_ctxt);
1113 obd->obd_lvfs_ctxt.pwdmnt = mnt;
1114 obd->obd_lvfs_ctxt.pwd = mnt->mnt_root;
1115 obd->obd_lvfs_ctxt.fs = get_ds();
1121 * Note: we do not count into QUOTA here.
1122 * If we mount with --data_journal we may need more.
1124 const int osd_dto_credits_noquota[DTO_NR] = {
1127 * INDEX_EXTRA_TRANS_BLOCKS(8) +
1128 * SINGLEDATA_TRANS_BLOCKS(8)
1129 * XXX Note: maybe iam need more, since iam have more level than
1132 [DTO_INDEX_INSERT] = 16,
1133 [DTO_INDEX_DELETE] = 16,
1137 [DTO_INDEX_UPDATE] = 16,
1139 * Create a object. The same as create object in EXT3.
1140 * DATA_TRANS_BLOCKS(14) +
1141 * INDEX_EXTRA_BLOCKS(8) +
1142 * 3(inode bits, groups, GDT)
1144 [DTO_OBJECT_CREATE] = 25,
1146 * XXX: real credits to be fixed
1148 [DTO_OBJECT_DELETE] = 25,
1150 * Attr set credits (inode)
1152 [DTO_ATTR_SET_BASE] = 1,
1154 * Xattr set. The same as xattr of EXT3.
1155 * DATA_TRANS_BLOCKS(14)
1156 * XXX Note: in original MDS implmentation INDEX_EXTRA_TRANS_BLOCKS
1157 * are also counted in. Do not know why?
1159 [DTO_XATTR_SET] = 14,
1162 * credits for inode change during write.
1164 [DTO_WRITE_BASE] = 3,
1166 * credits for single block write.
1168 [DTO_WRITE_BLOCK] = 14,
1170 * Attr set credits for chown.
1171 * This is extra credits for setattr, and it is null without quota
1173 [DTO_ATTR_SET_CHOWN]= 0
1176 static const struct dt_device_operations osd_dt_ops = {
1177 .dt_root_get = osd_root_get,
1178 .dt_statfs = osd_statfs,
1179 .dt_trans_create = osd_trans_create,
1180 .dt_trans_start = osd_trans_start,
1181 .dt_trans_stop = osd_trans_stop,
1182 .dt_trans_cb_add = osd_trans_cb_add,
1183 .dt_conf_get = osd_conf_get,
1184 .dt_sync = osd_sync,
1186 .dt_commit_async = osd_commit_async,
1187 .dt_init_capa_ctxt = osd_init_capa_ctxt,
1188 .dt_init_quota_ctxt= osd_init_quota_ctxt,
1191 static void osd_object_read_lock(const struct lu_env *env,
1192 struct dt_object *dt, unsigned role)
1194 struct osd_object *obj = osd_dt_obj(dt);
1195 struct osd_thread_info *oti = osd_oti_get(env);
1197 LINVRNT(osd_invariant(obj));
1199 LASSERT(obj->oo_owner != env);
1200 cfs_down_read_nested(&obj->oo_sem, role);
1202 LASSERT(obj->oo_owner == NULL);
1206 static void osd_object_write_lock(const struct lu_env *env,
1207 struct dt_object *dt, unsigned role)
1209 struct osd_object *obj = osd_dt_obj(dt);
1210 struct osd_thread_info *oti = osd_oti_get(env);
1212 LINVRNT(osd_invariant(obj));
1214 LASSERT(obj->oo_owner != env);
1215 cfs_down_write_nested(&obj->oo_sem, role);
1217 LASSERT(obj->oo_owner == NULL);
1218 obj->oo_owner = env;
1222 static void osd_object_read_unlock(const struct lu_env *env,
1223 struct dt_object *dt)
1225 struct osd_object *obj = osd_dt_obj(dt);
1226 struct osd_thread_info *oti = osd_oti_get(env);
1228 LINVRNT(osd_invariant(obj));
1230 LASSERT(oti->oti_r_locks > 0);
1232 cfs_up_read(&obj->oo_sem);
1235 static void osd_object_write_unlock(const struct lu_env *env,
1236 struct dt_object *dt)
1238 struct osd_object *obj = osd_dt_obj(dt);
1239 struct osd_thread_info *oti = osd_oti_get(env);
1241 LINVRNT(osd_invariant(obj));
1243 LASSERT(obj->oo_owner == env);
1244 LASSERT(oti->oti_w_locks > 0);
1246 obj->oo_owner = NULL;
1247 cfs_up_write(&obj->oo_sem);
1250 static int osd_object_write_locked(const struct lu_env *env,
1251 struct dt_object *dt)
1253 struct osd_object *obj = osd_dt_obj(dt);
1255 LINVRNT(osd_invariant(obj));
1257 return obj->oo_owner == env;
1260 static int capa_is_sane(const struct lu_env *env,
1261 struct osd_device *dev,
1262 struct lustre_capa *capa,
1263 struct lustre_capa_key *keys)
1265 struct osd_thread_info *oti = osd_oti_get(env);
1266 struct lustre_capa *tcapa = &oti->oti_capa;
1267 struct obd_capa *oc;
1271 oc = capa_lookup(dev->od_capa_hash, capa, 0);
1273 if (capa_is_expired(oc)) {
1274 DEBUG_CAPA(D_ERROR, capa, "expired");
1281 if (capa_is_expired_sec(capa)) {
1282 DEBUG_CAPA(D_ERROR, capa, "expired");
1286 cfs_spin_lock(&capa_lock);
1287 for (i = 0; i < 2; i++) {
1288 if (keys[i].lk_keyid == capa->lc_keyid) {
1289 oti->oti_capa_key = keys[i];
1293 cfs_spin_unlock(&capa_lock);
1296 DEBUG_CAPA(D_ERROR, capa, "no matched capa key");
1300 rc = capa_hmac(tcapa->lc_hmac, capa, oti->oti_capa_key.lk_key);
1304 if (memcmp(tcapa->lc_hmac, capa->lc_hmac, sizeof(capa->lc_hmac))) {
1305 DEBUG_CAPA(D_ERROR, capa, "HMAC mismatch");
1309 oc = capa_add(dev->od_capa_hash, capa);
1315 int osd_object_auth(const struct lu_env *env, struct dt_object *dt,
1316 struct lustre_capa *capa, __u64 opc)
1318 const struct lu_fid *fid = lu_object_fid(&dt->do_lu);
1319 struct osd_device *dev = osd_dev(dt->do_lu.lo_dev);
1320 struct md_capainfo *ci;
1323 if (!dev->od_fl_capa)
1326 if (capa == BYPASS_CAPA)
1329 ci = md_capainfo(env);
1333 if (ci->mc_auth == LC_ID_NONE)
1337 CERROR("no capability is provided for fid "DFID"\n", PFID(fid));
1341 if (!lu_fid_eq(fid, &capa->lc_fid)) {
1342 DEBUG_CAPA(D_ERROR, capa, "fid "DFID" mismatch with",
1347 if (!capa_opc_supported(capa, opc)) {
1348 DEBUG_CAPA(D_ERROR, capa, "opc "LPX64" not supported by", opc);
1352 if ((rc = capa_is_sane(env, dev, capa, dev->od_capa_keys))) {
1353 DEBUG_CAPA(D_ERROR, capa, "insane (rc %d)", rc);
1360 static struct timespec *osd_inode_time(const struct lu_env *env,
1361 struct inode *inode, __u64 seconds)
1363 struct osd_thread_info *oti = osd_oti_get(env);
1364 struct timespec *t = &oti->oti_time;
1366 t->tv_sec = seconds;
1368 *t = timespec_trunc(*t, inode->i_sb->s_time_gran);
1373 static void osd_inode_getattr(const struct lu_env *env,
1374 struct inode *inode, struct lu_attr *attr)
1376 attr->la_valid |= LA_ATIME | LA_MTIME | LA_CTIME | LA_MODE |
1377 LA_SIZE | LA_BLOCKS | LA_UID | LA_GID |
1378 LA_FLAGS | LA_NLINK | LA_RDEV | LA_BLKSIZE;
1380 attr->la_atime = LTIME_S(inode->i_atime);
1381 attr->la_mtime = LTIME_S(inode->i_mtime);
1382 attr->la_ctime = LTIME_S(inode->i_ctime);
1383 attr->la_mode = inode->i_mode;
1384 attr->la_size = i_size_read(inode);
1385 attr->la_blocks = inode->i_blocks;
1386 attr->la_uid = inode->i_uid;
1387 attr->la_gid = inode->i_gid;
1388 attr->la_flags = LDISKFS_I(inode)->i_flags;
1389 attr->la_nlink = inode->i_nlink;
1390 attr->la_rdev = inode->i_rdev;
1391 attr->la_blksize = 1 << inode->i_blkbits;
1392 attr->la_blkbits = inode->i_blkbits;
1395 static int osd_attr_get(const struct lu_env *env,
1396 struct dt_object *dt,
1397 struct lu_attr *attr,
1398 struct lustre_capa *capa)
1400 struct osd_object *obj = osd_dt_obj(dt);
1402 LASSERT(dt_object_exists(dt));
1403 LINVRNT(osd_invariant(obj));
1405 if (osd_object_auth(env, dt, capa, CAPA_OPC_META_READ))
1408 cfs_spin_lock(&obj->oo_guard);
1409 osd_inode_getattr(env, obj->oo_inode, attr);
1410 cfs_spin_unlock(&obj->oo_guard);
1414 static int osd_declare_attr_set(const struct lu_env *env,
1415 struct dt_object *dt,
1416 const struct lu_attr *attr,
1417 struct thandle *handle)
1419 struct osd_thandle *oh;
1420 struct osd_object *obj;
1421 struct osd_thread_info *info = osd_oti_get(env);
1422 struct lquota_id_info *qi = &info->oti_qi;
1428 LASSERT(dt != NULL);
1429 LASSERT(handle != NULL);
1431 obj = osd_dt_obj(dt);
1432 LASSERT(osd_invariant(obj));
1434 oh = container_of0(handle, struct osd_thandle, ot_super);
1435 LASSERT(oh->ot_handle == NULL);
1437 OSD_DECLARE_OP(oh, attr_set);
1438 oh->ot_credits += osd_dto_credits_noquota[DTO_ATTR_SET_BASE];
1440 if (attr == NULL || obj->oo_inode == NULL)
1443 bspace = obj->oo_inode->i_blocks;
1444 bspace <<= obj->oo_inode->i_sb->s_blocksize_bits;
1445 bspace = toqb(bspace);
1447 /* Changing ownership is always preformed by super user, it should not
1450 * We still need to call the osd_declare_qid() to calculate the journal
1451 * credits for updating quota accounting files and to trigger quota
1452 * space adjustment once the operation is completed.*/
1453 if ((attr->la_valid & LA_UID) != 0 &&
1454 attr->la_uid != obj->oo_inode->i_uid) {
1455 qi->lqi_type = USRQUOTA;
1457 /* inode accounting */
1458 qi->lqi_is_blk = false;
1460 /* one more inode for the new owner ... */
1461 qi->lqi_id.qid_uid = attr->la_uid;
1463 allocated = (attr->la_uid == 0) ? true : false;
1464 rc = osd_declare_qid(env, oh, qi, allocated, NULL);
1465 if (rc == -EDQUOT || rc == -EINPROGRESS)
1470 /* and one less inode for the current uid */
1471 qi->lqi_id.qid_uid = obj->oo_inode->i_uid;
1473 rc = osd_declare_qid(env, oh, qi, true, NULL);
1474 if (rc == -EDQUOT || rc == -EINPROGRESS)
1479 /* block accounting */
1480 qi->lqi_is_blk = true;
1482 /* more blocks for the new owner ... */
1483 qi->lqi_id.qid_uid = attr->la_uid;
1484 qi->lqi_space = bspace;
1485 allocated = (attr->la_uid == 0) ? true : false;
1486 rc = osd_declare_qid(env, oh, qi, allocated, NULL);
1487 if (rc == -EDQUOT || rc == -EINPROGRESS)
1492 /* and finally less blocks for the current owner */
1493 qi->lqi_id.qid_uid = obj->oo_inode->i_uid;
1494 qi->lqi_space = -bspace;
1495 rc = osd_declare_qid(env, oh, qi, true, NULL);
1496 if (rc == -EDQUOT || rc == -EINPROGRESS)
1502 if (attr->la_valid & LA_GID &&
1503 attr->la_gid != obj->oo_inode->i_gid) {
1504 qi->lqi_type = GRPQUOTA;
1506 /* inode accounting */
1507 qi->lqi_is_blk = false;
1509 /* one more inode for the new group owner ... */
1510 qi->lqi_id.qid_gid = attr->la_gid;
1512 allocated = (attr->la_gid == 0) ? true : false;
1513 rc = osd_declare_qid(env, oh, qi, allocated, NULL);
1514 if (rc == -EDQUOT || rc == -EINPROGRESS)
1519 /* and one less inode for the current gid */
1520 qi->lqi_id.qid_gid = obj->oo_inode->i_gid;
1522 rc = osd_declare_qid(env, oh, qi, true, NULL);
1523 if (rc == -EDQUOT || rc == -EINPROGRESS)
1528 /* block accounting */
1529 qi->lqi_is_blk = true;
1531 /* more blocks for the new owner ... */
1532 qi->lqi_id.qid_gid = attr->la_gid;
1533 qi->lqi_space = bspace;
1534 allocated = (attr->la_gid == 0) ? true : false;
1535 rc = osd_declare_qid(env, oh, qi, allocated, NULL);
1536 if (rc == -EDQUOT || rc == -EINPROGRESS)
1541 /* and finally less blocks for the current owner */
1542 qi->lqi_id.qid_gid = obj->oo_inode->i_gid;
1543 qi->lqi_space = -bspace;
1544 rc = osd_declare_qid(env, oh, qi, true, NULL);
1545 if (rc == -EDQUOT || rc == -EINPROGRESS)
1554 static int osd_inode_setattr(const struct lu_env *env,
1555 struct inode *inode, const struct lu_attr *attr)
1559 bits = attr->la_valid;
1561 LASSERT(!(bits & LA_TYPE)); /* Huh? You want too much. */
1563 if (bits & LA_ATIME)
1564 inode->i_atime = *osd_inode_time(env, inode, attr->la_atime);
1565 if (bits & LA_CTIME)
1566 inode->i_ctime = *osd_inode_time(env, inode, attr->la_ctime);
1567 if (bits & LA_MTIME)
1568 inode->i_mtime = *osd_inode_time(env, inode, attr->la_mtime);
1569 if (bits & LA_SIZE) {
1570 LDISKFS_I(inode)->i_disksize = attr->la_size;
1571 i_size_write(inode, attr->la_size);
1575 /* OSD should not change "i_blocks" which is used by quota.
1576 * "i_blocks" should be changed by ldiskfs only. */
1577 if (bits & LA_BLOCKS)
1578 inode->i_blocks = attr->la_blocks;
1581 inode->i_mode = (inode->i_mode & S_IFMT) |
1582 (attr->la_mode & ~S_IFMT);
1584 inode->i_uid = attr->la_uid;
1586 inode->i_gid = attr->la_gid;
1587 if (bits & LA_NLINK)
1588 inode->i_nlink = attr->la_nlink;
1590 inode->i_rdev = attr->la_rdev;
1592 if (bits & LA_FLAGS) {
1593 /* always keep S_NOCMTIME */
1594 inode->i_flags = ll_ext_to_inode_flags(attr->la_flags) |
1600 static int osd_quota_transfer(struct inode *inode, const struct lu_attr *attr)
1602 if ((attr->la_valid & LA_UID && attr->la_uid != inode->i_uid) ||
1603 (attr->la_valid & LA_GID && attr->la_gid != inode->i_gid)) {
1608 if (attr->la_valid & LA_UID)
1609 iattr.ia_valid |= ATTR_UID;
1610 if (attr->la_valid & LA_GID)
1611 iattr.ia_valid |= ATTR_GID;
1612 iattr.ia_uid = attr->la_uid;
1613 iattr.ia_gid = attr->la_gid;
1615 rc = ll_vfs_dq_transfer(inode, &iattr);
1617 CERROR("%s: quota transfer failed: rc = %d. Is quota "
1618 "enforcement enabled on the ldiskfs filesystem?",
1619 inode->i_sb->s_id, rc);
1626 static int osd_attr_set(const struct lu_env *env,
1627 struct dt_object *dt,
1628 const struct lu_attr *attr,
1629 struct thandle *handle,
1630 struct lustre_capa *capa)
1632 struct osd_object *obj = osd_dt_obj(dt);
1633 struct inode *inode;
1636 LASSERT(handle != NULL);
1637 LASSERT(dt_object_exists(dt));
1638 LASSERT(osd_invariant(obj));
1640 if (osd_object_auth(env, dt, capa, CAPA_OPC_META_WRITE))
1643 OSD_EXEC_OP(handle, attr_set);
1645 inode = obj->oo_inode;
1646 if (!osd_dt_dev(handle->th_dev)->od_is_md) {
1648 rc = osd_quota_transfer(inode, attr);
1652 #ifdef HAVE_QUOTA_SUPPORT
1653 if ((attr->la_valid & LA_UID && attr->la_uid != inode->i_uid) ||
1654 (attr->la_valid & LA_GID && attr->la_gid != inode->i_gid)) {
1655 struct osd_ctxt *save = &osd_oti_get(env)->oti_ctxt;
1660 if (attr->la_valid & LA_UID)
1661 iattr.ia_valid |= ATTR_UID;
1662 if (attr->la_valid & LA_GID)
1663 iattr.ia_valid |= ATTR_GID;
1664 iattr.ia_uid = attr->la_uid;
1665 iattr.ia_gid = attr->la_gid;
1666 osd_push_ctxt(env, save, 1);
1667 rc = ll_vfs_dq_transfer(inode, &iattr) ? -EDQUOT : 0;
1668 osd_pop_ctxt(save, 1);
1674 cfs_spin_lock(&obj->oo_guard);
1675 rc = osd_inode_setattr(env, inode, attr);
1676 cfs_spin_unlock(&obj->oo_guard);
1679 inode->i_sb->s_op->dirty_inode(inode);
1683 struct dentry *osd_child_dentry_get(const struct lu_env *env,
1684 struct osd_object *obj,
1685 const char *name, const int namelen)
1687 return osd_child_dentry_by_inode(env, obj->oo_inode, name, namelen);
1690 static int osd_mkfile(struct osd_thread_info *info, struct osd_object *obj,
1692 struct dt_allocation_hint *hint,
1696 struct osd_device *osd = osd_obj2dev(obj);
1697 struct osd_thandle *oth;
1698 struct dt_object *parent = NULL;
1699 struct inode *inode;
1700 #ifdef HAVE_QUOTA_SUPPORT
1701 struct osd_ctxt *save = &info->oti_ctxt;
1704 LINVRNT(osd_invariant(obj));
1705 LASSERT(obj->oo_inode == NULL);
1706 LASSERT(obj->oo_hl_head == NULL);
1708 if (S_ISDIR(mode) && ldiskfs_pdo) {
1709 obj->oo_hl_head =ldiskfs_htree_lock_head_alloc(HTREE_HBITS_DEF);
1710 if (obj->oo_hl_head == NULL)
1714 oth = container_of(th, struct osd_thandle, ot_super);
1715 LASSERT(oth->ot_handle->h_transaction != NULL);
1717 if (hint && hint->dah_parent)
1718 parent = hint->dah_parent;
1720 #ifdef HAVE_QUOTA_SUPPORT
1721 osd_push_ctxt(info->oti_env, save, osd_dt_dev(th->th_dev)->od_is_md);
1723 inode = ldiskfs_create_inode(oth->ot_handle,
1724 parent ? osd_dt_obj(parent)->oo_inode :
1725 osd_sb(osd)->s_root->d_inode,
1727 #ifdef HAVE_QUOTA_SUPPORT
1728 osd_pop_ctxt(save, osd_dt_dev(th->th_dev)->od_is_md);
1730 if (!IS_ERR(inode)) {
1731 /* Do not update file c/mtime in ldiskfs.
1732 * NB: don't need any lock because no contention at this
1734 inode->i_flags |= S_NOCMTIME;
1735 inode->i_state |= I_LUSTRE_NOSCRUB;
1736 obj->oo_inode = inode;
1739 if (obj->oo_hl_head != NULL) {
1740 ldiskfs_htree_lock_head_free(obj->oo_hl_head);
1741 obj->oo_hl_head = NULL;
1743 result = PTR_ERR(inode);
1745 LINVRNT(osd_invariant(obj));
1753 static int osd_mkdir(struct osd_thread_info *info, struct osd_object *obj,
1754 struct lu_attr *attr,
1755 struct dt_allocation_hint *hint,
1756 struct dt_object_format *dof,
1760 struct osd_thandle *oth;
1761 struct osd_device *osd = osd_obj2dev(obj);
1762 __u32 mode = (attr->la_mode & (S_IFMT | S_IRWXUGO | S_ISVTX));
1764 LASSERT(S_ISDIR(attr->la_mode));
1766 oth = container_of(th, struct osd_thandle, ot_super);
1767 LASSERT(oth->ot_handle->h_transaction != NULL);
1768 result = osd_mkfile(info, obj, mode, hint, th);
1769 if (result == 0 && osd->od_iop_mode == 0) {
1770 LASSERT(obj->oo_inode != NULL);
1772 * XXX uh-oh... call low-level iam function directly.
1775 result = iam_lvar_create(obj->oo_inode, OSD_NAME_LEN, 4,
1776 sizeof (struct osd_fid_pack),
1782 static int osd_mk_index(struct osd_thread_info *info, struct osd_object *obj,
1783 struct lu_attr *attr,
1784 struct dt_allocation_hint *hint,
1785 struct dt_object_format *dof,
1789 struct osd_thandle *oth;
1790 const struct dt_index_features *feat = dof->u.dof_idx.di_feat;
1792 __u32 mode = (attr->la_mode & (S_IFMT | S_IALLUGO | S_ISVTX));
1794 LASSERT(S_ISREG(attr->la_mode));
1796 oth = container_of(th, struct osd_thandle, ot_super);
1797 LASSERT(oth->ot_handle->h_transaction != NULL);
1799 result = osd_mkfile(info, obj, mode, hint, th);
1801 LASSERT(obj->oo_inode != NULL);
1802 if (feat->dif_flags & DT_IND_VARKEY)
1803 result = iam_lvar_create(obj->oo_inode,
1804 feat->dif_keysize_max,
1806 feat->dif_recsize_max,
1809 result = iam_lfix_create(obj->oo_inode,
1810 feat->dif_keysize_max,
1812 feat->dif_recsize_max,
1819 static int osd_mkreg(struct osd_thread_info *info, struct osd_object *obj,
1820 struct lu_attr *attr,
1821 struct dt_allocation_hint *hint,
1822 struct dt_object_format *dof,
1825 LASSERT(S_ISREG(attr->la_mode));
1826 return osd_mkfile(info, obj, (attr->la_mode &
1827 (S_IFMT | S_IALLUGO | S_ISVTX)), hint, th);
1830 static int osd_mksym(struct osd_thread_info *info, struct osd_object *obj,
1831 struct lu_attr *attr,
1832 struct dt_allocation_hint *hint,
1833 struct dt_object_format *dof,
1836 LASSERT(S_ISLNK(attr->la_mode));
1837 return osd_mkfile(info, obj, (attr->la_mode &
1838 (S_IFMT | S_IALLUGO | S_ISVTX)), hint, th);
1841 static int osd_mknod(struct osd_thread_info *info, struct osd_object *obj,
1842 struct lu_attr *attr,
1843 struct dt_allocation_hint *hint,
1844 struct dt_object_format *dof,
1847 cfs_umode_t mode = attr->la_mode & (S_IFMT | S_IALLUGO | S_ISVTX);
1850 LINVRNT(osd_invariant(obj));
1851 LASSERT(obj->oo_inode == NULL);
1852 LASSERT(S_ISCHR(mode) || S_ISBLK(mode) ||
1853 S_ISFIFO(mode) || S_ISSOCK(mode));
1855 result = osd_mkfile(info, obj, mode, hint, th);
1857 LASSERT(obj->oo_inode != NULL);
1859 * This inode should be marked dirty for i_rdev. Currently
1860 * that is done in the osd_attr_init().
1862 init_special_inode(obj->oo_inode, mode, attr->la_rdev);
1864 LINVRNT(osd_invariant(obj));
1868 typedef int (*osd_obj_type_f)(struct osd_thread_info *, struct osd_object *,
1870 struct dt_allocation_hint *hint,
1871 struct dt_object_format *dof,
1874 static osd_obj_type_f osd_create_type_f(enum dt_format_type type)
1876 osd_obj_type_f result;
1892 result = osd_mk_index;
1903 static void osd_ah_init(const struct lu_env *env, struct dt_allocation_hint *ah,
1904 struct dt_object *parent, cfs_umode_t child_mode)
1908 memset(ah, 0, sizeof(*ah));
1909 ah->dah_parent = parent;
1910 ah->dah_mode = child_mode;
1913 static void osd_attr_init(struct osd_thread_info *info, struct osd_object *obj,
1914 struct lu_attr *attr, struct dt_object_format *dof)
1916 struct inode *inode = obj->oo_inode;
1917 __u64 valid = attr->la_valid;
1920 attr->la_valid &= ~(LA_TYPE | LA_MODE);
1922 if (dof->dof_type != DFT_NODE)
1923 attr->la_valid &= ~LA_RDEV;
1924 if ((valid & LA_ATIME) && (attr->la_atime == LTIME_S(inode->i_atime)))
1925 attr->la_valid &= ~LA_ATIME;
1926 if ((valid & LA_CTIME) && (attr->la_ctime == LTIME_S(inode->i_ctime)))
1927 attr->la_valid &= ~LA_CTIME;
1928 if ((valid & LA_MTIME) && (attr->la_mtime == LTIME_S(inode->i_mtime)))
1929 attr->la_valid &= ~LA_MTIME;
1931 if (!osd_obj2dev(obj)->od_is_md) {
1933 result = osd_quota_transfer(inode, attr);
1937 #ifdef HAVE_QUOTA_SUPPORT
1938 attr->la_valid &= ~(LA_UID | LA_GID);
1942 if (attr->la_valid != 0) {
1943 result = osd_inode_setattr(info->oti_env, inode, attr);
1945 * The osd_inode_setattr() should always succeed here. The
1946 * only error that could be returned is EDQUOT when we are
1947 * trying to change the UID or GID of the inode. However, this
1948 * should not happen since quota enforcement is no longer
1949 * enabled on ldiskfs (lquota takes care of it).
1951 LASSERTF(result == 0, "%d", result);
1952 inode->i_sb->s_op->dirty_inode(inode);
1955 attr->la_valid = valid;
1959 * Helper function for osd_object_create()
1961 * \retval 0, on success
1963 static int __osd_object_create(struct osd_thread_info *info,
1964 struct osd_object *obj, struct lu_attr *attr,
1965 struct dt_allocation_hint *hint,
1966 struct dt_object_format *dof,
1972 /* we drop umask so that permissions we pass are not affected */
1973 umask = current->fs->umask;
1974 current->fs->umask = 0;
1976 result = osd_create_type_f(dof->dof_type)(info, obj, attr, hint, dof,
1979 osd_attr_init(info, obj, attr, dof);
1980 osd_object_init0(obj);
1982 if (obj->oo_inode && (obj->oo_inode->i_state & I_NEW))
1983 unlock_new_inode(obj->oo_inode);
1986 /* restore previous umask value */
1987 current->fs->umask = umask;
1993 * Helper function for osd_object_create()
1995 * \retval 0, on success
1997 static int __osd_oi_insert(const struct lu_env *env, struct osd_object *obj,
1998 const struct lu_fid *fid, struct thandle *th)
2000 struct osd_thread_info *info = osd_oti_get(env);
2001 struct osd_inode_id *id = &info->oti_id;
2002 struct osd_device *osd = osd_obj2dev(obj);
2004 LASSERT(obj->oo_inode != NULL);
2006 if (osd->od_is_md) {
2007 struct md_ucred *uc = md_ucred(env);
2008 LASSERT(uc != NULL);
2011 osd_id_gen(id, obj->oo_inode->i_ino, obj->oo_inode->i_generation);
2012 return osd_oi_insert(info, osd, fid, id, th);
2015 static int osd_declare_object_create(const struct lu_env *env,
2016 struct dt_object *dt,
2017 struct lu_attr *attr,
2018 struct dt_allocation_hint *hint,
2019 struct dt_object_format *dof,
2020 struct thandle *handle)
2022 struct osd_thandle *oh;
2026 LASSERT(handle != NULL);
2028 oh = container_of0(handle, struct osd_thandle, ot_super);
2029 LASSERT(oh->ot_handle == NULL);
2031 OSD_DECLARE_OP(oh, create);
2032 oh->ot_credits += osd_dto_credits_noquota[DTO_OBJECT_CREATE];
2033 /* XXX: So far, only normal fid needs be inserted into the oi,
2034 * things could be changed later. Revise following code then. */
2035 if (fid_is_norm(lu_object_fid(&dt->do_lu))) {
2036 OSD_DECLARE_OP(oh, insert);
2037 oh->ot_credits += osd_dto_credits_noquota[DTO_INDEX_INSERT];
2038 /* Reuse idle OI block may cause additional one OI block
2040 oh->ot_credits += 1;
2042 /* If this is directory, then we expect . and .. to be inserted as
2043 * well. The one directory block always needs to be created for the
2044 * directory, so we could use DTO_WRITE_BASE here (GDT, block bitmap,
2045 * block), there is no danger of needing a tree for the first block.
2047 if (attr && S_ISDIR(attr->la_mode)) {
2048 OSD_DECLARE_OP(oh, insert);
2049 OSD_DECLARE_OP(oh, insert);
2050 oh->ot_credits += osd_dto_credits_noquota[DTO_WRITE_BASE];
2056 rc = osd_declare_inode_qid(env, attr->la_uid, attr->la_gid, 1, oh,
2057 false, false, NULL, false);
2061 static int osd_object_create(const struct lu_env *env, struct dt_object *dt,
2062 struct lu_attr *attr,
2063 struct dt_allocation_hint *hint,
2064 struct dt_object_format *dof,
2067 const struct lu_fid *fid = lu_object_fid(&dt->do_lu);
2068 struct osd_object *obj = osd_dt_obj(dt);
2069 struct osd_thread_info *info = osd_oti_get(env);
2074 LINVRNT(osd_invariant(obj));
2075 LASSERT(!dt_object_exists(dt));
2076 LASSERT(osd_write_locked(env, obj));
2077 LASSERT(th != NULL);
2079 if (unlikely(fid_is_acct(fid)))
2080 /* Quota files can't be created from the kernel any more,
2081 * 'tune2fs -O quota' will take care of creating them */
2084 OSD_EXEC_OP(th, create);
2086 result = __osd_object_create(info, obj, attr, hint, dof, th);
2088 result = __osd_oi_insert(env, obj, fid, th);
2090 LASSERT(ergo(result == 0, dt_object_exists(dt)));
2091 LASSERT(osd_invariant(obj));
2096 * Called to destroy on-disk representation of the object
2098 * Concurrency: must be locked
2100 static int osd_declare_object_destroy(const struct lu_env *env,
2101 struct dt_object *dt,
2104 struct osd_object *obj = osd_dt_obj(dt);
2105 struct inode *inode = obj->oo_inode;
2106 struct osd_thandle *oh;
2110 oh = container_of0(th, struct osd_thandle, ot_super);
2111 LASSERT(oh->ot_handle == NULL);
2114 OSD_DECLARE_OP(oh, destroy);
2115 OSD_DECLARE_OP(oh, delete);
2116 oh->ot_credits += osd_dto_credits_noquota[DTO_OBJECT_DELETE];
2117 /* XXX: So far, only normal fid needs to be inserted into the OI,
2118 * so only normal fid needs to be removed from the OI also. */
2119 if (fid_is_norm(lu_object_fid(&dt->do_lu))) {
2120 oh->ot_credits += osd_dto_credits_noquota[DTO_INDEX_DELETE];
2121 /* Recycle idle OI leaf may cause additional three OI blocks
2123 oh->ot_credits += 3;
2126 /* one less inode */
2127 rc = osd_declare_inode_qid(env, inode->i_uid, inode->i_gid, -1, oh,
2128 false, true, NULL, false);
2131 /* data to be truncated */
2132 rc = osd_declare_inode_qid(env, inode->i_uid, inode->i_gid, 0, oh, true,
2137 static int osd_object_destroy(const struct lu_env *env,
2138 struct dt_object *dt,
2141 const struct lu_fid *fid = lu_object_fid(&dt->do_lu);
2142 struct osd_object *obj = osd_dt_obj(dt);
2143 struct inode *inode = obj->oo_inode;
2144 struct osd_device *osd = osd_obj2dev(obj);
2145 struct osd_thandle *oh;
2149 oh = container_of0(th, struct osd_thandle, ot_super);
2150 LASSERT(oh->ot_handle);
2152 LASSERT(!lu_object_is_dying(dt->do_lu.lo_header));
2154 if (unlikely(fid_is_acct(fid)))
2157 /* Parallel control for OI scrub. For most of cases, there is no
2158 * lock contention. So it will not affect unlink performance. */
2159 cfs_mutex_lock(&inode->i_mutex);
2160 if (S_ISDIR(inode->i_mode)) {
2161 LASSERT(osd_inode_unlinked(inode) ||
2162 inode->i_nlink == 1);
2163 cfs_spin_lock(&obj->oo_guard);
2165 cfs_spin_unlock(&obj->oo_guard);
2166 inode->i_sb->s_op->dirty_inode(inode);
2168 LASSERT(osd_inode_unlinked(inode));
2171 OSD_EXEC_OP(th, destroy);
2173 result = osd_oi_delete(osd_oti_get(env), osd, fid, th);
2174 cfs_mutex_unlock(&inode->i_mutex);
2176 /* XXX: add to ext3 orphan list */
2177 /* rc = ext3_orphan_add(handle_t *handle, struct inode *inode) */
2179 /* not needed in the cache anymore */
2180 set_bit(LU_OBJECT_HEARD_BANSHEE, &dt->do_lu.lo_header->loh_flags);
2186 * Helper function for osd_xattr_set()
2188 static int __osd_xattr_set(const struct lu_env *env, struct dt_object *dt,
2189 const struct lu_buf *buf, const char *name, int fl)
2191 struct osd_object *obj = osd_dt_obj(dt);
2192 struct inode *inode = obj->oo_inode;
2193 struct osd_thread_info *info = osd_oti_get(env);
2194 struct dentry *dentry = &info->oti_child_dentry;
2198 LASSERT(dt_object_exists(dt));
2199 LASSERT(inode->i_op != NULL && inode->i_op->setxattr != NULL);
2201 if (fl & LU_XATTR_REPLACE)
2202 fs_flags |= XATTR_REPLACE;
2204 if (fl & LU_XATTR_CREATE)
2205 fs_flags |= XATTR_CREATE;
2207 dentry->d_inode = inode;
2208 rc = inode->i_op->setxattr(dentry, name, buf->lb_buf,
2209 buf->lb_len, fs_flags);
2214 * Put the fid into lustre_mdt_attrs, and then place the structure
2215 * inode's ea. This fid should not be altered during the life time
2218 * \retval +ve, on success
2219 * \retval -ve, on error
2221 * FIXME: It is good to have/use ldiskfs_xattr_set_handle() here
2223 static int osd_ea_fid_set(const struct lu_env *env, struct dt_object *dt,
2224 const struct lu_fid *fid)
2226 struct osd_thread_info *info = osd_oti_get(env);
2227 struct lustre_mdt_attrs *mdt_attrs = &info->oti_mdt_attrs;
2229 lustre_lma_init(mdt_attrs, fid);
2230 lustre_lma_swab(mdt_attrs);
2231 return __osd_xattr_set(env, dt,
2232 osd_buf_get(env, mdt_attrs, sizeof *mdt_attrs),
2233 XATTR_NAME_LMA, LU_XATTR_CREATE);
2238 * ldiskfs supports fid in dirent, it is passed in dentry->d_fsdata.
2239 * lustre 1.8 also uses d_fsdata for passing other info to ldiskfs.
2240 * To have compatilibility with 1.8 ldiskfs driver we need to have
2241 * magic number at start of fid data.
2242 * \ldiskfs_dentry_param is used only to pass fid from osd to ldiskfs.
2245 void osd_get_ldiskfs_dirent_param(struct ldiskfs_dentry_param *param,
2246 const struct dt_rec *fid)
2248 param->edp_magic = LDISKFS_LUFID_MAGIC;
2249 param->edp_len = sizeof(struct lu_fid) + 1;
2251 fid_cpu_to_be((struct lu_fid *)param->edp_data,
2252 (struct lu_fid *)fid);
2256 * Try to read the fid from inode ea into dt_rec, if return value
2257 * i.e. rc is +ve, then we got fid, otherwise we will have to form igif
2259 * \param fid object fid.
2261 * \retval 0 on success
2263 static int osd_ea_fid_get(const struct lu_env *env, struct osd_object *obj,
2264 __u32 ino, struct lu_fid *fid,
2265 struct osd_inode_id *id)
2267 struct osd_thread_info *info = osd_oti_get(env);
2268 struct inode *inode;
2271 osd_id_gen(id, ino, OSD_OII_NOGEN);
2272 inode = osd_iget_fid(info, osd_obj2dev(obj), id, fid);
2274 RETURN(PTR_ERR(inode));
2281 * OSD layer object create function for interoperability mode (b11826).
2282 * This is mostly similar to osd_object_create(). Only difference being, fid is
2283 * inserted into inode ea here.
2285 * \retval 0, on success
2286 * \retval -ve, on error
2288 static int osd_object_ea_create(const struct lu_env *env, struct dt_object *dt,
2289 struct lu_attr *attr,
2290 struct dt_allocation_hint *hint,
2291 struct dt_object_format *dof,
2294 const struct lu_fid *fid = lu_object_fid(&dt->do_lu);
2295 struct osd_object *obj = osd_dt_obj(dt);
2296 struct osd_thread_info *info = osd_oti_get(env);
2301 LASSERT(osd_invariant(obj));
2302 LASSERT(!dt_object_exists(dt));
2303 LASSERT(osd_write_locked(env, obj));
2304 LASSERT(th != NULL);
2306 if (unlikely(fid_is_acct(fid)))
2307 /* Quota files can't be created from the kernel any more,
2308 * 'tune2fs -O quota' will take care of creating them */
2311 OSD_EXEC_OP(th, create);
2313 result = __osd_object_create(info, obj, attr, hint, dof, th);
2314 /* objects under osd root shld have igif fid, so dont add fid EA */
2315 if (result == 0 && fid_seq(fid) >= FID_SEQ_NORMAL)
2316 result = osd_ea_fid_set(env, dt, fid);
2319 result = __osd_oi_insert(env, obj, fid, th);
2321 LASSERT(ergo(result == 0, dt_object_exists(dt)));
2322 LINVRNT(osd_invariant(obj));
2326 static int osd_declare_object_ref_add(const struct lu_env *env,
2327 struct dt_object *dt,
2328 struct thandle *handle)
2330 struct osd_thandle *oh;
2332 /* it's possible that object doesn't exist yet */
2333 LASSERT(handle != NULL);
2335 oh = container_of0(handle, struct osd_thandle, ot_super);
2336 LASSERT(oh->ot_handle == NULL);
2338 OSD_DECLARE_OP(oh, ref_add);
2339 oh->ot_credits += osd_dto_credits_noquota[DTO_ATTR_SET_BASE];
2345 * Concurrency: @dt is write locked.
2347 static int osd_object_ref_add(const struct lu_env *env,
2348 struct dt_object *dt, struct thandle *th)
2350 struct osd_object *obj = osd_dt_obj(dt);
2351 struct inode *inode = obj->oo_inode;
2353 LINVRNT(osd_invariant(obj));
2354 LASSERT(dt_object_exists(dt));
2355 LASSERT(osd_write_locked(env, obj));
2356 LASSERT(th != NULL);
2358 OSD_EXEC_OP(th, ref_add);
2361 * DIR_NLINK feature is set for compatibility reasons if:
2362 * 1) nlinks > LDISKFS_LINK_MAX, or
2363 * 2) nlinks == 2, since this indicates i_nlink was previously 1.
2365 * It is easier to always set this flag (rather than check and set),
2366 * since it has less overhead, and the superblock will be dirtied
2367 * at some point. Both e2fsprogs and any Lustre-supported ldiskfs
2368 * do not actually care whether this flag is set or not.
2370 cfs_spin_lock(&obj->oo_guard);
2372 if (S_ISDIR(inode->i_mode) && inode->i_nlink > 1) {
2373 if (inode->i_nlink >= LDISKFS_LINK_MAX ||
2374 inode->i_nlink == 2)
2377 LASSERT(inode->i_nlink <= LDISKFS_LINK_MAX);
2378 cfs_spin_unlock(&obj->oo_guard);
2379 inode->i_sb->s_op->dirty_inode(inode);
2380 LINVRNT(osd_invariant(obj));
2385 static int osd_declare_object_ref_del(const struct lu_env *env,
2386 struct dt_object *dt,
2387 struct thandle *handle)
2389 struct osd_thandle *oh;
2391 LASSERT(dt_object_exists(dt));
2392 LASSERT(handle != NULL);
2394 oh = container_of0(handle, struct osd_thandle, ot_super);
2395 LASSERT(oh->ot_handle == NULL);
2397 OSD_DECLARE_OP(oh, ref_del);
2398 oh->ot_credits += osd_dto_credits_noquota[DTO_ATTR_SET_BASE];
2404 * Concurrency: @dt is write locked.
2406 static int osd_object_ref_del(const struct lu_env *env, struct dt_object *dt,
2409 struct osd_object *obj = osd_dt_obj(dt);
2410 struct inode *inode = obj->oo_inode;
2412 LINVRNT(osd_invariant(obj));
2413 LASSERT(dt_object_exists(dt));
2414 LASSERT(osd_write_locked(env, obj));
2415 LASSERT(th != NULL);
2417 OSD_EXEC_OP(th, ref_del);
2419 cfs_spin_lock(&obj->oo_guard);
2420 LASSERT(inode->i_nlink > 0);
2422 /* If this is/was a many-subdir directory (nlink > LDISKFS_LINK_MAX)
2423 * then the nlink count is 1. Don't let it be set to 0 or the directory
2424 * inode will be deleted incorrectly. */
2425 if (S_ISDIR(inode->i_mode) && inode->i_nlink == 0)
2427 cfs_spin_unlock(&obj->oo_guard);
2428 inode->i_sb->s_op->dirty_inode(inode);
2429 LINVRNT(osd_invariant(obj));
2435 * Get the 64-bit version for an inode.
2437 static int osd_object_version_get(const struct lu_env *env,
2438 struct dt_object *dt, dt_obj_version_t *ver)
2440 struct inode *inode = osd_dt_obj(dt)->oo_inode;
2442 CDEBUG(D_INODE, "Get version "LPX64" for inode %lu\n",
2443 LDISKFS_I(inode)->i_fs_version, inode->i_ino);
2444 *ver = LDISKFS_I(inode)->i_fs_version;
2449 * Concurrency: @dt is read locked.
2451 static int osd_xattr_get(const struct lu_env *env, struct dt_object *dt,
2452 struct lu_buf *buf, const char *name,
2453 struct lustre_capa *capa)
2455 struct osd_object *obj = osd_dt_obj(dt);
2456 struct inode *inode = obj->oo_inode;
2457 struct osd_thread_info *info = osd_oti_get(env);
2458 struct dentry *dentry = &info->oti_obj_dentry;
2460 /* version get is not real XATTR but uses xattr API */
2461 if (strcmp(name, XATTR_NAME_VERSION) == 0) {
2462 /* for version we are just using xattr API but change inode
2464 LASSERT(buf->lb_len == sizeof(dt_obj_version_t));
2465 osd_object_version_get(env, dt, buf->lb_buf);
2466 return sizeof(dt_obj_version_t);
2469 LASSERT(dt_object_exists(dt));
2470 LASSERT(inode->i_op != NULL && inode->i_op->getxattr != NULL);
2471 LASSERT(osd_read_locked(env, obj) || osd_write_locked(env, obj));
2473 if (osd_object_auth(env, dt, capa, CAPA_OPC_META_READ))
2476 dentry->d_inode = inode;
2477 return inode->i_op->getxattr(dentry, name, buf->lb_buf, buf->lb_len);
2481 static int osd_declare_xattr_set(const struct lu_env *env,
2482 struct dt_object *dt,
2483 const struct lu_buf *buf, const char *name,
2484 int fl, struct thandle *handle)
2486 struct osd_thandle *oh;
2488 LASSERT(handle != NULL);
2490 oh = container_of0(handle, struct osd_thandle, ot_super);
2491 LASSERT(oh->ot_handle == NULL);
2493 OSD_DECLARE_OP(oh, xattr_set);
2494 if (strcmp(name, XATTR_NAME_VERSION) == 0)
2495 oh->ot_credits += osd_dto_credits_noquota[DTO_ATTR_SET_BASE];
2497 oh->ot_credits += osd_dto_credits_noquota[DTO_XATTR_SET];
2503 * Set the 64-bit version for object
2505 static void osd_object_version_set(const struct lu_env *env,
2506 struct dt_object *dt,
2507 dt_obj_version_t *new_version)
2509 struct inode *inode = osd_dt_obj(dt)->oo_inode;
2511 CDEBUG(D_INODE, "Set version "LPX64" (old "LPX64") for inode %lu\n",
2512 *new_version, LDISKFS_I(inode)->i_fs_version, inode->i_ino);
2514 LDISKFS_I(inode)->i_fs_version = *new_version;
2515 /** Version is set after all inode operations are finished,
2516 * so we should mark it dirty here */
2517 inode->i_sb->s_op->dirty_inode(inode);
2521 * Concurrency: @dt is write locked.
2523 static int osd_xattr_set(const struct lu_env *env, struct dt_object *dt,
2524 const struct lu_buf *buf, const char *name, int fl,
2525 struct thandle *handle, struct lustre_capa *capa)
2527 LASSERT(handle != NULL);
2529 /* version set is not real XATTR */
2530 if (strcmp(name, XATTR_NAME_VERSION) == 0) {
2531 /* for version we are just using xattr API but change inode
2533 LASSERT(buf->lb_len == sizeof(dt_obj_version_t));
2534 osd_object_version_set(env, dt, buf->lb_buf);
2535 return sizeof(dt_obj_version_t);
2538 if (osd_object_auth(env, dt, capa, CAPA_OPC_META_WRITE))
2541 OSD_EXEC_OP(handle, xattr_set);
2542 return __osd_xattr_set(env, dt, buf, name, fl);
2546 * Concurrency: @dt is read locked.
2548 static int osd_xattr_list(const struct lu_env *env, struct dt_object *dt,
2549 struct lu_buf *buf, struct lustre_capa *capa)
2551 struct osd_object *obj = osd_dt_obj(dt);
2552 struct inode *inode = obj->oo_inode;
2553 struct osd_thread_info *info = osd_oti_get(env);
2554 struct dentry *dentry = &info->oti_obj_dentry;
2556 LASSERT(dt_object_exists(dt));
2557 LASSERT(inode->i_op != NULL && inode->i_op->listxattr != NULL);
2558 LASSERT(osd_read_locked(env, obj) || osd_write_locked(env, obj));
2560 if (osd_object_auth(env, dt, capa, CAPA_OPC_META_READ))
2563 dentry->d_inode = inode;
2564 return inode->i_op->listxattr(dentry, buf->lb_buf, buf->lb_len);
2567 static int osd_declare_xattr_del(const struct lu_env *env,
2568 struct dt_object *dt, const char *name,
2569 struct thandle *handle)
2571 struct osd_thandle *oh;
2573 LASSERT(dt_object_exists(dt));
2574 LASSERT(handle != NULL);
2576 oh = container_of0(handle, struct osd_thandle, ot_super);
2577 LASSERT(oh->ot_handle == NULL);
2579 OSD_DECLARE_OP(oh, xattr_set);
2580 oh->ot_credits += osd_dto_credits_noquota[DTO_XATTR_SET];
2586 * Concurrency: @dt is write locked.
2588 static int osd_xattr_del(const struct lu_env *env, struct dt_object *dt,
2589 const char *name, struct thandle *handle,
2590 struct lustre_capa *capa)
2592 struct osd_object *obj = osd_dt_obj(dt);
2593 struct inode *inode = obj->oo_inode;
2594 struct osd_thread_info *info = osd_oti_get(env);
2595 struct dentry *dentry = &info->oti_obj_dentry;
2598 LASSERT(dt_object_exists(dt));
2599 LASSERT(inode->i_op != NULL && inode->i_op->removexattr != NULL);
2600 LASSERT(osd_write_locked(env, obj));
2601 LASSERT(handle != NULL);
2603 if (osd_object_auth(env, dt, capa, CAPA_OPC_META_WRITE))
2606 OSD_EXEC_OP(handle, xattr_set);
2608 dentry->d_inode = inode;
2609 rc = inode->i_op->removexattr(dentry, name);
2613 static struct obd_capa *osd_capa_get(const struct lu_env *env,
2614 struct dt_object *dt,
2615 struct lustre_capa *old,
2618 struct osd_thread_info *info = osd_oti_get(env);
2619 const struct lu_fid *fid = lu_object_fid(&dt->do_lu);
2620 struct osd_object *obj = osd_dt_obj(dt);
2621 struct osd_device *dev = osd_obj2dev(obj);
2622 struct lustre_capa_key *key = &info->oti_capa_key;
2623 struct lustre_capa *capa = &info->oti_capa;
2624 struct obd_capa *oc;
2625 struct md_capainfo *ci;
2629 if (!dev->od_fl_capa)
2630 RETURN(ERR_PTR(-ENOENT));
2632 LASSERT(dt_object_exists(dt));
2633 LINVRNT(osd_invariant(obj));
2635 /* renewal sanity check */
2636 if (old && osd_object_auth(env, dt, old, opc))
2637 RETURN(ERR_PTR(-EACCES));
2639 ci = md_capainfo(env);
2641 RETURN(ERR_PTR(-ENOENT));
2643 switch (ci->mc_auth) {
2647 capa->lc_uid = obj->oo_inode->i_uid;
2648 capa->lc_gid = obj->oo_inode->i_gid;
2649 capa->lc_flags = LC_ID_PLAIN;
2651 case LC_ID_CONVERT: {
2654 s[0] = obj->oo_inode->i_uid;
2655 cfs_get_random_bytes(&(s[1]), sizeof(__u32));
2656 s[2] = obj->oo_inode->i_gid;
2657 cfs_get_random_bytes(&(s[3]), sizeof(__u32));
2658 rc = capa_encrypt_id(d, s, key->lk_key, CAPA_HMAC_KEY_MAX_LEN);
2660 RETURN(ERR_PTR(rc));
2662 capa->lc_uid = ((__u64)d[1] << 32) | d[0];
2663 capa->lc_gid = ((__u64)d[3] << 32) | d[2];
2664 capa->lc_flags = LC_ID_CONVERT;
2668 RETURN(ERR_PTR(-EINVAL));
2671 capa->lc_fid = *fid;
2673 capa->lc_flags |= dev->od_capa_alg << 24;
2674 capa->lc_timeout = dev->od_capa_timeout;
2675 capa->lc_expiry = 0;
2677 oc = capa_lookup(dev->od_capa_hash, capa, 1);
2679 LASSERT(!capa_is_expired(oc));
2683 cfs_spin_lock(&capa_lock);
2684 *key = dev->od_capa_keys[1];
2685 cfs_spin_unlock(&capa_lock);
2687 capa->lc_keyid = key->lk_keyid;
2688 capa->lc_expiry = cfs_time_current_sec() + dev->od_capa_timeout;
2690 rc = capa_hmac(capa->lc_hmac, capa, key->lk_key);
2692 DEBUG_CAPA(D_ERROR, capa, "HMAC failed: %d for", rc);
2693 RETURN(ERR_PTR(rc));
2696 oc = capa_add(dev->od_capa_hash, capa);
2700 static int osd_object_sync(const struct lu_env *env, struct dt_object *dt)
2702 struct osd_object *obj = osd_dt_obj(dt);
2703 struct inode *inode = obj->oo_inode;
2704 struct osd_thread_info *info = osd_oti_get(env);
2705 struct dentry *dentry = &info->oti_obj_dentry;
2706 struct file *file = &info->oti_file;
2711 dentry->d_inode = inode;
2712 file->f_dentry = dentry;
2713 file->f_mapping = inode->i_mapping;
2714 file->f_op = inode->i_fop;
2715 mutex_lock(&inode->i_mutex);
2716 rc = file->f_op->fsync(file, dentry, 0);
2717 mutex_unlock(&inode->i_mutex);
2721 static int osd_data_get(const struct lu_env *env, struct dt_object *dt,
2724 struct osd_object *obj = osd_dt_obj(dt);
2727 *data = (void *)obj->oo_inode;
2735 static int osd_iam_index_probe(const struct lu_env *env, struct osd_object *o,
2736 const struct dt_index_features *feat)
2738 struct iam_descr *descr;
2740 if (osd_object_is_root(o))
2741 return feat == &dt_directory_features;
2743 LASSERT(o->oo_dir != NULL);
2745 descr = o->oo_dir->od_container.ic_descr;
2746 if (feat == &dt_directory_features) {
2747 if (descr->id_rec_size == sizeof(struct osd_fid_pack))
2753 feat->dif_keysize_min <= descr->id_key_size &&
2754 descr->id_key_size <= feat->dif_keysize_max &&
2755 feat->dif_recsize_min <= descr->id_rec_size &&
2756 descr->id_rec_size <= feat->dif_recsize_max &&
2757 !(feat->dif_flags & (DT_IND_VARKEY |
2758 DT_IND_VARREC | DT_IND_NONUNQ)) &&
2759 ergo(feat->dif_flags & DT_IND_UPDATE,
2760 1 /* XXX check that object (and file system) is
2765 static int osd_iam_container_init(const struct lu_env *env,
2766 struct osd_object *obj,
2767 struct osd_directory *dir)
2769 struct iam_container *bag = &dir->od_container;
2772 result = iam_container_init(bag, &dir->od_descr, obj->oo_inode);
2776 result = iam_container_setup(bag);
2778 obj->oo_dt.do_index_ops = &osd_index_iam_ops;
2780 iam_container_fini(bag);
2787 * Concurrency: no external locking is necessary.
2789 static int osd_index_try(const struct lu_env *env, struct dt_object *dt,
2790 const struct dt_index_features *feat)
2794 struct osd_object *obj = osd_dt_obj(dt);
2795 struct osd_device *osd = osd_obj2dev(obj);
2797 LINVRNT(osd_invariant(obj));
2798 LASSERT(dt_object_exists(dt));
2800 if (osd_object_is_root(obj)) {
2801 dt->do_index_ops = &osd_index_ea_ops;
2803 } else if (feat == &dt_directory_features && osd->od_iop_mode) {
2804 dt->do_index_ops = &osd_index_ea_ops;
2805 if (S_ISDIR(obj->oo_inode->i_mode))
2810 } else if (unlikely(feat == &dt_otable_features)) {
2811 dt->do_index_ops = &osd_otable_ops;
2813 } else if (feat == &dt_acct_features) {
2814 dt->do_index_ops = &osd_acct_index_ops;
2817 } else if (!osd_has_index(obj)) {
2818 struct osd_directory *dir;
2823 cfs_spin_lock(&obj->oo_guard);
2824 if (obj->oo_dir == NULL)
2828 * Concurrent thread allocated container data.
2831 cfs_spin_unlock(&obj->oo_guard);
2833 * Now, that we have container data, serialize its
2836 cfs_down_write(&obj->oo_ext_idx_sem);
2838 * recheck under lock.
2840 if (!osd_has_index(obj))
2841 result = osd_iam_container_init(env, obj, dir);
2844 cfs_up_write(&obj->oo_ext_idx_sem);
2852 if (result == 0 && skip_iam == 0) {
2853 if (!osd_iam_index_probe(env, obj, feat))
2856 LINVRNT(osd_invariant(obj));
2861 static int osd_otable_it_attr_get(const struct lu_env *env,
2862 struct dt_object *dt,
2863 struct lu_attr *attr,
2864 struct lustre_capa *capa)
2870 static const struct dt_object_operations osd_obj_ops = {
2871 .do_read_lock = osd_object_read_lock,
2872 .do_write_lock = osd_object_write_lock,
2873 .do_read_unlock = osd_object_read_unlock,
2874 .do_write_unlock = osd_object_write_unlock,
2875 .do_write_locked = osd_object_write_locked,
2876 .do_attr_get = osd_attr_get,
2877 .do_declare_attr_set = osd_declare_attr_set,
2878 .do_attr_set = osd_attr_set,
2879 .do_ah_init = osd_ah_init,
2880 .do_declare_create = osd_declare_object_create,
2881 .do_create = osd_object_create,
2882 .do_declare_destroy = osd_declare_object_destroy,
2883 .do_destroy = osd_object_destroy,
2884 .do_index_try = osd_index_try,
2885 .do_declare_ref_add = osd_declare_object_ref_add,
2886 .do_ref_add = osd_object_ref_add,
2887 .do_declare_ref_del = osd_declare_object_ref_del,
2888 .do_ref_del = osd_object_ref_del,
2889 .do_xattr_get = osd_xattr_get,
2890 .do_declare_xattr_set = osd_declare_xattr_set,
2891 .do_xattr_set = osd_xattr_set,
2892 .do_declare_xattr_del = osd_declare_xattr_del,
2893 .do_xattr_del = osd_xattr_del,
2894 .do_xattr_list = osd_xattr_list,
2895 .do_capa_get = osd_capa_get,
2896 .do_object_sync = osd_object_sync,
2897 .do_data_get = osd_data_get,
2901 * dt_object_operations for interoperability mode
2902 * (i.e. to run 2.0 mds on 1.8 disk) (b11826)
2904 static const struct dt_object_operations osd_obj_ea_ops = {
2905 .do_read_lock = osd_object_read_lock,
2906 .do_write_lock = osd_object_write_lock,
2907 .do_read_unlock = osd_object_read_unlock,
2908 .do_write_unlock = osd_object_write_unlock,
2909 .do_write_locked = osd_object_write_locked,
2910 .do_attr_get = osd_attr_get,
2911 .do_declare_attr_set = osd_declare_attr_set,
2912 .do_attr_set = osd_attr_set,
2913 .do_ah_init = osd_ah_init,
2914 .do_declare_create = osd_declare_object_create,
2915 .do_create = osd_object_ea_create,
2916 .do_declare_destroy = osd_declare_object_destroy,
2917 .do_destroy = osd_object_destroy,
2918 .do_index_try = osd_index_try,
2919 .do_declare_ref_add = osd_declare_object_ref_add,
2920 .do_ref_add = osd_object_ref_add,
2921 .do_declare_ref_del = osd_declare_object_ref_del,
2922 .do_ref_del = osd_object_ref_del,
2923 .do_xattr_get = osd_xattr_get,
2924 .do_declare_xattr_set = osd_declare_xattr_set,
2925 .do_xattr_set = osd_xattr_set,
2926 .do_declare_xattr_del = osd_declare_xattr_del,
2927 .do_xattr_del = osd_xattr_del,
2928 .do_xattr_list = osd_xattr_list,
2929 .do_capa_get = osd_capa_get,
2930 .do_object_sync = osd_object_sync,
2931 .do_data_get = osd_data_get,
2934 static const struct dt_object_operations osd_obj_otable_it_ops = {
2935 .do_attr_get = osd_otable_it_attr_get,
2936 .do_index_try = osd_index_try,
2939 static int osd_index_declare_iam_delete(const struct lu_env *env,
2940 struct dt_object *dt,
2941 const struct dt_key *key,
2942 struct thandle *handle)
2944 struct osd_thandle *oh;
2946 oh = container_of0(handle, struct osd_thandle, ot_super);
2947 LASSERT(oh->ot_handle == NULL);
2949 OSD_DECLARE_OP(oh, delete);
2950 oh->ot_credits += osd_dto_credits_noquota[DTO_INDEX_DELETE];
2956 * delete a (key, value) pair from index \a dt specified by \a key
2958 * \param dt osd index object
2959 * \param key key for index
2960 * \param rec record reference
2961 * \param handle transaction handler
2964 * \retval -ve failure
2967 static int osd_index_iam_delete(const struct lu_env *env, struct dt_object *dt,
2968 const struct dt_key *key,
2969 struct thandle *handle,
2970 struct lustre_capa *capa)
2972 struct osd_object *obj = osd_dt_obj(dt);
2973 struct osd_thandle *oh;
2974 struct iam_path_descr *ipd;
2975 struct iam_container *bag = &obj->oo_dir->od_container;
2980 LINVRNT(osd_invariant(obj));
2981 LASSERT(dt_object_exists(dt));
2982 LASSERT(bag->ic_object == obj->oo_inode);
2983 LASSERT(handle != NULL);
2985 if (osd_object_auth(env, dt, capa, CAPA_OPC_INDEX_DELETE))
2988 OSD_EXEC_OP(handle, delete);
2990 ipd = osd_idx_ipd_get(env, bag);
2991 if (unlikely(ipd == NULL))
2994 oh = container_of0(handle, struct osd_thandle, ot_super);
2995 LASSERT(oh->ot_handle != NULL);
2996 LASSERT(oh->ot_handle->h_transaction != NULL);
2998 rc = iam_delete(oh->ot_handle, bag, (const struct iam_key *)key, ipd);
2999 osd_ipd_put(env, bag, ipd);
3000 LINVRNT(osd_invariant(obj));
3004 static int osd_index_declare_ea_delete(const struct lu_env *env,
3005 struct dt_object *dt,
3006 const struct dt_key *key,
3007 struct thandle *handle)
3009 struct osd_thandle *oh;
3010 struct inode *inode;
3014 LASSERT(dt_object_exists(dt));
3015 LASSERT(handle != NULL);
3017 oh = container_of0(handle, struct osd_thandle, ot_super);
3018 LASSERT(oh->ot_handle == NULL);
3020 OSD_DECLARE_OP(oh, delete);
3021 oh->ot_credits += osd_dto_credits_noquota[DTO_INDEX_DELETE];
3023 inode = osd_dt_obj(dt)->oo_inode;
3026 rc = osd_declare_inode_qid(env, inode->i_uid, inode->i_gid, 0, oh,
3027 true, true, NULL, false);
3031 static inline int osd_get_fid_from_dentry(struct ldiskfs_dir_entry_2 *de,
3034 struct osd_fid_pack *rec;
3037 if (de->file_type & LDISKFS_DIRENT_LUFID) {
3038 rec = (struct osd_fid_pack *) (de->name + de->name_len + 1);
3039 rc = osd_fid_unpack((struct lu_fid *)fid, rec);
3045 * Index delete function for interoperability mode (b11826).
3046 * It will remove the directory entry added by osd_index_ea_insert().
3047 * This entry is needed to maintain name->fid mapping.
3049 * \param key, key i.e. file entry to be deleted
3051 * \retval 0, on success
3052 * \retval -ve, on error
3054 static int osd_index_ea_delete(const struct lu_env *env, struct dt_object *dt,
3055 const struct dt_key *key,
3056 struct thandle *handle,
3057 struct lustre_capa *capa)
3059 struct osd_object *obj = osd_dt_obj(dt);
3060 struct inode *dir = obj->oo_inode;
3061 struct dentry *dentry;
3062 struct osd_thandle *oh;
3063 struct ldiskfs_dir_entry_2 *de;
3064 struct buffer_head *bh;
3065 struct htree_lock *hlock = NULL;
3070 LINVRNT(osd_invariant(obj));
3071 LASSERT(dt_object_exists(dt));
3072 LASSERT(handle != NULL);
3074 OSD_EXEC_OP(handle, delete);
3076 oh = container_of(handle, struct osd_thandle, ot_super);
3077 LASSERT(oh->ot_handle != NULL);
3078 LASSERT(oh->ot_handle->h_transaction != NULL);
3080 if (osd_object_auth(env, dt, capa, CAPA_OPC_INDEX_DELETE))
3083 dentry = osd_child_dentry_get(env, obj,
3084 (char *)key, strlen((char *)key));
3086 if (obj->oo_hl_head != NULL) {
3087 hlock = osd_oti_get(env)->oti_hlock;
3088 ldiskfs_htree_lock(hlock, obj->oo_hl_head,
3089 dir, LDISKFS_HLOCK_DEL);
3091 cfs_down_write(&obj->oo_ext_idx_sem);
3094 bh = osd_ldiskfs_find_entry(dir, dentry, &de, hlock);
3096 rc = ldiskfs_delete_entry(oh->ot_handle,
3103 ldiskfs_htree_unlock(hlock);
3105 cfs_up_write(&obj->oo_ext_idx_sem);
3107 LASSERT(osd_invariant(obj));
3112 * Lookup index for \a key and copy record to \a rec.
3114 * \param dt osd index object
3115 * \param key key for index
3116 * \param rec record reference
3118 * \retval +ve success : exact mach
3119 * \retval 0 return record with key not greater than \a key
3120 * \retval -ve failure
3122 static int osd_index_iam_lookup(const struct lu_env *env, struct dt_object *dt,
3123 struct dt_rec *rec, const struct dt_key *key,
3124 struct lustre_capa *capa)
3126 struct osd_object *obj = osd_dt_obj(dt);
3127 struct iam_path_descr *ipd;
3128 struct iam_container *bag = &obj->oo_dir->od_container;
3129 struct osd_thread_info *oti = osd_oti_get(env);
3130 struct iam_iterator *it = &oti->oti_idx_it;
3131 struct iam_rec *iam_rec;
3136 LASSERT(osd_invariant(obj));
3137 LASSERT(dt_object_exists(dt));
3138 LASSERT(bag->ic_object == obj->oo_inode);
3140 if (osd_object_auth(env, dt, capa, CAPA_OPC_INDEX_LOOKUP))
3143 ipd = osd_idx_ipd_get(env, bag);
3147 /* got ipd now we can start iterator. */
3148 iam_it_init(it, bag, 0, ipd);
3150 rc = iam_it_get(it, (struct iam_key *)key);
3152 if (S_ISDIR(obj->oo_inode->i_mode))
3153 iam_rec = (struct iam_rec *)oti->oti_ldp;
3155 iam_rec = (struct iam_rec *) rec;
3157 iam_reccpy(&it->ii_path.ip_leaf, (struct iam_rec *)iam_rec);
3158 if (S_ISDIR(obj->oo_inode->i_mode))
3159 osd_fid_unpack((struct lu_fid *) rec,
3160 (struct osd_fid_pack *)iam_rec);
3164 osd_ipd_put(env, bag, ipd);
3166 LINVRNT(osd_invariant(obj));
3171 static int osd_index_declare_iam_insert(const struct lu_env *env,
3172 struct dt_object *dt,
3173 const struct dt_rec *rec,
3174 const struct dt_key *key,
3175 struct thandle *handle)
3177 struct osd_thandle *oh;
3179 LASSERT(dt_object_exists(dt));
3180 LASSERT(handle != NULL);
3182 oh = container_of0(handle, struct osd_thandle, ot_super);
3183 LASSERT(oh->ot_handle == NULL);
3185 OSD_DECLARE_OP(oh, insert);
3186 oh->ot_credits += osd_dto_credits_noquota[DTO_INDEX_INSERT];
3192 * Inserts (key, value) pair in \a dt index object.
3194 * \param dt osd index object
3195 * \param key key for index
3196 * \param rec record reference
3197 * \param th transaction handler
3200 * \retval -ve failure
3202 static int osd_index_iam_insert(const struct lu_env *env, struct dt_object *dt,
3203 const struct dt_rec *rec,
3204 const struct dt_key *key, struct thandle *th,
3205 struct lustre_capa *capa, int ignore_quota)
3207 struct osd_object *obj = osd_dt_obj(dt);
3208 struct iam_path_descr *ipd;
3209 struct osd_thandle *oh;
3210 struct iam_container *bag = &obj->oo_dir->od_container;
3211 #ifdef HAVE_QUOTA_SUPPORT
3212 cfs_cap_t save = cfs_curproc_cap_pack();
3214 struct osd_thread_info *oti = osd_oti_get(env);
3215 struct iam_rec *iam_rec = (struct iam_rec *)oti->oti_ldp;
3220 LINVRNT(osd_invariant(obj));
3221 LASSERT(dt_object_exists(dt));
3222 LASSERT(bag->ic_object == obj->oo_inode);
3223 LASSERT(th != NULL);
3225 if (osd_object_auth(env, dt, capa, CAPA_OPC_INDEX_INSERT))
3228 OSD_EXEC_OP(th, insert);
3230 ipd = osd_idx_ipd_get(env, bag);
3231 if (unlikely(ipd == NULL))
3234 oh = container_of0(th, struct osd_thandle, ot_super);
3235 LASSERT(oh->ot_handle != NULL);
3236 LASSERT(oh->ot_handle->h_transaction != NULL);
3237 #ifdef HAVE_QUOTA_SUPPORT
3239 cfs_cap_raise(CFS_CAP_SYS_RESOURCE);
3241 cfs_cap_lower(CFS_CAP_SYS_RESOURCE);
3243 if (S_ISDIR(obj->oo_inode->i_mode))
3244 osd_fid_pack((struct osd_fid_pack *)iam_rec, rec, &oti->oti_fid);
3246 iam_rec = (struct iam_rec *) rec;
3247 rc = iam_insert(oh->ot_handle, bag, (const struct iam_key *)key,
3249 #ifdef HAVE_QUOTA_SUPPORT
3250 cfs_curproc_cap_unpack(save);
3252 osd_ipd_put(env, bag, ipd);
3253 LINVRNT(osd_invariant(obj));
3258 * Calls ldiskfs_add_entry() to add directory entry
3259 * into the directory. This is required for
3260 * interoperability mode (b11826)
3262 * \retval 0, on success
3263 * \retval -ve, on error
3265 static int __osd_ea_add_rec(struct osd_thread_info *info,
3266 struct osd_object *pobj, struct inode *cinode,
3267 const char *name, const struct dt_rec *fid,
3268 struct htree_lock *hlock, struct thandle *th)
3270 struct ldiskfs_dentry_param *ldp;
3271 struct dentry *child;
3272 struct osd_thandle *oth;
3275 oth = container_of(th, struct osd_thandle, ot_super);
3276 LASSERT(oth->ot_handle != NULL);
3277 LASSERT(oth->ot_handle->h_transaction != NULL);
3279 child = osd_child_dentry_get(info->oti_env, pobj, name, strlen(name));
3281 /* XXX: remove fid_is_igif() check here.
3282 * IGIF check is just to handle insertion of .. when it is 'ROOT',
3283 * it is IGIF now but needs FID in dir entry as well for readdir
3285 * LU-838 should fix that and remove fid_is_igif() check */
3286 if (fid_is_igif((struct lu_fid *)fid) ||
3287 fid_is_norm((struct lu_fid *)fid)) {
3288 ldp = (struct ldiskfs_dentry_param *)info->oti_ldp;
3289 osd_get_ldiskfs_dirent_param(ldp, fid);
3290 child->d_fsdata = (void *)ldp;
3292 child->d_fsdata = NULL;
3294 rc = osd_ldiskfs_add_entry(oth->ot_handle, child, cinode, hlock);
3300 * Calls ldiskfs_add_dot_dotdot() to add dot and dotdot entries
3301 * into the directory.Also sets flags into osd object to
3302 * indicate dot and dotdot are created. This is required for
3303 * interoperability mode (b11826)
3305 * \param dir directory for dot and dotdot fixup.
3306 * \param obj child object for linking
3308 * \retval 0, on success
3309 * \retval -ve, on error
3311 static int osd_add_dot_dotdot(struct osd_thread_info *info,
3312 struct osd_object *dir,
3313 struct inode *parent_dir, const char *name,
3314 const struct dt_rec *dot_fid,
3315 const struct dt_rec *dot_dot_fid,
3318 struct inode *inode = dir->oo_inode;
3319 struct ldiskfs_dentry_param *dot_ldp;
3320 struct ldiskfs_dentry_param *dot_dot_ldp;
3321 struct osd_thandle *oth;
3324 oth = container_of(th, struct osd_thandle, ot_super);
3325 LASSERT(oth->ot_handle->h_transaction != NULL);
3326 LASSERT(S_ISDIR(dir->oo_inode->i_mode));
3328 if (strcmp(name, dot) == 0) {
3329 if (dir->oo_compat_dot_created) {
3332 LASSERT(inode == parent_dir);
3333 dir->oo_compat_dot_created = 1;
3336 } else if(strcmp(name, dotdot) == 0) {
3337 dot_ldp = (struct ldiskfs_dentry_param *)info->oti_ldp;
3338 dot_dot_ldp = (struct ldiskfs_dentry_param *)info->oti_ldp2;
3340 if (!dir->oo_compat_dot_created)
3342 if (!fid_is_igif((struct lu_fid *)dot_fid)) {
3343 osd_get_ldiskfs_dirent_param(dot_ldp, dot_fid);
3344 osd_get_ldiskfs_dirent_param(dot_dot_ldp, dot_dot_fid);
3349 /* in case of rename, dotdot is already created */
3350 if (dir->oo_compat_dotdot_created) {
3351 return __osd_ea_add_rec(info, dir, parent_dir, name,
3352 dot_dot_fid, NULL, th);
3355 result = ldiskfs_add_dot_dotdot(oth->ot_handle, parent_dir,
3356 inode, dot_ldp, dot_dot_ldp);
3358 dir->oo_compat_dotdot_created = 1;
3366 * It will call the appropriate osd_add* function and return the
3367 * value, return by respective functions.
3369 static int osd_ea_add_rec(const struct lu_env *env, struct osd_object *pobj,
3370 struct inode *cinode, const char *name,
3371 const struct dt_rec *fid, struct thandle *th)
3373 struct osd_thread_info *info = osd_oti_get(env);
3374 struct htree_lock *hlock;
3377 hlock = pobj->oo_hl_head != NULL ? info->oti_hlock : NULL;
3379 if (name[0] == '.' && (name[1] == '\0' || (name[1] == '.' &&
3381 if (hlock != NULL) {
3382 ldiskfs_htree_lock(hlock, pobj->oo_hl_head,
3385 cfs_down_write(&pobj->oo_ext_idx_sem);
3387 rc = osd_add_dot_dotdot(info, pobj, cinode, name,
3388 (struct dt_rec *)lu_object_fid(&pobj->oo_dt.do_lu),
3391 if (hlock != NULL) {
3392 ldiskfs_htree_lock(hlock, pobj->oo_hl_head,
3393 pobj->oo_inode, LDISKFS_HLOCK_ADD);
3395 cfs_down_write(&pobj->oo_ext_idx_sem);
3398 rc = __osd_ea_add_rec(info, pobj, cinode, name, fid,
3402 ldiskfs_htree_unlock(hlock);
3404 cfs_up_write(&pobj->oo_ext_idx_sem);
3410 osd_consistency_check(struct osd_thread_info *oti, struct osd_device *dev,
3411 struct osd_idmap_cache *oic)
3413 struct osd_scrub *scrub = &dev->od_scrub;
3414 struct lu_fid *fid = &oic->oic_fid;
3415 struct osd_inode_id *id = &oti->oti_id;
3421 rc = osd_oi_lookup(oti, dev, fid, id);
3422 if (rc != 0 && rc != -ENOENT)
3425 if (rc == 0 && osd_id_eq(id, &oic->oic_lid))
3428 if (thread_is_running(&scrub->os_thread)) {
3429 rc = osd_oii_insert(dev, oic, rc == -ENOENT);
3430 /* There is race condition between osd_oi_lookup and OI scrub.
3431 * The OI scrub finished just after osd_oi_lookup() failure.
3432 * Under such case, it is unnecessary to trigger OI scrub again,
3433 * but try to call osd_oi_lookup() again. */
3434 if (unlikely(rc == -EAGAIN))
3440 if (!scrub->os_no_scrub && ++once == 1) {
3441 CDEBUG(D_LFSCK, "Trigger OI scrub by RPC for "DFID"\n",
3443 rc = osd_scrub_start(dev);
3444 LCONSOLE_ERROR("%.16s: trigger OI scrub by RPC for "DFID
3446 LDISKFS_SB(osd_sb(dev))->s_es->s_volume_name,
3452 RETURN(rc = -EREMCHG);
3456 * Calls ->lookup() to find dentry. From dentry get inode and
3457 * read inode's ea to get fid. This is required for interoperability
3460 * \retval 0, on success
3461 * \retval -ve, on error
3463 static int osd_ea_lookup_rec(const struct lu_env *env, struct osd_object *obj,
3464 struct dt_rec *rec, const struct dt_key *key)
3466 struct inode *dir = obj->oo_inode;
3467 struct dentry *dentry;
3468 struct ldiskfs_dir_entry_2 *de;
3469 struct buffer_head *bh;
3470 struct lu_fid *fid = (struct lu_fid *) rec;
3471 struct htree_lock *hlock = NULL;
3475 LASSERT(dir->i_op != NULL && dir->i_op->lookup != NULL);
3477 dentry = osd_child_dentry_get(env, obj,
3478 (char *)key, strlen((char *)key));
3480 if (obj->oo_hl_head != NULL) {
3481 hlock = osd_oti_get(env)->oti_hlock;
3482 ldiskfs_htree_lock(hlock, obj->oo_hl_head,
3483 dir, LDISKFS_HLOCK_LOOKUP);
3485 cfs_down_read(&obj->oo_ext_idx_sem);
3488 bh = osd_ldiskfs_find_entry(dir, dentry, &de, hlock);
3490 struct osd_thread_info *oti = osd_oti_get(env);
3491 struct osd_idmap_cache *oic = &oti->oti_cache;
3492 struct osd_device *dev = osd_obj2dev(obj);
3493 struct osd_scrub *scrub = &dev->od_scrub;
3494 struct scrub_file *sf = &scrub->os_file;
3496 ino = le32_to_cpu(de->inode);
3497 rc = osd_get_fid_from_dentry(de, rec);
3499 /* done with de, release bh */
3502 rc = osd_ea_fid_get(env, obj, ino, fid, &oic->oic_lid);
3504 osd_id_gen(&oic->oic_lid, ino, OSD_OII_NOGEN);
3505 if (rc != 0 || !fid_is_norm(fid)) {
3506 fid_zero(&oic->oic_fid);
3510 oic->oic_fid = *fid;
3511 if ((scrub->os_pos_current <= ino) &&
3512 (sf->sf_flags & SF_INCONSISTENT ||
3513 ldiskfs_test_bit(osd_oi_fid2idx(dev, fid),
3515 rc = osd_consistency_check(oti, dev, oic);
3524 ldiskfs_htree_unlock(hlock);
3526 cfs_up_read(&obj->oo_ext_idx_sem);
3531 * Find the osd object for given fid.
3533 * \param fid need to find the osd object having this fid
3535 * \retval osd_object on success
3536 * \retval -ve on error
3538 struct osd_object *osd_object_find(const struct lu_env *env,
3539 struct dt_object *dt,
3540 const struct lu_fid *fid)
3542 struct lu_device *ludev = dt->do_lu.lo_dev;
3543 struct osd_object *child = NULL;
3544 struct lu_object *luch;
3545 struct lu_object *lo;
3548 * at this point topdev might not exist yet
3549 * (i.e. MGS is preparing profiles). so we can
3550 * not rely on topdev and instead lookup with
3551 * our device passed as topdev. this can't work
3552 * if the object isn't cached yet (as osd doesn't
3553 * allocate lu_header). IOW, the object must be
3554 * in the cache, otherwise lu_object_alloc() crashes
3557 luch = lu_object_find_at(env, ludev, fid, NULL);
3558 if (!IS_ERR(luch)) {
3559 if (lu_object_exists(luch)) {
3560 lo = lu_object_locate(luch->lo_header, ludev->ld_type);
3562 child = osd_obj(lo);
3564 LU_OBJECT_DEBUG(D_ERROR, env, luch,
3565 "lu_object can't be located"
3566 DFID"\n", PFID(fid));
3568 if (child == NULL) {
3569 lu_object_put(env, luch);
3570 CERROR("Unable to get osd_object\n");
3571 child = ERR_PTR(-ENOENT);
3574 LU_OBJECT_DEBUG(D_ERROR, env, luch,
3575 "lu_object does not exists "DFID"\n",
3577 lu_object_put(env, luch);
3578 child = ERR_PTR(-ENOENT);
3581 child = (void *)luch;
3587 * Put the osd object once done with it.
3589 * \param obj osd object that needs to be put
3591 static inline void osd_object_put(const struct lu_env *env,
3592 struct osd_object *obj)
3594 lu_object_put(env, &obj->oo_dt.do_lu);
3597 static int osd_index_declare_ea_insert(const struct lu_env *env,
3598 struct dt_object *dt,
3599 const struct dt_rec *rec,
3600 const struct dt_key *key,
3601 struct thandle *handle)
3603 struct osd_thandle *oh;
3604 struct inode *inode;
3608 LASSERT(dt_object_exists(dt));
3609 LASSERT(handle != NULL);
3611 oh = container_of0(handle, struct osd_thandle, ot_super);
3612 LASSERT(oh->ot_handle == NULL);
3614 OSD_DECLARE_OP(oh, insert);
3615 oh->ot_credits += osd_dto_credits_noquota[DTO_INDEX_INSERT];
3617 inode = osd_dt_obj(dt)->oo_inode;
3620 /* We ignore block quota on meta pool (MDTs), so needn't
3621 * calculate how many blocks will be consumed by this index
3623 rc = osd_declare_inode_qid(env, inode->i_uid, inode->i_gid, 0, oh,
3624 true, true, NULL, false);
3629 * Index add function for interoperability mode (b11826).
3630 * It will add the directory entry.This entry is needed to
3631 * maintain name->fid mapping.
3633 * \param key it is key i.e. file entry to be inserted
3634 * \param rec it is value of given key i.e. fid
3636 * \retval 0, on success
3637 * \retval -ve, on error
3639 static int osd_index_ea_insert(const struct lu_env *env, struct dt_object *dt,
3640 const struct dt_rec *rec,
3641 const struct dt_key *key, struct thandle *th,
3642 struct lustre_capa *capa, int ignore_quota)
3644 struct osd_object *obj = osd_dt_obj(dt);
3645 struct lu_fid *fid = (struct lu_fid *) rec;
3646 const char *name = (const char *)key;
3647 struct osd_object *child;
3648 #ifdef HAVE_QUOTA_SUPPORT
3649 cfs_cap_t save = cfs_curproc_cap_pack();
3655 LASSERT(osd_invariant(obj));
3656 LASSERT(dt_object_exists(dt));
3657 LASSERT(th != NULL);
3659 if (osd_object_auth(env, dt, capa, CAPA_OPC_INDEX_INSERT))
3662 child = osd_object_find(env, dt, fid);
3663 if (!IS_ERR(child)) {
3664 #ifdef HAVE_QUOTA_SUPPORT
3666 cfs_cap_raise(CFS_CAP_SYS_RESOURCE);
3668 cfs_cap_lower(CFS_CAP_SYS_RESOURCE);
3670 rc = osd_ea_add_rec(env, obj, child->oo_inode, name, rec, th);
3671 #ifdef HAVE_QUOTA_SUPPORT
3672 cfs_curproc_cap_unpack(save);
3674 osd_object_put(env, child);
3676 rc = PTR_ERR(child);
3679 LASSERT(osd_invariant(obj));
3684 * Initialize osd Iterator for given osd index object.
3686 * \param dt osd index object
3689 static struct dt_it *osd_it_iam_init(const struct lu_env *env,
3690 struct dt_object *dt,
3692 struct lustre_capa *capa)
3694 struct osd_it_iam *it;
3695 struct osd_thread_info *oti = osd_oti_get(env);
3696 struct osd_object *obj = osd_dt_obj(dt);
3697 struct lu_object *lo = &dt->do_lu;
3698 struct iam_path_descr *ipd;
3699 struct iam_container *bag = &obj->oo_dir->od_container;
3701 LASSERT(lu_object_exists(lo));
3703 if (osd_object_auth(env, dt, capa, CAPA_OPC_BODY_READ))
3704 return ERR_PTR(-EACCES);
3707 ipd = osd_it_ipd_get(env, bag);
3708 if (likely(ipd != NULL)) {
3712 iam_it_init(&it->oi_it, bag, IAM_IT_MOVE, ipd);
3713 return (struct dt_it *)it;
3715 return ERR_PTR(-ENOMEM);
3719 * free given Iterator.
3722 static void osd_it_iam_fini(const struct lu_env *env, struct dt_it *di)
3724 struct osd_it_iam *it = (struct osd_it_iam *)di;
3725 struct osd_object *obj = it->oi_obj;
3727 iam_it_fini(&it->oi_it);
3728 osd_ipd_put(env, &obj->oo_dir->od_container, it->oi_ipd);
3729 lu_object_put(env, &obj->oo_dt.do_lu);
3733 * Move Iterator to record specified by \a key
3735 * \param di osd iterator
3736 * \param key key for index
3738 * \retval +ve di points to record with least key not larger than key
3739 * \retval 0 di points to exact matched key
3740 * \retval -ve failure
3743 static int osd_it_iam_get(const struct lu_env *env,
3744 struct dt_it *di, const struct dt_key *key)
3746 struct osd_it_iam *it = (struct osd_it_iam *)di;
3748 return iam_it_get(&it->oi_it, (const struct iam_key *)key);
3754 * \param di osd iterator
3757 static void osd_it_iam_put(const struct lu_env *env, struct dt_it *di)
3759 struct osd_it_iam *it = (struct osd_it_iam *)di;
3761 iam_it_put(&it->oi_it);
3765 * Move iterator by one record
3767 * \param di osd iterator
3769 * \retval +1 end of container reached
3771 * \retval -ve failure
3774 static int osd_it_iam_next(const struct lu_env *env, struct dt_it *di)
3776 struct osd_it_iam *it = (struct osd_it_iam *)di;
3778 return iam_it_next(&it->oi_it);
3782 * Return pointer to the key under iterator.
3785 static struct dt_key *osd_it_iam_key(const struct lu_env *env,
3786 const struct dt_it *di)
3788 struct osd_it_iam *it = (struct osd_it_iam *)di;
3790 return (struct dt_key *)iam_it_key_get(&it->oi_it);
3794 * Return size of key under iterator (in bytes)
3797 static int osd_it_iam_key_size(const struct lu_env *env, const struct dt_it *di)
3799 struct osd_it_iam *it = (struct osd_it_iam *)di;
3801 return iam_it_key_size(&it->oi_it);
3804 static inline void osd_it_append_attrs(struct lu_dirent *ent, __u32 attr,
3805 int len, __u16 type)
3807 struct luda_type *lt;
3808 const unsigned align = sizeof(struct luda_type) - 1;
3810 /* check if file type is required */
3811 if (attr & LUDA_TYPE) {
3812 len = (len + align) & ~align;
3814 lt = (void *) ent->lde_name + len;
3815 lt->lt_type = cpu_to_le16(CFS_DTTOIF(type));
3816 ent->lde_attrs |= LUDA_TYPE;
3819 ent->lde_attrs = cpu_to_le32(ent->lde_attrs);
3823 * build lu direct from backend fs dirent.
3826 static inline void osd_it_pack_dirent(struct lu_dirent *ent,
3827 struct lu_fid *fid, __u64 offset,
3828 char *name, __u16 namelen,
3829 __u16 type, __u32 attr)
3831 fid_cpu_to_le(&ent->lde_fid, fid);
3832 ent->lde_attrs = LUDA_FID;
3834 ent->lde_hash = cpu_to_le64(offset);
3835 ent->lde_reclen = cpu_to_le16(lu_dirent_calc_size(namelen, attr));
3837 strncpy(ent->lde_name, name, namelen);
3838 ent->lde_namelen = cpu_to_le16(namelen);
3840 /* append lustre attributes */
3841 osd_it_append_attrs(ent, attr, namelen, type);
3845 * Return pointer to the record under iterator.
3847 static int osd_it_iam_rec(const struct lu_env *env,
3848 const struct dt_it *di,
3849 struct dt_rec *dtrec, __u32 attr)
3851 struct osd_it_iam *it = (struct osd_it_iam *)di;
3852 struct osd_thread_info *info = osd_oti_get(env);
3855 if (S_ISDIR(it->oi_obj->oo_inode->i_mode)) {
3856 const struct osd_fid_pack *rec;
3857 struct lu_fid *fid = &info->oti_fid;
3858 struct lu_dirent *lde = (struct lu_dirent *)dtrec;
3864 name = (char *)iam_it_key_get(&it->oi_it);
3866 RETURN(PTR_ERR(name));
3868 namelen = iam_it_key_size(&it->oi_it);
3870 rec = (const struct osd_fid_pack *)iam_it_rec_get(&it->oi_it);
3872 RETURN(PTR_ERR(rec));
3874 rc = osd_fid_unpack(fid, rec);
3878 hash = iam_it_store(&it->oi_it);
3880 /* IAM does not store object type in IAM index (dir) */
3881 osd_it_pack_dirent(lde, fid, hash, name, namelen,
3884 iam_reccpy(&it->oi_it.ii_path.ip_leaf,
3885 (struct iam_rec *)dtrec);
3892 * Returns cookie for current Iterator position.
3894 static __u64 osd_it_iam_store(const struct lu_env *env, const struct dt_it *di)
3896 struct osd_it_iam *it = (struct osd_it_iam *)di;
3898 return iam_it_store(&it->oi_it);
3902 * Restore iterator from cookie.
3904 * \param di osd iterator
3905 * \param hash Iterator location cookie
3907 * \retval +ve di points to record with least key not larger than key.
3908 * \retval 0 di points to exact matched key
3909 * \retval -ve failure
3912 static int osd_it_iam_load(const struct lu_env *env,
3913 const struct dt_it *di, __u64 hash)
3915 struct osd_it_iam *it = (struct osd_it_iam *)di;
3917 return iam_it_load(&it->oi_it, hash);
3920 static const struct dt_index_operations osd_index_iam_ops = {
3921 .dio_lookup = osd_index_iam_lookup,
3922 .dio_declare_insert = osd_index_declare_iam_insert,
3923 .dio_insert = osd_index_iam_insert,
3924 .dio_declare_delete = osd_index_declare_iam_delete,
3925 .dio_delete = osd_index_iam_delete,
3927 .init = osd_it_iam_init,
3928 .fini = osd_it_iam_fini,
3929 .get = osd_it_iam_get,
3930 .put = osd_it_iam_put,
3931 .next = osd_it_iam_next,
3932 .key = osd_it_iam_key,
3933 .key_size = osd_it_iam_key_size,
3934 .rec = osd_it_iam_rec,
3935 .store = osd_it_iam_store,
3936 .load = osd_it_iam_load
3941 * Creates or initializes iterator context.
3943 * \retval struct osd_it_ea, iterator structure on success
3946 static struct dt_it *osd_it_ea_init(const struct lu_env *env,
3947 struct dt_object *dt,
3949 struct lustre_capa *capa)
3951 struct osd_object *obj = osd_dt_obj(dt);
3952 struct osd_thread_info *info = osd_oti_get(env);
3953 struct osd_it_ea *it = &info->oti_it_ea;
3954 struct lu_object *lo = &dt->do_lu;
3955 struct dentry *obj_dentry = &info->oti_it_dentry;
3957 LASSERT(lu_object_exists(lo));
3959 obj_dentry->d_inode = obj->oo_inode;
3960 obj_dentry->d_sb = osd_sb(osd_obj2dev(obj));
3961 obj_dentry->d_name.hash = 0;
3963 it->oie_rd_dirent = 0;
3964 it->oie_it_dirent = 0;
3965 it->oie_dirent = NULL;
3966 it->oie_buf = info->oti_it_ea_buf;
3968 it->oie_file.f_pos = 0;
3969 it->oie_file.f_dentry = obj_dentry;
3970 if (attr & LUDA_64BITHASH)
3971 it->oie_file.f_mode |= FMODE_64BITHASH;
3973 it->oie_file.f_mode |= FMODE_32BITHASH;
3974 it->oie_file.f_mapping = obj->oo_inode->i_mapping;
3975 it->oie_file.f_op = obj->oo_inode->i_fop;
3976 it->oie_file.private_data = NULL;
3978 RETURN((struct dt_it *) it);
3982 * Destroy or finishes iterator context.
3984 * \param di iterator structure to be destroyed
3986 static void osd_it_ea_fini(const struct lu_env *env, struct dt_it *di)
3988 struct osd_it_ea *it = (struct osd_it_ea *)di;
3989 struct osd_object *obj = it->oie_obj;
3990 struct inode *inode = obj->oo_inode;
3993 it->oie_file.f_op->release(inode, &it->oie_file);
3994 lu_object_put(env, &obj->oo_dt.do_lu);
3999 * It position the iterator at given key, so that next lookup continues from
4000 * that key Or it is similar to dio_it->load() but based on a key,
4001 * rather than file position.
4003 * As a special convention, osd_it_ea_get(env, di, "") has to rewind iterator
4006 * TODO: Presently return +1 considering it is only used by mdd_dir_is_empty().
4008 static int osd_it_ea_get(const struct lu_env *env,
4009 struct dt_it *di, const struct dt_key *key)
4011 struct osd_it_ea *it = (struct osd_it_ea *)di;
4014 LASSERT(((const char *)key)[0] == '\0');
4015 it->oie_file.f_pos = 0;
4016 it->oie_rd_dirent = 0;
4017 it->oie_it_dirent = 0;
4018 it->oie_dirent = NULL;
4026 static void osd_it_ea_put(const struct lu_env *env, struct dt_it *di)
4031 * It is called internally by ->readdir(). It fills the
4032 * iterator's in-memory data structure with required
4033 * information i.e. name, namelen, rec_size etc.
4035 * \param buf in which information to be filled in.
4036 * \param name name of the file in given dir
4038 * \retval 0 on success
4039 * \retval 1 on buffer full
4041 static int osd_ldiskfs_filldir(char *buf, const char *name, int namelen,
4042 loff_t offset, __u64 ino,
4045 struct osd_it_ea *it = (struct osd_it_ea *)buf;
4046 struct osd_it_ea_dirent *ent = it->oie_dirent;
4047 struct lu_fid *fid = &ent->oied_fid;
4048 struct osd_fid_pack *rec;
4051 /* this should never happen */
4052 if (unlikely(namelen == 0 || namelen > LDISKFS_NAME_LEN)) {
4053 CERROR("ldiskfs return invalid namelen %d\n", namelen);
4057 if ((void *) ent - it->oie_buf + sizeof(*ent) + namelen >
4061 if (d_type & LDISKFS_DIRENT_LUFID) {
4062 rec = (struct osd_fid_pack*) (name + namelen + 1);
4064 if (osd_fid_unpack(fid, rec) != 0)
4067 d_type &= ~LDISKFS_DIRENT_LUFID;
4072 ent->oied_ino = ino;
4073 ent->oied_off = offset;
4074 ent->oied_namelen = namelen;
4075 ent->oied_type = d_type;
4077 memcpy(ent->oied_name, name, namelen);
4079 it->oie_rd_dirent++;
4080 it->oie_dirent = (void *) ent + cfs_size_round(sizeof(*ent) + namelen);
4085 * Calls ->readdir() to load a directory entry at a time
4086 * and stored it in iterator's in-memory data structure.
4088 * \param di iterator's in memory structure
4090 * \retval 0 on success
4091 * \retval -ve on error
4093 static int osd_ldiskfs_it_fill(const struct lu_env *env,
4094 const struct dt_it *di)
4096 struct osd_it_ea *it = (struct osd_it_ea *)di;
4097 struct osd_object *obj = it->oie_obj;
4098 struct inode *inode = obj->oo_inode;
4099 struct htree_lock *hlock = NULL;
4103 it->oie_dirent = it->oie_buf;
4104 it->oie_rd_dirent = 0;
4106 if (obj->oo_hl_head != NULL) {
4107 hlock = osd_oti_get(env)->oti_hlock;
4108 ldiskfs_htree_lock(hlock, obj->oo_hl_head,
4109 inode, LDISKFS_HLOCK_READDIR);
4111 cfs_down_read(&obj->oo_ext_idx_sem);
4114 result = inode->i_fop->readdir(&it->oie_file, it,
4115 (filldir_t) osd_ldiskfs_filldir);
4118 ldiskfs_htree_unlock(hlock);
4120 cfs_up_read(&obj->oo_ext_idx_sem);
4122 if (it->oie_rd_dirent == 0) {
4125 it->oie_dirent = it->oie_buf;
4126 it->oie_it_dirent = 1;
4133 * It calls osd_ldiskfs_it_fill() which will use ->readdir()
4134 * to load a directory entry at a time and stored it in
4135 * iterator's in-memory data structure.
4137 * \param di iterator's in memory structure
4139 * \retval +ve iterator reached to end
4140 * \retval 0 iterator not reached to end
4141 * \retval -ve on error
4143 static int osd_it_ea_next(const struct lu_env *env, struct dt_it *di)
4145 struct osd_it_ea *it = (struct osd_it_ea *)di;
4150 if (it->oie_it_dirent < it->oie_rd_dirent) {
4152 (void *) it->oie_dirent +
4153 cfs_size_round(sizeof(struct osd_it_ea_dirent) +
4154 it->oie_dirent->oied_namelen);
4155 it->oie_it_dirent++;
4158 if (it->oie_file.f_pos == ldiskfs_get_htree_eof(&it->oie_file))
4161 rc = osd_ldiskfs_it_fill(env, di);
4168 * Returns the key at current position from iterator's in memory structure.
4170 * \param di iterator's in memory structure
4172 * \retval key i.e. struct dt_key on success
4174 static struct dt_key *osd_it_ea_key(const struct lu_env *env,
4175 const struct dt_it *di)
4177 struct osd_it_ea *it = (struct osd_it_ea *)di;
4179 return (struct dt_key *)it->oie_dirent->oied_name;
4183 * Returns the key's size at current position from iterator's in memory structure.
4185 * \param di iterator's in memory structure
4187 * \retval key_size i.e. struct dt_key on success
4189 static int osd_it_ea_key_size(const struct lu_env *env, const struct dt_it *di)
4191 struct osd_it_ea *it = (struct osd_it_ea *)di;
4193 return it->oie_dirent->oied_namelen;
4198 * Returns the value (i.e. fid/igif) at current position from iterator's
4199 * in memory structure.
4201 * \param di struct osd_it_ea, iterator's in memory structure
4202 * \param attr attr requested for dirent.
4203 * \param lde lustre dirent
4205 * \retval 0 no error and \param lde has correct lustre dirent.
4206 * \retval -ve on error
4208 static inline int osd_it_ea_rec(const struct lu_env *env,
4209 const struct dt_it *di,
4210 struct dt_rec *dtrec, __u32 attr)
4212 struct osd_it_ea *it = (struct osd_it_ea *)di;
4213 struct osd_object *obj = it->oie_obj;
4214 struct osd_device *dev = osd_obj2dev(obj);
4215 struct osd_scrub *scrub = &dev->od_scrub;
4216 struct scrub_file *sf = &scrub->os_file;
4217 struct osd_thread_info *oti = osd_oti_get(env);
4218 struct osd_idmap_cache *oic = &oti->oti_cache;
4219 struct lu_fid *fid = &it->oie_dirent->oied_fid;
4220 struct lu_dirent *lde = (struct lu_dirent *)dtrec;
4221 __u32 ino = it->oie_dirent->oied_ino;
4225 if (!fid_is_sane(fid)) {
4226 rc = osd_ea_fid_get(env, obj, ino, fid, &oic->oic_lid);
4230 osd_id_gen(&oic->oic_lid, ino, OSD_OII_NOGEN);
4233 osd_it_pack_dirent(lde, fid, it->oie_dirent->oied_off,
4234 it->oie_dirent->oied_name,
4235 it->oie_dirent->oied_namelen,
4236 it->oie_dirent->oied_type, attr);
4237 if (!fid_is_norm(fid)) {
4238 fid_zero(&oic->oic_fid);
4242 oic->oic_fid = *fid;
4243 if ((scrub->os_pos_current <= ino) &&
4244 (sf->sf_flags & SF_INCONSISTENT ||
4245 ldiskfs_test_bit(osd_oi_fid2idx(dev, fid), sf->sf_oi_bitmap)))
4246 rc = osd_consistency_check(oti, dev, oic);
4252 * Returns a cookie for current position of the iterator head, so that
4253 * user can use this cookie to load/start the iterator next time.
4255 * \param di iterator's in memory structure
4257 * \retval cookie for current position, on success
4259 static __u64 osd_it_ea_store(const struct lu_env *env, const struct dt_it *di)
4261 struct osd_it_ea *it = (struct osd_it_ea *)di;
4263 return it->oie_dirent->oied_off;
4267 * It calls osd_ldiskfs_it_fill() which will use ->readdir()
4268 * to load a directory entry at a time and stored it i inn,
4269 * in iterator's in-memory data structure.
4271 * \param di struct osd_it_ea, iterator's in memory structure
4273 * \retval +ve on success
4274 * \retval -ve on error
4276 static int osd_it_ea_load(const struct lu_env *env,
4277 const struct dt_it *di, __u64 hash)
4279 struct osd_it_ea *it = (struct osd_it_ea *)di;
4283 it->oie_file.f_pos = hash;
4285 rc = osd_ldiskfs_it_fill(env, di);
4293 * Index lookup function for interoperability mode (b11826).
4295 * \param key, key i.e. file name to be searched
4297 * \retval +ve, on success
4298 * \retval -ve, on error
4300 static int osd_index_ea_lookup(const struct lu_env *env, struct dt_object *dt,
4301 struct dt_rec *rec, const struct dt_key *key,
4302 struct lustre_capa *capa)
4304 struct osd_object *obj = osd_dt_obj(dt);
4309 LASSERT(S_ISDIR(obj->oo_inode->i_mode));
4310 LINVRNT(osd_invariant(obj));
4312 if (osd_object_auth(env, dt, capa, CAPA_OPC_INDEX_LOOKUP))
4315 rc = osd_ea_lookup_rec(env, obj, rec, key);
4323 * Index and Iterator operations for interoperability
4324 * mode (i.e. to run 2.0 mds on 1.8 disk) (b11826)
4326 static const struct dt_index_operations osd_index_ea_ops = {
4327 .dio_lookup = osd_index_ea_lookup,
4328 .dio_declare_insert = osd_index_declare_ea_insert,
4329 .dio_insert = osd_index_ea_insert,
4330 .dio_declare_delete = osd_index_declare_ea_delete,
4331 .dio_delete = osd_index_ea_delete,
4333 .init = osd_it_ea_init,
4334 .fini = osd_it_ea_fini,
4335 .get = osd_it_ea_get,
4336 .put = osd_it_ea_put,
4337 .next = osd_it_ea_next,
4338 .key = osd_it_ea_key,
4339 .key_size = osd_it_ea_key_size,
4340 .rec = osd_it_ea_rec,
4341 .store = osd_it_ea_store,
4342 .load = osd_it_ea_load
4346 static void *osd_key_init(const struct lu_context *ctx,
4347 struct lu_context_key *key)
4349 struct osd_thread_info *info;
4351 OBD_ALLOC_PTR(info);
4353 return ERR_PTR(-ENOMEM);
4355 OBD_ALLOC(info->oti_it_ea_buf, OSD_IT_EA_BUFSIZE);
4356 if (info->oti_it_ea_buf == NULL)
4359 info->oti_env = container_of(ctx, struct lu_env, le_ctx);
4361 info->oti_hlock = ldiskfs_htree_lock_alloc();
4362 if (info->oti_hlock == NULL)
4368 OBD_FREE(info->oti_it_ea_buf, OSD_IT_EA_BUFSIZE);
4371 return ERR_PTR(-ENOMEM);
4374 static void osd_key_fini(const struct lu_context *ctx,
4375 struct lu_context_key *key, void* data)
4377 struct osd_thread_info *info = data;
4379 if (info->oti_hlock != NULL)
4380 ldiskfs_htree_lock_free(info->oti_hlock);
4381 OBD_FREE(info->oti_it_ea_buf, OSD_IT_EA_BUFSIZE);
4385 static void osd_key_exit(const struct lu_context *ctx,
4386 struct lu_context_key *key, void *data)
4388 struct osd_thread_info *info = data;
4390 LASSERT(info->oti_r_locks == 0);
4391 LASSERT(info->oti_w_locks == 0);
4392 LASSERT(info->oti_txns == 0);
4395 /* type constructor/destructor: osd_type_init, osd_type_fini */
4396 LU_TYPE_INIT_FINI(osd, &osd_key);
4398 struct lu_context_key osd_key = {
4399 .lct_tags = LCT_DT_THREAD | LCT_MD_THREAD | LCT_MG_THREAD | LCT_LOCAL,
4400 .lct_init = osd_key_init,
4401 .lct_fini = osd_key_fini,
4402 .lct_exit = osd_key_exit
4406 static int osd_device_init(const struct lu_env *env, struct lu_device *d,
4407 const char *name, struct lu_device *next)
4409 struct osd_device *osd = osd_dev(d);
4411 strncpy(osd->od_svname, name, MAX_OBD_NAME);
4412 return osd_procfs_init(osd, name);
4415 static int osd_shutdown(const struct lu_env *env, struct osd_device *o)
4419 osd_scrub_cleanup(env, o);
4422 fsfilt_put_ops(o->od_fsops);
4426 /* shutdown quota slave instance associated with the device */
4427 if (o->od_quota_slave != NULL) {
4428 qsd_fini(env, o->od_quota_slave);
4429 o->od_quota_slave = NULL;
4435 static int osd_mount(const struct lu_env *env,
4436 struct osd_device *o, struct lustre_cfg *cfg)
4438 const char *name = lustre_cfg_string(cfg, 0);
4439 const char *dev = lustre_cfg_string(cfg, 1);
4441 unsigned long page, s_flags, lmd_flags = 0;
4442 struct page *__page;
4443 struct file_system_type *type;
4444 char *options = NULL;
4449 if (o->od_mnt != NULL)
4452 o->od_fsops = fsfilt_get_ops(mt_str(LDD_MT_LDISKFS));
4453 if (o->od_fsops == NULL) {
4454 CERROR("Can't find fsfilt_ldiskfs\n");
4458 OBD_PAGE_ALLOC(__page, CFS_ALLOC_STD);
4462 str = lustre_cfg_string(cfg, 2);
4463 s_flags = simple_strtoul(str, NULL, 0);
4464 str = strstr(str, ":");
4466 lmd_flags = simple_strtoul(str + 1, NULL, 0);
4467 opts = lustre_cfg_string(cfg, 3);
4468 page = (unsigned long)cfs_page_address(__page);
4469 options = (char *)page;
4472 strcat(options, "user_xattr,acl");
4474 strcat(options, opts);
4476 /* Glom up mount options */
4477 if (*options != '\0')
4478 strcat(options, ",");
4479 strlcat(options, "no_mbcache", CFS_PAGE_SIZE);
4481 type = get_fs_type("ldiskfs");
4483 CERROR("%s: cannot find ldiskfs module\n", name);
4484 GOTO(out, rc = -ENODEV);
4487 o->od_mnt = vfs_kern_mount(type, s_flags, dev, options);
4488 cfs_module_put(type->owner);
4490 if (IS_ERR(o->od_mnt)) {
4491 rc = PTR_ERR(o->od_mnt);
4492 CERROR("%s: can't mount %s: %d\n", name, dev, rc);
4497 if (lvfs_check_rdonly(o->od_mnt->mnt_sb->s_bdev)) {
4498 CERROR("%s: underlying device %s is marked as read-only. "
4499 "Setup failed\n", name, dev);
4502 GOTO(out, rc = -EROFS);
4505 if (!LDISKFS_HAS_COMPAT_FEATURE(o->od_mnt->mnt_sb,
4506 LDISKFS_FEATURE_COMPAT_HAS_JOURNAL)) {
4507 CERROR("%s: device %s is mounted w/o journal\n", name, dev);
4510 GOTO(out, rc = -EINVAL);
4513 if (lmd_flags & LMD_FLG_IAM) {
4515 LCONSOLE_WARN("%s: OSD: IAM mode enabled\n", name);
4518 if (lmd_flags & LMD_FLG_NOSCRUB)
4519 o->od_scrub.os_no_scrub = 1;
4523 OBD_PAGE_FREE(__page);
4528 static struct lu_device *osd_device_fini(const struct lu_env *env,
4529 struct lu_device *d)
4534 rc = osd_shutdown(env, osd_dev(d));
4536 osd_compat_fini(osd_dev(d));
4538 shrink_dcache_sb(osd_sb(osd_dev(d)));
4539 osd_sync(env, lu2dt_dev(d));
4541 rc = osd_procfs_fini(osd_dev(d));
4543 CERROR("proc fini error %d \n", rc);
4544 RETURN (ERR_PTR(rc));
4547 if (osd_dev(d)->od_mnt) {
4548 mntput(osd_dev(d)->od_mnt);
4549 osd_dev(d)->od_mnt = NULL;
4555 static int osd_device_init0(const struct lu_env *env,
4556 struct osd_device *o,
4557 struct lustre_cfg *cfg)
4559 struct lu_device *l = osd2lu_dev(o);
4560 struct osd_thread_info *info;
4563 /* if the module was re-loaded, env can loose its keys */
4564 rc = lu_env_refill((struct lu_env *) env);
4567 info = osd_oti_get(env);
4570 l->ld_ops = &osd_lu_ops;
4571 o->od_dt_dev.dd_ops = &osd_dt_ops;
4573 cfs_spin_lock_init(&o->od_osfs_lock);
4574 cfs_mutex_init(&o->od_otable_mutex);
4575 o->od_osfs_age = cfs_time_shift_64(-1000);
4577 o->od_capa_hash = init_capa_hash();
4578 if (o->od_capa_hash == NULL)
4579 GOTO(out, rc = -ENOMEM);
4581 o->od_read_cache = 1;
4582 o->od_writethrough_cache = 1;
4584 rc = osd_mount(env, o, cfg);
4588 /* setup scrub, including OI files initialization */
4589 rc = osd_scrub_setup(env, o);
4593 strncpy(o->od_svname, lustre_cfg_string(cfg, 4),
4594 sizeof(o->od_svname) - 1);
4596 if (strstr(o->od_svname, "-OST")) {
4597 rc = osd_compat_init(o);
4602 rc = lu_site_init(&o->od_site, l);
4604 GOTO(out_compat, rc);
4606 rc = lu_site_init_finish(&o->od_site);
4608 GOTO(out_compat, rc);
4610 rc = osd_procfs_init(o, o->od_svname);
4612 CERROR("%s: can't initialize procfs: rc = %d\n",
4614 GOTO(out_compat, rc);
4617 LASSERT(l->ld_site->ls_linkage.next && l->ld_site->ls_linkage.prev);
4623 osd_oi_fini(info, o);
4624 osd_shutdown(env, o);
4628 cleanup_capa_hash(o->od_capa_hash);
4633 static struct lu_device *osd_device_alloc(const struct lu_env *env,
4634 struct lu_device_type *t,
4635 struct lustre_cfg *cfg)
4637 struct osd_device *o;
4642 return ERR_PTR(-ENOMEM);
4644 rc = dt_device_init(&o->od_dt_dev, t);
4646 rc = osd_device_init0(env, o, cfg);
4648 dt_device_fini(&o->od_dt_dev);
4651 if (unlikely(rc != 0))
4654 return rc == 0 ? osd2lu_dev(o) : ERR_PTR(rc);
4657 static struct lu_device *osd_device_free(const struct lu_env *env,
4658 struct lu_device *d)
4660 struct osd_device *o = osd_dev(d);
4663 cleanup_capa_hash(o->od_capa_hash);
4664 /* XXX: make osd top device in order to release reference */
4665 d->ld_site->ls_top_dev = d;
4666 lu_site_purge(env, d->ld_site, -1);
4667 if (!cfs_hash_is_empty(d->ld_site->ls_obj_hash)) {
4668 LIBCFS_DEBUG_MSG_DATA_DECL(msgdata, D_ERROR, NULL);
4669 lu_site_print(env, d->ld_site, &msgdata, lu_cdebug_printer);
4671 lu_site_fini(&o->od_site);
4672 dt_device_fini(&o->od_dt_dev);
4677 static int osd_process_config(const struct lu_env *env,
4678 struct lu_device *d, struct lustre_cfg *cfg)
4680 struct osd_device *o = osd_dev(d);
4684 switch(cfg->lcfg_command) {
4686 err = osd_mount(env, o, cfg);
4689 lu_dev_del_linkage(d->ld_site, d);
4699 static int osd_recovery_complete(const struct lu_env *env,
4700 struct lu_device *d)
4706 * we use exports to track all osd users
4708 static int osd_obd_connect(const struct lu_env *env, struct obd_export **exp,
4709 struct obd_device *obd, struct obd_uuid *cluuid,
4710 struct obd_connect_data *data, void *localdata)
4712 struct osd_device *osd = osd_dev(obd->obd_lu_dev);
4713 struct lustre_handle conn;
4717 CDEBUG(D_CONFIG, "connect #%d\n", osd->od_connects);
4719 rc = class_connect(&conn, obd, cluuid);
4723 *exp = class_conn2export(&conn);
4725 cfs_spin_lock(&osd->od_osfs_lock);
4727 cfs_spin_unlock(&osd->od_osfs_lock);
4733 * once last export (we don't count self-export) disappeared
4734 * osd can be released
4736 static int osd_obd_disconnect(struct obd_export *exp)
4738 struct obd_device *obd = exp->exp_obd;
4739 struct osd_device *osd = osd_dev(obd->obd_lu_dev);
4740 int rc, release = 0;
4743 /* Only disconnect the underlying layers on the final disconnect. */
4744 cfs_spin_lock(&osd->od_osfs_lock);
4746 if (osd->od_connects == 0)
4748 cfs_spin_unlock(&osd->od_osfs_lock);
4750 rc = class_disconnect(exp); /* bz 9811 */
4752 if (rc == 0 && release)
4753 class_manual_cleanup(obd);
4757 static int osd_prepare(const struct lu_env *env, struct lu_device *pdev,
4758 struct lu_device *dev)
4760 struct osd_device *osd = osd_dev(dev);
4764 /* 2. setup quota slave instance */
4765 osd->od_quota_slave = qsd_init(env, osd->od_svname, &osd->od_dt_dev,
4766 osd->od_proc_entry);
4767 if (IS_ERR(osd->od_quota_slave)) {
4768 result = PTR_ERR(osd->od_quota_slave);
4769 osd->od_quota_slave = NULL;
4773 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2, 3, 55, 0)
4774 /* Unfortunately, the current MDD implementation relies on some specific
4775 * code to be executed in the OSD layer. Since OFD now also uses the OSD
4776 * module, we need a way to skip the metadata-specific code when running
4778 * The hack here is to check the type of the parent device which is
4779 * either MD (i.e. MDD device) with the current MDT stack or DT (i.e.
4780 * OFD device) on an OST. As a reminder, obdfilter does not use the OSD
4781 * layer and still relies on lvfs. This hack won't work any more when
4782 * LOD is landed since LOD is of DT type.
4783 * This code should be removed once the orion MDT changes (LOD/OSP, ...)
4784 * have been landed */
4785 osd->od_is_md = lu_device_is_md(pdev);
4787 #warning "all is_md checks must be removed from osd-ldiskfs"
4793 /* 3. setup local objects */
4794 result = llo_local_objects_setup(env, lu2md_dev(pdev), lu2dt_dev(dev));
4798 static const struct lu_object_operations osd_lu_obj_ops = {
4799 .loo_object_init = osd_object_init,
4800 .loo_object_delete = osd_object_delete,
4801 .loo_object_release = osd_object_release,
4802 .loo_object_free = osd_object_free,
4803 .loo_object_print = osd_object_print,
4804 .loo_object_invariant = osd_object_invariant
4807 const struct lu_device_operations osd_lu_ops = {
4808 .ldo_object_alloc = osd_object_alloc,
4809 .ldo_process_config = osd_process_config,
4810 .ldo_recovery_complete = osd_recovery_complete,
4811 .ldo_prepare = osd_prepare,
4814 static const struct lu_device_type_operations osd_device_type_ops = {
4815 .ldto_init = osd_type_init,
4816 .ldto_fini = osd_type_fini,
4818 .ldto_start = osd_type_start,
4819 .ldto_stop = osd_type_stop,
4821 .ldto_device_alloc = osd_device_alloc,
4822 .ldto_device_free = osd_device_free,
4824 .ldto_device_init = osd_device_init,
4825 .ldto_device_fini = osd_device_fini
4828 struct lu_device_type osd_device_type = {
4829 .ldt_tags = LU_DEVICE_DT,
4830 .ldt_name = LUSTRE_OSD_LDISKFS_NAME,
4831 .ldt_ops = &osd_device_type_ops,
4832 .ldt_ctx_tags = LCT_LOCAL,
4836 * lprocfs legacy support.
4838 static struct obd_ops osd_obd_device_ops = {
4839 .o_owner = THIS_MODULE,
4840 .o_connect = osd_obd_connect,
4841 .o_disconnect = osd_obd_disconnect
4844 static int __init osd_mod_init(void)
4846 struct lprocfs_static_vars lvars;
4849 lprocfs_osd_init_vars(&lvars);
4850 return class_register_type(&osd_obd_device_ops, NULL, lvars.module_vars,
4851 LUSTRE_OSD_LDISKFS_NAME, &osd_device_type);
4854 static void __exit osd_mod_exit(void)
4856 class_unregister_type(LUSTRE_OSD_LDISKFS_NAME);
4859 MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");
4860 MODULE_DESCRIPTION("Lustre Object Storage Device ("LUSTRE_OSD_LDISKFS_NAME")");
4861 MODULE_LICENSE("GPL");
4863 cfs_module(osd, "0.1.0", osd_mod_init, osd_mod_exit);