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 ptlrpc_request *req = mdt_info_req(info);
1400 struct mdt_body *repbody;
1401 int need_shrink = 0;
1406 if (req_capsule_has_field(pill, &RMF_MDT_MD, RCL_SERVER)) {
1407 req_capsule_set_size(pill, &RMF_MDT_MD, RCL_SERVER,
1408 mdt->mdt_max_mdsize);
1411 if (req_capsule_has_field(pill, &RMF_LOGCOOKIES, RCL_SERVER)) {
1412 req_capsule_set_size(pill, &RMF_LOGCOOKIES, RCL_SERVER,
1413 mdt->mdt_max_cookiesize);
1416 rc = req_capsule_pack(pill);
1418 CERROR("Can't pack response, rc %d\n", rc);
1419 RETURN(err_serious(rc));
1422 if (req_capsule_has_field(pill, &RMF_MDT_BODY, RCL_SERVER)) {
1423 repbody = req_capsule_server_get(pill, &RMF_MDT_BODY);
1425 repbody->eadatasize = 0;
1426 repbody->aclsize = 0;
1429 if (MDT_FAIL_CHECK(OBD_FAIL_MDS_REINT_UNPACK))
1430 GOTO(out_shrink, rc = err_serious(-EFAULT));
1432 rc = mdt_reint_unpack(info, op);
1434 CERROR("Can't unpack reint, rc %d\n", rc);
1435 GOTO(out_shrink, rc = err_serious(rc));
1438 rc = mdt_init_ucred_reint(info);
1440 GOTO(out_shrink, rc);
1442 rc = mdt_fix_attr_ucred(info, op);
1444 GOTO(out_ucred, rc = err_serious(rc));
1446 if (lustre_msg_get_flags(req->rq_reqmsg) & MSG_RESENT) {
1447 struct mdt_client_data *mcd;
1449 mcd = req->rq_export->exp_mdt_data.med_mcd;
1450 if (req_xid_is_last(req)) {
1452 mdt_reconstruct(info, lhc);
1453 rc = lustre_msg_get_status(req->rq_repmsg);
1454 GOTO(out_ucred, rc);
1456 DEBUG_REQ(D_HA, req, "no reply for RESENT (xid "LPD64")",
1461 rc = mdt_reint_rec(info, lhc);
1464 mdt_exit_ucred(info);
1467 mdt_shrink_reply(info);
1471 static long mdt_reint_opcode(struct mdt_thread_info *info,
1472 const struct req_format **fmt)
1477 opc = err_serious(-EFAULT);
1478 ptr = req_capsule_client_get(&info->mti_pill, &RMF_REINT_OPC);
1481 DEBUG_REQ(D_INODE, mdt_info_req(info), "reint opt = %ld", opc);
1482 if (opc < REINT_MAX && fmt[opc] != NULL)
1483 req_capsule_extend(&info->mti_pill, fmt[opc]);
1485 CERROR("Unsupported opc: %ld\n", opc);
1486 opc = err_serious(opc);
1492 static int mdt_reint(struct mdt_thread_info *info)
1497 static const struct req_format *reint_fmts[REINT_MAX] = {
1498 [REINT_SETATTR] = &RQF_MDS_REINT_SETATTR,
1499 [REINT_CREATE] = &RQF_MDS_REINT_CREATE,
1500 [REINT_LINK] = &RQF_MDS_REINT_LINK,
1501 [REINT_UNLINK] = &RQF_MDS_REINT_UNLINK,
1502 [REINT_RENAME] = &RQF_MDS_REINT_RENAME,
1503 [REINT_OPEN] = &RQF_MDS_REINT_OPEN
1508 opc = mdt_reint_opcode(info, reint_fmts);
1511 * No lock possible here from client to pass it to reint code
1514 rc = mdt_reint_internal(info, NULL, opc);
1519 info->mti_fail_id = OBD_FAIL_MDS_REINT_NET_REP;
1523 /* TODO these two methods not available now. */
1525 /* this should sync the whole device */
1526 static int mdt_device_sync(struct mdt_thread_info *info)
1531 /* this should sync this object */
1532 static int mdt_object_sync(struct mdt_thread_info *info)
1537 static int mdt_sync(struct mdt_thread_info *info)
1539 struct req_capsule *pill = &info->mti_pill;
1540 struct mdt_body *body;
1544 /* The fid may be zero, so we req_capsule_set manually */
1545 req_capsule_set(pill, &RQF_MDS_SYNC);
1547 body = req_capsule_client_get(pill, &RMF_MDT_BODY);
1549 RETURN(err_serious(-EINVAL));
1551 if (MDT_FAIL_CHECK(OBD_FAIL_MDS_SYNC_PACK))
1552 RETURN(err_serious(-ENOMEM));
1554 if (fid_seq(&body->fid1) == 0) {
1555 /* sync the whole device */
1556 rc = req_capsule_pack(pill);
1558 rc = mdt_device_sync(info);
1560 rc = err_serious(rc);
1562 /* sync an object */
1563 rc = mdt_unpack_req_pack_rep(info, HABEO_CORPUS|HABEO_REFERO);
1565 rc = mdt_object_sync(info);
1567 struct md_object *next;
1568 const struct lu_fid *fid;
1569 struct lu_attr *la = &info->mti_attr.ma_attr;
1571 next = mdt_object_child(info->mti_object);
1572 info->mti_attr.ma_need = MA_INODE;
1573 info->mti_attr.ma_valid = 0;
1574 rc = mo_attr_get(info->mti_env, next,
1577 body = req_capsule_server_get(pill,
1579 fid = mdt_object_fid(info->mti_object);
1580 mdt_pack_attr2body(info, body, la, fid);
1584 rc = err_serious(rc);
1589 static int mdt_quotacheck_handle(struct mdt_thread_info *info)
1591 return err_serious(-EOPNOTSUPP);
1594 static int mdt_quotactl_handle(struct mdt_thread_info *info)
1596 return err_serious(-EOPNOTSUPP);
1600 * OBD PING and other handlers.
1602 static int mdt_obd_ping(struct mdt_thread_info *info)
1606 rc = target_handle_ping(mdt_info_req(info));
1608 rc = err_serious(rc);
1612 static int mdt_obd_log_cancel(struct mdt_thread_info *info)
1614 return err_serious(-EOPNOTSUPP);
1617 static int mdt_obd_qc_callback(struct mdt_thread_info *info)
1619 return err_serious(-EOPNOTSUPP);
1626 static struct ldlm_callback_suite cbs = {
1627 .lcs_completion = ldlm_server_completion_ast,
1628 .lcs_blocking = ldlm_server_blocking_ast,
1632 static int mdt_enqueue(struct mdt_thread_info *info)
1634 struct ptlrpc_request *req;
1639 * info->mti_dlm_req already contains swapped and (if necessary)
1640 * converted dlm request.
1642 LASSERT(info->mti_dlm_req != NULL);
1644 if (OBD_FAIL_CHECK(OBD_FAIL_LDLM_ENQUEUE)) {
1645 info->mti_fail_id = OBD_FAIL_LDLM_ENQUEUE;
1649 req = mdt_info_req(info);
1652 * Lock without inodebits makes no sense and will oops later in
1653 * ldlm. Let's check it now to see if we have wrong lock from client or
1654 * bits get corrupted somewhere in mdt_intent_policy().
1656 req_bits = info->mti_dlm_req->lock_desc.l_policy_data.l_inodebits.bits;
1657 LASSERT(req_bits != 0);
1659 rc = ldlm_handle_enqueue0(info->mti_mdt->mdt_namespace,
1660 req, info->mti_dlm_req, &cbs);
1661 info->mti_fail_id = OBD_FAIL_LDLM_REPLY;
1662 return rc ? err_serious(rc) : req->rq_status;
1665 static int mdt_convert(struct mdt_thread_info *info)
1668 struct ptlrpc_request *req;
1670 LASSERT(info->mti_dlm_req);
1671 req = mdt_info_req(info);
1672 rc = ldlm_handle_convert0(req, info->mti_dlm_req);
1673 return rc ? err_serious(rc) : req->rq_status;
1676 static int mdt_bl_callback(struct mdt_thread_info *info)
1678 CERROR("bl callbacks should not happen on MDS\n");
1680 return err_serious(-EOPNOTSUPP);
1683 static int mdt_cp_callback(struct mdt_thread_info *info)
1685 CERROR("cp callbacks should not happen on MDS\n");
1687 return err_serious(-EOPNOTSUPP);
1691 * sec context handlers
1693 static int mdt_sec_ctx_handle(struct mdt_thread_info *info)
1697 rc = mdt_handle_idmap(info);
1700 struct ptlrpc_request *req = mdt_info_req(info);
1703 opc = lustre_msg_get_opc(req->rq_reqmsg);
1704 if (opc == SEC_CTX_INIT || opc == SEC_CTX_INIT_CONT)
1705 sptlrpc_svc_ctx_invalidate(req);
1711 static struct mdt_object *mdt_obj(struct lu_object *o)
1713 LASSERT(lu_device_is_mdt(o->lo_dev));
1714 return container_of0(o, struct mdt_object, mot_obj.mo_lu);
1717 struct mdt_object *mdt_object_find(const struct lu_env *env,
1718 struct mdt_device *d,
1719 const struct lu_fid *f)
1721 struct lu_object *o;
1722 struct mdt_object *m;
1725 o = lu_object_find(env, d->mdt_md_dev.md_lu_dev.ld_site, f);
1726 if (unlikely(IS_ERR(o)))
1727 m = (struct mdt_object *)o;
1733 int mdt_object_lock(struct mdt_thread_info *info, struct mdt_object *o,
1734 struct mdt_lock_handle *lh, __u64 ibits, int locality)
1736 struct ldlm_namespace *ns = info->mti_mdt->mdt_namespace;
1737 ldlm_policy_data_t *policy = &info->mti_policy;
1738 struct ldlm_res_id *res_id = &info->mti_res_id;
1742 LASSERT(!lustre_handle_is_used(&lh->mlh_reg_lh));
1743 LASSERT(!lustre_handle_is_used(&lh->mlh_pdo_lh));
1744 LASSERT(lh->mlh_reg_mode != LCK_MINMODE);
1745 LASSERT(lh->mlh_type != MDT_NUL_LOCK);
1747 if (mdt_object_exists(o) < 0) {
1748 if (locality == MDT_CROSS_LOCK) {
1749 /* cross-ref object fix */
1750 ibits &= ~MDS_INODELOCK_UPDATE;
1751 ibits |= MDS_INODELOCK_LOOKUP;
1753 LASSERT(!(ibits & MDS_INODELOCK_UPDATE));
1754 LASSERT(ibits & MDS_INODELOCK_LOOKUP);
1756 /* No PDO lock on remote object */
1757 LASSERT(lh->mlh_type != MDT_PDO_LOCK);
1760 memset(policy, 0, sizeof(*policy));
1761 fid_build_reg_res_name(mdt_object_fid(o), res_id);
1764 * Take PDO lock on whole directory and build correct @res_id for lock
1765 * on part of directory.
1767 if (lh->mlh_pdo_hash != 0) {
1768 LASSERT(lh->mlh_type == MDT_PDO_LOCK);
1769 mdt_lock_pdo_mode(info, o, lh);
1770 if (lh->mlh_pdo_mode != LCK_NL) {
1772 * Do not use LDLM_FL_LOCAL_ONLY for parallel lock, it
1773 * is never going to be sent to client and we do not
1774 * want it slowed down due to possible cancels.
1776 policy->l_inodebits.bits = MDS_INODELOCK_UPDATE;
1777 rc = mdt_fid_lock(ns, &lh->mlh_pdo_lh, lh->mlh_pdo_mode,
1778 policy, res_id, LDLM_FL_ATOMIC_CB);
1784 * Finish res_id initializing by name hash marking patr of
1785 * directory which is taking modification.
1787 res_id->name[LUSTRE_RES_ID_HSH_OFF] = lh->mlh_pdo_hash;
1790 policy->l_inodebits.bits = ibits;
1793 * Use LDLM_FL_LOCAL_ONLY for this lock. We do not know yet if it is
1794 * going to be sent to client. If it is - mdt_intent_policy() path will
1795 * fix it up and turns FL_LOCAL flag off.
1797 rc = mdt_fid_lock(ns, &lh->mlh_reg_lh, lh->mlh_reg_mode, policy,
1798 res_id, LDLM_FL_LOCAL_ONLY | LDLM_FL_ATOMIC_CB);
1803 if (lh->mlh_type == MDT_PDO_LOCK) {
1804 /* check for exists after object is locked */
1805 if (mdt_object_exists(o) == 0) {
1806 /* Non-existent object shouldn't have PDO lock */
1809 /* Non-dir object shouldn't have PDO lock */
1810 LASSERT(S_ISDIR(lu_object_attr(&o->mot_obj.mo_lu)));
1815 mdt_object_unlock(info, o, lh, 1);
1822 * Just call ldlm_lock_decref() if decref, else we only call ptlrpc_save_lock()
1823 * to save this lock in req. when transaction committed, req will be released,
1824 * and lock will, too.
1826 void mdt_object_unlock(struct mdt_thread_info *info, struct mdt_object *o,
1827 struct mdt_lock_handle *lh, int decref)
1829 struct ptlrpc_request *req = mdt_info_req(info);
1832 if (lustre_handle_is_used(&lh->mlh_pdo_lh)) {
1833 /* Do not save PDO locks to request, just decref. */
1834 mdt_fid_unlock(&lh->mlh_pdo_lh,
1836 lh->mlh_pdo_lh.cookie = 0ull;
1839 if (lustre_handle_is_used(&lh->mlh_reg_lh)) {
1841 mdt_fid_unlock(&lh->mlh_reg_lh,
1844 ptlrpc_save_lock(req, &lh->mlh_reg_lh,
1847 lh->mlh_reg_lh.cookie = 0ull;
1853 struct mdt_object *mdt_object_find_lock(struct mdt_thread_info *info,
1854 const struct lu_fid *f,
1855 struct mdt_lock_handle *lh,
1858 struct mdt_object *o;
1860 o = mdt_object_find(info->mti_env, info->mti_mdt, f);
1864 rc = mdt_object_lock(info, o, lh, ibits,
1867 mdt_object_put(info->mti_env, o);
1874 void mdt_object_unlock_put(struct mdt_thread_info * info,
1875 struct mdt_object * o,
1876 struct mdt_lock_handle *lh,
1879 mdt_object_unlock(info, o, lh, decref);
1880 mdt_object_put(info->mti_env, o);
1883 static struct mdt_handler *mdt_handler_find(__u32 opc,
1884 struct mdt_opc_slice *supported)
1886 struct mdt_opc_slice *s;
1887 struct mdt_handler *h;
1890 for (s = supported; s->mos_hs != NULL; s++) {
1891 if (s->mos_opc_start <= opc && opc < s->mos_opc_end) {
1892 h = s->mos_hs + (opc - s->mos_opc_start);
1893 if (likely(h->mh_opc != 0))
1894 LASSERT(h->mh_opc == opc);
1896 h = NULL; /* unsupported opc */
1903 static int mdt_lock_resname_compat(struct mdt_device *m,
1904 struct ldlm_request *req)
1906 /* XXX something... later. */
1910 static int mdt_lock_reply_compat(struct mdt_device *m, struct ldlm_reply *rep)
1912 /* XXX something... later. */
1917 * Generic code handling requests that have struct mdt_body passed in:
1919 * - extract mdt_body from request and save it in @info, if present;
1921 * - create lu_object, corresponding to the fid in mdt_body, and save it in
1924 * - if HABEO_CORPUS flag is set for this request type check whether object
1925 * actually exists on storage (lu_object_exists()).
1928 static int mdt_body_unpack(struct mdt_thread_info *info, __u32 flags)
1930 const struct mdt_body *body;
1931 struct mdt_object *obj;
1932 const struct lu_env *env;
1933 struct req_capsule *pill;
1936 env = info->mti_env;
1937 pill = &info->mti_pill;
1939 body = info->mti_body = req_capsule_client_get(pill, &RMF_MDT_BODY);
1943 if (!fid_is_sane(&body->fid1)) {
1944 CERROR("Invalid fid: "DFID"\n", PFID(&body->fid1));
1949 * Do not get size or any capa fields before we check that request
1950 * contains capa actually. There are some requests which do not, for
1951 * instance MDS_IS_SUBDIR.
1953 if (req_capsule_has_field(pill, &RMF_CAPA1, RCL_CLIENT) &&
1954 req_capsule_get_size(pill, &RMF_CAPA1, RCL_CLIENT))
1955 mdt_set_capainfo(info, 0, &body->fid1,
1956 req_capsule_client_get(pill, &RMF_CAPA1));
1958 obj = mdt_object_find(env, info->mti_mdt, &body->fid1);
1960 if ((flags & HABEO_CORPUS) &&
1961 !mdt_object_exists(obj)) {
1962 mdt_object_put(env, obj);
1963 /* for capability renew ENOENT will be handled in
1965 if (body->valid & OBD_MD_FLOSSCAPA)
1970 info->mti_object = obj;
1979 static int mdt_unpack_req_pack_rep(struct mdt_thread_info *info, __u32 flags)
1981 struct req_capsule *pill;
1985 pill = &info->mti_pill;
1987 if (req_capsule_has_field(pill, &RMF_MDT_BODY, RCL_CLIENT))
1988 rc = mdt_body_unpack(info, flags);
1992 if (rc == 0 && (flags & HABEO_REFERO)) {
1993 struct mdt_device *mdt = info->mti_mdt;
1996 if (req_capsule_has_field(pill, &RMF_MDT_MD, RCL_SERVER))
1997 req_capsule_set_size(pill, &RMF_MDT_MD, RCL_SERVER,
1998 mdt->mdt_max_mdsize);
1999 if (req_capsule_has_field(pill, &RMF_LOGCOOKIES, RCL_SERVER))
2000 req_capsule_set_size(pill, &RMF_LOGCOOKIES, RCL_SERVER,
2001 mdt->mdt_max_cookiesize);
2003 rc = req_capsule_pack(pill);
2008 static int mdt_init_capa_ctxt(const struct lu_env *env, struct mdt_device *m)
2010 struct md_device *next = m->mdt_child;
2012 return next->md_ops->mdo_init_capa_ctxt(env, next,
2013 m->mdt_opts.mo_mds_capa,
2014 m->mdt_capa_timeout,
2020 * Invoke handler for this request opc. Also do necessary preprocessing
2021 * (according to handler ->mh_flags), and post-processing (setting of
2022 * ->last_{xid,committed}).
2024 static int mdt_req_handle(struct mdt_thread_info *info,
2025 struct mdt_handler *h, struct ptlrpc_request *req)
2027 int rc, serious = 0;
2032 LASSERT(h->mh_act != NULL);
2033 LASSERT(h->mh_opc == lustre_msg_get_opc(req->rq_reqmsg));
2034 LASSERT(current->journal_info == NULL);
2037 * Do not use *_FAIL_CHECK_ONCE() macros, because they will stop
2038 * correct handling of failed req later in ldlm due to doing
2039 * obd_fail_loc |= OBD_FAIL_ONCE | OBD_FAILED without actually
2040 * correct actions like it is done in target_send_reply_msg().
2042 if (h->mh_fail_id != 0) {
2044 * Set to info->mti_fail_id to handler fail_id, it will be used
2045 * later, and better than use default fail_id.
2047 if (OBD_FAIL_CHECK(h->mh_fail_id)) {
2048 info->mti_fail_id = h->mh_fail_id;
2054 flags = h->mh_flags;
2055 LASSERT(ergo(flags & (HABEO_CORPUS|HABEO_REFERO), h->mh_fmt != NULL));
2057 if (h->mh_fmt != NULL) {
2058 req_capsule_set(&info->mti_pill, h->mh_fmt);
2059 rc = mdt_unpack_req_pack_rep(info, flags);
2062 if (rc == 0 && flags & MUTABOR &&
2063 req->rq_export->exp_connect_flags & OBD_CONNECT_RDONLY)
2064 /* should it be rq_status? */
2067 if (rc == 0 && flags & HABEO_CLAVIS) {
2068 struct ldlm_request *dlm_req;
2070 LASSERT(h->mh_fmt != NULL);
2072 dlm_req = req_capsule_client_get(&info->mti_pill, &RMF_DLM_REQ);
2073 if (dlm_req != NULL) {
2074 if (info->mti_mdt->mdt_opts.mo_compat_resname)
2075 rc = mdt_lock_resname_compat(info->mti_mdt,
2077 info->mti_dlm_req = dlm_req;
2079 CERROR("Can't unpack dlm request\n");
2084 /* capability setting changed via /proc, needs reinitialize ctxt */
2085 if (info->mti_mdt && info->mti_mdt->mdt_capa_conf) {
2086 mdt_init_capa_ctxt(info->mti_env, info->mti_mdt);
2087 info->mti_mdt->mdt_capa_conf = 0;
2090 if (likely(rc == 0)) {
2092 * Process request, there can be two types of rc:
2093 * 1) errors with msg unpack/pack, other failures outside the
2094 * operation itself. This is counted as serious errors;
2095 * 2) errors during fs operation, should be placed in rq_status
2098 rc = h->mh_act(info);
2099 serious = is_serious(rc);
2100 rc = clear_serious(rc);
2104 req->rq_status = rc;
2107 * ELDLM_* codes which > 0 should be in rq_status only as well as
2108 * all non-serious errors.
2110 if (rc > 0 || !serious)
2113 LASSERT(current->journal_info == NULL);
2115 if (rc == 0 && (flags & HABEO_CLAVIS) &&
2116 info->mti_mdt->mdt_opts.mo_compat_resname) {
2117 struct ldlm_reply *dlmrep;
2119 dlmrep = req_capsule_server_get(&info->mti_pill, &RMF_DLM_REP);
2121 rc = mdt_lock_reply_compat(info->mti_mdt, dlmrep);
2124 /* If we're DISCONNECTing, the mdt_export_data is already freed */
2125 if (likely(rc == 0 && h->mh_opc != MDS_DISCONNECT))
2126 target_committed_to_req(req);
2128 if (unlikely((lustre_msg_get_flags(req->rq_reqmsg) & MSG_REPLAY) &&
2129 lustre_msg_get_transno(req->rq_reqmsg) == 0)) {
2130 DEBUG_REQ(D_ERROR, req, "transno is 0 during REPLAY");
2137 void mdt_lock_handle_init(struct mdt_lock_handle *lh)
2139 lh->mlh_type = MDT_NUL_LOCK;
2140 lh->mlh_reg_lh.cookie = 0ull;
2141 lh->mlh_reg_mode = LCK_MINMODE;
2142 lh->mlh_pdo_lh.cookie = 0ull;
2143 lh->mlh_pdo_mode = LCK_MINMODE;
2146 void mdt_lock_handle_fini(struct mdt_lock_handle *lh)
2148 LASSERT(!lustre_handle_is_used(&lh->mlh_reg_lh));
2149 LASSERT(!lustre_handle_is_used(&lh->mlh_pdo_lh));
2153 * Initialize fields of struct mdt_thread_info. Other fields are left in
2154 * uninitialized state, because it's too expensive to zero out whole
2155 * mdt_thread_info (> 1K) on each request arrival.
2157 static void mdt_thread_info_init(struct ptlrpc_request *req,
2158 struct mdt_thread_info *info)
2161 struct md_capainfo *ci;
2163 info->mti_rep_buf_nr = ARRAY_SIZE(info->mti_rep_buf_size);
2164 for (i = 0; i < ARRAY_SIZE(info->mti_rep_buf_size); i++)
2165 info->mti_rep_buf_size[i] = -1;
2166 req_capsule_init(&info->mti_pill, req, RCL_SERVER,
2167 info->mti_rep_buf_size);
2170 for (i = 0; i < ARRAY_SIZE(info->mti_lh); i++)
2171 mdt_lock_handle_init(&info->mti_lh[i]);
2173 /* mdt device: it can be NULL while CONNECT */
2174 if (req->rq_export) {
2175 info->mti_mdt = mdt_dev(req->rq_export->exp_obd->obd_lu_dev);
2176 info->mti_exp = req->rq_export;
2178 info->mti_mdt = NULL;
2179 info->mti_env = req->rq_svc_thread->t_env;
2180 ci = md_capainfo(info->mti_env);
2181 memset(ci, 0, sizeof *ci);
2183 info->mti_fail_id = OBD_FAIL_MDS_ALL_REPLY_NET;
2184 info->mti_transno = lustre_msg_get_transno(req->rq_reqmsg);
2186 memset(&info->mti_attr, 0, sizeof(info->mti_attr));
2187 info->mti_body = NULL;
2188 info->mti_object = NULL;
2189 info->mti_dlm_req = NULL;
2190 info->mti_has_trans = 0;
2191 info->mti_no_need_trans = 0;
2192 info->mti_cross_ref = 0;
2193 info->mti_opdata = 0;
2195 /* To not check for split by default. */
2196 info->mti_spec.sp_ck_split = 0;
2199 static void mdt_thread_info_fini(struct mdt_thread_info *info)
2203 req_capsule_fini(&info->mti_pill);
2204 if (info->mti_object != NULL) {
2205 mdt_object_put(info->mti_env, info->mti_object);
2206 info->mti_object = NULL;
2208 for (i = 0; i < ARRAY_SIZE(info->mti_lh); i++)
2209 mdt_lock_handle_fini(&info->mti_lh[i]);
2210 info->mti_env = NULL;
2214 extern int mds_filter_recovery_request(struct ptlrpc_request *req,
2215 struct obd_device *obd, int *process);
2217 * Handle recovery. Return:
2218 * +1: continue request processing;
2219 * -ve: abort immediately with the given error code;
2220 * 0: send reply with error code in req->rq_status;
2222 static int mdt_recovery(struct mdt_thread_info *info)
2224 struct ptlrpc_request *req = mdt_info_req(info);
2226 struct obd_device *obd;
2230 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
2233 case SEC_CTX_INIT_CONT:
2239 rc = mdt_handle_idmap(info);
2248 if (unlikely(req->rq_export == NULL)) {
2249 CERROR("operation %d on unconnected MDS from %s\n",
2250 lustre_msg_get_opc(req->rq_reqmsg),
2251 libcfs_id2str(req->rq_peer));
2252 /* FIXME: For CMD cleanup, when mds_B stop, the req from
2253 * mds_A will get -ENOTCONN(especially for ping req),
2254 * which will cause that mds_A deactive timeout, then when
2255 * mds_A cleanup, the cleanup process will be suspended since
2256 * deactive timeout is not zero.
2258 req->rq_status = -ENOTCONN;
2259 target_send_reply(req, -ENOTCONN, info->mti_fail_id);
2263 /* sanity check: if the xid matches, the request must be marked as a
2264 * resent or replayed */
2265 if (req_xid_is_last(req)) {
2266 if (!(lustre_msg_get_flags(req->rq_reqmsg) &
2267 (MSG_RESENT | MSG_REPLAY))) {
2268 DEBUG_REQ(D_WARNING, req, "rq_xid "LPU64" matches last_xid, "
2269 "expected REPLAY or RESENT flag (%x)", req->rq_xid,
2270 lustre_msg_get_flags(req->rq_reqmsg));
2272 req->rq_status = -ENOTCONN;
2277 /* else: note the opposite is not always true; a RESENT req after a
2278 * failover will usually not match the last_xid, since it was likely
2279 * never committed. A REPLAYed request will almost never match the
2280 * last xid, however it could for a committed, but still retained,
2283 obd = req->rq_export->exp_obd;
2285 /* Check for aborted recovery... */
2286 spin_lock_bh(&obd->obd_processing_task_lock);
2287 recovering = obd->obd_recovering;
2288 spin_unlock_bh(&obd->obd_processing_task_lock);
2289 if (unlikely(recovering)) {
2292 DEBUG_REQ(D_INFO, req, "Got new replay");
2293 rc = mds_filter_recovery_request(req, obd, &should_process);
2294 if (rc != 0 || !should_process)
2296 else if (should_process < 0) {
2297 req->rq_status = should_process;
2298 rc = ptlrpc_error(req);
2305 static int mdt_reply(struct ptlrpc_request *req, int rc,
2306 struct mdt_thread_info *info)
2311 if (req->rq_reply_state == NULL && rc == 0) {
2312 req->rq_status = rc;
2313 lustre_pack_reply(req, 1, NULL, NULL);
2316 target_send_reply(req, rc, info->mti_fail_id);
2321 extern int mds_msg_check_version(struct lustre_msg *msg);
2323 static int mdt_handle0(struct ptlrpc_request *req,
2324 struct mdt_thread_info *info,
2325 struct mdt_opc_slice *supported)
2327 struct mdt_handler *h;
2328 struct lustre_msg *msg;
2333 MDT_FAIL_RETURN(OBD_FAIL_MDS_ALL_REQUEST_NET | OBD_FAIL_ONCE, 0);
2335 LASSERT(current->journal_info == NULL);
2337 msg = req->rq_reqmsg;
2338 rc = mds_msg_check_version(msg);
2339 if (likely(rc == 0)) {
2340 rc = mdt_recovery(info);
2341 if (likely(rc == +1)) {
2342 h = mdt_handler_find(lustre_msg_get_opc(msg),
2344 if (likely(h != NULL)) {
2345 rc = mdt_req_handle(info, h, req);
2346 rc = mdt_reply(req, rc, info);
2348 CERROR("The unsupported opc: 0x%x\n", lustre_msg_get_opc(msg) );
2349 req->rq_status = -ENOTSUPP;
2350 rc = ptlrpc_error(req);
2355 CERROR(LUSTRE_MDT_NAME" drops mal-formed request\n");
2360 * MDT handler function called by ptlrpc service thread when request comes.
2362 * XXX common "target" functionality should be factored into separate module
2363 * shared by mdt, ost and stand-alone services like fld.
2365 static int mdt_handle_common(struct ptlrpc_request *req,
2366 struct mdt_opc_slice *supported)
2369 struct mdt_thread_info *info;
2373 env = req->rq_svc_thread->t_env;
2374 LASSERT(env != NULL);
2375 LASSERT(env->le_ses != NULL);
2376 LASSERT(env->le_ctx.lc_thread == req->rq_svc_thread);
2377 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
2378 LASSERT(info != NULL);
2380 mdt_thread_info_init(req, info);
2382 rc = mdt_handle0(req, info, supported);
2384 mdt_thread_info_fini(info);
2389 * This is called from recovery code as handler of _all_ RPC types, FLD and SEQ
2392 int mdt_recovery_handle(struct ptlrpc_request *req)
2397 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
2399 rc = mdt_handle_common(req, mdt_fld_handlers);
2402 rc = mdt_handle_common(req, mdt_seq_handlers);
2405 rc = mdt_handle_common(req, mdt_regular_handlers);
2412 static int mdt_regular_handle(struct ptlrpc_request *req)
2414 return mdt_handle_common(req, mdt_regular_handlers);
2417 static int mdt_readpage_handle(struct ptlrpc_request *req)
2419 return mdt_handle_common(req, mdt_readpage_handlers);
2422 static int mdt_xmds_handle(struct ptlrpc_request *req)
2424 return mdt_handle_common(req, mdt_xmds_handlers);
2427 static int mdt_mdsc_handle(struct ptlrpc_request *req)
2429 return mdt_handle_common(req, mdt_seq_handlers);
2432 static int mdt_mdss_handle(struct ptlrpc_request *req)
2434 return mdt_handle_common(req, mdt_seq_handlers);
2437 static int mdt_dtss_handle(struct ptlrpc_request *req)
2439 return mdt_handle_common(req, mdt_seq_handlers);
2442 static int mdt_fld_handle(struct ptlrpc_request *req)
2444 return mdt_handle_common(req, mdt_fld_handlers);
2460 static int mdt_intent_getattr(enum mdt_it_code opcode,
2461 struct mdt_thread_info *info,
2462 struct ldlm_lock **,
2464 static int mdt_intent_reint(enum mdt_it_code opcode,
2465 struct mdt_thread_info *info,
2466 struct ldlm_lock **,
2469 static struct mdt_it_flavor {
2470 const struct req_format *it_fmt;
2472 int (*it_act)(enum mdt_it_code ,
2473 struct mdt_thread_info *,
2474 struct ldlm_lock **,
2477 } mdt_it_flavor[] = {
2479 .it_fmt = &RQF_LDLM_INTENT,
2480 /*.it_flags = HABEO_REFERO,*/
2482 .it_act = mdt_intent_reint,
2483 .it_reint = REINT_OPEN
2486 .it_fmt = &RQF_LDLM_INTENT,
2487 .it_flags = MUTABOR,
2488 .it_act = mdt_intent_reint,
2489 .it_reint = REINT_OPEN
2492 .it_fmt = &RQF_LDLM_INTENT,
2493 .it_flags = MUTABOR,
2494 .it_act = mdt_intent_reint,
2495 .it_reint = REINT_CREATE
2497 [MDT_IT_GETATTR] = {
2498 .it_fmt = &RQF_LDLM_INTENT_GETATTR,
2499 .it_flags = HABEO_REFERO,
2500 .it_act = mdt_intent_getattr
2502 [MDT_IT_READDIR] = {
2508 .it_fmt = &RQF_LDLM_INTENT_GETATTR,
2509 .it_flags = HABEO_REFERO,
2510 .it_act = mdt_intent_getattr
2513 .it_fmt = &RQF_LDLM_INTENT_UNLINK,
2514 .it_flags = MUTABOR,
2516 .it_reint = REINT_UNLINK
2520 .it_flags = MUTABOR,
2523 [MDT_IT_GETXATTR] = {
2530 int mdt_intent_lock_replace(struct mdt_thread_info *info,
2531 struct ldlm_lock **lockp,
2532 struct ldlm_lock *new_lock,
2533 struct mdt_lock_handle *lh,
2536 struct ptlrpc_request *req = mdt_info_req(info);
2537 struct ldlm_lock *lock = *lockp;
2540 * Get new lock only for cases when possible resent did not find any
2543 if (new_lock == NULL)
2544 new_lock = ldlm_handle2lock(&lh->mlh_reg_lh);
2546 if (new_lock == NULL && (flags & LDLM_FL_INTENT_ONLY)) {
2547 lh->mlh_reg_lh.cookie = 0;
2551 LASSERTF(new_lock != NULL,
2552 "lockh "LPX64"\n", lh->mlh_reg_lh.cookie);
2555 * If we've already given this lock to a client once, then we should
2556 * have no readers or writers. Otherwise, we should have one reader
2557 * _or_ writer ref (which will be zeroed below) before returning the
2560 if (new_lock->l_export == req->rq_export) {
2561 LASSERT(new_lock->l_readers + new_lock->l_writers == 0);
2563 LASSERT(new_lock->l_export == NULL);
2564 LASSERT(new_lock->l_readers + new_lock->l_writers == 1);
2569 if (new_lock->l_export == req->rq_export) {
2571 * Already gave this to the client, which means that we
2572 * reconstructed a reply.
2574 LASSERT(lustre_msg_get_flags(req->rq_reqmsg) &
2576 lh->mlh_reg_lh.cookie = 0;
2577 RETURN(ELDLM_LOCK_REPLACED);
2580 /* This lock might already be given to the client by an resent req,
2581 * in this case we should return ELDLM_LOCK_ABORTED,
2582 * so we should check led_held_locks here, but it will affect
2583 * performance, FIXME
2585 /* Fixup the lock to be given to the client */
2586 lock_res_and_lock(new_lock);
2587 new_lock->l_readers = 0;
2588 new_lock->l_writers = 0;
2590 new_lock->l_export = class_export_get(req->rq_export);
2591 spin_lock(&req->rq_export->exp_ldlm_data.led_lock);
2592 list_add(&new_lock->l_export_chain,
2593 &new_lock->l_export->exp_ldlm_data.led_held_locks);
2594 spin_unlock(&req->rq_export->exp_ldlm_data.led_lock);
2596 new_lock->l_blocking_ast = lock->l_blocking_ast;
2597 new_lock->l_completion_ast = lock->l_completion_ast;
2598 new_lock->l_remote_handle = lock->l_remote_handle;
2599 new_lock->l_flags &= ~LDLM_FL_LOCAL;
2601 unlock_res_and_lock(new_lock);
2602 LDLM_LOCK_PUT(new_lock);
2603 lh->mlh_reg_lh.cookie = 0;
2605 RETURN(ELDLM_LOCK_REPLACED);
2608 static void mdt_intent_fixup_resent(struct mdt_thread_info *info,
2609 struct ldlm_lock *new_lock,
2610 struct ldlm_lock **old_lock,
2611 struct mdt_lock_handle *lh)
2613 struct ptlrpc_request *req = mdt_info_req(info);
2614 struct obd_export *exp = req->rq_export;
2615 struct lustre_handle remote_hdl;
2616 struct ldlm_request *dlmreq;
2617 struct list_head *iter;
2619 if (!(lustre_msg_get_flags(req->rq_reqmsg) & MSG_RESENT))
2622 dlmreq = req_capsule_client_get(&info->mti_pill, &RMF_DLM_REQ);
2623 remote_hdl = dlmreq->lock_handle[0];
2625 spin_lock(&exp->exp_ldlm_data.led_lock);
2626 list_for_each(iter, &exp->exp_ldlm_data.led_held_locks) {
2627 struct ldlm_lock *lock;
2628 lock = list_entry(iter, struct ldlm_lock, l_export_chain);
2629 if (lock == new_lock)
2631 if (lock->l_remote_handle.cookie == remote_hdl.cookie) {
2632 lh->mlh_reg_lh.cookie = lock->l_handle.h_cookie;
2633 lh->mlh_reg_mode = lock->l_granted_mode;
2635 LDLM_DEBUG(lock, "restoring lock cookie");
2636 DEBUG_REQ(D_HA, req, "restoring lock cookie "LPX64,
2637 lh->mlh_reg_lh.cookie);
2639 *old_lock = LDLM_LOCK_GET(lock);
2640 spin_unlock(&exp->exp_ldlm_data.led_lock);
2644 spin_unlock(&exp->exp_ldlm_data.led_lock);
2647 * If the xid matches, then we know this is a resent request, and allow
2648 * it. (It's probably an OPEN, for which we don't send a lock.
2650 if (req_xid_is_last(req))
2654 * This remote handle isn't enqueued, so we never received or processed
2655 * this request. Clear MSG_RESENT, because it can be handled like any
2656 * normal request now.
2658 lustre_msg_clear_flags(req->rq_reqmsg, MSG_RESENT);
2660 DEBUG_REQ(D_HA, req, "no existing lock with rhandle "LPX64,
2664 static int mdt_intent_getattr(enum mdt_it_code opcode,
2665 struct mdt_thread_info *info,
2666 struct ldlm_lock **lockp,
2669 struct mdt_lock_handle *lhc = &info->mti_lh[MDT_LH_RMT];
2670 struct ldlm_lock *new_lock = NULL;
2672 struct ldlm_reply *ldlm_rep;
2673 struct ptlrpc_request *req;
2674 struct mdt_body *reqbody;
2675 struct mdt_body *repbody;
2679 reqbody = req_capsule_client_get(&info->mti_pill, &RMF_MDT_BODY);
2682 repbody = req_capsule_server_get(&info->mti_pill, &RMF_MDT_BODY);
2685 info->mti_spec.sp_ck_split = !!(reqbody->valid & OBD_MD_FLCKSPLIT);
2686 info->mti_cross_ref = !!(reqbody->valid & OBD_MD_FLCROSSREF);
2687 repbody->eadatasize = 0;
2688 repbody->aclsize = 0;
2692 child_bits = MDS_INODELOCK_LOOKUP;
2694 case MDT_IT_GETATTR:
2695 child_bits = MDS_INODELOCK_LOOKUP | MDS_INODELOCK_UPDATE;
2698 CERROR("Unhandled till now");
2699 GOTO(out, rc = -EINVAL);
2702 rc = mdt_init_ucred(info, reqbody);
2706 req = info->mti_pill.rc_req;
2707 ldlm_rep = req_capsule_server_get(&info->mti_pill, &RMF_DLM_REP);
2708 mdt_set_disposition(info, ldlm_rep, DISP_IT_EXECD);
2710 /* Get lock from request for possible resent case. */
2711 mdt_intent_fixup_resent(info, *lockp, &new_lock, lhc);
2713 ldlm_rep->lock_policy_res2 =
2714 mdt_getattr_name_lock(info, lhc, child_bits, ldlm_rep);
2716 if (mdt_get_disposition(ldlm_rep, DISP_LOOKUP_NEG))
2717 ldlm_rep->lock_policy_res2 = 0;
2718 if (!mdt_get_disposition(ldlm_rep, DISP_LOOKUP_POS) ||
2719 ldlm_rep->lock_policy_res2) {
2720 lhc->mlh_reg_lh.cookie = 0ull;
2721 GOTO(out_ucred, rc = ELDLM_LOCK_ABORTED);
2724 rc = mdt_intent_lock_replace(info, lockp, new_lock, lhc, flags);
2727 mdt_exit_ucred(info);
2729 mdt_shrink_reply(info);
2733 static int mdt_intent_reint(enum mdt_it_code opcode,
2734 struct mdt_thread_info *info,
2735 struct ldlm_lock **lockp,
2738 struct mdt_lock_handle *lhc = &info->mti_lh[MDT_LH_RMT];
2739 struct ldlm_reply *rep = NULL;
2743 static const struct req_format *intent_fmts[REINT_MAX] = {
2744 [REINT_CREATE] = &RQF_LDLM_INTENT_CREATE,
2745 [REINT_OPEN] = &RQF_LDLM_INTENT_OPEN
2750 opc = mdt_reint_opcode(info, intent_fmts);
2752 GOTO(out, rc = opc);
2754 if (mdt_it_flavor[opcode].it_reint != opc) {
2755 CERROR("Reint code %ld doesn't match intent: %d\n",
2757 GOTO(out, rc = err_serious(-EPROTO));
2760 /* Get lock from request for possible resent case. */
2761 mdt_intent_fixup_resent(info, *lockp, NULL, lhc);
2763 rc = mdt_reint_internal(info, lhc, opc);
2765 /* Check whether the reply has been packed successfully. */
2766 if (mdt_info_req(info)->rq_repmsg != NULL)
2767 rep = req_capsule_server_get(&info->mti_pill, &RMF_DLM_REP);
2769 GOTO(out, rc = err_serious(-EFAULT));
2771 /* MDC expects this in any case */
2773 mdt_set_disposition(info, rep, DISP_LOOKUP_EXECD);
2775 /* Cross-ref case, the lock should be returned to the client */
2776 if (rc == -EREMOTE) {
2777 LASSERT(lustre_handle_is_used(&lhc->mlh_reg_lh));
2778 rep->lock_policy_res2 = 0;
2779 rc = mdt_intent_lock_replace(info, lockp, NULL, lhc, flags);
2782 rep->lock_policy_res2 = clear_serious(rc);
2784 lhc->mlh_reg_lh.cookie = 0ull;
2785 rc = ELDLM_LOCK_ABORTED;
2791 static int mdt_intent_code(long itcode)
2799 case IT_OPEN|IT_CREAT:
2806 rc = MDT_IT_READDIR;
2809 rc = MDT_IT_GETATTR;
2821 rc = MDT_IT_GETXATTR;
2824 CERROR("Unknown intent opcode: %ld\n", itcode);
2831 static int mdt_intent_opc(long itopc, struct mdt_thread_info *info,
2832 struct ldlm_lock **lockp, int flags)
2834 struct req_capsule *pill;
2835 struct mdt_it_flavor *flv;
2840 opc = mdt_intent_code(itopc);
2844 pill = &info->mti_pill;
2845 flv = &mdt_it_flavor[opc];
2847 if (flv->it_fmt != NULL)
2848 req_capsule_extend(pill, flv->it_fmt);
2850 rc = mdt_unpack_req_pack_rep(info, flv->it_flags);
2852 struct ptlrpc_request *req = mdt_info_req(info);
2853 if (flv->it_flags & MUTABOR &&
2854 req->rq_export->exp_connect_flags & OBD_CONNECT_RDONLY)
2857 if (rc == 0 && flv->it_act != NULL) {
2858 /* execute policy */
2859 rc = flv->it_act(opc, info, lockp, flags);
2865 static int mdt_intent_policy(struct ldlm_namespace *ns,
2866 struct ldlm_lock **lockp, void *req_cookie,
2867 ldlm_mode_t mode, int flags, void *data)
2869 struct mdt_thread_info *info;
2870 struct ptlrpc_request *req = req_cookie;
2871 struct ldlm_intent *it;
2872 struct req_capsule *pill;
2877 LASSERT(req != NULL);
2879 info = lu_context_key_get(&req->rq_svc_thread->t_env->le_ctx,
2881 LASSERT(info != NULL);
2882 pill = &info->mti_pill;
2883 LASSERT(pill->rc_req == req);
2885 if (req->rq_reqmsg->lm_bufcount > DLM_INTENT_IT_OFF) {
2886 req_capsule_extend(pill, &RQF_LDLM_INTENT);
2887 it = req_capsule_client_get(pill, &RMF_LDLM_INTENT);
2889 const struct ldlm_request *dlmreq;
2892 struct ldlm_lock *lock = *lockp;
2894 LDLM_DEBUG(lock, "intent policy opc: %s\n",
2895 ldlm_it2str(it->opc));
2898 rc = mdt_intent_opc(it->opc, info, lockp, flags);
2903 * Lock without inodebits makes no sense and will oops
2904 * later in ldlm. Let's check it now to see if we have
2905 * wrong lock from client or bits get corrupted
2906 * somewhere in mdt_intent_opc().
2908 dlmreq = info->mti_dlm_req;
2909 req_bits = dlmreq->lock_desc.l_policy_data.l_inodebits.bits;
2910 LASSERT(req_bits != 0);
2913 rc = err_serious(-EFAULT);
2915 /* No intent was provided */
2916 LASSERT(pill->rc_fmt == &RQF_LDLM_ENQUEUE);
2917 rc = req_capsule_pack(pill);
2919 rc = err_serious(rc);
2927 static void mdt_seq_adjust(const struct lu_env *env,
2928 struct mdt_device *m, int lost)
2930 struct lu_site *ls = m->mdt_md_dev.md_lu_dev.ld_site;
2931 struct lu_range out;
2934 LASSERT(ls && ls->ls_server_seq);
2936 /* get extra seq from seq_server, moving it's range up */
2937 while (lost-- > 0) {
2938 seq_server_alloc_meta(ls->ls_server_seq, NULL, &out, env);
2943 static int mdt_seq_fini(const struct lu_env *env,
2944 struct mdt_device *m)
2946 struct lu_site *ls = m->mdt_md_dev.md_lu_dev.ld_site;
2949 if (ls && ls->ls_server_seq) {
2950 seq_server_fini(ls->ls_server_seq, env);
2951 OBD_FREE_PTR(ls->ls_server_seq);
2952 ls->ls_server_seq = NULL;
2955 if (ls && ls->ls_control_seq) {
2956 seq_server_fini(ls->ls_control_seq, env);
2957 OBD_FREE_PTR(ls->ls_control_seq);
2958 ls->ls_control_seq = NULL;
2961 if (ls && ls->ls_client_seq) {
2962 seq_client_fini(ls->ls_client_seq);
2963 OBD_FREE_PTR(ls->ls_client_seq);
2964 ls->ls_client_seq = NULL;
2970 static int mdt_seq_init(const struct lu_env *env,
2972 struct mdt_device *m)
2979 ls = m->mdt_md_dev.md_lu_dev.ld_site;
2982 * This is sequence-controller node. Init seq-controller server on local
2985 if (ls->ls_node_id == 0) {
2986 LASSERT(ls->ls_control_seq == NULL);
2988 OBD_ALLOC_PTR(ls->ls_control_seq);
2989 if (ls->ls_control_seq == NULL)
2992 rc = seq_server_init(ls->ls_control_seq,
2993 m->mdt_bottom, uuid,
2994 LUSTRE_SEQ_CONTROLLER,
2998 GOTO(out_seq_fini, rc);
3000 OBD_ALLOC_PTR(ls->ls_client_seq);
3001 if (ls->ls_client_seq == NULL)
3002 GOTO(out_seq_fini, rc = -ENOMEM);
3004 OBD_ALLOC(prefix, MAX_OBD_NAME + 5);
3005 if (prefix == NULL) {
3006 OBD_FREE_PTR(ls->ls_client_seq);
3007 GOTO(out_seq_fini, rc = -ENOMEM);
3010 snprintf(prefix, MAX_OBD_NAME + 5, "ctl-%s",
3014 * Init seq-controller client after seq-controller server is
3015 * ready. Pass ls->ls_control_seq to it for direct talking.
3017 rc = seq_client_init(ls->ls_client_seq, NULL,
3018 LUSTRE_SEQ_METADATA, prefix,
3019 ls->ls_control_seq);
3020 OBD_FREE(prefix, MAX_OBD_NAME + 5);
3023 GOTO(out_seq_fini, rc);
3026 /* Init seq-server on local MDT */
3027 LASSERT(ls->ls_server_seq == NULL);
3029 OBD_ALLOC_PTR(ls->ls_server_seq);
3030 if (ls->ls_server_seq == NULL)
3031 GOTO(out_seq_fini, rc = -ENOMEM);
3033 rc = seq_server_init(ls->ls_server_seq,
3034 m->mdt_bottom, uuid,
3038 GOTO(out_seq_fini, rc = -ENOMEM);
3040 /* Assign seq-controller client to local seq-server. */
3041 if (ls->ls_node_id == 0) {
3042 LASSERT(ls->ls_client_seq != NULL);
3044 rc = seq_server_set_cli(ls->ls_server_seq,
3052 mdt_seq_fini(env, m);
3057 * Init client sequence manager which is used by local MDS to talk to sequence
3058 * controller on remote node.
3060 static int mdt_seq_init_cli(const struct lu_env *env,
3061 struct mdt_device *m,
3062 struct lustre_cfg *cfg)
3064 struct lu_site *ls = m->mdt_md_dev.md_lu_dev.ld_site;
3065 struct obd_device *mdc;
3066 struct obd_uuid *uuidp, *mdcuuidp;
3067 char *uuid_str, *mdc_uuid_str;
3070 struct mdt_thread_info *info;
3071 char *p, *index_string = lustre_cfg_string(cfg, 2);
3074 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
3075 uuidp = &info->mti_u.uuid[0];
3076 mdcuuidp = &info->mti_u.uuid[1];
3078 LASSERT(index_string);
3080 index = simple_strtol(index_string, &p, 10);
3082 CERROR("Invalid index in lustre_cgf, offset 2\n");
3086 /* check if this is adding the first MDC and controller is not yet
3088 if (index != 0 || ls->ls_client_seq)
3091 uuid_str = lustre_cfg_string(cfg, 1);
3092 mdc_uuid_str = lustre_cfg_string(cfg, 4);
3093 obd_str2uuid(uuidp, uuid_str);
3094 obd_str2uuid(mdcuuidp, mdc_uuid_str);
3096 mdc = class_find_client_obd(uuidp, LUSTRE_MDC_NAME, mdcuuidp);
3098 CERROR("can't find controller MDC by uuid %s\n",
3101 } else if (!mdc->obd_set_up) {
3102 CERROR("target %s not set up\n", mdc->obd_name);
3105 LASSERT(ls->ls_control_exp);
3106 OBD_ALLOC_PTR(ls->ls_client_seq);
3107 if (ls->ls_client_seq != NULL) {
3110 OBD_ALLOC(prefix, MAX_OBD_NAME + 5);
3114 snprintf(prefix, MAX_OBD_NAME + 5, "ctl-%s",
3117 rc = seq_client_init(ls->ls_client_seq,
3119 LUSTRE_SEQ_METADATA,
3121 OBD_FREE(prefix, MAX_OBD_NAME + 5);
3128 LASSERT(ls->ls_server_seq != NULL);
3129 rc = seq_server_set_cli(ls->ls_server_seq, ls->ls_client_seq,
3136 static void mdt_seq_fini_cli(struct mdt_device *m)
3142 ls = m->mdt_md_dev.md_lu_dev.ld_site;
3144 if (ls && ls->ls_server_seq)
3145 seq_server_set_cli(ls->ls_server_seq,
3148 if (ls && ls->ls_control_exp) {
3149 class_export_put(ls->ls_control_exp);
3150 ls->ls_control_exp = NULL;
3158 static int mdt_fld_fini(const struct lu_env *env,
3159 struct mdt_device *m)
3161 struct lu_site *ls = m->mdt_md_dev.md_lu_dev.ld_site;
3164 if (ls && ls->ls_server_fld) {
3165 fld_server_fini(ls->ls_server_fld, env);
3166 OBD_FREE_PTR(ls->ls_server_fld);
3167 ls->ls_server_fld = NULL;
3173 static int mdt_fld_init(const struct lu_env *env,
3175 struct mdt_device *m)
3181 ls = m->mdt_md_dev.md_lu_dev.ld_site;
3183 OBD_ALLOC_PTR(ls->ls_server_fld);
3184 if (ls->ls_server_fld == NULL)
3185 RETURN(rc = -ENOMEM);
3187 rc = fld_server_init(ls->ls_server_fld,
3188 m->mdt_bottom, uuid, env);
3190 OBD_FREE_PTR(ls->ls_server_fld);
3191 ls->ls_server_fld = NULL;
3198 /* device init/fini methods */
3199 static void mdt_stop_ptlrpc_service(struct mdt_device *m)
3202 if (m->mdt_regular_service != NULL) {
3203 ptlrpc_unregister_service(m->mdt_regular_service);
3204 m->mdt_regular_service = NULL;
3206 if (m->mdt_readpage_service != NULL) {
3207 ptlrpc_unregister_service(m->mdt_readpage_service);
3208 m->mdt_readpage_service = NULL;
3210 if (m->mdt_xmds_service != NULL) {
3211 ptlrpc_unregister_service(m->mdt_xmds_service);
3212 m->mdt_xmds_service = NULL;
3214 if (m->mdt_setattr_service != NULL) {
3215 ptlrpc_unregister_service(m->mdt_setattr_service);
3216 m->mdt_setattr_service = NULL;
3218 if (m->mdt_mdsc_service != NULL) {
3219 ptlrpc_unregister_service(m->mdt_mdsc_service);
3220 m->mdt_mdsc_service = NULL;
3222 if (m->mdt_mdss_service != NULL) {
3223 ptlrpc_unregister_service(m->mdt_mdss_service);
3224 m->mdt_mdss_service = NULL;
3226 if (m->mdt_dtss_service != NULL) {
3227 ptlrpc_unregister_service(m->mdt_dtss_service);
3228 m->mdt_dtss_service = NULL;
3230 if (m->mdt_fld_service != NULL) {
3231 ptlrpc_unregister_service(m->mdt_fld_service);
3232 m->mdt_fld_service = NULL;
3237 static int mdt_start_ptlrpc_service(struct mdt_device *m)
3240 static struct ptlrpc_service_conf conf;
3241 cfs_proc_dir_entry_t *procfs_entry;
3244 procfs_entry = m->mdt_md_dev.md_lu_dev.ld_obd->obd_proc_entry;
3246 conf = (typeof(conf)) {
3247 .psc_nbufs = MDS_NBUFS,
3248 .psc_bufsize = MDS_BUFSIZE,
3249 .psc_max_req_size = MDS_MAXREQSIZE,
3250 .psc_max_reply_size = MDS_MAXREPSIZE,
3251 .psc_req_portal = MDS_REQUEST_PORTAL,
3252 .psc_rep_portal = MDC_REPLY_PORTAL,
3253 .psc_watchdog_timeout = MDT_SERVICE_WATCHDOG_TIMEOUT,
3255 * We'd like to have a mechanism to set this on a per-device
3256 * basis, but alas...
3258 .psc_min_threads = min(max(mdt_num_threads, MDT_MIN_THREADS),
3260 .psc_max_threads = MDT_MAX_THREADS,
3261 .psc_ctx_tags = LCT_MD_THREAD
3264 m->mdt_ldlm_client = &m->mdt_md_dev.md_lu_dev.ld_obd->obd_ldlm_client;
3265 ptlrpc_init_client(LDLM_CB_REQUEST_PORTAL, LDLM_CB_REPLY_PORTAL,
3266 "mdt_ldlm_client", m->mdt_ldlm_client);
3268 m->mdt_regular_service =
3269 ptlrpc_init_svc_conf(&conf, mdt_regular_handle, LUSTRE_MDT_NAME,
3270 procfs_entry, NULL, LUSTRE_MDT_NAME);
3271 if (m->mdt_regular_service == NULL)
3274 rc = ptlrpc_start_threads(NULL, m->mdt_regular_service);
3276 GOTO(err_mdt_svc, rc);
3279 * readpage service configuration. Parameters have to be adjusted,
3282 conf = (typeof(conf)) {
3283 .psc_nbufs = MDS_NBUFS,
3284 .psc_bufsize = MDS_BUFSIZE,
3285 .psc_max_req_size = MDS_MAXREQSIZE,
3286 .psc_max_reply_size = MDS_MAXREPSIZE,
3287 .psc_req_portal = MDS_READPAGE_PORTAL,
3288 .psc_rep_portal = MDC_REPLY_PORTAL,
3289 .psc_watchdog_timeout = MDT_SERVICE_WATCHDOG_TIMEOUT,
3290 .psc_min_threads = min(max(mdt_num_threads, MDT_MIN_THREADS),
3292 .psc_max_threads = MDT_MAX_THREADS,
3293 .psc_ctx_tags = LCT_MD_THREAD
3295 m->mdt_readpage_service =
3296 ptlrpc_init_svc_conf(&conf, mdt_readpage_handle,
3297 LUSTRE_MDT_NAME "_readpage",
3298 procfs_entry, NULL, "mdt_rdpg");
3300 if (m->mdt_readpage_service == NULL) {
3301 CERROR("failed to start readpage service\n");
3302 GOTO(err_mdt_svc, rc = -ENOMEM);
3305 rc = ptlrpc_start_threads(NULL, m->mdt_readpage_service);
3308 * setattr service configuration.
3310 conf = (typeof(conf)) {
3311 .psc_nbufs = MDS_NBUFS,
3312 .psc_bufsize = MDS_BUFSIZE,
3313 .psc_max_req_size = MDS_MAXREQSIZE,
3314 .psc_max_reply_size = MDS_MAXREPSIZE,
3315 .psc_req_portal = MDS_SETATTR_PORTAL,
3316 .psc_rep_portal = MDC_REPLY_PORTAL,
3317 .psc_watchdog_timeout = MDT_SERVICE_WATCHDOG_TIMEOUT,
3318 .psc_min_threads = min(max(mdt_num_threads, MDT_MIN_THREADS),
3320 .psc_max_threads = MDT_MAX_THREADS,
3321 .psc_ctx_tags = LCT_MD_THREAD
3324 m->mdt_setattr_service =
3325 ptlrpc_init_svc_conf(&conf, mdt_regular_handle,
3326 LUSTRE_MDT_NAME "_setattr",
3327 procfs_entry, NULL, "mdt_attr");
3329 if (!m->mdt_setattr_service) {
3330 CERROR("failed to start setattr service\n");
3331 GOTO(err_mdt_svc, rc = -ENOMEM);
3334 rc = ptlrpc_start_threads(NULL, m->mdt_setattr_service);
3336 GOTO(err_mdt_svc, rc);
3339 * sequence controller service configuration
3341 conf = (typeof(conf)) {
3342 .psc_nbufs = MDS_NBUFS,
3343 .psc_bufsize = MDS_BUFSIZE,
3344 .psc_max_req_size = SEQ_MAXREQSIZE,
3345 .psc_max_reply_size = SEQ_MAXREPSIZE,
3346 .psc_req_portal = SEQ_CONTROLLER_PORTAL,
3347 .psc_rep_portal = MDC_REPLY_PORTAL,
3348 .psc_watchdog_timeout = MDT_SERVICE_WATCHDOG_TIMEOUT,
3349 .psc_min_threads = SEQ_NUM_THREADS,
3350 .psc_max_threads = SEQ_NUM_THREADS,
3351 .psc_ctx_tags = LCT_MD_THREAD|LCT_DT_THREAD
3354 m->mdt_mdsc_service =
3355 ptlrpc_init_svc_conf(&conf, mdt_mdsc_handle,
3356 LUSTRE_MDT_NAME"_mdsc",
3357 procfs_entry, NULL, "mdt_mdsc");
3358 if (!m->mdt_mdsc_service) {
3359 CERROR("failed to start seq controller service\n");
3360 GOTO(err_mdt_svc, rc = -ENOMEM);
3363 rc = ptlrpc_start_threads(NULL, m->mdt_mdsc_service);
3365 GOTO(err_mdt_svc, rc);
3368 * metadata sequence server service configuration
3370 conf = (typeof(conf)) {
3371 .psc_nbufs = MDS_NBUFS,
3372 .psc_bufsize = MDS_BUFSIZE,
3373 .psc_max_req_size = SEQ_MAXREQSIZE,
3374 .psc_max_reply_size = SEQ_MAXREPSIZE,
3375 .psc_req_portal = SEQ_METADATA_PORTAL,
3376 .psc_rep_portal = MDC_REPLY_PORTAL,
3377 .psc_watchdog_timeout = MDT_SERVICE_WATCHDOG_TIMEOUT,
3378 .psc_min_threads = SEQ_NUM_THREADS,
3379 .psc_max_threads = SEQ_NUM_THREADS,
3380 .psc_ctx_tags = LCT_MD_THREAD|LCT_DT_THREAD
3383 m->mdt_mdss_service =
3384 ptlrpc_init_svc_conf(&conf, mdt_mdss_handle,
3385 LUSTRE_MDT_NAME"_mdss",
3386 procfs_entry, NULL, "mdt_mdss");
3387 if (!m->mdt_mdss_service) {
3388 CERROR("failed to start metadata seq server service\n");
3389 GOTO(err_mdt_svc, rc = -ENOMEM);
3392 rc = ptlrpc_start_threads(NULL, m->mdt_mdss_service);
3394 GOTO(err_mdt_svc, rc);
3398 * Data sequence server service configuration. We want to have really
3399 * cluster-wide sequences space. This is why we start only one sequence
3400 * controller which manages space.
3402 conf = (typeof(conf)) {
3403 .psc_nbufs = MDS_NBUFS,
3404 .psc_bufsize = MDS_BUFSIZE,
3405 .psc_max_req_size = SEQ_MAXREQSIZE,
3406 .psc_max_reply_size = SEQ_MAXREPSIZE,
3407 .psc_req_portal = SEQ_DATA_PORTAL,
3408 .psc_rep_portal = OSC_REPLY_PORTAL,
3409 .psc_watchdog_timeout = MDT_SERVICE_WATCHDOG_TIMEOUT,
3410 .psc_min_threads = SEQ_NUM_THREADS,
3411 .psc_max_threads = SEQ_NUM_THREADS,
3412 .psc_ctx_tags = LCT_MD_THREAD|LCT_DT_THREAD
3415 m->mdt_dtss_service =
3416 ptlrpc_init_svc_conf(&conf, mdt_dtss_handle,
3417 LUSTRE_MDT_NAME"_dtss",
3418 procfs_entry, NULL, "mdt_dtss");
3419 if (!m->mdt_dtss_service) {
3420 CERROR("failed to start data seq server service\n");
3421 GOTO(err_mdt_svc, rc = -ENOMEM);
3424 rc = ptlrpc_start_threads(NULL, m->mdt_dtss_service);
3426 GOTO(err_mdt_svc, rc);
3428 /* FLD service start */
3429 conf = (typeof(conf)) {
3430 .psc_nbufs = MDS_NBUFS,
3431 .psc_bufsize = MDS_BUFSIZE,
3432 .psc_max_req_size = FLD_MAXREQSIZE,
3433 .psc_max_reply_size = FLD_MAXREPSIZE,
3434 .psc_req_portal = FLD_REQUEST_PORTAL,
3435 .psc_rep_portal = MDC_REPLY_PORTAL,
3436 .psc_watchdog_timeout = MDT_SERVICE_WATCHDOG_TIMEOUT,
3437 .psc_min_threads = FLD_NUM_THREADS,
3438 .psc_max_threads = FLD_NUM_THREADS,
3439 .psc_ctx_tags = LCT_DT_THREAD|LCT_MD_THREAD
3442 m->mdt_fld_service =
3443 ptlrpc_init_svc_conf(&conf, mdt_fld_handle,
3444 LUSTRE_MDT_NAME"_fld",
3445 procfs_entry, NULL, "mdt_fld");
3446 if (!m->mdt_fld_service) {
3447 CERROR("failed to start fld service\n");
3448 GOTO(err_mdt_svc, rc = -ENOMEM);
3451 rc = ptlrpc_start_threads(NULL, m->mdt_fld_service);
3453 GOTO(err_mdt_svc, rc);
3456 * mds-mds service configuration. Separate portal is used to allow
3457 * mds-mds requests be not blocked during recovery.
3459 conf = (typeof(conf)) {
3460 .psc_nbufs = MDS_NBUFS,
3461 .psc_bufsize = MDS_BUFSIZE,
3462 .psc_max_req_size = MDS_MAXREQSIZE,
3463 .psc_max_reply_size = MDS_MAXREPSIZE,
3464 .psc_req_portal = MDS_MDS_PORTAL,
3465 .psc_rep_portal = MDC_REPLY_PORTAL,
3466 .psc_watchdog_timeout = MDT_SERVICE_WATCHDOG_TIMEOUT,
3467 .psc_min_threads = min(max(mdt_num_threads, MDT_MIN_THREADS),
3469 .psc_max_threads = MDT_MAX_THREADS,
3470 .psc_ctx_tags = LCT_MD_THREAD
3472 m->mdt_xmds_service = ptlrpc_init_svc_conf(&conf, mdt_xmds_handle,
3473 LUSTRE_MDT_NAME "_mds",
3474 procfs_entry, NULL, "mdt_xmds");
3476 if (m->mdt_xmds_service == NULL) {
3477 CERROR("failed to start readpage service\n");
3478 GOTO(err_mdt_svc, rc = -ENOMEM);
3481 rc = ptlrpc_start_threads(NULL, m->mdt_xmds_service);
3483 GOTO(err_mdt_svc, rc);
3488 mdt_stop_ptlrpc_service(m);
3493 static void mdt_stack_fini(const struct lu_env *env,
3494 struct mdt_device *m, struct lu_device *top)
3496 struct lu_device *d = top, *n;
3497 struct obd_device *obd = m->mdt_md_dev.md_lu_dev.ld_obd;
3498 struct lustre_cfg_bufs *bufs;
3499 struct lustre_cfg *lcfg;
3500 struct mdt_thread_info *info;
3504 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
3505 LASSERT(info != NULL);
3507 bufs = &info->mti_u.bufs;
3508 /* process cleanup, pass mdt obd name to get obd umount flags */
3509 lustre_cfg_bufs_reset(bufs, obd->obd_name);
3514 lustre_cfg_bufs_set_string(bufs, 1, flags);
3515 lcfg = lustre_cfg_new(LCFG_CLEANUP, bufs);
3517 CERROR("Cannot alloc lcfg!\n");
3522 top->ld_ops->ldo_process_config(env, top, lcfg);
3523 lustre_cfg_free(lcfg);
3525 lu_site_purge(env, top->ld_site, ~0);
3527 struct obd_type *type;
3528 struct lu_device_type *ldt = d->ld_type;
3530 /* each fini() returns next device in stack of layers
3531 * * so we can avoid the recursion */
3532 n = ldt->ldt_ops->ldto_device_fini(env, d);
3534 ldt->ldt_ops->ldto_device_free(env, d);
3535 type = ldt->ldt_obd_type;
3537 class_put_type(type);
3539 /* switch to the next device in the layer */
3542 m->mdt_child = NULL;
3543 m->mdt_bottom = NULL;
3546 static struct lu_device *mdt_layer_setup(const struct lu_env *env,
3547 const char *typename,
3548 struct lu_device *child,
3549 struct lustre_cfg *cfg)
3551 const char *dev = lustre_cfg_string(cfg, 0);
3552 struct obd_type *type;
3553 struct lu_device_type *ldt;
3554 struct lu_device *d;
3559 type = class_get_type(typename);
3561 CERROR("Unknown type: '%s'\n", typename);
3562 GOTO(out, rc = -ENODEV);
3565 rc = lu_context_refill(&env->le_ctx);
3567 CERROR("Failure to refill context: '%d'\n", rc);
3571 if (env->le_ses != NULL) {
3572 rc = lu_context_refill(env->le_ses);
3574 CERROR("Failure to refill session: '%d'\n", rc);
3581 CERROR("type: '%s'\n", typename);
3582 GOTO(out_type, rc = -EINVAL);
3585 ldt->ldt_obd_type = type;
3586 d = ldt->ldt_ops->ldto_device_alloc(env, ldt, cfg);
3588 CERROR("Cannot allocate device: '%s'\n", typename);
3589 GOTO(out_type, rc = -ENODEV);
3592 LASSERT(child->ld_site);
3593 d->ld_site = child->ld_site;
3596 rc = ldt->ldt_ops->ldto_device_init(env, d, dev, child);
3598 CERROR("can't init device '%s', rc %d\n", typename, rc);
3599 GOTO(out_alloc, rc);
3606 ldt->ldt_ops->ldto_device_free(env, d);
3609 class_put_type(type);
3614 static int mdt_stack_init(const struct lu_env *env,
3615 struct mdt_device *m, struct lustre_cfg *cfg)
3617 struct lu_device *d = &m->mdt_md_dev.md_lu_dev;
3618 struct lu_device *tmp;
3619 struct md_device *md;
3623 /* init the stack */
3624 tmp = mdt_layer_setup(env, LUSTRE_OSD_NAME, d, cfg);
3626 RETURN(PTR_ERR(tmp));
3628 m->mdt_bottom = lu2dt_dev(tmp);
3630 tmp = mdt_layer_setup(env, LUSTRE_MDD_NAME, d, cfg);
3632 GOTO(out, rc = PTR_ERR(tmp));
3637 tmp = mdt_layer_setup(env, LUSTRE_CMM_NAME, d, cfg);
3639 GOTO(out, rc = PTR_ERR(tmp));
3642 /*set mdd upcall device*/
3643 md_upcall_dev_set(md, lu2md_dev(d));
3646 /*set cmm upcall device*/
3647 md_upcall_dev_set(md, &m->mdt_md_dev);
3649 m->mdt_child = lu2md_dev(d);
3651 /* process setup config */
3652 tmp = &m->mdt_md_dev.md_lu_dev;
3653 rc = tmp->ld_ops->ldo_process_config(env, tmp, cfg);
3656 /* fini from last known good lu_device */
3658 mdt_stack_fini(env, m, d);
3663 static void mdt_fini(const struct lu_env *env, struct mdt_device *m)
3665 struct md_device *next = m->mdt_child;
3666 struct lu_device *d = &m->mdt_md_dev.md_lu_dev;
3667 struct lu_site *ls = d->ld_site;
3668 struct obd_device *obd = m->mdt_md_dev.md_lu_dev.ld_obd;
3671 ping_evictor_stop();
3673 target_recovery_fini(obd);
3674 mdt_stop_ptlrpc_service(m);
3676 mdt_fs_cleanup(env, m);
3678 upcall_cache_cleanup(m->mdt_rmtacl_cache);
3679 m->mdt_rmtacl_cache = NULL;
3681 upcall_cache_cleanup(m->mdt_identity_cache);
3682 m->mdt_identity_cache = NULL;
3684 if (m->mdt_namespace != NULL) {
3685 ldlm_namespace_free(m->mdt_namespace, d->ld_obd->obd_force);
3686 d->ld_obd->obd_namespace = m->mdt_namespace = NULL;
3689 mdt_seq_fini(env, m);
3690 mdt_seq_fini_cli(m);
3691 mdt_fld_fini(env, m);
3693 ptlrpc_lprocfs_unregister_obd(d->ld_obd);
3694 lprocfs_obd_cleanup(d->ld_obd);
3696 if (m->mdt_rootsquash_info) {
3697 OBD_FREE_PTR(m->mdt_rootsquash_info);
3698 m->mdt_rootsquash_info = NULL;
3701 next->md_ops->mdo_init_capa_ctxt(env, next, 0, 0, 0, NULL);
3702 del_timer(&m->mdt_ck_timer);
3703 mdt_ck_thread_stop(m);
3705 /* finish the stack */
3706 mdt_stack_fini(env, m, md2lu_dev(m->mdt_child));
3709 if (!list_empty(&ls->ls_lru) || ls->ls_total != 0) {
3711 * Uh-oh, objects still exist.
3713 static DECLARE_LU_CDEBUG_PRINT_INFO(cookie, D_ERROR);
3715 lu_site_print(env, ls, &cookie, lu_cdebug_printer);
3722 LASSERT(atomic_read(&d->ld_ref) == 0);
3723 md_device_fini(&m->mdt_md_dev);
3728 static void fsoptions_to_mdt_flags(struct mdt_device *m, char *options)
3738 while (*p && *p != ',')
3742 if ((len == sizeof("user_xattr") - 1) &&
3743 (memcmp(options, "user_xattr", len) == 0)) {
3744 m->mdt_opts.mo_user_xattr = 1;
3745 LCONSOLE_INFO("Enabling user_xattr\n");
3746 } else if ((len == sizeof("nouser_xattr") - 1) &&
3747 (memcmp(options, "nouser_xattr", len) == 0)) {
3748 m->mdt_opts.mo_user_xattr = 0;
3749 LCONSOLE_INFO("Disabling user_xattr\n");
3750 } else if ((len == sizeof("acl") - 1) &&
3751 (memcmp(options, "acl", len) == 0)) {
3752 #ifdef CONFIG_FS_POSIX_ACL
3753 m->mdt_opts.mo_acl = 1;
3754 LCONSOLE_INFO("Enabling ACL\n");
3756 m->mdt_opts.mo_acl = 0;
3757 CWARN("ignoring unsupported acl mount option\n");
3758 LCONSOLE_INFO("Disabling ACL\n");
3760 } else if ((len == sizeof("noacl") - 1) &&
3761 (memcmp(options, "noacl", len) == 0)) {
3762 m->mdt_opts.mo_acl = 0;
3763 LCONSOLE_INFO("Disabling ACL\n");
3770 int mdt_postrecov(const struct lu_env *, struct mdt_device *);
3772 static int mdt_init0(const struct lu_env *env, struct mdt_device *m,
3773 struct lu_device_type *ldt, struct lustre_cfg *cfg)
3775 struct lprocfs_static_vars lvars;
3776 struct mdt_thread_info *info;
3777 struct obd_device *obd;
3778 const char *dev = lustre_cfg_string(cfg, 0);
3779 const char *num = lustre_cfg_string(cfg, 2);
3780 struct lustre_mount_info *lmi;
3781 struct lustre_sb_info *lsi;
3786 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
3787 LASSERT(info != NULL);
3789 obd = class_name2obd(dev);
3790 LASSERT(obd != NULL);
3792 spin_lock_init(&m->mdt_transno_lock);
3794 m->mdt_max_mdsize = MAX_MD_SIZE;
3795 m->mdt_max_cookiesize = sizeof(struct llog_cookie);
3797 m->mdt_opts.mo_user_xattr = 0;
3798 m->mdt_opts.mo_acl = 0;
3799 lmi = server_get_mount_2(dev);
3801 CERROR("Cannot get mount info for %s!\n", dev);
3804 lsi = s2lsi(lmi->lmi_sb);
3805 fsoptions_to_mdt_flags(m, lsi->lsi_lmd->lmd_opts);
3806 server_put_mount_2(dev, lmi->lmi_mnt);
3809 spin_lock_init(&m->mdt_ioepoch_lock);
3810 m->mdt_opts.mo_compat_resname = 0;
3811 m->mdt_capa_timeout = CAPA_TIMEOUT;
3812 m->mdt_capa_alg = CAPA_HMAC_ALG_SHA1;
3813 m->mdt_ck_timeout = CAPA_KEY_TIMEOUT;
3815 spin_lock_init(&m->mdt_client_bitmap_lock);
3821 md_device_init(&m->mdt_md_dev, ldt);
3822 m->mdt_md_dev.md_lu_dev.ld_ops = &mdt_lu_ops;
3823 m->mdt_md_dev.md_lu_dev.ld_obd = obd;
3824 /* set this lu_device to obd, because error handling need it */
3825 obd->obd_lu_dev = &m->mdt_md_dev.md_lu_dev;
3827 rc = lu_site_init(s, &m->mdt_md_dev.md_lu_dev);
3829 CERROR("Can't init lu_site, rc %d\n", rc);
3830 GOTO(err_free_site, rc);
3833 lprocfs_init_vars(mdt, &lvars);
3834 rc = lprocfs_obd_setup(obd, lvars.obd_vars);
3836 CERROR("Can't init lprocfs, rc %d\n", rc);
3837 GOTO(err_fini_site, rc);
3839 ptlrpc_lprocfs_register_obd(obd);
3841 rc = mdt_procfs_init(m, dev);
3843 CERROR("Can't init MDT lprocfs, rc %d\n", rc);
3844 GOTO(err_fini_proc, rc);
3847 /* set server index */
3849 s->ls_node_id = simple_strtol(num, NULL, 10);
3851 /* failover is the default
3852 * FIXME: we do not failout mds0/mgs, which may cause some problems.
3853 * assumed whose ls_node_id == 0 XXX
3855 obd->obd_replayable = 1;
3856 /* No connection accepted until configurations will finish */
3857 obd->obd_no_conn = 1;
3859 if (cfg->lcfg_bufcount > 4 && LUSTRE_CFG_BUFLEN(cfg, 4) > 0) {
3860 char *str = lustre_cfg_string(cfg, 4);
3861 if (strchr(str, 'n')) {
3862 CWARN("%s: recovery disabled\n", obd->obd_name);
3863 obd->obd_replayable = 0;
3867 /* init the stack */
3868 rc = mdt_stack_init(env, m, cfg);
3870 CERROR("Can't init device stack, rc %d\n", rc);
3871 GOTO(err_fini_proc, rc);
3874 rc = mdt_fld_init(env, obd->obd_name, m);
3876 GOTO(err_fini_stack, rc);
3878 rc = mdt_seq_init(env, obd->obd_name, m);
3880 GOTO(err_fini_fld, rc);
3882 snprintf(info->mti_u.ns_name, sizeof info->mti_u.ns_name,
3883 LUSTRE_MDT_NAME"-%p", m);
3884 m->mdt_namespace = ldlm_namespace_new(info->mti_u.ns_name,
3885 LDLM_NAMESPACE_SERVER);
3886 if (m->mdt_namespace == NULL)
3887 GOTO(err_fini_seq, rc = -ENOMEM);
3889 ldlm_register_intent(m->mdt_namespace, mdt_intent_policy);
3890 /* set obd_namespace for compatibility with old code */
3891 obd->obd_namespace = m->mdt_namespace;
3893 m->mdt_identity_cache = upcall_cache_init(obd->obd_name,
3895 &mdt_identity_upcall_cache_ops);
3896 if (IS_ERR(m->mdt_identity_cache)) {
3897 rc = PTR_ERR(m->mdt_identity_cache);
3898 m->mdt_identity_cache = NULL;
3899 GOTO(err_free_ns, rc);
3902 m->mdt_rmtacl_cache = upcall_cache_init(obd->obd_name,
3903 MDT_RMTACL_UPCALL_PATH,
3904 &mdt_rmtacl_upcall_cache_ops);
3905 if (IS_ERR(m->mdt_rmtacl_cache)) {
3906 rc = PTR_ERR(m->mdt_rmtacl_cache);
3907 m->mdt_rmtacl_cache = NULL;
3908 GOTO(err_free_ns, rc);
3911 m->mdt_ck_timer.function = mdt_ck_timer_callback;
3912 m->mdt_ck_timer.data = (unsigned long)m;
3913 init_timer(&m->mdt_ck_timer);
3914 rc = mdt_ck_thread_start(m);
3916 GOTO(err_free_ns, rc);
3918 rc = mdt_fs_setup(env, m, obd);
3922 target_recovery_init(obd, mdt_recovery_handle);
3924 rc = mdt_start_ptlrpc_service(m);
3926 GOTO(err_fs_cleanup, rc);
3928 ping_evictor_start();
3930 rc = lu_site_init_finish(s);
3932 GOTO(err_stop_service, rc);
3934 if (obd->obd_recovering == 0)
3935 mdt_postrecov(env, m);
3937 mdt_init_capa_ctxt(env, m);
3939 if (ldlm_timeout == LDLM_TIMEOUT_DEFAULT)
3945 ping_evictor_stop();
3946 mdt_stop_ptlrpc_service(m);
3948 target_recovery_fini(obd);
3949 mdt_fs_cleanup(env, m);
3951 del_timer(&m->mdt_ck_timer);
3952 mdt_ck_thread_stop(m);
3954 upcall_cache_cleanup(m->mdt_rmtacl_cache);
3955 m->mdt_rmtacl_cache = NULL;
3956 upcall_cache_cleanup(m->mdt_identity_cache);
3957 m->mdt_identity_cache = NULL;
3958 ldlm_namespace_free(m->mdt_namespace, 0);
3959 obd->obd_namespace = m->mdt_namespace = NULL;
3961 mdt_seq_fini(env, m);
3963 mdt_fld_fini(env, m);
3965 mdt_stack_fini(env, m, md2lu_dev(m->mdt_child));
3968 lprocfs_obd_cleanup(obd);
3974 md_device_fini(&m->mdt_md_dev);
3978 /* used by MGS to process specific configurations */
3979 static int mdt_process_config(const struct lu_env *env,
3980 struct lu_device *d, struct lustre_cfg *cfg)
3982 struct mdt_device *m = mdt_dev(d);
3983 struct md_device *md_next = m->mdt_child;
3984 struct lu_device *next = md2lu_dev(md_next);
3988 switch (cfg->lcfg_command) {
3990 struct lprocfs_static_vars lvars;
3991 struct obd_device *obd = d->ld_obd;
3993 lprocfs_init_vars(mdt, &lvars);
3994 rc = class_process_proc_param(PARAM_MDT, lvars.obd_vars, cfg, obd);
3996 /* others are passed further */
3997 rc = next->ld_ops->ldo_process_config(env, next, cfg);
4002 * Add mdc hook to get first MDT uuid and connect it to
4003 * ls->controller to use for seq manager.
4005 rc = next->ld_ops->ldo_process_config(env, next, cfg);
4007 CERROR("Can't add mdc, rc %d\n", rc);
4009 rc = mdt_seq_init_cli(env, mdt_dev(d), cfg);
4012 /* others are passed further */
4013 rc = next->ld_ops->ldo_process_config(env, next, cfg);
4019 static struct lu_object *mdt_object_alloc(const struct lu_env *env,
4020 const struct lu_object_header *hdr,
4021 struct lu_device *d)
4023 struct mdt_object *mo;
4029 struct lu_object *o;
4030 struct lu_object_header *h;
4032 o = &mo->mot_obj.mo_lu;
4033 h = &mo->mot_header;
4034 lu_object_header_init(h);
4035 lu_object_init(o, h, d);
4036 lu_object_add_top(h, o);
4037 o->lo_ops = &mdt_obj_ops;
4043 static int mdt_object_init(const struct lu_env *env, struct lu_object *o)
4045 struct mdt_device *d = mdt_dev(o->lo_dev);
4046 struct lu_device *under;
4047 struct lu_object *below;
4051 CDEBUG(D_INFO, "object init, fid = "DFID"\n",
4052 PFID(lu_object_fid(o)));
4054 under = &d->mdt_child->md_lu_dev;
4055 below = under->ld_ops->ldo_object_alloc(env, o->lo_header, under);
4056 if (below != NULL) {
4057 lu_object_add(o, below);
4064 static void mdt_object_free(const struct lu_env *env, struct lu_object *o)
4066 struct mdt_object *mo = mdt_obj(o);
4067 struct lu_object_header *h;
4071 CDEBUG(D_INFO, "object free, fid = "DFID"\n",
4072 PFID(lu_object_fid(o)));
4075 lu_object_header_fini(h);
4080 static int mdt_object_print(const struct lu_env *env, void *cookie,
4081 lu_printer_t p, const struct lu_object *o)
4083 return (*p)(env, cookie, LUSTRE_MDT_NAME"-object@%p", o);
4086 static struct lu_device_operations mdt_lu_ops = {
4087 .ldo_object_alloc = mdt_object_alloc,
4088 .ldo_process_config = mdt_process_config
4091 static struct lu_object_operations mdt_obj_ops = {
4092 .loo_object_init = mdt_object_init,
4093 .loo_object_free = mdt_object_free,
4094 .loo_object_print = mdt_object_print
4097 /* mds_connect_internal */
4098 static int mdt_connect_internal(struct obd_export *exp,
4099 struct mdt_device *mdt,
4100 struct obd_connect_data *data)
4105 data->ocd_connect_flags &= MDT_CONNECT_SUPPORTED;
4106 data->ocd_ibits_known &= MDS_INODELOCK_FULL;
4108 /* If no known bits (which should not happen, probably,
4109 as everybody should support LOOKUP and UPDATE bits at least)
4110 revert to compat mode with plain locks. */
4111 if (!data->ocd_ibits_known &&
4112 data->ocd_connect_flags & OBD_CONNECT_IBITS)
4113 data->ocd_connect_flags &= ~OBD_CONNECT_IBITS;
4115 if (!mdt->mdt_opts.mo_acl)
4116 data->ocd_connect_flags &= ~OBD_CONNECT_ACL;
4118 if (!mdt->mdt_opts.mo_user_xattr)
4119 data->ocd_connect_flags &= ~OBD_CONNECT_XATTR;
4121 if (!mdt->mdt_opts.mo_mds_capa)
4122 data->ocd_connect_flags &= ~OBD_CONNECT_MDS_CAPA;
4124 if (!mdt->mdt_opts.mo_oss_capa)
4125 data->ocd_connect_flags &= ~OBD_CONNECT_OSS_CAPA;
4127 spin_lock(&exp->exp_lock);
4128 exp->exp_connect_flags = data->ocd_connect_flags;
4129 spin_unlock(&exp->exp_lock);
4130 data->ocd_version = LUSTRE_VERSION_CODE;
4131 exp->exp_mdt_data.med_ibits_known = data->ocd_ibits_known;
4135 if (mdt->mdt_opts.mo_acl &&
4136 ((exp->exp_connect_flags & OBD_CONNECT_ACL) == 0)) {
4137 CWARN("%s: MDS requires ACL support but client does not\n",
4138 mdt->mdt_md_dev.md_lu_dev.ld_obd->obd_name);
4143 flags = OBD_CONNECT_LCL_CLIENT | OBD_CONNECT_RMT_CLIENT;
4144 if ((exp->exp_connect_flags & flags) == flags) {
4145 CWARN("%s: both local and remote client flags are set\n",
4146 mdt->mdt_md_dev.md_lu_dev.ld_obd->obd_name);
4150 if (mdt->mdt_opts.mo_mds_capa &&
4151 ((exp->exp_connect_flags & OBD_CONNECT_MDS_CAPA) == 0)) {
4152 CWARN("%s: MDS requires capability support, but client not\n",
4153 mdt->mdt_md_dev.md_lu_dev.ld_obd->obd_name);
4157 if (mdt->mdt_opts.mo_oss_capa &&
4158 ((exp->exp_connect_flags & OBD_CONNECT_OSS_CAPA) == 0)) {
4159 CWARN("%s: MDS requires OSS capability support, "
4161 mdt->mdt_md_dev.md_lu_dev.ld_obd->obd_name);
4168 /* mds_connect copy */
4169 static int mdt_obd_connect(const struct lu_env *env,
4170 struct lustre_handle *conn, struct obd_device *obd,
4171 struct obd_uuid *cluuid,
4172 struct obd_connect_data *data)
4174 struct mdt_client_data *mcd;
4175 struct obd_export *exp;
4176 struct mdt_device *mdt;
4180 LASSERT(env != NULL);
4181 if (!conn || !obd || !cluuid)
4184 mdt = mdt_dev(obd->obd_lu_dev);
4186 rc = class_connect(conn, obd, cluuid);
4190 exp = class_conn2export(conn);
4191 LASSERT(exp != NULL);
4193 rc = mdt_connect_internal(exp, mdt, data);
4197 struct mdt_thread_info *mti;
4198 mti = lu_context_key_get(&env->le_ctx,
4200 LASSERT(mti != NULL);
4202 memcpy(mcd->mcd_uuid, cluuid, sizeof mcd->mcd_uuid);
4203 exp->exp_mdt_data.med_mcd = mcd;
4204 rc = mdt_client_new(env, mdt);
4207 exp->exp_mdt_data.med_mcd = NULL;
4214 class_disconnect(exp);
4216 class_export_put(exp);
4221 static int mdt_obd_reconnect(struct obd_export *exp, struct obd_device *obd,
4222 struct obd_uuid *cluuid,
4223 struct obd_connect_data *data)
4228 if (exp == NULL || obd == NULL || cluuid == NULL)
4231 rc = mdt_connect_internal(exp, mdt_dev(obd->obd_lu_dev), data);
4236 static int mdt_obd_disconnect(struct obd_export *exp)
4238 struct mdt_device *mdt = mdt_dev(exp->exp_obd->obd_lu_dev);
4243 class_export_get(exp);
4245 /* Disconnect early so that clients can't keep using export */
4246 rc = class_disconnect(exp);
4247 if (mdt->mdt_namespace != NULL || exp->exp_obd->obd_namespace != NULL)
4248 ldlm_cancel_locks_for_export(exp);
4250 /* complete all outstanding replies */
4251 spin_lock(&exp->exp_lock);
4252 while (!list_empty(&exp->exp_outstanding_replies)) {
4253 struct ptlrpc_reply_state *rs =
4254 list_entry(exp->exp_outstanding_replies.next,
4255 struct ptlrpc_reply_state, rs_exp_list);
4256 struct ptlrpc_service *svc = rs->rs_service;
4258 spin_lock(&svc->srv_lock);
4259 list_del_init(&rs->rs_exp_list);
4260 ptlrpc_schedule_difficult_reply(rs);
4261 spin_unlock(&svc->srv_lock);
4263 spin_unlock(&exp->exp_lock);
4265 class_export_put(exp);
4269 /* FIXME: Can we avoid using these two interfaces? */
4270 static int mdt_init_export(struct obd_export *exp)
4272 struct mdt_export_data *med = &exp->exp_mdt_data;
4275 INIT_LIST_HEAD(&med->med_open_head);
4276 spin_lock_init(&med->med_open_lock);
4277 spin_lock(&exp->exp_lock);
4278 exp->exp_connecting = 1;
4279 spin_unlock(&exp->exp_lock);
4283 static int mdt_destroy_export(struct obd_export *export)
4285 struct mdt_export_data *med;
4286 struct obd_device *obd = export->exp_obd;
4287 struct mdt_device *mdt;
4288 struct mdt_thread_info *info;
4296 med = &export->exp_mdt_data;
4297 if (med->med_rmtclient)
4298 mdt_cleanup_idmap(med);
4300 target_destroy_export(export);
4302 if (obd_uuid_equals(&export->exp_client_uuid, &obd->obd_uuid))
4305 mdt = mdt_dev(obd->obd_lu_dev);
4306 LASSERT(mdt != NULL);
4308 rc = lu_env_init(&env, NULL, LCT_MD_THREAD);
4312 info = lu_context_key_get(&env.le_ctx, &mdt_thread_key);
4313 LASSERT(info != NULL);
4314 memset(info, 0, sizeof *info);
4315 info->mti_env = &env;
4316 info->mti_mdt = mdt;
4317 info->mti_exp = export;
4319 ma = &info->mti_attr;
4320 lmm_size = ma->ma_lmm_size = mdt->mdt_max_mdsize;
4321 cookie_size = ma->ma_cookie_size = mdt->mdt_max_cookiesize;
4322 OBD_ALLOC(ma->ma_lmm, lmm_size);
4323 OBD_ALLOC(ma->ma_cookie, cookie_size);
4325 if (ma->ma_lmm == NULL || ma->ma_cookie == NULL)
4326 GOTO(out, rc = -ENOMEM);
4327 ma->ma_need = MA_LOV | MA_COOKIE;
4329 /* Close any open files (which may also cause orphan unlinking). */
4330 spin_lock(&med->med_open_lock);
4331 while (!list_empty(&med->med_open_head)) {
4332 struct list_head *tmp = med->med_open_head.next;
4333 struct mdt_file_data *mfd =
4334 list_entry(tmp, struct mdt_file_data, mfd_list);
4336 /* Remove mfd handle so it can't be found again.
4337 * We are consuming the mfd_list reference here. */
4338 class_handle_unhash(&mfd->mfd_handle);
4339 list_del_init(&mfd->mfd_list);
4340 spin_unlock(&med->med_open_lock);
4341 mdt_mfd_close(info, mfd);
4342 /* TODO: if we close the unlinked file,
4343 * we need to remove it's objects from OST */
4344 memset(&ma->ma_attr, 0, sizeof(ma->ma_attr));
4345 spin_lock(&med->med_open_lock);
4346 ma->ma_lmm_size = lmm_size;
4347 ma->ma_cookie_size = cookie_size;
4348 ma->ma_need = MA_LOV | MA_COOKIE;
4351 spin_unlock(&med->med_open_lock);
4352 info->mti_mdt = NULL;
4353 mdt_client_del(&env, mdt);
4358 OBD_FREE(ma->ma_lmm, lmm_size);
4362 OBD_FREE(ma->ma_cookie, cookie_size);
4363 ma->ma_cookie = NULL;
4370 static int mdt_upcall(const struct lu_env *env, struct md_device *md,
4371 enum md_upcall_event ev)
4373 struct mdt_device *m = mdt_dev(&md->md_lu_dev);
4374 struct md_device *next = m->mdt_child;
4375 struct mdt_thread_info *mti;
4381 rc = next->md_ops->mdo_maxsize_get(env, next,
4383 &m->mdt_max_cookiesize);
4384 CDEBUG(D_INFO, "get max mdsize %d max cookiesize %d\n",
4385 m->mdt_max_mdsize, m->mdt_max_cookiesize);
4388 mti = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
4389 mti->mti_no_need_trans = 1;
4390 CDEBUG(D_INFO, "disable mdt trans for this thread\n");
4393 CERROR("invalid event\n");
4400 static int mdt_obd_notify(struct obd_device *host,
4401 struct obd_device *watched,
4402 enum obd_notify_event ev, void *owner)
4407 case OBD_NOTIFY_CONFIG:
4408 host->obd_no_conn = 0;
4410 CDEBUG(D_INFO, "Notification 0x%x\n", ev);
4415 static int mdt_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
4416 void *karg, void *uarg)
4419 struct obd_device *obd= exp->exp_obd;
4420 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
4421 struct dt_device *dt = mdt->mdt_bottom;
4425 CDEBUG(D_IOCTL, "handling ioctl cmd %#x\n", cmd);
4426 rc = lu_env_init(&env, NULL, LCT_MD_THREAD);
4432 rc = dt->dd_ops->dt_sync(&env, dt);
4434 case OBD_IOC_SET_READONLY:
4435 rc = dt->dd_ops->dt_sync(&env, dt);
4436 dt->dd_ops->dt_ro(&env, dt);
4438 case OBD_IOC_ABORT_RECOVERY:
4439 CERROR("Aborting recovery for device %s\n", obd->obd_name);
4440 target_stop_recovery_thread(obd);
4444 CERROR("Not supported cmd = %d for device %s\n",
4445 cmd, obd->obd_name);
4453 int mdt_postrecov(const struct lu_env *env, struct mdt_device *mdt)
4455 struct lu_device *ld = md2lu_dev(mdt->mdt_child);
4456 struct obd_device *obd = mdt->mdt_md_dev.md_lu_dev.ld_obd;
4459 /* if some clients didn't participate in recovery then we can possibly
4460 * lost sequence. Now we should increase sequence for safe value */
4461 lost = obd->obd_max_recoverable_clients - obd->obd_connected_clients;
4462 mdt_seq_adjust(env, mdt, lost);
4464 rc = ld->ld_ops->ldo_recovery_complete(env, ld);
4468 int mdt_obd_postrecov(struct obd_device *obd)
4473 rc = lu_env_init(&env, NULL, LCT_MD_THREAD);
4476 rc = mdt_postrecov(&env, mdt_dev(obd->obd_lu_dev));
4481 static struct obd_ops mdt_obd_device_ops = {
4482 .o_owner = THIS_MODULE,
4483 .o_connect = mdt_obd_connect,
4484 .o_reconnect = mdt_obd_reconnect,
4485 .o_disconnect = mdt_obd_disconnect,
4486 .o_init_export = mdt_init_export,
4487 .o_destroy_export = mdt_destroy_export,
4488 .o_iocontrol = mdt_iocontrol,
4489 .o_postrecov = mdt_obd_postrecov,
4490 .o_notify = mdt_obd_notify
4493 static struct lu_device* mdt_device_fini(const struct lu_env *env,
4494 struct lu_device *d)
4496 struct mdt_device *m = mdt_dev(d);
4503 static void mdt_device_free(const struct lu_env *env, struct lu_device *d)
4505 struct mdt_device *m = mdt_dev(d);
4510 static struct lu_device *mdt_device_alloc(const struct lu_env *env,
4511 struct lu_device_type *t,
4512 struct lustre_cfg *cfg)
4514 struct lu_device *l;
4515 struct mdt_device *m;
4521 l = &m->mdt_md_dev.md_lu_dev;
4522 rc = mdt_init0(env, m, t, cfg);
4528 md_upcall_init(&m->mdt_md_dev, mdt_upcall);
4530 l = ERR_PTR(-ENOMEM);
4535 * context key constructor/destructor
4537 static void *mdt_key_init(const struct lu_context *ctx,
4538 struct lu_context_key *key)
4540 struct mdt_thread_info *info;
4543 * check that no high order allocations are incurred.
4545 CLASSERT(CFS_PAGE_SIZE >= sizeof *info);
4546 OBD_ALLOC_PTR(info);
4548 info = ERR_PTR(-ENOMEM);
4552 static void mdt_key_fini(const struct lu_context *ctx,
4553 struct lu_context_key *key, void *data)
4555 struct mdt_thread_info *info = data;
4559 struct lu_context_key mdt_thread_key = {
4560 .lct_tags = LCT_MD_THREAD,
4561 .lct_init = mdt_key_init,
4562 .lct_fini = mdt_key_fini
4565 static void *mdt_txn_key_init(const struct lu_context *ctx,
4566 struct lu_context_key *key)
4568 struct mdt_txn_info *txi;
4571 * check that no high order allocations are incurred.
4573 CLASSERT(CFS_PAGE_SIZE >= sizeof *txi);
4576 txi = ERR_PTR(-ENOMEM);
4577 memset(txi, 0, sizeof(*txi));
4581 static void mdt_txn_key_fini(const struct lu_context *ctx,
4582 struct lu_context_key *key, void *data)
4584 struct mdt_txn_info *txi = data;
4588 struct lu_context_key mdt_txn_key = {
4589 .lct_tags = LCT_TX_HANDLE,
4590 .lct_init = mdt_txn_key_init,
4591 .lct_fini = mdt_txn_key_fini
4594 struct md_ucred *mdt_ucred(const struct mdt_thread_info *info)
4596 return md_ucred(info->mti_env);
4599 static int mdt_type_init(struct lu_device_type *t)
4603 LU_CONTEXT_KEY_INIT(&mdt_thread_key);
4604 rc = lu_context_key_register(&mdt_thread_key);
4606 LU_CONTEXT_KEY_INIT(&mdt_txn_key);
4607 rc = lu_context_key_register(&mdt_txn_key);
4612 static void mdt_type_fini(struct lu_device_type *t)
4614 lu_context_key_degister(&mdt_thread_key);
4615 lu_context_key_degister(&mdt_txn_key);
4618 static struct lu_device_type_operations mdt_device_type_ops = {
4619 .ldto_init = mdt_type_init,
4620 .ldto_fini = mdt_type_fini,
4622 .ldto_device_alloc = mdt_device_alloc,
4623 .ldto_device_free = mdt_device_free,
4624 .ldto_device_fini = mdt_device_fini
4627 static struct lu_device_type mdt_device_type = {
4628 .ldt_tags = LU_DEVICE_MD,
4629 .ldt_name = LUSTRE_MDT_NAME,
4630 .ldt_ops = &mdt_device_type_ops,
4631 .ldt_ctx_tags = LCT_MD_THREAD
4634 static int __init mdt_mod_init(void)
4636 struct lprocfs_static_vars lvars;
4639 mdt_num_threads = MDT_NUM_THREADS;
4640 lprocfs_init_vars(mdt, &lvars);
4641 rc = class_register_type(&mdt_obd_device_ops, NULL,
4642 lvars.module_vars, LUSTRE_MDT_NAME,
4648 static void __exit mdt_mod_exit(void)
4650 class_unregister_type(LUSTRE_MDT_NAME);
4654 #define DEF_HNDL(prefix, base, suffix, flags, opc, fn, fmt) \
4655 [prefix ## _ ## opc - prefix ## _ ## base] = { \
4657 .mh_fail_id = OBD_FAIL_ ## prefix ## _ ## opc ## suffix, \
4658 .mh_opc = prefix ## _ ## opc, \
4659 .mh_flags = flags, \
4664 #define DEF_MDT_HNDL(flags, name, fn, fmt) \
4665 DEF_HNDL(MDS, GETATTR, _NET, flags, name, fn, fmt)
4667 #define DEF_SEQ_HNDL(flags, name, fn, fmt) \
4668 DEF_HNDL(SEQ, QUERY, _NET, flags, name, fn, fmt)
4670 #define DEF_FLD_HNDL(flags, name, fn, fmt) \
4671 DEF_HNDL(FLD, QUERY, _NET, flags, name, fn, fmt)
4673 * Request with a format known in advance
4675 #define DEF_MDT_HNDL_F(flags, name, fn) \
4676 DEF_HNDL(MDS, GETATTR, _NET, flags, name, fn, &RQF_MDS_ ## name)
4678 #define DEF_SEQ_HNDL_F(flags, name, fn) \
4679 DEF_HNDL(SEQ, QUERY, _NET, flags, name, fn, &RQF_SEQ_ ## name)
4681 #define DEF_FLD_HNDL_F(flags, name, fn) \
4682 DEF_HNDL(FLD, QUERY, _NET, flags, name, fn, &RQF_FLD_ ## name)
4684 * Request with a format we do not yet know
4686 #define DEF_MDT_HNDL_0(flags, name, fn) \
4687 DEF_HNDL(MDS, GETATTR, _NET, flags, name, fn, NULL)
4689 static struct mdt_handler mdt_mds_ops[] = {
4690 DEF_MDT_HNDL_F(0, CONNECT, mdt_connect),
4691 DEF_MDT_HNDL_F(0, DISCONNECT, mdt_disconnect),
4692 DEF_MDT_HNDL_F(0, SET_INFO, mdt_set_info),
4693 DEF_MDT_HNDL_F(0 |HABEO_REFERO, GETSTATUS, mdt_getstatus),
4694 DEF_MDT_HNDL_F(HABEO_CORPUS, GETATTR, mdt_getattr),
4695 DEF_MDT_HNDL_F(HABEO_CORPUS|HABEO_REFERO, GETATTR_NAME, mdt_getattr_name),
4696 DEF_MDT_HNDL_F(HABEO_CORPUS|MUTABOR, SETXATTR, mdt_setxattr),
4697 DEF_MDT_HNDL_F(HABEO_CORPUS, GETXATTR, mdt_getxattr),
4698 DEF_MDT_HNDL_F(0 |HABEO_REFERO, STATFS, mdt_statfs),
4699 DEF_MDT_HNDL_F(0 |MUTABOR, REINT, mdt_reint),
4700 DEF_MDT_HNDL_F(HABEO_CORPUS, CLOSE, mdt_close),
4701 DEF_MDT_HNDL_F(HABEO_CORPUS, DONE_WRITING, mdt_done_writing),
4702 DEF_MDT_HNDL_F(0 |HABEO_REFERO, PIN, mdt_pin),
4703 DEF_MDT_HNDL_0(0, SYNC, mdt_sync),
4704 DEF_MDT_HNDL_F(HABEO_CORPUS|HABEO_REFERO, IS_SUBDIR, mdt_is_subdir),
4705 DEF_MDT_HNDL_0(0, QUOTACHECK, mdt_quotacheck_handle),
4706 DEF_MDT_HNDL_0(0, QUOTACTL, mdt_quotactl_handle)
4709 #define DEF_OBD_HNDL(flags, name, fn) \
4710 DEF_HNDL(OBD, PING, _NET, flags, name, fn, NULL)
4713 static struct mdt_handler mdt_obd_ops[] = {
4714 DEF_OBD_HNDL(0, PING, mdt_obd_ping),
4715 DEF_OBD_HNDL(0, LOG_CANCEL, mdt_obd_log_cancel),
4716 DEF_OBD_HNDL(0, QC_CALLBACK, mdt_obd_qc_callback)
4719 #define DEF_DLM_HNDL_0(flags, name, fn) \
4720 DEF_HNDL(LDLM, ENQUEUE, , flags, name, fn, NULL)
4721 #define DEF_DLM_HNDL_F(flags, name, fn) \
4722 DEF_HNDL(LDLM, ENQUEUE, , flags, name, fn, &RQF_LDLM_ ## name)
4724 static struct mdt_handler mdt_dlm_ops[] = {
4725 DEF_DLM_HNDL_F(HABEO_CLAVIS, ENQUEUE, mdt_enqueue),
4726 DEF_DLM_HNDL_0(HABEO_CLAVIS, CONVERT, mdt_convert),
4727 DEF_DLM_HNDL_0(0, BL_CALLBACK, mdt_bl_callback),
4728 DEF_DLM_HNDL_0(0, CP_CALLBACK, mdt_cp_callback)
4731 static struct mdt_handler mdt_llog_ops[] = {
4734 #define DEF_SEC_CTX_HNDL(name, fn) \
4735 DEF_HNDL(SEC_CTX, INIT, _NET, 0, name, fn, NULL)
4737 static struct mdt_handler mdt_sec_ctx_ops[] = {
4738 DEF_SEC_CTX_HNDL(INIT, mdt_sec_ctx_handle),
4739 DEF_SEC_CTX_HNDL(INIT_CONT, mdt_sec_ctx_handle),
4740 DEF_SEC_CTX_HNDL(FINI, mdt_sec_ctx_handle)
4743 static struct mdt_opc_slice mdt_regular_handlers[] = {
4745 .mos_opc_start = MDS_GETATTR,
4746 .mos_opc_end = MDS_LAST_OPC,
4747 .mos_hs = mdt_mds_ops
4750 .mos_opc_start = OBD_PING,
4751 .mos_opc_end = OBD_LAST_OPC,
4752 .mos_hs = mdt_obd_ops
4755 .mos_opc_start = LDLM_ENQUEUE,
4756 .mos_opc_end = LDLM_LAST_OPC,
4757 .mos_hs = mdt_dlm_ops
4760 .mos_opc_start = LLOG_ORIGIN_HANDLE_CREATE,
4761 .mos_opc_end = LLOG_LAST_OPC,
4762 .mos_hs = mdt_llog_ops
4765 .mos_opc_start = SEC_CTX_INIT,
4766 .mos_opc_end = SEC_LAST_OPC,
4767 .mos_hs = mdt_sec_ctx_ops
4774 static struct mdt_handler mdt_readpage_ops[] = {
4775 DEF_MDT_HNDL_F(0, CONNECT, mdt_connect),
4776 DEF_MDT_HNDL_F(HABEO_CORPUS|HABEO_REFERO, READPAGE, mdt_readpage),
4777 #ifdef HAVE_SPLIT_SUPPORT
4778 DEF_MDT_HNDL_F(HABEO_CORPUS|HABEO_REFERO, WRITEPAGE, mdt_writepage),
4782 * XXX: this is ugly and should be fixed one day, see mdc_close() for
4783 * detailed comments. --umka
4785 DEF_MDT_HNDL_F(HABEO_CORPUS, CLOSE, mdt_close),
4786 DEF_MDT_HNDL_F(HABEO_CORPUS, DONE_WRITING, mdt_done_writing),
4789 static struct mdt_opc_slice mdt_readpage_handlers[] = {
4791 .mos_opc_start = MDS_GETATTR,
4792 .mos_opc_end = MDS_LAST_OPC,
4793 .mos_hs = mdt_readpage_ops
4800 static struct mdt_handler mdt_xmds_ops[] = {
4801 DEF_MDT_HNDL_F(0, CONNECT, mdt_connect),
4802 DEF_MDT_HNDL_F(HABEO_CORPUS , GETATTR, mdt_getattr),
4803 DEF_MDT_HNDL_F(0 | MUTABOR , REINT, mdt_reint),
4804 DEF_MDT_HNDL_F(HABEO_CORPUS|HABEO_REFERO, IS_SUBDIR, mdt_is_subdir),
4807 static struct mdt_opc_slice mdt_xmds_handlers[] = {
4809 .mos_opc_start = MDS_GETATTR,
4810 .mos_opc_end = MDS_LAST_OPC,
4811 .mos_hs = mdt_xmds_ops
4814 .mos_opc_start = OBD_PING,
4815 .mos_opc_end = OBD_LAST_OPC,
4816 .mos_hs = mdt_obd_ops
4823 static struct mdt_handler mdt_seq_ops[] = {
4824 DEF_SEQ_HNDL_F(0, QUERY, (int (*)(struct mdt_thread_info *))seq_query)
4827 static struct mdt_opc_slice mdt_seq_handlers[] = {
4829 .mos_opc_start = SEQ_QUERY,
4830 .mos_opc_end = SEQ_LAST_OPC,
4831 .mos_hs = mdt_seq_ops
4838 static struct mdt_handler mdt_fld_ops[] = {
4839 DEF_FLD_HNDL_F(0, QUERY, (int (*)(struct mdt_thread_info *))fld_query)
4842 static struct mdt_opc_slice mdt_fld_handlers[] = {
4844 .mos_opc_start = FLD_QUERY,
4845 .mos_opc_end = FLD_LAST_OPC,
4846 .mos_hs = mdt_fld_ops
4853 MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
4854 MODULE_DESCRIPTION("Lustre Meta-data Target ("LUSTRE_MDT_NAME")");
4855 MODULE_LICENSE("GPL");
4857 CFS_MODULE_PARM(mdt_num_threads, "ul", ulong, 0444,
4858 "number of mdt service threads to start");
4860 cfs_module(mdt, "0.2.0", mdt_mod_init, mdt_mod_exit);