1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 only,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License version 2 for more details (a copy is included
16 * in the LICENSE file that accompanied this code).
18 * You should have received a copy of the GNU General Public License
19 * version 2 along with this program; If not, see
20 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
29 * Copyright 2008 Sun Microsystems, Inc. All rights reserved
30 * Use is subject to license terms.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * lustre/mdt/mdt_handler.c
38 * Lustre Metadata Target (mdt) request handler
40 * Author: Peter Braam <braam@clusterfs.com>
41 * Author: Andreas Dilger <adilger@clusterfs.com>
42 * Author: Phil Schwan <phil@clusterfs.com>
43 * Author: Mike Shaver <shaver@clusterfs.com>
44 * Author: Nikita Danilov <nikita@clusterfs.com>
45 * Author: Huang Hua <huanghua@clusterfs.com>
46 * Author: Yury Umanets <umka@clusterfs.com>
50 # define EXPORT_SYMTAB
52 #define DEBUG_SUBSYSTEM S_MDS
54 #include <linux/module.h>
56 * struct OBD_{ALLOC,FREE}*()
58 #include <obd_support.h>
59 /* struct ptlrpc_request */
60 #include <lustre_net.h>
61 /* struct obd_export */
62 #include <lustre_export.h>
63 /* struct obd_device */
66 #include <dt_object.h>
67 #include <lustre_mds.h>
68 #include <lustre_mdt.h>
69 #include "mdt_internal.h"
70 #include <lustre_acl.h>
71 #include <lustre_param.h>
73 mdl_mode_t mdt_mdl_lock_modes[] = {
74 [LCK_MINMODE] = MDL_MINMODE,
81 [LCK_GROUP] = MDL_GROUP
84 ldlm_mode_t mdt_dlm_lock_modes[] = {
85 [MDL_MINMODE] = LCK_MINMODE,
92 [MDL_GROUP] = LCK_GROUP
96 * Initialized in mdt_mod_init().
98 unsigned long mdt_num_threads;
100 /* ptlrpc request handler for MDT. All handlers are
101 * grouped into several slices - struct mdt_opc_slice,
102 * and stored in an array - mdt_handlers[].
105 /* The name of this handler. */
107 /* Fail id for this handler, checked at the beginning of this handler*/
109 /* Operation code for this handler */
111 /* flags are listed in enum mdt_handler_flags below. */
113 /* The actual handler function to execute. */
114 int (*mh_act)(struct mdt_thread_info *info);
115 /* Request format for this request. */
116 const struct req_format *mh_fmt;
119 enum mdt_handler_flags {
121 * struct mdt_body is passed in the incoming message, and object
122 * identified by this fid exists on disk.
124 * "habeo corpus" == "I have a body"
126 HABEO_CORPUS = (1 << 0),
128 * struct ldlm_request is passed in the incoming message.
130 * "habeo clavis" == "I have a key"
132 HABEO_CLAVIS = (1 << 1),
134 * this request has fixed reply format, so that reply message can be
135 * packed by generic code.
137 * "habeo refero" == "I have a reply"
139 HABEO_REFERO = (1 << 2),
141 * this request will modify something, so check whether the filesystem
142 * is readonly or not, then return -EROFS to client asap if necessary.
144 * "mutabor" == "I shall modify"
149 struct mdt_opc_slice {
152 struct mdt_handler *mos_hs;
155 static struct mdt_opc_slice mdt_regular_handlers[];
156 static struct mdt_opc_slice mdt_readpage_handlers[];
157 static struct mdt_opc_slice mdt_xmds_handlers[];
158 static struct mdt_opc_slice mdt_seq_handlers[];
159 static struct mdt_opc_slice mdt_fld_handlers[];
161 static struct mdt_device *mdt_dev(struct lu_device *d);
162 static int mdt_regular_handle(struct ptlrpc_request *req);
163 static int mdt_unpack_req_pack_rep(struct mdt_thread_info *info, __u32 flags);
165 static struct lu_object_operations mdt_obj_ops;
167 int mdt_get_disposition(struct ldlm_reply *rep, int flag)
171 return (rep->lock_policy_res1 & flag);
174 void mdt_clear_disposition(struct mdt_thread_info *info,
175 struct ldlm_reply *rep, int flag)
178 info->mti_opdata &= ~flag;
180 rep->lock_policy_res1 &= ~flag;
183 void mdt_set_disposition(struct mdt_thread_info *info,
184 struct ldlm_reply *rep, int flag)
187 info->mti_opdata |= flag;
189 rep->lock_policy_res1 |= flag;
192 void mdt_lock_reg_init(struct mdt_lock_handle *lh, ldlm_mode_t lm)
194 lh->mlh_pdo_hash = 0;
195 lh->mlh_reg_mode = lm;
196 lh->mlh_type = MDT_REG_LOCK;
199 void mdt_lock_pdo_init(struct mdt_lock_handle *lh, ldlm_mode_t lm,
200 const char *name, int namelen)
202 lh->mlh_reg_mode = lm;
203 lh->mlh_type = MDT_PDO_LOCK;
206 LASSERT(namelen > 0);
207 lh->mlh_pdo_hash = full_name_hash(name, namelen);
209 LASSERT(namelen == 0);
210 lh->mlh_pdo_hash = 0ull;
214 static void mdt_lock_pdo_mode(struct mdt_thread_info *info, struct mdt_object *o,
215 struct mdt_lock_handle *lh)
221 * Any dir access needs couple of locks:
223 * 1) on part of dir we gonna take lookup/modify;
225 * 2) on whole dir to protect it from concurrent splitting and/or to
226 * flush client's cache for readdir().
228 * so, for a given mode and object this routine decides what lock mode
229 * to use for lock #2:
231 * 1) if caller's gonna lookup in dir then we need to protect dir from
232 * being splitted only - LCK_CR
234 * 2) if caller's gonna modify dir then we need to protect dir from
235 * being splitted and to flush cache - LCK_CW
237 * 3) if caller's gonna modify dir and that dir seems ready for
238 * splitting then we need to protect it from any type of access
239 * (lookup/modify/split) - LCK_EX --bzzz
242 LASSERT(lh->mlh_reg_mode != LCK_MINMODE);
243 LASSERT(lh->mlh_pdo_mode == LCK_MINMODE);
246 * Ask underlaying level its opinion about preferable PDO lock mode
247 * having access type passed as regular lock mode:
249 * - MDL_MINMODE means that lower layer does not want to specify lock
252 * - MDL_NL means that no PDO lock should be taken. This is used in some
253 * cases. Say, for non-splittable directories no need to use PDO locks
256 mode = mdo_lock_mode(info->mti_env, mdt_object_child(o),
257 mdt_dlm_mode2mdl_mode(lh->mlh_reg_mode));
259 if (mode != MDL_MINMODE) {
260 lh->mlh_pdo_mode = mdt_mdl_mode2dlm_mode(mode);
263 * Lower layer does not want to specify locking mode. We do it
264 * our selves. No special protection is needed, just flush
265 * client's cache on modification and allow concurrent
268 switch (lh->mlh_reg_mode) {
270 lh->mlh_pdo_mode = LCK_EX;
273 lh->mlh_pdo_mode = LCK_CR;
276 lh->mlh_pdo_mode = LCK_CW;
279 CERROR("Not expected lock type (0x%x)\n",
280 (int)lh->mlh_reg_mode);
285 LASSERT(lh->mlh_pdo_mode != LCK_MINMODE);
289 static int mdt_getstatus(struct mdt_thread_info *info)
291 struct mdt_device *mdt = info->mti_mdt;
292 struct md_device *next = mdt->mdt_child;
293 struct mdt_body *repbody;
298 rc = mdt_check_ucred(info);
300 RETURN(err_serious(rc));
302 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_GETSTATUS_PACK))
303 RETURN(err_serious(-ENOMEM));
305 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
306 rc = next->md_ops->mdo_root_get(info->mti_env, next, &repbody->fid1);
310 repbody->valid |= OBD_MD_FLID;
312 if (mdt->mdt_opts.mo_mds_capa) {
313 struct mdt_object *root;
314 struct lustre_capa *capa;
316 root = mdt_object_find(info->mti_env, mdt, &repbody->fid1);
318 RETURN(PTR_ERR(root));
320 capa = req_capsule_server_get(info->mti_pill, &RMF_CAPA1);
322 capa->lc_opc = CAPA_OPC_MDS_DEFAULT;
324 rc = mo_capa_get(info->mti_env, mdt_object_child(root), capa,
326 mdt_object_put(info->mti_env, root);
328 repbody->valid |= OBD_MD_FLMDSCAPA;
334 static int mdt_statfs(struct mdt_thread_info *info)
336 struct md_device *next = info->mti_mdt->mdt_child;
337 struct ptlrpc_service *svc;
338 struct obd_statfs *osfs;
343 svc = info->mti_pill->rc_req->rq_rqbd->rqbd_service;
345 /* This will trigger a watchdog timeout */
346 OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_STATFS_LCW_SLEEP,
347 (MDT_SERVICE_WATCHDOG_FACTOR *
348 at_get(&svc->srv_at_estimate) / 1000) + 1);
350 rc = mdt_check_ucred(info);
352 RETURN(err_serious(rc));
354 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_STATFS_PACK)) {
355 rc = err_serious(-ENOMEM);
357 osfs = req_capsule_server_get(info->mti_pill, &RMF_OBD_STATFS);
358 rc = next->md_ops->mdo_statfs(info->mti_env, next,
360 statfs_pack(osfs, &info->mti_u.ksfs);
365 void mdt_pack_size2body(struct mdt_thread_info *info, struct mdt_object *o)
368 struct lu_attr *attr = &info->mti_attr.ma_attr;
370 b = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
372 /* Check if Size-on-MDS is enabled. */
373 if ((mdt_conn_flags(info) & OBD_CONNECT_SOM) &&
374 S_ISREG(attr->la_mode) && mdt_sizeonmds_enabled(o)) {
375 b->valid |= (OBD_MD_FLSIZE | OBD_MD_FLBLOCKS);
376 b->size = attr->la_size;
377 b->blocks = attr->la_blocks;
381 void mdt_pack_attr2body(struct mdt_thread_info *info, struct mdt_body *b,
382 const struct lu_attr *attr, const struct lu_fid *fid)
384 /*XXX should pack the reply body according to lu_valid*/
385 b->valid |= OBD_MD_FLCTIME | OBD_MD_FLUID |
386 OBD_MD_FLGID | OBD_MD_FLTYPE |
387 OBD_MD_FLMODE | OBD_MD_FLNLINK | OBD_MD_FLFLAGS |
388 OBD_MD_FLATIME | OBD_MD_FLMTIME ;
390 if (!S_ISREG(attr->la_mode))
391 b->valid |= OBD_MD_FLSIZE | OBD_MD_FLBLOCKS | OBD_MD_FLRDEV;
393 b->atime = attr->la_atime;
394 b->mtime = attr->la_mtime;
395 b->ctime = attr->la_ctime;
396 b->mode = attr->la_mode;
397 b->size = attr->la_size;
398 b->blocks = attr->la_blocks;
399 b->uid = attr->la_uid;
400 b->gid = attr->la_gid;
401 b->flags = attr->la_flags;
402 b->nlink = attr->la_nlink;
403 b->rdev = attr->la_rdev;
407 b->valid |= OBD_MD_FLID;
409 /* FIXME: these should be fixed when new igif ready.*/
410 b->ino = fid_oid(fid); /* 1.6 compatibility */
411 b->generation = fid_ver(fid); /* 1.6 compatibility */
412 b->valid |= OBD_MD_FLGENER; /* 1.6 compatibility */
414 CDEBUG(D_INODE, DFID": nlink=%d, mode=%o, size="LPU64"\n",
415 PFID(fid), b->nlink, b->mode, b->size);
419 mdt_body_reverse_idmap(info, b);
422 static inline int mdt_body_has_lov(const struct lu_attr *la,
423 const struct mdt_body *body)
425 return ((S_ISREG(la->la_mode) && (body->valid & OBD_MD_FLEASIZE)) ||
426 (S_ISDIR(la->la_mode) && (body->valid & OBD_MD_FLDIREA )) );
429 static int mdt_getattr_internal(struct mdt_thread_info *info,
430 struct mdt_object *o)
432 struct md_object *next = mdt_object_child(o);
433 const struct mdt_body *reqbody = info->mti_body;
434 struct ptlrpc_request *req = mdt_info_req(info);
435 struct mdt_export_data *med = &req->rq_export->exp_mdt_data;
436 struct md_attr *ma = &info->mti_attr;
437 struct lu_attr *la = &ma->ma_attr;
438 struct req_capsule *pill = info->mti_pill;
439 const struct lu_env *env = info->mti_env;
440 struct mdt_body *repbody;
441 struct lu_buf *buffer = &info->mti_buf;
445 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_GETATTR_PACK))
446 RETURN(err_serious(-ENOMEM));
448 repbody = req_capsule_server_get(pill, &RMF_MDT_BODY);
452 rc = mdt_object_exists(o);
454 /* This object is located on remote node.*/
455 repbody->fid1 = *mdt_object_fid(o);
456 repbody->valid = OBD_MD_FLID | OBD_MD_MDS;
460 buffer->lb_buf = req_capsule_server_get(pill, &RMF_MDT_MD);
461 buffer->lb_len = req_capsule_get_size(pill, &RMF_MDT_MD, RCL_SERVER);
463 /* If it is dir object and client require MEA, then we got MEA */
464 if (S_ISDIR(lu_object_attr(&next->mo_lu)) &&
465 reqbody->valid & OBD_MD_MEA) {
466 /* Assumption: MDT_MD size is enough for lmv size. */
467 ma->ma_lmv = buffer->lb_buf;
468 ma->ma_lmv_size = buffer->lb_len;
469 ma->ma_need = MA_LMV | MA_INODE;
471 ma->ma_lmm = buffer->lb_buf;
472 ma->ma_lmm_size = buffer->lb_len;
473 ma->ma_need = MA_LOV | MA_INODE;
476 if (S_ISDIR(lu_object_attr(&next->mo_lu)) &&
477 reqbody->valid & OBD_MD_FLDIREA &&
478 lustre_msg_get_opc(req->rq_reqmsg) == MDS_GETATTR) {
479 /* get default stripe info for this dir. */
480 ma->ma_need |= MA_LOV_DEF;
482 rc = mo_attr_get(env, next, ma);
484 CERROR("getattr error for "DFID": %d\n",
485 PFID(mdt_object_fid(o)), rc);
489 if (likely(ma->ma_valid & MA_INODE))
490 mdt_pack_attr2body(info, repbody, la, mdt_object_fid(o));
494 if (mdt_body_has_lov(la, reqbody)) {
495 if (ma->ma_valid & MA_LOV) {
496 LASSERT(ma->ma_lmm_size);
497 mdt_dump_lmm(D_INFO, ma->ma_lmm);
498 repbody->eadatasize = ma->ma_lmm_size;
499 if (S_ISDIR(la->la_mode))
500 repbody->valid |= OBD_MD_FLDIREA;
502 repbody->valid |= OBD_MD_FLEASIZE;
504 if (ma->ma_valid & MA_LMV) {
505 LASSERT(S_ISDIR(la->la_mode));
506 repbody->eadatasize = ma->ma_lmv_size;
507 repbody->valid |= (OBD_MD_FLDIREA|OBD_MD_MEA);
509 if (!(ma->ma_valid & MA_LOV) && !(ma->ma_valid & MA_LMV)) {
510 repbody->valid |= OBD_MD_FLSIZE | OBD_MD_FLBLOCKS;
512 } else if (S_ISLNK(la->la_mode) &&
513 reqbody->valid & OBD_MD_LINKNAME) {
514 buffer->lb_buf = ma->ma_lmm;
515 buffer->lb_len = reqbody->eadatasize;
516 rc = mo_readlink(env, next, buffer);
517 if (unlikely(rc <= 0)) {
518 CERROR("readlink failed: %d\n", rc);
521 repbody->valid |= OBD_MD_LINKNAME;
522 repbody->eadatasize = rc;
524 ((char*)ma->ma_lmm)[rc - 1] = 0;
525 CDEBUG(D_INODE, "symlink dest %s, len = %d\n",
526 (char*)ma->ma_lmm, rc);
531 if (reqbody->valid & OBD_MD_FLMODEASIZE) {
532 repbody->max_cookiesize = info->mti_mdt->mdt_max_cookiesize;
533 repbody->max_mdsize = info->mti_mdt->mdt_max_mdsize;
534 repbody->valid |= OBD_MD_FLMODEASIZE;
535 CDEBUG(D_INODE, "I am going to change the MAX_MD_SIZE & "
536 "MAX_COOKIE to : %d:%d\n", repbody->max_mdsize,
537 repbody->max_cookiesize);
540 if (med->med_rmtclient && (reqbody->valid & OBD_MD_FLRMTPERM)) {
541 void *buf = req_capsule_server_get(pill, &RMF_ACL);
543 /* mdt_getattr_lock only */
544 rc = mdt_pack_remote_perm(info, o, buf);
546 repbody->valid &= ~OBD_MD_FLRMTPERM;
547 repbody->aclsize = 0;
550 repbody->valid |= OBD_MD_FLRMTPERM;
551 repbody->aclsize = sizeof(struct mdt_remote_perm);
554 #ifdef CONFIG_FS_POSIX_ACL
555 else if ((req->rq_export->exp_connect_flags & OBD_CONNECT_ACL) &&
556 (reqbody->valid & OBD_MD_FLACL)) {
557 buffer->lb_buf = req_capsule_server_get(pill, &RMF_ACL);
558 buffer->lb_len = req_capsule_get_size(pill,
559 &RMF_ACL, RCL_SERVER);
560 if (buffer->lb_len > 0) {
561 rc = mo_xattr_get(env, next, buffer,
562 XATTR_NAME_ACL_ACCESS);
564 if (rc == -ENODATA) {
565 repbody->aclsize = 0;
566 repbody->valid |= OBD_MD_FLACL;
568 } else if (rc == -EOPNOTSUPP) {
571 CERROR("got acl size: %d\n", rc);
574 repbody->aclsize = rc;
575 repbody->valid |= OBD_MD_FLACL;
582 if ((reqbody->valid & OBD_MD_FLMDSCAPA) &&
583 info->mti_mdt->mdt_opts.mo_mds_capa) {
584 struct lustre_capa *capa;
586 capa = req_capsule_server_get(pill, &RMF_CAPA1);
588 capa->lc_opc = CAPA_OPC_MDS_DEFAULT;
589 rc = mo_capa_get(env, next, capa, 0);
592 repbody->valid |= OBD_MD_FLMDSCAPA;
597 static int mdt_renew_capa(struct mdt_thread_info *info)
599 struct mdt_device *mdt = info->mti_mdt;
600 struct mdt_object *obj = info->mti_object;
601 struct mdt_body *body;
602 struct lustre_capa *capa, *c;
606 /* if object doesn't exist, or server has disabled capability,
607 * return directly, client will find body->valid OBD_MD_FLOSSCAPA
610 if (!obj || !mdt->mdt_opts.mo_mds_capa)
613 body = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
614 LASSERT(body != NULL);
616 c = req_capsule_client_get(info->mti_pill, &RMF_CAPA1);
619 capa = req_capsule_server_get(info->mti_pill, &RMF_CAPA2);
623 rc = mo_capa_get(info->mti_env, mdt_object_child(obj), capa, 1);
625 body->valid |= OBD_MD_FLOSSCAPA;
629 static int mdt_getattr(struct mdt_thread_info *info)
631 struct mdt_object *obj = info->mti_object;
632 struct req_capsule *pill = info->mti_pill;
633 struct mdt_body *reqbody;
634 struct mdt_body *repbody;
640 reqbody = req_capsule_client_get(pill, &RMF_MDT_BODY);
643 if (reqbody->valid & OBD_MD_FLOSSCAPA) {
644 rc = req_capsule_server_pack(pill);
646 RETURN(err_serious(rc));
647 rc = mdt_renew_capa(info);
648 GOTO(out_shrink, rc);
651 LASSERT(obj != NULL);
652 LASSERT(lu_object_assert_exists(&obj->mot_obj.mo_lu));
654 mode = lu_object_attr(&obj->mot_obj.mo_lu);
655 if (S_ISLNK(mode) && (reqbody->valid & OBD_MD_LINKNAME) &&
656 (reqbody->eadatasize > info->mti_mdt->mdt_max_mdsize))
657 md_size = reqbody->eadatasize;
659 md_size = info->mti_mdt->mdt_max_mdsize;
661 req_capsule_set_size(pill, &RMF_MDT_MD, RCL_SERVER, md_size);
663 rc = req_capsule_server_pack(pill);
664 if (unlikely(rc != 0))
665 RETURN(err_serious(rc));
667 repbody = req_capsule_server_get(pill, &RMF_MDT_BODY);
668 LASSERT(repbody != NULL);
669 repbody->eadatasize = 0;
670 repbody->aclsize = 0;
672 if (reqbody->valid & OBD_MD_FLRMTPERM)
673 rc = mdt_init_ucred(info, reqbody);
675 rc = mdt_check_ucred(info);
677 GOTO(out_shrink, rc);
679 info->mti_spec.sp_ck_split = !!(reqbody->valid & OBD_MD_FLCKSPLIT);
680 info->mti_cross_ref = !!(reqbody->valid & OBD_MD_FLCROSSREF);
683 * Don't check capability at all, because rename might getattr for
684 * remote obj, and at that time no capability is available.
686 mdt_set_capainfo(info, 1, &reqbody->fid1, BYPASS_CAPA);
687 rc = mdt_getattr_internal(info, obj);
688 if (reqbody->valid & OBD_MD_FLRMTPERM)
689 mdt_exit_ucred(info);
692 mdt_shrink_reply(info);
696 static int mdt_is_subdir(struct mdt_thread_info *info)
698 struct mdt_object *o = info->mti_object;
699 struct req_capsule *pill = info->mti_pill;
700 const struct mdt_body *body = info->mti_body;
701 struct mdt_body *repbody;
707 repbody = req_capsule_server_get(pill, &RMF_MDT_BODY);
710 * We save last checked parent fid to @repbody->fid1 for remote
713 LASSERT(fid_is_sane(&body->fid2));
714 LASSERT(mdt_object_exists(o) > 0);
715 rc = mdo_is_subdir(info->mti_env, mdt_object_child(o),
716 &body->fid2, &repbody->fid1);
717 if (rc == 0 || rc == -EREMOTE)
718 repbody->valid |= OBD_MD_FLID;
723 static int mdt_raw_lookup(struct mdt_thread_info *info,
724 struct mdt_object *parent,
725 const struct lu_name *lname,
726 struct ldlm_reply *ldlm_rep)
728 struct md_object *next = mdt_object_child(info->mti_object);
729 const struct mdt_body *reqbody = info->mti_body;
730 struct lu_fid *child_fid = &info->mti_tmp_fid1;
731 struct mdt_body *repbody;
735 if (reqbody->valid != OBD_MD_FLID)
738 LASSERT(!info->mti_cross_ref);
740 /* Only got the fid of this obj by name */
741 rc = mdo_lookup(info->mti_env, next, lname, child_fid,
744 /* XXX is raw_lookup possible as intent operation? */
747 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_NEG);
750 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_POS);
752 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
755 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
756 repbody->fid1 = *child_fid;
757 repbody->valid = OBD_MD_FLID;
763 * UPDATE lock should be taken against parent, and be release before exit;
764 * child_bits lock should be taken against child, and be returned back:
765 * (1)normal request should release the child lock;
766 * (2)intent request will grant the lock to client.
768 static int mdt_getattr_name_lock(struct mdt_thread_info *info,
769 struct mdt_lock_handle *lhc,
771 struct ldlm_reply *ldlm_rep)
773 struct ptlrpc_request *req = mdt_info_req(info);
774 struct mdt_body *reqbody = NULL;
775 struct mdt_object *parent = info->mti_object;
776 struct mdt_object *child;
777 struct md_object *next = mdt_object_child(parent);
778 struct lu_fid *child_fid = &info->mti_tmp_fid1;
779 struct lu_name *lname = NULL;
782 struct mdt_lock_handle *lhp;
783 struct ldlm_lock *lock;
784 struct ldlm_res_id *res_id;
790 is_resent = lustre_handle_is_used(&lhc->mlh_reg_lh);
791 LASSERT(ergo(is_resent,
792 lustre_msg_get_flags(req->rq_reqmsg) & MSG_RESENT));
794 LASSERT(parent != NULL);
795 name = req_capsule_client_get(info->mti_pill, &RMF_NAME);
797 RETURN(err_serious(-EFAULT));
799 namelen = req_capsule_get_size(info->mti_pill, &RMF_NAME,
801 LASSERT(namelen >= 0);
803 /* XXX: "namelen == 0" is for getattr by fid (OBD_CONNECT_ATTRFID),
804 * otherwise do not allow empty name, that is the name must contain
805 * at least one character and the terminating '\0'*/
807 reqbody =req_capsule_client_get(info->mti_pill, &RMF_MDT_BODY);
808 LASSERT(fid_is_sane(&reqbody->fid2));
811 CDEBUG(D_INODE, "getattr with lock for "DFID"/"DFID", "
813 PFID(mdt_object_fid(parent)), PFID(&reqbody->fid2),
816 lname = mdt_name(info->mti_env, (char *)name, namelen);
817 CDEBUG(D_INODE, "getattr with lock for "DFID"/%s, "
819 PFID(mdt_object_fid(parent)), name, ldlm_rep);
822 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_EXECD);
824 rc = mdt_object_exists(parent);
825 if (unlikely(rc == 0)) {
826 LU_OBJECT_DEBUG(D_WARNING, info->mti_env,
827 &parent->mot_obj.mo_lu,
828 "Parent doesn't exist!\n");
831 LASSERTF(rc > 0, "Parent "DFID" is on remote server\n",
832 PFID(mdt_object_fid(parent)));
835 rc = mdt_raw_lookup(info, parent, lname, ldlm_rep);
843 if (info->mti_cross_ref) {
844 /* Only getattr on the child. Parent is on another node. */
845 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_POS);
847 CDEBUG(D_INODE, "partial getattr_name child_fid = "DFID", "
848 "ldlm_rep=%p\n", PFID(mdt_object_fid(child)), ldlm_rep);
851 /* Do not take lock for resent case. */
852 lock = ldlm_handle2lock(&lhc->mlh_reg_lh);
853 LASSERTF(lock != NULL, "Invalid lock handle "LPX64"\n",
854 lhc->mlh_reg_lh.cookie);
855 LASSERT(fid_res_name_eq(mdt_object_fid(child),
856 &lock->l_resource->lr_name));
860 mdt_lock_handle_init(lhc);
861 mdt_lock_reg_init(lhc, LCK_PR);
864 * Object's name is on another MDS, no lookup lock is
865 * needed here but update is.
867 child_bits &= ~MDS_INODELOCK_LOOKUP;
868 child_bits |= MDS_INODELOCK_UPDATE;
870 rc = mdt_object_lock(info, child, lhc, child_bits,
874 /* Finally, we can get attr for child. */
875 mdt_set_capainfo(info, 0, mdt_object_fid(child),
877 rc = mdt_getattr_internal(info, child);
878 if (unlikely(rc != 0))
879 mdt_object_unlock(info, child, lhc, 1);
884 /* step 1: lock parent */
885 lhp = &info->mti_lh[MDT_LH_PARENT];
886 mdt_lock_pdo_init(lhp, LCK_PR, name, namelen);
887 rc = mdt_object_lock(info, parent, lhp, MDS_INODELOCK_UPDATE,
890 if (unlikely(rc != 0))
894 /* step 2: lookup child's fid by name */
895 rc = mdo_lookup(info->mti_env, next, lname, child_fid,
900 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_NEG);
901 GOTO(out_parent, rc);
903 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_POS);
905 *child_fid = reqbody->fid2;
906 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_POS);
910 *step 3: find the child object by fid & lock it.
911 * regardless if it is local or remote.
913 child = mdt_object_find(info->mti_env, info->mti_mdt, child_fid);
915 if (unlikely(IS_ERR(child)))
916 GOTO(out_parent, rc = PTR_ERR(child));
918 /* Do not take lock for resent case. */
919 lock = ldlm_handle2lock(&lhc->mlh_reg_lh);
920 LASSERTF(lock != NULL, "Invalid lock handle "LPX64"\n",
921 lhc->mlh_reg_lh.cookie);
923 res_id = &lock->l_resource->lr_name;
924 if (!fid_res_name_eq(mdt_object_fid(child),
925 &lock->l_resource->lr_name)) {
926 LASSERTF(fid_res_name_eq(mdt_object_fid(parent),
927 &lock->l_resource->lr_name),
928 "Lock res_id: %lu/%lu/%lu, Fid: "DFID".\n",
929 (unsigned long)res_id->name[0],
930 (unsigned long)res_id->name[1],
931 (unsigned long)res_id->name[2],
932 PFID(mdt_object_fid(parent)));
933 CWARN("Although resent, but still not get child lock"
934 "parent:"DFID" child:"DFID"\n",
935 PFID(mdt_object_fid(parent)),
936 PFID(mdt_object_fid(child)));
937 lustre_msg_clear_flags(req->rq_reqmsg, MSG_RESENT);
946 ma = &info->mti_attr;
948 mdt_lock_handle_init(lhc);
949 mdt_lock_reg_init(lhc, LCK_PR);
951 if (mdt_object_exists(child) == 0) {
952 LU_OBJECT_DEBUG(D_WARNING, info->mti_env,
953 &child->mot_obj.mo_lu,
954 "Object doesn't exist!\n");
955 GOTO(out_child, rc = -ESTALE);
959 ma->ma_need = MA_INODE;
960 rc = mo_attr_get(info->mti_env, next, ma);
961 if (unlikely(rc != 0))
964 /* If the file has not been changed for some time, we return
965 * not only a LOOKUP lock, but also an UPDATE lock and this
966 * might save us RPC on later STAT. For directories, it also
967 * let negative dentry starts working for this dir. */
968 if (ma->ma_valid & MA_INODE &&
969 ma->ma_attr.la_valid & LA_CTIME &&
970 info->mti_mdt->mdt_namespace->ns_ctime_age_limit +
971 ma->ma_attr.la_ctime < cfs_time_current_sec())
972 child_bits |= MDS_INODELOCK_UPDATE;
974 rc = mdt_object_lock(info, child, lhc, child_bits,
977 if (unlikely(rc != 0))
981 /* finally, we can get attr for child. */
982 mdt_set_capainfo(info, 1, child_fid, BYPASS_CAPA);
983 rc = mdt_getattr_internal(info, child);
984 if (unlikely(rc != 0)) {
985 mdt_object_unlock(info, child, lhc, 1);
987 lock = ldlm_handle2lock(&lhc->mlh_reg_lh);
989 struct mdt_body *repbody;
991 /* Debugging code. */
992 res_id = &lock->l_resource->lr_name;
993 LDLM_DEBUG(lock, "Returning lock to client\n");
994 LASSERTF(fid_res_name_eq(mdt_object_fid(child),
995 &lock->l_resource->lr_name),
996 "Lock res_id: %lu/%lu/%lu, Fid: "DFID".\n",
997 (unsigned long)res_id->name[0],
998 (unsigned long)res_id->name[1],
999 (unsigned long)res_id->name[2],
1000 PFID(mdt_object_fid(child)));
1002 * Pack Size-on-MDS inode attributes to the body if
1003 * update lock is given.
1005 repbody = req_capsule_server_get(info->mti_pill,
1007 if (lock->l_policy_data.l_inodebits.bits &
1008 MDS_INODELOCK_UPDATE)
1009 mdt_pack_size2body(info, child);
1010 LDLM_LOCK_PUT(lock);
1015 mdt_object_put(info->mti_env, child);
1017 mdt_object_unlock(info, parent, lhp, 1);
1021 /* normal handler: should release the child lock */
1022 static int mdt_getattr_name(struct mdt_thread_info *info)
1024 struct mdt_lock_handle *lhc = &info->mti_lh[MDT_LH_CHILD];
1025 struct mdt_body *reqbody;
1026 struct mdt_body *repbody;
1030 reqbody = req_capsule_client_get(info->mti_pill, &RMF_MDT_BODY);
1031 LASSERT(reqbody != NULL);
1032 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
1033 LASSERT(repbody != NULL);
1035 info->mti_spec.sp_ck_split = !!(reqbody->valid & OBD_MD_FLCKSPLIT);
1036 info->mti_cross_ref = !!(reqbody->valid & OBD_MD_FLCROSSREF);
1037 repbody->eadatasize = 0;
1038 repbody->aclsize = 0;
1040 rc = mdt_init_ucred(info, reqbody);
1042 GOTO(out_shrink, rc);
1044 rc = mdt_getattr_name_lock(info, lhc, MDS_INODELOCK_UPDATE, NULL);
1045 if (lustre_handle_is_used(&lhc->mlh_reg_lh)) {
1046 ldlm_lock_decref(&lhc->mlh_reg_lh, lhc->mlh_reg_mode);
1047 lhc->mlh_reg_lh.cookie = 0;
1049 mdt_exit_ucred(info);
1052 mdt_shrink_reply(info);
1056 static struct lu_device_operations mdt_lu_ops;
1058 static int lu_device_is_mdt(struct lu_device *d)
1060 return ergo(d != NULL && d->ld_ops != NULL, d->ld_ops == &mdt_lu_ops);
1063 static int mdt_set_info(struct mdt_thread_info *info)
1065 struct ptlrpc_request *req = mdt_info_req(info);
1071 rc = req_capsule_server_pack(info->mti_pill);
1075 key = req_capsule_client_get(info->mti_pill, &RMF_SETINFO_KEY);
1077 DEBUG_REQ(D_HA, req, "no set_info key");
1081 keylen = req_capsule_get_size(info->mti_pill, &RMF_SETINFO_KEY,
1084 val = req_capsule_client_get(info->mti_pill, &RMF_SETINFO_VAL);
1086 DEBUG_REQ(D_HA, req, "no set_info val");
1090 if (!KEY_IS(KEY_READ_ONLY))
1094 lustre_msg_set_status(req->rq_repmsg, 0);
1096 spin_lock(&req->rq_export->exp_lock);
1098 req->rq_export->exp_connect_flags |= OBD_CONNECT_RDONLY;
1100 req->rq_export->exp_connect_flags &= ~OBD_CONNECT_RDONLY;
1101 spin_unlock(&req->rq_export->exp_lock);
1106 static int mdt_connect(struct mdt_thread_info *info)
1109 struct ptlrpc_request *req;
1111 req = mdt_info_req(info);
1112 rc = target_handle_connect(req);
1114 LASSERT(req->rq_export != NULL);
1115 info->mti_mdt = mdt_dev(req->rq_export->exp_obd->obd_lu_dev);
1116 rc = mdt_init_idmap(info);
1118 /* if mdt_init_idmap failed, revocation for connect */
1119 obd_disconnect(class_export_get(req->rq_export));
1121 rc = err_serious(rc);
1125 static int mdt_disconnect(struct mdt_thread_info *info)
1130 rc = target_handle_disconnect(mdt_info_req(info));
1132 rc = err_serious(rc);
1136 static int mdt_sendpage(struct mdt_thread_info *info,
1137 struct lu_rdpg *rdpg)
1139 struct ptlrpc_request *req = mdt_info_req(info);
1140 struct ptlrpc_bulk_desc *desc;
1141 struct l_wait_info *lwi = &info->mti_u.rdpg.mti_wait_info;
1149 desc = ptlrpc_prep_bulk_exp(req, rdpg->rp_npages, BULK_PUT_SOURCE,
1154 for (i = 0, tmpcount = rdpg->rp_count;
1155 i < rdpg->rp_npages; i++, tmpcount -= tmpsize) {
1156 tmpsize = min_t(int, tmpcount, CFS_PAGE_SIZE);
1157 ptlrpc_prep_bulk_page(desc, rdpg->rp_pages[i], 0, tmpsize);
1160 LASSERT(desc->bd_nob == rdpg->rp_count);
1161 rc = ptlrpc_start_bulk_transfer(desc);
1163 GOTO(free_desc, rc);
1165 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_SENDPAGE))
1166 GOTO(abort_bulk, rc = 0);
1168 timeout = (int) req->rq_deadline - cfs_time_current_sec();
1170 CERROR("Req deadline already passed %lu (now: %lu)\n",
1171 req->rq_deadline, cfs_time_current_sec());
1172 *lwi = LWI_TIMEOUT(max(timeout, 1) * HZ, NULL, NULL);
1173 rc = l_wait_event(desc->bd_waitq, !ptlrpc_bulk_active(desc), lwi);
1174 LASSERT (rc == 0 || rc == -ETIMEDOUT);
1177 if (desc->bd_success &&
1178 desc->bd_nob_transferred == rdpg->rp_count)
1179 GOTO(free_desc, rc);
1181 rc = -ETIMEDOUT; /* XXX should this be a different errno? */
1184 DEBUG_REQ(D_ERROR, req, "bulk failed: %s %d(%d), evicting %s@%s",
1185 (rc == -ETIMEDOUT) ? "timeout" : "network error",
1186 desc->bd_nob_transferred, rdpg->rp_count,
1187 req->rq_export->exp_client_uuid.uuid,
1188 req->rq_export->exp_connection->c_remote_uuid.uuid);
1190 class_fail_export(req->rq_export);
1194 ptlrpc_abort_bulk(desc);
1196 ptlrpc_free_bulk(desc);
1200 #ifdef HAVE_SPLIT_SUPPORT
1202 * Retrieve dir entry from the page and insert it to the slave object, actually,
1203 * this should be in osd layer, but since it will not in the final product, so
1204 * just do it here and do not define more moo api anymore for this.
1206 static int mdt_write_dir_page(struct mdt_thread_info *info, struct page *page,
1209 struct mdt_object *object = info->mti_object;
1210 struct lu_fid *lf = &info->mti_tmp_fid2;
1211 struct md_attr *ma = &info->mti_attr;
1212 struct lu_dirpage *dp;
1213 struct lu_dirent *ent;
1214 int rc = 0, offset = 0;
1217 /* Make sure we have at least one entry. */
1222 * Disable trans for this name insert, since it will include many trans
1225 info->mti_no_need_trans = 1;
1227 * When write_dir_page, no need update parent's ctime,
1228 * and no permission check for name_insert.
1230 ma->ma_attr.la_ctime = 0;
1231 ma->ma_attr.la_valid = LA_MODE;
1232 ma->ma_valid = MA_INODE;
1235 dp = page_address(page);
1236 offset = (int)((__u32)lu_dirent_start(dp) - (__u32)dp);
1238 for (ent = lu_dirent_start(dp); ent != NULL;
1239 ent = lu_dirent_next(ent)) {
1240 struct lu_name *lname;
1243 if (le16_to_cpu(ent->lde_namelen) == 0)
1246 fid_le_to_cpu(lf, &ent->lde_fid);
1247 if (le32_to_cpu(ent->lde_hash) & MAX_HASH_HIGHEST_BIT)
1248 ma->ma_attr.la_mode = S_IFDIR;
1250 ma->ma_attr.la_mode = 0;
1251 OBD_ALLOC(name, le16_to_cpu(ent->lde_namelen) + 1);
1253 GOTO(out, rc = -ENOMEM);
1255 memcpy(name, ent->lde_name, le16_to_cpu(ent->lde_namelen));
1256 lname = mdt_name(info->mti_env, name,
1257 le16_to_cpu(ent->lde_namelen) + 1);
1258 ma->ma_attr_flags |= MDS_PERM_BYPASS;
1259 rc = mdo_name_insert(info->mti_env,
1260 md_object_next(&object->mot_obj),
1262 OBD_FREE(name, le16_to_cpu(ent->lde_namelen) + 1);
1264 CERROR("Can't insert %*.*s, rc %d\n",
1265 le16_to_cpu(ent->lde_namelen),
1266 le16_to_cpu(ent->lde_namelen),
1271 offset += lu_dirent_size(ent);
1281 static int mdt_bulk_timeout(void *data)
1285 CERROR("mdt bulk transfer timeout \n");
1290 static int mdt_writepage(struct mdt_thread_info *info)
1292 struct ptlrpc_request *req = mdt_info_req(info);
1293 struct mdt_body *reqbody;
1294 struct l_wait_info *lwi;
1295 struct ptlrpc_bulk_desc *desc;
1301 reqbody = req_capsule_client_get(info->mti_pill, &RMF_MDT_BODY);
1302 if (reqbody == NULL)
1303 RETURN(err_serious(-EFAULT));
1305 desc = ptlrpc_prep_bulk_exp(req, 1, BULK_GET_SINK, MDS_BULK_PORTAL);
1307 RETURN(err_serious(-ENOMEM));
1309 /* allocate the page for the desc */
1310 page = cfs_alloc_page(CFS_ALLOC_STD);
1312 GOTO(desc_cleanup, rc = -ENOMEM);
1314 CDEBUG(D_INFO, "Received page offset %d size %d \n",
1315 (int)reqbody->size, (int)reqbody->nlink);
1317 ptlrpc_prep_bulk_page(desc, page, (int)reqbody->size,
1318 (int)reqbody->nlink);
1321 * Check if client was evicted while we were doing i/o before touching
1326 GOTO(cleanup_page, rc = -ENOMEM);
1328 if (desc->bd_export->exp_failed)
1331 rc = ptlrpc_start_bulk_transfer (desc);
1333 *lwi = LWI_TIMEOUT_INTERVAL(obd_timeout * HZ / 4, HZ,
1334 mdt_bulk_timeout, desc);
1335 rc = l_wait_event(desc->bd_waitq, !ptlrpc_bulk_active(desc) ||
1336 desc->bd_export->exp_failed, lwi);
1337 LASSERT(rc == 0 || rc == -ETIMEDOUT);
1338 if (rc == -ETIMEDOUT) {
1339 DEBUG_REQ(D_ERROR, req, "timeout on bulk GET");
1340 ptlrpc_abort_bulk(desc);
1341 } else if (desc->bd_export->exp_failed) {
1342 DEBUG_REQ(D_ERROR, req, "Eviction on bulk GET");
1344 ptlrpc_abort_bulk(desc);
1345 } else if (!desc->bd_success ||
1346 desc->bd_nob_transferred != desc->bd_nob) {
1347 DEBUG_REQ(D_ERROR, req, "%s bulk GET %d(%d)",
1349 "truncated" : "network error on",
1350 desc->bd_nob_transferred, desc->bd_nob);
1351 /* XXX should this be a different errno? */
1355 DEBUG_REQ(D_ERROR, req, "ptlrpc_bulk_get failed: rc %d", rc);
1358 GOTO(cleanup_lwi, rc);
1359 rc = mdt_write_dir_page(info, page, reqbody->nlink);
1364 cfs_free_page(page);
1366 ptlrpc_free_bulk(desc);
1371 static int mdt_readpage(struct mdt_thread_info *info)
1373 struct mdt_object *object = info->mti_object;
1374 struct lu_rdpg *rdpg = &info->mti_u.rdpg.mti_rdpg;
1375 struct mdt_body *reqbody;
1376 struct mdt_body *repbody;
1381 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_READPAGE_PACK))
1382 RETURN(err_serious(-ENOMEM));
1384 reqbody = req_capsule_client_get(info->mti_pill, &RMF_MDT_BODY);
1385 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
1386 if (reqbody == NULL || repbody == NULL)
1387 RETURN(err_serious(-EFAULT));
1390 * prepare @rdpg before calling lower layers and transfer itself. Here
1391 * reqbody->size contains offset of where to start to read and
1392 * reqbody->nlink contains number bytes to read.
1394 rdpg->rp_hash = reqbody->size;
1395 if ((__u64)rdpg->rp_hash != reqbody->size) {
1396 CERROR("Invalid hash: %#llx != %#llx\n",
1397 (__u64)rdpg->rp_hash, reqbody->size);
1400 rdpg->rp_count = reqbody->nlink;
1401 rdpg->rp_npages = (rdpg->rp_count + CFS_PAGE_SIZE - 1)>>CFS_PAGE_SHIFT;
1402 OBD_ALLOC(rdpg->rp_pages, rdpg->rp_npages * sizeof rdpg->rp_pages[0]);
1403 if (rdpg->rp_pages == NULL)
1406 for (i = 0; i < rdpg->rp_npages; ++i) {
1407 rdpg->rp_pages[i] = cfs_alloc_page(CFS_ALLOC_STD);
1408 if (rdpg->rp_pages[i] == NULL)
1409 GOTO(free_rdpg, rc = -ENOMEM);
1412 /* call lower layers to fill allocated pages with directory data */
1413 rc = mo_readpage(info->mti_env, mdt_object_child(object), rdpg);
1415 GOTO(free_rdpg, rc);
1417 /* send pages to client */
1418 rc = mdt_sendpage(info, rdpg);
1423 for (i = 0; i < rdpg->rp_npages; i++)
1424 if (rdpg->rp_pages[i] != NULL)
1425 cfs_free_page(rdpg->rp_pages[i]);
1426 OBD_FREE(rdpg->rp_pages, rdpg->rp_npages * sizeof rdpg->rp_pages[0]);
1428 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_SENDPAGE))
1434 static int mdt_reint_internal(struct mdt_thread_info *info,
1435 struct mdt_lock_handle *lhc,
1438 struct req_capsule *pill = info->mti_pill;
1439 struct mdt_device *mdt = info->mti_mdt;
1440 struct mdt_body *repbody;
1445 if (req_capsule_has_field(pill, &RMF_MDT_MD, RCL_SERVER))
1446 req_capsule_set_size(pill, &RMF_MDT_MD, RCL_SERVER,
1447 mdt->mdt_max_mdsize);
1448 if (req_capsule_has_field(pill, &RMF_LOGCOOKIES, RCL_SERVER))
1449 req_capsule_set_size(pill, &RMF_LOGCOOKIES, RCL_SERVER,
1450 mdt->mdt_max_cookiesize);
1452 rc = req_capsule_server_pack(pill);
1454 CERROR("Can't pack response, rc %d\n", rc);
1455 RETURN(err_serious(rc));
1458 if (req_capsule_has_field(pill, &RMF_MDT_BODY, RCL_SERVER)) {
1459 repbody = req_capsule_server_get(pill, &RMF_MDT_BODY);
1461 repbody->eadatasize = 0;
1462 repbody->aclsize = 0;
1465 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_REINT_UNPACK))
1466 GOTO(out_shrink, rc = err_serious(-EFAULT));
1468 rc = mdt_reint_unpack(info, op);
1470 CERROR("Can't unpack reint, rc %d\n", rc);
1471 GOTO(out_shrink, rc = err_serious(rc));
1474 rc = mdt_init_ucred_reint(info);
1476 GOTO(out_shrink, rc);
1478 rc = mdt_fix_attr_ucred(info, op);
1480 GOTO(out_ucred, rc = err_serious(rc));
1482 if (mdt_check_resent(info, mdt_reconstruct, lhc)) {
1483 rc = lustre_msg_get_status(mdt_info_req(info)->rq_repmsg);
1484 GOTO(out_ucred, rc);
1486 rc = mdt_reint_rec(info, lhc);
1489 mdt_exit_ucred(info);
1491 mdt_shrink_reply(info);
1495 static long mdt_reint_opcode(struct mdt_thread_info *info,
1496 const struct req_format **fmt)
1498 struct mdt_rec_reint *rec;
1501 opc = err_serious(-EFAULT);
1502 rec = req_capsule_client_get(info->mti_pill, &RMF_REC_REINT);
1504 opc = rec->rr_opcode;
1505 DEBUG_REQ(D_INODE, mdt_info_req(info), "reint opt = %ld", opc);
1506 if (opc < REINT_MAX && fmt[opc] != NULL)
1507 req_capsule_extend(info->mti_pill, fmt[opc]);
1509 CERROR("Unsupported opc: %ld\n", opc);
1510 opc = err_serious(opc);
1516 static int mdt_reint(struct mdt_thread_info *info)
1521 static const struct req_format *reint_fmts[REINT_MAX] = {
1522 [REINT_SETATTR] = &RQF_MDS_REINT_SETATTR,
1523 [REINT_CREATE] = &RQF_MDS_REINT_CREATE,
1524 [REINT_LINK] = &RQF_MDS_REINT_LINK,
1525 [REINT_UNLINK] = &RQF_MDS_REINT_UNLINK,
1526 [REINT_RENAME] = &RQF_MDS_REINT_RENAME,
1527 [REINT_OPEN] = &RQF_MDS_REINT_OPEN,
1528 [REINT_SETXATTR] = &RQF_MDS_REINT_SETXATTR
1533 opc = mdt_reint_opcode(info, reint_fmts);
1536 * No lock possible here from client to pass it to reint code
1539 rc = mdt_reint_internal(info, NULL, opc);
1544 info->mti_fail_id = OBD_FAIL_MDS_REINT_NET_REP;
1548 /* TODO these two methods not available now. */
1550 /* this should sync the whole device */
1551 static int mdt_device_sync(struct mdt_thread_info *info)
1556 /* this should sync this object */
1557 static int mdt_object_sync(struct mdt_thread_info *info)
1562 static int mdt_sync(struct mdt_thread_info *info)
1564 struct req_capsule *pill = info->mti_pill;
1565 struct mdt_body *body;
1569 /* The fid may be zero, so we req_capsule_set manually */
1570 req_capsule_set(pill, &RQF_MDS_SYNC);
1572 body = req_capsule_client_get(pill, &RMF_MDT_BODY);
1574 RETURN(err_serious(-EINVAL));
1576 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_SYNC_PACK))
1577 RETURN(err_serious(-ENOMEM));
1579 if (fid_seq(&body->fid1) == 0) {
1580 /* sync the whole device */
1581 rc = req_capsule_server_pack(pill);
1583 rc = mdt_device_sync(info);
1585 rc = err_serious(rc);
1587 /* sync an object */
1588 rc = mdt_unpack_req_pack_rep(info, HABEO_CORPUS|HABEO_REFERO);
1590 rc = mdt_object_sync(info);
1592 struct md_object *next;
1593 const struct lu_fid *fid;
1594 struct lu_attr *la = &info->mti_attr.ma_attr;
1596 next = mdt_object_child(info->mti_object);
1597 info->mti_attr.ma_need = MA_INODE;
1598 info->mti_attr.ma_valid = 0;
1599 rc = mo_attr_get(info->mti_env, next,
1602 body = req_capsule_server_get(pill,
1604 fid = mdt_object_fid(info->mti_object);
1605 mdt_pack_attr2body(info, body, la, fid);
1609 rc = err_serious(rc);
1614 static int mdt_quotacheck_handle(struct mdt_thread_info *info)
1616 return err_serious(-EOPNOTSUPP);
1619 static int mdt_quotactl_handle(struct mdt_thread_info *info)
1621 return err_serious(-EOPNOTSUPP);
1625 * OBD PING and other handlers.
1627 static int mdt_obd_ping(struct mdt_thread_info *info)
1632 req_capsule_set(info->mti_pill, &RQF_OBD_PING);
1634 rc = target_handle_ping(mdt_info_req(info));
1636 rc = err_serious(rc);
1640 static int mdt_obd_log_cancel(struct mdt_thread_info *info)
1642 return err_serious(-EOPNOTSUPP);
1645 static int mdt_obd_qc_callback(struct mdt_thread_info *info)
1647 return err_serious(-EOPNOTSUPP);
1654 static struct ldlm_callback_suite cbs = {
1655 .lcs_completion = ldlm_server_completion_ast,
1656 .lcs_blocking = ldlm_server_blocking_ast,
1660 static int mdt_enqueue(struct mdt_thread_info *info)
1662 struct ptlrpc_request *req;
1667 * info->mti_dlm_req already contains swapped and (if necessary)
1668 * converted dlm request.
1670 LASSERT(info->mti_dlm_req != NULL);
1672 req = mdt_info_req(info);
1675 * Lock without inodebits makes no sense and will oops later in
1676 * ldlm. Let's check it now to see if we have wrong lock from client or
1677 * bits get corrupted somewhere in mdt_intent_policy().
1679 req_bits = info->mti_dlm_req->lock_desc.l_policy_data.l_inodebits.bits;
1680 /* This is disabled because we need to support liblustre flock.
1681 * LASSERT(req_bits != 0);
1684 rc = ldlm_handle_enqueue0(info->mti_mdt->mdt_namespace,
1685 req, info->mti_dlm_req, &cbs);
1686 info->mti_fail_id = OBD_FAIL_LDLM_REPLY;
1687 return rc ? err_serious(rc) : req->rq_status;
1690 static int mdt_convert(struct mdt_thread_info *info)
1693 struct ptlrpc_request *req;
1695 LASSERT(info->mti_dlm_req);
1696 req = mdt_info_req(info);
1697 rc = ldlm_handle_convert0(req, info->mti_dlm_req);
1698 return rc ? err_serious(rc) : req->rq_status;
1701 static int mdt_bl_callback(struct mdt_thread_info *info)
1703 CERROR("bl callbacks should not happen on MDS\n");
1705 return err_serious(-EOPNOTSUPP);
1708 static int mdt_cp_callback(struct mdt_thread_info *info)
1710 CERROR("cp callbacks should not happen on MDS\n");
1712 return err_serious(-EOPNOTSUPP);
1716 * sec context handlers
1718 static int mdt_sec_ctx_handle(struct mdt_thread_info *info)
1722 rc = mdt_handle_idmap(info);
1725 struct ptlrpc_request *req = mdt_info_req(info);
1728 opc = lustre_msg_get_opc(req->rq_reqmsg);
1729 if (opc == SEC_CTX_INIT || opc == SEC_CTX_INIT_CONT)
1730 sptlrpc_svc_ctx_invalidate(req);
1733 OBD_FAIL_TIMEOUT(OBD_FAIL_SEC_CTX_HDL_PAUSE, obd_fail_val);
1738 static struct mdt_object *mdt_obj(struct lu_object *o)
1740 LASSERT(lu_device_is_mdt(o->lo_dev));
1741 return container_of0(o, struct mdt_object, mot_obj.mo_lu);
1744 struct mdt_object *mdt_object_find(const struct lu_env *env,
1745 struct mdt_device *d,
1746 const struct lu_fid *f)
1748 struct lu_object *o;
1749 struct mdt_object *m;
1752 CDEBUG(D_INFO, "Find object for "DFID"\n", PFID(f));
1753 o = lu_object_find(env, d->mdt_md_dev.md_lu_dev.ld_site, f);
1754 if (unlikely(IS_ERR(o)))
1755 m = (struct mdt_object *)o;
1761 int mdt_object_lock(struct mdt_thread_info *info, struct mdt_object *o,
1762 struct mdt_lock_handle *lh, __u64 ibits, int locality)
1764 struct ldlm_namespace *ns = info->mti_mdt->mdt_namespace;
1765 ldlm_policy_data_t *policy = &info->mti_policy;
1766 struct ldlm_res_id *res_id = &info->mti_res_id;
1770 LASSERT(!lustre_handle_is_used(&lh->mlh_reg_lh));
1771 LASSERT(!lustre_handle_is_used(&lh->mlh_pdo_lh));
1772 LASSERT(lh->mlh_reg_mode != LCK_MINMODE);
1773 LASSERT(lh->mlh_type != MDT_NUL_LOCK);
1775 if (mdt_object_exists(o) < 0) {
1776 if (locality == MDT_CROSS_LOCK) {
1777 /* cross-ref object fix */
1778 ibits &= ~MDS_INODELOCK_UPDATE;
1779 ibits |= MDS_INODELOCK_LOOKUP;
1781 LASSERT(!(ibits & MDS_INODELOCK_UPDATE));
1782 LASSERT(ibits & MDS_INODELOCK_LOOKUP);
1784 /* No PDO lock on remote object */
1785 LASSERT(lh->mlh_type != MDT_PDO_LOCK);
1788 memset(policy, 0, sizeof(*policy));
1789 fid_build_reg_res_name(mdt_object_fid(o), res_id);
1792 * Take PDO lock on whole directory and build correct @res_id for lock
1793 * on part of directory.
1795 if (lh->mlh_pdo_hash != 0) {
1796 LASSERT(lh->mlh_type == MDT_PDO_LOCK);
1797 mdt_lock_pdo_mode(info, o, lh);
1798 if (lh->mlh_pdo_mode != LCK_NL) {
1800 * Do not use LDLM_FL_LOCAL_ONLY for parallel lock, it
1801 * is never going to be sent to client and we do not
1802 * want it slowed down due to possible cancels.
1804 policy->l_inodebits.bits = MDS_INODELOCK_UPDATE;
1805 rc = mdt_fid_lock(ns, &lh->mlh_pdo_lh, lh->mlh_pdo_mode,
1806 policy, res_id, LDLM_FL_ATOMIC_CB);
1812 * Finish res_id initializing by name hash marking patr of
1813 * directory which is taking modification.
1815 res_id->name[LUSTRE_RES_ID_HSH_OFF] = lh->mlh_pdo_hash;
1818 policy->l_inodebits.bits = ibits;
1821 * Use LDLM_FL_LOCAL_ONLY for this lock. We do not know yet if it is
1822 * going to be sent to client. If it is - mdt_intent_policy() path will
1823 * fix it up and turns FL_LOCAL flag off.
1825 rc = mdt_fid_lock(ns, &lh->mlh_reg_lh, lh->mlh_reg_mode, policy,
1826 res_id, LDLM_FL_LOCAL_ONLY | LDLM_FL_ATOMIC_CB);
1831 if (lh->mlh_type == MDT_PDO_LOCK) {
1832 /* check for exists after object is locked */
1833 if (mdt_object_exists(o) == 0) {
1834 /* Non-existent object shouldn't have PDO lock */
1837 /* Non-dir object shouldn't have PDO lock */
1838 LASSERT(S_ISDIR(lu_object_attr(&o->mot_obj.mo_lu)));
1843 mdt_object_unlock(info, o, lh, 1);
1850 void mdt_save_lock(struct ptlrpc_request *req, struct lustre_handle *h,
1851 ldlm_mode_t mode, int decref)
1855 if (lustre_handle_is_used(h)) {
1857 mdt_fid_unlock(h, mode);
1859 ptlrpc_save_lock(req, h, mode);
1867 * Just call ldlm_lock_decref() if decref, else we only call ptlrpc_save_lock()
1868 * to save this lock in req. when transaction committed, req will be released,
1869 * and lock will, too.
1871 void mdt_object_unlock(struct mdt_thread_info *info, struct mdt_object *o,
1872 struct mdt_lock_handle *lh, int decref)
1874 struct ptlrpc_request *req = mdt_info_req(info);
1877 mdt_save_lock(req, &lh->mlh_pdo_lh, lh->mlh_pdo_mode, decref);
1878 mdt_save_lock(req, &lh->mlh_reg_lh, lh->mlh_reg_mode, decref);
1883 struct mdt_object *mdt_object_find_lock(struct mdt_thread_info *info,
1884 const struct lu_fid *f,
1885 struct mdt_lock_handle *lh,
1888 struct mdt_object *o;
1890 o = mdt_object_find(info->mti_env, info->mti_mdt, f);
1894 rc = mdt_object_lock(info, o, lh, ibits,
1897 mdt_object_put(info->mti_env, o);
1904 void mdt_object_unlock_put(struct mdt_thread_info * info,
1905 struct mdt_object * o,
1906 struct mdt_lock_handle *lh,
1909 mdt_object_unlock(info, o, lh, decref);
1910 mdt_object_put(info->mti_env, o);
1913 static struct mdt_handler *mdt_handler_find(__u32 opc,
1914 struct mdt_opc_slice *supported)
1916 struct mdt_opc_slice *s;
1917 struct mdt_handler *h;
1920 for (s = supported; s->mos_hs != NULL; s++) {
1921 if (s->mos_opc_start <= opc && opc < s->mos_opc_end) {
1922 h = s->mos_hs + (opc - s->mos_opc_start);
1923 if (likely(h->mh_opc != 0))
1924 LASSERT(h->mh_opc == opc);
1926 h = NULL; /* unsupported opc */
1933 static int mdt_lock_resname_compat(struct mdt_device *m,
1934 struct ldlm_request *req)
1936 /* XXX something... later. */
1940 static int mdt_lock_reply_compat(struct mdt_device *m, struct ldlm_reply *rep)
1942 /* XXX something... later. */
1947 * Generic code handling requests that have struct mdt_body passed in:
1949 * - extract mdt_body from request and save it in @info, if present;
1951 * - create lu_object, corresponding to the fid in mdt_body, and save it in
1954 * - if HABEO_CORPUS flag is set for this request type check whether object
1955 * actually exists on storage (lu_object_exists()).
1958 static int mdt_body_unpack(struct mdt_thread_info *info, __u32 flags)
1960 const struct mdt_body *body;
1961 struct mdt_object *obj;
1962 const struct lu_env *env;
1963 struct req_capsule *pill;
1967 env = info->mti_env;
1968 pill = info->mti_pill;
1970 body = info->mti_body = req_capsule_client_get(pill, &RMF_MDT_BODY);
1974 if (!(body->valid & OBD_MD_FLID))
1977 if (!fid_is_sane(&body->fid1)) {
1978 CERROR("Invalid fid: "DFID"\n", PFID(&body->fid1));
1983 * Do not get size or any capa fields before we check that request
1984 * contains capa actually. There are some requests which do not, for
1985 * instance MDS_IS_SUBDIR.
1987 if (req_capsule_has_field(pill, &RMF_CAPA1, RCL_CLIENT) &&
1988 req_capsule_get_size(pill, &RMF_CAPA1, RCL_CLIENT))
1989 mdt_set_capainfo(info, 0, &body->fid1,
1990 req_capsule_client_get(pill, &RMF_CAPA1));
1992 obj = mdt_object_find(env, info->mti_mdt, &body->fid1);
1994 if ((flags & HABEO_CORPUS) &&
1995 !mdt_object_exists(obj)) {
1996 mdt_object_put(env, obj);
1997 /* for capability renew ENOENT will be handled in
1999 if (body->valid & OBD_MD_FLOSSCAPA)
2004 info->mti_object = obj;
2013 static int mdt_unpack_req_pack_rep(struct mdt_thread_info *info, __u32 flags)
2015 struct req_capsule *pill = info->mti_pill;
2019 if (req_capsule_has_field(pill, &RMF_MDT_BODY, RCL_CLIENT))
2020 rc = mdt_body_unpack(info, flags);
2024 if (rc == 0 && (flags & HABEO_REFERO)) {
2025 struct mdt_device *mdt = info->mti_mdt;
2028 if (req_capsule_has_field(pill, &RMF_MDT_MD, RCL_SERVER))
2029 req_capsule_set_size(pill, &RMF_MDT_MD, RCL_SERVER,
2030 mdt->mdt_max_mdsize);
2031 if (req_capsule_has_field(pill, &RMF_LOGCOOKIES, RCL_SERVER))
2032 req_capsule_set_size(pill, &RMF_LOGCOOKIES, RCL_SERVER,
2033 mdt->mdt_max_cookiesize);
2035 rc = req_capsule_server_pack(pill);
2040 static int mdt_init_capa_ctxt(const struct lu_env *env, struct mdt_device *m)
2042 struct md_device *next = m->mdt_child;
2044 return next->md_ops->mdo_init_capa_ctxt(env, next,
2045 m->mdt_opts.mo_mds_capa,
2046 m->mdt_capa_timeout,
2052 * Invoke handler for this request opc. Also do necessary preprocessing
2053 * (according to handler ->mh_flags), and post-processing (setting of
2054 * ->last_{xid,committed}).
2056 static int mdt_req_handle(struct mdt_thread_info *info,
2057 struct mdt_handler *h, struct ptlrpc_request *req)
2059 int rc, serious = 0;
2064 LASSERT(h->mh_act != NULL);
2065 LASSERT(h->mh_opc == lustre_msg_get_opc(req->rq_reqmsg));
2066 LASSERT(current->journal_info == NULL);
2069 * Checking for various OBD_FAIL_$PREF_$OPC_NET codes. _Do_ not try
2070 * to put same checks into handlers like mdt_close(), mdt_reint(),
2071 * etc., without talking to mdt authors first. Checking same thing
2072 * there again is useless and returning 0 error wihtout packing reply
2073 * is buggy! Handlers either pack reply or return error.
2075 * We return 0 here and do not send any reply in order to emulate
2076 * network failure. Do not send any reply in case any of NET related
2077 * fail_id has occured.
2079 if (OBD_FAIL_CHECK_ORSET(h->mh_fail_id, OBD_FAIL_ONCE))
2083 flags = h->mh_flags;
2084 LASSERT(ergo(flags & (HABEO_CORPUS|HABEO_REFERO), h->mh_fmt != NULL));
2086 if (h->mh_fmt != NULL) {
2087 req_capsule_set(info->mti_pill, h->mh_fmt);
2088 rc = mdt_unpack_req_pack_rep(info, flags);
2091 if (rc == 0 && flags & MUTABOR &&
2092 req->rq_export->exp_connect_flags & OBD_CONNECT_RDONLY)
2093 /* should it be rq_status? */
2096 if (rc == 0 && flags & HABEO_CLAVIS) {
2097 struct ldlm_request *dlm_req;
2099 LASSERT(h->mh_fmt != NULL);
2101 dlm_req = req_capsule_client_get(info->mti_pill, &RMF_DLM_REQ);
2102 if (dlm_req != NULL) {
2103 if (info->mti_mdt->mdt_opts.mo_compat_resname)
2104 rc = mdt_lock_resname_compat(info->mti_mdt,
2106 info->mti_dlm_req = dlm_req;
2112 /* capability setting changed via /proc, needs reinitialize ctxt */
2113 if (info->mti_mdt && info->mti_mdt->mdt_capa_conf) {
2114 mdt_init_capa_ctxt(info->mti_env, info->mti_mdt);
2115 info->mti_mdt->mdt_capa_conf = 0;
2118 if (likely(rc == 0)) {
2120 * Process request, there can be two types of rc:
2121 * 1) errors with msg unpack/pack, other failures outside the
2122 * operation itself. This is counted as serious errors;
2123 * 2) errors during fs operation, should be placed in rq_status
2126 rc = h->mh_act(info);
2128 !req->rq_no_reply && req->rq_reply_state == NULL) {
2129 DEBUG_REQ(D_ERROR, req, "MDT \"handler\" %s did not "
2130 "pack reply and returned 0 error\n",
2134 serious = is_serious(rc);
2135 rc = clear_serious(rc);
2139 req->rq_status = rc;
2142 * ELDLM_* codes which > 0 should be in rq_status only as well as
2143 * all non-serious errors.
2145 if (rc > 0 || !serious)
2148 LASSERT(current->journal_info == NULL);
2150 if (rc == 0 && (flags & HABEO_CLAVIS) &&
2151 info->mti_mdt->mdt_opts.mo_compat_resname) {
2152 struct ldlm_reply *dlmrep;
2154 dlmrep = req_capsule_server_get(info->mti_pill, &RMF_DLM_REP);
2156 rc = mdt_lock_reply_compat(info->mti_mdt, dlmrep);
2159 /* If we're DISCONNECTing, the mdt_export_data is already freed */
2160 if (likely(rc == 0 && h->mh_opc != MDS_DISCONNECT))
2161 target_committed_to_req(req);
2163 if (unlikely((lustre_msg_get_flags(req->rq_reqmsg) & MSG_REPLAY) &&
2164 lustre_msg_get_transno(req->rq_reqmsg) == 0)) {
2165 DEBUG_REQ(D_ERROR, req, "transno is 0 during REPLAY");
2169 target_send_reply(req, rc, info->mti_fail_id);
2173 void mdt_lock_handle_init(struct mdt_lock_handle *lh)
2175 lh->mlh_type = MDT_NUL_LOCK;
2176 lh->mlh_reg_lh.cookie = 0ull;
2177 lh->mlh_reg_mode = LCK_MINMODE;
2178 lh->mlh_pdo_lh.cookie = 0ull;
2179 lh->mlh_pdo_mode = LCK_MINMODE;
2182 void mdt_lock_handle_fini(struct mdt_lock_handle *lh)
2184 LASSERT(!lustre_handle_is_used(&lh->mlh_reg_lh));
2185 LASSERT(!lustre_handle_is_used(&lh->mlh_pdo_lh));
2189 * Initialize fields of struct mdt_thread_info. Other fields are left in
2190 * uninitialized state, because it's too expensive to zero out whole
2191 * mdt_thread_info (> 1K) on each request arrival.
2193 static void mdt_thread_info_init(struct ptlrpc_request *req,
2194 struct mdt_thread_info *info)
2197 struct md_capainfo *ci;
2199 req_capsule_init(&req->rq_pill, req, RCL_SERVER);
2200 info->mti_pill = &req->rq_pill;
2203 for (i = 0; i < ARRAY_SIZE(info->mti_lh); i++)
2204 mdt_lock_handle_init(&info->mti_lh[i]);
2206 /* mdt device: it can be NULL while CONNECT */
2207 if (req->rq_export) {
2208 info->mti_mdt = mdt_dev(req->rq_export->exp_obd->obd_lu_dev);
2209 info->mti_exp = req->rq_export;
2211 info->mti_mdt = NULL;
2212 info->mti_env = req->rq_svc_thread->t_env;
2213 ci = md_capainfo(info->mti_env);
2214 memset(ci, 0, sizeof *ci);
2216 info->mti_fail_id = OBD_FAIL_MDS_ALL_REPLY_NET;
2217 info->mti_transno = lustre_msg_get_transno(req->rq_reqmsg);
2219 memset(&info->mti_attr, 0, sizeof(info->mti_attr));
2220 info->mti_body = NULL;
2221 info->mti_object = NULL;
2222 info->mti_dlm_req = NULL;
2223 info->mti_has_trans = 0;
2224 info->mti_no_need_trans = 0;
2225 info->mti_cross_ref = 0;
2226 info->mti_opdata = 0;
2228 /* To not check for split by default. */
2229 info->mti_spec.sp_ck_split = 0;
2232 static void mdt_thread_info_fini(struct mdt_thread_info *info)
2236 req_capsule_fini(info->mti_pill);
2237 if (info->mti_object != NULL) {
2238 mdt_object_put(info->mti_env, info->mti_object);
2239 info->mti_object = NULL;
2241 for (i = 0; i < ARRAY_SIZE(info->mti_lh); i++)
2242 mdt_lock_handle_fini(&info->mti_lh[i]);
2243 info->mti_env = NULL;
2246 static int mdt_filter_recovery_request(struct ptlrpc_request *req,
2247 struct obd_device *obd, int *process)
2249 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
2250 case MDS_CONNECT: /* This will never get here, but for completeness. */
2251 case OST_CONNECT: /* This will never get here, but for completeness. */
2252 case MDS_DISCONNECT:
2253 case OST_DISCONNECT:
2258 case MDS_DONE_WRITING:
2259 case MDS_SYNC: /* used in unmounting */
2265 *process = target_queue_recovery_request(req, obd);
2269 DEBUG_REQ(D_ERROR, req, "not permitted during recovery");
2276 * Handle recovery. Return:
2277 * +1: continue request processing;
2278 * -ve: abort immediately with the given error code;
2279 * 0: send reply with error code in req->rq_status;
2281 static int mdt_recovery(struct mdt_thread_info *info)
2283 struct ptlrpc_request *req = mdt_info_req(info);
2285 struct obd_device *obd;
2289 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
2292 case SEC_CTX_INIT_CONT:
2298 rc = mdt_handle_idmap(info);
2307 if (unlikely(req->rq_export == NULL)) {
2308 CERROR("operation %d on unconnected MDS from %s\n",
2309 lustre_msg_get_opc(req->rq_reqmsg),
2310 libcfs_id2str(req->rq_peer));
2311 /* FIXME: For CMD cleanup, when mds_B stop, the req from
2312 * mds_A will get -ENOTCONN(especially for ping req),
2313 * which will cause that mds_A deactive timeout, then when
2314 * mds_A cleanup, the cleanup process will be suspended since
2315 * deactive timeout is not zero.
2317 req->rq_status = -ENOTCONN;
2318 target_send_reply(req, -ENOTCONN, info->mti_fail_id);
2322 /* sanity check: if the xid matches, the request must be marked as a
2323 * resent or replayed */
2324 if (req_xid_is_last(req)) {
2325 if (!(lustre_msg_get_flags(req->rq_reqmsg) &
2326 (MSG_RESENT | MSG_REPLAY))) {
2327 DEBUG_REQ(D_WARNING, req, "rq_xid "LPU64" matches last_xid, "
2328 "expected REPLAY or RESENT flag (%x)", req->rq_xid,
2329 lustre_msg_get_flags(req->rq_reqmsg));
2331 req->rq_status = -ENOTCONN;
2336 /* else: note the opposite is not always true; a RESENT req after a
2337 * failover will usually not match the last_xid, since it was likely
2338 * never committed. A REPLAYed request will almost never match the
2339 * last xid, however it could for a committed, but still retained,
2342 obd = req->rq_export->exp_obd;
2344 /* Check for aborted recovery... */
2345 spin_lock_bh(&obd->obd_processing_task_lock);
2346 recovering = obd->obd_recovering;
2347 spin_unlock_bh(&obd->obd_processing_task_lock);
2348 if (unlikely(recovering)) {
2351 DEBUG_REQ(D_INFO, req, "Got new replay");
2352 rc = mdt_filter_recovery_request(req, obd, &should_process);
2353 if (rc != 0 || !should_process)
2355 else if (should_process < 0) {
2356 req->rq_status = should_process;
2357 rc = ptlrpc_error(req);
2364 static int mdt_msg_check_version(struct lustre_msg *msg)
2368 switch (lustre_msg_get_opc(msg)) {
2370 case MDS_DISCONNECT:
2373 case SEC_CTX_INIT_CONT:
2375 rc = lustre_msg_check_version(msg, LUSTRE_OBD_VERSION);
2377 CERROR("bad opc %u version %08x, expecting %08x\n",
2378 lustre_msg_get_opc(msg),
2379 lustre_msg_get_version(msg),
2380 LUSTRE_OBD_VERSION);
2384 case MDS_GETATTR_NAME:
2391 case MDS_DONE_WRITING:
2397 case MDS_QUOTACHECK:
2403 rc = lustre_msg_check_version(msg, LUSTRE_MDS_VERSION);
2405 CERROR("bad opc %u version %08x, expecting %08x\n",
2406 lustre_msg_get_opc(msg),
2407 lustre_msg_get_version(msg),
2408 LUSTRE_MDS_VERSION);
2412 case LDLM_BL_CALLBACK:
2413 case LDLM_CP_CALLBACK:
2414 rc = lustre_msg_check_version(msg, LUSTRE_DLM_VERSION);
2416 CERROR("bad opc %u version %08x, expecting %08x\n",
2417 lustre_msg_get_opc(msg),
2418 lustre_msg_get_version(msg),
2419 LUSTRE_DLM_VERSION);
2421 case OBD_LOG_CANCEL:
2422 case LLOG_ORIGIN_HANDLE_CREATE:
2423 case LLOG_ORIGIN_HANDLE_NEXT_BLOCK:
2424 case LLOG_ORIGIN_HANDLE_READ_HEADER:
2425 case LLOG_ORIGIN_HANDLE_CLOSE:
2426 case LLOG_ORIGIN_HANDLE_DESTROY:
2427 case LLOG_ORIGIN_HANDLE_PREV_BLOCK:
2429 rc = lustre_msg_check_version(msg, LUSTRE_LOG_VERSION);
2431 CERROR("bad opc %u version %08x, expecting %08x\n",
2432 lustre_msg_get_opc(msg),
2433 lustre_msg_get_version(msg),
2434 LUSTRE_LOG_VERSION);
2437 CERROR("MDS unknown opcode %d\n", lustre_msg_get_opc(msg));
2443 static int mdt_handle0(struct ptlrpc_request *req,
2444 struct mdt_thread_info *info,
2445 struct mdt_opc_slice *supported)
2447 struct mdt_handler *h;
2448 struct lustre_msg *msg;
2453 if (OBD_FAIL_CHECK_ORSET(OBD_FAIL_MDS_ALL_REQUEST_NET, OBD_FAIL_ONCE))
2456 LASSERT(current->journal_info == NULL);
2458 msg = req->rq_reqmsg;
2459 rc = mdt_msg_check_version(msg);
2460 if (likely(rc == 0)) {
2461 rc = mdt_recovery(info);
2462 if (likely(rc == +1)) {
2463 h = mdt_handler_find(lustre_msg_get_opc(msg),
2465 if (likely(h != NULL)) {
2466 rc = mdt_req_handle(info, h, req);
2468 CERROR("The unsupported opc: 0x%x\n", lustre_msg_get_opc(msg) );
2469 req->rq_status = -ENOTSUPP;
2470 rc = ptlrpc_error(req);
2475 CERROR(LUSTRE_MDT_NAME" drops mal-formed request\n");
2480 * MDT handler function called by ptlrpc service thread when request comes.
2482 * XXX common "target" functionality should be factored into separate module
2483 * shared by mdt, ost and stand-alone services like fld.
2485 static int mdt_handle_common(struct ptlrpc_request *req,
2486 struct mdt_opc_slice *supported)
2489 struct mdt_thread_info *info;
2493 env = req->rq_svc_thread->t_env;
2494 LASSERT(env != NULL);
2495 LASSERT(env->le_ses != NULL);
2496 LASSERT(env->le_ctx.lc_thread == req->rq_svc_thread);
2497 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
2498 LASSERT(info != NULL);
2500 mdt_thread_info_init(req, info);
2502 rc = mdt_handle0(req, info, supported);
2504 mdt_thread_info_fini(info);
2509 * This is called from recovery code as handler of _all_ RPC types, FLD and SEQ
2512 int mdt_recovery_handle(struct ptlrpc_request *req)
2517 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
2519 rc = mdt_handle_common(req, mdt_fld_handlers);
2522 rc = mdt_handle_common(req, mdt_seq_handlers);
2525 rc = mdt_handle_common(req, mdt_regular_handlers);
2532 static int mdt_regular_handle(struct ptlrpc_request *req)
2534 return mdt_handle_common(req, mdt_regular_handlers);
2537 static int mdt_readpage_handle(struct ptlrpc_request *req)
2539 return mdt_handle_common(req, mdt_readpage_handlers);
2542 static int mdt_xmds_handle(struct ptlrpc_request *req)
2544 return mdt_handle_common(req, mdt_xmds_handlers);
2547 static int mdt_mdsc_handle(struct ptlrpc_request *req)
2549 return mdt_handle_common(req, mdt_seq_handlers);
2552 static int mdt_mdss_handle(struct ptlrpc_request *req)
2554 return mdt_handle_common(req, mdt_seq_handlers);
2557 static int mdt_dtss_handle(struct ptlrpc_request *req)
2559 return mdt_handle_common(req, mdt_seq_handlers);
2562 static int mdt_fld_handle(struct ptlrpc_request *req)
2564 return mdt_handle_common(req, mdt_fld_handlers);
2580 static int mdt_intent_getattr(enum mdt_it_code opcode,
2581 struct mdt_thread_info *info,
2582 struct ldlm_lock **,
2584 static int mdt_intent_reint(enum mdt_it_code opcode,
2585 struct mdt_thread_info *info,
2586 struct ldlm_lock **,
2589 static struct mdt_it_flavor {
2590 const struct req_format *it_fmt;
2592 int (*it_act)(enum mdt_it_code ,
2593 struct mdt_thread_info *,
2594 struct ldlm_lock **,
2597 } mdt_it_flavor[] = {
2599 .it_fmt = &RQF_LDLM_INTENT,
2600 /*.it_flags = HABEO_REFERO,*/
2602 .it_act = mdt_intent_reint,
2603 .it_reint = REINT_OPEN
2606 .it_fmt = &RQF_LDLM_INTENT,
2607 .it_flags = MUTABOR,
2608 .it_act = mdt_intent_reint,
2609 .it_reint = REINT_OPEN
2612 .it_fmt = &RQF_LDLM_INTENT,
2613 .it_flags = MUTABOR,
2614 .it_act = mdt_intent_reint,
2615 .it_reint = REINT_CREATE
2617 [MDT_IT_GETATTR] = {
2618 .it_fmt = &RQF_LDLM_INTENT_GETATTR,
2619 .it_flags = HABEO_REFERO,
2620 .it_act = mdt_intent_getattr
2622 [MDT_IT_READDIR] = {
2628 .it_fmt = &RQF_LDLM_INTENT_GETATTR,
2629 .it_flags = HABEO_REFERO,
2630 .it_act = mdt_intent_getattr
2633 .it_fmt = &RQF_LDLM_INTENT_UNLINK,
2634 .it_flags = MUTABOR,
2636 .it_reint = REINT_UNLINK
2640 .it_flags = MUTABOR,
2643 [MDT_IT_GETXATTR] = {
2650 int mdt_intent_lock_replace(struct mdt_thread_info *info,
2651 struct ldlm_lock **lockp,
2652 struct ldlm_lock *new_lock,
2653 struct mdt_lock_handle *lh,
2656 struct ptlrpc_request *req = mdt_info_req(info);
2657 struct ldlm_lock *lock = *lockp;
2660 * Get new lock only for cases when possible resent did not find any
2663 if (new_lock == NULL)
2664 new_lock = ldlm_handle2lock(&lh->mlh_reg_lh);
2666 if (new_lock == NULL && (flags & LDLM_FL_INTENT_ONLY)) {
2667 lh->mlh_reg_lh.cookie = 0;
2671 LASSERTF(new_lock != NULL,
2672 "lockh "LPX64"\n", lh->mlh_reg_lh.cookie);
2675 * If we've already given this lock to a client once, then we should
2676 * have no readers or writers. Otherwise, we should have one reader
2677 * _or_ writer ref (which will be zeroed below) before returning the
2680 if (new_lock->l_export == req->rq_export) {
2681 LASSERT(new_lock->l_readers + new_lock->l_writers == 0);
2683 LASSERT(new_lock->l_export == NULL);
2684 LASSERT(new_lock->l_readers + new_lock->l_writers == 1);
2689 if (new_lock->l_export == req->rq_export) {
2691 * Already gave this to the client, which means that we
2692 * reconstructed a reply.
2694 LASSERT(lustre_msg_get_flags(req->rq_reqmsg) &
2696 lh->mlh_reg_lh.cookie = 0;
2697 RETURN(ELDLM_LOCK_REPLACED);
2700 /* This lock might already be given to the client by an resent req,
2701 * in this case we should return ELDLM_LOCK_ABORTED,
2702 * so we should check led_held_locks here, but it will affect
2703 * performance, FIXME
2705 /* Fixup the lock to be given to the client */
2706 lock_res_and_lock(new_lock);
2707 new_lock->l_readers = 0;
2708 new_lock->l_writers = 0;
2710 new_lock->l_export = class_export_get(req->rq_export);
2711 spin_lock(&req->rq_export->exp_ldlm_data.led_lock);
2712 list_add(&new_lock->l_export_chain,
2713 &new_lock->l_export->exp_ldlm_data.led_held_locks);
2714 spin_unlock(&req->rq_export->exp_ldlm_data.led_lock);
2716 new_lock->l_blocking_ast = lock->l_blocking_ast;
2717 new_lock->l_completion_ast = lock->l_completion_ast;
2718 new_lock->l_remote_handle = lock->l_remote_handle;
2719 new_lock->l_flags &= ~LDLM_FL_LOCAL;
2721 unlock_res_and_lock(new_lock);
2722 LDLM_LOCK_PUT(new_lock);
2723 lh->mlh_reg_lh.cookie = 0;
2725 RETURN(ELDLM_LOCK_REPLACED);
2728 static void mdt_intent_fixup_resent(struct mdt_thread_info *info,
2729 struct ldlm_lock *new_lock,
2730 struct ldlm_lock **old_lock,
2731 struct mdt_lock_handle *lh)
2733 struct ptlrpc_request *req = mdt_info_req(info);
2734 struct obd_export *exp = req->rq_export;
2735 struct lustre_handle remote_hdl;
2736 struct ldlm_request *dlmreq;
2737 struct list_head *iter;
2739 if (!(lustre_msg_get_flags(req->rq_reqmsg) & MSG_RESENT))
2742 dlmreq = req_capsule_client_get(info->mti_pill, &RMF_DLM_REQ);
2743 remote_hdl = dlmreq->lock_handle[0];
2745 spin_lock(&exp->exp_ldlm_data.led_lock);
2746 list_for_each(iter, &exp->exp_ldlm_data.led_held_locks) {
2747 struct ldlm_lock *lock;
2748 lock = list_entry(iter, struct ldlm_lock, l_export_chain);
2749 if (lock == new_lock)
2751 if (lock->l_remote_handle.cookie == remote_hdl.cookie) {
2752 lh->mlh_reg_lh.cookie = lock->l_handle.h_cookie;
2753 lh->mlh_reg_mode = lock->l_granted_mode;
2755 LDLM_DEBUG(lock, "restoring lock cookie");
2756 DEBUG_REQ(D_DLMTRACE, req,
2757 "restoring lock cookie "LPX64,
2758 lh->mlh_reg_lh.cookie);
2760 *old_lock = LDLM_LOCK_GET(lock);
2761 spin_unlock(&exp->exp_ldlm_data.led_lock);
2765 spin_unlock(&exp->exp_ldlm_data.led_lock);
2768 * If the xid matches, then we know this is a resent request, and allow
2769 * it. (It's probably an OPEN, for which we don't send a lock.
2771 if (req_xid_is_last(req))
2775 * This remote handle isn't enqueued, so we never received or processed
2776 * this request. Clear MSG_RESENT, because it can be handled like any
2777 * normal request now.
2779 lustre_msg_clear_flags(req->rq_reqmsg, MSG_RESENT);
2781 DEBUG_REQ(D_DLMTRACE, req, "no existing lock with rhandle "LPX64,
2785 static int mdt_intent_getattr(enum mdt_it_code opcode,
2786 struct mdt_thread_info *info,
2787 struct ldlm_lock **lockp,
2790 struct mdt_lock_handle *lhc = &info->mti_lh[MDT_LH_RMT];
2791 struct ldlm_lock *new_lock = NULL;
2793 struct ldlm_reply *ldlm_rep;
2794 struct ptlrpc_request *req;
2795 struct mdt_body *reqbody;
2796 struct mdt_body *repbody;
2800 reqbody = req_capsule_client_get(info->mti_pill, &RMF_MDT_BODY);
2803 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
2806 info->mti_spec.sp_ck_split = !!(reqbody->valid & OBD_MD_FLCKSPLIT);
2807 info->mti_cross_ref = !!(reqbody->valid & OBD_MD_FLCROSSREF);
2808 repbody->eadatasize = 0;
2809 repbody->aclsize = 0;
2813 child_bits = MDS_INODELOCK_LOOKUP;
2815 case MDT_IT_GETATTR:
2816 child_bits = MDS_INODELOCK_LOOKUP | MDS_INODELOCK_UPDATE;
2819 CERROR("Unhandled till now");
2820 GOTO(out_shrink, rc = -EINVAL);
2823 rc = mdt_init_ucred(info, reqbody);
2825 GOTO(out_shrink, rc);
2827 req = info->mti_pill->rc_req;
2828 ldlm_rep = req_capsule_server_get(info->mti_pill, &RMF_DLM_REP);
2829 mdt_set_disposition(info, ldlm_rep, DISP_IT_EXECD);
2831 /* Get lock from request for possible resent case. */
2832 mdt_intent_fixup_resent(info, *lockp, &new_lock, lhc);
2834 ldlm_rep->lock_policy_res2 =
2835 mdt_getattr_name_lock(info, lhc, child_bits, ldlm_rep);
2837 if (mdt_get_disposition(ldlm_rep, DISP_LOOKUP_NEG))
2838 ldlm_rep->lock_policy_res2 = 0;
2839 if (!mdt_get_disposition(ldlm_rep, DISP_LOOKUP_POS) ||
2840 ldlm_rep->lock_policy_res2) {
2841 lhc->mlh_reg_lh.cookie = 0ull;
2842 GOTO(out_ucred, rc = ELDLM_LOCK_ABORTED);
2845 rc = mdt_intent_lock_replace(info, lockp, new_lock, lhc, flags);
2848 mdt_exit_ucred(info);
2850 mdt_shrink_reply(info);
2854 static int mdt_intent_reint(enum mdt_it_code opcode,
2855 struct mdt_thread_info *info,
2856 struct ldlm_lock **lockp,
2859 struct mdt_lock_handle *lhc = &info->mti_lh[MDT_LH_RMT];
2860 struct ldlm_reply *rep = NULL;
2864 static const struct req_format *intent_fmts[REINT_MAX] = {
2865 [REINT_CREATE] = &RQF_LDLM_INTENT_CREATE,
2866 [REINT_OPEN] = &RQF_LDLM_INTENT_OPEN
2871 opc = mdt_reint_opcode(info, intent_fmts);
2875 if (mdt_it_flavor[opcode].it_reint != opc) {
2876 CERROR("Reint code %ld doesn't match intent: %d\n",
2878 RETURN(err_serious(-EPROTO));
2881 /* Get lock from request for possible resent case. */
2882 mdt_intent_fixup_resent(info, *lockp, NULL, lhc);
2884 rc = mdt_reint_internal(info, lhc, opc);
2886 /* Check whether the reply has been packed successfully. */
2887 if (mdt_info_req(info)->rq_repmsg != NULL)
2888 rep = req_capsule_server_get(info->mti_pill, &RMF_DLM_REP);
2890 RETURN(err_serious(-EFAULT));
2892 /* MDC expects this in any case */
2894 mdt_set_disposition(info, rep, DISP_LOOKUP_EXECD);
2896 /* Cross-ref case, the lock should be returned to the client */
2897 if (rc == -EREMOTE) {
2898 LASSERT(lustre_handle_is_used(&lhc->mlh_reg_lh));
2899 rep->lock_policy_res2 = 0;
2900 rc = mdt_intent_lock_replace(info, lockp, NULL, lhc, flags);
2903 rep->lock_policy_res2 = clear_serious(rc);
2905 lhc->mlh_reg_lh.cookie = 0ull;
2906 rc = ELDLM_LOCK_ABORTED;
2910 static int mdt_intent_code(long itcode)
2918 case IT_OPEN|IT_CREAT:
2925 rc = MDT_IT_READDIR;
2928 rc = MDT_IT_GETATTR;
2940 rc = MDT_IT_GETXATTR;
2943 CERROR("Unknown intent opcode: %ld\n", itcode);
2950 static int mdt_intent_opc(long itopc, struct mdt_thread_info *info,
2951 struct ldlm_lock **lockp, int flags)
2953 struct req_capsule *pill;
2954 struct mdt_it_flavor *flv;
2959 opc = mdt_intent_code(itopc);
2963 pill = info->mti_pill;
2964 flv = &mdt_it_flavor[opc];
2966 if (flv->it_fmt != NULL)
2967 req_capsule_extend(pill, flv->it_fmt);
2969 rc = mdt_unpack_req_pack_rep(info, flv->it_flags);
2971 struct ptlrpc_request *req = mdt_info_req(info);
2972 if (flv->it_flags & MUTABOR &&
2973 req->rq_export->exp_connect_flags & OBD_CONNECT_RDONLY)
2976 if (rc == 0 && flv->it_act != NULL) {
2977 /* execute policy */
2978 rc = flv->it_act(opc, info, lockp, flags);
2985 static int mdt_intent_policy(struct ldlm_namespace *ns,
2986 struct ldlm_lock **lockp, void *req_cookie,
2987 ldlm_mode_t mode, int flags, void *data)
2989 struct mdt_thread_info *info;
2990 struct ptlrpc_request *req = req_cookie;
2991 struct ldlm_intent *it;
2992 struct req_capsule *pill;
2997 LASSERT(req != NULL);
2999 info = lu_context_key_get(&req->rq_svc_thread->t_env->le_ctx,
3001 LASSERT(info != NULL);
3002 pill = info->mti_pill;
3003 LASSERT(pill->rc_req == req);
3005 if (req->rq_reqmsg->lm_bufcount > DLM_INTENT_IT_OFF) {
3006 req_capsule_extend(pill, &RQF_LDLM_INTENT);
3007 it = req_capsule_client_get(pill, &RMF_LDLM_INTENT);
3009 const struct ldlm_request *dlmreq;
3012 struct ldlm_lock *lock = *lockp;
3014 LDLM_DEBUG(lock, "intent policy opc: %s\n",
3015 ldlm_it2str(it->opc));
3018 rc = mdt_intent_opc(it->opc, info, lockp, flags);
3023 * Lock without inodebits makes no sense and will oops
3024 * later in ldlm. Let's check it now to see if we have
3025 * wrong lock from client or bits get corrupted
3026 * somewhere in mdt_intent_opc().
3028 dlmreq = info->mti_dlm_req;
3029 req_bits = dlmreq->lock_desc.l_policy_data.l_inodebits.bits;
3030 LASSERT(req_bits != 0);
3033 rc = err_serious(-EFAULT);
3035 /* No intent was provided */
3036 LASSERT(pill->rc_fmt == &RQF_LDLM_ENQUEUE);
3037 rc = req_capsule_server_pack(pill);
3039 rc = err_serious(rc);
3047 static void mdt_seq_adjust(const struct lu_env *env,
3048 struct mdt_device *m, int lost)
3050 struct lu_site *ls = m->mdt_md_dev.md_lu_dev.ld_site;
3051 struct lu_range out;
3054 LASSERT(ls && ls->ls_server_seq);
3056 /* get extra seq from seq_server, moving it's range up */
3057 while (lost-- > 0) {
3058 seq_server_alloc_meta(ls->ls_server_seq, NULL, &out, env);
3063 static int mdt_seq_fini(const struct lu_env *env,
3064 struct mdt_device *m)
3066 struct lu_site *ls = m->mdt_md_dev.md_lu_dev.ld_site;
3069 if (ls && ls->ls_server_seq) {
3070 seq_server_fini(ls->ls_server_seq, env);
3071 OBD_FREE_PTR(ls->ls_server_seq);
3072 ls->ls_server_seq = NULL;
3075 if (ls && ls->ls_control_seq) {
3076 seq_server_fini(ls->ls_control_seq, env);
3077 OBD_FREE_PTR(ls->ls_control_seq);
3078 ls->ls_control_seq = NULL;
3081 if (ls && ls->ls_client_seq) {
3082 seq_client_fini(ls->ls_client_seq);
3083 OBD_FREE_PTR(ls->ls_client_seq);
3084 ls->ls_client_seq = NULL;
3090 static int mdt_seq_init(const struct lu_env *env,
3092 struct mdt_device *m)
3099 ls = m->mdt_md_dev.md_lu_dev.ld_site;
3102 * This is sequence-controller node. Init seq-controller server on local
3105 if (ls->ls_node_id == 0) {
3106 LASSERT(ls->ls_control_seq == NULL);
3108 OBD_ALLOC_PTR(ls->ls_control_seq);
3109 if (ls->ls_control_seq == NULL)
3112 rc = seq_server_init(ls->ls_control_seq,
3113 m->mdt_bottom, uuid,
3114 LUSTRE_SEQ_CONTROLLER,
3118 GOTO(out_seq_fini, rc);
3120 OBD_ALLOC_PTR(ls->ls_client_seq);
3121 if (ls->ls_client_seq == NULL)
3122 GOTO(out_seq_fini, rc = -ENOMEM);
3124 OBD_ALLOC(prefix, MAX_OBD_NAME + 5);
3125 if (prefix == NULL) {
3126 OBD_FREE_PTR(ls->ls_client_seq);
3127 GOTO(out_seq_fini, rc = -ENOMEM);
3130 snprintf(prefix, MAX_OBD_NAME + 5, "ctl-%s",
3134 * Init seq-controller client after seq-controller server is
3135 * ready. Pass ls->ls_control_seq to it for direct talking.
3137 rc = seq_client_init(ls->ls_client_seq, NULL,
3138 LUSTRE_SEQ_METADATA, prefix,
3139 ls->ls_control_seq);
3140 OBD_FREE(prefix, MAX_OBD_NAME + 5);
3143 GOTO(out_seq_fini, rc);
3146 /* Init seq-server on local MDT */
3147 LASSERT(ls->ls_server_seq == NULL);
3149 OBD_ALLOC_PTR(ls->ls_server_seq);
3150 if (ls->ls_server_seq == NULL)
3151 GOTO(out_seq_fini, rc = -ENOMEM);
3153 rc = seq_server_init(ls->ls_server_seq,
3154 m->mdt_bottom, uuid,
3158 GOTO(out_seq_fini, rc = -ENOMEM);
3160 /* Assign seq-controller client to local seq-server. */
3161 if (ls->ls_node_id == 0) {
3162 LASSERT(ls->ls_client_seq != NULL);
3164 rc = seq_server_set_cli(ls->ls_server_seq,
3172 mdt_seq_fini(env, m);
3177 * Init client sequence manager which is used by local MDS to talk to sequence
3178 * controller on remote node.
3180 static int mdt_seq_init_cli(const struct lu_env *env,
3181 struct mdt_device *m,
3182 struct lustre_cfg *cfg)
3184 struct lu_site *ls = m->mdt_md_dev.md_lu_dev.ld_site;
3185 struct obd_device *mdc;
3186 struct obd_uuid *uuidp, *mdcuuidp;
3187 char *uuid_str, *mdc_uuid_str;
3190 struct mdt_thread_info *info;
3191 char *p, *index_string = lustre_cfg_string(cfg, 2);
3194 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
3195 uuidp = &info->mti_u.uuid[0];
3196 mdcuuidp = &info->mti_u.uuid[1];
3198 LASSERT(index_string);
3200 index = simple_strtol(index_string, &p, 10);
3202 CERROR("Invalid index in lustre_cgf, offset 2\n");
3206 /* check if this is adding the first MDC and controller is not yet
3208 if (index != 0 || ls->ls_client_seq)
3211 uuid_str = lustre_cfg_string(cfg, 1);
3212 mdc_uuid_str = lustre_cfg_string(cfg, 4);
3213 obd_str2uuid(uuidp, uuid_str);
3214 obd_str2uuid(mdcuuidp, mdc_uuid_str);
3216 mdc = class_find_client_obd(uuidp, LUSTRE_MDC_NAME, mdcuuidp);
3218 CERROR("can't find controller MDC by uuid %s\n",
3221 } else if (!mdc->obd_set_up) {
3222 CERROR("target %s not set up\n", mdc->obd_name);
3225 LASSERT(ls->ls_control_exp);
3226 OBD_ALLOC_PTR(ls->ls_client_seq);
3227 if (ls->ls_client_seq != NULL) {
3230 OBD_ALLOC(prefix, MAX_OBD_NAME + 5);
3234 snprintf(prefix, MAX_OBD_NAME + 5, "ctl-%s",
3237 rc = seq_client_init(ls->ls_client_seq,
3239 LUSTRE_SEQ_METADATA,
3241 OBD_FREE(prefix, MAX_OBD_NAME + 5);
3248 LASSERT(ls->ls_server_seq != NULL);
3249 rc = seq_server_set_cli(ls->ls_server_seq, ls->ls_client_seq,
3256 static void mdt_seq_fini_cli(struct mdt_device *m)
3262 ls = m->mdt_md_dev.md_lu_dev.ld_site;
3264 if (ls && ls->ls_server_seq)
3265 seq_server_set_cli(ls->ls_server_seq,
3268 if (ls && ls->ls_control_exp) {
3269 class_export_put(ls->ls_control_exp);
3270 ls->ls_control_exp = NULL;
3278 static int mdt_fld_fini(const struct lu_env *env,
3279 struct mdt_device *m)
3281 struct lu_site *ls = m->mdt_md_dev.md_lu_dev.ld_site;
3284 if (ls && ls->ls_server_fld) {
3285 fld_server_fini(ls->ls_server_fld, env);
3286 OBD_FREE_PTR(ls->ls_server_fld);
3287 ls->ls_server_fld = NULL;
3293 static int mdt_fld_init(const struct lu_env *env,
3295 struct mdt_device *m)
3301 ls = m->mdt_md_dev.md_lu_dev.ld_site;
3303 OBD_ALLOC_PTR(ls->ls_server_fld);
3304 if (ls->ls_server_fld == NULL)
3305 RETURN(rc = -ENOMEM);
3307 rc = fld_server_init(ls->ls_server_fld,
3308 m->mdt_bottom, uuid, env);
3310 OBD_FREE_PTR(ls->ls_server_fld);
3311 ls->ls_server_fld = NULL;
3318 /* device init/fini methods */
3319 static void mdt_stop_ptlrpc_service(struct mdt_device *m)
3322 if (m->mdt_regular_service != NULL) {
3323 ptlrpc_unregister_service(m->mdt_regular_service);
3324 m->mdt_regular_service = NULL;
3326 if (m->mdt_readpage_service != NULL) {
3327 ptlrpc_unregister_service(m->mdt_readpage_service);
3328 m->mdt_readpage_service = NULL;
3330 if (m->mdt_xmds_service != NULL) {
3331 ptlrpc_unregister_service(m->mdt_xmds_service);
3332 m->mdt_xmds_service = NULL;
3334 if (m->mdt_setattr_service != NULL) {
3335 ptlrpc_unregister_service(m->mdt_setattr_service);
3336 m->mdt_setattr_service = NULL;
3338 if (m->mdt_mdsc_service != NULL) {
3339 ptlrpc_unregister_service(m->mdt_mdsc_service);
3340 m->mdt_mdsc_service = NULL;
3342 if (m->mdt_mdss_service != NULL) {
3343 ptlrpc_unregister_service(m->mdt_mdss_service);
3344 m->mdt_mdss_service = NULL;
3346 if (m->mdt_dtss_service != NULL) {
3347 ptlrpc_unregister_service(m->mdt_dtss_service);
3348 m->mdt_dtss_service = NULL;
3350 if (m->mdt_fld_service != NULL) {
3351 ptlrpc_unregister_service(m->mdt_fld_service);
3352 m->mdt_fld_service = NULL;
3357 static int mdt_start_ptlrpc_service(struct mdt_device *m)
3360 static struct ptlrpc_service_conf conf;
3361 cfs_proc_dir_entry_t *procfs_entry;
3364 procfs_entry = m->mdt_md_dev.md_lu_dev.ld_obd->obd_proc_entry;
3366 conf = (typeof(conf)) {
3367 .psc_nbufs = MDS_NBUFS,
3368 .psc_bufsize = MDS_BUFSIZE,
3369 .psc_max_req_size = MDS_MAXREQSIZE,
3370 .psc_max_reply_size = MDS_MAXREPSIZE,
3371 .psc_req_portal = MDS_REQUEST_PORTAL,
3372 .psc_rep_portal = MDC_REPLY_PORTAL,
3373 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
3375 * We'd like to have a mechanism to set this on a per-device
3376 * basis, but alas...
3378 .psc_min_threads = min(max(mdt_num_threads, MDT_MIN_THREADS),
3380 .psc_max_threads = MDT_MAX_THREADS,
3381 .psc_ctx_tags = LCT_MD_THREAD
3384 m->mdt_ldlm_client = &m->mdt_md_dev.md_lu_dev.ld_obd->obd_ldlm_client;
3385 ptlrpc_init_client(LDLM_CB_REQUEST_PORTAL, LDLM_CB_REPLY_PORTAL,
3386 "mdt_ldlm_client", m->mdt_ldlm_client);
3388 m->mdt_regular_service =
3389 ptlrpc_init_svc_conf(&conf, mdt_regular_handle, LUSTRE_MDT_NAME,
3390 procfs_entry, target_print_req,
3392 if (m->mdt_regular_service == NULL)
3395 rc = ptlrpc_start_threads(NULL, m->mdt_regular_service);
3397 GOTO(err_mdt_svc, rc);
3400 * readpage service configuration. Parameters have to be adjusted,
3403 conf = (typeof(conf)) {
3404 .psc_nbufs = MDS_NBUFS,
3405 .psc_bufsize = MDS_BUFSIZE,
3406 .psc_max_req_size = MDS_MAXREQSIZE,
3407 .psc_max_reply_size = MDS_MAXREPSIZE,
3408 .psc_req_portal = MDS_READPAGE_PORTAL,
3409 .psc_rep_portal = MDC_REPLY_PORTAL,
3410 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
3411 .psc_min_threads = min(max(mdt_num_threads, MDT_MIN_THREADS),
3413 .psc_max_threads = MDT_MAX_THREADS,
3414 .psc_ctx_tags = LCT_MD_THREAD
3416 m->mdt_readpage_service =
3417 ptlrpc_init_svc_conf(&conf, mdt_readpage_handle,
3418 LUSTRE_MDT_NAME "_readpage",
3419 procfs_entry, target_print_req,"mdt_rdpg");
3421 if (m->mdt_readpage_service == NULL) {
3422 CERROR("failed to start readpage service\n");
3423 GOTO(err_mdt_svc, rc = -ENOMEM);
3426 rc = ptlrpc_start_threads(NULL, m->mdt_readpage_service);
3429 * setattr service configuration.
3431 conf = (typeof(conf)) {
3432 .psc_nbufs = MDS_NBUFS,
3433 .psc_bufsize = MDS_BUFSIZE,
3434 .psc_max_req_size = MDS_MAXREQSIZE,
3435 .psc_max_reply_size = MDS_MAXREPSIZE,
3436 .psc_req_portal = MDS_SETATTR_PORTAL,
3437 .psc_rep_portal = MDC_REPLY_PORTAL,
3438 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
3439 .psc_min_threads = min(max(mdt_num_threads, MDT_MIN_THREADS),
3441 .psc_max_threads = MDT_MAX_THREADS,
3442 .psc_ctx_tags = LCT_MD_THREAD
3445 m->mdt_setattr_service =
3446 ptlrpc_init_svc_conf(&conf, mdt_regular_handle,
3447 LUSTRE_MDT_NAME "_setattr",
3448 procfs_entry, target_print_req,"mdt_attr");
3450 if (!m->mdt_setattr_service) {
3451 CERROR("failed to start setattr service\n");
3452 GOTO(err_mdt_svc, rc = -ENOMEM);
3455 rc = ptlrpc_start_threads(NULL, m->mdt_setattr_service);
3457 GOTO(err_mdt_svc, rc);
3460 * sequence controller service configuration
3462 conf = (typeof(conf)) {
3463 .psc_nbufs = MDS_NBUFS,
3464 .psc_bufsize = MDS_BUFSIZE,
3465 .psc_max_req_size = SEQ_MAXREQSIZE,
3466 .psc_max_reply_size = SEQ_MAXREPSIZE,
3467 .psc_req_portal = SEQ_CONTROLLER_PORTAL,
3468 .psc_rep_portal = MDC_REPLY_PORTAL,
3469 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
3470 .psc_min_threads = SEQ_NUM_THREADS,
3471 .psc_max_threads = SEQ_NUM_THREADS,
3472 .psc_ctx_tags = LCT_MD_THREAD|LCT_DT_THREAD
3475 m->mdt_mdsc_service =
3476 ptlrpc_init_svc_conf(&conf, mdt_mdsc_handle,
3477 LUSTRE_MDT_NAME"_mdsc",
3478 procfs_entry, target_print_req,"mdt_mdsc");
3479 if (!m->mdt_mdsc_service) {
3480 CERROR("failed to start seq controller service\n");
3481 GOTO(err_mdt_svc, rc = -ENOMEM);
3484 rc = ptlrpc_start_threads(NULL, m->mdt_mdsc_service);
3486 GOTO(err_mdt_svc, rc);
3489 * metadata sequence server service configuration
3491 conf = (typeof(conf)) {
3492 .psc_nbufs = MDS_NBUFS,
3493 .psc_bufsize = MDS_BUFSIZE,
3494 .psc_max_req_size = SEQ_MAXREQSIZE,
3495 .psc_max_reply_size = SEQ_MAXREPSIZE,
3496 .psc_req_portal = SEQ_METADATA_PORTAL,
3497 .psc_rep_portal = MDC_REPLY_PORTAL,
3498 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
3499 .psc_min_threads = SEQ_NUM_THREADS,
3500 .psc_max_threads = SEQ_NUM_THREADS,
3501 .psc_ctx_tags = LCT_MD_THREAD|LCT_DT_THREAD
3504 m->mdt_mdss_service =
3505 ptlrpc_init_svc_conf(&conf, mdt_mdss_handle,
3506 LUSTRE_MDT_NAME"_mdss",
3507 procfs_entry, target_print_req,"mdt_mdss");
3508 if (!m->mdt_mdss_service) {
3509 CERROR("failed to start metadata seq server service\n");
3510 GOTO(err_mdt_svc, rc = -ENOMEM);
3513 rc = ptlrpc_start_threads(NULL, m->mdt_mdss_service);
3515 GOTO(err_mdt_svc, rc);
3519 * Data sequence server service configuration. We want to have really
3520 * cluster-wide sequences space. This is why we start only one sequence
3521 * controller which manages space.
3523 conf = (typeof(conf)) {
3524 .psc_nbufs = MDS_NBUFS,
3525 .psc_bufsize = MDS_BUFSIZE,
3526 .psc_max_req_size = SEQ_MAXREQSIZE,
3527 .psc_max_reply_size = SEQ_MAXREPSIZE,
3528 .psc_req_portal = SEQ_DATA_PORTAL,
3529 .psc_rep_portal = OSC_REPLY_PORTAL,
3530 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
3531 .psc_min_threads = SEQ_NUM_THREADS,
3532 .psc_max_threads = SEQ_NUM_THREADS,
3533 .psc_ctx_tags = LCT_MD_THREAD|LCT_DT_THREAD
3536 m->mdt_dtss_service =
3537 ptlrpc_init_svc_conf(&conf, mdt_dtss_handle,
3538 LUSTRE_MDT_NAME"_dtss",
3539 procfs_entry, target_print_req,"mdt_dtss");
3540 if (!m->mdt_dtss_service) {
3541 CERROR("failed to start data seq server service\n");
3542 GOTO(err_mdt_svc, rc = -ENOMEM);
3545 rc = ptlrpc_start_threads(NULL, m->mdt_dtss_service);
3547 GOTO(err_mdt_svc, rc);
3549 /* FLD service start */
3550 conf = (typeof(conf)) {
3551 .psc_nbufs = MDS_NBUFS,
3552 .psc_bufsize = MDS_BUFSIZE,
3553 .psc_max_req_size = FLD_MAXREQSIZE,
3554 .psc_max_reply_size = FLD_MAXREPSIZE,
3555 .psc_req_portal = FLD_REQUEST_PORTAL,
3556 .psc_rep_portal = MDC_REPLY_PORTAL,
3557 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
3558 .psc_min_threads = FLD_NUM_THREADS,
3559 .psc_max_threads = FLD_NUM_THREADS,
3560 .psc_ctx_tags = LCT_DT_THREAD|LCT_MD_THREAD
3563 m->mdt_fld_service =
3564 ptlrpc_init_svc_conf(&conf, mdt_fld_handle,
3565 LUSTRE_MDT_NAME"_fld",
3566 procfs_entry, target_print_req, "mdt_fld");
3567 if (!m->mdt_fld_service) {
3568 CERROR("failed to start fld service\n");
3569 GOTO(err_mdt_svc, rc = -ENOMEM);
3572 rc = ptlrpc_start_threads(NULL, m->mdt_fld_service);
3574 GOTO(err_mdt_svc, rc);
3577 * mds-mds service configuration. Separate portal is used to allow
3578 * mds-mds requests be not blocked during recovery.
3580 conf = (typeof(conf)) {
3581 .psc_nbufs = MDS_NBUFS,
3582 .psc_bufsize = MDS_BUFSIZE,
3583 .psc_max_req_size = MDS_MAXREQSIZE,
3584 .psc_max_reply_size = MDS_MAXREPSIZE,
3585 .psc_req_portal = MDS_MDS_PORTAL,
3586 .psc_rep_portal = MDC_REPLY_PORTAL,
3587 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
3588 .psc_min_threads = min(max(mdt_num_threads, MDT_MIN_THREADS),
3590 .psc_max_threads = MDT_MAX_THREADS,
3591 .psc_ctx_tags = LCT_MD_THREAD
3593 m->mdt_xmds_service =
3594 ptlrpc_init_svc_conf(&conf, mdt_xmds_handle,
3595 LUSTRE_MDT_NAME "_mds",
3596 procfs_entry, target_print_req,"mdt_xmds");
3598 if (m->mdt_xmds_service == NULL) {
3599 CERROR("failed to start readpage service\n");
3600 GOTO(err_mdt_svc, rc = -ENOMEM);
3603 rc = ptlrpc_start_threads(NULL, m->mdt_xmds_service);
3605 GOTO(err_mdt_svc, rc);
3610 mdt_stop_ptlrpc_service(m);
3615 static void mdt_stack_fini(const struct lu_env *env,
3616 struct mdt_device *m, struct lu_device *top)
3618 struct obd_device *obd = m->mdt_md_dev.md_lu_dev.ld_obd;
3619 struct lustre_cfg_bufs *bufs;
3620 struct lustre_cfg *lcfg;
3621 struct mdt_thread_info *info;
3625 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
3626 LASSERT(info != NULL);
3628 bufs = &info->mti_u.bufs;
3629 /* process cleanup, pass mdt obd name to get obd umount flags */
3630 lustre_cfg_bufs_reset(bufs, obd->obd_name);
3635 lustre_cfg_bufs_set_string(bufs, 1, flags);
3636 lcfg = lustre_cfg_new(LCFG_CLEANUP, bufs);
3638 CERROR("Cannot alloc lcfg!\n");
3643 top->ld_ops->ldo_process_config(env, top, lcfg);
3644 lustre_cfg_free(lcfg);
3646 lu_stack_fini(env, top);
3647 m->mdt_child = NULL;
3648 m->mdt_bottom = NULL;
3651 static struct lu_device *mdt_layer_setup(const struct lu_env *env,
3652 const char *typename,
3653 struct lu_device *child,
3654 struct lustre_cfg *cfg)
3656 const char *dev = lustre_cfg_string(cfg, 0);
3657 struct obd_type *type;
3658 struct lu_device_type *ldt;
3659 struct lu_device *d;
3664 type = class_get_type(typename);
3666 CERROR("Unknown type: '%s'\n", typename);
3667 GOTO(out, rc = -ENODEV);
3670 rc = lu_context_refill(&env->le_ctx);
3672 CERROR("Failure to refill context: '%d'\n", rc);
3676 if (env->le_ses != NULL) {
3677 rc = lu_context_refill(env->le_ses);
3679 CERROR("Failure to refill session: '%d'\n", rc);
3686 CERROR("type: '%s'\n", typename);
3687 GOTO(out_type, rc = -EINVAL);
3690 ldt->ldt_obd_type = type;
3691 d = ldt->ldt_ops->ldto_device_alloc(env, ldt, cfg);
3693 CERROR("Cannot allocate device: '%s'\n", typename);
3694 GOTO(out_type, rc = -ENODEV);
3697 LASSERT(child->ld_site);
3698 d->ld_site = child->ld_site;
3701 rc = ldt->ldt_ops->ldto_device_init(env, d, dev, child);
3703 CERROR("can't init device '%s', rc %d\n", typename, rc);
3704 GOTO(out_alloc, rc);
3711 ldt->ldt_ops->ldto_device_free(env, d);
3714 class_put_type(type);
3719 static int mdt_stack_init(const struct lu_env *env,
3720 struct mdt_device *m, struct lustre_cfg *cfg)
3722 struct lu_device *d = &m->mdt_md_dev.md_lu_dev;
3723 struct lu_device *tmp;
3724 struct md_device *md;
3728 /* init the stack */
3729 tmp = mdt_layer_setup(env, LUSTRE_OSD_NAME, d, cfg);
3731 RETURN(PTR_ERR(tmp));
3733 m->mdt_bottom = lu2dt_dev(tmp);
3735 tmp = mdt_layer_setup(env, LUSTRE_MDD_NAME, d, cfg);
3737 GOTO(out, rc = PTR_ERR(tmp));
3742 tmp = mdt_layer_setup(env, LUSTRE_CMM_NAME, d, cfg);
3744 GOTO(out, rc = PTR_ERR(tmp));
3747 /*set mdd upcall device*/
3748 md_upcall_dev_set(md, lu2md_dev(d));
3751 /*set cmm upcall device*/
3752 md_upcall_dev_set(md, &m->mdt_md_dev);
3754 m->mdt_child = lu2md_dev(d);
3756 /* process setup config */
3757 tmp = &m->mdt_md_dev.md_lu_dev;
3758 rc = tmp->ld_ops->ldo_process_config(env, tmp, cfg);
3761 /* fini from last known good lu_device */
3763 mdt_stack_fini(env, m, d);
3768 static void mdt_fini(const struct lu_env *env, struct mdt_device *m)
3770 struct md_device *next = m->mdt_child;
3771 struct lu_device *d = &m->mdt_md_dev.md_lu_dev;
3772 struct lu_site *ls = d->ld_site;
3773 struct obd_device *obd = m->mdt_md_dev.md_lu_dev.ld_obd;
3776 ping_evictor_stop();
3778 target_recovery_fini(obd);
3779 mdt_stop_ptlrpc_service(m);
3781 mdt_fs_cleanup(env, m);
3783 upcall_cache_cleanup(m->mdt_identity_cache);
3784 m->mdt_identity_cache = NULL;
3786 if (m->mdt_namespace != NULL) {
3787 ldlm_namespace_free(m->mdt_namespace, NULL, d->ld_obd->obd_force);
3788 d->ld_obd->obd_namespace = m->mdt_namespace = NULL;
3791 mdt_seq_fini(env, m);
3792 mdt_seq_fini_cli(m);
3793 mdt_fld_fini(env, m);
3795 ptlrpc_lprocfs_unregister_obd(d->ld_obd);
3796 lprocfs_obd_cleanup(d->ld_obd);
3798 sptlrpc_rule_set_free(&m->mdt_sptlrpc_rset);
3800 next->md_ops->mdo_init_capa_ctxt(env, next, 0, 0, 0, NULL);
3801 cfs_timer_disarm(&m->mdt_ck_timer);
3802 mdt_ck_thread_stop(m);
3804 /* finish the stack */
3805 mdt_stack_fini(env, m, md2lu_dev(m->mdt_child));
3812 LASSERT(atomic_read(&d->ld_ref) == 0);
3813 md_device_fini(&m->mdt_md_dev);
3818 static void fsoptions_to_mdt_flags(struct mdt_device *m, char *options)
3822 #ifdef CONFIG_FS_POSIX_ACL
3823 /* ACLs should be enabled by default (b=13829) */
3824 m->mdt_opts.mo_acl = 1;
3825 LCONSOLE_INFO("Enabling ACL\n");
3827 m->mdt_opts.mo_acl = 0;
3828 LCONSOLE_INFO("Disabling ACL\n");
3837 while (*p && *p != ',')
3841 if ((len == sizeof("user_xattr") - 1) &&
3842 (memcmp(options, "user_xattr", len) == 0)) {
3843 m->mdt_opts.mo_user_xattr = 1;
3844 LCONSOLE_INFO("Enabling user_xattr\n");
3845 } else if ((len == sizeof("nouser_xattr") - 1) &&
3846 (memcmp(options, "nouser_xattr", len) == 0)) {
3847 m->mdt_opts.mo_user_xattr = 0;
3848 LCONSOLE_INFO("Disabling user_xattr\n");
3849 } else if ((len == sizeof("noacl") - 1) &&
3850 (memcmp(options, "noacl", len) == 0)) {
3851 m->mdt_opts.mo_acl = 0;
3852 LCONSOLE_INFO("Disabling ACL\n");
3859 int mdt_postrecov(const struct lu_env *, struct mdt_device *);
3861 static int mdt_init0(const struct lu_env *env, struct mdt_device *m,
3862 struct lu_device_type *ldt, struct lustre_cfg *cfg)
3864 struct lprocfs_static_vars lvars;
3865 struct mdt_thread_info *info;
3866 struct obd_device *obd;
3867 const char *dev = lustre_cfg_string(cfg, 0);
3868 const char *num = lustre_cfg_string(cfg, 2);
3869 struct lustre_mount_info *lmi;
3870 struct lustre_sb_info *lsi;
3872 const char *identity_upcall = "NONE";
3876 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
3877 LASSERT(info != NULL);
3879 obd = class_name2obd(dev);
3880 LASSERT(obd != NULL);
3882 spin_lock_init(&m->mdt_transno_lock);
3884 m->mdt_max_mdsize = MAX_MD_SIZE;
3885 m->mdt_max_cookiesize = sizeof(struct llog_cookie);
3887 m->mdt_opts.mo_user_xattr = 0;
3888 m->mdt_opts.mo_acl = 0;
3889 lmi = server_get_mount_2(dev);
3891 CERROR("Cannot get mount info for %s!\n", dev);
3894 lsi = s2lsi(lmi->lmi_sb);
3895 fsoptions_to_mdt_flags(m, lsi->lsi_lmd->lmd_opts);
3896 server_put_mount_2(dev, lmi->lmi_mnt);
3899 m->mdt_sptlrpc_lock = RW_LOCK_UNLOCKED;
3900 sptlrpc_rule_set_init(&m->mdt_sptlrpc_rset);
3902 spin_lock_init(&m->mdt_ioepoch_lock);
3903 m->mdt_opts.mo_compat_resname = 0;
3904 m->mdt_capa_timeout = CAPA_TIMEOUT;
3905 m->mdt_capa_alg = CAPA_HMAC_ALG_SHA1;
3906 m->mdt_ck_timeout = CAPA_KEY_TIMEOUT;
3908 spin_lock_init(&m->mdt_client_bitmap_lock);
3914 md_device_init(&m->mdt_md_dev, ldt);
3915 m->mdt_md_dev.md_lu_dev.ld_ops = &mdt_lu_ops;
3916 m->mdt_md_dev.md_lu_dev.ld_obd = obd;
3917 /* set this lu_device to obd, because error handling need it */
3918 obd->obd_lu_dev = &m->mdt_md_dev.md_lu_dev;
3920 rc = lu_site_init(s, &m->mdt_md_dev.md_lu_dev);
3922 CERROR("Can't init lu_site, rc %d\n", rc);
3923 GOTO(err_free_site, rc);
3926 lprocfs_mdt_init_vars(&lvars);
3927 rc = lprocfs_obd_setup(obd, lvars.obd_vars);
3929 CERROR("Can't init lprocfs, rc %d\n", rc);
3930 GOTO(err_fini_site, rc);
3932 ptlrpc_lprocfs_register_obd(obd);
3934 rc = mdt_procfs_init(m, dev);
3936 CERROR("Can't init MDT lprocfs, rc %d\n", rc);
3937 GOTO(err_fini_proc, rc);
3940 /* set server index */
3942 s->ls_node_id = simple_strtol(num, NULL, 10);
3944 /* failover is the default
3945 * FIXME: we do not failout mds0/mgs, which may cause some problems.
3946 * assumed whose ls_node_id == 0 XXX
3948 obd->obd_replayable = 1;
3949 /* No connection accepted until configurations will finish */
3950 obd->obd_no_conn = 1;
3952 if (cfg->lcfg_bufcount > 4 && LUSTRE_CFG_BUFLEN(cfg, 4) > 0) {
3953 char *str = lustre_cfg_string(cfg, 4);
3954 if (strchr(str, 'n')) {
3955 CWARN("%s: recovery disabled\n", obd->obd_name);
3956 obd->obd_replayable = 0;
3960 /* init the stack */
3961 rc = mdt_stack_init(env, m, cfg);
3963 CERROR("Can't init device stack, rc %d\n", rc);
3964 GOTO(err_fini_proc, rc);
3967 rc = mdt_fld_init(env, obd->obd_name, m);
3969 GOTO(err_fini_stack, rc);
3971 rc = mdt_seq_init(env, obd->obd_name, m);
3973 GOTO(err_fini_fld, rc);
3975 snprintf(info->mti_u.ns_name, sizeof info->mti_u.ns_name,
3976 LUSTRE_MDT_NAME"-%p", m);
3977 m->mdt_namespace = ldlm_namespace_new(obd, info->mti_u.ns_name,
3978 LDLM_NAMESPACE_SERVER,
3979 LDLM_NAMESPACE_GREEDY);
3980 if (m->mdt_namespace == NULL)
3981 GOTO(err_fini_seq, rc = -ENOMEM);
3983 ldlm_register_intent(m->mdt_namespace, mdt_intent_policy);
3984 /* set obd_namespace for compatibility with old code */
3985 obd->obd_namespace = m->mdt_namespace;
3987 /* XXX: to support suppgid for ACL, we enable identity_upcall
3988 * by default, otherwise, maybe got unexpected -EACCESS. */
3989 if (m->mdt_opts.mo_acl)
3990 identity_upcall = MDT_IDENTITY_UPCALL_PATH;
3992 m->mdt_identity_cache = upcall_cache_init(obd->obd_name, identity_upcall,
3993 &mdt_identity_upcall_cache_ops);
3994 if (IS_ERR(m->mdt_identity_cache)) {
3995 rc = PTR_ERR(m->mdt_identity_cache);
3996 m->mdt_identity_cache = NULL;
3997 GOTO(err_free_ns, rc);
4000 cfs_timer_init(&m->mdt_ck_timer, mdt_ck_timer_callback, m);
4002 rc = mdt_ck_thread_start(m);
4004 GOTO(err_free_ns, rc);
4006 rc = mdt_fs_setup(env, m, obd);
4010 target_recovery_init(obd, mdt_recovery_handle);
4012 rc = mdt_start_ptlrpc_service(m);
4014 GOTO(err_fs_cleanup, rc);
4016 ping_evictor_start();
4018 rc = lu_site_init_finish(s);
4020 GOTO(err_stop_service, rc);
4022 if (obd->obd_recovering == 0)
4023 mdt_postrecov(env, m);
4025 mdt_init_capa_ctxt(env, m);
4027 /* Reduce the initial timeout on an MDS because it doesn't need such
4028 * a long timeout as an OST does. Adaptive timeouts will adjust this
4029 * value appropriately. */
4030 if (ldlm_timeout == LDLM_TIMEOUT_DEFAULT)
4031 ldlm_timeout = MDS_LDLM_TIMEOUT_DEFAULT;
4036 ping_evictor_stop();
4037 mdt_stop_ptlrpc_service(m);
4039 target_recovery_fini(obd);
4040 mdt_fs_cleanup(env, m);
4042 cfs_timer_disarm(&m->mdt_ck_timer);
4043 mdt_ck_thread_stop(m);
4045 upcall_cache_cleanup(m->mdt_identity_cache);
4046 m->mdt_identity_cache = NULL;
4047 ldlm_namespace_free(m->mdt_namespace, NULL, 0);
4048 obd->obd_namespace = m->mdt_namespace = NULL;
4050 mdt_seq_fini(env, m);
4052 mdt_fld_fini(env, m);
4054 mdt_stack_fini(env, m, md2lu_dev(m->mdt_child));
4057 ptlrpc_lprocfs_unregister_obd(obd);
4058 lprocfs_obd_cleanup(obd);
4064 md_device_fini(&m->mdt_md_dev);
4068 /* used by MGS to process specific configurations */
4069 static int mdt_process_config(const struct lu_env *env,
4070 struct lu_device *d, struct lustre_cfg *cfg)
4072 struct mdt_device *m = mdt_dev(d);
4073 struct md_device *md_next = m->mdt_child;
4074 struct lu_device *next = md2lu_dev(md_next);
4078 switch (cfg->lcfg_command) {
4079 case LCFG_SPTLRPC_CONF: {
4080 struct sptlrpc_conf_log *log;
4081 struct sptlrpc_rule_set tmp_rset;
4083 log = sptlrpc_conf_log_extract(cfg);
4089 sptlrpc_rule_set_init(&tmp_rset);
4091 rc = sptlrpc_rule_set_from_log(&tmp_rset, log);
4093 CERROR("mdt %p: failed get sptlrpc rules: %d\n", m, rc);
4097 write_lock(&m->mdt_sptlrpc_lock);
4098 sptlrpc_rule_set_free(&m->mdt_sptlrpc_rset);
4099 m->mdt_sptlrpc_rset = tmp_rset;
4100 write_unlock(&m->mdt_sptlrpc_lock);
4102 sptlrpc_target_update_exp_flavor(
4103 md2lu_dev(&m->mdt_md_dev)->ld_obd, &tmp_rset);
4108 struct lprocfs_static_vars lvars;
4109 struct obd_device *obd = d->ld_obd;
4111 lprocfs_mdt_init_vars(&lvars);
4112 rc = class_process_proc_param(PARAM_MDT, lvars.obd_vars, cfg, obd);
4114 /* others are passed further */
4115 rc = next->ld_ops->ldo_process_config(env, next, cfg);
4120 * Add mdc hook to get first MDT uuid and connect it to
4121 * ls->controller to use for seq manager.
4123 rc = next->ld_ops->ldo_process_config(env, next, cfg);
4125 CERROR("Can't add mdc, rc %d\n", rc);
4127 rc = mdt_seq_init_cli(env, mdt_dev(d), cfg);
4130 /* others are passed further */
4131 rc = next->ld_ops->ldo_process_config(env, next, cfg);
4137 static struct lu_object *mdt_object_alloc(const struct lu_env *env,
4138 const struct lu_object_header *hdr,
4139 struct lu_device *d)
4141 struct mdt_object *mo;
4147 struct lu_object *o;
4148 struct lu_object_header *h;
4150 o = &mo->mot_obj.mo_lu;
4151 h = &mo->mot_header;
4152 lu_object_header_init(h);
4153 lu_object_init(o, h, d);
4154 lu_object_add_top(h, o);
4155 o->lo_ops = &mdt_obj_ops;
4161 static int mdt_object_init(const struct lu_env *env, struct lu_object *o)
4163 struct mdt_device *d = mdt_dev(o->lo_dev);
4164 struct lu_device *under;
4165 struct lu_object *below;
4169 CDEBUG(D_INFO, "object init, fid = "DFID"\n",
4170 PFID(lu_object_fid(o)));
4172 under = &d->mdt_child->md_lu_dev;
4173 below = under->ld_ops->ldo_object_alloc(env, o->lo_header, under);
4174 if (below != NULL) {
4175 lu_object_add(o, below);
4182 static void mdt_object_free(const struct lu_env *env, struct lu_object *o)
4184 struct mdt_object *mo = mdt_obj(o);
4185 struct lu_object_header *h;
4189 CDEBUG(D_INFO, "object free, fid = "DFID"\n",
4190 PFID(lu_object_fid(o)));
4193 lu_object_header_fini(h);
4198 static int mdt_object_print(const struct lu_env *env, void *cookie,
4199 lu_printer_t p, const struct lu_object *o)
4201 return (*p)(env, cookie, LUSTRE_MDT_NAME"-object@%p", o);
4204 static struct lu_device_operations mdt_lu_ops = {
4205 .ldo_object_alloc = mdt_object_alloc,
4206 .ldo_process_config = mdt_process_config
4209 static struct lu_object_operations mdt_obj_ops = {
4210 .loo_object_init = mdt_object_init,
4211 .loo_object_free = mdt_object_free,
4212 .loo_object_print = mdt_object_print
4215 /* mds_connect_internal */
4216 static int mdt_connect_internal(struct obd_export *exp,
4217 struct mdt_device *mdt,
4218 struct obd_connect_data *data)
4223 data->ocd_connect_flags &= MDT_CONNECT_SUPPORTED;
4224 data->ocd_ibits_known &= MDS_INODELOCK_FULL;
4226 /* If no known bits (which should not happen, probably,
4227 as everybody should support LOOKUP and UPDATE bits at least)
4228 revert to compat mode with plain locks. */
4229 if (!data->ocd_ibits_known &&
4230 data->ocd_connect_flags & OBD_CONNECT_IBITS)
4231 data->ocd_connect_flags &= ~OBD_CONNECT_IBITS;
4233 if (!mdt->mdt_opts.mo_acl)
4234 data->ocd_connect_flags &= ~OBD_CONNECT_ACL;
4236 if (!mdt->mdt_opts.mo_user_xattr)
4237 data->ocd_connect_flags &= ~OBD_CONNECT_XATTR;
4239 if (!mdt->mdt_opts.mo_mds_capa)
4240 data->ocd_connect_flags &= ~OBD_CONNECT_MDS_CAPA;
4242 if (!mdt->mdt_opts.mo_oss_capa)
4243 data->ocd_connect_flags &= ~OBD_CONNECT_OSS_CAPA;
4245 spin_lock(&exp->exp_lock);
4246 exp->exp_connect_flags = data->ocd_connect_flags;
4247 spin_unlock(&exp->exp_lock);
4248 data->ocd_version = LUSTRE_VERSION_CODE;
4249 exp->exp_mdt_data.med_ibits_known = data->ocd_ibits_known;
4253 if (mdt->mdt_opts.mo_acl &&
4254 ((exp->exp_connect_flags & OBD_CONNECT_ACL) == 0)) {
4255 CWARN("%s: MDS requires ACL support but client does not\n",
4256 mdt->mdt_md_dev.md_lu_dev.ld_obd->obd_name);
4261 flags = OBD_CONNECT_LCL_CLIENT | OBD_CONNECT_RMT_CLIENT;
4262 if ((exp->exp_connect_flags & flags) == flags) {
4263 CWARN("%s: both local and remote client flags are set\n",
4264 mdt->mdt_md_dev.md_lu_dev.ld_obd->obd_name);
4268 if (mdt->mdt_opts.mo_mds_capa &&
4269 ((exp->exp_connect_flags & OBD_CONNECT_MDS_CAPA) == 0)) {
4270 CWARN("%s: MDS requires capability support, but client not\n",
4271 mdt->mdt_md_dev.md_lu_dev.ld_obd->obd_name);
4275 if (mdt->mdt_opts.mo_oss_capa &&
4276 ((exp->exp_connect_flags & OBD_CONNECT_OSS_CAPA) == 0)) {
4277 CWARN("%s: MDS requires OSS capability support, "
4279 mdt->mdt_md_dev.md_lu_dev.ld_obd->obd_name);
4283 if ((exp->exp_connect_flags & OBD_CONNECT_FID) == 0) {
4284 CWARN("%s: MDS requires FID support, but client not\n",
4285 mdt->mdt_md_dev.md_lu_dev.ld_obd->obd_name);
4292 /* mds_connect copy */
4293 static int mdt_obd_connect(const struct lu_env *env,
4294 struct lustre_handle *conn, struct obd_device *obd,
4295 struct obd_uuid *cluuid,
4296 struct obd_connect_data *data,
4299 struct mdt_thread_info *info;
4300 struct lsd_client_data *lcd;
4301 struct obd_export *exp;
4302 struct mdt_device *mdt;
4303 struct ptlrpc_request *req;
4307 LASSERT(env != NULL);
4308 if (!conn || !obd || !cluuid)
4311 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
4312 req = info->mti_pill->rc_req;
4313 mdt = mdt_dev(obd->obd_lu_dev);
4315 rc = class_connect(conn, obd, cluuid);
4319 exp = class_conn2export(conn);
4320 LASSERT(exp != NULL);
4322 CDEBUG(D_SEC, "from %s\n", sptlrpc_part2name(req->rq_sp_from));
4324 spin_lock(&exp->exp_lock);
4325 exp->exp_sp_peer = req->rq_sp_from;
4327 read_lock(&mdt->mdt_sptlrpc_lock);
4328 sptlrpc_rule_set_choose(&mdt->mdt_sptlrpc_rset, exp->exp_sp_peer,
4329 req->rq_peer.nid, &exp->exp_flvr);
4330 read_unlock(&mdt->mdt_sptlrpc_lock);
4332 if (exp->exp_flvr.sf_rpc != req->rq_flvr.sf_rpc) {
4333 CERROR("invalid rpc flavor %x, expect %x, from %s\n",
4334 req->rq_flvr.sf_rpc, exp->exp_flvr.sf_rpc,
4335 libcfs_nid2str(req->rq_peer.nid));
4336 exp->exp_flvr.sf_rpc = SPTLRPC_FLVR_INVALID;
4337 spin_unlock(&exp->exp_lock);
4340 spin_unlock(&exp->exp_lock);
4342 rc = mdt_connect_internal(exp, mdt, data);
4346 struct mdt_thread_info *mti;
4347 mti = lu_context_key_get(&env->le_ctx,
4349 LASSERT(mti != NULL);
4351 memcpy(lcd->lcd_uuid, cluuid, sizeof lcd->lcd_uuid);
4352 exp->exp_mdt_data.med_lcd = lcd;
4353 rc = mdt_client_new(env, mdt);
4356 exp->exp_mdt_data.med_lcd = NULL;
4363 class_disconnect(exp);
4365 class_export_put(exp);
4370 static int mdt_obd_reconnect(const struct lu_env *env,
4371 struct obd_export *exp, struct obd_device *obd,
4372 struct obd_uuid *cluuid,
4373 struct obd_connect_data *data)
4375 struct mdt_thread_info *info;
4376 struct mdt_device *mdt;
4377 struct ptlrpc_request *req;
4381 if (exp == NULL || obd == NULL || cluuid == NULL)
4384 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
4385 req = info->mti_pill->rc_req;
4386 mdt = mdt_dev(obd->obd_lu_dev);
4388 CDEBUG(D_SEC, "from %s\n", sptlrpc_part2name(req->rq_sp_from));
4390 spin_lock(&exp->exp_lock);
4391 if (exp->exp_flvr.sf_rpc == SPTLRPC_FLVR_INVALID) {
4392 exp->exp_sp_peer = req->rq_sp_from;
4394 read_lock(&mdt->mdt_sptlrpc_lock);
4395 sptlrpc_rule_set_choose(&mdt->mdt_sptlrpc_rset,
4397 req->rq_peer.nid, &exp->exp_flvr);
4398 read_unlock(&mdt->mdt_sptlrpc_lock);
4400 if (exp->exp_flvr.sf_rpc != req->rq_flvr.sf_rpc) {
4401 CERROR("invalid rpc flavor %x, expect %x, from %s\n",
4402 req->rq_flvr.sf_rpc, exp->exp_flvr.sf_rpc,
4403 libcfs_nid2str(req->rq_peer.nid));
4404 exp->exp_flvr.sf_rpc = SPTLRPC_FLVR_INVALID;
4405 spin_unlock(&exp->exp_lock);
4409 spin_unlock(&exp->exp_lock);
4411 rc = mdt_connect_internal(exp, mdt_dev(obd->obd_lu_dev), data);
4416 static int mdt_obd_disconnect(struct obd_export *exp)
4418 struct mdt_device *mdt = mdt_dev(exp->exp_obd->obd_lu_dev);
4423 class_export_get(exp);
4425 /* Disconnect early so that clients can't keep using export */
4426 rc = class_disconnect(exp);
4427 if (mdt->mdt_namespace != NULL || exp->exp_obd->obd_namespace != NULL)
4428 ldlm_cancel_locks_for_export(exp);
4430 /* complete all outstanding replies */
4431 spin_lock(&exp->exp_lock);
4432 while (!list_empty(&exp->exp_outstanding_replies)) {
4433 struct ptlrpc_reply_state *rs =
4434 list_entry(exp->exp_outstanding_replies.next,
4435 struct ptlrpc_reply_state, rs_exp_list);
4436 struct ptlrpc_service *svc = rs->rs_service;
4438 spin_lock(&svc->srv_lock);
4439 list_del_init(&rs->rs_exp_list);
4440 ptlrpc_schedule_difficult_reply(rs);
4441 spin_unlock(&svc->srv_lock);
4443 spin_unlock(&exp->exp_lock);
4445 class_export_put(exp);
4449 /* FIXME: Can we avoid using these two interfaces? */
4450 static int mdt_init_export(struct obd_export *exp)
4452 struct mdt_export_data *med = &exp->exp_mdt_data;
4455 CFS_INIT_LIST_HEAD(&med->med_open_head);
4456 spin_lock_init(&med->med_open_lock);
4457 sema_init(&med->med_idmap_sem, 1);
4458 med->med_idmap = NULL;
4459 spin_lock(&exp->exp_lock);
4460 exp->exp_connecting = 1;
4461 spin_unlock(&exp->exp_lock);
4465 static int mdt_destroy_export(struct obd_export *export)
4467 struct mdt_export_data *med;
4468 struct obd_device *obd = export->exp_obd;
4469 struct mdt_device *mdt;
4470 struct mdt_thread_info *info;
4478 med = &export->exp_mdt_data;
4479 if (med->med_rmtclient)
4480 mdt_cleanup_idmap(med);
4482 target_destroy_export(export);
4484 if (obd_uuid_equals(&export->exp_client_uuid, &obd->obd_uuid))
4487 mdt = mdt_dev(obd->obd_lu_dev);
4488 LASSERT(mdt != NULL);
4490 rc = lu_env_init(&env, NULL, LCT_MD_THREAD);
4494 info = lu_context_key_get(&env.le_ctx, &mdt_thread_key);
4495 LASSERT(info != NULL);
4496 memset(info, 0, sizeof *info);
4497 info->mti_env = &env;
4498 info->mti_mdt = mdt;
4499 info->mti_exp = export;
4501 ma = &info->mti_attr;
4502 lmm_size = ma->ma_lmm_size = mdt->mdt_max_mdsize;
4503 cookie_size = ma->ma_cookie_size = mdt->mdt_max_cookiesize;
4504 OBD_ALLOC(ma->ma_lmm, lmm_size);
4505 OBD_ALLOC(ma->ma_cookie, cookie_size);
4507 if (ma->ma_lmm == NULL || ma->ma_cookie == NULL)
4508 GOTO(out, rc = -ENOMEM);
4509 ma->ma_need = MA_LOV | MA_COOKIE;
4511 /* Close any open files (which may also cause orphan unlinking). */
4512 spin_lock(&med->med_open_lock);
4513 while (!list_empty(&med->med_open_head)) {
4514 struct list_head *tmp = med->med_open_head.next;
4515 struct mdt_file_data *mfd =
4516 list_entry(tmp, struct mdt_file_data, mfd_list);
4518 /* Remove mfd handle so it can't be found again.
4519 * We are consuming the mfd_list reference here. */
4520 class_handle_unhash(&mfd->mfd_handle);
4521 list_del_init(&mfd->mfd_list);
4522 spin_unlock(&med->med_open_lock);
4523 mdt_mfd_close(info, mfd);
4524 /* TODO: if we close the unlinked file,
4525 * we need to remove it's objects from OST */
4526 memset(&ma->ma_attr, 0, sizeof(ma->ma_attr));
4527 spin_lock(&med->med_open_lock);
4528 ma->ma_lmm_size = lmm_size;
4529 ma->ma_cookie_size = cookie_size;
4530 ma->ma_need = MA_LOV | MA_COOKIE;
4533 spin_unlock(&med->med_open_lock);
4534 info->mti_mdt = NULL;
4535 mdt_client_del(&env, mdt);
4540 OBD_FREE(ma->ma_lmm, lmm_size);
4544 OBD_FREE(ma->ma_cookie, cookie_size);
4545 ma->ma_cookie = NULL;
4552 static void mdt_allow_cli(struct mdt_device *m, unsigned int flag)
4554 if (flag & CONFIG_LOG)
4555 m->mdt_fl_cfglog = 1;
4556 if (flag & CONFIG_SYNC)
4557 m->mdt_fl_synced = 1;
4559 if (m->mdt_fl_cfglog /* bz11778: && m->mdt_fl_synced */)
4560 /* Open for clients */
4561 m->mdt_md_dev.md_lu_dev.ld_obd->obd_no_conn = 0;
4564 static int mdt_upcall(const struct lu_env *env, struct md_device *md,
4565 enum md_upcall_event ev)
4567 struct mdt_device *m = mdt_dev(&md->md_lu_dev);
4568 struct md_device *next = m->mdt_child;
4569 struct mdt_thread_info *mti;
4575 rc = next->md_ops->mdo_maxsize_get(env, next,
4577 &m->mdt_max_cookiesize);
4578 CDEBUG(D_INFO, "get max mdsize %d max cookiesize %d\n",
4579 m->mdt_max_mdsize, m->mdt_max_cookiesize);
4580 mdt_allow_cli(m, CONFIG_SYNC);
4583 mti = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
4584 mti->mti_no_need_trans = 1;
4585 CDEBUG(D_INFO, "disable mdt trans for this thread\n");
4588 /* Check that MDT is not yet configured */
4589 LASSERT(!m->mdt_fl_cfglog);
4592 CERROR("invalid event\n");
4599 static int mdt_obd_notify(struct obd_device *host,
4600 struct obd_device *watched,
4601 enum obd_notify_event ev, void *data)
4606 case OBD_NOTIFY_CONFIG:
4607 mdt_allow_cli(mdt_dev(host->obd_lu_dev), (unsigned long)data);
4610 CDEBUG(D_INFO, "Unhandled notification %#x\n", ev);
4615 static int mdt_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
4616 void *karg, void *uarg)
4619 struct obd_device *obd= exp->exp_obd;
4620 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
4621 struct dt_device *dt = mdt->mdt_bottom;
4625 CDEBUG(D_IOCTL, "handling ioctl cmd %#x\n", cmd);
4626 rc = lu_env_init(&env, NULL, LCT_MD_THREAD);
4632 rc = dt->dd_ops->dt_sync(&env, dt);
4634 case OBD_IOC_SET_READONLY:
4635 rc = dt->dd_ops->dt_sync(&env, dt);
4636 dt->dd_ops->dt_ro(&env, dt);
4638 case OBD_IOC_ABORT_RECOVERY:
4639 CERROR("Aborting recovery for device %s\n", obd->obd_name);
4640 target_stop_recovery_thread(obd);
4644 CERROR("Not supported cmd = %d for device %s\n",
4645 cmd, obd->obd_name);
4653 int mdt_postrecov(const struct lu_env *env, struct mdt_device *mdt)
4655 struct lu_device *ld = md2lu_dev(mdt->mdt_child);
4656 struct obd_device *obd = mdt->mdt_md_dev.md_lu_dev.ld_obd;
4659 /* if some clients didn't participate in recovery then we can possibly
4660 * lost sequence. Now we should increase sequence for safe value */
4661 lost = obd->obd_max_recoverable_clients - obd->obd_connected_clients;
4662 mdt_seq_adjust(env, mdt, lost);
4664 rc = ld->ld_ops->ldo_recovery_complete(env, ld);
4668 int mdt_obd_postrecov(struct obd_device *obd)
4673 rc = lu_env_init(&env, NULL, LCT_MD_THREAD);
4676 rc = mdt_postrecov(&env, mdt_dev(obd->obd_lu_dev));
4681 static struct obd_ops mdt_obd_device_ops = {
4682 .o_owner = THIS_MODULE,
4683 .o_connect = mdt_obd_connect,
4684 .o_reconnect = mdt_obd_reconnect,
4685 .o_disconnect = mdt_obd_disconnect,
4686 .o_init_export = mdt_init_export,
4687 .o_destroy_export = mdt_destroy_export,
4688 .o_iocontrol = mdt_iocontrol,
4689 .o_postrecov = mdt_obd_postrecov,
4690 .o_notify = mdt_obd_notify
4693 static struct lu_device* mdt_device_fini(const struct lu_env *env,
4694 struct lu_device *d)
4696 struct mdt_device *m = mdt_dev(d);
4703 static struct lu_device *mdt_device_free(const struct lu_env *env,
4704 struct lu_device *d)
4706 struct mdt_device *m = mdt_dev(d);
4713 static struct lu_device *mdt_device_alloc(const struct lu_env *env,
4714 struct lu_device_type *t,
4715 struct lustre_cfg *cfg)
4717 struct lu_device *l;
4718 struct mdt_device *m;
4724 l = &m->mdt_md_dev.md_lu_dev;
4725 rc = mdt_init0(env, m, t, cfg);
4731 md_upcall_init(&m->mdt_md_dev, mdt_upcall);
4733 l = ERR_PTR(-ENOMEM);
4737 /* context key constructor/destructor: mdt_key_init, mdt_key_fini */
4738 LU_KEY_INIT_FINI(mdt, struct mdt_thread_info);
4740 /* context key: mdt_thread_key */
4741 LU_CONTEXT_KEY_DEFINE(mdt, LCT_MD_THREAD);
4743 /* context key constructor/destructor: mdt_txn_key_init, mdt_txn_key_fini */
4744 LU_KEY_INIT_FINI(mdt_txn, struct mdt_txn_info);
4746 struct lu_context_key mdt_txn_key = {
4747 .lct_tags = LCT_TX_HANDLE,
4748 .lct_init = mdt_txn_key_init,
4749 .lct_fini = mdt_txn_key_fini
4752 struct md_ucred *mdt_ucred(const struct mdt_thread_info *info)
4754 return md_ucred(info->mti_env);
4757 /* type constructor/destructor: mdt_type_init, mdt_type_fini */
4758 LU_TYPE_INIT_FINI(mdt, &mdt_thread_key, &mdt_txn_key);
4760 static struct lu_device_type_operations mdt_device_type_ops = {
4761 .ldto_init = mdt_type_init,
4762 .ldto_fini = mdt_type_fini,
4764 .ldto_device_alloc = mdt_device_alloc,
4765 .ldto_device_free = mdt_device_free,
4766 .ldto_device_fini = mdt_device_fini
4769 static struct lu_device_type mdt_device_type = {
4770 .ldt_tags = LU_DEVICE_MD,
4771 .ldt_name = LUSTRE_MDT_NAME,
4772 .ldt_ops = &mdt_device_type_ops,
4773 .ldt_ctx_tags = LCT_MD_THREAD
4776 static int __init mdt_mod_init(void)
4778 struct lprocfs_static_vars lvars;
4781 mdt_num_threads = MDT_NUM_THREADS;
4782 lprocfs_mdt_init_vars(&lvars);
4783 rc = class_register_type(&mdt_obd_device_ops, NULL,
4784 lvars.module_vars, LUSTRE_MDT_NAME,
4790 static void __exit mdt_mod_exit(void)
4792 class_unregister_type(LUSTRE_MDT_NAME);
4796 #define DEF_HNDL(prefix, base, suffix, flags, opc, fn, fmt) \
4797 [prefix ## _ ## opc - prefix ## _ ## base] = { \
4799 .mh_fail_id = OBD_FAIL_ ## prefix ## _ ## opc ## suffix, \
4800 .mh_opc = prefix ## _ ## opc, \
4801 .mh_flags = flags, \
4806 #define DEF_MDT_HNDL(flags, name, fn, fmt) \
4807 DEF_HNDL(MDS, GETATTR, _NET, flags, name, fn, fmt)
4809 #define DEF_SEQ_HNDL(flags, name, fn, fmt) \
4810 DEF_HNDL(SEQ, QUERY, _NET, flags, name, fn, fmt)
4812 #define DEF_FLD_HNDL(flags, name, fn, fmt) \
4813 DEF_HNDL(FLD, QUERY, _NET, flags, name, fn, fmt)
4815 * Request with a format known in advance
4817 #define DEF_MDT_HNDL_F(flags, name, fn) \
4818 DEF_HNDL(MDS, GETATTR, _NET, flags, name, fn, &RQF_MDS_ ## name)
4820 #define DEF_SEQ_HNDL_F(flags, name, fn) \
4821 DEF_HNDL(SEQ, QUERY, _NET, flags, name, fn, &RQF_SEQ_ ## name)
4823 #define DEF_FLD_HNDL_F(flags, name, fn) \
4824 DEF_HNDL(FLD, QUERY, _NET, flags, name, fn, &RQF_FLD_ ## name)
4826 * Request with a format we do not yet know
4828 #define DEF_MDT_HNDL_0(flags, name, fn) \
4829 DEF_HNDL(MDS, GETATTR, _NET, flags, name, fn, NULL)
4831 static struct mdt_handler mdt_mds_ops[] = {
4832 DEF_MDT_HNDL_F(0, CONNECT, mdt_connect),
4833 DEF_MDT_HNDL_F(0, DISCONNECT, mdt_disconnect),
4834 DEF_MDT_HNDL_F(0, SET_INFO, mdt_set_info),
4835 DEF_MDT_HNDL_F(0 |HABEO_REFERO, GETSTATUS, mdt_getstatus),
4836 DEF_MDT_HNDL_F(HABEO_CORPUS, GETATTR, mdt_getattr),
4837 DEF_MDT_HNDL_F(HABEO_CORPUS|HABEO_REFERO, GETATTR_NAME, mdt_getattr_name),
4838 DEF_MDT_HNDL_F(HABEO_CORPUS, GETXATTR, mdt_getxattr),
4839 DEF_MDT_HNDL_F(0 |HABEO_REFERO, STATFS, mdt_statfs),
4840 DEF_MDT_HNDL_F(0 |MUTABOR, REINT, mdt_reint),
4841 DEF_MDT_HNDL_F(HABEO_CORPUS, CLOSE, mdt_close),
4842 DEF_MDT_HNDL_F(HABEO_CORPUS, DONE_WRITING, mdt_done_writing),
4843 DEF_MDT_HNDL_F(0 |HABEO_REFERO, PIN, mdt_pin),
4844 DEF_MDT_HNDL_0(0, SYNC, mdt_sync),
4845 DEF_MDT_HNDL_F(HABEO_CORPUS|HABEO_REFERO, IS_SUBDIR, mdt_is_subdir),
4846 DEF_MDT_HNDL_F(0, QUOTACHECK, mdt_quotacheck_handle),
4847 DEF_MDT_HNDL_F(0, QUOTACTL, mdt_quotactl_handle)
4850 #define DEF_OBD_HNDL(flags, name, fn) \
4851 DEF_HNDL(OBD, PING, _NET, flags, name, fn, NULL)
4854 static struct mdt_handler mdt_obd_ops[] = {
4855 DEF_OBD_HNDL(0, PING, mdt_obd_ping),
4856 DEF_OBD_HNDL(0, LOG_CANCEL, mdt_obd_log_cancel),
4857 DEF_OBD_HNDL(0, QC_CALLBACK, mdt_obd_qc_callback)
4860 #define DEF_DLM_HNDL_0(flags, name, fn) \
4861 DEF_HNDL(LDLM, ENQUEUE, , flags, name, fn, NULL)
4862 #define DEF_DLM_HNDL_F(flags, name, fn) \
4863 DEF_HNDL(LDLM, ENQUEUE, , flags, name, fn, &RQF_LDLM_ ## name)
4865 static struct mdt_handler mdt_dlm_ops[] = {
4866 DEF_DLM_HNDL_F(HABEO_CLAVIS, ENQUEUE, mdt_enqueue),
4867 DEF_DLM_HNDL_0(HABEO_CLAVIS, CONVERT, mdt_convert),
4868 DEF_DLM_HNDL_0(0, BL_CALLBACK, mdt_bl_callback),
4869 DEF_DLM_HNDL_0(0, CP_CALLBACK, mdt_cp_callback)
4872 static struct mdt_handler mdt_llog_ops[] = {
4875 #define DEF_SEC_CTX_HNDL(name, fn) \
4876 DEF_HNDL(SEC_CTX, INIT, _NET, 0, name, fn, NULL)
4878 static struct mdt_handler mdt_sec_ctx_ops[] = {
4879 DEF_SEC_CTX_HNDL(INIT, mdt_sec_ctx_handle),
4880 DEF_SEC_CTX_HNDL(INIT_CONT, mdt_sec_ctx_handle),
4881 DEF_SEC_CTX_HNDL(FINI, mdt_sec_ctx_handle)
4884 static struct mdt_opc_slice mdt_regular_handlers[] = {
4886 .mos_opc_start = MDS_GETATTR,
4887 .mos_opc_end = MDS_LAST_OPC,
4888 .mos_hs = mdt_mds_ops
4891 .mos_opc_start = OBD_PING,
4892 .mos_opc_end = OBD_LAST_OPC,
4893 .mos_hs = mdt_obd_ops
4896 .mos_opc_start = LDLM_ENQUEUE,
4897 .mos_opc_end = LDLM_LAST_OPC,
4898 .mos_hs = mdt_dlm_ops
4901 .mos_opc_start = LLOG_ORIGIN_HANDLE_CREATE,
4902 .mos_opc_end = LLOG_LAST_OPC,
4903 .mos_hs = mdt_llog_ops
4906 .mos_opc_start = SEC_CTX_INIT,
4907 .mos_opc_end = SEC_LAST_OPC,
4908 .mos_hs = mdt_sec_ctx_ops
4915 static struct mdt_handler mdt_readpage_ops[] = {
4916 DEF_MDT_HNDL_F(0, CONNECT, mdt_connect),
4917 DEF_MDT_HNDL_F(HABEO_CORPUS|HABEO_REFERO, READPAGE, mdt_readpage),
4918 #ifdef HAVE_SPLIT_SUPPORT
4919 DEF_MDT_HNDL_F(HABEO_CORPUS|HABEO_REFERO, WRITEPAGE, mdt_writepage),
4923 * XXX: this is ugly and should be fixed one day, see mdc_close() for
4924 * detailed comments. --umka
4926 DEF_MDT_HNDL_F(HABEO_CORPUS, CLOSE, mdt_close),
4927 DEF_MDT_HNDL_F(HABEO_CORPUS, DONE_WRITING, mdt_done_writing),
4930 static struct mdt_opc_slice mdt_readpage_handlers[] = {
4932 .mos_opc_start = MDS_GETATTR,
4933 .mos_opc_end = MDS_LAST_OPC,
4934 .mos_hs = mdt_readpage_ops
4941 static struct mdt_handler mdt_xmds_ops[] = {
4942 DEF_MDT_HNDL_F(0, CONNECT, mdt_connect),
4943 DEF_MDT_HNDL_F(HABEO_CORPUS , GETATTR, mdt_getattr),
4944 DEF_MDT_HNDL_F(0 | MUTABOR , REINT, mdt_reint),
4945 DEF_MDT_HNDL_F(HABEO_CORPUS|HABEO_REFERO, IS_SUBDIR, mdt_is_subdir),
4948 static struct mdt_opc_slice mdt_xmds_handlers[] = {
4950 .mos_opc_start = MDS_GETATTR,
4951 .mos_opc_end = MDS_LAST_OPC,
4952 .mos_hs = mdt_xmds_ops
4955 .mos_opc_start = OBD_PING,
4956 .mos_opc_end = OBD_LAST_OPC,
4957 .mos_hs = mdt_obd_ops
4960 .mos_opc_start = SEC_CTX_INIT,
4961 .mos_opc_end = SEC_LAST_OPC,
4962 .mos_hs = mdt_sec_ctx_ops
4969 static struct mdt_handler mdt_seq_ops[] = {
4970 DEF_SEQ_HNDL_F(0, QUERY, (int (*)(struct mdt_thread_info *))seq_query)
4973 static struct mdt_opc_slice mdt_seq_handlers[] = {
4975 .mos_opc_start = SEQ_QUERY,
4976 .mos_opc_end = SEQ_LAST_OPC,
4977 .mos_hs = mdt_seq_ops
4984 static struct mdt_handler mdt_fld_ops[] = {
4985 DEF_FLD_HNDL_F(0, QUERY, (int (*)(struct mdt_thread_info *))fld_query)
4988 static struct mdt_opc_slice mdt_fld_handlers[] = {
4990 .mos_opc_start = FLD_QUERY,
4991 .mos_opc_end = FLD_LAST_OPC,
4992 .mos_hs = mdt_fld_ops
4999 MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");
5000 MODULE_DESCRIPTION("Lustre Meta-data Target ("LUSTRE_MDT_NAME")");
5001 MODULE_LICENSE("GPL");
5003 CFS_MODULE_PARM(mdt_num_threads, "ul", ulong, 0444,
5004 "number of mdt service threads to start");
5006 cfs_module(mdt, "0.2.0", mdt_mod_init, mdt_mod_exit);