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;
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)), PFID(&reqbody->fid2),
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 */
973 lhp = &info->mti_lh[MDT_LH_PARENT];
974 mdt_lock_pdo_init(lhp, LCK_PR, name, namelen);
975 rc = mdt_object_lock(info, parent, lhp, MDS_INODELOCK_UPDATE,
977 if (unlikely(rc != 0))
980 /* step 2: lookup child's fid by name */
981 rc = mdo_lookup(info->mti_env, next, lname, child_fid,
986 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_NEG);
987 GOTO(out_parent, rc);
989 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_POS);
991 *child_fid = reqbody->fid2;
992 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_POS);
996 *step 3: find the child object by fid & lock it.
997 * regardless if it is local or remote.
999 child = mdt_object_find(info->mti_env, info->mti_mdt, child_fid,
1000 MDT_OBJ_MUST_EXIST);
1002 if (unlikely(IS_ERR(child)))
1003 GOTO(out_parent, rc = PTR_ERR(child));
1005 /* Do not take lock for resent case. */
1006 lock = ldlm_handle2lock(&lhc->mlh_reg_lh);
1007 LASSERTF(lock != NULL, "Invalid lock handle "LPX64"\n",
1008 lhc->mlh_reg_lh.cookie);
1010 res_id = &lock->l_resource->lr_name;
1011 if (!fid_res_name_eq(mdt_object_fid(child),
1012 &lock->l_resource->lr_name)) {
1013 LASSERTF(fid_res_name_eq(mdt_object_fid(parent),
1014 &lock->l_resource->lr_name),
1015 "Lock res_id: %lu/%lu/%lu, Fid: "DFID".\n",
1016 (unsigned long)res_id->name[0],
1017 (unsigned long)res_id->name[1],
1018 (unsigned long)res_id->name[2],
1019 PFID(mdt_object_fid(parent)));
1020 CWARN("Although resent, but still not get child lock"
1021 "parent:"DFID" child:"DFID"\n",
1022 PFID(mdt_object_fid(parent)),
1023 PFID(mdt_object_fid(child)));
1024 lustre_msg_clear_flags(req->rq_reqmsg, MSG_RESENT);
1025 LDLM_LOCK_PUT(lock);
1028 LDLM_LOCK_PUT(lock);
1032 OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_RESEND, obd_timeout*2);
1033 mdt_lock_handle_init(lhc);
1034 mdt_lock_reg_init(lhc, LCK_PR);
1036 if (!(child_bits & MDS_INODELOCK_UPDATE)) {
1037 struct md_attr *ma = &info->mti_attr;
1040 ma->ma_need = MA_INODE;
1041 rc = mo_attr_get(info->mti_env,
1042 mdt_object_child(child), ma);
1043 if (unlikely(rc != 0))
1044 GOTO(out_child, rc);
1046 /* If the file has not been changed for some time, we
1047 * return not only a LOOKUP lock, but also an UPDATE
1048 * lock and this might save us RPC on later STAT. For
1049 * directories, it also let negative dentry starts
1050 * working for this dir. */
1051 if (ma->ma_valid & MA_INODE &&
1052 ma->ma_attr.la_valid & LA_CTIME &&
1053 info->mti_mdt->mdt_namespace->ns_ctime_age_limit +
1054 ma->ma_attr.la_ctime < cfs_time_current_sec())
1055 child_bits |= MDS_INODELOCK_UPDATE;
1058 rc = mdt_object_lock(info, child, lhc, child_bits,
1061 if (unlikely(rc != 0))
1062 GOTO(out_child, rc);
1065 lock = ldlm_handle2lock(&lhc->mlh_reg_lh);
1066 /* Get MA_SOM attributes if update lock is given. */
1068 lock->l_policy_data.l_inodebits.bits & MDS_INODELOCK_UPDATE &&
1069 S_ISREG(lu_object_attr(&mdt_object_child(child)->mo_lu)))
1072 /* finally, we can get attr for child. */
1073 mdt_set_capainfo(info, 1, child_fid, BYPASS_CAPA);
1074 rc = mdt_getattr_internal(info, child, ma_need);
1075 if (unlikely(rc != 0)) {
1076 mdt_object_unlock(info, child, lhc, 1);
1078 /* Debugging code. */
1079 res_id = &lock->l_resource->lr_name;
1080 LDLM_DEBUG(lock, "Returning lock to client");
1081 LASSERTF(fid_res_name_eq(mdt_object_fid(child),
1082 &lock->l_resource->lr_name),
1083 "Lock res_id: %lu/%lu/%lu, Fid: "DFID".\n",
1084 (unsigned long)res_id->name[0],
1085 (unsigned long)res_id->name[1],
1086 (unsigned long)res_id->name[2],
1087 PFID(mdt_object_fid(child)));
1088 mdt_pack_size2body(info, child);
1091 LDLM_LOCK_PUT(lock);
1095 mdt_object_put(info->mti_env, child);
1098 mdt_object_unlock(info, parent, lhp, 1);
1102 /* normal handler: should release the child lock */
1103 static int mdt_getattr_name(struct mdt_thread_info *info)
1105 struct mdt_lock_handle *lhc = &info->mti_lh[MDT_LH_CHILD];
1106 struct mdt_body *reqbody;
1107 struct mdt_body *repbody;
1111 reqbody = req_capsule_client_get(info->mti_pill, &RMF_MDT_BODY);
1112 LASSERT(reqbody != NULL);
1113 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
1114 LASSERT(repbody != NULL);
1116 info->mti_spec.sp_ck_split = !!(reqbody->valid & OBD_MD_FLCKSPLIT);
1117 info->mti_cross_ref = !!(reqbody->valid & OBD_MD_FLCROSSREF);
1118 repbody->eadatasize = 0;
1119 repbody->aclsize = 0;
1121 rc = mdt_init_ucred(info, reqbody);
1123 GOTO(out_shrink, rc);
1125 rc = mdt_getattr_name_lock(info, lhc, MDS_INODELOCK_UPDATE, NULL);
1126 if (lustre_handle_is_used(&lhc->mlh_reg_lh)) {
1127 ldlm_lock_decref(&lhc->mlh_reg_lh, lhc->mlh_reg_mode);
1128 lhc->mlh_reg_lh.cookie = 0;
1130 mdt_exit_ucred(info);
1133 mdt_client_compatibility(info);
1134 mdt_shrink_reply(info);
1138 static const struct lu_device_operations mdt_lu_ops;
1140 static int lu_device_is_mdt(struct lu_device *d)
1142 return ergo(d != NULL && d->ld_ops != NULL, d->ld_ops == &mdt_lu_ops);
1145 static int mdt_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
1146 void *karg, void *uarg);
1148 static int mdt_set_info(struct mdt_thread_info *info)
1150 struct ptlrpc_request *req = mdt_info_req(info);
1153 int keylen, vallen, rc = 0;
1156 rc = req_capsule_server_pack(info->mti_pill);
1160 key = req_capsule_client_get(info->mti_pill, &RMF_SETINFO_KEY);
1162 DEBUG_REQ(D_HA, req, "no set_info key");
1166 keylen = req_capsule_get_size(info->mti_pill, &RMF_SETINFO_KEY,
1169 val = req_capsule_client_get(info->mti_pill, &RMF_SETINFO_VAL);
1171 DEBUG_REQ(D_HA, req, "no set_info val");
1175 vallen = req_capsule_get_size(info->mti_pill, &RMF_SETINFO_VAL,
1178 /* Swab any part of val you need to here */
1179 if (KEY_IS(KEY_READ_ONLY)) {
1181 lustre_msg_set_status(req->rq_repmsg, 0);
1183 cfs_spin_lock(&req->rq_export->exp_lock);
1185 req->rq_export->exp_connect_flags |= OBD_CONNECT_RDONLY;
1187 req->rq_export->exp_connect_flags &=~OBD_CONNECT_RDONLY;
1188 cfs_spin_unlock(&req->rq_export->exp_lock);
1190 } else if (KEY_IS(KEY_CHANGELOG_CLEAR)) {
1191 struct changelog_setinfo *cs =
1192 (struct changelog_setinfo *)val;
1193 if (vallen != sizeof(*cs)) {
1194 CERROR("Bad changelog_clear setinfo size %d\n", vallen);
1197 if (ptlrpc_req_need_swab(req)) {
1198 __swab64s(&cs->cs_recno);
1199 __swab32s(&cs->cs_id);
1202 rc = mdt_iocontrol(OBD_IOC_CHANGELOG_CLEAR, info->mti_exp,
1204 lustre_msg_set_status(req->rq_repmsg, rc);
1212 static int mdt_connect(struct mdt_thread_info *info)
1215 struct ptlrpc_request *req;
1217 req = mdt_info_req(info);
1218 rc = target_handle_connect(req);
1220 LASSERT(req->rq_export != NULL);
1221 info->mti_mdt = mdt_dev(req->rq_export->exp_obd->obd_lu_dev);
1222 rc = mdt_init_sec_level(info);
1224 rc = mdt_init_idmap(info);
1226 obd_disconnect(class_export_get(req->rq_export));
1228 rc = err_serious(rc);
1233 static int mdt_disconnect(struct mdt_thread_info *info)
1238 rc = target_handle_disconnect(mdt_info_req(info));
1240 rc = err_serious(rc);
1244 static int mdt_sendpage(struct mdt_thread_info *info,
1245 struct lu_rdpg *rdpg, int nob)
1247 struct ptlrpc_request *req = mdt_info_req(info);
1248 struct obd_export *exp = req->rq_export;
1249 struct ptlrpc_bulk_desc *desc;
1250 struct l_wait_info *lwi = &info->mti_u.rdpg.mti_wait_info;
1257 desc = ptlrpc_prep_bulk_exp(req, rdpg->rp_npages, BULK_PUT_SOURCE,
1262 for (i = 0, tmpcount = nob;
1263 i < rdpg->rp_npages && tmpcount > 0; i++, tmpcount -= tmpsize) {
1264 tmpsize = min_t(int, tmpcount, CFS_PAGE_SIZE);
1265 ptlrpc_prep_bulk_page(desc, rdpg->rp_pages[i], 0, tmpsize);
1268 LASSERT(desc->bd_nob == nob);
1269 rc = target_bulk_io(exp, desc, lwi);
1270 ptlrpc_free_bulk(desc);
1274 #ifdef HAVE_SPLIT_SUPPORT
1276 * Retrieve dir entry from the page and insert it to the slave object, actually,
1277 * this should be in osd layer, but since it will not in the final product, so
1278 * just do it here and do not define more moo api anymore for this.
1280 static int mdt_write_dir_page(struct mdt_thread_info *info, struct page *page,
1283 struct mdt_object *object = info->mti_object;
1284 struct lu_fid *lf = &info->mti_tmp_fid2;
1285 struct md_attr *ma = &info->mti_attr;
1286 struct lu_dirpage *dp;
1287 struct lu_dirent *ent;
1288 int rc = 0, offset = 0;
1291 /* Make sure we have at least one entry. */
1296 * Disable trans for this name insert, since it will include many trans
1299 info->mti_no_need_trans = 1;
1301 * When write_dir_page, no need update parent's ctime,
1302 * and no permission check for name_insert.
1304 ma->ma_attr.la_ctime = 0;
1305 ma->ma_attr.la_valid = LA_MODE;
1306 ma->ma_valid = MA_INODE;
1309 dp = page_address(page);
1310 offset = (int)((__u32)lu_dirent_start(dp) - (__u32)dp);
1312 for (ent = lu_dirent_start(dp); ent != NULL;
1313 ent = lu_dirent_next(ent)) {
1314 struct lu_name *lname;
1317 if (le16_to_cpu(ent->lde_namelen) == 0)
1320 fid_le_to_cpu(lf, &ent->lde_fid);
1321 if (le64_to_cpu(ent->lde_hash) & MAX_HASH_HIGHEST_BIT)
1322 ma->ma_attr.la_mode = S_IFDIR;
1324 ma->ma_attr.la_mode = 0;
1325 OBD_ALLOC(name, le16_to_cpu(ent->lde_namelen) + 1);
1327 GOTO(out, rc = -ENOMEM);
1329 memcpy(name, ent->lde_name, le16_to_cpu(ent->lde_namelen));
1330 lname = mdt_name(info->mti_env, name,
1331 le16_to_cpu(ent->lde_namelen));
1332 ma->ma_attr_flags |= (MDS_PERM_BYPASS | MDS_QUOTA_IGNORE);
1333 rc = mdo_name_insert(info->mti_env,
1334 md_object_next(&object->mot_obj),
1336 OBD_FREE(name, le16_to_cpu(ent->lde_namelen) + 1);
1338 CERROR("Can't insert %*.*s, rc %d\n",
1339 le16_to_cpu(ent->lde_namelen),
1340 le16_to_cpu(ent->lde_namelen),
1345 offset += lu_dirent_size(ent);
1355 static int mdt_bulk_timeout(void *data)
1359 CERROR("mdt bulk transfer timeout \n");
1364 static int mdt_writepage(struct mdt_thread_info *info)
1366 struct ptlrpc_request *req = mdt_info_req(info);
1367 struct mdt_body *reqbody;
1368 struct l_wait_info *lwi;
1369 struct ptlrpc_bulk_desc *desc;
1375 reqbody = req_capsule_client_get(info->mti_pill, &RMF_MDT_BODY);
1376 if (reqbody == NULL)
1377 RETURN(err_serious(-EFAULT));
1379 desc = ptlrpc_prep_bulk_exp(req, 1, BULK_GET_SINK, MDS_BULK_PORTAL);
1381 RETURN(err_serious(-ENOMEM));
1383 /* allocate the page for the desc */
1384 page = cfs_alloc_page(CFS_ALLOC_STD);
1386 GOTO(desc_cleanup, rc = -ENOMEM);
1388 CDEBUG(D_INFO, "Received page offset %d size %d \n",
1389 (int)reqbody->size, (int)reqbody->nlink);
1391 ptlrpc_prep_bulk_page(desc, page, (int)reqbody->size,
1392 (int)reqbody->nlink);
1394 rc = sptlrpc_svc_prep_bulk(req, desc);
1396 GOTO(cleanup_page, rc);
1398 * Check if client was evicted while we were doing i/o before touching
1403 GOTO(cleanup_page, rc = -ENOMEM);
1405 if (desc->bd_export->exp_failed)
1408 rc = ptlrpc_start_bulk_transfer (desc);
1410 *lwi = LWI_TIMEOUT_INTERVAL(obd_timeout * CFS_HZ / 4, CFS_HZ,
1411 mdt_bulk_timeout, desc);
1412 rc = l_wait_event(desc->bd_waitq, !ptlrpc_bulk_active(desc) ||
1413 desc->bd_export->exp_failed, lwi);
1414 LASSERT(rc == 0 || rc == -ETIMEDOUT);
1415 if (rc == -ETIMEDOUT) {
1416 DEBUG_REQ(D_ERROR, req, "timeout on bulk GET");
1417 ptlrpc_abort_bulk(desc);
1418 } else if (desc->bd_export->exp_failed) {
1419 DEBUG_REQ(D_ERROR, req, "Eviction on bulk GET");
1421 ptlrpc_abort_bulk(desc);
1422 } else if (!desc->bd_success ||
1423 desc->bd_nob_transferred != desc->bd_nob) {
1424 DEBUG_REQ(D_ERROR, req, "%s bulk GET %d(%d)",
1426 "truncated" : "network error on",
1427 desc->bd_nob_transferred, desc->bd_nob);
1428 /* XXX should this be a different errno? */
1432 DEBUG_REQ(D_ERROR, req, "ptlrpc_bulk_get failed: rc %d", rc);
1435 GOTO(cleanup_lwi, rc);
1436 rc = mdt_write_dir_page(info, page, reqbody->nlink);
1441 cfs_free_page(page);
1443 ptlrpc_free_bulk(desc);
1448 static int mdt_readpage(struct mdt_thread_info *info)
1450 struct mdt_object *object = info->mti_object;
1451 struct lu_rdpg *rdpg = &info->mti_u.rdpg.mti_rdpg;
1452 struct mdt_body *reqbody;
1453 struct mdt_body *repbody;
1458 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_READPAGE_PACK))
1459 RETURN(err_serious(-ENOMEM));
1461 reqbody = req_capsule_client_get(info->mti_pill, &RMF_MDT_BODY);
1462 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
1463 if (reqbody == NULL || repbody == NULL)
1464 RETURN(err_serious(-EFAULT));
1467 * prepare @rdpg before calling lower layers and transfer itself. Here
1468 * reqbody->size contains offset of where to start to read and
1469 * reqbody->nlink contains number bytes to read.
1471 rdpg->rp_hash = reqbody->size;
1472 if (rdpg->rp_hash != reqbody->size) {
1473 CERROR("Invalid hash: "LPX64" != "LPX64"\n",
1474 rdpg->rp_hash, reqbody->size);
1478 rdpg->rp_attrs = reqbody->mode;
1479 if (info->mti_exp->exp_connect_flags & OBD_CONNECT_64BITHASH)
1480 rdpg->rp_attrs |= LUDA_64BITHASH;
1481 rdpg->rp_count = min_t(unsigned int, reqbody->nlink,
1482 PTLRPC_MAX_BRW_SIZE);
1483 rdpg->rp_npages = (rdpg->rp_count + CFS_PAGE_SIZE - 1) >>
1485 OBD_ALLOC(rdpg->rp_pages, rdpg->rp_npages * sizeof rdpg->rp_pages[0]);
1486 if (rdpg->rp_pages == NULL)
1489 for (i = 0; i < rdpg->rp_npages; ++i) {
1490 rdpg->rp_pages[i] = cfs_alloc_page(CFS_ALLOC_STD);
1491 if (rdpg->rp_pages[i] == NULL)
1492 GOTO(free_rdpg, rc = -ENOMEM);
1495 /* call lower layers to fill allocated pages with directory data */
1496 rc = mo_readpage(info->mti_env, mdt_object_child(object), rdpg);
1498 GOTO(free_rdpg, rc);
1500 /* send pages to client */
1501 rc = mdt_sendpage(info, rdpg, rc);
1506 for (i = 0; i < rdpg->rp_npages; i++)
1507 if (rdpg->rp_pages[i] != NULL)
1508 cfs_free_page(rdpg->rp_pages[i]);
1509 OBD_FREE(rdpg->rp_pages, rdpg->rp_npages * sizeof rdpg->rp_pages[0]);
1511 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_SENDPAGE))
1517 static int mdt_reint_internal(struct mdt_thread_info *info,
1518 struct mdt_lock_handle *lhc,
1521 struct req_capsule *pill = info->mti_pill;
1522 struct mdt_device *mdt = info->mti_mdt;
1523 struct md_quota *mq = md_quota(info->mti_env);
1524 struct mdt_body *repbody;
1529 if (req_capsule_has_field(pill, &RMF_MDT_MD, RCL_SERVER))
1530 req_capsule_set_size(pill, &RMF_MDT_MD, RCL_SERVER,
1531 mdt->mdt_max_mdsize);
1532 if (req_capsule_has_field(pill, &RMF_LOGCOOKIES, RCL_SERVER))
1533 req_capsule_set_size(pill, &RMF_LOGCOOKIES, RCL_SERVER,
1534 mdt->mdt_max_cookiesize);
1536 rc = req_capsule_server_pack(pill);
1538 CERROR("Can't pack response, rc %d\n", rc);
1539 RETURN(err_serious(rc));
1542 if (req_capsule_has_field(pill, &RMF_MDT_BODY, RCL_SERVER)) {
1543 repbody = req_capsule_server_get(pill, &RMF_MDT_BODY);
1545 repbody->eadatasize = 0;
1546 repbody->aclsize = 0;
1549 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_REINT_UNPACK))
1550 GOTO(out_shrink, rc = err_serious(-EFAULT));
1552 rc = mdt_reint_unpack(info, op);
1554 CERROR("Can't unpack reint, rc %d\n", rc);
1555 GOTO(out_shrink, rc = err_serious(rc));
1558 OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_REINT_DELAY, 10);
1560 /* for replay no cookkie / lmm need, because client have this already */
1561 if (info->mti_spec.no_create == 1) {
1562 if (req_capsule_has_field(pill, &RMF_MDT_MD, RCL_SERVER))
1563 req_capsule_set_size(pill, &RMF_MDT_MD, RCL_SERVER, 0);
1565 if (req_capsule_has_field(pill, &RMF_LOGCOOKIES, RCL_SERVER))
1566 req_capsule_set_size(pill, &RMF_LOGCOOKIES, RCL_SERVER,
1570 rc = mdt_init_ucred_reint(info);
1572 GOTO(out_shrink, rc);
1574 rc = mdt_fix_attr_ucred(info, op);
1576 GOTO(out_ucred, rc = err_serious(rc));
1578 if (mdt_check_resent(info, mdt_reconstruct, lhc)) {
1579 rc = lustre_msg_get_status(mdt_info_req(info)->rq_repmsg);
1580 GOTO(out_ucred, rc);
1582 mq->mq_exp = info->mti_exp;
1583 rc = mdt_reint_rec(info, lhc);
1586 mdt_exit_ucred(info);
1588 mdt_client_compatibility(info);
1589 mdt_shrink_reply(info);
1593 static long mdt_reint_opcode(struct mdt_thread_info *info,
1594 const struct req_format **fmt)
1596 struct mdt_rec_reint *rec;
1599 opc = err_serious(-EFAULT);
1600 rec = req_capsule_client_get(info->mti_pill, &RMF_REC_REINT);
1602 opc = rec->rr_opcode;
1603 DEBUG_REQ(D_INODE, mdt_info_req(info), "reint opt = %ld", opc);
1604 if (opc < REINT_MAX && fmt[opc] != NULL)
1605 req_capsule_extend(info->mti_pill, fmt[opc]);
1607 CERROR("Unsupported opc: %ld\n", opc);
1608 opc = err_serious(opc);
1614 static int mdt_reint(struct mdt_thread_info *info)
1619 static const struct req_format *reint_fmts[REINT_MAX] = {
1620 [REINT_SETATTR] = &RQF_MDS_REINT_SETATTR,
1621 [REINT_CREATE] = &RQF_MDS_REINT_CREATE,
1622 [REINT_LINK] = &RQF_MDS_REINT_LINK,
1623 [REINT_UNLINK] = &RQF_MDS_REINT_UNLINK,
1624 [REINT_RENAME] = &RQF_MDS_REINT_RENAME,
1625 [REINT_OPEN] = &RQF_MDS_REINT_OPEN,
1626 [REINT_SETXATTR] = &RQF_MDS_REINT_SETXATTR
1631 opc = mdt_reint_opcode(info, reint_fmts);
1634 * No lock possible here from client to pass it to reint code
1637 rc = mdt_reint_internal(info, NULL, opc);
1642 info->mti_fail_id = OBD_FAIL_MDS_REINT_NET_REP;
1646 /* this should sync the whole device */
1647 static int mdt_device_sync(const struct lu_env *env, struct mdt_device *mdt)
1649 struct dt_device *dt = mdt->mdt_bottom;
1653 rc = dt->dd_ops->dt_sync(env, dt);
1657 /* this should sync this object */
1658 static int mdt_object_sync(struct mdt_thread_info *info)
1660 struct md_object *next;
1664 if (!mdt_object_exists(info->mti_object)) {
1665 CWARN("Non existing object "DFID"!\n",
1666 PFID(mdt_object_fid(info->mti_object)));
1669 next = mdt_object_child(info->mti_object);
1670 rc = mo_object_sync(info->mti_env, next);
1675 static int mdt_sync(struct mdt_thread_info *info)
1677 struct ptlrpc_request *req = mdt_info_req(info);
1678 struct req_capsule *pill = info->mti_pill;
1679 struct mdt_body *body;
1683 /* The fid may be zero, so we req_capsule_set manually */
1684 req_capsule_set(pill, &RQF_MDS_SYNC);
1686 body = req_capsule_client_get(pill, &RMF_MDT_BODY);
1688 RETURN(err_serious(-EINVAL));
1690 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_SYNC_PACK))
1691 RETURN(err_serious(-ENOMEM));
1693 if (fid_seq(&body->fid1) == 0) {
1694 /* sync the whole device */
1695 rc = req_capsule_server_pack(pill);
1697 rc = mdt_device_sync(info->mti_env, info->mti_mdt);
1699 rc = err_serious(rc);
1701 /* sync an object */
1702 rc = mdt_unpack_req_pack_rep(info, HABEO_CORPUS|HABEO_REFERO);
1704 rc = mdt_object_sync(info);
1706 struct md_object *next;
1707 const struct lu_fid *fid;
1708 struct lu_attr *la = &info->mti_attr.ma_attr;
1710 next = mdt_object_child(info->mti_object);
1711 info->mti_attr.ma_need = MA_INODE;
1712 info->mti_attr.ma_valid = 0;
1713 rc = mo_attr_get(info->mti_env, next,
1716 body = req_capsule_server_get(pill,
1718 fid = mdt_object_fid(info->mti_object);
1719 mdt_pack_attr2body(info, body, la, fid);
1723 rc = err_serious(rc);
1726 mdt_counter_incr(req->rq_export, LPROC_MDT_SYNC);
1731 #ifdef HAVE_QUOTA_SUPPORT
1732 static int mdt_quotacheck_handle(struct mdt_thread_info *info)
1734 struct obd_quotactl *oqctl;
1735 struct req_capsule *pill = info->mti_pill;
1736 struct obd_export *exp = info->mti_exp;
1737 struct md_quota *mq = md_quota(info->mti_env);
1738 struct md_device *next = info->mti_mdt->mdt_child;
1742 oqctl = req_capsule_client_get(pill, &RMF_OBD_QUOTACTL);
1746 /* remote client has no permission for quotacheck */
1747 if (unlikely(exp_connect_rmtclient(exp)))
1750 rc = req_capsule_server_pack(pill);
1755 rc = next->md_ops->mdo_quota.mqo_check(info->mti_env, next,
1760 static int mdt_quotactl_handle(struct mdt_thread_info *info)
1762 struct obd_quotactl *oqctl, *repoqc;
1763 struct req_capsule *pill = info->mti_pill;
1764 struct obd_export *exp = info->mti_exp;
1765 struct md_quota *mq = md_quota(info->mti_env);
1766 struct md_device *next = info->mti_mdt->mdt_child;
1767 const struct md_quota_operations *mqo = &next->md_ops->mdo_quota;
1771 oqctl = req_capsule_client_get(pill, &RMF_OBD_QUOTACTL);
1776 if (exp_connect_rmtclient(exp)) {
1777 struct ptlrpc_request *req = mdt_info_req(info);
1778 struct mdt_export_data *med = mdt_req2med(req);
1779 struct lustre_idmap_table *idmap = med->med_idmap;
1781 if (unlikely(oqctl->qc_cmd != Q_GETQUOTA &&
1782 oqctl->qc_cmd != Q_GETINFO))
1786 if (oqctl->qc_type == USRQUOTA)
1787 id = lustre_idmap_lookup_uid(NULL, idmap, 0,
1789 else if (oqctl->qc_type == GRPQUOTA)
1790 id = lustre_idmap_lookup_gid(NULL, idmap, 0,
1795 if (id == CFS_IDMAP_NOTFOUND) {
1796 CDEBUG(D_QUOTA, "no mapping for id %u\n",
1802 rc = req_capsule_server_pack(pill);
1806 repoqc = req_capsule_server_get(pill, &RMF_OBD_QUOTACTL);
1807 LASSERT(repoqc != NULL);
1810 switch (oqctl->qc_cmd) {
1812 rc = mqo->mqo_on(info->mti_env, next, oqctl->qc_type);
1815 rc = mqo->mqo_off(info->mti_env, next, oqctl->qc_type);
1818 rc = mqo->mqo_setinfo(info->mti_env, next, oqctl->qc_type, id,
1822 rc = mqo->mqo_getinfo(info->mti_env, next, oqctl->qc_type, id,
1826 rc = mqo->mqo_setquota(info->mti_env, next, oqctl->qc_type, id,
1830 rc = mqo->mqo_getquota(info->mti_env, next, oqctl->qc_type, id,
1834 rc = mqo->mqo_getoinfo(info->mti_env, next, oqctl->qc_type, id,
1838 rc = mqo->mqo_getoquota(info->mti_env, next, oqctl->qc_type, id,
1841 case LUSTRE_Q_INVALIDATE:
1842 rc = mqo->mqo_invalidate(info->mti_env, next, oqctl->qc_type);
1844 case LUSTRE_Q_FINVALIDATE:
1845 rc = mqo->mqo_finvalidate(info->mti_env, next, oqctl->qc_type);
1848 CERROR("unsupported mdt_quotactl command: %d\n",
1860 * OBD PING and other handlers.
1862 static int mdt_obd_ping(struct mdt_thread_info *info)
1867 req_capsule_set(info->mti_pill, &RQF_OBD_PING);
1869 rc = target_handle_ping(mdt_info_req(info));
1871 rc = err_serious(rc);
1875 static int mdt_obd_log_cancel(struct mdt_thread_info *info)
1877 return err_serious(-EOPNOTSUPP);
1880 static int mdt_obd_qc_callback(struct mdt_thread_info *info)
1882 return err_serious(-EOPNOTSUPP);
1890 /** clone llog ctxt from child (mdd)
1891 * This allows remote llog (replicator) access.
1892 * We can either pass all llog RPCs (eg mdt_llog_create) on to child where the
1893 * context was originally set up, or we can handle them directly.
1894 * I choose the latter, but that means I need any llog
1895 * contexts set up by child to be accessable by the mdt. So we clone the
1896 * context into our context list here.
1898 static int mdt_llog_ctxt_clone(const struct lu_env *env, struct mdt_device *mdt,
1901 struct md_device *next = mdt->mdt_child;
1902 struct llog_ctxt *ctxt;
1905 if (!llog_ctxt_null(mdt2obd_dev(mdt), idx))
1908 rc = next->md_ops->mdo_llog_ctxt_get(env, next, idx, (void **)&ctxt);
1909 if (rc || ctxt == NULL) {
1910 CERROR("Can't get mdd ctxt %d\n", rc);
1914 rc = llog_group_set_ctxt(&mdt2obd_dev(mdt)->obd_olg, ctxt, idx);
1916 CERROR("Can't set mdt ctxt %d\n", rc);
1921 static int mdt_llog_ctxt_unclone(const struct lu_env *env,
1922 struct mdt_device *mdt, int idx)
1924 struct llog_ctxt *ctxt;
1926 ctxt = llog_get_context(mdt2obd_dev(mdt), idx);
1929 /* Put once for the get we just did, and once for the clone */
1930 llog_ctxt_put(ctxt);
1931 llog_ctxt_put(ctxt);
1935 static int mdt_llog_create(struct mdt_thread_info *info)
1939 req_capsule_set(info->mti_pill, &RQF_LLOG_ORIGIN_HANDLE_CREATE);
1940 rc = llog_origin_handle_create(mdt_info_req(info));
1941 return (rc < 0 ? err_serious(rc) : rc);
1944 static int mdt_llog_destroy(struct mdt_thread_info *info)
1948 req_capsule_set(info->mti_pill, &RQF_LLOG_ORIGIN_HANDLE_DESTROY);
1949 rc = llog_origin_handle_destroy(mdt_info_req(info));
1950 return (rc < 0 ? err_serious(rc) : rc);
1953 static int mdt_llog_read_header(struct mdt_thread_info *info)
1957 req_capsule_set(info->mti_pill, &RQF_LLOG_ORIGIN_HANDLE_READ_HEADER);
1958 rc = llog_origin_handle_read_header(mdt_info_req(info));
1959 return (rc < 0 ? err_serious(rc) : rc);
1962 static int mdt_llog_next_block(struct mdt_thread_info *info)
1966 req_capsule_set(info->mti_pill, &RQF_LLOG_ORIGIN_HANDLE_NEXT_BLOCK);
1967 rc = llog_origin_handle_next_block(mdt_info_req(info));
1968 return (rc < 0 ? err_serious(rc) : rc);
1971 static int mdt_llog_prev_block(struct mdt_thread_info *info)
1975 req_capsule_set(info->mti_pill, &RQF_LLOG_ORIGIN_HANDLE_PREV_BLOCK);
1976 rc = llog_origin_handle_prev_block(mdt_info_req(info));
1977 return (rc < 0 ? err_serious(rc) : rc);
1984 static struct ldlm_callback_suite cbs = {
1985 .lcs_completion = ldlm_server_completion_ast,
1986 .lcs_blocking = ldlm_server_blocking_ast,
1990 static int mdt_enqueue(struct mdt_thread_info *info)
1992 struct ptlrpc_request *req;
1996 * info->mti_dlm_req already contains swapped and (if necessary)
1997 * converted dlm request.
1999 LASSERT(info->mti_dlm_req != NULL);
2001 req = mdt_info_req(info);
2002 rc = ldlm_handle_enqueue0(info->mti_mdt->mdt_namespace,
2003 req, info->mti_dlm_req, &cbs);
2004 info->mti_fail_id = OBD_FAIL_LDLM_REPLY;
2005 return rc ? err_serious(rc) : req->rq_status;
2008 static int mdt_convert(struct mdt_thread_info *info)
2011 struct ptlrpc_request *req;
2013 LASSERT(info->mti_dlm_req);
2014 req = mdt_info_req(info);
2015 rc = ldlm_handle_convert0(req, info->mti_dlm_req);
2016 return rc ? err_serious(rc) : req->rq_status;
2019 static int mdt_bl_callback(struct mdt_thread_info *info)
2021 CERROR("bl callbacks should not happen on MDS\n");
2023 return err_serious(-EOPNOTSUPP);
2026 static int mdt_cp_callback(struct mdt_thread_info *info)
2028 CERROR("cp callbacks should not happen on MDS\n");
2030 return err_serious(-EOPNOTSUPP);
2034 * sec context handlers
2036 static int mdt_sec_ctx_handle(struct mdt_thread_info *info)
2040 rc = mdt_handle_idmap(info);
2043 struct ptlrpc_request *req = mdt_info_req(info);
2046 opc = lustre_msg_get_opc(req->rq_reqmsg);
2047 if (opc == SEC_CTX_INIT || opc == SEC_CTX_INIT_CONT)
2048 sptlrpc_svc_ctx_invalidate(req);
2051 CFS_FAIL_TIMEOUT(OBD_FAIL_SEC_CTX_HDL_PAUSE, cfs_fail_val);
2056 static struct mdt_object *mdt_obj(struct lu_object *o)
2058 LASSERT(lu_device_is_mdt(o->lo_dev));
2059 return container_of0(o, struct mdt_object, mot_obj.mo_lu);
2062 struct mdt_object *mdt_object_find(const struct lu_env *env,
2063 struct mdt_device *d,
2064 const struct lu_fid *f,
2065 enum mdt_obj_exist check_exist)
2067 struct lu_object *o;
2068 struct mdt_object *m;
2071 CDEBUG(D_INFO, "Find object for "DFID"\n", PFID(f));
2072 o = lu_object_find(env, &d->mdt_md_dev.md_lu_dev, f, NULL);
2073 if (unlikely(IS_ERR(o)))
2074 RETURN((struct mdt_object *)o);
2078 if (check_exist == MDT_OBJ_MUST_EXIST && mdt_object_exists(m) == 0) {
2079 mdt_object_put(env, m);
2080 CERROR("%s: object "DFID" not found: rc = -2\n",
2081 mdt_obj_dev_name(m), PFID(f));
2082 RETURN(ERR_PTR(-ENOENT));
2088 * Asyncronous commit for mdt device.
2090 * Pass asynchonous commit call down the MDS stack.
2092 * \param env environment
2093 * \param mdt the mdt device
2095 static void mdt_device_commit_async(const struct lu_env *env,
2096 struct mdt_device *mdt)
2098 struct dt_device *dt = mdt->mdt_bottom;
2101 rc = dt->dd_ops->dt_commit_async(env, dt);
2102 if (unlikely(rc != 0))
2103 CWARN("async commit start failed with rc = %d", rc);
2107 * Mark the lock as "synchonous".
2109 * Mark the lock to deffer transaction commit to the unlock time.
2111 * \param lock the lock to mark as "synchonous"
2113 * \see mdt_is_lock_sync
2114 * \see mdt_save_lock
2116 static inline void mdt_set_lock_sync(struct ldlm_lock *lock)
2118 lock->l_ast_data = (void*)1;
2122 * Check whehter the lock "synchonous" or not.
2124 * \param lock the lock to check
2125 * \retval 1 the lock is "synchonous"
2126 * \retval 0 the lock isn't "synchronous"
2128 * \see mdt_set_lock_sync
2129 * \see mdt_save_lock
2131 static inline int mdt_is_lock_sync(struct ldlm_lock *lock)
2133 return lock->l_ast_data != NULL;
2137 * Blocking AST for mdt locks.
2139 * Starts transaction commit if in case of COS lock conflict or
2140 * deffers such a commit to the mdt_save_lock.
2142 * \param lock the lock which blocks a request or cancelling lock
2143 * \param desc unused
2144 * \param data unused
2145 * \param flag indicates whether this cancelling or blocking callback
2147 * \see ldlm_blocking_ast_nocheck
2149 int mdt_blocking_ast(struct ldlm_lock *lock, struct ldlm_lock_desc *desc,
2150 void *data, int flag)
2152 struct obd_device *obd = ldlm_lock_to_ns(lock)->ns_obd;
2153 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
2157 if (flag == LDLM_CB_CANCELING)
2159 lock_res_and_lock(lock);
2160 if (lock->l_blocking_ast != mdt_blocking_ast) {
2161 unlock_res_and_lock(lock);
2164 if (mdt_cos_is_enabled(mdt) &&
2165 lock->l_req_mode & (LCK_PW | LCK_EX) &&
2166 lock->l_blocking_lock != NULL &&
2167 lock->l_client_cookie != lock->l_blocking_lock->l_client_cookie) {
2168 mdt_set_lock_sync(lock);
2170 rc = ldlm_blocking_ast_nocheck(lock);
2172 /* There is no lock conflict if l_blocking_lock == NULL,
2173 * it indicates a blocking ast sent from ldlm_lock_decref_internal
2174 * when the last reference to a local lock was released */
2175 if (lock->l_req_mode == LCK_COS && lock->l_blocking_lock != NULL) {
2178 rc = lu_env_init(&env, LCT_MD_THREAD);
2179 if (unlikely(rc != 0))
2180 CWARN("lu_env initialization failed with rc = %d,"
2181 "cannot start asynchronous commit\n", rc);
2183 mdt_device_commit_async(&env, mdt);
2189 int mdt_object_lock(struct mdt_thread_info *info, struct mdt_object *o,
2190 struct mdt_lock_handle *lh, __u64 ibits, int locality)
2192 struct ldlm_namespace *ns = info->mti_mdt->mdt_namespace;
2193 ldlm_policy_data_t *policy = &info->mti_policy;
2194 struct ldlm_res_id *res_id = &info->mti_res_id;
2198 LASSERT(!lustre_handle_is_used(&lh->mlh_reg_lh));
2199 LASSERT(!lustre_handle_is_used(&lh->mlh_pdo_lh));
2200 LASSERT(lh->mlh_reg_mode != LCK_MINMODE);
2201 LASSERT(lh->mlh_type != MDT_NUL_LOCK);
2203 if (mdt_object_exists(o) < 0) {
2204 if (locality == MDT_CROSS_LOCK) {
2205 /* cross-ref object fix */
2206 ibits &= ~MDS_INODELOCK_UPDATE;
2207 ibits |= MDS_INODELOCK_LOOKUP;
2209 LASSERT(!(ibits & MDS_INODELOCK_UPDATE));
2210 LASSERT(ibits & MDS_INODELOCK_LOOKUP);
2212 /* No PDO lock on remote object */
2213 LASSERT(lh->mlh_type != MDT_PDO_LOCK);
2216 if (lh->mlh_type == MDT_PDO_LOCK) {
2217 /* check for exists after object is locked */
2218 if (mdt_object_exists(o) == 0) {
2219 /* Non-existent object shouldn't have PDO lock */
2222 /* Non-dir object shouldn't have PDO lock */
2223 if (!S_ISDIR(lu_object_attr(&o->mot_obj.mo_lu)))
2228 memset(policy, 0, sizeof(*policy));
2229 fid_build_reg_res_name(mdt_object_fid(o), res_id);
2232 * Take PDO lock on whole directory and build correct @res_id for lock
2233 * on part of directory.
2235 if (lh->mlh_pdo_hash != 0) {
2236 LASSERT(lh->mlh_type == MDT_PDO_LOCK);
2237 mdt_lock_pdo_mode(info, o, lh);
2238 if (lh->mlh_pdo_mode != LCK_NL) {
2240 * Do not use LDLM_FL_LOCAL_ONLY for parallel lock, it
2241 * is never going to be sent to client and we do not
2242 * want it slowed down due to possible cancels.
2244 policy->l_inodebits.bits = MDS_INODELOCK_UPDATE;
2245 rc = mdt_fid_lock(ns, &lh->mlh_pdo_lh, lh->mlh_pdo_mode,
2246 policy, res_id, LDLM_FL_ATOMIC_CB,
2247 &info->mti_exp->exp_handle.h_cookie);
2253 * Finish res_id initializing by name hash marking part of
2254 * directory which is taking modification.
2256 res_id->name[LUSTRE_RES_ID_HSH_OFF] = lh->mlh_pdo_hash;
2259 policy->l_inodebits.bits = ibits;
2262 * Use LDLM_FL_LOCAL_ONLY for this lock. We do not know yet if it is
2263 * going to be sent to client. If it is - mdt_intent_policy() path will
2264 * fix it up and turn FL_LOCAL flag off.
2266 rc = mdt_fid_lock(ns, &lh->mlh_reg_lh, lh->mlh_reg_mode, policy,
2267 res_id, LDLM_FL_LOCAL_ONLY | LDLM_FL_ATOMIC_CB,
2268 &info->mti_exp->exp_handle.h_cookie);
2270 mdt_object_unlock(info, o, lh, 1);
2271 else if (unlikely(OBD_FAIL_PRECHECK(OBD_FAIL_MDS_PDO_LOCK)) &&
2272 lh->mlh_pdo_hash != 0 &&
2273 (lh->mlh_reg_mode == LCK_PW || lh->mlh_reg_mode == LCK_EX)) {
2274 OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_PDO_LOCK, 15);
2281 * Save a lock within request object.
2283 * Keep the lock referenced until whether client ACK or transaction
2284 * commit happens or release the lock immediately depending on input
2285 * parameters. If COS is ON, a write lock is converted to COS lock
2288 * \param info thead info object
2289 * \param h lock handle
2290 * \param mode lock mode
2291 * \param decref force immediate lock releasing
2294 void mdt_save_lock(struct mdt_thread_info *info, struct lustre_handle *h,
2295 ldlm_mode_t mode, int decref)
2299 if (lustre_handle_is_used(h)) {
2300 if (decref || !info->mti_has_trans ||
2301 !(mode & (LCK_PW | LCK_EX))){
2302 mdt_fid_unlock(h, mode);
2304 struct mdt_device *mdt = info->mti_mdt;
2305 struct ldlm_lock *lock = ldlm_handle2lock(h);
2306 struct ptlrpc_request *req = mdt_info_req(info);
2309 LASSERTF(lock != NULL, "no lock for cookie "LPX64"\n",
2311 CDEBUG(D_HA, "request = %p reply state = %p"
2312 " transno = "LPD64"\n",
2313 req, req->rq_reply_state, req->rq_transno);
2314 if (mdt_cos_is_enabled(mdt)) {
2316 ldlm_lock_downgrade(lock, LCK_COS);
2319 ptlrpc_save_lock(req, h, mode, no_ack);
2320 if (mdt_is_lock_sync(lock)) {
2321 CDEBUG(D_HA, "found sync-lock,"
2322 " async commit started\n");
2323 mdt_device_commit_async(info->mti_env,
2326 LDLM_LOCK_PUT(lock);
2335 * Unlock mdt object.
2337 * Immeditely release the regular lock and the PDO lock or save the
2338 * lock in reqeuest and keep them referenced until client ACK or
2339 * transaction commit.
2341 * \param info thread info object
2342 * \param o mdt object
2343 * \param lh mdt lock handle referencing regular and PDO locks
2344 * \param decref force immediate lock releasing
2346 void mdt_object_unlock(struct mdt_thread_info *info, struct mdt_object *o,
2347 struct mdt_lock_handle *lh, int decref)
2351 mdt_save_lock(info, &lh->mlh_pdo_lh, lh->mlh_pdo_mode, decref);
2352 mdt_save_lock(info, &lh->mlh_reg_lh, lh->mlh_reg_mode, decref);
2357 struct mdt_object *mdt_object_find_lock(struct mdt_thread_info *info,
2358 const struct lu_fid *f,
2359 struct mdt_lock_handle *lh,
2361 enum mdt_obj_exist check_exist)
2363 struct mdt_object *o;
2365 o = mdt_object_find(info->mti_env, info->mti_mdt, f, check_exist);
2369 rc = mdt_object_lock(info, o, lh, ibits,
2372 mdt_object_put(info->mti_env, o);
2379 void mdt_object_unlock_put(struct mdt_thread_info * info,
2380 struct mdt_object * o,
2381 struct mdt_lock_handle *lh,
2384 mdt_object_unlock(info, o, lh, decref);
2385 mdt_object_put(info->mti_env, o);
2388 static struct mdt_handler *mdt_handler_find(__u32 opc,
2389 struct mdt_opc_slice *supported)
2391 struct mdt_opc_slice *s;
2392 struct mdt_handler *h;
2395 for (s = supported; s->mos_hs != NULL; s++) {
2396 if (s->mos_opc_start <= opc && opc < s->mos_opc_end) {
2397 h = s->mos_hs + (opc - s->mos_opc_start);
2398 if (likely(h->mh_opc != 0))
2399 LASSERTF(h->mh_opc == opc,
2400 "opcode mismatch %d != %d\n",
2403 h = NULL; /* unsupported opc */
2410 static int mdt_lock_resname_compat(struct mdt_device *m,
2411 struct ldlm_request *req)
2413 /* XXX something... later. */
2417 static int mdt_lock_reply_compat(struct mdt_device *m, struct ldlm_reply *rep)
2419 /* XXX something... later. */
2424 * Generic code handling requests that have struct mdt_body passed in:
2426 * - extract mdt_body from request and save it in @info, if present;
2428 * - create lu_object, corresponding to the fid in mdt_body, and save it in
2431 * - if HABEO_CORPUS flag is set for this request type check whether object
2432 * actually exists on storage (lu_object_exists()).
2435 static int mdt_body_unpack(struct mdt_thread_info *info, __u32 flags)
2437 const struct mdt_body *body;
2438 struct mdt_object *obj;
2439 const struct lu_env *env;
2440 struct req_capsule *pill;
2444 env = info->mti_env;
2445 pill = info->mti_pill;
2447 body = info->mti_body = req_capsule_client_get(pill, &RMF_MDT_BODY);
2451 if (!(body->valid & OBD_MD_FLID))
2454 if (!fid_is_sane(&body->fid1)) {
2455 CERROR("Invalid fid: "DFID"\n", PFID(&body->fid1));
2460 * Do not get size or any capa fields before we check that request
2461 * contains capa actually. There are some requests which do not, for
2462 * instance MDS_IS_SUBDIR.
2464 if (req_capsule_has_field(pill, &RMF_CAPA1, RCL_CLIENT) &&
2465 req_capsule_get_size(pill, &RMF_CAPA1, RCL_CLIENT))
2466 mdt_set_capainfo(info, 0, &body->fid1,
2467 req_capsule_client_get(pill, &RMF_CAPA1));
2469 obj = mdt_object_find(env, info->mti_mdt, &body->fid1,
2470 MDT_OBJ_MAY_NOT_EXIST);
2472 if ((flags & HABEO_CORPUS) &&
2473 mdt_object_exists(obj) == 0) {
2474 mdt_object_put(env, obj);
2475 /* for capability renew ENOENT will be handled in
2477 if (body->valid & OBD_MD_FLOSSCAPA)
2482 info->mti_object = obj;
2491 static int mdt_unpack_req_pack_rep(struct mdt_thread_info *info, __u32 flags)
2493 struct req_capsule *pill = info->mti_pill;
2497 if (req_capsule_has_field(pill, &RMF_MDT_BODY, RCL_CLIENT))
2498 rc = mdt_body_unpack(info, flags);
2502 if (rc == 0 && (flags & HABEO_REFERO)) {
2503 struct mdt_device *mdt = info->mti_mdt;
2507 if (req_capsule_has_field(pill, &RMF_MDT_MD, RCL_SERVER))
2508 req_capsule_set_size(pill, &RMF_MDT_MD, RCL_SERVER,
2509 mdt->mdt_max_mdsize);
2510 if (req_capsule_has_field(pill, &RMF_LOGCOOKIES, RCL_SERVER))
2511 req_capsule_set_size(pill, &RMF_LOGCOOKIES, RCL_SERVER,
2512 mdt->mdt_max_cookiesize);
2514 rc = req_capsule_server_pack(pill);
2519 static int mdt_init_capa_ctxt(const struct lu_env *env, struct mdt_device *m)
2521 struct md_device *next = m->mdt_child;
2523 return next->md_ops->mdo_init_capa_ctxt(env, next,
2524 m->mdt_opts.mo_mds_capa,
2525 m->mdt_capa_timeout,
2531 * Invoke handler for this request opc. Also do necessary preprocessing
2532 * (according to handler ->mh_flags), and post-processing (setting of
2533 * ->last_{xid,committed}).
2535 static int mdt_req_handle(struct mdt_thread_info *info,
2536 struct mdt_handler *h, struct ptlrpc_request *req)
2538 int rc, serious = 0;
2543 LASSERT(h->mh_act != NULL);
2544 LASSERT(h->mh_opc == lustre_msg_get_opc(req->rq_reqmsg));
2545 LASSERT(current->journal_info == NULL);
2548 * Checking for various OBD_FAIL_$PREF_$OPC_NET codes. _Do_ not try
2549 * to put same checks into handlers like mdt_close(), mdt_reint(),
2550 * etc., without talking to mdt authors first. Checking same thing
2551 * there again is useless and returning 0 error without packing reply
2552 * is buggy! Handlers either pack reply or return error.
2554 * We return 0 here and do not send any reply in order to emulate
2555 * network failure. Do not send any reply in case any of NET related
2556 * fail_id has occured.
2558 if (OBD_FAIL_CHECK_ORSET(h->mh_fail_id, OBD_FAIL_ONCE))
2562 flags = h->mh_flags;
2563 LASSERT(ergo(flags & (HABEO_CORPUS|HABEO_REFERO), h->mh_fmt != NULL));
2565 if (h->mh_fmt != NULL) {
2566 req_capsule_set(info->mti_pill, h->mh_fmt);
2567 rc = mdt_unpack_req_pack_rep(info, flags);
2570 if (rc == 0 && flags & MUTABOR &&
2571 req->rq_export->exp_connect_flags & OBD_CONNECT_RDONLY)
2572 /* should it be rq_status? */
2575 if (rc == 0 && flags & HABEO_CLAVIS) {
2576 struct ldlm_request *dlm_req;
2578 LASSERT(h->mh_fmt != NULL);
2580 dlm_req = req_capsule_client_get(info->mti_pill, &RMF_DLM_REQ);
2581 if (dlm_req != NULL) {
2582 if (unlikely(dlm_req->lock_desc.l_resource.lr_type ==
2584 dlm_req->lock_desc.l_policy_data.\
2585 l_inodebits.bits == 0)) {
2587 * Lock without inodebits makes no sense and
2588 * will oops later in ldlm. If client miss to
2589 * set such bits, do not trigger ASSERTION.
2591 * For liblustre flock case, it maybe zero.
2595 if (info->mti_mdt->mdt_opts.mo_compat_resname)
2596 rc = mdt_lock_resname_compat(
2599 info->mti_dlm_req = dlm_req;
2606 /* capability setting changed via /proc, needs reinitialize ctxt */
2607 if (info->mti_mdt && info->mti_mdt->mdt_capa_conf) {
2608 mdt_init_capa_ctxt(info->mti_env, info->mti_mdt);
2609 info->mti_mdt->mdt_capa_conf = 0;
2612 if (likely(rc == 0)) {
2614 * Process request, there can be two types of rc:
2615 * 1) errors with msg unpack/pack, other failures outside the
2616 * operation itself. This is counted as serious errors;
2617 * 2) errors during fs operation, should be placed in rq_status
2620 rc = h->mh_act(info);
2622 !req->rq_no_reply && req->rq_reply_state == NULL) {
2623 DEBUG_REQ(D_ERROR, req, "MDT \"handler\" %s did not "
2624 "pack reply and returned 0 error\n",
2628 serious = is_serious(rc);
2629 rc = clear_serious(rc);
2633 req->rq_status = rc;
2636 * ELDLM_* codes which > 0 should be in rq_status only as well as
2637 * all non-serious errors.
2639 if (rc > 0 || !serious)
2642 LASSERT(current->journal_info == NULL);
2644 if (rc == 0 && (flags & HABEO_CLAVIS) &&
2645 info->mti_mdt->mdt_opts.mo_compat_resname) {
2646 struct ldlm_reply *dlmrep;
2648 dlmrep = req_capsule_server_get(info->mti_pill, &RMF_DLM_REP);
2650 rc = mdt_lock_reply_compat(info->mti_mdt, dlmrep);
2653 /* If we're DISCONNECTing, the mdt_export_data is already freed */
2654 if (likely(rc == 0 && req->rq_export && h->mh_opc != MDS_DISCONNECT))
2655 target_committed_to_req(req);
2657 if (unlikely(req_is_replay(req) &&
2658 lustre_msg_get_transno(req->rq_reqmsg) == 0)) {
2659 DEBUG_REQ(D_ERROR, req, "transno is 0 during REPLAY");
2663 target_send_reply(req, rc, info->mti_fail_id);
2667 void mdt_lock_handle_init(struct mdt_lock_handle *lh)
2669 lh->mlh_type = MDT_NUL_LOCK;
2670 lh->mlh_reg_lh.cookie = 0ull;
2671 lh->mlh_reg_mode = LCK_MINMODE;
2672 lh->mlh_pdo_lh.cookie = 0ull;
2673 lh->mlh_pdo_mode = LCK_MINMODE;
2676 void mdt_lock_handle_fini(struct mdt_lock_handle *lh)
2678 LASSERT(!lustre_handle_is_used(&lh->mlh_reg_lh));
2679 LASSERT(!lustre_handle_is_used(&lh->mlh_pdo_lh));
2683 * Initialize fields of struct mdt_thread_info. Other fields are left in
2684 * uninitialized state, because it's too expensive to zero out whole
2685 * mdt_thread_info (> 1K) on each request arrival.
2687 static void mdt_thread_info_init(struct ptlrpc_request *req,
2688 struct mdt_thread_info *info)
2691 struct md_capainfo *ci;
2693 req_capsule_init(&req->rq_pill, req, RCL_SERVER);
2694 info->mti_pill = &req->rq_pill;
2697 for (i = 0; i < ARRAY_SIZE(info->mti_lh); i++)
2698 mdt_lock_handle_init(&info->mti_lh[i]);
2700 /* mdt device: it can be NULL while CONNECT */
2701 if (req->rq_export) {
2702 info->mti_mdt = mdt_dev(req->rq_export->exp_obd->obd_lu_dev);
2703 info->mti_exp = req->rq_export;
2705 info->mti_mdt = NULL;
2706 info->mti_env = req->rq_svc_thread->t_env;
2707 ci = md_capainfo(info->mti_env);
2708 memset(ci, 0, sizeof *ci);
2709 if (req->rq_export) {
2710 if (exp_connect_rmtclient(req->rq_export))
2711 ci->mc_auth = LC_ID_CONVERT;
2712 else if (req->rq_export->exp_connect_flags &
2713 OBD_CONNECT_MDS_CAPA)
2714 ci->mc_auth = LC_ID_PLAIN;
2716 ci->mc_auth = LC_ID_NONE;
2719 info->mti_fail_id = OBD_FAIL_MDS_ALL_REPLY_NET;
2720 info->mti_transno = lustre_msg_get_transno(req->rq_reqmsg);
2721 info->mti_mos = NULL;
2723 memset(&info->mti_attr, 0, sizeof(info->mti_attr));
2724 info->mti_body = NULL;
2725 info->mti_object = NULL;
2726 info->mti_dlm_req = NULL;
2727 info->mti_has_trans = 0;
2728 info->mti_no_need_trans = 0;
2729 info->mti_cross_ref = 0;
2730 info->mti_opdata = 0;
2732 /* To not check for split by default. */
2733 info->mti_spec.sp_ck_split = 0;
2734 info->mti_spec.no_create = 0;
2737 static void mdt_thread_info_fini(struct mdt_thread_info *info)
2741 req_capsule_fini(info->mti_pill);
2742 if (info->mti_object != NULL) {
2744 * freeing an object may lead to OSD level transaction, do not
2745 * let it mess with MDT. bz19385.
2747 info->mti_no_need_trans = 1;
2748 mdt_object_put(info->mti_env, info->mti_object);
2749 info->mti_object = NULL;
2751 for (i = 0; i < ARRAY_SIZE(info->mti_lh); i++)
2752 mdt_lock_handle_fini(&info->mti_lh[i]);
2753 info->mti_env = NULL;
2756 static int mdt_filter_recovery_request(struct ptlrpc_request *req,
2757 struct obd_device *obd, int *process)
2759 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
2760 case MDS_CONNECT: /* This will never get here, but for completeness. */
2761 case OST_CONNECT: /* This will never get here, but for completeness. */
2762 case MDS_DISCONNECT:
2763 case OST_DISCONNECT:
2768 case MDS_DONE_WRITING:
2769 case MDS_SYNC: /* used in unmounting */
2775 *process = target_queue_recovery_request(req, obd);
2779 DEBUG_REQ(D_ERROR, req, "not permitted during recovery");
2786 * Handle recovery. Return:
2787 * +1: continue request processing;
2788 * -ve: abort immediately with the given error code;
2789 * 0: send reply with error code in req->rq_status;
2791 static int mdt_recovery(struct mdt_thread_info *info)
2793 struct ptlrpc_request *req = mdt_info_req(info);
2794 struct obd_device *obd;
2798 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
2801 case SEC_CTX_INIT_CONT:
2807 rc = mdt_handle_idmap(info);
2816 if (unlikely(!class_connected_export(req->rq_export))) {
2817 CERROR("operation %d on unconnected MDS from %s\n",
2818 lustre_msg_get_opc(req->rq_reqmsg),
2819 libcfs_id2str(req->rq_peer));
2820 /* FIXME: For CMD cleanup, when mds_B stop, the req from
2821 * mds_A will get -ENOTCONN(especially for ping req),
2822 * which will cause that mds_A deactive timeout, then when
2823 * mds_A cleanup, the cleanup process will be suspended since
2824 * deactive timeout is not zero.
2826 req->rq_status = -ENOTCONN;
2827 target_send_reply(req, -ENOTCONN, info->mti_fail_id);
2831 /* sanity check: if the xid matches, the request must be marked as a
2832 * resent or replayed */
2833 if (req_xid_is_last(req)) {
2834 if (!(lustre_msg_get_flags(req->rq_reqmsg) &
2835 (MSG_RESENT | MSG_REPLAY))) {
2836 DEBUG_REQ(D_WARNING, req, "rq_xid "LPU64" matches last_xid, "
2837 "expected REPLAY or RESENT flag (%x)", req->rq_xid,
2838 lustre_msg_get_flags(req->rq_reqmsg));
2840 req->rq_status = -ENOTCONN;
2845 /* else: note the opposite is not always true; a RESENT req after a
2846 * failover will usually not match the last_xid, since it was likely
2847 * never committed. A REPLAYed request will almost never match the
2848 * last xid, however it could for a committed, but still retained,
2851 obd = req->rq_export->exp_obd;
2853 /* Check for aborted recovery... */
2854 if (unlikely(obd->obd_recovering)) {
2857 DEBUG_REQ(D_INFO, req, "Got new replay");
2858 rc = mdt_filter_recovery_request(req, obd, &should_process);
2859 if (rc != 0 || !should_process)
2861 else if (should_process < 0) {
2862 req->rq_status = should_process;
2863 rc = ptlrpc_error(req);
2870 static int mdt_msg_check_version(struct lustre_msg *msg)
2874 switch (lustre_msg_get_opc(msg)) {
2876 case MDS_DISCONNECT:
2879 case SEC_CTX_INIT_CONT:
2881 rc = lustre_msg_check_version(msg, LUSTRE_OBD_VERSION);
2883 CERROR("bad opc %u version %08x, expecting %08x\n",
2884 lustre_msg_get_opc(msg),
2885 lustre_msg_get_version(msg),
2886 LUSTRE_OBD_VERSION);
2890 case MDS_GETATTR_NAME:
2897 case MDS_DONE_WRITING:
2904 case MDS_QUOTACHECK:
2910 rc = lustre_msg_check_version(msg, LUSTRE_MDS_VERSION);
2912 CERROR("bad opc %u version %08x, expecting %08x\n",
2913 lustre_msg_get_opc(msg),
2914 lustre_msg_get_version(msg),
2915 LUSTRE_MDS_VERSION);
2919 case LDLM_BL_CALLBACK:
2920 case LDLM_CP_CALLBACK:
2921 rc = lustre_msg_check_version(msg, LUSTRE_DLM_VERSION);
2923 CERROR("bad opc %u version %08x, expecting %08x\n",
2924 lustre_msg_get_opc(msg),
2925 lustre_msg_get_version(msg),
2926 LUSTRE_DLM_VERSION);
2928 case OBD_LOG_CANCEL:
2929 case LLOG_ORIGIN_HANDLE_CREATE:
2930 case LLOG_ORIGIN_HANDLE_NEXT_BLOCK:
2931 case LLOG_ORIGIN_HANDLE_READ_HEADER:
2932 case LLOG_ORIGIN_HANDLE_CLOSE:
2933 case LLOG_ORIGIN_HANDLE_DESTROY:
2934 case LLOG_ORIGIN_HANDLE_PREV_BLOCK:
2936 rc = lustre_msg_check_version(msg, LUSTRE_LOG_VERSION);
2938 CERROR("bad opc %u version %08x, expecting %08x\n",
2939 lustre_msg_get_opc(msg),
2940 lustre_msg_get_version(msg),
2941 LUSTRE_LOG_VERSION);
2944 CERROR("MDS unknown opcode %d\n", lustre_msg_get_opc(msg));
2950 static int mdt_handle0(struct ptlrpc_request *req,
2951 struct mdt_thread_info *info,
2952 struct mdt_opc_slice *supported)
2954 struct mdt_handler *h;
2955 struct lustre_msg *msg;
2960 if (OBD_FAIL_CHECK_ORSET(OBD_FAIL_MDS_ALL_REQUEST_NET, OBD_FAIL_ONCE))
2963 LASSERT(current->journal_info == NULL);
2965 msg = req->rq_reqmsg;
2966 rc = mdt_msg_check_version(msg);
2967 if (likely(rc == 0)) {
2968 rc = mdt_recovery(info);
2969 if (likely(rc == +1)) {
2970 h = mdt_handler_find(lustre_msg_get_opc(msg),
2972 if (likely(h != NULL)) {
2973 rc = mdt_req_handle(info, h, req);
2975 CERROR("The unsupported opc: 0x%x\n",
2976 lustre_msg_get_opc(msg) );
2977 req->rq_status = -ENOTSUPP;
2978 rc = ptlrpc_error(req);
2983 CERROR(LUSTRE_MDT_NAME" drops mal-formed request\n");
2988 * MDT handler function called by ptlrpc service thread when request comes.
2990 * XXX common "target" functionality should be factored into separate module
2991 * shared by mdt, ost and stand-alone services like fld.
2993 static int mdt_handle_common(struct ptlrpc_request *req,
2994 struct mdt_opc_slice *supported)
2997 struct mdt_thread_info *info;
3001 env = req->rq_svc_thread->t_env;
3002 LASSERT(env != NULL);
3003 LASSERT(env->le_ses != NULL);
3004 LASSERT(env->le_ctx.lc_thread == req->rq_svc_thread);
3005 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
3006 LASSERT(info != NULL);
3008 mdt_thread_info_init(req, info);
3010 rc = mdt_handle0(req, info, supported);
3012 mdt_thread_info_fini(info);
3017 * This is called from recovery code as handler of _all_ RPC types, FLD and SEQ
3020 int mdt_recovery_handle(struct ptlrpc_request *req)
3025 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
3027 rc = mdt_handle_common(req, mdt_fld_handlers);
3030 rc = mdt_handle_common(req, mdt_seq_handlers);
3033 rc = mdt_handle_common(req, mdt_regular_handlers);
3040 static int mdt_regular_handle(struct ptlrpc_request *req)
3042 return mdt_handle_common(req, mdt_regular_handlers);
3045 static int mdt_readpage_handle(struct ptlrpc_request *req)
3047 return mdt_handle_common(req, mdt_readpage_handlers);
3050 static int mdt_xmds_handle(struct ptlrpc_request *req)
3052 return mdt_handle_common(req, mdt_xmds_handlers);
3055 static int mdt_mdsc_handle(struct ptlrpc_request *req)
3057 return mdt_handle_common(req, mdt_seq_handlers);
3060 static int mdt_mdss_handle(struct ptlrpc_request *req)
3062 return mdt_handle_common(req, mdt_seq_handlers);
3065 static int mdt_dtss_handle(struct ptlrpc_request *req)
3067 return mdt_handle_common(req, mdt_seq_handlers);
3070 static int mdt_fld_handle(struct ptlrpc_request *req)
3072 return mdt_handle_common(req, mdt_fld_handlers);
3088 static int mdt_intent_getattr(enum mdt_it_code opcode,
3089 struct mdt_thread_info *info,
3090 struct ldlm_lock **,
3092 static int mdt_intent_reint(enum mdt_it_code opcode,
3093 struct mdt_thread_info *info,
3094 struct ldlm_lock **,
3097 static struct mdt_it_flavor {
3098 const struct req_format *it_fmt;
3100 int (*it_act)(enum mdt_it_code ,
3101 struct mdt_thread_info *,
3102 struct ldlm_lock **,
3105 } mdt_it_flavor[] = {
3107 .it_fmt = &RQF_LDLM_INTENT,
3108 /*.it_flags = HABEO_REFERO,*/
3110 .it_act = mdt_intent_reint,
3111 .it_reint = REINT_OPEN
3114 .it_fmt = &RQF_LDLM_INTENT,
3115 .it_flags = MUTABOR,
3116 .it_act = mdt_intent_reint,
3117 .it_reint = REINT_OPEN
3120 .it_fmt = &RQF_LDLM_INTENT,
3121 .it_flags = MUTABOR,
3122 .it_act = mdt_intent_reint,
3123 .it_reint = REINT_CREATE
3125 [MDT_IT_GETATTR] = {
3126 .it_fmt = &RQF_LDLM_INTENT_GETATTR,
3127 .it_flags = HABEO_REFERO,
3128 .it_act = mdt_intent_getattr
3130 [MDT_IT_READDIR] = {
3136 .it_fmt = &RQF_LDLM_INTENT_GETATTR,
3137 .it_flags = HABEO_REFERO,
3138 .it_act = mdt_intent_getattr
3141 .it_fmt = &RQF_LDLM_INTENT_UNLINK,
3142 .it_flags = MUTABOR,
3144 .it_reint = REINT_UNLINK
3148 .it_flags = MUTABOR,
3151 [MDT_IT_GETXATTR] = {
3158 int mdt_intent_lock_replace(struct mdt_thread_info *info,
3159 struct ldlm_lock **lockp,
3160 struct ldlm_lock *new_lock,
3161 struct mdt_lock_handle *lh,
3164 struct ptlrpc_request *req = mdt_info_req(info);
3165 struct ldlm_lock *lock = *lockp;
3168 * Get new lock only for cases when possible resent did not find any
3171 if (new_lock == NULL)
3172 new_lock = ldlm_handle2lock_long(&lh->mlh_reg_lh, 0);
3174 if (new_lock == NULL && (flags & LDLM_FL_INTENT_ONLY)) {
3175 lh->mlh_reg_lh.cookie = 0;
3179 LASSERTF(new_lock != NULL,
3180 "lockh "LPX64"\n", lh->mlh_reg_lh.cookie);
3183 * If we've already given this lock to a client once, then we should
3184 * have no readers or writers. Otherwise, we should have one reader
3185 * _or_ writer ref (which will be zeroed below) before returning the
3188 if (new_lock->l_export == req->rq_export) {
3189 LASSERT(new_lock->l_readers + new_lock->l_writers == 0);
3191 LASSERT(new_lock->l_export == NULL);
3192 LASSERT(new_lock->l_readers + new_lock->l_writers == 1);
3197 if (new_lock->l_export == req->rq_export) {
3199 * Already gave this to the client, which means that we
3200 * reconstructed a reply.
3202 LASSERT(lustre_msg_get_flags(req->rq_reqmsg) &
3204 lh->mlh_reg_lh.cookie = 0;
3205 RETURN(ELDLM_LOCK_REPLACED);
3209 * Fixup the lock to be given to the client.
3211 lock_res_and_lock(new_lock);
3212 /* Zero new_lock->l_readers and new_lock->l_writers without triggering
3213 * possible blocking AST. */
3214 while (new_lock->l_readers > 0) {
3215 lu_ref_del(&new_lock->l_reference, "reader", new_lock);
3216 lu_ref_del(&new_lock->l_reference, "user", new_lock);
3217 new_lock->l_readers--;
3219 while (new_lock->l_writers > 0) {
3220 lu_ref_del(&new_lock->l_reference, "writer", new_lock);
3221 lu_ref_del(&new_lock->l_reference, "user", new_lock);
3222 new_lock->l_writers--;
3225 new_lock->l_export = class_export_lock_get(req->rq_export, new_lock);
3226 new_lock->l_blocking_ast = lock->l_blocking_ast;
3227 new_lock->l_completion_ast = lock->l_completion_ast;
3228 new_lock->l_remote_handle = lock->l_remote_handle;
3229 new_lock->l_flags &= ~LDLM_FL_LOCAL;
3231 unlock_res_and_lock(new_lock);
3233 cfs_hash_add(new_lock->l_export->exp_lock_hash,
3234 &new_lock->l_remote_handle,
3235 &new_lock->l_exp_hash);
3237 LDLM_LOCK_RELEASE(new_lock);
3238 lh->mlh_reg_lh.cookie = 0;
3240 RETURN(ELDLM_LOCK_REPLACED);
3243 static void mdt_intent_fixup_resent(struct mdt_thread_info *info,
3244 struct ldlm_lock *new_lock,
3245 struct ldlm_lock **old_lock,
3246 struct mdt_lock_handle *lh)
3248 struct ptlrpc_request *req = mdt_info_req(info);
3249 struct obd_export *exp = req->rq_export;
3250 struct lustre_handle remote_hdl;
3251 struct ldlm_request *dlmreq;
3252 struct ldlm_lock *lock;
3254 if (!(lustre_msg_get_flags(req->rq_reqmsg) & MSG_RESENT))
3257 dlmreq = req_capsule_client_get(info->mti_pill, &RMF_DLM_REQ);
3258 remote_hdl = dlmreq->lock_handle[0];
3260 lock = cfs_hash_lookup(exp->exp_lock_hash, &remote_hdl);
3262 if (lock != new_lock) {
3263 lh->mlh_reg_lh.cookie = lock->l_handle.h_cookie;
3264 lh->mlh_reg_mode = lock->l_granted_mode;
3266 LDLM_DEBUG(lock, "Restoring lock cookie");
3267 DEBUG_REQ(D_DLMTRACE, req,
3268 "restoring lock cookie "LPX64,
3269 lh->mlh_reg_lh.cookie);
3271 *old_lock = LDLM_LOCK_GET(lock);
3272 cfs_hash_put(exp->exp_lock_hash, &lock->l_exp_hash);
3276 cfs_hash_put(exp->exp_lock_hash, &lock->l_exp_hash);
3280 * If the xid matches, then we know this is a resent request, and allow
3281 * it. (It's probably an OPEN, for which we don't send a lock.
3283 if (req_xid_is_last(req))
3287 * This remote handle isn't enqueued, so we never received or processed
3288 * this request. Clear MSG_RESENT, because it can be handled like any
3289 * normal request now.
3291 lustre_msg_clear_flags(req->rq_reqmsg, MSG_RESENT);
3293 DEBUG_REQ(D_DLMTRACE, req, "no existing lock with rhandle "LPX64,
3297 static int mdt_intent_getattr(enum mdt_it_code opcode,
3298 struct mdt_thread_info *info,
3299 struct ldlm_lock **lockp,
3302 struct mdt_lock_handle *lhc = &info->mti_lh[MDT_LH_RMT];
3303 struct ldlm_lock *new_lock = NULL;
3305 struct ldlm_reply *ldlm_rep;
3306 struct ptlrpc_request *req;
3307 struct mdt_body *reqbody;
3308 struct mdt_body *repbody;
3312 reqbody = req_capsule_client_get(info->mti_pill, &RMF_MDT_BODY);
3315 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
3318 info->mti_spec.sp_ck_split = !!(reqbody->valid & OBD_MD_FLCKSPLIT);
3319 info->mti_cross_ref = !!(reqbody->valid & OBD_MD_FLCROSSREF);
3320 repbody->eadatasize = 0;
3321 repbody->aclsize = 0;
3325 child_bits = MDS_INODELOCK_LOOKUP;
3327 case MDT_IT_GETATTR:
3328 child_bits = MDS_INODELOCK_LOOKUP | MDS_INODELOCK_UPDATE;
3331 CERROR("Unhandled till now");
3332 GOTO(out_shrink, rc = -EINVAL);
3335 rc = mdt_init_ucred(info, reqbody);
3337 GOTO(out_shrink, rc);
3339 req = info->mti_pill->rc_req;
3340 ldlm_rep = req_capsule_server_get(info->mti_pill, &RMF_DLM_REP);
3341 mdt_set_disposition(info, ldlm_rep, DISP_IT_EXECD);
3343 /* Get lock from request for possible resent case. */
3344 mdt_intent_fixup_resent(info, *lockp, &new_lock, lhc);
3346 ldlm_rep->lock_policy_res2 =
3347 mdt_getattr_name_lock(info, lhc, child_bits, ldlm_rep);
3349 if (mdt_get_disposition(ldlm_rep, DISP_LOOKUP_NEG))
3350 ldlm_rep->lock_policy_res2 = 0;
3351 if (!mdt_get_disposition(ldlm_rep, DISP_LOOKUP_POS) ||
3352 ldlm_rep->lock_policy_res2) {
3353 lhc->mlh_reg_lh.cookie = 0ull;
3354 GOTO(out_ucred, rc = ELDLM_LOCK_ABORTED);
3357 rc = mdt_intent_lock_replace(info, lockp, new_lock, lhc, flags);
3360 mdt_exit_ucred(info);
3362 mdt_client_compatibility(info);
3363 mdt_shrink_reply(info);
3367 static int mdt_intent_reint(enum mdt_it_code opcode,
3368 struct mdt_thread_info *info,
3369 struct ldlm_lock **lockp,
3372 struct mdt_lock_handle *lhc = &info->mti_lh[MDT_LH_RMT];
3373 struct ldlm_reply *rep = NULL;
3377 static const struct req_format *intent_fmts[REINT_MAX] = {
3378 [REINT_CREATE] = &RQF_LDLM_INTENT_CREATE,
3379 [REINT_OPEN] = &RQF_LDLM_INTENT_OPEN
3384 opc = mdt_reint_opcode(info, intent_fmts);
3388 if (mdt_it_flavor[opcode].it_reint != opc) {
3389 CERROR("Reint code %ld doesn't match intent: %d\n",
3391 RETURN(err_serious(-EPROTO));
3394 /* Get lock from request for possible resent case. */
3395 mdt_intent_fixup_resent(info, *lockp, NULL, lhc);
3397 rc = mdt_reint_internal(info, lhc, opc);
3399 /* Check whether the reply has been packed successfully. */
3400 if (mdt_info_req(info)->rq_repmsg != NULL)
3401 rep = req_capsule_server_get(info->mti_pill, &RMF_DLM_REP);
3403 RETURN(err_serious(-EFAULT));
3405 /* MDC expects this in any case */
3407 mdt_set_disposition(info, rep, DISP_LOOKUP_EXECD);
3409 /* Cross-ref case, the lock should be returned to the client */
3410 if (rc == -EREMOTE) {
3411 LASSERT(lustre_handle_is_used(&lhc->mlh_reg_lh));
3412 rep->lock_policy_res2 = 0;
3413 rc = mdt_intent_lock_replace(info, lockp, NULL, lhc, flags);
3416 rep->lock_policy_res2 = clear_serious(rc);
3418 if (rep->lock_policy_res2 == -ENOENT &&
3419 mdt_get_disposition(rep, DISP_LOOKUP_NEG))
3420 rep->lock_policy_res2 = 0;
3422 if (rc == -ENOTCONN || rc == -ENODEV ||
3423 rc == -EOVERFLOW) { /**< if VBR failure then return error */
3425 * If it is the disconnect error (ENODEV & ENOCONN), the error
3426 * will be returned by rq_status, and client at ptlrpc layer
3427 * will detect this, then disconnect, reconnect the import
3428 * immediately, instead of impacting the following the rpc.
3430 lhc->mlh_reg_lh.cookie = 0ull;
3434 * For other cases, the error will be returned by intent.
3435 * and client will retrieve the result from intent.
3438 * FIXME: when open lock is finished, that should be
3441 if (lustre_handle_is_used(&lhc->mlh_reg_lh)) {
3442 LASSERTF(rc == 0, "Error occurred but lock handle "
3443 "is still in use\n");
3444 rep->lock_policy_res2 = 0;
3445 rc = mdt_intent_lock_replace(info, lockp, NULL, lhc, flags);
3448 lhc->mlh_reg_lh.cookie = 0ull;
3449 RETURN(ELDLM_LOCK_ABORTED);
3454 static int mdt_intent_code(long itcode)
3462 case IT_OPEN|IT_CREAT:
3469 rc = MDT_IT_READDIR;
3472 rc = MDT_IT_GETATTR;
3484 rc = MDT_IT_GETXATTR;
3487 CERROR("Unknown intent opcode: %ld\n", itcode);
3494 static int mdt_intent_opc(long itopc, struct mdt_thread_info *info,
3495 struct ldlm_lock **lockp, int flags)
3497 struct req_capsule *pill;
3498 struct mdt_it_flavor *flv;
3503 opc = mdt_intent_code(itopc);
3507 pill = info->mti_pill;
3508 flv = &mdt_it_flavor[opc];
3510 if (flv->it_fmt != NULL)
3511 req_capsule_extend(pill, flv->it_fmt);
3513 rc = mdt_unpack_req_pack_rep(info, flv->it_flags);
3515 struct ptlrpc_request *req = mdt_info_req(info);
3516 if (flv->it_flags & MUTABOR &&
3517 req->rq_export->exp_connect_flags & OBD_CONNECT_RDONLY)
3520 if (rc == 0 && flv->it_act != NULL) {
3521 /* execute policy */
3522 rc = flv->it_act(opc, info, lockp, flags);
3529 static int mdt_intent_policy(struct ldlm_namespace *ns,
3530 struct ldlm_lock **lockp, void *req_cookie,
3531 ldlm_mode_t mode, int flags, void *data)
3533 struct mdt_thread_info *info;
3534 struct ptlrpc_request *req = req_cookie;
3535 struct ldlm_intent *it;
3536 struct req_capsule *pill;
3541 LASSERT(req != NULL);
3543 info = lu_context_key_get(&req->rq_svc_thread->t_env->le_ctx,
3545 LASSERT(info != NULL);
3546 pill = info->mti_pill;
3547 LASSERT(pill->rc_req == req);
3549 if (req->rq_reqmsg->lm_bufcount > DLM_INTENT_IT_OFF) {
3550 req_capsule_extend(pill, &RQF_LDLM_INTENT);
3551 it = req_capsule_client_get(pill, &RMF_LDLM_INTENT);
3553 rc = mdt_intent_opc(it->opc, info, lockp, flags);
3557 /* Lock without inodebits makes no sense and will oops
3558 * later in ldlm. Let's check it now to see if we have
3559 * ibits corrupted somewhere in mdt_intent_opc().
3560 * The case for client miss to set ibits has been
3561 * processed by others. */
3562 LASSERT(ergo(info->mti_dlm_req->lock_desc.l_resource.\
3563 lr_type == LDLM_IBITS,
3564 info->mti_dlm_req->lock_desc.\
3565 l_policy_data.l_inodebits.bits != 0));
3567 rc = err_serious(-EFAULT);
3569 /* No intent was provided */
3570 LASSERT(pill->rc_fmt == &RQF_LDLM_ENQUEUE);
3571 rc = req_capsule_server_pack(pill);
3573 rc = err_serious(rc);
3578 static int mdt_seq_fini(const struct lu_env *env,
3579 struct mdt_device *m)
3581 struct md_site *ms = mdt_md_site(m);
3585 if (ms->ms_server_seq) {
3586 seq_server_fini(ms->ms_server_seq, env);
3587 OBD_FREE_PTR(ms->ms_server_seq);
3588 ms->ms_server_seq = NULL;
3591 if (ms->ms_control_seq) {
3592 seq_server_fini(ms->ms_control_seq, env);
3593 OBD_FREE_PTR(ms->ms_control_seq);
3594 ms->ms_control_seq = NULL;
3597 if (ms->ms_client_seq) {
3598 seq_client_fini(ms->ms_client_seq);
3599 OBD_FREE_PTR(ms->ms_client_seq);
3600 ms->ms_client_seq = NULL;
3607 static int mdt_seq_init(const struct lu_env *env,
3609 struct mdt_device *m)
3616 ms = mdt_md_site(m);
3619 * This is sequence-controller node. Init seq-controller server on local
3622 if (ms->ms_node_id == 0) {
3623 LASSERT(ms->ms_control_seq == NULL);
3625 OBD_ALLOC_PTR(ms->ms_control_seq);
3626 if (ms->ms_control_seq == NULL)
3629 rc = seq_server_init(ms->ms_control_seq,
3630 m->mdt_bottom, uuid,
3631 LUSTRE_SEQ_CONTROLLER,
3636 GOTO(out_seq_fini, rc);
3638 OBD_ALLOC_PTR(ms->ms_client_seq);
3639 if (ms->ms_client_seq == NULL)
3640 GOTO(out_seq_fini, rc = -ENOMEM);
3642 OBD_ALLOC(prefix, MAX_OBD_NAME + 5);
3643 if (prefix == NULL) {
3644 OBD_FREE_PTR(ms->ms_client_seq);
3645 GOTO(out_seq_fini, rc = -ENOMEM);
3648 snprintf(prefix, MAX_OBD_NAME + 5, "ctl-%s",
3652 * Init seq-controller client after seq-controller server is
3653 * ready. Pass ms->ms_control_seq to it for direct talking.
3655 rc = seq_client_init(ms->ms_client_seq, NULL,
3656 LUSTRE_SEQ_METADATA, prefix,
3657 ms->ms_control_seq);
3658 OBD_FREE(prefix, MAX_OBD_NAME + 5);
3661 GOTO(out_seq_fini, rc);
3664 /* Init seq-server on local MDT */
3665 LASSERT(ms->ms_server_seq == NULL);
3667 OBD_ALLOC_PTR(ms->ms_server_seq);
3668 if (ms->ms_server_seq == NULL)
3669 GOTO(out_seq_fini, rc = -ENOMEM);
3671 rc = seq_server_init(ms->ms_server_seq,
3672 m->mdt_bottom, uuid,
3677 GOTO(out_seq_fini, rc = -ENOMEM);
3679 /* Assign seq-controller client to local seq-server. */
3680 if (ms->ms_node_id == 0) {
3681 LASSERT(ms->ms_client_seq != NULL);
3683 rc = seq_server_set_cli(ms->ms_server_seq,
3691 mdt_seq_fini(env, m);
3696 * Init client sequence manager which is used by local MDS to talk to sequence
3697 * controller on remote node.
3699 static int mdt_seq_init_cli(const struct lu_env *env,
3700 struct mdt_device *m,
3701 struct lustre_cfg *cfg)
3703 struct md_site *ms = mdt_md_site(m);
3704 struct obd_device *mdc;
3705 struct obd_uuid *uuidp, *mdcuuidp;
3706 char *uuid_str, *mdc_uuid_str;
3709 struct mdt_thread_info *info;
3710 char *p, *index_string = lustre_cfg_string(cfg, 2);
3713 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
3714 uuidp = &info->mti_u.uuid[0];
3715 mdcuuidp = &info->mti_u.uuid[1];
3717 LASSERT(index_string);
3719 index = simple_strtol(index_string, &p, 10);
3721 CERROR("Invalid index in lustre_cgf, offset 2\n");
3725 /* check if this is adding the first MDC and controller is not yet
3727 if (index != 0 || ms->ms_client_seq)
3730 uuid_str = lustre_cfg_string(cfg, 1);
3731 mdc_uuid_str = lustre_cfg_string(cfg, 4);
3732 obd_str2uuid(uuidp, uuid_str);
3733 obd_str2uuid(mdcuuidp, mdc_uuid_str);
3735 mdc = class_find_client_obd(uuidp, LUSTRE_MDC_NAME, mdcuuidp);
3737 CERROR("can't find controller MDC by uuid %s\n",
3740 } else if (!mdc->obd_set_up) {
3741 CERROR("target %s not set up\n", mdc->obd_name);
3744 LASSERT(ms->ms_control_exp);
3745 OBD_ALLOC_PTR(ms->ms_client_seq);
3746 if (ms->ms_client_seq != NULL) {
3749 OBD_ALLOC(prefix, MAX_OBD_NAME + 5);
3753 snprintf(prefix, MAX_OBD_NAME + 5, "ctl-%s",
3756 rc = seq_client_init(ms->ms_client_seq,
3758 LUSTRE_SEQ_METADATA,
3760 OBD_FREE(prefix, MAX_OBD_NAME + 5);
3767 LASSERT(ms->ms_server_seq != NULL);
3768 rc = seq_server_set_cli(ms->ms_server_seq, ms->ms_client_seq,
3775 static void mdt_seq_fini_cli(struct mdt_device *m)
3781 ms = mdt_md_site(m);
3784 if (ms->ms_server_seq)
3785 seq_server_set_cli(ms->ms_server_seq,
3788 if (ms->ms_control_exp) {
3789 class_export_put(ms->ms_control_exp);
3790 ms->ms_control_exp = NULL;
3799 static int mdt_fld_fini(const struct lu_env *env,
3800 struct mdt_device *m)
3802 struct md_site *ms = mdt_md_site(m);
3805 if (ms && ms->ms_server_fld) {
3806 fld_server_fini(ms->ms_server_fld, env);
3807 OBD_FREE_PTR(ms->ms_server_fld);
3808 ms->ms_server_fld = NULL;
3814 static int mdt_fld_init(const struct lu_env *env,
3816 struct mdt_device *m)
3822 ms = mdt_md_site(m);
3824 OBD_ALLOC_PTR(ms->ms_server_fld);
3825 if (ms->ms_server_fld == NULL)
3826 RETURN(rc = -ENOMEM);
3828 rc = fld_server_init(ms->ms_server_fld,
3829 m->mdt_bottom, uuid,
3830 env, ms->ms_node_id);
3832 OBD_FREE_PTR(ms->ms_server_fld);
3833 ms->ms_server_fld = NULL;
3840 /* device init/fini methods */
3841 static void mdt_stop_ptlrpc_service(struct mdt_device *m)
3844 if (m->mdt_regular_service != NULL) {
3845 ptlrpc_unregister_service(m->mdt_regular_service);
3846 m->mdt_regular_service = NULL;
3848 if (m->mdt_readpage_service != NULL) {
3849 ptlrpc_unregister_service(m->mdt_readpage_service);
3850 m->mdt_readpage_service = NULL;
3852 if (m->mdt_xmds_service != NULL) {
3853 ptlrpc_unregister_service(m->mdt_xmds_service);
3854 m->mdt_xmds_service = NULL;
3856 if (m->mdt_setattr_service != NULL) {
3857 ptlrpc_unregister_service(m->mdt_setattr_service);
3858 m->mdt_setattr_service = NULL;
3860 if (m->mdt_mdsc_service != NULL) {
3861 ptlrpc_unregister_service(m->mdt_mdsc_service);
3862 m->mdt_mdsc_service = NULL;
3864 if (m->mdt_mdss_service != NULL) {
3865 ptlrpc_unregister_service(m->mdt_mdss_service);
3866 m->mdt_mdss_service = NULL;
3868 if (m->mdt_dtss_service != NULL) {
3869 ptlrpc_unregister_service(m->mdt_dtss_service);
3870 m->mdt_dtss_service = NULL;
3872 if (m->mdt_fld_service != NULL) {
3873 ptlrpc_unregister_service(m->mdt_fld_service);
3874 m->mdt_fld_service = NULL;
3879 static int mdt_start_ptlrpc_service(struct mdt_device *m)
3882 static struct ptlrpc_service_conf conf;
3883 cfs_proc_dir_entry_t *procfs_entry;
3886 procfs_entry = m->mdt_md_dev.md_lu_dev.ld_obd->obd_proc_entry;
3888 conf = (typeof(conf)) {
3889 .psc_nbufs = MDS_NBUFS,
3890 .psc_bufsize = MDS_BUFSIZE,
3891 .psc_max_req_size = MDS_MAXREQSIZE,
3892 .psc_max_reply_size = MDS_MAXREPSIZE,
3893 .psc_req_portal = MDS_REQUEST_PORTAL,
3894 .psc_rep_portal = MDC_REPLY_PORTAL,
3895 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
3897 * We'd like to have a mechanism to set this on a per-device
3898 * basis, but alas...
3900 .psc_min_threads = mdt_min_threads,
3901 .psc_max_threads = mdt_max_threads,
3902 .psc_ctx_tags = LCT_MD_THREAD
3905 m->mdt_ldlm_client = &m->mdt_md_dev.md_lu_dev.ld_obd->obd_ldlm_client;
3906 ptlrpc_init_client(LDLM_CB_REQUEST_PORTAL, LDLM_CB_REPLY_PORTAL,
3907 "mdt_ldlm_client", m->mdt_ldlm_client);
3909 m->mdt_regular_service =
3910 ptlrpc_init_svc_conf(&conf, mdt_regular_handle, LUSTRE_MDT_NAME,
3911 procfs_entry, target_print_req,
3913 if (m->mdt_regular_service == NULL)
3916 rc = ptlrpc_start_threads(m->mdt_regular_service);
3918 GOTO(err_mdt_svc, rc);
3921 * readpage service configuration. Parameters have to be adjusted,
3924 conf = (typeof(conf)) {
3925 .psc_nbufs = MDS_NBUFS,
3926 .psc_bufsize = MDS_BUFSIZE,
3927 .psc_max_req_size = MDS_MAXREQSIZE,
3928 .psc_max_reply_size = MDS_MAXREPSIZE,
3929 .psc_req_portal = MDS_READPAGE_PORTAL,
3930 .psc_rep_portal = MDC_REPLY_PORTAL,
3931 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
3932 .psc_min_threads = mdt_min_threads,
3933 .psc_max_threads = mdt_max_threads,
3934 .psc_ctx_tags = LCT_MD_THREAD
3936 m->mdt_readpage_service =
3937 ptlrpc_init_svc_conf(&conf, mdt_readpage_handle,
3938 LUSTRE_MDT_NAME "_readpage",
3939 procfs_entry, target_print_req,"mdt_rdpg");
3941 if (m->mdt_readpage_service == NULL) {
3942 CERROR("failed to start readpage service\n");
3943 GOTO(err_mdt_svc, rc = -ENOMEM);
3946 rc = ptlrpc_start_threads(m->mdt_readpage_service);
3949 * setattr service configuration.
3951 * XXX To keep the compatibility with old client(< 2.2), we need to
3952 * preserve this portal for a certain time, it should be removed
3953 * eventually. LU-617.
3955 conf = (typeof(conf)) {
3956 .psc_nbufs = MDS_NBUFS,
3957 .psc_bufsize = MDS_BUFSIZE,
3958 .psc_max_req_size = MDS_MAXREQSIZE,
3959 .psc_max_reply_size = MDS_MAXREPSIZE,
3960 .psc_req_portal = MDS_SETATTR_PORTAL,
3961 .psc_rep_portal = MDC_REPLY_PORTAL,
3962 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
3963 .psc_min_threads = mdt_min_threads,
3964 .psc_max_threads = mdt_max_threads,
3965 .psc_ctx_tags = LCT_MD_THREAD
3968 m->mdt_setattr_service =
3969 ptlrpc_init_svc_conf(&conf, mdt_regular_handle,
3970 LUSTRE_MDT_NAME "_setattr",
3971 procfs_entry, target_print_req,"mdt_attr");
3973 if (!m->mdt_setattr_service) {
3974 CERROR("failed to start setattr service\n");
3975 GOTO(err_mdt_svc, rc = -ENOMEM);
3978 rc = ptlrpc_start_threads(m->mdt_setattr_service);
3980 GOTO(err_mdt_svc, rc);
3983 * sequence controller service configuration
3985 conf = (typeof(conf)) {
3986 .psc_nbufs = MDS_NBUFS,
3987 .psc_bufsize = MDS_BUFSIZE,
3988 .psc_max_req_size = SEQ_MAXREQSIZE,
3989 .psc_max_reply_size = SEQ_MAXREPSIZE,
3990 .psc_req_portal = SEQ_CONTROLLER_PORTAL,
3991 .psc_rep_portal = MDC_REPLY_PORTAL,
3992 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
3993 .psc_min_threads = mdt_min_threads,
3994 .psc_max_threads = mdt_max_threads,
3995 .psc_ctx_tags = LCT_MD_THREAD|LCT_DT_THREAD
3998 m->mdt_mdsc_service =
3999 ptlrpc_init_svc_conf(&conf, mdt_mdsc_handle,
4000 LUSTRE_MDT_NAME"_mdsc",
4001 procfs_entry, target_print_req,"mdt_mdsc");
4002 if (!m->mdt_mdsc_service) {
4003 CERROR("failed to start seq controller service\n");
4004 GOTO(err_mdt_svc, rc = -ENOMEM);
4007 rc = ptlrpc_start_threads(m->mdt_mdsc_service);
4009 GOTO(err_mdt_svc, rc);
4012 * metadata sequence server service configuration
4014 conf = (typeof(conf)) {
4015 .psc_nbufs = MDS_NBUFS,
4016 .psc_bufsize = MDS_BUFSIZE,
4017 .psc_max_req_size = SEQ_MAXREQSIZE,
4018 .psc_max_reply_size = SEQ_MAXREPSIZE,
4019 .psc_req_portal = SEQ_METADATA_PORTAL,
4020 .psc_rep_portal = MDC_REPLY_PORTAL,
4021 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
4022 .psc_min_threads = mdt_min_threads,
4023 .psc_max_threads = mdt_max_threads,
4024 .psc_ctx_tags = LCT_MD_THREAD|LCT_DT_THREAD
4027 m->mdt_mdss_service =
4028 ptlrpc_init_svc_conf(&conf, mdt_mdss_handle,
4029 LUSTRE_MDT_NAME"_mdss",
4030 procfs_entry, target_print_req,"mdt_mdss");
4031 if (!m->mdt_mdss_service) {
4032 CERROR("failed to start metadata seq server service\n");
4033 GOTO(err_mdt_svc, rc = -ENOMEM);
4036 rc = ptlrpc_start_threads(m->mdt_mdss_service);
4038 GOTO(err_mdt_svc, rc);
4042 * Data sequence server service configuration. We want to have really
4043 * cluster-wide sequences space. This is why we start only one sequence
4044 * controller which manages space.
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_DATA_PORTAL,
4052 .psc_rep_portal = OSC_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_dtss_service =
4060 ptlrpc_init_svc_conf(&conf, mdt_dtss_handle,
4061 LUSTRE_MDT_NAME"_dtss",
4062 procfs_entry, target_print_req,"mdt_dtss");
4063 if (!m->mdt_dtss_service) {
4064 CERROR("failed to start data seq server service\n");
4065 GOTO(err_mdt_svc, rc = -ENOMEM);
4068 rc = ptlrpc_start_threads(m->mdt_dtss_service);
4070 GOTO(err_mdt_svc, rc);
4072 /* FLD service start */
4073 conf = (typeof(conf)) {
4074 .psc_nbufs = MDS_NBUFS,
4075 .psc_bufsize = MDS_BUFSIZE,
4076 .psc_max_req_size = FLD_MAXREQSIZE,
4077 .psc_max_reply_size = FLD_MAXREPSIZE,
4078 .psc_req_portal = FLD_REQUEST_PORTAL,
4079 .psc_rep_portal = MDC_REPLY_PORTAL,
4080 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
4081 .psc_min_threads = mdt_min_threads,
4082 .psc_max_threads = mdt_max_threads,
4083 .psc_ctx_tags = LCT_DT_THREAD|LCT_MD_THREAD
4086 m->mdt_fld_service =
4087 ptlrpc_init_svc_conf(&conf, mdt_fld_handle,
4088 LUSTRE_MDT_NAME"_fld",
4089 procfs_entry, target_print_req, "mdt_fld");
4090 if (!m->mdt_fld_service) {
4091 CERROR("failed to start fld service\n");
4092 GOTO(err_mdt_svc, rc = -ENOMEM);
4095 rc = ptlrpc_start_threads(m->mdt_fld_service);
4097 GOTO(err_mdt_svc, rc);
4100 * mds-mds service configuration. Separate portal is used to allow
4101 * mds-mds requests be not blocked during recovery.
4103 conf = (typeof(conf)) {
4104 .psc_nbufs = MDS_NBUFS,
4105 .psc_bufsize = MDS_BUFSIZE,
4106 .psc_max_req_size = MDS_MAXREQSIZE,
4107 .psc_max_reply_size = MDS_MAXREPSIZE,
4108 .psc_req_portal = MDS_MDS_PORTAL,
4109 .psc_rep_portal = MDC_REPLY_PORTAL,
4110 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
4111 .psc_min_threads = mdt_min_threads,
4112 .psc_max_threads = mdt_max_threads,
4113 .psc_ctx_tags = LCT_MD_THREAD
4115 m->mdt_xmds_service =
4116 ptlrpc_init_svc_conf(&conf, mdt_xmds_handle,
4117 LUSTRE_MDT_NAME "_mds",
4118 procfs_entry, target_print_req,"mdt_xmds");
4120 if (m->mdt_xmds_service == NULL) {
4121 CERROR("failed to start xmds service\n");
4122 GOTO(err_mdt_svc, rc = -ENOMEM);
4125 rc = ptlrpc_start_threads(m->mdt_xmds_service);
4127 GOTO(err_mdt_svc, rc);
4132 mdt_stop_ptlrpc_service(m);
4137 static void mdt_stack_fini(const struct lu_env *env,
4138 struct mdt_device *m, struct lu_device *top)
4140 struct obd_device *obd = mdt2obd_dev(m);
4141 struct lustre_cfg_bufs *bufs;
4142 struct lustre_cfg *lcfg;
4143 struct mdt_thread_info *info;
4147 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
4148 LASSERT(info != NULL);
4150 bufs = &info->mti_u.bufs;
4151 /* process cleanup, pass mdt obd name to get obd umount flags */
4152 lustre_cfg_bufs_reset(bufs, obd->obd_name);
4157 lustre_cfg_bufs_set_string(bufs, 1, flags);
4158 lcfg = lustre_cfg_new(LCFG_CLEANUP, bufs);
4160 CERROR("Cannot alloc lcfg!\n");
4165 top->ld_ops->ldo_process_config(env, top, lcfg);
4166 lustre_cfg_free(lcfg);
4168 lu_stack_fini(env, top);
4169 m->mdt_child = NULL;
4170 m->mdt_bottom = NULL;
4173 static struct lu_device *mdt_layer_setup(struct lu_env *env,
4174 const char *typename,
4175 struct lu_device *child,
4176 struct lustre_cfg *cfg)
4178 const char *dev = lustre_cfg_string(cfg, 0);
4179 struct obd_type *type;
4180 struct lu_device_type *ldt;
4181 struct lu_device *d;
4186 type = class_get_type(typename);
4188 CERROR("Unknown type: '%s'\n", typename);
4189 GOTO(out, rc = -ENODEV);
4192 rc = lu_env_refill((struct lu_env *)env);
4194 CERROR("Failure to refill session: '%d'\n", rc);
4200 CERROR("type: '%s'\n", typename);
4201 GOTO(out_type, rc = -EINVAL);
4204 ldt->ldt_obd_type = type;
4205 d = ldt->ldt_ops->ldto_device_alloc(env, ldt, cfg);
4207 CERROR("Cannot allocate device: '%s'\n", typename);
4208 GOTO(out_type, rc = -ENODEV);
4211 LASSERT(child->ld_site);
4212 d->ld_site = child->ld_site;
4215 rc = ldt->ldt_ops->ldto_device_init(env, d, dev, child);
4217 CERROR("can't init device '%s', rc %d\n", typename, rc);
4218 GOTO(out_alloc, rc);
4221 lu_ref_add(&d->ld_reference, "lu-stack", &lu_site_init);
4223 cfs_spin_lock(&d->ld_site->ls_ld_lock);
4224 cfs_list_add_tail(&d->ld_linkage, &d->ld_site->ls_ld_linkage);
4225 cfs_spin_unlock(&d->ld_site->ls_ld_lock);
4229 ldt->ldt_ops->ldto_device_free(env, d);
4232 class_put_type(type);
4237 static int mdt_stack_init(struct lu_env *env,
4238 struct mdt_device *m,
4239 struct lustre_cfg *cfg,
4240 struct lustre_mount_info *lmi)
4242 struct lu_device *d = &m->mdt_md_dev.md_lu_dev;
4243 struct lu_device *tmp;
4244 struct md_device *md;
4245 struct lu_device *child_lu_dev;
4249 /* init the stack */
4250 tmp = mdt_layer_setup(env, LUSTRE_OSD_NAME, d, cfg);
4252 RETURN(PTR_ERR(tmp));
4254 m->mdt_bottom = lu2dt_dev(tmp);
4256 tmp = mdt_layer_setup(env, LUSTRE_MDD_NAME, d, cfg);
4258 GOTO(out, rc = PTR_ERR(tmp));
4263 tmp = mdt_layer_setup(env, LUSTRE_CMM_NAME, d, cfg);
4265 GOTO(out, rc = PTR_ERR(tmp));
4268 /*set mdd upcall device*/
4269 md_upcall_dev_set(md, lu2md_dev(d));
4272 /*set cmm upcall device*/
4273 md_upcall_dev_set(md, &m->mdt_md_dev);
4275 m->mdt_child = lu2md_dev(d);
4277 /* process setup config */
4278 tmp = &m->mdt_md_dev.md_lu_dev;
4279 rc = tmp->ld_ops->ldo_process_config(env, tmp, cfg);
4283 /* initialize local objects */
4284 child_lu_dev = &m->mdt_child->md_lu_dev;
4286 rc = child_lu_dev->ld_ops->ldo_prepare(env,
4287 &m->mdt_md_dev.md_lu_dev,
4290 /* fini from last known good lu_device */
4292 mdt_stack_fini(env, m, d);
4298 * setup CONFIG_ORIG context, used to access local config log.
4299 * this may need to be rewrite as part of llog rewrite for lu-api.
4301 static int mdt_obd_llog_setup(struct obd_device *obd,
4302 struct lustre_sb_info *lsi)
4306 LASSERT(obd->obd_fsops == NULL);
4308 obd->obd_fsops = fsfilt_get_ops(MT_STR(lsi->lsi_ldd));
4309 if (IS_ERR(obd->obd_fsops))
4310 return PTR_ERR(obd->obd_fsops);
4312 rc = fsfilt_setup(obd, lsi->lsi_srv_mnt->mnt_sb);
4314 fsfilt_put_ops(obd->obd_fsops);
4318 OBD_SET_CTXT_MAGIC(&obd->obd_lvfs_ctxt);
4319 obd->obd_lvfs_ctxt.pwdmnt = lsi->lsi_srv_mnt;
4320 obd->obd_lvfs_ctxt.pwd = lsi->lsi_srv_mnt->mnt_root;
4321 obd->obd_lvfs_ctxt.fs = get_ds();
4323 rc = llog_setup(obd, &obd->obd_olg, LLOG_CONFIG_ORIG_CTXT, obd,
4324 0, NULL, &llog_lvfs_ops);
4326 CERROR("llog_setup() failed: %d\n", rc);
4327 fsfilt_put_ops(obd->obd_fsops);
4333 static void mdt_obd_llog_cleanup(struct obd_device *obd)
4335 struct llog_ctxt *ctxt;
4337 ctxt = llog_get_context(obd, LLOG_CONFIG_ORIG_CTXT);
4341 if (obd->obd_fsops) {
4342 fsfilt_put_ops(obd->obd_fsops);
4343 obd->obd_fsops = NULL;
4347 static void mdt_fini(const struct lu_env *env, struct mdt_device *m)
4349 struct md_device *next = m->mdt_child;
4350 struct lu_device *d = &m->mdt_md_dev.md_lu_dev;
4351 struct lu_site *ls = d->ld_site;
4352 struct obd_device *obd = mdt2obd_dev(m);
4355 target_recovery_fini(obd);
4357 ping_evictor_stop();
4359 mdt_stop_ptlrpc_service(m);
4360 mdt_llog_ctxt_unclone(env, m, LLOG_CHANGELOG_ORIG_CTXT);
4361 mdt_obd_llog_cleanup(obd);
4362 obd_exports_barrier(obd);
4363 obd_zombie_barrier();
4367 #ifdef HAVE_QUOTA_SUPPORT
4368 next->md_ops->mdo_quota.mqo_cleanup(env, next);
4370 lut_fini(env, &m->mdt_lut);
4371 mdt_fs_cleanup(env, m);
4372 upcall_cache_cleanup(m->mdt_identity_cache);
4373 m->mdt_identity_cache = NULL;
4375 if (m->mdt_namespace != NULL) {
4376 ldlm_namespace_free(m->mdt_namespace, NULL,
4377 d->ld_obd->obd_force);
4378 d->ld_obd->obd_namespace = m->mdt_namespace = NULL;
4381 cfs_free_nidlist(&m->mdt_nosquash_nids);
4382 if (m->mdt_nosquash_str) {
4383 OBD_FREE(m->mdt_nosquash_str, m->mdt_nosquash_strlen);
4384 m->mdt_nosquash_str = NULL;
4385 m->mdt_nosquash_strlen = 0;
4388 mdt_seq_fini(env, m);
4389 mdt_seq_fini_cli(m);
4390 mdt_fld_fini(env, m);
4391 sptlrpc_rule_set_free(&m->mdt_sptlrpc_rset);
4393 next->md_ops->mdo_init_capa_ctxt(env, next, 0, 0, 0, NULL);
4394 cfs_timer_disarm(&m->mdt_ck_timer);
4395 mdt_ck_thread_stop(m);
4400 mdt_stack_fini(env, m, md2lu_dev(m->mdt_child));
4403 struct md_site *mite;
4406 mite = lu_site2md(ls);
4410 LASSERT(cfs_atomic_read(&d->ld_ref) == 0);
4415 static int mdt_adapt_sptlrpc_conf(struct obd_device *obd, int initial)
4417 struct mdt_device *m = mdt_dev(obd->obd_lu_dev);
4418 struct sptlrpc_rule_set tmp_rset;
4421 sptlrpc_rule_set_init(&tmp_rset);
4422 rc = sptlrpc_conf_target_get_rules(obd, &tmp_rset, initial);
4424 CERROR("mdt %s: failed get sptlrpc rules: %d\n",
4429 sptlrpc_target_update_exp_flavor(obd, &tmp_rset);
4431 cfs_write_lock(&m->mdt_sptlrpc_lock);
4432 sptlrpc_rule_set_free(&m->mdt_sptlrpc_rset);
4433 m->mdt_sptlrpc_rset = tmp_rset;
4434 cfs_write_unlock(&m->mdt_sptlrpc_lock);
4439 int mdt_postrecov(const struct lu_env *, struct mdt_device *);
4441 static int mdt_init0(const struct lu_env *env, struct mdt_device *m,
4442 struct lu_device_type *ldt, struct lustre_cfg *cfg)
4444 struct mdt_thread_info *info;
4445 struct obd_device *obd;
4446 const char *dev = lustre_cfg_string(cfg, 0);
4447 const char *num = lustre_cfg_string(cfg, 2);
4448 struct lustre_mount_info *lmi = NULL;
4449 struct lustre_sb_info *lsi;
4450 struct lustre_disk_data *ldd;
4452 struct md_site *mite;
4453 const char *identity_upcall = "NONE";
4454 struct md_device *next;
4460 md_device_init(&m->mdt_md_dev, ldt);
4462 * Environment (env) might be missing mdt_thread_key values at that
4463 * point, if device is allocated when mdt_thread_key is in QUIESCENT
4466 * Usually device allocation path doesn't use module key values, but
4467 * mdt has to do a lot of work here, so allocate key value.
4469 rc = lu_env_refill((struct lu_env *)env);
4473 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
4474 LASSERT(info != NULL);
4476 obd = class_name2obd(dev);
4477 LASSERT(obd != NULL);
4479 m->mdt_max_mdsize = MAX_MD_SIZE;
4480 m->mdt_max_cookiesize = sizeof(struct llog_cookie);
4481 m->mdt_som_conf = 0;
4483 m->mdt_opts.mo_cos = MDT_COS_DEFAULT;
4484 lmi = server_get_mount_2(dev);
4486 CERROR("Cannot get mount info for %s!\n", dev);
4489 lsi = s2lsi(lmi->lmi_sb);
4490 /* CMD is supported only in IAM mode */
4493 node_id = simple_strtol(num, NULL, 10);
4494 if (!(ldd->ldd_flags & LDD_F_IAM_DIR) && node_id) {
4495 CERROR("CMD Operation not allowed in IOP mode\n");
4496 GOTO(err_lmi, rc = -EINVAL);
4499 obd->u.obt.obt_magic = OBT_MAGIC;
4502 cfs_rwlock_init(&m->mdt_sptlrpc_lock);
4503 sptlrpc_rule_set_init(&m->mdt_sptlrpc_rset);
4505 cfs_spin_lock_init(&m->mdt_ioepoch_lock);
4506 m->mdt_opts.mo_compat_resname = 0;
4507 m->mdt_opts.mo_mds_capa = 1;
4508 m->mdt_opts.mo_oss_capa = 1;
4509 m->mdt_capa_timeout = CAPA_TIMEOUT;
4510 m->mdt_capa_alg = CAPA_HMAC_ALG_SHA1;
4511 m->mdt_ck_timeout = CAPA_KEY_TIMEOUT;
4512 m->mdt_squash_uid = 0;
4513 m->mdt_squash_gid = 0;
4514 CFS_INIT_LIST_HEAD(&m->mdt_nosquash_nids);
4515 m->mdt_nosquash_str = NULL;
4516 m->mdt_nosquash_strlen = 0;
4517 cfs_init_rwsem(&m->mdt_squash_sem);
4519 OBD_ALLOC_PTR(mite);
4521 GOTO(err_lmi, rc = -ENOMEM);
4525 m->mdt_md_dev.md_lu_dev.ld_ops = &mdt_lu_ops;
4526 m->mdt_md_dev.md_lu_dev.ld_obd = obd;
4527 /* set this lu_device to obd, because error handling need it */
4528 obd->obd_lu_dev = &m->mdt_md_dev.md_lu_dev;
4530 rc = lu_site_init(s, &m->mdt_md_dev.md_lu_dev);
4532 CERROR("Can't init lu_site, rc %d\n", rc);
4533 GOTO(err_free_site, rc);
4536 /* set server index */
4537 lu_site2md(s)->ms_node_id = node_id;
4539 /* failover is the default
4540 * FIXME: we do not failout mds0/mgs, which may cause some problems.
4541 * assumed whose ms_node_id == 0 XXX
4543 obd->obd_replayable = 1;
4544 /* No connection accepted until configurations will finish */
4545 obd->obd_no_conn = 1;
4547 if (cfg->lcfg_bufcount > 4 && LUSTRE_CFG_BUFLEN(cfg, 4) > 0) {
4548 char *str = lustre_cfg_string(cfg, 4);
4549 if (strchr(str, 'n')) {
4550 CWARN("%s: recovery disabled\n", obd->obd_name);
4551 obd->obd_replayable = 0;
4555 /* init the stack */
4556 rc = mdt_stack_init((struct lu_env *)env, m, cfg, lmi);
4558 CERROR("Can't init device stack, rc %d\n", rc);
4559 GOTO(err_lu_site, rc);
4562 rc = lut_init(env, &m->mdt_lut, obd, m->mdt_bottom);
4564 GOTO(err_fini_stack, rc);
4566 rc = mdt_fld_init(env, obd->obd_name, m);
4570 rc = mdt_seq_init(env, obd->obd_name, m);
4572 GOTO(err_fini_fld, rc);
4574 snprintf(info->mti_u.ns_name, sizeof info->mti_u.ns_name,
4575 LUSTRE_MDT_NAME"-%p", m);
4576 m->mdt_namespace = ldlm_namespace_new(obd, info->mti_u.ns_name,
4577 LDLM_NAMESPACE_SERVER,
4578 LDLM_NAMESPACE_GREEDY,
4580 if (m->mdt_namespace == NULL)
4581 GOTO(err_fini_seq, rc = -ENOMEM);
4583 ldlm_register_intent(m->mdt_namespace, mdt_intent_policy);
4584 /* set obd_namespace for compatibility with old code */
4585 obd->obd_namespace = m->mdt_namespace;
4587 cfs_timer_init(&m->mdt_ck_timer, mdt_ck_timer_callback, m);
4589 rc = mdt_ck_thread_start(m);
4591 GOTO(err_free_ns, rc);
4593 rc = mdt_fs_setup(env, m, obd, lsi);
4597 rc = mdt_obd_llog_setup(obd, lsi);
4599 GOTO(err_fs_cleanup, rc);
4601 rc = mdt_llog_ctxt_clone(env, m, LLOG_CHANGELOG_ORIG_CTXT);
4603 GOTO(err_llog_cleanup, rc);
4605 mdt_adapt_sptlrpc_conf(obd, 1);
4607 next = m->mdt_child;
4608 #ifdef HAVE_QUOTA_SUPPORT
4609 rc = next->md_ops->mdo_quota.mqo_setup(env, next, lmi->lmi_mnt);
4611 GOTO(err_llog_cleanup, rc);
4614 server_put_mount_2(dev, lmi->lmi_mnt);
4617 rc = next->md_ops->mdo_iocontrol(env, next, OBD_IOC_GET_MNTOPT, 0,
4620 GOTO(err_quota, rc);
4622 if (mntopts & MNTOPT_USERXATTR)
4623 m->mdt_opts.mo_user_xattr = 1;
4625 m->mdt_opts.mo_user_xattr = 0;
4627 if (mntopts & MNTOPT_ACL)
4628 m->mdt_opts.mo_acl = 1;
4630 m->mdt_opts.mo_acl = 0;
4632 /* XXX: to support suppgid for ACL, we enable identity_upcall
4633 * by default, otherwise, maybe got unexpected -EACCESS. */
4634 if (m->mdt_opts.mo_acl)
4635 identity_upcall = MDT_IDENTITY_UPCALL_PATH;
4637 m->mdt_identity_cache = upcall_cache_init(obd->obd_name,identity_upcall,
4638 &mdt_identity_upcall_cache_ops);
4639 if (IS_ERR(m->mdt_identity_cache)) {
4640 rc = PTR_ERR(m->mdt_identity_cache);
4641 m->mdt_identity_cache = NULL;
4642 GOTO(err_quota, rc);
4645 target_recovery_init(&m->mdt_lut, mdt_recovery_handle);
4647 rc = mdt_procfs_init(m, dev);
4649 CERROR("Can't init MDT lprocfs, rc %d\n", rc);
4650 GOTO(err_recovery, rc);
4653 rc = mdt_start_ptlrpc_service(m);
4655 GOTO(err_procfs, rc);
4657 ping_evictor_start();
4659 rc = lu_site_init_finish(s);
4661 GOTO(err_stop_service, rc);
4663 if (obd->obd_recovering == 0)
4664 mdt_postrecov(env, m);
4666 mdt_init_capa_ctxt(env, m);
4668 /* Reduce the initial timeout on an MDS because it doesn't need such
4669 * a long timeout as an OST does. Adaptive timeouts will adjust this
4670 * value appropriately. */
4671 if (ldlm_timeout == LDLM_TIMEOUT_DEFAULT)
4672 ldlm_timeout = MDS_LDLM_TIMEOUT_DEFAULT;
4677 ping_evictor_stop();
4678 mdt_stop_ptlrpc_service(m);
4682 target_recovery_fini(obd);
4683 upcall_cache_cleanup(m->mdt_identity_cache);
4684 m->mdt_identity_cache = NULL;
4686 #ifdef HAVE_QUOTA_SUPPORT
4687 next->md_ops->mdo_quota.mqo_cleanup(env, next);
4690 mdt_llog_ctxt_unclone(env, m, LLOG_CHANGELOG_ORIG_CTXT);
4691 mdt_obd_llog_cleanup(obd);
4693 mdt_fs_cleanup(env, m);
4695 cfs_timer_disarm(&m->mdt_ck_timer);
4696 mdt_ck_thread_stop(m);
4698 ldlm_namespace_free(m->mdt_namespace, NULL, 0);
4699 obd->obd_namespace = m->mdt_namespace = NULL;
4701 mdt_seq_fini(env, m);
4703 mdt_fld_fini(env, m);
4705 lut_fini(env, &m->mdt_lut);
4707 mdt_stack_fini(env, m, md2lu_dev(m->mdt_child));
4714 server_put_mount_2(dev, lmi->lmi_mnt);
4718 /* used by MGS to process specific configurations */
4719 static int mdt_process_config(const struct lu_env *env,
4720 struct lu_device *d, struct lustre_cfg *cfg)
4722 struct mdt_device *m = mdt_dev(d);
4723 struct md_device *md_next = m->mdt_child;
4724 struct lu_device *next = md2lu_dev(md_next);
4728 switch (cfg->lcfg_command) {
4730 struct lprocfs_static_vars lvars;
4731 struct obd_device *obd = d->ld_obd;
4734 * For interoperability between 1.8 and 2.0,
4737 /* Skip old "mdt.group_upcall" param. */
4738 char *param = lustre_cfg_string(cfg, 1);
4739 if (param && !strncmp("mdt.group_upcall", param, 16)) {
4740 CWARN("For 1.8 interoperability, skip this"
4741 " mdt.group_upcall. It is obsolete\n");
4744 /* Rename old "mdt.quota_type" to "mdd.quota_type. */
4745 if (param && !strncmp("mdt.quota_type", param, 14)) {
4746 CWARN("Found old param mdt.quota_type, changed"
4747 " it to mdd.quota_type.\n");
4752 lprocfs_mdt_init_vars(&lvars);
4753 rc = class_process_proc_param(PARAM_MDT, lvars.obd_vars,
4755 if (rc > 0 || rc == -ENOSYS)
4756 /* we don't understand; pass it on */
4757 rc = next->ld_ops->ldo_process_config(env, next, cfg);
4762 * Add mdc hook to get first MDT uuid and connect it to
4763 * ls->controller to use for seq manager.
4765 rc = next->ld_ops->ldo_process_config(env, next, cfg);
4767 CERROR("Can't add mdc, rc %d\n", rc);
4769 rc = mdt_seq_init_cli(env, mdt_dev(d), cfg);
4772 /* others are passed further */
4773 rc = next->ld_ops->ldo_process_config(env, next, cfg);
4779 static struct lu_object *mdt_object_alloc(const struct lu_env *env,
4780 const struct lu_object_header *hdr,
4781 struct lu_device *d)
4783 struct mdt_object *mo;
4789 struct lu_object *o;
4790 struct lu_object_header *h;
4792 o = &mo->mot_obj.mo_lu;
4793 h = &mo->mot_header;
4794 lu_object_header_init(h);
4795 lu_object_init(o, h, d);
4796 lu_object_add_top(h, o);
4797 o->lo_ops = &mdt_obj_ops;
4798 cfs_sema_init(&mo->mot_ioepoch_sem, 1);
4799 cfs_sema_init(&mo->mot_lov_sem, 1);
4805 static int mdt_object_init(const struct lu_env *env, struct lu_object *o,
4806 const struct lu_object_conf *unused)
4808 struct mdt_device *d = mdt_dev(o->lo_dev);
4809 struct lu_device *under;
4810 struct lu_object *below;
4814 CDEBUG(D_INFO, "object init, fid = "DFID"\n",
4815 PFID(lu_object_fid(o)));
4817 under = &d->mdt_child->md_lu_dev;
4818 below = under->ld_ops->ldo_object_alloc(env, o->lo_header, under);
4819 if (below != NULL) {
4820 lu_object_add(o, below);
4827 static void mdt_object_free(const struct lu_env *env, struct lu_object *o)
4829 struct mdt_object *mo = mdt_obj(o);
4830 struct lu_object_header *h;
4834 CDEBUG(D_INFO, "object free, fid = "DFID"\n",
4835 PFID(lu_object_fid(o)));
4838 lu_object_header_fini(h);
4843 static int mdt_object_print(const struct lu_env *env, void *cookie,
4844 lu_printer_t p, const struct lu_object *o)
4846 struct mdt_object *mdto = mdt_obj((struct lu_object *)o);
4847 return (*p)(env, cookie, LUSTRE_MDT_NAME"-object@%p(ioepoch="LPU64" "
4848 "flags="LPX64", epochcount=%d, writecount=%d)",
4849 mdto, mdto->mot_ioepoch, mdto->mot_flags,
4850 mdto->mot_ioepoch_count, mdto->mot_writecount);
4853 static const struct lu_device_operations mdt_lu_ops = {
4854 .ldo_object_alloc = mdt_object_alloc,
4855 .ldo_process_config = mdt_process_config,
4858 static const struct lu_object_operations mdt_obj_ops = {
4859 .loo_object_init = mdt_object_init,
4860 .loo_object_free = mdt_object_free,
4861 .loo_object_print = mdt_object_print
4864 static int mdt_obd_set_info_async(struct obd_export *exp,
4865 __u32 keylen, void *key,
4866 __u32 vallen, void *val,
4867 struct ptlrpc_request_set *set)
4869 struct obd_device *obd = exp->exp_obd;
4875 if (KEY_IS(KEY_SPTLRPC_CONF)) {
4876 rc = mdt_adapt_sptlrpc_conf(obd, 0);
4883 /* mds_connect_internal */
4884 static int mdt_connect_internal(struct obd_export *exp,
4885 struct mdt_device *mdt,
4886 struct obd_connect_data *data)
4889 data->ocd_connect_flags &= MDT_CONNECT_SUPPORTED;
4890 data->ocd_ibits_known &= MDS_INODELOCK_FULL;
4892 /* If no known bits (which should not happen, probably,
4893 as everybody should support LOOKUP and UPDATE bits at least)
4894 revert to compat mode with plain locks. */
4895 if (!data->ocd_ibits_known &&
4896 data->ocd_connect_flags & OBD_CONNECT_IBITS)
4897 data->ocd_connect_flags &= ~OBD_CONNECT_IBITS;
4899 if (!mdt->mdt_opts.mo_acl)
4900 data->ocd_connect_flags &= ~OBD_CONNECT_ACL;
4902 if (!mdt->mdt_opts.mo_user_xattr)
4903 data->ocd_connect_flags &= ~OBD_CONNECT_XATTR;
4905 if (!mdt->mdt_som_conf)
4906 data->ocd_connect_flags &= ~OBD_CONNECT_SOM;
4908 if (data->ocd_connect_flags & OBD_CONNECT_BRW_SIZE) {
4909 data->ocd_brw_size = min(data->ocd_brw_size,
4910 (__u32)(PTLRPC_MAX_BRW_PAGES << CFS_PAGE_SHIFT));
4911 if (data->ocd_brw_size == 0) {
4912 CERROR("%s: cli %s/%p ocd_connect_flags: "LPX64
4913 " ocd_version: %x ocd_grant: %d "
4914 "ocd_index: %u ocd_brw_size is "
4915 "unexpectedly zero, network data "
4916 "corruption? Refusing connection of this"
4918 exp->exp_obd->obd_name,
4919 exp->exp_client_uuid.uuid,
4920 exp, data->ocd_connect_flags, data->ocd_version,
4921 data->ocd_grant, data->ocd_index);
4926 cfs_spin_lock(&exp->exp_lock);
4927 exp->exp_connect_flags = data->ocd_connect_flags;
4928 cfs_spin_unlock(&exp->exp_lock);
4929 data->ocd_version = LUSTRE_VERSION_CODE;
4930 exp->exp_mdt_data.med_ibits_known = data->ocd_ibits_known;
4934 if (mdt->mdt_opts.mo_acl &&
4935 ((exp->exp_connect_flags & OBD_CONNECT_ACL) == 0)) {
4936 CWARN("%s: MDS requires ACL support but client does not\n",
4937 mdt->mdt_md_dev.md_lu_dev.ld_obd->obd_name);
4942 if ((exp->exp_connect_flags & OBD_CONNECT_FID) == 0) {
4943 CWARN("%s: MDS requires FID support, but client not\n",
4944 mdt->mdt_md_dev.md_lu_dev.ld_obd->obd_name);
4948 if (mdt->mdt_som_conf && !exp_connect_som(exp) &&
4949 !(exp->exp_connect_flags & OBD_CONNECT_MDS_MDS)) {
4950 CWARN("%s: MDS has SOM enabled, but client does not support "
4951 "it\n", mdt->mdt_md_dev.md_lu_dev.ld_obd->obd_name);
4958 static int mdt_connect_check_sptlrpc(struct mdt_device *mdt,
4959 struct obd_export *exp,
4960 struct ptlrpc_request *req)
4962 struct sptlrpc_flavor flvr;
4965 if (exp->exp_flvr.sf_rpc == SPTLRPC_FLVR_INVALID) {
4966 cfs_read_lock(&mdt->mdt_sptlrpc_lock);
4967 sptlrpc_target_choose_flavor(&mdt->mdt_sptlrpc_rset,
4971 cfs_read_unlock(&mdt->mdt_sptlrpc_lock);
4973 cfs_spin_lock(&exp->exp_lock);
4975 exp->exp_sp_peer = req->rq_sp_from;
4976 exp->exp_flvr = flvr;
4978 if (exp->exp_flvr.sf_rpc != SPTLRPC_FLVR_ANY &&
4979 exp->exp_flvr.sf_rpc != req->rq_flvr.sf_rpc) {
4980 CERROR("unauthorized rpc flavor %x from %s, "
4981 "expect %x\n", req->rq_flvr.sf_rpc,
4982 libcfs_nid2str(req->rq_peer.nid),
4983 exp->exp_flvr.sf_rpc);
4987 cfs_spin_unlock(&exp->exp_lock);
4989 if (exp->exp_sp_peer != req->rq_sp_from) {
4990 CERROR("RPC source %s doesn't match %s\n",
4991 sptlrpc_part2name(req->rq_sp_from),
4992 sptlrpc_part2name(exp->exp_sp_peer));
4995 rc = sptlrpc_target_export_check(exp, req);
5002 /* mds_connect copy */
5003 static int mdt_obd_connect(const struct lu_env *env,
5004 struct obd_export **exp, struct obd_device *obd,
5005 struct obd_uuid *cluuid,
5006 struct obd_connect_data *data,
5009 struct mdt_thread_info *info;
5010 struct obd_export *lexp;
5011 struct lustre_handle conn = { 0 };
5012 struct mdt_device *mdt;
5013 struct ptlrpc_request *req;
5017 LASSERT(env != NULL);
5018 if (!exp || !obd || !cluuid)
5021 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
5022 req = info->mti_pill->rc_req;
5023 mdt = mdt_dev(obd->obd_lu_dev);
5025 rc = class_connect(&conn, obd, cluuid);
5029 lexp = class_conn2export(&conn);
5030 LASSERT(lexp != NULL);
5032 rc = mdt_connect_check_sptlrpc(mdt, lexp, req);
5036 if (OBD_FAIL_CHECK(OBD_FAIL_TGT_RCVG_FLAG))
5037 lustre_msg_add_op_flags(req->rq_repmsg, MSG_CONNECT_RECOVERING);
5039 rc = mdt_connect_internal(lexp, mdt, data);
5041 struct mdt_thread_info *mti;
5042 struct lsd_client_data *lcd = lexp->exp_target_data.ted_lcd;
5044 mti = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
5045 LASSERT(mti != NULL);
5046 mti->mti_exp = lexp;
5047 memcpy(lcd->lcd_uuid, cluuid, sizeof lcd->lcd_uuid);
5048 rc = mdt_client_new(env, mdt);
5050 mdt_export_stats_init(obd, lexp, localdata);
5055 class_disconnect(lexp);
5064 static int mdt_obd_reconnect(const struct lu_env *env,
5065 struct obd_export *exp, struct obd_device *obd,
5066 struct obd_uuid *cluuid,
5067 struct obd_connect_data *data,
5070 struct mdt_thread_info *info;
5071 struct mdt_device *mdt;
5072 struct ptlrpc_request *req;
5076 if (exp == NULL || obd == NULL || cluuid == NULL)
5079 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
5080 req = info->mti_pill->rc_req;
5081 mdt = mdt_dev(obd->obd_lu_dev);
5083 rc = mdt_connect_check_sptlrpc(mdt, exp, req);
5087 rc = mdt_connect_internal(exp, mdt_dev(obd->obd_lu_dev), data);
5089 mdt_export_stats_init(obd, exp, localdata);
5093 static int mdt_export_cleanup(struct obd_export *exp)
5095 struct mdt_export_data *med = &exp->exp_mdt_data;
5096 struct obd_device *obd = exp->exp_obd;
5097 struct mdt_device *mdt;
5098 struct mdt_thread_info *info;
5100 CFS_LIST_HEAD(closing_list);
5101 struct mdt_file_data *mfd, *n;
5105 cfs_spin_lock(&med->med_open_lock);
5106 while (!cfs_list_empty(&med->med_open_head)) {
5107 cfs_list_t *tmp = med->med_open_head.next;
5108 mfd = cfs_list_entry(tmp, struct mdt_file_data, mfd_list);
5110 /* Remove mfd handle so it can't be found again.
5111 * We are consuming the mfd_list reference here. */
5112 class_handle_unhash(&mfd->mfd_handle);
5113 cfs_list_move_tail(&mfd->mfd_list, &closing_list);
5115 cfs_spin_unlock(&med->med_open_lock);
5116 mdt = mdt_dev(obd->obd_lu_dev);
5117 LASSERT(mdt != NULL);
5119 rc = lu_env_init(&env, LCT_MD_THREAD);
5123 info = lu_context_key_get(&env.le_ctx, &mdt_thread_key);
5124 LASSERT(info != NULL);
5125 memset(info, 0, sizeof *info);
5126 info->mti_env = &env;
5127 info->mti_mdt = mdt;
5128 info->mti_exp = exp;
5130 if (!cfs_list_empty(&closing_list)) {
5131 struct md_attr *ma = &info->mti_attr;
5135 lmm_size = mdt->mdt_max_mdsize;
5136 OBD_ALLOC_LARGE(ma->ma_lmm, lmm_size);
5137 if (ma->ma_lmm == NULL)
5138 GOTO(out_lmm, rc = -ENOMEM);
5140 cookie_size = mdt->mdt_max_cookiesize;
5141 OBD_ALLOC_LARGE(ma->ma_cookie, cookie_size);
5142 if (ma->ma_cookie == NULL)
5143 GOTO(out_cookie, rc = -ENOMEM);
5145 /* Close any open files (which may also cause orphan unlinking). */
5146 cfs_list_for_each_entry_safe(mfd, n, &closing_list, mfd_list) {
5147 cfs_list_del_init(&mfd->mfd_list);
5148 memset(&ma->ma_attr, 0, sizeof(ma->ma_attr));
5149 ma->ma_lmm_size = lmm_size;
5150 ma->ma_cookie_size = cookie_size;
5152 /* It is not for setattr, just tell MDD to send
5153 * DESTROY RPC to OSS if needed */
5154 ma->ma_valid = MA_FLAGS;
5155 ma->ma_attr_flags = MDS_CLOSE_CLEANUP;
5156 /* Don't unlink orphan on failover umount, LU-184 */
5157 if (exp->exp_flags & OBD_OPT_FAILOVER)
5158 ma->ma_attr_flags |= MDS_KEEP_ORPHAN;
5159 mdt_mfd_close(info, mfd);
5161 OBD_FREE_LARGE(ma->ma_cookie, cookie_size);
5162 ma->ma_cookie = NULL;
5164 OBD_FREE_LARGE(ma->ma_lmm, lmm_size);
5168 info->mti_mdt = NULL;
5169 /* cleanup client slot early */
5170 /* Do not erase record for recoverable client. */
5171 if (!(exp->exp_flags & OBD_OPT_FAILOVER) || exp->exp_failed)
5172 mdt_client_del(&env, mdt);
5178 static int mdt_obd_disconnect(struct obd_export *exp)
5184 class_export_get(exp);
5186 rc = server_disconnect_export(exp);
5188 CDEBUG(D_IOCTL, "server disconnect error: %d\n", rc);
5190 rc = mdt_export_cleanup(exp);
5191 class_export_put(exp);
5195 /* FIXME: Can we avoid using these two interfaces? */
5196 static int mdt_init_export(struct obd_export *exp)
5198 struct mdt_export_data *med = &exp->exp_mdt_data;
5202 CFS_INIT_LIST_HEAD(&med->med_open_head);
5203 cfs_spin_lock_init(&med->med_open_lock);
5204 cfs_sema_init(&med->med_idmap_sem, 1);
5205 med->med_idmap = NULL;
5206 cfs_spin_lock(&exp->exp_lock);
5207 exp->exp_connecting = 1;
5208 cfs_spin_unlock(&exp->exp_lock);
5210 /* self-export doesn't need client data and ldlm initialization */
5211 if (unlikely(obd_uuid_equals(&exp->exp_obd->obd_uuid,
5212 &exp->exp_client_uuid)))
5215 rc = lut_client_alloc(exp);
5217 rc = ldlm_init_export(exp);
5219 CERROR("%s: Error %d while initializing export\n",
5220 exp->exp_obd->obd_name, rc);
5224 static int mdt_destroy_export(struct obd_export *exp)
5228 if (exp_connect_rmtclient(exp))
5229 mdt_cleanup_idmap(&exp->exp_mdt_data);
5231 target_destroy_export(exp);
5232 /* destroy can be called from failed obd_setup, so
5233 * checking uuid is safer than obd_self_export */
5234 if (unlikely(obd_uuid_equals(&exp->exp_obd->obd_uuid,
5235 &exp->exp_client_uuid)))
5238 ldlm_destroy_export(exp);
5239 lut_client_free(exp);
5241 LASSERT(cfs_list_empty(&exp->exp_outstanding_replies));
5242 LASSERT(cfs_list_empty(&exp->exp_mdt_data.med_open_head));
5247 static void mdt_allow_cli(struct mdt_device *m, unsigned int flag)
5249 if (flag & CONFIG_LOG)
5250 cfs_set_bit(MDT_FL_CFGLOG, &m->mdt_state);
5252 /* also notify active event */
5253 if (flag & CONFIG_SYNC)
5254 cfs_set_bit(MDT_FL_SYNCED, &m->mdt_state);
5256 if (cfs_test_bit(MDT_FL_CFGLOG, &m->mdt_state) &&
5257 cfs_test_bit(MDT_FL_SYNCED, &m->mdt_state)) {
5258 struct obd_device *obd = m->mdt_md_dev.md_lu_dev.ld_obd;
5260 /* Open for clients */
5261 if (obd->obd_no_conn) {
5262 cfs_spin_lock(&obd->obd_dev_lock);
5263 obd->obd_no_conn = 0;
5264 cfs_spin_unlock(&obd->obd_dev_lock);
5269 static int mdt_upcall(const struct lu_env *env, struct md_device *md,
5270 enum md_upcall_event ev, void *data)
5272 struct mdt_device *m = mdt_dev(&md->md_lu_dev);
5273 struct md_device *next = m->mdt_child;
5274 struct mdt_thread_info *mti;
5280 rc = next->md_ops->mdo_maxsize_get(env, next,
5282 &m->mdt_max_cookiesize);
5283 CDEBUG(D_INFO, "get max mdsize %d max cookiesize %d\n",
5284 m->mdt_max_mdsize, m->mdt_max_cookiesize);
5285 mdt_allow_cli(m, CONFIG_SYNC);
5288 m->mdt_lut.lut_obd->u.obt.obt_mount_count;
5291 mti = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
5292 mti->mti_no_need_trans = 1;
5293 CDEBUG(D_INFO, "disable mdt trans for this thread\n");
5296 /* Check that MDT is not yet configured */
5297 LASSERT(!cfs_test_bit(MDT_FL_CFGLOG, &m->mdt_state));
5299 #ifdef HAVE_QUOTA_SUPPORT
5301 if (md->md_lu_dev.ld_obd->obd_recovering == 0 &&
5302 likely(md->md_lu_dev.ld_obd->obd_stopping == 0))
5303 next->md_ops->mdo_quota.mqo_recovery(env, next);
5307 CERROR("invalid event\n");
5314 static int mdt_obd_notify(struct obd_device *obd,
5315 struct obd_device *watched,
5316 enum obd_notify_event ev, void *data)
5318 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
5319 #ifdef HAVE_QUOTA_SUPPORT
5320 struct md_device *next = mdt->mdt_child;
5325 case OBD_NOTIFY_CONFIG:
5326 mdt_allow_cli(mdt, (unsigned long)data);
5328 #ifdef HAVE_QUOTA_SUPPORT
5329 /* quota_type has been processed, we can now handle
5330 * incoming quota requests */
5331 next->md_ops->mdo_quota.mqo_notify(NULL, next);
5335 CDEBUG(D_INFO, "Unhandled notification %#x\n", ev);
5340 static int mdt_rpc_fid2path(struct mdt_thread_info *info, void *key,
5341 void *val, int vallen)
5343 struct mdt_device *mdt = mdt_dev(info->mti_exp->exp_obd->obd_lu_dev);
5344 struct getinfo_fid2path *fpout, *fpin;
5347 fpin = key + cfs_size_round(sizeof(KEY_FID2PATH));
5350 if (ptlrpc_req_need_swab(info->mti_pill->rc_req))
5351 lustre_swab_fid2path(fpin);
5353 memcpy(fpout, fpin, sizeof(*fpin));
5354 if (fpout->gf_pathlen != vallen - sizeof(*fpin))
5357 rc = mdt_fid2path(info->mti_env, mdt, fpout);
5361 static int mdt_fid2path(const struct lu_env *env, struct mdt_device *mdt,
5362 struct getinfo_fid2path *fp)
5364 struct mdt_object *obj;
5368 CDEBUG(D_IOCTL, "path get "DFID" from "LPU64" #%d\n",
5369 PFID(&fp->gf_fid), fp->gf_recno, fp->gf_linkno);
5371 if (!fid_is_sane(&fp->gf_fid))
5374 obj = mdt_object_find(env, mdt, &fp->gf_fid, MDT_OBJ_MUST_EXIST);
5375 if (obj == NULL || IS_ERR(obj)) {
5376 CDEBUG(D_IOCTL, "%s: no object "DFID": %ld\n",
5377 mdt2obd_dev(mdt)->obd_name, PFID(&fp->gf_fid),
5379 RETURN(obj == NULL ? -EINVAL : PTR_ERR(obj));
5382 if (lu_object_exists(&obj->mot_obj.mo_lu) < 0) {
5384 mdt_object_put(env, obj);
5385 CDEBUG(D_IOCTL, "nonlocal object "DFID": %d\n",
5386 PFID(&fp->gf_fid), rc);
5390 rc = mo_path(env, md_object_next(&obj->mot_obj), fp->gf_path,
5391 fp->gf_pathlen, &fp->gf_recno, &fp->gf_linkno);
5392 mdt_object_put(env, obj);
5397 static int mdt_get_info(struct mdt_thread_info *info)
5399 struct ptlrpc_request *req = mdt_info_req(info);
5407 key = req_capsule_client_get(info->mti_pill, &RMF_GETINFO_KEY);
5409 CDEBUG(D_IOCTL, "No GETINFO key");
5412 keylen = req_capsule_get_size(info->mti_pill, &RMF_GETINFO_KEY,
5415 vallen = req_capsule_client_get(info->mti_pill, &RMF_GETINFO_VALLEN);
5416 if (vallen == NULL) {
5417 CDEBUG(D_IOCTL, "Unable to get RMF_GETINFO_VALLEN buffer");
5421 req_capsule_set_size(info->mti_pill, &RMF_GETINFO_VAL, RCL_SERVER,
5423 rc = req_capsule_server_pack(info->mti_pill);
5424 valout = req_capsule_server_get(info->mti_pill, &RMF_GETINFO_VAL);
5425 if (valout == NULL) {
5426 CDEBUG(D_IOCTL, "Unable to get get-info RPC out buffer");
5430 if (KEY_IS(KEY_FID2PATH))
5431 rc = mdt_rpc_fid2path(info, key, valout, *vallen);
5435 lustre_msg_set_status(req->rq_repmsg, rc);
5440 /* Pass the ioc down */
5441 static int mdt_ioc_child(struct lu_env *env, struct mdt_device *mdt,
5442 unsigned int cmd, int len, void *data)
5444 struct lu_context ioctl_session;
5445 struct md_device *next = mdt->mdt_child;
5449 rc = lu_context_init(&ioctl_session, LCT_SESSION);
5452 ioctl_session.lc_thread = (struct ptlrpc_thread *)cfs_current();
5453 lu_context_enter(&ioctl_session);
5454 env->le_ses = &ioctl_session;
5456 LASSERT(next->md_ops->mdo_iocontrol);
5457 rc = next->md_ops->mdo_iocontrol(env, next, cmd, len, data);
5459 lu_context_exit(&ioctl_session);
5460 lu_context_fini(&ioctl_session);
5464 static int mdt_ioc_version_get(struct mdt_thread_info *mti, void *karg)
5466 struct obd_ioctl_data *data = karg;
5467 struct lu_fid *fid = (struct lu_fid *)data->ioc_inlbuf1;
5469 struct mdt_object *obj;
5470 struct mdt_lock_handle *lh;
5474 CDEBUG(D_IOCTL, "getting version for "DFID"\n", PFID(fid));
5475 if (!fid_is_sane(fid))
5478 lh = &mti->mti_lh[MDT_LH_PARENT];
5479 mdt_lock_reg_init(lh, LCK_CR);
5481 obj = mdt_object_find_lock(mti, fid, lh, MDS_INODELOCK_UPDATE,
5482 MDT_OBJ_MUST_EXIST);
5484 if (PTR_ERR(obj) == -ENOENT)
5485 *(__u64 *)data->ioc_inlbuf2 = ENOENT_VERSION;
5486 RETURN(PTR_ERR(obj));
5489 rc = mdt_object_exists(obj);
5493 * before calling version get the correct MDS should be
5494 * fid, this is error to find remote object here
5496 CERROR("nonlocal object "DFID"\n", PFID(fid));
5497 } else if (rc > 0) {
5498 version = dt_version_get(mti->mti_env, mdt_obj2dt(obj));
5499 *(__u64 *)data->ioc_inlbuf2 = version;
5502 mdt_object_unlock_put(mti, obj, lh, 1);
5507 /* ioctls on obd dev */
5508 static int mdt_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
5509 void *karg, void *uarg)
5512 struct obd_device *obd = exp->exp_obd;
5513 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
5514 struct dt_device *dt = mdt->mdt_bottom;
5518 CDEBUG(D_IOCTL, "handling ioctl cmd %#x\n", cmd);
5519 rc = lu_env_init(&env, LCT_MD_THREAD);
5525 rc = mdt_device_sync(&env, mdt);
5527 case OBD_IOC_SET_READONLY:
5528 dt->dd_ops->dt_ro(&env, dt);
5530 case OBD_IOC_ABORT_RECOVERY:
5531 CERROR("Aborting recovery for device %s\n", obd->obd_name);
5532 target_stop_recovery_thread(obd);
5535 case OBD_IOC_CHANGELOG_REG:
5536 case OBD_IOC_CHANGELOG_DEREG:
5537 case OBD_IOC_CHANGELOG_CLEAR:
5538 rc = mdt_ioc_child(&env, mdt, cmd, len, karg);
5540 case OBD_IOC_GET_OBJ_VERSION: {
5541 struct mdt_thread_info *mti;
5542 mti = lu_context_key_get(&env.le_ctx, &mdt_thread_key);
5543 memset(mti, 0, sizeof *mti);
5544 mti->mti_env = &env;
5548 rc = mdt_ioc_version_get(mti, karg);
5552 CERROR("Not supported cmd = %d for device %s\n",
5553 cmd, obd->obd_name);
5561 int mdt_postrecov(const struct lu_env *env, struct mdt_device *mdt)
5563 struct lu_device *ld = md2lu_dev(mdt->mdt_child);
5564 #ifdef HAVE_QUOTA_SUPPORT
5565 struct obd_device *obd = mdt2obd_dev(mdt);
5566 struct md_device *next = mdt->mdt_child;
5571 rc = ld->ld_ops->ldo_recovery_complete(env, ld);
5572 #ifdef HAVE_QUOTA_SUPPORT
5573 if (likely(obd->obd_stopping == 0))
5574 next->md_ops->mdo_quota.mqo_recovery(env, next);
5579 int mdt_obd_postrecov(struct obd_device *obd)
5584 rc = lu_env_init(&env, LCT_MD_THREAD);
5587 rc = mdt_postrecov(&env, mdt_dev(obd->obd_lu_dev));
5593 * Send a copytool req to a client
5594 * Note this sends a request RPC from a server (MDT) to a client (MDC),
5595 * backwards of normal comms.
5597 int mdt_hsm_copytool_send(struct obd_export *exp)
5600 struct hsm_action_list *hal;
5601 struct hsm_action_item *hai;
5605 CWARN("%s: writing to mdc at %s\n", exp->exp_obd->obd_name,
5606 libcfs_nid2str(exp->exp_connection->c_peer.nid));
5608 len = sizeof(*lh) + sizeof(*hal) + MTI_NAME_MAXLEN +
5609 /* for mockup below */ 2 * cfs_size_round(sizeof(*hai));
5614 lh->kuc_magic = KUC_MAGIC;
5615 lh->kuc_transport = KUC_TRANSPORT_HSM;
5616 lh->kuc_msgtype = HMT_ACTION_LIST;
5617 lh->kuc_msglen = len;
5619 hal = (struct hsm_action_list *)(lh + 1);
5620 hal->hal_version = HAL_VERSION;
5621 hal->hal_archive_num = 1;
5622 obd_uuid2fsname(hal->hal_fsname, exp->exp_obd->obd_name,
5625 /* mock up an action list */
5627 hai = hai_zero(hal);
5628 hai->hai_action = HSMA_ARCHIVE;
5629 hai->hai_fid.f_oid = 0xA00A;
5630 hai->hai_len = sizeof(*hai);
5631 hai = hai_next(hai);
5632 hai->hai_action = HSMA_RESTORE;
5633 hai->hai_fid.f_oid = 0xB00B;
5634 hai->hai_len = sizeof(*hai);
5636 /* Uses the ldlm reverse import; this rpc will be seen by
5637 the ldlm_callback_handler */
5638 rc = do_set_info_async(exp->exp_imp_reverse,
5639 LDLM_SET_INFO, LUSTRE_OBD_VERSION,
5640 sizeof(KEY_HSM_COPYTOOL_SEND),
5641 KEY_HSM_COPYTOOL_SEND,
5649 static struct obd_ops mdt_obd_device_ops = {
5650 .o_owner = THIS_MODULE,
5651 .o_set_info_async = mdt_obd_set_info_async,
5652 .o_connect = mdt_obd_connect,
5653 .o_reconnect = mdt_obd_reconnect,
5654 .o_disconnect = mdt_obd_disconnect,
5655 .o_init_export = mdt_init_export,
5656 .o_destroy_export = mdt_destroy_export,
5657 .o_iocontrol = mdt_iocontrol,
5658 .o_postrecov = mdt_obd_postrecov,
5659 .o_notify = mdt_obd_notify
5662 static struct lu_device* mdt_device_fini(const struct lu_env *env,
5663 struct lu_device *d)
5665 struct mdt_device *m = mdt_dev(d);
5672 static struct lu_device *mdt_device_free(const struct lu_env *env,
5673 struct lu_device *d)
5675 struct mdt_device *m = mdt_dev(d);
5678 md_device_fini(&m->mdt_md_dev);
5683 static struct lu_device *mdt_device_alloc(const struct lu_env *env,
5684 struct lu_device_type *t,
5685 struct lustre_cfg *cfg)
5687 struct lu_device *l;
5688 struct mdt_device *m;
5694 l = &m->mdt_md_dev.md_lu_dev;
5695 rc = mdt_init0(env, m, t, cfg);
5697 mdt_device_free(env, l);
5701 md_upcall_init(&m->mdt_md_dev, mdt_upcall);
5703 l = ERR_PTR(-ENOMEM);
5707 /* context key constructor/destructor: mdt_key_init, mdt_key_fini */
5708 LU_KEY_INIT_FINI(mdt, struct mdt_thread_info);
5710 /* context key: mdt_thread_key */
5711 LU_CONTEXT_KEY_DEFINE(mdt, LCT_MD_THREAD);
5713 struct md_ucred *mdt_ucred(const struct mdt_thread_info *info)
5715 return md_ucred(info->mti_env);
5719 * Enable/disable COS (Commit On Sharing).
5721 * Set/Clear the COS flag in mdt options.
5723 * \param mdt mdt device
5724 * \param val 0 disables COS, other values enable COS
5726 void mdt_enable_cos(struct mdt_device *mdt, int val)
5731 mdt->mdt_opts.mo_cos = !!val;
5732 rc = lu_env_init(&env, LCT_MD_THREAD);
5733 if (unlikely(rc != 0)) {
5734 CWARN("lu_env initialization failed with rc = %d,"
5735 "cannot sync\n", rc);
5738 mdt_device_sync(&env, mdt);
5743 * Check COS (Commit On Sharing) status.
5745 * Return COS flag status.
5747 * \param mdt mdt device
5749 int mdt_cos_is_enabled(struct mdt_device *mdt)
5751 return mdt->mdt_opts.mo_cos != 0;
5754 /* type constructor/destructor: mdt_type_init, mdt_type_fini */
5755 LU_TYPE_INIT_FINI(mdt, &mdt_thread_key);
5757 static struct lu_device_type_operations mdt_device_type_ops = {
5758 .ldto_init = mdt_type_init,
5759 .ldto_fini = mdt_type_fini,
5761 .ldto_start = mdt_type_start,
5762 .ldto_stop = mdt_type_stop,
5764 .ldto_device_alloc = mdt_device_alloc,
5765 .ldto_device_free = mdt_device_free,
5766 .ldto_device_fini = mdt_device_fini
5769 static struct lu_device_type mdt_device_type = {
5770 .ldt_tags = LU_DEVICE_MD,
5771 .ldt_name = LUSTRE_MDT_NAME,
5772 .ldt_ops = &mdt_device_type_ops,
5773 .ldt_ctx_tags = LCT_MD_THREAD
5776 static struct lu_local_obj_desc mdt_last_recv = {
5777 .llod_name = LAST_RCVD,
5778 .llod_oid = MDT_LAST_RECV_OID,
5782 static int __init mdt_mod_init(void)
5784 struct lprocfs_static_vars lvars;
5787 llo_local_obj_register(&mdt_last_recv);
5789 if (mdt_num_threads > 0) {
5790 if (mdt_num_threads > MDT_MAX_THREADS)
5791 mdt_num_threads = MDT_MAX_THREADS;
5792 if (mdt_num_threads < MDT_MIN_THREADS)
5793 mdt_num_threads = MDT_MIN_THREADS;
5794 mdt_max_threads = mdt_min_threads = mdt_num_threads;
5796 mdt_max_threads = MDT_MAX_THREADS;
5797 mdt_min_threads = MDT_MIN_THREADS;
5800 lprocfs_mdt_init_vars(&lvars);
5801 rc = class_register_type(&mdt_obd_device_ops, NULL,
5802 lvars.module_vars, LUSTRE_MDT_NAME,
5808 static void __exit mdt_mod_exit(void)
5810 llo_local_obj_unregister(&mdt_last_recv);
5811 class_unregister_type(LUSTRE_MDT_NAME);
5815 #define DEF_HNDL(prefix, base, suffix, flags, opc, fn, fmt) \
5816 [prefix ## _ ## opc - prefix ## _ ## base] = { \
5818 .mh_fail_id = OBD_FAIL_ ## prefix ## _ ## opc ## suffix, \
5819 .mh_opc = prefix ## _ ## opc, \
5820 .mh_flags = flags, \
5825 #define DEF_MDT_HNDL(flags, name, fn, fmt) \
5826 DEF_HNDL(MDS, GETATTR, _NET, flags, name, fn, fmt)
5828 #define DEF_SEQ_HNDL(flags, name, fn, fmt) \
5829 DEF_HNDL(SEQ, QUERY, _NET, flags, name, fn, fmt)
5831 #define DEF_FLD_HNDL(flags, name, fn, fmt) \
5832 DEF_HNDL(FLD, QUERY, _NET, flags, name, fn, fmt)
5834 * Request with a format known in advance
5836 #define DEF_MDT_HNDL_F(flags, name, fn) \
5837 DEF_HNDL(MDS, GETATTR, _NET, flags, name, fn, &RQF_MDS_ ## name)
5839 #define DEF_SEQ_HNDL_F(flags, name, fn) \
5840 DEF_HNDL(SEQ, QUERY, _NET, flags, name, fn, &RQF_SEQ_ ## name)
5842 #define DEF_FLD_HNDL_F(flags, name, fn) \
5843 DEF_HNDL(FLD, QUERY, _NET, flags, name, fn, &RQF_FLD_ ## name)
5845 * Request with a format we do not yet know
5847 #define DEF_MDT_HNDL_0(flags, name, fn) \
5848 DEF_HNDL(MDS, GETATTR, _NET, flags, name, fn, NULL)
5850 static struct mdt_handler mdt_mds_ops[] = {
5851 DEF_MDT_HNDL_F(0, CONNECT, mdt_connect),
5852 DEF_MDT_HNDL_F(0, DISCONNECT, mdt_disconnect),
5853 DEF_MDT_HNDL (0, SET_INFO, mdt_set_info,
5855 DEF_MDT_HNDL_F(0, GET_INFO, mdt_get_info),
5856 DEF_MDT_HNDL_F(0 |HABEO_REFERO, GETSTATUS, mdt_getstatus),
5857 DEF_MDT_HNDL_F(HABEO_CORPUS, GETATTR, mdt_getattr),
5858 DEF_MDT_HNDL_F(HABEO_CORPUS|HABEO_REFERO, GETATTR_NAME, mdt_getattr_name),
5859 DEF_MDT_HNDL_F(HABEO_CORPUS, GETXATTR, mdt_getxattr),
5860 DEF_MDT_HNDL_F(0 |HABEO_REFERO, STATFS, mdt_statfs),
5861 DEF_MDT_HNDL_F(0 |MUTABOR, REINT, mdt_reint),
5862 DEF_MDT_HNDL_F(HABEO_CORPUS, CLOSE, mdt_close),
5863 DEF_MDT_HNDL_F(HABEO_CORPUS, DONE_WRITING, mdt_done_writing),
5864 DEF_MDT_HNDL_F(0 |HABEO_REFERO, PIN, mdt_pin),
5865 DEF_MDT_HNDL_0(0, SYNC, mdt_sync),
5866 DEF_MDT_HNDL_F(HABEO_CORPUS|HABEO_REFERO, IS_SUBDIR, mdt_is_subdir),
5867 #ifdef HAVE_QUOTA_SUPPORT
5868 DEF_MDT_HNDL_F(0, QUOTACHECK, mdt_quotacheck_handle),
5869 DEF_MDT_HNDL_F(0, QUOTACTL, mdt_quotactl_handle)
5873 #define DEF_OBD_HNDL(flags, name, fn) \
5874 DEF_HNDL(OBD, PING, _NET, flags, name, fn, NULL)
5877 static struct mdt_handler mdt_obd_ops[] = {
5878 DEF_OBD_HNDL(0, PING, mdt_obd_ping),
5879 DEF_OBD_HNDL(0, LOG_CANCEL, mdt_obd_log_cancel),
5880 DEF_OBD_HNDL(0, QC_CALLBACK, mdt_obd_qc_callback)
5883 #define DEF_DLM_HNDL_0(flags, name, fn) \
5884 DEF_HNDL(LDLM, ENQUEUE, , flags, name, fn, NULL)
5885 #define DEF_DLM_HNDL_F(flags, name, fn) \
5886 DEF_HNDL(LDLM, ENQUEUE, , flags, name, fn, &RQF_LDLM_ ## name)
5888 static struct mdt_handler mdt_dlm_ops[] = {
5889 DEF_DLM_HNDL_F(HABEO_CLAVIS, ENQUEUE, mdt_enqueue),
5890 DEF_DLM_HNDL_0(HABEO_CLAVIS, CONVERT, mdt_convert),
5891 DEF_DLM_HNDL_0(0, BL_CALLBACK, mdt_bl_callback),
5892 DEF_DLM_HNDL_0(0, CP_CALLBACK, mdt_cp_callback)
5895 #define DEF_LLOG_HNDL(flags, name, fn) \
5896 DEF_HNDL(LLOG, ORIGIN_HANDLE_CREATE, _NET, flags, name, fn, NULL)
5898 static struct mdt_handler mdt_llog_ops[] = {
5899 DEF_LLOG_HNDL(0, ORIGIN_HANDLE_CREATE, mdt_llog_create),
5900 DEF_LLOG_HNDL(0, ORIGIN_HANDLE_NEXT_BLOCK, mdt_llog_next_block),
5901 DEF_LLOG_HNDL(0, ORIGIN_HANDLE_READ_HEADER, mdt_llog_read_header),
5902 DEF_LLOG_HNDL(0, ORIGIN_HANDLE_WRITE_REC, NULL),
5903 DEF_LLOG_HNDL(0, ORIGIN_HANDLE_CLOSE, NULL),
5904 DEF_LLOG_HNDL(0, ORIGIN_CONNECT, NULL),
5905 DEF_LLOG_HNDL(0, CATINFO, NULL),
5906 DEF_LLOG_HNDL(0, ORIGIN_HANDLE_PREV_BLOCK, mdt_llog_prev_block),
5907 DEF_LLOG_HNDL(0, ORIGIN_HANDLE_DESTROY, mdt_llog_destroy),
5910 #define DEF_SEC_CTX_HNDL(name, fn) \
5911 DEF_HNDL(SEC_CTX, INIT, _NET, 0, name, fn, NULL)
5913 static struct mdt_handler mdt_sec_ctx_ops[] = {
5914 DEF_SEC_CTX_HNDL(INIT, mdt_sec_ctx_handle),
5915 DEF_SEC_CTX_HNDL(INIT_CONT, mdt_sec_ctx_handle),
5916 DEF_SEC_CTX_HNDL(FINI, mdt_sec_ctx_handle)
5919 static struct mdt_opc_slice mdt_regular_handlers[] = {
5921 .mos_opc_start = MDS_GETATTR,
5922 .mos_opc_end = MDS_LAST_OPC,
5923 .mos_hs = mdt_mds_ops
5926 .mos_opc_start = OBD_PING,
5927 .mos_opc_end = OBD_LAST_OPC,
5928 .mos_hs = mdt_obd_ops
5931 .mos_opc_start = LDLM_ENQUEUE,
5932 .mos_opc_end = LDLM_LAST_OPC,
5933 .mos_hs = mdt_dlm_ops
5936 .mos_opc_start = LLOG_ORIGIN_HANDLE_CREATE,
5937 .mos_opc_end = LLOG_LAST_OPC,
5938 .mos_hs = mdt_llog_ops
5941 .mos_opc_start = SEC_CTX_INIT,
5942 .mos_opc_end = SEC_LAST_OPC,
5943 .mos_hs = mdt_sec_ctx_ops
5950 static struct mdt_handler mdt_readpage_ops[] = {
5951 DEF_MDT_HNDL_F(0, CONNECT, mdt_connect),
5952 DEF_MDT_HNDL_F(HABEO_CORPUS|HABEO_REFERO, READPAGE, mdt_readpage),
5953 #ifdef HAVE_SPLIT_SUPPORT
5954 DEF_MDT_HNDL_F(HABEO_CORPUS|HABEO_REFERO, WRITEPAGE, mdt_writepage),
5958 * XXX: this is ugly and should be fixed one day, see mdc_close() for
5959 * detailed comments. --umka
5961 DEF_MDT_HNDL_F(HABEO_CORPUS, CLOSE, mdt_close),
5962 DEF_MDT_HNDL_F(HABEO_CORPUS, DONE_WRITING, mdt_done_writing),
5965 static struct mdt_opc_slice mdt_readpage_handlers[] = {
5967 .mos_opc_start = MDS_GETATTR,
5968 .mos_opc_end = MDS_LAST_OPC,
5969 .mos_hs = mdt_readpage_ops
5976 static struct mdt_handler mdt_xmds_ops[] = {
5977 DEF_MDT_HNDL_F(0, CONNECT, mdt_connect),
5978 DEF_MDT_HNDL_F(HABEO_CORPUS , GETATTR, mdt_getattr),
5979 DEF_MDT_HNDL_F(0 | MUTABOR , REINT, mdt_reint),
5980 DEF_MDT_HNDL_F(HABEO_CORPUS|HABEO_REFERO, IS_SUBDIR, mdt_is_subdir),
5983 static struct mdt_opc_slice mdt_xmds_handlers[] = {
5985 .mos_opc_start = MDS_GETATTR,
5986 .mos_opc_end = MDS_LAST_OPC,
5987 .mos_hs = mdt_xmds_ops
5990 .mos_opc_start = OBD_PING,
5991 .mos_opc_end = OBD_LAST_OPC,
5992 .mos_hs = mdt_obd_ops
5995 .mos_opc_start = SEC_CTX_INIT,
5996 .mos_opc_end = SEC_LAST_OPC,
5997 .mos_hs = mdt_sec_ctx_ops
6004 static struct mdt_handler mdt_seq_ops[] = {
6005 DEF_SEQ_HNDL_F(0, QUERY, (int (*)(struct mdt_thread_info *))seq_query)
6008 static struct mdt_opc_slice mdt_seq_handlers[] = {
6010 .mos_opc_start = SEQ_QUERY,
6011 .mos_opc_end = SEQ_LAST_OPC,
6012 .mos_hs = mdt_seq_ops
6019 static struct mdt_handler mdt_fld_ops[] = {
6020 DEF_FLD_HNDL_F(0, QUERY, (int (*)(struct mdt_thread_info *))fld_query)
6023 static struct mdt_opc_slice mdt_fld_handlers[] = {
6025 .mos_opc_start = FLD_QUERY,
6026 .mos_opc_end = FLD_LAST_OPC,
6027 .mos_hs = mdt_fld_ops
6034 MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");
6035 MODULE_DESCRIPTION("Lustre Meta-data Target ("LUSTRE_MDT_NAME")");
6036 MODULE_LICENSE("GPL");
6038 CFS_MODULE_PARM(mdt_num_threads, "ul", ulong, 0444,
6039 "number of mdt service threads to start");
6041 cfs_module(mdt, "0.2.0", mdt_mod_init, mdt_mod_exit);