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);
158 LASSERT(namelen == 0);
159 lh->mlh_pdo_hash = 0ull;
163 static void mdt_lock_pdo_mode(struct mdt_thread_info *info, struct mdt_object *o,
164 struct mdt_lock_handle *lh)
170 * Any dir access needs couple of locks:
172 * 1) on part of dir we gonna take lookup/modify;
174 * 2) on whole dir to protect it from concurrent splitting and/or to
175 * flush client's cache for readdir().
177 * so, for a given mode and object this routine decides what lock mode
178 * to use for lock #2:
180 * 1) if caller's gonna lookup in dir then we need to protect dir from
181 * being splitted only - LCK_CR
183 * 2) if caller's gonna modify dir then we need to protect dir from
184 * being splitted and to flush cache - LCK_CW
186 * 3) if caller's gonna modify dir and that dir seems ready for
187 * splitting then we need to protect it from any type of access
188 * (lookup/modify/split) - LCK_EX --bzzz
191 LASSERT(lh->mlh_reg_mode != LCK_MINMODE);
192 LASSERT(lh->mlh_pdo_mode == LCK_MINMODE);
195 * Ask underlaying level its opinion about preferable PDO lock mode
196 * having access type passed as regular lock mode:
198 * - MDL_MINMODE means that lower layer does not want to specify lock
201 * - MDL_NL means that no PDO lock should be taken. This is used in some
202 * cases. Say, for non-splittable directories no need to use PDO locks
205 mode = mdo_lock_mode(info->mti_env, mdt_object_child(o),
206 mdt_dlm_mode2mdl_mode(lh->mlh_reg_mode));
208 if (mode != MDL_MINMODE) {
209 lh->mlh_pdo_mode = mdt_mdl_mode2dlm_mode(mode);
212 * Lower layer does not want to specify locking mode. We do it
213 * our selves. No special protection is needed, just flush
214 * client's cache on modification and allow concurrent
217 switch (lh->mlh_reg_mode) {
219 lh->mlh_pdo_mode = LCK_EX;
222 lh->mlh_pdo_mode = LCK_CR;
225 lh->mlh_pdo_mode = LCK_CW;
228 CERROR("Not expected lock type (0x%x)\n",
229 (int)lh->mlh_reg_mode);
234 LASSERT(lh->mlh_pdo_mode != LCK_MINMODE);
238 int mdt_getstatus(struct mdt_thread_info *info)
240 struct mdt_device *mdt = info->mti_mdt;
241 struct mdt_body *repbody;
245 rc = mdt_check_ucred(info);
247 RETURN(err_serious(rc));
249 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_GETSTATUS_PACK))
250 RETURN(err_serious(-ENOMEM));
252 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
253 repbody->fid1 = mdt->mdt_md_root_fid;
254 repbody->valid |= OBD_MD_FLID;
256 if (mdt->mdt_opts.mo_mds_capa &&
257 exp_connect_flags(info->mti_exp) & OBD_CONNECT_MDS_CAPA) {
258 struct mdt_object *root;
259 struct lustre_capa *capa;
261 root = mdt_object_find(info->mti_env, mdt, &repbody->fid1);
263 RETURN(PTR_ERR(root));
265 capa = req_capsule_server_get(info->mti_pill, &RMF_CAPA1);
267 capa->lc_opc = CAPA_OPC_MDS_DEFAULT;
268 rc = mo_capa_get(info->mti_env, mdt_object_child(root), capa,
270 mdt_object_put(info->mti_env, root);
272 repbody->valid |= OBD_MD_FLMDSCAPA;
278 int mdt_statfs(struct mdt_thread_info *info)
280 struct ptlrpc_request *req = mdt_info_req(info);
281 struct md_device *next = info->mti_mdt->mdt_child;
282 struct ptlrpc_service_part *svcpt;
283 struct obd_statfs *osfs;
288 svcpt = info->mti_pill->rc_req->rq_rqbd->rqbd_svcpt;
290 /* This will trigger a watchdog timeout */
291 OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_STATFS_LCW_SLEEP,
292 (MDT_SERVICE_WATCHDOG_FACTOR *
293 at_get(&svcpt->scp_at_estimate)) + 1);
295 rc = mdt_check_ucred(info);
297 RETURN(err_serious(rc));
299 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_STATFS_PACK))
300 RETURN(err_serious(-ENOMEM));
302 osfs = req_capsule_server_get(info->mti_pill, &RMF_OBD_STATFS);
306 /** statfs information are cached in the mdt_device */
307 if (cfs_time_before_64(info->mti_mdt->mdt_osfs_age,
308 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS))) {
309 /** statfs data is too old, get up-to-date one */
310 rc = next->md_ops->mdo_statfs(info->mti_env, next, osfs);
313 spin_lock(&info->mti_mdt->mdt_osfs_lock);
314 info->mti_mdt->mdt_osfs = *osfs;
315 info->mti_mdt->mdt_osfs_age = cfs_time_current_64();
316 spin_unlock(&info->mti_mdt->mdt_osfs_lock);
318 /** use cached statfs data */
319 spin_lock(&info->mti_mdt->mdt_osfs_lock);
320 *osfs = info->mti_mdt->mdt_osfs;
321 spin_unlock(&info->mti_mdt->mdt_osfs_lock);
325 mdt_counter_incr(req, LPROC_MDT_STATFS);
331 * Pack SOM attributes into the reply.
332 * Call under a DLM UPDATE lock.
334 static void mdt_pack_size2body(struct mdt_thread_info *info,
335 struct mdt_object *mo)
338 struct md_attr *ma = &info->mti_attr;
340 LASSERT(ma->ma_attr.la_valid & LA_MODE);
341 b = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
343 /* Check if Size-on-MDS is supported, if this is a regular file,
344 * if SOM is enabled on the object and if SOM cache exists and valid.
345 * Otherwise do not pack Size-on-MDS attributes to the reply. */
346 if (!(mdt_conn_flags(info) & OBD_CONNECT_SOM) ||
347 !S_ISREG(ma->ma_attr.la_mode) ||
348 !mdt_object_is_som_enabled(mo) ||
349 !(ma->ma_valid & MA_SOM))
352 b->valid |= OBD_MD_FLSIZE | OBD_MD_FLBLOCKS;
353 b->size = ma->ma_som->msd_size;
354 b->blocks = ma->ma_som->msd_blocks;
357 void mdt_pack_attr2body(struct mdt_thread_info *info, struct mdt_body *b,
358 const struct lu_attr *attr, const struct lu_fid *fid)
360 struct md_attr *ma = &info->mti_attr;
362 LASSERT(ma->ma_valid & MA_INODE);
364 b->atime = attr->la_atime;
365 b->mtime = attr->la_mtime;
366 b->ctime = attr->la_ctime;
367 b->mode = attr->la_mode;
368 b->size = attr->la_size;
369 b->blocks = attr->la_blocks;
370 b->uid = attr->la_uid;
371 b->gid = attr->la_gid;
372 b->flags = attr->la_flags;
373 b->nlink = attr->la_nlink;
374 b->rdev = attr->la_rdev;
376 /*XXX should pack the reply body according to lu_valid*/
377 b->valid |= OBD_MD_FLCTIME | OBD_MD_FLUID |
378 OBD_MD_FLGID | OBD_MD_FLTYPE |
379 OBD_MD_FLMODE | OBD_MD_FLNLINK | OBD_MD_FLFLAGS |
380 OBD_MD_FLATIME | OBD_MD_FLMTIME ;
382 if (!S_ISREG(attr->la_mode)) {
383 b->valid |= OBD_MD_FLSIZE | OBD_MD_FLBLOCKS | OBD_MD_FLRDEV;
384 } else if (ma->ma_need & MA_LOV && !(ma->ma_valid & MA_LOV)) {
385 /* means no objects are allocated on osts. */
386 LASSERT(!(ma->ma_valid & MA_LOV));
387 /* just ignore blocks occupied by extend attributes on MDS */
389 /* if no object is allocated on osts, the size on mds is valid. b=22272 */
390 b->valid |= OBD_MD_FLSIZE | OBD_MD_FLBLOCKS;
395 b->valid |= OBD_MD_FLID;
396 CDEBUG(D_INODE, DFID": nlink=%d, mode=%o, size="LPU64"\n",
397 PFID(fid), b->nlink, b->mode, b->size);
401 mdt_body_reverse_idmap(info, b);
403 if (b->valid & OBD_MD_FLSIZE)
404 CDEBUG(D_VFSTRACE, DFID": returning size %llu\n",
405 PFID(fid), (unsigned long long)b->size);
408 static inline int mdt_body_has_lov(const struct lu_attr *la,
409 const struct mdt_body *body)
411 return ((S_ISREG(la->la_mode) && (body->valid & OBD_MD_FLEASIZE)) ||
412 (S_ISDIR(la->la_mode) && (body->valid & OBD_MD_FLDIREA )) );
415 void mdt_client_compatibility(struct mdt_thread_info *info)
417 struct mdt_body *body;
418 struct ptlrpc_request *req = mdt_info_req(info);
419 struct obd_export *exp = req->rq_export;
420 struct md_attr *ma = &info->mti_attr;
421 struct lu_attr *la = &ma->ma_attr;
424 if (exp_connect_layout(exp))
425 /* the client can deal with 16-bit lmm_stripe_count */
428 body = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
430 if (!mdt_body_has_lov(la, body))
433 /* now we have a reply with a lov for a client not compatible with the
434 * layout lock so we have to clean the layout generation number */
435 if (S_ISREG(la->la_mode))
436 ma->ma_lmm->lmm_layout_gen = 0;
440 static int mdt_big_xattr_get(struct mdt_thread_info *info, struct mdt_object *o,
443 const struct lu_env *env = info->mti_env;
447 LASSERT(info->mti_big_lmm_used == 0);
448 rc = mo_xattr_get(env, mdt_object_child(o), &LU_BUF_NULL, name);
452 /* big_lmm may need to be grown */
453 if (info->mti_big_lmmsize < rc) {
454 int size = size_roundup_power2(rc);
456 if (info->mti_big_lmmsize > 0) {
457 /* free old buffer */
458 LASSERT(info->mti_big_lmm);
459 OBD_FREE_LARGE(info->mti_big_lmm,
460 info->mti_big_lmmsize);
461 info->mti_big_lmm = NULL;
462 info->mti_big_lmmsize = 0;
465 OBD_ALLOC_LARGE(info->mti_big_lmm, size);
466 if (info->mti_big_lmm == NULL)
468 info->mti_big_lmmsize = size;
470 LASSERT(info->mti_big_lmmsize >= rc);
472 info->mti_buf.lb_buf = info->mti_big_lmm;
473 info->mti_buf.lb_len = info->mti_big_lmmsize;
474 rc = mo_xattr_get(env, mdt_object_child(o), &info->mti_buf, name);
479 int mdt_attr_get_lov(struct mdt_thread_info *info,
480 struct mdt_object *o, struct md_attr *ma)
482 struct md_object *next = mdt_object_child(o);
483 struct lu_buf *buf = &info->mti_buf;
486 buf->lb_buf = ma->ma_lmm;
487 buf->lb_len = ma->ma_lmm_size;
488 rc = mo_xattr_get(info->mti_env, next, buf, XATTR_NAME_LOV);
490 ma->ma_lmm_size = rc;
491 ma->ma_valid |= MA_LOV;
493 } else if (rc == -ENODATA) {
496 } else if (rc == -ERANGE) {
497 rc = mdt_big_xattr_get(info, o, XATTR_NAME_LOV);
499 info->mti_big_lmm_used = 1;
500 ma->ma_valid |= MA_LOV;
501 ma->ma_lmm = info->mti_big_lmm;
502 ma->ma_lmm_size = rc;
503 /* update mdt_max_mdsize so all clients
504 * will be aware about that */
505 if (info->mti_mdt->mdt_max_mdsize < rc)
506 info->mti_mdt->mdt_max_mdsize = rc;
514 int mdt_attr_get_pfid(struct mdt_thread_info *info,
515 struct mdt_object *o, struct lu_fid *pfid)
517 struct lu_buf *buf = &info->mti_buf;
518 struct link_ea_header *leh;
519 struct link_ea_entry *lee;
523 buf->lb_buf = info->mti_big_lmm;
524 buf->lb_len = info->mti_big_lmmsize;
525 rc = mo_xattr_get(info->mti_env, mdt_object_child(o),
526 buf, XATTR_NAME_LINK);
527 /* ignore errors, MA_PFID won't be set and it is
528 * up to the caller to treat this as an error */
529 if (rc == -ERANGE || buf->lb_len == 0) {
530 rc = mdt_big_xattr_get(info, o, XATTR_NAME_LINK);
531 buf->lb_buf = info->mti_big_lmm;
532 buf->lb_len = info->mti_big_lmmsize;
537 if (rc < sizeof(*leh)) {
538 CERROR("short LinkEA on "DFID": rc = %d\n",
539 PFID(mdt_object_fid(o)), rc);
543 leh = (struct link_ea_header *) buf->lb_buf;
544 lee = (struct link_ea_entry *)(leh + 1);
545 if (leh->leh_magic == __swab32(LINK_EA_MAGIC)) {
546 leh->leh_magic = LINK_EA_MAGIC;
547 leh->leh_reccount = __swab32(leh->leh_reccount);
548 leh->leh_len = __swab64(leh->leh_len);
550 if (leh->leh_magic != LINK_EA_MAGIC)
552 if (leh->leh_reccount == 0)
555 memcpy(pfid, &lee->lee_parent_fid, sizeof(*pfid));
556 fid_be_to_cpu(pfid, pfid);
561 int mdt_attr_get_complex(struct mdt_thread_info *info,
562 struct mdt_object *o, struct md_attr *ma)
564 const struct lu_env *env = info->mti_env;
565 struct md_object *next = mdt_object_child(o);
566 struct lu_buf *buf = &info->mti_buf;
567 u32 mode = lu_object_attr(&next->mo_lu);
568 int need = ma->ma_need;
574 if (need & MA_INODE) {
575 ma->ma_need = MA_INODE;
576 rc = mo_attr_get(env, next, ma);
579 ma->ma_valid |= MA_INODE;
582 if (need & MA_PFID) {
583 rc = mdt_attr_get_pfid(info, o, &ma->ma_pfid);
585 ma->ma_valid |= MA_PFID;
586 /* ignore this error, parent fid is not mandatory */
590 if (need & MA_LOV && (S_ISREG(mode) || S_ISDIR(mode))) {
591 rc = mdt_attr_get_lov(info, o, ma);
596 if (need & MA_LMV && S_ISDIR(mode)) {
597 buf->lb_buf = ma->ma_lmv;
598 buf->lb_len = ma->ma_lmv_size;
599 rc2 = mo_xattr_get(env, next, buf, XATTR_NAME_LMV);
601 ma->ma_lmv_size = rc2;
602 ma->ma_valid |= MA_LMV;
603 } else if (rc2 == -ENODATA) {
610 if (need & MA_SOM && S_ISREG(mode)) {
611 buf->lb_buf = info->mti_xattr_buf;
612 buf->lb_len = sizeof(info->mti_xattr_buf);
613 CLASSERT(sizeof(struct som_attrs) <=
614 sizeof(info->mti_xattr_buf));
615 rc2 = mo_xattr_get(info->mti_env, next, buf, XATTR_NAME_SOM);
616 rc2 = lustre_buf2som(info->mti_xattr_buf, rc2, ma->ma_som);
618 ma->ma_valid |= MA_SOM;
619 else if (rc2 < 0 && rc2 != -ENODATA)
623 if (need & MA_HSM && S_ISREG(mode)) {
624 buf->lb_buf = info->mti_xattr_buf;
625 buf->lb_len = sizeof(info->mti_xattr_buf);
626 CLASSERT(sizeof(struct hsm_attrs) <=
627 sizeof(info->mti_xattr_buf));
628 rc2 = mo_xattr_get(info->mti_env, next, buf, XATTR_NAME_HSM);
629 rc2 = lustre_buf2hsm(info->mti_xattr_buf, rc2, &ma->ma_hsm);
631 ma->ma_valid |= MA_HSM;
632 else if (rc2 < 0 && rc2 != -ENODATA)
636 #ifdef CONFIG_FS_POSIX_ACL
637 if (need & MA_ACL_DEF && S_ISDIR(mode)) {
638 buf->lb_buf = ma->ma_acl;
639 buf->lb_len = ma->ma_acl_size;
640 rc2 = mo_xattr_get(env, next, buf, XATTR_NAME_ACL_DEFAULT);
642 ma->ma_acl_size = rc2;
643 ma->ma_valid |= MA_ACL_DEF;
644 } else if (rc2 == -ENODATA) {
653 CDEBUG(D_INODE, "after getattr rc = %d, ma_valid = "LPX64" ma_lmm=%p\n",
654 rc, ma->ma_valid, ma->ma_lmm);
658 static int mdt_getattr_internal(struct mdt_thread_info *info,
659 struct mdt_object *o, int ma_need)
661 struct md_object *next = mdt_object_child(o);
662 const struct mdt_body *reqbody = info->mti_body;
663 struct ptlrpc_request *req = mdt_info_req(info);
664 struct md_attr *ma = &info->mti_attr;
665 struct lu_attr *la = &ma->ma_attr;
666 struct req_capsule *pill = info->mti_pill;
667 const struct lu_env *env = info->mti_env;
668 struct mdt_body *repbody;
669 struct lu_buf *buffer = &info->mti_buf;
674 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_GETATTR_PACK))
675 RETURN(err_serious(-ENOMEM));
677 repbody = req_capsule_server_get(pill, &RMF_MDT_BODY);
681 if (mdt_object_remote(o)) {
682 /* This object is located on remote node.*/
683 /* Return -EIO for old client */
684 if (!mdt_is_dne_client(req->rq_export))
685 GOTO(out, rc = -EIO);
687 repbody->fid1 = *mdt_object_fid(o);
688 repbody->valid = OBD_MD_FLID | OBD_MD_MDS;
692 buffer->lb_len = reqbody->eadatasize;
693 if (buffer->lb_len > 0)
694 buffer->lb_buf = req_capsule_server_get(pill, &RMF_MDT_MD);
696 buffer->lb_buf = NULL;
698 /* If it is dir object and client require MEA, then we got MEA */
699 if (S_ISDIR(lu_object_attr(&next->mo_lu)) &&
700 reqbody->valid & OBD_MD_MEA) {
701 /* Assumption: MDT_MD size is enough for lmv size. */
702 ma->ma_lmv = buffer->lb_buf;
703 ma->ma_lmv_size = buffer->lb_len;
704 ma->ma_need = MA_LMV | MA_INODE;
706 ma->ma_lmm = buffer->lb_buf;
707 ma->ma_lmm_size = buffer->lb_len;
708 ma->ma_need = MA_LOV | MA_INODE | MA_HSM;
711 if (S_ISDIR(lu_object_attr(&next->mo_lu)) &&
712 reqbody->valid & OBD_MD_FLDIREA &&
713 lustre_msg_get_opc(req->rq_reqmsg) == MDS_GETATTR) {
714 /* get default stripe info for this dir. */
715 ma->ma_need |= MA_LOV_DEF;
717 ma->ma_need |= ma_need;
718 if (ma->ma_need & MA_SOM)
719 ma->ma_som = &info->mti_u.som.data;
721 rc = mdt_attr_get_complex(info, o, ma);
723 CERROR("getattr error for "DFID": %d\n",
724 PFID(mdt_object_fid(o)), rc);
728 is_root = lu_fid_eq(mdt_object_fid(o), &info->mti_mdt->mdt_md_root_fid);
730 /* the Lustre protocol supposes to return default striping
731 * on the user-visible root if explicitly requested */
732 if ((ma->ma_valid & MA_LOV) == 0 && S_ISDIR(la->la_mode) &&
733 (ma->ma_need & MA_LOV_DEF && is_root) && (ma->ma_need & MA_LOV)) {
734 struct lu_fid rootfid;
735 struct mdt_object *root;
736 struct mdt_device *mdt = info->mti_mdt;
738 rc = dt_root_get(env, mdt->mdt_bottom, &rootfid);
741 root = mdt_object_find(env, mdt, &rootfid);
743 RETURN(PTR_ERR(root));
744 rc = mdt_attr_get_lov(info, root, ma);
745 mdt_object_put(info->mti_env, root);
747 CERROR("getattr error for "DFID": %d\n",
748 PFID(mdt_object_fid(o)), rc);
753 if (likely(ma->ma_valid & MA_INODE))
754 mdt_pack_attr2body(info, repbody, la, mdt_object_fid(o));
758 if (mdt_body_has_lov(la, reqbody)) {
759 if (ma->ma_valid & MA_LOV) {
760 LASSERT(ma->ma_lmm_size);
761 mdt_dump_lmm(D_INFO, ma->ma_lmm);
762 repbody->eadatasize = ma->ma_lmm_size;
763 if (S_ISDIR(la->la_mode))
764 repbody->valid |= OBD_MD_FLDIREA;
766 repbody->valid |= OBD_MD_FLEASIZE;
768 if (ma->ma_valid & MA_LMV) {
769 LASSERT(S_ISDIR(la->la_mode));
770 repbody->eadatasize = ma->ma_lmv_size;
771 repbody->valid |= (OBD_MD_FLDIREA|OBD_MD_MEA);
773 } else if (S_ISLNK(la->la_mode) &&
774 reqbody->valid & OBD_MD_LINKNAME) {
775 buffer->lb_buf = ma->ma_lmm;
776 /* eadatasize from client includes NULL-terminator, so
777 * there is no need to read it */
778 buffer->lb_len = reqbody->eadatasize - 1;
779 rc = mo_readlink(env, next, buffer);
780 if (unlikely(rc <= 0)) {
781 CERROR("readlink failed: %d\n", rc);
784 int print_limit = min_t(int, CFS_PAGE_SIZE - 128, rc);
786 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_READLINK_EPROTO))
788 repbody->valid |= OBD_MD_LINKNAME;
789 /* we need to report back size with NULL-terminator
790 * because client expects that */
791 repbody->eadatasize = rc + 1;
792 if (repbody->eadatasize != reqbody->eadatasize)
793 CERROR("Read shorter symlink %d, expected %d\n",
794 rc, reqbody->eadatasize - 1);
796 ((char *)ma->ma_lmm)[rc] = 0;
798 /* If the total CDEBUG() size is larger than a page, it
799 * will print a warning to the console, avoid this by
800 * printing just the last part of the symlink. */
801 CDEBUG(D_INODE, "symlink dest %s%.*s, len = %d\n",
802 print_limit < rc ? "..." : "", print_limit,
803 (char *)ma->ma_lmm + rc - print_limit, rc);
808 if (reqbody->valid & OBD_MD_FLMODEASIZE) {
809 repbody->max_cookiesize = 0;
810 repbody->max_mdsize = info->mti_mdt->mdt_max_mdsize;
811 repbody->valid |= OBD_MD_FLMODEASIZE;
812 CDEBUG(D_INODE, "I am going to change the MAX_MD_SIZE & "
813 "MAX_COOKIE to : %d:%d\n", repbody->max_mdsize,
814 repbody->max_cookiesize);
817 if (exp_connect_rmtclient(info->mti_exp) &&
818 reqbody->valid & OBD_MD_FLRMTPERM) {
819 void *buf = req_capsule_server_get(pill, &RMF_ACL);
821 /* mdt_getattr_lock only */
822 rc = mdt_pack_remote_perm(info, o, buf);
824 repbody->valid &= ~OBD_MD_FLRMTPERM;
825 repbody->aclsize = 0;
828 repbody->valid |= OBD_MD_FLRMTPERM;
829 repbody->aclsize = sizeof(struct mdt_remote_perm);
832 #ifdef CONFIG_FS_POSIX_ACL
833 else if ((exp_connect_flags(req->rq_export) & OBD_CONNECT_ACL) &&
834 (reqbody->valid & OBD_MD_FLACL)) {
835 buffer->lb_buf = req_capsule_server_get(pill, &RMF_ACL);
836 buffer->lb_len = req_capsule_get_size(pill,
837 &RMF_ACL, RCL_SERVER);
838 if (buffer->lb_len > 0) {
839 rc = mo_xattr_get(env, next, buffer,
840 XATTR_NAME_ACL_ACCESS);
842 if (rc == -ENODATA) {
843 repbody->aclsize = 0;
844 repbody->valid |= OBD_MD_FLACL;
846 } else if (rc == -EOPNOTSUPP) {
849 CERROR("got acl size: %d\n", rc);
852 repbody->aclsize = rc;
853 repbody->valid |= OBD_MD_FLACL;
860 if (reqbody->valid & OBD_MD_FLMDSCAPA &&
861 info->mti_mdt->mdt_opts.mo_mds_capa &&
862 exp_connect_flags(info->mti_exp) & OBD_CONNECT_MDS_CAPA) {
863 struct lustre_capa *capa;
865 capa = req_capsule_server_get(pill, &RMF_CAPA1);
867 capa->lc_opc = CAPA_OPC_MDS_DEFAULT;
868 rc = mo_capa_get(env, next, capa, 0);
871 repbody->valid |= OBD_MD_FLMDSCAPA;
876 mdt_counter_incr(req, LPROC_MDT_GETATTR);
881 static int mdt_renew_capa(struct mdt_thread_info *info)
883 struct mdt_object *obj = info->mti_object;
884 struct mdt_body *body;
885 struct lustre_capa *capa, *c;
889 /* if object doesn't exist, or server has disabled capability,
890 * return directly, client will find body->valid OBD_MD_FLOSSCAPA
893 if (!obj || !info->mti_mdt->mdt_opts.mo_oss_capa ||
894 !(exp_connect_flags(info->mti_exp) & OBD_CONNECT_OSS_CAPA))
897 body = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
898 LASSERT(body != NULL);
900 c = req_capsule_client_get(info->mti_pill, &RMF_CAPA1);
903 capa = req_capsule_server_get(info->mti_pill, &RMF_CAPA2);
907 rc = mo_capa_get(info->mti_env, mdt_object_child(obj), capa, 1);
909 body->valid |= OBD_MD_FLOSSCAPA;
913 int mdt_getattr(struct mdt_thread_info *info)
915 struct mdt_object *obj = info->mti_object;
916 struct req_capsule *pill = info->mti_pill;
917 struct mdt_body *reqbody;
918 struct mdt_body *repbody;
923 reqbody = req_capsule_client_get(pill, &RMF_MDT_BODY);
926 if (reqbody->valid & OBD_MD_FLOSSCAPA) {
927 rc = req_capsule_server_pack(pill);
929 RETURN(err_serious(rc));
930 rc = mdt_renew_capa(info);
931 GOTO(out_shrink, rc);
934 LASSERT(obj != NULL);
935 LASSERT(lu_object_assert_exists(&obj->mot_obj.mo_lu));
937 mode = lu_object_attr(&obj->mot_obj.mo_lu);
939 /* old clients may not report needed easize, use max value then */
940 req_capsule_set_size(pill, &RMF_MDT_MD, RCL_SERVER,
941 reqbody->eadatasize == 0 ?
942 info->mti_mdt->mdt_max_mdsize :
943 reqbody->eadatasize);
945 rc = req_capsule_server_pack(pill);
946 if (unlikely(rc != 0))
947 RETURN(err_serious(rc));
949 repbody = req_capsule_server_get(pill, &RMF_MDT_BODY);
950 LASSERT(repbody != NULL);
951 repbody->eadatasize = 0;
952 repbody->aclsize = 0;
954 if (reqbody->valid & OBD_MD_FLRMTPERM)
955 rc = mdt_init_ucred(info, reqbody);
957 rc = mdt_check_ucred(info);
959 GOTO(out_shrink, rc);
961 info->mti_cross_ref = !!(reqbody->valid & OBD_MD_FLCROSSREF);
964 * Don't check capability at all, because rename might getattr for
965 * remote obj, and at that time no capability is available.
967 mdt_set_capainfo(info, 1, &reqbody->fid1, BYPASS_CAPA);
968 rc = mdt_getattr_internal(info, obj, 0);
969 if (reqbody->valid & OBD_MD_FLRMTPERM)
970 mdt_exit_ucred(info);
973 mdt_client_compatibility(info);
974 rc2 = mdt_fix_reply(info);
980 int mdt_is_subdir(struct mdt_thread_info *info)
982 struct mdt_object *o = info->mti_object;
983 struct req_capsule *pill = info->mti_pill;
984 const struct mdt_body *body = info->mti_body;
985 struct mdt_body *repbody;
991 repbody = req_capsule_server_get(pill, &RMF_MDT_BODY);
994 * We save last checked parent fid to @repbody->fid1 for remote
997 LASSERT(fid_is_sane(&body->fid2));
998 LASSERT(mdt_object_exists(o) && !mdt_object_remote(o));
999 rc = mdo_is_subdir(info->mti_env, mdt_object_child(o),
1000 &body->fid2, &repbody->fid1);
1001 if (rc == 0 || rc == -EREMOTE)
1002 repbody->valid |= OBD_MD_FLID;
1007 int mdt_swap_layouts(struct mdt_thread_info *info)
1009 struct ptlrpc_request *req = mdt_info_req(info);
1010 struct obd_export *exp = req->rq_export;
1011 struct mdt_object *o1, *o2, *o;
1012 struct mdt_lock_handle *lh1, *lh2;
1013 struct mdc_swap_layouts *msl;
1017 /* client does not support layout lock, so layout swaping
1019 * FIXME: there is a problem for old clients which don't support
1020 * layout lock yet. If those clients have already opened the file
1021 * they won't be notified at all so that old layout may still be
1022 * used to do IO. This can be fixed after file release is landed by
1023 * doing exclusive open and taking full EX ibits lock. - Jinshan */
1024 if (!exp_connect_layout(exp))
1025 RETURN(-EOPNOTSUPP);
1027 if (req_capsule_get_size(info->mti_pill, &RMF_CAPA1, RCL_CLIENT))
1028 mdt_set_capainfo(info, 0, &info->mti_body->fid1,
1029 req_capsule_client_get(info->mti_pill,
1032 if (req_capsule_get_size(info->mti_pill, &RMF_CAPA2, RCL_CLIENT))
1033 mdt_set_capainfo(info, 1, &info->mti_body->fid2,
1034 req_capsule_client_get(info->mti_pill,
1037 o1 = info->mti_object;
1038 o = o2 = mdt_object_find(info->mti_env, info->mti_mdt,
1039 &info->mti_body->fid2);
1041 GOTO(out, rc = PTR_ERR(o));
1043 if (mdt_object_remote(o) || !mdt_object_exists(o)) /* remote object */
1044 GOTO(put, rc = -ENOENT);
1046 rc = lu_fid_cmp(&info->mti_body->fid1, &info->mti_body->fid2);
1047 if (unlikely(rc == 0)) /* same file, you kidding me? no-op. */
1053 /* permission check. Make sure the calling process having permission
1054 * to write both files. */
1055 rc = mo_permission(info->mti_env, NULL, mdt_object_child(o1), NULL,
1060 rc = mo_permission(info->mti_env, NULL, mdt_object_child(o2), NULL,
1065 msl = req_capsule_client_get(info->mti_pill, &RMF_SWAP_LAYOUTS);
1067 GOTO(put, rc = -EPROTO);
1069 lh1 = &info->mti_lh[MDT_LH_NEW];
1070 mdt_lock_reg_init(lh1, LCK_EX);
1071 lh2 = &info->mti_lh[MDT_LH_OLD];
1072 mdt_lock_reg_init(lh2, LCK_EX);
1074 rc = mdt_object_lock(info, o1, lh1, MDS_INODELOCK_LAYOUT,
1079 rc = mdt_object_lock(info, o2, lh2, MDS_INODELOCK_LAYOUT,
1084 rc = mo_swap_layouts(info->mti_env, mdt_object_child(o1),
1085 mdt_object_child(o2), msl->msl_flags);
1088 mdt_object_unlock(info, o2, lh2, rc);
1090 mdt_object_unlock(info, o1, lh1, rc);
1092 mdt_object_put(info->mti_env, o);
1097 static int mdt_raw_lookup(struct mdt_thread_info *info,
1098 struct mdt_object *parent,
1099 const struct lu_name *lname,
1100 struct ldlm_reply *ldlm_rep)
1102 struct md_object *next = mdt_object_child(info->mti_object);
1103 const struct mdt_body *reqbody = info->mti_body;
1104 struct lu_fid *child_fid = &info->mti_tmp_fid1;
1105 struct mdt_body *repbody;
1109 if (reqbody->valid != OBD_MD_FLID)
1112 LASSERT(!info->mti_cross_ref);
1114 /* Only got the fid of this obj by name */
1115 fid_zero(child_fid);
1116 rc = mdo_lookup(info->mti_env, next, lname, child_fid,
1119 /* XXX is raw_lookup possible as intent operation? */
1122 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_NEG);
1125 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_POS);
1127 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
1130 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
1131 repbody->fid1 = *child_fid;
1132 repbody->valid = OBD_MD_FLID;
1138 * UPDATE lock should be taken against parent, and be release before exit;
1139 * child_bits lock should be taken against child, and be returned back:
1140 * (1)normal request should release the child lock;
1141 * (2)intent request will grant the lock to client.
1143 static int mdt_getattr_name_lock(struct mdt_thread_info *info,
1144 struct mdt_lock_handle *lhc,
1146 struct ldlm_reply *ldlm_rep)
1148 struct ptlrpc_request *req = mdt_info_req(info);
1149 struct mdt_body *reqbody = NULL;
1150 struct mdt_object *parent = info->mti_object;
1151 struct mdt_object *child;
1152 struct md_object *next = mdt_object_child(parent);
1153 struct lu_fid *child_fid = &info->mti_tmp_fid1;
1154 struct lu_name *lname = NULL;
1155 const char *name = NULL;
1157 struct mdt_lock_handle *lhp = NULL;
1158 struct ldlm_lock *lock;
1159 struct ldlm_res_id *res_id;
1166 is_resent = lustre_handle_is_used(&lhc->mlh_reg_lh);
1167 LASSERT(ergo(is_resent,
1168 lustre_msg_get_flags(req->rq_reqmsg) & MSG_RESENT));
1170 LASSERT(parent != NULL);
1171 name = req_capsule_client_get(info->mti_pill, &RMF_NAME);
1173 RETURN(err_serious(-EFAULT));
1175 namelen = req_capsule_get_size(info->mti_pill, &RMF_NAME,
1177 if (!info->mti_cross_ref) {
1179 * XXX: Check for "namelen == 0" is for getattr by fid
1180 * (OBD_CONNECT_ATTRFID), otherwise do not allow empty name,
1181 * that is the name must contain at least one character and
1182 * the terminating '\0'
1185 reqbody = req_capsule_client_get(info->mti_pill,
1187 if (unlikely(reqbody == NULL))
1188 RETURN(err_serious(-EFAULT));
1190 if (unlikely(!fid_is_sane(&reqbody->fid2)))
1191 RETURN(err_serious(-EINVAL));
1194 CDEBUG(D_INODE, "getattr with lock for "DFID"/"DFID", "
1196 PFID(mdt_object_fid(parent)),
1197 PFID(&reqbody->fid2), ldlm_rep);
1199 lname = mdt_name(info->mti_env, (char *)name, namelen);
1200 CDEBUG(D_INODE, "getattr with lock for "DFID"/%s, "
1201 "ldlm_rep = %p\n", PFID(mdt_object_fid(parent)),
1205 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_EXECD);
1207 if (unlikely(!mdt_object_exists(parent))) {
1208 LU_OBJECT_DEBUG(D_INODE, info->mti_env,
1209 &parent->mot_obj.mo_lu,
1210 "Parent doesn't exist!\n");
1212 } else if (!info->mti_cross_ref) {
1213 LASSERTF(!mdt_object_remote(parent),
1214 "Parent "DFID" is on remote server\n",
1215 PFID(mdt_object_fid(parent)));
1218 rc = mdt_raw_lookup(info, parent, lname, ldlm_rep);
1226 if (info->mti_cross_ref) {
1227 /* Only getattr on the child. Parent is on another node. */
1228 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_POS);
1230 CDEBUG(D_INODE, "partial getattr_name child_fid = "DFID", "
1231 "ldlm_rep=%p\n", PFID(mdt_object_fid(child)), ldlm_rep);
1234 /* Do not take lock for resent case. */
1235 lock = ldlm_handle2lock(&lhc->mlh_reg_lh);
1236 LASSERTF(lock != NULL, "Invalid lock handle "LPX64"\n",
1237 lhc->mlh_reg_lh.cookie);
1238 LASSERT(fid_res_name_eq(mdt_object_fid(child),
1239 &lock->l_resource->lr_name));
1240 LDLM_LOCK_PUT(lock);
1243 mdt_lock_handle_init(lhc);
1244 mdt_lock_reg_init(lhc, LCK_PR);
1247 * Object's name is on another MDS, no lookup lock is
1248 * needed here but update is.
1250 child_bits &= ~MDS_INODELOCK_LOOKUP;
1251 child_bits |= MDS_INODELOCK_PERM | MDS_INODELOCK_UPDATE;
1253 rc = mdt_object_lock(info, child, lhc, child_bits,
1257 /* Finally, we can get attr for child. */
1258 mdt_set_capainfo(info, 0, mdt_object_fid(child),
1260 rc = mdt_getattr_internal(info, child, 0);
1261 if (unlikely(rc != 0))
1262 mdt_object_unlock(info, child, lhc, 1);
1268 /* step 1: lock parent only if parent is a directory */
1269 if (S_ISDIR(lu_object_attr(&parent->mot_obj.mo_lu))) {
1270 lhp = &info->mti_lh[MDT_LH_PARENT];
1271 mdt_lock_pdo_init(lhp, LCK_PR, name, namelen);
1272 rc = mdt_object_lock(info, parent, lhp,
1273 MDS_INODELOCK_UPDATE,
1275 if (unlikely(rc != 0))
1279 /* step 2: lookup child's fid by name */
1280 fid_zero(child_fid);
1281 rc = mdo_lookup(info->mti_env, next, lname, child_fid,
1286 mdt_set_disposition(info, ldlm_rep,
1288 GOTO(out_parent, rc);
1290 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_POS);
1292 *child_fid = reqbody->fid2;
1293 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_POS);
1297 *step 3: find the child object by fid & lock it.
1298 * regardless if it is local or remote.
1300 child = mdt_object_find(info->mti_env, info->mti_mdt, child_fid);
1302 if (unlikely(IS_ERR(child)))
1303 GOTO(out_parent, rc = PTR_ERR(child));
1305 /* Do not take lock for resent case. */
1306 lock = ldlm_handle2lock(&lhc->mlh_reg_lh);
1307 LASSERTF(lock != NULL, "Invalid lock handle "LPX64"\n",
1308 lhc->mlh_reg_lh.cookie);
1310 res_id = &lock->l_resource->lr_name;
1311 if (!fid_res_name_eq(mdt_object_fid(child),
1312 &lock->l_resource->lr_name)) {
1313 LASSERTF(fid_res_name_eq(mdt_object_fid(parent),
1314 &lock->l_resource->lr_name),
1315 "Lock res_id: %lu/%lu/%lu, Fid: "DFID".\n",
1316 (unsigned long)res_id->name[0],
1317 (unsigned long)res_id->name[1],
1318 (unsigned long)res_id->name[2],
1319 PFID(mdt_object_fid(parent)));
1320 CWARN("Although resent, but still not get child lock"
1321 "parent:"DFID" child:"DFID"\n",
1322 PFID(mdt_object_fid(parent)),
1323 PFID(mdt_object_fid(child)));
1324 lustre_msg_clear_flags(req->rq_reqmsg, MSG_RESENT);
1325 LDLM_LOCK_PUT(lock);
1328 LDLM_LOCK_PUT(lock);
1331 bool try_layout = false;
1334 OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_RESEND, obd_timeout*2);
1335 mdt_lock_handle_init(lhc);
1336 mdt_lock_reg_init(lhc, LCK_PR);
1338 if (!mdt_object_exists(child)) {
1339 LU_OBJECT_DEBUG(D_INODE, info->mti_env,
1340 &child->mot_obj.mo_lu,
1341 "Object doesn't exist!\n");
1342 GOTO(out_child, rc = -ENOENT);
1345 if (!(child_bits & MDS_INODELOCK_UPDATE) &&
1346 mdt_object_exists(child) && !mdt_object_remote(child)) {
1347 struct md_attr *ma = &info->mti_attr;
1350 ma->ma_need = MA_INODE;
1351 rc = mdt_attr_get_complex(info, child, ma);
1352 if (unlikely(rc != 0))
1353 GOTO(out_child, rc);
1355 /* If the file has not been changed for some time, we
1356 * return not only a LOOKUP lock, but also an UPDATE
1357 * lock and this might save us RPC on later STAT. For
1358 * directories, it also let negative dentry starts
1359 * working for this dir. */
1360 if (ma->ma_valid & MA_INODE &&
1361 ma->ma_attr.la_valid & LA_CTIME &&
1362 info->mti_mdt->mdt_namespace->ns_ctime_age_limit +
1363 ma->ma_attr.la_ctime < cfs_time_current_sec())
1364 child_bits |= MDS_INODELOCK_UPDATE;
1367 /* layout lock must be granted in a best-effort way
1368 * for IT operations */
1369 LASSERT(!(child_bits & MDS_INODELOCK_LAYOUT));
1370 if (!OBD_FAIL_CHECK(OBD_FAIL_MDS_NO_LL_GETATTR) &&
1371 exp_connect_layout(info->mti_exp) &&
1372 S_ISREG(lu_object_attr(&child->mot_obj.mo_lu)) &&
1374 /* try to grant layout lock for regular file. */
1380 child_bits |= MDS_INODELOCK_LAYOUT;
1381 /* try layout lock, it may fail to be granted due to
1382 * contention at LOOKUP or UPDATE */
1383 if (!mdt_object_lock_try(info, child, lhc, child_bits,
1385 child_bits &= ~MDS_INODELOCK_LAYOUT;
1386 LASSERT(child_bits != 0);
1387 rc = mdt_object_lock(info, child, lhc,
1388 child_bits, MDT_CROSS_LOCK);
1393 rc = mdt_object_lock(info, child, lhc, child_bits,
1396 if (unlikely(rc != 0))
1397 GOTO(out_child, rc);
1400 lock = ldlm_handle2lock(&lhc->mlh_reg_lh);
1401 /* Get MA_SOM attributes if update lock is given. */
1403 lock->l_policy_data.l_inodebits.bits & MDS_INODELOCK_UPDATE &&
1404 S_ISREG(lu_object_attr(&mdt_object_child(child)->mo_lu)))
1407 /* finally, we can get attr for child. */
1408 mdt_set_capainfo(info, 1, child_fid, BYPASS_CAPA);
1409 rc = mdt_getattr_internal(info, child, ma_need);
1410 if (unlikely(rc != 0)) {
1411 mdt_object_unlock(info, child, lhc, 1);
1413 /* Debugging code. */
1414 res_id = &lock->l_resource->lr_name;
1415 LDLM_DEBUG(lock, "Returning lock to client");
1416 LASSERTF(fid_res_name_eq(mdt_object_fid(child),
1417 &lock->l_resource->lr_name),
1418 "Lock res_id: %lu/%lu/%lu, Fid: "DFID".\n",
1419 (unsigned long)res_id->name[0],
1420 (unsigned long)res_id->name[1],
1421 (unsigned long)res_id->name[2],
1422 PFID(mdt_object_fid(child)));
1423 if (mdt_object_exists(child) && !mdt_object_remote(child))
1424 mdt_pack_size2body(info, child);
1427 LDLM_LOCK_PUT(lock);
1431 mdt_object_put(info->mti_env, child);
1434 mdt_object_unlock(info, parent, lhp, 1);
1438 /* normal handler: should release the child lock */
1439 int mdt_getattr_name(struct mdt_thread_info *info)
1441 struct mdt_lock_handle *lhc = &info->mti_lh[MDT_LH_CHILD];
1442 struct mdt_body *reqbody;
1443 struct mdt_body *repbody;
1447 reqbody = req_capsule_client_get(info->mti_pill, &RMF_MDT_BODY);
1448 LASSERT(reqbody != NULL);
1449 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
1450 LASSERT(repbody != NULL);
1452 info->mti_cross_ref = !!(reqbody->valid & OBD_MD_FLCROSSREF);
1453 repbody->eadatasize = 0;
1454 repbody->aclsize = 0;
1456 rc = mdt_init_ucred(info, reqbody);
1458 GOTO(out_shrink, rc);
1460 rc = mdt_getattr_name_lock(info, lhc, MDS_INODELOCK_UPDATE, NULL);
1461 if (lustre_handle_is_used(&lhc->mlh_reg_lh)) {
1462 ldlm_lock_decref(&lhc->mlh_reg_lh, lhc->mlh_reg_mode);
1463 lhc->mlh_reg_lh.cookie = 0;
1465 mdt_exit_ucred(info);
1468 mdt_client_compatibility(info);
1469 rc2 = mdt_fix_reply(info);
1475 static int mdt_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
1476 void *karg, void *uarg);
1478 int mdt_set_info(struct mdt_thread_info *info)
1480 struct ptlrpc_request *req = mdt_info_req(info);
1483 int keylen, vallen, rc = 0;
1486 rc = req_capsule_server_pack(info->mti_pill);
1490 key = req_capsule_client_get(info->mti_pill, &RMF_SETINFO_KEY);
1492 DEBUG_REQ(D_HA, req, "no set_info key");
1496 keylen = req_capsule_get_size(info->mti_pill, &RMF_SETINFO_KEY,
1499 val = req_capsule_client_get(info->mti_pill, &RMF_SETINFO_VAL);
1501 DEBUG_REQ(D_HA, req, "no set_info val");
1505 vallen = req_capsule_get_size(info->mti_pill, &RMF_SETINFO_VAL,
1508 /* Swab any part of val you need to here */
1509 if (KEY_IS(KEY_READ_ONLY)) {
1511 lustre_msg_set_status(req->rq_repmsg, 0);
1513 spin_lock(&req->rq_export->exp_lock);
1515 *exp_connect_flags_ptr(req->rq_export) |=
1518 *exp_connect_flags_ptr(req->rq_export) &=
1519 ~OBD_CONNECT_RDONLY;
1520 spin_unlock(&req->rq_export->exp_lock);
1522 } else if (KEY_IS(KEY_CHANGELOG_CLEAR)) {
1523 struct changelog_setinfo *cs =
1524 (struct changelog_setinfo *)val;
1525 if (vallen != sizeof(*cs)) {
1526 CERROR("Bad changelog_clear setinfo size %d\n", vallen);
1529 if (ptlrpc_req_need_swab(req)) {
1530 __swab64s(&cs->cs_recno);
1531 __swab32s(&cs->cs_id);
1534 rc = mdt_iocontrol(OBD_IOC_CHANGELOG_CLEAR, info->mti_exp,
1536 lustre_msg_set_status(req->rq_repmsg, rc);
1545 * Top-level handler for MDT connection requests.
1547 int mdt_connect(struct mdt_thread_info *info)
1550 struct obd_connect_data *reply;
1551 struct obd_export *exp;
1552 struct ptlrpc_request *req = mdt_info_req(info);
1554 rc = target_handle_connect(req);
1556 return err_serious(rc);
1558 LASSERT(req->rq_export != NULL);
1559 info->mti_mdt = mdt_dev(req->rq_export->exp_obd->obd_lu_dev);
1560 rc = mdt_init_sec_level(info);
1562 obd_disconnect(class_export_get(req->rq_export));
1566 /* To avoid exposing partially initialized connection flags, changes up
1567 * to this point have been staged in reply->ocd_connect_flags. Now that
1568 * connection handling has completed successfully, atomically update
1569 * the connect flags in the shared export data structure. LU-1623 */
1570 reply = req_capsule_server_get(info->mti_pill, &RMF_CONNECT_DATA);
1571 exp = req->rq_export;
1572 spin_lock(&exp->exp_lock);
1573 *exp_connect_flags_ptr(exp) = reply->ocd_connect_flags;
1574 spin_unlock(&exp->exp_lock);
1576 rc = mdt_init_idmap(info);
1578 obd_disconnect(class_export_get(req->rq_export));
1583 int mdt_disconnect(struct mdt_thread_info *info)
1588 rc = target_handle_disconnect(mdt_info_req(info));
1590 rc = err_serious(rc);
1594 static int mdt_sendpage(struct mdt_thread_info *info,
1595 struct lu_rdpg *rdpg, int nob)
1597 struct ptlrpc_request *req = mdt_info_req(info);
1598 struct obd_export *exp = req->rq_export;
1599 struct ptlrpc_bulk_desc *desc;
1600 struct l_wait_info *lwi = &info->mti_u.rdpg.mti_wait_info;
1607 desc = ptlrpc_prep_bulk_exp(req, rdpg->rp_npages, 1, BULK_PUT_SOURCE,
1612 if (!(exp_connect_flags(exp) & OBD_CONNECT_BRW_SIZE))
1613 /* old client requires reply size in it's PAGE_SIZE,
1614 * which is rdpg->rp_count */
1615 nob = rdpg->rp_count;
1617 for (i = 0, tmpcount = nob; i < rdpg->rp_npages && tmpcount > 0;
1618 i++, tmpcount -= tmpsize) {
1619 tmpsize = min_t(int, tmpcount, CFS_PAGE_SIZE);
1620 ptlrpc_prep_bulk_page_pin(desc, rdpg->rp_pages[i], 0, tmpsize);
1623 LASSERT(desc->bd_nob == nob);
1624 rc = target_bulk_io(exp, desc, lwi);
1625 ptlrpc_free_bulk_pin(desc);
1629 int mdt_readpage(struct mdt_thread_info *info)
1631 struct mdt_object *object = info->mti_object;
1632 struct lu_rdpg *rdpg = &info->mti_u.rdpg.mti_rdpg;
1633 struct mdt_body *reqbody;
1634 struct mdt_body *repbody;
1639 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_READPAGE_PACK))
1640 RETURN(err_serious(-ENOMEM));
1642 reqbody = req_capsule_client_get(info->mti_pill, &RMF_MDT_BODY);
1643 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
1644 if (reqbody == NULL || repbody == NULL)
1645 RETURN(err_serious(-EFAULT));
1648 * prepare @rdpg before calling lower layers and transfer itself. Here
1649 * reqbody->size contains offset of where to start to read and
1650 * reqbody->nlink contains number bytes to read.
1652 rdpg->rp_hash = reqbody->size;
1653 if (rdpg->rp_hash != reqbody->size) {
1654 CERROR("Invalid hash: "LPX64" != "LPX64"\n",
1655 rdpg->rp_hash, reqbody->size);
1659 rdpg->rp_attrs = reqbody->mode;
1660 if (exp_connect_flags(info->mti_exp) & OBD_CONNECT_64BITHASH)
1661 rdpg->rp_attrs |= LUDA_64BITHASH;
1662 rdpg->rp_count = min_t(unsigned int, reqbody->nlink,
1663 exp_max_brw_size(info->mti_exp));
1664 rdpg->rp_npages = (rdpg->rp_count + CFS_PAGE_SIZE - 1) >>
1666 OBD_ALLOC(rdpg->rp_pages, rdpg->rp_npages * sizeof rdpg->rp_pages[0]);
1667 if (rdpg->rp_pages == NULL)
1670 for (i = 0; i < rdpg->rp_npages; ++i) {
1671 rdpg->rp_pages[i] = cfs_alloc_page(CFS_ALLOC_STD);
1672 if (rdpg->rp_pages[i] == NULL)
1673 GOTO(free_rdpg, rc = -ENOMEM);
1676 /* call lower layers to fill allocated pages with directory data */
1677 rc = mo_readpage(info->mti_env, mdt_object_child(object), rdpg);
1679 GOTO(free_rdpg, rc);
1681 /* send pages to client */
1682 rc = mdt_sendpage(info, rdpg, rc);
1687 for (i = 0; i < rdpg->rp_npages; i++)
1688 if (rdpg->rp_pages[i] != NULL)
1689 cfs_free_page(rdpg->rp_pages[i]);
1690 OBD_FREE(rdpg->rp_pages, rdpg->rp_npages * sizeof rdpg->rp_pages[0]);
1692 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_SENDPAGE))
1698 static int mdt_reint_internal(struct mdt_thread_info *info,
1699 struct mdt_lock_handle *lhc,
1702 struct req_capsule *pill = info->mti_pill;
1703 struct mdt_body *repbody;
1708 rc = mdt_reint_unpack(info, op);
1710 CERROR("Can't unpack reint, rc %d\n", rc);
1711 RETURN(err_serious(rc));
1714 /* for replay (no_create) lmm is not needed, client has it already */
1715 if (req_capsule_has_field(pill, &RMF_MDT_MD, RCL_SERVER))
1716 req_capsule_set_size(pill, &RMF_MDT_MD, RCL_SERVER,
1717 info->mti_rr.rr_eadatalen);
1719 /* llog cookies are always 0, the field is kept for compatibility */
1720 if (req_capsule_has_field(pill, &RMF_LOGCOOKIES, RCL_SERVER))
1721 req_capsule_set_size(pill, &RMF_LOGCOOKIES, RCL_SERVER, 0);
1723 rc = req_capsule_server_pack(pill);
1725 CERROR("Can't pack response, rc %d\n", rc);
1726 RETURN(err_serious(rc));
1729 if (req_capsule_has_field(pill, &RMF_MDT_BODY, RCL_SERVER)) {
1730 repbody = req_capsule_server_get(pill, &RMF_MDT_BODY);
1732 repbody->eadatasize = 0;
1733 repbody->aclsize = 0;
1736 OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_REINT_DELAY, 10);
1738 /* for replay no cookkie / lmm need, because client have this already */
1739 if (info->mti_spec.no_create)
1740 if (req_capsule_has_field(pill, &RMF_MDT_MD, RCL_SERVER))
1741 req_capsule_set_size(pill, &RMF_MDT_MD, RCL_SERVER, 0);
1743 rc = mdt_init_ucred_reint(info);
1745 GOTO(out_shrink, rc);
1747 rc = mdt_fix_attr_ucred(info, op);
1749 GOTO(out_ucred, rc = err_serious(rc));
1751 if (mdt_check_resent(info, mdt_reconstruct, lhc)) {
1752 rc = lustre_msg_get_status(mdt_info_req(info)->rq_repmsg);
1753 GOTO(out_ucred, rc);
1755 rc = mdt_reint_rec(info, lhc);
1758 mdt_exit_ucred(info);
1760 mdt_client_compatibility(info);
1761 rc2 = mdt_fix_reply(info);
1767 static long mdt_reint_opcode(struct mdt_thread_info *info,
1768 const struct req_format **fmt)
1770 struct mdt_rec_reint *rec;
1773 rec = req_capsule_client_get(info->mti_pill, &RMF_REC_REINT);
1775 opc = rec->rr_opcode;
1776 DEBUG_REQ(D_INODE, mdt_info_req(info), "reint opt = %ld", opc);
1777 if (opc < REINT_MAX && fmt[opc] != NULL)
1778 req_capsule_extend(info->mti_pill, fmt[opc]);
1780 CERROR("%s: Unsupported opcode '%ld' from client '%s': "
1781 "rc = %d\n", mdt_obd_name(info->mti_mdt), opc,
1782 info->mti_mdt->mdt_ldlm_client->cli_name,
1784 opc = err_serious(-EFAULT);
1787 opc = err_serious(-EFAULT);
1792 int mdt_reint(struct mdt_thread_info *info)
1797 static const struct req_format *reint_fmts[REINT_MAX] = {
1798 [REINT_SETATTR] = &RQF_MDS_REINT_SETATTR,
1799 [REINT_CREATE] = &RQF_MDS_REINT_CREATE,
1800 [REINT_LINK] = &RQF_MDS_REINT_LINK,
1801 [REINT_UNLINK] = &RQF_MDS_REINT_UNLINK,
1802 [REINT_RENAME] = &RQF_MDS_REINT_RENAME,
1803 [REINT_OPEN] = &RQF_MDS_REINT_OPEN,
1804 [REINT_SETXATTR] = &RQF_MDS_REINT_SETXATTR,
1805 [REINT_RMENTRY] = &RQF_MDS_REINT_UNLINK
1810 opc = mdt_reint_opcode(info, reint_fmts);
1813 * No lock possible here from client to pass it to reint code
1816 rc = mdt_reint_internal(info, NULL, opc);
1821 info->mti_fail_id = OBD_FAIL_MDS_REINT_NET_REP;
1825 /* this should sync the whole device */
1826 static int mdt_device_sync(const struct lu_env *env, struct mdt_device *mdt)
1828 struct dt_device *dt = mdt->mdt_bottom;
1832 rc = dt->dd_ops->dt_sync(env, dt);
1836 /* this should sync this object */
1837 static int mdt_object_sync(struct mdt_thread_info *info)
1839 struct md_object *next;
1843 if (!mdt_object_exists(info->mti_object)) {
1844 CWARN("Non existing object "DFID"!\n",
1845 PFID(mdt_object_fid(info->mti_object)));
1848 next = mdt_object_child(info->mti_object);
1849 rc = mo_object_sync(info->mti_env, next);
1854 int mdt_sync(struct mdt_thread_info *info)
1856 struct ptlrpc_request *req = mdt_info_req(info);
1857 struct req_capsule *pill = info->mti_pill;
1858 struct mdt_body *body;
1862 /* The fid may be zero, so we req_capsule_set manually */
1863 req_capsule_set(pill, &RQF_MDS_SYNC);
1865 body = req_capsule_client_get(pill, &RMF_MDT_BODY);
1867 RETURN(err_serious(-EINVAL));
1869 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_SYNC_PACK))
1870 RETURN(err_serious(-ENOMEM));
1872 if (fid_seq(&body->fid1) == 0) {
1873 /* sync the whole device */
1874 rc = req_capsule_server_pack(pill);
1876 rc = mdt_device_sync(info->mti_env, info->mti_mdt);
1878 rc = err_serious(rc);
1880 /* sync an object */
1881 rc = mdt_unpack_req_pack_rep(info, HABEO_CORPUS|HABEO_REFERO);
1883 rc = mdt_object_sync(info);
1885 const struct lu_fid *fid;
1886 struct lu_attr *la = &info->mti_attr.ma_attr;
1888 info->mti_attr.ma_need = MA_INODE;
1889 info->mti_attr.ma_valid = 0;
1890 rc = mdt_attr_get_complex(info, info->mti_object,
1893 body = req_capsule_server_get(pill,
1895 fid = mdt_object_fid(info->mti_object);
1896 mdt_pack_attr2body(info, body, la, fid);
1900 rc = err_serious(rc);
1903 mdt_counter_incr(req, LPROC_MDT_SYNC);
1909 * Quotacheck handler.
1910 * in-kernel quotacheck isn't supported any more.
1912 int mdt_quotacheck(struct mdt_thread_info *info)
1914 struct obd_quotactl *oqctl;
1918 oqctl = req_capsule_client_get(info->mti_pill, &RMF_OBD_QUOTACTL);
1920 RETURN(err_serious(-EPROTO));
1922 rc = req_capsule_server_pack(info->mti_pill);
1924 RETURN(err_serious(rc));
1926 /* deprecated, not used any more */
1927 RETURN(-EOPNOTSUPP);
1931 * Handle quota control requests to consult current usage/limit, but also
1932 * to configure quota enforcement
1934 int mdt_quotactl(struct mdt_thread_info *info)
1936 struct obd_export *exp = info->mti_exp;
1937 struct req_capsule *pill = info->mti_pill;
1938 struct obd_quotactl *oqctl, *repoqc;
1940 struct lu_device *qmt = info->mti_mdt->mdt_qmt_dev;
1943 oqctl = req_capsule_client_get(pill, &RMF_OBD_QUOTACTL);
1945 RETURN(err_serious(-EPROTO));
1947 rc = req_capsule_server_pack(pill);
1949 RETURN(err_serious(rc));
1951 switch (oqctl->qc_cmd) {
1953 case LUSTRE_Q_INVALIDATE:
1954 case LUSTRE_Q_FINVALIDATE:
1958 /* deprecated, not used any more */
1959 RETURN(-EOPNOTSUPP);
1960 /* master quotactl */
1966 RETURN(-EOPNOTSUPP);
1967 /* slave quotactl */
1972 CERROR("Unsupported quotactl command: %d\n", oqctl->qc_cmd);
1976 /* map uid/gid for remote client */
1978 if (exp_connect_rmtclient(exp)) {
1979 struct lustre_idmap_table *idmap;
1981 idmap = mdt_req2med(mdt_info_req(info))->med_idmap;
1983 if (unlikely(oqctl->qc_cmd != Q_GETQUOTA &&
1984 oqctl->qc_cmd != Q_GETINFO))
1987 if (oqctl->qc_type == USRQUOTA)
1988 id = lustre_idmap_lookup_uid(NULL, idmap, 0,
1990 else if (oqctl->qc_type == GRPQUOTA)
1991 id = lustre_idmap_lookup_gid(NULL, idmap, 0,
1996 if (id == CFS_IDMAP_NOTFOUND) {
1997 CDEBUG(D_QUOTA, "no mapping for id %u\n", oqctl->qc_id);
2002 repoqc = req_capsule_server_get(pill, &RMF_OBD_QUOTACTL);
2004 RETURN(err_serious(-EFAULT));
2006 if (oqctl->qc_id != id)
2007 swap(oqctl->qc_id, id);
2009 switch (oqctl->qc_cmd) {
2015 /* forward quotactl request to QMT */
2016 rc = qmt_hdls.qmth_quotactl(info->mti_env, qmt, oqctl);
2021 /* slave quotactl */
2022 rc = lquotactl_slv(info->mti_env, info->mti_mdt->mdt_bottom,
2027 CERROR("Unsupported quotactl command: %d\n", oqctl->qc_cmd);
2031 if (oqctl->qc_id != id)
2032 swap(oqctl->qc_id, id);
2039 * OBD PING and other handlers.
2041 int mdt_obd_ping(struct mdt_thread_info *info)
2046 req_capsule_set(info->mti_pill, &RQF_OBD_PING);
2048 rc = target_handle_ping(mdt_info_req(info));
2050 rc = err_serious(rc);
2055 * OBD_IDX_READ handler
2057 int mdt_obd_idx_read(struct mdt_thread_info *info)
2059 struct mdt_device *mdt = info->mti_mdt;
2060 struct lu_rdpg *rdpg = &info->mti_u.rdpg.mti_rdpg;
2061 struct idx_info *req_ii, *rep_ii;
2065 memset(rdpg, 0, sizeof(*rdpg));
2066 req_capsule_set(info->mti_pill, &RQF_OBD_IDX_READ);
2068 /* extract idx_info buffer from request & reply */
2069 req_ii = req_capsule_client_get(info->mti_pill, &RMF_IDX_INFO);
2070 if (req_ii == NULL || req_ii->ii_magic != IDX_INFO_MAGIC)
2071 RETURN(err_serious(-EPROTO));
2073 rc = req_capsule_server_pack(info->mti_pill);
2075 RETURN(err_serious(rc));
2077 rep_ii = req_capsule_server_get(info->mti_pill, &RMF_IDX_INFO);
2079 RETURN(err_serious(-EFAULT));
2080 rep_ii->ii_magic = IDX_INFO_MAGIC;
2082 /* extract hash to start with */
2083 rdpg->rp_hash = req_ii->ii_hash_start;
2085 /* extract requested attributes */
2086 rdpg->rp_attrs = req_ii->ii_attrs;
2088 /* check that fid packed in request is valid and supported */
2089 if (!fid_is_sane(&req_ii->ii_fid))
2091 rep_ii->ii_fid = req_ii->ii_fid;
2094 rep_ii->ii_flags = req_ii->ii_flags;
2096 /* compute number of pages to allocate, ii_count is the number of 4KB
2098 if (req_ii->ii_count <= 0)
2099 GOTO(out, rc = -EFAULT);
2100 rdpg->rp_count = min_t(unsigned int, req_ii->ii_count << LU_PAGE_SHIFT,
2101 exp_max_brw_size(info->mti_exp));
2102 rdpg->rp_npages = (rdpg->rp_count + CFS_PAGE_SIZE -1) >> CFS_PAGE_SHIFT;
2104 /* allocate pages to store the containers */
2105 OBD_ALLOC(rdpg->rp_pages, rdpg->rp_npages * sizeof(rdpg->rp_pages[0]));
2106 if (rdpg->rp_pages == NULL)
2107 GOTO(out, rc = -ENOMEM);
2108 for (i = 0; i < rdpg->rp_npages; i++) {
2109 rdpg->rp_pages[i] = cfs_alloc_page(CFS_ALLOC_STD);
2110 if (rdpg->rp_pages[i] == NULL)
2111 GOTO(out, rc = -ENOMEM);
2114 /* populate pages with key/record pairs */
2115 rc = dt_index_read(info->mti_env, mdt->mdt_bottom, rep_ii, rdpg);
2119 LASSERTF(rc <= rdpg->rp_count, "dt_index_read() returned more than "
2120 "asked %d > %d\n", rc, rdpg->rp_count);
2122 /* send pages to client */
2123 rc = mdt_sendpage(info, rdpg, rc);
2127 if (rdpg->rp_pages) {
2128 for (i = 0; i < rdpg->rp_npages; i++)
2129 if (rdpg->rp_pages[i])
2130 cfs_free_page(rdpg->rp_pages[i]);
2131 OBD_FREE(rdpg->rp_pages,
2132 rdpg->rp_npages * sizeof(rdpg->rp_pages[0]));
2137 int mdt_obd_log_cancel(struct mdt_thread_info *info)
2139 return err_serious(-EOPNOTSUPP);
2142 int mdt_obd_qc_callback(struct mdt_thread_info *info)
2144 return err_serious(-EOPNOTSUPP);
2151 /** clone llog ctxt from child (mdd)
2152 * This allows remote llog (replicator) access.
2153 * We can either pass all llog RPCs (eg mdt_llog_create) on to child where the
2154 * context was originally set up, or we can handle them directly.
2155 * I choose the latter, but that means I need any llog
2156 * contexts set up by child to be accessable by the mdt. So we clone the
2157 * context into our context list here.
2159 static int mdt_llog_ctxt_clone(const struct lu_env *env, struct mdt_device *mdt,
2162 struct md_device *next = mdt->mdt_child;
2163 struct llog_ctxt *ctxt;
2166 if (!llog_ctxt_null(mdt2obd_dev(mdt), idx))
2169 rc = next->md_ops->mdo_llog_ctxt_get(env, next, idx, (void **)&ctxt);
2170 if (rc || ctxt == NULL) {
2174 rc = llog_group_set_ctxt(&mdt2obd_dev(mdt)->obd_olg, ctxt, idx);
2176 CERROR("Can't set mdt ctxt %d\n", rc);
2181 static int mdt_llog_ctxt_unclone(const struct lu_env *env,
2182 struct mdt_device *mdt, int idx)
2184 struct llog_ctxt *ctxt;
2186 ctxt = llog_get_context(mdt2obd_dev(mdt), idx);
2189 /* Put once for the get we just did, and once for the clone */
2190 llog_ctxt_put(ctxt);
2191 llog_ctxt_put(ctxt);
2195 int mdt_llog_create(struct mdt_thread_info *info)
2199 req_capsule_set(info->mti_pill, &RQF_LLOG_ORIGIN_HANDLE_CREATE);
2200 rc = llog_origin_handle_open(mdt_info_req(info));
2201 return (rc < 0 ? err_serious(rc) : rc);
2204 int mdt_llog_destroy(struct mdt_thread_info *info)
2208 req_capsule_set(info->mti_pill, &RQF_LLOG_ORIGIN_HANDLE_DESTROY);
2209 rc = llog_origin_handle_destroy(mdt_info_req(info));
2210 return (rc < 0 ? err_serious(rc) : rc);
2213 int mdt_llog_read_header(struct mdt_thread_info *info)
2217 req_capsule_set(info->mti_pill, &RQF_LLOG_ORIGIN_HANDLE_READ_HEADER);
2218 rc = llog_origin_handle_read_header(mdt_info_req(info));
2219 return (rc < 0 ? err_serious(rc) : rc);
2222 int mdt_llog_next_block(struct mdt_thread_info *info)
2226 req_capsule_set(info->mti_pill, &RQF_LLOG_ORIGIN_HANDLE_NEXT_BLOCK);
2227 rc = llog_origin_handle_next_block(mdt_info_req(info));
2228 return (rc < 0 ? err_serious(rc) : rc);
2231 int mdt_llog_prev_block(struct mdt_thread_info *info)
2235 req_capsule_set(info->mti_pill, &RQF_LLOG_ORIGIN_HANDLE_PREV_BLOCK);
2236 rc = llog_origin_handle_prev_block(mdt_info_req(info));
2237 return (rc < 0 ? err_serious(rc) : rc);
2245 static struct ldlm_callback_suite cbs = {
2246 .lcs_completion = ldlm_server_completion_ast,
2247 .lcs_blocking = ldlm_server_blocking_ast,
2248 .lcs_glimpse = ldlm_server_glimpse_ast
2251 int mdt_enqueue(struct mdt_thread_info *info)
2253 struct ptlrpc_request *req;
2257 * info->mti_dlm_req already contains swapped and (if necessary)
2258 * converted dlm request.
2260 LASSERT(info->mti_dlm_req != NULL);
2262 req = mdt_info_req(info);
2263 rc = ldlm_handle_enqueue0(info->mti_mdt->mdt_namespace,
2264 req, info->mti_dlm_req, &cbs);
2265 info->mti_fail_id = OBD_FAIL_LDLM_REPLY;
2266 return rc ? err_serious(rc) : req->rq_status;
2269 int mdt_convert(struct mdt_thread_info *info)
2272 struct ptlrpc_request *req;
2274 LASSERT(info->mti_dlm_req);
2275 req = mdt_info_req(info);
2276 rc = ldlm_handle_convert0(req, info->mti_dlm_req);
2277 return rc ? err_serious(rc) : req->rq_status;
2280 int mdt_bl_callback(struct mdt_thread_info *info)
2282 CERROR("bl callbacks should not happen on MDS\n");
2284 return err_serious(-EOPNOTSUPP);
2287 int mdt_cp_callback(struct mdt_thread_info *info)
2289 CERROR("cp callbacks should not happen on MDS\n");
2291 return err_serious(-EOPNOTSUPP);
2295 * sec context handlers
2297 int mdt_sec_ctx_handle(struct mdt_thread_info *info)
2301 rc = mdt_handle_idmap(info);
2304 struct ptlrpc_request *req = mdt_info_req(info);
2307 opc = lustre_msg_get_opc(req->rq_reqmsg);
2308 if (opc == SEC_CTX_INIT || opc == SEC_CTX_INIT_CONT)
2309 sptlrpc_svc_ctx_invalidate(req);
2312 CFS_FAIL_TIMEOUT(OBD_FAIL_SEC_CTX_HDL_PAUSE, cfs_fail_val);
2318 * quota request handlers
2320 int mdt_quota_dqacq(struct mdt_thread_info *info)
2322 struct lu_device *qmt = info->mti_mdt->mdt_qmt_dev;
2327 RETURN(err_serious(-EOPNOTSUPP));
2329 rc = qmt_hdls.qmth_dqacq(info->mti_env, qmt, mdt_info_req(info));
2333 static struct mdt_object *mdt_obj(struct lu_object *o)
2335 LASSERT(lu_device_is_mdt(o->lo_dev));
2336 return container_of0(o, struct mdt_object, mot_obj.mo_lu);
2339 struct mdt_object *mdt_object_new(const struct lu_env *env,
2340 struct mdt_device *d,
2341 const struct lu_fid *f)
2343 struct lu_object_conf conf = { .loc_flags = LOC_F_NEW };
2344 struct lu_object *o;
2345 struct mdt_object *m;
2348 CDEBUG(D_INFO, "Allocate object for "DFID"\n", PFID(f));
2349 o = lu_object_find(env, &d->mdt_md_dev.md_lu_dev, f, &conf);
2350 if (unlikely(IS_ERR(o)))
2351 m = (struct mdt_object *)o;
2357 struct mdt_object *mdt_object_find(const struct lu_env *env,
2358 struct mdt_device *d,
2359 const struct lu_fid *f)
2361 struct lu_object *o;
2362 struct mdt_object *m;
2365 CDEBUG(D_INFO, "Find object for "DFID"\n", PFID(f));
2366 o = lu_object_find(env, &d->mdt_md_dev.md_lu_dev, f, NULL);
2367 if (unlikely(IS_ERR(o)))
2368 m = (struct mdt_object *)o;
2375 * Asyncronous commit for mdt device.
2377 * Pass asynchonous commit call down the MDS stack.
2379 * \param env environment
2380 * \param mdt the mdt device
2382 static void mdt_device_commit_async(const struct lu_env *env,
2383 struct mdt_device *mdt)
2385 struct dt_device *dt = mdt->mdt_bottom;
2388 rc = dt->dd_ops->dt_commit_async(env, dt);
2389 if (unlikely(rc != 0))
2390 CWARN("async commit start failed with rc = %d", rc);
2394 * Mark the lock as "synchonous".
2396 * Mark the lock to deffer transaction commit to the unlock time.
2398 * \param lock the lock to mark as "synchonous"
2400 * \see mdt_is_lock_sync
2401 * \see mdt_save_lock
2403 static inline void mdt_set_lock_sync(struct ldlm_lock *lock)
2405 lock->l_ast_data = (void*)1;
2409 * Check whehter the lock "synchonous" or not.
2411 * \param lock the lock to check
2412 * \retval 1 the lock is "synchonous"
2413 * \retval 0 the lock isn't "synchronous"
2415 * \see mdt_set_lock_sync
2416 * \see mdt_save_lock
2418 static inline int mdt_is_lock_sync(struct ldlm_lock *lock)
2420 return lock->l_ast_data != NULL;
2424 * Blocking AST for mdt locks.
2426 * Starts transaction commit if in case of COS lock conflict or
2427 * deffers such a commit to the mdt_save_lock.
2429 * \param lock the lock which blocks a request or cancelling lock
2430 * \param desc unused
2431 * \param data unused
2432 * \param flag indicates whether this cancelling or blocking callback
2434 * \see ldlm_blocking_ast_nocheck
2436 int mdt_blocking_ast(struct ldlm_lock *lock, struct ldlm_lock_desc *desc,
2437 void *data, int flag)
2439 struct obd_device *obd = ldlm_lock_to_ns(lock)->ns_obd;
2440 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
2444 if (flag == LDLM_CB_CANCELING)
2446 lock_res_and_lock(lock);
2447 if (lock->l_blocking_ast != mdt_blocking_ast) {
2448 unlock_res_and_lock(lock);
2451 if (mdt_cos_is_enabled(mdt) &&
2452 lock->l_req_mode & (LCK_PW | LCK_EX) &&
2453 lock->l_blocking_lock != NULL &&
2454 lock->l_client_cookie != lock->l_blocking_lock->l_client_cookie) {
2455 mdt_set_lock_sync(lock);
2457 rc = ldlm_blocking_ast_nocheck(lock);
2459 /* There is no lock conflict if l_blocking_lock == NULL,
2460 * it indicates a blocking ast sent from ldlm_lock_decref_internal
2461 * when the last reference to a local lock was released */
2462 if (lock->l_req_mode == LCK_COS && lock->l_blocking_lock != NULL) {
2465 rc = lu_env_init(&env, LCT_LOCAL);
2466 if (unlikely(rc != 0))
2467 CWARN("lu_env initialization failed with rc = %d,"
2468 "cannot start asynchronous commit\n", rc);
2470 mdt_device_commit_async(&env, mdt);
2476 int mdt_md_blocking_ast(struct ldlm_lock *lock, struct ldlm_lock_desc *desc,
2477 void *data, int flag)
2479 struct lustre_handle lockh;
2483 case LDLM_CB_BLOCKING:
2484 ldlm_lock2handle(lock, &lockh);
2485 rc = ldlm_cli_cancel(&lockh, LCF_ASYNC);
2487 CDEBUG(D_INODE, "ldlm_cli_cancel: %d\n", rc);
2491 case LDLM_CB_CANCELING:
2492 LDLM_DEBUG(lock, "Revoke remote lock\n");
2500 int mdt_remote_object_lock(struct mdt_thread_info *mti,
2501 struct mdt_object *o, struct lustre_handle *lh,
2502 ldlm_mode_t mode, __u64 ibits)
2504 struct ldlm_enqueue_info *einfo = &mti->mti_einfo;
2505 ldlm_policy_data_t *policy = &mti->mti_policy;
2509 LASSERT(mdt_object_remote(o));
2511 LASSERT((ibits & MDS_INODELOCK_UPDATE));
2513 memset(einfo, 0, sizeof(*einfo));
2514 einfo->ei_type = LDLM_IBITS;
2515 einfo->ei_mode = mode;
2516 einfo->ei_cb_bl = mdt_md_blocking_ast;
2517 einfo->ei_cb_cp = ldlm_completion_ast;
2519 memset(policy, 0, sizeof(*policy));
2520 policy->l_inodebits.bits = ibits;
2522 rc = mo_object_lock(mti->mti_env, mdt_object_child(o), lh, einfo,
2527 static int mdt_object_lock0(struct mdt_thread_info *info, struct mdt_object *o,
2528 struct mdt_lock_handle *lh, __u64 ibits,
2529 bool nonblock, int locality)
2531 struct ldlm_namespace *ns = info->mti_mdt->mdt_namespace;
2532 ldlm_policy_data_t *policy = &info->mti_policy;
2533 struct ldlm_res_id *res_id = &info->mti_res_id;
2538 LASSERT(!lustre_handle_is_used(&lh->mlh_reg_lh));
2539 LASSERT(!lustre_handle_is_used(&lh->mlh_pdo_lh));
2540 LASSERT(lh->mlh_reg_mode != LCK_MINMODE);
2541 LASSERT(lh->mlh_type != MDT_NUL_LOCK);
2543 if (mdt_object_remote(o)) {
2544 if (locality == MDT_CROSS_LOCK) {
2545 ibits &= ~(MDS_INODELOCK_UPDATE | MDS_INODELOCK_PERM);
2546 ibits |= MDS_INODELOCK_LOOKUP;
2549 (MDS_INODELOCK_UPDATE | MDS_INODELOCK_PERM)),
2550 "%s: wrong bit "LPX64" for remote obj "DFID"\n",
2551 mdt_obd_name(info->mti_mdt), ibits,
2552 PFID(mdt_object_fid(o)));
2553 LASSERT(ibits & MDS_INODELOCK_LOOKUP);
2555 /* No PDO lock on remote object */
2556 LASSERT(lh->mlh_type != MDT_PDO_LOCK);
2559 if (lh->mlh_type == MDT_PDO_LOCK) {
2560 /* check for exists after object is locked */
2561 if (mdt_object_exists(o) == 0) {
2562 /* Non-existent object shouldn't have PDO lock */
2565 /* Non-dir object shouldn't have PDO lock */
2566 if (!S_ISDIR(lu_object_attr(&o->mot_obj.mo_lu)))
2571 memset(policy, 0, sizeof(*policy));
2572 fid_build_reg_res_name(mdt_object_fid(o), res_id);
2574 dlmflags = LDLM_FL_ATOMIC_CB;
2576 dlmflags |= LDLM_FL_BLOCK_NOWAIT;
2579 * Take PDO lock on whole directory and build correct @res_id for lock
2580 * on part of directory.
2582 if (lh->mlh_pdo_hash != 0) {
2583 LASSERT(lh->mlh_type == MDT_PDO_LOCK);
2584 mdt_lock_pdo_mode(info, o, lh);
2585 if (lh->mlh_pdo_mode != LCK_NL) {
2587 * Do not use LDLM_FL_LOCAL_ONLY for parallel lock, it
2588 * is never going to be sent to client and we do not
2589 * want it slowed down due to possible cancels.
2591 policy->l_inodebits.bits = MDS_INODELOCK_UPDATE;
2592 rc = mdt_fid_lock(ns, &lh->mlh_pdo_lh, lh->mlh_pdo_mode,
2593 policy, res_id, dlmflags,
2594 &info->mti_exp->exp_handle.h_cookie);
2600 * Finish res_id initializing by name hash marking part of
2601 * directory which is taking modification.
2603 res_id->name[LUSTRE_RES_ID_HSH_OFF] = lh->mlh_pdo_hash;
2606 policy->l_inodebits.bits = ibits;
2609 * Use LDLM_FL_LOCAL_ONLY for this lock. We do not know yet if it is
2610 * going to be sent to client. If it is - mdt_intent_policy() path will
2611 * fix it up and turn FL_LOCAL flag off.
2613 rc = mdt_fid_lock(ns, &lh->mlh_reg_lh, lh->mlh_reg_mode, policy,
2614 res_id, LDLM_FL_LOCAL_ONLY | dlmflags,
2615 &info->mti_exp->exp_handle.h_cookie);
2617 mdt_object_unlock(info, o, lh, 1);
2618 else if (unlikely(OBD_FAIL_PRECHECK(OBD_FAIL_MDS_PDO_LOCK)) &&
2619 lh->mlh_pdo_hash != 0 &&
2620 (lh->mlh_reg_mode == LCK_PW || lh->mlh_reg_mode == LCK_EX)) {
2621 OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_PDO_LOCK, 15);
2627 int mdt_object_lock(struct mdt_thread_info *info, struct mdt_object *o,
2628 struct mdt_lock_handle *lh, __u64 ibits, int locality)
2630 return mdt_object_lock0(info, o, lh, ibits, false, locality);
2633 int mdt_object_lock_try(struct mdt_thread_info *info, struct mdt_object *o,
2634 struct mdt_lock_handle *lh, __u64 ibits, int locality)
2636 struct mdt_lock_handle tmp = *lh;
2639 rc = mdt_object_lock0(info, o, &tmp, ibits, true, locality);
2647 * Save a lock within request object.
2649 * Keep the lock referenced until whether client ACK or transaction
2650 * commit happens or release the lock immediately depending on input
2651 * parameters. If COS is ON, a write lock is converted to COS lock
2654 * \param info thead info object
2655 * \param h lock handle
2656 * \param mode lock mode
2657 * \param decref force immediate lock releasing
2660 void mdt_save_lock(struct mdt_thread_info *info, struct lustre_handle *h,
2661 ldlm_mode_t mode, int decref)
2665 if (lustre_handle_is_used(h)) {
2666 if (decref || !info->mti_has_trans ||
2667 !(mode & (LCK_PW | LCK_EX))){
2668 mdt_fid_unlock(h, mode);
2670 struct mdt_device *mdt = info->mti_mdt;
2671 struct ldlm_lock *lock = ldlm_handle2lock(h);
2672 struct ptlrpc_request *req = mdt_info_req(info);
2675 LASSERTF(lock != NULL, "no lock for cookie "LPX64"\n",
2677 CDEBUG(D_HA, "request = %p reply state = %p"
2678 " transno = "LPD64"\n",
2679 req, req->rq_reply_state, req->rq_transno);
2680 if (mdt_cos_is_enabled(mdt)) {
2682 ldlm_lock_downgrade(lock, LCK_COS);
2685 ptlrpc_save_lock(req, h, mode, no_ack);
2686 if (mdt_is_lock_sync(lock)) {
2687 CDEBUG(D_HA, "found sync-lock,"
2688 " async commit started\n");
2689 mdt_device_commit_async(info->mti_env,
2692 LDLM_LOCK_PUT(lock);
2701 * Unlock mdt object.
2703 * Immeditely release the regular lock and the PDO lock or save the
2704 * lock in reqeuest and keep them referenced until client ACK or
2705 * transaction commit.
2707 * \param info thread info object
2708 * \param o mdt object
2709 * \param lh mdt lock handle referencing regular and PDO locks
2710 * \param decref force immediate lock releasing
2712 void mdt_object_unlock(struct mdt_thread_info *info, struct mdt_object *o,
2713 struct mdt_lock_handle *lh, int decref)
2717 mdt_save_lock(info, &lh->mlh_pdo_lh, lh->mlh_pdo_mode, decref);
2718 mdt_save_lock(info, &lh->mlh_reg_lh, lh->mlh_reg_mode, decref);
2720 if (lustre_handle_is_used(&lh->mlh_rreg_lh))
2721 ldlm_lock_decref(&lh->mlh_rreg_lh, lh->mlh_rreg_mode);
2726 struct mdt_object *mdt_object_find_lock(struct mdt_thread_info *info,
2727 const struct lu_fid *f,
2728 struct mdt_lock_handle *lh,
2731 struct mdt_object *o;
2733 o = mdt_object_find(info->mti_env, info->mti_mdt, f);
2737 rc = mdt_object_lock(info, o, lh, ibits,
2740 mdt_object_put(info->mti_env, o);
2747 void mdt_object_unlock_put(struct mdt_thread_info * info,
2748 struct mdt_object * o,
2749 struct mdt_lock_handle *lh,
2752 mdt_object_unlock(info, o, lh, decref);
2753 mdt_object_put(info->mti_env, o);
2756 struct mdt_handler *mdt_handler_find(__u32 opc, struct mdt_opc_slice *supported)
2758 struct mdt_opc_slice *s;
2759 struct mdt_handler *h;
2762 for (s = supported; s->mos_hs != NULL; s++) {
2763 if (s->mos_opc_start <= opc && opc < s->mos_opc_end) {
2764 h = s->mos_hs + (opc - s->mos_opc_start);
2765 if (likely(h->mh_opc != 0))
2766 LASSERTF(h->mh_opc == opc,
2767 "opcode mismatch %d != %d\n",
2770 h = NULL; /* unsupported opc */
2777 static int mdt_lock_resname_compat(struct mdt_device *m,
2778 struct ldlm_request *req)
2780 /* XXX something... later. */
2784 static int mdt_lock_reply_compat(struct mdt_device *m, struct ldlm_reply *rep)
2786 /* XXX something... later. */
2791 * Generic code handling requests that have struct mdt_body passed in:
2793 * - extract mdt_body from request and save it in @info, if present;
2795 * - create lu_object, corresponding to the fid in mdt_body, and save it in
2798 * - if HABEO_CORPUS flag is set for this request type check whether object
2799 * actually exists on storage (lu_object_exists()).
2802 static int mdt_body_unpack(struct mdt_thread_info *info, __u32 flags)
2804 const struct mdt_body *body;
2805 struct mdt_object *obj;
2806 const struct lu_env *env;
2807 struct req_capsule *pill;
2811 env = info->mti_env;
2812 pill = info->mti_pill;
2814 body = info->mti_body = req_capsule_client_get(pill, &RMF_MDT_BODY);
2818 if (!(body->valid & OBD_MD_FLID))
2821 if (!fid_is_sane(&body->fid1)) {
2822 CERROR("Invalid fid: "DFID"\n", PFID(&body->fid1));
2827 * Do not get size or any capa fields before we check that request
2828 * contains capa actually. There are some requests which do not, for
2829 * instance MDS_IS_SUBDIR.
2831 if (req_capsule_has_field(pill, &RMF_CAPA1, RCL_CLIENT) &&
2832 req_capsule_get_size(pill, &RMF_CAPA1, RCL_CLIENT))
2833 mdt_set_capainfo(info, 0, &body->fid1,
2834 req_capsule_client_get(pill, &RMF_CAPA1));
2836 obj = mdt_object_find(env, info->mti_mdt, &body->fid1);
2838 if ((flags & HABEO_CORPUS) &&
2839 !mdt_object_exists(obj)) {
2840 mdt_object_put(env, obj);
2841 /* for capability renew ENOENT will be handled in
2843 if (body->valid & OBD_MD_FLOSSCAPA)
2848 info->mti_object = obj;
2857 static int mdt_unpack_req_pack_rep(struct mdt_thread_info *info, __u32 flags)
2859 struct req_capsule *pill = info->mti_pill;
2863 if (req_capsule_has_field(pill, &RMF_MDT_BODY, RCL_CLIENT))
2864 rc = mdt_body_unpack(info, flags);
2868 if (rc == 0 && (flags & HABEO_REFERO)) {
2870 if (req_capsule_has_field(pill, &RMF_MDT_MD, RCL_SERVER))
2871 req_capsule_set_size(pill, &RMF_MDT_MD, RCL_SERVER,
2872 info->mti_body->eadatasize);
2873 if (req_capsule_has_field(pill, &RMF_LOGCOOKIES, RCL_SERVER))
2874 req_capsule_set_size(pill, &RMF_LOGCOOKIES,
2877 rc = req_capsule_server_pack(pill);
2882 static int mdt_init_capa_ctxt(const struct lu_env *env, struct mdt_device *m)
2884 struct md_device *next = m->mdt_child;
2886 return next->md_ops->mdo_init_capa_ctxt(env, next,
2887 m->mdt_opts.mo_mds_capa,
2888 m->mdt_capa_timeout,
2894 * Invoke handler for this request opc. Also do necessary preprocessing
2895 * (according to handler ->mh_flags), and post-processing (setting of
2896 * ->last_{xid,committed}).
2898 static int mdt_req_handle(struct mdt_thread_info *info,
2899 struct mdt_handler *h, struct ptlrpc_request *req)
2901 int rc, serious = 0;
2906 LASSERT(h->mh_act != NULL);
2907 LASSERT(h->mh_opc == lustre_msg_get_opc(req->rq_reqmsg));
2908 LASSERT(current->journal_info == NULL);
2911 * Checking for various OBD_FAIL_$PREF_$OPC_NET codes. _Do_ not try
2912 * to put same checks into handlers like mdt_close(), mdt_reint(),
2913 * etc., without talking to mdt authors first. Checking same thing
2914 * there again is useless and returning 0 error without packing reply
2915 * is buggy! Handlers either pack reply or return error.
2917 * We return 0 here and do not send any reply in order to emulate
2918 * network failure. Do not send any reply in case any of NET related
2919 * fail_id has occured.
2921 if (OBD_FAIL_CHECK_ORSET(h->mh_fail_id, OBD_FAIL_ONCE))
2925 flags = h->mh_flags;
2926 LASSERT(ergo(flags & (HABEO_CORPUS|HABEO_REFERO), h->mh_fmt != NULL));
2928 if (h->mh_fmt != NULL) {
2929 req_capsule_set(info->mti_pill, h->mh_fmt);
2930 rc = mdt_unpack_req_pack_rep(info, flags);
2933 if (rc == 0 && flags & MUTABOR &&
2934 exp_connect_flags(req->rq_export) & OBD_CONNECT_RDONLY)
2935 /* should it be rq_status? */
2938 if (rc == 0 && flags & HABEO_CLAVIS) {
2939 struct ldlm_request *dlm_req;
2941 LASSERT(h->mh_fmt != NULL);
2943 dlm_req = req_capsule_client_get(info->mti_pill, &RMF_DLM_REQ);
2944 if (dlm_req != NULL) {
2945 if (unlikely(dlm_req->lock_desc.l_resource.lr_type ==
2947 dlm_req->lock_desc.l_policy_data.\
2948 l_inodebits.bits == 0)) {
2950 * Lock without inodebits makes no sense and
2951 * will oops later in ldlm. If client miss to
2952 * set such bits, do not trigger ASSERTION.
2954 * For liblustre flock case, it maybe zero.
2958 if (info->mti_mdt->mdt_opts.mo_compat_resname)
2959 rc = mdt_lock_resname_compat(
2962 info->mti_dlm_req = dlm_req;
2969 /* capability setting changed via /proc, needs reinitialize ctxt */
2970 if (info->mti_mdt && info->mti_mdt->mdt_capa_conf) {
2971 mdt_init_capa_ctxt(info->mti_env, info->mti_mdt);
2972 info->mti_mdt->mdt_capa_conf = 0;
2975 if (likely(rc == 0)) {
2977 * Process request, there can be two types of rc:
2978 * 1) errors with msg unpack/pack, other failures outside the
2979 * operation itself. This is counted as serious errors;
2980 * 2) errors during fs operation, should be placed in rq_status
2983 rc = h->mh_act(info);
2985 !req->rq_no_reply && req->rq_reply_state == NULL) {
2986 DEBUG_REQ(D_ERROR, req, "MDT \"handler\" %s did not "
2987 "pack reply and returned 0 error\n",
2991 serious = is_serious(rc);
2992 rc = clear_serious(rc);
2996 req->rq_status = rc;
2999 * ELDLM_* codes which > 0 should be in rq_status only as well as
3000 * all non-serious errors.
3002 if (rc > 0 || !serious)
3005 LASSERT(current->journal_info == NULL);
3007 if (rc == 0 && (flags & HABEO_CLAVIS) &&
3008 info->mti_mdt->mdt_opts.mo_compat_resname) {
3009 struct ldlm_reply *dlmrep;
3011 dlmrep = req_capsule_server_get(info->mti_pill, &RMF_DLM_REP);
3013 rc = mdt_lock_reply_compat(info->mti_mdt, dlmrep);
3016 /* If we're DISCONNECTing, the mdt_export_data is already freed */
3017 if (likely(rc == 0 && req->rq_export && h->mh_opc != MDS_DISCONNECT))
3018 target_committed_to_req(req);
3020 if (unlikely(req_is_replay(req) &&
3021 lustre_msg_get_transno(req->rq_reqmsg) == 0)) {
3022 DEBUG_REQ(D_ERROR, req, "transno is 0 during REPLAY");
3026 target_send_reply(req, rc, info->mti_fail_id);
3030 void mdt_lock_handle_init(struct mdt_lock_handle *lh)
3032 lh->mlh_type = MDT_NUL_LOCK;
3033 lh->mlh_reg_lh.cookie = 0ull;
3034 lh->mlh_reg_mode = LCK_MINMODE;
3035 lh->mlh_pdo_lh.cookie = 0ull;
3036 lh->mlh_pdo_mode = LCK_MINMODE;
3037 lh->mlh_rreg_lh.cookie = 0ull;
3038 lh->mlh_rreg_mode = LCK_MINMODE;
3041 void mdt_lock_handle_fini(struct mdt_lock_handle *lh)
3043 LASSERT(!lustre_handle_is_used(&lh->mlh_reg_lh));
3044 LASSERT(!lustre_handle_is_used(&lh->mlh_pdo_lh));
3048 * Initialize fields of struct mdt_thread_info. Other fields are left in
3049 * uninitialized state, because it's too expensive to zero out whole
3050 * mdt_thread_info (> 1K) on each request arrival.
3052 static void mdt_thread_info_init(struct ptlrpc_request *req,
3053 struct mdt_thread_info *info)
3057 req_capsule_init(&req->rq_pill, req, RCL_SERVER);
3058 info->mti_pill = &req->rq_pill;
3061 for (i = 0; i < ARRAY_SIZE(info->mti_lh); i++)
3062 mdt_lock_handle_init(&info->mti_lh[i]);
3064 /* mdt device: it can be NULL while CONNECT */
3065 if (req->rq_export) {
3066 info->mti_mdt = mdt_dev(req->rq_export->exp_obd->obd_lu_dev);
3067 info->mti_exp = req->rq_export;
3069 info->mti_mdt = NULL;
3070 info->mti_env = req->rq_svc_thread->t_env;
3071 info->mti_fail_id = OBD_FAIL_MDS_ALL_REPLY_NET;
3072 info->mti_transno = lustre_msg_get_transno(req->rq_reqmsg);
3073 info->mti_mos = NULL;
3075 memset(&info->mti_attr, 0, sizeof(info->mti_attr));
3076 info->mti_big_buf = LU_BUF_NULL;
3077 info->mti_body = NULL;
3078 info->mti_object = NULL;
3079 info->mti_dlm_req = NULL;
3080 info->mti_has_trans = 0;
3081 info->mti_cross_ref = 0;
3082 info->mti_opdata = 0;
3083 info->mti_big_lmm_used = 0;
3085 /* To not check for split by default. */
3086 info->mti_spec.no_create = 0;
3087 info->mti_spec.sp_rm_entry = 0;
3090 static void mdt_thread_info_fini(struct mdt_thread_info *info)
3094 req_capsule_fini(info->mti_pill);
3095 if (info->mti_object != NULL) {
3096 mdt_object_put(info->mti_env, info->mti_object);
3097 info->mti_object = NULL;
3100 for (i = 0; i < ARRAY_SIZE(info->mti_lh); i++)
3101 mdt_lock_handle_fini(&info->mti_lh[i]);
3102 info->mti_env = NULL;
3104 if (unlikely(info->mti_big_buf.lb_buf != NULL))
3105 lu_buf_free(&info->mti_big_buf);
3108 static int mdt_filter_recovery_request(struct ptlrpc_request *req,
3109 struct obd_device *obd, int *process)
3111 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
3112 case MDS_CONNECT: /* This will never get here, but for completeness. */
3113 case OST_CONNECT: /* This will never get here, but for completeness. */
3114 case MDS_DISCONNECT:
3115 case OST_DISCONNECT:
3121 case MDS_DONE_WRITING:
3122 case MDS_SYNC: /* used in unmounting */
3129 *process = target_queue_recovery_request(req, obd);
3133 DEBUG_REQ(D_ERROR, req, "not permitted during recovery");
3140 * Handle recovery. Return:
3141 * +1: continue request processing;
3142 * -ve: abort immediately with the given error code;
3143 * 0: send reply with error code in req->rq_status;
3145 static int mdt_recovery(struct mdt_thread_info *info)
3147 struct ptlrpc_request *req = mdt_info_req(info);
3148 struct obd_device *obd;
3152 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
3155 case SEC_CTX_INIT_CONT:
3161 rc = mdt_handle_idmap(info);
3170 if (unlikely(!class_connected_export(req->rq_export))) {
3171 CDEBUG(D_HA, "operation %d on unconnected MDS from %s\n",
3172 lustre_msg_get_opc(req->rq_reqmsg),
3173 libcfs_id2str(req->rq_peer));
3174 /* FIXME: For CMD cleanup, when mds_B stop, the req from
3175 * mds_A will get -ENOTCONN(especially for ping req),
3176 * which will cause that mds_A deactive timeout, then when
3177 * mds_A cleanup, the cleanup process will be suspended since
3178 * deactive timeout is not zero.
3180 req->rq_status = -ENOTCONN;
3181 target_send_reply(req, -ENOTCONN, info->mti_fail_id);
3185 /* sanity check: if the xid matches, the request must be marked as a
3186 * resent or replayed */
3187 if (req_xid_is_last(req)) {
3188 if (!(lustre_msg_get_flags(req->rq_reqmsg) &
3189 (MSG_RESENT | MSG_REPLAY))) {
3190 DEBUG_REQ(D_WARNING, req, "rq_xid "LPU64" matches last_xid, "
3191 "expected REPLAY or RESENT flag (%x)", req->rq_xid,
3192 lustre_msg_get_flags(req->rq_reqmsg));
3194 req->rq_status = -ENOTCONN;
3199 /* else: note the opposite is not always true; a RESENT req after a
3200 * failover will usually not match the last_xid, since it was likely
3201 * never committed. A REPLAYed request will almost never match the
3202 * last xid, however it could for a committed, but still retained,
3205 obd = req->rq_export->exp_obd;
3207 /* Check for aborted recovery... */
3208 if (unlikely(obd->obd_recovering)) {
3211 DEBUG_REQ(D_INFO, req, "Got new replay");
3212 rc = mdt_filter_recovery_request(req, obd, &should_process);
3213 if (rc != 0 || !should_process)
3215 else if (should_process < 0) {
3216 req->rq_status = should_process;
3217 rc = ptlrpc_error(req);
3224 static int mdt_msg_check_version(struct lustre_msg *msg)
3228 switch (lustre_msg_get_opc(msg)) {
3230 case MDS_DISCONNECT:
3233 case SEC_CTX_INIT_CONT:
3236 rc = lustre_msg_check_version(msg, LUSTRE_OBD_VERSION);
3238 CERROR("bad opc %u version %08x, expecting %08x\n",
3239 lustre_msg_get_opc(msg),
3240 lustre_msg_get_version(msg),
3241 LUSTRE_OBD_VERSION);
3245 case MDS_GETATTR_NAME:
3252 case MDS_DONE_WRITING:
3259 case MDS_HSM_PROGRESS:
3260 case MDS_HSM_REQUEST:
3261 case MDS_HSM_CT_REGISTER:
3262 case MDS_HSM_CT_UNREGISTER:
3263 case MDS_HSM_STATE_GET:
3264 case MDS_HSM_STATE_SET:
3265 case MDS_HSM_ACTION:
3266 case MDS_QUOTACHECK:
3269 case MDS_SWAP_LAYOUTS:
3274 rc = lustre_msg_check_version(msg, LUSTRE_MDS_VERSION);
3276 CERROR("bad opc %u version %08x, expecting %08x\n",
3277 lustre_msg_get_opc(msg),
3278 lustre_msg_get_version(msg),
3279 LUSTRE_MDS_VERSION);
3283 case LDLM_BL_CALLBACK:
3284 case LDLM_CP_CALLBACK:
3285 rc = lustre_msg_check_version(msg, LUSTRE_DLM_VERSION);
3287 CERROR("bad opc %u version %08x, expecting %08x\n",
3288 lustre_msg_get_opc(msg),
3289 lustre_msg_get_version(msg),
3290 LUSTRE_DLM_VERSION);
3292 case OBD_LOG_CANCEL:
3293 case LLOG_ORIGIN_HANDLE_CREATE:
3294 case LLOG_ORIGIN_HANDLE_NEXT_BLOCK:
3295 case LLOG_ORIGIN_HANDLE_READ_HEADER:
3296 case LLOG_ORIGIN_HANDLE_CLOSE:
3297 case LLOG_ORIGIN_HANDLE_DESTROY:
3298 case LLOG_ORIGIN_HANDLE_PREV_BLOCK:
3300 rc = lustre_msg_check_version(msg, LUSTRE_LOG_VERSION);
3302 CERROR("bad opc %u version %08x, expecting %08x\n",
3303 lustre_msg_get_opc(msg),
3304 lustre_msg_get_version(msg),
3305 LUSTRE_LOG_VERSION);
3308 CERROR("MDS unknown opcode %d\n", lustre_msg_get_opc(msg));
3314 static int mdt_handle0(struct ptlrpc_request *req,
3315 struct mdt_thread_info *info,
3316 struct mdt_opc_slice *supported)
3318 struct mdt_handler *h;
3319 struct lustre_msg *msg;
3324 if (OBD_FAIL_CHECK_ORSET(OBD_FAIL_MDS_ALL_REQUEST_NET, OBD_FAIL_ONCE))
3327 LASSERT(current->journal_info == NULL);
3329 msg = req->rq_reqmsg;
3330 rc = mdt_msg_check_version(msg);
3331 if (likely(rc == 0)) {
3332 rc = mdt_recovery(info);
3333 if (likely(rc == +1)) {
3334 h = mdt_handler_find(lustre_msg_get_opc(msg),
3336 if (likely(h != NULL)) {
3337 rc = mdt_req_handle(info, h, req);
3339 CERROR("The unsupported opc: 0x%x\n",
3340 lustre_msg_get_opc(msg) );
3341 req->rq_status = -ENOTSUPP;
3342 rc = ptlrpc_error(req);
3347 CERROR(LUSTRE_MDT_NAME" drops mal-formed request\n");
3352 * MDT handler function called by ptlrpc service thread when request comes.
3354 * XXX common "target" functionality should be factored into separate module
3355 * shared by mdt, ost and stand-alone services like fld.
3357 int mdt_handle_common(struct ptlrpc_request *req,
3358 struct mdt_opc_slice *supported)
3361 struct mdt_thread_info *info;
3365 env = req->rq_svc_thread->t_env;
3366 /* Refill(initilize) the context(mdt_thread_info), in case it is
3367 * not initialized yet. Usually it happens during start up, after
3368 * MDS(ptlrpc threads) is start up, it gets the first CONNECT request,
3369 * before MDT_thread_info is initialized */
3371 LASSERT(env != NULL);
3372 LASSERT(env->le_ses != NULL);
3373 LASSERT(env->le_ctx.lc_thread == req->rq_svc_thread);
3374 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
3375 LASSERT(info != NULL);
3377 mdt_thread_info_init(req, info);
3379 rc = mdt_handle0(req, info, supported);
3381 mdt_thread_info_fini(info);
3386 * This is called from recovery code as handler of _all_ RPC types, FLD and SEQ
3389 int mdt_recovery_handle(struct ptlrpc_request *req)
3394 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
3396 rc = mdt_handle_common(req, mdt_fld_handlers);
3399 rc = mdt_handle_common(req, mdt_seq_handlers);
3402 rc = mdt_handle_common(req, mdt_regular_handlers);
3424 static int mdt_intent_getattr(enum mdt_it_code opcode,
3425 struct mdt_thread_info *info,
3426 struct ldlm_lock **,
3428 static int mdt_intent_layout(enum mdt_it_code opcode,
3429 struct mdt_thread_info *info,
3430 struct ldlm_lock **,
3432 static int mdt_intent_reint(enum mdt_it_code opcode,
3433 struct mdt_thread_info *info,
3434 struct ldlm_lock **,
3437 static struct mdt_it_flavor {
3438 const struct req_format *it_fmt;
3440 int (*it_act)(enum mdt_it_code ,
3441 struct mdt_thread_info *,
3442 struct ldlm_lock **,
3445 } mdt_it_flavor[] = {
3447 .it_fmt = &RQF_LDLM_INTENT,
3448 /*.it_flags = HABEO_REFERO,*/
3450 .it_act = mdt_intent_reint,
3451 .it_reint = REINT_OPEN
3454 .it_fmt = &RQF_LDLM_INTENT,
3455 .it_flags = MUTABOR,
3456 .it_act = mdt_intent_reint,
3457 .it_reint = REINT_OPEN
3460 .it_fmt = &RQF_LDLM_INTENT,
3461 .it_flags = MUTABOR,
3462 .it_act = mdt_intent_reint,
3463 .it_reint = REINT_CREATE
3465 [MDT_IT_GETATTR] = {
3466 .it_fmt = &RQF_LDLM_INTENT_GETATTR,
3467 .it_flags = HABEO_REFERO,
3468 .it_act = mdt_intent_getattr
3470 [MDT_IT_READDIR] = {
3476 .it_fmt = &RQF_LDLM_INTENT_GETATTR,
3477 .it_flags = HABEO_REFERO,
3478 .it_act = mdt_intent_getattr
3481 .it_fmt = &RQF_LDLM_INTENT_UNLINK,
3482 .it_flags = MUTABOR,
3484 .it_reint = REINT_UNLINK
3488 .it_flags = MUTABOR,
3491 [MDT_IT_GETXATTR] = {
3497 .it_fmt = &RQF_LDLM_INTENT_LAYOUT,
3499 .it_act = mdt_intent_layout
3503 int mdt_intent_lock_replace(struct mdt_thread_info *info,
3504 struct ldlm_lock **lockp,
3505 struct ldlm_lock *new_lock,
3506 struct mdt_lock_handle *lh,
3509 struct ptlrpc_request *req = mdt_info_req(info);
3510 struct ldlm_lock *lock = *lockp;
3513 * Get new lock only for cases when possible resent did not find any
3516 if (new_lock == NULL)
3517 new_lock = ldlm_handle2lock_long(&lh->mlh_reg_lh, 0);
3519 if (new_lock == NULL && (flags & LDLM_FL_INTENT_ONLY)) {
3520 lh->mlh_reg_lh.cookie = 0;
3524 LASSERTF(new_lock != NULL,
3525 "lockh "LPX64"\n", lh->mlh_reg_lh.cookie);
3528 * If we've already given this lock to a client once, then we should
3529 * have no readers or writers. Otherwise, we should have one reader
3530 * _or_ writer ref (which will be zeroed below) before returning the
3533 if (new_lock->l_export == req->rq_export) {
3534 LASSERT(new_lock->l_readers + new_lock->l_writers == 0);
3536 LASSERT(new_lock->l_export == NULL);
3537 LASSERT(new_lock->l_readers + new_lock->l_writers == 1);
3542 if (new_lock->l_export == req->rq_export) {
3544 * Already gave this to the client, which means that we
3545 * reconstructed a reply.
3547 LASSERT(lustre_msg_get_flags(req->rq_reqmsg) &
3549 lh->mlh_reg_lh.cookie = 0;
3550 RETURN(ELDLM_LOCK_REPLACED);
3554 * Fixup the lock to be given to the client.
3556 lock_res_and_lock(new_lock);
3557 /* Zero new_lock->l_readers and new_lock->l_writers without triggering
3558 * possible blocking AST. */
3559 while (new_lock->l_readers > 0) {
3560 lu_ref_del(&new_lock->l_reference, "reader", new_lock);
3561 lu_ref_del(&new_lock->l_reference, "user", new_lock);
3562 new_lock->l_readers--;
3564 while (new_lock->l_writers > 0) {
3565 lu_ref_del(&new_lock->l_reference, "writer", new_lock);
3566 lu_ref_del(&new_lock->l_reference, "user", new_lock);
3567 new_lock->l_writers--;
3570 new_lock->l_export = class_export_lock_get(req->rq_export, new_lock);
3571 new_lock->l_blocking_ast = lock->l_blocking_ast;
3572 new_lock->l_completion_ast = lock->l_completion_ast;
3573 new_lock->l_remote_handle = lock->l_remote_handle;
3574 new_lock->l_flags &= ~LDLM_FL_LOCAL;
3576 unlock_res_and_lock(new_lock);
3578 cfs_hash_add(new_lock->l_export->exp_lock_hash,
3579 &new_lock->l_remote_handle,
3580 &new_lock->l_exp_hash);
3582 LDLM_LOCK_RELEASE(new_lock);
3583 lh->mlh_reg_lh.cookie = 0;
3585 RETURN(ELDLM_LOCK_REPLACED);
3588 static void mdt_intent_fixup_resent(struct mdt_thread_info *info,
3589 struct ldlm_lock *new_lock,
3590 struct ldlm_lock **old_lock,
3591 struct mdt_lock_handle *lh)
3593 struct ptlrpc_request *req = mdt_info_req(info);
3594 struct obd_export *exp = req->rq_export;
3595 struct lustre_handle remote_hdl;
3596 struct ldlm_request *dlmreq;
3597 struct ldlm_lock *lock;
3599 if (!(lustre_msg_get_flags(req->rq_reqmsg) & MSG_RESENT))
3602 dlmreq = req_capsule_client_get(info->mti_pill, &RMF_DLM_REQ);
3603 remote_hdl = dlmreq->lock_handle[0];
3605 /* In the function below, .hs_keycmp resolves to
3606 * ldlm_export_lock_keycmp() */
3607 /* coverity[overrun-buffer-val] */
3608 lock = cfs_hash_lookup(exp->exp_lock_hash, &remote_hdl);
3610 if (lock != new_lock) {
3611 lh->mlh_reg_lh.cookie = lock->l_handle.h_cookie;
3612 lh->mlh_reg_mode = lock->l_granted_mode;
3614 LDLM_DEBUG(lock, "Restoring lock cookie");
3615 DEBUG_REQ(D_DLMTRACE, req,
3616 "restoring lock cookie "LPX64,
3617 lh->mlh_reg_lh.cookie);
3619 *old_lock = LDLM_LOCK_GET(lock);
3620 cfs_hash_put(exp->exp_lock_hash, &lock->l_exp_hash);
3624 cfs_hash_put(exp->exp_lock_hash, &lock->l_exp_hash);
3628 * If the xid matches, then we know this is a resent request, and allow
3629 * it. (It's probably an OPEN, for which we don't send a lock.
3631 if (req_xid_is_last(req))
3635 * This remote handle isn't enqueued, so we never received or processed
3636 * this request. Clear MSG_RESENT, because it can be handled like any
3637 * normal request now.
3639 lustre_msg_clear_flags(req->rq_reqmsg, MSG_RESENT);
3641 DEBUG_REQ(D_DLMTRACE, req, "no existing lock with rhandle "LPX64,
3645 static int mdt_intent_getattr(enum mdt_it_code opcode,
3646 struct mdt_thread_info *info,
3647 struct ldlm_lock **lockp,
3650 struct mdt_lock_handle *lhc = &info->mti_lh[MDT_LH_RMT];
3651 struct ldlm_lock *new_lock = NULL;
3653 struct ldlm_reply *ldlm_rep;
3654 struct ptlrpc_request *req;
3655 struct mdt_body *reqbody;
3656 struct mdt_body *repbody;
3660 reqbody = req_capsule_client_get(info->mti_pill, &RMF_MDT_BODY);
3663 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
3666 info->mti_cross_ref = !!(reqbody->valid & OBD_MD_FLCROSSREF);
3667 repbody->eadatasize = 0;
3668 repbody->aclsize = 0;
3672 child_bits = MDS_INODELOCK_LOOKUP | MDS_INODELOCK_PERM;
3674 case MDT_IT_GETATTR:
3675 child_bits = MDS_INODELOCK_LOOKUP | MDS_INODELOCK_UPDATE |
3679 CERROR("Unsupported intent (%d)\n", opcode);
3680 GOTO(out_shrink, rc = -EINVAL);
3683 rc = mdt_init_ucred(info, reqbody);
3685 GOTO(out_shrink, rc);
3687 req = info->mti_pill->rc_req;
3688 ldlm_rep = req_capsule_server_get(info->mti_pill, &RMF_DLM_REP);
3689 mdt_set_disposition(info, ldlm_rep, DISP_IT_EXECD);
3691 /* Get lock from request for possible resent case. */
3692 mdt_intent_fixup_resent(info, *lockp, &new_lock, lhc);
3694 ldlm_rep->lock_policy_res2 =
3695 mdt_getattr_name_lock(info, lhc, child_bits, ldlm_rep);
3697 if (mdt_get_disposition(ldlm_rep, DISP_LOOKUP_NEG))
3698 ldlm_rep->lock_policy_res2 = 0;
3699 if (!mdt_get_disposition(ldlm_rep, DISP_LOOKUP_POS) ||
3700 ldlm_rep->lock_policy_res2) {
3701 lhc->mlh_reg_lh.cookie = 0ull;
3702 GOTO(out_ucred, rc = ELDLM_LOCK_ABORTED);
3705 rc = mdt_intent_lock_replace(info, lockp, new_lock, lhc, flags);
3708 mdt_exit_ucred(info);
3710 mdt_client_compatibility(info);
3711 rc2 = mdt_fix_reply(info);
3717 static int mdt_intent_layout(enum mdt_it_code opcode,
3718 struct mdt_thread_info *info,
3719 struct ldlm_lock **lockp,
3722 struct layout_intent *layout;
3726 if (opcode != MDT_IT_LAYOUT) {
3727 CERROR("%s: Unknown intent (%d)\n",
3728 info->mti_exp->exp_obd->obd_name, opcode);
3732 (*lockp)->l_lvb_type = LVB_T_LAYOUT;
3733 req_capsule_set_size(info->mti_pill, &RMF_DLM_LVB, RCL_SERVER,
3734 ldlm_lvbo_size(*lockp));
3735 rc = req_capsule_server_pack(info->mti_pill);
3739 layout = req_capsule_client_get(info->mti_pill, &RMF_LAYOUT_INTENT);
3740 LASSERT(layout != NULL);
3741 if (layout->li_opc == LAYOUT_INTENT_ACCESS)
3742 /* return to normal ldlm handling */
3745 CERROR("%s: Unsupported layout intent (%d)\n",
3746 info->mti_exp->exp_obd->obd_name, layout->li_opc);
3750 static int mdt_intent_reint(enum mdt_it_code opcode,
3751 struct mdt_thread_info *info,
3752 struct ldlm_lock **lockp,
3755 struct mdt_lock_handle *lhc = &info->mti_lh[MDT_LH_RMT];
3756 struct ldlm_reply *rep = NULL;
3760 static const struct req_format *intent_fmts[REINT_MAX] = {
3761 [REINT_CREATE] = &RQF_LDLM_INTENT_CREATE,
3762 [REINT_OPEN] = &RQF_LDLM_INTENT_OPEN
3767 opc = mdt_reint_opcode(info, intent_fmts);
3771 if (mdt_it_flavor[opcode].it_reint != opc) {
3772 CERROR("Reint code %ld doesn't match intent: %d\n",
3774 RETURN(err_serious(-EPROTO));
3777 /* Get lock from request for possible resent case. */
3778 mdt_intent_fixup_resent(info, *lockp, NULL, lhc);
3780 rc = mdt_reint_internal(info, lhc, opc);
3782 /* Check whether the reply has been packed successfully. */
3783 if (mdt_info_req(info)->rq_repmsg != NULL)
3784 rep = req_capsule_server_get(info->mti_pill, &RMF_DLM_REP);
3786 RETURN(err_serious(-EFAULT));
3788 /* MDC expects this in any case */
3790 mdt_set_disposition(info, rep, DISP_LOOKUP_EXECD);
3792 /* the open lock or the lock for cross-ref object should be
3793 * returned to the client */
3794 if (rc == -EREMOTE || mdt_get_disposition(rep, DISP_OPEN_LOCK)) {
3795 LASSERT(lustre_handle_is_used(&lhc->mlh_reg_lh));
3796 rep->lock_policy_res2 = 0;
3797 rc = mdt_intent_lock_replace(info, lockp, NULL, lhc, flags);
3801 rep->lock_policy_res2 = clear_serious(rc);
3803 if (rep->lock_policy_res2 == -ENOENT &&
3804 mdt_get_disposition(rep, DISP_LOOKUP_NEG))
3805 rep->lock_policy_res2 = 0;
3807 if (rc == -ENOTCONN || rc == -ENODEV ||
3808 rc == -EOVERFLOW) { /**< if VBR failure then return error */
3810 * If it is the disconnect error (ENODEV & ENOCONN), the error
3811 * will be returned by rq_status, and client at ptlrpc layer
3812 * will detect this, then disconnect, reconnect the import
3813 * immediately, instead of impacting the following the rpc.
3815 lhc->mlh_reg_lh.cookie = 0ull;
3819 * For other cases, the error will be returned by intent.
3820 * and client will retrieve the result from intent.
3823 * FIXME: when open lock is finished, that should be
3826 if (lustre_handle_is_used(&lhc->mlh_reg_lh)) {
3827 LASSERTF(rc == 0, "Error occurred but lock handle "
3828 "is still in use, rc = %d\n", rc);
3829 rep->lock_policy_res2 = 0;
3830 rc = mdt_intent_lock_replace(info, lockp, NULL, lhc, flags);
3833 lhc->mlh_reg_lh.cookie = 0ull;
3834 RETURN(ELDLM_LOCK_ABORTED);
3839 static int mdt_intent_code(long itcode)
3847 case IT_OPEN|IT_CREAT:
3854 rc = MDT_IT_READDIR;
3857 rc = MDT_IT_GETATTR;
3869 rc = MDT_IT_GETXATTR;
3874 case IT_QUOTA_DQACQ:
3879 CERROR("Unknown intent opcode: %ld\n", itcode);
3886 static int mdt_intent_opc(long itopc, struct mdt_thread_info *info,
3887 struct ldlm_lock **lockp, __u64 flags)
3889 struct req_capsule *pill;
3890 struct mdt_it_flavor *flv;
3895 opc = mdt_intent_code(itopc);
3899 pill = info->mti_pill;
3901 if (opc == MDT_IT_QUOTA) {
3902 struct lu_device *qmt = info->mti_mdt->mdt_qmt_dev;
3905 RETURN(-EOPNOTSUPP);
3907 (*lockp)->l_lvb_type = LVB_T_LQUOTA;
3908 /* pass the request to quota master */
3909 rc = qmt_hdls.qmth_intent_policy(info->mti_env, qmt,
3910 mdt_info_req(info), lockp,
3915 flv = &mdt_it_flavor[opc];
3916 if (flv->it_fmt != NULL)
3917 req_capsule_extend(pill, flv->it_fmt);
3919 rc = mdt_unpack_req_pack_rep(info, flv->it_flags);
3921 struct ptlrpc_request *req = mdt_info_req(info);
3922 if (flv->it_flags & MUTABOR &&
3923 exp_connect_flags(req->rq_export) & OBD_CONNECT_RDONLY)
3926 if (rc == 0 && flv->it_act != NULL) {
3927 /* execute policy */
3928 rc = flv->it_act(opc, info, lockp, flags);
3935 static int mdt_intent_policy(struct ldlm_namespace *ns,
3936 struct ldlm_lock **lockp, void *req_cookie,
3937 ldlm_mode_t mode, __u64 flags, void *data)
3939 struct mdt_thread_info *info;
3940 struct ptlrpc_request *req = req_cookie;
3941 struct ldlm_intent *it;
3942 struct req_capsule *pill;
3947 LASSERT(req != NULL);
3949 info = lu_context_key_get(&req->rq_svc_thread->t_env->le_ctx,
3951 LASSERT(info != NULL);
3952 pill = info->mti_pill;
3953 LASSERT(pill->rc_req == req);
3955 if (req->rq_reqmsg->lm_bufcount > DLM_INTENT_IT_OFF) {
3956 req_capsule_extend(pill, &RQF_LDLM_INTENT_BASIC);
3957 it = req_capsule_client_get(pill, &RMF_LDLM_INTENT);
3959 rc = mdt_intent_opc(it->opc, info, lockp, flags);
3963 /* Lock without inodebits makes no sense and will oops
3964 * later in ldlm. Let's check it now to see if we have
3965 * ibits corrupted somewhere in mdt_intent_opc().
3966 * The case for client miss to set ibits has been
3967 * processed by others. */
3968 LASSERT(ergo(info->mti_dlm_req->lock_desc.l_resource.\
3969 lr_type == LDLM_IBITS,
3970 info->mti_dlm_req->lock_desc.\
3971 l_policy_data.l_inodebits.bits != 0));
3973 rc = err_serious(-EFAULT);
3975 /* No intent was provided */
3976 LASSERT(pill->rc_fmt == &RQF_LDLM_ENQUEUE);
3977 req_capsule_set_size(pill, &RMF_DLM_LVB, RCL_SERVER, 0);
3978 rc = req_capsule_server_pack(pill);
3980 rc = err_serious(rc);
3985 static int mdt_seq_fini(const struct lu_env *env,
3986 struct mdt_device *m)
3988 return seq_site_fini(env, mdt_seq_site(m));
3991 static int mdt_seq_init(const struct lu_env *env,
3993 struct mdt_device *m)
3995 struct seq_server_site *ss;
4000 ss = mdt_seq_site(m);
4003 * This is sequence-controller node. Init seq-controller server on local
4006 if (ss->ss_node_id == 0) {
4007 LASSERT(ss->ss_control_seq == NULL);
4009 OBD_ALLOC_PTR(ss->ss_control_seq);
4010 if (ss->ss_control_seq == NULL)
4013 rc = seq_server_init(ss->ss_control_seq,
4014 m->mdt_bottom, uuid,
4015 LUSTRE_SEQ_CONTROLLER,
4020 GOTO(out_seq_fini, rc);
4022 OBD_ALLOC_PTR(ss->ss_client_seq);
4023 if (ss->ss_client_seq == NULL)
4024 GOTO(out_seq_fini, rc = -ENOMEM);
4026 OBD_ALLOC(prefix, MAX_OBD_NAME + 5);
4027 if (prefix == NULL) {
4028 OBD_FREE_PTR(ss->ss_client_seq);
4029 GOTO(out_seq_fini, rc = -ENOMEM);
4032 snprintf(prefix, MAX_OBD_NAME + 5, "ctl-%s",
4036 * Init seq-controller client after seq-controller server is
4037 * ready. Pass ss->ss_control_seq to it for direct talking.
4039 rc = seq_client_init(ss->ss_client_seq, NULL,
4040 LUSTRE_SEQ_METADATA, prefix,
4041 ss->ss_control_seq);
4042 OBD_FREE(prefix, MAX_OBD_NAME + 5);
4045 GOTO(out_seq_fini, rc);
4048 /* Init seq-server on local MDT */
4049 LASSERT(ss->ss_server_seq == NULL);
4051 OBD_ALLOC_PTR(ss->ss_server_seq);
4052 if (ss->ss_server_seq == NULL)
4053 GOTO(out_seq_fini, rc = -ENOMEM);
4055 rc = seq_server_init(ss->ss_server_seq,
4056 m->mdt_bottom, uuid,
4061 GOTO(out_seq_fini, rc = -ENOMEM);
4063 /* Assign seq-controller client to local seq-server. */
4064 if (ss->ss_node_id == 0) {
4065 LASSERT(ss->ss_client_seq != NULL);
4067 rc = seq_server_set_cli(ss->ss_server_seq,
4075 mdt_seq_fini(env, m);
4083 static int mdt_fld_fini(const struct lu_env *env,
4084 struct mdt_device *m)
4086 struct seq_server_site *ss = mdt_seq_site(m);
4089 if (ss && ss->ss_server_fld) {
4090 fld_server_fini(env, ss->ss_server_fld);
4091 OBD_FREE_PTR(ss->ss_server_fld);
4092 ss->ss_server_fld = NULL;
4098 static int mdt_fld_init(const struct lu_env *env,
4100 struct mdt_device *m)
4102 struct seq_server_site *ss;
4106 ss = mdt_seq_site(m);
4108 OBD_ALLOC_PTR(ss->ss_server_fld);
4109 if (ss->ss_server_fld == NULL)
4110 RETURN(rc = -ENOMEM);
4112 rc = fld_server_init(env, ss->ss_server_fld, m->mdt_bottom, uuid,
4113 ss->ss_node_id, LU_SEQ_RANGE_MDT);
4115 OBD_FREE_PTR(ss->ss_server_fld);
4116 ss->ss_server_fld = NULL;
4123 static void mdt_stack_pre_fini(const struct lu_env *env,
4124 struct mdt_device *m, struct lu_device *top)
4126 struct obd_device *obd = mdt2obd_dev(m);
4127 struct lustre_cfg_bufs *bufs;
4128 struct lustre_cfg *lcfg;
4129 struct mdt_thread_info *info;
4134 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
4135 LASSERT(info != NULL);
4137 bufs = &info->mti_u.bufs;
4139 LASSERT(m->mdt_child_exp);
4140 LASSERT(m->mdt_child_exp->exp_obd);
4141 obd = m->mdt_child_exp->exp_obd;
4143 /* process cleanup, pass mdt obd name to get obd umount flags */
4144 /* XXX: this is needed because all layers are referenced by
4145 * objects (some of them are pinned by osd, for example *
4146 * the proper solution should be a model where object used
4147 * by osd only doesn't have mdt/mdd slices -bzzz */
4148 lustre_cfg_bufs_reset(bufs, obd->obd_name);
4149 lustre_cfg_bufs_set_string(bufs, 1, NULL);
4150 lcfg = lustre_cfg_new(LCFG_PRE_CLEANUP, bufs);
4152 CERROR("%s:Cannot alloc lcfg!\n", mdt_obd_name(m));
4155 top->ld_ops->ldo_process_config(env, top, lcfg);
4156 lustre_cfg_free(lcfg);
4160 static void mdt_stack_fini(const struct lu_env *env,
4161 struct mdt_device *m, struct lu_device *top)
4163 struct obd_device *obd = mdt2obd_dev(m);
4164 struct lustre_cfg_bufs *bufs;
4165 struct lustre_cfg *lcfg;
4166 struct mdt_thread_info *info;
4170 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
4171 LASSERT(info != NULL);
4173 lu_dev_del_linkage(top->ld_site, top);
4175 lu_site_purge(env, top->ld_site, -1);
4177 bufs = &info->mti_u.bufs;
4178 /* process cleanup, pass mdt obd name to get obd umount flags */
4179 /* another purpose is to let all layers to release their objects */
4180 lustre_cfg_bufs_reset(bufs, obd->obd_name);
4185 lustre_cfg_bufs_set_string(bufs, 1, flags);
4186 lcfg = lustre_cfg_new(LCFG_CLEANUP, bufs);
4188 CERROR("Cannot alloc lcfg!\n");
4192 top->ld_ops->ldo_process_config(env, top, lcfg);
4193 lustre_cfg_free(lcfg);
4195 lu_site_purge(env, top->ld_site, -1);
4197 m->mdt_child = NULL;
4198 m->mdt_bottom = NULL;
4200 obd_disconnect(m->mdt_child_exp);
4201 m->mdt_child_exp = NULL;
4203 obd_disconnect(m->mdt_bottom_exp);
4204 m->mdt_child_exp = NULL;
4207 static int mdt_connect_to_next(const struct lu_env *env, struct mdt_device *m,
4208 const char *next, struct obd_export **exp)
4210 struct obd_connect_data *data = NULL;
4211 struct obd_device *obd;
4215 OBD_ALLOC_PTR(data);
4217 GOTO(out, rc = -ENOMEM);
4219 obd = class_name2obd(next);
4221 CERROR("%s: can't locate next device: %s\n",
4222 m->mdt_md_dev.md_lu_dev.ld_obd->obd_name, next);
4223 GOTO(out, rc = -ENOTCONN);
4226 data->ocd_connect_flags = OBD_CONNECT_VERSION;
4227 data->ocd_version = LUSTRE_VERSION_CODE;
4229 rc = obd_connect(NULL, exp, obd, &obd->obd_uuid, data, NULL);
4231 CERROR("%s: cannot connect to next dev %s (%d)\n",
4232 m->mdt_md_dev.md_lu_dev.ld_obd->obd_name, next, rc);
4242 static int mdt_stack_init(const struct lu_env *env, struct mdt_device *mdt,
4243 struct lustre_cfg *cfg)
4245 char *dev = lustre_cfg_string(cfg, 0);
4246 int rc, name_size, uuid_size;
4247 char *name, *uuid, *p;
4248 struct lustre_cfg_bufs *bufs;
4249 struct lustre_cfg *lcfg;
4250 struct obd_device *obd;
4251 struct lustre_profile *lprof;
4252 struct lu_site *site;
4255 /* in 1.8 we had the only device in the stack - MDS.
4256 * 2.0 introduces MDT, MDD, OSD; MDT starts others internally.
4257 * in 2.3 OSD is instantiated by obd_mount.c, so we need
4258 * to generate names and setup MDT, MDD. MDT will be using
4259 * generated name to connect to MDD. for MDD the next device
4260 * will be LOD with name taken from so called "profile" which
4261 * is generated by mount_option line
4263 * 1.8 MGS generates config. commands like this:
4264 * #06 (104)mount_option 0: 1:lustre-MDT0000 2:lustre-mdtlov
4265 * #08 (120)setup 0:lustre-MDT0000 1:dev 2:type 3:lustre-MDT0000
4266 * 2.0 MGS generates config. commands like this:
4267 * #07 (112)mount_option 0: 1:lustre-MDT0000 2:lustre-MDT0000-mdtlov
4268 * #08 (160)setup 0:lustre-MDT0000 1:lustre-MDT0000_UUID 2:0
4269 * 3:lustre-MDT0000-mdtlov 4:f
4271 * we generate MDD name from MDT one, just replacing T with D
4273 * after all the preparations, the logical equivalent will be
4274 * #01 (160)setup 0:lustre-MDD0000 1:lustre-MDD0000_UUID 2:0
4275 * 3:lustre-MDT0000-mdtlov 4:f
4276 * #02 (160)setup 0:lustre-MDT0000 1:lustre-MDT0000_UUID 2:0
4277 * 3:lustre-MDD0000 4:f
4279 * notice we build the stack from down to top: MDD first, then MDT */
4281 name_size = MAX_OBD_NAME;
4282 uuid_size = MAX_OBD_NAME;
4284 OBD_ALLOC(name, name_size);
4285 OBD_ALLOC(uuid, uuid_size);
4286 if (name == NULL || uuid == NULL)
4287 GOTO(cleanup_mem, rc = -ENOMEM);
4289 OBD_ALLOC_PTR(bufs);
4291 GOTO(cleanup_mem, rc = -ENOMEM);
4294 p = strstr(name, "-MDT");
4296 GOTO(cleanup_mem, rc = -ENOMEM);
4299 snprintf(uuid, MAX_OBD_NAME, "%s_UUID", name);
4301 lprof = class_get_profile(lustre_cfg_string(cfg, 0));
4302 if (lprof == NULL || lprof->lp_dt == NULL) {
4303 CERROR("can't find the profile: %s\n",
4304 lustre_cfg_string(cfg, 0));
4305 GOTO(cleanup_mem, rc = -EINVAL);
4308 lustre_cfg_bufs_reset(bufs, name);
4309 lustre_cfg_bufs_set_string(bufs, 1, LUSTRE_MDD_NAME);
4310 lustre_cfg_bufs_set_string(bufs, 2, uuid);
4311 lustre_cfg_bufs_set_string(bufs, 3, lprof->lp_dt);
4313 lcfg = lustre_cfg_new(LCFG_ATTACH, bufs);
4315 GOTO(free_bufs, rc = -ENOMEM);
4317 rc = class_attach(lcfg);
4319 GOTO(lcfg_cleanup, rc);
4321 obd = class_name2obd(name);
4323 CERROR("Can not find obd %s (%s in config)\n",
4324 MDD_OBD_NAME, lustre_cfg_string(cfg, 0));
4325 GOTO(class_detach, rc = -EINVAL);
4328 lustre_cfg_free(lcfg);
4330 lustre_cfg_bufs_reset(bufs, name);
4331 lustre_cfg_bufs_set_string(bufs, 1, uuid);
4332 lustre_cfg_bufs_set_string(bufs, 2, dev);
4333 lustre_cfg_bufs_set_string(bufs, 3, lprof->lp_dt);
4335 lcfg = lustre_cfg_new(LCFG_SETUP, bufs);
4337 rc = class_setup(obd, lcfg);
4339 GOTO(class_detach, rc);
4341 /* connect to MDD we just setup */
4342 rc = mdt_connect_to_next(env, mdt, name, &mdt->mdt_child_exp);
4346 site = mdt->mdt_child_exp->exp_obd->obd_lu_dev->ld_site;
4348 LASSERT(mdt->mdt_md_dev.md_lu_dev.ld_site == NULL);
4349 mdt->mdt_md_dev.md_lu_dev.ld_site = site;
4350 site->ls_top_dev = &mdt->mdt_md_dev.md_lu_dev;
4351 mdt->mdt_child = lu2md_dev(mdt->mdt_child_exp->exp_obd->obd_lu_dev);
4354 /* now connect to bottom OSD */
4355 snprintf(name, MAX_OBD_NAME, "%s-osd", dev);
4356 rc = mdt_connect_to_next(env, mdt, name, &mdt->mdt_bottom_exp);
4360 lu2dt_dev(mdt->mdt_bottom_exp->exp_obd->obd_lu_dev);
4363 rc = lu_env_refill((struct lu_env *)env);
4365 CERROR("Failure to refill session: '%d'\n", rc);
4367 lu_dev_add_linkage(site, &mdt->mdt_md_dev.md_lu_dev);
4372 class_detach(obd, lcfg);
4374 lustre_cfg_free(lcfg);
4379 OBD_FREE(name, name_size);
4381 OBD_FREE(uuid, uuid_size);
4385 /* setup quota master target on MDT0 */
4386 static int mdt_quota_init(const struct lu_env *env, struct mdt_device *mdt,
4387 struct lustre_cfg *cfg)
4389 struct obd_device *obd;
4390 char *dev = lustre_cfg_string(cfg, 0);
4391 char *qmtname, *uuid, *p;
4392 struct lustre_cfg_bufs *bufs;
4393 struct lustre_cfg *lcfg;
4394 struct lustre_profile *lprof;
4395 struct obd_connect_data *data;
4399 LASSERT(mdt->mdt_qmt_exp == NULL);
4400 LASSERT(mdt->mdt_qmt_dev == NULL);
4402 /* quota master is on MDT0 only for now */
4403 if (mdt->mdt_seq_site.ss_node_id != 0)
4406 /* MGS generates config commands which look as follows:
4407 * #01 (160)setup 0:lustre-MDT0000 1:lustre-MDT0000_UUID 2:0
4408 * 3:lustre-MDT0000-mdtlov 4:f
4410 * We generate the QMT name from the MDT one, just replacing MD with QM
4411 * after all the preparations, the logical equivalent will be:
4412 * #01 (160)setup 0:lustre-QMT0000 1:lustre-QMT0000_UUID 2:0
4413 * 3:lustre-MDT0000-osd 4:f */
4414 OBD_ALLOC(qmtname, MAX_OBD_NAME);
4415 OBD_ALLOC(uuid, UUID_MAX);
4416 OBD_ALLOC_PTR(bufs);
4417 OBD_ALLOC_PTR(data);
4418 if (qmtname == NULL || uuid == NULL || bufs == NULL || data == NULL)
4419 GOTO(cleanup_mem, rc = -ENOMEM);
4421 strcpy(qmtname, dev);
4422 p = strstr(qmtname, "-MDT");
4424 GOTO(cleanup_mem, rc = -ENOMEM);
4425 /* replace MD with QM */
4429 snprintf(uuid, UUID_MAX, "%s_UUID", qmtname);
4431 lprof = class_get_profile(lustre_cfg_string(cfg, 0));
4432 if (lprof == NULL || lprof->lp_dt == NULL) {
4433 CERROR("can't find profile for %s\n",
4434 lustre_cfg_string(cfg, 0));
4435 GOTO(cleanup_mem, rc = -EINVAL);
4438 lustre_cfg_bufs_reset(bufs, qmtname);
4439 lustre_cfg_bufs_set_string(bufs, 1, LUSTRE_QMT_NAME);
4440 lustre_cfg_bufs_set_string(bufs, 2, uuid);
4441 lustre_cfg_bufs_set_string(bufs, 3, lprof->lp_dt);
4443 lcfg = lustre_cfg_new(LCFG_ATTACH, bufs);
4445 GOTO(cleanup_mem, rc = -ENOMEM);
4447 rc = class_attach(lcfg);
4449 GOTO(lcfg_cleanup, rc);
4451 obd = class_name2obd(qmtname);
4453 CERROR("Can not find obd %s (%s in config)\n", qmtname,
4454 lustre_cfg_string(cfg, 0));
4455 GOTO(class_detach, rc = -EINVAL);
4458 lustre_cfg_free(lcfg);
4460 lustre_cfg_bufs_reset(bufs, qmtname);
4461 lustre_cfg_bufs_set_string(bufs, 1, uuid);
4462 lustre_cfg_bufs_set_string(bufs, 2, dev);
4464 /* for quota, the next device should be the OSD device */
4465 lustre_cfg_bufs_set_string(bufs, 3,
4466 mdt->mdt_bottom->dd_lu_dev.ld_obd->obd_name);
4468 lcfg = lustre_cfg_new(LCFG_SETUP, bufs);
4470 rc = class_setup(obd, lcfg);
4472 GOTO(class_detach, rc);
4474 mdt->mdt_qmt_dev = obd->obd_lu_dev;
4476 /* configure local quota objects */
4477 rc = mdt->mdt_qmt_dev->ld_ops->ldo_prepare(env,
4478 &mdt->mdt_md_dev.md_lu_dev,
4481 GOTO(class_cleanup, rc);
4483 /* connect to quota master target */
4484 data->ocd_connect_flags = OBD_CONNECT_VERSION;
4485 data->ocd_version = LUSTRE_VERSION_CODE;
4486 rc = obd_connect(NULL, &mdt->mdt_qmt_exp, obd, &obd->obd_uuid,
4489 CERROR("cannot connect to quota master device %s (%d)\n",
4491 GOTO(class_cleanup, rc);
4497 class_manual_cleanup(obd);
4498 mdt->mdt_qmt_dev = NULL;
4502 class_detach(obd, lcfg);
4504 lustre_cfg_free(lcfg);
4509 OBD_FREE(qmtname, MAX_OBD_NAME);
4511 OBD_FREE(uuid, UUID_MAX);
4517 /* Shutdown quota master target associated with mdt */
4518 static void mdt_quota_fini(const struct lu_env *env, struct mdt_device *mdt)
4522 if (mdt->mdt_qmt_exp == NULL)
4524 LASSERT(mdt->mdt_qmt_dev != NULL);
4526 /* the qmt automatically shuts down when the mdt disconnects */
4527 obd_disconnect(mdt->mdt_qmt_exp);
4528 mdt->mdt_qmt_exp = NULL;
4529 mdt->mdt_qmt_dev = NULL;
4533 static void mdt_fini(const struct lu_env *env, struct mdt_device *m)
4535 struct md_device *next = m->mdt_child;
4536 struct lu_device *d = &m->mdt_md_dev.md_lu_dev;
4537 struct obd_device *obd = mdt2obd_dev(m);
4540 target_recovery_fini(obd);
4542 ping_evictor_stop();
4545 mdt_stack_pre_fini(env, m, md2lu_dev(m->mdt_child));
4546 mdt_llog_ctxt_unclone(env, m, LLOG_CHANGELOG_ORIG_CTXT);
4547 obd_exports_barrier(obd);
4548 obd_zombie_barrier();
4552 tgt_fini(env, &m->mdt_lut);
4553 mdt_fs_cleanup(env, m);
4554 upcall_cache_cleanup(m->mdt_identity_cache);
4555 m->mdt_identity_cache = NULL;
4557 if (m->mdt_namespace != NULL) {
4558 ldlm_namespace_free(m->mdt_namespace, NULL,
4559 d->ld_obd->obd_force);
4560 d->ld_obd->obd_namespace = m->mdt_namespace = NULL;
4563 mdt_quota_fini(env, m);
4565 cfs_free_nidlist(&m->mdt_nosquash_nids);
4566 if (m->mdt_nosquash_str) {
4567 OBD_FREE(m->mdt_nosquash_str, m->mdt_nosquash_strlen);
4568 m->mdt_nosquash_str = NULL;
4569 m->mdt_nosquash_strlen = 0;
4572 next->md_ops->mdo_iocontrol(env, next, OBD_IOC_PAUSE_LFSCK,
4574 mdt_seq_fini(env, m);
4575 mdt_fld_fini(env, m);
4576 sptlrpc_rule_set_free(&m->mdt_sptlrpc_rset);
4578 next->md_ops->mdo_init_capa_ctxt(env, next, 0, 0, 0, NULL);
4579 cfs_timer_disarm(&m->mdt_ck_timer);
4580 mdt_ck_thread_stop(m);
4585 mdt_stack_fini(env, m, md2lu_dev(m->mdt_child));
4587 LASSERT(cfs_atomic_read(&d->ld_ref) == 0);
4589 server_put_mount(mdt2obd_dev(m)->obd_name, NULL);
4594 static int mdt_adapt_sptlrpc_conf(struct obd_device *obd, int initial)
4596 struct mdt_device *m = mdt_dev(obd->obd_lu_dev);
4597 struct sptlrpc_rule_set tmp_rset;
4600 sptlrpc_rule_set_init(&tmp_rset);
4601 rc = sptlrpc_conf_target_get_rules(obd, &tmp_rset, initial);
4603 CERROR("mdt %s: failed get sptlrpc rules: %d\n",
4608 sptlrpc_target_update_exp_flavor(obd, &tmp_rset);
4610 write_lock(&m->mdt_sptlrpc_lock);
4611 sptlrpc_rule_set_free(&m->mdt_sptlrpc_rset);
4612 m->mdt_sptlrpc_rset = tmp_rset;
4613 write_unlock(&m->mdt_sptlrpc_lock);
4618 int mdt_postrecov(const struct lu_env *, struct mdt_device *);
4620 static int mdt_init0(const struct lu_env *env, struct mdt_device *m,
4621 struct lu_device_type *ldt, struct lustre_cfg *cfg)
4623 struct mdt_thread_info *info;
4624 struct obd_device *obd;
4625 const char *dev = lustre_cfg_string(cfg, 0);
4626 const char *num = lustre_cfg_string(cfg, 2);
4627 struct lustre_mount_info *lmi = NULL;
4628 struct lustre_sb_info *lsi;
4630 struct seq_server_site *ss_site;
4631 const char *identity_upcall = "NONE";
4632 struct md_device *next;
4638 md_device_init(&m->mdt_md_dev, ldt);
4640 * Environment (env) might be missing mdt_thread_key values at that
4641 * point, if device is allocated when mdt_thread_key is in QUIESCENT
4644 * Usually device allocation path doesn't use module key values, but
4645 * mdt has to do a lot of work here, so allocate key value.
4647 rc = lu_env_refill((struct lu_env *)env);
4651 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
4652 LASSERT(info != NULL);
4654 obd = class_name2obd(dev);
4655 LASSERT(obd != NULL);
4657 m->mdt_max_mdsize = MAX_MD_SIZE; /* 4 stripes */
4659 m->mdt_som_conf = 0;
4661 m->mdt_opts.mo_cos = MDT_COS_DEFAULT;
4662 lmi = server_get_mount(dev);
4664 CERROR("Cannot get mount info for %s!\n", dev);
4667 lsi = s2lsi(lmi->lmi_sb);
4668 /* CMD is supported only in IAM mode */
4670 node_id = simple_strtol(num, NULL, 10);
4671 obd->u.obt.obt_magic = OBT_MAGIC;
4674 rwlock_init(&m->mdt_sptlrpc_lock);
4675 sptlrpc_rule_set_init(&m->mdt_sptlrpc_rset);
4677 spin_lock_init(&m->mdt_ioepoch_lock);
4678 m->mdt_opts.mo_compat_resname = 0;
4679 m->mdt_opts.mo_mds_capa = 1;
4680 m->mdt_opts.mo_oss_capa = 1;
4681 m->mdt_capa_timeout = CAPA_TIMEOUT;
4682 m->mdt_capa_alg = CAPA_HMAC_ALG_SHA1;
4683 m->mdt_ck_timeout = CAPA_KEY_TIMEOUT;
4684 m->mdt_squash_uid = 0;
4685 m->mdt_squash_gid = 0;
4686 CFS_INIT_LIST_HEAD(&m->mdt_nosquash_nids);
4687 m->mdt_nosquash_str = NULL;
4688 m->mdt_nosquash_strlen = 0;
4689 init_rwsem(&m->mdt_squash_sem);
4690 spin_lock_init(&m->mdt_osfs_lock);
4691 m->mdt_osfs_age = cfs_time_shift_64(-1000);
4692 m->mdt_enable_remote_dir = 0;
4693 m->mdt_enable_remote_dir_gid = 0;
4695 m->mdt_md_dev.md_lu_dev.ld_ops = &mdt_lu_ops;
4696 m->mdt_md_dev.md_lu_dev.ld_obd = obd;
4697 /* set this lu_device to obd, because error handling need it */
4698 obd->obd_lu_dev = &m->mdt_md_dev.md_lu_dev;
4700 /* init the stack */
4701 rc = mdt_stack_init((struct lu_env *)env, m, cfg);
4703 CERROR("Can't init device stack, rc %d\n", rc);
4707 s = m->mdt_md_dev.md_lu_dev.ld_site;
4708 ss_site = &m->mdt_seq_site;
4709 s->ld_seq_site = ss_site;
4712 /* set server index */
4713 ss_site->ss_node_id = node_id;
4715 /* failover is the default
4716 * FIXME: we do not failout mds0/mgs, which may cause some problems.
4717 * assumed whose ss_node_id == 0 XXX
4719 obd->obd_replayable = 1;
4720 /* No connection accepted until configurations will finish */
4721 obd->obd_no_conn = 1;
4723 if (cfg->lcfg_bufcount > 4 && LUSTRE_CFG_BUFLEN(cfg, 4) > 0) {
4724 char *str = lustre_cfg_string(cfg, 4);
4725 if (strchr(str, 'n')) {
4726 CWARN("%s: recovery disabled\n", obd->obd_name);
4727 obd->obd_replayable = 0;
4731 rc = tgt_init(env, &m->mdt_lut, obd, m->mdt_bottom);
4733 GOTO(err_fini_stack, rc);
4735 rc = mdt_fld_init(env, obd->obd_name, m);
4739 rc = mdt_seq_init(env, obd->obd_name, m);
4741 GOTO(err_fini_fld, rc);
4743 snprintf(info->mti_u.ns_name, sizeof info->mti_u.ns_name,
4744 LUSTRE_MDT_NAME"-%p", m);
4745 m->mdt_namespace = ldlm_namespace_new(obd, info->mti_u.ns_name,
4746 LDLM_NAMESPACE_SERVER,
4747 LDLM_NAMESPACE_GREEDY,
4749 if (m->mdt_namespace == NULL)
4750 GOTO(err_fini_seq, rc = -ENOMEM);
4752 m->mdt_namespace->ns_lvbp = m;
4753 m->mdt_namespace->ns_lvbo = &mdt_lvbo;
4755 ldlm_register_intent(m->mdt_namespace, mdt_intent_policy);
4756 /* set obd_namespace for compatibility with old code */
4757 obd->obd_namespace = m->mdt_namespace;
4759 cfs_timer_init(&m->mdt_ck_timer, mdt_ck_timer_callback, m);
4761 rc = mdt_ck_thread_start(m);
4763 GOTO(err_free_ns, rc);
4765 rc = mdt_fs_setup(env, m, obd, lsi);
4769 mdt_adapt_sptlrpc_conf(obd, 1);
4771 next = m->mdt_child;
4772 rc = next->md_ops->mdo_iocontrol(env, next, OBD_IOC_GET_MNTOPT, 0,
4775 GOTO(err_llog_cleanup, rc);
4777 if (mntopts & MNTOPT_USERXATTR)
4778 m->mdt_opts.mo_user_xattr = 1;
4780 m->mdt_opts.mo_user_xattr = 0;
4782 if (mntopts & MNTOPT_ACL)
4783 m->mdt_opts.mo_acl = 1;
4785 m->mdt_opts.mo_acl = 0;
4787 /* XXX: to support suppgid for ACL, we enable identity_upcall
4788 * by default, otherwise, maybe got unexpected -EACCESS. */
4789 if (m->mdt_opts.mo_acl)
4790 identity_upcall = MDT_IDENTITY_UPCALL_PATH;
4792 m->mdt_identity_cache = upcall_cache_init(obd->obd_name,identity_upcall,
4793 &mdt_identity_upcall_cache_ops);
4794 if (IS_ERR(m->mdt_identity_cache)) {
4795 rc = PTR_ERR(m->mdt_identity_cache);
4796 m->mdt_identity_cache = NULL;
4797 GOTO(err_llog_cleanup, rc);
4800 rc = mdt_procfs_init(m, dev);
4802 CERROR("Can't init MDT lprocfs, rc %d\n", rc);
4803 GOTO(err_recovery, rc);
4806 rc = mdt_quota_init(env, m, cfg);
4808 GOTO(err_procfs, rc);
4810 m->mdt_ldlm_client = &mdt2obd_dev(m)->obd_ldlm_client;
4811 ptlrpc_init_client(LDLM_CB_REQUEST_PORTAL, LDLM_CB_REPLY_PORTAL,
4812 "mdt_ldlm_client", m->mdt_ldlm_client);
4814 ping_evictor_start();
4816 /* recovery will be started upon mdt_prepare()
4817 * when the whole stack is complete and ready
4818 * to serve the requests */
4820 mdt_init_capa_ctxt(env, m);
4822 /* Reduce the initial timeout on an MDS because it doesn't need such
4823 * a long timeout as an OST does. Adaptive timeouts will adjust this
4824 * value appropriately. */
4825 if (ldlm_timeout == LDLM_TIMEOUT_DEFAULT)
4826 ldlm_timeout = MDS_LDLM_TIMEOUT_DEFAULT;
4833 target_recovery_fini(obd);
4834 upcall_cache_cleanup(m->mdt_identity_cache);
4835 m->mdt_identity_cache = NULL;
4837 mdt_llog_ctxt_unclone(env, m, LLOG_CHANGELOG_ORIG_CTXT);
4838 mdt_fs_cleanup(env, m);
4840 cfs_timer_disarm(&m->mdt_ck_timer);
4841 mdt_ck_thread_stop(m);
4843 ldlm_namespace_free(m->mdt_namespace, NULL, 0);
4844 obd->obd_namespace = m->mdt_namespace = NULL;
4846 mdt_seq_fini(env, m);
4848 mdt_fld_fini(env, m);
4850 tgt_fini(env, &m->mdt_lut);
4852 mdt_stack_fini(env, m, md2lu_dev(m->mdt_child));
4855 server_put_mount(dev, lmi->lmi_mnt);
4859 /* For interoperability, the left element is old parameter, the right one
4860 * is the new version of the parameter, if some parameter is deprecated,
4861 * the new version should be set as NULL. */
4862 static struct cfg_interop_param mdt_interop_param[] = {
4863 { "mdt.group_upcall", NULL },
4864 { "mdt.quota_type", NULL },
4865 { "mdd.quota_type", NULL },
4866 { "mdt.rootsquash", "mdt.root_squash" },
4867 { "mdt.nosquash_nid", "mdt.nosquash_nids" },
4871 /* used by MGS to process specific configurations */
4872 static int mdt_process_config(const struct lu_env *env,
4873 struct lu_device *d, struct lustre_cfg *cfg)
4875 struct mdt_device *m = mdt_dev(d);
4876 struct md_device *md_next = m->mdt_child;
4877 struct lu_device *next = md2lu_dev(md_next);
4881 switch (cfg->lcfg_command) {
4883 struct lprocfs_static_vars lvars;
4884 struct obd_device *obd = d->ld_obd;
4886 /* For interoperability */
4887 struct cfg_interop_param *ptr = NULL;
4888 struct lustre_cfg *old_cfg = NULL;
4891 param = lustre_cfg_string(cfg, 1);
4892 if (param == NULL) {
4893 CERROR("param is empty\n");
4898 ptr = class_find_old_param(param, mdt_interop_param);
4900 if (ptr->new_param == NULL) {
4902 CWARN("For interoperability, skip this %s."
4903 " It is obsolete.\n", ptr->old_param);
4907 CWARN("Found old param %s, changed it to %s.\n",
4908 ptr->old_param, ptr->new_param);
4911 cfg = lustre_cfg_rename(old_cfg, ptr->new_param);
4918 lprocfs_mdt_init_vars(&lvars);
4919 rc = class_process_proc_param(PARAM_MDT, lvars.obd_vars,
4921 if (rc > 0 || rc == -ENOSYS)
4922 /* we don't understand; pass it on */
4923 rc = next->ld_ops->ldo_process_config(env, next, cfg);
4925 if (old_cfg != NULL)
4926 lustre_cfg_free(cfg);
4931 /* others are passed further */
4932 rc = next->ld_ops->ldo_process_config(env, next, cfg);
4938 static struct lu_object *mdt_object_alloc(const struct lu_env *env,
4939 const struct lu_object_header *hdr,
4940 struct lu_device *d)
4942 struct mdt_object *mo;
4946 OBD_SLAB_ALLOC_PTR_GFP(mo, mdt_object_kmem, CFS_ALLOC_IO);
4948 struct lu_object *o;
4949 struct lu_object_header *h;
4951 o = &mo->mot_obj.mo_lu;
4952 h = &mo->mot_header;
4953 lu_object_header_init(h);
4954 lu_object_init(o, h, d);
4955 lu_object_add_top(h, o);
4956 o->lo_ops = &mdt_obj_ops;
4957 mutex_init(&mo->mot_ioepoch_mutex);
4958 mutex_init(&mo->mot_lov_mutex);
4964 static int mdt_object_init(const struct lu_env *env, struct lu_object *o,
4965 const struct lu_object_conf *unused)
4967 struct mdt_device *d = mdt_dev(o->lo_dev);
4968 struct lu_device *under;
4969 struct lu_object *below;
4973 CDEBUG(D_INFO, "object init, fid = "DFID"\n",
4974 PFID(lu_object_fid(o)));
4976 under = &d->mdt_child->md_lu_dev;
4977 below = under->ld_ops->ldo_object_alloc(env, o->lo_header, under);
4978 if (below != NULL) {
4979 lu_object_add(o, below);
4986 static void mdt_object_free(const struct lu_env *env, struct lu_object *o)
4988 struct mdt_object *mo = mdt_obj(o);
4989 struct lu_object_header *h;
4993 CDEBUG(D_INFO, "object free, fid = "DFID"\n",
4994 PFID(lu_object_fid(o)));
4997 lu_object_header_fini(h);
4998 OBD_SLAB_FREE_PTR(mo, mdt_object_kmem);
5003 static int mdt_object_print(const struct lu_env *env, void *cookie,
5004 lu_printer_t p, const struct lu_object *o)
5006 struct mdt_object *mdto = mdt_obj((struct lu_object *)o);
5007 return (*p)(env, cookie, LUSTRE_MDT_NAME"-object@%p(ioepoch="LPU64" "
5008 "flags="LPX64", epochcount=%d, writecount=%d)",
5009 mdto, mdto->mot_ioepoch, mdto->mot_flags,
5010 mdto->mot_ioepoch_count, mdto->mot_writecount);
5013 static int mdt_prepare(const struct lu_env *env,
5014 struct lu_device *pdev,
5015 struct lu_device *cdev)
5017 struct mdt_device *mdt = mdt_dev(cdev);
5018 struct lu_device *next = &mdt->mdt_child->md_lu_dev;
5019 struct obd_device *obd = cdev->ld_obd;
5026 rc = next->ld_ops->ldo_prepare(env, cdev, next);
5030 rc = mdt_llog_ctxt_clone(env, mdt, LLOG_CHANGELOG_ORIG_CTXT);
5034 rc = mdt->mdt_child->md_ops->mdo_iocontrol(env, mdt->mdt_child,
5035 OBD_IOC_START_LFSCK,
5038 CWARN("Fail to auto trigger paused LFSCK.\n");
5040 if (mdt->mdt_seq_site.ss_node_id == 0) {
5041 rc = mdt->mdt_child->md_ops->mdo_root_get(env, mdt->mdt_child,
5042 &mdt->mdt_md_root_fid);
5046 LASSERT(!test_bit(MDT_FL_CFGLOG, &mdt->mdt_state));
5047 target_recovery_init(&mdt->mdt_lut, mdt_recovery_handle);
5048 set_bit(MDT_FL_CFGLOG, &mdt->mdt_state);
5049 LASSERT(obd->obd_no_conn);
5050 spin_lock(&obd->obd_dev_lock);
5051 obd->obd_no_conn = 0;
5052 spin_unlock(&obd->obd_dev_lock);
5054 if (obd->obd_recovering == 0)
5055 mdt_postrecov(env, mdt);
5060 const struct lu_device_operations mdt_lu_ops = {
5061 .ldo_object_alloc = mdt_object_alloc,
5062 .ldo_process_config = mdt_process_config,
5063 .ldo_prepare = mdt_prepare,
5066 static const struct lu_object_operations mdt_obj_ops = {
5067 .loo_object_init = mdt_object_init,
5068 .loo_object_free = mdt_object_free,
5069 .loo_object_print = mdt_object_print
5072 static int mdt_obd_set_info_async(const struct lu_env *env,
5073 struct obd_export *exp,
5074 __u32 keylen, void *key,
5075 __u32 vallen, void *val,
5076 struct ptlrpc_request_set *set)
5078 struct obd_device *obd = exp->exp_obd;
5084 if (KEY_IS(KEY_SPTLRPC_CONF)) {
5085 rc = mdt_adapt_sptlrpc_conf(obd, 0);
5093 * Match client and server connection feature flags.
5095 * Compute the compatibility flags for a connection request based on
5096 * features mutually supported by client and server.
5098 * The obd_export::exp_connect_data.ocd_connect_flags field in \a exp
5099 * must not be updated here, otherwise a partially initialized value may
5100 * be exposed. After the connection request is successfully processed,
5101 * the top-level MDT connect request handler atomically updates the export
5102 * connect flags from the obd_connect_data::ocd_connect_flags field of the
5103 * reply. \see mdt_connect().
5105 * \param exp the obd_export associated with this client/target pair
5106 * \param mdt the target device for the connection
5107 * \param data stores data for this connect request
5110 * \retval -EPROTO \a data unexpectedly has zero obd_connect_data::ocd_brw_size
5111 * \retval -EBADE client and server feature requirements are incompatible
5113 static int mdt_connect_internal(struct obd_export *exp,
5114 struct mdt_device *mdt,
5115 struct obd_connect_data *data)
5117 LASSERT(data != NULL);
5119 data->ocd_connect_flags &= MDT_CONNECT_SUPPORTED;
5120 data->ocd_ibits_known &= MDS_INODELOCK_FULL;
5122 /* If no known bits (which should not happen, probably,
5123 as everybody should support LOOKUP and UPDATE bits at least)
5124 revert to compat mode with plain locks. */
5125 if (!data->ocd_ibits_known &&
5126 data->ocd_connect_flags & OBD_CONNECT_IBITS)
5127 data->ocd_connect_flags &= ~OBD_CONNECT_IBITS;
5129 if (!mdt->mdt_opts.mo_acl)
5130 data->ocd_connect_flags &= ~OBD_CONNECT_ACL;
5132 if (!mdt->mdt_opts.mo_user_xattr)
5133 data->ocd_connect_flags &= ~OBD_CONNECT_XATTR;
5135 if (!mdt->mdt_som_conf)
5136 data->ocd_connect_flags &= ~OBD_CONNECT_SOM;
5138 if (data->ocd_connect_flags & OBD_CONNECT_BRW_SIZE) {
5139 data->ocd_brw_size = min(data->ocd_brw_size,
5140 (__u32)MD_MAX_BRW_SIZE);
5141 if (data->ocd_brw_size == 0) {
5142 CERROR("%s: cli %s/%p ocd_connect_flags: "LPX64
5143 " ocd_version: %x ocd_grant: %d "
5144 "ocd_index: %u ocd_brw_size is "
5145 "unexpectedly zero, network data "
5146 "corruption? Refusing connection of this"
5148 exp->exp_obd->obd_name,
5149 exp->exp_client_uuid.uuid,
5150 exp, data->ocd_connect_flags, data->ocd_version,
5151 data->ocd_grant, data->ocd_index);
5156 /* NB: Disregard the rule against updating
5157 * exp_connect_data.ocd_connect_flags in this case, since
5158 * tgt_client_new() needs to know if this is a lightweight
5159 * connection, and it is safe to expose this flag before
5160 * connection processing completes. */
5161 if (data->ocd_connect_flags & OBD_CONNECT_LIGHTWEIGHT) {
5162 spin_lock(&exp->exp_lock);
5163 *exp_connect_flags_ptr(exp) |= OBD_CONNECT_LIGHTWEIGHT;
5164 spin_unlock(&exp->exp_lock);
5167 data->ocd_version = LUSTRE_VERSION_CODE;
5168 exp->exp_connect_data = *data;
5169 exp->exp_mdt_data.med_ibits_known = data->ocd_ibits_known;
5171 if ((data->ocd_connect_flags & OBD_CONNECT_FID) == 0) {
5172 CWARN("%s: MDS requires FID support, but client not\n",
5173 mdt->mdt_md_dev.md_lu_dev.ld_obd->obd_name);
5177 if (mdt->mdt_som_conf &&
5178 !(data->ocd_connect_flags & (OBD_CONNECT_LIGHTWEIGHT |
5179 OBD_CONNECT_MDS_MDS |
5180 OBD_CONNECT_SOM))) {
5181 CWARN("%s: MDS has SOM enabled, but client does not support "
5182 "it\n", mdt->mdt_md_dev.md_lu_dev.ld_obd->obd_name);
5186 if (data->ocd_connect_flags & OBD_CONNECT_PINGLESS) {
5187 if (ptlrpc_pinger_suppress_pings()) {
5188 spin_lock(&exp->exp_obd->obd_dev_lock);
5189 list_del_init(&exp->exp_obd_chain_timed);
5190 spin_unlock(&exp->exp_obd->obd_dev_lock);
5192 data->ocd_connect_flags &= ~OBD_CONNECT_PINGLESS;
5199 static int mdt_connect_check_sptlrpc(struct mdt_device *mdt,
5200 struct obd_export *exp,
5201 struct ptlrpc_request *req)
5203 struct sptlrpc_flavor flvr;
5206 if (exp->exp_flvr.sf_rpc == SPTLRPC_FLVR_INVALID) {
5207 read_lock(&mdt->mdt_sptlrpc_lock);
5208 sptlrpc_target_choose_flavor(&mdt->mdt_sptlrpc_rset,
5212 read_unlock(&mdt->mdt_sptlrpc_lock);
5214 spin_lock(&exp->exp_lock);
5216 exp->exp_sp_peer = req->rq_sp_from;
5217 exp->exp_flvr = flvr;
5219 if (exp->exp_flvr.sf_rpc != SPTLRPC_FLVR_ANY &&
5220 exp->exp_flvr.sf_rpc != req->rq_flvr.sf_rpc) {
5221 CERROR("unauthorized rpc flavor %x from %s, "
5222 "expect %x\n", req->rq_flvr.sf_rpc,
5223 libcfs_nid2str(req->rq_peer.nid),
5224 exp->exp_flvr.sf_rpc);
5228 spin_unlock(&exp->exp_lock);
5230 if (exp->exp_sp_peer != req->rq_sp_from) {
5231 CERROR("RPC source %s doesn't match %s\n",
5232 sptlrpc_part2name(req->rq_sp_from),
5233 sptlrpc_part2name(exp->exp_sp_peer));
5236 rc = sptlrpc_target_export_check(exp, req);
5243 /* mds_connect copy */
5244 static int mdt_obd_connect(const struct lu_env *env,
5245 struct obd_export **exp, struct obd_device *obd,
5246 struct obd_uuid *cluuid,
5247 struct obd_connect_data *data,
5250 struct mdt_thread_info *info;
5251 struct obd_export *lexp;
5252 struct lustre_handle conn = { 0 };
5253 struct mdt_device *mdt;
5254 struct ptlrpc_request *req;
5258 LASSERT(env != NULL);
5259 if (!exp || !obd || !cluuid)
5262 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
5263 req = info->mti_pill->rc_req;
5264 mdt = mdt_dev(obd->obd_lu_dev);
5267 * first, check whether the stack is ready to handle requests
5268 * XXX: probably not very appropriate method is used now
5269 * at some point we should find a better one
5271 if (!test_bit(MDT_FL_SYNCED, &mdt->mdt_state) &&
5272 !(data->ocd_connect_flags & OBD_CONNECT_LIGHTWEIGHT)) {
5273 rc = obd_health_check(env, mdt->mdt_child_exp->exp_obd);
5276 set_bit(MDT_FL_SYNCED, &mdt->mdt_state);
5279 rc = class_connect(&conn, obd, cluuid);
5283 lexp = class_conn2export(&conn);
5284 LASSERT(lexp != NULL);
5286 rc = mdt_connect_check_sptlrpc(mdt, lexp, req);
5290 if (OBD_FAIL_CHECK(OBD_FAIL_TGT_RCVG_FLAG))
5291 lustre_msg_add_op_flags(req->rq_repmsg, MSG_CONNECT_RECOVERING);
5293 rc = mdt_connect_internal(lexp, mdt, data);
5295 struct lsd_client_data *lcd = lexp->exp_target_data.ted_lcd;
5298 info->mti_exp = lexp;
5299 memcpy(lcd->lcd_uuid, cluuid, sizeof lcd->lcd_uuid);
5300 rc = tgt_client_new(env, lexp);
5302 mdt_export_stats_init(obd, lexp, localdata);
5307 class_disconnect(lexp);
5316 static int mdt_obd_reconnect(const struct lu_env *env,
5317 struct obd_export *exp, struct obd_device *obd,
5318 struct obd_uuid *cluuid,
5319 struct obd_connect_data *data,
5322 struct mdt_thread_info *info;
5323 struct mdt_device *mdt;
5324 struct ptlrpc_request *req;
5328 if (exp == NULL || obd == NULL || cluuid == NULL)
5331 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
5332 req = info->mti_pill->rc_req;
5333 mdt = mdt_dev(obd->obd_lu_dev);
5335 rc = mdt_connect_check_sptlrpc(mdt, exp, req);
5339 rc = mdt_connect_internal(exp, mdt_dev(obd->obd_lu_dev), data);
5341 mdt_export_stats_init(obd, exp, localdata);
5346 static int mdt_export_cleanup(struct obd_export *exp)
5348 struct mdt_export_data *med = &exp->exp_mdt_data;
5349 struct obd_device *obd = exp->exp_obd;
5350 struct mdt_device *mdt;
5351 struct mdt_thread_info *info;
5353 CFS_LIST_HEAD(closing_list);
5354 struct mdt_file_data *mfd, *n;
5358 spin_lock(&med->med_open_lock);
5359 while (!cfs_list_empty(&med->med_open_head)) {
5360 cfs_list_t *tmp = med->med_open_head.next;
5361 mfd = cfs_list_entry(tmp, struct mdt_file_data, mfd_list);
5363 /* Remove mfd handle so it can't be found again.
5364 * We are consuming the mfd_list reference here. */
5365 class_handle_unhash(&mfd->mfd_handle);
5366 cfs_list_move_tail(&mfd->mfd_list, &closing_list);
5368 spin_unlock(&med->med_open_lock);
5369 mdt = mdt_dev(obd->obd_lu_dev);
5370 LASSERT(mdt != NULL);
5372 rc = lu_env_init(&env, LCT_MD_THREAD);
5376 info = lu_context_key_get(&env.le_ctx, &mdt_thread_key);
5377 LASSERT(info != NULL);
5378 memset(info, 0, sizeof *info);
5379 info->mti_env = &env;
5380 info->mti_mdt = mdt;
5381 info->mti_exp = exp;
5383 if (!cfs_list_empty(&closing_list)) {
5384 struct md_attr *ma = &info->mti_attr;
5386 /* Close any open files (which may also cause orphan unlinking). */
5387 cfs_list_for_each_entry_safe(mfd, n, &closing_list, mfd_list) {
5388 cfs_list_del_init(&mfd->mfd_list);
5389 ma->ma_need = ma->ma_valid = 0;
5390 /* Don't unlink orphan on failover umount, LU-184 */
5391 if (exp->exp_flags & OBD_OPT_FAILOVER) {
5392 ma->ma_valid = MA_FLAGS;
5393 ma->ma_attr_flags |= MDS_KEEP_ORPHAN;
5395 mdt_mfd_close(info, mfd);
5398 info->mti_mdt = NULL;
5399 /* cleanup client slot early */
5400 /* Do not erase record for recoverable client. */
5401 if (!(exp->exp_flags & OBD_OPT_FAILOVER) || exp->exp_failed)
5402 tgt_client_del(&env, exp);
5408 static int mdt_obd_disconnect(struct obd_export *exp)
5414 class_export_get(exp);
5416 rc = server_disconnect_export(exp);
5418 CDEBUG(D_IOCTL, "server disconnect error: %d\n", rc);
5420 rc = mdt_export_cleanup(exp);
5421 class_export_put(exp);
5425 /* FIXME: Can we avoid using these two interfaces? */
5426 static int mdt_init_export(struct obd_export *exp)
5428 struct mdt_export_data *med = &exp->exp_mdt_data;
5432 CFS_INIT_LIST_HEAD(&med->med_open_head);
5433 spin_lock_init(&med->med_open_lock);
5434 mutex_init(&med->med_idmap_mutex);
5435 med->med_idmap = NULL;
5436 spin_lock(&exp->exp_lock);
5437 exp->exp_connecting = 1;
5438 spin_unlock(&exp->exp_lock);
5440 /* self-export doesn't need client data and ldlm initialization */
5441 if (unlikely(obd_uuid_equals(&exp->exp_obd->obd_uuid,
5442 &exp->exp_client_uuid)))
5445 rc = tgt_client_alloc(exp);
5449 rc = ldlm_init_export(exp);
5456 tgt_client_free(exp);
5458 CERROR("%s: Failed to initialize export: rc = %d\n",
5459 exp->exp_obd->obd_name, rc);
5463 static int mdt_destroy_export(struct obd_export *exp)
5467 if (exp_connect_rmtclient(exp))
5468 mdt_cleanup_idmap(&exp->exp_mdt_data);
5470 target_destroy_export(exp);
5471 /* destroy can be called from failed obd_setup, so
5472 * checking uuid is safer than obd_self_export */
5473 if (unlikely(obd_uuid_equals(&exp->exp_obd->obd_uuid,
5474 &exp->exp_client_uuid)))
5477 ldlm_destroy_export(exp);
5478 tgt_client_free(exp);
5480 LASSERT(cfs_list_empty(&exp->exp_outstanding_replies));
5481 LASSERT(cfs_list_empty(&exp->exp_mdt_data.med_open_head));
5486 /** The maximum depth that fid2path() will search.
5487 * This is limited only because we want to store the fids for
5488 * historical path lookup purposes.
5490 #define MAX_PATH_DEPTH 100
5492 /** mdt_path() lookup structure. */
5493 struct path_lookup_info {
5494 __u64 pli_recno; /**< history point */
5495 __u64 pli_currec; /**< current record */
5496 struct lu_fid pli_fid;
5497 struct lu_fid pli_fids[MAX_PATH_DEPTH]; /**< path, in fids */
5498 struct mdt_object *pli_mdt_obj;
5499 char *pli_path; /**< full path */
5501 int pli_linkno; /**< which hardlink to follow */
5502 int pli_fidcount; /**< number of \a pli_fids */
5505 static int mdt_links_read(struct mdt_thread_info *info,
5506 struct mdt_object *mdt_obj, struct linkea_data *ldata)
5510 LASSERT(ldata->ld_buf->lb_buf != NULL);
5512 if (!mdt_object_exists(mdt_obj))
5515 rc = mo_xattr_get(info->mti_env, mdt_object_child(mdt_obj),
5516 ldata->ld_buf, XATTR_NAME_LINK);
5517 if (rc == -ERANGE) {
5518 /* Buf was too small, figure out what we need. */
5519 lu_buf_free(ldata->ld_buf);
5520 rc = mo_xattr_get(info->mti_env, mdt_object_child(mdt_obj),
5521 ldata->ld_buf, XATTR_NAME_LINK);
5524 ldata->ld_buf = lu_buf_check_and_alloc(ldata->ld_buf, rc);
5525 if (ldata->ld_buf->lb_buf == NULL)
5527 rc = mo_xattr_get(info->mti_env, mdt_object_child(mdt_obj),
5528 ldata->ld_buf, XATTR_NAME_LINK);
5538 static int mdt_path_current(struct mdt_thread_info *info,
5539 struct path_lookup_info *pli)
5541 struct mdt_device *mdt = info->mti_mdt;
5542 struct mdt_object *mdt_obj;
5543 struct link_ea_header *leh;
5544 struct link_ea_entry *lee;
5545 struct lu_name *tmpname = &info->mti_name;
5546 struct lu_fid *tmpfid = &info->mti_tmp_fid1;
5547 struct lu_buf *buf = &info->mti_big_buf;
5550 struct linkea_data ldata = { 0 };
5554 /* temp buffer for path element, the buffer will be finally freed
5555 * in mdt_thread_info_fini */
5556 buf = lu_buf_check_and_alloc(buf, PATH_MAX);
5557 if (buf->lb_buf == NULL)
5561 ptr = pli->pli_path + pli->pli_pathlen - 1;
5564 pli->pli_fidcount = 0;
5565 pli->pli_fids[0] = *(struct lu_fid *)mdt_object_fid(pli->pli_mdt_obj);
5567 /* root FID only exists on MDT0, and fid2path should also ends at MDT0,
5568 * so checking root_fid can only happen on MDT0. */
5569 while (!lu_fid_eq(&mdt->mdt_md_root_fid,
5570 &pli->pli_fids[pli->pli_fidcount])) {
5571 mdt_obj = mdt_object_find(info->mti_env, mdt,
5572 &pli->pli_fids[pli->pli_fidcount]);
5573 if (IS_ERR(mdt_obj))
5574 GOTO(out, rc = PTR_ERR(mdt_obj));
5575 if (mdt_object_remote(mdt_obj)) {
5576 mdt_object_put(info->mti_env, mdt_obj);
5577 GOTO(remote_out, rc = -EREMOTE);
5579 if (!mdt_object_exists(mdt_obj)) {
5580 mdt_object_put(info->mti_env, mdt_obj);
5581 GOTO(out, rc = -ENOENT);
5584 rc = mdt_links_read(info, mdt_obj, &ldata);
5585 mdt_object_put(info->mti_env, mdt_obj);
5587 GOTO(out, rc = PTR_ERR(buf));
5590 lee = (struct link_ea_entry *)(leh + 1); /* link #0 */
5591 linkea_entry_unpack(lee, &reclen, tmpname, tmpfid);
5592 /* If set, use link #linkno for path lookup, otherwise use
5593 link #0. Only do this for the final path element. */
5594 if ((pli->pli_fidcount == 0) &&
5595 (pli->pli_linkno < leh->leh_reccount)) {
5597 for (count = 0; count < pli->pli_linkno; count++) {
5598 lee = (struct link_ea_entry *)
5599 ((char *)lee + reclen);
5600 linkea_entry_unpack(lee, &reclen, tmpname,
5603 if (pli->pli_linkno < leh->leh_reccount - 1)
5604 /* indicate to user there are more links */
5608 /* Pack the name in the end of the buffer */
5609 ptr -= tmpname->ln_namelen;
5610 if (ptr - 1 <= pli->pli_path)
5611 GOTO(out, rc = -EOVERFLOW);
5612 strncpy(ptr, tmpname->ln_name, tmpname->ln_namelen);
5615 /* Store the parent fid for historic lookup */
5616 if (++pli->pli_fidcount >= MAX_PATH_DEPTH)
5617 GOTO(out, rc = -EOVERFLOW);
5618 pli->pli_fids[pli->pli_fidcount] = *tmpfid;
5622 ptr++; /* skip leading / */
5623 memmove(pli->pli_path, ptr, pli->pli_path + pli->pli_pathlen - ptr);
5630 /* Returns the full path to this fid, as of changelog record recno. */
5631 static int mdt_path(struct mdt_thread_info *info, struct mdt_object *obj,
5632 char *path, int pathlen, __u64 *recno, int *linkno,
5635 struct mdt_device *mdt = info->mti_mdt;
5636 struct path_lookup_info *pli;
5644 if (lu_fid_eq(&mdt->mdt_md_root_fid, mdt_object_fid(obj))) {
5653 pli->pli_mdt_obj = obj;
5654 pli->pli_recno = *recno;
5655 pli->pli_path = path;
5656 pli->pli_pathlen = pathlen;
5657 pli->pli_linkno = *linkno;
5659 /* Retry multiple times in case file is being moved */
5660 while (tries-- && rc == -EAGAIN)
5661 rc = mdt_path_current(info, pli);
5663 /* return the last resolved fids to the client, so the client will
5664 * build the left path on another MDT for remote object */
5665 *fid = pli->pli_fids[pli->pli_fidcount];
5667 *recno = pli->pli_currec;
5668 /* Return next link index to caller */
5669 *linkno = pli->pli_linkno;
5676 static int mdt_fid2path(struct mdt_thread_info *info,
5677 struct getinfo_fid2path *fp)
5679 struct mdt_device *mdt = info->mti_mdt;
5680 struct obd_device *obd = mdt2obd_dev(mdt);
5681 struct mdt_object *obj;
5685 CDEBUG(D_IOCTL, "path get "DFID" from "LPU64" #%d\n",
5686 PFID(&fp->gf_fid), fp->gf_recno, fp->gf_linkno);
5688 if (!fid_is_sane(&fp->gf_fid))
5691 if (!fid_is_client_mdt_visible(&fp->gf_fid)) {
5692 CWARN("%s: "DFID" is invalid, sequence should be "
5693 ">= "LPX64"\n", obd->obd_name,
5694 PFID(&fp->gf_fid), (__u64)FID_SEQ_NORMAL);
5698 obj = mdt_object_find(info->mti_env, mdt, &fp->gf_fid);
5699 if (obj == NULL || IS_ERR(obj)) {
5700 CDEBUG(D_IOCTL, "no object "DFID": %ld\n", PFID(&fp->gf_fid),
5705 if (mdt_object_remote(obj))
5707 else if (!mdt_object_exists(obj))
5713 mdt_object_put(info->mti_env, obj);
5714 CDEBUG(D_IOCTL, "nonlocal object "DFID": %d\n",
5715 PFID(&fp->gf_fid), rc);
5719 rc = mdt_path(info, obj, fp->gf_path, fp->gf_pathlen, &fp->gf_recno,
5720 &fp->gf_linkno, &fp->gf_fid);
5722 CDEBUG(D_INFO, "fid "DFID", path %s recno "LPX64" linkno %u\n",
5723 PFID(&fp->gf_fid), fp->gf_path, fp->gf_recno, fp->gf_linkno);
5725 mdt_object_put(info->mti_env, obj);
5730 static int mdt_rpc_fid2path(struct mdt_thread_info *info, void *key,
5731 void *val, int vallen)
5733 struct getinfo_fid2path *fpout, *fpin;
5736 fpin = key + cfs_size_round(sizeof(KEY_FID2PATH));
5739 if (ptlrpc_req_need_swab(info->mti_pill->rc_req))
5740 lustre_swab_fid2path(fpin);
5742 memcpy(fpout, fpin, sizeof(*fpin));
5743 if (fpout->gf_pathlen != vallen - sizeof(*fpin))
5746 rc = mdt_fid2path(info, fpout);
5750 int mdt_get_info(struct mdt_thread_info *info)
5752 struct ptlrpc_request *req = mdt_info_req(info);
5760 key = req_capsule_client_get(info->mti_pill, &RMF_GETINFO_KEY);
5762 CDEBUG(D_IOCTL, "No GETINFO key");
5765 keylen = req_capsule_get_size(info->mti_pill, &RMF_GETINFO_KEY,
5768 vallen = req_capsule_client_get(info->mti_pill, &RMF_GETINFO_VALLEN);
5769 if (vallen == NULL) {
5770 CDEBUG(D_IOCTL, "Unable to get RMF_GETINFO_VALLEN buffer");
5774 req_capsule_set_size(info->mti_pill, &RMF_GETINFO_VAL, RCL_SERVER,
5776 rc = req_capsule_server_pack(info->mti_pill);
5777 valout = req_capsule_server_get(info->mti_pill, &RMF_GETINFO_VAL);
5778 if (valout == NULL) {
5779 CDEBUG(D_IOCTL, "Unable to get get-info RPC out buffer");
5783 if (KEY_IS(KEY_FID2PATH))
5784 rc = mdt_rpc_fid2path(info, key, valout, *vallen);
5788 lustre_msg_set_status(req->rq_repmsg, rc);
5793 /* Pass the ioc down */
5794 static int mdt_ioc_child(struct lu_env *env, struct mdt_device *mdt,
5795 unsigned int cmd, int len, void *data)
5797 struct lu_context ioctl_session;
5798 struct md_device *next = mdt->mdt_child;
5802 rc = lu_context_init(&ioctl_session, LCT_SESSION);
5805 ioctl_session.lc_thread = (struct ptlrpc_thread *)cfs_current();
5806 lu_context_enter(&ioctl_session);
5807 env->le_ses = &ioctl_session;
5809 LASSERT(next->md_ops->mdo_iocontrol);
5810 rc = next->md_ops->mdo_iocontrol(env, next, cmd, len, data);
5812 lu_context_exit(&ioctl_session);
5813 lu_context_fini(&ioctl_session);
5817 static int mdt_ioc_version_get(struct mdt_thread_info *mti, void *karg)
5819 struct obd_ioctl_data *data = karg;
5822 struct mdt_object *obj;
5823 struct mdt_lock_handle *lh;
5827 if (data->ioc_inlbuf1 == NULL || data->ioc_inllen1 != sizeof(*fid) ||
5828 data->ioc_inlbuf2 == NULL || data->ioc_inllen2 != sizeof(version))
5831 fid = (struct lu_fid *)data->ioc_inlbuf1;
5833 if (!fid_is_sane(fid))
5836 CDEBUG(D_IOCTL, "getting version for "DFID"\n", PFID(fid));
5838 lh = &mti->mti_lh[MDT_LH_PARENT];
5839 mdt_lock_reg_init(lh, LCK_CR);
5841 obj = mdt_object_find_lock(mti, fid, lh, MDS_INODELOCK_UPDATE);
5843 RETURN(PTR_ERR(obj));
5845 if (mdt_object_remote(obj)) {
5848 * before calling version get the correct MDS should be
5849 * fid, this is error to find remote object here
5851 CERROR("nonlocal object "DFID"\n", PFID(fid));
5852 } else if (!mdt_object_exists(obj)) {
5853 *(__u64 *)data->ioc_inlbuf2 = ENOENT_VERSION;
5856 version = dt_version_get(mti->mti_env, mdt_obj2dt(obj));
5857 *(__u64 *)data->ioc_inlbuf2 = version;
5860 mdt_object_unlock_put(mti, obj, lh, 1);
5864 /* ioctls on obd dev */
5865 static int mdt_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
5866 void *karg, void *uarg)
5869 struct obd_device *obd = exp->exp_obd;
5870 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
5871 struct dt_device *dt = mdt->mdt_bottom;
5875 CDEBUG(D_IOCTL, "handling ioctl cmd %#x\n", cmd);
5876 rc = lu_env_init(&env, LCT_MD_THREAD);
5882 rc = mdt_device_sync(&env, mdt);
5884 case OBD_IOC_SET_READONLY:
5885 rc = dt->dd_ops->dt_ro(&env, dt);
5887 case OBD_IOC_ABORT_RECOVERY:
5888 CERROR("Aborting recovery for device %s\n", obd->obd_name);
5889 target_stop_recovery_thread(obd);
5892 case OBD_IOC_CHANGELOG_REG:
5893 case OBD_IOC_CHANGELOG_DEREG:
5894 case OBD_IOC_CHANGELOG_CLEAR:
5895 rc = mdt_ioc_child(&env, mdt, cmd, len, karg);
5897 case OBD_IOC_START_LFSCK:
5898 case OBD_IOC_STOP_LFSCK: {
5899 struct md_device *next = mdt->mdt_child;
5900 struct obd_ioctl_data *data = karg;
5902 if (unlikely(data == NULL)) {
5907 rc = next->md_ops->mdo_iocontrol(&env, next, cmd,
5912 case OBD_IOC_GET_OBJ_VERSION: {
5913 struct mdt_thread_info *mti;
5914 mti = lu_context_key_get(&env.le_ctx, &mdt_thread_key);
5915 memset(mti, 0, sizeof *mti);
5916 mti->mti_env = &env;
5920 rc = mdt_ioc_version_get(mti, karg);
5924 CERROR("Not supported cmd = %d for device %s\n",
5925 cmd, obd->obd_name);
5933 int mdt_postrecov(const struct lu_env *env, struct mdt_device *mdt)
5935 struct lu_device *ld = md2lu_dev(mdt->mdt_child);
5939 rc = ld->ld_ops->ldo_recovery_complete(env, ld);
5943 int mdt_obd_postrecov(struct obd_device *obd)
5948 rc = lu_env_init(&env, LCT_MD_THREAD);
5951 rc = mdt_postrecov(&env, mdt_dev(obd->obd_lu_dev));
5956 static struct obd_ops mdt_obd_device_ops = {
5957 .o_owner = THIS_MODULE,
5958 .o_set_info_async = mdt_obd_set_info_async,
5959 .o_connect = mdt_obd_connect,
5960 .o_reconnect = mdt_obd_reconnect,
5961 .o_disconnect = mdt_obd_disconnect,
5962 .o_init_export = mdt_init_export,
5963 .o_destroy_export = mdt_destroy_export,
5964 .o_iocontrol = mdt_iocontrol,
5965 .o_postrecov = mdt_obd_postrecov,
5968 static struct lu_device* mdt_device_fini(const struct lu_env *env,
5969 struct lu_device *d)
5971 struct mdt_device *m = mdt_dev(d);
5978 static struct lu_device *mdt_device_free(const struct lu_env *env,
5979 struct lu_device *d)
5981 struct mdt_device *m = mdt_dev(d);
5984 md_device_fini(&m->mdt_md_dev);
5989 static struct lu_device *mdt_device_alloc(const struct lu_env *env,
5990 struct lu_device_type *t,
5991 struct lustre_cfg *cfg)
5993 struct lu_device *l;
5994 struct mdt_device *m;
6000 l = &m->mdt_md_dev.md_lu_dev;
6001 rc = mdt_init0(env, m, t, cfg);
6003 mdt_device_free(env, l);
6008 l = ERR_PTR(-ENOMEM);
6012 /* context key constructor/destructor: mdt_key_init, mdt_key_fini */
6013 LU_KEY_INIT(mdt, struct mdt_thread_info);
6015 static void mdt_key_fini(const struct lu_context *ctx,
6016 struct lu_context_key *key, void* data)
6018 struct mdt_thread_info *info = data;
6020 if (info->mti_big_lmm) {
6021 OBD_FREE_LARGE(info->mti_big_lmm, info->mti_big_lmmsize);
6022 info->mti_big_lmm = NULL;
6023 info->mti_big_lmmsize = 0;
6028 /* context key: mdt_thread_key */
6029 LU_CONTEXT_KEY_DEFINE(mdt, LCT_MD_THREAD);
6031 struct lu_ucred *mdt_ucred(const struct mdt_thread_info *info)
6033 return lu_ucred(info->mti_env);
6036 struct lu_ucred *mdt_ucred_check(const struct mdt_thread_info *info)
6038 return lu_ucred_check(info->mti_env);
6042 * Enable/disable COS (Commit On Sharing).
6044 * Set/Clear the COS flag in mdt options.
6046 * \param mdt mdt device
6047 * \param val 0 disables COS, other values enable COS
6049 void mdt_enable_cos(struct mdt_device *mdt, int val)
6054 mdt->mdt_opts.mo_cos = !!val;
6055 rc = lu_env_init(&env, LCT_LOCAL);
6056 if (unlikely(rc != 0)) {
6057 CWARN("lu_env initialization failed with rc = %d,"
6058 "cannot sync\n", rc);
6061 mdt_device_sync(&env, mdt);
6066 * Check COS (Commit On Sharing) status.
6068 * Return COS flag status.
6070 * \param mdt mdt device
6072 int mdt_cos_is_enabled(struct mdt_device *mdt)
6074 return mdt->mdt_opts.mo_cos != 0;
6077 static struct lu_device_type_operations mdt_device_type_ops = {
6078 .ldto_device_alloc = mdt_device_alloc,
6079 .ldto_device_free = mdt_device_free,
6080 .ldto_device_fini = mdt_device_fini
6083 static struct lu_device_type mdt_device_type = {
6084 .ldt_tags = LU_DEVICE_MD,
6085 .ldt_name = LUSTRE_MDT_NAME,
6086 .ldt_ops = &mdt_device_type_ops,
6087 .ldt_ctx_tags = LCT_MD_THREAD
6090 static int __init mdt_mod_init(void)
6092 struct lprocfs_static_vars lvars;
6095 rc = lu_kmem_init(mdt_caches);
6099 rc = mds_mod_init();
6103 lprocfs_mdt_init_vars(&lvars);
6104 rc = class_register_type(&mdt_obd_device_ops, NULL,
6105 lvars.module_vars, LUSTRE_MDT_NAME,
6111 lu_kmem_fini(mdt_caches);
6118 static void __exit mdt_mod_exit(void)
6120 class_unregister_type(LUSTRE_MDT_NAME);
6122 lu_kmem_fini(mdt_caches);
6125 MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");
6126 MODULE_DESCRIPTION("Lustre Metadata Target ("LUSTRE_MDT_NAME")");
6127 MODULE_LICENSE("GPL");
6129 cfs_module(mdt, LUSTRE_VERSION_STRING, mdt_mod_init, mdt_mod_exit);