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 ptlrpc_service *svc;
324 struct obd_statfs *osfs;
329 svc = info->mti_pill->rc_req->rq_rqbd->rqbd_service;
331 /* This will trigger a watchdog timeout */
332 OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_STATFS_LCW_SLEEP,
333 (MDT_SERVICE_WATCHDOG_FACTOR *
334 at_get(&svc->srv_at_estimate) / 1000) + 1);
336 rc = mdt_check_ucred(info);
338 RETURN(err_serious(rc));
340 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_STATFS_PACK)) {
341 rc = err_serious(-ENOMEM);
343 osfs = req_capsule_server_get(info->mti_pill, &RMF_OBD_STATFS);
344 rc = next->md_ops->mdo_statfs(info->mti_env, next,
346 statfs_pack(osfs, &info->mti_u.ksfs);
351 void mdt_pack_size2body(struct mdt_thread_info *info, struct mdt_object *o)
354 struct lu_attr *attr = &info->mti_attr.ma_attr;
356 b = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
358 /* Check if Size-on-MDS is enabled. */
359 if ((mdt_conn_flags(info) & OBD_CONNECT_SOM) &&
360 S_ISREG(attr->la_mode) && mdt_sizeonmds_enabled(o)) {
361 b->valid |= (OBD_MD_FLSIZE | OBD_MD_FLBLOCKS);
362 b->size = attr->la_size;
363 b->blocks = attr->la_blocks;
367 void mdt_pack_attr2body(struct mdt_thread_info *info, struct mdt_body *b,
368 const struct lu_attr *attr, const struct lu_fid *fid)
370 /*XXX should pack the reply body according to lu_valid*/
371 b->valid |= OBD_MD_FLCTIME | OBD_MD_FLUID |
372 OBD_MD_FLGID | OBD_MD_FLTYPE |
373 OBD_MD_FLMODE | OBD_MD_FLNLINK | OBD_MD_FLFLAGS |
374 OBD_MD_FLATIME | OBD_MD_FLMTIME ;
376 if (!S_ISREG(attr->la_mode))
377 b->valid |= OBD_MD_FLSIZE | OBD_MD_FLBLOCKS | OBD_MD_FLRDEV;
379 b->atime = attr->la_atime;
380 b->mtime = attr->la_mtime;
381 b->ctime = attr->la_ctime;
382 b->mode = attr->la_mode;
383 b->size = attr->la_size;
384 b->blocks = attr->la_blocks;
385 b->uid = attr->la_uid;
386 b->gid = attr->la_gid;
387 b->flags = attr->la_flags;
388 b->nlink = attr->la_nlink;
389 b->rdev = attr->la_rdev;
393 b->valid |= OBD_MD_FLID;
395 /* FIXME: these should be fixed when new igif ready.*/
396 b->ino = fid_oid(fid); /* 1.6 compatibility */
397 b->generation = fid_ver(fid); /* 1.6 compatibility */
398 b->valid |= OBD_MD_FLGENER; /* 1.6 compatibility */
400 CDEBUG(D_INODE, DFID": nlink=%d, mode=%o, size="LPU64"\n",
401 PFID(fid), b->nlink, b->mode, b->size);
405 mdt_body_reverse_idmap(info, b);
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 static int mdt_getattr_internal(struct mdt_thread_info *info,
416 struct mdt_object *o)
418 struct md_object *next = mdt_object_child(o);
419 const struct mdt_body *reqbody = info->mti_body;
420 struct ptlrpc_request *req = mdt_info_req(info);
421 struct mdt_export_data *med = &req->rq_export->exp_mdt_data;
422 struct md_attr *ma = &info->mti_attr;
423 struct lu_attr *la = &ma->ma_attr;
424 struct req_capsule *pill = info->mti_pill;
425 const struct lu_env *env = info->mti_env;
426 struct mdt_body *repbody;
427 struct lu_buf *buffer = &info->mti_buf;
431 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_GETATTR_PACK))
432 RETURN(err_serious(-ENOMEM));
434 repbody = req_capsule_server_get(pill, &RMF_MDT_BODY);
438 rc = mdt_object_exists(o);
440 /* This object is located on remote node.*/
441 repbody->fid1 = *mdt_object_fid(o);
442 repbody->valid = OBD_MD_FLID | OBD_MD_MDS;
446 buffer->lb_buf = req_capsule_server_get(pill, &RMF_MDT_MD);
447 buffer->lb_len = req_capsule_get_size(pill, &RMF_MDT_MD, RCL_SERVER);
449 /* If it is dir object and client require MEA, then we got MEA */
450 if (S_ISDIR(lu_object_attr(&next->mo_lu)) &&
451 reqbody->valid & OBD_MD_MEA) {
452 /* Assumption: MDT_MD size is enough for lmv size. */
453 ma->ma_lmv = buffer->lb_buf;
454 ma->ma_lmv_size = buffer->lb_len;
455 ma->ma_need = MA_LMV | MA_INODE;
457 ma->ma_lmm = buffer->lb_buf;
458 ma->ma_lmm_size = buffer->lb_len;
459 ma->ma_need = MA_LOV | MA_INODE;
462 if (S_ISDIR(lu_object_attr(&next->mo_lu)) &&
463 reqbody->valid & OBD_MD_FLDIREA &&
464 lustre_msg_get_opc(req->rq_reqmsg) == MDS_GETATTR) {
465 /* get default stripe info for this dir. */
466 ma->ma_need |= MA_LOV_DEF;
468 rc = mo_attr_get(env, next, ma);
470 CERROR("getattr error for "DFID": %d\n",
471 PFID(mdt_object_fid(o)), rc);
475 if (likely(ma->ma_valid & MA_INODE))
476 mdt_pack_attr2body(info, repbody, la, mdt_object_fid(o));
480 if (mdt_body_has_lov(la, reqbody)) {
481 if (ma->ma_valid & MA_LOV) {
482 LASSERT(ma->ma_lmm_size);
483 mdt_dump_lmm(D_INFO, ma->ma_lmm);
484 repbody->eadatasize = ma->ma_lmm_size;
485 if (S_ISDIR(la->la_mode))
486 repbody->valid |= OBD_MD_FLDIREA;
488 repbody->valid |= OBD_MD_FLEASIZE;
490 if (ma->ma_valid & MA_LMV) {
491 LASSERT(S_ISDIR(la->la_mode));
492 repbody->eadatasize = ma->ma_lmv_size;
493 repbody->valid |= (OBD_MD_FLDIREA|OBD_MD_MEA);
495 if (!(ma->ma_valid & MA_LOV) && !(ma->ma_valid & MA_LMV)) {
496 repbody->valid |= OBD_MD_FLSIZE | OBD_MD_FLBLOCKS;
498 } else if (S_ISLNK(la->la_mode) &&
499 reqbody->valid & OBD_MD_LINKNAME) {
500 buffer->lb_buf = ma->ma_lmm;
501 buffer->lb_len = reqbody->eadatasize;
502 rc = mo_readlink(env, next, buffer);
503 if (unlikely(rc <= 0)) {
504 CERROR("readlink failed: %d\n", rc);
507 repbody->valid |= OBD_MD_LINKNAME;
508 repbody->eadatasize = rc;
510 ((char*)ma->ma_lmm)[rc - 1] = 0;
511 CDEBUG(D_INODE, "symlink dest %s, len = %d\n",
512 (char*)ma->ma_lmm, rc);
517 if (reqbody->valid & OBD_MD_FLMODEASIZE) {
518 repbody->max_cookiesize = info->mti_mdt->mdt_max_cookiesize;
519 repbody->max_mdsize = info->mti_mdt->mdt_max_mdsize;
520 repbody->valid |= OBD_MD_FLMODEASIZE;
521 CDEBUG(D_INODE, "I am going to change the MAX_MD_SIZE & "
522 "MAX_COOKIE to : %d:%d\n", repbody->max_mdsize,
523 repbody->max_cookiesize);
526 if (med->med_rmtclient && (reqbody->valid & OBD_MD_FLRMTPERM)) {
527 void *buf = req_capsule_server_get(pill, &RMF_ACL);
529 /* mdt_getattr_lock only */
530 rc = mdt_pack_remote_perm(info, o, buf);
532 repbody->valid &= ~OBD_MD_FLRMTPERM;
533 repbody->aclsize = 0;
536 repbody->valid |= OBD_MD_FLRMTPERM;
537 repbody->aclsize = sizeof(struct mdt_remote_perm);
540 #ifdef CONFIG_FS_POSIX_ACL
541 else if ((req->rq_export->exp_connect_flags & OBD_CONNECT_ACL) &&
542 (reqbody->valid & OBD_MD_FLACL)) {
543 buffer->lb_buf = req_capsule_server_get(pill, &RMF_ACL);
544 buffer->lb_len = req_capsule_get_size(pill,
545 &RMF_ACL, RCL_SERVER);
546 if (buffer->lb_len > 0) {
547 rc = mo_xattr_get(env, next, buffer,
548 XATTR_NAME_ACL_ACCESS);
550 if (rc == -ENODATA) {
551 repbody->aclsize = 0;
552 repbody->valid |= OBD_MD_FLACL;
554 } else if (rc == -EOPNOTSUPP) {
557 CERROR("got acl size: %d\n", rc);
560 repbody->aclsize = rc;
561 repbody->valid |= OBD_MD_FLACL;
568 if ((reqbody->valid & OBD_MD_FLMDSCAPA) &&
569 info->mti_mdt->mdt_opts.mo_mds_capa) {
570 struct lustre_capa *capa;
572 capa = req_capsule_server_get(pill, &RMF_CAPA1);
574 capa->lc_opc = CAPA_OPC_MDS_DEFAULT;
575 rc = mo_capa_get(env, next, capa, 0);
578 repbody->valid |= OBD_MD_FLMDSCAPA;
583 static int mdt_renew_capa(struct mdt_thread_info *info)
585 struct mdt_device *mdt = info->mti_mdt;
586 struct mdt_object *obj = info->mti_object;
587 struct mdt_body *body;
588 struct lustre_capa *capa, *c;
592 /* if object doesn't exist, or server has disabled capability,
593 * return directly, client will find body->valid OBD_MD_FLOSSCAPA
596 if (!obj || !mdt->mdt_opts.mo_mds_capa)
599 body = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
600 LASSERT(body != NULL);
602 c = req_capsule_client_get(info->mti_pill, &RMF_CAPA1);
605 capa = req_capsule_server_get(info->mti_pill, &RMF_CAPA2);
609 rc = mo_capa_get(info->mti_env, mdt_object_child(obj), capa, 1);
611 body->valid |= OBD_MD_FLOSSCAPA;
615 static int mdt_getattr(struct mdt_thread_info *info)
617 struct mdt_object *obj = info->mti_object;
618 struct req_capsule *pill = info->mti_pill;
619 struct mdt_body *reqbody;
620 struct mdt_body *repbody;
626 reqbody = req_capsule_client_get(pill, &RMF_MDT_BODY);
629 if (reqbody->valid & OBD_MD_FLOSSCAPA) {
630 rc = req_capsule_server_pack(pill);
632 RETURN(err_serious(rc));
633 rc = mdt_renew_capa(info);
634 GOTO(out_shrink, rc);
637 LASSERT(obj != NULL);
638 LASSERT(lu_object_assert_exists(&obj->mot_obj.mo_lu));
640 mode = lu_object_attr(&obj->mot_obj.mo_lu);
641 if (S_ISLNK(mode) && (reqbody->valid & OBD_MD_LINKNAME) &&
642 (reqbody->eadatasize > info->mti_mdt->mdt_max_mdsize))
643 md_size = reqbody->eadatasize;
645 md_size = info->mti_mdt->mdt_max_mdsize;
647 req_capsule_set_size(pill, &RMF_MDT_MD, RCL_SERVER, md_size);
649 rc = req_capsule_server_pack(pill);
650 if (unlikely(rc != 0))
651 RETURN(err_serious(rc));
653 repbody = req_capsule_server_get(pill, &RMF_MDT_BODY);
654 LASSERT(repbody != NULL);
655 repbody->eadatasize = 0;
656 repbody->aclsize = 0;
658 if (reqbody->valid & OBD_MD_FLRMTPERM)
659 rc = mdt_init_ucred(info, reqbody);
661 rc = mdt_check_ucred(info);
663 GOTO(out_shrink, rc);
665 info->mti_spec.sp_ck_split = !!(reqbody->valid & OBD_MD_FLCKSPLIT);
666 info->mti_cross_ref = !!(reqbody->valid & OBD_MD_FLCROSSREF);
669 * Don't check capability at all, because rename might getattr for
670 * remote obj, and at that time no capability is available.
672 mdt_set_capainfo(info, 1, &reqbody->fid1, BYPASS_CAPA);
673 rc = mdt_getattr_internal(info, obj);
674 if (reqbody->valid & OBD_MD_FLRMTPERM)
675 mdt_exit_ucred(info);
678 mdt_shrink_reply(info);
682 static int mdt_is_subdir(struct mdt_thread_info *info)
684 struct mdt_object *o = info->mti_object;
685 struct req_capsule *pill = info->mti_pill;
686 const struct mdt_body *body = info->mti_body;
687 struct mdt_body *repbody;
693 repbody = req_capsule_server_get(pill, &RMF_MDT_BODY);
696 * We save last checked parent fid to @repbody->fid1 for remote
699 LASSERT(fid_is_sane(&body->fid2));
700 LASSERT(mdt_object_exists(o) > 0);
701 rc = mdo_is_subdir(info->mti_env, mdt_object_child(o),
702 &body->fid2, &repbody->fid1);
703 if (rc == 0 || rc == -EREMOTE)
704 repbody->valid |= OBD_MD_FLID;
709 static int mdt_raw_lookup(struct mdt_thread_info *info,
710 struct mdt_object *parent,
711 const struct lu_name *lname,
712 struct ldlm_reply *ldlm_rep)
714 struct md_object *next = mdt_object_child(info->mti_object);
715 const struct mdt_body *reqbody = info->mti_body;
716 struct lu_fid *child_fid = &info->mti_tmp_fid1;
717 struct mdt_body *repbody;
721 if (reqbody->valid != OBD_MD_FLID)
724 LASSERT(!info->mti_cross_ref);
726 /* Only got the fid of this obj by name */
727 rc = mdo_lookup(info->mti_env, next, lname, child_fid,
730 /* XXX is raw_lookup possible as intent operation? */
733 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_NEG);
736 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_POS);
738 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
741 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
742 repbody->fid1 = *child_fid;
743 repbody->valid = OBD_MD_FLID;
749 * UPDATE lock should be taken against parent, and be release before exit;
750 * child_bits lock should be taken against child, and be returned back:
751 * (1)normal request should release the child lock;
752 * (2)intent request will grant the lock to client.
754 static int mdt_getattr_name_lock(struct mdt_thread_info *info,
755 struct mdt_lock_handle *lhc,
757 struct ldlm_reply *ldlm_rep)
759 struct ptlrpc_request *req = mdt_info_req(info);
760 struct mdt_body *reqbody = NULL;
761 struct mdt_object *parent = info->mti_object;
762 struct mdt_object *child;
763 struct md_object *next = mdt_object_child(parent);
764 struct lu_fid *child_fid = &info->mti_tmp_fid1;
765 struct lu_name *lname = NULL;
768 struct mdt_lock_handle *lhp;
769 struct ldlm_lock *lock;
770 struct ldlm_res_id *res_id;
776 is_resent = lustre_handle_is_used(&lhc->mlh_reg_lh);
777 LASSERT(ergo(is_resent,
778 lustre_msg_get_flags(req->rq_reqmsg) & MSG_RESENT));
780 LASSERT(parent != NULL);
781 name = req_capsule_client_get(info->mti_pill, &RMF_NAME);
783 RETURN(err_serious(-EFAULT));
785 namelen = req_capsule_get_size(info->mti_pill, &RMF_NAME,
787 LASSERT(namelen >= 0);
789 /* XXX: "namelen == 0" is for getattr by fid (OBD_CONNECT_ATTRFID),
790 * otherwise do not allow empty name, that is the name must contain
791 * at least one character and the terminating '\0'*/
793 reqbody =req_capsule_client_get(info->mti_pill, &RMF_MDT_BODY);
794 LASSERT(fid_is_sane(&reqbody->fid2));
797 CDEBUG(D_INODE, "getattr with lock for "DFID"/"DFID", "
799 PFID(mdt_object_fid(parent)), PFID(&reqbody->fid2),
802 lname = mdt_name(info->mti_env, (char *)name, namelen);
803 CDEBUG(D_INODE, "getattr with lock for "DFID"/%s, "
805 PFID(mdt_object_fid(parent)), name, ldlm_rep);
808 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_EXECD);
810 rc = mdt_object_exists(parent);
811 if (unlikely(rc == 0)) {
812 LU_OBJECT_DEBUG(D_WARNING, info->mti_env,
813 &parent->mot_obj.mo_lu,
814 "Parent doesn't exist!\n");
817 LASSERTF(rc > 0, "Parent "DFID" is on remote server\n",
818 PFID(mdt_object_fid(parent)));
821 rc = mdt_raw_lookup(info, parent, lname, ldlm_rep);
829 if (info->mti_cross_ref) {
830 /* Only getattr on the child. Parent is on another node. */
831 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_POS);
833 CDEBUG(D_INODE, "partial getattr_name child_fid = "DFID", "
834 "ldlm_rep=%p\n", PFID(mdt_object_fid(child)), ldlm_rep);
837 /* Do not take lock for resent case. */
838 lock = ldlm_handle2lock(&lhc->mlh_reg_lh);
839 LASSERTF(lock != NULL, "Invalid lock handle "LPX64"\n",
840 lhc->mlh_reg_lh.cookie);
841 LASSERT(fid_res_name_eq(mdt_object_fid(child),
842 &lock->l_resource->lr_name));
846 mdt_lock_handle_init(lhc);
847 mdt_lock_reg_init(lhc, LCK_PR);
850 * Object's name is on another MDS, no lookup lock is
851 * needed here but update is.
853 child_bits &= ~MDS_INODELOCK_LOOKUP;
854 child_bits |= MDS_INODELOCK_UPDATE;
856 rc = mdt_object_lock(info, child, lhc, child_bits,
860 /* Finally, we can get attr for child. */
861 mdt_set_capainfo(info, 0, mdt_object_fid(child),
863 rc = mdt_getattr_internal(info, child);
864 if (unlikely(rc != 0))
865 mdt_object_unlock(info, child, lhc, 1);
870 /* step 1: lock parent */
871 lhp = &info->mti_lh[MDT_LH_PARENT];
872 mdt_lock_pdo_init(lhp, LCK_PR, name, namelen);
873 rc = mdt_object_lock(info, parent, lhp, MDS_INODELOCK_UPDATE,
876 if (unlikely(rc != 0))
880 /* step 2: lookup child's fid by name */
881 rc = mdo_lookup(info->mti_env, next, lname, child_fid,
886 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_NEG);
887 GOTO(out_parent, rc);
889 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_POS);
891 *child_fid = reqbody->fid2;
892 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_POS);
896 *step 3: find the child object by fid & lock it.
897 * regardless if it is local or remote.
899 child = mdt_object_find(info->mti_env, info->mti_mdt, child_fid);
901 if (unlikely(IS_ERR(child)))
902 GOTO(out_parent, rc = PTR_ERR(child));
904 /* Do not take lock for resent case. */
905 lock = ldlm_handle2lock(&lhc->mlh_reg_lh);
906 LASSERTF(lock != NULL, "Invalid lock handle "LPX64"\n",
907 lhc->mlh_reg_lh.cookie);
909 res_id = &lock->l_resource->lr_name;
910 if (!fid_res_name_eq(mdt_object_fid(child),
911 &lock->l_resource->lr_name)) {
912 LASSERTF(fid_res_name_eq(mdt_object_fid(parent),
913 &lock->l_resource->lr_name),
914 "Lock res_id: %lu/%lu/%lu, Fid: "DFID".\n",
915 (unsigned long)res_id->name[0],
916 (unsigned long)res_id->name[1],
917 (unsigned long)res_id->name[2],
918 PFID(mdt_object_fid(parent)));
919 CWARN("Although resent, but still not get child lock"
920 "parent:"DFID" child:"DFID"\n",
921 PFID(mdt_object_fid(parent)),
922 PFID(mdt_object_fid(child)));
923 lustre_msg_clear_flags(req->rq_reqmsg, MSG_RESENT);
932 ma = &info->mti_attr;
934 mdt_lock_handle_init(lhc);
935 mdt_lock_reg_init(lhc, LCK_PR);
937 if (mdt_object_exists(child) == 0) {
938 LU_OBJECT_DEBUG(D_WARNING, info->mti_env,
939 &child->mot_obj.mo_lu,
940 "Object doesn't exist!\n");
944 ma->ma_need = MA_INODE;
945 rc = mo_attr_get(info->mti_env, next, ma);
946 if (unlikely(rc != 0))
949 /* If the file has not been changed for some time, we return
950 * not only a LOOKUP lock, but also an UPDATE lock and this
951 * might save us RPC on later STAT. For directories, it also
952 * let negative dentry starts working for this dir. */
953 if (ma->ma_valid & MA_INODE &&
954 ma->ma_attr.la_valid & LA_CTIME &&
955 info->mti_mdt->mdt_namespace->ns_ctime_age_limit +
956 ma->ma_attr.la_ctime < cfs_time_current_sec())
957 child_bits |= MDS_INODELOCK_UPDATE;
959 rc = mdt_object_lock(info, child, lhc, child_bits,
962 if (unlikely(rc != 0))
966 /* finally, we can get attr for child. */
967 mdt_set_capainfo(info, 1, child_fid, BYPASS_CAPA);
968 rc = mdt_getattr_internal(info, child);
969 if (unlikely(rc != 0)) {
970 mdt_object_unlock(info, child, lhc, 1);
972 lock = ldlm_handle2lock(&lhc->mlh_reg_lh);
974 struct mdt_body *repbody;
976 /* Debugging code. */
977 res_id = &lock->l_resource->lr_name;
978 LDLM_DEBUG(lock, "Returning lock to client\n");
979 LASSERTF(fid_res_name_eq(mdt_object_fid(child),
980 &lock->l_resource->lr_name),
981 "Lock res_id: %lu/%lu/%lu, Fid: "DFID".\n",
982 (unsigned long)res_id->name[0],
983 (unsigned long)res_id->name[1],
984 (unsigned long)res_id->name[2],
985 PFID(mdt_object_fid(child)));
987 * Pack Size-on-MDS inode attributes to the body if
988 * update lock is given.
990 repbody = req_capsule_server_get(info->mti_pill,
992 if (lock->l_policy_data.l_inodebits.bits &
993 MDS_INODELOCK_UPDATE)
994 mdt_pack_size2body(info, child);
1000 mdt_object_put(info->mti_env, child);
1002 mdt_object_unlock(info, parent, lhp, 1);
1006 /* normal handler: should release the child lock */
1007 static int mdt_getattr_name(struct mdt_thread_info *info)
1009 struct mdt_lock_handle *lhc = &info->mti_lh[MDT_LH_CHILD];
1010 struct mdt_body *reqbody;
1011 struct mdt_body *repbody;
1015 reqbody = req_capsule_client_get(info->mti_pill, &RMF_MDT_BODY);
1016 LASSERT(reqbody != NULL);
1017 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
1018 LASSERT(repbody != NULL);
1020 info->mti_spec.sp_ck_split = !!(reqbody->valid & OBD_MD_FLCKSPLIT);
1021 info->mti_cross_ref = !!(reqbody->valid & OBD_MD_FLCROSSREF);
1022 repbody->eadatasize = 0;
1023 repbody->aclsize = 0;
1025 rc = mdt_init_ucred(info, reqbody);
1027 GOTO(out_shrink, rc);
1029 rc = mdt_getattr_name_lock(info, lhc, MDS_INODELOCK_UPDATE, NULL);
1030 if (lustre_handle_is_used(&lhc->mlh_reg_lh)) {
1031 ldlm_lock_decref(&lhc->mlh_reg_lh, lhc->mlh_reg_mode);
1032 lhc->mlh_reg_lh.cookie = 0;
1034 mdt_exit_ucred(info);
1037 mdt_shrink_reply(info);
1041 static struct lu_device_operations mdt_lu_ops;
1043 static int lu_device_is_mdt(struct lu_device *d)
1045 return ergo(d != NULL && d->ld_ops != NULL, d->ld_ops == &mdt_lu_ops);
1048 static int mdt_set_info(struct mdt_thread_info *info)
1050 struct ptlrpc_request *req = mdt_info_req(info);
1056 rc = req_capsule_server_pack(info->mti_pill);
1060 key = req_capsule_client_get(info->mti_pill, &RMF_SETINFO_KEY);
1062 DEBUG_REQ(D_HA, req, "no set_info key");
1066 keylen = req_capsule_get_size(info->mti_pill, &RMF_SETINFO_KEY,
1069 val = req_capsule_client_get(info->mti_pill, &RMF_SETINFO_VAL);
1071 DEBUG_REQ(D_HA, req, "no set_info val");
1075 if (keylen != (sizeof(KEY_READ_ONLY) - 1) ||
1076 memcmp(key, KEY_READ_ONLY, keylen) != 0)
1080 lustre_msg_set_status(req->rq_repmsg, 0);
1082 spin_lock(&req->rq_export->exp_lock);
1084 req->rq_export->exp_connect_flags |= OBD_CONNECT_RDONLY;
1086 req->rq_export->exp_connect_flags &= ~OBD_CONNECT_RDONLY;
1087 spin_unlock(&req->rq_export->exp_lock);
1092 static int mdt_connect(struct mdt_thread_info *info)
1095 struct ptlrpc_request *req;
1097 req = mdt_info_req(info);
1098 rc = target_handle_connect(req);
1100 LASSERT(req->rq_export != NULL);
1101 info->mti_mdt = mdt_dev(req->rq_export->exp_obd->obd_lu_dev);
1102 rc = mdt_init_idmap(info);
1104 /* if mdt_init_idmap failed, revocation for connect */
1105 obd_disconnect(class_export_get(req->rq_export));
1107 rc = err_serious(rc);
1111 static int mdt_disconnect(struct mdt_thread_info *info)
1116 rc = target_handle_disconnect(mdt_info_req(info));
1118 rc = err_serious(rc);
1122 static int mdt_sendpage(struct mdt_thread_info *info,
1123 struct lu_rdpg *rdpg)
1125 struct ptlrpc_request *req = mdt_info_req(info);
1126 struct ptlrpc_bulk_desc *desc;
1127 struct l_wait_info *lwi = &info->mti_u.rdpg.mti_wait_info;
1135 desc = ptlrpc_prep_bulk_exp(req, rdpg->rp_npages, BULK_PUT_SOURCE,
1140 for (i = 0, tmpcount = rdpg->rp_count;
1141 i < rdpg->rp_npages; i++, tmpcount -= tmpsize) {
1142 tmpsize = min_t(int, tmpcount, CFS_PAGE_SIZE);
1143 ptlrpc_prep_bulk_page(desc, rdpg->rp_pages[i], 0, tmpsize);
1146 LASSERT(desc->bd_nob == rdpg->rp_count);
1147 rc = ptlrpc_start_bulk_transfer(desc);
1149 GOTO(free_desc, rc);
1151 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_SENDPAGE))
1152 GOTO(abort_bulk, rc = 0);
1154 timeout = (int) req->rq_deadline - cfs_time_current_sec();
1156 CERROR("Req deadline already passed %lu (now: %lu)\n",
1157 req->rq_deadline, cfs_time_current_sec());
1158 *lwi = LWI_TIMEOUT(max(timeout, 1) * HZ, NULL, NULL);
1159 rc = l_wait_event(desc->bd_waitq, !ptlrpc_bulk_active(desc), lwi);
1160 LASSERT (rc == 0 || rc == -ETIMEDOUT);
1163 if (desc->bd_success &&
1164 desc->bd_nob_transferred == rdpg->rp_count)
1165 GOTO(free_desc, rc);
1167 rc = -ETIMEDOUT; /* XXX should this be a different errno? */
1170 DEBUG_REQ(D_ERROR, req, "bulk failed: %s %d(%d), evicting %s@%s",
1171 (rc == -ETIMEDOUT) ? "timeout" : "network error",
1172 desc->bd_nob_transferred, rdpg->rp_count,
1173 req->rq_export->exp_client_uuid.uuid,
1174 req->rq_export->exp_connection->c_remote_uuid.uuid);
1176 class_fail_export(req->rq_export);
1180 ptlrpc_abort_bulk(desc);
1182 ptlrpc_free_bulk(desc);
1186 #ifdef HAVE_SPLIT_SUPPORT
1188 * Retrieve dir entry from the page and insert it to the slave object, actually,
1189 * this should be in osd layer, but since it will not in the final product, so
1190 * just do it here and do not define more moo api anymore for this.
1192 static int mdt_write_dir_page(struct mdt_thread_info *info, struct page *page,
1195 struct mdt_object *object = info->mti_object;
1196 struct lu_fid *lf = &info->mti_tmp_fid2;
1197 struct md_attr *ma = &info->mti_attr;
1198 struct lu_dirpage *dp;
1199 struct lu_dirent *ent;
1200 int rc = 0, offset = 0;
1203 /* Make sure we have at least one entry. */
1208 * Disable trans for this name insert, since it will include many trans
1211 info->mti_no_need_trans = 1;
1213 * When write_dir_page, no need update parent's ctime,
1214 * and no permission check for name_insert.
1216 ma->ma_attr.la_ctime = 0;
1217 ma->ma_attr.la_valid = LA_MODE;
1218 ma->ma_valid = MA_INODE;
1221 dp = page_address(page);
1222 offset = (int)((__u32)lu_dirent_start(dp) - (__u32)dp);
1224 for (ent = lu_dirent_start(dp); ent != NULL;
1225 ent = lu_dirent_next(ent)) {
1226 struct lu_name *lname;
1229 if (le16_to_cpu(ent->lde_namelen) == 0)
1232 fid_le_to_cpu(lf, &ent->lde_fid);
1233 if (le32_to_cpu(ent->lde_hash) & MAX_HASH_HIGHEST_BIT)
1234 ma->ma_attr.la_mode = S_IFDIR;
1236 ma->ma_attr.la_mode = 0;
1237 OBD_ALLOC(name, le16_to_cpu(ent->lde_namelen) + 1);
1239 GOTO(out, rc = -ENOMEM);
1241 memcpy(name, ent->lde_name, le16_to_cpu(ent->lde_namelen));
1242 lname = mdt_name(info->mti_env, name,
1243 le16_to_cpu(ent->lde_namelen) + 1);
1244 ma->ma_attr_flags |= MDS_PERM_BYPASS;
1245 rc = mdo_name_insert(info->mti_env,
1246 md_object_next(&object->mot_obj),
1248 OBD_FREE(name, le16_to_cpu(ent->lde_namelen) + 1);
1250 CERROR("Can't insert %*.*s, rc %d\n",
1251 le16_to_cpu(ent->lde_namelen),
1252 le16_to_cpu(ent->lde_namelen),
1257 offset += lu_dirent_size(ent);
1267 static int mdt_bulk_timeout(void *data)
1271 CERROR("mdt bulk transfer timeout \n");
1276 static int mdt_writepage(struct mdt_thread_info *info)
1278 struct ptlrpc_request *req = mdt_info_req(info);
1279 struct mdt_body *reqbody;
1280 struct l_wait_info *lwi;
1281 struct ptlrpc_bulk_desc *desc;
1287 reqbody = req_capsule_client_get(info->mti_pill, &RMF_MDT_BODY);
1288 if (reqbody == NULL)
1289 RETURN(err_serious(-EFAULT));
1291 desc = ptlrpc_prep_bulk_exp(req, 1, BULK_GET_SINK, MDS_BULK_PORTAL);
1293 RETURN(err_serious(-ENOMEM));
1295 /* allocate the page for the desc */
1296 page = cfs_alloc_page(CFS_ALLOC_STD);
1298 GOTO(desc_cleanup, rc = -ENOMEM);
1300 CDEBUG(D_INFO, "Received page offset %d size %d \n",
1301 (int)reqbody->size, (int)reqbody->nlink);
1303 ptlrpc_prep_bulk_page(desc, page, (int)reqbody->size,
1304 (int)reqbody->nlink);
1307 * Check if client was evicted while we were doing i/o before touching
1312 GOTO(cleanup_page, rc = -ENOMEM);
1314 if (desc->bd_export->exp_failed)
1317 rc = ptlrpc_start_bulk_transfer (desc);
1319 *lwi = LWI_TIMEOUT_INTERVAL(obd_timeout * HZ / 4, HZ,
1320 mdt_bulk_timeout, desc);
1321 rc = l_wait_event(desc->bd_waitq, !ptlrpc_bulk_active(desc) ||
1322 desc->bd_export->exp_failed, lwi);
1323 LASSERT(rc == 0 || rc == -ETIMEDOUT);
1324 if (rc == -ETIMEDOUT) {
1325 DEBUG_REQ(D_ERROR, req, "timeout on bulk GET");
1326 ptlrpc_abort_bulk(desc);
1327 } else if (desc->bd_export->exp_failed) {
1328 DEBUG_REQ(D_ERROR, req, "Eviction on bulk GET");
1330 ptlrpc_abort_bulk(desc);
1331 } else if (!desc->bd_success ||
1332 desc->bd_nob_transferred != desc->bd_nob) {
1333 DEBUG_REQ(D_ERROR, req, "%s bulk GET %d(%d)",
1335 "truncated" : "network error on",
1336 desc->bd_nob_transferred, desc->bd_nob);
1337 /* XXX should this be a different errno? */
1341 DEBUG_REQ(D_ERROR, req, "ptlrpc_bulk_get failed: rc %d", rc);
1344 GOTO(cleanup_lwi, rc);
1345 rc = mdt_write_dir_page(info, page, reqbody->nlink);
1350 cfs_free_page(page);
1352 ptlrpc_free_bulk(desc);
1357 static int mdt_readpage(struct mdt_thread_info *info)
1359 struct mdt_object *object = info->mti_object;
1360 struct lu_rdpg *rdpg = &info->mti_u.rdpg.mti_rdpg;
1361 struct mdt_body *reqbody;
1362 struct mdt_body *repbody;
1367 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_READPAGE_PACK))
1368 RETURN(err_serious(-ENOMEM));
1370 reqbody = req_capsule_client_get(info->mti_pill, &RMF_MDT_BODY);
1371 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
1372 if (reqbody == NULL || repbody == NULL)
1373 RETURN(err_serious(-EFAULT));
1376 * prepare @rdpg before calling lower layers and transfer itself. Here
1377 * reqbody->size contains offset of where to start to read and
1378 * reqbody->nlink contains number bytes to read.
1380 rdpg->rp_hash = reqbody->size;
1381 if ((__u64)rdpg->rp_hash != reqbody->size) {
1382 CERROR("Invalid hash: %#llx != %#llx\n",
1383 (__u64)rdpg->rp_hash, reqbody->size);
1386 rdpg->rp_count = reqbody->nlink;
1387 rdpg->rp_npages = (rdpg->rp_count + CFS_PAGE_SIZE - 1)>>CFS_PAGE_SHIFT;
1388 OBD_ALLOC(rdpg->rp_pages, rdpg->rp_npages * sizeof rdpg->rp_pages[0]);
1389 if (rdpg->rp_pages == NULL)
1392 for (i = 0; i < rdpg->rp_npages; ++i) {
1393 rdpg->rp_pages[i] = cfs_alloc_page(CFS_ALLOC_STD);
1394 if (rdpg->rp_pages[i] == NULL)
1395 GOTO(free_rdpg, rc = -ENOMEM);
1398 /* call lower layers to fill allocated pages with directory data */
1399 rc = mo_readpage(info->mti_env, mdt_object_child(object), rdpg);
1401 GOTO(free_rdpg, rc);
1403 /* send pages to client */
1404 rc = mdt_sendpage(info, rdpg);
1409 for (i = 0; i < rdpg->rp_npages; i++)
1410 if (rdpg->rp_pages[i] != NULL)
1411 cfs_free_page(rdpg->rp_pages[i]);
1412 OBD_FREE(rdpg->rp_pages, rdpg->rp_npages * sizeof rdpg->rp_pages[0]);
1414 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_SENDPAGE))
1420 static int mdt_reint_internal(struct mdt_thread_info *info,
1421 struct mdt_lock_handle *lhc,
1424 struct req_capsule *pill = info->mti_pill;
1425 struct mdt_device *mdt = info->mti_mdt;
1426 struct mdt_body *repbody;
1431 if (req_capsule_has_field(pill, &RMF_MDT_MD, RCL_SERVER))
1432 req_capsule_set_size(pill, &RMF_MDT_MD, RCL_SERVER,
1433 mdt->mdt_max_mdsize);
1434 if (req_capsule_has_field(pill, &RMF_LOGCOOKIES, RCL_SERVER))
1435 req_capsule_set_size(pill, &RMF_LOGCOOKIES, RCL_SERVER,
1436 mdt->mdt_max_cookiesize);
1438 rc = req_capsule_server_pack(pill);
1440 CERROR("Can't pack response, rc %d\n", rc);
1441 RETURN(err_serious(rc));
1444 if (req_capsule_has_field(pill, &RMF_MDT_BODY, RCL_SERVER)) {
1445 repbody = req_capsule_server_get(pill, &RMF_MDT_BODY);
1447 repbody->eadatasize = 0;
1448 repbody->aclsize = 0;
1451 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_REINT_UNPACK))
1452 GOTO(out_shrink, rc = err_serious(-EFAULT));
1454 rc = mdt_reint_unpack(info, op);
1456 CERROR("Can't unpack reint, rc %d\n", rc);
1457 GOTO(out_shrink, rc = err_serious(rc));
1460 rc = mdt_init_ucred_reint(info);
1462 GOTO(out_shrink, rc);
1464 rc = mdt_fix_attr_ucred(info, op);
1466 GOTO(out_ucred, rc = err_serious(rc));
1468 if (mdt_check_resent(info, mdt_reconstruct, lhc)) {
1469 rc = lustre_msg_get_status(mdt_info_req(info)->rq_repmsg);
1470 GOTO(out_ucred, rc);
1472 rc = mdt_reint_rec(info, lhc);
1475 mdt_exit_ucred(info);
1477 mdt_shrink_reply(info);
1481 static long mdt_reint_opcode(struct mdt_thread_info *info,
1482 const struct req_format **fmt)
1484 struct mdt_rec_reint *rec;
1487 opc = err_serious(-EFAULT);
1488 rec = req_capsule_client_get(info->mti_pill, &RMF_REC_REINT);
1490 opc = rec->rr_opcode;
1491 DEBUG_REQ(D_INODE, mdt_info_req(info), "reint opt = %ld", opc);
1492 if (opc < REINT_MAX && fmt[opc] != NULL)
1493 req_capsule_extend(info->mti_pill, fmt[opc]);
1495 CERROR("Unsupported opc: %ld\n", opc);
1496 opc = err_serious(opc);
1502 static int mdt_reint(struct mdt_thread_info *info)
1507 static const struct req_format *reint_fmts[REINT_MAX] = {
1508 [REINT_SETATTR] = &RQF_MDS_REINT_SETATTR,
1509 [REINT_CREATE] = &RQF_MDS_REINT_CREATE,
1510 [REINT_LINK] = &RQF_MDS_REINT_LINK,
1511 [REINT_UNLINK] = &RQF_MDS_REINT_UNLINK,
1512 [REINT_RENAME] = &RQF_MDS_REINT_RENAME,
1513 [REINT_OPEN] = &RQF_MDS_REINT_OPEN,
1514 [REINT_SETXATTR] = &RQF_MDS_REINT_SETXATTR
1519 opc = mdt_reint_opcode(info, reint_fmts);
1522 * No lock possible here from client to pass it to reint code
1525 rc = mdt_reint_internal(info, NULL, opc);
1530 info->mti_fail_id = OBD_FAIL_MDS_REINT_NET_REP;
1534 /* TODO these two methods not available now. */
1536 /* this should sync the whole device */
1537 static int mdt_device_sync(struct mdt_thread_info *info)
1542 /* this should sync this object */
1543 static int mdt_object_sync(struct mdt_thread_info *info)
1548 static int mdt_sync(struct mdt_thread_info *info)
1550 struct req_capsule *pill = info->mti_pill;
1551 struct mdt_body *body;
1555 /* The fid may be zero, so we req_capsule_set manually */
1556 req_capsule_set(pill, &RQF_MDS_SYNC);
1558 body = req_capsule_client_get(pill, &RMF_MDT_BODY);
1560 RETURN(err_serious(-EINVAL));
1562 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_SYNC_PACK))
1563 RETURN(err_serious(-ENOMEM));
1565 if (fid_seq(&body->fid1) == 0) {
1566 /* sync the whole device */
1567 rc = req_capsule_server_pack(pill);
1569 rc = mdt_device_sync(info);
1571 rc = err_serious(rc);
1573 /* sync an object */
1574 rc = mdt_unpack_req_pack_rep(info, HABEO_CORPUS|HABEO_REFERO);
1576 rc = mdt_object_sync(info);
1578 struct md_object *next;
1579 const struct lu_fid *fid;
1580 struct lu_attr *la = &info->mti_attr.ma_attr;
1582 next = mdt_object_child(info->mti_object);
1583 info->mti_attr.ma_need = MA_INODE;
1584 info->mti_attr.ma_valid = 0;
1585 rc = mo_attr_get(info->mti_env, next,
1588 body = req_capsule_server_get(pill,
1590 fid = mdt_object_fid(info->mti_object);
1591 mdt_pack_attr2body(info, body, la, fid);
1595 rc = err_serious(rc);
1600 static int mdt_quotacheck_handle(struct mdt_thread_info *info)
1602 return err_serious(-EOPNOTSUPP);
1605 static int mdt_quotactl_handle(struct mdt_thread_info *info)
1607 return err_serious(-EOPNOTSUPP);
1611 * OBD PING and other handlers.
1613 static int mdt_obd_ping(struct mdt_thread_info *info)
1618 req_capsule_set(info->mti_pill, &RQF_OBD_PING);
1620 rc = target_handle_ping(mdt_info_req(info));
1622 rc = err_serious(rc);
1626 static int mdt_obd_log_cancel(struct mdt_thread_info *info)
1628 return err_serious(-EOPNOTSUPP);
1631 static int mdt_obd_qc_callback(struct mdt_thread_info *info)
1633 return err_serious(-EOPNOTSUPP);
1640 static struct ldlm_callback_suite cbs = {
1641 .lcs_completion = ldlm_server_completion_ast,
1642 .lcs_blocking = ldlm_server_blocking_ast,
1646 static int mdt_enqueue(struct mdt_thread_info *info)
1648 struct ptlrpc_request *req;
1653 * info->mti_dlm_req already contains swapped and (if necessary)
1654 * converted dlm request.
1656 LASSERT(info->mti_dlm_req != NULL);
1658 req = mdt_info_req(info);
1661 * Lock without inodebits makes no sense and will oops later in
1662 * ldlm. Let's check it now to see if we have wrong lock from client or
1663 * bits get corrupted somewhere in mdt_intent_policy().
1665 req_bits = info->mti_dlm_req->lock_desc.l_policy_data.l_inodebits.bits;
1666 /* This is disabled because we need to support liblustre flock.
1667 * LASSERT(req_bits != 0);
1670 rc = ldlm_handle_enqueue0(info->mti_mdt->mdt_namespace,
1671 req, info->mti_dlm_req, &cbs);
1672 info->mti_fail_id = OBD_FAIL_LDLM_REPLY;
1673 return rc ? err_serious(rc) : req->rq_status;
1676 static int mdt_convert(struct mdt_thread_info *info)
1679 struct ptlrpc_request *req;
1681 LASSERT(info->mti_dlm_req);
1682 req = mdt_info_req(info);
1683 rc = ldlm_handle_convert0(req, info->mti_dlm_req);
1684 return rc ? err_serious(rc) : req->rq_status;
1687 static int mdt_bl_callback(struct mdt_thread_info *info)
1689 CERROR("bl callbacks should not happen on MDS\n");
1691 return err_serious(-EOPNOTSUPP);
1694 static int mdt_cp_callback(struct mdt_thread_info *info)
1696 CERROR("cp callbacks should not happen on MDS\n");
1698 return err_serious(-EOPNOTSUPP);
1702 * sec context handlers
1704 static int mdt_sec_ctx_handle(struct mdt_thread_info *info)
1708 rc = mdt_handle_idmap(info);
1711 struct ptlrpc_request *req = mdt_info_req(info);
1714 opc = lustre_msg_get_opc(req->rq_reqmsg);
1715 if (opc == SEC_CTX_INIT || opc == SEC_CTX_INIT_CONT)
1716 sptlrpc_svc_ctx_invalidate(req);
1719 OBD_FAIL_TIMEOUT(OBD_FAIL_SEC_CTX_HDL_PAUSE, obd_fail_val);
1724 static struct mdt_object *mdt_obj(struct lu_object *o)
1726 LASSERT(lu_device_is_mdt(o->lo_dev));
1727 return container_of0(o, struct mdt_object, mot_obj.mo_lu);
1730 struct mdt_object *mdt_object_find(const struct lu_env *env,
1731 struct mdt_device *d,
1732 const struct lu_fid *f)
1734 struct lu_object *o;
1735 struct mdt_object *m;
1738 CDEBUG(D_INFO, "Find object for "DFID"\n", PFID(f));
1739 o = lu_object_find(env, d->mdt_md_dev.md_lu_dev.ld_site, f);
1740 if (unlikely(IS_ERR(o)))
1741 m = (struct mdt_object *)o;
1747 int mdt_object_lock(struct mdt_thread_info *info, struct mdt_object *o,
1748 struct mdt_lock_handle *lh, __u64 ibits, int locality)
1750 struct ldlm_namespace *ns = info->mti_mdt->mdt_namespace;
1751 ldlm_policy_data_t *policy = &info->mti_policy;
1752 struct ldlm_res_id *res_id = &info->mti_res_id;
1756 LASSERT(!lustre_handle_is_used(&lh->mlh_reg_lh));
1757 LASSERT(!lustre_handle_is_used(&lh->mlh_pdo_lh));
1758 LASSERT(lh->mlh_reg_mode != LCK_MINMODE);
1759 LASSERT(lh->mlh_type != MDT_NUL_LOCK);
1761 if (mdt_object_exists(o) < 0) {
1762 if (locality == MDT_CROSS_LOCK) {
1763 /* cross-ref object fix */
1764 ibits &= ~MDS_INODELOCK_UPDATE;
1765 ibits |= MDS_INODELOCK_LOOKUP;
1767 LASSERT(!(ibits & MDS_INODELOCK_UPDATE));
1768 LASSERT(ibits & MDS_INODELOCK_LOOKUP);
1770 /* No PDO lock on remote object */
1771 LASSERT(lh->mlh_type != MDT_PDO_LOCK);
1774 memset(policy, 0, sizeof(*policy));
1775 fid_build_reg_res_name(mdt_object_fid(o), res_id);
1778 * Take PDO lock on whole directory and build correct @res_id for lock
1779 * on part of directory.
1781 if (lh->mlh_pdo_hash != 0) {
1782 LASSERT(lh->mlh_type == MDT_PDO_LOCK);
1783 mdt_lock_pdo_mode(info, o, lh);
1784 if (lh->mlh_pdo_mode != LCK_NL) {
1786 * Do not use LDLM_FL_LOCAL_ONLY for parallel lock, it
1787 * is never going to be sent to client and we do not
1788 * want it slowed down due to possible cancels.
1790 policy->l_inodebits.bits = MDS_INODELOCK_UPDATE;
1791 rc = mdt_fid_lock(ns, &lh->mlh_pdo_lh, lh->mlh_pdo_mode,
1792 policy, res_id, LDLM_FL_ATOMIC_CB);
1798 * Finish res_id initializing by name hash marking patr of
1799 * directory which is taking modification.
1801 res_id->name[LUSTRE_RES_ID_HSH_OFF] = lh->mlh_pdo_hash;
1804 policy->l_inodebits.bits = ibits;
1807 * Use LDLM_FL_LOCAL_ONLY for this lock. We do not know yet if it is
1808 * going to be sent to client. If it is - mdt_intent_policy() path will
1809 * fix it up and turns FL_LOCAL flag off.
1811 rc = mdt_fid_lock(ns, &lh->mlh_reg_lh, lh->mlh_reg_mode, policy,
1812 res_id, LDLM_FL_LOCAL_ONLY | LDLM_FL_ATOMIC_CB);
1817 if (lh->mlh_type == MDT_PDO_LOCK) {
1818 /* check for exists after object is locked */
1819 if (mdt_object_exists(o) == 0) {
1820 /* Non-existent object shouldn't have PDO lock */
1823 /* Non-dir object shouldn't have PDO lock */
1824 LASSERT(S_ISDIR(lu_object_attr(&o->mot_obj.mo_lu)));
1829 mdt_object_unlock(info, o, lh, 1);
1836 * Just call ldlm_lock_decref() if decref, else we only call ptlrpc_save_lock()
1837 * to save this lock in req. when transaction committed, req will be released,
1838 * and lock will, too.
1840 void mdt_object_unlock(struct mdt_thread_info *info, struct mdt_object *o,
1841 struct mdt_lock_handle *lh, int decref)
1843 struct ptlrpc_request *req = mdt_info_req(info);
1846 if (lustre_handle_is_used(&lh->mlh_pdo_lh)) {
1847 /* Do not save PDO locks to request, just decref. */
1848 mdt_fid_unlock(&lh->mlh_pdo_lh,
1850 lh->mlh_pdo_lh.cookie = 0ull;
1853 if (lustre_handle_is_used(&lh->mlh_reg_lh)) {
1855 mdt_fid_unlock(&lh->mlh_reg_lh,
1858 ptlrpc_save_lock(req, &lh->mlh_reg_lh,
1861 lh->mlh_reg_lh.cookie = 0ull;
1867 struct mdt_object *mdt_object_find_lock(struct mdt_thread_info *info,
1868 const struct lu_fid *f,
1869 struct mdt_lock_handle *lh,
1872 struct mdt_object *o;
1874 o = mdt_object_find(info->mti_env, info->mti_mdt, f);
1878 rc = mdt_object_lock(info, o, lh, ibits,
1881 mdt_object_put(info->mti_env, o);
1888 void mdt_object_unlock_put(struct mdt_thread_info * info,
1889 struct mdt_object * o,
1890 struct mdt_lock_handle *lh,
1893 mdt_object_unlock(info, o, lh, decref);
1894 mdt_object_put(info->mti_env, o);
1897 static struct mdt_handler *mdt_handler_find(__u32 opc,
1898 struct mdt_opc_slice *supported)
1900 struct mdt_opc_slice *s;
1901 struct mdt_handler *h;
1904 for (s = supported; s->mos_hs != NULL; s++) {
1905 if (s->mos_opc_start <= opc && opc < s->mos_opc_end) {
1906 h = s->mos_hs + (opc - s->mos_opc_start);
1907 if (likely(h->mh_opc != 0))
1908 LASSERT(h->mh_opc == opc);
1910 h = NULL; /* unsupported opc */
1917 static int mdt_lock_resname_compat(struct mdt_device *m,
1918 struct ldlm_request *req)
1920 /* XXX something... later. */
1924 static int mdt_lock_reply_compat(struct mdt_device *m, struct ldlm_reply *rep)
1926 /* XXX something... later. */
1931 * Generic code handling requests that have struct mdt_body passed in:
1933 * - extract mdt_body from request and save it in @info, if present;
1935 * - create lu_object, corresponding to the fid in mdt_body, and save it in
1938 * - if HABEO_CORPUS flag is set for this request type check whether object
1939 * actually exists on storage (lu_object_exists()).
1942 static int mdt_body_unpack(struct mdt_thread_info *info, __u32 flags)
1944 const struct mdt_body *body;
1945 struct mdt_object *obj;
1946 const struct lu_env *env;
1947 struct req_capsule *pill;
1951 env = info->mti_env;
1952 pill = info->mti_pill;
1954 body = info->mti_body = req_capsule_client_get(pill, &RMF_MDT_BODY);
1958 if (!(body->valid & OBD_MD_FLID))
1961 if (!fid_is_sane(&body->fid1)) {
1962 CERROR("Invalid fid: "DFID"\n", PFID(&body->fid1));
1967 * Do not get size or any capa fields before we check that request
1968 * contains capa actually. There are some requests which do not, for
1969 * instance MDS_IS_SUBDIR.
1971 if (req_capsule_has_field(pill, &RMF_CAPA1, RCL_CLIENT) &&
1972 req_capsule_get_size(pill, &RMF_CAPA1, RCL_CLIENT))
1973 mdt_set_capainfo(info, 0, &body->fid1,
1974 req_capsule_client_get(pill, &RMF_CAPA1));
1976 obj = mdt_object_find(env, info->mti_mdt, &body->fid1);
1978 if ((flags & HABEO_CORPUS) &&
1979 !mdt_object_exists(obj)) {
1980 mdt_object_put(env, obj);
1981 /* for capability renew ENOENT will be handled in
1983 if (body->valid & OBD_MD_FLOSSCAPA)
1988 info->mti_object = obj;
1997 static int mdt_unpack_req_pack_rep(struct mdt_thread_info *info, __u32 flags)
1999 struct req_capsule *pill = info->mti_pill;
2003 if (req_capsule_has_field(pill, &RMF_MDT_BODY, RCL_CLIENT))
2004 rc = mdt_body_unpack(info, flags);
2008 if (rc == 0 && (flags & HABEO_REFERO)) {
2009 struct mdt_device *mdt = info->mti_mdt;
2012 if (req_capsule_has_field(pill, &RMF_MDT_MD, RCL_SERVER))
2013 req_capsule_set_size(pill, &RMF_MDT_MD, RCL_SERVER,
2014 mdt->mdt_max_mdsize);
2015 if (req_capsule_has_field(pill, &RMF_LOGCOOKIES, RCL_SERVER))
2016 req_capsule_set_size(pill, &RMF_LOGCOOKIES, RCL_SERVER,
2017 mdt->mdt_max_cookiesize);
2019 rc = req_capsule_server_pack(pill);
2024 static int mdt_init_capa_ctxt(const struct lu_env *env, struct mdt_device *m)
2026 struct md_device *next = m->mdt_child;
2028 return next->md_ops->mdo_init_capa_ctxt(env, next,
2029 m->mdt_opts.mo_mds_capa,
2030 m->mdt_capa_timeout,
2036 * Invoke handler for this request opc. Also do necessary preprocessing
2037 * (according to handler ->mh_flags), and post-processing (setting of
2038 * ->last_{xid,committed}).
2040 static int mdt_req_handle(struct mdt_thread_info *info,
2041 struct mdt_handler *h, struct ptlrpc_request *req)
2043 int rc, serious = 0;
2048 LASSERT(h->mh_act != NULL);
2049 LASSERT(h->mh_opc == lustre_msg_get_opc(req->rq_reqmsg));
2050 LASSERT(current->journal_info == NULL);
2053 * Checking for various OBD_FAIL_$PREF_$OPC_NET codes. _Do_ not try
2054 * to put same checks into handlers like mdt_close(), mdt_reint(),
2055 * etc., without talking to mdt authors first. Checking same thing
2056 * there again is useless and returning 0 error wihtout packing reply
2057 * is buggy! Handlers either pack reply or return error.
2059 * We return 0 here and do not send any reply in order to emulate
2060 * network failure. Do not send any reply in case any of NET related
2061 * fail_id has occured.
2063 if (OBD_FAIL_CHECK_ORSET(h->mh_fail_id, OBD_FAIL_ONCE))
2067 flags = h->mh_flags;
2068 LASSERT(ergo(flags & (HABEO_CORPUS|HABEO_REFERO), h->mh_fmt != NULL));
2070 if (h->mh_fmt != NULL) {
2071 req_capsule_set(info->mti_pill, h->mh_fmt);
2072 rc = mdt_unpack_req_pack_rep(info, flags);
2075 if (rc == 0 && flags & MUTABOR &&
2076 req->rq_export->exp_connect_flags & OBD_CONNECT_RDONLY)
2077 /* should it be rq_status? */
2080 if (rc == 0 && flags & HABEO_CLAVIS) {
2081 struct ldlm_request *dlm_req;
2083 LASSERT(h->mh_fmt != NULL);
2085 dlm_req = req_capsule_client_get(info->mti_pill, &RMF_DLM_REQ);
2086 if (dlm_req != NULL) {
2087 if (info->mti_mdt->mdt_opts.mo_compat_resname)
2088 rc = mdt_lock_resname_compat(info->mti_mdt,
2090 info->mti_dlm_req = dlm_req;
2096 /* capability setting changed via /proc, needs reinitialize ctxt */
2097 if (info->mti_mdt && info->mti_mdt->mdt_capa_conf) {
2098 mdt_init_capa_ctxt(info->mti_env, info->mti_mdt);
2099 info->mti_mdt->mdt_capa_conf = 0;
2102 if (likely(rc == 0)) {
2104 * Process request, there can be two types of rc:
2105 * 1) errors with msg unpack/pack, other failures outside the
2106 * operation itself. This is counted as serious errors;
2107 * 2) errors during fs operation, should be placed in rq_status
2110 rc = h->mh_act(info);
2112 !req->rq_no_reply && req->rq_reply_state == NULL) {
2113 DEBUG_REQ(D_ERROR, req, "MDT \"handler\" %s did not "
2114 "pack reply and returned 0 error\n",
2118 serious = is_serious(rc);
2119 rc = clear_serious(rc);
2123 req->rq_status = rc;
2126 * ELDLM_* codes which > 0 should be in rq_status only as well as
2127 * all non-serious errors.
2129 if (rc > 0 || !serious)
2132 LASSERT(current->journal_info == NULL);
2134 if (rc == 0 && (flags & HABEO_CLAVIS) &&
2135 info->mti_mdt->mdt_opts.mo_compat_resname) {
2136 struct ldlm_reply *dlmrep;
2138 dlmrep = req_capsule_server_get(info->mti_pill, &RMF_DLM_REP);
2140 rc = mdt_lock_reply_compat(info->mti_mdt, dlmrep);
2143 /* If we're DISCONNECTing, the mdt_export_data is already freed */
2144 if (likely(rc == 0 && h->mh_opc != MDS_DISCONNECT))
2145 target_committed_to_req(req);
2147 if (unlikely((lustre_msg_get_flags(req->rq_reqmsg) & MSG_REPLAY) &&
2148 lustre_msg_get_transno(req->rq_reqmsg) == 0)) {
2149 DEBUG_REQ(D_ERROR, req, "transno is 0 during REPLAY");
2153 target_send_reply(req, rc, info->mti_fail_id);
2157 void mdt_lock_handle_init(struct mdt_lock_handle *lh)
2159 lh->mlh_type = MDT_NUL_LOCK;
2160 lh->mlh_reg_lh.cookie = 0ull;
2161 lh->mlh_reg_mode = LCK_MINMODE;
2162 lh->mlh_pdo_lh.cookie = 0ull;
2163 lh->mlh_pdo_mode = LCK_MINMODE;
2166 void mdt_lock_handle_fini(struct mdt_lock_handle *lh)
2168 LASSERT(!lustre_handle_is_used(&lh->mlh_reg_lh));
2169 LASSERT(!lustre_handle_is_used(&lh->mlh_pdo_lh));
2173 * Initialize fields of struct mdt_thread_info. Other fields are left in
2174 * uninitialized state, because it's too expensive to zero out whole
2175 * mdt_thread_info (> 1K) on each request arrival.
2177 static void mdt_thread_info_init(struct ptlrpc_request *req,
2178 struct mdt_thread_info *info)
2181 struct md_capainfo *ci;
2183 req_capsule_init(&req->rq_pill, req, RCL_SERVER);
2184 info->mti_pill = &req->rq_pill;
2187 for (i = 0; i < ARRAY_SIZE(info->mti_lh); i++)
2188 mdt_lock_handle_init(&info->mti_lh[i]);
2190 /* mdt device: it can be NULL while CONNECT */
2191 if (req->rq_export) {
2192 info->mti_mdt = mdt_dev(req->rq_export->exp_obd->obd_lu_dev);
2193 info->mti_exp = req->rq_export;
2195 info->mti_mdt = NULL;
2196 info->mti_env = req->rq_svc_thread->t_env;
2197 ci = md_capainfo(info->mti_env);
2198 memset(ci, 0, sizeof *ci);
2200 info->mti_fail_id = OBD_FAIL_MDS_ALL_REPLY_NET;
2201 info->mti_transno = lustre_msg_get_transno(req->rq_reqmsg);
2203 memset(&info->mti_attr, 0, sizeof(info->mti_attr));
2204 info->mti_body = NULL;
2205 info->mti_object = NULL;
2206 info->mti_dlm_req = NULL;
2207 info->mti_has_trans = 0;
2208 info->mti_no_need_trans = 0;
2209 info->mti_cross_ref = 0;
2210 info->mti_opdata = 0;
2212 /* To not check for split by default. */
2213 info->mti_spec.sp_ck_split = 0;
2216 static void mdt_thread_info_fini(struct mdt_thread_info *info)
2220 req_capsule_fini(info->mti_pill);
2221 if (info->mti_object != NULL) {
2222 mdt_object_put(info->mti_env, info->mti_object);
2223 info->mti_object = NULL;
2225 for (i = 0; i < ARRAY_SIZE(info->mti_lh); i++)
2226 mdt_lock_handle_fini(&info->mti_lh[i]);
2227 info->mti_env = NULL;
2230 static int mdt_filter_recovery_request(struct ptlrpc_request *req,
2231 struct obd_device *obd, int *process)
2233 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
2234 case MDS_CONNECT: /* This will never get here, but for completeness. */
2235 case OST_CONNECT: /* This will never get here, but for completeness. */
2236 case MDS_DISCONNECT:
2237 case OST_DISCONNECT:
2242 case MDS_DONE_WRITING:
2243 case MDS_SYNC: /* used in unmounting */
2249 *process = target_queue_recovery_request(req, obd);
2253 DEBUG_REQ(D_ERROR, req, "not permitted during recovery");
2260 * Handle recovery. Return:
2261 * +1: continue request processing;
2262 * -ve: abort immediately with the given error code;
2263 * 0: send reply with error code in req->rq_status;
2265 static int mdt_recovery(struct mdt_thread_info *info)
2267 struct ptlrpc_request *req = mdt_info_req(info);
2269 struct obd_device *obd;
2273 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
2276 case SEC_CTX_INIT_CONT:
2282 rc = mdt_handle_idmap(info);
2291 if (unlikely(req->rq_export == NULL)) {
2292 CERROR("operation %d on unconnected MDS from %s\n",
2293 lustre_msg_get_opc(req->rq_reqmsg),
2294 libcfs_id2str(req->rq_peer));
2295 /* FIXME: For CMD cleanup, when mds_B stop, the req from
2296 * mds_A will get -ENOTCONN(especially for ping req),
2297 * which will cause that mds_A deactive timeout, then when
2298 * mds_A cleanup, the cleanup process will be suspended since
2299 * deactive timeout is not zero.
2301 req->rq_status = -ENOTCONN;
2302 target_send_reply(req, -ENOTCONN, info->mti_fail_id);
2306 /* sanity check: if the xid matches, the request must be marked as a
2307 * resent or replayed */
2308 if (req_xid_is_last(req)) {
2309 if (!(lustre_msg_get_flags(req->rq_reqmsg) &
2310 (MSG_RESENT | MSG_REPLAY))) {
2311 DEBUG_REQ(D_WARNING, req, "rq_xid "LPU64" matches last_xid, "
2312 "expected REPLAY or RESENT flag (%x)", req->rq_xid,
2313 lustre_msg_get_flags(req->rq_reqmsg));
2315 req->rq_status = -ENOTCONN;
2320 /* else: note the opposite is not always true; a RESENT req after a
2321 * failover will usually not match the last_xid, since it was likely
2322 * never committed. A REPLAYed request will almost never match the
2323 * last xid, however it could for a committed, but still retained,
2326 obd = req->rq_export->exp_obd;
2328 /* Check for aborted recovery... */
2329 spin_lock_bh(&obd->obd_processing_task_lock);
2330 recovering = obd->obd_recovering;
2331 spin_unlock_bh(&obd->obd_processing_task_lock);
2332 if (unlikely(recovering)) {
2335 DEBUG_REQ(D_INFO, req, "Got new replay");
2336 rc = mdt_filter_recovery_request(req, obd, &should_process);
2337 if (rc != 0 || !should_process)
2339 else if (should_process < 0) {
2340 req->rq_status = should_process;
2341 rc = ptlrpc_error(req);
2348 static int mdt_msg_check_version(struct lustre_msg *msg)
2352 switch (lustre_msg_get_opc(msg)) {
2354 case MDS_DISCONNECT:
2357 case SEC_CTX_INIT_CONT:
2359 rc = lustre_msg_check_version(msg, LUSTRE_OBD_VERSION);
2361 CERROR("bad opc %u version %08x, expecting %08x\n",
2362 lustre_msg_get_opc(msg),
2363 lustre_msg_get_version(msg),
2364 LUSTRE_OBD_VERSION);
2368 case MDS_GETATTR_NAME:
2375 case MDS_DONE_WRITING:
2381 case MDS_QUOTACHECK:
2387 rc = lustre_msg_check_version(msg, LUSTRE_MDS_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_MDS_VERSION);
2396 case LDLM_BL_CALLBACK:
2397 case LDLM_CP_CALLBACK:
2398 rc = lustre_msg_check_version(msg, LUSTRE_DLM_VERSION);
2400 CERROR("bad opc %u version %08x, expecting %08x\n",
2401 lustre_msg_get_opc(msg),
2402 lustre_msg_get_version(msg),
2403 LUSTRE_DLM_VERSION);
2405 case OBD_LOG_CANCEL:
2406 case LLOG_ORIGIN_HANDLE_CREATE:
2407 case LLOG_ORIGIN_HANDLE_NEXT_BLOCK:
2408 case LLOG_ORIGIN_HANDLE_READ_HEADER:
2409 case LLOG_ORIGIN_HANDLE_CLOSE:
2410 case LLOG_ORIGIN_HANDLE_DESTROY:
2411 case LLOG_ORIGIN_HANDLE_PREV_BLOCK:
2413 rc = lustre_msg_check_version(msg, LUSTRE_LOG_VERSION);
2415 CERROR("bad opc %u version %08x, expecting %08x\n",
2416 lustre_msg_get_opc(msg),
2417 lustre_msg_get_version(msg),
2418 LUSTRE_LOG_VERSION);
2421 CERROR("MDS unknown opcode %d\n", lustre_msg_get_opc(msg));
2427 static int mdt_handle0(struct ptlrpc_request *req,
2428 struct mdt_thread_info *info,
2429 struct mdt_opc_slice *supported)
2431 struct mdt_handler *h;
2432 struct lustre_msg *msg;
2437 if (OBD_FAIL_CHECK_ORSET(OBD_FAIL_MDS_ALL_REQUEST_NET, OBD_FAIL_ONCE))
2440 LASSERT(current->journal_info == NULL);
2442 msg = req->rq_reqmsg;
2443 rc = mdt_msg_check_version(msg);
2444 if (likely(rc == 0)) {
2445 rc = mdt_recovery(info);
2446 if (likely(rc == +1)) {
2447 h = mdt_handler_find(lustre_msg_get_opc(msg),
2449 if (likely(h != NULL)) {
2450 rc = mdt_req_handle(info, h, req);
2452 CERROR("The unsupported opc: 0x%x\n", lustre_msg_get_opc(msg) );
2453 req->rq_status = -ENOTSUPP;
2454 rc = ptlrpc_error(req);
2459 CERROR(LUSTRE_MDT_NAME" drops mal-formed request\n");
2464 * MDT handler function called by ptlrpc service thread when request comes.
2466 * XXX common "target" functionality should be factored into separate module
2467 * shared by mdt, ost and stand-alone services like fld.
2469 static int mdt_handle_common(struct ptlrpc_request *req,
2470 struct mdt_opc_slice *supported)
2473 struct mdt_thread_info *info;
2477 env = req->rq_svc_thread->t_env;
2478 LASSERT(env != NULL);
2479 LASSERT(env->le_ses != NULL);
2480 LASSERT(env->le_ctx.lc_thread == req->rq_svc_thread);
2481 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
2482 LASSERT(info != NULL);
2484 mdt_thread_info_init(req, info);
2486 rc = mdt_handle0(req, info, supported);
2488 mdt_thread_info_fini(info);
2493 * This is called from recovery code as handler of _all_ RPC types, FLD and SEQ
2496 int mdt_recovery_handle(struct ptlrpc_request *req)
2501 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
2503 rc = mdt_handle_common(req, mdt_fld_handlers);
2506 rc = mdt_handle_common(req, mdt_seq_handlers);
2509 rc = mdt_handle_common(req, mdt_regular_handlers);
2516 static int mdt_regular_handle(struct ptlrpc_request *req)
2518 return mdt_handle_common(req, mdt_regular_handlers);
2521 static int mdt_readpage_handle(struct ptlrpc_request *req)
2523 return mdt_handle_common(req, mdt_readpage_handlers);
2526 static int mdt_xmds_handle(struct ptlrpc_request *req)
2528 return mdt_handle_common(req, mdt_xmds_handlers);
2531 static int mdt_mdsc_handle(struct ptlrpc_request *req)
2533 return mdt_handle_common(req, mdt_seq_handlers);
2536 static int mdt_mdss_handle(struct ptlrpc_request *req)
2538 return mdt_handle_common(req, mdt_seq_handlers);
2541 static int mdt_dtss_handle(struct ptlrpc_request *req)
2543 return mdt_handle_common(req, mdt_seq_handlers);
2546 static int mdt_fld_handle(struct ptlrpc_request *req)
2548 return mdt_handle_common(req, mdt_fld_handlers);
2564 static int mdt_intent_getattr(enum mdt_it_code opcode,
2565 struct mdt_thread_info *info,
2566 struct ldlm_lock **,
2568 static int mdt_intent_reint(enum mdt_it_code opcode,
2569 struct mdt_thread_info *info,
2570 struct ldlm_lock **,
2573 static struct mdt_it_flavor {
2574 const struct req_format *it_fmt;
2576 int (*it_act)(enum mdt_it_code ,
2577 struct mdt_thread_info *,
2578 struct ldlm_lock **,
2581 } mdt_it_flavor[] = {
2583 .it_fmt = &RQF_LDLM_INTENT,
2584 /*.it_flags = HABEO_REFERO,*/
2586 .it_act = mdt_intent_reint,
2587 .it_reint = REINT_OPEN
2590 .it_fmt = &RQF_LDLM_INTENT,
2591 .it_flags = MUTABOR,
2592 .it_act = mdt_intent_reint,
2593 .it_reint = REINT_OPEN
2596 .it_fmt = &RQF_LDLM_INTENT,
2597 .it_flags = MUTABOR,
2598 .it_act = mdt_intent_reint,
2599 .it_reint = REINT_CREATE
2601 [MDT_IT_GETATTR] = {
2602 .it_fmt = &RQF_LDLM_INTENT_GETATTR,
2603 .it_flags = HABEO_REFERO,
2604 .it_act = mdt_intent_getattr
2606 [MDT_IT_READDIR] = {
2612 .it_fmt = &RQF_LDLM_INTENT_GETATTR,
2613 .it_flags = HABEO_REFERO,
2614 .it_act = mdt_intent_getattr
2617 .it_fmt = &RQF_LDLM_INTENT_UNLINK,
2618 .it_flags = MUTABOR,
2620 .it_reint = REINT_UNLINK
2624 .it_flags = MUTABOR,
2627 [MDT_IT_GETXATTR] = {
2634 int mdt_intent_lock_replace(struct mdt_thread_info *info,
2635 struct ldlm_lock **lockp,
2636 struct ldlm_lock *new_lock,
2637 struct mdt_lock_handle *lh,
2640 struct ptlrpc_request *req = mdt_info_req(info);
2641 struct ldlm_lock *lock = *lockp;
2644 * Get new lock only for cases when possible resent did not find any
2647 if (new_lock == NULL)
2648 new_lock = ldlm_handle2lock(&lh->mlh_reg_lh);
2650 if (new_lock == NULL && (flags & LDLM_FL_INTENT_ONLY)) {
2651 lh->mlh_reg_lh.cookie = 0;
2655 LASSERTF(new_lock != NULL,
2656 "lockh "LPX64"\n", lh->mlh_reg_lh.cookie);
2659 * If we've already given this lock to a client once, then we should
2660 * have no readers or writers. Otherwise, we should have one reader
2661 * _or_ writer ref (which will be zeroed below) before returning the
2664 if (new_lock->l_export == req->rq_export) {
2665 LASSERT(new_lock->l_readers + new_lock->l_writers == 0);
2667 LASSERT(new_lock->l_export == NULL);
2668 LASSERT(new_lock->l_readers + new_lock->l_writers == 1);
2673 if (new_lock->l_export == req->rq_export) {
2675 * Already gave this to the client, which means that we
2676 * reconstructed a reply.
2678 LASSERT(lustre_msg_get_flags(req->rq_reqmsg) &
2680 lh->mlh_reg_lh.cookie = 0;
2681 RETURN(ELDLM_LOCK_REPLACED);
2684 /* This lock might already be given to the client by an resent req,
2685 * in this case we should return ELDLM_LOCK_ABORTED,
2686 * so we should check led_held_locks here, but it will affect
2687 * performance, FIXME
2689 /* Fixup the lock to be given to the client */
2690 lock_res_and_lock(new_lock);
2691 new_lock->l_readers = 0;
2692 new_lock->l_writers = 0;
2694 new_lock->l_export = class_export_get(req->rq_export);
2695 spin_lock(&req->rq_export->exp_ldlm_data.led_lock);
2696 list_add(&new_lock->l_export_chain,
2697 &new_lock->l_export->exp_ldlm_data.led_held_locks);
2698 spin_unlock(&req->rq_export->exp_ldlm_data.led_lock);
2700 new_lock->l_blocking_ast = lock->l_blocking_ast;
2701 new_lock->l_completion_ast = lock->l_completion_ast;
2702 new_lock->l_remote_handle = lock->l_remote_handle;
2703 new_lock->l_flags &= ~LDLM_FL_LOCAL;
2705 unlock_res_and_lock(new_lock);
2706 LDLM_LOCK_PUT(new_lock);
2707 lh->mlh_reg_lh.cookie = 0;
2709 RETURN(ELDLM_LOCK_REPLACED);
2712 static void mdt_intent_fixup_resent(struct mdt_thread_info *info,
2713 struct ldlm_lock *new_lock,
2714 struct ldlm_lock **old_lock,
2715 struct mdt_lock_handle *lh)
2717 struct ptlrpc_request *req = mdt_info_req(info);
2718 struct obd_export *exp = req->rq_export;
2719 struct lustre_handle remote_hdl;
2720 struct ldlm_request *dlmreq;
2721 struct list_head *iter;
2723 if (!(lustre_msg_get_flags(req->rq_reqmsg) & MSG_RESENT))
2726 dlmreq = req_capsule_client_get(info->mti_pill, &RMF_DLM_REQ);
2727 remote_hdl = dlmreq->lock_handle[0];
2729 spin_lock(&exp->exp_ldlm_data.led_lock);
2730 list_for_each(iter, &exp->exp_ldlm_data.led_held_locks) {
2731 struct ldlm_lock *lock;
2732 lock = list_entry(iter, struct ldlm_lock, l_export_chain);
2733 if (lock == new_lock)
2735 if (lock->l_remote_handle.cookie == remote_hdl.cookie) {
2736 lh->mlh_reg_lh.cookie = lock->l_handle.h_cookie;
2737 lh->mlh_reg_mode = lock->l_granted_mode;
2739 LDLM_DEBUG(lock, "restoring lock cookie");
2740 DEBUG_REQ(D_DLMTRACE, req,
2741 "restoring lock cookie "LPX64,
2742 lh->mlh_reg_lh.cookie);
2744 *old_lock = LDLM_LOCK_GET(lock);
2745 spin_unlock(&exp->exp_ldlm_data.led_lock);
2749 spin_unlock(&exp->exp_ldlm_data.led_lock);
2752 * If the xid matches, then we know this is a resent request, and allow
2753 * it. (It's probably an OPEN, for which we don't send a lock.
2755 if (req_xid_is_last(req))
2759 * This remote handle isn't enqueued, so we never received or processed
2760 * this request. Clear MSG_RESENT, because it can be handled like any
2761 * normal request now.
2763 lustre_msg_clear_flags(req->rq_reqmsg, MSG_RESENT);
2765 DEBUG_REQ(D_DLMTRACE, req, "no existing lock with rhandle "LPX64,
2769 static int mdt_intent_getattr(enum mdt_it_code opcode,
2770 struct mdt_thread_info *info,
2771 struct ldlm_lock **lockp,
2774 struct mdt_lock_handle *lhc = &info->mti_lh[MDT_LH_RMT];
2775 struct ldlm_lock *new_lock = NULL;
2777 struct ldlm_reply *ldlm_rep;
2778 struct ptlrpc_request *req;
2779 struct mdt_body *reqbody;
2780 struct mdt_body *repbody;
2784 reqbody = req_capsule_client_get(info->mti_pill, &RMF_MDT_BODY);
2787 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
2790 info->mti_spec.sp_ck_split = !!(reqbody->valid & OBD_MD_FLCKSPLIT);
2791 info->mti_cross_ref = !!(reqbody->valid & OBD_MD_FLCROSSREF);
2792 repbody->eadatasize = 0;
2793 repbody->aclsize = 0;
2797 child_bits = MDS_INODELOCK_LOOKUP;
2799 case MDT_IT_GETATTR:
2800 child_bits = MDS_INODELOCK_LOOKUP | MDS_INODELOCK_UPDATE;
2803 CERROR("Unhandled till now");
2804 GOTO(out_shrink, rc = -EINVAL);
2807 rc = mdt_init_ucred(info, reqbody);
2809 GOTO(out_shrink, rc);
2811 req = info->mti_pill->rc_req;
2812 ldlm_rep = req_capsule_server_get(info->mti_pill, &RMF_DLM_REP);
2813 mdt_set_disposition(info, ldlm_rep, DISP_IT_EXECD);
2815 /* Get lock from request for possible resent case. */
2816 mdt_intent_fixup_resent(info, *lockp, &new_lock, lhc);
2818 ldlm_rep->lock_policy_res2 =
2819 mdt_getattr_name_lock(info, lhc, child_bits, ldlm_rep);
2821 if (mdt_get_disposition(ldlm_rep, DISP_LOOKUP_NEG))
2822 ldlm_rep->lock_policy_res2 = 0;
2823 if (!mdt_get_disposition(ldlm_rep, DISP_LOOKUP_POS) ||
2824 ldlm_rep->lock_policy_res2) {
2825 lhc->mlh_reg_lh.cookie = 0ull;
2826 GOTO(out_ucred, rc = ELDLM_LOCK_ABORTED);
2829 rc = mdt_intent_lock_replace(info, lockp, new_lock, lhc, flags);
2832 mdt_exit_ucred(info);
2834 mdt_shrink_reply(info);
2838 static int mdt_intent_reint(enum mdt_it_code opcode,
2839 struct mdt_thread_info *info,
2840 struct ldlm_lock **lockp,
2843 struct mdt_lock_handle *lhc = &info->mti_lh[MDT_LH_RMT];
2844 struct ldlm_reply *rep = NULL;
2848 static const struct req_format *intent_fmts[REINT_MAX] = {
2849 [REINT_CREATE] = &RQF_LDLM_INTENT_CREATE,
2850 [REINT_OPEN] = &RQF_LDLM_INTENT_OPEN
2855 opc = mdt_reint_opcode(info, intent_fmts);
2859 if (mdt_it_flavor[opcode].it_reint != opc) {
2860 CERROR("Reint code %ld doesn't match intent: %d\n",
2862 RETURN(err_serious(-EPROTO));
2865 /* Get lock from request for possible resent case. */
2866 mdt_intent_fixup_resent(info, *lockp, NULL, lhc);
2868 rc = mdt_reint_internal(info, lhc, opc);
2870 /* Check whether the reply has been packed successfully. */
2871 if (mdt_info_req(info)->rq_repmsg != NULL)
2872 rep = req_capsule_server_get(info->mti_pill, &RMF_DLM_REP);
2874 RETURN(err_serious(-EFAULT));
2876 /* MDC expects this in any case */
2878 mdt_set_disposition(info, rep, DISP_LOOKUP_EXECD);
2880 /* Cross-ref case, the lock should be returned to the client */
2881 if (rc == -EREMOTE) {
2882 LASSERT(lustre_handle_is_used(&lhc->mlh_reg_lh));
2883 rep->lock_policy_res2 = 0;
2884 rc = mdt_intent_lock_replace(info, lockp, NULL, lhc, flags);
2887 rep->lock_policy_res2 = clear_serious(rc);
2889 lhc->mlh_reg_lh.cookie = 0ull;
2890 rc = ELDLM_LOCK_ABORTED;
2894 static int mdt_intent_code(long itcode)
2902 case IT_OPEN|IT_CREAT:
2909 rc = MDT_IT_READDIR;
2912 rc = MDT_IT_GETATTR;
2924 rc = MDT_IT_GETXATTR;
2927 CERROR("Unknown intent opcode: %ld\n", itcode);
2934 static int mdt_intent_opc(long itopc, struct mdt_thread_info *info,
2935 struct ldlm_lock **lockp, int flags)
2937 struct req_capsule *pill;
2938 struct mdt_it_flavor *flv;
2943 opc = mdt_intent_code(itopc);
2947 pill = info->mti_pill;
2948 flv = &mdt_it_flavor[opc];
2950 if (flv->it_fmt != NULL)
2951 req_capsule_extend(pill, flv->it_fmt);
2953 rc = mdt_unpack_req_pack_rep(info, flv->it_flags);
2955 struct ptlrpc_request *req = mdt_info_req(info);
2956 if (flv->it_flags & MUTABOR &&
2957 req->rq_export->exp_connect_flags & OBD_CONNECT_RDONLY)
2960 if (rc == 0 && flv->it_act != NULL) {
2961 /* execute policy */
2962 rc = flv->it_act(opc, info, lockp, flags);
2969 static int mdt_intent_policy(struct ldlm_namespace *ns,
2970 struct ldlm_lock **lockp, void *req_cookie,
2971 ldlm_mode_t mode, int flags, void *data)
2973 struct mdt_thread_info *info;
2974 struct ptlrpc_request *req = req_cookie;
2975 struct ldlm_intent *it;
2976 struct req_capsule *pill;
2981 LASSERT(req != NULL);
2983 info = lu_context_key_get(&req->rq_svc_thread->t_env->le_ctx,
2985 LASSERT(info != NULL);
2986 pill = info->mti_pill;
2987 LASSERT(pill->rc_req == req);
2989 if (req->rq_reqmsg->lm_bufcount > DLM_INTENT_IT_OFF) {
2990 req_capsule_extend(pill, &RQF_LDLM_INTENT);
2991 it = req_capsule_client_get(pill, &RMF_LDLM_INTENT);
2993 const struct ldlm_request *dlmreq;
2996 struct ldlm_lock *lock = *lockp;
2998 LDLM_DEBUG(lock, "intent policy opc: %s\n",
2999 ldlm_it2str(it->opc));
3002 rc = mdt_intent_opc(it->opc, info, lockp, flags);
3007 * Lock without inodebits makes no sense and will oops
3008 * later in ldlm. Let's check it now to see if we have
3009 * wrong lock from client or bits get corrupted
3010 * somewhere in mdt_intent_opc().
3012 dlmreq = info->mti_dlm_req;
3013 req_bits = dlmreq->lock_desc.l_policy_data.l_inodebits.bits;
3014 LASSERT(req_bits != 0);
3017 rc = err_serious(-EFAULT);
3019 /* No intent was provided */
3020 LASSERT(pill->rc_fmt == &RQF_LDLM_ENQUEUE);
3021 rc = req_capsule_server_pack(pill);
3023 rc = err_serious(rc);
3031 static void mdt_seq_adjust(const struct lu_env *env,
3032 struct mdt_device *m, int lost)
3034 struct lu_site *ls = m->mdt_md_dev.md_lu_dev.ld_site;
3035 struct lu_range out;
3038 LASSERT(ls && ls->ls_server_seq);
3040 /* get extra seq from seq_server, moving it's range up */
3041 while (lost-- > 0) {
3042 seq_server_alloc_meta(ls->ls_server_seq, NULL, &out, env);
3047 static int mdt_seq_fini(const struct lu_env *env,
3048 struct mdt_device *m)
3050 struct lu_site *ls = m->mdt_md_dev.md_lu_dev.ld_site;
3053 if (ls && ls->ls_server_seq) {
3054 seq_server_fini(ls->ls_server_seq, env);
3055 OBD_FREE_PTR(ls->ls_server_seq);
3056 ls->ls_server_seq = NULL;
3059 if (ls && ls->ls_control_seq) {
3060 seq_server_fini(ls->ls_control_seq, env);
3061 OBD_FREE_PTR(ls->ls_control_seq);
3062 ls->ls_control_seq = NULL;
3065 if (ls && ls->ls_client_seq) {
3066 seq_client_fini(ls->ls_client_seq);
3067 OBD_FREE_PTR(ls->ls_client_seq);
3068 ls->ls_client_seq = NULL;
3074 static int mdt_seq_init(const struct lu_env *env,
3076 struct mdt_device *m)
3083 ls = m->mdt_md_dev.md_lu_dev.ld_site;
3086 * This is sequence-controller node. Init seq-controller server on local
3089 if (ls->ls_node_id == 0) {
3090 LASSERT(ls->ls_control_seq == NULL);
3092 OBD_ALLOC_PTR(ls->ls_control_seq);
3093 if (ls->ls_control_seq == NULL)
3096 rc = seq_server_init(ls->ls_control_seq,
3097 m->mdt_bottom, uuid,
3098 LUSTRE_SEQ_CONTROLLER,
3102 GOTO(out_seq_fini, rc);
3104 OBD_ALLOC_PTR(ls->ls_client_seq);
3105 if (ls->ls_client_seq == NULL)
3106 GOTO(out_seq_fini, rc = -ENOMEM);
3108 OBD_ALLOC(prefix, MAX_OBD_NAME + 5);
3109 if (prefix == NULL) {
3110 OBD_FREE_PTR(ls->ls_client_seq);
3111 GOTO(out_seq_fini, rc = -ENOMEM);
3114 snprintf(prefix, MAX_OBD_NAME + 5, "ctl-%s",
3118 * Init seq-controller client after seq-controller server is
3119 * ready. Pass ls->ls_control_seq to it for direct talking.
3121 rc = seq_client_init(ls->ls_client_seq, NULL,
3122 LUSTRE_SEQ_METADATA, prefix,
3123 ls->ls_control_seq);
3124 OBD_FREE(prefix, MAX_OBD_NAME + 5);
3127 GOTO(out_seq_fini, rc);
3130 /* Init seq-server on local MDT */
3131 LASSERT(ls->ls_server_seq == NULL);
3133 OBD_ALLOC_PTR(ls->ls_server_seq);
3134 if (ls->ls_server_seq == NULL)
3135 GOTO(out_seq_fini, rc = -ENOMEM);
3137 rc = seq_server_init(ls->ls_server_seq,
3138 m->mdt_bottom, uuid,
3142 GOTO(out_seq_fini, rc = -ENOMEM);
3144 /* Assign seq-controller client to local seq-server. */
3145 if (ls->ls_node_id == 0) {
3146 LASSERT(ls->ls_client_seq != NULL);
3148 rc = seq_server_set_cli(ls->ls_server_seq,
3156 mdt_seq_fini(env, m);
3161 * Init client sequence manager which is used by local MDS to talk to sequence
3162 * controller on remote node.
3164 static int mdt_seq_init_cli(const struct lu_env *env,
3165 struct mdt_device *m,
3166 struct lustre_cfg *cfg)
3168 struct lu_site *ls = m->mdt_md_dev.md_lu_dev.ld_site;
3169 struct obd_device *mdc;
3170 struct obd_uuid *uuidp, *mdcuuidp;
3171 char *uuid_str, *mdc_uuid_str;
3174 struct mdt_thread_info *info;
3175 char *p, *index_string = lustre_cfg_string(cfg, 2);
3178 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
3179 uuidp = &info->mti_u.uuid[0];
3180 mdcuuidp = &info->mti_u.uuid[1];
3182 LASSERT(index_string);
3184 index = simple_strtol(index_string, &p, 10);
3186 CERROR("Invalid index in lustre_cgf, offset 2\n");
3190 /* check if this is adding the first MDC and controller is not yet
3192 if (index != 0 || ls->ls_client_seq)
3195 uuid_str = lustre_cfg_string(cfg, 1);
3196 mdc_uuid_str = lustre_cfg_string(cfg, 4);
3197 obd_str2uuid(uuidp, uuid_str);
3198 obd_str2uuid(mdcuuidp, mdc_uuid_str);
3200 mdc = class_find_client_obd(uuidp, LUSTRE_MDC_NAME, mdcuuidp);
3202 CERROR("can't find controller MDC by uuid %s\n",
3205 } else if (!mdc->obd_set_up) {
3206 CERROR("target %s not set up\n", mdc->obd_name);
3209 LASSERT(ls->ls_control_exp);
3210 OBD_ALLOC_PTR(ls->ls_client_seq);
3211 if (ls->ls_client_seq != NULL) {
3214 OBD_ALLOC(prefix, MAX_OBD_NAME + 5);
3218 snprintf(prefix, MAX_OBD_NAME + 5, "ctl-%s",
3221 rc = seq_client_init(ls->ls_client_seq,
3223 LUSTRE_SEQ_METADATA,
3225 OBD_FREE(prefix, MAX_OBD_NAME + 5);
3232 LASSERT(ls->ls_server_seq != NULL);
3233 rc = seq_server_set_cli(ls->ls_server_seq, ls->ls_client_seq,
3240 static void mdt_seq_fini_cli(struct mdt_device *m)
3246 ls = m->mdt_md_dev.md_lu_dev.ld_site;
3248 if (ls && ls->ls_server_seq)