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);
452 if (b->valid & OBD_MD_FLSIZE)
453 CDEBUG(D_VFSTRACE, DFID": returning size %llu\n",
454 PFID(fid), (unsigned long long)b->size);
457 static inline int mdt_body_has_lov(const struct lu_attr *la,
458 const struct mdt_body *body)
460 return ((S_ISREG(la->la_mode) && (body->valid & OBD_MD_FLEASIZE)) ||
461 (S_ISDIR(la->la_mode) && (body->valid & OBD_MD_FLDIREA )) );
464 static int mdt_getattr_internal(struct mdt_thread_info *info,
465 struct mdt_object *o, int ma_need)
467 struct md_object *next = mdt_object_child(o);
468 const struct mdt_body *reqbody = info->mti_body;
469 struct ptlrpc_request *req = mdt_info_req(info);
470 struct md_attr *ma = &info->mti_attr;
471 struct lu_attr *la = &ma->ma_attr;
472 struct req_capsule *pill = info->mti_pill;
473 const struct lu_env *env = info->mti_env;
474 struct mdt_body *repbody;
475 struct lu_buf *buffer = &info->mti_buf;
479 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_GETATTR_PACK))
480 RETURN(err_serious(-ENOMEM));
482 repbody = req_capsule_server_get(pill, &RMF_MDT_BODY);
486 rc = mdt_object_exists(o);
488 /* This object is located on remote node.*/
489 repbody->fid1 = *mdt_object_fid(o);
490 repbody->valid = OBD_MD_FLID | OBD_MD_MDS;
494 buffer->lb_buf = req_capsule_server_get(pill, &RMF_MDT_MD);
495 buffer->lb_len = req_capsule_get_size(pill, &RMF_MDT_MD, RCL_SERVER);
497 /* If it is dir object and client require MEA, then we got MEA */
498 if (S_ISDIR(lu_object_attr(&next->mo_lu)) &&
499 reqbody->valid & OBD_MD_MEA) {
500 /* Assumption: MDT_MD size is enough for lmv size. */
501 ma->ma_lmv = buffer->lb_buf;
502 ma->ma_lmv_size = buffer->lb_len;
503 ma->ma_need = MA_LMV | MA_INODE;
505 ma->ma_lmm = buffer->lb_buf;
506 ma->ma_lmm_size = buffer->lb_len;
507 ma->ma_need = MA_LOV | MA_INODE;
510 if (S_ISDIR(lu_object_attr(&next->mo_lu)) &&
511 reqbody->valid & OBD_MD_FLDIREA &&
512 lustre_msg_get_opc(req->rq_reqmsg) == MDS_GETATTR) {
513 /* get default stripe info for this dir. */
514 ma->ma_need |= MA_LOV_DEF;
516 ma->ma_need |= ma_need;
517 if (ma->ma_need & MA_SOM)
518 ma->ma_som = &info->mti_u.som.data;
520 rc = mo_attr_get(env, next, ma);
522 CERROR("getattr error for "DFID": %d\n",
523 PFID(mdt_object_fid(o)), rc);
527 if (likely(ma->ma_valid & MA_INODE))
528 mdt_pack_attr2body(info, repbody, la, mdt_object_fid(o));
532 if (mdt_body_has_lov(la, reqbody)) {
533 if (ma->ma_valid & MA_LOV) {
534 LASSERT(ma->ma_lmm_size);
535 mdt_dump_lmm(D_INFO, ma->ma_lmm);
536 repbody->eadatasize = ma->ma_lmm_size;
537 if (S_ISDIR(la->la_mode))
538 repbody->valid |= OBD_MD_FLDIREA;
540 repbody->valid |= OBD_MD_FLEASIZE;
542 if (ma->ma_valid & MA_LMV) {
543 LASSERT(S_ISDIR(la->la_mode));
544 repbody->eadatasize = ma->ma_lmv_size;
545 repbody->valid |= (OBD_MD_FLDIREA|OBD_MD_MEA);
547 } else if (S_ISLNK(la->la_mode) &&
548 reqbody->valid & OBD_MD_LINKNAME) {
549 buffer->lb_buf = ma->ma_lmm;
550 buffer->lb_len = reqbody->eadatasize;
551 rc = mo_readlink(env, next, buffer);
552 if (unlikely(rc <= 0)) {
553 CERROR("readlink failed: %d\n", rc);
556 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_READLINK_EPROTO))
558 repbody->valid |= OBD_MD_LINKNAME;
559 repbody->eadatasize = rc;
561 ((char*)ma->ma_lmm)[rc - 1] = 0;
562 CDEBUG(D_INODE, "symlink dest %s, len = %d\n",
563 (char*)ma->ma_lmm, rc);
568 if (reqbody->valid & OBD_MD_FLMODEASIZE) {
569 repbody->max_cookiesize = info->mti_mdt->mdt_max_cookiesize;
570 repbody->max_mdsize = info->mti_mdt->mdt_max_mdsize;
571 repbody->valid |= OBD_MD_FLMODEASIZE;
572 CDEBUG(D_INODE, "I am going to change the MAX_MD_SIZE & "
573 "MAX_COOKIE to : %d:%d\n", repbody->max_mdsize,
574 repbody->max_cookiesize);
577 if (exp_connect_rmtclient(info->mti_exp) &&
578 reqbody->valid & OBD_MD_FLRMTPERM) {
579 void *buf = req_capsule_server_get(pill, &RMF_ACL);
581 /* mdt_getattr_lock only */
582 rc = mdt_pack_remote_perm(info, o, buf);
584 repbody->valid &= ~OBD_MD_FLRMTPERM;
585 repbody->aclsize = 0;
588 repbody->valid |= OBD_MD_FLRMTPERM;
589 repbody->aclsize = sizeof(struct mdt_remote_perm);
592 #ifdef CONFIG_FS_POSIX_ACL
593 else if ((req->rq_export->exp_connect_flags & OBD_CONNECT_ACL) &&
594 (reqbody->valid & OBD_MD_FLACL)) {
595 buffer->lb_buf = req_capsule_server_get(pill, &RMF_ACL);
596 buffer->lb_len = req_capsule_get_size(pill,
597 &RMF_ACL, RCL_SERVER);
598 if (buffer->lb_len > 0) {
599 rc = mo_xattr_get(env, next, buffer,
600 XATTR_NAME_ACL_ACCESS);
602 if (rc == -ENODATA) {
603 repbody->aclsize = 0;
604 repbody->valid |= OBD_MD_FLACL;
606 } else if (rc == -EOPNOTSUPP) {
609 CERROR("got acl size: %d\n", rc);
612 repbody->aclsize = rc;
613 repbody->valid |= OBD_MD_FLACL;
620 if (reqbody->valid & OBD_MD_FLMDSCAPA &&
621 info->mti_mdt->mdt_opts.mo_mds_capa &&
622 info->mti_exp->exp_connect_flags & OBD_CONNECT_MDS_CAPA) {
623 struct lustre_capa *capa;
625 capa = req_capsule_server_get(pill, &RMF_CAPA1);
627 capa->lc_opc = CAPA_OPC_MDS_DEFAULT;
628 rc = mo_capa_get(env, next, capa, 0);
631 repbody->valid |= OBD_MD_FLMDSCAPA;
636 static int mdt_renew_capa(struct mdt_thread_info *info)
638 struct mdt_object *obj = info->mti_object;
639 struct mdt_body *body;
640 struct lustre_capa *capa, *c;
644 /* if object doesn't exist, or server has disabled capability,
645 * return directly, client will find body->valid OBD_MD_FLOSSCAPA
648 if (!obj || !info->mti_mdt->mdt_opts.mo_oss_capa ||
649 !(info->mti_exp->exp_connect_flags & OBD_CONNECT_OSS_CAPA))
652 body = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
653 LASSERT(body != NULL);
655 c = req_capsule_client_get(info->mti_pill, &RMF_CAPA1);
658 capa = req_capsule_server_get(info->mti_pill, &RMF_CAPA2);
662 rc = mo_capa_get(info->mti_env, mdt_object_child(obj), capa, 1);
664 body->valid |= OBD_MD_FLOSSCAPA;
668 static int mdt_getattr(struct mdt_thread_info *info)
670 struct mdt_object *obj = info->mti_object;
671 struct req_capsule *pill = info->mti_pill;
672 struct mdt_body *reqbody;
673 struct mdt_body *repbody;
679 reqbody = req_capsule_client_get(pill, &RMF_MDT_BODY);
682 if (reqbody->valid & OBD_MD_FLOSSCAPA) {
683 rc = req_capsule_server_pack(pill);
685 RETURN(err_serious(rc));
686 rc = mdt_renew_capa(info);
687 GOTO(out_shrink, rc);
690 LASSERT(obj != NULL);
691 LASSERT(lu_object_assert_exists(&obj->mot_obj.mo_lu));
693 mode = lu_object_attr(&obj->mot_obj.mo_lu);
694 if (S_ISLNK(mode) && (reqbody->valid & OBD_MD_LINKNAME) &&
695 (reqbody->eadatasize > info->mti_mdt->mdt_max_mdsize))
696 md_size = reqbody->eadatasize;
698 md_size = info->mti_mdt->mdt_max_mdsize;
700 req_capsule_set_size(pill, &RMF_MDT_MD, RCL_SERVER, md_size);
702 rc = req_capsule_server_pack(pill);
703 if (unlikely(rc != 0))
704 RETURN(err_serious(rc));
706 repbody = req_capsule_server_get(pill, &RMF_MDT_BODY);
707 LASSERT(repbody != NULL);
708 repbody->eadatasize = 0;
709 repbody->aclsize = 0;
711 if (reqbody->valid & OBD_MD_FLRMTPERM)
712 rc = mdt_init_ucred(info, reqbody);
714 rc = mdt_check_ucred(info);
716 GOTO(out_shrink, rc);
718 info->mti_spec.sp_ck_split = !!(reqbody->valid & OBD_MD_FLCKSPLIT);
719 info->mti_cross_ref = !!(reqbody->valid & OBD_MD_FLCROSSREF);
722 * Don't check capability at all, because rename might getattr for
723 * remote obj, and at that time no capability is available.
725 mdt_set_capainfo(info, 1, &reqbody->fid1, BYPASS_CAPA);
726 rc = mdt_getattr_internal(info, obj, 0);
727 if (reqbody->valid & OBD_MD_FLRMTPERM)
728 mdt_exit_ucred(info);
731 mdt_shrink_reply(info);
735 static int mdt_is_subdir(struct mdt_thread_info *info)
737 struct mdt_object *o = info->mti_object;
738 struct req_capsule *pill = info->mti_pill;
739 const struct mdt_body *body = info->mti_body;
740 struct mdt_body *repbody;
746 repbody = req_capsule_server_get(pill, &RMF_MDT_BODY);
749 * We save last checked parent fid to @repbody->fid1 for remote
752 LASSERT(fid_is_sane(&body->fid2));
753 LASSERT(mdt_object_exists(o) > 0);
754 rc = mdo_is_subdir(info->mti_env, mdt_object_child(o),
755 &body->fid2, &repbody->fid1);
756 if (rc == 0 || rc == -EREMOTE)
757 repbody->valid |= OBD_MD_FLID;
762 static int mdt_raw_lookup(struct mdt_thread_info *info,
763 struct mdt_object *parent,
764 const struct lu_name *lname,
765 struct ldlm_reply *ldlm_rep)
767 struct md_object *next = mdt_object_child(info->mti_object);
768 const struct mdt_body *reqbody = info->mti_body;
769 struct lu_fid *child_fid = &info->mti_tmp_fid1;
770 struct mdt_body *repbody;
774 if (reqbody->valid != OBD_MD_FLID)
777 LASSERT(!info->mti_cross_ref);
779 /* Only got the fid of this obj by name */
780 rc = mdo_lookup(info->mti_env, next, lname, child_fid,
783 /* XXX is raw_lookup possible as intent operation? */
786 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_NEG);
789 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_POS);
791 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
794 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
795 repbody->fid1 = *child_fid;
796 repbody->valid = OBD_MD_FLID;
802 * UPDATE lock should be taken against parent, and be release before exit;
803 * child_bits lock should be taken against child, and be returned back:
804 * (1)normal request should release the child lock;
805 * (2)intent request will grant the lock to client.
807 static int mdt_getattr_name_lock(struct mdt_thread_info *info,
808 struct mdt_lock_handle *lhc,
810 struct ldlm_reply *ldlm_rep)
812 struct ptlrpc_request *req = mdt_info_req(info);
813 struct mdt_body *reqbody = NULL;
814 struct mdt_object *parent = info->mti_object;
815 struct mdt_object *child;
816 struct md_object *next = mdt_object_child(parent);
817 struct lu_fid *child_fid = &info->mti_tmp_fid1;
818 struct lu_name *lname = NULL;
819 const char *name = NULL;
821 struct mdt_lock_handle *lhp = NULL;
822 struct ldlm_lock *lock;
823 struct ldlm_res_id *res_id;
830 is_resent = lustre_handle_is_used(&lhc->mlh_reg_lh);
831 LASSERT(ergo(is_resent,
832 lustre_msg_get_flags(req->rq_reqmsg) & MSG_RESENT));
834 LASSERT(parent != NULL);
835 name = req_capsule_client_get(info->mti_pill, &RMF_NAME);
837 RETURN(err_serious(-EFAULT));
839 namelen = req_capsule_get_size(info->mti_pill, &RMF_NAME,
841 if (!info->mti_cross_ref) {
843 * XXX: Check for "namelen == 0" is for getattr by fid
844 * (OBD_CONNECT_ATTRFID), otherwise do not allow empty name,
845 * that is the name must contain at least one character and
846 * the terminating '\0'
849 reqbody = req_capsule_client_get(info->mti_pill,
851 if (unlikely(reqbody == NULL))
852 RETURN(err_serious(-EFAULT));
854 if (unlikely(!fid_is_sane(&reqbody->fid2)))
855 RETURN(err_serious(-EINVAL));
858 CDEBUG(D_INODE, "getattr with lock for "DFID"/"DFID", "
860 PFID(mdt_object_fid(parent)), PFID(&reqbody->fid2),
863 lname = mdt_name(info->mti_env, (char *)name, namelen);
864 CDEBUG(D_INODE, "getattr with lock for "DFID"/%s, "
865 "ldlm_rep = %p\n", PFID(mdt_object_fid(parent)),
869 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_EXECD);
871 rc = mdt_object_exists(parent);
872 if (unlikely(rc == 0)) {
873 LU_OBJECT_DEBUG(D_WARNING, info->mti_env,
874 &parent->mot_obj.mo_lu,
875 "Parent doesn't exist!\n");
877 } else if (!info->mti_cross_ref) {
878 LASSERTF(rc > 0, "Parent "DFID" is on remote server\n",
879 PFID(mdt_object_fid(parent)));
882 rc = mdt_raw_lookup(info, parent, lname, ldlm_rep);
890 if (info->mti_cross_ref) {
891 /* Only getattr on the child. Parent is on another node. */
892 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_POS);
894 CDEBUG(D_INODE, "partial getattr_name child_fid = "DFID", "
895 "ldlm_rep=%p\n", PFID(mdt_object_fid(child)), ldlm_rep);
898 /* Do not take lock for resent case. */
899 lock = ldlm_handle2lock(&lhc->mlh_reg_lh);
900 LASSERTF(lock != NULL, "Invalid lock handle "LPX64"\n",
901 lhc->mlh_reg_lh.cookie);
902 LASSERT(fid_res_name_eq(mdt_object_fid(child),
903 &lock->l_resource->lr_name));
907 mdt_lock_handle_init(lhc);
908 mdt_lock_reg_init(lhc, LCK_PR);
911 * Object's name is on another MDS, no lookup lock is
912 * needed here but update is.
914 child_bits &= ~MDS_INODELOCK_LOOKUP;
915 child_bits |= MDS_INODELOCK_UPDATE;
917 rc = mdt_object_lock(info, child, lhc, child_bits,
921 /* Finally, we can get attr for child. */
922 mdt_set_capainfo(info, 0, mdt_object_fid(child),
924 rc = mdt_getattr_internal(info, child, 0);
925 if (unlikely(rc != 0))
926 mdt_object_unlock(info, child, lhc, 1);
932 /* step 1: lock parent */
933 lhp = &info->mti_lh[MDT_LH_PARENT];
934 mdt_lock_pdo_init(lhp, LCK_PR, name, namelen);
935 rc = mdt_object_lock(info, parent, lhp, MDS_INODELOCK_UPDATE,
937 if (unlikely(rc != 0))
940 /* step 2: lookup child's fid by name */
941 rc = mdo_lookup(info->mti_env, next, lname, child_fid,
946 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_NEG);
947 GOTO(out_parent, rc);
949 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_POS);
951 *child_fid = reqbody->fid2;
952 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_POS);
956 *step 3: find the child object by fid & lock it.
957 * regardless if it is local or remote.
959 child = mdt_object_find(info->mti_env, info->mti_mdt, child_fid);
961 if (unlikely(IS_ERR(child)))
962 GOTO(out_parent, rc = PTR_ERR(child));
964 /* Do not take lock for resent case. */
965 lock = ldlm_handle2lock(&lhc->mlh_reg_lh);
966 LASSERTF(lock != NULL, "Invalid lock handle "LPX64"\n",
967 lhc->mlh_reg_lh.cookie);
969 res_id = &lock->l_resource->lr_name;
970 if (!fid_res_name_eq(mdt_object_fid(child),
971 &lock->l_resource->lr_name)) {
972 LASSERTF(fid_res_name_eq(mdt_object_fid(parent),
973 &lock->l_resource->lr_name),
974 "Lock res_id: %lu/%lu/%lu, Fid: "DFID".\n",
975 (unsigned long)res_id->name[0],
976 (unsigned long)res_id->name[1],
977 (unsigned long)res_id->name[2],
978 PFID(mdt_object_fid(parent)));
979 CWARN("Although resent, but still not get child lock"
980 "parent:"DFID" child:"DFID"\n",
981 PFID(mdt_object_fid(parent)),
982 PFID(mdt_object_fid(child)));
983 lustre_msg_clear_flags(req->rq_reqmsg, MSG_RESENT);
991 OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_RESEND, obd_timeout*2);
992 mdt_lock_handle_init(lhc);
993 mdt_lock_reg_init(lhc, LCK_PR);
995 if (mdt_object_exists(child) == 0) {
996 LU_OBJECT_DEBUG(D_WARNING, info->mti_env,
997 &child->mot_obj.mo_lu,
998 "Object doesn't exist!\n");
999 GOTO(out_child, rc = -ENOENT);
1002 if (!(child_bits & MDS_INODELOCK_UPDATE)) {
1003 struct md_attr *ma = &info->mti_attr;
1006 ma->ma_need = MA_INODE;
1007 rc = mo_attr_get(info->mti_env,
1008 mdt_object_child(child), ma);
1009 if (unlikely(rc != 0))
1010 GOTO(out_child, rc);
1012 /* If the file has not been changed for some time, we
1013 * return not only a LOOKUP lock, but also an UPDATE
1014 * lock and this might save us RPC on later STAT. For
1015 * directories, it also let negative dentry starts
1016 * working for this dir. */
1017 if (ma->ma_valid & MA_INODE &&
1018 ma->ma_attr.la_valid & LA_CTIME &&
1019 info->mti_mdt->mdt_namespace->ns_ctime_age_limit +
1020 ma->ma_attr.la_ctime < cfs_time_current_sec())
1021 child_bits |= MDS_INODELOCK_UPDATE;
1024 rc = mdt_object_lock(info, child, lhc, child_bits,
1027 if (unlikely(rc != 0))
1028 GOTO(out_child, rc);
1031 lock = ldlm_handle2lock(&lhc->mlh_reg_lh);
1032 /* Get MA_SOM attributes if update lock is given. */
1034 lock->l_policy_data.l_inodebits.bits & MDS_INODELOCK_UPDATE &&
1035 S_ISREG(lu_object_attr(&mdt_object_child(child)->mo_lu)))
1038 /* finally, we can get attr for child. */
1039 mdt_set_capainfo(info, 1, child_fid, BYPASS_CAPA);
1040 rc = mdt_getattr_internal(info, child, ma_need);
1041 if (unlikely(rc != 0)) {
1042 mdt_object_unlock(info, child, lhc, 1);
1044 /* Debugging code. */
1045 res_id = &lock->l_resource->lr_name;
1046 LDLM_DEBUG(lock, "Returning lock to client");
1047 LASSERTF(fid_res_name_eq(mdt_object_fid(child),
1048 &lock->l_resource->lr_name),
1049 "Lock res_id: %lu/%lu/%lu, Fid: "DFID".\n",
1050 (unsigned long)res_id->name[0],
1051 (unsigned long)res_id->name[1],
1052 (unsigned long)res_id->name[2],
1053 PFID(mdt_object_fid(child)));
1054 mdt_pack_size2body(info, child);
1057 LDLM_LOCK_PUT(lock);
1061 mdt_object_put(info->mti_env, child);
1064 mdt_object_unlock(info, parent, lhp, 1);
1068 /* normal handler: should release the child lock */
1069 static int mdt_getattr_name(struct mdt_thread_info *info)
1071 struct mdt_lock_handle *lhc = &info->mti_lh[MDT_LH_CHILD];
1072 struct mdt_body *reqbody;
1073 struct mdt_body *repbody;
1077 reqbody = req_capsule_client_get(info->mti_pill, &RMF_MDT_BODY);
1078 LASSERT(reqbody != NULL);
1079 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
1080 LASSERT(repbody != NULL);
1082 info->mti_spec.sp_ck_split = !!(reqbody->valid & OBD_MD_FLCKSPLIT);
1083 info->mti_cross_ref = !!(reqbody->valid & OBD_MD_FLCROSSREF);
1084 repbody->eadatasize = 0;
1085 repbody->aclsize = 0;
1087 rc = mdt_init_ucred(info, reqbody);
1089 GOTO(out_shrink, rc);
1091 rc = mdt_getattr_name_lock(info, lhc, MDS_INODELOCK_UPDATE, NULL);
1092 if (lustre_handle_is_used(&lhc->mlh_reg_lh)) {
1093 ldlm_lock_decref(&lhc->mlh_reg_lh, lhc->mlh_reg_mode);
1094 lhc->mlh_reg_lh.cookie = 0;
1096 mdt_exit_ucred(info);
1099 mdt_shrink_reply(info);
1103 static const struct lu_device_operations mdt_lu_ops;
1105 static int lu_device_is_mdt(struct lu_device *d)
1107 return ergo(d != NULL && d->ld_ops != NULL, d->ld_ops == &mdt_lu_ops);
1110 static int mdt_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
1111 void *karg, void *uarg);
1113 static int mdt_set_info(struct mdt_thread_info *info)
1115 struct ptlrpc_request *req = mdt_info_req(info);
1118 int keylen, vallen, rc = 0;
1121 rc = req_capsule_server_pack(info->mti_pill);
1125 key = req_capsule_client_get(info->mti_pill, &RMF_SETINFO_KEY);
1127 DEBUG_REQ(D_HA, req, "no set_info key");
1131 keylen = req_capsule_get_size(info->mti_pill, &RMF_SETINFO_KEY,
1134 val = req_capsule_client_get(info->mti_pill, &RMF_SETINFO_VAL);
1136 DEBUG_REQ(D_HA, req, "no set_info val");
1140 vallen = req_capsule_get_size(info->mti_pill, &RMF_SETINFO_VAL,
1143 /* Swab any part of val you need to here */
1144 if (KEY_IS(KEY_READ_ONLY)) {
1146 lustre_msg_set_status(req->rq_repmsg, 0);
1148 cfs_spin_lock(&req->rq_export->exp_lock);
1150 req->rq_export->exp_connect_flags |= OBD_CONNECT_RDONLY;
1152 req->rq_export->exp_connect_flags &=~OBD_CONNECT_RDONLY;
1153 cfs_spin_unlock(&req->rq_export->exp_lock);
1155 } else if (KEY_IS(KEY_CHANGELOG_CLEAR)) {
1156 struct changelog_setinfo *cs =
1157 (struct changelog_setinfo *)val;
1158 if (vallen != sizeof(*cs)) {
1159 CERROR("Bad changelog_clear setinfo size %d\n", vallen);
1162 if (ptlrpc_req_need_swab(req)) {
1163 __swab64s(&cs->cs_recno);
1164 __swab32s(&cs->cs_id);
1167 rc = mdt_iocontrol(OBD_IOC_CHANGELOG_CLEAR, info->mti_exp,
1169 lustre_msg_set_status(req->rq_repmsg, rc);
1177 static int mdt_connect(struct mdt_thread_info *info)
1180 struct ptlrpc_request *req;
1182 req = mdt_info_req(info);
1183 rc = target_handle_connect(req);
1185 LASSERT(req->rq_export != NULL);
1186 info->mti_mdt = mdt_dev(req->rq_export->exp_obd->obd_lu_dev);
1187 rc = mdt_init_sec_level(info);
1189 rc = mdt_init_idmap(info);
1191 obd_disconnect(class_export_get(req->rq_export));
1193 rc = err_serious(rc);
1198 static int mdt_disconnect(struct mdt_thread_info *info)
1203 rc = target_handle_disconnect(mdt_info_req(info));
1205 rc = err_serious(rc);
1209 static int mdt_sendpage(struct mdt_thread_info *info,
1210 struct lu_rdpg *rdpg)
1212 struct ptlrpc_request *req = mdt_info_req(info);
1213 struct obd_export *exp = req->rq_export;
1214 struct ptlrpc_bulk_desc *desc;
1215 struct l_wait_info *lwi = &info->mti_u.rdpg.mti_wait_info;
1223 desc = ptlrpc_prep_bulk_exp(req, rdpg->rp_npages, BULK_PUT_SOURCE,
1228 for (i = 0, tmpcount = rdpg->rp_count;
1229 i < rdpg->rp_npages; i++, tmpcount -= tmpsize) {
1230 tmpsize = min_t(int, tmpcount, CFS_PAGE_SIZE);
1231 ptlrpc_prep_bulk_page(desc, rdpg->rp_pages[i], 0, tmpsize);
1234 LASSERT(desc->bd_nob == rdpg->rp_count);
1235 rc = sptlrpc_svc_wrap_bulk(req, desc);
1237 GOTO(free_desc, rc);
1239 rc = ptlrpc_start_bulk_transfer(desc);
1241 GOTO(free_desc, rc);
1243 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_SENDPAGE))
1244 GOTO(abort_bulk, rc = 0);
1247 timeout = (int) req->rq_deadline - cfs_time_current_sec();
1249 CERROR("Req deadline already passed %lu (now: %lu)\n",
1250 req->rq_deadline, cfs_time_current_sec());
1251 *lwi = LWI_TIMEOUT_INTERVAL(cfs_time_seconds(max(timeout, 1)),
1252 cfs_time_seconds(1), NULL, NULL);
1253 rc = l_wait_event(desc->bd_waitq,
1254 !ptlrpc_server_bulk_active(desc) ||
1256 exp->exp_abort_active_req, lwi);
1257 LASSERT (rc == 0 || rc == -ETIMEDOUT);
1258 } while ((rc == -ETIMEDOUT) &&
1259 (req->rq_deadline > cfs_time_current_sec()));
1262 if (desc->bd_success &&
1263 desc->bd_nob_transferred == rdpg->rp_count)
1264 GOTO(free_desc, rc);
1267 if (exp->exp_abort_active_req || exp->exp_failed)
1268 GOTO(abort_bulk, rc);
1271 DEBUG_REQ(D_ERROR, req, "bulk failed: %s %d(%d), evicting %s@%s",
1272 (rc == -ETIMEDOUT) ? "timeout" : "network error",
1273 desc->bd_nob_transferred, rdpg->rp_count,
1274 exp->exp_client_uuid.uuid,
1275 exp->exp_connection->c_remote_uuid.uuid);
1277 class_fail_export(exp);
1281 ptlrpc_abort_bulk(desc);
1283 ptlrpc_free_bulk(desc);
1287 #ifdef HAVE_SPLIT_SUPPORT
1289 * Retrieve dir entry from the page and insert it to the slave object, actually,
1290 * this should be in osd layer, but since it will not in the final product, so
1291 * just do it here and do not define more moo api anymore for this.
1293 static int mdt_write_dir_page(struct mdt_thread_info *info, struct page *page,
1296 struct mdt_object *object = info->mti_object;
1297 struct lu_fid *lf = &info->mti_tmp_fid2;
1298 struct md_attr *ma = &info->mti_attr;
1299 struct lu_dirpage *dp;
1300 struct lu_dirent *ent;
1301 int rc = 0, offset = 0;
1304 /* Make sure we have at least one entry. */
1309 * Disable trans for this name insert, since it will include many trans
1312 info->mti_no_need_trans = 1;
1314 * When write_dir_page, no need update parent's ctime,
1315 * and no permission check for name_insert.
1317 ma->ma_attr.la_ctime = 0;
1318 ma->ma_attr.la_valid = LA_MODE;
1319 ma->ma_valid = MA_INODE;
1322 dp = page_address(page);
1323 offset = (int)((__u32)lu_dirent_start(dp) - (__u32)dp);
1325 for (ent = lu_dirent_start(dp); ent != NULL;
1326 ent = lu_dirent_next(ent)) {
1327 struct lu_name *lname;
1330 if (le16_to_cpu(ent->lde_namelen) == 0)
1333 fid_le_to_cpu(lf, &ent->lde_fid);
1334 if (le64_to_cpu(ent->lde_hash) & MAX_HASH_HIGHEST_BIT)
1335 ma->ma_attr.la_mode = S_IFDIR;
1337 ma->ma_attr.la_mode = 0;
1338 OBD_ALLOC(name, le16_to_cpu(ent->lde_namelen) + 1);
1340 GOTO(out, rc = -ENOMEM);
1342 memcpy(name, ent->lde_name, le16_to_cpu(ent->lde_namelen));
1343 lname = mdt_name(info->mti_env, name,
1344 le16_to_cpu(ent->lde_namelen));
1345 ma->ma_attr_flags |= (MDS_PERM_BYPASS | MDS_QUOTA_IGNORE);
1346 rc = mdo_name_insert(info->mti_env,
1347 md_object_next(&object->mot_obj),
1349 OBD_FREE(name, le16_to_cpu(ent->lde_namelen) + 1);
1351 CERROR("Can't insert %*.*s, rc %d\n",
1352 le16_to_cpu(ent->lde_namelen),
1353 le16_to_cpu(ent->lde_namelen),
1358 offset += lu_dirent_size(ent);
1368 static int mdt_bulk_timeout(void *data)
1372 CERROR("mdt bulk transfer timeout \n");
1377 static int mdt_writepage(struct mdt_thread_info *info)
1379 struct ptlrpc_request *req = mdt_info_req(info);
1380 struct mdt_body *reqbody;
1381 struct l_wait_info *lwi;
1382 struct ptlrpc_bulk_desc *desc;
1388 reqbody = req_capsule_client_get(info->mti_pill, &RMF_MDT_BODY);
1389 if (reqbody == NULL)
1390 RETURN(err_serious(-EFAULT));
1392 desc = ptlrpc_prep_bulk_exp(req, 1, BULK_GET_SINK, MDS_BULK_PORTAL);
1394 RETURN(err_serious(-ENOMEM));
1396 /* allocate the page for the desc */
1397 page = cfs_alloc_page(CFS_ALLOC_STD);
1399 GOTO(desc_cleanup, rc = -ENOMEM);
1401 CDEBUG(D_INFO, "Received page offset %d size %d \n",
1402 (int)reqbody->size, (int)reqbody->nlink);
1404 ptlrpc_prep_bulk_page(desc, page, (int)reqbody->size,
1405 (int)reqbody->nlink);
1407 rc = sptlrpc_svc_prep_bulk(req, desc);
1409 GOTO(cleanup_page, rc);
1411 * Check if client was evicted while we were doing i/o before touching
1416 GOTO(cleanup_page, rc = -ENOMEM);
1418 if (desc->bd_export->exp_failed)
1421 rc = ptlrpc_start_bulk_transfer (desc);
1423 *lwi = LWI_TIMEOUT_INTERVAL(obd_timeout * CFS_HZ / 4, CFS_HZ,
1424 mdt_bulk_timeout, desc);
1425 rc = l_wait_event(desc->bd_waitq, !ptlrpc_bulk_active(desc) ||
1426 desc->bd_export->exp_failed, lwi);
1427 LASSERT(rc == 0 || rc == -ETIMEDOUT);
1428 if (rc == -ETIMEDOUT) {
1429 DEBUG_REQ(D_ERROR, req, "timeout on bulk GET");
1430 ptlrpc_abort_bulk(desc);
1431 } else if (desc->bd_export->exp_failed) {
1432 DEBUG_REQ(D_ERROR, req, "Eviction on bulk GET");
1434 ptlrpc_abort_bulk(desc);
1435 } else if (!desc->bd_success ||
1436 desc->bd_nob_transferred != desc->bd_nob) {
1437 DEBUG_REQ(D_ERROR, req, "%s bulk GET %d(%d)",
1439 "truncated" : "network error on",
1440 desc->bd_nob_transferred, desc->bd_nob);
1441 /* XXX should this be a different errno? */
1445 DEBUG_REQ(D_ERROR, req, "ptlrpc_bulk_get failed: rc %d", rc);
1448 GOTO(cleanup_lwi, rc);
1449 rc = mdt_write_dir_page(info, page, reqbody->nlink);
1454 cfs_free_page(page);
1456 ptlrpc_free_bulk(desc);
1461 static int mdt_readpage(struct mdt_thread_info *info)
1463 struct mdt_object *object = info->mti_object;
1464 struct lu_rdpg *rdpg = &info->mti_u.rdpg.mti_rdpg;
1465 struct mdt_body *reqbody;
1466 struct mdt_body *repbody;
1471 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_READPAGE_PACK))
1472 RETURN(err_serious(-ENOMEM));
1474 reqbody = req_capsule_client_get(info->mti_pill, &RMF_MDT_BODY);
1475 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
1476 if (reqbody == NULL || repbody == NULL)
1477 RETURN(err_serious(-EFAULT));
1480 * prepare @rdpg before calling lower layers and transfer itself. Here
1481 * reqbody->size contains offset of where to start to read and
1482 * reqbody->nlink contains number bytes to read.
1484 rdpg->rp_hash = reqbody->size;
1485 if (rdpg->rp_hash != reqbody->size) {
1486 CERROR("Invalid hash: "LPX64" != "LPX64"\n",
1487 rdpg->rp_hash, reqbody->size);
1491 rdpg->rp_attrs = reqbody->mode;
1492 if (info->mti_exp->exp_connect_flags & OBD_CONNECT_64BITHASH)
1493 rdpg->rp_attrs |= LUDA_64BITHASH;
1494 rdpg->rp_count = reqbody->nlink;
1495 rdpg->rp_npages = (rdpg->rp_count + CFS_PAGE_SIZE - 1)>>CFS_PAGE_SHIFT;
1496 OBD_ALLOC(rdpg->rp_pages, rdpg->rp_npages * sizeof rdpg->rp_pages[0]);
1497 if (rdpg->rp_pages == NULL)
1500 for (i = 0; i < rdpg->rp_npages; ++i) {
1501 rdpg->rp_pages[i] = cfs_alloc_page(CFS_ALLOC_STD);
1502 if (rdpg->rp_pages[i] == NULL)
1503 GOTO(free_rdpg, rc = -ENOMEM);
1506 /* call lower layers to fill allocated pages with directory data */
1507 rc = mo_readpage(info->mti_env, mdt_object_child(object), rdpg);
1509 GOTO(free_rdpg, rc);
1511 /* send pages to client */
1512 rc = mdt_sendpage(info, rdpg);
1517 for (i = 0; i < rdpg->rp_npages; i++)
1518 if (rdpg->rp_pages[i] != NULL)
1519 cfs_free_page(rdpg->rp_pages[i]);
1520 OBD_FREE(rdpg->rp_pages, rdpg->rp_npages * sizeof rdpg->rp_pages[0]);
1522 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_SENDPAGE))
1528 static int mdt_reint_internal(struct mdt_thread_info *info,
1529 struct mdt_lock_handle *lhc,
1532 struct req_capsule *pill = info->mti_pill;
1533 struct mdt_device *mdt = info->mti_mdt;
1534 struct md_quota *mq = md_quota(info->mti_env);
1535 struct mdt_body *repbody;
1540 if (req_capsule_has_field(pill, &RMF_MDT_MD, RCL_SERVER))
1541 req_capsule_set_size(pill, &RMF_MDT_MD, RCL_SERVER,
1542 mdt->mdt_max_mdsize);
1543 if (req_capsule_has_field(pill, &RMF_LOGCOOKIES, RCL_SERVER))
1544 req_capsule_set_size(pill, &RMF_LOGCOOKIES, RCL_SERVER,
1545 mdt->mdt_max_cookiesize);
1547 rc = req_capsule_server_pack(pill);
1549 CERROR("Can't pack response, rc %d\n", rc);
1550 RETURN(err_serious(rc));
1553 if (req_capsule_has_field(pill, &RMF_MDT_BODY, RCL_SERVER)) {
1554 repbody = req_capsule_server_get(pill, &RMF_MDT_BODY);
1556 repbody->eadatasize = 0;
1557 repbody->aclsize = 0;
1560 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_REINT_UNPACK))
1561 GOTO(out_shrink, rc = err_serious(-EFAULT));
1563 rc = mdt_reint_unpack(info, op);
1565 CERROR("Can't unpack reint, rc %d\n", rc);
1566 GOTO(out_shrink, rc = err_serious(rc));
1569 OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_REINT_DELAY, 10);
1571 /* for replay no cookkie / lmm need, because client have this already */
1572 if (info->mti_spec.no_create == 1) {
1573 if (req_capsule_has_field(pill, &RMF_MDT_MD, RCL_SERVER))
1574 req_capsule_set_size(pill, &RMF_MDT_MD, RCL_SERVER, 0);
1576 if (req_capsule_has_field(pill, &RMF_LOGCOOKIES, RCL_SERVER))
1577 req_capsule_set_size(pill, &RMF_LOGCOOKIES, RCL_SERVER,
1581 rc = mdt_init_ucred_reint(info);
1583 GOTO(out_shrink, rc);
1585 rc = mdt_fix_attr_ucred(info, op);
1587 GOTO(out_ucred, rc = err_serious(rc));
1589 if (mdt_check_resent(info, mdt_reconstruct, lhc)) {
1590 rc = lustre_msg_get_status(mdt_info_req(info)->rq_repmsg);
1591 GOTO(out_ucred, rc);
1593 mq->mq_exp = info->mti_exp;
1594 rc = mdt_reint_rec(info, lhc);
1597 mdt_exit_ucred(info);
1599 mdt_shrink_reply(info);
1603 static long mdt_reint_opcode(struct mdt_thread_info *info,
1604 const struct req_format **fmt)
1606 struct mdt_rec_reint *rec;
1609 opc = err_serious(-EFAULT);
1610 rec = req_capsule_client_get(info->mti_pill, &RMF_REC_REINT);
1612 opc = rec->rr_opcode;
1613 DEBUG_REQ(D_INODE, mdt_info_req(info), "reint opt = %ld", opc);
1614 if (opc < REINT_MAX && fmt[opc] != NULL)
1615 req_capsule_extend(info->mti_pill, fmt[opc]);
1617 CERROR("Unsupported opc: %ld\n", opc);
1618 opc = err_serious(opc);
1624 static int mdt_reint(struct mdt_thread_info *info)
1629 static const struct req_format *reint_fmts[REINT_MAX] = {
1630 [REINT_SETATTR] = &RQF_MDS_REINT_SETATTR,
1631 [REINT_CREATE] = &RQF_MDS_REINT_CREATE,
1632 [REINT_LINK] = &RQF_MDS_REINT_LINK,
1633 [REINT_UNLINK] = &RQF_MDS_REINT_UNLINK,
1634 [REINT_RENAME] = &RQF_MDS_REINT_RENAME,
1635 [REINT_OPEN] = &RQF_MDS_REINT_OPEN,
1636 [REINT_SETXATTR] = &RQF_MDS_REINT_SETXATTR
1641 opc = mdt_reint_opcode(info, reint_fmts);
1644 * No lock possible here from client to pass it to reint code
1647 rc = mdt_reint_internal(info, NULL, opc);
1652 info->mti_fail_id = OBD_FAIL_MDS_REINT_NET_REP;
1656 /* this should sync the whole device */
1657 static int mdt_device_sync(const struct lu_env *env, struct mdt_device *mdt)
1659 struct dt_device *dt = mdt->mdt_bottom;
1663 rc = dt->dd_ops->dt_sync(env, dt);
1667 /* this should sync this object */
1668 static int mdt_object_sync(struct mdt_thread_info *info)
1670 struct md_object *next;
1674 if (!mdt_object_exists(info->mti_object)) {
1675 CWARN("Non existing object "DFID"!\n",
1676 PFID(mdt_object_fid(info->mti_object)));
1679 next = mdt_object_child(info->mti_object);
1680 rc = mo_object_sync(info->mti_env, next);
1685 static int mdt_sync(struct mdt_thread_info *info)
1687 struct req_capsule *pill = info->mti_pill;
1688 struct mdt_body *body;
1692 /* The fid may be zero, so we req_capsule_set manually */
1693 req_capsule_set(pill, &RQF_MDS_SYNC);
1695 body = req_capsule_client_get(pill, &RMF_MDT_BODY);
1697 RETURN(err_serious(-EINVAL));
1699 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_SYNC_PACK))
1700 RETURN(err_serious(-ENOMEM));
1702 if (fid_seq(&body->fid1) == 0) {
1703 /* sync the whole device */
1704 rc = req_capsule_server_pack(pill);
1706 rc = mdt_device_sync(info->mti_env, info->mti_mdt);
1708 rc = err_serious(rc);
1710 /* sync an object */
1711 rc = mdt_unpack_req_pack_rep(info, HABEO_CORPUS|HABEO_REFERO);
1713 rc = mdt_object_sync(info);
1715 struct md_object *next;
1716 const struct lu_fid *fid;
1717 struct lu_attr *la = &info->mti_attr.ma_attr;
1719 next = mdt_object_child(info->mti_object);
1720 info->mti_attr.ma_need = MA_INODE;
1721 info->mti_attr.ma_valid = 0;
1722 rc = mo_attr_get(info->mti_env, next,
1725 body = req_capsule_server_get(pill,
1727 fid = mdt_object_fid(info->mti_object);
1728 mdt_pack_attr2body(info, body, la, fid);
1732 rc = err_serious(rc);
1737 #ifdef HAVE_QUOTA_SUPPORT
1738 static int mdt_quotacheck_handle(struct mdt_thread_info *info)
1740 struct obd_quotactl *oqctl;
1741 struct req_capsule *pill = info->mti_pill;
1742 struct obd_export *exp = info->mti_exp;
1743 struct md_quota *mq = md_quota(info->mti_env);
1744 struct md_device *next = info->mti_mdt->mdt_child;
1748 oqctl = req_capsule_client_get(pill, &RMF_OBD_QUOTACTL);
1752 /* remote client has no permission for quotacheck */
1753 if (unlikely(exp_connect_rmtclient(exp)))
1756 rc = req_capsule_server_pack(pill);
1761 rc = next->md_ops->mdo_quota.mqo_check(info->mti_env, next,
1766 static int mdt_quotactl_handle(struct mdt_thread_info *info)
1768 struct obd_quotactl *oqctl, *repoqc;
1769 struct req_capsule *pill = info->mti_pill;
1770 struct obd_export *exp = info->mti_exp;
1771 struct md_quota *mq = md_quota(info->mti_env);
1772 struct md_device *next = info->mti_mdt->mdt_child;
1773 const struct md_quota_operations *mqo = &next->md_ops->mdo_quota;
1777 oqctl = req_capsule_client_get(pill, &RMF_OBD_QUOTACTL);
1782 if (exp_connect_rmtclient(exp)) {
1783 struct ptlrpc_request *req = mdt_info_req(info);
1784 struct mdt_export_data *med = mdt_req2med(req);
1785 struct lustre_idmap_table *idmap = med->med_idmap;
1787 if (unlikely(oqctl->qc_cmd != Q_GETQUOTA &&
1788 oqctl->qc_cmd != Q_GETINFO))
1792 if (oqctl->qc_type == USRQUOTA)
1793 id = lustre_idmap_lookup_uid(NULL, idmap, 0,
1795 else if (oqctl->qc_type == GRPQUOTA)
1796 id = lustre_idmap_lookup_gid(NULL, idmap, 0,
1801 if (id == CFS_IDMAP_NOTFOUND) {
1802 CDEBUG(D_QUOTA, "no mapping for id %u\n",
1808 rc = req_capsule_server_pack(pill);
1812 repoqc = req_capsule_server_get(pill, &RMF_OBD_QUOTACTL);
1813 LASSERT(repoqc != NULL);
1816 switch (oqctl->qc_cmd) {
1818 rc = mqo->mqo_on(info->mti_env, next, oqctl->qc_type);
1821 rc = mqo->mqo_off(info->mti_env, next, oqctl->qc_type);
1824 rc = mqo->mqo_setinfo(info->mti_env, next, oqctl->qc_type, id,
1828 rc = mqo->mqo_getinfo(info->mti_env, next, oqctl->qc_type, id,
1832 rc = mqo->mqo_setquota(info->mti_env, next, oqctl->qc_type, id,
1836 rc = mqo->mqo_getquota(info->mti_env, next, oqctl->qc_type, id,
1840 rc = mqo->mqo_getoinfo(info->mti_env, next, oqctl->qc_type, id,
1844 rc = mqo->mqo_getoquota(info->mti_env, next, oqctl->qc_type, id,
1847 case LUSTRE_Q_INVALIDATE:
1848 rc = mqo->mqo_invalidate(info->mti_env, next, oqctl->qc_type);
1850 case LUSTRE_Q_FINVALIDATE:
1851 rc = mqo->mqo_finvalidate(info->mti_env, next, oqctl->qc_type);
1854 CERROR("unsupported mdt_quotactl command: %d\n",
1866 * OBD PING and other handlers.
1868 static int mdt_obd_ping(struct mdt_thread_info *info)
1873 req_capsule_set(info->mti_pill, &RQF_OBD_PING);
1875 rc = target_handle_ping(mdt_info_req(info));
1877 rc = err_serious(rc);
1881 static int mdt_obd_log_cancel(struct mdt_thread_info *info)
1883 return err_serious(-EOPNOTSUPP);
1886 static int mdt_obd_qc_callback(struct mdt_thread_info *info)
1888 return err_serious(-EOPNOTSUPP);
1896 /** clone llog ctxt from child (mdd)
1897 * This allows remote llog (replicator) access.
1898 * We can either pass all llog RPCs (eg mdt_llog_create) on to child where the
1899 * context was originally set up, or we can handle them directly.
1900 * I choose the latter, but that means I need any llog
1901 * contexts set up by child to be accessable by the mdt. So we clone the
1902 * context into our context list here.
1904 static int mdt_llog_ctxt_clone(const struct lu_env *env, struct mdt_device *mdt,
1907 struct md_device *next = mdt->mdt_child;
1908 struct llog_ctxt *ctxt;
1911 if (!llog_ctxt_null(mdt2obd_dev(mdt), idx))
1914 rc = next->md_ops->mdo_llog_ctxt_get(env, next, idx, (void **)&ctxt);
1915 if (rc || ctxt == NULL) {
1916 CERROR("Can't get mdd ctxt %d\n", rc);
1920 rc = llog_group_set_ctxt(&mdt2obd_dev(mdt)->obd_olg, ctxt, idx);
1922 CERROR("Can't set mdt ctxt %d\n", rc);
1927 static int mdt_llog_ctxt_unclone(const struct lu_env *env,
1928 struct mdt_device *mdt, int idx)
1930 struct llog_ctxt *ctxt;
1932 ctxt = llog_get_context(mdt2obd_dev(mdt), idx);
1935 /* Put once for the get we just did, and once for the clone */
1936 llog_ctxt_put(ctxt);
1937 llog_ctxt_put(ctxt);
1941 static int mdt_llog_create(struct mdt_thread_info *info)
1945 req_capsule_set(info->mti_pill, &RQF_LLOG_ORIGIN_HANDLE_CREATE);
1946 rc = llog_origin_handle_create(mdt_info_req(info));
1947 return (rc < 0 ? err_serious(rc) : rc);
1950 static int mdt_llog_destroy(struct mdt_thread_info *info)
1954 req_capsule_set(info->mti_pill, &RQF_LLOG_ORIGIN_HANDLE_DESTROY);
1955 rc = llog_origin_handle_destroy(mdt_info_req(info));
1956 return (rc < 0 ? err_serious(rc) : rc);
1959 static int mdt_llog_read_header(struct mdt_thread_info *info)
1963 req_capsule_set(info->mti_pill, &RQF_LLOG_ORIGIN_HANDLE_READ_HEADER);
1964 rc = llog_origin_handle_read_header(mdt_info_req(info));
1965 return (rc < 0 ? err_serious(rc) : rc);
1968 static int mdt_llog_next_block(struct mdt_thread_info *info)
1972 req_capsule_set(info->mti_pill, &RQF_LLOG_ORIGIN_HANDLE_NEXT_BLOCK);
1973 rc = llog_origin_handle_next_block(mdt_info_req(info));
1974 return (rc < 0 ? err_serious(rc) : rc);
1977 static int mdt_llog_prev_block(struct mdt_thread_info *info)
1981 req_capsule_set(info->mti_pill, &RQF_LLOG_ORIGIN_HANDLE_PREV_BLOCK);
1982 rc = llog_origin_handle_prev_block(mdt_info_req(info));
1983 return (rc < 0 ? err_serious(rc) : rc);
1990 static struct ldlm_callback_suite cbs = {
1991 .lcs_completion = ldlm_server_completion_ast,
1992 .lcs_blocking = ldlm_server_blocking_ast,
1996 static int mdt_enqueue(struct mdt_thread_info *info)
1998 struct ptlrpc_request *req;
2002 * info->mti_dlm_req already contains swapped and (if necessary)
2003 * converted dlm request.
2005 LASSERT(info->mti_dlm_req != NULL);
2007 req = mdt_info_req(info);
2008 rc = ldlm_handle_enqueue0(info->mti_mdt->mdt_namespace,
2009 req, info->mti_dlm_req, &cbs);
2010 info->mti_fail_id = OBD_FAIL_LDLM_REPLY;
2011 return rc ? err_serious(rc) : req->rq_status;
2014 static int mdt_convert(struct mdt_thread_info *info)
2017 struct ptlrpc_request *req;
2019 LASSERT(info->mti_dlm_req);
2020 req = mdt_info_req(info);
2021 rc = ldlm_handle_convert0(req, info->mti_dlm_req);
2022 return rc ? err_serious(rc) : req->rq_status;
2025 static int mdt_bl_callback(struct mdt_thread_info *info)
2027 CERROR("bl callbacks should not happen on MDS\n");
2029 return err_serious(-EOPNOTSUPP);
2032 static int mdt_cp_callback(struct mdt_thread_info *info)
2034 CERROR("cp callbacks should not happen on MDS\n");
2036 return err_serious(-EOPNOTSUPP);
2040 * sec context handlers
2042 static int mdt_sec_ctx_handle(struct mdt_thread_info *info)
2046 rc = mdt_handle_idmap(info);
2049 struct ptlrpc_request *req = mdt_info_req(info);
2052 opc = lustre_msg_get_opc(req->rq_reqmsg);
2053 if (opc == SEC_CTX_INIT || opc == SEC_CTX_INIT_CONT)
2054 sptlrpc_svc_ctx_invalidate(req);
2057 CFS_FAIL_TIMEOUT(OBD_FAIL_SEC_CTX_HDL_PAUSE, cfs_fail_val);
2062 static struct mdt_object *mdt_obj(struct lu_object *o)
2064 LASSERT(lu_device_is_mdt(o->lo_dev));
2065 return container_of0(o, struct mdt_object, mot_obj.mo_lu);
2068 struct mdt_object *mdt_object_find(const struct lu_env *env,
2069 struct mdt_device *d,
2070 const struct lu_fid *f)
2072 struct lu_object *o;
2073 struct mdt_object *m;
2076 CDEBUG(D_INFO, "Find object for "DFID"\n", PFID(f));
2077 o = lu_object_find(env, &d->mdt_md_dev.md_lu_dev, f, NULL);
2078 if (unlikely(IS_ERR(o)))
2079 m = (struct mdt_object *)o;
2086 * Asyncronous commit for mdt device.
2088 * Pass asynchonous commit call down the MDS stack.
2090 * \param env environment
2091 * \param mdt the mdt device
2093 static void mdt_device_commit_async(const struct lu_env *env,
2094 struct mdt_device *mdt)
2096 struct dt_device *dt = mdt->mdt_bottom;
2099 rc = dt->dd_ops->dt_commit_async(env, dt);
2100 if (unlikely(rc != 0))
2101 CWARN("async commit start failed with rc = %d", rc);
2105 * Mark the lock as "synchonous".
2107 * Mark the lock to deffer transaction commit to the unlock time.
2109 * \param lock the lock to mark as "synchonous"
2111 * \see mdt_is_lock_sync
2112 * \see mdt_save_lock
2114 static inline void mdt_set_lock_sync(struct ldlm_lock *lock)
2116 lock->l_ast_data = (void*)1;
2120 * Check whehter the lock "synchonous" or not.
2122 * \param lock the lock to check
2123 * \retval 1 the lock is "synchonous"
2124 * \retval 0 the lock isn't "synchronous"
2126 * \see mdt_set_lock_sync
2127 * \see mdt_save_lock
2129 static inline int mdt_is_lock_sync(struct ldlm_lock *lock)
2131 return lock->l_ast_data != NULL;
2135 * Blocking AST for mdt locks.
2137 * Starts transaction commit if in case of COS lock conflict or
2138 * deffers such a commit to the mdt_save_lock.
2140 * \param lock the lock which blocks a request or cancelling lock
2141 * \param desc unused
2142 * \param data unused
2143 * \param flag indicates whether this cancelling or blocking callback
2145 * \see ldlm_blocking_ast_nocheck
2147 int mdt_blocking_ast(struct ldlm_lock *lock, struct ldlm_lock_desc *desc,
2148 void *data, int flag)
2150 struct obd_device *obd = ldlm_lock_to_ns(lock)->ns_obd;
2151 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
2155 if (flag == LDLM_CB_CANCELING)
2157 lock_res_and_lock(lock);
2158 if (lock->l_blocking_ast != mdt_blocking_ast) {
2159 unlock_res_and_lock(lock);
2162 if (mdt_cos_is_enabled(mdt) &&
2163 lock->l_req_mode & (LCK_PW | LCK_EX) &&
2164 lock->l_blocking_lock != NULL &&
2165 lock->l_client_cookie != lock->l_blocking_lock->l_client_cookie) {
2166 mdt_set_lock_sync(lock);
2168 rc = ldlm_blocking_ast_nocheck(lock);
2170 /* There is no lock conflict if l_blocking_lock == NULL,
2171 * it indicates a blocking ast sent from ldlm_lock_decref_internal
2172 * when the last reference to a local lock was released */
2173 if (lock->l_req_mode == LCK_COS && lock->l_blocking_lock != NULL) {
2176 rc = lu_env_init(&env, LCT_MD_THREAD);
2177 if (unlikely(rc != 0))
2178 CWARN("lu_env initialization failed with rc = %d,"
2179 "cannot start asynchronous commit\n", rc);
2181 mdt_device_commit_async(&env, mdt);
2187 int mdt_object_lock(struct mdt_thread_info *info, struct mdt_object *o,
2188 struct mdt_lock_handle *lh, __u64 ibits, int locality)
2190 struct ldlm_namespace *ns = info->mti_mdt->mdt_namespace;
2191 ldlm_policy_data_t *policy = &info->mti_policy;
2192 struct ldlm_res_id *res_id = &info->mti_res_id;
2196 LASSERT(!lustre_handle_is_used(&lh->mlh_reg_lh));
2197 LASSERT(!lustre_handle_is_used(&lh->mlh_pdo_lh));
2198 LASSERT(lh->mlh_reg_mode != LCK_MINMODE);
2199 LASSERT(lh->mlh_type != MDT_NUL_LOCK);
2201 if (mdt_object_exists(o) < 0) {
2202 if (locality == MDT_CROSS_LOCK) {
2203 /* cross-ref object fix */
2204 ibits &= ~MDS_INODELOCK_UPDATE;
2205 ibits |= MDS_INODELOCK_LOOKUP;
2207 LASSERT(!(ibits & MDS_INODELOCK_UPDATE));
2208 LASSERT(ibits & MDS_INODELOCK_LOOKUP);
2210 /* No PDO lock on remote object */
2211 LASSERT(lh->mlh_type != MDT_PDO_LOCK);
2214 if (lh->mlh_type == MDT_PDO_LOCK) {
2215 /* check for exists after object is locked */
2216 if (mdt_object_exists(o) == 0) {
2217 /* Non-existent object shouldn't have PDO lock */
2220 /* Non-dir object shouldn't have PDO lock */
2221 if (!S_ISDIR(lu_object_attr(&o->mot_obj.mo_lu)))
2226 memset(policy, 0, sizeof(*policy));
2227 fid_build_reg_res_name(mdt_object_fid(o), res_id);
2230 * Take PDO lock on whole directory and build correct @res_id for lock
2231 * on part of directory.
2233 if (lh->mlh_pdo_hash != 0) {
2234 LASSERT(lh->mlh_type == MDT_PDO_LOCK);
2235 mdt_lock_pdo_mode(info, o, lh);
2236 if (lh->mlh_pdo_mode != LCK_NL) {
2238 * Do not use LDLM_FL_LOCAL_ONLY for parallel lock, it
2239 * is never going to be sent to client and we do not
2240 * want it slowed down due to possible cancels.
2242 policy->l_inodebits.bits = MDS_INODELOCK_UPDATE;
2243 rc = mdt_fid_lock(ns, &lh->mlh_pdo_lh, lh->mlh_pdo_mode,
2244 policy, res_id, LDLM_FL_ATOMIC_CB,
2245 &info->mti_exp->exp_handle.h_cookie);
2251 * Finish res_id initializing by name hash marking part of
2252 * directory which is taking modification.
2254 res_id->name[LUSTRE_RES_ID_HSH_OFF] = lh->mlh_pdo_hash;
2257 policy->l_inodebits.bits = ibits;
2260 * Use LDLM_FL_LOCAL_ONLY for this lock. We do not know yet if it is
2261 * going to be sent to client. If it is - mdt_intent_policy() path will
2262 * fix it up and turn FL_LOCAL flag off.
2264 rc = mdt_fid_lock(ns, &lh->mlh_reg_lh, lh->mlh_reg_mode, policy,
2265 res_id, LDLM_FL_LOCAL_ONLY | LDLM_FL_ATOMIC_CB,
2266 &info->mti_exp->exp_handle.h_cookie);
2268 mdt_object_unlock(info, o, lh, 1);
2269 else if (unlikely(OBD_FAIL_PRECHECK(OBD_FAIL_MDS_PDO_LOCK)) &&
2270 lh->mlh_pdo_hash != 0 &&
2271 (lh->mlh_reg_mode == LCK_PW || lh->mlh_reg_mode == LCK_EX)) {
2272 OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_PDO_LOCK, 10);
2279 * Save a lock within request object.
2281 * Keep the lock referenced until whether client ACK or transaction
2282 * commit happens or release the lock immediately depending on input
2283 * parameters. If COS is ON, a write lock is converted to COS lock
2286 * \param info thead info object
2287 * \param h lock handle
2288 * \param mode lock mode
2289 * \param decref force immediate lock releasing
2292 void mdt_save_lock(struct mdt_thread_info *info, struct lustre_handle *h,
2293 ldlm_mode_t mode, int decref)
2297 if (lustre_handle_is_used(h)) {
2298 if (decref || !info->mti_has_trans ||
2299 !(mode & (LCK_PW | LCK_EX))){
2300 mdt_fid_unlock(h, mode);
2302 struct mdt_device *mdt = info->mti_mdt;
2303 struct ldlm_lock *lock = ldlm_handle2lock(h);
2304 struct ptlrpc_request *req = mdt_info_req(info);
2307 LASSERTF(lock != NULL, "no lock for cookie "LPX64"\n",
2309 CDEBUG(D_HA, "request = %p reply state = %p"
2310 " transno = "LPD64"\n",
2311 req, req->rq_reply_state, req->rq_transno);
2312 if (mdt_cos_is_enabled(mdt)) {
2314 ldlm_lock_downgrade(lock, LCK_COS);
2317 ptlrpc_save_lock(req, h, mode, no_ack);
2318 if (mdt_is_lock_sync(lock)) {
2319 CDEBUG(D_HA, "found sync-lock,"
2320 " async commit started\n");
2321 mdt_device_commit_async(info->mti_env,
2324 LDLM_LOCK_PUT(lock);
2333 * Unlock mdt object.
2335 * Immeditely release the regular lock and the PDO lock or save the
2336 * lock in reqeuest and keep them referenced until client ACK or
2337 * transaction commit.
2339 * \param info thread info object
2340 * \param o mdt object
2341 * \param lh mdt lock handle referencing regular and PDO locks
2342 * \param decref force immediate lock releasing
2344 void mdt_object_unlock(struct mdt_thread_info *info, struct mdt_object *o,
2345 struct mdt_lock_handle *lh, int decref)
2349 mdt_save_lock(info, &lh->mlh_pdo_lh, lh->mlh_pdo_mode, decref);
2350 mdt_save_lock(info, &lh->mlh_reg_lh, lh->mlh_reg_mode, decref);
2355 struct mdt_object *mdt_object_find_lock(struct mdt_thread_info *info,
2356 const struct lu_fid *f,
2357 struct mdt_lock_handle *lh,
2360 struct mdt_object *o;
2362 o = mdt_object_find(info->mti_env, info->mti_mdt, f);
2366 rc = mdt_object_lock(info, o, lh, ibits,
2369 mdt_object_put(info->mti_env, o);
2376 void mdt_object_unlock_put(struct mdt_thread_info * info,
2377 struct mdt_object * o,
2378 struct mdt_lock_handle *lh,
2381 mdt_object_unlock(info, o, lh, decref);
2382 mdt_object_put(info->mti_env, o);
2385 static struct mdt_handler *mdt_handler_find(__u32 opc,
2386 struct mdt_opc_slice *supported)
2388 struct mdt_opc_slice *s;
2389 struct mdt_handler *h;
2392 for (s = supported; s->mos_hs != NULL; s++) {
2393 if (s->mos_opc_start <= opc && opc < s->mos_opc_end) {
2394 h = s->mos_hs + (opc - s->mos_opc_start);
2395 if (likely(h->mh_opc != 0))
2396 LASSERTF(h->mh_opc == opc,
2397 "opcode mismatch %d != %d\n",
2400 h = NULL; /* unsupported opc */
2407 static int mdt_lock_resname_compat(struct mdt_device *m,
2408 struct ldlm_request *req)
2410 /* XXX something... later. */
2414 static int mdt_lock_reply_compat(struct mdt_device *m, struct ldlm_reply *rep)
2416 /* XXX something... later. */
2421 * Generic code handling requests that have struct mdt_body passed in:
2423 * - extract mdt_body from request and save it in @info, if present;
2425 * - create lu_object, corresponding to the fid in mdt_body, and save it in
2428 * - if HABEO_CORPUS flag is set for this request type check whether object
2429 * actually exists on storage (lu_object_exists()).
2432 static int mdt_body_unpack(struct mdt_thread_info *info, __u32 flags)
2434 const struct mdt_body *body;
2435 struct mdt_object *obj;
2436 const struct lu_env *env;
2437 struct req_capsule *pill;
2441 env = info->mti_env;
2442 pill = info->mti_pill;
2444 body = info->mti_body = req_capsule_client_get(pill, &RMF_MDT_BODY);
2448 if (!(body->valid & OBD_MD_FLID))
2451 if (!fid_is_sane(&body->fid1)) {
2452 CERROR("Invalid fid: "DFID"\n", PFID(&body->fid1));
2457 * Do not get size or any capa fields before we check that request
2458 * contains capa actually. There are some requests which do not, for
2459 * instance MDS_IS_SUBDIR.
2461 if (req_capsule_has_field(pill, &RMF_CAPA1, RCL_CLIENT) &&
2462 req_capsule_get_size(pill, &RMF_CAPA1, RCL_CLIENT))
2463 mdt_set_capainfo(info, 0, &body->fid1,
2464 req_capsule_client_get(pill, &RMF_CAPA1));
2466 obj = mdt_object_find(env, info->mti_mdt, &body->fid1);
2468 if ((flags & HABEO_CORPUS) &&
2469 !mdt_object_exists(obj)) {
2470 mdt_object_put(env, obj);
2471 /* for capability renew ENOENT will be handled in
2473 if (body->valid & OBD_MD_FLOSSCAPA)
2478 info->mti_object = obj;
2487 static int mdt_unpack_req_pack_rep(struct mdt_thread_info *info, __u32 flags)
2489 struct req_capsule *pill = info->mti_pill;
2493 if (req_capsule_has_field(pill, &RMF_MDT_BODY, RCL_CLIENT))
2494 rc = mdt_body_unpack(info, flags);
2498 if (rc == 0 && (flags & HABEO_REFERO)) {
2499 struct mdt_device *mdt = info->mti_mdt;
2503 if (req_capsule_has_field(pill, &RMF_MDT_MD, RCL_SERVER))
2504 req_capsule_set_size(pill, &RMF_MDT_MD, RCL_SERVER,
2505 mdt->mdt_max_mdsize);
2506 if (req_capsule_has_field(pill, &RMF_LOGCOOKIES, RCL_SERVER))
2507 req_capsule_set_size(pill, &RMF_LOGCOOKIES, RCL_SERVER,
2508 mdt->mdt_max_cookiesize);
2510 rc = req_capsule_server_pack(pill);
2515 static int mdt_init_capa_ctxt(const struct lu_env *env, struct mdt_device *m)
2517 struct md_device *next = m->mdt_child;
2519 return next->md_ops->mdo_init_capa_ctxt(env, next,
2520 m->mdt_opts.mo_mds_capa,
2521 m->mdt_capa_timeout,
2527 * Invoke handler for this request opc. Also do necessary preprocessing
2528 * (according to handler ->mh_flags), and post-processing (setting of
2529 * ->last_{xid,committed}).
2531 static int mdt_req_handle(struct mdt_thread_info *info,
2532 struct mdt_handler *h, struct ptlrpc_request *req)
2534 int rc, serious = 0;
2539 LASSERT(h->mh_act != NULL);
2540 LASSERT(h->mh_opc == lustre_msg_get_opc(req->rq_reqmsg));
2541 LASSERT(current->journal_info == NULL);
2544 * Checking for various OBD_FAIL_$PREF_$OPC_NET codes. _Do_ not try
2545 * to put same checks into handlers like mdt_close(), mdt_reint(),
2546 * etc., without talking to mdt authors first. Checking same thing
2547 * there again is useless and returning 0 error without packing reply
2548 * is buggy! Handlers either pack reply or return error.
2550 * We return 0 here and do not send any reply in order to emulate
2551 * network failure. Do not send any reply in case any of NET related
2552 * fail_id has occured.
2554 if (OBD_FAIL_CHECK_ORSET(h->mh_fail_id, OBD_FAIL_ONCE))
2558 flags = h->mh_flags;
2559 LASSERT(ergo(flags & (HABEO_CORPUS|HABEO_REFERO), h->mh_fmt != NULL));
2561 if (h->mh_fmt != NULL) {
2562 req_capsule_set(info->mti_pill, h->mh_fmt);
2563 rc = mdt_unpack_req_pack_rep(info, flags);
2566 if (rc == 0 && flags & MUTABOR &&
2567 req->rq_export->exp_connect_flags & OBD_CONNECT_RDONLY)
2568 /* should it be rq_status? */
2571 if (rc == 0 && flags & HABEO_CLAVIS) {
2572 struct ldlm_request *dlm_req;
2574 LASSERT(h->mh_fmt != NULL);
2576 dlm_req = req_capsule_client_get(info->mti_pill, &RMF_DLM_REQ);
2577 if (dlm_req != NULL) {
2578 if (unlikely(dlm_req->lock_desc.l_resource.lr_type ==
2580 dlm_req->lock_desc.l_policy_data.\
2581 l_inodebits.bits == 0)) {
2583 * Lock without inodebits makes no sense and
2584 * will oops later in ldlm. If client miss to
2585 * set such bits, do not trigger ASSERTION.
2587 * For liblustre flock case, it maybe zero.
2591 if (info->mti_mdt->mdt_opts.mo_compat_resname)
2592 rc = mdt_lock_resname_compat(
2595 info->mti_dlm_req = dlm_req;
2602 /* capability setting changed via /proc, needs reinitialize ctxt */
2603 if (info->mti_mdt && info->mti_mdt->mdt_capa_conf) {
2604 mdt_init_capa_ctxt(info->mti_env, info->mti_mdt);
2605 info->mti_mdt->mdt_capa_conf = 0;
2608 if (likely(rc == 0)) {
2610 * Process request, there can be two types of rc:
2611 * 1) errors with msg unpack/pack, other failures outside the
2612 * operation itself. This is counted as serious errors;
2613 * 2) errors during fs operation, should be placed in rq_status
2616 rc = h->mh_act(info);
2618 !req->rq_no_reply && req->rq_reply_state == NULL) {
2619 DEBUG_REQ(D_ERROR, req, "MDT \"handler\" %s did not "
2620 "pack reply and returned 0 error\n",
2624 serious = is_serious(rc);
2625 rc = clear_serious(rc);
2629 req->rq_status = rc;
2632 * ELDLM_* codes which > 0 should be in rq_status only as well as
2633 * all non-serious errors.
2635 if (rc > 0 || !serious)
2638 LASSERT(current->journal_info == NULL);
2640 if (rc == 0 && (flags & HABEO_CLAVIS) &&
2641 info->mti_mdt->mdt_opts.mo_compat_resname) {
2642 struct ldlm_reply *dlmrep;
2644 dlmrep = req_capsule_server_get(info->mti_pill, &RMF_DLM_REP);
2646 rc = mdt_lock_reply_compat(info->mti_mdt, dlmrep);
2649 /* If we're DISCONNECTing, the mdt_export_data is already freed */
2650 if (likely(rc == 0 && req->rq_export && h->mh_opc != MDS_DISCONNECT))
2651 target_committed_to_req(req);
2653 if (unlikely(req_is_replay(req) &&
2654 lustre_msg_get_transno(req->rq_reqmsg) == 0)) {
2655 DEBUG_REQ(D_ERROR, req, "transno is 0 during REPLAY");
2659 target_send_reply(req, rc, info->mti_fail_id);
2663 void mdt_lock_handle_init(struct mdt_lock_handle *lh)
2665 lh->mlh_type = MDT_NUL_LOCK;
2666 lh->mlh_reg_lh.cookie = 0ull;
2667 lh->mlh_reg_mode = LCK_MINMODE;
2668 lh->mlh_pdo_lh.cookie = 0ull;
2669 lh->mlh_pdo_mode = LCK_MINMODE;
2672 void mdt_lock_handle_fini(struct mdt_lock_handle *lh)
2674 LASSERT(!lustre_handle_is_used(&lh->mlh_reg_lh));
2675 LASSERT(!lustre_handle_is_used(&lh->mlh_pdo_lh));
2679 * Initialize fields of struct mdt_thread_info. Other fields are left in
2680 * uninitialized state, because it's too expensive to zero out whole
2681 * mdt_thread_info (> 1K) on each request arrival.
2683 static void mdt_thread_info_init(struct ptlrpc_request *req,
2684 struct mdt_thread_info *info)
2687 struct md_capainfo *ci;
2689 req_capsule_init(&req->rq_pill, req, RCL_SERVER);
2690 info->mti_pill = &req->rq_pill;
2693 for (i = 0; i < ARRAY_SIZE(info->mti_lh); i++)
2694 mdt_lock_handle_init(&info->mti_lh[i]);
2696 /* mdt device: it can be NULL while CONNECT */
2697 if (req->rq_export) {
2698 info->mti_mdt = mdt_dev(req->rq_export->exp_obd->obd_lu_dev);
2699 info->mti_exp = req->rq_export;
2701 info->mti_mdt = NULL;
2702 info->mti_env = req->rq_svc_thread->t_env;
2703 ci = md_capainfo(info->mti_env);
2704 memset(ci, 0, sizeof *ci);
2705 if (req->rq_export) {
2706 if (exp_connect_rmtclient(req->rq_export))
2707 ci->mc_auth = LC_ID_CONVERT;
2708 else if (req->rq_export->exp_connect_flags &
2709 OBD_CONNECT_MDS_CAPA)
2710 ci->mc_auth = LC_ID_PLAIN;
2712 ci->mc_auth = LC_ID_NONE;
2715 info->mti_fail_id = OBD_FAIL_MDS_ALL_REPLY_NET;
2716 info->mti_transno = lustre_msg_get_transno(req->rq_reqmsg);
2717 info->mti_mos = NULL;
2719 memset(&info->mti_attr, 0, sizeof(info->mti_attr));
2720 info->mti_body = NULL;
2721 info->mti_object = NULL;
2722 info->mti_dlm_req = NULL;
2723 info->mti_has_trans = 0;
2724 info->mti_no_need_trans = 0;
2725 info->mti_cross_ref = 0;
2726 info->mti_opdata = 0;
2728 /* To not check for split by default. */
2729 info->mti_spec.sp_ck_split = 0;
2730 info->mti_spec.no_create = 0;
2733 static void mdt_thread_info_fini(struct mdt_thread_info *info)
2737 req_capsule_fini(info->mti_pill);
2738 if (info->mti_object != NULL) {
2740 * freeing an object may lead to OSD level transaction, do not
2741 * let it mess with MDT. bz19385.
2743 info->mti_no_need_trans = 1;
2744 mdt_object_put(info->mti_env, info->mti_object);
2745 info->mti_object = NULL;
2747 for (i = 0; i < ARRAY_SIZE(info->mti_lh); i++)
2748 mdt_lock_handle_fini(&info->mti_lh[i]);
2749 info->mti_env = NULL;
2752 static int mdt_filter_recovery_request(struct ptlrpc_request *req,
2753 struct obd_device *obd, int *process)
2755 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
2756 case MDS_CONNECT: /* This will never get here, but for completeness. */
2757 case OST_CONNECT: /* This will never get here, but for completeness. */
2758 case MDS_DISCONNECT:
2759 case OST_DISCONNECT:
2764 case MDS_DONE_WRITING:
2765 case MDS_SYNC: /* used in unmounting */
2771 *process = target_queue_recovery_request(req, obd);
2775 DEBUG_REQ(D_ERROR, req, "not permitted during recovery");
2782 * Handle recovery. Return:
2783 * +1: continue request processing;
2784 * -ve: abort immediately with the given error code;
2785 * 0: send reply with error code in req->rq_status;
2787 static int mdt_recovery(struct mdt_thread_info *info)
2789 struct ptlrpc_request *req = mdt_info_req(info);
2790 struct obd_device *obd;
2794 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
2797 case SEC_CTX_INIT_CONT:
2803 rc = mdt_handle_idmap(info);
2812 if (unlikely(!class_connected_export(req->rq_export))) {
2813 CERROR("operation %d on unconnected MDS from %s\n",
2814 lustre_msg_get_opc(req->rq_reqmsg),
2815 libcfs_id2str(req->rq_peer));
2816 /* FIXME: For CMD cleanup, when mds_B stop, the req from
2817 * mds_A will get -ENOTCONN(especially for ping req),
2818 * which will cause that mds_A deactive timeout, then when
2819 * mds_A cleanup, the cleanup process will be suspended since
2820 * deactive timeout is not zero.
2822 req->rq_status = -ENOTCONN;
2823 target_send_reply(req, -ENOTCONN, info->mti_fail_id);
2827 /* sanity check: if the xid matches, the request must be marked as a
2828 * resent or replayed */
2829 if (req_xid_is_last(req)) {
2830 if (!(lustre_msg_get_flags(req->rq_reqmsg) &
2831 (MSG_RESENT | MSG_REPLAY))) {
2832 DEBUG_REQ(D_WARNING, req, "rq_xid "LPU64" matches last_xid, "
2833 "expected REPLAY or RESENT flag (%x)", req->rq_xid,
2834 lustre_msg_get_flags(req->rq_reqmsg));
2836 req->rq_status = -ENOTCONN;
2841 /* else: note the opposite is not always true; a RESENT req after a
2842 * failover will usually not match the last_xid, since it was likely
2843 * never committed. A REPLAYed request will almost never match the
2844 * last xid, however it could for a committed, but still retained,
2847 obd = req->rq_export->exp_obd;
2849 /* Check for aborted recovery... */
2850 if (unlikely(obd->obd_recovering)) {
2853 DEBUG_REQ(D_INFO, req, "Got new replay");
2854 rc = mdt_filter_recovery_request(req, obd, &should_process);
2855 if (rc != 0 || !should_process)
2857 else if (should_process < 0) {
2858 req->rq_status = should_process;
2859 rc = ptlrpc_error(req);
2866 static int mdt_msg_check_version(struct lustre_msg *msg)
2870 switch (lustre_msg_get_opc(msg)) {
2872 case MDS_DISCONNECT:
2875 case SEC_CTX_INIT_CONT:
2877 rc = lustre_msg_check_version(msg, LUSTRE_OBD_VERSION);
2879 CERROR("bad opc %u version %08x, expecting %08x\n",
2880 lustre_msg_get_opc(msg),
2881 lustre_msg_get_version(msg),
2882 LUSTRE_OBD_VERSION);
2886 case MDS_GETATTR_NAME:
2893 case MDS_DONE_WRITING:
2900 case MDS_QUOTACHECK:
2906 rc = lustre_msg_check_version(msg, LUSTRE_MDS_VERSION);
2908 CERROR("bad opc %u version %08x, expecting %08x\n",
2909 lustre_msg_get_opc(msg),
2910 lustre_msg_get_version(msg),
2911 LUSTRE_MDS_VERSION);
2915 case LDLM_BL_CALLBACK:
2916 case LDLM_CP_CALLBACK:
2917 rc = lustre_msg_check_version(msg, LUSTRE_DLM_VERSION);
2919 CERROR("bad opc %u version %08x, expecting %08x\n",
2920 lustre_msg_get_opc(msg),
2921 lustre_msg_get_version(msg),
2922 LUSTRE_DLM_VERSION);
2924 case OBD_LOG_CANCEL:
2925 case LLOG_ORIGIN_HANDLE_CREATE:
2926 case LLOG_ORIGIN_HANDLE_NEXT_BLOCK:
2927 case LLOG_ORIGIN_HANDLE_READ_HEADER:
2928 case LLOG_ORIGIN_HANDLE_CLOSE:
2929 case LLOG_ORIGIN_HANDLE_DESTROY:
2930 case LLOG_ORIGIN_HANDLE_PREV_BLOCK:
2932 rc = lustre_msg_check_version(msg, LUSTRE_LOG_VERSION);
2934 CERROR("bad opc %u version %08x, expecting %08x\n",
2935 lustre_msg_get_opc(msg),
2936 lustre_msg_get_version(msg),
2937 LUSTRE_LOG_VERSION);
2940 CERROR("MDS unknown opcode %d\n", lustre_msg_get_opc(msg));
2946 static int mdt_handle0(struct ptlrpc_request *req,
2947 struct mdt_thread_info *info,
2948 struct mdt_opc_slice *supported)
2950 struct mdt_handler *h;
2951 struct lustre_msg *msg;
2956 if (OBD_FAIL_CHECK_ORSET(OBD_FAIL_MDS_ALL_REQUEST_NET, OBD_FAIL_ONCE))
2959 LASSERT(current->journal_info == NULL);
2961 msg = req->rq_reqmsg;
2962 rc = mdt_msg_check_version(msg);
2963 if (likely(rc == 0)) {
2964 rc = mdt_recovery(info);
2965 if (likely(rc == +1)) {
2966 h = mdt_handler_find(lustre_msg_get_opc(msg),
2968 if (likely(h != NULL)) {
2969 rc = mdt_req_handle(info, h, req);
2971 CERROR("The unsupported opc: 0x%x\n",
2972 lustre_msg_get_opc(msg) );
2973 req->rq_status = -ENOTSUPP;
2974 rc = ptlrpc_error(req);
2979 CERROR(LUSTRE_MDT_NAME" drops mal-formed request\n");
2984 * MDT handler function called by ptlrpc service thread when request comes.
2986 * XXX common "target" functionality should be factored into separate module
2987 * shared by mdt, ost and stand-alone services like fld.
2989 static int mdt_handle_common(struct ptlrpc_request *req,
2990 struct mdt_opc_slice *supported)
2993 struct mdt_thread_info *info;
2997 env = req->rq_svc_thread->t_env;
2998 LASSERT(env != NULL);
2999 LASSERT(env->le_ses != NULL);
3000 LASSERT(env->le_ctx.lc_thread == req->rq_svc_thread);
3001 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
3002 LASSERT(info != NULL);
3004 mdt_thread_info_init(req, info);
3006 rc = mdt_handle0(req, info, supported);
3008 mdt_thread_info_fini(info);
3013 * This is called from recovery code as handler of _all_ RPC types, FLD and SEQ
3016 int mdt_recovery_handle(struct ptlrpc_request *req)
3021 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
3023 rc = mdt_handle_common(req, mdt_fld_handlers);
3026 rc = mdt_handle_common(req, mdt_seq_handlers);
3029 rc = mdt_handle_common(req, mdt_regular_handlers);
3036 static int mdt_regular_handle(struct ptlrpc_request *req)
3038 return mdt_handle_common(req, mdt_regular_handlers);
3041 static int mdt_readpage_handle(struct ptlrpc_request *req)
3043 return mdt_handle_common(req, mdt_readpage_handlers);
3046 static int mdt_xmds_handle(struct ptlrpc_request *req)
3048 return mdt_handle_common(req, mdt_xmds_handlers);
3051 static int mdt_mdsc_handle(struct ptlrpc_request *req)
3053 return mdt_handle_common(req, mdt_seq_handlers);
3056 static int mdt_mdss_handle(struct ptlrpc_request *req)
3058 return mdt_handle_common(req, mdt_seq_handlers);
3061 static int mdt_dtss_handle(struct ptlrpc_request *req)
3063 return mdt_handle_common(req, mdt_seq_handlers);
3066 static int mdt_fld_handle(struct ptlrpc_request *req)
3068 return mdt_handle_common(req, mdt_fld_handlers);
3084 static int mdt_intent_getattr(enum mdt_it_code opcode,
3085 struct mdt_thread_info *info,
3086 struct ldlm_lock **,
3088 static int mdt_intent_reint(enum mdt_it_code opcode,
3089 struct mdt_thread_info *info,
3090 struct ldlm_lock **,
3093 static struct mdt_it_flavor {
3094 const struct req_format *it_fmt;
3096 int (*it_act)(enum mdt_it_code ,
3097 struct mdt_thread_info *,
3098 struct ldlm_lock **,
3101 } mdt_it_flavor[] = {
3103 .it_fmt = &RQF_LDLM_INTENT,
3104 /*.it_flags = HABEO_REFERO,*/
3106 .it_act = mdt_intent_reint,
3107 .it_reint = REINT_OPEN
3110 .it_fmt = &RQF_LDLM_INTENT,
3111 .it_flags = MUTABOR,
3112 .it_act = mdt_intent_reint,
3113 .it_reint = REINT_OPEN
3116 .it_fmt = &RQF_LDLM_INTENT,
3117 .it_flags = MUTABOR,
3118 .it_act = mdt_intent_reint,
3119 .it_reint = REINT_CREATE
3121 [MDT_IT_GETATTR] = {
3122 .it_fmt = &RQF_LDLM_INTENT_GETATTR,
3123 .it_flags = HABEO_REFERO,
3124 .it_act = mdt_intent_getattr
3126 [MDT_IT_READDIR] = {
3132 .it_fmt = &RQF_LDLM_INTENT_GETATTR,
3133 .it_flags = HABEO_REFERO,
3134 .it_act = mdt_intent_getattr
3137 .it_fmt = &RQF_LDLM_INTENT_UNLINK,
3138 .it_flags = MUTABOR,
3140 .it_reint = REINT_UNLINK
3144 .it_flags = MUTABOR,
3147 [MDT_IT_GETXATTR] = {
3154 int mdt_intent_lock_replace(struct mdt_thread_info *info,
3155 struct ldlm_lock **lockp,
3156 struct ldlm_lock *new_lock,
3157 struct mdt_lock_handle *lh,
3160 struct ptlrpc_request *req = mdt_info_req(info);
3161 struct ldlm_lock *lock = *lockp;
3164 * Get new lock only for cases when possible resent did not find any
3167 if (new_lock == NULL)
3168 new_lock = ldlm_handle2lock_long(&lh->mlh_reg_lh, 0);
3170 if (new_lock == NULL && (flags & LDLM_FL_INTENT_ONLY)) {
3171 lh->mlh_reg_lh.cookie = 0;
3175 LASSERTF(new_lock != NULL,
3176 "lockh "LPX64"\n", lh->mlh_reg_lh.cookie);
3179 * If we've already given this lock to a client once, then we should
3180 * have no readers or writers. Otherwise, we should have one reader
3181 * _or_ writer ref (which will be zeroed below) before returning the
3184 if (new_lock->l_export == req->rq_export) {
3185 LASSERT(new_lock->l_readers + new_lock->l_writers == 0);
3187 LASSERT(new_lock->l_export == NULL);
3188 LASSERT(new_lock->l_readers + new_lock->l_writers == 1);
3193 if (new_lock->l_export == req->rq_export) {
3195 * Already gave this to the client, which means that we
3196 * reconstructed a reply.
3198 LASSERT(lustre_msg_get_flags(req->rq_reqmsg) &
3200 lh->mlh_reg_lh.cookie = 0;
3201 RETURN(ELDLM_LOCK_REPLACED);
3205 * Fixup the lock to be given to the client.
3207 lock_res_and_lock(new_lock);
3208 /* Zero new_lock->l_readers and new_lock->l_writers without triggering
3209 * possible blocking AST. */
3210 while (new_lock->l_readers > 0) {
3211 lu_ref_del(&new_lock->l_reference, "reader", new_lock);
3212 lu_ref_del(&new_lock->l_reference, "user", new_lock);
3213 new_lock->l_readers--;
3215 while (new_lock->l_writers > 0) {
3216 lu_ref_del(&new_lock->l_reference, "writer", new_lock);
3217 lu_ref_del(&new_lock->l_reference, "user", new_lock);
3218 new_lock->l_writers--;
3221 new_lock->l_export = class_export_lock_get(req->rq_export, new_lock);
3222 new_lock->l_blocking_ast = lock->l_blocking_ast;
3223 new_lock->l_completion_ast = lock->l_completion_ast;
3224 new_lock->l_remote_handle = lock->l_remote_handle;
3225 new_lock->l_flags &= ~LDLM_FL_LOCAL;
3227 unlock_res_and_lock(new_lock);
3229 cfs_hash_add(new_lock->l_export->exp_lock_hash,
3230 &new_lock->l_remote_handle,
3231 &new_lock->l_exp_hash);
3233 LDLM_LOCK_RELEASE(new_lock);
3234 lh->mlh_reg_lh.cookie = 0;
3236 RETURN(ELDLM_LOCK_REPLACED);
3239 static void mdt_intent_fixup_resent(struct mdt_thread_info *info,
3240 struct ldlm_lock *new_lock,
3241 struct ldlm_lock **old_lock,
3242 struct mdt_lock_handle *lh)
3244 struct ptlrpc_request *req = mdt_info_req(info);
3245 struct obd_export *exp = req->rq_export;
3246 struct lustre_handle remote_hdl;
3247 struct ldlm_request *dlmreq;
3248 struct ldlm_lock *lock;
3250 if (!(lustre_msg_get_flags(req->rq_reqmsg) & MSG_RESENT))
3253 dlmreq = req_capsule_client_get(info->mti_pill, &RMF_DLM_REQ);
3254 remote_hdl = dlmreq->lock_handle[0];
3256 lock = cfs_hash_lookup(exp->exp_lock_hash, &remote_hdl);
3258 if (lock != new_lock) {
3259 lh->mlh_reg_lh.cookie = lock->l_handle.h_cookie;
3260 lh->mlh_reg_mode = lock->l_granted_mode;
3262 LDLM_DEBUG(lock, "Restoring lock cookie");
3263 DEBUG_REQ(D_DLMTRACE, req,
3264 "restoring lock cookie "LPX64,
3265 lh->mlh_reg_lh.cookie);
3267 *old_lock = LDLM_LOCK_GET(lock);
3268 cfs_hash_put(exp->exp_lock_hash, &lock->l_exp_hash);
3272 cfs_hash_put(exp->exp_lock_hash, &lock->l_exp_hash);
3276 * If the xid matches, then we know this is a resent request, and allow
3277 * it. (It's probably an OPEN, for which we don't send a lock.
3279 if (req_xid_is_last(req))
3283 * This remote handle isn't enqueued, so we never received or processed
3284 * this request. Clear MSG_RESENT, because it can be handled like any
3285 * normal request now.
3287 lustre_msg_clear_flags(req->rq_reqmsg, MSG_RESENT);
3289 DEBUG_REQ(D_DLMTRACE, req, "no existing lock with rhandle "LPX64,
3293 static int mdt_intent_getattr(enum mdt_it_code opcode,
3294 struct mdt_thread_info *info,
3295 struct ldlm_lock **lockp,
3298 struct mdt_lock_handle *lhc = &info->mti_lh[MDT_LH_RMT];
3299 struct ldlm_lock *new_lock = NULL;
3301 struct ldlm_reply *ldlm_rep;
3302 struct ptlrpc_request *req;
3303 struct mdt_body *reqbody;
3304 struct mdt_body *repbody;
3308 reqbody = req_capsule_client_get(info->mti_pill, &RMF_MDT_BODY);
3311 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
3314 info->mti_spec.sp_ck_split = !!(reqbody->valid & OBD_MD_FLCKSPLIT);
3315 info->mti_cross_ref = !!(reqbody->valid & OBD_MD_FLCROSSREF);
3316 repbody->eadatasize = 0;
3317 repbody->aclsize = 0;
3321 child_bits = MDS_INODELOCK_LOOKUP;
3323 case MDT_IT_GETATTR:
3324 child_bits = MDS_INODELOCK_LOOKUP | MDS_INODELOCK_UPDATE;
3327 CERROR("Unhandled till now");
3328 GOTO(out_shrink, rc = -EINVAL);
3331 rc = mdt_init_ucred(info, reqbody);
3333 GOTO(out_shrink, rc);
3335 req = info->mti_pill->rc_req;
3336 ldlm_rep = req_capsule_server_get(info->mti_pill, &RMF_DLM_REP);
3337 mdt_set_disposition(info, ldlm_rep, DISP_IT_EXECD);
3339 /* Get lock from request for possible resent case. */
3340 mdt_intent_fixup_resent(info, *lockp, &new_lock, lhc);
3342 ldlm_rep->lock_policy_res2 =
3343 mdt_getattr_name_lock(info, lhc, child_bits, ldlm_rep);
3345 if (mdt_get_disposition(ldlm_rep, DISP_LOOKUP_NEG))
3346 ldlm_rep->lock_policy_res2 = 0;
3347 if (!mdt_get_disposition(ldlm_rep, DISP_LOOKUP_POS) ||
3348 ldlm_rep->lock_policy_res2) {
3349 lhc->mlh_reg_lh.cookie = 0ull;
3350 GOTO(out_ucred, rc = ELDLM_LOCK_ABORTED);
3353 rc = mdt_intent_lock_replace(info, lockp, new_lock, lhc, flags);
3356 mdt_exit_ucred(info);
3358 mdt_shrink_reply(info);
3362 static int mdt_intent_reint(enum mdt_it_code opcode,
3363 struct mdt_thread_info *info,
3364 struct ldlm_lock **lockp,
3367 struct mdt_lock_handle *lhc = &info->mti_lh[MDT_LH_RMT];
3368 struct ldlm_reply *rep = NULL;
3372 static const struct req_format *intent_fmts[REINT_MAX] = {
3373 [REINT_CREATE] = &RQF_LDLM_INTENT_CREATE,
3374 [REINT_OPEN] = &RQF_LDLM_INTENT_OPEN
3379 opc = mdt_reint_opcode(info, intent_fmts);
3383 if (mdt_it_flavor[opcode].it_reint != opc) {
3384 CERROR("Reint code %ld doesn't match intent: %d\n",
3386 RETURN(err_serious(-EPROTO));
3389 /* Get lock from request for possible resent case. */
3390 mdt_intent_fixup_resent(info, *lockp, NULL, lhc);
3392 rc = mdt_reint_internal(info, lhc, opc);
3394 /* Check whether the reply has been packed successfully. */
3395 if (mdt_info_req(info)->rq_repmsg != NULL)
3396 rep = req_capsule_server_get(info->mti_pill, &RMF_DLM_REP);
3398 RETURN(err_serious(-EFAULT));
3400 /* MDC expects this in any case */
3402 mdt_set_disposition(info, rep, DISP_LOOKUP_EXECD);
3404 /* Cross-ref case, the lock should be returned to the client */
3405 if (rc == -EREMOTE) {
3406 LASSERT(lustre_handle_is_used(&lhc->mlh_reg_lh));
3407 rep->lock_policy_res2 = 0;
3408 rc = mdt_intent_lock_replace(info, lockp, NULL, lhc, flags);
3411 rep->lock_policy_res2 = clear_serious(rc);
3413 if (rc == -ENOTCONN || rc == -ENODEV ||
3414 rc == -EOVERFLOW) { /**< if VBR failure then return error */
3416 * If it is the disconnect error (ENODEV & ENOCONN), the error
3417 * will be returned by rq_status, and client at ptlrpc layer
3418 * will detect this, then disconnect, reconnect the import
3419 * immediately, instead of impacting the following the rpc.
3421 lhc->mlh_reg_lh.cookie = 0ull;
3425 * For other cases, the error will be returned by intent.
3426 * and client will retrieve the result from intent.
3429 * FIXME: when open lock is finished, that should be
3432 if (lustre_handle_is_used(&lhc->mlh_reg_lh)) {
3433 LASSERTF(rc == 0, "Error occurred but lock handle "
3434 "is still in use\n");
3435 rep->lock_policy_res2 = 0;
3436 rc = mdt_intent_lock_replace(info, lockp, NULL, lhc, flags);
3439 lhc->mlh_reg_lh.cookie = 0ull;
3440 RETURN(ELDLM_LOCK_ABORTED);
3445 static int mdt_intent_code(long itcode)
3453 case IT_OPEN|IT_CREAT:
3460 rc = MDT_IT_READDIR;
3463 rc = MDT_IT_GETATTR;
3475 rc = MDT_IT_GETXATTR;
3478 CERROR("Unknown intent opcode: %ld\n", itcode);
3485 static int mdt_intent_opc(long itopc, struct mdt_thread_info *info,
3486 struct ldlm_lock **lockp, int flags)
3488 struct req_capsule *pill;
3489 struct mdt_it_flavor *flv;
3494 opc = mdt_intent_code(itopc);
3498 pill = info->mti_pill;
3499 flv = &mdt_it_flavor[opc];
3501 if (flv->it_fmt != NULL)
3502 req_capsule_extend(pill, flv->it_fmt);
3504 rc = mdt_unpack_req_pack_rep(info, flv->it_flags);
3506 struct ptlrpc_request *req = mdt_info_req(info);
3507 if (flv->it_flags & MUTABOR &&
3508 req->rq_export->exp_connect_flags & OBD_CONNECT_RDONLY)
3511 if (rc == 0 && flv->it_act != NULL) {
3512 /* execute policy */
3513 rc = flv->it_act(opc, info, lockp, flags);
3520 static int mdt_intent_policy(struct ldlm_namespace *ns,
3521 struct ldlm_lock **lockp, void *req_cookie,
3522 ldlm_mode_t mode, int flags, void *data)
3524 struct mdt_thread_info *info;
3525 struct ptlrpc_request *req = req_cookie;
3526 struct ldlm_intent *it;
3527 struct req_capsule *pill;
3532 LASSERT(req != NULL);
3534 info = lu_context_key_get(&req->rq_svc_thread->t_env->le_ctx,
3536 LASSERT(info != NULL);
3537 pill = info->mti_pill;
3538 LASSERT(pill->rc_req == req);
3540 if (req->rq_reqmsg->lm_bufcount > DLM_INTENT_IT_OFF) {
3541 req_capsule_extend(pill, &RQF_LDLM_INTENT);
3542 it = req_capsule_client_get(pill, &RMF_LDLM_INTENT);
3544 rc = mdt_intent_opc(it->opc, info, lockp, flags);
3548 /* Lock without inodebits makes no sense and will oops
3549 * later in ldlm. Let's check it now to see if we have
3550 * ibits corrupted somewhere in mdt_intent_opc().
3551 * The case for client miss to set ibits has been
3552 * processed by others. */
3553 LASSERT(ergo(info->mti_dlm_req->lock_desc.l_resource.\
3554 lr_type == LDLM_IBITS,
3555 info->mti_dlm_req->lock_desc.\
3556 l_policy_data.l_inodebits.bits != 0));
3558 rc = err_serious(-EFAULT);
3560 /* No intent was provided */
3561 LASSERT(pill->rc_fmt == &RQF_LDLM_ENQUEUE);
3562 rc = req_capsule_server_pack(pill);
3564 rc = err_serious(rc);
3569 static int mdt_seq_fini(const struct lu_env *env,
3570 struct mdt_device *m)
3572 struct md_site *ms = mdt_md_site(m);
3576 if (ms->ms_server_seq) {
3577 seq_server_fini(ms->ms_server_seq, env);
3578 OBD_FREE_PTR(ms->ms_server_seq);
3579 ms->ms_server_seq = NULL;
3582 if (ms->ms_control_seq) {
3583 seq_server_fini(ms->ms_control_seq, env);
3584 OBD_FREE_PTR(ms->ms_control_seq);
3585 ms->ms_control_seq = NULL;
3588 if (ms->ms_client_seq) {
3589 seq_client_fini(ms->ms_client_seq);
3590 OBD_FREE_PTR(ms->ms_client_seq);
3591 ms->ms_client_seq = NULL;
3598 static int mdt_seq_init(const struct lu_env *env,
3600 struct mdt_device *m)
3607 ms = mdt_md_site(m);
3610 * This is sequence-controller node. Init seq-controller server on local
3613 if (ms->ms_node_id == 0) {
3614 LASSERT(ms->ms_control_seq == NULL);
3616 OBD_ALLOC_PTR(ms->ms_control_seq);
3617 if (ms->ms_control_seq == NULL)
3620 rc = seq_server_init(ms->ms_control_seq,
3621 m->mdt_bottom, uuid,
3622 LUSTRE_SEQ_CONTROLLER,
3627 GOTO(out_seq_fini, rc);
3629 OBD_ALLOC_PTR(ms->ms_client_seq);
3630 if (ms->ms_client_seq == NULL)
3631 GOTO(out_seq_fini, rc = -ENOMEM);
3633 OBD_ALLOC(prefix, MAX_OBD_NAME + 5);
3634 if (prefix == NULL) {
3635 OBD_FREE_PTR(ms->ms_client_seq);
3636 GOTO(out_seq_fini, rc = -ENOMEM);
3639 snprintf(prefix, MAX_OBD_NAME + 5, "ctl-%s",
3643 * Init seq-controller client after seq-controller server is
3644 * ready. Pass ms->ms_control_seq to it for direct talking.
3646 rc = seq_client_init(ms->ms_client_seq, NULL,
3647 LUSTRE_SEQ_METADATA, prefix,
3648 ms->ms_control_seq);
3649 OBD_FREE(prefix, MAX_OBD_NAME + 5);
3652 GOTO(out_seq_fini, rc);
3655 /* Init seq-server on local MDT */
3656 LASSERT(ms->ms_server_seq == NULL);
3658 OBD_ALLOC_PTR(ms->ms_server_seq);
3659 if (ms->ms_server_seq == NULL)
3660 GOTO(out_seq_fini, rc = -ENOMEM);
3662 rc = seq_server_init(ms->ms_server_seq,
3663 m->mdt_bottom, uuid,
3668 GOTO(out_seq_fini, rc = -ENOMEM);
3670 /* Assign seq-controller client to local seq-server. */
3671 if (ms->ms_node_id == 0) {
3672 LASSERT(ms->ms_client_seq != NULL);
3674 rc = seq_server_set_cli(ms->ms_server_seq,
3682 mdt_seq_fini(env, m);
3687 * Init client sequence manager which is used by local MDS to talk to sequence
3688 * controller on remote node.
3690 static int mdt_seq_init_cli(const struct lu_env *env,
3691 struct mdt_device *m,
3692 struct lustre_cfg *cfg)
3694 struct md_site *ms = mdt_md_site(m);
3695 struct obd_device *mdc;
3696 struct obd_uuid *uuidp, *mdcuuidp;
3697 char *uuid_str, *mdc_uuid_str;
3700 struct mdt_thread_info *info;
3701 char *p, *index_string = lustre_cfg_string(cfg, 2);
3704 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
3705 uuidp = &info->mti_u.uuid[0];
3706 mdcuuidp = &info->mti_u.uuid[1];
3708 LASSERT(index_string);
3710 index = simple_strtol(index_string, &p, 10);
3712 CERROR("Invalid index in lustre_cgf, offset 2\n");
3716 /* check if this is adding the first MDC and controller is not yet
3718 if (index != 0 || ms->ms_client_seq)
3721 uuid_str = lustre_cfg_string(cfg, 1);
3722 mdc_uuid_str = lustre_cfg_string(cfg, 4);
3723 obd_str2uuid(uuidp, uuid_str);
3724 obd_str2uuid(mdcuuidp, mdc_uuid_str);
3726 mdc = class_find_client_obd(uuidp, LUSTRE_MDC_NAME, mdcuuidp);
3728 CERROR("can't find controller MDC by uuid %s\n",
3731 } else if (!mdc->obd_set_up) {
3732 CERROR("target %s not set up\n", mdc->obd_name);
3735 LASSERT(ms->ms_control_exp);
3736 OBD_ALLOC_PTR(ms->ms_client_seq);
3737 if (ms->ms_client_seq != NULL) {
3740 OBD_ALLOC(prefix, MAX_OBD_NAME + 5);
3744 snprintf(prefix, MAX_OBD_NAME + 5, "ctl-%s",
3747 rc = seq_client_init(ms->ms_client_seq,
3749 LUSTRE_SEQ_METADATA,
3751 OBD_FREE(prefix, MAX_OBD_NAME + 5);
3758 LASSERT(ms->ms_server_seq != NULL);
3759 rc = seq_server_set_cli(ms->ms_server_seq, ms->ms_client_seq,
3766 static void mdt_seq_fini_cli(struct mdt_device *m)
3772 ms = mdt_md_site(m);
3775 if (ms->ms_server_seq)
3776 seq_server_set_cli(ms->ms_server_seq,
3779 if (ms->ms_control_exp) {
3780 class_export_put(ms->ms_control_exp);
3781 ms->ms_control_exp = NULL;
3790 static int mdt_fld_fini(const struct lu_env *env,
3791 struct mdt_device *m)
3793 struct md_site *ms = mdt_md_site(m);
3796 if (ms && ms->ms_server_fld) {
3797 fld_server_fini(ms->ms_server_fld, env);
3798 OBD_FREE_PTR(ms->ms_server_fld);
3799 ms->ms_server_fld = NULL;
3805 static int mdt_fld_init(const struct lu_env *env,
3807 struct mdt_device *m)
3813 ms = mdt_md_site(m);
3815 OBD_ALLOC_PTR(ms->ms_server_fld);
3816 if (ms->ms_server_fld == NULL)
3817 RETURN(rc = -ENOMEM);
3819 rc = fld_server_init(ms->ms_server_fld,
3820 m->mdt_bottom, uuid,
3821 env, ms->ms_node_id);
3823 OBD_FREE_PTR(ms->ms_server_fld);
3824 ms->ms_server_fld = NULL;
3831 /* device init/fini methods */
3832 static void mdt_stop_ptlrpc_service(struct mdt_device *m)
3835 if (m->mdt_regular_service != NULL) {
3836 ptlrpc_unregister_service(m->mdt_regular_service);
3837 m->mdt_regular_service = NULL;
3839 if (m->mdt_readpage_service != NULL) {
3840 ptlrpc_unregister_service(m->mdt_readpage_service);
3841 m->mdt_readpage_service = NULL;
3843 if (m->mdt_xmds_service != NULL) {
3844 ptlrpc_unregister_service(m->mdt_xmds_service);
3845 m->mdt_xmds_service = NULL;
3847 if (m->mdt_setattr_service != NULL) {
3848 ptlrpc_unregister_service(m->mdt_setattr_service);
3849 m->mdt_setattr_service = NULL;
3851 if (m->mdt_mdsc_service != NULL) {
3852 ptlrpc_unregister_service(m->mdt_mdsc_service);
3853 m->mdt_mdsc_service = NULL;
3855 if (m->mdt_mdss_service != NULL) {
3856 ptlrpc_unregister_service(m->mdt_mdss_service);
3857 m->mdt_mdss_service = NULL;
3859 if (m->mdt_dtss_service != NULL) {
3860 ptlrpc_unregister_service(m->mdt_dtss_service);
3861 m->mdt_dtss_service = NULL;
3863 if (m->mdt_fld_service != NULL) {
3864 ptlrpc_unregister_service(m->mdt_fld_service);
3865 m->mdt_fld_service = NULL;
3870 static int mdt_start_ptlrpc_service(struct mdt_device *m)
3873 static struct ptlrpc_service_conf conf;
3874 cfs_proc_dir_entry_t *procfs_entry;
3877 procfs_entry = m->mdt_md_dev.md_lu_dev.ld_obd->obd_proc_entry;
3879 conf = (typeof(conf)) {
3880 .psc_nbufs = MDS_NBUFS,
3881 .psc_bufsize = MDS_BUFSIZE,
3882 .psc_max_req_size = MDS_MAXREQSIZE,
3883 .psc_max_reply_size = MDS_MAXREPSIZE,
3884 .psc_req_portal = MDS_REQUEST_PORTAL,
3885 .psc_rep_portal = MDC_REPLY_PORTAL,
3886 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
3888 * We'd like to have a mechanism to set this on a per-device
3889 * basis, but alas...
3891 .psc_min_threads = mdt_min_threads,
3892 .psc_max_threads = mdt_max_threads,
3893 .psc_ctx_tags = LCT_MD_THREAD
3896 m->mdt_ldlm_client = &m->mdt_md_dev.md_lu_dev.ld_obd->obd_ldlm_client;
3897 ptlrpc_init_client(LDLM_CB_REQUEST_PORTAL, LDLM_CB_REPLY_PORTAL,
3898 "mdt_ldlm_client", m->mdt_ldlm_client);
3900 m->mdt_regular_service =
3901 ptlrpc_init_svc_conf(&conf, mdt_regular_handle, LUSTRE_MDT_NAME,
3902 procfs_entry, target_print_req,
3904 if (m->mdt_regular_service == NULL)
3907 rc = ptlrpc_start_threads(m->mdt_regular_service);
3909 GOTO(err_mdt_svc, rc);
3912 * readpage service configuration. Parameters have to be adjusted,
3915 conf = (typeof(conf)) {
3916 .psc_nbufs = MDS_NBUFS,
3917 .psc_bufsize = MDS_BUFSIZE,
3918 .psc_max_req_size = MDS_MAXREQSIZE,
3919 .psc_max_reply_size = MDS_MAXREPSIZE,
3920 .psc_req_portal = MDS_READPAGE_PORTAL,
3921 .psc_rep_portal = MDC_REPLY_PORTAL,
3922 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
3923 .psc_min_threads = mdt_min_threads,
3924 .psc_max_threads = mdt_max_threads,
3925 .psc_ctx_tags = LCT_MD_THREAD
3927 m->mdt_readpage_service =
3928 ptlrpc_init_svc_conf(&conf, mdt_readpage_handle,
3929 LUSTRE_MDT_NAME "_readpage",
3930 procfs_entry, target_print_req,"mdt_rdpg");
3932 if (m->mdt_readpage_service == NULL) {
3933 CERROR("failed to start readpage service\n");
3934 GOTO(err_mdt_svc, rc = -ENOMEM);
3937 rc = ptlrpc_start_threads(m->mdt_readpage_service);
3940 * setattr service configuration.
3942 conf = (typeof(conf)) {
3943 .psc_nbufs = MDS_NBUFS,
3944 .psc_bufsize = MDS_BUFSIZE,
3945 .psc_max_req_size = MDS_MAXREQSIZE,
3946 .psc_max_reply_size = MDS_MAXREPSIZE,
3947 .psc_req_portal = MDS_SETATTR_PORTAL,
3948 .psc_rep_portal = MDC_REPLY_PORTAL,
3949 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
3950 .psc_min_threads = mdt_min_threads,
3951 .psc_max_threads = mdt_max_threads,
3952 .psc_ctx_tags = LCT_MD_THREAD
3955 m->mdt_setattr_service =
3956 ptlrpc_init_svc_conf(&conf, mdt_regular_handle,
3957 LUSTRE_MDT_NAME "_setattr",
3958 procfs_entry, target_print_req,"mdt_attr");
3960 if (!m->mdt_setattr_service) {
3961 CERROR("failed to start setattr service\n");
3962 GOTO(err_mdt_svc, rc = -ENOMEM);
3965 rc = ptlrpc_start_threads(m->mdt_setattr_service);
3967 GOTO(err_mdt_svc, rc);
3970 * sequence controller service configuration
3972 conf = (typeof(conf)) {
3973 .psc_nbufs = MDS_NBUFS,
3974 .psc_bufsize = MDS_BUFSIZE,
3975 .psc_max_req_size = SEQ_MAXREQSIZE,
3976 .psc_max_reply_size = SEQ_MAXREPSIZE,
3977 .psc_req_portal = SEQ_CONTROLLER_PORTAL,
3978 .psc_rep_portal = MDC_REPLY_PORTAL,
3979 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
3980 .psc_min_threads = mdt_min_threads,
3981 .psc_max_threads = mdt_max_threads,
3982 .psc_ctx_tags = LCT_MD_THREAD|LCT_DT_THREAD
3985 m->mdt_mdsc_service =
3986 ptlrpc_init_svc_conf(&conf, mdt_mdsc_handle,
3987 LUSTRE_MDT_NAME"_mdsc",
3988 procfs_entry, target_print_req,"mdt_mdsc");
3989 if (!m->mdt_mdsc_service) {
3990 CERROR("failed to start seq controller service\n");
3991 GOTO(err_mdt_svc, rc = -ENOMEM);
3994 rc = ptlrpc_start_threads(m->mdt_mdsc_service);
3996 GOTO(err_mdt_svc, rc);
3999 * metadata sequence server service configuration
4001 conf = (typeof(conf)) {
4002 .psc_nbufs = MDS_NBUFS,
4003 .psc_bufsize = MDS_BUFSIZE,
4004 .psc_max_req_size = SEQ_MAXREQSIZE,
4005 .psc_max_reply_size = SEQ_MAXREPSIZE,
4006 .psc_req_portal = SEQ_METADATA_PORTAL,
4007 .psc_rep_portal = MDC_REPLY_PORTAL,
4008 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
4009 .psc_min_threads = mdt_min_threads,
4010 .psc_max_threads = mdt_max_threads,
4011 .psc_ctx_tags = LCT_MD_THREAD|LCT_DT_THREAD
4014 m->mdt_mdss_service =
4015 ptlrpc_init_svc_conf(&conf, mdt_mdss_handle,
4016 LUSTRE_MDT_NAME"_mdss",
4017 procfs_entry, target_print_req,"mdt_mdss");
4018 if (!m->mdt_mdss_service) {
4019 CERROR("failed to start metadata seq server service\n");
4020 GOTO(err_mdt_svc, rc = -ENOMEM);
4023 rc = ptlrpc_start_threads(m->mdt_mdss_service);
4025 GOTO(err_mdt_svc, rc);
4029 * Data sequence server service configuration. We want to have really
4030 * cluster-wide sequences space. This is why we start only one sequence
4031 * controller which manages space.
4033 conf = (typeof(conf)) {
4034 .psc_nbufs = MDS_NBUFS,
4035 .psc_bufsize = MDS_BUFSIZE,
4036 .psc_max_req_size = SEQ_MAXREQSIZE,
4037 .psc_max_reply_size = SEQ_MAXREPSIZE,
4038 .psc_req_portal = SEQ_DATA_PORTAL,
4039 .psc_rep_portal = OSC_REPLY_PORTAL,
4040 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
4041 .psc_min_threads = mdt_min_threads,
4042 .psc_max_threads = mdt_max_threads,
4043 .psc_ctx_tags = LCT_MD_THREAD|LCT_DT_THREAD
4046 m->mdt_dtss_service =
4047 ptlrpc_init_svc_conf(&conf, mdt_dtss_handle,
4048 LUSTRE_MDT_NAME"_dtss",
4049 procfs_entry, target_print_req,"mdt_dtss");
4050 if (!m->mdt_dtss_service) {
4051 CERROR("failed to start data seq server service\n");
4052 GOTO(err_mdt_svc, rc = -ENOMEM);
4055 rc = ptlrpc_start_threads(m->mdt_dtss_service);
4057 GOTO(err_mdt_svc, rc);
4059 /* FLD service start */
4060 conf = (typeof(conf)) {
4061 .psc_nbufs = MDS_NBUFS,
4062 .psc_bufsize = MDS_BUFSIZE,
4063 .psc_max_req_size = FLD_MAXREQSIZE,
4064 .psc_max_reply_size = FLD_MAXREPSIZE,
4065 .psc_req_portal = FLD_REQUEST_PORTAL,
4066 .psc_rep_portal = MDC_REPLY_PORTAL,
4067 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
4068 .psc_min_threads = mdt_min_threads,
4069 .psc_max_threads = mdt_max_threads,
4070 .psc_ctx_tags = LCT_DT_THREAD|LCT_MD_THREAD
4073 m->mdt_fld_service =
4074 ptlrpc_init_svc_conf(&conf, mdt_fld_handle,
4075 LUSTRE_MDT_NAME"_fld",
4076 procfs_entry, target_print_req, "mdt_fld");
4077 if (!m->mdt_fld_service) {
4078 CERROR("failed to start fld service\n");
4079 GOTO(err_mdt_svc, rc = -ENOMEM);
4082 rc = ptlrpc_start_threads(m->mdt_fld_service);
4084 GOTO(err_mdt_svc, rc);
4087 * mds-mds service configuration. Separate portal is used to allow
4088 * mds-mds requests be not blocked during recovery.
4090 conf = (typeof(conf)) {
4091 .psc_nbufs = MDS_NBUFS,
4092 .psc_bufsize = MDS_BUFSIZE,
4093 .psc_max_req_size = MDS_MAXREQSIZE,
4094 .psc_max_reply_size = MDS_MAXREPSIZE,
4095 .psc_req_portal = MDS_MDS_PORTAL,
4096 .psc_rep_portal = MDC_REPLY_PORTAL,
4097 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
4098 .psc_min_threads = mdt_min_threads,
4099 .psc_max_threads = mdt_max_threads,
4100 .psc_ctx_tags = LCT_MD_THREAD
4102 m->mdt_xmds_service =
4103 ptlrpc_init_svc_conf(&conf, mdt_xmds_handle,
4104 LUSTRE_MDT_NAME "_mds",
4105 procfs_entry, target_print_req,"mdt_xmds");
4107 if (m->mdt_xmds_service == NULL) {
4108 CERROR("failed to start xmds service\n");
4109 GOTO(err_mdt_svc, rc = -ENOMEM);
4112 rc = ptlrpc_start_threads(m->mdt_xmds_service);
4114 GOTO(err_mdt_svc, rc);
4119 mdt_stop_ptlrpc_service(m);
4124 static void mdt_stack_fini(const struct lu_env *env,
4125 struct mdt_device *m, struct lu_device *top)
4127 struct obd_device *obd = mdt2obd_dev(m);
4128 struct lustre_cfg_bufs *bufs;
4129 struct lustre_cfg *lcfg;
4130 struct mdt_thread_info *info;
4134 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
4135 LASSERT(info != NULL);
4137 bufs = &info->mti_u.bufs;
4138 /* process cleanup, pass mdt obd name to get obd umount flags */
4139 lustre_cfg_bufs_reset(bufs, obd->obd_name);
4144 lustre_cfg_bufs_set_string(bufs, 1, flags);
4145 lcfg = lustre_cfg_new(LCFG_CLEANUP, bufs);
4147 CERROR("Cannot alloc lcfg!\n");
4152 top->ld_ops->ldo_process_config(env, top, lcfg);
4153 lustre_cfg_free(lcfg);
4155 lu_stack_fini(env, top);
4156 m->mdt_child = NULL;
4157 m->mdt_bottom = NULL;
4160 static struct lu_device *mdt_layer_setup(struct lu_env *env,
4161 const char *typename,
4162 struct lu_device *child,
4163 struct lustre_cfg *cfg)
4165 const char *dev = lustre_cfg_string(cfg, 0);
4166 struct obd_type *type;
4167 struct lu_device_type *ldt;
4168 struct lu_device *d;
4173 type = class_get_type(typename);
4175 CERROR("Unknown type: '%s'\n", typename);
4176 GOTO(out, rc = -ENODEV);
4179 rc = lu_env_refill((struct lu_env *)env);
4181 CERROR("Failure to refill session: '%d'\n", rc);
4187 CERROR("type: '%s'\n", typename);
4188 GOTO(out_type, rc = -EINVAL);
4191 ldt->ldt_obd_type = type;
4192 d = ldt->ldt_ops->ldto_device_alloc(env, ldt, cfg);
4194 CERROR("Cannot allocate device: '%s'\n", typename);
4195 GOTO(out_type, rc = -ENODEV);
4198 LASSERT(child->ld_site);
4199 d->ld_site = child->ld_site;
4202 rc = ldt->ldt_ops->ldto_device_init(env, d, dev, child);
4204 CERROR("can't init device '%s', rc %d\n", typename, rc);
4205 GOTO(out_alloc, rc);
4208 lu_ref_add(&d->ld_reference, "lu-stack", &lu_site_init);
4213 ldt->ldt_ops->ldto_device_free(env, d);
4216 class_put_type(type);
4221 static int mdt_stack_init(struct lu_env *env,
4222 struct mdt_device *m,
4223 struct lustre_cfg *cfg,
4224 struct lustre_mount_info *lmi)
4226 struct lu_device *d = &m->mdt_md_dev.md_lu_dev;
4227 struct lu_device *tmp;
4228 struct md_device *md;
4229 struct lu_device *child_lu_dev;
4233 /* init the stack */
4234 tmp = mdt_layer_setup(env, LUSTRE_OSD_NAME, d, cfg);
4236 RETURN(PTR_ERR(tmp));
4238 m->mdt_bottom = lu2dt_dev(tmp);
4240 tmp = mdt_layer_setup(env, LUSTRE_MDD_NAME, d, cfg);
4242 GOTO(out, rc = PTR_ERR(tmp));
4247 tmp = mdt_layer_setup(env, LUSTRE_CMM_NAME, d, cfg);
4249 GOTO(out, rc = PTR_ERR(tmp));
4252 /*set mdd upcall device*/
4253 md_upcall_dev_set(md, lu2md_dev(d));
4256 /*set cmm upcall device*/
4257 md_upcall_dev_set(md, &m->mdt_md_dev);
4259 m->mdt_child = lu2md_dev(d);
4261 /* process setup config */
4262 tmp = &m->mdt_md_dev.md_lu_dev;
4263 rc = tmp->ld_ops->ldo_process_config(env, tmp, cfg);
4267 /* initialize local objects */
4268 child_lu_dev = &m->mdt_child->md_lu_dev;
4270 rc = child_lu_dev->ld_ops->ldo_prepare(env,
4271 &m->mdt_md_dev.md_lu_dev,
4274 /* fini from last known good lu_device */
4276 mdt_stack_fini(env, m, d);
4282 * setup CONFIG_ORIG context, used to access local config log.
4283 * this may need to be rewrite as part of llog rewrite for lu-api.
4285 static int mdt_obd_llog_setup(struct obd_device *obd,
4286 struct lustre_sb_info *lsi)
4290 LASSERT(obd->obd_fsops == NULL);
4292 obd->obd_fsops = fsfilt_get_ops(MT_STR(lsi->lsi_ldd));
4293 if (IS_ERR(obd->obd_fsops))
4294 return PTR_ERR(obd->obd_fsops);
4296 rc = fsfilt_setup(obd, lsi->lsi_srv_mnt->mnt_sb);
4298 fsfilt_put_ops(obd->obd_fsops);
4302 OBD_SET_CTXT_MAGIC(&obd->obd_lvfs_ctxt);
4303 obd->obd_lvfs_ctxt.pwdmnt = lsi->lsi_srv_mnt;
4304 obd->obd_lvfs_ctxt.pwd = lsi->lsi_srv_mnt->mnt_root;
4305 obd->obd_lvfs_ctxt.fs = get_ds();
4307 rc = llog_setup(obd, &obd->obd_olg, LLOG_CONFIG_ORIG_CTXT, obd,
4308 0, NULL, &llog_lvfs_ops);
4310 CERROR("llog_setup() failed: %d\n", rc);
4311 fsfilt_put_ops(obd->obd_fsops);
4317 static void mdt_obd_llog_cleanup(struct obd_device *obd)
4319 struct llog_ctxt *ctxt;
4321 ctxt = llog_get_context(obd, LLOG_CONFIG_ORIG_CTXT);
4325 if (obd->obd_fsops) {
4326 fsfilt_put_ops(obd->obd_fsops);
4327 obd->obd_fsops = NULL;
4331 static void mdt_fini(const struct lu_env *env, struct mdt_device *m)
4333 struct md_device *next = m->mdt_child;
4334 struct lu_device *d = &m->mdt_md_dev.md_lu_dev;
4335 struct lu_site *ls = d->ld_site;
4336 struct obd_device *obd = mdt2obd_dev(m);
4339 target_recovery_fini(obd);
4341 ping_evictor_stop();
4343 mdt_stop_ptlrpc_service(m);
4344 mdt_llog_ctxt_unclone(env, m, LLOG_CHANGELOG_ORIG_CTXT);
4345 mdt_obd_llog_cleanup(obd);
4346 obd_exports_barrier(obd);
4347 obd_zombie_barrier();
4348 #ifdef HAVE_QUOTA_SUPPORT
4349 next->md_ops->mdo_quota.mqo_cleanup(env, next);
4351 lut_fini(env, &m->mdt_lut);
4352 mdt_fs_cleanup(env, m);
4353 upcall_cache_cleanup(m->mdt_identity_cache);
4354 m->mdt_identity_cache = NULL;
4356 if (m->mdt_namespace != NULL) {
4357 ldlm_namespace_free(m->mdt_namespace, NULL,
4358 d->ld_obd->obd_force);
4359 d->ld_obd->obd_namespace = m->mdt_namespace = NULL;
4362 cfs_free_nidlist(&m->mdt_nosquash_nids);
4363 if (m->mdt_nosquash_str) {
4364 OBD_FREE(m->mdt_nosquash_str, m->mdt_nosquash_strlen);
4365 m->mdt_nosquash_str = NULL;
4366 m->mdt_nosquash_strlen = 0;
4369 mdt_seq_fini(env, m);
4370 mdt_seq_fini_cli(m);
4371 mdt_fld_fini(env, m);
4372 sptlrpc_rule_set_free(&m->mdt_sptlrpc_rset);
4374 next->md_ops->mdo_init_capa_ctxt(env, next, 0, 0, 0, NULL);
4375 cfs_timer_disarm(&m->mdt_ck_timer);
4376 mdt_ck_thread_stop(m);
4381 mdt_stack_fini(env, m, md2lu_dev(m->mdt_child));
4383 lprocfs_free_per_client_stats(obd);
4384 lprocfs_free_obd_stats(obd);
4388 struct md_site *mite;
4391 mite = lu_site2md(ls);
4395 LASSERT(cfs_atomic_read(&d->ld_ref) == 0);
4400 static int mdt_adapt_sptlrpc_conf(struct obd_device *obd, int initial)
4402 struct mdt_device *m = mdt_dev(obd->obd_lu_dev);
4403 struct sptlrpc_rule_set tmp_rset;
4406 sptlrpc_rule_set_init(&tmp_rset);
4407 rc = sptlrpc_conf_target_get_rules(obd, &tmp_rset, initial);
4409 CERROR("mdt %s: failed get sptlrpc rules: %d\n",
4414 sptlrpc_target_update_exp_flavor(obd, &tmp_rset);
4416 cfs_write_lock(&m->mdt_sptlrpc_lock);
4417 sptlrpc_rule_set_free(&m->mdt_sptlrpc_rset);
4418 m->mdt_sptlrpc_rset = tmp_rset;
4419 cfs_write_unlock(&m->mdt_sptlrpc_lock);
4424 static void fsoptions_to_mdt_flags(struct mdt_device *m, char *options)
4428 m->mdt_opts.mo_mds_capa = 1;
4429 m->mdt_opts.mo_oss_capa = 1;
4430 #ifdef CONFIG_FS_POSIX_ACL
4431 /* ACLs should be enabled by default (b=13829) */
4432 m->mdt_opts.mo_acl = 1;
4433 LCONSOLE_INFO("Enabling ACL\n");
4435 m->mdt_opts.mo_acl = 0;
4436 LCONSOLE_INFO("Disabling ACL\n");
4445 while (*p && *p != ',')
4449 if ((len == sizeof("user_xattr") - 1) &&
4450 (memcmp(options, "user_xattr", len) == 0)) {
4451 m->mdt_opts.mo_user_xattr = 1;
4452 LCONSOLE_INFO("Enabling user_xattr\n");
4453 } else if ((len == sizeof("nouser_xattr") - 1) &&
4454 (memcmp(options, "nouser_xattr", len) == 0)) {
4455 m->mdt_opts.mo_user_xattr = 0;
4456 LCONSOLE_INFO("Disabling user_xattr\n");
4457 } else if ((len == sizeof("noacl") - 1) &&
4458 (memcmp(options, "noacl", len) == 0)) {
4459 m->mdt_opts.mo_acl = 0;
4460 LCONSOLE_INFO("Disabling ACL\n");
4470 int mdt_postrecov(const struct lu_env *, struct mdt_device *);
4472 static int mdt_init0(const struct lu_env *env, struct mdt_device *m,
4473 struct lu_device_type *ldt, struct lustre_cfg *cfg)
4475 struct mdt_thread_info *info;
4476 struct obd_device *obd;
4477 const char *dev = lustre_cfg_string(cfg, 0);
4478 const char *num = lustre_cfg_string(cfg, 2);
4479 struct lustre_mount_info *lmi = NULL;
4480 struct lustre_sb_info *lsi;
4481 struct lustre_disk_data *ldd;
4483 struct md_site *mite;
4484 const char *identity_upcall = "NONE";
4485 #ifdef HAVE_QUOTA_SUPPORT
4486 struct md_device *next;
4492 md_device_init(&m->mdt_md_dev, ldt);
4494 * Environment (env) might be missing mdt_thread_key values at that
4495 * point, if device is allocated when mdt_thread_key is in QUIESCENT
4498 * Usually device allocation path doesn't use module key values, but
4499 * mdt has to do a lot of work here, so allocate key value.
4501 rc = lu_env_refill((struct lu_env *)env);
4505 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
4506 LASSERT(info != NULL);
4508 obd = class_name2obd(dev);
4509 LASSERT(obd != NULL);
4511 m->mdt_max_mdsize = MAX_MD_SIZE;
4512 m->mdt_max_cookiesize = sizeof(struct llog_cookie);
4513 m->mdt_som_conf = 0;
4515 m->mdt_opts.mo_user_xattr = 0;
4516 m->mdt_opts.mo_acl = 0;
4517 m->mdt_opts.mo_cos = MDT_COS_DEFAULT;
4518 lmi = server_get_mount_2(dev);
4520 CERROR("Cannot get mount info for %s!\n", dev);
4523 lsi = s2lsi(lmi->lmi_sb);
4524 fsoptions_to_mdt_flags(m, lsi->lsi_lmd->lmd_opts);
4525 /* CMD is supported only in IAM mode */
4528 node_id = simple_strtol(num, NULL, 10);
4529 if (!(ldd->ldd_flags & LDD_F_IAM_DIR) && node_id) {
4530 CERROR("CMD Operation not allowed in IOP mode\n");
4531 GOTO(err_lmi, rc = -EINVAL);
4533 /* Read recovery timeouts */
4534 if (lsi->lsi_lmd && lsi->lsi_lmd->lmd_recovery_time_soft)
4535 obd->obd_recovery_timeout =
4536 lsi->lsi_lmd->lmd_recovery_time_soft;
4538 if (lsi->lsi_lmd && lsi->lsi_lmd->lmd_recovery_time_hard)
4539 obd->obd_recovery_time_hard =
4540 lsi->lsi_lmd->lmd_recovery_time_hard;
4543 cfs_rwlock_init(&m->mdt_sptlrpc_lock);
4544 sptlrpc_rule_set_init(&m->mdt_sptlrpc_rset);
4546 cfs_spin_lock_init(&m->mdt_ioepoch_lock);
4547 m->mdt_opts.mo_compat_resname = 0;
4548 m->mdt_capa_timeout = CAPA_TIMEOUT;
4549 m->mdt_capa_alg = CAPA_HMAC_ALG_SHA1;
4550 m->mdt_ck_timeout = CAPA_KEY_TIMEOUT;
4551 m->mdt_squash_uid = 0;
4552 m->mdt_squash_gid = 0;
4553 CFS_INIT_LIST_HEAD(&m->mdt_nosquash_nids);
4554 m->mdt_nosquash_str = NULL;
4555 m->mdt_nosquash_strlen = 0;
4556 cfs_init_rwsem(&m->mdt_squash_sem);
4558 OBD_ALLOC_PTR(mite);
4560 GOTO(err_lmi, rc = -ENOMEM);
4564 m->mdt_md_dev.md_lu_dev.ld_ops = &mdt_lu_ops;
4565 m->mdt_md_dev.md_lu_dev.ld_obd = obd;
4566 /* set this lu_device to obd, because error handling need it */
4567 obd->obd_lu_dev = &m->mdt_md_dev.md_lu_dev;
4569 rc = lu_site_init(s, &m->mdt_md_dev.md_lu_dev);
4571 CERROR("Can't init lu_site, rc %d\n", rc);
4572 GOTO(err_free_site, rc);
4575 rc = mdt_procfs_init(m, dev);
4577 CERROR("Can't init MDT lprocfs, rc %d\n", rc);
4578 GOTO(err_fini_proc, rc);
4581 /* set server index */
4582 lu_site2md(s)->ms_node_id = node_id;
4584 /* failover is the default
4585 * FIXME: we do not failout mds0/mgs, which may cause some problems.
4586 * assumed whose ms_node_id == 0 XXX
4588 obd->obd_replayable = 1;
4589 /* No connection accepted until configurations will finish */
4590 obd->obd_no_conn = 1;
4592 if (cfg->lcfg_bufcount > 4 && LUSTRE_CFG_BUFLEN(cfg, 4) > 0) {
4593 char *str = lustre_cfg_string(cfg, 4);
4594 if (strchr(str, 'n')) {
4595 CWARN("%s: recovery disabled\n", obd->obd_name);
4596 obd->obd_replayable = 0;
4600 /* init the stack */
4601 rc = mdt_stack_init((struct lu_env *)env, m, cfg, lmi);
4603 CERROR("Can't init device stack, rc %d\n", rc);
4604 GOTO(err_fini_proc, rc);
4607 rc = lut_init(env, &m->mdt_lut, obd, m->mdt_bottom);
4609 GOTO(err_fini_stack, rc);
4611 rc = mdt_fld_init(env, obd->obd_name, m);
4615 rc = mdt_seq_init(env, obd->obd_name, m);
4617 GOTO(err_fini_fld, rc);
4619 snprintf(info->mti_u.ns_name, sizeof info->mti_u.ns_name,
4620 LUSTRE_MDT_NAME"-%p", m);
4621 m->mdt_namespace = ldlm_namespace_new(obd, info->mti_u.ns_name,
4622 LDLM_NAMESPACE_SERVER,
4623 LDLM_NAMESPACE_GREEDY,
4625 if (m->mdt_namespace == NULL)
4626 GOTO(err_fini_seq, rc = -ENOMEM);
4628 ldlm_register_intent(m->mdt_namespace, mdt_intent_policy);
4629 /* set obd_namespace for compatibility with old code */
4630 obd->obd_namespace = m->mdt_namespace;
4632 /* XXX: to support suppgid for ACL, we enable identity_upcall
4633 * by default, otherwise, maybe got unexpected -EACCESS. */
4634 if (m->mdt_opts.mo_acl)
4635 identity_upcall = MDT_IDENTITY_UPCALL_PATH;
4637 m->mdt_identity_cache = upcall_cache_init(obd->obd_name, identity_upcall,
4638 &mdt_identity_upcall_cache_ops);
4639 if (IS_ERR(m->mdt_identity_cache)) {
4640 rc = PTR_ERR(m->mdt_identity_cache);
4641 m->mdt_identity_cache = NULL;
4642 GOTO(err_free_ns, rc);
4645 cfs_timer_init(&m->mdt_ck_timer, mdt_ck_timer_callback, m);
4647 rc = mdt_ck_thread_start(m);
4649 GOTO(err_free_ns, rc);
4651 rc = mdt_fs_setup(env, m, obd, lsi);
4655 rc = mdt_obd_llog_setup(obd, lsi);
4657 GOTO(err_fs_cleanup, rc);
4659 rc = mdt_llog_ctxt_clone(env, m, LLOG_CHANGELOG_ORIG_CTXT);
4661 GOTO(err_llog_cleanup, rc);
4663 mdt_adapt_sptlrpc_conf(obd, 1);
4665 #ifdef HAVE_QUOTA_SUPPORT
4666 next = m->mdt_child;
4667 rc = next->md_ops->mdo_quota.mqo_setup(env, next, lmi->lmi_mnt);
4669 GOTO(err_llog_cleanup, rc);
4672 server_put_mount_2(dev, lmi->lmi_mnt);
4675 target_recovery_init(&m->mdt_lut, mdt_recovery_handle);
4677 rc = mdt_start_ptlrpc_service(m);
4679 GOTO(err_recovery, rc);
4681 ping_evictor_start();
4683 rc = lu_site_init_finish(s);
4685 GOTO(err_stop_service, rc);
4687 if (obd->obd_recovering == 0)
4688 mdt_postrecov(env, m);
4690 mdt_init_capa_ctxt(env, m);
4692 /* Reduce the initial timeout on an MDS because it doesn't need such
4693 * a long timeout as an OST does. Adaptive timeouts will adjust this
4694 * value appropriately. */
4695 if (ldlm_timeout == LDLM_TIMEOUT_DEFAULT)
4696 ldlm_timeout = MDS_LDLM_TIMEOUT_DEFAULT;
4701 ping_evictor_stop();
4702 mdt_stop_ptlrpc_service(m);
4704 target_recovery_fini(obd);
4705 #ifdef HAVE_QUOTA_SUPPORT
4706 next->md_ops->mdo_quota.mqo_cleanup(env, next);
4709 mdt_llog_ctxt_unclone(env, m, LLOG_CHANGELOG_ORIG_CTXT);
4710 mdt_obd_llog_cleanup(obd);
4712 mdt_fs_cleanup(env, m);
4714 cfs_timer_disarm(&m->mdt_ck_timer);
4715 mdt_ck_thread_stop(m);
4717 upcall_cache_cleanup(m->mdt_identity_cache);
4718 m->mdt_identity_cache = NULL;
4719 ldlm_namespace_free(m->mdt_namespace, NULL, 0);
4720 obd->obd_namespace = m->mdt_namespace = NULL;
4722 mdt_seq_fini(env, m);
4724 mdt_fld_fini(env, m);
4726 lut_fini(env, &m->mdt_lut);
4728 mdt_stack_fini(env, m, md2lu_dev(m->mdt_child));
4736 server_put_mount_2(dev, lmi->lmi_mnt);
4740 /* used by MGS to process specific configurations */
4741 static int mdt_process_config(const struct lu_env *env,
4742 struct lu_device *d, struct lustre_cfg *cfg)
4744 struct mdt_device *m = mdt_dev(d);
4745 struct md_device *md_next = m->mdt_child;
4746 struct lu_device *next = md2lu_dev(md_next);
4750 switch (cfg->lcfg_command) {
4752 struct lprocfs_static_vars lvars;
4753 struct obd_device *obd = d->ld_obd;
4756 * For interoperability between 1.8 and 2.0,
4757 * skip old "mdt.group_upcall" param.
4760 char *param = lustre_cfg_string(cfg, 1);
4761 if (param && !strncmp("mdt.group_upcall", param, 16)) {
4762 CWARN("For 1.8 interoperability, skip this"
4763 " mdt.group_upcall. It is obsolete\n");
4768 lprocfs_mdt_init_vars(&lvars);
4769 rc = class_process_proc_param(PARAM_MDT, lvars.obd_vars,
4771 if (rc > 0 || rc == -ENOSYS)
4772 /* we don't understand; pass it on */
4773 rc = next->ld_ops->ldo_process_config(env, next, cfg);
4778 * Add mdc hook to get first MDT uuid and connect it to
4779 * ls->controller to use for seq manager.
4781 rc = next->ld_ops->ldo_process_config(env, next, cfg);
4783 CERROR("Can't add mdc, rc %d\n", rc);
4785 rc = mdt_seq_init_cli(env, mdt_dev(d), cfg);
4788 /* others are passed further */
4789 rc = next->ld_ops->ldo_process_config(env, next, cfg);
4795 static struct lu_object *mdt_object_alloc(const struct lu_env *env,
4796 const struct lu_object_header *hdr,
4797 struct lu_device *d)
4799 struct mdt_object *mo;
4805 struct lu_object *o;
4806 struct lu_object_header *h;
4808 o = &mo->mot_obj.mo_lu;
4809 h = &mo->mot_header;
4810 lu_object_header_init(h);
4811 lu_object_init(o, h, d);
4812 lu_object_add_top(h, o);
4813 o->lo_ops = &mdt_obj_ops;
4814 cfs_sema_init(&mo->mot_ioepoch_sem, 1);
4820 static int mdt_object_init(const struct lu_env *env, struct lu_object *o,
4821 const struct lu_object_conf *unused)
4823 struct mdt_device *d = mdt_dev(o->lo_dev);
4824 struct lu_device *under;
4825 struct lu_object *below;
4829 CDEBUG(D_INFO, "object init, fid = "DFID"\n",
4830 PFID(lu_object_fid(o)));
4832 under = &d->mdt_child->md_lu_dev;
4833 below = under->ld_ops->ldo_object_alloc(env, o->lo_header, under);
4834 if (below != NULL) {
4835 lu_object_add(o, below);
4842 static void mdt_object_free(const struct lu_env *env, struct lu_object *o)
4844 struct mdt_object *mo = mdt_obj(o);
4845 struct lu_object_header *h;
4849 CDEBUG(D_INFO, "object free, fid = "DFID"\n",
4850 PFID(lu_object_fid(o)));
4853 lu_object_header_fini(h);
4858 static int mdt_object_print(const struct lu_env *env, void *cookie,
4859 lu_printer_t p, const struct lu_object *o)
4861 struct mdt_object *mdto = mdt_obj((struct lu_object *)o);
4862 return (*p)(env, cookie, LUSTRE_MDT_NAME"-object@%p(ioepoch="LPU64" "
4863 "flags="LPX64", epochcount=%d, writecount=%d)",
4864 mdto, mdto->mot_ioepoch, mdto->mot_flags,
4865 mdto->mot_ioepoch_count, mdto->mot_writecount);
4868 static const struct lu_device_operations mdt_lu_ops = {
4869 .ldo_object_alloc = mdt_object_alloc,
4870 .ldo_process_config = mdt_process_config,
4873 static const struct lu_object_operations mdt_obj_ops = {
4874 .loo_object_init = mdt_object_init,
4875 .loo_object_free = mdt_object_free,
4876 .loo_object_print = mdt_object_print
4879 static int mdt_obd_set_info_async(struct obd_export *exp,
4880 __u32 keylen, void *key,
4881 __u32 vallen, void *val,
4882 struct ptlrpc_request_set *set)
4884 struct obd_device *obd = exp->exp_obd;
4890 if (KEY_IS(KEY_SPTLRPC_CONF)) {
4891 rc = mdt_adapt_sptlrpc_conf(obd, 0);
4898 /* mds_connect_internal */
4899 static int mdt_connect_internal(struct obd_export *exp,
4900 struct mdt_device *mdt,
4901 struct obd_connect_data *data)
4904 data->ocd_connect_flags &= MDT_CONNECT_SUPPORTED;
4905 data->ocd_ibits_known &= MDS_INODELOCK_FULL;
4907 /* If no known bits (which should not happen, probably,
4908 as everybody should support LOOKUP and UPDATE bits at least)
4909 revert to compat mode with plain locks. */
4910 if (!data->ocd_ibits_known &&
4911 data->ocd_connect_flags & OBD_CONNECT_IBITS)
4912 data->ocd_connect_flags &= ~OBD_CONNECT_IBITS;
4914 if (!mdt->mdt_opts.mo_acl)
4915 data->ocd_connect_flags &= ~OBD_CONNECT_ACL;
4917 if (!mdt->mdt_opts.mo_user_xattr)
4918 data->ocd_connect_flags &= ~OBD_CONNECT_XATTR;
4920 if (!mdt->mdt_som_conf)
4921 data->ocd_connect_flags &= ~OBD_CONNECT_SOM;
4923 cfs_spin_lock(&exp->exp_lock);
4924 exp->exp_connect_flags = data->ocd_connect_flags;
4925 cfs_spin_unlock(&exp->exp_lock);
4926 data->ocd_version = LUSTRE_VERSION_CODE;
4927 exp->exp_mdt_data.med_ibits_known = data->ocd_ibits_known;
4931 if (mdt->mdt_opts.mo_acl &&
4932 ((exp->exp_connect_flags & OBD_CONNECT_ACL) == 0)) {
4933 CWARN("%s: MDS requires ACL support but client does not\n",
4934 mdt->mdt_md_dev.md_lu_dev.ld_obd->obd_name);
4939 if ((exp->exp_connect_flags & OBD_CONNECT_FID) == 0) {
4940 CWARN("%s: MDS requires FID support, but client not\n",
4941 mdt->mdt_md_dev.md_lu_dev.ld_obd->obd_name);
4945 if (mdt->mdt_som_conf && !exp_connect_som(exp) &&
4946 !(exp->exp_connect_flags & OBD_CONNECT_MDS_MDS)) {
4947 CWARN("%s: MDS has SOM enabled, but client does not support "
4948 "it\n", mdt->mdt_md_dev.md_lu_dev.ld_obd->obd_name);
4955 static int mdt_connect_check_sptlrpc(struct mdt_device *mdt,
4956 struct obd_export *exp,
4957 struct ptlrpc_request *req)
4959 struct sptlrpc_flavor flvr;
4962 if (exp->exp_flvr.sf_rpc == SPTLRPC_FLVR_INVALID) {
4963 cfs_read_lock(&mdt->mdt_sptlrpc_lock);
4964 sptlrpc_target_choose_flavor(&mdt->mdt_sptlrpc_rset,
4968 cfs_read_unlock(&mdt->mdt_sptlrpc_lock);
4970 cfs_spin_lock(&exp->exp_lock);
4972 exp->exp_sp_peer = req->rq_sp_from;
4973 exp->exp_flvr = flvr;
4975 if (exp->exp_flvr.sf_rpc != SPTLRPC_FLVR_ANY &&
4976 exp->exp_flvr.sf_rpc != req->rq_flvr.sf_rpc) {
4977 CERROR("unauthorized rpc flavor %x from %s, "
4978 "expect %x\n", req->rq_flvr.sf_rpc,
4979 libcfs_nid2str(req->rq_peer.nid),
4980 exp->exp_flvr.sf_rpc);
4984 cfs_spin_unlock(&exp->exp_lock);
4986 if (exp->exp_sp_peer != req->rq_sp_from) {
4987 CERROR("RPC source %s doesn't match %s\n",
4988 sptlrpc_part2name(req->rq_sp_from),
4989 sptlrpc_part2name(exp->exp_sp_peer));
4992 rc = sptlrpc_target_export_check(exp, req);
4999 /* mds_connect copy */
5000 static int mdt_obd_connect(const struct lu_env *env,
5001 struct obd_export **exp, struct obd_device *obd,
5002 struct obd_uuid *cluuid,
5003 struct obd_connect_data *data,
5006 struct mdt_thread_info *info;
5007 struct obd_export *lexp;
5008 struct lustre_handle conn = { 0 };
5009 struct mdt_device *mdt;
5010 struct ptlrpc_request *req;
5014 LASSERT(env != NULL);
5015 if (!exp || !obd || !cluuid)
5018 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
5019 req = info->mti_pill->rc_req;
5020 mdt = mdt_dev(obd->obd_lu_dev);
5022 rc = class_connect(&conn, obd, cluuid);
5026 lexp = class_conn2export(&conn);
5027 LASSERT(lexp != NULL);
5029 rc = mdt_connect_check_sptlrpc(mdt, lexp, req);
5033 if (OBD_FAIL_CHECK(OBD_FAIL_TGT_RCVG_FLAG))
5034 lustre_msg_add_op_flags(req->rq_repmsg, MSG_CONNECT_RECOVERING);
5036 rc = mdt_connect_internal(lexp, mdt, data);
5038 struct mdt_thread_info *mti;
5039 struct lsd_client_data *lcd = lexp->exp_target_data.ted_lcd;
5041 mti = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
5042 LASSERT(mti != NULL);
5043 mti->mti_exp = lexp;
5044 memcpy(lcd->lcd_uuid, cluuid, sizeof lcd->lcd_uuid);
5045 rc = mdt_client_new(env, mdt);
5047 mdt_export_stats_init(obd, lexp, localdata);
5052 class_disconnect(lexp);
5061 static int mdt_obd_reconnect(const struct lu_env *env,
5062 struct obd_export *exp, struct obd_device *obd,
5063 struct obd_uuid *cluuid,
5064 struct obd_connect_data *data,
5067 struct mdt_thread_info *info;
5068 struct mdt_device *mdt;
5069 struct ptlrpc_request *req;
5073 if (exp == NULL || obd == NULL || cluuid == NULL)
5076 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
5077 req = info->mti_pill->rc_req;
5078 mdt = mdt_dev(obd->obd_lu_dev);
5080 rc = mdt_connect_check_sptlrpc(mdt, exp, req);
5084 rc = mdt_connect_internal(exp, mdt_dev(obd->obd_lu_dev), data);
5086 mdt_export_stats_init(obd, exp, localdata);
5090 static int mdt_export_cleanup(struct obd_export *exp)
5092 struct mdt_export_data *med = &exp->exp_mdt_data;
5093 struct obd_device *obd = exp->exp_obd;
5094 struct mdt_device *mdt;
5095 struct mdt_thread_info *info;
5097 CFS_LIST_HEAD(closing_list);
5098 struct mdt_file_data *mfd, *n;
5102 cfs_spin_lock(&med->med_open_lock);
5103 while (!cfs_list_empty(&med->med_open_head)) {
5104 cfs_list_t *tmp = med->med_open_head.next;
5105 mfd = cfs_list_entry(tmp, struct mdt_file_data, mfd_list);
5107 /* Remove mfd handle so it can't be found again.
5108 * We are consuming the mfd_list reference here. */
5109 class_handle_unhash(&mfd->mfd_handle);
5110 cfs_list_move_tail(&mfd->mfd_list, &closing_list);
5112 cfs_spin_unlock(&med->med_open_lock);
5113 mdt = mdt_dev(obd->obd_lu_dev);
5114 LASSERT(mdt != NULL);
5116 rc = lu_env_init(&env, LCT_MD_THREAD);
5120 info = lu_context_key_get(&env.le_ctx, &mdt_thread_key);
5121 LASSERT(info != NULL);
5122 memset(info, 0, sizeof *info);
5123 info->mti_env = &env;
5124 info->mti_mdt = mdt;
5125 info->mti_exp = exp;
5127 if (!cfs_list_empty(&closing_list)) {
5128 struct md_attr *ma = &info->mti_attr;
5132 lmm_size = mdt->mdt_max_mdsize;
5133 OBD_ALLOC_LARGE(ma->ma_lmm, lmm_size);
5134 if (ma->ma_lmm == NULL)
5135 GOTO(out_lmm, rc = -ENOMEM);
5137 cookie_size = mdt->mdt_max_cookiesize;
5138 OBD_ALLOC_LARGE(ma->ma_cookie, cookie_size);
5139 if (ma->ma_cookie == NULL)
5140 GOTO(out_cookie, rc = -ENOMEM);
5142 /* Close any open files (which may also cause orphan unlinking). */
5143 cfs_list_for_each_entry_safe(mfd, n, &closing_list, mfd_list) {
5144 cfs_list_del_init(&mfd->mfd_list);
5145 memset(&ma->ma_attr, 0, sizeof(ma->ma_attr));
5146 ma->ma_lmm_size = lmm_size;
5147 ma->ma_cookie_size = cookie_size;
5149 /* It is not for setattr, just tell MDD to send
5150 * DESTROY RPC to OSS if needed */
5151 ma->ma_valid = MA_FLAGS;
5152 ma->ma_attr_flags = MDS_CLOSE_CLEANUP;
5153 /* Don't unlink orphan on failover umount, LU-184 */
5154 if (exp->exp_flags & OBD_OPT_FAILOVER)
5155 ma->ma_attr_flags |= MDS_KEEP_ORPHAN;
5156 mdt_mfd_close(info, mfd);
5158 OBD_FREE_LARGE(ma->ma_cookie, cookie_size);
5159 ma->ma_cookie = NULL;
5161 OBD_FREE_LARGE(ma->ma_lmm, lmm_size);
5165 info->mti_mdt = NULL;
5166 /* cleanup client slot early */
5167 /* Do not erase record for recoverable client. */
5168 if (!(exp->exp_flags & OBD_OPT_FAILOVER) || exp->exp_failed)
5169 mdt_client_del(&env, mdt);
5175 static int mdt_obd_disconnect(struct obd_export *exp)
5181 class_export_get(exp);
5183 rc = server_disconnect_export(exp);
5185 CDEBUG(D_IOCTL, "server disconnect error: %d\n", rc);
5187 rc = mdt_export_cleanup(exp);
5188 class_export_put(exp);
5192 /* FIXME: Can we avoid using these two interfaces? */
5193 static int mdt_init_export(struct obd_export *exp)
5195 struct mdt_export_data *med = &exp->exp_mdt_data;
5199 CFS_INIT_LIST_HEAD(&med->med_open_head);
5200 cfs_spin_lock_init(&med->med_open_lock);
5201 cfs_sema_init(&med->med_idmap_sem, 1);
5202 med->med_idmap = NULL;
5203 cfs_spin_lock(&exp->exp_lock);
5204 exp->exp_connecting = 1;
5205 cfs_spin_unlock(&exp->exp_lock);
5206 rc = lut_client_alloc(exp);
5208 rc = ldlm_init_export(exp);
5211 CERROR("Error %d while initializing export\n", rc);
5215 static int mdt_destroy_export(struct obd_export *exp)
5217 struct mdt_export_data *med;
5221 med = &exp->exp_mdt_data;
5222 if (exp_connect_rmtclient(exp))
5223 mdt_cleanup_idmap(&exp->exp_mdt_data);
5225 target_destroy_export(exp);
5226 ldlm_destroy_export(exp);
5227 lut_client_free(exp);
5229 LASSERT(cfs_list_empty(&exp->exp_outstanding_replies));
5230 LASSERT(cfs_list_empty(&exp->exp_mdt_data.med_open_head));
5231 if (obd_uuid_equals(&exp->exp_client_uuid, &exp->exp_obd->obd_uuid))
5237 static void mdt_allow_cli(struct mdt_device *m, unsigned int flag)
5239 if (flag & CONFIG_LOG)
5240 cfs_set_bit(MDT_FL_CFGLOG, &m->mdt_state);
5242 /* also notify active event */
5243 if (flag & CONFIG_SYNC)
5244 cfs_set_bit(MDT_FL_SYNCED, &m->mdt_state);
5246 if (cfs_test_bit(MDT_FL_CFGLOG, &m->mdt_state) &&
5247 cfs_test_bit(MDT_FL_SYNCED, &m->mdt_state)) {
5248 struct obd_device *obd = m->mdt_md_dev.md_lu_dev.ld_obd;
5250 /* Open for clients */
5251 if (obd->obd_no_conn) {
5252 cfs_spin_lock(&obd->obd_dev_lock);
5253 obd->obd_no_conn = 0;
5254 cfs_spin_unlock(&obd->obd_dev_lock);
5259 static int mdt_upcall(const struct lu_env *env, struct md_device *md,
5260 enum md_upcall_event ev, void *data)
5262 struct mdt_device *m = mdt_dev(&md->md_lu_dev);
5263 struct md_device *next = m->mdt_child;
5264 struct mdt_thread_info *mti;
5270 rc = next->md_ops->mdo_maxsize_get(env, next,
5272 &m->mdt_max_cookiesize);
5273 CDEBUG(D_INFO, "get max mdsize %d max cookiesize %d\n",
5274 m->mdt_max_mdsize, m->mdt_max_cookiesize);
5275 mdt_allow_cli(m, CONFIG_SYNC);
5278 m->mdt_lut.lut_obd->u.obt.obt_mount_count;
5281 mti = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
5282 mti->mti_no_need_trans = 1;
5283 CDEBUG(D_INFO, "disable mdt trans for this thread\n");
5286 /* Check that MDT is not yet configured */
5287 LASSERT(!cfs_test_bit(MDT_FL_CFGLOG, &m->mdt_state));
5289 #ifdef HAVE_QUOTA_SUPPORT
5291 if (md->md_lu_dev.ld_obd->obd_recovering == 0 &&
5292 likely(md->md_lu_dev.ld_obd->obd_stopping == 0))
5293 next->md_ops->mdo_quota.mqo_recovery(env, next);
5297 CERROR("invalid event\n");
5304 static int mdt_obd_notify(struct obd_device *host,
5305 struct obd_device *watched,
5306 enum obd_notify_event ev, void *data)
5308 struct mdt_device *mdt = mdt_dev(host->obd_lu_dev);
5309 #ifdef HAVE_QUOTA_SUPPORT
5310 struct md_device *next = mdt->mdt_child;
5315 case OBD_NOTIFY_CONFIG:
5316 mdt_allow_cli(mdt, (unsigned long)data);
5318 #ifdef HAVE_QUOTA_SUPPORT
5319 /* quota_type has been processed, we can now handle
5320 * incoming quota requests */
5321 next->md_ops->mdo_quota.mqo_notify(NULL, next);
5325 CDEBUG(D_INFO, "Unhandled notification %#x\n", ev);
5330 static int mdt_rpc_fid2path(struct mdt_thread_info *info, void *key,
5331 void *val, int vallen)
5333 struct mdt_device *mdt = mdt_dev(info->mti_exp->exp_obd->obd_lu_dev);
5334 struct getinfo_fid2path *fpout, *fpin;
5337 fpin = key + cfs_size_round(sizeof(KEY_FID2PATH));
5340 if (ptlrpc_req_need_swab(info->mti_pill->rc_req))
5341 lustre_swab_fid2path(fpin);
5343 memcpy(fpout, fpin, sizeof(*fpin));
5344 if (fpout->gf_pathlen != vallen - sizeof(*fpin))
5347 rc = mdt_fid2path(info->mti_env, mdt, fpout);
5351 static int mdt_fid2path(const struct lu_env *env, struct mdt_device *mdt,
5352 struct getinfo_fid2path *fp)
5354 struct mdt_object *obj;
5358 CDEBUG(D_IOCTL, "path get "DFID" from "LPU64" #%d\n",
5359 PFID(&fp->gf_fid), fp->gf_recno, fp->gf_linkno);
5361 if (!fid_is_sane(&fp->gf_fid))
5364 obj = mdt_object_find(env, mdt, &fp->gf_fid);
5365 if (obj == NULL || IS_ERR(obj)) {
5366 CDEBUG(D_IOCTL, "no object "DFID": %ld\n",PFID(&fp->gf_fid),
5371 rc = lu_object_exists(&obj->mot_obj.mo_lu);
5377 mdt_object_put(env, obj);
5378 CDEBUG(D_IOCTL, "nonlocal object "DFID": %d\n",
5379 PFID(&fp->gf_fid), rc);
5383 rc = mo_path(env, md_object_next(&obj->mot_obj), fp->gf_path,
5384 fp->gf_pathlen, &fp->gf_recno, &fp->gf_linkno);
5385 mdt_object_put(env, obj);
5390 static int mdt_get_info(struct mdt_thread_info *info)
5392 struct ptlrpc_request *req = mdt_info_req(info);
5400 key = req_capsule_client_get(info->mti_pill, &RMF_GETINFO_KEY);
5402 CDEBUG(D_IOCTL, "No GETINFO key");
5405 keylen = req_capsule_get_size(info->mti_pill, &RMF_GETINFO_KEY,
5408 vallen = req_capsule_client_get(info->mti_pill, &RMF_GETINFO_VALLEN);
5409 if (vallen == NULL) {
5410 CDEBUG(D_IOCTL, "Unable to get RMF_GETINFO_VALLEN buffer");
5414 req_capsule_set_size(info->mti_pill, &RMF_GETINFO_VAL, RCL_SERVER,
5416 rc = req_capsule_server_pack(info->mti_pill);
5417 valout = req_capsule_server_get(info->mti_pill, &RMF_GETINFO_VAL);
5418 if (valout == NULL) {
5419 CDEBUG(D_IOCTL, "Unable to get get-info RPC out buffer");
5423 if (KEY_IS(KEY_FID2PATH))
5424 rc = mdt_rpc_fid2path(info, key, valout, *vallen);
5428 lustre_msg_set_status(req->rq_repmsg, rc);
5433 /* Pass the ioc down */
5434 static int mdt_ioc_child(struct lu_env *env, struct mdt_device *mdt,
5435 unsigned int cmd, int len, void *data)
5437 struct lu_context ioctl_session;
5438 struct md_device *next = mdt->mdt_child;
5442 rc = lu_context_init(&ioctl_session, LCT_SESSION);
5445 ioctl_session.lc_thread = (struct ptlrpc_thread *)cfs_current();
5446 lu_context_enter(&ioctl_session);
5447 env->le_ses = &ioctl_session;
5449 LASSERT(next->md_ops->mdo_iocontrol);
5450 rc = next->md_ops->mdo_iocontrol(env, next, cmd, len, data);
5452 lu_context_exit(&ioctl_session);
5453 lu_context_fini(&ioctl_session);
5457 static int mdt_ioc_version_get(struct mdt_thread_info *mti, void *karg)
5459 struct obd_ioctl_data *data = karg;
5460 struct lu_fid *fid = (struct lu_fid *)data->ioc_inlbuf1;
5462 struct mdt_object *obj;
5463 struct mdt_lock_handle *lh;
5466 CDEBUG(D_IOCTL, "getting version for "DFID"\n", PFID(fid));
5467 if (!fid_is_sane(fid))
5470 lh = &mti->mti_lh[MDT_LH_PARENT];
5471 mdt_lock_reg_init(lh, LCK_CR);
5473 obj = mdt_object_find_lock(mti, fid, lh, MDS_INODELOCK_UPDATE);
5475 RETURN(PTR_ERR(obj));
5477 rc = mdt_object_exists(obj);
5481 * before calling version get the correct MDS should be
5482 * fid, this is error to find remote object here
5484 CERROR("nonlocal object "DFID"\n", PFID(fid));
5486 version = mo_version_get(mti->mti_env, mdt_object_child(obj));
5487 *(__u64 *)data->ioc_inlbuf2 = version;
5490 mdt_object_unlock_put(mti, obj, lh, 1);
5494 /* ioctls on obd dev */
5495 static int mdt_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
5496 void *karg, void *uarg)
5499 struct obd_device *obd = exp->exp_obd;
5500 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
5501 struct dt_device *dt = mdt->mdt_bottom;
5505 CDEBUG(D_IOCTL, "handling ioctl cmd %#x\n", cmd);
5506 rc = lu_env_init(&env, LCT_MD_THREAD);
5512 rc = mdt_device_sync(&env, mdt);
5514 case OBD_IOC_SET_READONLY:
5515 dt->dd_ops->dt_ro(&env, dt);
5517 case OBD_IOC_ABORT_RECOVERY:
5518 CERROR("Aborting recovery for device %s\n", obd->obd_name);
5519 target_stop_recovery_thread(obd);
5522 case OBD_IOC_CHANGELOG_REG:
5523 case OBD_IOC_CHANGELOG_DEREG:
5524 case OBD_IOC_CHANGELOG_CLEAR:
5525 rc = mdt_ioc_child(&env, mdt, cmd, len, karg);
5527 case OBD_IOC_GET_OBJ_VERSION: {
5528 struct mdt_thread_info *mti;
5529 mti = lu_context_key_get(&env.le_ctx, &mdt_thread_key);
5530 memset(mti, 0, sizeof *mti);
5531 mti->mti_env = &env;
5535 rc = mdt_ioc_version_get(mti, karg);
5539 CERROR("Not supported cmd = %d for device %s\n",
5540 cmd, obd->obd_name);
5548 int mdt_postrecov(const struct lu_env *env, struct mdt_device *mdt)
5550 struct lu_device *ld = md2lu_dev(mdt->mdt_child);
5551 #ifdef HAVE_QUOTA_SUPPORT
5552 struct obd_device *obd = mdt2obd_dev(mdt);
5553 struct md_device *next = mdt->mdt_child;
5558 rc = ld->ld_ops->ldo_recovery_complete(env, ld);
5559 #ifdef HAVE_QUOTA_SUPPORT
5560 if (likely(obd->obd_stopping == 0))
5561 next->md_ops->mdo_quota.mqo_recovery(env, next);
5566 int mdt_obd_postrecov(struct obd_device *obd)
5571 rc = lu_env_init(&env, LCT_MD_THREAD);
5574 rc = mdt_postrecov(&env, mdt_dev(obd->obd_lu_dev));
5580 * Send a copytool req to a client
5581 * Note this sends a request RPC from a server (MDT) to a client (MDC),
5582 * backwards of normal comms.
5584 int mdt_hsm_copytool_send(struct obd_export *exp)
5587 struct hsm_action_list *hal;
5588 struct hsm_action_item *hai;
5592 CWARN("%s: writing to mdc at %s\n", exp->exp_obd->obd_name,
5593 libcfs_nid2str(exp->exp_connection->c_peer.nid));
5595 len = sizeof(*lh) + sizeof(*hal) + MTI_NAME_MAXLEN +
5596 /* for mockup below */ 2 * cfs_size_round(sizeof(*hai));
5601 lh->kuc_magic = KUC_MAGIC;
5602 lh->kuc_transport = KUC_TRANSPORT_HSM;
5603 lh->kuc_msgtype = HMT_ACTION_LIST;
5604 lh->kuc_msglen = len;
5606 hal = (struct hsm_action_list *)(lh + 1);
5607 hal->hal_version = HAL_VERSION;
5608 hal->hal_archive_num = 1;
5609 obd_uuid2fsname(hal->hal_fsname, exp->exp_obd->obd_name,
5612 /* mock up an action list */
5614 hai = hai_zero(hal);
5615 hai->hai_action = HSMA_ARCHIVE;
5616 hai->hai_fid.f_oid = 0xA00A;
5617 hai->hai_len = sizeof(*hai);
5618 hai = hai_next(hai);
5619 hai->hai_action = HSMA_RESTORE;
5620 hai->hai_fid.f_oid = 0xB00B;
5621 hai->hai_len = sizeof(*hai);
5623 /* Uses the ldlm reverse import; this rpc will be seen by
5624 the ldlm_callback_handler */
5625 rc = do_set_info_async(exp->exp_imp_reverse,
5626 LDLM_SET_INFO, LUSTRE_OBD_VERSION,
5627 sizeof(KEY_HSM_COPYTOOL_SEND),
5628 KEY_HSM_COPYTOOL_SEND,
5636 static struct obd_ops mdt_obd_device_ops = {
5637 .o_owner = THIS_MODULE,
5638 .o_set_info_async = mdt_obd_set_info_async,
5639 .o_connect = mdt_obd_connect,
5640 .o_reconnect = mdt_obd_reconnect,
5641 .o_disconnect = mdt_obd_disconnect,
5642 .o_init_export = mdt_init_export,
5643 .o_destroy_export = mdt_destroy_export,
5644 .o_iocontrol = mdt_iocontrol,
5645 .o_postrecov = mdt_obd_postrecov,
5646 .o_notify = mdt_obd_notify
5649 static struct lu_device* mdt_device_fini(const struct lu_env *env,
5650 struct lu_device *d)
5652 struct mdt_device *m = mdt_dev(d);
5659 static struct lu_device *mdt_device_free(const struct lu_env *env,
5660 struct lu_device *d)
5662 struct mdt_device *m = mdt_dev(d);
5665 md_device_fini(&m->mdt_md_dev);
5670 static struct lu_device *mdt_device_alloc(const struct lu_env *env,
5671 struct lu_device_type *t,
5672 struct lustre_cfg *cfg)
5674 struct lu_device *l;
5675 struct mdt_device *m;
5681 l = &m->mdt_md_dev.md_lu_dev;
5682 rc = mdt_init0(env, m, t, cfg);
5684 mdt_device_free(env, l);
5688 md_upcall_init(&m->mdt_md_dev, mdt_upcall);
5690 l = ERR_PTR(-ENOMEM);
5694 /* context key constructor/destructor: mdt_key_init, mdt_key_fini */
5695 LU_KEY_INIT_FINI(mdt, struct mdt_thread_info);
5697 /* context key: mdt_thread_key */
5698 LU_CONTEXT_KEY_DEFINE(mdt, LCT_MD_THREAD);
5700 /* context key constructor/destructor: mdt_txn_key_init, mdt_txn_key_fini */
5701 LU_KEY_INIT_FINI(mdt_txn, struct mdt_txn_info);
5703 struct lu_context_key mdt_txn_key = {
5704 .lct_tags = LCT_TX_HANDLE,
5705 .lct_init = mdt_txn_key_init,
5706 .lct_fini = mdt_txn_key_fini
5709 struct md_ucred *mdt_ucred(const struct mdt_thread_info *info)
5711 return md_ucred(info->mti_env);
5715 * Enable/disable COS (Commit On Sharing).
5717 * Set/Clear the COS flag in mdt options.
5719 * \param mdt mdt device
5720 * \param val 0 disables COS, other values enable COS
5722 void mdt_enable_cos(struct mdt_device *mdt, int val)
5727 mdt->mdt_opts.mo_cos = !!val;
5728 rc = lu_env_init(&env, LCT_MD_THREAD);
5729 if (unlikely(rc != 0)) {
5730 CWARN("lu_env initialization failed with rc = %d,"
5731 "cannot sync\n", rc);
5734 mdt_device_sync(&env, mdt);
5739 * Check COS (Commit On Sharing) status.
5741 * Return COS flag status.
5743 * \param mdt mdt device
5745 int mdt_cos_is_enabled(struct mdt_device *mdt)
5747 return mdt->mdt_opts.mo_cos != 0;
5750 /* type constructor/destructor: mdt_type_init, mdt_type_fini */
5751 LU_TYPE_INIT_FINI(mdt, &mdt_thread_key, &mdt_txn_key);
5753 static struct lu_device_type_operations mdt_device_type_ops = {
5754 .ldto_init = mdt_type_init,
5755 .ldto_fini = mdt_type_fini,
5757 .ldto_start = mdt_type_start,
5758 .ldto_stop = mdt_type_stop,
5760 .ldto_device_alloc = mdt_device_alloc,
5761 .ldto_device_free = mdt_device_free,
5762 .ldto_device_fini = mdt_device_fini
5765 static struct lu_device_type mdt_device_type = {
5766 .ldt_tags = LU_DEVICE_MD,
5767 .ldt_name = LUSTRE_MDT_NAME,
5768 .ldt_ops = &mdt_device_type_ops,
5769 .ldt_ctx_tags = LCT_MD_THREAD
5772 static struct lu_local_obj_desc mdt_last_recv = {
5773 .llod_name = LAST_RCVD,
5774 .llod_oid = MDT_LAST_RECV_OID,
5778 static int __init mdt_mod_init(void)
5780 struct lprocfs_static_vars lvars;
5783 llo_local_obj_register(&mdt_last_recv);
5785 if (mdt_num_threads > 0) {
5786 if (mdt_num_threads > MDT_MAX_THREADS)
5787 mdt_num_threads = MDT_MAX_THREADS;
5788 if (mdt_num_threads < MDT_MIN_THREADS)
5789 mdt_num_threads = MDT_MIN_THREADS;
5790 mdt_max_threads = mdt_min_threads = mdt_num_threads;
5792 mdt_max_threads = MDT_MAX_THREADS;
5793 mdt_min_threads = MDT_MIN_THREADS;
5796 lprocfs_mdt_init_vars(&lvars);
5797 rc = class_register_type(&mdt_obd_device_ops, NULL,
5798 lvars.module_vars, LUSTRE_MDT_NAME,
5804 static void __exit mdt_mod_exit(void)
5806 llo_local_obj_unregister(&mdt_last_recv);
5807 class_unregister_type(LUSTRE_MDT_NAME);
5811 #define DEF_HNDL(prefix, base, suffix, flags, opc, fn, fmt) \
5812 [prefix ## _ ## opc - prefix ## _ ## base] = { \
5814 .mh_fail_id = OBD_FAIL_ ## prefix ## _ ## opc ## suffix, \
5815 .mh_opc = prefix ## _ ## opc, \
5816 .mh_flags = flags, \
5821 #define DEF_MDT_HNDL(flags, name, fn, fmt) \
5822 DEF_HNDL(MDS, GETATTR, _NET, flags, name, fn, fmt)
5824 #define DEF_SEQ_HNDL(flags, name, fn, fmt) \
5825 DEF_HNDL(SEQ, QUERY, _NET, flags, name, fn, fmt)
5827 #define DEF_FLD_HNDL(flags, name, fn, fmt) \
5828 DEF_HNDL(FLD, QUERY, _NET, flags, name, fn, fmt)
5830 * Request with a format known in advance
5832 #define DEF_MDT_HNDL_F(flags, name, fn) \
5833 DEF_HNDL(MDS, GETATTR, _NET, flags, name, fn, &RQF_MDS_ ## name)
5835 #define DEF_SEQ_HNDL_F(flags, name, fn) \
5836 DEF_HNDL(SEQ, QUERY, _NET, flags, name, fn, &RQF_SEQ_ ## name)
5838 #define DEF_FLD_HNDL_F(flags, name, fn) \
5839 DEF_HNDL(FLD, QUERY, _NET, flags, name, fn, &RQF_FLD_ ## name)
5841 * Request with a format we do not yet know
5843 #define DEF_MDT_HNDL_0(flags, name, fn) \
5844 DEF_HNDL(MDS, GETATTR, _NET, flags, name, fn, NULL)
5846 static struct mdt_handler mdt_mds_ops[] = {
5847 DEF_MDT_HNDL_F(0, CONNECT, mdt_connect),
5848 DEF_MDT_HNDL_F(0, DISCONNECT, mdt_disconnect),
5849 DEF_MDT_HNDL (0, SET_INFO, mdt_set_info,
5851 DEF_MDT_HNDL_F(0, GET_INFO, mdt_get_info),
5852 DEF_MDT_HNDL_F(0 |HABEO_REFERO, GETSTATUS, mdt_getstatus),
5853 DEF_MDT_HNDL_F(HABEO_CORPUS, GETATTR, mdt_getattr),
5854 DEF_MDT_HNDL_F(HABEO_CORPUS|HABEO_REFERO, GETATTR_NAME, mdt_getattr_name),
5855 DEF_MDT_HNDL_F(HABEO_CORPUS, GETXATTR, mdt_getxattr),
5856 DEF_MDT_HNDL_F(0 |HABEO_REFERO, STATFS, mdt_statfs),
5857 DEF_MDT_HNDL_F(0 |MUTABOR, REINT, mdt_reint),
5858 DEF_MDT_HNDL_F(HABEO_CORPUS, CLOSE, mdt_close),
5859 DEF_MDT_HNDL_F(HABEO_CORPUS, DONE_WRITING, mdt_done_writing),
5860 DEF_MDT_HNDL_F(0 |HABEO_REFERO, PIN, mdt_pin),
5861 DEF_MDT_HNDL_0(0, SYNC, mdt_sync),
5862 DEF_MDT_HNDL_F(HABEO_CORPUS|HABEO_REFERO, IS_SUBDIR, mdt_is_subdir),
5863 #ifdef HAVE_QUOTA_SUPPORT
5864 DEF_MDT_HNDL_F(0, QUOTACHECK, mdt_quotacheck_handle),
5865 DEF_MDT_HNDL_F(0, QUOTACTL, mdt_quotactl_handle)
5869 #define DEF_OBD_HNDL(flags, name, fn) \
5870 DEF_HNDL(OBD, PING, _NET, flags, name, fn, NULL)
5873 static struct mdt_handler mdt_obd_ops[] = {
5874 DEF_OBD_HNDL(0, PING, mdt_obd_ping),
5875 DEF_OBD_HNDL(0, LOG_CANCEL, mdt_obd_log_cancel),
5876 DEF_OBD_HNDL(0, QC_CALLBACK, mdt_obd_qc_callback)
5879 #define DEF_DLM_HNDL_0(flags, name, fn) \
5880 DEF_HNDL(LDLM, ENQUEUE, , flags, name, fn, NULL)
5881 #define DEF_DLM_HNDL_F(flags, name, fn) \
5882 DEF_HNDL(LDLM, ENQUEUE, , flags, name, fn, &RQF_LDLM_ ## name)
5884 static struct mdt_handler mdt_dlm_ops[] = {
5885 DEF_DLM_HNDL_F(HABEO_CLAVIS, ENQUEUE, mdt_enqueue),
5886 DEF_DLM_HNDL_0(HABEO_CLAVIS, CONVERT, mdt_convert),
5887 DEF_DLM_HNDL_0(0, BL_CALLBACK, mdt_bl_callback),
5888 DEF_DLM_HNDL_0(0, CP_CALLBACK, mdt_cp_callback)
5891 #define DEF_LLOG_HNDL(flags, name, fn) \
5892 DEF_HNDL(LLOG, ORIGIN_HANDLE_CREATE, _NET, flags, name, fn, NULL)
5894 static struct mdt_handler mdt_llog_ops[] = {
5895 DEF_LLOG_HNDL(0, ORIGIN_HANDLE_CREATE, mdt_llog_create),
5896 DEF_LLOG_HNDL(0, ORIGIN_HANDLE_NEXT_BLOCK, mdt_llog_next_block),
5897 DEF_LLOG_HNDL(0, ORIGIN_HANDLE_READ_HEADER, mdt_llog_read_header),
5898 DEF_LLOG_HNDL(0, ORIGIN_HANDLE_WRITE_REC, NULL),
5899 DEF_LLOG_HNDL(0, ORIGIN_HANDLE_CLOSE, NULL),
5900 DEF_LLOG_HNDL(0, ORIGIN_CONNECT, NULL),
5901 DEF_LLOG_HNDL(0, CATINFO, NULL),
5902 DEF_LLOG_HNDL(0, ORIGIN_HANDLE_PREV_BLOCK, mdt_llog_prev_block),
5903 DEF_LLOG_HNDL(0, ORIGIN_HANDLE_DESTROY, mdt_llog_destroy),
5906 #define DEF_SEC_CTX_HNDL(name, fn) \
5907 DEF_HNDL(SEC_CTX, INIT, _NET, 0, name, fn, NULL)
5909 static struct mdt_handler mdt_sec_ctx_ops[] = {
5910 DEF_SEC_CTX_HNDL(INIT, mdt_sec_ctx_handle),
5911 DEF_SEC_CTX_HNDL(INIT_CONT, mdt_sec_ctx_handle),
5912 DEF_SEC_CTX_HNDL(FINI, mdt_sec_ctx_handle)
5915 static struct mdt_opc_slice mdt_regular_handlers[] = {
5917 .mos_opc_start = MDS_GETATTR,
5918 .mos_opc_end = MDS_LAST_OPC,
5919 .mos_hs = mdt_mds_ops
5922 .mos_opc_start = OBD_PING,
5923 .mos_opc_end = OBD_LAST_OPC,
5924 .mos_hs = mdt_obd_ops
5927 .mos_opc_start = LDLM_ENQUEUE,
5928 .mos_opc_end = LDLM_LAST_OPC,
5929 .mos_hs = mdt_dlm_ops
5932 .mos_opc_start = LLOG_ORIGIN_HANDLE_CREATE,
5933 .mos_opc_end = LLOG_LAST_OPC,
5934 .mos_hs = mdt_llog_ops
5937 .mos_opc_start = SEC_CTX_INIT,
5938 .mos_opc_end = SEC_LAST_OPC,
5939 .mos_hs = mdt_sec_ctx_ops
5946 static struct mdt_handler mdt_readpage_ops[] = {
5947 DEF_MDT_HNDL_F(0, CONNECT, mdt_connect),
5948 DEF_MDT_HNDL_F(HABEO_CORPUS|HABEO_REFERO, READPAGE, mdt_readpage),
5949 #ifdef HAVE_SPLIT_SUPPORT
5950 DEF_MDT_HNDL_F(HABEO_CORPUS|HABEO_REFERO, WRITEPAGE, mdt_writepage),
5954 * XXX: this is ugly and should be fixed one day, see mdc_close() for
5955 * detailed comments. --umka
5957 DEF_MDT_HNDL_F(HABEO_CORPUS, CLOSE, mdt_close),
5958 DEF_MDT_HNDL_F(HABEO_CORPUS, DONE_WRITING, mdt_done_writing),
5961 static struct mdt_opc_slice mdt_readpage_handlers[] = {
5963 .mos_opc_start = MDS_GETATTR,
5964 .mos_opc_end = MDS_LAST_OPC,
5965 .mos_hs = mdt_readpage_ops
5972 static struct mdt_handler mdt_xmds_ops[] = {
5973 DEF_MDT_HNDL_F(0, CONNECT, mdt_connect),
5974 DEF_MDT_HNDL_F(HABEO_CORPUS , GETATTR, mdt_getattr),
5975 DEF_MDT_HNDL_F(0 | MUTABOR , REINT, mdt_reint),
5976 DEF_MDT_HNDL_F(HABEO_CORPUS|HABEO_REFERO, IS_SUBDIR, mdt_is_subdir),
5979 static struct mdt_opc_slice mdt_xmds_handlers[] = {
5981 .mos_opc_start = MDS_GETATTR,
5982 .mos_opc_end = MDS_LAST_OPC,
5983 .mos_hs = mdt_xmds_ops
5986 .mos_opc_start = OBD_PING,
5987 .mos_opc_end = OBD_LAST_OPC,
5988 .mos_hs = mdt_obd_ops
5991 .mos_opc_start = SEC_CTX_INIT,
5992 .mos_opc_end = SEC_LAST_OPC,
5993 .mos_hs = mdt_sec_ctx_ops
6000 static struct mdt_handler mdt_seq_ops[] = {
6001 DEF_SEQ_HNDL_F(0, QUERY, (int (*)(struct mdt_thread_info *))seq_query)
6004 static struct mdt_opc_slice mdt_seq_handlers[] = {
6006 .mos_opc_start = SEQ_QUERY,
6007 .mos_opc_end = SEQ_LAST_OPC,
6008 .mos_hs = mdt_seq_ops
6015 static struct mdt_handler mdt_fld_ops[] = {
6016 DEF_FLD_HNDL_F(0, QUERY, (int (*)(struct mdt_thread_info *))fld_query)
6019 static struct mdt_opc_slice mdt_fld_handlers[] = {
6021 .mos_opc_start = FLD_QUERY,
6022 .mos_opc_end = FLD_LAST_OPC,
6023 .mos_hs = mdt_fld_ops
6030 MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");
6031 MODULE_DESCRIPTION("Lustre Meta-data Target ("LUSTRE_MDT_NAME")");
6032 MODULE_LICENSE("GPL");
6034 CFS_MODULE_PARM(mdt_num_threads, "ul", ulong, 0444,
6035 "number of mdt service threads to start");
6037 cfs_module(mdt, "0.2.0", mdt_mod_init, mdt_mod_exit);