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 * Copyright (c) 2011 Whamcloud, Inc.
36 * This file is part of Lustre, http://www.lustre.org/
37 * Lustre is a trademark of Sun Microsystems, Inc.
39 * lustre/mdt/mdt_handler.c
41 * Lustre Metadata Target (mdt) request handler
43 * Author: Peter Braam <braam@clusterfs.com>
44 * Author: Andreas Dilger <adilger@clusterfs.com>
45 * Author: Phil Schwan <phil@clusterfs.com>
46 * Author: Mike Shaver <shaver@clusterfs.com>
47 * Author: Nikita Danilov <nikita@clusterfs.com>
48 * Author: Huang Hua <huanghua@clusterfs.com>
49 * Author: Yury Umanets <umka@clusterfs.com>
53 # define EXPORT_SYMTAB
55 #define DEBUG_SUBSYSTEM S_MDS
57 #include <linux/module.h>
59 * struct OBD_{ALLOC,FREE}*()
61 #include <obd_support.h>
62 /* struct ptlrpc_request */
63 #include <lustre_net.h>
64 /* struct obd_export */
65 #include <lustre_export.h>
66 /* struct obd_device */
69 #include <dt_object.h>
70 #include <lustre_mds.h>
71 #include <lustre_mdt.h>
72 #include "mdt_internal.h"
73 #ifdef HAVE_QUOTA_SUPPORT
74 # include <lustre_quota.h>
76 #include <lustre_acl.h>
77 #include <lustre_param.h>
78 #include <lustre_fsfilt.h>
80 mdl_mode_t mdt_mdl_lock_modes[] = {
81 [LCK_MINMODE] = MDL_MINMODE,
88 [LCK_GROUP] = MDL_GROUP
91 ldlm_mode_t mdt_dlm_lock_modes[] = {
92 [MDL_MINMODE] = LCK_MINMODE,
99 [MDL_GROUP] = LCK_GROUP
103 * Initialized in mdt_mod_init().
105 static unsigned long mdt_num_threads;
106 static unsigned long mdt_min_threads;
107 static unsigned long mdt_max_threads;
109 /* ptlrpc request handler for MDT. All handlers are
110 * grouped into several slices - struct mdt_opc_slice,
111 * and stored in an array - mdt_handlers[].
114 /* The name of this handler. */
116 /* Fail id for this handler, checked at the beginning of this handler*/
118 /* Operation code for this handler */
120 /* flags are listed in enum mdt_handler_flags below. */
122 /* The actual handler function to execute. */
123 int (*mh_act)(struct mdt_thread_info *info);
124 /* Request format for this request. */
125 const struct req_format *mh_fmt;
128 enum mdt_handler_flags {
130 * struct mdt_body is passed in the incoming message, and object
131 * identified by this fid exists on disk.
133 * "habeo corpus" == "I have a body"
135 HABEO_CORPUS = (1 << 0),
137 * struct ldlm_request is passed in the incoming message.
139 * "habeo clavis" == "I have a key"
141 HABEO_CLAVIS = (1 << 1),
143 * this request has fixed reply format, so that reply message can be
144 * packed by generic code.
146 * "habeo refero" == "I have a reply"
148 HABEO_REFERO = (1 << 2),
150 * this request will modify something, so check whether the filesystem
151 * is readonly or not, then return -EROFS to client asap if necessary.
153 * "mutabor" == "I shall modify"
158 struct mdt_opc_slice {
161 struct mdt_handler *mos_hs;
164 static struct mdt_opc_slice mdt_regular_handlers[];
165 static struct mdt_opc_slice mdt_readpage_handlers[];
166 static struct mdt_opc_slice mdt_xmds_handlers[];
167 static struct mdt_opc_slice mdt_seq_handlers[];
168 static struct mdt_opc_slice mdt_fld_handlers[];
170 static struct mdt_device *mdt_dev(struct lu_device *d);
171 static int mdt_regular_handle(struct ptlrpc_request *req);
172 static int mdt_unpack_req_pack_rep(struct mdt_thread_info *info, __u32 flags);
173 static int mdt_fid2path(const struct lu_env *env, struct mdt_device *mdt,
174 struct getinfo_fid2path *fp);
176 static const struct lu_object_operations mdt_obj_ops;
178 int mdt_get_disposition(struct ldlm_reply *rep, int flag)
182 return (rep->lock_policy_res1 & flag);
185 void mdt_clear_disposition(struct mdt_thread_info *info,
186 struct ldlm_reply *rep, int flag)
189 info->mti_opdata &= ~flag;
191 rep->lock_policy_res1 &= ~flag;
194 void mdt_set_disposition(struct mdt_thread_info *info,
195 struct ldlm_reply *rep, int flag)
198 info->mti_opdata |= flag;
200 rep->lock_policy_res1 |= flag;
203 void mdt_lock_reg_init(struct mdt_lock_handle *lh, ldlm_mode_t lm)
205 lh->mlh_pdo_hash = 0;
206 lh->mlh_reg_mode = lm;
207 lh->mlh_type = MDT_REG_LOCK;
210 void mdt_lock_pdo_init(struct mdt_lock_handle *lh, ldlm_mode_t lm,
211 const char *name, int namelen)
213 lh->mlh_reg_mode = lm;
214 lh->mlh_type = MDT_PDO_LOCK;
216 if (name != NULL && (name[0] != '\0')) {
217 LASSERT(namelen > 0);
218 lh->mlh_pdo_hash = full_name_hash(name, namelen);
220 LASSERT(namelen == 0);
221 lh->mlh_pdo_hash = 0ull;
225 static void mdt_lock_pdo_mode(struct mdt_thread_info *info, struct mdt_object *o,
226 struct mdt_lock_handle *lh)
232 * Any dir access needs couple of locks:
234 * 1) on part of dir we gonna take lookup/modify;
236 * 2) on whole dir to protect it from concurrent splitting and/or to
237 * flush client's cache for readdir().
239 * so, for a given mode and object this routine decides what lock mode
240 * to use for lock #2:
242 * 1) if caller's gonna lookup in dir then we need to protect dir from
243 * being splitted only - LCK_CR
245 * 2) if caller's gonna modify dir then we need to protect dir from
246 * being splitted and to flush cache - LCK_CW
248 * 3) if caller's gonna modify dir and that dir seems ready for
249 * splitting then we need to protect it from any type of access
250 * (lookup/modify/split) - LCK_EX --bzzz
253 LASSERT(lh->mlh_reg_mode != LCK_MINMODE);
254 LASSERT(lh->mlh_pdo_mode == LCK_MINMODE);
257 * Ask underlaying level its opinion about preferable PDO lock mode
258 * having access type passed as regular lock mode:
260 * - MDL_MINMODE means that lower layer does not want to specify lock
263 * - MDL_NL means that no PDO lock should be taken. This is used in some
264 * cases. Say, for non-splittable directories no need to use PDO locks
267 mode = mdo_lock_mode(info->mti_env, mdt_object_child(o),
268 mdt_dlm_mode2mdl_mode(lh->mlh_reg_mode));
270 if (mode != MDL_MINMODE) {
271 lh->mlh_pdo_mode = mdt_mdl_mode2dlm_mode(mode);
274 * Lower layer does not want to specify locking mode. We do it
275 * our selves. No special protection is needed, just flush
276 * client's cache on modification and allow concurrent
279 switch (lh->mlh_reg_mode) {
281 lh->mlh_pdo_mode = LCK_EX;
284 lh->mlh_pdo_mode = LCK_CR;
287 lh->mlh_pdo_mode = LCK_CW;
290 CERROR("Not expected lock type (0x%x)\n",
291 (int)lh->mlh_reg_mode);
296 LASSERT(lh->mlh_pdo_mode != LCK_MINMODE);
300 static int mdt_getstatus(struct mdt_thread_info *info)
302 struct mdt_device *mdt = info->mti_mdt;
303 struct md_device *next = mdt->mdt_child;
304 struct mdt_body *repbody;
309 rc = mdt_check_ucred(info);
311 RETURN(err_serious(rc));
313 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_GETSTATUS_PACK))
314 RETURN(err_serious(-ENOMEM));
316 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
317 rc = next->md_ops->mdo_root_get(info->mti_env, next, &repbody->fid1);
321 repbody->valid |= OBD_MD_FLID;
323 if (mdt->mdt_opts.mo_mds_capa &&
324 info->mti_exp->exp_connect_flags & OBD_CONNECT_MDS_CAPA) {
325 struct mdt_object *root;
326 struct lustre_capa *capa;
328 root = mdt_object_find(info->mti_env, mdt, &repbody->fid1,
331 RETURN(PTR_ERR(root));
333 capa = req_capsule_server_get(info->mti_pill, &RMF_CAPA1);
335 capa->lc_opc = CAPA_OPC_MDS_DEFAULT;
336 rc = mo_capa_get(info->mti_env, mdt_object_child(root), capa,
338 mdt_object_put(info->mti_env, root);
340 repbody->valid |= OBD_MD_FLMDSCAPA;
346 static int mdt_statfs(struct mdt_thread_info *info)
348 struct ptlrpc_request *req = mdt_info_req(info);
349 struct md_device *next = info->mti_mdt->mdt_child;
350 struct ptlrpc_service *svc;
351 struct obd_statfs *osfs;
356 svc = info->mti_pill->rc_req->rq_rqbd->rqbd_service;
358 /* This will trigger a watchdog timeout */
359 OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_STATFS_LCW_SLEEP,
360 (MDT_SERVICE_WATCHDOG_FACTOR *
361 at_get(&svc->srv_at_estimate)) + 1);
363 rc = mdt_check_ucred(info);
365 RETURN(err_serious(rc));
367 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_STATFS_PACK)) {
368 rc = err_serious(-ENOMEM);
370 osfs = req_capsule_server_get(info->mti_pill, &RMF_OBD_STATFS);
371 rc = next->md_ops->mdo_statfs(info->mti_env, next,
373 statfs_pack(osfs, &info->mti_u.ksfs);
377 mdt_counter_incr(req->rq_export, LPROC_MDT_STATFS);
383 * Pack SOM attributes into the reply.
384 * Call under a DLM UPDATE lock.
386 static void mdt_pack_size2body(struct mdt_thread_info *info,
387 struct mdt_object *mo)
390 struct md_attr *ma = &info->mti_attr;
392 LASSERT(ma->ma_attr.la_valid & LA_MODE);
393 b = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
395 /* Check if Size-on-MDS is supported, if this is a regular file,
396 * if SOM is enabled on the object and if SOM cache exists and valid.
397 * Otherwise do not pack Size-on-MDS attributes to the reply. */
398 if (!(mdt_conn_flags(info) & OBD_CONNECT_SOM) ||
399 !S_ISREG(ma->ma_attr.la_mode) ||
400 !mdt_object_is_som_enabled(mo) ||
401 !(ma->ma_valid & MA_SOM))
404 b->valid |= OBD_MD_FLSIZE | OBD_MD_FLBLOCKS;
405 b->size = ma->ma_som->msd_size;
406 b->blocks = ma->ma_som->msd_blocks;
409 void mdt_pack_attr2body(struct mdt_thread_info *info, struct mdt_body *b,
410 const struct lu_attr *attr, const struct lu_fid *fid)
412 struct md_attr *ma = &info->mti_attr;
414 LASSERT(ma->ma_valid & MA_INODE);
416 b->atime = attr->la_atime;
417 b->mtime = attr->la_mtime;
418 b->ctime = attr->la_ctime;
419 b->mode = attr->la_mode;
420 b->size = attr->la_size;
421 b->blocks = attr->la_blocks;
422 b->uid = attr->la_uid;
423 b->gid = attr->la_gid;
424 b->flags = attr->la_flags;
425 b->nlink = attr->la_nlink;
426 b->rdev = attr->la_rdev;
428 /*XXX should pack the reply body according to lu_valid*/
429 b->valid |= OBD_MD_FLCTIME | OBD_MD_FLUID |
430 OBD_MD_FLGID | OBD_MD_FLTYPE |
431 OBD_MD_FLMODE | OBD_MD_FLNLINK | OBD_MD_FLFLAGS |
432 OBD_MD_FLATIME | OBD_MD_FLMTIME ;
434 if (!S_ISREG(attr->la_mode)) {
435 b->valid |= OBD_MD_FLSIZE | OBD_MD_FLBLOCKS | OBD_MD_FLRDEV;
436 } else if (ma->ma_need & MA_LOV && ma->ma_lmm_size == 0) {
437 /* means no objects are allocated on osts. */
438 LASSERT(!(ma->ma_valid & MA_LOV));
439 /* just ignore blocks occupied by extend attributes on MDS */
441 /* if no object is allocated on osts, the size on mds is valid. b=22272 */
442 b->valid |= OBD_MD_FLSIZE | OBD_MD_FLBLOCKS;
447 b->valid |= OBD_MD_FLID;
449 /* FIXME: these should be fixed when new igif ready.*/
450 b->ino = fid_oid(fid); /* 1.6 compatibility */
451 b->generation = fid_ver(fid); /* 1.6 compatibility */
452 b->valid |= OBD_MD_FLGENER; /* 1.6 compatibility */
454 CDEBUG(D_INODE, DFID": nlink=%d, mode=%o, size="LPU64"\n",
455 PFID(fid), b->nlink, b->mode, b->size);
459 mdt_body_reverse_idmap(info, b);
461 if (b->valid & OBD_MD_FLSIZE)
462 CDEBUG(D_VFSTRACE, DFID": returning size %llu\n",
463 PFID(fid), (unsigned long long)b->size);
466 static inline int mdt_body_has_lov(const struct lu_attr *la,
467 const struct mdt_body *body)
469 return ((S_ISREG(la->la_mode) && (body->valid & OBD_MD_FLEASIZE)) ||
470 (S_ISDIR(la->la_mode) && (body->valid & OBD_MD_FLDIREA )) );
473 void mdt_client_compatibility(struct mdt_thread_info *info)
475 struct mdt_body *body;
476 struct ptlrpc_request *req = mdt_info_req(info);
477 struct obd_export *exp = req->rq_export;
478 struct md_attr *ma = &info->mti_attr;
479 struct lu_attr *la = &ma->ma_attr;
482 if (exp->exp_connect_flags & OBD_CONNECT_LAYOUTLOCK)
483 /* the client can deal with 16-bit lmm_stripe_count */
486 body = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
488 if (!mdt_body_has_lov(la, body))
491 /* now we have a reply with a lov for a client not compatible with the
492 * layout lock so we have to clean the layout generation number */
493 if (S_ISREG(la->la_mode))
494 ma->ma_lmm->lmm_layout_gen = 0;
499 static int mdt_getattr_internal(struct mdt_thread_info *info,
500 struct mdt_object *o, int ma_need)
502 struct md_object *next = mdt_object_child(o);
503 const struct mdt_body *reqbody = info->mti_body;
504 struct ptlrpc_request *req = mdt_info_req(info);
505 struct md_attr *ma = &info->mti_attr;
506 struct lu_attr *la = &ma->ma_attr;
507 struct req_capsule *pill = info->mti_pill;
508 const struct lu_env *env = info->mti_env;
509 struct mdt_body *repbody;
510 struct lu_buf *buffer = &info->mti_buf;
514 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_GETATTR_PACK))
515 RETURN(err_serious(-ENOMEM));
517 repbody = req_capsule_server_get(pill, &RMF_MDT_BODY);
521 rc = mdt_object_exists(o);
523 /* This object is located on remote node.*/
524 repbody->fid1 = *mdt_object_fid(o);
525 repbody->valid = OBD_MD_FLID | OBD_MD_MDS;
529 buffer->lb_buf = req_capsule_server_get(pill, &RMF_MDT_MD);
530 buffer->lb_len = req_capsule_get_size(pill, &RMF_MDT_MD, RCL_SERVER);
532 /* If it is dir object and client require MEA, then we got MEA */
533 if (S_ISDIR(lu_object_attr(&next->mo_lu)) &&
534 reqbody->valid & OBD_MD_MEA) {
535 /* Assumption: MDT_MD size is enough for lmv size. */
536 ma->ma_lmv = buffer->lb_buf;
537 ma->ma_lmv_size = buffer->lb_len;
538 ma->ma_need = MA_LMV | MA_INODE;
540 ma->ma_lmm = buffer->lb_buf;
541 ma->ma_lmm_size = buffer->lb_len;
542 ma->ma_need = MA_LOV | MA_INODE;
545 if (S_ISDIR(lu_object_attr(&next->mo_lu)) &&
546 reqbody->valid & OBD_MD_FLDIREA &&
547 lustre_msg_get_opc(req->rq_reqmsg) == MDS_GETATTR) {
548 /* get default stripe info for this dir. */
549 ma->ma_need |= MA_LOV_DEF;
551 ma->ma_need |= ma_need;
552 if (ma->ma_need & MA_SOM)
553 ma->ma_som = &info->mti_u.som.data;
555 rc = mo_attr_get(env, next, ma);
557 CERROR("getattr error for "DFID": %d\n",
558 PFID(mdt_object_fid(o)), rc);
562 if (likely(ma->ma_valid & MA_INODE))
563 mdt_pack_attr2body(info, repbody, la, mdt_object_fid(o));
567 if (mdt_body_has_lov(la, reqbody)) {
568 if (ma->ma_valid & MA_LOV) {
569 LASSERT(ma->ma_lmm_size);
570 mdt_dump_lmm(D_INFO, ma->ma_lmm);
571 repbody->eadatasize = ma->ma_lmm_size;
572 if (S_ISDIR(la->la_mode))
573 repbody->valid |= OBD_MD_FLDIREA;
575 repbody->valid |= OBD_MD_FLEASIZE;
577 if (ma->ma_valid & MA_LMV) {
578 LASSERT(S_ISDIR(la->la_mode));
579 repbody->eadatasize = ma->ma_lmv_size;
580 repbody->valid |= (OBD_MD_FLDIREA|OBD_MD_MEA);
582 } else if (S_ISLNK(la->la_mode) &&
583 reqbody->valid & OBD_MD_LINKNAME) {
584 buffer->lb_buf = ma->ma_lmm;
585 buffer->lb_len = reqbody->eadatasize;
586 rc = mo_readlink(env, next, buffer);
587 if (unlikely(rc <= 0)) {
588 CERROR("readlink failed: %d\n", rc);
591 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_READLINK_EPROTO))
593 repbody->valid |= OBD_MD_LINKNAME;
594 repbody->eadatasize = rc;
596 ((char*)ma->ma_lmm)[rc - 1] = 0;
597 CDEBUG(D_INODE, "symlink dest %s, len = %d\n",
598 (char*)ma->ma_lmm, rc);
603 if (reqbody->valid & OBD_MD_FLMODEASIZE) {
604 repbody->max_cookiesize = info->mti_mdt->mdt_max_cookiesize;
605 repbody->max_mdsize = info->mti_mdt->mdt_max_mdsize;
606 repbody->valid |= OBD_MD_FLMODEASIZE;
607 CDEBUG(D_INODE, "I am going to change the MAX_MD_SIZE & "
608 "MAX_COOKIE to : %d:%d\n", repbody->max_mdsize,
609 repbody->max_cookiesize);
612 if (exp_connect_rmtclient(info->mti_exp) &&
613 reqbody->valid & OBD_MD_FLRMTPERM) {
614 void *buf = req_capsule_server_get(pill, &RMF_ACL);
616 /* mdt_getattr_lock only */
617 rc = mdt_pack_remote_perm(info, o, buf);
619 repbody->valid &= ~OBD_MD_FLRMTPERM;
620 repbody->aclsize = 0;
623 repbody->valid |= OBD_MD_FLRMTPERM;
624 repbody->aclsize = sizeof(struct mdt_remote_perm);
627 #ifdef CONFIG_FS_POSIX_ACL
628 else if ((req->rq_export->exp_connect_flags & OBD_CONNECT_ACL) &&
629 (reqbody->valid & OBD_MD_FLACL)) {
630 buffer->lb_buf = req_capsule_server_get(pill, &RMF_ACL);
631 buffer->lb_len = req_capsule_get_size(pill,
632 &RMF_ACL, RCL_SERVER);
633 if (buffer->lb_len > 0) {
634 rc = mo_xattr_get(env, next, buffer,
635 XATTR_NAME_ACL_ACCESS);
637 if (rc == -ENODATA) {
638 repbody->aclsize = 0;
639 repbody->valid |= OBD_MD_FLACL;
641 } else if (rc == -EOPNOTSUPP) {
644 CERROR("got acl size: %d\n", rc);
647 repbody->aclsize = rc;
648 repbody->valid |= OBD_MD_FLACL;
655 if (reqbody->valid & OBD_MD_FLMDSCAPA &&
656 info->mti_mdt->mdt_opts.mo_mds_capa &&
657 info->mti_exp->exp_connect_flags & OBD_CONNECT_MDS_CAPA) {
658 struct lustre_capa *capa;
660 capa = req_capsule_server_get(pill, &RMF_CAPA1);
662 capa->lc_opc = CAPA_OPC_MDS_DEFAULT;
663 rc = mo_capa_get(env, next, capa, 0);
666 repbody->valid |= OBD_MD_FLMDSCAPA;
671 static int mdt_renew_capa(struct mdt_thread_info *info)
673 struct mdt_object *obj = info->mti_object;
674 struct mdt_body *body;
675 struct lustre_capa *capa, *c;
679 /* if object doesn't exist, or server has disabled capability,
680 * return directly, client will find body->valid OBD_MD_FLOSSCAPA
683 if (!obj || !info->mti_mdt->mdt_opts.mo_oss_capa ||
684 !(info->mti_exp->exp_connect_flags & OBD_CONNECT_OSS_CAPA))
687 body = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
688 LASSERT(body != NULL);
690 c = req_capsule_client_get(info->mti_pill, &RMF_CAPA1);
693 capa = req_capsule_server_get(info->mti_pill, &RMF_CAPA2);
697 rc = mo_capa_get(info->mti_env, mdt_object_child(obj), capa, 1);
699 body->valid |= OBD_MD_FLOSSCAPA;
703 static int mdt_getattr(struct mdt_thread_info *info)
705 struct ptlrpc_request *req = mdt_info_req(info);
706 struct mdt_object *obj = info->mti_object;
707 struct req_capsule *pill = info->mti_pill;
708 struct mdt_body *reqbody;
709 struct mdt_body *repbody;
715 reqbody = req_capsule_client_get(pill, &RMF_MDT_BODY);
718 if (reqbody->valid & OBD_MD_FLOSSCAPA) {
719 rc = req_capsule_server_pack(pill);
721 RETURN(err_serious(rc));
722 rc = mdt_renew_capa(info);
723 GOTO(out_shrink, rc);
726 LASSERT(obj != NULL);
727 LASSERT(lu_object_assert_exists(&obj->mot_obj.mo_lu));
729 mode = lu_object_attr(&obj->mot_obj.mo_lu);
730 if (S_ISLNK(mode) && (reqbody->valid & OBD_MD_LINKNAME) &&
731 (reqbody->eadatasize > info->mti_mdt->mdt_max_mdsize))
732 md_size = reqbody->eadatasize;
734 md_size = info->mti_mdt->mdt_max_mdsize;
736 req_capsule_set_size(pill, &RMF_MDT_MD, RCL_SERVER, md_size);
738 rc = req_capsule_server_pack(pill);
739 if (unlikely(rc != 0))
740 RETURN(err_serious(rc));
742 repbody = req_capsule_server_get(pill, &RMF_MDT_BODY);
743 LASSERT(repbody != NULL);
744 repbody->eadatasize = 0;
745 repbody->aclsize = 0;
747 if (reqbody->valid & OBD_MD_FLRMTPERM)
748 rc = mdt_init_ucred(info, reqbody);
750 rc = mdt_check_ucred(info);
752 GOTO(out_shrink, rc);
754 info->mti_spec.sp_ck_split = !!(reqbody->valid & OBD_MD_FLCKSPLIT);
755 info->mti_cross_ref = !!(reqbody->valid & OBD_MD_FLCROSSREF);
758 * Don't check capability at all, because rename might getattr for
759 * remote obj, and at that time no capability is available.
761 mdt_set_capainfo(info, 1, &reqbody->fid1, BYPASS_CAPA);
762 rc = mdt_getattr_internal(info, obj, 0);
763 if (reqbody->valid & OBD_MD_FLRMTPERM)
764 mdt_exit_ucred(info);
768 mdt_counter_incr(req->rq_export, LPROC_MDT_GETATTR);
770 mdt_client_compatibility(info);
771 mdt_shrink_reply(info);
775 static int mdt_is_subdir(struct mdt_thread_info *info)
777 struct mdt_object *o = info->mti_object;
778 struct req_capsule *pill = info->mti_pill;
779 const struct mdt_body *body = info->mti_body;
780 struct mdt_body *repbody;
786 repbody = req_capsule_server_get(pill, &RMF_MDT_BODY);
789 * We save last checked parent fid to @repbody->fid1 for remote
792 LASSERT(fid_is_sane(&body->fid2));
793 LASSERT(mdt_object_exists(o) > 0);
794 rc = mdo_is_subdir(info->mti_env, mdt_object_child(o),
795 &body->fid2, &repbody->fid1);
796 if (rc == 0 || rc == -EREMOTE)
797 repbody->valid |= OBD_MD_FLID;
802 static int mdt_raw_lookup(struct mdt_thread_info *info,
803 struct mdt_object *parent,
804 const struct lu_name *lname,
805 struct ldlm_reply *ldlm_rep)
807 struct md_object *next = mdt_object_child(info->mti_object);
808 const struct mdt_body *reqbody = info->mti_body;
809 struct lu_fid *child_fid = &info->mti_tmp_fid1;
810 struct mdt_body *repbody;
814 if (reqbody->valid != OBD_MD_FLID)
817 LASSERT(!info->mti_cross_ref);
819 /* Only got the fid of this obj by name */
820 rc = mdo_lookup(info->mti_env, next, lname, child_fid,
823 /* XXX is raw_lookup possible as intent operation? */
826 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_NEG);
829 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_POS);
831 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
834 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
835 repbody->fid1 = *child_fid;
836 repbody->valid = OBD_MD_FLID;
842 * UPDATE lock should be taken against parent, and be release before exit;
843 * child_bits lock should be taken against child, and be returned back:
844 * (1)normal request should release the child lock;
845 * (2)intent request will grant the lock to client.
847 static int mdt_getattr_name_lock(struct mdt_thread_info *info,
848 struct mdt_lock_handle *lhc,
850 struct ldlm_reply *ldlm_rep)
852 struct ptlrpc_request *req = mdt_info_req(info);
853 struct mdt_body *reqbody = NULL;
854 struct mdt_object *parent = info->mti_object;
855 struct mdt_object *child;
856 struct md_object *next = mdt_object_child(parent);
857 struct lu_fid *child_fid = &info->mti_tmp_fid1;
858 struct lu_name *lname = NULL;
859 const char *name = NULL;
861 struct mdt_lock_handle *lhp = NULL;
862 struct ldlm_lock *lock;
863 struct ldlm_res_id *res_id;
870 is_resent = lustre_handle_is_used(&lhc->mlh_reg_lh);
871 LASSERT(ergo(is_resent,
872 lustre_msg_get_flags(req->rq_reqmsg) & MSG_RESENT));
874 LASSERT(parent != NULL);
875 name = req_capsule_client_get(info->mti_pill, &RMF_NAME);
877 RETURN(err_serious(-EFAULT));
879 namelen = req_capsule_get_size(info->mti_pill, &RMF_NAME,
881 if (!info->mti_cross_ref) {
883 * XXX: Check for "namelen == 0" is for getattr by fid
884 * (OBD_CONNECT_ATTRFID), otherwise do not allow empty name,
885 * that is the name must contain at least one character and
886 * the terminating '\0'
889 reqbody = req_capsule_client_get(info->mti_pill,
891 if (unlikely(reqbody == NULL))
892 RETURN(err_serious(-EFAULT));
894 if (unlikely(!fid_is_sane(&reqbody->fid2)))
895 RETURN(err_serious(-EINVAL));
898 CDEBUG(D_INODE, "getattr with lock for "DFID"/"DFID", "
900 PFID(mdt_object_fid(parent)),
901 PFID(&reqbody->fid2), ldlm_rep);
903 lname = mdt_name(info->mti_env, (char *)name, namelen);
904 CDEBUG(D_INODE, "getattr with lock for "DFID"/%s, "
905 "ldlm_rep = %p\n", PFID(mdt_object_fid(parent)),
909 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_EXECD);
911 rc = mdt_object_exists(parent);
912 if (unlikely(rc == 0)) {
913 LU_OBJECT_DEBUG(D_WARNING, info->mti_env,
914 &parent->mot_obj.mo_lu,
915 "Parent doesn't exist!\n");
917 } else if (!info->mti_cross_ref) {
918 LASSERTF(rc > 0, "Parent "DFID" is on remote server\n",
919 PFID(mdt_object_fid(parent)));
922 rc = mdt_raw_lookup(info, parent, lname, ldlm_rep);
930 if (info->mti_cross_ref) {
931 /* Only getattr on the child. Parent is on another node. */
932 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_POS);
934 CDEBUG(D_INODE, "partial getattr_name child_fid = "DFID", "
935 "ldlm_rep=%p\n", PFID(mdt_object_fid(child)), ldlm_rep);
938 /* Do not take lock for resent case. */
939 lock = ldlm_handle2lock(&lhc->mlh_reg_lh);
940 LASSERTF(lock != NULL, "Invalid lock handle "LPX64"\n",
941 lhc->mlh_reg_lh.cookie);
942 LASSERT(fid_res_name_eq(mdt_object_fid(child),
943 &lock->l_resource->lr_name));
947 mdt_lock_handle_init(lhc);
948 mdt_lock_reg_init(lhc, LCK_PR);
951 * Object's name is on another MDS, no lookup lock is
952 * needed here but update is.
954 child_bits &= ~MDS_INODELOCK_LOOKUP;
955 child_bits |= MDS_INODELOCK_UPDATE;
957 rc = mdt_object_lock(info, child, lhc, child_bits,
961 /* Finally, we can get attr for child. */
962 mdt_set_capainfo(info, 0, mdt_object_fid(child),
964 rc = mdt_getattr_internal(info, child, 0);
965 if (unlikely(rc != 0))
966 mdt_object_unlock(info, child, lhc, 1);
972 /* step 1: lock parent only if parent is a directory */
973 if (S_ISDIR(lu_object_attr(&parent->mot_obj.mo_lu))) {
974 lhp = &info->mti_lh[MDT_LH_PARENT];
975 mdt_lock_pdo_init(lhp, LCK_PR, name, namelen);
976 rc = mdt_object_lock(info, parent, lhp,
977 MDS_INODELOCK_UPDATE,
979 if (unlikely(rc != 0))
983 /* step 2: lookup child's fid by name */
984 rc = mdo_lookup(info->mti_env, next, lname, child_fid,
989 mdt_set_disposition(info, ldlm_rep,
991 GOTO(out_parent, rc);
993 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_POS);
995 *child_fid = reqbody->fid2;
996 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_POS);
1000 *step 3: find the child object by fid & lock it.
1001 * regardless if it is local or remote.
1003 child = mdt_object_find(info->mti_env, info->mti_mdt, child_fid,
1004 MDT_OBJ_MUST_EXIST);
1006 if (unlikely(IS_ERR(child)))
1007 GOTO(out_parent, rc = PTR_ERR(child));
1009 /* Do not take lock for resent case. */
1010 lock = ldlm_handle2lock(&lhc->mlh_reg_lh);
1011 LASSERTF(lock != NULL, "Invalid lock handle "LPX64"\n",
1012 lhc->mlh_reg_lh.cookie);
1014 res_id = &lock->l_resource->lr_name;
1015 if (!fid_res_name_eq(mdt_object_fid(child),
1016 &lock->l_resource->lr_name)) {
1017 LASSERTF(fid_res_name_eq(mdt_object_fid(parent),
1018 &lock->l_resource->lr_name),
1019 "Lock res_id: %lu/%lu/%lu, Fid: "DFID".\n",
1020 (unsigned long)res_id->name[0],
1021 (unsigned long)res_id->name[1],
1022 (unsigned long)res_id->name[2],
1023 PFID(mdt_object_fid(parent)));
1024 CWARN("Although resent, but still not get child lock"
1025 "parent:"DFID" child:"DFID"\n",
1026 PFID(mdt_object_fid(parent)),
1027 PFID(mdt_object_fid(child)));
1028 lustre_msg_clear_flags(req->rq_reqmsg, MSG_RESENT);
1029 LDLM_LOCK_PUT(lock);
1032 LDLM_LOCK_PUT(lock);
1036 OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_RESEND, obd_timeout*2);
1037 mdt_lock_handle_init(lhc);
1038 if (child_bits == MDS_INODELOCK_LAYOUT)
1039 mdt_lock_reg_init(lhc, LCK_CR);
1041 mdt_lock_reg_init(lhc, LCK_PR);
1043 if (!(child_bits & MDS_INODELOCK_UPDATE)) {
1044 struct md_attr *ma = &info->mti_attr;
1047 ma->ma_need = MA_INODE;
1048 rc = mo_attr_get(info->mti_env,
1049 mdt_object_child(child), ma);
1050 if (unlikely(rc != 0))
1051 GOTO(out_child, rc);
1053 /* layout lock is used only on regular files */
1054 if ((ma->ma_valid & MA_INODE) &&
1055 (ma->ma_attr.la_valid & LA_MODE) &&
1056 !S_ISREG(ma->ma_attr.la_mode))
1057 child_bits &= ~MDS_INODELOCK_LAYOUT;
1059 /* If the file has not been changed for some time, we
1060 * return not only a LOOKUP lock, but also an UPDATE
1061 * lock and this might save us RPC on later STAT. For
1062 * directories, it also let negative dentry starts
1063 * working for this dir. */
1064 if (ma->ma_valid & MA_INODE &&
1065 ma->ma_attr.la_valid & LA_CTIME &&
1066 info->mti_mdt->mdt_namespace->ns_ctime_age_limit +
1067 ma->ma_attr.la_ctime < cfs_time_current_sec())
1068 child_bits |= MDS_INODELOCK_UPDATE;
1071 rc = mdt_object_lock(info, child, lhc, child_bits,
1074 if (unlikely(rc != 0))
1075 GOTO(out_child, rc);
1078 lock = ldlm_handle2lock(&lhc->mlh_reg_lh);
1079 /* Get MA_SOM attributes if update lock is given. */
1081 lock->l_policy_data.l_inodebits.bits & MDS_INODELOCK_UPDATE &&
1082 S_ISREG(lu_object_attr(&mdt_object_child(child)->mo_lu)))
1085 /* finally, we can get attr for child. */
1086 mdt_set_capainfo(info, 1, child_fid, BYPASS_CAPA);
1087 rc = mdt_getattr_internal(info, child, ma_need);
1088 if (unlikely(rc != 0)) {
1089 mdt_object_unlock(info, child, lhc, 1);
1091 /* Debugging code. */
1092 res_id = &lock->l_resource->lr_name;
1093 LDLM_DEBUG(lock, "Returning lock to client");
1094 LASSERTF(fid_res_name_eq(mdt_object_fid(child),
1095 &lock->l_resource->lr_name),
1096 "Lock res_id: %lu/%lu/%lu, Fid: "DFID".\n",
1097 (unsigned long)res_id->name[0],
1098 (unsigned long)res_id->name[1],
1099 (unsigned long)res_id->name[2],
1100 PFID(mdt_object_fid(child)));
1101 mdt_pack_size2body(info, child);
1104 LDLM_LOCK_PUT(lock);
1108 mdt_object_put(info->mti_env, child);
1111 mdt_object_unlock(info, parent, lhp, 1);
1115 /* normal handler: should release the child lock */
1116 static int mdt_getattr_name(struct mdt_thread_info *info)
1118 struct mdt_lock_handle *lhc = &info->mti_lh[MDT_LH_CHILD];
1119 struct mdt_body *reqbody;
1120 struct mdt_body *repbody;
1124 reqbody = req_capsule_client_get(info->mti_pill, &RMF_MDT_BODY);
1125 LASSERT(reqbody != NULL);
1126 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
1127 LASSERT(repbody != NULL);
1129 info->mti_spec.sp_ck_split = !!(reqbody->valid & OBD_MD_FLCKSPLIT);
1130 info->mti_cross_ref = !!(reqbody->valid & OBD_MD_FLCROSSREF);
1131 repbody->eadatasize = 0;
1132 repbody->aclsize = 0;
1134 rc = mdt_init_ucred(info, reqbody);
1136 GOTO(out_shrink, rc);
1138 rc = mdt_getattr_name_lock(info, lhc, MDS_INODELOCK_UPDATE, NULL);
1139 if (lustre_handle_is_used(&lhc->mlh_reg_lh)) {
1140 ldlm_lock_decref(&lhc->mlh_reg_lh, lhc->mlh_reg_mode);
1141 lhc->mlh_reg_lh.cookie = 0;
1143 mdt_exit_ucred(info);
1146 mdt_client_compatibility(info);
1147 mdt_shrink_reply(info);
1151 static const struct lu_device_operations mdt_lu_ops;
1153 static int lu_device_is_mdt(struct lu_device *d)
1155 return ergo(d != NULL && d->ld_ops != NULL, d->ld_ops == &mdt_lu_ops);
1158 static int mdt_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
1159 void *karg, void *uarg);
1161 static int mdt_set_info(struct mdt_thread_info *info)
1163 struct ptlrpc_request *req = mdt_info_req(info);
1166 int keylen, vallen, rc = 0;
1169 rc = req_capsule_server_pack(info->mti_pill);
1173 key = req_capsule_client_get(info->mti_pill, &RMF_SETINFO_KEY);
1175 DEBUG_REQ(D_HA, req, "no set_info key");
1179 keylen = req_capsule_get_size(info->mti_pill, &RMF_SETINFO_KEY,
1182 val = req_capsule_client_get(info->mti_pill, &RMF_SETINFO_VAL);
1184 DEBUG_REQ(D_HA, req, "no set_info val");
1188 vallen = req_capsule_get_size(info->mti_pill, &RMF_SETINFO_VAL,
1191 /* Swab any part of val you need to here */
1192 if (KEY_IS(KEY_READ_ONLY)) {
1194 lustre_msg_set_status(req->rq_repmsg, 0);
1196 cfs_spin_lock(&req->rq_export->exp_lock);
1198 req->rq_export->exp_connect_flags |= OBD_CONNECT_RDONLY;
1200 req->rq_export->exp_connect_flags &=~OBD_CONNECT_RDONLY;
1201 cfs_spin_unlock(&req->rq_export->exp_lock);
1203 } else if (KEY_IS(KEY_CHANGELOG_CLEAR)) {
1204 struct changelog_setinfo *cs =
1205 (struct changelog_setinfo *)val;
1206 if (vallen != sizeof(*cs)) {
1207 CERROR("Bad changelog_clear setinfo size %d\n", vallen);
1210 if (ptlrpc_req_need_swab(req)) {
1211 __swab64s(&cs->cs_recno);
1212 __swab32s(&cs->cs_id);
1215 rc = mdt_iocontrol(OBD_IOC_CHANGELOG_CLEAR, info->mti_exp,
1217 lustre_msg_set_status(req->rq_repmsg, rc);
1225 static int mdt_connect(struct mdt_thread_info *info)
1228 struct ptlrpc_request *req;
1230 req = mdt_info_req(info);
1231 rc = target_handle_connect(req);
1233 LASSERT(req->rq_export != NULL);
1234 info->mti_mdt = mdt_dev(req->rq_export->exp_obd->obd_lu_dev);
1235 rc = mdt_init_sec_level(info);
1237 rc = mdt_init_idmap(info);
1239 obd_disconnect(class_export_get(req->rq_export));
1241 rc = err_serious(rc);
1246 static int mdt_disconnect(struct mdt_thread_info *info)
1251 rc = target_handle_disconnect(mdt_info_req(info));
1253 rc = err_serious(rc);
1257 static int mdt_sendpage(struct mdt_thread_info *info,
1258 struct lu_rdpg *rdpg, int nob)
1260 struct ptlrpc_request *req = mdt_info_req(info);
1261 struct obd_export *exp = req->rq_export;
1262 struct ptlrpc_bulk_desc *desc;
1263 struct l_wait_info *lwi = &info->mti_u.rdpg.mti_wait_info;
1270 desc = ptlrpc_prep_bulk_exp(req, rdpg->rp_npages, BULK_PUT_SOURCE,
1275 for (i = 0, tmpcount = nob;
1276 i < rdpg->rp_npages && tmpcount > 0; i++, tmpcount -= tmpsize) {
1277 tmpsize = min_t(int, tmpcount, CFS_PAGE_SIZE);
1278 ptlrpc_prep_bulk_page(desc, rdpg->rp_pages[i], 0, tmpsize);
1281 LASSERT(desc->bd_nob == nob);
1282 rc = target_bulk_io(exp, desc, lwi);
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 = min_t(unsigned int, reqbody->nlink,
1495 PTLRPC_MAX_BRW_SIZE);
1496 rdpg->rp_npages = (rdpg->rp_count + CFS_PAGE_SIZE - 1) >>
1498 OBD_ALLOC(rdpg->rp_pages, rdpg->rp_npages * sizeof rdpg->rp_pages[0]);
1499 if (rdpg->rp_pages == NULL)
1502 for (i = 0; i < rdpg->rp_npages; ++i) {
1503 rdpg->rp_pages[i] = cfs_alloc_page(CFS_ALLOC_STD);
1504 if (rdpg->rp_pages[i] == NULL)
1505 GOTO(free_rdpg, rc = -ENOMEM);
1508 /* call lower layers to fill allocated pages with directory data */
1509 rc = mo_readpage(info->mti_env, mdt_object_child(object), rdpg);
1511 GOTO(free_rdpg, rc);
1513 /* send pages to client */
1514 rc = mdt_sendpage(info, rdpg, rc);
1519 for (i = 0; i < rdpg->rp_npages; i++)
1520 if (rdpg->rp_pages[i] != NULL)
1521 cfs_free_page(rdpg->rp_pages[i]);
1522 OBD_FREE(rdpg->rp_pages, rdpg->rp_npages * sizeof rdpg->rp_pages[0]);
1524 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_SENDPAGE))
1530 static int mdt_reint_internal(struct mdt_thread_info *info,
1531 struct mdt_lock_handle *lhc,
1534 struct req_capsule *pill = info->mti_pill;
1535 struct mdt_device *mdt = info->mti_mdt;
1536 struct md_quota *mq = md_quota(info->mti_env);
1537 struct mdt_body *repbody;
1542 if (req_capsule_has_field(pill, &RMF_MDT_MD, RCL_SERVER))
1543 req_capsule_set_size(pill, &RMF_MDT_MD, RCL_SERVER,
1544 mdt->mdt_max_mdsize);
1545 if (req_capsule_has_field(pill, &RMF_LOGCOOKIES, RCL_SERVER))
1546 req_capsule_set_size(pill, &RMF_LOGCOOKIES, RCL_SERVER,
1547 mdt->mdt_max_cookiesize);
1549 rc = req_capsule_server_pack(pill);
1551 CERROR("Can't pack response, rc %d\n", rc);
1552 RETURN(err_serious(rc));
1555 if (req_capsule_has_field(pill, &RMF_MDT_BODY, RCL_SERVER)) {
1556 repbody = req_capsule_server_get(pill, &RMF_MDT_BODY);
1558 repbody->eadatasize = 0;
1559 repbody->aclsize = 0;
1562 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_REINT_UNPACK))
1563 GOTO(out_shrink, rc = err_serious(-EFAULT));
1565 rc = mdt_reint_unpack(info, op);
1567 CERROR("Can't unpack reint, rc %d\n", rc);
1568 GOTO(out_shrink, rc = err_serious(rc));
1571 OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_REINT_DELAY, 10);
1573 /* for replay no cookkie / lmm need, because client have this already */
1574 if (info->mti_spec.no_create == 1) {
1575 if (req_capsule_has_field(pill, &RMF_MDT_MD, RCL_SERVER))
1576 req_capsule_set_size(pill, &RMF_MDT_MD, RCL_SERVER, 0);
1578 if (req_capsule_has_field(pill, &RMF_LOGCOOKIES, RCL_SERVER))
1579 req_capsule_set_size(pill, &RMF_LOGCOOKIES, RCL_SERVER,
1583 rc = mdt_init_ucred_reint(info);
1585 GOTO(out_shrink, rc);
1587 rc = mdt_fix_attr_ucred(info, op);
1589 GOTO(out_ucred, rc = err_serious(rc));
1591 if (mdt_check_resent(info, mdt_reconstruct, lhc)) {
1592 rc = lustre_msg_get_status(mdt_info_req(info)->rq_repmsg);
1593 GOTO(out_ucred, rc);
1595 mq->mq_exp = info->mti_exp;
1596 rc = mdt_reint_rec(info, lhc);
1599 mdt_exit_ucred(info);
1601 mdt_client_compatibility(info);
1602 mdt_shrink_reply(info);
1606 static long mdt_reint_opcode(struct mdt_thread_info *info,
1607 const struct req_format **fmt)
1609 struct mdt_rec_reint *rec;
1612 opc = err_serious(-EFAULT);
1613 rec = req_capsule_client_get(info->mti_pill, &RMF_REC_REINT);
1615 opc = rec->rr_opcode;
1616 DEBUG_REQ(D_INODE, mdt_info_req(info), "reint opt = %ld", opc);
1617 if (opc < REINT_MAX && fmt[opc] != NULL)
1618 req_capsule_extend(info->mti_pill, fmt[opc]);
1620 CERROR("Unsupported opc: %ld\n", opc);
1621 opc = err_serious(opc);
1627 static int mdt_reint(struct mdt_thread_info *info)
1632 static const struct req_format *reint_fmts[REINT_MAX] = {
1633 [REINT_SETATTR] = &RQF_MDS_REINT_SETATTR,
1634 [REINT_CREATE] = &RQF_MDS_REINT_CREATE,
1635 [REINT_LINK] = &RQF_MDS_REINT_LINK,
1636 [REINT_UNLINK] = &RQF_MDS_REINT_UNLINK,
1637 [REINT_RENAME] = &RQF_MDS_REINT_RENAME,
1638 [REINT_OPEN] = &RQF_MDS_REINT_OPEN,
1639 [REINT_SETXATTR] = &RQF_MDS_REINT_SETXATTR
1644 opc = mdt_reint_opcode(info, reint_fmts);
1647 * No lock possible here from client to pass it to reint code
1650 rc = mdt_reint_internal(info, NULL, opc);
1655 info->mti_fail_id = OBD_FAIL_MDS_REINT_NET_REP;
1659 /* this should sync the whole device */
1660 static int mdt_device_sync(const struct lu_env *env, struct mdt_device *mdt)
1662 struct dt_device *dt = mdt->mdt_bottom;
1666 rc = dt->dd_ops->dt_sync(env, dt);
1670 /* this should sync this object */
1671 static int mdt_object_sync(struct mdt_thread_info *info)
1673 struct md_object *next;
1677 if (!mdt_object_exists(info->mti_object)) {
1678 CWARN("Non existing object "DFID"!\n",
1679 PFID(mdt_object_fid(info->mti_object)));
1682 next = mdt_object_child(info->mti_object);
1683 rc = mo_object_sync(info->mti_env, next);
1688 static int mdt_sync(struct mdt_thread_info *info)
1690 struct ptlrpc_request *req = mdt_info_req(info);
1691 struct req_capsule *pill = info->mti_pill;
1692 struct mdt_body *body;
1696 /* The fid may be zero, so we req_capsule_set manually */
1697 req_capsule_set(pill, &RQF_MDS_SYNC);
1699 body = req_capsule_client_get(pill, &RMF_MDT_BODY);
1701 RETURN(err_serious(-EINVAL));
1703 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_SYNC_PACK))
1704 RETURN(err_serious(-ENOMEM));
1706 if (fid_seq(&body->fid1) == 0) {
1707 /* sync the whole device */
1708 rc = req_capsule_server_pack(pill);
1710 rc = mdt_device_sync(info->mti_env, info->mti_mdt);
1712 rc = err_serious(rc);
1714 /* sync an object */
1715 rc = mdt_unpack_req_pack_rep(info, HABEO_CORPUS|HABEO_REFERO);
1717 rc = mdt_object_sync(info);
1719 struct md_object *next;
1720 const struct lu_fid *fid;
1721 struct lu_attr *la = &info->mti_attr.ma_attr;
1723 next = mdt_object_child(info->mti_object);
1724 info->mti_attr.ma_need = MA_INODE;
1725 info->mti_attr.ma_valid = 0;
1726 rc = mo_attr_get(info->mti_env, next,
1729 body = req_capsule_server_get(pill,
1731 fid = mdt_object_fid(info->mti_object);
1732 mdt_pack_attr2body(info, body, la, fid);
1736 rc = err_serious(rc);
1739 mdt_counter_incr(req->rq_export, LPROC_MDT_SYNC);
1744 #ifdef HAVE_QUOTA_SUPPORT
1745 static int mdt_quotacheck_handle(struct mdt_thread_info *info)
1747 struct obd_quotactl *oqctl;
1748 struct req_capsule *pill = info->mti_pill;
1749 struct obd_export *exp = info->mti_exp;
1750 struct md_quota *mq = md_quota(info->mti_env);
1751 struct md_device *next = info->mti_mdt->mdt_child;
1755 oqctl = req_capsule_client_get(pill, &RMF_OBD_QUOTACTL);
1759 /* remote client has no permission for quotacheck */
1760 if (unlikely(exp_connect_rmtclient(exp)))
1763 rc = req_capsule_server_pack(pill);
1768 rc = next->md_ops->mdo_quota.mqo_check(info->mti_env, next,
1773 static int mdt_quotactl_handle(struct mdt_thread_info *info)
1775 struct obd_quotactl *oqctl, *repoqc;
1776 struct req_capsule *pill = info->mti_pill;
1777 struct obd_export *exp = info->mti_exp;
1778 struct md_quota *mq = md_quota(info->mti_env);
1779 struct md_device *next = info->mti_mdt->mdt_child;
1780 const struct md_quota_operations *mqo = &next->md_ops->mdo_quota;
1784 oqctl = req_capsule_client_get(pill, &RMF_OBD_QUOTACTL);
1789 if (exp_connect_rmtclient(exp)) {
1790 struct ptlrpc_request *req = mdt_info_req(info);
1791 struct mdt_export_data *med = mdt_req2med(req);
1792 struct lustre_idmap_table *idmap = med->med_idmap;
1794 if (unlikely(oqctl->qc_cmd != Q_GETQUOTA &&
1795 oqctl->qc_cmd != Q_GETINFO))
1799 if (oqctl->qc_type == USRQUOTA)
1800 id = lustre_idmap_lookup_uid(NULL, idmap, 0,
1802 else if (oqctl->qc_type == GRPQUOTA)
1803 id = lustre_idmap_lookup_gid(NULL, idmap, 0,
1808 if (id == CFS_IDMAP_NOTFOUND) {
1809 CDEBUG(D_QUOTA, "no mapping for id %u\n",
1815 rc = req_capsule_server_pack(pill);
1819 repoqc = req_capsule_server_get(pill, &RMF_OBD_QUOTACTL);
1820 LASSERT(repoqc != NULL);
1823 switch (oqctl->qc_cmd) {
1825 rc = mqo->mqo_on(info->mti_env, next, oqctl->qc_type);
1828 rc = mqo->mqo_off(info->mti_env, next, oqctl->qc_type);
1831 rc = mqo->mqo_setinfo(info->mti_env, next, oqctl->qc_type, id,
1835 rc = mqo->mqo_getinfo(info->mti_env, next, oqctl->qc_type, id,
1839 rc = mqo->mqo_setquota(info->mti_env, next, oqctl->qc_type, id,
1843 rc = mqo->mqo_getquota(info->mti_env, next, oqctl->qc_type, id,
1847 rc = mqo->mqo_getoinfo(info->mti_env, next, oqctl->qc_type, id,
1851 rc = mqo->mqo_getoquota(info->mti_env, next, oqctl->qc_type, id,
1854 case LUSTRE_Q_INVALIDATE:
1855 rc = mqo->mqo_invalidate(info->mti_env, next, oqctl->qc_type);
1857 case LUSTRE_Q_FINVALIDATE:
1858 rc = mqo->mqo_finvalidate(info->mti_env, next, oqctl->qc_type);
1861 CERROR("unsupported mdt_quotactl command: %d\n",
1873 * OBD PING and other handlers.
1875 static int mdt_obd_ping(struct mdt_thread_info *info)
1880 req_capsule_set(info->mti_pill, &RQF_OBD_PING);
1882 rc = target_handle_ping(mdt_info_req(info));
1884 rc = err_serious(rc);
1888 static int mdt_obd_log_cancel(struct mdt_thread_info *info)
1890 return err_serious(-EOPNOTSUPP);
1893 static int mdt_obd_qc_callback(struct mdt_thread_info *info)
1895 return err_serious(-EOPNOTSUPP);
1903 /** clone llog ctxt from child (mdd)
1904 * This allows remote llog (replicator) access.
1905 * We can either pass all llog RPCs (eg mdt_llog_create) on to child where the
1906 * context was originally set up, or we can handle them directly.
1907 * I choose the latter, but that means I need any llog
1908 * contexts set up by child to be accessable by the mdt. So we clone the
1909 * context into our context list here.
1911 static int mdt_llog_ctxt_clone(const struct lu_env *env, struct mdt_device *mdt,
1914 struct md_device *next = mdt->mdt_child;
1915 struct llog_ctxt *ctxt;
1918 if (!llog_ctxt_null(mdt2obd_dev(mdt), idx))
1921 rc = next->md_ops->mdo_llog_ctxt_get(env, next, idx, (void **)&ctxt);
1922 if (rc || ctxt == NULL) {
1923 CERROR("Can't get mdd ctxt %d\n", rc);
1927 rc = llog_group_set_ctxt(&mdt2obd_dev(mdt)->obd_olg, ctxt, idx);
1929 CERROR("Can't set mdt ctxt %d\n", rc);
1934 static int mdt_llog_ctxt_unclone(const struct lu_env *env,
1935 struct mdt_device *mdt, int idx)
1937 struct llog_ctxt *ctxt;
1939 ctxt = llog_get_context(mdt2obd_dev(mdt), idx);
1942 /* Put once for the get we just did, and once for the clone */
1943 llog_ctxt_put(ctxt);
1944 llog_ctxt_put(ctxt);
1948 static int mdt_llog_create(struct mdt_thread_info *info)
1952 req_capsule_set(info->mti_pill, &RQF_LLOG_ORIGIN_HANDLE_CREATE);
1953 rc = llog_origin_handle_create(mdt_info_req(info));
1954 return (rc < 0 ? err_serious(rc) : rc);
1957 static int mdt_llog_destroy(struct mdt_thread_info *info)
1961 req_capsule_set(info->mti_pill, &RQF_LLOG_ORIGIN_HANDLE_DESTROY);
1962 rc = llog_origin_handle_destroy(mdt_info_req(info));
1963 return (rc < 0 ? err_serious(rc) : rc);
1966 static int mdt_llog_read_header(struct mdt_thread_info *info)
1970 req_capsule_set(info->mti_pill, &RQF_LLOG_ORIGIN_HANDLE_READ_HEADER);
1971 rc = llog_origin_handle_read_header(mdt_info_req(info));
1972 return (rc < 0 ? err_serious(rc) : rc);
1975 static int mdt_llog_next_block(struct mdt_thread_info *info)
1979 req_capsule_set(info->mti_pill, &RQF_LLOG_ORIGIN_HANDLE_NEXT_BLOCK);
1980 rc = llog_origin_handle_next_block(mdt_info_req(info));
1981 return (rc < 0 ? err_serious(rc) : rc);
1984 static int mdt_llog_prev_block(struct mdt_thread_info *info)
1988 req_capsule_set(info->mti_pill, &RQF_LLOG_ORIGIN_HANDLE_PREV_BLOCK);
1989 rc = llog_origin_handle_prev_block(mdt_info_req(info));
1990 return (rc < 0 ? err_serious(rc) : rc);
1997 static struct ldlm_callback_suite cbs = {
1998 .lcs_completion = ldlm_server_completion_ast,
1999 .lcs_blocking = ldlm_server_blocking_ast,
2003 static int mdt_enqueue(struct mdt_thread_info *info)
2005 struct ptlrpc_request *req;
2009 * info->mti_dlm_req already contains swapped and (if necessary)
2010 * converted dlm request.
2012 LASSERT(info->mti_dlm_req != NULL);
2014 req = mdt_info_req(info);
2015 rc = ldlm_handle_enqueue0(info->mti_mdt->mdt_namespace,
2016 req, info->mti_dlm_req, &cbs);
2017 info->mti_fail_id = OBD_FAIL_LDLM_REPLY;
2018 return rc ? err_serious(rc) : req->rq_status;
2021 static int mdt_convert(struct mdt_thread_info *info)
2024 struct ptlrpc_request *req;
2026 LASSERT(info->mti_dlm_req);
2027 req = mdt_info_req(info);
2028 rc = ldlm_handle_convert0(req, info->mti_dlm_req);
2029 return rc ? err_serious(rc) : req->rq_status;
2032 static int mdt_bl_callback(struct mdt_thread_info *info)
2034 CERROR("bl callbacks should not happen on MDS\n");
2036 return err_serious(-EOPNOTSUPP);
2039 static int mdt_cp_callback(struct mdt_thread_info *info)
2041 CERROR("cp callbacks should not happen on MDS\n");
2043 return err_serious(-EOPNOTSUPP);
2047 * sec context handlers
2049 static int mdt_sec_ctx_handle(struct mdt_thread_info *info)
2053 rc = mdt_handle_idmap(info);
2056 struct ptlrpc_request *req = mdt_info_req(info);
2059 opc = lustre_msg_get_opc(req->rq_reqmsg);
2060 if (opc == SEC_CTX_INIT || opc == SEC_CTX_INIT_CONT)
2061 sptlrpc_svc_ctx_invalidate(req);
2064 CFS_FAIL_TIMEOUT(OBD_FAIL_SEC_CTX_HDL_PAUSE, cfs_fail_val);
2069 static struct mdt_object *mdt_obj(struct lu_object *o)
2071 LASSERT(lu_device_is_mdt(o->lo_dev));
2072 return container_of0(o, struct mdt_object, mot_obj.mo_lu);
2075 struct mdt_object *mdt_object_find(const struct lu_env *env,
2076 struct mdt_device *d,
2077 const struct lu_fid *f,
2078 enum mdt_obj_exist check_exist)
2080 struct lu_object *o;
2081 struct mdt_object *m;
2084 CDEBUG(D_INFO, "Find object for "DFID"\n", PFID(f));
2085 o = lu_object_find(env, &d->mdt_md_dev.md_lu_dev, f, NULL);
2086 if (unlikely(IS_ERR(o)))
2087 RETURN((struct mdt_object *)o);
2091 if (check_exist == MDT_OBJ_MUST_EXIST && mdt_object_exists(m) == 0) {
2092 mdt_object_put(env, m);
2093 CERROR("%s: object "DFID" not found: rc = -2\n",
2094 mdt_obj_dev_name(m), PFID(f));
2095 RETURN(ERR_PTR(-ENOENT));
2101 * Asyncronous commit for mdt device.
2103 * Pass asynchonous commit call down the MDS stack.
2105 * \param env environment
2106 * \param mdt the mdt device
2108 static void mdt_device_commit_async(const struct lu_env *env,
2109 struct mdt_device *mdt)
2111 struct dt_device *dt = mdt->mdt_bottom;
2114 rc = dt->dd_ops->dt_commit_async(env, dt);
2115 if (unlikely(rc != 0))
2116 CWARN("async commit start failed with rc = %d", rc);
2120 * Mark the lock as "synchonous".
2122 * Mark the lock to deffer transaction commit to the unlock time.
2124 * \param lock the lock to mark as "synchonous"
2126 * \see mdt_is_lock_sync
2127 * \see mdt_save_lock
2129 static inline void mdt_set_lock_sync(struct ldlm_lock *lock)
2131 lock->l_ast_data = (void*)1;
2135 * Check whehter the lock "synchonous" or not.
2137 * \param lock the lock to check
2138 * \retval 1 the lock is "synchonous"
2139 * \retval 0 the lock isn't "synchronous"
2141 * \see mdt_set_lock_sync
2142 * \see mdt_save_lock
2144 static inline int mdt_is_lock_sync(struct ldlm_lock *lock)
2146 return lock->l_ast_data != NULL;
2150 * Blocking AST for mdt locks.
2152 * Starts transaction commit if in case of COS lock conflict or
2153 * deffers such a commit to the mdt_save_lock.
2155 * \param lock the lock which blocks a request or cancelling lock
2156 * \param desc unused
2157 * \param data unused
2158 * \param flag indicates whether this cancelling or blocking callback
2160 * \see ldlm_blocking_ast_nocheck
2162 int mdt_blocking_ast(struct ldlm_lock *lock, struct ldlm_lock_desc *desc,
2163 void *data, int flag)
2165 struct obd_device *obd = ldlm_lock_to_ns(lock)->ns_obd;
2166 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
2170 if (flag == LDLM_CB_CANCELING)
2172 lock_res_and_lock(lock);
2173 if (lock->l_blocking_ast != mdt_blocking_ast) {
2174 unlock_res_and_lock(lock);
2177 if (mdt_cos_is_enabled(mdt) &&
2178 lock->l_req_mode & (LCK_PW | LCK_EX) &&
2179 lock->l_blocking_lock != NULL &&
2180 lock->l_client_cookie != lock->l_blocking_lock->l_client_cookie) {
2181 mdt_set_lock_sync(lock);
2183 rc = ldlm_blocking_ast_nocheck(lock);
2185 /* There is no lock conflict if l_blocking_lock == NULL,
2186 * it indicates a blocking ast sent from ldlm_lock_decref_internal
2187 * when the last reference to a local lock was released */
2188 if (lock->l_req_mode == LCK_COS && lock->l_blocking_lock != NULL) {
2191 rc = lu_env_init(&env, LCT_MD_THREAD);
2192 if (unlikely(rc != 0))
2193 CWARN("lu_env initialization failed with rc = %d,"
2194 "cannot start asynchronous commit\n", rc);
2196 mdt_device_commit_async(&env, mdt);
2202 int mdt_object_lock(struct mdt_thread_info *info, struct mdt_object *o,
2203 struct mdt_lock_handle *lh, __u64 ibits, int locality)
2205 struct ldlm_namespace *ns = info->mti_mdt->mdt_namespace;
2206 ldlm_policy_data_t *policy = &info->mti_policy;
2207 struct ldlm_res_id *res_id = &info->mti_res_id;
2211 LASSERT(!lustre_handle_is_used(&lh->mlh_reg_lh));
2212 LASSERT(!lustre_handle_is_used(&lh->mlh_pdo_lh));
2213 LASSERT(lh->mlh_reg_mode != LCK_MINMODE);
2214 LASSERT(lh->mlh_type != MDT_NUL_LOCK);
2216 if (mdt_object_exists(o) < 0) {
2217 if (locality == MDT_CROSS_LOCK) {
2218 /* cross-ref object fix */
2219 ibits &= ~MDS_INODELOCK_UPDATE;
2220 ibits |= MDS_INODELOCK_LOOKUP;
2222 LASSERT(!(ibits & MDS_INODELOCK_UPDATE));
2223 LASSERT(ibits & MDS_INODELOCK_LOOKUP);
2225 /* No PDO lock on remote object */
2226 LASSERT(lh->mlh_type != MDT_PDO_LOCK);
2229 if (lh->mlh_type == MDT_PDO_LOCK) {
2230 /* check for exists after object is locked */
2231 if (mdt_object_exists(o) == 0) {
2232 /* Non-existent object shouldn't have PDO lock */
2235 /* Non-dir object shouldn't have PDO lock */
2236 if (!S_ISDIR(lu_object_attr(&o->mot_obj.mo_lu)))
2241 memset(policy, 0, sizeof(*policy));
2242 fid_build_reg_res_name(mdt_object_fid(o), res_id);
2245 * Take PDO lock on whole directory and build correct @res_id for lock
2246 * on part of directory.
2248 if (lh->mlh_pdo_hash != 0) {
2249 LASSERT(lh->mlh_type == MDT_PDO_LOCK);
2250 mdt_lock_pdo_mode(info, o, lh);
2251 if (lh->mlh_pdo_mode != LCK_NL) {
2253 * Do not use LDLM_FL_LOCAL_ONLY for parallel lock, it
2254 * is never going to be sent to client and we do not
2255 * want it slowed down due to possible cancels.
2257 policy->l_inodebits.bits = MDS_INODELOCK_UPDATE;
2258 rc = mdt_fid_lock(ns, &lh->mlh_pdo_lh, lh->mlh_pdo_mode,
2259 policy, res_id, LDLM_FL_ATOMIC_CB,
2260 &info->mti_exp->exp_handle.h_cookie);
2266 * Finish res_id initializing by name hash marking part of
2267 * directory which is taking modification.
2269 res_id->name[LUSTRE_RES_ID_HSH_OFF] = lh->mlh_pdo_hash;
2272 policy->l_inodebits.bits = ibits;
2275 * Use LDLM_FL_LOCAL_ONLY for this lock. We do not know yet if it is
2276 * going to be sent to client. If it is - mdt_intent_policy() path will
2277 * fix it up and turn FL_LOCAL flag off.
2279 rc = mdt_fid_lock(ns, &lh->mlh_reg_lh, lh->mlh_reg_mode, policy,
2280 res_id, LDLM_FL_LOCAL_ONLY | LDLM_FL_ATOMIC_CB,
2281 &info->mti_exp->exp_handle.h_cookie);
2283 mdt_object_unlock(info, o, lh, 1);
2284 else if (unlikely(OBD_FAIL_PRECHECK(OBD_FAIL_MDS_PDO_LOCK)) &&
2285 lh->mlh_pdo_hash != 0 &&
2286 (lh->mlh_reg_mode == LCK_PW || lh->mlh_reg_mode == LCK_EX)) {
2287 OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_PDO_LOCK, 15);
2294 * Save a lock within request object.
2296 * Keep the lock referenced until whether client ACK or transaction
2297 * commit happens or release the lock immediately depending on input
2298 * parameters. If COS is ON, a write lock is converted to COS lock
2301 * \param info thead info object
2302 * \param h lock handle
2303 * \param mode lock mode
2304 * \param decref force immediate lock releasing
2307 void mdt_save_lock(struct mdt_thread_info *info, struct lustre_handle *h,
2308 ldlm_mode_t mode, int decref)
2312 if (lustre_handle_is_used(h)) {
2313 if (decref || !info->mti_has_trans ||
2314 !(mode & (LCK_PW | LCK_EX))){
2315 mdt_fid_unlock(h, mode);
2317 struct mdt_device *mdt = info->mti_mdt;
2318 struct ldlm_lock *lock = ldlm_handle2lock(h);
2319 struct ptlrpc_request *req = mdt_info_req(info);
2322 LASSERTF(lock != NULL, "no lock for cookie "LPX64"\n",
2324 CDEBUG(D_HA, "request = %p reply state = %p"
2325 " transno = "LPD64"\n",
2326 req, req->rq_reply_state, req->rq_transno);
2327 if (mdt_cos_is_enabled(mdt)) {
2329 ldlm_lock_downgrade(lock, LCK_COS);
2332 ptlrpc_save_lock(req, h, mode, no_ack);
2333 if (mdt_is_lock_sync(lock)) {
2334 CDEBUG(D_HA, "found sync-lock,"
2335 " async commit started\n");
2336 mdt_device_commit_async(info->mti_env,
2339 LDLM_LOCK_PUT(lock);
2348 * Unlock mdt object.
2350 * Immeditely release the regular lock and the PDO lock or save the
2351 * lock in reqeuest and keep them referenced until client ACK or
2352 * transaction commit.
2354 * \param info thread info object
2355 * \param o mdt object
2356 * \param lh mdt lock handle referencing regular and PDO locks
2357 * \param decref force immediate lock releasing
2359 void mdt_object_unlock(struct mdt_thread_info *info, struct mdt_object *o,
2360 struct mdt_lock_handle *lh, int decref)
2364 mdt_save_lock(info, &lh->mlh_pdo_lh, lh->mlh_pdo_mode, decref);
2365 mdt_save_lock(info, &lh->mlh_reg_lh, lh->mlh_reg_mode, decref);
2370 struct mdt_object *mdt_object_find_lock(struct mdt_thread_info *info,
2371 const struct lu_fid *f,
2372 struct mdt_lock_handle *lh,
2374 enum mdt_obj_exist check_exist)
2376 struct mdt_object *o;
2378 o = mdt_object_find(info->mti_env, info->mti_mdt, f, check_exist);
2382 rc = mdt_object_lock(info, o, lh, ibits,
2385 mdt_object_put(info->mti_env, o);
2392 void mdt_object_unlock_put(struct mdt_thread_info * info,
2393 struct mdt_object * o,
2394 struct mdt_lock_handle *lh,
2397 mdt_object_unlock(info, o, lh, decref);
2398 mdt_object_put(info->mti_env, o);
2401 static struct mdt_handler *mdt_handler_find(__u32 opc,
2402 struct mdt_opc_slice *supported)
2404 struct mdt_opc_slice *s;
2405 struct mdt_handler *h;
2408 for (s = supported; s->mos_hs != NULL; s++) {
2409 if (s->mos_opc_start <= opc && opc < s->mos_opc_end) {
2410 h = s->mos_hs + (opc - s->mos_opc_start);
2411 if (likely(h->mh_opc != 0))
2412 LASSERTF(h->mh_opc == opc,
2413 "opcode mismatch %d != %d\n",
2416 h = NULL; /* unsupported opc */
2423 static int mdt_lock_resname_compat(struct mdt_device *m,
2424 struct ldlm_request *req)
2426 /* XXX something... later. */
2430 static int mdt_lock_reply_compat(struct mdt_device *m, struct ldlm_reply *rep)
2432 /* XXX something... later. */
2437 * Generic code handling requests that have struct mdt_body passed in:
2439 * - extract mdt_body from request and save it in @info, if present;
2441 * - create lu_object, corresponding to the fid in mdt_body, and save it in
2444 * - if HABEO_CORPUS flag is set for this request type check whether object
2445 * actually exists on storage (lu_object_exists()).
2448 static int mdt_body_unpack(struct mdt_thread_info *info, __u32 flags)
2450 const struct mdt_body *body;
2451 struct mdt_object *obj;
2452 const struct lu_env *env;
2453 struct req_capsule *pill;
2457 env = info->mti_env;
2458 pill = info->mti_pill;
2460 body = info->mti_body = req_capsule_client_get(pill, &RMF_MDT_BODY);
2464 if (!(body->valid & OBD_MD_FLID))
2467 if (!fid_is_sane(&body->fid1)) {
2468 CERROR("Invalid fid: "DFID"\n", PFID(&body->fid1));
2473 * Do not get size or any capa fields before we check that request
2474 * contains capa actually. There are some requests which do not, for
2475 * instance MDS_IS_SUBDIR.
2477 if (req_capsule_has_field(pill, &RMF_CAPA1, RCL_CLIENT) &&
2478 req_capsule_get_size(pill, &RMF_CAPA1, RCL_CLIENT))
2479 mdt_set_capainfo(info, 0, &body->fid1,
2480 req_capsule_client_get(pill, &RMF_CAPA1));
2482 obj = mdt_object_find(env, info->mti_mdt, &body->fid1,
2483 MDT_OBJ_MAY_NOT_EXIST);
2485 if ((flags & HABEO_CORPUS) &&
2486 mdt_object_exists(obj) == 0) {
2487 mdt_object_put(env, obj);
2488 /* for capability renew ENOENT will be handled in
2490 if (body->valid & OBD_MD_FLOSSCAPA)
2495 info->mti_object = obj;
2504 static int mdt_unpack_req_pack_rep(struct mdt_thread_info *info, __u32 flags)
2506 struct req_capsule *pill = info->mti_pill;
2510 if (req_capsule_has_field(pill, &RMF_MDT_BODY, RCL_CLIENT))
2511 rc = mdt_body_unpack(info, flags);
2515 if (rc == 0 && (flags & HABEO_REFERO)) {
2516 struct mdt_device *mdt = info->mti_mdt;
2520 if (req_capsule_has_field(pill, &RMF_MDT_MD, RCL_SERVER))
2521 req_capsule_set_size(pill, &RMF_MDT_MD, RCL_SERVER,
2522 mdt->mdt_max_mdsize);
2523 if (req_capsule_has_field(pill, &RMF_LOGCOOKIES, RCL_SERVER))
2524 req_capsule_set_size(pill, &RMF_LOGCOOKIES, RCL_SERVER,
2525 mdt->mdt_max_cookiesize);
2527 rc = req_capsule_server_pack(pill);
2532 static int mdt_init_capa_ctxt(const struct lu_env *env, struct mdt_device *m)
2534 struct md_device *next = m->mdt_child;
2536 return next->md_ops->mdo_init_capa_ctxt(env, next,
2537 m->mdt_opts.mo_mds_capa,
2538 m->mdt_capa_timeout,
2544 * Invoke handler for this request opc. Also do necessary preprocessing
2545 * (according to handler ->mh_flags), and post-processing (setting of
2546 * ->last_{xid,committed}).
2548 static int mdt_req_handle(struct mdt_thread_info *info,
2549 struct mdt_handler *h, struct ptlrpc_request *req)
2551 int rc, serious = 0;
2556 LASSERT(h->mh_act != NULL);
2557 LASSERT(h->mh_opc == lustre_msg_get_opc(req->rq_reqmsg));
2558 LASSERT(current->journal_info == NULL);
2561 * Checking for various OBD_FAIL_$PREF_$OPC_NET codes. _Do_ not try
2562 * to put same checks into handlers like mdt_close(), mdt_reint(),
2563 * etc., without talking to mdt authors first. Checking same thing
2564 * there again is useless and returning 0 error without packing reply
2565 * is buggy! Handlers either pack reply or return error.
2567 * We return 0 here and do not send any reply in order to emulate
2568 * network failure. Do not send any reply in case any of NET related
2569 * fail_id has occured.
2571 if (OBD_FAIL_CHECK_ORSET(h->mh_fail_id, OBD_FAIL_ONCE))
2575 flags = h->mh_flags;
2576 LASSERT(ergo(flags & (HABEO_CORPUS|HABEO_REFERO), h->mh_fmt != NULL));
2578 if (h->mh_fmt != NULL) {
2579 req_capsule_set(info->mti_pill, h->mh_fmt);
2580 rc = mdt_unpack_req_pack_rep(info, flags);
2583 if (rc == 0 && flags & MUTABOR &&
2584 req->rq_export->exp_connect_flags & OBD_CONNECT_RDONLY)
2585 /* should it be rq_status? */
2588 if (rc == 0 && flags & HABEO_CLAVIS) {
2589 struct ldlm_request *dlm_req;
2591 LASSERT(h->mh_fmt != NULL);
2593 dlm_req = req_capsule_client_get(info->mti_pill, &RMF_DLM_REQ);
2594 if (dlm_req != NULL) {
2595 if (unlikely(dlm_req->lock_desc.l_resource.lr_type ==
2597 dlm_req->lock_desc.l_policy_data.\
2598 l_inodebits.bits == 0)) {
2600 * Lock without inodebits makes no sense and
2601 * will oops later in ldlm. If client miss to
2602 * set such bits, do not trigger ASSERTION.
2604 * For liblustre flock case, it maybe zero.
2608 if (info->mti_mdt->mdt_opts.mo_compat_resname)
2609 rc = mdt_lock_resname_compat(
2612 info->mti_dlm_req = dlm_req;
2619 /* capability setting changed via /proc, needs reinitialize ctxt */
2620 if (info->mti_mdt && info->mti_mdt->mdt_capa_conf) {
2621 mdt_init_capa_ctxt(info->mti_env, info->mti_mdt);
2622 info->mti_mdt->mdt_capa_conf = 0;
2625 if (likely(rc == 0)) {
2627 * Process request, there can be two types of rc:
2628 * 1) errors with msg unpack/pack, other failures outside the
2629 * operation itself. This is counted as serious errors;
2630 * 2) errors during fs operation, should be placed in rq_status
2633 rc = h->mh_act(info);
2635 !req->rq_no_reply && req->rq_reply_state == NULL) {
2636 DEBUG_REQ(D_ERROR, req, "MDT \"handler\" %s did not "
2637 "pack reply and returned 0 error\n",
2641 serious = is_serious(rc);
2642 rc = clear_serious(rc);
2646 req->rq_status = rc;
2649 * ELDLM_* codes which > 0 should be in rq_status only as well as
2650 * all non-serious errors.
2652 if (rc > 0 || !serious)
2655 LASSERT(current->journal_info == NULL);
2657 if (rc == 0 && (flags & HABEO_CLAVIS) &&
2658 info->mti_mdt->mdt_opts.mo_compat_resname) {
2659 struct ldlm_reply *dlmrep;
2661 dlmrep = req_capsule_server_get(info->mti_pill, &RMF_DLM_REP);
2663 rc = mdt_lock_reply_compat(info->mti_mdt, dlmrep);
2666 /* If we're DISCONNECTing, the mdt_export_data is already freed */
2667 if (likely(rc == 0 && req->rq_export && h->mh_opc != MDS_DISCONNECT))
2668 target_committed_to_req(req);
2670 if (unlikely(req_is_replay(req) &&
2671 lustre_msg_get_transno(req->rq_reqmsg) == 0)) {
2672 DEBUG_REQ(D_ERROR, req, "transno is 0 during REPLAY");
2676 target_send_reply(req, rc, info->mti_fail_id);
2680 void mdt_lock_handle_init(struct mdt_lock_handle *lh)
2682 lh->mlh_type = MDT_NUL_LOCK;
2683 lh->mlh_reg_lh.cookie = 0ull;
2684 lh->mlh_reg_mode = LCK_MINMODE;
2685 lh->mlh_pdo_lh.cookie = 0ull;
2686 lh->mlh_pdo_mode = LCK_MINMODE;
2689 void mdt_lock_handle_fini(struct mdt_lock_handle *lh)
2691 LASSERT(!lustre_handle_is_used(&lh->mlh_reg_lh));
2692 LASSERT(!lustre_handle_is_used(&lh->mlh_pdo_lh));
2696 * Initialize fields of struct mdt_thread_info. Other fields are left in
2697 * uninitialized state, because it's too expensive to zero out whole
2698 * mdt_thread_info (> 1K) on each request arrival.
2700 static void mdt_thread_info_init(struct ptlrpc_request *req,
2701 struct mdt_thread_info *info)
2704 struct md_capainfo *ci;
2706 req_capsule_init(&req->rq_pill, req, RCL_SERVER);
2707 info->mti_pill = &req->rq_pill;
2710 for (i = 0; i < ARRAY_SIZE(info->mti_lh); i++)
2711 mdt_lock_handle_init(&info->mti_lh[i]);
2713 /* mdt device: it can be NULL while CONNECT */
2714 if (req->rq_export) {
2715 info->mti_mdt = mdt_dev(req->rq_export->exp_obd->obd_lu_dev);
2716 info->mti_exp = req->rq_export;
2718 info->mti_mdt = NULL;
2719 info->mti_env = req->rq_svc_thread->t_env;
2720 ci = md_capainfo(info->mti_env);
2721 memset(ci, 0, sizeof *ci);
2722 if (req->rq_export) {
2723 if (exp_connect_rmtclient(req->rq_export))
2724 ci->mc_auth = LC_ID_CONVERT;
2725 else if (req->rq_export->exp_connect_flags &
2726 OBD_CONNECT_MDS_CAPA)
2727 ci->mc_auth = LC_ID_PLAIN;
2729 ci->mc_auth = LC_ID_NONE;
2732 info->mti_fail_id = OBD_FAIL_MDS_ALL_REPLY_NET;
2733 info->mti_transno = lustre_msg_get_transno(req->rq_reqmsg);
2734 info->mti_mos = NULL;
2736 memset(&info->mti_attr, 0, sizeof(info->mti_attr));
2737 info->mti_body = NULL;
2738 info->mti_object = NULL;
2739 info->mti_dlm_req = NULL;
2740 info->mti_has_trans = 0;
2741 info->mti_no_need_trans = 0;
2742 info->mti_cross_ref = 0;
2743 info->mti_opdata = 0;
2745 /* To not check for split by default. */
2746 info->mti_spec.sp_ck_split = 0;
2747 info->mti_spec.no_create = 0;
2750 static void mdt_thread_info_fini(struct mdt_thread_info *info)
2754 req_capsule_fini(info->mti_pill);
2755 if (info->mti_object != NULL) {
2757 * freeing an object may lead to OSD level transaction, do not
2758 * let it mess with MDT. bz19385.
2760 info->mti_no_need_trans = 1;
2761 mdt_object_put(info->mti_env, info->mti_object);
2762 info->mti_object = NULL;
2764 for (i = 0; i < ARRAY_SIZE(info->mti_lh); i++)
2765 mdt_lock_handle_fini(&info->mti_lh[i]);
2766 info->mti_env = NULL;
2769 static int mdt_filter_recovery_request(struct ptlrpc_request *req,
2770 struct obd_device *obd, int *process)
2772 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
2773 case MDS_CONNECT: /* This will never get here, but for completeness. */
2774 case OST_CONNECT: /* This will never get here, but for completeness. */
2775 case MDS_DISCONNECT:
2776 case OST_DISCONNECT:
2781 case MDS_DONE_WRITING:
2782 case MDS_SYNC: /* used in unmounting */
2788 *process = target_queue_recovery_request(req, obd);
2792 DEBUG_REQ(D_ERROR, req, "not permitted during recovery");
2799 * Handle recovery. Return:
2800 * +1: continue request processing;
2801 * -ve: abort immediately with the given error code;
2802 * 0: send reply with error code in req->rq_status;
2804 static int mdt_recovery(struct mdt_thread_info *info)
2806 struct ptlrpc_request *req = mdt_info_req(info);
2807 struct obd_device *obd;
2811 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
2814 case SEC_CTX_INIT_CONT:
2820 rc = mdt_handle_idmap(info);
2829 if (unlikely(!class_connected_export(req->rq_export))) {
2830 CERROR("operation %d on unconnected MDS from %s\n",
2831 lustre_msg_get_opc(req->rq_reqmsg),
2832 libcfs_id2str(req->rq_peer));
2833 /* FIXME: For CMD cleanup, when mds_B stop, the req from
2834 * mds_A will get -ENOTCONN(especially for ping req),
2835 * which will cause that mds_A deactive timeout, then when
2836 * mds_A cleanup, the cleanup process will be suspended since
2837 * deactive timeout is not zero.
2839 req->rq_status = -ENOTCONN;
2840 target_send_reply(req, -ENOTCONN, info->mti_fail_id);
2844 /* sanity check: if the xid matches, the request must be marked as a
2845 * resent or replayed */
2846 if (req_xid_is_last(req)) {
2847 if (!(lustre_msg_get_flags(req->rq_reqmsg) &
2848 (MSG_RESENT | MSG_REPLAY))) {
2849 DEBUG_REQ(D_WARNING, req, "rq_xid "LPU64" matches last_xid, "
2850 "expected REPLAY or RESENT flag (%x)", req->rq_xid,
2851 lustre_msg_get_flags(req->rq_reqmsg));
2853 req->rq_status = -ENOTCONN;
2858 /* else: note the opposite is not always true; a RESENT req after a
2859 * failover will usually not match the last_xid, since it was likely
2860 * never committed. A REPLAYed request will almost never match the
2861 * last xid, however it could for a committed, but still retained,
2864 obd = req->rq_export->exp_obd;
2866 /* Check for aborted recovery... */
2867 if (unlikely(obd->obd_recovering)) {
2870 DEBUG_REQ(D_INFO, req, "Got new replay");
2871 rc = mdt_filter_recovery_request(req, obd, &should_process);
2872 if (rc != 0 || !should_process)
2874 else if (should_process < 0) {
2875 req->rq_status = should_process;
2876 rc = ptlrpc_error(req);
2883 static int mdt_msg_check_version(struct lustre_msg *msg)
2887 switch (lustre_msg_get_opc(msg)) {
2889 case MDS_DISCONNECT:
2892 case SEC_CTX_INIT_CONT:
2894 rc = lustre_msg_check_version(msg, LUSTRE_OBD_VERSION);
2896 CERROR("bad opc %u version %08x, expecting %08x\n",
2897 lustre_msg_get_opc(msg),
2898 lustre_msg_get_version(msg),
2899 LUSTRE_OBD_VERSION);
2903 case MDS_GETATTR_NAME:
2910 case MDS_DONE_WRITING:
2917 case MDS_QUOTACHECK:
2923 rc = lustre_msg_check_version(msg, LUSTRE_MDS_VERSION);
2925 CERROR("bad opc %u version %08x, expecting %08x\n",
2926 lustre_msg_get_opc(msg),
2927 lustre_msg_get_version(msg),
2928 LUSTRE_MDS_VERSION);
2932 case LDLM_BL_CALLBACK:
2933 case LDLM_CP_CALLBACK:
2934 rc = lustre_msg_check_version(msg, LUSTRE_DLM_VERSION);
2936 CERROR("bad opc %u version %08x, expecting %08x\n",
2937 lustre_msg_get_opc(msg),
2938 lustre_msg_get_version(msg),
2939 LUSTRE_DLM_VERSION);
2941 case OBD_LOG_CANCEL:
2942 case LLOG_ORIGIN_HANDLE_CREATE:
2943 case LLOG_ORIGIN_HANDLE_NEXT_BLOCK:
2944 case LLOG_ORIGIN_HANDLE_READ_HEADER:
2945 case LLOG_ORIGIN_HANDLE_CLOSE:
2946 case LLOG_ORIGIN_HANDLE_DESTROY:
2947 case LLOG_ORIGIN_HANDLE_PREV_BLOCK:
2949 rc = lustre_msg_check_version(msg, LUSTRE_LOG_VERSION);
2951 CERROR("bad opc %u version %08x, expecting %08x\n",
2952 lustre_msg_get_opc(msg),
2953 lustre_msg_get_version(msg),
2954 LUSTRE_LOG_VERSION);
2957 CERROR("MDS unknown opcode %d\n", lustre_msg_get_opc(msg));
2963 static int mdt_handle0(struct ptlrpc_request *req,
2964 struct mdt_thread_info *info,
2965 struct mdt_opc_slice *supported)
2967 struct mdt_handler *h;
2968 struct lustre_msg *msg;
2973 if (OBD_FAIL_CHECK_ORSET(OBD_FAIL_MDS_ALL_REQUEST_NET, OBD_FAIL_ONCE))
2976 LASSERT(current->journal_info == NULL);
2978 msg = req->rq_reqmsg;
2979 rc = mdt_msg_check_version(msg);
2980 if (likely(rc == 0)) {
2981 rc = mdt_recovery(info);
2982 if (likely(rc == +1)) {
2983 h = mdt_handler_find(lustre_msg_get_opc(msg),
2985 if (likely(h != NULL)) {
2986 rc = mdt_req_handle(info, h, req);
2988 CERROR("The unsupported opc: 0x%x\n",
2989 lustre_msg_get_opc(msg) );
2990 req->rq_status = -ENOTSUPP;
2991 rc = ptlrpc_error(req);
2996 CERROR(LUSTRE_MDT_NAME" drops mal-formed request\n");
3001 * MDT handler function called by ptlrpc service thread when request comes.
3003 * XXX common "target" functionality should be factored into separate module
3004 * shared by mdt, ost and stand-alone services like fld.
3006 static int mdt_handle_common(struct ptlrpc_request *req,
3007 struct mdt_opc_slice *supported)
3010 struct mdt_thread_info *info;
3014 env = req->rq_svc_thread->t_env;
3015 LASSERT(env != NULL);
3016 LASSERT(env->le_ses != NULL);
3017 LASSERT(env->le_ctx.lc_thread == req->rq_svc_thread);
3018 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
3019 LASSERT(info != NULL);
3021 mdt_thread_info_init(req, info);
3023 rc = mdt_handle0(req, info, supported);
3025 mdt_thread_info_fini(info);
3030 * This is called from recovery code as handler of _all_ RPC types, FLD and SEQ
3033 int mdt_recovery_handle(struct ptlrpc_request *req)
3038 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
3040 rc = mdt_handle_common(req, mdt_fld_handlers);
3043 rc = mdt_handle_common(req, mdt_seq_handlers);
3046 rc = mdt_handle_common(req, mdt_regular_handlers);
3053 static int mdt_regular_handle(struct ptlrpc_request *req)
3055 return mdt_handle_common(req, mdt_regular_handlers);
3058 static int mdt_readpage_handle(struct ptlrpc_request *req)
3060 return mdt_handle_common(req, mdt_readpage_handlers);
3063 static int mdt_xmds_handle(struct ptlrpc_request *req)
3065 return mdt_handle_common(req, mdt_xmds_handlers);
3068 static int mdt_mdsc_handle(struct ptlrpc_request *req)
3070 return mdt_handle_common(req, mdt_seq_handlers);
3073 static int mdt_mdss_handle(struct ptlrpc_request *req)
3075 return mdt_handle_common(req, mdt_seq_handlers);
3078 static int mdt_dtss_handle(struct ptlrpc_request *req)
3080 return mdt_handle_common(req, mdt_seq_handlers);
3083 static int mdt_fld_handle(struct ptlrpc_request *req)
3085 return mdt_handle_common(req, mdt_fld_handlers);
3102 static int mdt_intent_getattr(enum mdt_it_code opcode,
3103 struct mdt_thread_info *info,
3104 struct ldlm_lock **,
3106 static int mdt_intent_reint(enum mdt_it_code opcode,
3107 struct mdt_thread_info *info,
3108 struct ldlm_lock **,
3111 static struct mdt_it_flavor {
3112 const struct req_format *it_fmt;
3114 int (*it_act)(enum mdt_it_code ,
3115 struct mdt_thread_info *,
3116 struct ldlm_lock **,
3119 } mdt_it_flavor[] = {
3121 .it_fmt = &RQF_LDLM_INTENT,
3122 /*.it_flags = HABEO_REFERO,*/
3124 .it_act = mdt_intent_reint,
3125 .it_reint = REINT_OPEN
3128 .it_fmt = &RQF_LDLM_INTENT,
3129 .it_flags = MUTABOR,
3130 .it_act = mdt_intent_reint,
3131 .it_reint = REINT_OPEN
3134 .it_fmt = &RQF_LDLM_INTENT,
3135 .it_flags = MUTABOR,
3136 .it_act = mdt_intent_reint,
3137 .it_reint = REINT_CREATE
3139 [MDT_IT_GETATTR] = {
3140 .it_fmt = &RQF_LDLM_INTENT_GETATTR,
3141 .it_flags = HABEO_REFERO,
3142 .it_act = mdt_intent_getattr
3144 [MDT_IT_READDIR] = {
3150 .it_fmt = &RQF_LDLM_INTENT_GETATTR,
3151 .it_flags = HABEO_REFERO,
3152 .it_act = mdt_intent_getattr
3155 .it_fmt = &RQF_LDLM_INTENT_UNLINK,
3156 .it_flags = MUTABOR,
3158 .it_reint = REINT_UNLINK
3162 .it_flags = MUTABOR,
3165 [MDT_IT_GETXATTR] = {
3171 .it_fmt = &RQF_LDLM_INTENT_GETATTR,
3172 .it_flags = HABEO_REFERO,
3173 .it_act = mdt_intent_getattr
3177 int mdt_intent_lock_replace(struct mdt_thread_info *info,
3178 struct ldlm_lock **lockp,
3179 struct ldlm_lock *new_lock,
3180 struct mdt_lock_handle *lh,
3183 struct ptlrpc_request *req = mdt_info_req(info);
3184 struct ldlm_lock *lock = *lockp;
3187 * Get new lock only for cases when possible resent did not find any
3190 if (new_lock == NULL)
3191 new_lock = ldlm_handle2lock_long(&lh->mlh_reg_lh, 0);
3193 if (new_lock == NULL && (flags & LDLM_FL_INTENT_ONLY)) {
3194 lh->mlh_reg_lh.cookie = 0;
3198 LASSERTF(new_lock != NULL,
3199 "lockh "LPX64"\n", lh->mlh_reg_lh.cookie);
3202 * If we've already given this lock to a client once, then we should
3203 * have no readers or writers. Otherwise, we should have one reader
3204 * _or_ writer ref (which will be zeroed below) before returning the
3207 if (new_lock->l_export == req->rq_export) {
3208 LASSERT(new_lock->l_readers + new_lock->l_writers == 0);
3210 LASSERT(new_lock->l_export == NULL);
3211 LASSERT(new_lock->l_readers + new_lock->l_writers == 1);
3216 if (new_lock->l_export == req->rq_export) {
3218 * Already gave this to the client, which means that we
3219 * reconstructed a reply.
3221 LASSERT(lustre_msg_get_flags(req->rq_reqmsg) &
3223 lh->mlh_reg_lh.cookie = 0;
3224 RETURN(ELDLM_LOCK_REPLACED);
3228 * Fixup the lock to be given to the client.
3230 lock_res_and_lock(new_lock);
3231 /* Zero new_lock->l_readers and new_lock->l_writers without triggering
3232 * possible blocking AST. */
3233 while (new_lock->l_readers > 0) {
3234 lu_ref_del(&new_lock->l_reference, "reader", new_lock);
3235 lu_ref_del(&new_lock->l_reference, "user", new_lock);
3236 new_lock->l_readers--;
3238 while (new_lock->l_writers > 0) {
3239 lu_ref_del(&new_lock->l_reference, "writer", new_lock);
3240 lu_ref_del(&new_lock->l_reference, "user", new_lock);
3241 new_lock->l_writers--;
3244 new_lock->l_export = class_export_lock_get(req->rq_export, new_lock);
3245 new_lock->l_blocking_ast = lock->l_blocking_ast;
3246 new_lock->l_completion_ast = lock->l_completion_ast;
3247 new_lock->l_remote_handle = lock->l_remote_handle;
3248 new_lock->l_flags &= ~LDLM_FL_LOCAL;
3250 unlock_res_and_lock(new_lock);
3252 cfs_hash_add(new_lock->l_export->exp_lock_hash,
3253 &new_lock->l_remote_handle,
3254 &new_lock->l_exp_hash);
3256 LDLM_LOCK_RELEASE(new_lock);
3257 lh->mlh_reg_lh.cookie = 0;
3259 RETURN(ELDLM_LOCK_REPLACED);
3262 static void mdt_intent_fixup_resent(struct mdt_thread_info *info,
3263 struct ldlm_lock *new_lock,
3264 struct ldlm_lock **old_lock,
3265 struct mdt_lock_handle *lh)
3267 struct ptlrpc_request *req = mdt_info_req(info);
3268 struct obd_export *exp = req->rq_export;
3269 struct lustre_handle remote_hdl;
3270 struct ldlm_request *dlmreq;
3271 struct ldlm_lock *lock;
3273 if (!(lustre_msg_get_flags(req->rq_reqmsg) & MSG_RESENT))
3276 dlmreq = req_capsule_client_get(info->mti_pill, &RMF_DLM_REQ);
3277 remote_hdl = dlmreq->lock_handle[0];
3279 lock = cfs_hash_lookup(exp->exp_lock_hash, &remote_hdl);
3281 if (lock != new_lock) {
3282 lh->mlh_reg_lh.cookie = lock->l_handle.h_cookie;
3283 lh->mlh_reg_mode = lock->l_granted_mode;
3285 LDLM_DEBUG(lock, "Restoring lock cookie");
3286 DEBUG_REQ(D_DLMTRACE, req,
3287 "restoring lock cookie "LPX64,
3288 lh->mlh_reg_lh.cookie);
3290 *old_lock = LDLM_LOCK_GET(lock);
3291 cfs_hash_put(exp->exp_lock_hash, &lock->l_exp_hash);
3295 cfs_hash_put(exp->exp_lock_hash, &lock->l_exp_hash);
3299 * If the xid matches, then we know this is a resent request, and allow
3300 * it. (It's probably an OPEN, for which we don't send a lock.
3302 if (req_xid_is_last(req))
3306 * This remote handle isn't enqueued, so we never received or processed
3307 * this request. Clear MSG_RESENT, because it can be handled like any
3308 * normal request now.
3310 lustre_msg_clear_flags(req->rq_reqmsg, MSG_RESENT);
3312 DEBUG_REQ(D_DLMTRACE, req, "no existing lock with rhandle "LPX64,
3316 static int mdt_intent_getattr(enum mdt_it_code opcode,
3317 struct mdt_thread_info *info,
3318 struct ldlm_lock **lockp,
3321 struct mdt_lock_handle *lhc = &info->mti_lh[MDT_LH_RMT];
3322 struct ldlm_lock *new_lock = NULL;
3324 struct ldlm_reply *ldlm_rep;
3325 struct ptlrpc_request *req;
3326 struct mdt_body *reqbody;
3327 struct mdt_body *repbody;
3331 reqbody = req_capsule_client_get(info->mti_pill, &RMF_MDT_BODY);
3334 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
3337 info->mti_spec.sp_ck_split = !!(reqbody->valid & OBD_MD_FLCKSPLIT);
3338 info->mti_cross_ref = !!(reqbody->valid & OBD_MD_FLCROSSREF);
3339 repbody->eadatasize = 0;
3340 repbody->aclsize = 0;
3344 child_bits = MDS_INODELOCK_LOOKUP;
3346 case MDT_IT_GETATTR:
3347 child_bits = MDS_INODELOCK_LOOKUP | MDS_INODELOCK_UPDATE;
3349 case MDT_IT_LAYOUT: {
3350 static int printed = 0;
3353 CERROR("layout lock not supported by this version\n");
3356 GOTO(out_shrink, rc = -EINVAL);
3360 CERROR("Unsupported intent (%d)\n", opcode);
3361 GOTO(out_shrink, rc = -EINVAL);
3364 rc = mdt_init_ucred(info, reqbody);
3366 GOTO(out_shrink, rc);
3368 req = info->mti_pill->rc_req;
3369 ldlm_rep = req_capsule_server_get(info->mti_pill, &RMF_DLM_REP);
3370 mdt_set_disposition(info, ldlm_rep, DISP_IT_EXECD);
3372 /* Get lock from request for possible resent case. */
3373 mdt_intent_fixup_resent(info, *lockp, &new_lock, lhc);
3375 ldlm_rep->lock_policy_res2 =
3376 mdt_getattr_name_lock(info, lhc, child_bits, ldlm_rep);
3378 if (mdt_get_disposition(ldlm_rep, DISP_LOOKUP_NEG))
3379 ldlm_rep->lock_policy_res2 = 0;
3380 if (!mdt_get_disposition(ldlm_rep, DISP_LOOKUP_POS) ||
3381 ldlm_rep->lock_policy_res2) {
3382 lhc->mlh_reg_lh.cookie = 0ull;
3383 GOTO(out_ucred, rc = ELDLM_LOCK_ABORTED);
3386 rc = mdt_intent_lock_replace(info, lockp, new_lock, lhc, flags);
3389 mdt_exit_ucred(info);
3391 mdt_client_compatibility(info);
3392 mdt_shrink_reply(info);
3396 static int mdt_intent_reint(enum mdt_it_code opcode,
3397 struct mdt_thread_info *info,
3398 struct ldlm_lock **lockp,
3401 struct mdt_lock_handle *lhc = &info->mti_lh[MDT_LH_RMT];
3402 struct ldlm_reply *rep = NULL;
3406 static const struct req_format *intent_fmts[REINT_MAX] = {
3407 [REINT_CREATE] = &RQF_LDLM_INTENT_CREATE,
3408 [REINT_OPEN] = &RQF_LDLM_INTENT_OPEN
3413 opc = mdt_reint_opcode(info, intent_fmts);
3417 if (mdt_it_flavor[opcode].it_reint != opc) {
3418 CERROR("Reint code %ld doesn't match intent: %d\n",
3420 RETURN(err_serious(-EPROTO));
3423 /* Get lock from request for possible resent case. */
3424 mdt_intent_fixup_resent(info, *lockp, NULL, lhc);
3426 rc = mdt_reint_internal(info, lhc, opc);
3428 /* Check whether the reply has been packed successfully. */
3429 if (mdt_info_req(info)->rq_repmsg != NULL)
3430 rep = req_capsule_server_get(info->mti_pill, &RMF_DLM_REP);
3432 RETURN(err_serious(-EFAULT));
3434 /* MDC expects this in any case */
3436 mdt_set_disposition(info, rep, DISP_LOOKUP_EXECD);
3438 /* Cross-ref case, the lock should be returned to the client */
3439 if (rc == -EREMOTE) {
3440 LASSERT(lustre_handle_is_used(&lhc->mlh_reg_lh));
3441 rep->lock_policy_res2 = 0;
3442 rc = mdt_intent_lock_replace(info, lockp, NULL, lhc, flags);
3445 rep->lock_policy_res2 = clear_serious(rc);
3447 if (rep->lock_policy_res2 == -ENOENT &&
3448 mdt_get_disposition(rep, DISP_LOOKUP_NEG))
3449 rep->lock_policy_res2 = 0;
3451 if (rc == -ENOTCONN || rc == -ENODEV ||
3452 rc == -EOVERFLOW) { /**< if VBR failure then return error */
3454 * If it is the disconnect error (ENODEV & ENOCONN), the error
3455 * will be returned by rq_status, and client at ptlrpc layer
3456 * will detect this, then disconnect, reconnect the import
3457 * immediately, instead of impacting the following the rpc.
3459 lhc->mlh_reg_lh.cookie = 0ull;
3463 * For other cases, the error will be returned by intent.
3464 * and client will retrieve the result from intent.
3467 * FIXME: when open lock is finished, that should be
3470 if (lustre_handle_is_used(&lhc->mlh_reg_lh)) {
3471 LASSERTF(rc == 0, "Error occurred but lock handle "
3472 "is still in use\n");
3473 rep->lock_policy_res2 = 0;
3474 rc = mdt_intent_lock_replace(info, lockp, NULL, lhc, flags);
3477 lhc->mlh_reg_lh.cookie = 0ull;
3478 RETURN(ELDLM_LOCK_ABORTED);
3483 static int mdt_intent_code(long itcode)
3491 case IT_OPEN|IT_CREAT:
3498 rc = MDT_IT_READDIR;
3501 rc = MDT_IT_GETATTR;
3513 rc = MDT_IT_GETXATTR;
3519 CERROR("Unknown intent opcode: %ld\n", itcode);
3526 static int mdt_intent_opc(long itopc, struct mdt_thread_info *info,
3527 struct ldlm_lock **lockp, int flags)
3529 struct req_capsule *pill;
3530 struct mdt_it_flavor *flv;
3535 opc = mdt_intent_code(itopc);
3539 pill = info->mti_pill;
3540 flv = &mdt_it_flavor[opc];
3542 if (flv->it_fmt != NULL)
3543 req_capsule_extend(pill, flv->it_fmt);
3545 rc = mdt_unpack_req_pack_rep(info, flv->it_flags);
3547 struct ptlrpc_request *req = mdt_info_req(info);
3548 if (flv->it_flags & MUTABOR &&
3549 req->rq_export->exp_connect_flags & OBD_CONNECT_RDONLY)
3552 if (rc == 0 && flv->it_act != NULL) {
3553 /* execute policy */
3554 rc = flv->it_act(opc, info, lockp, flags);
3561 static int mdt_intent_policy(struct ldlm_namespace *ns,
3562 struct ldlm_lock **lockp, void *req_cookie,
3563 ldlm_mode_t mode, int flags, void *data)
3565 struct mdt_thread_info *info;
3566 struct ptlrpc_request *req = req_cookie;
3567 struct ldlm_intent *it;
3568 struct req_capsule *pill;
3573 LASSERT(req != NULL);
3575 info = lu_context_key_get(&req->rq_svc_thread->t_env->le_ctx,
3577 LASSERT(info != NULL);
3578 pill = info->mti_pill;
3579 LASSERT(pill->rc_req == req);
3581 if (req->rq_reqmsg->lm_bufcount > DLM_INTENT_IT_OFF) {
3582 req_capsule_extend(pill, &RQF_LDLM_INTENT);
3583 it = req_capsule_client_get(pill, &RMF_LDLM_INTENT);
3585 rc = mdt_intent_opc(it->opc, info, lockp, flags);
3589 /* Lock without inodebits makes no sense and will oops
3590 * later in ldlm. Let's check it now to see if we have
3591 * ibits corrupted somewhere in mdt_intent_opc().
3592 * The case for client miss to set ibits has been
3593 * processed by others. */
3594 LASSERT(ergo(info->mti_dlm_req->lock_desc.l_resource.\
3595 lr_type == LDLM_IBITS,
3596 info->mti_dlm_req->lock_desc.\
3597 l_policy_data.l_inodebits.bits != 0));
3599 rc = err_serious(-EFAULT);
3601 /* No intent was provided */
3602 LASSERT(pill->rc_fmt == &RQF_LDLM_ENQUEUE);
3603 rc = req_capsule_server_pack(pill);
3605 rc = err_serious(rc);
3610 static int mdt_seq_fini(const struct lu_env *env,
3611 struct mdt_device *m)
3613 struct md_site *ms = mdt_md_site(m);
3617 if (ms->ms_server_seq) {
3618 seq_server_fini(ms->ms_server_seq, env);
3619 OBD_FREE_PTR(ms->ms_server_seq);
3620 ms->ms_server_seq = NULL;
3623 if (ms->ms_control_seq) {
3624 seq_server_fini(ms->ms_control_seq, env);
3625 OBD_FREE_PTR(ms->ms_control_seq);
3626 ms->ms_control_seq = NULL;
3629 if (ms->ms_client_seq) {
3630 seq_client_fini(ms->ms_client_seq);
3631 OBD_FREE_PTR(ms->ms_client_seq);
3632 ms->ms_client_seq = NULL;
3639 static int mdt_seq_init(const struct lu_env *env,
3641 struct mdt_device *m)
3648 ms = mdt_md_site(m);
3651 * This is sequence-controller node. Init seq-controller server on local
3654 if (ms->ms_node_id == 0) {
3655 LASSERT(ms->ms_control_seq == NULL);
3657 OBD_ALLOC_PTR(ms->ms_control_seq);
3658 if (ms->ms_control_seq == NULL)
3661 rc = seq_server_init(ms->ms_control_seq,
3662 m->mdt_bottom, uuid,
3663 LUSTRE_SEQ_CONTROLLER,
3668 GOTO(out_seq_fini, rc);
3670 OBD_ALLOC_PTR(ms->ms_client_seq);
3671 if (ms->ms_client_seq == NULL)
3672 GOTO(out_seq_fini, rc = -ENOMEM);
3674 OBD_ALLOC(prefix, MAX_OBD_NAME + 5);
3675 if (prefix == NULL) {
3676 OBD_FREE_PTR(ms->ms_client_seq);
3677 GOTO(out_seq_fini, rc = -ENOMEM);
3680 snprintf(prefix, MAX_OBD_NAME + 5, "ctl-%s",
3684 * Init seq-controller client after seq-controller server is
3685 * ready. Pass ms->ms_control_seq to it for direct talking.
3687 rc = seq_client_init(ms->ms_client_seq, NULL,
3688 LUSTRE_SEQ_METADATA, prefix,
3689 ms->ms_control_seq);
3690 OBD_FREE(prefix, MAX_OBD_NAME + 5);
3693 GOTO(out_seq_fini, rc);
3696 /* Init seq-server on local MDT */
3697 LASSERT(ms->ms_server_seq == NULL);
3699 OBD_ALLOC_PTR(ms->ms_server_seq);
3700 if (ms->ms_server_seq == NULL)
3701 GOTO(out_seq_fini, rc = -ENOMEM);
3703 rc = seq_server_init(ms->ms_server_seq,
3704 m->mdt_bottom, uuid,
3709 GOTO(out_seq_fini, rc = -ENOMEM);
3711 /* Assign seq-controller client to local seq-server. */
3712 if (ms->ms_node_id == 0) {
3713 LASSERT(ms->ms_client_seq != NULL);
3715 rc = seq_server_set_cli(ms->ms_server_seq,
3723 mdt_seq_fini(env, m);
3728 * Init client sequence manager which is used by local MDS to talk to sequence
3729 * controller on remote node.
3731 static int mdt_seq_init_cli(const struct lu_env *env,
3732 struct mdt_device *m,
3733 struct lustre_cfg *cfg)
3735 struct md_site *ms = mdt_md_site(m);
3736 struct obd_device *mdc;
3737 struct obd_uuid *uuidp, *mdcuuidp;
3738 char *uuid_str, *mdc_uuid_str;
3741 struct mdt_thread_info *info;
3742 char *p, *index_string = lustre_cfg_string(cfg, 2);
3745 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
3746 uuidp = &info->mti_u.uuid[0];
3747 mdcuuidp = &info->mti_u.uuid[1];
3749 LASSERT(index_string);
3751 index = simple_strtol(index_string, &p, 10);
3753 CERROR("Invalid index in lustre_cgf, offset 2\n");
3757 /* check if this is adding the first MDC and controller is not yet
3759 if (index != 0 || ms->ms_client_seq)
3762 uuid_str = lustre_cfg_string(cfg, 1);
3763 mdc_uuid_str = lustre_cfg_string(cfg, 4);
3764 obd_str2uuid(uuidp, uuid_str);
3765 obd_str2uuid(mdcuuidp, mdc_uuid_str);
3767 mdc = class_find_client_obd(uuidp, LUSTRE_MDC_NAME, mdcuuidp);
3769 CERROR("can't find controller MDC by uuid %s\n",
3772 } else if (!mdc->obd_set_up) {
3773 CERROR("target %s not set up\n", mdc->obd_name);
3776 LASSERT(ms->ms_control_exp);
3777 OBD_ALLOC_PTR(ms->ms_client_seq);
3778 if (ms->ms_client_seq != NULL) {
3781 OBD_ALLOC(prefix, MAX_OBD_NAME + 5);
3785 snprintf(prefix, MAX_OBD_NAME + 5, "ctl-%s",
3788 rc = seq_client_init(ms->ms_client_seq,
3790 LUSTRE_SEQ_METADATA,
3792 OBD_FREE(prefix, MAX_OBD_NAME + 5);
3799 LASSERT(ms->ms_server_seq != NULL);
3800 rc = seq_server_set_cli(ms->ms_server_seq, ms->ms_client_seq,
3807 static void mdt_seq_fini_cli(struct mdt_device *m)
3813 ms = mdt_md_site(m);
3816 if (ms->ms_server_seq)
3817 seq_server_set_cli(ms->ms_server_seq,
3820 if (ms->ms_control_exp) {
3821 class_export_put(ms->ms_control_exp);
3822 ms->ms_control_exp = NULL;
3831 static int mdt_fld_fini(const struct lu_env *env,
3832 struct mdt_device *m)
3834 struct md_site *ms = mdt_md_site(m);
3837 if (ms && ms->ms_server_fld) {
3838 fld_server_fini(ms->ms_server_fld, env);
3839 OBD_FREE_PTR(ms->ms_server_fld);
3840 ms->ms_server_fld = NULL;
3846 static int mdt_fld_init(const struct lu_env *env,
3848 struct mdt_device *m)
3854 ms = mdt_md_site(m);
3856 OBD_ALLOC_PTR(ms->ms_server_fld);
3857 if (ms->ms_server_fld == NULL)
3858 RETURN(rc = -ENOMEM);
3860 rc = fld_server_init(ms->ms_server_fld,
3861 m->mdt_bottom, uuid,
3862 env, ms->ms_node_id);
3864 OBD_FREE_PTR(ms->ms_server_fld);
3865 ms->ms_server_fld = NULL;
3872 /* device init/fini methods */
3873 static void mdt_stop_ptlrpc_service(struct mdt_device *m)
3876 if (m->mdt_regular_service != NULL) {
3877 ptlrpc_unregister_service(m->mdt_regular_service);
3878 m->mdt_regular_service = NULL;
3880 if (m->mdt_readpage_service != NULL) {
3881 ptlrpc_unregister_service(m->mdt_readpage_service);
3882 m->mdt_readpage_service = NULL;
3884 if (m->mdt_xmds_service != NULL) {
3885 ptlrpc_unregister_service(m->mdt_xmds_service);
3886 m->mdt_xmds_service = NULL;
3888 if (m->mdt_setattr_service != NULL) {
3889 ptlrpc_unregister_service(m->mdt_setattr_service);
3890 m->mdt_setattr_service = NULL;
3892 if (m->mdt_mdsc_service != NULL) {
3893 ptlrpc_unregister_service(m->mdt_mdsc_service);
3894 m->mdt_mdsc_service = NULL;
3896 if (m->mdt_mdss_service != NULL) {
3897 ptlrpc_unregister_service(m->mdt_mdss_service);
3898 m->mdt_mdss_service = NULL;
3900 if (m->mdt_dtss_service != NULL) {
3901 ptlrpc_unregister_service(m->mdt_dtss_service);
3902 m->mdt_dtss_service = NULL;
3904 if (m->mdt_fld_service != NULL) {
3905 ptlrpc_unregister_service(m->mdt_fld_service);
3906 m->mdt_fld_service = NULL;
3911 static int mdt_start_ptlrpc_service(struct mdt_device *m)
3914 static struct ptlrpc_service_conf conf;
3915 cfs_proc_dir_entry_t *procfs_entry;
3918 procfs_entry = m->mdt_md_dev.md_lu_dev.ld_obd->obd_proc_entry;
3920 conf = (typeof(conf)) {
3921 .psc_nbufs = MDS_NBUFS,
3922 .psc_bufsize = MDS_BUFSIZE,
3923 .psc_max_req_size = MDS_MAXREQSIZE,
3924 .psc_max_reply_size = MDS_MAXREPSIZE,
3925 .psc_req_portal = MDS_REQUEST_PORTAL,
3926 .psc_rep_portal = MDC_REPLY_PORTAL,
3927 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
3929 * We'd like to have a mechanism to set this on a per-device
3930 * basis, but alas...
3932 .psc_min_threads = mdt_min_threads,
3933 .psc_max_threads = mdt_max_threads,
3934 .psc_ctx_tags = LCT_MD_THREAD
3937 m->mdt_ldlm_client = &m->mdt_md_dev.md_lu_dev.ld_obd->obd_ldlm_client;
3938 ptlrpc_init_client(LDLM_CB_REQUEST_PORTAL, LDLM_CB_REPLY_PORTAL,
3939 "mdt_ldlm_client", m->mdt_ldlm_client);
3941 m->mdt_regular_service =
3942 ptlrpc_init_svc_conf(&conf, mdt_regular_handle, LUSTRE_MDT_NAME,
3943 procfs_entry, target_print_req,
3945 if (m->mdt_regular_service == NULL)
3948 rc = ptlrpc_start_threads(m->mdt_regular_service);
3950 GOTO(err_mdt_svc, rc);
3953 * readpage service configuration. Parameters have to be adjusted,
3956 conf = (typeof(conf)) {
3957 .psc_nbufs = MDS_NBUFS,
3958 .psc_bufsize = MDS_BUFSIZE,
3959 .psc_max_req_size = MDS_MAXREQSIZE,
3960 .psc_max_reply_size = MDS_MAXREPSIZE,
3961 .psc_req_portal = MDS_READPAGE_PORTAL,
3962 .psc_rep_portal = MDC_REPLY_PORTAL,
3963 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
3964 .psc_min_threads = mdt_min_threads,
3965 .psc_max_threads = mdt_max_threads,
3966 .psc_ctx_tags = LCT_MD_THREAD
3968 m->mdt_readpage_service =
3969 ptlrpc_init_svc_conf(&conf, mdt_readpage_handle,
3970 LUSTRE_MDT_NAME "_readpage",
3971 procfs_entry, target_print_req,"mdt_rdpg");
3973 if (m->mdt_readpage_service == NULL) {
3974 CERROR("failed to start readpage service\n");
3975 GOTO(err_mdt_svc, rc = -ENOMEM);
3978 rc = ptlrpc_start_threads(m->mdt_readpage_service);
3981 * setattr service configuration.
3983 * XXX To keep the compatibility with old client(< 2.2), we need to
3984 * preserve this portal for a certain time, it should be removed
3985 * eventually. LU-617.
3987 conf = (typeof(conf)) {
3988 .psc_nbufs = MDS_NBUFS,
3989 .psc_bufsize = MDS_BUFSIZE,
3990 .psc_max_req_size = MDS_MAXREQSIZE,
3991 .psc_max_reply_size = MDS_MAXREPSIZE,
3992 .psc_req_portal = MDS_SETATTR_PORTAL,
3993 .psc_rep_portal = MDC_REPLY_PORTAL,
3994 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
3995 .psc_min_threads = mdt_min_threads,
3996 .psc_max_threads = mdt_max_threads,
3997 .psc_ctx_tags = LCT_MD_THREAD
4000 m->mdt_setattr_service =
4001 ptlrpc_init_svc_conf(&conf, mdt_regular_handle,
4002 LUSTRE_MDT_NAME "_setattr",
4003 procfs_entry, target_print_req,"mdt_attr");
4005 if (!m->mdt_setattr_service) {
4006 CERROR("failed to start setattr service\n");
4007 GOTO(err_mdt_svc, rc = -ENOMEM);
4010 rc = ptlrpc_start_threads(m->mdt_setattr_service);
4012 GOTO(err_mdt_svc, rc);
4015 * sequence controller service configuration
4017 conf = (typeof(conf)) {
4018 .psc_nbufs = MDS_NBUFS,
4019 .psc_bufsize = MDS_BUFSIZE,
4020 .psc_max_req_size = SEQ_MAXREQSIZE,
4021 .psc_max_reply_size = SEQ_MAXREPSIZE,
4022 .psc_req_portal = SEQ_CONTROLLER_PORTAL,
4023 .psc_rep_portal = MDC_REPLY_PORTAL,
4024 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
4025 .psc_min_threads = mdt_min_threads,
4026 .psc_max_threads = mdt_max_threads,
4027 .psc_ctx_tags = LCT_MD_THREAD|LCT_DT_THREAD
4030 m->mdt_mdsc_service =
4031 ptlrpc_init_svc_conf(&conf, mdt_mdsc_handle,
4032 LUSTRE_MDT_NAME"_mdsc",
4033 procfs_entry, target_print_req,"mdt_mdsc");
4034 if (!m->mdt_mdsc_service) {
4035 CERROR("failed to start seq controller service\n");
4036 GOTO(err_mdt_svc, rc = -ENOMEM);
4039 rc = ptlrpc_start_threads(m->mdt_mdsc_service);
4041 GOTO(err_mdt_svc, rc);
4044 * metadata sequence server service configuration
4046 conf = (typeof(conf)) {
4047 .psc_nbufs = MDS_NBUFS,
4048 .psc_bufsize = MDS_BUFSIZE,
4049 .psc_max_req_size = SEQ_MAXREQSIZE,
4050 .psc_max_reply_size = SEQ_MAXREPSIZE,
4051 .psc_req_portal = SEQ_METADATA_PORTAL,
4052 .psc_rep_portal = MDC_REPLY_PORTAL,
4053 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
4054 .psc_min_threads = mdt_min_threads,
4055 .psc_max_threads = mdt_max_threads,
4056 .psc_ctx_tags = LCT_MD_THREAD|LCT_DT_THREAD
4059 m->mdt_mdss_service =
4060 ptlrpc_init_svc_conf(&conf, mdt_mdss_handle,
4061 LUSTRE_MDT_NAME"_mdss",
4062 procfs_entry, target_print_req,"mdt_mdss");
4063 if (!m->mdt_mdss_service) {
4064 CERROR("failed to start metadata seq server service\n");
4065 GOTO(err_mdt_svc, rc = -ENOMEM);
4068 rc = ptlrpc_start_threads(m->mdt_mdss_service);
4070 GOTO(err_mdt_svc, rc);
4074 * Data sequence server service configuration. We want to have really
4075 * cluster-wide sequences space. This is why we start only one sequence
4076 * controller which manages space.
4078 conf = (typeof(conf)) {
4079 .psc_nbufs = MDS_NBUFS,
4080 .psc_bufsize = MDS_BUFSIZE,
4081 .psc_max_req_size = SEQ_MAXREQSIZE,
4082 .psc_max_reply_size = SEQ_MAXREPSIZE,
4083 .psc_req_portal = SEQ_DATA_PORTAL,
4084 .psc_rep_portal = OSC_REPLY_PORTAL,
4085 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
4086 .psc_min_threads = mdt_min_threads,
4087 .psc_max_threads = mdt_max_threads,
4088 .psc_ctx_tags = LCT_MD_THREAD|LCT_DT_THREAD
4091 m->mdt_dtss_service =
4092 ptlrpc_init_svc_conf(&conf, mdt_dtss_handle,
4093 LUSTRE_MDT_NAME"_dtss",
4094 procfs_entry, target_print_req,"mdt_dtss");
4095 if (!m->mdt_dtss_service) {
4096 CERROR("failed to start data seq server service\n");
4097 GOTO(err_mdt_svc, rc = -ENOMEM);
4100 rc = ptlrpc_start_threads(m->mdt_dtss_service);
4102 GOTO(err_mdt_svc, rc);
4104 /* FLD service start */
4105 conf = (typeof(conf)) {
4106 .psc_nbufs = MDS_NBUFS,
4107 .psc_bufsize = MDS_BUFSIZE,
4108 .psc_max_req_size = FLD_MAXREQSIZE,
4109 .psc_max_reply_size = FLD_MAXREPSIZE,
4110 .psc_req_portal = FLD_REQUEST_PORTAL,
4111 .psc_rep_portal = MDC_REPLY_PORTAL,
4112 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
4113 .psc_min_threads = mdt_min_threads,
4114 .psc_max_threads = mdt_max_threads,
4115 .psc_ctx_tags = LCT_DT_THREAD|LCT_MD_THREAD
4118 m->mdt_fld_service =
4119 ptlrpc_init_svc_conf(&conf, mdt_fld_handle,
4120 LUSTRE_MDT_NAME"_fld",
4121 procfs_entry, target_print_req, "mdt_fld");
4122 if (!m->mdt_fld_service) {
4123 CERROR("failed to start fld service\n");
4124 GOTO(err_mdt_svc, rc = -ENOMEM);
4127 rc = ptlrpc_start_threads(m->mdt_fld_service);
4129 GOTO(err_mdt_svc, rc);
4132 * mds-mds service configuration. Separate portal is used to allow
4133 * mds-mds requests be not blocked during recovery.
4135 conf = (typeof(conf)) {
4136 .psc_nbufs = MDS_NBUFS,
4137 .psc_bufsize = MDS_BUFSIZE,
4138 .psc_max_req_size = MDS_MAXREQSIZE,
4139 .psc_max_reply_size = MDS_MAXREPSIZE,
4140 .psc_req_portal = MDS_MDS_PORTAL,
4141 .psc_rep_portal = MDC_REPLY_PORTAL,
4142 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
4143 .psc_min_threads = mdt_min_threads,
4144 .psc_max_threads = mdt_max_threads,
4145 .psc_ctx_tags = LCT_MD_THREAD
4147 m->mdt_xmds_service =
4148 ptlrpc_init_svc_conf(&conf, mdt_xmds_handle,
4149 LUSTRE_MDT_NAME "_mds",
4150 procfs_entry, target_print_req,"mdt_xmds");
4152 if (m->mdt_xmds_service == NULL) {
4153 CERROR("failed to start xmds service\n");
4154 GOTO(err_mdt_svc, rc = -ENOMEM);
4157 rc = ptlrpc_start_threads(m->mdt_xmds_service);
4159 GOTO(err_mdt_svc, rc);
4164 mdt_stop_ptlrpc_service(m);
4169 static void mdt_stack_fini(const struct lu_env *env,
4170 struct mdt_device *m, struct lu_device *top)
4172 struct obd_device *obd = mdt2obd_dev(m);
4173 struct lustre_cfg_bufs *bufs;
4174 struct lustre_cfg *lcfg;
4175 struct mdt_thread_info *info;
4179 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
4180 LASSERT(info != NULL);
4182 bufs = &info->mti_u.bufs;
4183 /* process cleanup, pass mdt obd name to get obd umount flags */
4184 lustre_cfg_bufs_reset(bufs, obd->obd_name);
4189 lustre_cfg_bufs_set_string(bufs, 1, flags);
4190 lcfg = lustre_cfg_new(LCFG_CLEANUP, bufs);
4192 CERROR("Cannot alloc lcfg!\n");
4197 top->ld_ops->ldo_process_config(env, top, lcfg);
4198 lustre_cfg_free(lcfg);
4200 lu_stack_fini(env, top);
4201 m->mdt_child = NULL;
4202 m->mdt_bottom = NULL;
4205 static struct lu_device *mdt_layer_setup(struct lu_env *env,
4206 const char *typename,
4207 struct lu_device *child,
4208 struct lustre_cfg *cfg)
4210 const char *dev = lustre_cfg_string(cfg, 0);
4211 struct obd_type *type;
4212 struct lu_device_type *ldt;
4213 struct lu_device *d;
4218 type = class_get_type(typename);
4220 CERROR("Unknown type: '%s'\n", typename);
4221 GOTO(out, rc = -ENODEV);
4224 rc = lu_env_refill((struct lu_env *)env);
4226 CERROR("Failure to refill session: '%d'\n", rc);
4232 CERROR("type: '%s'\n", typename);
4233 GOTO(out_type, rc = -EINVAL);
4236 ldt->ldt_obd_type = type;
4237 d = ldt->ldt_ops->ldto_device_alloc(env, ldt, cfg);
4239 CERROR("Cannot allocate device: '%s'\n", typename);
4240 GOTO(out_type, rc = -ENODEV);
4243 LASSERT(child->ld_site);
4244 d->ld_site = child->ld_site;
4247 rc = ldt->ldt_ops->ldto_device_init(env, d, dev, child);
4249 CERROR("can't init device '%s', rc %d\n", typename, rc);
4250 GOTO(out_alloc, rc);
4253 lu_ref_add(&d->ld_reference, "lu-stack", &lu_site_init);
4255 cfs_spin_lock(&d->ld_site->ls_ld_lock);
4256 cfs_list_add_tail(&d->ld_linkage, &d->ld_site->ls_ld_linkage);
4257 cfs_spin_unlock(&d->ld_site->ls_ld_lock);
4261 ldt->ldt_ops->ldto_device_free(env, d);
4264 class_put_type(type);
4269 static int mdt_stack_init(struct lu_env *env,
4270 struct mdt_device *m,
4271 struct lustre_cfg *cfg,
4272 struct lustre_mount_info *lmi)
4274 struct lu_device *d = &m->mdt_md_dev.md_lu_dev;
4275 struct lu_device *tmp;
4276 struct md_device *md;
4277 struct lu_device *child_lu_dev;
4281 /* init the stack */
4282 tmp = mdt_layer_setup(env, LUSTRE_OSD_NAME, d, cfg);
4284 RETURN(PTR_ERR(tmp));
4286 m->mdt_bottom = lu2dt_dev(tmp);
4288 tmp = mdt_layer_setup(env, LUSTRE_MDD_NAME, d, cfg);
4290 GOTO(out, rc = PTR_ERR(tmp));
4295 tmp = mdt_layer_setup(env, LUSTRE_CMM_NAME, d, cfg);
4297 GOTO(out, rc = PTR_ERR(tmp));
4300 /*set mdd upcall device*/
4301 md_upcall_dev_set(md, lu2md_dev(d));
4304 /*set cmm upcall device*/
4305 md_upcall_dev_set(md, &m->mdt_md_dev);
4307 m->mdt_child = lu2md_dev(d);
4309 /* process setup config */
4310 tmp = &m->mdt_md_dev.md_lu_dev;
4311 rc = tmp->ld_ops->ldo_process_config(env, tmp, cfg);
4315 /* initialize local objects */
4316 child_lu_dev = &m->mdt_child->md_lu_dev;
4318 rc = child_lu_dev->ld_ops->ldo_prepare(env,
4319 &m->mdt_md_dev.md_lu_dev,
4322 /* fini from last known good lu_device */
4324 mdt_stack_fini(env, m, d);
4330 * setup CONFIG_ORIG context, used to access local config log.
4331 * this may need to be rewrite as part of llog rewrite for lu-api.
4333 static int mdt_obd_llog_setup(struct obd_device *obd,
4334 struct lustre_sb_info *lsi)
4338 LASSERT(obd->obd_fsops == NULL);
4340 obd->obd_fsops = fsfilt_get_ops(MT_STR(lsi->lsi_ldd));
4341 if (IS_ERR(obd->obd_fsops))
4342 return PTR_ERR(obd->obd_fsops);
4344 rc = fsfilt_setup(obd, lsi->lsi_srv_mnt->mnt_sb);
4346 fsfilt_put_ops(obd->obd_fsops);
4350 OBD_SET_CTXT_MAGIC(&obd->obd_lvfs_ctxt);
4351 obd->obd_lvfs_ctxt.pwdmnt = lsi->lsi_srv_mnt;
4352 obd->obd_lvfs_ctxt.pwd = lsi->lsi_srv_mnt->mnt_root;
4353 obd->obd_lvfs_ctxt.fs = get_ds();
4355 rc = llog_setup(obd, &obd->obd_olg, LLOG_CONFIG_ORIG_CTXT, obd,
4356 0, NULL, &llog_lvfs_ops);
4358 CERROR("llog_setup() failed: %d\n", rc);
4359 fsfilt_put_ops(obd->obd_fsops);
4365 static void mdt_obd_llog_cleanup(struct obd_device *obd)
4367 struct llog_ctxt *ctxt;
4369 ctxt = llog_get_context(obd, LLOG_CONFIG_ORIG_CTXT);
4373 if (obd->obd_fsops) {
4374 fsfilt_put_ops(obd->obd_fsops);
4375 obd->obd_fsops = NULL;
4379 static void mdt_fini(const struct lu_env *env, struct mdt_device *m)
4381 struct md_device *next = m->mdt_child;
4382 struct lu_device *d = &m->mdt_md_dev.md_lu_dev;
4383 struct lu_site *ls = d->ld_site;
4384 struct obd_device *obd = mdt2obd_dev(m);
4387 target_recovery_fini(obd);
4389 ping_evictor_stop();
4391 mdt_stop_ptlrpc_service(m);
4392 mdt_llog_ctxt_unclone(env, m, LLOG_CHANGELOG_ORIG_CTXT);
4393 mdt_obd_llog_cleanup(obd);
4394 obd_exports_barrier(obd);
4395 obd_zombie_barrier();
4399 #ifdef HAVE_QUOTA_SUPPORT
4400 next->md_ops->mdo_quota.mqo_cleanup(env, next);
4402 lut_fini(env, &m->mdt_lut);
4403 mdt_fs_cleanup(env, m);
4404 upcall_cache_cleanup(m->mdt_identity_cache);
4405 m->mdt_identity_cache = NULL;
4407 if (m->mdt_namespace != NULL) {
4408 ldlm_namespace_free(m->mdt_namespace, NULL,
4409 d->ld_obd->obd_force);
4410 d->ld_obd->obd_namespace = m->mdt_namespace = NULL;
4413 cfs_free_nidlist(&m->mdt_nosquash_nids);
4414 if (m->mdt_nosquash_str) {
4415 OBD_FREE(m->mdt_nosquash_str, m->mdt_nosquash_strlen);
4416 m->mdt_nosquash_str = NULL;
4417 m->mdt_nosquash_strlen = 0;
4420 mdt_seq_fini(env, m);
4421 mdt_seq_fini_cli(m);
4422 mdt_fld_fini(env, m);
4423 sptlrpc_rule_set_free(&m->mdt_sptlrpc_rset);
4425 next->md_ops->mdo_init_capa_ctxt(env, next, 0, 0, 0, NULL);
4426 cfs_timer_disarm(&m->mdt_ck_timer);
4427 mdt_ck_thread_stop(m);
4432 mdt_stack_fini(env, m, md2lu_dev(m->mdt_child));
4435 struct md_site *mite;
4438 mite = lu_site2md(ls);
4442 LASSERT(cfs_atomic_read(&d->ld_ref) == 0);
4447 static int mdt_adapt_sptlrpc_conf(struct obd_device *obd, int initial)
4449 struct mdt_device *m = mdt_dev(obd->obd_lu_dev);
4450 struct sptlrpc_rule_set tmp_rset;
4453 sptlrpc_rule_set_init(&tmp_rset);
4454 rc = sptlrpc_conf_target_get_rules(obd, &tmp_rset, initial);
4456 CERROR("mdt %s: failed get sptlrpc rules: %d\n",
4461 sptlrpc_target_update_exp_flavor(obd, &tmp_rset);
4463 cfs_write_lock(&m->mdt_sptlrpc_lock);
4464 sptlrpc_rule_set_free(&m->mdt_sptlrpc_rset);
4465 m->mdt_sptlrpc_rset = tmp_rset;
4466 cfs_write_unlock(&m->mdt_sptlrpc_lock);
4471 int mdt_postrecov(const struct lu_env *, struct mdt_device *);
4473 static int mdt_init0(const struct lu_env *env, struct mdt_device *m,
4474 struct lu_device_type *ldt, struct lustre_cfg *cfg)
4476 struct mdt_thread_info *info;
4477 struct obd_device *obd;
4478 const char *dev = lustre_cfg_string(cfg, 0);
4479 const char *num = lustre_cfg_string(cfg, 2);
4480 struct lustre_mount_info *lmi = NULL;
4481 struct lustre_sb_info *lsi;
4482 struct lustre_disk_data *ldd;
4484 struct md_site *mite;
4485 const char *identity_upcall = "NONE";
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_cos = MDT_COS_DEFAULT;
4516 lmi = server_get_mount_2(dev);
4518 CERROR("Cannot get mount info for %s!\n", dev);
4521 lsi = s2lsi(lmi->lmi_sb);
4522 /* CMD is supported only in IAM mode */
4525 node_id = simple_strtol(num, NULL, 10);
4526 if (!(ldd->ldd_flags & LDD_F_IAM_DIR) && node_id) {
4527 CERROR("CMD Operation not allowed in IOP mode\n");
4528 GOTO(err_lmi, rc = -EINVAL);
4531 obd->u.obt.obt_magic = OBT_MAGIC;
4534 cfs_rwlock_init(&m->mdt_sptlrpc_lock);
4535 sptlrpc_rule_set_init(&m->mdt_sptlrpc_rset);
4537 cfs_spin_lock_init(&m->mdt_ioepoch_lock);
4538 m->mdt_opts.mo_compat_resname = 0;
4539 m->mdt_opts.mo_mds_capa = 1;
4540 m->mdt_opts.mo_oss_capa = 1;
4541 m->mdt_capa_timeout = CAPA_TIMEOUT;
4542 m->mdt_capa_alg = CAPA_HMAC_ALG_SHA1;
4543 m->mdt_ck_timeout = CAPA_KEY_TIMEOUT;
4544 m->mdt_squash_uid = 0;
4545 m->mdt_squash_gid = 0;
4546 CFS_INIT_LIST_HEAD(&m->mdt_nosquash_nids);
4547 m->mdt_nosquash_str = NULL;
4548 m->mdt_nosquash_strlen = 0;
4549 cfs_init_rwsem(&m->mdt_squash_sem);
4551 OBD_ALLOC_PTR(mite);
4553 GOTO(err_lmi, rc = -ENOMEM);
4557 m->mdt_md_dev.md_lu_dev.ld_ops = &mdt_lu_ops;
4558 m->mdt_md_dev.md_lu_dev.ld_obd = obd;
4559 /* set this lu_device to obd, because error handling need it */
4560 obd->obd_lu_dev = &m->mdt_md_dev.md_lu_dev;
4562 rc = lu_site_init(s, &m->mdt_md_dev.md_lu_dev);
4564 CERROR("Can't init lu_site, rc %d\n", rc);
4565 GOTO(err_free_site, rc);
4568 /* set server index */
4569 lu_site2md(s)->ms_node_id = node_id;
4571 /* failover is the default
4572 * FIXME: we do not failout mds0/mgs, which may cause some problems.
4573 * assumed whose ms_node_id == 0 XXX
4575 obd->obd_replayable = 1;
4576 /* No connection accepted until configurations will finish */
4577 obd->obd_no_conn = 1;
4579 if (cfg->lcfg_bufcount > 4 && LUSTRE_CFG_BUFLEN(cfg, 4) > 0) {
4580 char *str = lustre_cfg_string(cfg, 4);
4581 if (strchr(str, 'n')) {
4582 CWARN("%s: recovery disabled\n", obd->obd_name);
4583 obd->obd_replayable = 0;
4587 /* init the stack */
4588 rc = mdt_stack_init((struct lu_env *)env, m, cfg, lmi);
4590 CERROR("Can't init device stack, rc %d\n", rc);
4591 GOTO(err_lu_site, rc);
4594 rc = lut_init(env, &m->mdt_lut, obd, m->mdt_bottom);
4596 GOTO(err_fini_stack, rc);
4598 rc = mdt_fld_init(env, obd->obd_name, m);
4602 rc = mdt_seq_init(env, obd->obd_name, m);
4604 GOTO(err_fini_fld, rc);
4606 snprintf(info->mti_u.ns_name, sizeof info->mti_u.ns_name,
4607 LUSTRE_MDT_NAME"-%p", m);
4608 m->mdt_namespace = ldlm_namespace_new(obd, info->mti_u.ns_name,
4609 LDLM_NAMESPACE_SERVER,
4610 LDLM_NAMESPACE_GREEDY,
4612 if (m->mdt_namespace == NULL)
4613 GOTO(err_fini_seq, rc = -ENOMEM);
4615 ldlm_register_intent(m->mdt_namespace, mdt_intent_policy);
4616 /* set obd_namespace for compatibility with old code */
4617 obd->obd_namespace = m->mdt_namespace;
4619 cfs_timer_init(&m->mdt_ck_timer, mdt_ck_timer_callback, m);
4621 rc = mdt_ck_thread_start(m);
4623 GOTO(err_free_ns, rc);
4625 rc = mdt_fs_setup(env, m, obd, lsi);
4629 rc = mdt_obd_llog_setup(obd, lsi);
4631 GOTO(err_fs_cleanup, rc);
4633 rc = mdt_llog_ctxt_clone(env, m, LLOG_CHANGELOG_ORIG_CTXT);
4635 GOTO(err_llog_cleanup, rc);
4637 mdt_adapt_sptlrpc_conf(obd, 1);
4639 next = m->mdt_child;
4640 #ifdef HAVE_QUOTA_SUPPORT
4641 rc = next->md_ops->mdo_quota.mqo_setup(env, next, lmi->lmi_mnt);
4643 GOTO(err_llog_cleanup, rc);
4646 server_put_mount_2(dev, lmi->lmi_mnt);
4649 rc = next->md_ops->mdo_iocontrol(env, next, OBD_IOC_GET_MNTOPT, 0,
4652 GOTO(err_quota, rc);
4654 if (mntopts & MNTOPT_USERXATTR)
4655 m->mdt_opts.mo_user_xattr = 1;
4657 m->mdt_opts.mo_user_xattr = 0;
4659 if (mntopts & MNTOPT_ACL)
4660 m->mdt_opts.mo_acl = 1;
4662 m->mdt_opts.mo_acl = 0;
4664 /* XXX: to support suppgid for ACL, we enable identity_upcall
4665 * by default, otherwise, maybe got unexpected -EACCESS. */
4666 if (m->mdt_opts.mo_acl)
4667 identity_upcall = MDT_IDENTITY_UPCALL_PATH;
4669 m->mdt_identity_cache = upcall_cache_init(obd->obd_name,identity_upcall,
4670 &mdt_identity_upcall_cache_ops);
4671 if (IS_ERR(m->mdt_identity_cache)) {
4672 rc = PTR_ERR(m->mdt_identity_cache);
4673 m->mdt_identity_cache = NULL;
4674 GOTO(err_quota, rc);
4677 target_recovery_init(&m->mdt_lut, mdt_recovery_handle);
4679 rc = mdt_procfs_init(m, dev);
4681 CERROR("Can't init MDT lprocfs, rc %d\n", rc);
4682 GOTO(err_recovery, rc);
4685 rc = mdt_start_ptlrpc_service(m);
4687 GOTO(err_procfs, rc);
4689 ping_evictor_start();
4691 rc = lu_site_init_finish(s);
4693 GOTO(err_stop_service, rc);
4695 if (obd->obd_recovering == 0)
4696 mdt_postrecov(env, m);
4698 mdt_init_capa_ctxt(env, m);
4700 /* Reduce the initial timeout on an MDS because it doesn't need such
4701 * a long timeout as an OST does. Adaptive timeouts will adjust this
4702 * value appropriately. */
4703 if (ldlm_timeout == LDLM_TIMEOUT_DEFAULT)
4704 ldlm_timeout = MDS_LDLM_TIMEOUT_DEFAULT;
4709 ping_evictor_stop();
4710 mdt_stop_ptlrpc_service(m);
4714 target_recovery_fini(obd);
4715 upcall_cache_cleanup(m->mdt_identity_cache);
4716 m->mdt_identity_cache = NULL;
4718 #ifdef HAVE_QUOTA_SUPPORT
4719 next->md_ops->mdo_quota.mqo_cleanup(env, next);
4722 mdt_llog_ctxt_unclone(env, m, LLOG_CHANGELOG_ORIG_CTXT);
4723 mdt_obd_llog_cleanup(obd);
4725 mdt_fs_cleanup(env, m);
4727 cfs_timer_disarm(&m->mdt_ck_timer);
4728 mdt_ck_thread_stop(m);
4730 ldlm_namespace_free(m->mdt_namespace, NULL, 0);
4731 obd->obd_namespace = m->mdt_namespace = NULL;
4733 mdt_seq_fini(env, m);
4735 mdt_fld_fini(env, m);
4737 lut_fini(env, &m->mdt_lut);
4739 mdt_stack_fini(env, m, md2lu_dev(m->mdt_child));
4746 server_put_mount_2(dev, lmi->lmi_mnt);
4750 /* used by MGS to process specific configurations */
4751 static int mdt_process_config(const struct lu_env *env,
4752 struct lu_device *d, struct lustre_cfg *cfg)
4754 struct mdt_device *m = mdt_dev(d);
4755 struct md_device *md_next = m->mdt_child;
4756 struct lu_device *next = md2lu_dev(md_next);
4760 switch (cfg->lcfg_command) {
4762 struct lprocfs_static_vars lvars;
4763 struct obd_device *obd = d->ld_obd;
4766 * For interoperability between 1.8 and 2.0,
4769 /* Skip old "mdt.group_upcall" param. */
4770 char *param = lustre_cfg_string(cfg, 1);
4771 if (param && !strncmp("mdt.group_upcall", param, 16)) {
4772 CWARN("For 1.8 interoperability, skip this"
4773 " mdt.group_upcall. It is obsolete\n");
4776 /* Rename old "mdt.quota_type" to "mdd.quota_type. */
4777 if (param && !strncmp("mdt.quota_type", param, 14)) {
4778 CWARN("Found old param mdt.quota_type, changed"
4779 " it to mdd.quota_type.\n");
4784 lprocfs_mdt_init_vars(&lvars);
4785 rc = class_process_proc_param(PARAM_MDT, lvars.obd_vars,
4787 if (rc > 0 || rc == -ENOSYS)
4788 /* we don't understand; pass it on */
4789 rc = next->ld_ops->ldo_process_config(env, next, cfg);
4794 * Add mdc hook to get first MDT uuid and connect it to
4795 * ls->controller to use for seq manager.
4797 rc = next->ld_ops->ldo_process_config(env, next, cfg);
4799 CERROR("Can't add mdc, rc %d\n", rc);
4801 rc = mdt_seq_init_cli(env, mdt_dev(d), cfg);
4804 /* others are passed further */
4805 rc = next->ld_ops->ldo_process_config(env, next, cfg);
4811 static struct lu_object *mdt_object_alloc(const struct lu_env *env,
4812 const struct lu_object_header *hdr,
4813 struct lu_device *d)
4815 struct mdt_object *mo;
4821 struct lu_object *o;
4822 struct lu_object_header *h;
4824 o = &mo->mot_obj.mo_lu;
4825 h = &mo->mot_header;
4826 lu_object_header_init(h);
4827 lu_object_init(o, h, d);
4828 lu_object_add_top(h, o);
4829 o->lo_ops = &mdt_obj_ops;
4830 cfs_sema_init(&mo->mot_ioepoch_sem, 1);
4831 cfs_sema_init(&mo->mot_lov_sem, 1);
4837 static int mdt_object_init(const struct lu_env *env, struct lu_object *o,
4838 const struct lu_object_conf *unused)
4840 struct mdt_device *d = mdt_dev(o->lo_dev);
4841 struct lu_device *under;
4842 struct lu_object *below;
4846 CDEBUG(D_INFO, "object init, fid = "DFID"\n",
4847 PFID(lu_object_fid(o)));
4849 under = &d->mdt_child->md_lu_dev;
4850 below = under->ld_ops->ldo_object_alloc(env, o->lo_header, under);
4851 if (below != NULL) {
4852 lu_object_add(o, below);
4859 static void mdt_object_free(const struct lu_env *env, struct lu_object *o)
4861 struct mdt_object *mo = mdt_obj(o);
4862 struct lu_object_header *h;
4866 CDEBUG(D_INFO, "object free, fid = "DFID"\n",
4867 PFID(lu_object_fid(o)));
4870 lu_object_header_fini(h);
4875 static int mdt_object_print(const struct lu_env *env, void *cookie,
4876 lu_printer_t p, const struct lu_object *o)
4878 struct mdt_object *mdto = mdt_obj((struct lu_object *)o);
4879 return (*p)(env, cookie, LUSTRE_MDT_NAME"-object@%p(ioepoch="LPU64" "
4880 "flags="LPX64", epochcount=%d, writecount=%d)",
4881 mdto, mdto->mot_ioepoch, mdto->mot_flags,
4882 mdto->mot_ioepoch_count, mdto->mot_writecount);
4885 static const struct lu_device_operations mdt_lu_ops = {
4886 .ldo_object_alloc = mdt_object_alloc,
4887 .ldo_process_config = mdt_process_config,
4890 static const struct lu_object_operations mdt_obj_ops = {
4891 .loo_object_init = mdt_object_init,
4892 .loo_object_free = mdt_object_free,
4893 .loo_object_print = mdt_object_print
4896 static int mdt_obd_set_info_async(struct obd_export *exp,
4897 __u32 keylen, void *key,
4898 __u32 vallen, void *val,
4899 struct ptlrpc_request_set *set)
4901 struct obd_device *obd = exp->exp_obd;
4907 if (KEY_IS(KEY_SPTLRPC_CONF)) {
4908 rc = mdt_adapt_sptlrpc_conf(obd, 0);
4915 /* mds_connect_internal */
4916 static int mdt_connect_internal(struct obd_export *exp,
4917 struct mdt_device *mdt,
4918 struct obd_connect_data *data)
4921 data->ocd_connect_flags &= MDT_CONNECT_SUPPORTED;
4922 data->ocd_ibits_known &= MDS_INODELOCK_FULL;
4924 /* If no known bits (which should not happen, probably,
4925 as everybody should support LOOKUP and UPDATE bits at least)
4926 revert to compat mode with plain locks. */
4927 if (!data->ocd_ibits_known &&
4928 data->ocd_connect_flags & OBD_CONNECT_IBITS)
4929 data->ocd_connect_flags &= ~OBD_CONNECT_IBITS;
4931 if (!mdt->mdt_opts.mo_acl)
4932 data->ocd_connect_flags &= ~OBD_CONNECT_ACL;
4934 if (!mdt->mdt_opts.mo_user_xattr)
4935 data->ocd_connect_flags &= ~OBD_CONNECT_XATTR;
4937 if (!mdt->mdt_som_conf)
4938 data->ocd_connect_flags &= ~OBD_CONNECT_SOM;
4940 if (data->ocd_connect_flags & OBD_CONNECT_BRW_SIZE) {
4941 data->ocd_brw_size = min(data->ocd_brw_size,
4942 (__u32)(PTLRPC_MAX_BRW_PAGES << CFS_PAGE_SHIFT));
4943 if (data->ocd_brw_size == 0) {
4944 CERROR("%s: cli %s/%p ocd_connect_flags: "LPX64
4945 " ocd_version: %x ocd_grant: %d "
4946 "ocd_index: %u ocd_brw_size is "
4947 "unexpectedly zero, network data "
4948 "corruption? Refusing connection of this"
4950 exp->exp_obd->obd_name,
4951 exp->exp_client_uuid.uuid,
4952 exp, data->ocd_connect_flags, data->ocd_version,
4953 data->ocd_grant, data->ocd_index);
4958 cfs_spin_lock(&exp->exp_lock);
4959 exp->exp_connect_flags = data->ocd_connect_flags;
4960 cfs_spin_unlock(&exp->exp_lock);
4961 data->ocd_version = LUSTRE_VERSION_CODE;
4962 exp->exp_mdt_data.med_ibits_known = data->ocd_ibits_known;
4966 if (mdt->mdt_opts.mo_acl &&
4967 ((exp->exp_connect_flags & OBD_CONNECT_ACL) == 0)) {
4968 CWARN("%s: MDS requires ACL support but client does not\n",
4969 mdt->mdt_md_dev.md_lu_dev.ld_obd->obd_name);
4974 if ((exp->exp_connect_flags & OBD_CONNECT_FID) == 0) {
4975 CWARN("%s: MDS requires FID support, but client not\n",
4976 mdt->mdt_md_dev.md_lu_dev.ld_obd->obd_name);
4980 if (mdt->mdt_som_conf && !exp_connect_som(exp) &&
4981 !(exp->exp_connect_flags & OBD_CONNECT_MDS_MDS)) {
4982 CWARN("%s: MDS has SOM enabled, but client does not support "
4983 "it\n", mdt->mdt_md_dev.md_lu_dev.ld_obd->obd_name);
4990 static int mdt_connect_check_sptlrpc(struct mdt_device *mdt,
4991 struct obd_export *exp,
4992 struct ptlrpc_request *req)
4994 struct sptlrpc_flavor flvr;
4997 if (exp->exp_flvr.sf_rpc == SPTLRPC_FLVR_INVALID) {
4998 cfs_read_lock(&mdt->mdt_sptlrpc_lock);
4999 sptlrpc_target_choose_flavor(&mdt->mdt_sptlrpc_rset,
5003 cfs_read_unlock(&mdt->mdt_sptlrpc_lock);
5005 cfs_spin_lock(&exp->exp_lock);
5007 exp->exp_sp_peer = req->rq_sp_from;
5008 exp->exp_flvr = flvr;
5010 if (exp->exp_flvr.sf_rpc != SPTLRPC_FLVR_ANY &&
5011 exp->exp_flvr.sf_rpc != req->rq_flvr.sf_rpc) {
5012 CERROR("unauthorized rpc flavor %x from %s, "
5013 "expect %x\n", req->rq_flvr.sf_rpc,
5014 libcfs_nid2str(req->rq_peer.nid),
5015 exp->exp_flvr.sf_rpc);
5019 cfs_spin_unlock(&exp->exp_lock);
5021 if (exp->exp_sp_peer != req->rq_sp_from) {
5022 CERROR("RPC source %s doesn't match %s\n",
5023 sptlrpc_part2name(req->rq_sp_from),
5024 sptlrpc_part2name(exp->exp_sp_peer));
5027 rc = sptlrpc_target_export_check(exp, req);
5034 /* mds_connect copy */
5035 static int mdt_obd_connect(const struct lu_env *env,
5036 struct obd_export **exp, struct obd_device *obd,
5037 struct obd_uuid *cluuid,
5038 struct obd_connect_data *data,
5041 struct mdt_thread_info *info;
5042 struct obd_export *lexp;
5043 struct lustre_handle conn = { 0 };
5044 struct mdt_device *mdt;
5045 struct ptlrpc_request *req;
5049 LASSERT(env != NULL);
5050 if (!exp || !obd || !cluuid)
5053 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
5054 req = info->mti_pill->rc_req;
5055 mdt = mdt_dev(obd->obd_lu_dev);
5057 rc = class_connect(&conn, obd, cluuid);
5061 lexp = class_conn2export(&conn);
5062 LASSERT(lexp != NULL);
5064 rc = mdt_connect_check_sptlrpc(mdt, lexp, req);
5068 if (OBD_FAIL_CHECK(OBD_FAIL_TGT_RCVG_FLAG))
5069 lustre_msg_add_op_flags(req->rq_repmsg, MSG_CONNECT_RECOVERING);
5071 rc = mdt_connect_internal(lexp, mdt, data);
5073 struct mdt_thread_info *mti;
5074 struct lsd_client_data *lcd = lexp->exp_target_data.ted_lcd;
5076 mti = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
5077 LASSERT(mti != NULL);
5078 mti->mti_exp = lexp;
5079 memcpy(lcd->lcd_uuid, cluuid, sizeof lcd->lcd_uuid);
5080 rc = mdt_client_new(env, mdt);
5082 mdt_export_stats_init(obd, lexp, localdata);
5087 class_disconnect(lexp);
5096 static int mdt_obd_reconnect(const struct lu_env *env,
5097 struct obd_export *exp, struct obd_device *obd,
5098 struct obd_uuid *cluuid,
5099 struct obd_connect_data *data,
5102 struct mdt_thread_info *info;
5103 struct mdt_device *mdt;
5104 struct ptlrpc_request *req;
5108 if (exp == NULL || obd == NULL || cluuid == NULL)
5111 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
5112 req = info->mti_pill->rc_req;
5113 mdt = mdt_dev(obd->obd_lu_dev);
5115 rc = mdt_connect_check_sptlrpc(mdt, exp, req);
5119 rc = mdt_connect_internal(exp, mdt_dev(obd->obd_lu_dev), data);
5121 mdt_export_stats_init(obd, exp, localdata);
5125 static int mdt_export_cleanup(struct obd_export *exp)
5127 struct mdt_export_data *med = &exp->exp_mdt_data;
5128 struct obd_device *obd = exp->exp_obd;
5129 struct mdt_device *mdt;
5130 struct mdt_thread_info *info;
5132 CFS_LIST_HEAD(closing_list);
5133 struct mdt_file_data *mfd, *n;
5137 cfs_spin_lock(&med->med_open_lock);
5138 while (!cfs_list_empty(&med->med_open_head)) {
5139 cfs_list_t *tmp = med->med_open_head.next;
5140 mfd = cfs_list_entry(tmp, struct mdt_file_data, mfd_list);
5142 /* Remove mfd handle so it can't be found again.
5143 * We are consuming the mfd_list reference here. */
5144 class_handle_unhash(&mfd->mfd_handle);
5145 cfs_list_move_tail(&mfd->mfd_list, &closing_list);
5147 cfs_spin_unlock(&med->med_open_lock);
5148 mdt = mdt_dev(obd->obd_lu_dev);
5149 LASSERT(mdt != NULL);
5151 rc = lu_env_init(&env, LCT_MD_THREAD);
5155 info = lu_context_key_get(&env.le_ctx, &mdt_thread_key);
5156 LASSERT(info != NULL);
5157 memset(info, 0, sizeof *info);
5158 info->mti_env = &env;
5159 info->mti_mdt = mdt;
5160 info->mti_exp = exp;
5162 if (!cfs_list_empty(&closing_list)) {
5163 struct md_attr *ma = &info->mti_attr;
5167 lmm_size = mdt->mdt_max_mdsize;
5168 OBD_ALLOC_LARGE(ma->ma_lmm, lmm_size);
5169 if (ma->ma_lmm == NULL)
5170 GOTO(out_lmm, rc = -ENOMEM);
5172 cookie_size = mdt->mdt_max_cookiesize;
5173 OBD_ALLOC_LARGE(ma->ma_cookie, cookie_size);
5174 if (ma->ma_cookie == NULL)
5175 GOTO(out_cookie, rc = -ENOMEM);
5177 /* Close any open files (which may also cause orphan unlinking). */
5178 cfs_list_for_each_entry_safe(mfd, n, &closing_list, mfd_list) {
5179 cfs_list_del_init(&mfd->mfd_list);
5180 memset(&ma->ma_attr, 0, sizeof(ma->ma_attr));
5181 ma->ma_lmm_size = lmm_size;
5182 ma->ma_cookie_size = cookie_size;
5184 /* It is not for setattr, just tell MDD to send
5185 * DESTROY RPC to OSS if needed */
5186 ma->ma_valid = MA_FLAGS;
5187 ma->ma_attr_flags = MDS_CLOSE_CLEANUP;
5188 /* Don't unlink orphan on failover umount, LU-184 */
5189 if (exp->exp_flags & OBD_OPT_FAILOVER)
5190 ma->ma_attr_flags |= MDS_KEEP_ORPHAN;
5191 mdt_mfd_close(info, mfd);
5193 OBD_FREE_LARGE(ma->ma_cookie, cookie_size);
5194 ma->ma_cookie = NULL;
5196 OBD_FREE_LARGE(ma->ma_lmm, lmm_size);
5200 info->mti_mdt = NULL;
5201 /* cleanup client slot early */
5202 /* Do not erase record for recoverable client. */
5203 if (!(exp->exp_flags & OBD_OPT_FAILOVER) || exp->exp_failed)
5204 mdt_client_del(&env, mdt);
5210 static int mdt_obd_disconnect(struct obd_export *exp)
5216 class_export_get(exp);
5218 rc = server_disconnect_export(exp);
5220 CDEBUG(D_IOCTL, "server disconnect error: %d\n", rc);
5222 rc = mdt_export_cleanup(exp);
5223 class_export_put(exp);
5227 /* FIXME: Can we avoid using these two interfaces? */
5228 static int mdt_init_export(struct obd_export *exp)
5230 struct mdt_export_data *med = &exp->exp_mdt_data;
5234 CFS_INIT_LIST_HEAD(&med->med_open_head);
5235 cfs_spin_lock_init(&med->med_open_lock);
5236 cfs_sema_init(&med->med_idmap_sem, 1);
5237 med->med_idmap = NULL;
5238 cfs_spin_lock(&exp->exp_lock);
5239 exp->exp_connecting = 1;
5240 cfs_spin_unlock(&exp->exp_lock);
5242 /* self-export doesn't need client data and ldlm initialization */
5243 if (unlikely(obd_uuid_equals(&exp->exp_obd->obd_uuid,
5244 &exp->exp_client_uuid)))
5247 rc = lut_client_alloc(exp);
5249 rc = ldlm_init_export(exp);
5251 CERROR("%s: Error %d while initializing export\n",
5252 exp->exp_obd->obd_name, rc);
5256 static int mdt_destroy_export(struct obd_export *exp)
5260 if (exp_connect_rmtclient(exp))
5261 mdt_cleanup_idmap(&exp->exp_mdt_data);
5263 target_destroy_export(exp);
5264 /* destroy can be called from failed obd_setup, so
5265 * checking uuid is safer than obd_self_export */
5266 if (unlikely(obd_uuid_equals(&exp->exp_obd->obd_uuid,
5267 &exp->exp_client_uuid)))
5270 ldlm_destroy_export(exp);
5271 lut_client_free(exp);
5273 LASSERT(cfs_list_empty(&exp->exp_outstanding_replies));
5274 LASSERT(cfs_list_empty(&exp->exp_mdt_data.med_open_head));
5279 static void mdt_allow_cli(struct mdt_device *m, unsigned int flag)
5281 if (flag & CONFIG_LOG)
5282 cfs_set_bit(MDT_FL_CFGLOG, &m->mdt_state);
5284 /* also notify active event */
5285 if (flag & CONFIG_SYNC)
5286 cfs_set_bit(MDT_FL_SYNCED, &m->mdt_state);
5288 if (cfs_test_bit(MDT_FL_CFGLOG, &m->mdt_state) &&
5289 cfs_test_bit(MDT_FL_SYNCED, &m->mdt_state)) {
5290 struct obd_device *obd = m->mdt_md_dev.md_lu_dev.ld_obd;
5292 /* Open for clients */
5293 if (obd->obd_no_conn) {
5294 cfs_spin_lock(&obd->obd_dev_lock);
5295 obd->obd_no_conn = 0;
5296 cfs_spin_unlock(&obd->obd_dev_lock);
5301 static int mdt_upcall(const struct lu_env *env, struct md_device *md,
5302 enum md_upcall_event ev, void *data)
5304 struct mdt_device *m = mdt_dev(&md->md_lu_dev);
5305 struct md_device *next = m->mdt_child;
5306 struct mdt_thread_info *mti;
5312 rc = next->md_ops->mdo_maxsize_get(env, next,
5314 &m->mdt_max_cookiesize);
5315 CDEBUG(D_INFO, "get max mdsize %d max cookiesize %d\n",
5316 m->mdt_max_mdsize, m->mdt_max_cookiesize);
5317 mdt_allow_cli(m, CONFIG_SYNC);
5320 m->mdt_lut.lut_obd->u.obt.obt_mount_count;
5323 mti = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
5324 mti->mti_no_need_trans = 1;
5325 CDEBUG(D_INFO, "disable mdt trans for this thread\n");
5328 /* Check that MDT is not yet configured */
5329 LASSERT(!cfs_test_bit(MDT_FL_CFGLOG, &m->mdt_state));
5331 #ifdef HAVE_QUOTA_SUPPORT
5333 if (md->md_lu_dev.ld_obd->obd_recovering == 0 &&
5334 likely(md->md_lu_dev.ld_obd->obd_stopping == 0))
5335 next->md_ops->mdo_quota.mqo_recovery(env, next);
5339 CERROR("invalid event\n");
5346 static int mdt_obd_notify(struct obd_device *obd,
5347 struct obd_device *watched,
5348 enum obd_notify_event ev, void *data)
5350 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
5351 #ifdef HAVE_QUOTA_SUPPORT
5352 struct md_device *next = mdt->mdt_child;
5357 case OBD_NOTIFY_CONFIG:
5358 mdt_allow_cli(mdt, (unsigned long)data);
5360 #ifdef HAVE_QUOTA_SUPPORT
5361 /* quota_type has been processed, we can now handle
5362 * incoming quota requests */
5363 next->md_ops->mdo_quota.mqo_notify(NULL, next);
5367 CDEBUG(D_INFO, "Unhandled notification %#x\n", ev);
5372 static int mdt_rpc_fid2path(struct mdt_thread_info *info, void *key,
5373 void *val, int vallen)
5375 struct mdt_device *mdt = mdt_dev(info->mti_exp->exp_obd->obd_lu_dev);
5376 struct getinfo_fid2path *fpout, *fpin;
5379 fpin = key + cfs_size_round(sizeof(KEY_FID2PATH));
5382 if (ptlrpc_req_need_swab(info->mti_pill->rc_req))
5383 lustre_swab_fid2path(fpin);
5385 memcpy(fpout, fpin, sizeof(*fpin));
5386 if (fpout->gf_pathlen != vallen - sizeof(*fpin))
5389 rc = mdt_fid2path(info->mti_env, mdt, fpout);
5393 static int mdt_fid2path(const struct lu_env *env, struct mdt_device *mdt,
5394 struct getinfo_fid2path *fp)
5396 struct mdt_object *obj;
5400 CDEBUG(D_IOCTL, "path get "DFID" from "LPU64" #%d\n",
5401 PFID(&fp->gf_fid), fp->gf_recno, fp->gf_linkno);
5403 if (!fid_is_sane(&fp->gf_fid))
5406 obj = mdt_object_find(env, mdt, &fp->gf_fid, MDT_OBJ_MUST_EXIST);
5407 if (obj == NULL || IS_ERR(obj)) {
5408 CDEBUG(D_IOCTL, "%s: no object "DFID": %ld\n",
5409 mdt2obd_dev(mdt)->obd_name, PFID(&fp->gf_fid),
5411 RETURN(obj == NULL ? -EINVAL : PTR_ERR(obj));
5414 if (lu_object_exists(&obj->mot_obj.mo_lu) < 0) {
5416 mdt_object_put(env, obj);
5417 CDEBUG(D_IOCTL, "nonlocal object "DFID": %d\n",
5418 PFID(&fp->gf_fid), rc);
5422 rc = mo_path(env, md_object_next(&obj->mot_obj), fp->gf_path,
5423 fp->gf_pathlen, &fp->gf_recno, &fp->gf_linkno);
5424 mdt_object_put(env, obj);
5429 static int mdt_get_info(struct mdt_thread_info *info)
5431 struct ptlrpc_request *req = mdt_info_req(info);
5439 key = req_capsule_client_get(info->mti_pill, &RMF_GETINFO_KEY);
5441 CDEBUG(D_IOCTL, "No GETINFO key");
5444 keylen = req_capsule_get_size(info->mti_pill, &RMF_GETINFO_KEY,
5447 vallen = req_capsule_client_get(info->mti_pill, &RMF_GETINFO_VALLEN);
5448 if (vallen == NULL) {
5449 CDEBUG(D_IOCTL, "Unable to get RMF_GETINFO_VALLEN buffer");
5453 req_capsule_set_size(info->mti_pill, &RMF_GETINFO_VAL, RCL_SERVER,
5455 rc = req_capsule_server_pack(info->mti_pill);
5456 valout = req_capsule_server_get(info->mti_pill, &RMF_GETINFO_VAL);
5457 if (valout == NULL) {
5458 CDEBUG(D_IOCTL, "Unable to get get-info RPC out buffer");
5462 if (KEY_IS(KEY_FID2PATH))
5463 rc = mdt_rpc_fid2path(info, key, valout, *vallen);
5467 lustre_msg_set_status(req->rq_repmsg, rc);
5472 /* Pass the ioc down */
5473 static int mdt_ioc_child(struct lu_env *env, struct mdt_device *mdt,
5474 unsigned int cmd, int len, void *data)
5476 struct lu_context ioctl_session;
5477 struct md_device *next = mdt->mdt_child;
5481 rc = lu_context_init(&ioctl_session, LCT_SESSION);
5484 ioctl_session.lc_thread = (struct ptlrpc_thread *)cfs_current();
5485 lu_context_enter(&ioctl_session);
5486 env->le_ses = &ioctl_session;
5488 LASSERT(next->md_ops->mdo_iocontrol);
5489 rc = next->md_ops->mdo_iocontrol(env, next, cmd, len, data);
5491 lu_context_exit(&ioctl_session);
5492 lu_context_fini(&ioctl_session);
5496 static int mdt_ioc_version_get(struct mdt_thread_info *mti, void *karg)
5498 struct obd_ioctl_data *data = karg;
5499 struct lu_fid *fid = (struct lu_fid *)data->ioc_inlbuf1;
5501 struct mdt_object *obj;
5502 struct mdt_lock_handle *lh;
5506 CDEBUG(D_IOCTL, "getting version for "DFID"\n", PFID(fid));
5507 if (!fid_is_sane(fid))
5510 lh = &mti->mti_lh[MDT_LH_PARENT];
5511 mdt_lock_reg_init(lh, LCK_CR);
5513 obj = mdt_object_find_lock(mti, fid, lh, MDS_INODELOCK_UPDATE,
5514 MDT_OBJ_MUST_EXIST);
5516 if (PTR_ERR(obj) == -ENOENT)
5517 *(__u64 *)data->ioc_inlbuf2 = ENOENT_VERSION;
5518 RETURN(PTR_ERR(obj));
5521 rc = mdt_object_exists(obj);
5525 * before calling version get the correct MDS should be
5526 * fid, this is error to find remote object here
5528 CERROR("nonlocal object "DFID"\n", PFID(fid));
5529 } else if (rc > 0) {
5530 version = dt_version_get(mti->mti_env, mdt_obj2dt(obj));
5531 *(__u64 *)data->ioc_inlbuf2 = version;
5534 mdt_object_unlock_put(mti, obj, lh, 1);
5539 /* ioctls on obd dev */
5540 static int mdt_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
5541 void *karg, void *uarg)
5544 struct obd_device *obd = exp->exp_obd;
5545 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
5546 struct dt_device *dt = mdt->mdt_bottom;
5550 CDEBUG(D_IOCTL, "handling ioctl cmd %#x\n", cmd);
5551 rc = lu_env_init(&env, LCT_MD_THREAD);
5557 rc = mdt_device_sync(&env, mdt);
5559 case OBD_IOC_SET_READONLY:
5560 dt->dd_ops->dt_ro(&env, dt);
5562 case OBD_IOC_ABORT_RECOVERY:
5563 CERROR("Aborting recovery for device %s\n", obd->obd_name);
5564 target_stop_recovery_thread(obd);
5567 case OBD_IOC_CHANGELOG_REG:
5568 case OBD_IOC_CHANGELOG_DEREG:
5569 case OBD_IOC_CHANGELOG_CLEAR:
5570 rc = mdt_ioc_child(&env, mdt, cmd, len, karg);
5572 case OBD_IOC_GET_OBJ_VERSION: {
5573 struct mdt_thread_info *mti;
5574 mti = lu_context_key_get(&env.le_ctx, &mdt_thread_key);
5575 memset(mti, 0, sizeof *mti);
5576 mti->mti_env = &env;
5580 rc = mdt_ioc_version_get(mti, karg);
5584 CERROR("Not supported cmd = %d for device %s\n",
5585 cmd, obd->obd_name);
5593 int mdt_postrecov(const struct lu_env *env, struct mdt_device *mdt)
5595 struct lu_device *ld = md2lu_dev(mdt->mdt_child);
5596 #ifdef HAVE_QUOTA_SUPPORT
5597 struct obd_device *obd = mdt2obd_dev(mdt);
5598 struct md_device *next = mdt->mdt_child;
5603 rc = ld->ld_ops->ldo_recovery_complete(env, ld);
5604 #ifdef HAVE_QUOTA_SUPPORT
5605 if (likely(obd->obd_stopping == 0))
5606 next->md_ops->mdo_quota.mqo_recovery(env, next);
5611 int mdt_obd_postrecov(struct obd_device *obd)
5616 rc = lu_env_init(&env, LCT_MD_THREAD);
5619 rc = mdt_postrecov(&env, mdt_dev(obd->obd_lu_dev));
5625 * Send a copytool req to a client
5626 * Note this sends a request RPC from a server (MDT) to a client (MDC),
5627 * backwards of normal comms.
5629 int mdt_hsm_copytool_send(struct obd_export *exp)
5632 struct hsm_action_list *hal;
5633 struct hsm_action_item *hai;
5637 CWARN("%s: writing to mdc at %s\n", exp->exp_obd->obd_name,
5638 libcfs_nid2str(exp->exp_connection->c_peer.nid));
5640 len = sizeof(*lh) + sizeof(*hal) + MTI_NAME_MAXLEN +
5641 /* for mockup below */ 2 * cfs_size_round(sizeof(*hai));
5646 lh->kuc_magic = KUC_MAGIC;
5647 lh->kuc_transport = KUC_TRANSPORT_HSM;
5648 lh->kuc_msgtype = HMT_ACTION_LIST;
5649 lh->kuc_msglen = len;
5651 hal = (struct hsm_action_list *)(lh + 1);
5652 hal->hal_version = HAL_VERSION;
5653 hal->hal_archive_num = 1;
5654 obd_uuid2fsname(hal->hal_fsname, exp->exp_obd->obd_name,
5657 /* mock up an action list */
5659 hai = hai_zero(hal);
5660 hai->hai_action = HSMA_ARCHIVE;
5661 hai->hai_fid.f_oid = 0xA00A;
5662 hai->hai_len = sizeof(*hai);
5663 hai = hai_next(hai);
5664 hai->hai_action = HSMA_RESTORE;
5665 hai->hai_fid.f_oid = 0xB00B;
5666 hai->hai_len = sizeof(*hai);
5668 /* Uses the ldlm reverse import; this rpc will be seen by
5669 the ldlm_callback_handler */
5670 rc = do_set_info_async(exp->exp_imp_reverse,
5671 LDLM_SET_INFO, LUSTRE_OBD_VERSION,
5672 sizeof(KEY_HSM_COPYTOOL_SEND),
5673 KEY_HSM_COPYTOOL_SEND,
5681 static struct obd_ops mdt_obd_device_ops = {
5682 .o_owner = THIS_MODULE,
5683 .o_set_info_async = mdt_obd_set_info_async,
5684 .o_connect = mdt_obd_connect,
5685 .o_reconnect = mdt_obd_reconnect,
5686 .o_disconnect = mdt_obd_disconnect,
5687 .o_init_export = mdt_init_export,
5688 .o_destroy_export = mdt_destroy_export,
5689 .o_iocontrol = mdt_iocontrol,
5690 .o_postrecov = mdt_obd_postrecov,
5691 .o_notify = mdt_obd_notify
5694 static struct lu_device* mdt_device_fini(const struct lu_env *env,
5695 struct lu_device *d)
5697 struct mdt_device *m = mdt_dev(d);
5704 static struct lu_device *mdt_device_free(const struct lu_env *env,
5705 struct lu_device *d)
5707 struct mdt_device *m = mdt_dev(d);
5710 md_device_fini(&m->mdt_md_dev);
5715 static struct lu_device *mdt_device_alloc(const struct lu_env *env,
5716 struct lu_device_type *t,
5717 struct lustre_cfg *cfg)
5719 struct lu_device *l;
5720 struct mdt_device *m;
5726 l = &m->mdt_md_dev.md_lu_dev;
5727 rc = mdt_init0(env, m, t, cfg);
5729 mdt_device_free(env, l);
5733 md_upcall_init(&m->mdt_md_dev, mdt_upcall);
5735 l = ERR_PTR(-ENOMEM);
5739 /* context key constructor/destructor: mdt_key_init, mdt_key_fini */
5740 LU_KEY_INIT_FINI(mdt, struct mdt_thread_info);
5742 /* context key: mdt_thread_key */
5743 LU_CONTEXT_KEY_DEFINE(mdt, LCT_MD_THREAD);
5745 struct md_ucred *mdt_ucred(const struct mdt_thread_info *info)
5747 return md_ucred(info->mti_env);
5751 * Enable/disable COS (Commit On Sharing).
5753 * Set/Clear the COS flag in mdt options.
5755 * \param mdt mdt device
5756 * \param val 0 disables COS, other values enable COS
5758 void mdt_enable_cos(struct mdt_device *mdt, int val)
5763 mdt->mdt_opts.mo_cos = !!val;
5764 rc = lu_env_init(&env, LCT_MD_THREAD);
5765 if (unlikely(rc != 0)) {
5766 CWARN("lu_env initialization failed with rc = %d,"
5767 "cannot sync\n", rc);
5770 mdt_device_sync(&env, mdt);
5775 * Check COS (Commit On Sharing) status.
5777 * Return COS flag status.
5779 * \param mdt mdt device
5781 int mdt_cos_is_enabled(struct mdt_device *mdt)
5783 return mdt->mdt_opts.mo_cos != 0;
5786 /* type constructor/destructor: mdt_type_init, mdt_type_fini */
5787 LU_TYPE_INIT_FINI(mdt, &mdt_thread_key);
5789 static struct lu_device_type_operations mdt_device_type_ops = {
5790 .ldto_init = mdt_type_init,
5791 .ldto_fini = mdt_type_fini,
5793 .ldto_start = mdt_type_start,
5794 .ldto_stop = mdt_type_stop,
5796 .ldto_device_alloc = mdt_device_alloc,
5797 .ldto_device_free = mdt_device_free,
5798 .ldto_device_fini = mdt_device_fini
5801 static struct lu_device_type mdt_device_type = {
5802 .ldt_tags = LU_DEVICE_MD,
5803 .ldt_name = LUSTRE_MDT_NAME,
5804 .ldt_ops = &mdt_device_type_ops,
5805 .ldt_ctx_tags = LCT_MD_THREAD
5808 static struct lu_local_obj_desc mdt_last_recv = {
5809 .llod_name = LAST_RCVD,
5810 .llod_oid = MDT_LAST_RECV_OID,
5814 static int __init mdt_mod_init(void)
5816 struct lprocfs_static_vars lvars;
5819 llo_local_obj_register(&mdt_last_recv);
5821 if (mdt_num_threads > 0) {
5822 if (mdt_num_threads > MDT_MAX_THREADS)
5823 mdt_num_threads = MDT_MAX_THREADS;
5824 if (mdt_num_threads < MDT_MIN_THREADS)
5825 mdt_num_threads = MDT_MIN_THREADS;
5826 mdt_max_threads = mdt_min_threads = mdt_num_threads;
5828 mdt_max_threads = MDT_MAX_THREADS;
5829 mdt_min_threads = MDT_MIN_THREADS;
5832 lprocfs_mdt_init_vars(&lvars);
5833 rc = class_register_type(&mdt_obd_device_ops, NULL,
5834 lvars.module_vars, LUSTRE_MDT_NAME,
5840 static void __exit mdt_mod_exit(void)
5842 llo_local_obj_unregister(&mdt_last_recv);
5843 class_unregister_type(LUSTRE_MDT_NAME);
5847 #define DEF_HNDL(prefix, base, suffix, flags, opc, fn, fmt) \
5848 [prefix ## _ ## opc - prefix ## _ ## base] = { \
5850 .mh_fail_id = OBD_FAIL_ ## prefix ## _ ## opc ## suffix, \
5851 .mh_opc = prefix ## _ ## opc, \
5852 .mh_flags = flags, \
5857 #define DEF_MDT_HNDL(flags, name, fn, fmt) \
5858 DEF_HNDL(MDS, GETATTR, _NET, flags, name, fn, fmt)
5860 #define DEF_SEQ_HNDL(flags, name, fn, fmt) \
5861 DEF_HNDL(SEQ, QUERY, _NET, flags, name, fn, fmt)
5863 #define DEF_FLD_HNDL(flags, name, fn, fmt) \
5864 DEF_HNDL(FLD, QUERY, _NET, flags, name, fn, fmt)
5866 * Request with a format known in advance
5868 #define DEF_MDT_HNDL_F(flags, name, fn) \
5869 DEF_HNDL(MDS, GETATTR, _NET, flags, name, fn, &RQF_MDS_ ## name)
5871 #define DEF_SEQ_HNDL_F(flags, name, fn) \
5872 DEF_HNDL(SEQ, QUERY, _NET, flags, name, fn, &RQF_SEQ_ ## name)
5874 #define DEF_FLD_HNDL_F(flags, name, fn) \
5875 DEF_HNDL(FLD, QUERY, _NET, flags, name, fn, &RQF_FLD_ ## name)
5877 * Request with a format we do not yet know
5879 #define DEF_MDT_HNDL_0(flags, name, fn) \
5880 DEF_HNDL(MDS, GETATTR, _NET, flags, name, fn, NULL)
5882 static struct mdt_handler mdt_mds_ops[] = {
5883 DEF_MDT_HNDL_F(0, CONNECT, mdt_connect),
5884 DEF_MDT_HNDL_F(0, DISCONNECT, mdt_disconnect),
5885 DEF_MDT_HNDL (0, SET_INFO, mdt_set_info,
5887 DEF_MDT_HNDL_F(0, GET_INFO, mdt_get_info),
5888 DEF_MDT_HNDL_F(0 |HABEO_REFERO, GETSTATUS, mdt_getstatus),
5889 DEF_MDT_HNDL_F(HABEO_CORPUS, GETATTR, mdt_getattr),
5890 DEF_MDT_HNDL_F(HABEO_CORPUS|HABEO_REFERO, GETATTR_NAME, mdt_getattr_name),
5891 DEF_MDT_HNDL_F(HABEO_CORPUS, GETXATTR, mdt_getxattr),
5892 DEF_MDT_HNDL_F(0 |HABEO_REFERO, STATFS, mdt_statfs),
5893 DEF_MDT_HNDL_F(0 |MUTABOR, REINT, mdt_reint),
5894 DEF_MDT_HNDL_F(HABEO_CORPUS, CLOSE, mdt_close),
5895 DEF_MDT_HNDL_F(HABEO_CORPUS, DONE_WRITING, mdt_done_writing),
5896 DEF_MDT_HNDL_F(0 |HABEO_REFERO, PIN, mdt_pin),
5897 DEF_MDT_HNDL_0(0, SYNC, mdt_sync),
5898 DEF_MDT_HNDL_F(HABEO_CORPUS|HABEO_REFERO, IS_SUBDIR, mdt_is_subdir),
5899 #ifdef HAVE_QUOTA_SUPPORT
5900 DEF_MDT_HNDL_F(0, QUOTACHECK, mdt_quotacheck_handle),
5901 DEF_MDT_HNDL_F(0, QUOTACTL, mdt_quotactl_handle)
5905 #define DEF_OBD_HNDL(flags, name, fn) \
5906 DEF_HNDL(OBD, PING, _NET, flags, name, fn, NULL)
5909 static struct mdt_handler mdt_obd_ops[] = {
5910 DEF_OBD_HNDL(0, PING, mdt_obd_ping),
5911 DEF_OBD_HNDL(0, LOG_CANCEL, mdt_obd_log_cancel),
5912 DEF_OBD_HNDL(0, QC_CALLBACK, mdt_obd_qc_callback)
5915 #define DEF_DLM_HNDL_0(flags, name, fn) \
5916 DEF_HNDL(LDLM, ENQUEUE, , flags, name, fn, NULL)
5917 #define DEF_DLM_HNDL_F(flags, name, fn) \
5918 DEF_HNDL(LDLM, ENQUEUE, , flags, name, fn, &RQF_LDLM_ ## name)
5920 static struct mdt_handler mdt_dlm_ops[] = {
5921 DEF_DLM_HNDL_F(HABEO_CLAVIS, ENQUEUE, mdt_enqueue),
5922 DEF_DLM_HNDL_0(HABEO_CLAVIS, CONVERT, mdt_convert),
5923 DEF_DLM_HNDL_0(0, BL_CALLBACK, mdt_bl_callback),
5924 DEF_DLM_HNDL_0(0, CP_CALLBACK, mdt_cp_callback)
5927 #define DEF_LLOG_HNDL(flags, name, fn) \
5928 DEF_HNDL(LLOG, ORIGIN_HANDLE_CREATE, _NET, flags, name, fn, NULL)
5930 static struct mdt_handler mdt_llog_ops[] = {
5931 DEF_LLOG_HNDL(0, ORIGIN_HANDLE_CREATE, mdt_llog_create),
5932 DEF_LLOG_HNDL(0, ORIGIN_HANDLE_NEXT_BLOCK, mdt_llog_next_block),
5933 DEF_LLOG_HNDL(0, ORIGIN_HANDLE_READ_HEADER, mdt_llog_read_header),
5934 DEF_LLOG_HNDL(0, ORIGIN_HANDLE_WRITE_REC, NULL),
5935 DEF_LLOG_HNDL(0, ORIGIN_HANDLE_CLOSE, NULL),
5936 DEF_LLOG_HNDL(0, ORIGIN_CONNECT, NULL),
5937 DEF_LLOG_HNDL(0, CATINFO, NULL),
5938 DEF_LLOG_HNDL(0, ORIGIN_HANDLE_PREV_BLOCK, mdt_llog_prev_block),
5939 DEF_LLOG_HNDL(0, ORIGIN_HANDLE_DESTROY, mdt_llog_destroy),
5942 #define DEF_SEC_CTX_HNDL(name, fn) \
5943 DEF_HNDL(SEC_CTX, INIT, _NET, 0, name, fn, NULL)
5945 static struct mdt_handler mdt_sec_ctx_ops[] = {
5946 DEF_SEC_CTX_HNDL(INIT, mdt_sec_ctx_handle),
5947 DEF_SEC_CTX_HNDL(INIT_CONT, mdt_sec_ctx_handle),
5948 DEF_SEC_CTX_HNDL(FINI, mdt_sec_ctx_handle)
5951 static struct mdt_opc_slice mdt_regular_handlers[] = {
5953 .mos_opc_start = MDS_GETATTR,
5954 .mos_opc_end = MDS_LAST_OPC,
5955 .mos_hs = mdt_mds_ops
5958 .mos_opc_start = OBD_PING,
5959 .mos_opc_end = OBD_LAST_OPC,
5960 .mos_hs = mdt_obd_ops
5963 .mos_opc_start = LDLM_ENQUEUE,
5964 .mos_opc_end = LDLM_LAST_OPC,
5965 .mos_hs = mdt_dlm_ops
5968 .mos_opc_start = LLOG_ORIGIN_HANDLE_CREATE,
5969 .mos_opc_end = LLOG_LAST_OPC,
5970 .mos_hs = mdt_llog_ops
5973 .mos_opc_start = SEC_CTX_INIT,
5974 .mos_opc_end = SEC_LAST_OPC,
5975 .mos_hs = mdt_sec_ctx_ops
5982 static struct mdt_handler mdt_readpage_ops[] = {
5983 DEF_MDT_HNDL_F(0, CONNECT, mdt_connect),
5984 DEF_MDT_HNDL_F(HABEO_CORPUS|HABEO_REFERO, READPAGE, mdt_readpage),
5985 #ifdef HAVE_SPLIT_SUPPORT
5986 DEF_MDT_HNDL_F(HABEO_CORPUS|HABEO_REFERO, WRITEPAGE, mdt_writepage),
5990 * XXX: this is ugly and should be fixed one day, see mdc_close() for
5991 * detailed comments. --umka
5993 DEF_MDT_HNDL_F(HABEO_CORPUS, CLOSE, mdt_close),
5994 DEF_MDT_HNDL_F(HABEO_CORPUS, DONE_WRITING, mdt_done_writing),
5997 static struct mdt_opc_slice mdt_readpage_handlers[] = {
5999 .mos_opc_start = MDS_GETATTR,
6000 .mos_opc_end = MDS_LAST_OPC,
6001 .mos_hs = mdt_readpage_ops
6008 static struct mdt_handler mdt_xmds_ops[] = {
6009 DEF_MDT_HNDL_F(0, CONNECT, mdt_connect),
6010 DEF_MDT_HNDL_F(HABEO_CORPUS , GETATTR, mdt_getattr),
6011 DEF_MDT_HNDL_F(0 | MUTABOR , REINT, mdt_reint),
6012 DEF_MDT_HNDL_F(HABEO_CORPUS|HABEO_REFERO, IS_SUBDIR, mdt_is_subdir),
6015 static struct mdt_opc_slice mdt_xmds_handlers[] = {
6017 .mos_opc_start = MDS_GETATTR,
6018 .mos_opc_end = MDS_LAST_OPC,
6019 .mos_hs = mdt_xmds_ops
6022 .mos_opc_start = OBD_PING,
6023 .mos_opc_end = OBD_LAST_OPC,
6024 .mos_hs = mdt_obd_ops
6027 .mos_opc_start = SEC_CTX_INIT,
6028 .mos_opc_end = SEC_LAST_OPC,
6029 .mos_hs = mdt_sec_ctx_ops
6036 static struct mdt_handler mdt_seq_ops[] = {
6037 DEF_SEQ_HNDL_F(0, QUERY, (int (*)(struct mdt_thread_info *))seq_query)
6040 static struct mdt_opc_slice mdt_seq_handlers[] = {
6042 .mos_opc_start = SEQ_QUERY,
6043 .mos_opc_end = SEQ_LAST_OPC,
6044 .mos_hs = mdt_seq_ops
6051 static struct mdt_handler mdt_fld_ops[] = {
6052 DEF_FLD_HNDL_F(0, QUERY, (int (*)(struct mdt_thread_info *))fld_query)
6055 static struct mdt_opc_slice mdt_fld_handlers[] = {
6057 .mos_opc_start = FLD_QUERY,
6058 .mos_opc_end = FLD_LAST_OPC,
6059 .mos_hs = mdt_fld_ops
6066 MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");
6067 MODULE_DESCRIPTION("Lustre Meta-data Target ("LUSTRE_MDT_NAME")");
6068 MODULE_LICENSE("GPL");
6070 CFS_MODULE_PARM(mdt_num_threads, "ul", ulong, 0444,
6071 "number of mdt service threads to start");
6073 cfs_module(mdt, "0.2.0", mdt_mod_init, mdt_mod_exit);