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.gnu.org/licenses/gpl-2.0.html
23 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2010, 2016, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
30 * Lustre is a trademark of Sun Microsystems, Inc.
32 * lustre/mdt/mdt_handler.c
34 * Lustre Metadata Target (mdt) request handler
36 * Author: Peter Braam <braam@clusterfs.com>
37 * Author: Andreas Dilger <adilger@clusterfs.com>
38 * Author: Phil Schwan <phil@clusterfs.com>
39 * Author: Mike Shaver <shaver@clusterfs.com>
40 * Author: Nikita Danilov <nikita@clusterfs.com>
41 * Author: Huang Hua <huanghua@clusterfs.com>
42 * Author: Yury Umanets <umka@clusterfs.com>
45 #define DEBUG_SUBSYSTEM S_MDS
47 #include <linux/module.h>
48 #include <linux/pagemap.h>
50 #include <dt_object.h>
51 #include <lustre_acl.h>
52 #include <lustre_export.h>
53 #include <uapi/linux/lustre/lustre_ioctl.h>
54 #include <lustre_lfsck.h>
55 #include <lustre_log.h>
56 #include <lustre_nodemap.h>
57 #include <lustre_mds.h>
58 #include <uapi/linux/lustre/lustre_param.h>
59 #include <lustre_quota.h>
60 #include <lustre_swab.h>
62 #include <obd_support.h>
63 #include <lustre_barrier.h>
64 #include <obd_cksum.h>
65 #include <llog_swab.h>
67 #include "mdt_internal.h"
70 static unsigned int max_mod_rpcs_per_client = 8;
71 module_param(max_mod_rpcs_per_client, uint, 0644);
72 MODULE_PARM_DESC(max_mod_rpcs_per_client, "maximum number of modify RPCs in flight allowed per client");
74 mdl_mode_t mdt_mdl_lock_modes[] = {
75 [LCK_MINMODE] = MDL_MINMODE,
82 [LCK_GROUP] = MDL_GROUP
85 enum ldlm_mode mdt_dlm_lock_modes[] = {
86 [MDL_MINMODE] = LCK_MINMODE,
93 [MDL_GROUP] = LCK_GROUP
96 static struct mdt_device *mdt_dev(struct lu_device *d);
97 static int mdt_unpack_req_pack_rep(struct mdt_thread_info *info, __u32 flags);
99 static const struct lu_object_operations mdt_obj_ops;
101 /* Slab for MDT object allocation */
102 static struct kmem_cache *mdt_object_kmem;
104 /* For HSM restore handles */
105 struct kmem_cache *mdt_hsm_cdt_kmem;
107 /* For HSM request handles */
108 struct kmem_cache *mdt_hsm_car_kmem;
110 static struct lu_kmem_descr mdt_caches[] = {
112 .ckd_cache = &mdt_object_kmem,
113 .ckd_name = "mdt_obj",
114 .ckd_size = sizeof(struct mdt_object)
117 .ckd_cache = &mdt_hsm_cdt_kmem,
118 .ckd_name = "mdt_cdt_restore_handle",
119 .ckd_size = sizeof(struct cdt_restore_handle)
122 .ckd_cache = &mdt_hsm_car_kmem,
123 .ckd_name = "mdt_cdt_agent_req",
124 .ckd_size = sizeof(struct cdt_agent_req)
131 __u64 mdt_get_disposition(struct ldlm_reply *rep, __u64 op_flag)
135 return rep->lock_policy_res1 & op_flag;
138 void mdt_clear_disposition(struct mdt_thread_info *info,
139 struct ldlm_reply *rep, __u64 op_flag)
142 info->mti_opdata &= ~op_flag;
143 tgt_opdata_clear(info->mti_env, op_flag);
146 rep->lock_policy_res1 &= ~op_flag;
149 void mdt_set_disposition(struct mdt_thread_info *info,
150 struct ldlm_reply *rep, __u64 op_flag)
153 info->mti_opdata |= op_flag;
154 tgt_opdata_set(info->mti_env, op_flag);
157 rep->lock_policy_res1 |= op_flag;
160 void mdt_lock_reg_init(struct mdt_lock_handle *lh, enum ldlm_mode lm)
162 lh->mlh_pdo_hash = 0;
163 lh->mlh_reg_mode = lm;
164 lh->mlh_rreg_mode = lm;
165 lh->mlh_type = MDT_REG_LOCK;
168 void mdt_lock_pdo_init(struct mdt_lock_handle *lh, enum ldlm_mode lock_mode,
169 const struct lu_name *lname)
171 lh->mlh_reg_mode = lock_mode;
172 lh->mlh_pdo_mode = LCK_MINMODE;
173 lh->mlh_rreg_mode = lock_mode;
174 lh->mlh_type = MDT_PDO_LOCK;
176 if (lu_name_is_valid(lname)) {
177 lh->mlh_pdo_hash = ll_full_name_hash(NULL, lname->ln_name,
179 /* XXX Workaround for LU-2856
181 * Zero is a valid return value of full_name_hash, but
182 * several users of mlh_pdo_hash assume a non-zero
183 * hash value. We therefore map zero onto an
184 * arbitrary, but consistent value (1) to avoid
185 * problems further down the road. */
186 if (unlikely(lh->mlh_pdo_hash == 0))
187 lh->mlh_pdo_hash = 1;
189 lh->mlh_pdo_hash = 0;
193 static void mdt_lock_pdo_mode(struct mdt_thread_info *info, struct mdt_object *o,
194 struct mdt_lock_handle *lh)
200 * Any dir access needs couple of locks:
202 * 1) on part of dir we gonna take lookup/modify;
204 * 2) on whole dir to protect it from concurrent splitting and/or to
205 * flush client's cache for readdir().
207 * so, for a given mode and object this routine decides what lock mode
208 * to use for lock #2:
210 * 1) if caller's gonna lookup in dir then we need to protect dir from
211 * being splitted only - LCK_CR
213 * 2) if caller's gonna modify dir then we need to protect dir from
214 * being splitted and to flush cache - LCK_CW
216 * 3) if caller's gonna modify dir and that dir seems ready for
217 * splitting then we need to protect it from any type of access
218 * (lookup/modify/split) - LCK_EX --bzzz
221 LASSERT(lh->mlh_reg_mode != LCK_MINMODE);
222 LASSERT(lh->mlh_pdo_mode == LCK_MINMODE);
225 * Ask underlaying level its opinion about preferable PDO lock mode
226 * having access type passed as regular lock mode:
228 * - MDL_MINMODE means that lower layer does not want to specify lock
231 * - MDL_NL means that no PDO lock should be taken. This is used in some
232 * cases. Say, for non-splittable directories no need to use PDO locks
235 mode = mdo_lock_mode(info->mti_env, mdt_object_child(o),
236 mdt_dlm_mode2mdl_mode(lh->mlh_reg_mode));
238 if (mode != MDL_MINMODE) {
239 lh->mlh_pdo_mode = mdt_mdl_mode2dlm_mode(mode);
242 * Lower layer does not want to specify locking mode. We do it
243 * our selves. No special protection is needed, just flush
244 * client's cache on modification and allow concurrent
247 switch (lh->mlh_reg_mode) {
249 lh->mlh_pdo_mode = LCK_EX;
252 lh->mlh_pdo_mode = LCK_CR;
255 lh->mlh_pdo_mode = LCK_CW;
258 CERROR("Not expected lock type (0x%x)\n",
259 (int)lh->mlh_reg_mode);
264 LASSERT(lh->mlh_pdo_mode != LCK_MINMODE);
268 static int mdt_lookup_fileset(struct mdt_thread_info *info, const char *fileset,
271 struct mdt_device *mdt = info->mti_mdt;
272 struct lu_name *lname = &info->mti_name;
274 struct mdt_object *parent;
278 LASSERT(!info->mti_cross_ref);
280 OBD_ALLOC(name, NAME_MAX + 1);
283 lname->ln_name = name;
286 * We may want to allow this to mount a completely separate
287 * fileset from the MDT in the future, but keeping it to
288 * ROOT/ only for now avoid potential security issues.
290 *fid = mdt->mdt_md_root_fid;
292 while (rc == 0 && fileset != NULL && *fileset != '\0') {
293 const char *s1 = fileset;
299 while (*s2 != '/' && *s2 != '\0')
307 lname->ln_namelen = s2 - s1;
308 if (lname->ln_namelen > NAME_MAX) {
313 /* reject .. as a path component */
314 if (lname->ln_namelen == 2 &&
315 strncmp(s1, "..", 2) == 0) {
320 strncpy(name, s1, lname->ln_namelen);
321 name[lname->ln_namelen] = '\0';
323 parent = mdt_object_find(info->mti_env, mdt, fid);
324 if (IS_ERR(parent)) {
325 rc = PTR_ERR(parent);
328 /* Only got the fid of this obj by name */
330 rc = mdo_lookup(info->mti_env, mdt_object_child(parent), lname,
331 fid, &info->mti_spec);
332 mdt_object_put(info->mti_env, parent);
335 parent = mdt_object_find(info->mti_env, mdt, fid);
337 rc = PTR_ERR(parent);
339 mode = lu_object_attr(&parent->mot_obj);
340 mdt_object_put(info->mti_env, parent);
346 OBD_FREE(name, NAME_MAX + 1);
351 static int mdt_get_root(struct tgt_session_info *tsi)
353 struct mdt_thread_info *info = tsi2mdt_info(tsi);
354 struct mdt_device *mdt = info->mti_mdt;
355 struct mdt_body *repbody;
356 char *fileset = NULL, *buffer = NULL;
358 struct obd_export *exp = info->mti_exp;
359 char *nodemap_fileset;
363 rc = mdt_check_ucred(info);
365 GOTO(out, rc = err_serious(rc));
367 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_GET_ROOT_PACK))
368 GOTO(out, rc = err_serious(-ENOMEM));
370 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
371 if (req_capsule_get_size(info->mti_pill, &RMF_NAME, RCL_CLIENT) > 0) {
372 fileset = req_capsule_client_get(info->mti_pill, &RMF_NAME);
374 GOTO(out, rc = err_serious(-EFAULT));
377 nodemap_fileset = nodemap_get_fileset(exp->exp_target_data.ted_nodemap);
378 if (nodemap_fileset && nodemap_fileset[0]) {
379 CDEBUG(D_INFO, "nodemap fileset is %s\n", nodemap_fileset);
381 /* consider fileset from client as a sub-fileset
382 * of the nodemap one */
383 OBD_ALLOC(buffer, PATH_MAX + 1);
385 GOTO(out, rc = err_serious(-ENOMEM));
386 if (snprintf(buffer, PATH_MAX + 1, "%s/%s",
387 nodemap_fileset, fileset) >= PATH_MAX + 1)
388 GOTO(out, rc = err_serious(-EINVAL));
391 /* enforce fileset as specified in the nodemap */
392 fileset = nodemap_fileset;
397 CDEBUG(D_INFO, "Getting fileset %s\n", fileset);
398 rc = mdt_lookup_fileset(info, fileset, &repbody->mbo_fid1);
400 GOTO(out, rc = err_serious(rc));
402 repbody->mbo_fid1 = mdt->mdt_md_root_fid;
404 repbody->mbo_valid |= OBD_MD_FLID;
408 mdt_thread_info_fini(info);
410 OBD_FREE(buffer, PATH_MAX+1);
414 static int mdt_statfs(struct tgt_session_info *tsi)
416 struct ptlrpc_request *req = tgt_ses_req(tsi);
417 struct mdt_thread_info *info = tsi2mdt_info(tsi);
418 struct md_device *next = info->mti_mdt->mdt_child;
419 struct ptlrpc_service_part *svcpt;
420 struct obd_statfs *osfs;
425 svcpt = req->rq_rqbd->rqbd_svcpt;
427 /* This will trigger a watchdog timeout */
428 OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_STATFS_LCW_SLEEP,
429 (MDT_SERVICE_WATCHDOG_FACTOR *
430 at_get(&svcpt->scp_at_estimate)) + 1);
432 rc = mdt_check_ucred(info);
434 GOTO(out, rc = err_serious(rc));
436 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_STATFS_PACK))
437 GOTO(out, rc = err_serious(-ENOMEM));
439 osfs = req_capsule_server_get(info->mti_pill, &RMF_OBD_STATFS);
441 GOTO(out, rc = -EPROTO);
443 /** statfs information are cached in the mdt_device */
444 if (cfs_time_before_64(info->mti_mdt->mdt_osfs_age,
445 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS))) {
446 /** statfs data is too old, get up-to-date one */
447 rc = next->md_ops->mdo_statfs(info->mti_env, next, osfs);
450 spin_lock(&info->mti_mdt->mdt_lock);
451 info->mti_mdt->mdt_osfs = *osfs;
452 info->mti_mdt->mdt_osfs_age = cfs_time_current_64();
453 spin_unlock(&info->mti_mdt->mdt_lock);
455 /** use cached statfs data */
456 spin_lock(&info->mti_mdt->mdt_lock);
457 *osfs = info->mti_mdt->mdt_osfs;
458 spin_unlock(&info->mti_mdt->mdt_lock);
462 mdt_counter_incr(req, LPROC_MDT_STATFS);
464 mdt_thread_info_fini(info);
468 #ifdef CONFIG_FS_POSIX_ACL
470 * Pack ACL data into the reply. UIDs/GIDs are mapped and filtered by nodemap.
472 * \param info thread info object
473 * \param repbody reply to pack ACLs into
474 * \param o mdt object of file to examine
475 * \param nodemap nodemap of client to reply to
477 * \retval -errno error getting or parsing ACL from disk
479 int mdt_pack_acl2body(struct mdt_thread_info *info, struct mdt_body *repbody,
480 struct mdt_object *o, struct lu_nodemap *nodemap)
482 const struct lu_env *env = info->mti_env;
483 struct md_object *next = mdt_object_child(o);
484 struct lu_buf *buf = &info->mti_buf;
485 struct mdt_device *mdt = info->mti_mdt;
490 buf->lb_buf = req_capsule_server_get(info->mti_pill, &RMF_ACL);
491 buf->lb_len = req_capsule_get_size(info->mti_pill, &RMF_ACL,
493 if (buf->lb_len == 0)
497 rc = mo_xattr_get(env, next, buf, XATTR_NAME_ACL_ACCESS);
499 if (rc == -ENODATA) {
500 repbody->mbo_aclsize = 0;
501 repbody->mbo_valid |= OBD_MD_FLACL;
503 } else if (rc == -EOPNOTSUPP) {
507 exp_connect_large_acl(info->mti_exp) &&
508 buf->lb_buf != info->mti_big_acl) {
509 if (info->mti_big_acl == NULL) {
510 OBD_ALLOC_LARGE(info->mti_big_acl,
511 mdt->mdt_max_ea_size);
512 if (info->mti_big_acl == NULL) {
513 CERROR("%s: unable to grow "
516 PFID(mdt_object_fid(o)));
520 info->mti_big_aclsize =
521 mdt->mdt_max_ea_size;
524 CDEBUG(D_INODE, "%s: grow the "DFID
525 " ACL buffer to size %d\n",
527 PFID(mdt_object_fid(o)),
528 mdt->mdt_max_ea_size);
530 buf->lb_buf = info->mti_big_acl;
531 buf->lb_len = info->mti_big_aclsize;
536 CERROR("%s: unable to read "DFID" ACL: rc = %d\n",
537 mdt_obd_name(mdt), PFID(mdt_object_fid(o)), rc);
540 if (buf->lb_buf == info->mti_big_acl)
541 info->mti_big_acl_used = 1;
543 rc = nodemap_map_acl(nodemap, buf->lb_buf,
544 rc, NODEMAP_FS_TO_CLIENT);
545 /* if all ACLs mapped out, rc is still >= 0 */
547 CERROR("%s: nodemap_map_acl unable to parse "DFID
548 " ACL: rc = %d\n", mdt_obd_name(mdt),
549 PFID(mdt_object_fid(o)), rc);
551 repbody->mbo_aclsize = rc;
552 repbody->mbo_valid |= OBD_MD_FLACL;
561 /* XXX Look into layout in MDT layer. */
562 static inline bool mdt_hsm_is_released(struct lov_mds_md *lmm)
564 struct lov_comp_md_v1 *comp_v1;
565 struct lov_mds_md *v1;
568 if (lmm->lmm_magic == LOV_MAGIC_COMP_V1) {
569 comp_v1 = (struct lov_comp_md_v1 *)lmm;
571 for (i = 0; i < comp_v1->lcm_entry_count; i++) {
572 v1 = (struct lov_mds_md *)((char *)comp_v1 +
573 comp_v1->lcm_entries[i].lcme_offset);
574 /* We don't support partial release for now */
575 if (!(v1->lmm_pattern & LOV_PATTERN_F_RELEASED))
580 return (lmm->lmm_pattern & LOV_PATTERN_F_RELEASED) ?
585 void mdt_pack_attr2body(struct mdt_thread_info *info, struct mdt_body *b,
586 const struct lu_attr *attr, const struct lu_fid *fid)
588 struct md_attr *ma = &info->mti_attr;
589 struct obd_export *exp = info->mti_exp;
590 struct lu_nodemap *nodemap = NULL;
592 LASSERT(ma->ma_valid & MA_INODE);
594 if (attr->la_valid & LA_ATIME) {
595 b->mbo_atime = attr->la_atime;
596 b->mbo_valid |= OBD_MD_FLATIME;
598 if (attr->la_valid & LA_MTIME) {
599 b->mbo_mtime = attr->la_mtime;
600 b->mbo_valid |= OBD_MD_FLMTIME;
602 if (attr->la_valid & LA_CTIME) {
603 b->mbo_ctime = attr->la_ctime;
604 b->mbo_valid |= OBD_MD_FLCTIME;
606 if (attr->la_valid & LA_FLAGS) {
607 b->mbo_flags = attr->la_flags;
608 b->mbo_valid |= OBD_MD_FLFLAGS;
610 if (attr->la_valid & LA_NLINK) {
611 b->mbo_nlink = attr->la_nlink;
612 b->mbo_valid |= OBD_MD_FLNLINK;
614 if (attr->la_valid & (LA_UID|LA_GID)) {
615 nodemap = nodemap_get_from_exp(exp);
619 if (attr->la_valid & LA_UID) {
620 b->mbo_uid = nodemap_map_id(nodemap, NODEMAP_UID,
621 NODEMAP_FS_TO_CLIENT,
623 b->mbo_valid |= OBD_MD_FLUID;
625 if (attr->la_valid & LA_GID) {
626 b->mbo_gid = nodemap_map_id(nodemap, NODEMAP_GID,
627 NODEMAP_FS_TO_CLIENT,
629 b->mbo_valid |= OBD_MD_FLGID;
632 if (attr->la_valid & LA_PROJID) {
633 /* TODO, nodemap for project id */
634 b->mbo_projid = attr->la_projid;
635 b->mbo_valid |= OBD_MD_FLPROJID;
638 b->mbo_mode = attr->la_mode;
639 if (attr->la_valid & LA_MODE)
640 b->mbo_valid |= OBD_MD_FLMODE;
641 if (attr->la_valid & LA_TYPE)
642 b->mbo_valid |= OBD_MD_FLTYPE;
646 b->mbo_valid |= OBD_MD_FLID;
647 CDEBUG(D_INODE, DFID": nlink=%d, mode=%o, valid=%#llx\n",
648 PFID(fid), b->mbo_nlink, b->mbo_mode, b->mbo_valid);
651 if (!(attr->la_valid & LA_TYPE))
654 b->mbo_rdev = attr->la_rdev;
655 b->mbo_size = attr->la_size;
656 b->mbo_blocks = attr->la_blocks;
658 if (!S_ISREG(attr->la_mode)) {
659 b->mbo_valid |= OBD_MD_FLSIZE | OBD_MD_FLBLOCKS | OBD_MD_FLRDEV;
660 } else if (ma->ma_need & MA_LOV && !(ma->ma_valid & MA_LOV)) {
661 /* means no objects are allocated on osts. */
662 LASSERT(!(ma->ma_valid & MA_LOV));
663 /* just ignore blocks occupied by extend attributes on MDS */
665 /* if no object is allocated on osts, the size on mds is valid.
667 b->mbo_valid |= OBD_MD_FLSIZE | OBD_MD_FLBLOCKS;
668 } else if ((ma->ma_valid & MA_LOV) && ma->ma_lmm != NULL) {
669 if (mdt_hsm_is_released(ma->ma_lmm)) {
670 /* A released file stores its size on MDS. */
671 /* But return 1 block for released file, unless tools
672 * like tar will consider it fully sparse. (LU-3864)
674 if (unlikely(b->mbo_size == 0))
678 b->mbo_valid |= OBD_MD_FLSIZE | OBD_MD_FLBLOCKS;
682 if (fid != NULL && (b->mbo_valid & OBD_MD_FLSIZE))
683 CDEBUG(D_VFSTRACE, DFID": returning size %llu\n",
684 PFID(fid), (unsigned long long)b->mbo_size);
687 if (!IS_ERR_OR_NULL(nodemap))
688 nodemap_putref(nodemap);
691 static inline int mdt_body_has_lov(const struct lu_attr *la,
692 const struct mdt_body *body)
694 return (S_ISREG(la->la_mode) && (body->mbo_valid & OBD_MD_FLEASIZE)) ||
695 (S_ISDIR(la->la_mode) && (body->mbo_valid & OBD_MD_FLDIREA));
698 void mdt_client_compatibility(struct mdt_thread_info *info)
700 struct mdt_body *body;
701 struct ptlrpc_request *req = mdt_info_req(info);
702 struct obd_export *exp = req->rq_export;
703 struct md_attr *ma = &info->mti_attr;
704 struct lu_attr *la = &ma->ma_attr;
707 if (exp_connect_layout(exp))
708 /* the client can deal with 16-bit lmm_stripe_count */
711 body = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
713 if (!mdt_body_has_lov(la, body))
716 /* now we have a reply with a lov for a client not compatible with the
717 * layout lock so we have to clean the layout generation number */
718 if (S_ISREG(la->la_mode))
719 ma->ma_lmm->lmm_layout_gen = 0;
723 static int mdt_attr_get_eabuf_size(struct mdt_thread_info *info,
724 struct mdt_object *o)
726 const struct lu_env *env = info->mti_env;
729 rc = mo_xattr_get(env, mdt_object_child(o), &LU_BUF_NULL,
738 /* Is it a directory? Let's check for the LMV as well */
739 if (S_ISDIR(lu_object_attr(&mdt_object_child(o)->mo_lu))) {
740 rc2 = mo_xattr_get(env, mdt_object_child(o), &LU_BUF_NULL,
744 rc2 = mo_xattr_get(env, mdt_object_child(o),
746 XATTR_NAME_DEFAULT_LMV);
748 if ((rc2 < 0 && rc2 != -ENODATA) || (rc2 > rc))
756 int mdt_big_xattr_get(struct mdt_thread_info *info, struct mdt_object *o,
759 const struct lu_env *env = info->mti_env;
763 LASSERT(info->mti_big_lmm_used == 0);
764 rc = mo_xattr_get(env, mdt_object_child(o), &LU_BUF_NULL, name);
768 /* big_lmm may need to be grown */
769 if (info->mti_big_lmmsize < rc) {
770 int size = size_roundup_power2(rc);
772 if (info->mti_big_lmmsize > 0) {
773 /* free old buffer */
774 LASSERT(info->mti_big_lmm);
775 OBD_FREE_LARGE(info->mti_big_lmm,
776 info->mti_big_lmmsize);
777 info->mti_big_lmm = NULL;
778 info->mti_big_lmmsize = 0;
781 OBD_ALLOC_LARGE(info->mti_big_lmm, size);
782 if (info->mti_big_lmm == NULL)
784 info->mti_big_lmmsize = size;
786 LASSERT(info->mti_big_lmmsize >= rc);
788 info->mti_buf.lb_buf = info->mti_big_lmm;
789 info->mti_buf.lb_len = info->mti_big_lmmsize;
790 rc = mo_xattr_get(env, mdt_object_child(o), &info->mti_buf, name);
795 int mdt_stripe_get(struct mdt_thread_info *info, struct mdt_object *o,
796 struct md_attr *ma, const char *name)
798 struct md_object *next = mdt_object_child(o);
799 struct lu_buf *buf = &info->mti_buf;
802 if (strcmp(name, XATTR_NAME_LOV) == 0) {
803 buf->lb_buf = ma->ma_lmm;
804 buf->lb_len = ma->ma_lmm_size;
805 LASSERT(!(ma->ma_valid & MA_LOV));
806 } else if (strcmp(name, XATTR_NAME_LMV) == 0) {
807 buf->lb_buf = ma->ma_lmv;
808 buf->lb_len = ma->ma_lmv_size;
809 LASSERT(!(ma->ma_valid & MA_LMV));
810 } else if (strcmp(name, XATTR_NAME_DEFAULT_LMV) == 0) {
811 buf->lb_buf = ma->ma_lmv;
812 buf->lb_len = ma->ma_lmv_size;
813 LASSERT(!(ma->ma_valid & MA_LMV_DEF));
818 rc = mo_xattr_get(info->mti_env, next, buf, name);
822 if (strcmp(name, XATTR_NAME_LOV) == 0) {
823 if (info->mti_big_lmm_used)
824 ma->ma_lmm = info->mti_big_lmm;
826 /* NOT return LOV EA with hole to old client. */
827 if (unlikely(le32_to_cpu(ma->ma_lmm->lmm_pattern) &
828 LOV_PATTERN_F_HOLE) &&
829 !(exp_connect_flags(info->mti_exp) &
830 OBD_CONNECT_LFSCK)) {
833 ma->ma_lmm_size = rc;
834 ma->ma_valid |= MA_LOV;
836 } else if (strcmp(name, XATTR_NAME_LMV) == 0) {
837 if (info->mti_big_lmm_used)
838 ma->ma_lmv = info->mti_big_lmm;
840 ma->ma_lmv_size = rc;
841 ma->ma_valid |= MA_LMV;
842 } else if (strcmp(name, XATTR_NAME_DEFAULT_LMV) == 0) {
843 ma->ma_lmv_size = rc;
844 ma->ma_valid |= MA_LMV_DEF;
847 /* Update mdt_max_mdsize so all clients will be aware that */
848 if (info->mti_mdt->mdt_max_mdsize < rc)
849 info->mti_mdt->mdt_max_mdsize = rc;
852 } else if (rc == -ENODATA) {
855 } else if (rc == -ERANGE) {
856 /* Default LMV has fixed size, so it must be able to fit
857 * in the original buffer */
858 if (strcmp(name, XATTR_NAME_DEFAULT_LMV) == 0)
860 rc = mdt_big_xattr_get(info, o, name);
862 info->mti_big_lmm_used = 1;
870 static int mdt_attr_get_pfid(struct mdt_thread_info *info,
871 struct mdt_object *o, struct lu_fid *pfid)
873 struct lu_buf *buf = &info->mti_buf;
874 struct link_ea_header *leh;
875 struct link_ea_entry *lee;
879 buf->lb_buf = info->mti_big_lmm;
880 buf->lb_len = info->mti_big_lmmsize;
881 rc = mo_xattr_get(info->mti_env, mdt_object_child(o),
882 buf, XATTR_NAME_LINK);
883 /* ignore errors, MA_PFID won't be set and it is
884 * up to the caller to treat this as an error */
885 if (rc == -ERANGE || buf->lb_len == 0) {
886 rc = mdt_big_xattr_get(info, o, XATTR_NAME_LINK);
887 buf->lb_buf = info->mti_big_lmm;
888 buf->lb_len = info->mti_big_lmmsize;
893 if (rc < sizeof(*leh)) {
894 CERROR("short LinkEA on "DFID": rc = %d\n",
895 PFID(mdt_object_fid(o)), rc);
899 leh = (struct link_ea_header *) buf->lb_buf;
900 lee = (struct link_ea_entry *)(leh + 1);
901 if (leh->leh_magic == __swab32(LINK_EA_MAGIC)) {
902 leh->leh_magic = LINK_EA_MAGIC;
903 leh->leh_reccount = __swab32(leh->leh_reccount);
904 leh->leh_len = __swab64(leh->leh_len);
906 if (leh->leh_magic != LINK_EA_MAGIC)
908 if (leh->leh_reccount == 0)
911 memcpy(pfid, &lee->lee_parent_fid, sizeof(*pfid));
912 fid_be_to_cpu(pfid, pfid);
917 int mdt_attr_get_complex(struct mdt_thread_info *info,
918 struct mdt_object *o, struct md_attr *ma)
920 const struct lu_env *env = info->mti_env;
921 struct md_object *next = mdt_object_child(o);
922 struct lu_buf *buf = &info->mti_buf;
923 int need = ma->ma_need;
930 if (mdt_object_exists(o) == 0)
931 GOTO(out, rc = -ENOENT);
932 mode = lu_object_attr(&next->mo_lu);
934 if (need & MA_INODE) {
935 ma->ma_need = MA_INODE;
936 rc = mo_attr_get(env, next, ma);
939 ma->ma_valid |= MA_INODE;
942 if (need & MA_PFID) {
943 rc = mdt_attr_get_pfid(info, o, &ma->ma_pfid);
945 ma->ma_valid |= MA_PFID;
946 /* ignore this error, parent fid is not mandatory */
950 if (need & MA_LOV && (S_ISREG(mode) || S_ISDIR(mode))) {
951 rc = mdt_stripe_get(info, o, ma, XATTR_NAME_LOV);
956 if (need & MA_LMV && S_ISDIR(mode)) {
957 rc = mdt_stripe_get(info, o, ma, XATTR_NAME_LMV);
962 if (need & MA_LMV_DEF && S_ISDIR(mode)) {
963 rc = mdt_stripe_get(info, o, ma, XATTR_NAME_DEFAULT_LMV);
968 if (need & MA_HSM && S_ISREG(mode)) {
969 buf->lb_buf = info->mti_xattr_buf;
970 buf->lb_len = sizeof(info->mti_xattr_buf);
971 CLASSERT(sizeof(struct hsm_attrs) <=
972 sizeof(info->mti_xattr_buf));
973 rc2 = mo_xattr_get(info->mti_env, next, buf, XATTR_NAME_HSM);
974 rc2 = lustre_buf2hsm(info->mti_xattr_buf, rc2, &ma->ma_hsm);
976 ma->ma_valid |= MA_HSM;
977 else if (rc2 < 0 && rc2 != -ENODATA)
981 #ifdef CONFIG_FS_POSIX_ACL
982 if (need & MA_ACL_DEF && S_ISDIR(mode)) {
983 buf->lb_buf = ma->ma_acl;
984 buf->lb_len = ma->ma_acl_size;
985 rc2 = mo_xattr_get(env, next, buf, XATTR_NAME_ACL_DEFAULT);
987 ma->ma_acl_size = rc2;
988 ma->ma_valid |= MA_ACL_DEF;
989 } else if (rc2 == -ENODATA) {
998 CDEBUG(D_INODE, "after getattr rc = %d, ma_valid = %#llx ma_lmm=%p\n",
999 rc, ma->ma_valid, ma->ma_lmm);
1003 static int mdt_getattr_internal(struct mdt_thread_info *info,
1004 struct mdt_object *o, int ma_need)
1006 struct md_object *next = mdt_object_child(o);
1007 const struct mdt_body *reqbody = info->mti_body;
1008 struct ptlrpc_request *req = mdt_info_req(info);
1009 struct md_attr *ma = &info->mti_attr;
1010 struct lu_attr *la = &ma->ma_attr;
1011 struct req_capsule *pill = info->mti_pill;
1012 const struct lu_env *env = info->mti_env;
1013 struct mdt_body *repbody;
1014 struct lu_buf *buffer = &info->mti_buf;
1015 struct obd_export *exp = info->mti_exp;
1019 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_GETATTR_PACK))
1020 RETURN(err_serious(-ENOMEM));
1022 repbody = req_capsule_server_get(pill, &RMF_MDT_BODY);
1026 if (mdt_object_remote(o)) {
1027 /* This object is located on remote node.*/
1028 /* Return -ENOTSUPP for old client */
1029 if (!mdt_is_dne_client(req->rq_export))
1030 GOTO(out, rc = -ENOTSUPP);
1032 repbody->mbo_fid1 = *mdt_object_fid(o);
1033 repbody->mbo_valid = OBD_MD_FLID | OBD_MD_MDS;
1037 if (reqbody->mbo_eadatasize > 0) {
1038 buffer->lb_buf = req_capsule_server_get(pill, &RMF_MDT_MD);
1039 if (buffer->lb_buf == NULL)
1040 GOTO(out, rc = -EPROTO);
1041 buffer->lb_len = req_capsule_get_size(pill, &RMF_MDT_MD,
1044 buffer->lb_buf = NULL;
1046 ma_need &= ~(MA_LOV | MA_LMV);
1047 CDEBUG(D_INFO, "%s: RPC from %s: does not need LOVEA.\n",
1048 mdt_obd_name(info->mti_mdt),
1049 req->rq_export->exp_client_uuid.uuid);
1052 /* If it is dir object and client require MEA, then we got MEA */
1053 if (S_ISDIR(lu_object_attr(&next->mo_lu)) &&
1054 (reqbody->mbo_valid & (OBD_MD_MEA | OBD_MD_DEFAULT_MEA))) {
1055 /* Assumption: MDT_MD size is enough for lmv size. */
1056 ma->ma_lmv = buffer->lb_buf;
1057 ma->ma_lmv_size = buffer->lb_len;
1058 ma->ma_need = MA_INODE;
1059 if (ma->ma_lmv_size > 0) {
1060 if (reqbody->mbo_valid & OBD_MD_MEA)
1061 ma->ma_need |= MA_LMV;
1062 else if (reqbody->mbo_valid & OBD_MD_DEFAULT_MEA)
1063 ma->ma_need |= MA_LMV_DEF;
1066 ma->ma_lmm = buffer->lb_buf;
1067 ma->ma_lmm_size = buffer->lb_len;
1068 ma->ma_need = MA_INODE | MA_HSM;
1069 if (ma->ma_lmm_size > 0)
1070 ma->ma_need |= MA_LOV;
1073 if (S_ISDIR(lu_object_attr(&next->mo_lu)) &&
1074 reqbody->mbo_valid & OBD_MD_FLDIREA &&
1075 lustre_msg_get_opc(req->rq_reqmsg) == MDS_GETATTR) {
1076 /* get default stripe info for this dir. */
1077 ma->ma_need |= MA_LOV_DEF;
1079 ma->ma_need |= ma_need;
1081 rc = mdt_attr_get_complex(info, o, ma);
1083 CDEBUG(rc == -ENOENT ? D_OTHER : D_ERROR,
1084 "%s: getattr error for "DFID": rc = %d\n",
1085 mdt_obd_name(info->mti_mdt),
1086 PFID(mdt_object_fid(o)), rc);
1090 /* if file is released, check if a restore is running */
1091 if (ma->ma_valid & MA_HSM) {
1092 repbody->mbo_valid |= OBD_MD_TSTATE;
1093 if ((ma->ma_hsm.mh_flags & HS_RELEASED) &&
1094 mdt_hsm_restore_is_running(info, mdt_object_fid(o)))
1095 repbody->mbo_t_state = MS_RESTORE;
1098 if (likely(ma->ma_valid & MA_INODE))
1099 mdt_pack_attr2body(info, repbody, la, mdt_object_fid(o));
1103 if (mdt_body_has_lov(la, reqbody)) {
1104 if (ma->ma_valid & MA_LOV) {
1105 LASSERT(ma->ma_lmm_size);
1106 repbody->mbo_eadatasize = ma->ma_lmm_size;
1107 if (S_ISDIR(la->la_mode))
1108 repbody->mbo_valid |= OBD_MD_FLDIREA;
1110 repbody->mbo_valid |= OBD_MD_FLEASIZE;
1111 mdt_dump_lmm(D_INFO, ma->ma_lmm, repbody->mbo_valid);
1113 if (ma->ma_valid & MA_LMV) {
1114 /* Return -ENOTSUPP for old client */
1115 if (!mdt_is_striped_client(req->rq_export))
1118 LASSERT(S_ISDIR(la->la_mode));
1119 mdt_dump_lmv(D_INFO, ma->ma_lmv);
1120 repbody->mbo_eadatasize = ma->ma_lmv_size;
1121 repbody->mbo_valid |= (OBD_MD_FLDIREA|OBD_MD_MEA);
1123 if (ma->ma_valid & MA_LMV_DEF) {
1124 /* Return -ENOTSUPP for old client */
1125 if (!mdt_is_striped_client(req->rq_export))
1127 LASSERT(S_ISDIR(la->la_mode));
1128 mdt_dump_lmv(D_INFO, ma->ma_lmv);
1129 repbody->mbo_eadatasize = ma->ma_lmv_size;
1130 repbody->mbo_valid |= (OBD_MD_FLDIREA |
1131 OBD_MD_DEFAULT_MEA);
1133 } else if (S_ISLNK(la->la_mode) &&
1134 reqbody->mbo_valid & OBD_MD_LINKNAME) {
1135 buffer->lb_buf = ma->ma_lmm;
1136 /* eadatasize from client includes NULL-terminator, so
1137 * there is no need to read it */
1138 buffer->lb_len = reqbody->mbo_eadatasize - 1;
1139 rc = mo_readlink(env, next, buffer);
1140 if (unlikely(rc <= 0)) {
1141 CERROR("%s: readlink failed for "DFID": rc = %d\n",
1142 mdt_obd_name(info->mti_mdt),
1143 PFID(mdt_object_fid(o)), rc);
1146 int print_limit = min_t(int, PAGE_SIZE - 128, rc);
1148 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_READLINK_EPROTO))
1150 repbody->mbo_valid |= OBD_MD_LINKNAME;
1151 /* we need to report back size with NULL-terminator
1152 * because client expects that */
1153 repbody->mbo_eadatasize = rc + 1;
1154 if (repbody->mbo_eadatasize != reqbody->mbo_eadatasize)
1155 CDEBUG(D_INODE, "%s: Read shorter symlink %d "
1156 "on "DFID ", expected %d\n",
1157 mdt_obd_name(info->mti_mdt),
1158 rc, PFID(mdt_object_fid(o)),
1159 reqbody->mbo_eadatasize - 1);
1160 /* NULL terminate */
1161 ((char *)ma->ma_lmm)[rc] = 0;
1163 /* If the total CDEBUG() size is larger than a page, it
1164 * will print a warning to the console, avoid this by
1165 * printing just the last part of the symlink. */
1166 CDEBUG(D_INODE, "symlink dest %s%.*s, len = %d\n",
1167 print_limit < rc ? "..." : "", print_limit,
1168 (char *)ma->ma_lmm + rc - print_limit, rc);
1173 if (reqbody->mbo_valid & OBD_MD_FLMODEASIZE) {
1174 repbody->mbo_max_mdsize = info->mti_mdt->mdt_max_mdsize;
1175 repbody->mbo_valid |= OBD_MD_FLMODEASIZE;
1176 CDEBUG(D_INODE, "changing the max MD size to %u\n",
1177 repbody->mbo_max_mdsize);
1180 #ifdef CONFIG_FS_POSIX_ACL
1181 if ((exp_connect_flags(req->rq_export) & OBD_CONNECT_ACL) &&
1182 (reqbody->mbo_valid & OBD_MD_FLACL)) {
1183 struct lu_nodemap *nodemap = nodemap_get_from_exp(exp);
1184 if (IS_ERR(nodemap))
1185 RETURN(PTR_ERR(nodemap));
1187 rc = mdt_pack_acl2body(info, repbody, o, nodemap);
1188 nodemap_putref(nodemap);
1194 mdt_counter_incr(req, LPROC_MDT_GETATTR);
1199 static int mdt_getattr(struct tgt_session_info *tsi)
1201 struct mdt_thread_info *info = tsi2mdt_info(tsi);
1202 struct mdt_object *obj = info->mti_object;
1203 struct req_capsule *pill = info->mti_pill;
1204 struct mdt_body *reqbody;
1205 struct mdt_body *repbody;
1209 reqbody = req_capsule_client_get(pill, &RMF_MDT_BODY);
1211 LASSERT(obj != NULL);
1212 LASSERT(lu_object_assert_exists(&obj->mot_obj));
1214 /* Unlike intent case where we need to pre-fill out buffers early on
1215 * in intent policy for ldlm reasons, here we can have a much better
1216 * guess at EA size by just reading it from disk.
1217 * Exceptions are readdir and (missing) directory striping */
1219 if (reqbody->mbo_valid & OBD_MD_LINKNAME) {
1220 /* No easy way to know how long is the symlink, but it cannot
1221 * be more than PATH_MAX, so we allocate +1 */
1224 /* A special case for fs ROOT: getattr there might fetch
1225 * default EA for entire fs, not just for this dir!
1227 } else if (lu_fid_eq(mdt_object_fid(obj),
1228 &info->mti_mdt->mdt_md_root_fid) &&
1229 (reqbody->mbo_valid & OBD_MD_FLDIREA) &&
1230 (lustre_msg_get_opc(mdt_info_req(info)->rq_reqmsg) ==
1232 /* Should the default strping be bigger, mdt_fix_reply
1233 * will reallocate */
1234 rc = DEF_REP_MD_SIZE;
1236 /* Read the actual EA size from disk */
1237 rc = mdt_attr_get_eabuf_size(info, obj);
1241 GOTO(out, rc = err_serious(rc));
1243 req_capsule_set_size(pill, &RMF_MDT_MD, RCL_SERVER, rc);
1245 /* Set ACL reply buffer size as LUSTRE_POSIX_ACL_MAX_SIZE_OLD
1246 * by default. If the target object has more ACL entries, then
1247 * enlarge the buffer when necessary. */
1248 req_capsule_set_size(pill, &RMF_ACL, RCL_SERVER,
1249 LUSTRE_POSIX_ACL_MAX_SIZE_OLD);
1251 rc = req_capsule_server_pack(pill);
1252 if (unlikely(rc != 0))
1253 GOTO(out, rc = err_serious(rc));
1255 repbody = req_capsule_server_get(pill, &RMF_MDT_BODY);
1256 LASSERT(repbody != NULL);
1257 repbody->mbo_eadatasize = 0;
1258 repbody->mbo_aclsize = 0;
1260 rc = mdt_check_ucred(info);
1262 GOTO(out_shrink, rc);
1264 info->mti_cross_ref = !!(reqbody->mbo_valid & OBD_MD_FLCROSSREF);
1266 rc = mdt_getattr_internal(info, obj, 0);
1269 mdt_client_compatibility(info);
1270 rc2 = mdt_fix_reply(info);
1274 mdt_thread_info_fini(info);
1279 * Handler of layout intent RPC requiring the layout modification
1281 * \param[in] info thread environment
1282 * \param[in] obj object
1283 * \param[in] layout layout intent
1284 * \param[in] buf buffer containing client's lovea, could be empty
1286 * \retval 0 on success
1287 * \retval < 0 error code
1289 static int mdt_layout_change(struct mdt_thread_info *info,
1290 struct mdt_object *obj,
1291 struct layout_intent *layout,
1292 const struct lu_buf *buf)
1294 struct mdt_lock_handle *lh = &info->mti_lh[MDT_LH_LOCAL];
1298 CDEBUG(D_INFO, "got layout change request from client: "
1299 "opc:%u flags:%#x extent[%#llx,%#llx)\n",
1300 layout->li_opc, layout->li_flags,
1301 layout->li_start, layout->li_end);
1302 if (layout->li_start >= layout->li_end) {
1303 CERROR("Recieved an invalid layout change range [%llu, %llu) "
1304 "for "DFID"\n", layout->li_start, layout->li_end,
1305 PFID(mdt_object_fid(obj)));
1309 if (!S_ISREG(lu_object_attr(&obj->mot_obj)))
1310 GOTO(out, rc = -EINVAL);
1312 rc = mo_permission(info->mti_env, NULL, mdt_object_child(obj), NULL,
1317 /* take layout lock to prepare layout change */
1318 mdt_lock_reg_init(lh, LCK_EX);
1319 rc = mdt_object_lock(info, obj, lh,
1320 MDS_INODELOCK_LAYOUT | MDS_INODELOCK_XATTR);
1324 rc = mo_layout_change(info->mti_env, mdt_object_child(obj), layout,
1327 mdt_object_unlock(info, obj, lh, 1);
1333 * Exchange MOF_LOV_CREATED flags between two objects after a
1334 * layout swap. No assumption is made on whether o1 or o2 have
1335 * created objects or not.
1337 * \param[in,out] o1 First swap layout object
1338 * \param[in,out] o2 Second swap layout object
1340 static void mdt_swap_lov_flag(struct mdt_object *o1, struct mdt_object *o2)
1342 unsigned int o1_lov_created = o1->mot_lov_created;
1344 mutex_lock(&o1->mot_lov_mutex);
1345 mutex_lock(&o2->mot_lov_mutex);
1347 o1->mot_lov_created = o2->mot_lov_created;
1348 o2->mot_lov_created = o1_lov_created;
1350 mutex_unlock(&o2->mot_lov_mutex);
1351 mutex_unlock(&o1->mot_lov_mutex);
1354 static int mdt_swap_layouts(struct tgt_session_info *tsi)
1356 struct mdt_thread_info *info;
1357 struct ptlrpc_request *req = tgt_ses_req(tsi);
1358 struct obd_export *exp = req->rq_export;
1359 struct mdt_object *o1, *o2, *o;
1360 struct mdt_lock_handle *lh1, *lh2;
1361 struct mdc_swap_layouts *msl;
1365 /* client does not support layout lock, so layout swaping
1367 * FIXME: there is a problem for old clients which don't support
1368 * layout lock yet. If those clients have already opened the file
1369 * they won't be notified at all so that old layout may still be
1370 * used to do IO. This can be fixed after file release is landed by
1371 * doing exclusive open and taking full EX ibits lock. - Jinshan */
1372 if (!exp_connect_layout(exp))
1373 RETURN(-EOPNOTSUPP);
1375 info = tsi2mdt_info(tsi);
1377 if (info->mti_dlm_req != NULL)
1378 ldlm_request_cancel(req, info->mti_dlm_req, 0, LATF_SKIP);
1380 o1 = info->mti_object;
1381 o = o2 = mdt_object_find(info->mti_env, info->mti_mdt,
1382 &info->mti_body->mbo_fid2);
1384 GOTO(out, rc = PTR_ERR(o));
1386 if (mdt_object_remote(o) || !mdt_object_exists(o)) /* remote object */
1387 GOTO(put, rc = -ENOENT);
1389 rc = lu_fid_cmp(&info->mti_body->mbo_fid1, &info->mti_body->mbo_fid2);
1390 if (unlikely(rc == 0)) /* same file, you kidding me? no-op. */
1396 /* permission check. Make sure the calling process having permission
1397 * to write both files. */
1398 rc = mo_permission(info->mti_env, NULL, mdt_object_child(o1), NULL,
1403 rc = mo_permission(info->mti_env, NULL, mdt_object_child(o2), NULL,
1408 msl = req_capsule_client_get(info->mti_pill, &RMF_SWAP_LAYOUTS);
1410 GOTO(put, rc = -EPROTO);
1412 lh1 = &info->mti_lh[MDT_LH_NEW];
1413 mdt_lock_reg_init(lh1, LCK_EX);
1414 lh2 = &info->mti_lh[MDT_LH_OLD];
1415 mdt_lock_reg_init(lh2, LCK_EX);
1417 rc = mdt_object_lock(info, o1, lh1, MDS_INODELOCK_LAYOUT |
1418 MDS_INODELOCK_XATTR);
1422 rc = mdt_object_lock(info, o2, lh2, MDS_INODELOCK_LAYOUT |
1423 MDS_INODELOCK_XATTR);
1427 rc = mo_swap_layouts(info->mti_env, mdt_object_child(o1),
1428 mdt_object_child(o2), msl->msl_flags);
1432 mdt_swap_lov_flag(o1, o2);
1435 mdt_object_unlock(info, o2, lh2, rc);
1437 mdt_object_unlock(info, o1, lh1, rc);
1439 mdt_object_put(info->mti_env, o);
1441 mdt_thread_info_fini(info);
1445 static int mdt_raw_lookup(struct mdt_thread_info *info,
1446 struct mdt_object *parent,
1447 const struct lu_name *lname,
1448 struct ldlm_reply *ldlm_rep)
1450 struct lu_fid *child_fid = &info->mti_tmp_fid1;
1454 LASSERT(!info->mti_cross_ref);
1456 /* Only got the fid of this obj by name */
1457 fid_zero(child_fid);
1458 rc = mdo_lookup(info->mti_env, mdt_object_child(info->mti_object),
1459 lname, child_fid, &info->mti_spec);
1461 struct mdt_body *repbody;
1463 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
1464 repbody->mbo_fid1 = *child_fid;
1465 repbody->mbo_valid = OBD_MD_FLID;
1466 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_POS);
1467 } else if (rc == -ENOENT) {
1468 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_NEG);
1475 * UPDATE lock should be taken against parent, and be released before exit;
1476 * child_bits lock should be taken against child, and be returned back:
1477 * (1)normal request should release the child lock;
1478 * (2)intent request will grant the lock to client.
1480 static int mdt_getattr_name_lock(struct mdt_thread_info *info,
1481 struct mdt_lock_handle *lhc,
1483 struct ldlm_reply *ldlm_rep)
1485 struct ptlrpc_request *req = mdt_info_req(info);
1486 struct mdt_body *reqbody = NULL;
1487 struct mdt_object *parent = info->mti_object;
1488 struct mdt_object *child;
1489 struct lu_fid *child_fid = &info->mti_tmp_fid1;
1490 struct lu_name *lname = NULL;
1491 struct mdt_lock_handle *lhp = NULL;
1492 struct ldlm_lock *lock;
1500 is_resent = lustre_handle_is_used(&lhc->mlh_reg_lh);
1501 LASSERT(ergo(is_resent,
1502 lustre_msg_get_flags(req->rq_reqmsg) & MSG_RESENT));
1507 if (info->mti_cross_ref) {
1508 /* Only getattr on the child. Parent is on another node. */
1509 mdt_set_disposition(info, ldlm_rep,
1510 DISP_LOOKUP_EXECD | DISP_LOOKUP_POS);
1512 CDEBUG(D_INODE, "partial getattr_name child_fid = "DFID", "
1514 PFID(mdt_object_fid(child)), ldlm_rep);
1516 rc = mdt_check_resent_lock(info, child, lhc);
1519 } else if (rc > 0) {
1520 mdt_lock_handle_init(lhc);
1521 mdt_lock_reg_init(lhc, LCK_PR);
1524 * Object's name is on another MDS, no lookup or layout
1525 * lock is needed here but update lock is.
1527 child_bits &= ~(MDS_INODELOCK_LOOKUP |
1528 MDS_INODELOCK_LAYOUT);
1529 child_bits |= MDS_INODELOCK_PERM | MDS_INODELOCK_UPDATE;
1531 rc = mdt_object_lock(info, child, lhc, child_bits);
1536 /* Finally, we can get attr for child. */
1537 if (!mdt_object_exists(child)) {
1538 LU_OBJECT_DEBUG(D_INFO, info->mti_env,
1540 "remote object doesn't exist.");
1541 mdt_object_unlock(info, child, lhc, 1);
1545 rc = mdt_getattr_internal(info, child, 0);
1546 if (unlikely(rc != 0))
1547 mdt_object_unlock(info, child, lhc, 1);
1552 lname = &info->mti_name;
1553 mdt_name_unpack(info->mti_pill, &RMF_NAME, lname, MNF_FIX_ANON);
1555 if (lu_name_is_valid(lname)) {
1556 CDEBUG(D_INODE, "getattr with lock for "DFID"/"DNAME", "
1557 "ldlm_rep = %p\n", PFID(mdt_object_fid(parent)),
1558 PNAME(lname), ldlm_rep);
1560 reqbody = req_capsule_client_get(info->mti_pill, &RMF_MDT_BODY);
1561 if (unlikely(reqbody == NULL))
1562 RETURN(err_serious(-EPROTO));
1564 *child_fid = reqbody->mbo_fid2;
1566 if (unlikely(!fid_is_sane(child_fid)))
1567 RETURN(err_serious(-EINVAL));
1569 CDEBUG(D_INODE, "getattr with lock for "DFID"/"DFID", "
1571 PFID(mdt_object_fid(parent)),
1572 PFID(&reqbody->mbo_fid2), ldlm_rep);
1575 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_EXECD);
1577 if (unlikely(!mdt_object_exists(parent)) && lu_name_is_valid(lname)) {
1578 LU_OBJECT_DEBUG(D_INODE, info->mti_env,
1580 "Parent doesn't exist!");
1584 if (mdt_object_remote(parent)) {
1585 CERROR("%s: parent "DFID" is on remote target\n",
1586 mdt_obd_name(info->mti_mdt),
1587 PFID(mdt_object_fid(parent)));
1591 if (lu_name_is_valid(lname)) {
1592 /* Always allow to lookup ".." */
1593 if (unlikely(lname->ln_namelen == 2 &&
1594 lname->ln_name[0] == '.' &&
1595 lname->ln_name[1] == '.'))
1596 info->mti_spec.sp_permitted = 1;
1598 if (info->mti_body->mbo_valid == OBD_MD_FLID) {
1599 rc = mdt_raw_lookup(info, parent, lname, ldlm_rep);
1604 /* step 1: lock parent only if parent is a directory */
1605 if (S_ISDIR(lu_object_attr(&parent->mot_obj))) {
1606 lhp = &info->mti_lh[MDT_LH_PARENT];
1607 mdt_lock_pdo_init(lhp, LCK_PR, lname);
1608 rc = mdt_object_lock(info, parent, lhp,
1609 MDS_INODELOCK_UPDATE);
1610 if (unlikely(rc != 0))
1614 /* step 2: lookup child's fid by name */
1615 fid_zero(child_fid);
1616 rc = mdo_lookup(info->mti_env, mdt_object_child(parent), lname,
1617 child_fid, &info->mti_spec);
1619 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_NEG);
1622 GOTO(out_parent, rc);
1625 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_POS);
1628 *step 3: find the child object by fid & lock it.
1629 * regardless if it is local or remote.
1631 *Note: LU-3240 (commit 762f2114d282a98ebfa4dbbeea9298a8088ad24e)
1632 * set parent dir fid the same as child fid in getattr by fid case
1633 * we should not lu_object_find() the object again, could lead
1634 * to hung if there is a concurrent unlink destroyed the object.
1636 if (lu_fid_eq(mdt_object_fid(parent), child_fid)) {
1637 mdt_object_get(info->mti_env, parent);
1640 child = mdt_object_find(info->mti_env, info->mti_mdt,
1644 if (unlikely(IS_ERR(child)))
1645 GOTO(out_parent, rc = PTR_ERR(child));
1647 OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_RESEND, obd_timeout * 2);
1648 if (!mdt_object_exists(child)) {
1649 LU_OBJECT_DEBUG(D_INODE, info->mti_env,
1651 "Object doesn't exist!");
1652 GOTO(out_child, rc = -ENOENT);
1655 rc = mdt_check_resent_lock(info, child, lhc);
1657 GOTO(out_child, rc);
1658 } else if (rc > 0) {
1659 mdt_lock_handle_init(lhc);
1660 mdt_lock_reg_init(lhc, LCK_PR);
1662 if (!(child_bits & MDS_INODELOCK_UPDATE) &&
1663 mdt_object_exists(child) && !mdt_object_remote(child)) {
1664 struct md_attr *ma = &info->mti_attr;
1667 ma->ma_need = MA_INODE;
1668 rc = mdt_attr_get_complex(info, child, ma);
1669 if (unlikely(rc != 0))
1670 GOTO(out_child, rc);
1672 /* If the file has not been changed for some time, we
1673 * return not only a LOOKUP lock, but also an UPDATE
1674 * lock and this might save us RPC on later STAT. For
1675 * directories, it also let negative dentry cache start
1676 * working for this dir. */
1677 if (ma->ma_valid & MA_INODE &&
1678 ma->ma_attr.la_valid & LA_CTIME &&
1679 info->mti_mdt->mdt_namespace->ns_ctime_age_limit +
1680 ma->ma_attr.la_ctime < cfs_time_current_sec())
1681 child_bits |= MDS_INODELOCK_UPDATE;
1684 /* layout lock must be granted in a best-effort way
1685 * for IT operations */
1686 LASSERT(!(child_bits & MDS_INODELOCK_LAYOUT));
1687 if (!OBD_FAIL_CHECK(OBD_FAIL_MDS_NO_LL_GETATTR) &&
1688 exp_connect_layout(info->mti_exp) &&
1689 S_ISREG(lu_object_attr(&child->mot_obj)) &&
1690 !mdt_object_remote(child) && ldlm_rep != NULL) {
1691 /* try to grant layout lock for regular file. */
1692 try_bits = MDS_INODELOCK_LAYOUT;
1695 if (try_bits != 0) {
1696 /* try layout lock, it may fail to be granted due to
1697 * contention at LOOKUP or UPDATE */
1698 rc = mdt_object_lock_try(info, child, lhc, &child_bits,
1700 if (child_bits & MDS_INODELOCK_LAYOUT)
1703 /* Do not enqueue the UPDATE lock from MDT(cross-MDT),
1704 * client will enqueue the lock to the remote MDT */
1705 if (mdt_object_remote(child))
1706 child_bits &= ~MDS_INODELOCK_UPDATE;
1707 rc = mdt_object_lock(info, child, lhc, child_bits);
1709 if (unlikely(rc != 0))
1710 GOTO(out_child, rc);
1713 lock = ldlm_handle2lock(&lhc->mlh_reg_lh);
1715 /* finally, we can get attr for child. */
1716 rc = mdt_getattr_internal(info, child, ma_need);
1717 if (unlikely(rc != 0)) {
1718 mdt_object_unlock(info, child, lhc, 1);
1720 /* Debugging code. */
1721 LDLM_DEBUG(lock, "Returning lock to client");
1722 LASSERTF(fid_res_name_eq(mdt_object_fid(child),
1723 &lock->l_resource->lr_name),
1724 "Lock res_id: "DLDLMRES", fid: "DFID"\n",
1725 PLDLMRES(lock->l_resource),
1726 PFID(mdt_object_fid(child)));
1729 LDLM_LOCK_PUT(lock);
1733 mdt_object_put(info->mti_env, child);
1736 mdt_object_unlock(info, parent, lhp, 1);
1740 /* normal handler: should release the child lock */
1741 static int mdt_getattr_name(struct tgt_session_info *tsi)
1743 struct mdt_thread_info *info = tsi2mdt_info(tsi);
1744 struct mdt_lock_handle *lhc = &info->mti_lh[MDT_LH_CHILD];
1745 struct mdt_body *reqbody;
1746 struct mdt_body *repbody;
1750 reqbody = req_capsule_client_get(info->mti_pill, &RMF_MDT_BODY);
1751 LASSERT(reqbody != NULL);
1752 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
1753 LASSERT(repbody != NULL);
1755 info->mti_cross_ref = !!(reqbody->mbo_valid & OBD_MD_FLCROSSREF);
1756 repbody->mbo_eadatasize = 0;
1757 repbody->mbo_aclsize = 0;
1759 rc = mdt_init_ucred_intent_getattr(info, reqbody);
1761 GOTO(out_shrink, rc);
1763 rc = mdt_getattr_name_lock(info, lhc, MDS_INODELOCK_UPDATE, NULL);
1764 if (lustre_handle_is_used(&lhc->mlh_reg_lh)) {
1765 ldlm_lock_decref(&lhc->mlh_reg_lh, lhc->mlh_reg_mode);
1766 lhc->mlh_reg_lh.cookie = 0;
1768 mdt_exit_ucred(info);
1771 mdt_client_compatibility(info);
1772 rc2 = mdt_fix_reply(info);
1775 mdt_thread_info_fini(info);
1779 static int mdt_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
1780 void *karg, void __user *uarg);
1782 static int mdt_set_info(struct tgt_session_info *tsi)
1784 struct ptlrpc_request *req = tgt_ses_req(tsi);
1787 int keylen, vallen, rc = 0;
1791 key = req_capsule_client_get(tsi->tsi_pill, &RMF_SETINFO_KEY);
1793 DEBUG_REQ(D_HA, req, "no set_info key");
1794 RETURN(err_serious(-EFAULT));
1797 keylen = req_capsule_get_size(tsi->tsi_pill, &RMF_SETINFO_KEY,
1800 val = req_capsule_client_get(tsi->tsi_pill, &RMF_SETINFO_VAL);
1802 DEBUG_REQ(D_HA, req, "no set_info val");
1803 RETURN(err_serious(-EFAULT));
1806 vallen = req_capsule_get_size(tsi->tsi_pill, &RMF_SETINFO_VAL,
1809 /* Swab any part of val you need to here */
1810 if (KEY_IS(KEY_READ_ONLY)) {
1811 spin_lock(&req->rq_export->exp_lock);
1813 *exp_connect_flags_ptr(req->rq_export) |=
1816 *exp_connect_flags_ptr(req->rq_export) &=
1817 ~OBD_CONNECT_RDONLY;
1818 spin_unlock(&req->rq_export->exp_lock);
1819 } else if (KEY_IS(KEY_CHANGELOG_CLEAR)) {
1820 struct changelog_setinfo *cs = val;
1822 if (vallen != sizeof(*cs)) {
1823 CERROR("%s: bad changelog_clear setinfo size %d\n",
1824 tgt_name(tsi->tsi_tgt), vallen);
1827 if (ptlrpc_req_need_swab(req)) {
1828 __swab64s(&cs->cs_recno);
1829 __swab32s(&cs->cs_id);
1832 rc = mdt_iocontrol(OBD_IOC_CHANGELOG_CLEAR, req->rq_export,
1834 } else if (KEY_IS(KEY_EVICT_BY_NID)) {
1836 obd_export_evict_by_nid(req->rq_export->exp_obd, val);
1843 static int mdt_readpage(struct tgt_session_info *tsi)
1845 struct mdt_thread_info *info = mdt_th_info(tsi->tsi_env);
1846 struct mdt_object *object = mdt_obj(tsi->tsi_corpus);
1847 struct lu_rdpg *rdpg = &info->mti_u.rdpg.mti_rdpg;
1848 const struct mdt_body *reqbody = tsi->tsi_mdt_body;
1849 struct mdt_body *repbody;
1855 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_READPAGE_PACK))
1856 RETURN(err_serious(-ENOMEM));
1858 repbody = req_capsule_server_get(tsi->tsi_pill, &RMF_MDT_BODY);
1859 if (repbody == NULL || reqbody == NULL)
1860 RETURN(err_serious(-EFAULT));
1863 * prepare @rdpg before calling lower layers and transfer itself. Here
1864 * reqbody->size contains offset of where to start to read and
1865 * reqbody->nlink contains number bytes to read.
1867 rdpg->rp_hash = reqbody->mbo_size;
1868 if (rdpg->rp_hash != reqbody->mbo_size) {
1869 CERROR("Invalid hash: %#llx != %#llx\n",
1870 rdpg->rp_hash, reqbody->mbo_size);
1874 rdpg->rp_attrs = reqbody->mbo_mode;
1875 if (exp_connect_flags(tsi->tsi_exp) & OBD_CONNECT_64BITHASH)
1876 rdpg->rp_attrs |= LUDA_64BITHASH;
1877 rdpg->rp_count = min_t(unsigned int, reqbody->mbo_nlink,
1878 exp_max_brw_size(tsi->tsi_exp));
1879 rdpg->rp_npages = (rdpg->rp_count + PAGE_SIZE - 1) >>
1881 OBD_ALLOC(rdpg->rp_pages, rdpg->rp_npages * sizeof rdpg->rp_pages[0]);
1882 if (rdpg->rp_pages == NULL)
1885 for (i = 0; i < rdpg->rp_npages; ++i) {
1886 rdpg->rp_pages[i] = alloc_page(GFP_NOFS);
1887 if (rdpg->rp_pages[i] == NULL)
1888 GOTO(free_rdpg, rc = -ENOMEM);
1891 /* call lower layers to fill allocated pages with directory data */
1892 rc = mo_readpage(tsi->tsi_env, mdt_object_child(object), rdpg);
1894 GOTO(free_rdpg, rc);
1896 /* send pages to client */
1897 rc = tgt_sendpage(tsi, rdpg, rc);
1902 for (i = 0; i < rdpg->rp_npages; i++)
1903 if (rdpg->rp_pages[i] != NULL)
1904 __free_page(rdpg->rp_pages[i]);
1905 OBD_FREE(rdpg->rp_pages, rdpg->rp_npages * sizeof rdpg->rp_pages[0]);
1907 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_SENDPAGE))
1913 static int mdt_fix_attr_ucred(struct mdt_thread_info *info, __u32 op)
1915 struct lu_ucred *uc = mdt_ucred_check(info);
1916 struct lu_attr *attr = &info->mti_attr.ma_attr;
1921 if (op != REINT_SETATTR) {
1922 if ((attr->la_valid & LA_UID) && (attr->la_uid != -1))
1923 attr->la_uid = uc->uc_fsuid;
1924 /* for S_ISGID, inherit gid from his parent, such work will be
1925 * done in cmm/mdd layer, here set all cases as uc->uc_fsgid. */
1926 if ((attr->la_valid & LA_GID) && (attr->la_gid != -1))
1927 attr->la_gid = uc->uc_fsgid;
1933 static int mdt_reint_internal(struct mdt_thread_info *info,
1934 struct mdt_lock_handle *lhc,
1937 struct req_capsule *pill = info->mti_pill;
1938 struct mdt_body *repbody;
1943 rc = mdt_reint_unpack(info, op);
1945 CERROR("Can't unpack reint, rc %d\n", rc);
1946 RETURN(err_serious(rc));
1949 /* for replay (no_create) lmm is not needed, client has it already */
1950 if (req_capsule_has_field(pill, &RMF_MDT_MD, RCL_SERVER))
1951 req_capsule_set_size(pill, &RMF_MDT_MD, RCL_SERVER,
1954 /* llog cookies are always 0, the field is kept for compatibility */
1955 if (req_capsule_has_field(pill, &RMF_LOGCOOKIES, RCL_SERVER))
1956 req_capsule_set_size(pill, &RMF_LOGCOOKIES, RCL_SERVER, 0);
1958 /* Set ACL reply buffer size as LUSTRE_POSIX_ACL_MAX_SIZE_OLD
1959 * by default. If the target object has more ACL entries, then
1960 * enlarge the buffer when necessary. */
1961 if (req_capsule_has_field(pill, &RMF_ACL, RCL_SERVER))
1962 req_capsule_set_size(pill, &RMF_ACL, RCL_SERVER,
1963 LUSTRE_POSIX_ACL_MAX_SIZE_OLD);
1965 rc = req_capsule_server_pack(pill);
1967 CERROR("Can't pack response, rc %d\n", rc);
1968 RETURN(err_serious(rc));
1971 if (req_capsule_has_field(pill, &RMF_MDT_BODY, RCL_SERVER)) {
1972 repbody = req_capsule_server_get(pill, &RMF_MDT_BODY);
1974 repbody->mbo_eadatasize = 0;
1975 repbody->mbo_aclsize = 0;
1978 OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_REINT_DELAY, 10);
1980 /* for replay no cookkie / lmm need, because client have this already */
1981 if (info->mti_spec.no_create)
1982 if (req_capsule_has_field(pill, &RMF_MDT_MD, RCL_SERVER))
1983 req_capsule_set_size(pill, &RMF_MDT_MD, RCL_SERVER, 0);
1985 rc = mdt_init_ucred_reint(info);
1987 GOTO(out_shrink, rc);
1989 rc = mdt_fix_attr_ucred(info, op);
1991 GOTO(out_ucred, rc = err_serious(rc));
1993 rc = mdt_check_resent(info, mdt_reconstruct, lhc);
1995 GOTO(out_ucred, rc);
1996 } else if (rc == 1) {
1997 DEBUG_REQ(D_INODE, mdt_info_req(info), "resent opt.");
1998 rc = lustre_msg_get_status(mdt_info_req(info)->rq_repmsg);
1999 GOTO(out_ucred, rc);
2001 rc = mdt_reint_rec(info, lhc);
2004 mdt_exit_ucred(info);
2006 mdt_client_compatibility(info);
2007 rc2 = mdt_fix_reply(info);
2013 static long mdt_reint_opcode(struct ptlrpc_request *req,
2014 const struct req_format **fmt)
2016 struct mdt_device *mdt;
2017 struct mdt_rec_reint *rec;
2020 rec = req_capsule_client_get(&req->rq_pill, &RMF_REC_REINT);
2022 opc = rec->rr_opcode;
2023 DEBUG_REQ(D_INODE, req, "reint opt = %ld", opc);
2024 if (opc < REINT_MAX && fmt[opc] != NULL)
2025 req_capsule_extend(&req->rq_pill, fmt[opc]);
2027 mdt = mdt_exp2dev(req->rq_export);
2028 CERROR("%s: Unsupported opcode '%ld' from client '%s':"
2029 " rc = %d\n", req->rq_export->exp_obd->obd_name,
2030 opc, mdt->mdt_ldlm_client->cli_name, -EFAULT);
2031 opc = err_serious(-EFAULT);
2034 opc = err_serious(-EFAULT);
2039 static int mdt_reint(struct tgt_session_info *tsi)
2043 static const struct req_format *reint_fmts[REINT_MAX] = {
2044 [REINT_SETATTR] = &RQF_MDS_REINT_SETATTR,
2045 [REINT_CREATE] = &RQF_MDS_REINT_CREATE,
2046 [REINT_LINK] = &RQF_MDS_REINT_LINK,
2047 [REINT_UNLINK] = &RQF_MDS_REINT_UNLINK,
2048 [REINT_RENAME] = &RQF_MDS_REINT_RENAME,
2049 [REINT_OPEN] = &RQF_MDS_REINT_OPEN,
2050 [REINT_SETXATTR] = &RQF_MDS_REINT_SETXATTR,
2051 [REINT_RMENTRY] = &RQF_MDS_REINT_UNLINK,
2052 [REINT_MIGRATE] = &RQF_MDS_REINT_RENAME
2057 opc = mdt_reint_opcode(tgt_ses_req(tsi), reint_fmts);
2059 struct mdt_thread_info *info = tsi2mdt_info(tsi);
2061 * No lock possible here from client to pass it to reint code
2064 rc = mdt_reint_internal(info, NULL, opc);
2065 mdt_thread_info_fini(info);
2070 tsi->tsi_reply_fail_id = OBD_FAIL_MDS_REINT_NET_REP;
2074 /* this should sync the whole device */
2075 static int mdt_device_sync(const struct lu_env *env, struct mdt_device *mdt)
2077 struct dt_device *dt = mdt->mdt_bottom;
2081 rc = dt->dd_ops->dt_sync(env, dt);
2085 /* this should sync this object */
2086 static int mdt_object_sync(const struct lu_env *env, struct obd_export *exp,
2087 struct mdt_object *mo)
2093 if (!mdt_object_exists(mo)) {
2094 CWARN("%s: non existing object "DFID": rc = %d\n",
2095 exp->exp_obd->obd_name, PFID(mdt_object_fid(mo)),
2100 rc = mo_object_sync(env, mdt_object_child(mo));
2105 static int mdt_sync(struct tgt_session_info *tsi)
2107 struct ptlrpc_request *req = tgt_ses_req(tsi);
2108 struct req_capsule *pill = tsi->tsi_pill;
2109 struct mdt_body *body;
2114 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_SYNC_PACK))
2115 RETURN(err_serious(-ENOMEM));
2117 if (fid_seq(&tsi->tsi_mdt_body->mbo_fid1) == 0) {
2118 rc = mdt_device_sync(tsi->tsi_env, mdt_exp2dev(tsi->tsi_exp));
2120 struct mdt_thread_info *info = tsi2mdt_info(tsi);
2122 /* sync an object */
2123 rc = mdt_object_sync(tsi->tsi_env, tsi->tsi_exp,
2126 const struct lu_fid *fid;
2127 struct lu_attr *la = &info->mti_attr.ma_attr;
2129 info->mti_attr.ma_need = MA_INODE;
2130 info->mti_attr.ma_valid = 0;
2131 rc = mdt_attr_get_complex(info, info->mti_object,
2134 body = req_capsule_server_get(pill,
2136 fid = mdt_object_fid(info->mti_object);
2137 mdt_pack_attr2body(info, body, la, fid);
2140 mdt_thread_info_fini(info);
2143 mdt_counter_incr(req, LPROC_MDT_SYNC);
2148 static int mdt_data_sync(struct tgt_session_info *tsi)
2150 struct mdt_thread_info *info;
2151 struct mdt_device *mdt = mdt_exp2dev(tsi->tsi_exp);
2152 struct ost_body *body = tsi->tsi_ost_body;
2153 struct ost_body *repbody;
2154 struct mdt_object *mo = NULL;
2160 repbody = req_capsule_server_get(tsi->tsi_pill, &RMF_OST_BODY);
2162 /* if no fid is specified then do nothing,
2163 * device sync is done via MDS_SYNC */
2164 if (fid_is_zero(&tsi->tsi_fid))
2167 mo = mdt_object_find(tsi->tsi_env, mdt, &tsi->tsi_fid);
2169 RETURN(PTR_ERR(mo));
2171 rc = mdt_object_sync(tsi->tsi_env, tsi->tsi_exp, mo);
2175 repbody->oa.o_oi = body->oa.o_oi;
2176 repbody->oa.o_valid = OBD_MD_FLID | OBD_MD_FLGROUP;
2178 info = tsi2mdt_info(tsi);
2179 ma = &info->mti_attr;
2180 ma->ma_need = MA_INODE;
2182 rc = mdt_attr_get_complex(info, mo, ma);
2184 obdo_from_la(&repbody->oa, &ma->ma_attr, VALID_FLAGS);
2187 mdt_thread_info_fini(info);
2192 mdt_object_put(tsi->tsi_env, mo);
2197 * Handle quota control requests to consult current usage/limit, but also
2198 * to configure quota enforcement
2200 static int mdt_quotactl(struct tgt_session_info *tsi)
2202 struct obd_export *exp = tsi->tsi_exp;
2203 struct req_capsule *pill = tsi->tsi_pill;
2204 struct obd_quotactl *oqctl, *repoqc;
2206 struct mdt_device *mdt = mdt_exp2dev(exp);
2207 struct lu_device *qmt = mdt->mdt_qmt_dev;
2208 struct lu_nodemap *nodemap;
2211 oqctl = req_capsule_client_get(pill, &RMF_OBD_QUOTACTL);
2213 RETURN(err_serious(-EPROTO));
2215 rc = req_capsule_server_pack(pill);
2217 RETURN(err_serious(rc));
2219 nodemap = nodemap_get_from_exp(exp);
2220 if (IS_ERR(nodemap))
2221 RETURN(PTR_ERR(nodemap));
2223 switch (oqctl->qc_cmd) {
2224 /* master quotactl */
2227 if (!nodemap_can_setquota(nodemap))
2228 GOTO(out_nodemap, rc = -EPERM);
2232 GOTO(out_nodemap, rc = -EOPNOTSUPP);
2233 /* slave quotactl */
2238 CERROR("Unsupported quotactl command: %d\n", oqctl->qc_cmd);
2239 GOTO(out_nodemap, rc = -EFAULT);
2243 switch (oqctl->qc_type) {
2245 id = nodemap_map_id(nodemap, NODEMAP_UID,
2246 NODEMAP_CLIENT_TO_FS, id);
2249 id = nodemap_map_id(nodemap, NODEMAP_GID,
2250 NODEMAP_CLIENT_TO_FS, id);
2253 /* todo: check/map project id */
2257 GOTO(out_nodemap, rc = -EOPNOTSUPP);
2259 repoqc = req_capsule_server_get(pill, &RMF_OBD_QUOTACTL);
2261 GOTO(out_nodemap, rc = err_serious(-EFAULT));
2263 if (oqctl->qc_cmd == Q_SETINFO || oqctl->qc_cmd == Q_SETQUOTA)
2264 barrier_exit(tsi->tsi_tgt->lut_bottom);
2266 if (oqctl->qc_id != id)
2267 swap(oqctl->qc_id, id);
2269 if (oqctl->qc_cmd == Q_SETINFO || oqctl->qc_cmd == Q_SETQUOTA) {
2270 if (unlikely(!barrier_entry(tsi->tsi_tgt->lut_bottom)))
2271 RETURN(-EINPROGRESS);
2274 switch (oqctl->qc_cmd) {
2280 /* forward quotactl request to QMT */
2281 rc = qmt_hdls.qmth_quotactl(tsi->tsi_env, qmt, oqctl);
2286 /* slave quotactl */
2287 rc = lquotactl_slv(tsi->tsi_env, tsi->tsi_tgt->lut_bottom,
2292 CERROR("Unsupported quotactl command: %d\n", oqctl->qc_cmd);
2293 GOTO(out_nodemap, rc = -EFAULT);
2296 if (oqctl->qc_id != id)
2297 swap(oqctl->qc_id, id);
2304 nodemap_putref(nodemap);
2309 /** clone llog ctxt from child (mdd)
2310 * This allows remote llog (replicator) access.
2311 * We can either pass all llog RPCs (eg mdt_llog_create) on to child where the
2312 * context was originally set up, or we can handle them directly.
2313 * I choose the latter, but that means I need any llog
2314 * contexts set up by child to be accessable by the mdt. So we clone the
2315 * context into our context list here.
2317 static int mdt_llog_ctxt_clone(const struct lu_env *env, struct mdt_device *mdt,
2320 struct md_device *next = mdt->mdt_child;
2321 struct llog_ctxt *ctxt;
2324 if (!llog_ctxt_null(mdt2obd_dev(mdt), idx))
2327 rc = next->md_ops->mdo_llog_ctxt_get(env, next, idx, (void **)&ctxt);
2328 if (rc || ctxt == NULL) {
2332 rc = llog_group_set_ctxt(&mdt2obd_dev(mdt)->obd_olg, ctxt, idx);
2334 CERROR("Can't set mdt ctxt %d\n", rc);
2339 static int mdt_llog_ctxt_unclone(const struct lu_env *env,
2340 struct mdt_device *mdt, int idx)
2342 struct llog_ctxt *ctxt;
2344 ctxt = llog_get_context(mdt2obd_dev(mdt), idx);
2347 /* Put once for the get we just did, and once for the clone */
2348 llog_ctxt_put(ctxt);
2349 llog_ctxt_put(ctxt);
2354 * sec context handlers
2356 static int mdt_sec_ctx_handle(struct tgt_session_info *tsi)
2358 CFS_FAIL_TIMEOUT(OBD_FAIL_SEC_CTX_HDL_PAUSE, cfs_fail_val);
2364 * quota request handlers
2366 static int mdt_quota_dqacq(struct tgt_session_info *tsi)
2368 struct mdt_device *mdt = mdt_exp2dev(tsi->tsi_exp);
2369 struct lu_device *qmt = mdt->mdt_qmt_dev;
2374 RETURN(err_serious(-EOPNOTSUPP));
2376 rc = qmt_hdls.qmth_dqacq(tsi->tsi_env, qmt, tgt_ses_req(tsi));
2380 struct mdt_object *mdt_object_new(const struct lu_env *env,
2381 struct mdt_device *d,
2382 const struct lu_fid *f)
2384 struct lu_object_conf conf = { .loc_flags = LOC_F_NEW };
2385 struct lu_object *o;
2386 struct mdt_object *m;
2389 CDEBUG(D_INFO, "Allocate object for "DFID"\n", PFID(f));
2390 o = lu_object_find(env, &d->mdt_lu_dev, f, &conf);
2391 if (unlikely(IS_ERR(o)))
2392 m = (struct mdt_object *)o;
2398 struct mdt_object *mdt_object_find(const struct lu_env *env,
2399 struct mdt_device *d,
2400 const struct lu_fid *f)
2402 struct lu_object *o;
2403 struct mdt_object *m;
2406 CDEBUG(D_INFO, "Find object for "DFID"\n", PFID(f));
2407 o = lu_object_find(env, &d->mdt_lu_dev, f, NULL);
2408 if (unlikely(IS_ERR(o)))
2409 m = (struct mdt_object *)o;
2417 * Asyncronous commit for mdt device.
2419 * Pass asynchonous commit call down the MDS stack.
2421 * \param env environment
2422 * \param mdt the mdt device
2424 static void mdt_device_commit_async(const struct lu_env *env,
2425 struct mdt_device *mdt)
2427 struct dt_device *dt = mdt->mdt_bottom;
2431 rc = dt->dd_ops->dt_commit_async(env, dt);
2432 if (unlikely(rc != 0))
2433 CWARN("%s: async commit start failed: rc = %d\n",
2434 mdt_obd_name(mdt), rc);
2435 atomic_inc(&mdt->mdt_async_commit_count);
2440 * Mark the lock as "synchonous".
2442 * Mark the lock to deffer transaction commit to the unlock time.
2444 * \param lock the lock to mark as "synchonous"
2446 * \see mdt_is_lock_sync
2447 * \see mdt_save_lock
2449 static inline void mdt_set_lock_sync(struct ldlm_lock *lock)
2451 lock->l_ast_data = (void*)1;
2455 * Check whehter the lock "synchonous" or not.
2457 * \param lock the lock to check
2458 * \retval 1 the lock is "synchonous"
2459 * \retval 0 the lock isn't "synchronous"
2461 * \see mdt_set_lock_sync
2462 * \see mdt_save_lock
2464 static inline int mdt_is_lock_sync(struct ldlm_lock *lock)
2466 return lock->l_ast_data != NULL;
2470 * Blocking AST for mdt locks.
2472 * Starts transaction commit if in case of COS lock conflict or
2473 * deffers such a commit to the mdt_save_lock.
2475 * \param lock the lock which blocks a request or cancelling lock
2476 * \param desc unused
2477 * \param data unused
2478 * \param flag indicates whether this cancelling or blocking callback
2480 * \see ldlm_blocking_ast_nocheck
2482 int mdt_blocking_ast(struct ldlm_lock *lock, struct ldlm_lock_desc *desc,
2483 void *data, int flag)
2485 struct obd_device *obd = ldlm_lock_to_ns(lock)->ns_obd;
2486 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
2487 bool commit_async = false;
2491 if (flag == LDLM_CB_CANCELING)
2494 lock_res_and_lock(lock);
2495 if (lock->l_blocking_ast != mdt_blocking_ast) {
2496 unlock_res_and_lock(lock);
2499 /* There is no lock conflict if l_blocking_lock == NULL,
2500 * it indicates a blocking ast sent from ldlm_lock_decref_internal
2501 * when the last reference to a local lock was released */
2502 if (lock->l_req_mode & (LCK_PW | LCK_EX) &&
2503 lock->l_blocking_lock != NULL) {
2504 if (mdt_cos_is_enabled(mdt)) {
2505 if (lock->l_client_cookie !=
2506 lock->l_blocking_lock->l_client_cookie)
2507 mdt_set_lock_sync(lock);
2508 } else if (mdt_slc_is_enabled(mdt) &&
2509 ldlm_is_cos_incompat(lock->l_blocking_lock)) {
2510 mdt_set_lock_sync(lock);
2512 * we may do extra commit here, but there is a small
2513 * window to miss a commit: lock was unlocked (saved),
2514 * then a conflict lock queued and we come here, but
2515 * REP-ACK not received, so lock was not converted to
2517 * Fortunately this window is quite small, so the
2518 * extra commit should be rare (not to say distributed
2519 * operation is rare too).
2521 commit_async = true;
2523 } else if (lock->l_req_mode == LCK_COS &&
2524 lock->l_blocking_lock != NULL) {
2525 commit_async = true;
2528 rc = ldlm_blocking_ast_nocheck(lock);
2533 rc = lu_env_init(&env, LCT_LOCAL);
2534 if (unlikely(rc != 0))
2535 CWARN("%s: lu_env initialization failed, cannot "
2536 "start asynchronous commit: rc = %d\n",
2539 mdt_device_commit_async(&env, mdt);
2546 * Blocking AST for cross-MDT lock
2548 * Discard lock from uncommitted_slc_locks and cancel it.
2550 * \param lock the lock which blocks a request or cancelling lock
2551 * \param desc unused
2552 * \param data unused
2553 * \param flag indicates whether this cancelling or blocking callback
2554 * \retval 0 on success
2555 * \retval negative number on error
2557 int mdt_remote_blocking_ast(struct ldlm_lock *lock, struct ldlm_lock_desc *desc,
2558 void *data, int flag)
2564 case LDLM_CB_BLOCKING: {
2565 struct lustre_handle lockh;
2567 ldlm_lock2handle(lock, &lockh);
2568 rc = ldlm_cli_cancel(&lockh,
2569 ldlm_is_atomic_cb(lock) ? 0 : LCF_ASYNC);
2571 CDEBUG(D_INODE, "ldlm_cli_cancel: %d\n", rc);
2576 case LDLM_CB_CANCELING: {
2577 struct obd_device *obd = ldlm_lock_to_ns(lock)->ns_obd;
2578 struct mdt_device *mdt =
2579 mdt_dev(obd->obd_lu_dev->ld_site->ls_top_dev);
2581 LDLM_DEBUG(lock, "Revoke remote lock\n");
2583 /* discard slc lock here so that it can be cleaned anytime,
2584 * especially for cleanup_resource() */
2585 tgt_discard_slc_lock(&mdt->mdt_lut, lock);
2587 /* once we cache lock, l_ast_data is set to mdt_object */
2588 if (lock->l_ast_data != NULL) {
2589 struct mdt_object *mo = lock->l_ast_data;
2592 rc = lu_env_init(&env, LCT_MD_THREAD);
2593 if (unlikely(rc != 0)) {
2594 CWARN("%s: lu_env initialization failed, object"
2595 "%p "DFID" is leaked!\n",
2597 PFID(mdt_object_fid(mo)));
2601 if (lock->l_policy_data.l_inodebits.bits &
2602 (MDS_INODELOCK_XATTR | MDS_INODELOCK_UPDATE)) {
2603 rc = mo_invalidate(&env, mdt_object_child(mo));
2604 mo->mot_cache_attr = 0;
2606 mdt_object_put(&env, mo);
2618 int mdt_check_resent_lock(struct mdt_thread_info *info,
2619 struct mdt_object *mo,
2620 struct mdt_lock_handle *lhc)
2622 /* the lock might already be gotten in ldlm_handle_enqueue() */
2623 if (unlikely(lustre_handle_is_used(&lhc->mlh_reg_lh))) {
2624 struct ptlrpc_request *req = mdt_info_req(info);
2625 struct ldlm_lock *lock;
2627 lock = ldlm_handle2lock(&lhc->mlh_reg_lh);
2628 LASSERT(lustre_msg_get_flags(req->rq_reqmsg) & MSG_RESENT);
2630 /* Lock is pinned by ldlm_handle_enqueue0() as it is
2631 * a resend case, however, it could be already destroyed
2632 * due to client eviction or a raced cancel RPC. */
2633 LDLM_DEBUG_NOLOCK("Invalid lock handle %#llx",
2634 lhc->mlh_reg_lh.cookie);
2638 if (!fid_res_name_eq(mdt_object_fid(mo),
2639 &lock->l_resource->lr_name)) {
2640 CWARN("%s: Although resent, but still not "
2641 "get child lock:"DFID"\n",
2642 info->mti_exp->exp_obd->obd_name,
2643 PFID(mdt_object_fid(mo)));
2644 LDLM_LOCK_PUT(lock);
2647 LDLM_LOCK_PUT(lock);
2653 int mdt_remote_object_lock_try(struct mdt_thread_info *mti,
2654 struct mdt_object *o, const struct lu_fid *fid,
2655 struct lustre_handle *lh, enum ldlm_mode mode,
2656 __u64 *ibits, __u64 trybits, bool cache)
2658 struct ldlm_enqueue_info *einfo = &mti->mti_einfo;
2659 union ldlm_policy_data *policy = &mti->mti_policy;
2660 struct ldlm_res_id *res_id = &mti->mti_res_id;
2664 LASSERT(mdt_object_remote(o));
2666 fid_build_reg_res_name(fid, res_id);
2668 memset(einfo, 0, sizeof(*einfo));
2669 einfo->ei_type = LDLM_IBITS;
2670 einfo->ei_mode = mode;
2671 einfo->ei_cb_bl = mdt_remote_blocking_ast;
2672 einfo->ei_cb_cp = ldlm_completion_ast;
2673 einfo->ei_enq_slave = 0;
2674 einfo->ei_res_id = res_id;
2678 * if we cache lock, couple lock with mdt_object, so that object
2679 * can be easily found in lock ASTs.
2681 mdt_object_get(mti->mti_env, o);
2682 einfo->ei_cbdata = o;
2686 memset(policy, 0, sizeof(*policy));
2687 policy->l_inodebits.bits = *ibits;
2688 policy->l_inodebits.try_bits = trybits;
2690 rc = mo_object_lock(mti->mti_env, mdt_object_child(o), lh, einfo,
2692 if (rc < 0 && cache) {
2693 mdt_object_put(mti->mti_env, o);
2694 einfo->ei_cbdata = NULL;
2697 /* Return successfully acquired bits to a caller */
2699 struct ldlm_lock *lock = ldlm_handle2lock(lh);
2702 *ibits = lock->l_policy_data.l_inodebits.bits;
2703 LDLM_LOCK_PUT(lock);
2708 int mdt_remote_object_lock(struct mdt_thread_info *mti, struct mdt_object *o,
2709 const struct lu_fid *fid, struct lustre_handle *lh,
2710 enum ldlm_mode mode, __u64 ibits, bool cache)
2712 return mdt_remote_object_lock_try(mti, o, fid, lh, mode, &ibits, 0,
2716 static int mdt_object_local_lock(struct mdt_thread_info *info,
2717 struct mdt_object *o,
2718 struct mdt_lock_handle *lh, __u64 *ibits,
2719 __u64 trybits, bool cos_incompat)
2721 struct ldlm_namespace *ns = info->mti_mdt->mdt_namespace;
2722 union ldlm_policy_data *policy = &info->mti_policy;
2723 struct ldlm_res_id *res_id = &info->mti_res_id;
2728 LASSERT(!lustre_handle_is_used(&lh->mlh_reg_lh));
2729 LASSERT(!lustre_handle_is_used(&lh->mlh_pdo_lh));
2730 LASSERT(lh->mlh_reg_mode != LCK_MINMODE);
2731 LASSERT(lh->mlh_type != MDT_NUL_LOCK);
2734 LASSERT(lh->mlh_reg_mode == LCK_PW ||
2735 lh->mlh_reg_mode == LCK_EX);
2736 dlmflags |= LDLM_FL_COS_INCOMPAT;
2737 } else if (mdt_cos_is_enabled(info->mti_mdt)) {
2738 dlmflags |= LDLM_FL_COS_ENABLED;
2741 /* Only enqueue LOOKUP lock for remote object */
2742 if (mdt_object_remote(o)) {
2743 LASSERT(*ibits == MDS_INODELOCK_LOOKUP);
2746 if (lh->mlh_type == MDT_PDO_LOCK) {
2747 /* check for exists after object is locked */
2748 if (mdt_object_exists(o) == 0) {
2749 /* Non-existent object shouldn't have PDO lock */
2752 /* Non-dir object shouldn't have PDO lock */
2753 if (!S_ISDIR(lu_object_attr(&o->mot_obj)))
2759 fid_build_reg_res_name(mdt_object_fid(o), res_id);
2760 dlmflags |= LDLM_FL_ATOMIC_CB;
2763 * Take PDO lock on whole directory and build correct @res_id for lock
2764 * on part of directory.
2766 if (lh->mlh_pdo_hash != 0) {
2767 LASSERT(lh->mlh_type == MDT_PDO_LOCK);
2768 mdt_lock_pdo_mode(info, o, lh);
2769 if (lh->mlh_pdo_mode != LCK_NL) {
2771 * Do not use LDLM_FL_LOCAL_ONLY for parallel lock, it
2772 * is never going to be sent to client and we do not
2773 * want it slowed down due to possible cancels.
2775 policy->l_inodebits.bits = MDS_INODELOCK_UPDATE;
2776 policy->l_inodebits.try_bits = 0;
2777 rc = mdt_fid_lock(ns, &lh->mlh_pdo_lh, lh->mlh_pdo_mode,
2778 policy, res_id, dlmflags,
2779 info->mti_exp == NULL ? NULL :
2780 &info->mti_exp->exp_handle.h_cookie);
2781 if (unlikely(rc != 0))
2782 GOTO(out_unlock, rc);
2786 * Finish res_id initializing by name hash marking part of
2787 * directory which is taking modification.
2789 res_id->name[LUSTRE_RES_ID_HSH_OFF] = lh->mlh_pdo_hash;
2792 policy->l_inodebits.bits = *ibits;
2793 policy->l_inodebits.try_bits = trybits;
2796 * Use LDLM_FL_LOCAL_ONLY for this lock. We do not know yet if it is
2797 * going to be sent to client. If it is - mdt_intent_policy() path will
2798 * fix it up and turn FL_LOCAL flag off.
2800 rc = mdt_fid_lock(ns, &lh->mlh_reg_lh, lh->mlh_reg_mode, policy,
2801 res_id, LDLM_FL_LOCAL_ONLY | dlmflags,
2802 info->mti_exp == NULL ? NULL :
2803 &info->mti_exp->exp_handle.h_cookie);
2806 mdt_object_unlock(info, o, lh, 1);
2807 else if (unlikely(OBD_FAIL_PRECHECK(OBD_FAIL_MDS_PDO_LOCK)) &&
2808 lh->mlh_pdo_hash != 0 &&
2809 (lh->mlh_reg_mode == LCK_PW || lh->mlh_reg_mode == LCK_EX))
2810 OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_PDO_LOCK, 15);
2812 /* Return successfully acquired bits to a caller */
2814 struct ldlm_lock *lock = ldlm_handle2lock(&lh->mlh_reg_lh);
2817 *ibits = lock->l_policy_data.l_inodebits.bits;
2818 LDLM_LOCK_PUT(lock);
2824 mdt_object_lock_internal(struct mdt_thread_info *info, struct mdt_object *o,
2825 struct mdt_lock_handle *lh, __u64 *ibits,
2826 __u64 trybits, bool cos_incompat)
2828 struct mdt_lock_handle *local_lh = NULL;
2832 if (!mdt_object_remote(o)) {
2833 rc = mdt_object_local_lock(info, o, lh, ibits, trybits,
2838 /* XXX do not support PERM/LAYOUT/XATTR lock for remote object yet */
2839 *ibits &= ~(MDS_INODELOCK_PERM | MDS_INODELOCK_LAYOUT |
2840 MDS_INODELOCK_XATTR);
2842 /* Only enqueue LOOKUP lock for remote object */
2843 if (*ibits & MDS_INODELOCK_LOOKUP) {
2844 __u64 local = MDS_INODELOCK_LOOKUP;
2846 rc = mdt_object_local_lock(info, o, lh, &local, 0,
2854 if ((*ibits | trybits) & MDS_INODELOCK_UPDATE) {
2855 /* Sigh, PDO needs to enqueue 2 locks right now, but
2856 * enqueue RPC can only request 1 lock, to avoid extra
2857 * RPC, so it will instead enqueue EX lock for remote
2858 * object anyway XXX*/
2859 if (lh->mlh_type == MDT_PDO_LOCK &&
2860 lh->mlh_pdo_hash != 0) {
2861 CDEBUG(D_INFO, "%s: "DFID" convert PDO lock to"
2862 "EX lock.\n", mdt_obd_name(info->mti_mdt),
2863 PFID(mdt_object_fid(o)));
2864 lh->mlh_pdo_hash = 0;
2865 lh->mlh_rreg_mode = LCK_EX;
2866 lh->mlh_type = MDT_REG_LOCK;
2869 rc = mdt_remote_object_lock_try(info, o, mdt_object_fid(o),
2872 ibits, trybits, false);
2873 if (rc != ELDLM_OK) {
2874 if (local_lh != NULL)
2875 mdt_object_unlock(info, o, local_lh, rc);
2883 int mdt_object_lock(struct mdt_thread_info *info, struct mdt_object *o,
2884 struct mdt_lock_handle *lh, __u64 ibits)
2886 return mdt_object_lock_internal(info, o, lh, &ibits, 0, false);
2889 int mdt_reint_object_lock(struct mdt_thread_info *info, struct mdt_object *o,
2890 struct mdt_lock_handle *lh, __u64 ibits,
2893 LASSERT(lh->mlh_reg_mode == LCK_PW || lh->mlh_reg_mode == LCK_EX);
2894 return mdt_object_lock_internal(info, o, lh, &ibits, 0,
2898 int mdt_object_lock_try(struct mdt_thread_info *info, struct mdt_object *o,
2899 struct mdt_lock_handle *lh, __u64 *ibits,
2900 __u64 trybits, bool cos_incompat)
2902 return mdt_object_lock_internal(info, o, lh, ibits, trybits,
2907 * Save a lock within request object.
2909 * Keep the lock referenced until whether client ACK or transaction
2910 * commit happens or release the lock immediately depending on input
2911 * parameters. If COS is ON, a write lock is converted to COS lock
2914 * \param info thead info object
2915 * \param h lock handle
2916 * \param mode lock mode
2917 * \param decref force immediate lock releasing
2919 void mdt_save_lock(struct mdt_thread_info *info, struct lustre_handle *h,
2920 enum ldlm_mode mode, int decref)
2924 if (lustre_handle_is_used(h)) {
2925 if (decref || !info->mti_has_trans ||
2926 !(mode & (LCK_PW | LCK_EX))) {
2927 mdt_fid_unlock(h, mode);
2929 struct mdt_device *mdt = info->mti_mdt;
2930 struct ldlm_lock *lock = ldlm_handle2lock(h);
2931 struct ptlrpc_request *req = mdt_info_req(info);
2932 bool cos = mdt_cos_is_enabled(mdt);
2933 bool convert_lock = !cos && mdt_slc_is_enabled(mdt);
2935 LASSERTF(lock != NULL, "no lock for cookie %#llx\n",
2938 /* there is no request if mdt_object_unlock() is called
2939 * from mdt_export_cleanup()->mdt_add_dirty_flag() */
2940 if (likely(req != NULL)) {
2941 LDLM_DEBUG(lock, "save lock request %p reply "
2942 "state %p transno %lld\n", req,
2943 req->rq_reply_state, req->rq_transno);
2945 ldlm_lock_downgrade(lock, LCK_COS);
2948 if (req->rq_export->exp_disconnected)
2949 mdt_fid_unlock(h, mode);
2951 ptlrpc_save_lock(req, h, mode, cos,
2954 mdt_fid_unlock(h, mode);
2956 if (mdt_is_lock_sync(lock)) {
2957 CDEBUG(D_HA, "found sync-lock,"
2958 " async commit started\n");
2959 mdt_device_commit_async(info->mti_env,
2962 LDLM_LOCK_PUT(lock);
2971 * Save cross-MDT lock in uncommitted_slc_locks
2973 * Keep the lock referenced until transaction commit happens or release the lock
2974 * immediately depending on input parameters.
2976 * \param info thead info object
2977 * \param h lock handle
2978 * \param mode lock mode
2979 * \param decref force immediate lock releasing
2981 static void mdt_save_remote_lock(struct mdt_thread_info *info,
2982 struct mdt_object *o, struct lustre_handle *h,
2983 enum ldlm_mode mode, int decref)
2987 if (lustre_handle_is_used(h)) {
2988 struct ldlm_lock *lock = ldlm_handle2lock(h);
2991 (lock->l_policy_data.l_inodebits.bits &
2992 (MDS_INODELOCK_XATTR | MDS_INODELOCK_UPDATE)))
2993 mo_invalidate(info->mti_env, mdt_object_child(o));
2995 if (decref || !info->mti_has_trans ||
2996 !(mode & (LCK_PW | LCK_EX))) {
2997 ldlm_lock_decref_and_cancel(h, mode);
2998 LDLM_LOCK_PUT(lock);
3000 struct ptlrpc_request *req = mdt_info_req(info);
3002 LASSERT(req != NULL);
3003 tgt_save_slc_lock(&info->mti_mdt->mdt_lut, lock,
3005 ldlm_lock_decref(h, mode);
3014 * Unlock mdt object.
3016 * Immeditely release the regular lock and the PDO lock or save the
3017 * lock in request and keep them referenced until client ACK or
3018 * transaction commit.
3020 * \param info thread info object
3021 * \param o mdt object
3022 * \param lh mdt lock handle referencing regular and PDO locks
3023 * \param decref force immediate lock releasing
3025 * XXX o is not used and may be NULL, see hsm_cdt_request_completed().
3027 void mdt_object_unlock(struct mdt_thread_info *info, struct mdt_object *o,
3028 struct mdt_lock_handle *lh, int decref)
3032 mdt_save_lock(info, &lh->mlh_pdo_lh, lh->mlh_pdo_mode, decref);
3033 mdt_save_lock(info, &lh->mlh_reg_lh, lh->mlh_reg_mode, decref);
3034 mdt_save_remote_lock(info, o, &lh->mlh_rreg_lh, lh->mlh_rreg_mode,
3040 struct mdt_object *mdt_object_find_lock(struct mdt_thread_info *info,
3041 const struct lu_fid *f,
3042 struct mdt_lock_handle *lh,
3045 struct mdt_object *o;
3047 o = mdt_object_find(info->mti_env, info->mti_mdt, f);
3051 rc = mdt_object_lock(info, o, lh, ibits);
3053 mdt_object_put(info->mti_env, o);
3060 void mdt_object_unlock_put(struct mdt_thread_info * info,
3061 struct mdt_object * o,
3062 struct mdt_lock_handle *lh,
3065 mdt_object_unlock(info, o, lh, decref);
3066 mdt_object_put(info->mti_env, o);
3070 * Generic code handling requests that have struct mdt_body passed in:
3072 * - extract mdt_body from request and save it in @info, if present;
3074 * - create lu_object, corresponding to the fid in mdt_body, and save it in
3077 * - if HABEO_CORPUS flag is set for this request type check whether object
3078 * actually exists on storage (lu_object_exists()).
3081 static int mdt_body_unpack(struct mdt_thread_info *info, __u32 flags)
3083 const struct mdt_body *body;
3084 struct mdt_object *obj;
3085 const struct lu_env *env;
3086 struct req_capsule *pill;
3090 env = info->mti_env;
3091 pill = info->mti_pill;
3093 body = info->mti_body = req_capsule_client_get(pill, &RMF_MDT_BODY);
3097 if (!(body->mbo_valid & OBD_MD_FLID))
3100 if (!fid_is_sane(&body->mbo_fid1)) {
3101 CERROR("Invalid fid: "DFID"\n", PFID(&body->mbo_fid1));
3105 obj = mdt_object_find(env, info->mti_mdt, &body->mbo_fid1);
3107 if ((flags & HABEO_CORPUS) && !mdt_object_exists(obj)) {
3108 mdt_object_put(env, obj);
3111 info->mti_object = obj;
3120 static int mdt_unpack_req_pack_rep(struct mdt_thread_info *info, __u32 flags)
3122 struct req_capsule *pill = info->mti_pill;
3126 if (req_capsule_has_field(pill, &RMF_MDT_BODY, RCL_CLIENT))
3127 rc = mdt_body_unpack(info, flags);
3131 if (rc == 0 && (flags & HABEO_REFERO)) {
3133 if (req_capsule_has_field(pill, &RMF_MDT_MD, RCL_SERVER))
3134 req_capsule_set_size(pill, &RMF_MDT_MD, RCL_SERVER,
3136 if (req_capsule_has_field(pill, &RMF_LOGCOOKIES, RCL_SERVER))
3137 req_capsule_set_size(pill, &RMF_LOGCOOKIES,
3140 /* Set ACL reply buffer size as LUSTRE_POSIX_ACL_MAX_SIZE_OLD
3141 * by default. If the target object has more ACL entries, then
3142 * enlarge the buffer when necessary. */
3143 if (req_capsule_has_field(pill, &RMF_ACL, RCL_SERVER))
3144 req_capsule_set_size(pill, &RMF_ACL, RCL_SERVER,
3145 LUSTRE_POSIX_ACL_MAX_SIZE_OLD);
3147 rc = req_capsule_server_pack(pill);
3152 void mdt_lock_handle_init(struct mdt_lock_handle *lh)
3154 lh->mlh_type = MDT_NUL_LOCK;
3155 lh->mlh_reg_lh.cookie = 0ull;
3156 lh->mlh_reg_mode = LCK_MINMODE;
3157 lh->mlh_pdo_lh.cookie = 0ull;
3158 lh->mlh_pdo_mode = LCK_MINMODE;
3159 lh->mlh_rreg_lh.cookie = 0ull;
3160 lh->mlh_rreg_mode = LCK_MINMODE;
3163 void mdt_lock_handle_fini(struct mdt_lock_handle *lh)
3165 LASSERT(!lustre_handle_is_used(&lh->mlh_reg_lh));
3166 LASSERT(!lustre_handle_is_used(&lh->mlh_pdo_lh));
3170 * Initialize fields of struct mdt_thread_info. Other fields are left in
3171 * uninitialized state, because it's too expensive to zero out whole
3172 * mdt_thread_info (> 1K) on each request arrival.
3174 void mdt_thread_info_init(struct ptlrpc_request *req,
3175 struct mdt_thread_info *info)
3179 info->mti_pill = &req->rq_pill;
3182 for (i = 0; i < ARRAY_SIZE(info->mti_lh); i++)
3183 mdt_lock_handle_init(&info->mti_lh[i]);
3185 /* mdt device: it can be NULL while CONNECT */
3186 if (req->rq_export) {
3187 info->mti_mdt = mdt_dev(req->rq_export->exp_obd->obd_lu_dev);
3188 info->mti_exp = req->rq_export;
3190 info->mti_mdt = NULL;
3191 info->mti_env = req->rq_svc_thread->t_env;
3192 info->mti_transno = lustre_msg_get_transno(req->rq_reqmsg);
3194 memset(&info->mti_attr, 0, sizeof(info->mti_attr));
3195 info->mti_big_buf = LU_BUF_NULL;
3196 info->mti_body = NULL;
3197 info->mti_object = NULL;
3198 info->mti_dlm_req = NULL;
3199 info->mti_has_trans = 0;
3200 info->mti_cross_ref = 0;
3201 info->mti_opdata = 0;
3202 info->mti_big_lmm_used = 0;
3203 info->mti_big_acl_used = 0;
3205 info->mti_spec.no_create = 0;
3206 info->mti_spec.sp_rm_entry = 0;
3207 info->mti_spec.sp_permitted = 0;
3208 info->mti_spec.sp_migrate_close = 0;
3210 info->mti_spec.u.sp_ea.eadata = NULL;
3211 info->mti_spec.u.sp_ea.eadatalen = 0;
3214 void mdt_thread_info_fini(struct mdt_thread_info *info)
3218 if (info->mti_object != NULL) {
3219 mdt_object_put(info->mti_env, info->mti_object);
3220 info->mti_object = NULL;
3223 for (i = 0; i < ARRAY_SIZE(info->mti_lh); i++)
3224 mdt_lock_handle_fini(&info->mti_lh[i]);
3225 info->mti_env = NULL;
3226 info->mti_pill = NULL;
3227 info->mti_exp = NULL;
3229 if (unlikely(info->mti_big_buf.lb_buf != NULL))
3230 lu_buf_free(&info->mti_big_buf);
3233 struct mdt_thread_info *tsi2mdt_info(struct tgt_session_info *tsi)
3235 struct mdt_thread_info *mti;
3237 mti = mdt_th_info(tsi->tsi_env);
3238 LASSERT(mti != NULL);
3240 mdt_thread_info_init(tgt_ses_req(tsi), mti);
3241 if (tsi->tsi_corpus != NULL) {
3242 mti->mti_object = mdt_obj(tsi->tsi_corpus);
3243 lu_object_get(tsi->tsi_corpus);
3245 mti->mti_body = tsi->tsi_mdt_body;
3246 mti->mti_dlm_req = tsi->tsi_dlm_req;
3251 static int mdt_tgt_connect(struct tgt_session_info *tsi)
3253 if (OBD_FAIL_CHECK(OBD_FAIL_TGT_DELAY_CONDITIONAL) &&
3255 tsi2mdt_info(tsi)->mti_mdt->mdt_seq_site.ss_node_id) {
3256 set_current_state(TASK_UNINTERRUPTIBLE);
3257 schedule_timeout(msecs_to_jiffies(3 * MSEC_PER_SEC));
3260 return tgt_connect(tsi);
3280 static int mdt_intent_getattr(enum mdt_it_code opcode,
3281 struct mdt_thread_info *info,
3282 struct ldlm_lock **, __u64);
3284 static int mdt_intent_getxattr(enum mdt_it_code opcode,
3285 struct mdt_thread_info *info,
3286 struct ldlm_lock **lockp,
3289 static int mdt_intent_layout(enum mdt_it_code opcode,
3290 struct mdt_thread_info *info,
3291 struct ldlm_lock **,
3293 static int mdt_intent_reint(enum mdt_it_code opcode,
3294 struct mdt_thread_info *info,
3295 struct ldlm_lock **,
3297 static int mdt_intent_glimpse(enum mdt_it_code opcode,
3298 struct mdt_thread_info *info,
3299 struct ldlm_lock **lockp, __u64 flags)
3301 return mdt_glimpse_enqueue(info, info->mti_mdt->mdt_namespace,
3304 static int mdt_intent_brw(enum mdt_it_code opcode,
3305 struct mdt_thread_info *info,
3306 struct ldlm_lock **lockp, __u64 flags)
3308 return mdt_brw_enqueue(info, info->mti_mdt->mdt_namespace,
3312 static struct mdt_it_flavor {
3313 const struct req_format *it_fmt;
3315 int (*it_act)(enum mdt_it_code ,
3316 struct mdt_thread_info *,
3317 struct ldlm_lock **,
3320 } mdt_it_flavor[] = {
3322 .it_fmt = &RQF_LDLM_INTENT,
3323 /*.it_flags = HABEO_REFERO,*/
3325 .it_act = mdt_intent_reint,
3326 .it_reint = REINT_OPEN
3329 .it_fmt = &RQF_LDLM_INTENT,
3331 * OCREAT is not a MUTABOR request as if the file
3333 * We do the extra check of OBD_CONNECT_RDONLY in
3334 * mdt_reint_open() when we really need to create
3338 .it_act = mdt_intent_reint,
3339 .it_reint = REINT_OPEN
3342 .it_fmt = &RQF_LDLM_INTENT,
3343 .it_flags = MUTABOR,
3344 .it_act = mdt_intent_reint,
3345 .it_reint = REINT_CREATE
3347 [MDT_IT_GETATTR] = {
3348 .it_fmt = &RQF_LDLM_INTENT_GETATTR,
3349 .it_flags = HABEO_REFERO,
3350 .it_act = mdt_intent_getattr
3352 [MDT_IT_READDIR] = {
3358 .it_fmt = &RQF_LDLM_INTENT_GETATTR,
3359 .it_flags = HABEO_REFERO,
3360 .it_act = mdt_intent_getattr
3363 .it_fmt = &RQF_LDLM_INTENT_UNLINK,
3364 .it_flags = MUTABOR,
3366 .it_reint = REINT_UNLINK
3370 .it_flags = MUTABOR,
3373 [MDT_IT_GETXATTR] = {
3374 .it_fmt = &RQF_LDLM_INTENT_GETXATTR,
3375 .it_flags = HABEO_CORPUS,
3376 .it_act = mdt_intent_getxattr
3379 .it_fmt = &RQF_LDLM_INTENT_LAYOUT,
3381 .it_act = mdt_intent_layout
3383 [MDT_IT_GLIMPSE] = {
3384 .it_fmt = &RQF_LDLM_INTENT,
3386 .it_act = mdt_intent_glimpse,
3389 .it_fmt = &RQF_LDLM_INTENT,
3391 .it_act = mdt_intent_brw,
3396 int mdt_intent_lock_replace(struct mdt_thread_info *info,
3397 struct ldlm_lock **lockp,
3398 struct mdt_lock_handle *lh,
3399 __u64 flags, int result)
3401 struct ptlrpc_request *req = mdt_info_req(info);
3402 struct ldlm_lock *lock = *lockp;
3403 struct ldlm_lock *new_lock;
3405 /* If possible resent found a lock, @lh is set to its handle */
3406 new_lock = ldlm_handle2lock_long(&lh->mlh_reg_lh, 0);
3408 if (new_lock == NULL && (flags & LDLM_FL_INTENT_ONLY)) {
3409 lh->mlh_reg_lh.cookie = 0;
3413 if (new_lock == NULL && (flags & LDLM_FL_RESENT)) {
3414 /* Lock is pinned by ldlm_handle_enqueue0() as it is
3415 * a resend case, however, it could be already destroyed
3416 * due to client eviction or a raced cancel RPC. */
3417 LDLM_DEBUG_NOLOCK("Invalid lock handle %#llx\n",
3418 lh->mlh_reg_lh.cookie);
3419 lh->mlh_reg_lh.cookie = 0;
3423 LASSERTF(new_lock != NULL,
3424 "lockh %#llx flags %#llx : rc = %d\n",
3425 lh->mlh_reg_lh.cookie, flags, result);
3428 * If we've already given this lock to a client once, then we should
3429 * have no readers or writers. Otherwise, we should have one reader
3430 * _or_ writer ref (which will be zeroed below) before returning the
3433 if (new_lock->l_export == req->rq_export) {
3434 LASSERT(new_lock->l_readers + new_lock->l_writers == 0);
3436 LASSERT(new_lock->l_export == NULL);
3437 LASSERT(new_lock->l_readers + new_lock->l_writers == 1);
3442 if (new_lock->l_export == req->rq_export) {
3444 * Already gave this to the client, which means that we
3445 * reconstructed a reply.
3447 LASSERT(lustre_msg_get_flags(req->rq_reqmsg) &
3450 LDLM_LOCK_RELEASE(new_lock);
3451 lh->mlh_reg_lh.cookie = 0;
3452 RETURN(ELDLM_LOCK_REPLACED);
3456 * Fixup the lock to be given to the client.
3458 lock_res_and_lock(new_lock);
3459 /* Zero new_lock->l_readers and new_lock->l_writers without triggering
3460 * possible blocking AST. */
3461 while (new_lock->l_readers > 0) {
3462 lu_ref_del(&new_lock->l_reference, "reader", new_lock);
3463 lu_ref_del(&new_lock->l_reference, "user", new_lock);
3464 new_lock->l_readers--;
3466 while (new_lock->l_writers > 0) {
3467 lu_ref_del(&new_lock->l_reference, "writer", new_lock);
3468 lu_ref_del(&new_lock->l_reference, "user", new_lock);
3469 new_lock->l_writers--;
3472 new_lock->l_export = class_export_lock_get(req->rq_export, new_lock);
3473 new_lock->l_blocking_ast = lock->l_blocking_ast;
3474 new_lock->l_completion_ast = lock->l_completion_ast;
3475 if (ldlm_has_dom(new_lock))
3476 new_lock->l_glimpse_ast = ldlm_server_glimpse_ast;
3477 new_lock->l_remote_handle = lock->l_remote_handle;
3478 new_lock->l_flags &= ~LDLM_FL_LOCAL;
3480 unlock_res_and_lock(new_lock);
3482 cfs_hash_add(new_lock->l_export->exp_lock_hash,
3483 &new_lock->l_remote_handle,
3484 &new_lock->l_exp_hash);
3486 LDLM_LOCK_RELEASE(new_lock);
3487 lh->mlh_reg_lh.cookie = 0;
3489 RETURN(ELDLM_LOCK_REPLACED);
3492 void mdt_intent_fixup_resent(struct mdt_thread_info *info,
3493 struct ldlm_lock *new_lock,
3494 struct mdt_lock_handle *lh, __u64 flags)
3496 struct ptlrpc_request *req = mdt_info_req(info);
3497 struct ldlm_request *dlmreq;
3499 if (!(lustre_msg_get_flags(req->rq_reqmsg) & MSG_RESENT))
3502 dlmreq = req_capsule_client_get(info->mti_pill, &RMF_DLM_REQ);
3504 /* Check if this is a resend case (MSG_RESENT is set on RPC) and a
3505 * lock was found by ldlm_handle_enqueue(); if so @lh must be
3507 if (flags & LDLM_FL_RESENT) {
3508 lh->mlh_reg_lh.cookie = new_lock->l_handle.h_cookie;
3509 lh->mlh_reg_mode = new_lock->l_granted_mode;
3511 LDLM_DEBUG(new_lock, "Restoring lock cookie");
3512 DEBUG_REQ(D_DLMTRACE, req, "restoring lock cookie %#llx",
3513 lh->mlh_reg_lh.cookie);
3518 * If the xid matches, then we know this is a resent request, and allow
3519 * it. (It's probably an OPEN, for which we don't send a lock.
3521 if (req_can_reconstruct(req, NULL))
3525 * This remote handle isn't enqueued, so we never received or processed
3526 * this request. Clear MSG_RESENT, because it can be handled like any
3527 * normal request now.
3529 lustre_msg_clear_flags(req->rq_reqmsg, MSG_RESENT);
3531 DEBUG_REQ(D_DLMTRACE, req, "no existing lock with rhandle %#llx",
3532 dlmreq->lock_handle[0].cookie);
3535 static int mdt_intent_getxattr(enum mdt_it_code opcode,
3536 struct mdt_thread_info *info,
3537 struct ldlm_lock **lockp,
3540 struct mdt_lock_handle *lhc = &info->mti_lh[MDT_LH_RMT];
3541 struct ldlm_reply *ldlm_rep = NULL;
3546 * Initialize lhc->mlh_reg_lh either from a previously granted lock
3547 * (for the resend case) or a new lock. Below we will use it to
3548 * replace the original lock.
3550 mdt_intent_fixup_resent(info, *lockp, lhc, flags);
3551 if (!lustre_handle_is_used(&lhc->mlh_reg_lh)) {
3552 mdt_lock_reg_init(lhc, (*lockp)->l_req_mode);
3553 rc = mdt_object_lock(info, info->mti_object, lhc,
3554 MDS_INODELOCK_XATTR);
3559 rc = mdt_getxattr(info);
3561 if (mdt_info_req(info)->rq_repmsg != NULL)
3562 ldlm_rep = req_capsule_server_get(info->mti_pill, &RMF_DLM_REP);
3564 if (ldlm_rep == NULL ||
3565 OBD_FAIL_CHECK(OBD_FAIL_MDS_XATTR_REP)) {
3566 mdt_object_unlock(info, info->mti_object, lhc, 1);
3567 RETURN(err_serious(-EFAULT));
3570 ldlm_rep->lock_policy_res2 = clear_serious(rc);
3572 /* This is left for interop instead of adding a new interop flag.
3574 #if LUSTRE_VERSION_CODE > OBD_OCD_VERSION(3, 0, 0, 0)
3575 if (ldlm_rep->lock_policy_res2) {
3576 mdt_object_unlock(info, info->mti_object, lhc, 1);
3577 RETURN(ELDLM_LOCK_ABORTED);
3581 rc = mdt_intent_lock_replace(info, lockp, lhc, flags, rc);
3585 static int mdt_intent_getattr(enum mdt_it_code opcode,
3586 struct mdt_thread_info *info,
3587 struct ldlm_lock **lockp,
3590 struct mdt_lock_handle *lhc = &info->mti_lh[MDT_LH_RMT];
3592 struct ldlm_reply *ldlm_rep;
3593 struct mdt_body *reqbody;
3594 struct mdt_body *repbody;
3598 reqbody = req_capsule_client_get(info->mti_pill, &RMF_MDT_BODY);
3601 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
3604 info->mti_cross_ref = !!(reqbody->mbo_valid & OBD_MD_FLCROSSREF);
3605 repbody->mbo_eadatasize = 0;
3606 repbody->mbo_aclsize = 0;
3610 child_bits = MDS_INODELOCK_LOOKUP | MDS_INODELOCK_PERM;
3612 case MDT_IT_GETATTR:
3613 child_bits = MDS_INODELOCK_LOOKUP | MDS_INODELOCK_UPDATE |
3617 CERROR("Unsupported intent (%d)\n", opcode);
3618 GOTO(out_shrink, rc = -EINVAL);
3621 rc = mdt_init_ucred_intent_getattr(info, reqbody);
3623 GOTO(out_shrink, rc);
3625 ldlm_rep = req_capsule_server_get(info->mti_pill, &RMF_DLM_REP);
3626 mdt_set_disposition(info, ldlm_rep, DISP_IT_EXECD);
3628 /* Get lock from request for possible resent case. */
3629 mdt_intent_fixup_resent(info, *lockp, lhc, flags);
3631 rc = mdt_getattr_name_lock(info, lhc, child_bits, ldlm_rep);
3632 ldlm_rep->lock_policy_res2 = clear_serious(rc);
3634 if (mdt_get_disposition(ldlm_rep, DISP_LOOKUP_NEG))
3635 ldlm_rep->lock_policy_res2 = 0;
3636 if (!mdt_get_disposition(ldlm_rep, DISP_LOOKUP_POS) ||
3637 ldlm_rep->lock_policy_res2) {
3638 lhc->mlh_reg_lh.cookie = 0ull;
3639 GOTO(out_ucred, rc = ELDLM_LOCK_ABORTED);
3642 rc = mdt_intent_lock_replace(info, lockp, lhc, flags, rc);
3645 mdt_exit_ucred(info);
3647 mdt_client_compatibility(info);
3648 rc2 = mdt_fix_reply(info);
3654 static int mdt_intent_layout(enum mdt_it_code opcode,
3655 struct mdt_thread_info *info,
3656 struct ldlm_lock **lockp,
3659 struct mdt_lock_handle *lhc = &info->mti_lh[MDT_LH_LAYOUT];
3660 struct layout_intent *layout;
3662 struct mdt_object *obj = NULL;
3663 bool layout_change = false;
3664 int layout_size = 0;
3668 if (opcode != MDT_IT_LAYOUT) {
3669 CERROR("%s: Unknown intent (%d)\n", mdt_obd_name(info->mti_mdt),
3674 layout = req_capsule_client_get(info->mti_pill, &RMF_LAYOUT_INTENT);
3678 switch (layout->li_opc) {
3679 case LAYOUT_INTENT_TRUNC:
3680 case LAYOUT_INTENT_WRITE:
3681 layout_change = true;
3683 case LAYOUT_INTENT_ACCESS:
3685 case LAYOUT_INTENT_READ:
3686 case LAYOUT_INTENT_GLIMPSE:
3687 case LAYOUT_INTENT_RELEASE:
3688 case LAYOUT_INTENT_RESTORE:
3689 CERROR("%s: Unsupported layout intent opc %d\n",
3690 mdt_obd_name(info->mti_mdt), layout->li_opc);
3694 CERROR("%s: Unknown layout intent opc %d\n",
3695 mdt_obd_name(info->mti_mdt), layout->li_opc);
3702 fid = &info->mti_tmp_fid2;
3703 fid_extract_from_res_name(fid, &(*lockp)->l_resource->lr_name);
3705 /* Get lock from request for possible resent case. */
3706 mdt_intent_fixup_resent(info, *lockp, lhc, flags);
3708 obj = mdt_object_find(info->mti_env, info->mti_mdt, fid);
3710 GOTO(out, rc = PTR_ERR(obj));
3712 if (mdt_object_exists(obj) && !mdt_object_remote(obj)) {
3713 layout_size = mdt_attr_get_eabuf_size(info, obj);
3714 if (layout_size < 0)
3715 GOTO(out_obj, rc = layout_size);
3717 if (layout_size > info->mti_mdt->mdt_max_mdsize)
3718 info->mti_mdt->mdt_max_mdsize = layout_size;
3722 * set reply buffer size, so that ldlm_handle_enqueue0()->
3723 * ldlm_lvbo_fill() will fill the reply buffer with lovea.
3725 (*lockp)->l_lvb_type = LVB_T_LAYOUT;
3726 req_capsule_set_size(info->mti_pill, &RMF_DLM_LVB, RCL_SERVER,
3728 rc = req_capsule_server_pack(info->mti_pill);
3733 if (layout_change) {
3734 struct lu_buf *buf = &info->mti_buf;
3737 * mdt_layout_change is a reint operation, when the request
3738 * is resent, layout write shouldn't reprocess it again.
3740 rc = mdt_check_resent(info, mdt_reconstruct_generic, lhc);
3742 GOTO(out_obj, rc = rc < 0 ? rc : 0);
3745 * There is another resent case: the client's job has been
3746 * done by another client, referring lod_declare_layout_change
3747 * -EALREADY case, and it became a operation w/o transaction,
3748 * so we should not do the layout change, otherwise
3749 * mdt_layout_change() will try to cancel the granted server
3750 * CR lock whose remote counterpart is still in hold on the
3751 * client, and a deadlock ensues.
3753 rc = mdt_check_resent_lock(info, obj, lhc);
3759 if (unlikely(req_is_replay(mdt_info_req(info)))) {
3760 buf->lb_buf = req_capsule_client_get(info->mti_pill,
3762 buf->lb_len = req_capsule_get_size(info->mti_pill,
3763 &RMF_EADATA, RCL_CLIENT);
3765 * If it's a replay of layout write intent RPC, the
3766 * client has saved the extended lovea when
3767 * it get reply then.
3769 if (buf->lb_len > 0)
3770 mdt_fix_lov_magic(info, buf->lb_buf);
3774 * Instantiate some layout components, if @buf contains
3775 * lovea, then it's a replay of the layout intent write
3778 rc = mdt_layout_change(info, obj, layout, buf);
3783 mdt_object_put(info->mti_env, obj);
3785 if (rc == 0 && lustre_handle_is_used(&lhc->mlh_reg_lh))
3786 rc = mdt_intent_lock_replace(info, lockp, lhc, flags, rc);
3789 lhc->mlh_reg_lh.cookie = 0;
3794 static int mdt_intent_reint(enum mdt_it_code opcode,
3795 struct mdt_thread_info *info,
3796 struct ldlm_lock **lockp,
3799 struct mdt_lock_handle *lhc = &info->mti_lh[MDT_LH_RMT];
3800 struct ldlm_reply *rep = NULL;
3804 static const struct req_format *intent_fmts[REINT_MAX] = {
3805 [REINT_CREATE] = &RQF_LDLM_INTENT_CREATE,
3806 [REINT_OPEN] = &RQF_LDLM_INTENT_OPEN
3811 opc = mdt_reint_opcode(mdt_info_req(info), intent_fmts);
3815 if (mdt_it_flavor[opcode].it_reint != opc) {
3816 CERROR("Reint code %ld doesn't match intent: %d\n",
3818 RETURN(err_serious(-EPROTO));
3821 /* Get lock from request for possible resent case. */
3822 mdt_intent_fixup_resent(info, *lockp, lhc, flags);
3824 rc = mdt_reint_internal(info, lhc, opc);
3826 /* Check whether the reply has been packed successfully. */
3827 if (mdt_info_req(info)->rq_repmsg != NULL)
3828 rep = req_capsule_server_get(info->mti_pill, &RMF_DLM_REP);
3830 RETURN(err_serious(-EFAULT));
3832 /* MDC expects this in any case */
3834 mdt_set_disposition(info, rep, DISP_LOOKUP_EXECD);
3836 /* the open lock or the lock for cross-ref object should be
3837 * returned to the client */
3838 if (lustre_handle_is_used(&lhc->mlh_reg_lh) &&
3839 (rc == 0 || rc == -MDT_EREMOTE_OPEN)) {
3840 rep->lock_policy_res2 = 0;
3841 rc = mdt_intent_lock_replace(info, lockp, lhc, flags, rc);
3845 rep->lock_policy_res2 = clear_serious(rc);
3847 if (rep->lock_policy_res2 == -ENOENT &&
3848 mdt_get_disposition(rep, DISP_LOOKUP_NEG) &&
3849 !mdt_get_disposition(rep, DISP_OPEN_CREATE))
3850 rep->lock_policy_res2 = 0;
3852 lhc->mlh_reg_lh.cookie = 0ull;
3853 if (rc == -ENOTCONN || rc == -ENODEV ||
3854 rc == -EOVERFLOW) { /**< if VBR failure then return error */
3856 * If it is the disconnect error (ENODEV & ENOCONN), the error
3857 * will be returned by rq_status, and client at ptlrpc layer
3858 * will detect this, then disconnect, reconnect the import
3859 * immediately, instead of impacting the following the rpc.
3864 * For other cases, the error will be returned by intent, and client
3865 * will retrieve the result from intent.
3867 RETURN(ELDLM_LOCK_ABORTED);
3870 static int mdt_intent_code(enum ldlm_intent_flags itcode)
3878 case IT_OPEN|IT_CREAT:
3885 rc = MDT_IT_READDIR;
3888 rc = MDT_IT_GETATTR;
3900 rc = MDT_IT_GETXATTR;
3905 case IT_QUOTA_DQACQ:
3910 rc = MDT_IT_GLIMPSE;
3916 CERROR("Unknown intent opcode: 0x%08x\n", itcode);
3923 static int mdt_intent_opc(enum ldlm_intent_flags itopc,
3924 struct mdt_thread_info *info,
3925 struct ldlm_lock **lockp, __u64 flags)
3927 struct req_capsule *pill = info->mti_pill;
3928 struct ptlrpc_request *req = mdt_info_req(info);
3929 struct mdt_it_flavor *flv;
3934 opc = mdt_intent_code(itopc);
3938 if (opc == MDT_IT_QUOTA) {
3939 struct lu_device *qmt = info->mti_mdt->mdt_qmt_dev;
3942 RETURN(-EOPNOTSUPP);
3944 if (mdt_rdonly(req->rq_export))
3947 (*lockp)->l_lvb_type = LVB_T_LQUOTA;
3948 /* pass the request to quota master */
3949 rc = qmt_hdls.qmth_intent_policy(info->mti_env, qmt,
3950 mdt_info_req(info), lockp,
3955 flv = &mdt_it_flavor[opc];
3956 if (flv->it_fmt != NULL)
3957 req_capsule_extend(pill, flv->it_fmt);
3959 rc = mdt_unpack_req_pack_rep(info, flv->it_flags);
3963 if (flv->it_flags & MUTABOR && mdt_rdonly(req->rq_export))
3966 if (flv->it_act != NULL) {
3967 struct ldlm_reply *rep;
3969 OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_INTENT_DELAY, 10);
3971 /* execute policy */
3972 rc = flv->it_act(opc, info, lockp, flags);
3974 /* Check whether the reply has been packed successfully. */
3975 if (req->rq_repmsg != NULL) {
3976 rep = req_capsule_server_get(info->mti_pill,
3978 rep->lock_policy_res2 =
3979 ptlrpc_status_hton(rep->lock_policy_res2);
3986 static void mdt_ptlrpc_stats_update(struct ptlrpc_request *req,
3987 enum ldlm_intent_flags it_opc)
3989 struct lprocfs_stats *srv_stats = ptlrpc_req2svc(req)->srv_stats;
3991 /* update stats when IT code is known */
3992 if (srv_stats != NULL)
3993 lprocfs_counter_incr(srv_stats,
3994 PTLRPC_LAST_CNTR + (it_opc == IT_GLIMPSE ?
3995 LDLM_GLIMPSE_ENQUEUE : LDLM_IBITS_ENQUEUE));
3998 static int mdt_intent_policy(struct ldlm_namespace *ns,
3999 struct ldlm_lock **lockp, void *req_cookie,
4000 enum ldlm_mode mode, __u64 flags, void *data)
4002 struct tgt_session_info *tsi;
4003 struct mdt_thread_info *info;
4004 struct ptlrpc_request *req = req_cookie;
4005 struct ldlm_intent *it;
4006 struct req_capsule *pill;
4007 const struct ldlm_lock_desc *ldesc;
4012 LASSERT(req != NULL);
4014 tsi = tgt_ses_info(req->rq_svc_thread->t_env);
4016 info = tsi2mdt_info(tsi);
4017 LASSERT(info != NULL);
4018 pill = info->mti_pill;
4019 LASSERT(pill->rc_req == req);
4020 ldesc = &info->mti_dlm_req->lock_desc;
4022 if (req->rq_reqmsg->lm_bufcount > DLM_INTENT_IT_OFF) {
4023 req_capsule_extend(pill, &RQF_LDLM_INTENT_BASIC);
4024 it = req_capsule_client_get(pill, &RMF_LDLM_INTENT);
4026 mdt_ptlrpc_stats_update(req, it->opc);
4027 rc = mdt_intent_opc(it->opc, info, lockp, flags);
4031 /* Lock without inodebits makes no sense and will oops
4032 * later in ldlm. Let's check it now to see if we have
4033 * ibits corrupted somewhere in mdt_intent_opc().
4034 * The case for client miss to set ibits has been
4035 * processed by others. */
4036 LASSERT(ergo(ldesc->l_resource.lr_type == LDLM_IBITS,
4037 ldesc->l_policy_data.l_inodebits.bits != 0));
4039 rc = err_serious(-EFAULT);
4042 /* No intent was provided */
4043 req_capsule_set_size(pill, &RMF_DLM_LVB, RCL_SERVER, 0);
4044 rc = req_capsule_server_pack(pill);
4046 rc = err_serious(rc);
4048 mdt_thread_info_fini(info);
4052 static void mdt_deregister_seq_exp(struct mdt_device *mdt)
4054 struct seq_server_site *ss = mdt_seq_site(mdt);
4056 if (ss->ss_node_id == 0)
4059 if (ss->ss_client_seq != NULL) {
4060 lustre_deregister_lwp_item(&ss->ss_client_seq->lcs_exp);
4061 ss->ss_client_seq->lcs_exp = NULL;
4064 if (ss->ss_server_fld != NULL) {
4065 lustre_deregister_lwp_item(&ss->ss_server_fld->lsf_control_exp);
4066 ss->ss_server_fld->lsf_control_exp = NULL;
4070 static void mdt_seq_fini_cli(struct mdt_device *mdt)
4072 struct seq_server_site *ss = mdt_seq_site(mdt);
4077 if (ss->ss_server_seq != NULL)
4078 seq_server_set_cli(NULL, ss->ss_server_seq, NULL);
4081 static int mdt_seq_fini(const struct lu_env *env, struct mdt_device *mdt)
4083 mdt_seq_fini_cli(mdt);
4084 mdt_deregister_seq_exp(mdt);
4086 return seq_site_fini(env, mdt_seq_site(mdt));
4090 * It will retrieve its FLDB entries from MDT0, and it only happens
4091 * when upgrading existent FS to 2.6 or when local FLDB is corrupted,
4092 * and it needs to refresh FLDB from the MDT0.
4094 static int mdt_register_lwp_callback(void *data)
4097 struct mdt_device *mdt = data;
4098 struct lu_server_fld *fld = mdt_seq_site(mdt)->ss_server_fld;
4102 LASSERT(mdt_seq_site(mdt)->ss_node_id != 0);
4104 rc = lu_env_init(&env, LCT_MD_THREAD);
4106 CERROR("%s: cannot init env: rc = %d\n", mdt_obd_name(mdt), rc);
4110 /* Allocate new sequence now to avoid creating local transaction
4111 * in the normal transaction process */
4112 rc = seq_server_check_and_alloc_super(&env,
4113 mdt_seq_site(mdt)->ss_server_seq);
4118 rc = fld_update_from_controller(&env, fld);
4120 CERROR("%s: cannot update controller: rc = %d\n",
4121 mdt_obd_name(mdt), rc);
4130 static int mdt_register_seq_exp(struct mdt_device *mdt)
4132 struct seq_server_site *ss = mdt_seq_site(mdt);
4133 char *lwp_name = NULL;
4136 if (ss->ss_node_id == 0)
4139 OBD_ALLOC(lwp_name, MAX_OBD_NAME);
4140 if (lwp_name == NULL)
4141 GOTO(out_free, rc = -ENOMEM);
4143 rc = tgt_name2lwp_name(mdt_obd_name(mdt), lwp_name, MAX_OBD_NAME, 0);
4147 rc = lustre_register_lwp_item(lwp_name, &ss->ss_client_seq->lcs_exp,
4152 rc = lustre_register_lwp_item(lwp_name,
4153 &ss->ss_server_fld->lsf_control_exp,
4154 mdt_register_lwp_callback, mdt);
4156 lustre_deregister_lwp_item(&ss->ss_client_seq->lcs_exp);
4157 ss->ss_client_seq->lcs_exp = NULL;
4161 if (lwp_name != NULL)
4162 OBD_FREE(lwp_name, MAX_OBD_NAME);
4168 * Init client sequence manager which is used by local MDS to talk to sequence
4169 * controller on remote node.
4171 static int mdt_seq_init_cli(const struct lu_env *env, struct mdt_device *mdt)
4173 struct seq_server_site *ss = mdt_seq_site(mdt);
4178 /* check if this is adding the first MDC and controller is not yet
4180 OBD_ALLOC_PTR(ss->ss_client_seq);
4181 if (ss->ss_client_seq == NULL)
4184 OBD_ALLOC(prefix, MAX_OBD_NAME + 5);
4185 if (prefix == NULL) {
4186 OBD_FREE_PTR(ss->ss_client_seq);
4187 ss->ss_client_seq = NULL;
4191 /* Note: seq_client_fini will be called in seq_site_fini */
4192 snprintf(prefix, MAX_OBD_NAME + 5, "ctl-%s", mdt_obd_name(mdt));
4193 rc = seq_client_init(ss->ss_client_seq, NULL, LUSTRE_SEQ_METADATA,
4194 prefix, ss->ss_node_id == 0 ? ss->ss_control_seq :
4196 OBD_FREE(prefix, MAX_OBD_NAME + 5);
4198 OBD_FREE_PTR(ss->ss_client_seq);
4199 ss->ss_client_seq = NULL;
4203 rc = seq_server_set_cli(env, ss->ss_server_seq, ss->ss_client_seq);
4208 static int mdt_seq_init(const struct lu_env *env, struct mdt_device *mdt)
4210 struct seq_server_site *ss;
4214 ss = mdt_seq_site(mdt);
4215 /* init sequence controller server(MDT0) */
4216 if (ss->ss_node_id == 0) {
4217 OBD_ALLOC_PTR(ss->ss_control_seq);
4218 if (ss->ss_control_seq == NULL)
4221 rc = seq_server_init(env, ss->ss_control_seq, mdt->mdt_bottom,
4222 mdt_obd_name(mdt), LUSTRE_SEQ_CONTROLLER,
4225 GOTO(out_seq_fini, rc);
4228 /* Init normal sequence server */
4229 OBD_ALLOC_PTR(ss->ss_server_seq);
4230 if (ss->ss_server_seq == NULL)
4231 GOTO(out_seq_fini, rc = -ENOMEM);
4233 rc = seq_server_init(env, ss->ss_server_seq, mdt->mdt_bottom,
4234 mdt_obd_name(mdt), LUSTRE_SEQ_SERVER, ss);
4236 GOTO(out_seq_fini, rc);
4238 /* init seq client for seq server to talk to seq controller(MDT0) */
4239 rc = mdt_seq_init_cli(env, mdt);
4241 GOTO(out_seq_fini, rc);
4243 if (ss->ss_node_id != 0)
4244 /* register controller export through lwp */
4245 rc = mdt_register_seq_exp(mdt);
4250 mdt_seq_fini(env, mdt);
4258 static int mdt_fld_fini(const struct lu_env *env,
4259 struct mdt_device *m)
4261 struct seq_server_site *ss = mdt_seq_site(m);
4264 if (ss && ss->ss_server_fld) {
4265 fld_server_fini(env, ss->ss_server_fld);
4266 OBD_FREE_PTR(ss->ss_server_fld);
4267 ss->ss_server_fld = NULL;
4273 static int mdt_fld_init(const struct lu_env *env,
4275 struct mdt_device *m)
4277 struct seq_server_site *ss;
4281 ss = mdt_seq_site(m);
4283 OBD_ALLOC_PTR(ss->ss_server_fld);
4284 if (ss->ss_server_fld == NULL)
4285 RETURN(rc = -ENOMEM);
4287 rc = fld_server_init(env, ss->ss_server_fld, m->mdt_bottom, uuid,
4290 OBD_FREE_PTR(ss->ss_server_fld);
4291 ss->ss_server_fld = NULL;
4298 static void mdt_stack_pre_fini(const struct lu_env *env,
4299 struct mdt_device *m, struct lu_device *top)
4301 struct lustre_cfg_bufs *bufs;
4302 struct lustre_cfg *lcfg;
4303 struct mdt_thread_info *info;
4308 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
4309 LASSERT(info != NULL);
4311 bufs = &info->mti_u.bufs;
4313 LASSERT(m->mdt_child_exp);
4314 LASSERT(m->mdt_child_exp->exp_obd);
4316 /* process cleanup, pass mdt obd name to get obd umount flags */
4317 /* XXX: this is needed because all layers are referenced by
4318 * objects (some of them are pinned by osd, for example *
4319 * the proper solution should be a model where object used
4320 * by osd only doesn't have mdt/mdd slices -bzzz */
4321 lustre_cfg_bufs_reset(bufs, mdt_obd_name(m));
4322 lustre_cfg_bufs_set_string(bufs, 1, NULL);
4323 OBD_ALLOC(lcfg, lustre_cfg_len(bufs->lcfg_bufcount, bufs->lcfg_buflen));
4326 lustre_cfg_init(lcfg, LCFG_PRE_CLEANUP, bufs);
4328 top->ld_ops->ldo_process_config(env, top, lcfg);
4329 OBD_FREE(lcfg, lustre_cfg_len(lcfg->lcfg_bufcount, lcfg->lcfg_buflens));
4333 static void mdt_stack_fini(const struct lu_env *env,
4334 struct mdt_device *m, struct lu_device *top)
4336 struct obd_device *obd = mdt2obd_dev(m);
4337 struct lustre_cfg_bufs *bufs;
4338 struct lustre_cfg *lcfg;
4339 struct mdt_thread_info *info;
4343 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
4344 LASSERT(info != NULL);
4346 lu_dev_del_linkage(top->ld_site, top);
4348 lu_site_purge(env, top->ld_site, -1);
4350 bufs = &info->mti_u.bufs;
4351 /* process cleanup, pass mdt obd name to get obd umount flags */
4352 /* another purpose is to let all layers to release their objects */
4353 lustre_cfg_bufs_reset(bufs, mdt_obd_name(m));
4358 lustre_cfg_bufs_set_string(bufs, 1, flags);
4359 OBD_ALLOC(lcfg, lustre_cfg_len(bufs->lcfg_bufcount, bufs->lcfg_buflen));
4362 lustre_cfg_init(lcfg, LCFG_CLEANUP, bufs);
4365 top->ld_ops->ldo_process_config(env, top, lcfg);
4366 OBD_FREE(lcfg, lustre_cfg_len(lcfg->lcfg_bufcount, lcfg->lcfg_buflens));
4368 lu_site_purge(env, top->ld_site, -1);
4370 m->mdt_child = NULL;
4371 m->mdt_bottom = NULL;
4373 obd_disconnect(m->mdt_child_exp);
4374 m->mdt_child_exp = NULL;
4376 obd_disconnect(m->mdt_bottom_exp);
4377 m->mdt_child_exp = NULL;
4380 static int mdt_connect_to_next(const struct lu_env *env, struct mdt_device *m,
4381 const char *next, struct obd_export **exp)
4383 struct obd_connect_data *data = NULL;
4384 struct obd_device *obd;
4388 OBD_ALLOC_PTR(data);
4390 GOTO(out, rc = -ENOMEM);
4392 obd = class_name2obd(next);
4394 CERROR("%s: can't locate next device: %s\n",
4395 mdt_obd_name(m), next);
4396 GOTO(out, rc = -ENOTCONN);
4399 data->ocd_connect_flags = OBD_CONNECT_VERSION;
4400 data->ocd_version = LUSTRE_VERSION_CODE;
4402 rc = obd_connect(NULL, exp, obd, &obd->obd_uuid, data, NULL);
4404 CERROR("%s: cannot connect to next dev %s (%d)\n",
4405 mdt_obd_name(m), next, rc);
4415 static int mdt_stack_init(const struct lu_env *env, struct mdt_device *mdt,
4416 struct lustre_cfg *cfg)
4418 char *dev = lustre_cfg_string(cfg, 0);
4419 int rc, name_size, uuid_size;
4420 char *name, *uuid, *p;
4421 struct lustre_cfg_bufs *bufs;
4422 struct lustre_cfg *lcfg;
4423 struct obd_device *obd;
4424 struct lustre_profile *lprof;
4425 struct lu_site *site;
4428 /* in 1.8 we had the only device in the stack - MDS.
4429 * 2.0 introduces MDT, MDD, OSD; MDT starts others internally.
4430 * in 2.3 OSD is instantiated by obd_mount.c, so we need
4431 * to generate names and setup MDT, MDD. MDT will be using
4432 * generated name to connect to MDD. for MDD the next device
4433 * will be LOD with name taken from so called "profile" which
4434 * is generated by mount_option line
4436 * 1.8 MGS generates config. commands like this:
4437 * #06 (104)mount_option 0: 1:lustre-MDT0000 2:lustre-mdtlov
4438 * #08 (120)setup 0:lustre-MDT0000 1:dev 2:type 3:lustre-MDT0000
4439 * 2.0 MGS generates config. commands like this:
4440 * #07 (112)mount_option 0: 1:lustre-MDT0000 2:lustre-MDT0000-mdtlov
4441 * #08 (160)setup 0:lustre-MDT0000 1:lustre-MDT0000_UUID 2:0
4442 * 3:lustre-MDT0000-mdtlov 4:f
4444 * we generate MDD name from MDT one, just replacing T with D
4446 * after all the preparations, the logical equivalent will be
4447 * #01 (160)setup 0:lustre-MDD0000 1:lustre-MDD0000_UUID 2:0
4448 * 3:lustre-MDT0000-mdtlov 4:f
4449 * #02 (160)setup 0:lustre-MDT0000 1:lustre-MDT0000_UUID 2:0
4450 * 3:lustre-MDD0000 4:f
4452 * notice we build the stack from down to top: MDD first, then MDT */
4454 name_size = MAX_OBD_NAME;
4455 uuid_size = MAX_OBD_NAME;
4457 OBD_ALLOC(name, name_size);
4458 OBD_ALLOC(uuid, uuid_size);
4459 if (name == NULL || uuid == NULL)
4460 GOTO(cleanup_mem, rc = -ENOMEM);
4462 OBD_ALLOC_PTR(bufs);
4464 GOTO(cleanup_mem, rc = -ENOMEM);
4467 p = strstr(name, "-MDT");
4469 GOTO(free_bufs, rc = -ENOMEM);
4472 snprintf(uuid, MAX_OBD_NAME, "%s_UUID", name);
4474 lprof = class_get_profile(lustre_cfg_string(cfg, 0));
4475 if (lprof == NULL || lprof->lp_dt == NULL) {
4476 CERROR("can't find the profile: %s\n",
4477 lustre_cfg_string(cfg, 0));
4478 GOTO(free_bufs, rc = -EINVAL);
4481 lustre_cfg_bufs_reset(bufs, name);
4482 lustre_cfg_bufs_set_string(bufs, 1, LUSTRE_MDD_NAME);
4483 lustre_cfg_bufs_set_string(bufs, 2, uuid);
4484 lustre_cfg_bufs_set_string(bufs, 3, lprof->lp_dt);
4486 OBD_ALLOC(lcfg, lustre_cfg_len(bufs->lcfg_bufcount, bufs->lcfg_buflen));
4488 GOTO(put_profile, rc = -ENOMEM);
4489 lustre_cfg_init(lcfg, LCFG_ATTACH, bufs);
4491 rc = class_attach(lcfg);
4493 GOTO(lcfg_cleanup, rc);
4495 obd = class_name2obd(name);
4497 CERROR("Can not find obd %s (%s in config)\n",
4498 MDD_OBD_NAME, lustre_cfg_string(cfg, 0));
4499 GOTO(lcfg_cleanup, rc = -EINVAL);
4502 OBD_FREE(lcfg, lustre_cfg_len(lcfg->lcfg_bufcount, lcfg->lcfg_buflens));
4504 lustre_cfg_bufs_reset(bufs, name);
4505 lustre_cfg_bufs_set_string(bufs, 1, uuid);
4506 lustre_cfg_bufs_set_string(bufs, 2, dev);
4507 lustre_cfg_bufs_set_string(bufs, 3, lprof->lp_dt);
4509 OBD_ALLOC(lcfg, lustre_cfg_len(bufs->lcfg_bufcount, bufs->lcfg_buflen));
4511 GOTO(class_detach, rc = -ENOMEM);
4512 lustre_cfg_init(lcfg, LCFG_SETUP, bufs);
4514 rc = class_setup(obd, lcfg);
4516 GOTO(class_detach, rc);
4518 /* connect to MDD we just setup */
4519 rc = mdt_connect_to_next(env, mdt, name, &mdt->mdt_child_exp);
4521 GOTO(class_detach, rc);
4523 site = mdt->mdt_child_exp->exp_obd->obd_lu_dev->ld_site;
4525 LASSERT(mdt_lu_site(mdt) == NULL);
4526 mdt->mdt_lu_dev.ld_site = site;
4527 site->ls_top_dev = &mdt->mdt_lu_dev;
4528 mdt->mdt_child = lu2md_dev(mdt->mdt_child_exp->exp_obd->obd_lu_dev);
4530 /* now connect to bottom OSD */
4531 snprintf(name, MAX_OBD_NAME, "%s-osd", dev);
4532 rc = mdt_connect_to_next(env, mdt, name, &mdt->mdt_bottom_exp);
4534 GOTO(class_detach, rc);
4536 lu2dt_dev(mdt->mdt_bottom_exp->exp_obd->obd_lu_dev);
4538 rc = lu_env_refill((struct lu_env *)env);
4540 CERROR("Failure to refill session: '%d'\n", rc);
4542 lu_dev_add_linkage(site, &mdt->mdt_lu_dev);
4547 class_detach(obd, lcfg);
4549 OBD_FREE(lcfg, lustre_cfg_len(lcfg->lcfg_bufcount, lcfg->lcfg_buflens));
4551 class_put_profile(lprof);
4556 OBD_FREE(name, name_size);
4558 OBD_FREE(uuid, uuid_size);
4562 /* setup quota master target on MDT0 */
4563 static int mdt_quota_init(const struct lu_env *env, struct mdt_device *mdt,
4564 struct lustre_cfg *cfg)
4566 struct obd_device *obd;
4567 char *dev = lustre_cfg_string(cfg, 0);
4568 char *qmtname, *uuid, *p;
4569 struct lustre_cfg_bufs *bufs;
4570 struct lustre_cfg *lcfg;
4571 struct lustre_profile *lprof;
4572 struct obd_connect_data *data;
4576 LASSERT(mdt->mdt_qmt_exp == NULL);
4577 LASSERT(mdt->mdt_qmt_dev == NULL);
4579 /* quota master is on MDT0 only for now */
4580 if (mdt->mdt_seq_site.ss_node_id != 0)
4583 /* MGS generates config commands which look as follows:
4584 * #01 (160)setup 0:lustre-MDT0000 1:lustre-MDT0000_UUID 2:0
4585 * 3:lustre-MDT0000-mdtlov 4:f
4587 * We generate the QMT name from the MDT one, just replacing MD with QM
4588 * after all the preparations, the logical equivalent will be:
4589 * #01 (160)setup 0:lustre-QMT0000 1:lustre-QMT0000_UUID 2:0
4590 * 3:lustre-MDT0000-osd 4:f */
4591 OBD_ALLOC(qmtname, MAX_OBD_NAME);
4592 OBD_ALLOC(uuid, UUID_MAX);
4593 OBD_ALLOC_PTR(bufs);
4594 OBD_ALLOC_PTR(data);
4595 if (qmtname == NULL || uuid == NULL || bufs == NULL || data == NULL)
4596 GOTO(cleanup_mem, rc = -ENOMEM);
4598 strcpy(qmtname, dev);
4599 p = strstr(qmtname, "-MDT");
4601 GOTO(cleanup_mem, rc = -ENOMEM);
4602 /* replace MD with QM */
4606 snprintf(uuid, UUID_MAX, "%s_UUID", qmtname);
4608 lprof = class_get_profile(lustre_cfg_string(cfg, 0));
4609 if (lprof == NULL || lprof->lp_dt == NULL) {
4610 CERROR("can't find profile for %s\n",
4611 lustre_cfg_string(cfg, 0));
4612 GOTO(cleanup_mem, rc = -EINVAL);
4615 lustre_cfg_bufs_reset(bufs, qmtname);
4616 lustre_cfg_bufs_set_string(bufs, 1, LUSTRE_QMT_NAME);
4617 lustre_cfg_bufs_set_string(bufs, 2, uuid);
4618 lustre_cfg_bufs_set_string(bufs, 3, lprof->lp_dt);
4620 OBD_ALLOC(lcfg, lustre_cfg_len(bufs->lcfg_bufcount, bufs->lcfg_buflen));
4622 GOTO(put_profile, rc = -ENOMEM);
4623 lustre_cfg_init(lcfg, LCFG_ATTACH, bufs);
4625 rc = class_attach(lcfg);
4627 GOTO(lcfg_cleanup, rc);
4629 obd = class_name2obd(qmtname);
4631 CERROR("Can not find obd %s (%s in config)\n", qmtname,
4632 lustre_cfg_string(cfg, 0));
4633 GOTO(lcfg_cleanup, rc = -EINVAL);
4636 OBD_FREE(lcfg, lustre_cfg_len(lcfg->lcfg_bufcount, lcfg->lcfg_buflens));
4638 lustre_cfg_bufs_reset(bufs, qmtname);
4639 lustre_cfg_bufs_set_string(bufs, 1, uuid);
4640 lustre_cfg_bufs_set_string(bufs, 2, dev);
4642 /* for quota, the next device should be the OSD device */
4643 lustre_cfg_bufs_set_string(bufs, 3,
4644 mdt->mdt_bottom->dd_lu_dev.ld_obd->obd_name);
4646 OBD_ALLOC(lcfg, lustre_cfg_len(bufs->lcfg_bufcount, bufs->lcfg_buflen));
4648 GOTO(class_detach, rc = -ENOMEM);
4649 lustre_cfg_init(lcfg, LCFG_SETUP, bufs);
4651 rc = class_setup(obd, lcfg);
4653 GOTO(class_detach, rc);
4655 mdt->mdt_qmt_dev = obd->obd_lu_dev;
4657 /* configure local quota objects */
4658 rc = mdt->mdt_qmt_dev->ld_ops->ldo_prepare(env,
4662 GOTO(class_cleanup, rc);
4664 /* connect to quota master target */
4665 data->ocd_connect_flags = OBD_CONNECT_VERSION;
4666 data->ocd_version = LUSTRE_VERSION_CODE;
4667 rc = obd_connect(NULL, &mdt->mdt_qmt_exp, obd, &obd->obd_uuid,
4670 CERROR("cannot connect to quota master device %s (%d)\n",
4672 GOTO(class_cleanup, rc);
4678 class_manual_cleanup(obd);
4679 mdt->mdt_qmt_dev = NULL;
4683 class_detach(obd, lcfg);
4685 OBD_FREE(lcfg, lustre_cfg_len(lcfg->lcfg_bufcount, lcfg->lcfg_buflens));
4687 class_put_profile(lprof);
4692 OBD_FREE(qmtname, MAX_OBD_NAME);
4694 OBD_FREE(uuid, UUID_MAX);
4700 /* Shutdown quota master target associated with mdt */
4701 static void mdt_quota_fini(const struct lu_env *env, struct mdt_device *mdt)
4705 if (mdt->mdt_qmt_exp == NULL)
4707 LASSERT(mdt->mdt_qmt_dev != NULL);
4709 /* the qmt automatically shuts down when the mdt disconnects */
4710 obd_disconnect(mdt->mdt_qmt_exp);
4711 mdt->mdt_qmt_exp = NULL;
4712 mdt->mdt_qmt_dev = NULL;
4716 /* mdt_getxattr() is used from mdt_intent_getxattr(), use this wrapper
4717 * for now. This will be removed along with converting rest of MDT code
4718 * to use tgt_session_info */
4719 static int mdt_tgt_getxattr(struct tgt_session_info *tsi)
4721 struct mdt_thread_info *info = tsi2mdt_info(tsi);
4724 rc = mdt_getxattr(info);
4726 mdt_thread_info_fini(info);
4730 #define OBD_FAIL_OST_READ_NET OBD_FAIL_OST_BRW_NET
4731 #define OBD_FAIL_OST_WRITE_NET OBD_FAIL_OST_BRW_NET
4732 #define OST_BRW_READ OST_READ
4733 #define OST_BRW_WRITE OST_WRITE
4735 static struct tgt_handler mdt_tgt_handlers[] = {
4736 TGT_RPC_HANDLER(MDS_FIRST_OPC,
4737 0, MDS_CONNECT, mdt_tgt_connect,
4738 &RQF_CONNECT, LUSTRE_OBD_VERSION),
4739 TGT_RPC_HANDLER(MDS_FIRST_OPC,
4740 0, MDS_DISCONNECT, tgt_disconnect,
4741 &RQF_MDS_DISCONNECT, LUSTRE_OBD_VERSION),
4742 TGT_RPC_HANDLER(MDS_FIRST_OPC,
4743 HABEO_REFERO, MDS_SET_INFO, mdt_set_info,
4744 &RQF_OBD_SET_INFO, LUSTRE_MDS_VERSION),
4745 TGT_MDT_HDL(0, MDS_GET_INFO, mdt_get_info),
4746 TGT_MDT_HDL(0 | HABEO_REFERO, MDS_GET_ROOT, mdt_get_root),
4747 TGT_MDT_HDL(HABEO_CORPUS, MDS_GETATTR, mdt_getattr),
4748 TGT_MDT_HDL(HABEO_CORPUS| HABEO_REFERO, MDS_GETATTR_NAME,
4750 TGT_MDT_HDL(HABEO_CORPUS, MDS_GETXATTR, mdt_tgt_getxattr),
4751 TGT_MDT_HDL(0 | HABEO_REFERO, MDS_STATFS, mdt_statfs),
4752 TGT_MDT_HDL(0 | MUTABOR, MDS_REINT, mdt_reint),
4753 TGT_MDT_HDL(HABEO_CORPUS, MDS_CLOSE, mdt_close),
4754 TGT_MDT_HDL(HABEO_CORPUS| HABEO_REFERO, MDS_READPAGE, mdt_readpage),
4755 TGT_MDT_HDL(HABEO_CORPUS| HABEO_REFERO, MDS_SYNC, mdt_sync),
4756 TGT_MDT_HDL(0, MDS_QUOTACTL, mdt_quotactl),
4757 TGT_MDT_HDL(HABEO_CORPUS| HABEO_REFERO | MUTABOR, MDS_HSM_PROGRESS,
4759 TGT_MDT_HDL(HABEO_CORPUS| HABEO_REFERO | MUTABOR, MDS_HSM_CT_REGISTER,
4760 mdt_hsm_ct_register),
4761 TGT_MDT_HDL(HABEO_CORPUS| HABEO_REFERO | MUTABOR, MDS_HSM_CT_UNREGISTER,
4762 mdt_hsm_ct_unregister),
4763 TGT_MDT_HDL(HABEO_CORPUS| HABEO_REFERO, MDS_HSM_STATE_GET,
4765 TGT_MDT_HDL(HABEO_CORPUS| HABEO_REFERO | MUTABOR, MDS_HSM_STATE_SET,
4767 TGT_MDT_HDL(HABEO_CORPUS| HABEO_REFERO, MDS_HSM_ACTION, mdt_hsm_action),
4768 TGT_MDT_HDL(HABEO_CORPUS| HABEO_REFERO, MDS_HSM_REQUEST,
4770 TGT_MDT_HDL(HABEO_CLAVIS | HABEO_CORPUS | HABEO_REFERO | MUTABOR,
4775 static struct tgt_handler mdt_io_ops[] = {
4776 TGT_OST_HDL(HABEO_CORPUS | HABEO_REFERO, OST_BRW_READ, tgt_brw_read),
4777 TGT_OST_HDL(HABEO_CORPUS | MUTABOR, OST_BRW_WRITE, tgt_brw_write),
4778 TGT_OST_HDL(HABEO_CORPUS | HABEO_REFERO | MUTABOR,
4779 OST_PUNCH, mdt_punch_hdl),
4780 TGT_OST_HDL(HABEO_CORPUS | HABEO_REFERO, OST_SYNC, mdt_data_sync),
4783 static struct tgt_handler mdt_sec_ctx_ops[] = {
4784 TGT_SEC_HDL_VAR(0, SEC_CTX_INIT, mdt_sec_ctx_handle),
4785 TGT_SEC_HDL_VAR(0, SEC_CTX_INIT_CONT,mdt_sec_ctx_handle),
4786 TGT_SEC_HDL_VAR(0, SEC_CTX_FINI, mdt_sec_ctx_handle)
4789 static struct tgt_handler mdt_quota_ops[] = {
4790 TGT_QUOTA_HDL(HABEO_REFERO, QUOTA_DQACQ, mdt_quota_dqacq),
4793 static struct tgt_opc_slice mdt_common_slice[] = {
4795 .tos_opc_start = MDS_FIRST_OPC,
4796 .tos_opc_end = MDS_LAST_OPC,
4797 .tos_hs = mdt_tgt_handlers
4800 .tos_opc_start = OBD_FIRST_OPC,
4801 .tos_opc_end = OBD_LAST_OPC,
4802 .tos_hs = tgt_obd_handlers
4805 .tos_opc_start = LDLM_FIRST_OPC,
4806 .tos_opc_end = LDLM_LAST_OPC,
4807 .tos_hs = tgt_dlm_handlers
4810 .tos_opc_start = SEC_FIRST_OPC,
4811 .tos_opc_end = SEC_LAST_OPC,
4812 .tos_hs = mdt_sec_ctx_ops
4815 .tos_opc_start = OUT_UPDATE_FIRST_OPC,
4816 .tos_opc_end = OUT_UPDATE_LAST_OPC,
4817 .tos_hs = tgt_out_handlers
4820 .tos_opc_start = FLD_FIRST_OPC,
4821 .tos_opc_end = FLD_LAST_OPC,
4822 .tos_hs = fld_handlers
4825 .tos_opc_start = SEQ_FIRST_OPC,
4826 .tos_opc_end = SEQ_LAST_OPC,
4827 .tos_hs = seq_handlers
4830 .tos_opc_start = QUOTA_DQACQ,
4831 .tos_opc_end = QUOTA_LAST_OPC,
4832 .tos_hs = mdt_quota_ops
4835 .tos_opc_start = LLOG_FIRST_OPC,
4836 .tos_opc_end = LLOG_LAST_OPC,
4837 .tos_hs = tgt_llog_handlers
4840 .tos_opc_start = LFSCK_FIRST_OPC,
4841 .tos_opc_end = LFSCK_LAST_OPC,
4842 .tos_hs = tgt_lfsck_handlers
4845 .tos_opc_start = OST_FIRST_OPC,
4846 .tos_opc_end = OST_LAST_OPC,
4847 .tos_hs = mdt_io_ops
4854 static void mdt_fini(const struct lu_env *env, struct mdt_device *m)
4856 struct md_device *next = m->mdt_child;
4857 struct lu_device *d = &m->mdt_lu_dev;
4858 struct obd_device *obd = mdt2obd_dev(m);
4859 struct lfsck_stop stop;
4862 stop.ls_status = LS_PAUSED;
4864 next->md_ops->mdo_iocontrol(env, next, OBD_IOC_STOP_LFSCK, 0, &stop);
4866 mdt_stack_pre_fini(env, m, md2lu_dev(m->mdt_child));
4867 ping_evictor_stop();
4869 /* Remove the HSM /proc entry so the coordinator cannot be
4870 * restarted by a user while it's shutting down. */
4871 hsm_cdt_procfs_fini(m);
4872 mdt_hsm_cdt_stop(m);
4874 mdt_llog_ctxt_unclone(env, m, LLOG_AGENT_ORIG_CTXT);
4875 mdt_llog_ctxt_unclone(env, m, LLOG_CHANGELOG_ORIG_CTXT);
4877 if (m->mdt_namespace != NULL)
4878 ldlm_namespace_free_prior(m->mdt_namespace, NULL,
4879 d->ld_obd->obd_force);
4881 obd_exports_barrier(obd);
4882 obd_zombie_barrier();
4884 mdt_quota_fini(env, m);
4886 cfs_free_nidlist(&m->mdt_squash.rsi_nosquash_nids);
4888 /* Calling the cleanup functions in the same order as in the mdt_init0
4893 target_recovery_fini(obd);
4894 upcall_cache_cleanup(m->mdt_identity_cache);
4895 m->mdt_identity_cache = NULL;
4897 mdt_fs_cleanup(env, m);
4899 tgt_fini(env, &m->mdt_lut);
4901 mdt_hsm_cdt_fini(m);
4903 if (m->mdt_namespace != NULL) {
4904 ldlm_namespace_free_post(m->mdt_namespace);
4905 d->ld_obd->obd_namespace = m->mdt_namespace = NULL;
4908 if (m->mdt_md_root != NULL) {
4909 mdt_object_put(env, m->mdt_md_root);
4910 m->mdt_md_root = NULL;
4913 mdt_seq_fini(env, m);
4915 mdt_fld_fini(env, m);
4920 mdt_stack_fini(env, m, md2lu_dev(m->mdt_child));
4922 LASSERT(atomic_read(&d->ld_ref) == 0);
4924 server_put_mount(mdt_obd_name(m), true);
4929 static int mdt_postrecov(const struct lu_env *, struct mdt_device *);
4931 static int mdt_init0(const struct lu_env *env, struct mdt_device *m,
4932 struct lu_device_type *ldt, struct lustre_cfg *cfg)
4934 struct mdt_thread_info *info;
4935 struct obd_device *obd;
4936 const char *dev = lustre_cfg_string(cfg, 0);
4937 const char *num = lustre_cfg_string(cfg, 2);
4938 struct lustre_mount_info *lmi = NULL;
4939 struct lustre_sb_info *lsi;
4941 struct seq_server_site *ss_site;
4942 const char *identity_upcall = "NONE";
4943 struct md_device *next;
4949 lu_device_init(&m->mdt_lu_dev, ldt);
4951 * Environment (env) might be missing mdt_thread_key values at that
4952 * point, if device is allocated when mdt_thread_key is in QUIESCENT
4955 * Usually device allocation path doesn't use module key values, but
4956 * mdt has to do a lot of work here, so allocate key value.
4958 rc = lu_env_refill((struct lu_env *)env);
4962 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
4963 LASSERT(info != NULL);
4965 obd = class_name2obd(dev);
4966 LASSERT(obd != NULL);
4968 m->mdt_max_mdsize = MAX_MD_SIZE; /* 4 stripes */
4969 m->mdt_opts.mo_evict_tgt_nids = 1;
4970 m->mdt_opts.mo_cos = MDT_COS_DEFAULT;
4972 lmi = server_get_mount(dev);
4974 CERROR("Cannot get mount info for %s!\n", dev);
4977 lsi = s2lsi(lmi->lmi_sb);
4978 /* CMD is supported only in IAM mode */
4980 node_id = simple_strtol(num, NULL, 10);
4981 obd->u.obt.obt_magic = OBT_MAGIC;
4982 if (lsi->lsi_lmd != NULL &&
4983 lsi->lsi_lmd->lmd_flags & LMD_FLG_SKIP_LFSCK)
4984 m->mdt_skip_lfsck = 1;
4987 m->mdt_squash.rsi_uid = 0;
4988 m->mdt_squash.rsi_gid = 0;
4989 INIT_LIST_HEAD(&m->mdt_squash.rsi_nosquash_nids);
4990 init_rwsem(&m->mdt_squash.rsi_sem);
4991 spin_lock_init(&m->mdt_lock);
4992 m->mdt_osfs_age = cfs_time_shift_64(-1000);
4993 m->mdt_enable_remote_dir = 0;
4994 m->mdt_enable_remote_dir_gid = 0;
4996 atomic_set(&m->mdt_mds_mds_conns, 0);
4997 atomic_set(&m->mdt_async_commit_count, 0);
4999 m->mdt_lu_dev.ld_ops = &mdt_lu_ops;
5000 m->mdt_lu_dev.ld_obd = obd;
5001 /* Set this lu_device to obd for error handling purposes. */
5002 obd->obd_lu_dev = &m->mdt_lu_dev;
5004 /* init the stack */
5005 rc = mdt_stack_init((struct lu_env *)env, m, cfg);
5007 CERROR("%s: Can't init device stack, rc %d\n",
5008 mdt_obd_name(m), rc);
5013 ss_site = mdt_seq_site(m);
5014 s->ld_seq_site = ss_site;
5017 /* set server index */
5018 ss_site->ss_node_id = node_id;
5020 /* failover is the default
5021 * FIXME: we do not failout mds0/mgs, which may cause some problems.
5022 * assumed whose ss_node_id == 0 XXX
5024 obd->obd_replayable = 1;
5025 /* No connection accepted until configurations will finish */
5026 obd->obd_no_conn = 1;
5028 if (cfg->lcfg_bufcount > 4 && LUSTRE_CFG_BUFLEN(cfg, 4) > 0) {
5029 char *str = lustre_cfg_string(cfg, 4);
5030 if (strchr(str, 'n')) {
5031 CWARN("%s: recovery disabled\n", mdt_obd_name(m));
5032 obd->obd_replayable = 0;
5036 rc = mdt_fld_init(env, mdt_obd_name(m), m);
5038 GOTO(err_fini_stack, rc);
5040 rc = mdt_seq_init(env, m);
5042 GOTO(err_fini_fld, rc);
5044 snprintf(info->mti_u.ns_name, sizeof(info->mti_u.ns_name), "%s-%s",
5045 LUSTRE_MDT_NAME, obd->obd_uuid.uuid);
5046 m->mdt_namespace = ldlm_namespace_new(obd, info->mti_u.ns_name,
5047 LDLM_NAMESPACE_SERVER,
5048 LDLM_NAMESPACE_GREEDY,
5050 if (m->mdt_namespace == NULL)
5051 GOTO(err_fini_seq, rc = -ENOMEM);
5053 m->mdt_namespace->ns_lvbp = m;
5054 m->mdt_namespace->ns_lvbo = &mdt_lvbo;
5056 ldlm_register_intent(m->mdt_namespace, mdt_intent_policy);
5057 /* set obd_namespace for compatibility with old code */
5058 obd->obd_namespace = m->mdt_namespace;
5060 rc = mdt_hsm_cdt_init(m);
5062 CERROR("%s: error initializing coordinator, rc %d\n",
5063 mdt_obd_name(m), rc);
5064 GOTO(err_free_ns, rc);
5067 rc = tgt_init(env, &m->mdt_lut, obd, m->mdt_bottom, mdt_common_slice,
5068 OBD_FAIL_MDS_ALL_REQUEST_NET,
5069 OBD_FAIL_MDS_ALL_REPLY_NET);
5071 GOTO(err_free_hsm, rc);
5073 rc = mdt_fs_setup(env, m, obd, lsi);
5077 tgt_adapt_sptlrpc_conf(&m->mdt_lut);
5079 next = m->mdt_child;
5080 rc = next->md_ops->mdo_iocontrol(env, next, OBD_IOC_GET_MNTOPT, 0,
5083 GOTO(err_fs_cleanup, rc);
5085 if (mntopts & MNTOPT_USERXATTR)
5086 m->mdt_opts.mo_user_xattr = 1;
5088 m->mdt_opts.mo_user_xattr = 0;
5090 rc = next->md_ops->mdo_maxeasize_get(env, next, &m->mdt_max_ea_size);
5092 GOTO(err_fs_cleanup, rc);
5094 if (mntopts & MNTOPT_ACL)
5095 m->mdt_opts.mo_acl = 1;
5097 m->mdt_opts.mo_acl = 0;
5099 /* XXX: to support suppgid for ACL, we enable identity_upcall
5100 * by default, otherwise, maybe got unexpected -EACCESS. */
5101 if (m->mdt_opts.mo_acl)
5102 identity_upcall = MDT_IDENTITY_UPCALL_PATH;
5104 m->mdt_identity_cache = upcall_cache_init(mdt_obd_name(m),
5106 &mdt_identity_upcall_cache_ops);
5107 if (IS_ERR(m->mdt_identity_cache)) {
5108 rc = PTR_ERR(m->mdt_identity_cache);
5109 m->mdt_identity_cache = NULL;
5110 GOTO(err_fs_cleanup, rc);
5113 rc = mdt_procfs_init(m, dev);
5115 CERROR("Can't init MDT lprocfs, rc %d\n", rc);
5116 GOTO(err_recovery, rc);
5119 rc = mdt_quota_init(env, m, cfg);
5121 GOTO(err_procfs, rc);
5123 m->mdt_ldlm_client = &mdt2obd_dev(m)->obd_ldlm_client;
5124 ptlrpc_init_client(LDLM_CB_REQUEST_PORTAL, LDLM_CB_REPLY_PORTAL,
5125 "mdt_ldlm_client", m->mdt_ldlm_client);
5127 ping_evictor_start();
5129 /* recovery will be started upon mdt_prepare()
5130 * when the whole stack is complete and ready
5131 * to serve the requests */
5133 /* Reduce the initial timeout on an MDS because it doesn't need such
5134 * a long timeout as an OST does. Adaptive timeouts will adjust this
5135 * value appropriately. */
5136 if (ldlm_timeout == LDLM_TIMEOUT_DEFAULT)
5137 ldlm_timeout = MDS_LDLM_TIMEOUT_DEFAULT;
5143 target_recovery_fini(obd);
5144 upcall_cache_cleanup(m->mdt_identity_cache);
5145 m->mdt_identity_cache = NULL;
5147 mdt_fs_cleanup(env, m);
5149 tgt_fini(env, &m->mdt_lut);
5151 mdt_hsm_cdt_fini(m);
5153 ldlm_namespace_free(m->mdt_namespace, NULL, 0);
5154 obd->obd_namespace = m->mdt_namespace = NULL;
5156 mdt_seq_fini(env, m);
5158 mdt_fld_fini(env, m);
5160 mdt_stack_fini(env, m, md2lu_dev(m->mdt_child));
5163 server_put_mount(dev, true);
5167 /* For interoperability, the left element is old parameter, the right one
5168 * is the new version of the parameter, if some parameter is deprecated,
5169 * the new version should be set as NULL. */
5170 static struct cfg_interop_param mdt_interop_param[] = {
5171 { "mdt.group_upcall", NULL },
5172 { "mdt.quota_type", NULL },
5173 { "mdd.quota_type", NULL },
5174 { "mdt.som", NULL },
5175 { "mdt.rootsquash", "mdt.root_squash" },
5176 { "mdt.nosquash_nid", "mdt.nosquash_nids" },
5180 /* used by MGS to process specific configurations */
5181 static int mdt_process_config(const struct lu_env *env,
5182 struct lu_device *d, struct lustre_cfg *cfg)
5184 struct mdt_device *m = mdt_dev(d);
5185 struct md_device *md_next = m->mdt_child;
5186 struct lu_device *next = md2lu_dev(md_next);
5190 switch (cfg->lcfg_command) {
5192 struct obd_device *obd = d->ld_obd;
5194 /* For interoperability */
5195 struct cfg_interop_param *ptr = NULL;
5196 struct lustre_cfg *old_cfg = NULL;
5199 param = lustre_cfg_string(cfg, 1);
5200 if (param == NULL) {
5201 CERROR("param is empty\n");
5206 ptr = class_find_old_param(param, mdt_interop_param);
5208 if (ptr->new_param == NULL) {
5210 CWARN("For interoperability, skip this %s."
5211 " It is obsolete.\n", ptr->old_param);
5215 CWARN("Found old param %s, changed it to %s.\n",
5216 ptr->old_param, ptr->new_param);
5219 cfg = lustre_cfg_rename(old_cfg, ptr->new_param);
5226 rc = class_process_proc_param(PARAM_MDT, obd->obd_vars,
5228 if (rc > 0 || rc == -ENOSYS) {
5229 /* is it an HSM var ? */
5230 rc = class_process_proc_param(PARAM_HSM,
5231 hsm_cdt_get_proc_vars(),
5233 if (rc > 0 || rc == -ENOSYS)
5234 /* we don't understand; pass it on */
5235 rc = next->ld_ops->ldo_process_config(env, next,
5240 OBD_FREE(cfg, lustre_cfg_len(cfg->lcfg_bufcount,
5241 cfg->lcfg_buflens));
5245 /* others are passed further */
5246 rc = next->ld_ops->ldo_process_config(env, next, cfg);
5252 static struct lu_object *mdt_object_alloc(const struct lu_env *env,
5253 const struct lu_object_header *hdr,
5254 struct lu_device *d)
5256 struct mdt_object *mo;
5260 OBD_SLAB_ALLOC_PTR_GFP(mo, mdt_object_kmem, GFP_NOFS);
5262 struct lu_object *o;
5263 struct lu_object_header *h;
5266 h = &mo->mot_header;
5267 lu_object_header_init(h);
5268 lu_object_init(o, h, d);
5269 lu_object_add_top(h, o);
5270 o->lo_ops = &mdt_obj_ops;
5271 spin_lock_init(&mo->mot_write_lock);
5272 mutex_init(&mo->mot_lov_mutex);
5273 init_rwsem(&mo->mot_dom_sem);
5274 init_rwsem(&mo->mot_open_sem);
5275 atomic_set(&mo->mot_open_count, 0);
5281 static int mdt_object_init(const struct lu_env *env, struct lu_object *o,
5282 const struct lu_object_conf *unused)
5284 struct mdt_device *d = mdt_dev(o->lo_dev);
5285 struct lu_device *under;
5286 struct lu_object *below;
5290 CDEBUG(D_INFO, "object init, fid = "DFID"\n",
5291 PFID(lu_object_fid(o)));
5293 under = &d->mdt_child->md_lu_dev;
5294 below = under->ld_ops->ldo_object_alloc(env, o->lo_header, under);
5295 if (below != NULL) {
5296 lu_object_add(o, below);
5303 static void mdt_object_free(const struct lu_env *env, struct lu_object *o)
5305 struct mdt_object *mo = mdt_obj(o);
5306 struct lu_object_header *h;
5310 CDEBUG(D_INFO, "object free, fid = "DFID"\n",
5311 PFID(lu_object_fid(o)));
5313 LASSERT(atomic_read(&mo->mot_open_count) == 0);
5314 LASSERT(atomic_read(&mo->mot_lease_count) == 0);
5317 lu_object_header_fini(h);
5318 OBD_SLAB_FREE_PTR(mo, mdt_object_kmem);
5323 static int mdt_object_print(const struct lu_env *env, void *cookie,
5324 lu_printer_t p, const struct lu_object *o)
5326 struct mdt_object *mdto = mdt_obj((struct lu_object *)o);
5328 return (*p)(env, cookie,
5329 LUSTRE_MDT_NAME"-object@%p(%s %s, writecount=%d)",
5330 mdto, mdto->mot_lov_created ? "lov_created" : "",
5331 mdto->mot_cache_attr ? "cache_attr" : "",
5332 mdto->mot_write_count);
5335 static int mdt_prepare(const struct lu_env *env,
5336 struct lu_device *pdev,
5337 struct lu_device *cdev)
5339 struct mdt_device *mdt = mdt_dev(cdev);
5340 struct lu_device *next = &mdt->mdt_child->md_lu_dev;
5341 struct obd_device *obd = cdev->ld_obd;
5348 rc = next->ld_ops->ldo_prepare(env, cdev, next);
5352 rc = mdt_llog_ctxt_clone(env, mdt, LLOG_CHANGELOG_ORIG_CTXT);
5356 rc = mdt_llog_ctxt_clone(env, mdt, LLOG_AGENT_ORIG_CTXT);
5360 rc = lfsck_register_namespace(env, mdt->mdt_bottom, mdt->mdt_namespace);
5361 /* The LFSCK instance is registered just now, so it must be there when
5362 * register the namespace to such instance. */
5363 LASSERTF(rc == 0, "register namespace failed: rc = %d\n", rc);
5365 if (mdt->mdt_seq_site.ss_node_id == 0) {
5366 rc = mdt->mdt_child->md_ops->mdo_root_get(env, mdt->mdt_child,
5367 &mdt->mdt_md_root_fid);
5372 LASSERT(!test_bit(MDT_FL_CFGLOG, &mdt->mdt_state));
5374 target_recovery_init(&mdt->mdt_lut, tgt_request_handle);
5375 set_bit(MDT_FL_CFGLOG, &mdt->mdt_state);
5376 LASSERT(obd->obd_no_conn);
5377 spin_lock(&obd->obd_dev_lock);
5378 obd->obd_no_conn = 0;
5379 spin_unlock(&obd->obd_dev_lock);
5381 if (obd->obd_recovering == 0)
5382 mdt_postrecov(env, mdt);
5387 const struct lu_device_operations mdt_lu_ops = {
5388 .ldo_object_alloc = mdt_object_alloc,
5389 .ldo_process_config = mdt_process_config,
5390 .ldo_prepare = mdt_prepare,
5393 static const struct lu_object_operations mdt_obj_ops = {
5394 .loo_object_init = mdt_object_init,
5395 .loo_object_free = mdt_object_free,
5396 .loo_object_print = mdt_object_print
5399 static int mdt_obd_set_info_async(const struct lu_env *env,
5400 struct obd_export *exp,
5401 __u32 keylen, void *key,
5402 __u32 vallen, void *val,
5403 struct ptlrpc_request_set *set)
5409 if (KEY_IS(KEY_SPTLRPC_CONF)) {
5410 rc = tgt_adapt_sptlrpc_conf(class_exp2tgt(exp));
5418 * Match client and server connection feature flags.
5420 * Compute the compatibility flags for a connection request based on
5421 * features mutually supported by client and server.
5423 * The obd_export::exp_connect_data.ocd_connect_flags field in \a exp
5424 * must not be updated here, otherwise a partially initialized value may
5425 * be exposed. After the connection request is successfully processed,
5426 * the top-level MDT connect request handler atomically updates the export
5427 * connect flags from the obd_connect_data::ocd_connect_flags field of the
5428 * reply. \see mdt_connect().
5430 * Before 2.7.50 clients will send a struct obd_connect_data_v1 rather than a
5431 * full struct obd_connect_data. So care must be taken when accessing fields
5432 * that are not present in struct obd_connect_data_v1. See LU-16.
5434 * \param exp the obd_export associated with this client/target pair
5435 * \param mdt the target device for the connection
5436 * \param data stores data for this connect request
5439 * \retval -EPROTO \a data unexpectedly has zero obd_connect_data::ocd_brw_size
5440 * \retval -EBADE client and server feature requirements are incompatible
5442 static int mdt_connect_internal(const struct lu_env *env,
5443 struct obd_export *exp,
5444 struct mdt_device *mdt,
5445 struct obd_connect_data *data, bool reconnect)
5447 LASSERT(data != NULL);
5449 data->ocd_connect_flags &= MDT_CONNECT_SUPPORTED;
5451 if (mdt->mdt_bottom->dd_rdonly &&
5452 !(data->ocd_connect_flags & OBD_CONNECT_MDS_MDS) &&
5453 !(data->ocd_connect_flags & OBD_CONNECT_RDONLY))
5456 if (data->ocd_connect_flags & OBD_CONNECT_FLAGS2)
5457 data->ocd_connect_flags2 &= MDT_CONNECT_SUPPORTED2;
5459 data->ocd_ibits_known &= MDS_INODELOCK_FULL;
5461 if (!(data->ocd_connect_flags & OBD_CONNECT_MDS_MDS) &&
5462 !(data->ocd_connect_flags & OBD_CONNECT_IBITS)) {
5463 CWARN("%s: client %s does not support ibits lock, either "
5464 "very old or an invalid client: flags %#llx\n",
5465 mdt_obd_name(mdt), exp->exp_client_uuid.uuid,
5466 data->ocd_connect_flags);
5470 if (!mdt->mdt_opts.mo_acl)
5471 data->ocd_connect_flags &= ~OBD_CONNECT_ACL;
5473 if (!mdt->mdt_opts.mo_user_xattr)
5474 data->ocd_connect_flags &= ~OBD_CONNECT_XATTR;
5476 if (OCD_HAS_FLAG(data, BRW_SIZE)) {
5477 data->ocd_brw_size = min(data->ocd_brw_size, MD_MAX_BRW_SIZE);
5478 if (data->ocd_brw_size == 0) {
5479 CERROR("%s: cli %s/%p ocd_connect_flags: %#llx "
5480 "ocd_version: %x ocd_grant: %d ocd_index: %u "
5481 "ocd_brw_size unexpectedly zero, network data "
5482 "corruption? Refusing to connect this client\n",
5484 exp->exp_client_uuid.uuid,
5485 exp, data->ocd_connect_flags, data->ocd_version,
5486 data->ocd_grant, data->ocd_index);
5491 if (OCD_HAS_FLAG(data, GRANT))
5492 data->ocd_grant = mdt_grant_connect(env, exp, data->ocd_grant,
5495 /* NB: Disregard the rule against updating
5496 * exp_connect_data.ocd_connect_flags in this case, since
5497 * tgt_client_new() needs to know if this is a lightweight
5498 * connection, and it is safe to expose this flag before
5499 * connection processing completes. */
5500 if (data->ocd_connect_flags & OBD_CONNECT_LIGHTWEIGHT) {
5501 spin_lock(&exp->exp_lock);
5502 *exp_connect_flags_ptr(exp) |= OBD_CONNECT_LIGHTWEIGHT;
5503 spin_unlock(&exp->exp_lock);
5506 data->ocd_version = LUSTRE_VERSION_CODE;
5508 if ((data->ocd_connect_flags & OBD_CONNECT_FID) == 0) {
5509 CWARN("%s: MDS requires FID support, but client not\n",
5514 if (OCD_HAS_FLAG(data, PINGLESS)) {
5515 if (ptlrpc_pinger_suppress_pings()) {
5516 spin_lock(&exp->exp_obd->obd_dev_lock);
5517 list_del_init(&exp->exp_obd_chain_timed);
5518 spin_unlock(&exp->exp_obd->obd_dev_lock);
5520 data->ocd_connect_flags &= ~OBD_CONNECT_PINGLESS;
5524 data->ocd_max_easize = mdt->mdt_max_ea_size;
5526 /* NB: Disregard the rule against updating
5527 * exp_connect_data.ocd_connect_flags in this case, since
5528 * tgt_client_new() needs to know if this is client supports
5529 * multiple modify RPCs, and it is safe to expose this flag before
5530 * connection processing completes. */
5531 if (data->ocd_connect_flags & OBD_CONNECT_MULTIMODRPCS) {
5532 data->ocd_maxmodrpcs = max_mod_rpcs_per_client;
5533 spin_lock(&exp->exp_lock);
5534 *exp_connect_flags_ptr(exp) |= OBD_CONNECT_MULTIMODRPCS;
5535 spin_unlock(&exp->exp_lock);
5538 if (OCD_HAS_FLAG(data, CKSUM)) {
5539 __u32 cksum_types = data->ocd_cksum_types;
5541 /* The client set in ocd_cksum_types the checksum types it
5542 * supports. We have to mask off the algorithms that we don't
5544 data->ocd_cksum_types &= cksum_types_supported_server();
5546 if (unlikely(data->ocd_cksum_types == 0)) {
5547 CERROR("%s: Connect with checksum support but no "
5548 "ocd_cksum_types is set\n",
5549 exp->exp_obd->obd_name);
5553 CDEBUG(D_RPCTRACE, "%s: cli %s supports cksum type %x, return "
5554 "%x\n", exp->exp_obd->obd_name, obd_export_nid2str(exp),
5555 cksum_types, data->ocd_cksum_types);
5557 /* This client does not support OBD_CONNECT_CKSUM
5558 * fall back to CRC32 */
5559 CDEBUG(D_RPCTRACE, "%s: cli %s does not support "
5560 "OBD_CONNECT_CKSUM, CRC32 will be used\n",
5561 exp->exp_obd->obd_name, obd_export_nid2str(exp));
5567 static int mdt_ctxt_add_dirty_flag(struct lu_env *env,
5568 struct mdt_thread_info *info,
5569 struct mdt_file_data *mfd)
5571 struct lu_context ses;
5575 rc = lu_context_init(&ses, LCT_SERVER_SESSION);
5580 lu_context_enter(&ses);
5582 mdt_ucred(info)->uc_valid = UCRED_OLD;
5583 rc = mdt_add_dirty_flag(info, mfd->mfd_object, &info->mti_attr);
5585 lu_context_exit(&ses);
5586 lu_context_fini(&ses);
5592 static int mdt_export_cleanup(struct obd_export *exp)
5594 struct list_head closing_list;
5595 struct mdt_export_data *med = &exp->exp_mdt_data;
5596 struct obd_device *obd = exp->exp_obd;
5597 struct mdt_device *mdt;
5598 struct mdt_thread_info *info;
5600 struct mdt_file_data *mfd, *n;
5604 INIT_LIST_HEAD(&closing_list);
5605 spin_lock(&med->med_open_lock);
5606 while (!list_empty(&med->med_open_head)) {
5607 struct list_head *tmp = med->med_open_head.next;
5608 mfd = list_entry(tmp, struct mdt_file_data, mfd_list);
5610 /* Remove mfd handle so it can't be found again.
5611 * We are consuming the mfd_list reference here. */
5612 class_handle_unhash(&mfd->mfd_handle);
5613 list_move_tail(&mfd->mfd_list, &closing_list);
5615 spin_unlock(&med->med_open_lock);
5616 mdt = mdt_dev(obd->obd_lu_dev);
5617 LASSERT(mdt != NULL);
5619 rc = lu_env_init(&env, LCT_MD_THREAD);
5623 info = lu_context_key_get(&env.le_ctx, &mdt_thread_key);
5624 LASSERT(info != NULL);
5625 memset(info, 0, sizeof *info);
5626 info->mti_env = &env;
5627 info->mti_mdt = mdt;
5628 info->mti_exp = exp;
5630 if (!list_empty(&closing_list)) {
5631 struct md_attr *ma = &info->mti_attr;
5633 /* Close any open files (which may also cause orphan
5635 list_for_each_entry_safe(mfd, n, &closing_list, mfd_list) {
5636 list_del_init(&mfd->mfd_list);
5637 ma->ma_need = ma->ma_valid = 0;
5639 /* This file is being closed due to an eviction, it
5640 * could have been modified and now dirty regarding to
5641 * HSM archive, check this!
5642 * The logic here is to mark a file dirty if there's a
5643 * chance it was dirtied before the client was evicted,
5644 * so that we don't have to wait for a release attempt
5645 * before finding out the file was actually dirty and
5646 * fail the release. Aggressively marking it dirty here
5647 * will cause the policy engine to attempt to
5648 * re-archive it; when rearchiving, we can compare the
5649 * current version to the HSM data_version and make the
5650 * archive request into a noop if it's not actually
5653 if (mfd->mfd_mode & FMODE_WRITE)
5654 rc = mdt_ctxt_add_dirty_flag(&env, info, mfd);
5656 /* Don't unlink orphan on failover umount, LU-184 */
5657 if (exp->exp_flags & OBD_OPT_FAILOVER) {
5658 ma->ma_valid = MA_FLAGS;
5659 ma->ma_attr_flags |= MDS_KEEP_ORPHAN;
5661 mdt_mfd_close(info, mfd);
5664 info->mti_mdt = NULL;
5665 /* cleanup client slot early */
5666 /* Do not erase record for recoverable client. */
5667 if (!(exp->exp_flags & OBD_OPT_FAILOVER) || exp->exp_failed)
5668 tgt_client_del(&env, exp);
5674 static inline void mdt_enable_slc(struct mdt_device *mdt)
5676 if (mdt->mdt_lut.lut_sync_lock_cancel == NEVER_SYNC_ON_CANCEL)
5677 mdt->mdt_lut.lut_sync_lock_cancel = BLOCKING_SYNC_ON_CANCEL;
5680 static inline void mdt_disable_slc(struct mdt_device *mdt)
5682 if (mdt->mdt_lut.lut_sync_lock_cancel == BLOCKING_SYNC_ON_CANCEL)
5683 mdt->mdt_lut.lut_sync_lock_cancel = NEVER_SYNC_ON_CANCEL;
5686 static int mdt_obd_disconnect(struct obd_export *exp)
5692 class_export_get(exp);
5694 if ((exp_connect_flags(exp) & OBD_CONNECT_MDS_MDS) &&
5695 !(exp_connect_flags(exp) & OBD_CONNECT_LIGHTWEIGHT)) {
5696 struct mdt_device *mdt = mdt_dev(exp->exp_obd->obd_lu_dev);
5698 if (atomic_dec_and_test(&mdt->mdt_mds_mds_conns))
5699 mdt_disable_slc(mdt);
5702 rc = server_disconnect_export(exp);
5704 CDEBUG(D_IOCTL, "server disconnect error: rc = %d\n", rc);
5706 rc = mdt_export_cleanup(exp);
5707 nodemap_del_member(exp);
5708 class_export_put(exp);
5712 /* mds_connect copy */
5713 static int mdt_obd_connect(const struct lu_env *env,
5714 struct obd_export **exp, struct obd_device *obd,
5715 struct obd_uuid *cluuid,
5716 struct obd_connect_data *data,
5719 struct obd_export *lexp;
5720 struct lustre_handle conn = { 0 };
5721 struct mdt_device *mdt;
5723 lnet_nid_t *client_nid = localdata;
5726 LASSERT(env != NULL);
5727 LASSERT(data != NULL);
5729 if (!exp || !obd || !cluuid)
5732 mdt = mdt_dev(obd->obd_lu_dev);
5734 if ((data->ocd_connect_flags & OBD_CONNECT_MDS_MDS) &&
5735 !(data->ocd_connect_flags & OBD_CONNECT_LIGHTWEIGHT)) {
5736 atomic_inc(&mdt->mdt_mds_mds_conns);
5737 mdt_enable_slc(mdt);
5741 * first, check whether the stack is ready to handle requests
5742 * XXX: probably not very appropriate method is used now
5743 * at some point we should find a better one
5745 if (!test_bit(MDT_FL_SYNCED, &mdt->mdt_state) &&
5746 !(data->ocd_connect_flags & OBD_CONNECT_LIGHTWEIGHT) &&
5747 !(data->ocd_connect_flags & OBD_CONNECT_MDS_MDS)) {
5748 rc = obd_get_info(env, mdt->mdt_child_exp,
5749 sizeof(KEY_OSP_CONNECTED),
5750 KEY_OSP_CONNECTED, NULL, NULL);
5753 set_bit(MDT_FL_SYNCED, &mdt->mdt_state);
5756 rc = class_connect(&conn, obd, cluuid);
5760 lexp = class_conn2export(&conn);
5761 LASSERT(lexp != NULL);
5763 rc = nodemap_add_member(*client_nid, lexp);
5764 if (rc != 0 && rc != -EEXIST)
5767 rc = mdt_connect_internal(env, lexp, mdt, data, false);
5769 struct lsd_client_data *lcd = lexp->exp_target_data.ted_lcd;
5772 memcpy(lcd->lcd_uuid, cluuid, sizeof lcd->lcd_uuid);
5773 rc = tgt_client_new(env, lexp);
5775 mdt_export_stats_init(obd, lexp, localdata);
5779 class_disconnect(lexp);
5780 nodemap_del_member(lexp);
5784 /* Because we do not want this export to be evicted by pinger,
5785 * let's not add this export to the timed chain list. */
5786 if (data->ocd_connect_flags & OBD_CONNECT_MDS_MDS) {
5787 spin_lock(&lexp->exp_obd->obd_dev_lock);
5788 list_del_init(&lexp->exp_obd_chain_timed);
5789 spin_unlock(&lexp->exp_obd->obd_dev_lock);
5796 static int mdt_obd_reconnect(const struct lu_env *env,
5797 struct obd_export *exp, struct obd_device *obd,
5798 struct obd_uuid *cluuid,
5799 struct obd_connect_data *data,
5802 lnet_nid_t *client_nid = localdata;
5806 if (exp == NULL || obd == NULL || cluuid == NULL)
5809 rc = nodemap_add_member(*client_nid, exp);
5810 if (rc != 0 && rc != -EEXIST)
5813 rc = mdt_connect_internal(env, exp, mdt_dev(obd->obd_lu_dev), data,
5816 mdt_export_stats_init(obd, exp, localdata);
5818 nodemap_del_member(exp);
5823 /* FIXME: Can we avoid using these two interfaces? */
5824 static int mdt_init_export(struct obd_export *exp)
5826 struct mdt_export_data *med = &exp->exp_mdt_data;
5830 INIT_LIST_HEAD(&med->med_open_head);
5831 spin_lock_init(&med->med_open_lock);
5832 spin_lock(&exp->exp_lock);
5833 exp->exp_connecting = 1;
5834 spin_unlock(&exp->exp_lock);
5836 /* self-export doesn't need client data and ldlm initialization */
5837 if (unlikely(obd_uuid_equals(&exp->exp_obd->obd_uuid,
5838 &exp->exp_client_uuid)))
5841 rc = tgt_client_alloc(exp);
5845 rc = ldlm_init_export(exp);
5852 tgt_client_free(exp);
5854 CERROR("%s: Failed to initialize export: rc = %d\n",
5855 exp->exp_obd->obd_name, rc);
5859 static int mdt_destroy_export(struct obd_export *exp)
5863 target_destroy_export(exp);
5864 /* destroy can be called from failed obd_setup, so
5865 * checking uuid is safer than obd_self_export */
5866 if (unlikely(obd_uuid_equals(&exp->exp_obd->obd_uuid,
5867 &exp->exp_client_uuid)))
5870 ldlm_destroy_export(exp);
5871 tgt_client_free(exp);
5873 LASSERT(list_empty(&exp->exp_outstanding_replies));
5874 LASSERT(list_empty(&exp->exp_mdt_data.med_open_head));
5879 int mdt_links_read(struct mdt_thread_info *info, struct mdt_object *mdt_obj,
5880 struct linkea_data *ldata)
5884 LASSERT(ldata->ld_buf->lb_buf != NULL);
5886 if (!mdt_object_exists(mdt_obj))
5889 rc = mo_xattr_get(info->mti_env, mdt_object_child(mdt_obj),
5890 ldata->ld_buf, XATTR_NAME_LINK);
5891 if (rc == -ERANGE) {
5892 /* Buf was too small, figure out what we need. */
5893 lu_buf_free(ldata->ld_buf);
5894 rc = mo_xattr_get(info->mti_env, mdt_object_child(mdt_obj),
5895 ldata->ld_buf, XATTR_NAME_LINK);
5898 ldata->ld_buf = lu_buf_check_and_alloc(ldata->ld_buf, rc);
5899 if (ldata->ld_buf->lb_buf == NULL)
5901 rc = mo_xattr_get(info->mti_env, mdt_object_child(mdt_obj),
5902 ldata->ld_buf, XATTR_NAME_LINK);
5907 return linkea_init_with_rec(ldata);
5911 * Given an MDT object, try to look up the full path to the object.
5912 * Part of the MDT layer implementation of lfs fid2path.
5914 * \param[in] info Per-thread common data shared by MDT level handlers.
5915 * \param[in] obj Object to do path lookup of
5916 * \param[in,out] fp User-provided struct to store path information
5917 * \param[in] root_fid Root FID of current path should reach
5919 * \retval 0 Lookup successful, path information stored in fp
5920 * \retval -EAGAIN Lookup failed, usually because object is being moved
5921 * \retval negative errno if there was a problem
5923 static int mdt_path_current(struct mdt_thread_info *info,
5924 struct mdt_object *obj,
5925 struct getinfo_fid2path *fp,
5926 struct lu_fid *root_fid)
5928 struct mdt_device *mdt = info->mti_mdt;
5929 struct mdt_object *mdt_obj;
5930 struct link_ea_header *leh;
5931 struct link_ea_entry *lee;
5932 struct lu_name *tmpname = &info->mti_name;
5933 struct lu_fid *tmpfid = &info->mti_tmp_fid1;
5934 struct lu_buf *buf = &info->mti_big_buf;
5937 struct linkea_data ldata = { NULL };
5942 /* temp buffer for path element, the buffer will be finally freed
5943 * in mdt_thread_info_fini */
5944 buf = lu_buf_check_and_alloc(buf, PATH_MAX);
5945 if (buf->lb_buf == NULL)
5949 ptr = fp->gf_u.gf_path + fp->gf_pathlen - 1;
5952 *tmpfid = fp->gf_fid = *mdt_object_fid(obj);
5954 while (!lu_fid_eq(root_fid, &fp->gf_fid)) {
5955 struct lu_buf lmv_buf;
5957 if (!lu_fid_eq(root_fid, &mdt->mdt_md_root_fid) &&
5958 lu_fid_eq(&mdt->mdt_md_root_fid, &fp->gf_fid))
5959 GOTO(out, rc = -ENOENT);
5961 if (lu_fid_eq(mdt_object_fid(obj), tmpfid)) {
5963 mdt_object_get(info->mti_env, mdt_obj);
5965 mdt_obj = mdt_object_find(info->mti_env, mdt, tmpfid);
5966 if (IS_ERR(mdt_obj))
5967 GOTO(out, rc = PTR_ERR(mdt_obj));
5970 if (!mdt_object_exists(mdt_obj)) {
5971 mdt_object_put(info->mti_env, mdt_obj);
5972 GOTO(out, rc = -ENOENT);
5975 if (mdt_object_remote(mdt_obj)) {
5976 mdt_object_put(info->mti_env, mdt_obj);
5977 GOTO(remote_out, rc = -EREMOTE);
5980 rc = mdt_links_read(info, mdt_obj, &ldata);
5982 mdt_object_put(info->mti_env, mdt_obj);
5987 lee = (struct link_ea_entry *)(leh + 1); /* link #0 */
5988 linkea_entry_unpack(lee, &reclen, tmpname, tmpfid);
5989 /* If set, use link #linkno for path lookup, otherwise use
5990 link #0. Only do this for the final path element. */
5991 if (first && fp->gf_linkno < leh->leh_reccount) {
5993 for (count = 0; count < fp->gf_linkno; count++) {
5994 lee = (struct link_ea_entry *)
5995 ((char *)lee + reclen);
5996 linkea_entry_unpack(lee, &reclen, tmpname,
5999 if (fp->gf_linkno < leh->leh_reccount - 1)
6000 /* indicate to user there are more links */
6004 lmv_buf.lb_buf = info->mti_xattr_buf;
6005 lmv_buf.lb_len = sizeof(info->mti_xattr_buf);
6006 /* Check if it is slave stripes */
6007 rc = mo_xattr_get(info->mti_env, mdt_object_child(mdt_obj),
6008 &lmv_buf, XATTR_NAME_LMV);
6009 mdt_object_put(info->mti_env, mdt_obj);
6011 union lmv_mds_md *lmm = lmv_buf.lb_buf;
6013 /* For slave stripes, get its master */
6014 if (le32_to_cpu(lmm->lmv_magic) == LMV_MAGIC_STRIPE) {
6015 fp->gf_fid = *tmpfid;
6018 } else if (rc < 0 && rc != -ENODATA) {
6024 /* Pack the name in the end of the buffer */
6025 ptr -= tmpname->ln_namelen;
6026 if (ptr - 1 <= fp->gf_u.gf_path)
6027 GOTO(out, rc = -EOVERFLOW);
6028 strncpy(ptr, tmpname->ln_name, tmpname->ln_namelen);
6031 /* keep the last resolved fid to the client, so the
6032 * client will build the left path on another MDT for
6034 fp->gf_fid = *tmpfid;
6040 ptr++; /* skip leading / */
6041 memmove(fp->gf_u.gf_path, ptr,
6042 fp->gf_u.gf_path + fp->gf_pathlen - ptr);
6049 * Given an MDT object, use mdt_path_current to get the path.
6050 * Essentially a wrapper to retry mdt_path_current a set number of times
6051 * if -EAGAIN is returned (usually because an object is being moved).
6053 * Part of the MDT layer implementation of lfs fid2path.
6055 * \param[in] info Per-thread common data shared by mdt level handlers.
6056 * \param[in] obj Object to do path lookup of
6057 * \param[in,out] fp User-provided struct for arguments and to store path
6060 * \retval 0 Lookup successful, path information stored in fp
6061 * \retval negative errno if there was a problem
6063 static int mdt_path(struct mdt_thread_info *info, struct mdt_object *obj,
6064 struct getinfo_fid2path *fp, struct lu_fid *root_fid)
6066 struct mdt_device *mdt = info->mti_mdt;
6071 if (fp->gf_pathlen < 3)
6074 if (root_fid == NULL)
6075 root_fid = &mdt->mdt_md_root_fid;
6077 if (lu_fid_eq(root_fid, mdt_object_fid(obj))) {
6078 fp->gf_u.gf_path[0] = '\0';
6082 /* Retry multiple times in case file is being moved */
6083 while (tries-- && rc == -EAGAIN)
6084 rc = mdt_path_current(info, obj, fp, root_fid);
6090 * Get the full path of the provided FID, as of changelog record recno.
6092 * This checks sanity and looks up object for user provided FID
6093 * before calling the actual path lookup code.
6095 * Part of the MDT layer implementation of lfs fid2path.
6097 * \param[in] info Per-thread common data shared by mdt level handlers.
6098 * \param[in,out] fp User-provided struct for arguments and to store path
6101 * \retval 0 Lookup successful, path information and recno stored in fp
6102 * \retval -ENOENT, object does not exist
6103 * \retval negative errno if there was a problem
6105 static int mdt_fid2path(struct mdt_thread_info *info,
6106 struct lu_fid *root_fid,
6107 struct getinfo_fid2path *fp)
6109 struct mdt_device *mdt = info->mti_mdt;
6110 struct mdt_object *obj;
6114 CDEBUG(D_IOCTL, "path get "DFID" from %llu #%d\n",
6115 PFID(&fp->gf_fid), fp->gf_recno, fp->gf_linkno);
6117 if (!fid_is_sane(&fp->gf_fid))
6120 if (!fid_is_namespace_visible(&fp->gf_fid)) {
6121 CDEBUG(D_INFO, "%s: "DFID" is invalid, f_seq should be >= %#llx"
6122 ", or f_oid != 0, or f_ver == 0\n", mdt_obd_name(mdt),
6123 PFID(&fp->gf_fid), (__u64)FID_SEQ_NORMAL);
6127 obj = mdt_object_find(info->mti_env, mdt, &fp->gf_fid);
6130 CDEBUG(D_IOCTL, "cannot find "DFID": rc = %d\n",
6131 PFID(&fp->gf_fid), rc);
6135 if (mdt_object_remote(obj))
6137 else if (!mdt_object_exists(obj))
6143 mdt_object_put(info->mti_env, obj);
6144 CDEBUG(D_IOCTL, "nonlocal object "DFID": rc = %d\n",
6145 PFID(&fp->gf_fid), rc);
6149 rc = mdt_path(info, obj, fp, root_fid);
6151 CDEBUG(D_INFO, "fid "DFID", path %s recno %#llx linkno %u\n",
6152 PFID(&fp->gf_fid), fp->gf_u.gf_path,
6153 fp->gf_recno, fp->gf_linkno);
6155 mdt_object_put(info->mti_env, obj);
6160 static int mdt_rpc_fid2path(struct mdt_thread_info *info, void *key, int keylen,
6161 void *val, int vallen)
6163 struct getinfo_fid2path *fpout, *fpin;
6164 struct lu_fid *root_fid = NULL;
6167 fpin = key + cfs_size_round(sizeof(KEY_FID2PATH));
6170 if (ptlrpc_req_need_swab(info->mti_pill->rc_req))
6171 lustre_swab_fid2path(fpin);
6173 memcpy(fpout, fpin, sizeof(*fpin));
6174 if (fpout->gf_pathlen != vallen - sizeof(*fpin))
6177 if (keylen >= cfs_size_round(sizeof(KEY_FID2PATH)) + sizeof(*fpin) +
6178 sizeof(struct lu_fid)) {
6179 /* client sent its root FID, which is normally fileset FID */
6180 root_fid = fpin->gf_u.gf_root_fid;
6181 if (ptlrpc_req_need_swab(info->mti_pill->rc_req))
6182 lustre_swab_lu_fid(root_fid);
6184 if (root_fid != NULL && !fid_is_sane(root_fid))
6188 rc = mdt_fid2path(info, root_fid, fpout);
6192 int mdt_get_info(struct tgt_session_info *tsi)
6202 key = req_capsule_client_get(tsi->tsi_pill, &RMF_GETINFO_KEY);
6204 CDEBUG(D_IOCTL, "No GETINFO key\n");
6205 RETURN(err_serious(-EFAULT));
6207 keylen = req_capsule_get_size(tsi->tsi_pill, &RMF_GETINFO_KEY,
6210 vallen = req_capsule_client_get(tsi->tsi_pill, &RMF_GETINFO_VALLEN);
6211 if (vallen == NULL) {
6212 CDEBUG(D_IOCTL, "%s: cannot get RMF_GETINFO_VALLEN buffer\n",
6213 tgt_name(tsi->tsi_tgt));
6214 RETURN(err_serious(-EFAULT));
6217 req_capsule_set_size(tsi->tsi_pill, &RMF_GETINFO_VAL, RCL_SERVER,
6219 rc = req_capsule_server_pack(tsi->tsi_pill);
6221 RETURN(err_serious(rc));
6223 valout = req_capsule_server_get(tsi->tsi_pill, &RMF_GETINFO_VAL);
6224 if (valout == NULL) {
6225 CDEBUG(D_IOCTL, "%s: cannot get get-info RPC out buffer\n",
6226 tgt_name(tsi->tsi_tgt));
6227 RETURN(err_serious(-EFAULT));
6230 if (KEY_IS(KEY_FID2PATH)) {
6231 struct mdt_thread_info *info = tsi2mdt_info(tsi);
6233 rc = mdt_rpc_fid2path(info, key, keylen, valout, *vallen);
6234 mdt_thread_info_fini(info);
6241 static int mdt_ioc_version_get(struct mdt_thread_info *mti, void *karg)
6243 struct obd_ioctl_data *data = karg;
6246 struct mdt_object *obj;
6247 struct mdt_lock_handle *lh;
6251 if (data->ioc_inlbuf1 == NULL || data->ioc_inllen1 != sizeof(*fid) ||
6252 data->ioc_inlbuf2 == NULL || data->ioc_inllen2 != sizeof(version))
6255 fid = (struct lu_fid *)data->ioc_inlbuf1;
6257 if (!fid_is_sane(fid))
6260 CDEBUG(D_IOCTL, "getting version for "DFID"\n", PFID(fid));
6262 lh = &mti->mti_lh[MDT_LH_PARENT];
6263 mdt_lock_reg_init(lh, LCK_CR);
6265 obj = mdt_object_find_lock(mti, fid, lh, MDS_INODELOCK_UPDATE);
6267 RETURN(PTR_ERR(obj));
6269 if (mdt_object_remote(obj)) {
6272 * before calling version get the correct MDS should be
6273 * fid, this is error to find remote object here
6275 CERROR("nonlocal object "DFID"\n", PFID(fid));
6276 } else if (!mdt_object_exists(obj)) {
6277 *(__u64 *)data->ioc_inlbuf2 = ENOENT_VERSION;
6280 version = dt_version_get(mti->mti_env, mdt_obj2dt(obj));
6281 *(__u64 *)data->ioc_inlbuf2 = version;
6284 mdt_object_unlock_put(mti, obj, lh, 1);
6288 /* ioctls on obd dev */
6289 static int mdt_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
6290 void *karg, void __user *uarg)
6293 struct obd_device *obd = exp->exp_obd;
6294 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
6295 struct dt_device *dt = mdt->mdt_bottom;
6299 CDEBUG(D_IOCTL, "handling ioctl cmd %#x\n", cmd);
6300 rc = lu_env_init(&env, LCT_MD_THREAD);
6306 rc = mdt_device_sync(&env, mdt);
6308 case OBD_IOC_SET_READONLY:
6309 rc = dt_sync(&env, dt);
6311 rc = dt_ro(&env, dt);
6313 case OBD_IOC_ABORT_RECOVERY:
6314 CERROR("%s: Aborting recovery for device\n", mdt_obd_name(mdt));
6315 obd->obd_abort_recovery = 1;
6316 target_stop_recovery_thread(obd);
6319 case OBD_IOC_CHANGELOG_REG:
6320 case OBD_IOC_CHANGELOG_DEREG:
6321 case OBD_IOC_CHANGELOG_CLEAR:
6322 rc = mdt->mdt_child->md_ops->mdo_iocontrol(&env,
6326 case OBD_IOC_START_LFSCK: {
6327 struct md_device *next = mdt->mdt_child;
6328 struct obd_ioctl_data *data = karg;
6329 struct lfsck_start_param lsp;
6331 if (unlikely(data == NULL)) {
6336 lsp.lsp_start = (struct lfsck_start *)(data->ioc_inlbuf1);
6337 lsp.lsp_index_valid = 0;
6338 rc = next->md_ops->mdo_iocontrol(&env, next, cmd, 0, &lsp);
6341 case OBD_IOC_STOP_LFSCK: {
6342 struct md_device *next = mdt->mdt_child;
6343 struct obd_ioctl_data *data = karg;
6344 struct lfsck_stop stop;
6346 stop.ls_status = LS_STOPPED;
6347 /* Old lfsck utils may pass NULL @stop. */
6348 if (data->ioc_inlbuf1 == NULL)
6352 ((struct lfsck_stop *)(data->ioc_inlbuf1))->ls_flags;
6354 rc = next->md_ops->mdo_iocontrol(&env, next, cmd, 0, &stop);
6357 case OBD_IOC_QUERY_LFSCK: {
6358 struct md_device *next = mdt->mdt_child;
6359 struct obd_ioctl_data *data = karg;
6361 rc = next->md_ops->mdo_iocontrol(&env, next, cmd, 0,
6365 case OBD_IOC_GET_OBJ_VERSION: {
6366 struct mdt_thread_info *mti;
6367 mti = lu_context_key_get(&env.le_ctx, &mdt_thread_key);
6368 memset(mti, 0, sizeof *mti);
6369 mti->mti_env = &env;
6373 rc = mdt_ioc_version_get(mti, karg);
6376 case OBD_IOC_CATLOGLIST: {
6377 struct mdt_thread_info *mti;
6379 mti = lu_context_key_get(&env.le_ctx, &mdt_thread_key);
6380 lu_local_obj_fid(&mti->mti_tmp_fid1, LLOG_CATALOGS_OID);
6381 rc = llog_catalog_list(&env, mdt->mdt_bottom, 0, karg,
6382 &mti->mti_tmp_fid1);
6387 CERROR("%s: Not supported cmd = %d, rc = %d\n",
6388 mdt_obd_name(mdt), cmd, rc);
6395 static int mdt_postrecov(const struct lu_env *env, struct mdt_device *mdt)
6397 struct lu_device *ld = md2lu_dev(mdt->mdt_child);
6401 if (!mdt->mdt_skip_lfsck && !mdt->mdt_bottom->dd_rdonly) {
6402 struct lfsck_start_param lsp;
6404 lsp.lsp_start = NULL;
6405 lsp.lsp_index_valid = 0;
6406 rc = mdt->mdt_child->md_ops->mdo_iocontrol(env, mdt->mdt_child,
6407 OBD_IOC_START_LFSCK,
6409 if (rc != 0 && rc != -EALREADY)
6410 CWARN("%s: auto trigger paused LFSCK failed: rc = %d\n",
6411 mdt_obd_name(mdt), rc);
6414 rc = ld->ld_ops->ldo_recovery_complete(env, ld);
6418 static int mdt_obd_postrecov(struct obd_device *obd)
6423 rc = lu_env_init(&env, LCT_MD_THREAD);
6426 rc = mdt_postrecov(&env, mdt_dev(obd->obd_lu_dev));
6431 static struct obd_ops mdt_obd_device_ops = {
6432 .o_owner = THIS_MODULE,
6433 .o_set_info_async = mdt_obd_set_info_async,
6434 .o_connect = mdt_obd_connect,
6435 .o_reconnect = mdt_obd_reconnect,
6436 .o_disconnect = mdt_obd_disconnect,
6437 .o_init_export = mdt_init_export,
6438 .o_destroy_export = mdt_destroy_export,
6439 .o_iocontrol = mdt_iocontrol,
6440 .o_postrecov = mdt_obd_postrecov,
6441 /* Data-on-MDT IO methods */
6442 .o_preprw = mdt_obd_preprw,
6443 .o_commitrw = mdt_obd_commitrw,
6446 static struct lu_device* mdt_device_fini(const struct lu_env *env,
6447 struct lu_device *d)
6449 struct mdt_device *m = mdt_dev(d);
6456 static struct lu_device *mdt_device_free(const struct lu_env *env,
6457 struct lu_device *d)
6459 struct mdt_device *m = mdt_dev(d);
6462 lu_device_fini(&m->mdt_lu_dev);
6468 static struct lu_device *mdt_device_alloc(const struct lu_env *env,
6469 struct lu_device_type *t,
6470 struct lustre_cfg *cfg)
6472 struct lu_device *l;
6473 struct mdt_device *m;
6480 rc = mdt_init0(env, m, t, cfg);
6482 mdt_device_free(env, l);
6487 l = ERR_PTR(-ENOMEM);
6491 /* context key constructor/destructor: mdt_key_init, mdt_key_fini */
6492 LU_KEY_INIT(mdt, struct mdt_thread_info);
6494 static void mdt_key_fini(const struct lu_context *ctx,
6495 struct lu_context_key *key, void* data)
6497 struct mdt_thread_info *info = data;
6499 if (info->mti_big_lmm) {
6500 OBD_FREE_LARGE(info->mti_big_lmm, info->mti_big_lmmsize);
6501 info->mti_big_lmm = NULL;
6502 info->mti_big_lmmsize = 0;
6505 if (info->mti_big_acl) {
6506 OBD_FREE_LARGE(info->mti_big_acl, info->mti_big_aclsize);
6507 info->mti_big_acl = NULL;
6508 info->mti_big_aclsize = 0;
6514 /* context key: mdt_thread_key */
6515 LU_CONTEXT_KEY_DEFINE(mdt, LCT_MD_THREAD);
6517 struct lu_ucred *mdt_ucred(const struct mdt_thread_info *info)
6519 return lu_ucred(info->mti_env);
6522 struct lu_ucred *mdt_ucred_check(const struct mdt_thread_info *info)
6524 return lu_ucred_check(info->mti_env);
6528 * Enable/disable COS (Commit On Sharing).
6530 * Set/Clear the COS flag in mdt options.
6532 * \param mdt mdt device
6533 * \param val 0 disables COS, other values enable COS
6535 void mdt_enable_cos(struct mdt_device *mdt, int val)
6540 mdt->mdt_opts.mo_cos = !!val;
6541 rc = lu_env_init(&env, LCT_LOCAL);
6542 if (unlikely(rc != 0)) {
6543 CWARN("%s: lu_env initialization failed, cannot "
6544 "sync: rc = %d\n", mdt_obd_name(mdt), rc);
6547 mdt_device_sync(&env, mdt);
6552 * Check COS (Commit On Sharing) status.
6554 * Return COS flag status.
6556 * \param mdt mdt device
6558 int mdt_cos_is_enabled(struct mdt_device *mdt)
6560 return mdt->mdt_opts.mo_cos != 0;
6563 static struct lu_device_type_operations mdt_device_type_ops = {
6564 .ldto_device_alloc = mdt_device_alloc,
6565 .ldto_device_free = mdt_device_free,
6566 .ldto_device_fini = mdt_device_fini
6569 static struct lu_device_type mdt_device_type = {
6570 .ldt_tags = LU_DEVICE_MD,
6571 .ldt_name = LUSTRE_MDT_NAME,
6572 .ldt_ops = &mdt_device_type_ops,
6573 .ldt_ctx_tags = LCT_MD_THREAD
6576 static int __init mdt_init(void)
6580 CLASSERT(sizeof("0x0123456789ABCDEF:0x01234567:0x01234567") ==
6581 FID_NOBRACE_LEN + 1);
6582 CLASSERT(sizeof("[0x0123456789ABCDEF:0x01234567:0x01234567]") ==
6584 rc = lu_kmem_init(mdt_caches);
6588 rc = mds_mod_init();
6592 rc = class_register_type(&mdt_obd_device_ops, NULL, true, NULL,
6593 LUSTRE_MDT_NAME, &mdt_device_type);
6598 lu_kmem_fini(mdt_caches);
6605 static void __exit mdt_exit(void)
6607 class_unregister_type(LUSTRE_MDT_NAME);
6609 lu_kmem_fini(mdt_caches);
6612 MODULE_AUTHOR("OpenSFS, Inc. <http://www.lustre.org/>");
6613 MODULE_DESCRIPTION("Lustre Metadata Target ("LUSTRE_MDT_NAME")");
6614 MODULE_VERSION(LUSTRE_VERSION_STRING);
6615 MODULE_LICENSE("GPL");
6617 module_init(mdt_init);
6618 module_exit(mdt_exit);