1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 only,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License version 2 for more details (a copy is included
16 * in the LICENSE file that accompanied this code).
18 * You should have received a copy of the GNU General Public License
19 * version 2 along with this program; If not, see
20 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
29 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
30 * Use is subject to license terms.
32 * Copyright (c) 2011, 2012, Whamcloud, Inc.
35 * This file is part of Lustre, http://www.lustre.org/
36 * Lustre is a trademark of Sun Microsystems, Inc.
38 * lustre/mdt/mdt_handler.c
40 * Lustre Metadata Target (mdt) request handler
42 * Author: Peter Braam <braam@clusterfs.com>
43 * Author: Andreas Dilger <adilger@clusterfs.com>
44 * Author: Phil Schwan <phil@clusterfs.com>
45 * Author: Mike Shaver <shaver@clusterfs.com>
46 * Author: Nikita Danilov <nikita@clusterfs.com>
47 * Author: Huang Hua <huanghua@clusterfs.com>
48 * Author: Yury Umanets <umka@clusterfs.com>
52 # define EXPORT_SYMTAB
54 #define DEBUG_SUBSYSTEM S_MDS
56 #include <linux/module.h>
58 * struct OBD_{ALLOC,FREE}*()
60 #include <obd_support.h>
61 /* struct ptlrpc_request */
62 #include <lustre_net.h>
63 /* struct obd_export */
64 #include <lustre_export.h>
65 /* struct obd_device */
68 #include <dt_object.h>
69 #include <lustre_mds.h>
70 #include <lustre_mdt.h>
71 #include "mdt_internal.h"
72 #ifdef HAVE_QUOTA_SUPPORT
73 # include <lustre_quota.h>
75 #include <lustre_acl.h>
76 #include <lustre_param.h>
77 #include <lustre_fsfilt.h>
79 mdl_mode_t mdt_mdl_lock_modes[] = {
80 [LCK_MINMODE] = MDL_MINMODE,
87 [LCK_GROUP] = MDL_GROUP
90 ldlm_mode_t mdt_dlm_lock_modes[] = {
91 [MDL_MINMODE] = LCK_MINMODE,
98 [MDL_GROUP] = LCK_GROUP
102 * Initialized in mdt_mod_init().
104 static unsigned long mdt_num_threads;
105 static unsigned long mdt_min_threads;
106 static unsigned long mdt_max_threads;
108 /* ptlrpc request handler for MDT. All handlers are
109 * grouped into several slices - struct mdt_opc_slice,
110 * and stored in an array - mdt_handlers[].
113 /* The name of this handler. */
115 /* Fail id for this handler, checked at the beginning of this handler*/
117 /* Operation code for this handler */
119 /* flags are listed in enum mdt_handler_flags below. */
121 /* The actual handler function to execute. */
122 int (*mh_act)(struct mdt_thread_info *info);
123 /* Request format for this request. */
124 const struct req_format *mh_fmt;
127 enum mdt_handler_flags {
129 * struct mdt_body is passed in the incoming message, and object
130 * identified by this fid exists on disk.
132 * "habeo corpus" == "I have a body"
134 HABEO_CORPUS = (1 << 0),
136 * struct ldlm_request is passed in the incoming message.
138 * "habeo clavis" == "I have a key"
140 HABEO_CLAVIS = (1 << 1),
142 * this request has fixed reply format, so that reply message can be
143 * packed by generic code.
145 * "habeo refero" == "I have a reply"
147 HABEO_REFERO = (1 << 2),
149 * this request will modify something, so check whether the filesystem
150 * is readonly or not, then return -EROFS to client asap if necessary.
152 * "mutabor" == "I shall modify"
157 struct mdt_opc_slice {
160 struct mdt_handler *mos_hs;
163 static struct mdt_opc_slice mdt_regular_handlers[];
164 static struct mdt_opc_slice mdt_readpage_handlers[];
165 static struct mdt_opc_slice mdt_xmds_handlers[];
166 static struct mdt_opc_slice mdt_seq_handlers[];
167 static struct mdt_opc_slice mdt_fld_handlers[];
169 static struct mdt_device *mdt_dev(struct lu_device *d);
170 static int mdt_regular_handle(struct ptlrpc_request *req);
171 static int mdt_unpack_req_pack_rep(struct mdt_thread_info *info, __u32 flags);
172 static int mdt_fid2path(const struct lu_env *env, struct mdt_device *mdt,
173 struct getinfo_fid2path *fp);
175 static const struct lu_object_operations mdt_obj_ops;
177 int mdt_get_disposition(struct ldlm_reply *rep, int flag)
181 return (rep->lock_policy_res1 & flag);
184 void mdt_clear_disposition(struct mdt_thread_info *info,
185 struct ldlm_reply *rep, int flag)
188 info->mti_opdata &= ~flag;
190 rep->lock_policy_res1 &= ~flag;
193 void mdt_set_disposition(struct mdt_thread_info *info,
194 struct ldlm_reply *rep, int flag)
197 info->mti_opdata |= flag;
199 rep->lock_policy_res1 |= flag;
202 void mdt_lock_reg_init(struct mdt_lock_handle *lh, ldlm_mode_t lm)
204 lh->mlh_pdo_hash = 0;
205 lh->mlh_reg_mode = lm;
206 lh->mlh_type = MDT_REG_LOCK;
209 void mdt_lock_pdo_init(struct mdt_lock_handle *lh, ldlm_mode_t lm,
210 const char *name, int namelen)
212 lh->mlh_reg_mode = lm;
213 lh->mlh_type = MDT_PDO_LOCK;
215 if (name != NULL && (name[0] != '\0')) {
216 LASSERT(namelen > 0);
217 lh->mlh_pdo_hash = full_name_hash(name, namelen);
219 LASSERT(namelen == 0);
220 lh->mlh_pdo_hash = 0ull;
224 static void mdt_lock_pdo_mode(struct mdt_thread_info *info, struct mdt_object *o,
225 struct mdt_lock_handle *lh)
231 * Any dir access needs couple of locks:
233 * 1) on part of dir we gonna take lookup/modify;
235 * 2) on whole dir to protect it from concurrent splitting and/or to
236 * flush client's cache for readdir().
238 * so, for a given mode and object this routine decides what lock mode
239 * to use for lock #2:
241 * 1) if caller's gonna lookup in dir then we need to protect dir from
242 * being splitted only - LCK_CR
244 * 2) if caller's gonna modify dir then we need to protect dir from
245 * being splitted and to flush cache - LCK_CW
247 * 3) if caller's gonna modify dir and that dir seems ready for
248 * splitting then we need to protect it from any type of access
249 * (lookup/modify/split) - LCK_EX --bzzz
252 LASSERT(lh->mlh_reg_mode != LCK_MINMODE);
253 LASSERT(lh->mlh_pdo_mode == LCK_MINMODE);
256 * Ask underlaying level its opinion about preferable PDO lock mode
257 * having access type passed as regular lock mode:
259 * - MDL_MINMODE means that lower layer does not want to specify lock
262 * - MDL_NL means that no PDO lock should be taken. This is used in some
263 * cases. Say, for non-splittable directories no need to use PDO locks
266 mode = mdo_lock_mode(info->mti_env, mdt_object_child(o),
267 mdt_dlm_mode2mdl_mode(lh->mlh_reg_mode));
269 if (mode != MDL_MINMODE) {
270 lh->mlh_pdo_mode = mdt_mdl_mode2dlm_mode(mode);
273 * Lower layer does not want to specify locking mode. We do it
274 * our selves. No special protection is needed, just flush
275 * client's cache on modification and allow concurrent
278 switch (lh->mlh_reg_mode) {
280 lh->mlh_pdo_mode = LCK_EX;
283 lh->mlh_pdo_mode = LCK_CR;
286 lh->mlh_pdo_mode = LCK_CW;
289 CERROR("Not expected lock type (0x%x)\n",
290 (int)lh->mlh_reg_mode);
295 LASSERT(lh->mlh_pdo_mode != LCK_MINMODE);
299 static int mdt_getstatus(struct mdt_thread_info *info)
301 struct mdt_device *mdt = info->mti_mdt;
302 struct md_device *next = mdt->mdt_child;
303 struct mdt_body *repbody;
308 rc = mdt_check_ucred(info);
310 RETURN(err_serious(rc));
312 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_GETSTATUS_PACK))
313 RETURN(err_serious(-ENOMEM));
315 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
316 rc = next->md_ops->mdo_root_get(info->mti_env, next, &repbody->fid1);
320 repbody->valid |= OBD_MD_FLID;
322 if (mdt->mdt_opts.mo_mds_capa &&
323 info->mti_exp->exp_connect_flags & OBD_CONNECT_MDS_CAPA) {
324 struct mdt_object *root;
325 struct lustre_capa *capa;
327 root = mdt_object_find(info->mti_env, mdt, &repbody->fid1);
329 RETURN(PTR_ERR(root));
331 capa = req_capsule_server_get(info->mti_pill, &RMF_CAPA1);
333 capa->lc_opc = CAPA_OPC_MDS_DEFAULT;
334 rc = mo_capa_get(info->mti_env, mdt_object_child(root), capa,
336 mdt_object_put(info->mti_env, root);
338 repbody->valid |= OBD_MD_FLMDSCAPA;
344 static int mdt_statfs(struct mdt_thread_info *info)
346 struct ptlrpc_request *req = mdt_info_req(info);
347 struct md_device *next = info->mti_mdt->mdt_child;
348 struct ptlrpc_service *svc;
349 struct obd_statfs *osfs;
354 svc = info->mti_pill->rc_req->rq_rqbd->rqbd_service;
356 /* This will trigger a watchdog timeout */
357 OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_STATFS_LCW_SLEEP,
358 (MDT_SERVICE_WATCHDOG_FACTOR *
359 at_get(&svc->srv_at_estimate)) + 1);
361 rc = mdt_check_ucred(info);
363 RETURN(err_serious(rc));
365 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_STATFS_PACK)) {
366 rc = err_serious(-ENOMEM);
368 osfs = req_capsule_server_get(info->mti_pill, &RMF_OBD_STATFS);
369 rc = next->md_ops->mdo_statfs(info->mti_env, next,
371 statfs_pack(osfs, &info->mti_u.ksfs);
375 mdt_counter_incr(req->rq_export, LPROC_MDT_STATFS);
381 * Pack SOM attributes into the reply.
382 * Call under a DLM UPDATE lock.
384 static void mdt_pack_size2body(struct mdt_thread_info *info,
385 struct mdt_object *mo)
388 struct md_attr *ma = &info->mti_attr;
390 LASSERT(ma->ma_attr.la_valid & LA_MODE);
391 b = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
393 /* Check if Size-on-MDS is supported, if this is a regular file,
394 * if SOM is enabled on the object and if SOM cache exists and valid.
395 * Otherwise do not pack Size-on-MDS attributes to the reply. */
396 if (!(mdt_conn_flags(info) & OBD_CONNECT_SOM) ||
397 !S_ISREG(ma->ma_attr.la_mode) ||
398 !mdt_object_is_som_enabled(mo) ||
399 !(ma->ma_valid & MA_SOM))
402 b->valid |= OBD_MD_FLSIZE | OBD_MD_FLBLOCKS;
403 b->size = ma->ma_som->msd_size;
404 b->blocks = ma->ma_som->msd_blocks;
407 void mdt_pack_attr2body(struct mdt_thread_info *info, struct mdt_body *b,
408 const struct lu_attr *attr, const struct lu_fid *fid)
410 struct md_attr *ma = &info->mti_attr;
412 LASSERT(ma->ma_valid & MA_INODE);
414 b->atime = attr->la_atime;
415 b->mtime = attr->la_mtime;
416 b->ctime = attr->la_ctime;
417 b->mode = attr->la_mode;
418 b->size = attr->la_size;
419 b->blocks = attr->la_blocks;
420 b->uid = attr->la_uid;
421 b->gid = attr->la_gid;
422 b->flags = attr->la_flags;
423 b->nlink = attr->la_nlink;
424 b->rdev = attr->la_rdev;
426 /*XXX should pack the reply body according to lu_valid*/
427 b->valid |= OBD_MD_FLCTIME | OBD_MD_FLUID |
428 OBD_MD_FLGID | OBD_MD_FLTYPE |
429 OBD_MD_FLMODE | OBD_MD_FLNLINK | OBD_MD_FLFLAGS |
430 OBD_MD_FLATIME | OBD_MD_FLMTIME ;
432 if (!S_ISREG(attr->la_mode)) {
433 b->valid |= OBD_MD_FLSIZE | OBD_MD_FLBLOCKS | OBD_MD_FLRDEV;
434 } else if (ma->ma_need & MA_LOV && ma->ma_lmm_size == 0) {
435 /* means no objects are allocated on osts. */
436 LASSERT(!(ma->ma_valid & MA_LOV));
437 /* just ignore blocks occupied by extend attributes on MDS */
439 /* if no object is allocated on osts, the size on mds is valid. b=22272 */
440 b->valid |= OBD_MD_FLSIZE | OBD_MD_FLBLOCKS;
445 b->valid |= OBD_MD_FLID;
447 /* FIXME: these should be fixed when new igif ready.*/
448 b->ino = fid_oid(fid); /* 1.6 compatibility */
449 b->generation = fid_ver(fid); /* 1.6 compatibility */
450 b->valid |= OBD_MD_FLGENER; /* 1.6 compatibility */
452 CDEBUG(D_INODE, DFID": nlink=%d, mode=%o, size="LPU64"\n",
453 PFID(fid), b->nlink, b->mode, b->size);
457 mdt_body_reverse_idmap(info, b);
459 if (b->valid & OBD_MD_FLSIZE)
460 CDEBUG(D_VFSTRACE, DFID": returning size %llu\n",
461 PFID(fid), (unsigned long long)b->size);
464 static inline int mdt_body_has_lov(const struct lu_attr *la,
465 const struct mdt_body *body)
467 return ((S_ISREG(la->la_mode) && (body->valid & OBD_MD_FLEASIZE)) ||
468 (S_ISDIR(la->la_mode) && (body->valid & OBD_MD_FLDIREA )) );
471 void mdt_client_compatibility(struct mdt_thread_info *info)
473 struct mdt_body *body;
474 struct ptlrpc_request *req = mdt_info_req(info);
475 struct obd_export *exp = req->rq_export;
476 struct md_attr *ma = &info->mti_attr;
477 struct lu_attr *la = &ma->ma_attr;
480 if (exp->exp_connect_flags & OBD_CONNECT_LAYOUTLOCK)
481 /* the client can deal with 16-bit lmm_stripe_count */
484 body = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
486 if (!mdt_body_has_lov(la, body))
489 /* now we have a reply with a lov for a client not compatible with the
490 * layout lock so we have to clean the layout generation number */
491 if (S_ISREG(la->la_mode))
492 ma->ma_lmm->lmm_layout_gen = 0;
497 static int mdt_getattr_internal(struct mdt_thread_info *info,
498 struct mdt_object *o, int ma_need)
500 struct md_object *next = mdt_object_child(o);
501 const struct mdt_body *reqbody = info->mti_body;
502 struct ptlrpc_request *req = mdt_info_req(info);
503 struct md_attr *ma = &info->mti_attr;
504 struct lu_attr *la = &ma->ma_attr;
505 struct req_capsule *pill = info->mti_pill;
506 const struct lu_env *env = info->mti_env;
507 struct mdt_body *repbody;
508 struct lu_buf *buffer = &info->mti_buf;
512 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_GETATTR_PACK))
513 RETURN(err_serious(-ENOMEM));
515 repbody = req_capsule_server_get(pill, &RMF_MDT_BODY);
519 rc = mdt_object_exists(o);
521 /* This object is located on remote node.*/
522 repbody->fid1 = *mdt_object_fid(o);
523 repbody->valid = OBD_MD_FLID | OBD_MD_MDS;
527 buffer->lb_buf = req_capsule_server_get(pill, &RMF_MDT_MD);
528 buffer->lb_len = req_capsule_get_size(pill, &RMF_MDT_MD, RCL_SERVER);
530 /* If it is dir object and client require MEA, then we got MEA */
531 if (S_ISDIR(lu_object_attr(&next->mo_lu)) &&
532 reqbody->valid & OBD_MD_MEA) {
533 /* Assumption: MDT_MD size is enough for lmv size. */
534 ma->ma_lmv = buffer->lb_buf;
535 ma->ma_lmv_size = buffer->lb_len;
536 ma->ma_need = MA_LMV | MA_INODE;
538 ma->ma_lmm = buffer->lb_buf;
539 ma->ma_lmm_size = buffer->lb_len;
540 ma->ma_need = MA_LOV | MA_INODE;
543 if (S_ISDIR(lu_object_attr(&next->mo_lu)) &&
544 reqbody->valid & OBD_MD_FLDIREA &&
545 lustre_msg_get_opc(req->rq_reqmsg) == MDS_GETATTR) {
546 /* get default stripe info for this dir. */
547 ma->ma_need |= MA_LOV_DEF;
549 ma->ma_need |= ma_need;
550 if (ma->ma_need & MA_SOM)
551 ma->ma_som = &info->mti_u.som.data;
553 rc = mo_attr_get(env, next, ma);
555 CERROR("getattr error for "DFID": %d\n",
556 PFID(mdt_object_fid(o)), rc);
560 if (likely(ma->ma_valid & MA_INODE))
561 mdt_pack_attr2body(info, repbody, la, mdt_object_fid(o));
565 if (mdt_body_has_lov(la, reqbody)) {
566 if (ma->ma_valid & MA_LOV) {
567 LASSERT(ma->ma_lmm_size);
568 mdt_dump_lmm(D_INFO, ma->ma_lmm);
569 repbody->eadatasize = ma->ma_lmm_size;
570 if (S_ISDIR(la->la_mode))
571 repbody->valid |= OBD_MD_FLDIREA;
573 repbody->valid |= OBD_MD_FLEASIZE;
575 if (ma->ma_valid & MA_LMV) {
576 LASSERT(S_ISDIR(la->la_mode));
577 repbody->eadatasize = ma->ma_lmv_size;
578 repbody->valid |= (OBD_MD_FLDIREA|OBD_MD_MEA);
580 } else if (S_ISLNK(la->la_mode) &&
581 reqbody->valid & OBD_MD_LINKNAME) {
582 buffer->lb_buf = ma->ma_lmm;
583 buffer->lb_len = reqbody->eadatasize;
584 rc = mo_readlink(env, next, buffer);
585 if (unlikely(rc <= 0)) {
586 CERROR("readlink failed: %d\n", rc);
589 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_READLINK_EPROTO))
591 repbody->valid |= OBD_MD_LINKNAME;
592 repbody->eadatasize = rc;
594 ((char*)ma->ma_lmm)[rc - 1] = 0;
595 CDEBUG(D_INODE, "symlink dest %s, len = %d\n",
596 (char*)ma->ma_lmm, rc);
601 if (reqbody->valid & OBD_MD_FLMODEASIZE) {
602 repbody->max_cookiesize = info->mti_mdt->mdt_max_cookiesize;
603 repbody->max_mdsize = info->mti_mdt->mdt_max_mdsize;
604 repbody->valid |= OBD_MD_FLMODEASIZE;
605 CDEBUG(D_INODE, "I am going to change the MAX_MD_SIZE & "
606 "MAX_COOKIE to : %d:%d\n", repbody->max_mdsize,
607 repbody->max_cookiesize);
610 if (exp_connect_rmtclient(info->mti_exp) &&
611 reqbody->valid & OBD_MD_FLRMTPERM) {
612 void *buf = req_capsule_server_get(pill, &RMF_ACL);
614 /* mdt_getattr_lock only */
615 rc = mdt_pack_remote_perm(info, o, buf);
617 repbody->valid &= ~OBD_MD_FLRMTPERM;
618 repbody->aclsize = 0;
621 repbody->valid |= OBD_MD_FLRMTPERM;
622 repbody->aclsize = sizeof(struct mdt_remote_perm);
625 #ifdef CONFIG_FS_POSIX_ACL
626 else if ((req->rq_export->exp_connect_flags & OBD_CONNECT_ACL) &&
627 (reqbody->valid & OBD_MD_FLACL)) {
628 buffer->lb_buf = req_capsule_server_get(pill, &RMF_ACL);
629 buffer->lb_len = req_capsule_get_size(pill,
630 &RMF_ACL, RCL_SERVER);
631 if (buffer->lb_len > 0) {
632 rc = mo_xattr_get(env, next, buffer,
633 XATTR_NAME_ACL_ACCESS);
635 if (rc == -ENODATA) {
636 repbody->aclsize = 0;
637 repbody->valid |= OBD_MD_FLACL;
639 } else if (rc == -EOPNOTSUPP) {
642 CERROR("got acl size: %d\n", rc);
645 repbody->aclsize = rc;
646 repbody->valid |= OBD_MD_FLACL;
653 if (reqbody->valid & OBD_MD_FLMDSCAPA &&
654 info->mti_mdt->mdt_opts.mo_mds_capa &&
655 info->mti_exp->exp_connect_flags & OBD_CONNECT_MDS_CAPA) {
656 struct lustre_capa *capa;
658 capa = req_capsule_server_get(pill, &RMF_CAPA1);
660 capa->lc_opc = CAPA_OPC_MDS_DEFAULT;
661 rc = mo_capa_get(env, next, capa, 0);
664 repbody->valid |= OBD_MD_FLMDSCAPA;
669 static int mdt_renew_capa(struct mdt_thread_info *info)
671 struct mdt_object *obj = info->mti_object;
672 struct mdt_body *body;
673 struct lustre_capa *capa, *c;
677 /* if object doesn't exist, or server has disabled capability,
678 * return directly, client will find body->valid OBD_MD_FLOSSCAPA
681 if (!obj || !info->mti_mdt->mdt_opts.mo_oss_capa ||
682 !(info->mti_exp->exp_connect_flags & OBD_CONNECT_OSS_CAPA))
685 body = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
686 LASSERT(body != NULL);
688 c = req_capsule_client_get(info->mti_pill, &RMF_CAPA1);
691 capa = req_capsule_server_get(info->mti_pill, &RMF_CAPA2);
695 rc = mo_capa_get(info->mti_env, mdt_object_child(obj), capa, 1);
697 body->valid |= OBD_MD_FLOSSCAPA;
701 static int mdt_getattr(struct mdt_thread_info *info)
703 struct ptlrpc_request *req = mdt_info_req(info);
704 struct mdt_object *obj = info->mti_object;
705 struct req_capsule *pill = info->mti_pill;
706 struct mdt_body *reqbody;
707 struct mdt_body *repbody;
713 reqbody = req_capsule_client_get(pill, &RMF_MDT_BODY);
716 if (reqbody->valid & OBD_MD_FLOSSCAPA) {
717 rc = req_capsule_server_pack(pill);
719 RETURN(err_serious(rc));
720 rc = mdt_renew_capa(info);
721 GOTO(out_shrink, rc);
724 LASSERT(obj != NULL);
725 LASSERT(lu_object_assert_exists(&obj->mot_obj.mo_lu));
727 mode = lu_object_attr(&obj->mot_obj.mo_lu);
728 if (S_ISLNK(mode) && (reqbody->valid & OBD_MD_LINKNAME) &&
729 (reqbody->eadatasize > info->mti_mdt->mdt_max_mdsize))
730 md_size = reqbody->eadatasize;
732 md_size = info->mti_mdt->mdt_max_mdsize;
734 req_capsule_set_size(pill, &RMF_MDT_MD, RCL_SERVER, md_size);
736 rc = req_capsule_server_pack(pill);
737 if (unlikely(rc != 0))
738 RETURN(err_serious(rc));
740 repbody = req_capsule_server_get(pill, &RMF_MDT_BODY);
741 LASSERT(repbody != NULL);
742 repbody->eadatasize = 0;
743 repbody->aclsize = 0;
745 if (reqbody->valid & OBD_MD_FLRMTPERM)
746 rc = mdt_init_ucred(info, reqbody);
748 rc = mdt_check_ucred(info);
750 GOTO(out_shrink, rc);
752 info->mti_spec.sp_ck_split = !!(reqbody->valid & OBD_MD_FLCKSPLIT);
753 info->mti_cross_ref = !!(reqbody->valid & OBD_MD_FLCROSSREF);
756 * Don't check capability at all, because rename might getattr for
757 * remote obj, and at that time no capability is available.
759 mdt_set_capainfo(info, 1, &reqbody->fid1, BYPASS_CAPA);
760 rc = mdt_getattr_internal(info, obj, 0);
761 if (reqbody->valid & OBD_MD_FLRMTPERM)
762 mdt_exit_ucred(info);
766 mdt_counter_incr(req->rq_export, LPROC_MDT_GETATTR);
768 mdt_client_compatibility(info);
769 mdt_shrink_reply(info);
773 static int mdt_is_subdir(struct mdt_thread_info *info)
775 struct mdt_object *o = info->mti_object;
776 struct req_capsule *pill = info->mti_pill;
777 const struct mdt_body *body = info->mti_body;
778 struct mdt_body *repbody;
784 repbody = req_capsule_server_get(pill, &RMF_MDT_BODY);
787 * We save last checked parent fid to @repbody->fid1 for remote
790 LASSERT(fid_is_sane(&body->fid2));
791 LASSERT(mdt_object_exists(o) > 0);
792 rc = mdo_is_subdir(info->mti_env, mdt_object_child(o),
793 &body->fid2, &repbody->fid1);
794 if (rc == 0 || rc == -EREMOTE)
795 repbody->valid |= OBD_MD_FLID;
800 static int mdt_raw_lookup(struct mdt_thread_info *info,
801 struct mdt_object *parent,
802 const struct lu_name *lname,
803 struct ldlm_reply *ldlm_rep)
805 struct md_object *next = mdt_object_child(info->mti_object);
806 const struct mdt_body *reqbody = info->mti_body;
807 struct lu_fid *child_fid = &info->mti_tmp_fid1;
808 struct mdt_body *repbody;
812 if (reqbody->valid != OBD_MD_FLID)
815 LASSERT(!info->mti_cross_ref);
817 /* Only got the fid of this obj by name */
819 rc = mdo_lookup(info->mti_env, next, lname, child_fid,
822 /* XXX is raw_lookup possible as intent operation? */
825 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_NEG);
828 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_POS);
830 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
833 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
834 repbody->fid1 = *child_fid;
835 repbody->valid = OBD_MD_FLID;
841 * UPDATE lock should be taken against parent, and be release before exit;
842 * child_bits lock should be taken against child, and be returned back:
843 * (1)normal request should release the child lock;
844 * (2)intent request will grant the lock to client.
846 static int mdt_getattr_name_lock(struct mdt_thread_info *info,
847 struct mdt_lock_handle *lhc,
849 struct ldlm_reply *ldlm_rep)
851 struct ptlrpc_request *req = mdt_info_req(info);
852 struct mdt_body *reqbody = NULL;
853 struct mdt_object *parent = info->mti_object;
854 struct mdt_object *child;
855 struct md_object *next = mdt_object_child(parent);
856 struct lu_fid *child_fid = &info->mti_tmp_fid1;
857 struct lu_name *lname = NULL;
858 const char *name = NULL;
860 struct mdt_lock_handle *lhp = NULL;
861 struct ldlm_lock *lock;
862 struct ldlm_res_id *res_id;
869 is_resent = lustre_handle_is_used(&lhc->mlh_reg_lh);
870 LASSERT(ergo(is_resent,
871 lustre_msg_get_flags(req->rq_reqmsg) & MSG_RESENT));
873 LASSERT(parent != NULL);
874 name = req_capsule_client_get(info->mti_pill, &RMF_NAME);
876 RETURN(err_serious(-EFAULT));
878 namelen = req_capsule_get_size(info->mti_pill, &RMF_NAME,
880 if (!info->mti_cross_ref) {
882 * XXX: Check for "namelen == 0" is for getattr by fid
883 * (OBD_CONNECT_ATTRFID), otherwise do not allow empty name,
884 * that is the name must contain at least one character and
885 * the terminating '\0'
888 reqbody = req_capsule_client_get(info->mti_pill,
890 if (unlikely(reqbody == NULL))
891 RETURN(err_serious(-EFAULT));
893 if (unlikely(!fid_is_sane(&reqbody->fid2)))
894 RETURN(err_serious(-EINVAL));
897 CDEBUG(D_INODE, "getattr with lock for "DFID"/"DFID", "
899 PFID(mdt_object_fid(parent)),
900 PFID(&reqbody->fid2), ldlm_rep);
902 lname = mdt_name(info->mti_env, (char *)name, namelen);
903 CDEBUG(D_INODE, "getattr with lock for "DFID"/%s, "
904 "ldlm_rep = %p\n", PFID(mdt_object_fid(parent)),
908 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_EXECD);
910 rc = mdt_object_exists(parent);
911 if (unlikely(rc == 0)) {
912 LU_OBJECT_DEBUG(D_WARNING, info->mti_env,
913 &parent->mot_obj.mo_lu,
914 "Parent doesn't exist!\n");
916 } else if (!info->mti_cross_ref) {
917 LASSERTF(rc > 0, "Parent "DFID" is on remote server\n",
918 PFID(mdt_object_fid(parent)));
921 rc = mdt_raw_lookup(info, parent, lname, ldlm_rep);
929 if (info->mti_cross_ref) {
930 /* Only getattr on the child. Parent is on another node. */
931 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_POS);
933 CDEBUG(D_INODE, "partial getattr_name child_fid = "DFID", "
934 "ldlm_rep=%p\n", PFID(mdt_object_fid(child)), ldlm_rep);
937 /* Do not take lock for resent case. */
938 lock = ldlm_handle2lock(&lhc->mlh_reg_lh);
939 LASSERTF(lock != NULL, "Invalid lock handle "LPX64"\n",
940 lhc->mlh_reg_lh.cookie);
941 LASSERT(fid_res_name_eq(mdt_object_fid(child),
942 &lock->l_resource->lr_name));
946 mdt_lock_handle_init(lhc);
947 mdt_lock_reg_init(lhc, LCK_PR);
950 * Object's name is on another MDS, no lookup lock is
951 * needed here but update is.
953 child_bits &= ~MDS_INODELOCK_LOOKUP;
954 child_bits |= MDS_INODELOCK_UPDATE;
956 rc = mdt_object_lock(info, child, lhc, child_bits,
960 /* Finally, we can get attr for child. */
961 mdt_set_capainfo(info, 0, mdt_object_fid(child),
963 rc = mdt_getattr_internal(info, child, 0);
964 if (unlikely(rc != 0))
965 mdt_object_unlock(info, child, lhc, 1);
971 /* step 1: lock parent only if parent is a directory */
972 if (S_ISDIR(lu_object_attr(&parent->mot_obj.mo_lu))) {
973 lhp = &info->mti_lh[MDT_LH_PARENT];
974 mdt_lock_pdo_init(lhp, LCK_PR, name, namelen);
975 rc = mdt_object_lock(info, parent, lhp,
976 MDS_INODELOCK_UPDATE,
978 if (unlikely(rc != 0))
982 /* step 2: lookup child's fid by name */
984 rc = mdo_lookup(info->mti_env, next, lname, child_fid,
989 mdt_set_disposition(info, ldlm_rep,
991 GOTO(out_parent, rc);
993 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_POS);
995 *child_fid = reqbody->fid2;
996 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_POS);
1000 *step 3: find the child object by fid & lock it.
1001 * regardless if it is local or remote.
1003 child = mdt_object_find(info->mti_env, info->mti_mdt, child_fid);
1005 if (unlikely(IS_ERR(child)))
1006 GOTO(out_parent, rc = PTR_ERR(child));
1008 /* Do not take lock for resent case. */
1009 lock = ldlm_handle2lock(&lhc->mlh_reg_lh);
1010 LASSERTF(lock != NULL, "Invalid lock handle "LPX64"\n",
1011 lhc->mlh_reg_lh.cookie);
1013 res_id = &lock->l_resource->lr_name;
1014 if (!fid_res_name_eq(mdt_object_fid(child),
1015 &lock->l_resource->lr_name)) {
1016 LASSERTF(fid_res_name_eq(mdt_object_fid(parent),
1017 &lock->l_resource->lr_name),
1018 "Lock res_id: %lu/%lu/%lu, Fid: "DFID".\n",
1019 (unsigned long)res_id->name[0],
1020 (unsigned long)res_id->name[1],
1021 (unsigned long)res_id->name[2],
1022 PFID(mdt_object_fid(parent)));
1023 CWARN("Although resent, but still not get child lock"
1024 "parent:"DFID" child:"DFID"\n",
1025 PFID(mdt_object_fid(parent)),
1026 PFID(mdt_object_fid(child)));
1027 lustre_msg_clear_flags(req->rq_reqmsg, MSG_RESENT);
1028 LDLM_LOCK_PUT(lock);
1031 LDLM_LOCK_PUT(lock);
1035 OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_RESEND, obd_timeout*2);
1036 mdt_lock_handle_init(lhc);
1037 if (child_bits == MDS_INODELOCK_LAYOUT)
1038 mdt_lock_reg_init(lhc, LCK_CR);
1040 mdt_lock_reg_init(lhc, LCK_PR);
1042 if (mdt_object_exists(child) == 0) {
1043 LU_OBJECT_DEBUG(D_INODE, info->mti_env,
1044 &child->mot_obj.mo_lu,
1045 "Object doesn't exist!\n");
1046 GOTO(out_child, rc = -ENOENT);
1049 if (!(child_bits & MDS_INODELOCK_UPDATE)) {
1050 struct md_attr *ma = &info->mti_attr;
1053 ma->ma_need = MA_INODE;
1054 rc = mo_attr_get(info->mti_env,
1055 mdt_object_child(child), ma);
1056 if (unlikely(rc != 0))
1057 GOTO(out_child, rc);
1059 /* layout lock is used only on regular files */
1060 if ((ma->ma_valid & MA_INODE) &&
1061 (ma->ma_attr.la_valid & LA_MODE) &&
1062 !S_ISREG(ma->ma_attr.la_mode))
1063 child_bits &= ~MDS_INODELOCK_LAYOUT;
1065 /* If the file has not been changed for some time, we
1066 * return not only a LOOKUP lock, but also an UPDATE
1067 * lock and this might save us RPC on later STAT. For
1068 * directories, it also let negative dentry starts
1069 * working for this dir. */
1070 if (ma->ma_valid & MA_INODE &&
1071 ma->ma_attr.la_valid & LA_CTIME &&
1072 info->mti_mdt->mdt_namespace->ns_ctime_age_limit +
1073 ma->ma_attr.la_ctime < cfs_time_current_sec())
1074 child_bits |= MDS_INODELOCK_UPDATE;
1077 rc = mdt_object_lock(info, child, lhc, child_bits,
1080 if (unlikely(rc != 0))
1081 GOTO(out_child, rc);
1084 lock = ldlm_handle2lock(&lhc->mlh_reg_lh);
1085 /* Get MA_SOM attributes if update lock is given. */
1087 lock->l_policy_data.l_inodebits.bits & MDS_INODELOCK_UPDATE &&
1088 S_ISREG(lu_object_attr(&mdt_object_child(child)->mo_lu)))
1091 /* finally, we can get attr for child. */
1092 mdt_set_capainfo(info, 1, child_fid, BYPASS_CAPA);
1093 rc = mdt_getattr_internal(info, child, ma_need);
1094 if (unlikely(rc != 0)) {
1095 mdt_object_unlock(info, child, lhc, 1);
1097 /* Debugging code. */
1098 res_id = &lock->l_resource->lr_name;
1099 LDLM_DEBUG(lock, "Returning lock to client");
1100 LASSERTF(fid_res_name_eq(mdt_object_fid(child),
1101 &lock->l_resource->lr_name),
1102 "Lock res_id: %lu/%lu/%lu, Fid: "DFID".\n",
1103 (unsigned long)res_id->name[0],
1104 (unsigned long)res_id->name[1],
1105 (unsigned long)res_id->name[2],
1106 PFID(mdt_object_fid(child)));
1107 mdt_pack_size2body(info, child);
1110 LDLM_LOCK_PUT(lock);
1114 mdt_object_put(info->mti_env, child);
1117 mdt_object_unlock(info, parent, lhp, 1);
1121 /* normal handler: should release the child lock */
1122 static int mdt_getattr_name(struct mdt_thread_info *info)
1124 struct mdt_lock_handle *lhc = &info->mti_lh[MDT_LH_CHILD];
1125 struct mdt_body *reqbody;
1126 struct mdt_body *repbody;
1130 reqbody = req_capsule_client_get(info->mti_pill, &RMF_MDT_BODY);
1131 LASSERT(reqbody != NULL);
1132 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
1133 LASSERT(repbody != NULL);
1135 info->mti_spec.sp_ck_split = !!(reqbody->valid & OBD_MD_FLCKSPLIT);
1136 info->mti_cross_ref = !!(reqbody->valid & OBD_MD_FLCROSSREF);
1137 repbody->eadatasize = 0;
1138 repbody->aclsize = 0;
1140 rc = mdt_init_ucred(info, reqbody);
1142 GOTO(out_shrink, rc);
1144 rc = mdt_getattr_name_lock(info, lhc, MDS_INODELOCK_UPDATE, NULL);
1145 if (lustre_handle_is_used(&lhc->mlh_reg_lh)) {
1146 ldlm_lock_decref(&lhc->mlh_reg_lh, lhc->mlh_reg_mode);
1147 lhc->mlh_reg_lh.cookie = 0;
1149 mdt_exit_ucred(info);
1152 mdt_client_compatibility(info);
1153 mdt_shrink_reply(info);
1157 static const struct lu_device_operations mdt_lu_ops;
1159 static int lu_device_is_mdt(struct lu_device *d)
1161 return ergo(d != NULL && d->ld_ops != NULL, d->ld_ops == &mdt_lu_ops);
1164 static int mdt_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
1165 void *karg, void *uarg);
1167 static int mdt_set_info(struct mdt_thread_info *info)
1169 struct ptlrpc_request *req = mdt_info_req(info);
1172 int keylen, vallen, rc = 0;
1175 rc = req_capsule_server_pack(info->mti_pill);
1179 key = req_capsule_client_get(info->mti_pill, &RMF_SETINFO_KEY);
1181 DEBUG_REQ(D_HA, req, "no set_info key");
1185 keylen = req_capsule_get_size(info->mti_pill, &RMF_SETINFO_KEY,
1188 val = req_capsule_client_get(info->mti_pill, &RMF_SETINFO_VAL);
1190 DEBUG_REQ(D_HA, req, "no set_info val");
1194 vallen = req_capsule_get_size(info->mti_pill, &RMF_SETINFO_VAL,
1197 /* Swab any part of val you need to here */
1198 if (KEY_IS(KEY_READ_ONLY)) {
1200 lustre_msg_set_status(req->rq_repmsg, 0);
1202 cfs_spin_lock(&req->rq_export->exp_lock);
1204 req->rq_export->exp_connect_flags |= OBD_CONNECT_RDONLY;
1206 req->rq_export->exp_connect_flags &=~OBD_CONNECT_RDONLY;
1207 cfs_spin_unlock(&req->rq_export->exp_lock);
1209 } else if (KEY_IS(KEY_CHANGELOG_CLEAR)) {
1210 struct changelog_setinfo *cs =
1211 (struct changelog_setinfo *)val;
1212 if (vallen != sizeof(*cs)) {
1213 CERROR("Bad changelog_clear setinfo size %d\n", vallen);
1216 if (ptlrpc_req_need_swab(req)) {
1217 __swab64s(&cs->cs_recno);
1218 __swab32s(&cs->cs_id);
1221 rc = mdt_iocontrol(OBD_IOC_CHANGELOG_CLEAR, info->mti_exp,
1223 lustre_msg_set_status(req->rq_repmsg, rc);
1231 static int mdt_connect(struct mdt_thread_info *info)
1234 struct ptlrpc_request *req;
1236 req = mdt_info_req(info);
1237 rc = target_handle_connect(req);
1239 LASSERT(req->rq_export != NULL);
1240 info->mti_mdt = mdt_dev(req->rq_export->exp_obd->obd_lu_dev);
1241 rc = mdt_init_sec_level(info);
1243 rc = mdt_init_idmap(info);
1245 obd_disconnect(class_export_get(req->rq_export));
1247 rc = err_serious(rc);
1252 static int mdt_disconnect(struct mdt_thread_info *info)
1257 rc = target_handle_disconnect(mdt_info_req(info));
1259 rc = err_serious(rc);
1263 static int mdt_sendpage(struct mdt_thread_info *info,
1264 struct lu_rdpg *rdpg, int nob)
1266 struct ptlrpc_request *req = mdt_info_req(info);
1267 struct obd_export *exp = req->rq_export;
1268 struct ptlrpc_bulk_desc *desc;
1269 struct l_wait_info *lwi = &info->mti_u.rdpg.mti_wait_info;
1276 desc = ptlrpc_prep_bulk_exp(req, rdpg->rp_npages, BULK_PUT_SOURCE,
1281 for (i = 0, tmpcount = nob;
1282 i < rdpg->rp_npages && tmpcount > 0; i++, tmpcount -= tmpsize) {
1283 tmpsize = min_t(int, tmpcount, CFS_PAGE_SIZE);
1284 ptlrpc_prep_bulk_page(desc, rdpg->rp_pages[i], 0, tmpsize);
1287 LASSERT(desc->bd_nob == nob);
1288 rc = target_bulk_io(exp, desc, lwi);
1289 ptlrpc_free_bulk(desc);
1293 #ifdef HAVE_SPLIT_SUPPORT
1295 * Retrieve dir entry from the page and insert it to the slave object, actually,
1296 * this should be in osd layer, but since it will not in the final product, so
1297 * just do it here and do not define more moo api anymore for this.
1299 static int mdt_write_dir_page(struct mdt_thread_info *info, struct page *page,
1302 struct mdt_object *object = info->mti_object;
1303 struct lu_fid *lf = &info->mti_tmp_fid2;
1304 struct md_attr *ma = &info->mti_attr;
1305 struct lu_dirpage *dp;
1306 struct lu_dirent *ent;
1307 int rc = 0, offset = 0;
1310 /* Make sure we have at least one entry. */
1315 * Disable trans for this name insert, since it will include many trans
1318 info->mti_no_need_trans = 1;
1320 * When write_dir_page, no need update parent's ctime,
1321 * and no permission check for name_insert.
1323 ma->ma_attr.la_ctime = 0;
1324 ma->ma_attr.la_valid = LA_MODE;
1325 ma->ma_valid = MA_INODE;
1328 dp = page_address(page);
1329 offset = (int)((__u32)lu_dirent_start(dp) - (__u32)dp);
1331 for (ent = lu_dirent_start(dp); ent != NULL;
1332 ent = lu_dirent_next(ent)) {
1333 struct lu_name *lname;
1336 if (le16_to_cpu(ent->lde_namelen) == 0)
1339 fid_le_to_cpu(lf, &ent->lde_fid);
1340 if (le64_to_cpu(ent->lde_hash) & MAX_HASH_HIGHEST_BIT)
1341 ma->ma_attr.la_mode = S_IFDIR;
1343 ma->ma_attr.la_mode = 0;
1344 OBD_ALLOC(name, le16_to_cpu(ent->lde_namelen) + 1);
1346 GOTO(out, rc = -ENOMEM);
1348 memcpy(name, ent->lde_name, le16_to_cpu(ent->lde_namelen));
1349 lname = mdt_name(info->mti_env, name,
1350 le16_to_cpu(ent->lde_namelen));
1351 ma->ma_attr_flags |= (MDS_PERM_BYPASS | MDS_QUOTA_IGNORE);
1352 rc = mdo_name_insert(info->mti_env,
1353 md_object_next(&object->mot_obj),
1355 OBD_FREE(name, le16_to_cpu(ent->lde_namelen) + 1);
1357 CERROR("Can't insert %*.*s, rc %d\n",
1358 le16_to_cpu(ent->lde_namelen),
1359 le16_to_cpu(ent->lde_namelen),
1364 offset += lu_dirent_size(ent);
1374 static int mdt_bulk_timeout(void *data)
1378 CERROR("mdt bulk transfer timeout \n");
1383 static int mdt_writepage(struct mdt_thread_info *info)
1385 struct ptlrpc_request *req = mdt_info_req(info);
1386 struct mdt_body *reqbody;
1387 struct l_wait_info *lwi;
1388 struct ptlrpc_bulk_desc *desc;
1394 reqbody = req_capsule_client_get(info->mti_pill, &RMF_MDT_BODY);
1395 if (reqbody == NULL)
1396 RETURN(err_serious(-EFAULT));
1398 desc = ptlrpc_prep_bulk_exp(req, 1, BULK_GET_SINK, MDS_BULK_PORTAL);
1400 RETURN(err_serious(-ENOMEM));
1402 /* allocate the page for the desc */
1403 page = cfs_alloc_page(CFS_ALLOC_STD);
1405 GOTO(desc_cleanup, rc = -ENOMEM);
1407 CDEBUG(D_INFO, "Received page offset %d size %d \n",
1408 (int)reqbody->size, (int)reqbody->nlink);
1410 ptlrpc_prep_bulk_page(desc, page, (int)reqbody->size,
1411 (int)reqbody->nlink);
1413 rc = sptlrpc_svc_prep_bulk(req, desc);
1415 GOTO(cleanup_page, rc);
1417 * Check if client was evicted while we were doing i/o before touching
1422 GOTO(cleanup_page, rc = -ENOMEM);
1424 if (desc->bd_export->exp_failed)
1427 rc = ptlrpc_start_bulk_transfer (desc);
1429 *lwi = LWI_TIMEOUT_INTERVAL(obd_timeout * CFS_HZ / 4, CFS_HZ,
1430 mdt_bulk_timeout, desc);
1431 rc = l_wait_event(desc->bd_waitq, !ptlrpc_bulk_active(desc) ||
1432 desc->bd_export->exp_failed, lwi);
1433 LASSERT(rc == 0 || rc == -ETIMEDOUT);
1434 if (rc == -ETIMEDOUT) {
1435 DEBUG_REQ(D_ERROR, req, "timeout on bulk GET");
1436 ptlrpc_abort_bulk(desc);
1437 } else if (desc->bd_export->exp_failed) {
1438 DEBUG_REQ(D_ERROR, req, "Eviction on bulk GET");
1440 ptlrpc_abort_bulk(desc);
1441 } else if (!desc->bd_success ||
1442 desc->bd_nob_transferred != desc->bd_nob) {
1443 DEBUG_REQ(D_ERROR, req, "%s bulk GET %d(%d)",
1445 "truncated" : "network error on",
1446 desc->bd_nob_transferred, desc->bd_nob);
1447 /* XXX should this be a different errno? */
1451 DEBUG_REQ(D_ERROR, req, "ptlrpc_bulk_get failed: rc %d", rc);
1454 GOTO(cleanup_lwi, rc);
1455 rc = mdt_write_dir_page(info, page, reqbody->nlink);
1460 cfs_free_page(page);
1462 ptlrpc_free_bulk(desc);
1467 static int mdt_readpage(struct mdt_thread_info *info)
1469 struct mdt_object *object = info->mti_object;
1470 struct lu_rdpg *rdpg = &info->mti_u.rdpg.mti_rdpg;
1471 struct mdt_body *reqbody;
1472 struct mdt_body *repbody;
1477 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_READPAGE_PACK))
1478 RETURN(err_serious(-ENOMEM));
1480 reqbody = req_capsule_client_get(info->mti_pill, &RMF_MDT_BODY);
1481 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
1482 if (reqbody == NULL || repbody == NULL)
1483 RETURN(err_serious(-EFAULT));
1486 * prepare @rdpg before calling lower layers and transfer itself. Here
1487 * reqbody->size contains offset of where to start to read and
1488 * reqbody->nlink contains number bytes to read.
1490 rdpg->rp_hash = reqbody->size;
1491 if (rdpg->rp_hash != reqbody->size) {
1492 CERROR("Invalid hash: "LPX64" != "LPX64"\n",
1493 rdpg->rp_hash, reqbody->size);
1497 rdpg->rp_attrs = reqbody->mode;
1498 if (info->mti_exp->exp_connect_flags & OBD_CONNECT_64BITHASH)
1499 rdpg->rp_attrs |= LUDA_64BITHASH;
1500 rdpg->rp_count = min_t(unsigned int, reqbody->nlink,
1501 PTLRPC_MAX_BRW_SIZE);
1502 rdpg->rp_npages = (rdpg->rp_count + CFS_PAGE_SIZE - 1) >>
1504 OBD_ALLOC(rdpg->rp_pages, rdpg->rp_npages * sizeof rdpg->rp_pages[0]);
1505 if (rdpg->rp_pages == NULL)
1508 for (i = 0; i < rdpg->rp_npages; ++i) {
1509 rdpg->rp_pages[i] = cfs_alloc_page(CFS_ALLOC_STD);
1510 if (rdpg->rp_pages[i] == NULL)
1511 GOTO(free_rdpg, rc = -ENOMEM);
1514 /* call lower layers to fill allocated pages with directory data */
1515 rc = mo_readpage(info->mti_env, mdt_object_child(object), rdpg);
1517 GOTO(free_rdpg, rc);
1519 /* send pages to client */
1520 rc = mdt_sendpage(info, rdpg, rc);
1525 for (i = 0; i < rdpg->rp_npages; i++)
1526 if (rdpg->rp_pages[i] != NULL)
1527 cfs_free_page(rdpg->rp_pages[i]);
1528 OBD_FREE(rdpg->rp_pages, rdpg->rp_npages * sizeof rdpg->rp_pages[0]);
1530 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_SENDPAGE))
1536 static int mdt_reint_internal(struct mdt_thread_info *info,
1537 struct mdt_lock_handle *lhc,
1540 struct req_capsule *pill = info->mti_pill;
1541 struct mdt_device *mdt = info->mti_mdt;
1542 struct md_quota *mq = md_quota(info->mti_env);
1543 struct mdt_body *repbody;
1548 if (req_capsule_has_field(pill, &RMF_MDT_MD, RCL_SERVER))
1549 req_capsule_set_size(pill, &RMF_MDT_MD, RCL_SERVER,
1550 mdt->mdt_max_mdsize);
1551 if (req_capsule_has_field(pill, &RMF_LOGCOOKIES, RCL_SERVER))
1552 req_capsule_set_size(pill, &RMF_LOGCOOKIES, RCL_SERVER,
1553 mdt->mdt_max_cookiesize);
1555 rc = req_capsule_server_pack(pill);
1557 CERROR("Can't pack response, rc %d\n", rc);
1558 RETURN(err_serious(rc));
1561 if (req_capsule_has_field(pill, &RMF_MDT_BODY, RCL_SERVER)) {
1562 repbody = req_capsule_server_get(pill, &RMF_MDT_BODY);
1564 repbody->eadatasize = 0;
1565 repbody->aclsize = 0;
1568 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_REINT_UNPACK))
1569 GOTO(out_shrink, rc = err_serious(-EFAULT));
1571 rc = mdt_reint_unpack(info, op);
1573 CERROR("Can't unpack reint, rc %d\n", rc);
1574 GOTO(out_shrink, rc = err_serious(rc));
1577 OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_REINT_DELAY, 10);
1579 /* for replay no cookkie / lmm need, because client have this already */
1580 if (info->mti_spec.no_create == 1) {
1581 if (req_capsule_has_field(pill, &RMF_MDT_MD, RCL_SERVER))
1582 req_capsule_set_size(pill, &RMF_MDT_MD, RCL_SERVER, 0);
1584 if (req_capsule_has_field(pill, &RMF_LOGCOOKIES, RCL_SERVER))
1585 req_capsule_set_size(pill, &RMF_LOGCOOKIES, RCL_SERVER,
1589 rc = mdt_init_ucred_reint(info);
1591 GOTO(out_shrink, rc);
1593 rc = mdt_fix_attr_ucred(info, op);
1595 GOTO(out_ucred, rc = err_serious(rc));
1597 if (mdt_check_resent(info, mdt_reconstruct, lhc)) {
1598 rc = lustre_msg_get_status(mdt_info_req(info)->rq_repmsg);
1599 GOTO(out_ucred, rc);
1601 mq->mq_exp = info->mti_exp;
1602 rc = mdt_reint_rec(info, lhc);
1605 mdt_exit_ucred(info);
1607 mdt_client_compatibility(info);
1608 mdt_shrink_reply(info);
1612 static long mdt_reint_opcode(struct mdt_thread_info *info,
1613 const struct req_format **fmt)
1615 struct mdt_rec_reint *rec;
1618 opc = err_serious(-EFAULT);
1619 rec = req_capsule_client_get(info->mti_pill, &RMF_REC_REINT);
1621 opc = rec->rr_opcode;
1622 DEBUG_REQ(D_INODE, mdt_info_req(info), "reint opt = %ld", opc);
1623 if (opc < REINT_MAX && fmt[opc] != NULL)
1624 req_capsule_extend(info->mti_pill, fmt[opc]);
1626 CERROR("Unsupported opc: %ld\n", opc);
1627 opc = err_serious(opc);
1633 static int mdt_reint(struct mdt_thread_info *info)
1638 static const struct req_format *reint_fmts[REINT_MAX] = {
1639 [REINT_SETATTR] = &RQF_MDS_REINT_SETATTR,
1640 [REINT_CREATE] = &RQF_MDS_REINT_CREATE,
1641 [REINT_LINK] = &RQF_MDS_REINT_LINK,
1642 [REINT_UNLINK] = &RQF_MDS_REINT_UNLINK,
1643 [REINT_RENAME] = &RQF_MDS_REINT_RENAME,
1644 [REINT_OPEN] = &RQF_MDS_REINT_OPEN,
1645 [REINT_SETXATTR] = &RQF_MDS_REINT_SETXATTR
1650 opc = mdt_reint_opcode(info, reint_fmts);
1653 * No lock possible here from client to pass it to reint code
1656 rc = mdt_reint_internal(info, NULL, opc);
1661 info->mti_fail_id = OBD_FAIL_MDS_REINT_NET_REP;
1665 /* this should sync the whole device */
1666 static int mdt_device_sync(const struct lu_env *env, struct mdt_device *mdt)
1668 struct dt_device *dt = mdt->mdt_bottom;
1672 rc = dt->dd_ops->dt_sync(env, dt);
1676 /* this should sync this object */
1677 static int mdt_object_sync(struct mdt_thread_info *info)
1679 struct md_object *next;
1683 if (!mdt_object_exists(info->mti_object)) {
1684 CWARN("Non existing object "DFID"!\n",
1685 PFID(mdt_object_fid(info->mti_object)));
1688 next = mdt_object_child(info->mti_object);
1689 rc = mo_object_sync(info->mti_env, next);
1694 static int mdt_sync(struct mdt_thread_info *info)
1696 struct ptlrpc_request *req = mdt_info_req(info);
1697 struct req_capsule *pill = info->mti_pill;
1698 struct mdt_body *body;
1702 /* The fid may be zero, so we req_capsule_set manually */
1703 req_capsule_set(pill, &RQF_MDS_SYNC);
1705 body = req_capsule_client_get(pill, &RMF_MDT_BODY);
1707 RETURN(err_serious(-EINVAL));
1709 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_SYNC_PACK))
1710 RETURN(err_serious(-ENOMEM));
1712 if (fid_seq(&body->fid1) == 0) {
1713 /* sync the whole device */
1714 rc = req_capsule_server_pack(pill);
1716 rc = mdt_device_sync(info->mti_env, info->mti_mdt);
1718 rc = err_serious(rc);
1720 /* sync an object */
1721 rc = mdt_unpack_req_pack_rep(info, HABEO_CORPUS|HABEO_REFERO);
1723 rc = mdt_object_sync(info);
1725 struct md_object *next;
1726 const struct lu_fid *fid;
1727 struct lu_attr *la = &info->mti_attr.ma_attr;
1729 next = mdt_object_child(info->mti_object);
1730 info->mti_attr.ma_need = MA_INODE;
1731 info->mti_attr.ma_valid = 0;
1732 rc = mo_attr_get(info->mti_env, next,
1735 body = req_capsule_server_get(pill,
1737 fid = mdt_object_fid(info->mti_object);
1738 mdt_pack_attr2body(info, body, la, fid);
1742 rc = err_serious(rc);
1745 mdt_counter_incr(req->rq_export, LPROC_MDT_SYNC);
1750 #ifdef HAVE_QUOTA_SUPPORT
1751 static int mdt_quotacheck_handle(struct mdt_thread_info *info)
1753 struct obd_quotactl *oqctl;
1754 struct req_capsule *pill = info->mti_pill;
1755 struct obd_export *exp = info->mti_exp;
1756 struct md_quota *mq = md_quota(info->mti_env);
1757 struct md_device *next = info->mti_mdt->mdt_child;
1761 oqctl = req_capsule_client_get(pill, &RMF_OBD_QUOTACTL);
1765 /* remote client has no permission for quotacheck */
1766 if (unlikely(exp_connect_rmtclient(exp)))
1769 rc = req_capsule_server_pack(pill);
1774 rc = next->md_ops->mdo_quota.mqo_check(info->mti_env, next,
1779 static int mdt_quotactl_handle(struct mdt_thread_info *info)
1781 struct obd_quotactl *oqctl, *repoqc;
1782 struct req_capsule *pill = info->mti_pill;
1783 struct obd_export *exp = info->mti_exp;
1784 struct md_quota *mq = md_quota(info->mti_env);
1785 struct md_device *next = info->mti_mdt->mdt_child;
1786 const struct md_quota_operations *mqo = &next->md_ops->mdo_quota;
1790 oqctl = req_capsule_client_get(pill, &RMF_OBD_QUOTACTL);
1795 if (exp_connect_rmtclient(exp)) {
1796 struct ptlrpc_request *req = mdt_info_req(info);
1797 struct mdt_export_data *med = mdt_req2med(req);
1798 struct lustre_idmap_table *idmap = med->med_idmap;
1800 if (unlikely(oqctl->qc_cmd != Q_GETQUOTA &&
1801 oqctl->qc_cmd != Q_GETINFO))
1805 if (oqctl->qc_type == USRQUOTA)
1806 id = lustre_idmap_lookup_uid(NULL, idmap, 0,
1808 else if (oqctl->qc_type == GRPQUOTA)
1809 id = lustre_idmap_lookup_gid(NULL, idmap, 0,
1814 if (id == CFS_IDMAP_NOTFOUND) {
1815 CDEBUG(D_QUOTA, "no mapping for id %u\n",
1821 rc = req_capsule_server_pack(pill);
1825 repoqc = req_capsule_server_get(pill, &RMF_OBD_QUOTACTL);
1826 LASSERT(repoqc != NULL);
1829 switch (oqctl->qc_cmd) {
1831 rc = mqo->mqo_on(info->mti_env, next, oqctl->qc_type);
1834 rc = mqo->mqo_off(info->mti_env, next, oqctl->qc_type);
1837 rc = mqo->mqo_setinfo(info->mti_env, next, oqctl->qc_type, id,
1841 rc = mqo->mqo_getinfo(info->mti_env, next, oqctl->qc_type, id,
1845 rc = mqo->mqo_setquota(info->mti_env, next, oqctl->qc_type, id,
1849 rc = mqo->mqo_getquota(info->mti_env, next, oqctl->qc_type, id,
1853 rc = mqo->mqo_getoinfo(info->mti_env, next, oqctl->qc_type, id,
1857 rc = mqo->mqo_getoquota(info->mti_env, next, oqctl->qc_type, id,
1860 case LUSTRE_Q_INVALIDATE:
1861 rc = mqo->mqo_invalidate(info->mti_env, next, oqctl->qc_type);
1863 case LUSTRE_Q_FINVALIDATE:
1864 rc = mqo->mqo_finvalidate(info->mti_env, next, oqctl->qc_type);
1867 CERROR("unsupported mdt_quotactl command: %d\n",
1879 * OBD PING and other handlers.
1881 static int mdt_obd_ping(struct mdt_thread_info *info)
1886 req_capsule_set(info->mti_pill, &RQF_OBD_PING);
1888 rc = target_handle_ping(mdt_info_req(info));
1890 rc = err_serious(rc);
1894 static int mdt_obd_log_cancel(struct mdt_thread_info *info)
1896 return err_serious(-EOPNOTSUPP);
1899 static int mdt_obd_qc_callback(struct mdt_thread_info *info)
1901 return err_serious(-EOPNOTSUPP);
1909 /** clone llog ctxt from child (mdd)
1910 * This allows remote llog (replicator) access.
1911 * We can either pass all llog RPCs (eg mdt_llog_create) on to child where the
1912 * context was originally set up, or we can handle them directly.
1913 * I choose the latter, but that means I need any llog
1914 * contexts set up by child to be accessable by the mdt. So we clone the
1915 * context into our context list here.
1917 static int mdt_llog_ctxt_clone(const struct lu_env *env, struct mdt_device *mdt,
1920 struct md_device *next = mdt->mdt_child;
1921 struct llog_ctxt *ctxt;
1924 if (!llog_ctxt_null(mdt2obd_dev(mdt), idx))
1927 rc = next->md_ops->mdo_llog_ctxt_get(env, next, idx, (void **)&ctxt);
1928 if (rc || ctxt == NULL) {
1929 CERROR("Can't get mdd ctxt %d\n", rc);
1933 rc = llog_group_set_ctxt(&mdt2obd_dev(mdt)->obd_olg, ctxt, idx);
1935 CERROR("Can't set mdt ctxt %d\n", rc);
1940 static int mdt_llog_ctxt_unclone(const struct lu_env *env,
1941 struct mdt_device *mdt, int idx)
1943 struct llog_ctxt *ctxt;
1945 ctxt = llog_get_context(mdt2obd_dev(mdt), idx);
1948 /* Put once for the get we just did, and once for the clone */
1949 llog_ctxt_put(ctxt);
1950 llog_ctxt_put(ctxt);
1954 static int mdt_llog_create(struct mdt_thread_info *info)
1958 req_capsule_set(info->mti_pill, &RQF_LLOG_ORIGIN_HANDLE_CREATE);
1959 rc = llog_origin_handle_create(mdt_info_req(info));
1960 return (rc < 0 ? err_serious(rc) : rc);
1963 static int mdt_llog_destroy(struct mdt_thread_info *info)
1967 req_capsule_set(info->mti_pill, &RQF_LLOG_ORIGIN_HANDLE_DESTROY);
1968 rc = llog_origin_handle_destroy(mdt_info_req(info));
1969 return (rc < 0 ? err_serious(rc) : rc);
1972 static int mdt_llog_read_header(struct mdt_thread_info *info)
1976 req_capsule_set(info->mti_pill, &RQF_LLOG_ORIGIN_HANDLE_READ_HEADER);
1977 rc = llog_origin_handle_read_header(mdt_info_req(info));
1978 return (rc < 0 ? err_serious(rc) : rc);
1981 static int mdt_llog_next_block(struct mdt_thread_info *info)
1985 req_capsule_set(info->mti_pill, &RQF_LLOG_ORIGIN_HANDLE_NEXT_BLOCK);
1986 rc = llog_origin_handle_next_block(mdt_info_req(info));
1987 return (rc < 0 ? err_serious(rc) : rc);
1990 static int mdt_llog_prev_block(struct mdt_thread_info *info)
1994 req_capsule_set(info->mti_pill, &RQF_LLOG_ORIGIN_HANDLE_PREV_BLOCK);
1995 rc = llog_origin_handle_prev_block(mdt_info_req(info));
1996 return (rc < 0 ? err_serious(rc) : rc);
2003 static struct ldlm_callback_suite cbs = {
2004 .lcs_completion = ldlm_server_completion_ast,
2005 .lcs_blocking = ldlm_server_blocking_ast,
2009 static int mdt_enqueue(struct mdt_thread_info *info)
2011 struct ptlrpc_request *req;
2015 * info->mti_dlm_req already contains swapped and (if necessary)
2016 * converted dlm request.
2018 LASSERT(info->mti_dlm_req != NULL);
2020 req = mdt_info_req(info);
2021 rc = ldlm_handle_enqueue0(info->mti_mdt->mdt_namespace,
2022 req, info->mti_dlm_req, &cbs);
2023 info->mti_fail_id = OBD_FAIL_LDLM_REPLY;
2024 return rc ? err_serious(rc) : req->rq_status;
2027 static int mdt_convert(struct mdt_thread_info *info)
2030 struct ptlrpc_request *req;
2032 LASSERT(info->mti_dlm_req);
2033 req = mdt_info_req(info);
2034 rc = ldlm_handle_convert0(req, info->mti_dlm_req);
2035 return rc ? err_serious(rc) : req->rq_status;
2038 static int mdt_bl_callback(struct mdt_thread_info *info)
2040 CERROR("bl callbacks should not happen on MDS\n");
2042 return err_serious(-EOPNOTSUPP);
2045 static int mdt_cp_callback(struct mdt_thread_info *info)
2047 CERROR("cp callbacks should not happen on MDS\n");
2049 return err_serious(-EOPNOTSUPP);
2053 * sec context handlers
2055 static int mdt_sec_ctx_handle(struct mdt_thread_info *info)
2059 rc = mdt_handle_idmap(info);
2062 struct ptlrpc_request *req = mdt_info_req(info);
2065 opc = lustre_msg_get_opc(req->rq_reqmsg);
2066 if (opc == SEC_CTX_INIT || opc == SEC_CTX_INIT_CONT)
2067 sptlrpc_svc_ctx_invalidate(req);
2070 CFS_FAIL_TIMEOUT(OBD_FAIL_SEC_CTX_HDL_PAUSE, cfs_fail_val);
2075 static struct mdt_object *mdt_obj(struct lu_object *o)
2077 LASSERT(lu_device_is_mdt(o->lo_dev));
2078 return container_of0(o, struct mdt_object, mot_obj.mo_lu);
2081 struct mdt_object *mdt_object_find(const struct lu_env *env,
2082 struct mdt_device *d,
2083 const struct lu_fid *f)
2085 struct lu_object *o;
2086 struct mdt_object *m;
2089 CDEBUG(D_INFO, "Find object for "DFID"\n", PFID(f));
2090 o = lu_object_find(env, &d->mdt_md_dev.md_lu_dev, f, NULL);
2091 if (unlikely(IS_ERR(o)))
2092 m = (struct mdt_object *)o;
2099 * Asyncronous commit for mdt device.
2101 * Pass asynchonous commit call down the MDS stack.
2103 * \param env environment
2104 * \param mdt the mdt device
2106 static void mdt_device_commit_async(const struct lu_env *env,
2107 struct mdt_device *mdt)
2109 struct dt_device *dt = mdt->mdt_bottom;
2112 rc = dt->dd_ops->dt_commit_async(env, dt);
2113 if (unlikely(rc != 0))
2114 CWARN("async commit start failed with rc = %d", rc);
2118 * Mark the lock as "synchonous".
2120 * Mark the lock to deffer transaction commit to the unlock time.
2122 * \param lock the lock to mark as "synchonous"
2124 * \see mdt_is_lock_sync
2125 * \see mdt_save_lock
2127 static inline void mdt_set_lock_sync(struct ldlm_lock *lock)
2129 lock->l_ast_data = (void*)1;
2133 * Check whehter the lock "synchonous" or not.
2135 * \param lock the lock to check
2136 * \retval 1 the lock is "synchonous"
2137 * \retval 0 the lock isn't "synchronous"
2139 * \see mdt_set_lock_sync
2140 * \see mdt_save_lock
2142 static inline int mdt_is_lock_sync(struct ldlm_lock *lock)
2144 return lock->l_ast_data != NULL;
2148 * Blocking AST for mdt locks.
2150 * Starts transaction commit if in case of COS lock conflict or
2151 * deffers such a commit to the mdt_save_lock.
2153 * \param lock the lock which blocks a request or cancelling lock
2154 * \param desc unused
2155 * \param data unused
2156 * \param flag indicates whether this cancelling or blocking callback
2158 * \see ldlm_blocking_ast_nocheck
2160 int mdt_blocking_ast(struct ldlm_lock *lock, struct ldlm_lock_desc *desc,
2161 void *data, int flag)
2163 struct obd_device *obd = ldlm_lock_to_ns(lock)->ns_obd;
2164 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
2168 if (flag == LDLM_CB_CANCELING)
2170 lock_res_and_lock(lock);
2171 if (lock->l_blocking_ast != mdt_blocking_ast) {
2172 unlock_res_and_lock(lock);
2175 if (mdt_cos_is_enabled(mdt) &&
2176 lock->l_req_mode & (LCK_PW | LCK_EX) &&
2177 lock->l_blocking_lock != NULL &&
2178 lock->l_client_cookie != lock->l_blocking_lock->l_client_cookie) {
2179 mdt_set_lock_sync(lock);
2181 rc = ldlm_blocking_ast_nocheck(lock);
2183 /* There is no lock conflict if l_blocking_lock == NULL,
2184 * it indicates a blocking ast sent from ldlm_lock_decref_internal
2185 * when the last reference to a local lock was released */
2186 if (lock->l_req_mode == LCK_COS && lock->l_blocking_lock != NULL) {
2189 rc = lu_env_init(&env, LCT_MD_THREAD);
2190 if (unlikely(rc != 0))
2191 CWARN("lu_env initialization failed with rc = %d,"
2192 "cannot start asynchronous commit\n", rc);
2194 mdt_device_commit_async(&env, mdt);
2200 int mdt_object_lock(struct mdt_thread_info *info, struct mdt_object *o,
2201 struct mdt_lock_handle *lh, __u64 ibits, int locality)
2203 struct ldlm_namespace *ns = info->mti_mdt->mdt_namespace;
2204 ldlm_policy_data_t *policy = &info->mti_policy;
2205 struct ldlm_res_id *res_id = &info->mti_res_id;
2209 LASSERT(!lustre_handle_is_used(&lh->mlh_reg_lh));
2210 LASSERT(!lustre_handle_is_used(&lh->mlh_pdo_lh));
2211 LASSERT(lh->mlh_reg_mode != LCK_MINMODE);
2212 LASSERT(lh->mlh_type != MDT_NUL_LOCK);
2214 if (mdt_object_exists(o) < 0) {
2215 if (locality == MDT_CROSS_LOCK) {
2216 /* cross-ref object fix */
2217 ibits &= ~MDS_INODELOCK_UPDATE;
2218 ibits |= MDS_INODELOCK_LOOKUP;
2220 LASSERT(!(ibits & MDS_INODELOCK_UPDATE));
2221 LASSERT(ibits & MDS_INODELOCK_LOOKUP);
2223 /* No PDO lock on remote object */
2224 LASSERT(lh->mlh_type != MDT_PDO_LOCK);
2227 if (lh->mlh_type == MDT_PDO_LOCK) {
2228 /* check for exists after object is locked */
2229 if (mdt_object_exists(o) == 0) {
2230 /* Non-existent object shouldn't have PDO lock */
2233 /* Non-dir object shouldn't have PDO lock */
2234 if (!S_ISDIR(lu_object_attr(&o->mot_obj.mo_lu)))
2239 memset(policy, 0, sizeof(*policy));
2240 fid_build_reg_res_name(mdt_object_fid(o), res_id);
2243 * Take PDO lock on whole directory and build correct @res_id for lock
2244 * on part of directory.
2246 if (lh->mlh_pdo_hash != 0) {
2247 LASSERT(lh->mlh_type == MDT_PDO_LOCK);
2248 mdt_lock_pdo_mode(info, o, lh);
2249 if (lh->mlh_pdo_mode != LCK_NL) {
2251 * Do not use LDLM_FL_LOCAL_ONLY for parallel lock, it
2252 * is never going to be sent to client and we do not
2253 * want it slowed down due to possible cancels.
2255 policy->l_inodebits.bits = MDS_INODELOCK_UPDATE;
2256 rc = mdt_fid_lock(ns, &lh->mlh_pdo_lh, lh->mlh_pdo_mode,
2257 policy, res_id, LDLM_FL_ATOMIC_CB,
2258 &info->mti_exp->exp_handle.h_cookie);
2264 * Finish res_id initializing by name hash marking part of
2265 * directory which is taking modification.
2267 res_id->name[LUSTRE_RES_ID_HSH_OFF] = lh->mlh_pdo_hash;
2270 policy->l_inodebits.bits = ibits;
2273 * Use LDLM_FL_LOCAL_ONLY for this lock. We do not know yet if it is
2274 * going to be sent to client. If it is - mdt_intent_policy() path will
2275 * fix it up and turn FL_LOCAL flag off.
2277 rc = mdt_fid_lock(ns, &lh->mlh_reg_lh, lh->mlh_reg_mode, policy,
2278 res_id, LDLM_FL_LOCAL_ONLY | LDLM_FL_ATOMIC_CB,
2279 &info->mti_exp->exp_handle.h_cookie);
2281 mdt_object_unlock(info, o, lh, 1);
2282 else if (unlikely(OBD_FAIL_PRECHECK(OBD_FAIL_MDS_PDO_LOCK)) &&
2283 lh->mlh_pdo_hash != 0 &&
2284 (lh->mlh_reg_mode == LCK_PW || lh->mlh_reg_mode == LCK_EX)) {
2285 OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_PDO_LOCK, 15);
2292 * Save a lock within request object.
2294 * Keep the lock referenced until whether client ACK or transaction
2295 * commit happens or release the lock immediately depending on input
2296 * parameters. If COS is ON, a write lock is converted to COS lock
2299 * \param info thead info object
2300 * \param h lock handle
2301 * \param mode lock mode
2302 * \param decref force immediate lock releasing
2305 void mdt_save_lock(struct mdt_thread_info *info, struct lustre_handle *h,
2306 ldlm_mode_t mode, int decref)
2310 if (lustre_handle_is_used(h)) {
2311 if (decref || !info->mti_has_trans ||
2312 !(mode & (LCK_PW | LCK_EX))){
2313 mdt_fid_unlock(h, mode);
2315 struct mdt_device *mdt = info->mti_mdt;
2316 struct ldlm_lock *lock = ldlm_handle2lock(h);
2317 struct ptlrpc_request *req = mdt_info_req(info);
2320 LASSERTF(lock != NULL, "no lock for cookie "LPX64"\n",
2322 CDEBUG(D_HA, "request = %p reply state = %p"
2323 " transno = "LPD64"\n",
2324 req, req->rq_reply_state, req->rq_transno);
2325 if (mdt_cos_is_enabled(mdt)) {
2327 ldlm_lock_downgrade(lock, LCK_COS);
2330 ptlrpc_save_lock(req, h, mode, no_ack);
2331 if (mdt_is_lock_sync(lock)) {
2332 CDEBUG(D_HA, "found sync-lock,"
2333 " async commit started\n");
2334 mdt_device_commit_async(info->mti_env,
2337 LDLM_LOCK_PUT(lock);
2346 * Unlock mdt object.
2348 * Immeditely release the regular lock and the PDO lock or save the
2349 * lock in reqeuest and keep them referenced until client ACK or
2350 * transaction commit.
2352 * \param info thread info object
2353 * \param o mdt object
2354 * \param lh mdt lock handle referencing regular and PDO locks
2355 * \param decref force immediate lock releasing
2357 void mdt_object_unlock(struct mdt_thread_info *info, struct mdt_object *o,
2358 struct mdt_lock_handle *lh, int decref)
2362 mdt_save_lock(info, &lh->mlh_pdo_lh, lh->mlh_pdo_mode, decref);
2363 mdt_save_lock(info, &lh->mlh_reg_lh, lh->mlh_reg_mode, decref);
2368 struct mdt_object *mdt_object_find_lock(struct mdt_thread_info *info,
2369 const struct lu_fid *f,
2370 struct mdt_lock_handle *lh,
2373 struct mdt_object *o;
2375 o = mdt_object_find(info->mti_env, info->mti_mdt, f);
2379 rc = mdt_object_lock(info, o, lh, ibits,
2382 mdt_object_put(info->mti_env, o);
2389 void mdt_object_unlock_put(struct mdt_thread_info * info,
2390 struct mdt_object * o,
2391 struct mdt_lock_handle *lh,
2394 mdt_object_unlock(info, o, lh, decref);
2395 mdt_object_put(info->mti_env, o);
2398 static struct mdt_handler *mdt_handler_find(__u32 opc,
2399 struct mdt_opc_slice *supported)
2401 struct mdt_opc_slice *s;
2402 struct mdt_handler *h;
2405 for (s = supported; s->mos_hs != NULL; s++) {
2406 if (s->mos_opc_start <= opc && opc < s->mos_opc_end) {
2407 h = s->mos_hs + (opc - s->mos_opc_start);
2408 if (likely(h->mh_opc != 0))
2409 LASSERTF(h->mh_opc == opc,
2410 "opcode mismatch %d != %d\n",
2413 h = NULL; /* unsupported opc */
2420 static int mdt_lock_resname_compat(struct mdt_device *m,
2421 struct ldlm_request *req)
2423 /* XXX something... later. */
2427 static int mdt_lock_reply_compat(struct mdt_device *m, struct ldlm_reply *rep)
2429 /* XXX something... later. */
2434 * Generic code handling requests that have struct mdt_body passed in:
2436 * - extract mdt_body from request and save it in @info, if present;
2438 * - create lu_object, corresponding to the fid in mdt_body, and save it in
2441 * - if HABEO_CORPUS flag is set for this request type check whether object
2442 * actually exists on storage (lu_object_exists()).
2445 static int mdt_body_unpack(struct mdt_thread_info *info, __u32 flags)
2447 const struct mdt_body *body;
2448 struct mdt_object *obj;
2449 const struct lu_env *env;
2450 struct req_capsule *pill;
2454 env = info->mti_env;
2455 pill = info->mti_pill;
2457 body = info->mti_body = req_capsule_client_get(pill, &RMF_MDT_BODY);
2461 if (!(body->valid & OBD_MD_FLID))
2464 if (!fid_is_sane(&body->fid1)) {
2465 CERROR("Invalid fid: "DFID"\n", PFID(&body->fid1));
2470 * Do not get size or any capa fields before we check that request
2471 * contains capa actually. There are some requests which do not, for
2472 * instance MDS_IS_SUBDIR.
2474 if (req_capsule_has_field(pill, &RMF_CAPA1, RCL_CLIENT) &&
2475 req_capsule_get_size(pill, &RMF_CAPA1, RCL_CLIENT))
2476 mdt_set_capainfo(info, 0, &body->fid1,
2477 req_capsule_client_get(pill, &RMF_CAPA1));
2479 obj = mdt_object_find(env, info->mti_mdt, &body->fid1);
2481 if ((flags & HABEO_CORPUS) &&
2482 !mdt_object_exists(obj)) {
2483 mdt_object_put(env, obj);
2484 /* for capability renew ENOENT will be handled in
2486 if (body->valid & OBD_MD_FLOSSCAPA)
2491 info->mti_object = obj;
2500 static int mdt_unpack_req_pack_rep(struct mdt_thread_info *info, __u32 flags)
2502 struct req_capsule *pill = info->mti_pill;
2506 if (req_capsule_has_field(pill, &RMF_MDT_BODY, RCL_CLIENT))
2507 rc = mdt_body_unpack(info, flags);
2511 if (rc == 0 && (flags & HABEO_REFERO)) {
2512 struct mdt_device *mdt = info->mti_mdt;
2516 if (req_capsule_has_field(pill, &RMF_MDT_MD, RCL_SERVER))
2517 req_capsule_set_size(pill, &RMF_MDT_MD, RCL_SERVER,
2518 mdt->mdt_max_mdsize);
2519 if (req_capsule_has_field(pill, &RMF_LOGCOOKIES, RCL_SERVER))
2520 req_capsule_set_size(pill, &RMF_LOGCOOKIES, RCL_SERVER,
2521 mdt->mdt_max_cookiesize);
2523 rc = req_capsule_server_pack(pill);
2528 static int mdt_init_capa_ctxt(const struct lu_env *env, struct mdt_device *m)
2530 struct md_device *next = m->mdt_child;
2532 return next->md_ops->mdo_init_capa_ctxt(env, next,
2533 m->mdt_opts.mo_mds_capa,
2534 m->mdt_capa_timeout,
2540 * Invoke handler for this request opc. Also do necessary preprocessing
2541 * (according to handler ->mh_flags), and post-processing (setting of
2542 * ->last_{xid,committed}).
2544 static int mdt_req_handle(struct mdt_thread_info *info,
2545 struct mdt_handler *h, struct ptlrpc_request *req)
2547 int rc, serious = 0;
2552 LASSERT(h->mh_act != NULL);
2553 LASSERT(h->mh_opc == lustre_msg_get_opc(req->rq_reqmsg));
2554 LASSERT(current->journal_info == NULL);
2557 * Checking for various OBD_FAIL_$PREF_$OPC_NET codes. _Do_ not try
2558 * to put same checks into handlers like mdt_close(), mdt_reint(),
2559 * etc., without talking to mdt authors first. Checking same thing
2560 * there again is useless and returning 0 error without packing reply
2561 * is buggy! Handlers either pack reply or return error.
2563 * We return 0 here and do not send any reply in order to emulate
2564 * network failure. Do not send any reply in case any of NET related
2565 * fail_id has occured.
2567 if (OBD_FAIL_CHECK_ORSET(h->mh_fail_id, OBD_FAIL_ONCE))
2571 flags = h->mh_flags;
2572 LASSERT(ergo(flags & (HABEO_CORPUS|HABEO_REFERO), h->mh_fmt != NULL));
2574 if (h->mh_fmt != NULL) {
2575 req_capsule_set(info->mti_pill, h->mh_fmt);
2576 rc = mdt_unpack_req_pack_rep(info, flags);
2579 if (rc == 0 && flags & MUTABOR &&
2580 req->rq_export->exp_connect_flags & OBD_CONNECT_RDONLY)
2581 /* should it be rq_status? */
2584 if (rc == 0 && flags & HABEO_CLAVIS) {
2585 struct ldlm_request *dlm_req;
2587 LASSERT(h->mh_fmt != NULL);
2589 dlm_req = req_capsule_client_get(info->mti_pill, &RMF_DLM_REQ);
2590 if (dlm_req != NULL) {
2591 if (unlikely(dlm_req->lock_desc.l_resource.lr_type ==
2593 dlm_req->lock_desc.l_policy_data.\
2594 l_inodebits.bits == 0)) {
2596 * Lock without inodebits makes no sense and
2597 * will oops later in ldlm. If client miss to
2598 * set such bits, do not trigger ASSERTION.
2600 * For liblustre flock case, it maybe zero.
2604 if (info->mti_mdt->mdt_opts.mo_compat_resname)
2605 rc = mdt_lock_resname_compat(
2608 info->mti_dlm_req = dlm_req;
2615 /* capability setting changed via /proc, needs reinitialize ctxt */
2616 if (info->mti_mdt && info->mti_mdt->mdt_capa_conf) {
2617 mdt_init_capa_ctxt(info->mti_env, info->mti_mdt);
2618 info->mti_mdt->mdt_capa_conf = 0;
2621 if (likely(rc == 0)) {
2623 * Process request, there can be two types of rc:
2624 * 1) errors with msg unpack/pack, other failures outside the
2625 * operation itself. This is counted as serious errors;
2626 * 2) errors during fs operation, should be placed in rq_status
2629 rc = h->mh_act(info);
2631 !req->rq_no_reply && req->rq_reply_state == NULL) {
2632 DEBUG_REQ(D_ERROR, req, "MDT \"handler\" %s did not "
2633 "pack reply and returned 0 error\n",
2637 serious = is_serious(rc);
2638 rc = clear_serious(rc);
2642 req->rq_status = rc;
2645 * ELDLM_* codes which > 0 should be in rq_status only as well as
2646 * all non-serious errors.
2648 if (rc > 0 || !serious)
2651 LASSERT(current->journal_info == NULL);
2653 if (rc == 0 && (flags & HABEO_CLAVIS) &&
2654 info->mti_mdt->mdt_opts.mo_compat_resname) {
2655 struct ldlm_reply *dlmrep;
2657 dlmrep = req_capsule_server_get(info->mti_pill, &RMF_DLM_REP);
2659 rc = mdt_lock_reply_compat(info->mti_mdt, dlmrep);
2662 /* If we're DISCONNECTing, the mdt_export_data is already freed */
2663 if (likely(rc == 0 && req->rq_export && h->mh_opc != MDS_DISCONNECT))
2664 target_committed_to_req(req);
2666 if (unlikely(req_is_replay(req) &&
2667 lustre_msg_get_transno(req->rq_reqmsg) == 0)) {
2668 DEBUG_REQ(D_ERROR, req, "transno is 0 during REPLAY");
2672 target_send_reply(req, rc, info->mti_fail_id);
2676 void mdt_lock_handle_init(struct mdt_lock_handle *lh)
2678 lh->mlh_type = MDT_NUL_LOCK;
2679 lh->mlh_reg_lh.cookie = 0ull;
2680 lh->mlh_reg_mode = LCK_MINMODE;
2681 lh->mlh_pdo_lh.cookie = 0ull;
2682 lh->mlh_pdo_mode = LCK_MINMODE;
2685 void mdt_lock_handle_fini(struct mdt_lock_handle *lh)
2687 LASSERT(!lustre_handle_is_used(&lh->mlh_reg_lh));
2688 LASSERT(!lustre_handle_is_used(&lh->mlh_pdo_lh));
2692 * Initialize fields of struct mdt_thread_info. Other fields are left in
2693 * uninitialized state, because it's too expensive to zero out whole
2694 * mdt_thread_info (> 1K) on each request arrival.
2696 static void mdt_thread_info_init(struct ptlrpc_request *req,
2697 struct mdt_thread_info *info)
2700 struct md_capainfo *ci;
2702 req_capsule_init(&req->rq_pill, req, RCL_SERVER);
2703 info->mti_pill = &req->rq_pill;
2706 for (i = 0; i < ARRAY_SIZE(info->mti_lh); i++)
2707 mdt_lock_handle_init(&info->mti_lh[i]);
2709 /* mdt device: it can be NULL while CONNECT */
2710 if (req->rq_export) {
2711 info->mti_mdt = mdt_dev(req->rq_export->exp_obd->obd_lu_dev);
2712 info->mti_exp = req->rq_export;
2714 info->mti_mdt = NULL;
2715 info->mti_env = req->rq_svc_thread->t_env;
2716 ci = md_capainfo(info->mti_env);
2717 memset(ci, 0, sizeof *ci);
2718 if (req->rq_export) {
2719 if (exp_connect_rmtclient(req->rq_export))
2720 ci->mc_auth = LC_ID_CONVERT;
2721 else if (req->rq_export->exp_connect_flags &
2722 OBD_CONNECT_MDS_CAPA)
2723 ci->mc_auth = LC_ID_PLAIN;
2725 ci->mc_auth = LC_ID_NONE;
2728 info->mti_fail_id = OBD_FAIL_MDS_ALL_REPLY_NET;
2729 info->mti_transno = lustre_msg_get_transno(req->rq_reqmsg);
2730 info->mti_mos = NULL;
2732 memset(&info->mti_attr, 0, sizeof(info->mti_attr));
2733 info->mti_body = NULL;
2734 info->mti_object = NULL;
2735 info->mti_dlm_req = NULL;
2736 info->mti_has_trans = 0;
2737 info->mti_no_need_trans = 0;
2738 info->mti_cross_ref = 0;
2739 info->mti_opdata = 0;
2741 /* To not check for split by default. */
2742 info->mti_spec.sp_ck_split = 0;
2743 info->mti_spec.no_create = 0;
2746 static void mdt_thread_info_fini(struct mdt_thread_info *info)
2750 req_capsule_fini(info->mti_pill);
2751 if (info->mti_object != NULL) {
2753 * freeing an object may lead to OSD level transaction, do not
2754 * let it mess with MDT. bz19385.
2756 info->mti_no_need_trans = 1;
2757 mdt_object_put(info->mti_env, info->mti_object);
2758 info->mti_object = NULL;
2760 for (i = 0; i < ARRAY_SIZE(info->mti_lh); i++)
2761 mdt_lock_handle_fini(&info->mti_lh[i]);
2762 info->mti_env = NULL;
2765 static int mdt_filter_recovery_request(struct ptlrpc_request *req,
2766 struct obd_device *obd, int *process)
2768 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
2769 case MDS_CONNECT: /* This will never get here, but for completeness. */
2770 case OST_CONNECT: /* This will never get here, but for completeness. */
2771 case MDS_DISCONNECT:
2772 case OST_DISCONNECT:
2777 case MDS_DONE_WRITING:
2778 case MDS_SYNC: /* used in unmounting */
2784 *process = target_queue_recovery_request(req, obd);
2788 DEBUG_REQ(D_ERROR, req, "not permitted during recovery");
2795 * Handle recovery. Return:
2796 * +1: continue request processing;
2797 * -ve: abort immediately with the given error code;
2798 * 0: send reply with error code in req->rq_status;
2800 static int mdt_recovery(struct mdt_thread_info *info)
2802 struct ptlrpc_request *req = mdt_info_req(info);
2803 struct obd_device *obd;
2807 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
2810 case SEC_CTX_INIT_CONT:
2816 rc = mdt_handle_idmap(info);
2825 if (unlikely(!class_connected_export(req->rq_export))) {
2826 CERROR("operation %d on unconnected MDS from %s\n",
2827 lustre_msg_get_opc(req->rq_reqmsg),
2828 libcfs_id2str(req->rq_peer));
2829 /* FIXME: For CMD cleanup, when mds_B stop, the req from
2830 * mds_A will get -ENOTCONN(especially for ping req),
2831 * which will cause that mds_A deactive timeout, then when
2832 * mds_A cleanup, the cleanup process will be suspended since
2833 * deactive timeout is not zero.
2835 req->rq_status = -ENOTCONN;
2836 target_send_reply(req, -ENOTCONN, info->mti_fail_id);
2840 /* sanity check: if the xid matches, the request must be marked as a
2841 * resent or replayed */
2842 if (req_xid_is_last(req)) {
2843 if (!(lustre_msg_get_flags(req->rq_reqmsg) &
2844 (MSG_RESENT | MSG_REPLAY))) {
2845 DEBUG_REQ(D_WARNING, req, "rq_xid "LPU64" matches last_xid, "
2846 "expected REPLAY or RESENT flag (%x)", req->rq_xid,
2847 lustre_msg_get_flags(req->rq_reqmsg));
2849 req->rq_status = -ENOTCONN;
2854 /* else: note the opposite is not always true; a RESENT req after a
2855 * failover will usually not match the last_xid, since it was likely
2856 * never committed. A REPLAYed request will almost never match the
2857 * last xid, however it could for a committed, but still retained,
2860 obd = req->rq_export->exp_obd;
2862 /* Check for aborted recovery... */
2863 if (unlikely(obd->obd_recovering)) {
2866 DEBUG_REQ(D_INFO, req, "Got new replay");
2867 rc = mdt_filter_recovery_request(req, obd, &should_process);
2868 if (rc != 0 || !should_process)
2870 else if (should_process < 0) {
2871 req->rq_status = should_process;
2872 rc = ptlrpc_error(req);
2879 static int mdt_msg_check_version(struct lustre_msg *msg)
2883 switch (lustre_msg_get_opc(msg)) {
2885 case MDS_DISCONNECT:
2888 case SEC_CTX_INIT_CONT:
2890 rc = lustre_msg_check_version(msg, LUSTRE_OBD_VERSION);
2892 CERROR("bad opc %u version %08x, expecting %08x\n",
2893 lustre_msg_get_opc(msg),
2894 lustre_msg_get_version(msg),
2895 LUSTRE_OBD_VERSION);
2899 case MDS_GETATTR_NAME:
2906 case MDS_DONE_WRITING:
2913 case MDS_QUOTACHECK:
2919 rc = lustre_msg_check_version(msg, LUSTRE_MDS_VERSION);
2921 CERROR("bad opc %u version %08x, expecting %08x\n",
2922 lustre_msg_get_opc(msg),
2923 lustre_msg_get_version(msg),
2924 LUSTRE_MDS_VERSION);
2928 case LDLM_BL_CALLBACK:
2929 case LDLM_CP_CALLBACK:
2930 rc = lustre_msg_check_version(msg, LUSTRE_DLM_VERSION);
2932 CERROR("bad opc %u version %08x, expecting %08x\n",
2933 lustre_msg_get_opc(msg),
2934 lustre_msg_get_version(msg),
2935 LUSTRE_DLM_VERSION);
2937 case OBD_LOG_CANCEL:
2938 case LLOG_ORIGIN_HANDLE_CREATE:
2939 case LLOG_ORIGIN_HANDLE_NEXT_BLOCK:
2940 case LLOG_ORIGIN_HANDLE_READ_HEADER:
2941 case LLOG_ORIGIN_HANDLE_CLOSE:
2942 case LLOG_ORIGIN_HANDLE_DESTROY:
2943 case LLOG_ORIGIN_HANDLE_PREV_BLOCK:
2945 rc = lustre_msg_check_version(msg, LUSTRE_LOG_VERSION);
2947 CERROR("bad opc %u version %08x, expecting %08x\n",
2948 lustre_msg_get_opc(msg),
2949 lustre_msg_get_version(msg),
2950 LUSTRE_LOG_VERSION);
2953 CERROR("MDS unknown opcode %d\n", lustre_msg_get_opc(msg));
2959 static int mdt_handle0(struct ptlrpc_request *req,
2960 struct mdt_thread_info *info,
2961 struct mdt_opc_slice *supported)
2963 struct mdt_handler *h;
2964 struct lustre_msg *msg;
2969 if (OBD_FAIL_CHECK_ORSET(OBD_FAIL_MDS_ALL_REQUEST_NET, OBD_FAIL_ONCE))
2972 LASSERT(current->journal_info == NULL);
2974 msg = req->rq_reqmsg;
2975 rc = mdt_msg_check_version(msg);
2976 if (likely(rc == 0)) {
2977 rc = mdt_recovery(info);
2978 if (likely(rc == +1)) {
2979 h = mdt_handler_find(lustre_msg_get_opc(msg),
2981 if (likely(h != NULL)) {
2982 rc = mdt_req_handle(info, h, req);
2984 CERROR("The unsupported opc: 0x%x\n",
2985 lustre_msg_get_opc(msg) );
2986 req->rq_status = -ENOTSUPP;
2987 rc = ptlrpc_error(req);
2992 CERROR(LUSTRE_MDT_NAME" drops mal-formed request\n");
2997 * MDT handler function called by ptlrpc service thread when request comes.
2999 * XXX common "target" functionality should be factored into separate module
3000 * shared by mdt, ost and stand-alone services like fld.
3002 static int mdt_handle_common(struct ptlrpc_request *req,
3003 struct mdt_opc_slice *supported)
3006 struct mdt_thread_info *info;
3010 env = req->rq_svc_thread->t_env;
3011 LASSERT(env != NULL);
3012 LASSERT(env->le_ses != NULL);
3013 LASSERT(env->le_ctx.lc_thread == req->rq_svc_thread);
3014 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
3015 LASSERT(info != NULL);
3017 mdt_thread_info_init(req, info);
3019 rc = mdt_handle0(req, info, supported);
3021 mdt_thread_info_fini(info);
3026 * This is called from recovery code as handler of _all_ RPC types, FLD and SEQ
3029 int mdt_recovery_handle(struct ptlrpc_request *req)
3034 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
3036 rc = mdt_handle_common(req, mdt_fld_handlers);
3039 rc = mdt_handle_common(req, mdt_seq_handlers);
3042 rc = mdt_handle_common(req, mdt_regular_handlers);
3049 static int mdt_regular_handle(struct ptlrpc_request *req)
3051 return mdt_handle_common(req, mdt_regular_handlers);
3054 static int mdt_readpage_handle(struct ptlrpc_request *req)
3056 return mdt_handle_common(req, mdt_readpage_handlers);
3059 static int mdt_xmds_handle(struct ptlrpc_request *req)
3061 return mdt_handle_common(req, mdt_xmds_handlers);
3064 static int mdt_mdsc_handle(struct ptlrpc_request *req)
3066 return mdt_handle_common(req, mdt_seq_handlers);
3069 static int mdt_mdss_handle(struct ptlrpc_request *req)
3071 return mdt_handle_common(req, mdt_seq_handlers);
3074 static int mdt_dtss_handle(struct ptlrpc_request *req)
3076 return mdt_handle_common(req, mdt_seq_handlers);
3079 static int mdt_fld_handle(struct ptlrpc_request *req)
3081 return mdt_handle_common(req, mdt_fld_handlers);
3098 static int mdt_intent_getattr(enum mdt_it_code opcode,
3099 struct mdt_thread_info *info,
3100 struct ldlm_lock **,
3102 static int mdt_intent_reint(enum mdt_it_code opcode,
3103 struct mdt_thread_info *info,
3104 struct ldlm_lock **,
3107 static struct mdt_it_flavor {
3108 const struct req_format *it_fmt;
3110 int (*it_act)(enum mdt_it_code ,
3111 struct mdt_thread_info *,
3112 struct ldlm_lock **,
3115 } mdt_it_flavor[] = {
3117 .it_fmt = &RQF_LDLM_INTENT,
3118 /*.it_flags = HABEO_REFERO,*/
3120 .it_act = mdt_intent_reint,
3121 .it_reint = REINT_OPEN
3124 .it_fmt = &RQF_LDLM_INTENT,
3125 .it_flags = MUTABOR,
3126 .it_act = mdt_intent_reint,
3127 .it_reint = REINT_OPEN
3130 .it_fmt = &RQF_LDLM_INTENT,
3131 .it_flags = MUTABOR,
3132 .it_act = mdt_intent_reint,
3133 .it_reint = REINT_CREATE
3135 [MDT_IT_GETATTR] = {
3136 .it_fmt = &RQF_LDLM_INTENT_GETATTR,
3137 .it_flags = HABEO_REFERO,
3138 .it_act = mdt_intent_getattr
3140 [MDT_IT_READDIR] = {
3146 .it_fmt = &RQF_LDLM_INTENT_GETATTR,
3147 .it_flags = HABEO_REFERO,
3148 .it_act = mdt_intent_getattr
3151 .it_fmt = &RQF_LDLM_INTENT_UNLINK,
3152 .it_flags = MUTABOR,
3154 .it_reint = REINT_UNLINK
3158 .it_flags = MUTABOR,
3161 [MDT_IT_GETXATTR] = {
3167 .it_fmt = &RQF_LDLM_INTENT_GETATTR,
3168 .it_flags = HABEO_REFERO,
3169 .it_act = mdt_intent_getattr
3173 int mdt_intent_lock_replace(struct mdt_thread_info *info,
3174 struct ldlm_lock **lockp,
3175 struct ldlm_lock *new_lock,
3176 struct mdt_lock_handle *lh,
3179 struct ptlrpc_request *req = mdt_info_req(info);
3180 struct ldlm_lock *lock = *lockp;
3183 * Get new lock only for cases when possible resent did not find any
3186 if (new_lock == NULL)
3187 new_lock = ldlm_handle2lock_long(&lh->mlh_reg_lh, 0);
3189 if (new_lock == NULL && (flags & LDLM_FL_INTENT_ONLY)) {
3190 lh->mlh_reg_lh.cookie = 0;
3194 LASSERTF(new_lock != NULL,
3195 "lockh "LPX64"\n", lh->mlh_reg_lh.cookie);
3198 * If we've already given this lock to a client once, then we should
3199 * have no readers or writers. Otherwise, we should have one reader
3200 * _or_ writer ref (which will be zeroed below) before returning the
3203 if (new_lock->l_export == req->rq_export) {
3204 LASSERT(new_lock->l_readers + new_lock->l_writers == 0);
3206 LASSERT(new_lock->l_export == NULL);
3207 LASSERT(new_lock->l_readers + new_lock->l_writers == 1);
3212 if (new_lock->l_export == req->rq_export) {
3214 * Already gave this to the client, which means that we
3215 * reconstructed a reply.
3217 LASSERT(lustre_msg_get_flags(req->rq_reqmsg) &
3219 lh->mlh_reg_lh.cookie = 0;
3220 RETURN(ELDLM_LOCK_REPLACED);
3224 * Fixup the lock to be given to the client.
3226 lock_res_and_lock(new_lock);
3227 /* Zero new_lock->l_readers and new_lock->l_writers without triggering
3228 * possible blocking AST. */
3229 while (new_lock->l_readers > 0) {
3230 lu_ref_del(&new_lock->l_reference, "reader", new_lock);
3231 lu_ref_del(&new_lock->l_reference, "user", new_lock);
3232 new_lock->l_readers--;
3234 while (new_lock->l_writers > 0) {
3235 lu_ref_del(&new_lock->l_reference, "writer", new_lock);
3236 lu_ref_del(&new_lock->l_reference, "user", new_lock);
3237 new_lock->l_writers--;
3240 new_lock->l_export = class_export_lock_get(req->rq_export, new_lock);
3241 new_lock->l_blocking_ast = lock->l_blocking_ast;
3242 new_lock->l_completion_ast = lock->l_completion_ast;
3243 new_lock->l_remote_handle = lock->l_remote_handle;
3244 new_lock->l_flags &= ~LDLM_FL_LOCAL;
3246 unlock_res_and_lock(new_lock);
3248 cfs_hash_add(new_lock->l_export->exp_lock_hash,
3249 &new_lock->l_remote_handle,
3250 &new_lock->l_exp_hash);
3252 LDLM_LOCK_RELEASE(new_lock);
3253 lh->mlh_reg_lh.cookie = 0;
3255 RETURN(ELDLM_LOCK_REPLACED);
3258 static void mdt_intent_fixup_resent(struct mdt_thread_info *info,
3259 struct ldlm_lock *new_lock,
3260 struct ldlm_lock **old_lock,
3261 struct mdt_lock_handle *lh)
3263 struct ptlrpc_request *req = mdt_info_req(info);
3264 struct obd_export *exp = req->rq_export;
3265 struct lustre_handle remote_hdl;
3266 struct ldlm_request *dlmreq;
3267 struct ldlm_lock *lock;
3269 if (!(lustre_msg_get_flags(req->rq_reqmsg) & MSG_RESENT))
3272 dlmreq = req_capsule_client_get(info->mti_pill, &RMF_DLM_REQ);
3273 remote_hdl = dlmreq->lock_handle[0];
3275 lock = cfs_hash_lookup(exp->exp_lock_hash, &remote_hdl);
3277 if (lock != new_lock) {
3278 lh->mlh_reg_lh.cookie = lock->l_handle.h_cookie;
3279 lh->mlh_reg_mode = lock->l_granted_mode;
3281 LDLM_DEBUG(lock, "Restoring lock cookie");
3282 DEBUG_REQ(D_DLMTRACE, req,
3283 "restoring lock cookie "LPX64,
3284 lh->mlh_reg_lh.cookie);
3286 *old_lock = LDLM_LOCK_GET(lock);
3287 cfs_hash_put(exp->exp_lock_hash, &lock->l_exp_hash);
3291 cfs_hash_put(exp->exp_lock_hash, &lock->l_exp_hash);
3295 * If the xid matches, then we know this is a resent request, and allow
3296 * it. (It's probably an OPEN, for which we don't send a lock.
3298 if (req_xid_is_last(req))
3302 * This remote handle isn't enqueued, so we never received or processed
3303 * this request. Clear MSG_RESENT, because it can be handled like any
3304 * normal request now.
3306 lustre_msg_clear_flags(req->rq_reqmsg, MSG_RESENT);
3308 DEBUG_REQ(D_DLMTRACE, req, "no existing lock with rhandle "LPX64,
3312 static int mdt_intent_getattr(enum mdt_it_code opcode,
3313 struct mdt_thread_info *info,
3314 struct ldlm_lock **lockp,
3317 struct mdt_lock_handle *lhc = &info->mti_lh[MDT_LH_RMT];
3318 struct ldlm_lock *new_lock = NULL;
3320 struct ldlm_reply *ldlm_rep;
3321 struct ptlrpc_request *req;
3322 struct mdt_body *reqbody;
3323 struct mdt_body *repbody;
3327 reqbody = req_capsule_client_get(info->mti_pill, &RMF_MDT_BODY);
3330 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
3333 info->mti_spec.sp_ck_split = !!(reqbody->valid & OBD_MD_FLCKSPLIT);
3334 info->mti_cross_ref = !!(reqbody->valid & OBD_MD_FLCROSSREF);
3335 repbody->eadatasize = 0;
3336 repbody->aclsize = 0;
3340 child_bits = MDS_INODELOCK_LOOKUP;
3342 case MDT_IT_GETATTR:
3343 child_bits = MDS_INODELOCK_LOOKUP | MDS_INODELOCK_UPDATE;
3345 case MDT_IT_LAYOUT: {
3346 static int printed = 0;
3349 CERROR("layout lock not supported by this version\n");
3352 GOTO(out_shrink, rc = -EINVAL);
3356 CERROR("Unsupported intent (%d)\n", opcode);
3357 GOTO(out_shrink, rc = -EINVAL);
3360 rc = mdt_init_ucred(info, reqbody);
3362 GOTO(out_shrink, rc);
3364 req = info->mti_pill->rc_req;
3365 ldlm_rep = req_capsule_server_get(info->mti_pill, &RMF_DLM_REP);
3366 mdt_set_disposition(info, ldlm_rep, DISP_IT_EXECD);
3368 /* Get lock from request for possible resent case. */
3369 mdt_intent_fixup_resent(info, *lockp, &new_lock, lhc);
3371 ldlm_rep->lock_policy_res2 =
3372 mdt_getattr_name_lock(info, lhc, child_bits, ldlm_rep);
3374 if (mdt_get_disposition(ldlm_rep, DISP_LOOKUP_NEG))
3375 ldlm_rep->lock_policy_res2 = 0;
3376 if (!mdt_get_disposition(ldlm_rep, DISP_LOOKUP_POS) ||
3377 ldlm_rep->lock_policy_res2) {
3378 lhc->mlh_reg_lh.cookie = 0ull;
3379 GOTO(out_ucred, rc = ELDLM_LOCK_ABORTED);
3382 rc = mdt_intent_lock_replace(info, lockp, new_lock, lhc, flags);
3385 mdt_exit_ucred(info);
3387 mdt_client_compatibility(info);
3388 mdt_shrink_reply(info);
3392 static int mdt_intent_reint(enum mdt_it_code opcode,
3393 struct mdt_thread_info *info,
3394 struct ldlm_lock **lockp,
3397 struct mdt_lock_handle *lhc = &info->mti_lh[MDT_LH_RMT];
3398 struct ldlm_reply *rep = NULL;
3402 static const struct req_format *intent_fmts[REINT_MAX] = {
3403 [REINT_CREATE] = &RQF_LDLM_INTENT_CREATE,
3404 [REINT_OPEN] = &RQF_LDLM_INTENT_OPEN
3409 opc = mdt_reint_opcode(info, intent_fmts);
3413 if (mdt_it_flavor[opcode].it_reint != opc) {
3414 CERROR("Reint code %ld doesn't match intent: %d\n",
3416 RETURN(err_serious(-EPROTO));
3419 /* Get lock from request for possible resent case. */
3420 mdt_intent_fixup_resent(info, *lockp, NULL, lhc);
3422 rc = mdt_reint_internal(info, lhc, opc);
3424 /* Check whether the reply has been packed successfully. */
3425 if (mdt_info_req(info)->rq_repmsg != NULL)
3426 rep = req_capsule_server_get(info->mti_pill, &RMF_DLM_REP);
3428 RETURN(err_serious(-EFAULT));
3430 /* MDC expects this in any case */
3432 mdt_set_disposition(info, rep, DISP_LOOKUP_EXECD);
3434 /* Cross-ref case, the lock should be returned to the client */
3435 if (rc == -EREMOTE) {
3436 LASSERT(lustre_handle_is_used(&lhc->mlh_reg_lh));
3437 rep->lock_policy_res2 = 0;
3438 rc = mdt_intent_lock_replace(info, lockp, NULL, lhc, flags);
3441 rep->lock_policy_res2 = clear_serious(rc);
3443 if (rep->lock_policy_res2 == -ENOENT &&
3444 mdt_get_disposition(rep, DISP_LOOKUP_NEG))
3445 rep->lock_policy_res2 = 0;
3447 if (rc == -ENOTCONN || rc == -ENODEV ||
3448 rc == -EOVERFLOW) { /**< if VBR failure then return error */
3450 * If it is the disconnect error (ENODEV & ENOCONN), the error
3451 * will be returned by rq_status, and client at ptlrpc layer
3452 * will detect this, then disconnect, reconnect the import
3453 * immediately, instead of impacting the following the rpc.
3455 lhc->mlh_reg_lh.cookie = 0ull;
3459 * For other cases, the error will be returned by intent.
3460 * and client will retrieve the result from intent.
3463 * FIXME: when open lock is finished, that should be
3466 if (lustre_handle_is_used(&lhc->mlh_reg_lh)) {
3467 LASSERTF(rc == 0, "Error occurred but lock handle "
3468 "is still in use\n");
3469 rep->lock_policy_res2 = 0;
3470 rc = mdt_intent_lock_replace(info, lockp, NULL, lhc, flags);
3473 lhc->mlh_reg_lh.cookie = 0ull;
3474 RETURN(ELDLM_LOCK_ABORTED);
3479 static int mdt_intent_code(long itcode)
3487 case IT_OPEN|IT_CREAT:
3494 rc = MDT_IT_READDIR;
3497 rc = MDT_IT_GETATTR;
3509 rc = MDT_IT_GETXATTR;
3515 CERROR("Unknown intent opcode: %ld\n", itcode);
3522 static int mdt_intent_opc(long itopc, struct mdt_thread_info *info,
3523 struct ldlm_lock **lockp, int flags)
3525 struct req_capsule *pill;
3526 struct mdt_it_flavor *flv;
3531 opc = mdt_intent_code(itopc);
3535 pill = info->mti_pill;
3536 flv = &mdt_it_flavor[opc];
3538 if (flv->it_fmt != NULL)
3539 req_capsule_extend(pill, flv->it_fmt);
3541 rc = mdt_unpack_req_pack_rep(info, flv->it_flags);
3543 struct ptlrpc_request *req = mdt_info_req(info);
3544 if (flv->it_flags & MUTABOR &&
3545 req->rq_export->exp_connect_flags & OBD_CONNECT_RDONLY)
3548 if (rc == 0 && flv->it_act != NULL) {
3549 /* execute policy */
3550 rc = flv->it_act(opc, info, lockp, flags);
3557 static int mdt_intent_policy(struct ldlm_namespace *ns,
3558 struct ldlm_lock **lockp, void *req_cookie,
3559 ldlm_mode_t mode, int flags, void *data)
3561 struct mdt_thread_info *info;
3562 struct ptlrpc_request *req = req_cookie;
3563 struct ldlm_intent *it;
3564 struct req_capsule *pill;
3569 LASSERT(req != NULL);
3571 info = lu_context_key_get(&req->rq_svc_thread->t_env->le_ctx,
3573 LASSERT(info != NULL);
3574 pill = info->mti_pill;
3575 LASSERT(pill->rc_req == req);
3577 if (req->rq_reqmsg->lm_bufcount > DLM_INTENT_IT_OFF) {
3578 req_capsule_extend(pill, &RQF_LDLM_INTENT);
3579 it = req_capsule_client_get(pill, &RMF_LDLM_INTENT);
3581 rc = mdt_intent_opc(it->opc, info, lockp, flags);
3585 /* Lock without inodebits makes no sense and will oops
3586 * later in ldlm. Let's check it now to see if we have
3587 * ibits corrupted somewhere in mdt_intent_opc().
3588 * The case for client miss to set ibits has been
3589 * processed by others. */
3590 LASSERT(ergo(info->mti_dlm_req->lock_desc.l_resource.\
3591 lr_type == LDLM_IBITS,
3592 info->mti_dlm_req->lock_desc.\
3593 l_policy_data.l_inodebits.bits != 0));
3595 rc = err_serious(-EFAULT);
3597 /* No intent was provided */
3598 LASSERT(pill->rc_fmt == &RQF_LDLM_ENQUEUE);
3599 rc = req_capsule_server_pack(pill);
3601 rc = err_serious(rc);
3606 static int mdt_seq_fini(const struct lu_env *env,
3607 struct mdt_device *m)
3609 struct md_site *ms = mdt_md_site(m);
3613 if (ms->ms_server_seq) {
3614 seq_server_fini(ms->ms_server_seq, env);
3615 OBD_FREE_PTR(ms->ms_server_seq);
3616 ms->ms_server_seq = NULL;
3619 if (ms->ms_control_seq) {
3620 seq_server_fini(ms->ms_control_seq, env);
3621 OBD_FREE_PTR(ms->ms_control_seq);
3622 ms->ms_control_seq = NULL;
3625 if (ms->ms_client_seq) {
3626 seq_client_fini(ms->ms_client_seq);
3627 OBD_FREE_PTR(ms->ms_client_seq);
3628 ms->ms_client_seq = NULL;
3635 static int mdt_seq_init(const struct lu_env *env,
3637 struct mdt_device *m)
3644 ms = mdt_md_site(m);
3647 * This is sequence-controller node. Init seq-controller server on local
3650 if (ms->ms_node_id == 0) {
3651 LASSERT(ms->ms_control_seq == NULL);
3653 OBD_ALLOC_PTR(ms->ms_control_seq);
3654 if (ms->ms_control_seq == NULL)
3657 rc = seq_server_init(ms->ms_control_seq,
3658 m->mdt_bottom, uuid,
3659 LUSTRE_SEQ_CONTROLLER,
3664 GOTO(out_seq_fini, rc);
3666 OBD_ALLOC_PTR(ms->ms_client_seq);
3667 if (ms->ms_client_seq == NULL)
3668 GOTO(out_seq_fini, rc = -ENOMEM);
3670 OBD_ALLOC(prefix, MAX_OBD_NAME + 5);
3671 if (prefix == NULL) {
3672 OBD_FREE_PTR(ms->ms_client_seq);
3673 GOTO(out_seq_fini, rc = -ENOMEM);
3676 snprintf(prefix, MAX_OBD_NAME + 5, "ctl-%s",
3680 * Init seq-controller client after seq-controller server is
3681 * ready. Pass ms->ms_control_seq to it for direct talking.
3683 rc = seq_client_init(ms->ms_client_seq, NULL,
3684 LUSTRE_SEQ_METADATA, prefix,
3685 ms->ms_control_seq);
3686 OBD_FREE(prefix, MAX_OBD_NAME + 5);
3689 GOTO(out_seq_fini, rc);
3692 /* Init seq-server on local MDT */
3693 LASSERT(ms->ms_server_seq == NULL);
3695 OBD_ALLOC_PTR(ms->ms_server_seq);
3696 if (ms->ms_server_seq == NULL)
3697 GOTO(out_seq_fini, rc = -ENOMEM);
3699 rc = seq_server_init(ms->ms_server_seq,
3700 m->mdt_bottom, uuid,
3705 GOTO(out_seq_fini, rc = -ENOMEM);
3707 /* Assign seq-controller client to local seq-server. */
3708 if (ms->ms_node_id == 0) {
3709 LASSERT(ms->ms_client_seq != NULL);
3711 rc = seq_server_set_cli(ms->ms_server_seq,
3719 mdt_seq_fini(env, m);
3724 * Init client sequence manager which is used by local MDS to talk to sequence
3725 * controller on remote node.
3727 static int mdt_seq_init_cli(const struct lu_env *env,
3728 struct mdt_device *m,
3729 struct lustre_cfg *cfg)
3731 struct md_site *ms = mdt_md_site(m);
3732 struct obd_device *mdc;
3733 struct obd_uuid *uuidp, *mdcuuidp;
3734 char *uuid_str, *mdc_uuid_str;
3737 struct mdt_thread_info *info;
3738 char *p, *index_string = lustre_cfg_string(cfg, 2);
3741 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
3742 uuidp = &info->mti_u.uuid[0];
3743 mdcuuidp = &info->mti_u.uuid[1];
3745 LASSERT(index_string);
3747 index = simple_strtol(index_string, &p, 10);
3749 CERROR("Invalid index in lustre_cgf, offset 2\n");
3753 /* check if this is adding the first MDC and controller is not yet
3755 if (index != 0 || ms->ms_client_seq)
3758 uuid_str = lustre_cfg_string(cfg, 1);
3759 mdc_uuid_str = lustre_cfg_string(cfg, 4);
3760 obd_str2uuid(uuidp, uuid_str);
3761 obd_str2uuid(mdcuuidp, mdc_uuid_str);
3763 mdc = class_find_client_obd(uuidp, LUSTRE_MDC_NAME, mdcuuidp);
3765 CERROR("can't find controller MDC by uuid %s\n",
3768 } else if (!mdc->obd_set_up) {
3769 CERROR("target %s not set up\n", mdc->obd_name);
3772 LASSERT(ms->ms_control_exp);
3773 OBD_ALLOC_PTR(ms->ms_client_seq);
3774 if (ms->ms_client_seq != NULL) {
3777 OBD_ALLOC(prefix, MAX_OBD_NAME + 5);
3781 snprintf(prefix, MAX_OBD_NAME + 5, "ctl-%s",
3784 rc = seq_client_init(ms->ms_client_seq,
3786 LUSTRE_SEQ_METADATA,
3788 OBD_FREE(prefix, MAX_OBD_NAME + 5);
3795 LASSERT(ms->ms_server_seq != NULL);
3796 rc = seq_server_set_cli(ms->ms_server_seq, ms->ms_client_seq,
3803 static void mdt_seq_fini_cli(struct mdt_device *m)
3809 ms = mdt_md_site(m);
3812 if (ms->ms_server_seq)
3813 seq_server_set_cli(ms->ms_server_seq,
3816 if (ms->ms_control_exp) {
3817 class_export_put(ms->ms_control_exp);
3818 ms->ms_control_exp = NULL;
3827 static int mdt_fld_fini(const struct lu_env *env,
3828 struct mdt_device *m)
3830 struct md_site *ms = mdt_md_site(m);
3833 if (ms && ms->ms_server_fld) {
3834 fld_server_fini(ms->ms_server_fld, env);
3835 OBD_FREE_PTR(ms->ms_server_fld);
3836 ms->ms_server_fld = NULL;
3842 static int mdt_fld_init(const struct lu_env *env,
3844 struct mdt_device *m)
3850 ms = mdt_md_site(m);
3852 OBD_ALLOC_PTR(ms->ms_server_fld);
3853 if (ms->ms_server_fld == NULL)
3854 RETURN(rc = -ENOMEM);
3856 rc = fld_server_init(ms->ms_server_fld,
3857 m->mdt_bottom, uuid,
3858 env, ms->ms_node_id);
3860 OBD_FREE_PTR(ms->ms_server_fld);
3861 ms->ms_server_fld = NULL;
3868 /* device init/fini methods */
3869 static void mdt_stop_ptlrpc_service(struct mdt_device *m)
3872 if (m->mdt_regular_service != NULL) {
3873 ptlrpc_unregister_service(m->mdt_regular_service);
3874 m->mdt_regular_service = NULL;
3876 if (m->mdt_readpage_service != NULL) {
3877 ptlrpc_unregister_service(m->mdt_readpage_service);
3878 m->mdt_readpage_service = NULL;
3880 if (m->mdt_xmds_service != NULL) {
3881 ptlrpc_unregister_service(m->mdt_xmds_service);
3882 m->mdt_xmds_service = NULL;
3884 if (m->mdt_setattr_service != NULL) {
3885 ptlrpc_unregister_service(m->mdt_setattr_service);
3886 m->mdt_setattr_service = NULL;
3888 if (m->mdt_mdsc_service != NULL) {
3889 ptlrpc_unregister_service(m->mdt_mdsc_service);
3890 m->mdt_mdsc_service = NULL;
3892 if (m->mdt_mdss_service != NULL) {
3893 ptlrpc_unregister_service(m->mdt_mdss_service);
3894 m->mdt_mdss_service = NULL;
3896 if (m->mdt_dtss_service != NULL) {
3897 ptlrpc_unregister_service(m->mdt_dtss_service);
3898 m->mdt_dtss_service = NULL;
3900 if (m->mdt_fld_service != NULL) {
3901 ptlrpc_unregister_service(m->mdt_fld_service);
3902 m->mdt_fld_service = NULL;
3907 static int mdt_start_ptlrpc_service(struct mdt_device *m)
3910 static struct ptlrpc_service_conf conf;
3911 cfs_proc_dir_entry_t *procfs_entry;
3914 procfs_entry = m->mdt_md_dev.md_lu_dev.ld_obd->obd_proc_entry;
3916 conf = (typeof(conf)) {
3917 .psc_nbufs = MDS_NBUFS,
3918 .psc_bufsize = MDS_BUFSIZE,
3919 .psc_max_req_size = MDS_MAXREQSIZE,
3920 .psc_max_reply_size = MDS_MAXREPSIZE,
3921 .psc_req_portal = MDS_REQUEST_PORTAL,
3922 .psc_rep_portal = MDC_REPLY_PORTAL,
3923 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
3925 * We'd like to have a mechanism to set this on a per-device
3926 * basis, but alas...
3928 .psc_min_threads = mdt_min_threads,
3929 .psc_max_threads = mdt_max_threads,
3930 .psc_ctx_tags = LCT_MD_THREAD
3933 m->mdt_ldlm_client = &m->mdt_md_dev.md_lu_dev.ld_obd->obd_ldlm_client;
3934 ptlrpc_init_client(LDLM_CB_REQUEST_PORTAL, LDLM_CB_REPLY_PORTAL,
3935 "mdt_ldlm_client", m->mdt_ldlm_client);
3937 m->mdt_regular_service =
3938 ptlrpc_init_svc_conf(&conf, mdt_regular_handle, LUSTRE_MDT_NAME,
3939 procfs_entry, target_print_req,
3941 if (m->mdt_regular_service == NULL)
3944 rc = ptlrpc_start_threads(m->mdt_regular_service);
3946 GOTO(err_mdt_svc, rc);
3949 * readpage service configuration. Parameters have to be adjusted,
3952 conf = (typeof(conf)) {
3953 .psc_nbufs = MDS_NBUFS,
3954 .psc_bufsize = MDS_BUFSIZE,
3955 .psc_max_req_size = MDS_MAXREQSIZE,
3956 .psc_max_reply_size = MDS_MAXREPSIZE,
3957 .psc_req_portal = MDS_READPAGE_PORTAL,
3958 .psc_rep_portal = MDC_REPLY_PORTAL,
3959 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
3960 .psc_min_threads = mdt_min_threads,
3961 .psc_max_threads = mdt_max_threads,
3962 .psc_ctx_tags = LCT_MD_THREAD
3964 m->mdt_readpage_service =
3965 ptlrpc_init_svc_conf(&conf, mdt_readpage_handle,
3966 LUSTRE_MDT_NAME "_readpage",
3967 procfs_entry, target_print_req,"mdt_rdpg");
3969 if (m->mdt_readpage_service == NULL) {
3970 CERROR("failed to start readpage service\n");
3971 GOTO(err_mdt_svc, rc = -ENOMEM);
3974 rc = ptlrpc_start_threads(m->mdt_readpage_service);
3977 * setattr service configuration.
3979 * XXX To keep the compatibility with old client(< 2.2), we need to
3980 * preserve this portal for a certain time, it should be removed
3981 * eventually. LU-617.
3983 conf = (typeof(conf)) {
3984 .psc_nbufs = MDS_NBUFS,
3985 .psc_bufsize = MDS_BUFSIZE,
3986 .psc_max_req_size = MDS_MAXREQSIZE,
3987 .psc_max_reply_size = MDS_MAXREPSIZE,
3988 .psc_req_portal = MDS_SETATTR_PORTAL,
3989 .psc_rep_portal = MDC_REPLY_PORTAL,
3990 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
3991 .psc_min_threads = mdt_min_threads,
3992 .psc_max_threads = mdt_max_threads,
3993 .psc_ctx_tags = LCT_MD_THREAD
3996 m->mdt_setattr_service =
3997 ptlrpc_init_svc_conf(&conf, mdt_regular_handle,
3998 LUSTRE_MDT_NAME "_setattr",
3999 procfs_entry, target_print_req,"mdt_attr");
4001 if (!m->mdt_setattr_service) {
4002 CERROR("failed to start setattr service\n");
4003 GOTO(err_mdt_svc, rc = -ENOMEM);
4006 rc = ptlrpc_start_threads(m->mdt_setattr_service);
4008 GOTO(err_mdt_svc, rc);
4011 * sequence controller service configuration
4013 conf = (typeof(conf)) {
4014 .psc_nbufs = MDS_NBUFS,
4015 .psc_bufsize = MDS_BUFSIZE,
4016 .psc_max_req_size = SEQ_MAXREQSIZE,
4017 .psc_max_reply_size = SEQ_MAXREPSIZE,
4018 .psc_req_portal = SEQ_CONTROLLER_PORTAL,
4019 .psc_rep_portal = MDC_REPLY_PORTAL,
4020 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
4021 .psc_min_threads = mdt_min_threads,
4022 .psc_max_threads = mdt_max_threads,
4023 .psc_ctx_tags = LCT_MD_THREAD|LCT_DT_THREAD
4026 m->mdt_mdsc_service =
4027 ptlrpc_init_svc_conf(&conf, mdt_mdsc_handle,
4028 LUSTRE_MDT_NAME"_mdsc",
4029 procfs_entry, target_print_req,"mdt_mdsc");
4030 if (!m->mdt_mdsc_service) {
4031 CERROR("failed to start seq controller service\n");
4032 GOTO(err_mdt_svc, rc = -ENOMEM);
4035 rc = ptlrpc_start_threads(m->mdt_mdsc_service);
4037 GOTO(err_mdt_svc, rc);
4040 * metadata sequence server service configuration
4042 conf = (typeof(conf)) {
4043 .psc_nbufs = MDS_NBUFS,
4044 .psc_bufsize = MDS_BUFSIZE,
4045 .psc_max_req_size = SEQ_MAXREQSIZE,
4046 .psc_max_reply_size = SEQ_MAXREPSIZE,
4047 .psc_req_portal = SEQ_METADATA_PORTAL,
4048 .psc_rep_portal = MDC_REPLY_PORTAL,
4049 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
4050 .psc_min_threads = mdt_min_threads,
4051 .psc_max_threads = mdt_max_threads,
4052 .psc_ctx_tags = LCT_MD_THREAD|LCT_DT_THREAD
4055 m->mdt_mdss_service =
4056 ptlrpc_init_svc_conf(&conf, mdt_mdss_handle,
4057 LUSTRE_MDT_NAME"_mdss",
4058 procfs_entry, target_print_req,"mdt_mdss");
4059 if (!m->mdt_mdss_service) {
4060 CERROR("failed to start metadata seq server service\n");
4061 GOTO(err_mdt_svc, rc = -ENOMEM);
4064 rc = ptlrpc_start_threads(m->mdt_mdss_service);
4066 GOTO(err_mdt_svc, rc);
4070 * Data sequence server service configuration. We want to have really
4071 * cluster-wide sequences space. This is why we start only one sequence
4072 * controller which manages space.
4074 conf = (typeof(conf)) {
4075 .psc_nbufs = MDS_NBUFS,
4076 .psc_bufsize = MDS_BUFSIZE,
4077 .psc_max_req_size = SEQ_MAXREQSIZE,
4078 .psc_max_reply_size = SEQ_MAXREPSIZE,
4079 .psc_req_portal = SEQ_DATA_PORTAL,
4080 .psc_rep_portal = OSC_REPLY_PORTAL,
4081 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
4082 .psc_min_threads = mdt_min_threads,
4083 .psc_max_threads = mdt_max_threads,
4084 .psc_ctx_tags = LCT_MD_THREAD|LCT_DT_THREAD
4087 m->mdt_dtss_service =
4088 ptlrpc_init_svc_conf(&conf, mdt_dtss_handle,
4089 LUSTRE_MDT_NAME"_dtss",
4090 procfs_entry, target_print_req,"mdt_dtss");
4091 if (!m->mdt_dtss_service) {
4092 CERROR("failed to start data seq server service\n");
4093 GOTO(err_mdt_svc, rc = -ENOMEM);
4096 rc = ptlrpc_start_threads(m->mdt_dtss_service);
4098 GOTO(err_mdt_svc, rc);
4100 /* FLD service start */
4101 conf = (typeof(conf)) {
4102 .psc_nbufs = MDS_NBUFS,
4103 .psc_bufsize = MDS_BUFSIZE,
4104 .psc_max_req_size = FLD_MAXREQSIZE,
4105 .psc_max_reply_size = FLD_MAXREPSIZE,
4106 .psc_req_portal = FLD_REQUEST_PORTAL,
4107 .psc_rep_portal = MDC_REPLY_PORTAL,
4108 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
4109 .psc_min_threads = mdt_min_threads,
4110 .psc_max_threads = mdt_max_threads,
4111 .psc_ctx_tags = LCT_DT_THREAD|LCT_MD_THREAD
4114 m->mdt_fld_service =
4115 ptlrpc_init_svc_conf(&conf, mdt_fld_handle,
4116 LUSTRE_MDT_NAME"_fld",
4117 procfs_entry, target_print_req, "mdt_fld");
4118 if (!m->mdt_fld_service) {
4119 CERROR("failed to start fld service\n");
4120 GOTO(err_mdt_svc, rc = -ENOMEM);
4123 rc = ptlrpc_start_threads(m->mdt_fld_service);
4125 GOTO(err_mdt_svc, rc);
4128 * mds-mds service configuration. Separate portal is used to allow
4129 * mds-mds requests be not blocked during recovery.
4131 conf = (typeof(conf)) {
4132 .psc_nbufs = MDS_NBUFS,
4133 .psc_bufsize = MDS_BUFSIZE,
4134 .psc_max_req_size = MDS_MAXREQSIZE,
4135 .psc_max_reply_size = MDS_MAXREPSIZE,
4136 .psc_req_portal = MDS_MDS_PORTAL,
4137 .psc_rep_portal = MDC_REPLY_PORTAL,
4138 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
4139 .psc_min_threads = mdt_min_threads,
4140 .psc_max_threads = mdt_max_threads,
4141 .psc_ctx_tags = LCT_MD_THREAD
4143 m->mdt_xmds_service =
4144 ptlrpc_init_svc_conf(&conf, mdt_xmds_handle,
4145 LUSTRE_MDT_NAME "_mds",
4146 procfs_entry, target_print_req,"mdt_xmds");
4148 if (m->mdt_xmds_service == NULL) {
4149 CERROR("failed to start xmds service\n");
4150 GOTO(err_mdt_svc, rc = -ENOMEM);
4153 rc = ptlrpc_start_threads(m->mdt_xmds_service);
4155 GOTO(err_mdt_svc, rc);
4160 mdt_stop_ptlrpc_service(m);
4165 static void mdt_stack_fini(const struct lu_env *env,
4166 struct mdt_device *m, struct lu_device *top)
4168 struct obd_device *obd = mdt2obd_dev(m);
4169 struct lustre_cfg_bufs *bufs;
4170 struct lustre_cfg *lcfg;
4171 struct mdt_thread_info *info;
4175 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
4176 LASSERT(info != NULL);
4178 bufs = &info->mti_u.bufs;
4179 /* process cleanup, pass mdt obd name to get obd umount flags */
4180 lustre_cfg_bufs_reset(bufs, obd->obd_name);
4185 lustre_cfg_bufs_set_string(bufs, 1, flags);
4186 lcfg = lustre_cfg_new(LCFG_CLEANUP, bufs);
4188 CERROR("Cannot alloc lcfg!\n");
4193 top->ld_ops->ldo_process_config(env, top, lcfg);
4194 lustre_cfg_free(lcfg);
4196 lu_stack_fini(env, top);
4197 m->mdt_child = NULL;
4198 m->mdt_bottom = NULL;
4201 static struct lu_device *mdt_layer_setup(struct lu_env *env,
4202 const char *typename,
4203 struct lu_device *child,
4204 struct lustre_cfg *cfg)
4206 const char *dev = lustre_cfg_string(cfg, 0);
4207 struct obd_type *type;
4208 struct lu_device_type *ldt;
4209 struct lu_device *d;
4214 type = class_get_type(typename);
4216 CERROR("Unknown type: '%s'\n", typename);
4217 GOTO(out, rc = -ENODEV);
4220 rc = lu_env_refill((struct lu_env *)env);
4222 CERROR("Failure to refill session: '%d'\n", rc);
4228 CERROR("type: '%s'\n", typename);
4229 GOTO(out_type, rc = -EINVAL);
4232 ldt->ldt_obd_type = type;
4233 d = ldt->ldt_ops->ldto_device_alloc(env, ldt, cfg);
4235 CERROR("Cannot allocate device: '%s'\n", typename);
4236 GOTO(out_type, rc = -ENODEV);
4239 LASSERT(child->ld_site);
4240 d->ld_site = child->ld_site;
4243 rc = ldt->ldt_ops->ldto_device_init(env, d, dev, child);
4245 CERROR("can't init device '%s', rc %d\n", typename, rc);
4246 GOTO(out_alloc, rc);
4249 lu_ref_add(&d->ld_reference, "lu-stack", &lu_site_init);
4251 cfs_spin_lock(&d->ld_site->ls_ld_lock);
4252 cfs_list_add_tail(&d->ld_linkage, &d->ld_site->ls_ld_linkage);
4253 cfs_spin_unlock(&d->ld_site->ls_ld_lock);
4257 ldt->ldt_ops->ldto_device_free(env, d);
4260 class_put_type(type);
4265 static int mdt_stack_init(struct lu_env *env,
4266 struct mdt_device *m,
4267 struct lustre_cfg *cfg,
4268 struct lustre_mount_info *lmi)
4270 struct lu_device *d = &m->mdt_md_dev.md_lu_dev;
4271 struct lu_device *tmp;
4272 struct md_device *md;
4273 struct lu_device *child_lu_dev;
4277 /* init the stack */
4278 tmp = mdt_layer_setup(env, LUSTRE_OSD_NAME, d, cfg);
4280 RETURN(PTR_ERR(tmp));
4282 m->mdt_bottom = lu2dt_dev(tmp);
4284 tmp = mdt_layer_setup(env, LUSTRE_MDD_NAME, d, cfg);
4286 GOTO(out, rc = PTR_ERR(tmp));
4291 tmp = mdt_layer_setup(env, LUSTRE_CMM_NAME, d, cfg);
4293 GOTO(out, rc = PTR_ERR(tmp));
4296 /*set mdd upcall device*/
4297 md_upcall_dev_set(md, lu2md_dev(d));
4300 /*set cmm upcall device*/
4301 md_upcall_dev_set(md, &m->mdt_md_dev);
4303 m->mdt_child = lu2md_dev(d);
4305 /* process setup config */
4306 tmp = &m->mdt_md_dev.md_lu_dev;
4307 rc = tmp->ld_ops->ldo_process_config(env, tmp, cfg);
4311 /* initialize local objects */
4312 child_lu_dev = &m->mdt_child->md_lu_dev;
4314 rc = child_lu_dev->ld_ops->ldo_prepare(env,
4315 &m->mdt_md_dev.md_lu_dev,
4318 /* fini from last known good lu_device */
4320 mdt_stack_fini(env, m, d);
4326 * setup CONFIG_ORIG context, used to access local config log.
4327 * this may need to be rewrite as part of llog rewrite for lu-api.
4329 static int mdt_obd_llog_setup(struct obd_device *obd,
4330 struct lustre_sb_info *lsi)
4334 LASSERT(obd->obd_fsops == NULL);
4336 obd->obd_fsops = fsfilt_get_ops(MT_STR(lsi->lsi_ldd));
4337 if (IS_ERR(obd->obd_fsops))
4338 return PTR_ERR(obd->obd_fsops);
4340 rc = fsfilt_setup(obd, lsi->lsi_srv_mnt->mnt_sb);
4342 fsfilt_put_ops(obd->obd_fsops);
4346 OBD_SET_CTXT_MAGIC(&obd->obd_lvfs_ctxt);
4347 obd->obd_lvfs_ctxt.pwdmnt = lsi->lsi_srv_mnt;
4348 obd->obd_lvfs_ctxt.pwd = lsi->lsi_srv_mnt->mnt_root;
4349 obd->obd_lvfs_ctxt.fs = get_ds();
4351 rc = llog_setup(obd, &obd->obd_olg, LLOG_CONFIG_ORIG_CTXT, obd,
4352 0, NULL, &llog_lvfs_ops);
4354 CERROR("llog_setup() failed: %d\n", rc);
4355 fsfilt_put_ops(obd->obd_fsops);
4361 static void mdt_obd_llog_cleanup(struct obd_device *obd)
4363 struct llog_ctxt *ctxt;
4365 ctxt = llog_get_context(obd, LLOG_CONFIG_ORIG_CTXT);
4369 if (obd->obd_fsops) {
4370 fsfilt_put_ops(obd->obd_fsops);
4371 obd->obd_fsops = NULL;
4375 static void mdt_fini(const struct lu_env *env, struct mdt_device *m)
4377 struct md_device *next = m->mdt_child;
4378 struct lu_device *d = &m->mdt_md_dev.md_lu_dev;
4379 struct lu_site *ls = d->ld_site;
4380 struct obd_device *obd = mdt2obd_dev(m);
4383 target_recovery_fini(obd);
4385 ping_evictor_stop();
4387 mdt_stop_ptlrpc_service(m);
4388 mdt_llog_ctxt_unclone(env, m, LLOG_CHANGELOG_ORIG_CTXT);
4389 mdt_obd_llog_cleanup(obd);
4390 obd_exports_barrier(obd);
4391 obd_zombie_barrier();
4395 #ifdef HAVE_QUOTA_SUPPORT
4396 next->md_ops->mdo_quota.mqo_cleanup(env, next);
4398 lut_fini(env, &m->mdt_lut);
4399 mdt_fs_cleanup(env, m);
4400 upcall_cache_cleanup(m->mdt_identity_cache);
4401 m->mdt_identity_cache = NULL;
4403 if (m->mdt_namespace != NULL) {
4404 ldlm_namespace_free(m->mdt_namespace, NULL,
4405 d->ld_obd->obd_force);
4406 d->ld_obd->obd_namespace = m->mdt_namespace = NULL;
4409 cfs_free_nidlist(&m->mdt_nosquash_nids);
4410 if (m->mdt_nosquash_str) {
4411 OBD_FREE(m->mdt_nosquash_str, m->mdt_nosquash_strlen);
4412 m->mdt_nosquash_str = NULL;
4413 m->mdt_nosquash_strlen = 0;
4416 mdt_seq_fini(env, m);
4417 mdt_seq_fini_cli(m);
4418 mdt_fld_fini(env, m);
4419 sptlrpc_rule_set_free(&m->mdt_sptlrpc_rset);
4421 next->md_ops->mdo_init_capa_ctxt(env, next, 0, 0, 0, NULL);
4422 cfs_timer_disarm(&m->mdt_ck_timer);
4423 mdt_ck_thread_stop(m);
4428 mdt_stack_fini(env, m, md2lu_dev(m->mdt_child));
4431 struct md_site *mite;
4434 mite = lu_site2md(ls);
4438 LASSERT(cfs_atomic_read(&d->ld_ref) == 0);
4443 static int mdt_adapt_sptlrpc_conf(struct obd_device *obd, int initial)
4445 struct mdt_device *m = mdt_dev(obd->obd_lu_dev);
4446 struct sptlrpc_rule_set tmp_rset;
4449 sptlrpc_rule_set_init(&tmp_rset);
4450 rc = sptlrpc_conf_target_get_rules(obd, &tmp_rset, initial);
4452 CERROR("mdt %s: failed get sptlrpc rules: %d\n",
4457 sptlrpc_target_update_exp_flavor(obd, &tmp_rset);
4459 cfs_write_lock(&m->mdt_sptlrpc_lock);
4460 sptlrpc_rule_set_free(&m->mdt_sptlrpc_rset);
4461 m->mdt_sptlrpc_rset = tmp_rset;
4462 cfs_write_unlock(&m->mdt_sptlrpc_lock);
4467 int mdt_postrecov(const struct lu_env *, struct mdt_device *);
4469 static int mdt_init0(const struct lu_env *env, struct mdt_device *m,
4470 struct lu_device_type *ldt, struct lustre_cfg *cfg)
4472 struct mdt_thread_info *info;
4473 struct obd_device *obd;
4474 const char *dev = lustre_cfg_string(cfg, 0);
4475 const char *num = lustre_cfg_string(cfg, 2);
4476 struct lustre_mount_info *lmi = NULL;
4477 struct lustre_sb_info *lsi;
4478 struct lustre_disk_data *ldd;
4480 struct md_site *mite;
4481 const char *identity_upcall = "NONE";
4482 struct md_device *next;
4488 md_device_init(&m->mdt_md_dev, ldt);
4490 * Environment (env) might be missing mdt_thread_key values at that
4491 * point, if device is allocated when mdt_thread_key is in QUIESCENT
4494 * Usually device allocation path doesn't use module key values, but
4495 * mdt has to do a lot of work here, so allocate key value.
4497 rc = lu_env_refill((struct lu_env *)env);
4501 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
4502 LASSERT(info != NULL);
4504 obd = class_name2obd(dev);
4505 LASSERT(obd != NULL);
4507 m->mdt_max_mdsize = MAX_MD_SIZE;
4508 m->mdt_max_cookiesize = sizeof(struct llog_cookie);
4509 m->mdt_som_conf = 0;
4511 m->mdt_opts.mo_cos = MDT_COS_DEFAULT;
4512 lmi = server_get_mount_2(dev);
4514 CERROR("Cannot get mount info for %s!\n", dev);
4517 lsi = s2lsi(lmi->lmi_sb);
4518 /* CMD is supported only in IAM mode */
4521 node_id = simple_strtol(num, NULL, 10);
4522 if (!(ldd->ldd_flags & LDD_F_IAM_DIR) && node_id) {
4523 CERROR("CMD Operation not allowed in IOP mode\n");
4524 GOTO(err_lmi, rc = -EINVAL);
4527 obd->u.obt.obt_magic = OBT_MAGIC;
4530 cfs_rwlock_init(&m->mdt_sptlrpc_lock);
4531 sptlrpc_rule_set_init(&m->mdt_sptlrpc_rset);
4533 cfs_spin_lock_init(&m->mdt_ioepoch_lock);
4534 m->mdt_opts.mo_compat_resname = 0;
4535 m->mdt_opts.mo_mds_capa = 1;
4536 m->mdt_opts.mo_oss_capa = 1;
4537 m->mdt_capa_timeout = CAPA_TIMEOUT;
4538 m->mdt_capa_alg = CAPA_HMAC_ALG_SHA1;
4539 m->mdt_ck_timeout = CAPA_KEY_TIMEOUT;
4540 m->mdt_squash_uid = 0;
4541 m->mdt_squash_gid = 0;
4542 CFS_INIT_LIST_HEAD(&m->mdt_nosquash_nids);
4543 m->mdt_nosquash_str = NULL;
4544 m->mdt_nosquash_strlen = 0;
4545 cfs_init_rwsem(&m->mdt_squash_sem);
4547 OBD_ALLOC_PTR(mite);
4549 GOTO(err_lmi, rc = -ENOMEM);
4553 m->mdt_md_dev.md_lu_dev.ld_ops = &mdt_lu_ops;
4554 m->mdt_md_dev.md_lu_dev.ld_obd = obd;
4555 /* set this lu_device to obd, because error handling need it */
4556 obd->obd_lu_dev = &m->mdt_md_dev.md_lu_dev;
4558 rc = lu_site_init(s, &m->mdt_md_dev.md_lu_dev);
4560 CERROR("Can't init lu_site, rc %d\n", rc);
4561 GOTO(err_free_site, rc);
4564 /* set server index */
4565 lu_site2md(s)->ms_node_id = node_id;
4567 /* failover is the default
4568 * FIXME: we do not failout mds0/mgs, which may cause some problems.
4569 * assumed whose ms_node_id == 0 XXX
4571 obd->obd_replayable = 1;
4572 /* No connection accepted until configurations will finish */
4573 obd->obd_no_conn = 1;
4575 if (cfg->lcfg_bufcount > 4 && LUSTRE_CFG_BUFLEN(cfg, 4) > 0) {
4576 char *str = lustre_cfg_string(cfg, 4);
4577 if (strchr(str, 'n')) {
4578 CWARN("%s: recovery disabled\n", obd->obd_name);
4579 obd->obd_replayable = 0;
4583 /* init the stack */
4584 rc = mdt_stack_init((struct lu_env *)env, m, cfg, lmi);
4586 CERROR("Can't init device stack, rc %d\n", rc);
4587 GOTO(err_lu_site, rc);
4590 rc = lut_init(env, &m->mdt_lut, obd, m->mdt_bottom);
4592 GOTO(err_fini_stack, rc);
4594 rc = mdt_fld_init(env, obd->obd_name, m);
4598 rc = mdt_seq_init(env, obd->obd_name, m);
4600 GOTO(err_fini_fld, rc);
4602 snprintf(info->mti_u.ns_name, sizeof info->mti_u.ns_name,
4603 LUSTRE_MDT_NAME"-%p", m);
4604 m->mdt_namespace = ldlm_namespace_new(obd, info->mti_u.ns_name,
4605 LDLM_NAMESPACE_SERVER,
4606 LDLM_NAMESPACE_GREEDY,
4608 if (m->mdt_namespace == NULL)
4609 GOTO(err_fini_seq, rc = -ENOMEM);
4611 ldlm_register_intent(m->mdt_namespace, mdt_intent_policy);
4612 /* set obd_namespace for compatibility with old code */
4613 obd->obd_namespace = m->mdt_namespace;
4615 cfs_timer_init(&m->mdt_ck_timer, mdt_ck_timer_callback, m);
4617 rc = mdt_ck_thread_start(m);
4619 GOTO(err_free_ns, rc);
4621 rc = mdt_fs_setup(env, m, obd, lsi);
4625 rc = mdt_obd_llog_setup(obd, lsi);
4627 GOTO(err_fs_cleanup, rc);
4629 rc = mdt_llog_ctxt_clone(env, m, LLOG_CHANGELOG_ORIG_CTXT);
4631 GOTO(err_llog_cleanup, rc);
4633 mdt_adapt_sptlrpc_conf(obd, 1);
4635 next = m->mdt_child;
4636 #ifdef HAVE_QUOTA_SUPPORT
4637 rc = next->md_ops->mdo_quota.mqo_setup(env, next, lmi->lmi_mnt);
4639 GOTO(err_llog_cleanup, rc);
4642 server_put_mount_2(dev, lmi->lmi_mnt);
4645 rc = next->md_ops->mdo_iocontrol(env, next, OBD_IOC_GET_MNTOPT, 0,
4648 GOTO(err_quota, rc);
4650 if (mntopts & MNTOPT_USERXATTR)
4651 m->mdt_opts.mo_user_xattr = 1;
4653 m->mdt_opts.mo_user_xattr = 0;
4655 if (mntopts & MNTOPT_ACL)
4656 m->mdt_opts.mo_acl = 1;
4658 m->mdt_opts.mo_acl = 0;
4660 /* XXX: to support suppgid for ACL, we enable identity_upcall
4661 * by default, otherwise, maybe got unexpected -EACCESS. */
4662 if (m->mdt_opts.mo_acl)
4663 identity_upcall = MDT_IDENTITY_UPCALL_PATH;
4665 m->mdt_identity_cache = upcall_cache_init(obd->obd_name,identity_upcall,
4666 &mdt_identity_upcall_cache_ops);
4667 if (IS_ERR(m->mdt_identity_cache)) {
4668 rc = PTR_ERR(m->mdt_identity_cache);
4669 m->mdt_identity_cache = NULL;
4670 GOTO(err_quota, rc);
4673 target_recovery_init(&m->mdt_lut, mdt_recovery_handle);
4675 rc = mdt_procfs_init(m, dev);
4677 CERROR("Can't init MDT lprocfs, rc %d\n", rc);
4678 GOTO(err_recovery, rc);
4681 rc = mdt_start_ptlrpc_service(m);
4683 GOTO(err_procfs, rc);
4685 ping_evictor_start();
4687 rc = lu_site_init_finish(s);
4689 GOTO(err_stop_service, rc);
4691 if (obd->obd_recovering == 0)
4692 mdt_postrecov(env, m);
4694 mdt_init_capa_ctxt(env, m);
4696 /* Reduce the initial timeout on an MDS because it doesn't need such
4697 * a long timeout as an OST does. Adaptive timeouts will adjust this
4698 * value appropriately. */
4699 if (ldlm_timeout == LDLM_TIMEOUT_DEFAULT)
4700 ldlm_timeout = MDS_LDLM_TIMEOUT_DEFAULT;
4705 ping_evictor_stop();
4706 mdt_stop_ptlrpc_service(m);
4710 target_recovery_fini(obd);
4711 upcall_cache_cleanup(m->mdt_identity_cache);
4712 m->mdt_identity_cache = NULL;
4714 #ifdef HAVE_QUOTA_SUPPORT
4715 next->md_ops->mdo_quota.mqo_cleanup(env, next);
4718 mdt_llog_ctxt_unclone(env, m, LLOG_CHANGELOG_ORIG_CTXT);
4719 mdt_obd_llog_cleanup(obd);
4721 mdt_fs_cleanup(env, m);
4723 cfs_timer_disarm(&m->mdt_ck_timer);
4724 mdt_ck_thread_stop(m);
4726 ldlm_namespace_free(m->mdt_namespace, NULL, 0);
4727 obd->obd_namespace = m->mdt_namespace = NULL;
4729 mdt_seq_fini(env, m);
4731 mdt_fld_fini(env, m);
4733 lut_fini(env, &m->mdt_lut);
4735 mdt_stack_fini(env, m, md2lu_dev(m->mdt_child));
4742 server_put_mount_2(dev, lmi->lmi_mnt);
4746 /* used by MGS to process specific configurations */
4747 static int mdt_process_config(const struct lu_env *env,
4748 struct lu_device *d, struct lustre_cfg *cfg)
4750 struct mdt_device *m = mdt_dev(d);
4751 struct md_device *md_next = m->mdt_child;
4752 struct lu_device *next = md2lu_dev(md_next);
4756 switch (cfg->lcfg_command) {
4758 struct lprocfs_static_vars lvars;
4759 struct obd_device *obd = d->ld_obd;
4762 * For interoperability between 1.8 and 2.0,
4765 /* Skip old "mdt.group_upcall" param. */
4766 char *param = lustre_cfg_string(cfg, 1);
4767 if (param && !strncmp("mdt.group_upcall", param, 16)) {
4768 CWARN("For 1.8 interoperability, skip this"
4769 " mdt.group_upcall. It is obsolete\n");
4772 /* Rename old "mdt.quota_type" to "mdd.quota_type. */
4773 if (param && !strncmp("mdt.quota_type", param, 14)) {
4774 CWARN("Found old param mdt.quota_type, changed"
4775 " it to mdd.quota_type.\n");
4780 lprocfs_mdt_init_vars(&lvars);
4781 rc = class_process_proc_param(PARAM_MDT, lvars.obd_vars,
4783 if (rc > 0 || rc == -ENOSYS)
4784 /* we don't understand; pass it on */
4785 rc = next->ld_ops->ldo_process_config(env, next, cfg);
4790 * Add mdc hook to get first MDT uuid and connect it to
4791 * ls->controller to use for seq manager.
4793 rc = next->ld_ops->ldo_process_config(env, next, cfg);
4795 CERROR("Can't add mdc, rc %d\n", rc);
4797 rc = mdt_seq_init_cli(env, mdt_dev(d), cfg);
4800 /* others are passed further */
4801 rc = next->ld_ops->ldo_process_config(env, next, cfg);
4807 static struct lu_object *mdt_object_alloc(const struct lu_env *env,
4808 const struct lu_object_header *hdr,
4809 struct lu_device *d)
4811 struct mdt_object *mo;
4817 struct lu_object *o;
4818 struct lu_object_header *h;
4820 o = &mo->mot_obj.mo_lu;
4821 h = &mo->mot_header;
4822 lu_object_header_init(h);
4823 lu_object_init(o, h, d);
4824 lu_object_add_top(h, o);
4825 o->lo_ops = &mdt_obj_ops;
4826 cfs_mutex_init(&mo->mot_ioepoch_mutex);
4827 cfs_mutex_init(&mo->mot_lov_mutex);
4833 static int mdt_object_init(const struct lu_env *env, struct lu_object *o,
4834 const struct lu_object_conf *unused)
4836 struct mdt_device *d = mdt_dev(o->lo_dev);
4837 struct lu_device *under;
4838 struct lu_object *below;
4842 CDEBUG(D_INFO, "object init, fid = "DFID"\n",
4843 PFID(lu_object_fid(o)));
4845 under = &d->mdt_child->md_lu_dev;
4846 below = under->ld_ops->ldo_object_alloc(env, o->lo_header, under);
4847 if (below != NULL) {
4848 lu_object_add(o, below);
4855 static void mdt_object_free(const struct lu_env *env, struct lu_object *o)
4857 struct mdt_object *mo = mdt_obj(o);
4858 struct lu_object_header *h;
4862 CDEBUG(D_INFO, "object free, fid = "DFID"\n",
4863 PFID(lu_object_fid(o)));
4866 lu_object_header_fini(h);
4871 static int mdt_object_print(const struct lu_env *env, void *cookie,
4872 lu_printer_t p, const struct lu_object *o)
4874 struct mdt_object *mdto = mdt_obj((struct lu_object *)o);
4875 return (*p)(env, cookie, LUSTRE_MDT_NAME"-object@%p(ioepoch="LPU64" "
4876 "flags="LPX64", epochcount=%d, writecount=%d)",
4877 mdto, mdto->mot_ioepoch, mdto->mot_flags,
4878 mdto->mot_ioepoch_count, mdto->mot_writecount);
4881 static const struct lu_device_operations mdt_lu_ops = {
4882 .ldo_object_alloc = mdt_object_alloc,
4883 .ldo_process_config = mdt_process_config,
4886 static const struct lu_object_operations mdt_obj_ops = {
4887 .loo_object_init = mdt_object_init,
4888 .loo_object_free = mdt_object_free,
4889 .loo_object_print = mdt_object_print
4892 static int mdt_obd_set_info_async(struct obd_export *exp,
4893 __u32 keylen, void *key,
4894 __u32 vallen, void *val,
4895 struct ptlrpc_request_set *set)
4897 struct obd_device *obd = exp->exp_obd;
4903 if (KEY_IS(KEY_SPTLRPC_CONF)) {
4904 rc = mdt_adapt_sptlrpc_conf(obd, 0);
4911 /* mds_connect_internal */
4912 static int mdt_connect_internal(struct obd_export *exp,
4913 struct mdt_device *mdt,
4914 struct obd_connect_data *data)
4917 data->ocd_connect_flags &= MDT_CONNECT_SUPPORTED;
4918 data->ocd_ibits_known &= MDS_INODELOCK_FULL;
4920 /* If no known bits (which should not happen, probably,
4921 as everybody should support LOOKUP and UPDATE bits at least)
4922 revert to compat mode with plain locks. */
4923 if (!data->ocd_ibits_known &&
4924 data->ocd_connect_flags & OBD_CONNECT_IBITS)
4925 data->ocd_connect_flags &= ~OBD_CONNECT_IBITS;
4927 if (!mdt->mdt_opts.mo_acl)
4928 data->ocd_connect_flags &= ~OBD_CONNECT_ACL;
4930 if (!mdt->mdt_opts.mo_user_xattr)
4931 data->ocd_connect_flags &= ~OBD_CONNECT_XATTR;
4933 if (!mdt->mdt_som_conf)
4934 data->ocd_connect_flags &= ~OBD_CONNECT_SOM;
4936 if (data->ocd_connect_flags & OBD_CONNECT_BRW_SIZE) {
4937 data->ocd_brw_size = min(data->ocd_brw_size,
4938 (__u32)(PTLRPC_MAX_BRW_PAGES << CFS_PAGE_SHIFT));
4939 if (data->ocd_brw_size == 0) {
4940 CERROR("%s: cli %s/%p ocd_connect_flags: "LPX64
4941 " ocd_version: %x ocd_grant: %d "
4942 "ocd_index: %u ocd_brw_size is "
4943 "unexpectedly zero, network data "
4944 "corruption? Refusing connection of this"
4946 exp->exp_obd->obd_name,
4947 exp->exp_client_uuid.uuid,
4948 exp, data->ocd_connect_flags, data->ocd_version,
4949 data->ocd_grant, data->ocd_index);
4954 cfs_spin_lock(&exp->exp_lock);
4955 exp->exp_connect_flags = data->ocd_connect_flags;
4956 cfs_spin_unlock(&exp->exp_lock);
4957 data->ocd_version = LUSTRE_VERSION_CODE;
4958 exp->exp_mdt_data.med_ibits_known = data->ocd_ibits_known;
4962 if (mdt->mdt_opts.mo_acl &&
4963 ((exp->exp_connect_flags & OBD_CONNECT_ACL) == 0)) {
4964 CWARN("%s: MDS requires ACL support but client does not\n",
4965 mdt->mdt_md_dev.md_lu_dev.ld_obd->obd_name);
4970 if ((exp->exp_connect_flags & OBD_CONNECT_FID) == 0) {
4971 CWARN("%s: MDS requires FID support, but client not\n",
4972 mdt->mdt_md_dev.md_lu_dev.ld_obd->obd_name);
4976 if (mdt->mdt_som_conf && !exp_connect_som(exp) &&
4977 !(exp->exp_connect_flags & OBD_CONNECT_MDS_MDS)) {
4978 CWARN("%s: MDS has SOM enabled, but client does not support "
4979 "it\n", mdt->mdt_md_dev.md_lu_dev.ld_obd->obd_name);
4986 static int mdt_connect_check_sptlrpc(struct mdt_device *mdt,
4987 struct obd_export *exp,
4988 struct ptlrpc_request *req)
4990 struct sptlrpc_flavor flvr;
4993 if (exp->exp_flvr.sf_rpc == SPTLRPC_FLVR_INVALID) {
4994 cfs_read_lock(&mdt->mdt_sptlrpc_lock);
4995 sptlrpc_target_choose_flavor(&mdt->mdt_sptlrpc_rset,
4999 cfs_read_unlock(&mdt->mdt_sptlrpc_lock);
5001 cfs_spin_lock(&exp->exp_lock);
5003 exp->exp_sp_peer = req->rq_sp_from;
5004 exp->exp_flvr = flvr;
5006 if (exp->exp_flvr.sf_rpc != SPTLRPC_FLVR_ANY &&
5007 exp->exp_flvr.sf_rpc != req->rq_flvr.sf_rpc) {
5008 CERROR("unauthorized rpc flavor %x from %s, "
5009 "expect %x\n", req->rq_flvr.sf_rpc,
5010 libcfs_nid2str(req->rq_peer.nid),
5011 exp->exp_flvr.sf_rpc);
5015 cfs_spin_unlock(&exp->exp_lock);
5017 if (exp->exp_sp_peer != req->rq_sp_from) {
5018 CERROR("RPC source %s doesn't match %s\n",
5019 sptlrpc_part2name(req->rq_sp_from),
5020 sptlrpc_part2name(exp->exp_sp_peer));
5023 rc = sptlrpc_target_export_check(exp, req);
5030 /* mds_connect copy */
5031 static int mdt_obd_connect(const struct lu_env *env,
5032 struct obd_export **exp, struct obd_device *obd,
5033 struct obd_uuid *cluuid,
5034 struct obd_connect_data *data,
5037 struct mdt_thread_info *info;
5038 struct obd_export *lexp;
5039 struct lustre_handle conn = { 0 };
5040 struct mdt_device *mdt;
5041 struct ptlrpc_request *req;
5045 LASSERT(env != NULL);
5046 if (!exp || !obd || !cluuid)
5049 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
5050 req = info->mti_pill->rc_req;
5051 mdt = mdt_dev(obd->obd_lu_dev);
5053 rc = class_connect(&conn, obd, cluuid);
5057 lexp = class_conn2export(&conn);
5058 LASSERT(lexp != NULL);
5060 rc = mdt_connect_check_sptlrpc(mdt, lexp, req);
5064 if (OBD_FAIL_CHECK(OBD_FAIL_TGT_RCVG_FLAG))
5065 lustre_msg_add_op_flags(req->rq_repmsg, MSG_CONNECT_RECOVERING);
5067 rc = mdt_connect_internal(lexp, mdt, data);
5069 struct mdt_thread_info *mti;
5070 struct lsd_client_data *lcd = lexp->exp_target_data.ted_lcd;
5072 mti = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
5073 LASSERT(mti != NULL);
5074 mti->mti_exp = lexp;
5075 memcpy(lcd->lcd_uuid, cluuid, sizeof lcd->lcd_uuid);
5076 rc = mdt_client_new(env, mdt);
5078 mdt_export_stats_init(obd, lexp, localdata);
5083 class_disconnect(lexp);
5092 static int mdt_obd_reconnect(const struct lu_env *env,
5093 struct obd_export *exp, struct obd_device *obd,
5094 struct obd_uuid *cluuid,
5095 struct obd_connect_data *data,
5098 struct mdt_thread_info *info;
5099 struct mdt_device *mdt;
5100 struct ptlrpc_request *req;
5104 if (exp == NULL || obd == NULL || cluuid == NULL)
5107 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
5108 req = info->mti_pill->rc_req;
5109 mdt = mdt_dev(obd->obd_lu_dev);
5111 rc = mdt_connect_check_sptlrpc(mdt, exp, req);
5115 rc = mdt_connect_internal(exp, mdt_dev(obd->obd_lu_dev), data);
5117 mdt_export_stats_init(obd, exp, localdata);
5121 static int mdt_export_cleanup(struct obd_export *exp)
5123 struct mdt_export_data *med = &exp->exp_mdt_data;
5124 struct obd_device *obd = exp->exp_obd;
5125 struct mdt_device *mdt;
5126 struct mdt_thread_info *info;
5128 CFS_LIST_HEAD(closing_list);
5129 struct mdt_file_data *mfd, *n;
5133 cfs_spin_lock(&med->med_open_lock);
5134 while (!cfs_list_empty(&med->med_open_head)) {
5135 cfs_list_t *tmp = med->med_open_head.next;
5136 mfd = cfs_list_entry(tmp, struct mdt_file_data, mfd_list);
5138 /* Remove mfd handle so it can't be found again.
5139 * We are consuming the mfd_list reference here. */
5140 class_handle_unhash(&mfd->mfd_handle);
5141 cfs_list_move_tail(&mfd->mfd_list, &closing_list);
5143 cfs_spin_unlock(&med->med_open_lock);
5144 mdt = mdt_dev(obd->obd_lu_dev);
5145 LASSERT(mdt != NULL);
5147 rc = lu_env_init(&env, LCT_MD_THREAD);
5151 info = lu_context_key_get(&env.le_ctx, &mdt_thread_key);
5152 LASSERT(info != NULL);
5153 memset(info, 0, sizeof *info);
5154 info->mti_env = &env;
5155 info->mti_mdt = mdt;
5156 info->mti_exp = exp;
5158 if (!cfs_list_empty(&closing_list)) {
5159 struct md_attr *ma = &info->mti_attr;
5163 lmm_size = mdt->mdt_max_mdsize;
5164 OBD_ALLOC_LARGE(ma->ma_lmm, lmm_size);
5165 if (ma->ma_lmm == NULL)
5166 GOTO(out_lmm, rc = -ENOMEM);
5168 cookie_size = mdt->mdt_max_cookiesize;
5169 OBD_ALLOC_LARGE(ma->ma_cookie, cookie_size);
5170 if (ma->ma_cookie == NULL)
5171 GOTO(out_cookie, rc = -ENOMEM);
5173 /* Close any open files (which may also cause orphan unlinking). */
5174 cfs_list_for_each_entry_safe(mfd, n, &closing_list, mfd_list) {
5175 cfs_list_del_init(&mfd->mfd_list);
5176 memset(&ma->ma_attr, 0, sizeof(ma->ma_attr));
5177 ma->ma_lmm_size = lmm_size;
5178 ma->ma_cookie_size = cookie_size;
5180 /* It is not for setattr, just tell MDD to send
5181 * DESTROY RPC to OSS if needed */
5182 ma->ma_valid = MA_FLAGS;
5183 ma->ma_attr_flags = MDS_CLOSE_CLEANUP;
5184 /* Don't unlink orphan on failover umount, LU-184 */
5185 if (exp->exp_flags & OBD_OPT_FAILOVER)
5186 ma->ma_attr_flags |= MDS_KEEP_ORPHAN;
5187 mdt_mfd_close(info, mfd);
5189 OBD_FREE_LARGE(ma->ma_cookie, cookie_size);
5190 ma->ma_cookie = NULL;
5192 OBD_FREE_LARGE(ma->ma_lmm, lmm_size);
5196 info->mti_mdt = NULL;
5197 /* cleanup client slot early */
5198 /* Do not erase record for recoverable client. */
5199 if (!(exp->exp_flags & OBD_OPT_FAILOVER) || exp->exp_failed)
5200 mdt_client_del(&env, mdt);
5206 static int mdt_obd_disconnect(struct obd_export *exp)
5212 class_export_get(exp);
5214 rc = server_disconnect_export(exp);
5216 CDEBUG(D_IOCTL, "server disconnect error: %d\n", rc);
5218 rc = mdt_export_cleanup(exp);
5219 class_export_put(exp);
5223 /* FIXME: Can we avoid using these two interfaces? */
5224 static int mdt_init_export(struct obd_export *exp)
5226 struct mdt_export_data *med = &exp->exp_mdt_data;
5230 CFS_INIT_LIST_HEAD(&med->med_open_head);
5231 cfs_spin_lock_init(&med->med_open_lock);
5232 cfs_mutex_init(&med->med_idmap_mutex);
5233 med->med_idmap = NULL;
5234 cfs_spin_lock(&exp->exp_lock);
5235 exp->exp_connecting = 1;
5236 cfs_spin_unlock(&exp->exp_lock);
5238 /* self-export doesn't need client data and ldlm initialization */
5239 if (unlikely(obd_uuid_equals(&exp->exp_obd->obd_uuid,
5240 &exp->exp_client_uuid)))
5243 rc = lut_client_alloc(exp);
5245 rc = ldlm_init_export(exp);
5247 CERROR("%s: Error %d while initializing export\n",
5248 exp->exp_obd->obd_name, rc);
5252 static int mdt_destroy_export(struct obd_export *exp)
5256 if (exp_connect_rmtclient(exp))
5257 mdt_cleanup_idmap(&exp->exp_mdt_data);
5259 target_destroy_export(exp);
5260 /* destroy can be called from failed obd_setup, so
5261 * checking uuid is safer than obd_self_export */
5262 if (unlikely(obd_uuid_equals(&exp->exp_obd->obd_uuid,
5263 &exp->exp_client_uuid)))
5266 ldlm_destroy_export(exp);
5267 lut_client_free(exp);
5269 LASSERT(cfs_list_empty(&exp->exp_outstanding_replies));
5270 LASSERT(cfs_list_empty(&exp->exp_mdt_data.med_open_head));
5275 static void mdt_allow_cli(struct mdt_device *m, unsigned int flag)
5277 if (flag & CONFIG_LOG)
5278 cfs_set_bit(MDT_FL_CFGLOG, &m->mdt_state);
5280 /* also notify active event */
5281 if (flag & CONFIG_SYNC)
5282 cfs_set_bit(MDT_FL_SYNCED, &m->mdt_state);
5284 if (cfs_test_bit(MDT_FL_CFGLOG, &m->mdt_state) &&
5285 cfs_test_bit(MDT_FL_SYNCED, &m->mdt_state)) {
5286 struct obd_device *obd = m->mdt_md_dev.md_lu_dev.ld_obd;
5288 /* Open for clients */
5289 if (obd->obd_no_conn) {
5290 cfs_spin_lock(&obd->obd_dev_lock);
5291 obd->obd_no_conn = 0;
5292 cfs_spin_unlock(&obd->obd_dev_lock);
5297 static int mdt_upcall(const struct lu_env *env, struct md_device *md,
5298 enum md_upcall_event ev, void *data)
5300 struct mdt_device *m = mdt_dev(&md->md_lu_dev);
5301 struct md_device *next = m->mdt_child;
5302 struct mdt_thread_info *mti;
5308 rc = next->md_ops->mdo_maxsize_get(env, next,
5310 &m->mdt_max_cookiesize);
5311 CDEBUG(D_INFO, "get max mdsize %d max cookiesize %d\n",
5312 m->mdt_max_mdsize, m->mdt_max_cookiesize);
5313 mdt_allow_cli(m, CONFIG_SYNC);
5316 m->mdt_lut.lut_obd->u.obt.obt_mount_count;
5319 mti = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
5320 mti->mti_no_need_trans = 1;
5321 CDEBUG(D_INFO, "disable mdt trans for this thread\n");
5324 /* Check that MDT is not yet configured */
5325 LASSERT(!cfs_test_bit(MDT_FL_CFGLOG, &m->mdt_state));
5327 #ifdef HAVE_QUOTA_SUPPORT
5329 if (md->md_lu_dev.ld_obd->obd_recovering == 0 &&
5330 likely(md->md_lu_dev.ld_obd->obd_stopping == 0))
5331 next->md_ops->mdo_quota.mqo_recovery(env, next);
5335 CERROR("invalid event\n");
5342 static int mdt_obd_notify(struct obd_device *obd,
5343 struct obd_device *watched,
5344 enum obd_notify_event ev, void *data)
5346 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
5347 #ifdef HAVE_QUOTA_SUPPORT
5348 struct md_device *next = mdt->mdt_child;
5353 case OBD_NOTIFY_CONFIG:
5354 mdt_allow_cli(mdt, (unsigned long)data);
5356 #ifdef HAVE_QUOTA_SUPPORT
5357 /* quota_type has been processed, we can now handle
5358 * incoming quota requests */
5359 next->md_ops->mdo_quota.mqo_notify(NULL, next);
5363 CDEBUG(D_INFO, "Unhandled notification %#x\n", ev);
5368 static int mdt_rpc_fid2path(struct mdt_thread_info *info, void *key,
5369 void *val, int vallen)
5371 struct mdt_device *mdt = mdt_dev(info->mti_exp->exp_obd->obd_lu_dev);
5372 struct getinfo_fid2path *fpout, *fpin;
5375 fpin = key + cfs_size_round(sizeof(KEY_FID2PATH));
5378 if (ptlrpc_req_need_swab(info->mti_pill->rc_req))
5379 lustre_swab_fid2path(fpin);
5381 memcpy(fpout, fpin, sizeof(*fpin));
5382 if (fpout->gf_pathlen != vallen - sizeof(*fpin))
5385 rc = mdt_fid2path(info->mti_env, mdt, fpout);
5389 static int mdt_fid2path(const struct lu_env *env, struct mdt_device *mdt,
5390 struct getinfo_fid2path *fp)
5392 struct mdt_object *obj;
5396 CDEBUG(D_IOCTL, "path get "DFID" from "LPU64" #%d\n",
5397 PFID(&fp->gf_fid), fp->gf_recno, fp->gf_linkno);
5399 if (!fid_is_sane(&fp->gf_fid))
5402 obj = mdt_object_find(env, mdt, &fp->gf_fid);
5403 if (obj == NULL || IS_ERR(obj)) {
5404 CDEBUG(D_IOCTL, "no object "DFID": %ld\n", PFID(&fp->gf_fid),
5409 rc = lu_object_exists(&obj->mot_obj.mo_lu);
5415 mdt_object_put(env, obj);
5416 CDEBUG(D_IOCTL, "nonlocal object "DFID": %d\n",
5417 PFID(&fp->gf_fid), rc);
5421 rc = mo_path(env, md_object_next(&obj->mot_obj), fp->gf_path,
5422 fp->gf_pathlen, &fp->gf_recno, &fp->gf_linkno);
5423 mdt_object_put(env, obj);
5428 static int mdt_get_info(struct mdt_thread_info *info)
5430 struct ptlrpc_request *req = mdt_info_req(info);
5438 key = req_capsule_client_get(info->mti_pill, &RMF_GETINFO_KEY);
5440 CDEBUG(D_IOCTL, "No GETINFO key");
5443 keylen = req_capsule_get_size(info->mti_pill, &RMF_GETINFO_KEY,
5446 vallen = req_capsule_client_get(info->mti_pill, &RMF_GETINFO_VALLEN);
5447 if (vallen == NULL) {
5448 CDEBUG(D_IOCTL, "Unable to get RMF_GETINFO_VALLEN buffer");
5452 req_capsule_set_size(info->mti_pill, &RMF_GETINFO_VAL, RCL_SERVER,
5454 rc = req_capsule_server_pack(info->mti_pill);
5455 valout = req_capsule_server_get(info->mti_pill, &RMF_GETINFO_VAL);
5456 if (valout == NULL) {
5457 CDEBUG(D_IOCTL, "Unable to get get-info RPC out buffer");
5461 if (KEY_IS(KEY_FID2PATH))
5462 rc = mdt_rpc_fid2path(info, key, valout, *vallen);
5466 lustre_msg_set_status(req->rq_repmsg, rc);
5471 /* Pass the ioc down */
5472 static int mdt_ioc_child(struct lu_env *env, struct mdt_device *mdt,
5473 unsigned int cmd, int len, void *data)
5475 struct lu_context ioctl_session;
5476 struct md_device *next = mdt->mdt_child;
5480 rc = lu_context_init(&ioctl_session, LCT_SESSION);
5483 ioctl_session.lc_thread = (struct ptlrpc_thread *)cfs_current();
5484 lu_context_enter(&ioctl_session);
5485 env->le_ses = &ioctl_session;
5487 LASSERT(next->md_ops->mdo_iocontrol);
5488 rc = next->md_ops->mdo_iocontrol(env, next, cmd, len, data);
5490 lu_context_exit(&ioctl_session);
5491 lu_context_fini(&ioctl_session);
5495 static int mdt_ioc_version_get(struct mdt_thread_info *mti, void *karg)
5497 struct obd_ioctl_data *data = karg;
5498 struct lu_fid *fid = (struct lu_fid *)data->ioc_inlbuf1;
5500 struct mdt_object *obj;
5501 struct mdt_lock_handle *lh;
5505 CDEBUG(D_IOCTL, "getting version for "DFID"\n", PFID(fid));
5506 if (!fid_is_sane(fid))
5509 lh = &mti->mti_lh[MDT_LH_PARENT];
5510 mdt_lock_reg_init(lh, LCK_CR);
5512 obj = mdt_object_find_lock(mti, fid, lh, MDS_INODELOCK_UPDATE);
5514 RETURN(PTR_ERR(obj));
5516 rc = mdt_object_exists(obj);
5520 * before calling version get the correct MDS should be
5521 * fid, this is error to find remote object here
5523 CERROR("nonlocal object "DFID"\n", PFID(fid));
5524 } else if (rc == 0) {
5525 *(__u64 *)data->ioc_inlbuf2 = ENOENT_VERSION;
5528 version = dt_version_get(mti->mti_env, mdt_obj2dt(obj));
5529 *(__u64 *)data->ioc_inlbuf2 = version;
5532 mdt_object_unlock_put(mti, obj, lh, 1);
5536 /* ioctls on obd dev */
5537 static int mdt_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
5538 void *karg, void *uarg)
5541 struct obd_device *obd = exp->exp_obd;
5542 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
5543 struct dt_device *dt = mdt->mdt_bottom;
5547 CDEBUG(D_IOCTL, "handling ioctl cmd %#x\n", cmd);
5548 rc = lu_env_init(&env, LCT_MD_THREAD);
5554 rc = mdt_device_sync(&env, mdt);
5556 case OBD_IOC_SET_READONLY:
5557 rc = dt->dd_ops->dt_ro(&env, dt);
5559 case OBD_IOC_ABORT_RECOVERY:
5560 CERROR("Aborting recovery for device %s\n", obd->obd_name);
5561 target_stop_recovery_thread(obd);
5564 case OBD_IOC_CHANGELOG_REG:
5565 case OBD_IOC_CHANGELOG_DEREG:
5566 case OBD_IOC_CHANGELOG_CLEAR:
5567 rc = mdt_ioc_child(&env, mdt, cmd, len, karg);
5569 case OBD_IOC_GET_OBJ_VERSION: {
5570 struct mdt_thread_info *mti;
5571 mti = lu_context_key_get(&env.le_ctx, &mdt_thread_key);
5572 memset(mti, 0, sizeof *mti);
5573 mti->mti_env = &env;
5577 rc = mdt_ioc_version_get(mti, karg);
5581 CERROR("Not supported cmd = %d for device %s\n",
5582 cmd, obd->obd_name);
5590 int mdt_postrecov(const struct lu_env *env, struct mdt_device *mdt)
5592 struct lu_device *ld = md2lu_dev(mdt->mdt_child);
5593 #ifdef HAVE_QUOTA_SUPPORT
5594 struct obd_device *obd = mdt2obd_dev(mdt);
5595 struct md_device *next = mdt->mdt_child;
5600 rc = ld->ld_ops->ldo_recovery_complete(env, ld);
5601 #ifdef HAVE_QUOTA_SUPPORT
5602 if (likely(obd->obd_stopping == 0))
5603 next->md_ops->mdo_quota.mqo_recovery(env, next);
5608 int mdt_obd_postrecov(struct obd_device *obd)
5613 rc = lu_env_init(&env, LCT_MD_THREAD);
5616 rc = mdt_postrecov(&env, mdt_dev(obd->obd_lu_dev));
5622 * Send a copytool req to a client
5623 * Note this sends a request RPC from a server (MDT) to a client (MDC),
5624 * backwards of normal comms.
5626 int mdt_hsm_copytool_send(struct obd_export *exp)
5629 struct hsm_action_list *hal;
5630 struct hsm_action_item *hai;
5634 CWARN("%s: writing to mdc at %s\n", exp->exp_obd->obd_name,
5635 libcfs_nid2str(exp->exp_connection->c_peer.nid));
5637 len = sizeof(*lh) + sizeof(*hal) + MTI_NAME_MAXLEN +
5638 /* for mockup below */ 2 * cfs_size_round(sizeof(*hai));
5643 lh->kuc_magic = KUC_MAGIC;
5644 lh->kuc_transport = KUC_TRANSPORT_HSM;
5645 lh->kuc_msgtype = HMT_ACTION_LIST;
5646 lh->kuc_msglen = len;
5648 hal = (struct hsm_action_list *)(lh + 1);
5649 hal->hal_version = HAL_VERSION;
5650 hal->hal_archive_num = 1;
5651 obd_uuid2fsname(hal->hal_fsname, exp->exp_obd->obd_name,
5654 /* mock up an action list */
5656 hai = hai_zero(hal);
5657 hai->hai_action = HSMA_ARCHIVE;
5658 hai->hai_fid.f_oid = 0xA00A;
5659 hai->hai_len = sizeof(*hai);
5660 hai = hai_next(hai);
5661 hai->hai_action = HSMA_RESTORE;
5662 hai->hai_fid.f_oid = 0xB00B;
5663 hai->hai_len = sizeof(*hai);
5665 /* Uses the ldlm reverse import; this rpc will be seen by
5666 the ldlm_callback_handler */
5667 rc = do_set_info_async(exp->exp_imp_reverse,
5668 LDLM_SET_INFO, LUSTRE_OBD_VERSION,
5669 sizeof(KEY_HSM_COPYTOOL_SEND),
5670 KEY_HSM_COPYTOOL_SEND,
5678 static struct obd_ops mdt_obd_device_ops = {
5679 .o_owner = THIS_MODULE,
5680 .o_set_info_async = mdt_obd_set_info_async,
5681 .o_connect = mdt_obd_connect,
5682 .o_reconnect = mdt_obd_reconnect,
5683 .o_disconnect = mdt_obd_disconnect,
5684 .o_init_export = mdt_init_export,
5685 .o_destroy_export = mdt_destroy_export,
5686 .o_iocontrol = mdt_iocontrol,
5687 .o_postrecov = mdt_obd_postrecov,
5688 .o_notify = mdt_obd_notify
5691 static struct lu_device* mdt_device_fini(const struct lu_env *env,
5692 struct lu_device *d)
5694 struct mdt_device *m = mdt_dev(d);
5701 static struct lu_device *mdt_device_free(const struct lu_env *env,
5702 struct lu_device *d)
5704 struct mdt_device *m = mdt_dev(d);
5707 md_device_fini(&m->mdt_md_dev);
5712 static struct lu_device *mdt_device_alloc(const struct lu_env *env,
5713 struct lu_device_type *t,
5714 struct lustre_cfg *cfg)
5716 struct lu_device *l;
5717 struct mdt_device *m;
5723 l = &m->mdt_md_dev.md_lu_dev;
5724 rc = mdt_init0(env, m, t, cfg);
5726 mdt_device_free(env, l);
5730 md_upcall_init(&m->mdt_md_dev, mdt_upcall);
5732 l = ERR_PTR(-ENOMEM);
5736 /* context key constructor/destructor: mdt_key_init, mdt_key_fini */
5737 LU_KEY_INIT_FINI(mdt, struct mdt_thread_info);
5739 /* context key: mdt_thread_key */
5740 LU_CONTEXT_KEY_DEFINE(mdt, LCT_MD_THREAD);
5742 struct md_ucred *mdt_ucred(const struct mdt_thread_info *info)
5744 return md_ucred(info->mti_env);
5748 * Enable/disable COS (Commit On Sharing).
5750 * Set/Clear the COS flag in mdt options.
5752 * \param mdt mdt device
5753 * \param val 0 disables COS, other values enable COS
5755 void mdt_enable_cos(struct mdt_device *mdt, int val)
5760 mdt->mdt_opts.mo_cos = !!val;
5761 rc = lu_env_init(&env, LCT_MD_THREAD);
5762 if (unlikely(rc != 0)) {
5763 CWARN("lu_env initialization failed with rc = %d,"
5764 "cannot sync\n", rc);
5767 mdt_device_sync(&env, mdt);
5772 * Check COS (Commit On Sharing) status.
5774 * Return COS flag status.
5776 * \param mdt mdt device
5778 int mdt_cos_is_enabled(struct mdt_device *mdt)
5780 return mdt->mdt_opts.mo_cos != 0;
5783 /* type constructor/destructor: mdt_type_init, mdt_type_fini */
5784 LU_TYPE_INIT_FINI(mdt, &mdt_thread_key);
5786 static struct lu_device_type_operations mdt_device_type_ops = {
5787 .ldto_init = mdt_type_init,
5788 .ldto_fini = mdt_type_fini,
5790 .ldto_start = mdt_type_start,
5791 .ldto_stop = mdt_type_stop,
5793 .ldto_device_alloc = mdt_device_alloc,
5794 .ldto_device_free = mdt_device_free,
5795 .ldto_device_fini = mdt_device_fini
5798 static struct lu_device_type mdt_device_type = {
5799 .ldt_tags = LU_DEVICE_MD,
5800 .ldt_name = LUSTRE_MDT_NAME,
5801 .ldt_ops = &mdt_device_type_ops,
5802 .ldt_ctx_tags = LCT_MD_THREAD
5805 static struct lu_local_obj_desc mdt_last_recv = {
5806 .llod_name = LAST_RCVD,
5807 .llod_oid = MDT_LAST_RECV_OID,
5811 static int __init mdt_mod_init(void)
5813 struct lprocfs_static_vars lvars;
5816 llo_local_obj_register(&mdt_last_recv);
5818 if (mdt_num_threads > 0) {
5819 if (mdt_num_threads > MDT_MAX_THREADS)
5820 mdt_num_threads = MDT_MAX_THREADS;
5821 if (mdt_num_threads < MDT_MIN_THREADS)
5822 mdt_num_threads = MDT_MIN_THREADS;
5823 mdt_max_threads = mdt_min_threads = mdt_num_threads;
5825 mdt_max_threads = MDT_MAX_THREADS;
5826 mdt_min_threads = MDT_MIN_THREADS;
5829 lprocfs_mdt_init_vars(&lvars);
5830 rc = class_register_type(&mdt_obd_device_ops, NULL,
5831 lvars.module_vars, LUSTRE_MDT_NAME,
5837 static void __exit mdt_mod_exit(void)
5839 llo_local_obj_unregister(&mdt_last_recv);
5840 class_unregister_type(LUSTRE_MDT_NAME);
5844 #define DEF_HNDL(prefix, base, suffix, flags, opc, fn, fmt) \
5845 [prefix ## _ ## opc - prefix ## _ ## base] = { \
5847 .mh_fail_id = OBD_FAIL_ ## prefix ## _ ## opc ## suffix, \
5848 .mh_opc = prefix ## _ ## opc, \
5849 .mh_flags = flags, \
5854 #define DEF_MDT_HNDL(flags, name, fn, fmt) \
5855 DEF_HNDL(MDS, GETATTR, _NET, flags, name, fn, fmt)
5857 #define DEF_SEQ_HNDL(flags, name, fn, fmt) \
5858 DEF_HNDL(SEQ, QUERY, _NET, flags, name, fn, fmt)
5860 #define DEF_FLD_HNDL(flags, name, fn, fmt) \
5861 DEF_HNDL(FLD, QUERY, _NET, flags, name, fn, fmt)
5863 * Request with a format known in advance
5865 #define DEF_MDT_HNDL_F(flags, name, fn) \
5866 DEF_HNDL(MDS, GETATTR, _NET, flags, name, fn, &RQF_MDS_ ## name)
5868 #define DEF_SEQ_HNDL_F(flags, name, fn) \
5869 DEF_HNDL(SEQ, QUERY, _NET, flags, name, fn, &RQF_SEQ_ ## name)
5871 #define DEF_FLD_HNDL_F(flags, name, fn) \
5872 DEF_HNDL(FLD, QUERY, _NET, flags, name, fn, &RQF_FLD_ ## name)
5874 * Request with a format we do not yet know
5876 #define DEF_MDT_HNDL_0(flags, name, fn) \
5877 DEF_HNDL(MDS, GETATTR, _NET, flags, name, fn, NULL)
5879 static struct mdt_handler mdt_mds_ops[] = {
5880 DEF_MDT_HNDL_F(0, CONNECT, mdt_connect),
5881 DEF_MDT_HNDL_F(0, DISCONNECT, mdt_disconnect),
5882 DEF_MDT_HNDL (0, SET_INFO, mdt_set_info,
5884 DEF_MDT_HNDL_F(0, GET_INFO, mdt_get_info),
5885 DEF_MDT_HNDL_F(0 |HABEO_REFERO, GETSTATUS, mdt_getstatus),
5886 DEF_MDT_HNDL_F(HABEO_CORPUS, GETATTR, mdt_getattr),
5887 DEF_MDT_HNDL_F(HABEO_CORPUS|HABEO_REFERO, GETATTR_NAME, mdt_getattr_name),
5888 DEF_MDT_HNDL_F(HABEO_CORPUS, GETXATTR, mdt_getxattr),
5889 DEF_MDT_HNDL_F(0 |HABEO_REFERO, STATFS, mdt_statfs),
5890 DEF_MDT_HNDL_F(0 |MUTABOR, REINT, mdt_reint),
5891 DEF_MDT_HNDL_F(HABEO_CORPUS, CLOSE, mdt_close),
5892 DEF_MDT_HNDL_F(HABEO_CORPUS, DONE_WRITING, mdt_done_writing),
5893 DEF_MDT_HNDL_F(0 |HABEO_REFERO, PIN, mdt_pin),
5894 DEF_MDT_HNDL_0(0, SYNC, mdt_sync),
5895 DEF_MDT_HNDL_F(HABEO_CORPUS|HABEO_REFERO, IS_SUBDIR, mdt_is_subdir),
5896 #ifdef HAVE_QUOTA_SUPPORT
5897 DEF_MDT_HNDL_F(0, QUOTACHECK, mdt_quotacheck_handle),
5898 DEF_MDT_HNDL_F(0, QUOTACTL, mdt_quotactl_handle)
5902 #define DEF_OBD_HNDL(flags, name, fn) \
5903 DEF_HNDL(OBD, PING, _NET, flags, name, fn, NULL)
5906 static struct mdt_handler mdt_obd_ops[] = {
5907 DEF_OBD_HNDL(0, PING, mdt_obd_ping),
5908 DEF_OBD_HNDL(0, LOG_CANCEL, mdt_obd_log_cancel),
5909 DEF_OBD_HNDL(0, QC_CALLBACK, mdt_obd_qc_callback)
5912 #define DEF_DLM_HNDL_0(flags, name, fn) \
5913 DEF_HNDL(LDLM, ENQUEUE, , flags, name, fn, NULL)
5914 #define DEF_DLM_HNDL_F(flags, name, fn) \
5915 DEF_HNDL(LDLM, ENQUEUE, , flags, name, fn, &RQF_LDLM_ ## name)
5917 static struct mdt_handler mdt_dlm_ops[] = {
5918 DEF_DLM_HNDL_F(HABEO_CLAVIS, ENQUEUE, mdt_enqueue),
5919 DEF_DLM_HNDL_0(HABEO_CLAVIS, CONVERT, mdt_convert),
5920 DEF_DLM_HNDL_0(0, BL_CALLBACK, mdt_bl_callback),
5921 DEF_DLM_HNDL_0(0, CP_CALLBACK, mdt_cp_callback)
5924 #define DEF_LLOG_HNDL(flags, name, fn) \
5925 DEF_HNDL(LLOG, ORIGIN_HANDLE_CREATE, _NET, flags, name, fn, NULL)
5927 static struct mdt_handler mdt_llog_ops[] = {
5928 DEF_LLOG_HNDL(0, ORIGIN_HANDLE_CREATE, mdt_llog_create),
5929 DEF_LLOG_HNDL(0, ORIGIN_HANDLE_NEXT_BLOCK, mdt_llog_next_block),
5930 DEF_LLOG_HNDL(0, ORIGIN_HANDLE_READ_HEADER, mdt_llog_read_header),
5931 DEF_LLOG_HNDL(0, ORIGIN_HANDLE_WRITE_REC, NULL),
5932 DEF_LLOG_HNDL(0, ORIGIN_HANDLE_CLOSE, NULL),
5933 DEF_LLOG_HNDL(0, ORIGIN_CONNECT, NULL),
5934 DEF_LLOG_HNDL(0, CATINFO, NULL),
5935 DEF_LLOG_HNDL(0, ORIGIN_HANDLE_PREV_BLOCK, mdt_llog_prev_block),
5936 DEF_LLOG_HNDL(0, ORIGIN_HANDLE_DESTROY, mdt_llog_destroy),
5939 #define DEF_SEC_CTX_HNDL(name, fn) \
5940 DEF_HNDL(SEC_CTX, INIT, _NET, 0, name, fn, NULL)
5942 static struct mdt_handler mdt_sec_ctx_ops[] = {
5943 DEF_SEC_CTX_HNDL(INIT, mdt_sec_ctx_handle),
5944 DEF_SEC_CTX_HNDL(INIT_CONT, mdt_sec_ctx_handle),
5945 DEF_SEC_CTX_HNDL(FINI, mdt_sec_ctx_handle)
5948 static struct mdt_opc_slice mdt_regular_handlers[] = {
5950 .mos_opc_start = MDS_GETATTR,
5951 .mos_opc_end = MDS_LAST_OPC,
5952 .mos_hs = mdt_mds_ops
5955 .mos_opc_start = OBD_PING,
5956 .mos_opc_end = OBD_LAST_OPC,
5957 .mos_hs = mdt_obd_ops
5960 .mos_opc_start = LDLM_ENQUEUE,
5961 .mos_opc_end = LDLM_LAST_OPC,
5962 .mos_hs = mdt_dlm_ops
5965 .mos_opc_start = LLOG_ORIGIN_HANDLE_CREATE,
5966 .mos_opc_end = LLOG_LAST_OPC,
5967 .mos_hs = mdt_llog_ops
5970 .mos_opc_start = SEC_CTX_INIT,
5971 .mos_opc_end = SEC_LAST_OPC,
5972 .mos_hs = mdt_sec_ctx_ops
5979 static struct mdt_handler mdt_readpage_ops[] = {
5980 DEF_MDT_HNDL_F(0, CONNECT, mdt_connect),
5981 DEF_MDT_HNDL_F(HABEO_CORPUS|HABEO_REFERO, READPAGE, mdt_readpage),
5982 #ifdef HAVE_SPLIT_SUPPORT
5983 DEF_MDT_HNDL_F(HABEO_CORPUS|HABEO_REFERO, WRITEPAGE, mdt_writepage),
5987 * XXX: this is ugly and should be fixed one day, see mdc_close() for
5988 * detailed comments. --umka
5990 DEF_MDT_HNDL_F(HABEO_CORPUS, CLOSE, mdt_close),
5991 DEF_MDT_HNDL_F(HABEO_CORPUS, DONE_WRITING, mdt_done_writing),
5994 static struct mdt_opc_slice mdt_readpage_handlers[] = {
5996 .mos_opc_start = MDS_GETATTR,
5997 .mos_opc_end = MDS_LAST_OPC,
5998 .mos_hs = mdt_readpage_ops
6005 static struct mdt_handler mdt_xmds_ops[] = {
6006 DEF_MDT_HNDL_F(0, CONNECT, mdt_connect),
6007 DEF_MDT_HNDL_F(HABEO_CORPUS , GETATTR, mdt_getattr),
6008 DEF_MDT_HNDL_F(0 | MUTABOR , REINT, mdt_reint),
6009 DEF_MDT_HNDL_F(HABEO_CORPUS|HABEO_REFERO, IS_SUBDIR, mdt_is_subdir),
6012 static struct mdt_opc_slice mdt_xmds_handlers[] = {
6014 .mos_opc_start = MDS_GETATTR,
6015 .mos_opc_end = MDS_LAST_OPC,
6016 .mos_hs = mdt_xmds_ops
6019 .mos_opc_start = OBD_PING,
6020 .mos_opc_end = OBD_LAST_OPC,
6021 .mos_hs = mdt_obd_ops
6024 .mos_opc_start = SEC_CTX_INIT,
6025 .mos_opc_end = SEC_LAST_OPC,
6026 .mos_hs = mdt_sec_ctx_ops
6033 static struct mdt_handler mdt_seq_ops[] = {
6034 DEF_SEQ_HNDL_F(0, QUERY, (int (*)(struct mdt_thread_info *))seq_query)
6037 static struct mdt_opc_slice mdt_seq_handlers[] = {
6039 .mos_opc_start = SEQ_QUERY,
6040 .mos_opc_end = SEQ_LAST_OPC,
6041 .mos_hs = mdt_seq_ops
6048 static struct mdt_handler mdt_fld_ops[] = {
6049 DEF_FLD_HNDL_F(0, QUERY, (int (*)(struct mdt_thread_info *))fld_query)
6052 static struct mdt_opc_slice mdt_fld_handlers[] = {
6054 .mos_opc_start = FLD_QUERY,
6055 .mos_opc_end = FLD_LAST_OPC,
6056 .mos_hs = mdt_fld_ops
6063 MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");
6064 MODULE_DESCRIPTION("Lustre Meta-data Target ("LUSTRE_MDT_NAME")");
6065 MODULE_LICENSE("GPL");
6067 CFS_MODULE_PARM(mdt_num_threads, "ul", ulong, 0444,
6068 "number of mdt service threads to start");
6070 cfs_module(mdt, "0.2.0", mdt_mod_init, mdt_mod_exit);