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,
371 statfs_pack(osfs, &info->mti_u.ksfs);
375 mdt_counter_incr(req->rq_export, LPROC_MDT_STATFS);
381 * Pack SOM attributes into the reply.
382 * Call under a DLM UPDATE lock.
384 static void mdt_pack_size2body(struct mdt_thread_info *info,
385 struct mdt_object *mo)
388 struct md_attr *ma = &info->mti_attr;
390 LASSERT(ma->ma_attr.la_valid & LA_MODE);
391 b = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
393 /* Check if Size-on-MDS is supported, if this is a regular file,
394 * if SOM is enabled on the object and if SOM cache exists and valid.
395 * Otherwise do not pack Size-on-MDS attributes to the reply. */
396 if (!(mdt_conn_flags(info) & OBD_CONNECT_SOM) ||
397 !S_ISREG(ma->ma_attr.la_mode) ||
398 !mdt_object_is_som_enabled(mo) ||
399 !(ma->ma_valid & MA_SOM))
402 b->valid |= OBD_MD_FLSIZE | OBD_MD_FLBLOCKS;
403 b->size = ma->ma_som->msd_size;
404 b->blocks = ma->ma_som->msd_blocks;
407 void mdt_pack_attr2body(struct mdt_thread_info *info, struct mdt_body *b,
408 const struct lu_attr *attr, const struct lu_fid *fid)
410 struct md_attr *ma = &info->mti_attr;
412 LASSERT(ma->ma_valid & MA_INODE);
414 b->atime = attr->la_atime;
415 b->mtime = attr->la_mtime;
416 b->ctime = attr->la_ctime;
417 b->mode = attr->la_mode;
418 b->size = attr->la_size;
419 b->blocks = attr->la_blocks;
420 b->uid = attr->la_uid;
421 b->gid = attr->la_gid;
422 b->flags = attr->la_flags;
423 b->nlink = attr->la_nlink;
424 b->rdev = attr->la_rdev;
426 /*XXX should pack the reply body according to lu_valid*/
427 b->valid |= OBD_MD_FLCTIME | OBD_MD_FLUID |
428 OBD_MD_FLGID | OBD_MD_FLTYPE |
429 OBD_MD_FLMODE | OBD_MD_FLNLINK | OBD_MD_FLFLAGS |
430 OBD_MD_FLATIME | OBD_MD_FLMTIME ;
432 if (!S_ISREG(attr->la_mode)) {
433 b->valid |= OBD_MD_FLSIZE | OBD_MD_FLBLOCKS | OBD_MD_FLRDEV;
434 } else if (ma->ma_need & MA_LOV && ma->ma_lmm_size == 0) {
435 /* means no objects are allocated on osts. */
436 LASSERT(!(ma->ma_valid & MA_LOV));
437 /* just ignore blocks occupied by extend attributes on MDS */
439 /* if no object is allocated on osts, the size on mds is valid. b=22272 */
440 b->valid |= OBD_MD_FLSIZE | OBD_MD_FLBLOCKS;
445 b->valid |= OBD_MD_FLID;
447 /* FIXME: these should be fixed when new igif ready.*/
448 b->ino = fid_oid(fid); /* 1.6 compatibility */
449 b->generation = fid_ver(fid); /* 1.6 compatibility */
450 b->valid |= OBD_MD_FLGENER; /* 1.6 compatibility */
452 CDEBUG(D_INODE, DFID": nlink=%d, mode=%o, size="LPU64"\n",
453 PFID(fid), b->nlink, b->mode, b->size);
457 mdt_body_reverse_idmap(info, b);
459 if (b->valid & OBD_MD_FLSIZE)
460 CDEBUG(D_VFSTRACE, DFID": returning size %llu\n",
461 PFID(fid), (unsigned long long)b->size);
464 static inline int mdt_body_has_lov(const struct lu_attr *la,
465 const struct mdt_body *body)
467 return ((S_ISREG(la->la_mode) && (body->valid & OBD_MD_FLEASIZE)) ||
468 (S_ISDIR(la->la_mode) && (body->valid & OBD_MD_FLDIREA )) );
471 void mdt_client_compatibility(struct mdt_thread_info *info)
473 struct mdt_body *body;
474 struct ptlrpc_request *req = mdt_info_req(info);
475 struct obd_export *exp = req->rq_export;
476 struct md_attr *ma = &info->mti_attr;
477 struct lu_attr *la = &ma->ma_attr;
480 if (exp->exp_connect_flags & OBD_CONNECT_LAYOUTLOCK)
481 /* the client can deal with 16-bit lmm_stripe_count */
484 body = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
486 if (!mdt_body_has_lov(la, body))
489 /* now we have a reply with a lov for a client not compatible with the
490 * layout lock so we have to clean the layout generation number */
491 if (S_ISREG(la->la_mode))
492 ma->ma_lmm->lmm_layout_gen = 0;
497 static int mdt_getattr_internal(struct mdt_thread_info *info,
498 struct mdt_object *o, int ma_need)
500 struct md_object *next = mdt_object_child(o);
501 const struct mdt_body *reqbody = info->mti_body;
502 struct ptlrpc_request *req = mdt_info_req(info);
503 struct md_attr *ma = &info->mti_attr;
504 struct lu_attr *la = &ma->ma_attr;
505 struct req_capsule *pill = info->mti_pill;
506 const struct lu_env *env = info->mti_env;
507 struct mdt_body *repbody;
508 struct lu_buf *buffer = &info->mti_buf;
512 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_GETATTR_PACK))
513 RETURN(err_serious(-ENOMEM));
515 repbody = req_capsule_server_get(pill, &RMF_MDT_BODY);
519 rc = mdt_object_exists(o);
521 /* This object is located on remote node.*/
522 repbody->fid1 = *mdt_object_fid(o);
523 repbody->valid = OBD_MD_FLID | OBD_MD_MDS;
527 buffer->lb_buf = req_capsule_server_get(pill, &RMF_MDT_MD);
528 buffer->lb_len = req_capsule_get_size(pill, &RMF_MDT_MD, RCL_SERVER);
530 /* If it is dir object and client require MEA, then we got MEA */
531 if (S_ISDIR(lu_object_attr(&next->mo_lu)) &&
532 reqbody->valid & OBD_MD_MEA) {
533 /* Assumption: MDT_MD size is enough for lmv size. */
534 ma->ma_lmv = buffer->lb_buf;
535 ma->ma_lmv_size = buffer->lb_len;
536 ma->ma_need = MA_LMV | MA_INODE;
538 ma->ma_lmm = buffer->lb_buf;
539 ma->ma_lmm_size = buffer->lb_len;
540 ma->ma_need = MA_LOV | MA_INODE;
543 if (S_ISDIR(lu_object_attr(&next->mo_lu)) &&
544 reqbody->valid & OBD_MD_FLDIREA &&
545 lustre_msg_get_opc(req->rq_reqmsg) == MDS_GETATTR) {
546 /* get default stripe info for this dir. */
547 ma->ma_need |= MA_LOV_DEF;
549 ma->ma_need |= ma_need;
550 if (ma->ma_need & MA_SOM)
551 ma->ma_som = &info->mti_u.som.data;
553 rc = mo_attr_get(env, next, ma);
555 CERROR("getattr error for "DFID": %d\n",
556 PFID(mdt_object_fid(o)), rc);
560 if (likely(ma->ma_valid & MA_INODE))
561 mdt_pack_attr2body(info, repbody, la, mdt_object_fid(o));
565 if (mdt_body_has_lov(la, reqbody)) {
566 if (ma->ma_valid & MA_LOV) {
567 LASSERT(ma->ma_lmm_size);
568 mdt_dump_lmm(D_INFO, ma->ma_lmm);
569 repbody->eadatasize = ma->ma_lmm_size;
570 if (S_ISDIR(la->la_mode))
571 repbody->valid |= OBD_MD_FLDIREA;
573 repbody->valid |= OBD_MD_FLEASIZE;
575 if (ma->ma_valid & MA_LMV) {
576 LASSERT(S_ISDIR(la->la_mode));
577 repbody->eadatasize = ma->ma_lmv_size;
578 repbody->valid |= (OBD_MD_FLDIREA|OBD_MD_MEA);
580 } else if (S_ISLNK(la->la_mode) &&
581 reqbody->valid & OBD_MD_LINKNAME) {
582 buffer->lb_buf = ma->ma_lmm;
583 buffer->lb_len = reqbody->eadatasize;
584 rc = mo_readlink(env, next, buffer);
585 if (unlikely(rc <= 0)) {
586 CERROR("readlink failed: %d\n", rc);
589 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_READLINK_EPROTO))
591 repbody->valid |= OBD_MD_LINKNAME;
592 repbody->eadatasize = rc;
594 ((char*)ma->ma_lmm)[rc - 1] = 0;
595 CDEBUG(D_INODE, "symlink dest %s, len = %d\n",
596 (char*)ma->ma_lmm, rc);
601 if (reqbody->valid & OBD_MD_FLMODEASIZE) {
602 repbody->max_cookiesize = info->mti_mdt->mdt_max_cookiesize;
603 repbody->max_mdsize = info->mti_mdt->mdt_max_mdsize;
604 repbody->valid |= OBD_MD_FLMODEASIZE;
605 CDEBUG(D_INODE, "I am going to change the MAX_MD_SIZE & "
606 "MAX_COOKIE to : %d:%d\n", repbody->max_mdsize,
607 repbody->max_cookiesize);
610 if (exp_connect_rmtclient(info->mti_exp) &&
611 reqbody->valid & OBD_MD_FLRMTPERM) {
612 void *buf = req_capsule_server_get(pill, &RMF_ACL);
614 /* mdt_getattr_lock only */
615 rc = mdt_pack_remote_perm(info, o, buf);
617 repbody->valid &= ~OBD_MD_FLRMTPERM;
618 repbody->aclsize = 0;
621 repbody->valid |= OBD_MD_FLRMTPERM;
622 repbody->aclsize = sizeof(struct mdt_remote_perm);
625 #ifdef CONFIG_FS_POSIX_ACL
626 else if ((req->rq_export->exp_connect_flags & OBD_CONNECT_ACL) &&
627 (reqbody->valid & OBD_MD_FLACL)) {
628 buffer->lb_buf = req_capsule_server_get(pill, &RMF_ACL);
629 buffer->lb_len = req_capsule_get_size(pill,
630 &RMF_ACL, RCL_SERVER);
631 if (buffer->lb_len > 0) {
632 rc = mo_xattr_get(env, next, buffer,
633 XATTR_NAME_ACL_ACCESS);
635 if (rc == -ENODATA) {
636 repbody->aclsize = 0;
637 repbody->valid |= OBD_MD_FLACL;
639 } else if (rc == -EOPNOTSUPP) {
642 CERROR("got acl size: %d\n", rc);
645 repbody->aclsize = rc;
646 repbody->valid |= OBD_MD_FLACL;
653 if (reqbody->valid & OBD_MD_FLMDSCAPA &&
654 info->mti_mdt->mdt_opts.mo_mds_capa &&
655 info->mti_exp->exp_connect_flags & OBD_CONNECT_MDS_CAPA) {
656 struct lustre_capa *capa;
658 capa = req_capsule_server_get(pill, &RMF_CAPA1);
660 capa->lc_opc = CAPA_OPC_MDS_DEFAULT;
661 rc = mo_capa_get(env, next, capa, 0);
664 repbody->valid |= OBD_MD_FLMDSCAPA;
669 static int mdt_renew_capa(struct mdt_thread_info *info)
671 struct mdt_object *obj = info->mti_object;
672 struct mdt_body *body;
673 struct lustre_capa *capa, *c;
677 /* if object doesn't exist, or server has disabled capability,
678 * return directly, client will find body->valid OBD_MD_FLOSSCAPA
681 if (!obj || !info->mti_mdt->mdt_opts.mo_oss_capa ||
682 !(info->mti_exp->exp_connect_flags & OBD_CONNECT_OSS_CAPA))
685 body = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
686 LASSERT(body != NULL);
688 c = req_capsule_client_get(info->mti_pill, &RMF_CAPA1);
691 capa = req_capsule_server_get(info->mti_pill, &RMF_CAPA2);
695 rc = mo_capa_get(info->mti_env, mdt_object_child(obj), capa, 1);
697 body->valid |= OBD_MD_FLOSSCAPA;
701 static int mdt_getattr(struct mdt_thread_info *info)
703 struct ptlrpc_request *req = mdt_info_req(info);
704 struct mdt_object *obj = info->mti_object;
705 struct req_capsule *pill = info->mti_pill;
706 struct mdt_body *reqbody;
707 struct mdt_body *repbody;
713 reqbody = req_capsule_client_get(pill, &RMF_MDT_BODY);
716 if (reqbody->valid & OBD_MD_FLOSSCAPA) {
717 rc = req_capsule_server_pack(pill);
719 RETURN(err_serious(rc));
720 rc = mdt_renew_capa(info);
721 GOTO(out_shrink, rc);
724 LASSERT(obj != NULL);
725 LASSERT(lu_object_assert_exists(&obj->mot_obj.mo_lu));
727 mode = lu_object_attr(&obj->mot_obj.mo_lu);
728 if (S_ISLNK(mode) && (reqbody->valid & OBD_MD_LINKNAME) &&
729 (reqbody->eadatasize > info->mti_mdt->mdt_max_mdsize))
730 md_size = reqbody->eadatasize;
732 md_size = info->mti_mdt->mdt_max_mdsize;
734 req_capsule_set_size(pill, &RMF_MDT_MD, RCL_SERVER, md_size);
736 rc = req_capsule_server_pack(pill);
737 if (unlikely(rc != 0))
738 RETURN(err_serious(rc));
740 repbody = req_capsule_server_get(pill, &RMF_MDT_BODY);
741 LASSERT(repbody != NULL);
742 repbody->eadatasize = 0;
743 repbody->aclsize = 0;
745 if (reqbody->valid & OBD_MD_FLRMTPERM)
746 rc = mdt_init_ucred(info, reqbody);
748 rc = mdt_check_ucred(info);
750 GOTO(out_shrink, rc);
752 info->mti_spec.sp_ck_split = !!(reqbody->valid & OBD_MD_FLCKSPLIT);
753 info->mti_cross_ref = !!(reqbody->valid & OBD_MD_FLCROSSREF);
756 * Don't check capability at all, because rename might getattr for
757 * remote obj, and at that time no capability is available.
759 mdt_set_capainfo(info, 1, &reqbody->fid1, BYPASS_CAPA);
760 rc = mdt_getattr_internal(info, obj, 0);
761 if (reqbody->valid & OBD_MD_FLRMTPERM)
762 mdt_exit_ucred(info);
766 mdt_counter_incr(req->rq_export, LPROC_MDT_GETATTR);
768 mdt_client_compatibility(info);
769 mdt_shrink_reply(info);
773 static int mdt_is_subdir(struct mdt_thread_info *info)
775 struct mdt_object *o = info->mti_object;
776 struct req_capsule *pill = info->mti_pill;
777 const struct mdt_body *body = info->mti_body;
778 struct mdt_body *repbody;
784 repbody = req_capsule_server_get(pill, &RMF_MDT_BODY);
787 * We save last checked parent fid to @repbody->fid1 for remote
790 LASSERT(fid_is_sane(&body->fid2));
791 LASSERT(mdt_object_exists(o) > 0);
792 rc = mdo_is_subdir(info->mti_env, mdt_object_child(o),
793 &body->fid2, &repbody->fid1);
794 if (rc == 0 || rc == -EREMOTE)
795 repbody->valid |= OBD_MD_FLID;
800 static int mdt_raw_lookup(struct mdt_thread_info *info,
801 struct mdt_object *parent,
802 const struct lu_name *lname,
803 struct ldlm_reply *ldlm_rep)
805 struct md_object *next = mdt_object_child(info->mti_object);
806 const struct mdt_body *reqbody = info->mti_body;
807 struct lu_fid *child_fid = &info->mti_tmp_fid1;
808 struct mdt_body *repbody;
812 if (reqbody->valid != OBD_MD_FLID)
815 LASSERT(!info->mti_cross_ref);
817 /* Only got the fid of this obj by name */
818 rc = mdo_lookup(info->mti_env, next, lname, child_fid,
821 /* XXX is raw_lookup possible as intent operation? */
824 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_NEG);
827 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_POS);
829 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
832 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
833 repbody->fid1 = *child_fid;
834 repbody->valid = OBD_MD_FLID;
840 * UPDATE lock should be taken against parent, and be release before exit;
841 * child_bits lock should be taken against child, and be returned back:
842 * (1)normal request should release the child lock;
843 * (2)intent request will grant the lock to client.
845 static int mdt_getattr_name_lock(struct mdt_thread_info *info,
846 struct mdt_lock_handle *lhc,
848 struct ldlm_reply *ldlm_rep)
850 struct ptlrpc_request *req = mdt_info_req(info);
851 struct mdt_body *reqbody = NULL;
852 struct mdt_object *parent = info->mti_object;
853 struct mdt_object *child;
854 struct md_object *next = mdt_object_child(parent);
855 struct lu_fid *child_fid = &info->mti_tmp_fid1;
856 struct lu_name *lname = NULL;
857 const char *name = NULL;
859 struct mdt_lock_handle *lhp = NULL;
860 struct ldlm_lock *lock;
861 struct ldlm_res_id *res_id;
868 is_resent = lustre_handle_is_used(&lhc->mlh_reg_lh);
869 LASSERT(ergo(is_resent,
870 lustre_msg_get_flags(req->rq_reqmsg) & MSG_RESENT));
872 LASSERT(parent != NULL);
873 name = req_capsule_client_get(info->mti_pill, &RMF_NAME);
875 RETURN(err_serious(-EFAULT));
877 namelen = req_capsule_get_size(info->mti_pill, &RMF_NAME,
879 if (!info->mti_cross_ref) {
881 * XXX: Check for "namelen == 0" is for getattr by fid
882 * (OBD_CONNECT_ATTRFID), otherwise do not allow empty name,
883 * that is the name must contain at least one character and
884 * the terminating '\0'
887 reqbody = req_capsule_client_get(info->mti_pill,
889 if (unlikely(reqbody == NULL))
890 RETURN(err_serious(-EFAULT));
892 if (unlikely(!fid_is_sane(&reqbody->fid2)))
893 RETURN(err_serious(-EINVAL));
896 CDEBUG(D_INODE, "getattr with lock for "DFID"/"DFID", "
898 PFID(mdt_object_fid(parent)),
899 PFID(&reqbody->fid2), ldlm_rep);
901 lname = mdt_name(info->mti_env, (char *)name, namelen);
902 CDEBUG(D_INODE, "getattr with lock for "DFID"/%s, "
903 "ldlm_rep = %p\n", PFID(mdt_object_fid(parent)),
907 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_EXECD);
909 rc = mdt_object_exists(parent);
910 if (unlikely(rc == 0)) {
911 LU_OBJECT_DEBUG(D_WARNING, info->mti_env,
912 &parent->mot_obj.mo_lu,
913 "Parent doesn't exist!\n");
915 } else if (!info->mti_cross_ref) {
916 LASSERTF(rc > 0, "Parent "DFID" is on remote server\n",
917 PFID(mdt_object_fid(parent)));
920 rc = mdt_raw_lookup(info, parent, lname, ldlm_rep);
928 if (info->mti_cross_ref) {
929 /* Only getattr on the child. Parent is on another node. */
930 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_POS);
932 CDEBUG(D_INODE, "partial getattr_name child_fid = "DFID", "
933 "ldlm_rep=%p\n", PFID(mdt_object_fid(child)), ldlm_rep);
936 /* Do not take lock for resent case. */
937 lock = ldlm_handle2lock(&lhc->mlh_reg_lh);
938 LASSERTF(lock != NULL, "Invalid lock handle "LPX64"\n",
939 lhc->mlh_reg_lh.cookie);
940 LASSERT(fid_res_name_eq(mdt_object_fid(child),
941 &lock->l_resource->lr_name));
945 mdt_lock_handle_init(lhc);
946 mdt_lock_reg_init(lhc, LCK_PR);
949 * Object's name is on another MDS, no lookup lock is
950 * needed here but update is.
952 child_bits &= ~MDS_INODELOCK_LOOKUP;
953 child_bits |= MDS_INODELOCK_UPDATE;
955 rc = mdt_object_lock(info, child, lhc, child_bits,
959 /* Finally, we can get attr for child. */
960 mdt_set_capainfo(info, 0, mdt_object_fid(child),
962 rc = mdt_getattr_internal(info, child, 0);
963 if (unlikely(rc != 0))
964 mdt_object_unlock(info, child, lhc, 1);
970 /* step 1: lock parent only if parent is a directory */
971 if (S_ISDIR(lu_object_attr(&parent->mot_obj.mo_lu))) {
972 lhp = &info->mti_lh[MDT_LH_PARENT];
973 mdt_lock_pdo_init(lhp, LCK_PR, name, namelen);
974 rc = mdt_object_lock(info, parent, lhp,
975 MDS_INODELOCK_UPDATE,
977 if (unlikely(rc != 0))
981 /* 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 mdt_shrink_reply(info);
1155 static const struct lu_device_operations mdt_lu_ops;
1157 static int lu_device_is_mdt(struct lu_device *d)
1159 return ergo(d != NULL && d->ld_ops != NULL, d->ld_ops == &mdt_lu_ops);
1162 static int mdt_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
1163 void *karg, void *uarg);
1165 static int mdt_set_info(struct mdt_thread_info *info)
1167 struct ptlrpc_request *req = mdt_info_req(info);
1170 int keylen, vallen, rc = 0;
1173 rc = req_capsule_server_pack(info->mti_pill);
1177 key = req_capsule_client_get(info->mti_pill, &RMF_SETINFO_KEY);
1179 DEBUG_REQ(D_HA, req, "no set_info key");
1183 keylen = req_capsule_get_size(info->mti_pill, &RMF_SETINFO_KEY,
1186 val = req_capsule_client_get(info->mti_pill, &RMF_SETINFO_VAL);
1188 DEBUG_REQ(D_HA, req, "no set_info val");
1192 vallen = req_capsule_get_size(info->mti_pill, &RMF_SETINFO_VAL,
1195 /* Swab any part of val you need to here */
1196 if (KEY_IS(KEY_READ_ONLY)) {
1198 lustre_msg_set_status(req->rq_repmsg, 0);
1200 cfs_spin_lock(&req->rq_export->exp_lock);
1202 req->rq_export->exp_connect_flags |= OBD_CONNECT_RDONLY;
1204 req->rq_export->exp_connect_flags &=~OBD_CONNECT_RDONLY;
1205 cfs_spin_unlock(&req->rq_export->exp_lock);
1207 } else if (KEY_IS(KEY_CHANGELOG_CLEAR)) {
1208 struct changelog_setinfo *cs =
1209 (struct changelog_setinfo *)val;
1210 if (vallen != sizeof(*cs)) {
1211 CERROR("Bad changelog_clear setinfo size %d\n", vallen);
1214 if (ptlrpc_req_need_swab(req)) {
1215 __swab64s(&cs->cs_recno);
1216 __swab32s(&cs->cs_id);
1219 rc = mdt_iocontrol(OBD_IOC_CHANGELOG_CLEAR, info->mti_exp,
1221 lustre_msg_set_status(req->rq_repmsg, rc);
1229 static int mdt_connect(struct mdt_thread_info *info)
1232 struct ptlrpc_request *req;
1234 req = mdt_info_req(info);
1235 rc = target_handle_connect(req);
1237 LASSERT(req->rq_export != NULL);
1238 info->mti_mdt = mdt_dev(req->rq_export->exp_obd->obd_lu_dev);
1239 rc = mdt_init_sec_level(info);
1241 rc = mdt_init_idmap(info);
1243 obd_disconnect(class_export_get(req->rq_export));
1245 rc = err_serious(rc);
1250 static int mdt_disconnect(struct mdt_thread_info *info)
1255 rc = target_handle_disconnect(mdt_info_req(info));
1257 rc = err_serious(rc);
1261 static int mdt_sendpage(struct mdt_thread_info *info,
1262 struct lu_rdpg *rdpg, int nob)
1264 struct ptlrpc_request *req = mdt_info_req(info);
1265 struct obd_export *exp = req->rq_export;
1266 struct ptlrpc_bulk_desc *desc;
1267 struct l_wait_info *lwi = &info->mti_u.rdpg.mti_wait_info;
1274 desc = ptlrpc_prep_bulk_exp(req, rdpg->rp_npages, BULK_PUT_SOURCE,
1279 for (i = 0, tmpcount = nob;
1280 i < rdpg->rp_npages && tmpcount > 0; i++, tmpcount -= tmpsize) {
1281 tmpsize = min_t(int, tmpcount, CFS_PAGE_SIZE);
1282 ptlrpc_prep_bulk_page(desc, rdpg->rp_pages[i], 0, tmpsize);
1285 LASSERT(desc->bd_nob == nob);
1286 rc = target_bulk_io(exp, desc, lwi);
1287 ptlrpc_free_bulk(desc);
1291 #ifdef HAVE_SPLIT_SUPPORT
1293 * Retrieve dir entry from the page and insert it to the slave object, actually,
1294 * this should be in osd layer, but since it will not in the final product, so
1295 * just do it here and do not define more moo api anymore for this.
1297 static int mdt_write_dir_page(struct mdt_thread_info *info, struct page *page,
1300 struct mdt_object *object = info->mti_object;
1301 struct lu_fid *lf = &info->mti_tmp_fid2;
1302 struct md_attr *ma = &info->mti_attr;
1303 struct lu_dirpage *dp;
1304 struct lu_dirent *ent;
1305 int rc = 0, offset = 0;
1308 /* Make sure we have at least one entry. */
1313 * Disable trans for this name insert, since it will include many trans
1316 info->mti_no_need_trans = 1;
1318 * When write_dir_page, no need update parent's ctime,
1319 * and no permission check for name_insert.
1321 ma->ma_attr.la_ctime = 0;
1322 ma->ma_attr.la_valid = LA_MODE;
1323 ma->ma_valid = MA_INODE;
1326 dp = page_address(page);
1327 offset = (int)((__u32)lu_dirent_start(dp) - (__u32)dp);
1329 for (ent = lu_dirent_start(dp); ent != NULL;
1330 ent = lu_dirent_next(ent)) {
1331 struct lu_name *lname;
1334 if (le16_to_cpu(ent->lde_namelen) == 0)
1337 fid_le_to_cpu(lf, &ent->lde_fid);
1338 if (le64_to_cpu(ent->lde_hash) & MAX_HASH_HIGHEST_BIT)
1339 ma->ma_attr.la_mode = S_IFDIR;
1341 ma->ma_attr.la_mode = 0;
1342 OBD_ALLOC(name, le16_to_cpu(ent->lde_namelen) + 1);
1344 GOTO(out, rc = -ENOMEM);
1346 memcpy(name, ent->lde_name, le16_to_cpu(ent->lde_namelen));
1347 lname = mdt_name(info->mti_env, name,
1348 le16_to_cpu(ent->lde_namelen));
1349 ma->ma_attr_flags |= (MDS_PERM_BYPASS | MDS_QUOTA_IGNORE);
1350 rc = mdo_name_insert(info->mti_env,
1351 md_object_next(&object->mot_obj),
1353 OBD_FREE(name, le16_to_cpu(ent->lde_namelen) + 1);
1355 CERROR("Can't insert %*.*s, rc %d\n",
1356 le16_to_cpu(ent->lde_namelen),
1357 le16_to_cpu(ent->lde_namelen),
1362 offset += lu_dirent_size(ent);
1372 static int mdt_bulk_timeout(void *data)
1376 CERROR("mdt bulk transfer timeout \n");
1381 static int mdt_writepage(struct mdt_thread_info *info)
1383 struct ptlrpc_request *req = mdt_info_req(info);
1384 struct mdt_body *reqbody;
1385 struct l_wait_info *lwi;
1386 struct ptlrpc_bulk_desc *desc;
1392 reqbody = req_capsule_client_get(info->mti_pill, &RMF_MDT_BODY);
1393 if (reqbody == NULL)
1394 RETURN(err_serious(-EFAULT));
1396 desc = ptlrpc_prep_bulk_exp(req, 1, BULK_GET_SINK, MDS_BULK_PORTAL);
1398 RETURN(err_serious(-ENOMEM));
1400 /* allocate the page for the desc */
1401 page = cfs_alloc_page(CFS_ALLOC_STD);
1403 GOTO(desc_cleanup, rc = -ENOMEM);
1405 CDEBUG(D_INFO, "Received page offset %d size %d \n",
1406 (int)reqbody->size, (int)reqbody->nlink);
1408 ptlrpc_prep_bulk_page(desc, page, (int)reqbody->size,
1409 (int)reqbody->nlink);
1411 rc = sptlrpc_svc_prep_bulk(req, desc);
1413 GOTO(cleanup_page, rc);
1415 * Check if client was evicted while we were doing i/o before touching
1420 GOTO(cleanup_page, rc = -ENOMEM);
1422 if (desc->bd_export->exp_failed)
1425 rc = ptlrpc_start_bulk_transfer (desc);
1427 *lwi = LWI_TIMEOUT_INTERVAL(obd_timeout * CFS_HZ / 4, CFS_HZ,
1428 mdt_bulk_timeout, desc);
1429 rc = l_wait_event(desc->bd_waitq, !ptlrpc_bulk_active(desc) ||
1430 desc->bd_export->exp_failed, lwi);
1431 LASSERT(rc == 0 || rc == -ETIMEDOUT);
1432 if (rc == -ETIMEDOUT) {
1433 DEBUG_REQ(D_ERROR, req, "timeout on bulk GET");
1434 ptlrpc_abort_bulk(desc);
1435 } else if (desc->bd_export->exp_failed) {
1436 DEBUG_REQ(D_ERROR, req, "Eviction on bulk GET");
1438 ptlrpc_abort_bulk(desc);
1439 } else if (!desc->bd_success ||
1440 desc->bd_nob_transferred != desc->bd_nob) {
1441 DEBUG_REQ(D_ERROR, req, "%s bulk GET %d(%d)",
1443 "truncated" : "network error on",
1444 desc->bd_nob_transferred, desc->bd_nob);
1445 /* XXX should this be a different errno? */
1449 DEBUG_REQ(D_ERROR, req, "ptlrpc_bulk_get failed: rc %d", rc);
1452 GOTO(cleanup_lwi, rc);
1453 rc = mdt_write_dir_page(info, page, reqbody->nlink);
1458 cfs_free_page(page);
1460 ptlrpc_free_bulk(desc);
1465 static int mdt_readpage(struct mdt_thread_info *info)
1467 struct mdt_object *object = info->mti_object;
1468 struct lu_rdpg *rdpg = &info->mti_u.rdpg.mti_rdpg;
1469 struct mdt_body *reqbody;
1470 struct mdt_body *repbody;
1475 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_READPAGE_PACK))
1476 RETURN(err_serious(-ENOMEM));
1478 reqbody = req_capsule_client_get(info->mti_pill, &RMF_MDT_BODY);
1479 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
1480 if (reqbody == NULL || repbody == NULL)
1481 RETURN(err_serious(-EFAULT));
1484 * prepare @rdpg before calling lower layers and transfer itself. Here
1485 * reqbody->size contains offset of where to start to read and
1486 * reqbody->nlink contains number bytes to read.
1488 rdpg->rp_hash = reqbody->size;
1489 if (rdpg->rp_hash != reqbody->size) {
1490 CERROR("Invalid hash: "LPX64" != "LPX64"\n",
1491 rdpg->rp_hash, reqbody->size);
1495 rdpg->rp_attrs = reqbody->mode;
1496 if (info->mti_exp->exp_connect_flags & OBD_CONNECT_64BITHASH)
1497 rdpg->rp_attrs |= LUDA_64BITHASH;
1498 rdpg->rp_count = min_t(unsigned int, reqbody->nlink,
1499 PTLRPC_MAX_BRW_SIZE);
1500 rdpg->rp_npages = (rdpg->rp_count + CFS_PAGE_SIZE - 1) >>
1502 OBD_ALLOC(rdpg->rp_pages, rdpg->rp_npages * sizeof rdpg->rp_pages[0]);
1503 if (rdpg->rp_pages == NULL)
1506 for (i = 0; i < rdpg->rp_npages; ++i) {
1507 rdpg->rp_pages[i] = cfs_alloc_page(CFS_ALLOC_STD);
1508 if (rdpg->rp_pages[i] == NULL)
1509 GOTO(free_rdpg, rc = -ENOMEM);
1512 /* call lower layers to fill allocated pages with directory data */
1513 rc = mo_readpage(info->mti_env, mdt_object_child(object), rdpg);
1515 GOTO(free_rdpg, rc);
1517 /* send pages to client */
1518 rc = mdt_sendpage(info, rdpg, rc);
1523 for (i = 0; i < rdpg->rp_npages; i++)
1524 if (rdpg->rp_pages[i] != NULL)
1525 cfs_free_page(rdpg->rp_pages[i]);
1526 OBD_FREE(rdpg->rp_pages, rdpg->rp_npages * sizeof rdpg->rp_pages[0]);
1528 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_SENDPAGE))
1534 static int mdt_reint_internal(struct mdt_thread_info *info,
1535 struct mdt_lock_handle *lhc,
1538 struct req_capsule *pill = info->mti_pill;
1539 struct mdt_device *mdt = info->mti_mdt;
1540 struct md_quota *mq = md_quota(info->mti_env);
1541 struct mdt_body *repbody;
1546 if (req_capsule_has_field(pill, &RMF_MDT_MD, RCL_SERVER))
1547 req_capsule_set_size(pill, &RMF_MDT_MD, RCL_SERVER,
1548 mdt->mdt_max_mdsize);
1549 if (req_capsule_has_field(pill, &RMF_LOGCOOKIES, RCL_SERVER))
1550 req_capsule_set_size(pill, &RMF_LOGCOOKIES, RCL_SERVER,
1551 mdt->mdt_max_cookiesize);
1553 rc = req_capsule_server_pack(pill);
1555 CERROR("Can't pack response, rc %d\n", rc);
1556 RETURN(err_serious(rc));
1559 if (req_capsule_has_field(pill, &RMF_MDT_BODY, RCL_SERVER)) {
1560 repbody = req_capsule_server_get(pill, &RMF_MDT_BODY);
1562 repbody->eadatasize = 0;
1563 repbody->aclsize = 0;
1566 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_REINT_UNPACK))
1567 GOTO(out_shrink, rc = err_serious(-EFAULT));
1569 rc = mdt_reint_unpack(info, op);
1571 CERROR("Can't unpack reint, rc %d\n", rc);
1572 GOTO(out_shrink, rc = err_serious(rc));
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 == 1) {
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 if (req_capsule_has_field(pill, &RMF_LOGCOOKIES, RCL_SERVER))
1583 req_capsule_set_size(pill, &RMF_LOGCOOKIES, RCL_SERVER,
1587 rc = mdt_init_ucred_reint(info);
1589 GOTO(out_shrink, rc);
1591 rc = mdt_fix_attr_ucred(info, op);
1593 GOTO(out_ucred, rc = err_serious(rc));
1595 if (mdt_check_resent(info, mdt_reconstruct, lhc)) {
1596 rc = lustre_msg_get_status(mdt_info_req(info)->rq_repmsg);
1597 GOTO(out_ucred, rc);
1599 mq->mq_exp = info->mti_exp;
1600 rc = mdt_reint_rec(info, lhc);
1603 mdt_exit_ucred(info);
1605 mdt_client_compatibility(info);
1606 mdt_shrink_reply(info);
1610 static long mdt_reint_opcode(struct mdt_thread_info *info,
1611 const struct req_format **fmt)
1613 struct mdt_rec_reint *rec;
1616 opc = err_serious(-EFAULT);
1617 rec = req_capsule_client_get(info->mti_pill, &RMF_REC_REINT);
1619 opc = rec->rr_opcode;
1620 DEBUG_REQ(D_INODE, mdt_info_req(info), "reint opt = %ld", opc);
1621 if (opc < REINT_MAX && fmt[opc] != NULL)
1622 req_capsule_extend(info->mti_pill, fmt[opc]);
1624 CERROR("Unsupported opc: %ld\n", opc);
1625 opc = err_serious(opc);
1631 static int mdt_reint(struct mdt_thread_info *info)
1636 static const struct req_format *reint_fmts[REINT_MAX] = {
1637 [REINT_SETATTR] = &RQF_MDS_REINT_SETATTR,
1638 [REINT_CREATE] = &RQF_MDS_REINT_CREATE,
1639 [REINT_LINK] = &RQF_MDS_REINT_LINK,
1640 [REINT_UNLINK] = &RQF_MDS_REINT_UNLINK,
1641 [REINT_RENAME] = &RQF_MDS_REINT_RENAME,
1642 [REINT_OPEN] = &RQF_MDS_REINT_OPEN,
1643 [REINT_SETXATTR] = &RQF_MDS_REINT_SETXATTR
1648 opc = mdt_reint_opcode(info, reint_fmts);
1651 * No lock possible here from client to pass it to reint code
1654 rc = mdt_reint_internal(info, NULL, opc);
1659 info->mti_fail_id = OBD_FAIL_MDS_REINT_NET_REP;
1663 /* this should sync the whole device */
1664 static int mdt_device_sync(const struct lu_env *env, struct mdt_device *mdt)
1666 struct dt_device *dt = mdt->mdt_bottom;
1670 rc = dt->dd_ops->dt_sync(env, dt);
1674 /* this should sync this object */
1675 static int mdt_object_sync(struct mdt_thread_info *info)
1677 struct md_object *next;
1681 if (!mdt_object_exists(info->mti_object)) {
1682 CWARN("Non existing object "DFID"!\n",
1683 PFID(mdt_object_fid(info->mti_object)));
1686 next = mdt_object_child(info->mti_object);
1687 rc = mo_object_sync(info->mti_env, next);
1692 static int mdt_sync(struct mdt_thread_info *info)
1694 struct ptlrpc_request *req = mdt_info_req(info);
1695 struct req_capsule *pill = info->mti_pill;
1696 struct mdt_body *body;
1700 /* The fid may be zero, so we req_capsule_set manually */
1701 req_capsule_set(pill, &RQF_MDS_SYNC);
1703 body = req_capsule_client_get(pill, &RMF_MDT_BODY);
1705 RETURN(err_serious(-EINVAL));
1707 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_SYNC_PACK))
1708 RETURN(err_serious(-ENOMEM));
1710 if (fid_seq(&body->fid1) == 0) {
1711 /* sync the whole device */
1712 rc = req_capsule_server_pack(pill);
1714 rc = mdt_device_sync(info->mti_env, info->mti_mdt);
1716 rc = err_serious(rc);
1718 /* sync an object */
1719 rc = mdt_unpack_req_pack_rep(info, HABEO_CORPUS|HABEO_REFERO);
1721 rc = mdt_object_sync(info);
1723 struct md_object *next;
1724 const struct lu_fid *fid;
1725 struct lu_attr *la = &info->mti_attr.ma_attr;
1727 next = mdt_object_child(info->mti_object);
1728 info->mti_attr.ma_need = MA_INODE;
1729 info->mti_attr.ma_valid = 0;
1730 rc = mo_attr_get(info->mti_env, next,
1733 body = req_capsule_server_get(pill,
1735 fid = mdt_object_fid(info->mti_object);
1736 mdt_pack_attr2body(info, body, la, fid);
1740 rc = err_serious(rc);
1743 mdt_counter_incr(req->rq_export, LPROC_MDT_SYNC);
1748 #ifdef HAVE_QUOTA_SUPPORT
1749 static int mdt_quotacheck_handle(struct mdt_thread_info *info)
1751 struct obd_quotactl *oqctl;
1752 struct req_capsule *pill = info->mti_pill;
1753 struct obd_export *exp = info->mti_exp;
1754 struct md_quota *mq = md_quota(info->mti_env);
1755 struct md_device *next = info->mti_mdt->mdt_child;
1759 oqctl = req_capsule_client_get(pill, &RMF_OBD_QUOTACTL);
1763 /* remote client has no permission for quotacheck */
1764 if (unlikely(exp_connect_rmtclient(exp)))
1767 rc = req_capsule_server_pack(pill);
1772 rc = next->md_ops->mdo_quota.mqo_check(info->mti_env, next,
1777 static int mdt_quotactl_handle(struct mdt_thread_info *info)
1779 struct obd_quotactl *oqctl, *repoqc;
1780 struct req_capsule *pill = info->mti_pill;
1781 struct obd_export *exp = info->mti_exp;
1782 struct md_quota *mq = md_quota(info->mti_env);
1783 struct md_device *next = info->mti_mdt->mdt_child;
1784 const struct md_quota_operations *mqo = &next->md_ops->mdo_quota;
1788 oqctl = req_capsule_client_get(pill, &RMF_OBD_QUOTACTL);
1793 if (exp_connect_rmtclient(exp)) {
1794 struct ptlrpc_request *req = mdt_info_req(info);
1795 struct mdt_export_data *med = mdt_req2med(req);
1796 struct lustre_idmap_table *idmap = med->med_idmap;
1798 if (unlikely(oqctl->qc_cmd != Q_GETQUOTA &&
1799 oqctl->qc_cmd != Q_GETINFO))
1803 if (oqctl->qc_type == USRQUOTA)
1804 id = lustre_idmap_lookup_uid(NULL, idmap, 0,
1806 else if (oqctl->qc_type == GRPQUOTA)
1807 id = lustre_idmap_lookup_gid(NULL, idmap, 0,
1812 if (id == CFS_IDMAP_NOTFOUND) {
1813 CDEBUG(D_QUOTA, "no mapping for id %u\n",
1819 rc = req_capsule_server_pack(pill);
1823 repoqc = req_capsule_server_get(pill, &RMF_OBD_QUOTACTL);
1824 LASSERT(repoqc != NULL);
1827 switch (oqctl->qc_cmd) {
1829 rc = mqo->mqo_on(info->mti_env, next, oqctl->qc_type);
1832 rc = mqo->mqo_off(info->mti_env, next, oqctl->qc_type);
1835 rc = mqo->mqo_setinfo(info->mti_env, next, oqctl->qc_type, id,
1839 rc = mqo->mqo_getinfo(info->mti_env, next, oqctl->qc_type, id,
1843 rc = mqo->mqo_setquota(info->mti_env, next, oqctl->qc_type, id,
1847 rc = mqo->mqo_getquota(info->mti_env, next, oqctl->qc_type, id,
1851 rc = mqo->mqo_getoinfo(info->mti_env, next, oqctl->qc_type, id,
1855 rc = mqo->mqo_getoquota(info->mti_env, next, oqctl->qc_type, id,
1858 case LUSTRE_Q_INVALIDATE:
1859 rc = mqo->mqo_invalidate(info->mti_env, next, oqctl->qc_type);
1861 case LUSTRE_Q_FINVALIDATE:
1862 rc = mqo->mqo_finvalidate(info->mti_env, next, oqctl->qc_type);
1865 CERROR("unsupported mdt_quotactl command: %d\n",
1877 * OBD PING and other handlers.
1879 static int mdt_obd_ping(struct mdt_thread_info *info)
1884 req_capsule_set(info->mti_pill, &RQF_OBD_PING);
1886 rc = target_handle_ping(mdt_info_req(info));
1888 rc = err_serious(rc);
1892 static int mdt_obd_log_cancel(struct mdt_thread_info *info)
1894 return err_serious(-EOPNOTSUPP);
1897 static int mdt_obd_qc_callback(struct mdt_thread_info *info)
1899 return err_serious(-EOPNOTSUPP);
1907 /** clone llog ctxt from child (mdd)
1908 * This allows remote llog (replicator) access.
1909 * We can either pass all llog RPCs (eg mdt_llog_create) on to child where the
1910 * context was originally set up, or we can handle them directly.
1911 * I choose the latter, but that means I need any llog
1912 * contexts set up by child to be accessable by the mdt. So we clone the
1913 * context into our context list here.
1915 static int mdt_llog_ctxt_clone(const struct lu_env *env, struct mdt_device *mdt,
1918 struct md_device *next = mdt->mdt_child;
1919 struct llog_ctxt *ctxt;
1922 if (!llog_ctxt_null(mdt2obd_dev(mdt), idx))
1925 rc = next->md_ops->mdo_llog_ctxt_get(env, next, idx, (void **)&ctxt);
1926 if (rc || ctxt == NULL) {
1927 CERROR("Can't get mdd ctxt %d\n", rc);
1931 rc = llog_group_set_ctxt(&mdt2obd_dev(mdt)->obd_olg, ctxt, idx);
1933 CERROR("Can't set mdt ctxt %d\n", rc);
1938 static int mdt_llog_ctxt_unclone(const struct lu_env *env,
1939 struct mdt_device *mdt, int idx)
1941 struct llog_ctxt *ctxt;
1943 ctxt = llog_get_context(mdt2obd_dev(mdt), idx);
1946 /* Put once for the get we just did, and once for the clone */
1947 llog_ctxt_put(ctxt);
1948 llog_ctxt_put(ctxt);
1952 static int mdt_llog_create(struct mdt_thread_info *info)
1956 req_capsule_set(info->mti_pill, &RQF_LLOG_ORIGIN_HANDLE_CREATE);
1957 rc = llog_origin_handle_create(mdt_info_req(info));
1958 return (rc < 0 ? err_serious(rc) : rc);
1961 static int mdt_llog_destroy(struct mdt_thread_info *info)
1965 req_capsule_set(info->mti_pill, &RQF_LLOG_ORIGIN_HANDLE_DESTROY);
1966 rc = llog_origin_handle_destroy(mdt_info_req(info));
1967 return (rc < 0 ? err_serious(rc) : rc);
1970 static int mdt_llog_read_header(struct mdt_thread_info *info)
1974 req_capsule_set(info->mti_pill, &RQF_LLOG_ORIGIN_HANDLE_READ_HEADER);
1975 rc = llog_origin_handle_read_header(mdt_info_req(info));
1976 return (rc < 0 ? err_serious(rc) : rc);
1979 static int mdt_llog_next_block(struct mdt_thread_info *info)
1983 req_capsule_set(info->mti_pill, &RQF_LLOG_ORIGIN_HANDLE_NEXT_BLOCK);
1984 rc = llog_origin_handle_next_block(mdt_info_req(info));
1985 return (rc < 0 ? err_serious(rc) : rc);
1988 static int mdt_llog_prev_block(struct mdt_thread_info *info)
1992 req_capsule_set(info->mti_pill, &RQF_LLOG_ORIGIN_HANDLE_PREV_BLOCK);
1993 rc = llog_origin_handle_prev_block(mdt_info_req(info));
1994 return (rc < 0 ? err_serious(rc) : rc);
2001 static struct ldlm_callback_suite cbs = {
2002 .lcs_completion = ldlm_server_completion_ast,
2003 .lcs_blocking = ldlm_server_blocking_ast,
2007 static int mdt_enqueue(struct mdt_thread_info *info)
2009 struct ptlrpc_request *req;
2013 * info->mti_dlm_req already contains swapped and (if necessary)
2014 * converted dlm request.
2016 LASSERT(info->mti_dlm_req != NULL);
2018 req = mdt_info_req(info);
2019 rc = ldlm_handle_enqueue0(info->mti_mdt->mdt_namespace,
2020 req, info->mti_dlm_req, &cbs);
2021 info->mti_fail_id = OBD_FAIL_LDLM_REPLY;
2022 return rc ? err_serious(rc) : req->rq_status;
2025 static int mdt_convert(struct mdt_thread_info *info)
2028 struct ptlrpc_request *req;
2030 LASSERT(info->mti_dlm_req);
2031 req = mdt_info_req(info);
2032 rc = ldlm_handle_convert0(req, info->mti_dlm_req);
2033 return rc ? err_serious(rc) : req->rq_status;
2036 static int mdt_bl_callback(struct mdt_thread_info *info)
2038 CERROR("bl callbacks should not happen on MDS\n");
2040 return err_serious(-EOPNOTSUPP);
2043 static int mdt_cp_callback(struct mdt_thread_info *info)
2045 CERROR("cp callbacks should not happen on MDS\n");
2047 return err_serious(-EOPNOTSUPP);
2051 * sec context handlers
2053 static int mdt_sec_ctx_handle(struct mdt_thread_info *info)
2057 rc = mdt_handle_idmap(info);
2060 struct ptlrpc_request *req = mdt_info_req(info);
2063 opc = lustre_msg_get_opc(req->rq_reqmsg);
2064 if (opc == SEC_CTX_INIT || opc == SEC_CTX_INIT_CONT)
2065 sptlrpc_svc_ctx_invalidate(req);
2068 CFS_FAIL_TIMEOUT(OBD_FAIL_SEC_CTX_HDL_PAUSE, cfs_fail_val);
2073 static struct mdt_object *mdt_obj(struct lu_object *o)
2075 LASSERT(lu_device_is_mdt(o->lo_dev));
2076 return container_of0(o, struct mdt_object, mot_obj.mo_lu);
2079 struct mdt_object *mdt_object_find(const struct lu_env *env,
2080 struct mdt_device *d,
2081 const struct lu_fid *f)
2083 struct lu_object *o;
2084 struct mdt_object *m;
2087 CDEBUG(D_INFO, "Find object for "DFID"\n", PFID(f));
2088 o = lu_object_find(env, &d->mdt_md_dev.md_lu_dev, f, NULL);
2089 if (unlikely(IS_ERR(o)))
2090 m = (struct mdt_object *)o;
2097 * Asyncronous commit for mdt device.
2099 * Pass asynchonous commit call down the MDS stack.
2101 * \param env environment
2102 * \param mdt the mdt device
2104 static void mdt_device_commit_async(const struct lu_env *env,
2105 struct mdt_device *mdt)
2107 struct dt_device *dt = mdt->mdt_bottom;
2110 rc = dt->dd_ops->dt_commit_async(env, dt);
2111 if (unlikely(rc != 0))
2112 CWARN("async commit start failed with rc = %d", rc);
2116 * Mark the lock as "synchonous".
2118 * Mark the lock to deffer transaction commit to the unlock time.
2120 * \param lock the lock to mark as "synchonous"
2122 * \see mdt_is_lock_sync
2123 * \see mdt_save_lock
2125 static inline void mdt_set_lock_sync(struct ldlm_lock *lock)
2127 lock->l_ast_data = (void*)1;
2131 * Check whehter the lock "synchonous" or not.
2133 * \param lock the lock to check
2134 * \retval 1 the lock is "synchonous"
2135 * \retval 0 the lock isn't "synchronous"
2137 * \see mdt_set_lock_sync
2138 * \see mdt_save_lock
2140 static inline int mdt_is_lock_sync(struct ldlm_lock *lock)
2142 return lock->l_ast_data != NULL;
2146 * Blocking AST for mdt locks.
2148 * Starts transaction commit if in case of COS lock conflict or
2149 * deffers such a commit to the mdt_save_lock.
2151 * \param lock the lock which blocks a request or cancelling lock
2152 * \param desc unused
2153 * \param data unused
2154 * \param flag indicates whether this cancelling or blocking callback
2156 * \see ldlm_blocking_ast_nocheck
2158 int mdt_blocking_ast(struct ldlm_lock *lock, struct ldlm_lock_desc *desc,
2159 void *data, int flag)
2161 struct obd_device *obd = ldlm_lock_to_ns(lock)->ns_obd;
2162 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
2166 if (flag == LDLM_CB_CANCELING)
2168 lock_res_and_lock(lock);
2169 if (lock->l_blocking_ast != mdt_blocking_ast) {
2170 unlock_res_and_lock(lock);
2173 if (mdt_cos_is_enabled(mdt) &&
2174 lock->l_req_mode & (LCK_PW | LCK_EX) &&
2175 lock->l_blocking_lock != NULL &&
2176 lock->l_client_cookie != lock->l_blocking_lock->l_client_cookie) {
2177 mdt_set_lock_sync(lock);
2179 rc = ldlm_blocking_ast_nocheck(lock);
2181 /* There is no lock conflict if l_blocking_lock == NULL,
2182 * it indicates a blocking ast sent from ldlm_lock_decref_internal
2183 * when the last reference to a local lock was released */
2184 if (lock->l_req_mode == LCK_COS && lock->l_blocking_lock != NULL) {
2187 rc = lu_env_init(&env, LCT_MD_THREAD);
2188 if (unlikely(rc != 0))
2189 CWARN("lu_env initialization failed with rc = %d,"
2190 "cannot start asynchronous commit\n", rc);
2192 mdt_device_commit_async(&env, mdt);
2198 int mdt_object_lock(struct mdt_thread_info *info, struct mdt_object *o,
2199 struct mdt_lock_handle *lh, __u64 ibits, int locality)
2201 struct ldlm_namespace *ns = info->mti_mdt->mdt_namespace;
2202 ldlm_policy_data_t *policy = &info->mti_policy;
2203 struct ldlm_res_id *res_id = &info->mti_res_id;
2207 LASSERT(!lustre_handle_is_used(&lh->mlh_reg_lh));
2208 LASSERT(!lustre_handle_is_used(&lh->mlh_pdo_lh));
2209 LASSERT(lh->mlh_reg_mode != LCK_MINMODE);
2210 LASSERT(lh->mlh_type != MDT_NUL_LOCK);
2212 if (mdt_object_exists(o) < 0) {
2213 if (locality == MDT_CROSS_LOCK) {
2214 /* cross-ref object fix */
2215 ibits &= ~MDS_INODELOCK_UPDATE;
2216 ibits |= MDS_INODELOCK_LOOKUP;
2218 LASSERT(!(ibits & MDS_INODELOCK_UPDATE));
2219 LASSERT(ibits & MDS_INODELOCK_LOOKUP);
2221 /* No PDO lock on remote object */
2222 LASSERT(lh->mlh_type != MDT_PDO_LOCK);
2225 if (lh->mlh_type == MDT_PDO_LOCK) {
2226 /* check for exists after object is locked */
2227 if (mdt_object_exists(o) == 0) {
2228 /* Non-existent object shouldn't have PDO lock */
2231 /* Non-dir object shouldn't have PDO lock */
2232 if (!S_ISDIR(lu_object_attr(&o->mot_obj.mo_lu)))
2237 memset(policy, 0, sizeof(*policy));
2238 fid_build_reg_res_name(mdt_object_fid(o), res_id);
2241 * Take PDO lock on whole directory and build correct @res_id for lock
2242 * on part of directory.
2244 if (lh->mlh_pdo_hash != 0) {
2245 LASSERT(lh->mlh_type == MDT_PDO_LOCK);
2246 mdt_lock_pdo_mode(info, o, lh);
2247 if (lh->mlh_pdo_mode != LCK_NL) {
2249 * Do not use LDLM_FL_LOCAL_ONLY for parallel lock, it
2250 * is never going to be sent to client and we do not
2251 * want it slowed down due to possible cancels.
2253 policy->l_inodebits.bits = MDS_INODELOCK_UPDATE;
2254 rc = mdt_fid_lock(ns, &lh->mlh_pdo_lh, lh->mlh_pdo_mode,
2255 policy, res_id, LDLM_FL_ATOMIC_CB,
2256 &info->mti_exp->exp_handle.h_cookie);
2262 * Finish res_id initializing by name hash marking part of
2263 * directory which is taking modification.
2265 res_id->name[LUSTRE_RES_ID_HSH_OFF] = lh->mlh_pdo_hash;
2268 policy->l_inodebits.bits = ibits;
2271 * Use LDLM_FL_LOCAL_ONLY for this lock. We do not know yet if it is
2272 * going to be sent to client. If it is - mdt_intent_policy() path will
2273 * fix it up and turn FL_LOCAL flag off.
2275 rc = mdt_fid_lock(ns, &lh->mlh_reg_lh, lh->mlh_reg_mode, policy,
2276 res_id, LDLM_FL_LOCAL_ONLY | LDLM_FL_ATOMIC_CB,
2277 &info->mti_exp->exp_handle.h_cookie);
2279 mdt_object_unlock(info, o, lh, 1);
2280 else if (unlikely(OBD_FAIL_PRECHECK(OBD_FAIL_MDS_PDO_LOCK)) &&
2281 lh->mlh_pdo_hash != 0 &&
2282 (lh->mlh_reg_mode == LCK_PW || lh->mlh_reg_mode == LCK_EX)) {
2283 OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_PDO_LOCK, 15);
2290 * Save a lock within request object.
2292 * Keep the lock referenced until whether client ACK or transaction
2293 * commit happens or release the lock immediately depending on input
2294 * parameters. If COS is ON, a write lock is converted to COS lock
2297 * \param info thead info object
2298 * \param h lock handle
2299 * \param mode lock mode
2300 * \param decref force immediate lock releasing
2303 void mdt_save_lock(struct mdt_thread_info *info, struct lustre_handle *h,
2304 ldlm_mode_t mode, int decref)
2308 if (lustre_handle_is_used(h)) {
2309 if (decref || !info->mti_has_trans ||
2310 !(mode & (LCK_PW | LCK_EX))){
2311 mdt_fid_unlock(h, mode);
2313 struct mdt_device *mdt = info->mti_mdt;
2314 struct ldlm_lock *lock = ldlm_handle2lock(h);
2315 struct ptlrpc_request *req = mdt_info_req(info);
2318 LASSERTF(lock != NULL, "no lock for cookie "LPX64"\n",
2320 CDEBUG(D_HA, "request = %p reply state = %p"
2321 " transno = "LPD64"\n",
2322 req, req->rq_reply_state, req->rq_transno);
2323 if (mdt_cos_is_enabled(mdt)) {
2325 ldlm_lock_downgrade(lock, LCK_COS);
2328 ptlrpc_save_lock(req, h, mode, no_ack);
2329 if (mdt_is_lock_sync(lock)) {
2330 CDEBUG(D_HA, "found sync-lock,"
2331 " async commit started\n");
2332 mdt_device_commit_async(info->mti_env,
2335 LDLM_LOCK_PUT(lock);
2344 * Unlock mdt object.
2346 * Immeditely release the regular lock and the PDO lock or save the
2347 * lock in reqeuest and keep them referenced until client ACK or
2348 * transaction commit.
2350 * \param info thread info object
2351 * \param o mdt object
2352 * \param lh mdt lock handle referencing regular and PDO locks
2353 * \param decref force immediate lock releasing
2355 void mdt_object_unlock(struct mdt_thread_info *info, struct mdt_object *o,
2356 struct mdt_lock_handle *lh, int decref)
2360 mdt_save_lock(info, &lh->mlh_pdo_lh, lh->mlh_pdo_mode, decref);
2361 mdt_save_lock(info, &lh->mlh_reg_lh, lh->mlh_reg_mode, decref);
2366 struct mdt_object *mdt_object_find_lock(struct mdt_thread_info *info,
2367 const struct lu_fid *f,
2368 struct mdt_lock_handle *lh,
2371 struct mdt_object *o;
2373 o = mdt_object_find(info->mti_env, info->mti_mdt, f);
2377 rc = mdt_object_lock(info, o, lh, ibits,
2380 mdt_object_put(info->mti_env, o);
2387 void mdt_object_unlock_put(struct mdt_thread_info * info,
2388 struct mdt_object * o,
2389 struct mdt_lock_handle *lh,
2392 mdt_object_unlock(info, o, lh, decref);
2393 mdt_object_put(info->mti_env, o);
2396 static struct mdt_handler *mdt_handler_find(__u32 opc,
2397 struct mdt_opc_slice *supported)
2399 struct mdt_opc_slice *s;
2400 struct mdt_handler *h;
2403 for (s = supported; s->mos_hs != NULL; s++) {
2404 if (s->mos_opc_start <= opc && opc < s->mos_opc_end) {
2405 h = s->mos_hs + (opc - s->mos_opc_start);
2406 if (likely(h->mh_opc != 0))
2407 LASSERTF(h->mh_opc == opc,
2408 "opcode mismatch %d != %d\n",
2411 h = NULL; /* unsupported opc */
2418 static int mdt_lock_resname_compat(struct mdt_device *m,
2419 struct ldlm_request *req)
2421 /* XXX something... later. */
2425 static int mdt_lock_reply_compat(struct mdt_device *m, struct ldlm_reply *rep)
2427 /* XXX something... later. */
2432 * Generic code handling requests that have struct mdt_body passed in:
2434 * - extract mdt_body from request and save it in @info, if present;
2436 * - create lu_object, corresponding to the fid in mdt_body, and save it in
2439 * - if HABEO_CORPUS flag is set for this request type check whether object
2440 * actually exists on storage (lu_object_exists()).
2443 static int mdt_body_unpack(struct mdt_thread_info *info, __u32 flags)
2445 const struct mdt_body *body;
2446 struct mdt_object *obj;
2447 const struct lu_env *env;
2448 struct req_capsule *pill;
2452 env = info->mti_env;
2453 pill = info->mti_pill;
2455 body = info->mti_body = req_capsule_client_get(pill, &RMF_MDT_BODY);
2459 if (!(body->valid & OBD_MD_FLID))
2462 if (!fid_is_sane(&body->fid1)) {
2463 CERROR("Invalid fid: "DFID"\n", PFID(&body->fid1));
2468 * Do not get size or any capa fields before we check that request
2469 * contains capa actually. There are some requests which do not, for
2470 * instance MDS_IS_SUBDIR.
2472 if (req_capsule_has_field(pill, &RMF_CAPA1, RCL_CLIENT) &&
2473 req_capsule_get_size(pill, &RMF_CAPA1, RCL_CLIENT))
2474 mdt_set_capainfo(info, 0, &body->fid1,
2475 req_capsule_client_get(pill, &RMF_CAPA1));
2477 obj = mdt_object_find(env, info->mti_mdt, &body->fid1);
2479 if ((flags & HABEO_CORPUS) &&
2480 !mdt_object_exists(obj)) {
2481 mdt_object_put(env, obj);
2482 /* for capability renew ENOENT will be handled in
2484 if (body->valid & OBD_MD_FLOSSCAPA)
2489 info->mti_object = obj;
2498 static int mdt_unpack_req_pack_rep(struct mdt_thread_info *info, __u32 flags)
2500 struct req_capsule *pill = info->mti_pill;
2504 if (req_capsule_has_field(pill, &RMF_MDT_BODY, RCL_CLIENT))
2505 rc = mdt_body_unpack(info, flags);
2509 if (rc == 0 && (flags & HABEO_REFERO)) {
2510 struct mdt_device *mdt = info->mti_mdt;
2514 if (req_capsule_has_field(pill, &RMF_MDT_MD, RCL_SERVER))
2515 req_capsule_set_size(pill, &RMF_MDT_MD, RCL_SERVER,
2516 mdt->mdt_max_mdsize);
2517 if (req_capsule_has_field(pill, &RMF_LOGCOOKIES, RCL_SERVER))
2518 req_capsule_set_size(pill, &RMF_LOGCOOKIES, RCL_SERVER,
2519 mdt->mdt_max_cookiesize);
2521 rc = req_capsule_server_pack(pill);
2526 static int mdt_init_capa_ctxt(const struct lu_env *env, struct mdt_device *m)
2528 struct md_device *next = m->mdt_child;
2530 return next->md_ops->mdo_init_capa_ctxt(env, next,
2531 m->mdt_opts.mo_mds_capa,
2532 m->mdt_capa_timeout,
2538 * Invoke handler for this request opc. Also do necessary preprocessing
2539 * (according to handler ->mh_flags), and post-processing (setting of
2540 * ->last_{xid,committed}).
2542 static int mdt_req_handle(struct mdt_thread_info *info,
2543 struct mdt_handler *h, struct ptlrpc_request *req)
2545 int rc, serious = 0;
2550 LASSERT(h->mh_act != NULL);
2551 LASSERT(h->mh_opc == lustre_msg_get_opc(req->rq_reqmsg));
2552 LASSERT(current->journal_info == NULL);
2555 * Checking for various OBD_FAIL_$PREF_$OPC_NET codes. _Do_ not try
2556 * to put same checks into handlers like mdt_close(), mdt_reint(),
2557 * etc., without talking to mdt authors first. Checking same thing
2558 * there again is useless and returning 0 error without packing reply
2559 * is buggy! Handlers either pack reply or return error.
2561 * We return 0 here and do not send any reply in order to emulate
2562 * network failure. Do not send any reply in case any of NET related
2563 * fail_id has occured.
2565 if (OBD_FAIL_CHECK_ORSET(h->mh_fail_id, OBD_FAIL_ONCE))
2569 flags = h->mh_flags;
2570 LASSERT(ergo(flags & (HABEO_CORPUS|HABEO_REFERO), h->mh_fmt != NULL));
2572 if (h->mh_fmt != NULL) {
2573 req_capsule_set(info->mti_pill, h->mh_fmt);
2574 rc = mdt_unpack_req_pack_rep(info, flags);
2577 if (rc == 0 && flags & MUTABOR &&
2578 req->rq_export->exp_connect_flags & OBD_CONNECT_RDONLY)
2579 /* should it be rq_status? */
2582 if (rc == 0 && flags & HABEO_CLAVIS) {
2583 struct ldlm_request *dlm_req;
2585 LASSERT(h->mh_fmt != NULL);
2587 dlm_req = req_capsule_client_get(info->mti_pill, &RMF_DLM_REQ);
2588 if (dlm_req != NULL) {
2589 if (unlikely(dlm_req->lock_desc.l_resource.lr_type ==
2591 dlm_req->lock_desc.l_policy_data.\
2592 l_inodebits.bits == 0)) {
2594 * Lock without inodebits makes no sense and
2595 * will oops later in ldlm. If client miss to
2596 * set such bits, do not trigger ASSERTION.
2598 * For liblustre flock case, it maybe zero.
2602 if (info->mti_mdt->mdt_opts.mo_compat_resname)
2603 rc = mdt_lock_resname_compat(
2606 info->mti_dlm_req = dlm_req;
2613 /* capability setting changed via /proc, needs reinitialize ctxt */
2614 if (info->mti_mdt && info->mti_mdt->mdt_capa_conf) {
2615 mdt_init_capa_ctxt(info->mti_env, info->mti_mdt);
2616 info->mti_mdt->mdt_capa_conf = 0;
2619 if (likely(rc == 0)) {
2621 * Process request, there can be two types of rc:
2622 * 1) errors with msg unpack/pack, other failures outside the
2623 * operation itself. This is counted as serious errors;
2624 * 2) errors during fs operation, should be placed in rq_status
2627 rc = h->mh_act(info);
2629 !req->rq_no_reply && req->rq_reply_state == NULL) {
2630 DEBUG_REQ(D_ERROR, req, "MDT \"handler\" %s did not "
2631 "pack reply and returned 0 error\n",
2635 serious = is_serious(rc);
2636 rc = clear_serious(rc);
2640 req->rq_status = rc;
2643 * ELDLM_* codes which > 0 should be in rq_status only as well as
2644 * all non-serious errors.
2646 if (rc > 0 || !serious)
2649 LASSERT(current->journal_info == NULL);
2651 if (rc == 0 && (flags & HABEO_CLAVIS) &&
2652 info->mti_mdt->mdt_opts.mo_compat_resname) {
2653 struct ldlm_reply *dlmrep;
2655 dlmrep = req_capsule_server_get(info->mti_pill, &RMF_DLM_REP);
2657 rc = mdt_lock_reply_compat(info->mti_mdt, dlmrep);
2660 /* If we're DISCONNECTing, the mdt_export_data is already freed */
2661 if (likely(rc == 0 && req->rq_export && h->mh_opc != MDS_DISCONNECT))
2662 target_committed_to_req(req);
2664 if (unlikely(req_is_replay(req) &&
2665 lustre_msg_get_transno(req->rq_reqmsg) == 0)) {
2666 DEBUG_REQ(D_ERROR, req, "transno is 0 during REPLAY");
2670 target_send_reply(req, rc, info->mti_fail_id);
2674 void mdt_lock_handle_init(struct mdt_lock_handle *lh)
2676 lh->mlh_type = MDT_NUL_LOCK;
2677 lh->mlh_reg_lh.cookie = 0ull;
2678 lh->mlh_reg_mode = LCK_MINMODE;
2679 lh->mlh_pdo_lh.cookie = 0ull;
2680 lh->mlh_pdo_mode = LCK_MINMODE;
2683 void mdt_lock_handle_fini(struct mdt_lock_handle *lh)
2685 LASSERT(!lustre_handle_is_used(&lh->mlh_reg_lh));
2686 LASSERT(!lustre_handle_is_used(&lh->mlh_pdo_lh));
2690 * Initialize fields of struct mdt_thread_info. Other fields are left in
2691 * uninitialized state, because it's too expensive to zero out whole
2692 * mdt_thread_info (> 1K) on each request arrival.
2694 static void mdt_thread_info_init(struct ptlrpc_request *req,
2695 struct mdt_thread_info *info)
2698 struct md_capainfo *ci;
2700 req_capsule_init(&req->rq_pill, req, RCL_SERVER);
2701 info->mti_pill = &req->rq_pill;
2704 for (i = 0; i < ARRAY_SIZE(info->mti_lh); i++)
2705 mdt_lock_handle_init(&info->mti_lh[i]);
2707 /* mdt device: it can be NULL while CONNECT */
2708 if (req->rq_export) {
2709 info->mti_mdt = mdt_dev(req->rq_export->exp_obd->obd_lu_dev);
2710 info->mti_exp = req->rq_export;
2712 info->mti_mdt = NULL;
2713 info->mti_env = req->rq_svc_thread->t_env;
2714 ci = md_capainfo(info->mti_env);
2715 memset(ci, 0, sizeof *ci);
2716 if (req->rq_export) {
2717 if (exp_connect_rmtclient(req->rq_export))
2718 ci->mc_auth = LC_ID_CONVERT;
2719 else if (req->rq_export->exp_connect_flags &
2720 OBD_CONNECT_MDS_CAPA)
2721 ci->mc_auth = LC_ID_PLAIN;
2723 ci->mc_auth = LC_ID_NONE;
2726 info->mti_fail_id = OBD_FAIL_MDS_ALL_REPLY_NET;
2727 info->mti_transno = lustre_msg_get_transno(req->rq_reqmsg);
2728 info->mti_mos = NULL;
2730 memset(&info->mti_attr, 0, sizeof(info->mti_attr));
2731 info->mti_body = NULL;
2732 info->mti_object = NULL;
2733 info->mti_dlm_req = NULL;
2734 info->mti_has_trans = 0;
2735 info->mti_no_need_trans = 0;
2736 info->mti_cross_ref = 0;
2737 info->mti_opdata = 0;
2739 /* To not check for split by default. */
2740 info->mti_spec.sp_ck_split = 0;
2741 info->mti_spec.no_create = 0;
2744 static void mdt_thread_info_fini(struct mdt_thread_info *info)
2748 req_capsule_fini(info->mti_pill);
2749 if (info->mti_object != NULL) {
2751 * freeing an object may lead to OSD level transaction, do not
2752 * let it mess with MDT. bz19385.
2754 info->mti_no_need_trans = 1;
2755 mdt_object_put(info->mti_env, info->mti_object);
2756 info->mti_object = NULL;
2758 for (i = 0; i < ARRAY_SIZE(info->mti_lh); i++)
2759 mdt_lock_handle_fini(&info->mti_lh[i]);
2760 info->mti_env = NULL;
2763 static int mdt_filter_recovery_request(struct ptlrpc_request *req,
2764 struct obd_device *obd, int *process)
2766 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
2767 case MDS_CONNECT: /* This will never get here, but for completeness. */
2768 case OST_CONNECT: /* This will never get here, but for completeness. */
2769 case MDS_DISCONNECT:
2770 case OST_DISCONNECT:
2775 case MDS_DONE_WRITING:
2776 case MDS_SYNC: /* used in unmounting */
2782 *process = target_queue_recovery_request(req, obd);
2786 DEBUG_REQ(D_ERROR, req, "not permitted during recovery");
2793 * Handle recovery. Return:
2794 * +1: continue request processing;
2795 * -ve: abort immediately with the given error code;
2796 * 0: send reply with error code in req->rq_status;
2798 static int mdt_recovery(struct mdt_thread_info *info)
2800 struct ptlrpc_request *req = mdt_info_req(info);
2801 struct obd_device *obd;
2805 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
2808 case SEC_CTX_INIT_CONT:
2814 rc = mdt_handle_idmap(info);
2823 if (unlikely(!class_connected_export(req->rq_export))) {
2824 CERROR("operation %d on unconnected MDS from %s\n",
2825 lustre_msg_get_opc(req->rq_reqmsg),
2826 libcfs_id2str(req->rq_peer));
2827 /* FIXME: For CMD cleanup, when mds_B stop, the req from
2828 * mds_A will get -ENOTCONN(especially for ping req),
2829 * which will cause that mds_A deactive timeout, then when
2830 * mds_A cleanup, the cleanup process will be suspended since
2831 * deactive timeout is not zero.
2833 req->rq_status = -ENOTCONN;
2834 target_send_reply(req, -ENOTCONN, info->mti_fail_id);
2838 /* sanity check: if the xid matches, the request must be marked as a
2839 * resent or replayed */
2840 if (req_xid_is_last(req)) {
2841 if (!(lustre_msg_get_flags(req->rq_reqmsg) &
2842 (MSG_RESENT | MSG_REPLAY))) {
2843 DEBUG_REQ(D_WARNING, req, "rq_xid "LPU64" matches last_xid, "
2844 "expected REPLAY or RESENT flag (%x)", req->rq_xid,
2845 lustre_msg_get_flags(req->rq_reqmsg));
2847 req->rq_status = -ENOTCONN;
2852 /* else: note the opposite is not always true; a RESENT req after a
2853 * failover will usually not match the last_xid, since it was likely
2854 * never committed. A REPLAYed request will almost never match the
2855 * last xid, however it could for a committed, but still retained,
2858 obd = req->rq_export->exp_obd;
2860 /* Check for aborted recovery... */
2861 if (unlikely(obd->obd_recovering)) {
2864 DEBUG_REQ(D_INFO, req, "Got new replay");
2865 rc = mdt_filter_recovery_request(req, obd, &should_process);
2866 if (rc != 0 || !should_process)
2868 else if (should_process < 0) {
2869 req->rq_status = should_process;
2870 rc = ptlrpc_error(req);
2877 static int mdt_msg_check_version(struct lustre_msg *msg)
2881 switch (lustre_msg_get_opc(msg)) {
2883 case MDS_DISCONNECT:
2886 case SEC_CTX_INIT_CONT:
2888 rc = lustre_msg_check_version(msg, LUSTRE_OBD_VERSION);
2890 CERROR("bad opc %u version %08x, expecting %08x\n",
2891 lustre_msg_get_opc(msg),
2892 lustre_msg_get_version(msg),
2893 LUSTRE_OBD_VERSION);
2897 case MDS_GETATTR_NAME:
2904 case MDS_DONE_WRITING:
2911 case MDS_QUOTACHECK:
2917 rc = lustre_msg_check_version(msg, LUSTRE_MDS_VERSION);
2919 CERROR("bad opc %u version %08x, expecting %08x\n",
2920 lustre_msg_get_opc(msg),
2921 lustre_msg_get_version(msg),
2922 LUSTRE_MDS_VERSION);
2926 case LDLM_BL_CALLBACK:
2927 case LDLM_CP_CALLBACK:
2928 rc = lustre_msg_check_version(msg, LUSTRE_DLM_VERSION);
2930 CERROR("bad opc %u version %08x, expecting %08x\n",
2931 lustre_msg_get_opc(msg),
2932 lustre_msg_get_version(msg),
2933 LUSTRE_DLM_VERSION);
2935 case OBD_LOG_CANCEL:
2936 case LLOG_ORIGIN_HANDLE_CREATE:
2937 case LLOG_ORIGIN_HANDLE_NEXT_BLOCK:
2938 case LLOG_ORIGIN_HANDLE_READ_HEADER:
2939 case LLOG_ORIGIN_HANDLE_CLOSE:
2940 case LLOG_ORIGIN_HANDLE_DESTROY:
2941 case LLOG_ORIGIN_HANDLE_PREV_BLOCK:
2943 rc = lustre_msg_check_version(msg, LUSTRE_LOG_VERSION);
2945 CERROR("bad opc %u version %08x, expecting %08x\n",
2946 lustre_msg_get_opc(msg),
2947 lustre_msg_get_version(msg),
2948 LUSTRE_LOG_VERSION);
2951 CERROR("MDS unknown opcode %d\n", lustre_msg_get_opc(msg));
2957 static int mdt_handle0(struct ptlrpc_request *req,
2958 struct mdt_thread_info *info,
2959 struct mdt_opc_slice *supported)
2961 struct mdt_handler *h;
2962 struct lustre_msg *msg;
2967 if (OBD_FAIL_CHECK_ORSET(OBD_FAIL_MDS_ALL_REQUEST_NET, OBD_FAIL_ONCE))
2970 LASSERT(current->journal_info == NULL);
2972 msg = req->rq_reqmsg;
2973 rc = mdt_msg_check_version(msg);
2974 if (likely(rc == 0)) {
2975 rc = mdt_recovery(info);
2976 if (likely(rc == +1)) {
2977 h = mdt_handler_find(lustre_msg_get_opc(msg),
2979 if (likely(h != NULL)) {
2980 rc = mdt_req_handle(info, h, req);
2982 CERROR("The unsupported opc: 0x%x\n",
2983 lustre_msg_get_opc(msg) );
2984 req->rq_status = -ENOTSUPP;
2985 rc = ptlrpc_error(req);
2990 CERROR(LUSTRE_MDT_NAME" drops mal-formed request\n");
2995 * MDT handler function called by ptlrpc service thread when request comes.
2997 * XXX common "target" functionality should be factored into separate module
2998 * shared by mdt, ost and stand-alone services like fld.
3000 static int mdt_handle_common(struct ptlrpc_request *req,
3001 struct mdt_opc_slice *supported)
3004 struct mdt_thread_info *info;
3008 env = req->rq_svc_thread->t_env;
3009 LASSERT(env != NULL);
3010 LASSERT(env->le_ses != NULL);
3011 LASSERT(env->le_ctx.lc_thread == req->rq_svc_thread);
3012 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
3013 LASSERT(info != NULL);
3015 mdt_thread_info_init(req, info);
3017 rc = mdt_handle0(req, info, supported);
3019 mdt_thread_info_fini(info);
3024 * This is called from recovery code as handler of _all_ RPC types, FLD and SEQ
3027 int mdt_recovery_handle(struct ptlrpc_request *req)
3032 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
3034 rc = mdt_handle_common(req, mdt_fld_handlers);
3037 rc = mdt_handle_common(req, mdt_seq_handlers);
3040 rc = mdt_handle_common(req, mdt_regular_handlers);
3047 static int mdt_regular_handle(struct ptlrpc_request *req)
3049 return mdt_handle_common(req, mdt_regular_handlers);
3052 static int mdt_readpage_handle(struct ptlrpc_request *req)
3054 return mdt_handle_common(req, mdt_readpage_handlers);
3057 static int mdt_xmds_handle(struct ptlrpc_request *req)
3059 return mdt_handle_common(req, mdt_xmds_handlers);
3062 static int mdt_mdsc_handle(struct ptlrpc_request *req)
3064 return mdt_handle_common(req, mdt_seq_handlers);
3067 static int mdt_mdss_handle(struct ptlrpc_request *req)
3069 return mdt_handle_common(req, mdt_seq_handlers);
3072 static int mdt_dtss_handle(struct ptlrpc_request *req)
3074 return mdt_handle_common(req, mdt_seq_handlers);
3077 static int mdt_fld_handle(struct ptlrpc_request *req)
3079 return mdt_handle_common(req, mdt_fld_handlers);
3096 static int mdt_intent_getattr(enum mdt_it_code opcode,
3097 struct mdt_thread_info *info,
3098 struct ldlm_lock **,
3100 static int mdt_intent_reint(enum mdt_it_code opcode,
3101 struct mdt_thread_info *info,
3102 struct ldlm_lock **,
3105 static struct mdt_it_flavor {
3106 const struct req_format *it_fmt;
3108 int (*it_act)(enum mdt_it_code ,
3109 struct mdt_thread_info *,
3110 struct ldlm_lock **,
3113 } mdt_it_flavor[] = {
3115 .it_fmt = &RQF_LDLM_INTENT,
3116 /*.it_flags = HABEO_REFERO,*/
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_OPEN
3128 .it_fmt = &RQF_LDLM_INTENT,
3129 .it_flags = MUTABOR,
3130 .it_act = mdt_intent_reint,
3131 .it_reint = REINT_CREATE
3133 [MDT_IT_GETATTR] = {
3134 .it_fmt = &RQF_LDLM_INTENT_GETATTR,
3135 .it_flags = HABEO_REFERO,
3136 .it_act = mdt_intent_getattr
3138 [MDT_IT_READDIR] = {
3144 .it_fmt = &RQF_LDLM_INTENT_GETATTR,
3145 .it_flags = HABEO_REFERO,
3146 .it_act = mdt_intent_getattr
3149 .it_fmt = &RQF_LDLM_INTENT_UNLINK,
3150 .it_flags = MUTABOR,
3152 .it_reint = REINT_UNLINK
3156 .it_flags = MUTABOR,
3159 [MDT_IT_GETXATTR] = {
3165 .it_fmt = &RQF_LDLM_INTENT_GETATTR,
3166 .it_flags = HABEO_REFERO,
3167 .it_act = mdt_intent_getattr
3171 int mdt_intent_lock_replace(struct mdt_thread_info *info,
3172 struct ldlm_lock **lockp,
3173 struct ldlm_lock *new_lock,
3174 struct mdt_lock_handle *lh,
3177 struct ptlrpc_request *req = mdt_info_req(info);
3178 struct ldlm_lock *lock = *lockp;
3181 * Get new lock only for cases when possible resent did not find any
3184 if (new_lock == NULL)
3185 new_lock = ldlm_handle2lock_long(&lh->mlh_reg_lh, 0);
3187 if (new_lock == NULL && (flags & LDLM_FL_INTENT_ONLY)) {
3188 lh->mlh_reg_lh.cookie = 0;
3192 LASSERTF(new_lock != NULL,
3193 "lockh "LPX64"\n", lh->mlh_reg_lh.cookie);
3196 * If we've already given this lock to a client once, then we should
3197 * have no readers or writers. Otherwise, we should have one reader
3198 * _or_ writer ref (which will be zeroed below) before returning the
3201 if (new_lock->l_export == req->rq_export) {
3202 LASSERT(new_lock->l_readers + new_lock->l_writers == 0);
3204 LASSERT(new_lock->l_export == NULL);
3205 LASSERT(new_lock->l_readers + new_lock->l_writers == 1);
3210 if (new_lock->l_export == req->rq_export) {
3212 * Already gave this to the client, which means that we
3213 * reconstructed a reply.
3215 LASSERT(lustre_msg_get_flags(req->rq_reqmsg) &
3217 lh->mlh_reg_lh.cookie = 0;
3218 RETURN(ELDLM_LOCK_REPLACED);
3222 * Fixup the lock to be given to the client.
3224 lock_res_and_lock(new_lock);
3225 /* Zero new_lock->l_readers and new_lock->l_writers without triggering
3226 * possible blocking AST. */
3227 while (new_lock->l_readers > 0) {
3228 lu_ref_del(&new_lock->l_reference, "reader", new_lock);
3229 lu_ref_del(&new_lock->l_reference, "user", new_lock);
3230 new_lock->l_readers--;
3232 while (new_lock->l_writers > 0) {
3233 lu_ref_del(&new_lock->l_reference, "writer", new_lock);
3234 lu_ref_del(&new_lock->l_reference, "user", new_lock);
3235 new_lock->l_writers--;
3238 new_lock->l_export = class_export_lock_get(req->rq_export, new_lock);
3239 new_lock->l_blocking_ast = lock->l_blocking_ast;
3240 new_lock->l_completion_ast = lock->l_completion_ast;
3241 new_lock->l_remote_handle = lock->l_remote_handle;
3242 new_lock->l_flags &= ~LDLM_FL_LOCAL;
3244 unlock_res_and_lock(new_lock);
3246 cfs_hash_add(new_lock->l_export->exp_lock_hash,
3247 &new_lock->l_remote_handle,
3248 &new_lock->l_exp_hash);
3250 LDLM_LOCK_RELEASE(new_lock);
3251 lh->mlh_reg_lh.cookie = 0;
3253 RETURN(ELDLM_LOCK_REPLACED);
3256 static void mdt_intent_fixup_resent(struct mdt_thread_info *info,
3257 struct ldlm_lock *new_lock,
3258 struct ldlm_lock **old_lock,
3259 struct mdt_lock_handle *lh)
3261 struct ptlrpc_request *req = mdt_info_req(info);
3262 struct obd_export *exp = req->rq_export;
3263 struct lustre_handle remote_hdl;
3264 struct ldlm_request *dlmreq;
3265 struct ldlm_lock *lock;
3267 if (!(lustre_msg_get_flags(req->rq_reqmsg) & MSG_RESENT))
3270 dlmreq = req_capsule_client_get(info->mti_pill, &RMF_DLM_REQ);
3271 remote_hdl = dlmreq->lock_handle[0];
3273 lock = cfs_hash_lookup(exp->exp_lock_hash, &remote_hdl);
3275 if (lock != new_lock) {
3276 lh->mlh_reg_lh.cookie = lock->l_handle.h_cookie;
3277 lh->mlh_reg_mode = lock->l_granted_mode;
3279 LDLM_DEBUG(lock, "Restoring lock cookie");
3280 DEBUG_REQ(D_DLMTRACE, req,
3281 "restoring lock cookie "LPX64,
3282 lh->mlh_reg_lh.cookie);
3284 *old_lock = LDLM_LOCK_GET(lock);
3285 cfs_hash_put(exp->exp_lock_hash, &lock->l_exp_hash);
3289 cfs_hash_put(exp->exp_lock_hash, &lock->l_exp_hash);
3293 * If the xid matches, then we know this is a resent request, and allow
3294 * it. (It's probably an OPEN, for which we don't send a lock.
3296 if (req_xid_is_last(req))
3300 * This remote handle isn't enqueued, so we never received or processed
3301 * this request. Clear MSG_RESENT, because it can be handled like any
3302 * normal request now.
3304 lustre_msg_clear_flags(req->rq_reqmsg, MSG_RESENT);
3306 DEBUG_REQ(D_DLMTRACE, req, "no existing lock with rhandle "LPX64,
3310 static int mdt_intent_getattr(enum mdt_it_code opcode,
3311 struct mdt_thread_info *info,
3312 struct ldlm_lock **lockp,
3315 struct mdt_lock_handle *lhc = &info->mti_lh[MDT_LH_RMT];
3316 struct ldlm_lock *new_lock = NULL;
3318 struct ldlm_reply *ldlm_rep;
3319 struct ptlrpc_request *req;
3320 struct mdt_body *reqbody;
3321 struct mdt_body *repbody;
3325 reqbody = req_capsule_client_get(info->mti_pill, &RMF_MDT_BODY);
3328 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
3331 info->mti_spec.sp_ck_split = !!(reqbody->valid & OBD_MD_FLCKSPLIT);
3332 info->mti_cross_ref = !!(reqbody->valid & OBD_MD_FLCROSSREF);
3333 repbody->eadatasize = 0;
3334 repbody->aclsize = 0;
3338 child_bits = MDS_INODELOCK_LOOKUP;
3340 case MDT_IT_GETATTR:
3341 child_bits = MDS_INODELOCK_LOOKUP | MDS_INODELOCK_UPDATE;
3343 case MDT_IT_LAYOUT: {
3344 static int printed = 0;
3347 CERROR("layout lock not supported by this version\n");
3350 GOTO(out_shrink, rc = -EINVAL);
3354 CERROR("Unsupported intent (%d)\n", opcode);
3355 GOTO(out_shrink, rc = -EINVAL);
3358 rc = mdt_init_ucred(info, reqbody);
3360 GOTO(out_shrink, rc);
3362 req = info->mti_pill->rc_req;
3363 ldlm_rep = req_capsule_server_get(info->mti_pill, &RMF_DLM_REP);
3364 mdt_set_disposition(info, ldlm_rep, DISP_IT_EXECD);
3366 /* Get lock from request for possible resent case. */
3367 mdt_intent_fixup_resent(info, *lockp, &new_lock, lhc);
3369 ldlm_rep->lock_policy_res2 =
3370 mdt_getattr_name_lock(info, lhc, child_bits, ldlm_rep);
3372 if (mdt_get_disposition(ldlm_rep, DISP_LOOKUP_NEG))
3373 ldlm_rep->lock_policy_res2 = 0;
3374 if (!mdt_get_disposition(ldlm_rep, DISP_LOOKUP_POS) ||
3375 ldlm_rep->lock_policy_res2) {
3376 lhc->mlh_reg_lh.cookie = 0ull;
3377 GOTO(out_ucred, rc = ELDLM_LOCK_ABORTED);
3380 rc = mdt_intent_lock_replace(info, lockp, new_lock, lhc, flags);
3383 mdt_exit_ucred(info);
3385 mdt_client_compatibility(info);
3386 mdt_shrink_reply(info);
3390 static int mdt_intent_reint(enum mdt_it_code opcode,
3391 struct mdt_thread_info *info,
3392 struct ldlm_lock **lockp,
3395 struct mdt_lock_handle *lhc = &info->mti_lh[MDT_LH_RMT];
3396 struct ldlm_reply *rep = NULL;
3400 static const struct req_format *intent_fmts[REINT_MAX] = {
3401 [REINT_CREATE] = &RQF_LDLM_INTENT_CREATE,
3402 [REINT_OPEN] = &RQF_LDLM_INTENT_OPEN
3407 opc = mdt_reint_opcode(info, intent_fmts);
3411 if (mdt_it_flavor[opcode].it_reint != opc) {
3412 CERROR("Reint code %ld doesn't match intent: %d\n",
3414 RETURN(err_serious(-EPROTO));
3417 /* Get lock from request for possible resent case. */
3418 mdt_intent_fixup_resent(info, *lockp, NULL, lhc);
3420 rc = mdt_reint_internal(info, lhc, opc);
3422 /* Check whether the reply has been packed successfully. */
3423 if (mdt_info_req(info)->rq_repmsg != NULL)
3424 rep = req_capsule_server_get(info->mti_pill, &RMF_DLM_REP);
3426 RETURN(err_serious(-EFAULT));
3428 /* MDC expects this in any case */
3430 mdt_set_disposition(info, rep, DISP_LOOKUP_EXECD);
3432 /* Cross-ref case, the lock should be returned to the client */
3433 if (rc == -EREMOTE) {
3434 LASSERT(lustre_handle_is_used(&lhc->mlh_reg_lh));
3435 rep->lock_policy_res2 = 0;
3436 rc = mdt_intent_lock_replace(info, lockp, NULL, lhc, flags);
3439 rep->lock_policy_res2 = clear_serious(rc);
3441 if (rep->lock_policy_res2 == -ENOENT &&
3442 mdt_get_disposition(rep, DISP_LOOKUP_NEG))
3443 rep->lock_policy_res2 = 0;
3445 if (rc == -ENOTCONN || rc == -ENODEV ||
3446 rc == -EOVERFLOW) { /**< if VBR failure then return error */
3448 * If it is the disconnect error (ENODEV & ENOCONN), the error
3449 * will be returned by rq_status, and client at ptlrpc layer
3450 * will detect this, then disconnect, reconnect the import
3451 * immediately, instead of impacting the following the rpc.
3453 lhc->mlh_reg_lh.cookie = 0ull;
3457 * For other cases, the error will be returned by intent.
3458 * and client will retrieve the result from intent.
3461 * FIXME: when open lock is finished, that should be
3464 if (lustre_handle_is_used(&lhc->mlh_reg_lh)) {
3465 LASSERTF(rc == 0, "Error occurred but lock handle "
3466 "is still in use\n");
3467 rep->lock_policy_res2 = 0;
3468 rc = mdt_intent_lock_replace(info, lockp, NULL, lhc, flags);
3471 lhc->mlh_reg_lh.cookie = 0ull;
3472 RETURN(ELDLM_LOCK_ABORTED);
3477 static int mdt_intent_code(long itcode)
3485 case IT_OPEN|IT_CREAT:
3492 rc = MDT_IT_READDIR;
3495 rc = MDT_IT_GETATTR;
3507 rc = MDT_IT_GETXATTR;
3513 CERROR("Unknown intent opcode: %ld\n", itcode);
3520 static int mdt_intent_opc(long itopc, struct mdt_thread_info *info,
3521 struct ldlm_lock **lockp, int flags)
3523 struct req_capsule *pill;
3524 struct mdt_it_flavor *flv;
3529 opc = mdt_intent_code(itopc);
3533 pill = info->mti_pill;
3534 flv = &mdt_it_flavor[opc];
3536 if (flv->it_fmt != NULL)
3537 req_capsule_extend(pill, flv->it_fmt);
3539 rc = mdt_unpack_req_pack_rep(info, flv->it_flags);
3541 struct ptlrpc_request *req = mdt_info_req(info);
3542 if (flv->it_flags & MUTABOR &&
3543 req->rq_export->exp_connect_flags & OBD_CONNECT_RDONLY)
3546 if (rc == 0 && flv->it_act != NULL) {
3547 /* execute policy */
3548 rc = flv->it_act(opc, info, lockp, flags);
3555 static int mdt_intent_policy(struct ldlm_namespace *ns,
3556 struct ldlm_lock **lockp, void *req_cookie,
3557 ldlm_mode_t mode, int flags, void *data)
3559 struct mdt_thread_info *info;
3560 struct ptlrpc_request *req = req_cookie;
3561 struct ldlm_intent *it;
3562 struct req_capsule *pill;
3567 LASSERT(req != NULL);
3569 info = lu_context_key_get(&req->rq_svc_thread->t_env->le_ctx,
3571 LASSERT(info != NULL);
3572 pill = info->mti_pill;
3573 LASSERT(pill->rc_req == req);
3575 if (req->rq_reqmsg->lm_bufcount > DLM_INTENT_IT_OFF) {
3576 req_capsule_extend(pill, &RQF_LDLM_INTENT);
3577 it = req_capsule_client_get(pill, &RMF_LDLM_INTENT);
3579 rc = mdt_intent_opc(it->opc, info, lockp, flags);
3583 /* Lock without inodebits makes no sense and will oops
3584 * later in ldlm. Let's check it now to see if we have
3585 * ibits corrupted somewhere in mdt_intent_opc().
3586 * The case for client miss to set ibits has been
3587 * processed by others. */
3588 LASSERT(ergo(info->mti_dlm_req->lock_desc.l_resource.\
3589 lr_type == LDLM_IBITS,
3590 info->mti_dlm_req->lock_desc.\
3591 l_policy_data.l_inodebits.bits != 0));
3593 rc = err_serious(-EFAULT);
3595 /* No intent was provided */
3596 LASSERT(pill->rc_fmt == &RQF_LDLM_ENQUEUE);
3597 rc = req_capsule_server_pack(pill);
3599 rc = err_serious(rc);
3604 static int mdt_seq_fini(const struct lu_env *env,
3605 struct mdt_device *m)
3607 struct md_site *ms = mdt_md_site(m);
3611 if (ms->ms_server_seq) {
3612 seq_server_fini(ms->ms_server_seq, env);
3613 OBD_FREE_PTR(ms->ms_server_seq);
3614 ms->ms_server_seq = NULL;
3617 if (ms->ms_control_seq) {
3618 seq_server_fini(ms->ms_control_seq, env);
3619 OBD_FREE_PTR(ms->ms_control_seq);
3620 ms->ms_control_seq = NULL;
3623 if (ms->ms_client_seq) {
3624 seq_client_fini(ms->ms_client_seq);
3625 OBD_FREE_PTR(ms->ms_client_seq);
3626 ms->ms_client_seq = NULL;
3633 static int mdt_seq_init(const struct lu_env *env,
3635 struct mdt_device *m)
3642 ms = mdt_md_site(m);
3645 * This is sequence-controller node. Init seq-controller server on local
3648 if (ms->ms_node_id == 0) {
3649 LASSERT(ms->ms_control_seq == NULL);
3651 OBD_ALLOC_PTR(ms->ms_control_seq);
3652 if (ms->ms_control_seq == NULL)
3655 rc = seq_server_init(ms->ms_control_seq,
3656 m->mdt_bottom, uuid,
3657 LUSTRE_SEQ_CONTROLLER,
3662 GOTO(out_seq_fini, rc);
3664 OBD_ALLOC_PTR(ms->ms_client_seq);
3665 if (ms->ms_client_seq == NULL)
3666 GOTO(out_seq_fini, rc = -ENOMEM);
3668 OBD_ALLOC(prefix, MAX_OBD_NAME + 5);
3669 if (prefix == NULL) {
3670 OBD_FREE_PTR(ms->ms_client_seq);
3671 GOTO(out_seq_fini, rc = -ENOMEM);
3674 snprintf(prefix, MAX_OBD_NAME + 5, "ctl-%s",
3678 * Init seq-controller client after seq-controller server is
3679 * ready. Pass ms->ms_control_seq to it for direct talking.
3681 rc = seq_client_init(ms->ms_client_seq, NULL,
3682 LUSTRE_SEQ_METADATA, prefix,
3683 ms->ms_control_seq);
3684 OBD_FREE(prefix, MAX_OBD_NAME + 5);
3687 GOTO(out_seq_fini, rc);
3690 /* Init seq-server on local MDT */
3691 LASSERT(ms->ms_server_seq == NULL);
3693 OBD_ALLOC_PTR(ms->ms_server_seq);
3694 if (ms->ms_server_seq == NULL)
3695 GOTO(out_seq_fini, rc = -ENOMEM);
3697 rc = seq_server_init(ms->ms_server_seq,
3698 m->mdt_bottom, uuid,
3703 GOTO(out_seq_fini, rc = -ENOMEM);
3705 /* Assign seq-controller client to local seq-server. */
3706 if (ms->ms_node_id == 0) {
3707 LASSERT(ms->ms_client_seq != NULL);
3709 rc = seq_server_set_cli(ms->ms_server_seq,
3717 mdt_seq_fini(env, m);
3722 * Init client sequence manager which is used by local MDS to talk to sequence
3723 * controller on remote node.
3725 static int mdt_seq_init_cli(const struct lu_env *env,
3726 struct mdt_device *m,
3727 struct lustre_cfg *cfg)
3729 struct md_site *ms = mdt_md_site(m);
3730 struct obd_device *mdc;
3731 struct obd_uuid *uuidp, *mdcuuidp;
3732 char *uuid_str, *mdc_uuid_str;
3735 struct mdt_thread_info *info;
3736 char *p, *index_string = lustre_cfg_string(cfg, 2);
3739 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
3740 uuidp = &info->mti_u.uuid[0];
3741 mdcuuidp = &info->mti_u.uuid[1];
3743 LASSERT(index_string);
3745 index = simple_strtol(index_string, &p, 10);
3747 CERROR("Invalid index in lustre_cgf, offset 2\n");
3751 /* check if this is adding the first MDC and controller is not yet
3753 if (index != 0 || ms->ms_client_seq)
3756 uuid_str = lustre_cfg_string(cfg, 1);
3757 mdc_uuid_str = lustre_cfg_string(cfg, 4);
3758 obd_str2uuid(uuidp, uuid_str);
3759 obd_str2uuid(mdcuuidp, mdc_uuid_str);
3761 mdc = class_find_client_obd(uuidp, LUSTRE_MDC_NAME, mdcuuidp);
3763 CERROR("can't find controller MDC by uuid %s\n",
3766 } else if (!mdc->obd_set_up) {
3767 CERROR("target %s not set up\n", mdc->obd_name);
3770 LASSERT(ms->ms_control_exp);
3771 OBD_ALLOC_PTR(ms->ms_client_seq);
3772 if (ms->ms_client_seq != NULL) {
3775 OBD_ALLOC(prefix, MAX_OBD_NAME + 5);
3779 snprintf(prefix, MAX_OBD_NAME + 5, "ctl-%s",
3782 rc = seq_client_init(ms->ms_client_seq,
3784 LUSTRE_SEQ_METADATA,
3786 OBD_FREE(prefix, MAX_OBD_NAME + 5);
3793 LASSERT(ms->ms_server_seq != NULL);
3794 rc = seq_server_set_cli(ms->ms_server_seq, ms->ms_client_seq,
3801 static void mdt_seq_fini_cli(struct mdt_device *m)
3807 ms = mdt_md_site(m);
3810 if (ms->ms_server_seq)
3811 seq_server_set_cli(ms->ms_server_seq,
3814 if (ms->ms_control_exp) {
3815 class_export_put(ms->ms_control_exp);
3816 ms->ms_control_exp = NULL;
3825 static int mdt_fld_fini(const struct lu_env *env,
3826 struct mdt_device *m)
3828 struct md_site *ms = mdt_md_site(m);
3831 if (ms && ms->ms_server_fld) {
3832 fld_server_fini(ms->ms_server_fld, env);
3833 OBD_FREE_PTR(ms->ms_server_fld);
3834 ms->ms_server_fld = NULL;
3840 static int mdt_fld_init(const struct lu_env *env,
3842 struct mdt_device *m)
3848 ms = mdt_md_site(m);
3850 OBD_ALLOC_PTR(ms->ms_server_fld);
3851 if (ms->ms_server_fld == NULL)
3852 RETURN(rc = -ENOMEM);
3854 rc = fld_server_init(ms->ms_server_fld,
3855 m->mdt_bottom, uuid,
3856 env, ms->ms_node_id);
3858 OBD_FREE_PTR(ms->ms_server_fld);
3859 ms->ms_server_fld = NULL;
3866 /* device init/fini methods */
3867 static void mdt_stop_ptlrpc_service(struct mdt_device *m)
3870 if (m->mdt_regular_service != NULL) {
3871 ptlrpc_unregister_service(m->mdt_regular_service);
3872 m->mdt_regular_service = NULL;
3874 if (m->mdt_readpage_service != NULL) {
3875 ptlrpc_unregister_service(m->mdt_readpage_service);
3876 m->mdt_readpage_service = NULL;
3878 if (m->mdt_xmds_service != NULL) {
3879 ptlrpc_unregister_service(m->mdt_xmds_service);
3880 m->mdt_xmds_service = NULL;
3882 if (m->mdt_setattr_service != NULL) {
3883 ptlrpc_unregister_service(m->mdt_setattr_service);
3884 m->mdt_setattr_service = NULL;
3886 if (m->mdt_mdsc_service != NULL) {
3887 ptlrpc_unregister_service(m->mdt_mdsc_service);
3888 m->mdt_mdsc_service = NULL;
3890 if (m->mdt_mdss_service != NULL) {
3891 ptlrpc_unregister_service(m->mdt_mdss_service);
3892 m->mdt_mdss_service = NULL;
3894 if (m->mdt_dtss_service != NULL) {
3895 ptlrpc_unregister_service(m->mdt_dtss_service);
3896 m->mdt_dtss_service = NULL;
3898 if (m->mdt_fld_service != NULL) {
3899 ptlrpc_unregister_service(m->mdt_fld_service);
3900 m->mdt_fld_service = NULL;
3905 static int mdt_start_ptlrpc_service(struct mdt_device *m)
3908 static struct ptlrpc_service_conf conf;
3909 cfs_proc_dir_entry_t *procfs_entry;
3912 procfs_entry = m->mdt_md_dev.md_lu_dev.ld_obd->obd_proc_entry;
3914 conf = (typeof(conf)) {
3915 .psc_nbufs = MDS_NBUFS,
3916 .psc_bufsize = MDS_BUFSIZE,
3917 .psc_max_req_size = MDS_MAXREQSIZE,
3918 .psc_max_reply_size = MDS_MAXREPSIZE,
3919 .psc_req_portal = MDS_REQUEST_PORTAL,
3920 .psc_rep_portal = MDC_REPLY_PORTAL,
3921 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
3923 * We'd like to have a mechanism to set this on a per-device
3924 * basis, but alas...
3926 .psc_min_threads = mdt_min_threads,
3927 .psc_max_threads = mdt_max_threads,
3928 .psc_ctx_tags = LCT_MD_THREAD
3931 m->mdt_ldlm_client = &m->mdt_md_dev.md_lu_dev.ld_obd->obd_ldlm_client;
3932 ptlrpc_init_client(LDLM_CB_REQUEST_PORTAL, LDLM_CB_REPLY_PORTAL,
3933 "mdt_ldlm_client", m->mdt_ldlm_client);
3935 m->mdt_regular_service =
3936 ptlrpc_init_svc_conf(&conf, mdt_regular_handle, LUSTRE_MDT_NAME,
3937 procfs_entry, target_print_req,
3939 if (m->mdt_regular_service == NULL)
3942 rc = ptlrpc_start_threads(m->mdt_regular_service);
3944 GOTO(err_mdt_svc, rc);
3947 * readpage service configuration. Parameters have to be adjusted,
3950 conf = (typeof(conf)) {
3951 .psc_nbufs = MDS_NBUFS,
3952 .psc_bufsize = MDS_BUFSIZE,
3953 .psc_max_req_size = MDS_MAXREQSIZE,
3954 .psc_max_reply_size = MDS_MAXREPSIZE,
3955 .psc_req_portal = MDS_READPAGE_PORTAL,
3956 .psc_rep_portal = MDC_REPLY_PORTAL,
3957 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
3958 .psc_min_threads = mdt_min_threads,
3959 .psc_max_threads = mdt_max_threads,
3960 .psc_ctx_tags = LCT_MD_THREAD
3962 m->mdt_readpage_service =
3963 ptlrpc_init_svc_conf(&conf, mdt_readpage_handle,
3964 LUSTRE_MDT_NAME "_readpage",
3965 procfs_entry, target_print_req,"mdt_rdpg");
3967 if (m->mdt_readpage_service == NULL) {
3968 CERROR("failed to start readpage service\n");
3969 GOTO(err_mdt_svc, rc = -ENOMEM);
3972 rc = ptlrpc_start_threads(m->mdt_readpage_service);
3975 * setattr service configuration.
3977 * XXX To keep the compatibility with old client(< 2.2), we need to
3978 * preserve this portal for a certain time, it should be removed
3979 * eventually. LU-617.
3981 conf = (typeof(conf)) {
3982 .psc_nbufs = MDS_NBUFS,
3983 .psc_bufsize = MDS_BUFSIZE,
3984 .psc_max_req_size = MDS_MAXREQSIZE,
3985 .psc_max_reply_size = MDS_MAXREPSIZE,
3986 .psc_req_portal = MDS_SETATTR_PORTAL,
3987 .psc_rep_portal = MDC_REPLY_PORTAL,
3988 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
3989 .psc_min_threads = mdt_min_threads,
3990 .psc_max_threads = mdt_max_threads,
3991 .psc_ctx_tags = LCT_MD_THREAD
3994 m->mdt_setattr_service =
3995 ptlrpc_init_svc_conf(&conf, mdt_regular_handle,
3996 LUSTRE_MDT_NAME "_setattr",
3997 procfs_entry, target_print_req,"mdt_attr");
3999 if (!m->mdt_setattr_service) {
4000 CERROR("failed to start setattr service\n");
4001 GOTO(err_mdt_svc, rc = -ENOMEM);
4004 rc = ptlrpc_start_threads(m->mdt_setattr_service);
4006 GOTO(err_mdt_svc, rc);
4009 * sequence controller service configuration
4011 conf = (typeof(conf)) {
4012 .psc_nbufs = MDS_NBUFS,
4013 .psc_bufsize = MDS_BUFSIZE,
4014 .psc_max_req_size = SEQ_MAXREQSIZE,
4015 .psc_max_reply_size = SEQ_MAXREPSIZE,
4016 .psc_req_portal = SEQ_CONTROLLER_PORTAL,
4017 .psc_rep_portal = MDC_REPLY_PORTAL,
4018 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
4019 .psc_min_threads = mdt_min_threads,
4020 .psc_max_threads = mdt_max_threads,
4021 .psc_ctx_tags = LCT_MD_THREAD|LCT_DT_THREAD
4024 m->mdt_mdsc_service =
4025 ptlrpc_init_svc_conf(&conf, mdt_mdsc_handle,
4026 LUSTRE_MDT_NAME"_mdsc",
4027 procfs_entry, target_print_req,"mdt_mdsc");
4028 if (!m->mdt_mdsc_service) {
4029 CERROR("failed to start seq controller service\n");
4030 GOTO(err_mdt_svc, rc = -ENOMEM);
4033 rc = ptlrpc_start_threads(m->mdt_mdsc_service);
4035 GOTO(err_mdt_svc, rc);
4038 * metadata sequence server service configuration
4040 conf = (typeof(conf)) {
4041 .psc_nbufs = MDS_NBUFS,
4042 .psc_bufsize = MDS_BUFSIZE,
4043 .psc_max_req_size = SEQ_MAXREQSIZE,
4044 .psc_max_reply_size = SEQ_MAXREPSIZE,
4045 .psc_req_portal = SEQ_METADATA_PORTAL,
4046 .psc_rep_portal = MDC_REPLY_PORTAL,
4047 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
4048 .psc_min_threads = mdt_min_threads,
4049 .psc_max_threads = mdt_max_threads,
4050 .psc_ctx_tags = LCT_MD_THREAD|LCT_DT_THREAD
4053 m->mdt_mdss_service =
4054 ptlrpc_init_svc_conf(&conf, mdt_mdss_handle,
4055 LUSTRE_MDT_NAME"_mdss",
4056 procfs_entry, target_print_req,"mdt_mdss");
4057 if (!m->mdt_mdss_service) {
4058 CERROR("failed to start metadata seq server service\n");
4059 GOTO(err_mdt_svc, rc = -ENOMEM);
4062 rc = ptlrpc_start_threads(m->mdt_mdss_service);
4064 GOTO(err_mdt_svc, rc);
4068 * Data sequence server service configuration. We want to have really
4069 * cluster-wide sequences space. This is why we start only one sequence
4070 * controller which manages space.
4072 conf = (typeof(conf)) {
4073 .psc_nbufs = MDS_NBUFS,
4074 .psc_bufsize = MDS_BUFSIZE,
4075 .psc_max_req_size = SEQ_MAXREQSIZE,
4076 .psc_max_reply_size = SEQ_MAXREPSIZE,
4077 .psc_req_portal = SEQ_DATA_PORTAL,
4078 .psc_rep_portal = OSC_REPLY_PORTAL,
4079 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
4080 .psc_min_threads = mdt_min_threads,
4081 .psc_max_threads = mdt_max_threads,
4082 .psc_ctx_tags = LCT_MD_THREAD|LCT_DT_THREAD
4085 m->mdt_dtss_service =
4086 ptlrpc_init_svc_conf(&conf, mdt_dtss_handle,
4087 LUSTRE_MDT_NAME"_dtss",
4088 procfs_entry, target_print_req,"mdt_dtss");
4089 if (!m->mdt_dtss_service) {
4090 CERROR("failed to start data seq server service\n");
4091 GOTO(err_mdt_svc, rc = -ENOMEM);
4094 rc = ptlrpc_start_threads(m->mdt_dtss_service);
4096 GOTO(err_mdt_svc, rc);
4098 /* FLD service start */
4099 conf = (typeof(conf)) {
4100 .psc_nbufs = MDS_NBUFS,
4101 .psc_bufsize = MDS_BUFSIZE,
4102 .psc_max_req_size = FLD_MAXREQSIZE,
4103 .psc_max_reply_size = FLD_MAXREPSIZE,
4104 .psc_req_portal = FLD_REQUEST_PORTAL,
4105 .psc_rep_portal = MDC_REPLY_PORTAL,
4106 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
4107 .psc_min_threads = mdt_min_threads,
4108 .psc_max_threads = mdt_max_threads,
4109 .psc_ctx_tags = LCT_DT_THREAD|LCT_MD_THREAD
4112 m->mdt_fld_service =
4113 ptlrpc_init_svc_conf(&conf, mdt_fld_handle,
4114 LUSTRE_MDT_NAME"_fld",
4115 procfs_entry, target_print_req, "mdt_fld");
4116 if (!m->mdt_fld_service) {
4117 CERROR("failed to start fld service\n");
4118 GOTO(err_mdt_svc, rc = -ENOMEM);
4121 rc = ptlrpc_start_threads(m->mdt_fld_service);
4123 GOTO(err_mdt_svc, rc);
4126 * mds-mds service configuration. Separate portal is used to allow
4127 * mds-mds requests be not blocked during recovery.
4129 conf = (typeof(conf)) {
4130 .psc_nbufs = MDS_NBUFS,
4131 .psc_bufsize = MDS_BUFSIZE,
4132 .psc_max_req_size = MDS_MAXREQSIZE,
4133 .psc_max_reply_size = MDS_MAXREPSIZE,
4134 .psc_req_portal = MDS_MDS_PORTAL,
4135 .psc_rep_portal = MDC_REPLY_PORTAL,
4136 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
4137 .psc_min_threads = mdt_min_threads,
4138 .psc_max_threads = mdt_max_threads,
4139 .psc_ctx_tags = LCT_MD_THREAD
4141 m->mdt_xmds_service =
4142 ptlrpc_init_svc_conf(&conf, mdt_xmds_handle,
4143 LUSTRE_MDT_NAME "_mds",
4144 procfs_entry, target_print_req,"mdt_xmds");
4146 if (m->mdt_xmds_service == NULL) {
4147 CERROR("failed to start xmds service\n");
4148 GOTO(err_mdt_svc, rc = -ENOMEM);
4151 rc = ptlrpc_start_threads(m->mdt_xmds_service);
4153 GOTO(err_mdt_svc, rc);
4158 mdt_stop_ptlrpc_service(m);
4163 static void mdt_stack_fini(const struct lu_env *env,
4164 struct mdt_device *m, struct lu_device *top)
4166 struct obd_device *obd = mdt2obd_dev(m);
4167 struct lustre_cfg_bufs *bufs;
4168 struct lustre_cfg *lcfg;
4169 struct mdt_thread_info *info;
4173 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
4174 LASSERT(info != NULL);
4176 bufs = &info->mti_u.bufs;
4177 /* process cleanup, pass mdt obd name to get obd umount flags */
4178 lustre_cfg_bufs_reset(bufs, obd->obd_name);
4183 lustre_cfg_bufs_set_string(bufs, 1, flags);
4184 lcfg = lustre_cfg_new(LCFG_CLEANUP, bufs);
4186 CERROR("Cannot alloc lcfg!\n");
4191 top->ld_ops->ldo_process_config(env, top, lcfg);
4192 lustre_cfg_free(lcfg);
4194 lu_stack_fini(env, top);
4195 m->mdt_child = NULL;
4196 m->mdt_bottom = NULL;
4199 static struct lu_device *mdt_layer_setup(struct lu_env *env,
4200 const char *typename,
4201 struct lu_device *child,
4202 struct lustre_cfg *cfg)
4204 const char *dev = lustre_cfg_string(cfg, 0);
4205 struct obd_type *type;
4206 struct lu_device_type *ldt;
4207 struct lu_device *d;
4212 type = class_get_type(typename);
4214 CERROR("Unknown type: '%s'\n", typename);
4215 GOTO(out, rc = -ENODEV);
4218 rc = lu_env_refill((struct lu_env *)env);
4220 CERROR("Failure to refill session: '%d'\n", rc);
4226 CERROR("type: '%s'\n", typename);
4227 GOTO(out_type, rc = -EINVAL);
4230 ldt->ldt_obd_type = type;
4231 d = ldt->ldt_ops->ldto_device_alloc(env, ldt, cfg);
4233 CERROR("Cannot allocate device: '%s'\n", typename);
4234 GOTO(out_type, rc = -ENODEV);
4237 LASSERT(child->ld_site);
4238 d->ld_site = child->ld_site;
4241 rc = ldt->ldt_ops->ldto_device_init(env, d, dev, child);
4243 CERROR("can't init device '%s', rc %d\n", typename, rc);
4244 GOTO(out_alloc, rc);
4247 lu_ref_add(&d->ld_reference, "lu-stack", &lu_site_init);
4249 cfs_spin_lock(&d->ld_site->ls_ld_lock);
4250 cfs_list_add_tail(&d->ld_linkage, &d->ld_site->ls_ld_linkage);
4251 cfs_spin_unlock(&d->ld_site->ls_ld_lock);
4255 ldt->ldt_ops->ldto_device_free(env, d);
4258 class_put_type(type);
4263 static int mdt_stack_init(struct lu_env *env,
4264 struct mdt_device *m,
4265 struct lustre_cfg *cfg,
4266 struct lustre_mount_info *lmi)
4268 struct lu_device *d = &m->mdt_md_dev.md_lu_dev;
4269 struct lu_device *tmp;
4270 struct md_device *md;
4271 struct lu_device *child_lu_dev;
4275 /* init the stack */
4276 tmp = mdt_layer_setup(env, LUSTRE_OSD_NAME, d, cfg);
4278 RETURN(PTR_ERR(tmp));
4280 m->mdt_bottom = lu2dt_dev(tmp);
4282 tmp = mdt_layer_setup(env, LUSTRE_MDD_NAME, d, cfg);
4284 GOTO(out, rc = PTR_ERR(tmp));
4289 tmp = mdt_layer_setup(env, LUSTRE_CMM_NAME, d, cfg);
4291 GOTO(out, rc = PTR_ERR(tmp));
4294 /*set mdd upcall device*/
4295 md_upcall_dev_set(md, lu2md_dev(d));
4298 /*set cmm upcall device*/
4299 md_upcall_dev_set(md, &m->mdt_md_dev);
4301 m->mdt_child = lu2md_dev(d);
4303 /* process setup config */
4304 tmp = &m->mdt_md_dev.md_lu_dev;
4305 rc = tmp->ld_ops->ldo_process_config(env, tmp, cfg);
4309 /* initialize local objects */
4310 child_lu_dev = &m->mdt_child->md_lu_dev;
4312 rc = child_lu_dev->ld_ops->ldo_prepare(env,
4313 &m->mdt_md_dev.md_lu_dev,
4316 /* fini from last known good lu_device */
4318 mdt_stack_fini(env, m, d);
4324 * setup CONFIG_ORIG context, used to access local config log.
4325 * this may need to be rewrite as part of llog rewrite for lu-api.
4327 static int mdt_obd_llog_setup(struct obd_device *obd,
4328 struct lustre_sb_info *lsi)
4332 LASSERT(obd->obd_fsops == NULL);
4334 obd->obd_fsops = fsfilt_get_ops(MT_STR(lsi->lsi_ldd));
4335 if (IS_ERR(obd->obd_fsops))
4336 return PTR_ERR(obd->obd_fsops);
4338 rc = fsfilt_setup(obd, lsi->lsi_srv_mnt->mnt_sb);
4340 fsfilt_put_ops(obd->obd_fsops);
4344 OBD_SET_CTXT_MAGIC(&obd->obd_lvfs_ctxt);
4345 obd->obd_lvfs_ctxt.pwdmnt = lsi->lsi_srv_mnt;
4346 obd->obd_lvfs_ctxt.pwd = lsi->lsi_srv_mnt->mnt_root;
4347 obd->obd_lvfs_ctxt.fs = get_ds();
4349 rc = llog_setup(obd, &obd->obd_olg, LLOG_CONFIG_ORIG_CTXT, obd,
4350 0, NULL, &llog_lvfs_ops);
4352 CERROR("llog_setup() failed: %d\n", rc);
4353 fsfilt_put_ops(obd->obd_fsops);
4359 static void mdt_obd_llog_cleanup(struct obd_device *obd)
4361 struct llog_ctxt *ctxt;
4363 ctxt = llog_get_context(obd, LLOG_CONFIG_ORIG_CTXT);
4367 if (obd->obd_fsops) {
4368 fsfilt_put_ops(obd->obd_fsops);
4369 obd->obd_fsops = NULL;
4373 static void mdt_fini(const struct lu_env *env, struct mdt_device *m)
4375 struct md_device *next = m->mdt_child;
4376 struct lu_device *d = &m->mdt_md_dev.md_lu_dev;
4377 struct lu_site *ls = d->ld_site;
4378 struct obd_device *obd = mdt2obd_dev(m);
4381 target_recovery_fini(obd);
4383 ping_evictor_stop();
4385 mdt_stop_ptlrpc_service(m);
4386 mdt_llog_ctxt_unclone(env, m, LLOG_CHANGELOG_ORIG_CTXT);
4387 mdt_obd_llog_cleanup(obd);
4388 obd_exports_barrier(obd);
4389 obd_zombie_barrier();
4393 #ifdef HAVE_QUOTA_SUPPORT
4394 next->md_ops->mdo_quota.mqo_cleanup(env, next);
4396 lut_fini(env, &m->mdt_lut);
4397 mdt_fs_cleanup(env, m);
4398 upcall_cache_cleanup(m->mdt_identity_cache);
4399 m->mdt_identity_cache = NULL;
4401 if (m->mdt_namespace != NULL) {
4402 ldlm_namespace_free(m->mdt_namespace, NULL,
4403 d->ld_obd->obd_force);
4404 d->ld_obd->obd_namespace = m->mdt_namespace = NULL;
4407 cfs_free_nidlist(&m->mdt_nosquash_nids);
4408 if (m->mdt_nosquash_str) {
4409 OBD_FREE(m->mdt_nosquash_str, m->mdt_nosquash_strlen);
4410 m->mdt_nosquash_str = NULL;
4411 m->mdt_nosquash_strlen = 0;
4414 mdt_seq_fini(env, m);
4415 mdt_seq_fini_cli(m);
4416 mdt_fld_fini(env, m);
4417 sptlrpc_rule_set_free(&m->mdt_sptlrpc_rset);
4419 next->md_ops->mdo_init_capa_ctxt(env, next, 0, 0, 0, NULL);
4420 cfs_timer_disarm(&m->mdt_ck_timer);
4421 mdt_ck_thread_stop(m);
4426 mdt_stack_fini(env, m, md2lu_dev(m->mdt_child));
4429 struct md_site *mite;
4432 mite = lu_site2md(ls);
4436 LASSERT(cfs_atomic_read(&d->ld_ref) == 0);
4441 static int mdt_adapt_sptlrpc_conf(struct obd_device *obd, int initial)
4443 struct mdt_device *m = mdt_dev(obd->obd_lu_dev);
4444 struct sptlrpc_rule_set tmp_rset;
4447 sptlrpc_rule_set_init(&tmp_rset);
4448 rc = sptlrpc_conf_target_get_rules(obd, &tmp_rset, initial);
4450 CERROR("mdt %s: failed get sptlrpc rules: %d\n",
4455 sptlrpc_target_update_exp_flavor(obd, &tmp_rset);
4457 cfs_write_lock(&m->mdt_sptlrpc_lock);
4458 sptlrpc_rule_set_free(&m->mdt_sptlrpc_rset);
4459 m->mdt_sptlrpc_rset = tmp_rset;
4460 cfs_write_unlock(&m->mdt_sptlrpc_lock);
4465 int mdt_postrecov(const struct lu_env *, struct mdt_device *);
4467 static int mdt_init0(const struct lu_env *env, struct mdt_device *m,
4468 struct lu_device_type *ldt, struct lustre_cfg *cfg)
4470 struct mdt_thread_info *info;
4471 struct obd_device *obd;
4472 const char *dev = lustre_cfg_string(cfg, 0);
4473 const char *num = lustre_cfg_string(cfg, 2);
4474 struct lustre_mount_info *lmi = NULL;
4475 struct lustre_sb_info *lsi;
4476 struct lustre_disk_data *ldd;
4478 struct md_site *mite;
4479 const char *identity_upcall = "NONE";
4480 struct md_device *next;
4486 md_device_init(&m->mdt_md_dev, ldt);
4488 * Environment (env) might be missing mdt_thread_key values at that
4489 * point, if device is allocated when mdt_thread_key is in QUIESCENT
4492 * Usually device allocation path doesn't use module key values, but
4493 * mdt has to do a lot of work here, so allocate key value.
4495 rc = lu_env_refill((struct lu_env *)env);
4499 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
4500 LASSERT(info != NULL);
4502 obd = class_name2obd(dev);
4503 LASSERT(obd != NULL);
4505 m->mdt_max_mdsize = MAX_MD_SIZE;
4506 m->mdt_max_cookiesize = sizeof(struct llog_cookie);
4507 m->mdt_som_conf = 0;
4509 m->mdt_opts.mo_cos = MDT_COS_DEFAULT;
4510 lmi = server_get_mount_2(dev);
4512 CERROR("Cannot get mount info for %s!\n", dev);
4515 lsi = s2lsi(lmi->lmi_sb);
4516 /* CMD is supported only in IAM mode */
4519 node_id = simple_strtol(num, NULL, 10);
4520 if (!(ldd->ldd_flags & LDD_F_IAM_DIR) && node_id) {
4521 CERROR("CMD Operation not allowed in IOP mode\n");
4522 GOTO(err_lmi, rc = -EINVAL);
4525 obd->u.obt.obt_magic = OBT_MAGIC;
4528 cfs_rwlock_init(&m->mdt_sptlrpc_lock);
4529 sptlrpc_rule_set_init(&m->mdt_sptlrpc_rset);
4531 cfs_spin_lock_init(&m->mdt_ioepoch_lock);
4532 m->mdt_opts.mo_compat_resname = 0;
4533 m->mdt_opts.mo_mds_capa = 1;
4534 m->mdt_opts.mo_oss_capa = 1;
4535 m->mdt_capa_timeout = CAPA_TIMEOUT;
4536 m->mdt_capa_alg = CAPA_HMAC_ALG_SHA1;
4537 m->mdt_ck_timeout = CAPA_KEY_TIMEOUT;
4538 m->mdt_squash_uid = 0;
4539 m->mdt_squash_gid = 0;
4540 CFS_INIT_LIST_HEAD(&m->mdt_nosquash_nids);
4541 m->mdt_nosquash_str = NULL;
4542 m->mdt_nosquash_strlen = 0;
4543 cfs_init_rwsem(&m->mdt_squash_sem);
4545 OBD_ALLOC_PTR(mite);
4547 GOTO(err_lmi, rc = -ENOMEM);
4551 m->mdt_md_dev.md_lu_dev.ld_ops = &mdt_lu_ops;
4552 m->mdt_md_dev.md_lu_dev.ld_obd = obd;
4553 /* set this lu_device to obd, because error handling need it */
4554 obd->obd_lu_dev = &m->mdt_md_dev.md_lu_dev;
4556 rc = lu_site_init(s, &m->mdt_md_dev.md_lu_dev);
4558 CERROR("Can't init lu_site, rc %d\n", rc);
4559 GOTO(err_free_site, rc);
4562 /* set server index */
4563 lu_site2md(s)->ms_node_id = node_id;
4565 /* failover is the default
4566 * FIXME: we do not failout mds0/mgs, which may cause some problems.
4567 * assumed whose ms_node_id == 0 XXX
4569 obd->obd_replayable = 1;
4570 /* No connection accepted until configurations will finish */
4571 obd->obd_no_conn = 1;
4573 if (cfg->lcfg_bufcount > 4 && LUSTRE_CFG_BUFLEN(cfg, 4) > 0) {
4574 char *str = lustre_cfg_string(cfg, 4);
4575 if (strchr(str, 'n')) {
4576 CWARN("%s: recovery disabled\n", obd->obd_name);
4577 obd->obd_replayable = 0;
4581 /* init the stack */
4582 rc = mdt_stack_init((struct lu_env *)env, m, cfg, lmi);
4584 CERROR("Can't init device stack, rc %d\n", rc);
4585 GOTO(err_lu_site, rc);
4588 rc = lut_init(env, &m->mdt_lut, obd, m->mdt_bottom);
4590 GOTO(err_fini_stack, rc);
4592 rc = mdt_fld_init(env, obd->obd_name, m);
4596 rc = mdt_seq_init(env, obd->obd_name, m);
4598 GOTO(err_fini_fld, rc);
4600 snprintf(info->mti_u.ns_name, sizeof info->mti_u.ns_name,
4601 LUSTRE_MDT_NAME"-%p", m);
4602 m->mdt_namespace = ldlm_namespace_new(obd, info->mti_u.ns_name,
4603 LDLM_NAMESPACE_SERVER,
4604 LDLM_NAMESPACE_GREEDY,
4606 if (m->mdt_namespace == NULL)
4607 GOTO(err_fini_seq, rc = -ENOMEM);
4609 ldlm_register_intent(m->mdt_namespace, mdt_intent_policy);
4610 /* set obd_namespace for compatibility with old code */
4611 obd->obd_namespace = m->mdt_namespace;
4613 cfs_timer_init(&m->mdt_ck_timer, mdt_ck_timer_callback, m);
4615 rc = mdt_ck_thread_start(m);
4617 GOTO(err_free_ns, rc);
4619 rc = mdt_fs_setup(env, m, obd, lsi);
4623 rc = mdt_obd_llog_setup(obd, lsi);
4625 GOTO(err_fs_cleanup, rc);
4627 rc = mdt_llog_ctxt_clone(env, m, LLOG_CHANGELOG_ORIG_CTXT);
4629 GOTO(err_llog_cleanup, rc);
4631 mdt_adapt_sptlrpc_conf(obd, 1);
4633 next = m->mdt_child;
4634 #ifdef HAVE_QUOTA_SUPPORT
4635 rc = next->md_ops->mdo_quota.mqo_setup(env, next, lmi->lmi_mnt);
4637 GOTO(err_llog_cleanup, rc);
4640 server_put_mount_2(dev, lmi->lmi_mnt);
4643 rc = next->md_ops->mdo_iocontrol(env, next, OBD_IOC_GET_MNTOPT, 0,
4646 GOTO(err_quota, rc);
4648 if (mntopts & MNTOPT_USERXATTR)
4649 m->mdt_opts.mo_user_xattr = 1;
4651 m->mdt_opts.mo_user_xattr = 0;
4653 if (mntopts & MNTOPT_ACL)
4654 m->mdt_opts.mo_acl = 1;
4656 m->mdt_opts.mo_acl = 0;
4658 /* XXX: to support suppgid for ACL, we enable identity_upcall
4659 * by default, otherwise, maybe got unexpected -EACCESS. */
4660 if (m->mdt_opts.mo_acl)
4661 identity_upcall = MDT_IDENTITY_UPCALL_PATH;
4663 m->mdt_identity_cache = upcall_cache_init(obd->obd_name,identity_upcall,
4664 &mdt_identity_upcall_cache_ops);
4665 if (IS_ERR(m->mdt_identity_cache)) {
4666 rc = PTR_ERR(m->mdt_identity_cache);
4667 m->mdt_identity_cache = NULL;
4668 GOTO(err_quota, rc);
4671 target_recovery_init(&m->mdt_lut, mdt_recovery_handle);
4673 rc = mdt_procfs_init(m, dev);
4675 CERROR("Can't init MDT lprocfs, rc %d\n", rc);
4676 GOTO(err_recovery, rc);
4679 rc = mdt_start_ptlrpc_service(m);
4681 GOTO(err_procfs, rc);
4683 ping_evictor_start();
4685 rc = lu_site_init_finish(s);
4687 GOTO(err_stop_service, rc);
4689 if (obd->obd_recovering == 0)
4690 mdt_postrecov(env, m);
4692 mdt_init_capa_ctxt(env, m);
4694 /* Reduce the initial timeout on an MDS because it doesn't need such
4695 * a long timeout as an OST does. Adaptive timeouts will adjust this
4696 * value appropriately. */
4697 if (ldlm_timeout == LDLM_TIMEOUT_DEFAULT)
4698 ldlm_timeout = MDS_LDLM_TIMEOUT_DEFAULT;
4703 ping_evictor_stop();
4704 mdt_stop_ptlrpc_service(m);
4708 target_recovery_fini(obd);
4709 upcall_cache_cleanup(m->mdt_identity_cache);
4710 m->mdt_identity_cache = NULL;
4712 #ifdef HAVE_QUOTA_SUPPORT
4713 next->md_ops->mdo_quota.mqo_cleanup(env, next);
4716 mdt_llog_ctxt_unclone(env, m, LLOG_CHANGELOG_ORIG_CTXT);
4717 mdt_obd_llog_cleanup(obd);
4719 mdt_fs_cleanup(env, m);
4721 cfs_timer_disarm(&m->mdt_ck_timer);
4722 mdt_ck_thread_stop(m);
4724 ldlm_namespace_free(m->mdt_namespace, NULL, 0);
4725 obd->obd_namespace = m->mdt_namespace = NULL;
4727 mdt_seq_fini(env, m);
4729 mdt_fld_fini(env, m);
4731 lut_fini(env, &m->mdt_lut);
4733 mdt_stack_fini(env, m, md2lu_dev(m->mdt_child));
4740 server_put_mount_2(dev, lmi->lmi_mnt);
4744 /* used by MGS to process specific configurations */
4745 static int mdt_process_config(const struct lu_env *env,
4746 struct lu_device *d, struct lustre_cfg *cfg)
4748 struct mdt_device *m = mdt_dev(d);
4749 struct md_device *md_next = m->mdt_child;
4750 struct lu_device *next = md2lu_dev(md_next);
4754 switch (cfg->lcfg_command) {
4756 struct lprocfs_static_vars lvars;
4757 struct obd_device *obd = d->ld_obd;
4760 * For interoperability between 1.8 and 2.0,
4763 /* Skip old "mdt.group_upcall" param. */
4764 char *param = lustre_cfg_string(cfg, 1);
4765 if (param && !strncmp("mdt.group_upcall", param, 16)) {
4766 CWARN("For 1.8 interoperability, skip this"
4767 " mdt.group_upcall. It is obsolete\n");
4770 /* Rename old "mdt.quota_type" to "mdd.quota_type. */
4771 if (param && !strncmp("mdt.quota_type", param, 14)) {
4772 CWARN("Found old param mdt.quota_type, changed"
4773 " it to mdd.quota_type.\n");
4778 lprocfs_mdt_init_vars(&lvars);
4779 rc = class_process_proc_param(PARAM_MDT, lvars.obd_vars,
4781 if (rc > 0 || rc == -ENOSYS)
4782 /* we don't understand; pass it on */
4783 rc = next->ld_ops->ldo_process_config(env, next, cfg);
4788 * Add mdc hook to get first MDT uuid and connect it to
4789 * ls->controller to use for seq manager.
4791 rc = next->ld_ops->ldo_process_config(env, next, cfg);
4793 CERROR("Can't add mdc, rc %d\n", rc);
4795 rc = mdt_seq_init_cli(env, mdt_dev(d), cfg);
4798 /* others are passed further */
4799 rc = next->ld_ops->ldo_process_config(env, next, cfg);
4805 static struct lu_object *mdt_object_alloc(const struct lu_env *env,
4806 const struct lu_object_header *hdr,
4807 struct lu_device *d)
4809 struct mdt_object *mo;
4815 struct lu_object *o;
4816 struct lu_object_header *h;
4818 o = &mo->mot_obj.mo_lu;
4819 h = &mo->mot_header;
4820 lu_object_header_init(h);
4821 lu_object_init(o, h, d);
4822 lu_object_add_top(h, o);
4823 o->lo_ops = &mdt_obj_ops;
4824 cfs_sema_init(&mo->mot_ioepoch_sem, 1);
4825 cfs_sema_init(&mo->mot_lov_sem, 1);
4831 static int mdt_object_init(const struct lu_env *env, struct lu_object *o,
4832 const struct lu_object_conf *unused)
4834 struct mdt_device *d = mdt_dev(o->lo_dev);
4835 struct lu_device *under;
4836 struct lu_object *below;
4840 CDEBUG(D_INFO, "object init, fid = "DFID"\n",
4841 PFID(lu_object_fid(o)));
4843 under = &d->mdt_child->md_lu_dev;
4844 below = under->ld_ops->ldo_object_alloc(env, o->lo_header, under);
4845 if (below != NULL) {
4846 lu_object_add(o, below);
4853 static void mdt_object_free(const struct lu_env *env, struct lu_object *o)
4855 struct mdt_object *mo = mdt_obj(o);
4856 struct lu_object_header *h;
4860 CDEBUG(D_INFO, "object free, fid = "DFID"\n",
4861 PFID(lu_object_fid(o)));
4864 lu_object_header_fini(h);
4869 static int mdt_object_print(const struct lu_env *env, void *cookie,
4870 lu_printer_t p, const struct lu_object *o)
4872 struct mdt_object *mdto = mdt_obj((struct lu_object *)o);
4873 return (*p)(env, cookie, LUSTRE_MDT_NAME"-object@%p(ioepoch="LPU64" "
4874 "flags="LPX64", epochcount=%d, writecount=%d)",
4875 mdto, mdto->mot_ioepoch, mdto->mot_flags,
4876 mdto->mot_ioepoch_count, mdto->mot_writecount);
4879 static const struct lu_device_operations mdt_lu_ops = {
4880 .ldo_object_alloc = mdt_object_alloc,
4881 .ldo_process_config = mdt_process_config,
4884 static const struct lu_object_operations mdt_obj_ops = {
4885 .loo_object_init = mdt_object_init,
4886 .loo_object_free = mdt_object_free,
4887 .loo_object_print = mdt_object_print
4890 static int mdt_obd_set_info_async(struct obd_export *exp,
4891 __u32 keylen, void *key,
4892 __u32 vallen, void *val,
4893 struct ptlrpc_request_set *set)
4895 struct obd_device *obd = exp->exp_obd;
4901 if (KEY_IS(KEY_SPTLRPC_CONF)) {
4902 rc = mdt_adapt_sptlrpc_conf(obd, 0);
4909 /* mds_connect_internal */
4910 static int mdt_connect_internal(struct obd_export *exp,
4911 struct mdt_device *mdt,
4912 struct obd_connect_data *data)
4915 data->ocd_connect_flags &= MDT_CONNECT_SUPPORTED;
4916 data->ocd_ibits_known &= MDS_INODELOCK_FULL;
4918 /* If no known bits (which should not happen, probably,
4919 as everybody should support LOOKUP and UPDATE bits at least)
4920 revert to compat mode with plain locks. */
4921 if (!data->ocd_ibits_known &&
4922 data->ocd_connect_flags & OBD_CONNECT_IBITS)
4923 data->ocd_connect_flags &= ~OBD_CONNECT_IBITS;
4925 if (!mdt->mdt_opts.mo_acl)
4926 data->ocd_connect_flags &= ~OBD_CONNECT_ACL;
4928 if (!mdt->mdt_opts.mo_user_xattr)
4929 data->ocd_connect_flags &= ~OBD_CONNECT_XATTR;
4931 if (!mdt->mdt_som_conf)
4932 data->ocd_connect_flags &= ~OBD_CONNECT_SOM;
4934 if (data->ocd_connect_flags & OBD_CONNECT_BRW_SIZE) {
4935 data->ocd_brw_size = min(data->ocd_brw_size,
4936 (__u32)(PTLRPC_MAX_BRW_PAGES << CFS_PAGE_SHIFT));
4937 if (data->ocd_brw_size == 0) {
4938 CERROR("%s: cli %s/%p ocd_connect_flags: "LPX64
4939 " ocd_version: %x ocd_grant: %d "
4940 "ocd_index: %u ocd_brw_size is "
4941 "unexpectedly zero, network data "
4942 "corruption? Refusing connection of this"
4944 exp->exp_obd->obd_name,
4945 exp->exp_client_uuid.uuid,
4946 exp, data->ocd_connect_flags, data->ocd_version,
4947 data->ocd_grant, data->ocd_index);
4952 cfs_spin_lock(&exp->exp_lock);
4953 exp->exp_connect_flags = data->ocd_connect_flags;
4954 cfs_spin_unlock(&exp->exp_lock);
4955 data->ocd_version = LUSTRE_VERSION_CODE;
4956 exp->exp_mdt_data.med_ibits_known = data->ocd_ibits_known;
4960 if (mdt->mdt_opts.mo_acl &&
4961 ((exp->exp_connect_flags & OBD_CONNECT_ACL) == 0)) {
4962 CWARN("%s: MDS requires ACL support but client does not\n",
4963 mdt->mdt_md_dev.md_lu_dev.ld_obd->obd_name);
4968 if ((exp->exp_connect_flags & OBD_CONNECT_FID) == 0) {
4969 CWARN("%s: MDS requires FID support, but client not\n",
4970 mdt->mdt_md_dev.md_lu_dev.ld_obd->obd_name);
4974 if (mdt->mdt_som_conf && !exp_connect_som(exp) &&
4975 !(exp->exp_connect_flags & OBD_CONNECT_MDS_MDS)) {
4976 CWARN("%s: MDS has SOM enabled, but client does not support "
4977 "it\n", mdt->mdt_md_dev.md_lu_dev.ld_obd->obd_name);
4984 static int mdt_connect_check_sptlrpc(struct mdt_device *mdt,
4985 struct obd_export *exp,
4986 struct ptlrpc_request *req)
4988 struct sptlrpc_flavor flvr;
4991 if (exp->exp_flvr.sf_rpc == SPTLRPC_FLVR_INVALID) {
4992 cfs_read_lock(&mdt->mdt_sptlrpc_lock);
4993 sptlrpc_target_choose_flavor(&mdt->mdt_sptlrpc_rset,
4997 cfs_read_unlock(&mdt->mdt_sptlrpc_lock);
4999 cfs_spin_lock(&exp->exp_lock);
5001 exp->exp_sp_peer = req->rq_sp_from;
5002 exp->exp_flvr = flvr;
5004 if (exp->exp_flvr.sf_rpc != SPTLRPC_FLVR_ANY &&
5005 exp->exp_flvr.sf_rpc != req->rq_flvr.sf_rpc) {
5006 CERROR("unauthorized rpc flavor %x from %s, "
5007 "expect %x\n", req->rq_flvr.sf_rpc,
5008 libcfs_nid2str(req->rq_peer.nid),
5009 exp->exp_flvr.sf_rpc);
5013 cfs_spin_unlock(&exp->exp_lock);
5015 if (exp->exp_sp_peer != req->rq_sp_from) {
5016 CERROR("RPC source %s doesn't match %s\n",
5017 sptlrpc_part2name(req->rq_sp_from),
5018 sptlrpc_part2name(exp->exp_sp_peer));
5021 rc = sptlrpc_target_export_check(exp, req);
5028 /* mds_connect copy */
5029 static int mdt_obd_connect(const struct lu_env *env,
5030 struct obd_export **exp, struct obd_device *obd,
5031 struct obd_uuid *cluuid,
5032 struct obd_connect_data *data,
5035 struct mdt_thread_info *info;
5036 struct obd_export *lexp;
5037 struct lustre_handle conn = { 0 };
5038 struct mdt_device *mdt;
5039 struct ptlrpc_request *req;
5043 LASSERT(env != NULL);
5044 if (!exp || !obd || !cluuid)
5047 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
5048 req = info->mti_pill->rc_req;
5049 mdt = mdt_dev(obd->obd_lu_dev);
5051 rc = class_connect(&conn, obd, cluuid);
5055 lexp = class_conn2export(&conn);
5056 LASSERT(lexp != NULL);
5058 rc = mdt_connect_check_sptlrpc(mdt, lexp, req);
5062 if (OBD_FAIL_CHECK(OBD_FAIL_TGT_RCVG_FLAG))
5063 lustre_msg_add_op_flags(req->rq_repmsg, MSG_CONNECT_RECOVERING);
5065 rc = mdt_connect_internal(lexp, mdt, data);
5067 struct mdt_thread_info *mti;
5068 struct lsd_client_data *lcd = lexp->exp_target_data.ted_lcd;
5070 mti = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
5071 LASSERT(mti != NULL);
5072 mti->mti_exp = lexp;
5073 memcpy(lcd->lcd_uuid, cluuid, sizeof lcd->lcd_uuid);
5074 rc = mdt_client_new(env, mdt);
5076 mdt_export_stats_init(obd, lexp, localdata);
5081 class_disconnect(lexp);
5090 static int mdt_obd_reconnect(const struct lu_env *env,
5091 struct obd_export *exp, struct obd_device *obd,
5092 struct obd_uuid *cluuid,
5093 struct obd_connect_data *data,
5096 struct mdt_thread_info *info;
5097 struct mdt_device *mdt;
5098 struct ptlrpc_request *req;
5102 if (exp == NULL || obd == NULL || cluuid == NULL)
5105 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
5106 req = info->mti_pill->rc_req;
5107 mdt = mdt_dev(obd->obd_lu_dev);
5109 rc = mdt_connect_check_sptlrpc(mdt, exp, req);
5113 rc = mdt_connect_internal(exp, mdt_dev(obd->obd_lu_dev), data);
5115 mdt_export_stats_init(obd, exp, localdata);
5119 static int mdt_export_cleanup(struct obd_export *exp)
5121 struct mdt_export_data *med = &exp->exp_mdt_data;
5122 struct obd_device *obd = exp->exp_obd;
5123 struct mdt_device *mdt;
5124 struct mdt_thread_info *info;
5126 CFS_LIST_HEAD(closing_list);
5127 struct mdt_file_data *mfd, *n;
5131 cfs_spin_lock(&med->med_open_lock);
5132 while (!cfs_list_empty(&med->med_open_head)) {
5133 cfs_list_t *tmp = med->med_open_head.next;
5134 mfd = cfs_list_entry(tmp, struct mdt_file_data, mfd_list);
5136 /* Remove mfd handle so it can't be found again.
5137 * We are consuming the mfd_list reference here. */
5138 class_handle_unhash(&mfd->mfd_handle);
5139 cfs_list_move_tail(&mfd->mfd_list, &closing_list);
5141 cfs_spin_unlock(&med->med_open_lock);
5142 mdt = mdt_dev(obd->obd_lu_dev);
5143 LASSERT(mdt != NULL);
5145 rc = lu_env_init(&env, LCT_MD_THREAD);
5149 info = lu_context_key_get(&env.le_ctx, &mdt_thread_key);
5150 LASSERT(info != NULL);
5151 memset(info, 0, sizeof *info);
5152 info->mti_env = &env;
5153 info->mti_mdt = mdt;
5154 info->mti_exp = exp;
5156 if (!cfs_list_empty(&closing_list)) {
5157 struct md_attr *ma = &info->mti_attr;
5161 lmm_size = mdt->mdt_max_mdsize;
5162 OBD_ALLOC_LARGE(ma->ma_lmm, lmm_size);
5163 if (ma->ma_lmm == NULL)
5164 GOTO(out_lmm, rc = -ENOMEM);
5166 cookie_size = mdt->mdt_max_cookiesize;
5167 OBD_ALLOC_LARGE(ma->ma_cookie, cookie_size);
5168 if (ma->ma_cookie == NULL)
5169 GOTO(out_cookie, rc = -ENOMEM);
5171 /* Close any open files (which may also cause orphan unlinking). */
5172 cfs_list_for_each_entry_safe(mfd, n, &closing_list, mfd_list) {
5173 cfs_list_del_init(&mfd->mfd_list);
5174 memset(&ma->ma_attr, 0, sizeof(ma->ma_attr));
5175 ma->ma_lmm_size = lmm_size;
5176 ma->ma_cookie_size = cookie_size;
5178 /* It is not for setattr, just tell MDD to send
5179 * DESTROY RPC to OSS if needed */
5180 ma->ma_valid = MA_FLAGS;
5181 ma->ma_attr_flags = MDS_CLOSE_CLEANUP;
5182 /* Don't unlink orphan on failover umount, LU-184 */
5183 if (exp->exp_flags & OBD_OPT_FAILOVER)
5184 ma->ma_attr_flags |= MDS_KEEP_ORPHAN;
5185 mdt_mfd_close(info, mfd);
5187 OBD_FREE_LARGE(ma->ma_cookie, cookie_size);
5188 ma->ma_cookie = NULL;
5190 OBD_FREE_LARGE(ma->ma_lmm, lmm_size);
5194 info->mti_mdt = NULL;
5195 /* cleanup client slot early */
5196 /* Do not erase record for recoverable client. */
5197 if (!(exp->exp_flags & OBD_OPT_FAILOVER) || exp->exp_failed)
5198 mdt_client_del(&env, mdt);
5204 static int mdt_obd_disconnect(struct obd_export *exp)
5210 class_export_get(exp);
5212 rc = server_disconnect_export(exp);
5214 CDEBUG(D_IOCTL, "server disconnect error: %d\n", rc);
5216 rc = mdt_export_cleanup(exp);
5217 class_export_put(exp);
5221 /* FIXME: Can we avoid using these two interfaces? */
5222 static int mdt_init_export(struct obd_export *exp)
5224 struct mdt_export_data *med = &exp->exp_mdt_data;
5228 CFS_INIT_LIST_HEAD(&med->med_open_head);
5229 cfs_spin_lock_init(&med->med_open_lock);
5230 cfs_sema_init(&med->med_idmap_sem, 1);
5231 med->med_idmap = NULL;
5232 cfs_spin_lock(&exp->exp_lock);
5233 exp->exp_connecting = 1;
5234 cfs_spin_unlock(&exp->exp_lock);
5236 /* self-export doesn't need client data and ldlm initialization */
5237 if (unlikely(obd_uuid_equals(&exp->exp_obd->obd_uuid,
5238 &exp->exp_client_uuid)))
5241 rc = lut_client_alloc(exp);
5243 rc = ldlm_init_export(exp);
5245 CERROR("%s: Error %d while initializing export\n",
5246 exp->exp_obd->obd_name, rc);
5250 static int mdt_destroy_export(struct obd_export *exp)
5254 if (exp_connect_rmtclient(exp))
5255 mdt_cleanup_idmap(&exp->exp_mdt_data);
5257 target_destroy_export(exp);
5258 /* destroy can be called from failed obd_setup, so
5259 * checking uuid is safer than obd_self_export */
5260 if (unlikely(obd_uuid_equals(&exp->exp_obd->obd_uuid,
5261 &exp->exp_client_uuid)))
5264 ldlm_destroy_export(exp);
5265 lut_client_free(exp);
5267 LASSERT(cfs_list_empty(&exp->exp_outstanding_replies));
5268 LASSERT(cfs_list_empty(&exp->exp_mdt_data.med_open_head));
5273 static void mdt_allow_cli(struct mdt_device *m, unsigned int flag)
5275 if (flag & CONFIG_LOG)
5276 cfs_set_bit(MDT_FL_CFGLOG, &m->mdt_state);
5278 /* also notify active event */
5279 if (flag & CONFIG_SYNC)
5280 cfs_set_bit(MDT_FL_SYNCED, &m->mdt_state);
5282 if (cfs_test_bit(MDT_FL_CFGLOG, &m->mdt_state) &&
5283 cfs_test_bit(MDT_FL_SYNCED, &m->mdt_state)) {
5284 struct obd_device *obd = m->mdt_md_dev.md_lu_dev.ld_obd;
5286 /* Open for clients */
5287 if (obd->obd_no_conn) {
5288 cfs_spin_lock(&obd->obd_dev_lock);
5289 obd->obd_no_conn = 0;
5290 cfs_spin_unlock(&obd->obd_dev_lock);
5295 static int mdt_upcall(const struct lu_env *env, struct md_device *md,
5296 enum md_upcall_event ev, void *data)
5298 struct mdt_device *m = mdt_dev(&md->md_lu_dev);
5299 struct md_device *next = m->mdt_child;
5300 struct mdt_thread_info *mti;
5306 rc = next->md_ops->mdo_maxsize_get(env, next,
5308 &m->mdt_max_cookiesize);
5309 CDEBUG(D_INFO, "get max mdsize %d max cookiesize %d\n",
5310 m->mdt_max_mdsize, m->mdt_max_cookiesize);
5311 mdt_allow_cli(m, CONFIG_SYNC);
5314 m->mdt_lut.lut_obd->u.obt.obt_mount_count;
5317 mti = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
5318 mti->mti_no_need_trans = 1;
5319 CDEBUG(D_INFO, "disable mdt trans for this thread\n");
5322 /* Check that MDT is not yet configured */
5323 LASSERT(!cfs_test_bit(MDT_FL_CFGLOG, &m->mdt_state));
5325 #ifdef HAVE_QUOTA_SUPPORT
5327 if (md->md_lu_dev.ld_obd->obd_recovering == 0 &&
5328 likely(md->md_lu_dev.ld_obd->obd_stopping == 0))
5329 next->md_ops->mdo_quota.mqo_recovery(env, next);
5333 CERROR("invalid event\n");
5340 static int mdt_obd_notify(struct obd_device *obd,
5341 struct obd_device *watched,
5342 enum obd_notify_event ev, void *data)
5344 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
5345 #ifdef HAVE_QUOTA_SUPPORT
5346 struct md_device *next = mdt->mdt_child;
5351 case OBD_NOTIFY_CONFIG:
5352 mdt_allow_cli(mdt, (unsigned long)data);
5354 #ifdef HAVE_QUOTA_SUPPORT
5355 /* quota_type has been processed, we can now handle
5356 * incoming quota requests */
5357 next->md_ops->mdo_quota.mqo_notify(NULL, next);
5361 CDEBUG(D_INFO, "Unhandled notification %#x\n", ev);
5366 static int mdt_rpc_fid2path(struct mdt_thread_info *info, void *key,
5367 void *val, int vallen)
5369 struct mdt_device *mdt = mdt_dev(info->mti_exp->exp_obd->obd_lu_dev);
5370 struct getinfo_fid2path *fpout, *fpin;
5373 fpin = key + cfs_size_round(sizeof(KEY_FID2PATH));
5376 if (ptlrpc_req_need_swab(info->mti_pill->rc_req))
5377 lustre_swab_fid2path(fpin);
5379 memcpy(fpout, fpin, sizeof(*fpin));
5380 if (fpout->gf_pathlen != vallen - sizeof(*fpin))
5383 rc = mdt_fid2path(info->mti_env, mdt, fpout);
5387 static int mdt_fid2path(const struct lu_env *env, struct mdt_device *mdt,
5388 struct getinfo_fid2path *fp)
5390 struct mdt_object *obj;
5394 CDEBUG(D_IOCTL, "path get "DFID" from "LPU64" #%d\n",
5395 PFID(&fp->gf_fid), fp->gf_recno, fp->gf_linkno);
5397 if (!fid_is_sane(&fp->gf_fid))
5400 obj = mdt_object_find(env, mdt, &fp->gf_fid);
5401 if (obj == NULL || IS_ERR(obj)) {
5402 CDEBUG(D_IOCTL, "no object "DFID": %ld\n", PFID(&fp->gf_fid),
5407 rc = lu_object_exists(&obj->mot_obj.mo_lu);
5413 mdt_object_put(env, obj);
5414 CDEBUG(D_IOCTL, "nonlocal object "DFID": %d\n",
5415 PFID(&fp->gf_fid), rc);
5419 rc = mo_path(env, md_object_next(&obj->mot_obj), fp->gf_path,
5420 fp->gf_pathlen, &fp->gf_recno, &fp->gf_linkno);
5421 mdt_object_put(env, obj);
5426 static int mdt_get_info(struct mdt_thread_info *info)
5428 struct ptlrpc_request *req = mdt_info_req(info);
5436 key = req_capsule_client_get(info->mti_pill, &RMF_GETINFO_KEY);
5438 CDEBUG(D_IOCTL, "No GETINFO key");
5441 keylen = req_capsule_get_size(info->mti_pill, &RMF_GETINFO_KEY,
5444 vallen = req_capsule_client_get(info->mti_pill, &RMF_GETINFO_VALLEN);
5445 if (vallen == NULL) {
5446 CDEBUG(D_IOCTL, "Unable to get RMF_GETINFO_VALLEN buffer");
5450 req_capsule_set_size(info->mti_pill, &RMF_GETINFO_VAL, RCL_SERVER,
5452 rc = req_capsule_server_pack(info->mti_pill);
5453 valout = req_capsule_server_get(info->mti_pill, &RMF_GETINFO_VAL);
5454 if (valout == NULL) {
5455 CDEBUG(D_IOCTL, "Unable to get get-info RPC out buffer");
5459 if (KEY_IS(KEY_FID2PATH))
5460 rc = mdt_rpc_fid2path(info, key, valout, *vallen);
5464 lustre_msg_set_status(req->rq_repmsg, rc);
5469 /* Pass the ioc down */
5470 static int mdt_ioc_child(struct lu_env *env, struct mdt_device *mdt,
5471 unsigned int cmd, int len, void *data)
5473 struct lu_context ioctl_session;
5474 struct md_device *next = mdt->mdt_child;
5478 rc = lu_context_init(&ioctl_session, LCT_SESSION);
5481 ioctl_session.lc_thread = (struct ptlrpc_thread *)cfs_current();
5482 lu_context_enter(&ioctl_session);
5483 env->le_ses = &ioctl_session;
5485 LASSERT(next->md_ops->mdo_iocontrol);
5486 rc = next->md_ops->mdo_iocontrol(env, next, cmd, len, data);
5488 lu_context_exit(&ioctl_session);
5489 lu_context_fini(&ioctl_session);
5493 static int mdt_ioc_version_get(struct mdt_thread_info *mti, void *karg)
5495 struct obd_ioctl_data *data = karg;
5496 struct lu_fid *fid = (struct lu_fid *)data->ioc_inlbuf1;
5498 struct mdt_object *obj;
5499 struct mdt_lock_handle *lh;
5503 CDEBUG(D_IOCTL, "getting version for "DFID"\n", PFID(fid));
5504 if (!fid_is_sane(fid))
5507 lh = &mti->mti_lh[MDT_LH_PARENT];
5508 mdt_lock_reg_init(lh, LCK_CR);
5510 obj = mdt_object_find_lock(mti, fid, lh, MDS_INODELOCK_UPDATE);
5512 RETURN(PTR_ERR(obj));
5514 rc = mdt_object_exists(obj);
5518 * before calling version get the correct MDS should be
5519 * fid, this is error to find remote object here
5521 CERROR("nonlocal object "DFID"\n", PFID(fid));
5522 } else if (rc == 0) {
5523 *(__u64 *)data->ioc_inlbuf2 = ENOENT_VERSION;
5526 version = dt_version_get(mti->mti_env, mdt_obj2dt(obj));
5527 *(__u64 *)data->ioc_inlbuf2 = version;
5530 mdt_object_unlock_put(mti, obj, lh, 1);
5534 /* ioctls on obd dev */
5535 static int mdt_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
5536 void *karg, void *uarg)
5539 struct obd_device *obd = exp->exp_obd;
5540 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
5541 struct dt_device *dt = mdt->mdt_bottom;
5545 CDEBUG(D_IOCTL, "handling ioctl cmd %#x\n", cmd);
5546 rc = lu_env_init(&env, LCT_MD_THREAD);
5552 rc = mdt_device_sync(&env, mdt);
5554 case OBD_IOC_SET_READONLY:
5555 dt->dd_ops->dt_ro(&env, dt);
5557 case OBD_IOC_ABORT_RECOVERY:
5558 CERROR("Aborting recovery for device %s\n", obd->obd_name);
5559 target_stop_recovery_thread(obd);
5562 case OBD_IOC_CHANGELOG_REG:
5563 case OBD_IOC_CHANGELOG_DEREG:
5564 case OBD_IOC_CHANGELOG_CLEAR:
5565 rc = mdt_ioc_child(&env, mdt, cmd, len, karg);
5567 case OBD_IOC_GET_OBJ_VERSION: {
5568 struct mdt_thread_info *mti;
5569 mti = lu_context_key_get(&env.le_ctx, &mdt_thread_key);
5570 memset(mti, 0, sizeof *mti);
5571 mti->mti_env = &env;
5575 rc = mdt_ioc_version_get(mti, karg);
5579 CERROR("Not supported cmd = %d for device %s\n",
5580 cmd, obd->obd_name);
5588 int mdt_postrecov(const struct lu_env *env, struct mdt_device *mdt)
5590 struct lu_device *ld = md2lu_dev(mdt->mdt_child);
5591 #ifdef HAVE_QUOTA_SUPPORT
5592 struct obd_device *obd = mdt2obd_dev(mdt);
5593 struct md_device *next = mdt->mdt_child;
5598 rc = ld->ld_ops->ldo_recovery_complete(env, ld);
5599 #ifdef HAVE_QUOTA_SUPPORT
5600 if (likely(obd->obd_stopping == 0))
5601 next->md_ops->mdo_quota.mqo_recovery(env, next);
5606 int mdt_obd_postrecov(struct obd_device *obd)
5611 rc = lu_env_init(&env, LCT_MD_THREAD);
5614 rc = mdt_postrecov(&env, mdt_dev(obd->obd_lu_dev));
5620 * Send a copytool req to a client
5621 * Note this sends a request RPC from a server (MDT) to a client (MDC),
5622 * backwards of normal comms.
5624 int mdt_hsm_copytool_send(struct obd_export *exp)
5627 struct hsm_action_list *hal;
5628 struct hsm_action_item *hai;
5632 CWARN("%s: writing to mdc at %s\n", exp->exp_obd->obd_name,
5633 libcfs_nid2str(exp->exp_connection->c_peer.nid));
5635 len = sizeof(*lh) + sizeof(*hal) + MTI_NAME_MAXLEN +
5636 /* for mockup below */ 2 * cfs_size_round(sizeof(*hai));
5641 lh->kuc_magic = KUC_MAGIC;
5642 lh->kuc_transport = KUC_TRANSPORT_HSM;
5643 lh->kuc_msgtype = HMT_ACTION_LIST;
5644 lh->kuc_msglen = len;
5646 hal = (struct hsm_action_list *)(lh + 1);
5647 hal->hal_version = HAL_VERSION;
5648 hal->hal_archive_num = 1;
5649 obd_uuid2fsname(hal->hal_fsname, exp->exp_obd->obd_name,
5652 /* mock up an action list */
5654 hai = hai_zero(hal);
5655 hai->hai_action = HSMA_ARCHIVE;
5656 hai->hai_fid.f_oid = 0xA00A;
5657 hai->hai_len = sizeof(*hai);
5658 hai = hai_next(hai);
5659 hai->hai_action = HSMA_RESTORE;
5660 hai->hai_fid.f_oid = 0xB00B;
5661 hai->hai_len = sizeof(*hai);
5663 /* Uses the ldlm reverse import; this rpc will be seen by
5664 the ldlm_callback_handler */
5665 rc = do_set_info_async(exp->exp_imp_reverse,
5666 LDLM_SET_INFO, LUSTRE_OBD_VERSION,
5667 sizeof(KEY_HSM_COPYTOOL_SEND),
5668 KEY_HSM_COPYTOOL_SEND,
5676 static struct obd_ops mdt_obd_device_ops = {
5677 .o_owner = THIS_MODULE,
5678 .o_set_info_async = mdt_obd_set_info_async,
5679 .o_connect = mdt_obd_connect,
5680 .o_reconnect = mdt_obd_reconnect,
5681 .o_disconnect = mdt_obd_disconnect,
5682 .o_init_export = mdt_init_export,
5683 .o_destroy_export = mdt_destroy_export,
5684 .o_iocontrol = mdt_iocontrol,
5685 .o_postrecov = mdt_obd_postrecov,
5686 .o_notify = mdt_obd_notify
5689 static struct lu_device* mdt_device_fini(const struct lu_env *env,
5690 struct lu_device *d)
5692 struct mdt_device *m = mdt_dev(d);
5699 static struct lu_device *mdt_device_free(const struct lu_env *env,
5700 struct lu_device *d)
5702 struct mdt_device *m = mdt_dev(d);
5705 md_device_fini(&m->mdt_md_dev);
5710 static struct lu_device *mdt_device_alloc(const struct lu_env *env,
5711 struct lu_device_type *t,
5712 struct lustre_cfg *cfg)
5714 struct lu_device *l;
5715 struct mdt_device *m;
5721 l = &m->mdt_md_dev.md_lu_dev;
5722 rc = mdt_init0(env, m, t, cfg);
5724 mdt_device_free(env, l);
5728 md_upcall_init(&m->mdt_md_dev, mdt_upcall);
5730 l = ERR_PTR(-ENOMEM);
5734 /* context key constructor/destructor: mdt_key_init, mdt_key_fini */
5735 LU_KEY_INIT_FINI(mdt, struct mdt_thread_info);
5737 /* context key: mdt_thread_key */
5738 LU_CONTEXT_KEY_DEFINE(mdt, LCT_MD_THREAD);
5740 struct md_ucred *mdt_ucred(const struct mdt_thread_info *info)
5742 return md_ucred(info->mti_env);
5746 * Enable/disable COS (Commit On Sharing).
5748 * Set/Clear the COS flag in mdt options.
5750 * \param mdt mdt device
5751 * \param val 0 disables COS, other values enable COS
5753 void mdt_enable_cos(struct mdt_device *mdt, int val)
5758 mdt->mdt_opts.mo_cos = !!val;
5759 rc = lu_env_init(&env, LCT_MD_THREAD);
5760 if (unlikely(rc != 0)) {
5761 CWARN("lu_env initialization failed with rc = %d,"
5762 "cannot sync\n", rc);
5765 mdt_device_sync(&env, mdt);
5770 * Check COS (Commit On Sharing) status.
5772 * Return COS flag status.
5774 * \param mdt mdt device
5776 int mdt_cos_is_enabled(struct mdt_device *mdt)
5778 return mdt->mdt_opts.mo_cos != 0;
5781 /* type constructor/destructor: mdt_type_init, mdt_type_fini */
5782 LU_TYPE_INIT_FINI(mdt, &mdt_thread_key);
5784 static struct lu_device_type_operations mdt_device_type_ops = {
5785 .ldto_init = mdt_type_init,
5786 .ldto_fini = mdt_type_fini,
5788 .ldto_start = mdt_type_start,
5789 .ldto_stop = mdt_type_stop,
5791 .ldto_device_alloc = mdt_device_alloc,
5792 .ldto_device_free = mdt_device_free,
5793 .ldto_device_fini = mdt_device_fini
5796 static struct lu_device_type mdt_device_type = {
5797 .ldt_tags = LU_DEVICE_MD,
5798 .ldt_name = LUSTRE_MDT_NAME,
5799 .ldt_ops = &mdt_device_type_ops,
5800 .ldt_ctx_tags = LCT_MD_THREAD
5803 static struct lu_local_obj_desc mdt_last_recv = {
5804 .llod_name = LAST_RCVD,
5805 .llod_oid = MDT_LAST_RECV_OID,
5809 static int __init mdt_mod_init(void)
5811 struct lprocfs_static_vars lvars;
5814 llo_local_obj_register(&mdt_last_recv);
5816 if (mdt_num_threads > 0) {
5817 if (mdt_num_threads > MDT_MAX_THREADS)
5818 mdt_num_threads = MDT_MAX_THREADS;
5819 if (mdt_num_threads < MDT_MIN_THREADS)
5820 mdt_num_threads = MDT_MIN_THREADS;
5821 mdt_max_threads = mdt_min_threads = mdt_num_threads;
5823 mdt_max_threads = MDT_MAX_THREADS;
5824 mdt_min_threads = MDT_MIN_THREADS;
5827 lprocfs_mdt_init_vars(&lvars);
5828 rc = class_register_type(&mdt_obd_device_ops, NULL,
5829 lvars.module_vars, LUSTRE_MDT_NAME,
5835 static void __exit mdt_mod_exit(void)
5837 llo_local_obj_unregister(&mdt_last_recv);
5838 class_unregister_type(LUSTRE_MDT_NAME);
5842 #define DEF_HNDL(prefix, base, suffix, flags, opc, fn, fmt) \
5843 [prefix ## _ ## opc - prefix ## _ ## base] = { \
5845 .mh_fail_id = OBD_FAIL_ ## prefix ## _ ## opc ## suffix, \
5846 .mh_opc = prefix ## _ ## opc, \
5847 .mh_flags = flags, \
5852 #define DEF_MDT_HNDL(flags, name, fn, fmt) \
5853 DEF_HNDL(MDS, GETATTR, _NET, flags, name, fn, fmt)
5855 #define DEF_SEQ_HNDL(flags, name, fn, fmt) \
5856 DEF_HNDL(SEQ, QUERY, _NET, flags, name, fn, fmt)
5858 #define DEF_FLD_HNDL(flags, name, fn, fmt) \
5859 DEF_HNDL(FLD, QUERY, _NET, flags, name, fn, fmt)
5861 * Request with a format known in advance
5863 #define DEF_MDT_HNDL_F(flags, name, fn) \
5864 DEF_HNDL(MDS, GETATTR, _NET, flags, name, fn, &RQF_MDS_ ## name)
5866 #define DEF_SEQ_HNDL_F(flags, name, fn) \
5867 DEF_HNDL(SEQ, QUERY, _NET, flags, name, fn, &RQF_SEQ_ ## name)
5869 #define DEF_FLD_HNDL_F(flags, name, fn) \
5870 DEF_HNDL(FLD, QUERY, _NET, flags, name, fn, &RQF_FLD_ ## name)
5872 * Request with a format we do not yet know
5874 #define DEF_MDT_HNDL_0(flags, name, fn) \
5875 DEF_HNDL(MDS, GETATTR, _NET, flags, name, fn, NULL)
5877 static struct mdt_handler mdt_mds_ops[] = {
5878 DEF_MDT_HNDL_F(0, CONNECT, mdt_connect),
5879 DEF_MDT_HNDL_F(0, DISCONNECT, mdt_disconnect),
5880 DEF_MDT_HNDL (0, SET_INFO, mdt_set_info,
5882 DEF_MDT_HNDL_F(0, GET_INFO, mdt_get_info),
5883 DEF_MDT_HNDL_F(0 |HABEO_REFERO, GETSTATUS, mdt_getstatus),
5884 DEF_MDT_HNDL_F(HABEO_CORPUS, GETATTR, mdt_getattr),
5885 DEF_MDT_HNDL_F(HABEO_CORPUS|HABEO_REFERO, GETATTR_NAME, mdt_getattr_name),
5886 DEF_MDT_HNDL_F(HABEO_CORPUS, GETXATTR, mdt_getxattr),
5887 DEF_MDT_HNDL_F(0 |HABEO_REFERO, STATFS, mdt_statfs),
5888 DEF_MDT_HNDL_F(0 |MUTABOR, REINT, mdt_reint),
5889 DEF_MDT_HNDL_F(HABEO_CORPUS, CLOSE, mdt_close),
5890 DEF_MDT_HNDL_F(HABEO_CORPUS, DONE_WRITING, mdt_done_writing),
5891 DEF_MDT_HNDL_F(0 |HABEO_REFERO, PIN, mdt_pin),
5892 DEF_MDT_HNDL_0(0, SYNC, mdt_sync),
5893 DEF_MDT_HNDL_F(HABEO_CORPUS|HABEO_REFERO, IS_SUBDIR, mdt_is_subdir),
5894 #ifdef HAVE_QUOTA_SUPPORT
5895 DEF_MDT_HNDL_F(0, QUOTACHECK, mdt_quotacheck_handle),
5896 DEF_MDT_HNDL_F(0, QUOTACTL, mdt_quotactl_handle)
5900 #define DEF_OBD_HNDL(flags, name, fn) \
5901 DEF_HNDL(OBD, PING, _NET, flags, name, fn, NULL)
5904 static struct mdt_handler mdt_obd_ops[] = {
5905 DEF_OBD_HNDL(0, PING, mdt_obd_ping),
5906 DEF_OBD_HNDL(0, LOG_CANCEL, mdt_obd_log_cancel),
5907 DEF_OBD_HNDL(0, QC_CALLBACK, mdt_obd_qc_callback)
5910 #define DEF_DLM_HNDL_0(flags, name, fn) \
5911 DEF_HNDL(LDLM, ENQUEUE, , flags, name, fn, NULL)
5912 #define DEF_DLM_HNDL_F(flags, name, fn) \
5913 DEF_HNDL(LDLM, ENQUEUE, , flags, name, fn, &RQF_LDLM_ ## name)
5915 static struct mdt_handler mdt_dlm_ops[] = {
5916 DEF_DLM_HNDL_F(HABEO_CLAVIS, ENQUEUE, mdt_enqueue),
5917 DEF_DLM_HNDL_0(HABEO_CLAVIS, CONVERT, mdt_convert),
5918 DEF_DLM_HNDL_0(0, BL_CALLBACK, mdt_bl_callback),
5919 DEF_DLM_HNDL_0(0, CP_CALLBACK, mdt_cp_callback)
5922 #define DEF_LLOG_HNDL(flags, name, fn) \
5923 DEF_HNDL(LLOG, ORIGIN_HANDLE_CREATE, _NET, flags, name, fn, NULL)
5925 static struct mdt_handler mdt_llog_ops[] = {
5926 DEF_LLOG_HNDL(0, ORIGIN_HANDLE_CREATE, mdt_llog_create),
5927 DEF_LLOG_HNDL(0, ORIGIN_HANDLE_NEXT_BLOCK, mdt_llog_next_block),
5928 DEF_LLOG_HNDL(0, ORIGIN_HANDLE_READ_HEADER, mdt_llog_read_header),
5929 DEF_LLOG_HNDL(0, ORIGIN_HANDLE_WRITE_REC, NULL),
5930 DEF_LLOG_HNDL(0, ORIGIN_HANDLE_CLOSE, NULL),
5931 DEF_LLOG_HNDL(0, ORIGIN_CONNECT, NULL),
5932 DEF_LLOG_HNDL(0, CATINFO, NULL),
5933 DEF_LLOG_HNDL(0, ORIGIN_HANDLE_PREV_BLOCK, mdt_llog_prev_block),
5934 DEF_LLOG_HNDL(0, ORIGIN_HANDLE_DESTROY, mdt_llog_destroy),
5937 #define DEF_SEC_CTX_HNDL(name, fn) \
5938 DEF_HNDL(SEC_CTX, INIT, _NET, 0, name, fn, NULL)
5940 static struct mdt_handler mdt_sec_ctx_ops[] = {
5941 DEF_SEC_CTX_HNDL(INIT, mdt_sec_ctx_handle),
5942 DEF_SEC_CTX_HNDL(INIT_CONT, mdt_sec_ctx_handle),
5943 DEF_SEC_CTX_HNDL(FINI, mdt_sec_ctx_handle)
5946 static struct mdt_opc_slice mdt_regular_handlers[] = {
5948 .mos_opc_start = MDS_GETATTR,
5949 .mos_opc_end = MDS_LAST_OPC,
5950 .mos_hs = mdt_mds_ops
5953 .mos_opc_start = OBD_PING,
5954 .mos_opc_end = OBD_LAST_OPC,
5955 .mos_hs = mdt_obd_ops
5958 .mos_opc_start = LDLM_ENQUEUE,
5959 .mos_opc_end = LDLM_LAST_OPC,
5960 .mos_hs = mdt_dlm_ops
5963 .mos_opc_start = LLOG_ORIGIN_HANDLE_CREATE,
5964 .mos_opc_end = LLOG_LAST_OPC,
5965 .mos_hs = mdt_llog_ops
5968 .mos_opc_start = SEC_CTX_INIT,
5969 .mos_opc_end = SEC_LAST_OPC,
5970 .mos_hs = mdt_sec_ctx_ops
5977 static struct mdt_handler mdt_readpage_ops[] = {
5978 DEF_MDT_HNDL_F(0, CONNECT, mdt_connect),
5979 DEF_MDT_HNDL_F(HABEO_CORPUS|HABEO_REFERO, READPAGE, mdt_readpage),
5980 #ifdef HAVE_SPLIT_SUPPORT
5981 DEF_MDT_HNDL_F(HABEO_CORPUS|HABEO_REFERO, WRITEPAGE, mdt_writepage),
5985 * XXX: this is ugly and should be fixed one day, see mdc_close() for
5986 * detailed comments. --umka
5988 DEF_MDT_HNDL_F(HABEO_CORPUS, CLOSE, mdt_close),
5989 DEF_MDT_HNDL_F(HABEO_CORPUS, DONE_WRITING, mdt_done_writing),
5992 static struct mdt_opc_slice mdt_readpage_handlers[] = {
5994 .mos_opc_start = MDS_GETATTR,
5995 .mos_opc_end = MDS_LAST_OPC,
5996 .mos_hs = mdt_readpage_ops
6003 static struct mdt_handler mdt_xmds_ops[] = {
6004 DEF_MDT_HNDL_F(0, CONNECT, mdt_connect),
6005 DEF_MDT_HNDL_F(HABEO_CORPUS , GETATTR, mdt_getattr),
6006 DEF_MDT_HNDL_F(0 | MUTABOR , REINT, mdt_reint),
6007 DEF_MDT_HNDL_F(HABEO_CORPUS|HABEO_REFERO, IS_SUBDIR, mdt_is_subdir),
6010 static struct mdt_opc_slice mdt_xmds_handlers[] = {
6012 .mos_opc_start = MDS_GETATTR,
6013 .mos_opc_end = MDS_LAST_OPC,
6014 .mos_hs = mdt_xmds_ops
6017 .mos_opc_start = OBD_PING,
6018 .mos_opc_end = OBD_LAST_OPC,
6019 .mos_hs = mdt_obd_ops
6022 .mos_opc_start = SEC_CTX_INIT,
6023 .mos_opc_end = SEC_LAST_OPC,
6024 .mos_hs = mdt_sec_ctx_ops
6031 static struct mdt_handler mdt_seq_ops[] = {
6032 DEF_SEQ_HNDL_F(0, QUERY, (int (*)(struct mdt_thread_info *))seq_query)
6035 static struct mdt_opc_slice mdt_seq_handlers[] = {
6037 .mos_opc_start = SEQ_QUERY,
6038 .mos_opc_end = SEQ_LAST_OPC,
6039 .mos_hs = mdt_seq_ops
6046 static struct mdt_handler mdt_fld_ops[] = {
6047 DEF_FLD_HNDL_F(0, QUERY, (int (*)(struct mdt_thread_info *))fld_query)
6050 static struct mdt_opc_slice mdt_fld_handlers[] = {
6052 .mos_opc_start = FLD_QUERY,
6053 .mos_opc_end = FLD_LAST_OPC,
6054 .mos_hs = mdt_fld_ops
6061 MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");
6062 MODULE_DESCRIPTION("Lustre Meta-data Target ("LUSTRE_MDT_NAME")");
6063 MODULE_LICENSE("GPL");
6065 CFS_MODULE_PARM(mdt_num_threads, "ul", ulong, 0444,
6066 "number of mdt service threads to start");
6068 cfs_module(mdt, "0.2.0", mdt_mod_init, mdt_mod_exit);