1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * lustre/mdt/mdt_handler.c
5 * Lustre Metadata Target (mdt) request handler
7 * Copyright (c) 2006 Cluster File Systems, Inc.
8 * Author: Peter Braam <braam@clusterfs.com>
9 * Author: Andreas Dilger <adilger@clusterfs.com>
10 * Author: Phil Schwan <phil@clusterfs.com>
11 * Author: Mike Shaver <shaver@clusterfs.com>
12 * Author: Nikita Danilov <nikita@clusterfs.com>
13 * Author: Huang Hua <huanghua@clusterfs.com>
14 * Author: Yury Umanets <umka@clusterfs.com>
16 * This file is part of the Lustre file system, http://www.lustre.org
17 * Lustre is a trademark of Cluster File Systems, Inc.
19 * You may have signed or agreed to another license before downloading
20 * this software. If so, you are bound by the terms and conditions
21 * of that agreement, and the following does not apply to you. See the
22 * LICENSE file included with this distribution for more information.
24 * If you did not agree to a different license, then this copy of Lustre
25 * is open source software; you can redistribute it and/or modify it
26 * under the terms of version 2 of the GNU General Public License as
27 * published by the Free Software Foundation.
29 * In either case, Lustre is distributed in the hope that it will be
30 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
31 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32 * license text for more details.
36 # define EXPORT_SYMTAB
38 #define DEBUG_SUBSYSTEM S_MDS
40 #include <linux/module.h>
42 * struct OBD_{ALLOC,FREE}*()
44 #include <obd_support.h>
45 /* struct ptlrpc_request */
46 #include <lustre_net.h>
47 /* struct obd_export */
48 #include <lustre_export.h>
49 /* struct obd_device */
52 #include <dt_object.h>
53 #include <lustre_mds.h>
54 #include <lustre_mdt.h>
55 #include "mdt_internal.h"
56 #include <linux/lustre_acl.h>
57 #include <lustre_param.h>
59 mdl_mode_t mdt_mdl_lock_modes[] = {
60 [LCK_MINMODE] = MDL_MINMODE,
67 [LCK_GROUP] = MDL_GROUP
70 ldlm_mode_t mdt_dlm_lock_modes[] = {
71 [MDL_MINMODE] = LCK_MINMODE,
78 [MDL_GROUP] = LCK_GROUP
82 * Initialized in mdt_mod_init().
84 unsigned long mdt_num_threads;
86 /* ptlrpc request handler for MDT. All handlers are
87 * grouped into several slices - struct mdt_opc_slice,
88 * and stored in an array - mdt_handlers[].
91 /* The name of this handler. */
93 /* Fail id for this handler, checked at the beginning of this handler*/
95 /* Operation code for this handler */
97 /* flags are listed in enum mdt_handler_flags below. */
99 /* The actual handler function to execute. */
100 int (*mh_act)(struct mdt_thread_info *info);
101 /* Request format for this request. */
102 const struct req_format *mh_fmt;
105 enum mdt_handler_flags {
107 * struct mdt_body is passed in the incoming message, and object
108 * identified by this fid exists on disk.
110 * "habeo corpus" == "I have a body"
112 HABEO_CORPUS = (1 << 0),
114 * struct ldlm_request is passed in the incoming message.
116 * "habeo clavis" == "I have a key"
118 HABEO_CLAVIS = (1 << 1),
120 * this request has fixed reply format, so that reply message can be
121 * packed by generic code.
123 * "habeo refero" == "I have a reply"
125 HABEO_REFERO = (1 << 2),
127 * this request will modify something, so check whether the filesystem
128 * is readonly or not, then return -EROFS to client asap if necessary.
130 * "mutabor" == "I shall modify"
135 struct mdt_opc_slice {
138 struct mdt_handler *mos_hs;
141 static struct mdt_opc_slice mdt_regular_handlers[];
142 static struct mdt_opc_slice mdt_readpage_handlers[];
143 static struct mdt_opc_slice mdt_xmds_handlers[];
144 static struct mdt_opc_slice mdt_seq_handlers[];
145 static struct mdt_opc_slice mdt_fld_handlers[];
147 static struct mdt_device *mdt_dev(struct lu_device *d);
148 static int mdt_regular_handle(struct ptlrpc_request *req);
149 static int mdt_unpack_req_pack_rep(struct mdt_thread_info *info, __u32 flags);
151 static struct lu_object_operations mdt_obj_ops;
153 int mdt_get_disposition(struct ldlm_reply *rep, int flag)
157 return (rep->lock_policy_res1 & flag);
160 void mdt_clear_disposition(struct mdt_thread_info *info,
161 struct ldlm_reply *rep, int flag)
164 info->mti_opdata &= ~flag;
166 rep->lock_policy_res1 &= ~flag;
169 void mdt_set_disposition(struct mdt_thread_info *info,
170 struct ldlm_reply *rep, int flag)
173 info->mti_opdata |= flag;
175 rep->lock_policy_res1 |= flag;
178 void mdt_lock_reg_init(struct mdt_lock_handle *lh, ldlm_mode_t lm)
180 lh->mlh_pdo_hash = 0;
181 lh->mlh_reg_mode = lm;
182 lh->mlh_type = MDT_REG_LOCK;
185 void mdt_lock_pdo_init(struct mdt_lock_handle *lh, ldlm_mode_t lm,
186 const char *name, int namelen)
188 lh->mlh_reg_mode = lm;
189 lh->mlh_type = MDT_PDO_LOCK;
192 LASSERT(namelen > 0);
193 lh->mlh_pdo_hash = full_name_hash(name, namelen);
195 LASSERT(namelen == 0);
196 lh->mlh_pdo_hash = 0ull;
200 static void mdt_lock_pdo_mode(struct mdt_thread_info *info, struct mdt_object *o,
201 struct mdt_lock_handle *lh)
207 * Any dir access needs couple of locks:
209 * 1) on part of dir we gonna take lookup/modify;
211 * 2) on whole dir to protect it from concurrent splitting and/or to
212 * flush client's cache for readdir().
214 * so, for a given mode and object this routine decides what lock mode
215 * to use for lock #2:
217 * 1) if caller's gonna lookup in dir then we need to protect dir from
218 * being splitted only - LCK_CR
220 * 2) if caller's gonna modify dir then we need to protect dir from
221 * being splitted and to flush cache - LCK_CW
223 * 3) if caller's gonna modify dir and that dir seems ready for
224 * splitting then we need to protect it from any type of access
225 * (lookup/modify/split) - LCK_EX --bzzz
228 LASSERT(lh->mlh_reg_mode != LCK_MINMODE);
229 LASSERT(lh->mlh_pdo_mode == LCK_MINMODE);
232 * Ask underlaying level its opinion about preferable PDO lock mode
233 * having access type passed as regular lock mode:
235 * - MDL_MINMODE means that lower layer does not want to specify lock
238 * - MDL_NL means that no PDO lock should be taken. This is used in some
239 * cases. Say, for non-splittable directories no need to use PDO locks
242 mode = mdo_lock_mode(info->mti_env, mdt_object_child(o),
243 mdt_dlm_mode2mdl_mode(lh->mlh_reg_mode));
245 if (mode != MDL_MINMODE) {
246 lh->mlh_pdo_mode = mdt_mdl_mode2dlm_mode(mode);
249 * Lower layer does not want to specify locking mode. We do it
250 * our selves. No special protection is needed, just flush
251 * client's cache on modification and allow concurrent
254 switch (lh->mlh_reg_mode) {
256 lh->mlh_pdo_mode = LCK_EX;
259 lh->mlh_pdo_mode = LCK_CR;
262 lh->mlh_pdo_mode = LCK_CW;
265 CERROR("Not expected lock type (0x%x)\n",
266 (int)lh->mlh_reg_mode);
271 LASSERT(lh->mlh_pdo_mode != LCK_MINMODE);
275 static int mdt_getstatus(struct mdt_thread_info *info)
277 struct mdt_device *mdt = info->mti_mdt;
278 struct md_device *next = mdt->mdt_child;
279 struct mdt_body *repbody;
284 rc = mdt_check_ucred(info);
286 RETURN(err_serious(rc));
288 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_GETSTATUS_PACK))
289 RETURN(err_serious(-ENOMEM));
291 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
292 rc = next->md_ops->mdo_root_get(info->mti_env, next, &repbody->fid1);
296 repbody->valid |= OBD_MD_FLID;
298 if (mdt->mdt_opts.mo_mds_capa) {
299 struct mdt_object *root;
300 struct lustre_capa *capa;
302 root = mdt_object_find(info->mti_env, mdt, &repbody->fid1);
304 RETURN(PTR_ERR(root));
306 capa = req_capsule_server_get(info->mti_pill, &RMF_CAPA1);
308 capa->lc_opc = CAPA_OPC_MDS_DEFAULT;
310 rc = mo_capa_get(info->mti_env, mdt_object_child(root), capa,
312 mdt_object_put(info->mti_env, root);
314 repbody->valid |= OBD_MD_FLMDSCAPA;
320 static int mdt_statfs(struct mdt_thread_info *info)
322 struct md_device *next = info->mti_mdt->mdt_child;
323 struct obd_statfs *osfs;
328 /* This will trigger a watchdog timeout */
329 OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_STATFS_LCW_SLEEP,
330 (MDT_SERVICE_WATCHDOG_TIMEOUT / 1000) + 1);
332 rc = mdt_check_ucred(info);
334 RETURN(err_serious(rc));
336 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_STATFS_PACK)) {
337 rc = err_serious(-ENOMEM);
339 osfs = req_capsule_server_get(info->mti_pill, &RMF_OBD_STATFS);
340 rc = next->md_ops->mdo_statfs(info->mti_env, next,
342 statfs_pack(osfs, &info->mti_u.ksfs);
347 void mdt_pack_size2body(struct mdt_thread_info *info, struct mdt_object *o)
350 struct lu_attr *attr = &info->mti_attr.ma_attr;
352 b = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
354 /* Check if Size-on-MDS is enabled. */
355 if ((mdt_conn_flags(info) & OBD_CONNECT_SOM) &&
356 S_ISREG(attr->la_mode) && mdt_sizeonmds_enabled(o)) {
357 b->valid |= (OBD_MD_FLSIZE | OBD_MD_FLBLOCKS);
358 b->size = attr->la_size;
359 b->blocks = attr->la_blocks;
363 void mdt_pack_attr2body(struct mdt_thread_info *info, struct mdt_body *b,
364 const struct lu_attr *attr, const struct lu_fid *fid)
366 /*XXX should pack the reply body according to lu_valid*/
367 b->valid |= OBD_MD_FLCTIME | OBD_MD_FLUID |
368 OBD_MD_FLGID | OBD_MD_FLTYPE |
369 OBD_MD_FLMODE | OBD_MD_FLNLINK | OBD_MD_FLFLAGS |
370 OBD_MD_FLATIME | OBD_MD_FLMTIME ;
372 if (!S_ISREG(attr->la_mode))
373 b->valid |= OBD_MD_FLSIZE | OBD_MD_FLBLOCKS | OBD_MD_FLRDEV;
375 b->atime = attr->la_atime;
376 b->mtime = attr->la_mtime;
377 b->ctime = attr->la_ctime;
378 b->mode = attr->la_mode;
379 b->size = attr->la_size;
380 b->blocks = attr->la_blocks;
381 b->uid = attr->la_uid;
382 b->gid = attr->la_gid;
383 b->flags = attr->la_flags;
384 b->nlink = attr->la_nlink;
385 b->rdev = attr->la_rdev;
389 b->valid |= OBD_MD_FLID;
391 /* FIXME: these should be fixed when new igif ready.*/
392 b->ino = fid_oid(fid); /* 1.6 compatibility */
393 b->generation = fid_ver(fid); /* 1.6 compatibility */
394 b->valid |= OBD_MD_FLGENER; /* 1.6 compatibility */
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);
404 static inline int mdt_body_has_lov(const struct lu_attr *la,
405 const struct mdt_body *body)
407 return ((S_ISREG(la->la_mode) && (body->valid & OBD_MD_FLEASIZE)) ||
408 (S_ISDIR(la->la_mode) && (body->valid & OBD_MD_FLDIREA )) );
411 static int mdt_getattr_internal(struct mdt_thread_info *info,
412 struct mdt_object *o)
414 struct md_object *next = mdt_object_child(o);
415 const struct mdt_body *reqbody = info->mti_body;
416 struct ptlrpc_request *req = mdt_info_req(info);
417 struct mdt_export_data *med = &req->rq_export->exp_mdt_data;
418 struct md_attr *ma = &info->mti_attr;
419 struct lu_attr *la = &ma->ma_attr;
420 struct req_capsule *pill = info->mti_pill;
421 const struct lu_env *env = info->mti_env;
422 struct mdt_body *repbody;
423 struct lu_buf *buffer = &info->mti_buf;
427 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_GETATTR_PACK))
428 RETURN(err_serious(-ENOMEM));
430 repbody = req_capsule_server_get(pill, &RMF_MDT_BODY);
434 rc = mdt_object_exists(o);
436 /* This object is located on remote node.*/
437 repbody->fid1 = *mdt_object_fid(o);
438 repbody->valid = OBD_MD_FLID | OBD_MD_MDS;
442 buffer->lb_buf = req_capsule_server_get(pill, &RMF_MDT_MD);
443 buffer->lb_len = req_capsule_get_size(pill, &RMF_MDT_MD, RCL_SERVER);
445 /* If it is dir object and client require MEA, then we got MEA */
446 if (S_ISDIR(lu_object_attr(&next->mo_lu)) &&
447 reqbody->valid & OBD_MD_MEA) {
448 /* Assumption: MDT_MD size is enough for lmv size. */
449 ma->ma_lmv = buffer->lb_buf;
450 ma->ma_lmv_size = buffer->lb_len;
451 ma->ma_need = MA_LMV | MA_INODE;
453 ma->ma_lmm = buffer->lb_buf;
454 ma->ma_lmm_size = buffer->lb_len;
455 ma->ma_need = MA_LOV | MA_INODE;
458 if (S_ISDIR(lu_object_attr(&next->mo_lu)) &&
459 reqbody->valid & OBD_MD_FLDIREA &&
460 lustre_msg_get_opc(req->rq_reqmsg) == MDS_GETATTR) {
461 /* get default stripe info for this dir. */
462 ma->ma_need |= MA_LOV_DEF;
464 rc = mo_attr_get(env, next, ma);
466 CERROR("getattr error for "DFID": %d\n",
467 PFID(mdt_object_fid(o)), rc);
471 if (likely(ma->ma_valid & MA_INODE))
472 mdt_pack_attr2body(info, repbody, la, mdt_object_fid(o));
476 if (mdt_body_has_lov(la, reqbody)) {
477 if (ma->ma_valid & MA_LOV) {
478 LASSERT(ma->ma_lmm_size);
479 mdt_dump_lmm(D_INFO, ma->ma_lmm);
480 repbody->eadatasize = ma->ma_lmm_size;
481 if (S_ISDIR(la->la_mode))
482 repbody->valid |= OBD_MD_FLDIREA;
484 repbody->valid |= OBD_MD_FLEASIZE;
486 if (ma->ma_valid & MA_LMV) {
487 LASSERT(S_ISDIR(la->la_mode));
488 repbody->eadatasize = ma->ma_lmv_size;
489 repbody->valid |= (OBD_MD_FLDIREA|OBD_MD_MEA);
491 if (!(ma->ma_valid & MA_LOV) && !(ma->ma_valid & MA_LMV)) {
492 repbody->valid |= OBD_MD_FLSIZE | OBD_MD_FLBLOCKS;
494 } else if (S_ISLNK(la->la_mode) &&
495 reqbody->valid & OBD_MD_LINKNAME) {
496 buffer->lb_buf = ma->ma_lmm;
497 buffer->lb_len = reqbody->eadatasize;
498 rc = mo_readlink(env, next, buffer);
499 if (unlikely(rc <= 0)) {
500 CERROR("readlink failed: %d\n", rc);
503 repbody->valid |= OBD_MD_LINKNAME;
504 repbody->eadatasize = rc;
506 ((char*)ma->ma_lmm)[rc - 1] = 0;
507 CDEBUG(D_INODE, "symlink dest %s, len = %d\n",
508 (char*)ma->ma_lmm, rc);
513 if (reqbody->valid & OBD_MD_FLMODEASIZE) {
514 repbody->max_cookiesize = info->mti_mdt->mdt_max_cookiesize;
515 repbody->max_mdsize = info->mti_mdt->mdt_max_mdsize;
516 repbody->valid |= OBD_MD_FLMODEASIZE;
517 CDEBUG(D_INODE, "I am going to change the MAX_MD_SIZE & "
518 "MAX_COOKIE to : %d:%d\n", repbody->max_mdsize,
519 repbody->max_cookiesize);
522 if (med->med_rmtclient && (reqbody->valid & OBD_MD_FLRMTPERM)) {
523 void *buf = req_capsule_server_get(pill, &RMF_ACL);
525 /* mdt_getattr_lock only */
526 rc = mdt_pack_remote_perm(info, o, buf);
528 repbody->valid &= ~OBD_MD_FLRMTPERM;
529 repbody->aclsize = 0;
532 repbody->valid |= OBD_MD_FLRMTPERM;
533 repbody->aclsize = sizeof(struct mdt_remote_perm);
536 #ifdef CONFIG_FS_POSIX_ACL
537 else if ((req->rq_export->exp_connect_flags & OBD_CONNECT_ACL) &&
538 (reqbody->valid & OBD_MD_FLACL)) {
539 buffer->lb_buf = req_capsule_server_get(pill, &RMF_ACL);
540 buffer->lb_len = req_capsule_get_size(pill,
541 &RMF_ACL, RCL_SERVER);
542 if (buffer->lb_len > 0) {
543 rc = mo_xattr_get(env, next, buffer,
544 XATTR_NAME_ACL_ACCESS);
546 if (rc == -ENODATA) {
547 repbody->aclsize = 0;
548 repbody->valid |= OBD_MD_FLACL;
550 } else if (rc == -EOPNOTSUPP) {
553 CERROR("got acl size: %d\n", rc);
556 repbody->aclsize = rc;
557 repbody->valid |= OBD_MD_FLACL;
564 if ((reqbody->valid & OBD_MD_FLMDSCAPA) &&
565 info->mti_mdt->mdt_opts.mo_mds_capa) {
566 struct lustre_capa *capa;
568 capa = req_capsule_server_get(pill, &RMF_CAPA1);
570 capa->lc_opc = CAPA_OPC_MDS_DEFAULT;
571 rc = mo_capa_get(env, next, capa, 0);
574 repbody->valid |= OBD_MD_FLMDSCAPA;
579 static int mdt_renew_capa(struct mdt_thread_info *info)
581 struct mdt_device *mdt = info->mti_mdt;
582 struct mdt_object *obj = info->mti_object;
583 struct mdt_body *body;
584 struct lustre_capa *capa, *c;
588 /* if object doesn't exist, or server has disabled capability,
589 * return directly, client will find body->valid OBD_MD_FLOSSCAPA
592 if (!obj || !mdt->mdt_opts.mo_mds_capa)
595 body = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
596 LASSERT(body != NULL);
598 c = req_capsule_client_get(info->mti_pill, &RMF_CAPA1);
601 capa = req_capsule_server_get(info->mti_pill, &RMF_CAPA2);
605 rc = mo_capa_get(info->mti_env, mdt_object_child(obj), capa, 1);
607 body->valid |= OBD_MD_FLOSSCAPA;
611 static int mdt_getattr(struct mdt_thread_info *info)
613 struct mdt_object *obj = info->mti_object;
614 struct req_capsule *pill = info->mti_pill;
615 struct mdt_body *reqbody;
616 struct mdt_body *repbody;
622 reqbody = req_capsule_client_get(pill, &RMF_MDT_BODY);
625 if (reqbody->valid & OBD_MD_FLOSSCAPA) {
626 rc = req_capsule_server_pack(pill);
628 RETURN(err_serious(rc));
629 rc = mdt_renew_capa(info);
630 GOTO(out_shrink, rc);
633 LASSERT(obj != NULL);
634 LASSERT(lu_object_assert_exists(&obj->mot_obj.mo_lu));
636 mode = lu_object_attr(&obj->mot_obj.mo_lu);
637 if (S_ISLNK(mode) && (reqbody->valid & OBD_MD_LINKNAME) &&
638 (reqbody->eadatasize > info->mti_mdt->mdt_max_mdsize))
639 md_size = reqbody->eadatasize;
641 md_size = info->mti_mdt->mdt_max_mdsize;
643 req_capsule_set_size(pill, &RMF_MDT_MD, RCL_SERVER, md_size);
645 rc = req_capsule_server_pack(pill);
646 if (unlikely(rc != 0))
647 RETURN(err_serious(rc));
649 repbody = req_capsule_server_get(pill, &RMF_MDT_BODY);
650 LASSERT(repbody != NULL);
651 repbody->eadatasize = 0;
652 repbody->aclsize = 0;
654 if (reqbody->valid & OBD_MD_FLRMTPERM)
655 rc = mdt_init_ucred(info, reqbody);
657 rc = mdt_check_ucred(info);
659 GOTO(out_shrink, rc);
661 info->mti_spec.sp_ck_split = !!(reqbody->valid & OBD_MD_FLCKSPLIT);
662 info->mti_cross_ref = !!(reqbody->valid & OBD_MD_FLCROSSREF);
665 * Don't check capability at all, because rename might getattr for
666 * remote obj, and at that time no capability is available.
668 mdt_set_capainfo(info, 1, &reqbody->fid1, BYPASS_CAPA);
669 rc = mdt_getattr_internal(info, obj);
670 if (reqbody->valid & OBD_MD_FLRMTPERM)
671 mdt_exit_ucred(info);
674 mdt_shrink_reply(info);
678 static int mdt_is_subdir(struct mdt_thread_info *info)
680 struct mdt_object *o = info->mti_object;
681 struct req_capsule *pill = info->mti_pill;
682 const struct mdt_body *body = info->mti_body;
683 struct mdt_body *repbody;
689 repbody = req_capsule_server_get(pill, &RMF_MDT_BODY);
692 * We save last checked parent fid to @repbody->fid1 for remote
695 LASSERT(fid_is_sane(&body->fid2));
696 LASSERT(mdt_object_exists(o) > 0);
697 rc = mdo_is_subdir(info->mti_env, mdt_object_child(o),
698 &body->fid2, &repbody->fid1);
699 if (rc == 0 || rc == -EREMOTE)
700 repbody->valid |= OBD_MD_FLID;
705 static int mdt_raw_lookup(struct mdt_thread_info *info,
706 struct mdt_object *parent,
707 const struct lu_name *lname,
708 struct ldlm_reply *ldlm_rep)
710 struct md_object *next = mdt_object_child(info->mti_object);
711 const struct mdt_body *reqbody = info->mti_body;
712 struct lu_fid *child_fid = &info->mti_tmp_fid1;
713 struct mdt_body *repbody;
717 if (reqbody->valid != OBD_MD_FLID)
720 LASSERT(!info->mti_cross_ref);
722 /* Only got the fid of this obj by name */
723 rc = mdo_lookup(info->mti_env, next, lname, child_fid,
726 /* XXX is raw_lookup possible as intent operation? */
729 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_NEG);
732 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_POS);
734 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
737 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
738 repbody->fid1 = *child_fid;
739 repbody->valid = OBD_MD_FLID;
745 * UPDATE lock should be taken against parent, and be release before exit;
746 * child_bits lock should be taken against child, and be returned back:
747 * (1)normal request should release the child lock;
748 * (2)intent request will grant the lock to client.
750 static int mdt_getattr_name_lock(struct mdt_thread_info *info,
751 struct mdt_lock_handle *lhc,
753 struct ldlm_reply *ldlm_rep)
755 struct ptlrpc_request *req = mdt_info_req(info);
756 struct mdt_body *reqbody = NULL;
757 struct mdt_object *parent = info->mti_object;
758 struct mdt_object *child;
759 struct md_object *next = mdt_object_child(parent);
760 struct lu_fid *child_fid = &info->mti_tmp_fid1;
761 struct lu_name *lname = NULL;
764 struct mdt_lock_handle *lhp;
765 struct ldlm_lock *lock;
766 struct ldlm_res_id *res_id;
772 is_resent = lustre_handle_is_used(&lhc->mlh_reg_lh);
773 LASSERT(ergo(is_resent,
774 lustre_msg_get_flags(req->rq_reqmsg) & MSG_RESENT));
776 LASSERT(parent != NULL);
777 name = req_capsule_client_get(info->mti_pill, &RMF_NAME);
779 RETURN(err_serious(-EFAULT));
781 namelen = req_capsule_get_size(info->mti_pill, &RMF_NAME,
783 LASSERT(namelen >= 0);
785 /* XXX: "namelen == 0" is for getattr by fid (OBD_CONNECT_ATTRFID),
786 * otherwise do not allow empty name, that is the name must contain
787 * at least one character and the terminating '\0'*/
789 reqbody =req_capsule_client_get(info->mti_pill, &RMF_MDT_BODY);
790 LASSERT(fid_is_sane(&reqbody->fid2));
793 CDEBUG(D_INODE, "getattr with lock for "DFID"/"DFID", "
795 PFID(mdt_object_fid(parent)), PFID(&reqbody->fid2),
798 lname = mdt_name(info->mti_env, (char *)name, namelen);
799 CDEBUG(D_INODE, "getattr with lock for "DFID"/%s, "
801 PFID(mdt_object_fid(parent)), name, ldlm_rep);
804 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_EXECD);
806 rc = mdt_object_exists(parent);
807 if (unlikely(rc == 0)) {
808 LU_OBJECT_DEBUG(D_WARNING, info->mti_env,
809 &parent->mot_obj.mo_lu,
810 "Parent doesn't exist!\n");
813 LASSERTF(rc > 0, "Parent "DFID" is on remote server\n",
814 PFID(mdt_object_fid(parent)));
817 rc = mdt_raw_lookup(info, parent, lname, ldlm_rep);
825 if (info->mti_cross_ref) {
826 /* Only getattr on the child. Parent is on another node. */
827 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_POS);
829 CDEBUG(D_INODE, "partial getattr_name child_fid = "DFID", "
830 "ldlm_rep=%p\n", PFID(mdt_object_fid(child)), ldlm_rep);
833 /* Do not take lock for resent case. */
834 lock = ldlm_handle2lock(&lhc->mlh_reg_lh);
835 LASSERTF(lock != NULL, "Invalid lock handle "LPX64"\n",
836 lhc->mlh_reg_lh.cookie);
837 LASSERT(fid_res_name_eq(mdt_object_fid(child),
838 &lock->l_resource->lr_name));
842 mdt_lock_handle_init(lhc);
843 mdt_lock_reg_init(lhc, LCK_PR);
846 * Object's name is on another MDS, no lookup lock is
847 * needed here but update is.
849 child_bits &= ~MDS_INODELOCK_LOOKUP;
850 child_bits |= MDS_INODELOCK_UPDATE;
852 rc = mdt_object_lock(info, child, lhc, child_bits,
856 /* Finally, we can get attr for child. */
857 mdt_set_capainfo(info, 0, mdt_object_fid(child),
859 rc = mdt_getattr_internal(info, child);
860 if (unlikely(rc != 0))
861 mdt_object_unlock(info, child, lhc, 1);
866 /* step 1: lock parent */
867 lhp = &info->mti_lh[MDT_LH_PARENT];
868 mdt_lock_pdo_init(lhp, LCK_PR, name, namelen);
869 rc = mdt_object_lock(info, parent, lhp, MDS_INODELOCK_UPDATE,
872 if (unlikely(rc != 0))
876 /* step 2: lookup child's fid by name */
877 rc = mdo_lookup(info->mti_env, next, lname, child_fid,
882 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_NEG);
883 GOTO(out_parent, rc);
885 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_POS);
887 *child_fid = reqbody->fid2;
888 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_POS);
892 *step 3: find the child object by fid & lock it.
893 * regardless if it is local or remote.
895 child = mdt_object_find(info->mti_env, info->mti_mdt, child_fid);
897 if (unlikely(IS_ERR(child)))
898 GOTO(out_parent, rc = PTR_ERR(child));
900 /* Do not take lock for resent case. */
901 lock = ldlm_handle2lock(&lhc->mlh_reg_lh);
902 LASSERTF(lock != NULL, "Invalid lock handle "LPX64"\n",
903 lhc->mlh_reg_lh.cookie);
905 res_id = &lock->l_resource->lr_name;
906 if (!fid_res_name_eq(mdt_object_fid(child),
907 &lock->l_resource->lr_name)) {
908 LASSERTF(fid_res_name_eq(mdt_object_fid(parent),
909 &lock->l_resource->lr_name),
910 "Lock res_id: %lu/%lu/%lu, Fid: "DFID".\n",
911 (unsigned long)res_id->name[0],
912 (unsigned long)res_id->name[1],
913 (unsigned long)res_id->name[2],
914 PFID(mdt_object_fid(parent)));
915 CWARN("Although resent, but still not get child lock"
916 "parent:"DFID" child:"DFID"\n",
917 PFID(mdt_object_fid(parent)),
918 PFID(mdt_object_fid(child)));
919 lustre_msg_clear_flags(req->rq_reqmsg, MSG_RESENT);
926 struct md_attr *ma = &info->mti_attr;
928 mdt_lock_handle_init(lhc);
929 mdt_lock_reg_init(lhc, LCK_PR);
931 if (mdt_object_exists(child) == 0) {
932 LU_OBJECT_DEBUG(D_WARNING, info->mti_env,
933 &child->mot_obj.mo_lu,
934 "Object doesn't exist!\n");
938 ma->ma_need = MA_INODE;
939 rc = mo_attr_get(info->mti_env, next, ma);
940 if (unlikely(rc != 0))
943 /* If the file has not been changed for some time, we return
944 * not only a LOOKUP lock, but also an UPDATE lock and this
945 * might save us RPC on later STAT. For directories, it also
946 * let negative dentry starts working for this dir. */
947 if (ma->ma_valid & MA_INODE &&
948 ma->ma_attr.la_valid & LA_CTIME &&
949 info->mti_mdt->mdt_namespace->ns_ctime_age_limit +
950 ma->ma_attr.la_ctime < cfs_time_current_sec())
951 child_bits |= MDS_INODELOCK_UPDATE;
953 rc = mdt_object_lock(info, child, lhc, child_bits,
956 if (unlikely(rc != 0))
960 /* finally, we can get attr for child. */
961 mdt_set_capainfo(info, 1, child_fid, BYPASS_CAPA);
962 rc = mdt_getattr_internal(info, child);
963 if (unlikely(rc != 0)) {
964 mdt_object_unlock(info, child, lhc, 1);
966 lock = ldlm_handle2lock(&lhc->mlh_reg_lh);
968 struct mdt_body *repbody;
971 /* Debugging code. */
972 res_id = &lock->l_resource->lr_name;
973 LDLM_DEBUG(lock, "Returning lock to client\n");
974 LASSERTF(fid_res_name_eq(mdt_object_fid(child),
975 &lock->l_resource->lr_name),
976 "Lock res_id: %lu/%lu/%lu, Fid: "DFID".\n",
977 (unsigned long)res_id->name[0],
978 (unsigned long)res_id->name[1],
979 (unsigned long)res_id->name[2],
980 PFID(mdt_object_fid(child)));
982 * Pack Size-on-MDS inode attributes to the body if
983 * update lock is given.
985 repbody = req_capsule_server_get(info->mti_pill,
987 ma = &info->mti_attr.ma_attr;
988 if (lock->l_policy_data.l_inodebits.bits &
989 MDS_INODELOCK_UPDATE)
990 mdt_pack_size2body(info, child);
996 mdt_object_put(info->mti_env, child);
998 mdt_object_unlock(info, parent, lhp, 1);
1002 /* normal handler: should release the child lock */
1003 static int mdt_getattr_name(struct mdt_thread_info *info)
1005 struct mdt_lock_handle *lhc = &info->mti_lh[MDT_LH_CHILD];
1006 struct mdt_body *reqbody;
1007 struct mdt_body *repbody;
1011 reqbody = req_capsule_client_get(info->mti_pill, &RMF_MDT_BODY);
1012 LASSERT(reqbody != NULL);
1013 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
1014 LASSERT(repbody != NULL);
1016 info->mti_spec.sp_ck_split = !!(reqbody->valid & OBD_MD_FLCKSPLIT);
1017 info->mti_cross_ref = !!(reqbody->valid & OBD_MD_FLCROSSREF);
1018 repbody->eadatasize = 0;
1019 repbody->aclsize = 0;
1021 rc = mdt_init_ucred(info, reqbody);
1023 GOTO(out_shrink, rc);
1025 rc = mdt_getattr_name_lock(info, lhc, MDS_INODELOCK_UPDATE, NULL);
1026 if (lustre_handle_is_used(&lhc->mlh_reg_lh)) {
1027 ldlm_lock_decref(&lhc->mlh_reg_lh, lhc->mlh_reg_mode);
1028 lhc->mlh_reg_lh.cookie = 0;
1030 mdt_exit_ucred(info);
1033 mdt_shrink_reply(info);
1037 static struct lu_device_operations mdt_lu_ops;
1039 static int lu_device_is_mdt(struct lu_device *d)
1041 return ergo(d != NULL && d->ld_ops != NULL, d->ld_ops == &mdt_lu_ops);
1044 static int mdt_set_info(struct mdt_thread_info *info)
1046 struct ptlrpc_request *req = mdt_info_req(info);
1052 rc = req_capsule_server_pack(info->mti_pill);
1056 key = req_capsule_client_get(info->mti_pill, &RMF_SETINFO_KEY);
1058 DEBUG_REQ(D_HA, req, "no set_info key");
1062 keylen = req_capsule_get_size(info->mti_pill, &RMF_SETINFO_KEY,
1065 val = req_capsule_client_get(info->mti_pill, &RMF_SETINFO_VAL);
1067 DEBUG_REQ(D_HA, req, "no set_info val");
1071 if (keylen != (sizeof(KEY_READ_ONLY) - 1) ||
1072 memcmp(key, KEY_READ_ONLY, keylen) != 0)
1076 lustre_msg_set_status(req->rq_repmsg, 0);
1078 spin_lock(&req->rq_export->exp_lock);
1080 req->rq_export->exp_connect_flags |= OBD_CONNECT_RDONLY;
1082 req->rq_export->exp_connect_flags &= ~OBD_CONNECT_RDONLY;
1083 spin_unlock(&req->rq_export->exp_lock);
1088 static int mdt_connect(struct mdt_thread_info *info)
1091 struct ptlrpc_request *req;
1093 req = mdt_info_req(info);
1094 rc = target_handle_connect(req);
1096 LASSERT(req->rq_export != NULL);
1097 info->mti_mdt = mdt_dev(req->rq_export->exp_obd->obd_lu_dev);
1098 rc = mdt_init_idmap(info);
1100 /* if mdt_init_idmap failed, revocation for connect */
1101 obd_disconnect(class_export_get(req->rq_export));
1103 rc = err_serious(rc);
1107 static int mdt_disconnect(struct mdt_thread_info *info)
1112 rc = target_handle_disconnect(mdt_info_req(info));
1114 rc = err_serious(rc);
1118 static int mdt_sendpage(struct mdt_thread_info *info,
1119 struct lu_rdpg *rdpg)
1121 struct ptlrpc_request *req = mdt_info_req(info);
1122 struct ptlrpc_bulk_desc *desc;
1123 struct l_wait_info *lwi = &info->mti_u.rdpg.mti_wait_info;
1130 desc = ptlrpc_prep_bulk_exp(req, rdpg->rp_npages, BULK_PUT_SOURCE,
1135 for (i = 0, tmpcount = rdpg->rp_count;
1136 i < rdpg->rp_npages; i++, tmpcount -= tmpsize) {
1137 tmpsize = min_t(int, tmpcount, CFS_PAGE_SIZE);
1138 ptlrpc_prep_bulk_page(desc, rdpg->rp_pages[i], 0, tmpsize);
1141 LASSERT(desc->bd_nob == rdpg->rp_count);
1142 rc = ptlrpc_start_bulk_transfer(desc);
1144 GOTO(free_desc, rc);
1146 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_SENDPAGE))
1147 GOTO(abort_bulk, rc = 0);
1149 *lwi = LWI_TIMEOUT(obd_timeout * HZ / 4, NULL, NULL);
1150 rc = l_wait_event(desc->bd_waitq, !ptlrpc_bulk_active(desc), lwi);
1151 LASSERT (rc == 0 || rc == -ETIMEDOUT);
1154 if (desc->bd_success &&
1155 desc->bd_nob_transferred == rdpg->rp_count)
1156 GOTO(free_desc, rc);
1158 rc = -ETIMEDOUT; /* XXX should this be a different errno? */
1161 DEBUG_REQ(D_ERROR, req, "bulk failed: %s %d(%d), evicting %s@%s",
1162 (rc == -ETIMEDOUT) ? "timeout" : "network error",
1163 desc->bd_nob_transferred, rdpg->rp_count,
1164 req->rq_export->exp_client_uuid.uuid,
1165 req->rq_export->exp_connection->c_remote_uuid.uuid);
1167 class_fail_export(req->rq_export);
1171 ptlrpc_abort_bulk(desc);
1173 ptlrpc_free_bulk(desc);
1177 #ifdef HAVE_SPLIT_SUPPORT
1179 * Retrieve dir entry from the page and insert it to the slave object, actually,
1180 * this should be in osd layer, but since it will not in the final product, so
1181 * just do it here and do not define more moo api anymore for this.
1183 static int mdt_write_dir_page(struct mdt_thread_info *info, struct page *page,
1186 struct mdt_object *object = info->mti_object;
1187 struct lu_fid *lf = &info->mti_tmp_fid2;
1188 struct md_attr *ma = &info->mti_attr;
1189 struct lu_dirpage *dp;
1190 struct lu_dirent *ent;
1191 int rc = 0, offset = 0;
1194 /* Make sure we have at least one entry. */
1199 * Disable trans for this name insert, since it will include many trans
1202 info->mti_no_need_trans = 1;
1204 * When write_dir_page, no need update parent's ctime,
1205 * and no permission check for name_insert.
1207 ma->ma_attr.la_ctime = 0;
1208 ma->ma_attr.la_valid = LA_MODE;
1209 ma->ma_valid = MA_INODE;
1212 dp = page_address(page);
1213 offset = (int)((__u32)lu_dirent_start(dp) - (__u32)dp);
1215 for (ent = lu_dirent_start(dp); ent != NULL;
1216 ent = lu_dirent_next(ent)) {
1217 struct lu_name *lname;
1220 if (le16_to_cpu(ent->lde_namelen) == 0)
1223 fid_le_to_cpu(lf, &ent->lde_fid);
1224 if (le32_to_cpu(ent->lde_hash) & MAX_HASH_HIGHEST_BIT)
1225 ma->ma_attr.la_mode = S_IFDIR;
1227 ma->ma_attr.la_mode = 0;
1228 OBD_ALLOC(name, le16_to_cpu(ent->lde_namelen) + 1);
1230 GOTO(out, rc = -ENOMEM);
1232 memcpy(name, ent->lde_name, le16_to_cpu(ent->lde_namelen));
1233 lname = mdt_name(info->mti_env, name,
1234 le16_to_cpu(ent->lde_namelen) + 1);
1235 ma->ma_attr_flags |= MDS_PERM_BYPASS;
1236 rc = mdo_name_insert(info->mti_env,
1237 md_object_next(&object->mot_obj),
1239 OBD_FREE(name, le16_to_cpu(ent->lde_namelen) + 1);
1241 CERROR("Can't insert %*.*s, rc %d\n",
1242 le16_to_cpu(ent->lde_namelen),
1243 le16_to_cpu(ent->lde_namelen),
1248 offset += lu_dirent_size(ent);
1258 static int mdt_bulk_timeout(void *data)
1262 CERROR("mdt bulk transfer timeout \n");
1267 static int mdt_writepage(struct mdt_thread_info *info)
1269 struct ptlrpc_request *req = mdt_info_req(info);
1270 struct mdt_body *reqbody;
1271 struct l_wait_info *lwi;
1272 struct ptlrpc_bulk_desc *desc;
1278 reqbody = req_capsule_client_get(info->mti_pill, &RMF_MDT_BODY);
1279 if (reqbody == NULL)
1280 RETURN(err_serious(-EFAULT));
1282 desc = ptlrpc_prep_bulk_exp(req, 1, BULK_GET_SINK, MDS_BULK_PORTAL);
1284 RETURN(err_serious(-ENOMEM));
1286 /* allocate the page for the desc */
1287 page = cfs_alloc_page(CFS_ALLOC_STD);
1289 GOTO(desc_cleanup, rc = -ENOMEM);
1291 CDEBUG(D_INFO, "Received page offset %d size %d \n",
1292 (int)reqbody->size, (int)reqbody->nlink);
1294 ptlrpc_prep_bulk_page(desc, page, (int)reqbody->size,
1295 (int)reqbody->nlink);
1298 * Check if client was evicted while we were doing i/o before touching
1303 GOTO(cleanup_page, rc = -ENOMEM);
1305 if (desc->bd_export->exp_failed)
1308 rc = ptlrpc_start_bulk_transfer (desc);
1310 *lwi = LWI_TIMEOUT_INTERVAL(obd_timeout * HZ / 4, HZ,
1311 mdt_bulk_timeout, desc);
1312 rc = l_wait_event(desc->bd_waitq, !ptlrpc_bulk_active(desc) ||
1313 desc->bd_export->exp_failed, lwi);
1314 LASSERT(rc == 0 || rc == -ETIMEDOUT);
1315 if (rc == -ETIMEDOUT) {
1316 DEBUG_REQ(D_ERROR, req, "timeout on bulk GET");
1317 ptlrpc_abort_bulk(desc);
1318 } else if (desc->bd_export->exp_failed) {
1319 DEBUG_REQ(D_ERROR, req, "Eviction on bulk GET");
1321 ptlrpc_abort_bulk(desc);
1322 } else if (!desc->bd_success ||
1323 desc->bd_nob_transferred != desc->bd_nob) {
1324 DEBUG_REQ(D_ERROR, req, "%s bulk GET %d(%d)",
1326 "truncated" : "network error on",
1327 desc->bd_nob_transferred, desc->bd_nob);
1328 /* XXX should this be a different errno? */
1332 DEBUG_REQ(D_ERROR, req, "ptlrpc_bulk_get failed: rc %d", rc);
1335 GOTO(cleanup_lwi, rc);
1336 rc = mdt_write_dir_page(info, page, reqbody->nlink);
1341 cfs_free_page(page);
1343 ptlrpc_free_bulk(desc);
1348 static int mdt_readpage(struct mdt_thread_info *info)
1350 struct mdt_object *object = info->mti_object;
1351 struct lu_rdpg *rdpg = &info->mti_u.rdpg.mti_rdpg;
1352 struct mdt_body *reqbody;
1353 struct mdt_body *repbody;
1358 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_READPAGE_PACK))
1359 RETURN(err_serious(-ENOMEM));
1361 reqbody = req_capsule_client_get(info->mti_pill, &RMF_MDT_BODY);
1362 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
1363 if (reqbody == NULL || repbody == NULL)
1364 RETURN(err_serious(-EFAULT));
1367 * prepare @rdpg before calling lower layers and transfer itself. Here
1368 * reqbody->size contains offset of where to start to read and
1369 * reqbody->nlink contains number bytes to read.
1371 rdpg->rp_hash = reqbody->size;
1372 if ((__u64)rdpg->rp_hash != reqbody->size) {
1373 CERROR("Invalid hash: %#llx != %#llx\n",
1374 (__u64)rdpg->rp_hash, reqbody->size);
1377 rdpg->rp_count = reqbody->nlink;
1378 rdpg->rp_npages = (rdpg->rp_count + CFS_PAGE_SIZE - 1)>>CFS_PAGE_SHIFT;
1379 OBD_ALLOC(rdpg->rp_pages, rdpg->rp_npages * sizeof rdpg->rp_pages[0]);
1380 if (rdpg->rp_pages == NULL)
1383 for (i = 0; i < rdpg->rp_npages; ++i) {
1384 rdpg->rp_pages[i] = cfs_alloc_page(CFS_ALLOC_STD);
1385 if (rdpg->rp_pages[i] == NULL)
1386 GOTO(free_rdpg, rc = -ENOMEM);
1389 /* call lower layers to fill allocated pages with directory data */
1390 rc = mo_readpage(info->mti_env, mdt_object_child(object), rdpg);
1392 GOTO(free_rdpg, rc);
1394 /* send pages to client */
1395 rc = mdt_sendpage(info, rdpg);
1400 for (i = 0; i < rdpg->rp_npages; i++)
1401 if (rdpg->rp_pages[i] != NULL)
1402 cfs_free_page(rdpg->rp_pages[i]);
1403 OBD_FREE(rdpg->rp_pages, rdpg->rp_npages * sizeof rdpg->rp_pages[0]);
1405 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_SENDPAGE))
1411 static int mdt_reint_internal(struct mdt_thread_info *info,
1412 struct mdt_lock_handle *lhc,
1415 struct req_capsule *pill = info->mti_pill;
1416 struct mdt_device *mdt = info->mti_mdt;
1417 struct mdt_body *repbody;
1422 if (req_capsule_has_field(pill, &RMF_MDT_MD, RCL_SERVER))
1423 req_capsule_set_size(pill, &RMF_MDT_MD, RCL_SERVER,
1424 mdt->mdt_max_mdsize);
1425 if (req_capsule_has_field(pill, &RMF_LOGCOOKIES, RCL_SERVER))
1426 req_capsule_set_size(pill, &RMF_LOGCOOKIES, RCL_SERVER,
1427 mdt->mdt_max_cookiesize);
1429 rc = req_capsule_server_pack(pill);
1431 CERROR("Can't pack response, rc %d\n", rc);
1432 RETURN(err_serious(rc));
1435 if (req_capsule_has_field(pill, &RMF_MDT_BODY, RCL_SERVER)) {
1436 repbody = req_capsule_server_get(pill, &RMF_MDT_BODY);
1438 repbody->eadatasize = 0;
1439 repbody->aclsize = 0;
1442 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_REINT_UNPACK))
1443 GOTO(out_shrink, rc = err_serious(-EFAULT));
1445 rc = mdt_reint_unpack(info, op);
1447 CERROR("Can't unpack reint, rc %d\n", rc);
1448 GOTO(out_shrink, rc = err_serious(rc));
1451 rc = mdt_init_ucred_reint(info);
1453 GOTO(out_shrink, rc);
1455 rc = mdt_fix_attr_ucred(info, op);
1457 GOTO(out_ucred, rc = err_serious(rc));
1459 if (mdt_check_resent(info, mdt_reconstruct, lhc)) {
1460 rc = lustre_msg_get_status(mdt_info_req(info)->rq_repmsg);
1461 GOTO(out_ucred, rc);
1463 rc = mdt_reint_rec(info, lhc);
1466 mdt_exit_ucred(info);
1468 mdt_shrink_reply(info);
1472 static long mdt_reint_opcode(struct mdt_thread_info *info,
1473 const struct req_format **fmt)
1475 struct mdt_rec_reint *rec;
1478 opc = err_serious(-EFAULT);
1479 rec = req_capsule_client_get(info->mti_pill, &RMF_REC_REINT);
1481 opc = rec->rr_opcode;
1482 DEBUG_REQ(D_INODE, mdt_info_req(info), "reint opt = %ld", opc);
1483 if (opc < REINT_MAX && fmt[opc] != NULL)
1484 req_capsule_extend(info->mti_pill, fmt[opc]);
1486 CERROR("Unsupported opc: %ld\n", opc);
1487 opc = err_serious(opc);
1493 static int mdt_reint(struct mdt_thread_info *info)
1498 static const struct req_format *reint_fmts[REINT_MAX] = {
1499 [REINT_SETATTR] = &RQF_MDS_REINT_SETATTR,
1500 [REINT_CREATE] = &RQF_MDS_REINT_CREATE,
1501 [REINT_LINK] = &RQF_MDS_REINT_LINK,
1502 [REINT_UNLINK] = &RQF_MDS_REINT_UNLINK,
1503 [REINT_RENAME] = &RQF_MDS_REINT_RENAME,
1504 [REINT_OPEN] = &RQF_MDS_REINT_OPEN,
1505 [REINT_SETXATTR] = &RQF_MDS_REINT_SETXATTR
1510 opc = mdt_reint_opcode(info, reint_fmts);
1513 * No lock possible here from client to pass it to reint code
1516 rc = mdt_reint_internal(info, NULL, opc);
1521 info->mti_fail_id = OBD_FAIL_MDS_REINT_NET_REP;
1525 /* TODO these two methods not available now. */
1527 /* this should sync the whole device */
1528 static int mdt_device_sync(struct mdt_thread_info *info)
1533 /* this should sync this object */
1534 static int mdt_object_sync(struct mdt_thread_info *info)
1539 static int mdt_sync(struct mdt_thread_info *info)
1541 struct req_capsule *pill = info->mti_pill;
1542 struct mdt_body *body;
1546 /* The fid may be zero, so we req_capsule_set manually */
1547 req_capsule_set(pill, &RQF_MDS_SYNC);
1549 body = req_capsule_client_get(pill, &RMF_MDT_BODY);
1551 RETURN(err_serious(-EINVAL));
1553 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_SYNC_PACK))
1554 RETURN(err_serious(-ENOMEM));
1556 if (fid_seq(&body->fid1) == 0) {
1557 /* sync the whole device */
1558 rc = req_capsule_server_pack(pill);
1560 rc = mdt_device_sync(info);
1562 rc = err_serious(rc);
1564 /* sync an object */
1565 rc = mdt_unpack_req_pack_rep(info, HABEO_CORPUS|HABEO_REFERO);
1567 rc = mdt_object_sync(info);
1569 struct md_object *next;
1570 const struct lu_fid *fid;
1571 struct lu_attr *la = &info->mti_attr.ma_attr;
1573 next = mdt_object_child(info->mti_object);
1574 info->mti_attr.ma_need = MA_INODE;
1575 info->mti_attr.ma_valid = 0;
1576 rc = mo_attr_get(info->mti_env, next,
1579 body = req_capsule_server_get(pill,
1581 fid = mdt_object_fid(info->mti_object);
1582 mdt_pack_attr2body(info, body, la, fid);
1586 rc = err_serious(rc);
1591 static int mdt_quotacheck_handle(struct mdt_thread_info *info)
1593 return err_serious(-EOPNOTSUPP);
1596 static int mdt_quotactl_handle(struct mdt_thread_info *info)
1598 return err_serious(-EOPNOTSUPP);
1602 * OBD PING and other handlers.
1604 static int mdt_obd_ping(struct mdt_thread_info *info)
1609 req_capsule_set(info->mti_pill, &RQF_OBD_PING);
1611 rc = target_handle_ping(mdt_info_req(info));
1613 rc = err_serious(rc);
1617 static int mdt_obd_log_cancel(struct mdt_thread_info *info)
1619 return err_serious(-EOPNOTSUPP);
1622 static int mdt_obd_qc_callback(struct mdt_thread_info *info)
1624 return err_serious(-EOPNOTSUPP);
1631 static struct ldlm_callback_suite cbs = {
1632 .lcs_completion = ldlm_server_completion_ast,
1633 .lcs_blocking = ldlm_server_blocking_ast,
1637 static int mdt_enqueue(struct mdt_thread_info *info)
1639 struct ptlrpc_request *req;
1644 * info->mti_dlm_req already contains swapped and (if necessary)
1645 * converted dlm request.
1647 LASSERT(info->mti_dlm_req != NULL);
1649 req = mdt_info_req(info);
1652 * Lock without inodebits makes no sense and will oops later in
1653 * ldlm. Let's check it now to see if we have wrong lock from client or
1654 * bits get corrupted somewhere in mdt_intent_policy().
1656 req_bits = info->mti_dlm_req->lock_desc.l_policy_data.l_inodebits.bits;
1657 /* This is disabled because we need to support liblustre flock.
1658 * LASSERT(req_bits != 0);
1661 rc = ldlm_handle_enqueue0(info->mti_mdt->mdt_namespace,
1662 req, info->mti_dlm_req, &cbs);
1663 info->mti_fail_id = OBD_FAIL_LDLM_REPLY;
1664 return rc ? err_serious(rc) : req->rq_status;
1667 static int mdt_convert(struct mdt_thread_info *info)
1670 struct ptlrpc_request *req;
1672 LASSERT(info->mti_dlm_req);
1673 req = mdt_info_req(info);
1674 rc = ldlm_handle_convert0(req, info->mti_dlm_req);
1675 return rc ? err_serious(rc) : req->rq_status;
1678 static int mdt_bl_callback(struct mdt_thread_info *info)
1680 CERROR("bl callbacks should not happen on MDS\n");
1682 return err_serious(-EOPNOTSUPP);
1685 static int mdt_cp_callback(struct mdt_thread_info *info)
1687 CERROR("cp callbacks should not happen on MDS\n");
1689 return err_serious(-EOPNOTSUPP);
1693 * sec context handlers
1695 static int mdt_sec_ctx_handle(struct mdt_thread_info *info)
1699 rc = mdt_handle_idmap(info);
1702 struct ptlrpc_request *req = mdt_info_req(info);
1705 opc = lustre_msg_get_opc(req->rq_reqmsg);
1706 if (opc == SEC_CTX_INIT || opc == SEC_CTX_INIT_CONT)
1707 sptlrpc_svc_ctx_invalidate(req);
1713 static struct mdt_object *mdt_obj(struct lu_object *o)
1715 LASSERT(lu_device_is_mdt(o->lo_dev));
1716 return container_of0(o, struct mdt_object, mot_obj.mo_lu);
1719 struct mdt_object *mdt_object_find(const struct lu_env *env,
1720 struct mdt_device *d,
1721 const struct lu_fid *f)
1723 struct lu_object *o;
1724 struct mdt_object *m;
1727 CDEBUG(D_INFO, "Find object for "DFID"\n", PFID(f));
1728 o = lu_object_find(env, d->mdt_md_dev.md_lu_dev.ld_site, f);
1729 if (unlikely(IS_ERR(o)))
1730 m = (struct mdt_object *)o;
1736 int mdt_object_lock(struct mdt_thread_info *info, struct mdt_object *o,
1737 struct mdt_lock_handle *lh, __u64 ibits, int locality)
1739 struct ldlm_namespace *ns = info->mti_mdt->mdt_namespace;
1740 ldlm_policy_data_t *policy = &info->mti_policy;
1741 struct ldlm_res_id *res_id = &info->mti_res_id;
1745 LASSERT(!lustre_handle_is_used(&lh->mlh_reg_lh));
1746 LASSERT(!lustre_handle_is_used(&lh->mlh_pdo_lh));
1747 LASSERT(lh->mlh_reg_mode != LCK_MINMODE);
1748 LASSERT(lh->mlh_type != MDT_NUL_LOCK);
1750 if (mdt_object_exists(o) < 0) {
1751 if (locality == MDT_CROSS_LOCK) {
1752 /* cross-ref object fix */
1753 ibits &= ~MDS_INODELOCK_UPDATE;
1754 ibits |= MDS_INODELOCK_LOOKUP;
1756 LASSERT(!(ibits & MDS_INODELOCK_UPDATE));
1757 LASSERT(ibits & MDS_INODELOCK_LOOKUP);
1759 /* No PDO lock on remote object */
1760 LASSERT(lh->mlh_type != MDT_PDO_LOCK);
1763 memset(policy, 0, sizeof(*policy));
1764 fid_build_reg_res_name(mdt_object_fid(o), res_id);
1767 * Take PDO lock on whole directory and build correct @res_id for lock
1768 * on part of directory.
1770 if (lh->mlh_pdo_hash != 0) {
1771 LASSERT(lh->mlh_type == MDT_PDO_LOCK);
1772 mdt_lock_pdo_mode(info, o, lh);
1773 if (lh->mlh_pdo_mode != LCK_NL) {
1775 * Do not use LDLM_FL_LOCAL_ONLY for parallel lock, it
1776 * is never going to be sent to client and we do not
1777 * want it slowed down due to possible cancels.
1779 policy->l_inodebits.bits = MDS_INODELOCK_UPDATE;
1780 rc = mdt_fid_lock(ns, &lh->mlh_pdo_lh, lh->mlh_pdo_mode,
1781 policy, res_id, LDLM_FL_ATOMIC_CB);
1787 * Finish res_id initializing by name hash marking patr of
1788 * directory which is taking modification.
1790 res_id->name[LUSTRE_RES_ID_HSH_OFF] = lh->mlh_pdo_hash;
1793 policy->l_inodebits.bits = ibits;
1796 * Use LDLM_FL_LOCAL_ONLY for this lock. We do not know yet if it is
1797 * going to be sent to client. If it is - mdt_intent_policy() path will
1798 * fix it up and turns FL_LOCAL flag off.
1800 rc = mdt_fid_lock(ns, &lh->mlh_reg_lh, lh->mlh_reg_mode, policy,
1801 res_id, LDLM_FL_LOCAL_ONLY | LDLM_FL_ATOMIC_CB);
1806 if (lh->mlh_type == MDT_PDO_LOCK) {
1807 /* check for exists after object is locked */
1808 if (mdt_object_exists(o) == 0) {
1809 /* Non-existent object shouldn't have PDO lock */
1812 /* Non-dir object shouldn't have PDO lock */
1813 LASSERT(S_ISDIR(lu_object_attr(&o->mot_obj.mo_lu)));
1818 mdt_object_unlock(info, o, lh, 1);
1825 * Just call ldlm_lock_decref() if decref, else we only call ptlrpc_save_lock()
1826 * to save this lock in req. when transaction committed, req will be released,
1827 * and lock will, too.
1829 void mdt_object_unlock(struct mdt_thread_info *info, struct mdt_object *o,
1830 struct mdt_lock_handle *lh, int decref)
1832 struct ptlrpc_request *req = mdt_info_req(info);
1835 if (lustre_handle_is_used(&lh->mlh_pdo_lh)) {
1836 /* Do not save PDO locks to request, just decref. */
1837 mdt_fid_unlock(&lh->mlh_pdo_lh,
1839 lh->mlh_pdo_lh.cookie = 0ull;
1842 if (lustre_handle_is_used(&lh->mlh_reg_lh)) {
1844 mdt_fid_unlock(&lh->mlh_reg_lh,
1847 ptlrpc_save_lock(req, &lh->mlh_reg_lh,
1850 lh->mlh_reg_lh.cookie = 0ull;
1856 struct mdt_object *mdt_object_find_lock(struct mdt_thread_info *info,
1857 const struct lu_fid *f,
1858 struct mdt_lock_handle *lh,
1861 struct mdt_object *o;
1863 o = mdt_object_find(info->mti_env, info->mti_mdt, f);
1867 rc = mdt_object_lock(info, o, lh, ibits,
1870 mdt_object_put(info->mti_env, o);
1877 void mdt_object_unlock_put(struct mdt_thread_info * info,
1878 struct mdt_object * o,
1879 struct mdt_lock_handle *lh,
1882 mdt_object_unlock(info, o, lh, decref);
1883 mdt_object_put(info->mti_env, o);
1886 static struct mdt_handler *mdt_handler_find(__u32 opc,
1887 struct mdt_opc_slice *supported)
1889 struct mdt_opc_slice *s;
1890 struct mdt_handler *h;
1893 for (s = supported; s->mos_hs != NULL; s++) {
1894 if (s->mos_opc_start <= opc && opc < s->mos_opc_end) {
1895 h = s->mos_hs + (opc - s->mos_opc_start);
1896 if (likely(h->mh_opc != 0))
1897 LASSERT(h->mh_opc == opc);
1899 h = NULL; /* unsupported opc */
1906 static int mdt_lock_resname_compat(struct mdt_device *m,
1907 struct ldlm_request *req)
1909 /* XXX something... later. */
1913 static int mdt_lock_reply_compat(struct mdt_device *m, struct ldlm_reply *rep)
1915 /* XXX something... later. */
1920 * Generic code handling requests that have struct mdt_body passed in:
1922 * - extract mdt_body from request and save it in @info, if present;
1924 * - create lu_object, corresponding to the fid in mdt_body, and save it in
1927 * - if HABEO_CORPUS flag is set for this request type check whether object
1928 * actually exists on storage (lu_object_exists()).
1931 static int mdt_body_unpack(struct mdt_thread_info *info, __u32 flags)
1933 const struct mdt_body *body;
1934 struct mdt_object *obj;
1935 const struct lu_env *env;
1936 struct req_capsule *pill;
1940 env = info->mti_env;
1941 pill = info->mti_pill;
1943 body = info->mti_body = req_capsule_client_get(pill, &RMF_MDT_BODY);
1947 if (!(body->valid & OBD_MD_FLID))
1950 if (!fid_is_sane(&body->fid1)) {
1951 CERROR("Invalid fid: "DFID"\n", PFID(&body->fid1));
1956 * Do not get size or any capa fields before we check that request
1957 * contains capa actually. There are some requests which do not, for
1958 * instance MDS_IS_SUBDIR.
1960 if (req_capsule_has_field(pill, &RMF_CAPA1, RCL_CLIENT) &&
1961 req_capsule_get_size(pill, &RMF_CAPA1, RCL_CLIENT))
1962 mdt_set_capainfo(info, 0, &body->fid1,
1963 req_capsule_client_get(pill, &RMF_CAPA1));
1965 obj = mdt_object_find(env, info->mti_mdt, &body->fid1);
1967 if ((flags & HABEO_CORPUS) &&
1968 !mdt_object_exists(obj)) {
1969 mdt_object_put(env, obj);
1970 /* for capability renew ENOENT will be handled in
1972 if (body->valid & OBD_MD_FLOSSCAPA)
1977 info->mti_object = obj;
1986 static int mdt_unpack_req_pack_rep(struct mdt_thread_info *info, __u32 flags)
1988 struct req_capsule *pill = info->mti_pill;
1992 if (req_capsule_has_field(pill, &RMF_MDT_BODY, RCL_CLIENT))
1993 rc = mdt_body_unpack(info, flags);
1997 if (rc == 0 && (flags & HABEO_REFERO)) {
1998 struct mdt_device *mdt = info->mti_mdt;
2001 if (req_capsule_has_field(pill, &RMF_MDT_MD, RCL_SERVER))
2002 req_capsule_set_size(pill, &RMF_MDT_MD, RCL_SERVER,
2003 mdt->mdt_max_mdsize);
2004 if (req_capsule_has_field(pill, &RMF_LOGCOOKIES, RCL_SERVER))
2005 req_capsule_set_size(pill, &RMF_LOGCOOKIES, RCL_SERVER,
2006 mdt->mdt_max_cookiesize);
2008 rc = req_capsule_server_pack(pill);
2013 static int mdt_init_capa_ctxt(const struct lu_env *env, struct mdt_device *m)
2015 struct md_device *next = m->mdt_child;
2017 return next->md_ops->mdo_init_capa_ctxt(env, next,
2018 m->mdt_opts.mo_mds_capa,
2019 m->mdt_capa_timeout,
2025 * Invoke handler for this request opc. Also do necessary preprocessing
2026 * (according to handler ->mh_flags), and post-processing (setting of
2027 * ->last_{xid,committed}).
2029 static int mdt_req_handle(struct mdt_thread_info *info,
2030 struct mdt_handler *h, struct ptlrpc_request *req)
2032 int rc, serious = 0;
2037 LASSERT(h->mh_act != NULL);
2038 LASSERT(h->mh_opc == lustre_msg_get_opc(req->rq_reqmsg));
2039 LASSERT(current->journal_info == NULL);
2042 * Checking for various OBD_FAIL_$PREF_$OPC_NET codes. _Do_ not try
2043 * to put same checks into handlers like mdt_close(), mdt_reint(),
2044 * etc., without talking to mdt authors first. Checking same thing
2045 * there again is useless and returning 0 error wihtout packing reply
2046 * is buggy! Handlers either pack reply or return error.
2048 * We return 0 here and do not send any reply in order to emulate
2049 * network failure. Do not send any reply in case any of NET related
2050 * fail_id has occured.
2052 if (OBD_FAIL_CHECK_ORSET(h->mh_fail_id, OBD_FAIL_ONCE))
2056 flags = h->mh_flags;
2057 LASSERT(ergo(flags & (HABEO_CORPUS|HABEO_REFERO), h->mh_fmt != NULL));
2059 if (h->mh_fmt != NULL) {
2060 req_capsule_set(info->mti_pill, h->mh_fmt);
2061 rc = mdt_unpack_req_pack_rep(info, flags);
2064 if (rc == 0 && flags & MUTABOR &&
2065 req->rq_export->exp_connect_flags & OBD_CONNECT_RDONLY)
2066 /* should it be rq_status? */
2069 if (rc == 0 && flags & HABEO_CLAVIS) {
2070 struct ldlm_request *dlm_req;
2072 LASSERT(h->mh_fmt != NULL);
2074 dlm_req = req_capsule_client_get(info->mti_pill, &RMF_DLM_REQ);
2075 if (dlm_req != NULL) {
2076 if (info->mti_mdt->mdt_opts.mo_compat_resname)
2077 rc = mdt_lock_resname_compat(info->mti_mdt,
2079 info->mti_dlm_req = dlm_req;
2085 /* capability setting changed via /proc, needs reinitialize ctxt */
2086 if (info->mti_mdt && info->mti_mdt->mdt_capa_conf) {
2087 mdt_init_capa_ctxt(info->mti_env, info->mti_mdt);
2088 info->mti_mdt->mdt_capa_conf = 0;
2091 if (likely(rc == 0)) {
2093 * Process request, there can be two types of rc:
2094 * 1) errors with msg unpack/pack, other failures outside the
2095 * operation itself. This is counted as serious errors;
2096 * 2) errors during fs operation, should be placed in rq_status
2099 rc = h->mh_act(info);
2101 !req->rq_no_reply && req->rq_reply_state == NULL) {
2102 DEBUG_REQ(D_ERROR, req, "MDT \"handler\" %s did not "
2103 "pack reply and returned 0 error\n",
2107 serious = is_serious(rc);
2108 rc = clear_serious(rc);
2112 req->rq_status = rc;
2115 * ELDLM_* codes which > 0 should be in rq_status only as well as
2116 * all non-serious errors.
2118 if (rc > 0 || !serious)
2121 LASSERT(current->journal_info == NULL);
2123 if (rc == 0 && (flags & HABEO_CLAVIS) &&
2124 info->mti_mdt->mdt_opts.mo_compat_resname) {
2125 struct ldlm_reply *dlmrep;
2127 dlmrep = req_capsule_server_get(info->mti_pill, &RMF_DLM_REP);
2129 rc = mdt_lock_reply_compat(info->mti_mdt, dlmrep);
2132 /* If we're DISCONNECTing, the mdt_export_data is already freed */
2133 if (likely(rc == 0 && h->mh_opc != MDS_DISCONNECT))
2134 target_committed_to_req(req);
2136 if (unlikely((lustre_msg_get_flags(req->rq_reqmsg) & MSG_REPLAY) &&
2137 lustre_msg_get_transno(req->rq_reqmsg) == 0)) {
2138 DEBUG_REQ(D_ERROR, req, "transno is 0 during REPLAY");
2142 target_send_reply(req, rc, info->mti_fail_id);
2146 void mdt_lock_handle_init(struct mdt_lock_handle *lh)
2148 lh->mlh_type = MDT_NUL_LOCK;
2149 lh->mlh_reg_lh.cookie = 0ull;
2150 lh->mlh_reg_mode = LCK_MINMODE;
2151 lh->mlh_pdo_lh.cookie = 0ull;
2152 lh->mlh_pdo_mode = LCK_MINMODE;
2155 void mdt_lock_handle_fini(struct mdt_lock_handle *lh)
2157 LASSERT(!lustre_handle_is_used(&lh->mlh_reg_lh));
2158 LASSERT(!lustre_handle_is_used(&lh->mlh_pdo_lh));
2162 * Initialize fields of struct mdt_thread_info. Other fields are left in
2163 * uninitialized state, because it's too expensive to zero out whole
2164 * mdt_thread_info (> 1K) on each request arrival.
2166 static void mdt_thread_info_init(struct ptlrpc_request *req,
2167 struct mdt_thread_info *info)
2170 struct md_capainfo *ci;
2172 req_capsule_init(&req->rq_pill, req, RCL_SERVER);
2173 info->mti_pill = &req->rq_pill;
2176 for (i = 0; i < ARRAY_SIZE(info->mti_lh); i++)
2177 mdt_lock_handle_init(&info->mti_lh[i]);
2179 /* mdt device: it can be NULL while CONNECT */
2180 if (req->rq_export) {
2181 info->mti_mdt = mdt_dev(req->rq_export->exp_obd->obd_lu_dev);
2182 info->mti_exp = req->rq_export;
2184 info->mti_mdt = NULL;
2185 info->mti_env = req->rq_svc_thread->t_env;
2186 ci = md_capainfo(info->mti_env);
2187 memset(ci, 0, sizeof *ci);
2189 info->mti_fail_id = OBD_FAIL_MDS_ALL_REPLY_NET;
2190 info->mti_transno = lustre_msg_get_transno(req->rq_reqmsg);
2192 memset(&info->mti_attr, 0, sizeof(info->mti_attr));
2193 info->mti_body = NULL;
2194 info->mti_object = NULL;
2195 info->mti_dlm_req = NULL;
2196 info->mti_has_trans = 0;
2197 info->mti_no_need_trans = 0;
2198 info->mti_cross_ref = 0;
2199 info->mti_opdata = 0;
2201 /* To not check for split by default. */
2202 info->mti_spec.sp_ck_split = 0;
2205 static void mdt_thread_info_fini(struct mdt_thread_info *info)
2209 req_capsule_fini(info->mti_pill);
2210 if (info->mti_object != NULL) {
2211 mdt_object_put(info->mti_env, info->mti_object);
2212 info->mti_object = NULL;
2214 for (i = 0; i < ARRAY_SIZE(info->mti_lh); i++)
2215 mdt_lock_handle_fini(&info->mti_lh[i]);
2216 info->mti_env = NULL;
2219 static int mdt_filter_recovery_request(struct ptlrpc_request *req,
2220 struct obd_device *obd, int *process)
2222 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
2223 case MDS_CONNECT: /* This will never get here, but for completeness. */
2224 case OST_CONNECT: /* This will never get here, but for completeness. */
2225 case MDS_DISCONNECT:
2226 case OST_DISCONNECT:
2231 case MDS_DONE_WRITING:
2232 case MDS_SYNC: /* used in unmounting */
2238 *process = target_queue_recovery_request(req, obd);
2242 DEBUG_REQ(D_ERROR, req, "not permitted during recovery");
2249 * Handle recovery. Return:
2250 * +1: continue request processing;
2251 * -ve: abort immediately with the given error code;
2252 * 0: send reply with error code in req->rq_status;
2254 static int mdt_recovery(struct mdt_thread_info *info)
2256 struct ptlrpc_request *req = mdt_info_req(info);
2258 struct obd_device *obd;
2262 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
2265 case SEC_CTX_INIT_CONT:
2271 rc = mdt_handle_idmap(info);
2280 if (unlikely(req->rq_export == NULL)) {
2281 CERROR("operation %d on unconnected MDS from %s\n",
2282 lustre_msg_get_opc(req->rq_reqmsg),
2283 libcfs_id2str(req->rq_peer));
2284 /* FIXME: For CMD cleanup, when mds_B stop, the req from
2285 * mds_A will get -ENOTCONN(especially for ping req),
2286 * which will cause that mds_A deactive timeout, then when
2287 * mds_A cleanup, the cleanup process will be suspended since
2288 * deactive timeout is not zero.
2290 req->rq_status = -ENOTCONN;
2291 target_send_reply(req, -ENOTCONN, info->mti_fail_id);
2295 /* sanity check: if the xid matches, the request must be marked as a
2296 * resent or replayed */
2297 if (req_xid_is_last(req)) {
2298 if (!(lustre_msg_get_flags(req->rq_reqmsg) &
2299 (MSG_RESENT | MSG_REPLAY))) {
2300 DEBUG_REQ(D_WARNING, req, "rq_xid "LPU64" matches last_xid, "
2301 "expected REPLAY or RESENT flag (%x)", req->rq_xid,
2302 lustre_msg_get_flags(req->rq_reqmsg));
2304 req->rq_status = -ENOTCONN;
2309 /* else: note the opposite is not always true; a RESENT req after a
2310 * failover will usually not match the last_xid, since it was likely
2311 * never committed. A REPLAYed request will almost never match the
2312 * last xid, however it could for a committed, but still retained,
2315 obd = req->rq_export->exp_obd;
2317 /* Check for aborted recovery... */
2318 spin_lock_bh(&obd->obd_processing_task_lock);
2319 recovering = obd->obd_recovering;
2320 spin_unlock_bh(&obd->obd_processing_task_lock);
2321 if (unlikely(recovering)) {
2324 DEBUG_REQ(D_INFO, req, "Got new replay");
2325 rc = mdt_filter_recovery_request(req, obd, &should_process);
2326 if (rc != 0 || !should_process)
2328 else if (should_process < 0) {
2329 req->rq_status = should_process;
2330 rc = ptlrpc_error(req);
2337 static int mdt_msg_check_version(struct lustre_msg *msg)
2341 switch (lustre_msg_get_opc(msg)) {
2343 case MDS_DISCONNECT:
2346 case SEC_CTX_INIT_CONT:
2348 rc = lustre_msg_check_version(msg, LUSTRE_OBD_VERSION);
2350 CERROR("bad opc %u version %08x, expecting %08x\n",
2351 lustre_msg_get_opc(msg),
2352 lustre_msg_get_version(msg),
2353 LUSTRE_OBD_VERSION);
2357 case MDS_GETATTR_NAME:
2364 case MDS_DONE_WRITING:
2370 case MDS_QUOTACHECK:
2376 rc = lustre_msg_check_version(msg, LUSTRE_MDS_VERSION);
2378 CERROR("bad opc %u version %08x, expecting %08x\n",
2379 lustre_msg_get_opc(msg),
2380 lustre_msg_get_version(msg),
2381 LUSTRE_MDS_VERSION);
2385 case LDLM_BL_CALLBACK:
2386 case LDLM_CP_CALLBACK:
2387 rc = lustre_msg_check_version(msg, LUSTRE_DLM_VERSION);
2389 CERROR("bad opc %u version %08x, expecting %08x\n",
2390 lustre_msg_get_opc(msg),
2391 lustre_msg_get_version(msg),
2392 LUSTRE_DLM_VERSION);
2394 case OBD_LOG_CANCEL:
2395 case LLOG_ORIGIN_HANDLE_CREATE:
2396 case LLOG_ORIGIN_HANDLE_NEXT_BLOCK:
2397 case LLOG_ORIGIN_HANDLE_READ_HEADER:
2398 case LLOG_ORIGIN_HANDLE_CLOSE:
2399 case LLOG_ORIGIN_HANDLE_DESTROY:
2400 case LLOG_ORIGIN_HANDLE_PREV_BLOCK:
2402 rc = lustre_msg_check_version(msg, LUSTRE_LOG_VERSION);
2404 CERROR("bad opc %u version %08x, expecting %08x\n",
2405 lustre_msg_get_opc(msg),
2406 lustre_msg_get_version(msg),
2407 LUSTRE_LOG_VERSION);
2410 CERROR("MDS unknown opcode %d\n", lustre_msg_get_opc(msg));
2416 static int mdt_handle0(struct ptlrpc_request *req,
2417 struct mdt_thread_info *info,
2418 struct mdt_opc_slice *supported)
2420 struct mdt_handler *h;
2421 struct lustre_msg *msg;
2426 if (OBD_FAIL_CHECK_ORSET(OBD_FAIL_MDS_ALL_REQUEST_NET, OBD_FAIL_ONCE))
2429 LASSERT(current->journal_info == NULL);
2431 msg = req->rq_reqmsg;
2432 rc = mdt_msg_check_version(msg);
2433 if (likely(rc == 0)) {
2434 rc = mdt_recovery(info);
2435 if (likely(rc == +1)) {
2436 h = mdt_handler_find(lustre_msg_get_opc(msg),
2438 if (likely(h != NULL)) {
2439 rc = mdt_req_handle(info, h, req);
2441 CERROR("The unsupported opc: 0x%x\n", lustre_msg_get_opc(msg) );
2442 req->rq_status = -ENOTSUPP;
2443 rc = ptlrpc_error(req);
2448 CERROR(LUSTRE_MDT_NAME" drops mal-formed request\n");
2453 * MDT handler function called by ptlrpc service thread when request comes.
2455 * XXX common "target" functionality should be factored into separate module
2456 * shared by mdt, ost and stand-alone services like fld.
2458 static int mdt_handle_common(struct ptlrpc_request *req,
2459 struct mdt_opc_slice *supported)
2462 struct mdt_thread_info *info;
2466 env = req->rq_svc_thread->t_env;
2467 LASSERT(env != NULL);
2468 LASSERT(env->le_ses != NULL);
2469 LASSERT(env->le_ctx.lc_thread == req->rq_svc_thread);
2470 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
2471 LASSERT(info != NULL);
2473 mdt_thread_info_init(req, info);
2475 rc = mdt_handle0(req, info, supported);
2477 mdt_thread_info_fini(info);
2482 * This is called from recovery code as handler of _all_ RPC types, FLD and SEQ
2485 int mdt_recovery_handle(struct ptlrpc_request *req)
2490 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
2492 rc = mdt_handle_common(req, mdt_fld_handlers);
2495 rc = mdt_handle_common(req, mdt_seq_handlers);
2498 rc = mdt_handle_common(req, mdt_regular_handlers);
2505 static int mdt_regular_handle(struct ptlrpc_request *req)
2507 return mdt_handle_common(req, mdt_regular_handlers);
2510 static int mdt_readpage_handle(struct ptlrpc_request *req)
2512 return mdt_handle_common(req, mdt_readpage_handlers);
2515 static int mdt_xmds_handle(struct ptlrpc_request *req)
2517 return mdt_handle_common(req, mdt_xmds_handlers);
2520 static int mdt_mdsc_handle(struct ptlrpc_request *req)
2522 return mdt_handle_common(req, mdt_seq_handlers);
2525 static int mdt_mdss_handle(struct ptlrpc_request *req)
2527 return mdt_handle_common(req, mdt_seq_handlers);
2530 static int mdt_dtss_handle(struct ptlrpc_request *req)
2532 return mdt_handle_common(req, mdt_seq_handlers);
2535 static int mdt_fld_handle(struct ptlrpc_request *req)
2537 return mdt_handle_common(req, mdt_fld_handlers);
2553 static int mdt_intent_getattr(enum mdt_it_code opcode,
2554 struct mdt_thread_info *info,
2555 struct ldlm_lock **,
2557 static int mdt_intent_reint(enum mdt_it_code opcode,
2558 struct mdt_thread_info *info,
2559 struct ldlm_lock **,
2562 static struct mdt_it_flavor {
2563 const struct req_format *it_fmt;
2565 int (*it_act)(enum mdt_it_code ,
2566 struct mdt_thread_info *,
2567 struct ldlm_lock **,
2570 } mdt_it_flavor[] = {
2572 .it_fmt = &RQF_LDLM_INTENT,
2573 /*.it_flags = HABEO_REFERO,*/
2575 .it_act = mdt_intent_reint,
2576 .it_reint = REINT_OPEN
2579 .it_fmt = &RQF_LDLM_INTENT,
2580 .it_flags = MUTABOR,
2581 .it_act = mdt_intent_reint,
2582 .it_reint = REINT_OPEN
2585 .it_fmt = &RQF_LDLM_INTENT,
2586 .it_flags = MUTABOR,
2587 .it_act = mdt_intent_reint,
2588 .it_reint = REINT_CREATE
2590 [MDT_IT_GETATTR] = {
2591 .it_fmt = &RQF_LDLM_INTENT_GETATTR,
2592 .it_flags = HABEO_REFERO,
2593 .it_act = mdt_intent_getattr
2595 [MDT_IT_READDIR] = {
2601 .it_fmt = &RQF_LDLM_INTENT_GETATTR,
2602 .it_flags = HABEO_REFERO,
2603 .it_act = mdt_intent_getattr
2606 .it_fmt = &RQF_LDLM_INTENT_UNLINK,
2607 .it_flags = MUTABOR,
2609 .it_reint = REINT_UNLINK
2613 .it_flags = MUTABOR,
2616 [MDT_IT_GETXATTR] = {
2623 int mdt_intent_lock_replace(struct mdt_thread_info *info,
2624 struct ldlm_lock **lockp,
2625 struct ldlm_lock *new_lock,
2626 struct mdt_lock_handle *lh,
2629 struct ptlrpc_request *req = mdt_info_req(info);
2630 struct ldlm_lock *lock = *lockp;
2633 * Get new lock only for cases when possible resent did not find any
2636 if (new_lock == NULL)
2637 new_lock = ldlm_handle2lock(&lh->mlh_reg_lh);
2639 if (new_lock == NULL && (flags & LDLM_FL_INTENT_ONLY)) {
2640 lh->mlh_reg_lh.cookie = 0;
2644 LASSERTF(new_lock != NULL,
2645 "lockh "LPX64"\n", lh->mlh_reg_lh.cookie);
2648 * If we've already given this lock to a client once, then we should
2649 * have no readers or writers. Otherwise, we should have one reader
2650 * _or_ writer ref (which will be zeroed below) before returning the
2653 if (new_lock->l_export == req->rq_export) {
2654 LASSERT(new_lock->l_readers + new_lock->l_writers == 0);
2656 LASSERT(new_lock->l_export == NULL);
2657 LASSERT(new_lock->l_readers + new_lock->l_writers == 1);
2662 if (new_lock->l_export == req->rq_export) {
2664 * Already gave this to the client, which means that we
2665 * reconstructed a reply.
2667 LASSERT(lustre_msg_get_flags(req->rq_reqmsg) &
2669 lh->mlh_reg_lh.cookie = 0;
2670 RETURN(ELDLM_LOCK_REPLACED);
2673 /* This lock might already be given to the client by an resent req,
2674 * in this case we should return ELDLM_LOCK_ABORTED,
2675 * so we should check led_held_locks here, but it will affect
2676 * performance, FIXME
2678 /* Fixup the lock to be given to the client */
2679 lock_res_and_lock(new_lock);
2680 new_lock->l_readers = 0;
2681 new_lock->l_writers = 0;
2683 new_lock->l_export = class_export_get(req->rq_export);
2684 spin_lock(&req->rq_export->exp_ldlm_data.led_lock);
2685 list_add(&new_lock->l_export_chain,
2686 &new_lock->l_export->exp_ldlm_data.led_held_locks);
2687 spin_unlock(&req->rq_export->exp_ldlm_data.led_lock);
2689 new_lock->l_blocking_ast = lock->l_blocking_ast;
2690 new_lock->l_completion_ast = lock->l_completion_ast;
2691 new_lock->l_remote_handle = lock->l_remote_handle;
2692 new_lock->l_flags &= ~LDLM_FL_LOCAL;
2694 unlock_res_and_lock(new_lock);
2695 LDLM_LOCK_PUT(new_lock);
2696 lh->mlh_reg_lh.cookie = 0;
2698 RETURN(ELDLM_LOCK_REPLACED);
2701 static void mdt_intent_fixup_resent(struct mdt_thread_info *info,
2702 struct ldlm_lock *new_lock,
2703 struct ldlm_lock **old_lock,
2704 struct mdt_lock_handle *lh)
2706 struct ptlrpc_request *req = mdt_info_req(info);
2707 struct obd_export *exp = req->rq_export;
2708 struct lustre_handle remote_hdl;
2709 struct ldlm_request *dlmreq;
2710 struct list_head *iter;
2712 if (!(lustre_msg_get_flags(req->rq_reqmsg) & MSG_RESENT))
2715 dlmreq = req_capsule_client_get(info->mti_pill, &RMF_DLM_REQ);
2716 remote_hdl = dlmreq->lock_handle[0];
2718 spin_lock(&exp->exp_ldlm_data.led_lock);
2719 list_for_each(iter, &exp->exp_ldlm_data.led_held_locks) {
2720 struct ldlm_lock *lock;
2721 lock = list_entry(iter, struct ldlm_lock, l_export_chain);
2722 if (lock == new_lock)
2724 if (lock->l_remote_handle.cookie == remote_hdl.cookie) {
2725 lh->mlh_reg_lh.cookie = lock->l_handle.h_cookie;
2726 lh->mlh_reg_mode = lock->l_granted_mode;
2728 LDLM_DEBUG(lock, "restoring lock cookie");
2729 DEBUG_REQ(D_DLMTRACE, req,
2730 "restoring lock cookie "LPX64,
2731 lh->mlh_reg_lh.cookie);
2733 *old_lock = LDLM_LOCK_GET(lock);
2734 spin_unlock(&exp->exp_ldlm_data.led_lock);
2738 spin_unlock(&exp->exp_ldlm_data.led_lock);
2741 * If the xid matches, then we know this is a resent request, and allow
2742 * it. (It's probably an OPEN, for which we don't send a lock.
2744 if (req_xid_is_last(req))
2748 * This remote handle isn't enqueued, so we never received or processed
2749 * this request. Clear MSG_RESENT, because it can be handled like any
2750 * normal request now.
2752 lustre_msg_clear_flags(req->rq_reqmsg, MSG_RESENT);
2754 DEBUG_REQ(D_DLMTRACE, req, "no existing lock with rhandle "LPX64,
2758 static int mdt_intent_getattr(enum mdt_it_code opcode,
2759 struct mdt_thread_info *info,
2760 struct ldlm_lock **lockp,
2763 struct mdt_lock_handle *lhc = &info->mti_lh[MDT_LH_RMT];
2764 struct ldlm_lock *new_lock = NULL;
2766 struct ldlm_reply *ldlm_rep;
2767 struct ptlrpc_request *req;
2768 struct mdt_body *reqbody;
2769 struct mdt_body *repbody;
2773 reqbody = req_capsule_client_get(info->mti_pill, &RMF_MDT_BODY);
2776 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
2779 info->mti_spec.sp_ck_split = !!(reqbody->valid & OBD_MD_FLCKSPLIT);
2780 info->mti_cross_ref = !!(reqbody->valid & OBD_MD_FLCROSSREF);
2781 repbody->eadatasize = 0;
2782 repbody->aclsize = 0;
2786 child_bits = MDS_INODELOCK_LOOKUP;
2788 case MDT_IT_GETATTR:
2789 child_bits = MDS_INODELOCK_LOOKUP | MDS_INODELOCK_UPDATE;
2792 CERROR("Unhandled till now");
2793 GOTO(out_shrink, rc = -EINVAL);
2796 rc = mdt_init_ucred(info, reqbody);
2798 GOTO(out_shrink, rc);
2800 req = info->mti_pill->rc_req;
2801 ldlm_rep = req_capsule_server_get(info->mti_pill, &RMF_DLM_REP);
2802 mdt_set_disposition(info, ldlm_rep, DISP_IT_EXECD);
2804 /* Get lock from request for possible resent case. */
2805 mdt_intent_fixup_resent(info, *lockp, &new_lock, lhc);
2807 ldlm_rep->lock_policy_res2 =
2808 mdt_getattr_name_lock(info, lhc, child_bits, ldlm_rep);
2810 if (mdt_get_disposition(ldlm_rep, DISP_LOOKUP_NEG))
2811 ldlm_rep->lock_policy_res2 = 0;
2812 if (!mdt_get_disposition(ldlm_rep, DISP_LOOKUP_POS) ||
2813 ldlm_rep->lock_policy_res2) {
2814 lhc->mlh_reg_lh.cookie = 0ull;
2815 GOTO(out_ucred, rc = ELDLM_LOCK_ABORTED);
2818 rc = mdt_intent_lock_replace(info, lockp, new_lock, lhc, flags);
2821 mdt_exit_ucred(info);
2823 mdt_shrink_reply(info);
2827 static int mdt_intent_reint(enum mdt_it_code opcode,
2828 struct mdt_thread_info *info,
2829 struct ldlm_lock **lockp,
2832 struct mdt_lock_handle *lhc = &info->mti_lh[MDT_LH_RMT];
2833 struct ldlm_reply *rep = NULL;
2837 static const struct req_format *intent_fmts[REINT_MAX] = {
2838 [REINT_CREATE] = &RQF_LDLM_INTENT_CREATE,
2839 [REINT_OPEN] = &RQF_LDLM_INTENT_OPEN
2844 opc = mdt_reint_opcode(info, intent_fmts);
2848 if (mdt_it_flavor[opcode].it_reint != opc) {
2849 CERROR("Reint code %ld doesn't match intent: %d\n",
2851 RETURN(err_serious(-EPROTO));
2854 /* Get lock from request for possible resent case. */
2855 mdt_intent_fixup_resent(info, *lockp, NULL, lhc);
2857 rc = mdt_reint_internal(info, lhc, opc);
2859 /* Check whether the reply has been packed successfully. */
2860 if (mdt_info_req(info)->rq_repmsg != NULL)
2861 rep = req_capsule_server_get(info->mti_pill, &RMF_DLM_REP);
2863 RETURN(err_serious(-EFAULT));
2865 /* MDC expects this in any case */
2867 mdt_set_disposition(info, rep, DISP_LOOKUP_EXECD);
2869 /* Cross-ref case, the lock should be returned to the client */
2870 if (rc == -EREMOTE) {
2871 LASSERT(lustre_handle_is_used(&lhc->mlh_reg_lh));
2872 rep->lock_policy_res2 = 0;
2873 rc = mdt_intent_lock_replace(info, lockp, NULL, lhc, flags);
2876 rep->lock_policy_res2 = clear_serious(rc);
2878 lhc->mlh_reg_lh.cookie = 0ull;
2879 rc = ELDLM_LOCK_ABORTED;
2883 static int mdt_intent_code(long itcode)
2891 case IT_OPEN|IT_CREAT:
2898 rc = MDT_IT_READDIR;
2901 rc = MDT_IT_GETATTR;
2913 rc = MDT_IT_GETXATTR;
2916 CERROR("Unknown intent opcode: %ld\n", itcode);
2923 static int mdt_intent_opc(long itopc, struct mdt_thread_info *info,
2924 struct ldlm_lock **lockp, int flags)
2926 struct req_capsule *pill;
2927 struct mdt_it_flavor *flv;
2932 opc = mdt_intent_code(itopc);
2936 pill = info->mti_pill;
2937 flv = &mdt_it_flavor[opc];
2939 if (flv->it_fmt != NULL)
2940 req_capsule_extend(pill, flv->it_fmt);
2942 rc = mdt_unpack_req_pack_rep(info, flv->it_flags);
2944 struct ptlrpc_request *req = mdt_info_req(info);
2945 if (flv->it_flags & MUTABOR &&
2946 req->rq_export->exp_connect_flags & OBD_CONNECT_RDONLY)
2949 if (rc == 0 && flv->it_act != NULL) {
2950 /* execute policy */
2951 rc = flv->it_act(opc, info, lockp, flags);
2958 static int mdt_intent_policy(struct ldlm_namespace *ns,
2959 struct ldlm_lock **lockp, void *req_cookie,
2960 ldlm_mode_t mode, int flags, void *data)
2962 struct mdt_thread_info *info;
2963 struct ptlrpc_request *req = req_cookie;
2964 struct ldlm_intent *it;
2965 struct req_capsule *pill;
2970 LASSERT(req != NULL);
2972 info = lu_context_key_get(&req->rq_svc_thread->t_env->le_ctx,
2974 LASSERT(info != NULL);
2975 pill = info->mti_pill;
2976 LASSERT(pill->rc_req == req);
2978 if (req->rq_reqmsg->lm_bufcount > DLM_INTENT_IT_OFF) {
2979 req_capsule_extend(pill, &RQF_LDLM_INTENT);
2980 it = req_capsule_client_get(pill, &RMF_LDLM_INTENT);
2982 const struct ldlm_request *dlmreq;
2985 struct ldlm_lock *lock = *lockp;
2987 LDLM_DEBUG(lock, "intent policy opc: %s\n",
2988 ldlm_it2str(it->opc));
2991 rc = mdt_intent_opc(it->opc, info, lockp, flags);
2996 * Lock without inodebits makes no sense and will oops
2997 * later in ldlm. Let's check it now to see if we have
2998 * wrong lock from client or bits get corrupted
2999 * somewhere in mdt_intent_opc().
3001 dlmreq = info->mti_dlm_req;
3002 req_bits = dlmreq->lock_desc.l_policy_data.l_inodebits.bits;
3003 LASSERT(req_bits != 0);
3006 rc = err_serious(-EFAULT);
3008 /* No intent was provided */
3009 LASSERT(pill->rc_fmt == &RQF_LDLM_ENQUEUE);
3010 rc = req_capsule_server_pack(pill);
3012 rc = err_serious(rc);
3020 static void mdt_seq_adjust(const struct lu_env *env,
3021 struct mdt_device *m, int lost)
3023 struct lu_site *ls = m->mdt_md_dev.md_lu_dev.ld_site;
3024 struct lu_range out;
3027 LASSERT(ls && ls->ls_server_seq);
3029 /* get extra seq from seq_server, moving it's range up */
3030 while (lost-- > 0) {
3031 seq_server_alloc_meta(ls->ls_server_seq, NULL, &out, env);
3036 static int mdt_seq_fini(const struct lu_env *env,
3037 struct mdt_device *m)
3039 struct lu_site *ls = m->mdt_md_dev.md_lu_dev.ld_site;
3042 if (ls && ls->ls_server_seq) {
3043 seq_server_fini(ls->ls_server_seq, env);
3044 OBD_FREE_PTR(ls->ls_server_seq);
3045 ls->ls_server_seq = NULL;
3048 if (ls && ls->ls_control_seq) {
3049 seq_server_fini(ls->ls_control_seq, env);
3050 OBD_FREE_PTR(ls->ls_control_seq);
3051 ls->ls_control_seq = NULL;
3054 if (ls && ls->ls_client_seq) {
3055 seq_client_fini(ls->ls_client_seq);
3056 OBD_FREE_PTR(ls->ls_client_seq);
3057 ls->ls_client_seq = NULL;
3063 static int mdt_seq_init(const struct lu_env *env,
3065 struct mdt_device *m)
3072 ls = m->mdt_md_dev.md_lu_dev.ld_site;
3075 * This is sequence-controller node. Init seq-controller server on local
3078 if (ls->ls_node_id == 0) {
3079 LASSERT(ls->ls_control_seq == NULL);
3081 OBD_ALLOC_PTR(ls->ls_control_seq);
3082 if (ls->ls_control_seq == NULL)
3085 rc = seq_server_init(ls->ls_control_seq,
3086 m->mdt_bottom, uuid,
3087 LUSTRE_SEQ_CONTROLLER,
3091 GOTO(out_seq_fini, rc);
3093 OBD_ALLOC_PTR(ls->ls_client_seq);
3094 if (ls->ls_client_seq == NULL)
3095 GOTO(out_seq_fini, rc = -ENOMEM);
3097 OBD_ALLOC(prefix, MAX_OBD_NAME + 5);
3098 if (prefix == NULL) {
3099 OBD_FREE_PTR(ls->ls_client_seq);
3100 GOTO(out_seq_fini, rc = -ENOMEM);
3103 snprintf(prefix, MAX_OBD_NAME + 5, "ctl-%s",
3107 * Init seq-controller client after seq-controller server is
3108 * ready. Pass ls->ls_control_seq to it for direct talking.
3110 rc = seq_client_init(ls->ls_client_seq, NULL,
3111 LUSTRE_SEQ_METADATA, prefix,
3112 ls->ls_control_seq);
3113 OBD_FREE(prefix, MAX_OBD_NAME + 5);
3116 GOTO(out_seq_fini, rc);
3119 /* Init seq-server on local MDT */
3120 LASSERT(ls->ls_server_seq == NULL);
3122 OBD_ALLOC_PTR(ls->ls_server_seq);
3123 if (ls->ls_server_seq == NULL)
3124 GOTO(out_seq_fini, rc = -ENOMEM);
3126 rc = seq_server_init(ls->ls_server_seq,
3127 m->mdt_bottom, uuid,
3131 GOTO(out_seq_fini, rc = -ENOMEM);
3133 /* Assign seq-controller client to local seq-server. */
3134 if (ls->ls_node_id == 0) {
3135 LASSERT(ls->ls_client_seq != NULL);
3137 rc = seq_server_set_cli(ls->ls_server_seq,
3145 mdt_seq_fini(env, m);
3150 * Init client sequence manager which is used by local MDS to talk to sequence
3151 * controller on remote node.
3153 static int mdt_seq_init_cli(const struct lu_env *env,
3154 struct mdt_device *m,
3155 struct lustre_cfg *cfg)
3157 struct lu_site *ls = m->mdt_md_dev.md_lu_dev.ld_site;
3158 struct obd_device *mdc;
3159 struct obd_uuid *uuidp, *mdcuuidp;
3160 char *uuid_str, *mdc_uuid_str;
3163 struct mdt_thread_info *info;
3164 char *p, *index_string = lustre_cfg_string(cfg, 2);
3167 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
3168 uuidp = &info->mti_u.uuid[0];
3169 mdcuuidp = &info->mti_u.uuid[1];
3171 LASSERT(index_string);
3173 index = simple_strtol(index_string, &p, 10);
3175 CERROR("Invalid index in lustre_cgf, offset 2\n");
3179 /* check if this is adding the first MDC and controller is not yet
3181 if (index != 0 || ls->ls_client_seq)
3184 uuid_str = lustre_cfg_string(cfg, 1);
3185 mdc_uuid_str = lustre_cfg_string(cfg, 4);
3186 obd_str2uuid(uuidp, uuid_str);
3187 obd_str2uuid(mdcuuidp, mdc_uuid_str);
3189 mdc = class_find_client_obd(uuidp, LUSTRE_MDC_NAME, mdcuuidp);
3191 CERROR("can't find controller MDC by uuid %s\n",
3194 } else if (!mdc->obd_set_up) {
3195 CERROR("target %s not set up\n", mdc->obd_name);
3198 LASSERT(ls->ls_control_exp);
3199 OBD_ALLOC_PTR(ls->ls_client_seq);
3200 if (ls->ls_client_seq != NULL) {
3203 OBD_ALLOC(prefix, MAX_OBD_NAME + 5);
3207 snprintf(prefix, MAX_OBD_NAME + 5, "ctl-%s",
3210 rc = seq_client_init(ls->ls_client_seq,
3212 LUSTRE_SEQ_METADATA,
3214 OBD_FREE(prefix, MAX_OBD_NAME + 5);
3221 LASSERT(ls->ls_server_seq != NULL);
3222 rc = seq_server_set_cli(ls->ls_server_seq, ls->ls_client_seq,
3229 static void mdt_seq_fini_cli(struct mdt_device *m)
3235 ls = m->mdt_md_dev.md_lu_dev.ld_site;
3237 if (ls && ls->ls_server_seq)
3238 seq_server_set_cli(ls->ls_server_seq,
3241 if (ls && ls->ls_control_exp) {
3242 class_export_put(ls->ls_control_exp);
3243 ls->ls_control_exp = NULL;
3251 static int mdt_fld_fini(const struct lu_env *env,
3252 struct mdt_device *m)