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 = sptlrpc_svc_wrap_bulk(req, desc);
1173 GOTO(free_desc, rc);
1175 rc = ptlrpc_start_bulk_transfer(desc);
1177 GOTO(free_desc, rc);
1179 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_SENDPAGE))
1180 GOTO(abort_bulk, rc = 0);
1182 timeout = (int) req->rq_deadline - cfs_time_current_sec();
1184 CERROR("Req deadline already passed %lu (now: %lu)\n",
1185 req->rq_deadline, cfs_time_current_sec());
1186 *lwi = LWI_TIMEOUT(cfs_time_seconds(max(timeout, 1)), NULL, NULL);
1187 rc = l_wait_event(desc->bd_waitq, !ptlrpc_server_bulk_active(desc), lwi);
1188 LASSERT (rc == 0 || rc == -ETIMEDOUT);
1191 if (desc->bd_success &&
1192 desc->bd_nob_transferred == rdpg->rp_count)
1193 GOTO(free_desc, rc);
1195 rc = -ETIMEDOUT; /* XXX should this be a different errno? */
1198 DEBUG_REQ(D_ERROR, req, "bulk failed: %s %d(%d), evicting %s@%s",
1199 (rc == -ETIMEDOUT) ? "timeout" : "network error",
1200 desc->bd_nob_transferred, rdpg->rp_count,
1201 req->rq_export->exp_client_uuid.uuid,
1202 req->rq_export->exp_connection->c_remote_uuid.uuid);
1204 class_fail_export(req->rq_export);
1208 ptlrpc_abort_bulk(desc);
1210 ptlrpc_free_bulk(desc);
1214 #ifdef HAVE_SPLIT_SUPPORT
1216 * Retrieve dir entry from the page and insert it to the slave object, actually,
1217 * this should be in osd layer, but since it will not in the final product, so
1218 * just do it here and do not define more moo api anymore for this.
1220 static int mdt_write_dir_page(struct mdt_thread_info *info, struct page *page,
1223 struct mdt_object *object = info->mti_object;
1224 struct lu_fid *lf = &info->mti_tmp_fid2;
1225 struct md_attr *ma = &info->mti_attr;
1226 struct lu_dirpage *dp;
1227 struct lu_dirent *ent;
1228 int rc = 0, offset = 0;
1231 /* Make sure we have at least one entry. */
1236 * Disable trans for this name insert, since it will include many trans
1239 info->mti_no_need_trans = 1;
1241 * When write_dir_page, no need update parent's ctime,
1242 * and no permission check for name_insert.
1244 ma->ma_attr.la_ctime = 0;
1245 ma->ma_attr.la_valid = LA_MODE;
1246 ma->ma_valid = MA_INODE;
1249 dp = page_address(page);
1250 offset = (int)((__u32)lu_dirent_start(dp) - (__u32)dp);
1252 for (ent = lu_dirent_start(dp); ent != NULL;
1253 ent = lu_dirent_next(ent)) {
1254 struct lu_name *lname;
1257 if (le16_to_cpu(ent->lde_namelen) == 0)
1260 fid_le_to_cpu(lf, &ent->lde_fid);
1261 if (le64_to_cpu(ent->lde_hash) & MAX_HASH_HIGHEST_BIT)
1262 ma->ma_attr.la_mode = S_IFDIR;
1264 ma->ma_attr.la_mode = 0;
1265 OBD_ALLOC(name, le16_to_cpu(ent->lde_namelen) + 1);
1267 GOTO(out, rc = -ENOMEM);
1269 memcpy(name, ent->lde_name, le16_to_cpu(ent->lde_namelen));
1270 lname = mdt_name(info->mti_env, name,
1271 le16_to_cpu(ent->lde_namelen));
1272 ma->ma_attr_flags |= (MDS_PERM_BYPASS | MDS_QUOTA_IGNORE);
1273 rc = mdo_name_insert(info->mti_env,
1274 md_object_next(&object->mot_obj),
1276 OBD_FREE(name, le16_to_cpu(ent->lde_namelen) + 1);
1278 CERROR("Can't insert %*.*s, rc %d\n",
1279 le16_to_cpu(ent->lde_namelen),
1280 le16_to_cpu(ent->lde_namelen),
1285 offset += lu_dirent_size(ent);
1295 static int mdt_bulk_timeout(void *data)
1299 CERROR("mdt bulk transfer timeout \n");
1304 static int mdt_writepage(struct mdt_thread_info *info)
1306 struct ptlrpc_request *req = mdt_info_req(info);
1307 struct mdt_body *reqbody;
1308 struct l_wait_info *lwi;
1309 struct ptlrpc_bulk_desc *desc;
1315 reqbody = req_capsule_client_get(info->mti_pill, &RMF_MDT_BODY);
1316 if (reqbody == NULL)
1317 RETURN(err_serious(-EFAULT));
1319 desc = ptlrpc_prep_bulk_exp(req, 1, BULK_GET_SINK, MDS_BULK_PORTAL);
1321 RETURN(err_serious(-ENOMEM));
1323 /* allocate the page for the desc */
1324 page = cfs_alloc_page(CFS_ALLOC_STD);
1326 GOTO(desc_cleanup, rc = -ENOMEM);
1328 CDEBUG(D_INFO, "Received page offset %d size %d \n",
1329 (int)reqbody->size, (int)reqbody->nlink);
1331 ptlrpc_prep_bulk_page(desc, page, (int)reqbody->size,
1332 (int)reqbody->nlink);
1334 rc = sptlrpc_svc_prep_bulk(req, desc);
1336 GOTO(cleanup_page, rc);
1338 * Check if client was evicted while we were doing i/o before touching
1343 GOTO(cleanup_page, rc = -ENOMEM);
1345 if (desc->bd_export->exp_failed)
1348 rc = ptlrpc_start_bulk_transfer (desc);
1350 *lwi = LWI_TIMEOUT_INTERVAL(obd_timeout * HZ / 4, HZ,
1351 mdt_bulk_timeout, desc);
1352 rc = l_wait_event(desc->bd_waitq, !ptlrpc_bulk_active(desc) ||
1353 desc->bd_export->exp_failed, lwi);
1354 LASSERT(rc == 0 || rc == -ETIMEDOUT);
1355 if (rc == -ETIMEDOUT) {
1356 DEBUG_REQ(D_ERROR, req, "timeout on bulk GET");
1357 ptlrpc_abort_bulk(desc);
1358 } else if (desc->bd_export->exp_failed) {
1359 DEBUG_REQ(D_ERROR, req, "Eviction on bulk GET");
1361 ptlrpc_abort_bulk(desc);
1362 } else if (!desc->bd_success ||
1363 desc->bd_nob_transferred != desc->bd_nob) {
1364 DEBUG_REQ(D_ERROR, req, "%s bulk GET %d(%d)",
1366 "truncated" : "network error on",
1367 desc->bd_nob_transferred, desc->bd_nob);
1368 /* XXX should this be a different errno? */
1372 DEBUG_REQ(D_ERROR, req, "ptlrpc_bulk_get failed: rc %d", rc);
1375 GOTO(cleanup_lwi, rc);
1376 rc = mdt_write_dir_page(info, page, reqbody->nlink);
1381 cfs_free_page(page);
1383 ptlrpc_free_bulk(desc);
1388 static int mdt_readpage(struct mdt_thread_info *info)
1390 struct mdt_object *object = info->mti_object;
1391 struct lu_rdpg *rdpg = &info->mti_u.rdpg.mti_rdpg;
1392 struct mdt_body *reqbody;
1393 struct mdt_body *repbody;
1398 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_READPAGE_PACK))
1399 RETURN(err_serious(-ENOMEM));
1401 reqbody = req_capsule_client_get(info->mti_pill, &RMF_MDT_BODY);
1402 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
1403 if (reqbody == NULL || repbody == NULL)
1404 RETURN(err_serious(-EFAULT));
1407 * prepare @rdpg before calling lower layers and transfer itself. Here
1408 * reqbody->size contains offset of where to start to read and
1409 * reqbody->nlink contains number bytes to read.
1411 rdpg->rp_hash = reqbody->size;
1412 if (rdpg->rp_hash != reqbody->size) {
1413 CERROR("Invalid hash: "LPX64" != "LPX64"\n",
1414 rdpg->rp_hash, reqbody->size);
1418 rdpg->rp_attrs = reqbody->mode;
1419 rdpg->rp_count = reqbody->nlink;
1420 rdpg->rp_npages = (rdpg->rp_count + CFS_PAGE_SIZE - 1)>>CFS_PAGE_SHIFT;
1421 OBD_ALLOC(rdpg->rp_pages, rdpg->rp_npages * sizeof rdpg->rp_pages[0]);
1422 if (rdpg->rp_pages == NULL)
1425 for (i = 0; i < rdpg->rp_npages; ++i) {
1426 rdpg->rp_pages[i] = cfs_alloc_page(CFS_ALLOC_STD);
1427 if (rdpg->rp_pages[i] == NULL)
1428 GOTO(free_rdpg, rc = -ENOMEM);
1431 /* call lower layers to fill allocated pages with directory data */
1432 rc = mo_readpage(info->mti_env, mdt_object_child(object), rdpg);
1434 GOTO(free_rdpg, rc);
1436 /* send pages to client */
1437 rc = mdt_sendpage(info, rdpg);
1442 for (i = 0; i < rdpg->rp_npages; i++)
1443 if (rdpg->rp_pages[i] != NULL)
1444 cfs_free_page(rdpg->rp_pages[i]);
1445 OBD_FREE(rdpg->rp_pages, rdpg->rp_npages * sizeof rdpg->rp_pages[0]);
1447 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_SENDPAGE))
1453 static int mdt_reint_internal(struct mdt_thread_info *info,
1454 struct mdt_lock_handle *lhc,
1457 struct req_capsule *pill = info->mti_pill;
1458 struct mdt_device *mdt = info->mti_mdt;
1459 struct mdt_body *repbody;
1464 if (req_capsule_has_field(pill, &RMF_MDT_MD, RCL_SERVER))
1465 req_capsule_set_size(pill, &RMF_MDT_MD, RCL_SERVER,
1466 mdt->mdt_max_mdsize);
1467 if (req_capsule_has_field(pill, &RMF_LOGCOOKIES, RCL_SERVER))
1468 req_capsule_set_size(pill, &RMF_LOGCOOKIES, RCL_SERVER,
1469 mdt->mdt_max_cookiesize);
1471 rc = req_capsule_server_pack(pill);
1473 CERROR("Can't pack response, rc %d\n", rc);
1474 RETURN(err_serious(rc));
1477 if (req_capsule_has_field(pill, &RMF_MDT_BODY, RCL_SERVER)) {
1478 repbody = req_capsule_server_get(pill, &RMF_MDT_BODY);
1480 repbody->eadatasize = 0;
1481 repbody->aclsize = 0;
1484 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_REINT_UNPACK))
1485 GOTO(out_shrink, rc = err_serious(-EFAULT));
1487 rc = mdt_reint_unpack(info, op);
1489 CERROR("Can't unpack reint, rc %d\n", rc);
1490 GOTO(out_shrink, rc = err_serious(rc));
1493 /* for replay no cookkie / lmm need, because client have this already */
1494 if (info->mti_spec.no_create == 1) {
1495 if (req_capsule_has_field(pill, &RMF_MDT_MD, RCL_SERVER))
1496 req_capsule_set_size(pill, &RMF_MDT_MD, RCL_SERVER, 0);
1498 if (req_capsule_has_field(pill, &RMF_LOGCOOKIES, RCL_SERVER))
1499 req_capsule_set_size(pill, &RMF_LOGCOOKIES, RCL_SERVER,
1503 rc = mdt_init_ucred_reint(info);
1505 GOTO(out_shrink, rc);
1507 rc = mdt_fix_attr_ucred(info, op);
1509 GOTO(out_ucred, rc = err_serious(rc));
1511 if (mdt_check_resent(info, mdt_reconstruct, lhc)) {
1512 rc = lustre_msg_get_status(mdt_info_req(info)->rq_repmsg);
1513 GOTO(out_ucred, rc);
1515 rc = mdt_reint_rec(info, lhc);
1518 mdt_exit_ucred(info);
1520 mdt_shrink_reply(info);
1524 static long mdt_reint_opcode(struct mdt_thread_info *info,
1525 const struct req_format **fmt)
1527 struct mdt_rec_reint *rec;
1530 opc = err_serious(-EFAULT);
1531 rec = req_capsule_client_get(info->mti_pill, &RMF_REC_REINT);
1533 opc = rec->rr_opcode;
1534 DEBUG_REQ(D_INODE, mdt_info_req(info), "reint opt = %ld", opc);
1535 if (opc < REINT_MAX && fmt[opc] != NULL)
1536 req_capsule_extend(info->mti_pill, fmt[opc]);
1538 CERROR("Unsupported opc: %ld\n", opc);
1539 opc = err_serious(opc);
1545 static int mdt_reint(struct mdt_thread_info *info)
1550 static const struct req_format *reint_fmts[REINT_MAX] = {
1551 [REINT_SETATTR] = &RQF_MDS_REINT_SETATTR,
1552 [REINT_CREATE] = &RQF_MDS_REINT_CREATE,
1553 [REINT_LINK] = &RQF_MDS_REINT_LINK,
1554 [REINT_UNLINK] = &RQF_MDS_REINT_UNLINK,
1555 [REINT_RENAME] = &RQF_MDS_REINT_RENAME,
1556 [REINT_OPEN] = &RQF_MDS_REINT_OPEN,
1557 [REINT_SETXATTR] = &RQF_MDS_REINT_SETXATTR
1562 opc = mdt_reint_opcode(info, reint_fmts);
1565 * No lock possible here from client to pass it to reint code
1568 rc = mdt_reint_internal(info, NULL, opc);
1573 info->mti_fail_id = OBD_FAIL_MDS_REINT_NET_REP;
1577 /* this should sync the whole device */
1578 static int mdt_device_sync(const struct lu_env *env, struct mdt_device *mdt)
1580 struct dt_device *dt = mdt->mdt_bottom;
1584 rc = dt->dd_ops->dt_sync(env, dt);
1588 /* this should sync this object */
1589 static int mdt_object_sync(struct mdt_thread_info *info)
1591 struct md_object *next;
1595 if (!mdt_object_exists(info->mti_object)) {
1596 CWARN("Non existing object "DFID"!\n",
1597 PFID(mdt_object_fid(info->mti_object)));
1600 next = mdt_object_child(info->mti_object);
1601 rc = mo_object_sync(info->mti_env, next);
1606 static int mdt_sync(struct mdt_thread_info *info)
1608 struct req_capsule *pill = info->mti_pill;
1609 struct mdt_body *body;
1613 /* The fid may be zero, so we req_capsule_set manually */
1614 req_capsule_set(pill, &RQF_MDS_SYNC);
1616 body = req_capsule_client_get(pill, &RMF_MDT_BODY);
1618 RETURN(err_serious(-EINVAL));
1620 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_SYNC_PACK))
1621 RETURN(err_serious(-ENOMEM));
1623 if (fid_seq(&body->fid1) == 0) {
1624 /* sync the whole device */
1625 rc = req_capsule_server_pack(pill);
1627 rc = mdt_device_sync(info->mti_env, info->mti_mdt);
1629 rc = err_serious(rc);
1631 /* sync an object */
1632 rc = mdt_unpack_req_pack_rep(info, HABEO_CORPUS|HABEO_REFERO);
1634 rc = mdt_object_sync(info);
1636 struct md_object *next;
1637 const struct lu_fid *fid;
1638 struct lu_attr *la = &info->mti_attr.ma_attr;
1640 next = mdt_object_child(info->mti_object);
1641 info->mti_attr.ma_need = MA_INODE;
1642 info->mti_attr.ma_valid = 0;
1643 rc = mo_attr_get(info->mti_env, next,
1646 body = req_capsule_server_get(pill,
1648 fid = mdt_object_fid(info->mti_object);
1649 mdt_pack_attr2body(info, body, la, fid);
1653 rc = err_serious(rc);
1658 #ifdef HAVE_QUOTA_SUPPORT
1659 static int mdt_quotacheck_handle(struct mdt_thread_info *info)
1661 struct obd_quotactl *oqctl;
1662 struct req_capsule *pill = info->mti_pill;
1663 struct obd_export *exp = info->mti_exp;
1664 struct md_device *next = info->mti_mdt->mdt_child;
1668 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_QUOTACHECK_NET))
1671 oqctl = req_capsule_client_get(pill, &RMF_OBD_QUOTACTL);
1675 /* remote client has no permission for quotacheck */
1676 if (unlikely(exp_connect_rmtclient(exp)))
1679 rc = req_capsule_server_pack(pill);
1683 rc = next->md_ops->mdo_quota.mqo_check(info->mti_env, next, exp,
1688 static int mdt_quotactl_handle(struct mdt_thread_info *info)
1690 struct obd_quotactl *oqctl, *repoqc;
1691 struct req_capsule *pill = info->mti_pill;
1692 struct obd_export *exp = info->mti_exp;
1693 struct md_device *next = info->mti_mdt->mdt_child;
1694 const struct md_quota_operations *mqo = &next->md_ops->mdo_quota;
1698 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_QUOTACTL_NET))
1701 oqctl = req_capsule_client_get(pill, &RMF_OBD_QUOTACTL);
1706 if (exp_connect_rmtclient(exp)) {
1707 struct ptlrpc_request *req = mdt_info_req(info);
1708 struct mdt_export_data *med = mdt_req2med(req);
1709 struct lustre_idmap_table *idmap = med->med_idmap;
1711 if (unlikely(oqctl->qc_cmd != Q_GETQUOTA &&
1712 oqctl->qc_cmd != Q_GETINFO))
1716 if (oqctl->qc_type == USRQUOTA)
1717 id = lustre_idmap_lookup_uid(NULL, idmap, 0,
1719 else if (oqctl->qc_type == GRPQUOTA)
1720 id = lustre_idmap_lookup_gid(NULL, idmap, 0,
1725 if (id == CFS_IDMAP_NOTFOUND) {
1726 CDEBUG(D_QUOTA, "no mapping for id %u\n",
1732 rc = req_capsule_server_pack(pill);
1736 repoqc = req_capsule_server_get(pill, &RMF_OBD_QUOTACTL);
1737 LASSERT(repoqc != NULL);
1739 switch (oqctl->qc_cmd) {
1741 rc = mqo->mqo_on(info->mti_env, next, oqctl->qc_type);
1744 rc = mqo->mqo_off(info->mti_env, next, oqctl->qc_type);
1747 rc = mqo->mqo_setinfo(info->mti_env, next, oqctl->qc_type, id,
1751 rc = mqo->mqo_getinfo(info->mti_env, next, oqctl->qc_type, id,
1755 rc = mqo->mqo_setquota(info->mti_env, next, oqctl->qc_type, id,
1759 rc = mqo->mqo_getquota(info->mti_env, next, oqctl->qc_type, id,
1763 rc = mqo->mqo_getoinfo(info->mti_env, next, oqctl->qc_type, id,
1767 rc = mqo->mqo_getoquota(info->mti_env, next, oqctl->qc_type, id,
1770 case LUSTRE_Q_INVALIDATE:
1771 rc = mqo->mqo_invalidate(info->mti_env, next, oqctl->qc_type);
1773 case LUSTRE_Q_FINVALIDATE:
1774 rc = mqo->mqo_finvalidate(info->mti_env, next, oqctl->qc_type);
1777 CERROR("unsupported mdt_quotactl command: %d\n",
1788 * OBD PING and other handlers.
1790 static int mdt_obd_ping(struct mdt_thread_info *info)
1795 req_capsule_set(info->mti_pill, &RQF_OBD_PING);
1797 rc = target_handle_ping(mdt_info_req(info));
1799 rc = err_serious(rc);
1803 static int mdt_obd_log_cancel(struct mdt_thread_info *info)
1805 return err_serious(-EOPNOTSUPP);
1808 static int mdt_obd_qc_callback(struct mdt_thread_info *info)
1810 return err_serious(-EOPNOTSUPP);
1817 static struct ldlm_callback_suite cbs = {
1818 .lcs_completion = ldlm_server_completion_ast,
1819 .lcs_blocking = ldlm_server_blocking_ast,
1823 static int mdt_enqueue(struct mdt_thread_info *info)
1825 struct ptlrpc_request *req;
1830 * info->mti_dlm_req already contains swapped and (if necessary)
1831 * converted dlm request.
1833 LASSERT(info->mti_dlm_req != NULL);
1835 req = mdt_info_req(info);
1838 * Lock without inodebits makes no sense and will oops later in
1839 * ldlm. Let's check it now to see if we have wrong lock from client or
1840 * bits get corrupted somewhere in mdt_intent_policy().
1842 req_bits = info->mti_dlm_req->lock_desc.l_policy_data.l_inodebits.bits;
1843 /* This is disabled because we need to support liblustre flock.
1844 * LASSERT(req_bits != 0);
1847 rc = ldlm_handle_enqueue0(info->mti_mdt->mdt_namespace,
1848 req, info->mti_dlm_req, &cbs);
1849 info->mti_fail_id = OBD_FAIL_LDLM_REPLY;
1850 return rc ? err_serious(rc) : req->rq_status;
1853 static int mdt_convert(struct mdt_thread_info *info)
1856 struct ptlrpc_request *req;
1858 LASSERT(info->mti_dlm_req);
1859 req = mdt_info_req(info);
1860 rc = ldlm_handle_convert0(req, info->mti_dlm_req);
1861 return rc ? err_serious(rc) : req->rq_status;
1864 static int mdt_bl_callback(struct mdt_thread_info *info)
1866 CERROR("bl callbacks should not happen on MDS\n");
1868 return err_serious(-EOPNOTSUPP);
1871 static int mdt_cp_callback(struct mdt_thread_info *info)
1873 CERROR("cp callbacks should not happen on MDS\n");
1875 return err_serious(-EOPNOTSUPP);
1879 * sec context handlers
1881 static int mdt_sec_ctx_handle(struct mdt_thread_info *info)
1885 rc = mdt_handle_idmap(info);
1888 struct ptlrpc_request *req = mdt_info_req(info);
1891 opc = lustre_msg_get_opc(req->rq_reqmsg);
1892 if (opc == SEC_CTX_INIT || opc == SEC_CTX_INIT_CONT)
1893 sptlrpc_svc_ctx_invalidate(req);
1896 OBD_FAIL_TIMEOUT(OBD_FAIL_SEC_CTX_HDL_PAUSE, obd_fail_val);
1901 static struct mdt_object *mdt_obj(struct lu_object *o)
1903 LASSERT(lu_device_is_mdt(o->lo_dev));
1904 return container_of0(o, struct mdt_object, mot_obj.mo_lu);
1907 struct mdt_object *mdt_object_find(const struct lu_env *env,
1908 struct mdt_device *d,
1909 const struct lu_fid *f)
1911 struct lu_object *o;
1912 struct mdt_object *m;
1915 CDEBUG(D_INFO, "Find object for "DFID"\n", PFID(f));
1916 o = lu_object_find(env, &d->mdt_md_dev.md_lu_dev, f, NULL);
1917 if (unlikely(IS_ERR(o)))
1918 m = (struct mdt_object *)o;
1925 * Asyncronous commit for mdt device.
1927 * Pass asynchonous commit call down the MDS stack.
1929 * \param env environment
1930 * \param mdt the mdt device
1932 static void mdt_device_commit_async(const struct lu_env *env,
1933 struct mdt_device *mdt)
1935 struct dt_device *dt = mdt->mdt_bottom;
1938 rc = dt->dd_ops->dt_commit_async(env, dt);
1939 if (unlikely(rc != 0))
1940 CWARN("async commit start failed with rc = %d", rc);
1944 * Mark the lock as "synchonous".
1946 * Mark the lock to deffer transaction commit to the unlock time.
1948 * \param lock the lock to mark as "synchonous"
1950 * \see mdt_is_lock_sync
1951 * \see mdt_save_lock
1953 static inline void mdt_set_lock_sync(struct ldlm_lock *lock)
1955 lock->l_ast_data = (void*)1;
1959 * Check whehter the lock "synchonous" or not.
1961 * \param lock the lock to check
1962 * \retval 1 the lock is "synchonous"
1963 * \retval 0 the lock isn't "synchronous"
1965 * \see mdt_set_lock_sync
1966 * \see mdt_save_lock
1968 static inline int mdt_is_lock_sync(struct ldlm_lock *lock)
1970 return lock->l_ast_data != NULL;
1974 * Blocking AST for mdt locks.
1976 * Starts transaction commit if in case of COS lock conflict or
1977 * deffers such a commit to the mdt_save_lock.
1979 * \param lock the lock which blocks a request or cancelling lock
1980 * \param desc unused
1981 * \param data unused
1982 * \param flag indicates whether this cancelling or blocking callback
1984 * \see ldlm_blocking_ast_nocheck
1986 int mdt_blocking_ast(struct ldlm_lock *lock, struct ldlm_lock_desc *desc,
1987 void *data, int flag)
1989 struct obd_device *obd = lock->l_resource->lr_namespace->ns_obd;
1990 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
1994 if (flag == LDLM_CB_CANCELING)
1996 lock_res_and_lock(lock);
1997 if (lock->l_blocking_ast != mdt_blocking_ast) {
1998 unlock_res_and_lock(lock);
2001 if (mdt_cos_is_enabled(mdt) &&
2002 lock->l_req_mode & (LCK_PW | LCK_EX) &&
2003 lock->l_blocking_lock != NULL &&
2004 lock->l_client_cookie != lock->l_blocking_lock->l_client_cookie) {
2005 mdt_set_lock_sync(lock);
2007 rc = ldlm_blocking_ast_nocheck(lock);
2009 /* There is no lock conflict if l_blocking_lock == NULL,
2010 * it indicates a blocking ast sent from ldlm_lock_decref_internal
2011 * when the last reference to a local lock was released */
2012 if (lock->l_req_mode == LCK_COS && lock->l_blocking_lock != NULL) {
2015 rc = lu_env_init(&env, LCT_MD_THREAD);
2016 if (unlikely(rc != 0))
2017 CWARN("lu_env initialization failed with rc = %d,"
2018 "cannot start asynchronous commit\n", rc);
2020 mdt_device_commit_async(&env, mdt);
2026 int mdt_object_lock(struct mdt_thread_info *info, struct mdt_object *o,
2027 struct mdt_lock_handle *lh, __u64 ibits, int locality)
2029 struct ldlm_namespace *ns = info->mti_mdt->mdt_namespace;
2030 ldlm_policy_data_t *policy = &info->mti_policy;
2031 struct ldlm_res_id *res_id = &info->mti_res_id;
2035 LASSERT(!lustre_handle_is_used(&lh->mlh_reg_lh));
2036 LASSERT(!lustre_handle_is_used(&lh->mlh_pdo_lh));
2037 LASSERT(lh->mlh_reg_mode != LCK_MINMODE);
2038 LASSERT(lh->mlh_type != MDT_NUL_LOCK);
2040 if (mdt_object_exists(o) < 0) {
2041 if (locality == MDT_CROSS_LOCK) {
2042 /* cross-ref object fix */
2043 ibits &= ~MDS_INODELOCK_UPDATE;
2044 ibits |= MDS_INODELOCK_LOOKUP;
2046 LASSERT(!(ibits & MDS_INODELOCK_UPDATE));
2047 LASSERT(ibits & MDS_INODELOCK_LOOKUP);
2049 /* No PDO lock on remote object */
2050 LASSERT(lh->mlh_type != MDT_PDO_LOCK);
2053 if (lh->mlh_type == MDT_PDO_LOCK) {
2054 /* check for exists after object is locked */
2055 if (mdt_object_exists(o) == 0) {
2056 /* Non-existent object shouldn't have PDO lock */
2059 /* Non-dir object shouldn't have PDO lock */
2060 LASSERT(S_ISDIR(lu_object_attr(&o->mot_obj.mo_lu)));
2064 memset(policy, 0, sizeof(*policy));
2065 fid_build_reg_res_name(mdt_object_fid(o), res_id);
2068 * Take PDO lock on whole directory and build correct @res_id for lock
2069 * on part of directory.
2071 if (lh->mlh_pdo_hash != 0) {
2072 LASSERT(lh->mlh_type == MDT_PDO_LOCK);
2073 mdt_lock_pdo_mode(info, o, lh);
2074 if (lh->mlh_pdo_mode != LCK_NL) {
2076 * Do not use LDLM_FL_LOCAL_ONLY for parallel lock, it
2077 * is never going to be sent to client and we do not
2078 * want it slowed down due to possible cancels.
2080 policy->l_inodebits.bits = MDS_INODELOCK_UPDATE;
2081 rc = mdt_fid_lock(ns, &lh->mlh_pdo_lh, lh->mlh_pdo_mode,
2082 policy, res_id, LDLM_FL_ATOMIC_CB,
2083 &info->mti_exp->exp_handle.h_cookie);
2089 * Finish res_id initializing by name hash marking part of
2090 * directory which is taking modification.
2092 res_id->name[LUSTRE_RES_ID_HSH_OFF] = lh->mlh_pdo_hash;
2095 policy->l_inodebits.bits = ibits;
2098 * Use LDLM_FL_LOCAL_ONLY for this lock. We do not know yet if it is
2099 * going to be sent to client. If it is - mdt_intent_policy() path will
2100 * fix it up and turn FL_LOCAL flag off.
2102 rc = mdt_fid_lock(ns, &lh->mlh_reg_lh, lh->mlh_reg_mode, policy,
2103 res_id, LDLM_FL_LOCAL_ONLY | LDLM_FL_ATOMIC_CB,
2104 &info->mti_exp->exp_handle.h_cookie);
2110 mdt_object_unlock(info, o, lh, 1);
2117 * Save a lock within request object.
2119 * Keep the lock referenced until whether client ACK or transaction
2120 * commit happens or release the lock immediately depending on input
2121 * parameters. If COS is ON, a write lock is converted to COS lock
2124 * \param info thead info object
2125 * \param h lock handle
2126 * \param mode lock mode
2127 * \param decref force immediate lock releasing
2130 void mdt_save_lock(struct mdt_thread_info *info, struct lustre_handle *h,
2131 ldlm_mode_t mode, int decref)
2135 if (lustre_handle_is_used(h)) {
2136 if (decref || !info->mti_has_trans ||
2137 !(mode & (LCK_PW | LCK_EX))){
2138 mdt_fid_unlock(h, mode);
2140 struct mdt_device *mdt = info->mti_mdt;
2141 struct ldlm_lock *lock = ldlm_handle2lock(h);
2142 struct ptlrpc_request *req = mdt_info_req(info);
2145 LASSERTF(lock != NULL, "no lock for cookie "LPX64"\n",
2147 CDEBUG(D_HA, "request = %p reply state = %p"
2148 " transno = "LPD64"\n",
2149 req, req->rq_reply_state, req->rq_transno);
2150 if (mdt_cos_is_enabled(mdt)) {
2152 ldlm_lock_downgrade(lock, LCK_COS);
2155 ptlrpc_save_lock(req, h, mode, no_ack);
2156 if (mdt_is_lock_sync(lock)) {
2157 CDEBUG(D_HA, "found sync-lock,"
2158 " async commit started\n");
2159 mdt_device_commit_async(info->mti_env,
2162 LDLM_LOCK_PUT(lock);
2171 * Unlock mdt object.
2173 * Immeditely release the regular lock and the PDO lock or save the
2174 * lock in reqeuest and keep them referenced until client ACK or
2175 * transaction commit.
2177 * \param info thread info object
2178 * \param o mdt object
2179 * \param h mdt lock handle referencing regular and PDO locks
2180 * \param decref force immediate lock releasing
2182 void mdt_object_unlock(struct mdt_thread_info *info, struct mdt_object *o,
2183 struct mdt_lock_handle *lh, int decref)
2187 mdt_save_lock(info, &lh->mlh_pdo_lh, lh->mlh_pdo_mode, decref);
2188 mdt_save_lock(info, &lh->mlh_reg_lh, lh->mlh_reg_mode, decref);
2193 struct mdt_object *mdt_object_find_lock(struct mdt_thread_info *info,
2194 const struct lu_fid *f,
2195 struct mdt_lock_handle *lh,
2198 struct mdt_object *o;
2200 o = mdt_object_find(info->mti_env, info->mti_mdt, f);
2204 rc = mdt_object_lock(info, o, lh, ibits,
2207 mdt_object_put(info->mti_env, o);
2214 void mdt_object_unlock_put(struct mdt_thread_info * info,
2215 struct mdt_object * o,
2216 struct mdt_lock_handle *lh,
2219 mdt_object_unlock(info, o, lh, decref);
2220 mdt_object_put(info->mti_env, o);
2223 static struct mdt_handler *mdt_handler_find(__u32 opc,
2224 struct mdt_opc_slice *supported)
2226 struct mdt_opc_slice *s;
2227 struct mdt_handler *h;
2230 for (s = supported; s->mos_hs != NULL; s++) {
2231 if (s->mos_opc_start <= opc && opc < s->mos_opc_end) {
2232 h = s->mos_hs + (opc - s->mos_opc_start);
2233 if (likely(h->mh_opc != 0))
2234 LASSERT(h->mh_opc == opc);
2236 h = NULL; /* unsupported opc */
2243 static int mdt_lock_resname_compat(struct mdt_device *m,
2244 struct ldlm_request *req)
2246 /* XXX something... later. */
2250 static int mdt_lock_reply_compat(struct mdt_device *m, struct ldlm_reply *rep)
2252 /* XXX something... later. */
2257 * Generic code handling requests that have struct mdt_body passed in:
2259 * - extract mdt_body from request and save it in @info, if present;
2261 * - create lu_object, corresponding to the fid in mdt_body, and save it in
2264 * - if HABEO_CORPUS flag is set for this request type check whether object
2265 * actually exists on storage (lu_object_exists()).
2268 static int mdt_body_unpack(struct mdt_thread_info *info, __u32 flags)
2270 const struct mdt_body *body;
2271 struct mdt_object *obj;
2272 const struct lu_env *env;
2273 struct req_capsule *pill;
2277 env = info->mti_env;
2278 pill = info->mti_pill;
2280 body = info->mti_body = req_capsule_client_get(pill, &RMF_MDT_BODY);
2284 if (!(body->valid & OBD_MD_FLID))
2287 if (!fid_is_sane(&body->fid1)) {
2288 CERROR("Invalid fid: "DFID"\n", PFID(&body->fid1));
2293 * Do not get size or any capa fields before we check that request
2294 * contains capa actually. There are some requests which do not, for
2295 * instance MDS_IS_SUBDIR.
2297 if (req_capsule_has_field(pill, &RMF_CAPA1, RCL_CLIENT) &&
2298 req_capsule_get_size(pill, &RMF_CAPA1, RCL_CLIENT))
2299 mdt_set_capainfo(info, 0, &body->fid1,
2300 req_capsule_client_get(pill, &RMF_CAPA1));
2302 obj = mdt_object_find(env, info->mti_mdt, &body->fid1);
2304 if ((flags & HABEO_CORPUS) &&
2305 !mdt_object_exists(obj)) {
2306 mdt_object_put(env, obj);
2307 /* for capability renew ENOENT will be handled in
2309 if (body->valid & OBD_MD_FLOSSCAPA)
2314 info->mti_object = obj;
2323 static int mdt_unpack_req_pack_rep(struct mdt_thread_info *info, __u32 flags)
2325 struct req_capsule *pill = info->mti_pill;
2329 if (req_capsule_has_field(pill, &RMF_MDT_BODY, RCL_CLIENT))
2330 rc = mdt_body_unpack(info, flags);
2334 if (rc == 0 && (flags & HABEO_REFERO)) {
2335 struct mdt_device *mdt = info->mti_mdt;
2338 if (req_capsule_has_field(pill, &RMF_MDT_MD, RCL_SERVER))
2339 req_capsule_set_size(pill, &RMF_MDT_MD, RCL_SERVER,
2340 mdt->mdt_max_mdsize);
2341 if (req_capsule_has_field(pill, &RMF_LOGCOOKIES, RCL_SERVER))
2342 req_capsule_set_size(pill, &RMF_LOGCOOKIES, RCL_SERVER,
2343 mdt->mdt_max_cookiesize);
2345 rc = req_capsule_server_pack(pill);
2350 static int mdt_init_capa_ctxt(const struct lu_env *env, struct mdt_device *m)
2352 struct md_device *next = m->mdt_child;
2354 return next->md_ops->mdo_init_capa_ctxt(env, next,
2355 m->mdt_opts.mo_mds_capa,
2356 m->mdt_capa_timeout,
2362 * Invoke handler for this request opc. Also do necessary preprocessing
2363 * (according to handler ->mh_flags), and post-processing (setting of
2364 * ->last_{xid,committed}).
2366 static int mdt_req_handle(struct mdt_thread_info *info,
2367 struct mdt_handler *h, struct ptlrpc_request *req)
2369 int rc, serious = 0;
2374 LASSERT(h->mh_act != NULL);
2375 LASSERT(h->mh_opc == lustre_msg_get_opc(req->rq_reqmsg));
2376 LASSERT(current->journal_info == NULL);
2379 * Checking for various OBD_FAIL_$PREF_$OPC_NET codes. _Do_ not try
2380 * to put same checks into handlers like mdt_close(), mdt_reint(),
2381 * etc., without talking to mdt authors first. Checking same thing
2382 * there again is useless and returning 0 error wihtout packing reply
2383 * is buggy! Handlers either pack reply or return error.
2385 * We return 0 here and do not send any reply in order to emulate
2386 * network failure. Do not send any reply in case any of NET related
2387 * fail_id has occured.
2389 if (OBD_FAIL_CHECK_ORSET(h->mh_fail_id, OBD_FAIL_ONCE))
2393 flags = h->mh_flags;
2394 LASSERT(ergo(flags & (HABEO_CORPUS|HABEO_REFERO), h->mh_fmt != NULL));
2396 if (h->mh_fmt != NULL) {
2397 req_capsule_set(info->mti_pill, h->mh_fmt);
2398 rc = mdt_unpack_req_pack_rep(info, flags);
2401 if (rc == 0 && flags & MUTABOR &&
2402 req->rq_export->exp_connect_flags & OBD_CONNECT_RDONLY)
2403 /* should it be rq_status? */
2406 if (rc == 0 && flags & HABEO_CLAVIS) {
2407 struct ldlm_request *dlm_req;
2409 LASSERT(h->mh_fmt != NULL);
2411 dlm_req = req_capsule_client_get(info->mti_pill, &RMF_DLM_REQ);
2412 if (dlm_req != NULL) {
2413 if (info->mti_mdt->mdt_opts.mo_compat_resname)
2414 rc = mdt_lock_resname_compat(info->mti_mdt,
2416 info->mti_dlm_req = dlm_req;
2422 /* capability setting changed via /proc, needs reinitialize ctxt */
2423 if (info->mti_mdt && info->mti_mdt->mdt_capa_conf) {
2424 mdt_init_capa_ctxt(info->mti_env, info->mti_mdt);
2425 info->mti_mdt->mdt_capa_conf = 0;
2428 if (likely(rc == 0)) {
2430 * Process request, there can be two types of rc:
2431 * 1) errors with msg unpack/pack, other failures outside the
2432 * operation itself. This is counted as serious errors;
2433 * 2) errors during fs operation, should be placed in rq_status
2436 rc = h->mh_act(info);
2438 !req->rq_no_reply && req->rq_reply_state == NULL) {
2439 DEBUG_REQ(D_ERROR, req, "MDT \"handler\" %s did not "
2440 "pack reply and returned 0 error\n",
2444 serious = is_serious(rc);
2445 rc = clear_serious(rc);
2449 req->rq_status = rc;
2452 * ELDLM_* codes which > 0 should be in rq_status only as well as
2453 * all non-serious errors.
2455 if (rc > 0 || !serious)
2458 LASSERT(current->journal_info == NULL);
2460 if (rc == 0 && (flags & HABEO_CLAVIS) &&
2461 info->mti_mdt->mdt_opts.mo_compat_resname) {
2462 struct ldlm_reply *dlmrep;
2464 dlmrep = req_capsule_server_get(info->mti_pill, &RMF_DLM_REP);
2466 rc = mdt_lock_reply_compat(info->mti_mdt, dlmrep);
2469 /* If we're DISCONNECTing, the mdt_export_data is already freed */
2470 if (likely(rc == 0 && h->mh_opc != MDS_DISCONNECT))
2471 target_committed_to_req(req);
2473 if (unlikely((lustre_msg_get_flags(req->rq_reqmsg) & MSG_REPLAY) &&
2474 lustre_msg_get_transno(req->rq_reqmsg) == 0)) {
2475 DEBUG_REQ(D_ERROR, req, "transno is 0 during REPLAY");
2479 target_send_reply(req, rc, info->mti_fail_id);
2483 void mdt_lock_handle_init(struct mdt_lock_handle *lh)
2485 lh->mlh_type = MDT_NUL_LOCK;
2486 lh->mlh_reg_lh.cookie = 0ull;
2487 lh->mlh_reg_mode = LCK_MINMODE;
2488 lh->mlh_pdo_lh.cookie = 0ull;
2489 lh->mlh_pdo_mode = LCK_MINMODE;
2492 void mdt_lock_handle_fini(struct mdt_lock_handle *lh)
2494 LASSERT(!lustre_handle_is_used(&lh->mlh_reg_lh));
2495 LASSERT(!lustre_handle_is_used(&lh->mlh_pdo_lh));
2499 * Initialize fields of struct mdt_thread_info. Other fields are left in
2500 * uninitialized state, because it's too expensive to zero out whole
2501 * mdt_thread_info (> 1K) on each request arrival.
2503 static void mdt_thread_info_init(struct ptlrpc_request *req,
2504 struct mdt_thread_info *info)
2507 struct md_capainfo *ci;
2509 req_capsule_init(&req->rq_pill, req, RCL_SERVER);
2510 info->mti_pill = &req->rq_pill;
2513 for (i = 0; i < ARRAY_SIZE(info->mti_lh); i++)
2514 mdt_lock_handle_init(&info->mti_lh[i]);
2516 /* mdt device: it can be NULL while CONNECT */
2517 if (req->rq_export) {
2518 info->mti_mdt = mdt_dev(req->rq_export->exp_obd->obd_lu_dev);
2519 info->mti_exp = req->rq_export;
2521 info->mti_mdt = NULL;
2522 info->mti_env = req->rq_svc_thread->t_env;
2523 ci = md_capainfo(info->mti_env);
2524 memset(ci, 0, sizeof *ci);
2525 if (req->rq_export) {
2526 if (exp_connect_rmtclient(req->rq_export))
2527 ci->mc_auth = LC_ID_CONVERT;
2528 else if (req->rq_export->exp_connect_flags &
2529 OBD_CONNECT_MDS_CAPA)
2530 ci->mc_auth = LC_ID_PLAIN;
2532 ci->mc_auth = LC_ID_NONE;
2535 info->mti_fail_id = OBD_FAIL_MDS_ALL_REPLY_NET;
2536 info->mti_transno = lustre_msg_get_transno(req->rq_reqmsg);
2538 memset(&info->mti_attr, 0, sizeof(info->mti_attr));
2539 info->mti_body = NULL;
2540 info->mti_object = NULL;
2541 info->mti_dlm_req = NULL;
2542 info->mti_has_trans = 0;
2543 info->mti_no_need_trans = 0;
2544 info->mti_cross_ref = 0;
2545 info->mti_opdata = 0;
2547 /* To not check for split by default. */
2548 info->mti_spec.sp_ck_split = 0;
2549 info->mti_spec.no_create = 0;
2552 static void mdt_thread_info_fini(struct mdt_thread_info *info)
2556 req_capsule_fini(info->mti_pill);
2557 if (info->mti_object != NULL) {
2558 mdt_object_put(info->mti_env, info->mti_object);
2559 info->mti_object = NULL;
2561 for (i = 0; i < ARRAY_SIZE(info->mti_lh); i++)
2562 mdt_lock_handle_fini(&info->mti_lh[i]);
2563 info->mti_env = NULL;
2566 static int mdt_filter_recovery_request(struct ptlrpc_request *req,
2567 struct obd_device *obd, int *process)
2569 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
2570 case MDS_CONNECT: /* This will never get here, but for completeness. */
2571 case OST_CONNECT: /* This will never get here, but for completeness. */
2572 case MDS_DISCONNECT:
2573 case OST_DISCONNECT:
2578 case MDS_DONE_WRITING:
2579 case MDS_SYNC: /* used in unmounting */
2585 *process = target_queue_recovery_request(req, obd);
2589 DEBUG_REQ(D_ERROR, req, "not permitted during recovery");
2596 * Handle recovery. Return:
2597 * +1: continue request processing;
2598 * -ve: abort immediately with the given error code;
2599 * 0: send reply with error code in req->rq_status;
2601 static int mdt_recovery(struct mdt_thread_info *info)
2603 struct ptlrpc_request *req = mdt_info_req(info);
2605 struct obd_device *obd;
2609 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
2612 case SEC_CTX_INIT_CONT:
2618 rc = mdt_handle_idmap(info);
2627 if (unlikely(req->rq_export == NULL)) {
2628 CERROR("operation %d on unconnected MDS from %s\n",
2629 lustre_msg_get_opc(req->rq_reqmsg),
2630 libcfs_id2str(req->rq_peer));
2631 /* FIXME: For CMD cleanup, when mds_B stop, the req from
2632 * mds_A will get -ENOTCONN(especially for ping req),
2633 * which will cause that mds_A deactive timeout, then when
2634 * mds_A cleanup, the cleanup process will be suspended since
2635 * deactive timeout is not zero.
2637 req->rq_status = -ENOTCONN;
2638 target_send_reply(req, -ENOTCONN, info->mti_fail_id);
2642 /* sanity check: if the xid matches, the request must be marked as a
2643 * resent or replayed */
2644 if (req_xid_is_last(req)) {
2645 if (!(lustre_msg_get_flags(req->rq_reqmsg) &
2646 (MSG_RESENT | MSG_REPLAY))) {
2647 DEBUG_REQ(D_WARNING, req, "rq_xid "LPU64" matches last_xid, "
2648 "expected REPLAY or RESENT flag (%x)", req->rq_xid,
2649 lustre_msg_get_flags(req->rq_reqmsg));
2651 req->rq_status = -ENOTCONN;
2656 /* else: note the opposite is not always true; a RESENT req after a
2657 * failover will usually not match the last_xid, since it was likely
2658 * never committed. A REPLAYed request will almost never match the
2659 * last xid, however it could for a committed, but still retained,
2662 obd = req->rq_export->exp_obd;
2664 /* Check for aborted recovery... */
2665 spin_lock_bh(&obd->obd_processing_task_lock);
2666 recovering = obd->obd_recovering;
2667 spin_unlock_bh(&obd->obd_processing_task_lock);
2668 if (unlikely(recovering)) {
2671 DEBUG_REQ(D_INFO, req, "Got new replay");
2672 rc = mdt_filter_recovery_request(req, obd, &should_process);
2673 if (rc != 0 || !should_process)
2675 else if (should_process < 0) {
2676 req->rq_status = should_process;
2677 rc = ptlrpc_error(req);
2684 static int mdt_msg_check_version(struct lustre_msg *msg)
2688 switch (lustre_msg_get_opc(msg)) {
2690 case MDS_DISCONNECT:
2693 case SEC_CTX_INIT_CONT:
2695 rc = lustre_msg_check_version(msg, LUSTRE_OBD_VERSION);
2697 CERROR("bad opc %u version %08x, expecting %08x\n",
2698 lustre_msg_get_opc(msg),
2699 lustre_msg_get_version(msg),
2700 LUSTRE_OBD_VERSION);
2704 case MDS_GETATTR_NAME:
2711 case MDS_DONE_WRITING:
2717 case MDS_QUOTACHECK:
2723 rc = lustre_msg_check_version(msg, LUSTRE_MDS_VERSION);
2725 CERROR("bad opc %u version %08x, expecting %08x\n",
2726 lustre_msg_get_opc(msg),
2727 lustre_msg_get_version(msg),
2728 LUSTRE_MDS_VERSION);
2732 case LDLM_BL_CALLBACK:
2733 case LDLM_CP_CALLBACK:
2734 rc = lustre_msg_check_version(msg, LUSTRE_DLM_VERSION);
2736 CERROR("bad opc %u version %08x, expecting %08x\n",
2737 lustre_msg_get_opc(msg),
2738 lustre_msg_get_version(msg),
2739 LUSTRE_DLM_VERSION);
2741 case OBD_LOG_CANCEL:
2742 case LLOG_ORIGIN_HANDLE_CREATE:
2743 case LLOG_ORIGIN_HANDLE_NEXT_BLOCK:
2744 case LLOG_ORIGIN_HANDLE_READ_HEADER:
2745 case LLOG_ORIGIN_HANDLE_CLOSE:
2746 case LLOG_ORIGIN_HANDLE_DESTROY:
2747 case LLOG_ORIGIN_HANDLE_PREV_BLOCK:
2749 rc = lustre_msg_check_version(msg, LUSTRE_LOG_VERSION);
2751 CERROR("bad opc %u version %08x, expecting %08x\n",
2752 lustre_msg_get_opc(msg),
2753 lustre_msg_get_version(msg),
2754 LUSTRE_LOG_VERSION);
2757 CERROR("MDS unknown opcode %d\n", lustre_msg_get_opc(msg));
2763 static int mdt_handle0(struct ptlrpc_request *req,
2764 struct mdt_thread_info *info,
2765 struct mdt_opc_slice *supported)
2767 struct mdt_handler *h;
2768 struct lustre_msg *msg;
2773 if (OBD_FAIL_CHECK_ORSET(OBD_FAIL_MDS_ALL_REQUEST_NET, OBD_FAIL_ONCE))
2776 LASSERT(current->journal_info == NULL);
2778 msg = req->rq_reqmsg;
2779 rc = mdt_msg_check_version(msg);
2780 if (likely(rc == 0)) {
2781 rc = mdt_recovery(info);
2782 if (likely(rc == +1)) {
2783 switch (lustre_msg_get_opc(msg)) {
2785 req->rq_bulk_read = 1;
2788 req->rq_bulk_write = 1;
2792 h = mdt_handler_find(lustre_msg_get_opc(msg),
2794 if (likely(h != NULL)) {
2795 rc = mdt_req_handle(info, h, req);
2797 CERROR("The unsupported opc: 0x%x\n", lustre_msg_get_opc(msg) );
2798 req->rq_status = -ENOTSUPP;
2799 rc = ptlrpc_error(req);
2804 CERROR(LUSTRE_MDT_NAME" drops mal-formed request\n");
2809 * MDT handler function called by ptlrpc service thread when request comes.
2811 * XXX common "target" functionality should be factored into separate module
2812 * shared by mdt, ost and stand-alone services like fld.
2814 static int mdt_handle_common(struct ptlrpc_request *req,
2815 struct mdt_opc_slice *supported)
2818 struct mdt_thread_info *info;
2822 env = req->rq_svc_thread->t_env;
2823 LASSERT(env != NULL);
2824 LASSERT(env->le_ses != NULL);
2825 LASSERT(env->le_ctx.lc_thread == req->rq_svc_thread);
2826 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
2827 LASSERT(info != NULL);
2829 mdt_thread_info_init(req, info);
2831 rc = mdt_handle0(req, info, supported);
2833 mdt_thread_info_fini(info);
2838 * This is called from recovery code as handler of _all_ RPC types, FLD and SEQ
2841 int mdt_recovery_handle(struct ptlrpc_request *req)
2846 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
2848 rc = mdt_handle_common(req, mdt_fld_handlers);
2851 rc = mdt_handle_common(req, mdt_seq_handlers);
2854 rc = mdt_handle_common(req, mdt_regular_handlers);
2861 static int mdt_regular_handle(struct ptlrpc_request *req)
2863 return mdt_handle_common(req, mdt_regular_handlers);
2866 static int mdt_readpage_handle(struct ptlrpc_request *req)
2868 return mdt_handle_common(req, mdt_readpage_handlers);
2871 static int mdt_xmds_handle(struct ptlrpc_request *req)
2873 return mdt_handle_common(req, mdt_xmds_handlers);
2876 static int mdt_mdsc_handle(struct ptlrpc_request *req)
2878 return mdt_handle_common(req, mdt_seq_handlers);
2881 static int mdt_mdss_handle(struct ptlrpc_request *req)
2883 return mdt_handle_common(req, mdt_seq_handlers);
2886 static int mdt_dtss_handle(struct ptlrpc_request *req)
2888 return mdt_handle_common(req, mdt_seq_handlers);
2891 static int mdt_fld_handle(struct ptlrpc_request *req)
2893 return mdt_handle_common(req, mdt_fld_handlers);
2909 static int mdt_intent_getattr(enum mdt_it_code opcode,
2910 struct mdt_thread_info *info,
2911 struct ldlm_lock **,
2913 static int mdt_intent_reint(enum mdt_it_code opcode,
2914 struct mdt_thread_info *info,
2915 struct ldlm_lock **,
2918 static struct mdt_it_flavor {
2919 const struct req_format *it_fmt;
2921 int (*it_act)(enum mdt_it_code ,
2922 struct mdt_thread_info *,
2923 struct ldlm_lock **,
2926 } mdt_it_flavor[] = {
2928 .it_fmt = &RQF_LDLM_INTENT,
2929 /*.it_flags = HABEO_REFERO,*/
2931 .it_act = mdt_intent_reint,
2932 .it_reint = REINT_OPEN
2935 .it_fmt = &RQF_LDLM_INTENT,
2936 .it_flags = MUTABOR,
2937 .it_act = mdt_intent_reint,
2938 .it_reint = REINT_OPEN
2941 .it_fmt = &RQF_LDLM_INTENT,
2942 .it_flags = MUTABOR,
2943 .it_act = mdt_intent_reint,
2944 .it_reint = REINT_CREATE
2946 [MDT_IT_GETATTR] = {
2947 .it_fmt = &RQF_LDLM_INTENT_GETATTR,
2948 .it_flags = HABEO_REFERO,
2949 .it_act = mdt_intent_getattr
2951 [MDT_IT_READDIR] = {
2957 .it_fmt = &RQF_LDLM_INTENT_GETATTR,
2958 .it_flags = HABEO_REFERO,
2959 .it_act = mdt_intent_getattr
2962 .it_fmt = &RQF_LDLM_INTENT_UNLINK,
2963 .it_flags = MUTABOR,
2965 .it_reint = REINT_UNLINK
2969 .it_flags = MUTABOR,
2972 [MDT_IT_GETXATTR] = {
2979 int mdt_intent_lock_replace(struct mdt_thread_info *info,
2980 struct ldlm_lock **lockp,
2981 struct ldlm_lock *new_lock,
2982 struct mdt_lock_handle *lh,
2985 struct ptlrpc_request *req = mdt_info_req(info);
2986 struct ldlm_lock *lock = *lockp;
2989 * Get new lock only for cases when possible resent did not find any
2992 if (new_lock == NULL)
2993 new_lock = ldlm_handle2lock_long(&lh->mlh_reg_lh, 0);
2995 if (new_lock == NULL && (flags & LDLM_FL_INTENT_ONLY)) {
2996 lh->mlh_reg_lh.cookie = 0;
3000 LASSERTF(new_lock != NULL,
3001 "lockh "LPX64"\n", lh->mlh_reg_lh.cookie);
3004 * If we've already given this lock to a client once, then we should
3005 * have no readers or writers. Otherwise, we should have one reader
3006 * _or_ writer ref (which will be zeroed below) before returning the
3009 if (new_lock->l_export == req->rq_export) {
3010 LASSERT(new_lock->l_readers + new_lock->l_writers == 0);
3012 LASSERT(new_lock->l_export == NULL);
3013 LASSERT(new_lock->l_readers + new_lock->l_writers == 1);
3018 if (new_lock->l_export == req->rq_export) {
3020 * Already gave this to the client, which means that we
3021 * reconstructed a reply.
3023 LASSERT(lustre_msg_get_flags(req->rq_reqmsg) &
3025 lh->mlh_reg_lh.cookie = 0;
3026 RETURN(ELDLM_LOCK_REPLACED);
3030 * Fixup the lock to be given to the client.
3032 lock_res_and_lock(new_lock);
3033 /* Zero new_lock->l_readers and new_lock->l_writers without triggering
3034 * possible blocking AST. */
3035 while (new_lock->l_readers > 0) {
3036 lu_ref_del(&new_lock->l_reference, "reader", new_lock);
3037 lu_ref_del(&new_lock->l_reference, "user", new_lock);
3038 new_lock->l_readers--;
3040 while (new_lock->l_writers > 0) {
3041 lu_ref_del(&new_lock->l_reference, "writer", new_lock);
3042 lu_ref_del(&new_lock->l_reference, "user", new_lock);
3043 new_lock->l_writers--;
3046 new_lock->l_export = class_export_get(req->rq_export);
3047 new_lock->l_blocking_ast = lock->l_blocking_ast;
3048 new_lock->l_completion_ast = lock->l_completion_ast;
3049 new_lock->l_remote_handle = lock->l_remote_handle;
3050 new_lock->l_flags &= ~LDLM_FL_LOCAL;
3052 unlock_res_and_lock(new_lock);
3054 lustre_hash_add(new_lock->l_export->exp_lock_hash,
3055 &new_lock->l_remote_handle,
3056 &new_lock->l_exp_hash);
3058 LDLM_LOCK_RELEASE(new_lock);
3059 lh->mlh_reg_lh.cookie = 0;
3061 RETURN(ELDLM_LOCK_REPLACED);
3064 static void mdt_intent_fixup_resent(struct mdt_thread_info *info,
3065 struct ldlm_lock *new_lock,
3066 struct ldlm_lock **old_lock,
3067 struct mdt_lock_handle *lh)
3069 struct ptlrpc_request *req = mdt_info_req(info);
3070 struct obd_export *exp = req->rq_export;
3071 struct lustre_handle remote_hdl;
3072 struct ldlm_request *dlmreq;
3073 struct ldlm_lock *lock;
3075 if (!(lustre_msg_get_flags(req->rq_reqmsg) & MSG_RESENT))
3078 dlmreq = req_capsule_client_get(info->mti_pill, &RMF_DLM_REQ);
3079 remote_hdl = dlmreq->lock_handle[0];
3081 lock = lustre_hash_lookup(exp->exp_lock_hash, &remote_hdl);
3083 if (lock != new_lock) {
3084 lh->mlh_reg_lh.cookie = lock->l_handle.h_cookie;
3085 lh->mlh_reg_mode = lock->l_granted_mode;
3087 LDLM_DEBUG(lock, "Restoring lock cookie");
3088 DEBUG_REQ(D_DLMTRACE, req,
3089 "restoring lock cookie "LPX64,
3090 lh->mlh_reg_lh.cookie);
3092 *old_lock = LDLM_LOCK_GET(lock);
3093 lh_put(exp->exp_lock_hash, &lock->l_exp_hash);
3097 lh_put(exp->exp_lock_hash, &lock->l_exp_hash);
3101 * If the xid matches, then we know this is a resent request, and allow
3102 * it. (It's probably an OPEN, for which we don't send a lock.
3104 if (req_xid_is_last(req))
3108 * This remote handle isn't enqueued, so we never received or processed
3109 * this request. Clear MSG_RESENT, because it can be handled like any
3110 * normal request now.
3112 lustre_msg_clear_flags(req->rq_reqmsg, MSG_RESENT);
3114 DEBUG_REQ(D_DLMTRACE, req, "no existing lock with rhandle "LPX64,
3118 static int mdt_intent_getattr(enum mdt_it_code opcode,
3119 struct mdt_thread_info *info,
3120 struct ldlm_lock **lockp,
3123 struct mdt_lock_handle *lhc = &info->mti_lh[MDT_LH_RMT];
3124 struct ldlm_lock *new_lock = NULL;
3126 struct ldlm_reply *ldlm_rep;
3127 struct ptlrpc_request *req;
3128 struct mdt_body *reqbody;
3129 struct mdt_body *repbody;
3133 reqbody = req_capsule_client_get(info->mti_pill, &RMF_MDT_BODY);
3136 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
3139 info->mti_spec.sp_ck_split = !!(reqbody->valid & OBD_MD_FLCKSPLIT);
3140 info->mti_cross_ref = !!(reqbody->valid & OBD_MD_FLCROSSREF);
3141 repbody->eadatasize = 0;
3142 repbody->aclsize = 0;
3146 child_bits = MDS_INODELOCK_LOOKUP;
3148 case MDT_IT_GETATTR:
3149 child_bits = MDS_INODELOCK_LOOKUP | MDS_INODELOCK_UPDATE;
3152 CERROR("Unhandled till now");
3153 GOTO(out_shrink, rc = -EINVAL);
3156 rc = mdt_init_ucred(info, reqbody);
3158 GOTO(out_shrink, rc);
3160 req = info->mti_pill->rc_req;
3161 ldlm_rep = req_capsule_server_get(info->mti_pill, &RMF_DLM_REP);
3162 mdt_set_disposition(info, ldlm_rep, DISP_IT_EXECD);
3164 /* Get lock from request for possible resent case. */
3165 mdt_intent_fixup_resent(info, *lockp, &new_lock, lhc);
3167 ldlm_rep->lock_policy_res2 =
3168 mdt_getattr_name_lock(info, lhc, child_bits, ldlm_rep);
3170 if (mdt_get_disposition(ldlm_rep, DISP_LOOKUP_NEG))
3171 ldlm_rep->lock_policy_res2 = 0;
3172 if (!mdt_get_disposition(ldlm_rep, DISP_LOOKUP_POS) ||
3173 ldlm_rep->lock_policy_res2) {
3174 lhc->mlh_reg_lh.cookie = 0ull;
3175 GOTO(out_ucred, rc = ELDLM_LOCK_ABORTED);
3178 rc = mdt_intent_lock_replace(info, lockp, new_lock, lhc, flags);
3181 mdt_exit_ucred(info);
3183 mdt_shrink_reply(info);
3187 static int mdt_intent_reint(enum mdt_it_code opcode,
3188 struct mdt_thread_info *info,
3189 struct ldlm_lock **lockp,
3192 struct mdt_lock_handle *lhc = &info->mti_lh[MDT_LH_RMT];
3193 struct ldlm_reply *rep = NULL;
3197 static const struct req_format *intent_fmts[REINT_MAX] = {
3198 [REINT_CREATE] = &RQF_LDLM_INTENT_CREATE,
3199 [REINT_OPEN] = &RQF_LDLM_INTENT_OPEN
3204 opc = mdt_reint_opcode(info, intent_fmts);
3208 if (mdt_it_flavor[opcode].it_reint != opc) {
3209 CERROR("Reint code %ld doesn't match intent: %d\n",
3211 RETURN(err_serious(-EPROTO));
3214 /* Get lock from request for possible resent case. */
3215 mdt_intent_fixup_resent(info, *lockp, NULL, lhc);
3217 rc = mdt_reint_internal(info, lhc, opc);
3219 /* Check whether the reply has been packed successfully. */
3220 if (mdt_info_req(info)->rq_repmsg != NULL)
3221 rep = req_capsule_server_get(info->mti_pill, &RMF_DLM_REP);
3223 RETURN(err_serious(-EFAULT));
3225 /* MDC expects this in any case */
3227 mdt_set_disposition(info, rep, DISP_LOOKUP_EXECD);
3229 /* Cross-ref case, the lock should be returned to the client */
3230 if (rc == -EREMOTE) {
3231 LASSERT(lustre_handle_is_used(&lhc->mlh_reg_lh));
3232 rep->lock_policy_res2 = 0;
3233 rc = mdt_intent_lock_replace(info, lockp, NULL, lhc, flags);
3236 rep->lock_policy_res2 = clear_serious(rc);
3238 lhc->mlh_reg_lh.cookie = 0ull;
3239 if (rc == -ENOTCONN || rc == -ENODEV) {
3241 * If it is the disconnect error (ENODEV & ENOCONN), the error
3242 * will be returned by rq_status, and client at ptlrpc layer
3243 * will detect this, then disconnect, reconnect the import
3244 * immediately, instead of impacting the following the rpc.
3249 * For other cases, the error will be returned by intent.
3250 * and client will retrieve the result from intent.
3253 * FIXME: when open lock is finished, that should be
3256 RETURN(ELDLM_LOCK_ABORTED);
3260 static int mdt_intent_code(long itcode)
3268 case IT_OPEN|IT_CREAT:
3275 rc = MDT_IT_READDIR;
3278 rc = MDT_IT_GETATTR;
3290 rc = MDT_IT_GETXATTR;
3293 CERROR("Unknown intent opcode: %ld\n", itcode);
3300 static int mdt_intent_opc(long itopc, struct mdt_thread_info *info,
3301 struct ldlm_lock **lockp, int flags)
3303 struct req_capsule *pill;
3304 struct mdt_it_flavor *flv;
3309 opc = mdt_intent_code(itopc);
3313 pill = info->mti_pill;
3314 flv = &mdt_it_flavor[opc];
3316 if (flv->it_fmt != NULL)
3317 req_capsule_extend(pill, flv->it_fmt);
3319 rc = mdt_unpack_req_pack_rep(info, flv->it_flags);
3321 struct ptlrpc_request *req = mdt_info_req(info);
3322 if (flv->it_flags & MUTABOR &&
3323 req->rq_export->exp_connect_flags & OBD_CONNECT_RDONLY)
3326 if (rc == 0 && flv->it_act != NULL) {
3327 /* execute policy */
3328 rc = flv->it_act(opc, info, lockp, flags);
3335 static int mdt_intent_policy(struct ldlm_namespace *ns,
3336 struct ldlm_lock **lockp, void *req_cookie,
3337 ldlm_mode_t mode, int flags, void *data)
3339 struct mdt_thread_info *info;
3340 struct ptlrpc_request *req = req_cookie;
3341 struct ldlm_intent *it;
3342 struct req_capsule *pill;
3347 LASSERT(req != NULL);
3349 info = lu_context_key_get(&req->rq_svc_thread->t_env->le_ctx,
3351 LASSERT(info != NULL);
3352 pill = info->mti_pill;
3353 LASSERT(pill->rc_req == req);
3355 if (req->rq_reqmsg->lm_bufcount > DLM_INTENT_IT_OFF) {
3356 req_capsule_extend(pill, &RQF_LDLM_INTENT);
3357 it = req_capsule_client_get(pill, &RMF_LDLM_INTENT);
3359 const struct ldlm_request *dlmreq;
3362 rc = mdt_intent_opc(it->opc, info, lockp, flags);
3367 * Lock without inodebits makes no sense and will oops
3368 * later in ldlm. Let's check it now to see if we have
3369 * wrong lock from client or bits get corrupted
3370 * somewhere in mdt_intent_opc().
3372 dlmreq = info->mti_dlm_req;
3373 req_bits = dlmreq->lock_desc.l_policy_data.l_inodebits.bits;
3374 LASSERT(req_bits != 0);
3377 rc = err_serious(-EFAULT);
3379 /* No intent was provided */
3380 LASSERT(pill->rc_fmt == &RQF_LDLM_ENQUEUE);
3381 rc = req_capsule_server_pack(pill);
3383 rc = err_serious(rc);
3391 static void mdt_seq_adjust(const struct lu_env *env,
3392 struct mdt_device *m, int lost)
3394 struct md_site *ms = mdt_md_site(m);
3395 struct lu_seq_range out;
3398 LASSERT(ms && ms->ms_server_seq);
3400 /* get extra seq from seq_server, moving it's range up */
3401 while (lost-- > 0) {
3402 seq_server_alloc_meta(ms->ms_server_seq, NULL, &out, env);
3407 static int mdt_seq_fini(const struct lu_env *env,
3408 struct mdt_device *m)
3410 struct md_site *ms = mdt_md_site(m);
3414 if (ms->ms_server_seq) {
3415 seq_server_fini(ms->ms_server_seq, env);
3416 OBD_FREE_PTR(ms->ms_server_seq);
3417 ms->ms_server_seq = NULL;
3420 if (ms->ms_control_seq) {
3421 seq_server_fini(ms->ms_control_seq, env);
3422 OBD_FREE_PTR(ms->ms_control_seq);
3423 ms->ms_control_seq = NULL;
3426 if (ms->ms_client_seq) {
3427 seq_client_fini(ms->ms_client_seq);
3428 OBD_FREE_PTR(ms->ms_client_seq);
3429 ms->ms_client_seq = NULL;
3436 static int mdt_seq_init(const struct lu_env *env,
3438 struct mdt_device *m)
3445 ms = mdt_md_site(m);
3448 * This is sequence-controller node. Init seq-controller server on local
3451 if (ms->ms_node_id == 0) {
3452 LASSERT(ms->ms_control_seq == NULL);
3454 OBD_ALLOC_PTR(ms->ms_control_seq);
3455 if (ms->ms_control_seq == NULL)
3458 rc = seq_server_init(ms->ms_control_seq,
3459 m->mdt_bottom, uuid,
3460 LUSTRE_SEQ_CONTROLLER,
3465 GOTO(out_seq_fini, rc);
3467 OBD_ALLOC_PTR(ms->ms_client_seq);
3468 if (ms->ms_client_seq == NULL)
3469 GOTO(out_seq_fini, rc = -ENOMEM);
3471 OBD_ALLOC(prefix, MAX_OBD_NAME + 5);
3472 if (prefix == NULL) {
3473 OBD_FREE_PTR(ms->ms_client_seq);
3474 GOTO(out_seq_fini, rc = -ENOMEM);
3477 snprintf(prefix, MAX_OBD_NAME + 5, "ctl-%s",
3481 * Init seq-controller client after seq-controller server is
3482 * ready. Pass ms->ms_control_seq to it for direct talking.
3484 rc = seq_client_init(ms->ms_client_seq, NULL,
3485 LUSTRE_SEQ_METADATA, prefix,
3486 ms->ms_control_seq);
3487 OBD_FREE(prefix, MAX_OBD_NAME + 5);
3490 GOTO(out_seq_fini, rc);
3493 /* Init seq-server on local MDT */
3494 LASSERT(ms->ms_server_seq == NULL);
3496 OBD_ALLOC_PTR(ms->ms_server_seq);
3497 if (ms->ms_server_seq == NULL)
3498 GOTO(out_seq_fini, rc = -ENOMEM);
3500 rc = seq_server_init(ms->ms_server_seq,
3501 m->mdt_bottom, uuid,
3506 GOTO(out_seq_fini, rc = -ENOMEM);
3508 /* Assign seq-controller client to local seq-server. */
3509 if (ms->ms_node_id == 0) {
3510 LASSERT(ms->ms_client_seq != NULL);
3512 rc = seq_server_set_cli(ms->ms_server_seq,
3520 mdt_seq_fini(env, m);
3525 * Init client sequence manager which is used by local MDS to talk to sequence
3526 * controller on remote node.
3528 static int mdt_seq_init_cli(const struct lu_env *env,
3529 struct mdt_device *m,
3530 struct lustre_cfg *cfg)
3532 struct md_site *ms = mdt_md_site(m);
3533 struct obd_device *mdc;
3534 struct obd_uuid *uuidp, *mdcuuidp;
3535 char *uuid_str, *mdc_uuid_str;
3538 struct mdt_thread_info *info;
3539 char *p, *index_string = lustre_cfg_string(cfg, 2);
3542 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
3543 uuidp = &info->mti_u.uuid[0];
3544 mdcuuidp = &info->mti_u.uuid[1];
3546 LASSERT(index_string);
3548 index = simple_strtol(index_string, &p, 10);
3550 CERROR("Invalid index in lustre_cgf, offset 2\n");
3554 /* check if this is adding the first MDC and controller is not yet
3556 if (index != 0 || ms->ms_client_seq)
3559 uuid_str = lustre_cfg_string(cfg, 1);
3560 mdc_uuid_str = lustre_cfg_string(cfg, 4);
3561 obd_str2uuid(uuidp, uuid_str);
3562 obd_str2uuid(mdcuuidp, mdc_uuid_str);
3564 mdc = class_find_client_obd(uuidp, LUSTRE_MDC_NAME, mdcuuidp);
3566 CERROR("can't find controller MDC by uuid %s\n",
3569 } else if (!mdc->obd_set_up) {
3570 CERROR("target %s not set up\n", mdc->obd_name);
3573 LASSERT(ms->ms_control_exp);
3574 OBD_ALLOC_PTR(ms->ms_client_seq);
3575 if (ms->ms_client_seq != NULL) {
3578 OBD_ALLOC(prefix, MAX_OBD_NAME + 5);
3582 snprintf(prefix, MAX_OBD_NAME + 5, "ctl-%s",
3585 rc = seq_client_init(ms->ms_client_seq,
3587 LUSTRE_SEQ_METADATA,
3589 OBD_FREE(prefix, MAX_OBD_NAME + 5);
3596 LASSERT(ms->ms_server_seq != NULL);
3597 rc = seq_server_set_cli(ms->ms_server_seq, ms->ms_client_seq,
3604 static void mdt_seq_fini_cli(struct mdt_device *m)
3610 ms = mdt_md_site(m);
3613 if (ms->ms_server_seq)
3614 seq_server_set_cli(ms->ms_server_seq,
3617 if (ms->ms_control_exp) {
3618 class_export_put(ms->ms_control_exp);
3619 ms->ms_control_exp = NULL;
3628 static int mdt_fld_fini(const struct lu_env *env,
3629 struct mdt_device *m)
3631 struct md_site *ms = mdt_md_site(m);
3634 if (ms && ms->ms_server_fld) {
3635 fld_server_fini(ms->ms_server_fld, env);
3636 OBD_FREE_PTR(ms->ms_server_fld);
3637 ms->ms_server_fld = NULL;
3643 static int mdt_fld_init(const struct lu_env *env,
3645 struct mdt_device *m)
3651 ms = mdt_md_site(m);
3653 OBD_ALLOC_PTR(ms->ms_server_fld);
3654 if (ms->ms_server_fld == NULL)
3655 RETURN(rc = -ENOMEM);
3657 rc = fld_server_init(ms->ms_server_fld,
3658 m->mdt_bottom, uuid,
3659 env, ms->ms_node_id);
3661 OBD_FREE_PTR(ms->ms_server_fld);
3662 ms->ms_server_fld = NULL;
3669 /* device init/fini methods */
3670 static void mdt_stop_ptlrpc_service(struct mdt_device *m)
3673 if (m->mdt_regular_service != NULL) {
3674 ptlrpc_unregister_service(m->mdt_regular_service);
3675 m->mdt_regular_service = NULL;
3677 if (m->mdt_readpage_service != NULL) {
3678 ptlrpc_unregister_service(m->mdt_readpage_service);
3679 m->mdt_readpage_service = NULL;
3681 if (m->mdt_xmds_service != NULL) {
3682 ptlrpc_unregister_service(m->mdt_xmds_service);
3683 m->mdt_xmds_service = NULL;
3685 if (m->mdt_setattr_service != NULL) {
3686 ptlrpc_unregister_service(m->mdt_setattr_service);
3687 m->mdt_setattr_service = NULL;
3689 if (m->mdt_mdsc_service != NULL) {
3690 ptlrpc_unregister_service(m->mdt_mdsc_service);
3691 m->mdt_mdsc_service = NULL;
3693 if (m->mdt_mdss_service != NULL) {
3694 ptlrpc_unregister_service(m->mdt_mdss_service);
3695 m->mdt_mdss_service = NULL;
3697 if (m->mdt_dtss_service != NULL) {
3698 ptlrpc_unregister_service(m->mdt_dtss_service);
3699 m->mdt_dtss_service = NULL;
3701 if (m->mdt_fld_service != NULL) {
3702 ptlrpc_unregister_service(m->mdt_fld_service);
3703 m->mdt_fld_service = NULL;
3708 static int mdt_start_ptlrpc_service(struct mdt_device *m)
3711 static struct ptlrpc_service_conf conf;
3712 cfs_proc_dir_entry_t *procfs_entry;
3715 procfs_entry = m->mdt_md_dev.md_lu_dev.ld_obd->obd_proc_entry;
3717 conf = (typeof(conf)) {
3718 .psc_nbufs = MDS_NBUFS,
3719 .psc_bufsize = MDS_BUFSIZE,
3720 .psc_max_req_size = MDS_MAXREQSIZE,
3721 .psc_max_reply_size = MDS_MAXREPSIZE,
3722 .psc_req_portal = MDS_REQUEST_PORTAL,
3723 .psc_rep_portal = MDC_REPLY_PORTAL,
3724 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
3726 * We'd like to have a mechanism to set this on a per-device
3727 * basis, but alas...
3729 .psc_min_threads = min(max(mdt_num_threads, MDT_MIN_THREADS),
3731 .psc_max_threads = MDT_MAX_THREADS,
3732 .psc_ctx_tags = LCT_MD_THREAD
3735 m->mdt_ldlm_client = &m->mdt_md_dev.md_lu_dev.ld_obd->obd_ldlm_client;
3736 ptlrpc_init_client(LDLM_CB_REQUEST_PORTAL, LDLM_CB_REPLY_PORTAL,
3737 "mdt_ldlm_client", m->mdt_ldlm_client);
3739 m->mdt_regular_service =
3740 ptlrpc_init_svc_conf(&conf, mdt_regular_handle, LUSTRE_MDT_NAME,
3741 procfs_entry, target_print_req,
3743 if (m->mdt_regular_service == NULL)
3746 rc = ptlrpc_start_threads(NULL, m->mdt_regular_service);
3748 GOTO(err_mdt_svc, rc);
3751 * readpage service configuration. Parameters have to be adjusted,
3754 conf = (typeof(conf)) {
3755 .psc_nbufs = MDS_NBUFS,
3756 .psc_bufsize = MDS_BUFSIZE,
3757 .psc_max_req_size = MDS_MAXREQSIZE,
3758 .psc_max_reply_size = MDS_MAXREPSIZE,
3759 .psc_req_portal = MDS_READPAGE_PORTAL,
3760 .psc_rep_portal = MDC_REPLY_PORTAL,
3761 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
3762 .psc_min_threads = min(max(mdt_num_threads, MDT_MIN_THREADS),
3764 .psc_max_threads = MDT_MAX_THREADS,
3765 .psc_ctx_tags = LCT_MD_THREAD
3767 m->mdt_readpage_service =
3768 ptlrpc_init_svc_conf(&conf, mdt_readpage_handle,
3769 LUSTRE_MDT_NAME "_readpage",
3770 procfs_entry, target_print_req,"mdt_rdpg");
3772 if (m->mdt_readpage_service == NULL) {
3773 CERROR("failed to start readpage service\n");
3774 GOTO(err_mdt_svc, rc = -ENOMEM);
3777 rc = ptlrpc_start_threads(NULL, m->mdt_readpage_service);
3780 * setattr service configuration.
3782 conf = (typeof(conf)) {
3783 .psc_nbufs = MDS_NBUFS,
3784 .psc_bufsize = MDS_BUFSIZE,
3785 .psc_max_req_size = MDS_MAXREQSIZE,
3786 .psc_max_reply_size = MDS_MAXREPSIZE,
3787 .psc_req_portal = MDS_SETATTR_PORTAL,
3788 .psc_rep_portal = MDC_REPLY_PORTAL,
3789 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
3790 .psc_min_threads = min(max(mdt_num_threads, MDT_MIN_THREADS),
3792 .psc_max_threads = MDT_MAX_THREADS,
3793 .psc_ctx_tags = LCT_MD_THREAD
3796 m->mdt_setattr_service =
3797 ptlrpc_init_svc_conf(&conf, mdt_regular_handle,
3798 LUSTRE_MDT_NAME "_setattr",
3799 procfs_entry, target_print_req,"mdt_attr");
3801 if (!m->mdt_setattr_service) {
3802 CERROR("failed to start setattr service\n");
3803 GOTO(err_mdt_svc, rc = -ENOMEM);
3806 rc = ptlrpc_start_threads(NULL, m->mdt_setattr_service);
3808 GOTO(err_mdt_svc, rc);
3811 * sequence controller service configuration
3813 conf = (typeof(conf)) {
3814 .psc_nbufs = MDS_NBUFS,
3815 .psc_bufsize = MDS_BUFSIZE,
3816 .psc_max_req_size = SEQ_MAXREQSIZE,
3817 .psc_max_reply_size = SEQ_MAXREPSIZE,
3818 .psc_req_portal = SEQ_CONTROLLER_PORTAL,
3819 .psc_rep_portal = MDC_REPLY_PORTAL,
3820 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
3821 .psc_min_threads = SEQ_NUM_THREADS,
3822 .psc_max_threads = SEQ_NUM_THREADS,
3823 .psc_ctx_tags = LCT_MD_THREAD|LCT_DT_THREAD
3826 m->mdt_mdsc_service =
3827 ptlrpc_init_svc_conf(&conf, mdt_mdsc_handle,
3828 LUSTRE_MDT_NAME"_mdsc",
3829 procfs_entry, target_print_req,"mdt_mdsc");
3830 if (!m->mdt_mdsc_service) {
3831 CERROR("failed to start seq controller service\n");
3832 GOTO(err_mdt_svc, rc = -ENOMEM);
3835 rc = ptlrpc_start_threads(NULL, m->mdt_mdsc_service);
3837 GOTO(err_mdt_svc, rc);
3840 * metadata sequence server service configuration
3842 conf = (typeof(conf)) {
3843 .psc_nbufs = MDS_NBUFS,
3844 .psc_bufsize = MDS_BUFSIZE,
3845 .psc_max_req_size = SEQ_MAXREQSIZE,
3846 .psc_max_reply_size = SEQ_MAXREPSIZE,
3847 .psc_req_portal = SEQ_METADATA_PORTAL,
3848 .psc_rep_portal = MDC_REPLY_PORTAL,
3849 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
3850 .psc_min_threads = SEQ_NUM_THREADS,
3851 .psc_max_threads = SEQ_NUM_THREADS,
3852 .psc_ctx_tags = LCT_MD_THREAD|LCT_DT_THREAD
3855 m->mdt_mdss_service =
3856 ptlrpc_init_svc_conf(&conf, mdt_mdss_handle,
3857 LUSTRE_MDT_NAME"_mdss",
3858 procfs_entry, target_print_req,"mdt_mdss");
3859 if (!m->mdt_mdss_service) {
3860 CERROR("failed to start metadata seq server service\n");
3861 GOTO(err_mdt_svc, rc = -ENOMEM);
3864 rc = ptlrpc_start_threads(NULL, m->mdt_mdss_service);
3866 GOTO(err_mdt_svc, rc);
3870 * Data sequence server service configuration. We want to have really
3871 * cluster-wide sequences space. This is why we start only one sequence
3872 * controller which manages space.
3874 conf = (typeof(conf)) {
3875 .psc_nbufs = MDS_NBUFS,
3876 .psc_bufsize = MDS_BUFSIZE,
3877 .psc_max_req_size = SEQ_MAXREQSIZE,
3878 .psc_max_reply_size = SEQ_MAXREPSIZE,
3879 .psc_req_portal = SEQ_DATA_PORTAL,
3880 .psc_rep_portal = OSC_REPLY_PORTAL,
3881 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
3882 .psc_min_threads = SEQ_NUM_THREADS,
3883 .psc_max_threads = SEQ_NUM_THREADS,
3884 .psc_ctx_tags = LCT_MD_THREAD|LCT_DT_THREAD
3887 m->mdt_dtss_service =
3888 ptlrpc_init_svc_conf(&conf, mdt_dtss_handle,
3889 LUSTRE_MDT_NAME"_dtss",
3890 procfs_entry, target_print_req,"mdt_dtss");
3891 if (!m->mdt_dtss_service) {
3892 CERROR("failed to start data seq server service\n");
3893 GOTO(err_mdt_svc, rc = -ENOMEM);
3896 rc = ptlrpc_start_threads(NULL, m->mdt_dtss_service);
3898 GOTO(err_mdt_svc, rc);
3900 /* FLD service start */
3901 conf = (typeof(conf)) {
3902 .psc_nbufs = MDS_NBUFS,
3903 .psc_bufsize = MDS_BUFSIZE,
3904 .psc_max_req_size = FLD_MAXREQSIZE,
3905 .psc_max_reply_size = FLD_MAXREPSIZE,
3906 .psc_req_portal = FLD_REQUEST_PORTAL,
3907 .psc_rep_portal = MDC_REPLY_PORTAL,
3908 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
3909 .psc_min_threads = FLD_NUM_THREADS,
3910 .psc_max_threads = FLD_NUM_THREADS,
3911 .psc_ctx_tags = LCT_DT_THREAD|LCT_MD_THREAD
3914 m->mdt_fld_service =
3915 ptlrpc_init_svc_conf(&conf, mdt_fld_handle,
3916 LUSTRE_MDT_NAME"_fld",
3917 procfs_entry, target_print_req, "mdt_fld");
3918 if (!m->mdt_fld_service) {
3919 CERROR("failed to start fld service\n");
3920 GOTO(err_mdt_svc, rc = -ENOMEM);
3923 rc = ptlrpc_start_threads(NULL, m->mdt_fld_service);
3925 GOTO(err_mdt_svc, rc);
3928 * mds-mds service configuration. Separate portal is used to allow
3929 * mds-mds requests be not blocked during recovery.
3931 conf = (typeof(conf)) {
3932 .psc_nbufs = MDS_NBUFS,
3933 .psc_bufsize = MDS_BUFSIZE,
3934 .psc_max_req_size = MDS_MAXREQSIZE,
3935 .psc_max_reply_size = MDS_MAXREPSIZE,
3936 .psc_req_portal = MDS_MDS_PORTAL,
3937 .psc_rep_portal = MDC_REPLY_PORTAL,
3938 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
3939 .psc_min_threads = min(max(mdt_num_threads, MDT_MIN_THREADS),
3941 .psc_max_threads = MDT_MAX_THREADS,
3942 .psc_ctx_tags = LCT_MD_THREAD
3944 m->mdt_xmds_service =
3945 ptlrpc_init_svc_conf(&conf, mdt_xmds_handle,
3946 LUSTRE_MDT_NAME "_mds",
3947 procfs_entry, target_print_req,"mdt_xmds");
3949 if (m->mdt_xmds_service == NULL) {
3950 CERROR("failed to start readpage service\n");
3951 GOTO(err_mdt_svc, rc = -ENOMEM);
3954 rc = ptlrpc_start_threads(NULL, m->mdt_xmds_service);
3956 GOTO(err_mdt_svc, rc);
3961 mdt_stop_ptlrpc_service(m);
3966 static void mdt_stack_fini(const struct lu_env *env,
3967 struct mdt_device *m, struct lu_device *top)
3969 struct obd_device *obd = mdt2obd_dev(m);
3970 struct lustre_cfg_bufs *bufs;
3971 struct lustre_cfg *lcfg;
3972 struct mdt_thread_info *info;
3976 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
3977 LASSERT(info != NULL);
3979 bufs = &info->mti_u.bufs;
3980 /* process cleanup, pass mdt obd name to get obd umount flags */
3981 lustre_cfg_bufs_reset(bufs, obd->obd_name);
3986 lustre_cfg_bufs_set_string(bufs, 1, flags);
3987 lcfg = lustre_cfg_new(LCFG_CLEANUP, bufs);
3989 CERROR("Cannot alloc lcfg!\n");
3994 top->ld_ops->ldo_process_config(env, top, lcfg);
3995 lustre_cfg_free(lcfg);
3997 lu_stack_fini(env, top);
3998 m->mdt_child = NULL;
3999 m->mdt_bottom = NULL;
4002 static struct lu_device *mdt_layer_setup(struct lu_env *env,
4003 const char *typename,
4004 struct lu_device *child,
4005 struct lustre_cfg *cfg)
4007 const char *dev = lustre_cfg_string(cfg, 0);
4008 struct obd_type *type;
4009 struct lu_device_type *ldt;
4010 struct lu_device *d;
4015 type = class_get_type(typename);
4017 CERROR("Unknown type: '%s'\n", typename);
4018 GOTO(out, rc = -ENODEV);
4021 rc = lu_env_refill((struct lu_env *)env);
4023 CERROR("Failure to refill session: '%d'\n", rc);
4029 CERROR("type: '%s'\n", typename);
4030 GOTO(out_type, rc = -EINVAL);
4033 ldt->ldt_obd_type = type;
4034 d = ldt->ldt_ops->ldto_device_alloc(env, ldt, cfg);
4036 CERROR("Cannot allocate device: '%s'\n", typename);
4037 GOTO(out_type, rc = -ENODEV);
4040 LASSERT(child->ld_site);
4041 d->ld_site = child->ld_site;
4044 rc = ldt->ldt_ops->ldto_device_init(env, d, dev, child);
4046 CERROR("can't init device '%s', rc %d\n", typename, rc);
4047 GOTO(out_alloc, rc);
4050 lu_ref_add(&d->ld_reference, "lu-stack", &lu_site_init);
4055 ldt->ldt_ops->ldto_device_free(env, d);
4058 class_put_type(type);
4063 static int mdt_stack_init(struct lu_env *env,
4064 struct mdt_device *m,
4065 struct lustre_cfg *cfg,
4066 struct lustre_mount_info *lmi)
4068 struct lu_device *d = &m->mdt_md_dev.md_lu_dev;
4069 struct lu_device *tmp;
4070 struct md_device *md;
4071 struct lu_device *child_lu_dev;
4075 /* init the stack */
4076 tmp = mdt_layer_setup(env, LUSTRE_OSD_NAME, d, cfg);
4078 RETURN(PTR_ERR(tmp));
4080 m->mdt_bottom = lu2dt_dev(tmp);
4082 tmp = mdt_layer_setup(env, LUSTRE_MDD_NAME, d, cfg);
4084 GOTO(out, rc = PTR_ERR(tmp));
4089 tmp = mdt_layer_setup(env, LUSTRE_CMM_NAME, d, cfg);
4091 GOTO(out, rc = PTR_ERR(tmp));
4094 /*set mdd upcall device*/
4095 md_upcall_dev_set(md, lu2md_dev(d));
4098 /*set cmm upcall device*/
4099 md_upcall_dev_set(md, &m->mdt_md_dev);
4101 m->mdt_child = lu2md_dev(d);
4103 /* process setup config */
4104 tmp = &m->mdt_md_dev.md_lu_dev;
4105 rc = tmp->ld_ops->ldo_process_config(env, tmp, cfg);
4109 /* initialize local objects */
4110 child_lu_dev = &m->mdt_child->md_lu_dev;
4112 rc = child_lu_dev->ld_ops->ldo_prepare(env,
4113 &m->mdt_md_dev.md_lu_dev,
4116 /* fini from last known good lu_device */
4118 mdt_stack_fini(env, m, d);
4124 * setup CONFIG_ORIG context, used to access local config log.
4125 * this may need to be rewrite as part of llog rewrite for lu-api.
4127 static int mdt_obd_llog_setup(struct obd_device *obd,
4128 struct lustre_sb_info *lsi)
4132 LASSERT(obd->obd_fsops == NULL);
4134 obd->obd_fsops = fsfilt_get_ops(MT_STR(lsi->lsi_ldd));
4135 if (IS_ERR(obd->obd_fsops))
4136 return PTR_ERR(obd->obd_fsops);
4138 rc = fsfilt_setup(obd, lsi->lsi_srv_mnt->mnt_sb);
4140 fsfilt_put_ops(obd->obd_fsops);
4144 OBD_SET_CTXT_MAGIC(&obd->obd_lvfs_ctxt);
4145 obd->obd_lvfs_ctxt.pwdmnt = lsi->lsi_srv_mnt;
4146 obd->obd_lvfs_ctxt.pwd = lsi->lsi_srv_mnt->mnt_root;
4147 obd->obd_lvfs_ctxt.fs = get_ds();
4149 rc = llog_setup(obd, &obd->obd_olg, LLOG_CONFIG_ORIG_CTXT, obd,
4150 0, NULL, &llog_lvfs_ops);
4152 CERROR("llog_setup() failed: %d\n", rc);
4153 fsfilt_put_ops(obd->obd_fsops);
4159 static void mdt_obd_llog_cleanup(struct obd_device *obd)
4161 struct llog_ctxt *ctxt;
4163 ctxt = llog_get_context(obd, LLOG_CONFIG_ORIG_CTXT);
4167 if (obd->obd_fsops) {
4168 fsfilt_put_ops(obd->obd_fsops);
4169 obd->obd_fsops = NULL;
4173 static void mdt_fini(const struct lu_env *env, struct mdt_device *m)
4175 struct md_device *next = m->mdt_child;
4176 struct lu_device *d = &m->mdt_md_dev.md_lu_dev;
4177 struct lu_site *ls = d->ld_site;
4178 struct obd_device *obd = mdt2obd_dev(m);
4182 /* At this point, obd exports might still be on the "obd_zombie_exports"
4183 * list, and obd_zombie_impexp_thread() is trying to destroy them.
4184 * We wait a little bit until all exports (except the self-export)
4185 * have been destroyed, because the whole mdt stack might be accessed
4186 * in mdt_destroy_export(). This will not be a long time, maybe one or
4187 * two seconds are enough. This is not a problem while umounting.
4189 * The three references that should be remaining are the
4190 * obd_self_export and the attach and setup references.
4192 while (atomic_read(&obd->obd_refcount) > 3) {
4193 cfs_schedule_timeout(CFS_TASK_UNINT, cfs_time_seconds(1));
4195 if (waited > 5 && IS_PO2(waited))
4196 LCONSOLE_WARN("Waiting for obd_zombie_impexp_thread "
4197 "more than %d seconds to destroy all "
4198 "the exports. The current obd refcount ="
4199 " %d. Is it stuck there?\n",
4200 waited, atomic_read(&obd->obd_refcount));
4203 ping_evictor_stop();
4205 target_recovery_fini(obd);
4206 mdt_stop_ptlrpc_service(m);
4207 mdt_obd_llog_cleanup(obd);
4208 obd_zombie_barrier();
4209 #ifdef HAVE_QUOTA_SUPPORT
4210 next->md_ops->mdo_quota.mqo_cleanup(env, next);
4212 mdt_fs_cleanup(env, m);
4213 upcall_cache_cleanup(m->mdt_identity_cache);
4214 m->mdt_identity_cache = NULL;
4216 if (m->mdt_namespace != NULL) {
4217 ldlm_namespace_free(m->mdt_namespace, NULL, d->ld_obd->obd_force);
4218 d->ld_obd->obd_namespace = m->mdt_namespace = NULL;
4221 cfs_free_nidlist(&m->mdt_nosquash_nids);
4222 if (m->mdt_nosquash_str) {
4223 OBD_FREE(m->mdt_nosquash_str, m->mdt_nosquash_strlen);
4224 m->mdt_nosquash_str = NULL;
4225 m->mdt_nosquash_strlen = 0;
4228 mdt_seq_fini(env, m);
4229 mdt_seq_fini_cli(m);
4230 mdt_fld_fini(env, m);
4232 if (obd->obd_proc_exports_entry) {
4233 lprocfs_remove_proc_entry("clear", obd->obd_proc_exports_entry);
4234 obd->obd_proc_exports_entry = NULL;
4236 lprocfs_free_per_client_stats(obd);
4237 lprocfs_free_obd_stats(obd);
4238 ptlrpc_lprocfs_unregister_obd(d->ld_obd);
4239 lprocfs_obd_cleanup(d->ld_obd);
4241 sptlrpc_rule_set_free(&m->mdt_sptlrpc_rset);
4243 next->md_ops->mdo_init_capa_ctxt(env, next, 0, 0, 0, NULL);
4244 cfs_timer_disarm(&m->mdt_ck_timer);
4245 mdt_ck_thread_stop(m);
4250 mdt_stack_fini(env, m, md2lu_dev(m->mdt_child));
4253 struct md_site *mite;
4256 mite = lu_site2md(ls);
4260 LASSERT(atomic_read(&d->ld_ref) == 0);
4265 static int mdt_adapt_sptlrpc_conf(struct obd_device *obd, int initial)
4267 struct mdt_device *m = mdt_dev(obd->obd_lu_dev);
4268 struct sptlrpc_rule_set tmp_rset;
4271 sptlrpc_rule_set_init(&tmp_rset);
4272 rc = sptlrpc_conf_target_get_rules(obd, &tmp_rset, initial);
4274 CERROR("mdt %s: failed get sptlrpc rules: %d\n",
4279 sptlrpc_target_update_exp_flavor(obd, &tmp_rset);
4281 write_lock(&m->mdt_sptlrpc_lock);
4282 sptlrpc_rule_set_free(&m->mdt_sptlrpc_rset);
4283 m->mdt_sptlrpc_rset = tmp_rset;
4284 write_unlock(&m->mdt_sptlrpc_lock);
4289 static void fsoptions_to_mdt_flags(struct mdt_device *m, char *options)
4293 m->mdt_opts.mo_mds_capa = 1;
4294 m->mdt_opts.mo_oss_capa = 1;
4295 #ifdef CONFIG_FS_POSIX_ACL
4296 /* ACLs should be enabled by default (b=13829) */
4297 m->mdt_opts.mo_acl = 1;
4298 LCONSOLE_INFO("Enabling ACL\n");
4300 m->mdt_opts.mo_acl = 0;
4301 LCONSOLE_INFO("Disabling ACL\n");
4310 while (*p && *p != ',')
4314 if ((len == sizeof("user_xattr") - 1) &&
4315 (memcmp(options, "user_xattr", len) == 0)) {
4316 m->mdt_opts.mo_user_xattr = 1;
4317 LCONSOLE_INFO("Enabling user_xattr\n");
4318 } else if ((len == sizeof("nouser_xattr") - 1) &&
4319 (memcmp(options, "nouser_xattr", len) == 0)) {
4320 m->mdt_opts.mo_user_xattr = 0;
4321 LCONSOLE_INFO("Disabling user_xattr\n");
4322 } else if ((len == sizeof("noacl") - 1) &&
4323 (memcmp(options, "noacl", len) == 0)) {
4324 m->mdt_opts.mo_acl = 0;
4325 LCONSOLE_INFO("Disabling ACL\n");
4332 int mdt_postrecov(const struct lu_env *, struct mdt_device *);
4334 static int mdt_init0(const struct lu_env *env, struct mdt_device *m,
4335 struct lu_device_type *ldt, struct lustre_cfg *cfg)
4337 struct lprocfs_static_vars lvars;
4338 struct mdt_thread_info *info;
4339 struct obd_device *obd;
4340 const char *dev = lustre_cfg_string(cfg, 0);
4341 const char *num = lustre_cfg_string(cfg, 2);
4342 struct lustre_mount_info *lmi = NULL;
4343 struct lustre_sb_info *lsi;
4344 struct lustre_disk_data *ldd;
4346 struct md_site *mite;
4347 const char *identity_upcall = "NONE";
4348 #ifdef HAVE_QUOTA_SUPPORT
4349 struct md_device *next;
4355 md_device_init(&m->mdt_md_dev, ldt);
4357 * Environment (env) might be missing mdt_thread_key values at that
4358 * point, if device is allocated when mdt_thread_key is in QUIESCENT
4361 * Usually device allocation path doesn't use module key values, but
4362 * mdt has to do a lot of work here, so allocate key value.
4364 rc = lu_env_refill((struct lu_env *)env);
4368 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
4369 LASSERT(info != NULL);
4371 obd = class_name2obd(dev);
4372 LASSERT(obd != NULL);
4374 spin_lock_init(&m->mdt_transno_lock);
4376 m->mdt_max_mdsize = MAX_MD_SIZE;
4377 m->mdt_max_cookiesize = sizeof(struct llog_cookie);
4379 m->mdt_opts.mo_user_xattr = 0;
4380 m->mdt_opts.mo_acl = 0;
4381 m->mdt_opts.mo_cos = MDT_COS_DEFAULT;
4382 lmi = server_get_mount_2(dev);
4384 CERROR("Cannot get mount info for %s!\n", dev);
4387 lsi = s2lsi(lmi->lmi_sb);
4388 fsoptions_to_mdt_flags(m, lsi->lsi_lmd->lmd_opts);
4389 /* CMD is supported only in IAM mode */
4392 node_id = simple_strtol(num, NULL, 10);
4393 if (!(ldd->ldd_flags & LDD_F_IAM_DIR) && node_id) {
4394 CERROR("CMD Operation not allowed in IOP mode\n");
4395 GOTO(err_lmi, rc = -EINVAL);
4399 rwlock_init(&m->mdt_sptlrpc_lock);
4400 sptlrpc_rule_set_init(&m->mdt_sptlrpc_rset);
4402 spin_lock_init(&m->mdt_ioepoch_lock);
4403 m->mdt_opts.mo_compat_resname = 0;
4404 m->mdt_capa_timeout = CAPA_TIMEOUT;
4405 m->mdt_capa_alg = CAPA_HMAC_ALG_SHA1;
4406 m->mdt_ck_timeout = CAPA_KEY_TIMEOUT;
4407 m->mdt_squash_uid = 0;
4408 m->mdt_squash_gid = 0;
4409 CFS_INIT_LIST_HEAD(&m->mdt_nosquash_nids);
4410 m->mdt_nosquash_str = NULL;
4411 m->mdt_nosquash_strlen = 0;
4412 init_rwsem(&m->mdt_squash_sem);
4414 spin_lock_init(&m->mdt_client_bitmap_lock);
4416 OBD_ALLOC_PTR(mite);
4418 GOTO(err_lmi, rc = -ENOMEM);
4422 m->mdt_md_dev.md_lu_dev.ld_ops = &mdt_lu_ops;
4423 m->mdt_md_dev.md_lu_dev.ld_obd = obd;
4424 /* set this lu_device to obd, because error handling need it */
4425 obd->obd_lu_dev = &m->mdt_md_dev.md_lu_dev;
4427 rc = lu_site_init(s, &m->mdt_md_dev.md_lu_dev);
4429 CERROR("Can't init lu_site, rc %d\n", rc);
4430 GOTO(err_free_site, rc);
4433 lprocfs_mdt_init_vars(&lvars);
4434 rc = lprocfs_obd_setup(obd, lvars.obd_vars);
4436 CERROR("Can't init lprocfs, rc %d\n", rc);
4437 GOTO(err_fini_site, rc);
4439 ptlrpc_lprocfs_register_obd(obd);
4441 rc = mdt_procfs_init(m, dev);
4443 CERROR("Can't init MDT lprocfs, rc %d\n", rc);
4444 GOTO(err_fini_proc, rc);
4447 obd->obd_proc_exports_entry = proc_mkdir("exports",
4448 obd->obd_proc_entry);
4449 if (obd->obd_proc_exports_entry)
4450 lprocfs_add_simple(obd->obd_proc_exports_entry,
4451 "clear", lprocfs_nid_stats_clear_read,
4452 lprocfs_nid_stats_clear_write, obd, NULL);
4454 /* set server index */
4455 lu_site2md(s)->ms_node_id = node_id;
4457 /* failover is the default
4458 * FIXME: we do not failout mds0/mgs, which may cause some problems.
4459 * assumed whose ms_node_id == 0 XXX
4461 obd->obd_replayable = 1;
4462 /* No connection accepted until configurations will finish */
4463 obd->obd_no_conn = 1;
4465 if (cfg->lcfg_bufcount > 4 && LUSTRE_CFG_BUFLEN(cfg, 4) > 0) {
4466 char *str = lustre_cfg_string(cfg, 4);
4467 if (strchr(str, 'n')) {
4468 CWARN("%s: recovery disabled\n", obd->obd_name);
4469 obd->obd_replayable = 0;
4473 /* init the stack */
4474 rc = mdt_stack_init((struct lu_env *)env, m, cfg, lmi);
4476 CERROR("Can't init device stack, rc %d\n", rc);
4477 GOTO(err_fini_proc, rc);
4480 rc = mdt_fld_init(env, obd->obd_name, m);
4482 GOTO(err_fini_stack, rc);
4484 rc = mdt_seq_init(env, obd->obd_name, m);
4486 GOTO(err_fini_fld, rc);
4488 snprintf(info->mti_u.ns_name, sizeof info->mti_u.ns_name,
4489 LUSTRE_MDT_NAME"-%p", m);
4490 m->mdt_namespace = ldlm_namespace_new(obd, info->mti_u.ns_name,
4491 LDLM_NAMESPACE_SERVER,
4492 LDLM_NAMESPACE_GREEDY);
4493 if (m->mdt_namespace == NULL)
4494 GOTO(err_fini_seq, rc = -ENOMEM);
4496 ldlm_register_intent(m->mdt_namespace, mdt_intent_policy);
4497 /* set obd_namespace for compatibility with old code */
4498 obd->obd_namespace = m->mdt_namespace;
4500 /* XXX: to support suppgid for ACL, we enable identity_upcall
4501 * by default, otherwise, maybe got unexpected -EACCESS. */
4502 if (m->mdt_opts.mo_acl)
4503 identity_upcall = MDT_IDENTITY_UPCALL_PATH;
4505 m->mdt_identity_cache = upcall_cache_init(obd->obd_name, identity_upcall,
4506 &mdt_identity_upcall_cache_ops);
4507 if (IS_ERR(m->mdt_identity_cache)) {
4508 rc = PTR_ERR(m->mdt_identity_cache);
4509 m->mdt_identity_cache = NULL;
4510 GOTO(err_free_ns, rc);
4513 cfs_timer_init(&m->mdt_ck_timer, mdt_ck_timer_callback, m);
4515 rc = mdt_ck_thread_start(m);
4517 GOTO(err_free_ns, rc);
4519 rc = mdt_fs_setup(env, m, obd, lsi);
4523 rc = mdt_obd_llog_setup(obd, lsi);
4525 GOTO(err_fs_cleanup, rc);
4527 mdt_adapt_sptlrpc_conf(obd, 1);
4529 #ifdef HAVE_QUOTA_SUPPORT
4530 next = m->mdt_child;
4531 rc = next->md_ops->mdo_quota.mqo_setup(env, next, lmi->lmi_mnt);
4533 GOTO(err_llog_cleanup, rc);
4536 server_put_mount_2(dev, lmi->lmi_mnt);
4539 target_recovery_init(obd, mdt_recovery_handle);
4541 rc = mdt_start_ptlrpc_service(m);
4543 GOTO(err_recovery, rc);
4545 ping_evictor_start();
4547 rc = lu_site_init_finish(s);
4549 GOTO(err_stop_service, rc);
4551 if (obd->obd_recovering == 0)
4552 mdt_postrecov(env, m);
4554 mdt_init_capa_ctxt(env, m);
4556 /* Reduce the initial timeout on an MDS because it doesn't need such
4557 * a long timeout as an OST does. Adaptive timeouts will adjust this
4558 * value appropriately. */
4559 if (ldlm_timeout == LDLM_TIMEOUT_DEFAULT)
4560 ldlm_timeout = MDS_LDLM_TIMEOUT_DEFAULT;
4565 ping_evictor_stop();
4566 mdt_stop_ptlrpc_service(m);
4568 target_recovery_fini(obd);
4569 #ifdef HAVE_QUOTA_SUPPORT
4570 next->md_ops->mdo_quota.mqo_cleanup(env, next);
4573 mdt_obd_llog_cleanup(obd);
4575 mdt_fs_cleanup(env, m);
4577 cfs_timer_disarm(&m->mdt_ck_timer);
4578 mdt_ck_thread_stop(m);
4580 upcall_cache_cleanup(m->mdt_identity_cache);
4581 m->mdt_identity_cache = NULL;
4582 ldlm_namespace_free(m->mdt_namespace, NULL, 0);
4583 obd->obd_namespace = m->mdt_namespace = NULL;
4585 mdt_seq_fini(env, m);
4587 mdt_fld_fini(env, m);
4589 mdt_stack_fini(env, m, md2lu_dev(m->mdt_child));
4592 if (obd->obd_proc_exports_entry) {
4593 lprocfs_remove_proc_entry("clear", obd->obd_proc_exports_entry);
4594 obd->obd_proc_exports_entry = NULL;
4596 ptlrpc_lprocfs_unregister_obd(obd);
4597 lprocfs_obd_cleanup(obd);
4604 server_put_mount_2(dev, lmi->lmi_mnt);
4608 /* used by MGS to process specific configurations */
4609 static int mdt_process_config(const struct lu_env *env,
4610 struct lu_device *d, struct lustre_cfg *cfg)
4612 struct mdt_device *m = mdt_dev(d);
4613 struct md_device *md_next = m->mdt_child;
4614 struct lu_device *next = md2lu_dev(md_next);
4618 switch (cfg->lcfg_command) {
4620 struct lprocfs_static_vars lvars;
4621 struct obd_device *obd = d->ld_obd;
4624 * For interoperability between 1.8 and 2.0,
4625 * skip old "mdt.group_upcall" param.
4628 char *param = lustre_cfg_string(cfg, 1);
4629 if (param && !strncmp("mdt.group_upcall", param, 16)) {
4630 CWARN("For 1.8 interoperability, skip this"
4631 " mdt.group_upcall. It is obsolete\n");
4636 lprocfs_mdt_init_vars(&lvars);
4637 rc = class_process_proc_param(PARAM_MDT, lvars.obd_vars,
4639 if (rc > 0 || rc == -ENOSYS)
4640 /* we don't understand; pass it on */
4641 rc = next->ld_ops->ldo_process_config(env, next, cfg);
4646 * Add mdc hook to get first MDT uuid and connect it to
4647 * ls->controller to use for seq manager.
4649 rc = next->ld_ops->ldo_process_config(env, next, cfg);
4651 CERROR("Can't add mdc, rc %d\n", rc);
4653 rc = mdt_seq_init_cli(env, mdt_dev(d), cfg);
4656 /* others are passed further */
4657 rc = next->ld_ops->ldo_process_config(env, next, cfg);
4663 static struct lu_object *mdt_object_alloc(const struct lu_env *env,
4664 const struct lu_object_header *hdr,
4665 struct lu_device *d)
4667 struct mdt_object *mo;
4673 struct lu_object *o;
4674 struct lu_object_header *h;
4676 o = &mo->mot_obj.mo_lu;
4677 h = &mo->mot_header;
4678 lu_object_header_init(h);
4679 lu_object_init(o, h, d);
4680 lu_object_add_top(h, o);
4681 o->lo_ops = &mdt_obj_ops;
4687 static int mdt_object_init(const struct lu_env *env, struct lu_object *o,
4688 const struct lu_object_conf *_)
4690 struct mdt_device *d = mdt_dev(o->lo_dev);
4691 struct lu_device *under;
4692 struct lu_object *below;
4696 CDEBUG(D_INFO, "object init, fid = "DFID"\n",
4697 PFID(lu_object_fid(o)));
4699 under = &d->mdt_child->md_lu_dev;
4700 below = under->ld_ops->ldo_object_alloc(env, o->lo_header, under);
4701 if (below != NULL) {
4702 lu_object_add(o, below);
4709 static void mdt_object_free(const struct lu_env *env, struct lu_object *o)
4711 struct mdt_object *mo = mdt_obj(o);
4712 struct lu_object_header *h;
4716 CDEBUG(D_INFO, "object free, fid = "DFID"\n",
4717 PFID(lu_object_fid(o)));
4720 lu_object_header_fini(h);
4725 static const struct lu_device_operations mdt_lu_ops = {
4726 .ldo_object_alloc = mdt_object_alloc,
4727 .ldo_process_config = mdt_process_config,
4730 static const struct lu_object_operations mdt_obj_ops = {
4731 .loo_object_init = mdt_object_init,
4732 .loo_object_free = mdt_object_free
4735 static int mdt_obd_set_info_async(struct obd_export *exp,
4736 __u32 keylen, void *key,
4737 __u32 vallen, void *val,
4738 struct ptlrpc_request_set *set)
4740 struct obd_device *obd = exp->exp_obd;
4746 if (KEY_IS(KEY_SPTLRPC_CONF)) {
4747 rc = mdt_adapt_sptlrpc_conf(obd, 0);
4754 /* mds_connect_internal */
4755 static int mdt_connect_internal(struct obd_export *exp,
4756 struct mdt_device *mdt,
4757 struct obd_connect_data *data)
4760 data->ocd_connect_flags &= MDT_CONNECT_SUPPORTED;
4761 data->ocd_ibits_known &= MDS_INODELOCK_FULL;
4763 /* If no known bits (which should not happen, probably,
4764 as everybody should support LOOKUP and UPDATE bits at least)
4765 revert to compat mode with plain locks. */
4766 if (!data->ocd_ibits_known &&
4767 data->ocd_connect_flags & OBD_CONNECT_IBITS)
4768 data->ocd_connect_flags &= ~OBD_CONNECT_IBITS;
4770 if (!mdt->mdt_opts.mo_acl)
4771 data->ocd_connect_flags &= ~OBD_CONNECT_ACL;
4773 if (!mdt->mdt_opts.mo_user_xattr)
4774 data->ocd_connect_flags &= ~OBD_CONNECT_XATTR;
4776 spin_lock(&exp->exp_lock);
4777 exp->exp_connect_flags = data->ocd_connect_flags;
4778 spin_unlock(&exp->exp_lock);
4779 data->ocd_version = LUSTRE_VERSION_CODE;
4780 exp->exp_mdt_data.med_ibits_known = data->ocd_ibits_known;
4784 if (mdt->mdt_opts.mo_acl &&
4785 ((exp->exp_connect_flags & OBD_CONNECT_ACL) == 0)) {
4786 CWARN("%s: MDS requires ACL support but client does not\n",
4787 mdt->mdt_md_dev.md_lu_dev.ld_obd->obd_name);
4792 if ((exp->exp_connect_flags & OBD_CONNECT_FID) == 0) {
4793 CWARN("%s: MDS requires FID support, but client not\n",
4794 mdt->mdt_md_dev.md_lu_dev.ld_obd->obd_name);
4801 static int mdt_connect_check_sptlrpc(struct mdt_device *mdt,
4802 struct obd_export *exp,
4803 struct ptlrpc_request *req)
4805 struct sptlrpc_flavor flvr;
4808 if (exp->exp_flvr.sf_rpc == SPTLRPC_FLVR_INVALID) {
4809 read_lock(&mdt->mdt_sptlrpc_lock);
4810 sptlrpc_target_choose_flavor(&mdt->mdt_sptlrpc_rset,
4814 read_unlock(&mdt->mdt_sptlrpc_lock);
4816 spin_lock(&exp->exp_lock);
4818 exp->exp_sp_peer = req->rq_sp_from;
4819 exp->exp_flvr = flvr;
4821 if (exp->exp_flvr.sf_rpc != SPTLRPC_FLVR_ANY &&
4822 exp->exp_flvr.sf_rpc != req->rq_flvr.sf_rpc) {
4823 CERROR("unauthorized rpc flavor %x from %s, "
4824 "expect %x\n", req->rq_flvr.sf_rpc,
4825 libcfs_nid2str(req->rq_peer.nid),
4826 exp->exp_flvr.sf_rpc);
4830 spin_unlock(&exp->exp_lock);
4832 if (exp->exp_sp_peer != req->rq_sp_from) {
4833 CERROR("RPC source %s doesn't match %s\n",
4834 sptlrpc_part2name(req->rq_sp_from),
4835 sptlrpc_part2name(exp->exp_sp_peer));
4838 rc = sptlrpc_target_export_check(exp, req);
4845 /* mds_connect copy */
4846 static int mdt_obd_connect(const struct lu_env *env,
4847 struct obd_export **exp, struct obd_device *obd,
4848 struct obd_uuid *cluuid,
4849 struct obd_connect_data *data,
4852 struct mdt_thread_info *info;
4853 struct lsd_client_data *lcd;
4854 struct obd_export *lexp;
4855 struct lustre_handle conn = { 0 };
4856 struct mdt_device *mdt;
4857 struct ptlrpc_request *req;
4861 LASSERT(env != NULL);
4862 if (!exp || !obd || !cluuid)
4865 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
4866 req = info->mti_pill->rc_req;
4867 mdt = mdt_dev(obd->obd_lu_dev);
4869 rc = class_connect(&conn, obd, cluuid);
4873 lexp = class_conn2export(&conn);
4874 LASSERT(lexp != NULL);
4876 rc = mdt_connect_check_sptlrpc(mdt, lexp, req);
4880 rc = mdt_connect_internal(lexp, mdt, data);
4884 struct mdt_thread_info *mti;
4885 mti = lu_context_key_get(&env->le_ctx,
4887 LASSERT(mti != NULL);
4888 mti->mti_exp = lexp;
4889 memcpy(lcd->lcd_uuid, cluuid, sizeof lcd->lcd_uuid);
4890 lexp->exp_mdt_data.med_lcd = lcd;
4891 rc = mdt_client_new(env, mdt);
4894 lexp->exp_mdt_data.med_lcd = NULL;
4896 mdt_export_stats_init(obd, lexp, localdata);
4904 class_disconnect(lexp);
4911 static int mdt_obd_reconnect(const struct lu_env *env,
4912 struct obd_export *exp, struct obd_device *obd,
4913 struct obd_uuid *cluuid,
4914 struct obd_connect_data *data,
4917 struct mdt_thread_info *info;
4918 struct mdt_device *mdt;
4919 struct ptlrpc_request *req;
4923 if (exp == NULL || obd == NULL || cluuid == NULL)
4926 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
4927 req = info->mti_pill->rc_req;
4928 mdt = mdt_dev(obd->obd_lu_dev);
4930 rc = mdt_connect_check_sptlrpc(mdt, exp, req);
4934 rc = mdt_connect_internal(exp, mdt_dev(obd->obd_lu_dev), data);
4936 mdt_export_stats_init(obd, exp, localdata);
4941 static int mdt_obd_disconnect(struct obd_export *exp)
4943 struct mdt_device *mdt = mdt_dev(exp->exp_obd->obd_lu_dev);
4948 class_export_get(exp);
4950 /* Disconnect early so that clients can't keep using export */
4951 rc = class_disconnect(exp);
4952 if (mdt->mdt_namespace != NULL || exp->exp_obd->obd_namespace != NULL)
4953 ldlm_cancel_locks_for_export(exp);
4955 /* release nid stat refererence */
4956 lprocfs_exp_cleanup(exp);
4958 /* complete all outstanding replies */
4959 spin_lock(&exp->exp_lock);
4960 while (!list_empty(&exp->exp_outstanding_replies)) {
4961 struct ptlrpc_reply_state *rs =
4962 list_entry(exp->exp_outstanding_replies.next,
4963 struct ptlrpc_reply_state, rs_exp_list);
4964 struct ptlrpc_service *svc = rs->rs_service;
4966 spin_lock(&svc->srv_lock);
4967 list_del_init(&rs->rs_exp_list);
4968 spin_lock(&rs->rs_lock);
4969 ptlrpc_schedule_difficult_reply(rs);
4970 spin_unlock(&rs->rs_lock);
4971 spin_unlock(&svc->srv_lock);
4973 spin_unlock(&exp->exp_lock);
4975 class_export_put(exp);
4979 /* FIXME: Can we avoid using these two interfaces? */
4980 static int mdt_init_export(struct obd_export *exp)
4982 struct mdt_export_data *med = &exp->exp_mdt_data;
4986 CFS_INIT_LIST_HEAD(&med->med_open_head);
4987 spin_lock_init(&med->med_open_lock);
4988 sema_init(&med->med_idmap_sem, 1);
4989 med->med_idmap = NULL;
4990 spin_lock(&exp->exp_lock);
4991 exp->exp_connecting = 1;
4992 spin_unlock(&exp->exp_lock);
4993 rc = ldlm_init_export(exp);
4995 CERROR("Error %d while initializing export\n", rc);
4999 static int mdt_destroy_export(struct obd_export *export)
5001 struct mdt_export_data *med;
5002 struct obd_device *obd = export->exp_obd;
5003 struct mdt_device *mdt;
5004 struct mdt_thread_info *info;
5009 CFS_LIST_HEAD(closing_list);
5010 struct mdt_file_data *mfd, *n;
5014 med = &export->exp_mdt_data;
5015 if (exp_connect_rmtclient(export))
5016 mdt_cleanup_idmap(med);
5018 target_destroy_export(export);
5019 ldlm_destroy_export(export);
5021 if (obd_uuid_equals(&export->exp_client_uuid, &obd->obd_uuid))
5024 mdt = mdt_dev(obd->obd_lu_dev);
5025 LASSERT(mdt != NULL);
5027 rc = lu_env_init(&env, LCT_MD_THREAD);
5031 info = lu_context_key_get(&env.le_ctx, &mdt_thread_key);
5032 LASSERT(info != NULL);
5033 memset(info, 0, sizeof *info);
5034 info->mti_env = &env;
5035 info->mti_mdt = mdt;
5036 info->mti_exp = export;
5038 ma = &info->mti_attr;
5039 lmm_size = ma->ma_lmm_size = mdt->mdt_max_mdsize;
5040 cookie_size = ma->ma_cookie_size = mdt->mdt_max_cookiesize;
5041 OBD_ALLOC(ma->ma_lmm, lmm_size);
5042 OBD_ALLOC(ma->ma_cookie, cookie_size);
5044 if (ma->ma_lmm == NULL || ma->ma_cookie == NULL)
5045 GOTO(out, rc = -ENOMEM);
5046 ma->ma_need = MA_LOV | MA_COOKIE;
5048 /* Close any open files (which may also cause orphan unlinking). */
5049 spin_lock(&med->med_open_lock);
5050 while (!list_empty(&med->med_open_head)) {
5051 struct list_head *tmp = med->med_open_head.next;
5052 mfd = list_entry(tmp, struct mdt_file_data, mfd_list);
5054 /* Remove mfd handle so it can't be found again.
5055 * We are consuming the mfd_list reference here. */
5056 class_handle_unhash(&mfd->mfd_handle);
5057 list_move_tail(&mfd->mfd_list, &closing_list);
5059 spin_unlock(&med->med_open_lock);
5061 list_for_each_entry_safe(mfd, n, &closing_list, mfd_list) {
5062 list_del_init(&mfd->mfd_list);
5063 mdt_mfd_close(info, mfd);
5064 /* TODO: if we close the unlinked file,
5065 * we need to remove its objects from OST */
5066 memset(&ma->ma_attr, 0, sizeof(ma->ma_attr));
5067 spin_lock(&med->med_open_lock);
5068 ma->ma_lmm_size = lmm_size;
5069 ma->ma_cookie_size = cookie_size;
5070 ma->ma_need = MA_LOV | MA_COOKIE;
5072 spin_unlock(&med->med_open_lock);
5075 info->mti_mdt = NULL;
5076 mdt_client_del(&env, mdt);
5081 OBD_FREE(ma->ma_lmm, lmm_size);
5085 OBD_FREE(ma->ma_cookie, cookie_size);
5086 ma->ma_cookie = NULL;
5093 static void mdt_allow_cli(struct mdt_device *m, unsigned int flag)
5095 if (flag & CONFIG_LOG)
5096 m->mdt_fl_cfglog = 1;
5098 /* also notify active event */
5099 if (flag & CONFIG_SYNC)
5100 m->mdt_fl_synced = 1;
5102 if (m->mdt_fl_cfglog && m->mdt_fl_synced)
5103 /* Open for clients */
5104 m->mdt_md_dev.md_lu_dev.ld_obd->obd_no_conn = 0;
5107 static int mdt_upcall(const struct lu_env *env, struct md_device *md,
5108 enum md_upcall_event ev)
5110 struct mdt_device *m = mdt_dev(&md->md_lu_dev);
5111 struct md_device *next = m->mdt_child;
5112 struct mdt_thread_info *mti;
5118 rc = next->md_ops->mdo_maxsize_get(env, next,
5120 &m->mdt_max_cookiesize);
5121 CDEBUG(D_INFO, "get max mdsize %d max cookiesize %d\n",
5122 m->mdt_max_mdsize, m->mdt_max_cookiesize);
5123 mdt_allow_cli(m, CONFIG_SYNC);
5124 #ifdef HAVE_QUOTA_SUPPORT
5125 if (md->md_lu_dev.ld_obd->obd_recovering == 0)
5126 next->md_ops->mdo_quota.mqo_recovery(env, next);
5130 mti = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
5131 mti->mti_no_need_trans = 1;
5132 CDEBUG(D_INFO, "disable mdt trans for this thread\n");
5135 /* Check that MDT is not yet configured */
5136 LASSERT(!m->mdt_fl_cfglog);
5139 CERROR("invalid event\n");
5146 static int mdt_obd_notify(struct obd_device *host,
5147 struct obd_device *watched,
5148 enum obd_notify_event ev, void *data)
5150 struct mdt_device *mdt = mdt_dev(host->obd_lu_dev);
5151 #ifdef HAVE_QUOTA_SUPPORT
5152 struct md_device *next = mdt->mdt_child;
5157 case OBD_NOTIFY_CONFIG:
5158 mdt_allow_cli(mdt, (unsigned long)data);
5160 #ifdef HAVE_QUOTA_SUPPORT
5161 /* quota_type has been processed, we can now handle
5162 * incoming quota requests */
5163 next->md_ops->mdo_quota.mqo_notify(NULL, next);
5167 CDEBUG(D_INFO, "Unhandled notification %#x\n", ev);
5172 static int mdt_ioc_fid2path(struct lu_env *env, struct mdt_device *mdt,
5173 struct obd_ioctl_data *data)
5175 struct lu_context ioctl_session;
5176 struct mdt_object *obj;
5180 int pathlen = data->ioc_plen1;
5186 fid = (struct lu_fid *)data->ioc_inlbuf1;
5187 memcpy(&recno, data->ioc_inlbuf2, sizeof(recno));
5188 memcpy(&linkno, data->ioc_inlbuf3, sizeof(linkno));
5189 CDEBUG(D_IOCTL, "path get "DFID" from "LPU64" #%d\n",
5190 PFID(fid), recno, linkno);
5192 if (!fid_is_sane(fid))
5198 rc = lu_context_init(&ioctl_session, LCT_SESSION);
5201 ioctl_session.lc_thread = (struct ptlrpc_thread *)cfs_current();
5202 lu_context_enter(&ioctl_session);
5203 env->le_ses = &ioctl_session;
5205 OBD_ALLOC(path, pathlen);
5207 GOTO(out_context, rc = -ENOMEM);
5209 obj = mdt_object_find(env, mdt, fid);
5210 if (obj == NULL || IS_ERR(obj)) {
5211 CDEBUG(D_IOCTL, "no object "DFID": %ld\n", PFID(fid),
5213 GOTO(out_free, rc = -EINVAL);
5216 rc = lu_object_exists(&obj->mot_obj.mo_lu);
5222 mdt_object_put(env, obj);
5223 CDEBUG(D_IOCTL, "nonlocal object "DFID": %d\n", PFID(fid),
5228 rc = mo_path(env, md_object_next(&obj->mot_obj), path, pathlen, recno,
5230 mdt_object_put(env, obj);
5234 if (copy_to_user(data->ioc_pbuf1, path, pathlen))
5237 memcpy(data->ioc_inlbuf3, &linkno, sizeof(linkno));
5241 OBD_FREE(path, pathlen);
5243 lu_context_exit(&ioctl_session);
5244 lu_context_fini(&ioctl_session);
5248 static int mdt_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
5249 void *karg, void *uarg)
5252 struct obd_device *obd = exp->exp_obd;
5253 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
5254 struct dt_device *dt = mdt->mdt_bottom;
5258 CDEBUG(D_IOCTL, "handling ioctl cmd %#x\n", cmd);
5259 rc = lu_env_init(&env, LCT_MD_THREAD);
5265 rc = mdt_device_sync(&env, mdt);
5267 case OBD_IOC_SET_READONLY:
5268 dt->dd_ops->dt_ro(&env, dt);
5270 case OBD_IOC_ABORT_RECOVERY:
5271 CERROR("Aborting recovery for device %s\n", obd->obd_name);
5272 target_stop_recovery_thread(obd);
5275 case OBD_IOC_FID2PATH:
5276 rc = mdt_ioc_fid2path(&env, mdt, karg);
5279 CERROR("Not supported cmd = %d for device %s\n",
5280 cmd, obd->obd_name);
5288 int mdt_postrecov(const struct lu_env *env, struct mdt_device *mdt)
5290 struct lu_device *ld = md2lu_dev(mdt->mdt_child);
5291 struct obd_device *obd = mdt2obd_dev(mdt);
5292 #ifdef HAVE_QUOTA_SUPPORT
5293 struct md_device *next = mdt->mdt_child;
5297 /* if some clients didn't participate in recovery then we can possibly
5298 * lost sequence. Now we should increase sequence for safe value */
5299 lost = obd->obd_max_recoverable_clients - obd->obd_connected_clients;
5300 mdt_seq_adjust(env, mdt, lost);
5302 rc = ld->ld_ops->ldo_recovery_complete(env, ld);
5303 #ifdef HAVE_QUOTA_SUPPORT
5304 next->md_ops->mdo_quota.mqo_recovery(env, next);
5309 int mdt_obd_postrecov(struct obd_device *obd)
5314 rc = lu_env_init(&env, LCT_MD_THREAD);
5317 rc = mdt_postrecov(&env, mdt_dev(obd->obd_lu_dev));
5322 static struct obd_ops mdt_obd_device_ops = {
5323 .o_owner = THIS_MODULE,
5324 .o_set_info_async = mdt_obd_set_info_async,
5325 .o_connect = mdt_obd_connect,
5326 .o_reconnect = mdt_obd_reconnect,
5327 .o_disconnect = mdt_obd_disconnect,
5328 .o_init_export = mdt_init_export,
5329 .o_destroy_export = mdt_destroy_export,
5330 .o_iocontrol = mdt_iocontrol,
5331 .o_postrecov = mdt_obd_postrecov,
5332 .o_notify = mdt_obd_notify
5335 static struct lu_device* mdt_device_fini(const struct lu_env *env,
5336 struct lu_device *d)
5338 struct mdt_device *m = mdt_dev(d);
5345 static struct lu_device *mdt_device_free(const struct lu_env *env,
5346 struct lu_device *d)
5348 struct mdt_device *m = mdt_dev(d);
5351 md_device_fini(&m->mdt_md_dev);
5356 static struct lu_device *mdt_device_alloc(const struct lu_env *env,
5357 struct lu_device_type *t,
5358 struct lustre_cfg *cfg)
5360 struct lu_device *l;
5361 struct mdt_device *m;
5367 l = &m->mdt_md_dev.md_lu_dev;
5368 rc = mdt_init0(env, m, t, cfg);
5370 mdt_device_free(env, l);
5374 md_upcall_init(&m->mdt_md_dev, mdt_upcall);
5376 l = ERR_PTR(-ENOMEM);
5380 /* context key constructor/destructor: mdt_key_init, mdt_key_fini */
5381 LU_KEY_INIT_FINI(mdt, struct mdt_thread_info);
5383 /* context key: mdt_thread_key */
5384 LU_CONTEXT_KEY_DEFINE(mdt, LCT_MD_THREAD);
5386 /* context key constructor/destructor: mdt_txn_key_init, mdt_txn_key_fini */
5387 LU_KEY_INIT_FINI(mdt_txn, struct mdt_txn_info);
5389 struct lu_context_key mdt_txn_key = {
5390 .lct_tags = LCT_TX_HANDLE,
5391 .lct_init = mdt_txn_key_init,
5392 .lct_fini = mdt_txn_key_fini
5395 struct md_ucred *mdt_ucred(const struct mdt_thread_info *info)
5397 return md_ucred(info->mti_env);
5401 * Enable/disable COS.
5403 * Set/Clear the COS flag in mdt options.
5405 * \param mdt mdt device
5406 * \param val 0 disables COS, other values enable COS
5408 void mdt_enable_cos(struct mdt_device *mdt, int val)
5413 mdt->mdt_opts.mo_cos = !!val;
5414 rc = lu_env_init(&env, LCT_MD_THREAD);
5415 if (unlikely(rc != 0)) {
5416 CWARN("lu_env initialization failed with rc = %d,"
5417 "cannot sync\n", rc);
5420 mdt_device_sync(&env, mdt);
5427 * Return COS flag status/
5429 * \param mdt mdt device
5431 int mdt_cos_is_enabled(struct mdt_device *mdt)
5433 return mdt->mdt_opts.mo_cos != 0;
5436 /* type constructor/destructor: mdt_type_init, mdt_type_fini */
5437 LU_TYPE_INIT_FINI(mdt, &mdt_thread_key, &mdt_txn_key);
5439 static struct lu_device_type_operations mdt_device_type_ops = {
5440 .ldto_init = mdt_type_init,
5441 .ldto_fini = mdt_type_fini,
5443 .ldto_start = mdt_type_start,
5444 .ldto_stop = mdt_type_stop,
5446 .ldto_device_alloc = mdt_device_alloc,
5447 .ldto_device_free = mdt_device_free,
5448 .ldto_device_fini = mdt_device_fini
5451 static struct lu_device_type mdt_device_type = {
5452 .ldt_tags = LU_DEVICE_MD,
5453 .ldt_name = LUSTRE_MDT_NAME,
5454 .ldt_ops = &mdt_device_type_ops,
5455 .ldt_ctx_tags = LCT_MD_THREAD
5458 static struct lu_local_obj_desc mdt_last_recv = {
5459 .llod_name = LAST_RCVD,
5460 .llod_oid = MDT_LAST_RECV_OID,
5464 static int __init mdt_mod_init(void)
5466 struct lprocfs_static_vars lvars;
5469 llo_local_obj_register(&mdt_last_recv);
5471 mdt_num_threads = MDT_NUM_THREADS;
5472 lprocfs_mdt_init_vars(&lvars);
5473 rc = class_register_type(&mdt_obd_device_ops, NULL,
5474 lvars.module_vars, LUSTRE_MDT_NAME,
5480 static void __exit mdt_mod_exit(void)
5482 llo_local_obj_unregister(&mdt_last_recv);
5483 class_unregister_type(LUSTRE_MDT_NAME);
5487 #define DEF_HNDL(prefix, base, suffix, flags, opc, fn, fmt) \
5488 [prefix ## _ ## opc - prefix ## _ ## base] = { \
5490 .mh_fail_id = OBD_FAIL_ ## prefix ## _ ## opc ## suffix, \
5491 .mh_opc = prefix ## _ ## opc, \
5492 .mh_flags = flags, \
5497 #define DEF_MDT_HNDL(flags, name, fn, fmt) \
5498 DEF_HNDL(MDS, GETATTR, _NET, flags, name, fn, fmt)
5500 #define DEF_SEQ_HNDL(flags, name, fn, fmt) \
5501 DEF_HNDL(SEQ, QUERY, _NET, flags, name, fn, fmt)
5503 #define DEF_FLD_HNDL(flags, name, fn, fmt) \
5504 DEF_HNDL(FLD, QUERY, _NET, flags, name, fn, fmt)
5506 * Request with a format known in advance
5508 #define DEF_MDT_HNDL_F(flags, name, fn) \
5509 DEF_HNDL(MDS, GETATTR, _NET, flags, name, fn, &RQF_MDS_ ## name)
5511 #define DEF_SEQ_HNDL_F(flags, name, fn) \
5512 DEF_HNDL(SEQ, QUERY, _NET, flags, name, fn, &RQF_SEQ_ ## name)
5514 #define DEF_FLD_HNDL_F(flags, name, fn) \
5515 DEF_HNDL(FLD, QUERY, _NET, flags, name, fn, &RQF_FLD_ ## name)
5517 * Request with a format we do not yet know
5519 #define DEF_MDT_HNDL_0(flags, name, fn) \
5520 DEF_HNDL(MDS, GETATTR, _NET, flags, name, fn, NULL)
5522 static struct mdt_handler mdt_mds_ops[] = {
5523 DEF_MDT_HNDL_F(0, CONNECT, mdt_connect),
5524 DEF_MDT_HNDL_F(0, DISCONNECT, mdt_disconnect),
5525 DEF_MDT_HNDL_F(0, SET_INFO, mdt_set_info),
5526 DEF_MDT_HNDL_F(0 |HABEO_REFERO, GETSTATUS, mdt_getstatus),
5527 DEF_MDT_HNDL_F(HABEO_CORPUS, GETATTR, mdt_getattr),
5528 DEF_MDT_HNDL_F(HABEO_CORPUS|HABEO_REFERO, GETATTR_NAME, mdt_getattr_name),
5529 DEF_MDT_HNDL_F(HABEO_CORPUS, GETXATTR, mdt_getxattr),
5530 DEF_MDT_HNDL_F(0 |HABEO_REFERO, STATFS, mdt_statfs),
5531 DEF_MDT_HNDL_F(0 |MUTABOR, REINT, mdt_reint),
5532 DEF_MDT_HNDL_F(HABEO_CORPUS, CLOSE, mdt_close),
5533 DEF_MDT_HNDL_F(HABEO_CORPUS, DONE_WRITING, mdt_done_writing),
5534 DEF_MDT_HNDL_F(0 |HABEO_REFERO, PIN, mdt_pin),
5535 DEF_MDT_HNDL_0(0, SYNC, mdt_sync),
5536 DEF_MDT_HNDL_F(HABEO_CORPUS|HABEO_REFERO, IS_SUBDIR, mdt_is_subdir),
5537 #ifdef HAVE_QUOTA_SUPPORT
5538 DEF_MDT_HNDL_F(0, QUOTACHECK, mdt_quotacheck_handle),
5539 DEF_MDT_HNDL_F(0, QUOTACTL, mdt_quotactl_handle)
5543 #define DEF_OBD_HNDL(flags, name, fn) \
5544 DEF_HNDL(OBD, PING, _NET, flags, name, fn, NULL)
5547 static struct mdt_handler mdt_obd_ops[] = {
5548 DEF_OBD_HNDL(0, PING, mdt_obd_ping),
5549 DEF_OBD_HNDL(0, LOG_CANCEL, mdt_obd_log_cancel),
5550 DEF_OBD_HNDL(0, QC_CALLBACK, mdt_obd_qc_callback)
5553 #define DEF_DLM_HNDL_0(flags, name, fn) \
5554 DEF_HNDL(LDLM, ENQUEUE, , flags, name, fn, NULL)
5555 #define DEF_DLM_HNDL_F(flags, name, fn) \
5556 DEF_HNDL(LDLM, ENQUEUE, , flags, name, fn, &RQF_LDLM_ ## name)
5558 static struct mdt_handler mdt_dlm_ops[] = {
5559 DEF_DLM_HNDL_F(HABEO_CLAVIS, ENQUEUE, mdt_enqueue),
5560 DEF_DLM_HNDL_0(HABEO_CLAVIS, CONVERT, mdt_convert),
5561 DEF_DLM_HNDL_0(0, BL_CALLBACK, mdt_bl_callback),
5562 DEF_DLM_HNDL_0(0, CP_CALLBACK, mdt_cp_callback)
5565 static struct mdt_handler mdt_llog_ops[] = {
5568 #define DEF_SEC_CTX_HNDL(name, fn) \
5569 DEF_HNDL(SEC_CTX, INIT, _NET, 0, name, fn, NULL)
5571 static struct mdt_handler mdt_sec_ctx_ops[] = {
5572 DEF_SEC_CTX_HNDL(INIT, mdt_sec_ctx_handle),
5573 DEF_SEC_CTX_HNDL(INIT_CONT, mdt_sec_ctx_handle),
5574 DEF_SEC_CTX_HNDL(FINI, mdt_sec_ctx_handle)
5577 static struct mdt_opc_slice mdt_regular_handlers[] = {
5579 .mos_opc_start = MDS_GETATTR,
5580 .mos_opc_end = MDS_LAST_OPC,
5581 .mos_hs = mdt_mds_ops
5584 .mos_opc_start = OBD_PING,
5585 .mos_opc_end = OBD_LAST_OPC,
5586 .mos_hs = mdt_obd_ops
5589 .mos_opc_start = LDLM_ENQUEUE,
5590 .mos_opc_end = LDLM_LAST_OPC,
5591 .mos_hs = mdt_dlm_ops
5594 .mos_opc_start = LLOG_ORIGIN_HANDLE_CREATE,
5595 .mos_opc_end = LLOG_LAST_OPC,
5596 .mos_hs = mdt_llog_ops
5599 .mos_opc_start = SEC_CTX_INIT,
5600 .mos_opc_end = SEC_LAST_OPC,
5601 .mos_hs = mdt_sec_ctx_ops
5608 static struct mdt_handler mdt_readpage_ops[] = {
5609 DEF_MDT_HNDL_F(0, CONNECT, mdt_connect),
5610 DEF_MDT_HNDL_F(HABEO_CORPUS|HABEO_REFERO, READPAGE, mdt_readpage),
5611 #ifdef HAVE_SPLIT_SUPPORT
5612 DEF_MDT_HNDL_F(HABEO_CORPUS|HABEO_REFERO, WRITEPAGE, mdt_writepage),
5616 * XXX: this is ugly and should be fixed one day, see mdc_close() for
5617 * detailed comments. --umka
5619 DEF_MDT_HNDL_F(HABEO_CORPUS, CLOSE, mdt_close),
5620 DEF_MDT_HNDL_F(HABEO_CORPUS, DONE_WRITING, mdt_done_writing),
5623 static struct mdt_opc_slice mdt_readpage_handlers[] = {
5625 .mos_opc_start = MDS_GETATTR,
5626 .mos_opc_end = MDS_LAST_OPC,
5627 .mos_hs = mdt_readpage_ops
5634 static struct mdt_handler mdt_xmds_ops[] = {
5635 DEF_MDT_HNDL_F(0, CONNECT, mdt_connect),
5636 DEF_MDT_HNDL_F(HABEO_CORPUS , GETATTR, mdt_getattr),
5637 DEF_MDT_HNDL_F(0 | MUTABOR , REINT, mdt_reint),
5638 DEF_MDT_HNDL_F(HABEO_CORPUS|HABEO_REFERO, IS_SUBDIR, mdt_is_subdir),
5641 static struct mdt_opc_slice mdt_xmds_handlers[] = {
5643 .mos_opc_start = MDS_GETATTR,
5644 .mos_opc_end = MDS_LAST_OPC,
5645 .mos_hs = mdt_xmds_ops
5648 .mos_opc_start = OBD_PING,
5649 .mos_opc_end = OBD_LAST_OPC,
5650 .mos_hs = mdt_obd_ops
5653 .mos_opc_start = SEC_CTX_INIT,
5654 .mos_opc_end = SEC_LAST_OPC,
5655 .mos_hs = mdt_sec_ctx_ops
5662 static struct mdt_handler mdt_seq_ops[] = {
5663 DEF_SEQ_HNDL_F(0, QUERY, (int (*)(struct mdt_thread_info *))seq_query)
5666 static struct mdt_opc_slice mdt_seq_handlers[] = {
5668 .mos_opc_start = SEQ_QUERY,
5669 .mos_opc_end = SEQ_LAST_OPC,
5670 .mos_hs = mdt_seq_ops
5677 static struct mdt_handler mdt_fld_ops[] = {
5678 DEF_FLD_HNDL_F(0, QUERY, (int (*)(struct mdt_thread_info *))fld_query)
5681 static struct mdt_opc_slice mdt_fld_handlers[] = {
5683 .mos_opc_start = FLD_QUERY,
5684 .mos_opc_end = FLD_LAST_OPC,
5685 .mos_hs = mdt_fld_ops
5692 MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");
5693 MODULE_DESCRIPTION("Lustre Meta-data Target ("LUSTRE_MDT_NAME")");
5694 MODULE_LICENSE("GPL");
5696 CFS_MODULE_PARM(mdt_num_threads, "ul", ulong, 0444,
5697 "number of mdt service threads to start");
5699 cfs_module(mdt, "0.2.0", mdt_mod_init, mdt_mod_exit);