4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
27 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2010, 2013, Intel Corporation.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * lustre/mdt/mdt_handler.c
38 * Lustre Metadata Target (mdt) request handler
40 * Author: Peter Braam <braam@clusterfs.com>
41 * Author: Andreas Dilger <adilger@clusterfs.com>
42 * Author: Phil Schwan <phil@clusterfs.com>
43 * Author: Mike Shaver <shaver@clusterfs.com>
44 * Author: Nikita Danilov <nikita@clusterfs.com>
45 * Author: Huang Hua <huanghua@clusterfs.com>
46 * Author: Yury Umanets <umka@clusterfs.com>
49 #define DEBUG_SUBSYSTEM S_MDS
51 #include <linux/module.h>
53 * struct OBD_{ALLOC,FREE}*()
55 #include <obd_support.h>
56 /* struct ptlrpc_request */
57 #include <lustre_net.h>
58 /* struct obd_export */
59 #include <lustre_export.h>
60 /* struct obd_device */
63 #include <dt_object.h>
64 #include <lustre_mds.h>
65 #include <lustre_mdt.h>
66 #include <lustre_log.h>
67 #include "mdt_internal.h"
68 #include <lustre_acl.h>
69 #include <lustre_param.h>
70 #include <lustre_quota.h>
71 #include <lustre_linkea.h>
73 mdl_mode_t mdt_mdl_lock_modes[] = {
74 [LCK_MINMODE] = MDL_MINMODE,
81 [LCK_GROUP] = MDL_GROUP
84 ldlm_mode_t mdt_dlm_lock_modes[] = {
85 [MDL_MINMODE] = LCK_MINMODE,
92 [MDL_GROUP] = LCK_GROUP
95 static struct mdt_device *mdt_dev(struct lu_device *d);
96 static int mdt_unpack_req_pack_rep(struct mdt_thread_info *info, __u32 flags);
98 static const struct lu_object_operations mdt_obj_ops;
100 /* Slab for MDT object allocation */
101 static cfs_mem_cache_t *mdt_object_kmem;
103 static struct lu_kmem_descr mdt_caches[] = {
105 .ckd_cache = &mdt_object_kmem,
106 .ckd_name = "mdt_obj",
107 .ckd_size = sizeof(struct mdt_object)
114 int mdt_get_disposition(struct ldlm_reply *rep, int flag)
118 return (rep->lock_policy_res1 & flag);
121 void mdt_clear_disposition(struct mdt_thread_info *info,
122 struct ldlm_reply *rep, int flag)
125 info->mti_opdata &= ~flag;
127 rep->lock_policy_res1 &= ~flag;
130 void mdt_set_disposition(struct mdt_thread_info *info,
131 struct ldlm_reply *rep, int flag)
134 info->mti_opdata |= flag;
136 rep->lock_policy_res1 |= flag;
139 void mdt_lock_reg_init(struct mdt_lock_handle *lh, ldlm_mode_t lm)
141 lh->mlh_pdo_hash = 0;
142 lh->mlh_reg_mode = lm;
143 lh->mlh_rreg_mode = lm;
144 lh->mlh_type = MDT_REG_LOCK;
147 void mdt_lock_pdo_init(struct mdt_lock_handle *lh, ldlm_mode_t lm,
148 const char *name, int namelen)
150 lh->mlh_reg_mode = lm;
151 lh->mlh_rreg_mode = lm;
152 lh->mlh_type = MDT_PDO_LOCK;
154 if (name != NULL && (name[0] != '\0')) {
155 LASSERT(namelen > 0);
156 lh->mlh_pdo_hash = full_name_hash(name, namelen);
157 /* XXX Workaround for LU-2856
158 * Zero is a valid return value of full_name_hash, but several
159 * users of mlh_pdo_hash assume a non-zero hash value. We
160 * therefore map zero onto an arbitrary, but consistent
161 * value (1) to avoid problems further down the road. */
162 if (unlikely(!lh->mlh_pdo_hash))
163 lh->mlh_pdo_hash = 1;
165 LASSERT(namelen == 0);
166 lh->mlh_pdo_hash = 0ull;
170 static void mdt_lock_pdo_mode(struct mdt_thread_info *info, struct mdt_object *o,
171 struct mdt_lock_handle *lh)
177 * Any dir access needs couple of locks:
179 * 1) on part of dir we gonna take lookup/modify;
181 * 2) on whole dir to protect it from concurrent splitting and/or to
182 * flush client's cache for readdir().
184 * so, for a given mode and object this routine decides what lock mode
185 * to use for lock #2:
187 * 1) if caller's gonna lookup in dir then we need to protect dir from
188 * being splitted only - LCK_CR
190 * 2) if caller's gonna modify dir then we need to protect dir from
191 * being splitted and to flush cache - LCK_CW
193 * 3) if caller's gonna modify dir and that dir seems ready for
194 * splitting then we need to protect it from any type of access
195 * (lookup/modify/split) - LCK_EX --bzzz
198 LASSERT(lh->mlh_reg_mode != LCK_MINMODE);
199 LASSERT(lh->mlh_pdo_mode == LCK_MINMODE);
202 * Ask underlaying level its opinion about preferable PDO lock mode
203 * having access type passed as regular lock mode:
205 * - MDL_MINMODE means that lower layer does not want to specify lock
208 * - MDL_NL means that no PDO lock should be taken. This is used in some
209 * cases. Say, for non-splittable directories no need to use PDO locks
212 mode = mdo_lock_mode(info->mti_env, mdt_object_child(o),
213 mdt_dlm_mode2mdl_mode(lh->mlh_reg_mode));
215 if (mode != MDL_MINMODE) {
216 lh->mlh_pdo_mode = mdt_mdl_mode2dlm_mode(mode);
219 * Lower layer does not want to specify locking mode. We do it
220 * our selves. No special protection is needed, just flush
221 * client's cache on modification and allow concurrent
224 switch (lh->mlh_reg_mode) {
226 lh->mlh_pdo_mode = LCK_EX;
229 lh->mlh_pdo_mode = LCK_CR;
232 lh->mlh_pdo_mode = LCK_CW;
235 CERROR("Not expected lock type (0x%x)\n",
236 (int)lh->mlh_reg_mode);
241 LASSERT(lh->mlh_pdo_mode != LCK_MINMODE);
245 int mdt_getstatus(struct mdt_thread_info *info)
247 struct mdt_device *mdt = info->mti_mdt;
248 struct mdt_body *repbody;
252 rc = mdt_check_ucred(info);
254 RETURN(err_serious(rc));
256 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_GETSTATUS_PACK))
257 RETURN(err_serious(-ENOMEM));
259 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
260 repbody->fid1 = mdt->mdt_md_root_fid;
261 repbody->valid |= OBD_MD_FLID;
263 if (mdt->mdt_opts.mo_mds_capa &&
264 exp_connect_flags(info->mti_exp) & OBD_CONNECT_MDS_CAPA) {
265 struct mdt_object *root;
266 struct lustre_capa *capa;
268 root = mdt_object_find(info->mti_env, mdt, &repbody->fid1);
270 RETURN(PTR_ERR(root));
272 capa = req_capsule_server_get(info->mti_pill, &RMF_CAPA1);
274 capa->lc_opc = CAPA_OPC_MDS_DEFAULT;
275 rc = mo_capa_get(info->mti_env, mdt_object_child(root), capa,
277 mdt_object_put(info->mti_env, root);
279 repbody->valid |= OBD_MD_FLMDSCAPA;
285 int mdt_statfs(struct mdt_thread_info *info)
287 struct ptlrpc_request *req = mdt_info_req(info);
288 struct md_device *next = info->mti_mdt->mdt_child;
289 struct ptlrpc_service_part *svcpt;
290 struct obd_statfs *osfs;
295 svcpt = info->mti_pill->rc_req->rq_rqbd->rqbd_svcpt;
297 /* This will trigger a watchdog timeout */
298 OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_STATFS_LCW_SLEEP,
299 (MDT_SERVICE_WATCHDOG_FACTOR *
300 at_get(&svcpt->scp_at_estimate)) + 1);
302 rc = mdt_check_ucred(info);
304 RETURN(err_serious(rc));
306 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_STATFS_PACK))
307 RETURN(err_serious(-ENOMEM));
309 osfs = req_capsule_server_get(info->mti_pill, &RMF_OBD_STATFS);
313 /** statfs information are cached in the mdt_device */
314 if (cfs_time_before_64(info->mti_mdt->mdt_osfs_age,
315 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS))) {
316 /** statfs data is too old, get up-to-date one */
317 rc = next->md_ops->mdo_statfs(info->mti_env, next, osfs);
320 spin_lock(&info->mti_mdt->mdt_osfs_lock);
321 info->mti_mdt->mdt_osfs = *osfs;
322 info->mti_mdt->mdt_osfs_age = cfs_time_current_64();
323 spin_unlock(&info->mti_mdt->mdt_osfs_lock);
325 /** use cached statfs data */
326 spin_lock(&info->mti_mdt->mdt_osfs_lock);
327 *osfs = info->mti_mdt->mdt_osfs;
328 spin_unlock(&info->mti_mdt->mdt_osfs_lock);
332 mdt_counter_incr(req, LPROC_MDT_STATFS);
338 * Pack SOM attributes into the reply.
339 * Call under a DLM UPDATE lock.
341 static void mdt_pack_size2body(struct mdt_thread_info *info,
342 struct mdt_object *mo)
345 struct md_attr *ma = &info->mti_attr;
347 LASSERT(ma->ma_attr.la_valid & LA_MODE);
348 b = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
350 /* Check if Size-on-MDS is supported, if this is a regular file,
351 * if SOM is enabled on the object and if SOM cache exists and valid.
352 * Otherwise do not pack Size-on-MDS attributes to the reply. */
353 if (!(mdt_conn_flags(info) & OBD_CONNECT_SOM) ||
354 !S_ISREG(ma->ma_attr.la_mode) ||
355 !mdt_object_is_som_enabled(mo) ||
356 !(ma->ma_valid & MA_SOM))
359 b->valid |= OBD_MD_FLSIZE | OBD_MD_FLBLOCKS;
360 b->size = ma->ma_som->msd_size;
361 b->blocks = ma->ma_som->msd_blocks;
364 void mdt_pack_attr2body(struct mdt_thread_info *info, struct mdt_body *b,
365 const struct lu_attr *attr, const struct lu_fid *fid)
367 struct md_attr *ma = &info->mti_attr;
369 LASSERT(ma->ma_valid & MA_INODE);
371 b->atime = attr->la_atime;
372 b->mtime = attr->la_mtime;
373 b->ctime = attr->la_ctime;
374 b->mode = attr->la_mode;
375 b->size = attr->la_size;
376 b->blocks = attr->la_blocks;
377 b->uid = attr->la_uid;
378 b->gid = attr->la_gid;
379 b->flags = attr->la_flags;
380 b->nlink = attr->la_nlink;
381 b->rdev = attr->la_rdev;
383 /*XXX should pack the reply body according to lu_valid*/
384 b->valid |= OBD_MD_FLCTIME | OBD_MD_FLUID |
385 OBD_MD_FLGID | OBD_MD_FLTYPE |
386 OBD_MD_FLMODE | OBD_MD_FLNLINK | OBD_MD_FLFLAGS |
387 OBD_MD_FLATIME | OBD_MD_FLMTIME ;
389 if (!S_ISREG(attr->la_mode)) {
390 b->valid |= OBD_MD_FLSIZE | OBD_MD_FLBLOCKS | OBD_MD_FLRDEV;
391 } else if (ma->ma_need & MA_LOV && !(ma->ma_valid & MA_LOV)) {
392 /* means no objects are allocated on osts. */
393 LASSERT(!(ma->ma_valid & MA_LOV));
394 /* just ignore blocks occupied by extend attributes on MDS */
396 /* if no object is allocated on osts, the size on mds is valid. b=22272 */
397 b->valid |= OBD_MD_FLSIZE | OBD_MD_FLBLOCKS;
402 b->valid |= OBD_MD_FLID;
403 CDEBUG(D_INODE, DFID": nlink=%d, mode=%o, size="LPU64"\n",
404 PFID(fid), b->nlink, b->mode, b->size);
408 mdt_body_reverse_idmap(info, b);
410 if (b->valid & OBD_MD_FLSIZE)
411 CDEBUG(D_VFSTRACE, DFID": returning size %llu\n",
412 PFID(fid), (unsigned long long)b->size);
415 static inline int mdt_body_has_lov(const struct lu_attr *la,
416 const struct mdt_body *body)
418 return ((S_ISREG(la->la_mode) && (body->valid & OBD_MD_FLEASIZE)) ||
419 (S_ISDIR(la->la_mode) && (body->valid & OBD_MD_FLDIREA )) );
422 void mdt_client_compatibility(struct mdt_thread_info *info)
424 struct mdt_body *body;
425 struct ptlrpc_request *req = mdt_info_req(info);
426 struct obd_export *exp = req->rq_export;
427 struct md_attr *ma = &info->mti_attr;
428 struct lu_attr *la = &ma->ma_attr;
431 if (exp_connect_layout(exp))
432 /* the client can deal with 16-bit lmm_stripe_count */
435 body = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
437 if (!mdt_body_has_lov(la, body))
440 /* now we have a reply with a lov for a client not compatible with the
441 * layout lock so we have to clean the layout generation number */
442 if (S_ISREG(la->la_mode))
443 ma->ma_lmm->lmm_layout_gen = 0;
447 static int mdt_big_xattr_get(struct mdt_thread_info *info, struct mdt_object *o,
450 const struct lu_env *env = info->mti_env;
454 LASSERT(info->mti_big_lmm_used == 0);
455 rc = mo_xattr_get(env, mdt_object_child(o), &LU_BUF_NULL, name);
459 /* big_lmm may need to be grown */
460 if (info->mti_big_lmmsize < rc) {
461 int size = size_roundup_power2(rc);
463 if (info->mti_big_lmmsize > 0) {
464 /* free old buffer */
465 LASSERT(info->mti_big_lmm);
466 OBD_FREE_LARGE(info->mti_big_lmm,
467 info->mti_big_lmmsize);
468 info->mti_big_lmm = NULL;
469 info->mti_big_lmmsize = 0;
472 OBD_ALLOC_LARGE(info->mti_big_lmm, size);
473 if (info->mti_big_lmm == NULL)
475 info->mti_big_lmmsize = size;
477 LASSERT(info->mti_big_lmmsize >= rc);
479 info->mti_buf.lb_buf = info->mti_big_lmm;
480 info->mti_buf.lb_len = info->mti_big_lmmsize;
481 rc = mo_xattr_get(env, mdt_object_child(o), &info->mti_buf, name);
486 int mdt_attr_get_lov(struct mdt_thread_info *info,
487 struct mdt_object *o, struct md_attr *ma)
489 struct md_object *next = mdt_object_child(o);
490 struct lu_buf *buf = &info->mti_buf;
493 buf->lb_buf = ma->ma_lmm;
494 buf->lb_len = ma->ma_lmm_size;
495 rc = mo_xattr_get(info->mti_env, next, buf, XATTR_NAME_LOV);
497 ma->ma_lmm_size = rc;
498 ma->ma_valid |= MA_LOV;
500 } else if (rc == -ENODATA) {
503 } else if (rc == -ERANGE) {
504 rc = mdt_big_xattr_get(info, o, XATTR_NAME_LOV);
506 info->mti_big_lmm_used = 1;
507 ma->ma_valid |= MA_LOV;
508 ma->ma_lmm = info->mti_big_lmm;
509 ma->ma_lmm_size = rc;
510 /* update mdt_max_mdsize so all clients
511 * will be aware about that */
512 if (info->mti_mdt->mdt_max_mdsize < rc)
513 info->mti_mdt->mdt_max_mdsize = rc;
521 int mdt_attr_get_pfid(struct mdt_thread_info *info,
522 struct mdt_object *o, struct lu_fid *pfid)
524 struct lu_buf *buf = &info->mti_buf;
525 struct link_ea_header *leh;
526 struct link_ea_entry *lee;
530 buf->lb_buf = info->mti_big_lmm;
531 buf->lb_len = info->mti_big_lmmsize;
532 rc = mo_xattr_get(info->mti_env, mdt_object_child(o),
533 buf, XATTR_NAME_LINK);
534 /* ignore errors, MA_PFID won't be set and it is
535 * up to the caller to treat this as an error */
536 if (rc == -ERANGE || buf->lb_len == 0) {
537 rc = mdt_big_xattr_get(info, o, XATTR_NAME_LINK);
538 buf->lb_buf = info->mti_big_lmm;
539 buf->lb_len = info->mti_big_lmmsize;
544 if (rc < sizeof(*leh)) {
545 CERROR("short LinkEA on "DFID": rc = %d\n",
546 PFID(mdt_object_fid(o)), rc);
550 leh = (struct link_ea_header *) buf->lb_buf;
551 lee = (struct link_ea_entry *)(leh + 1);
552 if (leh->leh_magic == __swab32(LINK_EA_MAGIC)) {
553 leh->leh_magic = LINK_EA_MAGIC;
554 leh->leh_reccount = __swab32(leh->leh_reccount);
555 leh->leh_len = __swab64(leh->leh_len);
557 if (leh->leh_magic != LINK_EA_MAGIC)
559 if (leh->leh_reccount == 0)
562 memcpy(pfid, &lee->lee_parent_fid, sizeof(*pfid));
563 fid_be_to_cpu(pfid, pfid);
568 int mdt_attr_get_complex(struct mdt_thread_info *info,
569 struct mdt_object *o, struct md_attr *ma)
571 const struct lu_env *env = info->mti_env;
572 struct md_object *next = mdt_object_child(o);
573 struct lu_buf *buf = &info->mti_buf;
574 u32 mode = lu_object_attr(&next->mo_lu);
575 int need = ma->ma_need;
581 if (need & MA_INODE) {
582 ma->ma_need = MA_INODE;
583 rc = mo_attr_get(env, next, ma);
586 ma->ma_valid |= MA_INODE;
589 if (need & MA_PFID) {
590 rc = mdt_attr_get_pfid(info, o, &ma->ma_pfid);
592 ma->ma_valid |= MA_PFID;
593 /* ignore this error, parent fid is not mandatory */
597 if (need & MA_LOV && (S_ISREG(mode) || S_ISDIR(mode))) {
598 rc = mdt_attr_get_lov(info, o, ma);
603 if (need & MA_LMV && S_ISDIR(mode)) {
604 buf->lb_buf = ma->ma_lmv;
605 buf->lb_len = ma->ma_lmv_size;
606 rc2 = mo_xattr_get(env, next, buf, XATTR_NAME_LMV);
608 ma->ma_lmv_size = rc2;
609 ma->ma_valid |= MA_LMV;
610 } else if (rc2 == -ENODATA) {
617 if (need & MA_SOM && S_ISREG(mode)) {
618 buf->lb_buf = info->mti_xattr_buf;
619 buf->lb_len = sizeof(info->mti_xattr_buf);
620 CLASSERT(sizeof(struct som_attrs) <=
621 sizeof(info->mti_xattr_buf));
622 rc2 = mo_xattr_get(info->mti_env, next, buf, XATTR_NAME_SOM);
623 rc2 = lustre_buf2som(info->mti_xattr_buf, rc2, ma->ma_som);
625 ma->ma_valid |= MA_SOM;
626 else if (rc2 < 0 && rc2 != -ENODATA)
630 if (need & MA_HSM && S_ISREG(mode)) {
631 buf->lb_buf = info->mti_xattr_buf;
632 buf->lb_len = sizeof(info->mti_xattr_buf);
633 CLASSERT(sizeof(struct hsm_attrs) <=
634 sizeof(info->mti_xattr_buf));
635 rc2 = mo_xattr_get(info->mti_env, next, buf, XATTR_NAME_HSM);
636 rc2 = lustre_buf2hsm(info->mti_xattr_buf, rc2, &ma->ma_hsm);
638 ma->ma_valid |= MA_HSM;
639 else if (rc2 < 0 && rc2 != -ENODATA)
643 #ifdef CONFIG_FS_POSIX_ACL
644 if (need & MA_ACL_DEF && S_ISDIR(mode)) {
645 buf->lb_buf = ma->ma_acl;
646 buf->lb_len = ma->ma_acl_size;
647 rc2 = mo_xattr_get(env, next, buf, XATTR_NAME_ACL_DEFAULT);
649 ma->ma_acl_size = rc2;
650 ma->ma_valid |= MA_ACL_DEF;
651 } else if (rc2 == -ENODATA) {
660 CDEBUG(D_INODE, "after getattr rc = %d, ma_valid = "LPX64" ma_lmm=%p\n",
661 rc, ma->ma_valid, ma->ma_lmm);
665 static int mdt_getattr_internal(struct mdt_thread_info *info,
666 struct mdt_object *o, int ma_need)
668 struct md_object *next = mdt_object_child(o);
669 const struct mdt_body *reqbody = info->mti_body;
670 struct ptlrpc_request *req = mdt_info_req(info);
671 struct md_attr *ma = &info->mti_attr;
672 struct lu_attr *la = &ma->ma_attr;
673 struct req_capsule *pill = info->mti_pill;
674 const struct lu_env *env = info->mti_env;
675 struct mdt_body *repbody;
676 struct lu_buf *buffer = &info->mti_buf;
681 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_GETATTR_PACK))
682 RETURN(err_serious(-ENOMEM));
684 repbody = req_capsule_server_get(pill, &RMF_MDT_BODY);
688 if (mdt_object_remote(o)) {
689 /* This object is located on remote node.*/
690 /* Return -EIO for old client */
691 if (!mdt_is_dne_client(req->rq_export))
692 GOTO(out, rc = -EIO);
694 repbody->fid1 = *mdt_object_fid(o);
695 repbody->valid = OBD_MD_FLID | OBD_MD_MDS;
699 buffer->lb_len = reqbody->eadatasize;
700 if (buffer->lb_len > 0)
701 buffer->lb_buf = req_capsule_server_get(pill, &RMF_MDT_MD);
703 buffer->lb_buf = NULL;
705 /* If it is dir object and client require MEA, then we got MEA */
706 if (S_ISDIR(lu_object_attr(&next->mo_lu)) &&
707 reqbody->valid & OBD_MD_MEA) {
708 /* Assumption: MDT_MD size is enough for lmv size. */
709 ma->ma_lmv = buffer->lb_buf;
710 ma->ma_lmv_size = buffer->lb_len;
711 ma->ma_need = MA_LMV | MA_INODE;
713 ma->ma_lmm = buffer->lb_buf;
714 ma->ma_lmm_size = buffer->lb_len;
715 ma->ma_need = MA_LOV | MA_INODE | MA_HSM;
718 if (S_ISDIR(lu_object_attr(&next->mo_lu)) &&
719 reqbody->valid & OBD_MD_FLDIREA &&
720 lustre_msg_get_opc(req->rq_reqmsg) == MDS_GETATTR) {
721 /* get default stripe info for this dir. */
722 ma->ma_need |= MA_LOV_DEF;
724 ma->ma_need |= ma_need;
725 if (ma->ma_need & MA_SOM)
726 ma->ma_som = &info->mti_u.som.data;
728 rc = mdt_attr_get_complex(info, o, ma);
730 CERROR("%s: getattr error for "DFID": rc = %d\n",
731 mdt_obd_name(info->mti_mdt),
732 PFID(mdt_object_fid(o)), rc);
736 is_root = lu_fid_eq(mdt_object_fid(o), &info->mti_mdt->mdt_md_root_fid);
738 /* the Lustre protocol supposes to return default striping
739 * on the user-visible root if explicitly requested */
740 if ((ma->ma_valid & MA_LOV) == 0 && S_ISDIR(la->la_mode) &&
741 (ma->ma_need & MA_LOV_DEF && is_root) && (ma->ma_need & MA_LOV)) {
742 struct lu_fid rootfid;
743 struct mdt_object *root;
744 struct mdt_device *mdt = info->mti_mdt;
746 rc = dt_root_get(env, mdt->mdt_bottom, &rootfid);
749 root = mdt_object_find(env, mdt, &rootfid);
751 RETURN(PTR_ERR(root));
752 rc = mdt_attr_get_lov(info, root, ma);
753 mdt_object_put(info->mti_env, root);
755 CERROR("%s: getattr error for "DFID": rc = %d\n",
756 mdt_obd_name(info->mti_mdt),
757 PFID(mdt_object_fid(o)), rc);
762 if (likely(ma->ma_valid & MA_INODE))
763 mdt_pack_attr2body(info, repbody, la, mdt_object_fid(o));
767 if (mdt_body_has_lov(la, reqbody)) {
768 if (ma->ma_valid & MA_LOV) {
769 LASSERT(ma->ma_lmm_size);
770 mdt_dump_lmm(D_INFO, ma->ma_lmm);
771 repbody->eadatasize = ma->ma_lmm_size;
772 if (S_ISDIR(la->la_mode))
773 repbody->valid |= OBD_MD_FLDIREA;
775 repbody->valid |= OBD_MD_FLEASIZE;
777 if (ma->ma_valid & MA_LMV) {
778 LASSERT(S_ISDIR(la->la_mode));
779 repbody->eadatasize = ma->ma_lmv_size;
780 repbody->valid |= (OBD_MD_FLDIREA|OBD_MD_MEA);
782 } else if (S_ISLNK(la->la_mode) &&
783 reqbody->valid & OBD_MD_LINKNAME) {
784 buffer->lb_buf = ma->ma_lmm;
785 /* eadatasize from client includes NULL-terminator, so
786 * there is no need to read it */
787 buffer->lb_len = reqbody->eadatasize - 1;
788 rc = mo_readlink(env, next, buffer);
789 if (unlikely(rc <= 0)) {
790 CERROR("%s: readlink failed for "DFID": rc = %d\n",
791 mdt_obd_name(info->mti_mdt),
792 PFID(mdt_object_fid(o)), rc);
795 int print_limit = min_t(int, CFS_PAGE_SIZE - 128, rc);
797 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_READLINK_EPROTO))
799 repbody->valid |= OBD_MD_LINKNAME;
800 /* we need to report back size with NULL-terminator
801 * because client expects that */
802 repbody->eadatasize = rc + 1;
803 if (repbody->eadatasize != reqbody->eadatasize)
804 CDEBUG(D_INODE, "%s: Read shorter symlink %d "
805 "on "DFID ", expected %d\n",
806 mdt_obd_name(info->mti_mdt),
807 rc, PFID(mdt_object_fid(o)),
808 reqbody->eadatasize - 1);
810 ((char *)ma->ma_lmm)[rc] = 0;
812 /* If the total CDEBUG() size is larger than a page, it
813 * will print a warning to the console, avoid this by
814 * printing just the last part of the symlink. */
815 CDEBUG(D_INODE, "symlink dest %s%.*s, len = %d\n",
816 print_limit < rc ? "..." : "", print_limit,
817 (char *)ma->ma_lmm + rc - print_limit, rc);
822 if (reqbody->valid & OBD_MD_FLMODEASIZE) {
823 repbody->max_cookiesize = 0;
824 repbody->max_mdsize = info->mti_mdt->mdt_max_mdsize;
825 repbody->valid |= OBD_MD_FLMODEASIZE;
826 CDEBUG(D_INODE, "I am going to change the MAX_MD_SIZE & "
827 "MAX_COOKIE to : %d:%d\n", repbody->max_mdsize,
828 repbody->max_cookiesize);
831 if (exp_connect_rmtclient(info->mti_exp) &&
832 reqbody->valid & OBD_MD_FLRMTPERM) {
833 void *buf = req_capsule_server_get(pill, &RMF_ACL);
835 /* mdt_getattr_lock only */
836 rc = mdt_pack_remote_perm(info, o, buf);
838 repbody->valid &= ~OBD_MD_FLRMTPERM;
839 repbody->aclsize = 0;
842 repbody->valid |= OBD_MD_FLRMTPERM;
843 repbody->aclsize = sizeof(struct mdt_remote_perm);
846 #ifdef CONFIG_FS_POSIX_ACL
847 else if ((exp_connect_flags(req->rq_export) & OBD_CONNECT_ACL) &&
848 (reqbody->valid & OBD_MD_FLACL)) {
849 buffer->lb_buf = req_capsule_server_get(pill, &RMF_ACL);
850 buffer->lb_len = req_capsule_get_size(pill,
851 &RMF_ACL, RCL_SERVER);
852 if (buffer->lb_len > 0) {
853 rc = mo_xattr_get(env, next, buffer,
854 XATTR_NAME_ACL_ACCESS);
856 if (rc == -ENODATA) {
857 repbody->aclsize = 0;
858 repbody->valid |= OBD_MD_FLACL;
860 } else if (rc == -EOPNOTSUPP) {
863 CERROR("%s: unable to read "DFID
865 mdt_obd_name(info->mti_mdt),
866 PFID(mdt_object_fid(o)), rc);
869 repbody->aclsize = rc;
870 repbody->valid |= OBD_MD_FLACL;
877 if (reqbody->valid & OBD_MD_FLMDSCAPA &&
878 info->mti_mdt->mdt_opts.mo_mds_capa &&
879 exp_connect_flags(info->mti_exp) & OBD_CONNECT_MDS_CAPA) {
880 struct lustre_capa *capa;
882 capa = req_capsule_server_get(pill, &RMF_CAPA1);
884 capa->lc_opc = CAPA_OPC_MDS_DEFAULT;
885 rc = mo_capa_get(env, next, capa, 0);
888 repbody->valid |= OBD_MD_FLMDSCAPA;
893 mdt_counter_incr(req, LPROC_MDT_GETATTR);
898 static int mdt_renew_capa(struct mdt_thread_info *info)
900 struct mdt_object *obj = info->mti_object;
901 struct mdt_body *body;
902 struct lustre_capa *capa, *c;
906 /* if object doesn't exist, or server has disabled capability,
907 * return directly, client will find body->valid OBD_MD_FLOSSCAPA
910 if (!obj || !info->mti_mdt->mdt_opts.mo_oss_capa ||
911 !(exp_connect_flags(info->mti_exp) & OBD_CONNECT_OSS_CAPA))
914 body = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
915 LASSERT(body != NULL);
917 c = req_capsule_client_get(info->mti_pill, &RMF_CAPA1);
920 capa = req_capsule_server_get(info->mti_pill, &RMF_CAPA2);
924 rc = mo_capa_get(info->mti_env, mdt_object_child(obj), capa, 1);
926 body->valid |= OBD_MD_FLOSSCAPA;
930 int mdt_getattr(struct mdt_thread_info *info)
932 struct mdt_object *obj = info->mti_object;
933 struct req_capsule *pill = info->mti_pill;
934 struct mdt_body *reqbody;
935 struct mdt_body *repbody;
940 reqbody = req_capsule_client_get(pill, &RMF_MDT_BODY);
943 if (reqbody->valid & OBD_MD_FLOSSCAPA) {
944 rc = req_capsule_server_pack(pill);
946 RETURN(err_serious(rc));
947 rc = mdt_renew_capa(info);
948 GOTO(out_shrink, rc);
951 LASSERT(obj != NULL);
952 LASSERT(lu_object_assert_exists(&obj->mot_obj.mo_lu));
954 mode = lu_object_attr(&obj->mot_obj.mo_lu);
956 /* old clients may not report needed easize, use max value then */
957 req_capsule_set_size(pill, &RMF_MDT_MD, RCL_SERVER,
958 reqbody->eadatasize == 0 ?
959 info->mti_mdt->mdt_max_mdsize :
960 reqbody->eadatasize);
962 rc = req_capsule_server_pack(pill);
963 if (unlikely(rc != 0))
964 RETURN(err_serious(rc));
966 repbody = req_capsule_server_get(pill, &RMF_MDT_BODY);
967 LASSERT(repbody != NULL);
968 repbody->eadatasize = 0;
969 repbody->aclsize = 0;
971 if (reqbody->valid & OBD_MD_FLRMTPERM)
972 rc = mdt_init_ucred(info, reqbody);
974 rc = mdt_check_ucred(info);
976 GOTO(out_shrink, rc);
978 info->mti_cross_ref = !!(reqbody->valid & OBD_MD_FLCROSSREF);
981 * Don't check capability at all, because rename might getattr for
982 * remote obj, and at that time no capability is available.
984 mdt_set_capainfo(info, 1, &reqbody->fid1, BYPASS_CAPA);
985 rc = mdt_getattr_internal(info, obj, 0);
986 if (reqbody->valid & OBD_MD_FLRMTPERM)
987 mdt_exit_ucred(info);
990 mdt_client_compatibility(info);
991 rc2 = mdt_fix_reply(info);
997 int mdt_is_subdir(struct mdt_thread_info *info)
999 struct mdt_object *o = info->mti_object;
1000 struct req_capsule *pill = info->mti_pill;
1001 const struct mdt_body *body = info->mti_body;
1002 struct mdt_body *repbody;
1008 repbody = req_capsule_server_get(pill, &RMF_MDT_BODY);
1011 * We save last checked parent fid to @repbody->fid1 for remote
1014 LASSERT(fid_is_sane(&body->fid2));
1015 LASSERT(mdt_object_exists(o) && !mdt_object_remote(o));
1016 rc = mdo_is_subdir(info->mti_env, mdt_object_child(o),
1017 &body->fid2, &repbody->fid1);
1018 if (rc == 0 || rc == -EREMOTE)
1019 repbody->valid |= OBD_MD_FLID;
1024 int mdt_swap_layouts(struct mdt_thread_info *info)
1026 struct ptlrpc_request *req = mdt_info_req(info);
1027 struct obd_export *exp = req->rq_export;
1028 struct mdt_object *o1, *o2, *o;
1029 struct mdt_lock_handle *lh1, *lh2;
1030 struct mdc_swap_layouts *msl;
1034 /* client does not support layout lock, so layout swaping
1036 * FIXME: there is a problem for old clients which don't support
1037 * layout lock yet. If those clients have already opened the file
1038 * they won't be notified at all so that old layout may still be
1039 * used to do IO. This can be fixed after file release is landed by
1040 * doing exclusive open and taking full EX ibits lock. - Jinshan */
1041 if (!exp_connect_layout(exp))
1042 RETURN(-EOPNOTSUPP);
1044 if (req_capsule_get_size(info->mti_pill, &RMF_CAPA1, RCL_CLIENT))
1045 mdt_set_capainfo(info, 0, &info->mti_body->fid1,
1046 req_capsule_client_get(info->mti_pill,
1049 if (req_capsule_get_size(info->mti_pill, &RMF_CAPA2, RCL_CLIENT))
1050 mdt_set_capainfo(info, 1, &info->mti_body->fid2,
1051 req_capsule_client_get(info->mti_pill,
1054 o1 = info->mti_object;
1055 o = o2 = mdt_object_find(info->mti_env, info->mti_mdt,
1056 &info->mti_body->fid2);
1058 GOTO(out, rc = PTR_ERR(o));
1060 if (mdt_object_remote(o) || !mdt_object_exists(o)) /* remote object */
1061 GOTO(put, rc = -ENOENT);
1063 rc = lu_fid_cmp(&info->mti_body->fid1, &info->mti_body->fid2);
1064 if (unlikely(rc == 0)) /* same file, you kidding me? no-op. */
1070 /* permission check. Make sure the calling process having permission
1071 * to write both files. */
1072 rc = mo_permission(info->mti_env, NULL, mdt_object_child(o1), NULL,
1077 rc = mo_permission(info->mti_env, NULL, mdt_object_child(o2), NULL,
1082 msl = req_capsule_client_get(info->mti_pill, &RMF_SWAP_LAYOUTS);
1084 GOTO(put, rc = -EPROTO);
1086 lh1 = &info->mti_lh[MDT_LH_NEW];
1087 mdt_lock_reg_init(lh1, LCK_EX);
1088 lh2 = &info->mti_lh[MDT_LH_OLD];
1089 mdt_lock_reg_init(lh2, LCK_EX);
1091 rc = mdt_object_lock(info, o1, lh1, MDS_INODELOCK_LAYOUT,
1096 rc = mdt_object_lock(info, o2, lh2, MDS_INODELOCK_LAYOUT,
1101 rc = mo_swap_layouts(info->mti_env, mdt_object_child(o1),
1102 mdt_object_child(o2), msl->msl_flags);
1105 mdt_object_unlock(info, o2, lh2, rc);
1107 mdt_object_unlock(info, o1, lh1, rc);
1109 mdt_object_put(info->mti_env, o);
1114 static int mdt_raw_lookup(struct mdt_thread_info *info,
1115 struct mdt_object *parent,
1116 const struct lu_name *lname,
1117 struct ldlm_reply *ldlm_rep)
1119 struct md_object *next = mdt_object_child(info->mti_object);
1120 const struct mdt_body *reqbody = info->mti_body;
1121 struct lu_fid *child_fid = &info->mti_tmp_fid1;
1122 struct mdt_body *repbody;
1126 if (reqbody->valid != OBD_MD_FLID)
1129 LASSERT(!info->mti_cross_ref);
1131 /* Only got the fid of this obj by name */
1132 fid_zero(child_fid);
1133 rc = mdo_lookup(info->mti_env, next, lname, child_fid,
1136 /* XXX is raw_lookup possible as intent operation? */
1139 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_NEG);
1142 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_POS);
1144 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
1147 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
1148 repbody->fid1 = *child_fid;
1149 repbody->valid = OBD_MD_FLID;
1155 * UPDATE lock should be taken against parent, and be release before exit;
1156 * child_bits lock should be taken against child, and be returned back:
1157 * (1)normal request should release the child lock;
1158 * (2)intent request will grant the lock to client.
1160 static int mdt_getattr_name_lock(struct mdt_thread_info *info,
1161 struct mdt_lock_handle *lhc,
1163 struct ldlm_reply *ldlm_rep)
1165 struct ptlrpc_request *req = mdt_info_req(info);
1166 struct mdt_body *reqbody = NULL;
1167 struct mdt_object *parent = info->mti_object;
1168 struct mdt_object *child;
1169 struct md_object *next = mdt_object_child(parent);
1170 struct lu_fid *child_fid = &info->mti_tmp_fid1;
1171 struct lu_name *lname = NULL;
1172 const char *name = NULL;
1174 struct mdt_lock_handle *lhp = NULL;
1175 struct ldlm_lock *lock;
1176 struct ldlm_res_id *res_id;
1183 is_resent = lustre_handle_is_used(&lhc->mlh_reg_lh);
1184 LASSERT(ergo(is_resent,
1185 lustre_msg_get_flags(req->rq_reqmsg) & MSG_RESENT));
1187 LASSERT(parent != NULL);
1188 name = req_capsule_client_get(info->mti_pill, &RMF_NAME);
1190 RETURN(err_serious(-EFAULT));
1192 namelen = req_capsule_get_size(info->mti_pill, &RMF_NAME,
1194 if (!info->mti_cross_ref) {
1196 * XXX: Check for "namelen == 0" is for getattr by fid
1197 * (OBD_CONNECT_ATTRFID), otherwise do not allow empty name,
1198 * that is the name must contain at least one character and
1199 * the terminating '\0'
1202 reqbody = req_capsule_client_get(info->mti_pill,
1204 if (unlikely(reqbody == NULL))
1205 RETURN(err_serious(-EFAULT));
1207 if (unlikely(!fid_is_sane(&reqbody->fid2)))
1208 RETURN(err_serious(-EINVAL));
1211 CDEBUG(D_INODE, "getattr with lock for "DFID"/"DFID", "
1213 PFID(mdt_object_fid(parent)),
1214 PFID(&reqbody->fid2), ldlm_rep);
1216 lname = mdt_name(info->mti_env, (char *)name, namelen);
1217 CDEBUG(D_INODE, "getattr with lock for "DFID"/%s, "
1218 "ldlm_rep = %p\n", PFID(mdt_object_fid(parent)),
1222 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_EXECD);
1224 if (unlikely(!mdt_object_exists(parent))) {
1225 LU_OBJECT_DEBUG(D_INODE, info->mti_env,
1226 &parent->mot_obj.mo_lu,
1227 "Parent doesn't exist!\n");
1229 } else if (!info->mti_cross_ref) {
1230 LASSERTF(!mdt_object_remote(parent),
1231 "Parent "DFID" is on remote server\n",
1232 PFID(mdt_object_fid(parent)));
1235 rc = mdt_raw_lookup(info, parent, lname, ldlm_rep);
1243 if (info->mti_cross_ref) {
1244 /* Only getattr on the child. Parent is on another node. */
1245 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_POS);
1247 CDEBUG(D_INODE, "partial getattr_name child_fid = "DFID", "
1248 "ldlm_rep=%p\n", PFID(mdt_object_fid(child)), ldlm_rep);
1251 /* Do not take lock for resent case. */
1252 lock = ldlm_handle2lock(&lhc->mlh_reg_lh);
1253 LASSERTF(lock != NULL, "Invalid lock handle "LPX64"\n",
1254 lhc->mlh_reg_lh.cookie);
1255 LASSERT(fid_res_name_eq(mdt_object_fid(child),
1256 &lock->l_resource->lr_name));
1257 LDLM_LOCK_PUT(lock);
1260 mdt_lock_handle_init(lhc);
1261 mdt_lock_reg_init(lhc, LCK_PR);
1264 * Object's name is on another MDS, no lookup lock is
1265 * needed here but update is.
1267 child_bits &= ~MDS_INODELOCK_LOOKUP;
1268 child_bits |= MDS_INODELOCK_PERM | MDS_INODELOCK_UPDATE;
1270 rc = mdt_object_lock(info, child, lhc, child_bits,
1274 /* Finally, we can get attr for child. */
1275 mdt_set_capainfo(info, 0, mdt_object_fid(child),
1277 rc = mdt_getattr_internal(info, child, 0);
1278 if (unlikely(rc != 0))
1279 mdt_object_unlock(info, child, lhc, 1);
1285 /* step 1: lock parent only if parent is a directory */
1286 if (S_ISDIR(lu_object_attr(&parent->mot_obj.mo_lu))) {
1287 lhp = &info->mti_lh[MDT_LH_PARENT];
1288 mdt_lock_pdo_init(lhp, LCK_PR, name, namelen);
1289 rc = mdt_object_lock(info, parent, lhp,
1290 MDS_INODELOCK_UPDATE,
1292 if (unlikely(rc != 0))
1296 /* step 2: lookup child's fid by name */
1297 fid_zero(child_fid);
1298 rc = mdo_lookup(info->mti_env, next, lname, child_fid,
1303 mdt_set_disposition(info, ldlm_rep,
1305 GOTO(out_parent, rc);
1307 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_POS);
1309 *child_fid = reqbody->fid2;
1310 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_POS);
1314 *step 3: find the child object by fid & lock it.
1315 * regardless if it is local or remote.
1317 child = mdt_object_find(info->mti_env, info->mti_mdt, child_fid);
1319 if (unlikely(IS_ERR(child)))
1320 GOTO(out_parent, rc = PTR_ERR(child));
1322 /* Do not take lock for resent case. */
1323 lock = ldlm_handle2lock(&lhc->mlh_reg_lh);
1324 LASSERTF(lock != NULL, "Invalid lock handle "LPX64"\n",
1325 lhc->mlh_reg_lh.cookie);
1327 res_id = &lock->l_resource->lr_name;
1328 if (!fid_res_name_eq(mdt_object_fid(child),
1329 &lock->l_resource->lr_name)) {
1330 LASSERTF(fid_res_name_eq(mdt_object_fid(parent),
1331 &lock->l_resource->lr_name),
1332 "Lock res_id: %lu/%lu/%lu, Fid: "DFID".\n",
1333 (unsigned long)res_id->name[0],
1334 (unsigned long)res_id->name[1],
1335 (unsigned long)res_id->name[2],
1336 PFID(mdt_object_fid(parent)));
1337 CWARN("Although resent, but still not get child lock"
1338 "parent:"DFID" child:"DFID"\n",
1339 PFID(mdt_object_fid(parent)),
1340 PFID(mdt_object_fid(child)));
1341 lustre_msg_clear_flags(req->rq_reqmsg, MSG_RESENT);
1342 LDLM_LOCK_PUT(lock);
1345 LDLM_LOCK_PUT(lock);
1348 bool try_layout = false;
1351 OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_RESEND, obd_timeout*2);
1352 mdt_lock_handle_init(lhc);
1353 mdt_lock_reg_init(lhc, LCK_PR);
1355 if (!mdt_object_exists(child)) {
1356 LU_OBJECT_DEBUG(D_INODE, info->mti_env,
1357 &child->mot_obj.mo_lu,
1358 "Object doesn't exist!\n");
1359 GOTO(out_child, rc = -ENOENT);
1362 if (!(child_bits & MDS_INODELOCK_UPDATE) &&
1363 mdt_object_exists(child) && !mdt_object_remote(child)) {
1364 struct md_attr *ma = &info->mti_attr;
1367 ma->ma_need = MA_INODE;
1368 rc = mdt_attr_get_complex(info, child, ma);
1369 if (unlikely(rc != 0))
1370 GOTO(out_child, rc);
1372 /* If the file has not been changed for some time, we
1373 * return not only a LOOKUP lock, but also an UPDATE
1374 * lock and this might save us RPC on later STAT. For
1375 * directories, it also let negative dentry starts
1376 * working for this dir. */
1377 if (ma->ma_valid & MA_INODE &&
1378 ma->ma_attr.la_valid & LA_CTIME &&
1379 info->mti_mdt->mdt_namespace->ns_ctime_age_limit +
1380 ma->ma_attr.la_ctime < cfs_time_current_sec())
1381 child_bits |= MDS_INODELOCK_UPDATE;
1384 /* layout lock must be granted in a best-effort way
1385 * for IT operations */
1386 LASSERT(!(child_bits & MDS_INODELOCK_LAYOUT));
1387 if (!OBD_FAIL_CHECK(OBD_FAIL_MDS_NO_LL_GETATTR) &&
1388 exp_connect_layout(info->mti_exp) &&
1389 S_ISREG(lu_object_attr(&child->mot_obj.mo_lu)) &&
1391 /* try to grant layout lock for regular file. */
1397 child_bits |= MDS_INODELOCK_LAYOUT;
1398 /* try layout lock, it may fail to be granted due to
1399 * contention at LOOKUP or UPDATE */
1400 if (!mdt_object_lock_try(info, child, lhc, child_bits,
1402 child_bits &= ~MDS_INODELOCK_LAYOUT;
1403 LASSERT(child_bits != 0);
1404 rc = mdt_object_lock(info, child, lhc,
1405 child_bits, MDT_CROSS_LOCK);
1410 rc = mdt_object_lock(info, child, lhc, child_bits,
1413 if (unlikely(rc != 0))
1414 GOTO(out_child, rc);
1417 lock = ldlm_handle2lock(&lhc->mlh_reg_lh);
1418 /* Get MA_SOM attributes if update lock is given. */
1420 lock->l_policy_data.l_inodebits.bits & MDS_INODELOCK_UPDATE &&
1421 S_ISREG(lu_object_attr(&mdt_object_child(child)->mo_lu)))
1424 /* finally, we can get attr for child. */
1425 mdt_set_capainfo(info, 1, child_fid, BYPASS_CAPA);
1426 rc = mdt_getattr_internal(info, child, ma_need);
1427 if (unlikely(rc != 0)) {
1428 mdt_object_unlock(info, child, lhc, 1);
1430 /* Debugging code. */
1431 res_id = &lock->l_resource->lr_name;
1432 LDLM_DEBUG(lock, "Returning lock to client");
1433 LASSERTF(fid_res_name_eq(mdt_object_fid(child),
1434 &lock->l_resource->lr_name),
1435 "Lock res_id: %lu/%lu/%lu, Fid: "DFID".\n",
1436 (unsigned long)res_id->name[0],
1437 (unsigned long)res_id->name[1],
1438 (unsigned long)res_id->name[2],
1439 PFID(mdt_object_fid(child)));
1440 if (mdt_object_exists(child) && !mdt_object_remote(child))
1441 mdt_pack_size2body(info, child);
1444 LDLM_LOCK_PUT(lock);
1448 mdt_object_put(info->mti_env, child);
1451 mdt_object_unlock(info, parent, lhp, 1);
1455 /* normal handler: should release the child lock */
1456 int mdt_getattr_name(struct mdt_thread_info *info)
1458 struct mdt_lock_handle *lhc = &info->mti_lh[MDT_LH_CHILD];
1459 struct mdt_body *reqbody;
1460 struct mdt_body *repbody;
1464 reqbody = req_capsule_client_get(info->mti_pill, &RMF_MDT_BODY);
1465 LASSERT(reqbody != NULL);
1466 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
1467 LASSERT(repbody != NULL);
1469 info->mti_cross_ref = !!(reqbody->valid & OBD_MD_FLCROSSREF);
1470 repbody->eadatasize = 0;
1471 repbody->aclsize = 0;
1473 rc = mdt_init_ucred(info, reqbody);
1475 GOTO(out_shrink, rc);
1477 rc = mdt_getattr_name_lock(info, lhc, MDS_INODELOCK_UPDATE, NULL);
1478 if (lustre_handle_is_used(&lhc->mlh_reg_lh)) {
1479 ldlm_lock_decref(&lhc->mlh_reg_lh, lhc->mlh_reg_mode);
1480 lhc->mlh_reg_lh.cookie = 0;
1482 mdt_exit_ucred(info);
1485 mdt_client_compatibility(info);
1486 rc2 = mdt_fix_reply(info);
1492 static int mdt_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
1493 void *karg, void *uarg);
1495 int mdt_set_info(struct mdt_thread_info *info)
1497 struct ptlrpc_request *req = mdt_info_req(info);
1500 int keylen, vallen, rc = 0;
1503 rc = req_capsule_server_pack(info->mti_pill);
1507 key = req_capsule_client_get(info->mti_pill, &RMF_SETINFO_KEY);
1509 DEBUG_REQ(D_HA, req, "no set_info key");
1513 keylen = req_capsule_get_size(info->mti_pill, &RMF_SETINFO_KEY,
1516 val = req_capsule_client_get(info->mti_pill, &RMF_SETINFO_VAL);
1518 DEBUG_REQ(D_HA, req, "no set_info val");
1522 vallen = req_capsule_get_size(info->mti_pill, &RMF_SETINFO_VAL,
1525 /* Swab any part of val you need to here */
1526 if (KEY_IS(KEY_READ_ONLY)) {
1528 lustre_msg_set_status(req->rq_repmsg, 0);
1530 spin_lock(&req->rq_export->exp_lock);
1532 *exp_connect_flags_ptr(req->rq_export) |=
1535 *exp_connect_flags_ptr(req->rq_export) &=
1536 ~OBD_CONNECT_RDONLY;
1537 spin_unlock(&req->rq_export->exp_lock);
1539 } else if (KEY_IS(KEY_CHANGELOG_CLEAR)) {
1540 struct changelog_setinfo *cs =
1541 (struct changelog_setinfo *)val;
1542 if (vallen != sizeof(*cs)) {
1543 CERROR("Bad changelog_clear setinfo size %d\n", vallen);
1546 if (ptlrpc_req_need_swab(req)) {
1547 __swab64s(&cs->cs_recno);
1548 __swab32s(&cs->cs_id);
1551 rc = mdt_iocontrol(OBD_IOC_CHANGELOG_CLEAR, info->mti_exp,
1553 lustre_msg_set_status(req->rq_repmsg, rc);
1562 * Top-level handler for MDT connection requests.
1564 int mdt_connect(struct mdt_thread_info *info)
1567 struct obd_connect_data *reply;
1568 struct obd_export *exp;
1569 struct ptlrpc_request *req = mdt_info_req(info);
1571 rc = target_handle_connect(req);
1573 return err_serious(rc);
1575 LASSERT(req->rq_export != NULL);
1576 info->mti_mdt = mdt_dev(req->rq_export->exp_obd->obd_lu_dev);
1577 rc = mdt_init_sec_level(info);
1579 obd_disconnect(class_export_get(req->rq_export));
1583 /* To avoid exposing partially initialized connection flags, changes up
1584 * to this point have been staged in reply->ocd_connect_flags. Now that
1585 * connection handling has completed successfully, atomically update
1586 * the connect flags in the shared export data structure. LU-1623 */
1587 reply = req_capsule_server_get(info->mti_pill, &RMF_CONNECT_DATA);
1588 exp = req->rq_export;
1589 spin_lock(&exp->exp_lock);
1590 *exp_connect_flags_ptr(exp) = reply->ocd_connect_flags;
1591 spin_unlock(&exp->exp_lock);
1593 rc = mdt_init_idmap(info);
1595 obd_disconnect(class_export_get(req->rq_export));
1600 int mdt_disconnect(struct mdt_thread_info *info)
1605 rc = target_handle_disconnect(mdt_info_req(info));
1607 rc = err_serious(rc);
1611 static int mdt_sendpage(struct mdt_thread_info *info,
1612 struct lu_rdpg *rdpg, int nob)
1614 struct ptlrpc_request *req = mdt_info_req(info);
1615 struct obd_export *exp = req->rq_export;
1616 struct ptlrpc_bulk_desc *desc;
1617 struct l_wait_info *lwi = &info->mti_u.rdpg.mti_wait_info;
1624 desc = ptlrpc_prep_bulk_exp(req, rdpg->rp_npages, 1, BULK_PUT_SOURCE,
1629 if (!(exp_connect_flags(exp) & OBD_CONNECT_BRW_SIZE))
1630 /* old client requires reply size in it's PAGE_SIZE,
1631 * which is rdpg->rp_count */
1632 nob = rdpg->rp_count;
1634 for (i = 0, tmpcount = nob; i < rdpg->rp_npages && tmpcount > 0;
1635 i++, tmpcount -= tmpsize) {
1636 tmpsize = min_t(int, tmpcount, CFS_PAGE_SIZE);
1637 ptlrpc_prep_bulk_page_pin(desc, rdpg->rp_pages[i], 0, tmpsize);
1640 LASSERT(desc->bd_nob == nob);
1641 rc = target_bulk_io(exp, desc, lwi);
1642 ptlrpc_free_bulk_pin(desc);
1646 int mdt_readpage(struct mdt_thread_info *info)
1648 struct mdt_object *object = info->mti_object;
1649 struct lu_rdpg *rdpg = &info->mti_u.rdpg.mti_rdpg;
1650 struct mdt_body *reqbody;
1651 struct mdt_body *repbody;
1656 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_READPAGE_PACK))
1657 RETURN(err_serious(-ENOMEM));
1659 reqbody = req_capsule_client_get(info->mti_pill, &RMF_MDT_BODY);
1660 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
1661 if (reqbody == NULL || repbody == NULL)
1662 RETURN(err_serious(-EFAULT));
1665 * prepare @rdpg before calling lower layers and transfer itself. Here
1666 * reqbody->size contains offset of where to start to read and
1667 * reqbody->nlink contains number bytes to read.
1669 rdpg->rp_hash = reqbody->size;
1670 if (rdpg->rp_hash != reqbody->size) {
1671 CERROR("Invalid hash: "LPX64" != "LPX64"\n",
1672 rdpg->rp_hash, reqbody->size);
1676 rdpg->rp_attrs = reqbody->mode;
1677 if (exp_connect_flags(info->mti_exp) & OBD_CONNECT_64BITHASH)
1678 rdpg->rp_attrs |= LUDA_64BITHASH;
1679 rdpg->rp_count = min_t(unsigned int, reqbody->nlink,
1680 exp_max_brw_size(info->mti_exp));
1681 rdpg->rp_npages = (rdpg->rp_count + CFS_PAGE_SIZE - 1) >>
1683 OBD_ALLOC(rdpg->rp_pages, rdpg->rp_npages * sizeof rdpg->rp_pages[0]);
1684 if (rdpg->rp_pages == NULL)
1687 for (i = 0; i < rdpg->rp_npages; ++i) {
1688 rdpg->rp_pages[i] = cfs_alloc_page(CFS_ALLOC_STD);
1689 if (rdpg->rp_pages[i] == NULL)
1690 GOTO(free_rdpg, rc = -ENOMEM);
1693 /* call lower layers to fill allocated pages with directory data */
1694 rc = mo_readpage(info->mti_env, mdt_object_child(object), rdpg);
1696 GOTO(free_rdpg, rc);
1698 /* send pages to client */
1699 rc = mdt_sendpage(info, rdpg, rc);
1704 for (i = 0; i < rdpg->rp_npages; i++)
1705 if (rdpg->rp_pages[i] != NULL)
1706 cfs_free_page(rdpg->rp_pages[i]);
1707 OBD_FREE(rdpg->rp_pages, rdpg->rp_npages * sizeof rdpg->rp_pages[0]);
1709 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_SENDPAGE))
1715 static int mdt_reint_internal(struct mdt_thread_info *info,
1716 struct mdt_lock_handle *lhc,
1719 struct req_capsule *pill = info->mti_pill;
1720 struct mdt_body *repbody;
1725 rc = mdt_reint_unpack(info, op);
1727 CERROR("Can't unpack reint, rc %d\n", rc);
1728 RETURN(err_serious(rc));
1731 /* for replay (no_create) lmm is not needed, client has it already */
1732 if (req_capsule_has_field(pill, &RMF_MDT_MD, RCL_SERVER))
1733 req_capsule_set_size(pill, &RMF_MDT_MD, RCL_SERVER,
1734 info->mti_rr.rr_eadatalen);
1736 /* llog cookies are always 0, the field is kept for compatibility */
1737 if (req_capsule_has_field(pill, &RMF_LOGCOOKIES, RCL_SERVER))
1738 req_capsule_set_size(pill, &RMF_LOGCOOKIES, RCL_SERVER, 0);
1740 rc = req_capsule_server_pack(pill);
1742 CERROR("Can't pack response, rc %d\n", rc);
1743 RETURN(err_serious(rc));
1746 if (req_capsule_has_field(pill, &RMF_MDT_BODY, RCL_SERVER)) {
1747 repbody = req_capsule_server_get(pill, &RMF_MDT_BODY);
1749 repbody->eadatasize = 0;
1750 repbody->aclsize = 0;
1753 OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_REINT_DELAY, 10);
1755 /* for replay no cookkie / lmm need, because client have this already */
1756 if (info->mti_spec.no_create)
1757 if (req_capsule_has_field(pill, &RMF_MDT_MD, RCL_SERVER))
1758 req_capsule_set_size(pill, &RMF_MDT_MD, RCL_SERVER, 0);
1760 rc = mdt_init_ucred_reint(info);
1762 GOTO(out_shrink, rc);
1764 rc = mdt_fix_attr_ucred(info, op);
1766 GOTO(out_ucred, rc = err_serious(rc));
1768 if (mdt_check_resent(info, mdt_reconstruct, lhc)) {
1769 rc = lustre_msg_get_status(mdt_info_req(info)->rq_repmsg);
1770 GOTO(out_ucred, rc);
1772 rc = mdt_reint_rec(info, lhc);
1775 mdt_exit_ucred(info);
1777 mdt_client_compatibility(info);
1778 rc2 = mdt_fix_reply(info);
1784 static long mdt_reint_opcode(struct mdt_thread_info *info,
1785 const struct req_format **fmt)
1787 struct mdt_rec_reint *rec;
1790 rec = req_capsule_client_get(info->mti_pill, &RMF_REC_REINT);
1792 opc = rec->rr_opcode;
1793 DEBUG_REQ(D_INODE, mdt_info_req(info), "reint opt = %ld", opc);
1794 if (opc < REINT_MAX && fmt[opc] != NULL)
1795 req_capsule_extend(info->mti_pill, fmt[opc]);
1797 CERROR("%s: Unsupported opcode '%ld' from client '%s': "
1798 "rc = %d\n", mdt_obd_name(info->mti_mdt), opc,
1799 info->mti_mdt->mdt_ldlm_client->cli_name,
1801 opc = err_serious(-EFAULT);
1804 opc = err_serious(-EFAULT);
1809 int mdt_reint(struct mdt_thread_info *info)
1814 static const struct req_format *reint_fmts[REINT_MAX] = {
1815 [REINT_SETATTR] = &RQF_MDS_REINT_SETATTR,
1816 [REINT_CREATE] = &RQF_MDS_REINT_CREATE,
1817 [REINT_LINK] = &RQF_MDS_REINT_LINK,
1818 [REINT_UNLINK] = &RQF_MDS_REINT_UNLINK,
1819 [REINT_RENAME] = &RQF_MDS_REINT_RENAME,
1820 [REINT_OPEN] = &RQF_MDS_REINT_OPEN,
1821 [REINT_SETXATTR] = &RQF_MDS_REINT_SETXATTR,
1822 [REINT_RMENTRY] = &RQF_MDS_REINT_UNLINK
1827 opc = mdt_reint_opcode(info, reint_fmts);
1830 * No lock possible here from client to pass it to reint code
1833 rc = mdt_reint_internal(info, NULL, opc);
1838 info->mti_fail_id = OBD_FAIL_MDS_REINT_NET_REP;
1842 /* this should sync the whole device */
1843 static int mdt_device_sync(const struct lu_env *env, struct mdt_device *mdt)
1845 struct dt_device *dt = mdt->mdt_bottom;
1849 rc = dt->dd_ops->dt_sync(env, dt);
1853 /* this should sync this object */
1854 static int mdt_object_sync(struct mdt_thread_info *info)
1856 struct md_object *next;
1860 if (!mdt_object_exists(info->mti_object)) {
1861 CWARN("Non existing object "DFID"!\n",
1862 PFID(mdt_object_fid(info->mti_object)));
1865 next = mdt_object_child(info->mti_object);
1866 rc = mo_object_sync(info->mti_env, next);
1871 int mdt_sync(struct mdt_thread_info *info)
1873 struct ptlrpc_request *req = mdt_info_req(info);
1874 struct req_capsule *pill = info->mti_pill;
1875 struct mdt_body *body;
1879 /* The fid may be zero, so we req_capsule_set manually */
1880 req_capsule_set(pill, &RQF_MDS_SYNC);
1882 body = req_capsule_client_get(pill, &RMF_MDT_BODY);
1884 RETURN(err_serious(-EINVAL));
1886 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_SYNC_PACK))
1887 RETURN(err_serious(-ENOMEM));
1889 if (fid_seq(&body->fid1) == 0) {
1890 /* sync the whole device */
1891 rc = req_capsule_server_pack(pill);
1893 rc = mdt_device_sync(info->mti_env, info->mti_mdt);
1895 rc = err_serious(rc);
1897 /* sync an object */
1898 rc = mdt_unpack_req_pack_rep(info, HABEO_CORPUS|HABEO_REFERO);
1900 rc = mdt_object_sync(info);
1902 const struct lu_fid *fid;
1903 struct lu_attr *la = &info->mti_attr.ma_attr;
1905 info->mti_attr.ma_need = MA_INODE;
1906 info->mti_attr.ma_valid = 0;
1907 rc = mdt_attr_get_complex(info, info->mti_object,
1910 body = req_capsule_server_get(pill,
1912 fid = mdt_object_fid(info->mti_object);
1913 mdt_pack_attr2body(info, body, la, fid);
1917 rc = err_serious(rc);
1920 mdt_counter_incr(req, LPROC_MDT_SYNC);
1926 * Quotacheck handler.
1927 * in-kernel quotacheck isn't supported any more.
1929 int mdt_quotacheck(struct mdt_thread_info *info)
1931 struct obd_quotactl *oqctl;
1935 oqctl = req_capsule_client_get(info->mti_pill, &RMF_OBD_QUOTACTL);
1937 RETURN(err_serious(-EPROTO));
1939 rc = req_capsule_server_pack(info->mti_pill);
1941 RETURN(err_serious(rc));
1943 /* deprecated, not used any more */
1944 RETURN(-EOPNOTSUPP);
1948 * Handle quota control requests to consult current usage/limit, but also
1949 * to configure quota enforcement
1951 int mdt_quotactl(struct mdt_thread_info *info)
1953 struct obd_export *exp = info->mti_exp;
1954 struct req_capsule *pill = info->mti_pill;
1955 struct obd_quotactl *oqctl, *repoqc;
1957 struct lu_device *qmt = info->mti_mdt->mdt_qmt_dev;
1960 oqctl = req_capsule_client_get(pill, &RMF_OBD_QUOTACTL);
1962 RETURN(err_serious(-EPROTO));
1964 rc = req_capsule_server_pack(pill);
1966 RETURN(err_serious(rc));
1968 switch (oqctl->qc_cmd) {
1970 case LUSTRE_Q_INVALIDATE:
1971 case LUSTRE_Q_FINVALIDATE:
1975 /* deprecated, not used any more */
1976 RETURN(-EOPNOTSUPP);
1977 /* master quotactl */
1983 RETURN(-EOPNOTSUPP);
1984 /* slave quotactl */
1989 CERROR("Unsupported quotactl command: %d\n", oqctl->qc_cmd);
1993 /* map uid/gid for remote client */
1995 if (exp_connect_rmtclient(exp)) {
1996 struct lustre_idmap_table *idmap;
1998 idmap = mdt_req2med(mdt_info_req(info))->med_idmap;
2000 if (unlikely(oqctl->qc_cmd != Q_GETQUOTA &&
2001 oqctl->qc_cmd != Q_GETINFO))
2004 if (oqctl->qc_type == USRQUOTA)
2005 id = lustre_idmap_lookup_uid(NULL, idmap, 0,
2007 else if (oqctl->qc_type == GRPQUOTA)
2008 id = lustre_idmap_lookup_gid(NULL, idmap, 0,
2013 if (id == CFS_IDMAP_NOTFOUND) {
2014 CDEBUG(D_QUOTA, "no mapping for id %u\n", oqctl->qc_id);
2019 repoqc = req_capsule_server_get(pill, &RMF_OBD_QUOTACTL);
2021 RETURN(err_serious(-EFAULT));
2023 if (oqctl->qc_id != id)
2024 swap(oqctl->qc_id, id);
2026 switch (oqctl->qc_cmd) {
2032 /* forward quotactl request to QMT */
2033 rc = qmt_hdls.qmth_quotactl(info->mti_env, qmt, oqctl);
2038 /* slave quotactl */
2039 rc = lquotactl_slv(info->mti_env, info->mti_mdt->mdt_bottom,
2044 CERROR("Unsupported quotactl command: %d\n", oqctl->qc_cmd);
2048 if (oqctl->qc_id != id)
2049 swap(oqctl->qc_id, id);
2056 * OBD PING and other handlers.
2058 int mdt_obd_ping(struct mdt_thread_info *info)
2063 req_capsule_set(info->mti_pill, &RQF_OBD_PING);
2065 rc = target_handle_ping(mdt_info_req(info));
2067 rc = err_serious(rc);
2072 * OBD_IDX_READ handler
2074 int mdt_obd_idx_read(struct mdt_thread_info *info)
2076 struct mdt_device *mdt = info->mti_mdt;
2077 struct lu_rdpg *rdpg = &info->mti_u.rdpg.mti_rdpg;
2078 struct idx_info *req_ii, *rep_ii;
2082 memset(rdpg, 0, sizeof(*rdpg));
2083 req_capsule_set(info->mti_pill, &RQF_OBD_IDX_READ);
2085 /* extract idx_info buffer from request & reply */
2086 req_ii = req_capsule_client_get(info->mti_pill, &RMF_IDX_INFO);
2087 if (req_ii == NULL || req_ii->ii_magic != IDX_INFO_MAGIC)
2088 RETURN(err_serious(-EPROTO));
2090 rc = req_capsule_server_pack(info->mti_pill);
2092 RETURN(err_serious(rc));
2094 rep_ii = req_capsule_server_get(info->mti_pill, &RMF_IDX_INFO);
2096 RETURN(err_serious(-EFAULT));
2097 rep_ii->ii_magic = IDX_INFO_MAGIC;
2099 /* extract hash to start with */
2100 rdpg->rp_hash = req_ii->ii_hash_start;
2102 /* extract requested attributes */
2103 rdpg->rp_attrs = req_ii->ii_attrs;
2105 /* check that fid packed in request is valid and supported */
2106 if (!fid_is_sane(&req_ii->ii_fid))
2108 rep_ii->ii_fid = req_ii->ii_fid;
2111 rep_ii->ii_flags = req_ii->ii_flags;
2113 /* compute number of pages to allocate, ii_count is the number of 4KB
2115 if (req_ii->ii_count <= 0)
2116 GOTO(out, rc = -EFAULT);
2117 rdpg->rp_count = min_t(unsigned int, req_ii->ii_count << LU_PAGE_SHIFT,
2118 exp_max_brw_size(info->mti_exp));
2119 rdpg->rp_npages = (rdpg->rp_count + CFS_PAGE_SIZE -1) >> CFS_PAGE_SHIFT;
2121 /* allocate pages to store the containers */
2122 OBD_ALLOC(rdpg->rp_pages, rdpg->rp_npages * sizeof(rdpg->rp_pages[0]));
2123 if (rdpg->rp_pages == NULL)
2124 GOTO(out, rc = -ENOMEM);
2125 for (i = 0; i < rdpg->rp_npages; i++) {
2126 rdpg->rp_pages[i] = cfs_alloc_page(CFS_ALLOC_STD);
2127 if (rdpg->rp_pages[i] == NULL)
2128 GOTO(out, rc = -ENOMEM);
2131 /* populate pages with key/record pairs */
2132 rc = dt_index_read(info->mti_env, mdt->mdt_bottom, rep_ii, rdpg);
2136 LASSERTF(rc <= rdpg->rp_count, "dt_index_read() returned more than "
2137 "asked %d > %d\n", rc, rdpg->rp_count);
2139 /* send pages to client */
2140 rc = mdt_sendpage(info, rdpg, rc);
2144 if (rdpg->rp_pages) {
2145 for (i = 0; i < rdpg->rp_npages; i++)
2146 if (rdpg->rp_pages[i])
2147 cfs_free_page(rdpg->rp_pages[i]);
2148 OBD_FREE(rdpg->rp_pages,
2149 rdpg->rp_npages * sizeof(rdpg->rp_pages[0]));
2154 int mdt_obd_log_cancel(struct mdt_thread_info *info)
2156 return err_serious(-EOPNOTSUPP);
2159 int mdt_obd_qc_callback(struct mdt_thread_info *info)
2161 return err_serious(-EOPNOTSUPP);
2168 /** clone llog ctxt from child (mdd)
2169 * This allows remote llog (replicator) access.
2170 * We can either pass all llog RPCs (eg mdt_llog_create) on to child where the
2171 * context was originally set up, or we can handle them directly.
2172 * I choose the latter, but that means I need any llog
2173 * contexts set up by child to be accessable by the mdt. So we clone the
2174 * context into our context list here.
2176 static int mdt_llog_ctxt_clone(const struct lu_env *env, struct mdt_device *mdt,
2179 struct md_device *next = mdt->mdt_child;
2180 struct llog_ctxt *ctxt;
2183 if (!llog_ctxt_null(mdt2obd_dev(mdt), idx))
2186 rc = next->md_ops->mdo_llog_ctxt_get(env, next, idx, (void **)&ctxt);
2187 if (rc || ctxt == NULL) {
2191 rc = llog_group_set_ctxt(&mdt2obd_dev(mdt)->obd_olg, ctxt, idx);
2193 CERROR("Can't set mdt ctxt %d\n", rc);
2198 static int mdt_llog_ctxt_unclone(const struct lu_env *env,
2199 struct mdt_device *mdt, int idx)
2201 struct llog_ctxt *ctxt;
2203 ctxt = llog_get_context(mdt2obd_dev(mdt), idx);
2206 /* Put once for the get we just did, and once for the clone */
2207 llog_ctxt_put(ctxt);
2208 llog_ctxt_put(ctxt);
2212 int mdt_llog_create(struct mdt_thread_info *info)
2216 req_capsule_set(info->mti_pill, &RQF_LLOG_ORIGIN_HANDLE_CREATE);
2217 rc = llog_origin_handle_open(mdt_info_req(info));
2218 return (rc < 0 ? err_serious(rc) : rc);
2221 int mdt_llog_destroy(struct mdt_thread_info *info)
2225 req_capsule_set(info->mti_pill, &RQF_LLOG_ORIGIN_HANDLE_DESTROY);
2226 rc = llog_origin_handle_destroy(mdt_info_req(info));
2227 return (rc < 0 ? err_serious(rc) : rc);
2230 int mdt_llog_read_header(struct mdt_thread_info *info)
2234 req_capsule_set(info->mti_pill, &RQF_LLOG_ORIGIN_HANDLE_READ_HEADER);
2235 rc = llog_origin_handle_read_header(mdt_info_req(info));
2236 return (rc < 0 ? err_serious(rc) : rc);
2239 int mdt_llog_next_block(struct mdt_thread_info *info)
2243 req_capsule_set(info->mti_pill, &RQF_LLOG_ORIGIN_HANDLE_NEXT_BLOCK);
2244 rc = llog_origin_handle_next_block(mdt_info_req(info));
2245 return (rc < 0 ? err_serious(rc) : rc);
2248 int mdt_llog_prev_block(struct mdt_thread_info *info)
2252 req_capsule_set(info->mti_pill, &RQF_LLOG_ORIGIN_HANDLE_PREV_BLOCK);
2253 rc = llog_origin_handle_prev_block(mdt_info_req(info));
2254 return (rc < 0 ? err_serious(rc) : rc);
2262 static struct ldlm_callback_suite cbs = {
2263 .lcs_completion = ldlm_server_completion_ast,
2264 .lcs_blocking = ldlm_server_blocking_ast,
2265 .lcs_glimpse = ldlm_server_glimpse_ast
2268 int mdt_enqueue(struct mdt_thread_info *info)
2270 struct ptlrpc_request *req;
2274 * info->mti_dlm_req already contains swapped and (if necessary)
2275 * converted dlm request.
2277 LASSERT(info->mti_dlm_req != NULL);
2279 req = mdt_info_req(info);
2280 rc = ldlm_handle_enqueue0(info->mti_mdt->mdt_namespace,
2281 req, info->mti_dlm_req, &cbs);
2282 info->mti_fail_id = OBD_FAIL_LDLM_REPLY;
2283 return rc ? err_serious(rc) : req->rq_status;
2286 int mdt_convert(struct mdt_thread_info *info)
2289 struct ptlrpc_request *req;
2291 LASSERT(info->mti_dlm_req);
2292 req = mdt_info_req(info);
2293 rc = ldlm_handle_convert0(req, info->mti_dlm_req);
2294 return rc ? err_serious(rc) : req->rq_status;
2297 int mdt_bl_callback(struct mdt_thread_info *info)
2299 CERROR("bl callbacks should not happen on MDS\n");
2301 return err_serious(-EOPNOTSUPP);
2304 int mdt_cp_callback(struct mdt_thread_info *info)
2306 CERROR("cp callbacks should not happen on MDS\n");
2308 return err_serious(-EOPNOTSUPP);
2312 * sec context handlers
2314 int mdt_sec_ctx_handle(struct mdt_thread_info *info)
2318 rc = mdt_handle_idmap(info);
2321 struct ptlrpc_request *req = mdt_info_req(info);
2324 opc = lustre_msg_get_opc(req->rq_reqmsg);
2325 if (opc == SEC_CTX_INIT || opc == SEC_CTX_INIT_CONT)
2326 sptlrpc_svc_ctx_invalidate(req);
2329 CFS_FAIL_TIMEOUT(OBD_FAIL_SEC_CTX_HDL_PAUSE, cfs_fail_val);
2335 * quota request handlers
2337 int mdt_quota_dqacq(struct mdt_thread_info *info)
2339 struct lu_device *qmt = info->mti_mdt->mdt_qmt_dev;
2344 RETURN(err_serious(-EOPNOTSUPP));
2346 rc = qmt_hdls.qmth_dqacq(info->mti_env, qmt, mdt_info_req(info));
2350 static struct mdt_object *mdt_obj(struct lu_object *o)
2352 LASSERT(lu_device_is_mdt(o->lo_dev));
2353 return container_of0(o, struct mdt_object, mot_obj.mo_lu);
2356 struct mdt_object *mdt_object_new(const struct lu_env *env,
2357 struct mdt_device *d,
2358 const struct lu_fid *f)
2360 struct lu_object_conf conf = { .loc_flags = LOC_F_NEW };
2361 struct lu_object *o;
2362 struct mdt_object *m;
2365 CDEBUG(D_INFO, "Allocate object for "DFID"\n", PFID(f));
2366 o = lu_object_find(env, &d->mdt_md_dev.md_lu_dev, f, &conf);
2367 if (unlikely(IS_ERR(o)))
2368 m = (struct mdt_object *)o;
2374 struct mdt_object *mdt_object_find(const struct lu_env *env,
2375 struct mdt_device *d,
2376 const struct lu_fid *f)
2378 struct lu_object *o;
2379 struct mdt_object *m;
2382 CDEBUG(D_INFO, "Find object for "DFID"\n", PFID(f));
2383 o = lu_object_find(env, &d->mdt_md_dev.md_lu_dev, f, NULL);
2384 if (unlikely(IS_ERR(o)))
2385 m = (struct mdt_object *)o;
2392 * Asyncronous commit for mdt device.
2394 * Pass asynchonous commit call down the MDS stack.
2396 * \param env environment
2397 * \param mdt the mdt device
2399 static void mdt_device_commit_async(const struct lu_env *env,
2400 struct mdt_device *mdt)
2402 struct dt_device *dt = mdt->mdt_bottom;
2405 rc = dt->dd_ops->dt_commit_async(env, dt);
2406 if (unlikely(rc != 0))
2407 CWARN("async commit start failed with rc = %d", rc);
2411 * Mark the lock as "synchonous".
2413 * Mark the lock to deffer transaction commit to the unlock time.
2415 * \param lock the lock to mark as "synchonous"
2417 * \see mdt_is_lock_sync
2418 * \see mdt_save_lock
2420 static inline void mdt_set_lock_sync(struct ldlm_lock *lock)
2422 lock->l_ast_data = (void*)1;
2426 * Check whehter the lock "synchonous" or not.
2428 * \param lock the lock to check
2429 * \retval 1 the lock is "synchonous"
2430 * \retval 0 the lock isn't "synchronous"
2432 * \see mdt_set_lock_sync
2433 * \see mdt_save_lock
2435 static inline int mdt_is_lock_sync(struct ldlm_lock *lock)
2437 return lock->l_ast_data != NULL;
2441 * Blocking AST for mdt locks.
2443 * Starts transaction commit if in case of COS lock conflict or
2444 * deffers such a commit to the mdt_save_lock.
2446 * \param lock the lock which blocks a request or cancelling lock
2447 * \param desc unused
2448 * \param data unused
2449 * \param flag indicates whether this cancelling or blocking callback
2451 * \see ldlm_blocking_ast_nocheck
2453 int mdt_blocking_ast(struct ldlm_lock *lock, struct ldlm_lock_desc *desc,
2454 void *data, int flag)
2456 struct obd_device *obd = ldlm_lock_to_ns(lock)->ns_obd;
2457 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
2461 if (flag == LDLM_CB_CANCELING)
2463 lock_res_and_lock(lock);
2464 if (lock->l_blocking_ast != mdt_blocking_ast) {
2465 unlock_res_and_lock(lock);
2468 if (mdt_cos_is_enabled(mdt) &&
2469 lock->l_req_mode & (LCK_PW | LCK_EX) &&
2470 lock->l_blocking_lock != NULL &&
2471 lock->l_client_cookie != lock->l_blocking_lock->l_client_cookie) {
2472 mdt_set_lock_sync(lock);
2474 rc = ldlm_blocking_ast_nocheck(lock);
2476 /* There is no lock conflict if l_blocking_lock == NULL,
2477 * it indicates a blocking ast sent from ldlm_lock_decref_internal
2478 * when the last reference to a local lock was released */
2479 if (lock->l_req_mode == LCK_COS && lock->l_blocking_lock != NULL) {
2482 rc = lu_env_init(&env, LCT_LOCAL);
2483 if (unlikely(rc != 0))
2484 CWARN("lu_env initialization failed with rc = %d,"
2485 "cannot start asynchronous commit\n", rc);
2487 mdt_device_commit_async(&env, mdt);
2493 int mdt_md_blocking_ast(struct ldlm_lock *lock, struct ldlm_lock_desc *desc,
2494 void *data, int flag)
2496 struct lustre_handle lockh;
2500 case LDLM_CB_BLOCKING:
2501 ldlm_lock2handle(lock, &lockh);
2502 rc = ldlm_cli_cancel(&lockh, LCF_ASYNC);
2504 CDEBUG(D_INODE, "ldlm_cli_cancel: %d\n", rc);
2508 case LDLM_CB_CANCELING:
2509 LDLM_DEBUG(lock, "Revoke remote lock\n");
2517 int mdt_remote_object_lock(struct mdt_thread_info *mti,
2518 struct mdt_object *o, struct lustre_handle *lh,
2519 ldlm_mode_t mode, __u64 ibits)
2521 struct ldlm_enqueue_info *einfo = &mti->mti_einfo;
2522 ldlm_policy_data_t *policy = &mti->mti_policy;
2526 LASSERT(mdt_object_remote(o));
2528 LASSERT((ibits & MDS_INODELOCK_UPDATE));
2530 memset(einfo, 0, sizeof(*einfo));
2531 einfo->ei_type = LDLM_IBITS;
2532 einfo->ei_mode = mode;
2533 einfo->ei_cb_bl = mdt_md_blocking_ast;
2534 einfo->ei_cb_cp = ldlm_completion_ast;
2536 memset(policy, 0, sizeof(*policy));
2537 policy->l_inodebits.bits = ibits;
2539 rc = mo_object_lock(mti->mti_env, mdt_object_child(o), lh, einfo,
2544 static int mdt_object_lock0(struct mdt_thread_info *info, struct mdt_object *o,
2545 struct mdt_lock_handle *lh, __u64 ibits,
2546 bool nonblock, int locality)
2548 struct ldlm_namespace *ns = info->mti_mdt->mdt_namespace;
2549 ldlm_policy_data_t *policy = &info->mti_policy;
2550 struct ldlm_res_id *res_id = &info->mti_res_id;
2555 LASSERT(!lustre_handle_is_used(&lh->mlh_reg_lh));
2556 LASSERT(!lustre_handle_is_used(&lh->mlh_pdo_lh));
2557 LASSERT(lh->mlh_reg_mode != LCK_MINMODE);
2558 LASSERT(lh->mlh_type != MDT_NUL_LOCK);
2560 if (mdt_object_remote(o)) {
2561 if (locality == MDT_CROSS_LOCK) {
2562 ibits &= ~(MDS_INODELOCK_UPDATE | MDS_INODELOCK_PERM);
2563 ibits |= MDS_INODELOCK_LOOKUP;
2566 (MDS_INODELOCK_UPDATE | MDS_INODELOCK_PERM)),
2567 "%s: wrong bit "LPX64" for remote obj "DFID"\n",
2568 mdt_obd_name(info->mti_mdt), ibits,
2569 PFID(mdt_object_fid(o)));
2570 LASSERT(ibits & MDS_INODELOCK_LOOKUP);
2572 /* No PDO lock on remote object */
2573 LASSERT(lh->mlh_type != MDT_PDO_LOCK);
2576 if (lh->mlh_type == MDT_PDO_LOCK) {
2577 /* check for exists after object is locked */
2578 if (mdt_object_exists(o) == 0) {
2579 /* Non-existent object shouldn't have PDO lock */
2582 /* Non-dir object shouldn't have PDO lock */
2583 if (!S_ISDIR(lu_object_attr(&o->mot_obj.mo_lu)))
2588 memset(policy, 0, sizeof(*policy));
2589 fid_build_reg_res_name(mdt_object_fid(o), res_id);
2591 dlmflags = LDLM_FL_ATOMIC_CB;
2593 dlmflags |= LDLM_FL_BLOCK_NOWAIT;
2596 * Take PDO lock on whole directory and build correct @res_id for lock
2597 * on part of directory.
2599 if (lh->mlh_pdo_hash != 0) {
2600 LASSERT(lh->mlh_type == MDT_PDO_LOCK);
2601 mdt_lock_pdo_mode(info, o, lh);
2602 if (lh->mlh_pdo_mode != LCK_NL) {
2604 * Do not use LDLM_FL_LOCAL_ONLY for parallel lock, it
2605 * is never going to be sent to client and we do not
2606 * want it slowed down due to possible cancels.
2608 policy->l_inodebits.bits = MDS_INODELOCK_UPDATE;
2609 rc = mdt_fid_lock(ns, &lh->mlh_pdo_lh, lh->mlh_pdo_mode,
2610 policy, res_id, dlmflags,
2611 &info->mti_exp->exp_handle.h_cookie);
2617 * Finish res_id initializing by name hash marking part of
2618 * directory which is taking modification.
2620 res_id->name[LUSTRE_RES_ID_HSH_OFF] = lh->mlh_pdo_hash;
2623 policy->l_inodebits.bits = ibits;
2626 * Use LDLM_FL_LOCAL_ONLY for this lock. We do not know yet if it is
2627 * going to be sent to client. If it is - mdt_intent_policy() path will
2628 * fix it up and turn FL_LOCAL flag off.
2630 rc = mdt_fid_lock(ns, &lh->mlh_reg_lh, lh->mlh_reg_mode, policy,
2631 res_id, LDLM_FL_LOCAL_ONLY | dlmflags,
2632 &info->mti_exp->exp_handle.h_cookie);
2634 mdt_object_unlock(info, o, lh, 1);
2635 else if (unlikely(OBD_FAIL_PRECHECK(OBD_FAIL_MDS_PDO_LOCK)) &&
2636 lh->mlh_pdo_hash != 0 &&
2637 (lh->mlh_reg_mode == LCK_PW || lh->mlh_reg_mode == LCK_EX)) {
2638 OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_PDO_LOCK, 15);
2644 int mdt_object_lock(struct mdt_thread_info *info, struct mdt_object *o,
2645 struct mdt_lock_handle *lh, __u64 ibits, int locality)
2647 return mdt_object_lock0(info, o, lh, ibits, false, locality);
2650 int mdt_object_lock_try(struct mdt_thread_info *info, struct mdt_object *o,
2651 struct mdt_lock_handle *lh, __u64 ibits, int locality)
2653 struct mdt_lock_handle tmp = *lh;
2656 rc = mdt_object_lock0(info, o, &tmp, ibits, true, locality);
2664 * Save a lock within request object.
2666 * Keep the lock referenced until whether client ACK or transaction
2667 * commit happens or release the lock immediately depending on input
2668 * parameters. If COS is ON, a write lock is converted to COS lock
2671 * \param info thead info object
2672 * \param h lock handle
2673 * \param mode lock mode
2674 * \param decref force immediate lock releasing
2677 void mdt_save_lock(struct mdt_thread_info *info, struct lustre_handle *h,
2678 ldlm_mode_t mode, int decref)
2682 if (lustre_handle_is_used(h)) {
2683 if (decref || !info->mti_has_trans ||
2684 !(mode & (LCK_PW | LCK_EX))){
2685 mdt_fid_unlock(h, mode);
2687 struct mdt_device *mdt = info->mti_mdt;
2688 struct ldlm_lock *lock = ldlm_handle2lock(h);
2689 struct ptlrpc_request *req = mdt_info_req(info);
2692 LASSERTF(lock != NULL, "no lock for cookie "LPX64"\n",
2694 CDEBUG(D_HA, "request = %p reply state = %p"
2695 " transno = "LPD64"\n",
2696 req, req->rq_reply_state, req->rq_transno);
2697 if (mdt_cos_is_enabled(mdt)) {
2699 ldlm_lock_downgrade(lock, LCK_COS);
2702 ptlrpc_save_lock(req, h, mode, no_ack);
2703 if (mdt_is_lock_sync(lock)) {
2704 CDEBUG(D_HA, "found sync-lock,"
2705 " async commit started\n");
2706 mdt_device_commit_async(info->mti_env,
2709 LDLM_LOCK_PUT(lock);
2718 * Unlock mdt object.
2720 * Immeditely release the regular lock and the PDO lock or save the
2721 * lock in reqeuest and keep them referenced until client ACK or
2722 * transaction commit.
2724 * \param info thread info object
2725 * \param o mdt object
2726 * \param lh mdt lock handle referencing regular and PDO locks
2727 * \param decref force immediate lock releasing
2729 void mdt_object_unlock(struct mdt_thread_info *info, struct mdt_object *o,
2730 struct mdt_lock_handle *lh, int decref)
2734 mdt_save_lock(info, &lh->mlh_pdo_lh, lh->mlh_pdo_mode, decref);
2735 mdt_save_lock(info, &lh->mlh_reg_lh, lh->mlh_reg_mode, decref);
2737 if (lustre_handle_is_used(&lh->mlh_rreg_lh))
2738 ldlm_lock_decref(&lh->mlh_rreg_lh, lh->mlh_rreg_mode);
2743 struct mdt_object *mdt_object_find_lock(struct mdt_thread_info *info,
2744 const struct lu_fid *f,
2745 struct mdt_lock_handle *lh,
2748 struct mdt_object *o;
2750 o = mdt_object_find(info->mti_env, info->mti_mdt, f);
2754 rc = mdt_object_lock(info, o, lh, ibits,
2757 mdt_object_put(info->mti_env, o);
2764 void mdt_object_unlock_put(struct mdt_thread_info * info,
2765 struct mdt_object * o,
2766 struct mdt_lock_handle *lh,
2769 mdt_object_unlock(info, o, lh, decref);
2770 mdt_object_put(info->mti_env, o);
2773 struct mdt_handler *mdt_handler_find(__u32 opc, struct mdt_opc_slice *supported)
2775 struct mdt_opc_slice *s;
2776 struct mdt_handler *h;
2779 for (s = supported; s->mos_hs != NULL; s++) {
2780 if (s->mos_opc_start <= opc && opc < s->mos_opc_end) {
2781 h = s->mos_hs + (opc - s->mos_opc_start);
2782 if (likely(h->mh_opc != 0))
2783 LASSERTF(h->mh_opc == opc,
2784 "opcode mismatch %d != %d\n",
2787 h = NULL; /* unsupported opc */
2794 static int mdt_lock_resname_compat(struct mdt_device *m,
2795 struct ldlm_request *req)
2797 /* XXX something... later. */
2801 static int mdt_lock_reply_compat(struct mdt_device *m, struct ldlm_reply *rep)
2803 /* XXX something... later. */
2808 * Generic code handling requests that have struct mdt_body passed in:
2810 * - extract mdt_body from request and save it in @info, if present;
2812 * - create lu_object, corresponding to the fid in mdt_body, and save it in
2815 * - if HABEO_CORPUS flag is set for this request type check whether object
2816 * actually exists on storage (lu_object_exists()).
2819 static int mdt_body_unpack(struct mdt_thread_info *info, __u32 flags)
2821 const struct mdt_body *body;
2822 struct mdt_object *obj;
2823 const struct lu_env *env;
2824 struct req_capsule *pill;
2828 env = info->mti_env;
2829 pill = info->mti_pill;
2831 body = info->mti_body = req_capsule_client_get(pill, &RMF_MDT_BODY);
2835 if (!(body->valid & OBD_MD_FLID))
2838 if (!fid_is_sane(&body->fid1)) {
2839 CERROR("Invalid fid: "DFID"\n", PFID(&body->fid1));
2844 * Do not get size or any capa fields before we check that request
2845 * contains capa actually. There are some requests which do not, for
2846 * instance MDS_IS_SUBDIR.
2848 if (req_capsule_has_field(pill, &RMF_CAPA1, RCL_CLIENT) &&
2849 req_capsule_get_size(pill, &RMF_CAPA1, RCL_CLIENT))
2850 mdt_set_capainfo(info, 0, &body->fid1,
2851 req_capsule_client_get(pill, &RMF_CAPA1));
2853 obj = mdt_object_find(env, info->mti_mdt, &body->fid1);
2855 if ((flags & HABEO_CORPUS) &&
2856 !mdt_object_exists(obj)) {
2857 mdt_object_put(env, obj);
2858 /* for capability renew ENOENT will be handled in
2860 if (body->valid & OBD_MD_FLOSSCAPA)
2865 info->mti_object = obj;
2874 static int mdt_unpack_req_pack_rep(struct mdt_thread_info *info, __u32 flags)
2876 struct req_capsule *pill = info->mti_pill;
2880 if (req_capsule_has_field(pill, &RMF_MDT_BODY, RCL_CLIENT))
2881 rc = mdt_body_unpack(info, flags);
2885 if (rc == 0 && (flags & HABEO_REFERO)) {
2887 if (req_capsule_has_field(pill, &RMF_MDT_MD, RCL_SERVER))
2888 req_capsule_set_size(pill, &RMF_MDT_MD, RCL_SERVER,
2889 info->mti_body->eadatasize);
2890 if (req_capsule_has_field(pill, &RMF_LOGCOOKIES, RCL_SERVER))
2891 req_capsule_set_size(pill, &RMF_LOGCOOKIES,
2894 rc = req_capsule_server_pack(pill);
2899 static int mdt_init_capa_ctxt(const struct lu_env *env, struct mdt_device *m)
2901 struct md_device *next = m->mdt_child;
2903 return next->md_ops->mdo_init_capa_ctxt(env, next,
2904 m->mdt_opts.mo_mds_capa,
2905 m->mdt_capa_timeout,
2911 * Invoke handler for this request opc. Also do necessary preprocessing
2912 * (according to handler ->mh_flags), and post-processing (setting of
2913 * ->last_{xid,committed}).
2915 static int mdt_req_handle(struct mdt_thread_info *info,
2916 struct mdt_handler *h, struct ptlrpc_request *req)
2918 int rc, serious = 0;
2923 LASSERT(h->mh_act != NULL);
2924 LASSERT(h->mh_opc == lustre_msg_get_opc(req->rq_reqmsg));
2925 LASSERT(current->journal_info == NULL);
2928 * Checking for various OBD_FAIL_$PREF_$OPC_NET codes. _Do_ not try
2929 * to put same checks into handlers like mdt_close(), mdt_reint(),
2930 * etc., without talking to mdt authors first. Checking same thing
2931 * there again is useless and returning 0 error without packing reply
2932 * is buggy! Handlers either pack reply or return error.
2934 * We return 0 here and do not send any reply in order to emulate
2935 * network failure. Do not send any reply in case any of NET related
2936 * fail_id has occured.
2938 if (OBD_FAIL_CHECK_ORSET(h->mh_fail_id, OBD_FAIL_ONCE))
2942 flags = h->mh_flags;
2943 LASSERT(ergo(flags & (HABEO_CORPUS|HABEO_REFERO), h->mh_fmt != NULL));
2945 if (h->mh_fmt != NULL) {
2946 req_capsule_set(info->mti_pill, h->mh_fmt);
2947 rc = mdt_unpack_req_pack_rep(info, flags);
2950 if (rc == 0 && flags & MUTABOR &&
2951 exp_connect_flags(req->rq_export) & OBD_CONNECT_RDONLY)
2952 /* should it be rq_status? */
2955 if (rc == 0 && flags & HABEO_CLAVIS) {
2956 struct ldlm_request *dlm_req;
2958 LASSERT(h->mh_fmt != NULL);
2960 dlm_req = req_capsule_client_get(info->mti_pill, &RMF_DLM_REQ);
2961 if (dlm_req != NULL) {
2962 if (unlikely(dlm_req->lock_desc.l_resource.lr_type ==
2964 dlm_req->lock_desc.l_policy_data.\
2965 l_inodebits.bits == 0)) {
2967 * Lock without inodebits makes no sense and
2968 * will oops later in ldlm. If client miss to
2969 * set such bits, do not trigger ASSERTION.
2971 * For liblustre flock case, it maybe zero.
2975 if (info->mti_mdt->mdt_opts.mo_compat_resname)
2976 rc = mdt_lock_resname_compat(
2979 info->mti_dlm_req = dlm_req;
2986 /* capability setting changed via /proc, needs reinitialize ctxt */
2987 if (info->mti_mdt && info->mti_mdt->mdt_capa_conf) {
2988 mdt_init_capa_ctxt(info->mti_env, info->mti_mdt);
2989 info->mti_mdt->mdt_capa_conf = 0;
2992 if (likely(rc == 0)) {
2994 * Process request, there can be two types of rc:
2995 * 1) errors with msg unpack/pack, other failures outside the
2996 * operation itself. This is counted as serious errors;
2997 * 2) errors during fs operation, should be placed in rq_status
3000 rc = h->mh_act(info);
3002 !req->rq_no_reply && req->rq_reply_state == NULL) {
3003 DEBUG_REQ(D_ERROR, req, "MDT \"handler\" %s did not "
3004 "pack reply and returned 0 error\n",
3008 serious = is_serious(rc);
3009 rc = clear_serious(rc);
3013 req->rq_status = rc;
3016 * ELDLM_* codes which > 0 should be in rq_status only as well as
3017 * all non-serious errors.
3019 if (rc > 0 || !serious)
3022 LASSERT(current->journal_info == NULL);
3024 if (rc == 0 && (flags & HABEO_CLAVIS) &&
3025 info->mti_mdt->mdt_opts.mo_compat_resname) {
3026 struct ldlm_reply *dlmrep;
3028 dlmrep = req_capsule_server_get(info->mti_pill, &RMF_DLM_REP);
3030 rc = mdt_lock_reply_compat(info->mti_mdt, dlmrep);
3033 /* If we're DISCONNECTing, the mdt_export_data is already freed */
3034 if (likely(rc == 0 && req->rq_export && h->mh_opc != MDS_DISCONNECT))
3035 target_committed_to_req(req);
3037 if (unlikely(req_is_replay(req) &&
3038 lustre_msg_get_transno(req->rq_reqmsg) == 0)) {
3039 DEBUG_REQ(D_ERROR, req, "transno is 0 during REPLAY");
3043 target_send_reply(req, rc, info->mti_fail_id);
3047 void mdt_lock_handle_init(struct mdt_lock_handle *lh)
3049 lh->mlh_type = MDT_NUL_LOCK;
3050 lh->mlh_reg_lh.cookie = 0ull;
3051 lh->mlh_reg_mode = LCK_MINMODE;
3052 lh->mlh_pdo_lh.cookie = 0ull;
3053 lh->mlh_pdo_mode = LCK_MINMODE;
3054 lh->mlh_rreg_lh.cookie = 0ull;
3055 lh->mlh_rreg_mode = LCK_MINMODE;
3058 void mdt_lock_handle_fini(struct mdt_lock_handle *lh)
3060 LASSERT(!lustre_handle_is_used(&lh->mlh_reg_lh));
3061 LASSERT(!lustre_handle_is_used(&lh->mlh_pdo_lh));
3065 * Initialize fields of struct mdt_thread_info. Other fields are left in
3066 * uninitialized state, because it's too expensive to zero out whole
3067 * mdt_thread_info (> 1K) on each request arrival.
3069 static void mdt_thread_info_init(struct ptlrpc_request *req,
3070 struct mdt_thread_info *info)
3074 req_capsule_init(&req->rq_pill, req, RCL_SERVER);
3075 info->mti_pill = &req->rq_pill;
3078 for (i = 0; i < ARRAY_SIZE(info->mti_lh); i++)
3079 mdt_lock_handle_init(&info->mti_lh[i]);
3081 /* mdt device: it can be NULL while CONNECT */
3082 if (req->rq_export) {
3083 info->mti_mdt = mdt_dev(req->rq_export->exp_obd->obd_lu_dev);
3084 info->mti_exp = req->rq_export;
3086 info->mti_mdt = NULL;
3087 info->mti_env = req->rq_svc_thread->t_env;
3088 info->mti_fail_id = OBD_FAIL_MDS_ALL_REPLY_NET;
3089 info->mti_transno = lustre_msg_get_transno(req->rq_reqmsg);
3090 info->mti_mos = NULL;
3092 memset(&info->mti_attr, 0, sizeof(info->mti_attr));
3093 info->mti_big_buf = LU_BUF_NULL;
3094 info->mti_body = NULL;
3095 info->mti_object = NULL;
3096 info->mti_dlm_req = NULL;
3097 info->mti_has_trans = 0;
3098 info->mti_cross_ref = 0;
3099 info->mti_opdata = 0;
3100 info->mti_big_lmm_used = 0;
3102 /* To not check for split by default. */
3103 info->mti_spec.no_create = 0;
3104 info->mti_spec.sp_rm_entry = 0;
3107 static void mdt_thread_info_fini(struct mdt_thread_info *info)
3111 req_capsule_fini(info->mti_pill);
3112 if (info->mti_object != NULL) {
3113 mdt_object_put(info->mti_env, info->mti_object);
3114 info->mti_object = NULL;
3117 for (i = 0; i < ARRAY_SIZE(info->mti_lh); i++)
3118 mdt_lock_handle_fini(&info->mti_lh[i]);
3119 info->mti_env = NULL;
3121 if (unlikely(info->mti_big_buf.lb_buf != NULL))
3122 lu_buf_free(&info->mti_big_buf);
3125 static int mdt_filter_recovery_request(struct ptlrpc_request *req,
3126 struct obd_device *obd, int *process)
3128 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
3129 case MDS_CONNECT: /* This will never get here, but for completeness. */
3130 case OST_CONNECT: /* This will never get here, but for completeness. */
3131 case MDS_DISCONNECT:
3132 case OST_DISCONNECT:
3138 case MDS_DONE_WRITING:
3139 case MDS_SYNC: /* used in unmounting */
3146 *process = target_queue_recovery_request(req, obd);
3150 DEBUG_REQ(D_ERROR, req, "not permitted during recovery");
3157 * Handle recovery. Return:
3158 * +1: continue request processing;
3159 * -ve: abort immediately with the given error code;
3160 * 0: send reply with error code in req->rq_status;
3162 static int mdt_recovery(struct mdt_thread_info *info)
3164 struct ptlrpc_request *req = mdt_info_req(info);
3165 struct obd_device *obd;
3169 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
3172 case SEC_CTX_INIT_CONT:
3178 rc = mdt_handle_idmap(info);
3187 if (unlikely(!class_connected_export(req->rq_export))) {
3188 CDEBUG(D_HA, "operation %d on unconnected MDS from %s\n",
3189 lustre_msg_get_opc(req->rq_reqmsg),
3190 libcfs_id2str(req->rq_peer));
3191 /* FIXME: For CMD cleanup, when mds_B stop, the req from
3192 * mds_A will get -ENOTCONN(especially for ping req),
3193 * which will cause that mds_A deactive timeout, then when
3194 * mds_A cleanup, the cleanup process will be suspended since
3195 * deactive timeout is not zero.
3197 req->rq_status = -ENOTCONN;
3198 target_send_reply(req, -ENOTCONN, info->mti_fail_id);
3202 /* sanity check: if the xid matches, the request must be marked as a
3203 * resent or replayed */
3204 if (req_xid_is_last(req)) {
3205 if (!(lustre_msg_get_flags(req->rq_reqmsg) &
3206 (MSG_RESENT | MSG_REPLAY))) {
3207 DEBUG_REQ(D_WARNING, req, "rq_xid "LPU64" matches last_xid, "
3208 "expected REPLAY or RESENT flag (%x)", req->rq_xid,
3209 lustre_msg_get_flags(req->rq_reqmsg));
3211 req->rq_status = -ENOTCONN;
3216 /* else: note the opposite is not always true; a RESENT req after a
3217 * failover will usually not match the last_xid, since it was likely
3218 * never committed. A REPLAYed request will almost never match the
3219 * last xid, however it could for a committed, but still retained,
3222 obd = req->rq_export->exp_obd;
3224 /* Check for aborted recovery... */
3225 if (unlikely(obd->obd_recovering)) {
3228 DEBUG_REQ(D_INFO, req, "Got new replay");
3229 rc = mdt_filter_recovery_request(req, obd, &should_process);
3230 if (rc != 0 || !should_process)
3232 else if (should_process < 0) {
3233 req->rq_status = should_process;
3234 rc = ptlrpc_error(req);
3241 static int mdt_msg_check_version(struct lustre_msg *msg)
3245 switch (lustre_msg_get_opc(msg)) {
3247 case MDS_DISCONNECT:
3250 case SEC_CTX_INIT_CONT:
3253 rc = lustre_msg_check_version(msg, LUSTRE_OBD_VERSION);
3255 CERROR("bad opc %u version %08x, expecting %08x\n",
3256 lustre_msg_get_opc(msg),
3257 lustre_msg_get_version(msg),
3258 LUSTRE_OBD_VERSION);
3262 case MDS_GETATTR_NAME:
3269 case MDS_DONE_WRITING:
3276 case MDS_HSM_PROGRESS:
3277 case MDS_HSM_REQUEST:
3278 case MDS_HSM_CT_REGISTER:
3279 case MDS_HSM_CT_UNREGISTER:
3280 case MDS_HSM_STATE_GET:
3281 case MDS_HSM_STATE_SET:
3282 case MDS_HSM_ACTION:
3283 case MDS_QUOTACHECK:
3286 case MDS_SWAP_LAYOUTS:
3291 rc = lustre_msg_check_version(msg, LUSTRE_MDS_VERSION);
3293 CERROR("bad opc %u version %08x, expecting %08x\n",
3294 lustre_msg_get_opc(msg),
3295 lustre_msg_get_version(msg),
3296 LUSTRE_MDS_VERSION);
3300 case LDLM_BL_CALLBACK:
3301 case LDLM_CP_CALLBACK:
3302 rc = lustre_msg_check_version(msg, LUSTRE_DLM_VERSION);
3304 CERROR("bad opc %u version %08x, expecting %08x\n",
3305 lustre_msg_get_opc(msg),
3306 lustre_msg_get_version(msg),
3307 LUSTRE_DLM_VERSION);
3309 case OBD_LOG_CANCEL:
3310 case LLOG_ORIGIN_HANDLE_CREATE:
3311 case LLOG_ORIGIN_HANDLE_NEXT_BLOCK:
3312 case LLOG_ORIGIN_HANDLE_READ_HEADER:
3313 case LLOG_ORIGIN_HANDLE_CLOSE:
3314 case LLOG_ORIGIN_HANDLE_DESTROY:
3315 case LLOG_ORIGIN_HANDLE_PREV_BLOCK:
3317 rc = lustre_msg_check_version(msg, LUSTRE_LOG_VERSION);
3319 CERROR("bad opc %u version %08x, expecting %08x\n",
3320 lustre_msg_get_opc(msg),
3321 lustre_msg_get_version(msg),
3322 LUSTRE_LOG_VERSION);
3325 CERROR("MDS unknown opcode %d\n", lustre_msg_get_opc(msg));
3331 static int mdt_handle0(struct ptlrpc_request *req,
3332 struct mdt_thread_info *info,
3333 struct mdt_opc_slice *supported)
3335 struct mdt_handler *h;
3336 struct lustre_msg *msg;
3341 if (OBD_FAIL_CHECK_ORSET(OBD_FAIL_MDS_ALL_REQUEST_NET, OBD_FAIL_ONCE))
3344 LASSERT(current->journal_info == NULL);
3346 msg = req->rq_reqmsg;
3347 rc = mdt_msg_check_version(msg);
3348 if (likely(rc == 0)) {
3349 rc = mdt_recovery(info);
3350 if (likely(rc == +1)) {
3351 h = mdt_handler_find(lustre_msg_get_opc(msg),
3353 if (likely(h != NULL)) {
3354 rc = mdt_req_handle(info, h, req);
3356 CERROR("The unsupported opc: 0x%x\n",
3357 lustre_msg_get_opc(msg) );
3358 req->rq_status = -ENOTSUPP;
3359 rc = ptlrpc_error(req);
3364 CERROR(LUSTRE_MDT_NAME" drops mal-formed request\n");
3369 * MDT handler function called by ptlrpc service thread when request comes.
3371 * XXX common "target" functionality should be factored into separate module
3372 * shared by mdt, ost and stand-alone services like fld.
3374 int mdt_handle_common(struct ptlrpc_request *req,
3375 struct mdt_opc_slice *supported)
3378 struct mdt_thread_info *info;
3382 env = req->rq_svc_thread->t_env;
3383 /* Refill(initilize) the context(mdt_thread_info), in case it is
3384 * not initialized yet. Usually it happens during start up, after
3385 * MDS(ptlrpc threads) is start up, it gets the first CONNECT request,
3386 * before MDT_thread_info is initialized */
3388 LASSERT(env != NULL);
3389 LASSERT(env->le_ses != NULL);
3390 LASSERT(env->le_ctx.lc_thread == req->rq_svc_thread);
3391 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
3392 LASSERT(info != NULL);
3394 mdt_thread_info_init(req, info);
3396 rc = mdt_handle0(req, info, supported);
3398 mdt_thread_info_fini(info);
3403 * This is called from recovery code as handler of _all_ RPC types, FLD and SEQ
3406 int mdt_recovery_handle(struct ptlrpc_request *req)
3411 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
3413 rc = mdt_handle_common(req, mdt_fld_handlers);
3416 rc = mdt_handle_common(req, mdt_seq_handlers);
3419 rc = mdt_handle_common(req, mdt_regular_handlers);
3441 static int mdt_intent_getattr(enum mdt_it_code opcode,
3442 struct mdt_thread_info *info,
3443 struct ldlm_lock **,
3445 static int mdt_intent_layout(enum mdt_it_code opcode,
3446 struct mdt_thread_info *info,
3447 struct ldlm_lock **,
3449 static int mdt_intent_reint(enum mdt_it_code opcode,
3450 struct mdt_thread_info *info,
3451 struct ldlm_lock **,
3454 static struct mdt_it_flavor {
3455 const struct req_format *it_fmt;
3457 int (*it_act)(enum mdt_it_code ,
3458 struct mdt_thread_info *,
3459 struct ldlm_lock **,
3462 } mdt_it_flavor[] = {
3464 .it_fmt = &RQF_LDLM_INTENT,
3465 /*.it_flags = HABEO_REFERO,*/
3467 .it_act = mdt_intent_reint,
3468 .it_reint = REINT_OPEN
3471 .it_fmt = &RQF_LDLM_INTENT,
3472 .it_flags = MUTABOR,
3473 .it_act = mdt_intent_reint,
3474 .it_reint = REINT_OPEN
3477 .it_fmt = &RQF_LDLM_INTENT,
3478 .it_flags = MUTABOR,
3479 .it_act = mdt_intent_reint,
3480 .it_reint = REINT_CREATE
3482 [MDT_IT_GETATTR] = {
3483 .it_fmt = &RQF_LDLM_INTENT_GETATTR,
3484 .it_flags = HABEO_REFERO,
3485 .it_act = mdt_intent_getattr
3487 [MDT_IT_READDIR] = {
3493 .it_fmt = &RQF_LDLM_INTENT_GETATTR,
3494 .it_flags = HABEO_REFERO,
3495 .it_act = mdt_intent_getattr
3498 .it_fmt = &RQF_LDLM_INTENT_UNLINK,
3499 .it_flags = MUTABOR,
3501 .it_reint = REINT_UNLINK
3505 .it_flags = MUTABOR,
3508 [MDT_IT_GETXATTR] = {
3514 .it_fmt = &RQF_LDLM_INTENT_LAYOUT,
3516 .it_act = mdt_intent_layout
3520 int mdt_intent_lock_replace(struct mdt_thread_info *info,
3521 struct ldlm_lock **lockp,
3522 struct ldlm_lock *new_lock,
3523 struct mdt_lock_handle *lh,
3526 struct ptlrpc_request *req = mdt_info_req(info);
3527 struct ldlm_lock *lock = *lockp;
3530 * Get new lock only for cases when possible resent did not find any
3533 if (new_lock == NULL)
3534 new_lock = ldlm_handle2lock_long(&lh->mlh_reg_lh, 0);
3536 if (new_lock == NULL && (flags & LDLM_FL_INTENT_ONLY)) {
3537 lh->mlh_reg_lh.cookie = 0;
3541 LASSERTF(new_lock != NULL,
3542 "lockh "LPX64"\n", lh->mlh_reg_lh.cookie);
3545 * If we've already given this lock to a client once, then we should
3546 * have no readers or writers. Otherwise, we should have one reader
3547 * _or_ writer ref (which will be zeroed below) before returning the
3550 if (new_lock->l_export == req->rq_export) {
3551 LASSERT(new_lock->l_readers + new_lock->l_writers == 0);
3553 LASSERT(new_lock->l_export == NULL);
3554 LASSERT(new_lock->l_readers + new_lock->l_writers == 1);
3559 if (new_lock->l_export == req->rq_export) {
3561 * Already gave this to the client, which means that we
3562 * reconstructed a reply.
3564 LASSERT(lustre_msg_get_flags(req->rq_reqmsg) &
3566 lh->mlh_reg_lh.cookie = 0;
3567 RETURN(ELDLM_LOCK_REPLACED);
3571 * Fixup the lock to be given to the client.
3573 lock_res_and_lock(new_lock);
3574 /* Zero new_lock->l_readers and new_lock->l_writers without triggering
3575 * possible blocking AST. */
3576 while (new_lock->l_readers > 0) {
3577 lu_ref_del(&new_lock->l_reference, "reader", new_lock);
3578 lu_ref_del(&new_lock->l_reference, "user", new_lock);
3579 new_lock->l_readers--;
3581 while (new_lock->l_writers > 0) {
3582 lu_ref_del(&new_lock->l_reference, "writer", new_lock);
3583 lu_ref_del(&new_lock->l_reference, "user", new_lock);
3584 new_lock->l_writers--;
3587 new_lock->l_export = class_export_lock_get(req->rq_export, new_lock);
3588 new_lock->l_blocking_ast = lock->l_blocking_ast;
3589 new_lock->l_completion_ast = lock->l_completion_ast;
3590 new_lock->l_remote_handle = lock->l_remote_handle;
3591 new_lock->l_flags &= ~LDLM_FL_LOCAL;
3593 unlock_res_and_lock(new_lock);
3595 cfs_hash_add(new_lock->l_export->exp_lock_hash,
3596 &new_lock->l_remote_handle,
3597 &new_lock->l_exp_hash);
3599 LDLM_LOCK_RELEASE(new_lock);
3600 lh->mlh_reg_lh.cookie = 0;
3602 RETURN(ELDLM_LOCK_REPLACED);
3605 static void mdt_intent_fixup_resent(struct mdt_thread_info *info,
3606 struct ldlm_lock *new_lock,
3607 struct ldlm_lock **old_lock,
3608 struct mdt_lock_handle *lh)
3610 struct ptlrpc_request *req = mdt_info_req(info);
3611 struct obd_export *exp = req->rq_export;
3612 struct lustre_handle remote_hdl;
3613 struct ldlm_request *dlmreq;
3614 struct ldlm_lock *lock;
3616 if (!(lustre_msg_get_flags(req->rq_reqmsg) & MSG_RESENT))
3619 dlmreq = req_capsule_client_get(info->mti_pill, &RMF_DLM_REQ);
3620 remote_hdl = dlmreq->lock_handle[0];
3622 /* In the function below, .hs_keycmp resolves to
3623 * ldlm_export_lock_keycmp() */
3624 /* coverity[overrun-buffer-val] */
3625 lock = cfs_hash_lookup(exp->exp_lock_hash, &remote_hdl);
3627 if (lock != new_lock) {
3628 lh->mlh_reg_lh.cookie = lock->l_handle.h_cookie;
3629 lh->mlh_reg_mode = lock->l_granted_mode;
3631 LDLM_DEBUG(lock, "Restoring lock cookie");
3632 DEBUG_REQ(D_DLMTRACE, req,
3633 "restoring lock cookie "LPX64,
3634 lh->mlh_reg_lh.cookie);
3636 *old_lock = LDLM_LOCK_GET(lock);
3637 cfs_hash_put(exp->exp_lock_hash, &lock->l_exp_hash);
3641 cfs_hash_put(exp->exp_lock_hash, &lock->l_exp_hash);
3645 * If the xid matches, then we know this is a resent request, and allow
3646 * it. (It's probably an OPEN, for which we don't send a lock.
3648 if (req_xid_is_last(req))
3652 * This remote handle isn't enqueued, so we never received or processed
3653 * this request. Clear MSG_RESENT, because it can be handled like any
3654 * normal request now.
3656 lustre_msg_clear_flags(req->rq_reqmsg, MSG_RESENT);
3658 DEBUG_REQ(D_DLMTRACE, req, "no existing lock with rhandle "LPX64,
3662 static int mdt_intent_getattr(enum mdt_it_code opcode,
3663 struct mdt_thread_info *info,
3664 struct ldlm_lock **lockp,
3667 struct mdt_lock_handle *lhc = &info->mti_lh[MDT_LH_RMT];
3668 struct ldlm_lock *new_lock = NULL;
3670 struct ldlm_reply *ldlm_rep;
3671 struct ptlrpc_request *req;
3672 struct mdt_body *reqbody;
3673 struct mdt_body *repbody;
3677 reqbody = req_capsule_client_get(info->mti_pill, &RMF_MDT_BODY);
3680 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
3683 info->mti_cross_ref = !!(reqbody->valid & OBD_MD_FLCROSSREF);
3684 repbody->eadatasize = 0;
3685 repbody->aclsize = 0;
3689 child_bits = MDS_INODELOCK_LOOKUP | MDS_INODELOCK_PERM;
3691 case MDT_IT_GETATTR:
3692 child_bits = MDS_INODELOCK_LOOKUP | MDS_INODELOCK_UPDATE |
3696 CERROR("Unsupported intent (%d)\n", opcode);
3697 GOTO(out_shrink, rc = -EINVAL);
3700 rc = mdt_init_ucred(info, reqbody);
3702 GOTO(out_shrink, rc);
3704 req = info->mti_pill->rc_req;
3705 ldlm_rep = req_capsule_server_get(info->mti_pill, &RMF_DLM_REP);
3706 mdt_set_disposition(info, ldlm_rep, DISP_IT_EXECD);
3708 /* Get lock from request for possible resent case. */
3709 mdt_intent_fixup_resent(info, *lockp, &new_lock, lhc);
3711 ldlm_rep->lock_policy_res2 =
3712 mdt_getattr_name_lock(info, lhc, child_bits, ldlm_rep);
3714 if (mdt_get_disposition(ldlm_rep, DISP_LOOKUP_NEG))
3715 ldlm_rep->lock_policy_res2 = 0;
3716 if (!mdt_get_disposition(ldlm_rep, DISP_LOOKUP_POS) ||
3717 ldlm_rep->lock_policy_res2) {
3718 lhc->mlh_reg_lh.cookie = 0ull;
3719 GOTO(out_ucred, rc = ELDLM_LOCK_ABORTED);
3722 rc = mdt_intent_lock_replace(info, lockp, new_lock, lhc, flags);
3725 mdt_exit_ucred(info);
3727 mdt_client_compatibility(info);
3728 rc2 = mdt_fix_reply(info);
3734 static int mdt_intent_layout(enum mdt_it_code opcode,
3735 struct mdt_thread_info *info,
3736 struct ldlm_lock **lockp,
3739 struct layout_intent *layout;
3741 struct mdt_object *obj = NULL;
3742 struct md_object *child = NULL;
3746 if (opcode != MDT_IT_LAYOUT) {
3747 CERROR("%s: Unknown intent (%d)\n", mdt_obd_name(info->mti_mdt),
3752 fid = &info->mti_tmp_fid2;
3753 fid_build_from_res_name(fid, &(*lockp)->l_resource->lr_name);
3755 obj = mdt_object_find(info->mti_env, info->mti_mdt, fid);
3757 RETURN(PTR_ERR(obj));
3759 if (mdt_object_exists(obj) && !mdt_object_remote(obj)) {
3760 child = mdt_object_child(obj);
3762 /* get the length of lsm */
3763 rc = mo_xattr_get(info->mti_env, child, &LU_BUF_NULL,
3766 if (rc > info->mti_mdt->mdt_max_mdsize)
3767 info->mti_mdt->mdt_max_mdsize = rc;
3770 mdt_object_put(info->mti_env, obj);
3772 (*lockp)->l_lvb_type = LVB_T_LAYOUT;
3773 req_capsule_set_size(info->mti_pill, &RMF_DLM_LVB, RCL_SERVER,
3774 ldlm_lvbo_size(*lockp));
3775 rc = req_capsule_server_pack(info->mti_pill);
3779 layout = req_capsule_client_get(info->mti_pill, &RMF_LAYOUT_INTENT);
3780 LASSERT(layout != NULL);
3781 if (layout->li_opc == LAYOUT_INTENT_ACCESS)
3782 /* return to normal ldlm handling */
3785 CERROR("%s: Unsupported layout intent (%d)\n",
3786 mdt_obd_name(info->mti_mdt), layout->li_opc);
3790 static int mdt_intent_reint(enum mdt_it_code opcode,
3791 struct mdt_thread_info *info,
3792 struct ldlm_lock **lockp,
3795 struct mdt_lock_handle *lhc = &info->mti_lh[MDT_LH_RMT];
3796 struct ldlm_reply *rep = NULL;
3800 static const struct req_format *intent_fmts[REINT_MAX] = {
3801 [REINT_CREATE] = &RQF_LDLM_INTENT_CREATE,
3802 [REINT_OPEN] = &RQF_LDLM_INTENT_OPEN
3807 opc = mdt_reint_opcode(info, intent_fmts);
3811 if (mdt_it_flavor[opcode].it_reint != opc) {
3812 CERROR("Reint code %ld doesn't match intent: %d\n",
3814 RETURN(err_serious(-EPROTO));
3817 /* Get lock from request for possible resent case. */
3818 mdt_intent_fixup_resent(info, *lockp, NULL, lhc);
3820 rc = mdt_reint_internal(info, lhc, opc);
3822 /* Check whether the reply has been packed successfully. */
3823 if (mdt_info_req(info)->rq_repmsg != NULL)
3824 rep = req_capsule_server_get(info->mti_pill, &RMF_DLM_REP);
3826 RETURN(err_serious(-EFAULT));
3828 /* MDC expects this in any case */
3830 mdt_set_disposition(info, rep, DISP_LOOKUP_EXECD);
3832 /* the open lock or the lock for cross-ref object should be
3833 * returned to the client */
3834 if (rc == -EREMOTE || mdt_get_disposition(rep, DISP_OPEN_LOCK)) {
3835 LASSERT(lustre_handle_is_used(&lhc->mlh_reg_lh));
3836 rep->lock_policy_res2 = 0;
3837 rc = mdt_intent_lock_replace(info, lockp, NULL, lhc, flags);
3841 rep->lock_policy_res2 = clear_serious(rc);
3843 if (rep->lock_policy_res2 == -ENOENT &&
3844 mdt_get_disposition(rep, DISP_LOOKUP_NEG))
3845 rep->lock_policy_res2 = 0;
3847 if (rc == -ENOTCONN || rc == -ENODEV ||
3848 rc == -EOVERFLOW) { /**< if VBR failure then return error */
3850 * If it is the disconnect error (ENODEV & ENOCONN), the error
3851 * will be returned by rq_status, and client at ptlrpc layer
3852 * will detect this, then disconnect, reconnect the import
3853 * immediately, instead of impacting the following the rpc.
3855 lhc->mlh_reg_lh.cookie = 0ull;
3859 * For other cases, the error will be returned by intent.
3860 * and client will retrieve the result from intent.
3863 * FIXME: when open lock is finished, that should be
3866 if (lustre_handle_is_used(&lhc->mlh_reg_lh)) {
3867 LASSERTF(rc == 0, "Error occurred but lock handle "
3868 "is still in use, rc = %d\n", rc);
3869 rep->lock_policy_res2 = 0;
3870 rc = mdt_intent_lock_replace(info, lockp, NULL, lhc, flags);
3873 lhc->mlh_reg_lh.cookie = 0ull;
3874 RETURN(ELDLM_LOCK_ABORTED);
3879 static int mdt_intent_code(long itcode)
3887 case IT_OPEN|IT_CREAT:
3894 rc = MDT_IT_READDIR;
3897 rc = MDT_IT_GETATTR;
3909 rc = MDT_IT_GETXATTR;
3914 case IT_QUOTA_DQACQ:
3919 CERROR("Unknown intent opcode: %ld\n", itcode);
3926 static int mdt_intent_opc(long itopc, struct mdt_thread_info *info,
3927 struct ldlm_lock **lockp, __u64 flags)
3929 struct req_capsule *pill;
3930 struct mdt_it_flavor *flv;
3935 opc = mdt_intent_code(itopc);
3939 pill = info->mti_pill;
3941 if (opc == MDT_IT_QUOTA) {
3942 struct lu_device *qmt = info->mti_mdt->mdt_qmt_dev;
3945 RETURN(-EOPNOTSUPP);
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);
3961 struct ptlrpc_request *req = mdt_info_req(info);
3962 if (flv->it_flags & MUTABOR &&
3963 exp_connect_flags(req->rq_export) & OBD_CONNECT_RDONLY)
3966 if (rc == 0 && flv->it_act != NULL) {
3967 /* execute policy */
3968 rc = flv->it_act(opc, info, lockp, flags);
3975 static int mdt_intent_policy(struct ldlm_namespace *ns,
3976 struct ldlm_lock **lockp, void *req_cookie,
3977 ldlm_mode_t mode, __u64 flags, void *data)
3979 struct mdt_thread_info *info;
3980 struct ptlrpc_request *req = req_cookie;
3981 struct ldlm_intent *it;
3982 struct req_capsule *pill;
3987 LASSERT(req != NULL);
3989 info = lu_context_key_get(&req->rq_svc_thread->t_env->le_ctx,
3991 LASSERT(info != NULL);
3992 pill = info->mti_pill;
3993 LASSERT(pill->rc_req == req);
3995 if (req->rq_reqmsg->lm_bufcount > DLM_INTENT_IT_OFF) {
3996 req_capsule_extend(pill, &RQF_LDLM_INTENT_BASIC);
3997 it = req_capsule_client_get(pill, &RMF_LDLM_INTENT);
3999 rc = mdt_intent_opc(it->opc, info, lockp, flags);
4003 /* Lock without inodebits makes no sense and will oops
4004 * later in ldlm. Let's check it now to see if we have
4005 * ibits corrupted somewhere in mdt_intent_opc().
4006 * The case for client miss to set ibits has been
4007 * processed by others. */
4008 LASSERT(ergo(info->mti_dlm_req->lock_desc.l_resource.\
4009 lr_type == LDLM_IBITS,
4010 info->mti_dlm_req->lock_desc.\
4011 l_policy_data.l_inodebits.bits != 0));
4013 rc = err_serious(-EFAULT);
4015 /* No intent was provided */
4016 LASSERT(pill->rc_fmt == &RQF_LDLM_ENQUEUE);
4017 req_capsule_set_size(pill, &RMF_DLM_LVB, RCL_SERVER, 0);
4018 rc = req_capsule_server_pack(pill);
4020 rc = err_serious(rc);
4025 static int mdt_seq_fini(const struct lu_env *env,
4026 struct mdt_device *m)
4028 return seq_site_fini(env, mdt_seq_site(m));
4031 static int mdt_seq_init(const struct lu_env *env,
4033 struct mdt_device *m)
4035 struct seq_server_site *ss;
4040 ss = mdt_seq_site(m);
4043 * This is sequence-controller node. Init seq-controller server on local
4046 if (ss->ss_node_id == 0) {
4047 LASSERT(ss->ss_control_seq == NULL);
4049 OBD_ALLOC_PTR(ss->ss_control_seq);
4050 if (ss->ss_control_seq == NULL)
4053 rc = seq_server_init(ss->ss_control_seq,
4054 m->mdt_bottom, uuid,
4055 LUSTRE_SEQ_CONTROLLER,
4060 GOTO(out_seq_fini, rc);
4062 OBD_ALLOC_PTR(ss->ss_client_seq);
4063 if (ss->ss_client_seq == NULL)
4064 GOTO(out_seq_fini, rc = -ENOMEM);
4066 OBD_ALLOC(prefix, MAX_OBD_NAME + 5);
4067 if (prefix == NULL) {
4068 OBD_FREE_PTR(ss->ss_client_seq);
4069 GOTO(out_seq_fini, rc = -ENOMEM);
4072 snprintf(prefix, MAX_OBD_NAME + 5, "ctl-%s",
4076 * Init seq-controller client after seq-controller server is
4077 * ready. Pass ss->ss_control_seq to it for direct talking.
4079 rc = seq_client_init(ss->ss_client_seq, NULL,
4080 LUSTRE_SEQ_METADATA, prefix,
4081 ss->ss_control_seq);
4082 OBD_FREE(prefix, MAX_OBD_NAME + 5);
4085 GOTO(out_seq_fini, rc);
4088 /* Init seq-server on local MDT */
4089 LASSERT(ss->ss_server_seq == NULL);
4091 OBD_ALLOC_PTR(ss->ss_server_seq);
4092 if (ss->ss_server_seq == NULL)
4093 GOTO(out_seq_fini, rc = -ENOMEM);
4095 rc = seq_server_init(ss->ss_server_seq,
4096 m->mdt_bottom, uuid,
4101 GOTO(out_seq_fini, rc = -ENOMEM);
4103 /* Assign seq-controller client to local seq-server. */
4104 if (ss->ss_node_id == 0) {
4105 LASSERT(ss->ss_client_seq != NULL);
4107 rc = seq_server_set_cli(ss->ss_server_seq,
4115 mdt_seq_fini(env, m);
4123 static int mdt_fld_fini(const struct lu_env *env,
4124 struct mdt_device *m)
4126 struct seq_server_site *ss = mdt_seq_site(m);
4129 if (ss && ss->ss_server_fld) {
4130 fld_server_fini(env, ss->ss_server_fld);
4131 OBD_FREE_PTR(ss->ss_server_fld);
4132 ss->ss_server_fld = NULL;
4138 static int mdt_fld_init(const struct lu_env *env,
4140 struct mdt_device *m)
4142 struct seq_server_site *ss;
4146 ss = mdt_seq_site(m);
4148 OBD_ALLOC_PTR(ss->ss_server_fld);
4149 if (ss->ss_server_fld == NULL)
4150 RETURN(rc = -ENOMEM);
4152 rc = fld_server_init(env, ss->ss_server_fld, m->mdt_bottom, uuid,
4153 ss->ss_node_id, LU_SEQ_RANGE_MDT);
4155 OBD_FREE_PTR(ss->ss_server_fld);
4156 ss->ss_server_fld = NULL;
4163 static void mdt_stack_pre_fini(const struct lu_env *env,
4164 struct mdt_device *m, struct lu_device *top)
4166 struct obd_device *obd = mdt2obd_dev(m);
4167 struct lustre_cfg_bufs *bufs;
4168 struct lustre_cfg *lcfg;
4169 struct mdt_thread_info *info;
4174 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
4175 LASSERT(info != NULL);
4177 bufs = &info->mti_u.bufs;
4179 LASSERT(m->mdt_child_exp);
4180 LASSERT(m->mdt_child_exp->exp_obd);
4181 obd = m->mdt_child_exp->exp_obd;
4183 /* process cleanup, pass mdt obd name to get obd umount flags */
4184 /* XXX: this is needed because all layers are referenced by
4185 * objects (some of them are pinned by osd, for example *
4186 * the proper solution should be a model where object used
4187 * by osd only doesn't have mdt/mdd slices -bzzz */
4188 lustre_cfg_bufs_reset(bufs, mdt_obd_name(m));
4189 lustre_cfg_bufs_set_string(bufs, 1, NULL);
4190 lcfg = lustre_cfg_new(LCFG_PRE_CLEANUP, bufs);
4192 CERROR("%s:Cannot alloc lcfg!\n", mdt_obd_name(m));
4195 top->ld_ops->ldo_process_config(env, top, lcfg);
4196 lustre_cfg_free(lcfg);
4200 static void mdt_stack_fini(const struct lu_env *env,
4201 struct mdt_device *m, struct lu_device *top)
4203 struct obd_device *obd = mdt2obd_dev(m);
4204 struct lustre_cfg_bufs *bufs;
4205 struct lustre_cfg *lcfg;
4206 struct mdt_thread_info *info;
4210 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
4211 LASSERT(info != NULL);
4213 lu_dev_del_linkage(top->ld_site, top);
4215 lu_site_purge(env, top->ld_site, -1);
4217 bufs = &info->mti_u.bufs;
4218 /* process cleanup, pass mdt obd name to get obd umount flags */
4219 /* another purpose is to let all layers to release their objects */
4220 lustre_cfg_bufs_reset(bufs, mdt_obd_name(m));
4225 lustre_cfg_bufs_set_string(bufs, 1, flags);
4226 lcfg = lustre_cfg_new(LCFG_CLEANUP, bufs);
4228 CERROR("Cannot alloc lcfg!\n");
4232 top->ld_ops->ldo_process_config(env, top, lcfg);
4233 lustre_cfg_free(lcfg);
4235 lu_site_purge(env, top->ld_site, -1);
4237 m->mdt_child = NULL;
4238 m->mdt_bottom = NULL;
4240 obd_disconnect(m->mdt_child_exp);
4241 m->mdt_child_exp = NULL;
4243 obd_disconnect(m->mdt_bottom_exp);
4244 m->mdt_child_exp = NULL;
4247 static int mdt_connect_to_next(const struct lu_env *env, struct mdt_device *m,
4248 const char *next, struct obd_export **exp)
4250 struct obd_connect_data *data = NULL;
4251 struct obd_device *obd;
4255 OBD_ALLOC_PTR(data);
4257 GOTO(out, rc = -ENOMEM);
4259 obd = class_name2obd(next);
4261 CERROR("%s: can't locate next device: %s\n",
4262 mdt_obd_name(m), next);
4263 GOTO(out, rc = -ENOTCONN);
4266 data->ocd_connect_flags = OBD_CONNECT_VERSION;
4267 data->ocd_version = LUSTRE_VERSION_CODE;
4269 rc = obd_connect(NULL, exp, obd, &obd->obd_uuid, data, NULL);
4271 CERROR("%s: cannot connect to next dev %s (%d)\n",
4272 mdt_obd_name(m), next, rc);
4282 static int mdt_stack_init(const struct lu_env *env, struct mdt_device *mdt,
4283 struct lustre_cfg *cfg)
4285 char *dev = lustre_cfg_string(cfg, 0);
4286 int rc, name_size, uuid_size;
4287 char *name, *uuid, *p;
4288 struct lustre_cfg_bufs *bufs;
4289 struct lustre_cfg *lcfg;
4290 struct obd_device *obd;
4291 struct lustre_profile *lprof;
4292 struct lu_site *site;
4295 /* in 1.8 we had the only device in the stack - MDS.
4296 * 2.0 introduces MDT, MDD, OSD; MDT starts others internally.
4297 * in 2.3 OSD is instantiated by obd_mount.c, so we need
4298 * to generate names and setup MDT, MDD. MDT will be using
4299 * generated name to connect to MDD. for MDD the next device
4300 * will be LOD with name taken from so called "profile" which
4301 * is generated by mount_option line
4303 * 1.8 MGS generates config. commands like this:
4304 * #06 (104)mount_option 0: 1:lustre-MDT0000 2:lustre-mdtlov
4305 * #08 (120)setup 0:lustre-MDT0000 1:dev 2:type 3:lustre-MDT0000
4306 * 2.0 MGS generates config. commands like this:
4307 * #07 (112)mount_option 0: 1:lustre-MDT0000 2:lustre-MDT0000-mdtlov
4308 * #08 (160)setup 0:lustre-MDT0000 1:lustre-MDT0000_UUID 2:0
4309 * 3:lustre-MDT0000-mdtlov 4:f
4311 * we generate MDD name from MDT one, just replacing T with D
4313 * after all the preparations, the logical equivalent will be
4314 * #01 (160)setup 0:lustre-MDD0000 1:lustre-MDD0000_UUID 2:0
4315 * 3:lustre-MDT0000-mdtlov 4:f
4316 * #02 (160)setup 0:lustre-MDT0000 1:lustre-MDT0000_UUID 2:0
4317 * 3:lustre-MDD0000 4:f
4319 * notice we build the stack from down to top: MDD first, then MDT */
4321 name_size = MAX_OBD_NAME;
4322 uuid_size = MAX_OBD_NAME;
4324 OBD_ALLOC(name, name_size);
4325 OBD_ALLOC(uuid, uuid_size);
4326 if (name == NULL || uuid == NULL)
4327 GOTO(cleanup_mem, rc = -ENOMEM);
4329 OBD_ALLOC_PTR(bufs);
4331 GOTO(cleanup_mem, rc = -ENOMEM);
4334 p = strstr(name, "-MDT");
4336 GOTO(cleanup_mem, rc = -ENOMEM);
4339 snprintf(uuid, MAX_OBD_NAME, "%s_UUID", name);
4341 lprof = class_get_profile(lustre_cfg_string(cfg, 0));
4342 if (lprof == NULL || lprof->lp_dt == NULL) {
4343 CERROR("can't find the profile: %s\n",
4344 lustre_cfg_string(cfg, 0));
4345 GOTO(cleanup_mem, rc = -EINVAL);
4348 lustre_cfg_bufs_reset(bufs, name);
4349 lustre_cfg_bufs_set_string(bufs, 1, LUSTRE_MDD_NAME);
4350 lustre_cfg_bufs_set_string(bufs, 2, uuid);
4351 lustre_cfg_bufs_set_string(bufs, 3, lprof->lp_dt);
4353 lcfg = lustre_cfg_new(LCFG_ATTACH, bufs);
4355 GOTO(free_bufs, rc = -ENOMEM);
4357 rc = class_attach(lcfg);
4359 GOTO(lcfg_cleanup, rc);
4361 obd = class_name2obd(name);
4363 CERROR("Can not find obd %s (%s in config)\n",
4364 MDD_OBD_NAME, lustre_cfg_string(cfg, 0));
4365 GOTO(class_detach, rc = -EINVAL);
4368 lustre_cfg_free(lcfg);
4370 lustre_cfg_bufs_reset(bufs, name);
4371 lustre_cfg_bufs_set_string(bufs, 1, uuid);
4372 lustre_cfg_bufs_set_string(bufs, 2, dev);
4373 lustre_cfg_bufs_set_string(bufs, 3, lprof->lp_dt);
4375 lcfg = lustre_cfg_new(LCFG_SETUP, bufs);
4377 rc = class_setup(obd, lcfg);
4379 GOTO(class_detach, rc);
4381 /* connect to MDD we just setup */
4382 rc = mdt_connect_to_next(env, mdt, name, &mdt->mdt_child_exp);
4386 site = mdt->mdt_child_exp->exp_obd->obd_lu_dev->ld_site;
4388 LASSERT(mdt_lu_site(mdt) == NULL);
4389 mdt->mdt_md_dev.md_lu_dev.ld_site = site;
4390 site->ls_top_dev = &mdt->mdt_md_dev.md_lu_dev;
4391 mdt->mdt_child = lu2md_dev(mdt->mdt_child_exp->exp_obd->obd_lu_dev);
4394 /* now connect to bottom OSD */
4395 snprintf(name, MAX_OBD_NAME, "%s-osd", dev);
4396 rc = mdt_connect_to_next(env, mdt, name, &mdt->mdt_bottom_exp);
4400 lu2dt_dev(mdt->mdt_bottom_exp->exp_obd->obd_lu_dev);
4403 rc = lu_env_refill((struct lu_env *)env);
4405 CERROR("Failure to refill session: '%d'\n", rc);
4407 lu_dev_add_linkage(site, &mdt->mdt_md_dev.md_lu_dev);
4412 class_detach(obd, lcfg);
4414 lustre_cfg_free(lcfg);
4419 OBD_FREE(name, name_size);
4421 OBD_FREE(uuid, uuid_size);
4425 /* setup quota master target on MDT0 */
4426 static int mdt_quota_init(const struct lu_env *env, struct mdt_device *mdt,
4427 struct lustre_cfg *cfg)
4429 struct obd_device *obd;
4430 char *dev = lustre_cfg_string(cfg, 0);
4431 char *qmtname, *uuid, *p;
4432 struct lustre_cfg_bufs *bufs;
4433 struct lustre_cfg *lcfg;
4434 struct lustre_profile *lprof;
4435 struct obd_connect_data *data;
4439 LASSERT(mdt->mdt_qmt_exp == NULL);
4440 LASSERT(mdt->mdt_qmt_dev == NULL);
4442 /* quota master is on MDT0 only for now */
4443 if (mdt->mdt_seq_site.ss_node_id != 0)
4446 /* MGS generates config commands which look as follows:
4447 * #01 (160)setup 0:lustre-MDT0000 1:lustre-MDT0000_UUID 2:0
4448 * 3:lustre-MDT0000-mdtlov 4:f
4450 * We generate the QMT name from the MDT one, just replacing MD with QM
4451 * after all the preparations, the logical equivalent will be:
4452 * #01 (160)setup 0:lustre-QMT0000 1:lustre-QMT0000_UUID 2:0
4453 * 3:lustre-MDT0000-osd 4:f */
4454 OBD_ALLOC(qmtname, MAX_OBD_NAME);
4455 OBD_ALLOC(uuid, UUID_MAX);
4456 OBD_ALLOC_PTR(bufs);
4457 OBD_ALLOC_PTR(data);
4458 if (qmtname == NULL || uuid == NULL || bufs == NULL || data == NULL)
4459 GOTO(cleanup_mem, rc = -ENOMEM);
4461 strcpy(qmtname, dev);
4462 p = strstr(qmtname, "-MDT");
4464 GOTO(cleanup_mem, rc = -ENOMEM);
4465 /* replace MD with QM */
4469 snprintf(uuid, UUID_MAX, "%s_UUID", qmtname);
4471 lprof = class_get_profile(lustre_cfg_string(cfg, 0));
4472 if (lprof == NULL || lprof->lp_dt == NULL) {
4473 CERROR("can't find profile for %s\n",
4474 lustre_cfg_string(cfg, 0));
4475 GOTO(cleanup_mem, rc = -EINVAL);
4478 lustre_cfg_bufs_reset(bufs, qmtname);
4479 lustre_cfg_bufs_set_string(bufs, 1, LUSTRE_QMT_NAME);
4480 lustre_cfg_bufs_set_string(bufs, 2, uuid);
4481 lustre_cfg_bufs_set_string(bufs, 3, lprof->lp_dt);
4483 lcfg = lustre_cfg_new(LCFG_ATTACH, bufs);
4485 GOTO(cleanup_mem, rc = -ENOMEM);
4487 rc = class_attach(lcfg);
4489 GOTO(lcfg_cleanup, rc);
4491 obd = class_name2obd(qmtname);
4493 CERROR("Can not find obd %s (%s in config)\n", qmtname,
4494 lustre_cfg_string(cfg, 0));
4495 GOTO(class_detach, rc = -EINVAL);
4498 lustre_cfg_free(lcfg);
4500 lustre_cfg_bufs_reset(bufs, qmtname);
4501 lustre_cfg_bufs_set_string(bufs, 1, uuid);
4502 lustre_cfg_bufs_set_string(bufs, 2, dev);
4504 /* for quota, the next device should be the OSD device */
4505 lustre_cfg_bufs_set_string(bufs, 3,
4506 mdt->mdt_bottom->dd_lu_dev.ld_obd->obd_name);
4508 lcfg = lustre_cfg_new(LCFG_SETUP, bufs);
4510 rc = class_setup(obd, lcfg);
4512 GOTO(class_detach, rc);
4514 mdt->mdt_qmt_dev = obd->obd_lu_dev;
4516 /* configure local quota objects */
4517 rc = mdt->mdt_qmt_dev->ld_ops->ldo_prepare(env,
4518 &mdt->mdt_md_dev.md_lu_dev,
4521 GOTO(class_cleanup, rc);
4523 /* connect to quota master target */
4524 data->ocd_connect_flags = OBD_CONNECT_VERSION;
4525 data->ocd_version = LUSTRE_VERSION_CODE;
4526 rc = obd_connect(NULL, &mdt->mdt_qmt_exp, obd, &obd->obd_uuid,
4529 CERROR("cannot connect to quota master device %s (%d)\n",
4531 GOTO(class_cleanup, rc);
4537 class_manual_cleanup(obd);
4538 mdt->mdt_qmt_dev = NULL;
4542 class_detach(obd, lcfg);
4544 lustre_cfg_free(lcfg);
4549 OBD_FREE(qmtname, MAX_OBD_NAME);
4551 OBD_FREE(uuid, UUID_MAX);
4557 /* Shutdown quota master target associated with mdt */
4558 static void mdt_quota_fini(const struct lu_env *env, struct mdt_device *mdt)
4562 if (mdt->mdt_qmt_exp == NULL)
4564 LASSERT(mdt->mdt_qmt_dev != NULL);
4566 /* the qmt automatically shuts down when the mdt disconnects */
4567 obd_disconnect(mdt->mdt_qmt_exp);
4568 mdt->mdt_qmt_exp = NULL;
4569 mdt->mdt_qmt_dev = NULL;
4573 static void mdt_fini(const struct lu_env *env, struct mdt_device *m)
4575 struct md_device *next = m->mdt_child;
4576 struct lu_device *d = &m->mdt_md_dev.md_lu_dev;
4577 struct obd_device *obd = mdt2obd_dev(m);
4580 target_recovery_fini(obd);
4582 ping_evictor_stop();
4585 mdt_stack_pre_fini(env, m, md2lu_dev(m->mdt_child));
4586 mdt_llog_ctxt_unclone(env, m, LLOG_CHANGELOG_ORIG_CTXT);
4587 obd_exports_barrier(obd);
4588 obd_zombie_barrier();
4592 tgt_fini(env, &m->mdt_lut);
4593 mdt_fs_cleanup(env, m);
4594 upcall_cache_cleanup(m->mdt_identity_cache);
4595 m->mdt_identity_cache = NULL;
4597 if (m->mdt_namespace != NULL) {
4598 ldlm_namespace_free(m->mdt_namespace, NULL,
4599 d->ld_obd->obd_force);
4600 d->ld_obd->obd_namespace = m->mdt_namespace = NULL;
4603 mdt_quota_fini(env, m);
4605 cfs_free_nidlist(&m->mdt_nosquash_nids);
4606 if (m->mdt_nosquash_str) {
4607 OBD_FREE(m->mdt_nosquash_str, m->mdt_nosquash_strlen);
4608 m->mdt_nosquash_str = NULL;
4609 m->mdt_nosquash_strlen = 0;
4612 next->md_ops->mdo_iocontrol(env, next, OBD_IOC_PAUSE_LFSCK,
4614 mdt_seq_fini(env, m);
4615 mdt_fld_fini(env, m);
4616 sptlrpc_rule_set_free(&m->mdt_sptlrpc_rset);
4618 next->md_ops->mdo_init_capa_ctxt(env, next, 0, 0, 0, NULL);
4619 cfs_timer_disarm(&m->mdt_ck_timer);
4620 mdt_ck_thread_stop(m);
4625 mdt_stack_fini(env, m, md2lu_dev(m->mdt_child));
4627 LASSERT(cfs_atomic_read(&d->ld_ref) == 0);
4629 server_put_mount(mdt_obd_name(m), NULL);
4634 static int mdt_adapt_sptlrpc_conf(struct obd_device *obd, int initial)
4636 struct mdt_device *m = mdt_dev(obd->obd_lu_dev);
4637 struct sptlrpc_rule_set tmp_rset;
4640 sptlrpc_rule_set_init(&tmp_rset);
4641 rc = sptlrpc_conf_target_get_rules(obd, &tmp_rset, initial);
4643 CERROR("mdt %s: failed get sptlrpc rules: %d\n",
4644 mdt_obd_name(m), rc);
4648 sptlrpc_target_update_exp_flavor(obd, &tmp_rset);
4650 write_lock(&m->mdt_sptlrpc_lock);
4651 sptlrpc_rule_set_free(&m->mdt_sptlrpc_rset);
4652 m->mdt_sptlrpc_rset = tmp_rset;
4653 write_unlock(&m->mdt_sptlrpc_lock);
4658 int mdt_postrecov(const struct lu_env *, struct mdt_device *);
4660 static int mdt_init0(const struct lu_env *env, struct mdt_device *m,
4661 struct lu_device_type *ldt, struct lustre_cfg *cfg)
4663 struct mdt_thread_info *info;
4664 struct obd_device *obd;
4665 const char *dev = lustre_cfg_string(cfg, 0);
4666 const char *num = lustre_cfg_string(cfg, 2);
4667 struct lustre_mount_info *lmi = NULL;
4668 struct lustre_sb_info *lsi;
4670 struct seq_server_site *ss_site;
4671 const char *identity_upcall = "NONE";
4672 struct md_device *next;
4678 md_device_init(&m->mdt_md_dev, ldt);
4680 * Environment (env) might be missing mdt_thread_key values at that
4681 * point, if device is allocated when mdt_thread_key is in QUIESCENT
4684 * Usually device allocation path doesn't use module key values, but
4685 * mdt has to do a lot of work here, so allocate key value.
4687 rc = lu_env_refill((struct lu_env *)env);
4691 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
4692 LASSERT(info != NULL);
4694 obd = class_name2obd(dev);
4695 LASSERT(obd != NULL);
4697 m->mdt_max_mdsize = MAX_MD_SIZE; /* 4 stripes */
4699 m->mdt_som_conf = 0;
4701 m->mdt_opts.mo_cos = MDT_COS_DEFAULT;
4702 lmi = server_get_mount(dev);
4704 CERROR("Cannot get mount info for %s!\n", dev);
4707 lsi = s2lsi(lmi->lmi_sb);
4708 /* CMD is supported only in IAM mode */
4710 node_id = simple_strtol(num, NULL, 10);
4711 obd->u.obt.obt_magic = OBT_MAGIC;
4714 rwlock_init(&m->mdt_sptlrpc_lock);
4715 sptlrpc_rule_set_init(&m->mdt_sptlrpc_rset);
4717 spin_lock_init(&m->mdt_ioepoch_lock);
4718 m->mdt_opts.mo_compat_resname = 0;
4719 m->mdt_opts.mo_mds_capa = 1;
4720 m->mdt_opts.mo_oss_capa = 1;
4721 m->mdt_capa_timeout = CAPA_TIMEOUT;
4722 m->mdt_capa_alg = CAPA_HMAC_ALG_SHA1;
4723 m->mdt_ck_timeout = CAPA_KEY_TIMEOUT;
4724 m->mdt_squash_uid = 0;
4725 m->mdt_squash_gid = 0;
4726 CFS_INIT_LIST_HEAD(&m->mdt_nosquash_nids);
4727 m->mdt_nosquash_str = NULL;
4728 m->mdt_nosquash_strlen = 0;
4729 init_rwsem(&m->mdt_squash_sem);
4730 spin_lock_init(&m->mdt_osfs_lock);
4731 m->mdt_osfs_age = cfs_time_shift_64(-1000);
4732 m->mdt_enable_remote_dir = 0;
4733 m->mdt_enable_remote_dir_gid = 0;
4735 m->mdt_md_dev.md_lu_dev.ld_ops = &mdt_lu_ops;
4736 m->mdt_md_dev.md_lu_dev.ld_obd = obd;
4737 /* set this lu_device to obd, because error handling need it */
4738 obd->obd_lu_dev = &m->mdt_md_dev.md_lu_dev;
4740 /* init the stack */
4741 rc = mdt_stack_init((struct lu_env *)env, m, cfg);
4743 CERROR("%s: Can't init device stack, rc %d\n",
4744 mdt_obd_name(m), rc);
4749 ss_site = mdt_seq_site(m);
4750 s->ld_seq_site = ss_site;
4753 /* set server index */
4754 ss_site->ss_node_id = node_id;
4756 /* failover is the default
4757 * FIXME: we do not failout mds0/mgs, which may cause some problems.
4758 * assumed whose ss_node_id == 0 XXX
4760 obd->obd_replayable = 1;
4761 /* No connection accepted until configurations will finish */
4762 obd->obd_no_conn = 1;
4764 if (cfg->lcfg_bufcount > 4 && LUSTRE_CFG_BUFLEN(cfg, 4) > 0) {
4765 char *str = lustre_cfg_string(cfg, 4);
4766 if (strchr(str, 'n')) {
4767 CWARN("%s: recovery disabled\n", mdt_obd_name(m));
4768 obd->obd_replayable = 0;
4772 rc = tgt_init(env, &m->mdt_lut, obd, m->mdt_bottom);
4774 GOTO(err_fini_stack, rc);
4776 rc = mdt_fld_init(env, mdt_obd_name(m), m);
4780 rc = mdt_seq_init(env, mdt_obd_name(m), m);
4782 GOTO(err_fini_fld, rc);
4784 snprintf(info->mti_u.ns_name, sizeof(info->mti_u.ns_name), "%s-%s",
4785 LUSTRE_MDT_NAME, obd->obd_uuid.uuid);
4786 m->mdt_namespace = ldlm_namespace_new(obd, info->mti_u.ns_name,
4787 LDLM_NAMESPACE_SERVER,
4788 LDLM_NAMESPACE_GREEDY,
4790 if (m->mdt_namespace == NULL)
4791 GOTO(err_fini_seq, rc = -ENOMEM);
4793 m->mdt_namespace->ns_lvbp = m;
4794 m->mdt_namespace->ns_lvbo = &mdt_lvbo;
4796 ldlm_register_intent(m->mdt_namespace, mdt_intent_policy);
4797 /* set obd_namespace for compatibility with old code */
4798 obd->obd_namespace = m->mdt_namespace;
4800 cfs_timer_init(&m->mdt_ck_timer, mdt_ck_timer_callback, m);
4802 rc = mdt_ck_thread_start(m);
4804 GOTO(err_free_ns, rc);
4806 rc = mdt_fs_setup(env, m, obd, lsi);
4810 mdt_adapt_sptlrpc_conf(obd, 1);
4812 next = m->mdt_child;
4813 rc = next->md_ops->mdo_iocontrol(env, next, OBD_IOC_GET_MNTOPT, 0,
4816 GOTO(err_llog_cleanup, rc);
4818 if (mntopts & MNTOPT_USERXATTR)
4819 m->mdt_opts.mo_user_xattr = 1;
4821 m->mdt_opts.mo_user_xattr = 0;
4823 if (mntopts & MNTOPT_ACL)
4824 m->mdt_opts.mo_acl = 1;
4826 m->mdt_opts.mo_acl = 0;
4828 /* XXX: to support suppgid for ACL, we enable identity_upcall
4829 * by default, otherwise, maybe got unexpected -EACCESS. */
4830 if (m->mdt_opts.mo_acl)
4831 identity_upcall = MDT_IDENTITY_UPCALL_PATH;
4833 m->mdt_identity_cache = upcall_cache_init(mdt_obd_name(m),
4835 &mdt_identity_upcall_cache_ops);
4836 if (IS_ERR(m->mdt_identity_cache)) {
4837 rc = PTR_ERR(m->mdt_identity_cache);
4838 m->mdt_identity_cache = NULL;
4839 GOTO(err_llog_cleanup, rc);
4842 rc = mdt_procfs_init(m, dev);
4844 CERROR("Can't init MDT lprocfs, rc %d\n", rc);
4845 GOTO(err_recovery, rc);
4848 rc = mdt_quota_init(env, m, cfg);
4850 GOTO(err_procfs, rc);
4852 m->mdt_ldlm_client = &mdt2obd_dev(m)->obd_ldlm_client;
4853 ptlrpc_init_client(LDLM_CB_REQUEST_PORTAL, LDLM_CB_REPLY_PORTAL,
4854 "mdt_ldlm_client", m->mdt_ldlm_client);
4856 ping_evictor_start();
4858 /* recovery will be started upon mdt_prepare()
4859 * when the whole stack is complete and ready
4860 * to serve the requests */
4862 mdt_init_capa_ctxt(env, m);
4864 /* Reduce the initial timeout on an MDS because it doesn't need such
4865 * a long timeout as an OST does. Adaptive timeouts will adjust this
4866 * value appropriately. */
4867 if (ldlm_timeout == LDLM_TIMEOUT_DEFAULT)
4868 ldlm_timeout = MDS_LDLM_TIMEOUT_DEFAULT;
4875 target_recovery_fini(obd);
4876 upcall_cache_cleanup(m->mdt_identity_cache);
4877 m->mdt_identity_cache = NULL;
4879 mdt_llog_ctxt_unclone(env, m, LLOG_CHANGELOG_ORIG_CTXT);
4880 mdt_fs_cleanup(env, m);
4882 cfs_timer_disarm(&m->mdt_ck_timer);
4883 mdt_ck_thread_stop(m);
4885 ldlm_namespace_free(m->mdt_namespace, NULL, 0);
4886 obd->obd_namespace = m->mdt_namespace = NULL;
4888 mdt_seq_fini(env, m);
4890 mdt_fld_fini(env, m);
4892 tgt_fini(env, &m->mdt_lut);
4894 mdt_stack_fini(env, m, md2lu_dev(m->mdt_child));
4897 server_put_mount(dev, lmi->lmi_mnt);
4901 /* For interoperability, the left element is old parameter, the right one
4902 * is the new version of the parameter, if some parameter is deprecated,
4903 * the new version should be set as NULL. */
4904 static struct cfg_interop_param mdt_interop_param[] = {
4905 { "mdt.group_upcall", NULL },
4906 { "mdt.quota_type", NULL },
4907 { "mdd.quota_type", NULL },
4908 { "mdt.rootsquash", "mdt.root_squash" },
4909 { "mdt.nosquash_nid", "mdt.nosquash_nids" },
4913 /* used by MGS to process specific configurations */
4914 static int mdt_process_config(const struct lu_env *env,
4915 struct lu_device *d, struct lustre_cfg *cfg)
4917 struct mdt_device *m = mdt_dev(d);
4918 struct md_device *md_next = m->mdt_child;
4919 struct lu_device *next = md2lu_dev(md_next);
4923 switch (cfg->lcfg_command) {
4925 struct lprocfs_static_vars lvars;
4926 struct obd_device *obd = d->ld_obd;
4928 /* For interoperability */
4929 struct cfg_interop_param *ptr = NULL;
4930 struct lustre_cfg *old_cfg = NULL;
4933 param = lustre_cfg_string(cfg, 1);
4934 if (param == NULL) {
4935 CERROR("param is empty\n");
4940 ptr = class_find_old_param(param, mdt_interop_param);
4942 if (ptr->new_param == NULL) {
4944 CWARN("For interoperability, skip this %s."
4945 " It is obsolete.\n", ptr->old_param);
4949 CWARN("Found old param %s, changed it to %s.\n",
4950 ptr->old_param, ptr->new_param);
4953 cfg = lustre_cfg_rename(old_cfg, ptr->new_param);
4960 lprocfs_mdt_init_vars(&lvars);
4961 rc = class_process_proc_param(PARAM_MDT, lvars.obd_vars,
4963 if (rc > 0 || rc == -ENOSYS)
4964 /* we don't understand; pass it on */
4965 rc = next->ld_ops->ldo_process_config(env, next, cfg);
4967 if (old_cfg != NULL)
4968 lustre_cfg_free(cfg);
4973 /* others are passed further */
4974 rc = next->ld_ops->ldo_process_config(env, next, cfg);
4980 static struct lu_object *mdt_object_alloc(const struct lu_env *env,
4981 const struct lu_object_header *hdr,
4982 struct lu_device *d)
4984 struct mdt_object *mo;
4988 OBD_SLAB_ALLOC_PTR_GFP(mo, mdt_object_kmem, CFS_ALLOC_IO);
4990 struct lu_object *o;
4991 struct lu_object_header *h;
4993 o = &mo->mot_obj.mo_lu;
4994 h = &mo->mot_header;
4995 lu_object_header_init(h);
4996 lu_object_init(o, h, d);
4997 lu_object_add_top(h, o);
4998 o->lo_ops = &mdt_obj_ops;
4999 mutex_init(&mo->mot_ioepoch_mutex);
5000 mutex_init(&mo->mot_lov_mutex);
5006 static int mdt_object_init(const struct lu_env *env, struct lu_object *o,
5007 const struct lu_object_conf *unused)
5009 struct mdt_device *d = mdt_dev(o->lo_dev);
5010 struct lu_device *under;
5011 struct lu_object *below;
5015 CDEBUG(D_INFO, "object init, fid = "DFID"\n",
5016 PFID(lu_object_fid(o)));
5018 under = &d->mdt_child->md_lu_dev;
5019 below = under->ld_ops->ldo_object_alloc(env, o->lo_header, under);
5020 if (below != NULL) {
5021 lu_object_add(o, below);
5028 static void mdt_object_free(const struct lu_env *env, struct lu_object *o)
5030 struct mdt_object *mo = mdt_obj(o);
5031 struct lu_object_header *h;
5035 CDEBUG(D_INFO, "object free, fid = "DFID"\n",
5036 PFID(lu_object_fid(o)));
5039 lu_object_header_fini(h);
5040 OBD_SLAB_FREE_PTR(mo, mdt_object_kmem);
5045 static int mdt_object_print(const struct lu_env *env, void *cookie,
5046 lu_printer_t p, const struct lu_object *o)
5048 struct mdt_object *mdto = mdt_obj((struct lu_object *)o);
5049 return (*p)(env, cookie, LUSTRE_MDT_NAME"-object@%p(ioepoch="LPU64" "
5050 "flags="LPX64", epochcount=%d, writecount=%d)",
5051 mdto, mdto->mot_ioepoch, mdto->mot_flags,
5052 mdto->mot_ioepoch_count, mdto->mot_writecount);
5055 static int mdt_prepare(const struct lu_env *env,
5056 struct lu_device *pdev,
5057 struct lu_device *cdev)
5059 struct mdt_device *mdt = mdt_dev(cdev);
5060 struct lu_device *next = &mdt->mdt_child->md_lu_dev;
5061 struct obd_device *obd = cdev->ld_obd;
5068 rc = next->ld_ops->ldo_prepare(env, cdev, next);
5072 rc = mdt_llog_ctxt_clone(env, mdt, LLOG_CHANGELOG_ORIG_CTXT);
5076 rc = mdt->mdt_child->md_ops->mdo_iocontrol(env, mdt->mdt_child,
5077 OBD_IOC_START_LFSCK,
5080 CWARN("%s: auto trigger paused LFSCK failed: rc = %d\n",
5081 mdt_obd_name(mdt), rc);
5085 if (mdt->mdt_seq_site.ss_node_id == 0) {
5086 rc = mdt->mdt_child->md_ops->mdo_root_get(env, mdt->mdt_child,
5087 &mdt->mdt_md_root_fid);
5091 LASSERT(!test_bit(MDT_FL_CFGLOG, &mdt->mdt_state));
5092 target_recovery_init(&mdt->mdt_lut, mdt_recovery_handle);
5093 set_bit(MDT_FL_CFGLOG, &mdt->mdt_state);
5094 LASSERT(obd->obd_no_conn);
5095 spin_lock(&obd->obd_dev_lock);
5096 obd->obd_no_conn = 0;
5097 spin_unlock(&obd->obd_dev_lock);
5099 if (obd->obd_recovering == 0)
5100 mdt_postrecov(env, mdt);
5105 const struct lu_device_operations mdt_lu_ops = {
5106 .ldo_object_alloc = mdt_object_alloc,
5107 .ldo_process_config = mdt_process_config,
5108 .ldo_prepare = mdt_prepare,
5111 static const struct lu_object_operations mdt_obj_ops = {
5112 .loo_object_init = mdt_object_init,
5113 .loo_object_free = mdt_object_free,
5114 .loo_object_print = mdt_object_print
5117 static int mdt_obd_set_info_async(const struct lu_env *env,
5118 struct obd_export *exp,
5119 __u32 keylen, void *key,
5120 __u32 vallen, void *val,
5121 struct ptlrpc_request_set *set)
5123 struct obd_device *obd = exp->exp_obd;
5129 if (KEY_IS(KEY_SPTLRPC_CONF)) {
5130 rc = mdt_adapt_sptlrpc_conf(obd, 0);
5138 * Match client and server connection feature flags.
5140 * Compute the compatibility flags for a connection request based on
5141 * features mutually supported by client and server.
5143 * The obd_export::exp_connect_data.ocd_connect_flags field in \a exp
5144 * must not be updated here, otherwise a partially initialized value may
5145 * be exposed. After the connection request is successfully processed,
5146 * the top-level MDT connect request handler atomically updates the export
5147 * connect flags from the obd_connect_data::ocd_connect_flags field of the
5148 * reply. \see mdt_connect().
5150 * \param exp the obd_export associated with this client/target pair
5151 * \param mdt the target device for the connection
5152 * \param data stores data for this connect request
5155 * \retval -EPROTO \a data unexpectedly has zero obd_connect_data::ocd_brw_size
5156 * \retval -EBADE client and server feature requirements are incompatible
5158 static int mdt_connect_internal(struct obd_export *exp,
5159 struct mdt_device *mdt,
5160 struct obd_connect_data *data)
5162 LASSERT(data != NULL);
5164 data->ocd_connect_flags &= MDT_CONNECT_SUPPORTED;
5165 data->ocd_ibits_known &= MDS_INODELOCK_FULL;
5167 /* If no known bits (which should not happen, probably,
5168 as everybody should support LOOKUP and UPDATE bits at least)
5169 revert to compat mode with plain locks. */
5170 if (!data->ocd_ibits_known &&
5171 data->ocd_connect_flags & OBD_CONNECT_IBITS)
5172 data->ocd_connect_flags &= ~OBD_CONNECT_IBITS;
5174 if (!mdt->mdt_opts.mo_acl)
5175 data->ocd_connect_flags &= ~OBD_CONNECT_ACL;
5177 if (!mdt->mdt_opts.mo_user_xattr)
5178 data->ocd_connect_flags &= ~OBD_CONNECT_XATTR;
5180 if (!mdt->mdt_som_conf)
5181 data->ocd_connect_flags &= ~OBD_CONNECT_SOM;
5183 if (data->ocd_connect_flags & OBD_CONNECT_BRW_SIZE) {
5184 data->ocd_brw_size = min(data->ocd_brw_size,
5185 (__u32)MD_MAX_BRW_SIZE);
5186 if (data->ocd_brw_size == 0) {
5187 CERROR("%s: cli %s/%p ocd_connect_flags: "LPX64
5188 " ocd_version: %x ocd_grant: %d "
5189 "ocd_index: %u ocd_brw_size is "
5190 "unexpectedly zero, network data "
5191 "corruption? Refusing connection of this"
5194 exp->exp_client_uuid.uuid,
5195 exp, data->ocd_connect_flags, data->ocd_version,
5196 data->ocd_grant, data->ocd_index);
5201 /* NB: Disregard the rule against updating
5202 * exp_connect_data.ocd_connect_flags in this case, since
5203 * tgt_client_new() needs to know if this is a lightweight
5204 * connection, and it is safe to expose this flag before
5205 * connection processing completes. */
5206 if (data->ocd_connect_flags & OBD_CONNECT_LIGHTWEIGHT) {
5207 spin_lock(&exp->exp_lock);
5208 *exp_connect_flags_ptr(exp) |= OBD_CONNECT_LIGHTWEIGHT;
5209 spin_unlock(&exp->exp_lock);
5212 data->ocd_version = LUSTRE_VERSION_CODE;
5213 exp->exp_connect_data = *data;
5214 exp->exp_mdt_data.med_ibits_known = data->ocd_ibits_known;
5216 if ((data->ocd_connect_flags & OBD_CONNECT_FID) == 0) {
5217 CWARN("%s: MDS requires FID support, but client not\n",
5222 if (mdt->mdt_som_conf &&
5223 !(data->ocd_connect_flags & (OBD_CONNECT_LIGHTWEIGHT |
5224 OBD_CONNECT_MDS_MDS |
5225 OBD_CONNECT_SOM))) {
5226 CWARN("%s: MDS has SOM enabled, but client does not support "
5227 "it\n", mdt_obd_name(mdt));
5231 if (OCD_HAS_FLAG(data, PINGLESS)) {
5232 if (ptlrpc_pinger_suppress_pings()) {
5233 spin_lock(&exp->exp_obd->obd_dev_lock);
5234 list_del_init(&exp->exp_obd_chain_timed);
5235 spin_unlock(&exp->exp_obd->obd_dev_lock);
5237 data->ocd_connect_flags &= ~OBD_CONNECT_PINGLESS;
5244 static int mdt_connect_check_sptlrpc(struct mdt_device *mdt,
5245 struct obd_export *exp,
5246 struct ptlrpc_request *req)
5248 struct sptlrpc_flavor flvr;
5251 if (exp->exp_flvr.sf_rpc == SPTLRPC_FLVR_INVALID) {
5252 read_lock(&mdt->mdt_sptlrpc_lock);
5253 sptlrpc_target_choose_flavor(&mdt->mdt_sptlrpc_rset,
5257 read_unlock(&mdt->mdt_sptlrpc_lock);
5259 spin_lock(&exp->exp_lock);
5261 exp->exp_sp_peer = req->rq_sp_from;
5262 exp->exp_flvr = flvr;
5264 if (exp->exp_flvr.sf_rpc != SPTLRPC_FLVR_ANY &&
5265 exp->exp_flvr.sf_rpc != req->rq_flvr.sf_rpc) {
5266 CERROR("unauthorized rpc flavor %x from %s, "
5267 "expect %x\n", req->rq_flvr.sf_rpc,
5268 libcfs_nid2str(req->rq_peer.nid),
5269 exp->exp_flvr.sf_rpc);
5273 spin_unlock(&exp->exp_lock);
5275 if (exp->exp_sp_peer != req->rq_sp_from) {
5276 CERROR("RPC source %s doesn't match %s\n",
5277 sptlrpc_part2name(req->rq_sp_from),
5278 sptlrpc_part2name(exp->exp_sp_peer));
5281 rc = sptlrpc_target_export_check(exp, req);
5288 /* mds_connect copy */
5289 static int mdt_obd_connect(const struct lu_env *env,
5290 struct obd_export **exp, struct obd_device *obd,
5291 struct obd_uuid *cluuid,
5292 struct obd_connect_data *data,
5295 struct mdt_thread_info *info;
5296 struct obd_export *lexp;
5297 struct lustre_handle conn = { 0 };
5298 struct mdt_device *mdt;
5299 struct ptlrpc_request *req;
5303 LASSERT(env != NULL);
5304 if (!exp || !obd || !cluuid)
5307 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
5308 req = info->mti_pill->rc_req;
5309 mdt = mdt_dev(obd->obd_lu_dev);
5312 * first, check whether the stack is ready to handle requests
5313 * XXX: probably not very appropriate method is used now
5314 * at some point we should find a better one
5316 if (!test_bit(MDT_FL_SYNCED, &mdt->mdt_state) &&
5317 !(data->ocd_connect_flags & OBD_CONNECT_LIGHTWEIGHT)) {
5318 rc = obd_health_check(env, mdt->mdt_child_exp->exp_obd);
5321 set_bit(MDT_FL_SYNCED, &mdt->mdt_state);
5324 rc = class_connect(&conn, obd, cluuid);
5328 lexp = class_conn2export(&conn);
5329 LASSERT(lexp != NULL);
5331 rc = mdt_connect_check_sptlrpc(mdt, lexp, req);
5335 if (OBD_FAIL_CHECK(OBD_FAIL_TGT_RCVG_FLAG))
5336 lustre_msg_add_op_flags(req->rq_repmsg, MSG_CONNECT_RECOVERING);
5338 rc = mdt_connect_internal(lexp, mdt, data);
5340 struct lsd_client_data *lcd = lexp->exp_target_data.ted_lcd;
5343 info->mti_exp = lexp;
5344 memcpy(lcd->lcd_uuid, cluuid, sizeof lcd->lcd_uuid);
5345 rc = tgt_client_new(env, lexp);
5347 mdt_export_stats_init(obd, lexp, localdata);
5352 class_disconnect(lexp);
5361 static int mdt_obd_reconnect(const struct lu_env *env,
5362 struct obd_export *exp, struct obd_device *obd,
5363 struct obd_uuid *cluuid,
5364 struct obd_connect_data *data,
5367 struct mdt_thread_info *info;
5368 struct mdt_device *mdt;
5369 struct ptlrpc_request *req;
5373 if (exp == NULL || obd == NULL || cluuid == NULL)
5376 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
5377 req = info->mti_pill->rc_req;
5378 mdt = mdt_dev(obd->obd_lu_dev);
5380 rc = mdt_connect_check_sptlrpc(mdt, exp, req);
5384 rc = mdt_connect_internal(exp, mdt_dev(obd->obd_lu_dev), data);
5386 mdt_export_stats_init(obd, exp, localdata);
5391 static int mdt_export_cleanup(struct obd_export *exp)
5393 struct mdt_export_data *med = &exp->exp_mdt_data;
5394 struct obd_device *obd = exp->exp_obd;
5395 struct mdt_device *mdt;
5396 struct mdt_thread_info *info;
5398 CFS_LIST_HEAD(closing_list);
5399 struct mdt_file_data *mfd, *n;
5403 spin_lock(&med->med_open_lock);
5404 while (!cfs_list_empty(&med->med_open_head)) {
5405 cfs_list_t *tmp = med->med_open_head.next;
5406 mfd = cfs_list_entry(tmp, struct mdt_file_data, mfd_list);
5408 /* Remove mfd handle so it can't be found again.
5409 * We are consuming the mfd_list reference here. */
5410 class_handle_unhash(&mfd->mfd_handle);
5411 cfs_list_move_tail(&mfd->mfd_list, &closing_list);
5413 spin_unlock(&med->med_open_lock);
5414 mdt = mdt_dev(obd->obd_lu_dev);
5415 LASSERT(mdt != NULL);
5417 rc = lu_env_init(&env, LCT_MD_THREAD);
5421 info = lu_context_key_get(&env.le_ctx, &mdt_thread_key);
5422 LASSERT(info != NULL);
5423 memset(info, 0, sizeof *info);
5424 info->mti_env = &env;
5425 info->mti_mdt = mdt;
5426 info->mti_exp = exp;
5428 if (!cfs_list_empty(&closing_list)) {
5429 struct md_attr *ma = &info->mti_attr;
5431 /* Close any open files (which may also cause orphan unlinking). */
5432 cfs_list_for_each_entry_safe(mfd, n, &closing_list, mfd_list) {
5433 cfs_list_del_init(&mfd->mfd_list);
5434 ma->ma_need = ma->ma_valid = 0;
5435 /* Don't unlink orphan on failover umount, LU-184 */
5436 if (exp->exp_flags & OBD_OPT_FAILOVER) {
5437 ma->ma_valid = MA_FLAGS;
5438 ma->ma_attr_flags |= MDS_KEEP_ORPHAN;
5440 mdt_mfd_close(info, mfd);
5443 info->mti_mdt = NULL;
5444 /* cleanup client slot early */
5445 /* Do not erase record for recoverable client. */
5446 if (!(exp->exp_flags & OBD_OPT_FAILOVER) || exp->exp_failed)
5447 tgt_client_del(&env, exp);
5453 static int mdt_obd_disconnect(struct obd_export *exp)
5459 class_export_get(exp);
5461 rc = server_disconnect_export(exp);
5463 CDEBUG(D_IOCTL, "server disconnect error: %d\n", rc);
5465 rc = mdt_export_cleanup(exp);
5466 class_export_put(exp);
5470 /* FIXME: Can we avoid using these two interfaces? */
5471 static int mdt_init_export(struct obd_export *exp)
5473 struct mdt_export_data *med = &exp->exp_mdt_data;
5477 CFS_INIT_LIST_HEAD(&med->med_open_head);
5478 spin_lock_init(&med->med_open_lock);
5479 mutex_init(&med->med_idmap_mutex);
5480 med->med_idmap = NULL;
5481 spin_lock(&exp->exp_lock);
5482 exp->exp_connecting = 1;
5483 spin_unlock(&exp->exp_lock);
5485 /* self-export doesn't need client data and ldlm initialization */
5486 if (unlikely(obd_uuid_equals(&exp->exp_obd->obd_uuid,
5487 &exp->exp_client_uuid)))
5490 rc = tgt_client_alloc(exp);
5494 rc = ldlm_init_export(exp);
5501 tgt_client_free(exp);
5503 CERROR("%s: Failed to initialize export: rc = %d\n",
5504 exp->exp_obd->obd_name, rc);
5508 static int mdt_destroy_export(struct obd_export *exp)
5512 if (exp_connect_rmtclient(exp))
5513 mdt_cleanup_idmap(&exp->exp_mdt_data);
5515 target_destroy_export(exp);
5516 /* destroy can be called from failed obd_setup, so
5517 * checking uuid is safer than obd_self_export */
5518 if (unlikely(obd_uuid_equals(&exp->exp_obd->obd_uuid,
5519 &exp->exp_client_uuid)))
5522 ldlm_destroy_export(exp);
5523 tgt_client_free(exp);
5525 LASSERT(cfs_list_empty(&exp->exp_outstanding_replies));
5526 LASSERT(cfs_list_empty(&exp->exp_mdt_data.med_open_head));
5531 /** The maximum depth that fid2path() will search.
5532 * This is limited only because we want to store the fids for
5533 * historical path lookup purposes.
5535 #define MAX_PATH_DEPTH 100
5537 /** mdt_path() lookup structure. */
5538 struct path_lookup_info {
5539 __u64 pli_recno; /**< history point */
5540 __u64 pli_currec; /**< current record */
5541 struct lu_fid pli_fid;
5542 struct lu_fid pli_fids[MAX_PATH_DEPTH]; /**< path, in fids */
5543 struct mdt_object *pli_mdt_obj;
5544 char *pli_path; /**< full path */
5546 int pli_linkno; /**< which hardlink to follow */
5547 int pli_fidcount; /**< number of \a pli_fids */
5550 static int mdt_links_read(struct mdt_thread_info *info,
5551 struct mdt_object *mdt_obj, struct linkea_data *ldata)
5555 LASSERT(ldata->ld_buf->lb_buf != NULL);
5557 if (!mdt_object_exists(mdt_obj))
5560 rc = mo_xattr_get(info->mti_env, mdt_object_child(mdt_obj),
5561 ldata->ld_buf, XATTR_NAME_LINK);
5562 if (rc == -ERANGE) {
5563 /* Buf was too small, figure out what we need. */
5564 lu_buf_free(ldata->ld_buf);
5565 rc = mo_xattr_get(info->mti_env, mdt_object_child(mdt_obj),
5566 ldata->ld_buf, XATTR_NAME_LINK);
5569 ldata->ld_buf = lu_buf_check_and_alloc(ldata->ld_buf, rc);
5570 if (ldata->ld_buf->lb_buf == NULL)
5572 rc = mo_xattr_get(info->mti_env, mdt_object_child(mdt_obj),
5573 ldata->ld_buf, XATTR_NAME_LINK);
5583 static int mdt_path_current(struct mdt_thread_info *info,
5584 struct path_lookup_info *pli)
5586 struct mdt_device *mdt = info->mti_mdt;
5587 struct mdt_object *mdt_obj;
5588 struct link_ea_header *leh;
5589 struct link_ea_entry *lee;
5590 struct lu_name *tmpname = &info->mti_name;
5591 struct lu_fid *tmpfid = &info->mti_tmp_fid1;
5592 struct lu_buf *buf = &info->mti_big_buf;
5595 struct linkea_data ldata = { 0 };
5599 /* temp buffer for path element, the buffer will be finally freed
5600 * in mdt_thread_info_fini */
5601 buf = lu_buf_check_and_alloc(buf, PATH_MAX);
5602 if (buf->lb_buf == NULL)
5606 ptr = pli->pli_path + pli->pli_pathlen - 1;
5609 pli->pli_fidcount = 0;
5610 pli->pli_fids[0] = *(struct lu_fid *)mdt_object_fid(pli->pli_mdt_obj);
5612 /* root FID only exists on MDT0, and fid2path should also ends at MDT0,
5613 * so checking root_fid can only happen on MDT0. */
5614 while (!lu_fid_eq(&mdt->mdt_md_root_fid,
5615 &pli->pli_fids[pli->pli_fidcount])) {
5616 mdt_obj = mdt_object_find(info->mti_env, mdt,
5617 &pli->pli_fids[pli->pli_fidcount]);
5618 if (IS_ERR(mdt_obj))
5619 GOTO(out, rc = PTR_ERR(mdt_obj));
5620 if (mdt_object_remote(mdt_obj)) {
5621 mdt_object_put(info->mti_env, mdt_obj);
5622 GOTO(remote_out, rc = -EREMOTE);
5624 if (!mdt_object_exists(mdt_obj)) {
5625 mdt_object_put(info->mti_env, mdt_obj);
5626 GOTO(out, rc = -ENOENT);
5629 rc = mdt_links_read(info, mdt_obj, &ldata);
5630 mdt_object_put(info->mti_env, mdt_obj);
5632 GOTO(out, rc = PTR_ERR(buf));
5635 lee = (struct link_ea_entry *)(leh + 1); /* link #0 */
5636 linkea_entry_unpack(lee, &reclen, tmpname, tmpfid);
5637 /* If set, use link #linkno for path lookup, otherwise use
5638 link #0. Only do this for the final path element. */
5639 if ((pli->pli_fidcount == 0) &&
5640 (pli->pli_linkno < leh->leh_reccount)) {
5642 for (count = 0; count < pli->pli_linkno; count++) {
5643 lee = (struct link_ea_entry *)
5644 ((char *)lee + reclen);
5645 linkea_entry_unpack(lee, &reclen, tmpname,
5648 if (pli->pli_linkno < leh->leh_reccount - 1)
5649 /* indicate to user there are more links */
5653 /* Pack the name in the end of the buffer */
5654 ptr -= tmpname->ln_namelen;
5655 if (ptr - 1 <= pli->pli_path)
5656 GOTO(out, rc = -EOVERFLOW);
5657 strncpy(ptr, tmpname->ln_name, tmpname->ln_namelen);
5660 /* Store the parent fid for historic lookup */
5661 if (++pli->pli_fidcount >= MAX_PATH_DEPTH)
5662 GOTO(out, rc = -EOVERFLOW);
5663 pli->pli_fids[pli->pli_fidcount] = *tmpfid;
5667 ptr++; /* skip leading / */
5668 memmove(pli->pli_path, ptr, pli->pli_path + pli->pli_pathlen - ptr);
5675 /* Returns the full path to this fid, as of changelog record recno. */
5676 static int mdt_path(struct mdt_thread_info *info, struct mdt_object *obj,
5677 char *path, int pathlen, __u64 *recno, int *linkno,
5680 struct mdt_device *mdt = info->mti_mdt;
5681 struct path_lookup_info *pli;
5689 if (lu_fid_eq(&mdt->mdt_md_root_fid, mdt_object_fid(obj))) {
5698 pli->pli_mdt_obj = obj;
5699 pli->pli_recno = *recno;
5700 pli->pli_path = path;
5701 pli->pli_pathlen = pathlen;
5702 pli->pli_linkno = *linkno;
5704 /* Retry multiple times in case file is being moved */
5705 while (tries-- && rc == -EAGAIN)
5706 rc = mdt_path_current(info, pli);
5708 /* return the last resolved fids to the client, so the client will
5709 * build the left path on another MDT for remote object */
5710 *fid = pli->pli_fids[pli->pli_fidcount];
5712 *recno = pli->pli_currec;
5713 /* Return next link index to caller */
5714 *linkno = pli->pli_linkno;
5721 static int mdt_fid2path(struct mdt_thread_info *info,
5722 struct getinfo_fid2path *fp)
5724 struct mdt_device *mdt = info->mti_mdt;
5725 struct mdt_object *obj;
5729 CDEBUG(D_IOCTL, "path get "DFID" from "LPU64" #%d\n",
5730 PFID(&fp->gf_fid), fp->gf_recno, fp->gf_linkno);
5732 if (!fid_is_sane(&fp->gf_fid))
5735 if (!fid_is_namespace_visible(&fp->gf_fid)) {
5736 CWARN("%s: "DFID" is invalid, sequence should be "
5737 ">= "LPX64"\n", mdt_obd_name(mdt),
5738 PFID(&fp->gf_fid), (__u64)FID_SEQ_NORMAL);
5742 obj = mdt_object_find(info->mti_env, mdt, &fp->gf_fid);
5743 if (obj == NULL || IS_ERR(obj)) {
5744 CDEBUG(D_IOCTL, "no object "DFID": %ld\n", PFID(&fp->gf_fid),
5749 if (mdt_object_remote(obj))
5751 else if (!mdt_object_exists(obj))
5757 mdt_object_put(info->mti_env, obj);
5758 CDEBUG(D_IOCTL, "nonlocal object "DFID": %d\n",
5759 PFID(&fp->gf_fid), rc);
5763 rc = mdt_path(info, obj, fp->gf_path, fp->gf_pathlen, &fp->gf_recno,
5764 &fp->gf_linkno, &fp->gf_fid);
5766 CDEBUG(D_INFO, "fid "DFID", path %s recno "LPX64" linkno %u\n",
5767 PFID(&fp->gf_fid), fp->gf_path, fp->gf_recno, fp->gf_linkno);
5769 mdt_object_put(info->mti_env, obj);
5774 static int mdt_rpc_fid2path(struct mdt_thread_info *info, void *key,
5775 void *val, int vallen)
5777 struct getinfo_fid2path *fpout, *fpin;
5780 fpin = key + cfs_size_round(sizeof(KEY_FID2PATH));
5783 if (ptlrpc_req_need_swab(info->mti_pill->rc_req))
5784 lustre_swab_fid2path(fpin);
5786 memcpy(fpout, fpin, sizeof(*fpin));
5787 if (fpout->gf_pathlen != vallen - sizeof(*fpin))
5790 rc = mdt_fid2path(info, fpout);
5794 int mdt_get_info(struct mdt_thread_info *info)
5796 struct ptlrpc_request *req = mdt_info_req(info);
5804 key = req_capsule_client_get(info->mti_pill, &RMF_GETINFO_KEY);
5806 CDEBUG(D_IOCTL, "No GETINFO key");
5809 keylen = req_capsule_get_size(info->mti_pill, &RMF_GETINFO_KEY,
5812 vallen = req_capsule_client_get(info->mti_pill, &RMF_GETINFO_VALLEN);
5813 if (vallen == NULL) {
5814 CDEBUG(D_IOCTL, "Unable to get RMF_GETINFO_VALLEN buffer");
5818 req_capsule_set_size(info->mti_pill, &RMF_GETINFO_VAL, RCL_SERVER,
5820 rc = req_capsule_server_pack(info->mti_pill);
5821 valout = req_capsule_server_get(info->mti_pill, &RMF_GETINFO_VAL);
5822 if (valout == NULL) {
5823 CDEBUG(D_IOCTL, "Unable to get get-info RPC out buffer");
5827 if (KEY_IS(KEY_FID2PATH))
5828 rc = mdt_rpc_fid2path(info, key, valout, *vallen);
5832 lustre_msg_set_status(req->rq_repmsg, rc);
5837 /* Pass the ioc down */
5838 static int mdt_ioc_child(struct lu_env *env, struct mdt_device *mdt,
5839 unsigned int cmd, int len, void *data)
5841 struct lu_context ioctl_session;
5842 struct md_device *next = mdt->mdt_child;
5846 rc = lu_context_init(&ioctl_session, LCT_SESSION);
5849 ioctl_session.lc_thread = (struct ptlrpc_thread *)cfs_current();
5850 lu_context_enter(&ioctl_session);
5851 env->le_ses = &ioctl_session;
5853 LASSERT(next->md_ops->mdo_iocontrol);
5854 rc = next->md_ops->mdo_iocontrol(env, next, cmd, len, data);
5856 lu_context_exit(&ioctl_session);
5857 lu_context_fini(&ioctl_session);
5861 static int mdt_ioc_version_get(struct mdt_thread_info *mti, void *karg)
5863 struct obd_ioctl_data *data = karg;
5866 struct mdt_object *obj;
5867 struct mdt_lock_handle *lh;
5871 if (data->ioc_inlbuf1 == NULL || data->ioc_inllen1 != sizeof(*fid) ||
5872 data->ioc_inlbuf2 == NULL || data->ioc_inllen2 != sizeof(version))
5875 fid = (struct lu_fid *)data->ioc_inlbuf1;
5877 if (!fid_is_sane(fid))
5880 CDEBUG(D_IOCTL, "getting version for "DFID"\n", PFID(fid));
5882 lh = &mti->mti_lh[MDT_LH_PARENT];
5883 mdt_lock_reg_init(lh, LCK_CR);
5885 obj = mdt_object_find_lock(mti, fid, lh, MDS_INODELOCK_UPDATE);
5887 RETURN(PTR_ERR(obj));
5889 if (mdt_object_remote(obj)) {
5892 * before calling version get the correct MDS should be
5893 * fid, this is error to find remote object here
5895 CERROR("nonlocal object "DFID"\n", PFID(fid));
5896 } else if (!mdt_object_exists(obj)) {
5897 *(__u64 *)data->ioc_inlbuf2 = ENOENT_VERSION;
5900 version = dt_version_get(mti->mti_env, mdt_obj2dt(obj));
5901 *(__u64 *)data->ioc_inlbuf2 = version;
5904 mdt_object_unlock_put(mti, obj, lh, 1);
5908 /* ioctls on obd dev */
5909 static int mdt_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
5910 void *karg, void *uarg)
5913 struct obd_device *obd = exp->exp_obd;
5914 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
5915 struct dt_device *dt = mdt->mdt_bottom;
5919 CDEBUG(D_IOCTL, "handling ioctl cmd %#x\n", cmd);
5920 rc = lu_env_init(&env, LCT_MD_THREAD);
5926 rc = mdt_device_sync(&env, mdt);
5928 case OBD_IOC_SET_READONLY:
5929 rc = dt->dd_ops->dt_ro(&env, dt);
5931 case OBD_IOC_ABORT_RECOVERY:
5932 CERROR("%s: Aborting recovery for device\n", mdt_obd_name(mdt));
5933 target_stop_recovery_thread(obd);
5936 case OBD_IOC_CHANGELOG_REG:
5937 case OBD_IOC_CHANGELOG_DEREG:
5938 case OBD_IOC_CHANGELOG_CLEAR:
5939 rc = mdt_ioc_child(&env, mdt, cmd, len, karg);
5941 case OBD_IOC_START_LFSCK:
5942 case OBD_IOC_STOP_LFSCK: {
5943 struct md_device *next = mdt->mdt_child;
5944 struct obd_ioctl_data *data = karg;
5946 if (unlikely(data == NULL)) {
5951 rc = next->md_ops->mdo_iocontrol(&env, next, cmd,
5956 case OBD_IOC_GET_OBJ_VERSION: {
5957 struct mdt_thread_info *mti;
5958 mti = lu_context_key_get(&env.le_ctx, &mdt_thread_key);
5959 memset(mti, 0, sizeof *mti);
5960 mti->mti_env = &env;
5964 rc = mdt_ioc_version_get(mti, karg);
5969 CERROR("%s: Not supported cmd = %d, rc = %d\n",
5970 mdt_obd_name(mdt), cmd, rc);
5977 int mdt_postrecov(const struct lu_env *env, struct mdt_device *mdt)
5979 struct lu_device *ld = md2lu_dev(mdt->mdt_child);
5983 rc = ld->ld_ops->ldo_recovery_complete(env, ld);
5987 int mdt_obd_postrecov(struct obd_device *obd)
5992 rc = lu_env_init(&env, LCT_MD_THREAD);
5995 rc = mdt_postrecov(&env, mdt_dev(obd->obd_lu_dev));
6000 static struct obd_ops mdt_obd_device_ops = {
6001 .o_owner = THIS_MODULE,
6002 .o_set_info_async = mdt_obd_set_info_async,
6003 .o_connect = mdt_obd_connect,
6004 .o_reconnect = mdt_obd_reconnect,
6005 .o_disconnect = mdt_obd_disconnect,
6006 .o_init_export = mdt_init_export,
6007 .o_destroy_export = mdt_destroy_export,
6008 .o_iocontrol = mdt_iocontrol,
6009 .o_postrecov = mdt_obd_postrecov,
6012 static struct lu_device* mdt_device_fini(const struct lu_env *env,
6013 struct lu_device *d)
6015 struct mdt_device *m = mdt_dev(d);
6022 static struct lu_device *mdt_device_free(const struct lu_env *env,
6023 struct lu_device *d)
6025 struct mdt_device *m = mdt_dev(d);
6028 md_device_fini(&m->mdt_md_dev);
6033 static struct lu_device *mdt_device_alloc(const struct lu_env *env,
6034 struct lu_device_type *t,
6035 struct lustre_cfg *cfg)
6037 struct lu_device *l;
6038 struct mdt_device *m;
6044 l = &m->mdt_md_dev.md_lu_dev;
6045 rc = mdt_init0(env, m, t, cfg);
6047 mdt_device_free(env, l);
6052 l = ERR_PTR(-ENOMEM);
6056 /* context key constructor/destructor: mdt_key_init, mdt_key_fini */
6057 LU_KEY_INIT(mdt, struct mdt_thread_info);
6059 static void mdt_key_fini(const struct lu_context *ctx,
6060 struct lu_context_key *key, void* data)
6062 struct mdt_thread_info *info = data;
6064 if (info->mti_big_lmm) {
6065 OBD_FREE_LARGE(info->mti_big_lmm, info->mti_big_lmmsize);
6066 info->mti_big_lmm = NULL;
6067 info->mti_big_lmmsize = 0;
6072 /* context key: mdt_thread_key */
6073 LU_CONTEXT_KEY_DEFINE(mdt, LCT_MD_THREAD);
6075 struct lu_ucred *mdt_ucred(const struct mdt_thread_info *info)
6077 return lu_ucred(info->mti_env);
6080 struct lu_ucred *mdt_ucred_check(const struct mdt_thread_info *info)
6082 return lu_ucred_check(info->mti_env);
6086 * Enable/disable COS (Commit On Sharing).
6088 * Set/Clear the COS flag in mdt options.
6090 * \param mdt mdt device
6091 * \param val 0 disables COS, other values enable COS
6093 void mdt_enable_cos(struct mdt_device *mdt, int val)
6098 mdt->mdt_opts.mo_cos = !!val;
6099 rc = lu_env_init(&env, LCT_LOCAL);
6100 if (unlikely(rc != 0)) {
6101 CWARN("lu_env initialization failed with rc = %d,"
6102 "cannot sync\n", rc);
6105 mdt_device_sync(&env, mdt);
6110 * Check COS (Commit On Sharing) status.
6112 * Return COS flag status.
6114 * \param mdt mdt device
6116 int mdt_cos_is_enabled(struct mdt_device *mdt)
6118 return mdt->mdt_opts.mo_cos != 0;
6121 static struct lu_device_type_operations mdt_device_type_ops = {
6122 .ldto_device_alloc = mdt_device_alloc,
6123 .ldto_device_free = mdt_device_free,
6124 .ldto_device_fini = mdt_device_fini
6127 static struct lu_device_type mdt_device_type = {
6128 .ldt_tags = LU_DEVICE_MD,
6129 .ldt_name = LUSTRE_MDT_NAME,
6130 .ldt_ops = &mdt_device_type_ops,
6131 .ldt_ctx_tags = LCT_MD_THREAD
6134 static int __init mdt_mod_init(void)
6136 struct lprocfs_static_vars lvars;
6139 rc = lu_kmem_init(mdt_caches);
6143 rc = mds_mod_init();
6147 lprocfs_mdt_init_vars(&lvars);
6148 rc = class_register_type(&mdt_obd_device_ops, NULL,
6149 lvars.module_vars, LUSTRE_MDT_NAME,
6155 lu_kmem_fini(mdt_caches);
6162 static void __exit mdt_mod_exit(void)
6164 class_unregister_type(LUSTRE_MDT_NAME);
6166 lu_kmem_fini(mdt_caches);
6169 MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");
6170 MODULE_DESCRIPTION("Lustre Metadata Target ("LUSTRE_MDT_NAME")");
6171 MODULE_LICENSE("GPL");
6173 cfs_module(mdt, LUSTRE_VERSION_STRING, mdt_mod_init, mdt_mod_exit);