1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 only,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License version 2 for more details (a copy is included
16 * in the LICENSE file that accompanied this code).
18 * You should have received a copy of the GNU General Public License
19 * version 2 along with this program; If not, see
20 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
29 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
30 * Use is subject to license terms.
32 * Copyright (c) 2011, 2012, Whamcloud, Inc.
35 * This file is part of Lustre, http://www.lustre.org/
36 * Lustre is a trademark of Sun Microsystems, Inc.
38 * lustre/mdt/mdt_handler.c
40 * Lustre Metadata Target (mdt) request handler
42 * Author: Peter Braam <braam@clusterfs.com>
43 * Author: Andreas Dilger <adilger@clusterfs.com>
44 * Author: Phil Schwan <phil@clusterfs.com>
45 * Author: Mike Shaver <shaver@clusterfs.com>
46 * Author: Nikita Danilov <nikita@clusterfs.com>
47 * Author: Huang Hua <huanghua@clusterfs.com>
48 * Author: Yury Umanets <umka@clusterfs.com>
52 # define EXPORT_SYMTAB
54 #define DEBUG_SUBSYSTEM S_MDS
56 #include <linux/module.h>
58 * struct OBD_{ALLOC,FREE}*()
60 #include <obd_support.h>
61 /* struct ptlrpc_request */
62 #include <lustre_net.h>
63 /* struct obd_export */
64 #include <lustre_export.h>
65 /* struct obd_device */
68 #include <dt_object.h>
69 #include <lustre_mds.h>
70 #include <lustre_mdt.h>
71 #include "mdt_internal.h"
72 #ifdef HAVE_QUOTA_SUPPORT
73 # include <lustre_quota.h>
75 #include <lustre_acl.h>
76 #include <lustre_param.h>
77 #include <lustre_fsfilt.h>
79 mdl_mode_t mdt_mdl_lock_modes[] = {
80 [LCK_MINMODE] = MDL_MINMODE,
87 [LCK_GROUP] = MDL_GROUP
90 ldlm_mode_t mdt_dlm_lock_modes[] = {
91 [MDL_MINMODE] = LCK_MINMODE,
98 [MDL_GROUP] = LCK_GROUP
102 * Initialized in mdt_mod_init().
104 static unsigned long mdt_num_threads;
105 static unsigned long mdt_min_threads;
106 static unsigned long mdt_max_threads;
108 /* ptlrpc request handler for MDT. All handlers are
109 * grouped into several slices - struct mdt_opc_slice,
110 * and stored in an array - mdt_handlers[].
113 /* The name of this handler. */
115 /* Fail id for this handler, checked at the beginning of this handler*/
117 /* Operation code for this handler */
119 /* flags are listed in enum mdt_handler_flags below. */
121 /* The actual handler function to execute. */
122 int (*mh_act)(struct mdt_thread_info *info);
123 /* Request format for this request. */
124 const struct req_format *mh_fmt;
127 enum mdt_handler_flags {
129 * struct mdt_body is passed in the incoming message, and object
130 * identified by this fid exists on disk.
132 * "habeo corpus" == "I have a body"
134 HABEO_CORPUS = (1 << 0),
136 * struct ldlm_request is passed in the incoming message.
138 * "habeo clavis" == "I have a key"
140 HABEO_CLAVIS = (1 << 1),
142 * this request has fixed reply format, so that reply message can be
143 * packed by generic code.
145 * "habeo refero" == "I have a reply"
147 HABEO_REFERO = (1 << 2),
149 * this request will modify something, so check whether the filesystem
150 * is readonly or not, then return -EROFS to client asap if necessary.
152 * "mutabor" == "I shall modify"
157 struct mdt_opc_slice {
160 struct mdt_handler *mos_hs;
163 static struct mdt_opc_slice mdt_regular_handlers[];
164 static struct mdt_opc_slice mdt_readpage_handlers[];
165 static struct mdt_opc_slice mdt_xmds_handlers[];
166 static struct mdt_opc_slice mdt_seq_handlers[];
167 static struct mdt_opc_slice mdt_fld_handlers[];
169 static struct mdt_device *mdt_dev(struct lu_device *d);
170 static int mdt_regular_handle(struct ptlrpc_request *req);
171 static int mdt_unpack_req_pack_rep(struct mdt_thread_info *info, __u32 flags);
172 static int mdt_fid2path(const struct lu_env *env, struct mdt_device *mdt,
173 struct getinfo_fid2path *fp);
175 static const struct lu_object_operations mdt_obj_ops;
177 int mdt_get_disposition(struct ldlm_reply *rep, int flag)
181 return (rep->lock_policy_res1 & flag);
184 void mdt_clear_disposition(struct mdt_thread_info *info,
185 struct ldlm_reply *rep, int flag)
188 info->mti_opdata &= ~flag;
190 rep->lock_policy_res1 &= ~flag;
193 void mdt_set_disposition(struct mdt_thread_info *info,
194 struct ldlm_reply *rep, int flag)
197 info->mti_opdata |= flag;
199 rep->lock_policy_res1 |= flag;
202 void mdt_lock_reg_init(struct mdt_lock_handle *lh, ldlm_mode_t lm)
204 lh->mlh_pdo_hash = 0;
205 lh->mlh_reg_mode = lm;
206 lh->mlh_type = MDT_REG_LOCK;
209 void mdt_lock_pdo_init(struct mdt_lock_handle *lh, ldlm_mode_t lm,
210 const char *name, int namelen)
212 lh->mlh_reg_mode = lm;
213 lh->mlh_type = MDT_PDO_LOCK;
215 if (name != NULL && (name[0] != '\0')) {
216 LASSERT(namelen > 0);
217 lh->mlh_pdo_hash = full_name_hash(name, namelen);
219 LASSERT(namelen == 0);
220 lh->mlh_pdo_hash = 0ull;
224 static void mdt_lock_pdo_mode(struct mdt_thread_info *info, struct mdt_object *o,
225 struct mdt_lock_handle *lh)
231 * Any dir access needs couple of locks:
233 * 1) on part of dir we gonna take lookup/modify;
235 * 2) on whole dir to protect it from concurrent splitting and/or to
236 * flush client's cache for readdir().
238 * so, for a given mode and object this routine decides what lock mode
239 * to use for lock #2:
241 * 1) if caller's gonna lookup in dir then we need to protect dir from
242 * being splitted only - LCK_CR
244 * 2) if caller's gonna modify dir then we need to protect dir from
245 * being splitted and to flush cache - LCK_CW
247 * 3) if caller's gonna modify dir and that dir seems ready for
248 * splitting then we need to protect it from any type of access
249 * (lookup/modify/split) - LCK_EX --bzzz
252 LASSERT(lh->mlh_reg_mode != LCK_MINMODE);
253 LASSERT(lh->mlh_pdo_mode == LCK_MINMODE);
256 * Ask underlaying level its opinion about preferable PDO lock mode
257 * having access type passed as regular lock mode:
259 * - MDL_MINMODE means that lower layer does not want to specify lock
262 * - MDL_NL means that no PDO lock should be taken. This is used in some
263 * cases. Say, for non-splittable directories no need to use PDO locks
266 mode = mdo_lock_mode(info->mti_env, mdt_object_child(o),
267 mdt_dlm_mode2mdl_mode(lh->mlh_reg_mode));
269 if (mode != MDL_MINMODE) {
270 lh->mlh_pdo_mode = mdt_mdl_mode2dlm_mode(mode);
273 * Lower layer does not want to specify locking mode. We do it
274 * our selves. No special protection is needed, just flush
275 * client's cache on modification and allow concurrent
278 switch (lh->mlh_reg_mode) {
280 lh->mlh_pdo_mode = LCK_EX;
283 lh->mlh_pdo_mode = LCK_CR;
286 lh->mlh_pdo_mode = LCK_CW;
289 CERROR("Not expected lock type (0x%x)\n",
290 (int)lh->mlh_reg_mode);
295 LASSERT(lh->mlh_pdo_mode != LCK_MINMODE);
299 static int mdt_getstatus(struct mdt_thread_info *info)
301 struct mdt_device *mdt = info->mti_mdt;
302 struct md_device *next = mdt->mdt_child;
303 struct mdt_body *repbody;
308 rc = mdt_check_ucred(info);
310 RETURN(err_serious(rc));
312 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_GETSTATUS_PACK))
313 RETURN(err_serious(-ENOMEM));
315 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
316 rc = next->md_ops->mdo_root_get(info->mti_env, next, &repbody->fid1);
320 repbody->valid |= OBD_MD_FLID;
322 if (mdt->mdt_opts.mo_mds_capa &&
323 info->mti_exp->exp_connect_flags & OBD_CONNECT_MDS_CAPA) {
324 struct mdt_object *root;
325 struct lustre_capa *capa;
327 root = mdt_object_find(info->mti_env, mdt, &repbody->fid1);
329 RETURN(PTR_ERR(root));
331 capa = req_capsule_server_get(info->mti_pill, &RMF_CAPA1);
333 capa->lc_opc = CAPA_OPC_MDS_DEFAULT;
334 rc = mo_capa_get(info->mti_env, mdt_object_child(root), capa,
336 mdt_object_put(info->mti_env, root);
338 repbody->valid |= OBD_MD_FLMDSCAPA;
344 static int mdt_statfs(struct mdt_thread_info *info)
346 struct ptlrpc_request *req = mdt_info_req(info);
347 struct md_device *next = info->mti_mdt->mdt_child;
348 struct ptlrpc_service *svc;
349 struct obd_statfs *osfs;
354 svc = info->mti_pill->rc_req->rq_rqbd->rqbd_service;
356 /* This will trigger a watchdog timeout */
357 OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_STATFS_LCW_SLEEP,
358 (MDT_SERVICE_WATCHDOG_FACTOR *
359 at_get(&svc->srv_at_estimate)) + 1);
361 rc = mdt_check_ucred(info);
363 RETURN(err_serious(rc));
365 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_STATFS_PACK)) {
366 rc = err_serious(-ENOMEM);
368 osfs = req_capsule_server_get(info->mti_pill, &RMF_OBD_STATFS);
369 rc = next->md_ops->mdo_statfs(info->mti_env, next, osfs);
373 mdt_counter_incr(req->rq_export, LPROC_MDT_STATFS);
379 * Pack SOM attributes into the reply.
380 * Call under a DLM UPDATE lock.
382 static void mdt_pack_size2body(struct mdt_thread_info *info,
383 struct mdt_object *mo)
386 struct md_attr *ma = &info->mti_attr;
388 LASSERT(ma->ma_attr.la_valid & LA_MODE);
389 b = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
391 /* Check if Size-on-MDS is supported, if this is a regular file,
392 * if SOM is enabled on the object and if SOM cache exists and valid.
393 * Otherwise do not pack Size-on-MDS attributes to the reply. */
394 if (!(mdt_conn_flags(info) & OBD_CONNECT_SOM) ||
395 !S_ISREG(ma->ma_attr.la_mode) ||
396 !mdt_object_is_som_enabled(mo) ||
397 !(ma->ma_valid & MA_SOM))
400 b->valid |= OBD_MD_FLSIZE | OBD_MD_FLBLOCKS;
401 b->size = ma->ma_som->msd_size;
402 b->blocks = ma->ma_som->msd_blocks;
405 void mdt_pack_attr2body(struct mdt_thread_info *info, struct mdt_body *b,
406 const struct lu_attr *attr, const struct lu_fid *fid)
408 struct md_attr *ma = &info->mti_attr;
410 LASSERT(ma->ma_valid & MA_INODE);
412 b->atime = attr->la_atime;
413 b->mtime = attr->la_mtime;
414 b->ctime = attr->la_ctime;
415 b->mode = attr->la_mode;
416 b->size = attr->la_size;
417 b->blocks = attr->la_blocks;
418 b->uid = attr->la_uid;
419 b->gid = attr->la_gid;
420 b->flags = attr->la_flags;
421 b->nlink = attr->la_nlink;
422 b->rdev = attr->la_rdev;
424 /*XXX should pack the reply body according to lu_valid*/
425 b->valid |= OBD_MD_FLCTIME | OBD_MD_FLUID |
426 OBD_MD_FLGID | OBD_MD_FLTYPE |
427 OBD_MD_FLMODE | OBD_MD_FLNLINK | OBD_MD_FLFLAGS |
428 OBD_MD_FLATIME | OBD_MD_FLMTIME ;
430 if (!S_ISREG(attr->la_mode)) {
431 b->valid |= OBD_MD_FLSIZE | OBD_MD_FLBLOCKS | OBD_MD_FLRDEV;
432 } else if (ma->ma_need & MA_LOV && ma->ma_lmm_size == 0) {
433 /* means no objects are allocated on osts. */
434 LASSERT(!(ma->ma_valid & MA_LOV));
435 /* just ignore blocks occupied by extend attributes on MDS */
437 /* if no object is allocated on osts, the size on mds is valid. b=22272 */
438 b->valid |= OBD_MD_FLSIZE | OBD_MD_FLBLOCKS;
443 b->valid |= OBD_MD_FLID;
445 /* FIXME: these should be fixed when new igif ready.*/
446 b->ino = fid_oid(fid); /* 1.6 compatibility */
447 b->generation = fid_ver(fid); /* 1.6 compatibility */
448 b->valid |= OBD_MD_FLGENER; /* 1.6 compatibility */
450 CDEBUG(D_INODE, DFID": nlink=%d, mode=%o, size="LPU64"\n",
451 PFID(fid), b->nlink, b->mode, b->size);
455 mdt_body_reverse_idmap(info, b);
457 if (b->valid & OBD_MD_FLSIZE)
458 CDEBUG(D_VFSTRACE, DFID": returning size %llu\n",
459 PFID(fid), (unsigned long long)b->size);
462 static inline int mdt_body_has_lov(const struct lu_attr *la,
463 const struct mdt_body *body)
465 return ((S_ISREG(la->la_mode) && (body->valid & OBD_MD_FLEASIZE)) ||
466 (S_ISDIR(la->la_mode) && (body->valid & OBD_MD_FLDIREA )) );
469 void mdt_client_compatibility(struct mdt_thread_info *info)
471 struct mdt_body *body;
472 struct ptlrpc_request *req = mdt_info_req(info);
473 struct obd_export *exp = req->rq_export;
474 struct md_attr *ma = &info->mti_attr;
475 struct lu_attr *la = &ma->ma_attr;
478 if (exp->exp_connect_flags & OBD_CONNECT_LAYOUTLOCK)
479 /* the client can deal with 16-bit lmm_stripe_count */
482 body = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
484 if (!mdt_body_has_lov(la, body))
487 /* now we have a reply with a lov for a client not compatible with the
488 * layout lock so we have to clean the layout generation number */
489 if (S_ISREG(la->la_mode))
490 ma->ma_lmm->lmm_layout_gen = 0;
495 static int mdt_getattr_internal(struct mdt_thread_info *info,
496 struct mdt_object *o, int ma_need)
498 struct md_object *next = mdt_object_child(o);
499 const struct mdt_body *reqbody = info->mti_body;
500 struct ptlrpc_request *req = mdt_info_req(info);
501 struct md_attr *ma = &info->mti_attr;
502 struct lu_attr *la = &ma->ma_attr;
503 struct req_capsule *pill = info->mti_pill;
504 const struct lu_env *env = info->mti_env;
505 struct mdt_body *repbody;
506 struct lu_buf *buffer = &info->mti_buf;
510 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_GETATTR_PACK))
511 RETURN(err_serious(-ENOMEM));
513 repbody = req_capsule_server_get(pill, &RMF_MDT_BODY);
517 rc = mdt_object_exists(o);
519 /* This object is located on remote node.*/
520 repbody->fid1 = *mdt_object_fid(o);
521 repbody->valid = OBD_MD_FLID | OBD_MD_MDS;
525 buffer->lb_buf = req_capsule_server_get(pill, &RMF_MDT_MD);
526 buffer->lb_len = req_capsule_get_size(pill, &RMF_MDT_MD, RCL_SERVER);
528 /* If it is dir object and client require MEA, then we got MEA */
529 if (S_ISDIR(lu_object_attr(&next->mo_lu)) &&
530 reqbody->valid & OBD_MD_MEA) {
531 /* Assumption: MDT_MD size is enough for lmv size. */
532 ma->ma_lmv = buffer->lb_buf;
533 ma->ma_lmv_size = buffer->lb_len;
534 ma->ma_need = MA_LMV | MA_INODE;
536 ma->ma_lmm = buffer->lb_buf;
537 ma->ma_lmm_size = buffer->lb_len;
538 ma->ma_need = MA_LOV | MA_INODE;
541 if (S_ISDIR(lu_object_attr(&next->mo_lu)) &&
542 reqbody->valid & OBD_MD_FLDIREA &&
543 lustre_msg_get_opc(req->rq_reqmsg) == MDS_GETATTR) {
544 /* get default stripe info for this dir. */
545 ma->ma_need |= MA_LOV_DEF;
547 ma->ma_need |= ma_need;
548 if (ma->ma_need & MA_SOM)
549 ma->ma_som = &info->mti_u.som.data;
551 rc = mo_attr_get(env, next, ma);
553 CERROR("getattr error for "DFID": %d\n",
554 PFID(mdt_object_fid(o)), rc);
558 if (likely(ma->ma_valid & MA_INODE))
559 mdt_pack_attr2body(info, repbody, la, mdt_object_fid(o));
563 if (mdt_body_has_lov(la, reqbody)) {
564 if (ma->ma_valid & MA_LOV) {
565 LASSERT(ma->ma_lmm_size);
566 mdt_dump_lmm(D_INFO, ma->ma_lmm);
567 repbody->eadatasize = ma->ma_lmm_size;
568 if (S_ISDIR(la->la_mode))
569 repbody->valid |= OBD_MD_FLDIREA;
571 repbody->valid |= OBD_MD_FLEASIZE;
573 if (ma->ma_valid & MA_LMV) {
574 LASSERT(S_ISDIR(la->la_mode));
575 repbody->eadatasize = ma->ma_lmv_size;
576 repbody->valid |= (OBD_MD_FLDIREA|OBD_MD_MEA);
578 } else if (S_ISLNK(la->la_mode) &&
579 reqbody->valid & OBD_MD_LINKNAME) {
580 buffer->lb_buf = ma->ma_lmm;
581 /* eadatasize from client includes NULL-terminator, so
582 * there is no need to read it */
583 buffer->lb_len = reqbody->eadatasize - 1;
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 /* we need to report back size with NULL-terminator
593 * because client expects that */
594 repbody->eadatasize = rc + 1;
595 if (repbody->eadatasize != reqbody->eadatasize)
596 CERROR("Read shorter link %d than expected "
597 "%d\n", rc, reqbody->eadatasize - 1);
599 ((char*)ma->ma_lmm)[rc] = 0;
600 CDEBUG(D_INODE, "symlink dest %s, len = %d\n",
601 (char*)ma->ma_lmm, rc);
606 if (reqbody->valid & OBD_MD_FLMODEASIZE) {
607 repbody->max_cookiesize = info->mti_mdt->mdt_max_cookiesize;
608 repbody->max_mdsize = info->mti_mdt->mdt_max_mdsize;
609 repbody->valid |= OBD_MD_FLMODEASIZE;
610 CDEBUG(D_INODE, "I am going to change the MAX_MD_SIZE & "
611 "MAX_COOKIE to : %d:%d\n", repbody->max_mdsize,
612 repbody->max_cookiesize);
615 if (exp_connect_rmtclient(info->mti_exp) &&
616 reqbody->valid & OBD_MD_FLRMTPERM) {
617 void *buf = req_capsule_server_get(pill, &RMF_ACL);
619 /* mdt_getattr_lock only */
620 rc = mdt_pack_remote_perm(info, o, buf);
622 repbody->valid &= ~OBD_MD_FLRMTPERM;
623 repbody->aclsize = 0;
626 repbody->valid |= OBD_MD_FLRMTPERM;
627 repbody->aclsize = sizeof(struct mdt_remote_perm);
630 #ifdef CONFIG_FS_POSIX_ACL
631 else if ((req->rq_export->exp_connect_flags & OBD_CONNECT_ACL) &&
632 (reqbody->valid & OBD_MD_FLACL)) {
633 buffer->lb_buf = req_capsule_server_get(pill, &RMF_ACL);
634 buffer->lb_len = req_capsule_get_size(pill,
635 &RMF_ACL, RCL_SERVER);
636 if (buffer->lb_len > 0) {
637 rc = mo_xattr_get(env, next, buffer,
638 XATTR_NAME_ACL_ACCESS);
640 if (rc == -ENODATA) {
641 repbody->aclsize = 0;
642 repbody->valid |= OBD_MD_FLACL;
644 } else if (rc == -EOPNOTSUPP) {
647 CERROR("got acl size: %d\n", rc);
650 repbody->aclsize = rc;
651 repbody->valid |= OBD_MD_FLACL;
658 if (reqbody->valid & OBD_MD_FLMDSCAPA &&
659 info->mti_mdt->mdt_opts.mo_mds_capa &&
660 info->mti_exp->exp_connect_flags & OBD_CONNECT_MDS_CAPA) {
661 struct lustre_capa *capa;
663 capa = req_capsule_server_get(pill, &RMF_CAPA1);
665 capa->lc_opc = CAPA_OPC_MDS_DEFAULT;
666 rc = mo_capa_get(env, next, capa, 0);
669 repbody->valid |= OBD_MD_FLMDSCAPA;
674 mdt_counter_incr(req->rq_export, LPROC_MDT_GETATTR);
679 static int mdt_renew_capa(struct mdt_thread_info *info)
681 struct mdt_object *obj = info->mti_object;
682 struct mdt_body *body;
683 struct lustre_capa *capa, *c;
687 /* if object doesn't exist, or server has disabled capability,
688 * return directly, client will find body->valid OBD_MD_FLOSSCAPA
691 if (!obj || !info->mti_mdt->mdt_opts.mo_oss_capa ||
692 !(info->mti_exp->exp_connect_flags & OBD_CONNECT_OSS_CAPA))
695 body = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
696 LASSERT(body != NULL);
698 c = req_capsule_client_get(info->mti_pill, &RMF_CAPA1);
701 capa = req_capsule_server_get(info->mti_pill, &RMF_CAPA2);
705 rc = mo_capa_get(info->mti_env, mdt_object_child(obj), capa, 1);
707 body->valid |= OBD_MD_FLOSSCAPA;
711 static int mdt_getattr(struct mdt_thread_info *info)
713 struct mdt_object *obj = info->mti_object;
714 struct req_capsule *pill = info->mti_pill;
715 struct mdt_body *reqbody;
716 struct mdt_body *repbody;
721 reqbody = req_capsule_client_get(pill, &RMF_MDT_BODY);
724 if (reqbody->valid & OBD_MD_FLOSSCAPA) {
725 rc = req_capsule_server_pack(pill);
727 RETURN(err_serious(rc));
728 rc = mdt_renew_capa(info);
729 GOTO(out_shrink, rc);
732 LASSERT(obj != NULL);
733 LASSERT(lu_object_assert_exists(&obj->mot_obj.mo_lu));
735 mode = lu_object_attr(&obj->mot_obj.mo_lu);
737 /* old clients may not report needed easize, use max value then */
738 req_capsule_set_size(pill, &RMF_MDT_MD, RCL_SERVER,
739 reqbody->eadatasize == 0 ?
740 info->mti_mdt->mdt_max_mdsize :
741 reqbody->eadatasize);
743 rc = req_capsule_server_pack(pill);
744 if (unlikely(rc != 0))
745 RETURN(err_serious(rc));
747 repbody = req_capsule_server_get(pill, &RMF_MDT_BODY);
748 LASSERT(repbody != NULL);
749 repbody->eadatasize = 0;
750 repbody->aclsize = 0;
752 if (reqbody->valid & OBD_MD_FLRMTPERM)
753 rc = mdt_init_ucred(info, reqbody);
755 rc = mdt_check_ucred(info);
757 GOTO(out_shrink, rc);
759 info->mti_spec.sp_ck_split = !!(reqbody->valid & OBD_MD_FLCKSPLIT);
760 info->mti_cross_ref = !!(reqbody->valid & OBD_MD_FLCROSSREF);
763 * Don't check capability at all, because rename might getattr for
764 * remote obj, and at that time no capability is available.
766 mdt_set_capainfo(info, 1, &reqbody->fid1, BYPASS_CAPA);
767 rc = mdt_getattr_internal(info, obj, 0);
768 if (reqbody->valid & OBD_MD_FLRMTPERM)
769 mdt_exit_ucred(info);
773 mdt_client_compatibility(info);
774 rc2 = mdt_fix_reply(info);
780 static int mdt_is_subdir(struct mdt_thread_info *info)
782 struct mdt_object *o = info->mti_object;
783 struct req_capsule *pill = info->mti_pill;
784 const struct mdt_body *body = info->mti_body;
785 struct mdt_body *repbody;
791 repbody = req_capsule_server_get(pill, &RMF_MDT_BODY);
794 * We save last checked parent fid to @repbody->fid1 for remote
797 LASSERT(fid_is_sane(&body->fid2));
798 LASSERT(mdt_object_exists(o) > 0);
799 rc = mdo_is_subdir(info->mti_env, mdt_object_child(o),
800 &body->fid2, &repbody->fid1);
801 if (rc == 0 || rc == -EREMOTE)
802 repbody->valid |= OBD_MD_FLID;
807 static int mdt_raw_lookup(struct mdt_thread_info *info,
808 struct mdt_object *parent,
809 const struct lu_name *lname,
810 struct ldlm_reply *ldlm_rep)
812 struct md_object *next = mdt_object_child(info->mti_object);
813 const struct mdt_body *reqbody = info->mti_body;
814 struct lu_fid *child_fid = &info->mti_tmp_fid1;
815 struct mdt_body *repbody;
819 if (reqbody->valid != OBD_MD_FLID)
822 LASSERT(!info->mti_cross_ref);
824 /* Only got the fid of this obj by name */
826 rc = mdo_lookup(info->mti_env, next, lname, child_fid,
829 /* XXX is raw_lookup possible as intent operation? */
832 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_NEG);
835 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_POS);
837 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
840 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
841 repbody->fid1 = *child_fid;
842 repbody->valid = OBD_MD_FLID;
848 * UPDATE lock should be taken against parent, and be release before exit;
849 * child_bits lock should be taken against child, and be returned back:
850 * (1)normal request should release the child lock;
851 * (2)intent request will grant the lock to client.
853 static int mdt_getattr_name_lock(struct mdt_thread_info *info,
854 struct mdt_lock_handle *lhc,
856 struct ldlm_reply *ldlm_rep)
858 struct ptlrpc_request *req = mdt_info_req(info);
859 struct mdt_body *reqbody = NULL;
860 struct mdt_object *parent = info->mti_object;
861 struct mdt_object *child;
862 struct md_object *next = mdt_object_child(parent);
863 struct lu_fid *child_fid = &info->mti_tmp_fid1;
864 struct lu_name *lname = NULL;
865 const char *name = NULL;
867 struct mdt_lock_handle *lhp = NULL;
868 struct ldlm_lock *lock;
869 struct ldlm_res_id *res_id;
876 is_resent = lustre_handle_is_used(&lhc->mlh_reg_lh);
877 LASSERT(ergo(is_resent,
878 lustre_msg_get_flags(req->rq_reqmsg) & MSG_RESENT));
880 LASSERT(parent != NULL);
881 name = req_capsule_client_get(info->mti_pill, &RMF_NAME);
883 RETURN(err_serious(-EFAULT));
885 namelen = req_capsule_get_size(info->mti_pill, &RMF_NAME,
887 if (!info->mti_cross_ref) {
889 * XXX: Check for "namelen == 0" is for getattr by fid
890 * (OBD_CONNECT_ATTRFID), otherwise do not allow empty name,
891 * that is the name must contain at least one character and
892 * the terminating '\0'
895 reqbody = req_capsule_client_get(info->mti_pill,
897 if (unlikely(reqbody == NULL))
898 RETURN(err_serious(-EFAULT));
900 if (unlikely(!fid_is_sane(&reqbody->fid2)))
901 RETURN(err_serious(-EINVAL));
904 CDEBUG(D_INODE, "getattr with lock for "DFID"/"DFID", "
906 PFID(mdt_object_fid(parent)),
907 PFID(&reqbody->fid2), ldlm_rep);
909 lname = mdt_name(info->mti_env, (char *)name, namelen);
910 CDEBUG(D_INODE, "getattr with lock for "DFID"/%s, "
911 "ldlm_rep = %p\n", PFID(mdt_object_fid(parent)),
915 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_EXECD);
917 rc = mdt_object_exists(parent);
918 if (unlikely(rc == 0)) {
919 LU_OBJECT_DEBUG(D_WARNING, info->mti_env,
920 &parent->mot_obj.mo_lu,
921 "Parent doesn't exist!\n");
923 } else if (!info->mti_cross_ref) {
924 LASSERTF(rc > 0, "Parent "DFID" is on remote server\n",
925 PFID(mdt_object_fid(parent)));
928 rc = mdt_raw_lookup(info, parent, lname, ldlm_rep);
936 if (info->mti_cross_ref) {
937 /* Only getattr on the child. Parent is on another node. */
938 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_POS);
940 CDEBUG(D_INODE, "partial getattr_name child_fid = "DFID", "
941 "ldlm_rep=%p\n", PFID(mdt_object_fid(child)), ldlm_rep);
944 /* Do not take lock for resent case. */
945 lock = ldlm_handle2lock(&lhc->mlh_reg_lh);
946 LASSERTF(lock != NULL, "Invalid lock handle "LPX64"\n",
947 lhc->mlh_reg_lh.cookie);
948 LASSERT(fid_res_name_eq(mdt_object_fid(child),
949 &lock->l_resource->lr_name));
953 mdt_lock_handle_init(lhc);
954 mdt_lock_reg_init(lhc, LCK_PR);
957 * Object's name is on another MDS, no lookup lock is
958 * needed here but update is.
960 child_bits &= ~MDS_INODELOCK_LOOKUP;
961 child_bits |= MDS_INODELOCK_UPDATE;
963 rc = mdt_object_lock(info, child, lhc, child_bits,
967 /* Finally, we can get attr for child. */
968 mdt_set_capainfo(info, 0, mdt_object_fid(child),
970 rc = mdt_getattr_internal(info, child, 0);
971 if (unlikely(rc != 0))
972 mdt_object_unlock(info, child, lhc, 1);
978 /* step 1: lock parent only if parent is a directory */
979 if (S_ISDIR(lu_object_attr(&parent->mot_obj.mo_lu))) {
980 lhp = &info->mti_lh[MDT_LH_PARENT];
981 mdt_lock_pdo_init(lhp, LCK_PR, name, namelen);
982 rc = mdt_object_lock(info, parent, lhp,
983 MDS_INODELOCK_UPDATE,
985 if (unlikely(rc != 0))
989 /* step 2: lookup child's fid by name */
991 rc = mdo_lookup(info->mti_env, next, lname, child_fid,
996 mdt_set_disposition(info, ldlm_rep,
998 GOTO(out_parent, rc);
1000 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_POS);
1002 *child_fid = reqbody->fid2;
1003 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_POS);
1007 *step 3: find the child object by fid & lock it.
1008 * regardless if it is local or remote.
1010 child = mdt_object_find(info->mti_env, info->mti_mdt, child_fid);
1012 if (unlikely(IS_ERR(child)))
1013 GOTO(out_parent, rc = PTR_ERR(child));
1015 /* Do not take lock for resent case. */
1016 lock = ldlm_handle2lock(&lhc->mlh_reg_lh);
1017 LASSERTF(lock != NULL, "Invalid lock handle "LPX64"\n",
1018 lhc->mlh_reg_lh.cookie);
1020 res_id = &lock->l_resource->lr_name;
1021 if (!fid_res_name_eq(mdt_object_fid(child),
1022 &lock->l_resource->lr_name)) {
1023 LASSERTF(fid_res_name_eq(mdt_object_fid(parent),
1024 &lock->l_resource->lr_name),
1025 "Lock res_id: %lu/%lu/%lu, Fid: "DFID".\n",
1026 (unsigned long)res_id->name[0],
1027 (unsigned long)res_id->name[1],
1028 (unsigned long)res_id->name[2],
1029 PFID(mdt_object_fid(parent)));
1030 CWARN("Although resent, but still not get child lock"
1031 "parent:"DFID" child:"DFID"\n",
1032 PFID(mdt_object_fid(parent)),
1033 PFID(mdt_object_fid(child)));
1034 lustre_msg_clear_flags(req->rq_reqmsg, MSG_RESENT);
1035 LDLM_LOCK_PUT(lock);
1038 LDLM_LOCK_PUT(lock);
1042 OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_RESEND, obd_timeout*2);
1043 mdt_lock_handle_init(lhc);
1044 if (child_bits == MDS_INODELOCK_LAYOUT)
1045 mdt_lock_reg_init(lhc, LCK_CR);
1047 mdt_lock_reg_init(lhc, LCK_PR);
1049 if (mdt_object_exists(child) == 0) {
1050 LU_OBJECT_DEBUG(D_INODE, info->mti_env,
1051 &child->mot_obj.mo_lu,
1052 "Object doesn't exist!\n");
1053 GOTO(out_child, rc = -ENOENT);
1056 if (!(child_bits & MDS_INODELOCK_UPDATE)) {
1057 struct md_attr *ma = &info->mti_attr;
1060 ma->ma_need = MA_INODE;
1061 rc = mo_attr_get(info->mti_env,
1062 mdt_object_child(child), ma);
1063 if (unlikely(rc != 0))
1064 GOTO(out_child, rc);
1066 /* layout lock is used only on regular files */
1067 if ((ma->ma_valid & MA_INODE) &&
1068 (ma->ma_attr.la_valid & LA_MODE) &&
1069 !S_ISREG(ma->ma_attr.la_mode))
1070 child_bits &= ~MDS_INODELOCK_LAYOUT;
1072 /* If the file has not been changed for some time, we
1073 * return not only a LOOKUP lock, but also an UPDATE
1074 * lock and this might save us RPC on later STAT. For
1075 * directories, it also let negative dentry starts
1076 * working for this dir. */
1077 if (ma->ma_valid & MA_INODE &&
1078 ma->ma_attr.la_valid & LA_CTIME &&
1079 info->mti_mdt->mdt_namespace->ns_ctime_age_limit +
1080 ma->ma_attr.la_ctime < cfs_time_current_sec())
1081 child_bits |= MDS_INODELOCK_UPDATE;
1084 rc = mdt_object_lock(info, child, lhc, child_bits,
1087 if (unlikely(rc != 0))
1088 GOTO(out_child, rc);
1091 lock = ldlm_handle2lock(&lhc->mlh_reg_lh);
1092 /* Get MA_SOM attributes if update lock is given. */
1094 lock->l_policy_data.l_inodebits.bits & MDS_INODELOCK_UPDATE &&
1095 S_ISREG(lu_object_attr(&mdt_object_child(child)->mo_lu)))
1098 /* finally, we can get attr for child. */
1099 mdt_set_capainfo(info, 1, child_fid, BYPASS_CAPA);
1100 rc = mdt_getattr_internal(info, child, ma_need);
1101 if (unlikely(rc != 0)) {
1102 mdt_object_unlock(info, child, lhc, 1);
1104 /* Debugging code. */
1105 res_id = &lock->l_resource->lr_name;
1106 LDLM_DEBUG(lock, "Returning lock to client");
1107 LASSERTF(fid_res_name_eq(mdt_object_fid(child),
1108 &lock->l_resource->lr_name),
1109 "Lock res_id: %lu/%lu/%lu, Fid: "DFID".\n",
1110 (unsigned long)res_id->name[0],
1111 (unsigned long)res_id->name[1],
1112 (unsigned long)res_id->name[2],
1113 PFID(mdt_object_fid(child)));
1114 mdt_pack_size2body(info, child);
1117 LDLM_LOCK_PUT(lock);
1121 mdt_object_put(info->mti_env, child);
1124 mdt_object_unlock(info, parent, lhp, 1);
1128 /* normal handler: should release the child lock */
1129 static int mdt_getattr_name(struct mdt_thread_info *info)
1131 struct mdt_lock_handle *lhc = &info->mti_lh[MDT_LH_CHILD];
1132 struct mdt_body *reqbody;
1133 struct mdt_body *repbody;
1137 reqbody = req_capsule_client_get(info->mti_pill, &RMF_MDT_BODY);
1138 LASSERT(reqbody != NULL);
1139 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
1140 LASSERT(repbody != NULL);
1142 info->mti_spec.sp_ck_split = !!(reqbody->valid & OBD_MD_FLCKSPLIT);
1143 info->mti_cross_ref = !!(reqbody->valid & OBD_MD_FLCROSSREF);
1144 repbody->eadatasize = 0;
1145 repbody->aclsize = 0;
1147 rc = mdt_init_ucred(info, reqbody);
1149 GOTO(out_shrink, rc);
1151 rc = mdt_getattr_name_lock(info, lhc, MDS_INODELOCK_UPDATE, NULL);
1152 if (lustre_handle_is_used(&lhc->mlh_reg_lh)) {
1153 ldlm_lock_decref(&lhc->mlh_reg_lh, lhc->mlh_reg_mode);
1154 lhc->mlh_reg_lh.cookie = 0;
1156 mdt_exit_ucred(info);
1159 mdt_client_compatibility(info);
1160 rc2 = mdt_fix_reply(info);
1166 static const struct lu_device_operations mdt_lu_ops;
1168 static int lu_device_is_mdt(struct lu_device *d)
1170 return ergo(d != NULL && d->ld_ops != NULL, d->ld_ops == &mdt_lu_ops);
1173 static int mdt_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
1174 void *karg, void *uarg);
1176 static int mdt_set_info(struct mdt_thread_info *info)
1178 struct ptlrpc_request *req = mdt_info_req(info);
1181 int keylen, vallen, rc = 0;
1184 rc = req_capsule_server_pack(info->mti_pill);
1188 key = req_capsule_client_get(info->mti_pill, &RMF_SETINFO_KEY);
1190 DEBUG_REQ(D_HA, req, "no set_info key");
1194 keylen = req_capsule_get_size(info->mti_pill, &RMF_SETINFO_KEY,
1197 val = req_capsule_client_get(info->mti_pill, &RMF_SETINFO_VAL);
1199 DEBUG_REQ(D_HA, req, "no set_info val");
1203 vallen = req_capsule_get_size(info->mti_pill, &RMF_SETINFO_VAL,
1206 /* Swab any part of val you need to here */
1207 if (KEY_IS(KEY_READ_ONLY)) {
1209 lustre_msg_set_status(req->rq_repmsg, 0);
1211 cfs_spin_lock(&req->rq_export->exp_lock);
1213 req->rq_export->exp_connect_flags |= OBD_CONNECT_RDONLY;
1215 req->rq_export->exp_connect_flags &=~OBD_CONNECT_RDONLY;
1216 cfs_spin_unlock(&req->rq_export->exp_lock);
1218 } else if (KEY_IS(KEY_CHANGELOG_CLEAR)) {
1219 struct changelog_setinfo *cs =
1220 (struct changelog_setinfo *)val;
1221 if (vallen != sizeof(*cs)) {
1222 CERROR("Bad changelog_clear setinfo size %d\n", vallen);
1225 if (ptlrpc_req_need_swab(req)) {
1226 __swab64s(&cs->cs_recno);
1227 __swab32s(&cs->cs_id);
1230 rc = mdt_iocontrol(OBD_IOC_CHANGELOG_CLEAR, info->mti_exp,
1232 lustre_msg_set_status(req->rq_repmsg, rc);
1240 static int mdt_connect(struct mdt_thread_info *info)
1243 struct ptlrpc_request *req;
1245 req = mdt_info_req(info);
1246 rc = target_handle_connect(req);
1248 LASSERT(req->rq_export != NULL);
1249 info->mti_mdt = mdt_dev(req->rq_export->exp_obd->obd_lu_dev);
1250 rc = mdt_init_sec_level(info);
1252 rc = mdt_init_idmap(info);
1254 obd_disconnect(class_export_get(req->rq_export));
1256 rc = err_serious(rc);
1261 static int mdt_disconnect(struct mdt_thread_info *info)
1266 rc = target_handle_disconnect(mdt_info_req(info));
1268 rc = err_serious(rc);
1272 static int mdt_sendpage(struct mdt_thread_info *info,
1273 struct lu_rdpg *rdpg, int nob)
1275 struct ptlrpc_request *req = mdt_info_req(info);
1276 struct obd_export *exp = req->rq_export;
1277 struct ptlrpc_bulk_desc *desc;
1278 struct l_wait_info *lwi = &info->mti_u.rdpg.mti_wait_info;
1285 desc = ptlrpc_prep_bulk_exp(req, rdpg->rp_npages, BULK_PUT_SOURCE,
1290 for (i = 0, tmpcount = nob;
1291 i < rdpg->rp_npages && tmpcount > 0; i++, tmpcount -= tmpsize) {
1292 tmpsize = min_t(int, tmpcount, CFS_PAGE_SIZE);
1293 ptlrpc_prep_bulk_page(desc, rdpg->rp_pages[i], 0, tmpsize);
1296 LASSERT(desc->bd_nob == nob);
1297 rc = target_bulk_io(exp, desc, lwi);
1298 ptlrpc_free_bulk(desc);
1302 #ifdef HAVE_SPLIT_SUPPORT
1304 * Retrieve dir entry from the page and insert it to the slave object, actually,
1305 * this should be in osd layer, but since it will not in the final product, so
1306 * just do it here and do not define more moo api anymore for this.
1308 static int mdt_write_dir_page(struct mdt_thread_info *info, struct page *page,
1311 struct mdt_object *object = info->mti_object;
1312 struct lu_fid *lf = &info->mti_tmp_fid2;
1313 struct md_attr *ma = &info->mti_attr;
1314 struct lu_dirpage *dp;
1315 struct lu_dirent *ent;
1316 int rc = 0, offset = 0;
1319 /* Make sure we have at least one entry. */
1324 * Disable trans for this name insert, since it will include many trans
1327 info->mti_no_need_trans = 1;
1329 * When write_dir_page, no need update parent's ctime,
1330 * and no permission check for name_insert.
1332 ma->ma_attr.la_ctime = 0;
1333 ma->ma_attr.la_valid = LA_MODE;
1334 ma->ma_valid = MA_INODE;
1337 dp = page_address(page);
1338 offset = (int)((__u32)lu_dirent_start(dp) - (__u32)dp);
1340 for (ent = lu_dirent_start(dp); ent != NULL;
1341 ent = lu_dirent_next(ent)) {
1342 struct lu_name *lname;
1345 if (le16_to_cpu(ent->lde_namelen) == 0)
1348 fid_le_to_cpu(lf, &ent->lde_fid);
1349 if (le64_to_cpu(ent->lde_hash) & MAX_HASH_HIGHEST_BIT)
1350 ma->ma_attr.la_mode = S_IFDIR;
1352 ma->ma_attr.la_mode = 0;
1353 OBD_ALLOC(name, le16_to_cpu(ent->lde_namelen) + 1);
1355 GOTO(out, rc = -ENOMEM);
1357 memcpy(name, ent->lde_name, le16_to_cpu(ent->lde_namelen));
1358 lname = mdt_name(info->mti_env, name,
1359 le16_to_cpu(ent->lde_namelen));
1360 ma->ma_attr_flags |= (MDS_PERM_BYPASS | MDS_QUOTA_IGNORE);
1361 rc = mdo_name_insert(info->mti_env,
1362 md_object_next(&object->mot_obj),
1364 OBD_FREE(name, le16_to_cpu(ent->lde_namelen) + 1);
1366 CERROR("Can't insert %*.*s, rc %d\n",
1367 le16_to_cpu(ent->lde_namelen),
1368 le16_to_cpu(ent->lde_namelen),
1373 offset += lu_dirent_size(ent);
1383 static int mdt_bulk_timeout(void *data)
1387 CERROR("mdt bulk transfer timeout \n");
1392 static int mdt_writepage(struct mdt_thread_info *info)
1394 struct ptlrpc_request *req = mdt_info_req(info);
1395 struct mdt_body *reqbody;
1396 struct l_wait_info *lwi;
1397 struct ptlrpc_bulk_desc *desc;
1403 reqbody = req_capsule_client_get(info->mti_pill, &RMF_MDT_BODY);
1404 if (reqbody == NULL)
1405 RETURN(err_serious(-EFAULT));
1407 desc = ptlrpc_prep_bulk_exp(req, 1, BULK_GET_SINK, MDS_BULK_PORTAL);
1409 RETURN(err_serious(-ENOMEM));
1411 /* allocate the page for the desc */
1412 page = cfs_alloc_page(CFS_ALLOC_STD);
1414 GOTO(desc_cleanup, rc = -ENOMEM);
1416 CDEBUG(D_INFO, "Received page offset %d size %d \n",
1417 (int)reqbody->size, (int)reqbody->nlink);
1419 ptlrpc_prep_bulk_page(desc, page, (int)reqbody->size,
1420 (int)reqbody->nlink);
1422 rc = sptlrpc_svc_prep_bulk(req, desc);
1424 GOTO(cleanup_page, rc);
1426 * Check if client was evicted while we were doing i/o before touching
1431 GOTO(cleanup_page, rc = -ENOMEM);
1433 if (desc->bd_export->exp_failed)
1436 rc = ptlrpc_start_bulk_transfer (desc);
1438 *lwi = LWI_TIMEOUT_INTERVAL(obd_timeout * CFS_HZ / 4, CFS_HZ,
1439 mdt_bulk_timeout, desc);
1440 rc = l_wait_event(desc->bd_waitq, !ptlrpc_bulk_active(desc) ||
1441 desc->bd_export->exp_failed, lwi);
1442 LASSERT(rc == 0 || rc == -ETIMEDOUT);
1443 if (rc == -ETIMEDOUT) {
1444 DEBUG_REQ(D_ERROR, req, "timeout on bulk GET");
1445 ptlrpc_abort_bulk(desc);
1446 } else if (desc->bd_export->exp_failed) {
1447 DEBUG_REQ(D_ERROR, req, "Eviction on bulk GET");
1449 ptlrpc_abort_bulk(desc);
1450 } else if (!desc->bd_success ||
1451 desc->bd_nob_transferred != desc->bd_nob) {
1452 DEBUG_REQ(D_ERROR, req, "%s bulk GET %d(%d)",
1454 "truncated" : "network error on",
1455 desc->bd_nob_transferred, desc->bd_nob);
1456 /* XXX should this be a different errno? */
1460 DEBUG_REQ(D_ERROR, req, "ptlrpc_bulk_get failed: rc %d", rc);
1463 GOTO(cleanup_lwi, rc);
1464 rc = mdt_write_dir_page(info, page, reqbody->nlink);
1469 cfs_free_page(page);
1471 ptlrpc_free_bulk(desc);
1476 static int mdt_readpage(struct mdt_thread_info *info)
1478 struct mdt_object *object = info->mti_object;
1479 struct lu_rdpg *rdpg = &info->mti_u.rdpg.mti_rdpg;
1480 struct mdt_body *reqbody;
1481 struct mdt_body *repbody;
1486 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_READPAGE_PACK))
1487 RETURN(err_serious(-ENOMEM));
1489 reqbody = req_capsule_client_get(info->mti_pill, &RMF_MDT_BODY);
1490 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
1491 if (reqbody == NULL || repbody == NULL)
1492 RETURN(err_serious(-EFAULT));
1495 * prepare @rdpg before calling lower layers and transfer itself. Here
1496 * reqbody->size contains offset of where to start to read and
1497 * reqbody->nlink contains number bytes to read.
1499 rdpg->rp_hash = reqbody->size;
1500 if (rdpg->rp_hash != reqbody->size) {
1501 CERROR("Invalid hash: "LPX64" != "LPX64"\n",
1502 rdpg->rp_hash, reqbody->size);
1506 rdpg->rp_attrs = reqbody->mode;
1507 if (info->mti_exp->exp_connect_flags & OBD_CONNECT_64BITHASH)
1508 rdpg->rp_attrs |= LUDA_64BITHASH;
1509 rdpg->rp_count = min_t(unsigned int, reqbody->nlink,
1510 PTLRPC_MAX_BRW_SIZE);
1511 rdpg->rp_npages = (rdpg->rp_count + CFS_PAGE_SIZE - 1) >>
1513 OBD_ALLOC(rdpg->rp_pages, rdpg->rp_npages * sizeof rdpg->rp_pages[0]);
1514 if (rdpg->rp_pages == NULL)
1517 for (i = 0; i < rdpg->rp_npages; ++i) {
1518 rdpg->rp_pages[i] = cfs_alloc_page(CFS_ALLOC_STD);
1519 if (rdpg->rp_pages[i] == NULL)
1520 GOTO(free_rdpg, rc = -ENOMEM);
1523 /* call lower layers to fill allocated pages with directory data */
1524 rc = mo_readpage(info->mti_env, mdt_object_child(object), rdpg);
1526 GOTO(free_rdpg, rc);
1528 /* send pages to client */
1529 rc = mdt_sendpage(info, rdpg, rc);
1534 for (i = 0; i < rdpg->rp_npages; i++)
1535 if (rdpg->rp_pages[i] != NULL)
1536 cfs_free_page(rdpg->rp_pages[i]);
1537 OBD_FREE(rdpg->rp_pages, rdpg->rp_npages * sizeof rdpg->rp_pages[0]);
1539 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_SENDPAGE))
1545 static int mdt_reint_internal(struct mdt_thread_info *info,
1546 struct mdt_lock_handle *lhc,
1549 struct req_capsule *pill = info->mti_pill;
1550 struct md_quota *mq = md_quota(info->mti_env);
1551 struct mdt_body *repbody;
1556 rc = mdt_reint_unpack(info, op);
1558 CERROR("Can't unpack reint, rc %d\n", rc);
1559 RETURN(err_serious(rc));
1562 /* for replay (no_create) lmm is not needed, client has it already */
1563 if (req_capsule_has_field(pill, &RMF_MDT_MD, RCL_SERVER))
1564 req_capsule_set_size(pill, &RMF_MDT_MD, RCL_SERVER,
1565 info->mti_rr.rr_eadatalen);
1567 if (req_capsule_has_field(pill, &RMF_LOGCOOKIES, RCL_SERVER))
1568 req_capsule_set_size(pill, &RMF_LOGCOOKIES, RCL_SERVER,
1569 info->mti_mdt->mdt_max_cookiesize);
1571 rc = req_capsule_server_pack(pill);
1573 CERROR("Can't pack response, rc %d\n", rc);
1574 RETURN(err_serious(rc));
1577 if (req_capsule_has_field(pill, &RMF_MDT_BODY, RCL_SERVER)) {
1578 repbody = req_capsule_server_get(pill, &RMF_MDT_BODY);
1580 repbody->eadatasize = 0;
1581 repbody->aclsize = 0;
1584 OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_REINT_DELAY, 10);
1586 /* for replay no cookkie / lmm need, because client have this already */
1587 if (info->mti_spec.no_create)
1588 if (req_capsule_has_field(pill, &RMF_MDT_MD, RCL_SERVER))
1589 req_capsule_set_size(pill, &RMF_MDT_MD, RCL_SERVER, 0);
1591 rc = mdt_init_ucred_reint(info);
1593 GOTO(out_shrink, rc);
1595 rc = mdt_fix_attr_ucred(info, op);
1597 GOTO(out_ucred, rc = err_serious(rc));
1599 if (mdt_check_resent(info, mdt_reconstruct, lhc)) {
1600 rc = lustre_msg_get_status(mdt_info_req(info)->rq_repmsg);
1601 GOTO(out_ucred, rc);
1603 mq->mq_exp = info->mti_exp;
1604 rc = mdt_reint_rec(info, lhc);
1607 mdt_exit_ucred(info);
1609 mdt_client_compatibility(info);
1610 rc2 = mdt_fix_reply(info);
1616 static long mdt_reint_opcode(struct mdt_thread_info *info,
1617 const struct req_format **fmt)
1619 struct mdt_rec_reint *rec;
1622 opc = err_serious(-EFAULT);
1623 rec = req_capsule_client_get(info->mti_pill, &RMF_REC_REINT);
1625 opc = rec->rr_opcode;
1626 DEBUG_REQ(D_INODE, mdt_info_req(info), "reint opt = %ld", opc);
1627 if (opc < REINT_MAX && fmt[opc] != NULL)
1628 req_capsule_extend(info->mti_pill, fmt[opc]);
1630 CERROR("Unsupported opc: %ld\n", opc);
1631 opc = err_serious(opc);
1637 static int mdt_reint(struct mdt_thread_info *info)
1642 static const struct req_format *reint_fmts[REINT_MAX] = {
1643 [REINT_SETATTR] = &RQF_MDS_REINT_SETATTR,
1644 [REINT_CREATE] = &RQF_MDS_REINT_CREATE,
1645 [REINT_LINK] = &RQF_MDS_REINT_LINK,
1646 [REINT_UNLINK] = &RQF_MDS_REINT_UNLINK,
1647 [REINT_RENAME] = &RQF_MDS_REINT_RENAME,
1648 [REINT_OPEN] = &RQF_MDS_REINT_OPEN,
1649 [REINT_SETXATTR] = &RQF_MDS_REINT_SETXATTR
1654 opc = mdt_reint_opcode(info, reint_fmts);
1657 * No lock possible here from client to pass it to reint code
1660 rc = mdt_reint_internal(info, NULL, opc);
1665 info->mti_fail_id = OBD_FAIL_MDS_REINT_NET_REP;
1669 /* this should sync the whole device */
1670 static int mdt_device_sync(const struct lu_env *env, struct mdt_device *mdt)
1672 struct dt_device *dt = mdt->mdt_bottom;
1676 rc = dt->dd_ops->dt_sync(env, dt);
1680 /* this should sync this object */
1681 static int mdt_object_sync(struct mdt_thread_info *info)
1683 struct md_object *next;
1687 if (!mdt_object_exists(info->mti_object)) {
1688 CWARN("Non existing object "DFID"!\n",
1689 PFID(mdt_object_fid(info->mti_object)));
1692 next = mdt_object_child(info->mti_object);
1693 rc = mo_object_sync(info->mti_env, next);
1698 static int mdt_sync(struct mdt_thread_info *info)
1700 struct ptlrpc_request *req = mdt_info_req(info);
1701 struct req_capsule *pill = info->mti_pill;
1702 struct mdt_body *body;
1706 /* The fid may be zero, so we req_capsule_set manually */
1707 req_capsule_set(pill, &RQF_MDS_SYNC);
1709 body = req_capsule_client_get(pill, &RMF_MDT_BODY);
1711 RETURN(err_serious(-EINVAL));
1713 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_SYNC_PACK))
1714 RETURN(err_serious(-ENOMEM));
1716 if (fid_seq(&body->fid1) == 0) {
1717 /* sync the whole device */
1718 rc = req_capsule_server_pack(pill);
1720 rc = mdt_device_sync(info->mti_env, info->mti_mdt);
1722 rc = err_serious(rc);
1724 /* sync an object */
1725 rc = mdt_unpack_req_pack_rep(info, HABEO_CORPUS|HABEO_REFERO);
1727 rc = mdt_object_sync(info);
1729 struct md_object *next;
1730 const struct lu_fid *fid;
1731 struct lu_attr *la = &info->mti_attr.ma_attr;
1733 next = mdt_object_child(info->mti_object);
1734 info->mti_attr.ma_need = MA_INODE;
1735 info->mti_attr.ma_valid = 0;
1736 rc = mo_attr_get(info->mti_env, next,
1739 body = req_capsule_server_get(pill,
1741 fid = mdt_object_fid(info->mti_object);
1742 mdt_pack_attr2body(info, body, la, fid);
1746 rc = err_serious(rc);
1749 mdt_counter_incr(req->rq_export, LPROC_MDT_SYNC);
1754 #ifdef HAVE_QUOTA_SUPPORT
1755 static int mdt_quotacheck_handle(struct mdt_thread_info *info)
1757 struct obd_quotactl *oqctl;
1758 struct req_capsule *pill = info->mti_pill;
1759 struct obd_export *exp = info->mti_exp;
1760 struct md_quota *mq = md_quota(info->mti_env);
1761 struct md_device *next = info->mti_mdt->mdt_child;
1765 oqctl = req_capsule_client_get(pill, &RMF_OBD_QUOTACTL);
1769 /* remote client has no permission for quotacheck */
1770 if (unlikely(exp_connect_rmtclient(exp)))
1773 rc = req_capsule_server_pack(pill);
1778 rc = next->md_ops->mdo_quota.mqo_check(info->mti_env, next,
1783 static int mdt_quotactl_handle(struct mdt_thread_info *info)
1785 struct obd_quotactl *oqctl, *repoqc;
1786 struct req_capsule *pill = info->mti_pill;
1787 struct obd_export *exp = info->mti_exp;
1788 struct md_quota *mq = md_quota(info->mti_env);
1789 struct md_device *next = info->mti_mdt->mdt_child;
1790 const struct md_quota_operations *mqo = &next->md_ops->mdo_quota;
1794 oqctl = req_capsule_client_get(pill, &RMF_OBD_QUOTACTL);
1799 if (exp_connect_rmtclient(exp)) {
1800 struct ptlrpc_request *req = mdt_info_req(info);
1801 struct mdt_export_data *med = mdt_req2med(req);
1802 struct lustre_idmap_table *idmap = med->med_idmap;
1804 if (unlikely(oqctl->qc_cmd != Q_GETQUOTA &&
1805 oqctl->qc_cmd != Q_GETINFO))
1809 if (oqctl->qc_type == USRQUOTA)
1810 id = lustre_idmap_lookup_uid(NULL, idmap, 0,
1812 else if (oqctl->qc_type == GRPQUOTA)
1813 id = lustre_idmap_lookup_gid(NULL, idmap, 0,
1818 if (id == CFS_IDMAP_NOTFOUND) {
1819 CDEBUG(D_QUOTA, "no mapping for id %u\n",
1825 rc = req_capsule_server_pack(pill);
1829 repoqc = req_capsule_server_get(pill, &RMF_OBD_QUOTACTL);
1830 LASSERT(repoqc != NULL);
1833 switch (oqctl->qc_cmd) {
1835 rc = mqo->mqo_on(info->mti_env, next, oqctl->qc_type);
1838 rc = mqo->mqo_off(info->mti_env, next, oqctl->qc_type);
1841 rc = mqo->mqo_setinfo(info->mti_env, next, oqctl->qc_type, id,
1845 rc = mqo->mqo_getinfo(info->mti_env, next, oqctl->qc_type, id,
1849 rc = mqo->mqo_setquota(info->mti_env, next, oqctl->qc_type, id,
1853 rc = mqo->mqo_getquota(info->mti_env, next, oqctl->qc_type, id,
1857 rc = mqo->mqo_getoinfo(info->mti_env, next, oqctl->qc_type, id,
1861 rc = mqo->mqo_getoquota(info->mti_env, next, oqctl->qc_type, id,
1864 case LUSTRE_Q_INVALIDATE:
1865 rc = mqo->mqo_invalidate(info->mti_env, next, oqctl->qc_type);
1867 case LUSTRE_Q_FINVALIDATE:
1868 rc = mqo->mqo_finvalidate(info->mti_env, next, oqctl->qc_type);
1871 CERROR("unsupported mdt_quotactl command: %d\n",
1883 * OBD PING and other handlers.
1885 static int mdt_obd_ping(struct mdt_thread_info *info)
1890 req_capsule_set(info->mti_pill, &RQF_OBD_PING);
1892 rc = target_handle_ping(mdt_info_req(info));
1894 rc = err_serious(rc);
1898 static int mdt_obd_log_cancel(struct mdt_thread_info *info)
1900 return err_serious(-EOPNOTSUPP);
1903 static int mdt_obd_qc_callback(struct mdt_thread_info *info)
1905 return err_serious(-EOPNOTSUPP);
1913 /** clone llog ctxt from child (mdd)
1914 * This allows remote llog (replicator) access.
1915 * We can either pass all llog RPCs (eg mdt_llog_create) on to child where the
1916 * context was originally set up, or we can handle them directly.
1917 * I choose the latter, but that means I need any llog
1918 * contexts set up by child to be accessable by the mdt. So we clone the
1919 * context into our context list here.
1921 static int mdt_llog_ctxt_clone(const struct lu_env *env, struct mdt_device *mdt,
1924 struct md_device *next = mdt->mdt_child;
1925 struct llog_ctxt *ctxt;
1928 if (!llog_ctxt_null(mdt2obd_dev(mdt), idx))
1931 rc = next->md_ops->mdo_llog_ctxt_get(env, next, idx, (void **)&ctxt);
1932 if (rc || ctxt == NULL) {
1933 CERROR("Can't get mdd ctxt %d\n", rc);
1937 rc = llog_group_set_ctxt(&mdt2obd_dev(mdt)->obd_olg, ctxt, idx);
1939 CERROR("Can't set mdt ctxt %d\n", rc);
1944 static int mdt_llog_ctxt_unclone(const struct lu_env *env,
1945 struct mdt_device *mdt, int idx)
1947 struct llog_ctxt *ctxt;
1949 ctxt = llog_get_context(mdt2obd_dev(mdt), idx);
1952 /* Put once for the get we just did, and once for the clone */
1953 llog_ctxt_put(ctxt);
1954 llog_ctxt_put(ctxt);
1958 static int mdt_llog_create(struct mdt_thread_info *info)
1962 req_capsule_set(info->mti_pill, &RQF_LLOG_ORIGIN_HANDLE_CREATE);
1963 rc = llog_origin_handle_create(mdt_info_req(info));
1964 return (rc < 0 ? err_serious(rc) : rc);
1967 static int mdt_llog_destroy(struct mdt_thread_info *info)
1971 req_capsule_set(info->mti_pill, &RQF_LLOG_ORIGIN_HANDLE_DESTROY);
1972 rc = llog_origin_handle_destroy(mdt_info_req(info));
1973 return (rc < 0 ? err_serious(rc) : rc);
1976 static int mdt_llog_read_header(struct mdt_thread_info *info)
1980 req_capsule_set(info->mti_pill, &RQF_LLOG_ORIGIN_HANDLE_READ_HEADER);
1981 rc = llog_origin_handle_read_header(mdt_info_req(info));
1982 return (rc < 0 ? err_serious(rc) : rc);
1985 static int mdt_llog_next_block(struct mdt_thread_info *info)
1989 req_capsule_set(info->mti_pill, &RQF_LLOG_ORIGIN_HANDLE_NEXT_BLOCK);
1990 rc = llog_origin_handle_next_block(mdt_info_req(info));
1991 return (rc < 0 ? err_serious(rc) : rc);
1994 static int mdt_llog_prev_block(struct mdt_thread_info *info)
1998 req_capsule_set(info->mti_pill, &RQF_LLOG_ORIGIN_HANDLE_PREV_BLOCK);
1999 rc = llog_origin_handle_prev_block(mdt_info_req(info));
2000 return (rc < 0 ? err_serious(rc) : rc);
2007 static struct ldlm_callback_suite cbs = {
2008 .lcs_completion = ldlm_server_completion_ast,
2009 .lcs_blocking = ldlm_server_blocking_ast,
2013 static int mdt_enqueue(struct mdt_thread_info *info)
2015 struct ptlrpc_request *req;
2019 * info->mti_dlm_req already contains swapped and (if necessary)
2020 * converted dlm request.
2022 LASSERT(info->mti_dlm_req != NULL);
2024 req = mdt_info_req(info);
2025 rc = ldlm_handle_enqueue0(info->mti_mdt->mdt_namespace,
2026 req, info->mti_dlm_req, &cbs);
2027 info->mti_fail_id = OBD_FAIL_LDLM_REPLY;
2028 return rc ? err_serious(rc) : req->rq_status;
2031 static int mdt_convert(struct mdt_thread_info *info)
2034 struct ptlrpc_request *req;
2036 LASSERT(info->mti_dlm_req);
2037 req = mdt_info_req(info);
2038 rc = ldlm_handle_convert0(req, info->mti_dlm_req);
2039 return rc ? err_serious(rc) : req->rq_status;
2042 static int mdt_bl_callback(struct mdt_thread_info *info)
2044 CERROR("bl callbacks should not happen on MDS\n");
2046 return err_serious(-EOPNOTSUPP);
2049 static int mdt_cp_callback(struct mdt_thread_info *info)
2051 CERROR("cp callbacks should not happen on MDS\n");
2053 return err_serious(-EOPNOTSUPP);
2057 * sec context handlers
2059 static int mdt_sec_ctx_handle(struct mdt_thread_info *info)
2063 rc = mdt_handle_idmap(info);
2066 struct ptlrpc_request *req = mdt_info_req(info);
2069 opc = lustre_msg_get_opc(req->rq_reqmsg);
2070 if (opc == SEC_CTX_INIT || opc == SEC_CTX_INIT_CONT)
2071 sptlrpc_svc_ctx_invalidate(req);
2074 CFS_FAIL_TIMEOUT(OBD_FAIL_SEC_CTX_HDL_PAUSE, cfs_fail_val);
2079 static struct mdt_object *mdt_obj(struct lu_object *o)
2081 LASSERT(lu_device_is_mdt(o->lo_dev));
2082 return container_of0(o, struct mdt_object, mot_obj.mo_lu);
2085 struct mdt_object *mdt_object_find(const struct lu_env *env,
2086 struct mdt_device *d,
2087 const struct lu_fid *f)
2089 struct lu_object *o;
2090 struct mdt_object *m;
2093 CDEBUG(D_INFO, "Find object for "DFID"\n", PFID(f));
2094 o = lu_object_find(env, &d->mdt_md_dev.md_lu_dev, f, NULL);
2095 if (unlikely(IS_ERR(o)))
2096 m = (struct mdt_object *)o;
2103 * Asyncronous commit for mdt device.
2105 * Pass asynchonous commit call down the MDS stack.
2107 * \param env environment
2108 * \param mdt the mdt device
2110 static void mdt_device_commit_async(const struct lu_env *env,
2111 struct mdt_device *mdt)
2113 struct dt_device *dt = mdt->mdt_bottom;
2116 rc = dt->dd_ops->dt_commit_async(env, dt);
2117 if (unlikely(rc != 0))
2118 CWARN("async commit start failed with rc = %d", rc);
2122 * Mark the lock as "synchonous".
2124 * Mark the lock to deffer transaction commit to the unlock time.
2126 * \param lock the lock to mark as "synchonous"
2128 * \see mdt_is_lock_sync
2129 * \see mdt_save_lock
2131 static inline void mdt_set_lock_sync(struct ldlm_lock *lock)
2133 lock->l_ast_data = (void*)1;
2137 * Check whehter the lock "synchonous" or not.
2139 * \param lock the lock to check
2140 * \retval 1 the lock is "synchonous"
2141 * \retval 0 the lock isn't "synchronous"
2143 * \see mdt_set_lock_sync
2144 * \see mdt_save_lock
2146 static inline int mdt_is_lock_sync(struct ldlm_lock *lock)
2148 return lock->l_ast_data != NULL;
2152 * Blocking AST for mdt locks.
2154 * Starts transaction commit if in case of COS lock conflict or
2155 * deffers such a commit to the mdt_save_lock.
2157 * \param lock the lock which blocks a request or cancelling lock
2158 * \param desc unused
2159 * \param data unused
2160 * \param flag indicates whether this cancelling or blocking callback
2162 * \see ldlm_blocking_ast_nocheck
2164 int mdt_blocking_ast(struct ldlm_lock *lock, struct ldlm_lock_desc *desc,
2165 void *data, int flag)
2167 struct obd_device *obd = ldlm_lock_to_ns(lock)->ns_obd;
2168 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
2172 if (flag == LDLM_CB_CANCELING)
2174 lock_res_and_lock(lock);
2175 if (lock->l_blocking_ast != mdt_blocking_ast) {
2176 unlock_res_and_lock(lock);
2179 if (mdt_cos_is_enabled(mdt) &&
2180 lock->l_req_mode & (LCK_PW | LCK_EX) &&
2181 lock->l_blocking_lock != NULL &&
2182 lock->l_client_cookie != lock->l_blocking_lock->l_client_cookie) {
2183 mdt_set_lock_sync(lock);
2185 rc = ldlm_blocking_ast_nocheck(lock);
2187 /* There is no lock conflict if l_blocking_lock == NULL,
2188 * it indicates a blocking ast sent from ldlm_lock_decref_internal
2189 * when the last reference to a local lock was released */
2190 if (lock->l_req_mode == LCK_COS && lock->l_blocking_lock != NULL) {
2193 rc = lu_env_init(&env, LCT_MD_THREAD);
2194 if (unlikely(rc != 0))
2195 CWARN("lu_env initialization failed with rc = %d,"
2196 "cannot start asynchronous commit\n", rc);
2198 mdt_device_commit_async(&env, mdt);
2204 int mdt_object_lock(struct mdt_thread_info *info, struct mdt_object *o,
2205 struct mdt_lock_handle *lh, __u64 ibits, int locality)
2207 struct ldlm_namespace *ns = info->mti_mdt->mdt_namespace;
2208 ldlm_policy_data_t *policy = &info->mti_policy;
2209 struct ldlm_res_id *res_id = &info->mti_res_id;
2213 LASSERT(!lustre_handle_is_used(&lh->mlh_reg_lh));
2214 LASSERT(!lustre_handle_is_used(&lh->mlh_pdo_lh));
2215 LASSERT(lh->mlh_reg_mode != LCK_MINMODE);
2216 LASSERT(lh->mlh_type != MDT_NUL_LOCK);
2218 if (mdt_object_exists(o) < 0) {
2219 if (locality == MDT_CROSS_LOCK) {
2220 /* cross-ref object fix */
2221 ibits &= ~MDS_INODELOCK_UPDATE;
2222 ibits |= MDS_INODELOCK_LOOKUP;
2224 LASSERT(!(ibits & MDS_INODELOCK_UPDATE));
2225 LASSERT(ibits & MDS_INODELOCK_LOOKUP);
2227 /* No PDO lock on remote object */
2228 LASSERT(lh->mlh_type != MDT_PDO_LOCK);
2231 if (lh->mlh_type == MDT_PDO_LOCK) {
2232 /* check for exists after object is locked */
2233 if (mdt_object_exists(o) == 0) {
2234 /* Non-existent object shouldn't have PDO lock */
2237 /* Non-dir object shouldn't have PDO lock */
2238 if (!S_ISDIR(lu_object_attr(&o->mot_obj.mo_lu)))
2243 memset(policy, 0, sizeof(*policy));
2244 fid_build_reg_res_name(mdt_object_fid(o), res_id);
2247 * Take PDO lock on whole directory and build correct @res_id for lock
2248 * on part of directory.
2250 if (lh->mlh_pdo_hash != 0) {
2251 LASSERT(lh->mlh_type == MDT_PDO_LOCK);
2252 mdt_lock_pdo_mode(info, o, lh);
2253 if (lh->mlh_pdo_mode != LCK_NL) {
2255 * Do not use LDLM_FL_LOCAL_ONLY for parallel lock, it
2256 * is never going to be sent to client and we do not
2257 * want it slowed down due to possible cancels.
2259 policy->l_inodebits.bits = MDS_INODELOCK_UPDATE;
2260 rc = mdt_fid_lock(ns, &lh->mlh_pdo_lh, lh->mlh_pdo_mode,
2261 policy, res_id, LDLM_FL_ATOMIC_CB,
2262 &info->mti_exp->exp_handle.h_cookie);
2268 * Finish res_id initializing by name hash marking part of
2269 * directory which is taking modification.
2271 res_id->name[LUSTRE_RES_ID_HSH_OFF] = lh->mlh_pdo_hash;
2274 policy->l_inodebits.bits = ibits;
2277 * Use LDLM_FL_LOCAL_ONLY for this lock. We do not know yet if it is
2278 * going to be sent to client. If it is - mdt_intent_policy() path will
2279 * fix it up and turn FL_LOCAL flag off.
2281 rc = mdt_fid_lock(ns, &lh->mlh_reg_lh, lh->mlh_reg_mode, policy,
2282 res_id, LDLM_FL_LOCAL_ONLY | LDLM_FL_ATOMIC_CB,
2283 &info->mti_exp->exp_handle.h_cookie);
2285 mdt_object_unlock(info, o, lh, 1);
2286 else if (unlikely(OBD_FAIL_PRECHECK(OBD_FAIL_MDS_PDO_LOCK)) &&
2287 lh->mlh_pdo_hash != 0 &&
2288 (lh->mlh_reg_mode == LCK_PW || lh->mlh_reg_mode == LCK_EX)) {
2289 OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_PDO_LOCK, 15);
2296 * Save a lock within request object.
2298 * Keep the lock referenced until whether client ACK or transaction
2299 * commit happens or release the lock immediately depending on input
2300 * parameters. If COS is ON, a write lock is converted to COS lock
2303 * \param info thead info object
2304 * \param h lock handle
2305 * \param mode lock mode
2306 * \param decref force immediate lock releasing
2309 void mdt_save_lock(struct mdt_thread_info *info, struct lustre_handle *h,
2310 ldlm_mode_t mode, int decref)
2314 if (lustre_handle_is_used(h)) {
2315 if (decref || !info->mti_has_trans ||
2316 !(mode & (LCK_PW | LCK_EX))){
2317 mdt_fid_unlock(h, mode);
2319 struct mdt_device *mdt = info->mti_mdt;
2320 struct ldlm_lock *lock = ldlm_handle2lock(h);
2321 struct ptlrpc_request *req = mdt_info_req(info);
2324 LASSERTF(lock != NULL, "no lock for cookie "LPX64"\n",
2326 CDEBUG(D_HA, "request = %p reply state = %p"
2327 " transno = "LPD64"\n",
2328 req, req->rq_reply_state, req->rq_transno);
2329 if (mdt_cos_is_enabled(mdt)) {
2331 ldlm_lock_downgrade(lock, LCK_COS);
2334 ptlrpc_save_lock(req, h, mode, no_ack);
2335 if (mdt_is_lock_sync(lock)) {
2336 CDEBUG(D_HA, "found sync-lock,"
2337 " async commit started\n");
2338 mdt_device_commit_async(info->mti_env,
2341 LDLM_LOCK_PUT(lock);
2350 * Unlock mdt object.
2352 * Immeditely release the regular lock and the PDO lock or save the
2353 * lock in reqeuest and keep them referenced until client ACK or
2354 * transaction commit.
2356 * \param info thread info object
2357 * \param o mdt object
2358 * \param lh mdt lock handle referencing regular and PDO locks
2359 * \param decref force immediate lock releasing
2361 void mdt_object_unlock(struct mdt_thread_info *info, struct mdt_object *o,
2362 struct mdt_lock_handle *lh, int decref)
2366 mdt_save_lock(info, &lh->mlh_pdo_lh, lh->mlh_pdo_mode, decref);
2367 mdt_save_lock(info, &lh->mlh_reg_lh, lh->mlh_reg_mode, decref);
2372 struct mdt_object *mdt_object_find_lock(struct mdt_thread_info *info,
2373 const struct lu_fid *f,
2374 struct mdt_lock_handle *lh,
2377 struct mdt_object *o;
2379 o = mdt_object_find(info->mti_env, info->mti_mdt, f);
2383 rc = mdt_object_lock(info, o, lh, ibits,
2386 mdt_object_put(info->mti_env, o);
2393 void mdt_object_unlock_put(struct mdt_thread_info * info,
2394 struct mdt_object * o,
2395 struct mdt_lock_handle *lh,
2398 mdt_object_unlock(info, o, lh, decref);
2399 mdt_object_put(info->mti_env, o);
2402 static struct mdt_handler *mdt_handler_find(__u32 opc,
2403 struct mdt_opc_slice *supported)
2405 struct mdt_opc_slice *s;
2406 struct mdt_handler *h;
2409 for (s = supported; s->mos_hs != NULL; s++) {
2410 if (s->mos_opc_start <= opc && opc < s->mos_opc_end) {
2411 h = s->mos_hs + (opc - s->mos_opc_start);
2412 if (likely(h->mh_opc != 0))
2413 LASSERTF(h->mh_opc == opc,
2414 "opcode mismatch %d != %d\n",
2417 h = NULL; /* unsupported opc */
2424 static int mdt_lock_resname_compat(struct mdt_device *m,
2425 struct ldlm_request *req)
2427 /* XXX something... later. */
2431 static int mdt_lock_reply_compat(struct mdt_device *m, struct ldlm_reply *rep)
2433 /* XXX something... later. */
2438 * Generic code handling requests that have struct mdt_body passed in:
2440 * - extract mdt_body from request and save it in @info, if present;
2442 * - create lu_object, corresponding to the fid in mdt_body, and save it in
2445 * - if HABEO_CORPUS flag is set for this request type check whether object
2446 * actually exists on storage (lu_object_exists()).
2449 static int mdt_body_unpack(struct mdt_thread_info *info, __u32 flags)
2451 const struct mdt_body *body;
2452 struct mdt_object *obj;
2453 const struct lu_env *env;
2454 struct req_capsule *pill;
2458 env = info->mti_env;
2459 pill = info->mti_pill;
2461 body = info->mti_body = req_capsule_client_get(pill, &RMF_MDT_BODY);
2465 if (!(body->valid & OBD_MD_FLID))
2468 if (!fid_is_sane(&body->fid1)) {
2469 CERROR("Invalid fid: "DFID"\n", PFID(&body->fid1));
2474 * Do not get size or any capa fields before we check that request
2475 * contains capa actually. There are some requests which do not, for
2476 * instance MDS_IS_SUBDIR.
2478 if (req_capsule_has_field(pill, &RMF_CAPA1, RCL_CLIENT) &&
2479 req_capsule_get_size(pill, &RMF_CAPA1, RCL_CLIENT))
2480 mdt_set_capainfo(info, 0, &body->fid1,
2481 req_capsule_client_get(pill, &RMF_CAPA1));
2483 obj = mdt_object_find(env, info->mti_mdt, &body->fid1);
2485 if ((flags & HABEO_CORPUS) &&
2486 !mdt_object_exists(obj)) {
2487 mdt_object_put(env, obj);
2488 /* for capability renew ENOENT will be handled in
2490 if (body->valid & OBD_MD_FLOSSCAPA)
2495 info->mti_object = obj;
2504 static int mdt_unpack_req_pack_rep(struct mdt_thread_info *info, __u32 flags)
2506 struct req_capsule *pill = info->mti_pill;
2510 if (req_capsule_has_field(pill, &RMF_MDT_BODY, RCL_CLIENT))
2511 rc = mdt_body_unpack(info, flags);
2515 if (rc == 0 && (flags & HABEO_REFERO)) {
2517 if (req_capsule_has_field(pill, &RMF_MDT_MD, RCL_SERVER))
2518 req_capsule_set_size(pill, &RMF_MDT_MD, RCL_SERVER,
2519 info->mti_body->eadatasize);
2520 if (req_capsule_has_field(pill, &RMF_LOGCOOKIES, RCL_SERVER))
2521 req_capsule_set_size(pill, &RMF_LOGCOOKIES, RCL_SERVER,
2522 info->mti_mdt->mdt_max_cookiesize);
2524 rc = req_capsule_server_pack(pill);
2529 static int mdt_init_capa_ctxt(const struct lu_env *env, struct mdt_device *m)
2531 struct md_device *next = m->mdt_child;
2533 return next->md_ops->mdo_init_capa_ctxt(env, next,
2534 m->mdt_opts.mo_mds_capa,
2535 m->mdt_capa_timeout,
2541 * Invoke handler for this request opc. Also do necessary preprocessing
2542 * (according to handler ->mh_flags), and post-processing (setting of
2543 * ->last_{xid,committed}).
2545 static int mdt_req_handle(struct mdt_thread_info *info,
2546 struct mdt_handler *h, struct ptlrpc_request *req)
2548 int rc, serious = 0;
2553 LASSERT(h->mh_act != NULL);
2554 LASSERT(h->mh_opc == lustre_msg_get_opc(req->rq_reqmsg));
2555 LASSERT(current->journal_info == NULL);
2558 * Checking for various OBD_FAIL_$PREF_$OPC_NET codes. _Do_ not try
2559 * to put same checks into handlers like mdt_close(), mdt_reint(),
2560 * etc., without talking to mdt authors first. Checking same thing
2561 * there again is useless and returning 0 error without packing reply
2562 * is buggy! Handlers either pack reply or return error.
2564 * We return 0 here and do not send any reply in order to emulate
2565 * network failure. Do not send any reply in case any of NET related
2566 * fail_id has occured.
2568 if (OBD_FAIL_CHECK_ORSET(h->mh_fail_id, OBD_FAIL_ONCE))
2572 flags = h->mh_flags;
2573 LASSERT(ergo(flags & (HABEO_CORPUS|HABEO_REFERO), h->mh_fmt != NULL));
2575 if (h->mh_fmt != NULL) {
2576 req_capsule_set(info->mti_pill, h->mh_fmt);
2577 rc = mdt_unpack_req_pack_rep(info, flags);
2580 if (rc == 0 && flags & MUTABOR &&
2581 req->rq_export->exp_connect_flags & OBD_CONNECT_RDONLY)
2582 /* should it be rq_status? */
2585 if (rc == 0 && flags & HABEO_CLAVIS) {
2586 struct ldlm_request *dlm_req;
2588 LASSERT(h->mh_fmt != NULL);
2590 dlm_req = req_capsule_client_get(info->mti_pill, &RMF_DLM_REQ);
2591 if (dlm_req != NULL) {
2592 if (unlikely(dlm_req->lock_desc.l_resource.lr_type ==
2594 dlm_req->lock_desc.l_policy_data.\
2595 l_inodebits.bits == 0)) {
2597 * Lock without inodebits makes no sense and
2598 * will oops later in ldlm. If client miss to
2599 * set such bits, do not trigger ASSERTION.
2601 * For liblustre flock case, it maybe zero.
2605 if (info->mti_mdt->mdt_opts.mo_compat_resname)
2606 rc = mdt_lock_resname_compat(
2609 info->mti_dlm_req = dlm_req;
2616 /* capability setting changed via /proc, needs reinitialize ctxt */
2617 if (info->mti_mdt && info->mti_mdt->mdt_capa_conf) {
2618 mdt_init_capa_ctxt(info->mti_env, info->mti_mdt);
2619 info->mti_mdt->mdt_capa_conf = 0;
2622 if (likely(rc == 0)) {
2624 * Process request, there can be two types of rc:
2625 * 1) errors with msg unpack/pack, other failures outside the
2626 * operation itself. This is counted as serious errors;
2627 * 2) errors during fs operation, should be placed in rq_status
2630 rc = h->mh_act(info);
2632 !req->rq_no_reply && req->rq_reply_state == NULL) {
2633 DEBUG_REQ(D_ERROR, req, "MDT \"handler\" %s did not "
2634 "pack reply and returned 0 error\n",
2638 serious = is_serious(rc);
2639 rc = clear_serious(rc);
2643 req->rq_status = rc;
2646 * ELDLM_* codes which > 0 should be in rq_status only as well as
2647 * all non-serious errors.
2649 if (rc > 0 || !serious)
2652 LASSERT(current->journal_info == NULL);
2654 if (rc == 0 && (flags & HABEO_CLAVIS) &&
2655 info->mti_mdt->mdt_opts.mo_compat_resname) {
2656 struct ldlm_reply *dlmrep;
2658 dlmrep = req_capsule_server_get(info->mti_pill, &RMF_DLM_REP);
2660 rc = mdt_lock_reply_compat(info->mti_mdt, dlmrep);
2663 /* If we're DISCONNECTing, the mdt_export_data is already freed */
2664 if (likely(rc == 0 && req->rq_export && h->mh_opc != MDS_DISCONNECT))
2665 target_committed_to_req(req);
2667 if (unlikely(req_is_replay(req) &&
2668 lustre_msg_get_transno(req->rq_reqmsg) == 0)) {
2669 DEBUG_REQ(D_ERROR, req, "transno is 0 during REPLAY");
2673 target_send_reply(req, rc, info->mti_fail_id);
2677 void mdt_lock_handle_init(struct mdt_lock_handle *lh)
2679 lh->mlh_type = MDT_NUL_LOCK;
2680 lh->mlh_reg_lh.cookie = 0ull;
2681 lh->mlh_reg_mode = LCK_MINMODE;
2682 lh->mlh_pdo_lh.cookie = 0ull;
2683 lh->mlh_pdo_mode = LCK_MINMODE;
2686 void mdt_lock_handle_fini(struct mdt_lock_handle *lh)
2688 LASSERT(!lustre_handle_is_used(&lh->mlh_reg_lh));
2689 LASSERT(!lustre_handle_is_used(&lh->mlh_pdo_lh));
2693 * Initialize fields of struct mdt_thread_info. Other fields are left in
2694 * uninitialized state, because it's too expensive to zero out whole
2695 * mdt_thread_info (> 1K) on each request arrival.
2697 static void mdt_thread_info_init(struct ptlrpc_request *req,
2698 struct mdt_thread_info *info)
2701 struct md_capainfo *ci;
2703 req_capsule_init(&req->rq_pill, req, RCL_SERVER);
2704 info->mti_pill = &req->rq_pill;
2707 for (i = 0; i < ARRAY_SIZE(info->mti_lh); i++)
2708 mdt_lock_handle_init(&info->mti_lh[i]);
2710 /* mdt device: it can be NULL while CONNECT */
2711 if (req->rq_export) {
2712 info->mti_mdt = mdt_dev(req->rq_export->exp_obd->obd_lu_dev);
2713 info->mti_exp = req->rq_export;
2715 info->mti_mdt = NULL;
2716 info->mti_env = req->rq_svc_thread->t_env;
2717 ci = md_capainfo(info->mti_env);
2718 memset(ci, 0, sizeof *ci);
2719 if (req->rq_export) {
2720 if (exp_connect_rmtclient(req->rq_export))
2721 ci->mc_auth = LC_ID_CONVERT;
2722 else if (req->rq_export->exp_connect_flags &
2723 OBD_CONNECT_MDS_CAPA)
2724 ci->mc_auth = LC_ID_PLAIN;
2726 ci->mc_auth = LC_ID_NONE;
2729 info->mti_fail_id = OBD_FAIL_MDS_ALL_REPLY_NET;
2730 info->mti_transno = lustre_msg_get_transno(req->rq_reqmsg);
2731 info->mti_mos = NULL;
2733 memset(&info->mti_attr, 0, sizeof(info->mti_attr));
2734 info->mti_body = NULL;
2735 info->mti_object = NULL;
2736 info->mti_dlm_req = NULL;
2737 info->mti_has_trans = 0;
2738 info->mti_no_need_trans = 0;
2739 info->mti_cross_ref = 0;
2740 info->mti_opdata = 0;
2742 /* To not check for split by default. */
2743 info->mti_spec.sp_ck_split = 0;
2744 info->mti_spec.no_create = 0;
2747 static void mdt_thread_info_fini(struct mdt_thread_info *info)
2751 req_capsule_fini(info->mti_pill);
2752 if (info->mti_object != NULL) {
2754 * freeing an object may lead to OSD level transaction, do not
2755 * let it mess with MDT. bz19385.
2757 info->mti_no_need_trans = 1;
2758 mdt_object_put(info->mti_env, info->mti_object);
2759 info->mti_object = NULL;
2761 for (i = 0; i < ARRAY_SIZE(info->mti_lh); i++)
2762 mdt_lock_handle_fini(&info->mti_lh[i]);
2763 info->mti_env = NULL;
2766 static int mdt_filter_recovery_request(struct ptlrpc_request *req,
2767 struct obd_device *obd, int *process)
2769 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
2770 case MDS_CONNECT: /* This will never get here, but for completeness. */
2771 case OST_CONNECT: /* This will never get here, but for completeness. */
2772 case MDS_DISCONNECT:
2773 case OST_DISCONNECT:
2778 case MDS_DONE_WRITING:
2779 case MDS_SYNC: /* used in unmounting */
2785 *process = target_queue_recovery_request(req, obd);
2789 DEBUG_REQ(D_ERROR, req, "not permitted during recovery");
2796 * Handle recovery. Return:
2797 * +1: continue request processing;
2798 * -ve: abort immediately with the given error code;
2799 * 0: send reply with error code in req->rq_status;
2801 static int mdt_recovery(struct mdt_thread_info *info)
2803 struct ptlrpc_request *req = mdt_info_req(info);
2804 struct obd_device *obd;
2808 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
2811 case SEC_CTX_INIT_CONT:
2817 rc = mdt_handle_idmap(info);
2826 if (unlikely(!class_connected_export(req->rq_export))) {
2827 CERROR("operation %d on unconnected MDS from %s\n",
2828 lustre_msg_get_opc(req->rq_reqmsg),
2829 libcfs_id2str(req->rq_peer));
2830 /* FIXME: For CMD cleanup, when mds_B stop, the req from
2831 * mds_A will get -ENOTCONN(especially for ping req),
2832 * which will cause that mds_A deactive timeout, then when
2833 * mds_A cleanup, the cleanup process will be suspended since
2834 * deactive timeout is not zero.
2836 req->rq_status = -ENOTCONN;
2837 target_send_reply(req, -ENOTCONN, info->mti_fail_id);
2841 /* sanity check: if the xid matches, the request must be marked as a
2842 * resent or replayed */
2843 if (req_xid_is_last(req)) {
2844 if (!(lustre_msg_get_flags(req->rq_reqmsg) &
2845 (MSG_RESENT | MSG_REPLAY))) {
2846 DEBUG_REQ(D_WARNING, req, "rq_xid "LPU64" matches last_xid, "
2847 "expected REPLAY or RESENT flag (%x)", req->rq_xid,
2848 lustre_msg_get_flags(req->rq_reqmsg));
2850 req->rq_status = -ENOTCONN;
2855 /* else: note the opposite is not always true; a RESENT req after a
2856 * failover will usually not match the last_xid, since it was likely
2857 * never committed. A REPLAYed request will almost never match the
2858 * last xid, however it could for a committed, but still retained,
2861 obd = req->rq_export->exp_obd;
2863 /* Check for aborted recovery... */
2864 if (unlikely(obd->obd_recovering)) {
2867 DEBUG_REQ(D_INFO, req, "Got new replay");
2868 rc = mdt_filter_recovery_request(req, obd, &should_process);
2869 if (rc != 0 || !should_process)
2871 else if (should_process < 0) {
2872 req->rq_status = should_process;
2873 rc = ptlrpc_error(req);
2880 static int mdt_msg_check_version(struct lustre_msg *msg)
2884 switch (lustre_msg_get_opc(msg)) {
2886 case MDS_DISCONNECT:
2889 case SEC_CTX_INIT_CONT:
2891 rc = lustre_msg_check_version(msg, LUSTRE_OBD_VERSION);
2893 CERROR("bad opc %u version %08x, expecting %08x\n",
2894 lustre_msg_get_opc(msg),
2895 lustre_msg_get_version(msg),
2896 LUSTRE_OBD_VERSION);
2900 case MDS_GETATTR_NAME:
2907 case MDS_DONE_WRITING:
2914 case MDS_QUOTACHECK:
2920 rc = lustre_msg_check_version(msg, LUSTRE_MDS_VERSION);
2922 CERROR("bad opc %u version %08x, expecting %08x\n",
2923 lustre_msg_get_opc(msg),
2924 lustre_msg_get_version(msg),
2925 LUSTRE_MDS_VERSION);
2929 case LDLM_BL_CALLBACK:
2930 case LDLM_CP_CALLBACK:
2931 rc = lustre_msg_check_version(msg, LUSTRE_DLM_VERSION);
2933 CERROR("bad opc %u version %08x, expecting %08x\n",
2934 lustre_msg_get_opc(msg),
2935 lustre_msg_get_version(msg),
2936 LUSTRE_DLM_VERSION);
2938 case OBD_LOG_CANCEL:
2939 case LLOG_ORIGIN_HANDLE_CREATE:
2940 case LLOG_ORIGIN_HANDLE_NEXT_BLOCK:
2941 case LLOG_ORIGIN_HANDLE_READ_HEADER:
2942 case LLOG_ORIGIN_HANDLE_CLOSE:
2943 case LLOG_ORIGIN_HANDLE_DESTROY:
2944 case LLOG_ORIGIN_HANDLE_PREV_BLOCK:
2946 rc = lustre_msg_check_version(msg, LUSTRE_LOG_VERSION);
2948 CERROR("bad opc %u version %08x, expecting %08x\n",
2949 lustre_msg_get_opc(msg),
2950 lustre_msg_get_version(msg),
2951 LUSTRE_LOG_VERSION);
2954 CERROR("MDS unknown opcode %d\n", lustre_msg_get_opc(msg));
2960 static int mdt_handle0(struct ptlrpc_request *req,
2961 struct mdt_thread_info *info,
2962 struct mdt_opc_slice *supported)
2964 struct mdt_handler *h;
2965 struct lustre_msg *msg;
2970 if (OBD_FAIL_CHECK_ORSET(OBD_FAIL_MDS_ALL_REQUEST_NET, OBD_FAIL_ONCE))
2973 LASSERT(current->journal_info == NULL);
2975 msg = req->rq_reqmsg;
2976 rc = mdt_msg_check_version(msg);
2977 if (likely(rc == 0)) {
2978 rc = mdt_recovery(info);
2979 if (likely(rc == +1)) {
2980 h = mdt_handler_find(lustre_msg_get_opc(msg),
2982 if (likely(h != NULL)) {
2983 rc = mdt_req_handle(info, h, req);
2985 CERROR("The unsupported opc: 0x%x\n",
2986 lustre_msg_get_opc(msg) );
2987 req->rq_status = -ENOTSUPP;
2988 rc = ptlrpc_error(req);
2993 CERROR(LUSTRE_MDT_NAME" drops mal-formed request\n");
2998 * MDT handler function called by ptlrpc service thread when request comes.
3000 * XXX common "target" functionality should be factored into separate module
3001 * shared by mdt, ost and stand-alone services like fld.
3003 static int mdt_handle_common(struct ptlrpc_request *req,
3004 struct mdt_opc_slice *supported)
3007 struct mdt_thread_info *info;
3011 env = req->rq_svc_thread->t_env;
3012 LASSERT(env != NULL);
3013 LASSERT(env->le_ses != NULL);
3014 LASSERT(env->le_ctx.lc_thread == req->rq_svc_thread);
3015 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
3016 LASSERT(info != NULL);
3018 mdt_thread_info_init(req, info);
3020 rc = mdt_handle0(req, info, supported);
3022 mdt_thread_info_fini(info);
3027 * This is called from recovery code as handler of _all_ RPC types, FLD and SEQ
3030 int mdt_recovery_handle(struct ptlrpc_request *req)
3035 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
3037 rc = mdt_handle_common(req, mdt_fld_handlers);
3040 rc = mdt_handle_common(req, mdt_seq_handlers);
3043 rc = mdt_handle_common(req, mdt_regular_handlers);
3050 static int mdt_regular_handle(struct ptlrpc_request *req)
3052 return mdt_handle_common(req, mdt_regular_handlers);
3055 static int mdt_readpage_handle(struct ptlrpc_request *req)
3057 return mdt_handle_common(req, mdt_readpage_handlers);
3060 static int mdt_xmds_handle(struct ptlrpc_request *req)
3062 return mdt_handle_common(req, mdt_xmds_handlers);
3065 static int mdt_mdsc_handle(struct ptlrpc_request *req)
3067 return mdt_handle_common(req, mdt_seq_handlers);
3070 static int mdt_mdss_handle(struct ptlrpc_request *req)
3072 return mdt_handle_common(req, mdt_seq_handlers);
3075 static int mdt_dtss_handle(struct ptlrpc_request *req)
3077 return mdt_handle_common(req, mdt_seq_handlers);
3080 static int mdt_fld_handle(struct ptlrpc_request *req)
3082 return mdt_handle_common(req, mdt_fld_handlers);
3099 static int mdt_intent_getattr(enum mdt_it_code opcode,
3100 struct mdt_thread_info *info,
3101 struct ldlm_lock **,
3103 static int mdt_intent_reint(enum mdt_it_code opcode,
3104 struct mdt_thread_info *info,
3105 struct ldlm_lock **,
3108 static struct mdt_it_flavor {
3109 const struct req_format *it_fmt;
3111 int (*it_act)(enum mdt_it_code ,
3112 struct mdt_thread_info *,
3113 struct ldlm_lock **,
3116 } mdt_it_flavor[] = {
3118 .it_fmt = &RQF_LDLM_INTENT,
3119 /*.it_flags = HABEO_REFERO,*/
3121 .it_act = mdt_intent_reint,
3122 .it_reint = REINT_OPEN
3125 .it_fmt = &RQF_LDLM_INTENT,
3126 .it_flags = MUTABOR,
3127 .it_act = mdt_intent_reint,
3128 .it_reint = REINT_OPEN
3131 .it_fmt = &RQF_LDLM_INTENT,
3132 .it_flags = MUTABOR,
3133 .it_act = mdt_intent_reint,
3134 .it_reint = REINT_CREATE
3136 [MDT_IT_GETATTR] = {
3137 .it_fmt = &RQF_LDLM_INTENT_GETATTR,
3138 .it_flags = HABEO_REFERO,
3139 .it_act = mdt_intent_getattr
3141 [MDT_IT_READDIR] = {
3147 .it_fmt = &RQF_LDLM_INTENT_GETATTR,
3148 .it_flags = HABEO_REFERO,
3149 .it_act = mdt_intent_getattr
3152 .it_fmt = &RQF_LDLM_INTENT_UNLINK,
3153 .it_flags = MUTABOR,
3155 .it_reint = REINT_UNLINK
3159 .it_flags = MUTABOR,
3162 [MDT_IT_GETXATTR] = {
3168 .it_fmt = &RQF_LDLM_INTENT_GETATTR,
3169 .it_flags = HABEO_REFERO,
3170 .it_act = mdt_intent_getattr
3174 int mdt_intent_lock_replace(struct mdt_thread_info *info,
3175 struct ldlm_lock **lockp,
3176 struct ldlm_lock *new_lock,
3177 struct mdt_lock_handle *lh,
3180 struct ptlrpc_request *req = mdt_info_req(info);
3181 struct ldlm_lock *lock = *lockp;
3184 * Get new lock only for cases when possible resent did not find any
3187 if (new_lock == NULL)
3188 new_lock = ldlm_handle2lock_long(&lh->mlh_reg_lh, 0);
3190 if (new_lock == NULL && (flags & LDLM_FL_INTENT_ONLY)) {
3191 lh->mlh_reg_lh.cookie = 0;
3195 LASSERTF(new_lock != NULL,
3196 "lockh "LPX64"\n", lh->mlh_reg_lh.cookie);
3199 * If we've already given this lock to a client once, then we should
3200 * have no readers or writers. Otherwise, we should have one reader
3201 * _or_ writer ref (which will be zeroed below) before returning the
3204 if (new_lock->l_export == req->rq_export) {
3205 LASSERT(new_lock->l_readers + new_lock->l_writers == 0);
3207 LASSERT(new_lock->l_export == NULL);
3208 LASSERT(new_lock->l_readers + new_lock->l_writers == 1);
3213 if (new_lock->l_export == req->rq_export) {
3215 * Already gave this to the client, which means that we
3216 * reconstructed a reply.
3218 LASSERT(lustre_msg_get_flags(req->rq_reqmsg) &
3220 lh->mlh_reg_lh.cookie = 0;
3221 RETURN(ELDLM_LOCK_REPLACED);
3225 * Fixup the lock to be given to the client.
3227 lock_res_and_lock(new_lock);
3228 /* Zero new_lock->l_readers and new_lock->l_writers without triggering
3229 * possible blocking AST. */
3230 while (new_lock->l_readers > 0) {
3231 lu_ref_del(&new_lock->l_reference, "reader", new_lock);
3232 lu_ref_del(&new_lock->l_reference, "user", new_lock);
3233 new_lock->l_readers--;
3235 while (new_lock->l_writers > 0) {
3236 lu_ref_del(&new_lock->l_reference, "writer", new_lock);
3237 lu_ref_del(&new_lock->l_reference, "user", new_lock);
3238 new_lock->l_writers--;
3241 new_lock->l_export = class_export_lock_get(req->rq_export, new_lock);
3242 new_lock->l_blocking_ast = lock->l_blocking_ast;
3243 new_lock->l_completion_ast = lock->l_completion_ast;
3244 new_lock->l_remote_handle = lock->l_remote_handle;
3245 new_lock->l_flags &= ~LDLM_FL_LOCAL;
3247 unlock_res_and_lock(new_lock);
3249 cfs_hash_add(new_lock->l_export->exp_lock_hash,
3250 &new_lock->l_remote_handle,
3251 &new_lock->l_exp_hash);
3253 LDLM_LOCK_RELEASE(new_lock);
3254 lh->mlh_reg_lh.cookie = 0;
3256 RETURN(ELDLM_LOCK_REPLACED);
3259 static void mdt_intent_fixup_resent(struct mdt_thread_info *info,
3260 struct ldlm_lock *new_lock,
3261 struct ldlm_lock **old_lock,
3262 struct mdt_lock_handle *lh)
3264 struct ptlrpc_request *req = mdt_info_req(info);
3265 struct obd_export *exp = req->rq_export;
3266 struct lustre_handle remote_hdl;
3267 struct ldlm_request *dlmreq;
3268 struct ldlm_lock *lock;
3270 if (!(lustre_msg_get_flags(req->rq_reqmsg) & MSG_RESENT))
3273 dlmreq = req_capsule_client_get(info->mti_pill, &RMF_DLM_REQ);
3274 remote_hdl = dlmreq->lock_handle[0];
3276 lock = cfs_hash_lookup(exp->exp_lock_hash, &remote_hdl);
3278 if (lock != new_lock) {
3279 lh->mlh_reg_lh.cookie = lock->l_handle.h_cookie;
3280 lh->mlh_reg_mode = lock->l_granted_mode;
3282 LDLM_DEBUG(lock, "Restoring lock cookie");
3283 DEBUG_REQ(D_DLMTRACE, req,
3284 "restoring lock cookie "LPX64,
3285 lh->mlh_reg_lh.cookie);
3287 *old_lock = LDLM_LOCK_GET(lock);
3288 cfs_hash_put(exp->exp_lock_hash, &lock->l_exp_hash);
3292 cfs_hash_put(exp->exp_lock_hash, &lock->l_exp_hash);
3296 * If the xid matches, then we know this is a resent request, and allow
3297 * it. (It's probably an OPEN, for which we don't send a lock.
3299 if (req_xid_is_last(req))
3303 * This remote handle isn't enqueued, so we never received or processed
3304 * this request. Clear MSG_RESENT, because it can be handled like any
3305 * normal request now.
3307 lustre_msg_clear_flags(req->rq_reqmsg, MSG_RESENT);
3309 DEBUG_REQ(D_DLMTRACE, req, "no existing lock with rhandle "LPX64,
3313 static int mdt_intent_getattr(enum mdt_it_code opcode,
3314 struct mdt_thread_info *info,
3315 struct ldlm_lock **lockp,
3318 struct mdt_lock_handle *lhc = &info->mti_lh[MDT_LH_RMT];
3319 struct ldlm_lock *new_lock = NULL;
3321 struct ldlm_reply *ldlm_rep;
3322 struct ptlrpc_request *req;
3323 struct mdt_body *reqbody;
3324 struct mdt_body *repbody;
3328 reqbody = req_capsule_client_get(info->mti_pill, &RMF_MDT_BODY);
3331 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
3334 info->mti_spec.sp_ck_split = !!(reqbody->valid & OBD_MD_FLCKSPLIT);
3335 info->mti_cross_ref = !!(reqbody->valid & OBD_MD_FLCROSSREF);
3336 repbody->eadatasize = 0;
3337 repbody->aclsize = 0;
3341 child_bits = MDS_INODELOCK_LOOKUP;
3343 case MDT_IT_GETATTR:
3344 child_bits = MDS_INODELOCK_LOOKUP | MDS_INODELOCK_UPDATE;
3346 case MDT_IT_LAYOUT: {
3347 static int printed = 0;
3350 CERROR("layout lock not supported by this version\n");
3353 GOTO(out_shrink, rc = -EINVAL);
3357 CERROR("Unsupported intent (%d)\n", opcode);
3358 GOTO(out_shrink, rc = -EINVAL);
3361 rc = mdt_init_ucred(info, reqbody);
3363 GOTO(out_shrink, rc);
3365 req = info->mti_pill->rc_req;
3366 ldlm_rep = req_capsule_server_get(info->mti_pill, &RMF_DLM_REP);
3367 mdt_set_disposition(info, ldlm_rep, DISP_IT_EXECD);
3369 /* Get lock from request for possible resent case. */
3370 mdt_intent_fixup_resent(info, *lockp, &new_lock, lhc);
3372 ldlm_rep->lock_policy_res2 =
3373 mdt_getattr_name_lock(info, lhc, child_bits, ldlm_rep);
3375 if (mdt_get_disposition(ldlm_rep, DISP_LOOKUP_NEG))
3376 ldlm_rep->lock_policy_res2 = 0;
3377 if (!mdt_get_disposition(ldlm_rep, DISP_LOOKUP_POS) ||
3378 ldlm_rep->lock_policy_res2) {
3379 lhc->mlh_reg_lh.cookie = 0ull;
3380 GOTO(out_ucred, rc = ELDLM_LOCK_ABORTED);
3383 rc = mdt_intent_lock_replace(info, lockp, new_lock, lhc, flags);
3386 mdt_exit_ucred(info);
3388 mdt_client_compatibility(info);
3389 rc2 = mdt_fix_reply(info);
3395 static int mdt_intent_reint(enum mdt_it_code opcode,
3396 struct mdt_thread_info *info,
3397 struct ldlm_lock **lockp,
3400 struct mdt_lock_handle *lhc = &info->mti_lh[MDT_LH_RMT];
3401 struct ldlm_reply *rep = NULL;
3405 static const struct req_format *intent_fmts[REINT_MAX] = {
3406 [REINT_CREATE] = &RQF_LDLM_INTENT_CREATE,
3407 [REINT_OPEN] = &RQF_LDLM_INTENT_OPEN
3412 opc = mdt_reint_opcode(info, intent_fmts);
3416 if (mdt_it_flavor[opcode].it_reint != opc) {
3417 CERROR("Reint code %ld doesn't match intent: %d\n",
3419 RETURN(err_serious(-EPROTO));
3422 /* Get lock from request for possible resent case. */
3423 mdt_intent_fixup_resent(info, *lockp, NULL, lhc);
3425 rc = mdt_reint_internal(info, lhc, opc);
3427 /* Check whether the reply has been packed successfully. */
3428 if (mdt_info_req(info)->rq_repmsg != NULL)
3429 rep = req_capsule_server_get(info->mti_pill, &RMF_DLM_REP);
3431 RETURN(err_serious(-EFAULT));
3433 /* MDC expects this in any case */
3435 mdt_set_disposition(info, rep, DISP_LOOKUP_EXECD);
3437 /* Cross-ref case, the lock should be returned to the client */
3438 if (rc == -EREMOTE) {
3439 LASSERT(lustre_handle_is_used(&lhc->mlh_reg_lh));
3440 rep->lock_policy_res2 = 0;
3441 rc = mdt_intent_lock_replace(info, lockp, NULL, lhc, flags);
3444 rep->lock_policy_res2 = clear_serious(rc);
3446 if (rep->lock_policy_res2 == -ENOENT &&
3447 mdt_get_disposition(rep, DISP_LOOKUP_NEG))
3448 rep->lock_policy_res2 = 0;
3450 if (rc == -ENOTCONN || rc == -ENODEV ||
3451 rc == -EOVERFLOW) { /**< if VBR failure then return error */
3453 * If it is the disconnect error (ENODEV & ENOCONN), the error
3454 * will be returned by rq_status, and client at ptlrpc layer
3455 * will detect this, then disconnect, reconnect the import
3456 * immediately, instead of impacting the following the rpc.
3458 lhc->mlh_reg_lh.cookie = 0ull;
3462 * For other cases, the error will be returned by intent.
3463 * and client will retrieve the result from intent.
3466 * FIXME: when open lock is finished, that should be
3469 if (lustre_handle_is_used(&lhc->mlh_reg_lh)) {
3470 LASSERTF(rc == 0, "Error occurred but lock handle "
3471 "is still in use\n");
3472 rep->lock_policy_res2 = 0;
3473 rc = mdt_intent_lock_replace(info, lockp, NULL, lhc, flags);
3476 lhc->mlh_reg_lh.cookie = 0ull;
3477 RETURN(ELDLM_LOCK_ABORTED);
3482 static int mdt_intent_code(long itcode)
3490 case IT_OPEN|IT_CREAT:
3497 rc = MDT_IT_READDIR;
3500 rc = MDT_IT_GETATTR;
3512 rc = MDT_IT_GETXATTR;
3518 CERROR("Unknown intent opcode: %ld\n", itcode);
3525 static int mdt_intent_opc(long itopc, struct mdt_thread_info *info,
3526 struct ldlm_lock **lockp, int flags)
3528 struct req_capsule *pill;
3529 struct mdt_it_flavor *flv;
3534 opc = mdt_intent_code(itopc);
3538 pill = info->mti_pill;
3539 flv = &mdt_it_flavor[opc];
3541 if (flv->it_fmt != NULL)
3542 req_capsule_extend(pill, flv->it_fmt);
3544 rc = mdt_unpack_req_pack_rep(info, flv->it_flags);
3546 struct ptlrpc_request *req = mdt_info_req(info);
3547 if (flv->it_flags & MUTABOR &&
3548 req->rq_export->exp_connect_flags & OBD_CONNECT_RDONLY)
3551 if (rc == 0 && flv->it_act != NULL) {
3552 /* execute policy */
3553 rc = flv->it_act(opc, info, lockp, flags);
3560 static int mdt_intent_policy(struct ldlm_namespace *ns,
3561 struct ldlm_lock **lockp, void *req_cookie,
3562 ldlm_mode_t mode, int flags, void *data)
3564 struct mdt_thread_info *info;
3565 struct ptlrpc_request *req = req_cookie;
3566 struct ldlm_intent *it;
3567 struct req_capsule *pill;
3572 LASSERT(req != NULL);
3574 info = lu_context_key_get(&req->rq_svc_thread->t_env->le_ctx,
3576 LASSERT(info != NULL);
3577 pill = info->mti_pill;
3578 LASSERT(pill->rc_req == req);
3580 if (req->rq_reqmsg->lm_bufcount > DLM_INTENT_IT_OFF) {
3581 req_capsule_extend(pill, &RQF_LDLM_INTENT);
3582 it = req_capsule_client_get(pill, &RMF_LDLM_INTENT);
3584 rc = mdt_intent_opc(it->opc, info, lockp, flags);
3588 /* Lock without inodebits makes no sense and will oops
3589 * later in ldlm. Let's check it now to see if we have
3590 * ibits corrupted somewhere in mdt_intent_opc().
3591 * The case for client miss to set ibits has been
3592 * processed by others. */
3593 LASSERT(ergo(info->mti_dlm_req->lock_desc.l_resource.\
3594 lr_type == LDLM_IBITS,
3595 info->mti_dlm_req->lock_desc.\
3596 l_policy_data.l_inodebits.bits != 0));
3598 rc = err_serious(-EFAULT);
3600 /* No intent was provided */
3601 LASSERT(pill->rc_fmt == &RQF_LDLM_ENQUEUE);
3602 rc = req_capsule_server_pack(pill);
3604 rc = err_serious(rc);
3609 static int mdt_seq_fini(const struct lu_env *env,
3610 struct mdt_device *m)
3612 struct md_site *ms = mdt_md_site(m);
3616 if (ms->ms_server_seq) {
3617 seq_server_fini(ms->ms_server_seq, env);
3618 OBD_FREE_PTR(ms->ms_server_seq);
3619 ms->ms_server_seq = NULL;
3622 if (ms->ms_control_seq) {
3623 seq_server_fini(ms->ms_control_seq, env);
3624 OBD_FREE_PTR(ms->ms_control_seq);
3625 ms->ms_control_seq = NULL;
3628 if (ms->ms_client_seq) {
3629 seq_client_fini(ms->ms_client_seq);
3630 OBD_FREE_PTR(ms->ms_client_seq);
3631 ms->ms_client_seq = NULL;
3638 static int mdt_seq_init(const struct lu_env *env,
3640 struct mdt_device *m)
3647 ms = mdt_md_site(m);
3650 * This is sequence-controller node. Init seq-controller server on local
3653 if (ms->ms_node_id == 0) {
3654 LASSERT(ms->ms_control_seq == NULL);
3656 OBD_ALLOC_PTR(ms->ms_control_seq);
3657 if (ms->ms_control_seq == NULL)
3660 rc = seq_server_init(ms->ms_control_seq,
3661 m->mdt_bottom, uuid,
3662 LUSTRE_SEQ_CONTROLLER,
3667 GOTO(out_seq_fini, rc);
3669 OBD_ALLOC_PTR(ms->ms_client_seq);
3670 if (ms->ms_client_seq == NULL)
3671 GOTO(out_seq_fini, rc = -ENOMEM);
3673 OBD_ALLOC(prefix, MAX_OBD_NAME + 5);
3674 if (prefix == NULL) {
3675 OBD_FREE_PTR(ms->ms_client_seq);
3676 GOTO(out_seq_fini, rc = -ENOMEM);
3679 snprintf(prefix, MAX_OBD_NAME + 5, "ctl-%s",
3683 * Init seq-controller client after seq-controller server is
3684 * ready. Pass ms->ms_control_seq to it for direct talking.
3686 rc = seq_client_init(ms->ms_client_seq, NULL,
3687 LUSTRE_SEQ_METADATA, prefix,
3688 ms->ms_control_seq);
3689 OBD_FREE(prefix, MAX_OBD_NAME + 5);
3692 GOTO(out_seq_fini, rc);
3695 /* Init seq-server on local MDT */
3696 LASSERT(ms->ms_server_seq == NULL);
3698 OBD_ALLOC_PTR(ms->ms_server_seq);
3699 if (ms->ms_server_seq == NULL)
3700 GOTO(out_seq_fini, rc = -ENOMEM);
3702 rc = seq_server_init(ms->ms_server_seq,
3703 m->mdt_bottom, uuid,
3708 GOTO(out_seq_fini, rc = -ENOMEM);
3710 /* Assign seq-controller client to local seq-server. */
3711 if (ms->ms_node_id == 0) {
3712 LASSERT(ms->ms_client_seq != NULL);
3714 rc = seq_server_set_cli(ms->ms_server_seq,
3722 mdt_seq_fini(env, m);
3727 * Init client sequence manager which is used by local MDS to talk to sequence
3728 * controller on remote node.
3730 static int mdt_seq_init_cli(const struct lu_env *env,
3731 struct mdt_device *m,
3732 struct lustre_cfg *cfg)
3734 struct md_site *ms = mdt_md_site(m);
3735 struct obd_device *mdc;
3736 struct obd_uuid *uuidp, *mdcuuidp;
3737 char *uuid_str, *mdc_uuid_str;
3740 struct mdt_thread_info *info;
3741 char *p, *index_string = lustre_cfg_string(cfg, 2);
3744 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
3745 uuidp = &info->mti_u.uuid[0];
3746 mdcuuidp = &info->mti_u.uuid[1];
3748 LASSERT(index_string);
3750 index = simple_strtol(index_string, &p, 10);
3752 CERROR("Invalid index in lustre_cgf, offset 2\n");
3756 /* check if this is adding the first MDC and controller is not yet
3758 if (index != 0 || ms->ms_client_seq)
3761 uuid_str = lustre_cfg_string(cfg, 1);
3762 mdc_uuid_str = lustre_cfg_string(cfg, 4);
3763 obd_str2uuid(uuidp, uuid_str);
3764 obd_str2uuid(mdcuuidp, mdc_uuid_str);
3766 mdc = class_find_client_obd(uuidp, LUSTRE_MDC_NAME, mdcuuidp);
3768 CERROR("can't find controller MDC by uuid %s\n",
3771 } else if (!mdc->obd_set_up) {
3772 CERROR("target %s not set up\n", mdc->obd_name);
3775 LASSERT(ms->ms_control_exp);
3776 OBD_ALLOC_PTR(ms->ms_client_seq);
3777 if (ms->ms_client_seq != NULL) {
3780 OBD_ALLOC(prefix, MAX_OBD_NAME + 5);
3784 snprintf(prefix, MAX_OBD_NAME + 5, "ctl-%s",
3787 rc = seq_client_init(ms->ms_client_seq,
3789 LUSTRE_SEQ_METADATA,
3791 OBD_FREE(prefix, MAX_OBD_NAME + 5);
3798 LASSERT(ms->ms_server_seq != NULL);
3799 rc = seq_server_set_cli(ms->ms_server_seq, ms->ms_client_seq,
3806 static void mdt_seq_fini_cli(struct mdt_device *m)
3812 ms = mdt_md_site(m);
3815 if (ms->ms_server_seq)
3816 seq_server_set_cli(ms->ms_server_seq,
3819 if (ms->ms_control_exp) {
3820 class_export_put(ms->ms_control_exp);
3821 ms->ms_control_exp = NULL;
3830 static int mdt_fld_fini(const struct lu_env *env,
3831 struct mdt_device *m)
3833 struct md_site *ms = mdt_md_site(m);
3836 if (ms && ms->ms_server_fld) {
3837 fld_server_fini(ms->ms_server_fld, env);
3838 OBD_FREE_PTR(ms->ms_server_fld);
3839 ms->ms_server_fld = NULL;
3845 static int mdt_fld_init(const struct lu_env *env,
3847 struct mdt_device *m)
3853 ms = mdt_md_site(m);
3855 OBD_ALLOC_PTR(ms->ms_server_fld);
3856 if (ms->ms_server_fld == NULL)
3857 RETURN(rc = -ENOMEM);
3859 rc = fld_server_init(ms->ms_server_fld,
3860 m->mdt_bottom, uuid,
3861 env, ms->ms_node_id);
3863 OBD_FREE_PTR(ms->ms_server_fld);
3864 ms->ms_server_fld = NULL;
3871 /* device init/fini methods */
3872 static void mdt_stop_ptlrpc_service(struct mdt_device *m)
3875 if (m->mdt_regular_service != NULL) {
3876 ptlrpc_unregister_service(m->mdt_regular_service);
3877 m->mdt_regular_service = NULL;
3879 if (m->mdt_readpage_service != NULL) {
3880 ptlrpc_unregister_service(m->mdt_readpage_service);
3881 m->mdt_readpage_service = NULL;
3883 if (m->mdt_xmds_service != NULL) {
3884 ptlrpc_unregister_service(m->mdt_xmds_service);
3885 m->mdt_xmds_service = NULL;
3887 if (m->mdt_setattr_service != NULL) {
3888 ptlrpc_unregister_service(m->mdt_setattr_service);
3889 m->mdt_setattr_service = NULL;
3891 if (m->mdt_mdsc_service != NULL) {
3892 ptlrpc_unregister_service(m->mdt_mdsc_service);
3893 m->mdt_mdsc_service = NULL;
3895 if (m->mdt_mdss_service != NULL) {
3896 ptlrpc_unregister_service(m->mdt_mdss_service);
3897 m->mdt_mdss_service = NULL;
3899 if (m->mdt_dtss_service != NULL) {
3900 ptlrpc_unregister_service(m->mdt_dtss_service);
3901 m->mdt_dtss_service = NULL;
3903 if (m->mdt_fld_service != NULL) {
3904 ptlrpc_unregister_service(m->mdt_fld_service);
3905 m->mdt_fld_service = NULL;
3910 static int mdt_start_ptlrpc_service(struct mdt_device *m)
3913 static struct ptlrpc_service_conf conf;
3914 cfs_proc_dir_entry_t *procfs_entry;
3917 procfs_entry = m->mdt_md_dev.md_lu_dev.ld_obd->obd_proc_entry;
3919 conf = (typeof(conf)) {
3920 .psc_nbufs = MDS_NBUFS,
3921 .psc_bufsize = MDS_BUFSIZE,
3922 .psc_max_req_size = MDS_MAXREQSIZE,
3923 .psc_max_reply_size = MDS_MAXREPSIZE,
3924 .psc_req_portal = MDS_REQUEST_PORTAL,
3925 .psc_rep_portal = MDC_REPLY_PORTAL,
3926 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
3928 * We'd like to have a mechanism to set this on a per-device
3929 * basis, but alas...
3931 .psc_min_threads = mdt_min_threads,
3932 .psc_max_threads = mdt_max_threads,
3933 .psc_ctx_tags = LCT_MD_THREAD
3936 m->mdt_ldlm_client = &m->mdt_md_dev.md_lu_dev.ld_obd->obd_ldlm_client;
3937 ptlrpc_init_client(LDLM_CB_REQUEST_PORTAL, LDLM_CB_REPLY_PORTAL,
3938 "mdt_ldlm_client", m->mdt_ldlm_client);
3940 m->mdt_regular_service =
3941 ptlrpc_init_svc_conf(&conf, mdt_regular_handle, LUSTRE_MDT_NAME,
3942 procfs_entry, target_print_req,
3944 if (m->mdt_regular_service == NULL)
3947 rc = ptlrpc_start_threads(m->mdt_regular_service);
3949 GOTO(err_mdt_svc, rc);
3952 * readpage service configuration. Parameters have to be adjusted,
3955 conf = (typeof(conf)) {
3956 .psc_nbufs = MDS_NBUFS,
3957 .psc_bufsize = MDS_BUFSIZE,
3958 .psc_max_req_size = MDS_MAXREQSIZE,
3959 .psc_max_reply_size = MDS_MAXREPSIZE,
3960 .psc_req_portal = MDS_READPAGE_PORTAL,
3961 .psc_rep_portal = MDC_REPLY_PORTAL,
3962 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
3963 .psc_min_threads = mdt_min_threads,
3964 .psc_max_threads = mdt_max_threads,
3965 .psc_ctx_tags = LCT_MD_THREAD
3967 m->mdt_readpage_service =
3968 ptlrpc_init_svc_conf(&conf, mdt_readpage_handle,
3969 LUSTRE_MDT_NAME "_readpage",
3970 procfs_entry, target_print_req,"mdt_rdpg");
3972 if (m->mdt_readpage_service == NULL) {
3973 CERROR("failed to start readpage service\n");
3974 GOTO(err_mdt_svc, rc = -ENOMEM);
3977 rc = ptlrpc_start_threads(m->mdt_readpage_service);
3980 * setattr service configuration.
3982 * XXX To keep the compatibility with old client(< 2.2), we need to
3983 * preserve this portal for a certain time, it should be removed
3984 * eventually. LU-617.
3986 conf = (typeof(conf)) {
3987 .psc_nbufs = MDS_NBUFS,
3988 .psc_bufsize = MDS_BUFSIZE,
3989 .psc_max_req_size = MDS_MAXREQSIZE,
3990 .psc_max_reply_size = MDS_MAXREPSIZE,
3991 .psc_req_portal = MDS_SETATTR_PORTAL,
3992 .psc_rep_portal = MDC_REPLY_PORTAL,
3993 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
3994 .psc_min_threads = mdt_min_threads,
3995 .psc_max_threads = mdt_max_threads,
3996 .psc_ctx_tags = LCT_MD_THREAD
3999 m->mdt_setattr_service =
4000 ptlrpc_init_svc_conf(&conf, mdt_regular_handle,
4001 LUSTRE_MDT_NAME "_setattr",
4002 procfs_entry, target_print_req,"mdt_attr");
4004 if (!m->mdt_setattr_service) {
4005 CERROR("failed to start setattr service\n");
4006 GOTO(err_mdt_svc, rc = -ENOMEM);
4009 rc = ptlrpc_start_threads(m->mdt_setattr_service);
4011 GOTO(err_mdt_svc, rc);
4014 * sequence controller service configuration
4016 conf = (typeof(conf)) {
4017 .psc_nbufs = MDS_NBUFS,
4018 .psc_bufsize = MDS_BUFSIZE,
4019 .psc_max_req_size = SEQ_MAXREQSIZE,
4020 .psc_max_reply_size = SEQ_MAXREPSIZE,
4021 .psc_req_portal = SEQ_CONTROLLER_PORTAL,
4022 .psc_rep_portal = MDC_REPLY_PORTAL,
4023 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
4024 .psc_min_threads = mdt_min_threads,
4025 .psc_max_threads = mdt_max_threads,
4026 .psc_ctx_tags = LCT_MD_THREAD|LCT_DT_THREAD
4029 m->mdt_mdsc_service =
4030 ptlrpc_init_svc_conf(&conf, mdt_mdsc_handle,
4031 LUSTRE_MDT_NAME"_mdsc",
4032 procfs_entry, target_print_req,"mdt_mdsc");
4033 if (!m->mdt_mdsc_service) {
4034 CERROR("failed to start seq controller service\n");
4035 GOTO(err_mdt_svc, rc = -ENOMEM);
4038 rc = ptlrpc_start_threads(m->mdt_mdsc_service);
4040 GOTO(err_mdt_svc, rc);
4043 * metadata sequence server service configuration
4045 conf = (typeof(conf)) {
4046 .psc_nbufs = MDS_NBUFS,
4047 .psc_bufsize = MDS_BUFSIZE,
4048 .psc_max_req_size = SEQ_MAXREQSIZE,
4049 .psc_max_reply_size = SEQ_MAXREPSIZE,
4050 .psc_req_portal = SEQ_METADATA_PORTAL,
4051 .psc_rep_portal = MDC_REPLY_PORTAL,
4052 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
4053 .psc_min_threads = mdt_min_threads,
4054 .psc_max_threads = mdt_max_threads,
4055 .psc_ctx_tags = LCT_MD_THREAD|LCT_DT_THREAD
4058 m->mdt_mdss_service =
4059 ptlrpc_init_svc_conf(&conf, mdt_mdss_handle,
4060 LUSTRE_MDT_NAME"_mdss",
4061 procfs_entry, target_print_req,"mdt_mdss");
4062 if (!m->mdt_mdss_service) {
4063 CERROR("failed to start metadata seq server service\n");
4064 GOTO(err_mdt_svc, rc = -ENOMEM);
4067 rc = ptlrpc_start_threads(m->mdt_mdss_service);
4069 GOTO(err_mdt_svc, rc);
4073 * Data sequence server service configuration. We want to have really
4074 * cluster-wide sequences space. This is why we start only one sequence
4075 * controller which manages space.
4077 conf = (typeof(conf)) {
4078 .psc_nbufs = MDS_NBUFS,
4079 .psc_bufsize = MDS_BUFSIZE,
4080 .psc_max_req_size = SEQ_MAXREQSIZE,
4081 .psc_max_reply_size = SEQ_MAXREPSIZE,
4082 .psc_req_portal = SEQ_DATA_PORTAL,
4083 .psc_rep_portal = OSC_REPLY_PORTAL,
4084 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
4085 .psc_min_threads = mdt_min_threads,
4086 .psc_max_threads = mdt_max_threads,
4087 .psc_ctx_tags = LCT_MD_THREAD|LCT_DT_THREAD
4090 m->mdt_dtss_service =
4091 ptlrpc_init_svc_conf(&conf, mdt_dtss_handle,
4092 LUSTRE_MDT_NAME"_dtss",
4093 procfs_entry, target_print_req,"mdt_dtss");
4094 if (!m->mdt_dtss_service) {
4095 CERROR("failed to start data seq server service\n");
4096 GOTO(err_mdt_svc, rc = -ENOMEM);
4099 rc = ptlrpc_start_threads(m->mdt_dtss_service);
4101 GOTO(err_mdt_svc, rc);
4103 /* FLD service start */
4104 conf = (typeof(conf)) {
4105 .psc_nbufs = MDS_NBUFS,
4106 .psc_bufsize = MDS_BUFSIZE,
4107 .psc_max_req_size = FLD_MAXREQSIZE,
4108 .psc_max_reply_size = FLD_MAXREPSIZE,
4109 .psc_req_portal = FLD_REQUEST_PORTAL,
4110 .psc_rep_portal = MDC_REPLY_PORTAL,
4111 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
4112 .psc_min_threads = mdt_min_threads,
4113 .psc_max_threads = mdt_max_threads,
4114 .psc_ctx_tags = LCT_DT_THREAD|LCT_MD_THREAD
4117 m->mdt_fld_service =
4118 ptlrpc_init_svc_conf(&conf, mdt_fld_handle,
4119 LUSTRE_MDT_NAME"_fld",
4120 procfs_entry, target_print_req, "mdt_fld");
4121 if (!m->mdt_fld_service) {
4122 CERROR("failed to start fld service\n");
4123 GOTO(err_mdt_svc, rc = -ENOMEM);
4126 rc = ptlrpc_start_threads(m->mdt_fld_service);
4128 GOTO(err_mdt_svc, rc);
4131 * mds-mds service configuration. Separate portal is used to allow
4132 * mds-mds requests be not blocked during recovery.
4134 conf = (typeof(conf)) {
4135 .psc_nbufs = MDS_NBUFS,
4136 .psc_bufsize = MDS_BUFSIZE,
4137 .psc_max_req_size = MDS_MAXREQSIZE,
4138 .psc_max_reply_size = MDS_MAXREPSIZE,
4139 .psc_req_portal = MDS_MDS_PORTAL,
4140 .psc_rep_portal = MDC_REPLY_PORTAL,
4141 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
4142 .psc_min_threads = mdt_min_threads,
4143 .psc_max_threads = mdt_max_threads,
4144 .psc_ctx_tags = LCT_MD_THREAD
4146 m->mdt_xmds_service =
4147 ptlrpc_init_svc_conf(&conf, mdt_xmds_handle,
4148 LUSTRE_MDT_NAME "_mds",
4149 procfs_entry, target_print_req,"mdt_xmds");
4151 if (m->mdt_xmds_service == NULL) {
4152 CERROR("failed to start xmds service\n");
4153 GOTO(err_mdt_svc, rc = -ENOMEM);
4156 rc = ptlrpc_start_threads(m->mdt_xmds_service);
4158 GOTO(err_mdt_svc, rc);
4163 mdt_stop_ptlrpc_service(m);
4168 static void mdt_stack_fini(const struct lu_env *env,
4169 struct mdt_device *m, struct lu_device *top)
4171 struct obd_device *obd = mdt2obd_dev(m);
4172 struct lustre_cfg_bufs *bufs;
4173 struct lustre_cfg *lcfg;
4174 struct mdt_thread_info *info;
4178 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
4179 LASSERT(info != NULL);
4181 bufs = &info->mti_u.bufs;
4182 /* process cleanup, pass mdt obd name to get obd umount flags */
4183 lustre_cfg_bufs_reset(bufs, obd->obd_name);
4188 lustre_cfg_bufs_set_string(bufs, 1, flags);
4189 lcfg = lustre_cfg_new(LCFG_CLEANUP, bufs);
4191 CERROR("Cannot alloc lcfg!\n");
4196 top->ld_ops->ldo_process_config(env, top, lcfg);
4197 lustre_cfg_free(lcfg);
4199 lu_stack_fini(env, top);
4200 m->mdt_child = NULL;
4201 m->mdt_bottom = NULL;
4204 static struct lu_device *mdt_layer_setup(struct lu_env *env,
4205 const char *typename,
4206 struct lu_device *child,
4207 struct lustre_cfg *cfg)
4209 const char *dev = lustre_cfg_string(cfg, 0);
4210 struct obd_type *type;
4211 struct lu_device_type *ldt;
4212 struct lu_device *d;
4217 type = class_get_type(typename);
4219 CERROR("Unknown type: '%s'\n", typename);
4220 GOTO(out, rc = -ENODEV);
4223 rc = lu_env_refill((struct lu_env *)env);
4225 CERROR("Failure to refill session: '%d'\n", rc);
4231 CERROR("type: '%s'\n", typename);
4232 GOTO(out_type, rc = -EINVAL);
4235 ldt->ldt_obd_type = type;
4236 d = ldt->ldt_ops->ldto_device_alloc(env, ldt, cfg);
4238 CERROR("Cannot allocate device: '%s'\n", typename);
4239 GOTO(out_type, rc = -ENODEV);
4242 LASSERT(child->ld_site);
4243 d->ld_site = child->ld_site;
4246 rc = ldt->ldt_ops->ldto_device_init(env, d, dev, child);
4248 CERROR("can't init device '%s', rc %d\n", typename, rc);
4249 GOTO(out_alloc, rc);
4252 lu_ref_add(&d->ld_reference, "lu-stack", &lu_site_init);
4254 cfs_spin_lock(&d->ld_site->ls_ld_lock);
4255 cfs_list_add_tail(&d->ld_linkage, &d->ld_site->ls_ld_linkage);
4256 cfs_spin_unlock(&d->ld_site->ls_ld_lock);
4260 ldt->ldt_ops->ldto_device_free(env, d);
4263 class_put_type(type);
4268 static int mdt_stack_init(struct lu_env *env,
4269 struct mdt_device *m,
4270 struct lustre_cfg *cfg,
4271 struct lustre_mount_info *lmi)
4273 struct lu_device *d = &m->mdt_md_dev.md_lu_dev;
4274 struct lu_device *tmp;
4275 struct md_device *md;
4276 struct lu_device *child_lu_dev;
4280 /* init the stack */
4281 tmp = mdt_layer_setup(env, LUSTRE_OSD_NAME, d, cfg);
4283 RETURN(PTR_ERR(tmp));
4285 m->mdt_bottom = lu2dt_dev(tmp);
4287 tmp = mdt_layer_setup(env, LUSTRE_MDD_NAME, d, cfg);
4289 GOTO(out, rc = PTR_ERR(tmp));
4294 tmp = mdt_layer_setup(env, LUSTRE_CMM_NAME, d, cfg);
4296 GOTO(out, rc = PTR_ERR(tmp));
4299 /*set mdd upcall device*/
4300 md_upcall_dev_set(md, lu2md_dev(d));
4303 /*set cmm upcall device*/
4304 md_upcall_dev_set(md, &m->mdt_md_dev);
4306 m->mdt_child = lu2md_dev(d);
4308 /* process setup config */
4309 tmp = &m->mdt_md_dev.md_lu_dev;
4310 rc = tmp->ld_ops->ldo_process_config(env, tmp, cfg);
4314 /* initialize local objects */
4315 child_lu_dev = &m->mdt_child->md_lu_dev;
4317 rc = child_lu_dev->ld_ops->ldo_prepare(env,
4318 &m->mdt_md_dev.md_lu_dev,
4321 /* fini from last known good lu_device */
4323 mdt_stack_fini(env, m, d);
4329 * setup CONFIG_ORIG context, used to access local config log.
4330 * this may need to be rewrite as part of llog rewrite for lu-api.
4332 static int mdt_obd_llog_setup(struct obd_device *obd,
4333 struct lustre_sb_info *lsi)
4337 LASSERT(obd->obd_fsops == NULL);
4339 obd->obd_fsops = fsfilt_get_ops(MT_STR(lsi->lsi_ldd));
4340 if (IS_ERR(obd->obd_fsops))
4341 return PTR_ERR(obd->obd_fsops);
4343 rc = fsfilt_setup(obd, lsi->lsi_srv_mnt->mnt_sb);
4345 fsfilt_put_ops(obd->obd_fsops);
4349 OBD_SET_CTXT_MAGIC(&obd->obd_lvfs_ctxt);
4350 obd->obd_lvfs_ctxt.pwdmnt = lsi->lsi_srv_mnt;
4351 obd->obd_lvfs_ctxt.pwd = lsi->lsi_srv_mnt->mnt_root;
4352 obd->obd_lvfs_ctxt.fs = get_ds();
4354 rc = llog_setup(obd, &obd->obd_olg, LLOG_CONFIG_ORIG_CTXT, obd,
4355 0, NULL, &llog_lvfs_ops);
4357 CERROR("llog_setup() failed: %d\n", rc);
4358 fsfilt_put_ops(obd->obd_fsops);
4364 static void mdt_obd_llog_cleanup(struct obd_device *obd)
4366 struct llog_ctxt *ctxt;
4368 ctxt = llog_get_context(obd, LLOG_CONFIG_ORIG_CTXT);
4372 if (obd->obd_fsops) {
4373 fsfilt_put_ops(obd->obd_fsops);
4374 obd->obd_fsops = NULL;
4378 static void mdt_fini(const struct lu_env *env, struct mdt_device *m)
4380 struct md_device *next = m->mdt_child;
4381 struct lu_device *d = &m->mdt_md_dev.md_lu_dev;
4382 struct lu_site *ls = d->ld_site;
4383 struct obd_device *obd = mdt2obd_dev(m);
4386 target_recovery_fini(obd);
4388 ping_evictor_stop();
4390 mdt_stop_ptlrpc_service(m);
4391 mdt_llog_ctxt_unclone(env, m, LLOG_CHANGELOG_ORIG_CTXT);
4392 mdt_obd_llog_cleanup(obd);
4393 obd_exports_barrier(obd);
4394 obd_zombie_barrier();
4398 #ifdef HAVE_QUOTA_SUPPORT
4399 next->md_ops->mdo_quota.mqo_cleanup(env, next);
4401 lut_fini(env, &m->mdt_lut);
4402 mdt_fs_cleanup(env, m);
4403 upcall_cache_cleanup(m->mdt_identity_cache);
4404 m->mdt_identity_cache = NULL;
4406 if (m->mdt_namespace != NULL) {
4407 ldlm_namespace_free(m->mdt_namespace, NULL,
4408 d->ld_obd->obd_force);
4409 d->ld_obd->obd_namespace = m->mdt_namespace = NULL;
4412 cfs_free_nidlist(&m->mdt_nosquash_nids);
4413 if (m->mdt_nosquash_str) {
4414 OBD_FREE(m->mdt_nosquash_str, m->mdt_nosquash_strlen);
4415 m->mdt_nosquash_str = NULL;
4416 m->mdt_nosquash_strlen = 0;
4419 mdt_seq_fini(env, m);
4420 mdt_seq_fini_cli(m);
4421 mdt_fld_fini(env, m);
4422 sptlrpc_rule_set_free(&m->mdt_sptlrpc_rset);
4424 next->md_ops->mdo_init_capa_ctxt(env, next, 0, 0, 0, NULL);
4425 cfs_timer_disarm(&m->mdt_ck_timer);
4426 mdt_ck_thread_stop(m);
4431 mdt_stack_fini(env, m, md2lu_dev(m->mdt_child));
4434 struct md_site *mite;
4437 mite = lu_site2md(ls);
4441 LASSERT(cfs_atomic_read(&d->ld_ref) == 0);
4446 static int mdt_adapt_sptlrpc_conf(struct obd_device *obd, int initial)
4448 struct mdt_device *m = mdt_dev(obd->obd_lu_dev);
4449 struct sptlrpc_rule_set tmp_rset;
4452 sptlrpc_rule_set_init(&tmp_rset);
4453 rc = sptlrpc_conf_target_get_rules(obd, &tmp_rset, initial);
4455 CERROR("mdt %s: failed get sptlrpc rules: %d\n",
4460 sptlrpc_target_update_exp_flavor(obd, &tmp_rset);
4462 cfs_write_lock(&m->mdt_sptlrpc_lock);
4463 sptlrpc_rule_set_free(&m->mdt_sptlrpc_rset);
4464 m->mdt_sptlrpc_rset = tmp_rset;
4465 cfs_write_unlock(&m->mdt_sptlrpc_lock);
4470 int mdt_postrecov(const struct lu_env *, struct mdt_device *);
4472 static int mdt_init0(const struct lu_env *env, struct mdt_device *m,
4473 struct lu_device_type *ldt, struct lustre_cfg *cfg)
4475 struct mdt_thread_info *info;
4476 struct obd_device *obd;
4477 const char *dev = lustre_cfg_string(cfg, 0);
4478 const char *num = lustre_cfg_string(cfg, 2);
4479 struct lustre_mount_info *lmi = NULL;
4480 struct lustre_sb_info *lsi;
4481 struct lustre_disk_data *ldd;
4483 struct md_site *mite;
4484 const char *identity_upcall = "NONE";
4485 struct md_device *next;
4491 md_device_init(&m->mdt_md_dev, ldt);
4493 * Environment (env) might be missing mdt_thread_key values at that
4494 * point, if device is allocated when mdt_thread_key is in QUIESCENT
4497 * Usually device allocation path doesn't use module key values, but
4498 * mdt has to do a lot of work here, so allocate key value.
4500 rc = lu_env_refill((struct lu_env *)env);
4504 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
4505 LASSERT(info != NULL);
4507 obd = class_name2obd(dev);
4508 LASSERT(obd != NULL);
4510 m->mdt_max_mdsize = MAX_MD_SIZE; /* 4 stripes */
4511 m->mdt_max_cookiesize = sizeof(struct llog_cookie);
4513 m->mdt_som_conf = 0;
4515 m->mdt_opts.mo_cos = MDT_COS_DEFAULT;
4516 lmi = server_get_mount_2(dev);
4518 CERROR("Cannot get mount info for %s!\n", dev);
4521 lsi = s2lsi(lmi->lmi_sb);
4522 /* CMD is supported only in IAM mode */
4525 node_id = simple_strtol(num, NULL, 10);
4526 if (!(ldd->ldd_flags & LDD_F_IAM_DIR) && node_id) {
4527 CERROR("CMD Operation not allowed in IOP mode\n");
4528 GOTO(err_lmi, rc = -EINVAL);
4531 obd->u.obt.obt_magic = OBT_MAGIC;
4534 cfs_rwlock_init(&m->mdt_sptlrpc_lock);
4535 sptlrpc_rule_set_init(&m->mdt_sptlrpc_rset);
4537 cfs_spin_lock_init(&m->mdt_ioepoch_lock);
4538 m->mdt_opts.mo_compat_resname = 0;
4539 m->mdt_opts.mo_mds_capa = 1;
4540 m->mdt_opts.mo_oss_capa = 1;
4541 m->mdt_capa_timeout = CAPA_TIMEOUT;
4542 m->mdt_capa_alg = CAPA_HMAC_ALG_SHA1;
4543 m->mdt_ck_timeout = CAPA_KEY_TIMEOUT;
4544 m->mdt_squash_uid = 0;
4545 m->mdt_squash_gid = 0;
4546 CFS_INIT_LIST_HEAD(&m->mdt_nosquash_nids);
4547 m->mdt_nosquash_str = NULL;
4548 m->mdt_nosquash_strlen = 0;
4549 cfs_init_rwsem(&m->mdt_squash_sem);
4551 OBD_ALLOC_PTR(mite);
4553 GOTO(err_lmi, rc = -ENOMEM);
4557 m->mdt_md_dev.md_lu_dev.ld_ops = &mdt_lu_ops;
4558 m->mdt_md_dev.md_lu_dev.ld_obd = obd;
4559 /* set this lu_device to obd, because error handling need it */
4560 obd->obd_lu_dev = &m->mdt_md_dev.md_lu_dev;
4562 rc = lu_site_init(s, &m->mdt_md_dev.md_lu_dev);
4564 CERROR("Can't init lu_site, rc %d\n", rc);
4565 GOTO(err_free_site, rc);
4568 /* set server index */
4569 lu_site2md(s)->ms_node_id = node_id;
4571 /* failover is the default
4572 * FIXME: we do not failout mds0/mgs, which may cause some problems.
4573 * assumed whose ms_node_id == 0 XXX
4575 obd->obd_replayable = 1;
4576 /* No connection accepted until configurations will finish */
4577 obd->obd_no_conn = 1;
4579 if (cfg->lcfg_bufcount > 4 && LUSTRE_CFG_BUFLEN(cfg, 4) > 0) {
4580 char *str = lustre_cfg_string(cfg, 4);
4581 if (strchr(str, 'n')) {
4582 CWARN("%s: recovery disabled\n", obd->obd_name);
4583 obd->obd_replayable = 0;
4587 /* init the stack */
4588 rc = mdt_stack_init((struct lu_env *)env, m, cfg, lmi);
4590 CERROR("Can't init device stack, rc %d\n", rc);
4591 GOTO(err_lu_site, rc);
4594 rc = lut_init(env, &m->mdt_lut, obd, m->mdt_bottom);
4596 GOTO(err_fini_stack, rc);
4598 rc = mdt_fld_init(env, obd->obd_name, m);
4602 rc = mdt_seq_init(env, obd->obd_name, m);
4604 GOTO(err_fini_fld, rc);
4606 snprintf(info->mti_u.ns_name, sizeof info->mti_u.ns_name,
4607 LUSTRE_MDT_NAME"-%p", m);
4608 m->mdt_namespace = ldlm_namespace_new(obd, info->mti_u.ns_name,
4609 LDLM_NAMESPACE_SERVER,
4610 LDLM_NAMESPACE_GREEDY,
4612 if (m->mdt_namespace == NULL)
4613 GOTO(err_fini_seq, rc = -ENOMEM);
4615 ldlm_register_intent(m->mdt_namespace, mdt_intent_policy);
4616 /* set obd_namespace for compatibility with old code */
4617 obd->obd_namespace = m->mdt_namespace;
4619 cfs_timer_init(&m->mdt_ck_timer, mdt_ck_timer_callback, m);
4621 rc = mdt_ck_thread_start(m);
4623 GOTO(err_free_ns, rc);
4625 rc = mdt_fs_setup(env, m, obd, lsi);
4629 rc = mdt_obd_llog_setup(obd, lsi);
4631 GOTO(err_fs_cleanup, rc);
4633 rc = mdt_llog_ctxt_clone(env, m, LLOG_CHANGELOG_ORIG_CTXT);
4635 GOTO(err_llog_cleanup, rc);
4637 mdt_adapt_sptlrpc_conf(obd, 1);
4639 next = m->mdt_child;
4640 #ifdef HAVE_QUOTA_SUPPORT
4641 rc = next->md_ops->mdo_quota.mqo_setup(env, next, lmi->lmi_mnt);
4643 GOTO(err_llog_cleanup, rc);
4646 server_put_mount_2(dev, lmi->lmi_mnt);
4649 rc = next->md_ops->mdo_iocontrol(env, next, OBD_IOC_GET_MNTOPT, 0,
4652 GOTO(err_quota, rc);
4654 if (mntopts & MNTOPT_USERXATTR)
4655 m->mdt_opts.mo_user_xattr = 1;
4657 m->mdt_opts.mo_user_xattr = 0;
4659 if (mntopts & MNTOPT_ACL)
4660 m->mdt_opts.mo_acl = 1;
4662 m->mdt_opts.mo_acl = 0;
4664 /* XXX: to support suppgid for ACL, we enable identity_upcall
4665 * by default, otherwise, maybe got unexpected -EACCESS. */
4666 if (m->mdt_opts.mo_acl)
4667 identity_upcall = MDT_IDENTITY_UPCALL_PATH;
4669 m->mdt_identity_cache = upcall_cache_init(obd->obd_name,identity_upcall,
4670 &mdt_identity_upcall_cache_ops);
4671 if (IS_ERR(m->mdt_identity_cache)) {
4672 rc = PTR_ERR(m->mdt_identity_cache);
4673 m->mdt_identity_cache = NULL;
4674 GOTO(err_quota, rc);
4677 target_recovery_init(&m->mdt_lut, mdt_recovery_handle);
4679 rc = mdt_procfs_init(m, dev);
4681 CERROR("Can't init MDT lprocfs, rc %d\n", rc);
4682 GOTO(err_recovery, rc);
4685 rc = mdt_start_ptlrpc_service(m);
4687 GOTO(err_procfs, rc);
4689 ping_evictor_start();
4691 rc = lu_site_init_finish(s);
4693 GOTO(err_stop_service, rc);
4695 if (obd->obd_recovering == 0)
4696 mdt_postrecov(env, m);
4698 mdt_init_capa_ctxt(env, m);
4700 /* Reduce the initial timeout on an MDS because it doesn't need such
4701 * a long timeout as an OST does. Adaptive timeouts will adjust this
4702 * value appropriately. */
4703 if (ldlm_timeout == LDLM_TIMEOUT_DEFAULT)
4704 ldlm_timeout = MDS_LDLM_TIMEOUT_DEFAULT;
4709 ping_evictor_stop();
4710 mdt_stop_ptlrpc_service(m);
4714 target_recovery_fini(obd);
4715 upcall_cache_cleanup(m->mdt_identity_cache);
4716 m->mdt_identity_cache = NULL;
4718 #ifdef HAVE_QUOTA_SUPPORT
4719 next->md_ops->mdo_quota.mqo_cleanup(env, next);
4722 mdt_llog_ctxt_unclone(env, m, LLOG_CHANGELOG_ORIG_CTXT);
4723 mdt_obd_llog_cleanup(obd);
4725 mdt_fs_cleanup(env, m);
4727 cfs_timer_disarm(&m->mdt_ck_timer);
4728 mdt_ck_thread_stop(m);
4730 ldlm_namespace_free(m->mdt_namespace, NULL, 0);
4731 obd->obd_namespace = m->mdt_namespace = NULL;
4733 mdt_seq_fini(env, m);
4735 mdt_fld_fini(env, m);
4737 lut_fini(env, &m->mdt_lut);
4739 mdt_stack_fini(env, m, md2lu_dev(m->mdt_child));
4746 server_put_mount_2(dev, lmi->lmi_mnt);
4750 /* used by MGS to process specific configurations */
4751 static int mdt_process_config(const struct lu_env *env,
4752 struct lu_device *d, struct lustre_cfg *cfg)
4754 struct mdt_device *m = mdt_dev(d);
4755 struct md_device *md_next = m->mdt_child;
4756 struct lu_device *next = md2lu_dev(md_next);
4760 switch (cfg->lcfg_command) {
4762 struct lprocfs_static_vars lvars;
4763 struct obd_device *obd = d->ld_obd;
4766 * For interoperability between 1.8 and 2.0,
4769 /* Skip old "mdt.group_upcall" param. */
4770 char *param = lustre_cfg_string(cfg, 1);
4771 if (param && !strncmp("mdt.group_upcall", param, 16)) {
4772 CWARN("For 1.8 interoperability, skip this"
4773 " mdt.group_upcall. It is obsolete\n");
4776 /* Rename old "mdt.quota_type" to "mdd.quota_type. */
4777 if (param && !strncmp("mdt.quota_type", param, 14)) {
4778 CWARN("Found old param mdt.quota_type, changed"
4779 " it to mdd.quota_type.\n");
4784 lprocfs_mdt_init_vars(&lvars);
4785 rc = class_process_proc_param(PARAM_MDT, lvars.obd_vars,
4787 if (rc > 0 || rc == -ENOSYS)
4788 /* we don't understand; pass it on */
4789 rc = next->ld_ops->ldo_process_config(env, next, cfg);
4794 * Add mdc hook to get first MDT uuid and connect it to
4795 * ls->controller to use for seq manager.
4797 rc = next->ld_ops->ldo_process_config(env, next, cfg);
4799 CERROR("Can't add mdc, rc %d\n", rc);
4801 rc = mdt_seq_init_cli(env, mdt_dev(d), cfg);
4804 /* others are passed further */
4805 rc = next->ld_ops->ldo_process_config(env, next, cfg);
4811 static struct lu_object *mdt_object_alloc(const struct lu_env *env,
4812 const struct lu_object_header *hdr,
4813 struct lu_device *d)
4815 struct mdt_object *mo;
4821 struct lu_object *o;
4822 struct lu_object_header *h;
4824 o = &mo->mot_obj.mo_lu;
4825 h = &mo->mot_header;
4826 lu_object_header_init(h);
4827 lu_object_init(o, h, d);
4828 lu_object_add_top(h, o);
4829 o->lo_ops = &mdt_obj_ops;
4830 cfs_mutex_init(&mo->mot_ioepoch_mutex);
4831 cfs_mutex_init(&mo->mot_lov_mutex);
4837 static int mdt_object_init(const struct lu_env *env, struct lu_object *o,
4838 const struct lu_object_conf *unused)
4840 struct mdt_device *d = mdt_dev(o->lo_dev);
4841 struct lu_device *under;
4842 struct lu_object *below;
4846 CDEBUG(D_INFO, "object init, fid = "DFID"\n",
4847 PFID(lu_object_fid(o)));
4849 under = &d->mdt_child->md_lu_dev;
4850 below = under->ld_ops->ldo_object_alloc(env, o->lo_header, under);
4851 if (below != NULL) {
4852 lu_object_add(o, below);
4859 static void mdt_object_free(const struct lu_env *env, struct lu_object *o)
4861 struct mdt_object *mo = mdt_obj(o);
4862 struct lu_object_header *h;
4866 CDEBUG(D_INFO, "object free, fid = "DFID"\n",
4867 PFID(lu_object_fid(o)));
4870 lu_object_header_fini(h);
4875 static int mdt_object_print(const struct lu_env *env, void *cookie,
4876 lu_printer_t p, const struct lu_object *o)
4878 struct mdt_object *mdto = mdt_obj((struct lu_object *)o);
4879 return (*p)(env, cookie, LUSTRE_MDT_NAME"-object@%p(ioepoch="LPU64" "
4880 "flags="LPX64", epochcount=%d, writecount=%d)",
4881 mdto, mdto->mot_ioepoch, mdto->mot_flags,
4882 mdto->mot_ioepoch_count, mdto->mot_writecount);
4885 static const struct lu_device_operations mdt_lu_ops = {
4886 .ldo_object_alloc = mdt_object_alloc,
4887 .ldo_process_config = mdt_process_config,
4890 static const struct lu_object_operations mdt_obj_ops = {
4891 .loo_object_init = mdt_object_init,
4892 .loo_object_free = mdt_object_free,
4893 .loo_object_print = mdt_object_print
4896 static int mdt_obd_set_info_async(struct obd_export *exp,
4897 __u32 keylen, void *key,
4898 __u32 vallen, void *val,
4899 struct ptlrpc_request_set *set)
4901 struct obd_device *obd = exp->exp_obd;
4907 if (KEY_IS(KEY_SPTLRPC_CONF)) {
4908 rc = mdt_adapt_sptlrpc_conf(obd, 0);
4915 /* mds_connect_internal */
4916 static int mdt_connect_internal(struct obd_export *exp,
4917 struct mdt_device *mdt,
4918 struct obd_connect_data *data)
4921 data->ocd_connect_flags &= MDT_CONNECT_SUPPORTED;
4922 data->ocd_ibits_known &= MDS_INODELOCK_FULL;
4924 /* If no known bits (which should not happen, probably,
4925 as everybody should support LOOKUP and UPDATE bits at least)
4926 revert to compat mode with plain locks. */
4927 if (!data->ocd_ibits_known &&
4928 data->ocd_connect_flags & OBD_CONNECT_IBITS)
4929 data->ocd_connect_flags &= ~OBD_CONNECT_IBITS;
4931 if (!mdt->mdt_opts.mo_acl)
4932 data->ocd_connect_flags &= ~OBD_CONNECT_ACL;
4934 if (!mdt->mdt_opts.mo_user_xattr)
4935 data->ocd_connect_flags &= ~OBD_CONNECT_XATTR;
4937 if (!mdt->mdt_som_conf)
4938 data->ocd_connect_flags &= ~OBD_CONNECT_SOM;
4940 if (data->ocd_connect_flags & OBD_CONNECT_BRW_SIZE) {
4941 data->ocd_brw_size = min(data->ocd_brw_size,
4942 (__u32)(PTLRPC_MAX_BRW_PAGES << CFS_PAGE_SHIFT));
4943 if (data->ocd_brw_size == 0) {
4944 CERROR("%s: cli %s/%p ocd_connect_flags: "LPX64
4945 " ocd_version: %x ocd_grant: %d "
4946 "ocd_index: %u ocd_brw_size is "
4947 "unexpectedly zero, network data "
4948 "corruption? Refusing connection of this"
4950 exp->exp_obd->obd_name,
4951 exp->exp_client_uuid.uuid,
4952 exp, data->ocd_connect_flags, data->ocd_version,
4953 data->ocd_grant, data->ocd_index);
4958 cfs_spin_lock(&exp->exp_lock);
4959 exp->exp_connect_flags = data->ocd_connect_flags;
4960 cfs_spin_unlock(&exp->exp_lock);
4961 data->ocd_version = LUSTRE_VERSION_CODE;
4962 exp->exp_mdt_data.med_ibits_known = data->ocd_ibits_known;
4966 if (mdt->mdt_opts.mo_acl &&
4967 ((exp->exp_connect_flags & OBD_CONNECT_ACL) == 0)) {
4968 CWARN("%s: MDS requires ACL support but client does not\n",
4969 mdt->mdt_md_dev.md_lu_dev.ld_obd->obd_name);
4974 if ((exp->exp_connect_flags & OBD_CONNECT_FID) == 0) {
4975 CWARN("%s: MDS requires FID support, but client not\n",
4976 mdt->mdt_md_dev.md_lu_dev.ld_obd->obd_name);
4980 if (mdt->mdt_som_conf && !exp_connect_som(exp) &&
4981 !(exp->exp_connect_flags & OBD_CONNECT_MDS_MDS)) {
4982 CWARN("%s: MDS has SOM enabled, but client does not support "
4983 "it\n", mdt->mdt_md_dev.md_lu_dev.ld_obd->obd_name);
4990 static int mdt_connect_check_sptlrpc(struct mdt_device *mdt,
4991 struct obd_export *exp,
4992 struct ptlrpc_request *req)
4994 struct sptlrpc_flavor flvr;
4997 if (exp->exp_flvr.sf_rpc == SPTLRPC_FLVR_INVALID) {
4998 cfs_read_lock(&mdt->mdt_sptlrpc_lock);
4999 sptlrpc_target_choose_flavor(&mdt->mdt_sptlrpc_rset,
5003 cfs_read_unlock(&mdt->mdt_sptlrpc_lock);
5005 cfs_spin_lock(&exp->exp_lock);
5007 exp->exp_sp_peer = req->rq_sp_from;
5008 exp->exp_flvr = flvr;
5010 if (exp->exp_flvr.sf_rpc != SPTLRPC_FLVR_ANY &&
5011 exp->exp_flvr.sf_rpc != req->rq_flvr.sf_rpc) {
5012 CERROR("unauthorized rpc flavor %x from %s, "
5013 "expect %x\n", req->rq_flvr.sf_rpc,
5014 libcfs_nid2str(req->rq_peer.nid),
5015 exp->exp_flvr.sf_rpc);
5019 cfs_spin_unlock(&exp->exp_lock);
5021 if (exp->exp_sp_peer != req->rq_sp_from) {
5022 CERROR("RPC source %s doesn't match %s\n",
5023 sptlrpc_part2name(req->rq_sp_from),
5024 sptlrpc_part2name(exp->exp_sp_peer));
5027 rc = sptlrpc_target_export_check(exp, req);
5034 /* mds_connect copy */
5035 static int mdt_obd_connect(const struct lu_env *env,
5036 struct obd_export **exp, struct obd_device *obd,
5037 struct obd_uuid *cluuid,
5038 struct obd_connect_data *data,
5041 struct mdt_thread_info *info;
5042 struct obd_export *lexp;
5043 struct lustre_handle conn = { 0 };
5044 struct mdt_device *mdt;
5045 struct ptlrpc_request *req;
5049 LASSERT(env != NULL);
5050 if (!exp || !obd || !cluuid)
5053 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
5054 req = info->mti_pill->rc_req;
5055 mdt = mdt_dev(obd->obd_lu_dev);
5057 rc = class_connect(&conn, obd, cluuid);
5061 lexp = class_conn2export(&conn);
5062 LASSERT(lexp != NULL);
5064 rc = mdt_connect_check_sptlrpc(mdt, lexp, req);
5068 if (OBD_FAIL_CHECK(OBD_FAIL_TGT_RCVG_FLAG))
5069 lustre_msg_add_op_flags(req->rq_repmsg, MSG_CONNECT_RECOVERING);
5071 rc = mdt_connect_internal(lexp, mdt, data);
5073 struct mdt_thread_info *mti;
5074 struct lsd_client_data *lcd = lexp->exp_target_data.ted_lcd;
5076 mti = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
5077 LASSERT(mti != NULL);
5078 mti->mti_exp = lexp;
5079 memcpy(lcd->lcd_uuid, cluuid, sizeof lcd->lcd_uuid);
5080 rc = mdt_client_new(env, mdt);
5082 mdt_export_stats_init(obd, lexp, localdata);
5087 class_disconnect(lexp);
5096 static int mdt_obd_reconnect(const struct lu_env *env,
5097 struct obd_export *exp, struct obd_device *obd,
5098 struct obd_uuid *cluuid,
5099 struct obd_connect_data *data,
5102 struct mdt_thread_info *info;
5103 struct mdt_device *mdt;
5104 struct ptlrpc_request *req;
5108 if (exp == NULL || obd == NULL || cluuid == NULL)
5111 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
5112 req = info->mti_pill->rc_req;
5113 mdt = mdt_dev(obd->obd_lu_dev);
5115 rc = mdt_connect_check_sptlrpc(mdt, exp, req);
5119 rc = mdt_connect_internal(exp, mdt_dev(obd->obd_lu_dev), data);
5121 mdt_export_stats_init(obd, exp, localdata);
5125 static int mdt_export_cleanup(struct obd_export *exp)
5127 struct mdt_export_data *med = &exp->exp_mdt_data;
5128 struct obd_device *obd = exp->exp_obd;
5129 struct mdt_device *mdt;
5130 struct mdt_thread_info *info;
5132 CFS_LIST_HEAD(closing_list);
5133 struct mdt_file_data *mfd, *n;
5137 cfs_spin_lock(&med->med_open_lock);
5138 while (!cfs_list_empty(&med->med_open_head)) {
5139 cfs_list_t *tmp = med->med_open_head.next;
5140 mfd = cfs_list_entry(tmp, struct mdt_file_data, mfd_list);
5142 /* Remove mfd handle so it can't be found again.
5143 * We are consuming the mfd_list reference here. */
5144 class_handle_unhash(&mfd->mfd_handle);
5145 cfs_list_move_tail(&mfd->mfd_list, &closing_list);
5147 cfs_spin_unlock(&med->med_open_lock);
5148 mdt = mdt_dev(obd->obd_lu_dev);
5149 LASSERT(mdt != NULL);
5151 rc = lu_env_init(&env, LCT_MD_THREAD);
5155 info = lu_context_key_get(&env.le_ctx, &mdt_thread_key);
5156 LASSERT(info != NULL);
5157 memset(info, 0, sizeof *info);
5158 info->mti_env = &env;
5159 info->mti_mdt = mdt;
5160 info->mti_exp = exp;
5162 if (!cfs_list_empty(&closing_list)) {
5163 struct md_attr *ma = &info->mti_attr;
5167 lmm_size = mdt->mdt_max_mdsize;
5168 OBD_ALLOC_LARGE(ma->ma_lmm, lmm_size);
5169 if (ma->ma_lmm == NULL)
5170 GOTO(out_lmm, rc = -ENOMEM);
5172 cookie_size = mdt->mdt_max_cookiesize;
5173 OBD_ALLOC_LARGE(ma->ma_cookie, cookie_size);
5174 if (ma->ma_cookie == NULL)
5175 GOTO(out_cookie, rc = -ENOMEM);
5177 /* Close any open files (which may also cause orphan unlinking). */
5178 cfs_list_for_each_entry_safe(mfd, n, &closing_list, mfd_list) {
5179 cfs_list_del_init(&mfd->mfd_list);
5180 memset(&ma->ma_attr, 0, sizeof(ma->ma_attr));
5181 ma->ma_lmm_size = lmm_size;
5182 ma->ma_cookie_size = cookie_size;
5184 /* It is not for setattr, just tell MDD to send
5185 * DESTROY RPC to OSS if needed */
5186 ma->ma_valid = MA_FLAGS;
5187 ma->ma_attr_flags = MDS_CLOSE_CLEANUP;
5188 /* Don't unlink orphan on failover umount, LU-184 */
5189 if (exp->exp_flags & OBD_OPT_FAILOVER)
5190 ma->ma_attr_flags |= MDS_KEEP_ORPHAN;
5191 mdt_mfd_close(info, mfd);
5193 OBD_FREE_LARGE(ma->ma_cookie, cookie_size);
5194 ma->ma_cookie = NULL;
5196 OBD_FREE_LARGE(ma->ma_lmm, lmm_size);
5200 info->mti_mdt = NULL;
5201 /* cleanup client slot early */
5202 /* Do not erase record for recoverable client. */
5203 if (!(exp->exp_flags & OBD_OPT_FAILOVER) || exp->exp_failed)
5204 mdt_client_del(&env, mdt);
5210 static int mdt_obd_disconnect(struct obd_export *exp)
5216 class_export_get(exp);
5218 rc = server_disconnect_export(exp);
5220 CDEBUG(D_IOCTL, "server disconnect error: %d\n", rc);
5222 rc = mdt_export_cleanup(exp);
5223 class_export_put(exp);
5227 /* FIXME: Can we avoid using these two interfaces? */
5228 static int mdt_init_export(struct obd_export *exp)
5230 struct mdt_export_data *med = &exp->exp_mdt_data;
5234 CFS_INIT_LIST_HEAD(&med->med_open_head);
5235 cfs_spin_lock_init(&med->med_open_lock);
5236 cfs_mutex_init(&med->med_idmap_mutex);
5237 med->med_idmap = NULL;
5238 cfs_spin_lock(&exp->exp_lock);
5239 exp->exp_connecting = 1;
5240 cfs_spin_unlock(&exp->exp_lock);
5242 /* self-export doesn't need client data and ldlm initialization */
5243 if (unlikely(obd_uuid_equals(&exp->exp_obd->obd_uuid,
5244 &exp->exp_client_uuid)))
5247 rc = lut_client_alloc(exp);
5249 rc = ldlm_init_export(exp);
5251 CERROR("%s: Error %d while initializing export\n",
5252 exp->exp_obd->obd_name, rc);
5256 static int mdt_destroy_export(struct obd_export *exp)
5260 if (exp_connect_rmtclient(exp))
5261 mdt_cleanup_idmap(&exp->exp_mdt_data);
5263 target_destroy_export(exp);
5264 /* destroy can be called from failed obd_setup, so
5265 * checking uuid is safer than obd_self_export */
5266 if (unlikely(obd_uuid_equals(&exp->exp_obd->obd_uuid,
5267 &exp->exp_client_uuid)))
5270 ldlm_destroy_export(exp);
5271 lut_client_free(exp);
5273 LASSERT(cfs_list_empty(&exp->exp_outstanding_replies));
5274 LASSERT(cfs_list_empty(&exp->exp_mdt_data.med_open_head));
5279 static void mdt_allow_cli(struct mdt_device *m, unsigned int flag)
5281 if (flag & CONFIG_LOG)
5282 cfs_set_bit(MDT_FL_CFGLOG, &m->mdt_state);
5284 /* also notify active event */
5285 if (flag & CONFIG_SYNC)
5286 cfs_set_bit(MDT_FL_SYNCED, &m->mdt_state);
5288 if (cfs_test_bit(MDT_FL_CFGLOG, &m->mdt_state) &&
5289 cfs_test_bit(MDT_FL_SYNCED, &m->mdt_state)) {
5290 struct obd_device *obd = m->mdt_md_dev.md_lu_dev.ld_obd;
5292 /* Open for clients */
5293 if (obd->obd_no_conn) {
5294 cfs_spin_lock(&obd->obd_dev_lock);
5295 obd->obd_no_conn = 0;
5296 cfs_spin_unlock(&obd->obd_dev_lock);
5301 static int mdt_upcall(const struct lu_env *env, struct md_device *md,
5302 enum md_upcall_event ev, void *data)
5304 struct mdt_device *m = mdt_dev(&md->md_lu_dev);
5305 struct md_device *next = m->mdt_child;
5306 struct mdt_thread_info *mti;
5312 rc = next->md_ops->mdo_maxsize_get(env, next,
5314 &m->mdt_max_cookiesize);
5315 CDEBUG(D_INFO, "get max mdsize %d max cookiesize %d\n",
5316 m->mdt_max_mdsize, m->mdt_max_cookiesize);
5317 mdt_allow_cli(m, CONFIG_SYNC);
5320 m->mdt_lut.lut_obd->u.obt.obt_mount_count;
5323 mti = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
5324 mti->mti_no_need_trans = 1;
5325 CDEBUG(D_INFO, "disable mdt trans for this thread\n");
5328 /* Check that MDT is not yet configured */
5329 LASSERT(!cfs_test_bit(MDT_FL_CFGLOG, &m->mdt_state));
5331 #ifdef HAVE_QUOTA_SUPPORT
5333 if (md->md_lu_dev.ld_obd->obd_recovering == 0 &&
5334 likely(md->md_lu_dev.ld_obd->obd_stopping == 0))
5335 next->md_ops->mdo_quota.mqo_recovery(env, next);
5339 CERROR("invalid event\n");
5346 static int mdt_obd_notify(struct obd_device *obd,
5347 struct obd_device *watched,
5348 enum obd_notify_event ev, void *data)
5350 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
5351 #ifdef HAVE_QUOTA_SUPPORT
5352 struct md_device *next = mdt->mdt_child;
5357 case OBD_NOTIFY_CONFIG:
5358 mdt_allow_cli(mdt, (unsigned long)data);
5360 #ifdef HAVE_QUOTA_SUPPORT
5361 /* quota_type has been processed, we can now handle
5362 * incoming quota requests */
5363 next->md_ops->mdo_quota.mqo_notify(NULL, next);
5367 CDEBUG(D_INFO, "Unhandled notification %#x\n", ev);
5372 static int mdt_rpc_fid2path(struct mdt_thread_info *info, void *key,
5373 void *val, int vallen)
5375 struct mdt_device *mdt = mdt_dev(info->mti_exp->exp_obd->obd_lu_dev);
5376 struct getinfo_fid2path *fpout, *fpin;
5379 fpin = key + cfs_size_round(sizeof(KEY_FID2PATH));
5382 if (ptlrpc_req_need_swab(info->mti_pill->rc_req))
5383 lustre_swab_fid2path(fpin);
5385 memcpy(fpout, fpin, sizeof(*fpin));
5386 if (fpout->gf_pathlen != vallen - sizeof(*fpin))
5389 rc = mdt_fid2path(info->mti_env, mdt, fpout);
5393 static int mdt_fid2path(const struct lu_env *env, struct mdt_device *mdt,
5394 struct getinfo_fid2path *fp)
5396 struct mdt_object *obj;
5400 CDEBUG(D_IOCTL, "path get "DFID" from "LPU64" #%d\n",
5401 PFID(&fp->gf_fid), fp->gf_recno, fp->gf_linkno);
5403 if (!fid_is_sane(&fp->gf_fid))
5406 obj = mdt_object_find(env, mdt, &fp->gf_fid);
5407 if (obj == NULL || IS_ERR(obj)) {
5408 CDEBUG(D_IOCTL, "no object "DFID": %ld\n", PFID(&fp->gf_fid),
5413 rc = lu_object_exists(&obj->mot_obj.mo_lu);
5419 mdt_object_put(env, obj);
5420 CDEBUG(D_IOCTL, "nonlocal object "DFID": %d\n",
5421 PFID(&fp->gf_fid), rc);
5425 rc = mo_path(env, md_object_next(&obj->mot_obj), fp->gf_path,
5426 fp->gf_pathlen, &fp->gf_recno, &fp->gf_linkno);
5427 mdt_object_put(env, obj);
5432 static int mdt_get_info(struct mdt_thread_info *info)
5434 struct ptlrpc_request *req = mdt_info_req(info);
5442 key = req_capsule_client_get(info->mti_pill, &RMF_GETINFO_KEY);
5444 CDEBUG(D_IOCTL, "No GETINFO key");
5447 keylen = req_capsule_get_size(info->mti_pill, &RMF_GETINFO_KEY,
5450 vallen = req_capsule_client_get(info->mti_pill, &RMF_GETINFO_VALLEN);
5451 if (vallen == NULL) {
5452 CDEBUG(D_IOCTL, "Unable to get RMF_GETINFO_VALLEN buffer");
5456 req_capsule_set_size(info->mti_pill, &RMF_GETINFO_VAL, RCL_SERVER,
5458 rc = req_capsule_server_pack(info->mti_pill);
5459 valout = req_capsule_server_get(info->mti_pill, &RMF_GETINFO_VAL);
5460 if (valout == NULL) {
5461 CDEBUG(D_IOCTL, "Unable to get get-info RPC out buffer");
5465 if (KEY_IS(KEY_FID2PATH))
5466 rc = mdt_rpc_fid2path(info, key, valout, *vallen);
5470 lustre_msg_set_status(req->rq_repmsg, rc);
5475 /* Pass the ioc down */
5476 static int mdt_ioc_child(struct lu_env *env, struct mdt_device *mdt,
5477 unsigned int cmd, int len, void *data)
5479 struct lu_context ioctl_session;
5480 struct md_device *next = mdt->mdt_child;
5484 rc = lu_context_init(&ioctl_session, LCT_SESSION);
5487 ioctl_session.lc_thread = (struct ptlrpc_thread *)cfs_current();
5488 lu_context_enter(&ioctl_session);
5489 env->le_ses = &ioctl_session;
5491 LASSERT(next->md_ops->mdo_iocontrol);
5492 rc = next->md_ops->mdo_iocontrol(env, next, cmd, len, data);
5494 lu_context_exit(&ioctl_session);
5495 lu_context_fini(&ioctl_session);
5499 static int mdt_ioc_version_get(struct mdt_thread_info *mti, void *karg)
5501 struct obd_ioctl_data *data = karg;
5502 struct lu_fid *fid = (struct lu_fid *)data->ioc_inlbuf1;
5504 struct mdt_object *obj;
5505 struct mdt_lock_handle *lh;
5509 CDEBUG(D_IOCTL, "getting version for "DFID"\n", PFID(fid));
5510 if (!fid_is_sane(fid))
5513 lh = &mti->mti_lh[MDT_LH_PARENT];
5514 mdt_lock_reg_init(lh, LCK_CR);
5516 obj = mdt_object_find_lock(mti, fid, lh, MDS_INODELOCK_UPDATE);
5518 RETURN(PTR_ERR(obj));
5520 rc = mdt_object_exists(obj);
5524 * before calling version get the correct MDS should be
5525 * fid, this is error to find remote object here
5527 CERROR("nonlocal object "DFID"\n", PFID(fid));
5528 } else if (rc == 0) {
5529 *(__u64 *)data->ioc_inlbuf2 = ENOENT_VERSION;
5532 version = dt_version_get(mti->mti_env, mdt_obj2dt(obj));
5533 *(__u64 *)data->ioc_inlbuf2 = version;
5536 mdt_object_unlock_put(mti, obj, lh, 1);
5540 /* ioctls on obd dev */
5541 static int mdt_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
5542 void *karg, void *uarg)
5545 struct obd_device *obd = exp->exp_obd;
5546 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
5547 struct dt_device *dt = mdt->mdt_bottom;
5551 CDEBUG(D_IOCTL, "handling ioctl cmd %#x\n", cmd);
5552 rc = lu_env_init(&env, LCT_MD_THREAD);
5558 rc = mdt_device_sync(&env, mdt);
5560 case OBD_IOC_SET_READONLY:
5561 rc = dt->dd_ops->dt_ro(&env, dt);
5563 case OBD_IOC_ABORT_RECOVERY:
5564 CERROR("Aborting recovery for device %s\n", obd->obd_name);
5565 target_stop_recovery_thread(obd);
5568 case OBD_IOC_CHANGELOG_REG:
5569 case OBD_IOC_CHANGELOG_DEREG:
5570 case OBD_IOC_CHANGELOG_CLEAR:
5571 rc = mdt_ioc_child(&env, mdt, cmd, len, karg);
5573 case OBD_IOC_GET_OBJ_VERSION: {
5574 struct mdt_thread_info *mti;
5575 mti = lu_context_key_get(&env.le_ctx, &mdt_thread_key);
5576 memset(mti, 0, sizeof *mti);
5577 mti->mti_env = &env;
5581 rc = mdt_ioc_version_get(mti, karg);
5585 CERROR("Not supported cmd = %d for device %s\n",
5586 cmd, obd->obd_name);
5594 int mdt_postrecov(const struct lu_env *env, struct mdt_device *mdt)
5596 struct lu_device *ld = md2lu_dev(mdt->mdt_child);
5597 #ifdef HAVE_QUOTA_SUPPORT
5598 struct obd_device *obd = mdt2obd_dev(mdt);
5599 struct md_device *next = mdt->mdt_child;
5604 rc = ld->ld_ops->ldo_recovery_complete(env, ld);
5605 #ifdef HAVE_QUOTA_SUPPORT
5606 if (likely(obd->obd_stopping == 0))
5607 next->md_ops->mdo_quota.mqo_recovery(env, next);
5612 int mdt_obd_postrecov(struct obd_device *obd)
5617 rc = lu_env_init(&env, LCT_MD_THREAD);
5620 rc = mdt_postrecov(&env, mdt_dev(obd->obd_lu_dev));
5626 * Send a copytool req to a client
5627 * Note this sends a request RPC from a server (MDT) to a client (MDC),
5628 * backwards of normal comms.
5630 int mdt_hsm_copytool_send(struct obd_export *exp)
5633 struct hsm_action_list *hal;
5634 struct hsm_action_item *hai;
5638 CWARN("%s: writing to mdc at %s\n", exp->exp_obd->obd_name,
5639 libcfs_nid2str(exp->exp_connection->c_peer.nid));
5641 len = sizeof(*lh) + sizeof(*hal) + MTI_NAME_MAXLEN +
5642 /* for mockup below */ 2 * cfs_size_round(sizeof(*hai));
5647 lh->kuc_magic = KUC_MAGIC;
5648 lh->kuc_transport = KUC_TRANSPORT_HSM;
5649 lh->kuc_msgtype = HMT_ACTION_LIST;
5650 lh->kuc_msglen = len;
5652 hal = (struct hsm_action_list *)(lh + 1);
5653 hal->hal_version = HAL_VERSION;
5654 hal->hal_archive_num = 1;
5655 obd_uuid2fsname(hal->hal_fsname, exp->exp_obd->obd_name,
5658 /* mock up an action list */
5660 hai = hai_zero(hal);
5661 hai->hai_action = HSMA_ARCHIVE;
5662 hai->hai_fid.f_oid = 0xA00A;
5663 hai->hai_len = sizeof(*hai);
5664 hai = hai_next(hai);
5665 hai->hai_action = HSMA_RESTORE;
5666 hai->hai_fid.f_oid = 0xB00B;
5667 hai->hai_len = sizeof(*hai);
5669 /* Uses the ldlm reverse import; this rpc will be seen by
5670 the ldlm_callback_handler */
5671 rc = do_set_info_async(exp->exp_imp_reverse,
5672 LDLM_SET_INFO, LUSTRE_OBD_VERSION,
5673 sizeof(KEY_HSM_COPYTOOL_SEND),
5674 KEY_HSM_COPYTOOL_SEND,
5682 static struct obd_ops mdt_obd_device_ops = {
5683 .o_owner = THIS_MODULE,
5684 .o_set_info_async = mdt_obd_set_info_async,
5685 .o_connect = mdt_obd_connect,
5686 .o_reconnect = mdt_obd_reconnect,
5687 .o_disconnect = mdt_obd_disconnect,
5688 .o_init_export = mdt_init_export,
5689 .o_destroy_export = mdt_destroy_export,
5690 .o_iocontrol = mdt_iocontrol,
5691 .o_postrecov = mdt_obd_postrecov,
5692 .o_notify = mdt_obd_notify
5695 static struct lu_device* mdt_device_fini(const struct lu_env *env,
5696 struct lu_device *d)
5698 struct mdt_device *m = mdt_dev(d);
5705 static struct lu_device *mdt_device_free(const struct lu_env *env,
5706 struct lu_device *d)
5708 struct mdt_device *m = mdt_dev(d);
5711 md_device_fini(&m->mdt_md_dev);
5716 static struct lu_device *mdt_device_alloc(const struct lu_env *env,
5717 struct lu_device_type *t,
5718 struct lustre_cfg *cfg)
5720 struct lu_device *l;
5721 struct mdt_device *m;
5727 l = &m->mdt_md_dev.md_lu_dev;
5728 rc = mdt_init0(env, m, t, cfg);
5730 mdt_device_free(env, l);
5734 md_upcall_init(&m->mdt_md_dev, mdt_upcall);
5736 l = ERR_PTR(-ENOMEM);
5740 /* context key constructor/destructor: mdt_key_init, mdt_key_fini */
5741 LU_KEY_INIT_FINI(mdt, struct mdt_thread_info);
5743 /* context key: mdt_thread_key */
5744 LU_CONTEXT_KEY_DEFINE(mdt, LCT_MD_THREAD);
5746 struct md_ucred *mdt_ucred(const struct mdt_thread_info *info)
5748 return md_ucred(info->mti_env);
5752 * Enable/disable COS (Commit On Sharing).
5754 * Set/Clear the COS flag in mdt options.
5756 * \param mdt mdt device
5757 * \param val 0 disables COS, other values enable COS
5759 void mdt_enable_cos(struct mdt_device *mdt, int val)
5764 mdt->mdt_opts.mo_cos = !!val;
5765 rc = lu_env_init(&env, LCT_MD_THREAD);
5766 if (unlikely(rc != 0)) {
5767 CWARN("lu_env initialization failed with rc = %d,"
5768 "cannot sync\n", rc);
5771 mdt_device_sync(&env, mdt);
5776 * Check COS (Commit On Sharing) status.
5778 * Return COS flag status.
5780 * \param mdt mdt device
5782 int mdt_cos_is_enabled(struct mdt_device *mdt)
5784 return mdt->mdt_opts.mo_cos != 0;
5787 /* type constructor/destructor: mdt_type_init, mdt_type_fini */
5788 LU_TYPE_INIT_FINI(mdt, &mdt_thread_key);
5790 static struct lu_device_type_operations mdt_device_type_ops = {
5791 .ldto_init = mdt_type_init,
5792 .ldto_fini = mdt_type_fini,
5794 .ldto_start = mdt_type_start,
5795 .ldto_stop = mdt_type_stop,
5797 .ldto_device_alloc = mdt_device_alloc,
5798 .ldto_device_free = mdt_device_free,
5799 .ldto_device_fini = mdt_device_fini
5802 static struct lu_device_type mdt_device_type = {
5803 .ldt_tags = LU_DEVICE_MD,
5804 .ldt_name = LUSTRE_MDT_NAME,
5805 .ldt_ops = &mdt_device_type_ops,
5806 .ldt_ctx_tags = LCT_MD_THREAD
5809 static struct lu_local_obj_desc mdt_last_recv = {
5810 .llod_name = LAST_RCVD,
5811 .llod_oid = MDT_LAST_RECV_OID,
5815 static int __init mdt_mod_init(void)
5817 struct lprocfs_static_vars lvars;
5820 llo_local_obj_register(&mdt_last_recv);
5822 if (mdt_num_threads > 0) {
5823 if (mdt_num_threads > MDT_MAX_THREADS)
5824 mdt_num_threads = MDT_MAX_THREADS;
5825 if (mdt_num_threads < MDT_MIN_THREADS)
5826 mdt_num_threads = MDT_MIN_THREADS;
5827 mdt_max_threads = mdt_min_threads = mdt_num_threads;
5829 mdt_max_threads = MDT_MAX_THREADS;
5830 mdt_min_threads = MDT_MIN_THREADS;
5833 lprocfs_mdt_init_vars(&lvars);
5834 rc = class_register_type(&mdt_obd_device_ops, NULL,
5835 lvars.module_vars, LUSTRE_MDT_NAME,
5841 static void __exit mdt_mod_exit(void)
5843 llo_local_obj_unregister(&mdt_last_recv);
5844 class_unregister_type(LUSTRE_MDT_NAME);
5848 #define DEF_HNDL(prefix, base, suffix, flags, opc, fn, fmt) \
5849 [prefix ## _ ## opc - prefix ## _ ## base] = { \
5851 .mh_fail_id = OBD_FAIL_ ## prefix ## _ ## opc ## suffix, \
5852 .mh_opc = prefix ## _ ## opc, \
5853 .mh_flags = flags, \
5858 #define DEF_MDT_HNDL(flags, name, fn, fmt) \
5859 DEF_HNDL(MDS, GETATTR, _NET, flags, name, fn, fmt)
5861 #define DEF_SEQ_HNDL(flags, name, fn, fmt) \
5862 DEF_HNDL(SEQ, QUERY, _NET, flags, name, fn, fmt)
5864 #define DEF_FLD_HNDL(flags, name, fn, fmt) \
5865 DEF_HNDL(FLD, QUERY, _NET, flags, name, fn, fmt)
5867 * Request with a format known in advance
5869 #define DEF_MDT_HNDL_F(flags, name, fn) \
5870 DEF_HNDL(MDS, GETATTR, _NET, flags, name, fn, &RQF_MDS_ ## name)
5872 #define DEF_SEQ_HNDL_F(flags, name, fn) \
5873 DEF_HNDL(SEQ, QUERY, _NET, flags, name, fn, &RQF_SEQ_ ## name)
5875 #define DEF_FLD_HNDL_F(flags, name, fn) \
5876 DEF_HNDL(FLD, QUERY, _NET, flags, name, fn, &RQF_FLD_ ## name)
5878 * Request with a format we do not yet know
5880 #define DEF_MDT_HNDL_0(flags, name, fn) \
5881 DEF_HNDL(MDS, GETATTR, _NET, flags, name, fn, NULL)
5883 static struct mdt_handler mdt_mds_ops[] = {
5884 DEF_MDT_HNDL_F(0, CONNECT, mdt_connect),
5885 DEF_MDT_HNDL_F(0, DISCONNECT, mdt_disconnect),
5886 DEF_MDT_HNDL (0, SET_INFO, mdt_set_info,
5888 DEF_MDT_HNDL_F(0, GET_INFO, mdt_get_info),
5889 DEF_MDT_HNDL_F(0 |HABEO_REFERO, GETSTATUS, mdt_getstatus),
5890 DEF_MDT_HNDL_F(HABEO_CORPUS, GETATTR, mdt_getattr),
5891 DEF_MDT_HNDL_F(HABEO_CORPUS|HABEO_REFERO, GETATTR_NAME, mdt_getattr_name),
5892 DEF_MDT_HNDL_F(HABEO_CORPUS, GETXATTR, mdt_getxattr),
5893 DEF_MDT_HNDL_F(0 |HABEO_REFERO, STATFS, mdt_statfs),
5894 DEF_MDT_HNDL_F(0 |MUTABOR, REINT, mdt_reint),
5895 DEF_MDT_HNDL_F(HABEO_CORPUS, CLOSE, mdt_close),
5896 DEF_MDT_HNDL_F(HABEO_CORPUS, DONE_WRITING, mdt_done_writing),
5897 DEF_MDT_HNDL_F(0 |HABEO_REFERO, PIN, mdt_pin),
5898 DEF_MDT_HNDL_0(0, SYNC, mdt_sync),
5899 DEF_MDT_HNDL_F(HABEO_CORPUS|HABEO_REFERO, IS_SUBDIR, mdt_is_subdir),
5900 #ifdef HAVE_QUOTA_SUPPORT
5901 DEF_MDT_HNDL_F(0, QUOTACHECK, mdt_quotacheck_handle),
5902 DEF_MDT_HNDL_F(0, QUOTACTL, mdt_quotactl_handle)
5906 #define DEF_OBD_HNDL(flags, name, fn) \
5907 DEF_HNDL(OBD, PING, _NET, flags, name, fn, NULL)
5910 static struct mdt_handler mdt_obd_ops[] = {
5911 DEF_OBD_HNDL(0, PING, mdt_obd_ping),
5912 DEF_OBD_HNDL(0, LOG_CANCEL, mdt_obd_log_cancel),
5913 DEF_OBD_HNDL(0, QC_CALLBACK, mdt_obd_qc_callback)
5916 #define DEF_DLM_HNDL_0(flags, name, fn) \
5917 DEF_HNDL(LDLM, ENQUEUE, , flags, name, fn, NULL)
5918 #define DEF_DLM_HNDL_F(flags, name, fn) \
5919 DEF_HNDL(LDLM, ENQUEUE, , flags, name, fn, &RQF_LDLM_ ## name)
5921 static struct mdt_handler mdt_dlm_ops[] = {
5922 DEF_DLM_HNDL_F(HABEO_CLAVIS, ENQUEUE, mdt_enqueue),
5923 DEF_DLM_HNDL_0(HABEO_CLAVIS, CONVERT, mdt_convert),
5924 DEF_DLM_HNDL_0(0, BL_CALLBACK, mdt_bl_callback),
5925 DEF_DLM_HNDL_0(0, CP_CALLBACK, mdt_cp_callback)
5928 #define DEF_LLOG_HNDL(flags, name, fn) \
5929 DEF_HNDL(LLOG, ORIGIN_HANDLE_CREATE, _NET, flags, name, fn, NULL)
5931 static struct mdt_handler mdt_llog_ops[] = {
5932 DEF_LLOG_HNDL(0, ORIGIN_HANDLE_CREATE, mdt_llog_create),
5933 DEF_LLOG_HNDL(0, ORIGIN_HANDLE_NEXT_BLOCK, mdt_llog_next_block),
5934 DEF_LLOG_HNDL(0, ORIGIN_HANDLE_READ_HEADER, mdt_llog_read_header),
5935 DEF_LLOG_HNDL(0, ORIGIN_HANDLE_WRITE_REC, NULL),
5936 DEF_LLOG_HNDL(0, ORIGIN_HANDLE_CLOSE, NULL),
5937 DEF_LLOG_HNDL(0, ORIGIN_CONNECT, NULL),
5938 DEF_LLOG_HNDL(0, CATINFO, NULL),
5939 DEF_LLOG_HNDL(0, ORIGIN_HANDLE_PREV_BLOCK, mdt_llog_prev_block),
5940 DEF_LLOG_HNDL(0, ORIGIN_HANDLE_DESTROY, mdt_llog_destroy),
5943 #define DEF_SEC_CTX_HNDL(name, fn) \
5944 DEF_HNDL(SEC_CTX, INIT, _NET, 0, name, fn, NULL)
5946 static struct mdt_handler mdt_sec_ctx_ops[] = {
5947 DEF_SEC_CTX_HNDL(INIT, mdt_sec_ctx_handle),
5948 DEF_SEC_CTX_HNDL(INIT_CONT, mdt_sec_ctx_handle),
5949 DEF_SEC_CTX_HNDL(FINI, mdt_sec_ctx_handle)
5952 static struct mdt_opc_slice mdt_regular_handlers[] = {
5954 .mos_opc_start = MDS_GETATTR,
5955 .mos_opc_end = MDS_LAST_OPC,
5956 .mos_hs = mdt_mds_ops
5959 .mos_opc_start = OBD_PING,
5960 .mos_opc_end = OBD_LAST_OPC,
5961 .mos_hs = mdt_obd_ops
5964 .mos_opc_start = LDLM_ENQUEUE,
5965 .mos_opc_end = LDLM_LAST_OPC,
5966 .mos_hs = mdt_dlm_ops
5969 .mos_opc_start = LLOG_ORIGIN_HANDLE_CREATE,
5970 .mos_opc_end = LLOG_LAST_OPC,
5971 .mos_hs = mdt_llog_ops
5974 .mos_opc_start = SEC_CTX_INIT,
5975 .mos_opc_end = SEC_LAST_OPC,
5976 .mos_hs = mdt_sec_ctx_ops
5983 static struct mdt_handler mdt_readpage_ops[] = {
5984 DEF_MDT_HNDL_F(0, CONNECT, mdt_connect),
5985 DEF_MDT_HNDL_F(HABEO_CORPUS|HABEO_REFERO, READPAGE, mdt_readpage),
5986 #ifdef HAVE_SPLIT_SUPPORT
5987 DEF_MDT_HNDL_F(HABEO_CORPUS|HABEO_REFERO, WRITEPAGE, mdt_writepage),
5991 * XXX: this is ugly and should be fixed one day, see mdc_close() for
5992 * detailed comments. --umka
5994 DEF_MDT_HNDL_F(HABEO_CORPUS, CLOSE, mdt_close),
5995 DEF_MDT_HNDL_F(HABEO_CORPUS, DONE_WRITING, mdt_done_writing),
5998 static struct mdt_opc_slice mdt_readpage_handlers[] = {
6000 .mos_opc_start = MDS_GETATTR,
6001 .mos_opc_end = MDS_LAST_OPC,
6002 .mos_hs = mdt_readpage_ops
6009 static struct mdt_handler mdt_xmds_ops[] = {
6010 DEF_MDT_HNDL_F(0, CONNECT, mdt_connect),
6011 DEF_MDT_HNDL_F(HABEO_CORPUS , GETATTR, mdt_getattr),
6012 DEF_MDT_HNDL_F(0 | MUTABOR , REINT, mdt_reint),
6013 DEF_MDT_HNDL_F(HABEO_CORPUS|HABEO_REFERO, IS_SUBDIR, mdt_is_subdir),
6016 static struct mdt_opc_slice mdt_xmds_handlers[] = {
6018 .mos_opc_start = MDS_GETATTR,
6019 .mos_opc_end = MDS_LAST_OPC,
6020 .mos_hs = mdt_xmds_ops
6023 .mos_opc_start = OBD_PING,
6024 .mos_opc_end = OBD_LAST_OPC,
6025 .mos_hs = mdt_obd_ops
6028 .mos_opc_start = SEC_CTX_INIT,
6029 .mos_opc_end = SEC_LAST_OPC,
6030 .mos_hs = mdt_sec_ctx_ops
6037 static struct mdt_handler mdt_seq_ops[] = {
6038 DEF_SEQ_HNDL_F(0, QUERY, (int (*)(struct mdt_thread_info *))seq_query)
6041 static struct mdt_opc_slice mdt_seq_handlers[] = {
6043 .mos_opc_start = SEQ_QUERY,
6044 .mos_opc_end = SEQ_LAST_OPC,
6045 .mos_hs = mdt_seq_ops
6052 static struct mdt_handler mdt_fld_ops[] = {
6053 DEF_FLD_HNDL_F(0, QUERY, (int (*)(struct mdt_thread_info *))fld_query)
6056 static struct mdt_opc_slice mdt_fld_handlers[] = {
6058 .mos_opc_start = FLD_QUERY,
6059 .mos_opc_end = FLD_LAST_OPC,
6060 .mos_hs = mdt_fld_ops
6067 MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");
6068 MODULE_DESCRIPTION("Lustre Meta-data Target ("LUSTRE_MDT_NAME")");
6069 MODULE_LICENSE("GPL");
6071 CFS_MODULE_PARM(mdt_num_threads, "ul", ulong, 0444,
6072 "number of mdt service threads to start");
6074 cfs_module(mdt, "0.2.0", mdt_mod_init, mdt_mod_exit);