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>
76 mdl_mode_t mdt_mdl_lock_modes[] = {
77 [LCK_MINMODE] = MDL_MINMODE,
84 [LCK_GROUP] = MDL_GROUP
87 ldlm_mode_t mdt_dlm_lock_modes[] = {
88 [MDL_MINMODE] = LCK_MINMODE,
95 [MDL_GROUP] = LCK_GROUP
99 * Initialized in mdt_mod_init().
101 unsigned long mdt_num_threads;
103 /* ptlrpc request handler for MDT. All handlers are
104 * grouped into several slices - struct mdt_opc_slice,
105 * and stored in an array - mdt_handlers[].
108 /* The name of this handler. */
110 /* Fail id for this handler, checked at the beginning of this handler*/
112 /* Operation code for this handler */
114 /* flags are listed in enum mdt_handler_flags below. */
116 /* The actual handler function to execute. */
117 int (*mh_act)(struct mdt_thread_info *info);
118 /* Request format for this request. */
119 const struct req_format *mh_fmt;
122 enum mdt_handler_flags {
124 * struct mdt_body is passed in the incoming message, and object
125 * identified by this fid exists on disk.
127 * "habeo corpus" == "I have a body"
129 HABEO_CORPUS = (1 << 0),
131 * struct ldlm_request is passed in the incoming message.
133 * "habeo clavis" == "I have a key"
135 HABEO_CLAVIS = (1 << 1),
137 * this request has fixed reply format, so that reply message can be
138 * packed by generic code.
140 * "habeo refero" == "I have a reply"
142 HABEO_REFERO = (1 << 2),
144 * this request will modify something, so check whether the filesystem
145 * is readonly or not, then return -EROFS to client asap if necessary.
147 * "mutabor" == "I shall modify"
152 struct mdt_opc_slice {
155 struct mdt_handler *mos_hs;
158 static struct mdt_opc_slice mdt_regular_handlers[];
159 static struct mdt_opc_slice mdt_readpage_handlers[];
160 static struct mdt_opc_slice mdt_xmds_handlers[];
161 static struct mdt_opc_slice mdt_seq_handlers[];
162 static struct mdt_opc_slice mdt_fld_handlers[];
164 static struct mdt_device *mdt_dev(struct lu_device *d);
165 static int mdt_regular_handle(struct ptlrpc_request *req);
166 static int mdt_unpack_req_pack_rep(struct mdt_thread_info *info, __u32 flags);
168 static const struct lu_object_operations mdt_obj_ops;
170 int mdt_get_disposition(struct ldlm_reply *rep, int flag)
174 return (rep->lock_policy_res1 & flag);
177 void mdt_clear_disposition(struct mdt_thread_info *info,
178 struct ldlm_reply *rep, int flag)
181 info->mti_opdata &= ~flag;
183 rep->lock_policy_res1 &= ~flag;
186 void mdt_set_disposition(struct mdt_thread_info *info,
187 struct ldlm_reply *rep, int flag)
190 info->mti_opdata |= flag;
192 rep->lock_policy_res1 |= flag;
195 void mdt_lock_reg_init(struct mdt_lock_handle *lh, ldlm_mode_t lm)
197 lh->mlh_pdo_hash = 0;
198 lh->mlh_reg_mode = lm;
199 lh->mlh_type = MDT_REG_LOCK;
202 void mdt_lock_pdo_init(struct mdt_lock_handle *lh, ldlm_mode_t lm,
203 const char *name, int namelen)
205 lh->mlh_reg_mode = lm;
206 lh->mlh_type = MDT_PDO_LOCK;
209 LASSERT(namelen > 0);
210 lh->mlh_pdo_hash = full_name_hash(name, namelen);
212 LASSERT(namelen == 0);
213 lh->mlh_pdo_hash = 0ull;
217 static void mdt_lock_pdo_mode(struct mdt_thread_info *info, struct mdt_object *o,
218 struct mdt_lock_handle *lh)
224 * Any dir access needs couple of locks:
226 * 1) on part of dir we gonna take lookup/modify;
228 * 2) on whole dir to protect it from concurrent splitting and/or to
229 * flush client's cache for readdir().
231 * so, for a given mode and object this routine decides what lock mode
232 * to use for lock #2:
234 * 1) if caller's gonna lookup in dir then we need to protect dir from
235 * being splitted only - LCK_CR
237 * 2) if caller's gonna modify dir then we need to protect dir from
238 * being splitted and to flush cache - LCK_CW
240 * 3) if caller's gonna modify dir and that dir seems ready for
241 * splitting then we need to protect it from any type of access
242 * (lookup/modify/split) - LCK_EX --bzzz
245 LASSERT(lh->mlh_reg_mode != LCK_MINMODE);
246 LASSERT(lh->mlh_pdo_mode == LCK_MINMODE);
249 * Ask underlaying level its opinion about preferable PDO lock mode
250 * having access type passed as regular lock mode:
252 * - MDL_MINMODE means that lower layer does not want to specify lock
255 * - MDL_NL means that no PDO lock should be taken. This is used in some
256 * cases. Say, for non-splittable directories no need to use PDO locks
259 mode = mdo_lock_mode(info->mti_env, mdt_object_child(o),
260 mdt_dlm_mode2mdl_mode(lh->mlh_reg_mode));
262 if (mode != MDL_MINMODE) {
263 lh->mlh_pdo_mode = mdt_mdl_mode2dlm_mode(mode);
266 * Lower layer does not want to specify locking mode. We do it
267 * our selves. No special protection is needed, just flush
268 * client's cache on modification and allow concurrent
271 switch (lh->mlh_reg_mode) {
273 lh->mlh_pdo_mode = LCK_EX;
276 lh->mlh_pdo_mode = LCK_CR;
279 lh->mlh_pdo_mode = LCK_CW;
282 CERROR("Not expected lock type (0x%x)\n",
283 (int)lh->mlh_reg_mode);
288 LASSERT(lh->mlh_pdo_mode != LCK_MINMODE);
292 static int mdt_getstatus(struct mdt_thread_info *info)
294 struct mdt_device *mdt = info->mti_mdt;
295 struct md_device *next = mdt->mdt_child;
296 struct mdt_body *repbody;
301 rc = mdt_check_ucred(info);
303 RETURN(err_serious(rc));
305 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_GETSTATUS_PACK))
306 RETURN(err_serious(-ENOMEM));
308 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
309 rc = next->md_ops->mdo_root_get(info->mti_env, next, &repbody->fid1);
313 repbody->valid |= OBD_MD_FLID;
315 if (mdt->mdt_opts.mo_mds_capa &&
316 info->mti_exp->exp_connect_flags & OBD_CONNECT_MDS_CAPA) {
317 struct mdt_object *root;
318 struct lustre_capa *capa;
320 root = mdt_object_find(info->mti_env, mdt, &repbody->fid1);
322 RETURN(PTR_ERR(root));
324 capa = req_capsule_server_get(info->mti_pill, &RMF_CAPA1);
326 capa->lc_opc = CAPA_OPC_MDS_DEFAULT;
327 rc = mo_capa_get(info->mti_env, mdt_object_child(root), capa,
329 mdt_object_put(info->mti_env, root);
331 repbody->valid |= OBD_MD_FLMDSCAPA;
337 static int mdt_statfs(struct mdt_thread_info *info)
339 struct md_device *next = info->mti_mdt->mdt_child;
340 struct ptlrpc_service *svc;
341 struct obd_statfs *osfs;
346 svc = info->mti_pill->rc_req->rq_rqbd->rqbd_service;
348 /* This will trigger a watchdog timeout */
349 OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_STATFS_LCW_SLEEP,
350 (MDT_SERVICE_WATCHDOG_FACTOR *
351 at_get(&svc->srv_at_estimate) / 1000) + 1);
353 rc = mdt_check_ucred(info);
355 RETURN(err_serious(rc));
357 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_STATFS_PACK)) {
358 rc = err_serious(-ENOMEM);
360 osfs = req_capsule_server_get(info->mti_pill, &RMF_OBD_STATFS);
361 rc = next->md_ops->mdo_statfs(info->mti_env, next,
363 statfs_pack(osfs, &info->mti_u.ksfs);
368 void mdt_pack_size2body(struct mdt_thread_info *info, struct mdt_object *o)
371 struct lu_attr *attr = &info->mti_attr.ma_attr;
373 b = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
375 /* Check if Size-on-MDS is enabled. */
376 if ((mdt_conn_flags(info) & OBD_CONNECT_SOM) &&
377 S_ISREG(attr->la_mode) && mdt_sizeonmds_enabled(o)) {
378 b->valid |= (OBD_MD_FLSIZE | OBD_MD_FLBLOCKS);
379 b->size = attr->la_size;
380 b->blocks = attr->la_blocks;
384 void mdt_pack_attr2body(struct mdt_thread_info *info, struct mdt_body *b,
385 const struct lu_attr *attr, const struct lu_fid *fid)
387 /*XXX should pack the reply body according to lu_valid*/
388 b->valid |= OBD_MD_FLCTIME | OBD_MD_FLUID |
389 OBD_MD_FLGID | OBD_MD_FLTYPE |
390 OBD_MD_FLMODE | OBD_MD_FLNLINK | OBD_MD_FLFLAGS |
391 OBD_MD_FLATIME | OBD_MD_FLMTIME ;
393 if (!S_ISREG(attr->la_mode))
394 b->valid |= OBD_MD_FLSIZE | OBD_MD_FLBLOCKS | OBD_MD_FLRDEV;
396 b->atime = attr->la_atime;
397 b->mtime = attr->la_mtime;
398 b->ctime = attr->la_ctime;
399 b->mode = attr->la_mode;
400 b->size = attr->la_size;
401 b->blocks = attr->la_blocks;
402 b->uid = attr->la_uid;
403 b->gid = attr->la_gid;
404 b->flags = attr->la_flags;
405 b->nlink = attr->la_nlink;
406 b->rdev = attr->la_rdev;
410 b->valid |= OBD_MD_FLID;
412 /* FIXME: these should be fixed when new igif ready.*/
413 b->ino = fid_oid(fid); /* 1.6 compatibility */
414 b->generation = fid_ver(fid); /* 1.6 compatibility */
415 b->valid |= OBD_MD_FLGENER; /* 1.6 compatibility */
417 CDEBUG(D_INODE, DFID": nlink=%d, mode=%o, size="LPU64"\n",
418 PFID(fid), b->nlink, b->mode, b->size);
422 mdt_body_reverse_idmap(info, b);
425 static inline int mdt_body_has_lov(const struct lu_attr *la,
426 const struct mdt_body *body)
428 return ((S_ISREG(la->la_mode) && (body->valid & OBD_MD_FLEASIZE)) ||
429 (S_ISDIR(la->la_mode) && (body->valid & OBD_MD_FLDIREA )) );
432 static int mdt_getattr_internal(struct mdt_thread_info *info,
433 struct mdt_object *o)
435 struct md_object *next = mdt_object_child(o);
436 const struct mdt_body *reqbody = info->mti_body;
437 struct ptlrpc_request *req = mdt_info_req(info);
438 struct md_attr *ma = &info->mti_attr;
439 struct lu_attr *la = &ma->ma_attr;
440 struct req_capsule *pill = info->mti_pill;
441 const struct lu_env *env = info->mti_env;
442 struct mdt_body *repbody;
443 struct lu_buf *buffer = &info->mti_buf;
447 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_GETATTR_PACK))
448 RETURN(err_serious(-ENOMEM));
450 repbody = req_capsule_server_get(pill, &RMF_MDT_BODY);
454 rc = mdt_object_exists(o);
456 /* This object is located on remote node.*/
457 repbody->fid1 = *mdt_object_fid(o);
458 repbody->valid = OBD_MD_FLID | OBD_MD_MDS;
462 buffer->lb_buf = req_capsule_server_get(pill, &RMF_MDT_MD);
463 buffer->lb_len = req_capsule_get_size(pill, &RMF_MDT_MD, RCL_SERVER);
465 /* If it is dir object and client require MEA, then we got MEA */
466 if (S_ISDIR(lu_object_attr(&next->mo_lu)) &&
467 reqbody->valid & OBD_MD_MEA) {
468 /* Assumption: MDT_MD size is enough for lmv size. */
469 ma->ma_lmv = buffer->lb_buf;
470 ma->ma_lmv_size = buffer->lb_len;
471 ma->ma_need = MA_LMV | MA_INODE;
473 ma->ma_lmm = buffer->lb_buf;
474 ma->ma_lmm_size = buffer->lb_len;
475 ma->ma_need = MA_LOV | MA_INODE;
478 if (S_ISDIR(lu_object_attr(&next->mo_lu)) &&
479 reqbody->valid & OBD_MD_FLDIREA &&
480 lustre_msg_get_opc(req->rq_reqmsg) == MDS_GETATTR) {
481 /* get default stripe info for this dir. */
482 ma->ma_need |= MA_LOV_DEF;
484 rc = mo_attr_get(env, next, ma);
486 CERROR("getattr error for "DFID": %d\n",
487 PFID(mdt_object_fid(o)), rc);
491 if (likely(ma->ma_valid & MA_INODE))
492 mdt_pack_attr2body(info, repbody, la, mdt_object_fid(o));
496 if (mdt_body_has_lov(la, reqbody)) {
497 if (ma->ma_valid & MA_LOV) {
498 LASSERT(ma->ma_lmm_size);
499 mdt_dump_lmm(D_INFO, ma->ma_lmm);
500 repbody->eadatasize = ma->ma_lmm_size;
501 if (S_ISDIR(la->la_mode))
502 repbody->valid |= OBD_MD_FLDIREA;
504 repbody->valid |= OBD_MD_FLEASIZE;
506 if (ma->ma_valid & MA_LMV) {
507 LASSERT(S_ISDIR(la->la_mode));
508 repbody->eadatasize = ma->ma_lmv_size;
509 repbody->valid |= (OBD_MD_FLDIREA|OBD_MD_MEA);
511 if (!(ma->ma_valid & MA_LOV) && !(ma->ma_valid & MA_LMV)) {
512 repbody->valid |= OBD_MD_FLSIZE | OBD_MD_FLBLOCKS;
514 } else if (S_ISLNK(la->la_mode) &&
515 reqbody->valid & OBD_MD_LINKNAME) {
516 buffer->lb_buf = ma->ma_lmm;
517 buffer->lb_len = reqbody->eadatasize;
518 rc = mo_readlink(env, next, buffer);
519 if (unlikely(rc <= 0)) {
520 CERROR("readlink failed: %d\n", rc);
523 repbody->valid |= OBD_MD_LINKNAME;
524 repbody->eadatasize = rc;
526 ((char*)ma->ma_lmm)[rc - 1] = 0;
527 CDEBUG(D_INODE, "symlink dest %s, len = %d\n",
528 (char*)ma->ma_lmm, rc);
533 if (reqbody->valid & OBD_MD_FLMODEASIZE) {
534 repbody->max_cookiesize = info->mti_mdt->mdt_max_cookiesize;
535 repbody->max_mdsize = info->mti_mdt->mdt_max_mdsize;
536 repbody->valid |= OBD_MD_FLMODEASIZE;
537 CDEBUG(D_INODE, "I am going to change the MAX_MD_SIZE & "
538 "MAX_COOKIE to : %d:%d\n", repbody->max_mdsize,
539 repbody->max_cookiesize);
542 if (exp_connect_rmtclient(info->mti_exp) &&
543 reqbody->valid & OBD_MD_FLRMTPERM) {
544 void *buf = req_capsule_server_get(pill, &RMF_ACL);
546 /* mdt_getattr_lock only */
547 rc = mdt_pack_remote_perm(info, o, buf);
549 repbody->valid &= ~OBD_MD_FLRMTPERM;
550 repbody->aclsize = 0;
553 repbody->valid |= OBD_MD_FLRMTPERM;
554 repbody->aclsize = sizeof(struct mdt_remote_perm);
557 #ifdef CONFIG_FS_POSIX_ACL
558 else if ((req->rq_export->exp_connect_flags & OBD_CONNECT_ACL) &&
559 (reqbody->valid & OBD_MD_FLACL)) {
560 buffer->lb_buf = req_capsule_server_get(pill, &RMF_ACL);
561 buffer->lb_len = req_capsule_get_size(pill,
562 &RMF_ACL, RCL_SERVER);
563 if (buffer->lb_len > 0) {
564 rc = mo_xattr_get(env, next, buffer,
565 XATTR_NAME_ACL_ACCESS);
567 if (rc == -ENODATA) {
568 repbody->aclsize = 0;
569 repbody->valid |= OBD_MD_FLACL;
571 } else if (rc == -EOPNOTSUPP) {
574 CERROR("got acl size: %d\n", rc);
577 repbody->aclsize = rc;
578 repbody->valid |= OBD_MD_FLACL;
585 if (reqbody->valid & OBD_MD_FLMDSCAPA &&
586 info->mti_mdt->mdt_opts.mo_mds_capa &&
587 info->mti_exp->exp_connect_flags & OBD_CONNECT_MDS_CAPA) {
588 struct lustre_capa *capa;
590 capa = req_capsule_server_get(pill, &RMF_CAPA1);
592 capa->lc_opc = CAPA_OPC_MDS_DEFAULT;
593 rc = mo_capa_get(env, next, capa, 0);
596 repbody->valid |= OBD_MD_FLMDSCAPA;
601 static int mdt_renew_capa(struct mdt_thread_info *info)
603 struct mdt_object *obj = info->mti_object;
604 struct mdt_body *body;
605 struct lustre_capa *capa, *c;
609 /* if object doesn't exist, or server has disabled capability,
610 * return directly, client will find body->valid OBD_MD_FLOSSCAPA
613 if (!obj || !info->mti_mdt->mdt_opts.mo_oss_capa ||
614 !(info->mti_exp->exp_connect_flags & OBD_CONNECT_OSS_CAPA))
617 body = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
618 LASSERT(body != NULL);
620 c = req_capsule_client_get(info->mti_pill, &RMF_CAPA1);
623 capa = req_capsule_server_get(info->mti_pill, &RMF_CAPA2);
627 rc = mo_capa_get(info->mti_env, mdt_object_child(obj), capa, 1);
629 body->valid |= OBD_MD_FLOSSCAPA;
633 static int mdt_getattr(struct mdt_thread_info *info)
635 struct mdt_object *obj = info->mti_object;
636 struct req_capsule *pill = info->mti_pill;
637 struct mdt_body *reqbody;
638 struct mdt_body *repbody;
644 reqbody = req_capsule_client_get(pill, &RMF_MDT_BODY);
647 if (reqbody->valid & OBD_MD_FLOSSCAPA) {
648 rc = req_capsule_server_pack(pill);
650 RETURN(err_serious(rc));
651 rc = mdt_renew_capa(info);
652 GOTO(out_shrink, rc);
655 LASSERT(obj != NULL);
656 LASSERT(lu_object_assert_exists(&obj->mot_obj.mo_lu));
658 mode = lu_object_attr(&obj->mot_obj.mo_lu);
659 if (S_ISLNK(mode) && (reqbody->valid & OBD_MD_LINKNAME) &&
660 (reqbody->eadatasize > info->mti_mdt->mdt_max_mdsize))
661 md_size = reqbody->eadatasize;
663 md_size = info->mti_mdt->mdt_max_mdsize;
665 req_capsule_set_size(pill, &RMF_MDT_MD, RCL_SERVER, md_size);
667 rc = req_capsule_server_pack(pill);
668 if (unlikely(rc != 0))
669 RETURN(err_serious(rc));
671 repbody = req_capsule_server_get(pill, &RMF_MDT_BODY);
672 LASSERT(repbody != NULL);
673 repbody->eadatasize = 0;
674 repbody->aclsize = 0;
676 if (reqbody->valid & OBD_MD_FLRMTPERM)
677 rc = mdt_init_ucred(info, reqbody);
679 rc = mdt_check_ucred(info);
681 GOTO(out_shrink, rc);
683 info->mti_spec.sp_ck_split = !!(reqbody->valid & OBD_MD_FLCKSPLIT);
684 info->mti_cross_ref = !!(reqbody->valid & OBD_MD_FLCROSSREF);
687 * Don't check capability at all, because rename might getattr for
688 * remote obj, and at that time no capability is available.
690 mdt_set_capainfo(info, 1, &reqbody->fid1, BYPASS_CAPA);
691 rc = mdt_getattr_internal(info, obj);
692 if (reqbody->valid & OBD_MD_FLRMTPERM)
693 mdt_exit_ucred(info);
696 mdt_shrink_reply(info);
700 static int mdt_is_subdir(struct mdt_thread_info *info)
702 struct mdt_object *o = info->mti_object;
703 struct req_capsule *pill = info->mti_pill;
704 const struct mdt_body *body = info->mti_body;
705 struct mdt_body *repbody;
711 repbody = req_capsule_server_get(pill, &RMF_MDT_BODY);
714 * We save last checked parent fid to @repbody->fid1 for remote
717 LASSERT(fid_is_sane(&body->fid2));
718 LASSERT(mdt_object_exists(o) > 0);
719 rc = mdo_is_subdir(info->mti_env, mdt_object_child(o),
720 &body->fid2, &repbody->fid1);
721 if (rc == 0 || rc == -EREMOTE)
722 repbody->valid |= OBD_MD_FLID;
727 static int mdt_raw_lookup(struct mdt_thread_info *info,
728 struct mdt_object *parent,
729 const struct lu_name *lname,
730 struct ldlm_reply *ldlm_rep)
732 struct md_object *next = mdt_object_child(info->mti_object);
733 const struct mdt_body *reqbody = info->mti_body;
734 struct lu_fid *child_fid = &info->mti_tmp_fid1;
735 struct mdt_body *repbody;
739 if (reqbody->valid != OBD_MD_FLID)
742 LASSERT(!info->mti_cross_ref);
744 /* Only got the fid of this obj by name */
745 rc = mdo_lookup(info->mti_env, next, lname, child_fid,
748 /* XXX is raw_lookup possible as intent operation? */
751 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_NEG);
754 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_POS);
756 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
759 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
760 repbody->fid1 = *child_fid;
761 repbody->valid = OBD_MD_FLID;
767 * UPDATE lock should be taken against parent, and be release before exit;
768 * child_bits lock should be taken against child, and be returned back:
769 * (1)normal request should release the child lock;
770 * (2)intent request will grant the lock to client.
772 static int mdt_getattr_name_lock(struct mdt_thread_info *info,
773 struct mdt_lock_handle *lhc,
775 struct ldlm_reply *ldlm_rep)
777 struct ptlrpc_request *req = mdt_info_req(info);
778 struct mdt_body *reqbody = NULL;
779 struct mdt_object *parent = info->mti_object;
780 struct mdt_object *child;
781 struct md_object *next = mdt_object_child(parent);
782 struct lu_fid *child_fid = &info->mti_tmp_fid1;
783 struct lu_name *lname = NULL;
784 const char *name = NULL;
786 struct mdt_lock_handle *lhp;
787 struct ldlm_lock *lock;
788 struct ldlm_res_id *res_id;
794 is_resent = lustre_handle_is_used(&lhc->mlh_reg_lh);
795 LASSERT(ergo(is_resent,
796 lustre_msg_get_flags(req->rq_reqmsg) & MSG_RESENT));
798 LASSERT(parent != NULL);
799 name = req_capsule_client_get(info->mti_pill, &RMF_NAME);
801 RETURN(err_serious(-EFAULT));
803 namelen = req_capsule_get_size(info->mti_pill, &RMF_NAME,
805 if (!info->mti_cross_ref) {
807 * XXX: Check for "namelen == 0" is for getattr by fid
808 * (OBD_CONNECT_ATTRFID), otherwise do not allow empty name,
809 * that is the name must contain at least one character and
810 * the terminating '\0'
813 reqbody = req_capsule_client_get(info->mti_pill,
815 LASSERT(fid_is_sane(&reqbody->fid2));
818 CDEBUG(D_INODE, "getattr with lock for "DFID"/"DFID", "
820 PFID(mdt_object_fid(parent)), PFID(&reqbody->fid2),
823 lname = mdt_name(info->mti_env, (char *)name, namelen);
824 CDEBUG(D_INODE, "getattr with lock for "DFID"/%s, "
825 "ldlm_rep = %p\n", PFID(mdt_object_fid(parent)),
829 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_EXECD);
831 rc = mdt_object_exists(parent);
832 if (unlikely(rc == 0)) {
833 LU_OBJECT_DEBUG(D_WARNING, info->mti_env,
834 &parent->mot_obj.mo_lu,
835 "Parent doesn't exist!\n");
837 } else if (!info->mti_cross_ref) {
838 LASSERTF(rc > 0, "Parent "DFID" is on remote server\n",
839 PFID(mdt_object_fid(parent)));
842 rc = mdt_raw_lookup(info, parent, lname, ldlm_rep);
850 if (info->mti_cross_ref) {
851 /* Only getattr on the child. Parent is on another node. */
852 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_POS);
854 CDEBUG(D_INODE, "partial getattr_name child_fid = "DFID", "
855 "ldlm_rep=%p\n", PFID(mdt_object_fid(child)), ldlm_rep);
858 /* Do not take lock for resent case. */
859 lock = ldlm_handle2lock(&lhc->mlh_reg_lh);
860 LASSERTF(lock != NULL, "Invalid lock handle "LPX64"\n",
861 lhc->mlh_reg_lh.cookie);
862 LASSERT(fid_res_name_eq(mdt_object_fid(child),
863 &lock->l_resource->lr_name));
867 mdt_lock_handle_init(lhc);
868 mdt_lock_reg_init(lhc, LCK_PR);
871 * Object's name is on another MDS, no lookup lock is
872 * needed here but update is.
874 child_bits &= ~MDS_INODELOCK_LOOKUP;
875 child_bits |= MDS_INODELOCK_UPDATE;
877 rc = mdt_object_lock(info, child, lhc, child_bits,
881 /* Finally, we can get attr for child. */
882 mdt_set_capainfo(info, 0, mdt_object_fid(child),
884 rc = mdt_getattr_internal(info, child);
885 if (unlikely(rc != 0))
886 mdt_object_unlock(info, child, lhc, 1);
891 /* step 1: lock parent */
892 lhp = &info->mti_lh[MDT_LH_PARENT];
893 mdt_lock_pdo_init(lhp, LCK_PR, name, namelen);
894 rc = mdt_object_lock(info, parent, lhp, MDS_INODELOCK_UPDATE,
897 if (unlikely(rc != 0))
901 /* step 2: lookup child's fid by name */
902 rc = mdo_lookup(info->mti_env, next, lname, child_fid,
907 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_NEG);
908 GOTO(out_parent, rc);
910 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_POS);
912 *child_fid = reqbody->fid2;
913 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_POS);
917 *step 3: find the child object by fid & lock it.
918 * regardless if it is local or remote.
920 child = mdt_object_find(info->mti_env, info->mti_mdt, child_fid);
922 if (unlikely(IS_ERR(child)))
923 GOTO(out_parent, rc = PTR_ERR(child));
925 /* Do not take lock for resent case. */
926 lock = ldlm_handle2lock(&lhc->mlh_reg_lh);
927 LASSERTF(lock != NULL, "Invalid lock handle "LPX64"\n",
928 lhc->mlh_reg_lh.cookie);
930 res_id = &lock->l_resource->lr_name;
931 if (!fid_res_name_eq(mdt_object_fid(child),
932 &lock->l_resource->lr_name)) {
933 LASSERTF(fid_res_name_eq(mdt_object_fid(parent),
934 &lock->l_resource->lr_name),
935 "Lock res_id: %lu/%lu/%lu, Fid: "DFID".\n",
936 (unsigned long)res_id->name[0],
937 (unsigned long)res_id->name[1],
938 (unsigned long)res_id->name[2],
939 PFID(mdt_object_fid(parent)));
940 CWARN("Although resent, but still not get child lock"
941 "parent:"DFID" child:"DFID"\n",
942 PFID(mdt_object_fid(parent)),
943 PFID(mdt_object_fid(child)));
944 lustre_msg_clear_flags(req->rq_reqmsg, MSG_RESENT);
953 ma = &info->mti_attr;
955 mdt_lock_handle_init(lhc);
956 mdt_lock_reg_init(lhc, LCK_PR);
958 if (mdt_object_exists(child) == 0) {
959 LU_OBJECT_DEBUG(D_WARNING, info->mti_env,
960 &child->mot_obj.mo_lu,
961 "Object doesn't exist!\n");
962 GOTO(out_child, rc = -ESTALE);
966 ma->ma_need = MA_INODE;
967 rc = mo_attr_get(info->mti_env, next, ma);
968 if (unlikely(rc != 0))
971 /* If the file has not been changed for some time, we return
972 * not only a LOOKUP lock, but also an UPDATE lock and this
973 * might save us RPC on later STAT. For directories, it also
974 * let negative dentry starts working for this dir. */
975 if (ma->ma_valid & MA_INODE &&
976 ma->ma_attr.la_valid & LA_CTIME &&
977 info->mti_mdt->mdt_namespace->ns_ctime_age_limit +
978 ma->ma_attr.la_ctime < cfs_time_current_sec())
979 child_bits |= MDS_INODELOCK_UPDATE;
981 rc = mdt_object_lock(info, child, lhc, child_bits,
984 if (unlikely(rc != 0))
988 /* finally, we can get attr for child. */
989 mdt_set_capainfo(info, 1, child_fid, BYPASS_CAPA);
990 rc = mdt_getattr_internal(info, child);
991 if (unlikely(rc != 0)) {
992 mdt_object_unlock(info, child, lhc, 1);
994 lock = ldlm_handle2lock(&lhc->mlh_reg_lh);
996 struct mdt_body *repbody;
998 /* Debugging code. */
999 res_id = &lock->l_resource->lr_name;
1000 LDLM_DEBUG(lock, "Returning lock to client\n");
1001 LASSERTF(fid_res_name_eq(mdt_object_fid(child),
1002 &lock->l_resource->lr_name),
1003 "Lock res_id: %lu/%lu/%lu, Fid: "DFID".\n",
1004 (unsigned long)res_id->name[0],
1005 (unsigned long)res_id->name[1],
1006 (unsigned long)res_id->name[2],
1007 PFID(mdt_object_fid(child)));
1009 * Pack Size-on-MDS inode attributes to the body if
1010 * update lock is given.
1012 repbody = req_capsule_server_get(info->mti_pill,
1014 if (lock->l_policy_data.l_inodebits.bits &
1015 MDS_INODELOCK_UPDATE)
1016 mdt_pack_size2body(info, child);
1017 LDLM_LOCK_PUT(lock);
1022 mdt_object_put(info->mti_env, child);
1024 mdt_object_unlock(info, parent, lhp, 1);
1028 /* normal handler: should release the child lock */
1029 static int mdt_getattr_name(struct mdt_thread_info *info)
1031 struct mdt_lock_handle *lhc = &info->mti_lh[MDT_LH_CHILD];
1032 struct mdt_body *reqbody;
1033 struct mdt_body *repbody;
1037 reqbody = req_capsule_client_get(info->mti_pill, &RMF_MDT_BODY);
1038 LASSERT(reqbody != NULL);
1039 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
1040 LASSERT(repbody != NULL);
1042 info->mti_spec.sp_ck_split = !!(reqbody->valid & OBD_MD_FLCKSPLIT);
1043 info->mti_cross_ref = !!(reqbody->valid & OBD_MD_FLCROSSREF);
1044 repbody->eadatasize = 0;
1045 repbody->aclsize = 0;
1047 rc = mdt_init_ucred(info, reqbody);
1049 GOTO(out_shrink, rc);
1051 rc = mdt_getattr_name_lock(info, lhc, MDS_INODELOCK_UPDATE, NULL);
1052 if (lustre_handle_is_used(&lhc->mlh_reg_lh)) {
1053 ldlm_lock_decref(&lhc->mlh_reg_lh, lhc->mlh_reg_mode);
1054 lhc->mlh_reg_lh.cookie = 0;
1056 mdt_exit_ucred(info);
1059 mdt_shrink_reply(info);
1063 static const struct lu_device_operations mdt_lu_ops;
1065 static int lu_device_is_mdt(struct lu_device *d)
1067 return ergo(d != NULL && d->ld_ops != NULL, d->ld_ops == &mdt_lu_ops);
1070 static int mdt_set_info(struct mdt_thread_info *info)
1072 struct ptlrpc_request *req = mdt_info_req(info);
1078 rc = req_capsule_server_pack(info->mti_pill);
1082 key = req_capsule_client_get(info->mti_pill, &RMF_SETINFO_KEY);
1084 DEBUG_REQ(D_HA, req, "no set_info key");
1088 keylen = req_capsule_get_size(info->mti_pill, &RMF_SETINFO_KEY,
1091 val = req_capsule_client_get(info->mti_pill, &RMF_SETINFO_VAL);
1093 DEBUG_REQ(D_HA, req, "no set_info val");
1097 if (!KEY_IS(KEY_READ_ONLY))
1101 lustre_msg_set_status(req->rq_repmsg, 0);
1103 spin_lock(&req->rq_export->exp_lock);
1105 req->rq_export->exp_connect_flags |= OBD_CONNECT_RDONLY;
1107 req->rq_export->exp_connect_flags &= ~OBD_CONNECT_RDONLY;
1108 spin_unlock(&req->rq_export->exp_lock);
1113 static int mdt_connect(struct mdt_thread_info *info)
1116 struct ptlrpc_request *req;
1118 req = mdt_info_req(info);
1119 rc = target_handle_connect(req);
1121 LASSERT(req->rq_export != NULL);
1122 info->mti_mdt = mdt_dev(req->rq_export->exp_obd->obd_lu_dev);
1123 rc = mdt_init_sec_level(info);
1125 rc = mdt_init_idmap(info);
1127 obd_disconnect(class_export_get(req->rq_export));
1129 rc = err_serious(rc);
1134 static int mdt_disconnect(struct mdt_thread_info *info)
1139 rc = target_handle_disconnect(mdt_info_req(info));
1141 rc = err_serious(rc);
1145 static int mdt_sendpage(struct mdt_thread_info *info,
1146 struct lu_rdpg *rdpg)
1148 struct ptlrpc_request *req = mdt_info_req(info);
1149 struct ptlrpc_bulk_desc *desc;
1150 struct l_wait_info *lwi = &info->mti_u.rdpg.mti_wait_info;
1158 desc = ptlrpc_prep_bulk_exp(req, rdpg->rp_npages, BULK_PUT_SOURCE,
1163 for (i = 0, tmpcount = rdpg->rp_count;
1164 i < rdpg->rp_npages; i++, tmpcount -= tmpsize) {
1165 tmpsize = min_t(int, tmpcount, CFS_PAGE_SIZE);
1166 ptlrpc_prep_bulk_page(desc, rdpg->rp_pages[i], 0, tmpsize);
1169 LASSERT(desc->bd_nob == rdpg->rp_count);
1170 rc = ptlrpc_start_bulk_transfer(desc);
1172 GOTO(free_desc, rc);
1174 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_SENDPAGE))
1175 GOTO(abort_bulk, rc = 0);
1177 timeout = (int) req->rq_deadline - cfs_time_current_sec();
1179 CERROR("Req deadline already passed %lu (now: %lu)\n",
1180 req->rq_deadline, cfs_time_current_sec());
1181 *lwi = LWI_TIMEOUT(max(timeout, 1) * HZ, NULL, NULL);
1182 rc = l_wait_event(desc->bd_waitq, !ptlrpc_bulk_active(desc), lwi);
1183 LASSERT (rc == 0 || rc == -ETIMEDOUT);
1186 if (desc->bd_success &&
1187 desc->bd_nob_transferred == rdpg->rp_count)
1188 GOTO(free_desc, rc);
1190 rc = -ETIMEDOUT; /* XXX should this be a different errno? */
1193 DEBUG_REQ(D_ERROR, req, "bulk failed: %s %d(%d), evicting %s@%s",
1194 (rc == -ETIMEDOUT) ? "timeout" : "network error",
1195 desc->bd_nob_transferred, rdpg->rp_count,
1196 req->rq_export->exp_client_uuid.uuid,
1197 req->rq_export->exp_connection->c_remote_uuid.uuid);
1199 class_fail_export(req->rq_export);
1203 ptlrpc_abort_bulk(desc);
1205 ptlrpc_free_bulk(desc);
1209 #ifdef HAVE_SPLIT_SUPPORT
1211 * Retrieve dir entry from the page and insert it to the slave object, actually,
1212 * this should be in osd layer, but since it will not in the final product, so
1213 * just do it here and do not define more moo api anymore for this.
1215 static int mdt_write_dir_page(struct mdt_thread_info *info, struct page *page,
1218 struct mdt_object *object = info->mti_object;
1219 struct lu_fid *lf = &info->mti_tmp_fid2;
1220 struct md_attr *ma = &info->mti_attr;
1221 struct lu_dirpage *dp;
1222 struct lu_dirent *ent;
1223 int rc = 0, offset = 0;
1226 /* Make sure we have at least one entry. */
1231 * Disable trans for this name insert, since it will include many trans
1234 info->mti_no_need_trans = 1;
1236 * When write_dir_page, no need update parent's ctime,
1237 * and no permission check for name_insert.
1239 ma->ma_attr.la_ctime = 0;
1240 ma->ma_attr.la_valid = LA_MODE;
1241 ma->ma_valid = MA_INODE;
1244 dp = page_address(page);
1245 offset = (int)((__u32)lu_dirent_start(dp) - (__u32)dp);
1247 for (ent = lu_dirent_start(dp); ent != NULL;
1248 ent = lu_dirent_next(ent)) {
1249 struct lu_name *lname;
1252 if (le16_to_cpu(ent->lde_namelen) == 0)
1255 fid_le_to_cpu(lf, &ent->lde_fid);
1256 if (le64_to_cpu(ent->lde_hash) & MAX_HASH_HIGHEST_BIT)
1257 ma->ma_attr.la_mode = S_IFDIR;
1259 ma->ma_attr.la_mode = 0;
1260 OBD_ALLOC(name, le16_to_cpu(ent->lde_namelen) + 1);
1262 GOTO(out, rc = -ENOMEM);
1264 memcpy(name, ent->lde_name, le16_to_cpu(ent->lde_namelen));
1265 lname = mdt_name(info->mti_env, name,
1266 le16_to_cpu(ent->lde_namelen));
1267 ma->ma_attr_flags |= (MDS_PERM_BYPASS | MDS_QUOTA_IGNORE);
1268 rc = mdo_name_insert(info->mti_env,
1269 md_object_next(&object->mot_obj),
1271 OBD_FREE(name, le16_to_cpu(ent->lde_namelen) + 1);
1273 CERROR("Can't insert %*.*s, rc %d\n",
1274 le16_to_cpu(ent->lde_namelen),
1275 le16_to_cpu(ent->lde_namelen),
1280 offset += lu_dirent_size(ent);
1290 static int mdt_bulk_timeout(void *data)
1294 CERROR("mdt bulk transfer timeout \n");
1299 static int mdt_writepage(struct mdt_thread_info *info)
1301 struct ptlrpc_request *req = mdt_info_req(info);
1302 struct mdt_body *reqbody;
1303 struct l_wait_info *lwi;
1304 struct ptlrpc_bulk_desc *desc;
1310 reqbody = req_capsule_client_get(info->mti_pill, &RMF_MDT_BODY);
1311 if (reqbody == NULL)
1312 RETURN(err_serious(-EFAULT));
1314 desc = ptlrpc_prep_bulk_exp(req, 1, BULK_GET_SINK, MDS_BULK_PORTAL);
1316 RETURN(err_serious(-ENOMEM));
1318 /* allocate the page for the desc */
1319 page = cfs_alloc_page(CFS_ALLOC_STD);
1321 GOTO(desc_cleanup, rc = -ENOMEM);
1323 CDEBUG(D_INFO, "Received page offset %d size %d \n",
1324 (int)reqbody->size, (int)reqbody->nlink);
1326 ptlrpc_prep_bulk_page(desc, page, (int)reqbody->size,
1327 (int)reqbody->nlink);
1330 * Check if client was evicted while we were doing i/o before touching
1335 GOTO(cleanup_page, rc = -ENOMEM);
1337 if (desc->bd_export->exp_failed)
1340 rc = ptlrpc_start_bulk_transfer (desc);
1342 *lwi = LWI_TIMEOUT_INTERVAL(obd_timeout * HZ / 4, HZ,
1343 mdt_bulk_timeout, desc);
1344 rc = l_wait_event(desc->bd_waitq, !ptlrpc_bulk_active(desc) ||
1345 desc->bd_export->exp_failed, lwi);
1346 LASSERT(rc == 0 || rc == -ETIMEDOUT);
1347 if (rc == -ETIMEDOUT) {
1348 DEBUG_REQ(D_ERROR, req, "timeout on bulk GET");
1349 ptlrpc_abort_bulk(desc);
1350 } else if (desc->bd_export->exp_failed) {
1351 DEBUG_REQ(D_ERROR, req, "Eviction on bulk GET");
1353 ptlrpc_abort_bulk(desc);
1354 } else if (!desc->bd_success ||
1355 desc->bd_nob_transferred != desc->bd_nob) {
1356 DEBUG_REQ(D_ERROR, req, "%s bulk GET %d(%d)",
1358 "truncated" : "network error on",
1359 desc->bd_nob_transferred, desc->bd_nob);
1360 /* XXX should this be a different errno? */
1364 DEBUG_REQ(D_ERROR, req, "ptlrpc_bulk_get failed: rc %d", rc);
1367 GOTO(cleanup_lwi, rc);
1368 rc = mdt_write_dir_page(info, page, reqbody->nlink);
1373 cfs_free_page(page);
1375 ptlrpc_free_bulk(desc);
1380 static int mdt_readpage(struct mdt_thread_info *info)
1382 struct mdt_object *object = info->mti_object;
1383 struct lu_rdpg *rdpg = &info->mti_u.rdpg.mti_rdpg;
1384 struct mdt_body *reqbody;
1385 struct mdt_body *repbody;
1390 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_READPAGE_PACK))
1391 RETURN(err_serious(-ENOMEM));
1393 reqbody = req_capsule_client_get(info->mti_pill, &RMF_MDT_BODY);
1394 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
1395 if (reqbody == NULL || repbody == NULL)
1396 RETURN(err_serious(-EFAULT));
1399 * prepare @rdpg before calling lower layers and transfer itself. Here
1400 * reqbody->size contains offset of where to start to read and
1401 * reqbody->nlink contains number bytes to read.
1403 rdpg->rp_hash = reqbody->size;
1404 if (rdpg->rp_hash != reqbody->size) {
1405 CERROR("Invalid hash: "LPX64" != "LPX64"\n",
1406 rdpg->rp_hash, reqbody->size);
1409 rdpg->rp_count = reqbody->nlink;
1410 rdpg->rp_npages = (rdpg->rp_count + CFS_PAGE_SIZE - 1)>>CFS_PAGE_SHIFT;
1411 OBD_ALLOC(rdpg->rp_pages, rdpg->rp_npages * sizeof rdpg->rp_pages[0]);
1412 if (rdpg->rp_pages == NULL)
1415 for (i = 0; i < rdpg->rp_npages; ++i) {
1416 rdpg->rp_pages[i] = cfs_alloc_page(CFS_ALLOC_STD);
1417 if (rdpg->rp_pages[i] == NULL)
1418 GOTO(free_rdpg, rc = -ENOMEM);
1421 /* call lower layers to fill allocated pages with directory data */
1422 rc = mo_readpage(info->mti_env, mdt_object_child(object), rdpg);
1424 GOTO(free_rdpg, rc);
1426 /* send pages to client */
1427 rc = mdt_sendpage(info, rdpg);
1432 for (i = 0; i < rdpg->rp_npages; i++)
1433 if (rdpg->rp_pages[i] != NULL)
1434 cfs_free_page(rdpg->rp_pages[i]);
1435 OBD_FREE(rdpg->rp_pages, rdpg->rp_npages * sizeof rdpg->rp_pages[0]);
1437 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_SENDPAGE))
1443 static int mdt_reint_internal(struct mdt_thread_info *info,
1444 struct mdt_lock_handle *lhc,
1447 struct req_capsule *pill = info->mti_pill;
1448 struct mdt_device *mdt = info->mti_mdt;
1449 struct mdt_body *repbody;
1454 if (req_capsule_has_field(pill, &RMF_MDT_MD, RCL_SERVER))
1455 req_capsule_set_size(pill, &RMF_MDT_MD, RCL_SERVER,
1456 mdt->mdt_max_mdsize);
1457 if (req_capsule_has_field(pill, &RMF_LOGCOOKIES, RCL_SERVER))
1458 req_capsule_set_size(pill, &RMF_LOGCOOKIES, RCL_SERVER,
1459 mdt->mdt_max_cookiesize);
1461 rc = req_capsule_server_pack(pill);
1463 CERROR("Can't pack response, rc %d\n", rc);
1464 RETURN(err_serious(rc));
1467 if (req_capsule_has_field(pill, &RMF_MDT_BODY, RCL_SERVER)) {
1468 repbody = req_capsule_server_get(pill, &RMF_MDT_BODY);
1470 repbody->eadatasize = 0;
1471 repbody->aclsize = 0;
1474 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_REINT_UNPACK))
1475 GOTO(out_shrink, rc = err_serious(-EFAULT));
1477 rc = mdt_reint_unpack(info, op);
1479 CERROR("Can't unpack reint, rc %d\n", rc);
1480 GOTO(out_shrink, rc = err_serious(rc));
1483 rc = mdt_init_ucred_reint(info);
1485 GOTO(out_shrink, rc);
1487 rc = mdt_fix_attr_ucred(info, op);
1489 GOTO(out_ucred, rc = err_serious(rc));
1491 if (mdt_check_resent(info, mdt_reconstruct, lhc)) {
1492 rc = lustre_msg_get_status(mdt_info_req(info)->rq_repmsg);
1493 GOTO(out_ucred, rc);
1495 rc = mdt_reint_rec(info, lhc);
1498 mdt_exit_ucred(info);
1500 mdt_shrink_reply(info);
1504 static long mdt_reint_opcode(struct mdt_thread_info *info,
1505 const struct req_format **fmt)
1507 struct mdt_rec_reint *rec;
1510 opc = err_serious(-EFAULT);
1511 rec = req_capsule_client_get(info->mti_pill, &RMF_REC_REINT);
1513 opc = rec->rr_opcode;
1514 DEBUG_REQ(D_INODE, mdt_info_req(info), "reint opt = %ld", opc);
1515 if (opc < REINT_MAX && fmt[opc] != NULL)
1516 req_capsule_extend(info->mti_pill, fmt[opc]);
1518 CERROR("Unsupported opc: %ld\n", opc);
1519 opc = err_serious(opc);
1525 static int mdt_reint(struct mdt_thread_info *info)
1530 static const struct req_format *reint_fmts[REINT_MAX] = {
1531 [REINT_SETATTR] = &RQF_MDS_REINT_SETATTR,
1532 [REINT_CREATE] = &RQF_MDS_REINT_CREATE,
1533 [REINT_LINK] = &RQF_MDS_REINT_LINK,
1534 [REINT_UNLINK] = &RQF_MDS_REINT_UNLINK,
1535 [REINT_RENAME] = &RQF_MDS_REINT_RENAME,
1536 [REINT_OPEN] = &RQF_MDS_REINT_OPEN,
1537 [REINT_SETXATTR] = &RQF_MDS_REINT_SETXATTR
1542 opc = mdt_reint_opcode(info, reint_fmts);
1545 * No lock possible here from client to pass it to reint code
1548 rc = mdt_reint_internal(info, NULL, opc);
1553 info->mti_fail_id = OBD_FAIL_MDS_REINT_NET_REP;
1557 /* this should sync the whole device */
1558 static int mdt_device_sync(const struct lu_env *env, struct mdt_device *mdt)
1560 struct dt_device *dt = mdt->mdt_bottom;
1564 rc = dt->dd_ops->dt_sync(env, dt);
1568 /* this should sync this object */
1569 static int mdt_object_sync(struct mdt_thread_info *info)
1571 struct md_object *next;
1575 if (!mdt_object_exists(info->mti_object)) {
1576 CWARN("Non existing object "DFID"!\n",
1577 PFID(mdt_object_fid(info->mti_object)));
1580 next = mdt_object_child(info->mti_object);
1581 rc = mo_object_sync(info->mti_env, next);
1586 static int mdt_sync(struct mdt_thread_info *info)
1588 struct req_capsule *pill = info->mti_pill;
1589 struct mdt_body *body;
1593 /* The fid may be zero, so we req_capsule_set manually */
1594 req_capsule_set(pill, &RQF_MDS_SYNC);
1596 body = req_capsule_client_get(pill, &RMF_MDT_BODY);
1598 RETURN(err_serious(-EINVAL));
1600 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_SYNC_PACK))
1601 RETURN(err_serious(-ENOMEM));
1603 if (fid_seq(&body->fid1) == 0) {
1604 /* sync the whole device */
1605 rc = req_capsule_server_pack(pill);
1607 rc = mdt_device_sync(info->mti_env, info->mti_mdt);
1609 rc = err_serious(rc);
1611 /* sync an object */
1612 rc = mdt_unpack_req_pack_rep(info, HABEO_CORPUS|HABEO_REFERO);
1614 rc = mdt_object_sync(info);
1616 struct md_object *next;
1617 const struct lu_fid *fid;
1618 struct lu_attr *la = &info->mti_attr.ma_attr;
1620 next = mdt_object_child(info->mti_object);
1621 info->mti_attr.ma_need = MA_INODE;
1622 info->mti_attr.ma_valid = 0;
1623 rc = mo_attr_get(info->mti_env, next,
1626 body = req_capsule_server_get(pill,
1628 fid = mdt_object_fid(info->mti_object);
1629 mdt_pack_attr2body(info, body, la, fid);
1633 rc = err_serious(rc);
1638 #ifdef HAVE_QUOTA_SUPPORT
1639 static int mdt_quotacheck_handle(struct mdt_thread_info *info)
1641 struct obd_quotactl *oqctl;
1642 struct req_capsule *pill = info->mti_pill;
1643 struct obd_export *exp = info->mti_exp;
1644 struct md_device *next = info->mti_mdt->mdt_child;
1648 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_QUOTACHECK_NET))
1651 oqctl = req_capsule_client_get(pill, &RMF_OBD_QUOTACTL);
1655 /* remote client has no permission for quotacheck */
1656 if (unlikely(exp_connect_rmtclient(exp)))
1659 rc = req_capsule_server_pack(pill);
1663 rc = next->md_ops->mdo_quota.mqo_check(info->mti_env, next, exp,
1668 static int mdt_quotactl_handle(struct mdt_thread_info *info)
1670 struct obd_quotactl *oqctl, *repoqc;
1671 struct req_capsule *pill = info->mti_pill;
1672 struct obd_export *exp = info->mti_exp;
1673 struct md_device *next = info->mti_mdt->mdt_child;
1674 const struct md_quota_operations *mqo = &next->md_ops->mdo_quota;
1678 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_QUOTACTL_NET))
1681 oqctl = req_capsule_client_get(pill, &RMF_OBD_QUOTACTL);
1686 if (exp_connect_rmtclient(exp)) {
1687 struct ptlrpc_request *req = mdt_info_req(info);
1688 struct mdt_export_data *med = mdt_req2med(req);
1689 struct lustre_idmap_table *idmap = med->med_idmap;
1691 if (unlikely(oqctl->qc_cmd != Q_GETQUOTA &&
1692 oqctl->qc_cmd != Q_GETINFO))
1696 if (oqctl->qc_type == USRQUOTA)
1697 id = lustre_idmap_lookup_uid(NULL, idmap, 0,
1699 else if (oqctl->qc_type == GRPQUOTA)
1700 id = lustre_idmap_lookup_gid(NULL, idmap, 0,
1705 if (id == CFS_IDMAP_NOTFOUND) {
1706 CDEBUG(D_QUOTA, "no mapping for id %u\n",
1712 rc = req_capsule_server_pack(pill);
1716 repoqc = req_capsule_server_get(pill, &RMF_OBD_QUOTACTL);
1717 LASSERT(repoqc != NULL);
1719 switch (oqctl->qc_cmd) {
1721 rc = mqo->mqo_on(info->mti_env, next, oqctl->qc_type, id);
1724 rc = mqo->mqo_off(info->mti_env, next, oqctl->qc_type, id);
1727 rc = mqo->mqo_setinfo(info->mti_env, next, oqctl->qc_type, id,
1731 rc = mqo->mqo_getinfo(info->mti_env, next, oqctl->qc_type, id,
1735 rc = mqo->mqo_setquota(info->mti_env, next, oqctl->qc_type, id,
1739 rc = mqo->mqo_getquota(info->mti_env, next, oqctl->qc_type, id,
1743 rc = mqo->mqo_getoinfo(info->mti_env, next, oqctl->qc_type, id,
1747 rc = mqo->mqo_getoquota(info->mti_env, next, oqctl->qc_type, id,
1750 case LUSTRE_Q_INVALIDATE:
1751 rc = mqo->mqo_invalidate(info->mti_env, next, oqctl->qc_type);
1753 case LUSTRE_Q_FINVALIDATE:
1754 rc = mqo->mqo_finvalidate(info->mti_env, next, oqctl->qc_type);
1757 CERROR("unsupported mdt_quotactl command: %d\n",
1768 * OBD PING and other handlers.
1770 static int mdt_obd_ping(struct mdt_thread_info *info)
1775 req_capsule_set(info->mti_pill, &RQF_OBD_PING);
1777 rc = target_handle_ping(mdt_info_req(info));
1779 rc = err_serious(rc);
1783 static int mdt_obd_log_cancel(struct mdt_thread_info *info)
1785 return err_serious(-EOPNOTSUPP);
1788 static int mdt_obd_qc_callback(struct mdt_thread_info *info)
1790 return err_serious(-EOPNOTSUPP);
1797 static struct ldlm_callback_suite cbs = {
1798 .lcs_completion = ldlm_server_completion_ast,
1799 .lcs_blocking = ldlm_server_blocking_ast,
1803 static int mdt_enqueue(struct mdt_thread_info *info)
1805 struct ptlrpc_request *req;
1810 * info->mti_dlm_req already contains swapped and (if necessary)
1811 * converted dlm request.
1813 LASSERT(info->mti_dlm_req != NULL);
1815 req = mdt_info_req(info);
1818 * Lock without inodebits makes no sense and will oops later in
1819 * ldlm. Let's check it now to see if we have wrong lock from client or
1820 * bits get corrupted somewhere in mdt_intent_policy().
1822 req_bits = info->mti_dlm_req->lock_desc.l_policy_data.l_inodebits.bits;
1823 /* This is disabled because we need to support liblustre flock.
1824 * LASSERT(req_bits != 0);
1827 rc = ldlm_handle_enqueue0(info->mti_mdt->mdt_namespace,
1828 req, info->mti_dlm_req, &cbs);
1829 info->mti_fail_id = OBD_FAIL_LDLM_REPLY;
1830 return rc ? err_serious(rc) : req->rq_status;
1833 static int mdt_convert(struct mdt_thread_info *info)
1836 struct ptlrpc_request *req;
1838 LASSERT(info->mti_dlm_req);
1839 req = mdt_info_req(info);
1840 rc = ldlm_handle_convert0(req, info->mti_dlm_req);
1841 return rc ? err_serious(rc) : req->rq_status;
1844 static int mdt_bl_callback(struct mdt_thread_info *info)
1846 CERROR("bl callbacks should not happen on MDS\n");
1848 return err_serious(-EOPNOTSUPP);
1851 static int mdt_cp_callback(struct mdt_thread_info *info)
1853 CERROR("cp callbacks should not happen on MDS\n");
1855 return err_serious(-EOPNOTSUPP);
1859 * sec context handlers
1861 static int mdt_sec_ctx_handle(struct mdt_thread_info *info)
1865 rc = mdt_handle_idmap(info);
1868 struct ptlrpc_request *req = mdt_info_req(info);
1871 opc = lustre_msg_get_opc(req->rq_reqmsg);
1872 if (opc == SEC_CTX_INIT || opc == SEC_CTX_INIT_CONT)
1873 sptlrpc_svc_ctx_invalidate(req);
1876 OBD_FAIL_TIMEOUT(OBD_FAIL_SEC_CTX_HDL_PAUSE, obd_fail_val);
1881 static struct mdt_object *mdt_obj(struct lu_object *o)
1883 LASSERT(lu_device_is_mdt(o->lo_dev));
1884 return container_of0(o, struct mdt_object, mot_obj.mo_lu);
1887 struct mdt_object *mdt_object_find(const struct lu_env *env,
1888 struct mdt_device *d,
1889 const struct lu_fid *f)
1891 struct lu_object *o;
1892 struct mdt_object *m;
1895 CDEBUG(D_INFO, "Find object for "DFID"\n", PFID(f));
1896 o = lu_object_find(env, &d->mdt_md_dev.md_lu_dev, f, NULL);
1897 if (unlikely(IS_ERR(o)))
1898 m = (struct mdt_object *)o;
1905 * Asyncronous commit for mdt device.
1907 * Pass asynchonous commit call down the MDS stack.
1909 * \param env environment
1910 * \param mdt the mdt device
1912 static void mdt_device_commit_async(const struct lu_env *env,
1913 struct mdt_device *mdt)
1915 struct dt_device *dt = mdt->mdt_bottom;
1918 rc = dt->dd_ops->dt_commit_async(env, dt);
1919 if (unlikely(rc != 0))
1920 CWARN("async commit start failed with rc = %d", rc);
1924 * Mark the lock as "synchonous".
1926 * Mark the lock to deffer transaction commit to the unlock time.
1928 * \param lock the lock to mark as "synchonous"
1930 * \see mdt_is_lock_sync
1931 * \see mdt_save_lock
1933 static inline void mdt_set_lock_sync(struct ldlm_lock *lock)
1935 lock->l_ast_data = (void*)1;
1939 * Check whehter the lock "synchonous" or not.
1941 * \param lock the lock to check
1942 * \retval 1 the lock is "synchonous"
1943 * \retval 0 the lock isn't "synchronous"
1945 * \see mdt_set_lock_sync
1946 * \see mdt_save_lock
1948 static inline int mdt_is_lock_sync(struct ldlm_lock *lock)
1950 return lock->l_ast_data != NULL;
1954 * Blocking AST for mdt locks.
1956 * Starts transaction commit if in case of COS lock conflict or
1957 * deffers such a commit to the mdt_save_lock.
1959 * \param lock the lock which blocks a request or cancelling lock
1960 * \param desc unused
1961 * \param data unused
1962 * \param flag indicates whether this cancelling or blocking callback
1964 * \see ldlm_blocking_ast_nocheck
1966 int mdt_blocking_ast(struct ldlm_lock *lock, struct ldlm_lock_desc *desc,
1967 void *data, int flag)
1969 struct obd_device *obd = lock->l_resource->lr_namespace->ns_obd;
1970 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
1974 if (flag == LDLM_CB_CANCELING)
1976 lock_res_and_lock(lock);
1977 if (lock->l_blocking_ast != mdt_blocking_ast) {
1978 unlock_res_and_lock(lock);
1981 if (mdt_cos_is_enabled(mdt) &&
1982 lock->l_req_mode & (LCK_PW | LCK_EX) &&
1983 lock->l_blocking_lock != NULL &&
1984 lock->l_client_cookie != lock->l_blocking_lock->l_client_cookie) {
1985 mdt_set_lock_sync(lock);
1987 rc = ldlm_blocking_ast_nocheck(lock);
1989 /* There is no lock conflict if l_blocking_lock == NULL,
1990 * it indicates a blocking ast sent from ldlm_lock_decref_internal
1991 * when the last reference to a local lock was released */
1992 if (lock->l_req_mode == LCK_COS && lock->l_blocking_lock != NULL) {
1995 rc = lu_env_init(&env, LCT_MD_THREAD);
1996 if (unlikely(rc != 0))
1997 CWARN("lu_env initialization failed with rc = %d,"
1998 "cannot start asynchronous commit\n", rc);
2000 mdt_device_commit_async(&env, mdt);
2006 int mdt_object_lock(struct mdt_thread_info *info, struct mdt_object *o,
2007 struct mdt_lock_handle *lh, __u64 ibits, int locality)
2009 struct ldlm_namespace *ns = info->mti_mdt->mdt_namespace;
2010 ldlm_policy_data_t *policy = &info->mti_policy;
2011 struct ldlm_res_id *res_id = &info->mti_res_id;
2015 LASSERT(!lustre_handle_is_used(&lh->mlh_reg_lh));
2016 LASSERT(!lustre_handle_is_used(&lh->mlh_pdo_lh));
2017 LASSERT(lh->mlh_reg_mode != LCK_MINMODE);
2018 LASSERT(lh->mlh_type != MDT_NUL_LOCK);
2020 if (mdt_object_exists(o) < 0) {
2021 if (locality == MDT_CROSS_LOCK) {
2022 /* cross-ref object fix */
2023 ibits &= ~MDS_INODELOCK_UPDATE;
2024 ibits |= MDS_INODELOCK_LOOKUP;
2026 LASSERT(!(ibits & MDS_INODELOCK_UPDATE));
2027 LASSERT(ibits & MDS_INODELOCK_LOOKUP);
2029 /* No PDO lock on remote object */
2030 LASSERT(lh->mlh_type != MDT_PDO_LOCK);
2033 if (lh->mlh_type == MDT_PDO_LOCK) {
2034 /* check for exists after object is locked */
2035 if (mdt_object_exists(o) == 0) {
2036 /* Non-existent object shouldn't have PDO lock */
2039 /* Non-dir object shouldn't have PDO lock */
2040 LASSERT(S_ISDIR(lu_object_attr(&o->mot_obj.mo_lu)));
2044 memset(policy, 0, sizeof(*policy));
2045 fid_build_reg_res_name(mdt_object_fid(o), res_id);
2048 * Take PDO lock on whole directory and build correct @res_id for lock
2049 * on part of directory.
2051 if (lh->mlh_pdo_hash != 0) {
2052 LASSERT(lh->mlh_type == MDT_PDO_LOCK);
2053 mdt_lock_pdo_mode(info, o, lh);
2054 if (lh->mlh_pdo_mode != LCK_NL) {
2056 * Do not use LDLM_FL_LOCAL_ONLY for parallel lock, it
2057 * is never going to be sent to client and we do not
2058 * want it slowed down due to possible cancels.
2060 policy->l_inodebits.bits = MDS_INODELOCK_UPDATE;
2061 rc = mdt_fid_lock(ns, &lh->mlh_pdo_lh, lh->mlh_pdo_mode,
2062 policy, res_id, LDLM_FL_ATOMIC_CB,
2063 &info->mti_exp->exp_handle.h_cookie);
2069 * Finish res_id initializing by name hash marking part of
2070 * directory which is taking modification.
2072 res_id->name[LUSTRE_RES_ID_HSH_OFF] = lh->mlh_pdo_hash;
2075 policy->l_inodebits.bits = ibits;
2078 * Use LDLM_FL_LOCAL_ONLY for this lock. We do not know yet if it is
2079 * going to be sent to client. If it is - mdt_intent_policy() path will
2080 * fix it up and turn FL_LOCAL flag off.
2082 rc = mdt_fid_lock(ns, &lh->mlh_reg_lh, lh->mlh_reg_mode, policy,
2083 res_id, LDLM_FL_LOCAL_ONLY | LDLM_FL_ATOMIC_CB,
2084 &info->mti_exp->exp_handle.h_cookie);
2090 mdt_object_unlock(info, o, lh, 1);
2097 * Save a lock within request object.
2099 * Keep the lock referenced until whether client ACK or transaction
2100 * commit happens or release the lock immediately depending on input
2101 * parameters. If COS is ON, a write lock is converted to COS lock
2104 * \param info thead info object
2105 * \param h lock handle
2106 * \param mode lock mode
2107 * \param decref force immediate lock releasing
2110 void mdt_save_lock(struct mdt_thread_info *info, struct lustre_handle *h,
2111 ldlm_mode_t mode, int decref)
2115 if (lustre_handle_is_used(h)) {
2116 if (decref || !info->mti_has_trans ||
2117 !(mode & (LCK_PW | LCK_EX))){
2118 mdt_fid_unlock(h, mode);
2120 struct mdt_device *mdt = info->mti_mdt;
2121 struct ldlm_lock *lock = ldlm_handle2lock(h);
2122 struct ptlrpc_request *req = mdt_info_req(info);
2125 LASSERTF(lock != NULL, "no lock for cookie "LPX64"\n",
2127 CDEBUG(D_HA, "request = %p reply state = %p"
2128 " transno = "LPD64"\n",
2129 req, req->rq_reply_state, req->rq_transno);
2130 if (mdt_cos_is_enabled(mdt)) {
2132 ldlm_lock_downgrade(lock, LCK_COS);
2135 ptlrpc_save_lock(req, h, mode, no_ack);
2136 if (mdt_is_lock_sync(lock)) {
2137 CDEBUG(D_HA, "found sync-lock,"
2138 " async commit started\n");
2139 mdt_device_commit_async(info->mti_env,
2142 LDLM_LOCK_PUT(lock);
2151 * Unlock mdt object.
2153 * Immeditely release the regular lock and the PDO lock or save the
2154 * lock in reqeuest and keep them referenced until client ACK or
2155 * transaction commit.
2157 * \param info thread info object
2158 * \param o mdt object
2159 * \param h mdt lock handle referencing regular and PDO locks
2160 * \param decref force immediate lock releasing
2162 void mdt_object_unlock(struct mdt_thread_info *info, struct mdt_object *o,
2163 struct mdt_lock_handle *lh, int decref)
2167 mdt_save_lock(info, &lh->mlh_pdo_lh, lh->mlh_pdo_mode, decref);
2168 mdt_save_lock(info, &lh->mlh_reg_lh, lh->mlh_reg_mode, decref);
2173 struct mdt_object *mdt_object_find_lock(struct mdt_thread_info *info,
2174 const struct lu_fid *f,
2175 struct mdt_lock_handle *lh,
2178 struct mdt_object *o;
2180 o = mdt_object_find(info->mti_env, info->mti_mdt, f);
2184 rc = mdt_object_lock(info, o, lh, ibits,
2187 mdt_object_put(info->mti_env, o);
2194 void mdt_object_unlock_put(struct mdt_thread_info * info,
2195 struct mdt_object * o,
2196 struct mdt_lock_handle *lh,
2199 mdt_object_unlock(info, o, lh, decref);
2200 mdt_object_put(info->mti_env, o);
2203 static struct mdt_handler *mdt_handler_find(__u32 opc,
2204 struct mdt_opc_slice *supported)
2206 struct mdt_opc_slice *s;
2207 struct mdt_handler *h;
2210 for (s = supported; s->mos_hs != NULL; s++) {
2211 if (s->mos_opc_start <= opc && opc < s->mos_opc_end) {
2212 h = s->mos_hs + (opc - s->mos_opc_start);
2213 if (likely(h->mh_opc != 0))
2214 LASSERT(h->mh_opc == opc);
2216 h = NULL; /* unsupported opc */
2223 static int mdt_lock_resname_compat(struct mdt_device *m,
2224 struct ldlm_request *req)
2226 /* XXX something... later. */
2230 static int mdt_lock_reply_compat(struct mdt_device *m, struct ldlm_reply *rep)
2232 /* XXX something... later. */
2237 * Generic code handling requests that have struct mdt_body passed in:
2239 * - extract mdt_body from request and save it in @info, if present;
2241 * - create lu_object, corresponding to the fid in mdt_body, and save it in
2244 * - if HABEO_CORPUS flag is set for this request type check whether object
2245 * actually exists on storage (lu_object_exists()).
2248 static int mdt_body_unpack(struct mdt_thread_info *info, __u32 flags)
2250 const struct mdt_body *body;
2251 struct mdt_object *obj;
2252 const struct lu_env *env;
2253 struct req_capsule *pill;
2257 env = info->mti_env;
2258 pill = info->mti_pill;
2260 body = info->mti_body = req_capsule_client_get(pill, &RMF_MDT_BODY);
2264 if (!(body->valid & OBD_MD_FLID))
2267 if (!fid_is_sane(&body->fid1)) {
2268 CERROR("Invalid fid: "DFID"\n", PFID(&body->fid1));
2273 * Do not get size or any capa fields before we check that request
2274 * contains capa actually. There are some requests which do not, for
2275 * instance MDS_IS_SUBDIR.
2277 if (req_capsule_has_field(pill, &RMF_CAPA1, RCL_CLIENT) &&
2278 req_capsule_get_size(pill, &RMF_CAPA1, RCL_CLIENT))
2279 mdt_set_capainfo(info, 0, &body->fid1,
2280 req_capsule_client_get(pill, &RMF_CAPA1));
2282 obj = mdt_object_find(env, info->mti_mdt, &body->fid1);
2284 if ((flags & HABEO_CORPUS) &&
2285 !mdt_object_exists(obj)) {
2286 mdt_object_put(env, obj);
2287 /* for capability renew ENOENT will be handled in
2289 if (body->valid & OBD_MD_FLOSSCAPA)
2294 info->mti_object = obj;
2303 static int mdt_unpack_req_pack_rep(struct mdt_thread_info *info, __u32 flags)
2305 struct req_capsule *pill = info->mti_pill;
2309 if (req_capsule_has_field(pill, &RMF_MDT_BODY, RCL_CLIENT))
2310 rc = mdt_body_unpack(info, flags);
2314 if (rc == 0 && (flags & HABEO_REFERO)) {
2315 struct mdt_device *mdt = info->mti_mdt;
2318 if (req_capsule_has_field(pill, &RMF_MDT_MD, RCL_SERVER))
2319 req_capsule_set_size(pill, &RMF_MDT_MD, RCL_SERVER,
2320 mdt->mdt_max_mdsize);
2321 if (req_capsule_has_field(pill, &RMF_LOGCOOKIES, RCL_SERVER))
2322 req_capsule_set_size(pill, &RMF_LOGCOOKIES, RCL_SERVER,
2323 mdt->mdt_max_cookiesize);
2325 rc = req_capsule_server_pack(pill);
2330 static int mdt_init_capa_ctxt(const struct lu_env *env, struct mdt_device *m)
2332 struct md_device *next = m->mdt_child;
2334 return next->md_ops->mdo_init_capa_ctxt(env, next,
2335 m->mdt_opts.mo_mds_capa,
2336 m->mdt_capa_timeout,
2342 * Invoke handler for this request opc. Also do necessary preprocessing
2343 * (according to handler ->mh_flags), and post-processing (setting of
2344 * ->last_{xid,committed}).
2346 static int mdt_req_handle(struct mdt_thread_info *info,
2347 struct mdt_handler *h, struct ptlrpc_request *req)
2349 int rc, serious = 0;
2354 LASSERT(h->mh_act != NULL);
2355 LASSERT(h->mh_opc == lustre_msg_get_opc(req->rq_reqmsg));
2356 LASSERT(current->journal_info == NULL);
2359 * Checking for various OBD_FAIL_$PREF_$OPC_NET codes. _Do_ not try
2360 * to put same checks into handlers like mdt_close(), mdt_reint(),
2361 * etc., without talking to mdt authors first. Checking same thing
2362 * there again is useless and returning 0 error wihtout packing reply
2363 * is buggy! Handlers either pack reply or return error.
2365 * We return 0 here and do not send any reply in order to emulate
2366 * network failure. Do not send any reply in case any of NET related
2367 * fail_id has occured.
2369 if (OBD_FAIL_CHECK_ORSET(h->mh_fail_id, OBD_FAIL_ONCE))
2373 flags = h->mh_flags;
2374 LASSERT(ergo(flags & (HABEO_CORPUS|HABEO_REFERO), h->mh_fmt != NULL));
2376 if (h->mh_fmt != NULL) {
2377 req_capsule_set(info->mti_pill, h->mh_fmt);
2378 rc = mdt_unpack_req_pack_rep(info, flags);
2381 if (rc == 0 && flags & MUTABOR &&
2382 req->rq_export->exp_connect_flags & OBD_CONNECT_RDONLY)
2383 /* should it be rq_status? */
2386 if (rc == 0 && flags & HABEO_CLAVIS) {
2387 struct ldlm_request *dlm_req;
2389 LASSERT(h->mh_fmt != NULL);
2391 dlm_req = req_capsule_client_get(info->mti_pill, &RMF_DLM_REQ);
2392 if (dlm_req != NULL) {
2393 if (info->mti_mdt->mdt_opts.mo_compat_resname)
2394 rc = mdt_lock_resname_compat(info->mti_mdt,
2396 info->mti_dlm_req = dlm_req;
2402 /* capability setting changed via /proc, needs reinitialize ctxt */
2403 if (info->mti_mdt && info->mti_mdt->mdt_capa_conf) {
2404 mdt_init_capa_ctxt(info->mti_env, info->mti_mdt);
2405 info->mti_mdt->mdt_capa_conf = 0;
2408 if (likely(rc == 0)) {
2410 * Process request, there can be two types of rc:
2411 * 1) errors with msg unpack/pack, other failures outside the
2412 * operation itself. This is counted as serious errors;
2413 * 2) errors during fs operation, should be placed in rq_status
2416 rc = h->mh_act(info);
2418 !req->rq_no_reply && req->rq_reply_state == NULL) {
2419 DEBUG_REQ(D_ERROR, req, "MDT \"handler\" %s did not "
2420 "pack reply and returned 0 error\n",
2424 serious = is_serious(rc);
2425 rc = clear_serious(rc);
2429 req->rq_status = rc;
2432 * ELDLM_* codes which > 0 should be in rq_status only as well as
2433 * all non-serious errors.
2435 if (rc > 0 || !serious)
2438 LASSERT(current->journal_info == NULL);
2440 if (rc == 0 && (flags & HABEO_CLAVIS) &&
2441 info->mti_mdt->mdt_opts.mo_compat_resname) {
2442 struct ldlm_reply *dlmrep;
2444 dlmrep = req_capsule_server_get(info->mti_pill, &RMF_DLM_REP);
2446 rc = mdt_lock_reply_compat(info->mti_mdt, dlmrep);
2449 /* If we're DISCONNECTing, the mdt_export_data is already freed */
2450 if (likely(rc == 0 && h->mh_opc != MDS_DISCONNECT))
2451 target_committed_to_req(req);
2453 if (unlikely((lustre_msg_get_flags(req->rq_reqmsg) & MSG_REPLAY) &&
2454 lustre_msg_get_transno(req->rq_reqmsg) == 0)) {
2455 DEBUG_REQ(D_ERROR, req, "transno is 0 during REPLAY");
2459 target_send_reply(req, rc, info->mti_fail_id);
2463 void mdt_lock_handle_init(struct mdt_lock_handle *lh)
2465 lh->mlh_type = MDT_NUL_LOCK;
2466 lh->mlh_reg_lh.cookie = 0ull;
2467 lh->mlh_reg_mode = LCK_MINMODE;
2468 lh->mlh_pdo_lh.cookie = 0ull;
2469 lh->mlh_pdo_mode = LCK_MINMODE;
2472 void mdt_lock_handle_fini(struct mdt_lock_handle *lh)
2474 LASSERT(!lustre_handle_is_used(&lh->mlh_reg_lh));
2475 LASSERT(!lustre_handle_is_used(&lh->mlh_pdo_lh));
2479 * Initialize fields of struct mdt_thread_info. Other fields are left in
2480 * uninitialized state, because it's too expensive to zero out whole
2481 * mdt_thread_info (> 1K) on each request arrival.
2483 static void mdt_thread_info_init(struct ptlrpc_request *req,
2484 struct mdt_thread_info *info)
2487 struct md_capainfo *ci;
2489 req_capsule_init(&req->rq_pill, req, RCL_SERVER);
2490 info->mti_pill = &req->rq_pill;
2493 for (i = 0; i < ARRAY_SIZE(info->mti_lh); i++)
2494 mdt_lock_handle_init(&info->mti_lh[i]);
2496 /* mdt device: it can be NULL while CONNECT */
2497 if (req->rq_export) {
2498 info->mti_mdt = mdt_dev(req->rq_export->exp_obd->obd_lu_dev);
2499 info->mti_exp = req->rq_export;
2501 info->mti_mdt = NULL;
2502 info->mti_env = req->rq_svc_thread->t_env;
2503 ci = md_capainfo(info->mti_env);
2504 memset(ci, 0, sizeof *ci);
2505 if (req->rq_export) {
2506 if (exp_connect_rmtclient(req->rq_export))
2507 ci->mc_auth = LC_ID_CONVERT;
2508 else if (req->rq_export->exp_connect_flags &
2509 OBD_CONNECT_MDS_CAPA)
2510 ci->mc_auth = LC_ID_PLAIN;
2512 ci->mc_auth = LC_ID_NONE;
2515 info->mti_fail_id = OBD_FAIL_MDS_ALL_REPLY_NET;
2516 info->mti_transno = lustre_msg_get_transno(req->rq_reqmsg);
2518 memset(&info->mti_attr, 0, sizeof(info->mti_attr));
2519 info->mti_body = NULL;
2520 info->mti_object = NULL;
2521 info->mti_dlm_req = NULL;
2522 info->mti_has_trans = 0;
2523 info->mti_no_need_trans = 0;
2524 info->mti_cross_ref = 0;
2525 info->mti_opdata = 0;
2527 /* To not check for split by default. */
2528 info->mti_spec.sp_ck_split = 0;
2531 static void mdt_thread_info_fini(struct mdt_thread_info *info)
2535 req_capsule_fini(info->mti_pill);
2536 if (info->mti_object != NULL) {
2537 mdt_object_put(info->mti_env, info->mti_object);
2538 info->mti_object = NULL;
2540 for (i = 0; i < ARRAY_SIZE(info->mti_lh); i++)
2541 mdt_lock_handle_fini(&info->mti_lh[i]);
2542 info->mti_env = NULL;
2545 static int mdt_filter_recovery_request(struct ptlrpc_request *req,
2546 struct obd_device *obd, int *process)
2548 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
2549 case MDS_CONNECT: /* This will never get here, but for completeness. */
2550 case OST_CONNECT: /* This will never get here, but for completeness. */
2551 case MDS_DISCONNECT:
2552 case OST_DISCONNECT:
2557 case MDS_DONE_WRITING:
2558 case MDS_SYNC: /* used in unmounting */
2564 *process = target_queue_recovery_request(req, obd);
2568 DEBUG_REQ(D_ERROR, req, "not permitted during recovery");
2575 * Handle recovery. Return:
2576 * +1: continue request processing;
2577 * -ve: abort immediately with the given error code;
2578 * 0: send reply with error code in req->rq_status;
2580 static int mdt_recovery(struct mdt_thread_info *info)
2582 struct ptlrpc_request *req = mdt_info_req(info);
2584 struct obd_device *obd;
2588 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
2591 case SEC_CTX_INIT_CONT:
2597 rc = mdt_handle_idmap(info);
2606 if (unlikely(req->rq_export == NULL)) {
2607 CERROR("operation %d on unconnected MDS from %s\n",
2608 lustre_msg_get_opc(req->rq_reqmsg),
2609 libcfs_id2str(req->rq_peer));
2610 /* FIXME: For CMD cleanup, when mds_B stop, the req from
2611 * mds_A will get -ENOTCONN(especially for ping req),
2612 * which will cause that mds_A deactive timeout, then when
2613 * mds_A cleanup, the cleanup process will be suspended since
2614 * deactive timeout is not zero.
2616 req->rq_status = -ENOTCONN;
2617 target_send_reply(req, -ENOTCONN, info->mti_fail_id);
2621 /* sanity check: if the xid matches, the request must be marked as a
2622 * resent or replayed */
2623 if (req_xid_is_last(req)) {
2624 if (!(lustre_msg_get_flags(req->rq_reqmsg) &
2625 (MSG_RESENT | MSG_REPLAY))) {
2626 DEBUG_REQ(D_WARNING, req, "rq_xid "LPU64" matches last_xid, "
2627 "expected REPLAY or RESENT flag (%x)", req->rq_xid,
2628 lustre_msg_get_flags(req->rq_reqmsg));
2630 req->rq_status = -ENOTCONN;
2635 /* else: note the opposite is not always true; a RESENT req after a
2636 * failover will usually not match the last_xid, since it was likely
2637 * never committed. A REPLAYed request will almost never match the
2638 * last xid, however it could for a committed, but still retained,
2641 obd = req->rq_export->exp_obd;
2643 /* Check for aborted recovery... */
2644 spin_lock_bh(&obd->obd_processing_task_lock);
2645 recovering = obd->obd_recovering;
2646 spin_unlock_bh(&obd->obd_processing_task_lock);
2647 if (unlikely(recovering)) {
2650 DEBUG_REQ(D_INFO, req, "Got new replay");
2651 rc = mdt_filter_recovery_request(req, obd, &should_process);
2652 if (rc != 0 || !should_process)
2654 else if (should_process < 0) {
2655 req->rq_status = should_process;
2656 rc = ptlrpc_error(req);
2663 static int mdt_msg_check_version(struct lustre_msg *msg)
2667 switch (lustre_msg_get_opc(msg)) {
2669 case MDS_DISCONNECT:
2672 case SEC_CTX_INIT_CONT:
2674 rc = lustre_msg_check_version(msg, LUSTRE_OBD_VERSION);
2676 CERROR("bad opc %u version %08x, expecting %08x\n",
2677 lustre_msg_get_opc(msg),
2678 lustre_msg_get_version(msg),
2679 LUSTRE_OBD_VERSION);
2683 case MDS_GETATTR_NAME:
2690 case MDS_DONE_WRITING:
2696 case MDS_QUOTACHECK:
2702 rc = lustre_msg_check_version(msg, LUSTRE_MDS_VERSION);
2704 CERROR("bad opc %u version %08x, expecting %08x\n",
2705 lustre_msg_get_opc(msg),
2706 lustre_msg_get_version(msg),
2707 LUSTRE_MDS_VERSION);
2711 case LDLM_BL_CALLBACK:
2712 case LDLM_CP_CALLBACK:
2713 rc = lustre_msg_check_version(msg, LUSTRE_DLM_VERSION);
2715 CERROR("bad opc %u version %08x, expecting %08x\n",
2716 lustre_msg_get_opc(msg),
2717 lustre_msg_get_version(msg),
2718 LUSTRE_DLM_VERSION);
2720 case OBD_LOG_CANCEL:
2721 case LLOG_ORIGIN_HANDLE_CREATE:
2722 case LLOG_ORIGIN_HANDLE_NEXT_BLOCK:
2723 case LLOG_ORIGIN_HANDLE_READ_HEADER:
2724 case LLOG_ORIGIN_HANDLE_CLOSE:
2725 case LLOG_ORIGIN_HANDLE_DESTROY:
2726 case LLOG_ORIGIN_HANDLE_PREV_BLOCK:
2728 rc = lustre_msg_check_version(msg, LUSTRE_LOG_VERSION);
2730 CERROR("bad opc %u version %08x, expecting %08x\n",
2731 lustre_msg_get_opc(msg),
2732 lustre_msg_get_version(msg),
2733 LUSTRE_LOG_VERSION);
2736 CERROR("MDS unknown opcode %d\n", lustre_msg_get_opc(msg));
2742 static int mdt_handle0(struct ptlrpc_request *req,
2743 struct mdt_thread_info *info,
2744 struct mdt_opc_slice *supported)
2746 struct mdt_handler *h;
2747 struct lustre_msg *msg;
2752 if (OBD_FAIL_CHECK_ORSET(OBD_FAIL_MDS_ALL_REQUEST_NET, OBD_FAIL_ONCE))
2755 LASSERT(current->journal_info == NULL);
2757 msg = req->rq_reqmsg;
2758 rc = mdt_msg_check_version(msg);
2759 if (likely(rc == 0)) {
2760 rc = mdt_recovery(info);
2761 if (likely(rc == +1)) {
2762 h = mdt_handler_find(lustre_msg_get_opc(msg),
2764 if (likely(h != NULL)) {
2765 rc = mdt_req_handle(info, h, req);
2767 CERROR("The unsupported opc: 0x%x\n", lustre_msg_get_opc(msg) );
2768 req->rq_status = -ENOTSUPP;
2769 rc = ptlrpc_error(req);
2774 CERROR(LUSTRE_MDT_NAME" drops mal-formed request\n");
2779 * MDT handler function called by ptlrpc service thread when request comes.
2781 * XXX common "target" functionality should be factored into separate module
2782 * shared by mdt, ost and stand-alone services like fld.
2784 static int mdt_handle_common(struct ptlrpc_request *req,
2785 struct mdt_opc_slice *supported)
2788 struct mdt_thread_info *info;
2792 env = req->rq_svc_thread->t_env;
2793 LASSERT(env != NULL);
2794 LASSERT(env->le_ses != NULL);
2795 LASSERT(env->le_ctx.lc_thread == req->rq_svc_thread);
2796 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
2797 LASSERT(info != NULL);
2799 mdt_thread_info_init(req, info);
2801 rc = mdt_handle0(req, info, supported);
2803 mdt_thread_info_fini(info);
2808 * This is called from recovery code as handler of _all_ RPC types, FLD and SEQ
2811 int mdt_recovery_handle(struct ptlrpc_request *req)
2816 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
2818 rc = mdt_handle_common(req, mdt_fld_handlers);
2821 rc = mdt_handle_common(req, mdt_seq_handlers);
2824 rc = mdt_handle_common(req, mdt_regular_handlers);
2831 static int mdt_regular_handle(struct ptlrpc_request *req)
2833 return mdt_handle_common(req, mdt_regular_handlers);
2836 static int mdt_readpage_handle(struct ptlrpc_request *req)
2838 return mdt_handle_common(req, mdt_readpage_handlers);
2841 static int mdt_xmds_handle(struct ptlrpc_request *req)
2843 return mdt_handle_common(req, mdt_xmds_handlers);
2846 static int mdt_mdsc_handle(struct ptlrpc_request *req)
2848 return mdt_handle_common(req, mdt_seq_handlers);
2851 static int mdt_mdss_handle(struct ptlrpc_request *req)
2853 return mdt_handle_common(req, mdt_seq_handlers);
2856 static int mdt_dtss_handle(struct ptlrpc_request *req)
2858 return mdt_handle_common(req, mdt_seq_handlers);
2861 static int mdt_fld_handle(struct ptlrpc_request *req)
2863 return mdt_handle_common(req, mdt_fld_handlers);
2879 static int mdt_intent_getattr(enum mdt_it_code opcode,
2880 struct mdt_thread_info *info,
2881 struct ldlm_lock **,
2883 static int mdt_intent_reint(enum mdt_it_code opcode,
2884 struct mdt_thread_info *info,
2885 struct ldlm_lock **,
2888 static struct mdt_it_flavor {
2889 const struct req_format *it_fmt;
2891 int (*it_act)(enum mdt_it_code ,
2892 struct mdt_thread_info *,
2893 struct ldlm_lock **,
2896 } mdt_it_flavor[] = {
2898 .it_fmt = &RQF_LDLM_INTENT,
2899 /*.it_flags = HABEO_REFERO,*/
2901 .it_act = mdt_intent_reint,
2902 .it_reint = REINT_OPEN
2905 .it_fmt = &RQF_LDLM_INTENT,
2906 .it_flags = MUTABOR,
2907 .it_act = mdt_intent_reint,
2908 .it_reint = REINT_OPEN
2911 .it_fmt = &RQF_LDLM_INTENT,
2912 .it_flags = MUTABOR,
2913 .it_act = mdt_intent_reint,
2914 .it_reint = REINT_CREATE
2916 [MDT_IT_GETATTR] = {
2917 .it_fmt = &RQF_LDLM_INTENT_GETATTR,
2918 .it_flags = HABEO_REFERO,
2919 .it_act = mdt_intent_getattr
2921 [MDT_IT_READDIR] = {
2927 .it_fmt = &RQF_LDLM_INTENT_GETATTR,
2928 .it_flags = HABEO_REFERO,
2929 .it_act = mdt_intent_getattr
2932 .it_fmt = &RQF_LDLM_INTENT_UNLINK,
2933 .it_flags = MUTABOR,
2935 .it_reint = REINT_UNLINK
2939 .it_flags = MUTABOR,
2942 [MDT_IT_GETXATTR] = {
2949 int mdt_intent_lock_replace(struct mdt_thread_info *info,
2950 struct ldlm_lock **lockp,
2951 struct ldlm_lock *new_lock,
2952 struct mdt_lock_handle *lh,
2955 struct ptlrpc_request *req = mdt_info_req(info);
2956 struct ldlm_lock *lock = *lockp;
2959 * Get new lock only for cases when possible resent did not find any
2962 if (new_lock == NULL)
2963 new_lock = ldlm_handle2lock_long(&lh->mlh_reg_lh, 0);
2965 if (new_lock == NULL && (flags & LDLM_FL_INTENT_ONLY)) {
2966 lh->mlh_reg_lh.cookie = 0;
2970 LASSERTF(new_lock != NULL,
2971 "lockh "LPX64"\n", lh->mlh_reg_lh.cookie);
2974 * If we've already given this lock to a client once, then we should
2975 * have no readers or writers. Otherwise, we should have one reader
2976 * _or_ writer ref (which will be zeroed below) before returning the
2979 if (new_lock->l_export == req->rq_export) {
2980 LASSERT(new_lock->l_readers + new_lock->l_writers == 0);
2982 LASSERT(new_lock->l_export == NULL);
2983 LASSERT(new_lock->l_readers + new_lock->l_writers == 1);
2988 if (new_lock->l_export == req->rq_export) {
2990 * Already gave this to the client, which means that we
2991 * reconstructed a reply.
2993 LASSERT(lustre_msg_get_flags(req->rq_reqmsg) &
2995 lh->mlh_reg_lh.cookie = 0;
2996 RETURN(ELDLM_LOCK_REPLACED);
3000 * Fixup the lock to be given to the client.
3002 lock_res_and_lock(new_lock);
3003 /* Zero new_lock->l_readers and new_lock->l_writers without triggering
3004 * possible blocking AST. */
3005 while (new_lock->l_readers > 0) {
3006 lu_ref_del(&new_lock->l_reference, "reader", new_lock);
3007 lu_ref_del(&new_lock->l_reference, "user", new_lock);
3008 new_lock->l_readers--;
3010 while (new_lock->l_writers > 0) {
3011 lu_ref_del(&new_lock->l_reference, "writer", new_lock);
3012 lu_ref_del(&new_lock->l_reference, "user", new_lock);
3013 new_lock->l_writers--;
3016 new_lock->l_export = class_export_get(req->rq_export);
3017 new_lock->l_blocking_ast = lock->l_blocking_ast;
3018 new_lock->l_completion_ast = lock->l_completion_ast;
3019 new_lock->l_remote_handle = lock->l_remote_handle;
3020 new_lock->l_flags &= ~LDLM_FL_LOCAL;
3022 unlock_res_and_lock(new_lock);
3024 lustre_hash_add(new_lock->l_export->exp_lock_hash,
3025 &new_lock->l_remote_handle,
3026 &new_lock->l_exp_hash);
3028 LDLM_LOCK_RELEASE(new_lock);
3029 lh->mlh_reg_lh.cookie = 0;
3031 RETURN(ELDLM_LOCK_REPLACED);
3034 static void mdt_intent_fixup_resent(struct mdt_thread_info *info,
3035 struct ldlm_lock *new_lock,
3036 struct ldlm_lock **old_lock,
3037 struct mdt_lock_handle *lh)
3039 struct ptlrpc_request *req = mdt_info_req(info);
3040 struct obd_export *exp = req->rq_export;
3041 struct lustre_handle remote_hdl;
3042 struct ldlm_request *dlmreq;
3043 struct ldlm_lock *lock;
3045 if (!(lustre_msg_get_flags(req->rq_reqmsg) & MSG_RESENT))
3048 dlmreq = req_capsule_client_get(info->mti_pill, &RMF_DLM_REQ);
3049 remote_hdl = dlmreq->lock_handle[0];
3051 lock = lustre_hash_lookup(exp->exp_lock_hash, &remote_hdl);
3053 if (lock != new_lock) {
3054 lh->mlh_reg_lh.cookie = lock->l_handle.h_cookie;
3055 lh->mlh_reg_mode = lock->l_granted_mode;
3057 LDLM_DEBUG(lock, "Restoring lock cookie");
3058 DEBUG_REQ(D_DLMTRACE, req,
3059 "restoring lock cookie "LPX64,
3060 lh->mlh_reg_lh.cookie);
3062 *old_lock = LDLM_LOCK_GET(lock);
3063 lh_put(exp->exp_lock_hash, &lock->l_exp_hash);
3067 lh_put(exp->exp_lock_hash, &lock->l_exp_hash);
3071 * If the xid matches, then we know this is a resent request, and allow
3072 * it. (It's probably an OPEN, for which we don't send a lock.
3074 if (req_xid_is_last(req))
3078 * This remote handle isn't enqueued, so we never received or processed
3079 * this request. Clear MSG_RESENT, because it can be handled like any
3080 * normal request now.
3082 lustre_msg_clear_flags(req->rq_reqmsg, MSG_RESENT);
3084 DEBUG_REQ(D_DLMTRACE, req, "no existing lock with rhandle "LPX64,
3088 static int mdt_intent_getattr(enum mdt_it_code opcode,
3089 struct mdt_thread_info *info,
3090 struct ldlm_lock **lockp,
3093 struct mdt_lock_handle *lhc = &info->mti_lh[MDT_LH_RMT];
3094 struct ldlm_lock *new_lock = NULL;
3096 struct ldlm_reply *ldlm_rep;
3097 struct ptlrpc_request *req;
3098 struct mdt_body *reqbody;
3099 struct mdt_body *repbody;
3103 reqbody = req_capsule_client_get(info->mti_pill, &RMF_MDT_BODY);
3106 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
3109 info->mti_spec.sp_ck_split = !!(reqbody->valid & OBD_MD_FLCKSPLIT);
3110 info->mti_cross_ref = !!(reqbody->valid & OBD_MD_FLCROSSREF);
3111 repbody->eadatasize = 0;
3112 repbody->aclsize = 0;
3116 child_bits = MDS_INODELOCK_LOOKUP;
3118 case MDT_IT_GETATTR:
3119 child_bits = MDS_INODELOCK_LOOKUP | MDS_INODELOCK_UPDATE;
3122 CERROR("Unhandled till now");
3123 GOTO(out_shrink, rc = -EINVAL);
3126 rc = mdt_init_ucred(info, reqbody);
3128 GOTO(out_shrink, rc);
3130 req = info->mti_pill->rc_req;
3131 ldlm_rep = req_capsule_server_get(info->mti_pill, &RMF_DLM_REP);
3132 mdt_set_disposition(info, ldlm_rep, DISP_IT_EXECD);
3134 /* Get lock from request for possible resent case. */
3135 mdt_intent_fixup_resent(info, *lockp, &new_lock, lhc);
3137 ldlm_rep->lock_policy_res2 =
3138 mdt_getattr_name_lock(info, lhc, child_bits, ldlm_rep);
3140 if (mdt_get_disposition(ldlm_rep, DISP_LOOKUP_NEG))
3141 ldlm_rep->lock_policy_res2 = 0;
3142 if (!mdt_get_disposition(ldlm_rep, DISP_LOOKUP_POS) ||
3143 ldlm_rep->lock_policy_res2) {
3144 lhc->mlh_reg_lh.cookie = 0ull;
3145 GOTO(out_ucred, rc = ELDLM_LOCK_ABORTED);
3148 rc = mdt_intent_lock_replace(info, lockp, new_lock, lhc, flags);
3151 mdt_exit_ucred(info);
3153 mdt_shrink_reply(info);
3157 static int mdt_intent_reint(enum mdt_it_code opcode,
3158 struct mdt_thread_info *info,
3159 struct ldlm_lock **lockp,
3162 struct mdt_lock_handle *lhc = &info->mti_lh[MDT_LH_RMT];
3163 struct ldlm_reply *rep = NULL;
3167 static const struct req_format *intent_fmts[REINT_MAX] = {
3168 [REINT_CREATE] = &RQF_LDLM_INTENT_CREATE,
3169 [REINT_OPEN] = &RQF_LDLM_INTENT_OPEN
3174 opc = mdt_reint_opcode(info, intent_fmts);
3178 if (mdt_it_flavor[opcode].it_reint != opc) {
3179 CERROR("Reint code %ld doesn't match intent: %d\n",
3181 RETURN(err_serious(-EPROTO));
3184 /* Get lock from request for possible resent case. */
3185 mdt_intent_fixup_resent(info, *lockp, NULL, lhc);
3187 rc = mdt_reint_internal(info, lhc, opc);
3189 /* Check whether the reply has been packed successfully. */
3190 if (mdt_info_req(info)->rq_repmsg != NULL)
3191 rep = req_capsule_server_get(info->mti_pill, &RMF_DLM_REP);
3193 RETURN(err_serious(-EFAULT));
3195 /* MDC expects this in any case */
3197 mdt_set_disposition(info, rep, DISP_LOOKUP_EXECD);
3199 /* Cross-ref case, the lock should be returned to the client */
3200 if (rc == -EREMOTE) {
3201 LASSERT(lustre_handle_is_used(&lhc->mlh_reg_lh));
3202 rep->lock_policy_res2 = 0;
3203 rc = mdt_intent_lock_replace(info, lockp, NULL, lhc, flags);
3206 rep->lock_policy_res2 = clear_serious(rc);
3208 lhc->mlh_reg_lh.cookie = 0ull;
3209 if (rc == -ENOTCONN || rc == -ENODEV) {
3211 * If it is the disconnect error (ENODEV & ENOCONN), the error
3212 * will be returned by rq_status, and client at ptlrpc layer
3213 * will detect this, then disconnect, reconnect the import
3214 * immediately, instead of impacting the following the rpc.
3219 * For other cases, the error will be returned by intent.
3220 * and client will retrieve the result from intent.
3223 * FIXME: when open lock is finished, that should be
3226 RETURN(ELDLM_LOCK_ABORTED);
3230 static int mdt_intent_code(long itcode)
3238 case IT_OPEN|IT_CREAT:
3245 rc = MDT_IT_READDIR;
3248 rc = MDT_IT_GETATTR;
3260 rc = MDT_IT_GETXATTR;
3263 CERROR("Unknown intent opcode: %ld\n", itcode);
3270 static int mdt_intent_opc(long itopc, struct mdt_thread_info *info,
3271 struct ldlm_lock **lockp, int flags)
3273 struct req_capsule *pill;
3274 struct mdt_it_flavor *flv;
3279 opc = mdt_intent_code(itopc);
3283 pill = info->mti_pill;
3284 flv = &mdt_it_flavor[opc];
3286 if (flv->it_fmt != NULL)
3287 req_capsule_extend(pill, flv->it_fmt);
3289 rc = mdt_unpack_req_pack_rep(info, flv->it_flags);
3291 struct ptlrpc_request *req = mdt_info_req(info);
3292 if (flv->it_flags & MUTABOR &&
3293 req->rq_export->exp_connect_flags & OBD_CONNECT_RDONLY)
3296 if (rc == 0 && flv->it_act != NULL) {
3297 /* execute policy */
3298 rc = flv->it_act(opc, info, lockp, flags);
3305 static int mdt_intent_policy(struct ldlm_namespace *ns,
3306 struct ldlm_lock **lockp, void *req_cookie,
3307 ldlm_mode_t mode, int flags, void *data)
3309 struct mdt_thread_info *info;
3310 struct ptlrpc_request *req = req_cookie;
3311 struct ldlm_intent *it;
3312 struct req_capsule *pill;
3317 LASSERT(req != NULL);
3319 info = lu_context_key_get(&req->rq_svc_thread->t_env->le_ctx,
3321 LASSERT(info != NULL);
3322 pill = info->mti_pill;
3323 LASSERT(pill->rc_req == req);
3325 if (req->rq_reqmsg->lm_bufcount > DLM_INTENT_IT_OFF) {
3326 req_capsule_extend(pill, &RQF_LDLM_INTENT);
3327 it = req_capsule_client_get(pill, &RMF_LDLM_INTENT);
3329 const struct ldlm_request *dlmreq;
3332 rc = mdt_intent_opc(it->opc, info, lockp, flags);
3337 * Lock without inodebits makes no sense and will oops
3338 * later in ldlm. Let's check it now to see if we have
3339 * wrong lock from client or bits get corrupted
3340 * somewhere in mdt_intent_opc().
3342 dlmreq = info->mti_dlm_req;
3343 req_bits = dlmreq->lock_desc.l_policy_data.l_inodebits.bits;
3344 LASSERT(req_bits != 0);
3347 rc = err_serious(-EFAULT);
3349 /* No intent was provided */
3350 LASSERT(pill->rc_fmt == &RQF_LDLM_ENQUEUE);
3351 rc = req_capsule_server_pack(pill);
3353 rc = err_serious(rc);
3361 static void mdt_seq_adjust(const struct lu_env *env,
3362 struct mdt_device *m, int lost)
3364 struct md_site *ms = mdt_md_site(m);
3365 struct lu_range out;
3368 LASSERT(ms && ms->ms_server_seq);
3370 /* get extra seq from seq_server, moving it's range up */
3371 while (lost-- > 0) {
3372 seq_server_alloc_meta(ms->ms_server_seq, NULL, &out, env);
3377 static int mdt_seq_fini(const struct lu_env *env,
3378 struct mdt_device *m)
3380 struct md_site *ms = mdt_md_site(m);
3384 if (ms->ms_server_seq) {
3385 seq_server_fini(ms->ms_server_seq, env);
3386 OBD_FREE_PTR(ms->ms_server_seq);
3387 ms->ms_server_seq = NULL;
3390 if (ms->ms_control_seq) {
3391 seq_server_fini(ms->ms_control_seq, env);
3392 OBD_FREE_PTR(ms->ms_control_seq);
3393 ms->ms_control_seq = NULL;
3396 if (ms->ms_client_seq) {
3397 seq_client_fini(ms->ms_client_seq);
3398 OBD_FREE_PTR(ms->ms_client_seq);
3399 ms->ms_client_seq = NULL;
3406 static int mdt_seq_init(const struct lu_env *env,
3408 struct mdt_device *m)
3415 ms = mdt_md_site(m);
3418 * This is sequence-controller node. Init seq-controller server on local
3421 if (ms->ms_node_id == 0) {
3422 LASSERT(ms->ms_control_seq == NULL);
3424 OBD_ALLOC_PTR(ms->ms_control_seq);
3425 if (ms->ms_control_seq == NULL)
3428 rc = seq_server_init(ms->ms_control_seq,
3429 m->mdt_bottom, uuid,
3430 LUSTRE_SEQ_CONTROLLER,
3434 GOTO(out_seq_fini, rc);
3436 OBD_ALLOC_PTR(ms->ms_client_seq);
3437 if (ms->ms_client_seq == NULL)
3438 GOTO(out_seq_fini, rc = -ENOMEM);
3440 OBD_ALLOC(prefix, MAX_OBD_NAME + 5);
3441 if (prefix == NULL) {
3442 OBD_FREE_PTR(ms->ms_client_seq);
3443 GOTO(out_seq_fini, rc = -ENOMEM);
3446 snprintf(prefix, MAX_OBD_NAME + 5, "ctl-%s",
3450 * Init seq-controller client after seq-controller server is
3451 * ready. Pass ms->ms_control_seq to it for direct talking.
3453 rc = seq_client_init(ms->ms_client_seq, NULL,
3454 LUSTRE_SEQ_METADATA, prefix,
3455 ms->ms_control_seq);
3456 OBD_FREE(prefix, MAX_OBD_NAME + 5);
3459 GOTO(out_seq_fini, rc);
3462 /* Init seq-server on local MDT */
3463 LASSERT(ms->ms_server_seq == NULL);
3465 OBD_ALLOC_PTR(ms->ms_server_seq);
3466 if (ms->ms_server_seq == NULL)
3467 GOTO(out_seq_fini, rc = -ENOMEM);
3469 rc = seq_server_init(ms->ms_server_seq,
3470 m->mdt_bottom, uuid,
3474 GOTO(out_seq_fini, rc = -ENOMEM);
3476 /* Assign seq-controller client to local seq-server. */
3477 if (ms->ms_node_id == 0) {
3478 LASSERT(ms->ms_client_seq != NULL);
3480 rc = seq_server_set_cli(ms->ms_server_seq,
3488 mdt_seq_fini(env, m);
3493 * Init client sequence manager which is used by local MDS to talk to sequence
3494 * controller on remote node.
3496 static int mdt_seq_init_cli(const struct lu_env *env,
3497 struct mdt_device *m,
3498 struct lustre_cfg *cfg)
3500 struct md_site *ms = mdt_md_site(m);
3501 struct obd_device *mdc;
3502 struct obd_uuid *uuidp, *mdcuuidp;
3503 char *uuid_str, *mdc_uuid_str;
3506 struct mdt_thread_info *info;
3507 char *p, *index_string = lustre_cfg_string(cfg, 2);
3510 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
3511 uuidp = &info->mti_u.uuid[0];
3512 mdcuuidp = &info->mti_u.uuid[1];
3514 LASSERT(index_string);
3516 index = simple_strtol(index_string, &p, 10);
3518 CERROR("Invalid index in lustre_cgf, offset 2\n");
3522 /* check if this is adding the first MDC and controller is not yet
3524 if (index != 0 || ms->ms_client_seq)
3527 uuid_str = lustre_cfg_string(cfg, 1);
3528 mdc_uuid_str = lustre_cfg_string(cfg, 4);
3529 obd_str2uuid(uuidp, uuid_str);
3530 obd_str2uuid(mdcuuidp, mdc_uuid_str);
3532 mdc = class_find_client_obd(uuidp, LUSTRE_MDC_NAME, mdcuuidp);
3534 CERROR("can't find controller MDC by uuid %s\n",
3537 } else if (!mdc->obd_set_up) {
3538 CERROR("target %s not set up\n", mdc->obd_name);
3541 LASSERT(ms->ms_control_exp);
3542 OBD_ALLOC_PTR(ms->ms_client_seq);
3543 if (ms->ms_client_seq != NULL) {
3546 OBD_ALLOC(prefix, MAX_OBD_NAME + 5);
3550 snprintf(prefix, MAX_OBD_NAME + 5, "ctl-%s",
3553 rc = seq_client_init(ms->ms_client_seq,
3555 LUSTRE_SEQ_METADATA,
3557 OBD_FREE(prefix, MAX_OBD_NAME + 5);
3564 LASSERT(ms->ms_server_seq != NULL);
3565 rc = seq_server_set_cli(ms->ms_server_seq, ms->ms_client_seq,
3572 static void mdt_seq_fini_cli(struct mdt_device *m)
3578 ms = mdt_md_site(m);
3581 if (ms->ms_server_seq)
3582 seq_server_set_cli(ms->ms_server_seq,
3585 if (ms->ms_control_exp) {
3586 class_export_put(ms->ms_control_exp);
3587 ms->ms_control_exp = NULL;
3596 static int mdt_fld_fini(const struct lu_env *env,
3597 struct mdt_device *m)
3599 struct md_site *ms = mdt_md_site(m);
3602 if (ms && ms->ms_server_fld) {
3603 fld_server_fini(ms->ms_server_fld, env);
3604 OBD_FREE_PTR(ms->ms_server_fld);
3605 ms->ms_server_fld = NULL;
3611 static int mdt_fld_init(const struct lu_env *env,
3613 struct mdt_device *m)
3619 ms = mdt_md_site(m);
3621 OBD_ALLOC_PTR(ms->ms_server_fld);
3622 if (ms->ms_server_fld == NULL)
3623 RETURN(rc = -ENOMEM);
3625 rc = fld_server_init(ms->ms_server_fld,
3626 m->mdt_bottom, uuid, env);
3628 OBD_FREE_PTR(ms->ms_server_fld);
3629 ms->ms_server_fld = NULL;
3636 /* device init/fini methods */
3637 static void mdt_stop_ptlrpc_service(struct mdt_device *m)
3640 if (m->mdt_regular_service != NULL) {
3641 ptlrpc_unregister_service(m->mdt_regular_service);
3642 m->mdt_regular_service = NULL;
3644 if (m->mdt_readpage_service != NULL) {
3645 ptlrpc_unregister_service(m->mdt_readpage_service);
3646 m->mdt_readpage_service = NULL;
3648 if (m->mdt_xmds_service != NULL) {
3649 ptlrpc_unregister_service(m->mdt_xmds_service);
3650 m->mdt_xmds_service = NULL;
3652 if (m->mdt_setattr_service != NULL) {
3653 ptlrpc_unregister_service(m->mdt_setattr_service);
3654 m->mdt_setattr_service = NULL;
3656 if (m->mdt_mdsc_service != NULL) {
3657 ptlrpc_unregister_service(m->mdt_mdsc_service);
3658 m->mdt_mdsc_service = NULL;
3660 if (m->mdt_mdss_service != NULL) {
3661 ptlrpc_unregister_service(m->mdt_mdss_service);
3662 m->mdt_mdss_service = NULL;
3664 if (m->mdt_dtss_service != NULL) {
3665 ptlrpc_unregister_service(m->mdt_dtss_service);
3666 m->mdt_dtss_service = NULL;
3668 if (m->mdt_fld_service != NULL) {
3669 ptlrpc_unregister_service(m->mdt_fld_service);
3670 m->mdt_fld_service = NULL;
3675 static int mdt_start_ptlrpc_service(struct mdt_device *m)
3678 static struct ptlrpc_service_conf conf;
3679 cfs_proc_dir_entry_t *procfs_entry;
3682 procfs_entry = m->mdt_md_dev.md_lu_dev.ld_obd->obd_proc_entry;
3684 conf = (typeof(conf)) {
3685 .psc_nbufs = MDS_NBUFS,
3686 .psc_bufsize = MDS_BUFSIZE,
3687 .psc_max_req_size = MDS_MAXREQSIZE,
3688 .psc_max_reply_size = MDS_MAXREPSIZE,
3689 .psc_req_portal = MDS_REQUEST_PORTAL,
3690 .psc_rep_portal = MDC_REPLY_PORTAL,
3691 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
3693 * We'd like to have a mechanism to set this on a per-device
3694 * basis, but alas...
3696 .psc_min_threads = min(max(mdt_num_threads, MDT_MIN_THREADS),
3698 .psc_max_threads = MDT_MAX_THREADS,
3699 .psc_ctx_tags = LCT_MD_THREAD
3702 m->mdt_ldlm_client = &m->mdt_md_dev.md_lu_dev.ld_obd->obd_ldlm_client;
3703 ptlrpc_init_client(LDLM_CB_REQUEST_PORTAL, LDLM_CB_REPLY_PORTAL,
3704 "mdt_ldlm_client", m->mdt_ldlm_client);
3706 m->mdt_regular_service =
3707 ptlrpc_init_svc_conf(&conf, mdt_regular_handle, LUSTRE_MDT_NAME,
3708 procfs_entry, target_print_req,
3710 if (m->mdt_regular_service == NULL)
3713 rc = ptlrpc_start_threads(NULL, m->mdt_regular_service);
3715 GOTO(err_mdt_svc, rc);
3718 * readpage service configuration. Parameters have to be adjusted,
3721 conf = (typeof(conf)) {
3722 .psc_nbufs = MDS_NBUFS,
3723 .psc_bufsize = MDS_BUFSIZE,
3724 .psc_max_req_size = MDS_MAXREQSIZE,
3725 .psc_max_reply_size = MDS_MAXREPSIZE,
3726 .psc_req_portal = MDS_READPAGE_PORTAL,
3727 .psc_rep_portal = MDC_REPLY_PORTAL,
3728 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
3729 .psc_min_threads = min(max(mdt_num_threads, MDT_MIN_THREADS),
3731 .psc_max_threads = MDT_MAX_THREADS,
3732 .psc_ctx_tags = LCT_MD_THREAD
3734 m->mdt_readpage_service =
3735 ptlrpc_init_svc_conf(&conf, mdt_readpage_handle,
3736 LUSTRE_MDT_NAME "_readpage",
3737 procfs_entry, target_print_req,"mdt_rdpg");
3739 if (m->mdt_readpage_service == NULL) {
3740 CERROR("failed to start readpage service\n");
3741 GOTO(err_mdt_svc, rc = -ENOMEM);
3744 rc = ptlrpc_start_threads(NULL, m->mdt_readpage_service);
3747 * setattr service configuration.
3749 conf = (typeof(conf)) {
3750 .psc_nbufs = MDS_NBUFS,
3751 .psc_bufsize = MDS_BUFSIZE,
3752 .psc_max_req_size = MDS_MAXREQSIZE,
3753 .psc_max_reply_size = MDS_MAXREPSIZE,
3754 .psc_req_portal = MDS_SETATTR_PORTAL,
3755 .psc_rep_portal = MDC_REPLY_PORTAL,
3756 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
3757 .psc_min_threads = min(max(mdt_num_threads, MDT_MIN_THREADS),
3759 .psc_max_threads = MDT_MAX_THREADS,
3760 .psc_ctx_tags = LCT_MD_THREAD
3763 m->mdt_setattr_service =
3764 ptlrpc_init_svc_conf(&conf, mdt_regular_handle,
3765 LUSTRE_MDT_NAME "_setattr",
3766 procfs_entry, target_print_req,"mdt_attr");
3768 if (!m->mdt_setattr_service) {
3769 CERROR("failed to start setattr service\n");
3770 GOTO(err_mdt_svc, rc = -ENOMEM);
3773 rc = ptlrpc_start_threads(NULL, m->mdt_setattr_service);
3775 GOTO(err_mdt_svc, rc);
3778 * sequence controller service configuration
3780 conf = (typeof(conf)) {
3781 .psc_nbufs = MDS_NBUFS,
3782 .psc_bufsize = MDS_BUFSIZE,
3783 .psc_max_req_size = SEQ_MAXREQSIZE,
3784 .psc_max_reply_size = SEQ_MAXREPSIZE,
3785 .psc_req_portal = SEQ_CONTROLLER_PORTAL,
3786 .psc_rep_portal = MDC_REPLY_PORTAL,
3787 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
3788 .psc_min_threads = SEQ_NUM_THREADS,
3789 .psc_max_threads = SEQ_NUM_THREADS,
3790 .psc_ctx_tags = LCT_MD_THREAD|LCT_DT_THREAD
3793 m->mdt_mdsc_service =
3794 ptlrpc_init_svc_conf(&conf, mdt_mdsc_handle,
3795 LUSTRE_MDT_NAME"_mdsc",
3796 procfs_entry, target_print_req,"mdt_mdsc");
3797 if (!m->mdt_mdsc_service) {
3798 CERROR("failed to start seq controller service\n");
3799 GOTO(err_mdt_svc, rc = -ENOMEM);
3802 rc = ptlrpc_start_threads(NULL, m->mdt_mdsc_service);
3804 GOTO(err_mdt_svc, rc);
3807 * metadata sequence server service configuration
3809 conf = (typeof(conf)) {
3810 .psc_nbufs = MDS_NBUFS,
3811 .psc_bufsize = MDS_BUFSIZE,
3812 .psc_max_req_size = SEQ_MAXREQSIZE,
3813 .psc_max_reply_size = SEQ_MAXREPSIZE,
3814 .psc_req_portal = SEQ_METADATA_PORTAL,
3815 .psc_rep_portal = MDC_REPLY_PORTAL,
3816 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
3817 .psc_min_threads = SEQ_NUM_THREADS,
3818 .psc_max_threads = SEQ_NUM_THREADS,
3819 .psc_ctx_tags = LCT_MD_THREAD|LCT_DT_THREAD
3822 m->mdt_mdss_service =
3823 ptlrpc_init_svc_conf(&conf, mdt_mdss_handle,
3824 LUSTRE_MDT_NAME"_mdss",
3825 procfs_entry, target_print_req,"mdt_mdss");
3826 if (!m->mdt_mdss_service) {
3827 CERROR("failed to start metadata seq server service\n");
3828 GOTO(err_mdt_svc, rc = -ENOMEM);
3831 rc = ptlrpc_start_threads(NULL, m->mdt_mdss_service);
3833 GOTO(err_mdt_svc, rc);
3837 * Data sequence server service configuration. We want to have really
3838 * cluster-wide sequences space. This is why we start only one sequence
3839 * controller which manages space.
3841 conf = (typeof(conf)) {
3842 .psc_nbufs = MDS_NBUFS,
3843 .psc_bufsize = MDS_BUFSIZE,
3844 .psc_max_req_size = SEQ_MAXREQSIZE,
3845 .psc_max_reply_size = SEQ_MAXREPSIZE,
3846 .psc_req_portal = SEQ_DATA_PORTAL,
3847 .psc_rep_portal = OSC_REPLY_PORTAL,
3848 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
3849 .psc_min_threads = SEQ_NUM_THREADS,
3850 .psc_max_threads = SEQ_NUM_THREADS,
3851 .psc_ctx_tags = LCT_MD_THREAD|LCT_DT_THREAD
3854 m->mdt_dtss_service =
3855 ptlrpc_init_svc_conf(&conf, mdt_dtss_handle,
3856 LUSTRE_MDT_NAME"_dtss",
3857 procfs_entry, target_print_req,"mdt_dtss");
3858 if (!m->mdt_dtss_service) {
3859 CERROR("failed to start data seq server service\n");
3860 GOTO(err_mdt_svc, rc = -ENOMEM);
3863 rc = ptlrpc_start_threads(NULL, m->mdt_dtss_service);
3865 GOTO(err_mdt_svc, rc);
3867 /* FLD service start */
3868 conf = (typeof(conf)) {
3869 .psc_nbufs = MDS_NBUFS,
3870 .psc_bufsize = MDS_BUFSIZE,
3871 .psc_max_req_size = FLD_MAXREQSIZE,
3872 .psc_max_reply_size = FLD_MAXREPSIZE,
3873 .psc_req_portal = FLD_REQUEST_PORTAL,
3874 .psc_rep_portal = MDC_REPLY_PORTAL,
3875 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
3876 .psc_min_threads = FLD_NUM_THREADS,
3877 .psc_max_threads = FLD_NUM_THREADS,
3878 .psc_ctx_tags = LCT_DT_THREAD|LCT_MD_THREAD
3881 m->mdt_fld_service =
3882 ptlrpc_init_svc_conf(&conf, mdt_fld_handle,
3883 LUSTRE_MDT_NAME"_fld",
3884 procfs_entry, target_print_req, "mdt_fld");
3885 if (!m->mdt_fld_service) {
3886 CERROR("failed to start fld service\n");
3887 GOTO(err_mdt_svc, rc = -ENOMEM);
3890 rc = ptlrpc_start_threads(NULL, m->mdt_fld_service);
3892 GOTO(err_mdt_svc, rc);
3895 * mds-mds service configuration. Separate portal is used to allow
3896 * mds-mds requests be not blocked during recovery.
3898 conf = (typeof(conf)) {
3899 .psc_nbufs = MDS_NBUFS,
3900 .psc_bufsize = MDS_BUFSIZE,
3901 .psc_max_req_size = MDS_MAXREQSIZE,
3902 .psc_max_reply_size = MDS_MAXREPSIZE,
3903 .psc_req_portal = MDS_MDS_PORTAL,
3904 .psc_rep_portal = MDC_REPLY_PORTAL,
3905 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
3906 .psc_min_threads = min(max(mdt_num_threads, MDT_MIN_THREADS),
3908 .psc_max_threads = MDT_MAX_THREADS,
3909 .psc_ctx_tags = LCT_MD_THREAD
3911 m->mdt_xmds_service =
3912 ptlrpc_init_svc_conf(&conf, mdt_xmds_handle,
3913 LUSTRE_MDT_NAME "_mds",
3914 procfs_entry, target_print_req,"mdt_xmds");
3916 if (m->mdt_xmds_service == NULL) {
3917 CERROR("failed to start readpage service\n");
3918 GOTO(err_mdt_svc, rc = -ENOMEM);
3921 rc = ptlrpc_start_threads(NULL, m->mdt_xmds_service);
3923 GOTO(err_mdt_svc, rc);
3928 mdt_stop_ptlrpc_service(m);
3933 static void mdt_stack_fini(const struct lu_env *env,
3934 struct mdt_device *m, struct lu_device *top)
3936 struct obd_device *obd = mdt2obd_dev(m);
3937 struct lustre_cfg_bufs *bufs;
3938 struct lustre_cfg *lcfg;
3939 struct mdt_thread_info *info;
3943 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
3944 LASSERT(info != NULL);
3946 bufs = &info->mti_u.bufs;
3947 /* process cleanup, pass mdt obd name to get obd umount flags */
3948 lustre_cfg_bufs_reset(bufs, obd->obd_name);
3953 lustre_cfg_bufs_set_string(bufs, 1, flags);
3954 lcfg = lustre_cfg_new(LCFG_CLEANUP, bufs);
3956 CERROR("Cannot alloc lcfg!\n");
3961 top->ld_ops->ldo_process_config(env, top, lcfg);
3962 lustre_cfg_free(lcfg);
3964 lu_stack_fini(env, top);
3965 m->mdt_child = NULL;
3966 m->mdt_bottom = NULL;
3969 static struct lu_device *mdt_layer_setup(struct lu_env *env,
3970 const char *typename,
3971 struct lu_device *child,
3972 struct lustre_cfg *cfg)
3974 const char *dev = lustre_cfg_string(cfg, 0);
3975 struct obd_type *type;
3976 struct lu_device_type *ldt;
3977 struct lu_device *d;
3982 type = class_get_type(typename);
3984 CERROR("Unknown type: '%s'\n", typename);
3985 GOTO(out, rc = -ENODEV);
3988 rc = lu_env_refill((struct lu_env *)env);
3990 CERROR("Failure to refill session: '%d'\n", rc);
3996 CERROR("type: '%s'\n", typename);
3997 GOTO(out_type, rc = -EINVAL);
4000 ldt->ldt_obd_type = type;
4001 d = ldt->ldt_ops->ldto_device_alloc(env, ldt, cfg);
4003 CERROR("Cannot allocate device: '%s'\n", typename);
4004 GOTO(out_type, rc = -ENODEV);
4007 LASSERT(child->ld_site);
4008 d->ld_site = child->ld_site;
4011 rc = ldt->ldt_ops->ldto_device_init(env, d, dev, child);
4013 CERROR("can't init device '%s', rc %d\n", typename, rc);
4014 GOTO(out_alloc, rc);
4017 lu_ref_add(&d->ld_reference, "lu-stack", &lu_site_init);
4022 ldt->ldt_ops->ldto_device_free(env, d);
4025 class_put_type(type);
4030 static int mdt_stack_init(struct lu_env *env,
4031 struct mdt_device *m, struct lustre_cfg *cfg)
4033 struct lu_device *d = &m->mdt_md_dev.md_lu_dev;
4034 struct lu_device *tmp;
4035 struct md_device *md;
4039 /* init the stack */
4040 tmp = mdt_layer_setup(env, LUSTRE_OSD_NAME, d, cfg);
4042 RETURN(PTR_ERR(tmp));
4044 m->mdt_bottom = lu2dt_dev(tmp);
4046 tmp = mdt_layer_setup(env, LUSTRE_MDD_NAME, d, cfg);
4048 GOTO(out, rc = PTR_ERR(tmp));
4053 tmp = mdt_layer_setup(env, LUSTRE_CMM_NAME, d, cfg);
4055 GOTO(out, rc = PTR_ERR(tmp));
4058 /*set mdd upcall device*/
4059 md_upcall_dev_set(md, lu2md_dev(d));
4062 /*set cmm upcall device*/
4063 md_upcall_dev_set(md, &m->mdt_md_dev);
4065 m->mdt_child = lu2md_dev(d);
4067 /* process setup config */
4068 tmp = &m->mdt_md_dev.md_lu_dev;
4069 rc = tmp->ld_ops->ldo_process_config(env, tmp, cfg);
4072 /* fini from last known good lu_device */
4074 mdt_stack_fini(env, m, d);
4079 static void mdt_fini(const struct lu_env *env, struct mdt_device *m)
4081 struct md_device *next = m->mdt_child;
4082 struct lu_device *d = &m->mdt_md_dev.md_lu_dev;
4083 struct lu_site *ls = d->ld_site;
4084 struct obd_device *obd = mdt2obd_dev(m);
4088 /* At this point, obd exports might still be on the "obd_zombie_exports"
4089 * list, and obd_zombie_impexp_thread() is trying to destroy them.
4090 * We wait a little bit until all exports (except the self-export)
4091 * have been destroyed, because the whole mdt stack might be accessed
4092 * in mdt_destroy_export(). This will not be a long time, maybe one or
4093 * two seconds are enough. This is not a problem while umounting.
4095 * The three references that should be remaining are the
4096 * obd_self_export and the attach and setup references.
4098 while (atomic_read(&obd->obd_refcount) > 3) {
4099 cfs_schedule_timeout(CFS_TASK_UNINT, cfs_time_seconds(1));
4101 if (waited > 5 && IS_PO2(waited))
4102 LCONSOLE_WARN("Waiting for obd_zombie_impexp_thread "
4103 "more than %d seconds to destroy all "
4104 "the exports. The current obd refcount ="
4105 " %d. Is it stuck there?\n",
4106 waited, atomic_read(&obd->obd_refcount));
4109 ping_evictor_stop();
4111 target_recovery_fini(obd);
4112 mdt_stop_ptlrpc_service(m);
4113 obd_zombie_barrier();
4114 #ifdef HAVE_QUOTA_SUPPORT
4115 next->md_ops->mdo_quota.mqo_cleanup(env, next);
4117 mdt_fs_cleanup(env, m);
4118 upcall_cache_cleanup(m->mdt_identity_cache);
4119 m->mdt_identity_cache = NULL;
4121 if (m->mdt_namespace != NULL) {
4122 ldlm_namespace_free(m->mdt_namespace, NULL, d->ld_obd->obd_force);
4123 d->ld_obd->obd_namespace = m->mdt_namespace = NULL;
4126 mdt_seq_fini(env, m);
4127 mdt_seq_fini_cli(m);
4128 mdt_fld_fini(env, m);
4130 lprocfs_remove_proc_entry("clear", obd->obd_proc_exports_entry);
4131 lprocfs_free_per_client_stats(obd);
4132 lprocfs_free_obd_stats(obd);
4133 ptlrpc_lprocfs_unregister_obd(d->ld_obd);
4134 lprocfs_obd_cleanup(d->ld_obd);
4136 sptlrpc_rule_set_free(&m->mdt_sptlrpc_rset);
4138 next->md_ops->mdo_init_capa_ctxt(env, next, 0, 0, 0, NULL);
4139 cfs_timer_disarm(&m->mdt_ck_timer);
4140 mdt_ck_thread_stop(m);
4142 /* finish the stack */
4143 mdt_stack_fini(env, m, md2lu_dev(m->mdt_child));
4146 struct md_site *mite;
4149 mite = lu_site2md(ls);
4153 LASSERT(atomic_read(&d->ld_ref) == 0);
4158 static void fsoptions_to_mdt_flags(struct mdt_device *m, char *options)
4162 m->mdt_opts.mo_mds_capa = 1;
4163 m->mdt_opts.mo_oss_capa = 1;
4164 #ifdef CONFIG_FS_POSIX_ACL
4165 /* ACLs should be enabled by default (b=13829) */
4166 m->mdt_opts.mo_acl = 1;
4167 LCONSOLE_INFO("Enabling ACL\n");
4169 m->mdt_opts.mo_acl = 0;
4170 LCONSOLE_INFO("Disabling ACL\n");
4179 while (*p && *p != ',')
4183 if ((len == sizeof("user_xattr") - 1) &&
4184 (memcmp(options, "user_xattr", len) == 0)) {
4185 m->mdt_opts.mo_user_xattr = 1;
4186 LCONSOLE_INFO("Enabling user_xattr\n");
4187 } else if ((len == sizeof("nouser_xattr") - 1) &&
4188 (memcmp(options, "nouser_xattr", len) == 0)) {
4189 m->mdt_opts.mo_user_xattr = 0;
4190 LCONSOLE_INFO("Disabling user_xattr\n");
4191 } else if ((len == sizeof("noacl") - 1) &&
4192 (memcmp(options, "noacl", len) == 0)) {
4193 m->mdt_opts.mo_acl = 0;
4194 LCONSOLE_INFO("Disabling ACL\n");
4201 int mdt_postrecov(const struct lu_env *, struct mdt_device *);
4203 static int mdt_init0(const struct lu_env *env, struct mdt_device *m,
4204 struct lu_device_type *ldt, struct lustre_cfg *cfg)
4206 struct lprocfs_static_vars lvars;
4207 struct mdt_thread_info *info;
4208 struct obd_device *obd;
4209 const char *dev = lustre_cfg_string(cfg, 0);
4210 const char *num = lustre_cfg_string(cfg, 2);
4211 struct lustre_mount_info *lmi = NULL;
4212 struct lustre_sb_info *lsi;
4214 struct md_site *mite;
4215 const char *identity_upcall = "NONE";
4216 #ifdef HAVE_QUOTA_SUPPORT
4217 struct md_device *next;
4222 md_device_init(&m->mdt_md_dev, ldt);
4224 * Environment (env) might be missing mdt_thread_key values at that
4225 * point, if device is allocated when mdt_thread_key is in QUIESCENT
4228 * Usually device allocation path doesn't use module key values, but
4229 * mdt has to do a lot of work here, so allocate key value.
4231 rc = lu_env_refill((struct lu_env *)env);
4235 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
4236 LASSERT(info != NULL);
4238 obd = class_name2obd(dev);
4239 LASSERT(obd != NULL);
4241 spin_lock_init(&m->mdt_transno_lock);
4243 m->mdt_max_mdsize = MAX_MD_SIZE;
4244 m->mdt_max_cookiesize = sizeof(struct llog_cookie);
4246 m->mdt_opts.mo_user_xattr = 0;
4247 m->mdt_opts.mo_acl = 0;
4248 m->mdt_opts.mo_cos = MDT_COS_DEFAULT;
4249 lmi = server_get_mount_2(dev);
4251 CERROR("Cannot get mount info for %s!\n", dev);
4254 lsi = s2lsi(lmi->lmi_sb);
4255 fsoptions_to_mdt_flags(m, lsi->lsi_lmd->lmd_opts);
4258 rwlock_init(&m->mdt_sptlrpc_lock);
4259 sptlrpc_rule_set_init(&m->mdt_sptlrpc_rset);
4261 spin_lock_init(&m->mdt_ioepoch_lock);
4262 m->mdt_opts.mo_compat_resname = 0;
4263 m->mdt_capa_timeout = CAPA_TIMEOUT;
4264 m->mdt_capa_alg = CAPA_HMAC_ALG_SHA1;
4265 m->mdt_ck_timeout = CAPA_KEY_TIMEOUT;
4267 spin_lock_init(&m->mdt_client_bitmap_lock);
4269 OBD_ALLOC_PTR(mite);
4271 GOTO(err_lmi, rc = -ENOMEM);
4275 m->mdt_md_dev.md_lu_dev.ld_ops = &mdt_lu_ops;
4276 m->mdt_md_dev.md_lu_dev.ld_obd = obd;
4277 /* set this lu_device to obd, because error handling need it */
4278 obd->obd_lu_dev = &m->mdt_md_dev.md_lu_dev;
4280 rc = lu_site_init(s, &m->mdt_md_dev.md_lu_dev);
4282 CERROR("Can't init lu_site, rc %d\n", rc);
4283 GOTO(err_free_site, rc);
4286 lprocfs_mdt_init_vars(&lvars);
4287 rc = lprocfs_obd_setup(obd, lvars.obd_vars);
4289 CERROR("Can't init lprocfs, rc %d\n", rc);
4290 GOTO(err_fini_site, rc);
4292 ptlrpc_lprocfs_register_obd(obd);
4294 rc = mdt_procfs_init(m, dev);
4296 CERROR("Can't init MDT lprocfs, rc %d\n", rc);
4297 GOTO(err_fini_proc, rc);
4300 obd->obd_proc_exports_entry = proc_mkdir("exports",
4301 obd->obd_proc_entry);
4302 if (obd->obd_proc_exports_entry)
4303 lprocfs_add_simple(obd->obd_proc_exports_entry,
4304 "clear", lprocfs_nid_stats_clear_read,
4305 lprocfs_nid_stats_clear_write, obd, NULL);
4307 /* set server index */
4309 lu_site2md(s)->ms_node_id = simple_strtol(num, NULL, 10);
4311 /* failover is the default
4312 * FIXME: we do not failout mds0/mgs, which may cause some problems.
4313 * assumed whose ls_node_id == 0 XXX
4315 obd->obd_replayable = 1;
4316 /* No connection accepted until configurations will finish */
4317 obd->obd_no_conn = 1;
4319 if (cfg->lcfg_bufcount > 4 && LUSTRE_CFG_BUFLEN(cfg, 4) > 0) {
4320 char *str = lustre_cfg_string(cfg, 4);
4321 if (strchr(str, 'n')) {
4322 CWARN("%s: recovery disabled\n", obd->obd_name);
4323 obd->obd_replayable = 0;
4327 /* init the stack */
4328 rc = mdt_stack_init((struct lu_env *)env, m, cfg);
4330 CERROR("Can't init device stack, rc %d\n", rc);
4331 GOTO(err_fini_proc, rc);
4334 rc = mdt_fld_init(env, obd->obd_name, m);
4336 GOTO(err_fini_stack, rc);
4338 rc = mdt_seq_init(env, obd->obd_name, m);
4340 GOTO(err_fini_fld, rc);
4342 snprintf(info->mti_u.ns_name, sizeof info->mti_u.ns_name,
4343 LUSTRE_MDT_NAME"-%p", m);
4344 m->mdt_namespace = ldlm_namespace_new(obd, info->mti_u.ns_name,
4345 LDLM_NAMESPACE_SERVER,
4346 LDLM_NAMESPACE_GREEDY);
4347 if (m->mdt_namespace == NULL)
4348 GOTO(err_fini_seq, rc = -ENOMEM);
4350 ldlm_register_intent(m->mdt_namespace, mdt_intent_policy);
4351 /* set obd_namespace for compatibility with old code */
4352 obd->obd_namespace = m->mdt_namespace;
4354 /* XXX: to support suppgid for ACL, we enable identity_upcall
4355 * by default, otherwise, maybe got unexpected -EACCESS. */
4356 if (m->mdt_opts.mo_acl)
4357 identity_upcall = MDT_IDENTITY_UPCALL_PATH;
4359 m->mdt_identity_cache = upcall_cache_init(obd->obd_name, identity_upcall,
4360 &mdt_identity_upcall_cache_ops);
4361 if (IS_ERR(m->mdt_identity_cache)) {
4362 rc = PTR_ERR(m->mdt_identity_cache);
4363 m->mdt_identity_cache = NULL;
4364 GOTO(err_free_ns, rc);
4367 cfs_timer_init(&m->mdt_ck_timer, mdt_ck_timer_callback, m);
4369 rc = mdt_ck_thread_start(m);
4371 GOTO(err_free_ns, rc);
4373 rc = mdt_fs_setup(env, m, obd);
4377 #ifdef HAVE_QUOTA_SUPPORT
4378 next = m->mdt_child;
4379 rc = next->md_ops->mdo_quota.mqo_setup(env, next, lmi->lmi_mnt);
4381 GOTO(err_fs_cleanup, rc);
4384 server_put_mount_2(dev, lmi->lmi_mnt);
4387 target_recovery_init(obd, mdt_recovery_handle);
4389 rc = mdt_start_ptlrpc_service(m);
4391 GOTO(err_recovery, rc);
4393 ping_evictor_start();
4395 rc = lu_site_init_finish(s);
4397 GOTO(err_stop_service, rc);
4399 if (obd->obd_recovering == 0)
4400 mdt_postrecov(env, m);
4402 mdt_init_capa_ctxt(env, m);
4404 /* Reduce the initial timeout on an MDS because it doesn't need such
4405 * a long timeout as an OST does. Adaptive timeouts will adjust this
4406 * value appropriately. */
4407 if (ldlm_timeout == LDLM_TIMEOUT_DEFAULT)
4408 ldlm_timeout = MDS_LDLM_TIMEOUT_DEFAULT;
4413 ping_evictor_stop();
4414 mdt_stop_ptlrpc_service(m);
4416 target_recovery_fini(obd);
4417 #ifdef HAVE_QUOTA_SUPPORT
4418 next->md_ops->mdo_quota.mqo_cleanup(env, next);
4421 mdt_fs_cleanup(env, m);
4423 cfs_timer_disarm(&m->mdt_ck_timer);
4424 mdt_ck_thread_stop(m);
4426 upcall_cache_cleanup(m->mdt_identity_cache);
4427 m->mdt_identity_cache = NULL;
4428 ldlm_namespace_free(m->mdt_namespace, NULL, 0);
4429 obd->obd_namespace = m->mdt_namespace = NULL;
4431 mdt_seq_fini(env, m);
4433 mdt_fld_fini(env, m);
4435 mdt_stack_fini(env, m, md2lu_dev(m->mdt_child));
4438 if (obd->obd_proc_exports_entry)
4439 lprocfs_remove_proc_entry("clear", obd->obd_proc_exports_entry);
4440 ptlrpc_lprocfs_unregister_obd(obd);
4441 lprocfs_obd_cleanup(obd);
4448 server_put_mount_2(dev, lmi->lmi_mnt);
4452 /* used by MGS to process specific configurations */
4453 static int mdt_process_config(const struct lu_env *env,
4454 struct lu_device *d, struct lustre_cfg *cfg)
4456 struct mdt_device *m = mdt_dev(d);
4457 struct md_device *md_next = m->mdt_child;
4458 struct lu_device *next = md2lu_dev(md_next);
4462 switch (cfg->lcfg_command) {
4463 case LCFG_SPTLRPC_CONF: {
4464 struct sptlrpc_conf_log *log;
4465 struct sptlrpc_rule_set tmp_rset;
4467 log = sptlrpc_conf_log_extract(cfg);
4473 sptlrpc_rule_set_init(&tmp_rset);
4475 rc = sptlrpc_rule_set_from_log(&tmp_rset, log);
4477 CERROR("mdt %p: failed get sptlrpc rules: %d\n", m, rc);
4481 write_lock(&m->mdt_sptlrpc_lock);
4482 sptlrpc_rule_set_free(&m->mdt_sptlrpc_rset);
4483 m->mdt_sptlrpc_rset = tmp_rset;
4484 write_unlock(&m->mdt_sptlrpc_lock);
4486 sptlrpc_target_update_exp_flavor(
4487 md2lu_dev(&m->mdt_md_dev)->ld_obd, &tmp_rset);
4492 struct lprocfs_static_vars lvars;
4493 struct obd_device *obd = d->ld_obd;
4495 lprocfs_mdt_init_vars(&lvars);
4496 rc = class_process_proc_param(PARAM_MDT, lvars.obd_vars,
4498 if (rc > 0 || rc == -ENOSYS)
4499 /* we don't understand; pass it on */
4500 rc = next->ld_ops->ldo_process_config(env, next, cfg);
4505 * Add mdc hook to get first MDT uuid and connect it to
4506 * ls->controller to use for seq manager.
4508 rc = next->ld_ops->ldo_process_config(env, next, cfg);
4510 CERROR("Can't add mdc, rc %d\n", rc);
4512 rc = mdt_seq_init_cli(env, mdt_dev(d), cfg);
4515 /* others are passed further */
4516 rc = next->ld_ops->ldo_process_config(env, next, cfg);
4522 static struct lu_object *mdt_object_alloc(const struct lu_env *env,
4523 const struct lu_object_header *hdr,
4524 struct lu_device *d)
4526 struct mdt_object *mo;
4532 struct lu_object *o;
4533 struct lu_object_header *h;
4535 o = &mo->mot_obj.mo_lu;
4536 h = &mo->mot_header;
4537 lu_object_header_init(h);
4538 lu_object_init(o, h, d);
4539 lu_object_add_top(h, o);
4540 o->lo_ops = &mdt_obj_ops;
4546 static int mdt_object_init(const struct lu_env *env, struct lu_object *o,
4547 const struct lu_object_conf *_)
4549 struct mdt_device *d = mdt_dev(o->lo_dev);
4550 struct lu_device *under;
4551 struct lu_object *below;
4555 CDEBUG(D_INFO, "object init, fid = "DFID"\n",
4556 PFID(lu_object_fid(o)));
4558 under = &d->mdt_child->md_lu_dev;
4559 below = under->ld_ops->ldo_object_alloc(env, o->lo_header, under);
4560 if (below != NULL) {
4561 lu_object_add(o, below);
4568 static void mdt_object_free(const struct lu_env *env, struct lu_object *o)
4570 struct mdt_object *mo = mdt_obj(o);
4571 struct lu_object_header *h;
4575 CDEBUG(D_INFO, "object free, fid = "DFID"\n",
4576 PFID(lu_object_fid(o)));
4579 lu_object_header_fini(h);
4584 static const struct lu_device_operations mdt_lu_ops = {
4585 .ldo_object_alloc = mdt_object_alloc,
4586 .ldo_process_config = mdt_process_config
4589 static const struct lu_object_operations mdt_obj_ops = {
4590 .loo_object_init = mdt_object_init,
4591 .loo_object_free = mdt_object_free
4594 /* mds_connect_internal */
4595 static int mdt_connect_internal(struct obd_export *exp,
4596 struct mdt_device *mdt,
4597 struct obd_connect_data *data)
4600 data->ocd_connect_flags &= MDT_CONNECT_SUPPORTED;
4601 data->ocd_ibits_known &= MDS_INODELOCK_FULL;
4603 /* If no known bits (which should not happen, probably,
4604 as everybody should support LOOKUP and UPDATE bits at least)
4605 revert to compat mode with plain locks. */
4606 if (!data->ocd_ibits_known &&
4607 data->ocd_connect_flags & OBD_CONNECT_IBITS)
4608 data->ocd_connect_flags &= ~OBD_CONNECT_IBITS;
4610 if (!mdt->mdt_opts.mo_acl)
4611 data->ocd_connect_flags &= ~OBD_CONNECT_ACL;
4613 if (!mdt->mdt_opts.mo_user_xattr)
4614 data->ocd_connect_flags &= ~OBD_CONNECT_XATTR;
4616 spin_lock(&exp->exp_lock);
4617 exp->exp_connect_flags = data->ocd_connect_flags;
4618 spin_unlock(&exp->exp_lock);
4619 data->ocd_version = LUSTRE_VERSION_CODE;
4620 exp->exp_mdt_data.med_ibits_known = data->ocd_ibits_known;
4624 if (mdt->mdt_opts.mo_acl &&
4625 ((exp->exp_connect_flags & OBD_CONNECT_ACL) == 0)) {
4626 CWARN("%s: MDS requires ACL support but client does not\n",
4627 mdt->mdt_md_dev.md_lu_dev.ld_obd->obd_name);
4632 if ((exp->exp_connect_flags & OBD_CONNECT_FID) == 0) {
4633 CWARN("%s: MDS requires FID support, but client not\n",
4634 mdt->mdt_md_dev.md_lu_dev.ld_obd->obd_name);
4641 /* mds_connect copy */
4642 static int mdt_obd_connect(const struct lu_env *env,
4643 struct lustre_handle *conn, struct obd_device *obd,
4644 struct obd_uuid *cluuid,
4645 struct obd_connect_data *data,
4648 struct mdt_thread_info *info;
4649 struct lsd_client_data *lcd;
4650 struct obd_export *exp;
4651 struct mdt_device *mdt;
4652 struct ptlrpc_request *req;
4656 LASSERT(env != NULL);
4657 if (!conn || !obd || !cluuid)
4660 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
4661 req = info->mti_pill->rc_req;
4662 mdt = mdt_dev(obd->obd_lu_dev);
4664 rc = class_connect(conn, obd, cluuid);
4668 exp = class_conn2export(conn);
4669 LASSERT(exp != NULL);
4671 CDEBUG(D_SEC, "from %s\n", sptlrpc_part2name(req->rq_sp_from));
4673 spin_lock(&exp->exp_lock);
4674 exp->exp_sp_peer = req->rq_sp_from;
4676 read_lock(&mdt->mdt_sptlrpc_lock);
4677 sptlrpc_rule_set_choose(&mdt->mdt_sptlrpc_rset, exp->exp_sp_peer,
4678 req->rq_peer.nid, &exp->exp_flvr);
4679 read_unlock(&mdt->mdt_sptlrpc_lock);
4681 if (exp->exp_flvr.sf_rpc != req->rq_flvr.sf_rpc) {
4682 CERROR("invalid rpc flavor %x, expect %x, from %s\n",
4683 req->rq_flvr.sf_rpc, exp->exp_flvr.sf_rpc,
4684 libcfs_nid2str(req->rq_peer.nid));
4685 exp->exp_flvr.sf_rpc = SPTLRPC_FLVR_INVALID;
4686 spin_unlock(&exp->exp_lock);
4689 spin_unlock(&exp->exp_lock);
4691 rc = mdt_connect_internal(exp, mdt, data);
4695 struct mdt_thread_info *mti;
4696 mti = lu_context_key_get(&env->le_ctx,
4698 LASSERT(mti != NULL);
4700 memcpy(lcd->lcd_uuid, cluuid, sizeof lcd->lcd_uuid);
4701 exp->exp_mdt_data.med_lcd = lcd;
4702 rc = mdt_client_new(env, mdt);
4705 exp->exp_mdt_data.med_lcd = NULL;
4707 mdt_export_stats_init(obd, exp, localdata);
4714 class_disconnect(exp);
4716 class_export_put(exp);
4721 static int mdt_obd_reconnect(const struct lu_env *env,
4722 struct obd_export *exp, struct obd_device *obd,
4723 struct obd_uuid *cluuid,
4724 struct obd_connect_data *data,
4727 struct mdt_thread_info *info;
4728 struct mdt_device *mdt;
4729 struct ptlrpc_request *req;
4733 if (exp == NULL || obd == NULL || cluuid == NULL)
4736 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
4737 req = info->mti_pill->rc_req;
4738 mdt = mdt_dev(obd->obd_lu_dev);
4740 CDEBUG(D_SEC, "from %s\n", sptlrpc_part2name(req->rq_sp_from));
4742 spin_lock(&exp->exp_lock);
4743 if (exp->exp_flvr.sf_rpc == SPTLRPC_FLVR_INVALID) {
4744 exp->exp_sp_peer = req->rq_sp_from;
4746 read_lock(&mdt->mdt_sptlrpc_lock);
4747 sptlrpc_rule_set_choose(&mdt->mdt_sptlrpc_rset,
4749 req->rq_peer.nid, &exp->exp_flvr);
4750 read_unlock(&mdt->mdt_sptlrpc_lock);
4752 if (exp->exp_flvr.sf_rpc != req->rq_flvr.sf_rpc) {
4753 CERROR("invalid rpc flavor %x, expect %x, from %s\n",
4754 req->rq_flvr.sf_rpc, exp->exp_flvr.sf_rpc,
4755 libcfs_nid2str(req->rq_peer.nid));
4756 exp->exp_flvr.sf_rpc = SPTLRPC_FLVR_INVALID;
4757 spin_unlock(&exp->exp_lock);
4761 spin_unlock(&exp->exp_lock);
4763 rc = mdt_connect_internal(exp, mdt_dev(obd->obd_lu_dev), data);
4765 mdt_export_stats_init(obd, exp, localdata);
4770 static int mdt_obd_disconnect(struct obd_export *exp)
4772 struct mdt_device *mdt = mdt_dev(exp->exp_obd->obd_lu_dev);
4777 class_export_get(exp);
4779 /* Disconnect early so that clients can't keep using export */
4780 rc = class_disconnect(exp);
4781 if (mdt->mdt_namespace != NULL || exp->exp_obd->obd_namespace != NULL)
4782 ldlm_cancel_locks_for_export(exp);
4784 /* release nid stat refererence */
4785 lprocfs_exp_cleanup(exp);
4787 /* complete all outstanding replies */
4788 spin_lock(&exp->exp_lock);
4789 while (!list_empty(&exp->exp_outstanding_replies)) {
4790 struct ptlrpc_reply_state *rs =
4791 list_entry(exp->exp_outstanding_replies.next,
4792 struct ptlrpc_reply_state, rs_exp_list);
4793 struct ptlrpc_service *svc = rs->rs_service;
4795 spin_lock(&svc->srv_lock);
4796 list_del_init(&rs->rs_exp_list);
4797 ptlrpc_schedule_difficult_reply(rs);
4798 spin_unlock(&svc->srv_lock);
4800 spin_unlock(&exp->exp_lock);
4802 class_export_put(exp);
4806 /* FIXME: Can we avoid using these two interfaces? */
4807 static int mdt_init_export(struct obd_export *exp)
4809 struct mdt_export_data *med = &exp->exp_mdt_data;
4813 CFS_INIT_LIST_HEAD(&med->med_open_head);
4814 spin_lock_init(&med->med_open_lock);
4815 sema_init(&med->med_idmap_sem, 1);
4816 med->med_idmap = NULL;
4817 spin_lock(&exp->exp_lock);
4818 exp->exp_connecting = 1;
4819 spin_unlock(&exp->exp_lock);
4820 rc = ldlm_init_export(exp);
4822 CERROR("Error %d while initializing export\n", rc);
4826 static int mdt_destroy_export(struct obd_export *export)
4828 struct mdt_export_data *med;
4829 struct obd_device *obd = export->exp_obd;
4830 struct mdt_device *mdt;
4831 struct mdt_thread_info *info;
4836 CFS_LIST_HEAD(closing_list);
4837 struct mdt_file_data *mfd, *n;
4841 med = &export->exp_mdt_data;
4842 if (exp_connect_rmtclient(export))
4843 mdt_cleanup_idmap(med);
4845 target_destroy_export(export);
4846 ldlm_destroy_export(export);
4848 if (obd_uuid_equals(&export->exp_client_uuid, &obd->obd_uuid))
4851 mdt = mdt_dev(obd->obd_lu_dev);
4852 LASSERT(mdt != NULL);
4854 rc = lu_env_init(&env, LCT_MD_THREAD);
4858 info = lu_context_key_get(&env.le_ctx, &mdt_thread_key);
4859 LASSERT(info != NULL);
4860 memset(info, 0, sizeof *info);
4861 info->mti_env = &env;
4862 info->mti_mdt = mdt;
4863 info->mti_exp = export;
4865 ma = &info->mti_attr;
4866 lmm_size = ma->ma_lmm_size = mdt->mdt_max_mdsize;
4867 cookie_size = ma->ma_cookie_size = mdt->mdt_max_cookiesize;
4868 OBD_ALLOC(ma->ma_lmm, lmm_size);
4869 OBD_ALLOC(ma->ma_cookie, cookie_size);
4871 if (ma->ma_lmm == NULL || ma->ma_cookie == NULL)
4872 GOTO(out, rc = -ENOMEM);
4873 ma->ma_need = MA_LOV | MA_COOKIE;
4875 /* Close any open files (which may also cause orphan unlinking). */
4876 spin_lock(&med->med_open_lock);
4877 while (!list_empty(&med->med_open_head)) {
4878 struct list_head *tmp = med->med_open_head.next;
4879 mfd = list_entry(tmp, struct mdt_file_data, mfd_list);
4881 /* Remove mfd handle so it can't be found again.
4882 * We are consuming the mfd_list reference here. */
4883 class_handle_unhash(&mfd->mfd_handle);
4884 list_move_tail(&mfd->mfd_list, &closing_list);
4886 spin_unlock(&med->med_open_lock);
4888 list_for_each_entry_safe(mfd, n, &closing_list, mfd_list) {
4889 list_del_init(&mfd->mfd_list);
4890 mdt_mfd_close(info, mfd);
4891 /* TODO: if we close the unlinked file,
4892 * we need to remove its objects from OST */
4893 memset(&ma->ma_attr, 0, sizeof(ma->ma_attr));
4894 spin_lock(&med->med_open_lock);
4895 ma->ma_lmm_size = lmm_size;
4896 ma->ma_cookie_size = cookie_size;
4897 ma->ma_need = MA_LOV | MA_COOKIE;
4899 spin_unlock(&med->med_open_lock);
4902 info->mti_mdt = NULL;
4903 mdt_client_del(&env, mdt);
4908 OBD_FREE(ma->ma_lmm, lmm_size);
4912 OBD_FREE(ma->ma_cookie, cookie_size);
4913 ma->ma_cookie = NULL;
4920 static void mdt_allow_cli(struct mdt_device *m, unsigned int flag)
4922 if (flag & CONFIG_LOG)
4923 m->mdt_fl_cfglog = 1;
4924 if (flag & CONFIG_SYNC)
4925 m->mdt_fl_synced = 1;
4927 if (m->mdt_fl_cfglog /* bz11778: && m->mdt_fl_synced */)
4928 /* Open for clients */
4929 m->mdt_md_dev.md_lu_dev.ld_obd->obd_no_conn = 0;
4932 static int mdt_upcall(const struct lu_env *env, struct md_device *md,
4933 enum md_upcall_event ev)
4935 struct mdt_device *m = mdt_dev(&md->md_lu_dev);
4936 struct md_device *next = m->mdt_child;
4937 struct mdt_thread_info *mti;
4943 rc = next->md_ops->mdo_maxsize_get(env, next,
4945 &m->mdt_max_cookiesize);
4946 CDEBUG(D_INFO, "get max mdsize %d max cookiesize %d\n",
4947 m->mdt_max_mdsize, m->mdt_max_cookiesize);
4948 mdt_allow_cli(m, CONFIG_SYNC);
4949 #ifdef HAVE_QUOTA_SUPPORT
4950 if (md->md_lu_dev.ld_obd->obd_recovering == 0)
4951 next->md_ops->mdo_quota.mqo_recovery(env, next);
4955 mti = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
4956 mti->mti_no_need_trans = 1;
4957 CDEBUG(D_INFO, "disable mdt trans for this thread\n");
4960 /* Check that MDT is not yet configured */
4961 LASSERT(!m->mdt_fl_cfglog);
4964 CERROR("invalid event\n");
4971 static int mdt_obd_notify(struct obd_device *host,
4972 struct obd_device *watched,
4973 enum obd_notify_event ev, void *data)
4975 struct mdt_device *mdt = mdt_dev(host->obd_lu_dev);
4976 #ifdef HAVE_QUOTA_SUPPORT
4977 struct md_device *next = mdt->mdt_child;
4982 case OBD_NOTIFY_CONFIG:
4983 mdt_allow_cli(mdt, (unsigned long)data);
4985 #ifdef HAVE_QUOTA_SUPPORT
4986 /* quota_type has been processed, we can now handle
4987 * incoming quota requests */
4988 next->md_ops->mdo_quota.mqo_notify(NULL, next);
4992 CDEBUG(D_INFO, "Unhandled notification %#x\n", ev);
4997 static int mdt_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
4998 void *karg, void *uarg)
5001 struct obd_device *obd= exp->exp_obd;
5002 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
5003 struct dt_device *dt = mdt->mdt_bottom;
5007 CDEBUG(D_IOCTL, "handling ioctl cmd %#x\n", cmd);
5008 rc = lu_env_init(&env, LCT_MD_THREAD);
5014 rc = mdt_device_sync(&env, mdt);
5016 case OBD_IOC_SET_READONLY:
5017 dt->dd_ops->dt_ro(&env, dt);
5019 case OBD_IOC_ABORT_RECOVERY:
5020 CERROR("Aborting recovery for device %s\n", obd->obd_name);
5021 target_stop_recovery_thread(obd);
5025 CERROR("Not supported cmd = %d for device %s\n",
5026 cmd, obd->obd_name);
5034 int mdt_postrecov(const struct lu_env *env, struct mdt_device *mdt)
5036 struct lu_device *ld = md2lu_dev(mdt->mdt_child);
5037 struct obd_device *obd = mdt2obd_dev(mdt);
5038 #ifdef HAVE_QUOTA_SUPPORT
5039 struct md_device *next = mdt->mdt_child;
5043 /* if some clients didn't participate in recovery then we can possibly
5044 * lost sequence. Now we should increase sequence for safe value */
5045 lost = obd->obd_max_recoverable_clients - obd->obd_connected_clients;
5046 mdt_seq_adjust(env, mdt, lost);
5048 rc = ld->ld_ops->ldo_recovery_complete(env, ld);
5049 #ifdef HAVE_QUOTA_SUPPORT
5050 next->md_ops->mdo_quota.mqo_recovery(env, next);
5055 int mdt_obd_postrecov(struct obd_device *obd)
5060 rc = lu_env_init(&env, LCT_MD_THREAD);
5063 rc = mdt_postrecov(&env, mdt_dev(obd->obd_lu_dev));
5068 static struct obd_ops mdt_obd_device_ops = {
5069 .o_owner = THIS_MODULE,
5070 .o_connect = mdt_obd_connect,
5071 .o_reconnect = mdt_obd_reconnect,
5072 .o_disconnect = mdt_obd_disconnect,
5073 .o_init_export = mdt_init_export,
5074 .o_destroy_export = mdt_destroy_export,
5075 .o_iocontrol = mdt_iocontrol,
5076 .o_postrecov = mdt_obd_postrecov,
5077 .o_notify = mdt_obd_notify
5080 static struct lu_device* mdt_device_fini(const struct lu_env *env,
5081 struct lu_device *d)
5083 struct mdt_device *m = mdt_dev(d);
5090 static struct lu_device *mdt_device_free(const struct lu_env *env,
5091 struct lu_device *d)
5093 struct mdt_device *m = mdt_dev(d);
5096 md_device_fini(&m->mdt_md_dev);
5101 static struct lu_device *mdt_device_alloc(const struct lu_env *env,
5102 struct lu_device_type *t,
5103 struct lustre_cfg *cfg)
5105 struct lu_device *l;
5106 struct mdt_device *m;
5112 l = &m->mdt_md_dev.md_lu_dev;
5113 rc = mdt_init0(env, m, t, cfg);
5115 mdt_device_free(env, l);
5119 md_upcall_init(&m->mdt_md_dev, mdt_upcall);
5121 l = ERR_PTR(-ENOMEM);
5125 /* context key constructor/destructor: mdt_key_init, mdt_key_fini */
5126 LU_KEY_INIT_FINI(mdt, struct mdt_thread_info);
5128 /* context key: mdt_thread_key */
5129 LU_CONTEXT_KEY_DEFINE(mdt, LCT_MD_THREAD);
5131 /* context key constructor/destructor: mdt_txn_key_init, mdt_txn_key_fini */
5132 LU_KEY_INIT_FINI(mdt_txn, struct mdt_txn_info);
5134 struct lu_context_key mdt_txn_key = {
5135 .lct_tags = LCT_TX_HANDLE,
5136 .lct_init = mdt_txn_key_init,
5137 .lct_fini = mdt_txn_key_fini
5140 struct md_ucred *mdt_ucred(const struct mdt_thread_info *info)
5142 return md_ucred(info->mti_env);
5146 * Enable/disable COS.
5148 * Set/Clear the COS flag in mdt options.
5150 * \param mdt mdt device
5151 * \param val 0 disables COS, other values enable COS
5153 void mdt_enable_cos(struct mdt_device *mdt, int val)
5158 mdt->mdt_opts.mo_cos = !!val;
5159 rc = lu_env_init(&env, LCT_MD_THREAD);
5160 if (unlikely(rc != 0)) {
5161 CWARN("lu_env initialization failed with rc = %d,"
5162 "cannot sync\n", rc);
5165 mdt_device_sync(&env, mdt);
5172 * Return COS flag status/
5174 * \param mdt mdt device
5176 int mdt_cos_is_enabled(struct mdt_device *mdt)
5178 return mdt->mdt_opts.mo_cos != 0;
5181 /* type constructor/destructor: mdt_type_init, mdt_type_fini */
5182 LU_TYPE_INIT_FINI(mdt, &mdt_thread_key, &mdt_txn_key);
5184 static struct lu_device_type_operations mdt_device_type_ops = {
5185 .ldto_init = mdt_type_init,
5186 .ldto_fini = mdt_type_fini,
5188 .ldto_start = mdt_type_start,
5189 .ldto_stop = mdt_type_stop,
5191 .ldto_device_alloc = mdt_device_alloc,
5192 .ldto_device_free = mdt_device_free,
5193 .ldto_device_fini = mdt_device_fini
5196 static struct lu_device_type mdt_device_type = {
5197 .ldt_tags = LU_DEVICE_MD,
5198 .ldt_name = LUSTRE_MDT_NAME,
5199 .ldt_ops = &mdt_device_type_ops,
5200 .ldt_ctx_tags = LCT_MD_THREAD
5203 static int __init mdt_mod_init(void)
5205 struct lprocfs_static_vars lvars;
5208 mdt_num_threads = MDT_NUM_THREADS;
5209 lprocfs_mdt_init_vars(&lvars);
5210 rc = class_register_type(&mdt_obd_device_ops, NULL,
5211 lvars.module_vars, LUSTRE_MDT_NAME,
5217 static void __exit mdt_mod_exit(void)
5219 class_unregister_type(LUSTRE_MDT_NAME);
5223 #define DEF_HNDL(prefix, base, suffix, flags, opc, fn, fmt) \
5224 [prefix ## _ ## opc - prefix ## _ ## base] = { \
5226 .mh_fail_id = OBD_FAIL_ ## prefix ## _ ## opc ## suffix, \
5227 .mh_opc = prefix ## _ ## opc, \
5228 .mh_flags = flags, \
5233 #define DEF_MDT_HNDL(flags, name, fn, fmt) \
5234 DEF_HNDL(MDS, GETATTR, _NET, flags, name, fn, fmt)
5236 #define DEF_SEQ_HNDL(flags, name, fn, fmt) \
5237 DEF_HNDL(SEQ, QUERY, _NET, flags, name, fn, fmt)
5239 #define DEF_FLD_HNDL(flags, name, fn, fmt) \
5240 DEF_HNDL(FLD, QUERY, _NET, flags, name, fn, fmt)
5242 * Request with a format known in advance
5244 #define DEF_MDT_HNDL_F(flags, name, fn) \
5245 DEF_HNDL(MDS, GETATTR, _NET, flags, name, fn, &RQF_MDS_ ## name)
5247 #define DEF_SEQ_HNDL_F(flags, name, fn) \
5248 DEF_HNDL(SEQ, QUERY, _NET, flags, name, fn, &RQF_SEQ_ ## name)
5250 #define DEF_FLD_HNDL_F(flags, name, fn) \
5251 DEF_HNDL(FLD, QUERY, _NET, flags, name, fn, &RQF_FLD_ ## name)
5253 * Request with a format we do not yet know
5255 #define DEF_MDT_HNDL_0(flags, name, fn) \
5256 DEF_HNDL(MDS, GETATTR, _NET, flags, name, fn, NULL)
5258 static struct mdt_handler mdt_mds_ops[] = {
5259 DEF_MDT_HNDL_F(0, CONNECT, mdt_connect),
5260 DEF_MDT_HNDL_F(0, DISCONNECT, mdt_disconnect),
5261 DEF_MDT_HNDL_F(0, SET_INFO, mdt_set_info),
5262 DEF_MDT_HNDL_F(0 |HABEO_REFERO, GETSTATUS, mdt_getstatus),
5263 DEF_MDT_HNDL_F(HABEO_CORPUS, GETATTR, mdt_getattr),
5264 DEF_MDT_HNDL_F(HABEO_CORPUS|HABEO_REFERO, GETATTR_NAME, mdt_getattr_name),
5265 DEF_MDT_HNDL_F(HABEO_CORPUS, GETXATTR, mdt_getxattr),
5266 DEF_MDT_HNDL_F(0 |HABEO_REFERO, STATFS, mdt_statfs),
5267 DEF_MDT_HNDL_F(0 |MUTABOR, REINT, mdt_reint),
5268 DEF_MDT_HNDL_F(HABEO_CORPUS, CLOSE, mdt_close),
5269 DEF_MDT_HNDL_F(HABEO_CORPUS, DONE_WRITING, mdt_done_writing),
5270 DEF_MDT_HNDL_F(0 |HABEO_REFERO, PIN, mdt_pin),
5271 DEF_MDT_HNDL_0(0, SYNC, mdt_sync),
5272 DEF_MDT_HNDL_F(HABEO_CORPUS|HABEO_REFERO, IS_SUBDIR, mdt_is_subdir),
5273 #ifdef HAVE_QUOTA_SUPPORT
5274 DEF_MDT_HNDL_F(0, QUOTACHECK, mdt_quotacheck_handle),
5275 DEF_MDT_HNDL_F(0, QUOTACTL, mdt_quotactl_handle)
5279 #define DEF_OBD_HNDL(flags, name, fn) \
5280 DEF_HNDL(OBD, PING, _NET, flags, name, fn, NULL)
5283 static struct mdt_handler mdt_obd_ops[] = {
5284 DEF_OBD_HNDL(0, PING, mdt_obd_ping),
5285 DEF_OBD_HNDL(0, LOG_CANCEL, mdt_obd_log_cancel),
5286 DEF_OBD_HNDL(0, QC_CALLBACK, mdt_obd_qc_callback)
5289 #define DEF_DLM_HNDL_0(flags, name, fn) \
5290 DEF_HNDL(LDLM, ENQUEUE, , flags, name, fn, NULL)
5291 #define DEF_DLM_HNDL_F(flags, name, fn) \
5292 DEF_HNDL(LDLM, ENQUEUE, , flags, name, fn, &RQF_LDLM_ ## name)
5294 static struct mdt_handler mdt_dlm_ops[] = {
5295 DEF_DLM_HNDL_F(HABEO_CLAVIS, ENQUEUE, mdt_enqueue),
5296 DEF_DLM_HNDL_0(HABEO_CLAVIS, CONVERT, mdt_convert),
5297 DEF_DLM_HNDL_0(0, BL_CALLBACK, mdt_bl_callback),
5298 DEF_DLM_HNDL_0(0, CP_CALLBACK, mdt_cp_callback)
5301 static struct mdt_handler mdt_llog_ops[] = {
5304 #define DEF_SEC_CTX_HNDL(name, fn) \
5305 DEF_HNDL(SEC_CTX, INIT, _NET, 0, name, fn, NULL)
5307 static struct mdt_handler mdt_sec_ctx_ops[] = {
5308 DEF_SEC_CTX_HNDL(INIT, mdt_sec_ctx_handle),
5309 DEF_SEC_CTX_HNDL(INIT_CONT, mdt_sec_ctx_handle),
5310 DEF_SEC_CTX_HNDL(FINI, mdt_sec_ctx_handle)
5313 static struct mdt_opc_slice mdt_regular_handlers[] = {
5315 .mos_opc_start = MDS_GETATTR,
5316 .mos_opc_end = MDS_LAST_OPC,
5317 .mos_hs = mdt_mds_ops
5320 .mos_opc_start = OBD_PING,
5321 .mos_opc_end = OBD_LAST_OPC,
5322 .mos_hs = mdt_obd_ops
5325 .mos_opc_start = LDLM_ENQUEUE,
5326 .mos_opc_end = LDLM_LAST_OPC,
5327 .mos_hs = mdt_dlm_ops
5330 .mos_opc_start = LLOG_ORIGIN_HANDLE_CREATE,
5331 .mos_opc_end = LLOG_LAST_OPC,
5332 .mos_hs = mdt_llog_ops
5335 .mos_opc_start = SEC_CTX_INIT,
5336 .mos_opc_end = SEC_LAST_OPC,
5337 .mos_hs = mdt_sec_ctx_ops
5344 static struct mdt_handler mdt_readpage_ops[] = {
5345 DEF_MDT_HNDL_F(0, CONNECT, mdt_connect),
5346 DEF_MDT_HNDL_F(HABEO_CORPUS|HABEO_REFERO, READPAGE, mdt_readpage),
5347 #ifdef HAVE_SPLIT_SUPPORT
5348 DEF_MDT_HNDL_F(HABEO_CORPUS|HABEO_REFERO, WRITEPAGE, mdt_writepage),
5352 * XXX: this is ugly and should be fixed one day, see mdc_close() for
5353 * detailed comments. --umka
5355 DEF_MDT_HNDL_F(HABEO_CORPUS, CLOSE, mdt_close),
5356 DEF_MDT_HNDL_F(HABEO_CORPUS, DONE_WRITING, mdt_done_writing),
5359 static struct mdt_opc_slice mdt_readpage_handlers[] = {
5361 .mos_opc_start = MDS_GETATTR,
5362 .mos_opc_end = MDS_LAST_OPC,
5363 .mos_hs = mdt_readpage_ops
5370 static struct mdt_handler mdt_xmds_ops[] = {
5371 DEF_MDT_HNDL_F(0, CONNECT, mdt_connect),
5372 DEF_MDT_HNDL_F(HABEO_CORPUS , GETATTR, mdt_getattr),
5373 DEF_MDT_HNDL_F(0 | MUTABOR , REINT, mdt_reint),
5374 DEF_MDT_HNDL_F(HABEO_CORPUS|HABEO_REFERO, IS_SUBDIR, mdt_is_subdir),
5377 static struct mdt_opc_slice mdt_xmds_handlers[] = {
5379 .mos_opc_start = MDS_GETATTR,
5380 .mos_opc_end = MDS_LAST_OPC,
5381 .mos_hs = mdt_xmds_ops
5384 .mos_opc_start = OBD_PING,
5385 .mos_opc_end = OBD_LAST_OPC,
5386 .mos_hs = mdt_obd_ops
5389 .mos_opc_start = SEC_CTX_INIT,
5390 .mos_opc_end = SEC_LAST_OPC,
5391 .mos_hs = mdt_sec_ctx_ops
5398 static struct mdt_handler mdt_seq_ops[] = {
5399 DEF_SEQ_HNDL_F(0, QUERY, (int (*)(struct mdt_thread_info *))seq_query)
5402 static struct mdt_opc_slice mdt_seq_handlers[] = {
5404 .mos_opc_start = SEQ_QUERY,
5405 .mos_opc_end = SEQ_LAST_OPC,
5406 .mos_hs = mdt_seq_ops
5413 static struct mdt_handler mdt_fld_ops[] = {
5414 DEF_FLD_HNDL_F(0, QUERY, (int (*)(struct mdt_thread_info *))fld_query)
5417 static struct mdt_opc_slice mdt_fld_handlers[] = {
5419 .mos_opc_start = FLD_QUERY,
5420 .mos_opc_end = FLD_LAST_OPC,
5421 .mos_hs = mdt_fld_ops
5428 MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");
5429 MODULE_DESCRIPTION("Lustre Meta-data Target ("LUSTRE_MDT_NAME")");
5430 MODULE_LICENSE("GPL");
5432 CFS_MODULE_PARM(mdt_num_threads, "ul", ulong, 0444,
5433 "number of mdt service threads to start");
5435 cfs_module(mdt, "0.2.0", mdt_mod_init, mdt_mod_exit);