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 #ifdef HAVE_QUOTA_SUPPORT
71 # include <lustre_quota.h>
73 #include <lustre_acl.h>
74 #include <lustre_param.h>
75 #include <lustre_fsfilt.h>
77 mdl_mode_t mdt_mdl_lock_modes[] = {
78 [LCK_MINMODE] = MDL_MINMODE,
85 [LCK_GROUP] = MDL_GROUP
88 ldlm_mode_t mdt_dlm_lock_modes[] = {
89 [MDL_MINMODE] = LCK_MINMODE,
96 [MDL_GROUP] = LCK_GROUP
100 * Initialized in mdt_mod_init().
102 unsigned long mdt_num_threads;
104 /* ptlrpc request handler for MDT. All handlers are
105 * grouped into several slices - struct mdt_opc_slice,
106 * and stored in an array - mdt_handlers[].
109 /* The name of this handler. */
111 /* Fail id for this handler, checked at the beginning of this handler*/
113 /* Operation code for this handler */
115 /* flags are listed in enum mdt_handler_flags below. */
117 /* The actual handler function to execute. */
118 int (*mh_act)(struct mdt_thread_info *info);
119 /* Request format for this request. */
120 const struct req_format *mh_fmt;
123 enum mdt_handler_flags {
125 * struct mdt_body is passed in the incoming message, and object
126 * identified by this fid exists on disk.
128 * "habeo corpus" == "I have a body"
130 HABEO_CORPUS = (1 << 0),
132 * struct ldlm_request is passed in the incoming message.
134 * "habeo clavis" == "I have a key"
136 HABEO_CLAVIS = (1 << 1),
138 * this request has fixed reply format, so that reply message can be
139 * packed by generic code.
141 * "habeo refero" == "I have a reply"
143 HABEO_REFERO = (1 << 2),
145 * this request will modify something, so check whether the filesystem
146 * is readonly or not, then return -EROFS to client asap if necessary.
148 * "mutabor" == "I shall modify"
153 struct mdt_opc_slice {
156 struct mdt_handler *mos_hs;
159 static struct mdt_opc_slice mdt_regular_handlers[];
160 static struct mdt_opc_slice mdt_readpage_handlers[];
161 static struct mdt_opc_slice mdt_xmds_handlers[];
162 static struct mdt_opc_slice mdt_seq_handlers[];
163 static struct mdt_opc_slice mdt_fld_handlers[];
165 static struct mdt_device *mdt_dev(struct lu_device *d);
166 static int mdt_regular_handle(struct ptlrpc_request *req);
167 static int mdt_unpack_req_pack_rep(struct mdt_thread_info *info, __u32 flags);
169 static const struct lu_object_operations mdt_obj_ops;
171 int mdt_get_disposition(struct ldlm_reply *rep, int flag)
175 return (rep->lock_policy_res1 & flag);
178 void mdt_clear_disposition(struct mdt_thread_info *info,
179 struct ldlm_reply *rep, int flag)
182 info->mti_opdata &= ~flag;
184 rep->lock_policy_res1 &= ~flag;
187 void mdt_set_disposition(struct mdt_thread_info *info,
188 struct ldlm_reply *rep, int flag)
191 info->mti_opdata |= flag;
193 rep->lock_policy_res1 |= flag;
196 void mdt_lock_reg_init(struct mdt_lock_handle *lh, ldlm_mode_t lm)
198 lh->mlh_pdo_hash = 0;
199 lh->mlh_reg_mode = lm;
200 lh->mlh_type = MDT_REG_LOCK;
203 void mdt_lock_pdo_init(struct mdt_lock_handle *lh, ldlm_mode_t lm,
204 const char *name, int namelen)
206 lh->mlh_reg_mode = lm;
207 lh->mlh_type = MDT_PDO_LOCK;
210 LASSERT(namelen > 0);
211 lh->mlh_pdo_hash = full_name_hash(name, namelen);
213 LASSERT(namelen == 0);
214 lh->mlh_pdo_hash = 0ull;
218 static void mdt_lock_pdo_mode(struct mdt_thread_info *info, struct mdt_object *o,
219 struct mdt_lock_handle *lh)
225 * Any dir access needs couple of locks:
227 * 1) on part of dir we gonna take lookup/modify;
229 * 2) on whole dir to protect it from concurrent splitting and/or to
230 * flush client's cache for readdir().
232 * so, for a given mode and object this routine decides what lock mode
233 * to use for lock #2:
235 * 1) if caller's gonna lookup in dir then we need to protect dir from
236 * being splitted only - LCK_CR
238 * 2) if caller's gonna modify dir then we need to protect dir from
239 * being splitted and to flush cache - LCK_CW
241 * 3) if caller's gonna modify dir and that dir seems ready for
242 * splitting then we need to protect it from any type of access
243 * (lookup/modify/split) - LCK_EX --bzzz
246 LASSERT(lh->mlh_reg_mode != LCK_MINMODE);
247 LASSERT(lh->mlh_pdo_mode == LCK_MINMODE);
250 * Ask underlaying level its opinion about preferable PDO lock mode
251 * having access type passed as regular lock mode:
253 * - MDL_MINMODE means that lower layer does not want to specify lock
256 * - MDL_NL means that no PDO lock should be taken. This is used in some
257 * cases. Say, for non-splittable directories no need to use PDO locks
260 mode = mdo_lock_mode(info->mti_env, mdt_object_child(o),
261 mdt_dlm_mode2mdl_mode(lh->mlh_reg_mode));
263 if (mode != MDL_MINMODE) {
264 lh->mlh_pdo_mode = mdt_mdl_mode2dlm_mode(mode);
267 * Lower layer does not want to specify locking mode. We do it
268 * our selves. No special protection is needed, just flush
269 * client's cache on modification and allow concurrent
272 switch (lh->mlh_reg_mode) {
274 lh->mlh_pdo_mode = LCK_EX;
277 lh->mlh_pdo_mode = LCK_CR;
280 lh->mlh_pdo_mode = LCK_CW;
283 CERROR("Not expected lock type (0x%x)\n",
284 (int)lh->mlh_reg_mode);
289 LASSERT(lh->mlh_pdo_mode != LCK_MINMODE);
293 static int mdt_getstatus(struct mdt_thread_info *info)
295 struct mdt_device *mdt = info->mti_mdt;
296 struct md_device *next = mdt->mdt_child;
297 struct mdt_body *repbody;
302 rc = mdt_check_ucred(info);
304 RETURN(err_serious(rc));
306 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_GETSTATUS_PACK))
307 RETURN(err_serious(-ENOMEM));
309 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
310 rc = next->md_ops->mdo_root_get(info->mti_env, next, &repbody->fid1);
314 repbody->valid |= OBD_MD_FLID;
316 if (mdt->mdt_opts.mo_mds_capa &&
317 info->mti_exp->exp_connect_flags & OBD_CONNECT_MDS_CAPA) {
318 struct mdt_object *root;
319 struct lustre_capa *capa;
321 root = mdt_object_find(info->mti_env, mdt, &repbody->fid1);
323 RETURN(PTR_ERR(root));
325 capa = req_capsule_server_get(info->mti_pill, &RMF_CAPA1);
327 capa->lc_opc = CAPA_OPC_MDS_DEFAULT;
328 rc = mo_capa_get(info->mti_env, mdt_object_child(root), capa,
330 mdt_object_put(info->mti_env, root);
332 repbody->valid |= OBD_MD_FLMDSCAPA;
338 static int mdt_statfs(struct mdt_thread_info *info)
340 struct md_device *next = info->mti_mdt->mdt_child;
341 struct ptlrpc_service *svc;
342 struct obd_statfs *osfs;
347 svc = info->mti_pill->rc_req->rq_rqbd->rqbd_service;
349 /* This will trigger a watchdog timeout */
350 OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_STATFS_LCW_SLEEP,
351 (MDT_SERVICE_WATCHDOG_FACTOR *
352 at_get(&svc->srv_at_estimate) / 1000) + 1);
354 rc = mdt_check_ucred(info);
356 RETURN(err_serious(rc));
358 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_STATFS_PACK)) {
359 rc = err_serious(-ENOMEM);
361 osfs = req_capsule_server_get(info->mti_pill, &RMF_OBD_STATFS);
362 rc = next->md_ops->mdo_statfs(info->mti_env, next,
364 statfs_pack(osfs, &info->mti_u.ksfs);
369 void mdt_pack_size2body(struct mdt_thread_info *info, struct mdt_object *o)
372 struct lu_attr *attr = &info->mti_attr.ma_attr;
374 b = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
376 /* Check if Size-on-MDS is enabled. */
377 if ((mdt_conn_flags(info) & OBD_CONNECT_SOM) &&
378 S_ISREG(attr->la_mode) && mdt_sizeonmds_enabled(o)) {
379 b->valid |= (OBD_MD_FLSIZE | OBD_MD_FLBLOCKS);
380 b->size = attr->la_size;
381 b->blocks = attr->la_blocks;
385 void mdt_pack_attr2body(struct mdt_thread_info *info, struct mdt_body *b,
386 const struct lu_attr *attr, const struct lu_fid *fid)
388 /*XXX should pack the reply body according to lu_valid*/
389 b->valid |= OBD_MD_FLCTIME | OBD_MD_FLUID |
390 OBD_MD_FLGID | OBD_MD_FLTYPE |
391 OBD_MD_FLMODE | OBD_MD_FLNLINK | OBD_MD_FLFLAGS |
392 OBD_MD_FLATIME | OBD_MD_FLMTIME ;
394 if (!S_ISREG(attr->la_mode))
395 b->valid |= OBD_MD_FLSIZE | OBD_MD_FLBLOCKS | OBD_MD_FLRDEV;
397 b->atime = attr->la_atime;
398 b->mtime = attr->la_mtime;
399 b->ctime = attr->la_ctime;
400 b->mode = attr->la_mode;
401 b->size = attr->la_size;
402 b->blocks = attr->la_blocks;
403 b->uid = attr->la_uid;
404 b->gid = attr->la_gid;
405 b->flags = attr->la_flags;
406 b->nlink = attr->la_nlink;
407 b->rdev = attr->la_rdev;
411 b->valid |= OBD_MD_FLID;
413 /* FIXME: these should be fixed when new igif ready.*/
414 b->ino = fid_oid(fid); /* 1.6 compatibility */
415 b->generation = fid_ver(fid); /* 1.6 compatibility */
416 b->valid |= OBD_MD_FLGENER; /* 1.6 compatibility */
418 CDEBUG(D_INODE, DFID": nlink=%d, mode=%o, size="LPU64"\n",
419 PFID(fid), b->nlink, b->mode, b->size);
423 mdt_body_reverse_idmap(info, b);
426 static inline int mdt_body_has_lov(const struct lu_attr *la,
427 const struct mdt_body *body)
429 return ((S_ISREG(la->la_mode) && (body->valid & OBD_MD_FLEASIZE)) ||
430 (S_ISDIR(la->la_mode) && (body->valid & OBD_MD_FLDIREA )) );
433 static int mdt_getattr_internal(struct mdt_thread_info *info,
434 struct mdt_object *o)
436 struct md_object *next = mdt_object_child(o);
437 const struct mdt_body *reqbody = info->mti_body;
438 struct ptlrpc_request *req = mdt_info_req(info);
439 struct md_attr *ma = &info->mti_attr;
440 struct lu_attr *la = &ma->ma_attr;
441 struct req_capsule *pill = info->mti_pill;
442 const struct lu_env *env = info->mti_env;
443 struct mdt_body *repbody;
444 struct lu_buf *buffer = &info->mti_buf;
448 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_GETATTR_PACK))
449 RETURN(err_serious(-ENOMEM));
451 repbody = req_capsule_server_get(pill, &RMF_MDT_BODY);
455 rc = mdt_object_exists(o);
457 /* This object is located on remote node.*/
458 repbody->fid1 = *mdt_object_fid(o);
459 repbody->valid = OBD_MD_FLID | OBD_MD_MDS;
463 buffer->lb_buf = req_capsule_server_get(pill, &RMF_MDT_MD);
464 buffer->lb_len = req_capsule_get_size(pill, &RMF_MDT_MD, RCL_SERVER);
466 /* If it is dir object and client require MEA, then we got MEA */
467 if (S_ISDIR(lu_object_attr(&next->mo_lu)) &&
468 reqbody->valid & OBD_MD_MEA) {
469 /* Assumption: MDT_MD size is enough for lmv size. */
470 ma->ma_lmv = buffer->lb_buf;
471 ma->ma_lmv_size = buffer->lb_len;
472 ma->ma_need = MA_LMV | MA_INODE;
474 ma->ma_lmm = buffer->lb_buf;
475 ma->ma_lmm_size = buffer->lb_len;
476 ma->ma_need = MA_LOV | MA_INODE;
479 if (S_ISDIR(lu_object_attr(&next->mo_lu)) &&
480 reqbody->valid & OBD_MD_FLDIREA &&
481 lustre_msg_get_opc(req->rq_reqmsg) == MDS_GETATTR) {
482 /* get default stripe info for this dir. */
483 ma->ma_need |= MA_LOV_DEF;
485 rc = mo_attr_get(env, next, ma);
487 CERROR("getattr error for "DFID": %d\n",
488 PFID(mdt_object_fid(o)), rc);
492 if (likely(ma->ma_valid & MA_INODE))
493 mdt_pack_attr2body(info, repbody, la, mdt_object_fid(o));
497 if (mdt_body_has_lov(la, reqbody)) {
498 if (ma->ma_valid & MA_LOV) {
499 LASSERT(ma->ma_lmm_size);
500 mdt_dump_lmm(D_INFO, ma->ma_lmm);
501 repbody->eadatasize = ma->ma_lmm_size;
502 if (S_ISDIR(la->la_mode))
503 repbody->valid |= OBD_MD_FLDIREA;
505 repbody->valid |= OBD_MD_FLEASIZE;
507 if (ma->ma_valid & MA_LMV) {
508 LASSERT(S_ISDIR(la->la_mode));
509 repbody->eadatasize = ma->ma_lmv_size;
510 repbody->valid |= (OBD_MD_FLDIREA|OBD_MD_MEA);
512 if (!(ma->ma_valid & MA_LOV) && !(ma->ma_valid & MA_LMV)) {
513 repbody->valid |= OBD_MD_FLSIZE | OBD_MD_FLBLOCKS;
515 } else if (S_ISLNK(la->la_mode) &&
516 reqbody->valid & OBD_MD_LINKNAME) {
517 buffer->lb_buf = ma->ma_lmm;
518 buffer->lb_len = reqbody->eadatasize;
519 rc = mo_readlink(env, next, buffer);
520 if (unlikely(rc <= 0)) {
521 CERROR("readlink failed: %d\n", rc);
524 repbody->valid |= OBD_MD_LINKNAME;
525 repbody->eadatasize = rc;
527 ((char*)ma->ma_lmm)[rc - 1] = 0;
528 CDEBUG(D_INODE, "symlink dest %s, len = %d\n",
529 (char*)ma->ma_lmm, rc);
534 if (reqbody->valid & OBD_MD_FLMODEASIZE) {
535 repbody->max_cookiesize = info->mti_mdt->mdt_max_cookiesize;
536 repbody->max_mdsize = info->mti_mdt->mdt_max_mdsize;
537 repbody->valid |= OBD_MD_FLMODEASIZE;
538 CDEBUG(D_INODE, "I am going to change the MAX_MD_SIZE & "
539 "MAX_COOKIE to : %d:%d\n", repbody->max_mdsize,
540 repbody->max_cookiesize);
543 if (exp_connect_rmtclient(info->mti_exp) &&
544 reqbody->valid & OBD_MD_FLRMTPERM) {
545 void *buf = req_capsule_server_get(pill, &RMF_ACL);
547 /* mdt_getattr_lock only */
548 rc = mdt_pack_remote_perm(info, o, buf);
550 repbody->valid &= ~OBD_MD_FLRMTPERM;
551 repbody->aclsize = 0;
554 repbody->valid |= OBD_MD_FLRMTPERM;
555 repbody->aclsize = sizeof(struct mdt_remote_perm);
558 #ifdef CONFIG_FS_POSIX_ACL
559 else if ((req->rq_export->exp_connect_flags & OBD_CONNECT_ACL) &&
560 (reqbody->valid & OBD_MD_FLACL)) {
561 buffer->lb_buf = req_capsule_server_get(pill, &RMF_ACL);
562 buffer->lb_len = req_capsule_get_size(pill,
563 &RMF_ACL, RCL_SERVER);
564 if (buffer->lb_len > 0) {
565 rc = mo_xattr_get(env, next, buffer,
566 XATTR_NAME_ACL_ACCESS);
568 if (rc == -ENODATA) {
569 repbody->aclsize = 0;
570 repbody->valid |= OBD_MD_FLACL;
572 } else if (rc == -EOPNOTSUPP) {
575 CERROR("got acl size: %d\n", rc);
578 repbody->aclsize = rc;
579 repbody->valid |= OBD_MD_FLACL;
586 if (reqbody->valid & OBD_MD_FLMDSCAPA &&
587 info->mti_mdt->mdt_opts.mo_mds_capa &&
588 info->mti_exp->exp_connect_flags & OBD_CONNECT_MDS_CAPA) {
589 struct lustre_capa *capa;
591 capa = req_capsule_server_get(pill, &RMF_CAPA1);
593 capa->lc_opc = CAPA_OPC_MDS_DEFAULT;
594 rc = mo_capa_get(env, next, capa, 0);
597 repbody->valid |= OBD_MD_FLMDSCAPA;
602 static int mdt_renew_capa(struct mdt_thread_info *info)
604 struct mdt_object *obj = info->mti_object;
605 struct mdt_body *body;
606 struct lustre_capa *capa, *c;
610 /* if object doesn't exist, or server has disabled capability,
611 * return directly, client will find body->valid OBD_MD_FLOSSCAPA
614 if (!obj || !info->mti_mdt->mdt_opts.mo_oss_capa ||
615 !(info->mti_exp->exp_connect_flags & OBD_CONNECT_OSS_CAPA))
618 body = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
619 LASSERT(body != NULL);
621 c = req_capsule_client_get(info->mti_pill, &RMF_CAPA1);
624 capa = req_capsule_server_get(info->mti_pill, &RMF_CAPA2);
628 rc = mo_capa_get(info->mti_env, mdt_object_child(obj), capa, 1);
630 body->valid |= OBD_MD_FLOSSCAPA;
634 static int mdt_getattr(struct mdt_thread_info *info)
636 struct mdt_object *obj = info->mti_object;
637 struct req_capsule *pill = info->mti_pill;
638 struct mdt_body *reqbody;
639 struct mdt_body *repbody;
645 reqbody = req_capsule_client_get(pill, &RMF_MDT_BODY);
648 if (reqbody->valid & OBD_MD_FLOSSCAPA) {
649 rc = req_capsule_server_pack(pill);
651 RETURN(err_serious(rc));
652 rc = mdt_renew_capa(info);
653 GOTO(out_shrink, rc);
656 LASSERT(obj != NULL);
657 LASSERT(lu_object_assert_exists(&obj->mot_obj.mo_lu));
659 mode = lu_object_attr(&obj->mot_obj.mo_lu);
660 if (S_ISLNK(mode) && (reqbody->valid & OBD_MD_LINKNAME) &&
661 (reqbody->eadatasize > info->mti_mdt->mdt_max_mdsize))
662 md_size = reqbody->eadatasize;
664 md_size = info->mti_mdt->mdt_max_mdsize;
666 req_capsule_set_size(pill, &RMF_MDT_MD, RCL_SERVER, md_size);
668 rc = req_capsule_server_pack(pill);
669 if (unlikely(rc != 0))
670 RETURN(err_serious(rc));
672 repbody = req_capsule_server_get(pill, &RMF_MDT_BODY);
673 LASSERT(repbody != NULL);
674 repbody->eadatasize = 0;
675 repbody->aclsize = 0;
677 if (reqbody->valid & OBD_MD_FLRMTPERM)
678 rc = mdt_init_ucred(info, reqbody);
680 rc = mdt_check_ucred(info);
682 GOTO(out_shrink, rc);
684 info->mti_spec.sp_ck_split = !!(reqbody->valid & OBD_MD_FLCKSPLIT);
685 info->mti_cross_ref = !!(reqbody->valid & OBD_MD_FLCROSSREF);
688 * Don't check capability at all, because rename might getattr for
689 * remote obj, and at that time no capability is available.
691 mdt_set_capainfo(info, 1, &reqbody->fid1, BYPASS_CAPA);
692 rc = mdt_getattr_internal(info, obj);
693 if (reqbody->valid & OBD_MD_FLRMTPERM)
694 mdt_exit_ucred(info);
697 mdt_shrink_reply(info);
701 static int mdt_is_subdir(struct mdt_thread_info *info)
703 struct mdt_object *o = info->mti_object;
704 struct req_capsule *pill = info->mti_pill;
705 const struct mdt_body *body = info->mti_body;
706 struct mdt_body *repbody;
712 repbody = req_capsule_server_get(pill, &RMF_MDT_BODY);
715 * We save last checked parent fid to @repbody->fid1 for remote
718 LASSERT(fid_is_sane(&body->fid2));
719 LASSERT(mdt_object_exists(o) > 0);
720 rc = mdo_is_subdir(info->mti_env, mdt_object_child(o),
721 &body->fid2, &repbody->fid1);
722 if (rc == 0 || rc == -EREMOTE)
723 repbody->valid |= OBD_MD_FLID;
728 static int mdt_raw_lookup(struct mdt_thread_info *info,
729 struct mdt_object *parent,
730 const struct lu_name *lname,
731 struct ldlm_reply *ldlm_rep)
733 struct md_object *next = mdt_object_child(info->mti_object);
734 const struct mdt_body *reqbody = info->mti_body;
735 struct lu_fid *child_fid = &info->mti_tmp_fid1;
736 struct mdt_body *repbody;
740 if (reqbody->valid != OBD_MD_FLID)
743 LASSERT(!info->mti_cross_ref);
745 /* Only got the fid of this obj by name */
746 rc = mdo_lookup(info->mti_env, next, lname, child_fid,
749 /* XXX is raw_lookup possible as intent operation? */
752 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_NEG);
755 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_POS);
757 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
760 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
761 repbody->fid1 = *child_fid;
762 repbody->valid = OBD_MD_FLID;
768 * UPDATE lock should be taken against parent, and be release before exit;
769 * child_bits lock should be taken against child, and be returned back:
770 * (1)normal request should release the child lock;
771 * (2)intent request will grant the lock to client.
773 static int mdt_getattr_name_lock(struct mdt_thread_info *info,
774 struct mdt_lock_handle *lhc,
776 struct ldlm_reply *ldlm_rep)
778 struct ptlrpc_request *req = mdt_info_req(info);
779 struct mdt_body *reqbody = NULL;
780 struct mdt_object *parent = info->mti_object;
781 struct mdt_object *child;
782 struct md_object *next = mdt_object_child(parent);
783 struct lu_fid *child_fid = &info->mti_tmp_fid1;
784 struct lu_name *lname = NULL;
785 const char *name = NULL;
787 struct mdt_lock_handle *lhp;
788 struct ldlm_lock *lock;
789 struct ldlm_res_id *res_id;
795 is_resent = lustre_handle_is_used(&lhc->mlh_reg_lh);
796 LASSERT(ergo(is_resent,
797 lustre_msg_get_flags(req->rq_reqmsg) & MSG_RESENT));
799 LASSERT(parent != NULL);
800 name = req_capsule_client_get(info->mti_pill, &RMF_NAME);
802 RETURN(err_serious(-EFAULT));
804 namelen = req_capsule_get_size(info->mti_pill, &RMF_NAME,
806 if (!info->mti_cross_ref) {
808 * XXX: Check for "namelen == 0" is for getattr by fid
809 * (OBD_CONNECT_ATTRFID), otherwise do not allow empty name,
810 * that is the name must contain at least one character and
811 * the terminating '\0'
814 reqbody = req_capsule_client_get(info->mti_pill,
816 LASSERT(fid_is_sane(&reqbody->fid2));
819 CDEBUG(D_INODE, "getattr with lock for "DFID"/"DFID", "
821 PFID(mdt_object_fid(parent)), PFID(&reqbody->fid2),
824 lname = mdt_name(info->mti_env, (char *)name, namelen);
825 CDEBUG(D_INODE, "getattr with lock for "DFID"/%s, "
826 "ldlm_rep = %p\n", PFID(mdt_object_fid(parent)),
830 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_EXECD);
832 rc = mdt_object_exists(parent);
833 if (unlikely(rc == 0)) {
834 LU_OBJECT_DEBUG(D_WARNING, info->mti_env,
835 &parent->mot_obj.mo_lu,
836 "Parent doesn't exist!\n");
838 } else if (!info->mti_cross_ref) {
839 LASSERTF(rc > 0, "Parent "DFID" is on remote server\n",
840 PFID(mdt_object_fid(parent)));
843 rc = mdt_raw_lookup(info, parent, lname, ldlm_rep);
851 if (info->mti_cross_ref) {
852 /* Only getattr on the child. Parent is on another node. */
853 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_POS);
855 CDEBUG(D_INODE, "partial getattr_name child_fid = "DFID", "
856 "ldlm_rep=%p\n", PFID(mdt_object_fid(child)), ldlm_rep);
859 /* Do not take lock for resent case. */
860 lock = ldlm_handle2lock(&lhc->mlh_reg_lh);
861 LASSERTF(lock != NULL, "Invalid lock handle "LPX64"\n",
862 lhc->mlh_reg_lh.cookie);
863 LASSERT(fid_res_name_eq(mdt_object_fid(child),
864 &lock->l_resource->lr_name));
868 mdt_lock_handle_init(lhc);
869 mdt_lock_reg_init(lhc, LCK_PR);
872 * Object's name is on another MDS, no lookup lock is
873 * needed here but update is.
875 child_bits &= ~MDS_INODELOCK_LOOKUP;
876 child_bits |= MDS_INODELOCK_UPDATE;
878 rc = mdt_object_lock(info, child, lhc, child_bits,
882 /* Finally, we can get attr for child. */
883 mdt_set_capainfo(info, 0, mdt_object_fid(child),
885 rc = mdt_getattr_internal(info, child);
886 if (unlikely(rc != 0))
887 mdt_object_unlock(info, child, lhc, 1);
892 /* step 1: lock parent */
893 lhp = &info->mti_lh[MDT_LH_PARENT];
894 mdt_lock_pdo_init(lhp, LCK_PR, name, namelen);
895 rc = mdt_object_lock(info, parent, lhp, MDS_INODELOCK_UPDATE,
898 if (unlikely(rc != 0))
902 /* step 2: lookup child's fid by name */
903 rc = mdo_lookup(info->mti_env, next, lname, child_fid,
908 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_NEG);
909 GOTO(out_parent, rc);
911 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_POS);
913 *child_fid = reqbody->fid2;
914 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_POS);
918 *step 3: find the child object by fid & lock it.
919 * regardless if it is local or remote.
921 child = mdt_object_find(info->mti_env, info->mti_mdt, child_fid);
923 if (unlikely(IS_ERR(child)))
924 GOTO(out_parent, rc = PTR_ERR(child));
926 /* Do not take lock for resent case. */
927 lock = ldlm_handle2lock(&lhc->mlh_reg_lh);
928 LASSERTF(lock != NULL, "Invalid lock handle "LPX64"\n",
929 lhc->mlh_reg_lh.cookie);
931 res_id = &lock->l_resource->lr_name;
932 if (!fid_res_name_eq(mdt_object_fid(child),
933 &lock->l_resource->lr_name)) {
934 LASSERTF(fid_res_name_eq(mdt_object_fid(parent),
935 &lock->l_resource->lr_name),
936 "Lock res_id: %lu/%lu/%lu, Fid: "DFID".\n",
937 (unsigned long)res_id->name[0],
938 (unsigned long)res_id->name[1],
939 (unsigned long)res_id->name[2],
940 PFID(mdt_object_fid(parent)));
941 CWARN("Although resent, but still not get child lock"
942 "parent:"DFID" child:"DFID"\n",
943 PFID(mdt_object_fid(parent)),
944 PFID(mdt_object_fid(child)));
945 lustre_msg_clear_flags(req->rq_reqmsg, MSG_RESENT);
954 ma = &info->mti_attr;
956 mdt_lock_handle_init(lhc);
957 mdt_lock_reg_init(lhc, LCK_PR);
959 if (mdt_object_exists(child) == 0) {
960 LU_OBJECT_DEBUG(D_WARNING, info->mti_env,
961 &child->mot_obj.mo_lu,
962 "Object doesn't exist!\n");
963 GOTO(out_child, rc = -ESTALE);
967 ma->ma_need = MA_INODE;
968 rc = mo_attr_get(info->mti_env, next, ma);
969 if (unlikely(rc != 0))
972 /* If the file has not been changed for some time, we return
973 * not only a LOOKUP lock, but also an UPDATE lock and this
974 * might save us RPC on later STAT. For directories, it also
975 * let negative dentry starts working for this dir. */
976 if (ma->ma_valid & MA_INODE &&
977 ma->ma_attr.la_valid & LA_CTIME &&
978 info->mti_mdt->mdt_namespace->ns_ctime_age_limit +
979 ma->ma_attr.la_ctime < cfs_time_current_sec())
980 child_bits |= MDS_INODELOCK_UPDATE;
982 rc = mdt_object_lock(info, child, lhc, child_bits,
985 if (unlikely(rc != 0))
989 /* finally, we can get attr for child. */
990 mdt_set_capainfo(info, 1, child_fid, BYPASS_CAPA);
991 rc = mdt_getattr_internal(info, child);
992 if (unlikely(rc != 0)) {
993 mdt_object_unlock(info, child, lhc, 1);
995 lock = ldlm_handle2lock(&lhc->mlh_reg_lh);
997 struct mdt_body *repbody;
999 /* Debugging code. */
1000 res_id = &lock->l_resource->lr_name;
1001 LDLM_DEBUG(lock, "Returning lock to client\n");
1002 LASSERTF(fid_res_name_eq(mdt_object_fid(child),
1003 &lock->l_resource->lr_name),
1004 "Lock res_id: %lu/%lu/%lu, Fid: "DFID".\n",
1005 (unsigned long)res_id->name[0],
1006 (unsigned long)res_id->name[1],
1007 (unsigned long)res_id->name[2],
1008 PFID(mdt_object_fid(child)));
1010 * Pack Size-on-MDS inode attributes to the body if
1011 * update lock is given.
1013 repbody = req_capsule_server_get(info->mti_pill,
1015 if (lock->l_policy_data.l_inodebits.bits &
1016 MDS_INODELOCK_UPDATE)
1017 mdt_pack_size2body(info, child);
1018 LDLM_LOCK_PUT(lock);
1023 mdt_object_put(info->mti_env, child);
1025 mdt_object_unlock(info, parent, lhp, 1);
1029 /* normal handler: should release the child lock */
1030 static int mdt_getattr_name(struct mdt_thread_info *info)
1032 struct mdt_lock_handle *lhc = &info->mti_lh[MDT_LH_CHILD];
1033 struct mdt_body *reqbody;
1034 struct mdt_body *repbody;
1038 reqbody = req_capsule_client_get(info->mti_pill, &RMF_MDT_BODY);
1039 LASSERT(reqbody != NULL);
1040 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
1041 LASSERT(repbody != NULL);
1043 info->mti_spec.sp_ck_split = !!(reqbody->valid & OBD_MD_FLCKSPLIT);
1044 info->mti_cross_ref = !!(reqbody->valid & OBD_MD_FLCROSSREF);
1045 repbody->eadatasize = 0;
1046 repbody->aclsize = 0;
1048 rc = mdt_init_ucred(info, reqbody);
1050 GOTO(out_shrink, rc);
1052 rc = mdt_getattr_name_lock(info, lhc, MDS_INODELOCK_UPDATE, NULL);
1053 if (lustre_handle_is_used(&lhc->mlh_reg_lh)) {
1054 ldlm_lock_decref(&lhc->mlh_reg_lh, lhc->mlh_reg_mode);
1055 lhc->mlh_reg_lh.cookie = 0;
1057 mdt_exit_ucred(info);
1060 mdt_shrink_reply(info);
1064 static const struct lu_device_operations mdt_lu_ops;
1066 static int lu_device_is_mdt(struct lu_device *d)
1068 return ergo(d != NULL && d->ld_ops != NULL, d->ld_ops == &mdt_lu_ops);
1071 static int mdt_set_info(struct mdt_thread_info *info)
1073 struct ptlrpc_request *req = mdt_info_req(info);
1079 rc = req_capsule_server_pack(info->mti_pill);
1083 key = req_capsule_client_get(info->mti_pill, &RMF_SETINFO_KEY);
1085 DEBUG_REQ(D_HA, req, "no set_info key");
1089 keylen = req_capsule_get_size(info->mti_pill, &RMF_SETINFO_KEY,
1092 val = req_capsule_client_get(info->mti_pill, &RMF_SETINFO_VAL);
1094 DEBUG_REQ(D_HA, req, "no set_info val");
1098 if (!KEY_IS(KEY_READ_ONLY))
1102 lustre_msg_set_status(req->rq_repmsg, 0);
1104 spin_lock(&req->rq_export->exp_lock);
1106 req->rq_export->exp_connect_flags |= OBD_CONNECT_RDONLY;
1108 req->rq_export->exp_connect_flags &= ~OBD_CONNECT_RDONLY;
1109 spin_unlock(&req->rq_export->exp_lock);
1114 static int mdt_connect(struct mdt_thread_info *info)
1117 struct ptlrpc_request *req;
1119 req = mdt_info_req(info);
1120 rc = target_handle_connect(req);
1122 LASSERT(req->rq_export != NULL);
1123 info->mti_mdt = mdt_dev(req->rq_export->exp_obd->obd_lu_dev);
1124 rc = mdt_init_sec_level(info);
1126 rc = mdt_init_idmap(info);
1128 obd_disconnect(class_export_get(req->rq_export));
1130 rc = err_serious(rc);
1135 static int mdt_disconnect(struct mdt_thread_info *info)
1140 rc = target_handle_disconnect(mdt_info_req(info));
1142 rc = err_serious(rc);
1146 static int mdt_sendpage(struct mdt_thread_info *info,
1147 struct lu_rdpg *rdpg)
1149 struct ptlrpc_request *req = mdt_info_req(info);
1150 struct ptlrpc_bulk_desc *desc;
1151 struct l_wait_info *lwi = &info->mti_u.rdpg.mti_wait_info;
1159 desc = ptlrpc_prep_bulk_exp(req, rdpg->rp_npages, BULK_PUT_SOURCE,
1164 for (i = 0, tmpcount = rdpg->rp_count;
1165 i < rdpg->rp_npages; i++, tmpcount -= tmpsize) {
1166 tmpsize = min_t(int, tmpcount, CFS_PAGE_SIZE);
1167 ptlrpc_prep_bulk_page(desc, rdpg->rp_pages[i], 0, tmpsize);
1170 LASSERT(desc->bd_nob == rdpg->rp_count);
1171 rc = ptlrpc_start_bulk_transfer(desc);
1173 GOTO(free_desc, rc);
1175 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_SENDPAGE))
1176 GOTO(abort_bulk, rc = 0);
1178 timeout = (int) req->rq_deadline - cfs_time_current_sec();
1180 CERROR("Req deadline already passed %lu (now: %lu)\n",
1181 req->rq_deadline, cfs_time_current_sec());
1182 *lwi = LWI_TIMEOUT(cfs_time_seconds(max(timeout, 1)), NULL, NULL);
1183 rc = l_wait_event(desc->bd_waitq, !ptlrpc_server_bulk_active(desc), lwi);
1184 LASSERT (rc == 0 || rc == -ETIMEDOUT);
1187 if (desc->bd_success &&
1188 desc->bd_nob_transferred == rdpg->rp_count)
1189 GOTO(free_desc, rc);
1191 rc = -ETIMEDOUT; /* XXX should this be a different errno? */
1194 DEBUG_REQ(D_ERROR, req, "bulk failed: %s %d(%d), evicting %s@%s",
1195 (rc == -ETIMEDOUT) ? "timeout" : "network error",
1196 desc->bd_nob_transferred, rdpg->rp_count,
1197 req->rq_export->exp_client_uuid.uuid,
1198 req->rq_export->exp_connection->c_remote_uuid.uuid);
1200 class_fail_export(req->rq_export);
1204 ptlrpc_abort_bulk(desc);
1206 ptlrpc_free_bulk(desc);
1210 #ifdef HAVE_SPLIT_SUPPORT
1212 * Retrieve dir entry from the page and insert it to the slave object, actually,
1213 * this should be in osd layer, but since it will not in the final product, so
1214 * just do it here and do not define more moo api anymore for this.
1216 static int mdt_write_dir_page(struct mdt_thread_info *info, struct page *page,
1219 struct mdt_object *object = info->mti_object;
1220 struct lu_fid *lf = &info->mti_tmp_fid2;
1221 struct md_attr *ma = &info->mti_attr;
1222 struct lu_dirpage *dp;
1223 struct lu_dirent *ent;
1224 int rc = 0, offset = 0;
1227 /* Make sure we have at least one entry. */
1232 * Disable trans for this name insert, since it will include many trans
1235 info->mti_no_need_trans = 1;
1237 * When write_dir_page, no need update parent's ctime,
1238 * and no permission check for name_insert.
1240 ma->ma_attr.la_ctime = 0;
1241 ma->ma_attr.la_valid = LA_MODE;
1242 ma->ma_valid = MA_INODE;
1245 dp = page_address(page);
1246 offset = (int)((__u32)lu_dirent_start(dp) - (__u32)dp);
1248 for (ent = lu_dirent_start(dp); ent != NULL;
1249 ent = lu_dirent_next(ent)) {
1250 struct lu_name *lname;
1253 if (le16_to_cpu(ent->lde_namelen) == 0)
1256 fid_le_to_cpu(lf, &ent->lde_fid);
1257 if (le64_to_cpu(ent->lde_hash) & MAX_HASH_HIGHEST_BIT)
1258 ma->ma_attr.la_mode = S_IFDIR;
1260 ma->ma_attr.la_mode = 0;
1261 OBD_ALLOC(name, le16_to_cpu(ent->lde_namelen) + 1);
1263 GOTO(out, rc = -ENOMEM);
1265 memcpy(name, ent->lde_name, le16_to_cpu(ent->lde_namelen));
1266 lname = mdt_name(info->mti_env, name,
1267 le16_to_cpu(ent->lde_namelen));
1268 ma->ma_attr_flags |= (MDS_PERM_BYPASS | MDS_QUOTA_IGNORE);
1269 rc = mdo_name_insert(info->mti_env,
1270 md_object_next(&object->mot_obj),
1272 OBD_FREE(name, le16_to_cpu(ent->lde_namelen) + 1);
1274 CERROR("Can't insert %*.*s, rc %d\n",
1275 le16_to_cpu(ent->lde_namelen),
1276 le16_to_cpu(ent->lde_namelen),
1281 offset += lu_dirent_size(ent);
1291 static int mdt_bulk_timeout(void *data)
1295 CERROR("mdt bulk transfer timeout \n");
1300 static int mdt_writepage(struct mdt_thread_info *info)
1302 struct ptlrpc_request *req = mdt_info_req(info);
1303 struct mdt_body *reqbody;
1304 struct l_wait_info *lwi;
1305 struct ptlrpc_bulk_desc *desc;
1311 reqbody = req_capsule_client_get(info->mti_pill, &RMF_MDT_BODY);
1312 if (reqbody == NULL)
1313 RETURN(err_serious(-EFAULT));
1315 desc = ptlrpc_prep_bulk_exp(req, 1, BULK_GET_SINK, MDS_BULK_PORTAL);
1317 RETURN(err_serious(-ENOMEM));
1319 /* allocate the page for the desc */
1320 page = cfs_alloc_page(CFS_ALLOC_STD);
1322 GOTO(desc_cleanup, rc = -ENOMEM);
1324 CDEBUG(D_INFO, "Received page offset %d size %d \n",
1325 (int)reqbody->size, (int)reqbody->nlink);
1327 ptlrpc_prep_bulk_page(desc, page, (int)reqbody->size,
1328 (int)reqbody->nlink);
1331 * Check if client was evicted while we were doing i/o before touching
1336 GOTO(cleanup_page, rc = -ENOMEM);
1338 if (desc->bd_export->exp_failed)
1341 rc = ptlrpc_start_bulk_transfer (desc);
1343 *lwi = LWI_TIMEOUT_INTERVAL(obd_timeout * HZ / 4, HZ,
1344 mdt_bulk_timeout, desc);
1345 rc = l_wait_event(desc->bd_waitq, !ptlrpc_bulk_active(desc) ||
1346 desc->bd_export->exp_failed, lwi);
1347 LASSERT(rc == 0 || rc == -ETIMEDOUT);
1348 if (rc == -ETIMEDOUT) {
1349 DEBUG_REQ(D_ERROR, req, "timeout on bulk GET");
1350 ptlrpc_abort_bulk(desc);
1351 } else if (desc->bd_export->exp_failed) {
1352 DEBUG_REQ(D_ERROR, req, "Eviction on bulk GET");
1354 ptlrpc_abort_bulk(desc);
1355 } else if (!desc->bd_success ||
1356 desc->bd_nob_transferred != desc->bd_nob) {
1357 DEBUG_REQ(D_ERROR, req, "%s bulk GET %d(%d)",
1359 "truncated" : "network error on",
1360 desc->bd_nob_transferred, desc->bd_nob);
1361 /* XXX should this be a different errno? */
1365 DEBUG_REQ(D_ERROR, req, "ptlrpc_bulk_get failed: rc %d", rc);
1368 GOTO(cleanup_lwi, rc);
1369 rc = mdt_write_dir_page(info, page, reqbody->nlink);
1374 cfs_free_page(page);
1376 ptlrpc_free_bulk(desc);
1381 static int mdt_readpage(struct mdt_thread_info *info)
1383 struct mdt_object *object = info->mti_object;
1384 struct lu_rdpg *rdpg = &info->mti_u.rdpg.mti_rdpg;
1385 struct mdt_body *reqbody;
1386 struct mdt_body *repbody;
1391 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_READPAGE_PACK))
1392 RETURN(err_serious(-ENOMEM));
1394 reqbody = req_capsule_client_get(info->mti_pill, &RMF_MDT_BODY);
1395 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
1396 if (reqbody == NULL || repbody == NULL)
1397 RETURN(err_serious(-EFAULT));
1400 * prepare @rdpg before calling lower layers and transfer itself. Here
1401 * reqbody->size contains offset of where to start to read and
1402 * reqbody->nlink contains number bytes to read.
1404 rdpg->rp_hash = reqbody->size;
1405 if (rdpg->rp_hash != reqbody->size) {
1406 CERROR("Invalid hash: "LPX64" != "LPX64"\n",
1407 rdpg->rp_hash, reqbody->size);
1410 rdpg->rp_count = reqbody->nlink;
1411 rdpg->rp_npages = (rdpg->rp_count + CFS_PAGE_SIZE - 1)>>CFS_PAGE_SHIFT;
1412 OBD_ALLOC(rdpg->rp_pages, rdpg->rp_npages * sizeof rdpg->rp_pages[0]);
1413 if (rdpg->rp_pages == NULL)
1416 for (i = 0; i < rdpg->rp_npages; ++i) {
1417 rdpg->rp_pages[i] = cfs_alloc_page(CFS_ALLOC_STD);
1418 if (rdpg->rp_pages[i] == NULL)
1419 GOTO(free_rdpg, rc = -ENOMEM);
1422 /* call lower layers to fill allocated pages with directory data */
1423 rc = mo_readpage(info->mti_env, mdt_object_child(object), rdpg);
1425 GOTO(free_rdpg, rc);
1427 /* send pages to client */
1428 rc = mdt_sendpage(info, rdpg);
1433 for (i = 0; i < rdpg->rp_npages; i++)
1434 if (rdpg->rp_pages[i] != NULL)
1435 cfs_free_page(rdpg->rp_pages[i]);
1436 OBD_FREE(rdpg->rp_pages, rdpg->rp_npages * sizeof rdpg->rp_pages[0]);
1438 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_SENDPAGE))
1444 static int mdt_reint_internal(struct mdt_thread_info *info,
1445 struct mdt_lock_handle *lhc,
1448 struct req_capsule *pill = info->mti_pill;
1449 struct mdt_device *mdt = info->mti_mdt;
1450 struct mdt_body *repbody;
1455 if (req_capsule_has_field(pill, &RMF_MDT_MD, RCL_SERVER))
1456 req_capsule_set_size(pill, &RMF_MDT_MD, RCL_SERVER,
1457 mdt->mdt_max_mdsize);
1458 if (req_capsule_has_field(pill, &RMF_LOGCOOKIES, RCL_SERVER))
1459 req_capsule_set_size(pill, &RMF_LOGCOOKIES, RCL_SERVER,
1460 mdt->mdt_max_cookiesize);
1462 rc = req_capsule_server_pack(pill);
1464 CERROR("Can't pack response, rc %d\n", rc);
1465 RETURN(err_serious(rc));
1468 if (req_capsule_has_field(pill, &RMF_MDT_BODY, RCL_SERVER)) {
1469 repbody = req_capsule_server_get(pill, &RMF_MDT_BODY);
1471 repbody->eadatasize = 0;
1472 repbody->aclsize = 0;
1475 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_REINT_UNPACK))
1476 GOTO(out_shrink, rc = err_serious(-EFAULT));
1478 rc = mdt_reint_unpack(info, op);
1480 CERROR("Can't unpack reint, rc %d\n", rc);
1481 GOTO(out_shrink, rc = err_serious(rc));
1484 /* for replay no cookkie / lmm need, because client have this already */
1485 if (info->mti_spec.no_create == 1) {
1486 if (req_capsule_has_field(pill, &RMF_MDT_MD, RCL_SERVER))
1487 req_capsule_set_size(pill, &RMF_MDT_MD, RCL_SERVER, 0);
1489 if (req_capsule_has_field(pill, &RMF_LOGCOOKIES, RCL_SERVER))
1490 req_capsule_set_size(pill, &RMF_LOGCOOKIES, RCL_SERVER,
1494 rc = mdt_init_ucred_reint(info);
1496 GOTO(out_shrink, rc);
1498 rc = mdt_fix_attr_ucred(info, op);
1500 GOTO(out_ucred, rc = err_serious(rc));
1502 if (mdt_check_resent(info, mdt_reconstruct, lhc)) {
1503 rc = lustre_msg_get_status(mdt_info_req(info)->rq_repmsg);
1504 GOTO(out_ucred, rc);
1506 rc = mdt_reint_rec(info, lhc);
1509 mdt_exit_ucred(info);
1511 mdt_shrink_reply(info);
1515 static long mdt_reint_opcode(struct mdt_thread_info *info,
1516 const struct req_format **fmt)
1518 struct mdt_rec_reint *rec;
1521 opc = err_serious(-EFAULT);
1522 rec = req_capsule_client_get(info->mti_pill, &RMF_REC_REINT);
1524 opc = rec->rr_opcode;
1525 DEBUG_REQ(D_INODE, mdt_info_req(info), "reint opt = %ld", opc);
1526 if (opc < REINT_MAX && fmt[opc] != NULL)
1527 req_capsule_extend(info->mti_pill, fmt[opc]);
1529 CERROR("Unsupported opc: %ld\n", opc);
1530 opc = err_serious(opc);
1536 static int mdt_reint(struct mdt_thread_info *info)
1541 static const struct req_format *reint_fmts[REINT_MAX] = {
1542 [REINT_SETATTR] = &RQF_MDS_REINT_SETATTR,
1543 [REINT_CREATE] = &RQF_MDS_REINT_CREATE,
1544 [REINT_LINK] = &RQF_MDS_REINT_LINK,
1545 [REINT_UNLINK] = &RQF_MDS_REINT_UNLINK,
1546 [REINT_RENAME] = &RQF_MDS_REINT_RENAME,
1547 [REINT_OPEN] = &RQF_MDS_REINT_OPEN,
1548 [REINT_SETXATTR] = &RQF_MDS_REINT_SETXATTR
1553 opc = mdt_reint_opcode(info, reint_fmts);
1556 * No lock possible here from client to pass it to reint code
1559 rc = mdt_reint_internal(info, NULL, opc);
1564 info->mti_fail_id = OBD_FAIL_MDS_REINT_NET_REP;
1568 /* this should sync the whole device */
1569 static int mdt_device_sync(const struct lu_env *env, struct mdt_device *mdt)
1571 struct dt_device *dt = mdt->mdt_bottom;
1575 rc = dt->dd_ops->dt_sync(env, dt);
1579 /* this should sync this object */
1580 static int mdt_object_sync(struct mdt_thread_info *info)
1582 struct md_object *next;
1586 if (!mdt_object_exists(info->mti_object)) {
1587 CWARN("Non existing object "DFID"!\n",
1588 PFID(mdt_object_fid(info->mti_object)));
1591 next = mdt_object_child(info->mti_object);
1592 rc = mo_object_sync(info->mti_env, next);
1597 static int mdt_sync(struct mdt_thread_info *info)
1599 struct req_capsule *pill = info->mti_pill;
1600 struct mdt_body *body;
1604 /* The fid may be zero, so we req_capsule_set manually */
1605 req_capsule_set(pill, &RQF_MDS_SYNC);
1607 body = req_capsule_client_get(pill, &RMF_MDT_BODY);
1609 RETURN(err_serious(-EINVAL));
1611 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_SYNC_PACK))
1612 RETURN(err_serious(-ENOMEM));
1614 if (fid_seq(&body->fid1) == 0) {
1615 /* sync the whole device */
1616 rc = req_capsule_server_pack(pill);
1618 rc = mdt_device_sync(info->mti_env, info->mti_mdt);
1620 rc = err_serious(rc);
1622 /* sync an object */
1623 rc = mdt_unpack_req_pack_rep(info, HABEO_CORPUS|HABEO_REFERO);
1625 rc = mdt_object_sync(info);
1627 struct md_object *next;
1628 const struct lu_fid *fid;
1629 struct lu_attr *la = &info->mti_attr.ma_attr;
1631 next = mdt_object_child(info->mti_object);
1632 info->mti_attr.ma_need = MA_INODE;
1633 info->mti_attr.ma_valid = 0;
1634 rc = mo_attr_get(info->mti_env, next,
1637 body = req_capsule_server_get(pill,
1639 fid = mdt_object_fid(info->mti_object);
1640 mdt_pack_attr2body(info, body, la, fid);
1644 rc = err_serious(rc);
1649 #ifdef HAVE_QUOTA_SUPPORT
1650 static int mdt_quotacheck_handle(struct mdt_thread_info *info)
1652 struct obd_quotactl *oqctl;
1653 struct req_capsule *pill = info->mti_pill;
1654 struct obd_export *exp = info->mti_exp;
1655 struct md_device *next = info->mti_mdt->mdt_child;
1659 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_QUOTACHECK_NET))
1662 oqctl = req_capsule_client_get(pill, &RMF_OBD_QUOTACTL);
1666 /* remote client has no permission for quotacheck */
1667 if (unlikely(exp_connect_rmtclient(exp)))
1670 rc = req_capsule_server_pack(pill);
1674 rc = next->md_ops->mdo_quota.mqo_check(info->mti_env, next, exp,
1679 static int mdt_quotactl_handle(struct mdt_thread_info *info)
1681 struct obd_quotactl *oqctl, *repoqc;
1682 struct req_capsule *pill = info->mti_pill;
1683 struct obd_export *exp = info->mti_exp;
1684 struct md_device *next = info->mti_mdt->mdt_child;
1685 const struct md_quota_operations *mqo = &next->md_ops->mdo_quota;
1689 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_QUOTACTL_NET))
1692 oqctl = req_capsule_client_get(pill, &RMF_OBD_QUOTACTL);
1697 if (exp_connect_rmtclient(exp)) {
1698 struct ptlrpc_request *req = mdt_info_req(info);
1699 struct mdt_export_data *med = mdt_req2med(req);
1700 struct lustre_idmap_table *idmap = med->med_idmap;
1702 if (unlikely(oqctl->qc_cmd != Q_GETQUOTA &&
1703 oqctl->qc_cmd != Q_GETINFO))
1707 if (oqctl->qc_type == USRQUOTA)
1708 id = lustre_idmap_lookup_uid(NULL, idmap, 0,
1710 else if (oqctl->qc_type == GRPQUOTA)
1711 id = lustre_idmap_lookup_gid(NULL, idmap, 0,
1716 if (id == CFS_IDMAP_NOTFOUND) {
1717 CDEBUG(D_QUOTA, "no mapping for id %u\n",
1723 rc = req_capsule_server_pack(pill);
1727 repoqc = req_capsule_server_get(pill, &RMF_OBD_QUOTACTL);
1728 LASSERT(repoqc != NULL);
1730 switch (oqctl->qc_cmd) {
1732 rc = mqo->mqo_on(info->mti_env, next, oqctl->qc_type);
1735 rc = mqo->mqo_off(info->mti_env, next, oqctl->qc_type);
1738 rc = mqo->mqo_setinfo(info->mti_env, next, oqctl->qc_type, id,
1742 rc = mqo->mqo_getinfo(info->mti_env, next, oqctl->qc_type, id,
1746 rc = mqo->mqo_setquota(info->mti_env, next, oqctl->qc_type, id,
1750 rc = mqo->mqo_getquota(info->mti_env, next, oqctl->qc_type, id,
1754 rc = mqo->mqo_getoinfo(info->mti_env, next, oqctl->qc_type, id,
1758 rc = mqo->mqo_getoquota(info->mti_env, next, oqctl->qc_type, id,
1761 case LUSTRE_Q_INVALIDATE:
1762 rc = mqo->mqo_invalidate(info->mti_env, next, oqctl->qc_type);
1764 case LUSTRE_Q_FINVALIDATE:
1765 rc = mqo->mqo_finvalidate(info->mti_env, next, oqctl->qc_type);
1768 CERROR("unsupported mdt_quotactl command: %d\n",
1779 * OBD PING and other handlers.
1781 static int mdt_obd_ping(struct mdt_thread_info *info)
1786 req_capsule_set(info->mti_pill, &RQF_OBD_PING);
1788 rc = target_handle_ping(mdt_info_req(info));
1790 rc = err_serious(rc);
1794 static int mdt_obd_log_cancel(struct mdt_thread_info *info)
1796 return err_serious(-EOPNOTSUPP);
1799 static int mdt_obd_qc_callback(struct mdt_thread_info *info)
1801 return err_serious(-EOPNOTSUPP);
1808 static struct ldlm_callback_suite cbs = {
1809 .lcs_completion = ldlm_server_completion_ast,
1810 .lcs_blocking = ldlm_server_blocking_ast,
1814 static int mdt_enqueue(struct mdt_thread_info *info)
1816 struct ptlrpc_request *req;
1821 * info->mti_dlm_req already contains swapped and (if necessary)
1822 * converted dlm request.
1824 LASSERT(info->mti_dlm_req != NULL);
1826 req = mdt_info_req(info);
1829 * Lock without inodebits makes no sense and will oops later in
1830 * ldlm. Let's check it now to see if we have wrong lock from client or
1831 * bits get corrupted somewhere in mdt_intent_policy().
1833 req_bits = info->mti_dlm_req->lock_desc.l_policy_data.l_inodebits.bits;
1834 /* This is disabled because we need to support liblustre flock.
1835 * LASSERT(req_bits != 0);
1838 rc = ldlm_handle_enqueue0(info->mti_mdt->mdt_namespace,
1839 req, info->mti_dlm_req, &cbs);
1840 info->mti_fail_id = OBD_FAIL_LDLM_REPLY;
1841 return rc ? err_serious(rc) : req->rq_status;
1844 static int mdt_convert(struct mdt_thread_info *info)
1847 struct ptlrpc_request *req;
1849 LASSERT(info->mti_dlm_req);
1850 req = mdt_info_req(info);
1851 rc = ldlm_handle_convert0(req, info->mti_dlm_req);
1852 return rc ? err_serious(rc) : req->rq_status;
1855 static int mdt_bl_callback(struct mdt_thread_info *info)
1857 CERROR("bl callbacks should not happen on MDS\n");
1859 return err_serious(-EOPNOTSUPP);
1862 static int mdt_cp_callback(struct mdt_thread_info *info)
1864 CERROR("cp callbacks should not happen on MDS\n");
1866 return err_serious(-EOPNOTSUPP);
1870 * sec context handlers
1872 static int mdt_sec_ctx_handle(struct mdt_thread_info *info)
1876 rc = mdt_handle_idmap(info);
1879 struct ptlrpc_request *req = mdt_info_req(info);
1882 opc = lustre_msg_get_opc(req->rq_reqmsg);
1883 if (opc == SEC_CTX_INIT || opc == SEC_CTX_INIT_CONT)
1884 sptlrpc_svc_ctx_invalidate(req);
1887 OBD_FAIL_TIMEOUT(OBD_FAIL_SEC_CTX_HDL_PAUSE, obd_fail_val);
1892 static struct mdt_object *mdt_obj(struct lu_object *o)
1894 LASSERT(lu_device_is_mdt(o->lo_dev));
1895 return container_of0(o, struct mdt_object, mot_obj.mo_lu);
1898 struct mdt_object *mdt_object_find(const struct lu_env *env,
1899 struct mdt_device *d,
1900 const struct lu_fid *f)
1902 struct lu_object *o;
1903 struct mdt_object *m;
1906 CDEBUG(D_INFO, "Find object for "DFID"\n", PFID(f));
1907 o = lu_object_find(env, &d->mdt_md_dev.md_lu_dev, f, NULL);
1908 if (unlikely(IS_ERR(o)))
1909 m = (struct mdt_object *)o;
1916 * Asyncronous commit for mdt device.
1918 * Pass asynchonous commit call down the MDS stack.
1920 * \param env environment
1921 * \param mdt the mdt device
1923 static void mdt_device_commit_async(const struct lu_env *env,
1924 struct mdt_device *mdt)
1926 struct dt_device *dt = mdt->mdt_bottom;
1929 rc = dt->dd_ops->dt_commit_async(env, dt);
1930 if (unlikely(rc != 0))
1931 CWARN("async commit start failed with rc = %d", rc);
1935 * Mark the lock as "synchonous".
1937 * Mark the lock to deffer transaction commit to the unlock time.
1939 * \param lock the lock to mark as "synchonous"
1941 * \see mdt_is_lock_sync
1942 * \see mdt_save_lock
1944 static inline void mdt_set_lock_sync(struct ldlm_lock *lock)
1946 lock->l_ast_data = (void*)1;
1950 * Check whehter the lock "synchonous" or not.
1952 * \param lock the lock to check
1953 * \retval 1 the lock is "synchonous"
1954 * \retval 0 the lock isn't "synchronous"
1956 * \see mdt_set_lock_sync
1957 * \see mdt_save_lock
1959 static inline int mdt_is_lock_sync(struct ldlm_lock *lock)
1961 return lock->l_ast_data != NULL;
1965 * Blocking AST for mdt locks.
1967 * Starts transaction commit if in case of COS lock conflict or
1968 * deffers such a commit to the mdt_save_lock.
1970 * \param lock the lock which blocks a request or cancelling lock
1971 * \param desc unused
1972 * \param data unused
1973 * \param flag indicates whether this cancelling or blocking callback
1975 * \see ldlm_blocking_ast_nocheck
1977 int mdt_blocking_ast(struct ldlm_lock *lock, struct ldlm_lock_desc *desc,
1978 void *data, int flag)
1980 struct obd_device *obd = lock->l_resource->lr_namespace->ns_obd;
1981 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
1985 if (flag == LDLM_CB_CANCELING)
1987 lock_res_and_lock(lock);
1988 if (lock->l_blocking_ast != mdt_blocking_ast) {
1989 unlock_res_and_lock(lock);
1992 if (mdt_cos_is_enabled(mdt) &&
1993 lock->l_req_mode & (LCK_PW | LCK_EX) &&
1994 lock->l_blocking_lock != NULL &&
1995 lock->l_client_cookie != lock->l_blocking_lock->l_client_cookie) {
1996 mdt_set_lock_sync(lock);
1998 rc = ldlm_blocking_ast_nocheck(lock);
2000 /* There is no lock conflict if l_blocking_lock == NULL,
2001 * it indicates a blocking ast sent from ldlm_lock_decref_internal
2002 * when the last reference to a local lock was released */
2003 if (lock->l_req_mode == LCK_COS && lock->l_blocking_lock != NULL) {
2006 rc = lu_env_init(&env, LCT_MD_THREAD);
2007 if (unlikely(rc != 0))
2008 CWARN("lu_env initialization failed with rc = %d,"
2009 "cannot start asynchronous commit\n", rc);
2011 mdt_device_commit_async(&env, mdt);
2017 int mdt_object_lock(struct mdt_thread_info *info, struct mdt_object *o,
2018 struct mdt_lock_handle *lh, __u64 ibits, int locality)
2020 struct ldlm_namespace *ns = info->mti_mdt->mdt_namespace;
2021 ldlm_policy_data_t *policy = &info->mti_policy;
2022 struct ldlm_res_id *res_id = &info->mti_res_id;
2026 LASSERT(!lustre_handle_is_used(&lh->mlh_reg_lh));
2027 LASSERT(!lustre_handle_is_used(&lh->mlh_pdo_lh));
2028 LASSERT(lh->mlh_reg_mode != LCK_MINMODE);
2029 LASSERT(lh->mlh_type != MDT_NUL_LOCK);
2031 if (mdt_object_exists(o) < 0) {
2032 if (locality == MDT_CROSS_LOCK) {
2033 /* cross-ref object fix */
2034 ibits &= ~MDS_INODELOCK_UPDATE;
2035 ibits |= MDS_INODELOCK_LOOKUP;
2037 LASSERT(!(ibits & MDS_INODELOCK_UPDATE));
2038 LASSERT(ibits & MDS_INODELOCK_LOOKUP);
2040 /* No PDO lock on remote object */
2041 LASSERT(lh->mlh_type != MDT_PDO_LOCK);
2044 if (lh->mlh_type == MDT_PDO_LOCK) {
2045 /* check for exists after object is locked */
2046 if (mdt_object_exists(o) == 0) {
2047 /* Non-existent object shouldn't have PDO lock */
2050 /* Non-dir object shouldn't have PDO lock */
2051 LASSERT(S_ISDIR(lu_object_attr(&o->mot_obj.mo_lu)));
2055 memset(policy, 0, sizeof(*policy));
2056 fid_build_reg_res_name(mdt_object_fid(o), res_id);
2059 * Take PDO lock on whole directory and build correct @res_id for lock
2060 * on part of directory.
2062 if (lh->mlh_pdo_hash != 0) {
2063 LASSERT(lh->mlh_type == MDT_PDO_LOCK);
2064 mdt_lock_pdo_mode(info, o, lh);
2065 if (lh->mlh_pdo_mode != LCK_NL) {
2067 * Do not use LDLM_FL_LOCAL_ONLY for parallel lock, it
2068 * is never going to be sent to client and we do not
2069 * want it slowed down due to possible cancels.
2071 policy->l_inodebits.bits = MDS_INODELOCK_UPDATE;
2072 rc = mdt_fid_lock(ns, &lh->mlh_pdo_lh, lh->mlh_pdo_mode,
2073 policy, res_id, LDLM_FL_ATOMIC_CB,
2074 &info->mti_exp->exp_handle.h_cookie);
2080 * Finish res_id initializing by name hash marking part of
2081 * directory which is taking modification.
2083 res_id->name[LUSTRE_RES_ID_HSH_OFF] = lh->mlh_pdo_hash;
2086 policy->l_inodebits.bits = ibits;
2089 * Use LDLM_FL_LOCAL_ONLY for this lock. We do not know yet if it is
2090 * going to be sent to client. If it is - mdt_intent_policy() path will
2091 * fix it up and turn FL_LOCAL flag off.
2093 rc = mdt_fid_lock(ns, &lh->mlh_reg_lh, lh->mlh_reg_mode, policy,
2094 res_id, LDLM_FL_LOCAL_ONLY | LDLM_FL_ATOMIC_CB,
2095 &info->mti_exp->exp_handle.h_cookie);
2101 mdt_object_unlock(info, o, lh, 1);
2108 * Save a lock within request object.
2110 * Keep the lock referenced until whether client ACK or transaction
2111 * commit happens or release the lock immediately depending on input
2112 * parameters. If COS is ON, a write lock is converted to COS lock
2115 * \param info thead info object
2116 * \param h lock handle
2117 * \param mode lock mode
2118 * \param decref force immediate lock releasing
2121 void mdt_save_lock(struct mdt_thread_info *info, struct lustre_handle *h,
2122 ldlm_mode_t mode, int decref)
2126 if (lustre_handle_is_used(h)) {
2127 if (decref || !info->mti_has_trans ||
2128 !(mode & (LCK_PW | LCK_EX))){
2129 mdt_fid_unlock(h, mode);
2131 struct mdt_device *mdt = info->mti_mdt;
2132 struct ldlm_lock *lock = ldlm_handle2lock(h);
2133 struct ptlrpc_request *req = mdt_info_req(info);
2136 LASSERTF(lock != NULL, "no lock for cookie "LPX64"\n",
2138 CDEBUG(D_HA, "request = %p reply state = %p"
2139 " transno = "LPD64"\n",
2140 req, req->rq_reply_state, req->rq_transno);
2141 if (mdt_cos_is_enabled(mdt)) {
2143 ldlm_lock_downgrade(lock, LCK_COS);
2146 ptlrpc_save_lock(req, h, mode, no_ack);
2147 if (mdt_is_lock_sync(lock)) {
2148 CDEBUG(D_HA, "found sync-lock,"
2149 " async commit started\n");
2150 mdt_device_commit_async(info->mti_env,
2153 LDLM_LOCK_PUT(lock);
2162 * Unlock mdt object.
2164 * Immeditely release the regular lock and the PDO lock or save the
2165 * lock in reqeuest and keep them referenced until client ACK or
2166 * transaction commit.
2168 * \param info thread info object
2169 * \param o mdt object
2170 * \param h mdt lock handle referencing regular and PDO locks
2171 * \param decref force immediate lock releasing
2173 void mdt_object_unlock(struct mdt_thread_info *info, struct mdt_object *o,
2174 struct mdt_lock_handle *lh, int decref)
2178 mdt_save_lock(info, &lh->mlh_pdo_lh, lh->mlh_pdo_mode, decref);
2179 mdt_save_lock(info, &lh->mlh_reg_lh, lh->mlh_reg_mode, decref);
2184 struct mdt_object *mdt_object_find_lock(struct mdt_thread_info *info,
2185 const struct lu_fid *f,
2186 struct mdt_lock_handle *lh,
2189 struct mdt_object *o;
2191 o = mdt_object_find(info->mti_env, info->mti_mdt, f);
2195 rc = mdt_object_lock(info, o, lh, ibits,
2198 mdt_object_put(info->mti_env, o);
2205 void mdt_object_unlock_put(struct mdt_thread_info * info,
2206 struct mdt_object * o,
2207 struct mdt_lock_handle *lh,
2210 mdt_object_unlock(info, o, lh, decref);
2211 mdt_object_put(info->mti_env, o);
2214 static struct mdt_handler *mdt_handler_find(__u32 opc,
2215 struct mdt_opc_slice *supported)
2217 struct mdt_opc_slice *s;
2218 struct mdt_handler *h;
2221 for (s = supported; s->mos_hs != NULL; s++) {
2222 if (s->mos_opc_start <= opc && opc < s->mos_opc_end) {
2223 h = s->mos_hs + (opc - s->mos_opc_start);
2224 if (likely(h->mh_opc != 0))
2225 LASSERT(h->mh_opc == opc);
2227 h = NULL; /* unsupported opc */
2234 static int mdt_lock_resname_compat(struct mdt_device *m,
2235 struct ldlm_request *req)
2237 /* XXX something... later. */
2241 static int mdt_lock_reply_compat(struct mdt_device *m, struct ldlm_reply *rep)
2243 /* XXX something... later. */
2248 * Generic code handling requests that have struct mdt_body passed in:
2250 * - extract mdt_body from request and save it in @info, if present;
2252 * - create lu_object, corresponding to the fid in mdt_body, and save it in
2255 * - if HABEO_CORPUS flag is set for this request type check whether object
2256 * actually exists on storage (lu_object_exists()).
2259 static int mdt_body_unpack(struct mdt_thread_info *info, __u32 flags)
2261 const struct mdt_body *body;
2262 struct mdt_object *obj;
2263 const struct lu_env *env;
2264 struct req_capsule *pill;
2268 env = info->mti_env;
2269 pill = info->mti_pill;
2271 body = info->mti_body = req_capsule_client_get(pill, &RMF_MDT_BODY);
2275 if (!(body->valid & OBD_MD_FLID))
2278 if (!fid_is_sane(&body->fid1)) {
2279 CERROR("Invalid fid: "DFID"\n", PFID(&body->fid1));
2284 * Do not get size or any capa fields before we check that request
2285 * contains capa actually. There are some requests which do not, for
2286 * instance MDS_IS_SUBDIR.
2288 if (req_capsule_has_field(pill, &RMF_CAPA1, RCL_CLIENT) &&
2289 req_capsule_get_size(pill, &RMF_CAPA1, RCL_CLIENT))
2290 mdt_set_capainfo(info, 0, &body->fid1,
2291 req_capsule_client_get(pill, &RMF_CAPA1));
2293 obj = mdt_object_find(env, info->mti_mdt, &body->fid1);
2295 if ((flags & HABEO_CORPUS) &&
2296 !mdt_object_exists(obj)) {
2297 mdt_object_put(env, obj);
2298 /* for capability renew ENOENT will be handled in
2300 if (body->valid & OBD_MD_FLOSSCAPA)
2305 info->mti_object = obj;
2314 static int mdt_unpack_req_pack_rep(struct mdt_thread_info *info, __u32 flags)
2316 struct req_capsule *pill = info->mti_pill;
2320 if (req_capsule_has_field(pill, &RMF_MDT_BODY, RCL_CLIENT))
2321 rc = mdt_body_unpack(info, flags);
2325 if (rc == 0 && (flags & HABEO_REFERO)) {
2326 struct mdt_device *mdt = info->mti_mdt;
2329 if (req_capsule_has_field(pill, &RMF_MDT_MD, RCL_SERVER))
2330 req_capsule_set_size(pill, &RMF_MDT_MD, RCL_SERVER,
2331 mdt->mdt_max_mdsize);
2332 if (req_capsule_has_field(pill, &RMF_LOGCOOKIES, RCL_SERVER))
2333 req_capsule_set_size(pill, &RMF_LOGCOOKIES, RCL_SERVER,
2334 mdt->mdt_max_cookiesize);
2336 rc = req_capsule_server_pack(pill);
2341 static int mdt_init_capa_ctxt(const struct lu_env *env, struct mdt_device *m)
2343 struct md_device *next = m->mdt_child;
2345 return next->md_ops->mdo_init_capa_ctxt(env, next,
2346 m->mdt_opts.mo_mds_capa,
2347 m->mdt_capa_timeout,
2353 * Invoke handler for this request opc. Also do necessary preprocessing
2354 * (according to handler ->mh_flags), and post-processing (setting of
2355 * ->last_{xid,committed}).
2357 static int mdt_req_handle(struct mdt_thread_info *info,
2358 struct mdt_handler *h, struct ptlrpc_request *req)
2360 int rc, serious = 0;
2365 LASSERT(h->mh_act != NULL);
2366 LASSERT(h->mh_opc == lustre_msg_get_opc(req->rq_reqmsg));
2367 LASSERT(current->journal_info == NULL);
2370 * Checking for various OBD_FAIL_$PREF_$OPC_NET codes. _Do_ not try
2371 * to put same checks into handlers like mdt_close(), mdt_reint(),
2372 * etc., without talking to mdt authors first. Checking same thing
2373 * there again is useless and returning 0 error wihtout packing reply
2374 * is buggy! Handlers either pack reply or return error.
2376 * We return 0 here and do not send any reply in order to emulate
2377 * network failure. Do not send any reply in case any of NET related
2378 * fail_id has occured.
2380 if (OBD_FAIL_CHECK_ORSET(h->mh_fail_id, OBD_FAIL_ONCE))
2384 flags = h->mh_flags;
2385 LASSERT(ergo(flags & (HABEO_CORPUS|HABEO_REFERO), h->mh_fmt != NULL));
2387 if (h->mh_fmt != NULL) {
2388 req_capsule_set(info->mti_pill, h->mh_fmt);
2389 rc = mdt_unpack_req_pack_rep(info, flags);
2392 if (rc == 0 && flags & MUTABOR &&
2393 req->rq_export->exp_connect_flags & OBD_CONNECT_RDONLY)
2394 /* should it be rq_status? */
2397 if (rc == 0 && flags & HABEO_CLAVIS) {
2398 struct ldlm_request *dlm_req;
2400 LASSERT(h->mh_fmt != NULL);
2402 dlm_req = req_capsule_client_get(info->mti_pill, &RMF_DLM_REQ);
2403 if (dlm_req != NULL) {
2404 if (info->mti_mdt->mdt_opts.mo_compat_resname)
2405 rc = mdt_lock_resname_compat(info->mti_mdt,
2407 info->mti_dlm_req = dlm_req;
2413 /* capability setting changed via /proc, needs reinitialize ctxt */
2414 if (info->mti_mdt && info->mti_mdt->mdt_capa_conf) {
2415 mdt_init_capa_ctxt(info->mti_env, info->mti_mdt);
2416 info->mti_mdt->mdt_capa_conf = 0;
2419 if (likely(rc == 0)) {
2421 * Process request, there can be two types of rc:
2422 * 1) errors with msg unpack/pack, other failures outside the
2423 * operation itself. This is counted as serious errors;
2424 * 2) errors during fs operation, should be placed in rq_status
2427 rc = h->mh_act(info);
2429 !req->rq_no_reply && req->rq_reply_state == NULL) {
2430 DEBUG_REQ(D_ERROR, req, "MDT \"handler\" %s did not "
2431 "pack reply and returned 0 error\n",
2435 serious = is_serious(rc);
2436 rc = clear_serious(rc);
2440 req->rq_status = rc;
2443 * ELDLM_* codes which > 0 should be in rq_status only as well as
2444 * all non-serious errors.
2446 if (rc > 0 || !serious)
2449 LASSERT(current->journal_info == NULL);
2451 if (rc == 0 && (flags & HABEO_CLAVIS) &&
2452 info->mti_mdt->mdt_opts.mo_compat_resname) {
2453 struct ldlm_reply *dlmrep;
2455 dlmrep = req_capsule_server_get(info->mti_pill, &RMF_DLM_REP);
2457 rc = mdt_lock_reply_compat(info->mti_mdt, dlmrep);
2460 /* If we're DISCONNECTing, the mdt_export_data is already freed */
2461 if (likely(rc == 0 && h->mh_opc != MDS_DISCONNECT))
2462 target_committed_to_req(req);
2464 if (unlikely((lustre_msg_get_flags(req->rq_reqmsg) & MSG_REPLAY) &&
2465 lustre_msg_get_transno(req->rq_reqmsg) == 0)) {
2466 DEBUG_REQ(D_ERROR, req, "transno is 0 during REPLAY");
2470 target_send_reply(req, rc, info->mti_fail_id);
2474 void mdt_lock_handle_init(struct mdt_lock_handle *lh)
2476 lh->mlh_type = MDT_NUL_LOCK;
2477 lh->mlh_reg_lh.cookie = 0ull;
2478 lh->mlh_reg_mode = LCK_MINMODE;
2479 lh->mlh_pdo_lh.cookie = 0ull;
2480 lh->mlh_pdo_mode = LCK_MINMODE;
2483 void mdt_lock_handle_fini(struct mdt_lock_handle *lh)
2485 LASSERT(!lustre_handle_is_used(&lh->mlh_reg_lh));
2486 LASSERT(!lustre_handle_is_used(&lh->mlh_pdo_lh));
2490 * Initialize fields of struct mdt_thread_info. Other fields are left in
2491 * uninitialized state, because it's too expensive to zero out whole
2492 * mdt_thread_info (> 1K) on each request arrival.
2494 static void mdt_thread_info_init(struct ptlrpc_request *req,
2495 struct mdt_thread_info *info)
2498 struct md_capainfo *ci;
2500 req_capsule_init(&req->rq_pill, req, RCL_SERVER);
2501 info->mti_pill = &req->rq_pill;
2504 for (i = 0; i < ARRAY_SIZE(info->mti_lh); i++)
2505 mdt_lock_handle_init(&info->mti_lh[i]);
2507 /* mdt device: it can be NULL while CONNECT */
2508 if (req->rq_export) {
2509 info->mti_mdt = mdt_dev(req->rq_export->exp_obd->obd_lu_dev);
2510 info->mti_exp = req->rq_export;
2512 info->mti_mdt = NULL;
2513 info->mti_env = req->rq_svc_thread->t_env;
2514 ci = md_capainfo(info->mti_env);
2515 memset(ci, 0, sizeof *ci);
2516 if (req->rq_export) {
2517 if (exp_connect_rmtclient(req->rq_export))
2518 ci->mc_auth = LC_ID_CONVERT;
2519 else if (req->rq_export->exp_connect_flags &
2520 OBD_CONNECT_MDS_CAPA)
2521 ci->mc_auth = LC_ID_PLAIN;
2523 ci->mc_auth = LC_ID_NONE;
2526 info->mti_fail_id = OBD_FAIL_MDS_ALL_REPLY_NET;
2527 info->mti_transno = lustre_msg_get_transno(req->rq_reqmsg);
2529 memset(&info->mti_attr, 0, sizeof(info->mti_attr));
2530 info->mti_body = NULL;
2531 info->mti_object = NULL;
2532 info->mti_dlm_req = NULL;
2533 info->mti_has_trans = 0;
2534 info->mti_no_need_trans = 0;
2535 info->mti_cross_ref = 0;
2536 info->mti_opdata = 0;
2538 /* To not check for split by default. */
2539 info->mti_spec.sp_ck_split = 0;
2542 static void mdt_thread_info_fini(struct mdt_thread_info *info)
2546 req_capsule_fini(info->mti_pill);
2547 if (info->mti_object != NULL) {
2548 mdt_object_put(info->mti_env, info->mti_object);
2549 info->mti_object = NULL;
2551 for (i = 0; i < ARRAY_SIZE(info->mti_lh); i++)
2552 mdt_lock_handle_fini(&info->mti_lh[i]);
2553 info->mti_env = NULL;
2556 static int mdt_filter_recovery_request(struct ptlrpc_request *req,
2557 struct obd_device *obd, int *process)
2559 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
2560 case MDS_CONNECT: /* This will never get here, but for completeness. */
2561 case OST_CONNECT: /* This will never get here, but for completeness. */
2562 case MDS_DISCONNECT:
2563 case OST_DISCONNECT:
2568 case MDS_DONE_WRITING:
2569 case MDS_SYNC: /* used in unmounting */
2575 *process = target_queue_recovery_request(req, obd);
2579 DEBUG_REQ(D_ERROR, req, "not permitted during recovery");
2586 * Handle recovery. Return:
2587 * +1: continue request processing;
2588 * -ve: abort immediately with the given error code;
2589 * 0: send reply with error code in req->rq_status;
2591 static int mdt_recovery(struct mdt_thread_info *info)
2593 struct ptlrpc_request *req = mdt_info_req(info);
2595 struct obd_device *obd;
2599 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
2602 case SEC_CTX_INIT_CONT:
2608 rc = mdt_handle_idmap(info);
2617 if (unlikely(req->rq_export == NULL)) {
2618 CERROR("operation %d on unconnected MDS from %s\n",
2619 lustre_msg_get_opc(req->rq_reqmsg),
2620 libcfs_id2str(req->rq_peer));
2621 /* FIXME: For CMD cleanup, when mds_B stop, the req from
2622 * mds_A will get -ENOTCONN(especially for ping req),
2623 * which will cause that mds_A deactive timeout, then when
2624 * mds_A cleanup, the cleanup process will be suspended since
2625 * deactive timeout is not zero.
2627 req->rq_status = -ENOTCONN;
2628 target_send_reply(req, -ENOTCONN, info->mti_fail_id);
2632 /* sanity check: if the xid matches, the request must be marked as a
2633 * resent or replayed */
2634 if (req_xid_is_last(req)) {
2635 if (!(lustre_msg_get_flags(req->rq_reqmsg) &
2636 (MSG_RESENT | MSG_REPLAY))) {
2637 DEBUG_REQ(D_WARNING, req, "rq_xid "LPU64" matches last_xid, "
2638 "expected REPLAY or RESENT flag (%x)", req->rq_xid,
2639 lustre_msg_get_flags(req->rq_reqmsg));
2641 req->rq_status = -ENOTCONN;
2646 /* else: note the opposite is not always true; a RESENT req after a
2647 * failover will usually not match the last_xid, since it was likely
2648 * never committed. A REPLAYed request will almost never match the
2649 * last xid, however it could for a committed, but still retained,
2652 obd = req->rq_export->exp_obd;
2654 /* Check for aborted recovery... */
2655 spin_lock_bh(&obd->obd_processing_task_lock);
2656 recovering = obd->obd_recovering;
2657 spin_unlock_bh(&obd->obd_processing_task_lock);
2658 if (unlikely(recovering)) {
2661 DEBUG_REQ(D_INFO, req, "Got new replay");
2662 rc = mdt_filter_recovery_request(req, obd, &should_process);
2663 if (rc != 0 || !should_process)
2665 else if (should_process < 0) {
2666 req->rq_status = should_process;
2667 rc = ptlrpc_error(req);
2674 static int mdt_msg_check_version(struct lustre_msg *msg)
2678 switch (lustre_msg_get_opc(msg)) {
2680 case MDS_DISCONNECT:
2683 case SEC_CTX_INIT_CONT:
2685 rc = lustre_msg_check_version(msg, LUSTRE_OBD_VERSION);
2687 CERROR("bad opc %u version %08x, expecting %08x\n",
2688 lustre_msg_get_opc(msg),
2689 lustre_msg_get_version(msg),
2690 LUSTRE_OBD_VERSION);
2694 case MDS_GETATTR_NAME:
2701 case MDS_DONE_WRITING:
2707 case MDS_QUOTACHECK:
2713 rc = lustre_msg_check_version(msg, LUSTRE_MDS_VERSION);
2715 CERROR("bad opc %u version %08x, expecting %08x\n",
2716 lustre_msg_get_opc(msg),
2717 lustre_msg_get_version(msg),
2718 LUSTRE_MDS_VERSION);
2722 case LDLM_BL_CALLBACK:
2723 case LDLM_CP_CALLBACK:
2724 rc = lustre_msg_check_version(msg, LUSTRE_DLM_VERSION);
2726 CERROR("bad opc %u version %08x, expecting %08x\n",
2727 lustre_msg_get_opc(msg),
2728 lustre_msg_get_version(msg),
2729 LUSTRE_DLM_VERSION);
2731 case OBD_LOG_CANCEL:
2732 case LLOG_ORIGIN_HANDLE_CREATE:
2733 case LLOG_ORIGIN_HANDLE_NEXT_BLOCK:
2734 case LLOG_ORIGIN_HANDLE_READ_HEADER:
2735 case LLOG_ORIGIN_HANDLE_CLOSE:
2736 case LLOG_ORIGIN_HANDLE_DESTROY:
2737 case LLOG_ORIGIN_HANDLE_PREV_BLOCK:
2739 rc = lustre_msg_check_version(msg, LUSTRE_LOG_VERSION);
2741 CERROR("bad opc %u version %08x, expecting %08x\n",
2742 lustre_msg_get_opc(msg),
2743 lustre_msg_get_version(msg),
2744 LUSTRE_LOG_VERSION);
2747 CERROR("MDS unknown opcode %d\n", lustre_msg_get_opc(msg));
2753 static int mdt_handle0(struct ptlrpc_request *req,
2754 struct mdt_thread_info *info,
2755 struct mdt_opc_slice *supported)
2757 struct mdt_handler *h;
2758 struct lustre_msg *msg;
2763 if (OBD_FAIL_CHECK_ORSET(OBD_FAIL_MDS_ALL_REQUEST_NET, OBD_FAIL_ONCE))
2766 LASSERT(current->journal_info == NULL);
2768 msg = req->rq_reqmsg;
2769 rc = mdt_msg_check_version(msg);
2770 if (likely(rc == 0)) {
2771 rc = mdt_recovery(info);
2772 if (likely(rc == +1)) {
2773 h = mdt_handler_find(lustre_msg_get_opc(msg),
2775 if (likely(h != NULL)) {
2776 rc = mdt_req_handle(info, h, req);
2778 CERROR("The unsupported opc: 0x%x\n", lustre_msg_get_opc(msg) );
2779 req->rq_status = -ENOTSUPP;
2780 rc = ptlrpc_error(req);
2785 CERROR(LUSTRE_MDT_NAME" drops mal-formed request\n");
2790 * MDT handler function called by ptlrpc service thread when request comes.
2792 * XXX common "target" functionality should be factored into separate module
2793 * shared by mdt, ost and stand-alone services like fld.
2795 static int mdt_handle_common(struct ptlrpc_request *req,
2796 struct mdt_opc_slice *supported)
2799 struct mdt_thread_info *info;
2803 env = req->rq_svc_thread->t_env;
2804 LASSERT(env != NULL);
2805 LASSERT(env->le_ses != NULL);
2806 LASSERT(env->le_ctx.lc_thread == req->rq_svc_thread);
2807 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
2808 LASSERT(info != NULL);
2810 mdt_thread_info_init(req, info);
2812 rc = mdt_handle0(req, info, supported);
2814 mdt_thread_info_fini(info);
2819 * This is called from recovery code as handler of _all_ RPC types, FLD and SEQ
2822 int mdt_recovery_handle(struct ptlrpc_request *req)
2827 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
2829 rc = mdt_handle_common(req, mdt_fld_handlers);
2832 rc = mdt_handle_common(req, mdt_seq_handlers);
2835 rc = mdt_handle_common(req, mdt_regular_handlers);
2842 static int mdt_regular_handle(struct ptlrpc_request *req)
2844 return mdt_handle_common(req, mdt_regular_handlers);
2847 static int mdt_readpage_handle(struct ptlrpc_request *req)
2849 return mdt_handle_common(req, mdt_readpage_handlers);
2852 static int mdt_xmds_handle(struct ptlrpc_request *req)
2854 return mdt_handle_common(req, mdt_xmds_handlers);
2857 static int mdt_mdsc_handle(struct ptlrpc_request *req)
2859 return mdt_handle_common(req, mdt_seq_handlers);
2862 static int mdt_mdss_handle(struct ptlrpc_request *req)
2864 return mdt_handle_common(req, mdt_seq_handlers);
2867 static int mdt_dtss_handle(struct ptlrpc_request *req)
2869 return mdt_handle_common(req, mdt_seq_handlers);
2872 static int mdt_fld_handle(struct ptlrpc_request *req)
2874 return mdt_handle_common(req, mdt_fld_handlers);
2890 static int mdt_intent_getattr(enum mdt_it_code opcode,
2891 struct mdt_thread_info *info,
2892 struct ldlm_lock **,
2894 static int mdt_intent_reint(enum mdt_it_code opcode,
2895 struct mdt_thread_info *info,
2896 struct ldlm_lock **,
2899 static struct mdt_it_flavor {
2900 const struct req_format *it_fmt;
2902 int (*it_act)(enum mdt_it_code ,
2903 struct mdt_thread_info *,
2904 struct ldlm_lock **,
2907 } mdt_it_flavor[] = {
2909 .it_fmt = &RQF_LDLM_INTENT,
2910 /*.it_flags = HABEO_REFERO,*/
2912 .it_act = mdt_intent_reint,
2913 .it_reint = REINT_OPEN
2916 .it_fmt = &RQF_LDLM_INTENT,
2917 .it_flags = MUTABOR,
2918 .it_act = mdt_intent_reint,
2919 .it_reint = REINT_OPEN
2922 .it_fmt = &RQF_LDLM_INTENT,
2923 .it_flags = MUTABOR,
2924 .it_act = mdt_intent_reint,
2925 .it_reint = REINT_CREATE
2927 [MDT_IT_GETATTR] = {
2928 .it_fmt = &RQF_LDLM_INTENT_GETATTR,
2929 .it_flags = HABEO_REFERO,
2930 .it_act = mdt_intent_getattr
2932 [MDT_IT_READDIR] = {
2938 .it_fmt = &RQF_LDLM_INTENT_GETATTR,
2939 .it_flags = HABEO_REFERO,
2940 .it_act = mdt_intent_getattr
2943 .it_fmt = &RQF_LDLM_INTENT_UNLINK,
2944 .it_flags = MUTABOR,
2946 .it_reint = REINT_UNLINK
2950 .it_flags = MUTABOR,
2953 [MDT_IT_GETXATTR] = {
2960 int mdt_intent_lock_replace(struct mdt_thread_info *info,
2961 struct ldlm_lock **lockp,
2962 struct ldlm_lock *new_lock,
2963 struct mdt_lock_handle *lh,
2966 struct ptlrpc_request *req = mdt_info_req(info);
2967 struct ldlm_lock *lock = *lockp;
2970 * Get new lock only for cases when possible resent did not find any
2973 if (new_lock == NULL)
2974 new_lock = ldlm_handle2lock_long(&lh->mlh_reg_lh, 0);
2976 if (new_lock == NULL && (flags & LDLM_FL_INTENT_ONLY)) {
2977 lh->mlh_reg_lh.cookie = 0;
2981 LASSERTF(new_lock != NULL,
2982 "lockh "LPX64"\n", lh->mlh_reg_lh.cookie);
2985 * If we've already given this lock to a client once, then we should
2986 * have no readers or writers. Otherwise, we should have one reader
2987 * _or_ writer ref (which will be zeroed below) before returning the
2990 if (new_lock->l_export == req->rq_export) {
2991 LASSERT(new_lock->l_readers + new_lock->l_writers == 0);
2993 LASSERT(new_lock->l_export == NULL);
2994 LASSERT(new_lock->l_readers + new_lock->l_writers == 1);
2999 if (new_lock->l_export == req->rq_export) {
3001 * Already gave this to the client, which means that we
3002 * reconstructed a reply.
3004 LASSERT(lustre_msg_get_flags(req->rq_reqmsg) &
3006 lh->mlh_reg_lh.cookie = 0;
3007 RETURN(ELDLM_LOCK_REPLACED);
3011 * Fixup the lock to be given to the client.
3013 lock_res_and_lock(new_lock);
3014 /* Zero new_lock->l_readers and new_lock->l_writers without triggering
3015 * possible blocking AST. */
3016 while (new_lock->l_readers > 0) {
3017 lu_ref_del(&new_lock->l_reference, "reader", new_lock);
3018 lu_ref_del(&new_lock->l_reference, "user", new_lock);
3019 new_lock->l_readers--;
3021 while (new_lock->l_writers > 0) {
3022 lu_ref_del(&new_lock->l_reference, "writer", new_lock);
3023 lu_ref_del(&new_lock->l_reference, "user", new_lock);
3024 new_lock->l_writers--;
3027 new_lock->l_export = class_export_get(req->rq_export);
3028 new_lock->l_blocking_ast = lock->l_blocking_ast;
3029 new_lock->l_completion_ast = lock->l_completion_ast;
3030 new_lock->l_remote_handle = lock->l_remote_handle;
3031 new_lock->l_flags &= ~LDLM_FL_LOCAL;
3033 unlock_res_and_lock(new_lock);
3035 lustre_hash_add(new_lock->l_export->exp_lock_hash,
3036 &new_lock->l_remote_handle,
3037 &new_lock->l_exp_hash);
3039 LDLM_LOCK_RELEASE(new_lock);
3040 lh->mlh_reg_lh.cookie = 0;
3042 RETURN(ELDLM_LOCK_REPLACED);
3045 static void mdt_intent_fixup_resent(struct mdt_thread_info *info,
3046 struct ldlm_lock *new_lock,
3047 struct ldlm_lock **old_lock,
3048 struct mdt_lock_handle *lh)
3050 struct ptlrpc_request *req = mdt_info_req(info);
3051 struct obd_export *exp = req->rq_export;
3052 struct lustre_handle remote_hdl;
3053 struct ldlm_request *dlmreq;
3054 struct ldlm_lock *lock;
3056 if (!(lustre_msg_get_flags(req->rq_reqmsg) & MSG_RESENT))
3059 dlmreq = req_capsule_client_get(info->mti_pill, &RMF_DLM_REQ);
3060 remote_hdl = dlmreq->lock_handle[0];
3062 lock = lustre_hash_lookup(exp->exp_lock_hash, &remote_hdl);
3064 if (lock != new_lock) {
3065 lh->mlh_reg_lh.cookie = lock->l_handle.h_cookie;
3066 lh->mlh_reg_mode = lock->l_granted_mode;
3068 LDLM_DEBUG(lock, "Restoring lock cookie");
3069 DEBUG_REQ(D_DLMTRACE, req,
3070 "restoring lock cookie "LPX64,
3071 lh->mlh_reg_lh.cookie);
3073 *old_lock = LDLM_LOCK_GET(lock);
3074 lh_put(exp->exp_lock_hash, &lock->l_exp_hash);
3078 lh_put(exp->exp_lock_hash, &lock->l_exp_hash);
3082 * If the xid matches, then we know this is a resent request, and allow
3083 * it. (It's probably an OPEN, for which we don't send a lock.
3085 if (req_xid_is_last(req))
3089 * This remote handle isn't enqueued, so we never received or processed
3090 * this request. Clear MSG_RESENT, because it can be handled like any
3091 * normal request now.
3093 lustre_msg_clear_flags(req->rq_reqmsg, MSG_RESENT);
3095 DEBUG_REQ(D_DLMTRACE, req, "no existing lock with rhandle "LPX64,
3099 static int mdt_intent_getattr(enum mdt_it_code opcode,
3100 struct mdt_thread_info *info,
3101 struct ldlm_lock **lockp,
3104 struct mdt_lock_handle *lhc = &info->mti_lh[MDT_LH_RMT];
3105 struct ldlm_lock *new_lock = NULL;
3107 struct ldlm_reply *ldlm_rep;
3108 struct ptlrpc_request *req;
3109 struct mdt_body *reqbody;
3110 struct mdt_body *repbody;
3114 reqbody = req_capsule_client_get(info->mti_pill, &RMF_MDT_BODY);
3117 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
3120 info->mti_spec.sp_ck_split = !!(reqbody->valid & OBD_MD_FLCKSPLIT);
3121 info->mti_cross_ref = !!(reqbody->valid & OBD_MD_FLCROSSREF);
3122 repbody->eadatasize = 0;
3123 repbody->aclsize = 0;
3127 child_bits = MDS_INODELOCK_LOOKUP;
3129 case MDT_IT_GETATTR:
3130 child_bits = MDS_INODELOCK_LOOKUP | MDS_INODELOCK_UPDATE;
3133 CERROR("Unhandled till now");
3134 GOTO(out_shrink, rc = -EINVAL);
3137 rc = mdt_init_ucred(info, reqbody);
3139 GOTO(out_shrink, rc);
3141 req = info->mti_pill->rc_req;
3142 ldlm_rep = req_capsule_server_get(info->mti_pill, &RMF_DLM_REP);
3143 mdt_set_disposition(info, ldlm_rep, DISP_IT_EXECD);
3145 /* Get lock from request for possible resent case. */
3146 mdt_intent_fixup_resent(info, *lockp, &new_lock, lhc);
3148 ldlm_rep->lock_policy_res2 =
3149 mdt_getattr_name_lock(info, lhc, child_bits, ldlm_rep);
3151 if (mdt_get_disposition(ldlm_rep, DISP_LOOKUP_NEG))
3152 ldlm_rep->lock_policy_res2 = 0;
3153 if (!mdt_get_disposition(ldlm_rep, DISP_LOOKUP_POS) ||
3154 ldlm_rep->lock_policy_res2) {
3155 lhc->mlh_reg_lh.cookie = 0ull;
3156 GOTO(out_ucred, rc = ELDLM_LOCK_ABORTED);
3159 rc = mdt_intent_lock_replace(info, lockp, new_lock, lhc, flags);
3162 mdt_exit_ucred(info);
3164 mdt_shrink_reply(info);
3168 static int mdt_intent_reint(enum mdt_it_code opcode,
3169 struct mdt_thread_info *info,
3170 struct ldlm_lock **lockp,
3173 struct mdt_lock_handle *lhc = &info->mti_lh[MDT_LH_RMT];
3174 struct ldlm_reply *rep = NULL;
3178 static const struct req_format *intent_fmts[REINT_MAX] = {
3179 [REINT_CREATE] = &RQF_LDLM_INTENT_CREATE,
3180 [REINT_OPEN] = &RQF_LDLM_INTENT_OPEN
3185 opc = mdt_reint_opcode(info, intent_fmts);
3189 if (mdt_it_flavor[opcode].it_reint != opc) {
3190 CERROR("Reint code %ld doesn't match intent: %d\n",
3192 RETURN(err_serious(-EPROTO));
3195 /* Get lock from request for possible resent case. */
3196 mdt_intent_fixup_resent(info, *lockp, NULL, lhc);
3198 rc = mdt_reint_internal(info, lhc, opc);
3200 /* Check whether the reply has been packed successfully. */
3201 if (mdt_info_req(info)->rq_repmsg != NULL)
3202 rep = req_capsule_server_get(info->mti_pill, &RMF_DLM_REP);
3204 RETURN(err_serious(-EFAULT));
3206 /* MDC expects this in any case */
3208 mdt_set_disposition(info, rep, DISP_LOOKUP_EXECD);
3210 /* Cross-ref case, the lock should be returned to the client */
3211 if (rc == -EREMOTE) {
3212 LASSERT(lustre_handle_is_used(&lhc->mlh_reg_lh));
3213 rep->lock_policy_res2 = 0;
3214 rc = mdt_intent_lock_replace(info, lockp, NULL, lhc, flags);
3217 rep->lock_policy_res2 = clear_serious(rc);
3219 lhc->mlh_reg_lh.cookie = 0ull;
3220 if (rc == -ENOTCONN || rc == -ENODEV) {
3222 * If it is the disconnect error (ENODEV & ENOCONN), the error
3223 * will be returned by rq_status, and client at ptlrpc layer
3224 * will detect this, then disconnect, reconnect the import
3225 * immediately, instead of impacting the following the rpc.
3230 * For other cases, the error will be returned by intent.
3231 * and client will retrieve the result from intent.
3234 * FIXME: when open lock is finished, that should be
3237 RETURN(ELDLM_LOCK_ABORTED);
3241 static int mdt_intent_code(long itcode)
3249 case IT_OPEN|IT_CREAT:
3256 rc = MDT_IT_READDIR;
3259 rc = MDT_IT_GETATTR;
3271 rc = MDT_IT_GETXATTR;
3274 CERROR("Unknown intent opcode: %ld\n", itcode);
3281 static int mdt_intent_opc(long itopc, struct mdt_thread_info *info,
3282 struct ldlm_lock **lockp, int flags)
3284 struct req_capsule *pill;
3285 struct mdt_it_flavor *flv;
3290 opc = mdt_intent_code(itopc);
3294 pill = info->mti_pill;
3295 flv = &mdt_it_flavor[opc];
3297 if (flv->it_fmt != NULL)
3298 req_capsule_extend(pill, flv->it_fmt);
3300 rc = mdt_unpack_req_pack_rep(info, flv->it_flags);
3302 struct ptlrpc_request *req = mdt_info_req(info);
3303 if (flv->it_flags & MUTABOR &&
3304 req->rq_export->exp_connect_flags & OBD_CONNECT_RDONLY)
3307 if (rc == 0 && flv->it_act != NULL) {
3308 /* execute policy */
3309 rc = flv->it_act(opc, info, lockp, flags);
3316 static int mdt_intent_policy(struct ldlm_namespace *ns,
3317 struct ldlm_lock **lockp, void *req_cookie,
3318 ldlm_mode_t mode, int flags, void *data)
3320 struct mdt_thread_info *info;
3321 struct ptlrpc_request *req = req_cookie;
3322 struct ldlm_intent *it;
3323 struct req_capsule *pill;
3328 LASSERT(req != NULL);
3330 info = lu_context_key_get(&req->rq_svc_thread->t_env->le_ctx,
3332 LASSERT(info != NULL);
3333 pill = info->mti_pill;
3334 LASSERT(pill->rc_req == req);
3336 if (req->rq_reqmsg->lm_bufcount > DLM_INTENT_IT_OFF) {
3337 req_capsule_extend(pill, &RQF_LDLM_INTENT);
3338 it = req_capsule_client_get(pill, &RMF_LDLM_INTENT);
3340 const struct ldlm_request *dlmreq;
3343 rc = mdt_intent_opc(it->opc, info, lockp, flags);
3348 * Lock without inodebits makes no sense and will oops
3349 * later in ldlm. Let's check it now to see if we have
3350 * wrong lock from client or bits get corrupted
3351 * somewhere in mdt_intent_opc().
3353 dlmreq = info->mti_dlm_req;
3354 req_bits = dlmreq->lock_desc.l_policy_data.l_inodebits.bits;
3355 LASSERT(req_bits != 0);
3358 rc = err_serious(-EFAULT);
3360 /* No intent was provided */
3361 LASSERT(pill->rc_fmt == &RQF_LDLM_ENQUEUE);
3362 rc = req_capsule_server_pack(pill);
3364 rc = err_serious(rc);
3372 static void mdt_seq_adjust(const struct lu_env *env,
3373 struct mdt_device *m, int lost)
3375 struct md_site *ms = mdt_md_site(m);
3376 struct lu_seq_range out;
3379 LASSERT(ms && ms->ms_server_seq);
3381 /* get extra seq from seq_server, moving it's range up */
3382 while (lost-- > 0) {
3383 seq_server_alloc_meta(ms->ms_server_seq, NULL, &out, env);
3388 static int mdt_seq_fini(const struct lu_env *env,
3389 struct mdt_device *m)
3391 struct md_site *ms = mdt_md_site(m);
3395 if (ms->ms_server_seq) {
3396 seq_server_fini(ms->ms_server_seq, env);
3397 OBD_FREE_PTR(ms->ms_server_seq);
3398 ms->ms_server_seq = NULL;
3401 if (ms->ms_control_seq) {
3402 seq_server_fini(ms->ms_control_seq, env);
3403 OBD_FREE_PTR(ms->ms_control_seq);
3404 ms->ms_control_seq = NULL;
3407 if (ms->ms_client_seq) {
3408 seq_client_fini(ms->ms_client_seq);
3409 OBD_FREE_PTR(ms->ms_client_seq);
3410 ms->ms_client_seq = NULL;
3417 static int mdt_seq_init(const struct lu_env *env,
3419 struct mdt_device *m)
3426 ms = mdt_md_site(m);
3429 * This is sequence-controller node. Init seq-controller server on local
3432 if (ms->ms_node_id == 0) {
3433 LASSERT(ms->ms_control_seq == NULL);
3435 OBD_ALLOC_PTR(ms->ms_control_seq);
3436 if (ms->ms_control_seq == NULL)
3439 rc = seq_server_init(ms->ms_control_seq,
3440 m->mdt_bottom, uuid,
3441 LUSTRE_SEQ_CONTROLLER,
3446 GOTO(out_seq_fini, rc);
3448 OBD_ALLOC_PTR(ms->ms_client_seq);
3449 if (ms->ms_client_seq == NULL)
3450 GOTO(out_seq_fini, rc = -ENOMEM);
3452 OBD_ALLOC(prefix, MAX_OBD_NAME + 5);
3453 if (prefix == NULL) {
3454 OBD_FREE_PTR(ms->ms_client_seq);
3455 GOTO(out_seq_fini, rc = -ENOMEM);
3458 snprintf(prefix, MAX_OBD_NAME + 5, "ctl-%s",
3462 * Init seq-controller client after seq-controller server is
3463 * ready. Pass ms->ms_control_seq to it for direct talking.
3465 rc = seq_client_init(ms->ms_client_seq, NULL,
3466 LUSTRE_SEQ_METADATA, prefix,
3467 ms->ms_control_seq);
3468 OBD_FREE(prefix, MAX_OBD_NAME + 5);
3471 GOTO(out_seq_fini, rc);
3474 /* Init seq-server on local MDT */
3475 LASSERT(ms->ms_server_seq == NULL);
3477 OBD_ALLOC_PTR(ms->ms_server_seq);
3478 if (ms->ms_server_seq == NULL)
3479 GOTO(out_seq_fini, rc = -ENOMEM);
3481 rc = seq_server_init(ms->ms_server_seq,
3482 m->mdt_bottom, uuid,
3487 GOTO(out_seq_fini, rc = -ENOMEM);
3489 /* Assign seq-controller client to local seq-server. */
3490 if (ms->ms_node_id == 0) {
3491 LASSERT(ms->ms_client_seq != NULL);
3493 rc = seq_server_set_cli(ms->ms_server_seq,
3501 mdt_seq_fini(env, m);
3506 * Init client sequence manager which is used by local MDS to talk to sequence
3507 * controller on remote node.
3509 static int mdt_seq_init_cli(const struct lu_env *env,
3510 struct mdt_device *m,
3511 struct lustre_cfg *cfg)
3513 struct md_site *ms = mdt_md_site(m);
3514 struct obd_device *mdc;
3515 struct obd_uuid *uuidp, *mdcuuidp;
3516 char *uuid_str, *mdc_uuid_str;
3519 struct mdt_thread_info *info;
3520 char *p, *index_string = lustre_cfg_string(cfg, 2);
3523 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
3524 uuidp = &info->mti_u.uuid[0];
3525 mdcuuidp = &info->mti_u.uuid[1];
3527 LASSERT(index_string);
3529 index = simple_strtol(index_string, &p, 10);
3531 CERROR("Invalid index in lustre_cgf, offset 2\n");
3535 /* check if this is adding the first MDC and controller is not yet
3537 if (index != 0 || ms->ms_client_seq)
3540 uuid_str = lustre_cfg_string(cfg, 1);
3541 mdc_uuid_str = lustre_cfg_string(cfg, 4);
3542 obd_str2uuid(uuidp, uuid_str);
3543 obd_str2uuid(mdcuuidp, mdc_uuid_str);
3545 mdc = class_find_client_obd(uuidp, LUSTRE_MDC_NAME, mdcuuidp);
3547 CERROR("can't find controller MDC by uuid %s\n",
3550 } else if (!mdc->obd_set_up) {
3551 CERROR("target %s not set up\n", mdc->obd_name);
3554 LASSERT(ms->ms_control_exp);
3555 OBD_ALLOC_PTR(ms->ms_client_seq);
3556 if (ms->ms_client_seq != NULL) {
3559 OBD_ALLOC(prefix, MAX_OBD_NAME + 5);
3563 snprintf(prefix, MAX_OBD_NAME + 5, "ctl-%s",
3566 rc = seq_client_init(ms->ms_client_seq,
3568 LUSTRE_SEQ_METADATA,
3570 OBD_FREE(prefix, MAX_OBD_NAME + 5);
3577 LASSERT(ms->ms_server_seq != NULL);
3578 rc = seq_server_set_cli(ms->ms_server_seq, ms->ms_client_seq,
3585 static void mdt_seq_fini_cli(struct mdt_device *m)
3591 ms = mdt_md_site(m);
3594 if (ms->ms_server_seq)
3595 seq_server_set_cli(ms->ms_server_seq,
3598 if (ms->ms_control_exp) {
3599 class_export_put(ms->ms_control_exp);
3600 ms->ms_control_exp = NULL;
3609 static int mdt_fld_fini(const struct lu_env *env,
3610 struct mdt_device *m)
3612 struct md_site *ms = mdt_md_site(m);
3615 if (ms && ms->ms_server_fld) {
3616 fld_server_fini(ms->ms_server_fld, env);
3617 OBD_FREE_PTR(ms->ms_server_fld);
3618 ms->ms_server_fld = NULL;
3624 static int mdt_fld_init(const struct lu_env *env,
3626 struct mdt_device *m)
3632 ms = mdt_md_site(m);
3634 OBD_ALLOC_PTR(ms->ms_server_fld);
3635 if (ms->ms_server_fld == NULL)
3636 RETURN(rc = -ENOMEM);
3638 rc = fld_server_init(ms->ms_server_fld,
3639 m->mdt_bottom, uuid,
3640 env, ms->ms_node_id);
3642 OBD_FREE_PTR(ms->ms_server_fld);
3643 ms->ms_server_fld = NULL;
3650 /* device init/fini methods */
3651 static void mdt_stop_ptlrpc_service(struct mdt_device *m)
3654 if (m->mdt_regular_service != NULL) {
3655 ptlrpc_unregister_service(m->mdt_regular_service);
3656 m->mdt_regular_service = NULL;
3658 if (m->mdt_readpage_service != NULL) {
3659 ptlrpc_unregister_service(m->mdt_readpage_service);
3660 m->mdt_readpage_service = NULL;
3662 if (m->mdt_xmds_service != NULL) {
3663 ptlrpc_unregister_service(m->mdt_xmds_service);
3664 m->mdt_xmds_service = NULL;
3666 if (m->mdt_setattr_service != NULL) {
3667 ptlrpc_unregister_service(m->mdt_setattr_service);
3668 m->mdt_setattr_service = NULL;
3670 if (m->mdt_mdsc_service != NULL) {
3671 ptlrpc_unregister_service(m->mdt_mdsc_service);
3672 m->mdt_mdsc_service = NULL;
3674 if (m->mdt_mdss_service != NULL) {
3675 ptlrpc_unregister_service(m->mdt_mdss_service);
3676 m->mdt_mdss_service = NULL;
3678 if (m->mdt_dtss_service != NULL) {
3679 ptlrpc_unregister_service(m->mdt_dtss_service);
3680 m->mdt_dtss_service = NULL;
3682 if (m->mdt_fld_service != NULL) {
3683 ptlrpc_unregister_service(m->mdt_fld_service);
3684 m->mdt_fld_service = NULL;
3689 static int mdt_start_ptlrpc_service(struct mdt_device *m)
3692 static struct ptlrpc_service_conf conf;
3693 cfs_proc_dir_entry_t *procfs_entry;
3696 procfs_entry = m->mdt_md_dev.md_lu_dev.ld_obd->obd_proc_entry;
3698 conf = (typeof(conf)) {
3699 .psc_nbufs = MDS_NBUFS,
3700 .psc_bufsize = MDS_BUFSIZE,
3701 .psc_max_req_size = MDS_MAXREQSIZE,
3702 .psc_max_reply_size = MDS_MAXREPSIZE,
3703 .psc_req_portal = MDS_REQUEST_PORTAL,
3704 .psc_rep_portal = MDC_REPLY_PORTAL,
3705 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
3707 * We'd like to have a mechanism to set this on a per-device
3708 * basis, but alas...
3710 .psc_min_threads = min(max(mdt_num_threads, MDT_MIN_THREADS),
3712 .psc_max_threads = MDT_MAX_THREADS,
3713 .psc_ctx_tags = LCT_MD_THREAD
3716 m->mdt_ldlm_client = &m->mdt_md_dev.md_lu_dev.ld_obd->obd_ldlm_client;
3717 ptlrpc_init_client(LDLM_CB_REQUEST_PORTAL, LDLM_CB_REPLY_PORTAL,
3718 "mdt_ldlm_client", m->mdt_ldlm_client);
3720 m->mdt_regular_service =
3721 ptlrpc_init_svc_conf(&conf, mdt_regular_handle, LUSTRE_MDT_NAME,
3722 procfs_entry, target_print_req,
3724 if (m->mdt_regular_service == NULL)
3727 rc = ptlrpc_start_threads(NULL, m->mdt_regular_service);
3729 GOTO(err_mdt_svc, rc);
3732 * readpage service configuration. Parameters have to be adjusted,
3735 conf = (typeof(conf)) {
3736 .psc_nbufs = MDS_NBUFS,
3737 .psc_bufsize = MDS_BUFSIZE,
3738 .psc_max_req_size = MDS_MAXREQSIZE,
3739 .psc_max_reply_size = MDS_MAXREPSIZE,
3740 .psc_req_portal = MDS_READPAGE_PORTAL,
3741 .psc_rep_portal = MDC_REPLY_PORTAL,
3742 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
3743 .psc_min_threads = min(max(mdt_num_threads, MDT_MIN_THREADS),
3745 .psc_max_threads = MDT_MAX_THREADS,
3746 .psc_ctx_tags = LCT_MD_THREAD
3748 m->mdt_readpage_service =
3749 ptlrpc_init_svc_conf(&conf, mdt_readpage_handle,
3750 LUSTRE_MDT_NAME "_readpage",
3751 procfs_entry, target_print_req,"mdt_rdpg");
3753 if (m->mdt_readpage_service == NULL) {
3754 CERROR("failed to start readpage service\n");
3755 GOTO(err_mdt_svc, rc = -ENOMEM);
3758 rc = ptlrpc_start_threads(NULL, m->mdt_readpage_service);
3761 * setattr service configuration.
3763 conf = (typeof(conf)) {
3764 .psc_nbufs = MDS_NBUFS,
3765 .psc_bufsize = MDS_BUFSIZE,
3766 .psc_max_req_size = MDS_MAXREQSIZE,
3767 .psc_max_reply_size = MDS_MAXREPSIZE,
3768 .psc_req_portal = MDS_SETATTR_PORTAL,
3769 .psc_rep_portal = MDC_REPLY_PORTAL,
3770 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
3771 .psc_min_threads = min(max(mdt_num_threads, MDT_MIN_THREADS),
3773 .psc_max_threads = MDT_MAX_THREADS,
3774 .psc_ctx_tags = LCT_MD_THREAD
3777 m->mdt_setattr_service =
3778 ptlrpc_init_svc_conf(&conf, mdt_regular_handle,
3779 LUSTRE_MDT_NAME "_setattr",
3780 procfs_entry, target_print_req,"mdt_attr");
3782 if (!m->mdt_setattr_service) {
3783 CERROR("failed to start setattr service\n");
3784 GOTO(err_mdt_svc, rc = -ENOMEM);
3787 rc = ptlrpc_start_threads(NULL, m->mdt_setattr_service);
3789 GOTO(err_mdt_svc, rc);
3792 * sequence controller service configuration
3794 conf = (typeof(conf)) {
3795 .psc_nbufs = MDS_NBUFS,
3796 .psc_bufsize = MDS_BUFSIZE,
3797 .psc_max_req_size = SEQ_MAXREQSIZE,
3798 .psc_max_reply_size = SEQ_MAXREPSIZE,
3799 .psc_req_portal = SEQ_CONTROLLER_PORTAL,
3800 .psc_rep_portal = MDC_REPLY_PORTAL,
3801 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
3802 .psc_min_threads = SEQ_NUM_THREADS,
3803 .psc_max_threads = SEQ_NUM_THREADS,
3804 .psc_ctx_tags = LCT_MD_THREAD|LCT_DT_THREAD
3807 m->mdt_mdsc_service =
3808 ptlrpc_init_svc_conf(&conf, mdt_mdsc_handle,
3809 LUSTRE_MDT_NAME"_mdsc",
3810 procfs_entry, target_print_req,"mdt_mdsc");
3811 if (!m->mdt_mdsc_service) {
3812 CERROR("failed to start seq controller service\n");
3813 GOTO(err_mdt_svc, rc = -ENOMEM);
3816 rc = ptlrpc_start_threads(NULL, m->mdt_mdsc_service);
3818 GOTO(err_mdt_svc, rc);
3821 * metadata sequence server service configuration
3823 conf = (typeof(conf)) {
3824 .psc_nbufs = MDS_NBUFS,
3825 .psc_bufsize = MDS_BUFSIZE,
3826 .psc_max_req_size = SEQ_MAXREQSIZE,
3827 .psc_max_reply_size = SEQ_MAXREPSIZE,
3828 .psc_req_portal = SEQ_METADATA_PORTAL,
3829 .psc_rep_portal = MDC_REPLY_PORTAL,
3830 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
3831 .psc_min_threads = SEQ_NUM_THREADS,
3832 .psc_max_threads = SEQ_NUM_THREADS,
3833 .psc_ctx_tags = LCT_MD_THREAD|LCT_DT_THREAD
3836 m->mdt_mdss_service =
3837 ptlrpc_init_svc_conf(&conf, mdt_mdss_handle,
3838 LUSTRE_MDT_NAME"_mdss",
3839 procfs_entry, target_print_req,"mdt_mdss");
3840 if (!m->mdt_mdss_service) {
3841 CERROR("failed to start metadata seq server service\n");
3842 GOTO(err_mdt_svc, rc = -ENOMEM);
3845 rc = ptlrpc_start_threads(NULL, m->mdt_mdss_service);
3847 GOTO(err_mdt_svc, rc);
3851 * Data sequence server service configuration. We want to have really
3852 * cluster-wide sequences space. This is why we start only one sequence
3853 * controller which manages space.
3855 conf = (typeof(conf)) {
3856 .psc_nbufs = MDS_NBUFS,
3857 .psc_bufsize = MDS_BUFSIZE,
3858 .psc_max_req_size = SEQ_MAXREQSIZE,
3859 .psc_max_reply_size = SEQ_MAXREPSIZE,
3860 .psc_req_portal = SEQ_DATA_PORTAL,
3861 .psc_rep_portal = OSC_REPLY_PORTAL,
3862 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
3863 .psc_min_threads = SEQ_NUM_THREADS,
3864 .psc_max_threads = SEQ_NUM_THREADS,
3865 .psc_ctx_tags = LCT_MD_THREAD|LCT_DT_THREAD
3868 m->mdt_dtss_service =
3869 ptlrpc_init_svc_conf(&conf, mdt_dtss_handle,
3870 LUSTRE_MDT_NAME"_dtss",
3871 procfs_entry, target_print_req,"mdt_dtss");
3872 if (!m->mdt_dtss_service) {
3873 CERROR("failed to start data seq server service\n");
3874 GOTO(err_mdt_svc, rc = -ENOMEM);
3877 rc = ptlrpc_start_threads(NULL, m->mdt_dtss_service);
3879 GOTO(err_mdt_svc, rc);
3881 /* FLD service start */
3882 conf = (typeof(conf)) {
3883 .psc_nbufs = MDS_NBUFS,
3884 .psc_bufsize = MDS_BUFSIZE,
3885 .psc_max_req_size = FLD_MAXREQSIZE,
3886 .psc_max_reply_size = FLD_MAXREPSIZE,
3887 .psc_req_portal = FLD_REQUEST_PORTAL,
3888 .psc_rep_portal = MDC_REPLY_PORTAL,
3889 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
3890 .psc_min_threads = FLD_NUM_THREADS,
3891 .psc_max_threads = FLD_NUM_THREADS,
3892 .psc_ctx_tags = LCT_DT_THREAD|LCT_MD_THREAD
3895 m->mdt_fld_service =
3896 ptlrpc_init_svc_conf(&conf, mdt_fld_handle,
3897 LUSTRE_MDT_NAME"_fld",
3898 procfs_entry, target_print_req, "mdt_fld");
3899 if (!m->mdt_fld_service) {
3900 CERROR("failed to start fld service\n");
3901 GOTO(err_mdt_svc, rc = -ENOMEM);
3904 rc = ptlrpc_start_threads(NULL, m->mdt_fld_service);
3906 GOTO(err_mdt_svc, rc);
3909 * mds-mds service configuration. Separate portal is used to allow
3910 * mds-mds requests be not blocked during recovery.
3912 conf = (typeof(conf)) {
3913 .psc_nbufs = MDS_NBUFS,
3914 .psc_bufsize = MDS_BUFSIZE,
3915 .psc_max_req_size = MDS_MAXREQSIZE,
3916 .psc_max_reply_size = MDS_MAXREPSIZE,
3917 .psc_req_portal = MDS_MDS_PORTAL,
3918 .psc_rep_portal = MDC_REPLY_PORTAL,
3919 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
3920 .psc_min_threads = min(max(mdt_num_threads, MDT_MIN_THREADS),
3922 .psc_max_threads = MDT_MAX_THREADS,
3923 .psc_ctx_tags = LCT_MD_THREAD
3925 m->mdt_xmds_service =
3926 ptlrpc_init_svc_conf(&conf, mdt_xmds_handle,
3927 LUSTRE_MDT_NAME "_mds",
3928 procfs_entry, target_print_req,"mdt_xmds");
3930 if (m->mdt_xmds_service == NULL) {
3931 CERROR("failed to start readpage service\n");
3932 GOTO(err_mdt_svc, rc = -ENOMEM);
3935 rc = ptlrpc_start_threads(NULL, m->mdt_xmds_service);
3937 GOTO(err_mdt_svc, rc);
3942 mdt_stop_ptlrpc_service(m);
3947 static void mdt_stack_fini(const struct lu_env *env,
3948 struct mdt_device *m, struct lu_device *top)
3950 struct obd_device *obd = mdt2obd_dev(m);
3951 struct lustre_cfg_bufs *bufs;
3952 struct lustre_cfg *lcfg;
3953 struct mdt_thread_info *info;
3957 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
3958 LASSERT(info != NULL);
3960 bufs = &info->mti_u.bufs;
3961 /* process cleanup, pass mdt obd name to get obd umount flags */
3962 lustre_cfg_bufs_reset(bufs, obd->obd_name);
3967 lustre_cfg_bufs_set_string(bufs, 1, flags);
3968 lcfg = lustre_cfg_new(LCFG_CLEANUP, bufs);
3970 CERROR("Cannot alloc lcfg!\n");
3975 top->ld_ops->ldo_process_config(env, top, lcfg);
3976 lustre_cfg_free(lcfg);
3978 lu_stack_fini(env, top);
3979 m->mdt_child = NULL;
3980 m->mdt_bottom = NULL;
3983 static struct lu_device *mdt_layer_setup(struct lu_env *env,
3984 const char *typename,
3985 struct lu_device *child,
3986 struct lustre_cfg *cfg)
3988 const char *dev = lustre_cfg_string(cfg, 0);
3989 struct obd_type *type;
3990 struct lu_device_type *ldt;
3991 struct lu_device *d;
3996 type = class_get_type(typename);
3998 CERROR("Unknown type: '%s'\n", typename);
3999 GOTO(out, rc = -ENODEV);
4002 rc = lu_env_refill((struct lu_env *)env);
4004 CERROR("Failure to refill session: '%d'\n", rc);
4010 CERROR("type: '%s'\n", typename);
4011 GOTO(out_type, rc = -EINVAL);
4014 ldt->ldt_obd_type = type;
4015 d = ldt->ldt_ops->ldto_device_alloc(env, ldt, cfg);
4017 CERROR("Cannot allocate device: '%s'\n", typename);
4018 GOTO(out_type, rc = -ENODEV);
4021 LASSERT(child->ld_site);
4022 d->ld_site = child->ld_site;
4025 rc = ldt->ldt_ops->ldto_device_init(env, d, dev, child);
4027 CERROR("can't init device '%s', rc %d\n", typename, rc);
4028 GOTO(out_alloc, rc);
4031 lu_ref_add(&d->ld_reference, "lu-stack", &lu_site_init);
4036 ldt->ldt_ops->ldto_device_free(env, d);
4039 class_put_type(type);
4044 static int mdt_stack_init(struct lu_env *env,
4045 struct mdt_device *m,
4046 struct lustre_cfg *cfg,
4047 struct lustre_mount_info *lmi)
4049 struct lu_device *d = &m->mdt_md_dev.md_lu_dev;
4050 struct lu_device *tmp;
4051 struct md_device *md;
4052 struct lu_device *child_lu_dev;
4056 /* init the stack */
4057 tmp = mdt_layer_setup(env, LUSTRE_OSD_NAME, d, cfg);
4059 RETURN(PTR_ERR(tmp));
4061 m->mdt_bottom = lu2dt_dev(tmp);
4063 tmp = mdt_layer_setup(env, LUSTRE_MDD_NAME, d, cfg);
4065 GOTO(out, rc = PTR_ERR(tmp));
4070 tmp = mdt_layer_setup(env, LUSTRE_CMM_NAME, d, cfg);
4072 GOTO(out, rc = PTR_ERR(tmp));
4075 /*set mdd upcall device*/
4076 md_upcall_dev_set(md, lu2md_dev(d));
4079 /*set cmm upcall device*/
4080 md_upcall_dev_set(md, &m->mdt_md_dev);
4082 m->mdt_child = lu2md_dev(d);
4084 /* process setup config */
4085 tmp = &m->mdt_md_dev.md_lu_dev;
4086 rc = tmp->ld_ops->ldo_process_config(env, tmp, cfg);
4090 /* initialize local objects */
4091 child_lu_dev = &m->mdt_child->md_lu_dev;
4093 rc = child_lu_dev->ld_ops->ldo_prepare(env,
4094 &m->mdt_md_dev.md_lu_dev,
4097 /* fini from last known good lu_device */
4099 mdt_stack_fini(env, m, d);
4105 * setup CONFIG_ORIG context, used to access local config log.
4106 * this may need to be rewrite as part of llog rewrite for lu-api.
4108 static int mdt_obd_llog_setup(struct obd_device *obd,
4109 struct lustre_sb_info *lsi)
4113 LASSERT(obd->obd_fsops == NULL);
4115 obd->obd_fsops = fsfilt_get_ops(MT_STR(lsi->lsi_ldd));
4116 if (IS_ERR(obd->obd_fsops))
4117 return (int) PTR_ERR(obd->obd_fsops);
4119 rc = fsfilt_setup(obd, lsi->lsi_srv_mnt->mnt_sb);
4121 fsfilt_put_ops(obd->obd_fsops);
4125 OBD_SET_CTXT_MAGIC(&obd->obd_lvfs_ctxt);
4126 obd->obd_lvfs_ctxt.pwdmnt = lsi->lsi_srv_mnt;
4127 obd->obd_lvfs_ctxt.pwd = lsi->lsi_srv_mnt->mnt_root;
4128 obd->obd_lvfs_ctxt.fs = get_ds();
4130 rc = llog_setup(obd, &obd->obd_olg, LLOG_CONFIG_ORIG_CTXT, obd,
4131 0, NULL, &llog_lvfs_ops);
4133 CERROR("llog setup failed: %d\n", rc);
4134 fsfilt_put_ops(obd->obd_fsops);
4140 static void mdt_obd_llog_cleanup(struct obd_device *obd)
4142 struct llog_ctxt *ctxt;
4144 ctxt = llog_get_context(obd, LLOG_CONFIG_ORIG_CTXT);
4149 fsfilt_put_ops(obd->obd_fsops);
4152 static void mdt_fini(const struct lu_env *env, struct mdt_device *m)
4154 struct md_device *next = m->mdt_child;
4155 struct lu_device *d = &m->mdt_md_dev.md_lu_dev;
4156 struct lu_site *ls = d->ld_site;
4157 struct obd_device *obd = mdt2obd_dev(m);
4161 /* At this point, obd exports might still be on the "obd_zombie_exports"
4162 * list, and obd_zombie_impexp_thread() is trying to destroy them.
4163 * We wait a little bit until all exports (except the self-export)
4164 * have been destroyed, because the whole mdt stack might be accessed
4165 * in mdt_destroy_export(). This will not be a long time, maybe one or
4166 * two seconds are enough. This is not a problem while umounting.
4168 * The three references that should be remaining are the
4169 * obd_self_export and the attach and setup references.
4171 while (atomic_read(&obd->obd_refcount) > 3) {
4172 cfs_schedule_timeout(CFS_TASK_UNINT, cfs_time_seconds(1));
4174 if (waited > 5 && IS_PO2(waited))
4175 LCONSOLE_WARN("Waiting for obd_zombie_impexp_thread "
4176 "more than %d seconds to destroy all "
4177 "the exports. The current obd refcount ="
4178 " %d. Is it stuck there?\n",
4179 waited, atomic_read(&obd->obd_refcount));
4182 ping_evictor_stop();
4184 target_recovery_fini(obd);
4185 mdt_stop_ptlrpc_service(m);
4186 mdt_obd_llog_cleanup(obd);
4187 obd_zombie_barrier();
4188 #ifdef HAVE_QUOTA_SUPPORT
4189 next->md_ops->mdo_quota.mqo_cleanup(env, next);
4191 mdt_fs_cleanup(env, m);
4192 upcall_cache_cleanup(m->mdt_identity_cache);
4193 m->mdt_identity_cache = NULL;
4195 if (m->mdt_namespace != NULL) {
4196 ldlm_namespace_free(m->mdt_namespace, NULL, d->ld_obd->obd_force);
4197 d->ld_obd->obd_namespace = m->mdt_namespace = NULL;
4200 cfs_free_nidlist(&m->mdt_nosquash_nids);
4201 if (m->mdt_nosquash_str) {
4202 OBD_FREE(m->mdt_nosquash_str, m->mdt_nosquash_strlen);
4203 m->mdt_nosquash_str = NULL;
4204 m->mdt_nosquash_strlen = 0;
4207 mdt_seq_fini(env, m);
4208 mdt_seq_fini_cli(m);
4209 mdt_fld_fini(env, m);
4211 lprocfs_remove_proc_entry("clear", obd->obd_proc_exports_entry);
4212 lprocfs_free_per_client_stats(obd);
4213 lprocfs_free_obd_stats(obd);
4214 ptlrpc_lprocfs_unregister_obd(d->ld_obd);
4215 lprocfs_obd_cleanup(d->ld_obd);
4217 sptlrpc_rule_set_free(&m->mdt_sptlrpc_rset);
4219 next->md_ops->mdo_init_capa_ctxt(env, next, 0, 0, 0, NULL);
4220 cfs_timer_disarm(&m->mdt_ck_timer);
4221 mdt_ck_thread_stop(m);
4223 /* finish the stack */
4224 mdt_stack_fini(env, m, md2lu_dev(m->mdt_child));
4227 struct md_site *mite;
4230 mite = lu_site2md(ls);
4234 LASSERT(atomic_read(&d->ld_ref) == 0);
4239 static int mdt_adapt_sptlrpc_conf(struct obd_device *obd, int initial)
4241 struct mdt_device *m = mdt_dev(obd->obd_lu_dev);
4242 struct sptlrpc_rule_set tmp_rset;
4245 sptlrpc_rule_set_init(&tmp_rset);
4246 rc = sptlrpc_conf_target_get_rules(obd, &tmp_rset, initial);
4248 CERROR("mdt %s: failed get sptlrpc rules: %d\n",
4253 sptlrpc_target_update_exp_flavor(obd, &tmp_rset);
4255 write_lock(&m->mdt_sptlrpc_lock);
4256 sptlrpc_rule_set_free(&m->mdt_sptlrpc_rset);
4257 m->mdt_sptlrpc_rset = tmp_rset;
4258 write_unlock(&m->mdt_sptlrpc_lock);
4263 static void fsoptions_to_mdt_flags(struct mdt_device *m, char *options)
4267 m->mdt_opts.mo_mds_capa = 1;
4268 m->mdt_opts.mo_oss_capa = 1;
4269 #ifdef CONFIG_FS_POSIX_ACL
4270 /* ACLs should be enabled by default (b=13829) */
4271 m->mdt_opts.mo_acl = 1;
4272 LCONSOLE_INFO("Enabling ACL\n");
4274 m->mdt_opts.mo_acl = 0;
4275 LCONSOLE_INFO("Disabling ACL\n");
4284 while (*p && *p != ',')
4288 if ((len == sizeof("user_xattr") - 1) &&
4289 (memcmp(options, "user_xattr", len) == 0)) {
4290 m->mdt_opts.mo_user_xattr = 1;
4291 LCONSOLE_INFO("Enabling user_xattr\n");
4292 } else if ((len == sizeof("nouser_xattr") - 1) &&
4293 (memcmp(options, "nouser_xattr", len) == 0)) {
4294 m->mdt_opts.mo_user_xattr = 0;
4295 LCONSOLE_INFO("Disabling user_xattr\n");
4296 } else if ((len == sizeof("noacl") - 1) &&
4297 (memcmp(options, "noacl", len) == 0)) {
4298 m->mdt_opts.mo_acl = 0;
4299 LCONSOLE_INFO("Disabling ACL\n");
4306 int mdt_postrecov(const struct lu_env *, struct mdt_device *);
4308 static int mdt_init0(const struct lu_env *env, struct mdt_device *m,
4309 struct lu_device_type *ldt, struct lustre_cfg *cfg)
4311 struct lprocfs_static_vars lvars;
4312 struct mdt_thread_info *info;
4313 struct obd_device *obd;
4314 const char *dev = lustre_cfg_string(cfg, 0);
4315 const char *num = lustre_cfg_string(cfg, 2);
4316 struct lustre_mount_info *lmi = NULL;
4317 struct lustre_sb_info *lsi;
4318 struct lustre_disk_data *ldd;
4320 struct md_site *mite;
4321 const char *identity_upcall = "NONE";
4322 #ifdef HAVE_QUOTA_SUPPORT
4323 struct md_device *next;
4329 md_device_init(&m->mdt_md_dev, ldt);
4331 * Environment (env) might be missing mdt_thread_key values at that
4332 * point, if device is allocated when mdt_thread_key is in QUIESCENT
4335 * Usually device allocation path doesn't use module key values, but
4336 * mdt has to do a lot of work here, so allocate key value.
4338 rc = lu_env_refill((struct lu_env *)env);
4342 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
4343 LASSERT(info != NULL);
4345 obd = class_name2obd(dev);
4346 LASSERT(obd != NULL);
4348 spin_lock_init(&m->mdt_transno_lock);
4350 m->mdt_max_mdsize = MAX_MD_SIZE;
4351 m->mdt_max_cookiesize = sizeof(struct llog_cookie);
4353 m->mdt_opts.mo_user_xattr = 0;
4354 m->mdt_opts.mo_acl = 0;
4355 m->mdt_opts.mo_cos = MDT_COS_DEFAULT;
4356 lmi = server_get_mount_2(dev);
4358 CERROR("Cannot get mount info for %s!\n", dev);
4361 lsi = s2lsi(lmi->lmi_sb);
4362 fsoptions_to_mdt_flags(m, lsi->lsi_lmd->lmd_opts);
4363 /* CMD is supported only in IAM mode */
4366 node_id = simple_strtol(num, NULL, 10);
4367 if (!(ldd->ldd_flags & LDD_F_IAM_DIR) && node_id) {
4368 CERROR("CMD Operation not allowed in IOP mode\n");
4369 GOTO(err_lmi, rc = -EINVAL);
4373 rwlock_init(&m->mdt_sptlrpc_lock);
4374 sptlrpc_rule_set_init(&m->mdt_sptlrpc_rset);
4376 spin_lock_init(&m->mdt_ioepoch_lock);
4377 m->mdt_opts.mo_compat_resname = 0;
4378 m->mdt_capa_timeout = CAPA_TIMEOUT;
4379 m->mdt_capa_alg = CAPA_HMAC_ALG_SHA1;
4380 m->mdt_ck_timeout = CAPA_KEY_TIMEOUT;
4381 m->mdt_squash_uid = 0;
4382 m->mdt_squash_gid = 0;
4383 CFS_INIT_LIST_HEAD(&m->mdt_nosquash_nids);
4384 m->mdt_nosquash_str = NULL;
4385 m->mdt_nosquash_strlen = 0;
4386 init_rwsem(&m->mdt_squash_sem);
4388 spin_lock_init(&m->mdt_client_bitmap_lock);
4390 OBD_ALLOC_PTR(mite);
4392 GOTO(err_lmi, rc = -ENOMEM);
4396 m->mdt_md_dev.md_lu_dev.ld_ops = &mdt_lu_ops;
4397 m->mdt_md_dev.md_lu_dev.ld_obd = obd;
4398 /* set this lu_device to obd, because error handling need it */
4399 obd->obd_lu_dev = &m->mdt_md_dev.md_lu_dev;
4401 rc = lu_site_init(s, &m->mdt_md_dev.md_lu_dev);
4403 CERROR("Can't init lu_site, rc %d\n", rc);
4404 GOTO(err_free_site, rc);
4407 lprocfs_mdt_init_vars(&lvars);
4408 rc = lprocfs_obd_setup(obd, lvars.obd_vars);
4410 CERROR("Can't init lprocfs, rc %d\n", rc);
4411 GOTO(err_fini_site, rc);
4413 ptlrpc_lprocfs_register_obd(obd);
4415 rc = mdt_procfs_init(m, dev);
4417 CERROR("Can't init MDT lprocfs, rc %d\n", rc);
4418 GOTO(err_fini_proc, rc);
4421 obd->obd_proc_exports_entry = proc_mkdir("exports",
4422 obd->obd_proc_entry);
4423 if (obd->obd_proc_exports_entry)
4424 lprocfs_add_simple(obd->obd_proc_exports_entry,
4425 "clear", lprocfs_nid_stats_clear_read,
4426 lprocfs_nid_stats_clear_write, obd, NULL);
4428 /* set server index */
4429 lu_site2md(s)->ms_node_id = node_id;
4431 /* failover is the default
4432 * FIXME: we do not failout mds0/mgs, which may cause some problems.
4433 * assumed whose ms_node_id == 0 XXX
4435 obd->obd_replayable = 1;
4436 /* No connection accepted until configurations will finish */
4437 obd->obd_no_conn = 1;
4439 if (cfg->lcfg_bufcount > 4 && LUSTRE_CFG_BUFLEN(cfg, 4) > 0) {
4440 char *str = lustre_cfg_string(cfg, 4);
4441 if (strchr(str, 'n')) {
4442 CWARN("%s: recovery disabled\n", obd->obd_name);
4443 obd->obd_replayable = 0;
4447 /* init the stack */
4448 rc = mdt_stack_init((struct lu_env *)env, m, cfg, lmi);
4450 CERROR("Can't init device stack, rc %d\n", rc);
4451 GOTO(err_fini_proc, rc);
4454 rc = mdt_fld_init(env, obd->obd_name, m);
4456 GOTO(err_fini_stack, rc);
4458 rc = mdt_seq_init(env, obd->obd_name, m);
4460 GOTO(err_fini_fld, rc);
4462 snprintf(info->mti_u.ns_name, sizeof info->mti_u.ns_name,
4463 LUSTRE_MDT_NAME"-%p", m);
4464 m->mdt_namespace = ldlm_namespace_new(obd, info->mti_u.ns_name,
4465 LDLM_NAMESPACE_SERVER,
4466 LDLM_NAMESPACE_GREEDY);
4467 if (m->mdt_namespace == NULL)
4468 GOTO(err_fini_seq, rc = -ENOMEM);
4470 ldlm_register_intent(m->mdt_namespace, mdt_intent_policy);
4471 /* set obd_namespace for compatibility with old code */
4472 obd->obd_namespace = m->mdt_namespace;
4474 /* XXX: to support suppgid for ACL, we enable identity_upcall
4475 * by default, otherwise, maybe got unexpected -EACCESS. */
4476 if (m->mdt_opts.mo_acl)
4477 identity_upcall = MDT_IDENTITY_UPCALL_PATH;
4479 m->mdt_identity_cache = upcall_cache_init(obd->obd_name, identity_upcall,
4480 &mdt_identity_upcall_cache_ops);
4481 if (IS_ERR(m->mdt_identity_cache)) {
4482 rc = PTR_ERR(m->mdt_identity_cache);
4483 m->mdt_identity_cache = NULL;
4484 GOTO(err_free_ns, rc);
4487 cfs_timer_init(&m->mdt_ck_timer, mdt_ck_timer_callback, m);
4489 rc = mdt_ck_thread_start(m);
4491 GOTO(err_free_ns, rc);
4493 rc = mdt_fs_setup(env, m, obd, lsi);
4497 rc = mdt_obd_llog_setup(obd, lsi);
4499 GOTO(err_fs_cleanup, rc);
4501 mdt_adapt_sptlrpc_conf(obd, 1);
4503 #ifdef HAVE_QUOTA_SUPPORT
4504 next = m->mdt_child;
4505 rc = next->md_ops->mdo_quota.mqo_setup(env, next, lmi->lmi_mnt);
4507 GOTO(err_llog_cleanup, rc);
4510 server_put_mount_2(dev, lmi->lmi_mnt);
4513 target_recovery_init(obd, mdt_recovery_handle);
4515 rc = mdt_start_ptlrpc_service(m);
4517 GOTO(err_recovery, rc);
4519 ping_evictor_start();
4521 rc = lu_site_init_finish(s);
4523 GOTO(err_stop_service, rc);
4525 if (obd->obd_recovering == 0)
4526 mdt_postrecov(env, m);
4528 mdt_init_capa_ctxt(env, m);
4530 /* Reduce the initial timeout on an MDS because it doesn't need such
4531 * a long timeout as an OST does. Adaptive timeouts will adjust this
4532 * value appropriately. */
4533 if (ldlm_timeout == LDLM_TIMEOUT_DEFAULT)
4534 ldlm_timeout = MDS_LDLM_TIMEOUT_DEFAULT;
4539 ping_evictor_stop();
4540 mdt_stop_ptlrpc_service(m);
4542 target_recovery_fini(obd);
4543 #ifdef HAVE_QUOTA_SUPPORT
4544 next->md_ops->mdo_quota.mqo_cleanup(env, next);
4547 mdt_obd_llog_cleanup(obd);
4549 mdt_fs_cleanup(env, m);
4551 cfs_timer_disarm(&m->mdt_ck_timer);
4552 mdt_ck_thread_stop(m);
4554 upcall_cache_cleanup(m->mdt_identity_cache);
4555 m->mdt_identity_cache = NULL;
4556 ldlm_namespace_free(m->mdt_namespace, NULL, 0);
4557 obd->obd_namespace = m->mdt_namespace = NULL;
4559 mdt_seq_fini(env, m);
4561 mdt_fld_fini(env, m);
4563 mdt_stack_fini(env, m, md2lu_dev(m->mdt_child));
4566 if (obd->obd_proc_exports_entry)
4567 lprocfs_remove_proc_entry("clear", obd->obd_proc_exports_entry);
4568 ptlrpc_lprocfs_unregister_obd(obd);
4569 lprocfs_obd_cleanup(obd);
4576 server_put_mount_2(dev, lmi->lmi_mnt);
4580 /* used by MGS to process specific configurations */
4581 static int mdt_process_config(const struct lu_env *env,
4582 struct lu_device *d, struct lustre_cfg *cfg)
4584 struct mdt_device *m = mdt_dev(d);
4585 struct md_device *md_next = m->mdt_child;
4586 struct lu_device *next = md2lu_dev(md_next);
4590 switch (cfg->lcfg_command) {
4592 struct lprocfs_static_vars lvars;
4593 struct obd_device *obd = d->ld_obd;
4596 * For interoperability between 1.8 and 2.0,
4597 * skip old "mdt.group_upcall" param.
4600 char *param = lustre_cfg_string(cfg, 1);
4601 if (param && !strncmp("mdt.group_upcall", param, 16)) {
4602 CWARN("For 1.8 interoperability, skip this"
4603 " mdt.group_upcall. It is obsolete\n");
4608 lprocfs_mdt_init_vars(&lvars);
4609 rc = class_process_proc_param(PARAM_MDT, lvars.obd_vars,
4611 if (rc > 0 || rc == -ENOSYS)
4612 /* we don't understand; pass it on */
4613 rc = next->ld_ops->ldo_process_config(env, next, cfg);
4618 * Add mdc hook to get first MDT uuid and connect it to
4619 * ls->controller to use for seq manager.
4621 rc = next->ld_ops->ldo_process_config(env, next, cfg);
4623 CERROR("Can't add mdc, rc %d\n", rc);
4625 rc = mdt_seq_init_cli(env, mdt_dev(d), cfg);
4628 /* others are passed further */
4629 rc = next->ld_ops->ldo_process_config(env, next, cfg);
4635 static struct lu_object *mdt_object_alloc(const struct lu_env *env,
4636 const struct lu_object_header *hdr,
4637 struct lu_device *d)
4639 struct mdt_object *mo;
4645 struct lu_object *o;
4646 struct lu_object_header *h;
4648 o = &mo->mot_obj.mo_lu;
4649 h = &mo->mot_header;
4650 lu_object_header_init(h);
4651 lu_object_init(o, h, d);
4652 lu_object_add_top(h, o);
4653 o->lo_ops = &mdt_obj_ops;
4659 static int mdt_object_init(const struct lu_env *env, struct lu_object *o,
4660 const struct lu_object_conf *_)
4662 struct mdt_device *d = mdt_dev(o->lo_dev);
4663 struct lu_device *under;
4664 struct lu_object *below;
4668 CDEBUG(D_INFO, "object init, fid = "DFID"\n",
4669 PFID(lu_object_fid(o)));
4671 under = &d->mdt_child->md_lu_dev;
4672 below = under->ld_ops->ldo_object_alloc(env, o->lo_header, under);
4673 if (below != NULL) {
4674 lu_object_add(o, below);
4681 static void mdt_object_free(const struct lu_env *env, struct lu_object *o)
4683 struct mdt_object *mo = mdt_obj(o);
4684 struct lu_object_header *h;
4688 CDEBUG(D_INFO, "object free, fid = "DFID"\n",
4689 PFID(lu_object_fid(o)));
4692 lu_object_header_fini(h);
4697 static const struct lu_device_operations mdt_lu_ops = {
4698 .ldo_object_alloc = mdt_object_alloc,
4699 .ldo_process_config = mdt_process_config,
4702 static const struct lu_object_operations mdt_obj_ops = {
4703 .loo_object_init = mdt_object_init,
4704 .loo_object_free = mdt_object_free
4707 static int mdt_obd_set_info_async(struct obd_export *exp,
4708 __u32 keylen, void *key,
4709 __u32 vallen, void *val,
4710 struct ptlrpc_request_set *set)
4712 struct obd_device *obd = exp->exp_obd;
4718 if (KEY_IS(KEY_SPTLRPC_CONF)) {
4719 rc = mdt_adapt_sptlrpc_conf(obd, 0);
4726 /* mds_connect_internal */
4727 static int mdt_connect_internal(struct obd_export *exp,
4728 struct mdt_device *mdt,
4729 struct obd_connect_data *data)
4732 data->ocd_connect_flags &= MDT_CONNECT_SUPPORTED;
4733 data->ocd_ibits_known &= MDS_INODELOCK_FULL;
4735 /* If no known bits (which should not happen, probably,
4736 as everybody should support LOOKUP and UPDATE bits at least)
4737 revert to compat mode with plain locks. */
4738 if (!data->ocd_ibits_known &&
4739 data->ocd_connect_flags & OBD_CONNECT_IBITS)
4740 data->ocd_connect_flags &= ~OBD_CONNECT_IBITS;
4742 if (!mdt->mdt_opts.mo_acl)
4743 data->ocd_connect_flags &= ~OBD_CONNECT_ACL;
4745 if (!mdt->mdt_opts.mo_user_xattr)
4746 data->ocd_connect_flags &= ~OBD_CONNECT_XATTR;
4748 spin_lock(&exp->exp_lock);
4749 exp->exp_connect_flags = data->ocd_connect_flags;
4750 spin_unlock(&exp->exp_lock);
4751 data->ocd_version = LUSTRE_VERSION_CODE;
4752 exp->exp_mdt_data.med_ibits_known = data->ocd_ibits_known;
4756 if (mdt->mdt_opts.mo_acl &&
4757 ((exp->exp_connect_flags & OBD_CONNECT_ACL) == 0)) {
4758 CWARN("%s: MDS requires ACL support but client does not\n",
4759 mdt->mdt_md_dev.md_lu_dev.ld_obd->obd_name);
4764 if ((exp->exp_connect_flags & OBD_CONNECT_FID) == 0) {
4765 CWARN("%s: MDS requires FID support, but client not\n",
4766 mdt->mdt_md_dev.md_lu_dev.ld_obd->obd_name);
4773 static int mdt_connect_check_sptlrpc(struct mdt_device *mdt,
4774 struct obd_export *exp,
4775 struct ptlrpc_request *req)
4777 struct sptlrpc_flavor flvr;
4780 if (exp->exp_flvr.sf_rpc == SPTLRPC_FLVR_INVALID) {
4781 read_lock(&mdt->mdt_sptlrpc_lock);
4782 sptlrpc_target_choose_flavor(&mdt->mdt_sptlrpc_rset,
4786 read_unlock(&mdt->mdt_sptlrpc_lock);
4788 spin_lock(&exp->exp_lock);
4790 exp->exp_sp_peer = req->rq_sp_from;
4791 exp->exp_flvr = flvr;
4793 if (exp->exp_flvr.sf_rpc != SPTLRPC_FLVR_ANY &&
4794 exp->exp_flvr.sf_rpc != req->rq_flvr.sf_rpc) {
4795 CERROR("unauthorized rpc flavor %x from %s, "
4796 "expect %x\n", req->rq_flvr.sf_rpc,
4797 libcfs_nid2str(req->rq_peer.nid),
4798 exp->exp_flvr.sf_rpc);
4802 spin_unlock(&exp->exp_lock);
4804 if (exp->exp_sp_peer != req->rq_sp_from) {
4805 CERROR("RPC source %s doesn't match %s\n",
4806 sptlrpc_part2name(req->rq_sp_from),
4807 sptlrpc_part2name(exp->exp_sp_peer));
4810 rc = sptlrpc_target_export_check(exp, req);
4817 /* mds_connect copy */
4818 static int mdt_obd_connect(const struct lu_env *env,
4819 struct lustre_handle *conn, struct obd_device *obd,
4820 struct obd_uuid *cluuid,
4821 struct obd_connect_data *data,
4824 struct mdt_thread_info *info;
4825 struct lsd_client_data *lcd;
4826 struct obd_export *exp;
4827 struct mdt_device *mdt;
4828 struct ptlrpc_request *req;
4832 LASSERT(env != NULL);
4833 if (!conn || !obd || !cluuid)
4836 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
4837 req = info->mti_pill->rc_req;
4838 mdt = mdt_dev(obd->obd_lu_dev);
4840 rc = class_connect(conn, obd, cluuid);
4844 exp = class_conn2export(conn);
4845 LASSERT(exp != NULL);
4847 rc = mdt_connect_check_sptlrpc(mdt, exp, req);
4851 rc = mdt_connect_internal(exp, mdt, data);
4855 struct mdt_thread_info *mti;
4856 mti = lu_context_key_get(&env->le_ctx,
4858 LASSERT(mti != NULL);
4860 memcpy(lcd->lcd_uuid, cluuid, sizeof lcd->lcd_uuid);
4861 exp->exp_mdt_data.med_lcd = lcd;
4862 rc = mdt_client_new(env, mdt);
4865 exp->exp_mdt_data.med_lcd = NULL;
4867 mdt_export_stats_init(obd, exp, localdata);
4875 class_disconnect(exp);
4877 class_export_put(exp);
4882 static int mdt_obd_reconnect(const struct lu_env *env,
4883 struct obd_export *exp, struct obd_device *obd,
4884 struct obd_uuid *cluuid,
4885 struct obd_connect_data *data,
4888 struct mdt_thread_info *info;
4889 struct mdt_device *mdt;
4890 struct ptlrpc_request *req;
4894 if (exp == NULL || obd == NULL || cluuid == NULL)
4897 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
4898 req = info->mti_pill->rc_req;
4899 mdt = mdt_dev(obd->obd_lu_dev);
4901 rc = mdt_connect_check_sptlrpc(mdt, exp, req);
4905 rc = mdt_connect_internal(exp, mdt_dev(obd->obd_lu_dev), data);
4907 mdt_export_stats_init(obd, exp, localdata);
4912 static int mdt_obd_disconnect(struct obd_export *exp)
4914 struct mdt_device *mdt = mdt_dev(exp->exp_obd->obd_lu_dev);
4919 class_export_get(exp);
4921 /* Disconnect early so that clients can't keep using export */
4922 rc = class_disconnect(exp);
4923 if (mdt->mdt_namespace != NULL || exp->exp_obd->obd_namespace != NULL)
4924 ldlm_cancel_locks_for_export(exp);
4926 /* release nid stat refererence */
4927 lprocfs_exp_cleanup(exp);
4929 /* complete all outstanding replies */
4930 spin_lock(&exp->exp_lock);
4931 while (!list_empty(&exp->exp_outstanding_replies)) {
4932 struct ptlrpc_reply_state *rs =
4933 list_entry(exp->exp_outstanding_replies.next,
4934 struct ptlrpc_reply_state, rs_exp_list);
4935 struct ptlrpc_service *svc = rs->rs_service;
4937 spin_lock(&svc->srv_lock);
4938 list_del_init(&rs->rs_exp_list);
4939 spin_lock(&rs->rs_lock);
4940 ptlrpc_schedule_difficult_reply(rs);
4941 spin_unlock(&rs->rs_lock);
4942 spin_unlock(&svc->srv_lock);
4944 spin_unlock(&exp->exp_lock);
4946 class_export_put(exp);
4950 /* FIXME: Can we avoid using these two interfaces? */
4951 static int mdt_init_export(struct obd_export *exp)
4953 struct mdt_export_data *med = &exp->exp_mdt_data;
4957 CFS_INIT_LIST_HEAD(&med->med_open_head);
4958 spin_lock_init(&med->med_open_lock);
4959 sema_init(&med->med_idmap_sem, 1);
4960 med->med_idmap = NULL;
4961 spin_lock(&exp->exp_lock);
4962 exp->exp_connecting = 1;
4963 spin_unlock(&exp->exp_lock);
4964 rc = ldlm_init_export(exp);
4966 CERROR("Error %d while initializing export\n", rc);
4970 static int mdt_destroy_export(struct obd_export *export)
4972 struct mdt_export_data *med;
4973 struct obd_device *obd = export->exp_obd;
4974 struct mdt_device *mdt;
4975 struct mdt_thread_info *info;
4980 CFS_LIST_HEAD(closing_list);
4981 struct mdt_file_data *mfd, *n;
4985 med = &export->exp_mdt_data;
4986 if (exp_connect_rmtclient(export))
4987 mdt_cleanup_idmap(med);
4989 target_destroy_export(export);
4990 ldlm_destroy_export(export);
4992 if (obd_uuid_equals(&export->exp_client_uuid, &obd->obd_uuid))
4995 mdt = mdt_dev(obd->obd_lu_dev);
4996 LASSERT(mdt != NULL);
4998 rc = lu_env_init(&env, LCT_MD_THREAD);
5002 info = lu_context_key_get(&env.le_ctx, &mdt_thread_key);
5003 LASSERT(info != NULL);
5004 memset(info, 0, sizeof *info);
5005 info->mti_env = &env;
5006 info->mti_mdt = mdt;
5007 info->mti_exp = export;
5009 ma = &info->mti_attr;
5010 lmm_size = ma->ma_lmm_size = mdt->mdt_max_mdsize;
5011 cookie_size = ma->ma_cookie_size = mdt->mdt_max_cookiesize;
5012 OBD_ALLOC(ma->ma_lmm, lmm_size);
5013 OBD_ALLOC(ma->ma_cookie, cookie_size);
5015 if (ma->ma_lmm == NULL || ma->ma_cookie == NULL)
5016 GOTO(out, rc = -ENOMEM);
5017 ma->ma_need = MA_LOV | MA_COOKIE;
5019 /* Close any open files (which may also cause orphan unlinking). */
5020 spin_lock(&med->med_open_lock);
5021 while (!list_empty(&med->med_open_head)) {
5022 struct list_head *tmp = med->med_open_head.next;
5023 mfd = list_entry(tmp, struct mdt_file_data, mfd_list);
5025 /* Remove mfd handle so it can't be found again.
5026 * We are consuming the mfd_list reference here. */
5027 class_handle_unhash(&mfd->mfd_handle);
5028 list_move_tail(&mfd->mfd_list, &closing_list);
5030 spin_unlock(&med->med_open_lock);
5032 list_for_each_entry_safe(mfd, n, &closing_list, mfd_list) {
5033 list_del_init(&mfd->mfd_list);
5034 mdt_mfd_close(info, mfd);
5035 /* TODO: if we close the unlinked file,
5036 * we need to remove its objects from OST */
5037 memset(&ma->ma_attr, 0, sizeof(ma->ma_attr));
5038 spin_lock(&med->med_open_lock);
5039 ma->ma_lmm_size = lmm_size;
5040 ma->ma_cookie_size = cookie_size;
5041 ma->ma_need = MA_LOV | MA_COOKIE;
5043 spin_unlock(&med->med_open_lock);
5046 info->mti_mdt = NULL;
5047 mdt_client_del(&env, mdt);
5052 OBD_FREE(ma->ma_lmm, lmm_size);
5056 OBD_FREE(ma->ma_cookie, cookie_size);
5057 ma->ma_cookie = NULL;
5064 static void mdt_allow_cli(struct mdt_device *m, unsigned int flag)
5066 if (flag & CONFIG_LOG)
5067 m->mdt_fl_cfglog = 1;
5069 /* also notify active event */
5070 if (flag & CONFIG_SYNC)
5071 m->mdt_fl_synced = 1;
5073 if (m->mdt_fl_cfglog && m->mdt_fl_synced)
5074 /* Open for clients */
5075 m->mdt_md_dev.md_lu_dev.ld_obd->obd_no_conn = 0;
5078 static int mdt_upcall(const struct lu_env *env, struct md_device *md,
5079 enum md_upcall_event ev)
5081 struct mdt_device *m = mdt_dev(&md->md_lu_dev);
5082 struct md_device *next = m->mdt_child;
5083 struct mdt_thread_info *mti;
5089 rc = next->md_ops->mdo_maxsize_get(env, next,
5091 &m->mdt_max_cookiesize);
5092 CDEBUG(D_INFO, "get max mdsize %d max cookiesize %d\n",
5093 m->mdt_max_mdsize, m->mdt_max_cookiesize);
5094 mdt_allow_cli(m, CONFIG_SYNC);
5095 #ifdef HAVE_QUOTA_SUPPORT
5096 if (md->md_lu_dev.ld_obd->obd_recovering == 0)
5097 next->md_ops->mdo_quota.mqo_recovery(env, next);
5101 mti = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
5102 mti->mti_no_need_trans = 1;
5103 CDEBUG(D_INFO, "disable mdt trans for this thread\n");
5106 /* Check that MDT is not yet configured */
5107 LASSERT(!m->mdt_fl_cfglog);
5110 CERROR("invalid event\n");
5117 static int mdt_obd_notify(struct obd_device *host,
5118 struct obd_device *watched,
5119 enum obd_notify_event ev, void *data)
5121 struct mdt_device *mdt = mdt_dev(host->obd_lu_dev);
5122 #ifdef HAVE_QUOTA_SUPPORT
5123 struct md_device *next = mdt->mdt_child;
5128 case OBD_NOTIFY_CONFIG:
5129 mdt_allow_cli(mdt, (unsigned long)data);
5131 #ifdef HAVE_QUOTA_SUPPORT
5132 /* quota_type has been processed, we can now handle
5133 * incoming quota requests */
5134 next->md_ops->mdo_quota.mqo_notify(NULL, next);
5138 CDEBUG(D_INFO, "Unhandled notification %#x\n", ev);
5143 static int mdt_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
5144 void *karg, void *uarg)
5147 struct obd_device *obd= exp->exp_obd;
5148 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
5149 struct dt_device *dt = mdt->mdt_bottom;
5153 CDEBUG(D_IOCTL, "handling ioctl cmd %#x\n", cmd);
5154 rc = lu_env_init(&env, LCT_MD_THREAD);
5160 rc = mdt_device_sync(&env, mdt);
5162 case OBD_IOC_SET_READONLY:
5163 dt->dd_ops->dt_ro(&env, dt);
5165 case OBD_IOC_ABORT_RECOVERY:
5166 CERROR("Aborting recovery for device %s\n", obd->obd_name);
5167 target_stop_recovery_thread(obd);
5171 CERROR("Not supported cmd = %d for device %s\n",
5172 cmd, obd->obd_name);
5180 int mdt_postrecov(const struct lu_env *env, struct mdt_device *mdt)
5182 struct lu_device *ld = md2lu_dev(mdt->mdt_child);
5183 struct obd_device *obd = mdt2obd_dev(mdt);
5184 #ifdef HAVE_QUOTA_SUPPORT
5185 struct md_device *next = mdt->mdt_child;
5189 /* if some clients didn't participate in recovery then we can possibly
5190 * lost sequence. Now we should increase sequence for safe value */
5191 lost = obd->obd_max_recoverable_clients - obd->obd_connected_clients;
5192 mdt_seq_adjust(env, mdt, lost);
5194 rc = ld->ld_ops->ldo_recovery_complete(env, ld);
5195 #ifdef HAVE_QUOTA_SUPPORT
5196 next->md_ops->mdo_quota.mqo_recovery(env, next);
5201 int mdt_obd_postrecov(struct obd_device *obd)
5206 rc = lu_env_init(&env, LCT_MD_THREAD);
5209 rc = mdt_postrecov(&env, mdt_dev(obd->obd_lu_dev));
5214 static struct obd_ops mdt_obd_device_ops = {
5215 .o_owner = THIS_MODULE,
5216 .o_set_info_async = mdt_obd_set_info_async,
5217 .o_connect = mdt_obd_connect,
5218 .o_reconnect = mdt_obd_reconnect,
5219 .o_disconnect = mdt_obd_disconnect,
5220 .o_init_export = mdt_init_export,
5221 .o_destroy_export = mdt_destroy_export,
5222 .o_iocontrol = mdt_iocontrol,
5223 .o_postrecov = mdt_obd_postrecov,
5224 .o_notify = mdt_obd_notify
5227 static struct lu_device* mdt_device_fini(const struct lu_env *env,
5228 struct lu_device *d)
5230 struct mdt_device *m = mdt_dev(d);
5237 static struct lu_device *mdt_device_free(const struct lu_env *env,
5238 struct lu_device *d)
5240 struct mdt_device *m = mdt_dev(d);
5243 md_device_fini(&m->mdt_md_dev);
5248 static struct lu_device *mdt_device_alloc(const struct lu_env *env,
5249 struct lu_device_type *t,
5250 struct lustre_cfg *cfg)
5252 struct lu_device *l;
5253 struct mdt_device *m;
5259 l = &m->mdt_md_dev.md_lu_dev;
5260 rc = mdt_init0(env, m, t, cfg);
5262 mdt_device_free(env, l);
5266 md_upcall_init(&m->mdt_md_dev, mdt_upcall);
5268 l = ERR_PTR(-ENOMEM);
5272 /* context key constructor/destructor: mdt_key_init, mdt_key_fini */
5273 LU_KEY_INIT_FINI(mdt, struct mdt_thread_info);
5275 /* context key: mdt_thread_key */
5276 LU_CONTEXT_KEY_DEFINE(mdt, LCT_MD_THREAD);
5278 /* context key constructor/destructor: mdt_txn_key_init, mdt_txn_key_fini */
5279 LU_KEY_INIT_FINI(mdt_txn, struct mdt_txn_info);
5281 struct lu_context_key mdt_txn_key = {
5282 .lct_tags = LCT_TX_HANDLE,
5283 .lct_init = mdt_txn_key_init,
5284 .lct_fini = mdt_txn_key_fini
5287 struct md_ucred *mdt_ucred(const struct mdt_thread_info *info)
5289 return md_ucred(info->mti_env);
5293 * Enable/disable COS.
5295 * Set/Clear the COS flag in mdt options.
5297 * \param mdt mdt device
5298 * \param val 0 disables COS, other values enable COS
5300 void mdt_enable_cos(struct mdt_device *mdt, int val)
5305 mdt->mdt_opts.mo_cos = !!val;
5306 rc = lu_env_init(&env, LCT_MD_THREAD);
5307 if (unlikely(rc != 0)) {
5308 CWARN("lu_env initialization failed with rc = %d,"
5309 "cannot sync\n", rc);
5312 mdt_device_sync(&env, mdt);
5319 * Return COS flag status/
5321 * \param mdt mdt device
5323 int mdt_cos_is_enabled(struct mdt_device *mdt)
5325 return mdt->mdt_opts.mo_cos != 0;
5328 /* type constructor/destructor: mdt_type_init, mdt_type_fini */
5329 LU_TYPE_INIT_FINI(mdt, &mdt_thread_key, &mdt_txn_key);
5331 static struct lu_device_type_operations mdt_device_type_ops = {
5332 .ldto_init = mdt_type_init,
5333 .ldto_fini = mdt_type_fini,
5335 .ldto_start = mdt_type_start,
5336 .ldto_stop = mdt_type_stop,
5338 .ldto_device_alloc = mdt_device_alloc,
5339 .ldto_device_free = mdt_device_free,
5340 .ldto_device_fini = mdt_device_fini
5343 static struct lu_device_type mdt_device_type = {
5344 .ldt_tags = LU_DEVICE_MD,
5345 .ldt_name = LUSTRE_MDT_NAME,
5346 .ldt_ops = &mdt_device_type_ops,
5347 .ldt_ctx_tags = LCT_MD_THREAD
5350 static struct lu_local_obj_desc mdt_last_recv = {
5351 .llod_name = LAST_RCVD,
5352 .llod_oid = MDT_LAST_RECV_OID,
5356 static int __init mdt_mod_init(void)
5358 struct lprocfs_static_vars lvars;
5361 llo_local_obj_register(&mdt_last_recv);
5363 mdt_num_threads = MDT_NUM_THREADS;
5364 lprocfs_mdt_init_vars(&lvars);
5365 rc = class_register_type(&mdt_obd_device_ops, NULL,
5366 lvars.module_vars, LUSTRE_MDT_NAME,
5372 static void __exit mdt_mod_exit(void)
5374 llo_local_obj_unregister(&mdt_last_recv);
5375 class_unregister_type(LUSTRE_MDT_NAME);
5379 #define DEF_HNDL(prefix, base, suffix, flags, opc, fn, fmt) \
5380 [prefix ## _ ## opc - prefix ## _ ## base] = { \
5382 .mh_fail_id = OBD_FAIL_ ## prefix ## _ ## opc ## suffix, \
5383 .mh_opc = prefix ## _ ## opc, \
5384 .mh_flags = flags, \
5389 #define DEF_MDT_HNDL(flags, name, fn, fmt) \
5390 DEF_HNDL(MDS, GETATTR, _NET, flags, name, fn, fmt)
5392 #define DEF_SEQ_HNDL(flags, name, fn, fmt) \
5393 DEF_HNDL(SEQ, QUERY, _NET, flags, name, fn, fmt)
5395 #define DEF_FLD_HNDL(flags, name, fn, fmt) \
5396 DEF_HNDL(FLD, QUERY, _NET, flags, name, fn, fmt)
5398 * Request with a format known in advance
5400 #define DEF_MDT_HNDL_F(flags, name, fn) \
5401 DEF_HNDL(MDS, GETATTR, _NET, flags, name, fn, &RQF_MDS_ ## name)
5403 #define DEF_SEQ_HNDL_F(flags, name, fn) \
5404 DEF_HNDL(SEQ, QUERY, _NET, flags, name, fn, &RQF_SEQ_ ## name)
5406 #define DEF_FLD_HNDL_F(flags, name, fn) \
5407 DEF_HNDL(FLD, QUERY, _NET, flags, name, fn, &RQF_FLD_ ## name)
5409 * Request with a format we do not yet know
5411 #define DEF_MDT_HNDL_0(flags, name, fn) \
5412 DEF_HNDL(MDS, GETATTR, _NET, flags, name, fn, NULL)
5414 static struct mdt_handler mdt_mds_ops[] = {
5415 DEF_MDT_HNDL_F(0, CONNECT, mdt_connect),
5416 DEF_MDT_HNDL_F(0, DISCONNECT, mdt_disconnect),
5417 DEF_MDT_HNDL_F(0, SET_INFO, mdt_set_info),
5418 DEF_MDT_HNDL_F(0 |HABEO_REFERO, GETSTATUS, mdt_getstatus),
5419 DEF_MDT_HNDL_F(HABEO_CORPUS, GETATTR, mdt_getattr),
5420 DEF_MDT_HNDL_F(HABEO_CORPUS|HABEO_REFERO, GETATTR_NAME, mdt_getattr_name),
5421 DEF_MDT_HNDL_F(HABEO_CORPUS, GETXATTR, mdt_getxattr),
5422 DEF_MDT_HNDL_F(0 |HABEO_REFERO, STATFS, mdt_statfs),
5423 DEF_MDT_HNDL_F(0 |MUTABOR, REINT, mdt_reint),
5424 DEF_MDT_HNDL_F(HABEO_CORPUS, CLOSE, mdt_close),
5425 DEF_MDT_HNDL_F(HABEO_CORPUS, DONE_WRITING, mdt_done_writing),
5426 DEF_MDT_HNDL_F(0 |HABEO_REFERO, PIN, mdt_pin),
5427 DEF_MDT_HNDL_0(0, SYNC, mdt_sync),
5428 DEF_MDT_HNDL_F(HABEO_CORPUS|HABEO_REFERO, IS_SUBDIR, mdt_is_subdir),
5429 #ifdef HAVE_QUOTA_SUPPORT
5430 DEF_MDT_HNDL_F(0, QUOTACHECK, mdt_quotacheck_handle),
5431 DEF_MDT_HNDL_F(0, QUOTACTL, mdt_quotactl_handle)
5435 #define DEF_OBD_HNDL(flags, name, fn) \
5436 DEF_HNDL(OBD, PING, _NET, flags, name, fn, NULL)
5439 static struct mdt_handler mdt_obd_ops[] = {
5440 DEF_OBD_HNDL(0, PING, mdt_obd_ping),
5441 DEF_OBD_HNDL(0, LOG_CANCEL, mdt_obd_log_cancel),
5442 DEF_OBD_HNDL(0, QC_CALLBACK, mdt_obd_qc_callback)
5445 #define DEF_DLM_HNDL_0(flags, name, fn) \
5446 DEF_HNDL(LDLM, ENQUEUE, , flags, name, fn, NULL)
5447 #define DEF_DLM_HNDL_F(flags, name, fn) \
5448 DEF_HNDL(LDLM, ENQUEUE, , flags, name, fn, &RQF_LDLM_ ## name)
5450 static struct mdt_handler mdt_dlm_ops[] = {
5451 DEF_DLM_HNDL_F(HABEO_CLAVIS, ENQUEUE, mdt_enqueue),
5452 DEF_DLM_HNDL_0(HABEO_CLAVIS, CONVERT, mdt_convert),
5453 DEF_DLM_HNDL_0(0, BL_CALLBACK, mdt_bl_callback),
5454 DEF_DLM_HNDL_0(0, CP_CALLBACK, mdt_cp_callback)
5457 static struct mdt_handler mdt_llog_ops[] = {
5460 #define DEF_SEC_CTX_HNDL(name, fn) \
5461 DEF_HNDL(SEC_CTX, INIT, _NET, 0, name, fn, NULL)
5463 static struct mdt_handler mdt_sec_ctx_ops[] = {
5464 DEF_SEC_CTX_HNDL(INIT, mdt_sec_ctx_handle),
5465 DEF_SEC_CTX_HNDL(INIT_CONT, mdt_sec_ctx_handle),
5466 DEF_SEC_CTX_HNDL(FINI, mdt_sec_ctx_handle)
5469 static struct mdt_opc_slice mdt_regular_handlers[] = {
5471 .mos_opc_start = MDS_GETATTR,
5472 .mos_opc_end = MDS_LAST_OPC,
5473 .mos_hs = mdt_mds_ops
5476 .mos_opc_start = OBD_PING,
5477 .mos_opc_end = OBD_LAST_OPC,
5478 .mos_hs = mdt_obd_ops
5481 .mos_opc_start = LDLM_ENQUEUE,
5482 .mos_opc_end = LDLM_LAST_OPC,
5483 .mos_hs = mdt_dlm_ops
5486 .mos_opc_start = LLOG_ORIGIN_HANDLE_CREATE,
5487 .mos_opc_end = LLOG_LAST_OPC,
5488 .mos_hs = mdt_llog_ops
5491 .mos_opc_start = SEC_CTX_INIT,
5492 .mos_opc_end = SEC_LAST_OPC,
5493 .mos_hs = mdt_sec_ctx_ops
5500 static struct mdt_handler mdt_readpage_ops[] = {
5501 DEF_MDT_HNDL_F(0, CONNECT, mdt_connect),
5502 DEF_MDT_HNDL_F(HABEO_CORPUS|HABEO_REFERO, READPAGE, mdt_readpage),
5503 #ifdef HAVE_SPLIT_SUPPORT
5504 DEF_MDT_HNDL_F(HABEO_CORPUS|HABEO_REFERO, WRITEPAGE, mdt_writepage),
5508 * XXX: this is ugly and should be fixed one day, see mdc_close() for
5509 * detailed comments. --umka
5511 DEF_MDT_HNDL_F(HABEO_CORPUS, CLOSE, mdt_close),
5512 DEF_MDT_HNDL_F(HABEO_CORPUS, DONE_WRITING, mdt_done_writing),
5515 static struct mdt_opc_slice mdt_readpage_handlers[] = {
5517 .mos_opc_start = MDS_GETATTR,
5518 .mos_opc_end = MDS_LAST_OPC,
5519 .mos_hs = mdt_readpage_ops
5526 static struct mdt_handler mdt_xmds_ops[] = {
5527 DEF_MDT_HNDL_F(0, CONNECT, mdt_connect),
5528 DEF_MDT_HNDL_F(HABEO_CORPUS , GETATTR, mdt_getattr),
5529 DEF_MDT_HNDL_F(0 | MUTABOR , REINT, mdt_reint),
5530 DEF_MDT_HNDL_F(HABEO_CORPUS|HABEO_REFERO, IS_SUBDIR, mdt_is_subdir),
5533 static struct mdt_opc_slice mdt_xmds_handlers[] = {
5535 .mos_opc_start = MDS_GETATTR,
5536 .mos_opc_end = MDS_LAST_OPC,
5537 .mos_hs = mdt_xmds_ops
5540 .mos_opc_start = OBD_PING,
5541 .mos_opc_end = OBD_LAST_OPC,
5542 .mos_hs = mdt_obd_ops
5545 .mos_opc_start = SEC_CTX_INIT,
5546 .mos_opc_end = SEC_LAST_OPC,
5547 .mos_hs = mdt_sec_ctx_ops
5554 static struct mdt_handler mdt_seq_ops[] = {
5555 DEF_SEQ_HNDL_F(0, QUERY, (int (*)(struct mdt_thread_info *))seq_query)
5558 static struct mdt_opc_slice mdt_seq_handlers[] = {
5560 .mos_opc_start = SEQ_QUERY,
5561 .mos_opc_end = SEQ_LAST_OPC,
5562 .mos_hs = mdt_seq_ops
5569 static struct mdt_handler mdt_fld_ops[] = {
5570 DEF_FLD_HNDL_F(0, QUERY, (int (*)(struct mdt_thread_info *))fld_query)
5573 static struct mdt_opc_slice mdt_fld_handlers[] = {
5575 .mos_opc_start = FLD_QUERY,
5576 .mos_opc_end = FLD_LAST_OPC,
5577 .mos_hs = mdt_fld_ops
5584 MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");
5585 MODULE_DESCRIPTION("Lustre Meta-data Target ("LUSTRE_MDT_NAME")");
5586 MODULE_LICENSE("GPL");
5588 CFS_MODULE_PARM(mdt_num_threads, "ul", ulong, 0444,
5589 "number of mdt service threads to start");
5591 cfs_module(mdt, "0.2.0", mdt_mod_init, mdt_mod_exit);