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));
1350 rc = mdt_check_ucred(info);
1352 RETURN(err_serious(rc));
1355 * prepare @rdpg before calling lower layers and transfer itself. Here
1356 * reqbody->size contains offset of where to start to read and
1357 * reqbody->nlink contains number bytes to read.
1359 rdpg->rp_hash = reqbody->size;
1360 if ((__u64)rdpg->rp_hash != reqbody->size) {
1361 CERROR("Invalid hash: %#llx != %#llx\n",
1362 (__u64)rdpg->rp_hash, reqbody->size);
1365 rdpg->rp_count = reqbody->nlink;
1366 rdpg->rp_npages = (rdpg->rp_count + CFS_PAGE_SIZE - 1)>>CFS_PAGE_SHIFT;
1367 OBD_ALLOC(rdpg->rp_pages, rdpg->rp_npages * sizeof rdpg->rp_pages[0]);
1368 if (rdpg->rp_pages == NULL)
1371 for (i = 0; i < rdpg->rp_npages; ++i) {
1372 rdpg->rp_pages[i] = cfs_alloc_page(CFS_ALLOC_STD);
1373 if (rdpg->rp_pages[i] == NULL)
1374 GOTO(free_rdpg, rc = -ENOMEM);
1377 /* call lower layers to fill allocated pages with directory data */
1378 rc = mo_readpage(info->mti_env, mdt_object_child(object), rdpg);
1380 GOTO(free_rdpg, rc);
1382 /* send pages to client */
1383 rc = mdt_sendpage(info, rdpg);
1388 for (i = 0; i < rdpg->rp_npages; i++)
1389 if (rdpg->rp_pages[i] != NULL)
1390 __cfs_free_page(rdpg->rp_pages[i]);
1391 OBD_FREE(rdpg->rp_pages, rdpg->rp_npages * sizeof rdpg->rp_pages[0]);
1393 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_SENDPAGE))
1399 static int mdt_reint_internal(struct mdt_thread_info *info,
1400 struct mdt_lock_handle *lhc,
1403 struct req_capsule *pill = &info->mti_pill;
1404 struct mdt_device *mdt = info->mti_mdt;
1405 struct mdt_body *repbody;
1406 int need_shrink = 0;
1411 if (req_capsule_has_field(pill, &RMF_MDT_MD, RCL_SERVER)) {
1412 req_capsule_set_size(pill, &RMF_MDT_MD, RCL_SERVER,
1413 mdt->mdt_max_mdsize);
1416 if (req_capsule_has_field(pill, &RMF_LOGCOOKIES, RCL_SERVER)) {
1417 req_capsule_set_size(pill, &RMF_LOGCOOKIES, RCL_SERVER,
1418 mdt->mdt_max_cookiesize);
1421 rc = req_capsule_pack(pill);
1423 CERROR("Can't pack response, rc %d\n", rc);
1424 RETURN(err_serious(rc));
1427 if (req_capsule_has_field(pill, &RMF_MDT_BODY, RCL_SERVER)) {
1428 repbody = req_capsule_server_get(pill, &RMF_MDT_BODY);
1430 repbody->eadatasize = 0;
1431 repbody->aclsize = 0;
1434 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_REINT_UNPACK))
1435 GOTO(out_shrink, rc = err_serious(-EFAULT));
1437 rc = mdt_reint_unpack(info, op);
1439 CERROR("Can't unpack reint, rc %d\n", rc);
1440 GOTO(out_shrink, rc = err_serious(rc));
1443 rc = mdt_init_ucred_reint(info);
1445 GOTO(out_shrink, rc);
1447 rc = mdt_fix_attr_ucred(info, op);
1449 GOTO(out_ucred, rc = err_serious(rc));
1452 if (mdt_check_resent(info, mdt_reconstruct, lhc)) {
1453 rc = lustre_msg_get_status(mdt_info_req(info)->rq_repmsg);
1454 GOTO(out_ucred, rc);
1457 rc = mdt_reint_rec(info, lhc);
1460 mdt_exit_ucred(info);
1463 mdt_shrink_reply(info);
1467 static long mdt_reint_opcode(struct mdt_thread_info *info,
1468 const struct req_format **fmt)
1473 opc = err_serious(-EFAULT);
1474 ptr = req_capsule_client_get(&info->mti_pill, &RMF_REINT_OPC);
1477 DEBUG_REQ(D_INODE, mdt_info_req(info), "reint opt = %ld", opc);
1478 if (opc < REINT_MAX && fmt[opc] != NULL)
1479 req_capsule_extend(&info->mti_pill, fmt[opc]);
1481 CERROR("Unsupported opc: %ld\n", opc);
1482 opc = err_serious(opc);
1488 static int mdt_reint(struct mdt_thread_info *info)
1493 static const struct req_format *reint_fmts[REINT_MAX] = {
1494 [REINT_SETATTR] = &RQF_MDS_REINT_SETATTR,
1495 [REINT_CREATE] = &RQF_MDS_REINT_CREATE,
1496 [REINT_LINK] = &RQF_MDS_REINT_LINK,
1497 [REINT_UNLINK] = &RQF_MDS_REINT_UNLINK,
1498 [REINT_RENAME] = &RQF_MDS_REINT_RENAME,
1499 [REINT_OPEN] = &RQF_MDS_REINT_OPEN
1504 opc = mdt_reint_opcode(info, reint_fmts);
1507 * No lock possible here from client to pass it to reint code
1510 rc = mdt_reint_internal(info, NULL, opc);
1515 info->mti_fail_id = OBD_FAIL_MDS_REINT_NET_REP;
1519 /* TODO these two methods not available now. */
1521 /* this should sync the whole device */
1522 static int mdt_device_sync(struct mdt_thread_info *info)
1527 /* this should sync this object */
1528 static int mdt_object_sync(struct mdt_thread_info *info)
1533 static int mdt_sync(struct mdt_thread_info *info)
1535 struct req_capsule *pill = &info->mti_pill;
1536 struct mdt_body *body;
1540 /* The fid may be zero, so we req_capsule_set manually */
1541 req_capsule_set(pill, &RQF_MDS_SYNC);
1543 body = req_capsule_client_get(pill, &RMF_MDT_BODY);
1545 RETURN(err_serious(-EINVAL));
1547 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_SYNC_PACK))
1548 RETURN(err_serious(-ENOMEM));
1550 if (fid_seq(&body->fid1) == 0) {
1551 /* sync the whole device */
1552 rc = req_capsule_pack(pill);
1554 rc = mdt_device_sync(info);
1556 rc = err_serious(rc);
1558 /* sync an object */
1559 rc = mdt_unpack_req_pack_rep(info, HABEO_CORPUS|HABEO_REFERO);
1561 rc = mdt_object_sync(info);
1563 struct md_object *next;
1564 const struct lu_fid *fid;
1565 struct lu_attr *la = &info->mti_attr.ma_attr;
1567 next = mdt_object_child(info->mti_object);
1568 info->mti_attr.ma_need = MA_INODE;
1569 info->mti_attr.ma_valid = 0;
1570 rc = mo_attr_get(info->mti_env, next,
1573 body = req_capsule_server_get(pill,
1575 fid = mdt_object_fid(info->mti_object);
1576 mdt_pack_attr2body(info, body, la, fid);
1580 rc = err_serious(rc);
1585 static int mdt_quotacheck_handle(struct mdt_thread_info *info)
1587 return err_serious(-EOPNOTSUPP);
1590 static int mdt_quotactl_handle(struct mdt_thread_info *info)
1592 return err_serious(-EOPNOTSUPP);
1596 * OBD PING and other handlers.
1598 static int mdt_obd_ping(struct mdt_thread_info *info)
1602 rc = target_handle_ping(mdt_info_req(info));
1604 rc = err_serious(rc);
1608 static int mdt_obd_log_cancel(struct mdt_thread_info *info)
1610 return err_serious(-EOPNOTSUPP);
1613 static int mdt_obd_qc_callback(struct mdt_thread_info *info)
1615 return err_serious(-EOPNOTSUPP);
1622 static struct ldlm_callback_suite cbs = {
1623 .lcs_completion = ldlm_server_completion_ast,
1624 .lcs_blocking = ldlm_server_blocking_ast,
1628 static int mdt_enqueue(struct mdt_thread_info *info)
1630 struct ptlrpc_request *req;
1635 * info->mti_dlm_req already contains swapped and (if necessary)
1636 * converted dlm request.
1638 LASSERT(info->mti_dlm_req != NULL);
1640 if (OBD_FAIL_CHECK(OBD_FAIL_LDLM_ENQUEUE)) {
1641 info->mti_fail_id = OBD_FAIL_LDLM_ENQUEUE;
1645 req = mdt_info_req(info);
1648 * Lock without inodebits makes no sense and will oops later in
1649 * ldlm. Let's check it now to see if we have wrong lock from client or
1650 * bits get corrupted somewhere in mdt_intent_policy().
1652 req_bits = info->mti_dlm_req->lock_desc.l_policy_data.l_inodebits.bits;
1653 /* This is disabled because we need to support liblustre flock.
1654 * LASSERT(req_bits != 0);
1657 rc = ldlm_handle_enqueue0(info->mti_mdt->mdt_namespace,
1658 req, info->mti_dlm_req, &cbs);
1659 info->mti_fail_id = OBD_FAIL_LDLM_REPLY;
1660 return rc ? err_serious(rc) : req->rq_status;
1663 static int mdt_convert(struct mdt_thread_info *info)
1666 struct ptlrpc_request *req;
1668 LASSERT(info->mti_dlm_req);
1669 req = mdt_info_req(info);
1670 rc = ldlm_handle_convert0(req, info->mti_dlm_req);
1671 return rc ? err_serious(rc) : req->rq_status;
1674 static int mdt_bl_callback(struct mdt_thread_info *info)
1676 CERROR("bl callbacks should not happen on MDS\n");
1678 return err_serious(-EOPNOTSUPP);
1681 static int mdt_cp_callback(struct mdt_thread_info *info)
1683 CERROR("cp callbacks should not happen on MDS\n");
1685 return err_serious(-EOPNOTSUPP);
1689 * sec context handlers
1691 static int mdt_sec_ctx_handle(struct mdt_thread_info *info)
1695 rc = mdt_handle_idmap(info);
1698 struct ptlrpc_request *req = mdt_info_req(info);
1701 opc = lustre_msg_get_opc(req->rq_reqmsg);
1702 if (opc == SEC_CTX_INIT || opc == SEC_CTX_INIT_CONT)
1703 sptlrpc_svc_ctx_invalidate(req);
1709 static struct mdt_object *mdt_obj(struct lu_object *o)
1711 LASSERT(lu_device_is_mdt(o->lo_dev));
1712 return container_of0(o, struct mdt_object, mot_obj.mo_lu);
1715 struct mdt_object *mdt_object_find(const struct lu_env *env,
1716 struct mdt_device *d,
1717 const struct lu_fid *f)
1719 struct lu_object *o;
1720 struct mdt_object *m;
1723 o = lu_object_find(env, d->mdt_md_dev.md_lu_dev.ld_site, f);
1724 if (unlikely(IS_ERR(o)))
1725 m = (struct mdt_object *)o;
1731 int mdt_object_lock(struct mdt_thread_info *info, struct mdt_object *o,
1732 struct mdt_lock_handle *lh, __u64 ibits, int locality)
1734 struct ldlm_namespace *ns = info->mti_mdt->mdt_namespace;
1735 ldlm_policy_data_t *policy = &info->mti_policy;
1736 struct ldlm_res_id *res_id = &info->mti_res_id;
1740 LASSERT(!lustre_handle_is_used(&lh->mlh_reg_lh));
1741 LASSERT(!lustre_handle_is_used(&lh->mlh_pdo_lh));
1742 LASSERT(lh->mlh_reg_mode != LCK_MINMODE);
1743 LASSERT(lh->mlh_type != MDT_NUL_LOCK);
1745 if (mdt_object_exists(o) < 0) {
1746 if (locality == MDT_CROSS_LOCK) {
1747 /* cross-ref object fix */
1748 ibits &= ~MDS_INODELOCK_UPDATE;
1749 ibits |= MDS_INODELOCK_LOOKUP;
1751 LASSERT(!(ibits & MDS_INODELOCK_UPDATE));
1752 LASSERT(ibits & MDS_INODELOCK_LOOKUP);
1754 /* No PDO lock on remote object */
1755 LASSERT(lh->mlh_type != MDT_PDO_LOCK);
1758 memset(policy, 0, sizeof(*policy));
1759 fid_build_reg_res_name(mdt_object_fid(o), res_id);
1762 * Take PDO lock on whole directory and build correct @res_id for lock
1763 * on part of directory.
1765 if (lh->mlh_pdo_hash != 0) {
1766 LASSERT(lh->mlh_type == MDT_PDO_LOCK);
1767 mdt_lock_pdo_mode(info, o, lh);
1768 if (lh->mlh_pdo_mode != LCK_NL) {
1770 * Do not use LDLM_FL_LOCAL_ONLY for parallel lock, it
1771 * is never going to be sent to client and we do not
1772 * want it slowed down due to possible cancels.
1774 policy->l_inodebits.bits = MDS_INODELOCK_UPDATE;
1775 rc = mdt_fid_lock(ns, &lh->mlh_pdo_lh, lh->mlh_pdo_mode,
1776 policy, res_id, LDLM_FL_ATOMIC_CB);
1782 * Finish res_id initializing by name hash marking patr of
1783 * directory which is taking modification.
1785 res_id->name[LUSTRE_RES_ID_HSH_OFF] = lh->mlh_pdo_hash;
1788 policy->l_inodebits.bits = ibits;
1791 * Use LDLM_FL_LOCAL_ONLY for this lock. We do not know yet if it is
1792 * going to be sent to client. If it is - mdt_intent_policy() path will
1793 * fix it up and turns FL_LOCAL flag off.
1795 rc = mdt_fid_lock(ns, &lh->mlh_reg_lh, lh->mlh_reg_mode, policy,
1796 res_id, LDLM_FL_LOCAL_ONLY | LDLM_FL_ATOMIC_CB);
1801 if (lh->mlh_type == MDT_PDO_LOCK) {
1802 /* check for exists after object is locked */
1803 if (mdt_object_exists(o) == 0) {
1804 /* Non-existent object shouldn't have PDO lock */
1807 /* Non-dir object shouldn't have PDO lock */
1808 LASSERT(S_ISDIR(lu_object_attr(&o->mot_obj.mo_lu)));
1813 mdt_object_unlock(info, o, lh, 1);
1820 * Just call ldlm_lock_decref() if decref, else we only call ptlrpc_save_lock()
1821 * to save this lock in req. when transaction committed, req will be released,
1822 * and lock will, too.
1824 void mdt_object_unlock(struct mdt_thread_info *info, struct mdt_object *o,
1825 struct mdt_lock_handle *lh, int decref)
1827 struct ptlrpc_request *req = mdt_info_req(info);
1830 if (lustre_handle_is_used(&lh->mlh_pdo_lh)) {
1831 /* Do not save PDO locks to request, just decref. */
1832 mdt_fid_unlock(&lh->mlh_pdo_lh,
1834 lh->mlh_pdo_lh.cookie = 0ull;
1837 if (lustre_handle_is_used(&lh->mlh_reg_lh)) {
1839 mdt_fid_unlock(&lh->mlh_reg_lh,
1842 ptlrpc_save_lock(req, &lh->mlh_reg_lh,
1845 lh->mlh_reg_lh.cookie = 0ull;
1851 struct mdt_object *mdt_object_find_lock(struct mdt_thread_info *info,
1852 const struct lu_fid *f,
1853 struct mdt_lock_handle *lh,
1856 struct mdt_object *o;
1858 o = mdt_object_find(info->mti_env, info->mti_mdt, f);
1862 rc = mdt_object_lock(info, o, lh, ibits,
1865 mdt_object_put(info->mti_env, o);
1872 void mdt_object_unlock_put(struct mdt_thread_info * info,
1873 struct mdt_object * o,
1874 struct mdt_lock_handle *lh,
1877 mdt_object_unlock(info, o, lh, decref);
1878 mdt_object_put(info->mti_env, o);
1881 static struct mdt_handler *mdt_handler_find(__u32 opc,
1882 struct mdt_opc_slice *supported)
1884 struct mdt_opc_slice *s;
1885 struct mdt_handler *h;
1888 for (s = supported; s->mos_hs != NULL; s++) {
1889 if (s->mos_opc_start <= opc && opc < s->mos_opc_end) {
1890 h = s->mos_hs + (opc - s->mos_opc_start);
1891 if (likely(h->mh_opc != 0))
1892 LASSERT(h->mh_opc == opc);
1894 h = NULL; /* unsupported opc */
1901 static int mdt_lock_resname_compat(struct mdt_device *m,
1902 struct ldlm_request *req)
1904 /* XXX something... later. */
1908 static int mdt_lock_reply_compat(struct mdt_device *m, struct ldlm_reply *rep)
1910 /* XXX something... later. */
1915 * Generic code handling requests that have struct mdt_body passed in:
1917 * - extract mdt_body from request and save it in @info, if present;
1919 * - create lu_object, corresponding to the fid in mdt_body, and save it in
1922 * - if HABEO_CORPUS flag is set for this request type check whether object
1923 * actually exists on storage (lu_object_exists()).
1926 static int mdt_body_unpack(struct mdt_thread_info *info, __u32 flags)
1928 const struct mdt_body *body;
1929 struct mdt_object *obj;
1930 const struct lu_env *env;
1931 struct req_capsule *pill;
1934 env = info->mti_env;
1935 pill = &info->mti_pill;
1937 body = info->mti_body = req_capsule_client_get(pill, &RMF_MDT_BODY);
1941 if (!fid_is_sane(&body->fid1)) {
1942 CERROR("Invalid fid: "DFID"\n", PFID(&body->fid1));
1947 * Do not get size or any capa fields before we check that request
1948 * contains capa actually. There are some requests which do not, for
1949 * instance MDS_IS_SUBDIR.
1951 if (req_capsule_has_field(pill, &RMF_CAPA1, RCL_CLIENT) &&
1952 req_capsule_get_size(pill, &RMF_CAPA1, RCL_CLIENT))
1953 mdt_set_capainfo(info, 0, &body->fid1,
1954 req_capsule_client_get(pill, &RMF_CAPA1));
1956 obj = mdt_object_find(env, info->mti_mdt, &body->fid1);
1958 if ((flags & HABEO_CORPUS) &&
1959 !mdt_object_exists(obj)) {
1960 mdt_object_put(env, obj);
1961 /* for capability renew ENOENT will be handled in
1963 if (body->valid & OBD_MD_FLOSSCAPA)
1968 info->mti_object = obj;
1977 static int mdt_unpack_req_pack_rep(struct mdt_thread_info *info, __u32 flags)
1979 struct req_capsule *pill;
1983 pill = &info->mti_pill;
1985 if (req_capsule_has_field(pill, &RMF_MDT_BODY, RCL_CLIENT))
1986 rc = mdt_body_unpack(info, flags);
1990 if (rc == 0 && (flags & HABEO_REFERO)) {
1991 struct mdt_device *mdt = info->mti_mdt;
1994 if (req_capsule_has_field(pill, &RMF_MDT_MD, RCL_SERVER))
1995 req_capsule_set_size(pill, &RMF_MDT_MD, RCL_SERVER,
1996 mdt->mdt_max_mdsize);
1997 if (req_capsule_has_field(pill, &RMF_LOGCOOKIES, RCL_SERVER))
1998 req_capsule_set_size(pill, &RMF_LOGCOOKIES, RCL_SERVER,
1999 mdt->mdt_max_cookiesize);
2001 rc = req_capsule_pack(pill);
2006 static int mdt_init_capa_ctxt(const struct lu_env *env, struct mdt_device *m)
2008 struct md_device *next = m->mdt_child;
2010 return next->md_ops->mdo_init_capa_ctxt(env, next,
2011 m->mdt_opts.mo_mds_capa,
2012 m->mdt_capa_timeout,
2018 * Invoke handler for this request opc. Also do necessary preprocessing
2019 * (according to handler ->mh_flags), and post-processing (setting of
2020 * ->last_{xid,committed}).
2022 static int mdt_req_handle(struct mdt_thread_info *info,
2023 struct mdt_handler *h, struct ptlrpc_request *req)
2025 int rc, serious = 0;
2030 LASSERT(h->mh_act != NULL);
2031 LASSERT(h->mh_opc == lustre_msg_get_opc(req->rq_reqmsg));
2032 LASSERT(current->journal_info == NULL);
2035 * Mask out OBD_FAIL_ONCE, because that will stop
2036 * correct handling of failed req later in ldlm due to doing
2037 * obd_fail_loc |= OBD_FAIL_ONCE without actually
2038 * correct actions like it is done in target_send_reply_msg().
2040 if (h->mh_fail_id != 0) {
2042 * Set to info->mti_fail_id to handler fail_id, it will be used
2043 * later, and better than use default fail_id.
2045 if (OBD_FAIL_CHECK_RESET(h->mh_fail_id && OBD_FAIL_MASK_LOC,
2046 h->mh_fail_id & ~OBD_FAILED)) {
2047 info->mti_fail_id = h->mh_fail_id;
2053 flags = h->mh_flags;
2054 LASSERT(ergo(flags & (HABEO_CORPUS|HABEO_REFERO), h->mh_fmt != NULL));
2056 if (h->mh_fmt != NULL) {
2057 req_capsule_set(&info->mti_pill, h->mh_fmt);
2058 rc = mdt_unpack_req_pack_rep(info, flags);
2061 if (rc == 0 && flags & MUTABOR &&
2062 req->rq_export->exp_connect_flags & OBD_CONNECT_RDONLY)
2063 /* should it be rq_status? */
2066 if (rc == 0 && flags & HABEO_CLAVIS) {
2067 struct ldlm_request *dlm_req;
2069 LASSERT(h->mh_fmt != NULL);
2071 dlm_req = req_capsule_client_get(&info->mti_pill, &RMF_DLM_REQ);
2072 if (dlm_req != NULL) {
2073 if (info->mti_mdt->mdt_opts.mo_compat_resname)
2074 rc = mdt_lock_resname_compat(info->mti_mdt,
2076 info->mti_dlm_req = dlm_req;
2078 CERROR("Can't unpack dlm request\n");
2083 /* capability setting changed via /proc, needs reinitialize ctxt */
2084 if (info->mti_mdt && info->mti_mdt->mdt_capa_conf) {
2085 mdt_init_capa_ctxt(info->mti_env, info->mti_mdt);
2086 info->mti_mdt->mdt_capa_conf = 0;
2089 if (likely(rc == 0)) {
2091 * Process request, there can be two types of rc:
2092 * 1) errors with msg unpack/pack, other failures outside the
2093 * operation itself. This is counted as serious errors;
2094 * 2) errors during fs operation, should be placed in rq_status
2097 rc = h->mh_act(info);
2098 serious = is_serious(rc);
2099 rc = clear_serious(rc);
2103 req->rq_status = rc;
2106 * ELDLM_* codes which > 0 should be in rq_status only as well as
2107 * all non-serious errors.
2109 if (rc > 0 || !serious)
2112 LASSERT(current->journal_info == NULL);
2114 if (rc == 0 && (flags & HABEO_CLAVIS) &&
2115 info->mti_mdt->mdt_opts.mo_compat_resname) {
2116 struct ldlm_reply *dlmrep;
2118 dlmrep = req_capsule_server_get(&info->mti_pill, &RMF_DLM_REP);
2120 rc = mdt_lock_reply_compat(info->mti_mdt, dlmrep);
2123 /* If we're DISCONNECTing, the mdt_export_data is already freed */
2124 if (likely(rc == 0 && h->mh_opc != MDS_DISCONNECT))
2125 target_committed_to_req(req);
2127 if (unlikely((lustre_msg_get_flags(req->rq_reqmsg) & MSG_REPLAY) &&
2128 lustre_msg_get_transno(req->rq_reqmsg) == 0)) {
2129 DEBUG_REQ(D_ERROR, req, "transno is 0 during REPLAY");
2136 void mdt_lock_handle_init(struct mdt_lock_handle *lh)
2138 lh->mlh_type = MDT_NUL_LOCK;
2139 lh->mlh_reg_lh.cookie = 0ull;
2140 lh->mlh_reg_mode = LCK_MINMODE;
2141 lh->mlh_pdo_lh.cookie = 0ull;
2142 lh->mlh_pdo_mode = LCK_MINMODE;
2145 void mdt_lock_handle_fini(struct mdt_lock_handle *lh)
2147 LASSERT(!lustre_handle_is_used(&lh->mlh_reg_lh));
2148 LASSERT(!lustre_handle_is_used(&lh->mlh_pdo_lh));
2152 * Initialize fields of struct mdt_thread_info. Other fields are left in
2153 * uninitialized state, because it's too expensive to zero out whole
2154 * mdt_thread_info (> 1K) on each request arrival.
2156 static void mdt_thread_info_init(struct ptlrpc_request *req,
2157 struct mdt_thread_info *info)
2160 struct md_capainfo *ci;
2162 info->mti_rep_buf_nr = ARRAY_SIZE(info->mti_rep_buf_size);
2163 for (i = 0; i < ARRAY_SIZE(info->mti_rep_buf_size); i++)
2164 info->mti_rep_buf_size[i] = -1;
2165 req_capsule_init(&info->mti_pill, req, RCL_SERVER,
2166 info->mti_rep_buf_size);
2169 for (i = 0; i < ARRAY_SIZE(info->mti_lh); i++)
2170 mdt_lock_handle_init(&info->mti_lh[i]);
2172 /* mdt device: it can be NULL while CONNECT */
2173 if (req->rq_export) {
2174 info->mti_mdt = mdt_dev(req->rq_export->exp_obd->obd_lu_dev);
2175 info->mti_exp = req->rq_export;
2177 info->mti_mdt = NULL;
2178 info->mti_env = req->rq_svc_thread->t_env;
2179 ci = md_capainfo(info->mti_env);
2180 memset(ci, 0, sizeof *ci);
2182 info->mti_fail_id = OBD_FAIL_MDS_ALL_REPLY_NET;
2183 info->mti_transno = lustre_msg_get_transno(req->rq_reqmsg);
2185 memset(&info->mti_attr, 0, sizeof(info->mti_attr));
2186 info->mti_body = NULL;
2187 info->mti_object = NULL;
2188 info->mti_dlm_req = NULL;
2189 info->mti_has_trans = 0;
2190 info->mti_no_need_trans = 0;
2191 info->mti_cross_ref = 0;
2192 info->mti_opdata = 0;
2194 /* To not check for split by default. */
2195 info->mti_spec.sp_ck_split = 0;
2198 static void mdt_thread_info_fini(struct mdt_thread_info *info)
2202 req_capsule_fini(&info->mti_pill);
2203 if (info->mti_object != NULL) {
2204 mdt_object_put(info->mti_env, info->mti_object);
2205 info->mti_object = NULL;
2207 for (i = 0; i < ARRAY_SIZE(info->mti_lh); i++)
2208 mdt_lock_handle_fini(&info->mti_lh[i]);
2209 info->mti_env = NULL;
2213 extern int mds_filter_recovery_request(struct ptlrpc_request *req,
2214 struct obd_device *obd, int *process);
2216 * Handle recovery. Return:
2217 * +1: continue request processing;
2218 * -ve: abort immediately with the given error code;
2219 * 0: send reply with error code in req->rq_status;
2221 static int mdt_recovery(struct mdt_thread_info *info)
2223 struct ptlrpc_request *req = mdt_info_req(info);
2225 struct obd_device *obd;
2229 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
2232 case SEC_CTX_INIT_CONT:
2238 rc = mdt_handle_idmap(info);
2247 if (unlikely(req->rq_export == NULL)) {
2248 CERROR("operation %d on unconnected MDS from %s\n",
2249 lustre_msg_get_opc(req->rq_reqmsg),
2250 libcfs_id2str(req->rq_peer));
2251 /* FIXME: For CMD cleanup, when mds_B stop, the req from
2252 * mds_A will get -ENOTCONN(especially for ping req),
2253 * which will cause that mds_A deactive timeout, then when
2254 * mds_A cleanup, the cleanup process will be suspended since
2255 * deactive timeout is not zero.
2257 req->rq_status = -ENOTCONN;
2258 target_send_reply(req, -ENOTCONN, info->mti_fail_id);
2262 /* sanity check: if the xid matches, the request must be marked as a
2263 * resent or replayed */
2264 if (req_xid_is_last(req)) {
2265 if (!(lustre_msg_get_flags(req->rq_reqmsg) &
2266 (MSG_RESENT | MSG_REPLAY))) {
2267 DEBUG_REQ(D_WARNING, req, "rq_xid "LPU64" matches last_xid, "
2268 "expected REPLAY or RESENT flag (%x)", req->rq_xid,
2269 lustre_msg_get_flags(req->rq_reqmsg));
2271 req->rq_status = -ENOTCONN;
2276 /* else: note the opposite is not always true; a RESENT req after a
2277 * failover will usually not match the last_xid, since it was likely
2278 * never committed. A REPLAYed request will almost never match the
2279 * last xid, however it could for a committed, but still retained,
2282 obd = req->rq_export->exp_obd;
2284 /* Check for aborted recovery... */
2285 spin_lock_bh(&obd->obd_processing_task_lock);
2286 recovering = obd->obd_recovering;
2287 spin_unlock_bh(&obd->obd_processing_task_lock);
2288 if (unlikely(recovering)) {
2291 DEBUG_REQ(D_INFO, req, "Got new replay");
2292 rc = mds_filter_recovery_request(req, obd, &should_process);
2293 if (rc != 0 || !should_process)
2295 else if (should_process < 0) {
2296 req->rq_status = should_process;
2297 rc = ptlrpc_error(req);
2304 static int mdt_reply(struct ptlrpc_request *req, int rc,
2305 struct mdt_thread_info *info)
2310 if (req->rq_reply_state == NULL && rc == 0) {
2311 req->rq_status = rc;
2312 lustre_pack_reply(req, 1, NULL, NULL);
2315 target_send_reply(req, rc, info->mti_fail_id);
2320 extern int mds_msg_check_version(struct lustre_msg *msg);
2322 static int mdt_handle0(struct ptlrpc_request *req,
2323 struct mdt_thread_info *info,
2324 struct mdt_opc_slice *supported)
2326 struct mdt_handler *h;
2327 struct lustre_msg *msg;
2332 if (OBD_FAIL_CHECK_ORSET(OBD_FAIL_MDS_ALL_REQUEST_NET, OBD_FAIL_ONCE))
2335 LASSERT(current->journal_info == NULL);
2337 msg = req->rq_reqmsg;
2338 rc = mds_msg_check_version(msg);
2339 if (likely(rc == 0)) {
2340 rc = mdt_recovery(info);
2341 if (likely(rc == +1)) {
2342 h = mdt_handler_find(lustre_msg_get_opc(msg),
2344 if (likely(h != NULL)) {
2345 rc = mdt_req_handle(info, h, req);
2346 rc = mdt_reply(req, rc, info);
2348 CERROR("The unsupported opc: 0x%x\n", lustre_msg_get_opc(msg) );
2349 req->rq_status = -ENOTSUPP;
2350 rc = ptlrpc_error(req);
2355 CERROR(LUSTRE_MDT_NAME" drops mal-formed request\n");
2360 * MDT handler function called by ptlrpc service thread when request comes.
2362 * XXX common "target" functionality should be factored into separate module
2363 * shared by mdt, ost and stand-alone services like fld.
2365 static int mdt_handle_common(struct ptlrpc_request *req,
2366 struct mdt_opc_slice *supported)
2369 struct mdt_thread_info *info;
2373 env = req->rq_svc_thread->t_env;
2374 LASSERT(env != NULL);
2375 LASSERT(env->le_ses != NULL);
2376 LASSERT(env->le_ctx.lc_thread == req->rq_svc_thread);
2377 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
2378 LASSERT(info != NULL);
2380 mdt_thread_info_init(req, info);
2382 rc = mdt_handle0(req, info, supported);
2384 mdt_thread_info_fini(info);
2389 * This is called from recovery code as handler of _all_ RPC types, FLD and SEQ
2392 int mdt_recovery_handle(struct ptlrpc_request *req)
2397 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
2399 rc = mdt_handle_common(req, mdt_fld_handlers);
2402 rc = mdt_handle_common(req, mdt_seq_handlers);
2405 rc = mdt_handle_common(req, mdt_regular_handlers);
2412 static int mdt_regular_handle(struct ptlrpc_request *req)
2414 return mdt_handle_common(req, mdt_regular_handlers);
2417 static int mdt_readpage_handle(struct ptlrpc_request *req)
2419 return mdt_handle_common(req, mdt_readpage_handlers);
2422 static int mdt_xmds_handle(struct ptlrpc_request *req)
2424 return mdt_handle_common(req, mdt_xmds_handlers);
2427 static int mdt_mdsc_handle(struct ptlrpc_request *req)
2429 return mdt_handle_common(req, mdt_seq_handlers);
2432 static int mdt_mdss_handle(struct ptlrpc_request *req)
2434 return mdt_handle_common(req, mdt_seq_handlers);
2437 static int mdt_dtss_handle(struct ptlrpc_request *req)
2439 return mdt_handle_common(req, mdt_seq_handlers);
2442 static int mdt_fld_handle(struct ptlrpc_request *req)
2444 return mdt_handle_common(req, mdt_fld_handlers);
2460 static int mdt_intent_getattr(enum mdt_it_code opcode,
2461 struct mdt_thread_info *info,
2462 struct ldlm_lock **,
2464 static int mdt_intent_reint(enum mdt_it_code opcode,
2465 struct mdt_thread_info *info,
2466 struct ldlm_lock **,
2469 static struct mdt_it_flavor {
2470 const struct req_format *it_fmt;
2472 int (*it_act)(enum mdt_it_code ,
2473 struct mdt_thread_info *,
2474 struct ldlm_lock **,
2477 } mdt_it_flavor[] = {
2479 .it_fmt = &RQF_LDLM_INTENT,
2480 /*.it_flags = HABEO_REFERO,*/
2482 .it_act = mdt_intent_reint,
2483 .it_reint = REINT_OPEN
2486 .it_fmt = &RQF_LDLM_INTENT,
2487 .it_flags = MUTABOR,
2488 .it_act = mdt_intent_reint,
2489 .it_reint = REINT_OPEN
2492 .it_fmt = &RQF_LDLM_INTENT,
2493 .it_flags = MUTABOR,
2494 .it_act = mdt_intent_reint,
2495 .it_reint = REINT_CREATE
2497 [MDT_IT_GETATTR] = {
2498 .it_fmt = &RQF_LDLM_INTENT_GETATTR,
2499 .it_flags = HABEO_REFERO,
2500 .it_act = mdt_intent_getattr
2502 [MDT_IT_READDIR] = {
2508 .it_fmt = &RQF_LDLM_INTENT_GETATTR,
2509 .it_flags = HABEO_REFERO,
2510 .it_act = mdt_intent_getattr
2513 .it_fmt = &RQF_LDLM_INTENT_UNLINK,
2514 .it_flags = MUTABOR,
2516 .it_reint = REINT_UNLINK
2520 .it_flags = MUTABOR,
2523 [MDT_IT_GETXATTR] = {
2530 int mdt_intent_lock_replace(struct mdt_thread_info *info,
2531 struct ldlm_lock **lockp,
2532 struct ldlm_lock *new_lock,
2533 struct mdt_lock_handle *lh,
2536 struct ptlrpc_request *req = mdt_info_req(info);
2537 struct ldlm_lock *lock = *lockp;
2540 * Get new lock only for cases when possible resent did not find any
2543 if (new_lock == NULL)
2544 new_lock = ldlm_handle2lock(&lh->mlh_reg_lh);
2546 if (new_lock == NULL && (flags & LDLM_FL_INTENT_ONLY)) {
2547 lh->mlh_reg_lh.cookie = 0;
2551 LASSERTF(new_lock != NULL,
2552 "lockh "LPX64"\n", lh->mlh_reg_lh.cookie);
2555 * If we've already given this lock to a client once, then we should
2556 * have no readers or writers. Otherwise, we should have one reader
2557 * _or_ writer ref (which will be zeroed below) before returning the
2560 if (new_lock->l_export == req->rq_export) {
2561 LASSERT(new_lock->l_readers + new_lock->l_writers == 0);
2563 LASSERT(new_lock->l_export == NULL);
2564 LASSERT(new_lock->l_readers + new_lock->l_writers == 1);
2569 if (new_lock->l_export == req->rq_export) {
2571 * Already gave this to the client, which means that we
2572 * reconstructed a reply.
2574 LASSERT(lustre_msg_get_flags(req->rq_reqmsg) &
2576 lh->mlh_reg_lh.cookie = 0;
2577 RETURN(ELDLM_LOCK_REPLACED);
2580 /* This lock might already be given to the client by an resent req,
2581 * in this case we should return ELDLM_LOCK_ABORTED,
2582 * so we should check led_held_locks here, but it will affect
2583 * performance, FIXME
2585 /* Fixup the lock to be given to the client */
2586 lock_res_and_lock(new_lock);
2587 new_lock->l_readers = 0;
2588 new_lock->l_writers = 0;
2590 new_lock->l_export = class_export_get(req->rq_export);
2591 spin_lock(&req->rq_export->exp_ldlm_data.led_lock);
2592 list_add(&new_lock->l_export_chain,
2593 &new_lock->l_export->exp_ldlm_data.led_held_locks);
2594 spin_unlock(&req->rq_export->exp_ldlm_data.led_lock);
2596 new_lock->l_blocking_ast = lock->l_blocking_ast;
2597 new_lock->l_completion_ast = lock->l_completion_ast;
2598 new_lock->l_remote_handle = lock->l_remote_handle;
2599 new_lock->l_flags &= ~LDLM_FL_LOCAL;
2601 unlock_res_and_lock(new_lock);
2602 LDLM_LOCK_PUT(new_lock);
2603 lh->mlh_reg_lh.cookie = 0;
2605 RETURN(ELDLM_LOCK_REPLACED);
2608 static void mdt_intent_fixup_resent(struct mdt_thread_info *info,
2609 struct ldlm_lock *new_lock,
2610 struct ldlm_lock **old_lock,
2611 struct mdt_lock_handle *lh)
2613 struct ptlrpc_request *req = mdt_info_req(info);
2614 struct obd_export *exp = req->rq_export;
2615 struct lustre_handle remote_hdl;
2616 struct ldlm_request *dlmreq;
2617 struct list_head *iter;
2619 if (!(lustre_msg_get_flags(req->rq_reqmsg) & MSG_RESENT))
2622 dlmreq = req_capsule_client_get(&info->mti_pill, &RMF_DLM_REQ);
2623 remote_hdl = dlmreq->lock_handle[0];
2625 spin_lock(&exp->exp_ldlm_data.led_lock);
2626 list_for_each(iter, &exp->exp_ldlm_data.led_held_locks) {
2627 struct ldlm_lock *lock;
2628 lock = list_entry(iter, struct ldlm_lock, l_export_chain);
2629 if (lock == new_lock)
2631 if (lock->l_remote_handle.cookie == remote_hdl.cookie) {
2632 lh->mlh_reg_lh.cookie = lock->l_handle.h_cookie;
2633 lh->mlh_reg_mode = lock->l_granted_mode;
2635 LDLM_DEBUG(lock, "restoring lock cookie");
2636 DEBUG_REQ(D_DLMTRACE, req,
2637 "restoring lock cookie "LPX64,
2638 lh->mlh_reg_lh.cookie);
2640 *old_lock = LDLM_LOCK_GET(lock);
2641 spin_unlock(&exp->exp_ldlm_data.led_lock);
2645 spin_unlock(&exp->exp_ldlm_data.led_lock);
2648 * If the xid matches, then we know this is a resent request, and allow
2649 * it. (It's probably an OPEN, for which we don't send a lock.
2651 if (req_xid_is_last(req))
2655 * This remote handle isn't enqueued, so we never received or processed
2656 * this request. Clear MSG_RESENT, because it can be handled like any
2657 * normal request now.
2659 lustre_msg_clear_flags(req->rq_reqmsg, MSG_RESENT);
2661 DEBUG_REQ(D_DLMTRACE, req, "no existing lock with rhandle "LPX64,
2665 static int mdt_intent_getattr(enum mdt_it_code opcode,
2666 struct mdt_thread_info *info,
2667 struct ldlm_lock **lockp,
2670 struct mdt_lock_handle *lhc = &info->mti_lh[MDT_LH_RMT];
2671 struct ldlm_lock *new_lock = NULL;
2673 struct ldlm_reply *ldlm_rep;
2674 struct ptlrpc_request *req;
2675 struct mdt_body *reqbody;
2676 struct mdt_body *repbody;
2680 reqbody = req_capsule_client_get(&info->mti_pill, &RMF_MDT_BODY);
2683 repbody = req_capsule_server_get(&info->mti_pill, &RMF_MDT_BODY);
2686 info->mti_spec.sp_ck_split = !!(reqbody->valid & OBD_MD_FLCKSPLIT);
2687 info->mti_cross_ref = !!(reqbody->valid & OBD_MD_FLCROSSREF);
2688 repbody->eadatasize = 0;
2689 repbody->aclsize = 0;
2693 child_bits = MDS_INODELOCK_LOOKUP;
2695 case MDT_IT_GETATTR:
2696 child_bits = MDS_INODELOCK_LOOKUP | MDS_INODELOCK_UPDATE;
2699 CERROR("Unhandled till now");
2700 GOTO(out, rc = -EINVAL);
2703 rc = mdt_init_ucred(info, reqbody);
2707 req = info->mti_pill.rc_req;
2708 ldlm_rep = req_capsule_server_get(&info->mti_pill, &RMF_DLM_REP);
2709 mdt_set_disposition(info, ldlm_rep, DISP_IT_EXECD);
2711 /* Get lock from request for possible resent case. */
2712 mdt_intent_fixup_resent(info, *lockp, &new_lock, lhc);
2714 ldlm_rep->lock_policy_res2 =
2715 mdt_getattr_name_lock(info, lhc, child_bits, ldlm_rep);
2717 if (mdt_get_disposition(ldlm_rep, DISP_LOOKUP_NEG))
2718 ldlm_rep->lock_policy_res2 = 0;
2719 if (!mdt_get_disposition(ldlm_rep, DISP_LOOKUP_POS) ||
2720 ldlm_rep->lock_policy_res2) {
2721 lhc->mlh_reg_lh.cookie = 0ull;
2722 GOTO(out_ucred, rc = ELDLM_LOCK_ABORTED);
2725 rc = mdt_intent_lock_replace(info, lockp, new_lock, lhc, flags);
2728 mdt_exit_ucred(info);
2730 mdt_shrink_reply(info);
2734 static int mdt_intent_reint(enum mdt_it_code opcode,
2735 struct mdt_thread_info *info,
2736 struct ldlm_lock **lockp,
2739 struct mdt_lock_handle *lhc = &info->mti_lh[MDT_LH_RMT];
2740 struct ldlm_reply *rep = NULL;
2744 static const struct req_format *intent_fmts[REINT_MAX] = {
2745 [REINT_CREATE] = &RQF_LDLM_INTENT_CREATE,
2746 [REINT_OPEN] = &RQF_LDLM_INTENT_OPEN
2751 opc = mdt_reint_opcode(info, intent_fmts);
2753 GOTO(out, rc = opc);
2755 if (mdt_it_flavor[opcode].it_reint != opc) {
2756 CERROR("Reint code %ld doesn't match intent: %d\n",
2758 GOTO(out, rc = err_serious(-EPROTO));
2761 /* Get lock from request for possible resent case. */
2762 mdt_intent_fixup_resent(info, *lockp, NULL, lhc);
2764 rc = mdt_reint_internal(info, lhc, opc);
2766 /* Check whether the reply has been packed successfully. */
2767 if (mdt_info_req(info)->rq_repmsg != NULL)
2768 rep = req_capsule_server_get(&info->mti_pill, &RMF_DLM_REP);
2770 GOTO(out, rc = err_serious(-EFAULT));
2772 /* MDC expects this in any case */
2774 mdt_set_disposition(info, rep, DISP_LOOKUP_EXECD);
2776 /* Cross-ref case, the lock should be returned to the client */
2777 if (rc == -EREMOTE) {
2778 LASSERT(lustre_handle_is_used(&lhc->mlh_reg_lh));
2779 rep->lock_policy_res2 = 0;
2780 rc = mdt_intent_lock_replace(info, lockp, NULL, lhc, flags);
2783 rep->lock_policy_res2 = clear_serious(rc);
2785 lhc->mlh_reg_lh.cookie = 0ull;
2786 rc = ELDLM_LOCK_ABORTED;
2792 static int mdt_intent_code(long itcode)
2800 case IT_OPEN|IT_CREAT:
2807 rc = MDT_IT_READDIR;
2810 rc = MDT_IT_GETATTR;
2822 rc = MDT_IT_GETXATTR;
2825 CERROR("Unknown intent opcode: %ld\n", itcode);
2832 static int mdt_intent_opc(long itopc, struct mdt_thread_info *info,
2833 struct ldlm_lock **lockp, int flags)
2835 struct req_capsule *pill;
2836 struct mdt_it_flavor *flv;
2841 opc = mdt_intent_code(itopc);
2845 pill = &info->mti_pill;
2846 flv = &mdt_it_flavor[opc];
2848 if (flv->it_fmt != NULL)
2849 req_capsule_extend(pill, flv->it_fmt);
2851 rc = mdt_unpack_req_pack_rep(info, flv->it_flags);
2853 struct ptlrpc_request *req = mdt_info_req(info);
2854 if (flv->it_flags & MUTABOR &&
2855 req->rq_export->exp_connect_flags & OBD_CONNECT_RDONLY)
2858 if (rc == 0 && flv->it_act != NULL) {
2859 /* execute policy */
2860 rc = flv->it_act(opc, info, lockp, flags);
2866 static int mdt_intent_policy(struct ldlm_namespace *ns,
2867 struct ldlm_lock **lockp, void *req_cookie,
2868 ldlm_mode_t mode, int flags, void *data)
2870 struct mdt_thread_info *info;
2871 struct ptlrpc_request *req = req_cookie;
2872 struct ldlm_intent *it;
2873 struct req_capsule *pill;
2878 LASSERT(req != NULL);
2880 info = lu_context_key_get(&req->rq_svc_thread->t_env->le_ctx,
2882 LASSERT(info != NULL);
2883 pill = &info->mti_pill;
2884 LASSERT(pill->rc_req == req);
2886 if (req->rq_reqmsg->lm_bufcount > DLM_INTENT_IT_OFF) {
2887 req_capsule_extend(pill, &RQF_LDLM_INTENT);
2888 it = req_capsule_client_get(pill, &RMF_LDLM_INTENT);
2890 const struct ldlm_request *dlmreq;
2893 struct ldlm_lock *lock = *lockp;
2895 LDLM_DEBUG(lock, "intent policy opc: %s\n",
2896 ldlm_it2str(it->opc));
2899 rc = mdt_intent_opc(it->opc, info, lockp, flags);
2904 * Lock without inodebits makes no sense and will oops
2905 * later in ldlm. Let's check it now to see if we have
2906 * wrong lock from client or bits get corrupted
2907 * somewhere in mdt_intent_opc().
2909 dlmreq = info->mti_dlm_req;
2910 req_bits = dlmreq->lock_desc.l_policy_data.l_inodebits.bits;
2911 LASSERT(req_bits != 0);
2914 rc = err_serious(-EFAULT);
2916 /* No intent was provided */
2917 LASSERT(pill->rc_fmt == &RQF_LDLM_ENQUEUE);
2918 rc = req_capsule_pack(pill);
2920 rc = err_serious(rc);
2928 static void mdt_seq_adjust(const struct lu_env *env,
2929 struct mdt_device *m, int lost)
2931 struct lu_site *ls = m->mdt_md_dev.md_lu_dev.ld_site;
2932 struct lu_range out;
2935 LASSERT(ls && ls->ls_server_seq);
2937 /* get extra seq from seq_server, moving it's range up */
2938 while (lost-- > 0) {
2939 seq_server_alloc_meta(ls->ls_server_seq, NULL, &out, env);
2944 static int mdt_seq_fini(const struct lu_env *env,
2945 struct mdt_device *m)
2947 struct lu_site *ls = m->mdt_md_dev.md_lu_dev.ld_site;
2950 if (ls && ls->ls_server_seq) {
2951 seq_server_fini(ls->ls_server_seq, env);
2952 OBD_FREE_PTR(ls->ls_server_seq);
2953 ls->ls_server_seq = NULL;
2956 if (ls && ls->ls_control_seq) {
2957 seq_server_fini(ls->ls_control_seq, env);
2958 OBD_FREE_PTR(ls->ls_control_seq);
2959 ls->ls_control_seq = NULL;
2962 if (ls && ls->ls_client_seq) {
2963 seq_client_fini(ls->ls_client_seq);
2964 OBD_FREE_PTR(ls->ls_client_seq);
2965 ls->ls_client_seq = NULL;
2971 static int mdt_seq_init(const struct lu_env *env,
2973 struct mdt_device *m)
2980 ls = m->mdt_md_dev.md_lu_dev.ld_site;
2983 * This is sequence-controller node. Init seq-controller server on local
2986 if (ls->ls_node_id == 0) {
2987 LASSERT(ls->ls_control_seq == NULL);
2989 OBD_ALLOC_PTR(ls->ls_control_seq);
2990 if (ls->ls_control_seq == NULL)
2993 rc = seq_server_init(ls->ls_control_seq,
2994 m->mdt_bottom, uuid,
2995 LUSTRE_SEQ_CONTROLLER,
2999 GOTO(out_seq_fini, rc);
3001 OBD_ALLOC_PTR(ls->ls_client_seq);
3002 if (ls->ls_client_seq == NULL)
3003 GOTO(out_seq_fini, rc = -ENOMEM);
3005 OBD_ALLOC(prefix, MAX_OBD_NAME + 5);
3006 if (prefix == NULL) {
3007 OBD_FREE_PTR(ls->ls_client_seq);
3008 GOTO(out_seq_fini, rc = -ENOMEM);
3011 snprintf(prefix, MAX_OBD_NAME + 5, "ctl-%s",
3015 * Init seq-controller client after seq-controller server is
3016 * ready. Pass ls->ls_control_seq to it for direct talking.
3018 rc = seq_client_init(ls->ls_client_seq, NULL,
3019 LUSTRE_SEQ_METADATA, prefix,
3020 ls->ls_control_seq);
3021 OBD_FREE(prefix, MAX_OBD_NAME + 5);
3024 GOTO(out_seq_fini, rc);
3027 /* Init seq-server on local MDT */
3028 LASSERT(ls->ls_server_seq == NULL);
3030 OBD_ALLOC_PTR(ls->ls_server_seq);
3031 if (ls->ls_server_seq == NULL)
3032 GOTO(out_seq_fini, rc = -ENOMEM);
3034 rc = seq_server_init(ls->ls_server_seq,
3035 m->mdt_bottom, uuid,
3039 GOTO(out_seq_fini, rc = -ENOMEM);
3041 /* Assign seq-controller client to local seq-server. */
3042 if (ls->ls_node_id == 0) {
3043 LASSERT(ls->ls_client_seq != NULL);
3045 rc = seq_server_set_cli(ls->ls_server_seq,
3053 mdt_seq_fini(env, m);
3058 * Init client sequence manager which is used by local MDS to talk to sequence
3059 * controller on remote node.
3061 static int mdt_seq_init_cli(const struct lu_env *env,
3062 struct mdt_device *m,
3063 struct lustre_cfg *cfg)
3065 struct lu_site *ls = m->mdt_md_dev.md_lu_dev.ld_site;
3066 struct obd_device *mdc;
3067 struct obd_uuid *uuidp, *mdcuuidp;
3068 char *uuid_str, *mdc_uuid_str;
3071 struct mdt_thread_info *info;
3072 char *p, *index_string = lustre_cfg_string(cfg, 2);
3075 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
3076 uuidp = &info->mti_u.uuid[0];
3077 mdcuuidp = &info->mti_u.uuid[1];
3079 LASSERT(index_string);
3081 index = simple_strtol(index_string, &p, 10);
3083 CERROR("Invalid index in lustre_cgf, offset 2\n");
3087 /* check if this is adding the first MDC and controller is not yet
3089 if (index != 0 || ls->ls_client_seq)
3092 uuid_str = lustre_cfg_string(cfg, 1);
3093 mdc_uuid_str = lustre_cfg_string(cfg, 4);
3094 obd_str2uuid(uuidp, uuid_str);
3095 obd_str2uuid(mdcuuidp, mdc_uuid_str);
3097 mdc = class_find_client_obd(uuidp, LUSTRE_MDC_NAME, mdcuuidp);
3099 CERROR("can't find controller MDC by uuid %s\n",
3102 } else if (!mdc->obd_set_up) {
3103 CERROR("target %s not set up\n", mdc->obd_name);
3106 LASSERT(ls->ls_control_exp);
3107 OBD_ALLOC_PTR(ls->ls_client_seq);
3108 if (ls->ls_client_seq != NULL) {
3111 OBD_ALLOC(prefix, MAX_OBD_NAME + 5);
3115 snprintf(prefix, MAX_OBD_NAME + 5, "ctl-%s",
3118 rc = seq_client_init(ls->ls_client_seq,
3120 LUSTRE_SEQ_METADATA,
3122 OBD_FREE(prefix, MAX_OBD_NAME + 5);
3129 LASSERT(ls->ls_server_seq != NULL);
3130 rc = seq_server_set_cli(ls->ls_server_seq, ls->ls_client_seq,
3137 static void mdt_seq_fini_cli(struct mdt_device *m)
3143 ls = m->mdt_md_dev.md_lu_dev.ld_site;
3145 if (ls && ls->ls_server_seq)
3146 seq_server_set_cli(ls->ls_server_seq,
3149 if (ls && ls->ls_control_exp) {
3150 class_export_put(ls->ls_control_exp);
3151 ls->ls_control_exp = NULL;
3159 static int mdt_fld_fini(const struct lu_env *env,
3160 struct mdt_device *m)
3162 struct lu_site *ls = m->mdt_md_dev.md_lu_dev.ld_site;
3165 if (ls && ls->ls_server_fld) {
3166 fld_server_fini(ls->ls_server_fld, env);
3167 OBD_FREE_PTR(ls->ls_server_fld);
3168 ls->ls_server_fld = NULL;
3174 static int mdt_fld_init(const struct lu_env *env,
3176 struct mdt_device *m)
3182 ls = m->mdt_md_dev.md_lu_dev.ld_site;
3184 OBD_ALLOC_PTR(ls->ls_server_fld);
3185 if (ls->ls_server_fld == NULL)
3186 RETURN(rc = -ENOMEM);
3188 rc = fld_server_init(ls->ls_server_fld,
3189 m->mdt_bottom, uuid, env);
3191 OBD_FREE_PTR(ls->ls_server_fld);
3192 ls->ls_server_fld = NULL;
3199 /* device init/fini methods */
3200 static void mdt_stop_ptlrpc_service(struct mdt_device *m)
3203 if (m->mdt_regular_service != NULL) {
3204 ptlrpc_unregister_service(m->mdt_regular_service);
3205 m->mdt_regular_service = NULL;
3207 if (m->mdt_readpage_service != NULL) {
3208 ptlrpc_unregister_service(m->mdt_readpage_service);
3209 m->mdt_readpage_service = NULL;
3211 if (m->mdt_xmds_service != NULL) {
3212 ptlrpc_unregister_service(m->mdt_xmds_service);
3213 m->mdt_xmds_service = NULL;
3215 if (m->mdt_setattr_service != NULL) {
3216 ptlrpc_unregister_service(m->mdt_setattr_service);
3217 m->mdt_setattr_service = NULL;
3219 if (m->mdt_mdsc_service != NULL) {
3220 ptlrpc_unregister_service(m->mdt_mdsc_service);
3221 m->mdt_mdsc_service = NULL;
3223 if (m->mdt_mdss_service != NULL) {
3224 ptlrpc_unregister_service(m->mdt_mdss_service);
3225 m->mdt_mdss_service = NULL;
3227 if (m->mdt_dtss_service != NULL) {
3228 ptlrpc_unregister_service(m->mdt_dtss_service);
3229 m->mdt_dtss_service = NULL;
3231 if (m->mdt_fld_service != NULL) {
3232 ptlrpc_unregister_service(m->mdt_fld_service);
3233 m->mdt_fld_service = NULL;
3238 static int mdt_start_ptlrpc_service(struct mdt_device *m)
3241 static struct ptlrpc_service_conf conf;
3242 cfs_proc_dir_entry_t *procfs_entry;
3245 procfs_entry = m->mdt_md_dev.md_lu_dev.ld_obd->obd_proc_entry;
3247 conf = (typeof(conf)) {
3248 .psc_nbufs = MDS_NBUFS,
3249 .psc_bufsize = MDS_BUFSIZE,
3250 .psc_max_req_size = MDS_MAXREQSIZE,
3251 .psc_max_reply_size = MDS_MAXREPSIZE,
3252 .psc_req_portal = MDS_REQUEST_PORTAL,
3253 .psc_rep_portal = MDC_REPLY_PORTAL,
3254 .psc_watchdog_timeout = MDT_SERVICE_WATCHDOG_TIMEOUT,
3256 * We'd like to have a mechanism to set this on a per-device
3257 * basis, but alas...
3259 .psc_min_threads = min(max(mdt_num_threads, MDT_MIN_THREADS),
3261 .psc_max_threads = MDT_MAX_THREADS,
3262 .psc_ctx_tags = LCT_MD_THREAD
3265 m->mdt_ldlm_client = &m->mdt_md_dev.md_lu_dev.ld_obd->obd_ldlm_client;
3266 ptlrpc_init_client(LDLM_CB_REQUEST_PORTAL, LDLM_CB_REPLY_PORTAL,
3267 "mdt_ldlm_client", m->mdt_ldlm_client);
3269 m->mdt_regular_service =
3270 ptlrpc_init_svc_conf(&conf, mdt_regular_handle, LUSTRE_MDT_NAME,
3271 procfs_entry, NULL, LUSTRE_MDT_NAME);
3272 if (m->mdt_regular_service == NULL)
3275 rc = ptlrpc_start_threads(NULL, m->mdt_regular_service);
3277 GOTO(err_mdt_svc, rc);
3280 * readpage service configuration. Parameters have to be adjusted,
3283 conf = (typeof(conf)) {
3284 .psc_nbufs = MDS_NBUFS,
3285 .psc_bufsize = MDS_BUFSIZE,
3286 .psc_max_req_size = MDS_MAXREQSIZE,
3287 .psc_max_reply_size = MDS_MAXREPSIZE,
3288 .psc_req_portal = MDS_READPAGE_PORTAL,
3289 .psc_rep_portal = MDC_REPLY_PORTAL,
3290 .psc_watchdog_timeout = MDT_SERVICE_WATCHDOG_TIMEOUT,
3291 .psc_min_threads = min(max(mdt_num_threads, MDT_MIN_THREADS),
3293 .psc_max_threads = MDT_MAX_THREADS,
3294 .psc_ctx_tags = LCT_MD_THREAD
3296 m->mdt_readpage_service =
3297 ptlrpc_init_svc_conf(&conf, mdt_readpage_handle,
3298 LUSTRE_MDT_NAME "_readpage",
3299 procfs_entry, NULL, "mdt_rdpg");
3301 if (m->mdt_readpage_service == NULL) {
3302 CERROR("failed to start readpage service\n");
3303 GOTO(err_mdt_svc, rc = -ENOMEM);
3306 rc = ptlrpc_start_threads(NULL, m->mdt_readpage_service);
3309 * setattr service configuration.
3311 conf = (typeof(conf)) {
3312 .psc_nbufs = MDS_NBUFS,
3313 .psc_bufsize = MDS_BUFSIZE,
3314 .psc_max_req_size = MDS_MAXREQSIZE,
3315 .psc_max_reply_size = MDS_MAXREPSIZE,
3316 .psc_req_portal = MDS_SETATTR_PORTAL,
3317 .psc_rep_portal = MDC_REPLY_PORTAL,
3318 .psc_watchdog_timeout = MDT_SERVICE_WATCHDOG_TIMEOUT,
3319 .psc_min_threads = min(max(mdt_num_threads, MDT_MIN_THREADS),
3321 .psc_max_threads = MDT_MAX_THREADS,
3322 .psc_ctx_tags = LCT_MD_THREAD
3325 m->mdt_setattr_service =
3326 ptlrpc_init_svc_conf(&conf, mdt_regular_handle,
3327 LUSTRE_MDT_NAME "_setattr",
3328 procfs_entry, NULL, "mdt_attr");
3330 if (!m->mdt_setattr_service) {
3331 CERROR("failed to start setattr service\n");
3332 GOTO(err_mdt_svc, rc = -ENOMEM);
3335 rc = ptlrpc_start_threads(NULL, m->mdt_setattr_service);
3337 GOTO(err_mdt_svc, rc);
3340 * sequence controller service configuration
3342 conf = (typeof(conf)) {
3343 .psc_nbufs = MDS_NBUFS,
3344 .psc_bufsize = MDS_BUFSIZE,
3345 .psc_max_req_size = SEQ_MAXREQSIZE,
3346 .psc_max_reply_size = SEQ_MAXREPSIZE,
3347 .psc_req_portal = SEQ_CONTROLLER_PORTAL,
3348 .psc_rep_portal = MDC_REPLY_PORTAL,
3349 .psc_watchdog_timeout = MDT_SERVICE_WATCHDOG_TIMEOUT,
3350 .psc_min_threads = SEQ_NUM_THREADS,
3351 .psc_max_threads = SEQ_NUM_THREADS,
3352 .psc_ctx_tags = LCT_MD_THREAD|LCT_DT_THREAD
3355 m->mdt_mdsc_service =
3356 ptlrpc_init_svc_conf(&conf, mdt_mdsc_handle,
3357 LUSTRE_MDT_NAME"_mdsc",
3358 procfs_entry, NULL, "mdt_mdsc");
3359 if (!m->mdt_mdsc_service) {
3360 CERROR("failed to start seq controller service\n");
3361 GOTO(err_mdt_svc, rc = -ENOMEM);
3364 rc = ptlrpc_start_threads(NULL, m->mdt_mdsc_service);
3366 GOTO(err_mdt_svc, rc);
3369 * metadata sequence server service configuration
3371 conf = (typeof(conf)) {
3372 .psc_nbufs = MDS_NBUFS,
3373 .psc_bufsize = MDS_BUFSIZE,
3374 .psc_max_req_size = SEQ_MAXREQSIZE,
3375 .psc_max_reply_size = SEQ_MAXREPSIZE,
3376 .psc_req_portal = SEQ_METADATA_PORTAL,
3377 .psc_rep_portal = MDC_REPLY_PORTAL,
3378 .psc_watchdog_timeout = MDT_SERVICE_WATCHDOG_TIMEOUT,
3379 .psc_min_threads = SEQ_NUM_THREADS,
3380 .psc_max_threads = SEQ_NUM_THREADS,
3381 .psc_ctx_tags = LCT_MD_THREAD|LCT_DT_THREAD
3384 m->mdt_mdss_service =
3385 ptlrpc_init_svc_conf(&conf, mdt_mdss_handle,
3386 LUSTRE_MDT_NAME"_mdss",
3387 procfs_entry, NULL, "mdt_mdss");
3388 if (!m->mdt_mdss_service) {
3389 CERROR("failed to start metadata seq server service\n");
3390 GOTO(err_mdt_svc, rc = -ENOMEM);
3393 rc = ptlrpc_start_threads(NULL, m->mdt_mdss_service);
3395 GOTO(err_mdt_svc, rc);
3399 * Data sequence server service configuration. We want to have really
3400 * cluster-wide sequences space. This is why we start only one sequence
3401 * controller which manages space.
3403 conf = (typeof(conf)) {
3404 .psc_nbufs = MDS_NBUFS,
3405 .psc_bufsize = MDS_BUFSIZE,
3406 .psc_max_req_size = SEQ_MAXREQSIZE,
3407 .psc_max_reply_size = SEQ_MAXREPSIZE,
3408 .psc_req_portal = SEQ_DATA_PORTAL,
3409 .psc_rep_portal = OSC_REPLY_PORTAL,
3410 .psc_watchdog_timeout = MDT_SERVICE_WATCHDOG_TIMEOUT,
3411 .psc_min_threads = SEQ_NUM_THREADS,
3412 .psc_max_threads = SEQ_NUM_THREADS,
3413 .psc_ctx_tags = LCT_MD_THREAD|LCT_DT_THREAD
3416 m->mdt_dtss_service =
3417 ptlrpc_init_svc_conf(&conf, mdt_dtss_handle,
3418 LUSTRE_MDT_NAME"_dtss",
3419 procfs_entry, NULL, "mdt_dtss");
3420 if (!m->mdt_dtss_service) {
3421 CERROR("failed to start data seq server service\n");
3422 GOTO(err_mdt_svc, rc = -ENOMEM);
3425 rc = ptlrpc_start_threads(NULL, m->mdt_dtss_service);
3427 GOTO(err_mdt_svc, rc);
3429 /* FLD service start */
3430 conf = (typeof(conf)) {
3431 .psc_nbufs = MDS_NBUFS,
3432 .psc_bufsize = MDS_BUFSIZE,
3433 .psc_max_req_size = FLD_MAXREQSIZE,
3434 .psc_max_reply_size = FLD_MAXREPSIZE,
3435 .psc_req_portal = FLD_REQUEST_PORTAL,
3436 .psc_rep_portal = MDC_REPLY_PORTAL,
3437 .psc_watchdog_timeout = MDT_SERVICE_WATCHDOG_TIMEOUT,
3438 .psc_min_threads = FLD_NUM_THREADS,
3439 .psc_max_threads = FLD_NUM_THREADS,
3440 .psc_ctx_tags = LCT_DT_THREAD|LCT_MD_THREAD
3443 m->mdt_fld_service =
3444 ptlrpc_init_svc_conf(&conf, mdt_fld_handle,
3445 LUSTRE_MDT_NAME"_fld",
3446 procfs_entry, NULL, "mdt_fld");
3447 if (!m->mdt_fld_service) {
3448 CERROR("failed to start fld service\n");
3449 GOTO(err_mdt_svc, rc = -ENOMEM);
3452 rc = ptlrpc_start_threads(NULL, m->mdt_fld_service);
3454 GOTO(err_mdt_svc, rc);
3457 * mds-mds service configuration. Separate portal is used to allow
3458 * mds-mds requests be not blocked during recovery.
3460 conf = (typeof(conf)) {
3461 .psc_nbufs = MDS_NBUFS,
3462 .psc_bufsize = MDS_BUFSIZE,
3463 .psc_max_req_size = MDS_MAXREQSIZE,
3464 .psc_max_reply_size = MDS_MAXREPSIZE,
3465 .psc_req_portal = MDS_MDS_PORTAL,
3466 .psc_rep_portal = MDC_REPLY_PORTAL,
3467 .psc_watchdog_timeout = MDT_SERVICE_WATCHDOG_TIMEOUT,
3468 .psc_min_threads = min(max(mdt_num_threads, MDT_MIN_THREADS),
3470 .psc_max_threads = MDT_MAX_THREADS,
3471 .psc_ctx_tags = LCT_MD_THREAD
3473 m->mdt_xmds_service = ptlrpc_init_svc_conf(&conf, mdt_xmds_handle,
3474 LUSTRE_MDT_NAME "_mds",
3475 procfs_entry, NULL, "mdt_xmds");
3477 if (m->mdt_xmds_service == NULL) {
3478 CERROR("failed to start readpage service\n");
3479 GOTO(err_mdt_svc, rc = -ENOMEM);
3482 rc = ptlrpc_start_threads(NULL, m->mdt_xmds_service);
3484 GOTO(err_mdt_svc, rc);
3489 mdt_stop_ptlrpc_service(m);
3494 static void mdt_stack_fini(const struct lu_env *env,
3495 struct mdt_device *m, struct lu_device *top)
3497 struct lu_device *d = top, *n;
3498 struct obd_device *obd = m->mdt_md_dev.md_lu_dev.ld_obd;
3499 struct lustre_cfg_bufs *bufs;
3500 struct lustre_cfg *lcfg;
3501 struct mdt_thread_info *info;
3505 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
3506 LASSERT(info != NULL);
3508 bufs = &info->mti_u.bufs;
3509 /* process cleanup, pass mdt obd name to get obd umount flags */
3510 lustre_cfg_bufs_reset(bufs, obd->obd_name);
3515 lustre_cfg_bufs_set_string(bufs, 1, flags);
3516 lcfg = lustre_cfg_new(LCFG_CLEANUP, bufs);
3518 CERROR("Cannot alloc lcfg!\n");
3523 top->ld_ops->ldo_process_config(env, top, lcfg);
3524 lustre_cfg_free(lcfg);
3526 lu_site_purge(env, top->ld_site, ~0);
3528 struct obd_type *type;
3529 struct lu_device_type *ldt = d->ld_type;
3531 /* each fini() returns next device in stack of layers
3532 * * so we can avoid the recursion */
3533 n = ldt->ldt_ops->ldto_device_fini(env, d);
3535 ldt->ldt_ops->ldto_device_free(env, d);
3536 type = ldt->ldt_obd_type;
3538 class_put_type(type);
3540 /* switch to the next device in the layer */
3543 m->mdt_child = NULL;
3544 m->mdt_bottom = NULL;
3547 static struct lu_device *mdt_layer_setup(const struct lu_env *env,
3548 const char *typename,
3549 struct lu_device *child,
3550 struct lustre_cfg *cfg)
3552 const char *dev = lustre_cfg_string(cfg, 0);
3553 struct obd_type *type;
3554 struct lu_device_type *ldt;
3555 struct lu_device *d;
3560 type = class_get_type(typename);
3562 CERROR("Unknown type: '%s'\n", typename);
3563 GOTO(out, rc = -ENODEV);
3566 rc = lu_context_refill(&env->le_ctx);
3568 CERROR("Failure to refill context: '%d'\n", rc);
3572 if (env->le_ses != NULL) {
3573 rc = lu_context_refill(env->le_ses);
3575 CERROR("Failure to refill session: '%d'\n", rc);
3582 CERROR("type: '%s'\n", typename);
3583 GOTO(out_type, rc = -EINVAL);
3586 ldt->ldt_obd_type = type;
3587 d = ldt->ldt_ops->ldto_device_alloc(env, ldt, cfg);
3589 CERROR("Cannot allocate device: '%s'\n", typename);
3590 GOTO(out_type, rc = -ENODEV);
3593 LASSERT(child->ld_site);
3594 d->ld_site = child->ld_site;
3597 rc = ldt->ldt_ops->ldto_device_init(env, d, dev, child);
3599 CERROR("can't init device '%s', rc %d\n", typename, rc);
3600 GOTO(out_alloc, rc);
3607 ldt->ldt_ops->ldto_device_free(env, d);
3610 class_put_type(type);
3615 static int mdt_stack_init(const struct lu_env *env,
3616 struct mdt_device *m, struct lustre_cfg *cfg)
3618 struct lu_device *d = &m->mdt_md_dev.md_lu_dev;
3619 struct lu_device *tmp;
3620 struct md_device *md;
3624 /* init the stack */
3625 tmp = mdt_layer_setup(env, LUSTRE_OSD_NAME, d, cfg);
3627 RETURN(PTR_ERR(tmp));
3629 m->mdt_bottom = lu2dt_dev(tmp);
3631 tmp = mdt_layer_setup(env, LUSTRE_MDD_NAME, d, cfg);
3633 GOTO(out, rc = PTR_ERR(tmp));
3638 tmp = mdt_layer_setup(env, LUSTRE_CMM_NAME, d, cfg);
3640 GOTO(out, rc = PTR_ERR(tmp));
3643 /*set mdd upcall device*/
3644 md_upcall_dev_set(md, lu2md_dev(d));
3647 /*set cmm upcall device*/
3648 md_upcall_dev_set(md, &m->mdt_md_dev);
3650 m->mdt_child = lu2md_dev(d);
3652 /* process setup config */
3653 tmp = &m->mdt_md_dev.md_lu_dev;
3654 rc = tmp->ld_ops->ldo_process_config(env, tmp, cfg);
3657 /* fini from last known good lu_device */
3659 mdt_stack_fini(env, m, d);
3664 static void mdt_fini(const struct lu_env *env, struct mdt_device *m)
3666 struct md_device *next = m->mdt_child;
3667 struct lu_device *d = &m->mdt_md_dev.md_lu_dev;
3668 struct lu_site *ls = d->ld_site;
3669 struct obd_device *obd = m->mdt_md_dev.md_lu_dev.ld_obd;
3672 ping_evictor_stop();
3674 target_recovery_fini(obd);
3675 mdt_stop_ptlrpc_service(m);
3677 mdt_fs_cleanup(env, m);
3679 upcall_cache_cleanup(m->mdt_rmtacl_cache);
3680 m->mdt_rmtacl_cache = NULL;
3682 upcall_cache_cleanup(m->mdt_identity_cache);
3683 m->mdt_identity_cache = NULL;
3685 if (m->mdt_namespace != NULL) {
3686 ldlm_namespace_free(m->mdt_namespace, d->ld_obd->obd_force);
3687 d->ld_obd->obd_namespace = m->mdt_namespace = NULL;
3690 mdt_seq_fini(env, m);
3691 mdt_seq_fini_cli(m);
3692 mdt_fld_fini(env, m);
3694 ptlrpc_lprocfs_unregister_obd(d->ld_obd);
3695 lprocfs_obd_cleanup(d->ld_obd);
3697 if (m->mdt_rootsquash_info) {
3698 OBD_FREE_PTR(m->mdt_rootsquash_info);
3699 m->mdt_rootsquash_info = NULL;
3702 next->md_ops->mdo_init_capa_ctxt(env, next, 0, 0, 0, NULL);
3703 del_timer(&m->mdt_ck_timer);
3704 mdt_ck_thread_stop(m);
3706 /* finish the stack */
3707 mdt_stack_fini(env, m, md2lu_dev(m->mdt_child));
3710 if (!list_empty(&ls->ls_lru) || ls->ls_total != 0) {
3712 * Uh-oh, objects still exist.
3714 static DECLARE_LU_CDEBUG_PRINT_INFO(cookie, D_ERROR);
3716 lu_site_print(env, ls, &cookie, lu_cdebug_printer);
3723 LASSERT(atomic_read(&d->ld_ref) == 0);
3724 md_device_fini(&m->mdt_md_dev);
3729 static void fsoptions_to_mdt_flags(struct mdt_device *m, char *options)
3739 while (*p && *p != ',')
3743 if ((len == sizeof("user_xattr") - 1) &&
3744 (memcmp(options, "user_xattr", len) == 0)) {
3745 m->mdt_opts.mo_user_xattr = 1;
3746 LCONSOLE_INFO("Enabling user_xattr\n");
3747 } else if ((len == sizeof("nouser_xattr") - 1) &&
3748 (memcmp(options, "nouser_xattr", len) == 0)) {
3749 m->mdt_opts.mo_user_xattr = 0;
3750 LCONSOLE_INFO("Disabling user_xattr\n");
3751 } else if ((len == sizeof("acl") - 1) &&
3752 (memcmp(options, "acl", len) == 0)) {
3753 #ifdef CONFIG_FS_POSIX_ACL
3754 m->mdt_opts.mo_acl = 1;
3755 LCONSOLE_INFO("Enabling ACL\n");
3757 m->mdt_opts.mo_acl = 0;
3758 CWARN("ignoring unsupported acl mount option\n");
3759 LCONSOLE_INFO("Disabling ACL\n");
3761 } else if ((len == sizeof("noacl") - 1) &&
3762 (memcmp(options, "noacl", len) == 0)) {
3763 m->mdt_opts.mo_acl = 0;
3764 LCONSOLE_INFO("Disabling ACL\n");
3771 int mdt_postrecov(const struct lu_env *, struct mdt_device *);
3773 static int mdt_init0(const struct lu_env *env, struct mdt_device *m,
3774 struct lu_device_type *ldt, struct lustre_cfg *cfg)
3776 struct lprocfs_static_vars lvars;
3777 struct mdt_thread_info *info;
3778 struct obd_device *obd;
3779 const char *dev = lustre_cfg_string(cfg, 0);
3780 const char *num = lustre_cfg_string(cfg, 2);
3781 struct lustre_mount_info *lmi;
3782 struct lustre_sb_info *lsi;
3787 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
3788 LASSERT(info != NULL);
3790 obd = class_name2obd(dev);
3791 LASSERT(obd != NULL);
3793 spin_lock_init(&m->mdt_transno_lock);
3795 m->mdt_max_mdsize = MAX_MD_SIZE;
3796 m->mdt_max_cookiesize = sizeof(struct llog_cookie);
3798 m->mdt_opts.mo_user_xattr = 0;
3799 m->mdt_opts.mo_acl = 0;
3800 lmi = server_get_mount_2(dev);
3802 CERROR("Cannot get mount info for %s!\n", dev);
3805 lsi = s2lsi(lmi->lmi_sb);
3806 fsoptions_to_mdt_flags(m, lsi->lsi_lmd->lmd_opts);
3807 server_put_mount_2(dev, lmi->lmi_mnt);
3810 spin_lock_init(&m->mdt_ioepoch_lock);
3811 m->mdt_opts.mo_compat_resname = 0;
3812 m->mdt_capa_timeout = CAPA_TIMEOUT;
3813 m->mdt_capa_alg = CAPA_HMAC_ALG_SHA1;
3814 m->mdt_ck_timeout = CAPA_KEY_TIMEOUT;
3816 spin_lock_init(&m->mdt_client_bitmap_lock);
3822 md_device_init(&m->mdt_md_dev, ldt);
3823 m->mdt_md_dev.md_lu_dev.ld_ops = &mdt_lu_ops;
3824 m->mdt_md_dev.md_lu_dev.ld_obd = obd;
3825 /* set this lu_device to obd, because error handling need it */
3826 obd->obd_lu_dev = &m->mdt_md_dev.md_lu_dev;
3828 rc = lu_site_init(s, &m->mdt_md_dev.md_lu_dev);
3830 CERROR("Can't init lu_site, rc %d\n", rc);
3831 GOTO(err_free_site, rc);
3834 lprocfs_mdt_init_vars(&lvars);
3835 rc = lprocfs_obd_setup(obd, lvars.obd_vars);
3837 CERROR("Can't init lprocfs, rc %d\n", rc);
3838 GOTO(err_fini_site, rc);
3840 ptlrpc_lprocfs_register_obd(obd);
3842 rc = mdt_procfs_init(m, dev);
3844 CERROR("Can't init MDT lprocfs, rc %d\n", rc);
3845 GOTO(err_fini_proc, rc);
3848 /* set server index */
3850 s->ls_node_id = simple_strtol(num, NULL, 10);
3852 /* failover is the default
3853 * FIXME: we do not failout mds0/mgs, which may cause some problems.
3854 * assumed whose ls_node_id == 0 XXX
3856 obd->obd_replayable = 1;
3857 /* No connection accepted until configurations will finish */
3858 obd->obd_no_conn = 1;
3860 if (cfg->lcfg_bufcount > 4 && LUSTRE_CFG_BUFLEN(cfg, 4) > 0) {
3861 char *str = lustre_cfg_string(cfg, 4);
3862 if (strchr(str, 'n')) {
3863 CWARN("%s: recovery disabled\n", obd->obd_name);
3864 obd->obd_replayable = 0;
3868 /* init the stack */
3869 rc = mdt_stack_init(env, m, cfg);
3871 CERROR("Can't init device stack, rc %d\n", rc);
3872 GOTO(err_fini_proc, rc);
3875 rc = mdt_fld_init(env, obd->obd_name, m);
3877 GOTO(err_fini_stack, rc);
3879 rc = mdt_seq_init(env, obd->obd_name, m);
3881 GOTO(err_fini_fld, rc);
3883 snprintf(info->mti_u.ns_name, sizeof info->mti_u.ns_name,
3884 LUSTRE_MDT_NAME"-%p", m);
3885 m->mdt_namespace = ldlm_namespace_new(info->mti_u.ns_name,
3886 LDLM_NAMESPACE_SERVER,
3887 LDLM_NAMESPACE_GREEDY);
3888 if (m->mdt_namespace == NULL)
3889 GOTO(err_fini_seq, rc = -ENOMEM);
3891 ldlm_register_intent(m->mdt_namespace, mdt_intent_policy);
3892 /* set obd_namespace for compatibility with old code */
3893 obd->obd_namespace = m->mdt_namespace;
3895 m->mdt_identity_cache = upcall_cache_init(obd->obd_name,
3897 &mdt_identity_upcall_cache_ops);
3898 if (IS_ERR(m->mdt_identity_cache)) {
3899 rc = PTR_ERR(m->mdt_identity_cache);
3900 m->mdt_identity_cache = NULL;
3901 GOTO(err_free_ns, rc);
3904 m->mdt_rmtacl_cache = upcall_cache_init(obd->obd_name,
3905 MDT_RMTACL_UPCALL_PATH,
3906 &mdt_rmtacl_upcall_cache_ops);
3907 if (IS_ERR(m->mdt_rmtacl_cache)) {
3908 rc = PTR_ERR(m->mdt_rmtacl_cache);
3909 m->mdt_rmtacl_cache = NULL;
3910 GOTO(err_free_ns, rc);
3913 m->mdt_ck_timer.function = mdt_ck_timer_callback;
3914 m->mdt_ck_timer.data = (unsigned long)m;
3915 init_timer(&m->mdt_ck_timer);
3916 rc = mdt_ck_thread_start(m);
3918 GOTO(err_free_ns, rc);
3920 rc = mdt_fs_setup(env, m, obd);
3924 target_recovery_init(obd, mdt_recovery_handle);
3926 rc = mdt_start_ptlrpc_service(m);
3928 GOTO(err_fs_cleanup, rc);
3930 ping_evictor_start();
3932 rc = lu_site_init_finish(s);
3934 GOTO(err_stop_service, rc);
3936 if (obd->obd_recovering == 0)
3937 mdt_postrecov(env, m);
3939 mdt_init_capa_ctxt(env, m);
3941 if (ldlm_timeout == LDLM_TIMEOUT_DEFAULT)
3947 ping_evictor_stop();
3948 mdt_stop_ptlrpc_service(m);
3950 target_recovery_fini(obd);
3951 mdt_fs_cleanup(env, m);
3953 del_timer(&m->mdt_ck_timer);
3954 mdt_ck_thread_stop(m);
3956 upcall_cache_cleanup(m->mdt_rmtacl_cache);
3957 m->mdt_rmtacl_cache = NULL;
3958 upcall_cache_cleanup(m->mdt_identity_cache);
3959 m->mdt_identity_cache = NULL;
3960 ldlm_namespace_free(m->mdt_namespace, 0);
3961 obd->obd_namespace = m->mdt_namespace = NULL;
3963 mdt_seq_fini(env, m);
3965 mdt_fld_fini(env, m);
3967 mdt_stack_fini(env, m, md2lu_dev(m->mdt_child));
3970 lprocfs_obd_cleanup(obd);
3976 md_device_fini(&m->mdt_md_dev);
3980 /* used by MGS to process specific configurations */
3981 static int mdt_process_config(const struct lu_env *env,
3982 struct lu_device *d, struct lustre_cfg *cfg)
3984 struct mdt_device *m = mdt_dev(d);
3985 struct md_device *md_next = m->mdt_child;
3986 struct lu_device *next = md2lu_dev(md_next);
3990 switch (cfg->lcfg_command) {
3992 struct lprocfs_static_vars lvars;
3993 struct obd_device *obd = d->ld_obd;
3995 lprocfs_mdt_init_vars(&lvars);
3996 rc = class_process_proc_param(PARAM_MDT, lvars.obd_vars, cfg, obd);
3998 /* others are passed further */
3999 rc = next->ld_ops->ldo_process_config(env, next, cfg);
4004 * Add mdc hook to get first MDT uuid and connect it to
4005 * ls->controller to use for seq manager.
4007 rc = next->ld_ops->ldo_process_config(env, next, cfg);
4009 CERROR("Can't add mdc, rc %d\n", rc);
4011 rc = mdt_seq_init_cli(env, mdt_dev(d), cfg);
4014 /* others are passed further */
4015 rc = next->ld_ops->ldo_process_config(env, next, cfg);
4021 static struct lu_object *mdt_object_alloc(const struct lu_env *env,
4022 const struct lu_object_header *hdr,
4023 struct lu_device *d)
4025 struct mdt_object *mo;
4031 struct lu_object *o;
4032 struct lu_object_header *h;
4034 o = &mo->mot_obj.mo_lu;
4035 h = &mo->mot_header;
4036 lu_object_header_init(h);
4037 lu_object_init(o, h, d);
4038 lu_object_add_top(h, o);
4039 o->lo_ops = &mdt_obj_ops;
4045 static int mdt_object_init(const struct lu_env *env, struct lu_object *o)
4047 struct mdt_device *d = mdt_dev(o->lo_dev);
4048 struct lu_device *under;
4049 struct lu_object *below;
4053 CDEBUG(D_INFO, "object init, fid = "DFID"\n",
4054 PFID(lu_object_fid(o)));
4056 under = &d->mdt_child->md_lu_dev;
4057 below = under->ld_ops->ldo_object_alloc(env, o->lo_header, under);
4058 if (below != NULL) {
4059 lu_object_add(o, below);
4066 static void mdt_object_free(const struct lu_env *env, struct lu_object *o)
4068 struct mdt_object *mo = mdt_obj(o);
4069 struct lu_object_header *h;
4073 CDEBUG(D_INFO, "object free, fid = "DFID"\n",
4074 PFID(lu_object_fid(o)));
4077 lu_object_header_fini(h);
4082 static int mdt_object_print(const struct lu_env *env, void *cookie,
4083 lu_printer_t p, const struct lu_object *o)
4085 return (*p)(env, cookie, LUSTRE_MDT_NAME"-object@%p", o);
4088 static struct lu_device_operations mdt_lu_ops = {
4089 .ldo_object_alloc = mdt_object_alloc,
4090 .ldo_process_config = mdt_process_config
4093 static struct lu_object_operations mdt_obj_ops = {
4094 .loo_object_init = mdt_object_init,
4095 .loo_object_free = mdt_object_free,
4096 .loo_object_print = mdt_object_print
4099 /* mds_connect_internal */
4100 static int mdt_connect_internal(struct obd_export *exp,
4101 struct mdt_device *mdt,
4102 struct obd_connect_data *data)
4107 data->ocd_connect_flags &= MDT_CONNECT_SUPPORTED;
4108 data->ocd_ibits_known &= MDS_INODELOCK_FULL;
4110 /* If no known bits (which should not happen, probably,
4111 as everybody should support LOOKUP and UPDATE bits at least)
4112 revert to compat mode with plain locks. */
4113 if (!data->ocd_ibits_known &&
4114 data->ocd_connect_flags & OBD_CONNECT_IBITS)
4115 data->ocd_connect_flags &= ~OBD_CONNECT_IBITS;
4117 if (!mdt->mdt_opts.mo_acl)
4118 data->ocd_connect_flags &= ~OBD_CONNECT_ACL;
4120 if (!mdt->mdt_opts.mo_user_xattr)
4121 data->ocd_connect_flags &= ~OBD_CONNECT_XATTR;
4123 if (!mdt->mdt_opts.mo_mds_capa)
4124 data->ocd_connect_flags &= ~OBD_CONNECT_MDS_CAPA;
4126 if (!mdt->mdt_opts.mo_oss_capa)
4127 data->ocd_connect_flags &= ~OBD_CONNECT_OSS_CAPA;
4129 spin_lock(&exp->exp_lock);
4130 exp->exp_connect_flags = data->ocd_connect_flags;
4131 spin_unlock(&exp->exp_lock);
4132 data->ocd_version = LUSTRE_VERSION_CODE;
4133 exp->exp_mdt_data.med_ibits_known = data->ocd_ibits_known;
4137 if (mdt->mdt_opts.mo_acl &&
4138 ((exp->exp_connect_flags & OBD_CONNECT_ACL) == 0)) {
4139 CWARN("%s: MDS requires ACL support but client does not\n",
4140 mdt->mdt_md_dev.md_lu_dev.ld_obd->obd_name);
4145 flags = OBD_CONNECT_LCL_CLIENT | OBD_CONNECT_RMT_CLIENT;
4146 if ((exp->exp_connect_flags & flags) == flags) {
4147 CWARN("%s: both local and remote client flags are set\n",
4148 mdt->mdt_md_dev.md_lu_dev.ld_obd->obd_name);
4152 if (mdt->mdt_opts.mo_mds_capa &&
4153 ((exp->exp_connect_flags & OBD_CONNECT_MDS_CAPA) == 0)) {
4154 CWARN("%s: MDS requires capability support, but client not\n",
4155 mdt->mdt_md_dev.md_lu_dev.ld_obd->obd_name);
4159 if (mdt->mdt_opts.mo_oss_capa &&
4160 ((exp->exp_connect_flags & OBD_CONNECT_OSS_CAPA) == 0)) {
4161 CWARN("%s: MDS requires OSS capability support, "
4163 mdt->mdt_md_dev.md_lu_dev.ld_obd->obd_name);
4170 /* mds_connect copy */
4171 static int mdt_obd_connect(const struct lu_env *env,
4172 struct lustre_handle *conn, struct obd_device *obd,
4173 struct obd_uuid *cluuid,
4174 struct obd_connect_data *data)
4176 struct mdt_client_data *mcd;
4177 struct obd_export *exp;
4178 struct mdt_device *mdt;
4182 LASSERT(env != NULL);
4183 if (!conn || !obd || !cluuid)
4186 mdt = mdt_dev(obd->obd_lu_dev);
4188 rc = class_connect(conn, obd, cluuid);
4192 exp = class_conn2export(conn);
4193 LASSERT(exp != NULL);
4195 rc = mdt_connect_internal(exp, mdt, data);
4199 struct mdt_thread_info *mti;
4200 mti = lu_context_key_get(&env->le_ctx,
4202 LASSERT(mti != NULL);
4204 memcpy(mcd->mcd_uuid, cluuid, sizeof mcd->mcd_uuid);
4205 exp->exp_mdt_data.med_mcd = mcd;
4206 rc = mdt_client_new(env, mdt);
4209 exp->exp_mdt_data.med_mcd = NULL;
4216 class_disconnect(exp);
4218 class_export_put(exp);
4223 static int mdt_obd_reconnect(struct obd_export *exp, struct obd_device *obd,
4224 struct obd_uuid *cluuid,
4225 struct obd_connect_data *data)
4230 if (exp == NULL || obd == NULL || cluuid == NULL)
4233 rc = mdt_connect_internal(exp, mdt_dev(obd->obd_lu_dev), data);
4238 static int mdt_obd_disconnect(struct obd_export *exp)
4240 struct mdt_device *mdt = mdt_dev(exp->exp_obd->obd_lu_dev);
4245 class_export_get(exp);
4247 /* Disconnect early so that clients can't keep using export */
4248 rc = class_disconnect(exp);
4249 if (mdt->mdt_namespace != NULL || exp->exp_obd->obd_namespace != NULL)
4250 ldlm_cancel_locks_for_export(exp);
4252 /* complete all outstanding replies */
4253 spin_lock(&exp->exp_lock);
4254 while (!list_empty(&exp->exp_outstanding_replies)) {
4255 struct ptlrpc_reply_state *rs =
4256 list_entry(exp->exp_outstanding_replies.next,
4257 struct ptlrpc_reply_state, rs_exp_list);
4258 struct ptlrpc_service *svc = rs->rs_service;
4260 spin_lock(&svc->srv_lock);
4261 list_del_init(&rs->rs_exp_list);
4262 ptlrpc_schedule_difficult_reply(rs);
4263 spin_unlock(&svc->srv_lock);
4265 spin_unlock(&exp->exp_lock);
4267 class_export_put(exp);
4271 /* FIXME: Can we avoid using these two interfaces? */
4272 static int mdt_init_export(struct obd_export *exp)
4274 struct mdt_export_data *med = &exp->exp_mdt_data;
4277 INIT_LIST_HEAD(&med->med_open_head);
4278 spin_lock_init(&med->med_open_lock);
4279 spin_lock(&exp->exp_lock);
4280 exp->exp_connecting = 1;
4281 spin_unlock(&exp->exp_lock);
4285 static int mdt_destroy_export(struct obd_export *export)
4287 struct mdt_export_data *med;
4288 struct obd_device *obd = export->exp_obd;
4289 struct mdt_device *mdt;
4290 struct mdt_thread_info *info;
4298 med = &export->exp_mdt_data;
4299 if (med->med_rmtclient)
4300 mdt_cleanup_idmap(med);
4302 target_destroy_export(export);
4304 if (obd_uuid_equals(&export->exp_client_uuid, &obd->obd_uuid))
4307 mdt = mdt_dev(obd->obd_lu_dev);
4308 LASSERT(mdt != NULL);
4310 rc = lu_env_init(&env, NULL, LCT_MD_THREAD);
4314 info = lu_context_key_get(&env.le_ctx, &mdt_thread_key);
4315 LASSERT(info != NULL);
4316 memset(info, 0, sizeof *info);
4317 info->mti_env = &env;
4318 info->mti_mdt = mdt;
4319 info->mti_exp = export;
4321 ma = &info->mti_attr;
4322 lmm_size = ma->ma_lmm_size = mdt->mdt_max_mdsize;
4323 cookie_size = ma->ma_cookie_size = mdt->mdt_max_cookiesize;
4324 OBD_ALLOC(ma->ma_lmm, lmm_size);
4325 OBD_ALLOC(ma->ma_cookie, cookie_size);
4327 if (ma->ma_lmm == NULL || ma->ma_cookie == NULL)
4328 GOTO(out, rc = -ENOMEM);
4329 ma->ma_need = MA_LOV | MA_COOKIE;
4331 /* Close any open files (which may also cause orphan unlinking). */
4332 spin_lock(&med->med_open_lock);
4333 while (!list_empty(&med->med_open_head)) {
4334 struct list_head *tmp = med->med_open_head.next;
4335 struct mdt_file_data *mfd =
4336 list_entry(tmp, struct mdt_file_data, mfd_list);
4338 /* Remove mfd handle so it can't be found again.
4339 * We are consuming the mfd_list reference here. */
4340 class_handle_unhash(&mfd->mfd_handle);
4341 list_del_init(&mfd->mfd_list);
4342 spin_unlock(&med->med_open_lock);
4343 mdt_mfd_close(info, mfd);
4344 /* TODO: if we close the unlinked file,
4345 * we need to remove it's objects from OST */
4346 memset(&ma->ma_attr, 0, sizeof(ma->ma_attr));
4347 spin_lock(&med->med_open_lock);
4348 ma->ma_lmm_size = lmm_size;
4349 ma->ma_cookie_size = cookie_size;
4350 ma->ma_need = MA_LOV | MA_COOKIE;
4353 spin_unlock(&med->med_open_lock);
4354 info->mti_mdt = NULL;
4355 mdt_client_del(&env, mdt);
4360 OBD_FREE(ma->ma_lmm, lmm_size);
4364 OBD_FREE(ma->ma_cookie, cookie_size);
4365 ma->ma_cookie = NULL;
4372 static void mdt_allow_cli(struct mdt_device *m, unsigned int flag)
4374 if (flag & CONFIG_LOG)
4375 m->mdt_fl_cfglog = 1;
4376 if (flag & CONFIG_SYNC)
4377 m->mdt_fl_synced = 1;
4379 if (m->mdt_fl_cfglog /* bz11778: && m->mdt_fl_synced */)
4380 /* Open for clients */
4381 m->mdt_md_dev.md_lu_dev.ld_obd->obd_no_conn = 0;
4384 static int mdt_upcall(const struct lu_env *env, struct md_device *md,
4385 enum md_upcall_event ev)
4387 struct mdt_device *m = mdt_dev(&md->md_lu_dev);
4388 struct md_device *next = m->mdt_child;
4389 struct mdt_thread_info *mti;
4395 rc = next->md_ops->mdo_maxsize_get(env, next,
4397 &m->mdt_max_cookiesize);
4398 CDEBUG(D_INFO, "get max mdsize %d max cookiesize %d\n",
4399 m->mdt_max_mdsize, m->mdt_max_cookiesize);
4400 mdt_allow_cli(m, CONFIG_SYNC);
4403 mti = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
4404 mti->mti_no_need_trans = 1;
4405 CDEBUG(D_INFO, "disable mdt trans for this thread\n");
4408 /* Check that MDT is not yet configured */
4409 LASSERT(!m->mdt_fl_cfglog);
4412 CERROR("invalid event\n");
4419 static int mdt_obd_notify(struct obd_device *host,
4420 struct obd_device *watched,
4421 enum obd_notify_event ev, void *data)
4426 case OBD_NOTIFY_CONFIG:
4427 mdt_allow_cli(mdt_dev(host->obd_lu_dev), (unsigned int)data);
4430 CDEBUG(D_INFO, "Unhandled notification %#x\n", ev);
4435 static int mdt_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
4436 void *karg, void *uarg)
4439 struct obd_device *obd= exp->exp_obd;
4440 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
4441 struct dt_device *dt = mdt->mdt_bottom;
4445 CDEBUG(D_IOCTL, "handling ioctl cmd %#x\n", cmd);
4446 rc = lu_env_init(&env, NULL, LCT_MD_THREAD);
4452 rc = dt->dd_ops->dt_sync(&env, dt);
4454 case OBD_IOC_SET_READONLY:
4455 rc = dt->dd_ops->dt_sync(&env, dt);
4456 dt->dd_ops->dt_ro(&env, dt);
4458 case OBD_IOC_ABORT_RECOVERY:
4459 CERROR("Aborting recovery for device %s\n", obd->obd_name);
4460 target_stop_recovery_thread(obd);
4464 CERROR("Not supported cmd = %d for device %s\n",
4465 cmd, obd->obd_name);
4473 int mdt_postrecov(const struct lu_env *env, struct mdt_device *mdt)
4475 struct lu_device *ld = md2lu_dev(mdt->mdt_child);
4476 struct obd_device *obd = mdt->mdt_md_dev.md_lu_dev.ld_obd;
4479 /* if some clients didn't participate in recovery then we can possibly
4480 * lost sequence. Now we should increase sequence for safe value */
4481 lost = obd->obd_max_recoverable_clients - obd->obd_connected_clients;
4482 mdt_seq_adjust(env, mdt, lost);
4484 rc = ld->ld_ops->ldo_recovery_complete(env, ld);
4488 int mdt_obd_postrecov(struct obd_device *obd)
4493 rc = lu_env_init(&env, NULL, LCT_MD_THREAD);
4496 rc = mdt_postrecov(&env, mdt_dev(obd->obd_lu_dev));
4501 static struct obd_ops mdt_obd_device_ops = {
4502 .o_owner = THIS_MODULE,
4503 .o_connect = mdt_obd_connect,
4504 .o_reconnect = mdt_obd_reconnect,
4505 .o_disconnect = mdt_obd_disconnect,
4506 .o_init_export = mdt_init_export,
4507 .o_destroy_export = mdt_destroy_export,
4508 .o_iocontrol = mdt_iocontrol,
4509 .o_postrecov = mdt_obd_postrecov,
4510 .o_notify = mdt_obd_notify
4513 static struct lu_device* mdt_device_fini(const struct lu_env *env,
4514 struct lu_device *d)
4516 struct mdt_device *m = mdt_dev(d);
4523 static void mdt_device_free(const struct lu_env *env, struct lu_device *d)
4525 struct mdt_device *m = mdt_dev(d);
4530 static struct lu_device *mdt_device_alloc(const struct lu_env *env,
4531 struct lu_device_type *t,
4532 struct lustre_cfg *cfg)
4534 struct lu_device *l;
4535 struct mdt_device *m;
4541 l = &m->mdt_md_dev.md_lu_dev;
4542 rc = mdt_init0(env, m, t, cfg);
4548 md_upcall_init(&m->mdt_md_dev, mdt_upcall);
4550 l = ERR_PTR(-ENOMEM);
4554 /* context key constructor/destructor: mdt_key_init, mdt_key_fini */
4555 LU_KEY_INIT_FINI(mdt, struct mdt_thread_info);
4557 /* context key: mdt_thread_key */
4558 LU_CONTEXT_KEY_DEFINE(mdt, LCT_MD_THREAD);
4560 /* context key constructor/destructor: mdt_txn_key_init, mdt_txn_key_fini */
4561 LU_KEY_INIT_FINI(mdt_txn, struct mdt_txn_info);
4563 struct lu_context_key mdt_txn_key = {
4564 .lct_tags = LCT_TX_HANDLE,
4565 .lct_init = mdt_txn_key_init,
4566 .lct_fini = mdt_txn_key_fini
4569 struct md_ucred *mdt_ucred(const struct mdt_thread_info *info)
4571 return md_ucred(info->mti_env);
4574 /* type constructor/destructor: mdt_type_init, mdt_type_fini */
4575 LU_TYPE_INIT_FINI(mdt, &mdt_thread_key, &mdt_txn_key);
4577 static struct lu_device_type_operations mdt_device_type_ops = {
4578 .ldto_init = mdt_type_init,
4579 .ldto_fini = mdt_type_fini,
4581 .ldto_device_alloc = mdt_device_alloc,
4582 .ldto_device_free = mdt_device_free,
4583 .ldto_device_fini = mdt_device_fini
4586 static struct lu_device_type mdt_device_type = {
4587 .ldt_tags = LU_DEVICE_MD,
4588 .ldt_name = LUSTRE_MDT_NAME,
4589 .ldt_ops = &mdt_device_type_ops,
4590 .ldt_ctx_tags = LCT_MD_THREAD
4593 static int __init mdt_mod_init(void)
4595 struct lprocfs_static_vars lvars;
4598 mdt_num_threads = MDT_NUM_THREADS;
4599 lprocfs_mdt_init_vars(&lvars);
4600 rc = class_register_type(&mdt_obd_device_ops, NULL,
4601 lvars.module_vars, LUSTRE_MDT_NAME,
4607 static void __exit mdt_mod_exit(void)
4609 class_unregister_type(LUSTRE_MDT_NAME);
4613 #define DEF_HNDL(prefix, base, suffix, flags, opc, fn, fmt) \
4614 [prefix ## _ ## opc - prefix ## _ ## base] = { \
4616 .mh_fail_id = OBD_FAIL_ ## prefix ## _ ## opc ## suffix, \
4617 .mh_opc = prefix ## _ ## opc, \
4618 .mh_flags = flags, \
4623 #define DEF_MDT_HNDL(flags, name, fn, fmt) \
4624 DEF_HNDL(MDS, GETATTR, _NET, flags, name, fn, fmt)
4626 #define DEF_SEQ_HNDL(flags, name, fn, fmt) \
4627 DEF_HNDL(SEQ, QUERY, _NET, flags, name, fn, fmt)
4629 #define DEF_FLD_HNDL(flags, name, fn, fmt) \
4630 DEF_HNDL(FLD, QUERY, _NET, flags, name, fn, fmt)
4632 * Request with a format known in advance
4634 #define DEF_MDT_HNDL_F(flags, name, fn) \
4635 DEF_HNDL(MDS, GETATTR, _NET, flags, name, fn, &RQF_MDS_ ## name)
4637 #define DEF_SEQ_HNDL_F(flags, name, fn) \
4638 DEF_HNDL(SEQ, QUERY, _NET, flags, name, fn, &RQF_SEQ_ ## name)
4640 #define DEF_FLD_HNDL_F(flags, name, fn) \
4641 DEF_HNDL(FLD, QUERY, _NET, flags, name, fn, &RQF_FLD_ ## name)
4643 * Request with a format we do not yet know
4645 #define DEF_MDT_HNDL_0(flags, name, fn) \
4646 DEF_HNDL(MDS, GETATTR, _NET, flags, name, fn, NULL)
4648 static struct mdt_handler mdt_mds_ops[] = {
4649 DEF_MDT_HNDL_F(0, CONNECT, mdt_connect),
4650 DEF_MDT_HNDL_F(0, DISCONNECT, mdt_disconnect),
4651 DEF_MDT_HNDL_F(0, SET_INFO, mdt_set_info),
4652 DEF_MDT_HNDL_F(0 |HABEO_REFERO, GETSTATUS, mdt_getstatus),
4653 DEF_MDT_HNDL_F(HABEO_CORPUS, GETATTR, mdt_getattr),
4654 DEF_MDT_HNDL_F(HABEO_CORPUS|HABEO_REFERO, GETATTR_NAME, mdt_getattr_name),
4655 DEF_MDT_HNDL_F(HABEO_CORPUS|MUTABOR, SETXATTR, mdt_setxattr),
4656 DEF_MDT_HNDL_F(HABEO_CORPUS, GETXATTR, mdt_getxattr),
4657 DEF_MDT_HNDL_F(0 |HABEO_REFERO, STATFS, mdt_statfs),
4658 DEF_MDT_HNDL_F(0 |MUTABOR, REINT, mdt_reint),
4659 DEF_MDT_HNDL_F(HABEO_CORPUS, CLOSE, mdt_close),
4660 DEF_MDT_HNDL_F(HABEO_CORPUS, DONE_WRITING, mdt_done_writing),
4661 DEF_MDT_HNDL_F(0 |HABEO_REFERO, PIN, mdt_pin),
4662 DEF_MDT_HNDL_0(0, SYNC, mdt_sync),
4663 DEF_MDT_HNDL_F(HABEO_CORPUS|HABEO_REFERO, IS_SUBDIR, mdt_is_subdir),
4664 DEF_MDT_HNDL_0(0, QUOTACHECK, mdt_quotacheck_handle),
4665 DEF_MDT_HNDL_0(0, QUOTACTL, mdt_quotactl_handle)
4668 #define DEF_OBD_HNDL(flags, name, fn) \
4669 DEF_HNDL(OBD, PING, _NET, flags, name, fn, NULL)
4672 static struct mdt_handler mdt_obd_ops[] = {
4673 DEF_OBD_HNDL(0, PING, mdt_obd_ping),
4674 DEF_OBD_HNDL(0, LOG_CANCEL, mdt_obd_log_cancel),
4675 DEF_OBD_HNDL(0, QC_CALLBACK, mdt_obd_qc_callback)
4678 #define DEF_DLM_HNDL_0(flags, name, fn) \
4679 DEF_HNDL(LDLM, ENQUEUE, , flags, name, fn, NULL)
4680 #define DEF_DLM_HNDL_F(flags, name, fn) \
4681 DEF_HNDL(LDLM, ENQUEUE, , flags, name, fn, &RQF_LDLM_ ## name)
4683 static struct mdt_handler mdt_dlm_ops[] = {
4684 DEF_DLM_HNDL_F(HABEO_CLAVIS, ENQUEUE, mdt_enqueue),
4685 DEF_DLM_HNDL_0(HABEO_CLAVIS, CONVERT, mdt_convert),
4686 DEF_DLM_HNDL_0(0, BL_CALLBACK, mdt_bl_callback),
4687 DEF_DLM_HNDL_0(0, CP_CALLBACK, mdt_cp_callback)
4690 static struct mdt_handler mdt_llog_ops[] = {
4693 #define DEF_SEC_CTX_HNDL(name, fn) \
4694 DEF_HNDL(SEC_CTX, INIT, _NET, 0, name, fn, NULL)
4696 static struct mdt_handler mdt_sec_ctx_ops[] = {
4697 DEF_SEC_CTX_HNDL(INIT, mdt_sec_ctx_handle),
4698 DEF_SEC_CTX_HNDL(INIT_CONT, mdt_sec_ctx_handle),
4699 DEF_SEC_CTX_HNDL(FINI, mdt_sec_ctx_handle)
4702 static struct mdt_opc_slice mdt_regular_handlers[] = {
4704 .mos_opc_start = MDS_GETATTR,
4705 .mos_opc_end = MDS_LAST_OPC,
4706 .mos_hs = mdt_mds_ops
4709 .mos_opc_start = OBD_PING,
4710 .mos_opc_end = OBD_LAST_OPC,
4711 .mos_hs = mdt_obd_ops
4714 .mos_opc_start = LDLM_ENQUEUE,
4715 .mos_opc_end = LDLM_LAST_OPC,
4716 .mos_hs = mdt_dlm_ops
4719 .mos_opc_start = LLOG_ORIGIN_HANDLE_CREATE,
4720 .mos_opc_end = LLOG_LAST_OPC,
4721 .mos_hs = mdt_llog_ops
4724 .mos_opc_start = SEC_CTX_INIT,
4725 .mos_opc_end = SEC_LAST_OPC,
4726 .mos_hs = mdt_sec_ctx_ops
4733 static struct mdt_handler mdt_readpage_ops[] = {
4734 DEF_MDT_HNDL_F(0, CONNECT, mdt_connect),
4735 DEF_MDT_HNDL_F(HABEO_CORPUS|HABEO_REFERO, READPAGE, mdt_readpage),
4736 #ifdef HAVE_SPLIT_SUPPORT
4737 DEF_MDT_HNDL_F(HABEO_CORPUS|HABEO_REFERO, WRITEPAGE, mdt_writepage),
4741 * XXX: this is ugly and should be fixed one day, see mdc_close() for
4742 * detailed comments. --umka
4744 DEF_MDT_HNDL_F(HABEO_CORPUS, CLOSE, mdt_close),
4745 DEF_MDT_HNDL_F(HABEO_CORPUS, DONE_WRITING, mdt_done_writing),
4748 static struct mdt_opc_slice mdt_readpage_handlers[] = {
4750 .mos_opc_start = MDS_GETATTR,
4751 .mos_opc_end = MDS_LAST_OPC,
4752 .mos_hs = mdt_readpage_ops
4759 static struct mdt_handler mdt_xmds_ops[] = {
4760 DEF_MDT_HNDL_F(0, CONNECT, mdt_connect),
4761 DEF_MDT_HNDL_F(HABEO_CORPUS , GETATTR, mdt_getattr),
4762 DEF_MDT_HNDL_F(0 | MUTABOR , REINT, mdt_reint),
4763 DEF_MDT_HNDL_F(HABEO_CORPUS|HABEO_REFERO, IS_SUBDIR, mdt_is_subdir),
4766 static struct mdt_opc_slice mdt_xmds_handlers[] = {
4768 .mos_opc_start = MDS_GETATTR,
4769 .mos_opc_end = MDS_LAST_OPC,
4770 .mos_hs = mdt_xmds_ops
4773 .mos_opc_start = OBD_PING,
4774 .mos_opc_end = OBD_LAST_OPC,
4775 .mos_hs = mdt_obd_ops
4782 static struct mdt_handler mdt_seq_ops[] = {
4783 DEF_SEQ_HNDL_F(0, QUERY, (int (*)(struct mdt_thread_info *))seq_query)
4786 static struct mdt_opc_slice mdt_seq_handlers[] = {
4788 .mos_opc_start = SEQ_QUERY,
4789 .mos_opc_end = SEQ_LAST_OPC,
4790 .mos_hs = mdt_seq_ops
4797 static struct mdt_handler mdt_fld_ops[] = {
4798 DEF_FLD_HNDL_F(0, QUERY, (int (*)(struct mdt_thread_info *))fld_query)
4801 static struct mdt_opc_slice mdt_fld_handlers[] = {
4803 .mos_opc_start = FLD_QUERY,
4804 .mos_opc_end = FLD_LAST_OPC,
4805 .mos_hs = mdt_fld_ops
4812 MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
4813 MODULE_DESCRIPTION("Lustre Meta-data Target ("LUSTRE_MDT_NAME")");
4814 MODULE_LICENSE("GPL");
4816 CFS_MODULE_PARM(mdt_num_threads, "ul", ulong, 0444,
4817 "number of mdt service threads to start");
4819 cfs_module(mdt, "0.2.0", mdt_mod_init, mdt_mod_exit);