1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * lustre/mdt/mdt_handler.c
5 * Lustre Metadata Target (mdt) request handler
7 * Copyright (c) 2006 Cluster File Systems, Inc.
8 * Author: Peter Braam <braam@clusterfs.com>
9 * Author: Andreas Dilger <adilger@clusterfs.com>
10 * Author: Phil Schwan <phil@clusterfs.com>
11 * Author: Mike Shaver <shaver@clusterfs.com>
12 * Author: Nikita Danilov <nikita@clusterfs.com>
13 * Author: Huang Hua <huanghua@clusterfs.com>
14 * Author: Yury Umanets <umka@clusterfs.com>
16 * This file is part of the Lustre file system, http://www.lustre.org
17 * Lustre is a trademark of Cluster File Systems, Inc.
19 * You may have signed or agreed to another license before downloading
20 * this software. If so, you are bound by the terms and conditions
21 * of that agreement, and the following does not apply to you. See the
22 * LICENSE file included with this distribution for more information.
24 * If you did not agree to a different license, then this copy of Lustre
25 * is open source software; you can redistribute it and/or modify it
26 * under the terms of version 2 of the GNU General Public License as
27 * published by the Free Software Foundation.
29 * In either case, Lustre is distributed in the hope that it will be
30 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
31 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32 * license text for more details.
36 # define EXPORT_SYMTAB
38 #define DEBUG_SUBSYSTEM S_MDS
40 #include <linux/module.h>
42 * struct OBD_{ALLOC,FREE}*()
44 #include <obd_support.h>
45 /* struct ptlrpc_request */
46 #include <lustre_net.h>
47 /* struct obd_export */
48 #include <lustre_export.h>
49 /* struct obd_device */
52 #include <dt_object.h>
53 #include <lustre_mds.h>
54 #include <lustre_mdt.h>
55 #include "mdt_internal.h"
56 #include <linux/lustre_acl.h>
57 #include <lustre_param.h>
59 mdl_mode_t mdt_mdl_lock_modes[] = {
60 [LCK_MINMODE] = MDL_MINMODE,
67 [LCK_GROUP] = MDL_GROUP
70 ldlm_mode_t mdt_dlm_lock_modes[] = {
71 [MDL_MINMODE] = LCK_MINMODE,
78 [MDL_GROUP] = LCK_GROUP
82 * Initialized in mdt_mod_init().
84 unsigned long mdt_num_threads;
86 /* ptlrpc request handler for MDT. All handlers are
87 * grouped into several slices - struct mdt_opc_slice,
88 * and stored in an array - mdt_handlers[].
91 /* The name of this handler. */
93 /* Fail id for this handler, checked at the beginning of this handler*/
95 /* Operation code for this handler */
97 /* flags are listed in enum mdt_handler_flags below. */
99 /* The actual handler function to execute. */
100 int (*mh_act)(struct mdt_thread_info *info);
101 /* Request format for this request. */
102 const struct req_format *mh_fmt;
105 enum mdt_handler_flags {
107 * struct mdt_body is passed in the incoming message, and object
108 * identified by this fid exists on disk.
110 * "habeo corpus" == "I have a body"
112 HABEO_CORPUS = (1 << 0),
114 * struct ldlm_request is passed in the incoming message.
116 * "habeo clavis" == "I have a key"
118 HABEO_CLAVIS = (1 << 1),
120 * this request has fixed reply format, so that reply message can be
121 * packed by generic code.
123 * "habeo refero" == "I have a reply"
125 HABEO_REFERO = (1 << 2),
127 * this request will modify something, so check whether the filesystem
128 * is readonly or not, then return -EROFS to client asap if necessary.
130 * "mutabor" == "I shall modify"
135 struct mdt_opc_slice {
138 struct mdt_handler *mos_hs;
141 static struct mdt_opc_slice mdt_regular_handlers[];
142 static struct mdt_opc_slice mdt_readpage_handlers[];
143 static struct mdt_opc_slice mdt_xmds_handlers[];
144 static struct mdt_opc_slice mdt_seq_handlers[];
145 static struct mdt_opc_slice mdt_fld_handlers[];
147 static struct mdt_device *mdt_dev(struct lu_device *d);
148 static int mdt_regular_handle(struct ptlrpc_request *req);
149 static int mdt_unpack_req_pack_rep(struct mdt_thread_info *info, __u32 flags);
151 static struct lu_object_operations mdt_obj_ops;
153 int mdt_get_disposition(struct ldlm_reply *rep, int flag)
157 return (rep->lock_policy_res1 & flag);
160 void mdt_clear_disposition(struct mdt_thread_info *info,
161 struct ldlm_reply *rep, int flag)
164 info->mti_opdata &= ~flag;
166 rep->lock_policy_res1 &= ~flag;
169 void mdt_set_disposition(struct mdt_thread_info *info,
170 struct ldlm_reply *rep, int flag)
173 info->mti_opdata |= flag;
175 rep->lock_policy_res1 |= flag;
178 void mdt_lock_reg_init(struct mdt_lock_handle *lh, ldlm_mode_t lm)
180 lh->mlh_pdo_hash = 0;
181 lh->mlh_reg_mode = lm;
182 lh->mlh_type = MDT_REG_LOCK;
185 void mdt_lock_pdo_init(struct mdt_lock_handle *lh, ldlm_mode_t lm,
186 const char *name, int namelen)
188 lh->mlh_reg_mode = lm;
189 lh->mlh_type = MDT_PDO_LOCK;
192 LASSERT(namelen > 0);
193 lh->mlh_pdo_hash = full_name_hash(name, namelen);
195 LASSERT(namelen == 0);
196 lh->mlh_pdo_hash = 0ull;
200 static void mdt_lock_pdo_mode(struct mdt_thread_info *info, struct mdt_object *o,
201 struct mdt_lock_handle *lh)
207 * Any dir access needs couple of locks:
209 * 1) on part of dir we gonna take lookup/modify;
211 * 2) on whole dir to protect it from concurrent splitting and/or to
212 * flush client's cache for readdir().
214 * so, for a given mode and object this routine decides what lock mode
215 * to use for lock #2:
217 * 1) if caller's gonna lookup in dir then we need to protect dir from
218 * being splitted only - LCK_CR
220 * 2) if caller's gonna modify dir then we need to protect dir from
221 * being splitted and to flush cache - LCK_CW
223 * 3) if caller's gonna modify dir and that dir seems ready for
224 * splitting then we need to protect it from any type of access
225 * (lookup/modify/split) - LCK_EX --bzzz
228 LASSERT(lh->mlh_reg_mode != LCK_MINMODE);
229 LASSERT(lh->mlh_pdo_mode == LCK_MINMODE);
232 * Ask underlaying level its opinion about preferable PDO lock mode
233 * having access type passed as regular lock mode:
235 * - MDL_MINMODE means that lower layer does not want to specify lock
238 * - MDL_NL means that no PDO lock should be taken. This is used in some
239 * cases. Say, for non-splittable directories no need to use PDO locks
242 mode = mdo_lock_mode(info->mti_env, mdt_object_child(o),
243 mdt_dlm_mode2mdl_mode(lh->mlh_reg_mode));
245 if (mode != MDL_MINMODE) {
246 lh->mlh_pdo_mode = mdt_mdl_mode2dlm_mode(mode);
249 * Lower layer does not want to specify locking mode. We do it
250 * our selves. No special protection is needed, just flush
251 * client's cache on modification and allow concurrent
254 switch (lh->mlh_reg_mode) {
256 lh->mlh_pdo_mode = LCK_EX;
259 lh->mlh_pdo_mode = LCK_CR;
262 lh->mlh_pdo_mode = LCK_CW;
265 CERROR("Not expected lock type (0x%x)\n",
266 (int)lh->mlh_reg_mode);
271 LASSERT(lh->mlh_pdo_mode != LCK_MINMODE);
275 static int mdt_getstatus(struct mdt_thread_info *info)
277 struct mdt_device *mdt = info->mti_mdt;
278 struct md_device *next = mdt->mdt_child;
279 struct mdt_body *repbody;
284 rc = mdt_check_ucred(info);
286 RETURN(err_serious(rc));
288 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_GETSTATUS_PACK))
289 RETURN(err_serious(-ENOMEM));
291 repbody = req_capsule_server_get(&info->mti_pill, &RMF_MDT_BODY);
292 rc = next->md_ops->mdo_root_get(info->mti_env, next, &repbody->fid1);
296 repbody->valid |= OBD_MD_FLID;
298 if (mdt->mdt_opts.mo_mds_capa) {
299 struct mdt_object *root;
300 struct lustre_capa *capa;
302 root = mdt_object_find(info->mti_env, mdt, &repbody->fid1);
304 RETURN(PTR_ERR(root));
306 capa = req_capsule_server_get(&info->mti_pill, &RMF_CAPA1);
308 capa->lc_opc = CAPA_OPC_MDS_DEFAULT;
310 rc = mo_capa_get(info->mti_env, mdt_object_child(root), capa,
312 mdt_object_put(info->mti_env, root);
314 repbody->valid |= OBD_MD_FLMDSCAPA;
320 static int mdt_statfs(struct mdt_thread_info *info)
322 struct md_device *next = info->mti_mdt->mdt_child;
323 struct obd_statfs *osfs;
328 /* This will trigger a watchdog timeout */
329 OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_STATFS_LCW_SLEEP,
330 (MDT_SERVICE_WATCHDOG_TIMEOUT / 1000) + 1);
332 rc = mdt_check_ucred(info);
334 RETURN(err_serious(rc));
336 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_STATFS_PACK)) {
337 rc = err_serious(-ENOMEM);
339 osfs = req_capsule_server_get(&info->mti_pill,&RMF_OBD_STATFS);
340 rc = next->md_ops->mdo_statfs(info->mti_env, next,
342 statfs_pack(osfs, &info->mti_u.ksfs);
347 void mdt_pack_size2body(struct mdt_thread_info *info, struct mdt_object *o)
350 struct lu_attr *attr = &info->mti_attr.ma_attr;
352 b = req_capsule_server_get(&info->mti_pill, &RMF_MDT_BODY);
354 /* Check if Size-on-MDS is enabled. */
355 if ((mdt_conn_flags(info) & OBD_CONNECT_SOM) &&
356 S_ISREG(attr->la_mode) && mdt_sizeonmds_enabled(o)) {
357 b->valid |= (OBD_MD_FLSIZE | OBD_MD_FLBLOCKS);
358 b->size = attr->la_size;
359 b->blocks = attr->la_blocks;
363 void mdt_pack_attr2body(struct mdt_thread_info *info, struct mdt_body *b,
364 const struct lu_attr *attr, const struct lu_fid *fid)
366 /*XXX should pack the reply body according to lu_valid*/
367 b->valid |= OBD_MD_FLCTIME | OBD_MD_FLUID |
368 OBD_MD_FLGID | OBD_MD_FLTYPE |
369 OBD_MD_FLMODE | OBD_MD_FLNLINK | OBD_MD_FLFLAGS |
370 OBD_MD_FLATIME | OBD_MD_FLMTIME ;
372 if (!S_ISREG(attr->la_mode))
373 b->valid |= OBD_MD_FLSIZE | OBD_MD_FLBLOCKS | OBD_MD_FLRDEV;
375 b->atime = attr->la_atime;
376 b->mtime = attr->la_mtime;
377 b->ctime = attr->la_ctime;
378 b->mode = attr->la_mode;
379 b->size = attr->la_size;
380 b->blocks = attr->la_blocks;
381 b->uid = attr->la_uid;
382 b->gid = attr->la_gid;
383 b->flags = attr->la_flags;
384 b->nlink = attr->la_nlink;
385 b->rdev = attr->la_rdev;
389 b->valid |= OBD_MD_FLID;
390 CDEBUG(D_INODE, ""DFID": nlink=%d, mode=%o, size="LPU64"\n",
391 PFID(fid), b->nlink, b->mode, b->size);
395 mdt_body_reverse_idmap(info, b);
398 static inline int mdt_body_has_lov(const struct lu_attr *la,
399 const struct mdt_body *body)
401 return ((S_ISREG(la->la_mode) && (body->valid & OBD_MD_FLEASIZE)) ||
402 (S_ISDIR(la->la_mode) && (body->valid & OBD_MD_FLDIREA )) );
405 static int mdt_getattr_internal(struct mdt_thread_info *info,
406 struct mdt_object *o)
408 struct md_object *next = mdt_object_child(o);
409 const struct mdt_body *reqbody = info->mti_body;
410 struct ptlrpc_request *req = mdt_info_req(info);
411 struct mdt_export_data *med = &req->rq_export->exp_mdt_data;
412 struct md_attr *ma = &info->mti_attr;
413 struct lu_attr *la = &ma->ma_attr;
414 struct req_capsule *pill = &info->mti_pill;
415 const struct lu_env *env = info->mti_env;
416 struct mdt_body *repbody;
417 struct lu_buf *buffer = &info->mti_buf;
421 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_GETATTR_PACK))
422 RETURN(err_serious(-ENOMEM));
424 repbody = req_capsule_server_get(pill, &RMF_MDT_BODY);
428 rc = mdt_object_exists(o);
430 /* This object is located on remote node.*/
431 repbody->fid1 = *mdt_object_fid(o);
432 repbody->valid = OBD_MD_FLID | OBD_MD_MDS;
436 buffer->lb_buf = req_capsule_server_get(pill, &RMF_MDT_MD);
437 buffer->lb_len = req_capsule_get_size(pill, &RMF_MDT_MD, RCL_SERVER);
439 /* If it is dir object and client require MEA, then we got MEA */
440 if (S_ISDIR(lu_object_attr(&next->mo_lu)) &&
441 reqbody->valid & OBD_MD_MEA) {
442 /* Assumption: MDT_MD size is enough for lmv size. */
443 ma->ma_lmv = buffer->lb_buf;
444 ma->ma_lmv_size = buffer->lb_len;
445 ma->ma_need = MA_LMV | MA_INODE;
447 ma->ma_lmm = buffer->lb_buf;
448 ma->ma_lmm_size = buffer->lb_len;
449 ma->ma_need = MA_LOV | MA_INODE;
452 if (S_ISDIR(lu_object_attr(&next->mo_lu)) &&
453 reqbody->valid & OBD_MD_FLDIREA &&
454 lustre_msg_get_opc(req->rq_reqmsg) == MDS_GETATTR) {
455 /* get default stripe info for this dir. */
456 ma->ma_need |= MA_LOV_DEF;
458 rc = mo_attr_get(env, next, ma);
460 CERROR("getattr error for "DFID": %d\n",
461 PFID(mdt_object_fid(o)), rc);
465 if (likely(ma->ma_valid & MA_INODE))
466 mdt_pack_attr2body(info, repbody, la, mdt_object_fid(o));
470 if (mdt_body_has_lov(la, reqbody)) {
471 if (ma->ma_valid & MA_LOV) {
472 LASSERT(ma->ma_lmm_size);
473 mdt_dump_lmm(D_INFO, ma->ma_lmm);
474 repbody->eadatasize = ma->ma_lmm_size;
475 if (S_ISDIR(la->la_mode))
476 repbody->valid |= OBD_MD_FLDIREA;
478 repbody->valid |= OBD_MD_FLEASIZE;
480 if (ma->ma_valid & MA_LMV) {
481 LASSERT(S_ISDIR(la->la_mode));
482 repbody->eadatasize = ma->ma_lmv_size;
483 repbody->valid |= (OBD_MD_FLDIREA|OBD_MD_MEA);
485 if (!(ma->ma_valid & MA_LOV) && !(ma->ma_valid & MA_LMV)) {
486 repbody->valid |= OBD_MD_FLSIZE | OBD_MD_FLBLOCKS;
488 } else if (S_ISLNK(la->la_mode) &&
489 reqbody->valid & OBD_MD_LINKNAME) {
490 buffer->lb_buf = ma->ma_lmm;
491 buffer->lb_len = reqbody->eadatasize;
492 rc = mo_readlink(env, next, buffer);
493 if (unlikely(rc <= 0)) {
494 CERROR("readlink failed: %d\n", rc);
497 repbody->valid |= OBD_MD_LINKNAME;
498 repbody->eadatasize = rc;
500 ((char*)ma->ma_lmm)[rc - 1] = 0;
501 CDEBUG(D_INODE, "symlink dest %s, len = %d\n",
502 (char*)ma->ma_lmm, rc);
507 if (reqbody->valid & OBD_MD_FLMODEASIZE) {
508 repbody->max_cookiesize = info->mti_mdt->mdt_max_cookiesize;
509 repbody->max_mdsize = info->mti_mdt->mdt_max_mdsize;
510 repbody->valid |= OBD_MD_FLMODEASIZE;
511 CDEBUG(D_INODE, "I am going to change the MAX_MD_SIZE & "
512 "MAX_COOKIE to : %d:%d\n", repbody->max_mdsize,
513 repbody->max_cookiesize);
516 if (med->med_rmtclient && (reqbody->valid & OBD_MD_FLRMTPERM)) {
517 void *buf = req_capsule_server_get(pill, &RMF_ACL);
519 /* mdt_getattr_lock only */
520 rc = mdt_pack_remote_perm(info, o, buf);
522 repbody->valid &= ~OBD_MD_FLRMTPERM;
523 repbody->aclsize = 0;
526 repbody->valid |= OBD_MD_FLRMTPERM;
527 repbody->aclsize = sizeof(struct mdt_remote_perm);
530 #ifdef CONFIG_FS_POSIX_ACL
531 else if ((req->rq_export->exp_connect_flags & OBD_CONNECT_ACL) &&
532 (reqbody->valid & OBD_MD_FLACL)) {
533 buffer->lb_buf = req_capsule_server_get(pill, &RMF_ACL);
534 buffer->lb_len = req_capsule_get_size(pill,
535 &RMF_ACL, RCL_SERVER);
536 if (buffer->lb_len > 0) {
537 rc = mo_xattr_get(env, next, buffer,
538 XATTR_NAME_ACL_ACCESS);
540 if (rc == -ENODATA) {
541 repbody->aclsize = 0;
542 repbody->valid |= OBD_MD_FLACL;
544 } else if (rc == -EOPNOTSUPP) {
547 CERROR("got acl size: %d\n", rc);
550 repbody->aclsize = rc;
551 repbody->valid |= OBD_MD_FLACL;
558 if ((reqbody->valid & OBD_MD_FLMDSCAPA) &&
559 info->mti_mdt->mdt_opts.mo_mds_capa) {
560 struct lustre_capa *capa;
562 capa = req_capsule_server_get(&info->mti_pill, &RMF_CAPA1);
564 capa->lc_opc = CAPA_OPC_MDS_DEFAULT;
565 rc = mo_capa_get(env, next, capa, 0);
568 repbody->valid |= OBD_MD_FLMDSCAPA;
573 static int mdt_renew_capa(struct mdt_thread_info *info)
575 struct mdt_device *mdt = info->mti_mdt;
576 struct mdt_object *obj = info->mti_object;
577 struct mdt_body *body;
578 struct lustre_capa *capa, *c;
582 /* if object doesn't exist, or server has disabled capability,
583 * return directly, client will find body->valid OBD_MD_FLOSSCAPA
586 if (!obj || !mdt->mdt_opts.mo_mds_capa)
589 body = req_capsule_server_get(&info->mti_pill, &RMF_MDT_BODY);
590 LASSERT(body != NULL);
592 c = req_capsule_client_get(&info->mti_pill, &RMF_CAPA1);
595 capa = req_capsule_server_get(&info->mti_pill, &RMF_CAPA1);
599 rc = mo_capa_get(info->mti_env, mdt_object_child(obj), capa, 1);
601 body->valid |= OBD_MD_FLOSSCAPA;
606 static int mdt_getattr(struct mdt_thread_info *info)
608 struct mdt_object *obj = info->mti_object;
609 struct req_capsule *pill = &info->mti_pill;
610 struct mdt_body *reqbody;
611 struct mdt_body *repbody;
617 reqbody = req_capsule_client_get(pill, &RMF_MDT_BODY);
620 if (reqbody->valid & OBD_MD_FLOSSCAPA) {
621 rc = req_capsule_pack(pill);
623 rc = err_serious(rc);
625 rc = mdt_renew_capa(info);
626 mdt_shrink_reply(info);
631 LASSERT(obj != NULL);
632 LASSERT(lu_object_assert_exists(&obj->mot_obj.mo_lu));
634 mode = lu_object_attr(&obj->mot_obj.mo_lu);
635 if (S_ISLNK(mode) && (reqbody->valid & OBD_MD_LINKNAME) &&
636 (reqbody->eadatasize > info->mti_mdt->mdt_max_mdsize))
637 md_size = reqbody->eadatasize;
639 md_size = info->mti_mdt->mdt_max_mdsize;
641 req_capsule_set_size(pill, &RMF_MDT_MD, RCL_SERVER, md_size);
643 rc = req_capsule_pack(pill);
644 if (unlikely(rc != 0))
645 GOTO(out, rc = err_serious(rc));
647 repbody = req_capsule_server_get(pill, &RMF_MDT_BODY);
648 LASSERT(repbody != NULL);
649 repbody->eadatasize = 0;
650 repbody->aclsize = 0;
652 if (reqbody->valid & OBD_MD_FLRMTPERM)
653 rc = mdt_init_ucred(info, reqbody);
655 rc = mdt_check_ucred(info);
657 GOTO(out_shrink, rc);
659 info->mti_spec.sp_ck_split = !!(reqbody->valid & OBD_MD_FLCKSPLIT);
660 info->mti_cross_ref = !!(reqbody->valid & OBD_MD_FLCROSSREF);
663 * Don't check capability at all, because rename might getattr for
664 * remote obj, and at that time no capability is available.
666 mdt_set_capainfo(info, 1, &reqbody->fid1, BYPASS_CAPA);
667 rc = mdt_getattr_internal(info, obj);
668 if (reqbody->valid & OBD_MD_FLRMTPERM)
669 mdt_exit_ucred(info);
672 mdt_shrink_reply(info);
677 static int mdt_is_subdir(struct mdt_thread_info *info)
679 struct mdt_object *o = info->mti_object;
680 struct req_capsule *pill = &info->mti_pill;
681 const struct mdt_body *body = info->mti_body;
682 struct mdt_body *repbody;
688 repbody = req_capsule_server_get(pill, &RMF_MDT_BODY);
691 * We save last checked parent fid to @repbody->fid1 for remote
694 LASSERT(fid_is_sane(&body->fid2));
695 LASSERT(mdt_object_exists(o) > 0);
696 rc = mdo_is_subdir(info->mti_env, mdt_object_child(o),
697 &body->fid2, &repbody->fid1);
698 if (rc == 0 || rc == -EREMOTE)
699 repbody->valid |= OBD_MD_FLID;
704 static int mdt_raw_lookup(struct mdt_thread_info *info,
705 struct mdt_object *parent,
706 const struct lu_name *lname,
707 struct ldlm_reply *ldlm_rep)
709 struct md_object *next = mdt_object_child(info->mti_object);
710 const struct mdt_body *reqbody = info->mti_body;
711 struct lu_fid *child_fid = &info->mti_tmp_fid1;
712 struct mdt_body *repbody;
716 if (reqbody->valid != OBD_MD_FLID)
719 LASSERT(!info->mti_cross_ref);
721 /* Only got the fid of this obj by name */
722 rc = mdo_lookup(info->mti_env, next, lname, child_fid,
725 /* XXX is raw_lookup possible as intent operation? */
728 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_NEG);
731 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_POS);
733 repbody = req_capsule_server_get(&info->mti_pill, &RMF_MDT_BODY);
736 repbody = req_capsule_server_get(&info->mti_pill,
738 repbody->fid1 = *child_fid;
739 repbody->valid = OBD_MD_FLID;
745 * UPDATE lock should be taken against parent, and be release before exit;
746 * child_bits lock should be taken against child, and be returned back:
747 * (1)normal request should release the child lock;
748 * (2)intent request will grant the lock to client.
750 static int mdt_getattr_name_lock(struct mdt_thread_info *info,
751 struct mdt_lock_handle *lhc,
753 struct ldlm_reply *ldlm_rep)
755 struct ptlrpc_request *req = mdt_info_req(info);
756 struct mdt_body *reqbody = NULL;
757 struct mdt_object *parent = info->mti_object;
758 struct mdt_object *child;
759 struct md_object *next = mdt_object_child(parent);
760 struct lu_fid *child_fid = &info->mti_tmp_fid1;
761 struct lu_name *lname = NULL;
764 struct mdt_lock_handle *lhp;
765 struct ldlm_lock *lock;
766 struct ldlm_res_id *res_id;
772 is_resent = lustre_handle_is_used(&lhc->mlh_reg_lh);
773 LASSERT(ergo(is_resent,
774 lustre_msg_get_flags(req->rq_reqmsg) & MSG_RESENT));
776 LASSERT(parent != NULL);
777 name = req_capsule_client_get(&info->mti_pill, &RMF_NAME);
779 RETURN(err_serious(-EFAULT));
781 namelen = req_capsule_get_size(&info->mti_pill, &RMF_NAME,
783 LASSERT(namelen >= 0);
785 /* XXX: "namelen == 0" is for getattr by fid (OBD_CONNECT_ATTRFID),
786 * otherwise do not allow empty name, that is the name must contain
787 * at least one character and the terminating '\0'*/
789 reqbody =req_capsule_client_get(&info->mti_pill, &RMF_MDT_BODY);
790 LASSERT(fid_is_sane(&reqbody->fid2));
793 CDEBUG(D_INODE, "getattr with lock for "DFID"/"DFID", "
795 PFID(mdt_object_fid(parent)), PFID(&reqbody->fid2),
798 lname = mdt_name(info->mti_env, (char *)name, namelen);
799 CDEBUG(D_INODE, "getattr with lock for "DFID"/%s, "
801 PFID(mdt_object_fid(parent)), name, ldlm_rep);
804 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_EXECD);
806 rc = mdt_object_exists(parent);
807 if (unlikely(rc == 0)) {
808 LU_OBJECT_DEBUG(D_WARNING, info->mti_env,
809 &parent->mot_obj.mo_lu,
810 "Parent doesn't exist!\n");
813 LASSERTF(rc > 0, "Parent "DFID" is on remote server\n",
814 PFID(mdt_object_fid(parent)));
817 rc = mdt_raw_lookup(info, parent, lname, ldlm_rep);
825 if (info->mti_cross_ref) {
826 /* Only getattr on the child. Parent is on another node. */
827 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_POS);
829 CDEBUG(D_INODE, "partial getattr_name child_fid = "DFID", "
830 "ldlm_rep=%p\n", PFID(mdt_object_fid(child)), ldlm_rep);
833 /* Do not take lock for resent case. */
834 lock = ldlm_handle2lock(&lhc->mlh_reg_lh);
835 LASSERTF(lock != NULL, "Invalid lock handle "LPX64"\n",
836 lhc->mlh_reg_lh.cookie);
837 LASSERT(fid_res_name_eq(mdt_object_fid(child),
838 &lock->l_resource->lr_name));
842 mdt_lock_handle_init(lhc);
843 mdt_lock_reg_init(lhc, LCK_PR);
846 * Object's name is on another MDS, no lookup lock is
847 * needed here but update is.
849 child_bits &= ~MDS_INODELOCK_LOOKUP;
850 child_bits |= MDS_INODELOCK_UPDATE;
852 rc = mdt_object_lock(info, child, lhc, child_bits,
856 /* Finally, we can get attr for child. */
857 mdt_set_capainfo(info, 0, mdt_object_fid(child),
859 rc = mdt_getattr_internal(info, child);
860 if (unlikely(rc != 0))
861 mdt_object_unlock(info, child, lhc, 1);
866 /* step 1: lock parent */
867 lhp = &info->mti_lh[MDT_LH_PARENT];
868 mdt_lock_pdo_init(lhp, LCK_PR, name, namelen);
869 rc = mdt_object_lock(info, parent, lhp, MDS_INODELOCK_UPDATE,
872 if (unlikely(rc != 0))
876 /* step 2: lookup child's fid by name */
877 rc = mdo_lookup(info->mti_env, next, lname, child_fid,
882 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_NEG);
883 GOTO(out_parent, rc);
885 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_POS);
887 *child_fid = reqbody->fid2;
888 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_POS);
892 *step 3: find the child object by fid & lock it.
893 * regardless if it is local or remote.
895 child = mdt_object_find(info->mti_env, info->mti_mdt, child_fid);
897 if (unlikely(IS_ERR(child)))
898 GOTO(out_parent, rc = PTR_ERR(child));
900 /* Do not take lock for resent case. */
901 lock = ldlm_handle2lock(&lhc->mlh_reg_lh);
902 LASSERTF(lock != NULL, "Invalid lock handle "LPX64"\n",
903 lhc->mlh_reg_lh.cookie);
905 res_id = &lock->l_resource->lr_name;
906 if (!fid_res_name_eq(mdt_object_fid(child),
907 &lock->l_resource->lr_name)) {
908 LASSERTF(fid_res_name_eq(mdt_object_fid(parent),
909 &lock->l_resource->lr_name),
910 "Lock res_id: %lu/%lu/%lu, Fid: "DFID".\n",
911 (unsigned long)res_id->name[0],
912 (unsigned long)res_id->name[1],
913 (unsigned long)res_id->name[2],
914 PFID(mdt_object_fid(parent)));
915 CWARN("Although resent, but still not get child lock"
916 "parent:"DFID" child:"DFID"\n",
917 PFID(mdt_object_fid(parent)),
918 PFID(mdt_object_fid(child)));
919 lustre_msg_clear_flags(req->rq_reqmsg, MSG_RESENT);
927 mdt_lock_handle_init(lhc);
928 mdt_lock_reg_init(lhc, LCK_PR);
930 if (mdt_object_exists(child) == 0) {
931 LU_OBJECT_DEBUG(D_WARNING, info->mti_env,
932 &child->mot_obj.mo_lu,
933 "Object doesn't exist!\n");
935 rc = mdt_object_lock(info, child, lhc, child_bits,
938 if (unlikely(rc != 0))
942 /* finally, we can get attr for child. */
943 mdt_set_capainfo(info, 1, child_fid, BYPASS_CAPA);
944 rc = mdt_getattr_internal(info, child);
945 if (unlikely(rc != 0)) {
946 mdt_object_unlock(info, child, lhc, 1);
948 lock = ldlm_handle2lock(&lhc->mlh_reg_lh);
950 struct mdt_body *repbody;
953 /* Debugging code. */
954 res_id = &lock->l_resource->lr_name;
955 LDLM_DEBUG(lock, "Returning lock to client\n");
956 LASSERTF(fid_res_name_eq(mdt_object_fid(child),
957 &lock->l_resource->lr_name),
958 "Lock res_id: %lu/%lu/%lu, Fid: "DFID".\n",
959 (unsigned long)res_id->name[0],
960 (unsigned long)res_id->name[1],
961 (unsigned long)res_id->name[2],
962 PFID(mdt_object_fid(child)));
964 * Pack Size-on-MDS inode attributes to the body if
965 * update lock is given.
967 repbody = req_capsule_server_get(&info->mti_pill,
969 ma = &info->mti_attr.ma_attr;
970 if (lock->l_policy_data.l_inodebits.bits &
971 MDS_INODELOCK_UPDATE)
972 mdt_pack_size2body(info, child);
978 mdt_object_put(info->mti_env, child);
980 mdt_object_unlock(info, parent, lhp, 1);
985 /* normal handler: should release the child lock */
986 static int mdt_getattr_name(struct mdt_thread_info *info)
988 struct mdt_lock_handle *lhc = &info->mti_lh[MDT_LH_CHILD];
989 struct mdt_body *reqbody;
990 struct mdt_body *repbody;
994 reqbody = req_capsule_client_get(&info->mti_pill, &RMF_MDT_BODY);
995 LASSERT(reqbody != NULL);
996 repbody = req_capsule_server_get(&info->mti_pill, &RMF_MDT_BODY);
997 LASSERT(repbody != NULL);
999 info->mti_spec.sp_ck_split = !!(reqbody->valid & OBD_MD_FLCKSPLIT);
1000 info->mti_cross_ref = !!(reqbody->valid & OBD_MD_FLCROSSREF);
1001 repbody->eadatasize = 0;
1002 repbody->aclsize = 0;
1004 rc = mdt_init_ucred(info, reqbody);
1008 rc = mdt_getattr_name_lock(info, lhc, MDS_INODELOCK_UPDATE, NULL);
1009 if (lustre_handle_is_used(&lhc->mlh_reg_lh)) {
1010 ldlm_lock_decref(&lhc->mlh_reg_lh, lhc->mlh_reg_mode);
1011 lhc->mlh_reg_lh.cookie = 0;
1013 mdt_exit_ucred(info);
1016 mdt_shrink_reply(info);
1020 static struct lu_device_operations mdt_lu_ops;
1022 static int lu_device_is_mdt(struct lu_device *d)
1024 return ergo(d != NULL && d->ld_ops != NULL, d->ld_ops == &mdt_lu_ops);
1027 static int mdt_set_info(struct mdt_thread_info *info)
1029 struct ptlrpc_request *req = mdt_info_req(info);
1035 rc = lustre_pack_reply(req, 1, NULL, NULL);
1039 key = req_capsule_client_get(&info->mti_pill, &RMF_SETINFO_KEY);
1041 DEBUG_REQ(D_HA, req, "no set_info key");
1045 keylen = req_capsule_get_size(&info->mti_pill, &RMF_SETINFO_KEY,
1048 val = req_capsule_client_get(&info->mti_pill, &RMF_SETINFO_VAL);
1050 DEBUG_REQ(D_HA, req, "no set_info val");
1054 if (keylen != (sizeof(KEY_READ_ONLY) - 1) ||
1055 memcmp(key, KEY_READ_ONLY, keylen) != 0)
1059 lustre_msg_set_status(req->rq_repmsg, 0);
1061 spin_lock(&req->rq_export->exp_lock);
1063 req->rq_export->exp_connect_flags |= OBD_CONNECT_RDONLY;
1065 req->rq_export->exp_connect_flags &= ~OBD_CONNECT_RDONLY;
1066 spin_unlock(&req->rq_export->exp_lock);
1071 static int mdt_connect(struct mdt_thread_info *info)
1074 struct ptlrpc_request *req;
1076 req = mdt_info_req(info);
1077 rc = target_handle_connect(req);
1079 LASSERT(req->rq_export != NULL);
1080 info->mti_mdt = mdt_dev(req->rq_export->exp_obd->obd_lu_dev);
1081 rc = mdt_init_idmap(info);
1083 /* if mdt_init_idmap failed, revocation for connect */
1084 obd_disconnect(class_export_get(req->rq_export));
1086 rc = err_serious(rc);
1090 static int mdt_disconnect(struct mdt_thread_info *info)
1095 rc = target_handle_disconnect(mdt_info_req(info));
1097 rc = err_serious(rc);
1101 static int mdt_sendpage(struct mdt_thread_info *info,
1102 struct lu_rdpg *rdpg)
1104 struct ptlrpc_request *req = mdt_info_req(info);
1105 struct ptlrpc_bulk_desc *desc;
1106 struct l_wait_info *lwi = &info->mti_u.rdpg.mti_wait_info;
1113 desc = ptlrpc_prep_bulk_exp(req, rdpg->rp_npages, BULK_PUT_SOURCE,
1116 GOTO(out, rc = -ENOMEM);
1118 for (i = 0, tmpcount = rdpg->rp_count;
1119 i < rdpg->rp_npages; i++, tmpcount -= tmpsize) {
1120 tmpsize = min_t(int, tmpcount, CFS_PAGE_SIZE);
1121 ptlrpc_prep_bulk_page(desc, rdpg->rp_pages[i], 0, tmpsize);
1124 LASSERT(desc->bd_nob == rdpg->rp_count);
1125 rc = ptlrpc_start_bulk_transfer(desc);
1127 GOTO(free_desc, rc);
1129 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_SENDPAGE))
1130 GOTO(abort_bulk, rc);
1132 *lwi = LWI_TIMEOUT(obd_timeout * HZ / 4, NULL, NULL);
1133 rc = l_wait_event(desc->bd_waitq, !ptlrpc_bulk_active(desc), lwi);
1134 LASSERT (rc == 0 || rc == -ETIMEDOUT);
1137 if (desc->bd_success &&
1138 desc->bd_nob_transferred == rdpg->rp_count)
1139 GOTO(free_desc, rc);
1141 rc = -ETIMEDOUT; /* XXX should this be a different errno? */
1144 DEBUG_REQ(D_ERROR, req, "bulk failed: %s %d(%d), evicting %s@%s",
1145 (rc == -ETIMEDOUT) ? "timeout" : "network error",
1146 desc->bd_nob_transferred, rdpg->rp_count,
1147 req->rq_export->exp_client_uuid.uuid,
1148 req->rq_export->exp_connection->c_remote_uuid.uuid);
1150 class_fail_export(req->rq_export);
1154 ptlrpc_abort_bulk(desc);
1156 ptlrpc_free_bulk(desc);
1161 #ifdef HAVE_SPLIT_SUPPORT
1163 * Retrieve dir entry from the page and insert it to the slave object, actually,
1164 * this should be in osd layer, but since it will not in the final product, so
1165 * just do it here and do not define more moo api anymore for this.
1167 static int mdt_write_dir_page(struct mdt_thread_info *info, struct page *page,
1170 struct mdt_object *object = info->mti_object;
1171 struct lu_fid *lf = &info->mti_tmp_fid2;
1172 struct md_attr *ma = &info->mti_attr;
1173 struct lu_dirpage *dp;
1174 struct lu_dirent *ent;
1175 int rc = 0, offset = 0;
1178 /* Make sure we have at least one entry. */
1183 * Disable trans for this name insert, since it will include many trans
1186 info->mti_no_need_trans = 1;
1188 * When write_dir_page, no need update parent's ctime,
1189 * and no permission check for name_insert.
1191 ma->ma_attr.la_ctime = 0;
1192 ma->ma_attr.la_valid = LA_MODE;
1193 ma->ma_valid = MA_INODE;
1196 dp = page_address(page);
1197 offset = (int)((__u32)lu_dirent_start(dp) - (__u32)dp);
1199 for (ent = lu_dirent_start(dp); ent != NULL;
1200 ent = lu_dirent_next(ent)) {
1201 struct lu_name *lname;
1204 if (le16_to_cpu(ent->lde_namelen) == 0)
1207 fid_le_to_cpu(lf, &ent->lde_fid);
1208 if (le32_to_cpu(ent->lde_hash) & MAX_HASH_HIGHEST_BIT)
1209 ma->ma_attr.la_mode = S_IFDIR;
1211 ma->ma_attr.la_mode = 0;
1212 OBD_ALLOC(name, le16_to_cpu(ent->lde_namelen) + 1);
1214 GOTO(out, rc = -ENOMEM);
1216 memcpy(name, ent->lde_name, le16_to_cpu(ent->lde_namelen));
1217 lname = mdt_name(info->mti_env, name,
1218 le16_to_cpu(ent->lde_namelen) + 1);
1219 ma->ma_attr_flags |= MDS_PERM_BYPASS;
1220 rc = mdo_name_insert(info->mti_env,
1221 md_object_next(&object->mot_obj),
1223 OBD_FREE(name, le16_to_cpu(ent->lde_namelen) + 1);
1225 CERROR("Can't insert %*.*s, rc %d\n",
1226 le16_to_cpu(ent->lde_namelen),
1227 le16_to_cpu(ent->lde_namelen),
1232 offset += lu_dirent_size(ent);
1242 static int mdt_bulk_timeout(void *data)
1246 CERROR("mdt bulk transfer timeout \n");
1251 static int mdt_writepage(struct mdt_thread_info *info)
1253 struct ptlrpc_request *req = mdt_info_req(info);
1254 struct mdt_body *reqbody;
1255 struct l_wait_info *lwi;
1256 struct ptlrpc_bulk_desc *desc;
1262 reqbody = req_capsule_client_get(&info->mti_pill, &RMF_MDT_BODY);
1263 if (reqbody == NULL)
1264 RETURN(err_serious(-EFAULT));
1266 desc = ptlrpc_prep_bulk_exp(req, 1, BULK_GET_SINK, MDS_BULK_PORTAL);
1268 RETURN(err_serious(-ENOMEM));
1270 /* allocate the page for the desc */
1271 page = cfs_alloc_page(CFS_ALLOC_STD);
1273 GOTO(desc_cleanup, rc = -ENOMEM);
1275 CDEBUG(D_INFO, "Received page offset %d size %d \n",
1276 (int)reqbody->size, (int)reqbody->nlink);
1278 ptlrpc_prep_bulk_page(desc, page, (int)reqbody->size,
1279 (int)reqbody->nlink);
1282 * Check if client was evicted while we were doing i/o before touching
1287 GOTO(cleanup_page, rc = -ENOMEM);
1289 if (desc->bd_export->exp_failed)
1292 rc = ptlrpc_start_bulk_transfer (desc);
1294 *lwi = LWI_TIMEOUT_INTERVAL(obd_timeout * HZ / 4, HZ,
1295 mdt_bulk_timeout, desc);
1296 rc = l_wait_event(desc->bd_waitq, !ptlrpc_bulk_active(desc) ||
1297 desc->bd_export->exp_failed, lwi);
1298 LASSERT(rc == 0 || rc == -ETIMEDOUT);
1299 if (rc == -ETIMEDOUT) {
1300 DEBUG_REQ(D_ERROR, req, "timeout on bulk GET");
1301 ptlrpc_abort_bulk(desc);
1302 } else if (desc->bd_export->exp_failed) {
1303 DEBUG_REQ(D_ERROR, req, "Eviction on bulk GET");
1305 ptlrpc_abort_bulk(desc);
1306 } else if (!desc->bd_success ||
1307 desc->bd_nob_transferred != desc->bd_nob) {
1308 DEBUG_REQ(D_ERROR, req, "%s bulk GET %d(%d)",
1310 "truncated" : "network error on",
1311 desc->bd_nob_transferred, desc->bd_nob);
1312 /* XXX should this be a different errno? */
1316 DEBUG_REQ(D_ERROR, req, "ptlrpc_bulk_get failed: rc %d", rc);
1319 GOTO(cleanup_lwi, rc);
1320 rc = mdt_write_dir_page(info, page, reqbody->nlink);
1325 __cfs_free_page(page);
1327 ptlrpc_free_bulk(desc);
1332 static int mdt_readpage(struct mdt_thread_info *info)
1334 struct mdt_object *object = info->mti_object;
1335 struct lu_rdpg *rdpg = &info->mti_u.rdpg.mti_rdpg;
1336 struct mdt_body *reqbody;
1337 struct mdt_body *repbody;
1342 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_READPAGE_PACK))
1343 RETURN(err_serious(-ENOMEM));
1345 reqbody = req_capsule_client_get(&info->mti_pill, &RMF_MDT_BODY);
1346 repbody = req_capsule_server_get(&info->mti_pill, &RMF_MDT_BODY);
1347 if (reqbody == NULL || repbody == NULL)
1348 RETURN(err_serious(-EFAULT));
1351 * prepare @rdpg before calling lower layers and transfer itself. Here
1352 * reqbody->size contains offset of where to start to read and
1353 * reqbody->nlink contains number bytes to read.
1355 rdpg->rp_hash = reqbody->size;
1356 if ((__u64)rdpg->rp_hash != reqbody->size) {
1357 CERROR("Invalid hash: %#llx != %#llx\n",
1358 (__u64)rdpg->rp_hash, reqbody->size);
1361 rdpg->rp_count = reqbody->nlink;
1362 rdpg->rp_npages = (rdpg->rp_count + CFS_PAGE_SIZE - 1)>>CFS_PAGE_SHIFT;
1363 OBD_ALLOC(rdpg->rp_pages, rdpg->rp_npages * sizeof rdpg->rp_pages[0]);
1364 if (rdpg->rp_pages == NULL)
1367 for (i = 0; i < rdpg->rp_npages; ++i) {
1368 rdpg->rp_pages[i] = cfs_alloc_page(CFS_ALLOC_STD);
1369 if (rdpg->rp_pages[i] == NULL)
1370 GOTO(free_rdpg, rc = -ENOMEM);
1373 /* call lower layers to fill allocated pages with directory data */
1374 rc = mo_readpage(info->mti_env, mdt_object_child(object), rdpg);
1376 GOTO(free_rdpg, rc);
1378 /* send pages to client */
1379 rc = mdt_sendpage(info, rdpg);
1384 for (i = 0; i < rdpg->rp_npages; i++)
1385 if (rdpg->rp_pages[i] != NULL)
1386 __cfs_free_page(rdpg->rp_pages[i]);
1387 OBD_FREE(rdpg->rp_pages, rdpg->rp_npages * sizeof rdpg->rp_pages[0]);
1389 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_SENDPAGE))
1395 static int mdt_reint_internal(struct mdt_thread_info *info,
1396 struct mdt_lock_handle *lhc,
1399 struct req_capsule *pill = &info->mti_pill;
1400 struct mdt_device *mdt = info->mti_mdt;
1401 struct mdt_body *repbody;
1402 int need_shrink = 0;
1407 if (req_capsule_has_field(pill, &RMF_MDT_MD, RCL_SERVER)) {
1408 req_capsule_set_size(pill, &RMF_MDT_MD, RCL_SERVER,
1409 mdt->mdt_max_mdsize);
1412 if (req_capsule_has_field(pill, &RMF_LOGCOOKIES, RCL_SERVER)) {
1413 req_capsule_set_size(pill, &RMF_LOGCOOKIES, RCL_SERVER,
1414 mdt->mdt_max_cookiesize);
1417 rc = req_capsule_pack(pill);
1419 CERROR("Can't pack response, rc %d\n", rc);
1420 RETURN(err_serious(rc));
1423 if (req_capsule_has_field(pill, &RMF_MDT_BODY, RCL_SERVER)) {
1424 repbody = req_capsule_server_get(pill, &RMF_MDT_BODY);
1426 repbody->eadatasize = 0;
1427 repbody->aclsize = 0;
1430 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_REINT_UNPACK))
1431 GOTO(out_shrink, rc = err_serious(-EFAULT));
1433 rc = mdt_reint_unpack(info, op);
1435 CERROR("Can't unpack reint, rc %d\n", rc);
1436 GOTO(out_shrink, rc = err_serious(rc));
1439 rc = mdt_init_ucred_reint(info);
1441 GOTO(out_shrink, rc);
1443 rc = mdt_fix_attr_ucred(info, op);
1445 GOTO(out_ucred, rc = err_serious(rc));
1448 if (mdt_check_resent(info, mdt_reconstruct, lhc)) {
1449 rc = lustre_msg_get_status(mdt_info_req(info)->rq_repmsg);
1450 GOTO(out_ucred, rc);
1453 rc = mdt_reint_rec(info, lhc);
1456 mdt_exit_ucred(info);
1459 mdt_shrink_reply(info);
1463 static long mdt_reint_opcode(struct mdt_thread_info *info,
1464 const struct req_format **fmt)
1469 opc = err_serious(-EFAULT);
1470 ptr = req_capsule_client_get(&info->mti_pill, &RMF_REINT_OPC);
1473 DEBUG_REQ(D_INODE, mdt_info_req(info), "reint opt = %ld", opc);
1474 if (opc < REINT_MAX && fmt[opc] != NULL)
1475 req_capsule_extend(&info->mti_pill, fmt[opc]);
1477 CERROR("Unsupported opc: %ld\n", opc);
1478 opc = err_serious(opc);
1484 static int mdt_reint(struct mdt_thread_info *info)
1489 static const struct req_format *reint_fmts[REINT_MAX] = {
1490 [REINT_SETATTR] = &RQF_MDS_REINT_SETATTR,
1491 [REINT_CREATE] = &RQF_MDS_REINT_CREATE,
1492 [REINT_LINK] = &RQF_MDS_REINT_LINK,
1493 [REINT_UNLINK] = &RQF_MDS_REINT_UNLINK,
1494 [REINT_RENAME] = &RQF_MDS_REINT_RENAME,
1495 [REINT_OPEN] = &RQF_MDS_REINT_OPEN
1500 opc = mdt_reint_opcode(info, reint_fmts);
1503 * No lock possible here from client to pass it to reint code
1506 rc = mdt_reint_internal(info, NULL, opc);
1511 info->mti_fail_id = OBD_FAIL_MDS_REINT_NET_REP;
1515 /* TODO these two methods not available now. */
1517 /* this should sync the whole device */
1518 static int mdt_device_sync(struct mdt_thread_info *info)
1523 /* this should sync this object */
1524 static int mdt_object_sync(struct mdt_thread_info *info)
1529 static int mdt_sync(struct mdt_thread_info *info)
1531 struct req_capsule *pill = &info->mti_pill;
1532 struct mdt_body *body;
1536 /* The fid may be zero, so we req_capsule_set manually */
1537 req_capsule_set(pill, &RQF_MDS_SYNC);
1539 body = req_capsule_client_get(pill, &RMF_MDT_BODY);
1541 RETURN(err_serious(-EINVAL));
1543 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_SYNC_PACK))
1544 RETURN(err_serious(-ENOMEM));
1546 if (fid_seq(&body->fid1) == 0) {
1547 /* sync the whole device */
1548 rc = req_capsule_pack(pill);
1550 rc = mdt_device_sync(info);
1552 rc = err_serious(rc);
1554 /* sync an object */
1555 rc = mdt_unpack_req_pack_rep(info, HABEO_CORPUS|HABEO_REFERO);
1557 rc = mdt_object_sync(info);
1559 struct md_object *next;
1560 const struct lu_fid *fid;
1561 struct lu_attr *la = &info->mti_attr.ma_attr;
1563 next = mdt_object_child(info->mti_object);
1564 info->mti_attr.ma_need = MA_INODE;
1565 info->mti_attr.ma_valid = 0;
1566 rc = mo_attr_get(info->mti_env, next,
1569 body = req_capsule_server_get(pill,
1571 fid = mdt_object_fid(info->mti_object);
1572 mdt_pack_attr2body(info, body, la, fid);
1576 rc = err_serious(rc);
1581 static int mdt_quotacheck_handle(struct mdt_thread_info *info)
1583 return err_serious(-EOPNOTSUPP);
1586 static int mdt_quotactl_handle(struct mdt_thread_info *info)
1588 return err_serious(-EOPNOTSUPP);
1592 * OBD PING and other handlers.
1594 static int mdt_obd_ping(struct mdt_thread_info *info)
1598 rc = target_handle_ping(mdt_info_req(info));
1600 rc = err_serious(rc);
1604 static int mdt_obd_log_cancel(struct mdt_thread_info *info)
1606 return err_serious(-EOPNOTSUPP);
1609 static int mdt_obd_qc_callback(struct mdt_thread_info *info)
1611 return err_serious(-EOPNOTSUPP);
1618 static struct ldlm_callback_suite cbs = {
1619 .lcs_completion = ldlm_server_completion_ast,
1620 .lcs_blocking = ldlm_server_blocking_ast,
1624 static int mdt_enqueue(struct mdt_thread_info *info)
1626 struct ptlrpc_request *req;
1631 * info->mti_dlm_req already contains swapped and (if necessary)
1632 * converted dlm request.
1634 LASSERT(info->mti_dlm_req != NULL);
1636 if (OBD_FAIL_CHECK(OBD_FAIL_LDLM_ENQUEUE)) {
1637 info->mti_fail_id = OBD_FAIL_LDLM_ENQUEUE;
1641 req = mdt_info_req(info);
1644 * Lock without inodebits makes no sense and will oops later in
1645 * ldlm. Let's check it now to see if we have wrong lock from client or
1646 * bits get corrupted somewhere in mdt_intent_policy().
1648 req_bits = info->mti_dlm_req->lock_desc.l_policy_data.l_inodebits.bits;
1649 /* This is disabled because we need to support liblustre flock.
1650 * LASSERT(req_bits != 0);
1653 rc = ldlm_handle_enqueue0(info->mti_mdt->mdt_namespace,
1654 req, info->mti_dlm_req, &cbs);
1655 info->mti_fail_id = OBD_FAIL_LDLM_REPLY;
1656 return rc ? err_serious(rc) : req->rq_status;
1659 static int mdt_convert(struct mdt_thread_info *info)
1662 struct ptlrpc_request *req;
1664 LASSERT(info->mti_dlm_req);
1665 req = mdt_info_req(info);
1666 rc = ldlm_handle_convert0(req, info->mti_dlm_req);
1667 return rc ? err_serious(rc) : req->rq_status;
1670 static int mdt_bl_callback(struct mdt_thread_info *info)
1672 CERROR("bl callbacks should not happen on MDS\n");
1674 return err_serious(-EOPNOTSUPP);
1677 static int mdt_cp_callback(struct mdt_thread_info *info)
1679 CERROR("cp callbacks should not happen on MDS\n");
1681 return err_serious(-EOPNOTSUPP);
1685 * sec context handlers
1687 static int mdt_sec_ctx_handle(struct mdt_thread_info *info)
1691 rc = mdt_handle_idmap(info);
1694 struct ptlrpc_request *req = mdt_info_req(info);
1697 opc = lustre_msg_get_opc(req->rq_reqmsg);
1698 if (opc == SEC_CTX_INIT || opc == SEC_CTX_INIT_CONT)
1699 sptlrpc_svc_ctx_invalidate(req);
1705 static struct mdt_object *mdt_obj(struct lu_object *o)
1707 LASSERT(lu_device_is_mdt(o->lo_dev));
1708 return container_of0(o, struct mdt_object, mot_obj.mo_lu);
1711 struct mdt_object *mdt_object_find(const struct lu_env *env,
1712 struct mdt_device *d,
1713 const struct lu_fid *f)
1715 struct lu_object *o;
1716 struct mdt_object *m;
1719 o = lu_object_find(env, d->mdt_md_dev.md_lu_dev.ld_site, f);
1720 if (unlikely(IS_ERR(o)))
1721 m = (struct mdt_object *)o;
1727 int mdt_object_lock(struct mdt_thread_info *info, struct mdt_object *o,
1728 struct mdt_lock_handle *lh, __u64 ibits, int locality)
1730 struct ldlm_namespace *ns = info->mti_mdt->mdt_namespace;
1731 ldlm_policy_data_t *policy = &info->mti_policy;
1732 struct ldlm_res_id *res_id = &info->mti_res_id;
1736 LASSERT(!lustre_handle_is_used(&lh->mlh_reg_lh));
1737 LASSERT(!lustre_handle_is_used(&lh->mlh_pdo_lh));
1738 LASSERT(lh->mlh_reg_mode != LCK_MINMODE);
1739 LASSERT(lh->mlh_type != MDT_NUL_LOCK);
1741 if (mdt_object_exists(o) < 0) {
1742 if (locality == MDT_CROSS_LOCK) {
1743 /* cross-ref object fix */
1744 ibits &= ~MDS_INODELOCK_UPDATE;
1745 ibits |= MDS_INODELOCK_LOOKUP;
1747 LASSERT(!(ibits & MDS_INODELOCK_UPDATE));
1748 LASSERT(ibits & MDS_INODELOCK_LOOKUP);
1750 /* No PDO lock on remote object */
1751 LASSERT(lh->mlh_type != MDT_PDO_LOCK);
1754 memset(policy, 0, sizeof(*policy));
1755 fid_build_reg_res_name(mdt_object_fid(o), res_id);
1758 * Take PDO lock on whole directory and build correct @res_id for lock
1759 * on part of directory.
1761 if (lh->mlh_pdo_hash != 0) {
1762 LASSERT(lh->mlh_type == MDT_PDO_LOCK);
1763 mdt_lock_pdo_mode(info, o, lh);
1764 if (lh->mlh_pdo_mode != LCK_NL) {
1766 * Do not use LDLM_FL_LOCAL_ONLY for parallel lock, it
1767 * is never going to be sent to client and we do not
1768 * want it slowed down due to possible cancels.
1770 policy->l_inodebits.bits = MDS_INODELOCK_UPDATE;
1771 rc = mdt_fid_lock(ns, &lh->mlh_pdo_lh, lh->mlh_pdo_mode,
1772 policy, res_id, LDLM_FL_ATOMIC_CB);
1778 * Finish res_id initializing by name hash marking patr of
1779 * directory which is taking modification.
1781 res_id->name[LUSTRE_RES_ID_HSH_OFF] = lh->mlh_pdo_hash;
1784 policy->l_inodebits.bits = ibits;
1787 * Use LDLM_FL_LOCAL_ONLY for this lock. We do not know yet if it is
1788 * going to be sent to client. If it is - mdt_intent_policy() path will
1789 * fix it up and turns FL_LOCAL flag off.
1791 rc = mdt_fid_lock(ns, &lh->mlh_reg_lh, lh->mlh_reg_mode, policy,
1792 res_id, LDLM_FL_LOCAL_ONLY | LDLM_FL_ATOMIC_CB);
1797 if (lh->mlh_type == MDT_PDO_LOCK) {
1798 /* check for exists after object is locked */
1799 if (mdt_object_exists(o) == 0) {
1800 /* Non-existent object shouldn't have PDO lock */
1803 /* Non-dir object shouldn't have PDO lock */
1804 LASSERT(S_ISDIR(lu_object_attr(&o->mot_obj.mo_lu)));
1809 mdt_object_unlock(info, o, lh, 1);
1816 * Just call ldlm_lock_decref() if decref, else we only call ptlrpc_save_lock()
1817 * to save this lock in req. when transaction committed, req will be released,
1818 * and lock will, too.
1820 void mdt_object_unlock(struct mdt_thread_info *info, struct mdt_object *o,
1821 struct mdt_lock_handle *lh, int decref)
1823 struct ptlrpc_request *req = mdt_info_req(info);
1826 if (lustre_handle_is_used(&lh->mlh_pdo_lh)) {
1827 /* Do not save PDO locks to request, just decref. */
1828 mdt_fid_unlock(&lh->mlh_pdo_lh,
1830 lh->mlh_pdo_lh.cookie = 0ull;
1833 if (lustre_handle_is_used(&lh->mlh_reg_lh)) {
1835 mdt_fid_unlock(&lh->mlh_reg_lh,
1838 ptlrpc_save_lock(req, &lh->mlh_reg_lh,
1841 lh->mlh_reg_lh.cookie = 0ull;
1847 struct mdt_object *mdt_object_find_lock(struct mdt_thread_info *info,
1848 const struct lu_fid *f,
1849 struct mdt_lock_handle *lh,
1852 struct mdt_object *o;
1854 o = mdt_object_find(info->mti_env, info->mti_mdt, f);
1858 rc = mdt_object_lock(info, o, lh, ibits,
1861 mdt_object_put(info->mti_env, o);
1868 void mdt_object_unlock_put(struct mdt_thread_info * info,
1869 struct mdt_object * o,
1870 struct mdt_lock_handle *lh,
1873 mdt_object_unlock(info, o, lh, decref);
1874 mdt_object_put(info->mti_env, o);
1877 static struct mdt_handler *mdt_handler_find(__u32 opc,
1878 struct mdt_opc_slice *supported)
1880 struct mdt_opc_slice *s;
1881 struct mdt_handler *h;
1884 for (s = supported; s->mos_hs != NULL; s++) {
1885 if (s->mos_opc_start <= opc && opc < s->mos_opc_end) {
1886 h = s->mos_hs + (opc - s->mos_opc_start);
1887 if (likely(h->mh_opc != 0))
1888 LASSERT(h->mh_opc == opc);
1890 h = NULL; /* unsupported opc */
1897 static int mdt_lock_resname_compat(struct mdt_device *m,
1898 struct ldlm_request *req)
1900 /* XXX something... later. */
1904 static int mdt_lock_reply_compat(struct mdt_device *m, struct ldlm_reply *rep)
1906 /* XXX something... later. */
1911 * Generic code handling requests that have struct mdt_body passed in:
1913 * - extract mdt_body from request and save it in @info, if present;
1915 * - create lu_object, corresponding to the fid in mdt_body, and save it in
1918 * - if HABEO_CORPUS flag is set for this request type check whether object
1919 * actually exists on storage (lu_object_exists()).
1922 static int mdt_body_unpack(struct mdt_thread_info *info, __u32 flags)
1924 const struct mdt_body *body;
1925 struct mdt_object *obj;
1926 const struct lu_env *env;
1927 struct req_capsule *pill;
1930 env = info->mti_env;
1931 pill = &info->mti_pill;
1933 body = info->mti_body = req_capsule_client_get(pill, &RMF_MDT_BODY);
1937 if (!fid_is_sane(&body->fid1)) {
1938 CERROR("Invalid fid: "DFID"\n", PFID(&body->fid1));
1943 * Do not get size or any capa fields before we check that request
1944 * contains capa actually. There are some requests which do not, for
1945 * instance MDS_IS_SUBDIR.
1947 if (req_capsule_has_field(pill, &RMF_CAPA1, RCL_CLIENT) &&
1948 req_capsule_get_size(pill, &RMF_CAPA1, RCL_CLIENT))
1949 mdt_set_capainfo(info, 0, &body->fid1,
1950 req_capsule_client_get(pill, &RMF_CAPA1));
1952 obj = mdt_object_find(env, info->mti_mdt, &body->fid1);
1954 if ((flags & HABEO_CORPUS) &&
1955 !mdt_object_exists(obj)) {
1956 mdt_object_put(env, obj);
1957 /* for capability renew ENOENT will be handled in
1959 if (body->valid & OBD_MD_FLOSSCAPA)
1964 info->mti_object = obj;
1973 static int mdt_unpack_req_pack_rep(struct mdt_thread_info *info, __u32 flags)
1975 struct req_capsule *pill;
1979 pill = &info->mti_pill;
1981 if (req_capsule_has_field(pill, &RMF_MDT_BODY, RCL_CLIENT))
1982 rc = mdt_body_unpack(info, flags);
1986 if (rc == 0 && (flags & HABEO_REFERO)) {
1987 struct mdt_device *mdt = info->mti_mdt;
1990 if (req_capsule_has_field(pill, &RMF_MDT_MD, RCL_SERVER))
1991 req_capsule_set_size(pill, &RMF_MDT_MD, RCL_SERVER,
1992 mdt->mdt_max_mdsize);
1993 if (req_capsule_has_field(pill, &RMF_LOGCOOKIES, RCL_SERVER))
1994 req_capsule_set_size(pill, &RMF_LOGCOOKIES, RCL_SERVER,
1995 mdt->mdt_max_cookiesize);
1997 rc = req_capsule_pack(pill);
2002 static int mdt_init_capa_ctxt(const struct lu_env *env, struct mdt_device *m)
2004 struct md_device *next = m->mdt_child;
2006 return next->md_ops->mdo_init_capa_ctxt(env, next,
2007 m->mdt_opts.mo_mds_capa,
2008 m->mdt_capa_timeout,
2014 * Invoke handler for this request opc. Also do necessary preprocessing
2015 * (according to handler ->mh_flags), and post-processing (setting of
2016 * ->last_{xid,committed}).
2018 static int mdt_req_handle(struct mdt_thread_info *info,
2019 struct mdt_handler *h, struct ptlrpc_request *req)
2021 int rc, serious = 0;
2026 LASSERT(h->mh_act != NULL);
2027 LASSERT(h->mh_opc == lustre_msg_get_opc(req->rq_reqmsg));
2028 LASSERT(current->journal_info == NULL);
2031 * Mask out OBD_FAIL_ONCE, because that will stop
2032 * correct handling of failed req later in ldlm due to doing
2033 * obd_fail_loc |= OBD_FAIL_ONCE without actually
2034 * correct actions like it is done in target_send_reply_msg().
2036 if (h->mh_fail_id != 0) {
2038 * Set to info->mti_fail_id to handler fail_id, it will be used
2039 * later, and better than use default fail_id.
2041 if (OBD_FAIL_CHECK_RESET(h->mh_fail_id && OBD_FAIL_MASK_LOC,
2042 h->mh_fail_id & ~OBD_FAILED)) {
2043 info->mti_fail_id = h->mh_fail_id;
2049 flags = h->mh_flags;
2050 LASSERT(ergo(flags & (HABEO_CORPUS|HABEO_REFERO), h->mh_fmt != NULL));
2052 if (h->mh_fmt != NULL) {
2053 req_capsule_set(&info->mti_pill, h->mh_fmt);
2054 rc = mdt_unpack_req_pack_rep(info, flags);
2057 if (rc == 0 && flags & MUTABOR &&
2058 req->rq_export->exp_connect_flags & OBD_CONNECT_RDONLY)
2059 /* should it be rq_status? */
2062 if (rc == 0 && flags & HABEO_CLAVIS) {
2063 struct ldlm_request *dlm_req;
2065 LASSERT(h->mh_fmt != NULL);
2067 dlm_req = req_capsule_client_get(&info->mti_pill, &RMF_DLM_REQ);
2068 if (dlm_req != NULL) {
2069 if (info->mti_mdt->mdt_opts.mo_compat_resname)
2070 rc = mdt_lock_resname_compat(info->mti_mdt,
2072 info->mti_dlm_req = dlm_req;
2074 CERROR("Can't unpack dlm request\n");
2079 /* capability setting changed via /proc, needs reinitialize ctxt */
2080 if (info->mti_mdt && info->mti_mdt->mdt_capa_conf) {
2081 mdt_init_capa_ctxt(info->mti_env, info->mti_mdt);
2082 info->mti_mdt->mdt_capa_conf = 0;
2085 if (likely(rc == 0)) {
2087 * Process request, there can be two types of rc:
2088 * 1) errors with msg unpack/pack, other failures outside the
2089 * operation itself. This is counted as serious errors;
2090 * 2) errors during fs operation, should be placed in rq_status
2093 rc = h->mh_act(info);
2094 serious = is_serious(rc);
2095 rc = clear_serious(rc);
2099 req->rq_status = rc;
2102 * ELDLM_* codes which > 0 should be in rq_status only as well as
2103 * all non-serious errors.
2105 if (rc > 0 || !serious)
2108 LASSERT(current->journal_info == NULL);
2110 if (rc == 0 && (flags & HABEO_CLAVIS) &&
2111 info->mti_mdt->mdt_opts.mo_compat_resname) {
2112 struct ldlm_reply *dlmrep;
2114 dlmrep = req_capsule_server_get(&info->mti_pill, &RMF_DLM_REP);
2116 rc = mdt_lock_reply_compat(info->mti_mdt, dlmrep);
2119 /* If we're DISCONNECTing, the mdt_export_data is already freed */
2120 if (likely(rc == 0 && h->mh_opc != MDS_DISCONNECT))
2121 target_committed_to_req(req);
2123 if (unlikely((lustre_msg_get_flags(req->rq_reqmsg) & MSG_REPLAY) &&
2124 lustre_msg_get_transno(req->rq_reqmsg) == 0)) {
2125 DEBUG_REQ(D_ERROR, req, "transno is 0 during REPLAY");
2132 void mdt_lock_handle_init(struct mdt_lock_handle *lh)
2134 lh->mlh_type = MDT_NUL_LOCK;
2135 lh->mlh_reg_lh.cookie = 0ull;
2136 lh->mlh_reg_mode = LCK_MINMODE;
2137 lh->mlh_pdo_lh.cookie = 0ull;
2138 lh->mlh_pdo_mode = LCK_MINMODE;
2141 void mdt_lock_handle_fini(struct mdt_lock_handle *lh)
2143 LASSERT(!lustre_handle_is_used(&lh->mlh_reg_lh));
2144 LASSERT(!lustre_handle_is_used(&lh->mlh_pdo_lh));
2148 * Initialize fields of struct mdt_thread_info. Other fields are left in
2149 * uninitialized state, because it's too expensive to zero out whole
2150 * mdt_thread_info (> 1K) on each request arrival.
2152 static void mdt_thread_info_init(struct ptlrpc_request *req,
2153 struct mdt_thread_info *info)
2156 struct md_capainfo *ci;
2158 info->mti_rep_buf_nr = ARRAY_SIZE(info->mti_rep_buf_size);
2159 for (i = 0; i < ARRAY_SIZE(info->mti_rep_buf_size); i++)
2160 info->mti_rep_buf_size[i] = -1;
2161 req_capsule_init(&info->mti_pill, req, RCL_SERVER,
2162 info->mti_rep_buf_size);
2165 for (i = 0; i < ARRAY_SIZE(info->mti_lh); i++)
2166 mdt_lock_handle_init(&info->mti_lh[i]);
2168 /* mdt device: it can be NULL while CONNECT */
2169 if (req->rq_export) {
2170 info->mti_mdt = mdt_dev(req->rq_export->exp_obd->obd_lu_dev);
2171 info->mti_exp = req->rq_export;
2173 info->mti_mdt = NULL;
2174 info->mti_env = req->rq_svc_thread->t_env;
2175 ci = md_capainfo(info->mti_env);
2176 memset(ci, 0, sizeof *ci);
2178 info->mti_fail_id = OBD_FAIL_MDS_ALL_REPLY_NET;
2179 info->mti_transno = lustre_msg_get_transno(req->rq_reqmsg);
2181 memset(&info->mti_attr, 0, sizeof(info->mti_attr));
2182 info->mti_body = NULL;
2183 info->mti_object = NULL;
2184 info->mti_dlm_req = NULL;
2185 info->mti_has_trans = 0;
2186 info->mti_no_need_trans = 0;
2187 info->mti_cross_ref = 0;
2188 info->mti_opdata = 0;
2190 /* To not check for split by default. */
2191 info->mti_spec.sp_ck_split = 0;
2194 static void mdt_thread_info_fini(struct mdt_thread_info *info)
2198 req_capsule_fini(&info->mti_pill);
2199 if (info->mti_object != NULL) {
2200 mdt_object_put(info->mti_env, info->mti_object);
2201 info->mti_object = NULL;
2203 for (i = 0; i < ARRAY_SIZE(info->mti_lh); i++)
2204 mdt_lock_handle_fini(&info->mti_lh[i]);
2205 info->mti_env = NULL;
2209 extern int mds_filter_recovery_request(struct ptlrpc_request *req,
2210 struct obd_device *obd, int *process);
2212 * Handle recovery. Return:
2213 * +1: continue request processing;
2214 * -ve: abort immediately with the given error code;
2215 * 0: send reply with error code in req->rq_status;
2217 static int mdt_recovery(struct mdt_thread_info *info)
2219 struct ptlrpc_request *req = mdt_info_req(info);
2221 struct obd_device *obd;
2225 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
2228 case SEC_CTX_INIT_CONT:
2234 rc = mdt_handle_idmap(info);
2243 if (unlikely(req->rq_export == NULL)) {
2244 CERROR("operation %d on unconnected MDS from %s\n",
2245 lustre_msg_get_opc(req->rq_reqmsg),
2246 libcfs_id2str(req->rq_peer));
2247 /* FIXME: For CMD cleanup, when mds_B stop, the req from
2248 * mds_A will get -ENOTCONN(especially for ping req),
2249 * which will cause that mds_A deactive timeout, then when
2250 * mds_A cleanup, the cleanup process will be suspended since
2251 * deactive timeout is not zero.
2253 req->rq_status = -ENOTCONN;
2254 target_send_reply(req, -ENOTCONN, info->mti_fail_id);
2258 /* sanity check: if the xid matches, the request must be marked as a
2259 * resent or replayed */
2260 if (req_xid_is_last(req)) {
2261 if (!(lustre_msg_get_flags(req->rq_reqmsg) &
2262 (MSG_RESENT | MSG_REPLAY))) {
2263 DEBUG_REQ(D_WARNING, req, "rq_xid "LPU64" matches last_xid, "
2264 "expected REPLAY or RESENT flag (%x)", req->rq_xid,
2265 lustre_msg_get_flags(req->rq_reqmsg));
2267 req->rq_status = -ENOTCONN;
2272 /* else: note the opposite is not always true; a RESENT req after a
2273 * failover will usually not match the last_xid, since it was likely
2274 * never committed. A REPLAYed request will almost never match the
2275 * last xid, however it could for a committed, but still retained,
2278 obd = req->rq_export->exp_obd;
2280 /* Check for aborted recovery... */
2281 spin_lock_bh(&obd->obd_processing_task_lock);
2282 recovering = obd->obd_recovering;
2283 spin_unlock_bh(&obd->obd_processing_task_lock);
2284 if (unlikely(recovering)) {
2287 DEBUG_REQ(D_INFO, req, "Got new replay");
2288 rc = mds_filter_recovery_request(req, obd, &should_process);
2289 if (rc != 0 || !should_process)
2291 else if (should_process < 0) {
2292 req->rq_status = should_process;
2293 rc = ptlrpc_error(req);
2300 static int mdt_reply(struct ptlrpc_request *req, int rc,
2301 struct mdt_thread_info *info)
2306 if (req->rq_reply_state == NULL && rc == 0) {
2307 req->rq_status = rc;
2308 lustre_pack_reply(req, 1, NULL, NULL);
2311 target_send_reply(req, rc, info->mti_fail_id);
2316 extern int mds_msg_check_version(struct lustre_msg *msg);
2318 static int mdt_handle0(struct ptlrpc_request *req,
2319 struct mdt_thread_info *info,
2320 struct mdt_opc_slice *supported)
2322 struct mdt_handler *h;
2323 struct lustre_msg *msg;
2328 if (OBD_FAIL_CHECK_ORSET(OBD_FAIL_MDS_ALL_REQUEST_NET, OBD_FAIL_ONCE))
2331 LASSERT(current->journal_info == NULL);
2333 msg = req->rq_reqmsg;
2334 rc = mds_msg_check_version(msg);
2335 if (likely(rc == 0)) {
2336 rc = mdt_recovery(info);
2337 if (likely(rc == +1)) {
2338 h = mdt_handler_find(lustre_msg_get_opc(msg),
2340 if (likely(h != NULL)) {
2341 rc = mdt_req_handle(info, h, req);
2342 rc = mdt_reply(req, rc, info);
2344 CERROR("The unsupported opc: 0x%x\n", lustre_msg_get_opc(msg) );
2345 req->rq_status = -ENOTSUPP;
2346 rc = ptlrpc_error(req);
2351 CERROR(LUSTRE_MDT_NAME" drops mal-formed request\n");
2356 * MDT handler function called by ptlrpc service thread when request comes.
2358 * XXX common "target" functionality should be factored into separate module
2359 * shared by mdt, ost and stand-alone services like fld.
2361 static int mdt_handle_common(struct ptlrpc_request *req,
2362 struct mdt_opc_slice *supported)
2365 struct mdt_thread_info *info;
2369 env = req->rq_svc_thread->t_env;
2370 LASSERT(env != NULL);
2371 LASSERT(env->le_ses != NULL);
2372 LASSERT(env->le_ctx.lc_thread == req->rq_svc_thread);
2373 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
2374 LASSERT(info != NULL);
2376 mdt_thread_info_init(req, info);
2378 rc = mdt_handle0(req, info, supported);
2380 mdt_thread_info_fini(info);
2385 * This is called from recovery code as handler of _all_ RPC types, FLD and SEQ
2388 int mdt_recovery_handle(struct ptlrpc_request *req)
2393 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
2395 rc = mdt_handle_common(req, mdt_fld_handlers);
2398 rc = mdt_handle_common(req, mdt_seq_handlers);
2401 rc = mdt_handle_common(req, mdt_regular_handlers);
2408 static int mdt_regular_handle(struct ptlrpc_request *req)
2410 return mdt_handle_common(req, mdt_regular_handlers);
2413 static int mdt_readpage_handle(struct ptlrpc_request *req)
2415 return mdt_handle_common(req, mdt_readpage_handlers);
2418 static int mdt_xmds_handle(struct ptlrpc_request *req)
2420 return mdt_handle_common(req, mdt_xmds_handlers);
2423 static int mdt_mdsc_handle(struct ptlrpc_request *req)
2425 return mdt_handle_common(req, mdt_seq_handlers);
2428 static int mdt_mdss_handle(struct ptlrpc_request *req)
2430 return mdt_handle_common(req, mdt_seq_handlers);
2433 static int mdt_dtss_handle(struct ptlrpc_request *req)
2435 return mdt_handle_common(req, mdt_seq_handlers);
2438 static int mdt_fld_handle(struct ptlrpc_request *req)
2440 return mdt_handle_common(req, mdt_fld_handlers);
2456 static int mdt_intent_getattr(enum mdt_it_code opcode,
2457 struct mdt_thread_info *info,
2458 struct ldlm_lock **,
2460 static int mdt_intent_reint(enum mdt_it_code opcode,
2461 struct mdt_thread_info *info,
2462 struct ldlm_lock **,
2465 static struct mdt_it_flavor {
2466 const struct req_format *it_fmt;
2468 int (*it_act)(enum mdt_it_code ,
2469 struct mdt_thread_info *,
2470 struct ldlm_lock **,
2473 } mdt_it_flavor[] = {
2475 .it_fmt = &RQF_LDLM_INTENT,
2476 /*.it_flags = HABEO_REFERO,*/
2478 .it_act = mdt_intent_reint,
2479 .it_reint = REINT_OPEN
2482 .it_fmt = &RQF_LDLM_INTENT,
2483 .it_flags = MUTABOR,
2484 .it_act = mdt_intent_reint,
2485 .it_reint = REINT_OPEN
2488 .it_fmt = &RQF_LDLM_INTENT,
2489 .it_flags = MUTABOR,
2490 .it_act = mdt_intent_reint,
2491 .it_reint = REINT_CREATE
2493 [MDT_IT_GETATTR] = {
2494 .it_fmt = &RQF_LDLM_INTENT_GETATTR,
2495 .it_flags = HABEO_REFERO,
2496 .it_act = mdt_intent_getattr
2498 [MDT_IT_READDIR] = {
2504 .it_fmt = &RQF_LDLM_INTENT_GETATTR,
2505 .it_flags = HABEO_REFERO,
2506 .it_act = mdt_intent_getattr
2509 .it_fmt = &RQF_LDLM_INTENT_UNLINK,
2510 .it_flags = MUTABOR,
2512 .it_reint = REINT_UNLINK
2516 .it_flags = MUTABOR,
2519 [MDT_IT_GETXATTR] = {
2526 int mdt_intent_lock_replace(struct mdt_thread_info *info,
2527 struct ldlm_lock **lockp,
2528 struct ldlm_lock *new_lock,
2529 struct mdt_lock_handle *lh,
2532 struct ptlrpc_request *req = mdt_info_req(info);
2533 struct ldlm_lock *lock = *lockp;
2536 * Get new lock only for cases when possible resent did not find any
2539 if (new_lock == NULL)
2540 new_lock = ldlm_handle2lock(&lh->mlh_reg_lh);
2542 if (new_lock == NULL && (flags & LDLM_FL_INTENT_ONLY)) {
2543 lh->mlh_reg_lh.cookie = 0;
2547 LASSERTF(new_lock != NULL,
2548 "lockh "LPX64"\n", lh->mlh_reg_lh.cookie);
2551 * If we've already given this lock to a client once, then we should
2552 * have no readers or writers. Otherwise, we should have one reader
2553 * _or_ writer ref (which will be zeroed below) before returning the
2556 if (new_lock->l_export == req->rq_export) {
2557 LASSERT(new_lock->l_readers + new_lock->l_writers == 0);
2559 LASSERT(new_lock->l_export == NULL);
2560 LASSERT(new_lock->l_readers + new_lock->l_writers == 1);
2565 if (new_lock->l_export == req->rq_export) {
2567 * Already gave this to the client, which means that we
2568 * reconstructed a reply.
2570 LASSERT(lustre_msg_get_flags(req->rq_reqmsg) &
2572 lh->mlh_reg_lh.cookie = 0;
2573 RETURN(ELDLM_LOCK_REPLACED);
2576 /* This lock might already be given to the client by an resent req,
2577 * in this case we should return ELDLM_LOCK_ABORTED,
2578 * so we should check led_held_locks here, but it will affect
2579 * performance, FIXME
2581 /* Fixup the lock to be given to the client */
2582 lock_res_and_lock(new_lock);
2583 new_lock->l_readers = 0;
2584 new_lock->l_writers = 0;
2586 new_lock->l_export = class_export_get(req->rq_export);
2587 spin_lock(&req->rq_export->exp_ldlm_data.led_lock);
2588 list_add(&new_lock->l_export_chain,
2589 &new_lock->l_export->exp_ldlm_data.led_held_locks);
2590 spin_unlock(&req->rq_export->exp_ldlm_data.led_lock);
2592 new_lock->l_blocking_ast = lock->l_blocking_ast;
2593 new_lock->l_completion_ast = lock->l_completion_ast;
2594 new_lock->l_remote_handle = lock->l_remote_handle;
2595 new_lock->l_flags &= ~LDLM_FL_LOCAL;
2597 unlock_res_and_lock(new_lock);
2598 LDLM_LOCK_PUT(new_lock);
2599 lh->mlh_reg_lh.cookie = 0;
2601 RETURN(ELDLM_LOCK_REPLACED);
2604 static void mdt_intent_fixup_resent(struct mdt_thread_info *info,
2605 struct ldlm_lock *new_lock,
2606 struct ldlm_lock **old_lock,
2607 struct mdt_lock_handle *lh)
2609 struct ptlrpc_request *req = mdt_info_req(info);
2610 struct obd_export *exp = req->rq_export;
2611 struct lustre_handle remote_hdl;
2612 struct ldlm_request *dlmreq;
2613 struct list_head *iter;
2615 if (!(lustre_msg_get_flags(req->rq_reqmsg) & MSG_RESENT))
2618 dlmreq = req_capsule_client_get(&info->mti_pill, &RMF_DLM_REQ);
2619 remote_hdl = dlmreq->lock_handle[0];
2621 spin_lock(&exp->exp_ldlm_data.led_lock);
2622 list_for_each(iter, &exp->exp_ldlm_data.led_held_locks) {
2623 struct ldlm_lock *lock;
2624 lock = list_entry(iter, struct ldlm_lock, l_export_chain);
2625 if (lock == new_lock)
2627 if (lock->l_remote_handle.cookie == remote_hdl.cookie) {
2628 lh->mlh_reg_lh.cookie = lock->l_handle.h_cookie;
2629 lh->mlh_reg_mode = lock->l_granted_mode;
2631 LDLM_DEBUG(lock, "restoring lock cookie");
2632 DEBUG_REQ(D_DLMTRACE, req,
2633 "restoring lock cookie "LPX64,
2634 lh->mlh_reg_lh.cookie);
2636 *old_lock = LDLM_LOCK_GET(lock);
2637 spin_unlock(&exp->exp_ldlm_data.led_lock);
2641 spin_unlock(&exp->exp_ldlm_data.led_lock);
2644 * If the xid matches, then we know this is a resent request, and allow
2645 * it. (It's probably an OPEN, for which we don't send a lock.
2647 if (req_xid_is_last(req))
2651 * This remote handle isn't enqueued, so we never received or processed
2652 * this request. Clear MSG_RESENT, because it can be handled like any
2653 * normal request now.
2655 lustre_msg_clear_flags(req->rq_reqmsg, MSG_RESENT);
2657 DEBUG_REQ(D_DLMTRACE, req, "no existing lock with rhandle "LPX64,
2661 static int mdt_intent_getattr(enum mdt_it_code opcode,
2662 struct mdt_thread_info *info,
2663 struct ldlm_lock **lockp,
2666 struct mdt_lock_handle *lhc = &info->mti_lh[MDT_LH_RMT];
2667 struct ldlm_lock *new_lock = NULL;
2669 struct ldlm_reply *ldlm_rep;
2670 struct ptlrpc_request *req;
2671 struct mdt_body *reqbody;
2672 struct mdt_body *repbody;
2676 reqbody = req_capsule_client_get(&info->mti_pill, &RMF_MDT_BODY);
2679 repbody = req_capsule_server_get(&info->mti_pill, &RMF_MDT_BODY);
2682 info->mti_spec.sp_ck_split = !!(reqbody->valid & OBD_MD_FLCKSPLIT);
2683 info->mti_cross_ref = !!(reqbody->valid & OBD_MD_FLCROSSREF);
2684 repbody->eadatasize = 0;
2685 repbody->aclsize = 0;
2689 child_bits = MDS_INODELOCK_LOOKUP;
2691 case MDT_IT_GETATTR:
2692 child_bits = MDS_INODELOCK_LOOKUP | MDS_INODELOCK_UPDATE;
2695 CERROR("Unhandled till now");
2696 GOTO(out, rc = -EINVAL);
2699 rc = mdt_init_ucred(info, reqbody);
2703 req = info->mti_pill.rc_req;
2704 ldlm_rep = req_capsule_server_get(&info->mti_pill, &RMF_DLM_REP);
2705 mdt_set_disposition(info, ldlm_rep, DISP_IT_EXECD);
2707 /* Get lock from request for possible resent case. */
2708 mdt_intent_fixup_resent(info, *lockp, &new_lock, lhc);
2710 ldlm_rep->lock_policy_res2 =
2711 mdt_getattr_name_lock(info, lhc, child_bits, ldlm_rep);
2713 if (mdt_get_disposition(ldlm_rep, DISP_LOOKUP_NEG))
2714 ldlm_rep->lock_policy_res2 = 0;
2715 if (!mdt_get_disposition(ldlm_rep, DISP_LOOKUP_POS) ||
2716 ldlm_rep->lock_policy_res2) {
2717 lhc->mlh_reg_lh.cookie = 0ull;
2718 GOTO(out_ucred, rc = ELDLM_LOCK_ABORTED);
2721 rc = mdt_intent_lock_replace(info, lockp, new_lock, lhc, flags);
2724 mdt_exit_ucred(info);
2726 mdt_shrink_reply(info);
2730 static int mdt_intent_reint(enum mdt_it_code opcode,
2731 struct mdt_thread_info *info,
2732 struct ldlm_lock **lockp,
2735 struct mdt_lock_handle *lhc = &info->mti_lh[MDT_LH_RMT];
2736 struct ldlm_reply *rep = NULL;
2740 static const struct req_format *intent_fmts[REINT_MAX] = {
2741 [REINT_CREATE] = &RQF_LDLM_INTENT_CREATE,
2742 [REINT_OPEN] = &RQF_LDLM_INTENT_OPEN
2747 opc = mdt_reint_opcode(info, intent_fmts);
2749 GOTO(out, rc = opc);
2751 if (mdt_it_flavor[opcode].it_reint != opc) {
2752 CERROR("Reint code %ld doesn't match intent: %d\n",
2754 GOTO(out, rc = err_serious(-EPROTO));
2757 /* Get lock from request for possible resent case. */
2758 mdt_intent_fixup_resent(info, *lockp, NULL, lhc);
2760 rc = mdt_reint_internal(info, lhc, opc);
2762 /* Check whether the reply has been packed successfully. */
2763 if (mdt_info_req(info)->rq_repmsg != NULL)
2764 rep = req_capsule_server_get(&info->mti_pill, &RMF_DLM_REP);
2766 GOTO(out, rc = err_serious(-EFAULT));
2768 /* MDC expects this in any case */
2770 mdt_set_disposition(info, rep, DISP_LOOKUP_EXECD);
2772 /* Cross-ref case, the lock should be returned to the client */
2773 if (rc == -EREMOTE) {
2774 LASSERT(lustre_handle_is_used(&lhc->mlh_reg_lh));
2775 rep->lock_policy_res2 = 0;
2776 rc = mdt_intent_lock_replace(info, lockp, NULL, lhc, flags);
2779 rep->lock_policy_res2 = clear_serious(rc);
2781 lhc->mlh_reg_lh.cookie = 0ull;
2782 rc = ELDLM_LOCK_ABORTED;
2788 static int mdt_intent_code(long itcode)
2796 case IT_OPEN|IT_CREAT:
2803 rc = MDT_IT_READDIR;
2806 rc = MDT_IT_GETATTR;
2818 rc = MDT_IT_GETXATTR;
2821 CERROR("Unknown intent opcode: %ld\n", itcode);
2828 static int mdt_intent_opc(long itopc, struct mdt_thread_info *info,
2829 struct ldlm_lock **lockp, int flags)
2831 struct req_capsule *pill;
2832 struct mdt_it_flavor *flv;
2837 opc = mdt_intent_code(itopc);
2841 pill = &info->mti_pill;
2842 flv = &mdt_it_flavor[opc];
2844 if (flv->it_fmt != NULL)
2845 req_capsule_extend(pill, flv->it_fmt);
2847 rc = mdt_unpack_req_pack_rep(info, flv->it_flags);
2849 struct ptlrpc_request *req = mdt_info_req(info);
2850 if (flv->it_flags & MUTABOR &&
2851 req->rq_export->exp_connect_flags & OBD_CONNECT_RDONLY)
2854 if (rc == 0 && flv->it_act != NULL) {
2855 /* execute policy */
2856 rc = flv->it_act(opc, info, lockp, flags);
2862 static int mdt_intent_policy(struct ldlm_namespace *ns,
2863 struct ldlm_lock **lockp, void *req_cookie,
2864 ldlm_mode_t mode, int flags, void *data)
2866 struct mdt_thread_info *info;
2867 struct ptlrpc_request *req = req_cookie;
2868 struct ldlm_intent *it;
2869 struct req_capsule *pill;
2874 LASSERT(req != NULL);
2876 info = lu_context_key_get(&req->rq_svc_thread->t_env->le_ctx,
2878 LASSERT(info != NULL);
2879 pill = &info->mti_pill;
2880 LASSERT(pill->rc_req == req);
2882 if (req->rq_reqmsg->lm_bufcount > DLM_INTENT_IT_OFF) {
2883 req_capsule_extend(pill, &RQF_LDLM_INTENT);
2884 it = req_capsule_client_get(pill, &RMF_LDLM_INTENT);
2886 const struct ldlm_request *dlmreq;
2889 struct ldlm_lock *lock = *lockp;
2891 LDLM_DEBUG(lock, "intent policy opc: %s\n",
2892 ldlm_it2str(it->opc));
2895 rc = mdt_intent_opc(it->opc, info, lockp, flags);
2900 * Lock without inodebits makes no sense and will oops
2901 * later in ldlm. Let's check it now to see if we have
2902 * wrong lock from client or bits get corrupted
2903 * somewhere in mdt_intent_opc().
2905 dlmreq = info->mti_dlm_req;
2906 req_bits = dlmreq->lock_desc.l_policy_data.l_inodebits.bits;
2907 LASSERT(req_bits != 0);
2910 rc = err_serious(-EFAULT);
2912 /* No intent was provided */
2913 LASSERT(pill->rc_fmt == &RQF_LDLM_ENQUEUE);
2914 rc = req_capsule_pack(pill);
2916 rc = err_serious(rc);
2924 static void mdt_seq_adjust(const struct lu_env *env,
2925 struct mdt_device *m, int lost)
2927 struct lu_site *ls = m->mdt_md_dev.md_lu_dev.ld_site;
2928 struct lu_range out;
2931 LASSERT(ls && ls->ls_server_seq);
2933 /* get extra seq from seq_server, moving it's range up */
2934 while (lost-- > 0) {
2935 seq_server_alloc_meta(ls->ls_server_seq, NULL, &out, env);
2940 static int mdt_seq_fini(const struct lu_env *env,
2941 struct mdt_device *m)
2943 struct lu_site *ls = m->mdt_md_dev.md_lu_dev.ld_site;
2946 if (ls && ls->ls_server_seq) {
2947 seq_server_fini(ls->ls_server_seq, env);
2948 OBD_FREE_PTR(ls->ls_server_seq);
2949 ls->ls_server_seq = NULL;
2952 if (ls && ls->ls_control_seq) {
2953 seq_server_fini(ls->ls_control_seq, env);
2954 OBD_FREE_PTR(ls->ls_control_seq);
2955 ls->ls_control_seq = NULL;
2958 if (ls && ls->ls_client_seq) {
2959 seq_client_fini(ls->ls_client_seq);
2960 OBD_FREE_PTR(ls->ls_client_seq);
2961 ls->ls_client_seq = NULL;
2967 static int mdt_seq_init(const struct lu_env *env,
2969 struct mdt_device *m)
2976 ls = m->mdt_md_dev.md_lu_dev.ld_site;
2979 * This is sequence-controller node. Init seq-controller server on local
2982 if (ls->ls_node_id == 0) {
2983 LASSERT(ls->ls_control_seq == NULL);
2985 OBD_ALLOC_PTR(ls->ls_control_seq);
2986 if (ls->ls_control_seq == NULL)
2989 rc = seq_server_init(ls->ls_control_seq,
2990 m->mdt_bottom, uuid,
2991 LUSTRE_SEQ_CONTROLLER,
2995 GOTO(out_seq_fini, rc);
2997 OBD_ALLOC_PTR(ls->ls_client_seq);
2998 if (ls->ls_client_seq == NULL)
2999 GOTO(out_seq_fini, rc = -ENOMEM);
3001 OBD_ALLOC(prefix, MAX_OBD_NAME + 5);
3002 if (prefix == NULL) {
3003 OBD_FREE_PTR(ls->ls_client_seq);
3004 GOTO(out_seq_fini, rc = -ENOMEM);
3007 snprintf(prefix, MAX_OBD_NAME + 5, "ctl-%s",
3011 * Init seq-controller client after seq-controller server is
3012 * ready. Pass ls->ls_control_seq to it for direct talking.
3014 rc = seq_client_init(ls->ls_client_seq, NULL,
3015 LUSTRE_SEQ_METADATA, prefix,
3016 ls->ls_control_seq);
3017 OBD_FREE(prefix, MAX_OBD_NAME + 5);
3020 GOTO(out_seq_fini, rc);
3023 /* Init seq-server on local MDT */
3024 LASSERT(ls->ls_server_seq == NULL);
3026 OBD_ALLOC_PTR(ls->ls_server_seq);
3027 if (ls->ls_server_seq == NULL)
3028 GOTO(out_seq_fini, rc = -ENOMEM);
3030 rc = seq_server_init(ls->ls_server_seq,
3031 m->mdt_bottom, uuid,
3035 GOTO(out_seq_fini, rc = -ENOMEM);
3037 /* Assign seq-controller client to local seq-server. */
3038 if (ls->ls_node_id == 0) {
3039 LASSERT(ls->ls_client_seq != NULL);
3041 rc = seq_server_set_cli(ls->ls_server_seq,
3049 mdt_seq_fini(env, m);
3054 * Init client sequence manager which is used by local MDS to talk to sequence
3055 * controller on remote node.
3057 static int mdt_seq_init_cli(const struct lu_env *env,
3058 struct mdt_device *m,
3059 struct lustre_cfg *cfg)
3061 struct lu_site *ls = m->mdt_md_dev.md_lu_dev.ld_site;
3062 struct obd_device *mdc;
3063 struct obd_uuid *uuidp, *mdcuuidp;
3064 char *uuid_str, *mdc_uuid_str;
3067 struct mdt_thread_info *info;
3068 char *p, *index_string = lustre_cfg_string(cfg, 2);
3071 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
3072 uuidp = &info->mti_u.uuid[0];
3073 mdcuuidp = &info->mti_u.uuid[1];
3075 LASSERT(index_string);
3077 index = simple_strtol(index_string, &p, 10);
3079 CERROR("Invalid index in lustre_cgf, offset 2\n");
3083 /* check if this is adding the first MDC and controller is not yet
3085 if (index != 0 || ls->ls_client_seq)
3088 uuid_str = lustre_cfg_string(cfg, 1);
3089 mdc_uuid_str = lustre_cfg_string(cfg, 4);
3090 obd_str2uuid(uuidp, uuid_str);
3091 obd_str2uuid(mdcuuidp, mdc_uuid_str);
3093 mdc = class_find_client_obd(uuidp, LUSTRE_MDC_NAME, mdcuuidp);
3095 CERROR("can't find controller MDC by uuid %s\n",
3098 } else if (!mdc->obd_set_up) {
3099 CERROR("target %s not set up\n", mdc->obd_name);
3102 LASSERT(ls->ls_control_exp);
3103 OBD_ALLOC_PTR(ls->ls_client_seq);
3104 if (ls->ls_client_seq != NULL) {
3107 OBD_ALLOC(prefix, MAX_OBD_NAME + 5);
3111 snprintf(prefix, MAX_OBD_NAME + 5, "ctl-%s",
3114 rc = seq_client_init(ls->ls_client_seq,
3116 LUSTRE_SEQ_METADATA,
3118 OBD_FREE(prefix, MAX_OBD_NAME + 5);
3125 LASSERT(ls->ls_server_seq != NULL);
3126 rc = seq_server_set_cli(ls->ls_server_seq, ls->ls_client_seq,
3133 static void mdt_seq_fini_cli(struct mdt_device *m)
3139 ls = m->mdt_md_dev.md_lu_dev.ld_site;
3141 if (ls && ls->ls_server_seq)
3142 seq_server_set_cli(ls->ls_server_seq,
3145 if (ls && ls->ls_control_exp) {
3146 class_export_put(ls->ls_control_exp);
3147 ls->ls_control_exp = NULL;
3155 static int mdt_fld_fini(const struct lu_env *env,
3156 struct mdt_device *m)
3158 struct lu_site *ls = m->mdt_md_dev.md_lu_dev.ld_site;
3161 if (ls && ls->ls_server_fld) {
3162 fld_server_fini(ls->ls_server_fld, env);
3163 OBD_FREE_PTR(ls->ls_server_fld);
3164 ls->ls_server_fld = NULL;
3170 static int mdt_fld_init(const struct lu_env *env,
3172 struct mdt_device *m)
3178 ls = m->mdt_md_dev.md_lu_dev.ld_site;
3180 OBD_ALLOC_PTR(ls->ls_server_fld);
3181 if (ls->ls_server_fld == NULL)
3182 RETURN(rc = -ENOMEM);
3184 rc = fld_server_init(ls->ls_server_fld,
3185 m->mdt_bottom, uuid, env);
3187 OBD_FREE_PTR(ls->ls_server_fld);
3188 ls->ls_server_fld = NULL;
3195 /* device init/fini methods */
3196 static void mdt_stop_ptlrpc_service(struct mdt_device *m)
3199 if (m->mdt_regular_service != NULL) {
3200 ptlrpc_unregister_service(m->mdt_regular_service);
3201 m->mdt_regular_service = NULL;
3203 if (m->mdt_readpage_service != NULL) {
3204 ptlrpc_unregister_service(m->mdt_readpage_service);
3205 m->mdt_readpage_service = NULL;
3207 if (m->mdt_xmds_service != NULL) {
3208 ptlrpc_unregister_service(m->mdt_xmds_service);
3209 m->mdt_xmds_service = NULL;
3211 if (m->mdt_setattr_service != NULL) {
3212 ptlrpc_unregister_service(m->mdt_setattr_service);
3213 m->mdt_setattr_service = NULL;
3215 if (m->mdt_mdsc_service != NULL) {
3216 ptlrpc_unregister_service(m->mdt_mdsc_service);
3217 m->mdt_mdsc_service = NULL;
3219 if (m->mdt_mdss_service != NULL) {
3220 ptlrpc_unregister_service(m->mdt_mdss_service);
3221 m->mdt_mdss_service = NULL;
3223 if (m->mdt_dtss_service != NULL) {
3224 ptlrpc_unregister_service(m->mdt_dtss_service);
3225 m->mdt_dtss_service = NULL;
3227 if (m->mdt_fld_service != NULL) {
3228 ptlrpc_unregister_service(m->mdt_fld_service);
3229 m->mdt_fld_service = NULL;
3234 static int mdt_start_ptlrpc_service(struct mdt_device *m)
3237 static struct ptlrpc_service_conf conf;
3238 cfs_proc_dir_entry_t *procfs_entry;
3241 procfs_entry = m->mdt_md_dev.md_lu_dev.ld_obd->obd_proc_entry;
3243 conf = (typeof(conf)) {
3244 .psc_nbufs = MDS_NBUFS,
3245 .psc_bufsize = MDS_BUFSIZE,
3246 .psc_max_req_size = MDS_MAXREQSIZE,
3247 .psc_max_reply_size = MDS_MAXREPSIZE,
3248 .psc_req_portal = MDS_REQUEST_PORTAL,
3249 .psc_rep_portal = MDC_REPLY_PORTAL,
3250 .psc_watchdog_timeout = MDT_SERVICE_WATCHDOG_TIMEOUT,
3252 * We'd like to have a mechanism to set this on a per-device
3253 * basis, but alas...
3255 .psc_min_threads = min(max(mdt_num_threads, MDT_MIN_THREADS),
3257 .psc_max_threads = MDT_MAX_THREADS,
3258 .psc_ctx_tags = LCT_MD_THREAD
3261 m->mdt_ldlm_client = &m->mdt_md_dev.md_lu_dev.ld_obd->obd_ldlm_client;
3262 ptlrpc_init_client(LDLM_CB_REQUEST_PORTAL, LDLM_CB_REPLY_PORTAL,
3263 "mdt_ldlm_client", m->mdt_ldlm_client);
3265 m->mdt_regular_service =
3266 ptlrpc_init_svc_conf(&conf, mdt_regular_handle, LUSTRE_MDT_NAME,
3267 procfs_entry, NULL, LUSTRE_MDT_NAME);
3268 if (m->mdt_regular_service == NULL)
3271 rc = ptlrpc_start_threads(NULL, m->mdt_regular_service);
3273 GOTO(err_mdt_svc, rc);
3276 * readpage service configuration. Parameters have to be adjusted,
3279 conf = (typeof(conf)) {
3280 .psc_nbufs = MDS_NBUFS,
3281 .psc_bufsize = MDS_BUFSIZE,
3282 .psc_max_req_size = MDS_MAXREQSIZE,
3283 .psc_max_reply_size = MDS_MAXREPSIZE,
3284 .psc_req_portal = MDS_READPAGE_PORTAL,
3285 .psc_rep_portal = MDC_REPLY_PORTAL,
3286 .psc_watchdog_timeout = MDT_SERVICE_WATCHDOG_TIMEOUT,
3287 .psc_min_threads = min(max(mdt_num_threads, MDT_MIN_THREADS),
3289 .psc_max_threads = MDT_MAX_THREADS,
3290 .psc_ctx_tags = LCT_MD_THREAD
3292 m->mdt_readpage_service =
3293 ptlrpc_init_svc_conf(&conf, mdt_readpage_handle,
3294 LUSTRE_MDT_NAME "_readpage",
3295 procfs_entry, NULL, "mdt_rdpg");
3297 if (m->mdt_readpage_service == NULL) {
3298 CERROR("failed to start readpage service\n");
3299 GOTO(err_mdt_svc, rc = -ENOMEM);
3302 rc = ptlrpc_start_threads(NULL, m->mdt_readpage_service);
3305 * setattr service configuration.
3307 conf = (typeof(conf)) {
3308 .psc_nbufs = MDS_NBUFS,
3309 .psc_bufsize = MDS_BUFSIZE,
3310 .psc_max_req_size = MDS_MAXREQSIZE,
3311 .psc_max_reply_size = MDS_MAXREPSIZE,
3312 .psc_req_portal = MDS_SETATTR_PORTAL,
3313 .psc_rep_portal = MDC_REPLY_PORTAL,
3314 .psc_watchdog_timeout = MDT_SERVICE_WATCHDOG_TIMEOUT,
3315 .psc_min_threads = min(max(mdt_num_threads, MDT_MIN_THREADS),
3317 .psc_max_threads = MDT_MAX_THREADS,
3318 .psc_ctx_tags = LCT_MD_THREAD
3321 m->mdt_setattr_service =
3322 ptlrpc_init_svc_conf(&conf, mdt_regular_handle,
3323 LUSTRE_MDT_NAME "_setattr",
3324 procfs_entry, NULL, "mdt_attr");
3326 if (!m->mdt_setattr_service) {
3327 CERROR("failed to start setattr service\n");
3328 GOTO(err_mdt_svc, rc = -ENOMEM);
3331 rc = ptlrpc_start_threads(NULL, m->mdt_setattr_service);
3333 GOTO(err_mdt_svc, rc);
3336 * sequence controller service configuration
3338 conf = (typeof(conf)) {
3339 .psc_nbufs = MDS_NBUFS,
3340 .psc_bufsize = MDS_BUFSIZE,
3341 .psc_max_req_size = SEQ_MAXREQSIZE,
3342 .psc_max_reply_size = SEQ_MAXREPSIZE,
3343 .psc_req_portal = SEQ_CONTROLLER_PORTAL,
3344 .psc_rep_portal = MDC_REPLY_PORTAL,
3345 .psc_watchdog_timeout = MDT_SERVICE_WATCHDOG_TIMEOUT,
3346 .psc_min_threads = SEQ_NUM_THREADS,
3347 .psc_max_threads = SEQ_NUM_THREADS,
3348 .psc_ctx_tags = LCT_MD_THREAD|LCT_DT_THREAD
3351 m->mdt_mdsc_service =
3352 ptlrpc_init_svc_conf(&conf, mdt_mdsc_handle,
3353 LUSTRE_MDT_NAME"_mdsc",
3354 procfs_entry, NULL, "mdt_mdsc");
3355 if (!m->mdt_mdsc_service) {
3356 CERROR("failed to start seq controller service\n");
3357 GOTO(err_mdt_svc, rc = -ENOMEM);
3360 rc = ptlrpc_start_threads(NULL, m->mdt_mdsc_service);
3362 GOTO(err_mdt_svc, rc);
3365 * metadata sequence server service configuration
3367 conf = (typeof(conf)) {
3368 .psc_nbufs = MDS_NBUFS,
3369 .psc_bufsize = MDS_BUFSIZE,
3370 .psc_max_req_size = SEQ_MAXREQSIZE,
3371 .psc_max_reply_size = SEQ_MAXREPSIZE,
3372 .psc_req_portal = SEQ_METADATA_PORTAL,
3373 .psc_rep_portal = MDC_REPLY_PORTAL,
3374 .psc_watchdog_timeout = MDT_SERVICE_WATCHDOG_TIMEOUT,
3375 .psc_min_threads = SEQ_NUM_THREADS,
3376 .psc_max_threads = SEQ_NUM_THREADS,
3377 .psc_ctx_tags = LCT_MD_THREAD|LCT_DT_THREAD
3380 m->mdt_mdss_service =
3381 ptlrpc_init_svc_conf(&conf, mdt_mdss_handle,
3382 LUSTRE_MDT_NAME"_mdss",
3383 procfs_entry, NULL, "mdt_mdss");
3384 if (!m->mdt_mdss_service) {
3385 CERROR("failed to start metadata seq server service\n");
3386 GOTO(err_mdt_svc, rc = -ENOMEM);
3389 rc = ptlrpc_start_threads(NULL, m->mdt_mdss_service);
3391 GOTO(err_mdt_svc, rc);
3395 * Data sequence server service configuration. We want to have really
3396 * cluster-wide sequences space. This is why we start only one sequence
3397 * controller which manages space.
3399 conf = (typeof(conf)) {
3400 .psc_nbufs = MDS_NBUFS,
3401 .psc_bufsize = MDS_BUFSIZE,
3402 .psc_max_req_size = SEQ_MAXREQSIZE,
3403 .psc_max_reply_size = SEQ_MAXREPSIZE,
3404 .psc_req_portal = SEQ_DATA_PORTAL,
3405 .psc_rep_portal = OSC_REPLY_PORTAL,
3406 .psc_watchdog_timeout = MDT_SERVICE_WATCHDOG_TIMEOUT,
3407 .psc_min_threads = SEQ_NUM_THREADS,
3408 .psc_max_threads = SEQ_NUM_THREADS,
3409 .psc_ctx_tags = LCT_MD_THREAD|LCT_DT_THREAD
3412 m->mdt_dtss_service =
3413 ptlrpc_init_svc_conf(&conf, mdt_dtss_handle,
3414 LUSTRE_MDT_NAME"_dtss",
3415 procfs_entry, NULL, "mdt_dtss");
3416 if (!m->mdt_dtss_service) {
3417 CERROR("failed to start data seq server service\n");
3418 GOTO(err_mdt_svc, rc = -ENOMEM);
3421 rc = ptlrpc_start_threads(NULL, m->mdt_dtss_service);
3423 GOTO(err_mdt_svc, rc);
3425 /* FLD service start */
3426 conf = (typeof(conf)) {
3427 .psc_nbufs = MDS_NBUFS,
3428 .psc_bufsize = MDS_BUFSIZE,
3429 .psc_max_req_size = FLD_MAXREQSIZE,
3430 .psc_max_reply_size = FLD_MAXREPSIZE,
3431 .psc_req_portal = FLD_REQUEST_PORTAL,
3432 .psc_rep_portal = MDC_REPLY_PORTAL,
3433 .psc_watchdog_timeout = MDT_SERVICE_WATCHDOG_TIMEOUT,
3434 .psc_min_threads = FLD_NUM_THREADS,
3435 .psc_max_threads = FLD_NUM_THREADS,
3436 .psc_ctx_tags = LCT_DT_THREAD|LCT_MD_THREAD
3439 m->mdt_fld_service =
3440 ptlrpc_init_svc_conf(&conf, mdt_fld_handle,
3441 LUSTRE_MDT_NAME"_fld",
3442 procfs_entry, NULL, "mdt_fld");
3443 if (!m->mdt_fld_service) {
3444 CERROR("failed to start fld service\n");
3445 GOTO(err_mdt_svc, rc = -ENOMEM);
3448 rc = ptlrpc_start_threads(NULL, m->mdt_fld_service);
3450 GOTO(err_mdt_svc, rc);
3453 * mds-mds service configuration. Separate portal is used to allow
3454 * mds-mds requests be not blocked during recovery.
3456 conf = (typeof(conf)) {
3457 .psc_nbufs = MDS_NBUFS,
3458 .psc_bufsize = MDS_BUFSIZE,
3459 .psc_max_req_size = MDS_MAXREQSIZE,
3460 .psc_max_reply_size = MDS_MAXREPSIZE,
3461 .psc_req_portal = MDS_MDS_PORTAL,
3462 .psc_rep_portal = MDC_REPLY_PORTAL,
3463 .psc_watchdog_timeout = MDT_SERVICE_WATCHDOG_TIMEOUT,
3464 .psc_min_threads = min(max(mdt_num_threads, MDT_MIN_THREADS),
3466 .psc_max_threads = MDT_MAX_THREADS,
3467 .psc_ctx_tags = LCT_MD_THREAD
3469 m->mdt_xmds_service = ptlrpc_init_svc_conf(&conf, mdt_xmds_handle,
3470 LUSTRE_MDT_NAME "_mds",
3471 procfs_entry, NULL, "mdt_xmds");
3473 if (m->mdt_xmds_service == NULL) {
3474 CERROR("failed to start readpage service\n");
3475 GOTO(err_mdt_svc, rc = -ENOMEM);
3478 rc = ptlrpc_start_threads(NULL, m->mdt_xmds_service);
3480 GOTO(err_mdt_svc, rc);
3485 mdt_stop_ptlrpc_service(m);
3490 static void mdt_stack_fini(const struct lu_env *env,
3491 struct mdt_device *m, struct lu_device *top)
3493 struct lu_device *d = top, *n;
3494 struct obd_device *obd = m->mdt_md_dev.md_lu_dev.ld_obd;
3495 struct lustre_cfg_bufs *bufs;
3496 struct lustre_cfg *lcfg;
3497 struct mdt_thread_info *info;
3501 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
3502 LASSERT(info != NULL);
3504 bufs = &info->mti_u.bufs;
3505 /* process cleanup, pass mdt obd name to get obd umount flags */
3506 lustre_cfg_bufs_reset(bufs, obd->obd_name);
3511 lustre_cfg_bufs_set_string(bufs, 1, flags);
3512 lcfg = lustre_cfg_new(LCFG_CLEANUP, bufs);
3514 CERROR("Cannot alloc lcfg!\n");
3519 top->ld_ops->ldo_process_config(env, top, lcfg);
3520 lustre_cfg_free(lcfg);
3522 lu_site_purge(env, top->ld_site, ~0);
3524 struct obd_type *type;
3525 struct lu_device_type *ldt = d->ld_type;
3527 /* each fini() returns next device in stack of layers
3528 * * so we can avoid the recursion */
3529 n = ldt->ldt_ops->ldto_device_fini(env, d);
3531 ldt->ldt_ops->ldto_device_free(env, d);
3532 type = ldt->ldt_obd_type;
3534 class_put_type(type);
3536 /* switch to the next device in the layer */
3539 m->mdt_child = NULL;
3540 m->mdt_bottom = NULL;
3543 static struct lu_device *mdt_layer_setup(const struct lu_env *env,
3544 const char *typename,
3545 struct lu_device *child,
3546 struct lustre_cfg *cfg)
3548 const char *dev = lustre_cfg_string(cfg, 0);
3549 struct obd_type *type;
3550 struct lu_device_type *ldt;
3551 struct lu_device *d;
3556 type = class_get_type(typename);
3558 CERROR("Unknown type: '%s'\n", typename);
3559 GOTO(out, rc = -ENODEV);
3562 rc = lu_context_refill(&env->le_ctx);
3564 CERROR("Failure to refill context: '%d'\n", rc);
3568 if (env->le_ses != NULL) {
3569 rc = lu_context_refill(env->le_ses);
3571 CERROR("Failure to refill session: '%d'\n", rc);
3578 CERROR("type: '%s'\n", typename);
3579 GOTO(out_type, rc = -EINVAL);
3582 ldt->ldt_obd_type = type;
3583 d = ldt->ldt_ops->ldto_device_alloc(env, ldt, cfg);
3585 CERROR("Cannot allocate device: '%s'\n", typename);
3586 GOTO(out_type, rc = -ENODEV);
3589 LASSERT(child->ld_site);
3590 d->ld_site = child->ld_site;
3593 rc = ldt->ldt_ops->ldto_device_init(env, d, dev, child);
3595 CERROR("can't init device '%s', rc %d\n", typename, rc);
3596 GOTO(out_alloc, rc);
3603 ldt->ldt_ops->ldto_device_free(env, d);
3606 class_put_type(type);
3611 static int mdt_stack_init(const struct lu_env *env,
3612 struct mdt_device *m, struct lustre_cfg *cfg)
3614 struct lu_device *d = &m->mdt_md_dev.md_lu_dev;
3615 struct lu_device *tmp;
3616 struct md_device *md;
3620 /* init the stack */
3621 tmp = mdt_layer_setup(env, LUSTRE_OSD_NAME, d, cfg);
3623 RETURN(PTR_ERR(tmp));
3625 m->mdt_bottom = lu2dt_dev(tmp);
3627 tmp = mdt_layer_setup(env, LUSTRE_MDD_NAME, d, cfg);
3629 GOTO(out, rc = PTR_ERR(tmp));
3634 tmp = mdt_layer_setup(env, LUSTRE_CMM_NAME, d, cfg);
3636 GOTO(out, rc = PTR_ERR(tmp));
3639 /*set mdd upcall device*/
3640 md_upcall_dev_set(md, lu2md_dev(d));
3643 /*set cmm upcall device*/
3644 md_upcall_dev_set(md, &m->mdt_md_dev);
3646 m->mdt_child = lu2md_dev(d);
3648 /* process setup config */
3649 tmp = &m->mdt_md_dev.md_lu_dev;
3650 rc = tmp->ld_ops->ldo_process_config(env, tmp, cfg);
3653 /* fini from last known good lu_device */
3655 mdt_stack_fini(env, m, d);
3660 static void mdt_fini(const struct lu_env *env, struct mdt_device *m)
3662 struct md_device *next = m->mdt_child;
3663 struct lu_device *d = &m->mdt_md_dev.md_lu_dev;
3664 struct lu_site *ls = d->ld_site;
3665 struct obd_device *obd = m->mdt_md_dev.md_lu_dev.ld_obd;
3668 ping_evictor_stop();
3670 target_recovery_fini(obd);
3671 mdt_stop_ptlrpc_service(m);
3673 mdt_fs_cleanup(env, m);
3675 upcall_cache_cleanup(m->mdt_identity_cache);
3676 m->mdt_identity_cache = NULL;
3678 if (m->mdt_namespace != NULL) {
3679 ldlm_namespace_free(m->mdt_namespace, d->ld_obd->obd_force);
3680 d->ld_obd->obd_namespace = m->mdt_namespace = NULL;
3683 mdt_seq_fini(env, m);
3684 mdt_seq_fini_cli(m);
3685 mdt_fld_fini(env, m);
3687 ptlrpc_lprocfs_unregister_obd(d->ld_obd);
3688 lprocfs_obd_cleanup(d->ld_obd);
3690 sptlrpc_rule_set_free(&m->mdt_sptlrpc_rset);
3692 next->md_ops->mdo_init_capa_ctxt(env, next, 0, 0, 0, NULL);
3693 del_timer(&m->mdt_ck_timer);
3694 mdt_ck_thread_stop(m);
3696 /* finish the stack */
3697 mdt_stack_fini(env, m, md2lu_dev(m->mdt_child));
3700 if (!list_empty(&ls->ls_lru) || ls->ls_total != 0) {
3702 * Uh-oh, objects still exist.
3704 static DECLARE_LU_CDEBUG_PRINT_INFO(cookie, D_ERROR);
3706 lu_site_print(env, ls, &cookie, lu_cdebug_printer);
3713 LASSERT(atomic_read(&d->ld_ref) == 0);
3714 md_device_fini(&m->mdt_md_dev);
3719 static void fsoptions_to_mdt_flags(struct mdt_device *m, char *options)
3729 while (*p && *p != ',')
3733 if ((len == sizeof("user_xattr") - 1) &&
3734 (memcmp(options, "user_xattr", len) == 0)) {
3735 m->mdt_opts.mo_user_xattr = 1;
3736 LCONSOLE_INFO("Enabling user_xattr\n");
3737 } else if ((len == sizeof("nouser_xattr") - 1) &&
3738 (memcmp(options, "nouser_xattr", len) == 0)) {
3739 m->mdt_opts.mo_user_xattr = 0;
3740 LCONSOLE_INFO("Disabling user_xattr\n");
3741 } else if ((len == sizeof("acl") - 1) &&
3742 (memcmp(options, "acl", len) == 0)) {
3743 #ifdef CONFIG_FS_POSIX_ACL
3744 m->mdt_opts.mo_acl = 1;
3745 LCONSOLE_INFO("Enabling ACL\n");
3747 m->mdt_opts.mo_acl = 0;
3748 CWARN("ignoring unsupported acl mount option\n");
3749 LCONSOLE_INFO("Disabling ACL\n");
3751 } else if ((len == sizeof("noacl") - 1) &&
3752 (memcmp(options, "noacl", len) == 0)) {
3753 m->mdt_opts.mo_acl = 0;
3754 LCONSOLE_INFO("Disabling ACL\n");
3761 int mdt_postrecov(const struct lu_env *, struct mdt_device *);
3763 static int mdt_init0(const struct lu_env *env, struct mdt_device *m,
3764 struct lu_device_type *ldt, struct lustre_cfg *cfg)
3766 struct lprocfs_static_vars lvars;
3767 struct mdt_thread_info *info;
3768 struct obd_device *obd;
3769 const char *dev = lustre_cfg_string(cfg, 0);
3770 const char *num = lustre_cfg_string(cfg, 2);
3771 struct lustre_mount_info *lmi;
3772 struct lustre_sb_info *lsi;
3774 const char *identity_upcall = "NONE";
3778 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
3779 LASSERT(info != NULL);
3781 obd = class_name2obd(dev);
3782 LASSERT(obd != NULL);
3784 spin_lock_init(&m->mdt_transno_lock);
3786 m->mdt_max_mdsize = MAX_MD_SIZE;
3787 m->mdt_max_cookiesize = sizeof(struct llog_cookie);
3789 m->mdt_opts.mo_user_xattr = 0;
3790 m->mdt_opts.mo_acl = 0;
3791 lmi = server_get_mount_2(dev);
3793 CERROR("Cannot get mount info for %s!\n", dev);
3796 lsi = s2lsi(lmi->lmi_sb);
3797 fsoptions_to_mdt_flags(m, lsi->lsi_lmd->lmd_opts);
3798 server_put_mount_2(dev, lmi->lmi_mnt);
3801 m->mdt_sptlrpc_lock = RW_LOCK_UNLOCKED;
3802 sptlrpc_rule_set_init(&m->mdt_sptlrpc_rset);
3804 spin_lock_init(&m->mdt_ioepoch_lock);
3805 m->mdt_opts.mo_compat_resname = 0;
3806 m->mdt_capa_timeout = CAPA_TIMEOUT;
3807 m->mdt_capa_alg = CAPA_HMAC_ALG_SHA1;
3808 m->mdt_ck_timeout = CAPA_KEY_TIMEOUT;
3810 spin_lock_init(&m->mdt_client_bitmap_lock);
3816 md_device_init(&m->mdt_md_dev, ldt);
3817 m->mdt_md_dev.md_lu_dev.ld_ops = &mdt_lu_ops;
3818 m->mdt_md_dev.md_lu_dev.ld_obd = obd;
3819 /* set this lu_device to obd, because error handling need it */
3820 obd->obd_lu_dev = &m->mdt_md_dev.md_lu_dev;
3822 rc = lu_site_init(s, &m->mdt_md_dev.md_lu_dev);
3824 CERROR("Can't init lu_site, rc %d\n", rc);
3825 GOTO(err_free_site, rc);
3828 lprocfs_mdt_init_vars(&lvars);
3829 rc = lprocfs_obd_setup(obd, lvars.obd_vars);
3831 CERROR("Can't init lprocfs, rc %d\n", rc);
3832 GOTO(err_fini_site, rc);
3834 ptlrpc_lprocfs_register_obd(obd);
3836 rc = mdt_procfs_init(m, dev);
3838 CERROR("Can't init MDT lprocfs, rc %d\n", rc);
3839 GOTO(err_fini_proc, rc);
3842 /* set server index */
3844 s->ls_node_id = simple_strtol(num, NULL, 10);
3846 /* failover is the default
3847 * FIXME: we do not failout mds0/mgs, which may cause some problems.
3848 * assumed whose ls_node_id == 0 XXX
3850 obd->obd_replayable = 1;
3851 /* No connection accepted until configurations will finish */
3852 obd->obd_no_conn = 1;
3854 if (cfg->lcfg_bufcount > 4 && LUSTRE_CFG_BUFLEN(cfg, 4) > 0) {
3855 char *str = lustre_cfg_string(cfg, 4);
3856 if (strchr(str, 'n')) {
3857 CWARN("%s: recovery disabled\n", obd->obd_name);
3858 obd->obd_replayable = 0;
3862 /* init the stack */
3863 rc = mdt_stack_init(env, m, cfg);
3865 CERROR("Can't init device stack, rc %d\n", rc);
3866 GOTO(err_fini_proc, rc);
3869 rc = mdt_fld_init(env, obd->obd_name, m);
3871 GOTO(err_fini_stack, rc);
3873 rc = mdt_seq_init(env, obd->obd_name, m);
3875 GOTO(err_fini_fld, rc);
3877 snprintf(info->mti_u.ns_name, sizeof info->mti_u.ns_name,
3878 LUSTRE_MDT_NAME"-%p", m);
3879 m->mdt_namespace = ldlm_namespace_new(info->mti_u.ns_name,
3880 LDLM_NAMESPACE_SERVER,
3881 LDLM_NAMESPACE_GREEDY);
3882 if (m->mdt_namespace == NULL)
3883 GOTO(err_fini_seq, rc = -ENOMEM);
3885 ldlm_register_intent(m->mdt_namespace, mdt_intent_policy);
3886 /* set obd_namespace for compatibility with old code */
3887 obd->obd_namespace = m->mdt_namespace;
3889 /* XXX: to support suppgid for ACL, we enable identity_upcall
3890 * by default, otherwise, maybe got unexpected -EACCESS. */
3891 if (m->mdt_opts.mo_acl)
3892 identity_upcall = MDT_IDENTITY_UPCALL_PATH;
3894 m->mdt_identity_cache = upcall_cache_init(obd->obd_name, identity_upcall,
3895 &mdt_identity_upcall_cache_ops);
3896 if (IS_ERR(m->mdt_identity_cache)) {
3897 rc = PTR_ERR(m->mdt_identity_cache);
3898 m->mdt_identity_cache = NULL;
3899 GOTO(err_free_ns, rc);
3902 m->mdt_ck_timer.function = mdt_ck_timer_callback;
3903 m->mdt_ck_timer.data = (unsigned long)m;
3904 init_timer(&m->mdt_ck_timer);
3905 rc = mdt_ck_thread_start(m);
3907 GOTO(err_free_ns, rc);
3909 rc = mdt_fs_setup(env, m, obd);
3913 target_recovery_init(obd, mdt_recovery_handle);
3915 rc = mdt_start_ptlrpc_service(m);
3917 GOTO(err_fs_cleanup, rc);
3919 ping_evictor_start();
3921 rc = lu_site_init_finish(s);
3923 GOTO(err_stop_service, rc);
3925 if (obd->obd_recovering == 0)
3926 mdt_postrecov(env, m);
3928 mdt_init_capa_ctxt(env, m);
3930 if (ldlm_timeout == LDLM_TIMEOUT_DEFAULT)
3936 ping_evictor_stop();
3937 mdt_stop_ptlrpc_service(m);
3939 target_recovery_fini(obd);
3940 mdt_fs_cleanup(env, m);
3942 del_timer(&m->mdt_ck_timer);
3943 mdt_ck_thread_stop(m);
3945 upcall_cache_cleanup(m->mdt_identity_cache);
3946 m->mdt_identity_cache = NULL;
3947 ldlm_namespace_free(m->mdt_namespace, 0);
3948 obd->obd_namespace = m->mdt_namespace = NULL;
3950 mdt_seq_fini(env, m);
3952 mdt_fld_fini(env, m);
3954 mdt_stack_fini(env, m, md2lu_dev(m->mdt_child));
3957 lprocfs_obd_cleanup(obd);
3963 md_device_fini(&m->mdt_md_dev);
3967 /* used by MGS to process specific configurations */
3968 static int mdt_process_config(const struct lu_env *env,
3969 struct lu_device *d, struct lustre_cfg *cfg)
3971 struct mdt_device *m = mdt_dev(d);
3972 struct md_device *md_next = m->mdt_child;
3973 struct lu_device *next = md2lu_dev(md_next);
3977 switch (cfg->lcfg_command) {
3978 case LCFG_SPTLRPC_CONF: {
3979 struct sptlrpc_conf_log *log;
3980 struct sptlrpc_rule_set tmp_rset;
3982 log = sptlrpc_conf_log_extract(cfg);
3988 sptlrpc_rule_set_init(&tmp_rset);
3990 rc = sptlrpc_rule_set_from_log(&tmp_rset, log);
3992 CERROR("mdt %p: failed get sptlrpc rules: %d\n", m, rc);
3996 write_lock(&m->mdt_sptlrpc_lock);
3997 sptlrpc_rule_set_free(&m->mdt_sptlrpc_rset);
3998 m->mdt_sptlrpc_rset = tmp_rset;
3999 write_unlock(&m->mdt_sptlrpc_lock);
4001 sptlrpc_target_update_exp_flavor(
4002 md2lu_dev(&m->mdt_md_dev)->ld_obd, &tmp_rset);
4007 struct lprocfs_static_vars lvars;
4008 struct obd_device *obd = d->ld_obd;
4010 lprocfs_mdt_init_vars(&lvars);
4011 rc = class_process_proc_param(PARAM_MDT, lvars.obd_vars, cfg, obd);
4013 /* others are passed further */
4014 rc = next->ld_ops->ldo_process_config(env, next, cfg);
4019 * Add mdc hook to get first MDT uuid and connect it to
4020 * ls->controller to use for seq manager.
4022 rc = next->ld_ops->ldo_process_config(env, next, cfg);
4024 CERROR("Can't add mdc, rc %d\n", rc);
4026 rc = mdt_seq_init_cli(env, mdt_dev(d), cfg);
4029 /* others are passed further */
4030 rc = next->ld_ops->ldo_process_config(env, next, cfg);
4036 static struct lu_object *mdt_object_alloc(const struct lu_env *env,
4037 const struct lu_object_header *hdr,
4038 struct lu_device *d)
4040 struct mdt_object *mo;
4046 struct lu_object *o;
4047 struct lu_object_header *h;
4049 o = &mo->mot_obj.mo_lu;
4050 h = &mo->mot_header;
4051 lu_object_header_init(h);
4052 lu_object_init(o, h, d);
4053 lu_object_add_top(h, o);
4054 o->lo_ops = &mdt_obj_ops;
4060 static int mdt_object_init(const struct lu_env *env, struct lu_object *o)
4062 struct mdt_device *d = mdt_dev(o->lo_dev);
4063 struct lu_device *under;
4064 struct lu_object *below;
4068 CDEBUG(D_INFO, "object init, fid = "DFID"\n",
4069 PFID(lu_object_fid(o)));
4071 under = &d->mdt_child->md_lu_dev;
4072 below = under->ld_ops->ldo_object_alloc(env, o->lo_header, under);
4073 if (below != NULL) {
4074 lu_object_add(o, below);
4081 static void mdt_object_free(const struct lu_env *env, struct lu_object *o)
4083 struct mdt_object *mo = mdt_obj(o);
4084 struct lu_object_header *h;
4088 CDEBUG(D_INFO, "object free, fid = "DFID"\n",
4089 PFID(lu_object_fid(o)));
4092 lu_object_header_fini(h);
4097 static int mdt_object_print(const struct lu_env *env, void *cookie,
4098 lu_printer_t p, const struct lu_object *o)
4100 return (*p)(env, cookie, LUSTRE_MDT_NAME"-object@%p", o);
4103 static struct lu_device_operations mdt_lu_ops = {
4104 .ldo_object_alloc = mdt_object_alloc,
4105 .ldo_process_config = mdt_process_config
4108 static struct lu_object_operations mdt_obj_ops = {
4109 .loo_object_init = mdt_object_init,
4110 .loo_object_free = mdt_object_free,
4111 .loo_object_print = mdt_object_print
4114 /* mds_connect_internal */
4115 static int mdt_connect_internal(struct obd_export *exp,
4116 struct mdt_device *mdt,
4117 struct obd_connect_data *data)
4122 data->ocd_connect_flags &= MDT_CONNECT_SUPPORTED;
4123 data->ocd_ibits_known &= MDS_INODELOCK_FULL;
4125 /* If no known bits (which should not happen, probably,
4126 as everybody should support LOOKUP and UPDATE bits at least)
4127 revert to compat mode with plain locks. */
4128 if (!data->ocd_ibits_known &&
4129 data->ocd_connect_flags & OBD_CONNECT_IBITS)
4130 data->ocd_connect_flags &= ~OBD_CONNECT_IBITS;
4132 if (!mdt->mdt_opts.mo_acl)
4133 data->ocd_connect_flags &= ~OBD_CONNECT_ACL;
4135 if (!mdt->mdt_opts.mo_user_xattr)
4136 data->ocd_connect_flags &= ~OBD_CONNECT_XATTR;
4138 if (!mdt->mdt_opts.mo_mds_capa)
4139 data->ocd_connect_flags &= ~OBD_CONNECT_MDS_CAPA;
4141 if (!mdt->mdt_opts.mo_oss_capa)
4142 data->ocd_connect_flags &= ~OBD_CONNECT_OSS_CAPA;
4144 spin_lock(&exp->exp_lock);
4145 exp->exp_connect_flags = data->ocd_connect_flags;
4146 spin_unlock(&exp->exp_lock);
4147 data->ocd_version = LUSTRE_VERSION_CODE;
4148 exp->exp_mdt_data.med_ibits_known = data->ocd_ibits_known;
4152 if (mdt->mdt_opts.mo_acl &&
4153 ((exp->exp_connect_flags & OBD_CONNECT_ACL) == 0)) {
4154 CWARN("%s: MDS requires ACL support but client does not\n",
4155 mdt->mdt_md_dev.md_lu_dev.ld_obd->obd_name);
4160 flags = OBD_CONNECT_LCL_CLIENT | OBD_CONNECT_RMT_CLIENT;
4161 if ((exp->exp_connect_flags & flags) == flags) {
4162 CWARN("%s: both local and remote client flags are set\n",
4163 mdt->mdt_md_dev.md_lu_dev.ld_obd->obd_name);
4167 if (mdt->mdt_opts.mo_mds_capa &&
4168 ((exp->exp_connect_flags & OBD_CONNECT_MDS_CAPA) == 0)) {
4169 CWARN("%s: MDS requires capability support, but client not\n",
4170 mdt->mdt_md_dev.md_lu_dev.ld_obd->obd_name);
4174 if (mdt->mdt_opts.mo_oss_capa &&
4175 ((exp->exp_connect_flags & OBD_CONNECT_OSS_CAPA) == 0)) {
4176 CWARN("%s: MDS requires OSS capability support, "
4178 mdt->mdt_md_dev.md_lu_dev.ld_obd->obd_name);
4185 /* mds_connect copy */
4186 static int mdt_obd_connect(const struct lu_env *env,
4187 struct lustre_handle *conn, struct obd_device *obd,
4188 struct obd_uuid *cluuid,
4189 struct obd_connect_data *data)
4191 struct mdt_thread_info *info;
4192 struct mdt_client_data *mcd;
4193 struct obd_export *exp;
4194 struct mdt_device *mdt;
4195 struct ptlrpc_request *req;
4199 LASSERT(env != NULL);
4200 if (!conn || !obd || !cluuid)
4203 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
4204 req = info->mti_pill.rc_req;
4205 mdt = mdt_dev(obd->obd_lu_dev);
4207 rc = class_connect(conn, obd, cluuid);
4211 exp = class_conn2export(conn);
4212 LASSERT(exp != NULL);
4214 CDEBUG(D_SEC, "from %s\n", sptlrpc_part2name(req->rq_sp_from));
4216 spin_lock(&exp->exp_lock);
4217 exp->exp_sp_peer = req->rq_sp_from;
4219 read_lock(&mdt->mdt_sptlrpc_lock);
4220 sptlrpc_rule_set_choose(&mdt->mdt_sptlrpc_rset, exp->exp_sp_peer,
4221 req->rq_peer.nid, &exp->exp_flvr);
4222 read_unlock(&mdt->mdt_sptlrpc_lock);
4224 if (exp->exp_flvr.sf_rpc != req->rq_flvr.sf_rpc) {
4225 CERROR("invalid rpc flavor %x, expect %x, from %s\n",
4226 req->rq_flvr.sf_rpc, exp->exp_flvr.sf_rpc,
4227 libcfs_nid2str(req->rq_peer.nid));
4228 exp->exp_flvr.sf_rpc = SPTLRPC_FLVR_INVALID;
4229 spin_unlock(&exp->exp_lock);
4232 spin_unlock(&exp->exp_lock);
4234 rc = mdt_connect_internal(exp, mdt, data);
4238 struct mdt_thread_info *mti;
4239 mti = lu_context_key_get(&env->le_ctx,
4241 LASSERT(mti != NULL);
4243 memcpy(mcd->mcd_uuid, cluuid, sizeof mcd->mcd_uuid);
4244 exp->exp_mdt_data.med_mcd = mcd;
4245 rc = mdt_client_new(env, mdt);
4248 exp->exp_mdt_data.med_mcd = NULL;
4255 class_disconnect(exp);
4257 class_export_put(exp);
4262 static int mdt_obd_reconnect(const struct lu_env *env,
4263 struct obd_export *exp, struct obd_device *obd,
4264 struct obd_uuid *cluuid,
4265 struct obd_connect_data *data)
4267 struct mdt_thread_info *info;
4268 struct mdt_device *mdt;
4269 struct ptlrpc_request *req;
4273 if (exp == NULL || obd == NULL || cluuid == NULL)
4276 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
4277 req = info->mti_pill.rc_req;
4278 mdt = mdt_dev(obd->obd_lu_dev);
4280 CDEBUG(D_SEC, "from %s\n", sptlrpc_part2name(req->rq_sp_from));
4282 spin_lock(&exp->exp_lock);
4283 if (exp->exp_flvr.sf_rpc == SPTLRPC_FLVR_INVALID) {
4284 exp->exp_sp_peer = req->rq_sp_from;
4286 read_lock(&mdt->mdt_sptlrpc_lock);
4287 sptlrpc_rule_set_choose(&mdt->mdt_sptlrpc_rset,
4289 req->rq_peer.nid, &exp->exp_flvr);
4290 read_unlock(&mdt->mdt_sptlrpc_lock);
4292 if (exp->exp_flvr.sf_rpc != req->rq_flvr.sf_rpc) {
4293 CERROR("invalid rpc flavor %x, expect %x, from %s\n",
4294 req->rq_flvr.sf_rpc, exp->exp_flvr.sf_rpc,
4295 libcfs_nid2str(req->rq_peer.nid));
4296 exp->exp_flvr.sf_rpc = SPTLRPC_FLVR_INVALID;
4297 spin_unlock(&exp->exp_lock);
4301 spin_unlock(&exp->exp_lock);
4303 rc = mdt_connect_internal(exp, mdt_dev(obd->obd_lu_dev), data);
4308 static int mdt_obd_disconnect(struct obd_export *exp)
4310 struct mdt_device *mdt = mdt_dev(exp->exp_obd->obd_lu_dev);
4315 class_export_get(exp);
4317 /* Disconnect early so that clients can't keep using export */
4318 rc = class_disconnect(exp);
4319 if (mdt->mdt_namespace != NULL || exp->exp_obd->obd_namespace != NULL)
4320 ldlm_cancel_locks_for_export(exp);
4322 /* complete all outstanding replies */
4323 spin_lock(&exp->exp_lock);
4324 while (!list_empty(&exp->exp_outstanding_replies)) {
4325 struct ptlrpc_reply_state *rs =
4326 list_entry(exp->exp_outstanding_replies.next,
4327 struct ptlrpc_reply_state, rs_exp_list);
4328 struct ptlrpc_service *svc = rs->rs_service;
4330 spin_lock(&svc->srv_lock);
4331 list_del_init(&rs->rs_exp_list);
4332 ptlrpc_schedule_difficult_reply(rs);
4333 spin_unlock(&svc->srv_lock);
4335 spin_unlock(&exp->exp_lock);
4337 class_export_put(exp);
4341 /* FIXME: Can we avoid using these two interfaces? */
4342 static int mdt_init_export(struct obd_export *exp)
4344 struct mdt_export_data *med = &exp->exp_mdt_data;
4347 INIT_LIST_HEAD(&med->med_open_head);
4348 spin_lock_init(&med->med_open_lock);
4349 sema_init(&med->med_idmap_sem, 1);
4350 med->med_idmap = NULL;
4351 spin_lock(&exp->exp_lock);
4352 exp->exp_connecting = 1;
4353 spin_unlock(&exp->exp_lock);
4357 static int mdt_destroy_export(struct obd_export *export)
4359 struct mdt_export_data *med;
4360 struct obd_device *obd = export->exp_obd;
4361 struct mdt_device *mdt;
4362 struct mdt_thread_info *info;
4370 med = &export->exp_mdt_data;
4371 if (med->med_rmtclient)
4372 mdt_cleanup_idmap(med);
4374 target_destroy_export(export);
4376 if (obd_uuid_equals(&export->exp_client_uuid, &obd->obd_uuid))
4379 mdt = mdt_dev(obd->obd_lu_dev);
4380 LASSERT(mdt != NULL);
4382 rc = lu_env_init(&env, NULL, LCT_MD_THREAD);
4386 info = lu_context_key_get(&env.le_ctx, &mdt_thread_key);
4387 LASSERT(info != NULL);
4388 memset(info, 0, sizeof *info);
4389 info->mti_env = &env;
4390 info->mti_mdt = mdt;
4391 info->mti_exp = export;
4393 ma = &info->mti_attr;
4394 lmm_size = ma->ma_lmm_size = mdt->mdt_max_mdsize;
4395 cookie_size = ma->ma_cookie_size = mdt->mdt_max_cookiesize;
4396 OBD_ALLOC(ma->ma_lmm, lmm_size);
4397 OBD_ALLOC(ma->ma_cookie, cookie_size);
4399 if (ma->ma_lmm == NULL || ma->ma_cookie == NULL)
4400 GOTO(out, rc = -ENOMEM);
4401 ma->ma_need = MA_LOV | MA_COOKIE;
4403 /* Close any open files (which may also cause orphan unlinking). */
4404 spin_lock(&med->med_open_lock);
4405 while (!list_empty(&med->med_open_head)) {
4406 struct list_head *tmp = med->med_open_head.next;
4407 struct mdt_file_data *mfd =
4408 list_entry(tmp, struct mdt_file_data, mfd_list);
4410 /* Remove mfd handle so it can't be found again.
4411 * We are consuming the mfd_list reference here. */
4412 class_handle_unhash(&mfd->mfd_handle);
4413 list_del_init(&mfd->mfd_list);
4414 spin_unlock(&med->med_open_lock);
4415 mdt_mfd_close(info, mfd);
4416 /* TODO: if we close the unlinked file,
4417 * we need to remove it's objects from OST */
4418 memset(&ma->ma_attr, 0, sizeof(ma->ma_attr));
4419 spin_lock(&med->med_open_lock);
4420 ma->ma_lmm_size = lmm_size;
4421 ma->ma_cookie_size = cookie_size;
4422 ma->ma_need = MA_LOV | MA_COOKIE;
4425 spin_unlock(&med->med_open_lock);
4426 info->mti_mdt = NULL;
4427 mdt_client_del(&env, mdt);
4432 OBD_FREE(ma->ma_lmm, lmm_size);
4436 OBD_FREE(ma->ma_cookie, cookie_size);
4437 ma->ma_cookie = NULL;
4444 static void mdt_allow_cli(struct mdt_device *m, unsigned int flag)
4446 if (flag & CONFIG_LOG)
4447 m->mdt_fl_cfglog = 1;
4448 if (flag & CONFIG_SYNC)
4449 m->mdt_fl_synced = 1;
4451 if (m->mdt_fl_cfglog /* bz11778: && m->mdt_fl_synced */)
4452 /* Open for clients */
4453 m->mdt_md_dev.md_lu_dev.ld_obd->obd_no_conn = 0;
4456 static int mdt_upcall(const struct lu_env *env, struct md_device *md,
4457 enum md_upcall_event ev)
4459 struct mdt_device *m = mdt_dev(&md->md_lu_dev);
4460 struct md_device *next = m->mdt_child;
4461 struct mdt_thread_info *mti;
4467 rc = next->md_ops->mdo_maxsize_get(env, next,
4469 &m->mdt_max_cookiesize);
4470 CDEBUG(D_INFO, "get max mdsize %d max cookiesize %d\n",
4471 m->mdt_max_mdsize, m->mdt_max_cookiesize);
4472 mdt_allow_cli(m, CONFIG_SYNC);
4475 mti = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
4476 mti->mti_no_need_trans = 1;
4477 CDEBUG(D_INFO, "disable mdt trans for this thread\n");
4480 /* Check that MDT is not yet configured */
4481 LASSERT(!m->mdt_fl_cfglog);
4484 CERROR("invalid event\n");
4491 static int mdt_obd_notify(struct obd_device *host,
4492 struct obd_device *watched,
4493 enum obd_notify_event ev, void *data)
4498 case OBD_NOTIFY_CONFIG:
4499 mdt_allow_cli(mdt_dev(host->obd_lu_dev), (unsigned int)data);
4502 CDEBUG(D_INFO, "Unhandled notification %#x\n", ev);
4507 static int mdt_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
4508 void *karg, void *uarg)
4511 struct obd_device *obd= exp->exp_obd;
4512 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
4513 struct dt_device *dt = mdt->mdt_bottom;
4517 CDEBUG(D_IOCTL, "handling ioctl cmd %#x\n", cmd);
4518 rc = lu_env_init(&env, NULL, LCT_MD_THREAD);
4524 rc = dt->dd_ops->dt_sync(&env, dt);
4526 case OBD_IOC_SET_READONLY:
4527 rc = dt->dd_ops->dt_sync(&env, dt);
4528 dt->dd_ops->dt_ro(&env, dt);
4530 case OBD_IOC_ABORT_RECOVERY:
4531 CERROR("Aborting recovery for device %s\n", obd->obd_name);
4532 target_stop_recovery_thread(obd);
4536 CERROR("Not supported cmd = %d for device %s\n",
4537 cmd, obd->obd_name);
4545 int mdt_postrecov(const struct lu_env *env, struct mdt_device *mdt)
4547 struct lu_device *ld = md2lu_dev(mdt->mdt_child);
4548 struct obd_device *obd = mdt->mdt_md_dev.md_lu_dev.ld_obd;
4551 /* if some clients didn't participate in recovery then we can possibly
4552 * lost sequence. Now we should increase sequence for safe value */
4553 lost = obd->obd_max_recoverable_clients - obd->obd_connected_clients;
4554 mdt_seq_adjust(env, mdt, lost);
4556 rc = ld->ld_ops->ldo_recovery_complete(env, ld);
4560 int mdt_obd_postrecov(struct obd_device *obd)
4565 rc = lu_env_init(&env, NULL, LCT_MD_THREAD);
4568 rc = mdt_postrecov(&env, mdt_dev(obd->obd_lu_dev));
4573 static struct obd_ops mdt_obd_device_ops = {
4574 .o_owner = THIS_MODULE,
4575 .o_connect = mdt_obd_connect,
4576 .o_reconnect = mdt_obd_reconnect,
4577 .o_disconnect = mdt_obd_disconnect,
4578 .o_init_export = mdt_init_export,
4579 .o_destroy_export = mdt_destroy_export,
4580 .o_iocontrol = mdt_iocontrol,
4581 .o_postrecov = mdt_obd_postrecov,
4582 .o_notify = mdt_obd_notify
4585 static struct lu_device* mdt_device_fini(const struct lu_env *env,
4586 struct lu_device *d)
4588 struct mdt_device *m = mdt_dev(d);
4595 static void mdt_device_free(const struct lu_env *env, struct lu_device *d)
4597 struct mdt_device *m = mdt_dev(d);
4602 static struct lu_device *mdt_device_alloc(const struct lu_env *env,
4603 struct lu_device_type *t,
4604 struct lustre_cfg *cfg)
4606 struct lu_device *l;
4607 struct mdt_device *m;
4613 l = &m->mdt_md_dev.md_lu_dev;
4614 rc = mdt_init0(env, m, t, cfg);
4620 md_upcall_init(&m->mdt_md_dev, mdt_upcall);
4622 l = ERR_PTR(-ENOMEM);
4626 /* context key constructor/destructor: mdt_key_init, mdt_key_fini */
4627 LU_KEY_INIT_FINI(mdt, struct mdt_thread_info);
4629 /* context key: mdt_thread_key */
4630 LU_CONTEXT_KEY_DEFINE(mdt, LCT_MD_THREAD);
4632 /* context key constructor/destructor: mdt_txn_key_init, mdt_txn_key_fini */
4633 LU_KEY_INIT_FINI(mdt_txn, struct mdt_txn_info);
4635 struct lu_context_key mdt_txn_key = {
4636 .lct_tags = LCT_TX_HANDLE,
4637 .lct_init = mdt_txn_key_init,
4638 .lct_fini = mdt_txn_key_fini
4641 struct md_ucred *mdt_ucred(const struct mdt_thread_info *info)
4643 return md_ucred(info->mti_env);
4646 /* type constructor/destructor: mdt_type_init, mdt_type_fini */
4647 LU_TYPE_INIT_FINI(mdt, &mdt_thread_key, &mdt_txn_key);
4649 static struct lu_device_type_operations mdt_device_type_ops = {
4650 .ldto_init = mdt_type_init,
4651 .ldto_fini = mdt_type_fini,
4653 .ldto_device_alloc = mdt_device_alloc,
4654 .ldto_device_free = mdt_device_free,
4655 .ldto_device_fini = mdt_device_fini
4658 static struct lu_device_type mdt_device_type = {
4659 .ldt_tags = LU_DEVICE_MD,
4660 .ldt_name = LUSTRE_MDT_NAME,
4661 .ldt_ops = &mdt_device_type_ops,
4662 .ldt_ctx_tags = LCT_MD_THREAD
4665 static int __init mdt_mod_init(void)
4667 struct lprocfs_static_vars lvars;
4670 mdt_num_threads = MDT_NUM_THREADS;
4671 lprocfs_mdt_init_vars(&lvars);
4672 rc = class_register_type(&mdt_obd_device_ops, NULL,
4673 lvars.module_vars, LUSTRE_MDT_NAME,
4679 static void __exit mdt_mod_exit(void)
4681 class_unregister_type(LUSTRE_MDT_NAME);
4685 #define DEF_HNDL(prefix, base, suffix, flags, opc, fn, fmt) \
4686 [prefix ## _ ## opc - prefix ## _ ## base] = { \
4688 .mh_fail_id = OBD_FAIL_ ## prefix ## _ ## opc ## suffix, \
4689 .mh_opc = prefix ## _ ## opc, \
4690 .mh_flags = flags, \
4695 #define DEF_MDT_HNDL(flags, name, fn, fmt) \
4696 DEF_HNDL(MDS, GETATTR, _NET, flags, name, fn, fmt)
4698 #define DEF_SEQ_HNDL(flags, name, fn, fmt) \
4699 DEF_HNDL(SEQ, QUERY, _NET, flags, name, fn, fmt)
4701 #define DEF_FLD_HNDL(flags, name, fn, fmt) \
4702 DEF_HNDL(FLD, QUERY, _NET, flags, name, fn, fmt)
4704 * Request with a format known in advance
4706 #define DEF_MDT_HNDL_F(flags, name, fn) \
4707 DEF_HNDL(MDS, GETATTR, _NET, flags, name, fn, &RQF_MDS_ ## name)
4709 #define DEF_SEQ_HNDL_F(flags, name, fn) \
4710 DEF_HNDL(SEQ, QUERY, _NET, flags, name, fn, &RQF_SEQ_ ## name)
4712 #define DEF_FLD_HNDL_F(flags, name, fn) \
4713 DEF_HNDL(FLD, QUERY, _NET, flags, name, fn, &RQF_FLD_ ## name)
4715 * Request with a format we do not yet know
4717 #define DEF_MDT_HNDL_0(flags, name, fn) \
4718 DEF_HNDL(MDS, GETATTR, _NET, flags, name, fn, NULL)
4720 static struct mdt_handler mdt_mds_ops[] = {
4721 DEF_MDT_HNDL_F(0, CONNECT, mdt_connect),
4722 DEF_MDT_HNDL_F(0, DISCONNECT, mdt_disconnect),
4723 DEF_MDT_HNDL_F(0, SET_INFO, mdt_set_info),
4724 DEF_MDT_HNDL_F(0 |HABEO_REFERO, GETSTATUS, mdt_getstatus),
4725 DEF_MDT_HNDL_F(HABEO_CORPUS, GETATTR, mdt_getattr),
4726 DEF_MDT_HNDL_F(HABEO_CORPUS|HABEO_REFERO, GETATTR_NAME, mdt_getattr_name),
4727 DEF_MDT_HNDL_F(HABEO_CORPUS|MUTABOR, SETXATTR, mdt_setxattr),
4728 DEF_MDT_HNDL_F(HABEO_CORPUS, GETXATTR, mdt_getxattr),
4729 DEF_MDT_HNDL_F(0 |HABEO_REFERO, STATFS, mdt_statfs),
4730 DEF_MDT_HNDL_F(0 |MUTABOR, REINT, mdt_reint),
4731 DEF_MDT_HNDL_F(HABEO_CORPUS, CLOSE, mdt_close),
4732 DEF_MDT_HNDL_F(HABEO_CORPUS, DONE_WRITING, mdt_done_writing),
4733 DEF_MDT_HNDL_F(0 |HABEO_REFERO, PIN, mdt_pin),
4734 DEF_MDT_HNDL_0(0, SYNC, mdt_sync),
4735 DEF_MDT_HNDL_F(HABEO_CORPUS|HABEO_REFERO, IS_SUBDIR, mdt_is_subdir),
4736 DEF_MDT_HNDL_0(0, QUOTACHECK, mdt_quotacheck_handle),
4737 DEF_MDT_HNDL_0(0, QUOTACTL, mdt_quotactl_handle)
4740 #define DEF_OBD_HNDL(flags, name, fn) \
4741 DEF_HNDL(OBD, PING, _NET, flags, name, fn, NULL)
4744 static struct mdt_handler mdt_obd_ops[] = {
4745 DEF_OBD_HNDL(0, PING, mdt_obd_ping),
4746 DEF_OBD_HNDL(0, LOG_CANCEL, mdt_obd_log_cancel),
4747 DEF_OBD_HNDL(0, QC_CALLBACK, mdt_obd_qc_callback)
4750 #define DEF_DLM_HNDL_0(flags, name, fn) \
4751 DEF_HNDL(LDLM, ENQUEUE, , flags, name, fn, NULL)
4752 #define DEF_DLM_HNDL_F(flags, name, fn) \
4753 DEF_HNDL(LDLM, ENQUEUE, , flags, name, fn, &RQF_LDLM_ ## name)
4755 static struct mdt_handler mdt_dlm_ops[] = {
4756 DEF_DLM_HNDL_F(HABEO_CLAVIS, ENQUEUE, mdt_enqueue),
4757 DEF_DLM_HNDL_0(HABEO_CLAVIS, CONVERT, mdt_convert),
4758 DEF_DLM_HNDL_0(0, BL_CALLBACK, mdt_bl_callback),
4759 DEF_DLM_HNDL_0(0, CP_CALLBACK, mdt_cp_callback)
4762 static struct mdt_handler mdt_llog_ops[] = {
4765 #define DEF_SEC_CTX_HNDL(name, fn) \
4766 DEF_HNDL(SEC_CTX, INIT, _NET, 0, name, fn, NULL)
4768 static struct mdt_handler mdt_sec_ctx_ops[] = {
4769 DEF_SEC_CTX_HNDL(INIT, mdt_sec_ctx_handle),
4770 DEF_SEC_CTX_HNDL(INIT_CONT, mdt_sec_ctx_handle),
4771 DEF_SEC_CTX_HNDL(FINI, mdt_sec_ctx_handle)
4774 static struct mdt_opc_slice mdt_regular_handlers[] = {
4776 .mos_opc_start = MDS_GETATTR,
4777 .mos_opc_end = MDS_LAST_OPC,
4778 .mos_hs = mdt_mds_ops
4781 .mos_opc_start = OBD_PING,
4782 .mos_opc_end = OBD_LAST_OPC,
4783 .mos_hs = mdt_obd_ops
4786 .mos_opc_start = LDLM_ENQUEUE,
4787 .mos_opc_end = LDLM_LAST_OPC,
4788 .mos_hs = mdt_dlm_ops
4791 .mos_opc_start = LLOG_ORIGIN_HANDLE_CREATE,
4792 .mos_opc_end = LLOG_LAST_OPC,
4793 .mos_hs = mdt_llog_ops
4796 .mos_opc_start = SEC_CTX_INIT,
4797 .mos_opc_end = SEC_LAST_OPC,
4798 .mos_hs = mdt_sec_ctx_ops
4805 static struct mdt_handler mdt_readpage_ops[] = {
4806 DEF_MDT_HNDL_F(0, CONNECT, mdt_connect),
4807 DEF_MDT_HNDL_F(HABEO_CORPUS|HABEO_REFERO, READPAGE, mdt_readpage),
4808 #ifdef HAVE_SPLIT_SUPPORT
4809 DEF_MDT_HNDL_F(HABEO_CORPUS|HABEO_REFERO, WRITEPAGE, mdt_writepage),
4813 * XXX: this is ugly and should be fixed one day, see mdc_close() for
4814 * detailed comments. --umka
4816 DEF_MDT_HNDL_F(HABEO_CORPUS, CLOSE, mdt_close),
4817 DEF_MDT_HNDL_F(HABEO_CORPUS, DONE_WRITING, mdt_done_writing),
4820 static struct mdt_opc_slice mdt_readpage_handlers[] = {
4822 .mos_opc_start = MDS_GETATTR,
4823 .mos_opc_end = MDS_LAST_OPC,
4824 .mos_hs = mdt_readpage_ops
4831 static struct mdt_handler mdt_xmds_ops[] = {
4832 DEF_MDT_HNDL_F(0, CONNECT, mdt_connect),
4833 DEF_MDT_HNDL_F(HABEO_CORPUS , GETATTR, mdt_getattr),
4834 DEF_MDT_HNDL_F(0 | MUTABOR , REINT, mdt_reint),
4835 DEF_MDT_HNDL_F(HABEO_CORPUS|HABEO_REFERO, IS_SUBDIR, mdt_is_subdir),
4838 static struct mdt_opc_slice mdt_xmds_handlers[] = {
4840 .mos_opc_start = MDS_GETATTR,
4841 .mos_opc_end = MDS_LAST_OPC,
4842 .mos_hs = mdt_xmds_ops
4845 .mos_opc_start = OBD_PING,
4846 .mos_opc_end = OBD_LAST_OPC,
4847 .mos_hs = mdt_obd_ops
4850 .mos_opc_start = SEC_CTX_INIT,
4851 .mos_opc_end = SEC_LAST_OPC,
4852 .mos_hs = mdt_sec_ctx_ops
4859 static struct mdt_handler mdt_seq_ops[] = {
4860 DEF_SEQ_HNDL_F(0, QUERY, (int (*)(struct mdt_thread_info *))seq_query)
4863 static struct mdt_opc_slice mdt_seq_handlers[] = {
4865 .mos_opc_start = SEQ_QUERY,
4866 .mos_opc_end = SEQ_LAST_OPC,
4867 .mos_hs = mdt_seq_ops
4874 static struct mdt_handler mdt_fld_ops[] = {
4875 DEF_FLD_HNDL_F(0, QUERY, (int (*)(struct mdt_thread_info *))fld_query)
4878 static struct mdt_opc_slice mdt_fld_handlers[] = {
4880 .mos_opc_start = FLD_QUERY,
4881 .mos_opc_end = FLD_LAST_OPC,
4882 .mos_hs = mdt_fld_ops
4889 MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
4890 MODULE_DESCRIPTION("Lustre Meta-data Target ("LUSTRE_MDT_NAME")");
4891 MODULE_LICENSE("GPL");
4893 CFS_MODULE_PARM(mdt_num_threads, "ul", ulong, 0444,
4894 "number of mdt service threads to start");
4896 cfs_module(mdt, "0.2.0", mdt_mod_init, mdt_mod_exit);