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 /* this should sync the whole device */
1549 static int mdt_device_sync(const struct lu_env *env, struct mdt_device *mdt)
1551 struct dt_device *dt = mdt->mdt_bottom;
1555 rc = dt->dd_ops->dt_sync(env, dt);
1559 /* this should sync this object */
1560 static int mdt_object_sync(struct mdt_thread_info *info)
1562 struct md_object *next;
1566 if (!mdt_object_exists(info->mti_object)) {
1567 CWARN("Non existing object "DFID"!\n",
1568 PFID(mdt_object_fid(info->mti_object)));
1571 next = mdt_object_child(info->mti_object);
1572 rc = mo_object_sync(info->mti_env, next);
1577 static int mdt_sync(struct mdt_thread_info *info)
1579 struct req_capsule *pill = info->mti_pill;
1580 struct mdt_body *body;
1584 /* The fid may be zero, so we req_capsule_set manually */
1585 req_capsule_set(pill, &RQF_MDS_SYNC);
1587 body = req_capsule_client_get(pill, &RMF_MDT_BODY);
1589 RETURN(err_serious(-EINVAL));
1591 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_SYNC_PACK))
1592 RETURN(err_serious(-ENOMEM));
1594 if (fid_seq(&body->fid1) == 0) {
1595 /* sync the whole device */
1596 rc = req_capsule_server_pack(pill);
1598 rc = mdt_device_sync(info->mti_env, info->mti_mdt);
1600 rc = err_serious(rc);
1602 /* sync an object */
1603 rc = mdt_unpack_req_pack_rep(info, HABEO_CORPUS|HABEO_REFERO);
1605 rc = mdt_object_sync(info);
1607 struct md_object *next;
1608 const struct lu_fid *fid;
1609 struct lu_attr *la = &info->mti_attr.ma_attr;
1611 next = mdt_object_child(info->mti_object);
1612 info->mti_attr.ma_need = MA_INODE;
1613 info->mti_attr.ma_valid = 0;
1614 rc = mo_attr_get(info->mti_env, next,
1617 body = req_capsule_server_get(pill,
1619 fid = mdt_object_fid(info->mti_object);
1620 mdt_pack_attr2body(info, body, la, fid);
1624 rc = err_serious(rc);
1629 static int mdt_quotacheck_handle(struct mdt_thread_info *info)
1631 return err_serious(-EOPNOTSUPP);
1634 static int mdt_quotactl_handle(struct mdt_thread_info *info)
1636 return err_serious(-EOPNOTSUPP);
1640 * OBD PING and other handlers.
1642 static int mdt_obd_ping(struct mdt_thread_info *info)
1647 req_capsule_set(info->mti_pill, &RQF_OBD_PING);
1649 rc = target_handle_ping(mdt_info_req(info));
1651 rc = err_serious(rc);
1655 static int mdt_obd_log_cancel(struct mdt_thread_info *info)
1657 return err_serious(-EOPNOTSUPP);
1660 static int mdt_obd_qc_callback(struct mdt_thread_info *info)
1662 return err_serious(-EOPNOTSUPP);
1669 static struct ldlm_callback_suite cbs = {
1670 .lcs_completion = ldlm_server_completion_ast,
1671 .lcs_blocking = ldlm_server_blocking_ast,
1675 static int mdt_enqueue(struct mdt_thread_info *info)
1677 struct ptlrpc_request *req;
1682 * info->mti_dlm_req already contains swapped and (if necessary)
1683 * converted dlm request.
1685 LASSERT(info->mti_dlm_req != NULL);
1687 req = mdt_info_req(info);
1690 * Lock without inodebits makes no sense and will oops later in
1691 * ldlm. Let's check it now to see if we have wrong lock from client or
1692 * bits get corrupted somewhere in mdt_intent_policy().
1694 req_bits = info->mti_dlm_req->lock_desc.l_policy_data.l_inodebits.bits;
1695 /* This is disabled because we need to support liblustre flock.
1696 * LASSERT(req_bits != 0);
1699 rc = ldlm_handle_enqueue0(info->mti_mdt->mdt_namespace,
1700 req, info->mti_dlm_req, &cbs);
1701 info->mti_fail_id = OBD_FAIL_LDLM_REPLY;
1702 return rc ? err_serious(rc) : req->rq_status;
1705 static int mdt_convert(struct mdt_thread_info *info)
1708 struct ptlrpc_request *req;
1710 LASSERT(info->mti_dlm_req);
1711 req = mdt_info_req(info);
1712 rc = ldlm_handle_convert0(req, info->mti_dlm_req);
1713 return rc ? err_serious(rc) : req->rq_status;
1716 static int mdt_bl_callback(struct mdt_thread_info *info)
1718 CERROR("bl callbacks should not happen on MDS\n");
1720 return err_serious(-EOPNOTSUPP);
1723 static int mdt_cp_callback(struct mdt_thread_info *info)
1725 CERROR("cp callbacks should not happen on MDS\n");
1727 return err_serious(-EOPNOTSUPP);
1731 * sec context handlers
1733 static int mdt_sec_ctx_handle(struct mdt_thread_info *info)
1737 rc = mdt_handle_idmap(info);
1740 struct ptlrpc_request *req = mdt_info_req(info);
1743 opc = lustre_msg_get_opc(req->rq_reqmsg);
1744 if (opc == SEC_CTX_INIT || opc == SEC_CTX_INIT_CONT)
1745 sptlrpc_svc_ctx_invalidate(req);
1748 OBD_FAIL_TIMEOUT(OBD_FAIL_SEC_CTX_HDL_PAUSE, obd_fail_val);
1753 static struct mdt_object *mdt_obj(struct lu_object *o)
1755 LASSERT(lu_device_is_mdt(o->lo_dev));
1756 return container_of0(o, struct mdt_object, mot_obj.mo_lu);
1759 struct mdt_object *mdt_object_find(const struct lu_env *env,
1760 struct mdt_device *d,
1761 const struct lu_fid *f)
1763 struct lu_object *o;
1764 struct mdt_object *m;
1767 CDEBUG(D_INFO, "Find object for "DFID"\n", PFID(f));
1768 o = lu_object_find(env, d->mdt_md_dev.md_lu_dev.ld_site, f);
1769 if (unlikely(IS_ERR(o)))
1770 m = (struct mdt_object *)o;
1776 int mdt_object_lock(struct mdt_thread_info *info, struct mdt_object *o,
1777 struct mdt_lock_handle *lh, __u64 ibits, int locality)
1779 struct ldlm_namespace *ns = info->mti_mdt->mdt_namespace;
1780 ldlm_policy_data_t *policy = &info->mti_policy;
1781 struct ldlm_res_id *res_id = &info->mti_res_id;
1785 LASSERT(!lustre_handle_is_used(&lh->mlh_reg_lh));
1786 LASSERT(!lustre_handle_is_used(&lh->mlh_pdo_lh));
1787 LASSERT(lh->mlh_reg_mode != LCK_MINMODE);
1788 LASSERT(lh->mlh_type != MDT_NUL_LOCK);
1790 if (mdt_object_exists(o) < 0) {
1791 if (locality == MDT_CROSS_LOCK) {
1792 /* cross-ref object fix */
1793 ibits &= ~MDS_INODELOCK_UPDATE;
1794 ibits |= MDS_INODELOCK_LOOKUP;
1796 LASSERT(!(ibits & MDS_INODELOCK_UPDATE));
1797 LASSERT(ibits & MDS_INODELOCK_LOOKUP);
1799 /* No PDO lock on remote object */
1800 LASSERT(lh->mlh_type != MDT_PDO_LOCK);
1803 memset(policy, 0, sizeof(*policy));
1804 fid_build_reg_res_name(mdt_object_fid(o), res_id);
1807 * Take PDO lock on whole directory and build correct @res_id for lock
1808 * on part of directory.
1810 if (lh->mlh_pdo_hash != 0) {
1811 LASSERT(lh->mlh_type == MDT_PDO_LOCK);
1812 mdt_lock_pdo_mode(info, o, lh);
1813 if (lh->mlh_pdo_mode != LCK_NL) {
1815 * Do not use LDLM_FL_LOCAL_ONLY for parallel lock, it
1816 * is never going to be sent to client and we do not
1817 * want it slowed down due to possible cancels.
1819 policy->l_inodebits.bits = MDS_INODELOCK_UPDATE;
1820 rc = mdt_fid_lock(ns, &lh->mlh_pdo_lh, lh->mlh_pdo_mode,
1821 policy, res_id, LDLM_FL_ATOMIC_CB);
1827 * Finish res_id initializing by name hash marking patr of
1828 * directory which is taking modification.
1830 res_id->name[LUSTRE_RES_ID_HSH_OFF] = lh->mlh_pdo_hash;
1833 policy->l_inodebits.bits = ibits;
1836 * Use LDLM_FL_LOCAL_ONLY for this lock. We do not know yet if it is
1837 * going to be sent to client. If it is - mdt_intent_policy() path will
1838 * fix it up and turns FL_LOCAL flag off.
1840 rc = mdt_fid_lock(ns, &lh->mlh_reg_lh, lh->mlh_reg_mode, policy,
1841 res_id, LDLM_FL_LOCAL_ONLY | LDLM_FL_ATOMIC_CB);
1846 if (lh->mlh_type == MDT_PDO_LOCK) {
1847 /* check for exists after object is locked */
1848 if (mdt_object_exists(o) == 0) {
1849 /* Non-existent object shouldn't have PDO lock */
1852 /* Non-dir object shouldn't have PDO lock */
1853 LASSERT(S_ISDIR(lu_object_attr(&o->mot_obj.mo_lu)));
1858 mdt_object_unlock(info, o, lh, 1);
1865 void mdt_save_lock(struct ptlrpc_request *req, struct lustre_handle *h,
1866 ldlm_mode_t mode, int decref)
1870 if (lustre_handle_is_used(h)) {
1872 mdt_fid_unlock(h, mode);
1874 ptlrpc_save_lock(req, h, mode);
1882 * Just call ldlm_lock_decref() if decref, else we only call ptlrpc_save_lock()
1883 * to save this lock in req. when transaction committed, req will be released,
1884 * and lock will, too.
1886 void mdt_object_unlock(struct mdt_thread_info *info, struct mdt_object *o,
1887 struct mdt_lock_handle *lh, int decref)
1889 struct ptlrpc_request *req = mdt_info_req(info);
1892 mdt_save_lock(req, &lh->mlh_pdo_lh, lh->mlh_pdo_mode, decref);
1893 mdt_save_lock(req, &lh->mlh_reg_lh, lh->mlh_reg_mode, decref);
1898 struct mdt_object *mdt_object_find_lock(struct mdt_thread_info *info,
1899 const struct lu_fid *f,
1900 struct mdt_lock_handle *lh,
1903 struct mdt_object *o;
1905 o = mdt_object_find(info->mti_env, info->mti_mdt, f);
1909 rc = mdt_object_lock(info, o, lh, ibits,
1912 mdt_object_put(info->mti_env, o);
1919 void mdt_object_unlock_put(struct mdt_thread_info * info,
1920 struct mdt_object * o,
1921 struct mdt_lock_handle *lh,
1924 mdt_object_unlock(info, o, lh, decref);
1925 mdt_object_put(info->mti_env, o);
1928 static struct mdt_handler *mdt_handler_find(__u32 opc,
1929 struct mdt_opc_slice *supported)
1931 struct mdt_opc_slice *s;
1932 struct mdt_handler *h;
1935 for (s = supported; s->mos_hs != NULL; s++) {
1936 if (s->mos_opc_start <= opc && opc < s->mos_opc_end) {
1937 h = s->mos_hs + (opc - s->mos_opc_start);
1938 if (likely(h->mh_opc != 0))
1939 LASSERT(h->mh_opc == opc);
1941 h = NULL; /* unsupported opc */
1948 static int mdt_lock_resname_compat(struct mdt_device *m,
1949 struct ldlm_request *req)
1951 /* XXX something... later. */
1955 static int mdt_lock_reply_compat(struct mdt_device *m, struct ldlm_reply *rep)
1957 /* XXX something... later. */
1962 * Generic code handling requests that have struct mdt_body passed in:
1964 * - extract mdt_body from request and save it in @info, if present;
1966 * - create lu_object, corresponding to the fid in mdt_body, and save it in
1969 * - if HABEO_CORPUS flag is set for this request type check whether object
1970 * actually exists on storage (lu_object_exists()).
1973 static int mdt_body_unpack(struct mdt_thread_info *info, __u32 flags)
1975 const struct mdt_body *body;
1976 struct mdt_object *obj;
1977 const struct lu_env *env;
1978 struct req_capsule *pill;
1982 env = info->mti_env;
1983 pill = info->mti_pill;
1985 body = info->mti_body = req_capsule_client_get(pill, &RMF_MDT_BODY);
1989 if (!(body->valid & OBD_MD_FLID))
1992 if (!fid_is_sane(&body->fid1)) {
1993 CERROR("Invalid fid: "DFID"\n", PFID(&body->fid1));
1998 * Do not get size or any capa fields before we check that request
1999 * contains capa actually. There are some requests which do not, for
2000 * instance MDS_IS_SUBDIR.
2002 if (req_capsule_has_field(pill, &RMF_CAPA1, RCL_CLIENT) &&
2003 req_capsule_get_size(pill, &RMF_CAPA1, RCL_CLIENT))
2004 mdt_set_capainfo(info, 0, &body->fid1,
2005 req_capsule_client_get(pill, &RMF_CAPA1));
2007 obj = mdt_object_find(env, info->mti_mdt, &body->fid1);
2009 if ((flags & HABEO_CORPUS) &&
2010 !mdt_object_exists(obj)) {
2011 mdt_object_put(env, obj);
2012 /* for capability renew ENOENT will be handled in
2014 if (body->valid & OBD_MD_FLOSSCAPA)
2019 info->mti_object = obj;
2028 static int mdt_unpack_req_pack_rep(struct mdt_thread_info *info, __u32 flags)
2030 struct req_capsule *pill = info->mti_pill;
2034 if (req_capsule_has_field(pill, &RMF_MDT_BODY, RCL_CLIENT))
2035 rc = mdt_body_unpack(info, flags);
2039 if (rc == 0 && (flags & HABEO_REFERO)) {
2040 struct mdt_device *mdt = info->mti_mdt;
2043 if (req_capsule_has_field(pill, &RMF_MDT_MD, RCL_SERVER))
2044 req_capsule_set_size(pill, &RMF_MDT_MD, RCL_SERVER,
2045 mdt->mdt_max_mdsize);
2046 if (req_capsule_has_field(pill, &RMF_LOGCOOKIES, RCL_SERVER))
2047 req_capsule_set_size(pill, &RMF_LOGCOOKIES, RCL_SERVER,
2048 mdt->mdt_max_cookiesize);
2050 rc = req_capsule_server_pack(pill);
2055 static int mdt_init_capa_ctxt(const struct lu_env *env, struct mdt_device *m)
2057 struct md_device *next = m->mdt_child;
2059 return next->md_ops->mdo_init_capa_ctxt(env, next,
2060 m->mdt_opts.mo_mds_capa,
2061 m->mdt_capa_timeout,
2067 * Invoke handler for this request opc. Also do necessary preprocessing
2068 * (according to handler ->mh_flags), and post-processing (setting of
2069 * ->last_{xid,committed}).
2071 static int mdt_req_handle(struct mdt_thread_info *info,
2072 struct mdt_handler *h, struct ptlrpc_request *req)
2074 int rc, serious = 0;
2079 LASSERT(h->mh_act != NULL);
2080 LASSERT(h->mh_opc == lustre_msg_get_opc(req->rq_reqmsg));
2081 LASSERT(current->journal_info == NULL);
2084 * Checking for various OBD_FAIL_$PREF_$OPC_NET codes. _Do_ not try
2085 * to put same checks into handlers like mdt_close(), mdt_reint(),
2086 * etc., without talking to mdt authors first. Checking same thing
2087 * there again is useless and returning 0 error wihtout packing reply
2088 * is buggy! Handlers either pack reply or return error.
2090 * We return 0 here and do not send any reply in order to emulate
2091 * network failure. Do not send any reply in case any of NET related
2092 * fail_id has occured.
2094 if (OBD_FAIL_CHECK_ORSET(h->mh_fail_id, OBD_FAIL_ONCE))
2098 flags = h->mh_flags;
2099 LASSERT(ergo(flags & (HABEO_CORPUS|HABEO_REFERO), h->mh_fmt != NULL));
2101 if (h->mh_fmt != NULL) {
2102 req_capsule_set(info->mti_pill, h->mh_fmt);
2103 rc = mdt_unpack_req_pack_rep(info, flags);
2106 if (rc == 0 && flags & MUTABOR &&
2107 req->rq_export->exp_connect_flags & OBD_CONNECT_RDONLY)
2108 /* should it be rq_status? */
2111 if (rc == 0 && flags & HABEO_CLAVIS) {
2112 struct ldlm_request *dlm_req;
2114 LASSERT(h->mh_fmt != NULL);
2116 dlm_req = req_capsule_client_get(info->mti_pill, &RMF_DLM_REQ);
2117 if (dlm_req != NULL) {
2118 if (info->mti_mdt->mdt_opts.mo_compat_resname)
2119 rc = mdt_lock_resname_compat(info->mti_mdt,
2121 info->mti_dlm_req = dlm_req;
2127 /* capability setting changed via /proc, needs reinitialize ctxt */
2128 if (info->mti_mdt && info->mti_mdt->mdt_capa_conf) {
2129 mdt_init_capa_ctxt(info->mti_env, info->mti_mdt);
2130 info->mti_mdt->mdt_capa_conf = 0;
2133 if (likely(rc == 0)) {
2135 * Process request, there can be two types of rc:
2136 * 1) errors with msg unpack/pack, other failures outside the
2137 * operation itself. This is counted as serious errors;
2138 * 2) errors during fs operation, should be placed in rq_status
2141 rc = h->mh_act(info);
2143 !req->rq_no_reply && req->rq_reply_state == NULL) {
2144 DEBUG_REQ(D_ERROR, req, "MDT \"handler\" %s did not "
2145 "pack reply and returned 0 error\n",
2149 serious = is_serious(rc);
2150 rc = clear_serious(rc);
2154 req->rq_status = rc;
2157 * ELDLM_* codes which > 0 should be in rq_status only as well as
2158 * all non-serious errors.
2160 if (rc > 0 || !serious)
2163 LASSERT(current->journal_info == NULL);
2165 if (rc == 0 && (flags & HABEO_CLAVIS) &&
2166 info->mti_mdt->mdt_opts.mo_compat_resname) {
2167 struct ldlm_reply *dlmrep;
2169 dlmrep = req_capsule_server_get(info->mti_pill, &RMF_DLM_REP);
2171 rc = mdt_lock_reply_compat(info->mti_mdt, dlmrep);
2174 /* If we're DISCONNECTing, the mdt_export_data is already freed */
2175 if (likely(rc == 0 && h->mh_opc != MDS_DISCONNECT))
2176 target_committed_to_req(req);
2178 if (unlikely((lustre_msg_get_flags(req->rq_reqmsg) & MSG_REPLAY) &&
2179 lustre_msg_get_transno(req->rq_reqmsg) == 0)) {
2180 DEBUG_REQ(D_ERROR, req, "transno is 0 during REPLAY");
2184 target_send_reply(req, rc, info->mti_fail_id);
2188 void mdt_lock_handle_init(struct mdt_lock_handle *lh)
2190 lh->mlh_type = MDT_NUL_LOCK;
2191 lh->mlh_reg_lh.cookie = 0ull;
2192 lh->mlh_reg_mode = LCK_MINMODE;
2193 lh->mlh_pdo_lh.cookie = 0ull;
2194 lh->mlh_pdo_mode = LCK_MINMODE;
2197 void mdt_lock_handle_fini(struct mdt_lock_handle *lh)
2199 LASSERT(!lustre_handle_is_used(&lh->mlh_reg_lh));
2200 LASSERT(!lustre_handle_is_used(&lh->mlh_pdo_lh));
2204 * Initialize fields of struct mdt_thread_info. Other fields are left in
2205 * uninitialized state, because it's too expensive to zero out whole
2206 * mdt_thread_info (> 1K) on each request arrival.
2208 static void mdt_thread_info_init(struct ptlrpc_request *req,
2209 struct mdt_thread_info *info)
2212 struct md_capainfo *ci;
2214 req_capsule_init(&req->rq_pill, req, RCL_SERVER);
2215 info->mti_pill = &req->rq_pill;
2218 for (i = 0; i < ARRAY_SIZE(info->mti_lh); i++)
2219 mdt_lock_handle_init(&info->mti_lh[i]);
2221 /* mdt device: it can be NULL while CONNECT */
2222 if (req->rq_export) {
2223 info->mti_mdt = mdt_dev(req->rq_export->exp_obd->obd_lu_dev);
2224 info->mti_exp = req->rq_export;
2226 info->mti_mdt = NULL;
2227 info->mti_env = req->rq_svc_thread->t_env;
2228 ci = md_capainfo(info->mti_env);
2229 memset(ci, 0, sizeof *ci);
2231 info->mti_fail_id = OBD_FAIL_MDS_ALL_REPLY_NET;
2232 info->mti_transno = lustre_msg_get_transno(req->rq_reqmsg);
2234 memset(&info->mti_attr, 0, sizeof(info->mti_attr));
2235 info->mti_body = NULL;
2236 info->mti_object = NULL;
2237 info->mti_dlm_req = NULL;
2238 info->mti_has_trans = 0;
2239 info->mti_no_need_trans = 0;
2240 info->mti_cross_ref = 0;
2241 info->mti_opdata = 0;
2243 /* To not check for split by default. */
2244 info->mti_spec.sp_ck_split = 0;
2247 static void mdt_thread_info_fini(struct mdt_thread_info *info)
2251 req_capsule_fini(info->mti_pill);
2252 if (info->mti_object != NULL) {
2253 mdt_object_put(info->mti_env, info->mti_object);
2254 info->mti_object = NULL;
2256 for (i = 0; i < ARRAY_SIZE(info->mti_lh); i++)
2257 mdt_lock_handle_fini(&info->mti_lh[i]);
2258 info->mti_env = NULL;
2261 static int mdt_filter_recovery_request(struct ptlrpc_request *req,
2262 struct obd_device *obd, int *process)
2264 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
2265 case MDS_CONNECT: /* This will never get here, but for completeness. */
2266 case OST_CONNECT: /* This will never get here, but for completeness. */
2267 case MDS_DISCONNECT:
2268 case OST_DISCONNECT:
2273 case MDS_DONE_WRITING:
2274 case MDS_SYNC: /* used in unmounting */
2280 *process = target_queue_recovery_request(req, obd);
2284 DEBUG_REQ(D_ERROR, req, "not permitted during recovery");
2291 * Handle recovery. Return:
2292 * +1: continue request processing;
2293 * -ve: abort immediately with the given error code;
2294 * 0: send reply with error code in req->rq_status;
2296 static int mdt_recovery(struct mdt_thread_info *info)
2298 struct ptlrpc_request *req = mdt_info_req(info);
2300 struct obd_device *obd;
2304 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
2307 case SEC_CTX_INIT_CONT:
2313 rc = mdt_handle_idmap(info);
2322 if (unlikely(req->rq_export == NULL)) {
2323 CERROR("operation %d on unconnected MDS from %s\n",
2324 lustre_msg_get_opc(req->rq_reqmsg),
2325 libcfs_id2str(req->rq_peer));
2326 /* FIXME: For CMD cleanup, when mds_B stop, the req from
2327 * mds_A will get -ENOTCONN(especially for ping req),
2328 * which will cause that mds_A deactive timeout, then when
2329 * mds_A cleanup, the cleanup process will be suspended since
2330 * deactive timeout is not zero.
2332 req->rq_status = -ENOTCONN;
2333 target_send_reply(req, -ENOTCONN, info->mti_fail_id);
2337 /* sanity check: if the xid matches, the request must be marked as a
2338 * resent or replayed */
2339 if (req_xid_is_last(req)) {
2340 if (!(lustre_msg_get_flags(req->rq_reqmsg) &
2341 (MSG_RESENT | MSG_REPLAY))) {
2342 DEBUG_REQ(D_WARNING, req, "rq_xid "LPU64" matches last_xid, "
2343 "expected REPLAY or RESENT flag (%x)", req->rq_xid,
2344 lustre_msg_get_flags(req->rq_reqmsg));
2346 req->rq_status = -ENOTCONN;
2351 /* else: note the opposite is not always true; a RESENT req after a
2352 * failover will usually not match the last_xid, since it was likely
2353 * never committed. A REPLAYed request will almost never match the
2354 * last xid, however it could for a committed, but still retained,
2357 obd = req->rq_export->exp_obd;
2359 /* Check for aborted recovery... */
2360 spin_lock_bh(&obd->obd_processing_task_lock);
2361 recovering = obd->obd_recovering;
2362 spin_unlock_bh(&obd->obd_processing_task_lock);
2363 if (unlikely(recovering)) {
2366 DEBUG_REQ(D_INFO, req, "Got new replay");
2367 rc = mdt_filter_recovery_request(req, obd, &should_process);
2368 if (rc != 0 || !should_process)
2370 else if (should_process < 0) {
2371 req->rq_status = should_process;
2372 rc = ptlrpc_error(req);
2379 static int mdt_msg_check_version(struct lustre_msg *msg)
2383 switch (lustre_msg_get_opc(msg)) {
2385 case MDS_DISCONNECT:
2388 case SEC_CTX_INIT_CONT:
2390 rc = lustre_msg_check_version(msg, LUSTRE_OBD_VERSION);
2392 CERROR("bad opc %u version %08x, expecting %08x\n",
2393 lustre_msg_get_opc(msg),
2394 lustre_msg_get_version(msg),
2395 LUSTRE_OBD_VERSION);
2399 case MDS_GETATTR_NAME:
2406 case MDS_DONE_WRITING:
2412 case MDS_QUOTACHECK:
2418 rc = lustre_msg_check_version(msg, LUSTRE_MDS_VERSION);
2420 CERROR("bad opc %u version %08x, expecting %08x\n",
2421 lustre_msg_get_opc(msg),
2422 lustre_msg_get_version(msg),
2423 LUSTRE_MDS_VERSION);
2427 case LDLM_BL_CALLBACK:
2428 case LDLM_CP_CALLBACK:
2429 rc = lustre_msg_check_version(msg, LUSTRE_DLM_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_DLM_VERSION);
2436 case OBD_LOG_CANCEL:
2437 case LLOG_ORIGIN_HANDLE_CREATE:
2438 case LLOG_ORIGIN_HANDLE_NEXT_BLOCK:
2439 case LLOG_ORIGIN_HANDLE_READ_HEADER:
2440 case LLOG_ORIGIN_HANDLE_CLOSE:
2441 case LLOG_ORIGIN_HANDLE_DESTROY:
2442 case LLOG_ORIGIN_HANDLE_PREV_BLOCK:
2444 rc = lustre_msg_check_version(msg, LUSTRE_LOG_VERSION);
2446 CERROR("bad opc %u version %08x, expecting %08x\n",
2447 lustre_msg_get_opc(msg),
2448 lustre_msg_get_version(msg),
2449 LUSTRE_LOG_VERSION);
2452 CERROR("MDS unknown opcode %d\n", lustre_msg_get_opc(msg));
2458 static int mdt_handle0(struct ptlrpc_request *req,
2459 struct mdt_thread_info *info,
2460 struct mdt_opc_slice *supported)
2462 struct mdt_handler *h;
2463 struct lustre_msg *msg;
2468 if (OBD_FAIL_CHECK_ORSET(OBD_FAIL_MDS_ALL_REQUEST_NET, OBD_FAIL_ONCE))
2471 LASSERT(current->journal_info == NULL);
2473 msg = req->rq_reqmsg;
2474 rc = mdt_msg_check_version(msg);
2475 if (likely(rc == 0)) {
2476 rc = mdt_recovery(info);
2477 if (likely(rc == +1)) {
2478 h = mdt_handler_find(lustre_msg_get_opc(msg),
2480 if (likely(h != NULL)) {
2481 rc = mdt_req_handle(info, h, req);
2483 CERROR("The unsupported opc: 0x%x\n", lustre_msg_get_opc(msg) );
2484 req->rq_status = -ENOTSUPP;
2485 rc = ptlrpc_error(req);
2490 CERROR(LUSTRE_MDT_NAME" drops mal-formed request\n");
2495 * MDT handler function called by ptlrpc service thread when request comes.
2497 * XXX common "target" functionality should be factored into separate module
2498 * shared by mdt, ost and stand-alone services like fld.
2500 static int mdt_handle_common(struct ptlrpc_request *req,
2501 struct mdt_opc_slice *supported)
2504 struct mdt_thread_info *info;
2508 env = req->rq_svc_thread->t_env;
2509 LASSERT(env != NULL);
2510 LASSERT(env->le_ses != NULL);
2511 LASSERT(env->le_ctx.lc_thread == req->rq_svc_thread);
2512 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
2513 LASSERT(info != NULL);
2515 mdt_thread_info_init(req, info);
2517 rc = mdt_handle0(req, info, supported);
2519 mdt_thread_info_fini(info);
2524 * This is called from recovery code as handler of _all_ RPC types, FLD and SEQ
2527 int mdt_recovery_handle(struct ptlrpc_request *req)
2532 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
2534 rc = mdt_handle_common(req, mdt_fld_handlers);
2537 rc = mdt_handle_common(req, mdt_seq_handlers);
2540 rc = mdt_handle_common(req, mdt_regular_handlers);
2547 static int mdt_regular_handle(struct ptlrpc_request *req)
2549 return mdt_handle_common(req, mdt_regular_handlers);
2552 static int mdt_readpage_handle(struct ptlrpc_request *req)
2554 return mdt_handle_common(req, mdt_readpage_handlers);
2557 static int mdt_xmds_handle(struct ptlrpc_request *req)
2559 return mdt_handle_common(req, mdt_xmds_handlers);
2562 static int mdt_mdsc_handle(struct ptlrpc_request *req)
2564 return mdt_handle_common(req, mdt_seq_handlers);
2567 static int mdt_mdss_handle(struct ptlrpc_request *req)
2569 return mdt_handle_common(req, mdt_seq_handlers);
2572 static int mdt_dtss_handle(struct ptlrpc_request *req)
2574 return mdt_handle_common(req, mdt_seq_handlers);
2577 static int mdt_fld_handle(struct ptlrpc_request *req)
2579 return mdt_handle_common(req, mdt_fld_handlers);
2595 static int mdt_intent_getattr(enum mdt_it_code opcode,
2596 struct mdt_thread_info *info,
2597 struct ldlm_lock **,
2599 static int mdt_intent_reint(enum mdt_it_code opcode,
2600 struct mdt_thread_info *info,
2601 struct ldlm_lock **,
2604 static struct mdt_it_flavor {
2605 const struct req_format *it_fmt;
2607 int (*it_act)(enum mdt_it_code ,
2608 struct mdt_thread_info *,
2609 struct ldlm_lock **,
2612 } mdt_it_flavor[] = {
2614 .it_fmt = &RQF_LDLM_INTENT,
2615 /*.it_flags = HABEO_REFERO,*/
2617 .it_act = mdt_intent_reint,
2618 .it_reint = REINT_OPEN
2621 .it_fmt = &RQF_LDLM_INTENT,
2622 .it_flags = MUTABOR,
2623 .it_act = mdt_intent_reint,
2624 .it_reint = REINT_OPEN
2627 .it_fmt = &RQF_LDLM_INTENT,
2628 .it_flags = MUTABOR,
2629 .it_act = mdt_intent_reint,
2630 .it_reint = REINT_CREATE
2632 [MDT_IT_GETATTR] = {
2633 .it_fmt = &RQF_LDLM_INTENT_GETATTR,
2634 .it_flags = HABEO_REFERO,
2635 .it_act = mdt_intent_getattr
2637 [MDT_IT_READDIR] = {
2643 .it_fmt = &RQF_LDLM_INTENT_GETATTR,
2644 .it_flags = HABEO_REFERO,
2645 .it_act = mdt_intent_getattr
2648 .it_fmt = &RQF_LDLM_INTENT_UNLINK,
2649 .it_flags = MUTABOR,
2651 .it_reint = REINT_UNLINK
2655 .it_flags = MUTABOR,
2658 [MDT_IT_GETXATTR] = {
2665 int mdt_intent_lock_replace(struct mdt_thread_info *info,
2666 struct ldlm_lock **lockp,
2667 struct ldlm_lock *new_lock,
2668 struct mdt_lock_handle *lh,
2671 struct ptlrpc_request *req = mdt_info_req(info);
2672 struct ldlm_lock *lock = *lockp;
2675 * Get new lock only for cases when possible resent did not find any
2678 if (new_lock == NULL)
2679 new_lock = ldlm_handle2lock(&lh->mlh_reg_lh);
2681 if (new_lock == NULL && (flags & LDLM_FL_INTENT_ONLY)) {
2682 lh->mlh_reg_lh.cookie = 0;
2686 LASSERTF(new_lock != NULL,
2687 "lockh "LPX64"\n", lh->mlh_reg_lh.cookie);
2690 * If we've already given this lock to a client once, then we should
2691 * have no readers or writers. Otherwise, we should have one reader
2692 * _or_ writer ref (which will be zeroed below) before returning the
2695 if (new_lock->l_export == req->rq_export) {
2696 LASSERT(new_lock->l_readers + new_lock->l_writers == 0);
2698 LASSERT(new_lock->l_export == NULL);
2699 LASSERT(new_lock->l_readers + new_lock->l_writers == 1);
2704 if (new_lock->l_export == req->rq_export) {
2706 * Already gave this to the client, which means that we
2707 * reconstructed a reply.
2709 LASSERT(lustre_msg_get_flags(req->rq_reqmsg) &
2711 lh->mlh_reg_lh.cookie = 0;
2712 RETURN(ELDLM_LOCK_REPLACED);
2716 * Fixup the lock to be given to the client.
2718 lock_res_and_lock(new_lock);
2719 new_lock->l_readers = 0;
2720 new_lock->l_writers = 0;
2722 new_lock->l_export = class_export_get(req->rq_export);
2723 new_lock->l_blocking_ast = lock->l_blocking_ast;
2724 new_lock->l_completion_ast = lock->l_completion_ast;
2725 new_lock->l_remote_handle = lock->l_remote_handle;
2726 new_lock->l_flags &= ~LDLM_FL_LOCAL;
2728 lustre_hash_add(new_lock->l_export->exp_lock_hash,
2729 &new_lock->l_remote_handle,
2730 &new_lock->l_exp_hash);
2732 unlock_res_and_lock(new_lock);
2733 LDLM_LOCK_PUT(new_lock);
2734 lh->mlh_reg_lh.cookie = 0;
2736 RETURN(ELDLM_LOCK_REPLACED);
2739 static void mdt_intent_fixup_resent(struct mdt_thread_info *info,
2740 struct ldlm_lock *new_lock,
2741 struct ldlm_lock **old_lock,
2742 struct mdt_lock_handle *lh)
2744 struct ptlrpc_request *req = mdt_info_req(info);
2745 struct obd_export *exp = req->rq_export;
2746 struct lustre_handle remote_hdl;
2747 struct ldlm_request *dlmreq;
2748 struct ldlm_lock *lock;
2750 if (!(lustre_msg_get_flags(req->rq_reqmsg) & MSG_RESENT))
2753 dlmreq = req_capsule_client_get(info->mti_pill, &RMF_DLM_REQ);
2754 remote_hdl = dlmreq->lock_handle[0];
2756 lock = lustre_hash_lookup(exp->exp_lock_hash, &remote_hdl);
2758 if (lock != new_lock) {
2759 lh->mlh_reg_lh.cookie = lock->l_handle.h_cookie;
2760 lh->mlh_reg_mode = lock->l_granted_mode;
2762 LDLM_DEBUG(lock, "Restoring lock cookie");
2763 DEBUG_REQ(D_DLMTRACE, req,
2764 "restoring lock cookie "LPX64,
2765 lh->mlh_reg_lh.cookie);
2767 *old_lock = LDLM_LOCK_GET(lock);
2768 lh_put(exp->exp_lock_hash, &lock->l_exp_hash);
2772 lh_put(exp->exp_lock_hash, &lock->l_exp_hash);
2776 * If the xid matches, then we know this is a resent request, and allow
2777 * it. (It's probably an OPEN, for which we don't send a lock.
2779 if (req_xid_is_last(req))
2783 * This remote handle isn't enqueued, so we never received or processed
2784 * this request. Clear MSG_RESENT, because it can be handled like any
2785 * normal request now.
2787 lustre_msg_clear_flags(req->rq_reqmsg, MSG_RESENT);
2789 DEBUG_REQ(D_DLMTRACE, req, "no existing lock with rhandle "LPX64,
2793 static int mdt_intent_getattr(enum mdt_it_code opcode,
2794 struct mdt_thread_info *info,
2795 struct ldlm_lock **lockp,
2798 struct mdt_lock_handle *lhc = &info->mti_lh[MDT_LH_RMT];
2799 struct ldlm_lock *new_lock = NULL;
2801 struct ldlm_reply *ldlm_rep;
2802 struct ptlrpc_request *req;
2803 struct mdt_body *reqbody;
2804 struct mdt_body *repbody;
2808 reqbody = req_capsule_client_get(info->mti_pill, &RMF_MDT_BODY);
2811 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
2814 info->mti_spec.sp_ck_split = !!(reqbody->valid & OBD_MD_FLCKSPLIT);
2815 info->mti_cross_ref = !!(reqbody->valid & OBD_MD_FLCROSSREF);
2816 repbody->eadatasize = 0;
2817 repbody->aclsize = 0;
2821 child_bits = MDS_INODELOCK_LOOKUP;
2823 case MDT_IT_GETATTR:
2824 child_bits = MDS_INODELOCK_LOOKUP | MDS_INODELOCK_UPDATE;
2827 CERROR("Unhandled till now");
2828 GOTO(out_shrink, rc = -EINVAL);
2831 rc = mdt_init_ucred(info, reqbody);
2833 GOTO(out_shrink, rc);
2835 req = info->mti_pill->rc_req;
2836 ldlm_rep = req_capsule_server_get(info->mti_pill, &RMF_DLM_REP);
2837 mdt_set_disposition(info, ldlm_rep, DISP_IT_EXECD);
2839 /* Get lock from request for possible resent case. */
2840 mdt_intent_fixup_resent(info, *lockp, &new_lock, lhc);
2842 ldlm_rep->lock_policy_res2 =
2843 mdt_getattr_name_lock(info, lhc, child_bits, ldlm_rep);
2845 if (mdt_get_disposition(ldlm_rep, DISP_LOOKUP_NEG))
2846 ldlm_rep->lock_policy_res2 = 0;
2847 if (!mdt_get_disposition(ldlm_rep, DISP_LOOKUP_POS) ||
2848 ldlm_rep->lock_policy_res2) {
2849 lhc->mlh_reg_lh.cookie = 0ull;
2850 GOTO(out_ucred, rc = ELDLM_LOCK_ABORTED);
2853 rc = mdt_intent_lock_replace(info, lockp, new_lock, lhc, flags);
2856 mdt_exit_ucred(info);
2858 mdt_shrink_reply(info);
2862 static int mdt_intent_reint(enum mdt_it_code opcode,
2863 struct mdt_thread_info *info,
2864 struct ldlm_lock **lockp,
2867 struct mdt_lock_handle *lhc = &info->mti_lh[MDT_LH_RMT];
2868 struct ldlm_reply *rep = NULL;
2872 static const struct req_format *intent_fmts[REINT_MAX] = {
2873 [REINT_CREATE] = &RQF_LDLM_INTENT_CREATE,
2874 [REINT_OPEN] = &RQF_LDLM_INTENT_OPEN
2879 opc = mdt_reint_opcode(info, intent_fmts);
2883 if (mdt_it_flavor[opcode].it_reint != opc) {
2884 CERROR("Reint code %ld doesn't match intent: %d\n",
2886 RETURN(err_serious(-EPROTO));
2889 /* Get lock from request for possible resent case. */
2890 mdt_intent_fixup_resent(info, *lockp, NULL, lhc);
2892 rc = mdt_reint_internal(info, lhc, opc);
2894 /* Check whether the reply has been packed successfully. */
2895 if (mdt_info_req(info)->rq_repmsg != NULL)
2896 rep = req_capsule_server_get(info->mti_pill, &RMF_DLM_REP);
2898 RETURN(err_serious(-EFAULT));
2900 /* MDC expects this in any case */
2902 mdt_set_disposition(info, rep, DISP_LOOKUP_EXECD);
2904 /* Cross-ref case, the lock should be returned to the client */
2905 if (rc == -EREMOTE) {
2906 LASSERT(lustre_handle_is_used(&lhc->mlh_reg_lh));
2907 rep->lock_policy_res2 = 0;
2908 rc = mdt_intent_lock_replace(info, lockp, NULL, lhc, flags);
2911 rep->lock_policy_res2 = clear_serious(rc);
2913 lhc->mlh_reg_lh.cookie = 0ull;
2914 if (rc == -ENOTCONN || rc == -ENODEV) {
2916 * If it is the disconnect error (ENODEV & ENOCONN), the error
2917 * will be returned by rq_status, and client at ptlrpc layer
2918 * will detect this, then disconnect, reconnect the import
2919 * immediately, instead of impacting the following the rpc.
2924 * For other cases, the error will be returned by intent.
2925 * and client will retrieve the result from intent.
2928 * FIXME: when open lock is finished, that should be
2931 RETURN(ELDLM_LOCK_ABORTED);
2935 static int mdt_intent_code(long itcode)
2943 case IT_OPEN|IT_CREAT:
2950 rc = MDT_IT_READDIR;
2953 rc = MDT_IT_GETATTR;
2965 rc = MDT_IT_GETXATTR;
2968 CERROR("Unknown intent opcode: %ld\n", itcode);
2975 static int mdt_intent_opc(long itopc, struct mdt_thread_info *info,
2976 struct ldlm_lock **lockp, int flags)
2978 struct req_capsule *pill;
2979 struct mdt_it_flavor *flv;
2984 opc = mdt_intent_code(itopc);
2988 pill = info->mti_pill;
2989 flv = &mdt_it_flavor[opc];
2991 if (flv->it_fmt != NULL)
2992 req_capsule_extend(pill, flv->it_fmt);
2994 rc = mdt_unpack_req_pack_rep(info, flv->it_flags);
2996 struct ptlrpc_request *req = mdt_info_req(info);
2997 if (flv->it_flags & MUTABOR &&
2998 req->rq_export->exp_connect_flags & OBD_CONNECT_RDONLY)
3001 if (rc == 0 && flv->it_act != NULL) {
3002 /* execute policy */
3003 rc = flv->it_act(opc, info, lockp, flags);
3010 static int mdt_intent_policy(struct ldlm_namespace *ns,
3011 struct ldlm_lock **lockp, void *req_cookie,
3012 ldlm_mode_t mode, int flags, void *data)
3014 struct mdt_thread_info *info;
3015 struct ptlrpc_request *req = req_cookie;
3016 struct ldlm_intent *it;
3017 struct req_capsule *pill;
3022 LASSERT(req != NULL);
3024 info = lu_context_key_get(&req->rq_svc_thread->t_env->le_ctx,
3026 LASSERT(info != NULL);
3027 pill = info->mti_pill;
3028 LASSERT(pill->rc_req == req);
3030 if (req->rq_reqmsg->lm_bufcount > DLM_INTENT_IT_OFF) {
3031 req_capsule_extend(pill, &RQF_LDLM_INTENT);
3032 it = req_capsule_client_get(pill, &RMF_LDLM_INTENT);
3034 const struct ldlm_request *dlmreq;
3037 rc = mdt_intent_opc(it->opc, info, lockp, flags);
3042 * Lock without inodebits makes no sense and will oops
3043 * later in ldlm. Let's check it now to see if we have
3044 * wrong lock from client or bits get corrupted
3045 * somewhere in mdt_intent_opc().
3047 dlmreq = info->mti_dlm_req;
3048 req_bits = dlmreq->lock_desc.l_policy_data.l_inodebits.bits;
3049 LASSERT(req_bits != 0);
3052 rc = err_serious(-EFAULT);
3054 /* No intent was provided */
3055 LASSERT(pill->rc_fmt == &RQF_LDLM_ENQUEUE);
3056 rc = req_capsule_server_pack(pill);
3058 rc = err_serious(rc);
3066 static void mdt_seq_adjust(const struct lu_env *env,
3067 struct mdt_device *m, int lost)
3069 struct lu_site *ls = m->mdt_md_dev.md_lu_dev.ld_site;
3070 struct lu_range out;
3073 LASSERT(ls && ls->ls_server_seq);
3075 /* get extra seq from seq_server, moving it's range up */
3076 while (lost-- > 0) {
3077 seq_server_alloc_meta(ls->ls_server_seq, NULL, &out, env);
3082 static int mdt_seq_fini(const struct lu_env *env,
3083 struct mdt_device *m)
3085 struct lu_site *ls = m->mdt_md_dev.md_lu_dev.ld_site;
3088 if (ls && ls->ls_server_seq) {
3089 seq_server_fini(ls->ls_server_seq, env);
3090 OBD_FREE_PTR(ls->ls_server_seq);
3091 ls->ls_server_seq = NULL;
3094 if (ls && ls->ls_control_seq) {
3095 seq_server_fini(ls->ls_control_seq, env);
3096 OBD_FREE_PTR(ls->ls_control_seq);
3097 ls->ls_control_seq = NULL;
3100 if (ls && ls->ls_client_seq) {
3101 seq_client_fini(ls->ls_client_seq);
3102 OBD_FREE_PTR(ls->ls_client_seq);
3103 ls->ls_client_seq = NULL;
3109 static int mdt_seq_init(const struct lu_env *env,
3111 struct mdt_device *m)
3118 ls = m->mdt_md_dev.md_lu_dev.ld_site;
3121 * This is sequence-controller node. Init seq-controller server on local
3124 if (ls->ls_node_id == 0) {
3125 LASSERT(ls->ls_control_seq == NULL);
3127 OBD_ALLOC_PTR(ls->ls_control_seq);
3128 if (ls->ls_control_seq == NULL)
3131 rc = seq_server_init(ls->ls_control_seq,
3132 m->mdt_bottom, uuid,
3133 LUSTRE_SEQ_CONTROLLER,
3137 GOTO(out_seq_fini, rc);
3139 OBD_ALLOC_PTR(ls->ls_client_seq);
3140 if (ls->ls_client_seq == NULL)
3141 GOTO(out_seq_fini, rc = -ENOMEM);
3143 OBD_ALLOC(prefix, MAX_OBD_NAME + 5);
3144 if (prefix == NULL) {
3145 OBD_FREE_PTR(ls->ls_client_seq);
3146 GOTO(out_seq_fini, rc = -ENOMEM);
3149 snprintf(prefix, MAX_OBD_NAME + 5, "ctl-%s",
3153 * Init seq-controller client after seq-controller server is
3154 * ready. Pass ls->ls_control_seq to it for direct talking.
3156 rc = seq_client_init(ls->ls_client_seq, NULL,
3157 LUSTRE_SEQ_METADATA, prefix,
3158 ls->ls_control_seq);
3159 OBD_FREE(prefix, MAX_OBD_NAME + 5);
3162 GOTO(out_seq_fini, rc);
3165 /* Init seq-server on local MDT */
3166 LASSERT(ls->ls_server_seq == NULL);
3168 OBD_ALLOC_PTR(ls->ls_server_seq);
3169 if (ls->ls_server_seq == NULL)
3170 GOTO(out_seq_fini, rc = -ENOMEM);
3172 rc = seq_server_init(ls->ls_server_seq,
3173 m->mdt_bottom, uuid,
3177 GOTO(out_seq_fini, rc = -ENOMEM);
3179 /* Assign seq-controller client to local seq-server. */
3180 if (ls->ls_node_id == 0) {
3181 LASSERT(ls->ls_client_seq != NULL);
3183 rc = seq_server_set_cli(ls->ls_server_seq,
3191 mdt_seq_fini(env, m);
3196 * Init client sequence manager which is used by local MDS to talk to sequence
3197 * controller on remote node.
3199 static int mdt_seq_init_cli(const struct lu_env *env,
3200 struct mdt_device *m,
3201 struct lustre_cfg *cfg)
3203 struct lu_site *ls = m->mdt_md_dev.md_lu_dev.ld_site;
3204 struct obd_device *mdc;
3205 struct obd_uuid *uuidp, *mdcuuidp;
3206 char *uuid_str, *mdc_uuid_str;
3209 struct mdt_thread_info *info;
3210 char *p, *index_string = lustre_cfg_string(cfg, 2);
3213 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
3214 uuidp = &info->mti_u.uuid[0];
3215 mdcuuidp = &info->mti_u.uuid[1];
3217 LASSERT(index_string);
3219 index = simple_strtol(index_string, &p, 10);
3221 CERROR("Invalid index in lustre_cgf, offset 2\n");
3225 /* check if this is adding the first MDC and controller is not yet
3227 if (index != 0 || ls->ls_client_seq)
3230 uuid_str = lustre_cfg_string(cfg, 1);
3231 mdc_uuid_str = lustre_cfg_string(cfg, 4);
3232 obd_str2uuid(uuidp, uuid_str);
3233 obd_str2uuid(mdcuuidp, mdc_uuid_str);
3235 mdc = class_find_client_obd(uuidp, LUSTRE_MDC_NAME, mdcuuidp);
3237 CERROR("can't find controller MDC by uuid %s\n",
3240 } else if (!mdc->obd_set_up) {
3241 CERROR("target %s not set up\n", mdc->obd_name);
3244 LASSERT(ls->ls_control_exp);
3245 OBD_ALLOC_PTR(ls->ls_client_seq);
3246 if (ls->ls_client_seq != NULL) {
3249 OBD_ALLOC(prefix, MAX_OBD_NAME + 5);
3253 snprintf(prefix, MAX_OBD_NAME + 5, "ctl-%s",
3256 rc = seq_client_init(ls->ls_client_seq,
3258 LUSTRE_SEQ_METADATA,
3260 OBD_FREE(prefix, MAX_OBD_NAME + 5);
3267 LASSERT(ls->ls_server_seq != NULL);
3268 rc = seq_server_set_cli(ls->ls_server_seq, ls->ls_client_seq,
3275 static void mdt_seq_fini_cli(struct mdt_device *m)
3281 ls = m->mdt_md_dev.md_lu_dev.ld_site;
3283 if (ls && ls->ls_server_seq)
3284 seq_server_set_cli(ls->ls_server_seq,
3287 if (ls && ls->ls_control_exp) {
3288 class_export_put(ls->ls_control_exp);
3289 ls->ls_control_exp = NULL;
3297 static int mdt_fld_fini(const struct lu_env *env,
3298 struct mdt_device *m)
3300 struct lu_site *ls = m->mdt_md_dev.md_lu_dev.ld_site;
3303 if (ls && ls->ls_server_fld) {
3304 fld_server_fini(ls->ls_server_fld, env);
3305 OBD_FREE_PTR(ls->ls_server_fld);
3306 ls->ls_server_fld = NULL;
3312 static int mdt_fld_init(const struct lu_env *env,
3314 struct mdt_device *m)
3320 ls = m->mdt_md_dev.md_lu_dev.ld_site;
3322 OBD_ALLOC_PTR(ls->ls_server_fld);
3323 if (ls->ls_server_fld == NULL)
3324 RETURN(rc = -ENOMEM);
3326 rc = fld_server_init(ls->ls_server_fld,
3327 m->mdt_bottom, uuid, env);
3329 OBD_FREE_PTR(ls->ls_server_fld);
3330 ls->ls_server_fld = NULL;
3337 /* device init/fini methods */
3338 static void mdt_stop_ptlrpc_service(struct mdt_device *m)
3341 if (m->mdt_regular_service != NULL) {
3342 ptlrpc_unregister_service(m->mdt_regular_service);
3343 m->mdt_regular_service = NULL;
3345 if (m->mdt_readpage_service != NULL) {
3346 ptlrpc_unregister_service(m->mdt_readpage_service);
3347 m->mdt_readpage_service = NULL;
3349 if (m->mdt_xmds_service != NULL) {
3350 ptlrpc_unregister_service(m->mdt_xmds_service);
3351 m->mdt_xmds_service = NULL;
3353 if (m->mdt_setattr_service != NULL) {
3354 ptlrpc_unregister_service(m->mdt_setattr_service);
3355 m->mdt_setattr_service = NULL;
3357 if (m->mdt_mdsc_service != NULL) {
3358 ptlrpc_unregister_service(m->mdt_mdsc_service);
3359 m->mdt_mdsc_service = NULL;
3361 if (m->mdt_mdss_service != NULL) {
3362 ptlrpc_unregister_service(m->mdt_mdss_service);
3363 m->mdt_mdss_service = NULL;
3365 if (m->mdt_dtss_service != NULL) {
3366 ptlrpc_unregister_service(m->mdt_dtss_service);
3367 m->mdt_dtss_service = NULL;
3369 if (m->mdt_fld_service != NULL) {
3370 ptlrpc_unregister_service(m->mdt_fld_service);
3371 m->mdt_fld_service = NULL;
3376 static int mdt_start_ptlrpc_service(struct mdt_device *m)
3379 static struct ptlrpc_service_conf conf;
3380 cfs_proc_dir_entry_t *procfs_entry;
3383 procfs_entry = m->mdt_md_dev.md_lu_dev.ld_obd->obd_proc_entry;
3385 conf = (typeof(conf)) {
3386 .psc_nbufs = MDS_NBUFS,
3387 .psc_bufsize = MDS_BUFSIZE,
3388 .psc_max_req_size = MDS_MAXREQSIZE,
3389 .psc_max_reply_size = MDS_MAXREPSIZE,
3390 .psc_req_portal = MDS_REQUEST_PORTAL,
3391 .psc_rep_portal = MDC_REPLY_PORTAL,
3392 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
3394 * We'd like to have a mechanism to set this on a per-device
3395 * basis, but alas...
3397 .psc_min_threads = min(max(mdt_num_threads, MDT_MIN_THREADS),
3399 .psc_max_threads = MDT_MAX_THREADS,
3400 .psc_ctx_tags = LCT_MD_THREAD
3403 m->mdt_ldlm_client = &m->mdt_md_dev.md_lu_dev.ld_obd->obd_ldlm_client;
3404 ptlrpc_init_client(LDLM_CB_REQUEST_PORTAL, LDLM_CB_REPLY_PORTAL,
3405 "mdt_ldlm_client", m->mdt_ldlm_client);
3407 m->mdt_regular_service =
3408 ptlrpc_init_svc_conf(&conf, mdt_regular_handle, LUSTRE_MDT_NAME,
3409 procfs_entry, target_print_req,
3411 if (m->mdt_regular_service == NULL)
3414 rc = ptlrpc_start_threads(NULL, m->mdt_regular_service);
3416 GOTO(err_mdt_svc, rc);
3419 * readpage service configuration. Parameters have to be adjusted,
3422 conf = (typeof(conf)) {
3423 .psc_nbufs = MDS_NBUFS,
3424 .psc_bufsize = MDS_BUFSIZE,
3425 .psc_max_req_size = MDS_MAXREQSIZE,
3426 .psc_max_reply_size = MDS_MAXREPSIZE,
3427 .psc_req_portal = MDS_READPAGE_PORTAL,
3428 .psc_rep_portal = MDC_REPLY_PORTAL,
3429 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
3430 .psc_min_threads = min(max(mdt_num_threads, MDT_MIN_THREADS),
3432 .psc_max_threads = MDT_MAX_THREADS,
3433 .psc_ctx_tags = LCT_MD_THREAD
3435 m->mdt_readpage_service =
3436 ptlrpc_init_svc_conf(&conf, mdt_readpage_handle,
3437 LUSTRE_MDT_NAME "_readpage",
3438 procfs_entry, target_print_req,"mdt_rdpg");
3440 if (m->mdt_readpage_service == NULL) {
3441 CERROR("failed to start readpage service\n");
3442 GOTO(err_mdt_svc, rc = -ENOMEM);
3445 rc = ptlrpc_start_threads(NULL, m->mdt_readpage_service);
3448 * setattr service configuration.
3450 conf = (typeof(conf)) {
3451 .psc_nbufs = MDS_NBUFS,
3452 .psc_bufsize = MDS_BUFSIZE,
3453 .psc_max_req_size = MDS_MAXREQSIZE,
3454 .psc_max_reply_size = MDS_MAXREPSIZE,
3455 .psc_req_portal = MDS_SETATTR_PORTAL,
3456 .psc_rep_portal = MDC_REPLY_PORTAL,
3457 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
3458 .psc_min_threads = min(max(mdt_num_threads, MDT_MIN_THREADS),
3460 .psc_max_threads = MDT_MAX_THREADS,
3461 .psc_ctx_tags = LCT_MD_THREAD
3464 m->mdt_setattr_service =
3465 ptlrpc_init_svc_conf(&conf, mdt_regular_handle,
3466 LUSTRE_MDT_NAME "_setattr",
3467 procfs_entry, target_print_req,"mdt_attr");
3469 if (!m->mdt_setattr_service) {
3470 CERROR("failed to start setattr service\n");
3471 GOTO(err_mdt_svc, rc = -ENOMEM);
3474 rc = ptlrpc_start_threads(NULL, m->mdt_setattr_service);
3476 GOTO(err_mdt_svc, rc);
3479 * sequence controller service configuration
3481 conf = (typeof(conf)) {
3482 .psc_nbufs = MDS_NBUFS,
3483 .psc_bufsize = MDS_BUFSIZE,
3484 .psc_max_req_size = SEQ_MAXREQSIZE,
3485 .psc_max_reply_size = SEQ_MAXREPSIZE,
3486 .psc_req_portal = SEQ_CONTROLLER_PORTAL,
3487 .psc_rep_portal = MDC_REPLY_PORTAL,
3488 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
3489 .psc_min_threads = SEQ_NUM_THREADS,
3490 .psc_max_threads = SEQ_NUM_THREADS,
3491 .psc_ctx_tags = LCT_MD_THREAD|LCT_DT_THREAD
3494 m->mdt_mdsc_service =
3495 ptlrpc_init_svc_conf(&conf, mdt_mdsc_handle,
3496 LUSTRE_MDT_NAME"_mdsc",
3497 procfs_entry, target_print_req,"mdt_mdsc");
3498 if (!m->mdt_mdsc_service) {
3499 CERROR("failed to start seq controller service\n");
3500 GOTO(err_mdt_svc, rc = -ENOMEM);
3503 rc = ptlrpc_start_threads(NULL, m->mdt_mdsc_service);
3505 GOTO(err_mdt_svc, rc);
3508 * metadata sequence server service configuration
3510 conf = (typeof(conf)) {
3511 .psc_nbufs = MDS_NBUFS,
3512 .psc_bufsize = MDS_BUFSIZE,
3513 .psc_max_req_size = SEQ_MAXREQSIZE,
3514 .psc_max_reply_size = SEQ_MAXREPSIZE,
3515 .psc_req_portal = SEQ_METADATA_PORTAL,
3516 .psc_rep_portal = MDC_REPLY_PORTAL,
3517 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
3518 .psc_min_threads = SEQ_NUM_THREADS,
3519 .psc_max_threads = SEQ_NUM_THREADS,
3520 .psc_ctx_tags = LCT_MD_THREAD|LCT_DT_THREAD
3523 m->mdt_mdss_service =
3524 ptlrpc_init_svc_conf(&conf, mdt_mdss_handle,
3525 LUSTRE_MDT_NAME"_mdss",
3526 procfs_entry, target_print_req,"mdt_mdss");
3527 if (!m->mdt_mdss_service) {
3528 CERROR("failed to start metadata seq server service\n");
3529 GOTO(err_mdt_svc, rc = -ENOMEM);
3532 rc = ptlrpc_start_threads(NULL, m->mdt_mdss_service);
3534 GOTO(err_mdt_svc, rc);
3538 * Data sequence server service configuration. We want to have really
3539 * cluster-wide sequences space. This is why we start only one sequence
3540 * controller which manages space.
3542 conf = (typeof(conf)) {
3543 .psc_nbufs = MDS_NBUFS,
3544 .psc_bufsize = MDS_BUFSIZE,
3545 .psc_max_req_size = SEQ_MAXREQSIZE,
3546 .psc_max_reply_size = SEQ_MAXREPSIZE,
3547 .psc_req_portal = SEQ_DATA_PORTAL,
3548 .psc_rep_portal = OSC_REPLY_PORTAL,
3549 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
3550 .psc_min_threads = SEQ_NUM_THREADS,
3551 .psc_max_threads = SEQ_NUM_THREADS,
3552 .psc_ctx_tags = LCT_MD_THREAD|LCT_DT_THREAD
3555 m->mdt_dtss_service =
3556 ptlrpc_init_svc_conf(&conf, mdt_dtss_handle,
3557 LUSTRE_MDT_NAME"_dtss",
3558 procfs_entry, target_print_req,"mdt_dtss");
3559 if (!m->mdt_dtss_service) {
3560 CERROR("failed to start data seq server service\n");
3561 GOTO(err_mdt_svc, rc = -ENOMEM);
3564 rc = ptlrpc_start_threads(NULL, m->mdt_dtss_service);
3566 GOTO(err_mdt_svc, rc);
3568 /* FLD service start */
3569 conf = (typeof(conf)) {
3570 .psc_nbufs = MDS_NBUFS,
3571 .psc_bufsize = MDS_BUFSIZE,
3572 .psc_max_req_size = FLD_MAXREQSIZE,
3573 .psc_max_reply_size = FLD_MAXREPSIZE,
3574 .psc_req_portal = FLD_REQUEST_PORTAL,
3575 .psc_rep_portal = MDC_REPLY_PORTAL,
3576 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
3577 .psc_min_threads = FLD_NUM_THREADS,
3578 .psc_max_threads = FLD_NUM_THREADS,
3579 .psc_ctx_tags = LCT_DT_THREAD|LCT_MD_THREAD
3582 m->mdt_fld_service =
3583 ptlrpc_init_svc_conf(&conf, mdt_fld_handle,
3584 LUSTRE_MDT_NAME"_fld",
3585 procfs_entry, target_print_req, "mdt_fld");
3586 if (!m->mdt_fld_service) {
3587 CERROR("failed to start fld service\n");
3588 GOTO(err_mdt_svc, rc = -ENOMEM);
3591 rc = ptlrpc_start_threads(NULL, m->mdt_fld_service);
3593 GOTO(err_mdt_svc, rc);
3596 * mds-mds service configuration. Separate portal is used to allow
3597 * mds-mds requests be not blocked during recovery.
3599 conf = (typeof(conf)) {
3600 .psc_nbufs = MDS_NBUFS,
3601 .psc_bufsize = MDS_BUFSIZE,
3602 .psc_max_req_size = MDS_MAXREQSIZE,
3603 .psc_max_reply_size = MDS_MAXREPSIZE,
3604 .psc_req_portal = MDS_MDS_PORTAL,
3605 .psc_rep_portal = MDC_REPLY_PORTAL,
3606 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
3607 .psc_min_threads = min(max(mdt_num_threads, MDT_MIN_THREADS),
3609 .psc_max_threads = MDT_MAX_THREADS,
3610 .psc_ctx_tags = LCT_MD_THREAD
3612 m->mdt_xmds_service =
3613 ptlrpc_init_svc_conf(&conf, mdt_xmds_handle,
3614 LUSTRE_MDT_NAME "_mds",
3615 procfs_entry, target_print_req,"mdt_xmds");
3617 if (m->mdt_xmds_service == NULL) {
3618 CERROR("failed to start readpage service\n");
3619 GOTO(err_mdt_svc, rc = -ENOMEM);
3622 rc = ptlrpc_start_threads(NULL, m->mdt_xmds_service);
3624 GOTO(err_mdt_svc, rc);
3629 mdt_stop_ptlrpc_service(m);
3634 static void mdt_stack_fini(const struct lu_env *env,
3635 struct mdt_device *m, struct lu_device *top)
3637 struct obd_device *obd = m->mdt_md_dev.md_lu_dev.ld_obd;
3638 struct lustre_cfg_bufs *bufs;
3639 struct lustre_cfg *lcfg;
3640 struct mdt_thread_info *info;
3644 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
3645 LASSERT(info != NULL);
3647 bufs = &info->mti_u.bufs;
3648 /* process cleanup, pass mdt obd name to get obd umount flags */
3649 lustre_cfg_bufs_reset(bufs, obd->obd_name);
3654 lustre_cfg_bufs_set_string(bufs, 1, flags);
3655 lcfg = lustre_cfg_new(LCFG_CLEANUP, bufs);
3657 CERROR("Cannot alloc lcfg!\n");
3662 top->ld_ops->ldo_process_config(env, top, lcfg);
3663 lustre_cfg_free(lcfg);
3665 lu_stack_fini(env, top);
3666 m->mdt_child = NULL;
3667 m->mdt_bottom = NULL;
3670 static struct lu_device *mdt_layer_setup(const struct lu_env *env,
3671 const char *typename,
3672 struct lu_device *child,
3673 struct lustre_cfg *cfg)
3675 const char *dev = lustre_cfg_string(cfg, 0);
3676 struct obd_type *type;
3677 struct lu_device_type *ldt;
3678 struct lu_device *d;
3683 type = class_get_type(typename);
3685 CERROR("Unknown type: '%s'\n", typename);
3686 GOTO(out, rc = -ENODEV);
3689 rc = lu_context_refill(&env->le_ctx);
3691 CERROR("Failure to refill context: '%d'\n", rc);
3695 if (env->le_ses != NULL) {
3696 rc = lu_context_refill(env->le_ses);
3698 CERROR("Failure to refill session: '%d'\n", rc);
3705 CERROR("type: '%s'\n", typename);
3706 GOTO(out_type, rc = -EINVAL);
3709 ldt->ldt_obd_type = type;
3710 d = ldt->ldt_ops->ldto_device_alloc(env, ldt, cfg);
3712 CERROR("Cannot allocate device: '%s'\n", typename);
3713 GOTO(out_type, rc = -ENODEV);
3716 LASSERT(child->ld_site);
3717 d->ld_site = child->ld_site;
3720 rc = ldt->ldt_ops->ldto_device_init(env, d, dev, child);
3722 CERROR("can't init device '%s', rc %d\n", typename, rc);
3723 GOTO(out_alloc, rc);
3730 ldt->ldt_ops->ldto_device_free(env, d);
3733 class_put_type(type);
3738 static int mdt_stack_init(const struct lu_env *env,
3739 struct mdt_device *m, struct lustre_cfg *cfg)
3741 struct lu_device *d = &m->mdt_md_dev.md_lu_dev;
3742 struct lu_device *tmp;
3743 struct md_device *md;
3747 /* init the stack */
3748 tmp = mdt_layer_setup(env, LUSTRE_OSD_NAME, d, cfg);
3750 RETURN(PTR_ERR(tmp));
3752 m->mdt_bottom = lu2dt_dev(tmp);
3754 tmp = mdt_layer_setup(env, LUSTRE_MDD_NAME, d, cfg);
3756 GOTO(out, rc = PTR_ERR(tmp));
3761 tmp = mdt_layer_setup(env, LUSTRE_CMM_NAME, d, cfg);
3763 GOTO(out, rc = PTR_ERR(tmp));
3766 /*set mdd upcall device*/
3767 md_upcall_dev_set(md, lu2md_dev(d));
3770 /*set cmm upcall device*/
3771 md_upcall_dev_set(md, &m->mdt_md_dev);
3773 m->mdt_child = lu2md_dev(d);
3775 /* process setup config */
3776 tmp = &m->mdt_md_dev.md_lu_dev;
3777 rc = tmp->ld_ops->ldo_process_config(env, tmp, cfg);
3780 /* fini from last known good lu_device */
3782 mdt_stack_fini(env, m, d);
3787 static void mdt_fini(const struct lu_env *env, struct mdt_device *m)
3789 struct md_device *next = m->mdt_child;
3790 struct lu_device *d = &m->mdt_md_dev.md_lu_dev;
3791 struct lu_site *ls = d->ld_site;
3792 struct obd_device *obd = m->mdt_md_dev.md_lu_dev.ld_obd;
3795 ping_evictor_stop();
3797 target_recovery_fini(obd);
3798 mdt_stop_ptlrpc_service(m);
3800 mdt_fs_cleanup(env, m);
3802 upcall_cache_cleanup(m->mdt_identity_cache);
3803 m->mdt_identity_cache = NULL;
3805 if (m->mdt_namespace != NULL) {
3806 ldlm_namespace_free(m->mdt_namespace, NULL, d->ld_obd->obd_force);
3807 d->ld_obd->obd_namespace = m->mdt_namespace = NULL;
3810 mdt_seq_fini(env, m);
3811 mdt_seq_fini_cli(m);
3812 mdt_fld_fini(env, m);
3814 ptlrpc_lprocfs_unregister_obd(d->ld_obd);
3815 lprocfs_obd_cleanup(d->ld_obd);
3817 sptlrpc_rule_set_free(&m->mdt_sptlrpc_rset);
3819 next->md_ops->mdo_init_capa_ctxt(env, next, 0, 0, 0, NULL);
3820 cfs_timer_disarm(&m->mdt_ck_timer);
3821 mdt_ck_thread_stop(m);
3823 /* finish the stack */
3824 mdt_stack_fini(env, m, md2lu_dev(m->mdt_child));
3831 LASSERT(atomic_read(&d->ld_ref) == 0);
3832 md_device_fini(&m->mdt_md_dev);
3837 static void fsoptions_to_mdt_flags(struct mdt_device *m, char *options)
3841 #ifdef CONFIG_FS_POSIX_ACL
3842 /* ACLs should be enabled by default (b=13829) */
3843 m->mdt_opts.mo_acl = 1;
3844 LCONSOLE_INFO("Enabling ACL\n");
3846 m->mdt_opts.mo_acl = 0;
3847 LCONSOLE_INFO("Disabling ACL\n");
3856 while (*p && *p != ',')
3860 if ((len == sizeof("user_xattr") - 1) &&
3861 (memcmp(options, "user_xattr", len) == 0)) {
3862 m->mdt_opts.mo_user_xattr = 1;
3863 LCONSOLE_INFO("Enabling user_xattr\n");
3864 } else if ((len == sizeof("nouser_xattr") - 1) &&
3865 (memcmp(options, "nouser_xattr", len) == 0)) {
3866 m->mdt_opts.mo_user_xattr = 0;
3867 LCONSOLE_INFO("Disabling user_xattr\n");
3868 } else if ((len == sizeof("noacl") - 1) &&
3869 (memcmp(options, "noacl", len) == 0)) {
3870 m->mdt_opts.mo_acl = 0;
3871 LCONSOLE_INFO("Disabling ACL\n");
3878 int mdt_postrecov(const struct lu_env *, struct mdt_device *);
3880 static int mdt_init0(const struct lu_env *env, struct mdt_device *m,
3881 struct lu_device_type *ldt, struct lustre_cfg *cfg)
3883 struct lprocfs_static_vars lvars;
3884 struct mdt_thread_info *info;
3885 struct obd_device *obd;
3886 const char *dev = lustre_cfg_string(cfg, 0);
3887 const char *num = lustre_cfg_string(cfg, 2);
3888 struct lustre_mount_info *lmi;
3889 struct lustre_sb_info *lsi;
3891 const char *identity_upcall = "NONE";
3895 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
3896 LASSERT(info != NULL);
3898 obd = class_name2obd(dev);
3899 LASSERT(obd != NULL);
3901 spin_lock_init(&m->mdt_transno_lock);
3903 m->mdt_max_mdsize = MAX_MD_SIZE;
3904 m->mdt_max_cookiesize = sizeof(struct llog_cookie);
3906 m->mdt_opts.mo_user_xattr = 0;
3907 m->mdt_opts.mo_acl = 0;
3908 lmi = server_get_mount_2(dev);
3910 CERROR("Cannot get mount info for %s!\n", dev);
3913 lsi = s2lsi(lmi->lmi_sb);
3914 fsoptions_to_mdt_flags(m, lsi->lsi_lmd->lmd_opts);
3915 server_put_mount_2(dev, lmi->lmi_mnt);
3918 m->mdt_sptlrpc_lock = RW_LOCK_UNLOCKED;
3919 sptlrpc_rule_set_init(&m->mdt_sptlrpc_rset);
3921 spin_lock_init(&m->mdt_ioepoch_lock);
3922 m->mdt_opts.mo_compat_resname = 0;
3923 m->mdt_capa_timeout = CAPA_TIMEOUT;
3924 m->mdt_capa_alg = CAPA_HMAC_ALG_SHA1;
3925 m->mdt_ck_timeout = CAPA_KEY_TIMEOUT;
3927 spin_lock_init(&m->mdt_client_bitmap_lock);
3933 md_device_init(&m->mdt_md_dev, ldt);
3934 m->mdt_md_dev.md_lu_dev.ld_ops = &mdt_lu_ops;
3935 m->mdt_md_dev.md_lu_dev.ld_obd = obd;
3936 /* set this lu_device to obd, because error handling need it */
3937 obd->obd_lu_dev = &m->mdt_md_dev.md_lu_dev;
3939 rc = lu_site_init(s, &m->mdt_md_dev.md_lu_dev);
3941 CERROR("Can't init lu_site, rc %d\n", rc);
3942 GOTO(err_free_site, rc);
3945 lprocfs_mdt_init_vars(&lvars);
3946 rc = lprocfs_obd_setup(obd, lvars.obd_vars);
3948 CERROR("Can't init lprocfs, rc %d\n", rc);
3949 GOTO(err_fini_site, rc);
3951 ptlrpc_lprocfs_register_obd(obd);
3953 rc = mdt_procfs_init(m, dev);
3955 CERROR("Can't init MDT lprocfs, rc %d\n", rc);
3956 GOTO(err_fini_proc, rc);
3959 /* set server index */
3961 s->ls_node_id = simple_strtol(num, NULL, 10);
3963 /* failover is the default
3964 * FIXME: we do not failout mds0/mgs, which may cause some problems.
3965 * assumed whose ls_node_id == 0 XXX
3967 obd->obd_replayable = 1;
3968 /* No connection accepted until configurations will finish */
3969 obd->obd_no_conn = 1;
3971 if (cfg->lcfg_bufcount > 4 && LUSTRE_CFG_BUFLEN(cfg, 4) > 0) {
3972 char *str = lustre_cfg_string(cfg, 4);
3973 if (strchr(str, 'n')) {
3974 CWARN("%s: recovery disabled\n", obd->obd_name);
3975 obd->obd_replayable = 0;
3979 /* init the stack */
3980 rc = mdt_stack_init(env, m, cfg);
3982 CERROR("Can't init device stack, rc %d\n", rc);
3983 GOTO(err_fini_proc, rc);
3986 rc = mdt_fld_init(env, obd->obd_name, m);
3988 GOTO(err_fini_stack, rc);
3990 rc = mdt_seq_init(env, obd->obd_name, m);
3992 GOTO(err_fini_fld, rc);
3994 snprintf(info->mti_u.ns_name, sizeof info->mti_u.ns_name,
3995 LUSTRE_MDT_NAME"-%p", m);
3996 m->mdt_namespace = ldlm_namespace_new(obd, info->mti_u.ns_name,
3997 LDLM_NAMESPACE_SERVER,
3998 LDLM_NAMESPACE_GREEDY);
3999 if (m->mdt_namespace == NULL)
4000 GOTO(err_fini_seq, rc = -ENOMEM);
4002 ldlm_register_intent(m->mdt_namespace, mdt_intent_policy);
4003 /* set obd_namespace for compatibility with old code */
4004 obd->obd_namespace = m->mdt_namespace;
4006 /* XXX: to support suppgid for ACL, we enable identity_upcall
4007 * by default, otherwise, maybe got unexpected -EACCESS. */
4008 if (m->mdt_opts.mo_acl)
4009 identity_upcall = MDT_IDENTITY_UPCALL_PATH;
4011 m->mdt_identity_cache = upcall_cache_init(obd->obd_name, identity_upcall,
4012 &mdt_identity_upcall_cache_ops);
4013 if (IS_ERR(m->mdt_identity_cache)) {
4014 rc = PTR_ERR(m->mdt_identity_cache);
4015 m->mdt_identity_cache = NULL;
4016 GOTO(err_free_ns, rc);
4019 cfs_timer_init(&m->mdt_ck_timer, mdt_ck_timer_callback, m);
4021 rc = mdt_ck_thread_start(m);
4023 GOTO(err_free_ns, rc);
4025 rc = mdt_fs_setup(env, m, obd);
4029 target_recovery_init(obd, mdt_recovery_handle);
4031 rc = mdt_start_ptlrpc_service(m);
4033 GOTO(err_fs_cleanup, rc);
4035 ping_evictor_start();
4037 rc = lu_site_init_finish(s);
4039 GOTO(err_stop_service, rc);
4041 if (obd->obd_recovering == 0)
4042 mdt_postrecov(env, m);
4044 mdt_init_capa_ctxt(env, m);
4046 /* Reduce the initial timeout on an MDS because it doesn't need such
4047 * a long timeout as an OST does. Adaptive timeouts will adjust this
4048 * value appropriately. */
4049 if (ldlm_timeout == LDLM_TIMEOUT_DEFAULT)
4050 ldlm_timeout = MDS_LDLM_TIMEOUT_DEFAULT;
4055 ping_evictor_stop();
4056 mdt_stop_ptlrpc_service(m);
4058 target_recovery_fini(obd);
4059 mdt_fs_cleanup(env, m);
4061 cfs_timer_disarm(&m->mdt_ck_timer);
4062 mdt_ck_thread_stop(m);
4064 upcall_cache_cleanup(m->mdt_identity_cache);
4065 m->mdt_identity_cache = NULL;
4066 ldlm_namespace_free(m->mdt_namespace, NULL, 0);
4067 obd->obd_namespace = m->mdt_namespace = NULL;
4069 mdt_seq_fini(env, m);
4071 mdt_fld_fini(env, m);
4073 mdt_stack_fini(env, m, md2lu_dev(m->mdt_child));
4076 ptlrpc_lprocfs_unregister_obd(obd);
4077 lprocfs_obd_cleanup(obd);
4083 md_device_fini(&m->mdt_md_dev);
4087 /* used by MGS to process specific configurations */
4088 static int mdt_process_config(const struct lu_env *env,
4089 struct lu_device *d, struct lustre_cfg *cfg)
4091 struct mdt_device *m = mdt_dev(d);
4092 struct md_device *md_next = m->mdt_child;
4093 struct lu_device *next = md2lu_dev(md_next);
4097 switch (cfg->lcfg_command) {
4098 case LCFG_SPTLRPC_CONF: {
4099 struct sptlrpc_conf_log *log;
4100 struct sptlrpc_rule_set tmp_rset;
4102 log = sptlrpc_conf_log_extract(cfg);
4108 sptlrpc_rule_set_init(&tmp_rset);
4110 rc = sptlrpc_rule_set_from_log(&tmp_rset, log);
4112 CERROR("mdt %p: failed get sptlrpc rules: %d\n", m, rc);
4116 write_lock(&m->mdt_sptlrpc_lock);
4117 sptlrpc_rule_set_free(&m->mdt_sptlrpc_rset);
4118 m->mdt_sptlrpc_rset = tmp_rset;
4119 write_unlock(&m->mdt_sptlrpc_lock);
4121 sptlrpc_target_update_exp_flavor(
4122 md2lu_dev(&m->mdt_md_dev)->ld_obd, &tmp_rset);
4127 struct lprocfs_static_vars lvars;
4128 struct obd_device *obd = d->ld_obd;
4130 lprocfs_mdt_init_vars(&lvars);
4131 rc = class_process_proc_param(PARAM_MDT, lvars.obd_vars, cfg, obd);
4133 /* others are passed further */
4134 rc = next->ld_ops->ldo_process_config(env, next, cfg);
4139 * Add mdc hook to get first MDT uuid and connect it to
4140 * ls->controller to use for seq manager.
4142 rc = next->ld_ops->ldo_process_config(env, next, cfg);
4144 CERROR("Can't add mdc, rc %d\n", rc);
4146 rc = mdt_seq_init_cli(env, mdt_dev(d), cfg);
4149 /* others are passed further */
4150 rc = next->ld_ops->ldo_process_config(env, next, cfg);
4156 static struct lu_object *mdt_object_alloc(const struct lu_env *env,
4157 const struct lu_object_header *hdr,
4158 struct lu_device *d)
4160 struct mdt_object *mo;
4166 struct lu_object *o;
4167 struct lu_object_header *h;
4169 o = &mo->mot_obj.mo_lu;
4170 h = &mo->mot_header;
4171 lu_object_header_init(h);
4172 lu_object_init(o, h, d);
4173 lu_object_add_top(h, o);
4174 o->lo_ops = &mdt_obj_ops;
4180 static int mdt_object_init(const struct lu_env *env, struct lu_object *o)
4182 struct mdt_device *d = mdt_dev(o->lo_dev);
4183 struct lu_device *under;
4184 struct lu_object *below;
4188 CDEBUG(D_INFO, "object init, fid = "DFID"\n",
4189 PFID(lu_object_fid(o)));
4191 under = &d->mdt_child->md_lu_dev;
4192 below = under->ld_ops->ldo_object_alloc(env, o->lo_header, under);
4193 if (below != NULL) {
4194 lu_object_add(o, below);
4201 static void mdt_object_free(const struct lu_env *env, struct lu_object *o)
4203 struct mdt_object *mo = mdt_obj(o);
4204 struct lu_object_header *h;
4208 CDEBUG(D_INFO, "object free, fid = "DFID"\n",
4209 PFID(lu_object_fid(o)));
4212 lu_object_header_fini(h);
4217 static int mdt_object_print(const struct lu_env *env, void *cookie,
4218 lu_printer_t p, const struct lu_object *o)
4220 return (*p)(env, cookie, LUSTRE_MDT_NAME"-object@%p", o);
4223 static struct lu_device_operations mdt_lu_ops = {
4224 .ldo_object_alloc = mdt_object_alloc,
4225 .ldo_process_config = mdt_process_config
4228 static struct lu_object_operations mdt_obj_ops = {
4229 .loo_object_init = mdt_object_init,
4230 .loo_object_free = mdt_object_free,
4231 .loo_object_print = mdt_object_print
4234 /* mds_connect_internal */
4235 static int mdt_connect_internal(struct obd_export *exp,
4236 struct mdt_device *mdt,
4237 struct obd_connect_data *data)
4242 data->ocd_connect_flags &= MDT_CONNECT_SUPPORTED;
4243 data->ocd_ibits_known &= MDS_INODELOCK_FULL;
4245 /* If no known bits (which should not happen, probably,
4246 as everybody should support LOOKUP and UPDATE bits at least)
4247 revert to compat mode with plain locks. */
4248 if (!data->ocd_ibits_known &&
4249 data->ocd_connect_flags & OBD_CONNECT_IBITS)
4250 data->ocd_connect_flags &= ~OBD_CONNECT_IBITS;
4252 if (!mdt->mdt_opts.mo_acl)
4253 data->ocd_connect_flags &= ~OBD_CONNECT_ACL;
4255 if (!mdt->mdt_opts.mo_user_xattr)
4256 data->ocd_connect_flags &= ~OBD_CONNECT_XATTR;
4258 if (!mdt->mdt_opts.mo_mds_capa)
4259 data->ocd_connect_flags &= ~OBD_CONNECT_MDS_CAPA;
4261 if (!mdt->mdt_opts.mo_oss_capa)
4262 data->ocd_connect_flags &= ~OBD_CONNECT_OSS_CAPA;
4264 spin_lock(&exp->exp_lock);
4265 exp->exp_connect_flags = data->ocd_connect_flags;
4266 spin_unlock(&exp->exp_lock);
4267 data->ocd_version = LUSTRE_VERSION_CODE;
4268 exp->exp_mdt_data.med_ibits_known = data->ocd_ibits_known;
4272 if (mdt->mdt_opts.mo_acl &&
4273 ((exp->exp_connect_flags & OBD_CONNECT_ACL) == 0)) {
4274 CWARN("%s: MDS requires ACL support but client does not\n",
4275 mdt->mdt_md_dev.md_lu_dev.ld_obd->obd_name);
4280 flags = OBD_CONNECT_LCL_CLIENT | OBD_CONNECT_RMT_CLIENT;
4281 if ((exp->exp_connect_flags & flags) == flags) {
4282 CWARN("%s: both local and remote client flags are set\n",
4283 mdt->mdt_md_dev.md_lu_dev.ld_obd->obd_name);
4287 if (mdt->mdt_opts.mo_mds_capa &&
4288 ((exp->exp_connect_flags & OBD_CONNECT_MDS_CAPA) == 0)) {
4289 CWARN("%s: MDS requires capability support, but client not\n",
4290 mdt->mdt_md_dev.md_lu_dev.ld_obd->obd_name);
4294 if (mdt->mdt_opts.mo_oss_capa &&
4295 ((exp->exp_connect_flags & OBD_CONNECT_OSS_CAPA) == 0)) {
4296 CWARN("%s: MDS requires OSS capability support, "
4298 mdt->mdt_md_dev.md_lu_dev.ld_obd->obd_name);
4302 if ((exp->exp_connect_flags & OBD_CONNECT_FID) == 0) {
4303 CWARN("%s: MDS requires FID support, but client not\n",
4304 mdt->mdt_md_dev.md_lu_dev.ld_obd->obd_name);
4311 /* mds_connect copy */
4312 static int mdt_obd_connect(const struct lu_env *env,
4313 struct lustre_handle *conn, struct obd_device *obd,
4314 struct obd_uuid *cluuid,
4315 struct obd_connect_data *data,
4318 struct mdt_thread_info *info;
4319 struct lsd_client_data *lcd;
4320 struct obd_export *exp;
4321 struct mdt_device *mdt;
4322 struct ptlrpc_request *req;
4326 LASSERT(env != NULL);
4327 if (!conn || !obd || !cluuid)
4330 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
4331 req = info->mti_pill->rc_req;
4332 mdt = mdt_dev(obd->obd_lu_dev);
4334 rc = class_connect(conn, obd, cluuid);
4338 exp = class_conn2export(conn);
4339 LASSERT(exp != NULL);
4341 CDEBUG(D_SEC, "from %s\n", sptlrpc_part2name(req->rq_sp_from));
4343 spin_lock(&exp->exp_lock);
4344 exp->exp_sp_peer = req->rq_sp_from;
4346 read_lock(&mdt->mdt_sptlrpc_lock);
4347 sptlrpc_rule_set_choose(&mdt->mdt_sptlrpc_rset, exp->exp_sp_peer,
4348 req->rq_peer.nid, &exp->exp_flvr);
4349 read_unlock(&mdt->mdt_sptlrpc_lock);
4351 if (exp->exp_flvr.sf_rpc != req->rq_flvr.sf_rpc) {
4352 CERROR("invalid rpc flavor %x, expect %x, from %s\n",
4353 req->rq_flvr.sf_rpc, exp->exp_flvr.sf_rpc,
4354 libcfs_nid2str(req->rq_peer.nid));
4355 exp->exp_flvr.sf_rpc = SPTLRPC_FLVR_INVALID;
4356 spin_unlock(&exp->exp_lock);
4359 spin_unlock(&exp->exp_lock);
4361 rc = mdt_connect_internal(exp, mdt, data);
4365 struct mdt_thread_info *mti;
4366 mti = lu_context_key_get(&env->le_ctx,
4368 LASSERT(mti != NULL);
4370 memcpy(lcd->lcd_uuid, cluuid, sizeof lcd->lcd_uuid);
4371 exp->exp_mdt_data.med_lcd = lcd;
4372 rc = mdt_client_new(env, mdt);
4375 exp->exp_mdt_data.med_lcd = NULL;
4382 class_disconnect(exp);
4384 class_export_put(exp);
4389 static int mdt_obd_reconnect(const struct lu_env *env,
4390 struct obd_export *exp, struct obd_device *obd,
4391 struct obd_uuid *cluuid,
4392 struct obd_connect_data *data)
4394 struct mdt_thread_info *info;
4395 struct mdt_device *mdt;
4396 struct ptlrpc_request *req;
4400 if (exp == NULL || obd == NULL || cluuid == NULL)
4403 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
4404 req = info->mti_pill->rc_req;
4405 mdt = mdt_dev(obd->obd_lu_dev);
4407 CDEBUG(D_SEC, "from %s\n", sptlrpc_part2name(req->rq_sp_from));
4409 spin_lock(&exp->exp_lock);
4410 if (exp->exp_flvr.sf_rpc == SPTLRPC_FLVR_INVALID) {
4411 exp->exp_sp_peer = req->rq_sp_from;
4413 read_lock(&mdt->mdt_sptlrpc_lock);
4414 sptlrpc_rule_set_choose(&mdt->mdt_sptlrpc_rset,
4416 req->rq_peer.nid, &exp->exp_flvr);
4417 read_unlock(&mdt->mdt_sptlrpc_lock);
4419 if (exp->exp_flvr.sf_rpc != req->rq_flvr.sf_rpc) {
4420 CERROR("invalid rpc flavor %x, expect %x, from %s\n",
4421 req->rq_flvr.sf_rpc, exp->exp_flvr.sf_rpc,
4422 libcfs_nid2str(req->rq_peer.nid));
4423 exp->exp_flvr.sf_rpc = SPTLRPC_FLVR_INVALID;
4424 spin_unlock(&exp->exp_lock);
4428 spin_unlock(&exp->exp_lock);
4430 rc = mdt_connect_internal(exp, mdt_dev(obd->obd_lu_dev), data);
4435 static int mdt_obd_disconnect(struct obd_export *exp)
4437 struct mdt_device *mdt = mdt_dev(exp->exp_obd->obd_lu_dev);
4442 class_export_get(exp);
4444 /* Disconnect early so that clients can't keep using export */
4445 rc = class_disconnect(exp);
4446 if (mdt->mdt_namespace != NULL || exp->exp_obd->obd_namespace != NULL)
4447 ldlm_cancel_locks_for_export(exp);
4449 /* complete all outstanding replies */
4450 spin_lock(&exp->exp_lock);
4451 while (!list_empty(&exp->exp_outstanding_replies)) {
4452 struct ptlrpc_reply_state *rs =
4453 list_entry(exp->exp_outstanding_replies.next,
4454 struct ptlrpc_reply_state, rs_exp_list);
4455 struct ptlrpc_service *svc = rs->rs_service;
4457 spin_lock(&svc->srv_lock);
4458 list_del_init(&rs->rs_exp_list);
4459 ptlrpc_schedule_difficult_reply(rs);
4460 spin_unlock(&svc->srv_lock);
4462 spin_unlock(&exp->exp_lock);
4464 class_export_put(exp);
4468 /* FIXME: Can we avoid using these two interfaces? */
4469 static int mdt_init_export(struct obd_export *exp)
4471 struct mdt_export_data *med = &exp->exp_mdt_data;
4475 CFS_INIT_LIST_HEAD(&med->med_open_head);
4476 spin_lock_init(&med->med_open_lock);
4477 sema_init(&med->med_idmap_sem, 1);
4478 med->med_idmap = NULL;
4479 spin_lock(&exp->exp_lock);
4480 exp->exp_connecting = 1;
4481 spin_unlock(&exp->exp_lock);
4482 rc = ldlm_init_export(exp);
4484 CERROR("Error %d while initializing export\n", rc);
4488 static int mdt_destroy_export(struct obd_export *export)
4490 struct mdt_export_data *med;
4491 struct obd_device *obd = export->exp_obd;
4492 struct mdt_device *mdt;
4493 struct mdt_thread_info *info;
4501 med = &export->exp_mdt_data;
4502 if (med->med_rmtclient)
4503 mdt_cleanup_idmap(med);
4505 target_destroy_export(export);
4506 ldlm_destroy_export(export);
4508 if (obd_uuid_equals(&export->exp_client_uuid, &obd->obd_uuid))
4511 mdt = mdt_dev(obd->obd_lu_dev);
4512 LASSERT(mdt != NULL);
4514 rc = lu_env_init(&env, NULL, LCT_MD_THREAD);
4518 info = lu_context_key_get(&env.le_ctx, &mdt_thread_key);
4519 LASSERT(info != NULL);
4520 memset(info, 0, sizeof *info);
4521 info->mti_env = &env;
4522 info->mti_mdt = mdt;
4523 info->mti_exp = export;
4525 ma = &info->mti_attr;
4526 lmm_size = ma->ma_lmm_size = mdt->mdt_max_mdsize;
4527 cookie_size = ma->ma_cookie_size = mdt->mdt_max_cookiesize;
4528 OBD_ALLOC(ma->ma_lmm, lmm_size);
4529 OBD_ALLOC(ma->ma_cookie, cookie_size);
4531 if (ma->ma_lmm == NULL || ma->ma_cookie == NULL)
4532 GOTO(out, rc = -ENOMEM);
4533 ma->ma_need = MA_LOV | MA_COOKIE;
4535 /* Close any open files (which may also cause orphan unlinking). */
4536 spin_lock(&med->med_open_lock);
4537 while (!list_empty(&med->med_open_head)) {
4538 struct list_head *tmp = med->med_open_head.next;
4539 struct mdt_file_data *mfd =
4540 list_entry(tmp, struct mdt_file_data, mfd_list);
4542 /* Remove mfd handle so it can't be found again.
4543 * We are consuming the mfd_list reference here. */
4544 class_handle_unhash(&mfd->mfd_handle);
4545 list_del_init(&mfd->mfd_list);
4546 spin_unlock(&med->med_open_lock);
4547 mdt_mfd_close(info, mfd);
4548 /* TODO: if we close the unlinked file,
4549 * we need to remove it's objects from OST */
4550 memset(&ma->ma_attr, 0, sizeof(ma->ma_attr));
4551 spin_lock(&med->med_open_lock);
4552 ma->ma_lmm_size = lmm_size;
4553 ma->ma_cookie_size = cookie_size;
4554 ma->ma_need = MA_LOV | MA_COOKIE;
4557 spin_unlock(&med->med_open_lock);
4558 info->mti_mdt = NULL;
4559 mdt_client_del(&env, mdt);
4564 OBD_FREE(ma->ma_lmm, lmm_size);
4568 OBD_FREE(ma->ma_cookie, cookie_size);
4569 ma->ma_cookie = NULL;
4576 static void mdt_allow_cli(struct mdt_device *m, unsigned int flag)
4578 if (flag & CONFIG_LOG)
4579 m->mdt_fl_cfglog = 1;
4580 if (flag & CONFIG_SYNC)
4581 m->mdt_fl_synced = 1;
4583 if (m->mdt_fl_cfglog /* bz11778: && m->mdt_fl_synced */)
4584 /* Open for clients */
4585 m->mdt_md_dev.md_lu_dev.ld_obd->obd_no_conn = 0;
4588 static int mdt_upcall(const struct lu_env *env, struct md_device *md,
4589 enum md_upcall_event ev)
4591 struct mdt_device *m = mdt_dev(&md->md_lu_dev);
4592 struct md_device *next = m->mdt_child;
4593 struct mdt_thread_info *mti;
4599 rc = next->md_ops->mdo_maxsize_get(env, next,
4601 &m->mdt_max_cookiesize);
4602 CDEBUG(D_INFO, "get max mdsize %d max cookiesize %d\n",
4603 m->mdt_max_mdsize, m->mdt_max_cookiesize);
4604 mdt_allow_cli(m, CONFIG_SYNC);
4607 mti = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
4608 mti->mti_no_need_trans = 1;
4609 CDEBUG(D_INFO, "disable mdt trans for this thread\n");
4612 /* Check that MDT is not yet configured */
4613 LASSERT(!m->mdt_fl_cfglog);
4616 CERROR("invalid event\n");
4623 static int mdt_obd_notify(struct obd_device *host,
4624 struct obd_device *watched,
4625 enum obd_notify_event ev, void *data)
4630 case OBD_NOTIFY_CONFIG:
4631 mdt_allow_cli(mdt_dev(host->obd_lu_dev), (unsigned long)data);
4634 CDEBUG(D_INFO, "Unhandled notification %#x\n", ev);
4639 static int mdt_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
4640 void *karg, void *uarg)
4643 struct obd_device *obd= exp->exp_obd;
4644 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
4645 struct dt_device *dt = mdt->mdt_bottom;
4649 CDEBUG(D_IOCTL, "handling ioctl cmd %#x\n", cmd);
4650 rc = lu_env_init(&env, NULL, LCT_MD_THREAD);
4656 rc = mdt_device_sync(&env, mdt);
4658 case OBD_IOC_SET_READONLY:
4659 rc = dt->dd_ops->dt_sync(&env, dt);
4660 dt->dd_ops->dt_ro(&env, dt);
4662 case OBD_IOC_ABORT_RECOVERY:
4663 CERROR("Aborting recovery for device %s\n", obd->obd_name);
4664 target_stop_recovery_thread(obd);
4668 CERROR("Not supported cmd = %d for device %s\n",
4669 cmd, obd->obd_name);
4677 int mdt_postrecov(const struct lu_env *env, struct mdt_device *mdt)
4679 struct lu_device *ld = md2lu_dev(mdt->mdt_child);
4680 struct obd_device *obd = mdt->mdt_md_dev.md_lu_dev.ld_obd;
4683 /* if some clients didn't participate in recovery then we can possibly
4684 * lost sequence. Now we should increase sequence for safe value */
4685 lost = obd->obd_max_recoverable_clients - obd->obd_connected_clients;
4686 mdt_seq_adjust(env, mdt, lost);
4688 rc = ld->ld_ops->ldo_recovery_complete(env, ld);
4692 int mdt_obd_postrecov(struct obd_device *obd)
4697 rc = lu_env_init(&env, NULL, LCT_MD_THREAD);
4700 rc = mdt_postrecov(&env, mdt_dev(obd->obd_lu_dev));
4705 static struct obd_ops mdt_obd_device_ops = {
4706 .o_owner = THIS_MODULE,
4707 .o_connect = mdt_obd_connect,
4708 .o_reconnect = mdt_obd_reconnect,
4709 .o_disconnect = mdt_obd_disconnect,
4710 .o_init_export = mdt_init_export,
4711 .o_destroy_export = mdt_destroy_export,
4712 .o_iocontrol = mdt_iocontrol,
4713 .o_postrecov = mdt_obd_postrecov,
4714 .o_notify = mdt_obd_notify
4717 static struct lu_device* mdt_device_fini(const struct lu_env *env,
4718 struct lu_device *d)
4720 struct mdt_device *m = mdt_dev(d);
4727 static struct lu_device *mdt_device_free(const struct lu_env *env,
4728 struct lu_device *d)
4730 struct mdt_device *m = mdt_dev(d);
4737 static struct lu_device *mdt_device_alloc(const struct lu_env *env,
4738 struct lu_device_type *t,
4739 struct lustre_cfg *cfg)
4741 struct lu_device *l;
4742 struct mdt_device *m;
4748 l = &m->mdt_md_dev.md_lu_dev;
4749 rc = mdt_init0(env, m, t, cfg);
4755 md_upcall_init(&m->mdt_md_dev, mdt_upcall);
4757 l = ERR_PTR(-ENOMEM);
4761 /* context key constructor/destructor: mdt_key_init, mdt_key_fini */
4762 LU_KEY_INIT_FINI(mdt, struct mdt_thread_info);
4764 /* context key: mdt_thread_key */
4765 LU_CONTEXT_KEY_DEFINE(mdt, LCT_MD_THREAD);
4767 /* context key constructor/destructor: mdt_txn_key_init, mdt_txn_key_fini */
4768 LU_KEY_INIT_FINI(mdt_txn, struct mdt_txn_info);
4770 struct lu_context_key mdt_txn_key = {
4771 .lct_tags = LCT_TX_HANDLE,
4772 .lct_init = mdt_txn_key_init,
4773 .lct_fini = mdt_txn_key_fini
4776 struct md_ucred *mdt_ucred(const struct mdt_thread_info *info)
4778 return md_ucred(info->mti_env);
4781 /* type constructor/destructor: mdt_type_init, mdt_type_fini */
4782 LU_TYPE_INIT_FINI(mdt, &mdt_thread_key, &mdt_txn_key);
4784 static struct lu_device_type_operations mdt_device_type_ops = {
4785 .ldto_init = mdt_type_init,
4786 .ldto_fini = mdt_type_fini,
4788 .ldto_device_alloc = mdt_device_alloc,
4789 .ldto_device_free = mdt_device_free,
4790 .ldto_device_fini = mdt_device_fini
4793 static struct lu_device_type mdt_device_type = {
4794 .ldt_tags = LU_DEVICE_MD,
4795 .ldt_name = LUSTRE_MDT_NAME,
4796 .ldt_ops = &mdt_device_type_ops,
4797 .ldt_ctx_tags = LCT_MD_THREAD
4800 static int __init mdt_mod_init(void)
4802 struct lprocfs_static_vars lvars;
4805 mdt_num_threads = MDT_NUM_THREADS;
4806 lprocfs_mdt_init_vars(&lvars);
4807 rc = class_register_type(&mdt_obd_device_ops, NULL,
4808 lvars.module_vars, LUSTRE_MDT_NAME,
4814 static void __exit mdt_mod_exit(void)
4816 class_unregister_type(LUSTRE_MDT_NAME);
4820 #define DEF_HNDL(prefix, base, suffix, flags, opc, fn, fmt) \
4821 [prefix ## _ ## opc - prefix ## _ ## base] = { \
4823 .mh_fail_id = OBD_FAIL_ ## prefix ## _ ## opc ## suffix, \
4824 .mh_opc = prefix ## _ ## opc, \
4825 .mh_flags = flags, \
4830 #define DEF_MDT_HNDL(flags, name, fn, fmt) \
4831 DEF_HNDL(MDS, GETATTR, _NET, flags, name, fn, fmt)
4833 #define DEF_SEQ_HNDL(flags, name, fn, fmt) \
4834 DEF_HNDL(SEQ, QUERY, _NET, flags, name, fn, fmt)
4836 #define DEF_FLD_HNDL(flags, name, fn, fmt) \
4837 DEF_HNDL(FLD, QUERY, _NET, flags, name, fn, fmt)
4839 * Request with a format known in advance
4841 #define DEF_MDT_HNDL_F(flags, name, fn) \
4842 DEF_HNDL(MDS, GETATTR, _NET, flags, name, fn, &RQF_MDS_ ## name)
4844 #define DEF_SEQ_HNDL_F(flags, name, fn) \
4845 DEF_HNDL(SEQ, QUERY, _NET, flags, name, fn, &RQF_SEQ_ ## name)
4847 #define DEF_FLD_HNDL_F(flags, name, fn) \
4848 DEF_HNDL(FLD, QUERY, _NET, flags, name, fn, &RQF_FLD_ ## name)
4850 * Request with a format we do not yet know
4852 #define DEF_MDT_HNDL_0(flags, name, fn) \
4853 DEF_HNDL(MDS, GETATTR, _NET, flags, name, fn, NULL)
4855 static struct mdt_handler mdt_mds_ops[] = {
4856 DEF_MDT_HNDL_F(0, CONNECT, mdt_connect),
4857 DEF_MDT_HNDL_F(0, DISCONNECT, mdt_disconnect),
4858 DEF_MDT_HNDL_F(0, SET_INFO, mdt_set_info),
4859 DEF_MDT_HNDL_F(0 |HABEO_REFERO, GETSTATUS, mdt_getstatus),
4860 DEF_MDT_HNDL_F(HABEO_CORPUS, GETATTR, mdt_getattr),
4861 DEF_MDT_HNDL_F(HABEO_CORPUS|HABEO_REFERO, GETATTR_NAME, mdt_getattr_name),
4862 DEF_MDT_HNDL_F(HABEO_CORPUS, GETXATTR, mdt_getxattr),
4863 DEF_MDT_HNDL_F(0 |HABEO_REFERO, STATFS, mdt_statfs),
4864 DEF_MDT_HNDL_F(0 |MUTABOR, REINT, mdt_reint),
4865 DEF_MDT_HNDL_F(HABEO_CORPUS, CLOSE, mdt_close),
4866 DEF_MDT_HNDL_F(HABEO_CORPUS, DONE_WRITING, mdt_done_writing),
4867 DEF_MDT_HNDL_F(0 |HABEO_REFERO, PIN, mdt_pin),
4868 DEF_MDT_HNDL_0(0, SYNC, mdt_sync),
4869 DEF_MDT_HNDL_F(HABEO_CORPUS|HABEO_REFERO, IS_SUBDIR, mdt_is_subdir),
4870 DEF_MDT_HNDL_F(0, QUOTACHECK, mdt_quotacheck_handle),
4871 DEF_MDT_HNDL_F(0, QUOTACTL, mdt_quotactl_handle)
4874 #define DEF_OBD_HNDL(flags, name, fn) \
4875 DEF_HNDL(OBD, PING, _NET, flags, name, fn, NULL)
4878 static struct mdt_handler mdt_obd_ops[] = {
4879 DEF_OBD_HNDL(0, PING, mdt_obd_ping),
4880 DEF_OBD_HNDL(0, LOG_CANCEL, mdt_obd_log_cancel),
4881 DEF_OBD_HNDL(0, QC_CALLBACK, mdt_obd_qc_callback)
4884 #define DEF_DLM_HNDL_0(flags, name, fn) \
4885 DEF_HNDL(LDLM, ENQUEUE, , flags, name, fn, NULL)
4886 #define DEF_DLM_HNDL_F(flags, name, fn) \
4887 DEF_HNDL(LDLM, ENQUEUE, , flags, name, fn, &RQF_LDLM_ ## name)
4889 static struct mdt_handler mdt_dlm_ops[] = {
4890 DEF_DLM_HNDL_F(HABEO_CLAVIS, ENQUEUE, mdt_enqueue),
4891 DEF_DLM_HNDL_0(HABEO_CLAVIS, CONVERT, mdt_convert),
4892 DEF_DLM_HNDL_0(0, BL_CALLBACK, mdt_bl_callback),
4893 DEF_DLM_HNDL_0(0, CP_CALLBACK, mdt_cp_callback)
4896 static struct mdt_handler mdt_llog_ops[] = {
4899 #define DEF_SEC_CTX_HNDL(name, fn) \
4900 DEF_HNDL(SEC_CTX, INIT, _NET, 0, name, fn, NULL)
4902 static struct mdt_handler mdt_sec_ctx_ops[] = {
4903 DEF_SEC_CTX_HNDL(INIT, mdt_sec_ctx_handle),
4904 DEF_SEC_CTX_HNDL(INIT_CONT, mdt_sec_ctx_handle),
4905 DEF_SEC_CTX_HNDL(FINI, mdt_sec_ctx_handle)
4908 static struct mdt_opc_slice mdt_regular_handlers[] = {
4910 .mos_opc_start = MDS_GETATTR,
4911 .mos_opc_end = MDS_LAST_OPC,
4912 .mos_hs = mdt_mds_ops
4915 .mos_opc_start = OBD_PING,
4916 .mos_opc_end = OBD_LAST_OPC,
4917 .mos_hs = mdt_obd_ops
4920 .mos_opc_start = LDLM_ENQUEUE,
4921 .mos_opc_end = LDLM_LAST_OPC,
4922 .mos_hs = mdt_dlm_ops
4925 .mos_opc_start = LLOG_ORIGIN_HANDLE_CREATE,
4926 .mos_opc_end = LLOG_LAST_OPC,
4927 .mos_hs = mdt_llog_ops
4930 .mos_opc_start = SEC_CTX_INIT,
4931 .mos_opc_end = SEC_LAST_OPC,
4932 .mos_hs = mdt_sec_ctx_ops
4939 static struct mdt_handler mdt_readpage_ops[] = {
4940 DEF_MDT_HNDL_F(0, CONNECT, mdt_connect),
4941 DEF_MDT_HNDL_F(HABEO_CORPUS|HABEO_REFERO, READPAGE, mdt_readpage),
4942 #ifdef HAVE_SPLIT_SUPPORT
4943 DEF_MDT_HNDL_F(HABEO_CORPUS|HABEO_REFERO, WRITEPAGE, mdt_writepage),
4947 * XXX: this is ugly and should be fixed one day, see mdc_close() for
4948 * detailed comments. --umka
4950 DEF_MDT_HNDL_F(HABEO_CORPUS, CLOSE, mdt_close),
4951 DEF_MDT_HNDL_F(HABEO_CORPUS, DONE_WRITING, mdt_done_writing),
4954 static struct mdt_opc_slice mdt_readpage_handlers[] = {
4956 .mos_opc_start = MDS_GETATTR,
4957 .mos_opc_end = MDS_LAST_OPC,
4958 .mos_hs = mdt_readpage_ops
4965 static struct mdt_handler mdt_xmds_ops[] = {
4966 DEF_MDT_HNDL_F(0, CONNECT, mdt_connect),
4967 DEF_MDT_HNDL_F(HABEO_CORPUS , GETATTR, mdt_getattr),
4968 DEF_MDT_HNDL_F(0 | MUTABOR , REINT, mdt_reint),
4969 DEF_MDT_HNDL_F(HABEO_CORPUS|HABEO_REFERO, IS_SUBDIR, mdt_is_subdir),
4972 static struct mdt_opc_slice mdt_xmds_handlers[] = {
4974 .mos_opc_start = MDS_GETATTR,
4975 .mos_opc_end = MDS_LAST_OPC,
4976 .mos_hs = mdt_xmds_ops
4979 .mos_opc_start = OBD_PING,
4980 .mos_opc_end = OBD_LAST_OPC,
4981 .mos_hs = mdt_obd_ops
4984 .mos_opc_start = SEC_CTX_INIT,
4985 .mos_opc_end = SEC_LAST_OPC,
4986 .mos_hs = mdt_sec_ctx_ops
4993 static struct mdt_handler mdt_seq_ops[] = {
4994 DEF_SEQ_HNDL_F(0, QUERY, (int (*)(struct mdt_thread_info *))seq_query)
4997 static struct mdt_opc_slice mdt_seq_handlers[] = {
4999 .mos_opc_start = SEQ_QUERY,
5000 .mos_opc_end = SEQ_LAST_OPC,
5001 .mos_hs = mdt_seq_ops
5008 static struct mdt_handler mdt_fld_ops[] = {
5009 DEF_FLD_HNDL_F(0, QUERY, (int (*)(struct mdt_thread_info *))fld_query)
5012 static struct mdt_opc_slice mdt_fld_handlers[] = {
5014 .mos_opc_start = FLD_QUERY,
5015 .mos_opc_end = FLD_LAST_OPC,
5016 .mos_hs = mdt_fld_ops
5023 MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");
5024 MODULE_DESCRIPTION("Lustre Meta-data Target ("LUSTRE_MDT_NAME")");
5025 MODULE_LICENSE("GPL");
5027 CFS_MODULE_PARM(mdt_num_threads, "ul", ulong, 0444,
5028 "number of mdt service threads to start");
5030 cfs_module(mdt, "0.2.0", mdt_mod_init, mdt_mod_exit);