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.
32 * Copyright (c) 2011, 2012, Whamcloud, Inc.
35 * This file is part of Lustre, http://www.lustre.org/
36 * Lustre is a trademark of Sun Microsystems, Inc.
38 * lustre/mdt/mdt_handler.c
40 * Lustre Metadata Target (mdt) request handler
42 * Author: Peter Braam <braam@clusterfs.com>
43 * Author: Andreas Dilger <adilger@clusterfs.com>
44 * Author: Phil Schwan <phil@clusterfs.com>
45 * Author: Mike Shaver <shaver@clusterfs.com>
46 * Author: Nikita Danilov <nikita@clusterfs.com>
47 * Author: Huang Hua <huanghua@clusterfs.com>
48 * Author: Yury Umanets <umka@clusterfs.com>
52 # define EXPORT_SYMTAB
54 #define DEBUG_SUBSYSTEM S_MDS
56 #include <linux/module.h>
58 * struct OBD_{ALLOC,FREE}*()
60 #include <obd_support.h>
61 /* struct ptlrpc_request */
62 #include <lustre_net.h>
63 /* struct obd_export */
64 #include <lustre_export.h>
65 /* struct obd_device */
68 #include <dt_object.h>
69 #include <lustre_mds.h>
70 #include <lustre_mdt.h>
71 #include "mdt_internal.h"
72 #ifdef HAVE_QUOTA_SUPPORT
73 # include <lustre_quota.h>
75 #include <lustre_acl.h>
76 #include <lustre_param.h>
77 #include <lustre_fsfilt.h>
79 mdl_mode_t mdt_mdl_lock_modes[] = {
80 [LCK_MINMODE] = MDL_MINMODE,
87 [LCK_GROUP] = MDL_GROUP
90 ldlm_mode_t mdt_dlm_lock_modes[] = {
91 [MDL_MINMODE] = LCK_MINMODE,
98 [MDL_GROUP] = LCK_GROUP
102 * Initialized in mdt_mod_init().
104 static unsigned long mdt_num_threads;
105 static unsigned long mdt_min_threads;
106 static unsigned long mdt_max_threads;
108 /* ptlrpc request handler for MDT. All handlers are
109 * grouped into several slices - struct mdt_opc_slice,
110 * and stored in an array - mdt_handlers[].
113 /* The name of this handler. */
115 /* Fail id for this handler, checked at the beginning of this handler*/
117 /* Operation code for this handler */
119 /* flags are listed in enum mdt_handler_flags below. */
121 /* The actual handler function to execute. */
122 int (*mh_act)(struct mdt_thread_info *info);
123 /* Request format for this request. */
124 const struct req_format *mh_fmt;
127 enum mdt_handler_flags {
129 * struct mdt_body is passed in the incoming message, and object
130 * identified by this fid exists on disk.
132 * "habeo corpus" == "I have a body"
134 HABEO_CORPUS = (1 << 0),
136 * struct ldlm_request is passed in the incoming message.
138 * "habeo clavis" == "I have a key"
140 HABEO_CLAVIS = (1 << 1),
142 * this request has fixed reply format, so that reply message can be
143 * packed by generic code.
145 * "habeo refero" == "I have a reply"
147 HABEO_REFERO = (1 << 2),
149 * this request will modify something, so check whether the filesystem
150 * is readonly or not, then return -EROFS to client asap if necessary.
152 * "mutabor" == "I shall modify"
157 struct mdt_opc_slice {
160 struct mdt_handler *mos_hs;
163 static struct mdt_opc_slice mdt_regular_handlers[];
164 static struct mdt_opc_slice mdt_readpage_handlers[];
165 static struct mdt_opc_slice mdt_xmds_handlers[];
166 static struct mdt_opc_slice mdt_seq_handlers[];
167 static struct mdt_opc_slice mdt_fld_handlers[];
169 static struct mdt_device *mdt_dev(struct lu_device *d);
170 static int mdt_regular_handle(struct ptlrpc_request *req);
171 static int mdt_unpack_req_pack_rep(struct mdt_thread_info *info, __u32 flags);
172 static int mdt_fid2path(const struct lu_env *env, struct mdt_device *mdt,
173 struct getinfo_fid2path *fp);
175 static const struct lu_object_operations mdt_obj_ops;
177 int mdt_get_disposition(struct ldlm_reply *rep, int flag)
181 return (rep->lock_policy_res1 & flag);
184 void mdt_clear_disposition(struct mdt_thread_info *info,
185 struct ldlm_reply *rep, int flag)
188 info->mti_opdata &= ~flag;
190 rep->lock_policy_res1 &= ~flag;
193 void mdt_set_disposition(struct mdt_thread_info *info,
194 struct ldlm_reply *rep, int flag)
197 info->mti_opdata |= flag;
199 rep->lock_policy_res1 |= flag;
202 void mdt_lock_reg_init(struct mdt_lock_handle *lh, ldlm_mode_t lm)
204 lh->mlh_pdo_hash = 0;
205 lh->mlh_reg_mode = lm;
206 lh->mlh_type = MDT_REG_LOCK;
209 void mdt_lock_pdo_init(struct mdt_lock_handle *lh, ldlm_mode_t lm,
210 const char *name, int namelen)
212 lh->mlh_reg_mode = lm;
213 lh->mlh_type = MDT_PDO_LOCK;
215 if (name != NULL && (name[0] != '\0')) {
216 LASSERT(namelen > 0);
217 lh->mlh_pdo_hash = full_name_hash(name, namelen);
219 LASSERT(namelen == 0);
220 lh->mlh_pdo_hash = 0ull;
224 static void mdt_lock_pdo_mode(struct mdt_thread_info *info, struct mdt_object *o,
225 struct mdt_lock_handle *lh)
231 * Any dir access needs couple of locks:
233 * 1) on part of dir we gonna take lookup/modify;
235 * 2) on whole dir to protect it from concurrent splitting and/or to
236 * flush client's cache for readdir().
238 * so, for a given mode and object this routine decides what lock mode
239 * to use for lock #2:
241 * 1) if caller's gonna lookup in dir then we need to protect dir from
242 * being splitted only - LCK_CR
244 * 2) if caller's gonna modify dir then we need to protect dir from
245 * being splitted and to flush cache - LCK_CW
247 * 3) if caller's gonna modify dir and that dir seems ready for
248 * splitting then we need to protect it from any type of access
249 * (lookup/modify/split) - LCK_EX --bzzz
252 LASSERT(lh->mlh_reg_mode != LCK_MINMODE);
253 LASSERT(lh->mlh_pdo_mode == LCK_MINMODE);
256 * Ask underlaying level its opinion about preferable PDO lock mode
257 * having access type passed as regular lock mode:
259 * - MDL_MINMODE means that lower layer does not want to specify lock
262 * - MDL_NL means that no PDO lock should be taken. This is used in some
263 * cases. Say, for non-splittable directories no need to use PDO locks
266 mode = mdo_lock_mode(info->mti_env, mdt_object_child(o),
267 mdt_dlm_mode2mdl_mode(lh->mlh_reg_mode));
269 if (mode != MDL_MINMODE) {
270 lh->mlh_pdo_mode = mdt_mdl_mode2dlm_mode(mode);
273 * Lower layer does not want to specify locking mode. We do it
274 * our selves. No special protection is needed, just flush
275 * client's cache on modification and allow concurrent
278 switch (lh->mlh_reg_mode) {
280 lh->mlh_pdo_mode = LCK_EX;
283 lh->mlh_pdo_mode = LCK_CR;
286 lh->mlh_pdo_mode = LCK_CW;
289 CERROR("Not expected lock type (0x%x)\n",
290 (int)lh->mlh_reg_mode);
295 LASSERT(lh->mlh_pdo_mode != LCK_MINMODE);
299 static int mdt_getstatus(struct mdt_thread_info *info)
301 struct mdt_device *mdt = info->mti_mdt;
302 struct md_device *next = mdt->mdt_child;
303 struct mdt_body *repbody;
308 rc = mdt_check_ucred(info);
310 RETURN(err_serious(rc));
312 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_GETSTATUS_PACK))
313 RETURN(err_serious(-ENOMEM));
315 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
316 rc = next->md_ops->mdo_root_get(info->mti_env, next, &repbody->fid1);
320 repbody->valid |= OBD_MD_FLID;
322 if (mdt->mdt_opts.mo_mds_capa &&
323 info->mti_exp->exp_connect_flags & OBD_CONNECT_MDS_CAPA) {
324 struct mdt_object *root;
325 struct lustre_capa *capa;
327 root = mdt_object_find(info->mti_env, mdt, &repbody->fid1);
329 RETURN(PTR_ERR(root));
331 capa = req_capsule_server_get(info->mti_pill, &RMF_CAPA1);
333 capa->lc_opc = CAPA_OPC_MDS_DEFAULT;
334 rc = mo_capa_get(info->mti_env, mdt_object_child(root), capa,
336 mdt_object_put(info->mti_env, root);
338 repbody->valid |= OBD_MD_FLMDSCAPA;
344 static int mdt_statfs(struct mdt_thread_info *info)
346 struct ptlrpc_request *req = mdt_info_req(info);
347 struct md_device *next = info->mti_mdt->mdt_child;
348 struct ptlrpc_service *svc;
349 struct obd_statfs *osfs;
354 svc = info->mti_pill->rc_req->rq_rqbd->rqbd_service;
356 /* This will trigger a watchdog timeout */
357 OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_STATFS_LCW_SLEEP,
358 (MDT_SERVICE_WATCHDOG_FACTOR *
359 at_get(&svc->srv_at_estimate)) + 1);
361 rc = mdt_check_ucred(info);
363 RETURN(err_serious(rc));
365 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_STATFS_PACK)) {
366 rc = err_serious(-ENOMEM);
368 osfs = req_capsule_server_get(info->mti_pill, &RMF_OBD_STATFS);
369 rc = next->md_ops->mdo_statfs(info->mti_env, next, osfs);
373 mdt_counter_incr(req->rq_export, LPROC_MDT_STATFS);
379 * Pack SOM attributes into the reply.
380 * Call under a DLM UPDATE lock.
382 static void mdt_pack_size2body(struct mdt_thread_info *info,
383 struct mdt_object *mo)
386 struct md_attr *ma = &info->mti_attr;
388 LASSERT(ma->ma_attr.la_valid & LA_MODE);
389 b = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
391 /* Check if Size-on-MDS is supported, if this is a regular file,
392 * if SOM is enabled on the object and if SOM cache exists and valid.
393 * Otherwise do not pack Size-on-MDS attributes to the reply. */
394 if (!(mdt_conn_flags(info) & OBD_CONNECT_SOM) ||
395 !S_ISREG(ma->ma_attr.la_mode) ||
396 !mdt_object_is_som_enabled(mo) ||
397 !(ma->ma_valid & MA_SOM))
400 b->valid |= OBD_MD_FLSIZE | OBD_MD_FLBLOCKS;
401 b->size = ma->ma_som->msd_size;
402 b->blocks = ma->ma_som->msd_blocks;
405 void mdt_pack_attr2body(struct mdt_thread_info *info, struct mdt_body *b,
406 const struct lu_attr *attr, const struct lu_fid *fid)
408 struct md_attr *ma = &info->mti_attr;
410 LASSERT(ma->ma_valid & MA_INODE);
412 b->atime = attr->la_atime;
413 b->mtime = attr->la_mtime;
414 b->ctime = attr->la_ctime;
415 b->mode = attr->la_mode;
416 b->size = attr->la_size;
417 b->blocks = attr->la_blocks;
418 b->uid = attr->la_uid;
419 b->gid = attr->la_gid;
420 b->flags = attr->la_flags;
421 b->nlink = attr->la_nlink;
422 b->rdev = attr->la_rdev;
424 /*XXX should pack the reply body according to lu_valid*/
425 b->valid |= OBD_MD_FLCTIME | OBD_MD_FLUID |
426 OBD_MD_FLGID | OBD_MD_FLTYPE |
427 OBD_MD_FLMODE | OBD_MD_FLNLINK | OBD_MD_FLFLAGS |
428 OBD_MD_FLATIME | OBD_MD_FLMTIME ;
430 if (!S_ISREG(attr->la_mode)) {
431 b->valid |= OBD_MD_FLSIZE | OBD_MD_FLBLOCKS | OBD_MD_FLRDEV;
432 } else if (ma->ma_need & MA_LOV && ma->ma_lmm_size == 0) {
433 /* means no objects are allocated on osts. */
434 LASSERT(!(ma->ma_valid & MA_LOV));
435 /* just ignore blocks occupied by extend attributes on MDS */
437 /* if no object is allocated on osts, the size on mds is valid. b=22272 */
438 b->valid |= OBD_MD_FLSIZE | OBD_MD_FLBLOCKS;
443 b->valid |= OBD_MD_FLID;
445 /* FIXME: these should be fixed when new igif ready.*/
446 b->ino = fid_oid(fid); /* 1.6 compatibility */
447 b->generation = fid_ver(fid); /* 1.6 compatibility */
448 b->valid |= OBD_MD_FLGENER; /* 1.6 compatibility */
450 CDEBUG(D_INODE, DFID": nlink=%d, mode=%o, size="LPU64"\n",
451 PFID(fid), b->nlink, b->mode, b->size);
455 mdt_body_reverse_idmap(info, b);
457 if (b->valid & OBD_MD_FLSIZE)
458 CDEBUG(D_VFSTRACE, DFID": returning size %llu\n",
459 PFID(fid), (unsigned long long)b->size);
462 static inline int mdt_body_has_lov(const struct lu_attr *la,
463 const struct mdt_body *body)
465 return ((S_ISREG(la->la_mode) && (body->valid & OBD_MD_FLEASIZE)) ||
466 (S_ISDIR(la->la_mode) && (body->valid & OBD_MD_FLDIREA )) );
469 void mdt_client_compatibility(struct mdt_thread_info *info)
471 struct mdt_body *body;
472 struct ptlrpc_request *req = mdt_info_req(info);
473 struct obd_export *exp = req->rq_export;
474 struct md_attr *ma = &info->mti_attr;
475 struct lu_attr *la = &ma->ma_attr;
478 if (exp->exp_connect_flags & OBD_CONNECT_LAYOUTLOCK)
479 /* the client can deal with 16-bit lmm_stripe_count */
482 body = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
484 if (!mdt_body_has_lov(la, body))
487 /* now we have a reply with a lov for a client not compatible with the
488 * layout lock so we have to clean the layout generation number */
489 if (S_ISREG(la->la_mode))
490 ma->ma_lmm->lmm_layout_gen = 0;
495 static int mdt_getattr_internal(struct mdt_thread_info *info,
496 struct mdt_object *o, int ma_need)
498 struct md_object *next = mdt_object_child(o);
499 const struct mdt_body *reqbody = info->mti_body;
500 struct ptlrpc_request *req = mdt_info_req(info);
501 struct md_attr *ma = &info->mti_attr;
502 struct lu_attr *la = &ma->ma_attr;
503 struct req_capsule *pill = info->mti_pill;
504 const struct lu_env *env = info->mti_env;
505 struct mdt_body *repbody;
506 struct lu_buf *buffer = &info->mti_buf;
510 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_GETATTR_PACK))
511 RETURN(err_serious(-ENOMEM));
513 repbody = req_capsule_server_get(pill, &RMF_MDT_BODY);
517 rc = mdt_object_exists(o);
519 /* This object is located on remote node.*/
520 repbody->fid1 = *mdt_object_fid(o);
521 repbody->valid = OBD_MD_FLID | OBD_MD_MDS;
525 buffer->lb_buf = req_capsule_server_get(pill, &RMF_MDT_MD);
526 buffer->lb_len = req_capsule_get_size(pill, &RMF_MDT_MD, RCL_SERVER);
528 /* If it is dir object and client require MEA, then we got MEA */
529 if (S_ISDIR(lu_object_attr(&next->mo_lu)) &&
530 reqbody->valid & OBD_MD_MEA) {
531 /* Assumption: MDT_MD size is enough for lmv size. */
532 ma->ma_lmv = buffer->lb_buf;
533 ma->ma_lmv_size = buffer->lb_len;
534 ma->ma_need = MA_LMV | MA_INODE;
536 ma->ma_lmm = buffer->lb_buf;
537 ma->ma_lmm_size = buffer->lb_len;
538 ma->ma_need = MA_LOV | MA_INODE;
541 if (S_ISDIR(lu_object_attr(&next->mo_lu)) &&
542 reqbody->valid & OBD_MD_FLDIREA &&
543 lustre_msg_get_opc(req->rq_reqmsg) == MDS_GETATTR) {
544 /* get default stripe info for this dir. */
545 ma->ma_need |= MA_LOV_DEF;
547 ma->ma_need |= ma_need;
548 if (ma->ma_need & MA_SOM)
549 ma->ma_som = &info->mti_u.som.data;
551 rc = mo_attr_get(env, next, ma);
553 CERROR("getattr error for "DFID": %d\n",
554 PFID(mdt_object_fid(o)), rc);
558 if (likely(ma->ma_valid & MA_INODE))
559 mdt_pack_attr2body(info, repbody, la, mdt_object_fid(o));
563 if (mdt_body_has_lov(la, reqbody)) {
564 if (ma->ma_valid & MA_LOV) {
565 LASSERT(ma->ma_lmm_size);
566 mdt_dump_lmm(D_INFO, ma->ma_lmm);
567 repbody->eadatasize = ma->ma_lmm_size;
568 if (S_ISDIR(la->la_mode))
569 repbody->valid |= OBD_MD_FLDIREA;
571 repbody->valid |= OBD_MD_FLEASIZE;
573 if (ma->ma_valid & MA_LMV) {
574 LASSERT(S_ISDIR(la->la_mode));
575 repbody->eadatasize = ma->ma_lmv_size;
576 repbody->valid |= (OBD_MD_FLDIREA|OBD_MD_MEA);
578 } else if (S_ISLNK(la->la_mode) &&
579 reqbody->valid & OBD_MD_LINKNAME) {
580 buffer->lb_buf = ma->ma_lmm;
581 buffer->lb_len = reqbody->eadatasize;
582 rc = mo_readlink(env, next, buffer);
583 if (unlikely(rc <= 0)) {
584 CERROR("readlink failed: %d\n", rc);
587 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_READLINK_EPROTO))
589 repbody->valid |= OBD_MD_LINKNAME;
590 repbody->eadatasize = rc;
592 ((char*)ma->ma_lmm)[rc - 1] = 0;
593 CDEBUG(D_INODE, "symlink dest %s, len = %d\n",
594 (char*)ma->ma_lmm, rc);
599 if (reqbody->valid & OBD_MD_FLMODEASIZE) {
600 repbody->max_cookiesize = info->mti_mdt->mdt_max_cookiesize;
601 repbody->max_mdsize = info->mti_mdt->mdt_max_mdsize;
602 repbody->valid |= OBD_MD_FLMODEASIZE;
603 CDEBUG(D_INODE, "I am going to change the MAX_MD_SIZE & "
604 "MAX_COOKIE to : %d:%d\n", repbody->max_mdsize,
605 repbody->max_cookiesize);
608 if (exp_connect_rmtclient(info->mti_exp) &&
609 reqbody->valid & OBD_MD_FLRMTPERM) {
610 void *buf = req_capsule_server_get(pill, &RMF_ACL);
612 /* mdt_getattr_lock only */
613 rc = mdt_pack_remote_perm(info, o, buf);
615 repbody->valid &= ~OBD_MD_FLRMTPERM;
616 repbody->aclsize = 0;
619 repbody->valid |= OBD_MD_FLRMTPERM;
620 repbody->aclsize = sizeof(struct mdt_remote_perm);
623 #ifdef CONFIG_FS_POSIX_ACL
624 else if ((req->rq_export->exp_connect_flags & OBD_CONNECT_ACL) &&
625 (reqbody->valid & OBD_MD_FLACL)) {
626 buffer->lb_buf = req_capsule_server_get(pill, &RMF_ACL);
627 buffer->lb_len = req_capsule_get_size(pill,
628 &RMF_ACL, RCL_SERVER);
629 if (buffer->lb_len > 0) {
630 rc = mo_xattr_get(env, next, buffer,
631 XATTR_NAME_ACL_ACCESS);
633 if (rc == -ENODATA) {
634 repbody->aclsize = 0;
635 repbody->valid |= OBD_MD_FLACL;
637 } else if (rc == -EOPNOTSUPP) {
640 CERROR("got acl size: %d\n", rc);
643 repbody->aclsize = rc;
644 repbody->valid |= OBD_MD_FLACL;
651 if (reqbody->valid & OBD_MD_FLMDSCAPA &&
652 info->mti_mdt->mdt_opts.mo_mds_capa &&
653 info->mti_exp->exp_connect_flags & OBD_CONNECT_MDS_CAPA) {
654 struct lustre_capa *capa;
656 capa = req_capsule_server_get(pill, &RMF_CAPA1);
658 capa->lc_opc = CAPA_OPC_MDS_DEFAULT;
659 rc = mo_capa_get(env, next, capa, 0);
662 repbody->valid |= OBD_MD_FLMDSCAPA;
667 static int mdt_renew_capa(struct mdt_thread_info *info)
669 struct mdt_object *obj = info->mti_object;
670 struct mdt_body *body;
671 struct lustre_capa *capa, *c;
675 /* if object doesn't exist, or server has disabled capability,
676 * return directly, client will find body->valid OBD_MD_FLOSSCAPA
679 if (!obj || !info->mti_mdt->mdt_opts.mo_oss_capa ||
680 !(info->mti_exp->exp_connect_flags & OBD_CONNECT_OSS_CAPA))
683 body = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
684 LASSERT(body != NULL);
686 c = req_capsule_client_get(info->mti_pill, &RMF_CAPA1);
689 capa = req_capsule_server_get(info->mti_pill, &RMF_CAPA2);
693 rc = mo_capa_get(info->mti_env, mdt_object_child(obj), capa, 1);
695 body->valid |= OBD_MD_FLOSSCAPA;
699 static int mdt_getattr(struct mdt_thread_info *info)
701 struct ptlrpc_request *req = mdt_info_req(info);
702 struct mdt_object *obj = info->mti_object;
703 struct req_capsule *pill = info->mti_pill;
704 struct mdt_body *reqbody;
705 struct mdt_body *repbody;
710 reqbody = req_capsule_client_get(pill, &RMF_MDT_BODY);
713 if (reqbody->valid & OBD_MD_FLOSSCAPA) {
714 rc = req_capsule_server_pack(pill);
716 RETURN(err_serious(rc));
717 rc = mdt_renew_capa(info);
718 GOTO(out_shrink, rc);
721 LASSERT(obj != NULL);
722 LASSERT(lu_object_assert_exists(&obj->mot_obj.mo_lu));
724 mode = lu_object_attr(&obj->mot_obj.mo_lu);
726 /* old clients may not report needed easize, use max value then */
727 req_capsule_set_size(pill, &RMF_MDT_MD, RCL_SERVER,
728 reqbody->eadatasize == 0 ?
729 info->mti_mdt->mdt_max_mdsize :
730 reqbody->eadatasize);
732 rc = req_capsule_server_pack(pill);
733 if (unlikely(rc != 0))
734 RETURN(err_serious(rc));
736 repbody = req_capsule_server_get(pill, &RMF_MDT_BODY);
737 LASSERT(repbody != NULL);
738 repbody->eadatasize = 0;
739 repbody->aclsize = 0;
741 if (reqbody->valid & OBD_MD_FLRMTPERM)
742 rc = mdt_init_ucred(info, reqbody);
744 rc = mdt_check_ucred(info);
746 GOTO(out_shrink, rc);
748 info->mti_spec.sp_ck_split = !!(reqbody->valid & OBD_MD_FLCKSPLIT);
749 info->mti_cross_ref = !!(reqbody->valid & OBD_MD_FLCROSSREF);
752 * Don't check capability at all, because rename might getattr for
753 * remote obj, and at that time no capability is available.
755 mdt_set_capainfo(info, 1, &reqbody->fid1, BYPASS_CAPA);
756 rc = mdt_getattr_internal(info, obj, 0);
757 if (reqbody->valid & OBD_MD_FLRMTPERM)
758 mdt_exit_ucred(info);
762 mdt_counter_incr(req->rq_export, LPROC_MDT_GETATTR);
764 mdt_client_compatibility(info);
765 rc2 = mdt_fix_reply(info);
771 static int mdt_is_subdir(struct mdt_thread_info *info)
773 struct mdt_object *o = info->mti_object;
774 struct req_capsule *pill = info->mti_pill;
775 const struct mdt_body *body = info->mti_body;
776 struct mdt_body *repbody;
782 repbody = req_capsule_server_get(pill, &RMF_MDT_BODY);
785 * We save last checked parent fid to @repbody->fid1 for remote
788 LASSERT(fid_is_sane(&body->fid2));
789 LASSERT(mdt_object_exists(o) > 0);
790 rc = mdo_is_subdir(info->mti_env, mdt_object_child(o),
791 &body->fid2, &repbody->fid1);
792 if (rc == 0 || rc == -EREMOTE)
793 repbody->valid |= OBD_MD_FLID;
798 static int mdt_raw_lookup(struct mdt_thread_info *info,
799 struct mdt_object *parent,
800 const struct lu_name *lname,
801 struct ldlm_reply *ldlm_rep)
803 struct md_object *next = mdt_object_child(info->mti_object);
804 const struct mdt_body *reqbody = info->mti_body;
805 struct lu_fid *child_fid = &info->mti_tmp_fid1;
806 struct mdt_body *repbody;
810 if (reqbody->valid != OBD_MD_FLID)
813 LASSERT(!info->mti_cross_ref);
815 /* Only got the fid of this obj by name */
817 rc = mdo_lookup(info->mti_env, next, lname, child_fid,
820 /* XXX is raw_lookup possible as intent operation? */
823 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_NEG);
826 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_POS);
828 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
831 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
832 repbody->fid1 = *child_fid;
833 repbody->valid = OBD_MD_FLID;
839 * UPDATE lock should be taken against parent, and be release before exit;
840 * child_bits lock should be taken against child, and be returned back:
841 * (1)normal request should release the child lock;
842 * (2)intent request will grant the lock to client.
844 static int mdt_getattr_name_lock(struct mdt_thread_info *info,
845 struct mdt_lock_handle *lhc,
847 struct ldlm_reply *ldlm_rep)
849 struct ptlrpc_request *req = mdt_info_req(info);
850 struct mdt_body *reqbody = NULL;
851 struct mdt_object *parent = info->mti_object;
852 struct mdt_object *child;
853 struct md_object *next = mdt_object_child(parent);
854 struct lu_fid *child_fid = &info->mti_tmp_fid1;
855 struct lu_name *lname = NULL;
856 const char *name = NULL;
858 struct mdt_lock_handle *lhp = NULL;
859 struct ldlm_lock *lock;
860 struct ldlm_res_id *res_id;
867 is_resent = lustre_handle_is_used(&lhc->mlh_reg_lh);
868 LASSERT(ergo(is_resent,
869 lustre_msg_get_flags(req->rq_reqmsg) & MSG_RESENT));
871 LASSERT(parent != NULL);
872 name = req_capsule_client_get(info->mti_pill, &RMF_NAME);
874 RETURN(err_serious(-EFAULT));
876 namelen = req_capsule_get_size(info->mti_pill, &RMF_NAME,
878 if (!info->mti_cross_ref) {
880 * XXX: Check for "namelen == 0" is for getattr by fid
881 * (OBD_CONNECT_ATTRFID), otherwise do not allow empty name,
882 * that is the name must contain at least one character and
883 * the terminating '\0'
886 reqbody = req_capsule_client_get(info->mti_pill,
888 if (unlikely(reqbody == NULL))
889 RETURN(err_serious(-EFAULT));
891 if (unlikely(!fid_is_sane(&reqbody->fid2)))
892 RETURN(err_serious(-EINVAL));
895 CDEBUG(D_INODE, "getattr with lock for "DFID"/"DFID", "
897 PFID(mdt_object_fid(parent)),
898 PFID(&reqbody->fid2), ldlm_rep);
900 lname = mdt_name(info->mti_env, (char *)name, namelen);
901 CDEBUG(D_INODE, "getattr with lock for "DFID"/%s, "
902 "ldlm_rep = %p\n", PFID(mdt_object_fid(parent)),
906 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_EXECD);
908 rc = mdt_object_exists(parent);
909 if (unlikely(rc == 0)) {
910 LU_OBJECT_DEBUG(D_WARNING, info->mti_env,
911 &parent->mot_obj.mo_lu,
912 "Parent doesn't exist!\n");
914 } else if (!info->mti_cross_ref) {
915 LASSERTF(rc > 0, "Parent "DFID" is on remote server\n",
916 PFID(mdt_object_fid(parent)));
919 rc = mdt_raw_lookup(info, parent, lname, ldlm_rep);
927 if (info->mti_cross_ref) {
928 /* Only getattr on the child. Parent is on another node. */
929 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_POS);
931 CDEBUG(D_INODE, "partial getattr_name child_fid = "DFID", "
932 "ldlm_rep=%p\n", PFID(mdt_object_fid(child)), ldlm_rep);
935 /* Do not take lock for resent case. */
936 lock = ldlm_handle2lock(&lhc->mlh_reg_lh);
937 LASSERTF(lock != NULL, "Invalid lock handle "LPX64"\n",
938 lhc->mlh_reg_lh.cookie);
939 LASSERT(fid_res_name_eq(mdt_object_fid(child),
940 &lock->l_resource->lr_name));
944 mdt_lock_handle_init(lhc);
945 mdt_lock_reg_init(lhc, LCK_PR);
948 * Object's name is on another MDS, no lookup lock is
949 * needed here but update is.
951 child_bits &= ~MDS_INODELOCK_LOOKUP;
952 child_bits |= MDS_INODELOCK_UPDATE;
954 rc = mdt_object_lock(info, child, lhc, child_bits,
958 /* Finally, we can get attr for child. */
959 mdt_set_capainfo(info, 0, mdt_object_fid(child),
961 rc = mdt_getattr_internal(info, child, 0);
962 if (unlikely(rc != 0))
963 mdt_object_unlock(info, child, lhc, 1);
969 /* step 1: lock parent only if parent is a directory */
970 if (S_ISDIR(lu_object_attr(&parent->mot_obj.mo_lu))) {
971 lhp = &info->mti_lh[MDT_LH_PARENT];
972 mdt_lock_pdo_init(lhp, LCK_PR, name, namelen);
973 rc = mdt_object_lock(info, parent, lhp,
974 MDS_INODELOCK_UPDATE,
976 if (unlikely(rc != 0))
980 /* step 2: lookup child's fid by name */
982 rc = mdo_lookup(info->mti_env, next, lname, child_fid,
987 mdt_set_disposition(info, ldlm_rep,
989 GOTO(out_parent, rc);
991 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_POS);
993 *child_fid = reqbody->fid2;
994 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_POS);
998 *step 3: find the child object by fid & lock it.
999 * regardless if it is local or remote.
1001 child = mdt_object_find(info->mti_env, info->mti_mdt, child_fid);
1003 if (unlikely(IS_ERR(child)))
1004 GOTO(out_parent, rc = PTR_ERR(child));
1006 /* Do not take lock for resent case. */
1007 lock = ldlm_handle2lock(&lhc->mlh_reg_lh);
1008 LASSERTF(lock != NULL, "Invalid lock handle "LPX64"\n",
1009 lhc->mlh_reg_lh.cookie);
1011 res_id = &lock->l_resource->lr_name;
1012 if (!fid_res_name_eq(mdt_object_fid(child),
1013 &lock->l_resource->lr_name)) {
1014 LASSERTF(fid_res_name_eq(mdt_object_fid(parent),
1015 &lock->l_resource->lr_name),
1016 "Lock res_id: %lu/%lu/%lu, Fid: "DFID".\n",
1017 (unsigned long)res_id->name[0],
1018 (unsigned long)res_id->name[1],
1019 (unsigned long)res_id->name[2],
1020 PFID(mdt_object_fid(parent)));
1021 CWARN("Although resent, but still not get child lock"
1022 "parent:"DFID" child:"DFID"\n",
1023 PFID(mdt_object_fid(parent)),
1024 PFID(mdt_object_fid(child)));
1025 lustre_msg_clear_flags(req->rq_reqmsg, MSG_RESENT);
1026 LDLM_LOCK_PUT(lock);
1029 LDLM_LOCK_PUT(lock);
1033 OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_RESEND, obd_timeout*2);
1034 mdt_lock_handle_init(lhc);
1035 if (child_bits == MDS_INODELOCK_LAYOUT)
1036 mdt_lock_reg_init(lhc, LCK_CR);
1038 mdt_lock_reg_init(lhc, LCK_PR);
1040 if (mdt_object_exists(child) == 0) {
1041 LU_OBJECT_DEBUG(D_INODE, info->mti_env,
1042 &child->mot_obj.mo_lu,
1043 "Object doesn't exist!\n");
1044 GOTO(out_child, rc = -ENOENT);
1047 if (!(child_bits & MDS_INODELOCK_UPDATE)) {
1048 struct md_attr *ma = &info->mti_attr;
1051 ma->ma_need = MA_INODE;
1052 rc = mo_attr_get(info->mti_env,
1053 mdt_object_child(child), ma);
1054 if (unlikely(rc != 0))
1055 GOTO(out_child, rc);
1057 /* layout lock is used only on regular files */
1058 if ((ma->ma_valid & MA_INODE) &&
1059 (ma->ma_attr.la_valid & LA_MODE) &&
1060 !S_ISREG(ma->ma_attr.la_mode))
1061 child_bits &= ~MDS_INODELOCK_LAYOUT;
1063 /* If the file has not been changed for some time, we
1064 * return not only a LOOKUP lock, but also an UPDATE
1065 * lock and this might save us RPC on later STAT. For
1066 * directories, it also let negative dentry starts
1067 * working for this dir. */
1068 if (ma->ma_valid & MA_INODE &&
1069 ma->ma_attr.la_valid & LA_CTIME &&
1070 info->mti_mdt->mdt_namespace->ns_ctime_age_limit +
1071 ma->ma_attr.la_ctime < cfs_time_current_sec())
1072 child_bits |= MDS_INODELOCK_UPDATE;
1075 rc = mdt_object_lock(info, child, lhc, child_bits,
1078 if (unlikely(rc != 0))
1079 GOTO(out_child, rc);
1082 lock = ldlm_handle2lock(&lhc->mlh_reg_lh);
1083 /* Get MA_SOM attributes if update lock is given. */
1085 lock->l_policy_data.l_inodebits.bits & MDS_INODELOCK_UPDATE &&
1086 S_ISREG(lu_object_attr(&mdt_object_child(child)->mo_lu)))
1089 /* finally, we can get attr for child. */
1090 mdt_set_capainfo(info, 1, child_fid, BYPASS_CAPA);
1091 rc = mdt_getattr_internal(info, child, ma_need);
1092 if (unlikely(rc != 0)) {
1093 mdt_object_unlock(info, child, lhc, 1);
1095 /* Debugging code. */
1096 res_id = &lock->l_resource->lr_name;
1097 LDLM_DEBUG(lock, "Returning lock to client");
1098 LASSERTF(fid_res_name_eq(mdt_object_fid(child),
1099 &lock->l_resource->lr_name),
1100 "Lock res_id: %lu/%lu/%lu, Fid: "DFID".\n",
1101 (unsigned long)res_id->name[0],
1102 (unsigned long)res_id->name[1],
1103 (unsigned long)res_id->name[2],
1104 PFID(mdt_object_fid(child)));
1105 mdt_pack_size2body(info, child);
1108 LDLM_LOCK_PUT(lock);
1112 mdt_object_put(info->mti_env, child);
1115 mdt_object_unlock(info, parent, lhp, 1);
1119 /* normal handler: should release the child lock */
1120 static int mdt_getattr_name(struct mdt_thread_info *info)
1122 struct mdt_lock_handle *lhc = &info->mti_lh[MDT_LH_CHILD];
1123 struct mdt_body *reqbody;
1124 struct mdt_body *repbody;
1128 reqbody = req_capsule_client_get(info->mti_pill, &RMF_MDT_BODY);
1129 LASSERT(reqbody != NULL);
1130 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
1131 LASSERT(repbody != NULL);
1133 info->mti_spec.sp_ck_split = !!(reqbody->valid & OBD_MD_FLCKSPLIT);
1134 info->mti_cross_ref = !!(reqbody->valid & OBD_MD_FLCROSSREF);
1135 repbody->eadatasize = 0;
1136 repbody->aclsize = 0;
1138 rc = mdt_init_ucred(info, reqbody);
1140 GOTO(out_shrink, rc);
1142 rc = mdt_getattr_name_lock(info, lhc, MDS_INODELOCK_UPDATE, NULL);
1143 if (lustre_handle_is_used(&lhc->mlh_reg_lh)) {
1144 ldlm_lock_decref(&lhc->mlh_reg_lh, lhc->mlh_reg_mode);
1145 lhc->mlh_reg_lh.cookie = 0;
1147 mdt_exit_ucred(info);
1150 mdt_client_compatibility(info);
1151 rc2 = mdt_fix_reply(info);
1157 static const struct lu_device_operations mdt_lu_ops;
1159 static int lu_device_is_mdt(struct lu_device *d)
1161 return ergo(d != NULL && d->ld_ops != NULL, d->ld_ops == &mdt_lu_ops);
1164 static int mdt_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
1165 void *karg, void *uarg);
1167 static int mdt_set_info(struct mdt_thread_info *info)
1169 struct ptlrpc_request *req = mdt_info_req(info);
1172 int keylen, vallen, rc = 0;
1175 rc = req_capsule_server_pack(info->mti_pill);
1179 key = req_capsule_client_get(info->mti_pill, &RMF_SETINFO_KEY);
1181 DEBUG_REQ(D_HA, req, "no set_info key");
1185 keylen = req_capsule_get_size(info->mti_pill, &RMF_SETINFO_KEY,
1188 val = req_capsule_client_get(info->mti_pill, &RMF_SETINFO_VAL);
1190 DEBUG_REQ(D_HA, req, "no set_info val");
1194 vallen = req_capsule_get_size(info->mti_pill, &RMF_SETINFO_VAL,
1197 /* Swab any part of val you need to here */
1198 if (KEY_IS(KEY_READ_ONLY)) {
1200 lustre_msg_set_status(req->rq_repmsg, 0);
1202 cfs_spin_lock(&req->rq_export->exp_lock);
1204 req->rq_export->exp_connect_flags |= OBD_CONNECT_RDONLY;
1206 req->rq_export->exp_connect_flags &=~OBD_CONNECT_RDONLY;
1207 cfs_spin_unlock(&req->rq_export->exp_lock);
1209 } else if (KEY_IS(KEY_CHANGELOG_CLEAR)) {
1210 struct changelog_setinfo *cs =
1211 (struct changelog_setinfo *)val;
1212 if (vallen != sizeof(*cs)) {
1213 CERROR("Bad changelog_clear setinfo size %d\n", vallen);
1216 if (ptlrpc_req_need_swab(req)) {
1217 __swab64s(&cs->cs_recno);
1218 __swab32s(&cs->cs_id);
1221 rc = mdt_iocontrol(OBD_IOC_CHANGELOG_CLEAR, info->mti_exp,
1223 lustre_msg_set_status(req->rq_repmsg, rc);
1231 static int mdt_connect(struct mdt_thread_info *info)
1234 struct ptlrpc_request *req;
1236 req = mdt_info_req(info);
1237 rc = target_handle_connect(req);
1239 LASSERT(req->rq_export != NULL);
1240 info->mti_mdt = mdt_dev(req->rq_export->exp_obd->obd_lu_dev);
1241 rc = mdt_init_sec_level(info);
1243 rc = mdt_init_idmap(info);
1245 obd_disconnect(class_export_get(req->rq_export));
1247 rc = err_serious(rc);
1252 static int mdt_disconnect(struct mdt_thread_info *info)
1257 rc = target_handle_disconnect(mdt_info_req(info));
1259 rc = err_serious(rc);
1263 static int mdt_sendpage(struct mdt_thread_info *info,
1264 struct lu_rdpg *rdpg, int nob)
1266 struct ptlrpc_request *req = mdt_info_req(info);
1267 struct obd_export *exp = req->rq_export;
1268 struct ptlrpc_bulk_desc *desc;
1269 struct l_wait_info *lwi = &info->mti_u.rdpg.mti_wait_info;
1276 desc = ptlrpc_prep_bulk_exp(req, rdpg->rp_npages, BULK_PUT_SOURCE,
1281 for (i = 0, tmpcount = nob;
1282 i < rdpg->rp_npages && tmpcount > 0; i++, tmpcount -= tmpsize) {
1283 tmpsize = min_t(int, tmpcount, CFS_PAGE_SIZE);
1284 ptlrpc_prep_bulk_page(desc, rdpg->rp_pages[i], 0, tmpsize);
1287 LASSERT(desc->bd_nob == nob);
1288 rc = target_bulk_io(exp, desc, lwi);
1289 ptlrpc_free_bulk(desc);
1293 #ifdef HAVE_SPLIT_SUPPORT
1295 * Retrieve dir entry from the page and insert it to the slave object, actually,
1296 * this should be in osd layer, but since it will not in the final product, so
1297 * just do it here and do not define more moo api anymore for this.
1299 static int mdt_write_dir_page(struct mdt_thread_info *info, struct page *page,
1302 struct mdt_object *object = info->mti_object;
1303 struct lu_fid *lf = &info->mti_tmp_fid2;
1304 struct md_attr *ma = &info->mti_attr;
1305 struct lu_dirpage *dp;
1306 struct lu_dirent *ent;
1307 int rc = 0, offset = 0;
1310 /* Make sure we have at least one entry. */
1315 * Disable trans for this name insert, since it will include many trans
1318 info->mti_no_need_trans = 1;
1320 * When write_dir_page, no need update parent's ctime,
1321 * and no permission check for name_insert.
1323 ma->ma_attr.la_ctime = 0;
1324 ma->ma_attr.la_valid = LA_MODE;
1325 ma->ma_valid = MA_INODE;
1328 dp = page_address(page);
1329 offset = (int)((__u32)lu_dirent_start(dp) - (__u32)dp);
1331 for (ent = lu_dirent_start(dp); ent != NULL;
1332 ent = lu_dirent_next(ent)) {
1333 struct lu_name *lname;
1336 if (le16_to_cpu(ent->lde_namelen) == 0)
1339 fid_le_to_cpu(lf, &ent->lde_fid);
1340 if (le64_to_cpu(ent->lde_hash) & MAX_HASH_HIGHEST_BIT)
1341 ma->ma_attr.la_mode = S_IFDIR;
1343 ma->ma_attr.la_mode = 0;
1344 OBD_ALLOC(name, le16_to_cpu(ent->lde_namelen) + 1);
1346 GOTO(out, rc = -ENOMEM);
1348 memcpy(name, ent->lde_name, le16_to_cpu(ent->lde_namelen));
1349 lname = mdt_name(info->mti_env, name,
1350 le16_to_cpu(ent->lde_namelen));
1351 ma->ma_attr_flags |= (MDS_PERM_BYPASS | MDS_QUOTA_IGNORE);
1352 rc = mdo_name_insert(info->mti_env,
1353 md_object_next(&object->mot_obj),
1355 OBD_FREE(name, le16_to_cpu(ent->lde_namelen) + 1);
1357 CERROR("Can't insert %*.*s, rc %d\n",
1358 le16_to_cpu(ent->lde_namelen),
1359 le16_to_cpu(ent->lde_namelen),
1364 offset += lu_dirent_size(ent);
1374 static int mdt_bulk_timeout(void *data)
1378 CERROR("mdt bulk transfer timeout \n");
1383 static int mdt_writepage(struct mdt_thread_info *info)
1385 struct ptlrpc_request *req = mdt_info_req(info);
1386 struct mdt_body *reqbody;
1387 struct l_wait_info *lwi;
1388 struct ptlrpc_bulk_desc *desc;
1394 reqbody = req_capsule_client_get(info->mti_pill, &RMF_MDT_BODY);
1395 if (reqbody == NULL)
1396 RETURN(err_serious(-EFAULT));
1398 desc = ptlrpc_prep_bulk_exp(req, 1, BULK_GET_SINK, MDS_BULK_PORTAL);
1400 RETURN(err_serious(-ENOMEM));
1402 /* allocate the page for the desc */
1403 page = cfs_alloc_page(CFS_ALLOC_STD);
1405 GOTO(desc_cleanup, rc = -ENOMEM);
1407 CDEBUG(D_INFO, "Received page offset %d size %d \n",
1408 (int)reqbody->size, (int)reqbody->nlink);
1410 ptlrpc_prep_bulk_page(desc, page, (int)reqbody->size,
1411 (int)reqbody->nlink);
1413 rc = sptlrpc_svc_prep_bulk(req, desc);
1415 GOTO(cleanup_page, rc);
1417 * Check if client was evicted while we were doing i/o before touching
1422 GOTO(cleanup_page, rc = -ENOMEM);
1424 if (desc->bd_export->exp_failed)
1427 rc = ptlrpc_start_bulk_transfer (desc);
1429 *lwi = LWI_TIMEOUT_INTERVAL(obd_timeout * CFS_HZ / 4, CFS_HZ,
1430 mdt_bulk_timeout, desc);
1431 rc = l_wait_event(desc->bd_waitq, !ptlrpc_bulk_active(desc) ||
1432 desc->bd_export->exp_failed, lwi);
1433 LASSERT(rc == 0 || rc == -ETIMEDOUT);
1434 if (rc == -ETIMEDOUT) {
1435 DEBUG_REQ(D_ERROR, req, "timeout on bulk GET");
1436 ptlrpc_abort_bulk(desc);
1437 } else if (desc->bd_export->exp_failed) {
1438 DEBUG_REQ(D_ERROR, req, "Eviction on bulk GET");
1440 ptlrpc_abort_bulk(desc);
1441 } else if (!desc->bd_success ||
1442 desc->bd_nob_transferred != desc->bd_nob) {
1443 DEBUG_REQ(D_ERROR, req, "%s bulk GET %d(%d)",
1445 "truncated" : "network error on",
1446 desc->bd_nob_transferred, desc->bd_nob);
1447 /* XXX should this be a different errno? */
1451 DEBUG_REQ(D_ERROR, req, "ptlrpc_bulk_get failed: rc %d", rc);
1454 GOTO(cleanup_lwi, rc);
1455 rc = mdt_write_dir_page(info, page, reqbody->nlink);
1460 cfs_free_page(page);
1462 ptlrpc_free_bulk(desc);
1467 static int mdt_readpage(struct mdt_thread_info *info)
1469 struct mdt_object *object = info->mti_object;
1470 struct lu_rdpg *rdpg = &info->mti_u.rdpg.mti_rdpg;
1471 struct mdt_body *reqbody;
1472 struct mdt_body *repbody;
1477 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_READPAGE_PACK))
1478 RETURN(err_serious(-ENOMEM));
1480 reqbody = req_capsule_client_get(info->mti_pill, &RMF_MDT_BODY);
1481 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
1482 if (reqbody == NULL || repbody == NULL)
1483 RETURN(err_serious(-EFAULT));
1486 * prepare @rdpg before calling lower layers and transfer itself. Here
1487 * reqbody->size contains offset of where to start to read and
1488 * reqbody->nlink contains number bytes to read.
1490 rdpg->rp_hash = reqbody->size;
1491 if (rdpg->rp_hash != reqbody->size) {
1492 CERROR("Invalid hash: "LPX64" != "LPX64"\n",
1493 rdpg->rp_hash, reqbody->size);
1497 rdpg->rp_attrs = reqbody->mode;
1498 if (info->mti_exp->exp_connect_flags & OBD_CONNECT_64BITHASH)
1499 rdpg->rp_attrs |= LUDA_64BITHASH;
1500 rdpg->rp_count = min_t(unsigned int, reqbody->nlink,
1501 PTLRPC_MAX_BRW_SIZE);
1502 rdpg->rp_npages = (rdpg->rp_count + CFS_PAGE_SIZE - 1) >>
1504 OBD_ALLOC(rdpg->rp_pages, rdpg->rp_npages * sizeof rdpg->rp_pages[0]);
1505 if (rdpg->rp_pages == NULL)
1508 for (i = 0; i < rdpg->rp_npages; ++i) {
1509 rdpg->rp_pages[i] = cfs_alloc_page(CFS_ALLOC_STD);
1510 if (rdpg->rp_pages[i] == NULL)
1511 GOTO(free_rdpg, rc = -ENOMEM);
1514 /* call lower layers to fill allocated pages with directory data */
1515 rc = mo_readpage(info->mti_env, mdt_object_child(object), rdpg);
1517 GOTO(free_rdpg, rc);
1519 /* send pages to client */
1520 rc = mdt_sendpage(info, rdpg, rc);
1525 for (i = 0; i < rdpg->rp_npages; i++)
1526 if (rdpg->rp_pages[i] != NULL)
1527 cfs_free_page(rdpg->rp_pages[i]);
1528 OBD_FREE(rdpg->rp_pages, rdpg->rp_npages * sizeof rdpg->rp_pages[0]);
1530 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_SENDPAGE))
1536 static int mdt_reint_internal(struct mdt_thread_info *info,
1537 struct mdt_lock_handle *lhc,
1540 struct req_capsule *pill = info->mti_pill;
1541 struct md_quota *mq = md_quota(info->mti_env);
1542 struct mdt_body *repbody;
1547 rc = mdt_reint_unpack(info, op);
1549 CERROR("Can't unpack reint, rc %d\n", rc);
1550 RETURN(err_serious(rc));
1553 /* for replay (no_create) lmm is not needed, client has it already */
1554 if (req_capsule_has_field(pill, &RMF_MDT_MD, RCL_SERVER))
1555 req_capsule_set_size(pill, &RMF_MDT_MD, RCL_SERVER,
1556 info->mti_rr.rr_eadatalen);
1558 if (req_capsule_has_field(pill, &RMF_LOGCOOKIES, RCL_SERVER))
1559 req_capsule_set_size(pill, &RMF_LOGCOOKIES, RCL_SERVER,
1560 info->mti_mdt->mdt_max_cookiesize);
1562 rc = req_capsule_server_pack(pill);
1564 CERROR("Can't pack response, rc %d\n", rc);
1565 RETURN(err_serious(rc));
1568 if (req_capsule_has_field(pill, &RMF_MDT_BODY, RCL_SERVER)) {
1569 repbody = req_capsule_server_get(pill, &RMF_MDT_BODY);
1571 repbody->eadatasize = 0;
1572 repbody->aclsize = 0;
1575 OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_REINT_DELAY, 10);
1577 /* for replay no cookkie / lmm need, because client have this already */
1578 if (info->mti_spec.no_create)
1579 if (req_capsule_has_field(pill, &RMF_MDT_MD, RCL_SERVER))
1580 req_capsule_set_size(pill, &RMF_MDT_MD, RCL_SERVER, 0);
1582 rc = mdt_init_ucred_reint(info);
1584 GOTO(out_shrink, rc);
1586 rc = mdt_fix_attr_ucred(info, op);
1588 GOTO(out_ucred, rc = err_serious(rc));
1590 if (mdt_check_resent(info, mdt_reconstruct, lhc)) {
1591 rc = lustre_msg_get_status(mdt_info_req(info)->rq_repmsg);
1592 GOTO(out_ucred, rc);
1594 mq->mq_exp = info->mti_exp;
1595 rc = mdt_reint_rec(info, lhc);
1598 mdt_exit_ucred(info);
1600 mdt_client_compatibility(info);
1601 rc2 = mdt_fix_reply(info);
1607 static long mdt_reint_opcode(struct mdt_thread_info *info,
1608 const struct req_format **fmt)
1610 struct mdt_rec_reint *rec;
1613 opc = err_serious(-EFAULT);
1614 rec = req_capsule_client_get(info->mti_pill, &RMF_REC_REINT);
1616 opc = rec->rr_opcode;
1617 DEBUG_REQ(D_INODE, mdt_info_req(info), "reint opt = %ld", opc);
1618 if (opc < REINT_MAX && fmt[opc] != NULL)
1619 req_capsule_extend(info->mti_pill, fmt[opc]);
1621 CERROR("Unsupported opc: %ld\n", opc);
1622 opc = err_serious(opc);
1628 static int mdt_reint(struct mdt_thread_info *info)
1633 static const struct req_format *reint_fmts[REINT_MAX] = {
1634 [REINT_SETATTR] = &RQF_MDS_REINT_SETATTR,
1635 [REINT_CREATE] = &RQF_MDS_REINT_CREATE,
1636 [REINT_LINK] = &RQF_MDS_REINT_LINK,
1637 [REINT_UNLINK] = &RQF_MDS_REINT_UNLINK,
1638 [REINT_RENAME] = &RQF_MDS_REINT_RENAME,
1639 [REINT_OPEN] = &RQF_MDS_REINT_OPEN,
1640 [REINT_SETXATTR] = &RQF_MDS_REINT_SETXATTR
1645 opc = mdt_reint_opcode(info, reint_fmts);
1648 * No lock possible here from client to pass it to reint code
1651 rc = mdt_reint_internal(info, NULL, opc);
1656 info->mti_fail_id = OBD_FAIL_MDS_REINT_NET_REP;
1660 /* this should sync the whole device */
1661 static int mdt_device_sync(const struct lu_env *env, struct mdt_device *mdt)
1663 struct dt_device *dt = mdt->mdt_bottom;
1667 rc = dt->dd_ops->dt_sync(env, dt);
1671 /* this should sync this object */
1672 static int mdt_object_sync(struct mdt_thread_info *info)
1674 struct md_object *next;
1678 if (!mdt_object_exists(info->mti_object)) {
1679 CWARN("Non existing object "DFID"!\n",
1680 PFID(mdt_object_fid(info->mti_object)));
1683 next = mdt_object_child(info->mti_object);
1684 rc = mo_object_sync(info->mti_env, next);
1689 static int mdt_sync(struct mdt_thread_info *info)
1691 struct ptlrpc_request *req = mdt_info_req(info);
1692 struct req_capsule *pill = info->mti_pill;
1693 struct mdt_body *body;
1697 /* The fid may be zero, so we req_capsule_set manually */
1698 req_capsule_set(pill, &RQF_MDS_SYNC);
1700 body = req_capsule_client_get(pill, &RMF_MDT_BODY);
1702 RETURN(err_serious(-EINVAL));
1704 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_SYNC_PACK))
1705 RETURN(err_serious(-ENOMEM));
1707 if (fid_seq(&body->fid1) == 0) {
1708 /* sync the whole device */
1709 rc = req_capsule_server_pack(pill);
1711 rc = mdt_device_sync(info->mti_env, info->mti_mdt);
1713 rc = err_serious(rc);
1715 /* sync an object */
1716 rc = mdt_unpack_req_pack_rep(info, HABEO_CORPUS|HABEO_REFERO);
1718 rc = mdt_object_sync(info);
1720 struct md_object *next;
1721 const struct lu_fid *fid;
1722 struct lu_attr *la = &info->mti_attr.ma_attr;
1724 next = mdt_object_child(info->mti_object);
1725 info->mti_attr.ma_need = MA_INODE;
1726 info->mti_attr.ma_valid = 0;
1727 rc = mo_attr_get(info->mti_env, next,
1730 body = req_capsule_server_get(pill,
1732 fid = mdt_object_fid(info->mti_object);
1733 mdt_pack_attr2body(info, body, la, fid);
1737 rc = err_serious(rc);
1740 mdt_counter_incr(req->rq_export, LPROC_MDT_SYNC);
1745 #ifdef HAVE_QUOTA_SUPPORT
1746 static int mdt_quotacheck_handle(struct mdt_thread_info *info)
1748 struct obd_quotactl *oqctl;
1749 struct req_capsule *pill = info->mti_pill;
1750 struct obd_export *exp = info->mti_exp;
1751 struct md_quota *mq = md_quota(info->mti_env);
1752 struct md_device *next = info->mti_mdt->mdt_child;
1756 oqctl = req_capsule_client_get(pill, &RMF_OBD_QUOTACTL);
1760 /* remote client has no permission for quotacheck */
1761 if (unlikely(exp_connect_rmtclient(exp)))
1764 rc = req_capsule_server_pack(pill);
1769 rc = next->md_ops->mdo_quota.mqo_check(info->mti_env, next,
1774 static int mdt_quotactl_handle(struct mdt_thread_info *info)
1776 struct obd_quotactl *oqctl, *repoqc;
1777 struct req_capsule *pill = info->mti_pill;
1778 struct obd_export *exp = info->mti_exp;
1779 struct md_quota *mq = md_quota(info->mti_env);
1780 struct md_device *next = info->mti_mdt->mdt_child;
1781 const struct md_quota_operations *mqo = &next->md_ops->mdo_quota;
1785 oqctl = req_capsule_client_get(pill, &RMF_OBD_QUOTACTL);
1790 if (exp_connect_rmtclient(exp)) {
1791 struct ptlrpc_request *req = mdt_info_req(info);
1792 struct mdt_export_data *med = mdt_req2med(req);
1793 struct lustre_idmap_table *idmap = med->med_idmap;
1795 if (unlikely(oqctl->qc_cmd != Q_GETQUOTA &&
1796 oqctl->qc_cmd != Q_GETINFO))
1800 if (oqctl->qc_type == USRQUOTA)
1801 id = lustre_idmap_lookup_uid(NULL, idmap, 0,
1803 else if (oqctl->qc_type == GRPQUOTA)
1804 id = lustre_idmap_lookup_gid(NULL, idmap, 0,
1809 if (id == CFS_IDMAP_NOTFOUND) {
1810 CDEBUG(D_QUOTA, "no mapping for id %u\n",
1816 rc = req_capsule_server_pack(pill);
1820 repoqc = req_capsule_server_get(pill, &RMF_OBD_QUOTACTL);
1821 LASSERT(repoqc != NULL);
1824 switch (oqctl->qc_cmd) {
1826 rc = mqo->mqo_on(info->mti_env, next, oqctl->qc_type);
1829 rc = mqo->mqo_off(info->mti_env, next, oqctl->qc_type);
1832 rc = mqo->mqo_setinfo(info->mti_env, next, oqctl->qc_type, id,
1836 rc = mqo->mqo_getinfo(info->mti_env, next, oqctl->qc_type, id,
1840 rc = mqo->mqo_setquota(info->mti_env, next, oqctl->qc_type, id,
1844 rc = mqo->mqo_getquota(info->mti_env, next, oqctl->qc_type, id,
1848 rc = mqo->mqo_getoinfo(info->mti_env, next, oqctl->qc_type, id,
1852 rc = mqo->mqo_getoquota(info->mti_env, next, oqctl->qc_type, id,
1855 case LUSTRE_Q_INVALIDATE:
1856 rc = mqo->mqo_invalidate(info->mti_env, next, oqctl->qc_type);
1858 case LUSTRE_Q_FINVALIDATE:
1859 rc = mqo->mqo_finvalidate(info->mti_env, next, oqctl->qc_type);
1862 CERROR("unsupported mdt_quotactl command: %d\n",
1874 * OBD PING and other handlers.
1876 static int mdt_obd_ping(struct mdt_thread_info *info)
1881 req_capsule_set(info->mti_pill, &RQF_OBD_PING);
1883 rc = target_handle_ping(mdt_info_req(info));
1885 rc = err_serious(rc);
1889 static int mdt_obd_log_cancel(struct mdt_thread_info *info)
1891 return err_serious(-EOPNOTSUPP);
1894 static int mdt_obd_qc_callback(struct mdt_thread_info *info)
1896 return err_serious(-EOPNOTSUPP);
1904 /** clone llog ctxt from child (mdd)
1905 * This allows remote llog (replicator) access.
1906 * We can either pass all llog RPCs (eg mdt_llog_create) on to child where the
1907 * context was originally set up, or we can handle them directly.
1908 * I choose the latter, but that means I need any llog
1909 * contexts set up by child to be accessable by the mdt. So we clone the
1910 * context into our context list here.
1912 static int mdt_llog_ctxt_clone(const struct lu_env *env, struct mdt_device *mdt,
1915 struct md_device *next = mdt->mdt_child;
1916 struct llog_ctxt *ctxt;
1919 if (!llog_ctxt_null(mdt2obd_dev(mdt), idx))
1922 rc = next->md_ops->mdo_llog_ctxt_get(env, next, idx, (void **)&ctxt);
1923 if (rc || ctxt == NULL) {
1924 CERROR("Can't get mdd ctxt %d\n", rc);
1928 rc = llog_group_set_ctxt(&mdt2obd_dev(mdt)->obd_olg, ctxt, idx);
1930 CERROR("Can't set mdt ctxt %d\n", rc);
1935 static int mdt_llog_ctxt_unclone(const struct lu_env *env,
1936 struct mdt_device *mdt, int idx)
1938 struct llog_ctxt *ctxt;
1940 ctxt = llog_get_context(mdt2obd_dev(mdt), idx);
1943 /* Put once for the get we just did, and once for the clone */
1944 llog_ctxt_put(ctxt);
1945 llog_ctxt_put(ctxt);
1949 static int mdt_llog_create(struct mdt_thread_info *info)
1953 req_capsule_set(info->mti_pill, &RQF_LLOG_ORIGIN_HANDLE_CREATE);
1954 rc = llog_origin_handle_create(mdt_info_req(info));
1955 return (rc < 0 ? err_serious(rc) : rc);
1958 static int mdt_llog_destroy(struct mdt_thread_info *info)
1962 req_capsule_set(info->mti_pill, &RQF_LLOG_ORIGIN_HANDLE_DESTROY);
1963 rc = llog_origin_handle_destroy(mdt_info_req(info));
1964 return (rc < 0 ? err_serious(rc) : rc);
1967 static int mdt_llog_read_header(struct mdt_thread_info *info)
1971 req_capsule_set(info->mti_pill, &RQF_LLOG_ORIGIN_HANDLE_READ_HEADER);
1972 rc = llog_origin_handle_read_header(mdt_info_req(info));
1973 return (rc < 0 ? err_serious(rc) : rc);
1976 static int mdt_llog_next_block(struct mdt_thread_info *info)
1980 req_capsule_set(info->mti_pill, &RQF_LLOG_ORIGIN_HANDLE_NEXT_BLOCK);
1981 rc = llog_origin_handle_next_block(mdt_info_req(info));
1982 return (rc < 0 ? err_serious(rc) : rc);
1985 static int mdt_llog_prev_block(struct mdt_thread_info *info)
1989 req_capsule_set(info->mti_pill, &RQF_LLOG_ORIGIN_HANDLE_PREV_BLOCK);
1990 rc = llog_origin_handle_prev_block(mdt_info_req(info));
1991 return (rc < 0 ? err_serious(rc) : rc);
1998 static struct ldlm_callback_suite cbs = {
1999 .lcs_completion = ldlm_server_completion_ast,
2000 .lcs_blocking = ldlm_server_blocking_ast,
2004 static int mdt_enqueue(struct mdt_thread_info *info)
2006 struct ptlrpc_request *req;
2010 * info->mti_dlm_req already contains swapped and (if necessary)
2011 * converted dlm request.
2013 LASSERT(info->mti_dlm_req != NULL);
2015 req = mdt_info_req(info);
2016 rc = ldlm_handle_enqueue0(info->mti_mdt->mdt_namespace,
2017 req, info->mti_dlm_req, &cbs);
2018 info->mti_fail_id = OBD_FAIL_LDLM_REPLY;
2019 return rc ? err_serious(rc) : req->rq_status;
2022 static int mdt_convert(struct mdt_thread_info *info)
2025 struct ptlrpc_request *req;
2027 LASSERT(info->mti_dlm_req);
2028 req = mdt_info_req(info);
2029 rc = ldlm_handle_convert0(req, info->mti_dlm_req);
2030 return rc ? err_serious(rc) : req->rq_status;
2033 static int mdt_bl_callback(struct mdt_thread_info *info)
2035 CERROR("bl callbacks should not happen on MDS\n");
2037 return err_serious(-EOPNOTSUPP);
2040 static int mdt_cp_callback(struct mdt_thread_info *info)
2042 CERROR("cp callbacks should not happen on MDS\n");
2044 return err_serious(-EOPNOTSUPP);
2048 * sec context handlers
2050 static int mdt_sec_ctx_handle(struct mdt_thread_info *info)
2054 rc = mdt_handle_idmap(info);
2057 struct ptlrpc_request *req = mdt_info_req(info);
2060 opc = lustre_msg_get_opc(req->rq_reqmsg);
2061 if (opc == SEC_CTX_INIT || opc == SEC_CTX_INIT_CONT)
2062 sptlrpc_svc_ctx_invalidate(req);
2065 CFS_FAIL_TIMEOUT(OBD_FAIL_SEC_CTX_HDL_PAUSE, cfs_fail_val);
2070 static struct mdt_object *mdt_obj(struct lu_object *o)
2072 LASSERT(lu_device_is_mdt(o->lo_dev));
2073 return container_of0(o, struct mdt_object, mot_obj.mo_lu);
2076 struct mdt_object *mdt_object_find(const struct lu_env *env,
2077 struct mdt_device *d,
2078 const struct lu_fid *f)
2080 struct lu_object *o;
2081 struct mdt_object *m;
2084 CDEBUG(D_INFO, "Find object for "DFID"\n", PFID(f));
2085 o = lu_object_find(env, &d->mdt_md_dev.md_lu_dev, f, NULL);
2086 if (unlikely(IS_ERR(o)))
2087 m = (struct mdt_object *)o;
2094 * Asyncronous commit for mdt device.
2096 * Pass asynchonous commit call down the MDS stack.
2098 * \param env environment
2099 * \param mdt the mdt device
2101 static void mdt_device_commit_async(const struct lu_env *env,
2102 struct mdt_device *mdt)
2104 struct dt_device *dt = mdt->mdt_bottom;
2107 rc = dt->dd_ops->dt_commit_async(env, dt);
2108 if (unlikely(rc != 0))
2109 CWARN("async commit start failed with rc = %d", rc);
2113 * Mark the lock as "synchonous".
2115 * Mark the lock to deffer transaction commit to the unlock time.
2117 * \param lock the lock to mark as "synchonous"
2119 * \see mdt_is_lock_sync
2120 * \see mdt_save_lock
2122 static inline void mdt_set_lock_sync(struct ldlm_lock *lock)
2124 lock->l_ast_data = (void*)1;
2128 * Check whehter the lock "synchonous" or not.
2130 * \param lock the lock to check
2131 * \retval 1 the lock is "synchonous"
2132 * \retval 0 the lock isn't "synchronous"
2134 * \see mdt_set_lock_sync
2135 * \see mdt_save_lock
2137 static inline int mdt_is_lock_sync(struct ldlm_lock *lock)
2139 return lock->l_ast_data != NULL;
2143 * Blocking AST for mdt locks.
2145 * Starts transaction commit if in case of COS lock conflict or
2146 * deffers such a commit to the mdt_save_lock.
2148 * \param lock the lock which blocks a request or cancelling lock
2149 * \param desc unused
2150 * \param data unused
2151 * \param flag indicates whether this cancelling or blocking callback
2153 * \see ldlm_blocking_ast_nocheck
2155 int mdt_blocking_ast(struct ldlm_lock *lock, struct ldlm_lock_desc *desc,
2156 void *data, int flag)
2158 struct obd_device *obd = ldlm_lock_to_ns(lock)->ns_obd;
2159 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
2163 if (flag == LDLM_CB_CANCELING)
2165 lock_res_and_lock(lock);
2166 if (lock->l_blocking_ast != mdt_blocking_ast) {
2167 unlock_res_and_lock(lock);
2170 if (mdt_cos_is_enabled(mdt) &&
2171 lock->l_req_mode & (LCK_PW | LCK_EX) &&
2172 lock->l_blocking_lock != NULL &&
2173 lock->l_client_cookie != lock->l_blocking_lock->l_client_cookie) {
2174 mdt_set_lock_sync(lock);
2176 rc = ldlm_blocking_ast_nocheck(lock);
2178 /* There is no lock conflict if l_blocking_lock == NULL,
2179 * it indicates a blocking ast sent from ldlm_lock_decref_internal
2180 * when the last reference to a local lock was released */
2181 if (lock->l_req_mode == LCK_COS && lock->l_blocking_lock != NULL) {
2184 rc = lu_env_init(&env, LCT_MD_THREAD);
2185 if (unlikely(rc != 0))
2186 CWARN("lu_env initialization failed with rc = %d,"
2187 "cannot start asynchronous commit\n", rc);
2189 mdt_device_commit_async(&env, mdt);
2195 int mdt_object_lock(struct mdt_thread_info *info, struct mdt_object *o,
2196 struct mdt_lock_handle *lh, __u64 ibits, int locality)
2198 struct ldlm_namespace *ns = info->mti_mdt->mdt_namespace;
2199 ldlm_policy_data_t *policy = &info->mti_policy;
2200 struct ldlm_res_id *res_id = &info->mti_res_id;
2204 LASSERT(!lustre_handle_is_used(&lh->mlh_reg_lh));
2205 LASSERT(!lustre_handle_is_used(&lh->mlh_pdo_lh));
2206 LASSERT(lh->mlh_reg_mode != LCK_MINMODE);
2207 LASSERT(lh->mlh_type != MDT_NUL_LOCK);
2209 if (mdt_object_exists(o) < 0) {
2210 if (locality == MDT_CROSS_LOCK) {
2211 /* cross-ref object fix */
2212 ibits &= ~MDS_INODELOCK_UPDATE;
2213 ibits |= MDS_INODELOCK_LOOKUP;
2215 LASSERT(!(ibits & MDS_INODELOCK_UPDATE));
2216 LASSERT(ibits & MDS_INODELOCK_LOOKUP);
2218 /* No PDO lock on remote object */
2219 LASSERT(lh->mlh_type != MDT_PDO_LOCK);
2222 if (lh->mlh_type == MDT_PDO_LOCK) {
2223 /* check for exists after object is locked */
2224 if (mdt_object_exists(o) == 0) {
2225 /* Non-existent object shouldn't have PDO lock */
2228 /* Non-dir object shouldn't have PDO lock */
2229 if (!S_ISDIR(lu_object_attr(&o->mot_obj.mo_lu)))
2234 memset(policy, 0, sizeof(*policy));
2235 fid_build_reg_res_name(mdt_object_fid(o), res_id);
2238 * Take PDO lock on whole directory and build correct @res_id for lock
2239 * on part of directory.
2241 if (lh->mlh_pdo_hash != 0) {
2242 LASSERT(lh->mlh_type == MDT_PDO_LOCK);
2243 mdt_lock_pdo_mode(info, o, lh);
2244 if (lh->mlh_pdo_mode != LCK_NL) {
2246 * Do not use LDLM_FL_LOCAL_ONLY for parallel lock, it
2247 * is never going to be sent to client and we do not
2248 * want it slowed down due to possible cancels.
2250 policy->l_inodebits.bits = MDS_INODELOCK_UPDATE;
2251 rc = mdt_fid_lock(ns, &lh->mlh_pdo_lh, lh->mlh_pdo_mode,
2252 policy, res_id, LDLM_FL_ATOMIC_CB,
2253 &info->mti_exp->exp_handle.h_cookie);
2259 * Finish res_id initializing by name hash marking part of
2260 * directory which is taking modification.
2262 res_id->name[LUSTRE_RES_ID_HSH_OFF] = lh->mlh_pdo_hash;
2265 policy->l_inodebits.bits = ibits;
2268 * Use LDLM_FL_LOCAL_ONLY for this lock. We do not know yet if it is
2269 * going to be sent to client. If it is - mdt_intent_policy() path will
2270 * fix it up and turn FL_LOCAL flag off.
2272 rc = mdt_fid_lock(ns, &lh->mlh_reg_lh, lh->mlh_reg_mode, policy,
2273 res_id, LDLM_FL_LOCAL_ONLY | LDLM_FL_ATOMIC_CB,
2274 &info->mti_exp->exp_handle.h_cookie);
2276 mdt_object_unlock(info, o, lh, 1);
2277 else if (unlikely(OBD_FAIL_PRECHECK(OBD_FAIL_MDS_PDO_LOCK)) &&
2278 lh->mlh_pdo_hash != 0 &&
2279 (lh->mlh_reg_mode == LCK_PW || lh->mlh_reg_mode == LCK_EX)) {
2280 OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_PDO_LOCK, 15);
2287 * Save a lock within request object.
2289 * Keep the lock referenced until whether client ACK or transaction
2290 * commit happens or release the lock immediately depending on input
2291 * parameters. If COS is ON, a write lock is converted to COS lock
2294 * \param info thead info object
2295 * \param h lock handle
2296 * \param mode lock mode
2297 * \param decref force immediate lock releasing
2300 void mdt_save_lock(struct mdt_thread_info *info, struct lustre_handle *h,
2301 ldlm_mode_t mode, int decref)
2305 if (lustre_handle_is_used(h)) {
2306 if (decref || !info->mti_has_trans ||
2307 !(mode & (LCK_PW | LCK_EX))){
2308 mdt_fid_unlock(h, mode);
2310 struct mdt_device *mdt = info->mti_mdt;
2311 struct ldlm_lock *lock = ldlm_handle2lock(h);
2312 struct ptlrpc_request *req = mdt_info_req(info);
2315 LASSERTF(lock != NULL, "no lock for cookie "LPX64"\n",
2317 CDEBUG(D_HA, "request = %p reply state = %p"
2318 " transno = "LPD64"\n",
2319 req, req->rq_reply_state, req->rq_transno);
2320 if (mdt_cos_is_enabled(mdt)) {
2322 ldlm_lock_downgrade(lock, LCK_COS);
2325 ptlrpc_save_lock(req, h, mode, no_ack);
2326 if (mdt_is_lock_sync(lock)) {
2327 CDEBUG(D_HA, "found sync-lock,"
2328 " async commit started\n");
2329 mdt_device_commit_async(info->mti_env,
2332 LDLM_LOCK_PUT(lock);
2341 * Unlock mdt object.
2343 * Immeditely release the regular lock and the PDO lock or save the
2344 * lock in reqeuest and keep them referenced until client ACK or
2345 * transaction commit.
2347 * \param info thread info object
2348 * \param o mdt object
2349 * \param lh mdt lock handle referencing regular and PDO locks
2350 * \param decref force immediate lock releasing
2352 void mdt_object_unlock(struct mdt_thread_info *info, struct mdt_object *o,
2353 struct mdt_lock_handle *lh, int decref)
2357 mdt_save_lock(info, &lh->mlh_pdo_lh, lh->mlh_pdo_mode, decref);
2358 mdt_save_lock(info, &lh->mlh_reg_lh, lh->mlh_reg_mode, decref);
2363 struct mdt_object *mdt_object_find_lock(struct mdt_thread_info *info,
2364 const struct lu_fid *f,
2365 struct mdt_lock_handle *lh,
2368 struct mdt_object *o;
2370 o = mdt_object_find(info->mti_env, info->mti_mdt, f);
2374 rc = mdt_object_lock(info, o, lh, ibits,
2377 mdt_object_put(info->mti_env, o);
2384 void mdt_object_unlock_put(struct mdt_thread_info * info,
2385 struct mdt_object * o,
2386 struct mdt_lock_handle *lh,
2389 mdt_object_unlock(info, o, lh, decref);
2390 mdt_object_put(info->mti_env, o);
2393 static struct mdt_handler *mdt_handler_find(__u32 opc,
2394 struct mdt_opc_slice *supported)
2396 struct mdt_opc_slice *s;
2397 struct mdt_handler *h;
2400 for (s = supported; s->mos_hs != NULL; s++) {
2401 if (s->mos_opc_start <= opc && opc < s->mos_opc_end) {
2402 h = s->mos_hs + (opc - s->mos_opc_start);
2403 if (likely(h->mh_opc != 0))
2404 LASSERTF(h->mh_opc == opc,
2405 "opcode mismatch %d != %d\n",
2408 h = NULL; /* unsupported opc */
2415 static int mdt_lock_resname_compat(struct mdt_device *m,
2416 struct ldlm_request *req)
2418 /* XXX something... later. */
2422 static int mdt_lock_reply_compat(struct mdt_device *m, struct ldlm_reply *rep)
2424 /* XXX something... later. */
2429 * Generic code handling requests that have struct mdt_body passed in:
2431 * - extract mdt_body from request and save it in @info, if present;
2433 * - create lu_object, corresponding to the fid in mdt_body, and save it in
2436 * - if HABEO_CORPUS flag is set for this request type check whether object
2437 * actually exists on storage (lu_object_exists()).
2440 static int mdt_body_unpack(struct mdt_thread_info *info, __u32 flags)
2442 const struct mdt_body *body;
2443 struct mdt_object *obj;
2444 const struct lu_env *env;
2445 struct req_capsule *pill;
2449 env = info->mti_env;
2450 pill = info->mti_pill;
2452 body = info->mti_body = req_capsule_client_get(pill, &RMF_MDT_BODY);
2456 if (!(body->valid & OBD_MD_FLID))
2459 if (!fid_is_sane(&body->fid1)) {
2460 CERROR("Invalid fid: "DFID"\n", PFID(&body->fid1));
2465 * Do not get size or any capa fields before we check that request
2466 * contains capa actually. There are some requests which do not, for
2467 * instance MDS_IS_SUBDIR.
2469 if (req_capsule_has_field(pill, &RMF_CAPA1, RCL_CLIENT) &&
2470 req_capsule_get_size(pill, &RMF_CAPA1, RCL_CLIENT))
2471 mdt_set_capainfo(info, 0, &body->fid1,
2472 req_capsule_client_get(pill, &RMF_CAPA1));
2474 obj = mdt_object_find(env, info->mti_mdt, &body->fid1);
2476 if ((flags & HABEO_CORPUS) &&
2477 !mdt_object_exists(obj)) {
2478 mdt_object_put(env, obj);
2479 /* for capability renew ENOENT will be handled in
2481 if (body->valid & OBD_MD_FLOSSCAPA)
2486 info->mti_object = obj;
2495 static int mdt_unpack_req_pack_rep(struct mdt_thread_info *info, __u32 flags)
2497 struct req_capsule *pill = info->mti_pill;
2501 if (req_capsule_has_field(pill, &RMF_MDT_BODY, RCL_CLIENT))
2502 rc = mdt_body_unpack(info, flags);
2506 if (rc == 0 && (flags & HABEO_REFERO)) {
2508 if (req_capsule_has_field(pill, &RMF_MDT_MD, RCL_SERVER))
2509 req_capsule_set_size(pill, &RMF_MDT_MD, RCL_SERVER,
2510 info->mti_body->eadatasize);
2511 if (req_capsule_has_field(pill, &RMF_LOGCOOKIES, RCL_SERVER))
2512 req_capsule_set_size(pill, &RMF_LOGCOOKIES, RCL_SERVER,
2513 info->mti_mdt->mdt_max_cookiesize);
2515 rc = req_capsule_server_pack(pill);
2520 static int mdt_init_capa_ctxt(const struct lu_env *env, struct mdt_device *m)
2522 struct md_device *next = m->mdt_child;
2524 return next->md_ops->mdo_init_capa_ctxt(env, next,
2525 m->mdt_opts.mo_mds_capa,
2526 m->mdt_capa_timeout,
2532 * Invoke handler for this request opc. Also do necessary preprocessing
2533 * (according to handler ->mh_flags), and post-processing (setting of
2534 * ->last_{xid,committed}).
2536 static int mdt_req_handle(struct mdt_thread_info *info,
2537 struct mdt_handler *h, struct ptlrpc_request *req)
2539 int rc, serious = 0;
2544 LASSERT(h->mh_act != NULL);
2545 LASSERT(h->mh_opc == lustre_msg_get_opc(req->rq_reqmsg));
2546 LASSERT(current->journal_info == NULL);
2549 * Checking for various OBD_FAIL_$PREF_$OPC_NET codes. _Do_ not try
2550 * to put same checks into handlers like mdt_close(), mdt_reint(),
2551 * etc., without talking to mdt authors first. Checking same thing
2552 * there again is useless and returning 0 error without packing reply
2553 * is buggy! Handlers either pack reply or return error.
2555 * We return 0 here and do not send any reply in order to emulate
2556 * network failure. Do not send any reply in case any of NET related
2557 * fail_id has occured.
2559 if (OBD_FAIL_CHECK_ORSET(h->mh_fail_id, OBD_FAIL_ONCE))
2563 flags = h->mh_flags;
2564 LASSERT(ergo(flags & (HABEO_CORPUS|HABEO_REFERO), h->mh_fmt != NULL));
2566 if (h->mh_fmt != NULL) {
2567 req_capsule_set(info->mti_pill, h->mh_fmt);
2568 rc = mdt_unpack_req_pack_rep(info, flags);
2571 if (rc == 0 && flags & MUTABOR &&
2572 req->rq_export->exp_connect_flags & OBD_CONNECT_RDONLY)
2573 /* should it be rq_status? */
2576 if (rc == 0 && flags & HABEO_CLAVIS) {
2577 struct ldlm_request *dlm_req;
2579 LASSERT(h->mh_fmt != NULL);
2581 dlm_req = req_capsule_client_get(info->mti_pill, &RMF_DLM_REQ);
2582 if (dlm_req != NULL) {
2583 if (unlikely(dlm_req->lock_desc.l_resource.lr_type ==
2585 dlm_req->lock_desc.l_policy_data.\
2586 l_inodebits.bits == 0)) {
2588 * Lock without inodebits makes no sense and
2589 * will oops later in ldlm. If client miss to
2590 * set such bits, do not trigger ASSERTION.
2592 * For liblustre flock case, it maybe zero.
2596 if (info->mti_mdt->mdt_opts.mo_compat_resname)
2597 rc = mdt_lock_resname_compat(
2600 info->mti_dlm_req = dlm_req;
2607 /* capability setting changed via /proc, needs reinitialize ctxt */
2608 if (info->mti_mdt && info->mti_mdt->mdt_capa_conf) {
2609 mdt_init_capa_ctxt(info->mti_env, info->mti_mdt);
2610 info->mti_mdt->mdt_capa_conf = 0;
2613 if (likely(rc == 0)) {
2615 * Process request, there can be two types of rc:
2616 * 1) errors with msg unpack/pack, other failures outside the
2617 * operation itself. This is counted as serious errors;
2618 * 2) errors during fs operation, should be placed in rq_status
2621 rc = h->mh_act(info);
2623 !req->rq_no_reply && req->rq_reply_state == NULL) {
2624 DEBUG_REQ(D_ERROR, req, "MDT \"handler\" %s did not "
2625 "pack reply and returned 0 error\n",
2629 serious = is_serious(rc);
2630 rc = clear_serious(rc);
2634 req->rq_status = rc;
2637 * ELDLM_* codes which > 0 should be in rq_status only as well as
2638 * all non-serious errors.
2640 if (rc > 0 || !serious)
2643 LASSERT(current->journal_info == NULL);
2645 if (rc == 0 && (flags & HABEO_CLAVIS) &&
2646 info->mti_mdt->mdt_opts.mo_compat_resname) {
2647 struct ldlm_reply *dlmrep;
2649 dlmrep = req_capsule_server_get(info->mti_pill, &RMF_DLM_REP);
2651 rc = mdt_lock_reply_compat(info->mti_mdt, dlmrep);
2654 /* If we're DISCONNECTing, the mdt_export_data is already freed */
2655 if (likely(rc == 0 && req->rq_export && h->mh_opc != MDS_DISCONNECT))
2656 target_committed_to_req(req);
2658 if (unlikely(req_is_replay(req) &&
2659 lustre_msg_get_transno(req->rq_reqmsg) == 0)) {
2660 DEBUG_REQ(D_ERROR, req, "transno is 0 during REPLAY");
2664 target_send_reply(req, rc, info->mti_fail_id);
2668 void mdt_lock_handle_init(struct mdt_lock_handle *lh)
2670 lh->mlh_type = MDT_NUL_LOCK;
2671 lh->mlh_reg_lh.cookie = 0ull;
2672 lh->mlh_reg_mode = LCK_MINMODE;
2673 lh->mlh_pdo_lh.cookie = 0ull;
2674 lh->mlh_pdo_mode = LCK_MINMODE;
2677 void mdt_lock_handle_fini(struct mdt_lock_handle *lh)
2679 LASSERT(!lustre_handle_is_used(&lh->mlh_reg_lh));
2680 LASSERT(!lustre_handle_is_used(&lh->mlh_pdo_lh));
2684 * Initialize fields of struct mdt_thread_info. Other fields are left in
2685 * uninitialized state, because it's too expensive to zero out whole
2686 * mdt_thread_info (> 1K) on each request arrival.
2688 static void mdt_thread_info_init(struct ptlrpc_request *req,
2689 struct mdt_thread_info *info)
2692 struct md_capainfo *ci;
2694 req_capsule_init(&req->rq_pill, req, RCL_SERVER);
2695 info->mti_pill = &req->rq_pill;
2698 for (i = 0; i < ARRAY_SIZE(info->mti_lh); i++)
2699 mdt_lock_handle_init(&info->mti_lh[i]);
2701 /* mdt device: it can be NULL while CONNECT */
2702 if (req->rq_export) {
2703 info->mti_mdt = mdt_dev(req->rq_export->exp_obd->obd_lu_dev);
2704 info->mti_exp = req->rq_export;
2706 info->mti_mdt = NULL;
2707 info->mti_env = req->rq_svc_thread->t_env;
2708 ci = md_capainfo(info->mti_env);
2709 memset(ci, 0, sizeof *ci);
2710 if (req->rq_export) {
2711 if (exp_connect_rmtclient(req->rq_export))
2712 ci->mc_auth = LC_ID_CONVERT;
2713 else if (req->rq_export->exp_connect_flags &
2714 OBD_CONNECT_MDS_CAPA)
2715 ci->mc_auth = LC_ID_PLAIN;
2717 ci->mc_auth = LC_ID_NONE;
2720 info->mti_fail_id = OBD_FAIL_MDS_ALL_REPLY_NET;
2721 info->mti_transno = lustre_msg_get_transno(req->rq_reqmsg);
2722 info->mti_mos = NULL;
2724 memset(&info->mti_attr, 0, sizeof(info->mti_attr));
2725 info->mti_body = NULL;
2726 info->mti_object = NULL;
2727 info->mti_dlm_req = NULL;
2728 info->mti_has_trans = 0;
2729 info->mti_no_need_trans = 0;
2730 info->mti_cross_ref = 0;
2731 info->mti_opdata = 0;
2733 /* To not check for split by default. */
2734 info->mti_spec.sp_ck_split = 0;
2735 info->mti_spec.no_create = 0;
2738 static void mdt_thread_info_fini(struct mdt_thread_info *info)
2742 req_capsule_fini(info->mti_pill);
2743 if (info->mti_object != NULL) {
2745 * freeing an object may lead to OSD level transaction, do not
2746 * let it mess with MDT. bz19385.
2748 info->mti_no_need_trans = 1;
2749 mdt_object_put(info->mti_env, info->mti_object);
2750 info->mti_object = NULL;
2752 for (i = 0; i < ARRAY_SIZE(info->mti_lh); i++)
2753 mdt_lock_handle_fini(&info->mti_lh[i]);
2754 info->mti_env = NULL;
2757 static int mdt_filter_recovery_request(struct ptlrpc_request *req,
2758 struct obd_device *obd, int *process)
2760 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
2761 case MDS_CONNECT: /* This will never get here, but for completeness. */
2762 case OST_CONNECT: /* This will never get here, but for completeness. */
2763 case MDS_DISCONNECT:
2764 case OST_DISCONNECT:
2769 case MDS_DONE_WRITING:
2770 case MDS_SYNC: /* used in unmounting */
2776 *process = target_queue_recovery_request(req, obd);
2780 DEBUG_REQ(D_ERROR, req, "not permitted during recovery");
2787 * Handle recovery. Return:
2788 * +1: continue request processing;
2789 * -ve: abort immediately with the given error code;
2790 * 0: send reply with error code in req->rq_status;
2792 static int mdt_recovery(struct mdt_thread_info *info)
2794 struct ptlrpc_request *req = mdt_info_req(info);
2795 struct obd_device *obd;
2799 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
2802 case SEC_CTX_INIT_CONT:
2808 rc = mdt_handle_idmap(info);
2817 if (unlikely(!class_connected_export(req->rq_export))) {
2818 CERROR("operation %d on unconnected MDS from %s\n",
2819 lustre_msg_get_opc(req->rq_reqmsg),
2820 libcfs_id2str(req->rq_peer));
2821 /* FIXME: For CMD cleanup, when mds_B stop, the req from
2822 * mds_A will get -ENOTCONN(especially for ping req),
2823 * which will cause that mds_A deactive timeout, then when
2824 * mds_A cleanup, the cleanup process will be suspended since
2825 * deactive timeout is not zero.
2827 req->rq_status = -ENOTCONN;
2828 target_send_reply(req, -ENOTCONN, info->mti_fail_id);
2832 /* sanity check: if the xid matches, the request must be marked as a
2833 * resent or replayed */
2834 if (req_xid_is_last(req)) {
2835 if (!(lustre_msg_get_flags(req->rq_reqmsg) &
2836 (MSG_RESENT | MSG_REPLAY))) {
2837 DEBUG_REQ(D_WARNING, req, "rq_xid "LPU64" matches last_xid, "
2838 "expected REPLAY or RESENT flag (%x)", req->rq_xid,
2839 lustre_msg_get_flags(req->rq_reqmsg));
2841 req->rq_status = -ENOTCONN;
2846 /* else: note the opposite is not always true; a RESENT req after a
2847 * failover will usually not match the last_xid, since it was likely
2848 * never committed. A REPLAYed request will almost never match the
2849 * last xid, however it could for a committed, but still retained,
2852 obd = req->rq_export->exp_obd;
2854 /* Check for aborted recovery... */
2855 if (unlikely(obd->obd_recovering)) {
2858 DEBUG_REQ(D_INFO, req, "Got new replay");
2859 rc = mdt_filter_recovery_request(req, obd, &should_process);
2860 if (rc != 0 || !should_process)
2862 else if (should_process < 0) {
2863 req->rq_status = should_process;
2864 rc = ptlrpc_error(req);
2871 static int mdt_msg_check_version(struct lustre_msg *msg)
2875 switch (lustre_msg_get_opc(msg)) {
2877 case MDS_DISCONNECT:
2880 case SEC_CTX_INIT_CONT:
2882 rc = lustre_msg_check_version(msg, LUSTRE_OBD_VERSION);
2884 CERROR("bad opc %u version %08x, expecting %08x\n",
2885 lustre_msg_get_opc(msg),
2886 lustre_msg_get_version(msg),
2887 LUSTRE_OBD_VERSION);
2891 case MDS_GETATTR_NAME:
2898 case MDS_DONE_WRITING:
2905 case MDS_QUOTACHECK:
2911 rc = lustre_msg_check_version(msg, LUSTRE_MDS_VERSION);
2913 CERROR("bad opc %u version %08x, expecting %08x\n",
2914 lustre_msg_get_opc(msg),
2915 lustre_msg_get_version(msg),
2916 LUSTRE_MDS_VERSION);
2920 case LDLM_BL_CALLBACK:
2921 case LDLM_CP_CALLBACK:
2922 rc = lustre_msg_check_version(msg, LUSTRE_DLM_VERSION);
2924 CERROR("bad opc %u version %08x, expecting %08x\n",
2925 lustre_msg_get_opc(msg),
2926 lustre_msg_get_version(msg),
2927 LUSTRE_DLM_VERSION);
2929 case OBD_LOG_CANCEL:
2930 case LLOG_ORIGIN_HANDLE_CREATE:
2931 case LLOG_ORIGIN_HANDLE_NEXT_BLOCK:
2932 case LLOG_ORIGIN_HANDLE_READ_HEADER:
2933 case LLOG_ORIGIN_HANDLE_CLOSE:
2934 case LLOG_ORIGIN_HANDLE_DESTROY:
2935 case LLOG_ORIGIN_HANDLE_PREV_BLOCK:
2937 rc = lustre_msg_check_version(msg, LUSTRE_LOG_VERSION);
2939 CERROR("bad opc %u version %08x, expecting %08x\n",
2940 lustre_msg_get_opc(msg),
2941 lustre_msg_get_version(msg),
2942 LUSTRE_LOG_VERSION);
2945 CERROR("MDS unknown opcode %d\n", lustre_msg_get_opc(msg));
2951 static int mdt_handle0(struct ptlrpc_request *req,
2952 struct mdt_thread_info *info,
2953 struct mdt_opc_slice *supported)
2955 struct mdt_handler *h;
2956 struct lustre_msg *msg;
2961 if (OBD_FAIL_CHECK_ORSET(OBD_FAIL_MDS_ALL_REQUEST_NET, OBD_FAIL_ONCE))
2964 LASSERT(current->journal_info == NULL);
2966 msg = req->rq_reqmsg;
2967 rc = mdt_msg_check_version(msg);
2968 if (likely(rc == 0)) {
2969 rc = mdt_recovery(info);
2970 if (likely(rc == +1)) {
2971 h = mdt_handler_find(lustre_msg_get_opc(msg),
2973 if (likely(h != NULL)) {
2974 rc = mdt_req_handle(info, h, req);
2976 CERROR("The unsupported opc: 0x%x\n",
2977 lustre_msg_get_opc(msg) );
2978 req->rq_status = -ENOTSUPP;
2979 rc = ptlrpc_error(req);
2984 CERROR(LUSTRE_MDT_NAME" drops mal-formed request\n");
2989 * MDT handler function called by ptlrpc service thread when request comes.
2991 * XXX common "target" functionality should be factored into separate module
2992 * shared by mdt, ost and stand-alone services like fld.
2994 static int mdt_handle_common(struct ptlrpc_request *req,
2995 struct mdt_opc_slice *supported)
2998 struct mdt_thread_info *info;
3002 env = req->rq_svc_thread->t_env;
3003 LASSERT(env != NULL);
3004 LASSERT(env->le_ses != NULL);
3005 LASSERT(env->le_ctx.lc_thread == req->rq_svc_thread);
3006 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
3007 LASSERT(info != NULL);
3009 mdt_thread_info_init(req, info);
3011 rc = mdt_handle0(req, info, supported);
3013 mdt_thread_info_fini(info);
3018 * This is called from recovery code as handler of _all_ RPC types, FLD and SEQ
3021 int mdt_recovery_handle(struct ptlrpc_request *req)
3026 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
3028 rc = mdt_handle_common(req, mdt_fld_handlers);
3031 rc = mdt_handle_common(req, mdt_seq_handlers);
3034 rc = mdt_handle_common(req, mdt_regular_handlers);
3041 static int mdt_regular_handle(struct ptlrpc_request *req)
3043 return mdt_handle_common(req, mdt_regular_handlers);
3046 static int mdt_readpage_handle(struct ptlrpc_request *req)
3048 return mdt_handle_common(req, mdt_readpage_handlers);
3051 static int mdt_xmds_handle(struct ptlrpc_request *req)
3053 return mdt_handle_common(req, mdt_xmds_handlers);
3056 static int mdt_mdsc_handle(struct ptlrpc_request *req)
3058 return mdt_handle_common(req, mdt_seq_handlers);
3061 static int mdt_mdss_handle(struct ptlrpc_request *req)
3063 return mdt_handle_common(req, mdt_seq_handlers);
3066 static int mdt_dtss_handle(struct ptlrpc_request *req)
3068 return mdt_handle_common(req, mdt_seq_handlers);
3071 static int mdt_fld_handle(struct ptlrpc_request *req)
3073 return mdt_handle_common(req, mdt_fld_handlers);
3090 static int mdt_intent_getattr(enum mdt_it_code opcode,
3091 struct mdt_thread_info *info,
3092 struct ldlm_lock **,
3094 static int mdt_intent_reint(enum mdt_it_code opcode,
3095 struct mdt_thread_info *info,
3096 struct ldlm_lock **,
3099 static struct mdt_it_flavor {
3100 const struct req_format *it_fmt;
3102 int (*it_act)(enum mdt_it_code ,
3103 struct mdt_thread_info *,
3104 struct ldlm_lock **,
3107 } mdt_it_flavor[] = {
3109 .it_fmt = &RQF_LDLM_INTENT,
3110 /*.it_flags = HABEO_REFERO,*/
3112 .it_act = mdt_intent_reint,
3113 .it_reint = REINT_OPEN
3116 .it_fmt = &RQF_LDLM_INTENT,
3117 .it_flags = MUTABOR,
3118 .it_act = mdt_intent_reint,
3119 .it_reint = REINT_OPEN
3122 .it_fmt = &RQF_LDLM_INTENT,
3123 .it_flags = MUTABOR,
3124 .it_act = mdt_intent_reint,
3125 .it_reint = REINT_CREATE
3127 [MDT_IT_GETATTR] = {
3128 .it_fmt = &RQF_LDLM_INTENT_GETATTR,
3129 .it_flags = HABEO_REFERO,
3130 .it_act = mdt_intent_getattr
3132 [MDT_IT_READDIR] = {
3138 .it_fmt = &RQF_LDLM_INTENT_GETATTR,
3139 .it_flags = HABEO_REFERO,
3140 .it_act = mdt_intent_getattr
3143 .it_fmt = &RQF_LDLM_INTENT_UNLINK,
3144 .it_flags = MUTABOR,
3146 .it_reint = REINT_UNLINK
3150 .it_flags = MUTABOR,
3153 [MDT_IT_GETXATTR] = {
3159 .it_fmt = &RQF_LDLM_INTENT_GETATTR,
3160 .it_flags = HABEO_REFERO,
3161 .it_act = mdt_intent_getattr
3165 int mdt_intent_lock_replace(struct mdt_thread_info *info,
3166 struct ldlm_lock **lockp,
3167 struct ldlm_lock *new_lock,
3168 struct mdt_lock_handle *lh,
3171 struct ptlrpc_request *req = mdt_info_req(info);
3172 struct ldlm_lock *lock = *lockp;
3175 * Get new lock only for cases when possible resent did not find any
3178 if (new_lock == NULL)
3179 new_lock = ldlm_handle2lock_long(&lh->mlh_reg_lh, 0);
3181 if (new_lock == NULL && (flags & LDLM_FL_INTENT_ONLY)) {
3182 lh->mlh_reg_lh.cookie = 0;
3186 LASSERTF(new_lock != NULL,
3187 "lockh "LPX64"\n", lh->mlh_reg_lh.cookie);
3190 * If we've already given this lock to a client once, then we should
3191 * have no readers or writers. Otherwise, we should have one reader
3192 * _or_ writer ref (which will be zeroed below) before returning the
3195 if (new_lock->l_export == req->rq_export) {
3196 LASSERT(new_lock->l_readers + new_lock->l_writers == 0);
3198 LASSERT(new_lock->l_export == NULL);
3199 LASSERT(new_lock->l_readers + new_lock->l_writers == 1);
3204 if (new_lock->l_export == req->rq_export) {
3206 * Already gave this to the client, which means that we
3207 * reconstructed a reply.
3209 LASSERT(lustre_msg_get_flags(req->rq_reqmsg) &
3211 lh->mlh_reg_lh.cookie = 0;
3212 RETURN(ELDLM_LOCK_REPLACED);
3216 * Fixup the lock to be given to the client.
3218 lock_res_and_lock(new_lock);
3219 /* Zero new_lock->l_readers and new_lock->l_writers without triggering
3220 * possible blocking AST. */
3221 while (new_lock->l_readers > 0) {
3222 lu_ref_del(&new_lock->l_reference, "reader", new_lock);
3223 lu_ref_del(&new_lock->l_reference, "user", new_lock);
3224 new_lock->l_readers--;
3226 while (new_lock->l_writers > 0) {
3227 lu_ref_del(&new_lock->l_reference, "writer", new_lock);
3228 lu_ref_del(&new_lock->l_reference, "user", new_lock);
3229 new_lock->l_writers--;
3232 new_lock->l_export = class_export_lock_get(req->rq_export, new_lock);
3233 new_lock->l_blocking_ast = lock->l_blocking_ast;
3234 new_lock->l_completion_ast = lock->l_completion_ast;
3235 new_lock->l_remote_handle = lock->l_remote_handle;
3236 new_lock->l_flags &= ~LDLM_FL_LOCAL;
3238 unlock_res_and_lock(new_lock);
3240 cfs_hash_add(new_lock->l_export->exp_lock_hash,
3241 &new_lock->l_remote_handle,
3242 &new_lock->l_exp_hash);
3244 LDLM_LOCK_RELEASE(new_lock);
3245 lh->mlh_reg_lh.cookie = 0;
3247 RETURN(ELDLM_LOCK_REPLACED);
3250 static void mdt_intent_fixup_resent(struct mdt_thread_info *info,
3251 struct ldlm_lock *new_lock,
3252 struct ldlm_lock **old_lock,
3253 struct mdt_lock_handle *lh)
3255 struct ptlrpc_request *req = mdt_info_req(info);
3256 struct obd_export *exp = req->rq_export;
3257 struct lustre_handle remote_hdl;
3258 struct ldlm_request *dlmreq;
3259 struct ldlm_lock *lock;
3261 if (!(lustre_msg_get_flags(req->rq_reqmsg) & MSG_RESENT))
3264 dlmreq = req_capsule_client_get(info->mti_pill, &RMF_DLM_REQ);
3265 remote_hdl = dlmreq->lock_handle[0];
3267 lock = cfs_hash_lookup(exp->exp_lock_hash, &remote_hdl);
3269 if (lock != new_lock) {
3270 lh->mlh_reg_lh.cookie = lock->l_handle.h_cookie;
3271 lh->mlh_reg_mode = lock->l_granted_mode;
3273 LDLM_DEBUG(lock, "Restoring lock cookie");
3274 DEBUG_REQ(D_DLMTRACE, req,
3275 "restoring lock cookie "LPX64,
3276 lh->mlh_reg_lh.cookie);
3278 *old_lock = LDLM_LOCK_GET(lock);
3279 cfs_hash_put(exp->exp_lock_hash, &lock->l_exp_hash);
3283 cfs_hash_put(exp->exp_lock_hash, &lock->l_exp_hash);
3287 * If the xid matches, then we know this is a resent request, and allow
3288 * it. (It's probably an OPEN, for which we don't send a lock.
3290 if (req_xid_is_last(req))
3294 * This remote handle isn't enqueued, so we never received or processed
3295 * this request. Clear MSG_RESENT, because it can be handled like any
3296 * normal request now.
3298 lustre_msg_clear_flags(req->rq_reqmsg, MSG_RESENT);
3300 DEBUG_REQ(D_DLMTRACE, req, "no existing lock with rhandle "LPX64,
3304 static int mdt_intent_getattr(enum mdt_it_code opcode,
3305 struct mdt_thread_info *info,
3306 struct ldlm_lock **lockp,
3309 struct mdt_lock_handle *lhc = &info->mti_lh[MDT_LH_RMT];
3310 struct ldlm_lock *new_lock = NULL;
3312 struct ldlm_reply *ldlm_rep;
3313 struct ptlrpc_request *req;
3314 struct mdt_body *reqbody;
3315 struct mdt_body *repbody;
3319 reqbody = req_capsule_client_get(info->mti_pill, &RMF_MDT_BODY);
3322 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
3325 info->mti_spec.sp_ck_split = !!(reqbody->valid & OBD_MD_FLCKSPLIT);
3326 info->mti_cross_ref = !!(reqbody->valid & OBD_MD_FLCROSSREF);
3327 repbody->eadatasize = 0;
3328 repbody->aclsize = 0;
3332 child_bits = MDS_INODELOCK_LOOKUP;
3334 case MDT_IT_GETATTR:
3335 child_bits = MDS_INODELOCK_LOOKUP | MDS_INODELOCK_UPDATE;
3337 case MDT_IT_LAYOUT: {
3338 static int printed = 0;
3341 CERROR("layout lock not supported by this version\n");
3344 GOTO(out_shrink, rc = -EINVAL);
3348 CERROR("Unsupported intent (%d)\n", opcode);
3349 GOTO(out_shrink, rc = -EINVAL);
3352 rc = mdt_init_ucred(info, reqbody);
3354 GOTO(out_shrink, rc);
3356 req = info->mti_pill->rc_req;
3357 ldlm_rep = req_capsule_server_get(info->mti_pill, &RMF_DLM_REP);
3358 mdt_set_disposition(info, ldlm_rep, DISP_IT_EXECD);
3360 /* Get lock from request for possible resent case. */
3361 mdt_intent_fixup_resent(info, *lockp, &new_lock, lhc);
3363 ldlm_rep->lock_policy_res2 =
3364 mdt_getattr_name_lock(info, lhc, child_bits, ldlm_rep);
3366 if (mdt_get_disposition(ldlm_rep, DISP_LOOKUP_NEG))
3367 ldlm_rep->lock_policy_res2 = 0;
3368 if (!mdt_get_disposition(ldlm_rep, DISP_LOOKUP_POS) ||
3369 ldlm_rep->lock_policy_res2) {
3370 lhc->mlh_reg_lh.cookie = 0ull;
3371 GOTO(out_ucred, rc = ELDLM_LOCK_ABORTED);
3374 rc = mdt_intent_lock_replace(info, lockp, new_lock, lhc, flags);
3377 mdt_exit_ucred(info);
3379 mdt_client_compatibility(info);
3380 rc2 = mdt_fix_reply(info);
3386 static int mdt_intent_reint(enum mdt_it_code opcode,
3387 struct mdt_thread_info *info,
3388 struct ldlm_lock **lockp,
3391 struct mdt_lock_handle *lhc = &info->mti_lh[MDT_LH_RMT];
3392 struct ldlm_reply *rep = NULL;
3396 static const struct req_format *intent_fmts[REINT_MAX] = {
3397 [REINT_CREATE] = &RQF_LDLM_INTENT_CREATE,
3398 [REINT_OPEN] = &RQF_LDLM_INTENT_OPEN
3403 opc = mdt_reint_opcode(info, intent_fmts);
3407 if (mdt_it_flavor[opcode].it_reint != opc) {
3408 CERROR("Reint code %ld doesn't match intent: %d\n",
3410 RETURN(err_serious(-EPROTO));
3413 /* Get lock from request for possible resent case. */
3414 mdt_intent_fixup_resent(info, *lockp, NULL, lhc);
3416 rc = mdt_reint_internal(info, lhc, opc);
3418 /* Check whether the reply has been packed successfully. */
3419 if (mdt_info_req(info)->rq_repmsg != NULL)
3420 rep = req_capsule_server_get(info->mti_pill, &RMF_DLM_REP);
3422 RETURN(err_serious(-EFAULT));
3424 /* MDC expects this in any case */
3426 mdt_set_disposition(info, rep, DISP_LOOKUP_EXECD);
3428 /* Cross-ref case, the lock should be returned to the client */
3429 if (rc == -EREMOTE) {
3430 LASSERT(lustre_handle_is_used(&lhc->mlh_reg_lh));
3431 rep->lock_policy_res2 = 0;
3432 rc = mdt_intent_lock_replace(info, lockp, NULL, lhc, flags);
3435 rep->lock_policy_res2 = clear_serious(rc);
3437 if (rep->lock_policy_res2 == -ENOENT &&
3438 mdt_get_disposition(rep, DISP_LOOKUP_NEG))
3439 rep->lock_policy_res2 = 0;
3441 if (rc == -ENOTCONN || rc == -ENODEV ||
3442 rc == -EOVERFLOW) { /**< if VBR failure then return error */
3444 * If it is the disconnect error (ENODEV & ENOCONN), the error
3445 * will be returned by rq_status, and client at ptlrpc layer
3446 * will detect this, then disconnect, reconnect the import
3447 * immediately, instead of impacting the following the rpc.
3449 lhc->mlh_reg_lh.cookie = 0ull;
3453 * For other cases, the error will be returned by intent.
3454 * and client will retrieve the result from intent.
3457 * FIXME: when open lock is finished, that should be
3460 if (lustre_handle_is_used(&lhc->mlh_reg_lh)) {
3461 LASSERTF(rc == 0, "Error occurred but lock handle "
3462 "is still in use\n");
3463 rep->lock_policy_res2 = 0;
3464 rc = mdt_intent_lock_replace(info, lockp, NULL, lhc, flags);
3467 lhc->mlh_reg_lh.cookie = 0ull;
3468 RETURN(ELDLM_LOCK_ABORTED);
3473 static int mdt_intent_code(long itcode)
3481 case IT_OPEN|IT_CREAT:
3488 rc = MDT_IT_READDIR;
3491 rc = MDT_IT_GETATTR;
3503 rc = MDT_IT_GETXATTR;
3509 CERROR("Unknown intent opcode: %ld\n", itcode);
3516 static int mdt_intent_opc(long itopc, struct mdt_thread_info *info,
3517 struct ldlm_lock **lockp, int flags)
3519 struct req_capsule *pill;
3520 struct mdt_it_flavor *flv;
3525 opc = mdt_intent_code(itopc);
3529 pill = info->mti_pill;
3530 flv = &mdt_it_flavor[opc];
3532 if (flv->it_fmt != NULL)
3533 req_capsule_extend(pill, flv->it_fmt);
3535 rc = mdt_unpack_req_pack_rep(info, flv->it_flags);
3537 struct ptlrpc_request *req = mdt_info_req(info);
3538 if (flv->it_flags & MUTABOR &&
3539 req->rq_export->exp_connect_flags & OBD_CONNECT_RDONLY)
3542 if (rc == 0 && flv->it_act != NULL) {
3543 /* execute policy */
3544 rc = flv->it_act(opc, info, lockp, flags);
3551 static int mdt_intent_policy(struct ldlm_namespace *ns,
3552 struct ldlm_lock **lockp, void *req_cookie,
3553 ldlm_mode_t mode, int flags, void *data)
3555 struct mdt_thread_info *info;
3556 struct ptlrpc_request *req = req_cookie;
3557 struct ldlm_intent *it;
3558 struct req_capsule *pill;
3563 LASSERT(req != NULL);
3565 info = lu_context_key_get(&req->rq_svc_thread->t_env->le_ctx,
3567 LASSERT(info != NULL);
3568 pill = info->mti_pill;
3569 LASSERT(pill->rc_req == req);
3571 if (req->rq_reqmsg->lm_bufcount > DLM_INTENT_IT_OFF) {
3572 req_capsule_extend(pill, &RQF_LDLM_INTENT);
3573 it = req_capsule_client_get(pill, &RMF_LDLM_INTENT);
3575 rc = mdt_intent_opc(it->opc, info, lockp, flags);
3579 /* Lock without inodebits makes no sense and will oops
3580 * later in ldlm. Let's check it now to see if we have
3581 * ibits corrupted somewhere in mdt_intent_opc().
3582 * The case for client miss to set ibits has been
3583 * processed by others. */
3584 LASSERT(ergo(info->mti_dlm_req->lock_desc.l_resource.\
3585 lr_type == LDLM_IBITS,
3586 info->mti_dlm_req->lock_desc.\
3587 l_policy_data.l_inodebits.bits != 0));
3589 rc = err_serious(-EFAULT);
3591 /* No intent was provided */
3592 LASSERT(pill->rc_fmt == &RQF_LDLM_ENQUEUE);
3593 rc = req_capsule_server_pack(pill);
3595 rc = err_serious(rc);
3600 static int mdt_seq_fini(const struct lu_env *env,
3601 struct mdt_device *m)
3603 struct md_site *ms = mdt_md_site(m);
3607 if (ms->ms_server_seq) {
3608 seq_server_fini(ms->ms_server_seq, env);
3609 OBD_FREE_PTR(ms->ms_server_seq);
3610 ms->ms_server_seq = NULL;
3613 if (ms->ms_control_seq) {
3614 seq_server_fini(ms->ms_control_seq, env);
3615 OBD_FREE_PTR(ms->ms_control_seq);
3616 ms->ms_control_seq = NULL;
3619 if (ms->ms_client_seq) {
3620 seq_client_fini(ms->ms_client_seq);
3621 OBD_FREE_PTR(ms->ms_client_seq);
3622 ms->ms_client_seq = NULL;
3629 static int mdt_seq_init(const struct lu_env *env,
3631 struct mdt_device *m)
3638 ms = mdt_md_site(m);
3641 * This is sequence-controller node. Init seq-controller server on local
3644 if (ms->ms_node_id == 0) {
3645 LASSERT(ms->ms_control_seq == NULL);
3647 OBD_ALLOC_PTR(ms->ms_control_seq);
3648 if (ms->ms_control_seq == NULL)
3651 rc = seq_server_init(ms->ms_control_seq,
3652 m->mdt_bottom, uuid,
3653 LUSTRE_SEQ_CONTROLLER,
3658 GOTO(out_seq_fini, rc);
3660 OBD_ALLOC_PTR(ms->ms_client_seq);
3661 if (ms->ms_client_seq == NULL)
3662 GOTO(out_seq_fini, rc = -ENOMEM);
3664 OBD_ALLOC(prefix, MAX_OBD_NAME + 5);
3665 if (prefix == NULL) {
3666 OBD_FREE_PTR(ms->ms_client_seq);
3667 GOTO(out_seq_fini, rc = -ENOMEM);
3670 snprintf(prefix, MAX_OBD_NAME + 5, "ctl-%s",
3674 * Init seq-controller client after seq-controller server is
3675 * ready. Pass ms->ms_control_seq to it for direct talking.
3677 rc = seq_client_init(ms->ms_client_seq, NULL,
3678 LUSTRE_SEQ_METADATA, prefix,
3679 ms->ms_control_seq);
3680 OBD_FREE(prefix, MAX_OBD_NAME + 5);
3683 GOTO(out_seq_fini, rc);
3686 /* Init seq-server on local MDT */
3687 LASSERT(ms->ms_server_seq == NULL);
3689 OBD_ALLOC_PTR(ms->ms_server_seq);
3690 if (ms->ms_server_seq == NULL)
3691 GOTO(out_seq_fini, rc = -ENOMEM);
3693 rc = seq_server_init(ms->ms_server_seq,
3694 m->mdt_bottom, uuid,
3699 GOTO(out_seq_fini, rc = -ENOMEM);
3701 /* Assign seq-controller client to local seq-server. */
3702 if (ms->ms_node_id == 0) {
3703 LASSERT(ms->ms_client_seq != NULL);
3705 rc = seq_server_set_cli(ms->ms_server_seq,
3713 mdt_seq_fini(env, m);
3718 * Init client sequence manager which is used by local MDS to talk to sequence
3719 * controller on remote node.
3721 static int mdt_seq_init_cli(const struct lu_env *env,
3722 struct mdt_device *m,
3723 struct lustre_cfg *cfg)
3725 struct md_site *ms = mdt_md_site(m);
3726 struct obd_device *mdc;
3727 struct obd_uuid *uuidp, *mdcuuidp;
3728 char *uuid_str, *mdc_uuid_str;
3731 struct mdt_thread_info *info;
3732 char *p, *index_string = lustre_cfg_string(cfg, 2);
3735 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
3736 uuidp = &info->mti_u.uuid[0];
3737 mdcuuidp = &info->mti_u.uuid[1];
3739 LASSERT(index_string);
3741 index = simple_strtol(index_string, &p, 10);
3743 CERROR("Invalid index in lustre_cgf, offset 2\n");
3747 /* check if this is adding the first MDC and controller is not yet
3749 if (index != 0 || ms->ms_client_seq)
3752 uuid_str = lustre_cfg_string(cfg, 1);
3753 mdc_uuid_str = lustre_cfg_string(cfg, 4);
3754 obd_str2uuid(uuidp, uuid_str);
3755 obd_str2uuid(mdcuuidp, mdc_uuid_str);
3757 mdc = class_find_client_obd(uuidp, LUSTRE_MDC_NAME, mdcuuidp);
3759 CERROR("can't find controller MDC by uuid %s\n",
3762 } else if (!mdc->obd_set_up) {
3763 CERROR("target %s not set up\n", mdc->obd_name);
3766 LASSERT(ms->ms_control_exp);
3767 OBD_ALLOC_PTR(ms->ms_client_seq);
3768 if (ms->ms_client_seq != NULL) {
3771 OBD_ALLOC(prefix, MAX_OBD_NAME + 5);
3775 snprintf(prefix, MAX_OBD_NAME + 5, "ctl-%s",
3778 rc = seq_client_init(ms->ms_client_seq,
3780 LUSTRE_SEQ_METADATA,
3782 OBD_FREE(prefix, MAX_OBD_NAME + 5);
3789 LASSERT(ms->ms_server_seq != NULL);
3790 rc = seq_server_set_cli(ms->ms_server_seq, ms->ms_client_seq,
3797 static void mdt_seq_fini_cli(struct mdt_device *m)
3803 ms = mdt_md_site(m);
3806 if (ms->ms_server_seq)
3807 seq_server_set_cli(ms->ms_server_seq,
3810 if (ms->ms_control_exp) {
3811 class_export_put(ms->ms_control_exp);
3812 ms->ms_control_exp = NULL;
3821 static int mdt_fld_fini(const struct lu_env *env,
3822 struct mdt_device *m)
3824 struct md_site *ms = mdt_md_site(m);
3827 if (ms && ms->ms_server_fld) {
3828 fld_server_fini(ms->ms_server_fld, env);
3829 OBD_FREE_PTR(ms->ms_server_fld);
3830 ms->ms_server_fld = NULL;
3836 static int mdt_fld_init(const struct lu_env *env,
3838 struct mdt_device *m)
3844 ms = mdt_md_site(m);
3846 OBD_ALLOC_PTR(ms->ms_server_fld);
3847 if (ms->ms_server_fld == NULL)
3848 RETURN(rc = -ENOMEM);
3850 rc = fld_server_init(ms->ms_server_fld,
3851 m->mdt_bottom, uuid,
3852 env, ms->ms_node_id);
3854 OBD_FREE_PTR(ms->ms_server_fld);
3855 ms->ms_server_fld = NULL;
3862 /* device init/fini methods */
3863 static void mdt_stop_ptlrpc_service(struct mdt_device *m)
3866 if (m->mdt_regular_service != NULL) {
3867 ptlrpc_unregister_service(m->mdt_regular_service);
3868 m->mdt_regular_service = NULL;
3870 if (m->mdt_readpage_service != NULL) {
3871 ptlrpc_unregister_service(m->mdt_readpage_service);
3872 m->mdt_readpage_service = NULL;
3874 if (m->mdt_xmds_service != NULL) {
3875 ptlrpc_unregister_service(m->mdt_xmds_service);
3876 m->mdt_xmds_service = NULL;
3878 if (m->mdt_setattr_service != NULL) {
3879 ptlrpc_unregister_service(m->mdt_setattr_service);
3880 m->mdt_setattr_service = NULL;
3882 if (m->mdt_mdsc_service != NULL) {
3883 ptlrpc_unregister_service(m->mdt_mdsc_service);
3884 m->mdt_mdsc_service = NULL;
3886 if (m->mdt_mdss_service != NULL) {
3887 ptlrpc_unregister_service(m->mdt_mdss_service);
3888 m->mdt_mdss_service = NULL;
3890 if (m->mdt_dtss_service != NULL) {
3891 ptlrpc_unregister_service(m->mdt_dtss_service);
3892 m->mdt_dtss_service = NULL;
3894 if (m->mdt_fld_service != NULL) {
3895 ptlrpc_unregister_service(m->mdt_fld_service);
3896 m->mdt_fld_service = NULL;
3901 static int mdt_start_ptlrpc_service(struct mdt_device *m)
3904 static struct ptlrpc_service_conf conf;
3905 cfs_proc_dir_entry_t *procfs_entry;
3908 procfs_entry = m->mdt_md_dev.md_lu_dev.ld_obd->obd_proc_entry;
3910 conf = (typeof(conf)) {
3911 .psc_nbufs = MDS_NBUFS,
3912 .psc_bufsize = MDS_BUFSIZE,
3913 .psc_max_req_size = MDS_MAXREQSIZE,
3914 .psc_max_reply_size = MDS_MAXREPSIZE,
3915 .psc_req_portal = MDS_REQUEST_PORTAL,
3916 .psc_rep_portal = MDC_REPLY_PORTAL,
3917 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
3919 * We'd like to have a mechanism to set this on a per-device
3920 * basis, but alas...
3922 .psc_min_threads = mdt_min_threads,
3923 .psc_max_threads = mdt_max_threads,
3924 .psc_ctx_tags = LCT_MD_THREAD
3927 m->mdt_ldlm_client = &m->mdt_md_dev.md_lu_dev.ld_obd->obd_ldlm_client;
3928 ptlrpc_init_client(LDLM_CB_REQUEST_PORTAL, LDLM_CB_REPLY_PORTAL,
3929 "mdt_ldlm_client", m->mdt_ldlm_client);
3931 m->mdt_regular_service =
3932 ptlrpc_init_svc_conf(&conf, mdt_regular_handle, LUSTRE_MDT_NAME,
3933 procfs_entry, target_print_req,
3935 if (m->mdt_regular_service == NULL)
3938 rc = ptlrpc_start_threads(m->mdt_regular_service);
3940 GOTO(err_mdt_svc, rc);
3943 * readpage service configuration. Parameters have to be adjusted,
3946 conf = (typeof(conf)) {
3947 .psc_nbufs = MDS_NBUFS,
3948 .psc_bufsize = MDS_BUFSIZE,
3949 .psc_max_req_size = MDS_MAXREQSIZE,
3950 .psc_max_reply_size = MDS_MAXREPSIZE,
3951 .psc_req_portal = MDS_READPAGE_PORTAL,
3952 .psc_rep_portal = MDC_REPLY_PORTAL,
3953 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
3954 .psc_min_threads = mdt_min_threads,
3955 .psc_max_threads = mdt_max_threads,
3956 .psc_ctx_tags = LCT_MD_THREAD
3958 m->mdt_readpage_service =
3959 ptlrpc_init_svc_conf(&conf, mdt_readpage_handle,
3960 LUSTRE_MDT_NAME "_readpage",
3961 procfs_entry, target_print_req,"mdt_rdpg");
3963 if (m->mdt_readpage_service == NULL) {
3964 CERROR("failed to start readpage service\n");
3965 GOTO(err_mdt_svc, rc = -ENOMEM);
3968 rc = ptlrpc_start_threads(m->mdt_readpage_service);
3971 * setattr service configuration.
3973 * XXX To keep the compatibility with old client(< 2.2), we need to
3974 * preserve this portal for a certain time, it should be removed
3975 * eventually. LU-617.
3977 conf = (typeof(conf)) {
3978 .psc_nbufs = MDS_NBUFS,
3979 .psc_bufsize = MDS_BUFSIZE,
3980 .psc_max_req_size = MDS_MAXREQSIZE,
3981 .psc_max_reply_size = MDS_MAXREPSIZE,
3982 .psc_req_portal = MDS_SETATTR_PORTAL,
3983 .psc_rep_portal = MDC_REPLY_PORTAL,
3984 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
3985 .psc_min_threads = mdt_min_threads,
3986 .psc_max_threads = mdt_max_threads,
3987 .psc_ctx_tags = LCT_MD_THREAD
3990 m->mdt_setattr_service =
3991 ptlrpc_init_svc_conf(&conf, mdt_regular_handle,
3992 LUSTRE_MDT_NAME "_setattr",
3993 procfs_entry, target_print_req,"mdt_attr");
3995 if (!m->mdt_setattr_service) {
3996 CERROR("failed to start setattr service\n");
3997 GOTO(err_mdt_svc, rc = -ENOMEM);
4000 rc = ptlrpc_start_threads(m->mdt_setattr_service);
4002 GOTO(err_mdt_svc, rc);
4005 * sequence controller service configuration
4007 conf = (typeof(conf)) {
4008 .psc_nbufs = MDS_NBUFS,
4009 .psc_bufsize = MDS_BUFSIZE,
4010 .psc_max_req_size = SEQ_MAXREQSIZE,
4011 .psc_max_reply_size = SEQ_MAXREPSIZE,
4012 .psc_req_portal = SEQ_CONTROLLER_PORTAL,
4013 .psc_rep_portal = MDC_REPLY_PORTAL,
4014 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
4015 .psc_min_threads = mdt_min_threads,
4016 .psc_max_threads = mdt_max_threads,
4017 .psc_ctx_tags = LCT_MD_THREAD|LCT_DT_THREAD
4020 m->mdt_mdsc_service =
4021 ptlrpc_init_svc_conf(&conf, mdt_mdsc_handle,
4022 LUSTRE_MDT_NAME"_mdsc",
4023 procfs_entry, target_print_req,"mdt_mdsc");
4024 if (!m->mdt_mdsc_service) {
4025 CERROR("failed to start seq controller service\n");
4026 GOTO(err_mdt_svc, rc = -ENOMEM);
4029 rc = ptlrpc_start_threads(m->mdt_mdsc_service);
4031 GOTO(err_mdt_svc, rc);
4034 * metadata sequence server service configuration
4036 conf = (typeof(conf)) {
4037 .psc_nbufs = MDS_NBUFS,
4038 .psc_bufsize = MDS_BUFSIZE,
4039 .psc_max_req_size = SEQ_MAXREQSIZE,
4040 .psc_max_reply_size = SEQ_MAXREPSIZE,
4041 .psc_req_portal = SEQ_METADATA_PORTAL,
4042 .psc_rep_portal = MDC_REPLY_PORTAL,
4043 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
4044 .psc_min_threads = mdt_min_threads,
4045 .psc_max_threads = mdt_max_threads,
4046 .psc_ctx_tags = LCT_MD_THREAD|LCT_DT_THREAD
4049 m->mdt_mdss_service =
4050 ptlrpc_init_svc_conf(&conf, mdt_mdss_handle,
4051 LUSTRE_MDT_NAME"_mdss",
4052 procfs_entry, target_print_req,"mdt_mdss");
4053 if (!m->mdt_mdss_service) {
4054 CERROR("failed to start metadata seq server service\n");
4055 GOTO(err_mdt_svc, rc = -ENOMEM);
4058 rc = ptlrpc_start_threads(m->mdt_mdss_service);
4060 GOTO(err_mdt_svc, rc);
4064 * Data sequence server service configuration. We want to have really
4065 * cluster-wide sequences space. This is why we start only one sequence
4066 * controller which manages space.
4068 conf = (typeof(conf)) {
4069 .psc_nbufs = MDS_NBUFS,
4070 .psc_bufsize = MDS_BUFSIZE,
4071 .psc_max_req_size = SEQ_MAXREQSIZE,
4072 .psc_max_reply_size = SEQ_MAXREPSIZE,
4073 .psc_req_portal = SEQ_DATA_PORTAL,
4074 .psc_rep_portal = OSC_REPLY_PORTAL,
4075 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
4076 .psc_min_threads = mdt_min_threads,
4077 .psc_max_threads = mdt_max_threads,
4078 .psc_ctx_tags = LCT_MD_THREAD|LCT_DT_THREAD
4081 m->mdt_dtss_service =
4082 ptlrpc_init_svc_conf(&conf, mdt_dtss_handle,
4083 LUSTRE_MDT_NAME"_dtss",
4084 procfs_entry, target_print_req,"mdt_dtss");
4085 if (!m->mdt_dtss_service) {
4086 CERROR("failed to start data seq server service\n");
4087 GOTO(err_mdt_svc, rc = -ENOMEM);
4090 rc = ptlrpc_start_threads(m->mdt_dtss_service);
4092 GOTO(err_mdt_svc, rc);
4094 /* FLD service start */
4095 conf = (typeof(conf)) {
4096 .psc_nbufs = MDS_NBUFS,
4097 .psc_bufsize = MDS_BUFSIZE,
4098 .psc_max_req_size = FLD_MAXREQSIZE,
4099 .psc_max_reply_size = FLD_MAXREPSIZE,
4100 .psc_req_portal = FLD_REQUEST_PORTAL,
4101 .psc_rep_portal = MDC_REPLY_PORTAL,
4102 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
4103 .psc_min_threads = mdt_min_threads,
4104 .psc_max_threads = mdt_max_threads,
4105 .psc_ctx_tags = LCT_DT_THREAD|LCT_MD_THREAD
4108 m->mdt_fld_service =
4109 ptlrpc_init_svc_conf(&conf, mdt_fld_handle,
4110 LUSTRE_MDT_NAME"_fld",
4111 procfs_entry, target_print_req, "mdt_fld");
4112 if (!m->mdt_fld_service) {
4113 CERROR("failed to start fld service\n");
4114 GOTO(err_mdt_svc, rc = -ENOMEM);
4117 rc = ptlrpc_start_threads(m->mdt_fld_service);
4119 GOTO(err_mdt_svc, rc);
4122 * mds-mds service configuration. Separate portal is used to allow
4123 * mds-mds requests be not blocked during recovery.
4125 conf = (typeof(conf)) {
4126 .psc_nbufs = MDS_NBUFS,
4127 .psc_bufsize = MDS_BUFSIZE,
4128 .psc_max_req_size = MDS_MAXREQSIZE,
4129 .psc_max_reply_size = MDS_MAXREPSIZE,
4130 .psc_req_portal = MDS_MDS_PORTAL,
4131 .psc_rep_portal = MDC_REPLY_PORTAL,
4132 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
4133 .psc_min_threads = mdt_min_threads,
4134 .psc_max_threads = mdt_max_threads,
4135 .psc_ctx_tags = LCT_MD_THREAD
4137 m->mdt_xmds_service =
4138 ptlrpc_init_svc_conf(&conf, mdt_xmds_handle,
4139 LUSTRE_MDT_NAME "_mds",
4140 procfs_entry, target_print_req,"mdt_xmds");
4142 if (m->mdt_xmds_service == NULL) {
4143 CERROR("failed to start xmds service\n");
4144 GOTO(err_mdt_svc, rc = -ENOMEM);
4147 rc = ptlrpc_start_threads(m->mdt_xmds_service);
4149 GOTO(err_mdt_svc, rc);
4154 mdt_stop_ptlrpc_service(m);
4159 static void mdt_stack_fini(const struct lu_env *env,
4160 struct mdt_device *m, struct lu_device *top)
4162 struct obd_device *obd = mdt2obd_dev(m);
4163 struct lustre_cfg_bufs *bufs;
4164 struct lustre_cfg *lcfg;
4165 struct mdt_thread_info *info;
4169 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
4170 LASSERT(info != NULL);
4172 bufs = &info->mti_u.bufs;
4173 /* process cleanup, pass mdt obd name to get obd umount flags */
4174 lustre_cfg_bufs_reset(bufs, obd->obd_name);
4179 lustre_cfg_bufs_set_string(bufs, 1, flags);
4180 lcfg = lustre_cfg_new(LCFG_CLEANUP, bufs);
4182 CERROR("Cannot alloc lcfg!\n");
4187 top->ld_ops->ldo_process_config(env, top, lcfg);
4188 lustre_cfg_free(lcfg);
4190 lu_stack_fini(env, top);
4191 m->mdt_child = NULL;
4192 m->mdt_bottom = NULL;
4195 static struct lu_device *mdt_layer_setup(struct lu_env *env,
4196 const char *typename,
4197 struct lu_device *child,
4198 struct lustre_cfg *cfg)
4200 const char *dev = lustre_cfg_string(cfg, 0);
4201 struct obd_type *type;
4202 struct lu_device_type *ldt;
4203 struct lu_device *d;
4208 type = class_get_type(typename);
4210 CERROR("Unknown type: '%s'\n", typename);
4211 GOTO(out, rc = -ENODEV);
4214 rc = lu_env_refill((struct lu_env *)env);
4216 CERROR("Failure to refill session: '%d'\n", rc);
4222 CERROR("type: '%s'\n", typename);
4223 GOTO(out_type, rc = -EINVAL);
4226 ldt->ldt_obd_type = type;
4227 d = ldt->ldt_ops->ldto_device_alloc(env, ldt, cfg);
4229 CERROR("Cannot allocate device: '%s'\n", typename);
4230 GOTO(out_type, rc = -ENODEV);
4233 LASSERT(child->ld_site);
4234 d->ld_site = child->ld_site;
4237 rc = ldt->ldt_ops->ldto_device_init(env, d, dev, child);
4239 CERROR("can't init device '%s', rc %d\n", typename, rc);
4240 GOTO(out_alloc, rc);
4243 lu_ref_add(&d->ld_reference, "lu-stack", &lu_site_init);
4245 cfs_spin_lock(&d->ld_site->ls_ld_lock);
4246 cfs_list_add_tail(&d->ld_linkage, &d->ld_site->ls_ld_linkage);
4247 cfs_spin_unlock(&d->ld_site->ls_ld_lock);
4251 ldt->ldt_ops->ldto_device_free(env, d);
4254 class_put_type(type);
4259 static int mdt_stack_init(struct lu_env *env,
4260 struct mdt_device *m,
4261 struct lustre_cfg *cfg,
4262 struct lustre_mount_info *lmi)
4264 struct lu_device *d = &m->mdt_md_dev.md_lu_dev;
4265 struct lu_device *tmp;
4266 struct md_device *md;
4267 struct lu_device *child_lu_dev;
4271 /* init the stack */
4272 tmp = mdt_layer_setup(env, LUSTRE_OSD_NAME, d, cfg);
4274 RETURN(PTR_ERR(tmp));
4276 m->mdt_bottom = lu2dt_dev(tmp);
4278 tmp = mdt_layer_setup(env, LUSTRE_MDD_NAME, d, cfg);
4280 GOTO(out, rc = PTR_ERR(tmp));
4285 tmp = mdt_layer_setup(env, LUSTRE_CMM_NAME, d, cfg);
4287 GOTO(out, rc = PTR_ERR(tmp));
4290 /*set mdd upcall device*/
4291 md_upcall_dev_set(md, lu2md_dev(d));
4294 /*set cmm upcall device*/
4295 md_upcall_dev_set(md, &m->mdt_md_dev);
4297 m->mdt_child = lu2md_dev(d);
4299 /* process setup config */
4300 tmp = &m->mdt_md_dev.md_lu_dev;
4301 rc = tmp->ld_ops->ldo_process_config(env, tmp, cfg);
4305 /* initialize local objects */
4306 child_lu_dev = &m->mdt_child->md_lu_dev;
4308 rc = child_lu_dev->ld_ops->ldo_prepare(env,
4309 &m->mdt_md_dev.md_lu_dev,
4312 /* fini from last known good lu_device */
4314 mdt_stack_fini(env, m, d);
4320 * setup CONFIG_ORIG context, used to access local config log.
4321 * this may need to be rewrite as part of llog rewrite for lu-api.
4323 static int mdt_obd_llog_setup(struct obd_device *obd,
4324 struct lustre_sb_info *lsi)
4328 LASSERT(obd->obd_fsops == NULL);
4330 obd->obd_fsops = fsfilt_get_ops(MT_STR(lsi->lsi_ldd));
4331 if (IS_ERR(obd->obd_fsops))
4332 return PTR_ERR(obd->obd_fsops);
4334 rc = fsfilt_setup(obd, lsi->lsi_srv_mnt->mnt_sb);
4336 fsfilt_put_ops(obd->obd_fsops);
4340 OBD_SET_CTXT_MAGIC(&obd->obd_lvfs_ctxt);
4341 obd->obd_lvfs_ctxt.pwdmnt = lsi->lsi_srv_mnt;
4342 obd->obd_lvfs_ctxt.pwd = lsi->lsi_srv_mnt->mnt_root;
4343 obd->obd_lvfs_ctxt.fs = get_ds();
4345 rc = llog_setup(obd, &obd->obd_olg, LLOG_CONFIG_ORIG_CTXT, obd,
4346 0, NULL, &llog_lvfs_ops);
4348 CERROR("llog_setup() failed: %d\n", rc);
4349 fsfilt_put_ops(obd->obd_fsops);
4355 static void mdt_obd_llog_cleanup(struct obd_device *obd)
4357 struct llog_ctxt *ctxt;
4359 ctxt = llog_get_context(obd, LLOG_CONFIG_ORIG_CTXT);
4363 if (obd->obd_fsops) {
4364 fsfilt_put_ops(obd->obd_fsops);
4365 obd->obd_fsops = NULL;
4369 static void mdt_fini(const struct lu_env *env, struct mdt_device *m)
4371 struct md_device *next = m->mdt_child;
4372 struct lu_device *d = &m->mdt_md_dev.md_lu_dev;
4373 struct lu_site *ls = d->ld_site;
4374 struct obd_device *obd = mdt2obd_dev(m);
4377 target_recovery_fini(obd);
4379 ping_evictor_stop();
4381 mdt_stop_ptlrpc_service(m);
4382 mdt_llog_ctxt_unclone(env, m, LLOG_CHANGELOG_ORIG_CTXT);
4383 mdt_obd_llog_cleanup(obd);
4384 obd_exports_barrier(obd);
4385 obd_zombie_barrier();
4389 #ifdef HAVE_QUOTA_SUPPORT
4390 next->md_ops->mdo_quota.mqo_cleanup(env, next);
4392 lut_fini(env, &m->mdt_lut);
4393 mdt_fs_cleanup(env, m);
4394 upcall_cache_cleanup(m->mdt_identity_cache);
4395 m->mdt_identity_cache = NULL;
4397 if (m->mdt_namespace != NULL) {
4398 ldlm_namespace_free(m->mdt_namespace, NULL,
4399 d->ld_obd->obd_force);
4400 d->ld_obd->obd_namespace = m->mdt_namespace = NULL;
4403 cfs_free_nidlist(&m->mdt_nosquash_nids);
4404 if (m->mdt_nosquash_str) {
4405 OBD_FREE(m->mdt_nosquash_str, m->mdt_nosquash_strlen);
4406 m->mdt_nosquash_str = NULL;
4407 m->mdt_nosquash_strlen = 0;
4410 mdt_seq_fini(env, m);
4411 mdt_seq_fini_cli(m);
4412 mdt_fld_fini(env, m);
4413 sptlrpc_rule_set_free(&m->mdt_sptlrpc_rset);
4415 next->md_ops->mdo_init_capa_ctxt(env, next, 0, 0, 0, NULL);
4416 cfs_timer_disarm(&m->mdt_ck_timer);
4417 mdt_ck_thread_stop(m);
4422 mdt_stack_fini(env, m, md2lu_dev(m->mdt_child));
4425 struct md_site *mite;
4428 mite = lu_site2md(ls);
4432 LASSERT(cfs_atomic_read(&d->ld_ref) == 0);
4437 static int mdt_adapt_sptlrpc_conf(struct obd_device *obd, int initial)
4439 struct mdt_device *m = mdt_dev(obd->obd_lu_dev);
4440 struct sptlrpc_rule_set tmp_rset;
4443 sptlrpc_rule_set_init(&tmp_rset);
4444 rc = sptlrpc_conf_target_get_rules(obd, &tmp_rset, initial);
4446 CERROR("mdt %s: failed get sptlrpc rules: %d\n",
4451 sptlrpc_target_update_exp_flavor(obd, &tmp_rset);
4453 cfs_write_lock(&m->mdt_sptlrpc_lock);
4454 sptlrpc_rule_set_free(&m->mdt_sptlrpc_rset);
4455 m->mdt_sptlrpc_rset = tmp_rset;
4456 cfs_write_unlock(&m->mdt_sptlrpc_lock);
4461 int mdt_postrecov(const struct lu_env *, struct mdt_device *);
4463 static int mdt_init0(const struct lu_env *env, struct mdt_device *m,
4464 struct lu_device_type *ldt, struct lustre_cfg *cfg)
4466 struct mdt_thread_info *info;
4467 struct obd_device *obd;
4468 const char *dev = lustre_cfg_string(cfg, 0);
4469 const char *num = lustre_cfg_string(cfg, 2);
4470 struct lustre_mount_info *lmi = NULL;
4471 struct lustre_sb_info *lsi;
4472 struct lustre_disk_data *ldd;
4474 struct md_site *mite;
4475 const char *identity_upcall = "NONE";
4476 struct md_device *next;
4482 md_device_init(&m->mdt_md_dev, ldt);
4484 * Environment (env) might be missing mdt_thread_key values at that
4485 * point, if device is allocated when mdt_thread_key is in QUIESCENT
4488 * Usually device allocation path doesn't use module key values, but
4489 * mdt has to do a lot of work here, so allocate key value.
4491 rc = lu_env_refill((struct lu_env *)env);
4495 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
4496 LASSERT(info != NULL);
4498 obd = class_name2obd(dev);
4499 LASSERT(obd != NULL);
4501 m->mdt_max_mdsize = MAX_MD_SIZE; /* 4 stripes */
4502 m->mdt_max_cookiesize = sizeof(struct llog_cookie);
4504 m->mdt_som_conf = 0;
4506 m->mdt_opts.mo_cos = MDT_COS_DEFAULT;
4507 lmi = server_get_mount_2(dev);
4509 CERROR("Cannot get mount info for %s!\n", dev);
4512 lsi = s2lsi(lmi->lmi_sb);
4513 /* CMD is supported only in IAM mode */
4516 node_id = simple_strtol(num, NULL, 10);
4517 if (!(ldd->ldd_flags & LDD_F_IAM_DIR) && node_id) {
4518 CERROR("CMD Operation not allowed in IOP mode\n");
4519 GOTO(err_lmi, rc = -EINVAL);
4522 obd->u.obt.obt_magic = OBT_MAGIC;
4525 cfs_rwlock_init(&m->mdt_sptlrpc_lock);
4526 sptlrpc_rule_set_init(&m->mdt_sptlrpc_rset);
4528 cfs_spin_lock_init(&m->mdt_ioepoch_lock);
4529 m->mdt_opts.mo_compat_resname = 0;
4530 m->mdt_opts.mo_mds_capa = 1;
4531 m->mdt_opts.mo_oss_capa = 1;
4532 m->mdt_capa_timeout = CAPA_TIMEOUT;
4533 m->mdt_capa_alg = CAPA_HMAC_ALG_SHA1;
4534 m->mdt_ck_timeout = CAPA_KEY_TIMEOUT;
4535 m->mdt_squash_uid = 0;
4536 m->mdt_squash_gid = 0;
4537 CFS_INIT_LIST_HEAD(&m->mdt_nosquash_nids);
4538 m->mdt_nosquash_str = NULL;
4539 m->mdt_nosquash_strlen = 0;
4540 cfs_init_rwsem(&m->mdt_squash_sem);
4542 OBD_ALLOC_PTR(mite);
4544 GOTO(err_lmi, rc = -ENOMEM);
4548 m->mdt_md_dev.md_lu_dev.ld_ops = &mdt_lu_ops;
4549 m->mdt_md_dev.md_lu_dev.ld_obd = obd;
4550 /* set this lu_device to obd, because error handling need it */
4551 obd->obd_lu_dev = &m->mdt_md_dev.md_lu_dev;
4553 rc = lu_site_init(s, &m->mdt_md_dev.md_lu_dev);
4555 CERROR("Can't init lu_site, rc %d\n", rc);
4556 GOTO(err_free_site, rc);
4559 /* set server index */
4560 lu_site2md(s)->ms_node_id = node_id;
4562 /* failover is the default
4563 * FIXME: we do not failout mds0/mgs, which may cause some problems.
4564 * assumed whose ms_node_id == 0 XXX
4566 obd->obd_replayable = 1;
4567 /* No connection accepted until configurations will finish */
4568 obd->obd_no_conn = 1;
4570 if (cfg->lcfg_bufcount > 4 && LUSTRE_CFG_BUFLEN(cfg, 4) > 0) {
4571 char *str = lustre_cfg_string(cfg, 4);
4572 if (strchr(str, 'n')) {
4573 CWARN("%s: recovery disabled\n", obd->obd_name);
4574 obd->obd_replayable = 0;
4578 /* init the stack */
4579 rc = mdt_stack_init((struct lu_env *)env, m, cfg, lmi);
4581 CERROR("Can't init device stack, rc %d\n", rc);
4582 GOTO(err_lu_site, rc);
4585 rc = lut_init(env, &m->mdt_lut, obd, m->mdt_bottom);
4587 GOTO(err_fini_stack, rc);
4589 rc = mdt_fld_init(env, obd->obd_name, m);
4593 rc = mdt_seq_init(env, obd->obd_name, m);
4595 GOTO(err_fini_fld, rc);
4597 snprintf(info->mti_u.ns_name, sizeof info->mti_u.ns_name,
4598 LUSTRE_MDT_NAME"-%p", m);
4599 m->mdt_namespace = ldlm_namespace_new(obd, info->mti_u.ns_name,
4600 LDLM_NAMESPACE_SERVER,
4601 LDLM_NAMESPACE_GREEDY,
4603 if (m->mdt_namespace == NULL)
4604 GOTO(err_fini_seq, rc = -ENOMEM);
4606 ldlm_register_intent(m->mdt_namespace, mdt_intent_policy);
4607 /* set obd_namespace for compatibility with old code */
4608 obd->obd_namespace = m->mdt_namespace;
4610 cfs_timer_init(&m->mdt_ck_timer, mdt_ck_timer_callback, m);
4612 rc = mdt_ck_thread_start(m);
4614 GOTO(err_free_ns, rc);
4616 rc = mdt_fs_setup(env, m, obd, lsi);
4620 rc = mdt_obd_llog_setup(obd, lsi);
4622 GOTO(err_fs_cleanup, rc);
4624 rc = mdt_llog_ctxt_clone(env, m, LLOG_CHANGELOG_ORIG_CTXT);
4626 GOTO(err_llog_cleanup, rc);
4628 mdt_adapt_sptlrpc_conf(obd, 1);
4630 next = m->mdt_child;
4631 #ifdef HAVE_QUOTA_SUPPORT
4632 rc = next->md_ops->mdo_quota.mqo_setup(env, next, lmi->lmi_mnt);
4634 GOTO(err_llog_cleanup, rc);
4637 server_put_mount_2(dev, lmi->lmi_mnt);
4640 rc = next->md_ops->mdo_iocontrol(env, next, OBD_IOC_GET_MNTOPT, 0,
4643 GOTO(err_quota, rc);
4645 if (mntopts & MNTOPT_USERXATTR)
4646 m->mdt_opts.mo_user_xattr = 1;
4648 m->mdt_opts.mo_user_xattr = 0;
4650 if (mntopts & MNTOPT_ACL)
4651 m->mdt_opts.mo_acl = 1;
4653 m->mdt_opts.mo_acl = 0;
4655 /* XXX: to support suppgid for ACL, we enable identity_upcall
4656 * by default, otherwise, maybe got unexpected -EACCESS. */
4657 if (m->mdt_opts.mo_acl)
4658 identity_upcall = MDT_IDENTITY_UPCALL_PATH;
4660 m->mdt_identity_cache = upcall_cache_init(obd->obd_name,identity_upcall,
4661 &mdt_identity_upcall_cache_ops);
4662 if (IS_ERR(m->mdt_identity_cache)) {
4663 rc = PTR_ERR(m->mdt_identity_cache);
4664 m->mdt_identity_cache = NULL;
4665 GOTO(err_quota, rc);
4668 target_recovery_init(&m->mdt_lut, mdt_recovery_handle);
4670 rc = mdt_procfs_init(m, dev);
4672 CERROR("Can't init MDT lprocfs, rc %d\n", rc);
4673 GOTO(err_recovery, rc);
4676 rc = mdt_start_ptlrpc_service(m);
4678 GOTO(err_procfs, rc);
4680 ping_evictor_start();
4682 rc = lu_site_init_finish(s);
4684 GOTO(err_stop_service, rc);
4686 if (obd->obd_recovering == 0)
4687 mdt_postrecov(env, m);
4689 mdt_init_capa_ctxt(env, m);
4691 /* Reduce the initial timeout on an MDS because it doesn't need such
4692 * a long timeout as an OST does. Adaptive timeouts will adjust this
4693 * value appropriately. */
4694 if (ldlm_timeout == LDLM_TIMEOUT_DEFAULT)
4695 ldlm_timeout = MDS_LDLM_TIMEOUT_DEFAULT;
4700 ping_evictor_stop();
4701 mdt_stop_ptlrpc_service(m);
4705 target_recovery_fini(obd);
4706 upcall_cache_cleanup(m->mdt_identity_cache);
4707 m->mdt_identity_cache = NULL;
4709 #ifdef HAVE_QUOTA_SUPPORT
4710 next->md_ops->mdo_quota.mqo_cleanup(env, next);
4713 mdt_llog_ctxt_unclone(env, m, LLOG_CHANGELOG_ORIG_CTXT);
4714 mdt_obd_llog_cleanup(obd);
4716 mdt_fs_cleanup(env, m);
4718 cfs_timer_disarm(&m->mdt_ck_timer);
4719 mdt_ck_thread_stop(m);
4721 ldlm_namespace_free(m->mdt_namespace, NULL, 0);
4722 obd->obd_namespace = m->mdt_namespace = NULL;
4724 mdt_seq_fini(env, m);
4726 mdt_fld_fini(env, m);
4728 lut_fini(env, &m->mdt_lut);
4730 mdt_stack_fini(env, m, md2lu_dev(m->mdt_child));
4737 server_put_mount_2(dev, lmi->lmi_mnt);
4741 /* used by MGS to process specific configurations */
4742 static int mdt_process_config(const struct lu_env *env,
4743 struct lu_device *d, struct lustre_cfg *cfg)
4745 struct mdt_device *m = mdt_dev(d);
4746 struct md_device *md_next = m->mdt_child;
4747 struct lu_device *next = md2lu_dev(md_next);
4751 switch (cfg->lcfg_command) {
4753 struct lprocfs_static_vars lvars;
4754 struct obd_device *obd = d->ld_obd;
4757 * For interoperability between 1.8 and 2.0,
4760 /* Skip old "mdt.group_upcall" param. */
4761 char *param = lustre_cfg_string(cfg, 1);
4762 if (param && !strncmp("mdt.group_upcall", param, 16)) {
4763 CWARN("For 1.8 interoperability, skip this"
4764 " mdt.group_upcall. It is obsolete\n");
4767 /* Rename old "mdt.quota_type" to "mdd.quota_type. */
4768 if (param && !strncmp("mdt.quota_type", param, 14)) {
4769 CWARN("Found old param mdt.quota_type, changed"
4770 " it to mdd.quota_type.\n");
4775 lprocfs_mdt_init_vars(&lvars);
4776 rc = class_process_proc_param(PARAM_MDT, lvars.obd_vars,
4778 if (rc > 0 || rc == -ENOSYS)
4779 /* we don't understand; pass it on */
4780 rc = next->ld_ops->ldo_process_config(env, next, cfg);
4785 * Add mdc hook to get first MDT uuid and connect it to
4786 * ls->controller to use for seq manager.
4788 rc = next->ld_ops->ldo_process_config(env, next, cfg);
4790 CERROR("Can't add mdc, rc %d\n", rc);
4792 rc = mdt_seq_init_cli(env, mdt_dev(d), cfg);
4795 /* others are passed further */
4796 rc = next->ld_ops->ldo_process_config(env, next, cfg);
4802 static struct lu_object *mdt_object_alloc(const struct lu_env *env,
4803 const struct lu_object_header *hdr,
4804 struct lu_device *d)
4806 struct mdt_object *mo;
4812 struct lu_object *o;
4813 struct lu_object_header *h;
4815 o = &mo->mot_obj.mo_lu;
4816 h = &mo->mot_header;
4817 lu_object_header_init(h);
4818 lu_object_init(o, h, d);
4819 lu_object_add_top(h, o);
4820 o->lo_ops = &mdt_obj_ops;
4821 cfs_mutex_init(&mo->mot_ioepoch_mutex);
4822 cfs_mutex_init(&mo->mot_lov_mutex);
4828 static int mdt_object_init(const struct lu_env *env, struct lu_object *o,
4829 const struct lu_object_conf *unused)
4831 struct mdt_device *d = mdt_dev(o->lo_dev);
4832 struct lu_device *under;
4833 struct lu_object *below;
4837 CDEBUG(D_INFO, "object init, fid = "DFID"\n",
4838 PFID(lu_object_fid(o)));
4840 under = &d->mdt_child->md_lu_dev;
4841 below = under->ld_ops->ldo_object_alloc(env, o->lo_header, under);
4842 if (below != NULL) {
4843 lu_object_add(o, below);
4850 static void mdt_object_free(const struct lu_env *env, struct lu_object *o)
4852 struct mdt_object *mo = mdt_obj(o);
4853 struct lu_object_header *h;
4857 CDEBUG(D_INFO, "object free, fid = "DFID"\n",
4858 PFID(lu_object_fid(o)));
4861 lu_object_header_fini(h);
4866 static int mdt_object_print(const struct lu_env *env, void *cookie,
4867 lu_printer_t p, const struct lu_object *o)
4869 struct mdt_object *mdto = mdt_obj((struct lu_object *)o);
4870 return (*p)(env, cookie, LUSTRE_MDT_NAME"-object@%p(ioepoch="LPU64" "
4871 "flags="LPX64", epochcount=%d, writecount=%d)",
4872 mdto, mdto->mot_ioepoch, mdto->mot_flags,
4873 mdto->mot_ioepoch_count, mdto->mot_writecount);
4876 static const struct lu_device_operations mdt_lu_ops = {
4877 .ldo_object_alloc = mdt_object_alloc,
4878 .ldo_process_config = mdt_process_config,
4881 static const struct lu_object_operations mdt_obj_ops = {
4882 .loo_object_init = mdt_object_init,
4883 .loo_object_free = mdt_object_free,
4884 .loo_object_print = mdt_object_print
4887 static int mdt_obd_set_info_async(struct obd_export *exp,
4888 __u32 keylen, void *key,
4889 __u32 vallen, void *val,
4890 struct ptlrpc_request_set *set)
4892 struct obd_device *obd = exp->exp_obd;
4898 if (KEY_IS(KEY_SPTLRPC_CONF)) {
4899 rc = mdt_adapt_sptlrpc_conf(obd, 0);
4906 /* mds_connect_internal */
4907 static int mdt_connect_internal(struct obd_export *exp,
4908 struct mdt_device *mdt,
4909 struct obd_connect_data *data)
4912 data->ocd_connect_flags &= MDT_CONNECT_SUPPORTED;
4913 data->ocd_ibits_known &= MDS_INODELOCK_FULL;
4915 /* If no known bits (which should not happen, probably,
4916 as everybody should support LOOKUP and UPDATE bits at least)
4917 revert to compat mode with plain locks. */
4918 if (!data->ocd_ibits_known &&
4919 data->ocd_connect_flags & OBD_CONNECT_IBITS)
4920 data->ocd_connect_flags &= ~OBD_CONNECT_IBITS;
4922 if (!mdt->mdt_opts.mo_acl)
4923 data->ocd_connect_flags &= ~OBD_CONNECT_ACL;
4925 if (!mdt->mdt_opts.mo_user_xattr)
4926 data->ocd_connect_flags &= ~OBD_CONNECT_XATTR;
4928 if (!mdt->mdt_som_conf)
4929 data->ocd_connect_flags &= ~OBD_CONNECT_SOM;
4931 if (data->ocd_connect_flags & OBD_CONNECT_BRW_SIZE) {
4932 data->ocd_brw_size = min(data->ocd_brw_size,
4933 (__u32)(PTLRPC_MAX_BRW_PAGES << CFS_PAGE_SHIFT));
4934 if (data->ocd_brw_size == 0) {
4935 CERROR("%s: cli %s/%p ocd_connect_flags: "LPX64
4936 " ocd_version: %x ocd_grant: %d "
4937 "ocd_index: %u ocd_brw_size is "
4938 "unexpectedly zero, network data "
4939 "corruption? Refusing connection of this"
4941 exp->exp_obd->obd_name,
4942 exp->exp_client_uuid.uuid,
4943 exp, data->ocd_connect_flags, data->ocd_version,
4944 data->ocd_grant, data->ocd_index);
4949 cfs_spin_lock(&exp->exp_lock);
4950 exp->exp_connect_flags = data->ocd_connect_flags;
4951 cfs_spin_unlock(&exp->exp_lock);
4952 data->ocd_version = LUSTRE_VERSION_CODE;
4953 exp->exp_mdt_data.med_ibits_known = data->ocd_ibits_known;
4957 if (mdt->mdt_opts.mo_acl &&
4958 ((exp->exp_connect_flags & OBD_CONNECT_ACL) == 0)) {
4959 CWARN("%s: MDS requires ACL support but client does not\n",
4960 mdt->mdt_md_dev.md_lu_dev.ld_obd->obd_name);
4965 if ((exp->exp_connect_flags & OBD_CONNECT_FID) == 0) {
4966 CWARN("%s: MDS requires FID support, but client not\n",
4967 mdt->mdt_md_dev.md_lu_dev.ld_obd->obd_name);
4971 if (mdt->mdt_som_conf && !exp_connect_som(exp) &&
4972 !(exp->exp_connect_flags & OBD_CONNECT_MDS_MDS)) {
4973 CWARN("%s: MDS has SOM enabled, but client does not support "
4974 "it\n", mdt->mdt_md_dev.md_lu_dev.ld_obd->obd_name);
4981 static int mdt_connect_check_sptlrpc(struct mdt_device *mdt,
4982 struct obd_export *exp,
4983 struct ptlrpc_request *req)
4985 struct sptlrpc_flavor flvr;
4988 if (exp->exp_flvr.sf_rpc == SPTLRPC_FLVR_INVALID) {
4989 cfs_read_lock(&mdt->mdt_sptlrpc_lock);
4990 sptlrpc_target_choose_flavor(&mdt->mdt_sptlrpc_rset,
4994 cfs_read_unlock(&mdt->mdt_sptlrpc_lock);
4996 cfs_spin_lock(&exp->exp_lock);
4998 exp->exp_sp_peer = req->rq_sp_from;
4999 exp->exp_flvr = flvr;
5001 if (exp->exp_flvr.sf_rpc != SPTLRPC_FLVR_ANY &&
5002 exp->exp_flvr.sf_rpc != req->rq_flvr.sf_rpc) {
5003 CERROR("unauthorized rpc flavor %x from %s, "
5004 "expect %x\n", req->rq_flvr.sf_rpc,
5005 libcfs_nid2str(req->rq_peer.nid),
5006 exp->exp_flvr.sf_rpc);
5010 cfs_spin_unlock(&exp->exp_lock);
5012 if (exp->exp_sp_peer != req->rq_sp_from) {
5013 CERROR("RPC source %s doesn't match %s\n",
5014 sptlrpc_part2name(req->rq_sp_from),
5015 sptlrpc_part2name(exp->exp_sp_peer));
5018 rc = sptlrpc_target_export_check(exp, req);
5025 /* mds_connect copy */
5026 static int mdt_obd_connect(const struct lu_env *env,
5027 struct obd_export **exp, struct obd_device *obd,
5028 struct obd_uuid *cluuid,
5029 struct obd_connect_data *data,
5032 struct mdt_thread_info *info;
5033 struct obd_export *lexp;
5034 struct lustre_handle conn = { 0 };
5035 struct mdt_device *mdt;
5036 struct ptlrpc_request *req;
5040 LASSERT(env != NULL);
5041 if (!exp || !obd || !cluuid)
5044 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
5045 req = info->mti_pill->rc_req;
5046 mdt = mdt_dev(obd->obd_lu_dev);
5048 rc = class_connect(&conn, obd, cluuid);
5052 lexp = class_conn2export(&conn);
5053 LASSERT(lexp != NULL);
5055 rc = mdt_connect_check_sptlrpc(mdt, lexp, req);
5059 if (OBD_FAIL_CHECK(OBD_FAIL_TGT_RCVG_FLAG))
5060 lustre_msg_add_op_flags(req->rq_repmsg, MSG_CONNECT_RECOVERING);
5062 rc = mdt_connect_internal(lexp, mdt, data);
5064 struct mdt_thread_info *mti;
5065 struct lsd_client_data *lcd = lexp->exp_target_data.ted_lcd;
5067 mti = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
5068 LASSERT(mti != NULL);
5069 mti->mti_exp = lexp;
5070 memcpy(lcd->lcd_uuid, cluuid, sizeof lcd->lcd_uuid);
5071 rc = mdt_client_new(env, mdt);
5073 mdt_export_stats_init(obd, lexp, localdata);
5078 class_disconnect(lexp);
5087 static int mdt_obd_reconnect(const struct lu_env *env,
5088 struct obd_export *exp, struct obd_device *obd,
5089 struct obd_uuid *cluuid,
5090 struct obd_connect_data *data,
5093 struct mdt_thread_info *info;
5094 struct mdt_device *mdt;
5095 struct ptlrpc_request *req;
5099 if (exp == NULL || obd == NULL || cluuid == NULL)
5102 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
5103 req = info->mti_pill->rc_req;
5104 mdt = mdt_dev(obd->obd_lu_dev);
5106 rc = mdt_connect_check_sptlrpc(mdt, exp, req);
5110 rc = mdt_connect_internal(exp, mdt_dev(obd->obd_lu_dev), data);
5112 mdt_export_stats_init(obd, exp, localdata);
5116 static int mdt_export_cleanup(struct obd_export *exp)
5118 struct mdt_export_data *med = &exp->exp_mdt_data;
5119 struct obd_device *obd = exp->exp_obd;
5120 struct mdt_device *mdt;
5121 struct mdt_thread_info *info;
5123 CFS_LIST_HEAD(closing_list);
5124 struct mdt_file_data *mfd, *n;
5128 cfs_spin_lock(&med->med_open_lock);
5129 while (!cfs_list_empty(&med->med_open_head)) {
5130 cfs_list_t *tmp = med->med_open_head.next;
5131 mfd = cfs_list_entry(tmp, struct mdt_file_data, mfd_list);
5133 /* Remove mfd handle so it can't be found again.
5134 * We are consuming the mfd_list reference here. */
5135 class_handle_unhash(&mfd->mfd_handle);
5136 cfs_list_move_tail(&mfd->mfd_list, &closing_list);
5138 cfs_spin_unlock(&med->med_open_lock);
5139 mdt = mdt_dev(obd->obd_lu_dev);
5140 LASSERT(mdt != NULL);
5142 rc = lu_env_init(&env, LCT_MD_THREAD);
5146 info = lu_context_key_get(&env.le_ctx, &mdt_thread_key);
5147 LASSERT(info != NULL);
5148 memset(info, 0, sizeof *info);
5149 info->mti_env = &env;
5150 info->mti_mdt = mdt;
5151 info->mti_exp = exp;
5153 if (!cfs_list_empty(&closing_list)) {
5154 struct md_attr *ma = &info->mti_attr;
5158 lmm_size = mdt->mdt_max_mdsize;
5159 OBD_ALLOC_LARGE(ma->ma_lmm, lmm_size);
5160 if (ma->ma_lmm == NULL)
5161 GOTO(out_lmm, rc = -ENOMEM);
5163 cookie_size = mdt->mdt_max_cookiesize;
5164 OBD_ALLOC_LARGE(ma->ma_cookie, cookie_size);
5165 if (ma->ma_cookie == NULL)
5166 GOTO(out_cookie, rc = -ENOMEM);
5168 /* Close any open files (which may also cause orphan unlinking). */
5169 cfs_list_for_each_entry_safe(mfd, n, &closing_list, mfd_list) {
5170 cfs_list_del_init(&mfd->mfd_list);
5171 memset(&ma->ma_attr, 0, sizeof(ma->ma_attr));
5172 ma->ma_lmm_size = lmm_size;
5173 ma->ma_cookie_size = cookie_size;
5175 /* It is not for setattr, just tell MDD to send
5176 * DESTROY RPC to OSS if needed */
5177 ma->ma_valid = MA_FLAGS;
5178 ma->ma_attr_flags = MDS_CLOSE_CLEANUP;
5179 /* Don't unlink orphan on failover umount, LU-184 */
5180 if (exp->exp_flags & OBD_OPT_FAILOVER)
5181 ma->ma_attr_flags |= MDS_KEEP_ORPHAN;
5182 mdt_mfd_close(info, mfd);
5184 OBD_FREE_LARGE(ma->ma_cookie, cookie_size);
5185 ma->ma_cookie = NULL;
5187 OBD_FREE_LARGE(ma->ma_lmm, lmm_size);
5191 info->mti_mdt = NULL;
5192 /* cleanup client slot early */
5193 /* Do not erase record for recoverable client. */
5194 if (!(exp->exp_flags & OBD_OPT_FAILOVER) || exp->exp_failed)
5195 mdt_client_del(&env, mdt);
5201 static int mdt_obd_disconnect(struct obd_export *exp)
5207 class_export_get(exp);
5209 rc = server_disconnect_export(exp);
5211 CDEBUG(D_IOCTL, "server disconnect error: %d\n", rc);
5213 rc = mdt_export_cleanup(exp);
5214 class_export_put(exp);
5218 /* FIXME: Can we avoid using these two interfaces? */
5219 static int mdt_init_export(struct obd_export *exp)
5221 struct mdt_export_data *med = &exp->exp_mdt_data;
5225 CFS_INIT_LIST_HEAD(&med->med_open_head);
5226 cfs_spin_lock_init(&med->med_open_lock);
5227 cfs_mutex_init(&med->med_idmap_mutex);
5228 med->med_idmap = NULL;
5229 cfs_spin_lock(&exp->exp_lock);
5230 exp->exp_connecting = 1;
5231 cfs_spin_unlock(&exp->exp_lock);
5233 /* self-export doesn't need client data and ldlm initialization */
5234 if (unlikely(obd_uuid_equals(&exp->exp_obd->obd_uuid,
5235 &exp->exp_client_uuid)))
5238 rc = lut_client_alloc(exp);
5240 rc = ldlm_init_export(exp);
5242 CERROR("%s: Error %d while initializing export\n",
5243 exp->exp_obd->obd_name, rc);
5247 static int mdt_destroy_export(struct obd_export *exp)
5251 if (exp_connect_rmtclient(exp))
5252 mdt_cleanup_idmap(&exp->exp_mdt_data);
5254 target_destroy_export(exp);
5255 /* destroy can be called from failed obd_setup, so
5256 * checking uuid is safer than obd_self_export */
5257 if (unlikely(obd_uuid_equals(&exp->exp_obd->obd_uuid,
5258 &exp->exp_client_uuid)))
5261 ldlm_destroy_export(exp);
5262 lut_client_free(exp);
5264 LASSERT(cfs_list_empty(&exp->exp_outstanding_replies));
5265 LASSERT(cfs_list_empty(&exp->exp_mdt_data.med_open_head));
5270 static void mdt_allow_cli(struct mdt_device *m, unsigned int flag)
5272 if (flag & CONFIG_LOG)
5273 cfs_set_bit(MDT_FL_CFGLOG, &m->mdt_state);
5275 /* also notify active event */
5276 if (flag & CONFIG_SYNC)
5277 cfs_set_bit(MDT_FL_SYNCED, &m->mdt_state);
5279 if (cfs_test_bit(MDT_FL_CFGLOG, &m->mdt_state) &&
5280 cfs_test_bit(MDT_FL_SYNCED, &m->mdt_state)) {
5281 struct obd_device *obd = m->mdt_md_dev.md_lu_dev.ld_obd;
5283 /* Open for clients */
5284 if (obd->obd_no_conn) {
5285 cfs_spin_lock(&obd->obd_dev_lock);
5286 obd->obd_no_conn = 0;
5287 cfs_spin_unlock(&obd->obd_dev_lock);
5292 static int mdt_upcall(const struct lu_env *env, struct md_device *md,
5293 enum md_upcall_event ev, void *data)
5295 struct mdt_device *m = mdt_dev(&md->md_lu_dev);
5296 struct md_device *next = m->mdt_child;
5297 struct mdt_thread_info *mti;
5303 rc = next->md_ops->mdo_maxsize_get(env, next,
5305 &m->mdt_max_cookiesize);
5306 CDEBUG(D_INFO, "get max mdsize %d max cookiesize %d\n",
5307 m->mdt_max_mdsize, m->mdt_max_cookiesize);
5308 mdt_allow_cli(m, CONFIG_SYNC);
5311 m->mdt_lut.lut_obd->u.obt.obt_mount_count;
5314 mti = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
5315 mti->mti_no_need_trans = 1;
5316 CDEBUG(D_INFO, "disable mdt trans for this thread\n");
5319 /* Check that MDT is not yet configured */
5320 LASSERT(!cfs_test_bit(MDT_FL_CFGLOG, &m->mdt_state));
5322 #ifdef HAVE_QUOTA_SUPPORT
5324 if (md->md_lu_dev.ld_obd->obd_recovering == 0 &&
5325 likely(md->md_lu_dev.ld_obd->obd_stopping == 0))
5326 next->md_ops->mdo_quota.mqo_recovery(env, next);
5330 CERROR("invalid event\n");
5337 static int mdt_obd_notify(struct obd_device *obd,
5338 struct obd_device *watched,
5339 enum obd_notify_event ev, void *data)
5341 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
5342 #ifdef HAVE_QUOTA_SUPPORT
5343 struct md_device *next = mdt->mdt_child;
5348 case OBD_NOTIFY_CONFIG:
5349 mdt_allow_cli(mdt, (unsigned long)data);
5351 #ifdef HAVE_QUOTA_SUPPORT
5352 /* quota_type has been processed, we can now handle
5353 * incoming quota requests */
5354 next->md_ops->mdo_quota.mqo_notify(NULL, next);
5358 CDEBUG(D_INFO, "Unhandled notification %#x\n", ev);
5363 static int mdt_rpc_fid2path(struct mdt_thread_info *info, void *key,
5364 void *val, int vallen)
5366 struct mdt_device *mdt = mdt_dev(info->mti_exp->exp_obd->obd_lu_dev);
5367 struct getinfo_fid2path *fpout, *fpin;
5370 fpin = key + cfs_size_round(sizeof(KEY_FID2PATH));
5373 if (ptlrpc_req_need_swab(info->mti_pill->rc_req))
5374 lustre_swab_fid2path(fpin);
5376 memcpy(fpout, fpin, sizeof(*fpin));
5377 if (fpout->gf_pathlen != vallen - sizeof(*fpin))
5380 rc = mdt_fid2path(info->mti_env, mdt, fpout);
5384 static int mdt_fid2path(const struct lu_env *env, struct mdt_device *mdt,
5385 struct getinfo_fid2path *fp)
5387 struct mdt_object *obj;
5391 CDEBUG(D_IOCTL, "path get "DFID" from "LPU64" #%d\n",
5392 PFID(&fp->gf_fid), fp->gf_recno, fp->gf_linkno);
5394 if (!fid_is_sane(&fp->gf_fid))
5397 obj = mdt_object_find(env, mdt, &fp->gf_fid);
5398 if (obj == NULL || IS_ERR(obj)) {
5399 CDEBUG(D_IOCTL, "no object "DFID": %ld\n", PFID(&fp->gf_fid),
5404 rc = lu_object_exists(&obj->mot_obj.mo_lu);
5410 mdt_object_put(env, obj);
5411 CDEBUG(D_IOCTL, "nonlocal object "DFID": %d\n",
5412 PFID(&fp->gf_fid), rc);
5416 rc = mo_path(env, md_object_next(&obj->mot_obj), fp->gf_path,
5417 fp->gf_pathlen, &fp->gf_recno, &fp->gf_linkno);
5418 mdt_object_put(env, obj);
5423 static int mdt_get_info(struct mdt_thread_info *info)
5425 struct ptlrpc_request *req = mdt_info_req(info);
5433 key = req_capsule_client_get(info->mti_pill, &RMF_GETINFO_KEY);
5435 CDEBUG(D_IOCTL, "No GETINFO key");
5438 keylen = req_capsule_get_size(info->mti_pill, &RMF_GETINFO_KEY,
5441 vallen = req_capsule_client_get(info->mti_pill, &RMF_GETINFO_VALLEN);
5442 if (vallen == NULL) {
5443 CDEBUG(D_IOCTL, "Unable to get RMF_GETINFO_VALLEN buffer");
5447 req_capsule_set_size(info->mti_pill, &RMF_GETINFO_VAL, RCL_SERVER,
5449 rc = req_capsule_server_pack(info->mti_pill);
5450 valout = req_capsule_server_get(info->mti_pill, &RMF_GETINFO_VAL);
5451 if (valout == NULL) {
5452 CDEBUG(D_IOCTL, "Unable to get get-info RPC out buffer");
5456 if (KEY_IS(KEY_FID2PATH))
5457 rc = mdt_rpc_fid2path(info, key, valout, *vallen);
5461 lustre_msg_set_status(req->rq_repmsg, rc);
5466 /* Pass the ioc down */
5467 static int mdt_ioc_child(struct lu_env *env, struct mdt_device *mdt,
5468 unsigned int cmd, int len, void *data)
5470 struct lu_context ioctl_session;
5471 struct md_device *next = mdt->mdt_child;
5475 rc = lu_context_init(&ioctl_session, LCT_SESSION);
5478 ioctl_session.lc_thread = (struct ptlrpc_thread *)cfs_current();
5479 lu_context_enter(&ioctl_session);
5480 env->le_ses = &ioctl_session;
5482 LASSERT(next->md_ops->mdo_iocontrol);
5483 rc = next->md_ops->mdo_iocontrol(env, next, cmd, len, data);
5485 lu_context_exit(&ioctl_session);
5486 lu_context_fini(&ioctl_session);
5490 static int mdt_ioc_version_get(struct mdt_thread_info *mti, void *karg)
5492 struct obd_ioctl_data *data = karg;
5493 struct lu_fid *fid = (struct lu_fid *)data->ioc_inlbuf1;
5495 struct mdt_object *obj;
5496 struct mdt_lock_handle *lh;
5500 CDEBUG(D_IOCTL, "getting version for "DFID"\n", PFID(fid));
5501 if (!fid_is_sane(fid))
5504 lh = &mti->mti_lh[MDT_LH_PARENT];
5505 mdt_lock_reg_init(lh, LCK_CR);
5507 obj = mdt_object_find_lock(mti, fid, lh, MDS_INODELOCK_UPDATE);
5509 RETURN(PTR_ERR(obj));
5511 rc = mdt_object_exists(obj);
5515 * before calling version get the correct MDS should be
5516 * fid, this is error to find remote object here
5518 CERROR("nonlocal object "DFID"\n", PFID(fid));
5519 } else if (rc == 0) {
5520 *(__u64 *)data->ioc_inlbuf2 = ENOENT_VERSION;
5523 version = dt_version_get(mti->mti_env, mdt_obj2dt(obj));
5524 *(__u64 *)data->ioc_inlbuf2 = version;
5527 mdt_object_unlock_put(mti, obj, lh, 1);
5531 /* ioctls on obd dev */
5532 static int mdt_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
5533 void *karg, void *uarg)
5536 struct obd_device *obd = exp->exp_obd;
5537 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
5538 struct dt_device *dt = mdt->mdt_bottom;
5542 CDEBUG(D_IOCTL, "handling ioctl cmd %#x\n", cmd);
5543 rc = lu_env_init(&env, LCT_MD_THREAD);
5549 rc = mdt_device_sync(&env, mdt);
5551 case OBD_IOC_SET_READONLY:
5552 rc = dt->dd_ops->dt_ro(&env, dt);
5554 case OBD_IOC_ABORT_RECOVERY:
5555 CERROR("Aborting recovery for device %s\n", obd->obd_name);
5556 target_stop_recovery_thread(obd);
5559 case OBD_IOC_CHANGELOG_REG:
5560 case OBD_IOC_CHANGELOG_DEREG:
5561 case OBD_IOC_CHANGELOG_CLEAR:
5562 rc = mdt_ioc_child(&env, mdt, cmd, len, karg);
5564 case OBD_IOC_GET_OBJ_VERSION: {
5565 struct mdt_thread_info *mti;
5566 mti = lu_context_key_get(&env.le_ctx, &mdt_thread_key);
5567 memset(mti, 0, sizeof *mti);
5568 mti->mti_env = &env;
5572 rc = mdt_ioc_version_get(mti, karg);
5576 CERROR("Not supported cmd = %d for device %s\n",
5577 cmd, obd->obd_name);
5585 int mdt_postrecov(const struct lu_env *env, struct mdt_device *mdt)
5587 struct lu_device *ld = md2lu_dev(mdt->mdt_child);
5588 #ifdef HAVE_QUOTA_SUPPORT
5589 struct obd_device *obd = mdt2obd_dev(mdt);
5590 struct md_device *next = mdt->mdt_child;
5595 rc = ld->ld_ops->ldo_recovery_complete(env, ld);
5596 #ifdef HAVE_QUOTA_SUPPORT
5597 if (likely(obd->obd_stopping == 0))
5598 next->md_ops->mdo_quota.mqo_recovery(env, next);
5603 int mdt_obd_postrecov(struct obd_device *obd)
5608 rc = lu_env_init(&env, LCT_MD_THREAD);
5611 rc = mdt_postrecov(&env, mdt_dev(obd->obd_lu_dev));
5617 * Send a copytool req to a client
5618 * Note this sends a request RPC from a server (MDT) to a client (MDC),
5619 * backwards of normal comms.
5621 int mdt_hsm_copytool_send(struct obd_export *exp)
5624 struct hsm_action_list *hal;
5625 struct hsm_action_item *hai;
5629 CWARN("%s: writing to mdc at %s\n", exp->exp_obd->obd_name,
5630 libcfs_nid2str(exp->exp_connection->c_peer.nid));
5632 len = sizeof(*lh) + sizeof(*hal) + MTI_NAME_MAXLEN +
5633 /* for mockup below */ 2 * cfs_size_round(sizeof(*hai));
5638 lh->kuc_magic = KUC_MAGIC;
5639 lh->kuc_transport = KUC_TRANSPORT_HSM;
5640 lh->kuc_msgtype = HMT_ACTION_LIST;
5641 lh->kuc_msglen = len;
5643 hal = (struct hsm_action_list *)(lh + 1);
5644 hal->hal_version = HAL_VERSION;
5645 hal->hal_archive_num = 1;
5646 obd_uuid2fsname(hal->hal_fsname, exp->exp_obd->obd_name,
5649 /* mock up an action list */
5651 hai = hai_zero(hal);
5652 hai->hai_action = HSMA_ARCHIVE;
5653 hai->hai_fid.f_oid = 0xA00A;
5654 hai->hai_len = sizeof(*hai);
5655 hai = hai_next(hai);
5656 hai->hai_action = HSMA_RESTORE;
5657 hai->hai_fid.f_oid = 0xB00B;
5658 hai->hai_len = sizeof(*hai);
5660 /* Uses the ldlm reverse import; this rpc will be seen by
5661 the ldlm_callback_handler */
5662 rc = do_set_info_async(exp->exp_imp_reverse,
5663 LDLM_SET_INFO, LUSTRE_OBD_VERSION,
5664 sizeof(KEY_HSM_COPYTOOL_SEND),
5665 KEY_HSM_COPYTOOL_SEND,
5673 static struct obd_ops mdt_obd_device_ops = {
5674 .o_owner = THIS_MODULE,
5675 .o_set_info_async = mdt_obd_set_info_async,
5676 .o_connect = mdt_obd_connect,
5677 .o_reconnect = mdt_obd_reconnect,
5678 .o_disconnect = mdt_obd_disconnect,
5679 .o_init_export = mdt_init_export,
5680 .o_destroy_export = mdt_destroy_export,
5681 .o_iocontrol = mdt_iocontrol,
5682 .o_postrecov = mdt_obd_postrecov,
5683 .o_notify = mdt_obd_notify
5686 static struct lu_device* mdt_device_fini(const struct lu_env *env,
5687 struct lu_device *d)
5689 struct mdt_device *m = mdt_dev(d);
5696 static struct lu_device *mdt_device_free(const struct lu_env *env,
5697 struct lu_device *d)
5699 struct mdt_device *m = mdt_dev(d);
5702 md_device_fini(&m->mdt_md_dev);
5707 static struct lu_device *mdt_device_alloc(const struct lu_env *env,
5708 struct lu_device_type *t,
5709 struct lustre_cfg *cfg)
5711 struct lu_device *l;
5712 struct mdt_device *m;
5718 l = &m->mdt_md_dev.md_lu_dev;
5719 rc = mdt_init0(env, m, t, cfg);
5721 mdt_device_free(env, l);
5725 md_upcall_init(&m->mdt_md_dev, mdt_upcall);
5727 l = ERR_PTR(-ENOMEM);
5731 /* context key constructor/destructor: mdt_key_init, mdt_key_fini */
5732 LU_KEY_INIT_FINI(mdt, struct mdt_thread_info);
5734 /* context key: mdt_thread_key */
5735 LU_CONTEXT_KEY_DEFINE(mdt, LCT_MD_THREAD);
5737 struct md_ucred *mdt_ucred(const struct mdt_thread_info *info)
5739 return md_ucred(info->mti_env);
5743 * Enable/disable COS (Commit On Sharing).
5745 * Set/Clear the COS flag in mdt options.
5747 * \param mdt mdt device
5748 * \param val 0 disables COS, other values enable COS
5750 void mdt_enable_cos(struct mdt_device *mdt, int val)
5755 mdt->mdt_opts.mo_cos = !!val;
5756 rc = lu_env_init(&env, LCT_MD_THREAD);
5757 if (unlikely(rc != 0)) {
5758 CWARN("lu_env initialization failed with rc = %d,"
5759 "cannot sync\n", rc);
5762 mdt_device_sync(&env, mdt);
5767 * Check COS (Commit On Sharing) status.
5769 * Return COS flag status.
5771 * \param mdt mdt device
5773 int mdt_cos_is_enabled(struct mdt_device *mdt)
5775 return mdt->mdt_opts.mo_cos != 0;
5778 /* type constructor/destructor: mdt_type_init, mdt_type_fini */
5779 LU_TYPE_INIT_FINI(mdt, &mdt_thread_key);
5781 static struct lu_device_type_operations mdt_device_type_ops = {
5782 .ldto_init = mdt_type_init,
5783 .ldto_fini = mdt_type_fini,
5785 .ldto_start = mdt_type_start,
5786 .ldto_stop = mdt_type_stop,
5788 .ldto_device_alloc = mdt_device_alloc,
5789 .ldto_device_free = mdt_device_free,
5790 .ldto_device_fini = mdt_device_fini
5793 static struct lu_device_type mdt_device_type = {
5794 .ldt_tags = LU_DEVICE_MD,
5795 .ldt_name = LUSTRE_MDT_NAME,
5796 .ldt_ops = &mdt_device_type_ops,
5797 .ldt_ctx_tags = LCT_MD_THREAD
5800 static struct lu_local_obj_desc mdt_last_recv = {
5801 .llod_name = LAST_RCVD,
5802 .llod_oid = MDT_LAST_RECV_OID,
5806 static int __init mdt_mod_init(void)
5808 struct lprocfs_static_vars lvars;
5811 llo_local_obj_register(&mdt_last_recv);
5813 if (mdt_num_threads > 0) {
5814 if (mdt_num_threads > MDT_MAX_THREADS)
5815 mdt_num_threads = MDT_MAX_THREADS;
5816 if (mdt_num_threads < MDT_MIN_THREADS)
5817 mdt_num_threads = MDT_MIN_THREADS;
5818 mdt_max_threads = mdt_min_threads = mdt_num_threads;
5820 mdt_max_threads = MDT_MAX_THREADS;
5821 mdt_min_threads = MDT_MIN_THREADS;
5824 lprocfs_mdt_init_vars(&lvars);
5825 rc = class_register_type(&mdt_obd_device_ops, NULL,
5826 lvars.module_vars, LUSTRE_MDT_NAME,
5832 static void __exit mdt_mod_exit(void)
5834 llo_local_obj_unregister(&mdt_last_recv);
5835 class_unregister_type(LUSTRE_MDT_NAME);
5839 #define DEF_HNDL(prefix, base, suffix, flags, opc, fn, fmt) \
5840 [prefix ## _ ## opc - prefix ## _ ## base] = { \
5842 .mh_fail_id = OBD_FAIL_ ## prefix ## _ ## opc ## suffix, \
5843 .mh_opc = prefix ## _ ## opc, \
5844 .mh_flags = flags, \
5849 #define DEF_MDT_HNDL(flags, name, fn, fmt) \
5850 DEF_HNDL(MDS, GETATTR, _NET, flags, name, fn, fmt)
5852 #define DEF_SEQ_HNDL(flags, name, fn, fmt) \
5853 DEF_HNDL(SEQ, QUERY, _NET, flags, name, fn, fmt)
5855 #define DEF_FLD_HNDL(flags, name, fn, fmt) \
5856 DEF_HNDL(FLD, QUERY, _NET, flags, name, fn, fmt)
5858 * Request with a format known in advance
5860 #define DEF_MDT_HNDL_F(flags, name, fn) \
5861 DEF_HNDL(MDS, GETATTR, _NET, flags, name, fn, &RQF_MDS_ ## name)
5863 #define DEF_SEQ_HNDL_F(flags, name, fn) \
5864 DEF_HNDL(SEQ, QUERY, _NET, flags, name, fn, &RQF_SEQ_ ## name)
5866 #define DEF_FLD_HNDL_F(flags, name, fn) \
5867 DEF_HNDL(FLD, QUERY, _NET, flags, name, fn, &RQF_FLD_ ## name)
5869 * Request with a format we do not yet know
5871 #define DEF_MDT_HNDL_0(flags, name, fn) \
5872 DEF_HNDL(MDS, GETATTR, _NET, flags, name, fn, NULL)
5874 static struct mdt_handler mdt_mds_ops[] = {
5875 DEF_MDT_HNDL_F(0, CONNECT, mdt_connect),
5876 DEF_MDT_HNDL_F(0, DISCONNECT, mdt_disconnect),
5877 DEF_MDT_HNDL (0, SET_INFO, mdt_set_info,
5879 DEF_MDT_HNDL_F(0, GET_INFO, mdt_get_info),
5880 DEF_MDT_HNDL_F(0 |HABEO_REFERO, GETSTATUS, mdt_getstatus),
5881 DEF_MDT_HNDL_F(HABEO_CORPUS, GETATTR, mdt_getattr),
5882 DEF_MDT_HNDL_F(HABEO_CORPUS|HABEO_REFERO, GETATTR_NAME, mdt_getattr_name),
5883 DEF_MDT_HNDL_F(HABEO_CORPUS, GETXATTR, mdt_getxattr),
5884 DEF_MDT_HNDL_F(0 |HABEO_REFERO, STATFS, mdt_statfs),
5885 DEF_MDT_HNDL_F(0 |MUTABOR, REINT, mdt_reint),
5886 DEF_MDT_HNDL_F(HABEO_CORPUS, CLOSE, mdt_close),
5887 DEF_MDT_HNDL_F(HABEO_CORPUS, DONE_WRITING, mdt_done_writing),
5888 DEF_MDT_HNDL_F(0 |HABEO_REFERO, PIN, mdt_pin),
5889 DEF_MDT_HNDL_0(0, SYNC, mdt_sync),
5890 DEF_MDT_HNDL_F(HABEO_CORPUS|HABEO_REFERO, IS_SUBDIR, mdt_is_subdir),
5891 #ifdef HAVE_QUOTA_SUPPORT
5892 DEF_MDT_HNDL_F(0, QUOTACHECK, mdt_quotacheck_handle),
5893 DEF_MDT_HNDL_F(0, QUOTACTL, mdt_quotactl_handle)
5897 #define DEF_OBD_HNDL(flags, name, fn) \
5898 DEF_HNDL(OBD, PING, _NET, flags, name, fn, NULL)
5901 static struct mdt_handler mdt_obd_ops[] = {
5902 DEF_OBD_HNDL(0, PING, mdt_obd_ping),
5903 DEF_OBD_HNDL(0, LOG_CANCEL, mdt_obd_log_cancel),
5904 DEF_OBD_HNDL(0, QC_CALLBACK, mdt_obd_qc_callback)
5907 #define DEF_DLM_HNDL_0(flags, name, fn) \
5908 DEF_HNDL(LDLM, ENQUEUE, , flags, name, fn, NULL)
5909 #define DEF_DLM_HNDL_F(flags, name, fn) \
5910 DEF_HNDL(LDLM, ENQUEUE, , flags, name, fn, &RQF_LDLM_ ## name)
5912 static struct mdt_handler mdt_dlm_ops[] = {
5913 DEF_DLM_HNDL_F(HABEO_CLAVIS, ENQUEUE, mdt_enqueue),
5914 DEF_DLM_HNDL_0(HABEO_CLAVIS, CONVERT, mdt_convert),
5915 DEF_DLM_HNDL_0(0, BL_CALLBACK, mdt_bl_callback),
5916 DEF_DLM_HNDL_0(0, CP_CALLBACK, mdt_cp_callback)
5919 #define DEF_LLOG_HNDL(flags, name, fn) \
5920 DEF_HNDL(LLOG, ORIGIN_HANDLE_CREATE, _NET, flags, name, fn, NULL)
5922 static struct mdt_handler mdt_llog_ops[] = {
5923 DEF_LLOG_HNDL(0, ORIGIN_HANDLE_CREATE, mdt_llog_create),
5924 DEF_LLOG_HNDL(0, ORIGIN_HANDLE_NEXT_BLOCK, mdt_llog_next_block),
5925 DEF_LLOG_HNDL(0, ORIGIN_HANDLE_READ_HEADER, mdt_llog_read_header),
5926 DEF_LLOG_HNDL(0, ORIGIN_HANDLE_WRITE_REC, NULL),
5927 DEF_LLOG_HNDL(0, ORIGIN_HANDLE_CLOSE, NULL),
5928 DEF_LLOG_HNDL(0, ORIGIN_CONNECT, NULL),
5929 DEF_LLOG_HNDL(0, CATINFO, NULL),
5930 DEF_LLOG_HNDL(0, ORIGIN_HANDLE_PREV_BLOCK, mdt_llog_prev_block),
5931 DEF_LLOG_HNDL(0, ORIGIN_HANDLE_DESTROY, mdt_llog_destroy),
5934 #define DEF_SEC_CTX_HNDL(name, fn) \
5935 DEF_HNDL(SEC_CTX, INIT, _NET, 0, name, fn, NULL)
5937 static struct mdt_handler mdt_sec_ctx_ops[] = {
5938 DEF_SEC_CTX_HNDL(INIT, mdt_sec_ctx_handle),
5939 DEF_SEC_CTX_HNDL(INIT_CONT, mdt_sec_ctx_handle),
5940 DEF_SEC_CTX_HNDL(FINI, mdt_sec_ctx_handle)
5943 static struct mdt_opc_slice mdt_regular_handlers[] = {
5945 .mos_opc_start = MDS_GETATTR,
5946 .mos_opc_end = MDS_LAST_OPC,
5947 .mos_hs = mdt_mds_ops
5950 .mos_opc_start = OBD_PING,
5951 .mos_opc_end = OBD_LAST_OPC,
5952 .mos_hs = mdt_obd_ops
5955 .mos_opc_start = LDLM_ENQUEUE,
5956 .mos_opc_end = LDLM_LAST_OPC,
5957 .mos_hs = mdt_dlm_ops
5960 .mos_opc_start = LLOG_ORIGIN_HANDLE_CREATE,
5961 .mos_opc_end = LLOG_LAST_OPC,
5962 .mos_hs = mdt_llog_ops
5965 .mos_opc_start = SEC_CTX_INIT,
5966 .mos_opc_end = SEC_LAST_OPC,
5967 .mos_hs = mdt_sec_ctx_ops
5974 static struct mdt_handler mdt_readpage_ops[] = {
5975 DEF_MDT_HNDL_F(0, CONNECT, mdt_connect),
5976 DEF_MDT_HNDL_F(HABEO_CORPUS|HABEO_REFERO, READPAGE, mdt_readpage),
5977 #ifdef HAVE_SPLIT_SUPPORT
5978 DEF_MDT_HNDL_F(HABEO_CORPUS|HABEO_REFERO, WRITEPAGE, mdt_writepage),
5982 * XXX: this is ugly and should be fixed one day, see mdc_close() for
5983 * detailed comments. --umka
5985 DEF_MDT_HNDL_F(HABEO_CORPUS, CLOSE, mdt_close),
5986 DEF_MDT_HNDL_F(HABEO_CORPUS, DONE_WRITING, mdt_done_writing),
5989 static struct mdt_opc_slice mdt_readpage_handlers[] = {
5991 .mos_opc_start = MDS_GETATTR,
5992 .mos_opc_end = MDS_LAST_OPC,
5993 .mos_hs = mdt_readpage_ops
6000 static struct mdt_handler mdt_xmds_ops[] = {
6001 DEF_MDT_HNDL_F(0, CONNECT, mdt_connect),
6002 DEF_MDT_HNDL_F(HABEO_CORPUS , GETATTR, mdt_getattr),
6003 DEF_MDT_HNDL_F(0 | MUTABOR , REINT, mdt_reint),
6004 DEF_MDT_HNDL_F(HABEO_CORPUS|HABEO_REFERO, IS_SUBDIR, mdt_is_subdir),
6007 static struct mdt_opc_slice mdt_xmds_handlers[] = {
6009 .mos_opc_start = MDS_GETATTR,
6010 .mos_opc_end = MDS_LAST_OPC,
6011 .mos_hs = mdt_xmds_ops
6014 .mos_opc_start = OBD_PING,
6015 .mos_opc_end = OBD_LAST_OPC,
6016 .mos_hs = mdt_obd_ops
6019 .mos_opc_start = SEC_CTX_INIT,
6020 .mos_opc_end = SEC_LAST_OPC,
6021 .mos_hs = mdt_sec_ctx_ops
6028 static struct mdt_handler mdt_seq_ops[] = {
6029 DEF_SEQ_HNDL_F(0, QUERY, (int (*)(struct mdt_thread_info *))seq_query)
6032 static struct mdt_opc_slice mdt_seq_handlers[] = {
6034 .mos_opc_start = SEQ_QUERY,
6035 .mos_opc_end = SEQ_LAST_OPC,
6036 .mos_hs = mdt_seq_ops
6043 static struct mdt_handler mdt_fld_ops[] = {
6044 DEF_FLD_HNDL_F(0, QUERY, (int (*)(struct mdt_thread_info *))fld_query)
6047 static struct mdt_opc_slice mdt_fld_handlers[] = {
6049 .mos_opc_start = FLD_QUERY,
6050 .mos_opc_end = FLD_LAST_OPC,
6051 .mos_hs = mdt_fld_ops
6058 MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");
6059 MODULE_DESCRIPTION("Lustre Meta-data Target ("LUSTRE_MDT_NAME")");
6060 MODULE_LICENSE("GPL");
6062 CFS_MODULE_PARM(mdt_num_threads, "ul", ulong, 0444,
6063 "number of mdt service threads to start");
6065 cfs_module(mdt, "0.2.0", mdt_mod_init, mdt_mod_exit);