1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 only,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License version 2 for more details (a copy is included
16 * in the LICENSE file that accompanied this code).
18 * You should have received a copy of the GNU General Public License
19 * version 2 along with this program; If not, see
20 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
29 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
30 * Use is subject to license terms.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * lustre/mdt/mdt_handler.c
38 * Lustre Metadata Target (mdt) request handler
40 * Author: Peter Braam <braam@clusterfs.com>
41 * Author: Andreas Dilger <adilger@clusterfs.com>
42 * Author: Phil Schwan <phil@clusterfs.com>
43 * Author: Mike Shaver <shaver@clusterfs.com>
44 * Author: Nikita Danilov <nikita@clusterfs.com>
45 * Author: Huang Hua <huanghua@clusterfs.com>
46 * Author: Yury Umanets <umka@clusterfs.com>
50 # define EXPORT_SYMTAB
52 #define DEBUG_SUBSYSTEM S_MDS
54 #include <linux/module.h>
56 * struct OBD_{ALLOC,FREE}*()
58 #include <obd_support.h>
59 /* struct ptlrpc_request */
60 #include <lustre_net.h>
61 /* struct obd_export */
62 #include <lustre_export.h>
63 /* struct obd_device */
66 #include <dt_object.h>
67 #include <lustre_mds.h>
68 #include <lustre_mdt.h>
69 #include "mdt_internal.h"
70 #ifdef HAVE_QUOTA_SUPPORT
71 # include <lustre_quota.h>
73 #include <lustre_acl.h>
74 #include <lustre_param.h>
75 #include <lustre_fsfilt.h>
77 mdl_mode_t mdt_mdl_lock_modes[] = {
78 [LCK_MINMODE] = MDL_MINMODE,
85 [LCK_GROUP] = MDL_GROUP
88 ldlm_mode_t mdt_dlm_lock_modes[] = {
89 [MDL_MINMODE] = LCK_MINMODE,
96 [MDL_GROUP] = LCK_GROUP
100 * Initialized in mdt_mod_init().
102 static unsigned long mdt_num_threads;
103 static unsigned long mdt_min_threads;
104 static unsigned long mdt_max_threads;
106 /* ptlrpc request handler for MDT. All handlers are
107 * grouped into several slices - struct mdt_opc_slice,
108 * and stored in an array - mdt_handlers[].
111 /* The name of this handler. */
113 /* Fail id for this handler, checked at the beginning of this handler*/
115 /* Operation code for this handler */
117 /* flags are listed in enum mdt_handler_flags below. */
119 /* The actual handler function to execute. */
120 int (*mh_act)(struct mdt_thread_info *info);
121 /* Request format for this request. */
122 const struct req_format *mh_fmt;
125 enum mdt_handler_flags {
127 * struct mdt_body is passed in the incoming message, and object
128 * identified by this fid exists on disk.
130 * "habeo corpus" == "I have a body"
132 HABEO_CORPUS = (1 << 0),
134 * struct ldlm_request is passed in the incoming message.
136 * "habeo clavis" == "I have a key"
138 HABEO_CLAVIS = (1 << 1),
140 * this request has fixed reply format, so that reply message can be
141 * packed by generic code.
143 * "habeo refero" == "I have a reply"
145 HABEO_REFERO = (1 << 2),
147 * this request will modify something, so check whether the filesystem
148 * is readonly or not, then return -EROFS to client asap if necessary.
150 * "mutabor" == "I shall modify"
155 struct mdt_opc_slice {
158 struct mdt_handler *mos_hs;
161 static struct mdt_opc_slice mdt_regular_handlers[];
162 static struct mdt_opc_slice mdt_readpage_handlers[];
163 static struct mdt_opc_slice mdt_xmds_handlers[];
164 static struct mdt_opc_slice mdt_seq_handlers[];
165 static struct mdt_opc_slice mdt_fld_handlers[];
167 static struct mdt_device *mdt_dev(struct lu_device *d);
168 static int mdt_regular_handle(struct ptlrpc_request *req);
169 static int mdt_unpack_req_pack_rep(struct mdt_thread_info *info, __u32 flags);
170 static int mdt_fid2path(const struct lu_env *env, struct mdt_device *mdt,
171 struct getinfo_fid2path *fp);
173 static const struct lu_object_operations mdt_obj_ops;
175 int mdt_get_disposition(struct ldlm_reply *rep, int flag)
179 return (rep->lock_policy_res1 & flag);
182 void mdt_clear_disposition(struct mdt_thread_info *info,
183 struct ldlm_reply *rep, int flag)
186 info->mti_opdata &= ~flag;
188 rep->lock_policy_res1 &= ~flag;
191 void mdt_set_disposition(struct mdt_thread_info *info,
192 struct ldlm_reply *rep, int flag)
195 info->mti_opdata |= flag;
197 rep->lock_policy_res1 |= flag;
200 void mdt_lock_reg_init(struct mdt_lock_handle *lh, ldlm_mode_t lm)
202 lh->mlh_pdo_hash = 0;
203 lh->mlh_reg_mode = lm;
204 lh->mlh_type = MDT_REG_LOCK;
207 void mdt_lock_pdo_init(struct mdt_lock_handle *lh, ldlm_mode_t lm,
208 const char *name, int namelen)
210 lh->mlh_reg_mode = lm;
211 lh->mlh_type = MDT_PDO_LOCK;
214 LASSERT(namelen > 0);
215 lh->mlh_pdo_hash = full_name_hash(name, namelen);
217 LASSERT(namelen == 0);
218 lh->mlh_pdo_hash = 0ull;
222 static void mdt_lock_pdo_mode(struct mdt_thread_info *info, struct mdt_object *o,
223 struct mdt_lock_handle *lh)
229 * Any dir access needs couple of locks:
231 * 1) on part of dir we gonna take lookup/modify;
233 * 2) on whole dir to protect it from concurrent splitting and/or to
234 * flush client's cache for readdir().
236 * so, for a given mode and object this routine decides what lock mode
237 * to use for lock #2:
239 * 1) if caller's gonna lookup in dir then we need to protect dir from
240 * being splitted only - LCK_CR
242 * 2) if caller's gonna modify dir then we need to protect dir from
243 * being splitted and to flush cache - LCK_CW
245 * 3) if caller's gonna modify dir and that dir seems ready for
246 * splitting then we need to protect it from any type of access
247 * (lookup/modify/split) - LCK_EX --bzzz
250 LASSERT(lh->mlh_reg_mode != LCK_MINMODE);
251 LASSERT(lh->mlh_pdo_mode == LCK_MINMODE);
254 * Ask underlaying level its opinion about preferable PDO lock mode
255 * having access type passed as regular lock mode:
257 * - MDL_MINMODE means that lower layer does not want to specify lock
260 * - MDL_NL means that no PDO lock should be taken. This is used in some
261 * cases. Say, for non-splittable directories no need to use PDO locks
264 mode = mdo_lock_mode(info->mti_env, mdt_object_child(o),
265 mdt_dlm_mode2mdl_mode(lh->mlh_reg_mode));
267 if (mode != MDL_MINMODE) {
268 lh->mlh_pdo_mode = mdt_mdl_mode2dlm_mode(mode);
271 * Lower layer does not want to specify locking mode. We do it
272 * our selves. No special protection is needed, just flush
273 * client's cache on modification and allow concurrent
276 switch (lh->mlh_reg_mode) {
278 lh->mlh_pdo_mode = LCK_EX;
281 lh->mlh_pdo_mode = LCK_CR;
284 lh->mlh_pdo_mode = LCK_CW;
287 CERROR("Not expected lock type (0x%x)\n",
288 (int)lh->mlh_reg_mode);
293 LASSERT(lh->mlh_pdo_mode != LCK_MINMODE);
297 static int mdt_getstatus(struct mdt_thread_info *info)
299 struct mdt_device *mdt = info->mti_mdt;
300 struct md_device *next = mdt->mdt_child;
301 struct mdt_body *repbody;
306 rc = mdt_check_ucred(info);
308 RETURN(err_serious(rc));
310 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_GETSTATUS_PACK))
311 RETURN(err_serious(-ENOMEM));
313 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
314 rc = next->md_ops->mdo_root_get(info->mti_env, next, &repbody->fid1);
318 repbody->valid |= OBD_MD_FLID;
320 if (mdt->mdt_opts.mo_mds_capa &&
321 info->mti_exp->exp_connect_flags & OBD_CONNECT_MDS_CAPA) {
322 struct mdt_object *root;
323 struct lustre_capa *capa;
325 root = mdt_object_find(info->mti_env, mdt, &repbody->fid1);
327 RETURN(PTR_ERR(root));
329 capa = req_capsule_server_get(info->mti_pill, &RMF_CAPA1);
331 capa->lc_opc = CAPA_OPC_MDS_DEFAULT;
332 rc = mo_capa_get(info->mti_env, mdt_object_child(root), capa,
334 mdt_object_put(info->mti_env, root);
336 repbody->valid |= OBD_MD_FLMDSCAPA;
342 static int mdt_statfs(struct mdt_thread_info *info)
344 struct md_device *next = info->mti_mdt->mdt_child;
345 struct ptlrpc_service *svc;
346 struct obd_statfs *osfs;
351 svc = info->mti_pill->rc_req->rq_rqbd->rqbd_service;
353 /* This will trigger a watchdog timeout */
354 OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_STATFS_LCW_SLEEP,
355 (MDT_SERVICE_WATCHDOG_FACTOR *
356 at_get(&svc->srv_at_estimate)) + 1);
358 rc = mdt_check_ucred(info);
360 RETURN(err_serious(rc));
362 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_STATFS_PACK)) {
363 rc = err_serious(-ENOMEM);
365 osfs = req_capsule_server_get(info->mti_pill, &RMF_OBD_STATFS);
366 rc = next->md_ops->mdo_statfs(info->mti_env, next,
368 statfs_pack(osfs, &info->mti_u.ksfs);
374 * Pack SOM attributes into the reply.
375 * Call under a DLM UPDATE lock.
377 static void mdt_pack_size2body(struct mdt_thread_info *info,
378 struct mdt_object *mo)
381 struct md_attr *ma = &info->mti_attr;
383 LASSERT(ma->ma_attr.la_valid & LA_MODE);
384 b = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
386 /* Check if Size-on-MDS is supported, if this is a regular file,
387 * if SOM is enabled on the object and if SOM cache exists and valid.
388 * Otherwise do not pack Size-on-MDS attributes to the reply. */
389 if (!(mdt_conn_flags(info) & OBD_CONNECT_SOM) ||
390 !S_ISREG(ma->ma_attr.la_mode) ||
391 !mdt_object_is_som_enabled(mo) ||
392 !(ma->ma_valid & MA_SOM))
395 b->valid |= OBD_MD_FLSIZE | OBD_MD_FLBLOCKS;
396 b->size = ma->ma_som->msd_size;
397 b->blocks = ma->ma_som->msd_blocks;
400 void mdt_pack_attr2body(struct mdt_thread_info *info, struct mdt_body *b,
401 const struct lu_attr *attr, const struct lu_fid *fid)
403 struct md_attr *ma = &info->mti_attr;
405 LASSERT(ma->ma_valid & MA_INODE);
407 b->atime = attr->la_atime;
408 b->mtime = attr->la_mtime;
409 b->ctime = attr->la_ctime;
410 b->mode = attr->la_mode;
411 b->size = attr->la_size;
412 b->blocks = attr->la_blocks;
413 b->uid = attr->la_uid;
414 b->gid = attr->la_gid;
415 b->flags = attr->la_flags;
416 b->nlink = attr->la_nlink;
417 b->rdev = attr->la_rdev;
419 /*XXX should pack the reply body according to lu_valid*/
420 b->valid |= OBD_MD_FLCTIME | OBD_MD_FLUID |
421 OBD_MD_FLGID | OBD_MD_FLTYPE |
422 OBD_MD_FLMODE | OBD_MD_FLNLINK | OBD_MD_FLFLAGS |
423 OBD_MD_FLATIME | OBD_MD_FLMTIME ;
425 if (!S_ISREG(attr->la_mode)) {
426 b->valid |= OBD_MD_FLSIZE | OBD_MD_FLBLOCKS | OBD_MD_FLRDEV;
427 } else if (ma->ma_need & MA_LOV && ma->ma_lmm_size == 0) {
428 /* means no objects are allocated on osts. */
429 LASSERT(!(ma->ma_valid & MA_LOV));
430 /* just ignore blocks occupied by extend attributes on MDS */
432 /* if no object is allocated on osts, the size on mds is valid. b=22272 */
433 b->valid |= OBD_MD_FLSIZE | OBD_MD_FLBLOCKS;
438 b->valid |= OBD_MD_FLID;
440 /* FIXME: these should be fixed when new igif ready.*/
441 b->ino = fid_oid(fid); /* 1.6 compatibility */
442 b->generation = fid_ver(fid); /* 1.6 compatibility */
443 b->valid |= OBD_MD_FLGENER; /* 1.6 compatibility */
445 CDEBUG(D_INODE, DFID": nlink=%d, mode=%o, size="LPU64"\n",
446 PFID(fid), b->nlink, b->mode, b->size);
450 mdt_body_reverse_idmap(info, b);
453 static inline int mdt_body_has_lov(const struct lu_attr *la,
454 const struct mdt_body *body)
456 return ((S_ISREG(la->la_mode) && (body->valid & OBD_MD_FLEASIZE)) ||
457 (S_ISDIR(la->la_mode) && (body->valid & OBD_MD_FLDIREA )) );
460 static int mdt_getattr_internal(struct mdt_thread_info *info,
461 struct mdt_object *o, int ma_need)
463 struct md_object *next = mdt_object_child(o);
464 const struct mdt_body *reqbody = info->mti_body;
465 struct ptlrpc_request *req = mdt_info_req(info);
466 struct md_attr *ma = &info->mti_attr;
467 struct lu_attr *la = &ma->ma_attr;
468 struct req_capsule *pill = info->mti_pill;
469 const struct lu_env *env = info->mti_env;
470 struct mdt_body *repbody;
471 struct lu_buf *buffer = &info->mti_buf;
475 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_GETATTR_PACK))
476 RETURN(err_serious(-ENOMEM));
478 repbody = req_capsule_server_get(pill, &RMF_MDT_BODY);
482 rc = mdt_object_exists(o);
484 /* This object is located on remote node.*/
485 repbody->fid1 = *mdt_object_fid(o);
486 repbody->valid = OBD_MD_FLID | OBD_MD_MDS;
490 buffer->lb_buf = req_capsule_server_get(pill, &RMF_MDT_MD);
491 buffer->lb_len = req_capsule_get_size(pill, &RMF_MDT_MD, RCL_SERVER);
493 /* If it is dir object and client require MEA, then we got MEA */
494 if (S_ISDIR(lu_object_attr(&next->mo_lu)) &&
495 reqbody->valid & OBD_MD_MEA) {
496 /* Assumption: MDT_MD size is enough for lmv size. */
497 ma->ma_lmv = buffer->lb_buf;
498 ma->ma_lmv_size = buffer->lb_len;
499 ma->ma_need = MA_LMV | MA_INODE;
501 ma->ma_lmm = buffer->lb_buf;
502 ma->ma_lmm_size = buffer->lb_len;
503 ma->ma_need = MA_LOV | MA_INODE;
506 if (S_ISDIR(lu_object_attr(&next->mo_lu)) &&
507 reqbody->valid & OBD_MD_FLDIREA &&
508 lustre_msg_get_opc(req->rq_reqmsg) == MDS_GETATTR) {
509 /* get default stripe info for this dir. */
510 ma->ma_need |= MA_LOV_DEF;
512 ma->ma_need |= ma_need;
513 if (ma->ma_need & MA_SOM)
514 ma->ma_som = &info->mti_u.som.data;
516 rc = mo_attr_get(env, next, ma);
518 CERROR("getattr error for "DFID": %d\n",
519 PFID(mdt_object_fid(o)), rc);
523 if (likely(ma->ma_valid & MA_INODE))
524 mdt_pack_attr2body(info, repbody, la, mdt_object_fid(o));
528 if (mdt_body_has_lov(la, reqbody)) {
529 if (ma->ma_valid & MA_LOV) {
530 LASSERT(ma->ma_lmm_size);
531 mdt_dump_lmm(D_INFO, ma->ma_lmm);
532 repbody->eadatasize = ma->ma_lmm_size;
533 if (S_ISDIR(la->la_mode))
534 repbody->valid |= OBD_MD_FLDIREA;
536 repbody->valid |= OBD_MD_FLEASIZE;
538 if (ma->ma_valid & MA_LMV) {
539 LASSERT(S_ISDIR(la->la_mode));
540 repbody->eadatasize = ma->ma_lmv_size;
541 repbody->valid |= (OBD_MD_FLDIREA|OBD_MD_MEA);
543 } else if (S_ISLNK(la->la_mode) &&
544 reqbody->valid & OBD_MD_LINKNAME) {
545 buffer->lb_buf = ma->ma_lmm;
546 buffer->lb_len = reqbody->eadatasize;
547 rc = mo_readlink(env, next, buffer);
548 if (unlikely(rc <= 0)) {
549 CERROR("readlink failed: %d\n", rc);
552 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_READLINK_EPROTO))
554 repbody->valid |= OBD_MD_LINKNAME;
555 repbody->eadatasize = rc;
557 ((char*)ma->ma_lmm)[rc - 1] = 0;
558 CDEBUG(D_INODE, "symlink dest %s, len = %d\n",
559 (char*)ma->ma_lmm, rc);
564 if (reqbody->valid & OBD_MD_FLMODEASIZE) {
565 repbody->max_cookiesize = info->mti_mdt->mdt_max_cookiesize;
566 repbody->max_mdsize = info->mti_mdt->mdt_max_mdsize;
567 repbody->valid |= OBD_MD_FLMODEASIZE;
568 CDEBUG(D_INODE, "I am going to change the MAX_MD_SIZE & "
569 "MAX_COOKIE to : %d:%d\n", repbody->max_mdsize,
570 repbody->max_cookiesize);
573 if (exp_connect_rmtclient(info->mti_exp) &&
574 reqbody->valid & OBD_MD_FLRMTPERM) {
575 void *buf = req_capsule_server_get(pill, &RMF_ACL);
577 /* mdt_getattr_lock only */
578 rc = mdt_pack_remote_perm(info, o, buf);
580 repbody->valid &= ~OBD_MD_FLRMTPERM;
581 repbody->aclsize = 0;
584 repbody->valid |= OBD_MD_FLRMTPERM;
585 repbody->aclsize = sizeof(struct mdt_remote_perm);
588 #ifdef CONFIG_FS_POSIX_ACL
589 else if ((req->rq_export->exp_connect_flags & OBD_CONNECT_ACL) &&
590 (reqbody->valid & OBD_MD_FLACL)) {
591 buffer->lb_buf = req_capsule_server_get(pill, &RMF_ACL);
592 buffer->lb_len = req_capsule_get_size(pill,
593 &RMF_ACL, RCL_SERVER);
594 if (buffer->lb_len > 0) {
595 rc = mo_xattr_get(env, next, buffer,
596 XATTR_NAME_ACL_ACCESS);
598 if (rc == -ENODATA) {
599 repbody->aclsize = 0;
600 repbody->valid |= OBD_MD_FLACL;
602 } else if (rc == -EOPNOTSUPP) {
605 CERROR("got acl size: %d\n", rc);
608 repbody->aclsize = rc;
609 repbody->valid |= OBD_MD_FLACL;
616 if (reqbody->valid & OBD_MD_FLMDSCAPA &&
617 info->mti_mdt->mdt_opts.mo_mds_capa &&
618 info->mti_exp->exp_connect_flags & OBD_CONNECT_MDS_CAPA) {
619 struct lustre_capa *capa;
621 capa = req_capsule_server_get(pill, &RMF_CAPA1);
623 capa->lc_opc = CAPA_OPC_MDS_DEFAULT;
624 rc = mo_capa_get(env, next, capa, 0);
627 repbody->valid |= OBD_MD_FLMDSCAPA;
632 static int mdt_renew_capa(struct mdt_thread_info *info)
634 struct mdt_object *obj = info->mti_object;
635 struct mdt_body *body;
636 struct lustre_capa *capa, *c;
640 /* if object doesn't exist, or server has disabled capability,
641 * return directly, client will find body->valid OBD_MD_FLOSSCAPA
644 if (!obj || !info->mti_mdt->mdt_opts.mo_oss_capa ||
645 !(info->mti_exp->exp_connect_flags & OBD_CONNECT_OSS_CAPA))
648 body = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
649 LASSERT(body != NULL);
651 c = req_capsule_client_get(info->mti_pill, &RMF_CAPA1);
654 capa = req_capsule_server_get(info->mti_pill, &RMF_CAPA2);
658 rc = mo_capa_get(info->mti_env, mdt_object_child(obj), capa, 1);
660 body->valid |= OBD_MD_FLOSSCAPA;
664 static int mdt_getattr(struct mdt_thread_info *info)
666 struct mdt_object *obj = info->mti_object;
667 struct req_capsule *pill = info->mti_pill;
668 struct mdt_body *reqbody;
669 struct mdt_body *repbody;
675 reqbody = req_capsule_client_get(pill, &RMF_MDT_BODY);
678 if (reqbody->valid & OBD_MD_FLOSSCAPA) {
679 rc = req_capsule_server_pack(pill);
681 RETURN(err_serious(rc));
682 rc = mdt_renew_capa(info);
683 GOTO(out_shrink, rc);
686 LASSERT(obj != NULL);
687 LASSERT(lu_object_assert_exists(&obj->mot_obj.mo_lu));
689 mode = lu_object_attr(&obj->mot_obj.mo_lu);
690 if (S_ISLNK(mode) && (reqbody->valid & OBD_MD_LINKNAME) &&
691 (reqbody->eadatasize > info->mti_mdt->mdt_max_mdsize))
692 md_size = reqbody->eadatasize;
694 md_size = info->mti_mdt->mdt_max_mdsize;
696 req_capsule_set_size(pill, &RMF_MDT_MD, RCL_SERVER, md_size);
698 rc = req_capsule_server_pack(pill);
699 if (unlikely(rc != 0))
700 RETURN(err_serious(rc));
702 repbody = req_capsule_server_get(pill, &RMF_MDT_BODY);
703 LASSERT(repbody != NULL);
704 repbody->eadatasize = 0;
705 repbody->aclsize = 0;
707 if (reqbody->valid & OBD_MD_FLRMTPERM)
708 rc = mdt_init_ucred(info, reqbody);
710 rc = mdt_check_ucred(info);
712 GOTO(out_shrink, rc);
714 info->mti_spec.sp_ck_split = !!(reqbody->valid & OBD_MD_FLCKSPLIT);
715 info->mti_cross_ref = !!(reqbody->valid & OBD_MD_FLCROSSREF);
718 * Don't check capability at all, because rename might getattr for
719 * remote obj, and at that time no capability is available.
721 mdt_set_capainfo(info, 1, &reqbody->fid1, BYPASS_CAPA);
722 rc = mdt_getattr_internal(info, obj, 0);
723 if (reqbody->valid & OBD_MD_FLRMTPERM)
724 mdt_exit_ucred(info);
727 mdt_shrink_reply(info);
731 static int mdt_is_subdir(struct mdt_thread_info *info)
733 struct mdt_object *o = info->mti_object;
734 struct req_capsule *pill = info->mti_pill;
735 const struct mdt_body *body = info->mti_body;
736 struct mdt_body *repbody;
742 repbody = req_capsule_server_get(pill, &RMF_MDT_BODY);
745 * We save last checked parent fid to @repbody->fid1 for remote
748 LASSERT(fid_is_sane(&body->fid2));
749 LASSERT(mdt_object_exists(o) > 0);
750 rc = mdo_is_subdir(info->mti_env, mdt_object_child(o),
751 &body->fid2, &repbody->fid1);
752 if (rc == 0 || rc == -EREMOTE)
753 repbody->valid |= OBD_MD_FLID;
758 static int mdt_raw_lookup(struct mdt_thread_info *info,
759 struct mdt_object *parent,
760 const struct lu_name *lname,
761 struct ldlm_reply *ldlm_rep)
763 struct md_object *next = mdt_object_child(info->mti_object);
764 const struct mdt_body *reqbody = info->mti_body;
765 struct lu_fid *child_fid = &info->mti_tmp_fid1;
766 struct mdt_body *repbody;
770 if (reqbody->valid != OBD_MD_FLID)
773 LASSERT(!info->mti_cross_ref);
775 /* Only got the fid of this obj by name */
776 rc = mdo_lookup(info->mti_env, next, lname, child_fid,
779 /* XXX is raw_lookup possible as intent operation? */
782 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_NEG);
785 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_POS);
787 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
790 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
791 repbody->fid1 = *child_fid;
792 repbody->valid = OBD_MD_FLID;
798 * UPDATE lock should be taken against parent, and be release before exit;
799 * child_bits lock should be taken against child, and be returned back:
800 * (1)normal request should release the child lock;
801 * (2)intent request will grant the lock to client.
803 static int mdt_getattr_name_lock(struct mdt_thread_info *info,
804 struct mdt_lock_handle *lhc,
806 struct ldlm_reply *ldlm_rep)
808 struct ptlrpc_request *req = mdt_info_req(info);
809 struct mdt_body *reqbody = NULL;
810 struct mdt_object *parent = info->mti_object;
811 struct mdt_object *child;
812 struct md_object *next = mdt_object_child(parent);
813 struct lu_fid *child_fid = &info->mti_tmp_fid1;
814 struct lu_name *lname = NULL;
815 const char *name = NULL;
817 struct mdt_lock_handle *lhp;
818 struct ldlm_lock *lock;
819 struct ldlm_res_id *res_id;
826 is_resent = lustre_handle_is_used(&lhc->mlh_reg_lh);
827 LASSERT(ergo(is_resent,
828 lustre_msg_get_flags(req->rq_reqmsg) & MSG_RESENT));
830 LASSERT(parent != NULL);
831 name = req_capsule_client_get(info->mti_pill, &RMF_NAME);
833 RETURN(err_serious(-EFAULT));
835 namelen = req_capsule_get_size(info->mti_pill, &RMF_NAME,
837 if (!info->mti_cross_ref) {
839 * XXX: Check for "namelen == 0" is for getattr by fid
840 * (OBD_CONNECT_ATTRFID), otherwise do not allow empty name,
841 * that is the name must contain at least one character and
842 * the terminating '\0'
845 reqbody = req_capsule_client_get(info->mti_pill,
847 LASSERT(fid_is_sane(&reqbody->fid2));
850 CDEBUG(D_INODE, "getattr with lock for "DFID"/"DFID", "
852 PFID(mdt_object_fid(parent)), PFID(&reqbody->fid2),
855 lname = mdt_name(info->mti_env, (char *)name, namelen);
856 CDEBUG(D_INODE, "getattr with lock for "DFID"/%s, "
857 "ldlm_rep = %p\n", PFID(mdt_object_fid(parent)),
861 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_EXECD);
863 rc = mdt_object_exists(parent);
864 if (unlikely(rc == 0)) {
865 LU_OBJECT_DEBUG(D_WARNING, info->mti_env,
866 &parent->mot_obj.mo_lu,
867 "Parent doesn't exist!\n");
869 } else if (!info->mti_cross_ref) {
870 LASSERTF(rc > 0, "Parent "DFID" is on remote server\n",
871 PFID(mdt_object_fid(parent)));
874 rc = mdt_raw_lookup(info, parent, lname, ldlm_rep);
882 if (info->mti_cross_ref) {
883 /* Only getattr on the child. Parent is on another node. */
884 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_POS);
886 CDEBUG(D_INODE, "partial getattr_name child_fid = "DFID", "
887 "ldlm_rep=%p\n", PFID(mdt_object_fid(child)), ldlm_rep);
890 /* Do not take lock for resent case. */
891 lock = ldlm_handle2lock(&lhc->mlh_reg_lh);
892 LASSERTF(lock != NULL, "Invalid lock handle "LPX64"\n",
893 lhc->mlh_reg_lh.cookie);
894 LASSERT(fid_res_name_eq(mdt_object_fid(child),
895 &lock->l_resource->lr_name));
899 mdt_lock_handle_init(lhc);
900 mdt_lock_reg_init(lhc, LCK_PR);
903 * Object's name is on another MDS, no lookup lock is
904 * needed here but update is.
906 child_bits &= ~MDS_INODELOCK_LOOKUP;
907 child_bits |= MDS_INODELOCK_UPDATE;
909 rc = mdt_object_lock(info, child, lhc, child_bits,
913 /* Finally, we can get attr for child. */
914 mdt_set_capainfo(info, 0, mdt_object_fid(child),
916 rc = mdt_getattr_internal(info, child, 0);
917 if (unlikely(rc != 0))
918 mdt_object_unlock(info, child, lhc, 1);
923 /* step 1: lock parent */
924 lhp = &info->mti_lh[MDT_LH_PARENT];
925 mdt_lock_pdo_init(lhp, LCK_PR, name, namelen);
926 rc = mdt_object_lock(info, parent, lhp, MDS_INODELOCK_UPDATE,
929 if (unlikely(rc != 0))
933 /* step 2: lookup child's fid by name */
934 rc = mdo_lookup(info->mti_env, next, lname, child_fid,
939 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_NEG);
940 GOTO(out_parent, rc);
942 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_POS);
944 *child_fid = reqbody->fid2;
945 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_POS);
949 *step 3: find the child object by fid & lock it.
950 * regardless if it is local or remote.
952 child = mdt_object_find(info->mti_env, info->mti_mdt, child_fid);
954 if (unlikely(IS_ERR(child)))
955 GOTO(out_parent, rc = PTR_ERR(child));
957 /* Do not take lock for resent case. */
958 lock = ldlm_handle2lock(&lhc->mlh_reg_lh);
959 LASSERTF(lock != NULL, "Invalid lock handle "LPX64"\n",
960 lhc->mlh_reg_lh.cookie);
962 res_id = &lock->l_resource->lr_name;
963 if (!fid_res_name_eq(mdt_object_fid(child),
964 &lock->l_resource->lr_name)) {
965 LASSERTF(fid_res_name_eq(mdt_object_fid(parent),
966 &lock->l_resource->lr_name),
967 "Lock res_id: %lu/%lu/%lu, Fid: "DFID".\n",
968 (unsigned long)res_id->name[0],
969 (unsigned long)res_id->name[1],
970 (unsigned long)res_id->name[2],
971 PFID(mdt_object_fid(parent)));
972 CWARN("Although resent, but still not get child lock"
973 "parent:"DFID" child:"DFID"\n",
974 PFID(mdt_object_fid(parent)),
975 PFID(mdt_object_fid(child)));
976 lustre_msg_clear_flags(req->rq_reqmsg, MSG_RESENT);
985 ma = &info->mti_attr;
987 OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_RESEND, obd_timeout*2);
988 mdt_lock_handle_init(lhc);
989 mdt_lock_reg_init(lhc, LCK_PR);
991 if (mdt_object_exists(child) == 0) {
992 LU_OBJECT_DEBUG(D_WARNING, info->mti_env,
993 &child->mot_obj.mo_lu,
994 "Object doesn't exist!\n");
995 GOTO(out_child, rc = -ESTALE);
999 ma->ma_need = MA_INODE;
1000 rc = mo_attr_get(info->mti_env, next, ma);
1001 if (unlikely(rc != 0))
1002 GOTO(out_child, rc);
1004 /* If the file has not been changed for some time, we return
1005 * not only a LOOKUP lock, but also an UPDATE lock and this
1006 * might save us RPC on later STAT. For directories, it also
1007 * let negative dentry starts working for this dir. */
1008 if (ma->ma_valid & MA_INODE &&
1009 ma->ma_attr.la_valid & LA_CTIME &&
1010 info->mti_mdt->mdt_namespace->ns_ctime_age_limit +
1011 ma->ma_attr.la_ctime < cfs_time_current_sec())
1012 child_bits |= MDS_INODELOCK_UPDATE;
1014 rc = mdt_object_lock(info, child, lhc, child_bits,
1017 if (unlikely(rc != 0))
1018 GOTO(out_child, rc);
1021 lock = ldlm_handle2lock(&lhc->mlh_reg_lh);
1022 /* Get MA_SOM attributes if update lock is given. */
1024 lock->l_policy_data.l_inodebits.bits & MDS_INODELOCK_UPDATE &&
1025 S_ISREG(lu_object_attr(&mdt_object_child(child)->mo_lu)))
1028 /* finally, we can get attr for child. */
1029 mdt_set_capainfo(info, 1, child_fid, BYPASS_CAPA);
1030 rc = mdt_getattr_internal(info, child, ma_need);
1031 if (unlikely(rc != 0)) {
1032 mdt_object_unlock(info, child, lhc, 1);
1034 /* Debugging code. */
1035 res_id = &lock->l_resource->lr_name;
1036 LDLM_DEBUG(lock, "Returning lock to client");
1037 LASSERTF(fid_res_name_eq(mdt_object_fid(child),
1038 &lock->l_resource->lr_name),
1039 "Lock res_id: %lu/%lu/%lu, Fid: "DFID".\n",
1040 (unsigned long)res_id->name[0],
1041 (unsigned long)res_id->name[1],
1042 (unsigned long)res_id->name[2],
1043 PFID(mdt_object_fid(child)));
1044 mdt_pack_size2body(info, child);
1047 LDLM_LOCK_PUT(lock);
1051 mdt_object_put(info->mti_env, child);
1053 mdt_object_unlock(info, parent, lhp, 1);
1057 /* normal handler: should release the child lock */
1058 static int mdt_getattr_name(struct mdt_thread_info *info)
1060 struct mdt_lock_handle *lhc = &info->mti_lh[MDT_LH_CHILD];
1061 struct mdt_body *reqbody;
1062 struct mdt_body *repbody;
1066 reqbody = req_capsule_client_get(info->mti_pill, &RMF_MDT_BODY);
1067 LASSERT(reqbody != NULL);
1068 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
1069 LASSERT(repbody != NULL);
1071 info->mti_spec.sp_ck_split = !!(reqbody->valid & OBD_MD_FLCKSPLIT);
1072 info->mti_cross_ref = !!(reqbody->valid & OBD_MD_FLCROSSREF);
1073 repbody->eadatasize = 0;
1074 repbody->aclsize = 0;
1076 rc = mdt_init_ucred(info, reqbody);
1078 GOTO(out_shrink, rc);
1080 rc = mdt_getattr_name_lock(info, lhc, MDS_INODELOCK_UPDATE, NULL);
1081 if (lustre_handle_is_used(&lhc->mlh_reg_lh)) {
1082 ldlm_lock_decref(&lhc->mlh_reg_lh, lhc->mlh_reg_mode);
1083 lhc->mlh_reg_lh.cookie = 0;
1085 mdt_exit_ucred(info);
1088 mdt_shrink_reply(info);
1092 static const struct lu_device_operations mdt_lu_ops;
1094 static int lu_device_is_mdt(struct lu_device *d)
1096 return ergo(d != NULL && d->ld_ops != NULL, d->ld_ops == &mdt_lu_ops);
1099 static int mdt_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
1100 void *karg, void *uarg);
1102 static int mdt_set_info(struct mdt_thread_info *info)
1104 struct ptlrpc_request *req = mdt_info_req(info);
1107 int keylen, vallen, rc = 0;
1110 rc = req_capsule_server_pack(info->mti_pill);
1114 key = req_capsule_client_get(info->mti_pill, &RMF_SETINFO_KEY);
1116 DEBUG_REQ(D_HA, req, "no set_info key");
1120 keylen = req_capsule_get_size(info->mti_pill, &RMF_SETINFO_KEY,
1123 val = req_capsule_client_get(info->mti_pill, &RMF_SETINFO_VAL);
1125 DEBUG_REQ(D_HA, req, "no set_info val");
1129 vallen = req_capsule_get_size(info->mti_pill, &RMF_SETINFO_VAL,
1132 /* Swab any part of val you need to here */
1133 if (KEY_IS(KEY_READ_ONLY)) {
1135 lustre_msg_set_status(req->rq_repmsg, 0);
1137 cfs_spin_lock(&req->rq_export->exp_lock);
1139 req->rq_export->exp_connect_flags |= OBD_CONNECT_RDONLY;
1141 req->rq_export->exp_connect_flags &=~OBD_CONNECT_RDONLY;
1142 cfs_spin_unlock(&req->rq_export->exp_lock);
1144 } else if (KEY_IS(KEY_CHANGELOG_CLEAR)) {
1145 struct changelog_setinfo *cs =
1146 (struct changelog_setinfo *)val;
1147 if (vallen != sizeof(*cs)) {
1148 CERROR("Bad changelog_clear setinfo size %d\n", vallen);
1151 if (ptlrpc_req_need_swab(req)) {
1152 __swab64s(&cs->cs_recno);
1153 __swab32s(&cs->cs_id);
1156 rc = mdt_iocontrol(OBD_IOC_CHANGELOG_CLEAR, info->mti_exp,
1158 lustre_msg_set_status(req->rq_repmsg, rc);
1166 static int mdt_connect(struct mdt_thread_info *info)
1169 struct ptlrpc_request *req;
1171 req = mdt_info_req(info);
1172 rc = target_handle_connect(req);
1174 LASSERT(req->rq_export != NULL);
1175 info->mti_mdt = mdt_dev(req->rq_export->exp_obd->obd_lu_dev);
1176 rc = mdt_init_sec_level(info);
1178 rc = mdt_init_idmap(info);
1180 obd_disconnect(class_export_get(req->rq_export));
1182 rc = err_serious(rc);
1187 static int mdt_disconnect(struct mdt_thread_info *info)
1192 rc = target_handle_disconnect(mdt_info_req(info));
1194 rc = err_serious(rc);
1198 static int mdt_sendpage(struct mdt_thread_info *info,
1199 struct lu_rdpg *rdpg)
1201 struct ptlrpc_request *req = mdt_info_req(info);
1202 struct obd_export *exp = req->rq_export;
1203 struct ptlrpc_bulk_desc *desc;
1204 struct l_wait_info *lwi = &info->mti_u.rdpg.mti_wait_info;
1212 desc = ptlrpc_prep_bulk_exp(req, rdpg->rp_npages, BULK_PUT_SOURCE,
1217 for (i = 0, tmpcount = rdpg->rp_count;
1218 i < rdpg->rp_npages; i++, tmpcount -= tmpsize) {
1219 tmpsize = min_t(int, tmpcount, CFS_PAGE_SIZE);
1220 ptlrpc_prep_bulk_page(desc, rdpg->rp_pages[i], 0, tmpsize);
1223 LASSERT(desc->bd_nob == rdpg->rp_count);
1224 rc = sptlrpc_svc_wrap_bulk(req, desc);
1226 GOTO(free_desc, rc);
1228 rc = ptlrpc_start_bulk_transfer(desc);
1230 GOTO(free_desc, rc);
1232 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_SENDPAGE))
1233 GOTO(abort_bulk, rc = 0);
1236 timeout = (int) req->rq_deadline - cfs_time_current_sec();
1238 CERROR("Req deadline already passed %lu (now: %lu)\n",
1239 req->rq_deadline, cfs_time_current_sec());
1240 *lwi = LWI_TIMEOUT_INTERVAL(cfs_time_seconds(max(timeout, 1)),
1241 cfs_time_seconds(1), NULL, NULL);
1242 rc = l_wait_event(desc->bd_waitq,
1243 !ptlrpc_server_bulk_active(desc) ||
1245 exp->exp_abort_active_req, lwi);
1246 LASSERT (rc == 0 || rc == -ETIMEDOUT);
1247 } while ((rc == -ETIMEDOUT) &&
1248 (req->rq_deadline > cfs_time_current_sec()));
1251 if (desc->bd_success &&
1252 desc->bd_nob_transferred == rdpg->rp_count)
1253 GOTO(free_desc, rc);
1256 if (exp->exp_abort_active_req || exp->exp_failed)
1257 GOTO(abort_bulk, rc);
1260 DEBUG_REQ(D_ERROR, req, "bulk failed: %s %d(%d), evicting %s@%s",
1261 (rc == -ETIMEDOUT) ? "timeout" : "network error",
1262 desc->bd_nob_transferred, rdpg->rp_count,
1263 exp->exp_client_uuid.uuid,
1264 exp->exp_connection->c_remote_uuid.uuid);
1266 class_fail_export(exp);
1270 ptlrpc_abort_bulk(desc);
1272 ptlrpc_free_bulk(desc);
1276 #ifdef HAVE_SPLIT_SUPPORT
1278 * Retrieve dir entry from the page and insert it to the slave object, actually,
1279 * this should be in osd layer, but since it will not in the final product, so
1280 * just do it here and do not define more moo api anymore for this.
1282 static int mdt_write_dir_page(struct mdt_thread_info *info, struct page *page,
1285 struct mdt_object *object = info->mti_object;
1286 struct lu_fid *lf = &info->mti_tmp_fid2;
1287 struct md_attr *ma = &info->mti_attr;
1288 struct lu_dirpage *dp;
1289 struct lu_dirent *ent;
1290 int rc = 0, offset = 0;
1293 /* Make sure we have at least one entry. */
1298 * Disable trans for this name insert, since it will include many trans
1301 info->mti_no_need_trans = 1;
1303 * When write_dir_page, no need update parent's ctime,
1304 * and no permission check for name_insert.
1306 ma->ma_attr.la_ctime = 0;
1307 ma->ma_attr.la_valid = LA_MODE;
1308 ma->ma_valid = MA_INODE;
1311 dp = page_address(page);
1312 offset = (int)((__u32)lu_dirent_start(dp) - (__u32)dp);
1314 for (ent = lu_dirent_start(dp); ent != NULL;
1315 ent = lu_dirent_next(ent)) {
1316 struct lu_name *lname;
1319 if (le16_to_cpu(ent->lde_namelen) == 0)
1322 fid_le_to_cpu(lf, &ent->lde_fid);
1323 if (le64_to_cpu(ent->lde_hash) & MAX_HASH_HIGHEST_BIT)
1324 ma->ma_attr.la_mode = S_IFDIR;
1326 ma->ma_attr.la_mode = 0;
1327 OBD_ALLOC(name, le16_to_cpu(ent->lde_namelen) + 1);
1329 GOTO(out, rc = -ENOMEM);
1331 memcpy(name, ent->lde_name, le16_to_cpu(ent->lde_namelen));
1332 lname = mdt_name(info->mti_env, name,
1333 le16_to_cpu(ent->lde_namelen));
1334 ma->ma_attr_flags |= (MDS_PERM_BYPASS | MDS_QUOTA_IGNORE);
1335 rc = mdo_name_insert(info->mti_env,
1336 md_object_next(&object->mot_obj),
1338 OBD_FREE(name, le16_to_cpu(ent->lde_namelen) + 1);
1340 CERROR("Can't insert %*.*s, rc %d\n",
1341 le16_to_cpu(ent->lde_namelen),
1342 le16_to_cpu(ent->lde_namelen),
1347 offset += lu_dirent_size(ent);
1357 static int mdt_bulk_timeout(void *data)
1361 CERROR("mdt bulk transfer timeout \n");
1366 static int mdt_writepage(struct mdt_thread_info *info)
1368 struct ptlrpc_request *req = mdt_info_req(info);
1369 struct mdt_body *reqbody;
1370 struct l_wait_info *lwi;
1371 struct ptlrpc_bulk_desc *desc;
1377 reqbody = req_capsule_client_get(info->mti_pill, &RMF_MDT_BODY);
1378 if (reqbody == NULL)
1379 RETURN(err_serious(-EFAULT));
1381 desc = ptlrpc_prep_bulk_exp(req, 1, BULK_GET_SINK, MDS_BULK_PORTAL);
1383 RETURN(err_serious(-ENOMEM));
1385 /* allocate the page for the desc */
1386 page = cfs_alloc_page(CFS_ALLOC_STD);
1388 GOTO(desc_cleanup, rc = -ENOMEM);
1390 CDEBUG(D_INFO, "Received page offset %d size %d \n",
1391 (int)reqbody->size, (int)reqbody->nlink);
1393 ptlrpc_prep_bulk_page(desc, page, (int)reqbody->size,
1394 (int)reqbody->nlink);
1396 rc = sptlrpc_svc_prep_bulk(req, desc);
1398 GOTO(cleanup_page, rc);
1400 * Check if client was evicted while we were doing i/o before touching
1405 GOTO(cleanup_page, rc = -ENOMEM);
1407 if (desc->bd_export->exp_failed)
1410 rc = ptlrpc_start_bulk_transfer (desc);
1412 *lwi = LWI_TIMEOUT_INTERVAL(obd_timeout * CFS_HZ / 4, CFS_HZ,
1413 mdt_bulk_timeout, desc);
1414 rc = l_wait_event(desc->bd_waitq, !ptlrpc_bulk_active(desc) ||
1415 desc->bd_export->exp_failed, lwi);
1416 LASSERT(rc == 0 || rc == -ETIMEDOUT);
1417 if (rc == -ETIMEDOUT) {
1418 DEBUG_REQ(D_ERROR, req, "timeout on bulk GET");
1419 ptlrpc_abort_bulk(desc);
1420 } else if (desc->bd_export->exp_failed) {
1421 DEBUG_REQ(D_ERROR, req, "Eviction on bulk GET");
1423 ptlrpc_abort_bulk(desc);
1424 } else if (!desc->bd_success ||
1425 desc->bd_nob_transferred != desc->bd_nob) {
1426 DEBUG_REQ(D_ERROR, req, "%s bulk GET %d(%d)",
1428 "truncated" : "network error on",
1429 desc->bd_nob_transferred, desc->bd_nob);
1430 /* XXX should this be a different errno? */
1434 DEBUG_REQ(D_ERROR, req, "ptlrpc_bulk_get failed: rc %d", rc);
1437 GOTO(cleanup_lwi, rc);
1438 rc = mdt_write_dir_page(info, page, reqbody->nlink);
1443 cfs_free_page(page);
1445 ptlrpc_free_bulk(desc);
1450 static int mdt_readpage(struct mdt_thread_info *info)
1452 struct mdt_object *object = info->mti_object;
1453 struct lu_rdpg *rdpg = &info->mti_u.rdpg.mti_rdpg;
1454 struct mdt_body *reqbody;
1455 struct mdt_body *repbody;
1460 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_READPAGE_PACK))
1461 RETURN(err_serious(-ENOMEM));
1463 reqbody = req_capsule_client_get(info->mti_pill, &RMF_MDT_BODY);
1464 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
1465 if (reqbody == NULL || repbody == NULL)
1466 RETURN(err_serious(-EFAULT));
1469 * prepare @rdpg before calling lower layers and transfer itself. Here
1470 * reqbody->size contains offset of where to start to read and
1471 * reqbody->nlink contains number bytes to read.
1473 rdpg->rp_hash = reqbody->size;
1474 if (rdpg->rp_hash != reqbody->size) {
1475 CERROR("Invalid hash: "LPX64" != "LPX64"\n",
1476 rdpg->rp_hash, reqbody->size);
1480 rdpg->rp_attrs = reqbody->mode;
1481 rdpg->rp_count = reqbody->nlink;
1482 rdpg->rp_npages = (rdpg->rp_count + CFS_PAGE_SIZE - 1)>>CFS_PAGE_SHIFT;
1483 OBD_ALLOC(rdpg->rp_pages, rdpg->rp_npages * sizeof rdpg->rp_pages[0]);
1484 if (rdpg->rp_pages == NULL)
1487 for (i = 0; i < rdpg->rp_npages; ++i) {
1488 rdpg->rp_pages[i] = cfs_alloc_page(CFS_ALLOC_STD);
1489 if (rdpg->rp_pages[i] == NULL)
1490 GOTO(free_rdpg, rc = -ENOMEM);
1493 /* call lower layers to fill allocated pages with directory data */
1494 rc = mo_readpage(info->mti_env, mdt_object_child(object), rdpg);
1496 GOTO(free_rdpg, rc);
1498 /* send pages to client */
1499 rc = mdt_sendpage(info, rdpg);
1504 for (i = 0; i < rdpg->rp_npages; i++)
1505 if (rdpg->rp_pages[i] != NULL)
1506 cfs_free_page(rdpg->rp_pages[i]);
1507 OBD_FREE(rdpg->rp_pages, rdpg->rp_npages * sizeof rdpg->rp_pages[0]);
1509 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_SENDPAGE))
1515 static int mdt_reint_internal(struct mdt_thread_info *info,
1516 struct mdt_lock_handle *lhc,
1519 struct req_capsule *pill = info->mti_pill;
1520 struct mdt_device *mdt = info->mti_mdt;
1521 struct md_quota *mq = md_quota(info->mti_env);
1522 struct mdt_body *repbody;
1527 if (req_capsule_has_field(pill, &RMF_MDT_MD, RCL_SERVER))
1528 req_capsule_set_size(pill, &RMF_MDT_MD, RCL_SERVER,
1529 mdt->mdt_max_mdsize);
1530 if (req_capsule_has_field(pill, &RMF_LOGCOOKIES, RCL_SERVER))
1531 req_capsule_set_size(pill, &RMF_LOGCOOKIES, RCL_SERVER,
1532 mdt->mdt_max_cookiesize);
1534 rc = req_capsule_server_pack(pill);
1536 CERROR("Can't pack response, rc %d\n", rc);
1537 RETURN(err_serious(rc));
1540 if (req_capsule_has_field(pill, &RMF_MDT_BODY, RCL_SERVER)) {
1541 repbody = req_capsule_server_get(pill, &RMF_MDT_BODY);
1543 repbody->eadatasize = 0;
1544 repbody->aclsize = 0;
1547 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_REINT_UNPACK))
1548 GOTO(out_shrink, rc = err_serious(-EFAULT));
1550 rc = mdt_reint_unpack(info, op);
1552 CERROR("Can't unpack reint, rc %d\n", rc);
1553 GOTO(out_shrink, rc = err_serious(rc));
1556 OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_REINT_DELAY, 10);
1558 /* for replay no cookkie / lmm need, because client have this already */
1559 if (info->mti_spec.no_create == 1) {
1560 if (req_capsule_has_field(pill, &RMF_MDT_MD, RCL_SERVER))
1561 req_capsule_set_size(pill, &RMF_MDT_MD, RCL_SERVER, 0);
1563 if (req_capsule_has_field(pill, &RMF_LOGCOOKIES, RCL_SERVER))
1564 req_capsule_set_size(pill, &RMF_LOGCOOKIES, RCL_SERVER,
1568 rc = mdt_init_ucred_reint(info);
1570 GOTO(out_shrink, rc);
1572 rc = mdt_fix_attr_ucred(info, op);
1574 GOTO(out_ucred, rc = err_serious(rc));
1576 if (mdt_check_resent(info, mdt_reconstruct, lhc)) {
1577 rc = lustre_msg_get_status(mdt_info_req(info)->rq_repmsg);
1578 GOTO(out_ucred, rc);
1580 mq->mq_exp = info->mti_exp;
1581 rc = mdt_reint_rec(info, lhc);
1584 mdt_exit_ucred(info);
1586 mdt_shrink_reply(info);
1590 static long mdt_reint_opcode(struct mdt_thread_info *info,
1591 const struct req_format **fmt)
1593 struct mdt_rec_reint *rec;
1596 opc = err_serious(-EFAULT);
1597 rec = req_capsule_client_get(info->mti_pill, &RMF_REC_REINT);
1599 opc = rec->rr_opcode;
1600 DEBUG_REQ(D_INODE, mdt_info_req(info), "reint opt = %ld", opc);
1601 if (opc < REINT_MAX && fmt[opc] != NULL)
1602 req_capsule_extend(info->mti_pill, fmt[opc]);
1604 CERROR("Unsupported opc: %ld\n", opc);
1605 opc = err_serious(opc);
1611 static int mdt_reint(struct mdt_thread_info *info)
1616 static const struct req_format *reint_fmts[REINT_MAX] = {
1617 [REINT_SETATTR] = &RQF_MDS_REINT_SETATTR,
1618 [REINT_CREATE] = &RQF_MDS_REINT_CREATE,
1619 [REINT_LINK] = &RQF_MDS_REINT_LINK,
1620 [REINT_UNLINK] = &RQF_MDS_REINT_UNLINK,
1621 [REINT_RENAME] = &RQF_MDS_REINT_RENAME,
1622 [REINT_OPEN] = &RQF_MDS_REINT_OPEN,
1623 [REINT_SETXATTR] = &RQF_MDS_REINT_SETXATTR
1628 opc = mdt_reint_opcode(info, reint_fmts);
1631 * No lock possible here from client to pass it to reint code
1634 rc = mdt_reint_internal(info, NULL, opc);
1639 info->mti_fail_id = OBD_FAIL_MDS_REINT_NET_REP;
1643 /* this should sync the whole device */
1644 static int mdt_device_sync(const struct lu_env *env, struct mdt_device *mdt)
1646 struct dt_device *dt = mdt->mdt_bottom;
1650 rc = dt->dd_ops->dt_sync(env, dt);
1654 /* this should sync this object */
1655 static int mdt_object_sync(struct mdt_thread_info *info)
1657 struct md_object *next;
1661 if (!mdt_object_exists(info->mti_object)) {
1662 CWARN("Non existing object "DFID"!\n",
1663 PFID(mdt_object_fid(info->mti_object)));
1666 next = mdt_object_child(info->mti_object);
1667 rc = mo_object_sync(info->mti_env, next);
1672 static int mdt_sync(struct mdt_thread_info *info)
1674 struct req_capsule *pill = info->mti_pill;
1675 struct mdt_body *body;
1679 /* The fid may be zero, so we req_capsule_set manually */
1680 req_capsule_set(pill, &RQF_MDS_SYNC);
1682 body = req_capsule_client_get(pill, &RMF_MDT_BODY);
1684 RETURN(err_serious(-EINVAL));
1686 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_SYNC_PACK))
1687 RETURN(err_serious(-ENOMEM));
1689 if (fid_seq(&body->fid1) == 0) {
1690 /* sync the whole device */
1691 rc = req_capsule_server_pack(pill);
1693 rc = mdt_device_sync(info->mti_env, info->mti_mdt);
1695 rc = err_serious(rc);
1697 /* sync an object */
1698 rc = mdt_unpack_req_pack_rep(info, HABEO_CORPUS|HABEO_REFERO);
1700 rc = mdt_object_sync(info);
1702 struct md_object *next;
1703 const struct lu_fid *fid;
1704 struct lu_attr *la = &info->mti_attr.ma_attr;
1706 next = mdt_object_child(info->mti_object);
1707 info->mti_attr.ma_need = MA_INODE;
1708 info->mti_attr.ma_valid = 0;
1709 rc = mo_attr_get(info->mti_env, next,
1712 body = req_capsule_server_get(pill,
1714 fid = mdt_object_fid(info->mti_object);
1715 mdt_pack_attr2body(info, body, la, fid);
1719 rc = err_serious(rc);
1724 #ifdef HAVE_QUOTA_SUPPORT
1725 static int mdt_quotacheck_handle(struct mdt_thread_info *info)
1727 struct obd_quotactl *oqctl;
1728 struct req_capsule *pill = info->mti_pill;
1729 struct obd_export *exp = info->mti_exp;
1730 struct md_quota *mq = md_quota(info->mti_env);
1731 struct md_device *next = info->mti_mdt->mdt_child;
1735 oqctl = req_capsule_client_get(pill, &RMF_OBD_QUOTACTL);
1739 /* remote client has no permission for quotacheck */
1740 if (unlikely(exp_connect_rmtclient(exp)))
1743 rc = req_capsule_server_pack(pill);
1748 rc = next->md_ops->mdo_quota.mqo_check(info->mti_env, next,
1753 static int mdt_quotactl_handle(struct mdt_thread_info *info)
1755 struct obd_quotactl *oqctl, *repoqc;
1756 struct req_capsule *pill = info->mti_pill;
1757 struct obd_export *exp = info->mti_exp;
1758 struct md_quota *mq = md_quota(info->mti_env);
1759 struct md_device *next = info->mti_mdt->mdt_child;
1760 const struct md_quota_operations *mqo = &next->md_ops->mdo_quota;
1764 oqctl = req_capsule_client_get(pill, &RMF_OBD_QUOTACTL);
1769 if (exp_connect_rmtclient(exp)) {
1770 struct ptlrpc_request *req = mdt_info_req(info);
1771 struct mdt_export_data *med = mdt_req2med(req);
1772 struct lustre_idmap_table *idmap = med->med_idmap;
1774 if (unlikely(oqctl->qc_cmd != Q_GETQUOTA &&
1775 oqctl->qc_cmd != Q_GETINFO))
1779 if (oqctl->qc_type == USRQUOTA)
1780 id = lustre_idmap_lookup_uid(NULL, idmap, 0,
1782 else if (oqctl->qc_type == GRPQUOTA)
1783 id = lustre_idmap_lookup_gid(NULL, idmap, 0,
1788 if (id == CFS_IDMAP_NOTFOUND) {
1789 CDEBUG(D_QUOTA, "no mapping for id %u\n",
1795 rc = req_capsule_server_pack(pill);
1799 repoqc = req_capsule_server_get(pill, &RMF_OBD_QUOTACTL);
1800 LASSERT(repoqc != NULL);
1803 switch (oqctl->qc_cmd) {
1805 rc = mqo->mqo_on(info->mti_env, next, oqctl->qc_type);
1808 rc = mqo->mqo_off(info->mti_env, next, oqctl->qc_type);
1811 rc = mqo->mqo_setinfo(info->mti_env, next, oqctl->qc_type, id,
1815 rc = mqo->mqo_getinfo(info->mti_env, next, oqctl->qc_type, id,
1819 rc = mqo->mqo_setquota(info->mti_env, next, oqctl->qc_type, id,
1823 rc = mqo->mqo_getquota(info->mti_env, next, oqctl->qc_type, id,
1827 rc = mqo->mqo_getoinfo(info->mti_env, next, oqctl->qc_type, id,
1831 rc = mqo->mqo_getoquota(info->mti_env, next, oqctl->qc_type, id,
1834 case LUSTRE_Q_INVALIDATE:
1835 rc = mqo->mqo_invalidate(info->mti_env, next, oqctl->qc_type);
1837 case LUSTRE_Q_FINVALIDATE:
1838 rc = mqo->mqo_finvalidate(info->mti_env, next, oqctl->qc_type);
1841 CERROR("unsupported mdt_quotactl command: %d\n",
1853 * OBD PING and other handlers.
1855 static int mdt_obd_ping(struct mdt_thread_info *info)
1860 req_capsule_set(info->mti_pill, &RQF_OBD_PING);
1862 rc = target_handle_ping(mdt_info_req(info));
1864 rc = err_serious(rc);
1868 static int mdt_obd_log_cancel(struct mdt_thread_info *info)
1870 return err_serious(-EOPNOTSUPP);
1873 static int mdt_obd_qc_callback(struct mdt_thread_info *info)
1875 return err_serious(-EOPNOTSUPP);
1883 /** clone llog ctxt from child (mdd)
1884 * This allows remote llog (replicator) access.
1885 * We can either pass all llog RPCs (eg mdt_llog_create) on to child where the
1886 * context was originally set up, or we can handle them directly.
1887 * I choose the latter, but that means I need any llog
1888 * contexts set up by child to be accessable by the mdt. So we clone the
1889 * context into our context list here.
1891 static int mdt_llog_ctxt_clone(const struct lu_env *env, struct mdt_device *mdt,
1894 struct md_device *next = mdt->mdt_child;
1895 struct llog_ctxt *ctxt;
1898 if (!llog_ctxt_null(mdt2obd_dev(mdt), idx))
1901 rc = next->md_ops->mdo_llog_ctxt_get(env, next, idx, (void **)&ctxt);
1902 if (rc || ctxt == NULL) {
1903 CERROR("Can't get mdd ctxt %d\n", rc);
1907 rc = llog_group_set_ctxt(&mdt2obd_dev(mdt)->obd_olg, ctxt, idx);
1909 CERROR("Can't set mdt ctxt %d\n", rc);
1914 static int mdt_llog_ctxt_unclone(const struct lu_env *env,
1915 struct mdt_device *mdt, int idx)
1917 struct llog_ctxt *ctxt;
1919 ctxt = llog_get_context(mdt2obd_dev(mdt), idx);
1922 /* Put once for the get we just did, and once for the clone */
1923 llog_ctxt_put(ctxt);
1924 llog_ctxt_put(ctxt);
1928 static int mdt_llog_create(struct mdt_thread_info *info)
1932 req_capsule_set(info->mti_pill, &RQF_LLOG_ORIGIN_HANDLE_CREATE);
1933 rc = llog_origin_handle_create(mdt_info_req(info));
1934 return (rc < 0 ? err_serious(rc) : rc);
1937 static int mdt_llog_destroy(struct mdt_thread_info *info)
1941 req_capsule_set(info->mti_pill, &RQF_LLOG_ORIGIN_HANDLE_DESTROY);
1942 rc = llog_origin_handle_destroy(mdt_info_req(info));
1943 return (rc < 0 ? err_serious(rc) : rc);
1946 static int mdt_llog_read_header(struct mdt_thread_info *info)
1950 req_capsule_set(info->mti_pill, &RQF_LLOG_ORIGIN_HANDLE_READ_HEADER);
1951 rc = llog_origin_handle_read_header(mdt_info_req(info));
1952 return (rc < 0 ? err_serious(rc) : rc);
1955 static int mdt_llog_next_block(struct mdt_thread_info *info)
1959 req_capsule_set(info->mti_pill, &RQF_LLOG_ORIGIN_HANDLE_NEXT_BLOCK);
1960 rc = llog_origin_handle_next_block(mdt_info_req(info));
1961 return (rc < 0 ? err_serious(rc) : rc);
1964 static int mdt_llog_prev_block(struct mdt_thread_info *info)
1968 req_capsule_set(info->mti_pill, &RQF_LLOG_ORIGIN_HANDLE_PREV_BLOCK);
1969 rc = llog_origin_handle_prev_block(mdt_info_req(info));
1970 return (rc < 0 ? err_serious(rc) : rc);
1977 static struct ldlm_callback_suite cbs = {
1978 .lcs_completion = ldlm_server_completion_ast,
1979 .lcs_blocking = ldlm_server_blocking_ast,
1983 static int mdt_enqueue(struct mdt_thread_info *info)
1985 struct ptlrpc_request *req;
1989 * info->mti_dlm_req already contains swapped and (if necessary)
1990 * converted dlm request.
1992 LASSERT(info->mti_dlm_req != NULL);
1994 req = mdt_info_req(info);
1995 rc = ldlm_handle_enqueue0(info->mti_mdt->mdt_namespace,
1996 req, info->mti_dlm_req, &cbs);
1997 info->mti_fail_id = OBD_FAIL_LDLM_REPLY;
1998 return rc ? err_serious(rc) : req->rq_status;
2001 static int mdt_convert(struct mdt_thread_info *info)
2004 struct ptlrpc_request *req;
2006 LASSERT(info->mti_dlm_req);
2007 req = mdt_info_req(info);
2008 rc = ldlm_handle_convert0(req, info->mti_dlm_req);
2009 return rc ? err_serious(rc) : req->rq_status;
2012 static int mdt_bl_callback(struct mdt_thread_info *info)
2014 CERROR("bl callbacks should not happen on MDS\n");
2016 return err_serious(-EOPNOTSUPP);
2019 static int mdt_cp_callback(struct mdt_thread_info *info)
2021 CERROR("cp callbacks should not happen on MDS\n");
2023 return err_serious(-EOPNOTSUPP);
2027 * sec context handlers
2029 static int mdt_sec_ctx_handle(struct mdt_thread_info *info)
2033 rc = mdt_handle_idmap(info);
2036 struct ptlrpc_request *req = mdt_info_req(info);
2039 opc = lustre_msg_get_opc(req->rq_reqmsg);
2040 if (opc == SEC_CTX_INIT || opc == SEC_CTX_INIT_CONT)
2041 sptlrpc_svc_ctx_invalidate(req);
2044 OBD_FAIL_TIMEOUT(OBD_FAIL_SEC_CTX_HDL_PAUSE, obd_fail_val);
2049 static struct mdt_object *mdt_obj(struct lu_object *o)
2051 LASSERT(lu_device_is_mdt(o->lo_dev));
2052 return container_of0(o, struct mdt_object, mot_obj.mo_lu);
2055 struct mdt_object *mdt_object_find(const struct lu_env *env,
2056 struct mdt_device *d,
2057 const struct lu_fid *f)
2059 struct lu_object *o;
2060 struct mdt_object *m;
2063 CDEBUG(D_INFO, "Find object for "DFID"\n", PFID(f));
2064 o = lu_object_find(env, &d->mdt_md_dev.md_lu_dev, f, NULL);
2065 if (unlikely(IS_ERR(o)))
2066 m = (struct mdt_object *)o;
2073 * Asyncronous commit for mdt device.
2075 * Pass asynchonous commit call down the MDS stack.
2077 * \param env environment
2078 * \param mdt the mdt device
2080 static void mdt_device_commit_async(const struct lu_env *env,
2081 struct mdt_device *mdt)
2083 struct dt_device *dt = mdt->mdt_bottom;
2086 rc = dt->dd_ops->dt_commit_async(env, dt);
2087 if (unlikely(rc != 0))
2088 CWARN("async commit start failed with rc = %d", rc);
2092 * Mark the lock as "synchonous".
2094 * Mark the lock to deffer transaction commit to the unlock time.
2096 * \param lock the lock to mark as "synchonous"
2098 * \see mdt_is_lock_sync
2099 * \see mdt_save_lock
2101 static inline void mdt_set_lock_sync(struct ldlm_lock *lock)
2103 lock->l_ast_data = (void*)1;
2107 * Check whehter the lock "synchonous" or not.
2109 * \param lock the lock to check
2110 * \retval 1 the lock is "synchonous"
2111 * \retval 0 the lock isn't "synchronous"
2113 * \see mdt_set_lock_sync
2114 * \see mdt_save_lock
2116 static inline int mdt_is_lock_sync(struct ldlm_lock *lock)
2118 return lock->l_ast_data != NULL;
2122 * Blocking AST for mdt locks.
2124 * Starts transaction commit if in case of COS lock conflict or
2125 * deffers such a commit to the mdt_save_lock.
2127 * \param lock the lock which blocks a request or cancelling lock
2128 * \param desc unused
2129 * \param data unused
2130 * \param flag indicates whether this cancelling or blocking callback
2132 * \see ldlm_blocking_ast_nocheck
2134 int mdt_blocking_ast(struct ldlm_lock *lock, struct ldlm_lock_desc *desc,
2135 void *data, int flag)
2137 struct obd_device *obd = lock->l_resource->lr_namespace->ns_obd;
2138 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
2142 if (flag == LDLM_CB_CANCELING)
2144 lock_res_and_lock(lock);
2145 if (lock->l_blocking_ast != mdt_blocking_ast) {
2146 unlock_res_and_lock(lock);
2149 if (mdt_cos_is_enabled(mdt) &&
2150 lock->l_req_mode & (LCK_PW | LCK_EX) &&
2151 lock->l_blocking_lock != NULL &&
2152 lock->l_client_cookie != lock->l_blocking_lock->l_client_cookie) {
2153 mdt_set_lock_sync(lock);
2155 rc = ldlm_blocking_ast_nocheck(lock);
2157 /* There is no lock conflict if l_blocking_lock == NULL,
2158 * it indicates a blocking ast sent from ldlm_lock_decref_internal
2159 * when the last reference to a local lock was released */
2160 if (lock->l_req_mode == LCK_COS && lock->l_blocking_lock != NULL) {
2163 rc = lu_env_init(&env, LCT_MD_THREAD);
2164 if (unlikely(rc != 0))
2165 CWARN("lu_env initialization failed with rc = %d,"
2166 "cannot start asynchronous commit\n", rc);
2168 mdt_device_commit_async(&env, mdt);
2174 int mdt_object_lock(struct mdt_thread_info *info, struct mdt_object *o,
2175 struct mdt_lock_handle *lh, __u64 ibits, int locality)
2177 struct ldlm_namespace *ns = info->mti_mdt->mdt_namespace;
2178 ldlm_policy_data_t *policy = &info->mti_policy;
2179 struct ldlm_res_id *res_id = &info->mti_res_id;
2183 LASSERT(!lustre_handle_is_used(&lh->mlh_reg_lh));
2184 LASSERT(!lustre_handle_is_used(&lh->mlh_pdo_lh));
2185 LASSERT(lh->mlh_reg_mode != LCK_MINMODE);
2186 LASSERT(lh->mlh_type != MDT_NUL_LOCK);
2188 if (mdt_object_exists(o) < 0) {
2189 if (locality == MDT_CROSS_LOCK) {
2190 /* cross-ref object fix */
2191 ibits &= ~MDS_INODELOCK_UPDATE;
2192 ibits |= MDS_INODELOCK_LOOKUP;
2194 LASSERT(!(ibits & MDS_INODELOCK_UPDATE));
2195 LASSERT(ibits & MDS_INODELOCK_LOOKUP);
2197 /* No PDO lock on remote object */
2198 LASSERT(lh->mlh_type != MDT_PDO_LOCK);
2201 if (lh->mlh_type == MDT_PDO_LOCK) {
2202 /* check for exists after object is locked */
2203 if (mdt_object_exists(o) == 0) {
2204 /* Non-existent object shouldn't have PDO lock */
2207 /* Non-dir object shouldn't have PDO lock */
2208 LASSERT(S_ISDIR(lu_object_attr(&o->mot_obj.mo_lu)));
2212 memset(policy, 0, sizeof(*policy));
2213 fid_build_reg_res_name(mdt_object_fid(o), res_id);
2216 * Take PDO lock on whole directory and build correct @res_id for lock
2217 * on part of directory.
2219 if (lh->mlh_pdo_hash != 0) {
2220 LASSERT(lh->mlh_type == MDT_PDO_LOCK);
2221 mdt_lock_pdo_mode(info, o, lh);
2222 if (lh->mlh_pdo_mode != LCK_NL) {
2224 * Do not use LDLM_FL_LOCAL_ONLY for parallel lock, it
2225 * is never going to be sent to client and we do not
2226 * want it slowed down due to possible cancels.
2228 policy->l_inodebits.bits = MDS_INODELOCK_UPDATE;
2229 rc = mdt_fid_lock(ns, &lh->mlh_pdo_lh, lh->mlh_pdo_mode,
2230 policy, res_id, LDLM_FL_ATOMIC_CB,
2231 &info->mti_exp->exp_handle.h_cookie);
2237 * Finish res_id initializing by name hash marking part of
2238 * directory which is taking modification.
2240 res_id->name[LUSTRE_RES_ID_HSH_OFF] = lh->mlh_pdo_hash;
2243 policy->l_inodebits.bits = ibits;
2246 * Use LDLM_FL_LOCAL_ONLY for this lock. We do not know yet if it is
2247 * going to be sent to client. If it is - mdt_intent_policy() path will
2248 * fix it up and turn FL_LOCAL flag off.
2250 rc = mdt_fid_lock(ns, &lh->mlh_reg_lh, lh->mlh_reg_mode, policy,
2251 res_id, LDLM_FL_LOCAL_ONLY | LDLM_FL_ATOMIC_CB,
2252 &info->mti_exp->exp_handle.h_cookie);
2254 mdt_object_unlock(info, o, lh, 1);
2255 else if (unlikely(OBD_FAIL_PRECHECK(OBD_FAIL_MDS_PDO_LOCK)) &&
2256 lh->mlh_pdo_hash != 0 &&
2257 (lh->mlh_reg_mode == LCK_PW || lh->mlh_reg_mode == LCK_EX)) {
2258 OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_PDO_LOCK, 10);
2265 * Save a lock within request object.
2267 * Keep the lock referenced until whether client ACK or transaction
2268 * commit happens or release the lock immediately depending on input
2269 * parameters. If COS is ON, a write lock is converted to COS lock
2272 * \param info thead info object
2273 * \param h lock handle
2274 * \param mode lock mode
2275 * \param decref force immediate lock releasing
2278 void mdt_save_lock(struct mdt_thread_info *info, struct lustre_handle *h,
2279 ldlm_mode_t mode, int decref)
2283 if (lustre_handle_is_used(h)) {
2284 if (decref || !info->mti_has_trans ||
2285 !(mode & (LCK_PW | LCK_EX))){
2286 mdt_fid_unlock(h, mode);
2288 struct mdt_device *mdt = info->mti_mdt;
2289 struct ldlm_lock *lock = ldlm_handle2lock(h);
2290 struct ptlrpc_request *req = mdt_info_req(info);
2293 LASSERTF(lock != NULL, "no lock for cookie "LPX64"\n",
2295 CDEBUG(D_HA, "request = %p reply state = %p"
2296 " transno = "LPD64"\n",
2297 req, req->rq_reply_state, req->rq_transno);
2298 if (mdt_cos_is_enabled(mdt)) {
2300 ldlm_lock_downgrade(lock, LCK_COS);
2303 ptlrpc_save_lock(req, h, mode, no_ack);
2304 if (mdt_is_lock_sync(lock)) {
2305 CDEBUG(D_HA, "found sync-lock,"
2306 " async commit started\n");
2307 mdt_device_commit_async(info->mti_env,
2310 LDLM_LOCK_PUT(lock);
2319 * Unlock mdt object.
2321 * Immeditely release the regular lock and the PDO lock or save the
2322 * lock in reqeuest and keep them referenced until client ACK or
2323 * transaction commit.
2325 * \param info thread info object
2326 * \param o mdt object
2327 * \param lh mdt lock handle referencing regular and PDO locks
2328 * \param decref force immediate lock releasing
2330 void mdt_object_unlock(struct mdt_thread_info *info, struct mdt_object *o,
2331 struct mdt_lock_handle *lh, int decref)
2335 mdt_save_lock(info, &lh->mlh_pdo_lh, lh->mlh_pdo_mode, decref);
2336 mdt_save_lock(info, &lh->mlh_reg_lh, lh->mlh_reg_mode, decref);
2341 struct mdt_object *mdt_object_find_lock(struct mdt_thread_info *info,
2342 const struct lu_fid *f,
2343 struct mdt_lock_handle *lh,
2346 struct mdt_object *o;
2348 o = mdt_object_find(info->mti_env, info->mti_mdt, f);
2352 rc = mdt_object_lock(info, o, lh, ibits,
2355 mdt_object_put(info->mti_env, o);
2362 void mdt_object_unlock_put(struct mdt_thread_info * info,
2363 struct mdt_object * o,
2364 struct mdt_lock_handle *lh,
2367 mdt_object_unlock(info, o, lh, decref);
2368 mdt_object_put(info->mti_env, o);
2371 static struct mdt_handler *mdt_handler_find(__u32 opc,
2372 struct mdt_opc_slice *supported)
2374 struct mdt_opc_slice *s;
2375 struct mdt_handler *h;
2378 for (s = supported; s->mos_hs != NULL; s++) {
2379 if (s->mos_opc_start <= opc && opc < s->mos_opc_end) {
2380 h = s->mos_hs + (opc - s->mos_opc_start);
2381 if (likely(h->mh_opc != 0))
2382 LASSERTF(h->mh_opc == opc,
2383 "opcode mismatch %d != %d\n",
2386 h = NULL; /* unsupported opc */
2393 static int mdt_lock_resname_compat(struct mdt_device *m,
2394 struct ldlm_request *req)
2396 /* XXX something... later. */
2400 static int mdt_lock_reply_compat(struct mdt_device *m, struct ldlm_reply *rep)
2402 /* XXX something... later. */
2407 * Generic code handling requests that have struct mdt_body passed in:
2409 * - extract mdt_body from request and save it in @info, if present;
2411 * - create lu_object, corresponding to the fid in mdt_body, and save it in
2414 * - if HABEO_CORPUS flag is set for this request type check whether object
2415 * actually exists on storage (lu_object_exists()).
2418 static int mdt_body_unpack(struct mdt_thread_info *info, __u32 flags)
2420 const struct mdt_body *body;
2421 struct mdt_object *obj;
2422 const struct lu_env *env;
2423 struct req_capsule *pill;
2427 env = info->mti_env;
2428 pill = info->mti_pill;
2430 body = info->mti_body = req_capsule_client_get(pill, &RMF_MDT_BODY);
2434 if (!(body->valid & OBD_MD_FLID))
2437 if (!fid_is_sane(&body->fid1)) {
2438 CERROR("Invalid fid: "DFID"\n", PFID(&body->fid1));
2443 * Do not get size or any capa fields before we check that request
2444 * contains capa actually. There are some requests which do not, for
2445 * instance MDS_IS_SUBDIR.
2447 if (req_capsule_has_field(pill, &RMF_CAPA1, RCL_CLIENT) &&
2448 req_capsule_get_size(pill, &RMF_CAPA1, RCL_CLIENT))
2449 mdt_set_capainfo(info, 0, &body->fid1,
2450 req_capsule_client_get(pill, &RMF_CAPA1));
2452 obj = mdt_object_find(env, info->mti_mdt, &body->fid1);
2454 if ((flags & HABEO_CORPUS) &&
2455 !mdt_object_exists(obj)) {
2456 mdt_object_put(env, obj);
2457 /* for capability renew ENOENT will be handled in
2459 if (body->valid & OBD_MD_FLOSSCAPA)
2464 info->mti_object = obj;
2473 static int mdt_unpack_req_pack_rep(struct mdt_thread_info *info, __u32 flags)
2475 struct req_capsule *pill = info->mti_pill;
2479 if (req_capsule_has_field(pill, &RMF_MDT_BODY, RCL_CLIENT))
2480 rc = mdt_body_unpack(info, flags);
2484 if (rc == 0 && (flags & HABEO_REFERO)) {
2485 struct mdt_device *mdt = info->mti_mdt;
2489 if (req_capsule_has_field(pill, &RMF_MDT_MD, RCL_SERVER))
2490 req_capsule_set_size(pill, &RMF_MDT_MD, RCL_SERVER,
2491 mdt->mdt_max_mdsize);
2492 if (req_capsule_has_field(pill, &RMF_LOGCOOKIES, RCL_SERVER))
2493 req_capsule_set_size(pill, &RMF_LOGCOOKIES, RCL_SERVER,
2494 mdt->mdt_max_cookiesize);
2496 rc = req_capsule_server_pack(pill);
2501 static int mdt_init_capa_ctxt(const struct lu_env *env, struct mdt_device *m)
2503 struct md_device *next = m->mdt_child;
2505 return next->md_ops->mdo_init_capa_ctxt(env, next,
2506 m->mdt_opts.mo_mds_capa,
2507 m->mdt_capa_timeout,
2513 * Invoke handler for this request opc. Also do necessary preprocessing
2514 * (according to handler ->mh_flags), and post-processing (setting of
2515 * ->last_{xid,committed}).
2517 static int mdt_req_handle(struct mdt_thread_info *info,
2518 struct mdt_handler *h, struct ptlrpc_request *req)
2520 int rc, serious = 0;
2525 LASSERT(h->mh_act != NULL);
2526 LASSERT(h->mh_opc == lustre_msg_get_opc(req->rq_reqmsg));
2527 LASSERT(current->journal_info == NULL);
2530 * Checking for various OBD_FAIL_$PREF_$OPC_NET codes. _Do_ not try
2531 * to put same checks into handlers like mdt_close(), mdt_reint(),
2532 * etc., without talking to mdt authors first. Checking same thing
2533 * there again is useless and returning 0 error without packing reply
2534 * is buggy! Handlers either pack reply or return error.
2536 * We return 0 here and do not send any reply in order to emulate
2537 * network failure. Do not send any reply in case any of NET related
2538 * fail_id has occured.
2540 if (OBD_FAIL_CHECK_ORSET(h->mh_fail_id, OBD_FAIL_ONCE))
2544 flags = h->mh_flags;
2545 LASSERT(ergo(flags & (HABEO_CORPUS|HABEO_REFERO), h->mh_fmt != NULL));
2547 if (h->mh_fmt != NULL) {
2548 req_capsule_set(info->mti_pill, h->mh_fmt);
2549 rc = mdt_unpack_req_pack_rep(info, flags);
2552 if (rc == 0 && flags & MUTABOR &&
2553 req->rq_export->exp_connect_flags & OBD_CONNECT_RDONLY)
2554 /* should it be rq_status? */
2557 if (rc == 0 && flags & HABEO_CLAVIS) {
2558 struct ldlm_request *dlm_req;
2560 LASSERT(h->mh_fmt != NULL);
2562 dlm_req = req_capsule_client_get(info->mti_pill, &RMF_DLM_REQ);
2563 if (dlm_req != NULL) {
2564 if (unlikely(dlm_req->lock_desc.l_resource.lr_type ==
2566 dlm_req->lock_desc.l_policy_data.\
2567 l_inodebits.bits == 0)) {
2569 * Lock without inodebits makes no sense and
2570 * will oops later in ldlm. If client miss to
2571 * set such bits, do not trigger ASSERTION.
2573 * For liblustre flock case, it maybe zero.
2577 if (info->mti_mdt->mdt_opts.mo_compat_resname)
2578 rc = mdt_lock_resname_compat(
2581 info->mti_dlm_req = dlm_req;
2588 /* capability setting changed via /proc, needs reinitialize ctxt */
2589 if (info->mti_mdt && info->mti_mdt->mdt_capa_conf) {
2590 mdt_init_capa_ctxt(info->mti_env, info->mti_mdt);
2591 info->mti_mdt->mdt_capa_conf = 0;
2594 if (likely(rc == 0)) {
2596 * Process request, there can be two types of rc:
2597 * 1) errors with msg unpack/pack, other failures outside the
2598 * operation itself. This is counted as serious errors;
2599 * 2) errors during fs operation, should be placed in rq_status
2602 rc = h->mh_act(info);
2604 !req->rq_no_reply && req->rq_reply_state == NULL) {
2605 DEBUG_REQ(D_ERROR, req, "MDT \"handler\" %s did not "
2606 "pack reply and returned 0 error\n",
2610 serious = is_serious(rc);
2611 rc = clear_serious(rc);
2615 req->rq_status = rc;
2618 * ELDLM_* codes which > 0 should be in rq_status only as well as
2619 * all non-serious errors.
2621 if (rc > 0 || !serious)
2624 LASSERT(current->journal_info == NULL);
2626 if (rc == 0 && (flags & HABEO_CLAVIS) &&
2627 info->mti_mdt->mdt_opts.mo_compat_resname) {
2628 struct ldlm_reply *dlmrep;
2630 dlmrep = req_capsule_server_get(info->mti_pill, &RMF_DLM_REP);
2632 rc = mdt_lock_reply_compat(info->mti_mdt, dlmrep);
2635 /* If we're DISCONNECTing, the mdt_export_data is already freed */
2636 if (likely(rc == 0 && req->rq_export && h->mh_opc != MDS_DISCONNECT))
2637 target_committed_to_req(req);
2639 if (unlikely(req_is_replay(req) &&
2640 lustre_msg_get_transno(req->rq_reqmsg) == 0)) {
2641 DEBUG_REQ(D_ERROR, req, "transno is 0 during REPLAY");
2645 target_send_reply(req, rc, info->mti_fail_id);
2649 void mdt_lock_handle_init(struct mdt_lock_handle *lh)
2651 lh->mlh_type = MDT_NUL_LOCK;
2652 lh->mlh_reg_lh.cookie = 0ull;
2653 lh->mlh_reg_mode = LCK_MINMODE;
2654 lh->mlh_pdo_lh.cookie = 0ull;
2655 lh->mlh_pdo_mode = LCK_MINMODE;
2658 void mdt_lock_handle_fini(struct mdt_lock_handle *lh)
2660 LASSERT(!lustre_handle_is_used(&lh->mlh_reg_lh));
2661 LASSERT(!lustre_handle_is_used(&lh->mlh_pdo_lh));
2665 * Initialize fields of struct mdt_thread_info. Other fields are left in
2666 * uninitialized state, because it's too expensive to zero out whole
2667 * mdt_thread_info (> 1K) on each request arrival.
2669 static void mdt_thread_info_init(struct ptlrpc_request *req,
2670 struct mdt_thread_info *info)
2673 struct md_capainfo *ci;
2675 req_capsule_init(&req->rq_pill, req, RCL_SERVER);
2676 info->mti_pill = &req->rq_pill;
2679 for (i = 0; i < ARRAY_SIZE(info->mti_lh); i++)
2680 mdt_lock_handle_init(&info->mti_lh[i]);
2682 /* mdt device: it can be NULL while CONNECT */
2683 if (req->rq_export) {
2684 info->mti_mdt = mdt_dev(req->rq_export->exp_obd->obd_lu_dev);
2685 info->mti_exp = req->rq_export;
2687 info->mti_mdt = NULL;
2688 info->mti_env = req->rq_svc_thread->t_env;
2689 ci = md_capainfo(info->mti_env);
2690 memset(ci, 0, sizeof *ci);
2691 if (req->rq_export) {
2692 if (exp_connect_rmtclient(req->rq_export))
2693 ci->mc_auth = LC_ID_CONVERT;
2694 else if (req->rq_export->exp_connect_flags &
2695 OBD_CONNECT_MDS_CAPA)
2696 ci->mc_auth = LC_ID_PLAIN;
2698 ci->mc_auth = LC_ID_NONE;
2701 info->mti_fail_id = OBD_FAIL_MDS_ALL_REPLY_NET;
2702 info->mti_transno = lustre_msg_get_transno(req->rq_reqmsg);
2703 info->mti_mos = NULL;
2705 memset(&info->mti_attr, 0, sizeof(info->mti_attr));
2706 info->mti_body = NULL;
2707 info->mti_object = NULL;
2708 info->mti_dlm_req = NULL;
2709 info->mti_has_trans = 0;
2710 info->mti_no_need_trans = 0;
2711 info->mti_cross_ref = 0;
2712 info->mti_opdata = 0;
2714 /* To not check for split by default. */
2715 info->mti_spec.sp_ck_split = 0;
2716 info->mti_spec.no_create = 0;
2719 static void mdt_thread_info_fini(struct mdt_thread_info *info)
2723 req_capsule_fini(info->mti_pill);
2724 if (info->mti_object != NULL) {
2726 * freeing an object may lead to OSD level transaction, do not
2727 * let it mess with MDT. bz19385.
2729 info->mti_no_need_trans = 1;
2730 mdt_object_put(info->mti_env, info->mti_object);
2731 info->mti_object = NULL;
2733 for (i = 0; i < ARRAY_SIZE(info->mti_lh); i++)
2734 mdt_lock_handle_fini(&info->mti_lh[i]);
2735 info->mti_env = NULL;
2738 static int mdt_filter_recovery_request(struct ptlrpc_request *req,
2739 struct obd_device *obd, int *process)
2741 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
2742 case MDS_CONNECT: /* This will never get here, but for completeness. */
2743 case OST_CONNECT: /* This will never get here, but for completeness. */
2744 case MDS_DISCONNECT:
2745 case OST_DISCONNECT:
2750 case MDS_DONE_WRITING:
2751 case MDS_SYNC: /* used in unmounting */
2757 *process = target_queue_recovery_request(req, obd);
2761 DEBUG_REQ(D_ERROR, req, "not permitted during recovery");
2768 * Handle recovery. Return:
2769 * +1: continue request processing;
2770 * -ve: abort immediately with the given error code;
2771 * 0: send reply with error code in req->rq_status;
2773 static int mdt_recovery(struct mdt_thread_info *info)
2775 struct ptlrpc_request *req = mdt_info_req(info);
2776 struct obd_device *obd;
2780 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
2783 case SEC_CTX_INIT_CONT:
2789 rc = mdt_handle_idmap(info);
2798 if (unlikely(!class_connected_export(req->rq_export))) {
2799 CERROR("operation %d on unconnected MDS from %s\n",
2800 lustre_msg_get_opc(req->rq_reqmsg),
2801 libcfs_id2str(req->rq_peer));
2802 /* FIXME: For CMD cleanup, when mds_B stop, the req from
2803 * mds_A will get -ENOTCONN(especially for ping req),
2804 * which will cause that mds_A deactive timeout, then when
2805 * mds_A cleanup, the cleanup process will be suspended since
2806 * deactive timeout is not zero.
2808 req->rq_status = -ENOTCONN;
2809 target_send_reply(req, -ENOTCONN, info->mti_fail_id);
2813 /* sanity check: if the xid matches, the request must be marked as a
2814 * resent or replayed */
2815 if (req_xid_is_last(req)) {
2816 if (!(lustre_msg_get_flags(req->rq_reqmsg) &
2817 (MSG_RESENT | MSG_REPLAY))) {
2818 DEBUG_REQ(D_WARNING, req, "rq_xid "LPU64" matches last_xid, "
2819 "expected REPLAY or RESENT flag (%x)", req->rq_xid,
2820 lustre_msg_get_flags(req->rq_reqmsg));
2822 req->rq_status = -ENOTCONN;
2827 /* else: note the opposite is not always true; a RESENT req after a
2828 * failover will usually not match the last_xid, since it was likely
2829 * never committed. A REPLAYed request will almost never match the
2830 * last xid, however it could for a committed, but still retained,
2833 obd = req->rq_export->exp_obd;
2835 /* Check for aborted recovery... */
2836 if (unlikely(obd->obd_recovering)) {
2839 DEBUG_REQ(D_INFO, req, "Got new replay");
2840 rc = mdt_filter_recovery_request(req, obd, &should_process);
2841 if (rc != 0 || !should_process)
2843 else if (should_process < 0) {
2844 req->rq_status = should_process;
2845 rc = ptlrpc_error(req);
2852 static int mdt_msg_check_version(struct lustre_msg *msg)
2856 switch (lustre_msg_get_opc(msg)) {
2858 case MDS_DISCONNECT:
2861 case SEC_CTX_INIT_CONT:
2863 rc = lustre_msg_check_version(msg, LUSTRE_OBD_VERSION);
2865 CERROR("bad opc %u version %08x, expecting %08x\n",
2866 lustre_msg_get_opc(msg),
2867 lustre_msg_get_version(msg),
2868 LUSTRE_OBD_VERSION);
2872 case MDS_GETATTR_NAME:
2879 case MDS_DONE_WRITING:
2886 case MDS_QUOTACHECK:
2892 rc = lustre_msg_check_version(msg, LUSTRE_MDS_VERSION);
2894 CERROR("bad opc %u version %08x, expecting %08x\n",
2895 lustre_msg_get_opc(msg),
2896 lustre_msg_get_version(msg),
2897 LUSTRE_MDS_VERSION);
2901 case LDLM_BL_CALLBACK:
2902 case LDLM_CP_CALLBACK:
2903 rc = lustre_msg_check_version(msg, LUSTRE_DLM_VERSION);
2905 CERROR("bad opc %u version %08x, expecting %08x\n",
2906 lustre_msg_get_opc(msg),
2907 lustre_msg_get_version(msg),
2908 LUSTRE_DLM_VERSION);
2910 case OBD_LOG_CANCEL:
2911 case LLOG_ORIGIN_HANDLE_CREATE:
2912 case LLOG_ORIGIN_HANDLE_NEXT_BLOCK:
2913 case LLOG_ORIGIN_HANDLE_READ_HEADER:
2914 case LLOG_ORIGIN_HANDLE_CLOSE:
2915 case LLOG_ORIGIN_HANDLE_DESTROY:
2916 case LLOG_ORIGIN_HANDLE_PREV_BLOCK:
2918 rc = lustre_msg_check_version(msg, LUSTRE_LOG_VERSION);
2920 CERROR("bad opc %u version %08x, expecting %08x\n",
2921 lustre_msg_get_opc(msg),
2922 lustre_msg_get_version(msg),
2923 LUSTRE_LOG_VERSION);
2926 CERROR("MDS unknown opcode %d\n", lustre_msg_get_opc(msg));
2932 static int mdt_handle0(struct ptlrpc_request *req,
2933 struct mdt_thread_info *info,
2934 struct mdt_opc_slice *supported)
2936 struct mdt_handler *h;
2937 struct lustre_msg *msg;
2942 if (OBD_FAIL_CHECK_ORSET(OBD_FAIL_MDS_ALL_REQUEST_NET, OBD_FAIL_ONCE))
2945 LASSERT(current->journal_info == NULL);
2947 msg = req->rq_reqmsg;
2948 rc = mdt_msg_check_version(msg);
2949 if (likely(rc == 0)) {
2950 rc = mdt_recovery(info);
2951 if (likely(rc == +1)) {
2952 h = mdt_handler_find(lustre_msg_get_opc(msg),
2954 if (likely(h != NULL)) {
2955 rc = mdt_req_handle(info, h, req);
2957 CERROR("The unsupported opc: 0x%x\n",
2958 lustre_msg_get_opc(msg) );
2959 req->rq_status = -ENOTSUPP;
2960 rc = ptlrpc_error(req);
2965 CERROR(LUSTRE_MDT_NAME" drops mal-formed request\n");
2970 * MDT handler function called by ptlrpc service thread when request comes.
2972 * XXX common "target" functionality should be factored into separate module
2973 * shared by mdt, ost and stand-alone services like fld.
2975 static int mdt_handle_common(struct ptlrpc_request *req,
2976 struct mdt_opc_slice *supported)
2979 struct mdt_thread_info *info;
2983 env = req->rq_svc_thread->t_env;
2984 LASSERT(env != NULL);
2985 LASSERT(env->le_ses != NULL);
2986 LASSERT(env->le_ctx.lc_thread == req->rq_svc_thread);
2987 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
2988 LASSERT(info != NULL);
2990 mdt_thread_info_init(req, info);
2992 rc = mdt_handle0(req, info, supported);
2994 mdt_thread_info_fini(info);
2999 * This is called from recovery code as handler of _all_ RPC types, FLD and SEQ
3002 int mdt_recovery_handle(struct ptlrpc_request *req)
3007 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
3009 rc = mdt_handle_common(req, mdt_fld_handlers);
3012 rc = mdt_handle_common(req, mdt_seq_handlers);
3015 rc = mdt_handle_common(req, mdt_regular_handlers);
3022 static int mdt_regular_handle(struct ptlrpc_request *req)
3024 return mdt_handle_common(req, mdt_regular_handlers);
3027 static int mdt_readpage_handle(struct ptlrpc_request *req)
3029 return mdt_handle_common(req, mdt_readpage_handlers);
3032 static int mdt_xmds_handle(struct ptlrpc_request *req)
3034 return mdt_handle_common(req, mdt_xmds_handlers);
3037 static int mdt_mdsc_handle(struct ptlrpc_request *req)
3039 return mdt_handle_common(req, mdt_seq_handlers);
3042 static int mdt_mdss_handle(struct ptlrpc_request *req)
3044 return mdt_handle_common(req, mdt_seq_handlers);
3047 static int mdt_dtss_handle(struct ptlrpc_request *req)
3049 return mdt_handle_common(req, mdt_seq_handlers);
3052 static int mdt_fld_handle(struct ptlrpc_request *req)
3054 return mdt_handle_common(req, mdt_fld_handlers);
3070 static int mdt_intent_getattr(enum mdt_it_code opcode,
3071 struct mdt_thread_info *info,
3072 struct ldlm_lock **,
3074 static int mdt_intent_reint(enum mdt_it_code opcode,
3075 struct mdt_thread_info *info,
3076 struct ldlm_lock **,
3079 static struct mdt_it_flavor {
3080 const struct req_format *it_fmt;
3082 int (*it_act)(enum mdt_it_code ,
3083 struct mdt_thread_info *,
3084 struct ldlm_lock **,
3087 } mdt_it_flavor[] = {
3089 .it_fmt = &RQF_LDLM_INTENT,
3090 /*.it_flags = HABEO_REFERO,*/
3092 .it_act = mdt_intent_reint,
3093 .it_reint = REINT_OPEN
3096 .it_fmt = &RQF_LDLM_INTENT,
3097 .it_flags = MUTABOR,
3098 .it_act = mdt_intent_reint,
3099 .it_reint = REINT_OPEN
3102 .it_fmt = &RQF_LDLM_INTENT,
3103 .it_flags = MUTABOR,
3104 .it_act = mdt_intent_reint,
3105 .it_reint = REINT_CREATE
3107 [MDT_IT_GETATTR] = {
3108 .it_fmt = &RQF_LDLM_INTENT_GETATTR,
3109 .it_flags = HABEO_REFERO,
3110 .it_act = mdt_intent_getattr
3112 [MDT_IT_READDIR] = {
3118 .it_fmt = &RQF_LDLM_INTENT_GETATTR,
3119 .it_flags = HABEO_REFERO,
3120 .it_act = mdt_intent_getattr
3123 .it_fmt = &RQF_LDLM_INTENT_UNLINK,
3124 .it_flags = MUTABOR,
3126 .it_reint = REINT_UNLINK
3130 .it_flags = MUTABOR,
3133 [MDT_IT_GETXATTR] = {
3140 int mdt_intent_lock_replace(struct mdt_thread_info *info,
3141 struct ldlm_lock **lockp,
3142 struct ldlm_lock *new_lock,
3143 struct mdt_lock_handle *lh,
3146 struct ptlrpc_request *req = mdt_info_req(info);
3147 struct ldlm_lock *lock = *lockp;
3150 * Get new lock only for cases when possible resent did not find any
3153 if (new_lock == NULL)
3154 new_lock = ldlm_handle2lock_long(&lh->mlh_reg_lh, 0);
3156 if (new_lock == NULL && (flags & LDLM_FL_INTENT_ONLY)) {
3157 lh->mlh_reg_lh.cookie = 0;
3161 LASSERTF(new_lock != NULL,
3162 "lockh "LPX64"\n", lh->mlh_reg_lh.cookie);
3165 * If we've already given this lock to a client once, then we should
3166 * have no readers or writers. Otherwise, we should have one reader
3167 * _or_ writer ref (which will be zeroed below) before returning the
3170 if (new_lock->l_export == req->rq_export) {
3171 LASSERT(new_lock->l_readers + new_lock->l_writers == 0);
3173 LASSERT(new_lock->l_export == NULL);
3174 LASSERT(new_lock->l_readers + new_lock->l_writers == 1);
3179 if (new_lock->l_export == req->rq_export) {
3181 * Already gave this to the client, which means that we
3182 * reconstructed a reply.
3184 LASSERT(lustre_msg_get_flags(req->rq_reqmsg) &
3186 lh->mlh_reg_lh.cookie = 0;
3187 RETURN(ELDLM_LOCK_REPLACED);
3191 * Fixup the lock to be given to the client.
3193 lock_res_and_lock(new_lock);
3194 /* Zero new_lock->l_readers and new_lock->l_writers without triggering
3195 * possible blocking AST. */
3196 while (new_lock->l_readers > 0) {
3197 lu_ref_del(&new_lock->l_reference, "reader", new_lock);
3198 lu_ref_del(&new_lock->l_reference, "user", new_lock);
3199 new_lock->l_readers--;
3201 while (new_lock->l_writers > 0) {
3202 lu_ref_del(&new_lock->l_reference, "writer", new_lock);
3203 lu_ref_del(&new_lock->l_reference, "user", new_lock);
3204 new_lock->l_writers--;
3207 new_lock->l_export = class_export_lock_get(req->rq_export, new_lock);
3208 new_lock->l_blocking_ast = lock->l_blocking_ast;
3209 new_lock->l_completion_ast = lock->l_completion_ast;
3210 new_lock->l_remote_handle = lock->l_remote_handle;
3211 new_lock->l_flags &= ~LDLM_FL_LOCAL;
3213 unlock_res_and_lock(new_lock);
3215 cfs_hash_add(new_lock->l_export->exp_lock_hash,
3216 &new_lock->l_remote_handle,
3217 &new_lock->l_exp_hash);
3219 LDLM_LOCK_RELEASE(new_lock);
3220 lh->mlh_reg_lh.cookie = 0;
3222 RETURN(ELDLM_LOCK_REPLACED);
3225 static void mdt_intent_fixup_resent(struct mdt_thread_info *info,
3226 struct ldlm_lock *new_lock,
3227 struct ldlm_lock **old_lock,
3228 struct mdt_lock_handle *lh)
3230 struct ptlrpc_request *req = mdt_info_req(info);
3231 struct obd_export *exp = req->rq_export;
3232 struct lustre_handle remote_hdl;
3233 struct ldlm_request *dlmreq;
3234 struct ldlm_lock *lock;
3236 if (!(lustre_msg_get_flags(req->rq_reqmsg) & MSG_RESENT))
3239 dlmreq = req_capsule_client_get(info->mti_pill, &RMF_DLM_REQ);
3240 remote_hdl = dlmreq->lock_handle[0];
3242 lock = cfs_hash_lookup(exp->exp_lock_hash, &remote_hdl);
3244 if (lock != new_lock) {
3245 lh->mlh_reg_lh.cookie = lock->l_handle.h_cookie;
3246 lh->mlh_reg_mode = lock->l_granted_mode;
3248 LDLM_DEBUG(lock, "Restoring lock cookie");
3249 DEBUG_REQ(D_DLMTRACE, req,
3250 "restoring lock cookie "LPX64,
3251 lh->mlh_reg_lh.cookie);
3253 *old_lock = LDLM_LOCK_GET(lock);
3254 cfs_hash_put(exp->exp_lock_hash, &lock->l_exp_hash);
3258 cfs_hash_put(exp->exp_lock_hash, &lock->l_exp_hash);
3262 * If the xid matches, then we know this is a resent request, and allow
3263 * it. (It's probably an OPEN, for which we don't send a lock.
3265 if (req_xid_is_last(req))
3269 * This remote handle isn't enqueued, so we never received or processed
3270 * this request. Clear MSG_RESENT, because it can be handled like any
3271 * normal request now.
3273 lustre_msg_clear_flags(req->rq_reqmsg, MSG_RESENT);
3275 DEBUG_REQ(D_DLMTRACE, req, "no existing lock with rhandle "LPX64,
3279 static int mdt_intent_getattr(enum mdt_it_code opcode,
3280 struct mdt_thread_info *info,
3281 struct ldlm_lock **lockp,
3284 struct mdt_lock_handle *lhc = &info->mti_lh[MDT_LH_RMT];
3285 struct ldlm_lock *new_lock = NULL;
3287 struct ldlm_reply *ldlm_rep;
3288 struct ptlrpc_request *req;
3289 struct mdt_body *reqbody;
3290 struct mdt_body *repbody;
3294 reqbody = req_capsule_client_get(info->mti_pill, &RMF_MDT_BODY);
3297 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
3300 info->mti_spec.sp_ck_split = !!(reqbody->valid & OBD_MD_FLCKSPLIT);
3301 info->mti_cross_ref = !!(reqbody->valid & OBD_MD_FLCROSSREF);
3302 repbody->eadatasize = 0;
3303 repbody->aclsize = 0;
3307 child_bits = MDS_INODELOCK_LOOKUP;
3309 case MDT_IT_GETATTR:
3310 child_bits = MDS_INODELOCK_LOOKUP | MDS_INODELOCK_UPDATE;
3313 CERROR("Unhandled till now");
3314 GOTO(out_shrink, rc = -EINVAL);
3317 rc = mdt_init_ucred(info, reqbody);
3319 GOTO(out_shrink, rc);
3321 req = info->mti_pill->rc_req;
3322 ldlm_rep = req_capsule_server_get(info->mti_pill, &RMF_DLM_REP);
3323 mdt_set_disposition(info, ldlm_rep, DISP_IT_EXECD);
3325 /* Get lock from request for possible resent case. */
3326 mdt_intent_fixup_resent(info, *lockp, &new_lock, lhc);
3328 ldlm_rep->lock_policy_res2 =
3329 mdt_getattr_name_lock(info, lhc, child_bits, ldlm_rep);
3331 if (mdt_get_disposition(ldlm_rep, DISP_LOOKUP_NEG))
3332 ldlm_rep->lock_policy_res2 = 0;
3333 if (!mdt_get_disposition(ldlm_rep, DISP_LOOKUP_POS) ||
3334 ldlm_rep->lock_policy_res2) {
3335 lhc->mlh_reg_lh.cookie = 0ull;
3336 GOTO(out_ucred, rc = ELDLM_LOCK_ABORTED);
3339 rc = mdt_intent_lock_replace(info, lockp, new_lock, lhc, flags);
3342 mdt_exit_ucred(info);
3344 mdt_shrink_reply(info);
3348 static int mdt_intent_reint(enum mdt_it_code opcode,
3349 struct mdt_thread_info *info,
3350 struct ldlm_lock **lockp,
3353 struct mdt_lock_handle *lhc = &info->mti_lh[MDT_LH_RMT];
3354 struct ldlm_reply *rep = NULL;
3358 static const struct req_format *intent_fmts[REINT_MAX] = {
3359 [REINT_CREATE] = &RQF_LDLM_INTENT_CREATE,
3360 [REINT_OPEN] = &RQF_LDLM_INTENT_OPEN
3365 opc = mdt_reint_opcode(info, intent_fmts);
3369 if (mdt_it_flavor[opcode].it_reint != opc) {
3370 CERROR("Reint code %ld doesn't match intent: %d\n",
3372 RETURN(err_serious(-EPROTO));
3375 /* Get lock from request for possible resent case. */
3376 mdt_intent_fixup_resent(info, *lockp, NULL, lhc);
3378 rc = mdt_reint_internal(info, lhc, opc);
3380 /* Check whether the reply has been packed successfully. */
3381 if (mdt_info_req(info)->rq_repmsg != NULL)
3382 rep = req_capsule_server_get(info->mti_pill, &RMF_DLM_REP);
3384 RETURN(err_serious(-EFAULT));
3386 /* MDC expects this in any case */
3388 mdt_set_disposition(info, rep, DISP_LOOKUP_EXECD);
3390 /* Cross-ref case, the lock should be returned to the client */
3391 if (rc == -EREMOTE) {
3392 LASSERT(lustre_handle_is_used(&lhc->mlh_reg_lh));
3393 rep->lock_policy_res2 = 0;
3394 rc = mdt_intent_lock_replace(info, lockp, NULL, lhc, flags);
3397 rep->lock_policy_res2 = clear_serious(rc);
3399 if (rc == -ENOTCONN || rc == -ENODEV ||
3400 rc == -EOVERFLOW) { /**< if VBR failure then return error */
3402 * If it is the disconnect error (ENODEV & ENOCONN), the error
3403 * will be returned by rq_status, and client at ptlrpc layer
3404 * will detect this, then disconnect, reconnect the import
3405 * immediately, instead of impacting the following the rpc.
3407 lhc->mlh_reg_lh.cookie = 0ull;
3411 * For other cases, the error will be returned by intent.
3412 * and client will retrieve the result from intent.
3415 * FIXME: when open lock is finished, that should be
3418 if (lustre_handle_is_used(&lhc->mlh_reg_lh)) {
3419 LASSERTF(rc == 0, "Error occurred but lock handle "
3420 "is still in use\n");
3421 rep->lock_policy_res2 = 0;
3422 rc = mdt_intent_lock_replace(info, lockp, NULL, lhc, flags);
3425 lhc->mlh_reg_lh.cookie = 0ull;
3426 RETURN(ELDLM_LOCK_ABORTED);
3431 static int mdt_intent_code(long itcode)
3439 case IT_OPEN|IT_CREAT:
3446 rc = MDT_IT_READDIR;
3449 rc = MDT_IT_GETATTR;
3461 rc = MDT_IT_GETXATTR;
3464 CERROR("Unknown intent opcode: %ld\n", itcode);
3471 static int mdt_intent_opc(long itopc, struct mdt_thread_info *info,
3472 struct ldlm_lock **lockp, int flags)
3474 struct req_capsule *pill;
3475 struct mdt_it_flavor *flv;
3480 opc = mdt_intent_code(itopc);
3484 pill = info->mti_pill;
3485 flv = &mdt_it_flavor[opc];
3487 if (flv->it_fmt != NULL)
3488 req_capsule_extend(pill, flv->it_fmt);
3490 rc = mdt_unpack_req_pack_rep(info, flv->it_flags);
3492 struct ptlrpc_request *req = mdt_info_req(info);
3493 if (flv->it_flags & MUTABOR &&
3494 req->rq_export->exp_connect_flags & OBD_CONNECT_RDONLY)
3497 if (rc == 0 && flv->it_act != NULL) {
3498 /* execute policy */
3499 rc = flv->it_act(opc, info, lockp, flags);
3506 static int mdt_intent_policy(struct ldlm_namespace *ns,
3507 struct ldlm_lock **lockp, void *req_cookie,
3508 ldlm_mode_t mode, int flags, void *data)
3510 struct mdt_thread_info *info;
3511 struct ptlrpc_request *req = req_cookie;
3512 struct ldlm_intent *it;
3513 struct req_capsule *pill;
3518 LASSERT(req != NULL);
3520 info = lu_context_key_get(&req->rq_svc_thread->t_env->le_ctx,
3522 LASSERT(info != NULL);
3523 pill = info->mti_pill;
3524 LASSERT(pill->rc_req == req);
3526 if (req->rq_reqmsg->lm_bufcount > DLM_INTENT_IT_OFF) {
3527 req_capsule_extend(pill, &RQF_LDLM_INTENT);
3528 it = req_capsule_client_get(pill, &RMF_LDLM_INTENT);
3530 rc = mdt_intent_opc(it->opc, info, lockp, flags);
3534 /* Lock without inodebits makes no sense and will oops
3535 * later in ldlm. Let's check it now to see if we have
3536 * ibits corrupted somewhere in mdt_intent_opc().
3537 * The case for client miss to set ibits has been
3538 * processed by others. */
3539 LASSERT(ergo(info->mti_dlm_req->lock_desc.l_resource.\
3540 lr_type == LDLM_IBITS,
3541 info->mti_dlm_req->lock_desc.\
3542 l_policy_data.l_inodebits.bits != 0));
3544 rc = err_serious(-EFAULT);
3546 /* No intent was provided */
3547 LASSERT(pill->rc_fmt == &RQF_LDLM_ENQUEUE);
3548 rc = req_capsule_server_pack(pill);
3550 rc = err_serious(rc);
3555 static int mdt_seq_fini(const struct lu_env *env,
3556 struct mdt_device *m)
3558 struct md_site *ms = mdt_md_site(m);
3562 if (ms->ms_server_seq) {
3563 seq_server_fini(ms->ms_server_seq, env);
3564 OBD_FREE_PTR(ms->ms_server_seq);
3565 ms->ms_server_seq = NULL;
3568 if (ms->ms_control_seq) {
3569 seq_server_fini(ms->ms_control_seq, env);
3570 OBD_FREE_PTR(ms->ms_control_seq);
3571 ms->ms_control_seq = NULL;
3574 if (ms->ms_client_seq) {
3575 seq_client_fini(ms->ms_client_seq);
3576 OBD_FREE_PTR(ms->ms_client_seq);
3577 ms->ms_client_seq = NULL;
3584 static int mdt_seq_init(const struct lu_env *env,
3586 struct mdt_device *m)
3593 ms = mdt_md_site(m);
3596 * This is sequence-controller node. Init seq-controller server on local
3599 if (ms->ms_node_id == 0) {
3600 LASSERT(ms->ms_control_seq == NULL);
3602 OBD_ALLOC_PTR(ms->ms_control_seq);
3603 if (ms->ms_control_seq == NULL)
3606 rc = seq_server_init(ms->ms_control_seq,
3607 m->mdt_bottom, uuid,
3608 LUSTRE_SEQ_CONTROLLER,
3613 GOTO(out_seq_fini, rc);
3615 OBD_ALLOC_PTR(ms->ms_client_seq);
3616 if (ms->ms_client_seq == NULL)
3617 GOTO(out_seq_fini, rc = -ENOMEM);
3619 OBD_ALLOC(prefix, MAX_OBD_NAME + 5);
3620 if (prefix == NULL) {
3621 OBD_FREE_PTR(ms->ms_client_seq);
3622 GOTO(out_seq_fini, rc = -ENOMEM);
3625 snprintf(prefix, MAX_OBD_NAME + 5, "ctl-%s",
3629 * Init seq-controller client after seq-controller server is
3630 * ready. Pass ms->ms_control_seq to it for direct talking.
3632 rc = seq_client_init(ms->ms_client_seq, NULL,
3633 LUSTRE_SEQ_METADATA, prefix,
3634 ms->ms_control_seq);
3635 OBD_FREE(prefix, MAX_OBD_NAME + 5);
3638 GOTO(out_seq_fini, rc);
3641 /* Init seq-server on local MDT */
3642 LASSERT(ms->ms_server_seq == NULL);
3644 OBD_ALLOC_PTR(ms->ms_server_seq);
3645 if (ms->ms_server_seq == NULL)
3646 GOTO(out_seq_fini, rc = -ENOMEM);
3648 rc = seq_server_init(ms->ms_server_seq,
3649 m->mdt_bottom, uuid,
3654 GOTO(out_seq_fini, rc = -ENOMEM);
3656 /* Assign seq-controller client to local seq-server. */
3657 if (ms->ms_node_id == 0) {
3658 LASSERT(ms->ms_client_seq != NULL);
3660 rc = seq_server_set_cli(ms->ms_server_seq,
3668 mdt_seq_fini(env, m);
3673 * Init client sequence manager which is used by local MDS to talk to sequence
3674 * controller on remote node.
3676 static int mdt_seq_init_cli(const struct lu_env *env,
3677 struct mdt_device *m,
3678 struct lustre_cfg *cfg)
3680 struct md_site *ms = mdt_md_site(m);
3681 struct obd_device *mdc;
3682 struct obd_uuid *uuidp, *mdcuuidp;
3683 char *uuid_str, *mdc_uuid_str;
3686 struct mdt_thread_info *info;
3687 char *p, *index_string = lustre_cfg_string(cfg, 2);
3690 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
3691 uuidp = &info->mti_u.uuid[0];
3692 mdcuuidp = &info->mti_u.uuid[1];
3694 LASSERT(index_string);
3696 index = simple_strtol(index_string, &p, 10);
3698 CERROR("Invalid index in lustre_cgf, offset 2\n");
3702 /* check if this is adding the first MDC and controller is not yet
3704 if (index != 0 || ms->ms_client_seq)
3707 uuid_str = lustre_cfg_string(cfg, 1);
3708 mdc_uuid_str = lustre_cfg_string(cfg, 4);
3709 obd_str2uuid(uuidp, uuid_str);
3710 obd_str2uuid(mdcuuidp, mdc_uuid_str);
3712 mdc = class_find_client_obd(uuidp, LUSTRE_MDC_NAME, mdcuuidp);
3714 CERROR("can't find controller MDC by uuid %s\n",
3717 } else if (!mdc->obd_set_up) {
3718 CERROR("target %s not set up\n", mdc->obd_name);
3721 LASSERT(ms->ms_control_exp);
3722 OBD_ALLOC_PTR(ms->ms_client_seq);
3723 if (ms->ms_client_seq != NULL) {
3726 OBD_ALLOC(prefix, MAX_OBD_NAME + 5);
3730 snprintf(prefix, MAX_OBD_NAME + 5, "ctl-%s",
3733 rc = seq_client_init(ms->ms_client_seq,
3735 LUSTRE_SEQ_METADATA,
3737 OBD_FREE(prefix, MAX_OBD_NAME + 5);
3744 LASSERT(ms->ms_server_seq != NULL);
3745 rc = seq_server_set_cli(ms->ms_server_seq, ms->ms_client_seq,
3752 static void mdt_seq_fini_cli(struct mdt_device *m)
3758 ms = mdt_md_site(m);
3761 if (ms->ms_server_seq)
3762 seq_server_set_cli(ms->ms_server_seq,
3765 if (ms->ms_control_exp) {
3766 class_export_put(ms->ms_control_exp);
3767 ms->ms_control_exp = NULL;
3776 static int mdt_fld_fini(const struct lu_env *env,
3777 struct mdt_device *m)
3779 struct md_site *ms = mdt_md_site(m);
3782 if (ms && ms->ms_server_fld) {
3783 fld_server_fini(ms->ms_server_fld, env);
3784 OBD_FREE_PTR(ms->ms_server_fld);
3785 ms->ms_server_fld = NULL;
3791 static int mdt_fld_init(const struct lu_env *env,
3793 struct mdt_device *m)
3799 ms = mdt_md_site(m);
3801 OBD_ALLOC_PTR(ms->ms_server_fld);
3802 if (ms->ms_server_fld == NULL)
3803 RETURN(rc = -ENOMEM);
3805 rc = fld_server_init(ms->ms_server_fld,
3806 m->mdt_bottom, uuid,
3807 env, ms->ms_node_id);
3809 OBD_FREE_PTR(ms->ms_server_fld);
3810 ms->ms_server_fld = NULL;
3817 /* device init/fini methods */
3818 static void mdt_stop_ptlrpc_service(struct mdt_device *m)
3821 if (m->mdt_regular_service != NULL) {
3822 ptlrpc_unregister_service(m->mdt_regular_service);
3823 m->mdt_regular_service = NULL;
3825 if (m->mdt_readpage_service != NULL) {
3826 ptlrpc_unregister_service(m->mdt_readpage_service);
3827 m->mdt_readpage_service = NULL;
3829 if (m->mdt_xmds_service != NULL) {
3830 ptlrpc_unregister_service(m->mdt_xmds_service);
3831 m->mdt_xmds_service = NULL;
3833 if (m->mdt_setattr_service != NULL) {
3834 ptlrpc_unregister_service(m->mdt_setattr_service);
3835 m->mdt_setattr_service = NULL;
3837 if (m->mdt_mdsc_service != NULL) {
3838 ptlrpc_unregister_service(m->mdt_mdsc_service);
3839 m->mdt_mdsc_service = NULL;
3841 if (m->mdt_mdss_service != NULL) {
3842 ptlrpc_unregister_service(m->mdt_mdss_service);
3843 m->mdt_mdss_service = NULL;
3845 if (m->mdt_dtss_service != NULL) {
3846 ptlrpc_unregister_service(m->mdt_dtss_service);
3847 m->mdt_dtss_service = NULL;
3849 if (m->mdt_fld_service != NULL) {
3850 ptlrpc_unregister_service(m->mdt_fld_service);
3851 m->mdt_fld_service = NULL;
3856 static int mdt_start_ptlrpc_service(struct mdt_device *m)
3859 static struct ptlrpc_service_conf conf;
3860 cfs_proc_dir_entry_t *procfs_entry;
3863 procfs_entry = m->mdt_md_dev.md_lu_dev.ld_obd->obd_proc_entry;
3865 conf = (typeof(conf)) {
3866 .psc_nbufs = MDS_NBUFS,
3867 .psc_bufsize = MDS_BUFSIZE,
3868 .psc_max_req_size = MDS_MAXREQSIZE,
3869 .psc_max_reply_size = MDS_MAXREPSIZE,
3870 .psc_req_portal = MDS_REQUEST_PORTAL,
3871 .psc_rep_portal = MDC_REPLY_PORTAL,
3872 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
3874 * We'd like to have a mechanism to set this on a per-device
3875 * basis, but alas...
3877 .psc_min_threads = mdt_min_threads,
3878 .psc_max_threads = mdt_max_threads,
3879 .psc_ctx_tags = LCT_MD_THREAD
3882 m->mdt_ldlm_client = &m->mdt_md_dev.md_lu_dev.ld_obd->obd_ldlm_client;
3883 ptlrpc_init_client(LDLM_CB_REQUEST_PORTAL, LDLM_CB_REPLY_PORTAL,
3884 "mdt_ldlm_client", m->mdt_ldlm_client);
3886 m->mdt_regular_service =
3887 ptlrpc_init_svc_conf(&conf, mdt_regular_handle, LUSTRE_MDT_NAME,
3888 procfs_entry, target_print_req,
3890 if (m->mdt_regular_service == NULL)
3893 rc = ptlrpc_start_threads(NULL, m->mdt_regular_service);
3895 GOTO(err_mdt_svc, rc);
3898 * readpage service configuration. Parameters have to be adjusted,
3901 conf = (typeof(conf)) {
3902 .psc_nbufs = MDS_NBUFS,
3903 .psc_bufsize = MDS_BUFSIZE,
3904 .psc_max_req_size = MDS_MAXREQSIZE,
3905 .psc_max_reply_size = MDS_MAXREPSIZE,
3906 .psc_req_portal = MDS_READPAGE_PORTAL,
3907 .psc_rep_portal = MDC_REPLY_PORTAL,
3908 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
3909 .psc_min_threads = mdt_min_threads,
3910 .psc_max_threads = mdt_max_threads,
3911 .psc_ctx_tags = LCT_MD_THREAD
3913 m->mdt_readpage_service =
3914 ptlrpc_init_svc_conf(&conf, mdt_readpage_handle,
3915 LUSTRE_MDT_NAME "_readpage",
3916 procfs_entry, target_print_req,"mdt_rdpg");
3918 if (m->mdt_readpage_service == NULL) {
3919 CERROR("failed to start readpage service\n");
3920 GOTO(err_mdt_svc, rc = -ENOMEM);
3923 rc = ptlrpc_start_threads(NULL, m->mdt_readpage_service);
3926 * setattr service configuration.
3928 conf = (typeof(conf)) {
3929 .psc_nbufs = MDS_NBUFS,
3930 .psc_bufsize = MDS_BUFSIZE,
3931 .psc_max_req_size = MDS_MAXREQSIZE,
3932 .psc_max_reply_size = MDS_MAXREPSIZE,
3933 .psc_req_portal = MDS_SETATTR_PORTAL,
3934 .psc_rep_portal = MDC_REPLY_PORTAL,
3935 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
3936 .psc_min_threads = mdt_min_threads,
3937 .psc_max_threads = mdt_max_threads,
3938 .psc_ctx_tags = LCT_MD_THREAD
3941 m->mdt_setattr_service =
3942 ptlrpc_init_svc_conf(&conf, mdt_regular_handle,
3943 LUSTRE_MDT_NAME "_setattr",
3944 procfs_entry, target_print_req,"mdt_attr");
3946 if (!m->mdt_setattr_service) {
3947 CERROR("failed to start setattr service\n");
3948 GOTO(err_mdt_svc, rc = -ENOMEM);
3951 rc = ptlrpc_start_threads(NULL, m->mdt_setattr_service);
3953 GOTO(err_mdt_svc, rc);
3956 * sequence controller service configuration
3958 conf = (typeof(conf)) {
3959 .psc_nbufs = MDS_NBUFS,
3960 .psc_bufsize = MDS_BUFSIZE,
3961 .psc_max_req_size = SEQ_MAXREQSIZE,
3962 .psc_max_reply_size = SEQ_MAXREPSIZE,
3963 .psc_req_portal = SEQ_CONTROLLER_PORTAL,
3964 .psc_rep_portal = MDC_REPLY_PORTAL,
3965 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
3966 .psc_min_threads = mdt_min_threads,
3967 .psc_max_threads = mdt_max_threads,
3968 .psc_ctx_tags = LCT_MD_THREAD|LCT_DT_THREAD
3971 m->mdt_mdsc_service =
3972 ptlrpc_init_svc_conf(&conf, mdt_mdsc_handle,
3973 LUSTRE_MDT_NAME"_mdsc",
3974 procfs_entry, target_print_req,"mdt_mdsc");
3975 if (!m->mdt_mdsc_service) {
3976 CERROR("failed to start seq controller service\n");
3977 GOTO(err_mdt_svc, rc = -ENOMEM);
3980 rc = ptlrpc_start_threads(NULL, m->mdt_mdsc_service);
3982 GOTO(err_mdt_svc, rc);
3985 * metadata sequence server service configuration
3987 conf = (typeof(conf)) {
3988 .psc_nbufs = MDS_NBUFS,
3989 .psc_bufsize = MDS_BUFSIZE,
3990 .psc_max_req_size = SEQ_MAXREQSIZE,
3991 .psc_max_reply_size = SEQ_MAXREPSIZE,
3992 .psc_req_portal = SEQ_METADATA_PORTAL,
3993 .psc_rep_portal = MDC_REPLY_PORTAL,
3994 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
3995 .psc_min_threads = mdt_min_threads,
3996 .psc_max_threads = mdt_max_threads,
3997 .psc_ctx_tags = LCT_MD_THREAD|LCT_DT_THREAD
4000 m->mdt_mdss_service =
4001 ptlrpc_init_svc_conf(&conf, mdt_mdss_handle,
4002 LUSTRE_MDT_NAME"_mdss",
4003 procfs_entry, target_print_req,"mdt_mdss");
4004 if (!m->mdt_mdss_service) {
4005 CERROR("failed to start metadata seq server service\n");
4006 GOTO(err_mdt_svc, rc = -ENOMEM);
4009 rc = ptlrpc_start_threads(NULL, m->mdt_mdss_service);
4011 GOTO(err_mdt_svc, rc);
4015 * Data sequence server service configuration. We want to have really
4016 * cluster-wide sequences space. This is why we start only one sequence
4017 * controller which manages space.
4019 conf = (typeof(conf)) {
4020 .psc_nbufs = MDS_NBUFS,
4021 .psc_bufsize = MDS_BUFSIZE,
4022 .psc_max_req_size = SEQ_MAXREQSIZE,
4023 .psc_max_reply_size = SEQ_MAXREPSIZE,
4024 .psc_req_portal = SEQ_DATA_PORTAL,
4025 .psc_rep_portal = OSC_REPLY_PORTAL,
4026 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
4027 .psc_min_threads = mdt_min_threads,
4028 .psc_max_threads = mdt_max_threads,
4029 .psc_ctx_tags = LCT_MD_THREAD|LCT_DT_THREAD
4032 m->mdt_dtss_service =
4033 ptlrpc_init_svc_conf(&conf, mdt_dtss_handle,
4034 LUSTRE_MDT_NAME"_dtss",
4035 procfs_entry, target_print_req,"mdt_dtss");
4036 if (!m->mdt_dtss_service) {
4037 CERROR("failed to start data seq server service\n");
4038 GOTO(err_mdt_svc, rc = -ENOMEM);
4041 rc = ptlrpc_start_threads(NULL, m->mdt_dtss_service);
4043 GOTO(err_mdt_svc, rc);
4045 /* FLD service start */
4046 conf = (typeof(conf)) {
4047 .psc_nbufs = MDS_NBUFS,
4048 .psc_bufsize = MDS_BUFSIZE,
4049 .psc_max_req_size = FLD_MAXREQSIZE,
4050 .psc_max_reply_size = FLD_MAXREPSIZE,
4051 .psc_req_portal = FLD_REQUEST_PORTAL,
4052 .psc_rep_portal = MDC_REPLY_PORTAL,
4053 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
4054 .psc_min_threads = mdt_min_threads,
4055 .psc_max_threads = mdt_max_threads,
4056 .psc_ctx_tags = LCT_DT_THREAD|LCT_MD_THREAD
4059 m->mdt_fld_service =
4060 ptlrpc_init_svc_conf(&conf, mdt_fld_handle,
4061 LUSTRE_MDT_NAME"_fld",
4062 procfs_entry, target_print_req, "mdt_fld");
4063 if (!m->mdt_fld_service) {
4064 CERROR("failed to start fld service\n");
4065 GOTO(err_mdt_svc, rc = -ENOMEM);
4068 rc = ptlrpc_start_threads(NULL, m->mdt_fld_service);
4070 GOTO(err_mdt_svc, rc);
4073 * mds-mds service configuration. Separate portal is used to allow
4074 * mds-mds requests be not blocked during recovery.
4076 conf = (typeof(conf)) {
4077 .psc_nbufs = MDS_NBUFS,
4078 .psc_bufsize = MDS_BUFSIZE,
4079 .psc_max_req_size = MDS_MAXREQSIZE,
4080 .psc_max_reply_size = MDS_MAXREPSIZE,
4081 .psc_req_portal = MDS_MDS_PORTAL,
4082 .psc_rep_portal = MDC_REPLY_PORTAL,
4083 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
4084 .psc_min_threads = mdt_min_threads,
4085 .psc_max_threads = mdt_max_threads,
4086 .psc_ctx_tags = LCT_MD_THREAD
4088 m->mdt_xmds_service =
4089 ptlrpc_init_svc_conf(&conf, mdt_xmds_handle,
4090 LUSTRE_MDT_NAME "_mds",
4091 procfs_entry, target_print_req,"mdt_xmds");
4093 if (m->mdt_xmds_service == NULL) {
4094 CERROR("failed to start xmds service\n");
4095 GOTO(err_mdt_svc, rc = -ENOMEM);
4098 rc = ptlrpc_start_threads(NULL, m->mdt_xmds_service);
4100 GOTO(err_mdt_svc, rc);
4105 mdt_stop_ptlrpc_service(m);
4110 static void mdt_stack_fini(const struct lu_env *env,
4111 struct mdt_device *m, struct lu_device *top)
4113 struct obd_device *obd = mdt2obd_dev(m);
4114 struct lustre_cfg_bufs *bufs;
4115 struct lustre_cfg *lcfg;
4116 struct mdt_thread_info *info;
4120 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
4121 LASSERT(info != NULL);
4123 bufs = &info->mti_u.bufs;
4124 /* process cleanup, pass mdt obd name to get obd umount flags */
4125 lustre_cfg_bufs_reset(bufs, obd->obd_name);
4130 lustre_cfg_bufs_set_string(bufs, 1, flags);
4131 lcfg = lustre_cfg_new(LCFG_CLEANUP, bufs);
4133 CERROR("Cannot alloc lcfg!\n");
4138 top->ld_ops->ldo_process_config(env, top, lcfg);
4139 lustre_cfg_free(lcfg);
4141 lu_stack_fini(env, top);
4142 m->mdt_child = NULL;
4143 m->mdt_bottom = NULL;
4146 static struct lu_device *mdt_layer_setup(struct lu_env *env,
4147 const char *typename,
4148 struct lu_device *child,
4149 struct lustre_cfg *cfg)
4151 const char *dev = lustre_cfg_string(cfg, 0);
4152 struct obd_type *type;
4153 struct lu_device_type *ldt;
4154 struct lu_device *d;
4159 type = class_get_type(typename);
4161 CERROR("Unknown type: '%s'\n", typename);
4162 GOTO(out, rc = -ENODEV);
4165 rc = lu_env_refill((struct lu_env *)env);
4167 CERROR("Failure to refill session: '%d'\n", rc);
4173 CERROR("type: '%s'\n", typename);
4174 GOTO(out_type, rc = -EINVAL);
4177 ldt->ldt_obd_type = type;
4178 d = ldt->ldt_ops->ldto_device_alloc(env, ldt, cfg);
4180 CERROR("Cannot allocate device: '%s'\n", typename);
4181 GOTO(out_type, rc = -ENODEV);
4184 LASSERT(child->ld_site);
4185 d->ld_site = child->ld_site;
4188 rc = ldt->ldt_ops->ldto_device_init(env, d, dev, child);
4190 CERROR("can't init device '%s', rc %d\n", typename, rc);
4191 GOTO(out_alloc, rc);
4194 lu_ref_add(&d->ld_reference, "lu-stack", &lu_site_init);
4199 ldt->ldt_ops->ldto_device_free(env, d);
4202 class_put_type(type);
4207 static int mdt_stack_init(struct lu_env *env,
4208 struct mdt_device *m,
4209 struct lustre_cfg *cfg,
4210 struct lustre_mount_info *lmi)
4212 struct lu_device *d = &m->mdt_md_dev.md_lu_dev;
4213 struct lu_device *tmp;
4214 struct md_device *md;
4215 struct lu_device *child_lu_dev;
4219 /* init the stack */
4220 tmp = mdt_layer_setup(env, LUSTRE_OSD_NAME, d, cfg);
4222 RETURN(PTR_ERR(tmp));
4224 m->mdt_bottom = lu2dt_dev(tmp);
4226 tmp = mdt_layer_setup(env, LUSTRE_MDD_NAME, d, cfg);
4228 GOTO(out, rc = PTR_ERR(tmp));
4233 tmp = mdt_layer_setup(env, LUSTRE_CMM_NAME, d, cfg);
4235 GOTO(out, rc = PTR_ERR(tmp));
4238 /*set mdd upcall device*/
4239 md_upcall_dev_set(md, lu2md_dev(d));
4242 /*set cmm upcall device*/
4243 md_upcall_dev_set(md, &m->mdt_md_dev);
4245 m->mdt_child = lu2md_dev(d);
4247 /* process setup config */
4248 tmp = &m->mdt_md_dev.md_lu_dev;
4249 rc = tmp->ld_ops->ldo_process_config(env, tmp, cfg);
4253 /* initialize local objects */
4254 child_lu_dev = &m->mdt_child->md_lu_dev;
4256 rc = child_lu_dev->ld_ops->ldo_prepare(env,
4257 &m->mdt_md_dev.md_lu_dev,
4260 /* fini from last known good lu_device */
4262 mdt_stack_fini(env, m, d);
4268 * setup CONFIG_ORIG context, used to access local config log.
4269 * this may need to be rewrite as part of llog rewrite for lu-api.
4271 static int mdt_obd_llog_setup(struct obd_device *obd,
4272 struct lustre_sb_info *lsi)
4276 LASSERT(obd->obd_fsops == NULL);
4278 obd->obd_fsops = fsfilt_get_ops(MT_STR(lsi->lsi_ldd));
4279 if (IS_ERR(obd->obd_fsops))
4280 return PTR_ERR(obd->obd_fsops);
4282 rc = fsfilt_setup(obd, lsi->lsi_srv_mnt->mnt_sb);
4284 fsfilt_put_ops(obd->obd_fsops);
4288 OBD_SET_CTXT_MAGIC(&obd->obd_lvfs_ctxt);
4289 obd->obd_lvfs_ctxt.pwdmnt = lsi->lsi_srv_mnt;
4290 obd->obd_lvfs_ctxt.pwd = lsi->lsi_srv_mnt->mnt_root;
4291 obd->obd_lvfs_ctxt.fs = get_ds();
4293 rc = llog_setup(obd, &obd->obd_olg, LLOG_CONFIG_ORIG_CTXT, obd,
4294 0, NULL, &llog_lvfs_ops);
4296 CERROR("llog_setup() failed: %d\n", rc);
4297 fsfilt_put_ops(obd->obd_fsops);
4303 static void mdt_obd_llog_cleanup(struct obd_device *obd)
4305 struct llog_ctxt *ctxt;
4307 ctxt = llog_get_context(obd, LLOG_CONFIG_ORIG_CTXT);
4311 if (obd->obd_fsops) {
4312 fsfilt_put_ops(obd->obd_fsops);
4313 obd->obd_fsops = NULL;
4317 static void mdt_fini(const struct lu_env *env, struct mdt_device *m)
4319 struct md_device *next = m->mdt_child;
4320 struct lu_device *d = &m->mdt_md_dev.md_lu_dev;
4321 struct lu_site *ls = d->ld_site;
4322 struct obd_device *obd = mdt2obd_dev(m);
4325 target_recovery_fini(obd);
4327 ping_evictor_stop();
4329 mdt_stop_ptlrpc_service(m);
4330 mdt_llog_ctxt_unclone(env, m, LLOG_CHANGELOG_ORIG_CTXT);
4331 mdt_obd_llog_cleanup(obd);
4332 obd_exports_barrier(obd);
4333 obd_zombie_barrier();
4334 #ifdef HAVE_QUOTA_SUPPORT
4335 next->md_ops->mdo_quota.mqo_cleanup(env, next);
4337 lut_fini(env, &m->mdt_lut);
4338 mdt_fs_cleanup(env, m);
4339 upcall_cache_cleanup(m->mdt_identity_cache);
4340 m->mdt_identity_cache = NULL;
4342 if (m->mdt_namespace != NULL) {
4343 ldlm_namespace_free(m->mdt_namespace, NULL,
4344 d->ld_obd->obd_force);
4345 d->ld_obd->obd_namespace = m->mdt_namespace = NULL;
4348 cfs_free_nidlist(&m->mdt_nosquash_nids);
4349 if (m->mdt_nosquash_str) {
4350 OBD_FREE(m->mdt_nosquash_str, m->mdt_nosquash_strlen);
4351 m->mdt_nosquash_str = NULL;
4352 m->mdt_nosquash_strlen = 0;
4355 mdt_seq_fini(env, m);
4356 mdt_seq_fini_cli(m);
4357 mdt_fld_fini(env, m);
4358 sptlrpc_rule_set_free(&m->mdt_sptlrpc_rset);
4360 next->md_ops->mdo_init_capa_ctxt(env, next, 0, 0, 0, NULL);
4361 cfs_timer_disarm(&m->mdt_ck_timer);
4362 mdt_ck_thread_stop(m);
4367 mdt_stack_fini(env, m, md2lu_dev(m->mdt_child));
4369 lprocfs_free_per_client_stats(obd);
4370 lprocfs_free_obd_stats(obd);
4374 struct md_site *mite;
4377 mite = lu_site2md(ls);
4381 LASSERT(cfs_atomic_read(&d->ld_ref) == 0);
4386 static int mdt_adapt_sptlrpc_conf(struct obd_device *obd, int initial)
4388 struct mdt_device *m = mdt_dev(obd->obd_lu_dev);
4389 struct sptlrpc_rule_set tmp_rset;
4392 sptlrpc_rule_set_init(&tmp_rset);
4393 rc = sptlrpc_conf_target_get_rules(obd, &tmp_rset, initial);
4395 CERROR("mdt %s: failed get sptlrpc rules: %d\n",
4400 sptlrpc_target_update_exp_flavor(obd, &tmp_rset);
4402 cfs_write_lock(&m->mdt_sptlrpc_lock);
4403 sptlrpc_rule_set_free(&m->mdt_sptlrpc_rset);
4404 m->mdt_sptlrpc_rset = tmp_rset;
4405 cfs_write_unlock(&m->mdt_sptlrpc_lock);
4410 static void fsoptions_to_mdt_flags(struct mdt_device *m, char *options)
4414 m->mdt_opts.mo_mds_capa = 1;
4415 m->mdt_opts.mo_oss_capa = 1;
4416 #ifdef CONFIG_FS_POSIX_ACL
4417 /* ACLs should be enabled by default (b=13829) */
4418 m->mdt_opts.mo_acl = 1;
4419 LCONSOLE_INFO("Enabling ACL\n");
4421 m->mdt_opts.mo_acl = 0;
4422 LCONSOLE_INFO("Disabling ACL\n");
4431 while (*p && *p != ',')
4435 if ((len == sizeof("user_xattr") - 1) &&
4436 (memcmp(options, "user_xattr", len) == 0)) {
4437 m->mdt_opts.mo_user_xattr = 1;
4438 LCONSOLE_INFO("Enabling user_xattr\n");
4439 } else if ((len == sizeof("nouser_xattr") - 1) &&
4440 (memcmp(options, "nouser_xattr", len) == 0)) {
4441 m->mdt_opts.mo_user_xattr = 0;
4442 LCONSOLE_INFO("Disabling user_xattr\n");
4443 } else if ((len == sizeof("noacl") - 1) &&
4444 (memcmp(options, "noacl", len) == 0)) {
4445 m->mdt_opts.mo_acl = 0;
4446 LCONSOLE_INFO("Disabling ACL\n");
4453 int mdt_postrecov(const struct lu_env *, struct mdt_device *);
4455 static int mdt_init0(const struct lu_env *env, struct mdt_device *m,
4456 struct lu_device_type *ldt, struct lustre_cfg *cfg)
4458 struct mdt_thread_info *info;
4459 struct obd_device *obd;
4460 const char *dev = lustre_cfg_string(cfg, 0);
4461 const char *num = lustre_cfg_string(cfg, 2);
4462 struct lustre_mount_info *lmi = NULL;
4463 struct lustre_sb_info *lsi;
4464 struct lustre_disk_data *ldd;
4466 struct md_site *mite;
4467 const char *identity_upcall = "NONE";
4468 #ifdef HAVE_QUOTA_SUPPORT
4469 struct md_device *next;
4475 md_device_init(&m->mdt_md_dev, ldt);
4477 * Environment (env) might be missing mdt_thread_key values at that
4478 * point, if device is allocated when mdt_thread_key is in QUIESCENT
4481 * Usually device allocation path doesn't use module key values, but
4482 * mdt has to do a lot of work here, so allocate key value.
4484 rc = lu_env_refill((struct lu_env *)env);
4488 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
4489 LASSERT(info != NULL);
4491 obd = class_name2obd(dev);
4492 LASSERT(obd != NULL);
4494 m->mdt_max_mdsize = MAX_MD_SIZE;
4495 m->mdt_max_cookiesize = sizeof(struct llog_cookie);
4496 m->mdt_som_conf = 0;
4498 m->mdt_opts.mo_user_xattr = 0;
4499 m->mdt_opts.mo_acl = 0;
4500 m->mdt_opts.mo_cos = MDT_COS_DEFAULT;
4501 lmi = server_get_mount_2(dev);
4503 CERROR("Cannot get mount info for %s!\n", dev);
4506 lsi = s2lsi(lmi->lmi_sb);
4507 fsoptions_to_mdt_flags(m, lsi->lsi_lmd->lmd_opts);
4508 /* CMD is supported only in IAM mode */
4511 node_id = simple_strtol(num, NULL, 10);
4512 if (!(ldd->ldd_flags & LDD_F_IAM_DIR) && node_id) {
4513 CERROR("CMD Operation not allowed in IOP mode\n");
4514 GOTO(err_lmi, rc = -EINVAL);
4516 /* Read recovery timeouts */
4517 if (lsi->lsi_lmd && lsi->lsi_lmd->lmd_recovery_time_soft)
4518 obd->obd_recovery_timeout =
4519 lsi->lsi_lmd->lmd_recovery_time_soft;
4521 if (lsi->lsi_lmd && lsi->lsi_lmd->lmd_recovery_time_hard)
4522 obd->obd_recovery_time_hard =
4523 lsi->lsi_lmd->lmd_recovery_time_hard;
4526 cfs_rwlock_init(&m->mdt_sptlrpc_lock);
4527 sptlrpc_rule_set_init(&m->mdt_sptlrpc_rset);
4529 cfs_spin_lock_init(&m->mdt_ioepoch_lock);
4530 m->mdt_opts.mo_compat_resname = 0;
4531 m->mdt_capa_timeout = CAPA_TIMEOUT;
4532 m->mdt_capa_alg = CAPA_HMAC_ALG_SHA1;
4533 m->mdt_ck_timeout = CAPA_KEY_TIMEOUT;
4534 m->mdt_squash_uid = 0;
4535 m->mdt_squash_gid = 0;
4536 CFS_INIT_LIST_HEAD(&m->mdt_nosquash_nids);
4537 m->mdt_nosquash_str = NULL;
4538 m->mdt_nosquash_strlen = 0;
4539 cfs_init_rwsem(&m->mdt_squash_sem);
4541 OBD_ALLOC_PTR(mite);
4543 GOTO(err_lmi, rc = -ENOMEM);
4547 m->mdt_md_dev.md_lu_dev.ld_ops = &mdt_lu_ops;
4548 m->mdt_md_dev.md_lu_dev.ld_obd = obd;
4549 /* set this lu_device to obd, because error handling need it */
4550 obd->obd_lu_dev = &m->mdt_md_dev.md_lu_dev;
4552 rc = lu_site_init(s, &m->mdt_md_dev.md_lu_dev);
4554 CERROR("Can't init lu_site, rc %d\n", rc);
4555 GOTO(err_free_site, rc);
4558 rc = mdt_procfs_init(m, dev);
4560 CERROR("Can't init MDT lprocfs, rc %d\n", rc);
4561 GOTO(err_fini_proc, rc);
4564 /* set server index */
4565 lu_site2md(s)->ms_node_id = node_id;
4567 /* failover is the default
4568 * FIXME: we do not failout mds0/mgs, which may cause some problems.
4569 * assumed whose ms_node_id == 0 XXX
4571 obd->obd_replayable = 1;
4572 /* No connection accepted until configurations will finish */
4573 obd->obd_no_conn = 1;
4575 if (cfg->lcfg_bufcount > 4 && LUSTRE_CFG_BUFLEN(cfg, 4) > 0) {
4576 char *str = lustre_cfg_string(cfg, 4);
4577 if (strchr(str, 'n')) {
4578 CWARN("%s: recovery disabled\n", obd->obd_name);
4579 obd->obd_replayable = 0;
4583 /* init the stack */
4584 rc = mdt_stack_init((struct lu_env *)env, m, cfg, lmi);
4586 CERROR("Can't init device stack, rc %d\n", rc);
4587 GOTO(err_fini_proc, rc);
4590 rc = lut_init(env, &m->mdt_lut, obd, m->mdt_bottom);
4592 GOTO(err_fini_stack, rc);
4594 rc = mdt_fld_init(env, obd->obd_name, m);
4598 rc = mdt_seq_init(env, obd->obd_name, m);
4600 GOTO(err_fini_fld, rc);
4602 snprintf(info->mti_u.ns_name, sizeof info->mti_u.ns_name,
4603 LUSTRE_MDT_NAME"-%p", m);
4604 m->mdt_namespace = ldlm_namespace_new(obd, info->mti_u.ns_name,
4605 LDLM_NAMESPACE_SERVER,
4606 LDLM_NAMESPACE_GREEDY);
4607 if (m->mdt_namespace == NULL)
4608 GOTO(err_fini_seq, rc = -ENOMEM);
4610 ldlm_register_intent(m->mdt_namespace, mdt_intent_policy);
4611 /* set obd_namespace for compatibility with old code */
4612 obd->obd_namespace = m->mdt_namespace;
4614 /* XXX: to support suppgid for ACL, we enable identity_upcall
4615 * by default, otherwise, maybe got unexpected -EACCESS. */
4616 if (m->mdt_opts.mo_acl)
4617 identity_upcall = MDT_IDENTITY_UPCALL_PATH;
4619 m->mdt_identity_cache = upcall_cache_init(obd->obd_name, identity_upcall,
4620 &mdt_identity_upcall_cache_ops);
4621 if (IS_ERR(m->mdt_identity_cache)) {
4622 rc = PTR_ERR(m->mdt_identity_cache);
4623 m->mdt_identity_cache = NULL;
4624 GOTO(err_free_ns, rc);
4627 cfs_timer_init(&m->mdt_ck_timer, mdt_ck_timer_callback, m);
4629 rc = mdt_ck_thread_start(m);
4631 GOTO(err_free_ns, rc);
4633 rc = mdt_fs_setup(env, m, obd, lsi);
4637 rc = mdt_obd_llog_setup(obd, lsi);
4639 GOTO(err_fs_cleanup, rc);
4641 rc = mdt_llog_ctxt_clone(env, m, LLOG_CHANGELOG_ORIG_CTXT);
4643 GOTO(err_llog_cleanup, rc);
4645 mdt_adapt_sptlrpc_conf(obd, 1);
4647 #ifdef HAVE_QUOTA_SUPPORT
4648 next = m->mdt_child;
4649 rc = next->md_ops->mdo_quota.mqo_setup(env, next, lmi->lmi_mnt);
4651 GOTO(err_llog_cleanup, rc);
4654 server_put_mount_2(dev, lmi->lmi_mnt);
4657 target_recovery_init(&m->mdt_lut, mdt_recovery_handle);
4659 rc = mdt_start_ptlrpc_service(m);
4661 GOTO(err_recovery, rc);
4663 ping_evictor_start();
4665 rc = lu_site_init_finish(s);
4667 GOTO(err_stop_service, rc);
4669 if (obd->obd_recovering == 0)
4670 mdt_postrecov(env, m);
4672 mdt_init_capa_ctxt(env, m);
4674 /* Reduce the initial timeout on an MDS because it doesn't need such
4675 * a long timeout as an OST does. Adaptive timeouts will adjust this
4676 * value appropriately. */
4677 if (ldlm_timeout == LDLM_TIMEOUT_DEFAULT)
4678 ldlm_timeout = MDS_LDLM_TIMEOUT_DEFAULT;
4683 ping_evictor_stop();
4684 mdt_stop_ptlrpc_service(m);
4686 target_recovery_fini(obd);
4687 #ifdef HAVE_QUOTA_SUPPORT
4688 next->md_ops->mdo_quota.mqo_cleanup(env, next);
4691 mdt_llog_ctxt_unclone(env, m, LLOG_CHANGELOG_ORIG_CTXT);
4692 mdt_obd_llog_cleanup(obd);
4694 mdt_fs_cleanup(env, m);
4696 cfs_timer_disarm(&m->mdt_ck_timer);
4697 mdt_ck_thread_stop(m);
4699 upcall_cache_cleanup(m->mdt_identity_cache);
4700 m->mdt_identity_cache = NULL;
4701 ldlm_namespace_free(m->mdt_namespace, NULL, 0);
4702 obd->obd_namespace = m->mdt_namespace = NULL;
4704 mdt_seq_fini(env, m);
4706 mdt_fld_fini(env, m);
4708 lut_fini(env, &m->mdt_lut);
4710 mdt_stack_fini(env, m, md2lu_dev(m->mdt_child));
4718 server_put_mount_2(dev, lmi->lmi_mnt);
4722 /* used by MGS to process specific configurations */
4723 static int mdt_process_config(const struct lu_env *env,
4724 struct lu_device *d, struct lustre_cfg *cfg)
4726 struct mdt_device *m = mdt_dev(d);
4727 struct md_device *md_next = m->mdt_child;
4728 struct lu_device *next = md2lu_dev(md_next);
4732 switch (cfg->lcfg_command) {
4734 struct lprocfs_static_vars lvars;
4735 struct obd_device *obd = d->ld_obd;
4738 * For interoperability between 1.8 and 2.0,
4739 * skip old "mdt.group_upcall" param.
4742 char *param = lustre_cfg_string(cfg, 1);
4743 if (param && !strncmp("mdt.group_upcall", param, 16)) {
4744 CWARN("For 1.8 interoperability, skip this"
4745 " mdt.group_upcall. It is obsolete\n");
4750 lprocfs_mdt_init_vars(&lvars);
4751 rc = class_process_proc_param(PARAM_MDT, lvars.obd_vars,
4753 if (rc > 0 || rc == -ENOSYS)
4754 /* we don't understand; pass it on */
4755 rc = next->ld_ops->ldo_process_config(env, next, cfg);
4760 * Add mdc hook to get first MDT uuid and connect it to
4761 * ls->controller to use for seq manager.
4763 rc = next->ld_ops->ldo_process_config(env, next, cfg);
4765 CERROR("Can't add mdc, rc %d\n", rc);
4767 rc = mdt_seq_init_cli(env, mdt_dev(d), cfg);
4770 /* others are passed further */
4771 rc = next->ld_ops->ldo_process_config(env, next, cfg);
4777 static struct lu_object *mdt_object_alloc(const struct lu_env *env,
4778 const struct lu_object_header *hdr,
4779 struct lu_device *d)
4781 struct mdt_object *mo;
4787 struct lu_object *o;
4788 struct lu_object_header *h;
4790 o = &mo->mot_obj.mo_lu;
4791 h = &mo->mot_header;
4792 lu_object_header_init(h);
4793 lu_object_init(o, h, d);
4794 lu_object_add_top(h, o);
4795 o->lo_ops = &mdt_obj_ops;
4796 cfs_sema_init(&mo->mot_ioepoch_sem, 1);
4802 static int mdt_object_init(const struct lu_env *env, struct lu_object *o,
4803 const struct lu_object_conf *unused)
4805 struct mdt_device *d = mdt_dev(o->lo_dev);
4806 struct lu_device *under;
4807 struct lu_object *below;
4811 CDEBUG(D_INFO, "object init, fid = "DFID"\n",
4812 PFID(lu_object_fid(o)));
4814 under = &d->mdt_child->md_lu_dev;
4815 below = under->ld_ops->ldo_object_alloc(env, o->lo_header, under);
4816 if (below != NULL) {
4817 lu_object_add(o, below);
4824 static void mdt_object_free(const struct lu_env *env, struct lu_object *o)
4826 struct mdt_object *mo = mdt_obj(o);
4827 struct lu_object_header *h;
4831 CDEBUG(D_INFO, "object free, fid = "DFID"\n",
4832 PFID(lu_object_fid(o)));
4835 lu_object_header_fini(h);
4840 static int mdt_object_print(const struct lu_env *env, void *cookie,
4841 lu_printer_t p, const struct lu_object *o)
4843 struct mdt_object *mdto = mdt_obj((struct lu_object *)o);
4844 return (*p)(env, cookie, LUSTRE_MDT_NAME"-object@%p(ioepoch="LPU64" "
4845 "flags="LPX64", epochcount=%d, writecount=%d)",
4846 mdto, mdto->mot_ioepoch, mdto->mot_flags,
4847 mdto->mot_ioepoch_count, mdto->mot_writecount);
4850 static const struct lu_device_operations mdt_lu_ops = {
4851 .ldo_object_alloc = mdt_object_alloc,
4852 .ldo_process_config = mdt_process_config,
4855 static const struct lu_object_operations mdt_obj_ops = {
4856 .loo_object_init = mdt_object_init,
4857 .loo_object_free = mdt_object_free,
4858 .loo_object_print = mdt_object_print
4861 static int mdt_obd_set_info_async(struct obd_export *exp,
4862 __u32 keylen, void *key,
4863 __u32 vallen, void *val,
4864 struct ptlrpc_request_set *set)
4866 struct obd_device *obd = exp->exp_obd;
4872 if (KEY_IS(KEY_SPTLRPC_CONF)) {
4873 rc = mdt_adapt_sptlrpc_conf(obd, 0);
4880 /* mds_connect_internal */
4881 static int mdt_connect_internal(struct obd_export *exp,
4882 struct mdt_device *mdt,
4883 struct obd_connect_data *data)
4886 data->ocd_connect_flags &= MDT_CONNECT_SUPPORTED;
4887 data->ocd_ibits_known &= MDS_INODELOCK_FULL;
4889 /* If no known bits (which should not happen, probably,
4890 as everybody should support LOOKUP and UPDATE bits at least)
4891 revert to compat mode with plain locks. */
4892 if (!data->ocd_ibits_known &&
4893 data->ocd_connect_flags & OBD_CONNECT_IBITS)
4894 data->ocd_connect_flags &= ~OBD_CONNECT_IBITS;
4896 if (!mdt->mdt_opts.mo_acl)
4897 data->ocd_connect_flags &= ~OBD_CONNECT_ACL;
4899 if (!mdt->mdt_opts.mo_user_xattr)
4900 data->ocd_connect_flags &= ~OBD_CONNECT_XATTR;
4902 if (!mdt->mdt_som_conf)
4903 data->ocd_connect_flags &= ~OBD_CONNECT_SOM;
4905 cfs_spin_lock(&exp->exp_lock);
4906 exp->exp_connect_flags = data->ocd_connect_flags;
4907 cfs_spin_unlock(&exp->exp_lock);
4908 data->ocd_version = LUSTRE_VERSION_CODE;
4909 exp->exp_mdt_data.med_ibits_known = data->ocd_ibits_known;
4913 if (mdt->mdt_opts.mo_acl &&
4914 ((exp->exp_connect_flags & OBD_CONNECT_ACL) == 0)) {
4915 CWARN("%s: MDS requires ACL support but client does not\n",
4916 mdt->mdt_md_dev.md_lu_dev.ld_obd->obd_name);
4921 if ((exp->exp_connect_flags & OBD_CONNECT_FID) == 0) {
4922 CWARN("%s: MDS requires FID support, but client not\n",
4923 mdt->mdt_md_dev.md_lu_dev.ld_obd->obd_name);
4927 if (mdt->mdt_som_conf && !exp_connect_som(exp) &&
4928 !(exp->exp_connect_flags & OBD_CONNECT_MDS_MDS)) {
4929 CWARN("%s: MDS has SOM enabled, but client does not support "
4930 "it\n", mdt->mdt_md_dev.md_lu_dev.ld_obd->obd_name);
4937 static int mdt_connect_check_sptlrpc(struct mdt_device *mdt,
4938 struct obd_export *exp,
4939 struct ptlrpc_request *req)
4941 struct sptlrpc_flavor flvr;
4944 if (exp->exp_flvr.sf_rpc == SPTLRPC_FLVR_INVALID) {
4945 cfs_read_lock(&mdt->mdt_sptlrpc_lock);
4946 sptlrpc_target_choose_flavor(&mdt->mdt_sptlrpc_rset,
4950 cfs_read_unlock(&mdt->mdt_sptlrpc_lock);
4952 cfs_spin_lock(&exp->exp_lock);
4954 exp->exp_sp_peer = req->rq_sp_from;
4955 exp->exp_flvr = flvr;
4957 if (exp->exp_flvr.sf_rpc != SPTLRPC_FLVR_ANY &&
4958 exp->exp_flvr.sf_rpc != req->rq_flvr.sf_rpc) {
4959 CERROR("unauthorized rpc flavor %x from %s, "
4960 "expect %x\n", req->rq_flvr.sf_rpc,
4961 libcfs_nid2str(req->rq_peer.nid),
4962 exp->exp_flvr.sf_rpc);
4966 cfs_spin_unlock(&exp->exp_lock);
4968 if (exp->exp_sp_peer != req->rq_sp_from) {
4969 CERROR("RPC source %s doesn't match %s\n",
4970 sptlrpc_part2name(req->rq_sp_from),
4971 sptlrpc_part2name(exp->exp_sp_peer));
4974 rc = sptlrpc_target_export_check(exp, req);
4981 /* mds_connect copy */
4982 static int mdt_obd_connect(const struct lu_env *env,
4983 struct obd_export **exp, struct obd_device *obd,
4984 struct obd_uuid *cluuid,
4985 struct obd_connect_data *data,
4988 struct mdt_thread_info *info;
4989 struct obd_export *lexp;
4990 struct lustre_handle conn = { 0 };
4991 struct mdt_device *mdt;
4992 struct ptlrpc_request *req;
4996 LASSERT(env != NULL);
4997 if (!exp || !obd || !cluuid)
5000 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
5001 req = info->mti_pill->rc_req;
5002 mdt = mdt_dev(obd->obd_lu_dev);
5004 rc = class_connect(&conn, obd, cluuid);
5008 lexp = class_conn2export(&conn);
5009 LASSERT(lexp != NULL);
5011 rc = mdt_connect_check_sptlrpc(mdt, lexp, req);
5015 rc = mdt_connect_internal(lexp, mdt, data);
5017 struct mdt_thread_info *mti;
5018 struct lsd_client_data *lcd = lexp->exp_target_data.ted_lcd;
5020 mti = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
5021 LASSERT(mti != NULL);
5022 mti->mti_exp = lexp;
5023 memcpy(lcd->lcd_uuid, cluuid, sizeof lcd->lcd_uuid);
5024 rc = mdt_client_new(env, mdt);
5026 mdt_export_stats_init(obd, lexp, localdata);
5031 class_disconnect(lexp);
5040 static int mdt_obd_reconnect(const struct lu_env *env,
5041 struct obd_export *exp, struct obd_device *obd,
5042 struct obd_uuid *cluuid,
5043 struct obd_connect_data *data,
5046 struct mdt_thread_info *info;
5047 struct mdt_device *mdt;
5048 struct ptlrpc_request *req;
5052 if (exp == NULL || obd == NULL || cluuid == NULL)
5055 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
5056 req = info->mti_pill->rc_req;
5057 mdt = mdt_dev(obd->obd_lu_dev);
5059 rc = mdt_connect_check_sptlrpc(mdt, exp, req);
5063 rc = mdt_connect_internal(exp, mdt_dev(obd->obd_lu_dev), data);
5065 mdt_export_stats_init(obd, exp, localdata);
5069 static int mdt_export_cleanup(struct obd_export *exp)
5071 struct mdt_export_data *med = &exp->exp_mdt_data;
5072 struct obd_device *obd = exp->exp_obd;
5073 struct mdt_device *mdt;
5074 struct mdt_thread_info *info;
5076 CFS_LIST_HEAD(closing_list);
5077 struct mdt_file_data *mfd, *n;
5081 cfs_spin_lock(&med->med_open_lock);
5082 while (!cfs_list_empty(&med->med_open_head)) {
5083 cfs_list_t *tmp = med->med_open_head.next;
5084 mfd = cfs_list_entry(tmp, struct mdt_file_data, mfd_list);
5086 /* Remove mfd handle so it can't be found again.
5087 * We are consuming the mfd_list reference here. */
5088 class_handle_unhash(&mfd->mfd_handle);
5089 cfs_list_move_tail(&mfd->mfd_list, &closing_list);
5091 cfs_spin_unlock(&med->med_open_lock);
5092 mdt = mdt_dev(obd->obd_lu_dev);
5093 LASSERT(mdt != NULL);
5095 rc = lu_env_init(&env, LCT_MD_THREAD);
5099 info = lu_context_key_get(&env.le_ctx, &mdt_thread_key);
5100 LASSERT(info != NULL);
5101 memset(info, 0, sizeof *info);
5102 info->mti_env = &env;
5103 info->mti_mdt = mdt;
5104 info->mti_exp = exp;
5106 if (!cfs_list_empty(&closing_list)) {
5107 struct md_attr *ma = &info->mti_attr;
5111 lmm_size = mdt->mdt_max_mdsize;
5112 OBD_ALLOC(ma->ma_lmm, lmm_size);
5113 if (ma->ma_lmm == NULL)
5114 GOTO(out_lmm, rc = -ENOMEM);
5116 cookie_size = mdt->mdt_max_cookiesize;
5117 OBD_ALLOC(ma->ma_cookie, cookie_size);
5118 if (ma->ma_cookie == NULL)
5119 GOTO(out_cookie, rc = -ENOMEM);
5121 /* Close any open files (which may also cause orphan unlinking). */
5122 cfs_list_for_each_entry_safe(mfd, n, &closing_list, mfd_list) {
5123 cfs_list_del_init(&mfd->mfd_list);
5124 memset(&ma->ma_attr, 0, sizeof(ma->ma_attr));
5125 ma->ma_lmm_size = lmm_size;
5126 ma->ma_cookie_size = cookie_size;
5128 /* It is not for setattr, just tell MDD to send
5129 * DESTROY RPC to OSS if needed */
5130 ma->ma_attr_flags = MDS_CLOSE_CLEANUP;
5131 ma->ma_valid = MA_FLAGS;
5132 mdt_mfd_close(info, mfd);
5134 OBD_FREE(ma->ma_cookie, cookie_size);
5135 ma->ma_cookie = NULL;
5137 OBD_FREE(ma->ma_lmm, lmm_size);
5141 info->mti_mdt = NULL;
5142 /* cleanup client slot early */
5143 /* Do not erase record for recoverable client. */
5144 if (!obd->obd_fail || exp->exp_failed)
5145 mdt_client_del(&env, mdt);
5151 static int mdt_obd_disconnect(struct obd_export *exp)
5157 class_export_get(exp);
5159 rc = server_disconnect_export(exp);
5161 CDEBUG(D_IOCTL, "server disconnect error: %d\n", rc);
5163 rc = mdt_export_cleanup(exp);
5164 class_export_put(exp);
5168 /* FIXME: Can we avoid using these two interfaces? */
5169 static int mdt_init_export(struct obd_export *exp)
5171 struct mdt_export_data *med = &exp->exp_mdt_data;
5175 CFS_INIT_LIST_HEAD(&med->med_open_head);
5176 cfs_spin_lock_init(&med->med_open_lock);
5177 cfs_sema_init(&med->med_idmap_sem, 1);
5178 med->med_idmap = NULL;
5179 cfs_spin_lock(&exp->exp_lock);
5180 exp->exp_connecting = 1;
5181 cfs_spin_unlock(&exp->exp_lock);
5182 rc = lut_client_alloc(exp);
5184 rc = ldlm_init_export(exp);
5187 CERROR("Error %d while initializing export\n", rc);
5191 static int mdt_destroy_export(struct obd_export *exp)
5193 struct mdt_export_data *med;
5197 med = &exp->exp_mdt_data;
5198 if (exp_connect_rmtclient(exp))
5199 mdt_cleanup_idmap(&exp->exp_mdt_data);
5201 target_destroy_export(exp);
5202 ldlm_destroy_export(exp);
5203 lut_client_free(exp);
5205 LASSERT(cfs_list_empty(&exp->exp_outstanding_replies));
5206 LASSERT(cfs_list_empty(&exp->exp_mdt_data.med_open_head));
5207 if (obd_uuid_equals(&exp->exp_client_uuid, &exp->exp_obd->obd_uuid))
5213 static void mdt_allow_cli(struct mdt_device *m, unsigned int flag)
5215 if (flag & CONFIG_LOG)
5216 cfs_set_bit(MDT_FL_CFGLOG, &m->mdt_state);
5218 /* also notify active event */
5219 if (flag & CONFIG_SYNC)
5220 cfs_set_bit(MDT_FL_SYNCED, &m->mdt_state);
5222 if (cfs_test_bit(MDT_FL_CFGLOG, &m->mdt_state) &&
5223 cfs_test_bit(MDT_FL_SYNCED, &m->mdt_state)) {
5224 struct obd_device *obd = m->mdt_md_dev.md_lu_dev.ld_obd;
5226 /* Open for clients */
5227 if (obd->obd_no_conn) {
5228 cfs_spin_lock_bh(&obd->obd_processing_task_lock);
5229 obd->obd_no_conn = 0;
5230 cfs_spin_unlock_bh(&obd->obd_processing_task_lock);
5235 static int mdt_upcall(const struct lu_env *env, struct md_device *md,
5236 enum md_upcall_event ev, void *data)
5238 struct mdt_device *m = mdt_dev(&md->md_lu_dev);
5239 struct md_device *next = m->mdt_child;
5240 struct mdt_thread_info *mti;
5246 rc = next->md_ops->mdo_maxsize_get(env, next,
5248 &m->mdt_max_cookiesize);
5249 CDEBUG(D_INFO, "get max mdsize %d max cookiesize %d\n",
5250 m->mdt_max_mdsize, m->mdt_max_cookiesize);
5251 mdt_allow_cli(m, CONFIG_SYNC);
5254 m->mdt_lut.lut_obd->u.obt.obt_mount_count;
5257 mti = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
5258 mti->mti_no_need_trans = 1;
5259 CDEBUG(D_INFO, "disable mdt trans for this thread\n");
5262 /* Check that MDT is not yet configured */
5263 LASSERT(!cfs_test_bit(MDT_FL_CFGLOG, &m->mdt_state));
5265 #ifdef HAVE_QUOTA_SUPPORT
5267 if (md->md_lu_dev.ld_obd->obd_recovering == 0 &&
5268 likely(md->md_lu_dev.ld_obd->obd_stopping == 0))
5269 next->md_ops->mdo_quota.mqo_recovery(env, next);
5273 CERROR("invalid event\n");
5280 static int mdt_obd_notify(struct obd_device *host,
5281 struct obd_device *watched,
5282 enum obd_notify_event ev, void *data)
5284 struct mdt_device *mdt = mdt_dev(host->obd_lu_dev);
5285 #ifdef HAVE_QUOTA_SUPPORT
5286 struct md_device *next = mdt->mdt_child;
5291 case OBD_NOTIFY_CONFIG:
5292 mdt_allow_cli(mdt, (unsigned long)data);
5294 #ifdef HAVE_QUOTA_SUPPORT
5295 /* quota_type has been processed, we can now handle
5296 * incoming quota requests */
5297 next->md_ops->mdo_quota.mqo_notify(NULL, next);
5301 CDEBUG(D_INFO, "Unhandled notification %#x\n", ev);
5306 static int mdt_rpc_fid2path(struct mdt_thread_info *info, void *key,
5307 void *val, int vallen)
5309 struct mdt_device *mdt = mdt_dev(info->mti_exp->exp_obd->obd_lu_dev);
5310 struct getinfo_fid2path *fpout, *fpin;
5313 fpin = key + cfs_size_round(sizeof(KEY_FID2PATH));
5316 if (ptlrpc_req_need_swab(info->mti_pill->rc_req))
5317 lustre_swab_fid2path(fpin);
5319 memcpy(fpout, fpin, sizeof(*fpin));
5320 if (fpout->gf_pathlen != vallen - sizeof(*fpin))
5323 rc = mdt_fid2path(info->mti_env, mdt, fpout);
5327 static int mdt_fid2path(const struct lu_env *env, struct mdt_device *mdt,
5328 struct getinfo_fid2path *fp)
5330 struct mdt_object *obj;
5334 CDEBUG(D_IOCTL, "path get "DFID" from "LPU64" #%d\n",
5335 PFID(&fp->gf_fid), fp->gf_recno, fp->gf_linkno);
5337 if (!fid_is_sane(&fp->gf_fid))
5340 obj = mdt_object_find(env, mdt, &fp->gf_fid);
5341 if (obj == NULL || IS_ERR(obj)) {
5342 CDEBUG(D_IOCTL, "no object "DFID": %ld\n",PFID(&fp->gf_fid),
5347 rc = lu_object_exists(&obj->mot_obj.mo_lu);
5353 mdt_object_put(env, obj);
5354 CDEBUG(D_IOCTL, "nonlocal object "DFID": %d\n",
5355 PFID(&fp->gf_fid), rc);
5359 rc = mo_path(env, md_object_next(&obj->mot_obj), fp->gf_path,
5360 fp->gf_pathlen, &fp->gf_recno, &fp->gf_linkno);
5361 mdt_object_put(env, obj);
5366 static int mdt_get_info(struct mdt_thread_info *info)
5368 struct ptlrpc_request *req = mdt_info_req(info);
5376 key = req_capsule_client_get(info->mti_pill, &RMF_GETINFO_KEY);
5378 CDEBUG(D_IOCTL, "No GETINFO key");
5381 keylen = req_capsule_get_size(info->mti_pill, &RMF_GETINFO_KEY,
5384 vallen = req_capsule_client_get(info->mti_pill, &RMF_GETINFO_VALLEN);
5385 if (vallen == NULL) {
5386 CDEBUG(D_IOCTL, "Unable to get RMF_GETINFO_VALLEN buffer");
5390 req_capsule_set_size(info->mti_pill, &RMF_GETINFO_VAL, RCL_SERVER,
5392 rc = req_capsule_server_pack(info->mti_pill);
5393 valout = req_capsule_server_get(info->mti_pill, &RMF_GETINFO_VAL);
5394 if (valout == NULL) {
5395 CDEBUG(D_IOCTL, "Unable to get get-info RPC out buffer");
5399 if (KEY_IS(KEY_FID2PATH))
5400 rc = mdt_rpc_fid2path(info, key, valout, *vallen);
5404 lustre_msg_set_status(req->rq_repmsg, rc);
5409 /* Pass the ioc down */
5410 static int mdt_ioc_child(struct lu_env *env, struct mdt_device *mdt,
5411 unsigned int cmd, int len, void *data)
5413 struct lu_context ioctl_session;
5414 struct md_device *next = mdt->mdt_child;
5418 rc = lu_context_init(&ioctl_session, LCT_SESSION);
5421 ioctl_session.lc_thread = (struct ptlrpc_thread *)cfs_current();
5422 lu_context_enter(&ioctl_session);
5423 env->le_ses = &ioctl_session;
5425 LASSERT(next->md_ops->mdo_iocontrol);
5426 rc = next->md_ops->mdo_iocontrol(env, next, cmd, len, data);
5428 lu_context_exit(&ioctl_session);
5429 lu_context_fini(&ioctl_session);
5433 static int mdt_ioc_version_get(struct mdt_thread_info *mti, void *karg)
5435 struct obd_ioctl_data *data = karg;
5436 struct lu_fid *fid = (struct lu_fid *)data->ioc_inlbuf1;
5438 struct mdt_object *obj;
5439 struct mdt_lock_handle *lh;
5442 CDEBUG(D_IOCTL, "getting version for "DFID"\n", PFID(fid));
5443 if (!fid_is_sane(fid))
5446 lh = &mti->mti_lh[MDT_LH_PARENT];
5447 mdt_lock_reg_init(lh, LCK_CR);
5449 obj = mdt_object_find_lock(mti, fid, lh, MDS_INODELOCK_UPDATE);
5451 RETURN(PTR_ERR(obj));
5453 rc = mdt_object_exists(obj);
5457 * before calling version get the correct MDS should be
5458 * fid, this is error to find remote object here
5460 CERROR("nonlocal object "DFID"\n", PFID(fid));
5462 version = mo_version_get(mti->mti_env, mdt_object_child(obj));
5463 *(__u64 *)data->ioc_inlbuf2 = version;
5466 mdt_object_unlock_put(mti, obj, lh, 1);
5470 /* ioctls on obd dev */
5471 static int mdt_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
5472 void *karg, void *uarg)
5475 struct obd_device *obd = exp->exp_obd;
5476 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
5477 struct dt_device *dt = mdt->mdt_bottom;
5481 CDEBUG(D_IOCTL, "handling ioctl cmd %#x\n", cmd);
5482 rc = lu_env_init(&env, LCT_MD_THREAD);
5488 rc = mdt_device_sync(&env, mdt);
5490 case OBD_IOC_SET_READONLY:
5491 dt->dd_ops->dt_ro(&env, dt);
5493 case OBD_IOC_ABORT_RECOVERY:
5494 CERROR("Aborting recovery for device %s\n", obd->obd_name);
5495 target_stop_recovery_thread(obd);
5498 case OBD_IOC_CHANGELOG_REG:
5499 case OBD_IOC_CHANGELOG_DEREG:
5500 case OBD_IOC_CHANGELOG_CLEAR:
5501 rc = mdt_ioc_child(&env, mdt, cmd, len, karg);
5503 case OBD_IOC_GET_OBJ_VERSION: {
5504 struct mdt_thread_info *mti;
5505 mti = lu_context_key_get(&env.le_ctx, &mdt_thread_key);
5506 memset(mti, 0, sizeof *mti);
5507 mti->mti_env = &env;
5511 rc = mdt_ioc_version_get(mti, karg);
5515 CERROR("Not supported cmd = %d for device %s\n",
5516 cmd, obd->obd_name);
5524 int mdt_postrecov(const struct lu_env *env, struct mdt_device *mdt)
5526 struct lu_device *ld = md2lu_dev(mdt->mdt_child);
5527 struct obd_device *obd = mdt2obd_dev(mdt);
5528 #ifdef HAVE_QUOTA_SUPPORT
5529 struct md_device *next = mdt->mdt_child;
5534 rc = ld->ld_ops->ldo_recovery_complete(env, ld);
5535 #ifdef HAVE_QUOTA_SUPPORT
5536 if (likely(obd->obd_stopping == 0))
5537 next->md_ops->mdo_quota.mqo_recovery(env, next);
5542 int mdt_obd_postrecov(struct obd_device *obd)
5547 rc = lu_env_init(&env, LCT_MD_THREAD);
5550 rc = mdt_postrecov(&env, mdt_dev(obd->obd_lu_dev));
5556 * Send a copytool req to a client
5557 * Note this sends a request RPC from a server (MDT) to a client (MDC),
5558 * backwards of normal comms.
5560 int mdt_hsm_copytool_send(struct obd_export *exp)
5563 struct hsm_action_list *hal;
5564 struct hsm_action_item *hai;
5568 CWARN("%s: writing to mdc at %s\n", exp->exp_obd->obd_name,
5569 libcfs_nid2str(exp->exp_connection->c_peer.nid));
5571 len = sizeof(*lh) + sizeof(*hal) + MTI_NAME_MAXLEN +
5572 /* for mockup below */ 2 * cfs_size_round(sizeof(*hai));
5577 lh->kuc_magic = KUC_MAGIC;
5578 lh->kuc_transport = KUC_TRANSPORT_HSM;
5579 lh->kuc_msgtype = HMT_ACTION_LIST;
5580 lh->kuc_msglen = len;
5582 hal = (struct hsm_action_list *)(lh + 1);
5583 hal->hal_version = HAL_VERSION;
5584 hal->hal_archive_num = 1;
5585 obd_uuid2fsname(hal->hal_fsname, exp->exp_obd->obd_name,
5588 /* mock up an action list */
5590 hai = hai_zero(hal);
5591 hai->hai_action = HSMA_ARCHIVE;
5592 hai->hai_fid.f_oid = 0xA00A;
5593 hai->hai_len = sizeof(*hai);
5594 hai = hai_next(hai);
5595 hai->hai_action = HSMA_RESTORE;
5596 hai->hai_fid.f_oid = 0xB00B;
5597 hai->hai_len = sizeof(*hai);
5599 /* Uses the ldlm reverse import; this rpc will be seen by
5600 the ldlm_callback_handler */
5601 rc = do_set_info_async(exp->exp_imp_reverse,
5602 LDLM_SET_INFO, LUSTRE_OBD_VERSION,
5603 sizeof(KEY_HSM_COPYTOOL_SEND),
5604 KEY_HSM_COPYTOOL_SEND,
5612 static struct obd_ops mdt_obd_device_ops = {
5613 .o_owner = THIS_MODULE,
5614 .o_set_info_async = mdt_obd_set_info_async,
5615 .o_connect = mdt_obd_connect,
5616 .o_reconnect = mdt_obd_reconnect,
5617 .o_disconnect = mdt_obd_disconnect,
5618 .o_init_export = mdt_init_export,
5619 .o_destroy_export = mdt_destroy_export,
5620 .o_iocontrol = mdt_iocontrol,
5621 .o_postrecov = mdt_obd_postrecov,
5622 .o_notify = mdt_obd_notify
5625 static struct lu_device* mdt_device_fini(const struct lu_env *env,
5626 struct lu_device *d)
5628 struct mdt_device *m = mdt_dev(d);
5635 static struct lu_device *mdt_device_free(const struct lu_env *env,
5636 struct lu_device *d)
5638 struct mdt_device *m = mdt_dev(d);
5641 md_device_fini(&m->mdt_md_dev);
5646 static struct lu_device *mdt_device_alloc(const struct lu_env *env,
5647 struct lu_device_type *t,
5648 struct lustre_cfg *cfg)
5650 struct lu_device *l;
5651 struct mdt_device *m;
5657 l = &m->mdt_md_dev.md_lu_dev;
5658 rc = mdt_init0(env, m, t, cfg);
5660 mdt_device_free(env, l);
5664 md_upcall_init(&m->mdt_md_dev, mdt_upcall);
5666 l = ERR_PTR(-ENOMEM);
5670 /* context key constructor/destructor: mdt_key_init, mdt_key_fini */
5671 LU_KEY_INIT_FINI(mdt, struct mdt_thread_info);
5673 /* context key: mdt_thread_key */
5674 LU_CONTEXT_KEY_DEFINE(mdt, LCT_MD_THREAD);
5676 /* context key constructor/destructor: mdt_txn_key_init, mdt_txn_key_fini */
5677 LU_KEY_INIT_FINI(mdt_txn, struct mdt_txn_info);
5679 struct lu_context_key mdt_txn_key = {
5680 .lct_tags = LCT_TX_HANDLE,
5681 .lct_init = mdt_txn_key_init,
5682 .lct_fini = mdt_txn_key_fini
5685 struct md_ucred *mdt_ucred(const struct mdt_thread_info *info)
5687 return md_ucred(info->mti_env);
5691 * Enable/disable COS (Commit On Sharing).
5693 * Set/Clear the COS flag in mdt options.
5695 * \param mdt mdt device
5696 * \param val 0 disables COS, other values enable COS
5698 void mdt_enable_cos(struct mdt_device *mdt, int val)
5703 mdt->mdt_opts.mo_cos = !!val;
5704 rc = lu_env_init(&env, LCT_MD_THREAD);
5705 if (unlikely(rc != 0)) {
5706 CWARN("lu_env initialization failed with rc = %d,"
5707 "cannot sync\n", rc);
5710 mdt_device_sync(&env, mdt);
5715 * Check COS (Commit On Sharing) status.
5717 * Return COS flag status.
5719 * \param mdt mdt device
5721 int mdt_cos_is_enabled(struct mdt_device *mdt)
5723 return mdt->mdt_opts.mo_cos != 0;
5726 /* type constructor/destructor: mdt_type_init, mdt_type_fini */
5727 LU_TYPE_INIT_FINI(mdt, &mdt_thread_key, &mdt_txn_key);
5729 static struct lu_device_type_operations mdt_device_type_ops = {
5730 .ldto_init = mdt_type_init,
5731 .ldto_fini = mdt_type_fini,
5733 .ldto_start = mdt_type_start,
5734 .ldto_stop = mdt_type_stop,
5736 .ldto_device_alloc = mdt_device_alloc,
5737 .ldto_device_free = mdt_device_free,
5738 .ldto_device_fini = mdt_device_fini
5741 static struct lu_device_type mdt_device_type = {
5742 .ldt_tags = LU_DEVICE_MD,
5743 .ldt_name = LUSTRE_MDT_NAME,
5744 .ldt_ops = &mdt_device_type_ops,
5745 .ldt_ctx_tags = LCT_MD_THREAD
5748 static struct lu_local_obj_desc mdt_last_recv = {
5749 .llod_name = LAST_RCVD,
5750 .llod_oid = MDT_LAST_RECV_OID,
5754 static int __init mdt_mod_init(void)
5756 struct lprocfs_static_vars lvars;
5759 llo_local_obj_register(&mdt_last_recv);
5761 if (mdt_num_threads > 0) {
5762 if (mdt_num_threads > MDT_MAX_THREADS)
5763 mdt_num_threads = MDT_MAX_THREADS;
5764 if (mdt_num_threads < MDT_MIN_THREADS)
5765 mdt_num_threads = MDT_MIN_THREADS;
5766 mdt_max_threads = mdt_min_threads = mdt_num_threads;
5768 mdt_max_threads = MDT_MAX_THREADS;
5769 mdt_min_threads = MDT_MIN_THREADS;
5770 if (mdt_min_threads < MDT_NUM_THREADS)
5771 mdt_min_threads = MDT_NUM_THREADS;
5774 lprocfs_mdt_init_vars(&lvars);
5775 rc = class_register_type(&mdt_obd_device_ops, NULL,
5776 lvars.module_vars, LUSTRE_MDT_NAME,
5782 static void __exit mdt_mod_exit(void)
5784 llo_local_obj_unregister(&mdt_last_recv);
5785 class_unregister_type(LUSTRE_MDT_NAME);
5789 #define DEF_HNDL(prefix, base, suffix, flags, opc, fn, fmt) \
5790 [prefix ## _ ## opc - prefix ## _ ## base] = { \
5792 .mh_fail_id = OBD_FAIL_ ## prefix ## _ ## opc ## suffix, \
5793 .mh_opc = prefix ## _ ## opc, \
5794 .mh_flags = flags, \
5799 #define DEF_MDT_HNDL(flags, name, fn, fmt) \
5800 DEF_HNDL(MDS, GETATTR, _NET, flags, name, fn, fmt)
5802 #define DEF_SEQ_HNDL(flags, name, fn, fmt) \
5803 DEF_HNDL(SEQ, QUERY, _NET, flags, name, fn, fmt)
5805 #define DEF_FLD_HNDL(flags, name, fn, fmt) \
5806 DEF_HNDL(FLD, QUERY, _NET, flags, name, fn, fmt)
5808 * Request with a format known in advance
5810 #define DEF_MDT_HNDL_F(flags, name, fn) \
5811 DEF_HNDL(MDS, GETATTR, _NET, flags, name, fn, &RQF_MDS_ ## name)
5813 #define DEF_SEQ_HNDL_F(flags, name, fn) \
5814 DEF_HNDL(SEQ, QUERY, _NET, flags, name, fn, &RQF_SEQ_ ## name)
5816 #define DEF_FLD_HNDL_F(flags, name, fn) \
5817 DEF_HNDL(FLD, QUERY, _NET, flags, name, fn, &RQF_FLD_ ## name)
5819 * Request with a format we do not yet know
5821 #define DEF_MDT_HNDL_0(flags, name, fn) \
5822 DEF_HNDL(MDS, GETATTR, _NET, flags, name, fn, NULL)
5824 static struct mdt_handler mdt_mds_ops[] = {
5825 DEF_MDT_HNDL_F(0, CONNECT, mdt_connect),
5826 DEF_MDT_HNDL_F(0, DISCONNECT, mdt_disconnect),
5827 DEF_MDT_HNDL (0, SET_INFO, mdt_set_info,
5829 DEF_MDT_HNDL_F(0, GET_INFO, mdt_get_info),
5830 DEF_MDT_HNDL_F(0 |HABEO_REFERO, GETSTATUS, mdt_getstatus),
5831 DEF_MDT_HNDL_F(HABEO_CORPUS, GETATTR, mdt_getattr),
5832 DEF_MDT_HNDL_F(HABEO_CORPUS|HABEO_REFERO, GETATTR_NAME, mdt_getattr_name),
5833 DEF_MDT_HNDL_F(HABEO_CORPUS, GETXATTR, mdt_getxattr),
5834 DEF_MDT_HNDL_F(0 |HABEO_REFERO, STATFS, mdt_statfs),
5835 DEF_MDT_HNDL_F(0 |MUTABOR, REINT, mdt_reint),
5836 DEF_MDT_HNDL_F(HABEO_CORPUS, CLOSE, mdt_close),
5837 DEF_MDT_HNDL_F(HABEO_CORPUS, DONE_WRITING, mdt_done_writing),
5838 DEF_MDT_HNDL_F(0 |HABEO_REFERO, PIN, mdt_pin),
5839 DEF_MDT_HNDL_0(0, SYNC, mdt_sync),
5840 DEF_MDT_HNDL_F(HABEO_CORPUS|HABEO_REFERO, IS_SUBDIR, mdt_is_subdir),
5841 #ifdef HAVE_QUOTA_SUPPORT
5842 DEF_MDT_HNDL_F(0, QUOTACHECK, mdt_quotacheck_handle),
5843 DEF_MDT_HNDL_F(0, QUOTACTL, mdt_quotactl_handle)
5847 #define DEF_OBD_HNDL(flags, name, fn) \
5848 DEF_HNDL(OBD, PING, _NET, flags, name, fn, NULL)
5851 static struct mdt_handler mdt_obd_ops[] = {
5852 DEF_OBD_HNDL(0, PING, mdt_obd_ping),
5853 DEF_OBD_HNDL(0, LOG_CANCEL, mdt_obd_log_cancel),
5854 DEF_OBD_HNDL(0, QC_CALLBACK, mdt_obd_qc_callback)
5857 #define DEF_DLM_HNDL_0(flags, name, fn) \
5858 DEF_HNDL(LDLM, ENQUEUE, , flags, name, fn, NULL)
5859 #define DEF_DLM_HNDL_F(flags, name, fn) \
5860 DEF_HNDL(LDLM, ENQUEUE, , flags, name, fn, &RQF_LDLM_ ## name)
5862 static struct mdt_handler mdt_dlm_ops[] = {
5863 DEF_DLM_HNDL_F(HABEO_CLAVIS, ENQUEUE, mdt_enqueue),
5864 DEF_DLM_HNDL_0(HABEO_CLAVIS, CONVERT, mdt_convert),
5865 DEF_DLM_HNDL_0(0, BL_CALLBACK, mdt_bl_callback),
5866 DEF_DLM_HNDL_0(0, CP_CALLBACK, mdt_cp_callback)
5869 #define DEF_LLOG_HNDL(flags, name, fn) \
5870 DEF_HNDL(LLOG, ORIGIN_HANDLE_CREATE, _NET, flags, name, fn, NULL)
5872 static struct mdt_handler mdt_llog_ops[] = {
5873 DEF_LLOG_HNDL(0, ORIGIN_HANDLE_CREATE, mdt_llog_create),
5874 DEF_LLOG_HNDL(0, ORIGIN_HANDLE_NEXT_BLOCK, mdt_llog_next_block),
5875 DEF_LLOG_HNDL(0, ORIGIN_HANDLE_READ_HEADER, mdt_llog_read_header),
5876 DEF_LLOG_HNDL(0, ORIGIN_HANDLE_WRITE_REC, NULL),
5877 DEF_LLOG_HNDL(0, ORIGIN_HANDLE_CLOSE, NULL),
5878 DEF_LLOG_HNDL(0, ORIGIN_CONNECT, NULL),
5879 DEF_LLOG_HNDL(0, CATINFO, NULL),
5880 DEF_LLOG_HNDL(0, ORIGIN_HANDLE_PREV_BLOCK, mdt_llog_prev_block),
5881 DEF_LLOG_HNDL(0, ORIGIN_HANDLE_DESTROY, mdt_llog_destroy),
5884 #define DEF_SEC_CTX_HNDL(name, fn) \
5885 DEF_HNDL(SEC_CTX, INIT, _NET, 0, name, fn, NULL)
5887 static struct mdt_handler mdt_sec_ctx_ops[] = {
5888 DEF_SEC_CTX_HNDL(INIT, mdt_sec_ctx_handle),
5889 DEF_SEC_CTX_HNDL(INIT_CONT, mdt_sec_ctx_handle),
5890 DEF_SEC_CTX_HNDL(FINI, mdt_sec_ctx_handle)
5893 static struct mdt_opc_slice mdt_regular_handlers[] = {
5895 .mos_opc_start = MDS_GETATTR,
5896 .mos_opc_end = MDS_LAST_OPC,
5897 .mos_hs = mdt_mds_ops
5900 .mos_opc_start = OBD_PING,
5901 .mos_opc_end = OBD_LAST_OPC,
5902 .mos_hs = mdt_obd_ops
5905 .mos_opc_start = LDLM_ENQUEUE,
5906 .mos_opc_end = LDLM_LAST_OPC,
5907 .mos_hs = mdt_dlm_ops
5910 .mos_opc_start = LLOG_ORIGIN_HANDLE_CREATE,
5911 .mos_opc_end = LLOG_LAST_OPC,
5912 .mos_hs = mdt_llog_ops
5915 .mos_opc_start = SEC_CTX_INIT,
5916 .mos_opc_end = SEC_LAST_OPC,
5917 .mos_hs = mdt_sec_ctx_ops
5924 static struct mdt_handler mdt_readpage_ops[] = {
5925 DEF_MDT_HNDL_F(0, CONNECT, mdt_connect),
5926 DEF_MDT_HNDL_F(HABEO_CORPUS|HABEO_REFERO, READPAGE, mdt_readpage),
5927 #ifdef HAVE_SPLIT_SUPPORT
5928 DEF_MDT_HNDL_F(HABEO_CORPUS|HABEO_REFERO, WRITEPAGE, mdt_writepage),
5932 * XXX: this is ugly and should be fixed one day, see mdc_close() for
5933 * detailed comments. --umka
5935 DEF_MDT_HNDL_F(HABEO_CORPUS, CLOSE, mdt_close),
5936 DEF_MDT_HNDL_F(HABEO_CORPUS, DONE_WRITING, mdt_done_writing),
5939 static struct mdt_opc_slice mdt_readpage_handlers[] = {
5941 .mos_opc_start = MDS_GETATTR,
5942 .mos_opc_end = MDS_LAST_OPC,
5943 .mos_hs = mdt_readpage_ops
5950 static struct mdt_handler mdt_xmds_ops[] = {
5951 DEF_MDT_HNDL_F(0, CONNECT, mdt_connect),
5952 DEF_MDT_HNDL_F(HABEO_CORPUS , GETATTR, mdt_getattr),
5953 DEF_MDT_HNDL_F(0 | MUTABOR , REINT, mdt_reint),
5954 DEF_MDT_HNDL_F(HABEO_CORPUS|HABEO_REFERO, IS_SUBDIR, mdt_is_subdir),
5957 static struct mdt_opc_slice mdt_xmds_handlers[] = {
5959 .mos_opc_start = MDS_GETATTR,
5960 .mos_opc_end = MDS_LAST_OPC,
5961 .mos_hs = mdt_xmds_ops
5964 .mos_opc_start = OBD_PING,
5965 .mos_opc_end = OBD_LAST_OPC,
5966 .mos_hs = mdt_obd_ops
5969 .mos_opc_start = SEC_CTX_INIT,
5970 .mos_opc_end = SEC_LAST_OPC,
5971 .mos_hs = mdt_sec_ctx_ops
5978 static struct mdt_handler mdt_seq_ops[] = {
5979 DEF_SEQ_HNDL_F(0, QUERY, (int (*)(struct mdt_thread_info *))seq_query)
5982 static struct mdt_opc_slice mdt_seq_handlers[] = {
5984 .mos_opc_start = SEQ_QUERY,
5985 .mos_opc_end = SEQ_LAST_OPC,
5986 .mos_hs = mdt_seq_ops
5993 static struct mdt_handler mdt_fld_ops[] = {
5994 DEF_FLD_HNDL_F(0, QUERY, (int (*)(struct mdt_thread_info *))fld_query)
5997 static struct mdt_opc_slice mdt_fld_handlers[] = {
5999 .mos_opc_start = FLD_QUERY,
6000 .mos_opc_end = FLD_LAST_OPC,
6001 .mos_hs = mdt_fld_ops
6008 MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");
6009 MODULE_DESCRIPTION("Lustre Meta-data Target ("LUSTRE_MDT_NAME")");
6010 MODULE_LICENSE("GPL");
6012 CFS_MODULE_PARM(mdt_num_threads, "ul", ulong, 0444,
6013 "number of mdt service threads to start");
6015 cfs_module(mdt, "0.2.0", mdt_mod_init, mdt_mod_exit);