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);
1417 rdpg->rp_count = reqbody->nlink;
1418 rdpg->rp_npages = (rdpg->rp_count + CFS_PAGE_SIZE - 1)>>CFS_PAGE_SHIFT;
1419 OBD_ALLOC(rdpg->rp_pages, rdpg->rp_npages * sizeof rdpg->rp_pages[0]);
1420 if (rdpg->rp_pages == NULL)
1423 for (i = 0; i < rdpg->rp_npages; ++i) {
1424 rdpg->rp_pages[i] = cfs_alloc_page(CFS_ALLOC_STD);
1425 if (rdpg->rp_pages[i] == NULL)
1426 GOTO(free_rdpg, rc = -ENOMEM);
1429 /* call lower layers to fill allocated pages with directory data */
1430 rc = mo_readpage(info->mti_env, mdt_object_child(object), rdpg);
1432 GOTO(free_rdpg, rc);
1434 /* send pages to client */
1435 rc = mdt_sendpage(info, rdpg);
1440 for (i = 0; i < rdpg->rp_npages; i++)
1441 if (rdpg->rp_pages[i] != NULL)
1442 cfs_free_page(rdpg->rp_pages[i]);
1443 OBD_FREE(rdpg->rp_pages, rdpg->rp_npages * sizeof rdpg->rp_pages[0]);
1445 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_SENDPAGE))
1451 static int mdt_reint_internal(struct mdt_thread_info *info,
1452 struct mdt_lock_handle *lhc,
1455 struct req_capsule *pill = info->mti_pill;
1456 struct mdt_device *mdt = info->mti_mdt;
1457 struct mdt_body *repbody;
1462 if (req_capsule_has_field(pill, &RMF_MDT_MD, RCL_SERVER))
1463 req_capsule_set_size(pill, &RMF_MDT_MD, RCL_SERVER,
1464 mdt->mdt_max_mdsize);
1465 if (req_capsule_has_field(pill, &RMF_LOGCOOKIES, RCL_SERVER))
1466 req_capsule_set_size(pill, &RMF_LOGCOOKIES, RCL_SERVER,
1467 mdt->mdt_max_cookiesize);
1469 rc = req_capsule_server_pack(pill);
1471 CERROR("Can't pack response, rc %d\n", rc);
1472 RETURN(err_serious(rc));
1475 if (req_capsule_has_field(pill, &RMF_MDT_BODY, RCL_SERVER)) {
1476 repbody = req_capsule_server_get(pill, &RMF_MDT_BODY);
1478 repbody->eadatasize = 0;
1479 repbody->aclsize = 0;
1482 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_REINT_UNPACK))
1483 GOTO(out_shrink, rc = err_serious(-EFAULT));
1485 rc = mdt_reint_unpack(info, op);
1487 CERROR("Can't unpack reint, rc %d\n", rc);
1488 GOTO(out_shrink, rc = err_serious(rc));
1491 /* for replay no cookkie / lmm need, because client have this already */
1492 if (info->mti_spec.no_create == 1) {
1493 if (req_capsule_has_field(pill, &RMF_MDT_MD, RCL_SERVER))
1494 req_capsule_set_size(pill, &RMF_MDT_MD, RCL_SERVER, 0);
1496 if (req_capsule_has_field(pill, &RMF_LOGCOOKIES, RCL_SERVER))
1497 req_capsule_set_size(pill, &RMF_LOGCOOKIES, RCL_SERVER,
1501 rc = mdt_init_ucred_reint(info);
1503 GOTO(out_shrink, rc);
1505 rc = mdt_fix_attr_ucred(info, op);
1507 GOTO(out_ucred, rc = err_serious(rc));
1509 if (mdt_check_resent(info, mdt_reconstruct, lhc)) {
1510 rc = lustre_msg_get_status(mdt_info_req(info)->rq_repmsg);
1511 GOTO(out_ucred, rc);
1513 rc = mdt_reint_rec(info, lhc);
1516 mdt_exit_ucred(info);
1518 mdt_shrink_reply(info);
1522 static long mdt_reint_opcode(struct mdt_thread_info *info,
1523 const struct req_format **fmt)
1525 struct mdt_rec_reint *rec;
1528 opc = err_serious(-EFAULT);
1529 rec = req_capsule_client_get(info->mti_pill, &RMF_REC_REINT);
1531 opc = rec->rr_opcode;
1532 DEBUG_REQ(D_INODE, mdt_info_req(info), "reint opt = %ld", opc);
1533 if (opc < REINT_MAX && fmt[opc] != NULL)
1534 req_capsule_extend(info->mti_pill, fmt[opc]);
1536 CERROR("Unsupported opc: %ld\n", opc);
1537 opc = err_serious(opc);
1543 static int mdt_reint(struct mdt_thread_info *info)
1548 static const struct req_format *reint_fmts[REINT_MAX] = {
1549 [REINT_SETATTR] = &RQF_MDS_REINT_SETATTR,
1550 [REINT_CREATE] = &RQF_MDS_REINT_CREATE,
1551 [REINT_LINK] = &RQF_MDS_REINT_LINK,
1552 [REINT_UNLINK] = &RQF_MDS_REINT_UNLINK,
1553 [REINT_RENAME] = &RQF_MDS_REINT_RENAME,
1554 [REINT_OPEN] = &RQF_MDS_REINT_OPEN,
1555 [REINT_SETXATTR] = &RQF_MDS_REINT_SETXATTR
1560 opc = mdt_reint_opcode(info, reint_fmts);
1563 * No lock possible here from client to pass it to reint code
1566 rc = mdt_reint_internal(info, NULL, opc);
1571 info->mti_fail_id = OBD_FAIL_MDS_REINT_NET_REP;
1575 /* this should sync the whole device */
1576 static int mdt_device_sync(const struct lu_env *env, struct mdt_device *mdt)
1578 struct dt_device *dt = mdt->mdt_bottom;
1582 rc = dt->dd_ops->dt_sync(env, dt);
1586 /* this should sync this object */
1587 static int mdt_object_sync(struct mdt_thread_info *info)
1589 struct md_object *next;
1593 if (!mdt_object_exists(info->mti_object)) {
1594 CWARN("Non existing object "DFID"!\n",
1595 PFID(mdt_object_fid(info->mti_object)));
1598 next = mdt_object_child(info->mti_object);
1599 rc = mo_object_sync(info->mti_env, next);
1604 static int mdt_sync(struct mdt_thread_info *info)
1606 struct req_capsule *pill = info->mti_pill;
1607 struct mdt_body *body;
1611 /* The fid may be zero, so we req_capsule_set manually */
1612 req_capsule_set(pill, &RQF_MDS_SYNC);
1614 body = req_capsule_client_get(pill, &RMF_MDT_BODY);
1616 RETURN(err_serious(-EINVAL));
1618 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_SYNC_PACK))
1619 RETURN(err_serious(-ENOMEM));
1621 if (fid_seq(&body->fid1) == 0) {
1622 /* sync the whole device */
1623 rc = req_capsule_server_pack(pill);
1625 rc = mdt_device_sync(info->mti_env, info->mti_mdt);
1627 rc = err_serious(rc);
1629 /* sync an object */
1630 rc = mdt_unpack_req_pack_rep(info, HABEO_CORPUS|HABEO_REFERO);
1632 rc = mdt_object_sync(info);
1634 struct md_object *next;
1635 const struct lu_fid *fid;
1636 struct lu_attr *la = &info->mti_attr.ma_attr;
1638 next = mdt_object_child(info->mti_object);
1639 info->mti_attr.ma_need = MA_INODE;
1640 info->mti_attr.ma_valid = 0;
1641 rc = mo_attr_get(info->mti_env, next,
1644 body = req_capsule_server_get(pill,
1646 fid = mdt_object_fid(info->mti_object);
1647 mdt_pack_attr2body(info, body, la, fid);
1651 rc = err_serious(rc);
1656 #ifdef HAVE_QUOTA_SUPPORT
1657 static int mdt_quotacheck_handle(struct mdt_thread_info *info)
1659 struct obd_quotactl *oqctl;
1660 struct req_capsule *pill = info->mti_pill;
1661 struct obd_export *exp = info->mti_exp;
1662 struct md_device *next = info->mti_mdt->mdt_child;
1666 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_QUOTACHECK_NET))
1669 oqctl = req_capsule_client_get(pill, &RMF_OBD_QUOTACTL);
1673 /* remote client has no permission for quotacheck */
1674 if (unlikely(exp_connect_rmtclient(exp)))
1677 rc = req_capsule_server_pack(pill);
1681 rc = next->md_ops->mdo_quota.mqo_check(info->mti_env, next, exp,
1686 static int mdt_quotactl_handle(struct mdt_thread_info *info)
1688 struct obd_quotactl *oqctl, *repoqc;
1689 struct req_capsule *pill = info->mti_pill;
1690 struct obd_export *exp = info->mti_exp;
1691 struct md_device *next = info->mti_mdt->mdt_child;
1692 const struct md_quota_operations *mqo = &next->md_ops->mdo_quota;
1696 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_QUOTACTL_NET))
1699 oqctl = req_capsule_client_get(pill, &RMF_OBD_QUOTACTL);
1704 if (exp_connect_rmtclient(exp)) {
1705 struct ptlrpc_request *req = mdt_info_req(info);
1706 struct mdt_export_data *med = mdt_req2med(req);
1707 struct lustre_idmap_table *idmap = med->med_idmap;
1709 if (unlikely(oqctl->qc_cmd != Q_GETQUOTA &&
1710 oqctl->qc_cmd != Q_GETINFO))
1714 if (oqctl->qc_type == USRQUOTA)
1715 id = lustre_idmap_lookup_uid(NULL, idmap, 0,
1717 else if (oqctl->qc_type == GRPQUOTA)
1718 id = lustre_idmap_lookup_gid(NULL, idmap, 0,
1723 if (id == CFS_IDMAP_NOTFOUND) {
1724 CDEBUG(D_QUOTA, "no mapping for id %u\n",
1730 rc = req_capsule_server_pack(pill);
1734 repoqc = req_capsule_server_get(pill, &RMF_OBD_QUOTACTL);
1735 LASSERT(repoqc != NULL);
1737 switch (oqctl->qc_cmd) {
1739 rc = mqo->mqo_on(info->mti_env, next, oqctl->qc_type);
1742 rc = mqo->mqo_off(info->mti_env, next, oqctl->qc_type);
1745 rc = mqo->mqo_setinfo(info->mti_env, next, oqctl->qc_type, id,
1749 rc = mqo->mqo_getinfo(info->mti_env, next, oqctl->qc_type, id,
1753 rc = mqo->mqo_setquota(info->mti_env, next, oqctl->qc_type, id,
1757 rc = mqo->mqo_getquota(info->mti_env, next, oqctl->qc_type, id,
1761 rc = mqo->mqo_getoinfo(info->mti_env, next, oqctl->qc_type, id,
1765 rc = mqo->mqo_getoquota(info->mti_env, next, oqctl->qc_type, id,
1768 case LUSTRE_Q_INVALIDATE:
1769 rc = mqo->mqo_invalidate(info->mti_env, next, oqctl->qc_type);
1771 case LUSTRE_Q_FINVALIDATE:
1772 rc = mqo->mqo_finvalidate(info->mti_env, next, oqctl->qc_type);
1775 CERROR("unsupported mdt_quotactl command: %d\n",
1786 * OBD PING and other handlers.
1788 static int mdt_obd_ping(struct mdt_thread_info *info)
1793 req_capsule_set(info->mti_pill, &RQF_OBD_PING);
1795 rc = target_handle_ping(mdt_info_req(info));
1797 rc = err_serious(rc);
1801 static int mdt_obd_log_cancel(struct mdt_thread_info *info)
1803 return err_serious(-EOPNOTSUPP);
1806 static int mdt_obd_qc_callback(struct mdt_thread_info *info)
1808 return err_serious(-EOPNOTSUPP);
1815 static struct ldlm_callback_suite cbs = {
1816 .lcs_completion = ldlm_server_completion_ast,
1817 .lcs_blocking = ldlm_server_blocking_ast,
1821 static int mdt_enqueue(struct mdt_thread_info *info)
1823 struct ptlrpc_request *req;
1828 * info->mti_dlm_req already contains swapped and (if necessary)
1829 * converted dlm request.
1831 LASSERT(info->mti_dlm_req != NULL);
1833 req = mdt_info_req(info);
1836 * Lock without inodebits makes no sense and will oops later in
1837 * ldlm. Let's check it now to see if we have wrong lock from client or
1838 * bits get corrupted somewhere in mdt_intent_policy().
1840 req_bits = info->mti_dlm_req->lock_desc.l_policy_data.l_inodebits.bits;
1841 /* This is disabled because we need to support liblustre flock.
1842 * LASSERT(req_bits != 0);
1845 rc = ldlm_handle_enqueue0(info->mti_mdt->mdt_namespace,
1846 req, info->mti_dlm_req, &cbs);
1847 info->mti_fail_id = OBD_FAIL_LDLM_REPLY;
1848 return rc ? err_serious(rc) : req->rq_status;
1851 static int mdt_convert(struct mdt_thread_info *info)
1854 struct ptlrpc_request *req;
1856 LASSERT(info->mti_dlm_req);
1857 req = mdt_info_req(info);
1858 rc = ldlm_handle_convert0(req, info->mti_dlm_req);
1859 return rc ? err_serious(rc) : req->rq_status;
1862 static int mdt_bl_callback(struct mdt_thread_info *info)
1864 CERROR("bl callbacks should not happen on MDS\n");
1866 return err_serious(-EOPNOTSUPP);
1869 static int mdt_cp_callback(struct mdt_thread_info *info)
1871 CERROR("cp callbacks should not happen on MDS\n");
1873 return err_serious(-EOPNOTSUPP);
1877 * sec context handlers
1879 static int mdt_sec_ctx_handle(struct mdt_thread_info *info)
1883 rc = mdt_handle_idmap(info);
1886 struct ptlrpc_request *req = mdt_info_req(info);
1889 opc = lustre_msg_get_opc(req->rq_reqmsg);
1890 if (opc == SEC_CTX_INIT || opc == SEC_CTX_INIT_CONT)
1891 sptlrpc_svc_ctx_invalidate(req);
1894 OBD_FAIL_TIMEOUT(OBD_FAIL_SEC_CTX_HDL_PAUSE, obd_fail_val);
1899 static struct mdt_object *mdt_obj(struct lu_object *o)
1901 LASSERT(lu_device_is_mdt(o->lo_dev));
1902 return container_of0(o, struct mdt_object, mot_obj.mo_lu);
1905 struct mdt_object *mdt_object_find(const struct lu_env *env,
1906 struct mdt_device *d,
1907 const struct lu_fid *f)
1909 struct lu_object *o;
1910 struct mdt_object *m;
1913 CDEBUG(D_INFO, "Find object for "DFID"\n", PFID(f));
1914 o = lu_object_find(env, &d->mdt_md_dev.md_lu_dev, f, NULL);
1915 if (unlikely(IS_ERR(o)))
1916 m = (struct mdt_object *)o;
1923 * Asyncronous commit for mdt device.
1925 * Pass asynchonous commit call down the MDS stack.
1927 * \param env environment
1928 * \param mdt the mdt device
1930 static void mdt_device_commit_async(const struct lu_env *env,
1931 struct mdt_device *mdt)
1933 struct dt_device *dt = mdt->mdt_bottom;
1936 rc = dt->dd_ops->dt_commit_async(env, dt);
1937 if (unlikely(rc != 0))
1938 CWARN("async commit start failed with rc = %d", rc);
1942 * Mark the lock as "synchonous".
1944 * Mark the lock to deffer transaction commit to the unlock time.
1946 * \param lock the lock to mark as "synchonous"
1948 * \see mdt_is_lock_sync
1949 * \see mdt_save_lock
1951 static inline void mdt_set_lock_sync(struct ldlm_lock *lock)
1953 lock->l_ast_data = (void*)1;
1957 * Check whehter the lock "synchonous" or not.
1959 * \param lock the lock to check
1960 * \retval 1 the lock is "synchonous"
1961 * \retval 0 the lock isn't "synchronous"
1963 * \see mdt_set_lock_sync
1964 * \see mdt_save_lock
1966 static inline int mdt_is_lock_sync(struct ldlm_lock *lock)
1968 return lock->l_ast_data != NULL;
1972 * Blocking AST for mdt locks.
1974 * Starts transaction commit if in case of COS lock conflict or
1975 * deffers such a commit to the mdt_save_lock.
1977 * \param lock the lock which blocks a request or cancelling lock
1978 * \param desc unused
1979 * \param data unused
1980 * \param flag indicates whether this cancelling or blocking callback
1982 * \see ldlm_blocking_ast_nocheck
1984 int mdt_blocking_ast(struct ldlm_lock *lock, struct ldlm_lock_desc *desc,
1985 void *data, int flag)
1987 struct obd_device *obd = lock->l_resource->lr_namespace->ns_obd;
1988 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
1992 if (flag == LDLM_CB_CANCELING)
1994 lock_res_and_lock(lock);
1995 if (lock->l_blocking_ast != mdt_blocking_ast) {
1996 unlock_res_and_lock(lock);
1999 if (mdt_cos_is_enabled(mdt) &&
2000 lock->l_req_mode & (LCK_PW | LCK_EX) &&
2001 lock->l_blocking_lock != NULL &&
2002 lock->l_client_cookie != lock->l_blocking_lock->l_client_cookie) {
2003 mdt_set_lock_sync(lock);
2005 rc = ldlm_blocking_ast_nocheck(lock);
2007 /* There is no lock conflict if l_blocking_lock == NULL,
2008 * it indicates a blocking ast sent from ldlm_lock_decref_internal
2009 * when the last reference to a local lock was released */
2010 if (lock->l_req_mode == LCK_COS && lock->l_blocking_lock != NULL) {
2013 rc = lu_env_init(&env, LCT_MD_THREAD);
2014 if (unlikely(rc != 0))
2015 CWARN("lu_env initialization failed with rc = %d,"
2016 "cannot start asynchronous commit\n", rc);
2018 mdt_device_commit_async(&env, mdt);
2024 int mdt_object_lock(struct mdt_thread_info *info, struct mdt_object *o,
2025 struct mdt_lock_handle *lh, __u64 ibits, int locality)
2027 struct ldlm_namespace *ns = info->mti_mdt->mdt_namespace;
2028 ldlm_policy_data_t *policy = &info->mti_policy;
2029 struct ldlm_res_id *res_id = &info->mti_res_id;
2033 LASSERT(!lustre_handle_is_used(&lh->mlh_reg_lh));
2034 LASSERT(!lustre_handle_is_used(&lh->mlh_pdo_lh));
2035 LASSERT(lh->mlh_reg_mode != LCK_MINMODE);
2036 LASSERT(lh->mlh_type != MDT_NUL_LOCK);
2038 if (mdt_object_exists(o) < 0) {
2039 if (locality == MDT_CROSS_LOCK) {
2040 /* cross-ref object fix */
2041 ibits &= ~MDS_INODELOCK_UPDATE;
2042 ibits |= MDS_INODELOCK_LOOKUP;
2044 LASSERT(!(ibits & MDS_INODELOCK_UPDATE));
2045 LASSERT(ibits & MDS_INODELOCK_LOOKUP);
2047 /* No PDO lock on remote object */
2048 LASSERT(lh->mlh_type != MDT_PDO_LOCK);
2051 if (lh->mlh_type == MDT_PDO_LOCK) {
2052 /* check for exists after object is locked */
2053 if (mdt_object_exists(o) == 0) {
2054 /* Non-existent object shouldn't have PDO lock */
2057 /* Non-dir object shouldn't have PDO lock */
2058 LASSERT(S_ISDIR(lu_object_attr(&o->mot_obj.mo_lu)));
2062 memset(policy, 0, sizeof(*policy));
2063 fid_build_reg_res_name(mdt_object_fid(o), res_id);
2066 * Take PDO lock on whole directory and build correct @res_id for lock
2067 * on part of directory.
2069 if (lh->mlh_pdo_hash != 0) {
2070 LASSERT(lh->mlh_type == MDT_PDO_LOCK);
2071 mdt_lock_pdo_mode(info, o, lh);
2072 if (lh->mlh_pdo_mode != LCK_NL) {
2074 * Do not use LDLM_FL_LOCAL_ONLY for parallel lock, it
2075 * is never going to be sent to client and we do not
2076 * want it slowed down due to possible cancels.
2078 policy->l_inodebits.bits = MDS_INODELOCK_UPDATE;
2079 rc = mdt_fid_lock(ns, &lh->mlh_pdo_lh, lh->mlh_pdo_mode,
2080 policy, res_id, LDLM_FL_ATOMIC_CB,
2081 &info->mti_exp->exp_handle.h_cookie);
2087 * Finish res_id initializing by name hash marking part of
2088 * directory which is taking modification.
2090 res_id->name[LUSTRE_RES_ID_HSH_OFF] = lh->mlh_pdo_hash;
2093 policy->l_inodebits.bits = ibits;
2096 * Use LDLM_FL_LOCAL_ONLY for this lock. We do not know yet if it is
2097 * going to be sent to client. If it is - mdt_intent_policy() path will
2098 * fix it up and turn FL_LOCAL flag off.
2100 rc = mdt_fid_lock(ns, &lh->mlh_reg_lh, lh->mlh_reg_mode, policy,
2101 res_id, LDLM_FL_LOCAL_ONLY | LDLM_FL_ATOMIC_CB,
2102 &info->mti_exp->exp_handle.h_cookie);
2108 mdt_object_unlock(info, o, lh, 1);
2115 * Save a lock within request object.
2117 * Keep the lock referenced until whether client ACK or transaction
2118 * commit happens or release the lock immediately depending on input
2119 * parameters. If COS is ON, a write lock is converted to COS lock
2122 * \param info thead info object
2123 * \param h lock handle
2124 * \param mode lock mode
2125 * \param decref force immediate lock releasing
2128 void mdt_save_lock(struct mdt_thread_info *info, struct lustre_handle *h,
2129 ldlm_mode_t mode, int decref)
2133 if (lustre_handle_is_used(h)) {
2134 if (decref || !info->mti_has_trans ||
2135 !(mode & (LCK_PW | LCK_EX))){
2136 mdt_fid_unlock(h, mode);
2138 struct mdt_device *mdt = info->mti_mdt;
2139 struct ldlm_lock *lock = ldlm_handle2lock(h);
2140 struct ptlrpc_request *req = mdt_info_req(info);
2143 LASSERTF(lock != NULL, "no lock for cookie "LPX64"\n",
2145 CDEBUG(D_HA, "request = %p reply state = %p"
2146 " transno = "LPD64"\n",
2147 req, req->rq_reply_state, req->rq_transno);
2148 if (mdt_cos_is_enabled(mdt)) {
2150 ldlm_lock_downgrade(lock, LCK_COS);
2153 ptlrpc_save_lock(req, h, mode, no_ack);
2154 if (mdt_is_lock_sync(lock)) {
2155 CDEBUG(D_HA, "found sync-lock,"
2156 " async commit started\n");
2157 mdt_device_commit_async(info->mti_env,
2160 LDLM_LOCK_PUT(lock);
2169 * Unlock mdt object.
2171 * Immeditely release the regular lock and the PDO lock or save the
2172 * lock in reqeuest and keep them referenced until client ACK or
2173 * transaction commit.
2175 * \param info thread info object
2176 * \param o mdt object
2177 * \param h mdt lock handle referencing regular and PDO locks
2178 * \param decref force immediate lock releasing
2180 void mdt_object_unlock(struct mdt_thread_info *info, struct mdt_object *o,
2181 struct mdt_lock_handle *lh, int decref)
2185 mdt_save_lock(info, &lh->mlh_pdo_lh, lh->mlh_pdo_mode, decref);
2186 mdt_save_lock(info, &lh->mlh_reg_lh, lh->mlh_reg_mode, decref);
2191 struct mdt_object *mdt_object_find_lock(struct mdt_thread_info *info,
2192 const struct lu_fid *f,
2193 struct mdt_lock_handle *lh,
2196 struct mdt_object *o;
2198 o = mdt_object_find(info->mti_env, info->mti_mdt, f);
2202 rc = mdt_object_lock(info, o, lh, ibits,
2205 mdt_object_put(info->mti_env, o);
2212 void mdt_object_unlock_put(struct mdt_thread_info * info,
2213 struct mdt_object * o,
2214 struct mdt_lock_handle *lh,
2217 mdt_object_unlock(info, o, lh, decref);
2218 mdt_object_put(info->mti_env, o);
2221 static struct mdt_handler *mdt_handler_find(__u32 opc,
2222 struct mdt_opc_slice *supported)
2224 struct mdt_opc_slice *s;
2225 struct mdt_handler *h;
2228 for (s = supported; s->mos_hs != NULL; s++) {
2229 if (s->mos_opc_start <= opc && opc < s->mos_opc_end) {
2230 h = s->mos_hs + (opc - s->mos_opc_start);
2231 if (likely(h->mh_opc != 0))
2232 LASSERT(h->mh_opc == opc);
2234 h = NULL; /* unsupported opc */
2241 static int mdt_lock_resname_compat(struct mdt_device *m,
2242 struct ldlm_request *req)
2244 /* XXX something... later. */
2248 static int mdt_lock_reply_compat(struct mdt_device *m, struct ldlm_reply *rep)
2250 /* XXX something... later. */
2255 * Generic code handling requests that have struct mdt_body passed in:
2257 * - extract mdt_body from request and save it in @info, if present;
2259 * - create lu_object, corresponding to the fid in mdt_body, and save it in
2262 * - if HABEO_CORPUS flag is set for this request type check whether object
2263 * actually exists on storage (lu_object_exists()).
2266 static int mdt_body_unpack(struct mdt_thread_info *info, __u32 flags)
2268 const struct mdt_body *body;
2269 struct mdt_object *obj;
2270 const struct lu_env *env;
2271 struct req_capsule *pill;
2275 env = info->mti_env;
2276 pill = info->mti_pill;
2278 body = info->mti_body = req_capsule_client_get(pill, &RMF_MDT_BODY);
2282 if (!(body->valid & OBD_MD_FLID))
2285 if (!fid_is_sane(&body->fid1)) {
2286 CERROR("Invalid fid: "DFID"\n", PFID(&body->fid1));
2291 * Do not get size or any capa fields before we check that request
2292 * contains capa actually. There are some requests which do not, for
2293 * instance MDS_IS_SUBDIR.
2295 if (req_capsule_has_field(pill, &RMF_CAPA1, RCL_CLIENT) &&
2296 req_capsule_get_size(pill, &RMF_CAPA1, RCL_CLIENT))
2297 mdt_set_capainfo(info, 0, &body->fid1,
2298 req_capsule_client_get(pill, &RMF_CAPA1));
2300 obj = mdt_object_find(env, info->mti_mdt, &body->fid1);
2302 if ((flags & HABEO_CORPUS) &&
2303 !mdt_object_exists(obj)) {
2304 mdt_object_put(env, obj);
2305 /* for capability renew ENOENT will be handled in
2307 if (body->valid & OBD_MD_FLOSSCAPA)
2312 info->mti_object = obj;
2321 static int mdt_unpack_req_pack_rep(struct mdt_thread_info *info, __u32 flags)
2323 struct req_capsule *pill = info->mti_pill;
2327 if (req_capsule_has_field(pill, &RMF_MDT_BODY, RCL_CLIENT))
2328 rc = mdt_body_unpack(info, flags);
2332 if (rc == 0 && (flags & HABEO_REFERO)) {
2333 struct mdt_device *mdt = info->mti_mdt;
2336 if (req_capsule_has_field(pill, &RMF_MDT_MD, RCL_SERVER))
2337 req_capsule_set_size(pill, &RMF_MDT_MD, RCL_SERVER,
2338 mdt->mdt_max_mdsize);
2339 if (req_capsule_has_field(pill, &RMF_LOGCOOKIES, RCL_SERVER))
2340 req_capsule_set_size(pill, &RMF_LOGCOOKIES, RCL_SERVER,
2341 mdt->mdt_max_cookiesize);
2343 rc = req_capsule_server_pack(pill);
2348 static int mdt_init_capa_ctxt(const struct lu_env *env, struct mdt_device *m)
2350 struct md_device *next = m->mdt_child;
2352 return next->md_ops->mdo_init_capa_ctxt(env, next,
2353 m->mdt_opts.mo_mds_capa,
2354 m->mdt_capa_timeout,
2360 * Invoke handler for this request opc. Also do necessary preprocessing
2361 * (according to handler ->mh_flags), and post-processing (setting of
2362 * ->last_{xid,committed}).
2364 static int mdt_req_handle(struct mdt_thread_info *info,
2365 struct mdt_handler *h, struct ptlrpc_request *req)
2367 int rc, serious = 0;
2372 LASSERT(h->mh_act != NULL);
2373 LASSERT(h->mh_opc == lustre_msg_get_opc(req->rq_reqmsg));
2374 LASSERT(current->journal_info == NULL);
2377 * Checking for various OBD_FAIL_$PREF_$OPC_NET codes. _Do_ not try
2378 * to put same checks into handlers like mdt_close(), mdt_reint(),
2379 * etc., without talking to mdt authors first. Checking same thing
2380 * there again is useless and returning 0 error wihtout packing reply
2381 * is buggy! Handlers either pack reply or return error.
2383 * We return 0 here and do not send any reply in order to emulate
2384 * network failure. Do not send any reply in case any of NET related
2385 * fail_id has occured.
2387 if (OBD_FAIL_CHECK_ORSET(h->mh_fail_id, OBD_FAIL_ONCE))
2391 flags = h->mh_flags;
2392 LASSERT(ergo(flags & (HABEO_CORPUS|HABEO_REFERO), h->mh_fmt != NULL));
2394 if (h->mh_fmt != NULL) {
2395 req_capsule_set(info->mti_pill, h->mh_fmt);
2396 rc = mdt_unpack_req_pack_rep(info, flags);
2399 if (rc == 0 && flags & MUTABOR &&
2400 req->rq_export->exp_connect_flags & OBD_CONNECT_RDONLY)
2401 /* should it be rq_status? */
2404 if (rc == 0 && flags & HABEO_CLAVIS) {
2405 struct ldlm_request *dlm_req;
2407 LASSERT(h->mh_fmt != NULL);
2409 dlm_req = req_capsule_client_get(info->mti_pill, &RMF_DLM_REQ);
2410 if (dlm_req != NULL) {
2411 if (info->mti_mdt->mdt_opts.mo_compat_resname)
2412 rc = mdt_lock_resname_compat(info->mti_mdt,
2414 info->mti_dlm_req = dlm_req;
2420 /* capability setting changed via /proc, needs reinitialize ctxt */
2421 if (info->mti_mdt && info->mti_mdt->mdt_capa_conf) {
2422 mdt_init_capa_ctxt(info->mti_env, info->mti_mdt);
2423 info->mti_mdt->mdt_capa_conf = 0;
2426 if (likely(rc == 0)) {
2428 * Process request, there can be two types of rc:
2429 * 1) errors with msg unpack/pack, other failures outside the
2430 * operation itself. This is counted as serious errors;
2431 * 2) errors during fs operation, should be placed in rq_status
2434 rc = h->mh_act(info);
2436 !req->rq_no_reply && req->rq_reply_state == NULL) {
2437 DEBUG_REQ(D_ERROR, req, "MDT \"handler\" %s did not "
2438 "pack reply and returned 0 error\n",
2442 serious = is_serious(rc);
2443 rc = clear_serious(rc);
2447 req->rq_status = rc;
2450 * ELDLM_* codes which > 0 should be in rq_status only as well as
2451 * all non-serious errors.
2453 if (rc > 0 || !serious)
2456 LASSERT(current->journal_info == NULL);
2458 if (rc == 0 && (flags & HABEO_CLAVIS) &&
2459 info->mti_mdt->mdt_opts.mo_compat_resname) {
2460 struct ldlm_reply *dlmrep;
2462 dlmrep = req_capsule_server_get(info->mti_pill, &RMF_DLM_REP);
2464 rc = mdt_lock_reply_compat(info->mti_mdt, dlmrep);
2467 /* If we're DISCONNECTing, the mdt_export_data is already freed */
2468 if (likely(rc == 0 && h->mh_opc != MDS_DISCONNECT))
2469 target_committed_to_req(req);
2471 if (unlikely((lustre_msg_get_flags(req->rq_reqmsg) & MSG_REPLAY) &&
2472 lustre_msg_get_transno(req->rq_reqmsg) == 0)) {
2473 DEBUG_REQ(D_ERROR, req, "transno is 0 during REPLAY");
2477 target_send_reply(req, rc, info->mti_fail_id);
2481 void mdt_lock_handle_init(struct mdt_lock_handle *lh)
2483 lh->mlh_type = MDT_NUL_LOCK;
2484 lh->mlh_reg_lh.cookie = 0ull;
2485 lh->mlh_reg_mode = LCK_MINMODE;
2486 lh->mlh_pdo_lh.cookie = 0ull;
2487 lh->mlh_pdo_mode = LCK_MINMODE;
2490 void mdt_lock_handle_fini(struct mdt_lock_handle *lh)
2492 LASSERT(!lustre_handle_is_used(&lh->mlh_reg_lh));
2493 LASSERT(!lustre_handle_is_used(&lh->mlh_pdo_lh));
2497 * Initialize fields of struct mdt_thread_info. Other fields are left in
2498 * uninitialized state, because it's too expensive to zero out whole
2499 * mdt_thread_info (> 1K) on each request arrival.
2501 static void mdt_thread_info_init(struct ptlrpc_request *req,
2502 struct mdt_thread_info *info)
2505 struct md_capainfo *ci;
2507 req_capsule_init(&req->rq_pill, req, RCL_SERVER);
2508 info->mti_pill = &req->rq_pill;
2511 for (i = 0; i < ARRAY_SIZE(info->mti_lh); i++)
2512 mdt_lock_handle_init(&info->mti_lh[i]);
2514 /* mdt device: it can be NULL while CONNECT */
2515 if (req->rq_export) {
2516 info->mti_mdt = mdt_dev(req->rq_export->exp_obd->obd_lu_dev);
2517 info->mti_exp = req->rq_export;
2519 info->mti_mdt = NULL;
2520 info->mti_env = req->rq_svc_thread->t_env;
2521 ci = md_capainfo(info->mti_env);
2522 memset(ci, 0, sizeof *ci);
2523 if (req->rq_export) {
2524 if (exp_connect_rmtclient(req->rq_export))
2525 ci->mc_auth = LC_ID_CONVERT;
2526 else if (req->rq_export->exp_connect_flags &
2527 OBD_CONNECT_MDS_CAPA)
2528 ci->mc_auth = LC_ID_PLAIN;
2530 ci->mc_auth = LC_ID_NONE;
2533 info->mti_fail_id = OBD_FAIL_MDS_ALL_REPLY_NET;
2534 info->mti_transno = lustre_msg_get_transno(req->rq_reqmsg);
2536 memset(&info->mti_attr, 0, sizeof(info->mti_attr));
2537 info->mti_body = NULL;
2538 info->mti_object = NULL;
2539 info->mti_dlm_req = NULL;
2540 info->mti_has_trans = 0;
2541 info->mti_no_need_trans = 0;
2542 info->mti_cross_ref = 0;
2543 info->mti_opdata = 0;
2545 /* To not check for split by default. */
2546 info->mti_spec.sp_ck_split = 0;
2547 info->mti_spec.no_create = 0;
2550 static void mdt_thread_info_fini(struct mdt_thread_info *info)
2554 req_capsule_fini(info->mti_pill);
2555 if (info->mti_object != NULL) {
2556 mdt_object_put(info->mti_env, info->mti_object);
2557 info->mti_object = NULL;
2559 for (i = 0; i < ARRAY_SIZE(info->mti_lh); i++)
2560 mdt_lock_handle_fini(&info->mti_lh[i]);
2561 info->mti_env = NULL;
2564 static int mdt_filter_recovery_request(struct ptlrpc_request *req,
2565 struct obd_device *obd, int *process)
2567 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
2568 case MDS_CONNECT: /* This will never get here, but for completeness. */
2569 case OST_CONNECT: /* This will never get here, but for completeness. */
2570 case MDS_DISCONNECT:
2571 case OST_DISCONNECT:
2576 case MDS_DONE_WRITING:
2577 case MDS_SYNC: /* used in unmounting */
2583 *process = target_queue_recovery_request(req, obd);
2587 DEBUG_REQ(D_ERROR, req, "not permitted during recovery");
2594 * Handle recovery. Return:
2595 * +1: continue request processing;
2596 * -ve: abort immediately with the given error code;
2597 * 0: send reply with error code in req->rq_status;
2599 static int mdt_recovery(struct mdt_thread_info *info)
2601 struct ptlrpc_request *req = mdt_info_req(info);
2603 struct obd_device *obd;
2607 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
2610 case SEC_CTX_INIT_CONT:
2616 rc = mdt_handle_idmap(info);
2625 if (unlikely(req->rq_export == NULL)) {
2626 CERROR("operation %d on unconnected MDS from %s\n",
2627 lustre_msg_get_opc(req->rq_reqmsg),
2628 libcfs_id2str(req->rq_peer));
2629 /* FIXME: For CMD cleanup, when mds_B stop, the req from
2630 * mds_A will get -ENOTCONN(especially for ping req),
2631 * which will cause that mds_A deactive timeout, then when
2632 * mds_A cleanup, the cleanup process will be suspended since
2633 * deactive timeout is not zero.
2635 req->rq_status = -ENOTCONN;
2636 target_send_reply(req, -ENOTCONN, info->mti_fail_id);
2640 /* sanity check: if the xid matches, the request must be marked as a
2641 * resent or replayed */
2642 if (req_xid_is_last(req)) {
2643 if (!(lustre_msg_get_flags(req->rq_reqmsg) &
2644 (MSG_RESENT | MSG_REPLAY))) {
2645 DEBUG_REQ(D_WARNING, req, "rq_xid "LPU64" matches last_xid, "
2646 "expected REPLAY or RESENT flag (%x)", req->rq_xid,
2647 lustre_msg_get_flags(req->rq_reqmsg));
2649 req->rq_status = -ENOTCONN;
2654 /* else: note the opposite is not always true; a RESENT req after a
2655 * failover will usually not match the last_xid, since it was likely
2656 * never committed. A REPLAYed request will almost never match the
2657 * last xid, however it could for a committed, but still retained,
2660 obd = req->rq_export->exp_obd;
2662 /* Check for aborted recovery... */
2663 spin_lock_bh(&obd->obd_processing_task_lock);
2664 recovering = obd->obd_recovering;
2665 spin_unlock_bh(&obd->obd_processing_task_lock);
2666 if (unlikely(recovering)) {
2669 DEBUG_REQ(D_INFO, req, "Got new replay");
2670 rc = mdt_filter_recovery_request(req, obd, &should_process);
2671 if (rc != 0 || !should_process)
2673 else if (should_process < 0) {
2674 req->rq_status = should_process;
2675 rc = ptlrpc_error(req);
2682 static int mdt_msg_check_version(struct lustre_msg *msg)
2686 switch (lustre_msg_get_opc(msg)) {
2688 case MDS_DISCONNECT:
2691 case SEC_CTX_INIT_CONT:
2693 rc = lustre_msg_check_version(msg, LUSTRE_OBD_VERSION);
2695 CERROR("bad opc %u version %08x, expecting %08x\n",
2696 lustre_msg_get_opc(msg),
2697 lustre_msg_get_version(msg),
2698 LUSTRE_OBD_VERSION);
2702 case MDS_GETATTR_NAME:
2709 case MDS_DONE_WRITING:
2715 case MDS_QUOTACHECK:
2721 rc = lustre_msg_check_version(msg, LUSTRE_MDS_VERSION);
2723 CERROR("bad opc %u version %08x, expecting %08x\n",
2724 lustre_msg_get_opc(msg),
2725 lustre_msg_get_version(msg),
2726 LUSTRE_MDS_VERSION);
2730 case LDLM_BL_CALLBACK:
2731 case LDLM_CP_CALLBACK:
2732 rc = lustre_msg_check_version(msg, LUSTRE_DLM_VERSION);
2734 CERROR("bad opc %u version %08x, expecting %08x\n",
2735 lustre_msg_get_opc(msg),
2736 lustre_msg_get_version(msg),
2737 LUSTRE_DLM_VERSION);
2739 case OBD_LOG_CANCEL:
2740 case LLOG_ORIGIN_HANDLE_CREATE:
2741 case LLOG_ORIGIN_HANDLE_NEXT_BLOCK:
2742 case LLOG_ORIGIN_HANDLE_READ_HEADER:
2743 case LLOG_ORIGIN_HANDLE_CLOSE:
2744 case LLOG_ORIGIN_HANDLE_DESTROY:
2745 case LLOG_ORIGIN_HANDLE_PREV_BLOCK:
2747 rc = lustre_msg_check_version(msg, LUSTRE_LOG_VERSION);
2749 CERROR("bad opc %u version %08x, expecting %08x\n",
2750 lustre_msg_get_opc(msg),
2751 lustre_msg_get_version(msg),
2752 LUSTRE_LOG_VERSION);
2755 CERROR("MDS unknown opcode %d\n", lustre_msg_get_opc(msg));
2761 static int mdt_handle0(struct ptlrpc_request *req,
2762 struct mdt_thread_info *info,
2763 struct mdt_opc_slice *supported)
2765 struct mdt_handler *h;
2766 struct lustre_msg *msg;
2771 if (OBD_FAIL_CHECK_ORSET(OBD_FAIL_MDS_ALL_REQUEST_NET, OBD_FAIL_ONCE))
2774 LASSERT(current->journal_info == NULL);
2776 msg = req->rq_reqmsg;
2777 rc = mdt_msg_check_version(msg);
2778 if (likely(rc == 0)) {
2779 rc = mdt_recovery(info);
2780 if (likely(rc == +1)) {
2781 switch (lustre_msg_get_opc(msg)) {
2783 req->rq_bulk_read = 1;
2786 req->rq_bulk_write = 1;
2790 h = mdt_handler_find(lustre_msg_get_opc(msg),
2792 if (likely(h != NULL)) {
2793 rc = mdt_req_handle(info, h, req);
2795 CERROR("The unsupported opc: 0x%x\n", lustre_msg_get_opc(msg) );
2796 req->rq_status = -ENOTSUPP;
2797 rc = ptlrpc_error(req);
2802 CERROR(LUSTRE_MDT_NAME" drops mal-formed request\n");
2807 * MDT handler function called by ptlrpc service thread when request comes.
2809 * XXX common "target" functionality should be factored into separate module
2810 * shared by mdt, ost and stand-alone services like fld.
2812 static int mdt_handle_common(struct ptlrpc_request *req,
2813 struct mdt_opc_slice *supported)
2816 struct mdt_thread_info *info;
2820 env = req->rq_svc_thread->t_env;
2821 LASSERT(env != NULL);
2822 LASSERT(env->le_ses != NULL);
2823 LASSERT(env->le_ctx.lc_thread == req->rq_svc_thread);
2824 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
2825 LASSERT(info != NULL);
2827 mdt_thread_info_init(req, info);
2829 rc = mdt_handle0(req, info, supported);
2831 mdt_thread_info_fini(info);
2836 * This is called from recovery code as handler of _all_ RPC types, FLD and SEQ
2839 int mdt_recovery_handle(struct ptlrpc_request *req)
2844 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
2846 rc = mdt_handle_common(req, mdt_fld_handlers);
2849 rc = mdt_handle_common(req, mdt_seq_handlers);
2852 rc = mdt_handle_common(req, mdt_regular_handlers);
2859 static int mdt_regular_handle(struct ptlrpc_request *req)
2861 return mdt_handle_common(req, mdt_regular_handlers);
2864 static int mdt_readpage_handle(struct ptlrpc_request *req)
2866 return mdt_handle_common(req, mdt_readpage_handlers);
2869 static int mdt_xmds_handle(struct ptlrpc_request *req)
2871 return mdt_handle_common(req, mdt_xmds_handlers);
2874 static int mdt_mdsc_handle(struct ptlrpc_request *req)
2876 return mdt_handle_common(req, mdt_seq_handlers);
2879 static int mdt_mdss_handle(struct ptlrpc_request *req)
2881 return mdt_handle_common(req, mdt_seq_handlers);
2884 static int mdt_dtss_handle(struct ptlrpc_request *req)
2886 return mdt_handle_common(req, mdt_seq_handlers);
2889 static int mdt_fld_handle(struct ptlrpc_request *req)
2891 return mdt_handle_common(req, mdt_fld_handlers);
2907 static int mdt_intent_getattr(enum mdt_it_code opcode,
2908 struct mdt_thread_info *info,
2909 struct ldlm_lock **,
2911 static int mdt_intent_reint(enum mdt_it_code opcode,
2912 struct mdt_thread_info *info,
2913 struct ldlm_lock **,
2916 static struct mdt_it_flavor {
2917 const struct req_format *it_fmt;
2919 int (*it_act)(enum mdt_it_code ,
2920 struct mdt_thread_info *,
2921 struct ldlm_lock **,
2924 } mdt_it_flavor[] = {
2926 .it_fmt = &RQF_LDLM_INTENT,
2927 /*.it_flags = HABEO_REFERO,*/
2929 .it_act = mdt_intent_reint,
2930 .it_reint = REINT_OPEN
2933 .it_fmt = &RQF_LDLM_INTENT,
2934 .it_flags = MUTABOR,
2935 .it_act = mdt_intent_reint,
2936 .it_reint = REINT_OPEN
2939 .it_fmt = &RQF_LDLM_INTENT,
2940 .it_flags = MUTABOR,
2941 .it_act = mdt_intent_reint,
2942 .it_reint = REINT_CREATE
2944 [MDT_IT_GETATTR] = {
2945 .it_fmt = &RQF_LDLM_INTENT_GETATTR,
2946 .it_flags = HABEO_REFERO,
2947 .it_act = mdt_intent_getattr
2949 [MDT_IT_READDIR] = {
2955 .it_fmt = &RQF_LDLM_INTENT_GETATTR,
2956 .it_flags = HABEO_REFERO,
2957 .it_act = mdt_intent_getattr
2960 .it_fmt = &RQF_LDLM_INTENT_UNLINK,
2961 .it_flags = MUTABOR,
2963 .it_reint = REINT_UNLINK
2967 .it_flags = MUTABOR,
2970 [MDT_IT_GETXATTR] = {
2977 int mdt_intent_lock_replace(struct mdt_thread_info *info,
2978 struct ldlm_lock **lockp,
2979 struct ldlm_lock *new_lock,
2980 struct mdt_lock_handle *lh,
2983 struct ptlrpc_request *req = mdt_info_req(info);
2984 struct ldlm_lock *lock = *lockp;
2987 * Get new lock only for cases when possible resent did not find any
2990 if (new_lock == NULL)
2991 new_lock = ldlm_handle2lock_long(&lh->mlh_reg_lh, 0);
2993 if (new_lock == NULL && (flags & LDLM_FL_INTENT_ONLY)) {
2994 lh->mlh_reg_lh.cookie = 0;
2998 LASSERTF(new_lock != NULL,
2999 "lockh "LPX64"\n", lh->mlh_reg_lh.cookie);
3002 * If we've already given this lock to a client once, then we should
3003 * have no readers or writers. Otherwise, we should have one reader
3004 * _or_ writer ref (which will be zeroed below) before returning the
3007 if (new_lock->l_export == req->rq_export) {
3008 LASSERT(new_lock->l_readers + new_lock->l_writers == 0);
3010 LASSERT(new_lock->l_export == NULL);
3011 LASSERT(new_lock->l_readers + new_lock->l_writers == 1);
3016 if (new_lock->l_export == req->rq_export) {
3018 * Already gave this to the client, which means that we
3019 * reconstructed a reply.
3021 LASSERT(lustre_msg_get_flags(req->rq_reqmsg) &
3023 lh->mlh_reg_lh.cookie = 0;
3024 RETURN(ELDLM_LOCK_REPLACED);
3028 * Fixup the lock to be given to the client.
3030 lock_res_and_lock(new_lock);
3031 /* Zero new_lock->l_readers and new_lock->l_writers without triggering
3032 * possible blocking AST. */
3033 while (new_lock->l_readers > 0) {
3034 lu_ref_del(&new_lock->l_reference, "reader", new_lock);
3035 lu_ref_del(&new_lock->l_reference, "user", new_lock);
3036 new_lock->l_readers--;
3038 while (new_lock->l_writers > 0) {
3039 lu_ref_del(&new_lock->l_reference, "writer", new_lock);
3040 lu_ref_del(&new_lock->l_reference, "user", new_lock);
3041 new_lock->l_writers--;
3044 new_lock->l_export = class_export_get(req->rq_export);
3045 new_lock->l_blocking_ast = lock->l_blocking_ast;
3046 new_lock->l_completion_ast = lock->l_completion_ast;
3047 new_lock->l_remote_handle = lock->l_remote_handle;
3048 new_lock->l_flags &= ~LDLM_FL_LOCAL;
3050 unlock_res_and_lock(new_lock);
3052 lustre_hash_add(new_lock->l_export->exp_lock_hash,
3053 &new_lock->l_remote_handle,
3054 &new_lock->l_exp_hash);
3056 LDLM_LOCK_RELEASE(new_lock);
3057 lh->mlh_reg_lh.cookie = 0;
3059 RETURN(ELDLM_LOCK_REPLACED);
3062 static void mdt_intent_fixup_resent(struct mdt_thread_info *info,
3063 struct ldlm_lock *new_lock,
3064 struct ldlm_lock **old_lock,
3065 struct mdt_lock_handle *lh)
3067 struct ptlrpc_request *req = mdt_info_req(info);
3068 struct obd_export *exp = req->rq_export;
3069 struct lustre_handle remote_hdl;
3070 struct ldlm_request *dlmreq;
3071 struct ldlm_lock *lock;
3073 if (!(lustre_msg_get_flags(req->rq_reqmsg) & MSG_RESENT))
3076 dlmreq = req_capsule_client_get(info->mti_pill, &RMF_DLM_REQ);
3077 remote_hdl = dlmreq->lock_handle[0];
3079 lock = lustre_hash_lookup(exp->exp_lock_hash, &remote_hdl);
3081 if (lock != new_lock) {
3082 lh->mlh_reg_lh.cookie = lock->l_handle.h_cookie;
3083 lh->mlh_reg_mode = lock->l_granted_mode;
3085 LDLM_DEBUG(lock, "Restoring lock cookie");
3086 DEBUG_REQ(D_DLMTRACE, req,
3087 "restoring lock cookie "LPX64,
3088 lh->mlh_reg_lh.cookie);
3090 *old_lock = LDLM_LOCK_GET(lock);
3091 lh_put(exp->exp_lock_hash, &lock->l_exp_hash);
3095 lh_put(exp->exp_lock_hash, &lock->l_exp_hash);
3099 * If the xid matches, then we know this is a resent request, and allow
3100 * it. (It's probably an OPEN, for which we don't send a lock.
3102 if (req_xid_is_last(req))
3106 * This remote handle isn't enqueued, so we never received or processed
3107 * this request. Clear MSG_RESENT, because it can be handled like any
3108 * normal request now.
3110 lustre_msg_clear_flags(req->rq_reqmsg, MSG_RESENT);
3112 DEBUG_REQ(D_DLMTRACE, req, "no existing lock with rhandle "LPX64,
3116 static int mdt_intent_getattr(enum mdt_it_code opcode,
3117 struct mdt_thread_info *info,
3118 struct ldlm_lock **lockp,
3121 struct mdt_lock_handle *lhc = &info->mti_lh[MDT_LH_RMT];
3122 struct ldlm_lock *new_lock = NULL;
3124 struct ldlm_reply *ldlm_rep;
3125 struct ptlrpc_request *req;
3126 struct mdt_body *reqbody;
3127 struct mdt_body *repbody;
3131 reqbody = req_capsule_client_get(info->mti_pill, &RMF_MDT_BODY);
3134 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
3137 info->mti_spec.sp_ck_split = !!(reqbody->valid & OBD_MD_FLCKSPLIT);
3138 info->mti_cross_ref = !!(reqbody->valid & OBD_MD_FLCROSSREF);
3139 repbody->eadatasize = 0;
3140 repbody->aclsize = 0;
3144 child_bits = MDS_INODELOCK_LOOKUP;
3146 case MDT_IT_GETATTR:
3147 child_bits = MDS_INODELOCK_LOOKUP | MDS_INODELOCK_UPDATE;
3150 CERROR("Unhandled till now");
3151 GOTO(out_shrink, rc = -EINVAL);
3154 rc = mdt_init_ucred(info, reqbody);
3156 GOTO(out_shrink, rc);
3158 req = info->mti_pill->rc_req;
3159 ldlm_rep = req_capsule_server_get(info->mti_pill, &RMF_DLM_REP);
3160 mdt_set_disposition(info, ldlm_rep, DISP_IT_EXECD);
3162 /* Get lock from request for possible resent case. */
3163 mdt_intent_fixup_resent(info, *lockp, &new_lock, lhc);
3165 ldlm_rep->lock_policy_res2 =
3166 mdt_getattr_name_lock(info, lhc, child_bits, ldlm_rep);
3168 if (mdt_get_disposition(ldlm_rep, DISP_LOOKUP_NEG))
3169 ldlm_rep->lock_policy_res2 = 0;
3170 if (!mdt_get_disposition(ldlm_rep, DISP_LOOKUP_POS) ||
3171 ldlm_rep->lock_policy_res2) {
3172 lhc->mlh_reg_lh.cookie = 0ull;
3173 GOTO(out_ucred, rc = ELDLM_LOCK_ABORTED);
3176 rc = mdt_intent_lock_replace(info, lockp, new_lock, lhc, flags);
3179 mdt_exit_ucred(info);
3181 mdt_shrink_reply(info);
3185 static int mdt_intent_reint(enum mdt_it_code opcode,
3186 struct mdt_thread_info *info,
3187 struct ldlm_lock **lockp,
3190 struct mdt_lock_handle *lhc = &info->mti_lh[MDT_LH_RMT];
3191 struct ldlm_reply *rep = NULL;
3195 static const struct req_format *intent_fmts[REINT_MAX] = {
3196 [REINT_CREATE] = &RQF_LDLM_INTENT_CREATE,
3197 [REINT_OPEN] = &RQF_LDLM_INTENT_OPEN
3202 opc = mdt_reint_opcode(info, intent_fmts);
3206 if (mdt_it_flavor[opcode].it_reint != opc) {
3207 CERROR("Reint code %ld doesn't match intent: %d\n",
3209 RETURN(err_serious(-EPROTO));
3212 /* Get lock from request for possible resent case. */
3213 mdt_intent_fixup_resent(info, *lockp, NULL, lhc);
3215 rc = mdt_reint_internal(info, lhc, opc);
3217 /* Check whether the reply has been packed successfully. */
3218 if (mdt_info_req(info)->rq_repmsg != NULL)
3219 rep = req_capsule_server_get(info->mti_pill, &RMF_DLM_REP);
3221 RETURN(err_serious(-EFAULT));
3223 /* MDC expects this in any case */
3225 mdt_set_disposition(info, rep, DISP_LOOKUP_EXECD);
3227 /* Cross-ref case, the lock should be returned to the client */
3228 if (rc == -EREMOTE) {
3229 LASSERT(lustre_handle_is_used(&lhc->mlh_reg_lh));
3230 rep->lock_policy_res2 = 0;
3231 rc = mdt_intent_lock_replace(info, lockp, NULL, lhc, flags);
3234 rep->lock_policy_res2 = clear_serious(rc);
3236 lhc->mlh_reg_lh.cookie = 0ull;
3237 if (rc == -ENOTCONN || rc == -ENODEV) {
3239 * If it is the disconnect error (ENODEV & ENOCONN), the error
3240 * will be returned by rq_status, and client at ptlrpc layer
3241 * will detect this, then disconnect, reconnect the import
3242 * immediately, instead of impacting the following the rpc.
3247 * For other cases, the error will be returned by intent.
3248 * and client will retrieve the result from intent.
3251 * FIXME: when open lock is finished, that should be
3254 RETURN(ELDLM_LOCK_ABORTED);
3258 static int mdt_intent_code(long itcode)
3266 case IT_OPEN|IT_CREAT:
3273 rc = MDT_IT_READDIR;
3276 rc = MDT_IT_GETATTR;
3288 rc = MDT_IT_GETXATTR;
3291 CERROR("Unknown intent opcode: %ld\n", itcode);
3298 static int mdt_intent_opc(long itopc, struct mdt_thread_info *info,
3299 struct ldlm_lock **lockp, int flags)
3301 struct req_capsule *pill;
3302 struct mdt_it_flavor *flv;
3307 opc = mdt_intent_code(itopc);
3311 pill = info->mti_pill;
3312 flv = &mdt_it_flavor[opc];
3314 if (flv->it_fmt != NULL)
3315 req_capsule_extend(pill, flv->it_fmt);
3317 rc = mdt_unpack_req_pack_rep(info, flv->it_flags);
3319 struct ptlrpc_request *req = mdt_info_req(info);
3320 if (flv->it_flags & MUTABOR &&
3321 req->rq_export->exp_connect_flags & OBD_CONNECT_RDONLY)
3324 if (rc == 0 && flv->it_act != NULL) {
3325 /* execute policy */
3326 rc = flv->it_act(opc, info, lockp, flags);
3333 static int mdt_intent_policy(struct ldlm_namespace *ns,
3334 struct ldlm_lock **lockp, void *req_cookie,
3335 ldlm_mode_t mode, int flags, void *data)
3337 struct mdt_thread_info *info;
3338 struct ptlrpc_request *req = req_cookie;
3339 struct ldlm_intent *it;
3340 struct req_capsule *pill;
3345 LASSERT(req != NULL);
3347 info = lu_context_key_get(&req->rq_svc_thread->t_env->le_ctx,
3349 LASSERT(info != NULL);
3350 pill = info->mti_pill;
3351 LASSERT(pill->rc_req == req);
3353 if (req->rq_reqmsg->lm_bufcount > DLM_INTENT_IT_OFF) {
3354 req_capsule_extend(pill, &RQF_LDLM_INTENT);
3355 it = req_capsule_client_get(pill, &RMF_LDLM_INTENT);
3357 const struct ldlm_request *dlmreq;
3360 rc = mdt_intent_opc(it->opc, info, lockp, flags);
3365 * Lock without inodebits makes no sense and will oops
3366 * later in ldlm. Let's check it now to see if we have
3367 * wrong lock from client or bits get corrupted
3368 * somewhere in mdt_intent_opc().
3370 dlmreq = info->mti_dlm_req;
3371 req_bits = dlmreq->lock_desc.l_policy_data.l_inodebits.bits;
3372 LASSERT(req_bits != 0);
3375 rc = err_serious(-EFAULT);
3377 /* No intent was provided */
3378 LASSERT(pill->rc_fmt == &RQF_LDLM_ENQUEUE);
3379 rc = req_capsule_server_pack(pill);
3381 rc = err_serious(rc);
3389 static void mdt_seq_adjust(const struct lu_env *env,
3390 struct mdt_device *m, int lost)
3392 struct md_site *ms = mdt_md_site(m);
3393 struct lu_seq_range out;
3396 LASSERT(ms && ms->ms_server_seq);
3398 /* get extra seq from seq_server, moving it's range up */
3399 while (lost-- > 0) {
3400 seq_server_alloc_meta(ms->ms_server_seq, NULL, &out, env);
3405 static int mdt_seq_fini(const struct lu_env *env,
3406 struct mdt_device *m)
3408 struct md_site *ms = mdt_md_site(m);
3412 if (ms->ms_server_seq) {
3413 seq_server_fini(ms->ms_server_seq, env);
3414 OBD_FREE_PTR(ms->ms_server_seq);
3415 ms->ms_server_seq = NULL;
3418 if (ms->ms_control_seq) {
3419 seq_server_fini(ms->ms_control_seq, env);
3420 OBD_FREE_PTR(ms->ms_control_seq);
3421 ms->ms_control_seq = NULL;
3424 if (ms->ms_client_seq) {
3425 seq_client_fini(ms->ms_client_seq);
3426 OBD_FREE_PTR(ms->ms_client_seq);
3427 ms->ms_client_seq = NULL;
3434 static int mdt_seq_init(const struct lu_env *env,
3436 struct mdt_device *m)
3443 ms = mdt_md_site(m);
3446 * This is sequence-controller node. Init seq-controller server on local
3449 if (ms->ms_node_id == 0) {
3450 LASSERT(ms->ms_control_seq == NULL);
3452 OBD_ALLOC_PTR(ms->ms_control_seq);
3453 if (ms->ms_control_seq == NULL)
3456 rc = seq_server_init(ms->ms_control_seq,
3457 m->mdt_bottom, uuid,
3458 LUSTRE_SEQ_CONTROLLER,
3463 GOTO(out_seq_fini, rc);
3465 OBD_ALLOC_PTR(ms->ms_client_seq);
3466 if (ms->ms_client_seq == NULL)
3467 GOTO(out_seq_fini, rc = -ENOMEM);
3469 OBD_ALLOC(prefix, MAX_OBD_NAME + 5);
3470 if (prefix == NULL) {
3471 OBD_FREE_PTR(ms->ms_client_seq);
3472 GOTO(out_seq_fini, rc = -ENOMEM);
3475 snprintf(prefix, MAX_OBD_NAME + 5, "ctl-%s",
3479 * Init seq-controller client after seq-controller server is
3480 * ready. Pass ms->ms_control_seq to it for direct talking.
3482 rc = seq_client_init(ms->ms_client_seq, NULL,
3483 LUSTRE_SEQ_METADATA, prefix,
3484 ms->ms_control_seq);
3485 OBD_FREE(prefix, MAX_OBD_NAME + 5);
3488 GOTO(out_seq_fini, rc);
3491 /* Init seq-server on local MDT */
3492 LASSERT(ms->ms_server_seq == NULL);
3494 OBD_ALLOC_PTR(ms->ms_server_seq);
3495 if (ms->ms_server_seq == NULL)
3496 GOTO(out_seq_fini, rc = -ENOMEM);
3498 rc = seq_server_init(ms->ms_server_seq,
3499 m->mdt_bottom, uuid,
3504 GOTO(out_seq_fini, rc = -ENOMEM);
3506 /* Assign seq-controller client to local seq-server. */
3507 if (ms->ms_node_id == 0) {
3508 LASSERT(ms->ms_client_seq != NULL);
3510 rc = seq_server_set_cli(ms->ms_server_seq,
3518 mdt_seq_fini(env, m);
3523 * Init client sequence manager which is used by local MDS to talk to sequence
3524 * controller on remote node.
3526 static int mdt_seq_init_cli(const struct lu_env *env,
3527 struct mdt_device *m,
3528 struct lustre_cfg *cfg)
3530 struct md_site *ms = mdt_md_site(m);
3531 struct obd_device *mdc;
3532 struct obd_uuid *uuidp, *mdcuuidp;
3533 char *uuid_str, *mdc_uuid_str;
3536 struct mdt_thread_info *info;
3537 char *p, *index_string = lustre_cfg_string(cfg, 2);
3540 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
3541 uuidp = &info->mti_u.uuid[0];
3542 mdcuuidp = &info->mti_u.uuid[1];
3544 LASSERT(index_string);
3546 index = simple_strtol(index_string, &p, 10);
3548 CERROR("Invalid index in lustre_cgf, offset 2\n");
3552 /* check if this is adding the first MDC and controller is not yet
3554 if (index != 0 || ms->ms_client_seq)
3557 uuid_str = lustre_cfg_string(cfg, 1);
3558 mdc_uuid_str = lustre_cfg_string(cfg, 4);
3559 obd_str2uuid(uuidp, uuid_str);
3560 obd_str2uuid(mdcuuidp, mdc_uuid_str);
3562 mdc = class_find_client_obd(uuidp, LUSTRE_MDC_NAME, mdcuuidp);
3564 CERROR("can't find controller MDC by uuid %s\n",
3567 } else if (!mdc->obd_set_up) {
3568 CERROR("target %s not set up\n", mdc->obd_name);
3571 LASSERT(ms->ms_control_exp);
3572 OBD_ALLOC_PTR(ms->ms_client_seq);
3573 if (ms->ms_client_seq != NULL) {
3576 OBD_ALLOC(prefix, MAX_OBD_NAME + 5);
3580 snprintf(prefix, MAX_OBD_NAME + 5, "ctl-%s",
3583 rc = seq_client_init(ms->ms_client_seq,
3585 LUSTRE_SEQ_METADATA,
3587 OBD_FREE(prefix, MAX_OBD_NAME + 5);
3594 LASSERT(ms->ms_server_seq != NULL);
3595 rc = seq_server_set_cli(ms->ms_server_seq, ms->ms_client_seq,
3602 static void mdt_seq_fini_cli(struct mdt_device *m)
3608 ms = mdt_md_site(m);
3611 if (ms->ms_server_seq)
3612 seq_server_set_cli(ms->ms_server_seq,
3615 if (ms->ms_control_exp) {
3616 class_export_put(ms->ms_control_exp);
3617 ms->ms_control_exp = NULL;
3626 static int mdt_fld_fini(const struct lu_env *env,
3627 struct mdt_device *m)
3629 struct md_site *ms = mdt_md_site(m);
3632 if (ms && ms->ms_server_fld) {
3633 fld_server_fini(ms->ms_server_fld, env);
3634 OBD_FREE_PTR(ms->ms_server_fld);
3635 ms->ms_server_fld = NULL;
3641 static int mdt_fld_init(const struct lu_env *env,
3643 struct mdt_device *m)
3649 ms = mdt_md_site(m);
3651 OBD_ALLOC_PTR(ms->ms_server_fld);
3652 if (ms->ms_server_fld == NULL)
3653 RETURN(rc = -ENOMEM);
3655 rc = fld_server_init(ms->ms_server_fld,
3656 m->mdt_bottom, uuid,
3657 env, ms->ms_node_id);
3659 OBD_FREE_PTR(ms->ms_server_fld);
3660 ms->ms_server_fld = NULL;
3667 /* device init/fini methods */
3668 static void mdt_stop_ptlrpc_service(struct mdt_device *m)
3671 if (m->mdt_regular_service != NULL) {
3672 ptlrpc_unregister_service(m->mdt_regular_service);
3673 m->mdt_regular_service = NULL;
3675 if (m->mdt_readpage_service != NULL) {
3676 ptlrpc_unregister_service(m->mdt_readpage_service);
3677 m->mdt_readpage_service = NULL;
3679 if (m->mdt_xmds_service != NULL) {
3680 ptlrpc_unregister_service(m->mdt_xmds_service);
3681 m->mdt_xmds_service = NULL;
3683 if (m->mdt_setattr_service != NULL) {
3684 ptlrpc_unregister_service(m->mdt_setattr_service);
3685 m->mdt_setattr_service = NULL;
3687 if (m->mdt_mdsc_service != NULL) {
3688 ptlrpc_unregister_service(m->mdt_mdsc_service);
3689 m->mdt_mdsc_service = NULL;
3691 if (m->mdt_mdss_service != NULL) {
3692 ptlrpc_unregister_service(m->mdt_mdss_service);
3693 m->mdt_mdss_service = NULL;
3695 if (m->mdt_dtss_service != NULL) {
3696 ptlrpc_unregister_service(m->mdt_dtss_service);
3697 m->mdt_dtss_service = NULL;
3699 if (m->mdt_fld_service != NULL) {
3700 ptlrpc_unregister_service(m->mdt_fld_service);
3701 m->mdt_fld_service = NULL;
3706 static int mdt_start_ptlrpc_service(struct mdt_device *m)
3709 static struct ptlrpc_service_conf conf;
3710 cfs_proc_dir_entry_t *procfs_entry;
3713 procfs_entry = m->mdt_md_dev.md_lu_dev.ld_obd->obd_proc_entry;
3715 conf = (typeof(conf)) {
3716 .psc_nbufs = MDS_NBUFS,
3717 .psc_bufsize = MDS_BUFSIZE,
3718 .psc_max_req_size = MDS_MAXREQSIZE,
3719 .psc_max_reply_size = MDS_MAXREPSIZE,
3720 .psc_req_portal = MDS_REQUEST_PORTAL,
3721 .psc_rep_portal = MDC_REPLY_PORTAL,
3722 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
3724 * We'd like to have a mechanism to set this on a per-device
3725 * basis, but alas...
3727 .psc_min_threads = min(max(mdt_num_threads, MDT_MIN_THREADS),
3729 .psc_max_threads = MDT_MAX_THREADS,
3730 .psc_ctx_tags = LCT_MD_THREAD
3733 m->mdt_ldlm_client = &m->mdt_md_dev.md_lu_dev.ld_obd->obd_ldlm_client;
3734 ptlrpc_init_client(LDLM_CB_REQUEST_PORTAL, LDLM_CB_REPLY_PORTAL,
3735 "mdt_ldlm_client", m->mdt_ldlm_client);
3737 m->mdt_regular_service =
3738 ptlrpc_init_svc_conf(&conf, mdt_regular_handle, LUSTRE_MDT_NAME,
3739 procfs_entry, target_print_req,
3741 if (m->mdt_regular_service == NULL)
3744 rc = ptlrpc_start_threads(NULL, m->mdt_regular_service);
3746 GOTO(err_mdt_svc, rc);
3749 * readpage service configuration. Parameters have to be adjusted,
3752 conf = (typeof(conf)) {
3753 .psc_nbufs = MDS_NBUFS,
3754 .psc_bufsize = MDS_BUFSIZE,
3755 .psc_max_req_size = MDS_MAXREQSIZE,
3756 .psc_max_reply_size = MDS_MAXREPSIZE,
3757 .psc_req_portal = MDS_READPAGE_PORTAL,
3758 .psc_rep_portal = MDC_REPLY_PORTAL,
3759 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
3760 .psc_min_threads = min(max(mdt_num_threads, MDT_MIN_THREADS),
3762 .psc_max_threads = MDT_MAX_THREADS,
3763 .psc_ctx_tags = LCT_MD_THREAD
3765 m->mdt_readpage_service =
3766 ptlrpc_init_svc_conf(&conf, mdt_readpage_handle,
3767 LUSTRE_MDT_NAME "_readpage",
3768 procfs_entry, target_print_req,"mdt_rdpg");
3770 if (m->mdt_readpage_service == NULL) {
3771 CERROR("failed to start readpage service\n");
3772 GOTO(err_mdt_svc, rc = -ENOMEM);
3775 rc = ptlrpc_start_threads(NULL, m->mdt_readpage_service);
3778 * setattr service configuration.
3780 conf = (typeof(conf)) {
3781 .psc_nbufs = MDS_NBUFS,
3782 .psc_bufsize = MDS_BUFSIZE,
3783 .psc_max_req_size = MDS_MAXREQSIZE,
3784 .psc_max_reply_size = MDS_MAXREPSIZE,
3785 .psc_req_portal = MDS_SETATTR_PORTAL,
3786 .psc_rep_portal = MDC_REPLY_PORTAL,
3787 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
3788 .psc_min_threads = min(max(mdt_num_threads, MDT_MIN_THREADS),
3790 .psc_max_threads = MDT_MAX_THREADS,
3791 .psc_ctx_tags = LCT_MD_THREAD
3794 m->mdt_setattr_service =
3795 ptlrpc_init_svc_conf(&conf, mdt_regular_handle,
3796 LUSTRE_MDT_NAME "_setattr",
3797 procfs_entry, target_print_req,"mdt_attr");
3799 if (!m->mdt_setattr_service) {
3800 CERROR("failed to start setattr service\n");
3801 GOTO(err_mdt_svc, rc = -ENOMEM);
3804 rc = ptlrpc_start_threads(NULL, m->mdt_setattr_service);
3806 GOTO(err_mdt_svc, rc);
3809 * sequence controller service configuration
3811 conf = (typeof(conf)) {
3812 .psc_nbufs = MDS_NBUFS,
3813 .psc_bufsize = MDS_BUFSIZE,
3814 .psc_max_req_size = SEQ_MAXREQSIZE,
3815 .psc_max_reply_size = SEQ_MAXREPSIZE,
3816 .psc_req_portal = SEQ_CONTROLLER_PORTAL,
3817 .psc_rep_portal = MDC_REPLY_PORTAL,
3818 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
3819 .psc_min_threads = SEQ_NUM_THREADS,
3820 .psc_max_threads = SEQ_NUM_THREADS,
3821 .psc_ctx_tags = LCT_MD_THREAD|LCT_DT_THREAD
3824 m->mdt_mdsc_service =
3825 ptlrpc_init_svc_conf(&conf, mdt_mdsc_handle,
3826 LUSTRE_MDT_NAME"_mdsc",
3827 procfs_entry, target_print_req,"mdt_mdsc");
3828 if (!m->mdt_mdsc_service) {
3829 CERROR("failed to start seq controller service\n");
3830 GOTO(err_mdt_svc, rc = -ENOMEM);
3833 rc = ptlrpc_start_threads(NULL, m->mdt_mdsc_service);
3835 GOTO(err_mdt_svc, rc);
3838 * metadata sequence server service configuration
3840 conf = (typeof(conf)) {
3841 .psc_nbufs = MDS_NBUFS,
3842 .psc_bufsize = MDS_BUFSIZE,
3843 .psc_max_req_size = SEQ_MAXREQSIZE,
3844 .psc_max_reply_size = SEQ_MAXREPSIZE,
3845 .psc_req_portal = SEQ_METADATA_PORTAL,
3846 .psc_rep_portal = MDC_REPLY_PORTAL,
3847 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
3848 .psc_min_threads = SEQ_NUM_THREADS,
3849 .psc_max_threads = SEQ_NUM_THREADS,
3850 .psc_ctx_tags = LCT_MD_THREAD|LCT_DT_THREAD
3853 m->mdt_mdss_service =
3854 ptlrpc_init_svc_conf(&conf, mdt_mdss_handle,
3855 LUSTRE_MDT_NAME"_mdss",
3856 procfs_entry, target_print_req,"mdt_mdss");
3857 if (!m->mdt_mdss_service) {
3858 CERROR("failed to start metadata seq server service\n");
3859 GOTO(err_mdt_svc, rc = -ENOMEM);
3862 rc = ptlrpc_start_threads(NULL, m->mdt_mdss_service);
3864 GOTO(err_mdt_svc, rc);
3868 * Data sequence server service configuration. We want to have really
3869 * cluster-wide sequences space. This is why we start only one sequence
3870 * controller which manages space.
3872 conf = (typeof(conf)) {
3873 .psc_nbufs = MDS_NBUFS,
3874 .psc_bufsize = MDS_BUFSIZE,
3875 .psc_max_req_size = SEQ_MAXREQSIZE,
3876 .psc_max_reply_size = SEQ_MAXREPSIZE,
3877 .psc_req_portal = SEQ_DATA_PORTAL,
3878 .psc_rep_portal = OSC_REPLY_PORTAL,
3879 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
3880 .psc_min_threads = SEQ_NUM_THREADS,
3881 .psc_max_threads = SEQ_NUM_THREADS,
3882 .psc_ctx_tags = LCT_MD_THREAD|LCT_DT_THREAD
3885 m->mdt_dtss_service =
3886 ptlrpc_init_svc_conf(&conf, mdt_dtss_handle,
3887 LUSTRE_MDT_NAME"_dtss",
3888 procfs_entry, target_print_req,"mdt_dtss");
3889 if (!m->mdt_dtss_service) {
3890 CERROR("failed to start data seq server service\n");
3891 GOTO(err_mdt_svc, rc = -ENOMEM);
3894 rc = ptlrpc_start_threads(NULL, m->mdt_dtss_service);
3896 GOTO(err_mdt_svc, rc);
3898 /* FLD service start */
3899 conf = (typeof(conf)) {
3900 .psc_nbufs = MDS_NBUFS,
3901 .psc_bufsize = MDS_BUFSIZE,
3902 .psc_max_req_size = FLD_MAXREQSIZE,
3903 .psc_max_reply_size = FLD_MAXREPSIZE,
3904 .psc_req_portal = FLD_REQUEST_PORTAL,
3905 .psc_rep_portal = MDC_REPLY_PORTAL,
3906 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
3907 .psc_min_threads = FLD_NUM_THREADS,
3908 .psc_max_threads = FLD_NUM_THREADS,
3909 .psc_ctx_tags = LCT_DT_THREAD|LCT_MD_THREAD
3912 m->mdt_fld_service =
3913 ptlrpc_init_svc_conf(&conf, mdt_fld_handle,
3914 LUSTRE_MDT_NAME"_fld",
3915 procfs_entry, target_print_req, "mdt_fld");
3916 if (!m->mdt_fld_service) {
3917 CERROR("failed to start fld service\n");
3918 GOTO(err_mdt_svc, rc = -ENOMEM);
3921 rc = ptlrpc_start_threads(NULL, m->mdt_fld_service);
3923 GOTO(err_mdt_svc, rc);
3926 * mds-mds service configuration. Separate portal is used to allow
3927 * mds-mds requests be not blocked during recovery.
3929 conf = (typeof(conf)) {
3930 .psc_nbufs = MDS_NBUFS,
3931 .psc_bufsize = MDS_BUFSIZE,
3932 .psc_max_req_size = MDS_MAXREQSIZE,
3933 .psc_max_reply_size = MDS_MAXREPSIZE,
3934 .psc_req_portal = MDS_MDS_PORTAL,
3935 .psc_rep_portal = MDC_REPLY_PORTAL,
3936 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
3937 .psc_min_threads = min(max(mdt_num_threads, MDT_MIN_THREADS),
3939 .psc_max_threads = MDT_MAX_THREADS,
3940 .psc_ctx_tags = LCT_MD_THREAD
3942 m->mdt_xmds_service =
3943 ptlrpc_init_svc_conf(&conf, mdt_xmds_handle,
3944 LUSTRE_MDT_NAME "_mds",
3945 procfs_entry, target_print_req,"mdt_xmds");
3947 if (m->mdt_xmds_service == NULL) {
3948 CERROR("failed to start readpage service\n");
3949 GOTO(err_mdt_svc, rc = -ENOMEM);
3952 rc = ptlrpc_start_threads(NULL, m->mdt_xmds_service);
3954 GOTO(err_mdt_svc, rc);
3959 mdt_stop_ptlrpc_service(m);
3964 static void mdt_stack_fini(const struct lu_env *env,
3965 struct mdt_device *m, struct lu_device *top)
3967 struct obd_device *obd = mdt2obd_dev(m);
3968 struct lustre_cfg_bufs *bufs;
3969 struct lustre_cfg *lcfg;
3970 struct mdt_thread_info *info;
3974 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
3975 LASSERT(info != NULL);
3977 bufs = &info->mti_u.bufs;
3978 /* process cleanup, pass mdt obd name to get obd umount flags */
3979 lustre_cfg_bufs_reset(bufs, obd->obd_name);
3984 lustre_cfg_bufs_set_string(bufs, 1, flags);
3985 lcfg = lustre_cfg_new(LCFG_CLEANUP, bufs);
3987 CERROR("Cannot alloc lcfg!\n");
3992 top->ld_ops->ldo_process_config(env, top, lcfg);
3993 lustre_cfg_free(lcfg);
3995 lu_stack_fini(env, top);
3996 m->mdt_child = NULL;
3997 m->mdt_bottom = NULL;
4000 static struct lu_device *mdt_layer_setup(struct lu_env *env,
4001 const char *typename,
4002 struct lu_device *child,
4003 struct lustre_cfg *cfg)
4005 const char *dev = lustre_cfg_string(cfg, 0);
4006 struct obd_type *type;
4007 struct lu_device_type *ldt;
4008 struct lu_device *d;
4013 type = class_get_type(typename);
4015 CERROR("Unknown type: '%s'\n", typename);
4016 GOTO(out, rc = -ENODEV);
4019 rc = lu_env_refill((struct lu_env *)env);
4021 CERROR("Failure to refill session: '%d'\n", rc);
4027 CERROR("type: '%s'\n", typename);
4028 GOTO(out_type, rc = -EINVAL);
4031 ldt->ldt_obd_type = type;
4032 d = ldt->ldt_ops->ldto_device_alloc(env, ldt, cfg);
4034 CERROR("Cannot allocate device: '%s'\n", typename);
4035 GOTO(out_type, rc = -ENODEV);
4038 LASSERT(child->ld_site);
4039 d->ld_site = child->ld_site;
4042 rc = ldt->ldt_ops->ldto_device_init(env, d, dev, child);
4044 CERROR("can't init device '%s', rc %d\n", typename, rc);
4045 GOTO(out_alloc, rc);
4048 lu_ref_add(&d->ld_reference, "lu-stack", &lu_site_init);
4053 ldt->ldt_ops->ldto_device_free(env, d);
4056 class_put_type(type);
4061 static int mdt_stack_init(struct lu_env *env,
4062 struct mdt_device *m,
4063 struct lustre_cfg *cfg,
4064 struct lustre_mount_info *lmi)
4066 struct lu_device *d = &m->mdt_md_dev.md_lu_dev;
4067 struct lu_device *tmp;
4068 struct md_device *md;
4069 struct lu_device *child_lu_dev;
4073 /* init the stack */
4074 tmp = mdt_layer_setup(env, LUSTRE_OSD_NAME, d, cfg);
4076 RETURN(PTR_ERR(tmp));
4078 m->mdt_bottom = lu2dt_dev(tmp);
4080 tmp = mdt_layer_setup(env, LUSTRE_MDD_NAME, d, cfg);
4082 GOTO(out, rc = PTR_ERR(tmp));
4087 tmp = mdt_layer_setup(env, LUSTRE_CMM_NAME, d, cfg);
4089 GOTO(out, rc = PTR_ERR(tmp));
4092 /*set mdd upcall device*/
4093 md_upcall_dev_set(md, lu2md_dev(d));
4096 /*set cmm upcall device*/
4097 md_upcall_dev_set(md, &m->mdt_md_dev);
4099 m->mdt_child = lu2md_dev(d);
4101 /* process setup config */
4102 tmp = &m->mdt_md_dev.md_lu_dev;
4103 rc = tmp->ld_ops->ldo_process_config(env, tmp, cfg);
4107 /* initialize local objects */
4108 child_lu_dev = &m->mdt_child->md_lu_dev;
4110 rc = child_lu_dev->ld_ops->ldo_prepare(env,
4111 &m->mdt_md_dev.md_lu_dev,
4114 /* fini from last known good lu_device */
4116 mdt_stack_fini(env, m, d);
4122 * setup CONFIG_ORIG context, used to access local config log.
4123 * this may need to be rewrite as part of llog rewrite for lu-api.
4125 static int mdt_obd_llog_setup(struct obd_device *obd,
4126 struct lustre_sb_info *lsi)
4130 LASSERT(obd->obd_fsops == NULL);
4132 obd->obd_fsops = fsfilt_get_ops(MT_STR(lsi->lsi_ldd));
4133 if (IS_ERR(obd->obd_fsops))
4134 return PTR_ERR(obd->obd_fsops);
4136 rc = fsfilt_setup(obd, lsi->lsi_srv_mnt->mnt_sb);
4138 fsfilt_put_ops(obd->obd_fsops);
4142 OBD_SET_CTXT_MAGIC(&obd->obd_lvfs_ctxt);
4143 obd->obd_lvfs_ctxt.pwdmnt = lsi->lsi_srv_mnt;
4144 obd->obd_lvfs_ctxt.pwd = lsi->lsi_srv_mnt->mnt_root;
4145 obd->obd_lvfs_ctxt.fs = get_ds();
4147 rc = llog_setup(obd, &obd->obd_olg, LLOG_CONFIG_ORIG_CTXT, obd,
4148 0, NULL, &llog_lvfs_ops);
4150 CERROR("llog_setup() failed: %d\n", rc);
4151 fsfilt_put_ops(obd->obd_fsops);
4157 static void mdt_obd_llog_cleanup(struct obd_device *obd)
4159 struct llog_ctxt *ctxt;
4161 ctxt = llog_get_context(obd, LLOG_CONFIG_ORIG_CTXT);
4165 if (obd->obd_fsops) {
4166 fsfilt_put_ops(obd->obd_fsops);
4167 obd->obd_fsops = NULL;
4171 static void mdt_fini(const struct lu_env *env, struct mdt_device *m)
4173 struct md_device *next = m->mdt_child;
4174 struct lu_device *d = &m->mdt_md_dev.md_lu_dev;
4175 struct lu_site *ls = d->ld_site;
4176 struct obd_device *obd = mdt2obd_dev(m);
4180 /* At this point, obd exports might still be on the "obd_zombie_exports"
4181 * list, and obd_zombie_impexp_thread() is trying to destroy them.
4182 * We wait a little bit until all exports (except the self-export)
4183 * have been destroyed, because the whole mdt stack might be accessed
4184 * in mdt_destroy_export(). This will not be a long time, maybe one or
4185 * two seconds are enough. This is not a problem while umounting.
4187 * The three references that should be remaining are the
4188 * obd_self_export and the attach and setup references.
4190 while (atomic_read(&obd->obd_refcount) > 3) {
4191 cfs_schedule_timeout(CFS_TASK_UNINT, cfs_time_seconds(1));
4193 if (waited > 5 && IS_PO2(waited))
4194 LCONSOLE_WARN("Waiting for obd_zombie_impexp_thread "
4195 "more than %d seconds to destroy all "
4196 "the exports. The current obd refcount ="
4197 " %d. Is it stuck there?\n",
4198 waited, atomic_read(&obd->obd_refcount));
4201 ping_evictor_stop();
4203 target_recovery_fini(obd);
4204 mdt_stop_ptlrpc_service(m);
4205 mdt_obd_llog_cleanup(obd);
4206 obd_zombie_barrier();
4207 #ifdef HAVE_QUOTA_SUPPORT
4208 next->md_ops->mdo_quota.mqo_cleanup(env, next);
4210 mdt_fs_cleanup(env, m);
4211 upcall_cache_cleanup(m->mdt_identity_cache);
4212 m->mdt_identity_cache = NULL;
4214 if (m->mdt_namespace != NULL) {
4215 ldlm_namespace_free(m->mdt_namespace, NULL, d->ld_obd->obd_force);
4216 d->ld_obd->obd_namespace = m->mdt_namespace = NULL;
4219 cfs_free_nidlist(&m->mdt_nosquash_nids);
4220 if (m->mdt_nosquash_str) {
4221 OBD_FREE(m->mdt_nosquash_str, m->mdt_nosquash_strlen);
4222 m->mdt_nosquash_str = NULL;
4223 m->mdt_nosquash_strlen = 0;
4226 mdt_seq_fini(env, m);
4227 mdt_seq_fini_cli(m);
4228 mdt_fld_fini(env, m);
4230 if (obd->obd_proc_exports_entry) {
4231 lprocfs_remove_proc_entry("clear", obd->obd_proc_exports_entry);
4232 obd->obd_proc_exports_entry = NULL;
4234 lprocfs_free_per_client_stats(obd);
4235 lprocfs_free_obd_stats(obd);
4236 ptlrpc_lprocfs_unregister_obd(d->ld_obd);
4237 lprocfs_obd_cleanup(d->ld_obd);
4239 sptlrpc_rule_set_free(&m->mdt_sptlrpc_rset);
4241 next->md_ops->mdo_init_capa_ctxt(env, next, 0, 0, 0, NULL);
4242 cfs_timer_disarm(&m->mdt_ck_timer);
4243 mdt_ck_thread_stop(m);
4248 mdt_stack_fini(env, m, md2lu_dev(m->mdt_child));
4251 struct md_site *mite;
4254 mite = lu_site2md(ls);
4258 LASSERT(atomic_read(&d->ld_ref) == 0);
4263 static int mdt_adapt_sptlrpc_conf(struct obd_device *obd, int initial)
4265 struct mdt_device *m = mdt_dev(obd->obd_lu_dev);
4266 struct sptlrpc_rule_set tmp_rset;
4269 sptlrpc_rule_set_init(&tmp_rset);
4270 rc = sptlrpc_conf_target_get_rules(obd, &tmp_rset, initial);
4272 CERROR("mdt %s: failed get sptlrpc rules: %d\n",
4277 sptlrpc_target_update_exp_flavor(obd, &tmp_rset);
4279 write_lock(&m->mdt_sptlrpc_lock);
4280 sptlrpc_rule_set_free(&m->mdt_sptlrpc_rset);
4281 m->mdt_sptlrpc_rset = tmp_rset;
4282 write_unlock(&m->mdt_sptlrpc_lock);
4287 static void fsoptions_to_mdt_flags(struct mdt_device *m, char *options)
4291 m->mdt_opts.mo_mds_capa = 1;
4292 m->mdt_opts.mo_oss_capa = 1;
4293 #ifdef CONFIG_FS_POSIX_ACL
4294 /* ACLs should be enabled by default (b=13829) */
4295 m->mdt_opts.mo_acl = 1;
4296 LCONSOLE_INFO("Enabling ACL\n");
4298 m->mdt_opts.mo_acl = 0;
4299 LCONSOLE_INFO("Disabling ACL\n");
4308 while (*p && *p != ',')
4312 if ((len == sizeof("user_xattr") - 1) &&
4313 (memcmp(options, "user_xattr", len) == 0)) {
4314 m->mdt_opts.mo_user_xattr = 1;
4315 LCONSOLE_INFO("Enabling user_xattr\n");
4316 } else if ((len == sizeof("nouser_xattr") - 1) &&
4317 (memcmp(options, "nouser_xattr", len) == 0)) {
4318 m->mdt_opts.mo_user_xattr = 0;
4319 LCONSOLE_INFO("Disabling user_xattr\n");
4320 } else if ((len == sizeof("noacl") - 1) &&
4321 (memcmp(options, "noacl", len) == 0)) {
4322 m->mdt_opts.mo_acl = 0;
4323 LCONSOLE_INFO("Disabling ACL\n");
4330 int mdt_postrecov(const struct lu_env *, struct mdt_device *);
4332 static int mdt_init0(const struct lu_env *env, struct mdt_device *m,
4333 struct lu_device_type *ldt, struct lustre_cfg *cfg)
4335 struct lprocfs_static_vars lvars;
4336 struct mdt_thread_info *info;
4337 struct obd_device *obd;
4338 const char *dev = lustre_cfg_string(cfg, 0);
4339 const char *num = lustre_cfg_string(cfg, 2);
4340 struct lustre_mount_info *lmi = NULL;
4341 struct lustre_sb_info *lsi;
4342 struct lustre_disk_data *ldd;
4344 struct md_site *mite;
4345 const char *identity_upcall = "NONE";
4346 #ifdef HAVE_QUOTA_SUPPORT
4347 struct md_device *next;
4353 md_device_init(&m->mdt_md_dev, ldt);
4355 * Environment (env) might be missing mdt_thread_key values at that
4356 * point, if device is allocated when mdt_thread_key is in QUIESCENT
4359 * Usually device allocation path doesn't use module key values, but
4360 * mdt has to do a lot of work here, so allocate key value.
4362 rc = lu_env_refill((struct lu_env *)env);
4366 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
4367 LASSERT(info != NULL);
4369 obd = class_name2obd(dev);
4370 LASSERT(obd != NULL);
4372 spin_lock_init(&m->mdt_transno_lock);
4374 m->mdt_max_mdsize = MAX_MD_SIZE;
4375 m->mdt_max_cookiesize = sizeof(struct llog_cookie);
4377 m->mdt_opts.mo_user_xattr = 0;
4378 m->mdt_opts.mo_acl = 0;
4379 m->mdt_opts.mo_cos = MDT_COS_DEFAULT;
4380 lmi = server_get_mount_2(dev);
4382 CERROR("Cannot get mount info for %s!\n", dev);
4385 lsi = s2lsi(lmi->lmi_sb);
4386 fsoptions_to_mdt_flags(m, lsi->lsi_lmd->lmd_opts);
4387 /* CMD is supported only in IAM mode */
4390 node_id = simple_strtol(num, NULL, 10);
4391 if (!(ldd->ldd_flags & LDD_F_IAM_DIR) && node_id) {
4392 CERROR("CMD Operation not allowed in IOP mode\n");
4393 GOTO(err_lmi, rc = -EINVAL);
4397 rwlock_init(&m->mdt_sptlrpc_lock);
4398 sptlrpc_rule_set_init(&m->mdt_sptlrpc_rset);
4400 spin_lock_init(&m->mdt_ioepoch_lock);
4401 m->mdt_opts.mo_compat_resname = 0;
4402 m->mdt_capa_timeout = CAPA_TIMEOUT;
4403 m->mdt_capa_alg = CAPA_HMAC_ALG_SHA1;
4404 m->mdt_ck_timeout = CAPA_KEY_TIMEOUT;
4405 m->mdt_squash_uid = 0;
4406 m->mdt_squash_gid = 0;
4407 CFS_INIT_LIST_HEAD(&m->mdt_nosquash_nids);
4408 m->mdt_nosquash_str = NULL;
4409 m->mdt_nosquash_strlen = 0;
4410 init_rwsem(&m->mdt_squash_sem);
4412 spin_lock_init(&m->mdt_client_bitmap_lock);
4414 OBD_ALLOC_PTR(mite);
4416 GOTO(err_lmi, rc = -ENOMEM);
4420 m->mdt_md_dev.md_lu_dev.ld_ops = &mdt_lu_ops;
4421 m->mdt_md_dev.md_lu_dev.ld_obd = obd;
4422 /* set this lu_device to obd, because error handling need it */
4423 obd->obd_lu_dev = &m->mdt_md_dev.md_lu_dev;
4425 rc = lu_site_init(s, &m->mdt_md_dev.md_lu_dev);
4427 CERROR("Can't init lu_site, rc %d\n", rc);
4428 GOTO(err_free_site, rc);
4431 lprocfs_mdt_init_vars(&lvars);
4432 rc = lprocfs_obd_setup(obd, lvars.obd_vars);
4434 CERROR("Can't init lprocfs, rc %d\n", rc);
4435 GOTO(err_fini_site, rc);
4437 ptlrpc_lprocfs_register_obd(obd);
4439 rc = mdt_procfs_init(m, dev);
4441 CERROR("Can't init MDT lprocfs, rc %d\n", rc);
4442 GOTO(err_fini_proc, rc);
4445 obd->obd_proc_exports_entry = proc_mkdir("exports",
4446 obd->obd_proc_entry);
4447 if (obd->obd_proc_exports_entry)
4448 lprocfs_add_simple(obd->obd_proc_exports_entry,
4449 "clear", lprocfs_nid_stats_clear_read,
4450 lprocfs_nid_stats_clear_write, obd, NULL);
4452 /* set server index */
4453 lu_site2md(s)->ms_node_id = node_id;
4455 /* failover is the default
4456 * FIXME: we do not failout mds0/mgs, which may cause some problems.
4457 * assumed whose ms_node_id == 0 XXX
4459 obd->obd_replayable = 1;
4460 /* No connection accepted until configurations will finish */
4461 obd->obd_no_conn = 1;
4463 if (cfg->lcfg_bufcount > 4 && LUSTRE_CFG_BUFLEN(cfg, 4) > 0) {
4464 char *str = lustre_cfg_string(cfg, 4);
4465 if (strchr(str, 'n')) {
4466 CWARN("%s: recovery disabled\n", obd->obd_name);
4467 obd->obd_replayable = 0;
4471 /* init the stack */
4472 rc = mdt_stack_init((struct lu_env *)env, m, cfg, lmi);
4474 CERROR("Can't init device stack, rc %d\n", rc);
4475 GOTO(err_fini_proc, rc);
4478 rc = mdt_fld_init(env, obd->obd_name, m);
4480 GOTO(err_fini_stack, rc);
4482 rc = mdt_seq_init(env, obd->obd_name, m);
4484 GOTO(err_fini_fld, rc);
4486 snprintf(info->mti_u.ns_name, sizeof info->mti_u.ns_name,
4487 LUSTRE_MDT_NAME"-%p", m);
4488 m->mdt_namespace = ldlm_namespace_new(obd, info->mti_u.ns_name,
4489 LDLM_NAMESPACE_SERVER,
4490 LDLM_NAMESPACE_GREEDY);
4491 if (m->mdt_namespace == NULL)
4492 GOTO(err_fini_seq, rc = -ENOMEM);
4494 ldlm_register_intent(m->mdt_namespace, mdt_intent_policy);
4495 /* set obd_namespace for compatibility with old code */
4496 obd->obd_namespace = m->mdt_namespace;
4498 /* XXX: to support suppgid for ACL, we enable identity_upcall
4499 * by default, otherwise, maybe got unexpected -EACCESS. */
4500 if (m->mdt_opts.mo_acl)
4501 identity_upcall = MDT_IDENTITY_UPCALL_PATH;
4503 m->mdt_identity_cache = upcall_cache_init(obd->obd_name, identity_upcall,
4504 &mdt_identity_upcall_cache_ops);
4505 if (IS_ERR(m->mdt_identity_cache)) {
4506 rc = PTR_ERR(m->mdt_identity_cache);
4507 m->mdt_identity_cache = NULL;
4508 GOTO(err_free_ns, rc);
4511 cfs_timer_init(&m->mdt_ck_timer, mdt_ck_timer_callback, m);
4513 rc = mdt_ck_thread_start(m);
4515 GOTO(err_free_ns, rc);
4517 rc = mdt_fs_setup(env, m, obd, lsi);
4521 rc = mdt_obd_llog_setup(obd, lsi);
4523 GOTO(err_fs_cleanup, rc);
4525 mdt_adapt_sptlrpc_conf(obd, 1);
4527 #ifdef HAVE_QUOTA_SUPPORT
4528 next = m->mdt_child;
4529 rc = next->md_ops->mdo_quota.mqo_setup(env, next, lmi->lmi_mnt);
4531 GOTO(err_llog_cleanup, rc);
4534 server_put_mount_2(dev, lmi->lmi_mnt);
4537 target_recovery_init(obd, mdt_recovery_handle);
4539 rc = mdt_start_ptlrpc_service(m);
4541 GOTO(err_recovery, rc);
4543 ping_evictor_start();
4545 rc = lu_site_init_finish(s);
4547 GOTO(err_stop_service, rc);
4549 if (obd->obd_recovering == 0)
4550 mdt_postrecov(env, m);
4552 mdt_init_capa_ctxt(env, m);
4554 /* Reduce the initial timeout on an MDS because it doesn't need such
4555 * a long timeout as an OST does. Adaptive timeouts will adjust this
4556 * value appropriately. */
4557 if (ldlm_timeout == LDLM_TIMEOUT_DEFAULT)
4558 ldlm_timeout = MDS_LDLM_TIMEOUT_DEFAULT;
4563 ping_evictor_stop();
4564 mdt_stop_ptlrpc_service(m);
4566 target_recovery_fini(obd);
4567 #ifdef HAVE_QUOTA_SUPPORT
4568 next->md_ops->mdo_quota.mqo_cleanup(env, next);
4571 mdt_obd_llog_cleanup(obd);
4573 mdt_fs_cleanup(env, m);
4575 cfs_timer_disarm(&m->mdt_ck_timer);
4576 mdt_ck_thread_stop(m);
4578 upcall_cache_cleanup(m->mdt_identity_cache);
4579 m->mdt_identity_cache = NULL;
4580 ldlm_namespace_free(m->mdt_namespace, NULL, 0);
4581 obd->obd_namespace = m->mdt_namespace = NULL;
4583 mdt_seq_fini(env, m);
4585 mdt_fld_fini(env, m);
4587 mdt_stack_fini(env, m, md2lu_dev(m->mdt_child));
4590 if (obd->obd_proc_exports_entry) {
4591 lprocfs_remove_proc_entry("clear", obd->obd_proc_exports_entry);
4592 obd->obd_proc_exports_entry = NULL;
4594 ptlrpc_lprocfs_unregister_obd(obd);
4595 lprocfs_obd_cleanup(obd);
4602 server_put_mount_2(dev, lmi->lmi_mnt);
4606 /* used by MGS to process specific configurations */
4607 static int mdt_process_config(const struct lu_env *env,
4608 struct lu_device *d, struct lustre_cfg *cfg)
4610 struct mdt_device *m = mdt_dev(d);
4611 struct md_device *md_next = m->mdt_child;
4612 struct lu_device *next = md2lu_dev(md_next);
4616 switch (cfg->lcfg_command) {
4618 struct lprocfs_static_vars lvars;
4619 struct obd_device *obd = d->ld_obd;
4622 * For interoperability between 1.8 and 2.0,
4623 * skip old "mdt.group_upcall" param.
4626 char *param = lustre_cfg_string(cfg, 1);
4627 if (param && !strncmp("mdt.group_upcall", param, 16)) {
4628 CWARN("For 1.8 interoperability, skip this"
4629 " mdt.group_upcall. It is obsolete\n");
4634 lprocfs_mdt_init_vars(&lvars);
4635 rc = class_process_proc_param(PARAM_MDT, lvars.obd_vars,
4637 if (rc > 0 || rc == -ENOSYS)
4638 /* we don't understand; pass it on */
4639 rc = next->ld_ops->ldo_process_config(env, next, cfg);
4644 * Add mdc hook to get first MDT uuid and connect it to
4645 * ls->controller to use for seq manager.
4647 rc = next->ld_ops->ldo_process_config(env, next, cfg);
4649 CERROR("Can't add mdc, rc %d\n", rc);
4651 rc = mdt_seq_init_cli(env, mdt_dev(d), cfg);
4654 /* others are passed further */
4655 rc = next->ld_ops->ldo_process_config(env, next, cfg);
4661 static struct lu_object *mdt_object_alloc(const struct lu_env *env,
4662 const struct lu_object_header *hdr,
4663 struct lu_device *d)
4665 struct mdt_object *mo;
4671 struct lu_object *o;
4672 struct lu_object_header *h;
4674 o = &mo->mot_obj.mo_lu;
4675 h = &mo->mot_header;
4676 lu_object_header_init(h);
4677 lu_object_init(o, h, d);
4678 lu_object_add_top(h, o);
4679 o->lo_ops = &mdt_obj_ops;
4685 static int mdt_object_init(const struct lu_env *env, struct lu_object *o,
4686 const struct lu_object_conf *_)
4688 struct mdt_device *d = mdt_dev(o->lo_dev);
4689 struct lu_device *under;
4690 struct lu_object *below;
4694 CDEBUG(D_INFO, "object init, fid = "DFID"\n",
4695 PFID(lu_object_fid(o)));
4697 under = &d->mdt_child->md_lu_dev;
4698 below = under->ld_ops->ldo_object_alloc(env, o->lo_header, under);
4699 if (below != NULL) {
4700 lu_object_add(o, below);
4707 static void mdt_object_free(const struct lu_env *env, struct lu_object *o)
4709 struct mdt_object *mo = mdt_obj(o);
4710 struct lu_object_header *h;
4714 CDEBUG(D_INFO, "object free, fid = "DFID"\n",
4715 PFID(lu_object_fid(o)));
4718 lu_object_header_fini(h);
4723 static const struct lu_device_operations mdt_lu_ops = {
4724 .ldo_object_alloc = mdt_object_alloc,
4725 .ldo_process_config = mdt_process_config,
4728 static const struct lu_object_operations mdt_obj_ops = {
4729 .loo_object_init = mdt_object_init,
4730 .loo_object_free = mdt_object_free
4733 static int mdt_obd_set_info_async(struct obd_export *exp,
4734 __u32 keylen, void *key,
4735 __u32 vallen, void *val,
4736 struct ptlrpc_request_set *set)
4738 struct obd_device *obd = exp->exp_obd;
4744 if (KEY_IS(KEY_SPTLRPC_CONF)) {
4745 rc = mdt_adapt_sptlrpc_conf(obd, 0);
4752 /* mds_connect_internal */
4753 static int mdt_connect_internal(struct obd_export *exp,
4754 struct mdt_device *mdt,
4755 struct obd_connect_data *data)
4758 data->ocd_connect_flags &= MDT_CONNECT_SUPPORTED;
4759 data->ocd_ibits_known &= MDS_INODELOCK_FULL;
4761 /* If no known bits (which should not happen, probably,
4762 as everybody should support LOOKUP and UPDATE bits at least)
4763 revert to compat mode with plain locks. */
4764 if (!data->ocd_ibits_known &&
4765 data->ocd_connect_flags & OBD_CONNECT_IBITS)
4766 data->ocd_connect_flags &= ~OBD_CONNECT_IBITS;
4768 if (!mdt->mdt_opts.mo_acl)
4769 data->ocd_connect_flags &= ~OBD_CONNECT_ACL;
4771 if (!mdt->mdt_opts.mo_user_xattr)
4772 data->ocd_connect_flags &= ~OBD_CONNECT_XATTR;
4774 spin_lock(&exp->exp_lock);
4775 exp->exp_connect_flags = data->ocd_connect_flags;
4776 spin_unlock(&exp->exp_lock);
4777 data->ocd_version = LUSTRE_VERSION_CODE;
4778 exp->exp_mdt_data.med_ibits_known = data->ocd_ibits_known;
4782 if (mdt->mdt_opts.mo_acl &&
4783 ((exp->exp_connect_flags & OBD_CONNECT_ACL) == 0)) {
4784 CWARN("%s: MDS requires ACL support but client does not\n",
4785 mdt->mdt_md_dev.md_lu_dev.ld_obd->obd_name);
4790 if ((exp->exp_connect_flags & OBD_CONNECT_FID) == 0) {
4791 CWARN("%s: MDS requires FID support, but client not\n",
4792 mdt->mdt_md_dev.md_lu_dev.ld_obd->obd_name);
4799 static int mdt_connect_check_sptlrpc(struct mdt_device *mdt,
4800 struct obd_export *exp,
4801 struct ptlrpc_request *req)
4803 struct sptlrpc_flavor flvr;
4806 if (exp->exp_flvr.sf_rpc == SPTLRPC_FLVR_INVALID) {
4807 read_lock(&mdt->mdt_sptlrpc_lock);
4808 sptlrpc_target_choose_flavor(&mdt->mdt_sptlrpc_rset,
4812 read_unlock(&mdt->mdt_sptlrpc_lock);
4814 spin_lock(&exp->exp_lock);
4816 exp->exp_sp_peer = req->rq_sp_from;
4817 exp->exp_flvr = flvr;
4819 if (exp->exp_flvr.sf_rpc != SPTLRPC_FLVR_ANY &&
4820 exp->exp_flvr.sf_rpc != req->rq_flvr.sf_rpc) {
4821 CERROR("unauthorized rpc flavor %x from %s, "
4822 "expect %x\n", req->rq_flvr.sf_rpc,
4823 libcfs_nid2str(req->rq_peer.nid),
4824 exp->exp_flvr.sf_rpc);
4828 spin_unlock(&exp->exp_lock);
4830 if (exp->exp_sp_peer != req->rq_sp_from) {
4831 CERROR("RPC source %s doesn't match %s\n",
4832 sptlrpc_part2name(req->rq_sp_from),
4833 sptlrpc_part2name(exp->exp_sp_peer));
4836 rc = sptlrpc_target_export_check(exp, req);
4843 /* mds_connect copy */
4844 static int mdt_obd_connect(const struct lu_env *env,
4845 struct lustre_handle *conn, struct obd_device *obd,
4846 struct obd_uuid *cluuid,
4847 struct obd_connect_data *data,
4850 struct mdt_thread_info *info;
4851 struct lsd_client_data *lcd;
4852 struct obd_export *exp;
4853 struct mdt_device *mdt;
4854 struct ptlrpc_request *req;
4858 LASSERT(env != NULL);
4859 if (!conn || !obd || !cluuid)
4862 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
4863 req = info->mti_pill->rc_req;
4864 mdt = mdt_dev(obd->obd_lu_dev);
4866 rc = class_connect(conn, obd, cluuid);
4870 exp = class_conn2export(conn);
4871 LASSERT(exp != NULL);
4873 rc = mdt_connect_check_sptlrpc(mdt, exp, req);
4877 rc = mdt_connect_internal(exp, mdt, data);
4881 struct mdt_thread_info *mti;
4882 mti = lu_context_key_get(&env->le_ctx,
4884 LASSERT(mti != NULL);
4886 memcpy(lcd->lcd_uuid, cluuid, sizeof lcd->lcd_uuid);
4887 exp->exp_mdt_data.med_lcd = lcd;
4888 rc = mdt_client_new(env, mdt);
4891 exp->exp_mdt_data.med_lcd = NULL;
4893 mdt_export_stats_init(obd, exp, localdata);
4901 class_disconnect(exp);
4903 class_export_put(exp);
4908 static int mdt_obd_reconnect(const struct lu_env *env,
4909 struct obd_export *exp, struct obd_device *obd,
4910 struct obd_uuid *cluuid,
4911 struct obd_connect_data *data,
4914 struct mdt_thread_info *info;
4915 struct mdt_device *mdt;
4916 struct ptlrpc_request *req;
4920 if (exp == NULL || obd == NULL || cluuid == NULL)
4923 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
4924 req = info->mti_pill->rc_req;
4925 mdt = mdt_dev(obd->obd_lu_dev);
4927 rc = mdt_connect_check_sptlrpc(mdt, exp, req);
4931 rc = mdt_connect_internal(exp, mdt_dev(obd->obd_lu_dev), data);
4933 mdt_export_stats_init(obd, exp, localdata);
4938 static int mdt_obd_disconnect(struct obd_export *exp)
4940 struct mdt_device *mdt = mdt_dev(exp->exp_obd->obd_lu_dev);
4945 class_export_get(exp);
4947 /* Disconnect early so that clients can't keep using export */
4948 rc = class_disconnect(exp);
4949 if (mdt->mdt_namespace != NULL || exp->exp_obd->obd_namespace != NULL)
4950 ldlm_cancel_locks_for_export(exp);
4952 /* release nid stat refererence */
4953 lprocfs_exp_cleanup(exp);
4955 /* complete all outstanding replies */
4956 spin_lock(&exp->exp_lock);
4957 while (!list_empty(&exp->exp_outstanding_replies)) {
4958 struct ptlrpc_reply_state *rs =
4959 list_entry(exp->exp_outstanding_replies.next,
4960 struct ptlrpc_reply_state, rs_exp_list);
4961 struct ptlrpc_service *svc = rs->rs_service;
4963 spin_lock(&svc->srv_lock);
4964 list_del_init(&rs->rs_exp_list);
4965 spin_lock(&rs->rs_lock);
4966 ptlrpc_schedule_difficult_reply(rs);
4967 spin_unlock(&rs->rs_lock);
4968 spin_unlock(&svc->srv_lock);
4970 spin_unlock(&exp->exp_lock);
4972 class_export_put(exp);
4976 /* FIXME: Can we avoid using these two interfaces? */
4977 static int mdt_init_export(struct obd_export *exp)
4979 struct mdt_export_data *med = &exp->exp_mdt_data;
4983 CFS_INIT_LIST_HEAD(&med->med_open_head);
4984 spin_lock_init(&med->med_open_lock);
4985 sema_init(&med->med_idmap_sem, 1);
4986 med->med_idmap = NULL;
4987 spin_lock(&exp->exp_lock);
4988 exp->exp_connecting = 1;
4989 spin_unlock(&exp->exp_lock);
4990 rc = ldlm_init_export(exp);
4992 CERROR("Error %d while initializing export\n", rc);
4996 static int mdt_destroy_export(struct obd_export *export)
4998 struct mdt_export_data *med;
4999 struct obd_device *obd = export->exp_obd;
5000 struct mdt_device *mdt;
5001 struct mdt_thread_info *info;
5006 CFS_LIST_HEAD(closing_list);
5007 struct mdt_file_data *mfd, *n;
5011 med = &export->exp_mdt_data;
5012 if (exp_connect_rmtclient(export))
5013 mdt_cleanup_idmap(med);
5015 target_destroy_export(export);
5016 ldlm_destroy_export(export);
5018 if (obd_uuid_equals(&export->exp_client_uuid, &obd->obd_uuid))
5021 mdt = mdt_dev(obd->obd_lu_dev);
5022 LASSERT(mdt != NULL);
5024 rc = lu_env_init(&env, LCT_MD_THREAD);
5028 info = lu_context_key_get(&env.le_ctx, &mdt_thread_key);
5029 LASSERT(info != NULL);
5030 memset(info, 0, sizeof *info);
5031 info->mti_env = &env;
5032 info->mti_mdt = mdt;
5033 info->mti_exp = export;
5035 ma = &info->mti_attr;
5036 lmm_size = ma->ma_lmm_size = mdt->mdt_max_mdsize;
5037 cookie_size = ma->ma_cookie_size = mdt->mdt_max_cookiesize;
5038 OBD_ALLOC(ma->ma_lmm, lmm_size);
5039 OBD_ALLOC(ma->ma_cookie, cookie_size);
5041 if (ma->ma_lmm == NULL || ma->ma_cookie == NULL)
5042 GOTO(out, rc = -ENOMEM);
5043 ma->ma_need = MA_LOV | MA_COOKIE;
5045 /* Close any open files (which may also cause orphan unlinking). */
5046 spin_lock(&med->med_open_lock);
5047 while (!list_empty(&med->med_open_head)) {
5048 struct list_head *tmp = med->med_open_head.next;
5049 mfd = list_entry(tmp, struct mdt_file_data, mfd_list);
5051 /* Remove mfd handle so it can't be found again.
5052 * We are consuming the mfd_list reference here. */
5053 class_handle_unhash(&mfd->mfd_handle);
5054 list_move_tail(&mfd->mfd_list, &closing_list);
5056 spin_unlock(&med->med_open_lock);
5058 list_for_each_entry_safe(mfd, n, &closing_list, mfd_list) {
5059 list_del_init(&mfd->mfd_list);
5060 mdt_mfd_close(info, mfd);
5061 /* TODO: if we close the unlinked file,
5062 * we need to remove its objects from OST */
5063 memset(&ma->ma_attr, 0, sizeof(ma->ma_attr));
5064 spin_lock(&med->med_open_lock);
5065 ma->ma_lmm_size = lmm_size;
5066 ma->ma_cookie_size = cookie_size;
5067 ma->ma_need = MA_LOV | MA_COOKIE;
5069 spin_unlock(&med->med_open_lock);
5072 info->mti_mdt = NULL;
5073 mdt_client_del(&env, mdt);
5078 OBD_FREE(ma->ma_lmm, lmm_size);
5082 OBD_FREE(ma->ma_cookie, cookie_size);
5083 ma->ma_cookie = NULL;
5090 static void mdt_allow_cli(struct mdt_device *m, unsigned int flag)
5092 if (flag & CONFIG_LOG)
5093 m->mdt_fl_cfglog = 1;
5095 /* also notify active event */
5096 if (flag & CONFIG_SYNC)
5097 m->mdt_fl_synced = 1;
5099 if (m->mdt_fl_cfglog && m->mdt_fl_synced)
5100 /* Open for clients */
5101 m->mdt_md_dev.md_lu_dev.ld_obd->obd_no_conn = 0;
5104 static int mdt_upcall(const struct lu_env *env, struct md_device *md,
5105 enum md_upcall_event ev)
5107 struct mdt_device *m = mdt_dev(&md->md_lu_dev);
5108 struct md_device *next = m->mdt_child;
5109 struct mdt_thread_info *mti;
5115 rc = next->md_ops->mdo_maxsize_get(env, next,
5117 &m->mdt_max_cookiesize);
5118 CDEBUG(D_INFO, "get max mdsize %d max cookiesize %d\n",
5119 m->mdt_max_mdsize, m->mdt_max_cookiesize);
5120 mdt_allow_cli(m, CONFIG_SYNC);
5121 #ifdef HAVE_QUOTA_SUPPORT
5122 if (md->md_lu_dev.ld_obd->obd_recovering == 0)
5123 next->md_ops->mdo_quota.mqo_recovery(env, next);
5127 mti = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
5128 mti->mti_no_need_trans = 1;
5129 CDEBUG(D_INFO, "disable mdt trans for this thread\n");
5132 /* Check that MDT is not yet configured */
5133 LASSERT(!m->mdt_fl_cfglog);
5136 CERROR("invalid event\n");
5143 static int mdt_obd_notify(struct obd_device *host,
5144 struct obd_device *watched,
5145 enum obd_notify_event ev, void *data)
5147 struct mdt_device *mdt = mdt_dev(host->obd_lu_dev);
5148 #ifdef HAVE_QUOTA_SUPPORT
5149 struct md_device *next = mdt->mdt_child;
5154 case OBD_NOTIFY_CONFIG:
5155 mdt_allow_cli(mdt, (unsigned long)data);
5157 #ifdef HAVE_QUOTA_SUPPORT
5158 /* quota_type has been processed, we can now handle
5159 * incoming quota requests */
5160 next->md_ops->mdo_quota.mqo_notify(NULL, next);
5164 CDEBUG(D_INFO, "Unhandled notification %#x\n", ev);
5169 static int mdt_ioc_fid2path(struct lu_env *env, struct mdt_device *mdt,
5170 struct obd_ioctl_data *data)
5172 struct lu_context ioctl_session;
5173 struct mdt_object *obj;
5177 int pathlen = data->ioc_plen1;
5183 fid = (struct lu_fid *)data->ioc_inlbuf1;
5184 memcpy(&recno, data->ioc_inlbuf2, sizeof(recno));
5185 memcpy(&linkno, data->ioc_inlbuf3, sizeof(linkno));
5186 CDEBUG(D_IOCTL, "path get "DFID" from "LPU64" #%d\n",
5187 PFID(fid), recno, linkno);
5189 if (!fid_is_sane(fid))
5195 rc = lu_context_init(&ioctl_session, LCT_SESSION);
5198 ioctl_session.lc_thread = (struct ptlrpc_thread *)cfs_current();
5199 lu_context_enter(&ioctl_session);
5200 env->le_ses = &ioctl_session;
5202 OBD_ALLOC(path, pathlen);
5204 GOTO(out_context, rc = -ENOMEM);
5206 obj = mdt_object_find(env, mdt, fid);
5207 if (obj == NULL || IS_ERR(obj)) {
5208 CDEBUG(D_IOCTL, "no object "DFID": %ld\n", PFID(fid),
5210 GOTO(out_free, rc = -EINVAL);
5213 rc = lu_object_exists(&obj->mot_obj.mo_lu);
5219 mdt_object_put(env, obj);
5220 CDEBUG(D_IOCTL, "nonlocal object "DFID": %d\n", PFID(fid),
5225 rc = mo_path(env, md_object_next(&obj->mot_obj), path, pathlen, recno,
5227 mdt_object_put(env, obj);
5231 if (copy_to_user(data->ioc_pbuf1, path, pathlen))
5234 memcpy(data->ioc_inlbuf3, &linkno, sizeof(linkno));
5238 OBD_FREE(path, pathlen);
5240 lu_context_exit(&ioctl_session);
5241 lu_context_fini(&ioctl_session);
5245 static int mdt_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
5246 void *karg, void *uarg)
5249 struct obd_device *obd = exp->exp_obd;
5250 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
5251 struct dt_device *dt = mdt->mdt_bottom;
5255 CDEBUG(D_IOCTL, "handling ioctl cmd %#x\n", cmd);
5256 rc = lu_env_init(&env, LCT_MD_THREAD);
5262 rc = mdt_device_sync(&env, mdt);
5264 case OBD_IOC_SET_READONLY:
5265 dt->dd_ops->dt_ro(&env, dt);
5267 case OBD_IOC_ABORT_RECOVERY:
5268 CERROR("Aborting recovery for device %s\n", obd->obd_name);
5269 target_stop_recovery_thread(obd);
5272 case OBD_IOC_FID2PATH:
5273 rc = mdt_ioc_fid2path(&env, mdt, karg);
5276 CERROR("Not supported cmd = %d for device %s\n",
5277 cmd, obd->obd_name);
5285 int mdt_postrecov(const struct lu_env *env, struct mdt_device *mdt)
5287 struct lu_device *ld = md2lu_dev(mdt->mdt_child);
5288 struct obd_device *obd = mdt2obd_dev(mdt);
5289 #ifdef HAVE_QUOTA_SUPPORT
5290 struct md_device *next = mdt->mdt_child;
5294 /* if some clients didn't participate in recovery then we can possibly
5295 * lost sequence. Now we should increase sequence for safe value */
5296 lost = obd->obd_max_recoverable_clients - obd->obd_connected_clients;
5297 mdt_seq_adjust(env, mdt, lost);
5299 rc = ld->ld_ops->ldo_recovery_complete(env, ld);
5300 #ifdef HAVE_QUOTA_SUPPORT
5301 next->md_ops->mdo_quota.mqo_recovery(env, next);
5306 int mdt_obd_postrecov(struct obd_device *obd)
5311 rc = lu_env_init(&env, LCT_MD_THREAD);
5314 rc = mdt_postrecov(&env, mdt_dev(obd->obd_lu_dev));
5319 static struct obd_ops mdt_obd_device_ops = {
5320 .o_owner = THIS_MODULE,
5321 .o_set_info_async = mdt_obd_set_info_async,
5322 .o_connect = mdt_obd_connect,
5323 .o_reconnect = mdt_obd_reconnect,
5324 .o_disconnect = mdt_obd_disconnect,
5325 .o_init_export = mdt_init_export,
5326 .o_destroy_export = mdt_destroy_export,
5327 .o_iocontrol = mdt_iocontrol,
5328 .o_postrecov = mdt_obd_postrecov,
5329 .o_notify = mdt_obd_notify
5332 static struct lu_device* mdt_device_fini(const struct lu_env *env,
5333 struct lu_device *d)
5335 struct mdt_device *m = mdt_dev(d);
5342 static struct lu_device *mdt_device_free(const struct lu_env *env,
5343 struct lu_device *d)
5345 struct mdt_device *m = mdt_dev(d);
5348 md_device_fini(&m->mdt_md_dev);
5353 static struct lu_device *mdt_device_alloc(const struct lu_env *env,
5354 struct lu_device_type *t,
5355 struct lustre_cfg *cfg)
5357 struct lu_device *l;
5358 struct mdt_device *m;
5364 l = &m->mdt_md_dev.md_lu_dev;
5365 rc = mdt_init0(env, m, t, cfg);
5367 mdt_device_free(env, l);
5371 md_upcall_init(&m->mdt_md_dev, mdt_upcall);
5373 l = ERR_PTR(-ENOMEM);
5377 /* context key constructor/destructor: mdt_key_init, mdt_key_fini */
5378 LU_KEY_INIT_FINI(mdt, struct mdt_thread_info);
5380 /* context key: mdt_thread_key */
5381 LU_CONTEXT_KEY_DEFINE(mdt, LCT_MD_THREAD);
5383 /* context key constructor/destructor: mdt_txn_key_init, mdt_txn_key_fini */
5384 LU_KEY_INIT_FINI(mdt_txn, struct mdt_txn_info);
5386 struct lu_context_key mdt_txn_key = {
5387 .lct_tags = LCT_TX_HANDLE,
5388 .lct_init = mdt_txn_key_init,
5389 .lct_fini = mdt_txn_key_fini
5392 struct md_ucred *mdt_ucred(const struct mdt_thread_info *info)
5394 return md_ucred(info->mti_env);
5398 * Enable/disable COS.
5400 * Set/Clear the COS flag in mdt options.
5402 * \param mdt mdt device
5403 * \param val 0 disables COS, other values enable COS
5405 void mdt_enable_cos(struct mdt_device *mdt, int val)
5410 mdt->mdt_opts.mo_cos = !!val;
5411 rc = lu_env_init(&env, LCT_MD_THREAD);
5412 if (unlikely(rc != 0)) {
5413 CWARN("lu_env initialization failed with rc = %d,"
5414 "cannot sync\n", rc);
5417 mdt_device_sync(&env, mdt);
5424 * Return COS flag status/
5426 * \param mdt mdt device
5428 int mdt_cos_is_enabled(struct mdt_device *mdt)
5430 return mdt->mdt_opts.mo_cos != 0;
5433 /* type constructor/destructor: mdt_type_init, mdt_type_fini */
5434 LU_TYPE_INIT_FINI(mdt, &mdt_thread_key, &mdt_txn_key);
5436 static struct lu_device_type_operations mdt_device_type_ops = {
5437 .ldto_init = mdt_type_init,
5438 .ldto_fini = mdt_type_fini,
5440 .ldto_start = mdt_type_start,
5441 .ldto_stop = mdt_type_stop,
5443 .ldto_device_alloc = mdt_device_alloc,
5444 .ldto_device_free = mdt_device_free,
5445 .ldto_device_fini = mdt_device_fini
5448 static struct lu_device_type mdt_device_type = {
5449 .ldt_tags = LU_DEVICE_MD,
5450 .ldt_name = LUSTRE_MDT_NAME,
5451 .ldt_ops = &mdt_device_type_ops,
5452 .ldt_ctx_tags = LCT_MD_THREAD
5455 static struct lu_local_obj_desc mdt_last_recv = {
5456 .llod_name = LAST_RCVD,
5457 .llod_oid = MDT_LAST_RECV_OID,
5461 static int __init mdt_mod_init(void)
5463 struct lprocfs_static_vars lvars;
5466 llo_local_obj_register(&mdt_last_recv);
5468 mdt_num_threads = MDT_NUM_THREADS;
5469 lprocfs_mdt_init_vars(&lvars);
5470 rc = class_register_type(&mdt_obd_device_ops, NULL,
5471 lvars.module_vars, LUSTRE_MDT_NAME,
5477 static void __exit mdt_mod_exit(void)
5479 llo_local_obj_unregister(&mdt_last_recv);
5480 class_unregister_type(LUSTRE_MDT_NAME);
5484 #define DEF_HNDL(prefix, base, suffix, flags, opc, fn, fmt) \
5485 [prefix ## _ ## opc - prefix ## _ ## base] = { \
5487 .mh_fail_id = OBD_FAIL_ ## prefix ## _ ## opc ## suffix, \
5488 .mh_opc = prefix ## _ ## opc, \
5489 .mh_flags = flags, \
5494 #define DEF_MDT_HNDL(flags, name, fn, fmt) \
5495 DEF_HNDL(MDS, GETATTR, _NET, flags, name, fn, fmt)
5497 #define DEF_SEQ_HNDL(flags, name, fn, fmt) \
5498 DEF_HNDL(SEQ, QUERY, _NET, flags, name, fn, fmt)
5500 #define DEF_FLD_HNDL(flags, name, fn, fmt) \
5501 DEF_HNDL(FLD, QUERY, _NET, flags, name, fn, fmt)
5503 * Request with a format known in advance
5505 #define DEF_MDT_HNDL_F(flags, name, fn) \
5506 DEF_HNDL(MDS, GETATTR, _NET, flags, name, fn, &RQF_MDS_ ## name)
5508 #define DEF_SEQ_HNDL_F(flags, name, fn) \
5509 DEF_HNDL(SEQ, QUERY, _NET, flags, name, fn, &RQF_SEQ_ ## name)
5511 #define DEF_FLD_HNDL_F(flags, name, fn) \
5512 DEF_HNDL(FLD, QUERY, _NET, flags, name, fn, &RQF_FLD_ ## name)
5514 * Request with a format we do not yet know
5516 #define DEF_MDT_HNDL_0(flags, name, fn) \
5517 DEF_HNDL(MDS, GETATTR, _NET, flags, name, fn, NULL)
5519 static struct mdt_handler mdt_mds_ops[] = {
5520 DEF_MDT_HNDL_F(0, CONNECT, mdt_connect),
5521 DEF_MDT_HNDL_F(0, DISCONNECT, mdt_disconnect),
5522 DEF_MDT_HNDL_F(0, SET_INFO, mdt_set_info),
5523 DEF_MDT_HNDL_F(0 |HABEO_REFERO, GETSTATUS, mdt_getstatus),
5524 DEF_MDT_HNDL_F(HABEO_CORPUS, GETATTR, mdt_getattr),
5525 DEF_MDT_HNDL_F(HABEO_CORPUS|HABEO_REFERO, GETATTR_NAME, mdt_getattr_name),
5526 DEF_MDT_HNDL_F(HABEO_CORPUS, GETXATTR, mdt_getxattr),
5527 DEF_MDT_HNDL_F(0 |HABEO_REFERO, STATFS, mdt_statfs),
5528 DEF_MDT_HNDL_F(0 |MUTABOR, REINT, mdt_reint),
5529 DEF_MDT_HNDL_F(HABEO_CORPUS, CLOSE, mdt_close),
5530 DEF_MDT_HNDL_F(HABEO_CORPUS, DONE_WRITING, mdt_done_writing),
5531 DEF_MDT_HNDL_F(0 |HABEO_REFERO, PIN, mdt_pin),
5532 DEF_MDT_HNDL_0(0, SYNC, mdt_sync),
5533 DEF_MDT_HNDL_F(HABEO_CORPUS|HABEO_REFERO, IS_SUBDIR, mdt_is_subdir),
5534 #ifdef HAVE_QUOTA_SUPPORT
5535 DEF_MDT_HNDL_F(0, QUOTACHECK, mdt_quotacheck_handle),
5536 DEF_MDT_HNDL_F(0, QUOTACTL, mdt_quotactl_handle)
5540 #define DEF_OBD_HNDL(flags, name, fn) \
5541 DEF_HNDL(OBD, PING, _NET, flags, name, fn, NULL)
5544 static struct mdt_handler mdt_obd_ops[] = {
5545 DEF_OBD_HNDL(0, PING, mdt_obd_ping),
5546 DEF_OBD_HNDL(0, LOG_CANCEL, mdt_obd_log_cancel),
5547 DEF_OBD_HNDL(0, QC_CALLBACK, mdt_obd_qc_callback)
5550 #define DEF_DLM_HNDL_0(flags, name, fn) \
5551 DEF_HNDL(LDLM, ENQUEUE, , flags, name, fn, NULL)
5552 #define DEF_DLM_HNDL_F(flags, name, fn) \
5553 DEF_HNDL(LDLM, ENQUEUE, , flags, name, fn, &RQF_LDLM_ ## name)
5555 static struct mdt_handler mdt_dlm_ops[] = {
5556 DEF_DLM_HNDL_F(HABEO_CLAVIS, ENQUEUE, mdt_enqueue),
5557 DEF_DLM_HNDL_0(HABEO_CLAVIS, CONVERT, mdt_convert),
5558 DEF_DLM_HNDL_0(0, BL_CALLBACK, mdt_bl_callback),
5559 DEF_DLM_HNDL_0(0, CP_CALLBACK, mdt_cp_callback)
5562 static struct mdt_handler mdt_llog_ops[] = {
5565 #define DEF_SEC_CTX_HNDL(name, fn) \
5566 DEF_HNDL(SEC_CTX, INIT, _NET, 0, name, fn, NULL)
5568 static struct mdt_handler mdt_sec_ctx_ops[] = {
5569 DEF_SEC_CTX_HNDL(INIT, mdt_sec_ctx_handle),
5570 DEF_SEC_CTX_HNDL(INIT_CONT, mdt_sec_ctx_handle),
5571 DEF_SEC_CTX_HNDL(FINI, mdt_sec_ctx_handle)
5574 static struct mdt_opc_slice mdt_regular_handlers[] = {
5576 .mos_opc_start = MDS_GETATTR,
5577 .mos_opc_end = MDS_LAST_OPC,
5578 .mos_hs = mdt_mds_ops
5581 .mos_opc_start = OBD_PING,
5582 .mos_opc_end = OBD_LAST_OPC,
5583 .mos_hs = mdt_obd_ops
5586 .mos_opc_start = LDLM_ENQUEUE,
5587 .mos_opc_end = LDLM_LAST_OPC,
5588 .mos_hs = mdt_dlm_ops
5591 .mos_opc_start = LLOG_ORIGIN_HANDLE_CREATE,
5592 .mos_opc_end = LLOG_LAST_OPC,
5593 .mos_hs = mdt_llog_ops
5596 .mos_opc_start = SEC_CTX_INIT,
5597 .mos_opc_end = SEC_LAST_OPC,
5598 .mos_hs = mdt_sec_ctx_ops
5605 static struct mdt_handler mdt_readpage_ops[] = {
5606 DEF_MDT_HNDL_F(0, CONNECT, mdt_connect),
5607 DEF_MDT_HNDL_F(HABEO_CORPUS|HABEO_REFERO, READPAGE, mdt_readpage),
5608 #ifdef HAVE_SPLIT_SUPPORT
5609 DEF_MDT_HNDL_F(HABEO_CORPUS|HABEO_REFERO, WRITEPAGE, mdt_writepage),
5613 * XXX: this is ugly and should be fixed one day, see mdc_close() for
5614 * detailed comments. --umka
5616 DEF_MDT_HNDL_F(HABEO_CORPUS, CLOSE, mdt_close),
5617 DEF_MDT_HNDL_F(HABEO_CORPUS, DONE_WRITING, mdt_done_writing),
5620 static struct mdt_opc_slice mdt_readpage_handlers[] = {
5622 .mos_opc_start = MDS_GETATTR,
5623 .mos_opc_end = MDS_LAST_OPC,
5624 .mos_hs = mdt_readpage_ops
5631 static struct mdt_handler mdt_xmds_ops[] = {
5632 DEF_MDT_HNDL_F(0, CONNECT, mdt_connect),
5633 DEF_MDT_HNDL_F(HABEO_CORPUS , GETATTR, mdt_getattr),
5634 DEF_MDT_HNDL_F(0 | MUTABOR , REINT, mdt_reint),
5635 DEF_MDT_HNDL_F(HABEO_CORPUS|HABEO_REFERO, IS_SUBDIR, mdt_is_subdir),
5638 static struct mdt_opc_slice mdt_xmds_handlers[] = {
5640 .mos_opc_start = MDS_GETATTR,
5641 .mos_opc_end = MDS_LAST_OPC,
5642 .mos_hs = mdt_xmds_ops
5645 .mos_opc_start = OBD_PING,
5646 .mos_opc_end = OBD_LAST_OPC,
5647 .mos_hs = mdt_obd_ops
5650 .mos_opc_start = SEC_CTX_INIT,
5651 .mos_opc_end = SEC_LAST_OPC,
5652 .mos_hs = mdt_sec_ctx_ops
5659 static struct mdt_handler mdt_seq_ops[] = {
5660 DEF_SEQ_HNDL_F(0, QUERY, (int (*)(struct mdt_thread_info *))seq_query)
5663 static struct mdt_opc_slice mdt_seq_handlers[] = {
5665 .mos_opc_start = SEQ_QUERY,
5666 .mos_opc_end = SEQ_LAST_OPC,
5667 .mos_hs = mdt_seq_ops
5674 static struct mdt_handler mdt_fld_ops[] = {
5675 DEF_FLD_HNDL_F(0, QUERY, (int (*)(struct mdt_thread_info *))fld_query)
5678 static struct mdt_opc_slice mdt_fld_handlers[] = {
5680 .mos_opc_start = FLD_QUERY,
5681 .mos_opc_end = FLD_LAST_OPC,
5682 .mos_hs = mdt_fld_ops
5689 MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");
5690 MODULE_DESCRIPTION("Lustre Meta-data Target ("LUSTRE_MDT_NAME")");
5691 MODULE_LICENSE("GPL");
5693 CFS_MODULE_PARM(mdt_num_threads, "ul", ulong, 0444,
5694 "number of mdt service threads to start");
5696 cfs_module(mdt, "0.2.0", mdt_mod_init, mdt_mod_exit);