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}*()
45 #include <obd_support.h>
46 /* struct ptlrpc_request */
47 #include <lustre_net.h>
48 /* struct obd_export */
49 #include <lustre_export.h>
50 /* struct obd_device */
53 #include <dt_object.h>
54 #include <lustre_mds.h>
55 #include <lustre_mdt.h>
56 #include "mdt_internal.h"
57 #include <linux/lustre_acl.h>
58 #include <lustre_param.h>
60 mdl_mode_t mdt_mdl_lock_modes[] = {
61 [LCK_MINMODE] = MDL_MINMODE,
68 [LCK_GROUP] = MDL_GROUP
71 ldlm_mode_t mdt_dlm_lock_modes[] = {
72 [MDL_MINMODE] = LCK_MINMODE,
79 [MDL_GROUP] = LCK_GROUP
83 * Initialized in mdt_mod_init().
85 unsigned long mdt_num_threads;
87 /* ptlrpc request handler for MDT. All handlers are
88 * grouped into several slices - struct mdt_opc_slice,
89 * and stored in an array - mdt_handlers[].
92 /* The name of this handler. */
94 /* Fail id for this handler, checked at the beginning of this handler*/
96 /* Operation code for this handler */
98 /* flags are listed in enum mdt_handler_flags below. */
100 /* The actual handler function to execute. */
101 int (*mh_act)(struct mdt_thread_info *info);
102 /* Request format for this request. */
103 const struct req_format *mh_fmt;
106 enum mdt_handler_flags {
108 * struct mdt_body is passed in the incoming message, and object
109 * identified by this fid exists on disk.
111 * "habeo corpus" == "I have a body"
113 HABEO_CORPUS = (1 << 0),
115 * struct ldlm_request is passed in the incoming message.
117 * "habeo clavis" == "I have a key"
119 HABEO_CLAVIS = (1 << 1),
121 * this request has fixed reply format, so that reply message can be
122 * packed by generic code.
124 * "habeo refero" == "I have a reply"
126 HABEO_REFERO = (1 << 2),
128 * this request will modify something, so check whether the filesystem
129 * is readonly or not, then return -EROFS to client asap if necessary.
131 * "mutabor" == "I shall modify"
136 struct mdt_opc_slice {
139 struct mdt_handler *mos_hs;
142 static struct mdt_opc_slice mdt_regular_handlers[];
143 static struct mdt_opc_slice mdt_readpage_handlers[];
144 static struct mdt_opc_slice mdt_xmds_handlers[];
145 static struct mdt_opc_slice mdt_seq_handlers[];
146 static struct mdt_opc_slice mdt_fld_handlers[];
148 static struct mdt_device *mdt_dev(struct lu_device *d);
149 static int mdt_regular_handle(struct ptlrpc_request *req);
150 static int mdt_unpack_req_pack_rep(struct mdt_thread_info *info, __u32 flags);
152 static struct lu_object_operations mdt_obj_ops;
154 int mdt_get_disposition(struct ldlm_reply *rep, int flag)
158 return (rep->lock_policy_res1 & flag);
161 void mdt_clear_disposition(struct mdt_thread_info *info,
162 struct ldlm_reply *rep, int flag)
165 info->mti_opdata &= ~flag;
167 rep->lock_policy_res1 &= ~flag;
170 void mdt_set_disposition(struct mdt_thread_info *info,
171 struct ldlm_reply *rep, int flag)
174 info->mti_opdata |= flag;
176 rep->lock_policy_res1 |= flag;
179 void mdt_lock_reg_init(struct mdt_lock_handle *lh, ldlm_mode_t lm)
181 lh->mlh_pdo_hash = 0;
182 lh->mlh_reg_mode = lm;
183 lh->mlh_type = MDT_REG_LOCK;
186 void mdt_lock_pdo_init(struct mdt_lock_handle *lh, ldlm_mode_t lm,
187 const char *name, int namelen)
189 lh->mlh_reg_mode = lm;
190 lh->mlh_type = MDT_PDO_LOCK;
193 LASSERT(namelen > 0);
194 lh->mlh_pdo_hash = full_name_hash(name, namelen);
196 LASSERT(namelen == 0);
197 lh->mlh_pdo_hash = 0ull;
201 static void mdt_lock_pdo_mode(struct mdt_thread_info *info, struct mdt_object *o,
202 struct mdt_lock_handle *lh)
208 * Any dir access needs couple of locks:
210 * 1) on part of dir we gonna take lookup/modify;
212 * 2) on whole dir to protect it from concurrent splitting and/or to
213 * flush client's cache for readdir().
215 * so, for a given mode and object this routine decides what lock mode
216 * to use for lock #2:
218 * 1) if caller's gonna lookup in dir then we need to protect dir from
219 * being splitted only - LCK_CR
221 * 2) if caller's gonna modify dir then we need to protect dir from
222 * being splitted and to flush cache - LCK_CW
224 * 3) if caller's gonna modify dir and that dir seems ready for
225 * splitting then we need to protect it from any type of access
226 * (lookup/modify/split) - LCK_EX --bzzz
229 LASSERT(lh->mlh_reg_mode != LCK_MINMODE);
230 LASSERT(lh->mlh_pdo_mode == LCK_MINMODE);
233 * Ask underlaying level its opinion about preferable PDO lock mode
234 * having access type passed as regular lock mode:
236 * - MDL_MINMODE means that lower layer does not want to specify lock
239 * - MDL_NL means that no PDO lock should be taken. This is used in some
240 * cases. Say, for non-splittable directories no need to use PDO locks
243 mode = mdo_lock_mode(info->mti_env, mdt_object_child(o),
244 mdt_dlm_mode2mdl_mode(lh->mlh_reg_mode));
246 if (mode != MDL_MINMODE) {
247 lh->mlh_pdo_mode = mdt_mdl_mode2dlm_mode(mode);
250 * Lower layer does not want to specify locking mode. We do it
251 * our selves. No special protection is needed, just flush
252 * client's cache on modification and allow concurrent
255 switch (lh->mlh_reg_mode) {
257 lh->mlh_pdo_mode = LCK_EX;
260 lh->mlh_pdo_mode = LCK_CR;
263 lh->mlh_pdo_mode = LCK_CW;
266 CERROR("Not expected lock type (0x%x)\n",
267 (int)lh->mlh_reg_mode);
272 LASSERT(lh->mlh_pdo_mode != LCK_MINMODE);
276 static int mdt_getstatus(struct mdt_thread_info *info)
278 struct mdt_device *mdt = info->mti_mdt;
279 struct md_device *next = mdt->mdt_child;
280 struct mdt_body *repbody;
285 rc = mdt_check_ucred(info);
287 RETURN(err_serious(rc));
289 if (MDT_FAIL_CHECK(OBD_FAIL_MDS_GETSTATUS_PACK))
290 RETURN(err_serious(-ENOMEM));
292 repbody = req_capsule_server_get(&info->mti_pill, &RMF_MDT_BODY);
293 rc = next->md_ops->mdo_root_get(info->mti_env, next, &repbody->fid1);
297 repbody->valid |= OBD_MD_FLID;
299 if (mdt->mdt_opts.mo_mds_capa) {
300 struct mdt_object *root;
301 struct lustre_capa *capa;
303 root = mdt_object_find(info->mti_env, mdt, &repbody->fid1);
305 RETURN(PTR_ERR(root));
307 capa = req_capsule_server_get(&info->mti_pill, &RMF_CAPA1);
309 capa->lc_opc = CAPA_OPC_MDS_DEFAULT;
311 rc = mo_capa_get(info->mti_env, mdt_object_child(root), capa,
313 mdt_object_put(info->mti_env, root);
315 repbody->valid |= OBD_MD_FLMDSCAPA;
321 static int mdt_statfs(struct mdt_thread_info *info)
323 struct md_device *next = info->mti_mdt->mdt_child;
324 struct obd_statfs *osfs;
329 /* This will trigger a watchdog timeout */
330 OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_STATFS_LCW_SLEEP,
331 (MDT_SERVICE_WATCHDOG_TIMEOUT / 1000) + 1);
333 rc = mdt_check_ucred(info);
335 RETURN(err_serious(rc));
337 if (MDT_FAIL_CHECK(OBD_FAIL_MDS_STATFS_PACK)) {
338 rc = err_serious(-ENOMEM);
340 osfs = req_capsule_server_get(&info->mti_pill,&RMF_OBD_STATFS);
341 rc = next->md_ops->mdo_statfs(info->mti_env, next,
343 statfs_pack(osfs, &info->mti_u.ksfs);
348 void mdt_pack_size2body(struct mdt_thread_info *info, struct mdt_object *o)
351 struct lu_attr *attr = &info->mti_attr.ma_attr;
353 b = req_capsule_server_get(&info->mti_pill, &RMF_MDT_BODY);
355 /* Check if Size-on-MDS is enabled. */
356 if ((mdt_conn_flags(info) & OBD_CONNECT_SOM) &&
357 S_ISREG(attr->la_mode) && mdt_sizeonmds_enabled(o)) {
358 b->valid |= (OBD_MD_FLSIZE | OBD_MD_FLBLOCKS);
359 b->size = attr->la_size;
360 b->blocks = attr->la_blocks;
364 void mdt_pack_attr2body(struct mdt_thread_info *info, struct mdt_body *b,
365 const struct lu_attr *attr, const struct lu_fid *fid)
367 /*XXX should pack the reply body according to lu_valid*/
368 b->valid |= OBD_MD_FLCTIME | OBD_MD_FLUID |
369 OBD_MD_FLGID | OBD_MD_FLTYPE |
370 OBD_MD_FLMODE | OBD_MD_FLNLINK | OBD_MD_FLFLAGS |
371 OBD_MD_FLATIME | OBD_MD_FLMTIME ;
373 if (!S_ISREG(attr->la_mode))
374 b->valid |= OBD_MD_FLSIZE | OBD_MD_FLBLOCKS | OBD_MD_FLRDEV;
376 b->atime = attr->la_atime;
377 b->mtime = attr->la_mtime;
378 b->ctime = attr->la_ctime;
379 b->mode = attr->la_mode;
380 b->size = attr->la_size;
381 b->blocks = attr->la_blocks;
382 b->uid = attr->la_uid;
383 b->gid = attr->la_gid;
384 b->flags = attr->la_flags;
385 b->nlink = attr->la_nlink;
386 b->rdev = attr->la_rdev;
390 b->valid |= OBD_MD_FLID;
391 CDEBUG(D_INODE, ""DFID": nlink=%d, mode=%o, size="LPU64"\n",
392 PFID(fid), b->nlink, b->mode, b->size);
396 mdt_body_reverse_idmap(info, b);
399 static inline int mdt_body_has_lov(const struct lu_attr *la,
400 const struct mdt_body *body)
402 return ((S_ISREG(la->la_mode) && (body->valid & OBD_MD_FLEASIZE)) ||
403 (S_ISDIR(la->la_mode) && (body->valid & OBD_MD_FLDIREA )) );
406 static int mdt_getattr_internal(struct mdt_thread_info *info,
407 struct mdt_object *o)
409 struct md_object *next = mdt_object_child(o);
410 const struct mdt_body *reqbody = info->mti_body;
411 struct ptlrpc_request *req = mdt_info_req(info);
412 struct mdt_export_data *med = &req->rq_export->exp_mdt_data;
413 struct md_attr *ma = &info->mti_attr;
414 struct lu_attr *la = &ma->ma_attr;
415 struct req_capsule *pill = &info->mti_pill;
416 const struct lu_env *env = info->mti_env;
417 struct mdt_body *repbody;
418 struct lu_buf *buffer = &info->mti_buf;
422 if (unlikely(MDT_FAIL_CHECK(OBD_FAIL_MDS_GETATTR_PACK)))
423 RETURN(err_serious(-ENOMEM));
425 repbody = req_capsule_server_get(pill, &RMF_MDT_BODY);
429 rc = mdt_object_exists(o);
431 /* This object is located on remote node.*/
432 repbody->fid1 = *mdt_object_fid(o);
433 repbody->valid = OBD_MD_FLID | OBD_MD_MDS;
437 buffer->lb_buf = req_capsule_server_get(pill, &RMF_MDT_MD);
438 buffer->lb_len = req_capsule_get_size(pill, &RMF_MDT_MD, RCL_SERVER);
440 /* If it is dir object and client require MEA, then we got MEA */
441 if (S_ISDIR(lu_object_attr(&next->mo_lu)) &&
442 reqbody->valid & OBD_MD_MEA) {
443 /* Assumption: MDT_MD size is enough for lmv size. */
444 ma->ma_lmv = buffer->lb_buf;
445 ma->ma_lmv_size = buffer->lb_len;
446 ma->ma_need = MA_LMV | MA_INODE;
448 ma->ma_lmm = buffer->lb_buf;
449 ma->ma_lmm_size = buffer->lb_len;
450 ma->ma_need = MA_LOV | MA_INODE;
453 rc = mo_attr_get(env, next, ma);
455 CERROR("getattr error for "DFID": %d\n",
456 PFID(mdt_object_fid(o)), rc);
460 if (likely(ma->ma_valid & MA_INODE))
461 mdt_pack_attr2body(info, repbody, la, mdt_object_fid(o));
465 if (mdt_body_has_lov(la, reqbody)) {
466 if (ma->ma_valid & MA_LOV) {
467 LASSERT(ma->ma_lmm_size);
468 mdt_dump_lmm(D_INFO, ma->ma_lmm);
469 repbody->eadatasize = ma->ma_lmm_size;
470 if (S_ISDIR(la->la_mode))
471 repbody->valid |= OBD_MD_FLDIREA;
473 repbody->valid |= OBD_MD_FLEASIZE;
475 if (ma->ma_valid & MA_LMV) {
476 LASSERT(S_ISDIR(la->la_mode));
477 repbody->eadatasize = ma->ma_lmv_size;
478 repbody->valid |= (OBD_MD_FLDIREA|OBD_MD_MEA);
480 if (!(ma->ma_valid & MA_LOV) && !(ma->ma_valid & MA_LMV)) {
481 repbody->valid |= OBD_MD_FLSIZE | OBD_MD_FLBLOCKS;
483 } else if (S_ISLNK(la->la_mode) &&
484 reqbody->valid & OBD_MD_LINKNAME) {
485 buffer->lb_buf = ma->ma_lmm;
486 buffer->lb_len = reqbody->eadatasize;
487 rc = mo_readlink(env, next, buffer);
488 if (unlikely(rc <= 0)) {
489 CERROR("readlink failed: %d\n", rc);
492 repbody->valid |= OBD_MD_LINKNAME;
493 repbody->eadatasize = rc;
495 ((char*)ma->ma_lmm)[rc - 1] = 0;
496 CDEBUG(D_INODE, "symlink dest %s, len = %d\n",
497 (char*)ma->ma_lmm, rc);
502 if (reqbody->valid & OBD_MD_FLMODEASIZE) {
503 repbody->max_cookiesize = info->mti_mdt->mdt_max_cookiesize;
504 repbody->max_mdsize = info->mti_mdt->mdt_max_mdsize;
505 repbody->valid |= OBD_MD_FLMODEASIZE;
506 CDEBUG(D_INODE, "I am going to change the MAX_MD_SIZE & "
507 "MAX_COOKIE to : %d:%d\n", repbody->max_mdsize,
508 repbody->max_cookiesize);
511 if (med->med_rmtclient && (reqbody->valid & OBD_MD_FLRMTPERM)) {
512 void *buf = req_capsule_server_get(pill, &RMF_ACL);
514 /* mdt_getattr_lock only */
515 rc = mdt_pack_remote_perm(info, o, buf);
517 repbody->valid &= ~OBD_MD_FLRMTPERM;
518 repbody->aclsize = 0;
521 repbody->valid |= OBD_MD_FLRMTPERM;
522 repbody->aclsize = sizeof(struct mdt_remote_perm);
525 #ifdef CONFIG_FS_POSIX_ACL
526 else if ((req->rq_export->exp_connect_flags & OBD_CONNECT_ACL) &&
527 (reqbody->valid & OBD_MD_FLACL)) {
528 buffer->lb_buf = req_capsule_server_get(pill, &RMF_ACL);
529 buffer->lb_len = req_capsule_get_size(pill,
530 &RMF_ACL, RCL_SERVER);
531 if (buffer->lb_len > 0) {
532 rc = mo_xattr_get(env, next, buffer,
533 XATTR_NAME_ACL_ACCESS);
535 if (rc == -ENODATA) {
536 repbody->aclsize = 0;
537 repbody->valid |= OBD_MD_FLACL;
539 } else if (rc == -EOPNOTSUPP) {
542 CERROR("got acl size: %d\n", rc);
545 repbody->aclsize = rc;
546 repbody->valid |= OBD_MD_FLACL;
553 if ((reqbody->valid & OBD_MD_FLMDSCAPA) &&
554 info->mti_mdt->mdt_opts.mo_mds_capa) {
555 struct lustre_capa *capa;
557 capa = req_capsule_server_get(&info->mti_pill, &RMF_CAPA1);
559 capa->lc_opc = CAPA_OPC_MDS_DEFAULT;
560 rc = mo_capa_get(env, next, capa, 0);
563 repbody->valid |= OBD_MD_FLMDSCAPA;
568 static int mdt_renew_capa(struct mdt_thread_info *info)
570 struct mdt_device *mdt = info->mti_mdt;
571 struct mdt_object *obj = info->mti_object;
572 struct mdt_body *body;
573 struct lustre_capa *capa, *c;
577 /* if object doesn't exist, or server has disabled capability,
578 * return directly, client will find body->valid OBD_MD_FLOSSCAPA
581 if (!obj || !mdt->mdt_opts.mo_mds_capa)
584 body = req_capsule_server_get(&info->mti_pill, &RMF_MDT_BODY);
585 LASSERT(body != NULL);
587 c = req_capsule_client_get(&info->mti_pill, &RMF_CAPA1);
590 capa = req_capsule_server_get(&info->mti_pill, &RMF_CAPA1);
594 rc = mo_capa_get(info->mti_env, mdt_object_child(obj), capa, 1);
596 body->valid |= OBD_MD_FLOSSCAPA;
601 static int mdt_getattr(struct mdt_thread_info *info)
603 struct mdt_object *obj = info->mti_object;
604 struct req_capsule *pill = &info->mti_pill;
605 struct mdt_body *reqbody;
606 struct mdt_body *repbody;
612 reqbody = req_capsule_client_get(pill, &RMF_MDT_BODY);
615 if (reqbody->valid & OBD_MD_FLOSSCAPA) {
616 rc = req_capsule_pack(pill);
618 rc = err_serious(rc);
620 rc = mdt_renew_capa(info);
621 mdt_shrink_reply(info);
626 LASSERT(obj != NULL);
627 LASSERT(lu_object_assert_exists(&obj->mot_obj.mo_lu));
629 mode = lu_object_attr(&obj->mot_obj.mo_lu);
630 if (S_ISLNK(mode) && (reqbody->valid & OBD_MD_LINKNAME) &&
631 (reqbody->eadatasize > info->mti_mdt->mdt_max_mdsize))
632 md_size = reqbody->eadatasize;
634 md_size = info->mti_mdt->mdt_max_mdsize;
636 req_capsule_set_size(pill, &RMF_MDT_MD, RCL_SERVER, md_size);
638 rc = req_capsule_pack(pill);
639 if (unlikely(rc != 0))
640 GOTO(out, rc = err_serious(rc));
642 repbody = req_capsule_server_get(pill, &RMF_MDT_BODY);
643 LASSERT(repbody != NULL);
644 repbody->eadatasize = 0;
645 repbody->aclsize = 0;
647 if (reqbody->valid & OBD_MD_FLRMTPERM)
648 rc = mdt_init_ucred(info, reqbody);
650 rc = mdt_check_ucred(info);
652 GOTO(out_shrink, rc);
654 info->mti_spec.sp_ck_split = !!(reqbody->valid & OBD_MD_FLCKSPLIT);
655 info->mti_cross_ref = !!(reqbody->valid & OBD_MD_FLCROSSREF);
658 * Don't check capability at all, because rename might getattr for
659 * remote obj, and at that time no capability is available.
661 mdt_set_capainfo(info, 1, &reqbody->fid1, BYPASS_CAPA);
662 rc = mdt_getattr_internal(info, obj);
663 if (reqbody->valid & OBD_MD_FLRMTPERM)
664 mdt_exit_ucred(info);
667 mdt_shrink_reply(info);
672 static int mdt_is_subdir(struct mdt_thread_info *info)
674 struct mdt_object *o = info->mti_object;
675 struct req_capsule *pill = &info->mti_pill;
676 const struct mdt_body *body = info->mti_body;
677 struct mdt_body *repbody;
683 repbody = req_capsule_server_get(pill, &RMF_MDT_BODY);
686 * We save last checked parent fid to @repbody->fid1 for remote
689 LASSERT(fid_is_sane(&body->fid2));
690 LASSERT(mdt_object_exists(o) > 0);
691 rc = mdo_is_subdir(info->mti_env, mdt_object_child(o),
692 &body->fid2, &repbody->fid1);
693 if (rc == 0 || rc == -EREMOTE)
694 repbody->valid |= OBD_MD_FLID;
699 static int mdt_raw_lookup(struct mdt_thread_info *info,
700 struct mdt_object *parent,
701 const struct lu_name *lname,
702 struct ldlm_reply *ldlm_rep)
704 struct md_object *next = mdt_object_child(info->mti_object);
705 const struct mdt_body *reqbody = info->mti_body;
706 struct lu_fid *child_fid = &info->mti_tmp_fid1;
707 struct mdt_body *repbody;
711 if (reqbody->valid != OBD_MD_FLID)
714 LASSERT(!info->mti_cross_ref);
716 /* Only got the fid of this obj by name */
717 rc = mdo_lookup(info->mti_env, next, lname, child_fid,
720 /* XXX is raw_lookup possible as intent operation? */
723 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_NEG);
726 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_POS);
728 repbody = req_capsule_server_get(&info->mti_pill, &RMF_MDT_BODY);
731 repbody = req_capsule_server_get(&info->mti_pill,
733 repbody->fid1 = *child_fid;
734 repbody->valid = OBD_MD_FLID;
740 * UPDATE lock should be taken against parent, and be release before exit;
741 * child_bits lock should be taken against child, and be returned back:
742 * (1)normal request should release the child lock;
743 * (2)intent request will grant the lock to client.
745 static int mdt_getattr_name_lock(struct mdt_thread_info *info,
746 struct mdt_lock_handle *lhc,
748 struct ldlm_reply *ldlm_rep)
750 struct ptlrpc_request *req = mdt_info_req(info);
751 struct mdt_body *reqbody = NULL;
752 struct mdt_object *parent = info->mti_object;
753 struct mdt_object *child;
754 struct md_object *next = mdt_object_child(parent);
755 struct lu_fid *child_fid = &info->mti_tmp_fid1;
756 struct lu_name *lname = NULL;
759 struct mdt_lock_handle *lhp;
760 struct ldlm_lock *lock;
761 struct ldlm_res_id *res_id;
767 is_resent = lustre_handle_is_used(&lhc->mlh_reg_lh);
768 LASSERT(ergo(is_resent,
769 lustre_msg_get_flags(req->rq_reqmsg) & MSG_RESENT));
771 LASSERT(parent != NULL);
772 name = req_capsule_client_get(&info->mti_pill, &RMF_NAME);
774 RETURN(err_serious(-EFAULT));
776 namelen = req_capsule_get_size(&info->mti_pill, &RMF_NAME,
778 LASSERT(namelen >= 0);
780 /* XXX: "namelen == 0" is for getattr by fid (OBD_CONNECT_ATTRFID),
781 * otherwise do not allow empty name, that is the name must contain
782 * at least one character and the terminating '\0'*/
784 reqbody =req_capsule_client_get(&info->mti_pill, &RMF_MDT_BODY);
785 LASSERT(fid_is_sane(&reqbody->fid2));
788 CDEBUG(D_INODE, "getattr with lock for "DFID"/"DFID", "
790 PFID(mdt_object_fid(parent)), PFID(&reqbody->fid2),
793 lname = mdt_name(info->mti_env, (char *)name, namelen);
794 CDEBUG(D_INODE, "getattr with lock for "DFID"/%s, "
796 PFID(mdt_object_fid(parent)), name, ldlm_rep);
799 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_EXECD);
801 rc = mdt_object_exists(parent);
802 if (unlikely(rc == 0)) {
803 LU_OBJECT_DEBUG(D_WARNING, info->mti_env,
804 &parent->mot_obj.mo_lu,
805 "Parent doesn't exist!\n");
808 LASSERTF(rc > 0, "Parent "DFID" is on remote server\n",
809 PFID(mdt_object_fid(parent)));
812 rc = mdt_raw_lookup(info, parent, lname, ldlm_rep);
820 if (info->mti_cross_ref) {
821 /* Only getattr on the child. Parent is on another node. */
822 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_POS);
824 CDEBUG(D_INODE, "partial getattr_name child_fid = "DFID", "
825 "ldlm_rep=%p\n", PFID(mdt_object_fid(child)), ldlm_rep);
828 /* Do not take lock for resent case. */
829 lock = ldlm_handle2lock(&lhc->mlh_reg_lh);
830 LASSERTF(lock != NULL, "Invalid lock handle "LPX64"\n",
831 lhc->mlh_reg_lh.cookie);
832 LASSERT(fid_res_name_eq(mdt_object_fid(child),
833 &lock->l_resource->lr_name));
837 mdt_lock_handle_init(lhc);
838 mdt_lock_reg_init(lhc, LCK_PR);
841 * Object's name is on another MDS, no lookup lock is
842 * needed here but update is.
844 child_bits &= ~MDS_INODELOCK_LOOKUP;
845 child_bits |= MDS_INODELOCK_UPDATE;
847 rc = mdt_object_lock(info, child, lhc, child_bits,
851 /* Finally, we can get attr for child. */
852 mdt_set_capainfo(info, 0, mdt_object_fid(child),
854 rc = mdt_getattr_internal(info, child);
855 if (unlikely(rc != 0))
856 mdt_object_unlock(info, child, lhc, 1);
861 /* step 1: lock parent */
862 lhp = &info->mti_lh[MDT_LH_PARENT];
863 mdt_lock_pdo_init(lhp, LCK_PR, name, namelen);
864 rc = mdt_object_lock(info, parent, lhp, MDS_INODELOCK_UPDATE,
867 if (unlikely(rc != 0))
871 /* step 2: lookup child's fid by name */
872 rc = mdo_lookup(info->mti_env, next, lname, child_fid,
877 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_NEG);
878 GOTO(out_parent, rc);
880 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_POS);
882 *child_fid = reqbody->fid2;
883 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_POS);
887 *step 3: find the child object by fid & lock it.
888 * regardless if it is local or remote.
890 child = mdt_object_find(info->mti_env, info->mti_mdt, child_fid);
892 if (unlikely(IS_ERR(child)))
893 GOTO(out_parent, rc = PTR_ERR(child));
895 /* Do not take lock for resent case. */
896 lock = ldlm_handle2lock(&lhc->mlh_reg_lh);
897 LASSERTF(lock != NULL, "Invalid lock handle "LPX64"\n",
898 lhc->mlh_reg_lh.cookie);
900 res_id = &lock->l_resource->lr_name;
901 if (!fid_res_name_eq(mdt_object_fid(child),
902 &lock->l_resource->lr_name)) {
903 LASSERTF(fid_res_name_eq(mdt_object_fid(parent),
904 &lock->l_resource->lr_name),
905 "Lock res_id: %lu/%lu/%lu, Fid: "DFID".\n",
906 (unsigned long)res_id->name[0],
907 (unsigned long)res_id->name[1],
908 (unsigned long)res_id->name[2],
909 PFID(mdt_object_fid(parent)));
910 CWARN("Although resent, but still not get child lock"
911 "parent:"DFID" child:"DFID"\n",
912 PFID(mdt_object_fid(parent)),
913 PFID(mdt_object_fid(child)));
914 lustre_msg_clear_flags(req->rq_reqmsg, MSG_RESENT);
922 mdt_lock_handle_init(lhc);
923 mdt_lock_reg_init(lhc, LCK_PR);
925 if (mdt_object_exists(child) == 0) {
926 LU_OBJECT_DEBUG(D_WARNING, info->mti_env,
927 &child->mot_obj.mo_lu,
928 "Object doesn't exist!\n");
930 rc = mdt_object_lock(info, child, lhc, child_bits,
933 if (unlikely(rc != 0))
937 /* finally, we can get attr for child. */
938 mdt_set_capainfo(info, 1, child_fid, BYPASS_CAPA);
939 rc = mdt_getattr_internal(info, child);
940 if (unlikely(rc != 0)) {
941 mdt_object_unlock(info, child, lhc, 1);
943 lock = ldlm_handle2lock(&lhc->mlh_reg_lh);
945 struct mdt_body *repbody;
948 /* Debugging code. */
949 res_id = &lock->l_resource->lr_name;
950 LDLM_DEBUG(lock, "Returning lock to client\n");
951 LASSERTF(fid_res_name_eq(mdt_object_fid(child),
952 &lock->l_resource->lr_name),
953 "Lock res_id: %lu/%lu/%lu, Fid: "DFID".\n",
954 (unsigned long)res_id->name[0],
955 (unsigned long)res_id->name[1],
956 (unsigned long)res_id->name[2],
957 PFID(mdt_object_fid(child)));
959 * Pack Size-on-MDS inode attributes to the body if
960 * update lock is given.
962 repbody = req_capsule_server_get(&info->mti_pill,
964 ma = &info->mti_attr.ma_attr;
965 if (lock->l_policy_data.l_inodebits.bits &
966 MDS_INODELOCK_UPDATE)
967 mdt_pack_size2body(info, child);
973 mdt_object_put(info->mti_env, child);
975 mdt_object_unlock(info, parent, lhp, 1);
980 /* normal handler: should release the child lock */
981 static int mdt_getattr_name(struct mdt_thread_info *info)
983 struct mdt_lock_handle *lhc = &info->mti_lh[MDT_LH_CHILD];
984 struct mdt_body *reqbody;
985 struct mdt_body *repbody;
989 reqbody = req_capsule_client_get(&info->mti_pill, &RMF_MDT_BODY);
990 LASSERT(reqbody != NULL);
991 repbody = req_capsule_server_get(&info->mti_pill, &RMF_MDT_BODY);
992 LASSERT(repbody != NULL);
994 info->mti_spec.sp_ck_split = !!(reqbody->valid & OBD_MD_FLCKSPLIT);
995 info->mti_cross_ref = !!(reqbody->valid & OBD_MD_FLCROSSREF);
996 repbody->eadatasize = 0;
997 repbody->aclsize = 0;
999 rc = mdt_init_ucred(info, reqbody);
1003 rc = mdt_getattr_name_lock(info, lhc, MDS_INODELOCK_UPDATE, NULL);
1004 if (lustre_handle_is_used(&lhc->mlh_reg_lh)) {
1005 ldlm_lock_decref(&lhc->mlh_reg_lh, lhc->mlh_reg_mode);
1006 lhc->mlh_reg_lh.cookie = 0;
1008 mdt_exit_ucred(info);
1011 mdt_shrink_reply(info);
1015 static struct lu_device_operations mdt_lu_ops;
1017 static int lu_device_is_mdt(struct lu_device *d)
1019 return ergo(d != NULL && d->ld_ops != NULL, d->ld_ops == &mdt_lu_ops);
1022 static int mdt_set_info(struct mdt_thread_info *info)
1024 struct ptlrpc_request *req = mdt_info_req(info);
1030 rc = lustre_pack_reply(req, 1, NULL, NULL);
1034 key = req_capsule_client_get(&info->mti_pill, &RMF_SETINFO_KEY);
1036 DEBUG_REQ(D_HA, req, "no set_info key");
1040 keylen = req_capsule_get_size(&info->mti_pill, &RMF_SETINFO_KEY,
1043 val = req_capsule_client_get(&info->mti_pill, &RMF_SETINFO_VAL);
1045 DEBUG_REQ(D_HA, req, "no set_info val");
1049 if (keylen != (sizeof(KEY_READ_ONLY) - 1) ||
1050 memcmp(key, KEY_READ_ONLY, keylen) != 0)
1054 lustre_msg_set_status(req->rq_repmsg, 0);
1056 spin_lock(&req->rq_export->exp_lock);
1058 req->rq_export->exp_connect_flags |= OBD_CONNECT_RDONLY;
1060 req->rq_export->exp_connect_flags &= ~OBD_CONNECT_RDONLY;
1061 spin_unlock(&req->rq_export->exp_lock);
1066 static int mdt_connect(struct mdt_thread_info *info)
1069 struct ptlrpc_request *req;
1071 req = mdt_info_req(info);
1072 rc = target_handle_connect(req);
1074 LASSERT(req->rq_export != NULL);
1075 info->mti_mdt = mdt_dev(req->rq_export->exp_obd->obd_lu_dev);
1076 rc = mdt_init_idmap(info);
1078 /* if mdt_init_idmap failed, revocation for connect */
1079 obd_disconnect(class_export_get(req->rq_export));
1081 rc = err_serious(rc);
1085 static int mdt_disconnect(struct mdt_thread_info *info)
1090 rc = target_handle_disconnect(mdt_info_req(info));
1092 rc = err_serious(rc);
1096 static int mdt_sendpage(struct mdt_thread_info *info,
1097 struct lu_rdpg *rdpg)
1099 struct ptlrpc_request *req = mdt_info_req(info);
1100 struct ptlrpc_bulk_desc *desc;
1101 struct l_wait_info *lwi = &info->mti_u.rdpg.mti_wait_info;
1108 desc = ptlrpc_prep_bulk_exp(req, rdpg->rp_npages, BULK_PUT_SOURCE,
1111 GOTO(out, rc = -ENOMEM);
1113 for (i = 0, tmpcount = rdpg->rp_count;
1114 i < rdpg->rp_npages; i++, tmpcount -= tmpsize) {
1115 tmpsize = min_t(int, tmpcount, CFS_PAGE_SIZE);
1116 ptlrpc_prep_bulk_page(desc, rdpg->rp_pages[i], 0, tmpsize);
1119 LASSERT(desc->bd_nob == rdpg->rp_count);
1120 rc = ptlrpc_start_bulk_transfer(desc);
1122 GOTO(free_desc, rc);
1124 if (MDT_FAIL_CHECK(OBD_FAIL_MDS_SENDPAGE))
1125 GOTO(abort_bulk, rc);
1127 *lwi = LWI_TIMEOUT(obd_timeout * HZ / 4, NULL, NULL);
1128 rc = l_wait_event(desc->bd_waitq, !ptlrpc_bulk_active(desc), lwi);
1129 LASSERT (rc == 0 || rc == -ETIMEDOUT);
1132 if (desc->bd_success &&
1133 desc->bd_nob_transferred == rdpg->rp_count)
1134 GOTO(free_desc, rc);
1136 rc = -ETIMEDOUT; /* XXX should this be a different errno? */
1139 DEBUG_REQ(D_ERROR, req, "bulk failed: %s %d(%d), evicting %s@%s",
1140 (rc == -ETIMEDOUT) ? "timeout" : "network error",
1141 desc->bd_nob_transferred, rdpg->rp_count,
1142 req->rq_export->exp_client_uuid.uuid,
1143 req->rq_export->exp_connection->c_remote_uuid.uuid);
1145 class_fail_export(req->rq_export);
1149 ptlrpc_abort_bulk(desc);
1151 ptlrpc_free_bulk(desc);
1156 #ifdef HAVE_SPLIT_SUPPORT
1158 * Retrieve dir entry from the page and insert it to the slave object, actually,
1159 * this should be in osd layer, but since it will not in the final product, so
1160 * just do it here and do not define more moo api anymore for this.
1162 static int mdt_write_dir_page(struct mdt_thread_info *info, struct page *page,
1165 struct mdt_object *object = info->mti_object;
1166 struct lu_fid *lf = &info->mti_tmp_fid2;
1167 struct md_attr *ma = &info->mti_attr;
1168 struct lu_dirpage *dp;
1169 struct lu_dirent *ent;
1170 int rc = 0, offset = 0;
1173 /* Make sure we have at least one entry. */
1178 * Disable trans for this name insert, since it will include many trans
1181 info->mti_no_need_trans = 1;
1183 * When write_dir_page, no need update parent's ctime,
1184 * and no permission check for name_insert.
1186 ma->ma_attr.la_ctime = 0;
1187 ma->ma_attr.la_valid = LA_MODE;
1188 ma->ma_valid = MA_INODE;
1191 dp = page_address(page);
1192 offset = (int)((__u32)lu_dirent_start(dp) - (__u32)dp);
1194 for (ent = lu_dirent_start(dp); ent != NULL;
1195 ent = lu_dirent_next(ent)) {
1196 struct lu_name *lname;
1199 if (le16_to_cpu(ent->lde_namelen) == 0)
1202 fid_le_to_cpu(lf, &ent->lde_fid);
1203 if (le32_to_cpu(ent->lde_hash) & MAX_HASH_HIGHEST_BIT)
1204 ma->ma_attr.la_mode = S_IFDIR;
1206 ma->ma_attr.la_mode = 0;
1207 OBD_ALLOC(name, le16_to_cpu(ent->lde_namelen) + 1);
1209 GOTO(out, rc = -ENOMEM);
1211 memcpy(name, ent->lde_name, le16_to_cpu(ent->lde_namelen));
1212 lname = mdt_name(info->mti_env, name,
1213 le16_to_cpu(ent->lde_namelen) + 1);
1214 ma->ma_attr_flags |= MDS_PERM_BYPASS;
1215 rc = mdo_name_insert(info->mti_env,
1216 md_object_next(&object->mot_obj),
1218 OBD_FREE(name, le16_to_cpu(ent->lde_namelen) + 1);
1220 CERROR("Can't insert %*.*s, rc %d\n",
1221 le16_to_cpu(ent->lde_namelen),
1222 le16_to_cpu(ent->lde_namelen),
1227 offset += lu_dirent_size(ent);
1237 static int mdt_bulk_timeout(void *data)
1241 CERROR("mdt bulk transfer timeout \n");
1246 static int mdt_writepage(struct mdt_thread_info *info)
1248 struct ptlrpc_request *req = mdt_info_req(info);
1249 struct mdt_body *reqbody;
1250 struct l_wait_info *lwi;
1251 struct ptlrpc_bulk_desc *desc;
1257 reqbody = req_capsule_client_get(&info->mti_pill, &RMF_MDT_BODY);
1258 if (reqbody == NULL)
1259 RETURN(err_serious(-EFAULT));
1261 desc = ptlrpc_prep_bulk_exp(req, 1, BULK_GET_SINK, MDS_BULK_PORTAL);
1263 RETURN(err_serious(-ENOMEM));
1265 /* allocate the page for the desc */
1266 page = cfs_alloc_page(CFS_ALLOC_STD);
1268 GOTO(desc_cleanup, rc = -ENOMEM);
1270 CDEBUG(D_INFO, "Received page offset %d size %d \n",
1271 (int)reqbody->size, (int)reqbody->nlink);
1273 ptlrpc_prep_bulk_page(desc, page, (int)reqbody->size,
1274 (int)reqbody->nlink);
1277 * Check if client was evicted while we were doing i/o before touching
1282 GOTO(cleanup_page, rc = -ENOMEM);
1284 if (desc->bd_export->exp_failed)
1287 rc = ptlrpc_start_bulk_transfer (desc);
1289 *lwi = LWI_TIMEOUT_INTERVAL(obd_timeout * HZ / 4, HZ,
1290 mdt_bulk_timeout, desc);
1291 rc = l_wait_event(desc->bd_waitq, !ptlrpc_bulk_active(desc) ||
1292 desc->bd_export->exp_failed, lwi);
1293 LASSERT(rc == 0 || rc == -ETIMEDOUT);
1294 if (rc == -ETIMEDOUT) {
1295 DEBUG_REQ(D_ERROR, req, "timeout on bulk GET");
1296 ptlrpc_abort_bulk(desc);
1297 } else if (desc->bd_export->exp_failed) {
1298 DEBUG_REQ(D_ERROR, req, "Eviction on bulk GET");
1300 ptlrpc_abort_bulk(desc);
1301 } else if (!desc->bd_success ||
1302 desc->bd_nob_transferred != desc->bd_nob) {
1303 DEBUG_REQ(D_ERROR, req, "%s bulk GET %d(%d)",
1305 "truncated" : "network error on",
1306 desc->bd_nob_transferred, desc->bd_nob);
1307 /* XXX should this be a different errno? */
1311 DEBUG_REQ(D_ERROR, req, "ptlrpc_bulk_get failed: rc %d", rc);
1314 GOTO(cleanup_lwi, rc);
1315 rc = mdt_write_dir_page(info, page, reqbody->nlink);
1320 __cfs_free_page(page);
1322 ptlrpc_free_bulk(desc);
1327 static int mdt_readpage(struct mdt_thread_info *info)
1329 struct mdt_object *object = info->mti_object;
1330 struct lu_rdpg *rdpg = &info->mti_u.rdpg.mti_rdpg;
1331 struct mdt_body *reqbody;
1332 struct mdt_body *repbody;
1337 if (MDT_FAIL_CHECK(OBD_FAIL_MDS_READPAGE_PACK))
1338 RETURN(err_serious(-ENOMEM));
1340 reqbody = req_capsule_client_get(&info->mti_pill, &RMF_MDT_BODY);
1341 repbody = req_capsule_server_get(&info->mti_pill, &RMF_MDT_BODY);
1342 if (reqbody == NULL || repbody == NULL)
1343 RETURN(err_serious(-EFAULT));
1345 rc = mdt_check_ucred(info);
1347 RETURN(err_serious(rc));
1350 * prepare @rdpg before calling lower layers and transfer itself. Here
1351 * reqbody->size contains offset of where to start to read and
1352 * reqbody->nlink contains number bytes to read.
1354 rdpg->rp_hash = reqbody->size;
1355 if ((__u64)rdpg->rp_hash != reqbody->size) {
1356 CERROR("Invalid hash: %#llx != %#llx\n",
1357 (__u64)rdpg->rp_hash, reqbody->size);
1360 rdpg->rp_count = reqbody->nlink;
1361 rdpg->rp_npages = (rdpg->rp_count + CFS_PAGE_SIZE - 1)>>CFS_PAGE_SHIFT;
1362 OBD_ALLOC(rdpg->rp_pages, rdpg->rp_npages * sizeof rdpg->rp_pages[0]);
1363 if (rdpg->rp_pages == NULL)
1366 for (i = 0; i < rdpg->rp_npages; ++i) {
1367 rdpg->rp_pages[i] = cfs_alloc_page(CFS_ALLOC_STD);
1368 if (rdpg->rp_pages[i] == NULL)
1369 GOTO(free_rdpg, rc = -ENOMEM);
1372 /* call lower layers to fill allocated pages with directory data */
1373 rc = mo_readpage(info->mti_env, mdt_object_child(object), rdpg);
1375 GOTO(free_rdpg, rc);
1377 /* send pages to client */
1378 rc = mdt_sendpage(info, rdpg);
1383 for (i = 0; i < rdpg->rp_npages; i++)
1384 if (rdpg->rp_pages[i] != NULL)
1385 __cfs_free_page(rdpg->rp_pages[i]);
1386 OBD_FREE(rdpg->rp_pages, rdpg->rp_npages * sizeof rdpg->rp_pages[0]);
1388 MDT_FAIL_RETURN(OBD_FAIL_MDS_SENDPAGE, 0);
1393 static int mdt_reint_internal(struct mdt_thread_info *info,
1394 struct mdt_lock_handle *lhc,
1397 struct req_capsule *pill = &info->mti_pill;
1398 struct mdt_device *mdt = info->mti_mdt;
1399 struct mdt_body *repbody;
1400 int need_shrink = 0;
1405 if (req_capsule_has_field(pill, &RMF_MDT_MD, RCL_SERVER)) {
1406 req_capsule_set_size(pill, &RMF_MDT_MD, RCL_SERVER,
1407 mdt->mdt_max_mdsize);
1410 if (req_capsule_has_field(pill, &RMF_LOGCOOKIES, RCL_SERVER)) {
1411 req_capsule_set_size(pill, &RMF_LOGCOOKIES, RCL_SERVER,
1412 mdt->mdt_max_cookiesize);
1415 rc = req_capsule_pack(pill);
1417 CERROR("Can't pack response, rc %d\n", rc);
1418 RETURN(err_serious(rc));
1421 if (req_capsule_has_field(pill, &RMF_MDT_BODY, RCL_SERVER)) {
1422 repbody = req_capsule_server_get(pill, &RMF_MDT_BODY);
1424 repbody->eadatasize = 0;
1425 repbody->aclsize = 0;
1428 if (MDT_FAIL_CHECK(OBD_FAIL_MDS_REINT_UNPACK))
1429 GOTO(out_shrink, rc = err_serious(-EFAULT));
1431 rc = mdt_reint_unpack(info, op);
1433 CERROR("Can't unpack reint, rc %d\n", rc);
1434 GOTO(out_shrink, rc = err_serious(rc));
1437 rc = mdt_init_ucred_reint(info);
1439 GOTO(out_shrink, rc);
1441 rc = mdt_fix_attr_ucred(info, op);
1443 GOTO(out_ucred, rc = err_serious(rc));
1446 if (mdt_check_resent(info, mdt_reconstruct, lhc)) {
1447 rc = lustre_msg_get_status(mdt_info_req(info)->rq_repmsg);
1448 GOTO(out_ucred, rc);
1451 rc = mdt_reint_rec(info, lhc);
1454 mdt_exit_ucred(info);
1457 mdt_shrink_reply(info);
1461 static long mdt_reint_opcode(struct mdt_thread_info *info,
1462 const struct req_format **fmt)
1467 opc = err_serious(-EFAULT);
1468 ptr = req_capsule_client_get(&info->mti_pill, &RMF_REINT_OPC);
1471 DEBUG_REQ(D_INODE, mdt_info_req(info), "reint opt = %ld", opc);
1472 if (opc < REINT_MAX && fmt[opc] != NULL)
1473 req_capsule_extend(&info->mti_pill, fmt[opc]);
1475 CERROR("Unsupported opc: %ld\n", opc);
1476 opc = err_serious(opc);
1482 static int mdt_reint(struct mdt_thread_info *info)
1487 static const struct req_format *reint_fmts[REINT_MAX] = {
1488 [REINT_SETATTR] = &RQF_MDS_REINT_SETATTR,
1489 [REINT_CREATE] = &RQF_MDS_REINT_CREATE,
1490 [REINT_LINK] = &RQF_MDS_REINT_LINK,
1491 [REINT_UNLINK] = &RQF_MDS_REINT_UNLINK,
1492 [REINT_RENAME] = &RQF_MDS_REINT_RENAME,
1493 [REINT_OPEN] = &RQF_MDS_REINT_OPEN
1498 opc = mdt_reint_opcode(info, reint_fmts);
1501 * No lock possible here from client to pass it to reint code
1504 rc = mdt_reint_internal(info, NULL, opc);
1509 info->mti_fail_id = OBD_FAIL_MDS_REINT_NET_REP;
1513 /* TODO these two methods not available now. */
1515 /* this should sync the whole device */
1516 static int mdt_device_sync(struct mdt_thread_info *info)
1521 /* this should sync this object */
1522 static int mdt_object_sync(struct mdt_thread_info *info)
1527 static int mdt_sync(struct mdt_thread_info *info)
1529 struct req_capsule *pill = &info->mti_pill;
1530 struct mdt_body *body;
1534 /* The fid may be zero, so we req_capsule_set manually */
1535 req_capsule_set(pill, &RQF_MDS_SYNC);
1537 body = req_capsule_client_get(pill, &RMF_MDT_BODY);
1539 RETURN(err_serious(-EINVAL));
1541 if (MDT_FAIL_CHECK(OBD_FAIL_MDS_SYNC_PACK))
1542 RETURN(err_serious(-ENOMEM));
1544 if (fid_seq(&body->fid1) == 0) {
1545 /* sync the whole device */
1546 rc = req_capsule_pack(pill);
1548 rc = mdt_device_sync(info);
1550 rc = err_serious(rc);
1552 /* sync an object */
1553 rc = mdt_unpack_req_pack_rep(info, HABEO_CORPUS|HABEO_REFERO);
1555 rc = mdt_object_sync(info);
1557 struct md_object *next;
1558 const struct lu_fid *fid;
1559 struct lu_attr *la = &info->mti_attr.ma_attr;
1561 next = mdt_object_child(info->mti_object);
1562 info->mti_attr.ma_need = MA_INODE;
1563 info->mti_attr.ma_valid = 0;
1564 rc = mo_attr_get(info->mti_env, next,
1567 body = req_capsule_server_get(pill,
1569 fid = mdt_object_fid(info->mti_object);
1570 mdt_pack_attr2body(info, body, la, fid);
1574 rc = err_serious(rc);
1579 static int mdt_quotacheck_handle(struct mdt_thread_info *info)
1581 return err_serious(-EOPNOTSUPP);
1584 static int mdt_quotactl_handle(struct mdt_thread_info *info)
1586 return err_serious(-EOPNOTSUPP);
1590 * OBD PING and other handlers.
1592 static int mdt_obd_ping(struct mdt_thread_info *info)
1596 rc = target_handle_ping(mdt_info_req(info));
1598 rc = err_serious(rc);
1602 static int mdt_obd_log_cancel(struct mdt_thread_info *info)
1604 return err_serious(-EOPNOTSUPP);
1607 static int mdt_obd_qc_callback(struct mdt_thread_info *info)
1609 return err_serious(-EOPNOTSUPP);
1616 static struct ldlm_callback_suite cbs = {
1617 .lcs_completion = ldlm_server_completion_ast,
1618 .lcs_blocking = ldlm_server_blocking_ast,
1622 static int mdt_enqueue(struct mdt_thread_info *info)
1624 struct ptlrpc_request *req;
1629 * info->mti_dlm_req already contains swapped and (if necessary)
1630 * converted dlm request.
1632 LASSERT(info->mti_dlm_req != NULL);
1634 if (OBD_FAIL_CHECK(OBD_FAIL_LDLM_ENQUEUE)) {
1635 info->mti_fail_id = OBD_FAIL_LDLM_ENQUEUE;
1639 req = mdt_info_req(info);
1642 * Lock without inodebits makes no sense and will oops later in
1643 * ldlm. Let's check it now to see if we have wrong lock from client or
1644 * bits get corrupted somewhere in mdt_intent_policy().
1646 req_bits = info->mti_dlm_req->lock_desc.l_policy_data.l_inodebits.bits;
1647 LASSERT(req_bits != 0);
1649 rc = ldlm_handle_enqueue0(info->mti_mdt->mdt_namespace,
1650 req, info->mti_dlm_req, &cbs);
1651 info->mti_fail_id = OBD_FAIL_LDLM_REPLY;
1652 return rc ? err_serious(rc) : req->rq_status;
1655 static int mdt_convert(struct mdt_thread_info *info)
1658 struct ptlrpc_request *req;
1660 LASSERT(info->mti_dlm_req);
1661 req = mdt_info_req(info);
1662 rc = ldlm_handle_convert0(req, info->mti_dlm_req);
1663 return rc ? err_serious(rc) : req->rq_status;
1666 static int mdt_bl_callback(struct mdt_thread_info *info)
1668 CERROR("bl callbacks should not happen on MDS\n");
1670 return err_serious(-EOPNOTSUPP);
1673 static int mdt_cp_callback(struct mdt_thread_info *info)
1675 CERROR("cp callbacks should not happen on MDS\n");
1677 return err_serious(-EOPNOTSUPP);
1681 * sec context handlers
1683 static int mdt_sec_ctx_handle(struct mdt_thread_info *info)
1687 rc = mdt_handle_idmap(info);
1690 struct ptlrpc_request *req = mdt_info_req(info);
1693 opc = lustre_msg_get_opc(req->rq_reqmsg);
1694 if (opc == SEC_CTX_INIT || opc == SEC_CTX_INIT_CONT)
1695 sptlrpc_svc_ctx_invalidate(req);
1701 static struct mdt_object *mdt_obj(struct lu_object *o)
1703 LASSERT(lu_device_is_mdt(o->lo_dev));
1704 return container_of0(o, struct mdt_object, mot_obj.mo_lu);
1707 struct mdt_object *mdt_object_find(const struct lu_env *env,
1708 struct mdt_device *d,
1709 const struct lu_fid *f)
1711 struct lu_object *o;
1712 struct mdt_object *m;
1715 o = lu_object_find(env, d->mdt_md_dev.md_lu_dev.ld_site, f);
1716 if (unlikely(IS_ERR(o)))
1717 m = (struct mdt_object *)o;
1723 int mdt_object_lock(struct mdt_thread_info *info, struct mdt_object *o,
1724 struct mdt_lock_handle *lh, __u64 ibits, int locality)
1726 struct ldlm_namespace *ns = info->mti_mdt->mdt_namespace;
1727 ldlm_policy_data_t *policy = &info->mti_policy;
1728 struct ldlm_res_id *res_id = &info->mti_res_id;
1732 LASSERT(!lustre_handle_is_used(&lh->mlh_reg_lh));
1733 LASSERT(!lustre_handle_is_used(&lh->mlh_pdo_lh));
1734 LASSERT(lh->mlh_reg_mode != LCK_MINMODE);
1735 LASSERT(lh->mlh_type != MDT_NUL_LOCK);
1737 if (mdt_object_exists(o) < 0) {
1738 if (locality == MDT_CROSS_LOCK) {
1739 /* cross-ref object fix */
1740 ibits &= ~MDS_INODELOCK_UPDATE;
1741 ibits |= MDS_INODELOCK_LOOKUP;
1743 LASSERT(!(ibits & MDS_INODELOCK_UPDATE));
1744 LASSERT(ibits & MDS_INODELOCK_LOOKUP);
1746 /* No PDO lock on remote object */
1747 LASSERT(lh->mlh_type != MDT_PDO_LOCK);
1750 memset(policy, 0, sizeof(*policy));
1751 fid_build_reg_res_name(mdt_object_fid(o), res_id);
1754 * Take PDO lock on whole directory and build correct @res_id for lock
1755 * on part of directory.
1757 if (lh->mlh_pdo_hash != 0) {
1758 LASSERT(lh->mlh_type == MDT_PDO_LOCK);
1759 mdt_lock_pdo_mode(info, o, lh);
1760 if (lh->mlh_pdo_mode != LCK_NL) {
1762 * Do not use LDLM_FL_LOCAL_ONLY for parallel lock, it
1763 * is never going to be sent to client and we do not
1764 * want it slowed down due to possible cancels.
1766 policy->l_inodebits.bits = MDS_INODELOCK_UPDATE;
1767 rc = mdt_fid_lock(ns, &lh->mlh_pdo_lh, lh->mlh_pdo_mode,
1768 policy, res_id, LDLM_FL_ATOMIC_CB);
1774 * Finish res_id initializing by name hash marking patr of
1775 * directory which is taking modification.
1777 res_id->name[LUSTRE_RES_ID_HSH_OFF] = lh->mlh_pdo_hash;
1780 policy->l_inodebits.bits = ibits;
1783 * Use LDLM_FL_LOCAL_ONLY for this lock. We do not know yet if it is
1784 * going to be sent to client. If it is - mdt_intent_policy() path will
1785 * fix it up and turns FL_LOCAL flag off.
1787 rc = mdt_fid_lock(ns, &lh->mlh_reg_lh, lh->mlh_reg_mode, policy,
1788 res_id, LDLM_FL_LOCAL_ONLY | LDLM_FL_ATOMIC_CB);
1793 if (lh->mlh_type == MDT_PDO_LOCK) {
1794 /* check for exists after object is locked */
1795 if (mdt_object_exists(o) == 0) {
1796 /* Non-existent object shouldn't have PDO lock */
1799 /* Non-dir object shouldn't have PDO lock */
1800 LASSERT(S_ISDIR(lu_object_attr(&o->mot_obj.mo_lu)));
1805 mdt_object_unlock(info, o, lh, 1);
1812 * Just call ldlm_lock_decref() if decref, else we only call ptlrpc_save_lock()
1813 * to save this lock in req. when transaction committed, req will be released,
1814 * and lock will, too.
1816 void mdt_object_unlock(struct mdt_thread_info *info, struct mdt_object *o,
1817 struct mdt_lock_handle *lh, int decref)
1819 struct ptlrpc_request *req = mdt_info_req(info);
1822 if (lustre_handle_is_used(&lh->mlh_pdo_lh)) {
1823 /* Do not save PDO locks to request, just decref. */
1824 mdt_fid_unlock(&lh->mlh_pdo_lh,
1826 lh->mlh_pdo_lh.cookie = 0ull;
1829 if (lustre_handle_is_used(&lh->mlh_reg_lh)) {
1831 mdt_fid_unlock(&lh->mlh_reg_lh,
1834 ptlrpc_save_lock(req, &lh->mlh_reg_lh,
1837 lh->mlh_reg_lh.cookie = 0ull;
1843 struct mdt_object *mdt_object_find_lock(struct mdt_thread_info *info,
1844 const struct lu_fid *f,
1845 struct mdt_lock_handle *lh,
1848 struct mdt_object *o;
1850 o = mdt_object_find(info->mti_env, info->mti_mdt, f);
1854 rc = mdt_object_lock(info, o, lh, ibits,
1857 mdt_object_put(info->mti_env, o);
1864 void mdt_object_unlock_put(struct mdt_thread_info * info,
1865 struct mdt_object * o,
1866 struct mdt_lock_handle *lh,
1869 mdt_object_unlock(info, o, lh, decref);
1870 mdt_object_put(info->mti_env, o);
1873 static struct mdt_handler *mdt_handler_find(__u32 opc,
1874 struct mdt_opc_slice *supported)
1876 struct mdt_opc_slice *s;
1877 struct mdt_handler *h;
1880 for (s = supported; s->mos_hs != NULL; s++) {
1881 if (s->mos_opc_start <= opc && opc < s->mos_opc_end) {
1882 h = s->mos_hs + (opc - s->mos_opc_start);
1883 if (likely(h->mh_opc != 0))
1884 LASSERT(h->mh_opc == opc);
1886 h = NULL; /* unsupported opc */
1893 static int mdt_lock_resname_compat(struct mdt_device *m,
1894 struct ldlm_request *req)
1896 /* XXX something... later. */
1900 static int mdt_lock_reply_compat(struct mdt_device *m, struct ldlm_reply *rep)
1902 /* XXX something... later. */
1907 * Generic code handling requests that have struct mdt_body passed in:
1909 * - extract mdt_body from request and save it in @info, if present;
1911 * - create lu_object, corresponding to the fid in mdt_body, and save it in
1914 * - if HABEO_CORPUS flag is set for this request type check whether object
1915 * actually exists on storage (lu_object_exists()).
1918 static int mdt_body_unpack(struct mdt_thread_info *info, __u32 flags)
1920 const struct mdt_body *body;
1921 struct mdt_object *obj;
1922 const struct lu_env *env;
1923 struct req_capsule *pill;
1926 env = info->mti_env;
1927 pill = &info->mti_pill;
1929 body = info->mti_body = req_capsule_client_get(pill, &RMF_MDT_BODY);
1933 if (!fid_is_sane(&body->fid1)) {
1934 CERROR("Invalid fid: "DFID"\n", PFID(&body->fid1));
1939 * Do not get size or any capa fields before we check that request
1940 * contains capa actually. There are some requests which do not, for
1941 * instance MDS_IS_SUBDIR.
1943 if (req_capsule_has_field(pill, &RMF_CAPA1, RCL_CLIENT) &&
1944 req_capsule_get_size(pill, &RMF_CAPA1, RCL_CLIENT))
1945 mdt_set_capainfo(info, 0, &body->fid1,
1946 req_capsule_client_get(pill, &RMF_CAPA1));
1948 obj = mdt_object_find(env, info->mti_mdt, &body->fid1);
1950 if ((flags & HABEO_CORPUS) &&
1951 !mdt_object_exists(obj)) {
1952 mdt_object_put(env, obj);
1953 /* for capability renew ENOENT will be handled in
1955 if (body->valid & OBD_MD_FLOSSCAPA)
1960 info->mti_object = obj;
1969 static int mdt_unpack_req_pack_rep(struct mdt_thread_info *info, __u32 flags)
1971 struct req_capsule *pill;
1975 pill = &info->mti_pill;
1977 if (req_capsule_has_field(pill, &RMF_MDT_BODY, RCL_CLIENT))
1978 rc = mdt_body_unpack(info, flags);
1982 if (rc == 0 && (flags & HABEO_REFERO)) {
1983 struct mdt_device *mdt = info->mti_mdt;
1986 if (req_capsule_has_field(pill, &RMF_MDT_MD, RCL_SERVER))
1987 req_capsule_set_size(pill, &RMF_MDT_MD, RCL_SERVER,
1988 mdt->mdt_max_mdsize);
1989 if (req_capsule_has_field(pill, &RMF_LOGCOOKIES, RCL_SERVER))
1990 req_capsule_set_size(pill, &RMF_LOGCOOKIES, RCL_SERVER,
1991 mdt->mdt_max_cookiesize);
1993 rc = req_capsule_pack(pill);
1998 static int mdt_init_capa_ctxt(const struct lu_env *env, struct mdt_device *m)
2000 struct md_device *next = m->mdt_child;
2002 return next->md_ops->mdo_init_capa_ctxt(env, next,
2003 m->mdt_opts.mo_mds_capa,
2004 m->mdt_capa_timeout,
2010 * Invoke handler for this request opc. Also do necessary preprocessing
2011 * (according to handler ->mh_flags), and post-processing (setting of
2012 * ->last_{xid,committed}).
2014 static int mdt_req_handle(struct mdt_thread_info *info,
2015 struct mdt_handler *h, struct ptlrpc_request *req)
2017 int rc, serious = 0;
2022 LASSERT(h->mh_act != NULL);
2023 LASSERT(h->mh_opc == lustre_msg_get_opc(req->rq_reqmsg));
2024 LASSERT(current->journal_info == NULL);
2027 * Do not use *_FAIL_CHECK_ONCE() macros, because they will stop
2028 * correct handling of failed req later in ldlm due to doing
2029 * obd_fail_loc |= OBD_FAIL_ONCE | OBD_FAILED without actually
2030 * correct actions like it is done in target_send_reply_msg().
2032 if (h->mh_fail_id != 0) {
2034 * Set to info->mti_fail_id to handler fail_id, it will be used
2035 * later, and better than use default fail_id.
2037 if (OBD_FAIL_CHECK(h->mh_fail_id)) {
2038 info->mti_fail_id = h->mh_fail_id;
2044 flags = h->mh_flags;
2045 LASSERT(ergo(flags & (HABEO_CORPUS|HABEO_REFERO), h->mh_fmt != NULL));
2047 if (h->mh_fmt != NULL) {
2048 req_capsule_set(&info->mti_pill, h->mh_fmt);
2049 rc = mdt_unpack_req_pack_rep(info, flags);
2052 if (rc == 0 && flags & MUTABOR &&
2053 req->rq_export->exp_connect_flags & OBD_CONNECT_RDONLY)
2054 /* should it be rq_status? */
2057 if (rc == 0 && flags & HABEO_CLAVIS) {
2058 struct ldlm_request *dlm_req;
2060 LASSERT(h->mh_fmt != NULL);
2062 dlm_req = req_capsule_client_get(&info->mti_pill, &RMF_DLM_REQ);
2063 if (dlm_req != NULL) {
2064 if (info->mti_mdt->mdt_opts.mo_compat_resname)
2065 rc = mdt_lock_resname_compat(info->mti_mdt,
2067 info->mti_dlm_req = dlm_req;
2069 CERROR("Can't unpack dlm request\n");
2074 /* capability setting changed via /proc, needs reinitialize ctxt */
2075 if (info->mti_mdt && info->mti_mdt->mdt_capa_conf) {
2076 mdt_init_capa_ctxt(info->mti_env, info->mti_mdt);
2077 info->mti_mdt->mdt_capa_conf = 0;
2080 if (likely(rc == 0)) {
2082 * Process request, there can be two types of rc:
2083 * 1) errors with msg unpack/pack, other failures outside the
2084 * operation itself. This is counted as serious errors;
2085 * 2) errors during fs operation, should be placed in rq_status
2088 rc = h->mh_act(info);
2089 serious = is_serious(rc);
2090 rc = clear_serious(rc);
2094 req->rq_status = rc;
2097 * ELDLM_* codes which > 0 should be in rq_status only as well as
2098 * all non-serious errors.
2100 if (rc > 0 || !serious)
2103 LASSERT(current->journal_info == NULL);
2105 if (rc == 0 && (flags & HABEO_CLAVIS) &&
2106 info->mti_mdt->mdt_opts.mo_compat_resname) {
2107 struct ldlm_reply *dlmrep;
2109 dlmrep = req_capsule_server_get(&info->mti_pill, &RMF_DLM_REP);
2111 rc = mdt_lock_reply_compat(info->mti_mdt, dlmrep);
2114 /* If we're DISCONNECTing, the mdt_export_data is already freed */
2115 if (likely(rc == 0 && h->mh_opc != MDS_DISCONNECT))
2116 target_committed_to_req(req);
2118 if (unlikely((lustre_msg_get_flags(req->rq_reqmsg) & MSG_REPLAY) &&
2119 lustre_msg_get_transno(req->rq_reqmsg) == 0)) {
2120 DEBUG_REQ(D_ERROR, req, "transno is 0 during REPLAY");
2127 void mdt_lock_handle_init(struct mdt_lock_handle *lh)
2129 lh->mlh_type = MDT_NUL_LOCK;
2130 lh->mlh_reg_lh.cookie = 0ull;
2131 lh->mlh_reg_mode = LCK_MINMODE;
2132 lh->mlh_pdo_lh.cookie = 0ull;
2133 lh->mlh_pdo_mode = LCK_MINMODE;
2136 void mdt_lock_handle_fini(struct mdt_lock_handle *lh)
2138 LASSERT(!lustre_handle_is_used(&lh->mlh_reg_lh));
2139 LASSERT(!lustre_handle_is_used(&lh->mlh_pdo_lh));
2143 * Initialize fields of struct mdt_thread_info. Other fields are left in
2144 * uninitialized state, because it's too expensive to zero out whole
2145 * mdt_thread_info (> 1K) on each request arrival.
2147 static void mdt_thread_info_init(struct ptlrpc_request *req,
2148 struct mdt_thread_info *info)
2151 struct md_capainfo *ci;
2153 info->mti_rep_buf_nr = ARRAY_SIZE(info->mti_rep_buf_size);
2154 for (i = 0; i < ARRAY_SIZE(info->mti_rep_buf_size); i++)
2155 info->mti_rep_buf_size[i] = -1;
2156 req_capsule_init(&info->mti_pill, req, RCL_SERVER,
2157 info->mti_rep_buf_size);
2160 for (i = 0; i < ARRAY_SIZE(info->mti_lh); i++)
2161 mdt_lock_handle_init(&info->mti_lh[i]);
2163 /* mdt device: it can be NULL while CONNECT */
2164 if (req->rq_export) {
2165 info->mti_mdt = mdt_dev(req->rq_export->exp_obd->obd_lu_dev);
2166 info->mti_exp = req->rq_export;
2168 info->mti_mdt = NULL;
2169 info->mti_env = req->rq_svc_thread->t_env;
2170 ci = md_capainfo(info->mti_env);
2171 memset(ci, 0, sizeof *ci);
2173 info->mti_fail_id = OBD_FAIL_MDS_ALL_REPLY_NET;
2174 info->mti_transno = lustre_msg_get_transno(req->rq_reqmsg);
2176 memset(&info->mti_attr, 0, sizeof(info->mti_attr));
2177 info->mti_body = NULL;
2178 info->mti_object = NULL;
2179 info->mti_dlm_req = NULL;
2180 info->mti_has_trans = 0;
2181 info->mti_no_need_trans = 0;
2182 info->mti_cross_ref = 0;
2183 info->mti_opdata = 0;
2185 /* To not check for split by default. */
2186 info->mti_spec.sp_ck_split = 0;
2189 static void mdt_thread_info_fini(struct mdt_thread_info *info)
2193 req_capsule_fini(&info->mti_pill);
2194 if (info->mti_object != NULL) {
2195 mdt_object_put(info->mti_env, info->mti_object);
2196 info->mti_object = NULL;
2198 for (i = 0; i < ARRAY_SIZE(info->mti_lh); i++)
2199 mdt_lock_handle_fini(&info->mti_lh[i]);
2200 info->mti_env = NULL;
2204 extern int mds_filter_recovery_request(struct ptlrpc_request *req,
2205 struct obd_device *obd, int *process);
2207 * Handle recovery. Return:
2208 * +1: continue request processing;
2209 * -ve: abort immediately with the given error code;
2210 * 0: send reply with error code in req->rq_status;
2212 static int mdt_recovery(struct mdt_thread_info *info)
2214 struct ptlrpc_request *req = mdt_info_req(info);
2216 struct obd_device *obd;
2220 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
2223 case SEC_CTX_INIT_CONT:
2229 rc = mdt_handle_idmap(info);
2238 if (unlikely(req->rq_export == NULL)) {
2239 CERROR("operation %d on unconnected MDS from %s\n",
2240 lustre_msg_get_opc(req->rq_reqmsg),
2241 libcfs_id2str(req->rq_peer));
2242 /* FIXME: For CMD cleanup, when mds_B stop, the req from
2243 * mds_A will get -ENOTCONN(especially for ping req),
2244 * which will cause that mds_A deactive timeout, then when
2245 * mds_A cleanup, the cleanup process will be suspended since
2246 * deactive timeout is not zero.
2248 req->rq_status = -ENOTCONN;
2249 target_send_reply(req, -ENOTCONN, info->mti_fail_id);
2253 /* sanity check: if the xid matches, the request must be marked as a
2254 * resent or replayed */
2255 if (req_xid_is_last(req)) {
2256 if (!(lustre_msg_get_flags(req->rq_reqmsg) &
2257 (MSG_RESENT | MSG_REPLAY))) {
2258 DEBUG_REQ(D_WARNING, req, "rq_xid "LPU64" matches last_xid, "
2259 "expected REPLAY or RESENT flag (%x)", req->rq_xid,
2260 lustre_msg_get_flags(req->rq_reqmsg));
2262 req->rq_status = -ENOTCONN;
2267 /* else: note the opposite is not always true; a RESENT req after a
2268 * failover will usually not match the last_xid, since it was likely
2269 * never committed. A REPLAYed request will almost never match the
2270 * last xid, however it could for a committed, but still retained,
2273 obd = req->rq_export->exp_obd;
2275 /* Check for aborted recovery... */
2276 spin_lock_bh(&obd->obd_processing_task_lock);
2277 recovering = obd->obd_recovering;
2278 spin_unlock_bh(&obd->obd_processing_task_lock);
2279 if (unlikely(recovering)) {
2282 DEBUG_REQ(D_INFO, req, "Got new replay");
2283 rc = mds_filter_recovery_request(req, obd, &should_process);
2284 if (rc != 0 || !should_process)
2286 else if (should_process < 0) {
2287 req->rq_status = should_process;
2288 rc = ptlrpc_error(req);
2295 static int mdt_reply(struct ptlrpc_request *req, int rc,
2296 struct mdt_thread_info *info)
2301 if (req->rq_reply_state == NULL && rc == 0) {
2302 req->rq_status = rc;
2303 lustre_pack_reply(req, 1, NULL, NULL);
2306 target_send_reply(req, rc, info->mti_fail_id);
2311 extern int mds_msg_check_version(struct lustre_msg *msg);
2313 static int mdt_handle0(struct ptlrpc_request *req,
2314 struct mdt_thread_info *info,
2315 struct mdt_opc_slice *supported)
2317 struct mdt_handler *h;
2318 struct lustre_msg *msg;
2323 MDT_FAIL_RETURN(OBD_FAIL_MDS_ALL_REQUEST_NET | OBD_FAIL_ONCE, 0);
2325 LASSERT(current->journal_info == NULL);
2327 msg = req->rq_reqmsg;
2328 rc = mds_msg_check_version(msg);
2329 if (likely(rc == 0)) {
2330 rc = mdt_recovery(info);
2331 if (likely(rc == +1)) {
2332 h = mdt_handler_find(lustre_msg_get_opc(msg),
2334 if (likely(h != NULL)) {
2335 rc = mdt_req_handle(info, h, req);
2336 rc = mdt_reply(req, rc, info);
2338 CERROR("The unsupported opc: 0x%x\n", lustre_msg_get_opc(msg) );
2339 req->rq_status = -ENOTSUPP;
2340 rc = ptlrpc_error(req);
2345 CERROR(LUSTRE_MDT_NAME" drops mal-formed request\n");
2350 * MDT handler function called by ptlrpc service thread when request comes.
2352 * XXX common "target" functionality should be factored into separate module
2353 * shared by mdt, ost and stand-alone services like fld.
2355 static int mdt_handle_common(struct ptlrpc_request *req,
2356 struct mdt_opc_slice *supported)
2359 struct mdt_thread_info *info;
2363 env = req->rq_svc_thread->t_env;
2364 LASSERT(env != NULL);
2365 LASSERT(env->le_ses != NULL);
2366 LASSERT(env->le_ctx.lc_thread == req->rq_svc_thread);
2367 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
2368 LASSERT(info != NULL);
2370 mdt_thread_info_init(req, info);
2372 rc = mdt_handle0(req, info, supported);
2374 mdt_thread_info_fini(info);
2379 * This is called from recovery code as handler of _all_ RPC types, FLD and SEQ
2382 int mdt_recovery_handle(struct ptlrpc_request *req)
2387 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
2389 rc = mdt_handle_common(req, mdt_fld_handlers);
2392 rc = mdt_handle_common(req, mdt_seq_handlers);
2395 rc = mdt_handle_common(req, mdt_regular_handlers);
2402 static int mdt_regular_handle(struct ptlrpc_request *req)
2404 return mdt_handle_common(req, mdt_regular_handlers);
2407 static int mdt_readpage_handle(struct ptlrpc_request *req)
2409 return mdt_handle_common(req, mdt_readpage_handlers);
2412 static int mdt_xmds_handle(struct ptlrpc_request *req)
2414 return mdt_handle_common(req, mdt_xmds_handlers);
2417 static int mdt_mdsc_handle(struct ptlrpc_request *req)
2419 return mdt_handle_common(req, mdt_seq_handlers);
2422 static int mdt_mdss_handle(struct ptlrpc_request *req)
2424 return mdt_handle_common(req, mdt_seq_handlers);
2427 static int mdt_dtss_handle(struct ptlrpc_request *req)
2429 return mdt_handle_common(req, mdt_seq_handlers);
2432 static int mdt_fld_handle(struct ptlrpc_request *req)
2434 return mdt_handle_common(req, mdt_fld_handlers);
2450 static int mdt_intent_getattr(enum mdt_it_code opcode,
2451 struct mdt_thread_info *info,
2452 struct ldlm_lock **,
2454 static int mdt_intent_reint(enum mdt_it_code opcode,
2455 struct mdt_thread_info *info,
2456 struct ldlm_lock **,
2459 static struct mdt_it_flavor {
2460 const struct req_format *it_fmt;
2462 int (*it_act)(enum mdt_it_code ,
2463 struct mdt_thread_info *,
2464 struct ldlm_lock **,
2467 } mdt_it_flavor[] = {
2469 .it_fmt = &RQF_LDLM_INTENT,
2470 /*.it_flags = HABEO_REFERO,*/
2472 .it_act = mdt_intent_reint,
2473 .it_reint = REINT_OPEN
2476 .it_fmt = &RQF_LDLM_INTENT,
2477 .it_flags = MUTABOR,
2478 .it_act = mdt_intent_reint,
2479 .it_reint = REINT_OPEN
2482 .it_fmt = &RQF_LDLM_INTENT,
2483 .it_flags = MUTABOR,
2484 .it_act = mdt_intent_reint,
2485 .it_reint = REINT_CREATE
2487 [MDT_IT_GETATTR] = {
2488 .it_fmt = &RQF_LDLM_INTENT_GETATTR,
2489 .it_flags = HABEO_REFERO,
2490 .it_act = mdt_intent_getattr
2492 [MDT_IT_READDIR] = {
2498 .it_fmt = &RQF_LDLM_INTENT_GETATTR,
2499 .it_flags = HABEO_REFERO,
2500 .it_act = mdt_intent_getattr
2503 .it_fmt = &RQF_LDLM_INTENT_UNLINK,
2504 .it_flags = MUTABOR,
2506 .it_reint = REINT_UNLINK
2510 .it_flags = MUTABOR,
2513 [MDT_IT_GETXATTR] = {
2520 int mdt_intent_lock_replace(struct mdt_thread_info *info,
2521 struct ldlm_lock **lockp,
2522 struct ldlm_lock *new_lock,
2523 struct mdt_lock_handle *lh,
2526 struct ptlrpc_request *req = mdt_info_req(info);
2527 struct ldlm_lock *lock = *lockp;
2530 * Get new lock only for cases when possible resent did not find any
2533 if (new_lock == NULL)
2534 new_lock = ldlm_handle2lock(&lh->mlh_reg_lh);
2536 if (new_lock == NULL && (flags & LDLM_FL_INTENT_ONLY)) {
2537 lh->mlh_reg_lh.cookie = 0;
2541 LASSERTF(new_lock != NULL,
2542 "lockh "LPX64"\n", lh->mlh_reg_lh.cookie);
2545 * If we've already given this lock to a client once, then we should
2546 * have no readers or writers. Otherwise, we should have one reader
2547 * _or_ writer ref (which will be zeroed below) before returning the
2550 if (new_lock->l_export == req->rq_export) {
2551 LASSERT(new_lock->l_readers + new_lock->l_writers == 0);
2553 LASSERT(new_lock->l_export == NULL);
2554 LASSERT(new_lock->l_readers + new_lock->l_writers == 1);
2559 if (new_lock->l_export == req->rq_export) {
2561 * Already gave this to the client, which means that we
2562 * reconstructed a reply.
2564 LASSERT(lustre_msg_get_flags(req->rq_reqmsg) &
2566 lh->mlh_reg_lh.cookie = 0;
2567 RETURN(ELDLM_LOCK_REPLACED);
2570 /* This lock might already be given to the client by an resent req,
2571 * in this case we should return ELDLM_LOCK_ABORTED,
2572 * so we should check led_held_locks here, but it will affect
2573 * performance, FIXME
2575 /* Fixup the lock to be given to the client */
2576 lock_res_and_lock(new_lock);
2577 new_lock->l_readers = 0;
2578 new_lock->l_writers = 0;
2580 new_lock->l_export = class_export_get(req->rq_export);
2581 spin_lock(&req->rq_export->exp_ldlm_data.led_lock);
2582 list_add(&new_lock->l_export_chain,
2583 &new_lock->l_export->exp_ldlm_data.led_held_locks);
2584 spin_unlock(&req->rq_export->exp_ldlm_data.led_lock);
2586 new_lock->l_blocking_ast = lock->l_blocking_ast;
2587 new_lock->l_completion_ast = lock->l_completion_ast;
2588 new_lock->l_remote_handle = lock->l_remote_handle;
2589 new_lock->l_flags &= ~LDLM_FL_LOCAL;
2591 unlock_res_and_lock(new_lock);
2592 LDLM_LOCK_PUT(new_lock);
2593 lh->mlh_reg_lh.cookie = 0;
2595 RETURN(ELDLM_LOCK_REPLACED);
2598 static void mdt_intent_fixup_resent(struct mdt_thread_info *info,
2599 struct ldlm_lock *new_lock,
2600 struct ldlm_lock **old_lock,
2601 struct mdt_lock_handle *lh)
2603 struct ptlrpc_request *req = mdt_info_req(info);
2604 struct obd_export *exp = req->rq_export;
2605 struct lustre_handle remote_hdl;
2606 struct ldlm_request *dlmreq;
2607 struct list_head *iter;
2609 if (!(lustre_msg_get_flags(req->rq_reqmsg) & MSG_RESENT))
2612 dlmreq = req_capsule_client_get(&info->mti_pill, &RMF_DLM_REQ);
2613 remote_hdl = dlmreq->lock_handle[0];
2615 spin_lock(&exp->exp_ldlm_data.led_lock);
2616 list_for_each(iter, &exp->exp_ldlm_data.led_held_locks) {
2617 struct ldlm_lock *lock;
2618 lock = list_entry(iter, struct ldlm_lock, l_export_chain);
2619 if (lock == new_lock)
2621 if (lock->l_remote_handle.cookie == remote_hdl.cookie) {
2622 lh->mlh_reg_lh.cookie = lock->l_handle.h_cookie;
2623 lh->mlh_reg_mode = lock->l_granted_mode;
2625 LDLM_DEBUG(lock, "restoring lock cookie");
2626 DEBUG_REQ(D_HA, req, "restoring lock cookie "LPX64,
2627 lh->mlh_reg_lh.cookie);
2629 *old_lock = LDLM_LOCK_GET(lock);
2630 spin_unlock(&exp->exp_ldlm_data.led_lock);
2634 spin_unlock(&exp->exp_ldlm_data.led_lock);
2637 * If the xid matches, then we know this is a resent request, and allow
2638 * it. (It's probably an OPEN, for which we don't send a lock.
2640 if (req_xid_is_last(req))
2644 * This remote handle isn't enqueued, so we never received or processed
2645 * this request. Clear MSG_RESENT, because it can be handled like any
2646 * normal request now.
2648 lustre_msg_clear_flags(req->rq_reqmsg, MSG_RESENT);
2650 DEBUG_REQ(D_HA, req, "no existing lock with rhandle "LPX64,
2654 static int mdt_intent_getattr(enum mdt_it_code opcode,
2655 struct mdt_thread_info *info,
2656 struct ldlm_lock **lockp,
2659 struct mdt_lock_handle *lhc = &info->mti_lh[MDT_LH_RMT];
2660 struct ldlm_lock *new_lock = NULL;
2662 struct ldlm_reply *ldlm_rep;
2663 struct ptlrpc_request *req;
2664 struct mdt_body *reqbody;
2665 struct mdt_body *repbody;
2669 reqbody = req_capsule_client_get(&info->mti_pill, &RMF_MDT_BODY);
2672 repbody = req_capsule_server_get(&info->mti_pill, &RMF_MDT_BODY);
2675 info->mti_spec.sp_ck_split = !!(reqbody->valid & OBD_MD_FLCKSPLIT);
2676 info->mti_cross_ref = !!(reqbody->valid & OBD_MD_FLCROSSREF);
2677 repbody->eadatasize = 0;
2678 repbody->aclsize = 0;
2682 child_bits = MDS_INODELOCK_LOOKUP;
2684 case MDT_IT_GETATTR:
2685 child_bits = MDS_INODELOCK_LOOKUP | MDS_INODELOCK_UPDATE;
2688 CERROR("Unhandled till now");
2689 GOTO(out, rc = -EINVAL);
2692 rc = mdt_init_ucred(info, reqbody);
2696 req = info->mti_pill.rc_req;
2697 ldlm_rep = req_capsule_server_get(&info->mti_pill, &RMF_DLM_REP);
2698 mdt_set_disposition(info, ldlm_rep, DISP_IT_EXECD);
2700 /* Get lock from request for possible resent case. */
2701 mdt_intent_fixup_resent(info, *lockp, &new_lock, lhc);
2703 ldlm_rep->lock_policy_res2 =
2704 mdt_getattr_name_lock(info, lhc, child_bits, ldlm_rep);
2706 if (mdt_get_disposition(ldlm_rep, DISP_LOOKUP_NEG))
2707 ldlm_rep->lock_policy_res2 = 0;
2708 if (!mdt_get_disposition(ldlm_rep, DISP_LOOKUP_POS) ||
2709 ldlm_rep->lock_policy_res2) {
2710 lhc->mlh_reg_lh.cookie = 0ull;
2711 GOTO(out_ucred, rc = ELDLM_LOCK_ABORTED);
2714 rc = mdt_intent_lock_replace(info, lockp, new_lock, lhc, flags);
2717 mdt_exit_ucred(info);
2719 mdt_shrink_reply(info);
2723 static int mdt_intent_reint(enum mdt_it_code opcode,
2724 struct mdt_thread_info *info,
2725 struct ldlm_lock **lockp,
2728 struct mdt_lock_handle *lhc = &info->mti_lh[MDT_LH_RMT];
2729 struct ldlm_reply *rep = NULL;
2733 static const struct req_format *intent_fmts[REINT_MAX] = {
2734 [REINT_CREATE] = &RQF_LDLM_INTENT_CREATE,
2735 [REINT_OPEN] = &RQF_LDLM_INTENT_OPEN
2740 opc = mdt_reint_opcode(info, intent_fmts);
2742 GOTO(out, rc = opc);
2744 if (mdt_it_flavor[opcode].it_reint != opc) {
2745 CERROR("Reint code %ld doesn't match intent: %d\n",
2747 GOTO(out, rc = err_serious(-EPROTO));
2750 /* Get lock from request for possible resent case. */
2751 mdt_intent_fixup_resent(info, *lockp, NULL, lhc);
2753 rc = mdt_reint_internal(info, lhc, opc);
2755 /* Check whether the reply has been packed successfully. */
2756 if (mdt_info_req(info)->rq_repmsg != NULL)
2757 rep = req_capsule_server_get(&info->mti_pill, &RMF_DLM_REP);
2759 GOTO(out, rc = err_serious(-EFAULT));
2761 /* MDC expects this in any case */
2763 mdt_set_disposition(info, rep, DISP_LOOKUP_EXECD);
2765 /* Cross-ref case, the lock should be returned to the client */
2766 if (rc == -EREMOTE) {
2767 LASSERT(lustre_handle_is_used(&lhc->mlh_reg_lh));
2768 rep->lock_policy_res2 = 0;
2769 rc = mdt_intent_lock_replace(info, lockp, NULL, lhc, flags);
2772 rep->lock_policy_res2 = clear_serious(rc);
2774 lhc->mlh_reg_lh.cookie = 0ull;
2775 rc = ELDLM_LOCK_ABORTED;
2781 static int mdt_intent_code(long itcode)
2789 case IT_OPEN|IT_CREAT:
2796 rc = MDT_IT_READDIR;
2799 rc = MDT_IT_GETATTR;
2811 rc = MDT_IT_GETXATTR;
2814 CERROR("Unknown intent opcode: %ld\n", itcode);
2821 static int mdt_intent_opc(long itopc, struct mdt_thread_info *info,
2822 struct ldlm_lock **lockp, int flags)
2824 struct req_capsule *pill;
2825 struct mdt_it_flavor *flv;
2830 opc = mdt_intent_code(itopc);
2834 pill = &info->mti_pill;
2835 flv = &mdt_it_flavor[opc];
2837 if (flv->it_fmt != NULL)
2838 req_capsule_extend(pill, flv->it_fmt);
2840 rc = mdt_unpack_req_pack_rep(info, flv->it_flags);
2842 struct ptlrpc_request *req = mdt_info_req(info);
2843 if (flv->it_flags & MUTABOR &&
2844 req->rq_export->exp_connect_flags & OBD_CONNECT_RDONLY)
2847 if (rc == 0 && flv->it_act != NULL) {
2848 /* execute policy */
2849 rc = flv->it_act(opc, info, lockp, flags);
2855 static int mdt_intent_policy(struct ldlm_namespace *ns,
2856 struct ldlm_lock **lockp, void *req_cookie,
2857 ldlm_mode_t mode, int flags, void *data)
2859 struct mdt_thread_info *info;
2860 struct ptlrpc_request *req = req_cookie;
2861 struct ldlm_intent *it;
2862 struct req_capsule *pill;
2867 LASSERT(req != NULL);
2869 info = lu_context_key_get(&req->rq_svc_thread->t_env->le_ctx,
2871 LASSERT(info != NULL);
2872 pill = &info->mti_pill;
2873 LASSERT(pill->rc_req == req);
2875 if (req->rq_reqmsg->lm_bufcount > DLM_INTENT_IT_OFF) {
2876 req_capsule_extend(pill, &RQF_LDLM_INTENT);
2877 it = req_capsule_client_get(pill, &RMF_LDLM_INTENT);
2879 const struct ldlm_request *dlmreq;
2882 struct ldlm_lock *lock = *lockp;
2884 LDLM_DEBUG(lock, "intent policy opc: %s\n",
2885 ldlm_it2str(it->opc));
2888 rc = mdt_intent_opc(it->opc, info, lockp, flags);
2893 * Lock without inodebits makes no sense and will oops
2894 * later in ldlm. Let's check it now to see if we have
2895 * wrong lock from client or bits get corrupted
2896 * somewhere in mdt_intent_opc().
2898 dlmreq = info->mti_dlm_req;
2899 req_bits = dlmreq->lock_desc.l_policy_data.l_inodebits.bits;
2900 LASSERT(req_bits != 0);
2903 rc = err_serious(-EFAULT);
2905 /* No intent was provided */
2906 LASSERT(pill->rc_fmt == &RQF_LDLM_ENQUEUE);
2907 rc = req_capsule_pack(pill);
2909 rc = err_serious(rc);
2917 static void mdt_seq_adjust(const struct lu_env *env,
2918 struct mdt_device *m, int lost)
2920 struct lu_site *ls = m->mdt_md_dev.md_lu_dev.ld_site;
2921 struct lu_range out;
2924 LASSERT(ls && ls->ls_server_seq);
2926 /* get extra seq from seq_server, moving it's range up */
2927 while (lost-- > 0) {
2928 seq_server_alloc_meta(ls->ls_server_seq, NULL, &out, env);
2933 static int mdt_seq_fini(const struct lu_env *env,
2934 struct mdt_device *m)
2936 struct lu_site *ls = m->mdt_md_dev.md_lu_dev.ld_site;
2939 if (ls && ls->ls_server_seq) {
2940 seq_server_fini(ls->ls_server_seq, env);
2941 OBD_FREE_PTR(ls->ls_server_seq);
2942 ls->ls_server_seq = NULL;
2945 if (ls && ls->ls_control_seq) {
2946 seq_server_fini(ls->ls_control_seq, env);
2947 OBD_FREE_PTR(ls->ls_control_seq);
2948 ls->ls_control_seq = NULL;
2951 if (ls && ls->ls_client_seq) {
2952 seq_client_fini(ls->ls_client_seq);
2953 OBD_FREE_PTR(ls->ls_client_seq);
2954 ls->ls_client_seq = NULL;
2960 static int mdt_seq_init(const struct lu_env *env,
2962 struct mdt_device *m)
2969 ls = m->mdt_md_dev.md_lu_dev.ld_site;
2972 * This is sequence-controller node. Init seq-controller server on local
2975 if (ls->ls_node_id == 0) {
2976 LASSERT(ls->ls_control_seq == NULL);
2978 OBD_ALLOC_PTR(ls->ls_control_seq);
2979 if (ls->ls_control_seq == NULL)
2982 rc = seq_server_init(ls->ls_control_seq,
2983 m->mdt_bottom, uuid,
2984 LUSTRE_SEQ_CONTROLLER,
2988 GOTO(out_seq_fini, rc);
2990 OBD_ALLOC_PTR(ls->ls_client_seq);
2991 if (ls->ls_client_seq == NULL)
2992 GOTO(out_seq_fini, rc = -ENOMEM);
2994 OBD_ALLOC(prefix, MAX_OBD_NAME + 5);
2995 if (prefix == NULL) {
2996 OBD_FREE_PTR(ls->ls_client_seq);
2997 GOTO(out_seq_fini, rc = -ENOMEM);
3000 snprintf(prefix, MAX_OBD_NAME + 5, "ctl-%s",
3004 * Init seq-controller client after seq-controller server is
3005 * ready. Pass ls->ls_control_seq to it for direct talking.
3007 rc = seq_client_init(ls->ls_client_seq, NULL,
3008 LUSTRE_SEQ_METADATA, prefix,
3009 ls->ls_control_seq);
3010 OBD_FREE(prefix, MAX_OBD_NAME + 5);
3013 GOTO(out_seq_fini, rc);
3016 /* Init seq-server on local MDT */
3017 LASSERT(ls->ls_server_seq == NULL);
3019 OBD_ALLOC_PTR(ls->ls_server_seq);
3020 if (ls->ls_server_seq == NULL)
3021 GOTO(out_seq_fini, rc = -ENOMEM);
3023 rc = seq_server_init(ls->ls_server_seq,
3024 m->mdt_bottom, uuid,
3028 GOTO(out_seq_fini, rc = -ENOMEM);
3030 /* Assign seq-controller client to local seq-server. */
3031 if (ls->ls_node_id == 0) {
3032 LASSERT(ls->ls_client_seq != NULL);
3034 rc = seq_server_set_cli(ls->ls_server_seq,
3042 mdt_seq_fini(env, m);
3047 * Init client sequence manager which is used by local MDS to talk to sequence
3048 * controller on remote node.
3050 static int mdt_seq_init_cli(const struct lu_env *env,
3051 struct mdt_device *m,
3052 struct lustre_cfg *cfg)
3054 struct lu_site *ls = m->mdt_md_dev.md_lu_dev.ld_site;
3055 struct obd_device *mdc;
3056 struct obd_uuid *uuidp, *mdcuuidp;
3057 char *uuid_str, *mdc_uuid_str;
3060 struct mdt_thread_info *info;
3061 char *p, *index_string = lustre_cfg_string(cfg, 2);
3064 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
3065 uuidp = &info->mti_u.uuid[0];
3066 mdcuuidp = &info->mti_u.uuid[1];
3068 LASSERT(index_string);
3070 index = simple_strtol(index_string, &p, 10);
3072 CERROR("Invalid index in lustre_cgf, offset 2\n");
3076 /* check if this is adding the first MDC and controller is not yet
3078 if (index != 0 || ls->ls_client_seq)
3081 uuid_str = lustre_cfg_string(cfg, 1);
3082 mdc_uuid_str = lustre_cfg_string(cfg, 4);
3083 obd_str2uuid(uuidp, uuid_str);
3084 obd_str2uuid(mdcuuidp, mdc_uuid_str);
3086 mdc = class_find_client_obd(uuidp, LUSTRE_MDC_NAME, mdcuuidp);
3088 CERROR("can't find controller MDC by uuid %s\n",
3091 } else if (!mdc->obd_set_up) {
3092 CERROR("target %s not set up\n", mdc->obd_name);
3095 LASSERT(ls->ls_control_exp);
3096 OBD_ALLOC_PTR(ls->ls_client_seq);
3097 if (ls->ls_client_seq != NULL) {
3100 OBD_ALLOC(prefix, MAX_OBD_NAME + 5);
3104 snprintf(prefix, MAX_OBD_NAME + 5, "ctl-%s",
3107 rc = seq_client_init(ls->ls_client_seq,
3109 LUSTRE_SEQ_METADATA,
3111 OBD_FREE(prefix, MAX_OBD_NAME + 5);
3118 LASSERT(ls->ls_server_seq != NULL);
3119 rc = seq_server_set_cli(ls->ls_server_seq, ls->ls_client_seq,
3126 static void mdt_seq_fini_cli(struct mdt_device *m)
3132 ls = m->mdt_md_dev.md_lu_dev.ld_site;
3134 if (ls && ls->ls_server_seq)
3135 seq_server_set_cli(ls->ls_server_seq,
3138 if (ls && ls->ls_control_exp) {
3139 class_export_put(ls->ls_control_exp);
3140 ls->ls_control_exp = NULL;
3148 static int mdt_fld_fini(const struct lu_env *env,
3149 struct mdt_device *m)
3151 struct lu_site *ls = m->mdt_md_dev.md_lu_dev.ld_site;
3154 if (ls && ls->ls_server_fld) {
3155 fld_server_fini(ls->ls_server_fld, env);
3156 OBD_FREE_PTR(ls->ls_server_fld);
3157 ls->ls_server_fld = NULL;
3163 static int mdt_fld_init(const struct lu_env *env,
3165 struct mdt_device *m)
3171 ls = m->mdt_md_dev.md_lu_dev.ld_site;
3173 OBD_ALLOC_PTR(ls->ls_server_fld);
3174 if (ls->ls_server_fld == NULL)
3175 RETURN(rc = -ENOMEM);
3177 rc = fld_server_init(ls->ls_server_fld,
3178 m->mdt_bottom, uuid, env);
3180 OBD_FREE_PTR(ls->ls_server_fld);
3181 ls->ls_server_fld = NULL;
3188 /* device init/fini methods */
3189 static void mdt_stop_ptlrpc_service(struct mdt_device *m)
3192 if (m->mdt_regular_service != NULL) {
3193 ptlrpc_unregister_service(m->mdt_regular_service);
3194 m->mdt_regular_service = NULL;
3196 if (m->mdt_readpage_service != NULL) {
3197 ptlrpc_unregister_service(m->mdt_readpage_service);
3198 m->mdt_readpage_service = NULL;
3200 if (m->mdt_xmds_service != NULL) {
3201 ptlrpc_unregister_service(m->mdt_xmds_service);
3202 m->mdt_xmds_service = NULL;
3204 if (m->mdt_setattr_service != NULL) {
3205 ptlrpc_unregister_service(m->mdt_setattr_service);
3206 m->mdt_setattr_service = NULL;
3208 if (m->mdt_mdsc_service != NULL) {
3209 ptlrpc_unregister_service(m->mdt_mdsc_service);
3210 m->mdt_mdsc_service = NULL;
3212 if (m->mdt_mdss_service != NULL) {
3213 ptlrpc_unregister_service(m->mdt_mdss_service);
3214 m->mdt_mdss_service = NULL;
3216 if (m->mdt_dtss_service != NULL) {
3217 ptlrpc_unregister_service(m->mdt_dtss_service);
3218 m->mdt_dtss_service = NULL;
3220 if (m->mdt_fld_service != NULL) {
3221 ptlrpc_unregister_service(m->mdt_fld_service);
3222 m->mdt_fld_service = NULL;
3227 static int mdt_start_ptlrpc_service(struct mdt_device *m)
3230 static struct ptlrpc_service_conf conf;
3231 cfs_proc_dir_entry_t *procfs_entry;
3234 procfs_entry = m->mdt_md_dev.md_lu_dev.ld_obd->obd_proc_entry;
3236 conf = (typeof(conf)) {
3237 .psc_nbufs = MDS_NBUFS,
3238 .psc_bufsize = MDS_BUFSIZE,
3239 .psc_max_req_size = MDS_MAXREQSIZE,
3240 .psc_max_reply_size = MDS_MAXREPSIZE,
3241 .psc_req_portal = MDS_REQUEST_PORTAL,
3242 .psc_rep_portal = MDC_REPLY_PORTAL,
3243 .psc_watchdog_timeout = MDT_SERVICE_WATCHDOG_TIMEOUT,
3245 * We'd like to have a mechanism to set this on a per-device
3246 * basis, but alas...
3248 .psc_min_threads = min(max(mdt_num_threads, MDT_MIN_THREADS),
3250 .psc_max_threads = MDT_MAX_THREADS,
3251 .psc_ctx_tags = LCT_MD_THREAD
3254 m->mdt_ldlm_client = &m->mdt_md_dev.md_lu_dev.ld_obd->obd_ldlm_client;
3255 ptlrpc_init_client(LDLM_CB_REQUEST_PORTAL, LDLM_CB_REPLY_PORTAL,
3256 "mdt_ldlm_client", m->mdt_ldlm_client);
3258 m->mdt_regular_service =
3259 ptlrpc_init_svc_conf(&conf, mdt_regular_handle, LUSTRE_MDT_NAME,