4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
27 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2011, 2012, Whamcloud, Inc.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * lustre/mdt/mdt_handler.c
38 * Lustre Metadata Target (mdt) request handler
40 * Author: Peter Braam <braam@clusterfs.com>
41 * Author: Andreas Dilger <adilger@clusterfs.com>
42 * Author: Phil Schwan <phil@clusterfs.com>
43 * Author: Mike Shaver <shaver@clusterfs.com>
44 * Author: Nikita Danilov <nikita@clusterfs.com>
45 * Author: Huang Hua <huanghua@clusterfs.com>
46 * Author: Yury Umanets <umka@clusterfs.com>
49 #define DEBUG_SUBSYSTEM S_MDS
51 #include <linux/module.h>
53 * struct OBD_{ALLOC,FREE}*()
55 #include <obd_support.h>
56 /* struct ptlrpc_request */
57 #include <lustre_net.h>
58 /* struct obd_export */
59 #include <lustre_export.h>
60 /* struct obd_device */
63 #include <dt_object.h>
64 #include <lustre_mds.h>
65 #include <lustre_mdt.h>
66 #include "mdt_internal.h"
67 #ifdef HAVE_QUOTA_SUPPORT
68 # include <lustre_quota.h>
70 #include <lustre_acl.h>
71 #include <lustre_param.h>
72 #include <lustre_fsfilt.h>
74 mdl_mode_t mdt_mdl_lock_modes[] = {
75 [LCK_MINMODE] = MDL_MINMODE,
82 [LCK_GROUP] = MDL_GROUP
85 ldlm_mode_t mdt_dlm_lock_modes[] = {
86 [MDL_MINMODE] = LCK_MINMODE,
93 [MDL_GROUP] = LCK_GROUP
97 * Initialized in mdt_mod_init().
99 static unsigned long mdt_num_threads;
101 /* ptlrpc request handler for MDT. All handlers are
102 * grouped into several slices - struct mdt_opc_slice,
103 * and stored in an array - mdt_handlers[].
106 /* The name of this handler. */
108 /* Fail id for this handler, checked at the beginning of this handler*/
110 /* Operation code for this handler */
112 /* flags are listed in enum mdt_handler_flags below. */
114 /* The actual handler function to execute. */
115 int (*mh_act)(struct mdt_thread_info *info);
116 /* Request format for this request. */
117 const struct req_format *mh_fmt;
120 enum mdt_handler_flags {
122 * struct mdt_body is passed in the incoming message, and object
123 * identified by this fid exists on disk.
125 * "habeo corpus" == "I have a body"
127 HABEO_CORPUS = (1 << 0),
129 * struct ldlm_request is passed in the incoming message.
131 * "habeo clavis" == "I have a key"
133 HABEO_CLAVIS = (1 << 1),
135 * this request has fixed reply format, so that reply message can be
136 * packed by generic code.
138 * "habeo refero" == "I have a reply"
140 HABEO_REFERO = (1 << 2),
142 * this request will modify something, so check whether the filesystem
143 * is readonly or not, then return -EROFS to client asap if necessary.
145 * "mutabor" == "I shall modify"
150 struct mdt_opc_slice {
153 struct mdt_handler *mos_hs;
156 static struct mdt_opc_slice mdt_regular_handlers[];
157 static struct mdt_opc_slice mdt_readpage_handlers[];
158 static struct mdt_opc_slice mdt_xmds_handlers[];
159 static struct mdt_opc_slice mdt_seq_handlers[];
160 static struct mdt_opc_slice mdt_fld_handlers[];
162 static struct mdt_device *mdt_dev(struct lu_device *d);
163 static int mdt_regular_handle(struct ptlrpc_request *req);
164 static int mdt_unpack_req_pack_rep(struct mdt_thread_info *info, __u32 flags);
165 static int mdt_fid2path(const struct lu_env *env, struct mdt_device *mdt,
166 struct getinfo_fid2path *fp);
168 static const struct lu_object_operations mdt_obj_ops;
170 int mdt_get_disposition(struct ldlm_reply *rep, int flag)
174 return (rep->lock_policy_res1 & flag);
177 void mdt_clear_disposition(struct mdt_thread_info *info,
178 struct ldlm_reply *rep, int flag)
181 info->mti_opdata &= ~flag;
183 rep->lock_policy_res1 &= ~flag;
186 void mdt_set_disposition(struct mdt_thread_info *info,
187 struct ldlm_reply *rep, int flag)
190 info->mti_opdata |= flag;
192 rep->lock_policy_res1 |= flag;
195 void mdt_lock_reg_init(struct mdt_lock_handle *lh, ldlm_mode_t lm)
197 lh->mlh_pdo_hash = 0;
198 lh->mlh_reg_mode = lm;
199 lh->mlh_type = MDT_REG_LOCK;
202 void mdt_lock_pdo_init(struct mdt_lock_handle *lh, ldlm_mode_t lm,
203 const char *name, int namelen)
205 lh->mlh_reg_mode = lm;
206 lh->mlh_type = MDT_PDO_LOCK;
208 if (name != NULL && (name[0] != '\0')) {
209 LASSERT(namelen > 0);
210 lh->mlh_pdo_hash = full_name_hash(name, namelen);
212 LASSERT(namelen == 0);
213 lh->mlh_pdo_hash = 0ull;
217 static void mdt_lock_pdo_mode(struct mdt_thread_info *info, struct mdt_object *o,
218 struct mdt_lock_handle *lh)
224 * Any dir access needs couple of locks:
226 * 1) on part of dir we gonna take lookup/modify;
228 * 2) on whole dir to protect it from concurrent splitting and/or to
229 * flush client's cache for readdir().
231 * so, for a given mode and object this routine decides what lock mode
232 * to use for lock #2:
234 * 1) if caller's gonna lookup in dir then we need to protect dir from
235 * being splitted only - LCK_CR
237 * 2) if caller's gonna modify dir then we need to protect dir from
238 * being splitted and to flush cache - LCK_CW
240 * 3) if caller's gonna modify dir and that dir seems ready for
241 * splitting then we need to protect it from any type of access
242 * (lookup/modify/split) - LCK_EX --bzzz
245 LASSERT(lh->mlh_reg_mode != LCK_MINMODE);
246 LASSERT(lh->mlh_pdo_mode == LCK_MINMODE);
249 * Ask underlaying level its opinion about preferable PDO lock mode
250 * having access type passed as regular lock mode:
252 * - MDL_MINMODE means that lower layer does not want to specify lock
255 * - MDL_NL means that no PDO lock should be taken. This is used in some
256 * cases. Say, for non-splittable directories no need to use PDO locks
259 mode = mdo_lock_mode(info->mti_env, mdt_object_child(o),
260 mdt_dlm_mode2mdl_mode(lh->mlh_reg_mode));
262 if (mode != MDL_MINMODE) {
263 lh->mlh_pdo_mode = mdt_mdl_mode2dlm_mode(mode);
266 * Lower layer does not want to specify locking mode. We do it
267 * our selves. No special protection is needed, just flush
268 * client's cache on modification and allow concurrent
271 switch (lh->mlh_reg_mode) {
273 lh->mlh_pdo_mode = LCK_EX;
276 lh->mlh_pdo_mode = LCK_CR;
279 lh->mlh_pdo_mode = LCK_CW;
282 CERROR("Not expected lock type (0x%x)\n",
283 (int)lh->mlh_reg_mode);
288 LASSERT(lh->mlh_pdo_mode != LCK_MINMODE);
292 static int mdt_getstatus(struct mdt_thread_info *info)
294 struct mdt_device *mdt = info->mti_mdt;
295 struct md_device *next = mdt->mdt_child;
296 struct mdt_body *repbody;
301 rc = mdt_check_ucred(info);
303 RETURN(err_serious(rc));
305 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_GETSTATUS_PACK))
306 RETURN(err_serious(-ENOMEM));
308 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
309 rc = next->md_ops->mdo_root_get(info->mti_env, next, &repbody->fid1);
313 repbody->valid |= OBD_MD_FLID;
315 if (mdt->mdt_opts.mo_mds_capa &&
316 info->mti_exp->exp_connect_flags & OBD_CONNECT_MDS_CAPA) {
317 struct mdt_object *root;
318 struct lustre_capa *capa;
320 root = mdt_object_find(info->mti_env, mdt, &repbody->fid1);
322 RETURN(PTR_ERR(root));
324 capa = req_capsule_server_get(info->mti_pill, &RMF_CAPA1);
326 capa->lc_opc = CAPA_OPC_MDS_DEFAULT;
327 rc = mo_capa_get(info->mti_env, mdt_object_child(root), capa,
329 mdt_object_put(info->mti_env, root);
331 repbody->valid |= OBD_MD_FLMDSCAPA;
337 static int mdt_statfs(struct mdt_thread_info *info)
339 struct ptlrpc_request *req = mdt_info_req(info);
340 struct md_device *next = info->mti_mdt->mdt_child;
341 struct ptlrpc_service *svc;
342 struct obd_statfs *osfs;
347 svc = info->mti_pill->rc_req->rq_rqbd->rqbd_service;
349 /* This will trigger a watchdog timeout */
350 OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_STATFS_LCW_SLEEP,
351 (MDT_SERVICE_WATCHDOG_FACTOR *
352 at_get(&svc->srv_at_estimate)) + 1);
354 rc = mdt_check_ucred(info);
356 RETURN(err_serious(rc));
358 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_STATFS_PACK)) {
359 rc = err_serious(-ENOMEM);
361 osfs = req_capsule_server_get(info->mti_pill, &RMF_OBD_STATFS);
362 rc = next->md_ops->mdo_statfs(info->mti_env, next, osfs);
366 mdt_counter_incr(req, LPROC_MDT_STATFS);
372 * Pack SOM attributes into the reply.
373 * Call under a DLM UPDATE lock.
375 static void mdt_pack_size2body(struct mdt_thread_info *info,
376 struct mdt_object *mo)
379 struct md_attr *ma = &info->mti_attr;
381 LASSERT(ma->ma_attr.la_valid & LA_MODE);
382 b = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
384 /* Check if Size-on-MDS is supported, if this is a regular file,
385 * if SOM is enabled on the object and if SOM cache exists and valid.
386 * Otherwise do not pack Size-on-MDS attributes to the reply. */
387 if (!(mdt_conn_flags(info) & OBD_CONNECT_SOM) ||
388 !S_ISREG(ma->ma_attr.la_mode) ||
389 !mdt_object_is_som_enabled(mo) ||
390 !(ma->ma_valid & MA_SOM))
393 b->valid |= OBD_MD_FLSIZE | OBD_MD_FLBLOCKS;
394 b->size = ma->ma_som->msd_size;
395 b->blocks = ma->ma_som->msd_blocks;
398 void mdt_pack_attr2body(struct mdt_thread_info *info, struct mdt_body *b,
399 const struct lu_attr *attr, const struct lu_fid *fid)
401 struct md_attr *ma = &info->mti_attr;
403 LASSERT(ma->ma_valid & MA_INODE);
405 b->atime = attr->la_atime;
406 b->mtime = attr->la_mtime;
407 b->ctime = attr->la_ctime;
408 b->mode = attr->la_mode;
409 b->size = attr->la_size;
410 b->blocks = attr->la_blocks;
411 b->uid = attr->la_uid;
412 b->gid = attr->la_gid;
413 b->flags = attr->la_flags;
414 b->nlink = attr->la_nlink;
415 b->rdev = attr->la_rdev;
417 /*XXX should pack the reply body according to lu_valid*/
418 b->valid |= OBD_MD_FLCTIME | OBD_MD_FLUID |
419 OBD_MD_FLGID | OBD_MD_FLTYPE |
420 OBD_MD_FLMODE | OBD_MD_FLNLINK | OBD_MD_FLFLAGS |
421 OBD_MD_FLATIME | OBD_MD_FLMTIME ;
423 if (!S_ISREG(attr->la_mode)) {
424 b->valid |= OBD_MD_FLSIZE | OBD_MD_FLBLOCKS | OBD_MD_FLRDEV;
425 } else if (ma->ma_need & MA_LOV && ma->ma_lmm_size == 0) {
426 /* means no objects are allocated on osts. */
427 LASSERT(!(ma->ma_valid & MA_LOV));
428 /* just ignore blocks occupied by extend attributes on MDS */
430 /* if no object is allocated on osts, the size on mds is valid. b=22272 */
431 b->valid |= OBD_MD_FLSIZE | OBD_MD_FLBLOCKS;
436 b->valid |= OBD_MD_FLID;
438 /* FIXME: these should be fixed when new igif ready.*/
439 b->ino = fid_oid(fid); /* 1.6 compatibility */
440 b->generation = fid_ver(fid); /* 1.6 compatibility */
441 b->valid |= OBD_MD_FLGENER; /* 1.6 compatibility */
443 CDEBUG(D_INODE, DFID": nlink=%d, mode=%o, size="LPU64"\n",
444 PFID(fid), b->nlink, b->mode, b->size);
448 mdt_body_reverse_idmap(info, b);
450 if (b->valid & OBD_MD_FLSIZE)
451 CDEBUG(D_VFSTRACE, DFID": returning size %llu\n",
452 PFID(fid), (unsigned long long)b->size);
455 static inline int mdt_body_has_lov(const struct lu_attr *la,
456 const struct mdt_body *body)
458 return ((S_ISREG(la->la_mode) && (body->valid & OBD_MD_FLEASIZE)) ||
459 (S_ISDIR(la->la_mode) && (body->valid & OBD_MD_FLDIREA )) );
462 void mdt_client_compatibility(struct mdt_thread_info *info)
464 struct mdt_body *body;
465 struct ptlrpc_request *req = mdt_info_req(info);
466 struct obd_export *exp = req->rq_export;
467 struct md_attr *ma = &info->mti_attr;
468 struct lu_attr *la = &ma->ma_attr;
471 if (exp->exp_connect_flags & OBD_CONNECT_LAYOUTLOCK)
472 /* the client can deal with 16-bit lmm_stripe_count */
475 body = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
477 if (!mdt_body_has_lov(la, body))
480 /* now we have a reply with a lov for a client not compatible with the
481 * layout lock so we have to clean the layout generation number */
482 if (S_ISREG(la->la_mode))
483 ma->ma_lmm->lmm_layout_gen = 0;
488 static int mdt_getattr_internal(struct mdt_thread_info *info,
489 struct mdt_object *o, int ma_need)
491 struct md_object *next = mdt_object_child(o);
492 const struct mdt_body *reqbody = info->mti_body;
493 struct ptlrpc_request *req = mdt_info_req(info);
494 struct md_attr *ma = &info->mti_attr;
495 struct lu_attr *la = &ma->ma_attr;
496 struct req_capsule *pill = info->mti_pill;
497 const struct lu_env *env = info->mti_env;
498 struct mdt_body *repbody;
499 struct lu_buf *buffer = &info->mti_buf;
503 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_GETATTR_PACK))
504 RETURN(err_serious(-ENOMEM));
506 repbody = req_capsule_server_get(pill, &RMF_MDT_BODY);
510 rc = mdt_object_exists(o);
512 /* This object is located on remote node.*/
513 repbody->fid1 = *mdt_object_fid(o);
514 repbody->valid = OBD_MD_FLID | OBD_MD_MDS;
518 buffer->lb_buf = req_capsule_server_get(pill, &RMF_MDT_MD);
519 buffer->lb_len = req_capsule_get_size(pill, &RMF_MDT_MD, RCL_SERVER);
521 /* If it is dir object and client require MEA, then we got MEA */
522 if (S_ISDIR(lu_object_attr(&next->mo_lu)) &&
523 reqbody->valid & OBD_MD_MEA) {
524 /* Assumption: MDT_MD size is enough for lmv size. */
525 ma->ma_lmv = buffer->lb_buf;
526 ma->ma_lmv_size = buffer->lb_len;
527 ma->ma_need = MA_LMV | MA_INODE;
529 ma->ma_lmm = buffer->lb_buf;
530 ma->ma_lmm_size = buffer->lb_len;
531 ma->ma_need = MA_LOV | MA_INODE;
534 if (S_ISDIR(lu_object_attr(&next->mo_lu)) &&
535 reqbody->valid & OBD_MD_FLDIREA &&
536 lustre_msg_get_opc(req->rq_reqmsg) == MDS_GETATTR) {
537 /* get default stripe info for this dir. */
538 ma->ma_need |= MA_LOV_DEF;
540 ma->ma_need |= ma_need;
541 if (ma->ma_need & MA_SOM)
542 ma->ma_som = &info->mti_u.som.data;
544 rc = mo_attr_get(env, next, ma);
546 CERROR("getattr error for "DFID": %d\n",
547 PFID(mdt_object_fid(o)), rc);
551 if (likely(ma->ma_valid & MA_INODE))
552 mdt_pack_attr2body(info, repbody, la, mdt_object_fid(o));
556 if (mdt_body_has_lov(la, reqbody)) {
557 if (ma->ma_valid & MA_LOV) {
558 LASSERT(ma->ma_lmm_size);
559 mdt_dump_lmm(D_INFO, ma->ma_lmm);
560 repbody->eadatasize = ma->ma_lmm_size;
561 if (S_ISDIR(la->la_mode))
562 repbody->valid |= OBD_MD_FLDIREA;
564 repbody->valid |= OBD_MD_FLEASIZE;
566 if (ma->ma_valid & MA_LMV) {
567 LASSERT(S_ISDIR(la->la_mode));
568 repbody->eadatasize = ma->ma_lmv_size;
569 repbody->valid |= (OBD_MD_FLDIREA|OBD_MD_MEA);
571 } else if (S_ISLNK(la->la_mode) &&
572 reqbody->valid & OBD_MD_LINKNAME) {
573 buffer->lb_buf = ma->ma_lmm;
574 /* eadatasize from client includes NULL-terminator, so
575 * there is no need to read it */
576 buffer->lb_len = reqbody->eadatasize - 1;
577 rc = mo_readlink(env, next, buffer);
578 if (unlikely(rc <= 0)) {
579 CERROR("readlink failed: %d\n", rc);
582 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_READLINK_EPROTO))
584 repbody->valid |= OBD_MD_LINKNAME;
585 /* we need to report back size with NULL-terminator
586 * because client expects that */
587 repbody->eadatasize = rc + 1;
588 if (repbody->eadatasize != reqbody->eadatasize)
589 CERROR("Read shorter link %d than expected "
590 "%d\n", rc, reqbody->eadatasize - 1);
592 ((char*)ma->ma_lmm)[rc] = 0;
593 CDEBUG(D_INODE, "symlink dest %s, len = %d\n",
594 (char*)ma->ma_lmm, rc);
599 if (reqbody->valid & OBD_MD_FLMODEASIZE) {
600 repbody->max_cookiesize = info->mti_mdt->mdt_max_cookiesize;
601 repbody->max_mdsize = info->mti_mdt->mdt_max_mdsize;
602 repbody->valid |= OBD_MD_FLMODEASIZE;
603 CDEBUG(D_INODE, "I am going to change the MAX_MD_SIZE & "
604 "MAX_COOKIE to : %d:%d\n", repbody->max_mdsize,
605 repbody->max_cookiesize);
608 if (exp_connect_rmtclient(info->mti_exp) &&
609 reqbody->valid & OBD_MD_FLRMTPERM) {
610 void *buf = req_capsule_server_get(pill, &RMF_ACL);
612 /* mdt_getattr_lock only */
613 rc = mdt_pack_remote_perm(info, o, buf);
615 repbody->valid &= ~OBD_MD_FLRMTPERM;
616 repbody->aclsize = 0;
619 repbody->valid |= OBD_MD_FLRMTPERM;
620 repbody->aclsize = sizeof(struct mdt_remote_perm);
623 #ifdef CONFIG_FS_POSIX_ACL
624 else if ((req->rq_export->exp_connect_flags & OBD_CONNECT_ACL) &&
625 (reqbody->valid & OBD_MD_FLACL)) {
626 buffer->lb_buf = req_capsule_server_get(pill, &RMF_ACL);
627 buffer->lb_len = req_capsule_get_size(pill,
628 &RMF_ACL, RCL_SERVER);
629 if (buffer->lb_len > 0) {
630 rc = mo_xattr_get(env, next, buffer,
631 XATTR_NAME_ACL_ACCESS);
633 if (rc == -ENODATA) {
634 repbody->aclsize = 0;
635 repbody->valid |= OBD_MD_FLACL;
637 } else if (rc == -EOPNOTSUPP) {
640 CERROR("got acl size: %d\n", rc);
643 repbody->aclsize = rc;
644 repbody->valid |= OBD_MD_FLACL;
651 if (reqbody->valid & OBD_MD_FLMDSCAPA &&
652 info->mti_mdt->mdt_opts.mo_mds_capa &&
653 info->mti_exp->exp_connect_flags & OBD_CONNECT_MDS_CAPA) {
654 struct lustre_capa *capa;
656 capa = req_capsule_server_get(pill, &RMF_CAPA1);
658 capa->lc_opc = CAPA_OPC_MDS_DEFAULT;
659 rc = mo_capa_get(env, next, capa, 0);
662 repbody->valid |= OBD_MD_FLMDSCAPA;
667 mdt_counter_incr(req, LPROC_MDT_GETATTR);
672 static int mdt_renew_capa(struct mdt_thread_info *info)
674 struct mdt_object *obj = info->mti_object;
675 struct mdt_body *body;
676 struct lustre_capa *capa, *c;
680 /* if object doesn't exist, or server has disabled capability,
681 * return directly, client will find body->valid OBD_MD_FLOSSCAPA
684 if (!obj || !info->mti_mdt->mdt_opts.mo_oss_capa ||
685 !(info->mti_exp->exp_connect_flags & OBD_CONNECT_OSS_CAPA))
688 body = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
689 LASSERT(body != NULL);
691 c = req_capsule_client_get(info->mti_pill, &RMF_CAPA1);
694 capa = req_capsule_server_get(info->mti_pill, &RMF_CAPA2);
698 rc = mo_capa_get(info->mti_env, mdt_object_child(obj), capa, 1);
700 body->valid |= OBD_MD_FLOSSCAPA;
704 static int mdt_getattr(struct mdt_thread_info *info)
706 struct mdt_object *obj = info->mti_object;
707 struct req_capsule *pill = info->mti_pill;
708 struct mdt_body *reqbody;
709 struct mdt_body *repbody;
714 reqbody = req_capsule_client_get(pill, &RMF_MDT_BODY);
717 if (reqbody->valid & OBD_MD_FLOSSCAPA) {
718 rc = req_capsule_server_pack(pill);
720 RETURN(err_serious(rc));
721 rc = mdt_renew_capa(info);
722 GOTO(out_shrink, rc);
725 LASSERT(obj != NULL);
726 LASSERT(lu_object_assert_exists(&obj->mot_obj.mo_lu));
728 mode = lu_object_attr(&obj->mot_obj.mo_lu);
730 /* old clients may not report needed easize, use max value then */
731 req_capsule_set_size(pill, &RMF_MDT_MD, RCL_SERVER,
732 reqbody->eadatasize == 0 ?
733 info->mti_mdt->mdt_max_mdsize :
734 reqbody->eadatasize);
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);
765 mdt_client_compatibility(info);
766 rc2 = mdt_fix_reply(info);
772 static int mdt_is_subdir(struct mdt_thread_info *info)
774 struct mdt_object *o = info->mti_object;
775 struct req_capsule *pill = info->mti_pill;
776 const struct mdt_body *body = info->mti_body;
777 struct mdt_body *repbody;
783 repbody = req_capsule_server_get(pill, &RMF_MDT_BODY);
786 * We save last checked parent fid to @repbody->fid1 for remote
789 LASSERT(fid_is_sane(&body->fid2));
790 LASSERT(mdt_object_exists(o) > 0);
791 rc = mdo_is_subdir(info->mti_env, mdt_object_child(o),
792 &body->fid2, &repbody->fid1);
793 if (rc == 0 || rc == -EREMOTE)
794 repbody->valid |= OBD_MD_FLID;
799 static int mdt_raw_lookup(struct mdt_thread_info *info,
800 struct mdt_object *parent,
801 const struct lu_name *lname,
802 struct ldlm_reply *ldlm_rep)
804 struct md_object *next = mdt_object_child(info->mti_object);
805 const struct mdt_body *reqbody = info->mti_body;
806 struct lu_fid *child_fid = &info->mti_tmp_fid1;
807 struct mdt_body *repbody;
811 if (reqbody->valid != OBD_MD_FLID)
814 LASSERT(!info->mti_cross_ref);
816 /* Only got the fid of this obj by name */
818 rc = mdo_lookup(info->mti_env, next, lname, child_fid,
821 /* XXX is raw_lookup possible as intent operation? */
824 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_NEG);
827 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_POS);
829 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
832 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
833 repbody->fid1 = *child_fid;
834 repbody->valid = OBD_MD_FLID;
840 * UPDATE lock should be taken against parent, and be release before exit;
841 * child_bits lock should be taken against child, and be returned back:
842 * (1)normal request should release the child lock;
843 * (2)intent request will grant the lock to client.
845 static int mdt_getattr_name_lock(struct mdt_thread_info *info,
846 struct mdt_lock_handle *lhc,
848 struct ldlm_reply *ldlm_rep)
850 struct ptlrpc_request *req = mdt_info_req(info);
851 struct mdt_body *reqbody = NULL;
852 struct mdt_object *parent = info->mti_object;
853 struct mdt_object *child;
854 struct md_object *next = mdt_object_child(parent);
855 struct lu_fid *child_fid = &info->mti_tmp_fid1;
856 struct lu_name *lname = NULL;
857 const char *name = NULL;
859 struct mdt_lock_handle *lhp = NULL;
860 struct ldlm_lock *lock;
861 struct ldlm_res_id *res_id;
868 is_resent = lustre_handle_is_used(&lhc->mlh_reg_lh);
869 LASSERT(ergo(is_resent,
870 lustre_msg_get_flags(req->rq_reqmsg) & MSG_RESENT));
872 LASSERT(parent != NULL);
873 name = req_capsule_client_get(info->mti_pill, &RMF_NAME);
875 RETURN(err_serious(-EFAULT));
877 namelen = req_capsule_get_size(info->mti_pill, &RMF_NAME,
879 if (!info->mti_cross_ref) {
881 * XXX: Check for "namelen == 0" is for getattr by fid
882 * (OBD_CONNECT_ATTRFID), otherwise do not allow empty name,
883 * that is the name must contain at least one character and
884 * the terminating '\0'
887 reqbody = req_capsule_client_get(info->mti_pill,
889 if (unlikely(reqbody == NULL))
890 RETURN(err_serious(-EFAULT));
892 if (unlikely(!fid_is_sane(&reqbody->fid2)))
893 RETURN(err_serious(-EINVAL));
896 CDEBUG(D_INODE, "getattr with lock for "DFID"/"DFID", "
898 PFID(mdt_object_fid(parent)),
899 PFID(&reqbody->fid2), ldlm_rep);
901 lname = mdt_name(info->mti_env, (char *)name, namelen);
902 CDEBUG(D_INODE, "getattr with lock for "DFID"/%s, "
903 "ldlm_rep = %p\n", PFID(mdt_object_fid(parent)),
907 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_EXECD);
909 rc = mdt_object_exists(parent);
910 if (unlikely(rc == 0)) {
911 LU_OBJECT_DEBUG(D_INODE, info->mti_env,
912 &parent->mot_obj.mo_lu,
913 "Parent doesn't exist!\n");
915 } else if (!info->mti_cross_ref) {
916 LASSERTF(rc > 0, "Parent "DFID" is on remote server\n",
917 PFID(mdt_object_fid(parent)));
920 rc = mdt_raw_lookup(info, parent, lname, ldlm_rep);
928 if (info->mti_cross_ref) {
929 /* Only getattr on the child. Parent is on another node. */
930 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_POS);
932 CDEBUG(D_INODE, "partial getattr_name child_fid = "DFID", "
933 "ldlm_rep=%p\n", PFID(mdt_object_fid(child)), ldlm_rep);
936 /* Do not take lock for resent case. */
937 lock = ldlm_handle2lock(&lhc->mlh_reg_lh);
938 LASSERTF(lock != NULL, "Invalid lock handle "LPX64"\n",
939 lhc->mlh_reg_lh.cookie);
940 LASSERT(fid_res_name_eq(mdt_object_fid(child),
941 &lock->l_resource->lr_name));
945 mdt_lock_handle_init(lhc);
946 mdt_lock_reg_init(lhc, LCK_PR);
949 * Object's name is on another MDS, no lookup lock is
950 * needed here but update is.
952 child_bits &= ~MDS_INODELOCK_LOOKUP;
953 child_bits |= MDS_INODELOCK_UPDATE;
955 rc = mdt_object_lock(info, child, lhc, child_bits,
959 /* Finally, we can get attr for child. */
960 mdt_set_capainfo(info, 0, mdt_object_fid(child),
962 rc = mdt_getattr_internal(info, child, 0);
963 if (unlikely(rc != 0))
964 mdt_object_unlock(info, child, lhc, 1);
970 /* step 1: lock parent only if parent is a directory */
971 if (S_ISDIR(lu_object_attr(&parent->mot_obj.mo_lu))) {
972 lhp = &info->mti_lh[MDT_LH_PARENT];
973 mdt_lock_pdo_init(lhp, LCK_PR, name, namelen);
974 rc = mdt_object_lock(info, parent, lhp,
975 MDS_INODELOCK_UPDATE,
977 if (unlikely(rc != 0))
981 /* step 2: lookup child's fid by name */
983 rc = mdo_lookup(info->mti_env, next, lname, child_fid,
988 mdt_set_disposition(info, ldlm_rep,
990 GOTO(out_parent, rc);
992 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_POS);
994 *child_fid = reqbody->fid2;
995 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_POS);
999 *step 3: find the child object by fid & lock it.
1000 * regardless if it is local or remote.
1002 child = mdt_object_find(info->mti_env, info->mti_mdt, child_fid);
1004 if (unlikely(IS_ERR(child)))
1005 GOTO(out_parent, rc = PTR_ERR(child));
1007 /* Do not take lock for resent case. */
1008 lock = ldlm_handle2lock(&lhc->mlh_reg_lh);
1009 LASSERTF(lock != NULL, "Invalid lock handle "LPX64"\n",
1010 lhc->mlh_reg_lh.cookie);
1012 res_id = &lock->l_resource->lr_name;
1013 if (!fid_res_name_eq(mdt_object_fid(child),
1014 &lock->l_resource->lr_name)) {
1015 LASSERTF(fid_res_name_eq(mdt_object_fid(parent),
1016 &lock->l_resource->lr_name),
1017 "Lock res_id: %lu/%lu/%lu, Fid: "DFID".\n",
1018 (unsigned long)res_id->name[0],
1019 (unsigned long)res_id->name[1],
1020 (unsigned long)res_id->name[2],
1021 PFID(mdt_object_fid(parent)));
1022 CWARN("Although resent, but still not get child lock"
1023 "parent:"DFID" child:"DFID"\n",
1024 PFID(mdt_object_fid(parent)),
1025 PFID(mdt_object_fid(child)));
1026 lustre_msg_clear_flags(req->rq_reqmsg, MSG_RESENT);
1027 LDLM_LOCK_PUT(lock);
1030 LDLM_LOCK_PUT(lock);
1034 OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_RESEND, obd_timeout*2);
1035 mdt_lock_handle_init(lhc);
1036 if (child_bits == MDS_INODELOCK_LAYOUT)
1037 mdt_lock_reg_init(lhc, LCK_CR);
1039 mdt_lock_reg_init(lhc, LCK_PR);
1041 if (mdt_object_exists(child) == 0) {
1042 LU_OBJECT_DEBUG(D_INODE, info->mti_env,
1043 &child->mot_obj.mo_lu,
1044 "Object doesn't exist!\n");
1045 GOTO(out_child, rc = -ENOENT);
1048 if (!(child_bits & MDS_INODELOCK_UPDATE)) {
1049 struct md_attr *ma = &info->mti_attr;
1052 ma->ma_need = MA_INODE;
1053 rc = mo_attr_get(info->mti_env,
1054 mdt_object_child(child), ma);
1055 if (unlikely(rc != 0))
1056 GOTO(out_child, rc);
1058 /* layout lock is used only on regular files */
1059 if ((ma->ma_valid & MA_INODE) &&
1060 (ma->ma_attr.la_valid & LA_MODE) &&
1061 !S_ISREG(ma->ma_attr.la_mode))
1062 child_bits &= ~MDS_INODELOCK_LAYOUT;
1064 /* If the file has not been changed for some time, we
1065 * return not only a LOOKUP lock, but also an UPDATE
1066 * lock and this might save us RPC on later STAT. For
1067 * directories, it also let negative dentry starts
1068 * working for this dir. */
1069 if (ma->ma_valid & MA_INODE &&
1070 ma->ma_attr.la_valid & LA_CTIME &&
1071 info->mti_mdt->mdt_namespace->ns_ctime_age_limit +
1072 ma->ma_attr.la_ctime < cfs_time_current_sec())
1073 child_bits |= MDS_INODELOCK_UPDATE;
1076 rc = mdt_object_lock(info, child, lhc, child_bits,
1079 if (unlikely(rc != 0))
1080 GOTO(out_child, rc);
1083 lock = ldlm_handle2lock(&lhc->mlh_reg_lh);
1084 /* Get MA_SOM attributes if update lock is given. */
1086 lock->l_policy_data.l_inodebits.bits & MDS_INODELOCK_UPDATE &&
1087 S_ISREG(lu_object_attr(&mdt_object_child(child)->mo_lu)))
1090 /* finally, we can get attr for child. */
1091 mdt_set_capainfo(info, 1, child_fid, BYPASS_CAPA);
1092 rc = mdt_getattr_internal(info, child, ma_need);
1093 if (unlikely(rc != 0)) {
1094 mdt_object_unlock(info, child, lhc, 1);
1096 /* Debugging code. */
1097 res_id = &lock->l_resource->lr_name;
1098 LDLM_DEBUG(lock, "Returning lock to client");
1099 LASSERTF(fid_res_name_eq(mdt_object_fid(child),
1100 &lock->l_resource->lr_name),
1101 "Lock res_id: %lu/%lu/%lu, Fid: "DFID".\n",
1102 (unsigned long)res_id->name[0],
1103 (unsigned long)res_id->name[1],
1104 (unsigned long)res_id->name[2],
1105 PFID(mdt_object_fid(child)));
1106 mdt_pack_size2body(info, child);
1109 LDLM_LOCK_PUT(lock);
1113 mdt_object_put(info->mti_env, child);
1116 mdt_object_unlock(info, parent, lhp, 1);
1120 /* normal handler: should release the child lock */
1121 static int mdt_getattr_name(struct mdt_thread_info *info)
1123 struct mdt_lock_handle *lhc = &info->mti_lh[MDT_LH_CHILD];
1124 struct mdt_body *reqbody;
1125 struct mdt_body *repbody;
1129 reqbody = req_capsule_client_get(info->mti_pill, &RMF_MDT_BODY);
1130 LASSERT(reqbody != NULL);
1131 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
1132 LASSERT(repbody != NULL);
1134 info->mti_spec.sp_ck_split = !!(reqbody->valid & OBD_MD_FLCKSPLIT);
1135 info->mti_cross_ref = !!(reqbody->valid & OBD_MD_FLCROSSREF);
1136 repbody->eadatasize = 0;
1137 repbody->aclsize = 0;
1139 rc = mdt_init_ucred(info, reqbody);
1141 GOTO(out_shrink, rc);
1143 rc = mdt_getattr_name_lock(info, lhc, MDS_INODELOCK_UPDATE, NULL);
1144 if (lustre_handle_is_used(&lhc->mlh_reg_lh)) {
1145 ldlm_lock_decref(&lhc->mlh_reg_lh, lhc->mlh_reg_mode);
1146 lhc->mlh_reg_lh.cookie = 0;
1148 mdt_exit_ucred(info);
1151 mdt_client_compatibility(info);
1152 rc2 = mdt_fix_reply(info);
1158 static const struct lu_device_operations mdt_lu_ops;
1160 static int lu_device_is_mdt(struct lu_device *d)
1162 return ergo(d != NULL && d->ld_ops != NULL, d->ld_ops == &mdt_lu_ops);
1165 static int mdt_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
1166 void *karg, void *uarg);
1168 static int mdt_set_info(struct mdt_thread_info *info)
1170 struct ptlrpc_request *req = mdt_info_req(info);
1173 int keylen, vallen, rc = 0;
1176 rc = req_capsule_server_pack(info->mti_pill);
1180 key = req_capsule_client_get(info->mti_pill, &RMF_SETINFO_KEY);
1182 DEBUG_REQ(D_HA, req, "no set_info key");
1186 keylen = req_capsule_get_size(info->mti_pill, &RMF_SETINFO_KEY,
1189 val = req_capsule_client_get(info->mti_pill, &RMF_SETINFO_VAL);
1191 DEBUG_REQ(D_HA, req, "no set_info val");
1195 vallen = req_capsule_get_size(info->mti_pill, &RMF_SETINFO_VAL,
1198 /* Swab any part of val you need to here */
1199 if (KEY_IS(KEY_READ_ONLY)) {
1201 lustre_msg_set_status(req->rq_repmsg, 0);
1203 cfs_spin_lock(&req->rq_export->exp_lock);
1205 req->rq_export->exp_connect_flags |= OBD_CONNECT_RDONLY;
1207 req->rq_export->exp_connect_flags &=~OBD_CONNECT_RDONLY;
1208 cfs_spin_unlock(&req->rq_export->exp_lock);
1210 } else if (KEY_IS(KEY_CHANGELOG_CLEAR)) {
1211 struct changelog_setinfo *cs =
1212 (struct changelog_setinfo *)val;
1213 if (vallen != sizeof(*cs)) {
1214 CERROR("Bad changelog_clear setinfo size %d\n", vallen);
1217 if (ptlrpc_req_need_swab(req)) {
1218 __swab64s(&cs->cs_recno);
1219 __swab32s(&cs->cs_id);
1222 rc = mdt_iocontrol(OBD_IOC_CHANGELOG_CLEAR, info->mti_exp,
1224 lustre_msg_set_status(req->rq_repmsg, rc);
1232 static int mdt_connect(struct mdt_thread_info *info)
1235 struct ptlrpc_request *req;
1237 req = mdt_info_req(info);
1238 rc = target_handle_connect(req);
1240 LASSERT(req->rq_export != NULL);
1241 info->mti_mdt = mdt_dev(req->rq_export->exp_obd->obd_lu_dev);
1242 rc = mdt_init_sec_level(info);
1244 rc = mdt_init_idmap(info);
1246 obd_disconnect(class_export_get(req->rq_export));
1248 rc = err_serious(rc);
1253 static int mdt_disconnect(struct mdt_thread_info *info)
1258 rc = target_handle_disconnect(mdt_info_req(info));
1260 rc = err_serious(rc);
1264 static int mdt_sendpage(struct mdt_thread_info *info,
1265 struct lu_rdpg *rdpg, int nob)
1267 struct ptlrpc_request *req = mdt_info_req(info);
1268 struct obd_export *exp = req->rq_export;
1269 struct ptlrpc_bulk_desc *desc;
1270 struct l_wait_info *lwi = &info->mti_u.rdpg.mti_wait_info;
1277 desc = ptlrpc_prep_bulk_exp(req, rdpg->rp_npages, BULK_PUT_SOURCE,
1282 for (i = 0, tmpcount = nob;
1283 i < rdpg->rp_npages && tmpcount > 0; i++, tmpcount -= tmpsize) {
1284 tmpsize = min_t(int, tmpcount, CFS_PAGE_SIZE);
1285 ptlrpc_prep_bulk_page(desc, rdpg->rp_pages[i], 0, tmpsize);
1288 LASSERT(desc->bd_nob == nob);
1289 rc = target_bulk_io(exp, desc, lwi);
1290 ptlrpc_free_bulk(desc);
1294 #ifdef HAVE_SPLIT_SUPPORT
1296 * Retrieve dir entry from the page and insert it to the slave object, actually,
1297 * this should be in osd layer, but since it will not in the final product, so
1298 * just do it here and do not define more moo api anymore for this.
1300 static int mdt_write_dir_page(struct mdt_thread_info *info, struct page *page,
1303 struct mdt_object *object = info->mti_object;
1304 struct lu_fid *lf = &info->mti_tmp_fid2;
1305 struct md_attr *ma = &info->mti_attr;
1306 struct lu_dirpage *dp;
1307 struct lu_dirent *ent;
1308 int rc = 0, offset = 0;
1311 /* Make sure we have at least one entry. */
1316 * Disable trans for this name insert, since it will include many trans
1319 info->mti_no_need_trans = 1;
1321 * When write_dir_page, no need update parent's ctime,
1322 * and no permission check for name_insert.
1324 ma->ma_attr.la_ctime = 0;
1325 ma->ma_attr.la_valid = LA_MODE;
1326 ma->ma_valid = MA_INODE;
1329 dp = page_address(page);
1330 offset = (int)((__u32)lu_dirent_start(dp) - (__u32)dp);
1332 for (ent = lu_dirent_start(dp); ent != NULL;
1333 ent = lu_dirent_next(ent)) {
1334 struct lu_name *lname;
1337 if (le16_to_cpu(ent->lde_namelen) == 0)
1340 fid_le_to_cpu(lf, &ent->lde_fid);
1341 if (le64_to_cpu(ent->lde_hash) & MAX_HASH_HIGHEST_BIT)
1342 ma->ma_attr.la_mode = S_IFDIR;
1344 ma->ma_attr.la_mode = 0;
1345 OBD_ALLOC(name, le16_to_cpu(ent->lde_namelen) + 1);
1347 GOTO(out, rc = -ENOMEM);
1349 memcpy(name, ent->lde_name, le16_to_cpu(ent->lde_namelen));
1350 lname = mdt_name(info->mti_env, name,
1351 le16_to_cpu(ent->lde_namelen));
1352 ma->ma_attr_flags |= (MDS_PERM_BYPASS | MDS_QUOTA_IGNORE);
1353 rc = mdo_name_insert(info->mti_env,
1354 md_object_next(&object->mot_obj),
1356 OBD_FREE(name, le16_to_cpu(ent->lde_namelen) + 1);
1358 CERROR("Can't insert %*.*s, rc %d\n",
1359 le16_to_cpu(ent->lde_namelen),
1360 le16_to_cpu(ent->lde_namelen),
1365 offset += lu_dirent_size(ent);
1375 static int mdt_bulk_timeout(void *data)
1379 CERROR("mdt bulk transfer timeout \n");
1384 static int mdt_writepage(struct mdt_thread_info *info)
1386 struct ptlrpc_request *req = mdt_info_req(info);
1387 struct mdt_body *reqbody;
1388 struct l_wait_info *lwi;
1389 struct ptlrpc_bulk_desc *desc;
1395 reqbody = req_capsule_client_get(info->mti_pill, &RMF_MDT_BODY);
1396 if (reqbody == NULL)
1397 RETURN(err_serious(-EFAULT));
1399 desc = ptlrpc_prep_bulk_exp(req, 1, BULK_GET_SINK, MDS_BULK_PORTAL);
1401 RETURN(err_serious(-ENOMEM));
1403 /* allocate the page for the desc */
1404 page = cfs_alloc_page(CFS_ALLOC_STD);
1406 GOTO(desc_cleanup, rc = -ENOMEM);
1408 CDEBUG(D_INFO, "Received page offset %d size %d \n",
1409 (int)reqbody->size, (int)reqbody->nlink);
1411 ptlrpc_prep_bulk_page(desc, page, (int)reqbody->size,
1412 (int)reqbody->nlink);
1414 rc = sptlrpc_svc_prep_bulk(req, desc);
1416 GOTO(cleanup_page, rc);
1418 * Check if client was evicted while we were doing i/o before touching
1423 GOTO(cleanup_page, rc = -ENOMEM);
1425 if (desc->bd_export->exp_failed)
1428 rc = ptlrpc_start_bulk_transfer (desc);
1430 *lwi = LWI_TIMEOUT_INTERVAL(obd_timeout * CFS_HZ / 4, CFS_HZ,
1431 mdt_bulk_timeout, desc);
1432 rc = l_wait_event(desc->bd_waitq, !ptlrpc_bulk_active(desc) ||
1433 desc->bd_export->exp_failed, lwi);
1434 LASSERT(rc == 0 || rc == -ETIMEDOUT);
1435 if (rc == -ETIMEDOUT) {
1436 DEBUG_REQ(D_ERROR, req, "timeout on bulk GET");
1437 ptlrpc_abort_bulk(desc);
1438 } else if (desc->bd_export->exp_failed) {
1439 DEBUG_REQ(D_ERROR, req, "Eviction on bulk GET");
1441 ptlrpc_abort_bulk(desc);
1442 } else if (!desc->bd_success ||
1443 desc->bd_nob_transferred != desc->bd_nob) {
1444 DEBUG_REQ(D_ERROR, req, "%s bulk GET %d(%d)",
1446 "truncated" : "network error on",
1447 desc->bd_nob_transferred, desc->bd_nob);
1448 /* XXX should this be a different errno? */
1452 DEBUG_REQ(D_ERROR, req, "ptlrpc_bulk_get failed: rc %d", rc);
1455 GOTO(cleanup_lwi, rc);
1456 rc = mdt_write_dir_page(info, page, reqbody->nlink);
1461 cfs_free_page(page);
1463 ptlrpc_free_bulk(desc);
1468 static int mdt_readpage(struct mdt_thread_info *info)
1470 struct mdt_object *object = info->mti_object;
1471 struct lu_rdpg *rdpg = &info->mti_u.rdpg.mti_rdpg;
1472 struct mdt_body *reqbody;
1473 struct mdt_body *repbody;
1478 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_READPAGE_PACK))
1479 RETURN(err_serious(-ENOMEM));
1481 reqbody = req_capsule_client_get(info->mti_pill, &RMF_MDT_BODY);
1482 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
1483 if (reqbody == NULL || repbody == NULL)
1484 RETURN(err_serious(-EFAULT));
1487 * prepare @rdpg before calling lower layers and transfer itself. Here
1488 * reqbody->size contains offset of where to start to read and
1489 * reqbody->nlink contains number bytes to read.
1491 rdpg->rp_hash = reqbody->size;
1492 if (rdpg->rp_hash != reqbody->size) {
1493 CERROR("Invalid hash: "LPX64" != "LPX64"\n",
1494 rdpg->rp_hash, reqbody->size);
1498 rdpg->rp_attrs = reqbody->mode;
1499 if (info->mti_exp->exp_connect_flags & OBD_CONNECT_64BITHASH)
1500 rdpg->rp_attrs |= LUDA_64BITHASH;
1501 rdpg->rp_count = min_t(unsigned int, reqbody->nlink,
1502 PTLRPC_MAX_BRW_SIZE);
1503 rdpg->rp_npages = (rdpg->rp_count + CFS_PAGE_SIZE - 1) >>
1505 OBD_ALLOC(rdpg->rp_pages, rdpg->rp_npages * sizeof rdpg->rp_pages[0]);
1506 if (rdpg->rp_pages == NULL)
1509 for (i = 0; i < rdpg->rp_npages; ++i) {
1510 rdpg->rp_pages[i] = cfs_alloc_page(CFS_ALLOC_STD);
1511 if (rdpg->rp_pages[i] == NULL)
1512 GOTO(free_rdpg, rc = -ENOMEM);
1515 /* call lower layers to fill allocated pages with directory data */
1516 rc = mo_readpage(info->mti_env, mdt_object_child(object), rdpg);
1518 GOTO(free_rdpg, rc);
1520 /* send pages to client */
1521 rc = mdt_sendpage(info, rdpg, rc);
1526 for (i = 0; i < rdpg->rp_npages; i++)
1527 if (rdpg->rp_pages[i] != NULL)
1528 cfs_free_page(rdpg->rp_pages[i]);
1529 OBD_FREE(rdpg->rp_pages, rdpg->rp_npages * sizeof rdpg->rp_pages[0]);
1531 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_SENDPAGE))
1537 static int mdt_reint_internal(struct mdt_thread_info *info,
1538 struct mdt_lock_handle *lhc,
1541 struct req_capsule *pill = info->mti_pill;
1542 struct md_quota *mq = md_quota(info->mti_env);
1543 struct mdt_body *repbody;
1548 rc = mdt_reint_unpack(info, op);
1550 CERROR("Can't unpack reint, rc %d\n", rc);
1551 RETURN(err_serious(rc));
1554 /* for replay (no_create) lmm is not needed, client has it already */
1555 if (req_capsule_has_field(pill, &RMF_MDT_MD, RCL_SERVER))
1556 req_capsule_set_size(pill, &RMF_MDT_MD, RCL_SERVER,
1557 info->mti_rr.rr_eadatalen);
1559 if (req_capsule_has_field(pill, &RMF_LOGCOOKIES, RCL_SERVER))
1560 req_capsule_set_size(pill, &RMF_LOGCOOKIES, RCL_SERVER,
1561 info->mti_mdt->mdt_max_cookiesize);
1563 rc = req_capsule_server_pack(pill);
1565 CERROR("Can't pack response, rc %d\n", rc);
1566 RETURN(err_serious(rc));
1569 if (req_capsule_has_field(pill, &RMF_MDT_BODY, RCL_SERVER)) {
1570 repbody = req_capsule_server_get(pill, &RMF_MDT_BODY);
1572 repbody->eadatasize = 0;
1573 repbody->aclsize = 0;
1576 OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_REINT_DELAY, 10);
1578 /* for replay no cookkie / lmm need, because client have this already */
1579 if (info->mti_spec.no_create)
1580 if (req_capsule_has_field(pill, &RMF_MDT_MD, RCL_SERVER))
1581 req_capsule_set_size(pill, &RMF_MDT_MD, RCL_SERVER, 0);
1583 rc = mdt_init_ucred_reint(info);
1585 GOTO(out_shrink, rc);
1587 rc = mdt_fix_attr_ucred(info, op);
1589 GOTO(out_ucred, rc = err_serious(rc));
1591 if (mdt_check_resent(info, mdt_reconstruct, lhc)) {
1592 rc = lustre_msg_get_status(mdt_info_req(info)->rq_repmsg);
1593 GOTO(out_ucred, rc);
1595 mq->mq_exp = info->mti_exp;
1596 rc = mdt_reint_rec(info, lhc);
1599 mdt_exit_ucred(info);
1601 mdt_client_compatibility(info);
1602 rc2 = mdt_fix_reply(info);
1608 static long mdt_reint_opcode(struct mdt_thread_info *info,
1609 const struct req_format **fmt)
1611 struct mdt_rec_reint *rec;
1614 opc = err_serious(-EFAULT);
1615 rec = req_capsule_client_get(info->mti_pill, &RMF_REC_REINT);
1617 opc = rec->rr_opcode;
1618 DEBUG_REQ(D_INODE, mdt_info_req(info), "reint opt = %ld", opc);
1619 if (opc < REINT_MAX && fmt[opc] != NULL)
1620 req_capsule_extend(info->mti_pill, fmt[opc]);
1622 CERROR("Unsupported opc: %ld\n", opc);
1623 opc = err_serious(opc);
1629 static int mdt_reint(struct mdt_thread_info *info)
1634 static const struct req_format *reint_fmts[REINT_MAX] = {
1635 [REINT_SETATTR] = &RQF_MDS_REINT_SETATTR,
1636 [REINT_CREATE] = &RQF_MDS_REINT_CREATE,
1637 [REINT_LINK] = &RQF_MDS_REINT_LINK,
1638 [REINT_UNLINK] = &RQF_MDS_REINT_UNLINK,
1639 [REINT_RENAME] = &RQF_MDS_REINT_RENAME,
1640 [REINT_OPEN] = &RQF_MDS_REINT_OPEN,
1641 [REINT_SETXATTR] = &RQF_MDS_REINT_SETXATTR
1646 opc = mdt_reint_opcode(info, reint_fmts);
1649 * No lock possible here from client to pass it to reint code
1652 rc = mdt_reint_internal(info, NULL, opc);
1657 info->mti_fail_id = OBD_FAIL_MDS_REINT_NET_REP;
1661 /* this should sync the whole device */
1662 static int mdt_device_sync(const struct lu_env *env, struct mdt_device *mdt)
1664 struct dt_device *dt = mdt->mdt_bottom;
1668 rc = dt->dd_ops->dt_sync(env, dt);
1672 /* this should sync this object */
1673 static int mdt_object_sync(struct mdt_thread_info *info)
1675 struct md_object *next;
1679 if (!mdt_object_exists(info->mti_object)) {
1680 CWARN("Non existing object "DFID"!\n",
1681 PFID(mdt_object_fid(info->mti_object)));
1684 next = mdt_object_child(info->mti_object);
1685 rc = mo_object_sync(info->mti_env, next);
1690 static int mdt_sync(struct mdt_thread_info *info)
1692 struct ptlrpc_request *req = mdt_info_req(info);
1693 struct req_capsule *pill = info->mti_pill;
1694 struct mdt_body *body;
1698 /* The fid may be zero, so we req_capsule_set manually */
1699 req_capsule_set(pill, &RQF_MDS_SYNC);
1701 body = req_capsule_client_get(pill, &RMF_MDT_BODY);
1703 RETURN(err_serious(-EINVAL));
1705 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_SYNC_PACK))
1706 RETURN(err_serious(-ENOMEM));
1708 if (fid_seq(&body->fid1) == 0) {
1709 /* sync the whole device */
1710 rc = req_capsule_server_pack(pill);
1712 rc = mdt_device_sync(info->mti_env, info->mti_mdt);
1714 rc = err_serious(rc);
1716 /* sync an object */
1717 rc = mdt_unpack_req_pack_rep(info, HABEO_CORPUS|HABEO_REFERO);
1719 rc = mdt_object_sync(info);
1721 struct md_object *next;
1722 const struct lu_fid *fid;
1723 struct lu_attr *la = &info->mti_attr.ma_attr;
1725 next = mdt_object_child(info->mti_object);
1726 info->mti_attr.ma_need = MA_INODE;
1727 info->mti_attr.ma_valid = 0;
1728 rc = mo_attr_get(info->mti_env, next,
1731 body = req_capsule_server_get(pill,
1733 fid = mdt_object_fid(info->mti_object);
1734 mdt_pack_attr2body(info, body, la, fid);
1738 rc = err_serious(rc);
1741 mdt_counter_incr(req, LPROC_MDT_SYNC);
1746 #ifdef HAVE_QUOTA_SUPPORT
1747 static int mdt_quotacheck_handle(struct mdt_thread_info *info)
1749 struct obd_quotactl *oqctl;
1750 struct req_capsule *pill = info->mti_pill;
1751 struct obd_export *exp = info->mti_exp;
1752 struct md_quota *mq = md_quota(info->mti_env);
1753 struct md_device *next = info->mti_mdt->mdt_child;
1757 oqctl = req_capsule_client_get(pill, &RMF_OBD_QUOTACTL);
1761 /* remote client has no permission for quotacheck */
1762 if (unlikely(exp_connect_rmtclient(exp)))
1765 rc = req_capsule_server_pack(pill);
1770 rc = next->md_ops->mdo_quota.mqo_check(info->mti_env, next,
1775 static int mdt_quotactl_handle(struct mdt_thread_info *info)
1777 struct obd_quotactl *oqctl, *repoqc;
1778 struct req_capsule *pill = info->mti_pill;
1779 struct obd_export *exp = info->mti_exp;
1780 struct md_quota *mq = md_quota(info->mti_env);
1781 struct md_device *next = info->mti_mdt->mdt_child;
1782 const struct md_quota_operations *mqo = &next->md_ops->mdo_quota;
1786 oqctl = req_capsule_client_get(pill, &RMF_OBD_QUOTACTL);
1791 if (exp_connect_rmtclient(exp)) {
1792 struct ptlrpc_request *req = mdt_info_req(info);
1793 struct mdt_export_data *med = mdt_req2med(req);
1794 struct lustre_idmap_table *idmap = med->med_idmap;
1796 if (unlikely(oqctl->qc_cmd != Q_GETQUOTA &&
1797 oqctl->qc_cmd != Q_GETINFO))
1801 if (oqctl->qc_type == USRQUOTA)
1802 id = lustre_idmap_lookup_uid(NULL, idmap, 0,
1804 else if (oqctl->qc_type == GRPQUOTA)
1805 id = lustre_idmap_lookup_gid(NULL, idmap, 0,
1810 if (id == CFS_IDMAP_NOTFOUND) {
1811 CDEBUG(D_QUOTA, "no mapping for id %u\n",
1817 rc = req_capsule_server_pack(pill);
1821 repoqc = req_capsule_server_get(pill, &RMF_OBD_QUOTACTL);
1822 LASSERT(repoqc != NULL);
1825 switch (oqctl->qc_cmd) {
1827 rc = mqo->mqo_on(info->mti_env, next, oqctl->qc_type);
1830 rc = mqo->mqo_off(info->mti_env, next, oqctl->qc_type);
1833 rc = mqo->mqo_setinfo(info->mti_env, next, oqctl->qc_type, id,
1837 rc = mqo->mqo_getinfo(info->mti_env, next, oqctl->qc_type, id,
1841 rc = mqo->mqo_setquota(info->mti_env, next, oqctl->qc_type, id,
1845 rc = mqo->mqo_getquota(info->mti_env, next, oqctl->qc_type, id,
1849 rc = mqo->mqo_getoinfo(info->mti_env, next, oqctl->qc_type, id,
1853 rc = mqo->mqo_getoquota(info->mti_env, next, oqctl->qc_type, id,
1856 case LUSTRE_Q_INVALIDATE:
1857 rc = mqo->mqo_invalidate(info->mti_env, next, oqctl->qc_type);
1859 case LUSTRE_Q_FINVALIDATE:
1860 rc = mqo->mqo_finvalidate(info->mti_env, next, oqctl->qc_type);
1863 CERROR("unsupported mdt_quotactl command: %d\n",
1875 * OBD PING and other handlers.
1877 static int mdt_obd_ping(struct mdt_thread_info *info)
1882 req_capsule_set(info->mti_pill, &RQF_OBD_PING);
1884 rc = target_handle_ping(mdt_info_req(info));
1886 rc = err_serious(rc);
1890 static int mdt_obd_log_cancel(struct mdt_thread_info *info)
1892 return err_serious(-EOPNOTSUPP);
1895 static int mdt_obd_qc_callback(struct mdt_thread_info *info)
1897 return err_serious(-EOPNOTSUPP);
1905 /** clone llog ctxt from child (mdd)
1906 * This allows remote llog (replicator) access.
1907 * We can either pass all llog RPCs (eg mdt_llog_create) on to child where the
1908 * context was originally set up, or we can handle them directly.
1909 * I choose the latter, but that means I need any llog
1910 * contexts set up by child to be accessable by the mdt. So we clone the
1911 * context into our context list here.
1913 static int mdt_llog_ctxt_clone(const struct lu_env *env, struct mdt_device *mdt,
1916 struct md_device *next = mdt->mdt_child;
1917 struct llog_ctxt *ctxt;
1920 if (!llog_ctxt_null(mdt2obd_dev(mdt), idx))
1923 rc = next->md_ops->mdo_llog_ctxt_get(env, next, idx, (void **)&ctxt);
1924 if (rc || ctxt == NULL) {
1925 CERROR("Can't get mdd ctxt %d\n", rc);
1929 rc = llog_group_set_ctxt(&mdt2obd_dev(mdt)->obd_olg, ctxt, idx);
1931 CERROR("Can't set mdt ctxt %d\n", rc);
1936 static int mdt_llog_ctxt_unclone(const struct lu_env *env,
1937 struct mdt_device *mdt, int idx)
1939 struct llog_ctxt *ctxt;
1941 ctxt = llog_get_context(mdt2obd_dev(mdt), idx);
1944 /* Put once for the get we just did, and once for the clone */
1945 llog_ctxt_put(ctxt);
1946 llog_ctxt_put(ctxt);
1950 static int mdt_llog_create(struct mdt_thread_info *info)
1954 req_capsule_set(info->mti_pill, &RQF_LLOG_ORIGIN_HANDLE_CREATE);
1955 rc = llog_origin_handle_create(mdt_info_req(info));
1956 return (rc < 0 ? err_serious(rc) : rc);
1959 static int mdt_llog_destroy(struct mdt_thread_info *info)
1963 req_capsule_set(info->mti_pill, &RQF_LLOG_ORIGIN_HANDLE_DESTROY);
1964 rc = llog_origin_handle_destroy(mdt_info_req(info));
1965 return (rc < 0 ? err_serious(rc) : rc);
1968 static int mdt_llog_read_header(struct mdt_thread_info *info)
1972 req_capsule_set(info->mti_pill, &RQF_LLOG_ORIGIN_HANDLE_READ_HEADER);
1973 rc = llog_origin_handle_read_header(mdt_info_req(info));
1974 return (rc < 0 ? err_serious(rc) : rc);
1977 static int mdt_llog_next_block(struct mdt_thread_info *info)
1981 req_capsule_set(info->mti_pill, &RQF_LLOG_ORIGIN_HANDLE_NEXT_BLOCK);
1982 rc = llog_origin_handle_next_block(mdt_info_req(info));
1983 return (rc < 0 ? err_serious(rc) : rc);
1986 static int mdt_llog_prev_block(struct mdt_thread_info *info)
1990 req_capsule_set(info->mti_pill, &RQF_LLOG_ORIGIN_HANDLE_PREV_BLOCK);
1991 rc = llog_origin_handle_prev_block(mdt_info_req(info));
1992 return (rc < 0 ? err_serious(rc) : rc);
1999 static struct ldlm_callback_suite cbs = {
2000 .lcs_completion = ldlm_server_completion_ast,
2001 .lcs_blocking = ldlm_server_blocking_ast,
2005 static int mdt_enqueue(struct mdt_thread_info *info)
2007 struct ptlrpc_request *req;
2011 * info->mti_dlm_req already contains swapped and (if necessary)
2012 * converted dlm request.
2014 LASSERT(info->mti_dlm_req != NULL);
2016 req = mdt_info_req(info);
2017 rc = ldlm_handle_enqueue0(info->mti_mdt->mdt_namespace,
2018 req, info->mti_dlm_req, &cbs);
2019 info->mti_fail_id = OBD_FAIL_LDLM_REPLY;
2020 return rc ? err_serious(rc) : req->rq_status;
2023 static int mdt_convert(struct mdt_thread_info *info)
2026 struct ptlrpc_request *req;
2028 LASSERT(info->mti_dlm_req);
2029 req = mdt_info_req(info);
2030 rc = ldlm_handle_convert0(req, info->mti_dlm_req);
2031 return rc ? err_serious(rc) : req->rq_status;
2034 static int mdt_bl_callback(struct mdt_thread_info *info)
2036 CERROR("bl callbacks should not happen on MDS\n");
2038 return err_serious(-EOPNOTSUPP);
2041 static int mdt_cp_callback(struct mdt_thread_info *info)
2043 CERROR("cp callbacks should not happen on MDS\n");
2045 return err_serious(-EOPNOTSUPP);
2049 * sec context handlers
2051 static int mdt_sec_ctx_handle(struct mdt_thread_info *info)
2055 rc = mdt_handle_idmap(info);
2058 struct ptlrpc_request *req = mdt_info_req(info);
2061 opc = lustre_msg_get_opc(req->rq_reqmsg);
2062 if (opc == SEC_CTX_INIT || opc == SEC_CTX_INIT_CONT)
2063 sptlrpc_svc_ctx_invalidate(req);
2066 CFS_FAIL_TIMEOUT(OBD_FAIL_SEC_CTX_HDL_PAUSE, cfs_fail_val);
2071 static struct mdt_object *mdt_obj(struct lu_object *o)
2073 LASSERT(lu_device_is_mdt(o->lo_dev));
2074 return container_of0(o, struct mdt_object, mot_obj.mo_lu);
2077 struct mdt_object *mdt_object_find(const struct lu_env *env,
2078 struct mdt_device *d,
2079 const struct lu_fid *f)
2081 struct lu_object *o;
2082 struct mdt_object *m;
2085 CDEBUG(D_INFO, "Find object for "DFID"\n", PFID(f));
2086 o = lu_object_find(env, &d->mdt_md_dev.md_lu_dev, f, NULL);
2087 if (unlikely(IS_ERR(o)))
2088 m = (struct mdt_object *)o;
2095 * Asyncronous commit for mdt device.
2097 * Pass asynchonous commit call down the MDS stack.
2099 * \param env environment
2100 * \param mdt the mdt device
2102 static void mdt_device_commit_async(const struct lu_env *env,
2103 struct mdt_device *mdt)
2105 struct dt_device *dt = mdt->mdt_bottom;
2108 rc = dt->dd_ops->dt_commit_async(env, dt);
2109 if (unlikely(rc != 0))
2110 CWARN("async commit start failed with rc = %d", rc);
2114 * Mark the lock as "synchonous".
2116 * Mark the lock to deffer transaction commit to the unlock time.
2118 * \param lock the lock to mark as "synchonous"
2120 * \see mdt_is_lock_sync
2121 * \see mdt_save_lock
2123 static inline void mdt_set_lock_sync(struct ldlm_lock *lock)
2125 lock->l_ast_data = (void*)1;
2129 * Check whehter the lock "synchonous" or not.
2131 * \param lock the lock to check
2132 * \retval 1 the lock is "synchonous"
2133 * \retval 0 the lock isn't "synchronous"
2135 * \see mdt_set_lock_sync
2136 * \see mdt_save_lock
2138 static inline int mdt_is_lock_sync(struct ldlm_lock *lock)
2140 return lock->l_ast_data != NULL;
2144 * Blocking AST for mdt locks.
2146 * Starts transaction commit if in case of COS lock conflict or
2147 * deffers such a commit to the mdt_save_lock.
2149 * \param lock the lock which blocks a request or cancelling lock
2150 * \param desc unused
2151 * \param data unused
2152 * \param flag indicates whether this cancelling or blocking callback
2154 * \see ldlm_blocking_ast_nocheck
2156 int mdt_blocking_ast(struct ldlm_lock *lock, struct ldlm_lock_desc *desc,
2157 void *data, int flag)
2159 struct obd_device *obd = ldlm_lock_to_ns(lock)->ns_obd;
2160 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
2164 if (flag == LDLM_CB_CANCELING)
2166 lock_res_and_lock(lock);
2167 if (lock->l_blocking_ast != mdt_blocking_ast) {
2168 unlock_res_and_lock(lock);
2171 if (mdt_cos_is_enabled(mdt) &&
2172 lock->l_req_mode & (LCK_PW | LCK_EX) &&
2173 lock->l_blocking_lock != NULL &&
2174 lock->l_client_cookie != lock->l_blocking_lock->l_client_cookie) {
2175 mdt_set_lock_sync(lock);
2177 rc = ldlm_blocking_ast_nocheck(lock);
2179 /* There is no lock conflict if l_blocking_lock == NULL,
2180 * it indicates a blocking ast sent from ldlm_lock_decref_internal
2181 * when the last reference to a local lock was released */
2182 if (lock->l_req_mode == LCK_COS && lock->l_blocking_lock != NULL) {
2185 rc = lu_env_init(&env, LCT_LOCAL);
2186 if (unlikely(rc != 0))
2187 CWARN("lu_env initialization failed with rc = %d,"
2188 "cannot start asynchronous commit\n", rc);
2190 mdt_device_commit_async(&env, mdt);
2196 int mdt_object_lock(struct mdt_thread_info *info, struct mdt_object *o,
2197 struct mdt_lock_handle *lh, __u64 ibits, int locality)
2199 struct ldlm_namespace *ns = info->mti_mdt->mdt_namespace;
2200 ldlm_policy_data_t *policy = &info->mti_policy;
2201 struct ldlm_res_id *res_id = &info->mti_res_id;
2205 LASSERT(!lustre_handle_is_used(&lh->mlh_reg_lh));
2206 LASSERT(!lustre_handle_is_used(&lh->mlh_pdo_lh));
2207 LASSERT(lh->mlh_reg_mode != LCK_MINMODE);
2208 LASSERT(lh->mlh_type != MDT_NUL_LOCK);
2210 if (mdt_object_exists(o) < 0) {
2211 if (locality == MDT_CROSS_LOCK) {
2212 /* cross-ref object fix */
2213 ibits &= ~MDS_INODELOCK_UPDATE;
2214 ibits |= MDS_INODELOCK_LOOKUP;
2216 LASSERT(!(ibits & MDS_INODELOCK_UPDATE));
2217 LASSERT(ibits & MDS_INODELOCK_LOOKUP);
2219 /* No PDO lock on remote object */
2220 LASSERT(lh->mlh_type != MDT_PDO_LOCK);
2223 if (lh->mlh_type == MDT_PDO_LOCK) {
2224 /* check for exists after object is locked */
2225 if (mdt_object_exists(o) == 0) {
2226 /* Non-existent object shouldn't have PDO lock */
2229 /* Non-dir object shouldn't have PDO lock */
2230 if (!S_ISDIR(lu_object_attr(&o->mot_obj.mo_lu)))
2235 memset(policy, 0, sizeof(*policy));
2236 fid_build_reg_res_name(mdt_object_fid(o), res_id);
2239 * Take PDO lock on whole directory and build correct @res_id for lock
2240 * on part of directory.
2242 if (lh->mlh_pdo_hash != 0) {
2243 LASSERT(lh->mlh_type == MDT_PDO_LOCK);
2244 mdt_lock_pdo_mode(info, o, lh);
2245 if (lh->mlh_pdo_mode != LCK_NL) {
2247 * Do not use LDLM_FL_LOCAL_ONLY for parallel lock, it
2248 * is never going to be sent to client and we do not
2249 * want it slowed down due to possible cancels.
2251 policy->l_inodebits.bits = MDS_INODELOCK_UPDATE;
2252 rc = mdt_fid_lock(ns, &lh->mlh_pdo_lh, lh->mlh_pdo_mode,
2253 policy, res_id, LDLM_FL_ATOMIC_CB,
2254 &info->mti_exp->exp_handle.h_cookie);
2260 * Finish res_id initializing by name hash marking part of
2261 * directory which is taking modification.
2263 res_id->name[LUSTRE_RES_ID_HSH_OFF] = lh->mlh_pdo_hash;
2266 policy->l_inodebits.bits = ibits;
2269 * Use LDLM_FL_LOCAL_ONLY for this lock. We do not know yet if it is
2270 * going to be sent to client. If it is - mdt_intent_policy() path will
2271 * fix it up and turn FL_LOCAL flag off.
2273 rc = mdt_fid_lock(ns, &lh->mlh_reg_lh, lh->mlh_reg_mode, policy,
2274 res_id, LDLM_FL_LOCAL_ONLY | LDLM_FL_ATOMIC_CB,
2275 &info->mti_exp->exp_handle.h_cookie);
2277 mdt_object_unlock(info, o, lh, 1);
2278 else if (unlikely(OBD_FAIL_PRECHECK(OBD_FAIL_MDS_PDO_LOCK)) &&
2279 lh->mlh_pdo_hash != 0 &&
2280 (lh->mlh_reg_mode == LCK_PW || lh->mlh_reg_mode == LCK_EX)) {
2281 OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_PDO_LOCK, 15);
2288 * Save a lock within request object.
2290 * Keep the lock referenced until whether client ACK or transaction
2291 * commit happens or release the lock immediately depending on input
2292 * parameters. If COS is ON, a write lock is converted to COS lock
2295 * \param info thead info object
2296 * \param h lock handle
2297 * \param mode lock mode
2298 * \param decref force immediate lock releasing
2301 void mdt_save_lock(struct mdt_thread_info *info, struct lustre_handle *h,
2302 ldlm_mode_t mode, int decref)
2306 if (lustre_handle_is_used(h)) {
2307 if (decref || !info->mti_has_trans ||
2308 !(mode & (LCK_PW | LCK_EX))){
2309 mdt_fid_unlock(h, mode);
2311 struct mdt_device *mdt = info->mti_mdt;
2312 struct ldlm_lock *lock = ldlm_handle2lock(h);
2313 struct ptlrpc_request *req = mdt_info_req(info);
2316 LASSERTF(lock != NULL, "no lock for cookie "LPX64"\n",
2318 CDEBUG(D_HA, "request = %p reply state = %p"
2319 " transno = "LPD64"\n",
2320 req, req->rq_reply_state, req->rq_transno);
2321 if (mdt_cos_is_enabled(mdt)) {
2323 ldlm_lock_downgrade(lock, LCK_COS);
2326 ptlrpc_save_lock(req, h, mode, no_ack);
2327 if (mdt_is_lock_sync(lock)) {
2328 CDEBUG(D_HA, "found sync-lock,"
2329 " async commit started\n");
2330 mdt_device_commit_async(info->mti_env,
2333 LDLM_LOCK_PUT(lock);
2342 * Unlock mdt object.
2344 * Immeditely release the regular lock and the PDO lock or save the
2345 * lock in reqeuest and keep them referenced until client ACK or
2346 * transaction commit.
2348 * \param info thread info object
2349 * \param o mdt object
2350 * \param lh mdt lock handle referencing regular and PDO locks
2351 * \param decref force immediate lock releasing
2353 void mdt_object_unlock(struct mdt_thread_info *info, struct mdt_object *o,
2354 struct mdt_lock_handle *lh, int decref)
2358 mdt_save_lock(info, &lh->mlh_pdo_lh, lh->mlh_pdo_mode, decref);
2359 mdt_save_lock(info, &lh->mlh_reg_lh, lh->mlh_reg_mode, decref);
2364 struct mdt_object *mdt_object_find_lock(struct mdt_thread_info *info,
2365 const struct lu_fid *f,
2366 struct mdt_lock_handle *lh,
2369 struct mdt_object *o;
2371 o = mdt_object_find(info->mti_env, info->mti_mdt, f);
2375 rc = mdt_object_lock(info, o, lh, ibits,
2378 mdt_object_put(info->mti_env, o);
2385 void mdt_object_unlock_put(struct mdt_thread_info * info,
2386 struct mdt_object * o,
2387 struct mdt_lock_handle *lh,
2390 mdt_object_unlock(info, o, lh, decref);
2391 mdt_object_put(info->mti_env, o);
2394 static struct mdt_handler *mdt_handler_find(__u32 opc,
2395 struct mdt_opc_slice *supported)
2397 struct mdt_opc_slice *s;
2398 struct mdt_handler *h;
2401 for (s = supported; s->mos_hs != NULL; s++) {
2402 if (s->mos_opc_start <= opc && opc < s->mos_opc_end) {
2403 h = s->mos_hs + (opc - s->mos_opc_start);
2404 if (likely(h->mh_opc != 0))
2405 LASSERTF(h->mh_opc == opc,
2406 "opcode mismatch %d != %d\n",
2409 h = NULL; /* unsupported opc */
2416 static int mdt_lock_resname_compat(struct mdt_device *m,
2417 struct ldlm_request *req)
2419 /* XXX something... later. */
2423 static int mdt_lock_reply_compat(struct mdt_device *m, struct ldlm_reply *rep)
2425 /* XXX something... later. */
2430 * Generic code handling requests that have struct mdt_body passed in:
2432 * - extract mdt_body from request and save it in @info, if present;
2434 * - create lu_object, corresponding to the fid in mdt_body, and save it in
2437 * - if HABEO_CORPUS flag is set for this request type check whether object
2438 * actually exists on storage (lu_object_exists()).
2441 static int mdt_body_unpack(struct mdt_thread_info *info, __u32 flags)
2443 const struct mdt_body *body;
2444 struct mdt_object *obj;
2445 const struct lu_env *env;
2446 struct req_capsule *pill;
2450 env = info->mti_env;
2451 pill = info->mti_pill;
2453 body = info->mti_body = req_capsule_client_get(pill, &RMF_MDT_BODY);
2457 if (!(body->valid & OBD_MD_FLID))
2460 if (!fid_is_sane(&body->fid1)) {
2461 CERROR("Invalid fid: "DFID"\n", PFID(&body->fid1));
2466 * Do not get size or any capa fields before we check that request
2467 * contains capa actually. There are some requests which do not, for
2468 * instance MDS_IS_SUBDIR.
2470 if (req_capsule_has_field(pill, &RMF_CAPA1, RCL_CLIENT) &&
2471 req_capsule_get_size(pill, &RMF_CAPA1, RCL_CLIENT))
2472 mdt_set_capainfo(info, 0, &body->fid1,
2473 req_capsule_client_get(pill, &RMF_CAPA1));
2475 obj = mdt_object_find(env, info->mti_mdt, &body->fid1);
2477 if ((flags & HABEO_CORPUS) &&
2478 !mdt_object_exists(obj)) {
2479 mdt_object_put(env, obj);
2480 /* for capability renew ENOENT will be handled in
2482 if (body->valid & OBD_MD_FLOSSCAPA)
2487 info->mti_object = obj;
2496 static int mdt_unpack_req_pack_rep(struct mdt_thread_info *info, __u32 flags)
2498 struct req_capsule *pill = info->mti_pill;
2502 if (req_capsule_has_field(pill, &RMF_MDT_BODY, RCL_CLIENT))
2503 rc = mdt_body_unpack(info, flags);
2507 if (rc == 0 && (flags & HABEO_REFERO)) {
2509 if (req_capsule_has_field(pill, &RMF_MDT_MD, RCL_SERVER))
2510 req_capsule_set_size(pill, &RMF_MDT_MD, RCL_SERVER,
2511 info->mti_body->eadatasize);
2512 if (req_capsule_has_field(pill, &RMF_LOGCOOKIES, RCL_SERVER))
2513 req_capsule_set_size(pill, &RMF_LOGCOOKIES, RCL_SERVER,
2514 info->mti_mdt->mdt_max_cookiesize);
2516 rc = req_capsule_server_pack(pill);
2521 static int mdt_init_capa_ctxt(const struct lu_env *env, struct mdt_device *m)
2523 struct md_device *next = m->mdt_child;
2525 return next->md_ops->mdo_init_capa_ctxt(env, next,
2526 m->mdt_opts.mo_mds_capa,
2527 m->mdt_capa_timeout,
2533 * Invoke handler for this request opc. Also do necessary preprocessing
2534 * (according to handler ->mh_flags), and post-processing (setting of
2535 * ->last_{xid,committed}).
2537 static int mdt_req_handle(struct mdt_thread_info *info,
2538 struct mdt_handler *h, struct ptlrpc_request *req)
2540 int rc, serious = 0;
2545 LASSERT(h->mh_act != NULL);
2546 LASSERT(h->mh_opc == lustre_msg_get_opc(req->rq_reqmsg));
2547 LASSERT(current->journal_info == NULL);
2550 * Checking for various OBD_FAIL_$PREF_$OPC_NET codes. _Do_ not try
2551 * to put same checks into handlers like mdt_close(), mdt_reint(),
2552 * etc., without talking to mdt authors first. Checking same thing
2553 * there again is useless and returning 0 error without packing reply
2554 * is buggy! Handlers either pack reply or return error.
2556 * We return 0 here and do not send any reply in order to emulate
2557 * network failure. Do not send any reply in case any of NET related
2558 * fail_id has occured.
2560 if (OBD_FAIL_CHECK_ORSET(h->mh_fail_id, OBD_FAIL_ONCE))
2564 flags = h->mh_flags;
2565 LASSERT(ergo(flags & (HABEO_CORPUS|HABEO_REFERO), h->mh_fmt != NULL));
2567 if (h->mh_fmt != NULL) {
2568 req_capsule_set(info->mti_pill, h->mh_fmt);
2569 rc = mdt_unpack_req_pack_rep(info, flags);
2572 if (rc == 0 && flags & MUTABOR &&
2573 req->rq_export->exp_connect_flags & OBD_CONNECT_RDONLY)
2574 /* should it be rq_status? */
2577 if (rc == 0 && flags & HABEO_CLAVIS) {
2578 struct ldlm_request *dlm_req;
2580 LASSERT(h->mh_fmt != NULL);
2582 dlm_req = req_capsule_client_get(info->mti_pill, &RMF_DLM_REQ);
2583 if (dlm_req != NULL) {
2584 if (unlikely(dlm_req->lock_desc.l_resource.lr_type ==
2586 dlm_req->lock_desc.l_policy_data.\
2587 l_inodebits.bits == 0)) {
2589 * Lock without inodebits makes no sense and
2590 * will oops later in ldlm. If client miss to
2591 * set such bits, do not trigger ASSERTION.
2593 * For liblustre flock case, it maybe zero.
2597 if (info->mti_mdt->mdt_opts.mo_compat_resname)
2598 rc = mdt_lock_resname_compat(
2601 info->mti_dlm_req = dlm_req;
2608 /* capability setting changed via /proc, needs reinitialize ctxt */
2609 if (info->mti_mdt && info->mti_mdt->mdt_capa_conf) {
2610 mdt_init_capa_ctxt(info->mti_env, info->mti_mdt);
2611 info->mti_mdt->mdt_capa_conf = 0;
2614 if (likely(rc == 0)) {
2616 * Process request, there can be two types of rc:
2617 * 1) errors with msg unpack/pack, other failures outside the
2618 * operation itself. This is counted as serious errors;
2619 * 2) errors during fs operation, should be placed in rq_status
2622 rc = h->mh_act(info);
2624 !req->rq_no_reply && req->rq_reply_state == NULL) {
2625 DEBUG_REQ(D_ERROR, req, "MDT \"handler\" %s did not "
2626 "pack reply and returned 0 error\n",
2630 serious = is_serious(rc);
2631 rc = clear_serious(rc);
2635 req->rq_status = rc;
2638 * ELDLM_* codes which > 0 should be in rq_status only as well as
2639 * all non-serious errors.
2641 if (rc > 0 || !serious)
2644 LASSERT(current->journal_info == NULL);
2646 if (rc == 0 && (flags & HABEO_CLAVIS) &&
2647 info->mti_mdt->mdt_opts.mo_compat_resname) {
2648 struct ldlm_reply *dlmrep;
2650 dlmrep = req_capsule_server_get(info->mti_pill, &RMF_DLM_REP);
2652 rc = mdt_lock_reply_compat(info->mti_mdt, dlmrep);
2655 /* If we're DISCONNECTing, the mdt_export_data is already freed */
2656 if (likely(rc == 0 && req->rq_export && h->mh_opc != MDS_DISCONNECT))
2657 target_committed_to_req(req);
2659 if (unlikely(req_is_replay(req) &&
2660 lustre_msg_get_transno(req->rq_reqmsg) == 0)) {
2661 DEBUG_REQ(D_ERROR, req, "transno is 0 during REPLAY");
2665 target_send_reply(req, rc, info->mti_fail_id);
2669 void mdt_lock_handle_init(struct mdt_lock_handle *lh)
2671 lh->mlh_type = MDT_NUL_LOCK;
2672 lh->mlh_reg_lh.cookie = 0ull;
2673 lh->mlh_reg_mode = LCK_MINMODE;
2674 lh->mlh_pdo_lh.cookie = 0ull;
2675 lh->mlh_pdo_mode = LCK_MINMODE;
2678 void mdt_lock_handle_fini(struct mdt_lock_handle *lh)
2680 LASSERT(!lustre_handle_is_used(&lh->mlh_reg_lh));
2681 LASSERT(!lustre_handle_is_used(&lh->mlh_pdo_lh));
2685 * Initialize fields of struct mdt_thread_info. Other fields are left in
2686 * uninitialized state, because it's too expensive to zero out whole
2687 * mdt_thread_info (> 1K) on each request arrival.
2689 static void mdt_thread_info_init(struct ptlrpc_request *req,
2690 struct mdt_thread_info *info)
2693 struct md_capainfo *ci;
2695 req_capsule_init(&req->rq_pill, req, RCL_SERVER);
2696 info->mti_pill = &req->rq_pill;
2699 for (i = 0; i < ARRAY_SIZE(info->mti_lh); i++)
2700 mdt_lock_handle_init(&info->mti_lh[i]);
2702 /* mdt device: it can be NULL while CONNECT */
2703 if (req->rq_export) {
2704 info->mti_mdt = mdt_dev(req->rq_export->exp_obd->obd_lu_dev);
2705 info->mti_exp = req->rq_export;
2707 info->mti_mdt = NULL;
2708 info->mti_env = req->rq_svc_thread->t_env;
2709 ci = md_capainfo(info->mti_env);
2710 memset(ci, 0, sizeof *ci);
2711 if (req->rq_export) {
2712 if (exp_connect_rmtclient(req->rq_export))
2713 ci->mc_auth = LC_ID_CONVERT;
2714 else if (req->rq_export->exp_connect_flags &
2715 OBD_CONNECT_MDS_CAPA)
2716 ci->mc_auth = LC_ID_PLAIN;
2718 ci->mc_auth = LC_ID_NONE;
2721 info->mti_fail_id = OBD_FAIL_MDS_ALL_REPLY_NET;
2722 info->mti_transno = lustre_msg_get_transno(req->rq_reqmsg);
2723 info->mti_mos = NULL;
2725 memset(&info->mti_attr, 0, sizeof(info->mti_attr));
2726 info->mti_body = NULL;
2727 info->mti_object = NULL;
2728 info->mti_dlm_req = NULL;
2729 info->mti_has_trans = 0;
2730 info->mti_no_need_trans = 0;
2731 info->mti_cross_ref = 0;
2732 info->mti_opdata = 0;
2734 /* To not check for split by default. */
2735 info->mti_spec.sp_ck_split = 0;
2736 info->mti_spec.no_create = 0;
2739 static void mdt_thread_info_fini(struct mdt_thread_info *info)
2743 req_capsule_fini(info->mti_pill);
2744 if (info->mti_object != NULL) {
2746 * freeing an object may lead to OSD level transaction, do not
2747 * let it mess with MDT. bz19385.
2749 info->mti_no_need_trans = 1;
2750 mdt_object_put(info->mti_env, info->mti_object);
2751 info->mti_object = NULL;
2753 for (i = 0; i < ARRAY_SIZE(info->mti_lh); i++)
2754 mdt_lock_handle_fini(&info->mti_lh[i]);
2755 info->mti_env = NULL;
2758 static int mdt_filter_recovery_request(struct ptlrpc_request *req,
2759 struct obd_device *obd, int *process)
2761 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
2762 case MDS_CONNECT: /* This will never get here, but for completeness. */
2763 case OST_CONNECT: /* This will never get here, but for completeness. */
2764 case MDS_DISCONNECT:
2765 case OST_DISCONNECT:
2770 case MDS_DONE_WRITING:
2771 case MDS_SYNC: /* used in unmounting */
2777 *process = target_queue_recovery_request(req, obd);
2781 DEBUG_REQ(D_ERROR, req, "not permitted during recovery");
2788 * Handle recovery. Return:
2789 * +1: continue request processing;
2790 * -ve: abort immediately with the given error code;
2791 * 0: send reply with error code in req->rq_status;
2793 static int mdt_recovery(struct mdt_thread_info *info)
2795 struct ptlrpc_request *req = mdt_info_req(info);
2796 struct obd_device *obd;
2800 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
2803 case SEC_CTX_INIT_CONT:
2809 rc = mdt_handle_idmap(info);
2818 if (unlikely(!class_connected_export(req->rq_export))) {
2819 CERROR("operation %d on unconnected MDS from %s\n",
2820 lustre_msg_get_opc(req->rq_reqmsg),
2821 libcfs_id2str(req->rq_peer));
2822 /* FIXME: For CMD cleanup, when mds_B stop, the req from
2823 * mds_A will get -ENOTCONN(especially for ping req),
2824 * which will cause that mds_A deactive timeout, then when
2825 * mds_A cleanup, the cleanup process will be suspended since
2826 * deactive timeout is not zero.
2828 req->rq_status = -ENOTCONN;
2829 target_send_reply(req, -ENOTCONN, info->mti_fail_id);
2833 /* sanity check: if the xid matches, the request must be marked as a
2834 * resent or replayed */
2835 if (req_xid_is_last(req)) {
2836 if (!(lustre_msg_get_flags(req->rq_reqmsg) &
2837 (MSG_RESENT | MSG_REPLAY))) {
2838 DEBUG_REQ(D_WARNING, req, "rq_xid "LPU64" matches last_xid, "
2839 "expected REPLAY or RESENT flag (%x)", req->rq_xid,
2840 lustre_msg_get_flags(req->rq_reqmsg));
2842 req->rq_status = -ENOTCONN;
2847 /* else: note the opposite is not always true; a RESENT req after a
2848 * failover will usually not match the last_xid, since it was likely
2849 * never committed. A REPLAYed request will almost never match the
2850 * last xid, however it could for a committed, but still retained,
2853 obd = req->rq_export->exp_obd;
2855 /* Check for aborted recovery... */
2856 if (unlikely(obd->obd_recovering)) {
2859 DEBUG_REQ(D_INFO, req, "Got new replay");
2860 rc = mdt_filter_recovery_request(req, obd, &should_process);
2861 if (rc != 0 || !should_process)
2863 else if (should_process < 0) {
2864 req->rq_status = should_process;
2865 rc = ptlrpc_error(req);
2872 static int mdt_msg_check_version(struct lustre_msg *msg)
2876 switch (lustre_msg_get_opc(msg)) {
2878 case MDS_DISCONNECT:
2881 case SEC_CTX_INIT_CONT:
2883 rc = lustre_msg_check_version(msg, LUSTRE_OBD_VERSION);
2885 CERROR("bad opc %u version %08x, expecting %08x\n",
2886 lustre_msg_get_opc(msg),
2887 lustre_msg_get_version(msg),
2888 LUSTRE_OBD_VERSION);
2892 case MDS_GETATTR_NAME:
2899 case MDS_DONE_WRITING:
2906 case MDS_QUOTACHECK:
2912 rc = lustre_msg_check_version(msg, LUSTRE_MDS_VERSION);
2914 CERROR("bad opc %u version %08x, expecting %08x\n",
2915 lustre_msg_get_opc(msg),
2916 lustre_msg_get_version(msg),
2917 LUSTRE_MDS_VERSION);
2921 case LDLM_BL_CALLBACK:
2922 case LDLM_CP_CALLBACK:
2923 rc = lustre_msg_check_version(msg, LUSTRE_DLM_VERSION);
2925 CERROR("bad opc %u version %08x, expecting %08x\n",
2926 lustre_msg_get_opc(msg),
2927 lustre_msg_get_version(msg),
2928 LUSTRE_DLM_VERSION);
2930 case OBD_LOG_CANCEL:
2931 case LLOG_ORIGIN_HANDLE_CREATE:
2932 case LLOG_ORIGIN_HANDLE_NEXT_BLOCK:
2933 case LLOG_ORIGIN_HANDLE_READ_HEADER:
2934 case LLOG_ORIGIN_HANDLE_CLOSE:
2935 case LLOG_ORIGIN_HANDLE_DESTROY:
2936 case LLOG_ORIGIN_HANDLE_PREV_BLOCK:
2938 rc = lustre_msg_check_version(msg, LUSTRE_LOG_VERSION);
2940 CERROR("bad opc %u version %08x, expecting %08x\n",
2941 lustre_msg_get_opc(msg),
2942 lustre_msg_get_version(msg),
2943 LUSTRE_LOG_VERSION);
2946 CERROR("MDS unknown opcode %d\n", lustre_msg_get_opc(msg));
2952 static int mdt_handle0(struct ptlrpc_request *req,
2953 struct mdt_thread_info *info,
2954 struct mdt_opc_slice *supported)
2956 struct mdt_handler *h;
2957 struct lustre_msg *msg;
2962 if (OBD_FAIL_CHECK_ORSET(OBD_FAIL_MDS_ALL_REQUEST_NET, OBD_FAIL_ONCE))
2965 LASSERT(current->journal_info == NULL);
2967 msg = req->rq_reqmsg;
2968 rc = mdt_msg_check_version(msg);
2969 if (likely(rc == 0)) {
2970 rc = mdt_recovery(info);
2971 if (likely(rc == +1)) {
2972 h = mdt_handler_find(lustre_msg_get_opc(msg),
2974 if (likely(h != NULL)) {
2975 rc = mdt_req_handle(info, h, req);
2977 CERROR("The unsupported opc: 0x%x\n",
2978 lustre_msg_get_opc(msg) );
2979 req->rq_status = -ENOTSUPP;
2980 rc = ptlrpc_error(req);
2985 CERROR(LUSTRE_MDT_NAME" drops mal-formed request\n");
2990 * MDT handler function called by ptlrpc service thread when request comes.
2992 * XXX common "target" functionality should be factored into separate module
2993 * shared by mdt, ost and stand-alone services like fld.
2995 static int mdt_handle_common(struct ptlrpc_request *req,
2996 struct mdt_opc_slice *supported)
2999 struct mdt_thread_info *info;
3003 env = req->rq_svc_thread->t_env;
3004 LASSERT(env != NULL);
3005 LASSERT(env->le_ses != NULL);
3006 LASSERT(env->le_ctx.lc_thread == req->rq_svc_thread);
3007 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
3008 LASSERT(info != NULL);
3010 mdt_thread_info_init(req, info);
3012 rc = mdt_handle0(req, info, supported);
3014 mdt_thread_info_fini(info);
3019 * This is called from recovery code as handler of _all_ RPC types, FLD and SEQ
3022 int mdt_recovery_handle(struct ptlrpc_request *req)
3027 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
3029 rc = mdt_handle_common(req, mdt_fld_handlers);
3032 rc = mdt_handle_common(req, mdt_seq_handlers);
3035 rc = mdt_handle_common(req, mdt_regular_handlers);
3042 static int mdt_regular_handle(struct ptlrpc_request *req)
3044 return mdt_handle_common(req, mdt_regular_handlers);
3047 static int mdt_readpage_handle(struct ptlrpc_request *req)
3049 return mdt_handle_common(req, mdt_readpage_handlers);
3052 static int mdt_xmds_handle(struct ptlrpc_request *req)
3054 return mdt_handle_common(req, mdt_xmds_handlers);
3057 static int mdt_mdsc_handle(struct ptlrpc_request *req)
3059 return mdt_handle_common(req, mdt_seq_handlers);
3062 static int mdt_mdss_handle(struct ptlrpc_request *req)
3064 return mdt_handle_common(req, mdt_seq_handlers);
3067 static int mdt_dtss_handle(struct ptlrpc_request *req)
3069 return mdt_handle_common(req, mdt_seq_handlers);
3072 static int mdt_fld_handle(struct ptlrpc_request *req)
3074 return mdt_handle_common(req, mdt_fld_handlers);
3091 static int mdt_intent_getattr(enum mdt_it_code opcode,
3092 struct mdt_thread_info *info,
3093 struct ldlm_lock **,
3095 static int mdt_intent_reint(enum mdt_it_code opcode,
3096 struct mdt_thread_info *info,
3097 struct ldlm_lock **,
3100 static struct mdt_it_flavor {
3101 const struct req_format *it_fmt;
3103 int (*it_act)(enum mdt_it_code ,
3104 struct mdt_thread_info *,
3105 struct ldlm_lock **,
3108 } mdt_it_flavor[] = {
3110 .it_fmt = &RQF_LDLM_INTENT,
3111 /*.it_flags = HABEO_REFERO,*/
3113 .it_act = mdt_intent_reint,
3114 .it_reint = REINT_OPEN
3117 .it_fmt = &RQF_LDLM_INTENT,
3118 .it_flags = MUTABOR,
3119 .it_act = mdt_intent_reint,
3120 .it_reint = REINT_OPEN
3123 .it_fmt = &RQF_LDLM_INTENT,
3124 .it_flags = MUTABOR,
3125 .it_act = mdt_intent_reint,
3126 .it_reint = REINT_CREATE
3128 [MDT_IT_GETATTR] = {
3129 .it_fmt = &RQF_LDLM_INTENT_GETATTR,
3130 .it_flags = HABEO_REFERO,
3131 .it_act = mdt_intent_getattr
3133 [MDT_IT_READDIR] = {
3139 .it_fmt = &RQF_LDLM_INTENT_GETATTR,
3140 .it_flags = HABEO_REFERO,
3141 .it_act = mdt_intent_getattr
3144 .it_fmt = &RQF_LDLM_INTENT_UNLINK,
3145 .it_flags = MUTABOR,
3147 .it_reint = REINT_UNLINK
3151 .it_flags = MUTABOR,
3154 [MDT_IT_GETXATTR] = {
3160 .it_fmt = &RQF_LDLM_INTENT_GETATTR,
3161 .it_flags = HABEO_REFERO,
3162 .it_act = mdt_intent_getattr
3166 int mdt_intent_lock_replace(struct mdt_thread_info *info,
3167 struct ldlm_lock **lockp,
3168 struct ldlm_lock *new_lock,
3169 struct mdt_lock_handle *lh,
3172 struct ptlrpc_request *req = mdt_info_req(info);
3173 struct ldlm_lock *lock = *lockp;
3176 * Get new lock only for cases when possible resent did not find any
3179 if (new_lock == NULL)
3180 new_lock = ldlm_handle2lock_long(&lh->mlh_reg_lh, 0);
3182 if (new_lock == NULL && (flags & LDLM_FL_INTENT_ONLY)) {
3183 lh->mlh_reg_lh.cookie = 0;
3187 LASSERTF(new_lock != NULL,
3188 "lockh "LPX64"\n", lh->mlh_reg_lh.cookie);
3191 * If we've already given this lock to a client once, then we should
3192 * have no readers or writers. Otherwise, we should have one reader
3193 * _or_ writer ref (which will be zeroed below) before returning the
3196 if (new_lock->l_export == req->rq_export) {
3197 LASSERT(new_lock->l_readers + new_lock->l_writers == 0);
3199 LASSERT(new_lock->l_export == NULL);
3200 LASSERT(new_lock->l_readers + new_lock->l_writers == 1);
3205 if (new_lock->l_export == req->rq_export) {
3207 * Already gave this to the client, which means that we
3208 * reconstructed a reply.
3210 LASSERT(lustre_msg_get_flags(req->rq_reqmsg) &
3212 lh->mlh_reg_lh.cookie = 0;
3213 RETURN(ELDLM_LOCK_REPLACED);
3217 * Fixup the lock to be given to the client.
3219 lock_res_and_lock(new_lock);
3220 /* Zero new_lock->l_readers and new_lock->l_writers without triggering
3221 * possible blocking AST. */
3222 while (new_lock->l_readers > 0) {
3223 lu_ref_del(&new_lock->l_reference, "reader", new_lock);
3224 lu_ref_del(&new_lock->l_reference, "user", new_lock);
3225 new_lock->l_readers--;
3227 while (new_lock->l_writers > 0) {
3228 lu_ref_del(&new_lock->l_reference, "writer", new_lock);
3229 lu_ref_del(&new_lock->l_reference, "user", new_lock);
3230 new_lock->l_writers--;
3233 new_lock->l_export = class_export_lock_get(req->rq_export, new_lock);
3234 new_lock->l_blocking_ast = lock->l_blocking_ast;
3235 new_lock->l_completion_ast = lock->l_completion_ast;
3236 new_lock->l_remote_handle = lock->l_remote_handle;
3237 new_lock->l_flags &= ~LDLM_FL_LOCAL;
3239 unlock_res_and_lock(new_lock);
3241 cfs_hash_add(new_lock->l_export->exp_lock_hash,
3242 &new_lock->l_remote_handle,
3243 &new_lock->l_exp_hash);
3245 LDLM_LOCK_RELEASE(new_lock);
3246 lh->mlh_reg_lh.cookie = 0;
3248 RETURN(ELDLM_LOCK_REPLACED);
3251 static void mdt_intent_fixup_resent(struct mdt_thread_info *info,
3252 struct ldlm_lock *new_lock,
3253 struct ldlm_lock **old_lock,
3254 struct mdt_lock_handle *lh)
3256 struct ptlrpc_request *req = mdt_info_req(info);
3257 struct obd_export *exp = req->rq_export;
3258 struct lustre_handle remote_hdl;
3259 struct ldlm_request *dlmreq;
3260 struct ldlm_lock *lock;
3262 if (!(lustre_msg_get_flags(req->rq_reqmsg) & MSG_RESENT))
3265 dlmreq = req_capsule_client_get(info->mti_pill, &RMF_DLM_REQ);
3266 remote_hdl = dlmreq->lock_handle[0];
3268 lock = cfs_hash_lookup(exp->exp_lock_hash, &remote_hdl);
3270 if (lock != new_lock) {
3271 lh->mlh_reg_lh.cookie = lock->l_handle.h_cookie;
3272 lh->mlh_reg_mode = lock->l_granted_mode;
3274 LDLM_DEBUG(lock, "Restoring lock cookie");
3275 DEBUG_REQ(D_DLMTRACE, req,
3276 "restoring lock cookie "LPX64,
3277 lh->mlh_reg_lh.cookie);
3279 *old_lock = LDLM_LOCK_GET(lock);
3280 cfs_hash_put(exp->exp_lock_hash, &lock->l_exp_hash);
3284 cfs_hash_put(exp->exp_lock_hash, &lock->l_exp_hash);
3288 * If the xid matches, then we know this is a resent request, and allow
3289 * it. (It's probably an OPEN, for which we don't send a lock.
3291 if (req_xid_is_last(req))
3295 * This remote handle isn't enqueued, so we never received or processed
3296 * this request. Clear MSG_RESENT, because it can be handled like any
3297 * normal request now.
3299 lustre_msg_clear_flags(req->rq_reqmsg, MSG_RESENT);
3301 DEBUG_REQ(D_DLMTRACE, req, "no existing lock with rhandle "LPX64,
3305 static int mdt_intent_getattr(enum mdt_it_code opcode,
3306 struct mdt_thread_info *info,
3307 struct ldlm_lock **lockp,
3310 struct mdt_lock_handle *lhc = &info->mti_lh[MDT_LH_RMT];
3311 struct ldlm_lock *new_lock = NULL;
3313 struct ldlm_reply *ldlm_rep;
3314 struct ptlrpc_request *req;
3315 struct mdt_body *reqbody;
3316 struct mdt_body *repbody;
3320 reqbody = req_capsule_client_get(info->mti_pill, &RMF_MDT_BODY);
3323 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
3326 info->mti_spec.sp_ck_split = !!(reqbody->valid & OBD_MD_FLCKSPLIT);
3327 info->mti_cross_ref = !!(reqbody->valid & OBD_MD_FLCROSSREF);
3328 repbody->eadatasize = 0;
3329 repbody->aclsize = 0;
3333 child_bits = MDS_INODELOCK_LOOKUP;
3335 case MDT_IT_GETATTR:
3336 child_bits = MDS_INODELOCK_LOOKUP | MDS_INODELOCK_UPDATE;
3338 case MDT_IT_LAYOUT: {
3339 static int printed = 0;
3342 CERROR("layout lock not supported by this version\n");
3345 GOTO(out_shrink, rc = -EINVAL);
3349 CERROR("Unsupported intent (%d)\n", opcode);
3350 GOTO(out_shrink, rc = -EINVAL);
3353 rc = mdt_init_ucred(info, reqbody);
3355 GOTO(out_shrink, rc);
3357 req = info->mti_pill->rc_req;
3358 ldlm_rep = req_capsule_server_get(info->mti_pill, &RMF_DLM_REP);
3359 mdt_set_disposition(info, ldlm_rep, DISP_IT_EXECD);
3361 /* Get lock from request for possible resent case. */
3362 mdt_intent_fixup_resent(info, *lockp, &new_lock, lhc);
3364 ldlm_rep->lock_policy_res2 =
3365 mdt_getattr_name_lock(info, lhc, child_bits, ldlm_rep);
3367 if (mdt_get_disposition(ldlm_rep, DISP_LOOKUP_NEG))
3368 ldlm_rep->lock_policy_res2 = 0;
3369 if (!mdt_get_disposition(ldlm_rep, DISP_LOOKUP_POS) ||
3370 ldlm_rep->lock_policy_res2) {
3371 lhc->mlh_reg_lh.cookie = 0ull;
3372 GOTO(out_ucred, rc = ELDLM_LOCK_ABORTED);
3375 rc = mdt_intent_lock_replace(info, lockp, new_lock, lhc, flags);
3378 mdt_exit_ucred(info);
3380 mdt_client_compatibility(info);
3381 rc2 = mdt_fix_reply(info);
3387 static int mdt_intent_reint(enum mdt_it_code opcode,
3388 struct mdt_thread_info *info,
3389 struct ldlm_lock **lockp,
3392 struct mdt_lock_handle *lhc = &info->mti_lh[MDT_LH_RMT];
3393 struct ldlm_reply *rep = NULL;
3397 static const struct req_format *intent_fmts[REINT_MAX] = {
3398 [REINT_CREATE] = &RQF_LDLM_INTENT_CREATE,
3399 [REINT_OPEN] = &RQF_LDLM_INTENT_OPEN
3404 opc = mdt_reint_opcode(info, intent_fmts);
3408 if (mdt_it_flavor[opcode].it_reint != opc) {
3409 CERROR("Reint code %ld doesn't match intent: %d\n",
3411 RETURN(err_serious(-EPROTO));
3414 /* Get lock from request for possible resent case. */
3415 mdt_intent_fixup_resent(info, *lockp, NULL, lhc);
3417 rc = mdt_reint_internal(info, lhc, opc);
3419 /* Check whether the reply has been packed successfully. */
3420 if (mdt_info_req(info)->rq_repmsg != NULL)
3421 rep = req_capsule_server_get(info->mti_pill, &RMF_DLM_REP);
3423 RETURN(err_serious(-EFAULT));
3425 /* MDC expects this in any case */
3427 mdt_set_disposition(info, rep, DISP_LOOKUP_EXECD);
3429 /* Cross-ref case, the lock should be returned to the client */
3430 if (rc == -EREMOTE) {
3431 LASSERT(lustre_handle_is_used(&lhc->mlh_reg_lh));
3432 rep->lock_policy_res2 = 0;
3433 rc = mdt_intent_lock_replace(info, lockp, NULL, lhc, flags);
3436 rep->lock_policy_res2 = clear_serious(rc);
3438 if (rep->lock_policy_res2 == -ENOENT &&
3439 mdt_get_disposition(rep, DISP_LOOKUP_NEG))
3440 rep->lock_policy_res2 = 0;
3442 if (rc == -ENOTCONN || rc == -ENODEV ||
3443 rc == -EOVERFLOW) { /**< if VBR failure then return error */
3445 * If it is the disconnect error (ENODEV & ENOCONN), the error
3446 * will be returned by rq_status, and client at ptlrpc layer
3447 * will detect this, then disconnect, reconnect the import
3448 * immediately, instead of impacting the following the rpc.
3450 lhc->mlh_reg_lh.cookie = 0ull;
3454 * For other cases, the error will be returned by intent.
3455 * and client will retrieve the result from intent.
3458 * FIXME: when open lock is finished, that should be
3461 if (lustre_handle_is_used(&lhc->mlh_reg_lh)) {
3462 LASSERTF(rc == 0, "Error occurred but lock handle "
3463 "is still in use\n");
3464 rep->lock_policy_res2 = 0;
3465 rc = mdt_intent_lock_replace(info, lockp, NULL, lhc, flags);
3468 lhc->mlh_reg_lh.cookie = 0ull;
3469 RETURN(ELDLM_LOCK_ABORTED);
3474 static int mdt_intent_code(long itcode)
3482 case IT_OPEN|IT_CREAT:
3489 rc = MDT_IT_READDIR;
3492 rc = MDT_IT_GETATTR;
3504 rc = MDT_IT_GETXATTR;
3510 CERROR("Unknown intent opcode: %ld\n", itcode);
3517 static int mdt_intent_opc(long itopc, struct mdt_thread_info *info,
3518 struct ldlm_lock **lockp, int flags)
3520 struct req_capsule *pill;
3521 struct mdt_it_flavor *flv;
3526 opc = mdt_intent_code(itopc);
3530 pill = info->mti_pill;
3531 flv = &mdt_it_flavor[opc];
3533 if (flv->it_fmt != NULL)
3534 req_capsule_extend(pill, flv->it_fmt);
3536 rc = mdt_unpack_req_pack_rep(info, flv->it_flags);
3538 struct ptlrpc_request *req = mdt_info_req(info);
3539 if (flv->it_flags & MUTABOR &&
3540 req->rq_export->exp_connect_flags & OBD_CONNECT_RDONLY)
3543 if (rc == 0 && flv->it_act != NULL) {
3544 /* execute policy */
3545 rc = flv->it_act(opc, info, lockp, flags);
3552 static int mdt_intent_policy(struct ldlm_namespace *ns,
3553 struct ldlm_lock **lockp, void *req_cookie,
3554 ldlm_mode_t mode, int flags, void *data)
3556 struct mdt_thread_info *info;
3557 struct ptlrpc_request *req = req_cookie;
3558 struct ldlm_intent *it;
3559 struct req_capsule *pill;
3564 LASSERT(req != NULL);
3566 info = lu_context_key_get(&req->rq_svc_thread->t_env->le_ctx,
3568 LASSERT(info != NULL);
3569 pill = info->mti_pill;
3570 LASSERT(pill->rc_req == req);
3572 if (req->rq_reqmsg->lm_bufcount > DLM_INTENT_IT_OFF) {
3573 req_capsule_extend(pill, &RQF_LDLM_INTENT);
3574 it = req_capsule_client_get(pill, &RMF_LDLM_INTENT);
3576 rc = mdt_intent_opc(it->opc, info, lockp, flags);
3580 /* Lock without inodebits makes no sense and will oops
3581 * later in ldlm. Let's check it now to see if we have
3582 * ibits corrupted somewhere in mdt_intent_opc().
3583 * The case for client miss to set ibits has been
3584 * processed by others. */
3585 LASSERT(ergo(info->mti_dlm_req->lock_desc.l_resource.\
3586 lr_type == LDLM_IBITS,
3587 info->mti_dlm_req->lock_desc.\
3588 l_policy_data.l_inodebits.bits != 0));
3590 rc = err_serious(-EFAULT);
3592 /* No intent was provided */
3593 LASSERT(pill->rc_fmt == &RQF_LDLM_ENQUEUE);
3594 rc = req_capsule_server_pack(pill);
3596 rc = err_serious(rc);
3601 static int mdt_seq_fini(const struct lu_env *env,
3602 struct mdt_device *m)
3604 struct md_site *ms = mdt_md_site(m);
3608 if (ms->ms_server_seq) {
3609 seq_server_fini(ms->ms_server_seq, env);
3610 OBD_FREE_PTR(ms->ms_server_seq);
3611 ms->ms_server_seq = NULL;
3614 if (ms->ms_control_seq) {
3615 seq_server_fini(ms->ms_control_seq, env);
3616 OBD_FREE_PTR(ms->ms_control_seq);
3617 ms->ms_control_seq = NULL;
3620 if (ms->ms_client_seq) {
3621 seq_client_fini(ms->ms_client_seq);
3622 OBD_FREE_PTR(ms->ms_client_seq);
3623 ms->ms_client_seq = NULL;
3630 static int mdt_seq_init(const struct lu_env *env,
3632 struct mdt_device *m)
3639 ms = mdt_md_site(m);
3642 * This is sequence-controller node. Init seq-controller server on local
3645 if (ms->ms_node_id == 0) {
3646 LASSERT(ms->ms_control_seq == NULL);
3648 OBD_ALLOC_PTR(ms->ms_control_seq);
3649 if (ms->ms_control_seq == NULL)
3652 rc = seq_server_init(ms->ms_control_seq,
3653 m->mdt_bottom, uuid,
3654 LUSTRE_SEQ_CONTROLLER,
3659 GOTO(out_seq_fini, rc);
3661 OBD_ALLOC_PTR(ms->ms_client_seq);
3662 if (ms->ms_client_seq == NULL)
3663 GOTO(out_seq_fini, rc = -ENOMEM);
3665 OBD_ALLOC(prefix, MAX_OBD_NAME + 5);
3666 if (prefix == NULL) {
3667 OBD_FREE_PTR(ms->ms_client_seq);
3668 GOTO(out_seq_fini, rc = -ENOMEM);
3671 snprintf(prefix, MAX_OBD_NAME + 5, "ctl-%s",
3675 * Init seq-controller client after seq-controller server is
3676 * ready. Pass ms->ms_control_seq to it for direct talking.
3678 rc = seq_client_init(ms->ms_client_seq, NULL,
3679 LUSTRE_SEQ_METADATA, prefix,
3680 ms->ms_control_seq);
3681 OBD_FREE(prefix, MAX_OBD_NAME + 5);
3684 GOTO(out_seq_fini, rc);
3687 /* Init seq-server on local MDT */
3688 LASSERT(ms->ms_server_seq == NULL);
3690 OBD_ALLOC_PTR(ms->ms_server_seq);
3691 if (ms->ms_server_seq == NULL)
3692 GOTO(out_seq_fini, rc = -ENOMEM);
3694 rc = seq_server_init(ms->ms_server_seq,
3695 m->mdt_bottom, uuid,
3700 GOTO(out_seq_fini, rc = -ENOMEM);
3702 /* Assign seq-controller client to local seq-server. */
3703 if (ms->ms_node_id == 0) {
3704 LASSERT(ms->ms_client_seq != NULL);
3706 rc = seq_server_set_cli(ms->ms_server_seq,
3714 mdt_seq_fini(env, m);
3719 * Init client sequence manager which is used by local MDS to talk to sequence
3720 * controller on remote node.
3722 static int mdt_seq_init_cli(const struct lu_env *env,
3723 struct mdt_device *m,
3724 struct lustre_cfg *cfg)
3726 struct md_site *ms = mdt_md_site(m);
3727 struct obd_device *mdc;
3728 struct obd_uuid *uuidp, *mdcuuidp;
3729 char *uuid_str, *mdc_uuid_str;
3732 struct mdt_thread_info *info;
3733 char *p, *index_string = lustre_cfg_string(cfg, 2);
3736 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
3737 uuidp = &info->mti_u.uuid[0];
3738 mdcuuidp = &info->mti_u.uuid[1];
3740 LASSERT(index_string);
3742 index = simple_strtol(index_string, &p, 10);
3744 CERROR("Invalid index in lustre_cgf, offset 2\n");
3748 /* check if this is adding the first MDC and controller is not yet
3750 if (index != 0 || ms->ms_client_seq)
3753 uuid_str = lustre_cfg_string(cfg, 1);
3754 mdc_uuid_str = lustre_cfg_string(cfg, 4);
3755 obd_str2uuid(uuidp, uuid_str);
3756 obd_str2uuid(mdcuuidp, mdc_uuid_str);
3758 mdc = class_find_client_obd(uuidp, LUSTRE_MDC_NAME, mdcuuidp);
3760 CERROR("can't find controller MDC by uuid %s\n",
3763 } else if (!mdc->obd_set_up) {
3764 CERROR("target %s not set up\n", mdc->obd_name);
3767 LASSERT(ms->ms_control_exp);
3768 OBD_ALLOC_PTR(ms->ms_client_seq);
3769 if (ms->ms_client_seq != NULL) {
3772 OBD_ALLOC(prefix, MAX_OBD_NAME + 5);
3776 snprintf(prefix, MAX_OBD_NAME + 5, "ctl-%s",
3779 rc = seq_client_init(ms->ms_client_seq,
3781 LUSTRE_SEQ_METADATA,
3783 OBD_FREE(prefix, MAX_OBD_NAME + 5);
3790 LASSERT(ms->ms_server_seq != NULL);
3791 rc = seq_server_set_cli(ms->ms_server_seq, ms->ms_client_seq,
3798 static void mdt_seq_fini_cli(struct mdt_device *m)
3804 ms = mdt_md_site(m);
3807 if (ms->ms_server_seq)
3808 seq_server_set_cli(ms->ms_server_seq,
3811 if (ms->ms_control_exp) {
3812 class_export_put(ms->ms_control_exp);
3813 ms->ms_control_exp = NULL;
3822 static int mdt_fld_fini(const struct lu_env *env,
3823 struct mdt_device *m)
3825 struct md_site *ms = mdt_md_site(m);
3828 if (ms && ms->ms_server_fld) {
3829 fld_server_fini(ms->ms_server_fld, env);
3830 OBD_FREE_PTR(ms->ms_server_fld);
3831 ms->ms_server_fld = NULL;
3837 static int mdt_fld_init(const struct lu_env *env,
3839 struct mdt_device *m)
3845 ms = mdt_md_site(m);
3847 OBD_ALLOC_PTR(ms->ms_server_fld);
3848 if (ms->ms_server_fld == NULL)
3849 RETURN(rc = -ENOMEM);
3851 rc = fld_server_init(ms->ms_server_fld,
3852 m->mdt_bottom, uuid,
3853 env, ms->ms_node_id);
3855 OBD_FREE_PTR(ms->ms_server_fld);
3856 ms->ms_server_fld = NULL;
3863 /* device init/fini methods */
3864 static void mdt_stop_ptlrpc_service(struct mdt_device *m)
3867 if (m->mdt_regular_service != NULL) {
3868 ptlrpc_unregister_service(m->mdt_regular_service);
3869 m->mdt_regular_service = NULL;
3871 if (m->mdt_readpage_service != NULL) {
3872 ptlrpc_unregister_service(m->mdt_readpage_service);
3873 m->mdt_readpage_service = NULL;
3875 if (m->mdt_xmds_service != NULL) {
3876 ptlrpc_unregister_service(m->mdt_xmds_service);
3877 m->mdt_xmds_service = NULL;
3879 if (m->mdt_setattr_service != NULL) {
3880 ptlrpc_unregister_service(m->mdt_setattr_service);
3881 m->mdt_setattr_service = NULL;
3883 if (m->mdt_mdsc_service != NULL) {
3884 ptlrpc_unregister_service(m->mdt_mdsc_service);
3885 m->mdt_mdsc_service = NULL;
3887 if (m->mdt_mdss_service != NULL) {
3888 ptlrpc_unregister_service(m->mdt_mdss_service);
3889 m->mdt_mdss_service = NULL;
3891 if (m->mdt_dtss_service != NULL) {
3892 ptlrpc_unregister_service(m->mdt_dtss_service);
3893 m->mdt_dtss_service = NULL;
3895 if (m->mdt_fld_service != NULL) {
3896 ptlrpc_unregister_service(m->mdt_fld_service);
3897 m->mdt_fld_service = NULL;
3902 static int mdt_start_ptlrpc_service(struct mdt_device *m)
3904 static struct ptlrpc_service_conf conf;
3905 cfs_proc_dir_entry_t *procfs_entry;
3909 m->mdt_ldlm_client = &m->mdt_md_dev.md_lu_dev.ld_obd->obd_ldlm_client;
3910 ptlrpc_init_client(LDLM_CB_REQUEST_PORTAL, LDLM_CB_REPLY_PORTAL,
3911 "mdt_ldlm_client", m->mdt_ldlm_client);
3913 procfs_entry = m->mdt_md_dev.md_lu_dev.ld_obd->obd_proc_entry;
3915 conf = (typeof(conf)) {
3916 .psc_name = LUSTRE_MDT_NAME,
3917 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
3919 .bc_nbufs = MDS_NBUFS,
3920 .bc_buf_size = MDS_BUFSIZE,
3921 .bc_req_max_size = MDS_MAXREQSIZE,
3922 .bc_rep_max_size = MDS_MAXREPSIZE,
3923 .bc_req_portal = MDS_REQUEST_PORTAL,
3924 .bc_rep_portal = MDC_REPLY_PORTAL,
3927 * We'd like to have a mechanism to set this on a per-device
3928 * basis, but alas...
3931 .tc_thr_name = LUSTRE_MDT_NAME,
3932 .tc_nthrs_min = MDT_MIN_THREADS,
3933 .tc_nthrs_max = MDT_MAX_THREADS,
3934 .tc_nthrs_user = mdt_num_threads,
3935 .tc_ctx_tags = LCT_MD_THREAD,
3938 .so_req_handler = mdt_regular_handle,
3939 .so_req_printer = target_print_req,
3942 m->mdt_regular_service = ptlrpc_register_service(&conf, procfs_entry);
3943 if (IS_ERR(m->mdt_regular_service)) {
3944 rc = PTR_ERR(m->mdt_regular_service);
3945 CERROR("failed to start regular mdt service: %d\n", rc);
3946 m->mdt_regular_service = NULL;
3952 * readpage service configuration. Parameters have to be adjusted,
3955 memset(&conf, 0, sizeof(conf));
3956 conf = (typeof(conf)) {
3957 .psc_name = LUSTRE_MDT_NAME "_readpage",
3958 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
3960 .bc_nbufs = MDS_NBUFS,
3961 .bc_buf_size = MDS_BUFSIZE,
3962 .bc_req_max_size = MDS_MAXREQSIZE,
3963 .bc_rep_max_size = MDS_MAXREPSIZE,
3964 .bc_req_portal = MDS_READPAGE_PORTAL,
3965 .bc_rep_portal = MDC_REPLY_PORTAL,
3968 .tc_thr_name = "mdt_rdpg",
3969 .tc_nthrs_min = MDT_MIN_THREADS,
3970 .tc_nthrs_max = MDT_MAX_THREADS,
3971 .tc_nthrs_user = mdt_num_threads,
3972 .tc_ctx_tags = LCT_MD_THREAD,
3975 .so_req_handler = mdt_readpage_handle,
3976 .so_req_printer = target_print_req,
3979 m->mdt_readpage_service = ptlrpc_register_service(&conf, procfs_entry);
3980 if (IS_ERR(m->mdt_readpage_service)) {
3981 rc = PTR_ERR(m->mdt_readpage_service);
3982 CERROR("failed to start readpage service: %d\n", rc);
3983 m->mdt_readpage_service = NULL;
3985 GOTO(err_mdt_svc, rc);
3989 * setattr service configuration.
3991 * XXX To keep the compatibility with old client(< 2.2), we need to
3992 * preserve this portal for a certain time, it should be removed
3993 * eventually. LU-617.
3995 memset(&conf, 0, sizeof(conf));
3996 conf = (typeof(conf)) {
3997 .psc_name = LUSTRE_MDT_NAME "_setattr",
3998 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
4000 .bc_nbufs = MDS_NBUFS,
4001 .bc_buf_size = MDS_BUFSIZE,
4002 .bc_req_max_size = MDS_MAXREQSIZE,
4003 .bc_rep_max_size = MDS_MAXREPSIZE,
4004 .bc_req_portal = MDS_SETATTR_PORTAL,
4005 .bc_rep_portal = MDC_REPLY_PORTAL,
4008 .tc_thr_name = "mdt_attr",
4009 .tc_nthrs_min = MDT_MIN_THREADS,
4010 .tc_nthrs_max = MDT_MAX_THREADS,
4011 .tc_nthrs_user = mdt_num_threads,
4012 .tc_ctx_tags = LCT_MD_THREAD,
4015 .so_req_handler = mdt_regular_handle,
4016 .so_req_printer = target_print_req,
4019 m->mdt_setattr_service = ptlrpc_register_service(&conf, procfs_entry);
4020 if (IS_ERR(m->mdt_setattr_service)) {
4021 rc = PTR_ERR(m->mdt_setattr_service);
4022 CERROR("failed to start setattr service: %d\n", rc);
4023 m->mdt_setattr_service = NULL;
4025 GOTO(err_mdt_svc, rc);
4029 * sequence controller service configuration
4031 memset(&conf, 0, sizeof(conf));
4032 conf = (typeof(conf)) {
4033 .psc_name = LUSTRE_MDT_NAME "_mdsc",
4034 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
4036 .bc_nbufs = MDS_NBUFS,
4037 .bc_buf_size = MDS_BUFSIZE,
4038 .bc_req_max_size = SEQ_MAXREQSIZE,
4039 .bc_rep_max_size = SEQ_MAXREPSIZE,
4040 .bc_req_portal = SEQ_CONTROLLER_PORTAL,
4041 .bc_rep_portal = MDC_REPLY_PORTAL,
4044 .tc_thr_name = "mdt_mdsc",
4045 .tc_nthrs_min = MDT_MIN_THREADS,
4046 .tc_nthrs_max = MDT_MAX_THREADS,
4047 .tc_nthrs_user = mdt_num_threads,
4048 .tc_ctx_tags = LCT_MD_THREAD,
4051 .so_req_handler = mdt_mdsc_handle,
4052 .so_req_printer = target_print_req,
4055 m->mdt_mdsc_service = ptlrpc_register_service(&conf, procfs_entry);
4056 if (IS_ERR(m->mdt_mdsc_service)) {
4057 rc = PTR_ERR(m->mdt_mdsc_service);
4058 CERROR("failed to start seq controller service: %d\n", rc);
4059 m->mdt_mdsc_service = NULL;
4061 GOTO(err_mdt_svc, rc);
4065 * metadata sequence server service configuration
4067 memset(&conf, 0, sizeof(conf));
4068 conf = (typeof(conf)) {
4069 .psc_name = LUSTRE_MDT_NAME "_mdss",
4070 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
4072 .bc_nbufs = MDS_NBUFS,
4073 .bc_buf_size = MDS_BUFSIZE,
4074 .bc_req_max_size = SEQ_MAXREQSIZE,
4075 .bc_rep_max_size = SEQ_MAXREPSIZE,
4076 .bc_req_portal = SEQ_METADATA_PORTAL,
4077 .bc_rep_portal = MDC_REPLY_PORTAL,
4080 .tc_thr_name = "mdt_mdss",
4081 .tc_nthrs_min = MDT_MIN_THREADS,
4082 .tc_nthrs_max = MDT_MAX_THREADS,
4083 .tc_nthrs_user = mdt_num_threads,
4084 .tc_ctx_tags = LCT_MD_THREAD | LCT_DT_THREAD
4087 .so_req_handler = mdt_mdss_handle,
4088 .so_req_printer = target_print_req,
4091 m->mdt_mdss_service = ptlrpc_register_service(&conf, procfs_entry);
4092 if (IS_ERR(m->mdt_mdss_service)) {
4093 rc = PTR_ERR(m->mdt_mdss_service);
4094 CERROR("failed to start metadata seq server service: %d\n", rc);
4095 m->mdt_mdss_service = NULL;
4097 GOTO(err_mdt_svc, rc);
4101 * Data sequence server service configuration. We want to have really
4102 * cluster-wide sequences space. This is why we start only one sequence
4103 * controller which manages space.
4105 memset(&conf, 0, sizeof(conf));
4106 conf = (typeof(conf)) {
4107 .psc_name = LUSTRE_MDT_NAME "_dtss",
4108 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
4110 .bc_nbufs = MDS_NBUFS,
4111 .bc_buf_size = MDS_BUFSIZE,
4112 .bc_req_max_size = SEQ_MAXREQSIZE,
4113 .bc_rep_max_size = SEQ_MAXREPSIZE,
4114 .bc_req_portal = SEQ_DATA_PORTAL,
4115 .bc_rep_portal = OSC_REPLY_PORTAL,
4118 .tc_thr_name = "mdt_dtss",
4119 .tc_nthrs_min = MDT_MIN_THREADS,
4120 .tc_nthrs_max = MDT_MAX_THREADS,
4121 .tc_nthrs_user = mdt_num_threads,
4122 .tc_ctx_tags = LCT_MD_THREAD | LCT_DT_THREAD
4125 .so_req_handler = mdt_dtss_handle,
4126 .so_req_printer = target_print_req,
4129 m->mdt_dtss_service = ptlrpc_register_service(&conf, procfs_entry);
4130 if (IS_ERR(m->mdt_dtss_service)) {
4131 rc = PTR_ERR(m->mdt_dtss_service);
4132 CERROR("failed to start data seq server service: %d\n", rc);
4133 m->mdt_dtss_service = NULL;
4135 GOTO(err_mdt_svc, rc);
4138 /* FLD service start */
4139 memset(&conf, 0, sizeof(conf));
4140 conf = (typeof(conf)) {
4141 .psc_name = LUSTRE_MDT_NAME "_fld",
4142 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
4144 .bc_nbufs = MDS_NBUFS,
4145 .bc_buf_size = MDS_BUFSIZE,
4146 .bc_req_max_size = FLD_MAXREQSIZE,
4147 .bc_rep_max_size = FLD_MAXREPSIZE,
4148 .bc_req_portal = FLD_REQUEST_PORTAL,
4149 .bc_rep_portal = MDC_REPLY_PORTAL,
4152 .tc_thr_name = "mdt_fld",
4153 .tc_nthrs_min = MDT_MIN_THREADS,
4154 .tc_nthrs_max = MDT_MAX_THREADS,
4155 .tc_nthrs_user = mdt_num_threads,
4156 .tc_ctx_tags = LCT_DT_THREAD | LCT_MD_THREAD
4159 .so_req_handler = mdt_fld_handle,
4160 .so_req_printer = target_print_req,
4163 m->mdt_fld_service = ptlrpc_register_service(&conf, procfs_entry);
4164 if (IS_ERR(m->mdt_fld_service)) {
4165 rc = PTR_ERR(m->mdt_fld_service);
4166 CERROR("failed to start fld service: %d\n", rc);
4167 m->mdt_fld_service = NULL;
4169 GOTO(err_mdt_svc, rc);
4173 * mds-mds service configuration. Separate portal is used to allow
4174 * mds-mds requests be not blocked during recovery.
4176 memset(&conf, 0, sizeof(conf));
4177 conf = (typeof(conf)) {
4178 .psc_name = LUSTRE_MDT_NAME "_mds",
4179 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
4181 .bc_nbufs = MDS_NBUFS,
4182 .bc_buf_size = MDS_BUFSIZE,
4183 .bc_req_max_size = MDS_MAXREQSIZE,
4184 .bc_rep_max_size = MDS_MAXREPSIZE,
4185 .bc_req_portal = MDS_MDS_PORTAL,
4186 .bc_rep_portal = MDC_REPLY_PORTAL,
4189 .tc_thr_name = "mdt_mds",
4190 .tc_nthrs_min = MDT_MIN_THREADS,
4191 .tc_nthrs_max = MDT_MAX_THREADS,
4192 .tc_nthrs_user = mdt_num_threads,
4193 .tc_ctx_tags = LCT_MD_THREAD,
4196 .so_req_handler = mdt_xmds_handle,
4197 .so_req_printer = target_print_req,
4200 m->mdt_xmds_service = ptlrpc_register_service(&conf, procfs_entry);
4201 if (IS_ERR(m->mdt_xmds_service)) {
4202 rc = PTR_ERR(m->mdt_xmds_service);
4203 CERROR("failed to start xmds service: %d\n", rc);
4204 m->mdt_xmds_service = NULL;
4206 GOTO(err_mdt_svc, rc);
4212 mdt_stop_ptlrpc_service(m);
4217 static void mdt_stack_fini(const struct lu_env *env,
4218 struct mdt_device *m, struct lu_device *top)
4220 struct obd_device *obd = mdt2obd_dev(m);
4221 struct lustre_cfg_bufs *bufs;
4222 struct lustre_cfg *lcfg;
4223 struct mdt_thread_info *info;
4227 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
4228 LASSERT(info != NULL);
4230 bufs = &info->mti_u.bufs;
4231 /* process cleanup, pass mdt obd name to get obd umount flags */
4232 lustre_cfg_bufs_reset(bufs, obd->obd_name);
4237 lustre_cfg_bufs_set_string(bufs, 1, flags);
4238 lcfg = lustre_cfg_new(LCFG_CLEANUP, bufs);
4240 CERROR("Cannot alloc lcfg!\n");
4245 top->ld_ops->ldo_process_config(env, top, lcfg);
4246 lustre_cfg_free(lcfg);
4248 lu_stack_fini(env, top);
4249 m->mdt_child = NULL;
4250 m->mdt_bottom = NULL;
4253 static struct lu_device *mdt_layer_setup(struct lu_env *env,
4254 const char *typename,
4255 struct lu_device *child,
4256 struct lustre_cfg *cfg)
4258 const char *dev = lustre_cfg_string(cfg, 0);
4259 struct obd_type *type;
4260 struct lu_device_type *ldt;
4261 struct lu_device *d;
4266 type = class_get_type(typename);
4268 CERROR("Unknown type: '%s'\n", typename);
4269 GOTO(out, rc = -ENODEV);
4272 rc = lu_env_refill((struct lu_env *)env);
4274 CERROR("Failure to refill session: '%d'\n", rc);
4280 CERROR("type: '%s'\n", typename);
4281 GOTO(out_type, rc = -EINVAL);
4284 ldt->ldt_obd_type = type;
4285 d = ldt->ldt_ops->ldto_device_alloc(env, ldt, cfg);
4287 CERROR("Cannot allocate device: '%s'\n", typename);
4288 GOTO(out_type, rc = -ENODEV);
4291 LASSERT(child->ld_site);
4292 d->ld_site = child->ld_site;
4295 rc = ldt->ldt_ops->ldto_device_init(env, d, dev, child);
4297 CERROR("can't init device '%s', rc %d\n", typename, rc);
4298 GOTO(out_alloc, rc);
4301 lu_ref_add(&d->ld_reference, "lu-stack", &lu_site_init);
4303 cfs_spin_lock(&d->ld_site->ls_ld_lock);
4304 cfs_list_add_tail(&d->ld_linkage, &d->ld_site->ls_ld_linkage);
4305 cfs_spin_unlock(&d->ld_site->ls_ld_lock);
4309 ldt->ldt_ops->ldto_device_free(env, d);
4312 class_put_type(type);
4317 static int mdt_stack_init(struct lu_env *env,
4318 struct mdt_device *m,
4319 struct lustre_cfg *cfg,
4320 struct lustre_mount_info *lmi)
4322 struct lu_device *d = &m->mdt_md_dev.md_lu_dev;
4323 struct lu_device *tmp;
4324 struct md_device *md;
4325 struct lu_device *child_lu_dev;
4329 /* init the stack */
4330 tmp = mdt_layer_setup(env, LUSTRE_OSD_NAME, d, cfg);
4332 RETURN(PTR_ERR(tmp));
4334 m->mdt_bottom = lu2dt_dev(tmp);
4336 tmp = mdt_layer_setup(env, LUSTRE_MDD_NAME, d, cfg);
4338 GOTO(out, rc = PTR_ERR(tmp));
4343 tmp = mdt_layer_setup(env, LUSTRE_CMM_NAME, d, cfg);
4345 GOTO(out, rc = PTR_ERR(tmp));
4348 /*set mdd upcall device*/
4349 md_upcall_dev_set(md, lu2md_dev(d));
4352 /*set cmm upcall device*/
4353 md_upcall_dev_set(md, &m->mdt_md_dev);
4355 m->mdt_child = lu2md_dev(d);
4357 /* process setup config */
4358 tmp = &m->mdt_md_dev.md_lu_dev;
4359 rc = tmp->ld_ops->ldo_process_config(env, tmp, cfg);
4363 /* initialize local objects */
4364 child_lu_dev = &m->mdt_child->md_lu_dev;
4366 rc = child_lu_dev->ld_ops->ldo_prepare(env,
4367 &m->mdt_md_dev.md_lu_dev,
4370 /* fini from last known good lu_device */
4372 mdt_stack_fini(env, m, d);
4378 * setup CONFIG_ORIG context, used to access local config log.
4379 * this may need to be rewrite as part of llog rewrite for lu-api.
4381 static int mdt_obd_llog_setup(struct obd_device *obd,
4382 struct lustre_sb_info *lsi)
4386 LASSERT(obd->obd_fsops == NULL);
4388 obd->obd_fsops = fsfilt_get_ops(MT_STR(lsi->lsi_ldd));
4389 if (IS_ERR(obd->obd_fsops))
4390 return PTR_ERR(obd->obd_fsops);
4392 rc = fsfilt_setup(obd, lsi->lsi_srv_mnt->mnt_sb);
4394 fsfilt_put_ops(obd->obd_fsops);
4398 OBD_SET_CTXT_MAGIC(&obd->obd_lvfs_ctxt);
4399 obd->obd_lvfs_ctxt.pwdmnt = lsi->lsi_srv_mnt;
4400 obd->obd_lvfs_ctxt.pwd = lsi->lsi_srv_mnt->mnt_root;
4401 obd->obd_lvfs_ctxt.fs = get_ds();
4403 rc = llog_setup(obd, &obd->obd_olg, LLOG_CONFIG_ORIG_CTXT, obd,
4404 0, NULL, &llog_lvfs_ops);
4406 CERROR("llog_setup() failed: %d\n", rc);
4407 fsfilt_put_ops(obd->obd_fsops);
4413 static void mdt_obd_llog_cleanup(struct obd_device *obd)
4415 struct llog_ctxt *ctxt;
4417 ctxt = llog_get_context(obd, LLOG_CONFIG_ORIG_CTXT);
4421 if (obd->obd_fsops) {
4422 fsfilt_put_ops(obd->obd_fsops);
4423 obd->obd_fsops = NULL;
4427 static void mdt_fini(const struct lu_env *env, struct mdt_device *m)
4429 struct md_device *next = m->mdt_child;
4430 struct lu_device *d = &m->mdt_md_dev.md_lu_dev;
4431 struct lu_site *ls = d->ld_site;
4432 struct obd_device *obd = mdt2obd_dev(m);
4435 target_recovery_fini(obd);
4437 ping_evictor_stop();
4439 mdt_stop_ptlrpc_service(m);
4440 mdt_llog_ctxt_unclone(env, m, LLOG_CHANGELOG_ORIG_CTXT);
4441 mdt_obd_llog_cleanup(obd);
4442 obd_exports_barrier(obd);
4443 obd_zombie_barrier();
4447 #ifdef HAVE_QUOTA_SUPPORT
4448 next->md_ops->mdo_quota.mqo_cleanup(env, next);
4450 lut_fini(env, &m->mdt_lut);
4451 mdt_fs_cleanup(env, m);
4452 upcall_cache_cleanup(m->mdt_identity_cache);
4453 m->mdt_identity_cache = NULL;
4455 if (m->mdt_namespace != NULL) {
4456 ldlm_namespace_free(m->mdt_namespace, NULL,
4457 d->ld_obd->obd_force);
4458 d->ld_obd->obd_namespace = m->mdt_namespace = NULL;
4461 cfs_free_nidlist(&m->mdt_nosquash_nids);
4462 if (m->mdt_nosquash_str) {
4463 OBD_FREE(m->mdt_nosquash_str, m->mdt_nosquash_strlen);
4464 m->mdt_nosquash_str = NULL;
4465 m->mdt_nosquash_strlen = 0;
4468 mdt_seq_fini(env, m);
4469 mdt_seq_fini_cli(m);
4470 mdt_fld_fini(env, m);
4471 sptlrpc_rule_set_free(&m->mdt_sptlrpc_rset);
4473 next->md_ops->mdo_init_capa_ctxt(env, next, 0, 0, 0, NULL);
4474 cfs_timer_disarm(&m->mdt_ck_timer);
4475 mdt_ck_thread_stop(m);
4480 mdt_stack_fini(env, m, md2lu_dev(m->mdt_child));
4483 struct md_site *mite;
4486 mite = lu_site2md(ls);
4490 LASSERT(cfs_atomic_read(&d->ld_ref) == 0);
4495 static int mdt_adapt_sptlrpc_conf(struct obd_device *obd, int initial)
4497 struct mdt_device *m = mdt_dev(obd->obd_lu_dev);
4498 struct sptlrpc_rule_set tmp_rset;
4501 sptlrpc_rule_set_init(&tmp_rset);
4502 rc = sptlrpc_conf_target_get_rules(obd, &tmp_rset, initial);
4504 CERROR("mdt %s: failed get sptlrpc rules: %d\n",
4509 sptlrpc_target_update_exp_flavor(obd, &tmp_rset);
4511 cfs_write_lock(&m->mdt_sptlrpc_lock);
4512 sptlrpc_rule_set_free(&m->mdt_sptlrpc_rset);
4513 m->mdt_sptlrpc_rset = tmp_rset;
4514 cfs_write_unlock(&m->mdt_sptlrpc_lock);
4519 int mdt_postrecov(const struct lu_env *, struct mdt_device *);
4521 static int mdt_init0(const struct lu_env *env, struct mdt_device *m,
4522 struct lu_device_type *ldt, struct lustre_cfg *cfg)
4524 struct mdt_thread_info *info;
4525 struct obd_device *obd;
4526 const char *dev = lustre_cfg_string(cfg, 0);
4527 const char *num = lustre_cfg_string(cfg, 2);
4528 struct lustre_mount_info *lmi = NULL;
4529 struct lustre_sb_info *lsi;
4530 struct lustre_disk_data *ldd;
4532 struct md_site *mite;
4533 const char *identity_upcall = "NONE";
4534 struct md_device *next;
4540 md_device_init(&m->mdt_md_dev, ldt);
4542 * Environment (env) might be missing mdt_thread_key values at that
4543 * point, if device is allocated when mdt_thread_key is in QUIESCENT
4546 * Usually device allocation path doesn't use module key values, but
4547 * mdt has to do a lot of work here, so allocate key value.
4549 rc = lu_env_refill((struct lu_env *)env);
4553 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
4554 LASSERT(info != NULL);
4556 obd = class_name2obd(dev);
4557 LASSERT(obd != NULL);
4559 m->mdt_max_mdsize = MAX_MD_SIZE; /* 4 stripes */
4560 m->mdt_max_cookiesize = sizeof(struct llog_cookie);
4562 m->mdt_som_conf = 0;
4564 m->mdt_opts.mo_cos = MDT_COS_DEFAULT;
4565 lmi = server_get_mount_2(dev);
4567 CERROR("Cannot get mount info for %s!\n", dev);
4570 lsi = s2lsi(lmi->lmi_sb);
4571 /* CMD is supported only in IAM mode */
4574 node_id = simple_strtol(num, NULL, 10);
4575 if (!(ldd->ldd_flags & LDD_F_IAM_DIR) && node_id) {
4576 CERROR("CMD Operation not allowed in IOP mode\n");
4577 GOTO(err_lmi, rc = -EINVAL);
4580 obd->u.obt.obt_magic = OBT_MAGIC;
4583 cfs_rwlock_init(&m->mdt_sptlrpc_lock);
4584 sptlrpc_rule_set_init(&m->mdt_sptlrpc_rset);
4586 cfs_spin_lock_init(&m->mdt_ioepoch_lock);
4587 m->mdt_opts.mo_compat_resname = 0;
4588 m->mdt_opts.mo_mds_capa = 1;
4589 m->mdt_opts.mo_oss_capa = 1;
4590 m->mdt_capa_timeout = CAPA_TIMEOUT;
4591 m->mdt_capa_alg = CAPA_HMAC_ALG_SHA1;
4592 m->mdt_ck_timeout = CAPA_KEY_TIMEOUT;
4593 m->mdt_squash_uid = 0;
4594 m->mdt_squash_gid = 0;
4595 CFS_INIT_LIST_HEAD(&m->mdt_nosquash_nids);
4596 m->mdt_nosquash_str = NULL;
4597 m->mdt_nosquash_strlen = 0;
4598 cfs_init_rwsem(&m->mdt_squash_sem);
4600 OBD_ALLOC_PTR(mite);
4602 GOTO(err_lmi, rc = -ENOMEM);
4606 m->mdt_md_dev.md_lu_dev.ld_ops = &mdt_lu_ops;
4607 m->mdt_md_dev.md_lu_dev.ld_obd = obd;
4608 /* set this lu_device to obd, because error handling need it */
4609 obd->obd_lu_dev = &m->mdt_md_dev.md_lu_dev;
4611 rc = lu_site_init(s, &m->mdt_md_dev.md_lu_dev);
4613 CERROR("Can't init lu_site, rc %d\n", rc);
4614 GOTO(err_free_site, rc);
4617 /* set server index */
4618 lu_site2md(s)->ms_node_id = node_id;
4620 /* failover is the default
4621 * FIXME: we do not failout mds0/mgs, which may cause some problems.
4622 * assumed whose ms_node_id == 0 XXX
4624 obd->obd_replayable = 1;
4625 /* No connection accepted until configurations will finish */
4626 obd->obd_no_conn = 1;
4628 if (cfg->lcfg_bufcount > 4 && LUSTRE_CFG_BUFLEN(cfg, 4) > 0) {
4629 char *str = lustre_cfg_string(cfg, 4);
4630 if (strchr(str, 'n')) {
4631 CWARN("%s: recovery disabled\n", obd->obd_name);
4632 obd->obd_replayable = 0;
4636 /* init the stack */
4637 rc = mdt_stack_init((struct lu_env *)env, m, cfg, lmi);
4639 CERROR("Can't init device stack, rc %d\n", rc);
4640 GOTO(err_lu_site, rc);
4643 rc = lut_init(env, &m->mdt_lut, obd, m->mdt_bottom);
4645 GOTO(err_fini_stack, rc);
4647 rc = mdt_fld_init(env, obd->obd_name, m);
4651 rc = mdt_seq_init(env, obd->obd_name, m);
4653 GOTO(err_fini_fld, rc);
4655 snprintf(info->mti_u.ns_name, sizeof info->mti_u.ns_name,
4656 LUSTRE_MDT_NAME"-%p", m);
4657 m->mdt_namespace = ldlm_namespace_new(obd, info->mti_u.ns_name,
4658 LDLM_NAMESPACE_SERVER,
4659 LDLM_NAMESPACE_GREEDY,
4661 if (m->mdt_namespace == NULL)
4662 GOTO(err_fini_seq, rc = -ENOMEM);
4664 ldlm_register_intent(m->mdt_namespace, mdt_intent_policy);
4665 /* set obd_namespace for compatibility with old code */
4666 obd->obd_namespace = m->mdt_namespace;
4668 cfs_timer_init(&m->mdt_ck_timer, mdt_ck_timer_callback, m);
4670 rc = mdt_ck_thread_start(m);
4672 GOTO(err_free_ns, rc);
4674 rc = mdt_fs_setup(env, m, obd, lsi);
4678 rc = mdt_obd_llog_setup(obd, lsi);
4680 GOTO(err_fs_cleanup, rc);
4682 rc = mdt_llog_ctxt_clone(env, m, LLOG_CHANGELOG_ORIG_CTXT);
4684 GOTO(err_llog_cleanup, rc);
4686 mdt_adapt_sptlrpc_conf(obd, 1);
4688 next = m->mdt_child;
4689 #ifdef HAVE_QUOTA_SUPPORT
4690 rc = next->md_ops->mdo_quota.mqo_setup(env, next, lmi->lmi_mnt);
4692 GOTO(err_llog_cleanup, rc);
4695 server_put_mount_2(dev, lmi->lmi_mnt);
4698 rc = next->md_ops->mdo_iocontrol(env, next, OBD_IOC_GET_MNTOPT, 0,
4701 GOTO(err_quota, rc);
4703 if (mntopts & MNTOPT_USERXATTR)
4704 m->mdt_opts.mo_user_xattr = 1;
4706 m->mdt_opts.mo_user_xattr = 0;
4708 if (mntopts & MNTOPT_ACL)
4709 m->mdt_opts.mo_acl = 1;
4711 m->mdt_opts.mo_acl = 0;
4713 /* XXX: to support suppgid for ACL, we enable identity_upcall
4714 * by default, otherwise, maybe got unexpected -EACCESS. */
4715 if (m->mdt_opts.mo_acl)
4716 identity_upcall = MDT_IDENTITY_UPCALL_PATH;
4718 m->mdt_identity_cache = upcall_cache_init(obd->obd_name,identity_upcall,
4719 &mdt_identity_upcall_cache_ops);
4720 if (IS_ERR(m->mdt_identity_cache)) {
4721 rc = PTR_ERR(m->mdt_identity_cache);
4722 m->mdt_identity_cache = NULL;
4723 GOTO(err_quota, rc);
4726 target_recovery_init(&m->mdt_lut, mdt_recovery_handle);
4728 rc = mdt_procfs_init(m, dev);
4730 CERROR("Can't init MDT lprocfs, rc %d\n", rc);
4731 GOTO(err_recovery, rc);
4734 rc = mdt_start_ptlrpc_service(m);
4736 GOTO(err_procfs, rc);
4738 ping_evictor_start();
4740 rc = lu_site_init_finish(s);
4742 GOTO(err_stop_service, rc);
4744 if (obd->obd_recovering == 0)
4745 mdt_postrecov(env, m);
4747 mdt_init_capa_ctxt(env, m);
4749 /* Reduce the initial timeout on an MDS because it doesn't need such
4750 * a long timeout as an OST does. Adaptive timeouts will adjust this
4751 * value appropriately. */
4752 if (ldlm_timeout == LDLM_TIMEOUT_DEFAULT)
4753 ldlm_timeout = MDS_LDLM_TIMEOUT_DEFAULT;
4758 ping_evictor_stop();
4759 mdt_stop_ptlrpc_service(m);
4763 target_recovery_fini(obd);
4764 upcall_cache_cleanup(m->mdt_identity_cache);
4765 m->mdt_identity_cache = NULL;
4767 #ifdef HAVE_QUOTA_SUPPORT
4768 next->md_ops->mdo_quota.mqo_cleanup(env, next);
4771 mdt_llog_ctxt_unclone(env, m, LLOG_CHANGELOG_ORIG_CTXT);
4772 mdt_obd_llog_cleanup(obd);
4774 mdt_fs_cleanup(env, m);
4776 cfs_timer_disarm(&m->mdt_ck_timer);
4777 mdt_ck_thread_stop(m);
4779 ldlm_namespace_free(m->mdt_namespace, NULL, 0);
4780 obd->obd_namespace = m->mdt_namespace = NULL;
4782 mdt_seq_fini(env, m);
4784 mdt_fld_fini(env, m);
4786 lut_fini(env, &m->mdt_lut);
4788 mdt_stack_fini(env, m, md2lu_dev(m->mdt_child));
4795 server_put_mount_2(dev, lmi->lmi_mnt);
4799 /* used by MGS to process specific configurations */
4800 static int mdt_process_config(const struct lu_env *env,
4801 struct lu_device *d, struct lustre_cfg *cfg)
4803 struct mdt_device *m = mdt_dev(d);
4804 struct md_device *md_next = m->mdt_child;
4805 struct lu_device *next = md2lu_dev(md_next);
4809 switch (cfg->lcfg_command) {
4811 struct lprocfs_static_vars lvars;
4812 struct obd_device *obd = d->ld_obd;
4815 * For interoperability between 1.8 and 2.0,
4818 /* Skip old "mdt.group_upcall" param. */
4819 char *param = lustre_cfg_string(cfg, 1);
4820 if (param && !strncmp("mdt.group_upcall", param, 16)) {
4821 CWARN("For 1.8 interoperability, skip this"
4822 " mdt.group_upcall. It is obsolete\n");
4825 /* Rename old "mdt.quota_type" to "mdd.quota_type. */
4826 if (param && !strncmp("mdt.quota_type", param, 14)) {
4827 CWARN("Found old param mdt.quota_type, changed"
4828 " it to mdd.quota_type.\n");
4833 lprocfs_mdt_init_vars(&lvars);
4834 rc = class_process_proc_param(PARAM_MDT, lvars.obd_vars,
4836 if (rc > 0 || rc == -ENOSYS)
4837 /* we don't understand; pass it on */
4838 rc = next->ld_ops->ldo_process_config(env, next, cfg);
4843 * Add mdc hook to get first MDT uuid and connect it to
4844 * ls->controller to use for seq manager.
4846 rc = next->ld_ops->ldo_process_config(env, next, cfg);
4848 CERROR("Can't add mdc, rc %d\n", rc);
4850 rc = mdt_seq_init_cli(env, mdt_dev(d), cfg);
4853 /* others are passed further */
4854 rc = next->ld_ops->ldo_process_config(env, next, cfg);
4860 static struct lu_object *mdt_object_alloc(const struct lu_env *env,
4861 const struct lu_object_header *hdr,
4862 struct lu_device *d)
4864 struct mdt_object *mo;
4870 struct lu_object *o;
4871 struct lu_object_header *h;
4873 o = &mo->mot_obj.mo_lu;
4874 h = &mo->mot_header;
4875 lu_object_header_init(h);
4876 lu_object_init(o, h, d);
4877 lu_object_add_top(h, o);
4878 o->lo_ops = &mdt_obj_ops;
4879 cfs_mutex_init(&mo->mot_ioepoch_mutex);
4880 cfs_mutex_init(&mo->mot_lov_mutex);
4886 static int mdt_object_init(const struct lu_env *env, struct lu_object *o,
4887 const struct lu_object_conf *unused)
4889 struct mdt_device *d = mdt_dev(o->lo_dev);
4890 struct lu_device *under;
4891 struct lu_object *below;
4895 CDEBUG(D_INFO, "object init, fid = "DFID"\n",
4896 PFID(lu_object_fid(o)));
4898 under = &d->mdt_child->md_lu_dev;
4899 below = under->ld_ops->ldo_object_alloc(env, o->lo_header, under);
4900 if (below != NULL) {
4901 lu_object_add(o, below);
4908 static void mdt_object_free(const struct lu_env *env, struct lu_object *o)
4910 struct mdt_object *mo = mdt_obj(o);
4911 struct lu_object_header *h;
4915 CDEBUG(D_INFO, "object free, fid = "DFID"\n",
4916 PFID(lu_object_fid(o)));
4919 lu_object_header_fini(h);
4924 static int mdt_object_print(const struct lu_env *env, void *cookie,
4925 lu_printer_t p, const struct lu_object *o)
4927 struct mdt_object *mdto = mdt_obj((struct lu_object *)o);
4928 return (*p)(env, cookie, LUSTRE_MDT_NAME"-object@%p(ioepoch="LPU64" "
4929 "flags="LPX64", epochcount=%d, writecount=%d)",
4930 mdto, mdto->mot_ioepoch, mdto->mot_flags,
4931 mdto->mot_ioepoch_count, mdto->mot_writecount);
4934 static const struct lu_device_operations mdt_lu_ops = {
4935 .ldo_object_alloc = mdt_object_alloc,
4936 .ldo_process_config = mdt_process_config,
4939 static const struct lu_object_operations mdt_obj_ops = {
4940 .loo_object_init = mdt_object_init,
4941 .loo_object_free = mdt_object_free,
4942 .loo_object_print = mdt_object_print
4945 static int mdt_obd_set_info_async(const struct lu_env *env,
4946 struct obd_export *exp,
4947 __u32 keylen, void *key,
4948 __u32 vallen, void *val,
4949 struct ptlrpc_request_set *set)
4951 struct obd_device *obd = exp->exp_obd;
4957 if (KEY_IS(KEY_SPTLRPC_CONF)) {
4958 rc = mdt_adapt_sptlrpc_conf(obd, 0);
4965 /* mds_connect_internal */
4966 static int mdt_connect_internal(struct obd_export *exp,
4967 struct mdt_device *mdt,
4968 struct obd_connect_data *data)
4971 data->ocd_connect_flags &= MDT_CONNECT_SUPPORTED;
4972 data->ocd_ibits_known &= MDS_INODELOCK_FULL;
4974 /* If no known bits (which should not happen, probably,
4975 as everybody should support LOOKUP and UPDATE bits at least)
4976 revert to compat mode with plain locks. */
4977 if (!data->ocd_ibits_known &&
4978 data->ocd_connect_flags & OBD_CONNECT_IBITS)
4979 data->ocd_connect_flags &= ~OBD_CONNECT_IBITS;
4981 if (!mdt->mdt_opts.mo_acl)
4982 data->ocd_connect_flags &= ~OBD_CONNECT_ACL;
4984 if (!mdt->mdt_opts.mo_user_xattr)
4985 data->ocd_connect_flags &= ~OBD_CONNECT_XATTR;
4987 if (!mdt->mdt_som_conf)
4988 data->ocd_connect_flags &= ~OBD_CONNECT_SOM;
4990 if (data->ocd_connect_flags & OBD_CONNECT_BRW_SIZE) {
4991 data->ocd_brw_size = min(data->ocd_brw_size,
4992 (__u32)(PTLRPC_MAX_BRW_PAGES << CFS_PAGE_SHIFT));
4993 if (data->ocd_brw_size == 0) {
4994 CERROR("%s: cli %s/%p ocd_connect_flags: "LPX64
4995 " ocd_version: %x ocd_grant: %d "
4996 "ocd_index: %u ocd_brw_size is "
4997 "unexpectedly zero, network data "
4998 "corruption? Refusing connection of this"
5000 exp->exp_obd->obd_name,
5001 exp->exp_client_uuid.uuid,
5002 exp, data->ocd_connect_flags, data->ocd_version,
5003 data->ocd_grant, data->ocd_index);
5008 cfs_spin_lock(&exp->exp_lock);
5009 exp->exp_connect_flags = data->ocd_connect_flags;
5010 cfs_spin_unlock(&exp->exp_lock);
5011 data->ocd_version = LUSTRE_VERSION_CODE;
5012 exp->exp_mdt_data.med_ibits_known = data->ocd_ibits_known;
5016 if (mdt->mdt_opts.mo_acl &&
5017 ((exp->exp_connect_flags & OBD_CONNECT_ACL) == 0)) {
5018 CWARN("%s: MDS requires ACL support but client does not\n",
5019 mdt->mdt_md_dev.md_lu_dev.ld_obd->obd_name);
5024 if ((exp->exp_connect_flags & OBD_CONNECT_FID) == 0) {
5025 CWARN("%s: MDS requires FID support, but client not\n",
5026 mdt->mdt_md_dev.md_lu_dev.ld_obd->obd_name);
5030 if (mdt->mdt_som_conf && !exp_connect_som(exp) &&
5031 !(exp->exp_connect_flags & OBD_CONNECT_MDS_MDS)) {
5032 CWARN("%s: MDS has SOM enabled, but client does not support "
5033 "it\n", mdt->mdt_md_dev.md_lu_dev.ld_obd->obd_name);
5040 static int mdt_connect_check_sptlrpc(struct mdt_device *mdt,
5041 struct obd_export *exp,
5042 struct ptlrpc_request *req)
5044 struct sptlrpc_flavor flvr;
5047 if (exp->exp_flvr.sf_rpc == SPTLRPC_FLVR_INVALID) {
5048 cfs_read_lock(&mdt->mdt_sptlrpc_lock);
5049 sptlrpc_target_choose_flavor(&mdt->mdt_sptlrpc_rset,
5053 cfs_read_unlock(&mdt->mdt_sptlrpc_lock);
5055 cfs_spin_lock(&exp->exp_lock);
5057 exp->exp_sp_peer = req->rq_sp_from;
5058 exp->exp_flvr = flvr;
5060 if (exp->exp_flvr.sf_rpc != SPTLRPC_FLVR_ANY &&
5061 exp->exp_flvr.sf_rpc != req->rq_flvr.sf_rpc) {
5062 CERROR("unauthorized rpc flavor %x from %s, "
5063 "expect %x\n", req->rq_flvr.sf_rpc,
5064 libcfs_nid2str(req->rq_peer.nid),
5065 exp->exp_flvr.sf_rpc);
5069 cfs_spin_unlock(&exp->exp_lock);
5071 if (exp->exp_sp_peer != req->rq_sp_from) {
5072 CERROR("RPC source %s doesn't match %s\n",
5073 sptlrpc_part2name(req->rq_sp_from),
5074 sptlrpc_part2name(exp->exp_sp_peer));
5077 rc = sptlrpc_target_export_check(exp, req);
5084 /* mds_connect copy */
5085 static int mdt_obd_connect(const struct lu_env *env,
5086 struct obd_export **exp, struct obd_device *obd,
5087 struct obd_uuid *cluuid,
5088 struct obd_connect_data *data,
5091 struct mdt_thread_info *info;
5092 struct obd_export *lexp;
5093 struct lustre_handle conn = { 0 };
5094 struct mdt_device *mdt;
5095 struct ptlrpc_request *req;
5099 LASSERT(env != NULL);
5100 if (!exp || !obd || !cluuid)
5103 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
5104 req = info->mti_pill->rc_req;
5105 mdt = mdt_dev(obd->obd_lu_dev);
5107 rc = class_connect(&conn, obd, cluuid);
5111 lexp = class_conn2export(&conn);
5112 LASSERT(lexp != NULL);
5114 rc = mdt_connect_check_sptlrpc(mdt, lexp, req);
5118 if (OBD_FAIL_CHECK(OBD_FAIL_TGT_RCVG_FLAG))
5119 lustre_msg_add_op_flags(req->rq_repmsg, MSG_CONNECT_RECOVERING);
5121 rc = mdt_connect_internal(lexp, mdt, data);
5123 struct lsd_client_data *lcd = lexp->exp_target_data.ted_lcd;
5126 info->mti_exp = lexp;
5127 memcpy(lcd->lcd_uuid, cluuid, sizeof lcd->lcd_uuid);
5128 rc = lut_client_new(env, lexp);
5130 mdt_export_stats_init(obd, lexp, localdata);
5135 class_disconnect(lexp);
5144 static int mdt_obd_reconnect(const struct lu_env *env,
5145 struct obd_export *exp, struct obd_device *obd,
5146 struct obd_uuid *cluuid,
5147 struct obd_connect_data *data,
5150 struct mdt_thread_info *info;
5151 struct mdt_device *mdt;
5152 struct ptlrpc_request *req;
5156 if (exp == NULL || obd == NULL || cluuid == NULL)
5159 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
5160 req = info->mti_pill->rc_req;
5161 mdt = mdt_dev(obd->obd_lu_dev);
5163 rc = mdt_connect_check_sptlrpc(mdt, exp, req);
5167 rc = mdt_connect_internal(exp, mdt_dev(obd->obd_lu_dev), data);
5169 mdt_export_stats_init(obd, exp, localdata);
5174 static int mdt_export_cleanup(struct obd_export *exp)
5176 struct mdt_export_data *med = &exp->exp_mdt_data;
5177 struct obd_device *obd = exp->exp_obd;
5178 struct mdt_device *mdt;
5179 struct mdt_thread_info *info;
5181 CFS_LIST_HEAD(closing_list);
5182 struct mdt_file_data *mfd, *n;
5186 cfs_spin_lock(&med->med_open_lock);
5187 while (!cfs_list_empty(&med->med_open_head)) {
5188 cfs_list_t *tmp = med->med_open_head.next;
5189 mfd = cfs_list_entry(tmp, struct mdt_file_data, mfd_list);
5191 /* Remove mfd handle so it can't be found again.
5192 * We are consuming the mfd_list reference here. */
5193 class_handle_unhash(&mfd->mfd_handle);
5194 cfs_list_move_tail(&mfd->mfd_list, &closing_list);
5196 cfs_spin_unlock(&med->med_open_lock);
5197 mdt = mdt_dev(obd->obd_lu_dev);
5198 LASSERT(mdt != NULL);
5200 rc = lu_env_init(&env, LCT_MD_THREAD);
5204 info = lu_context_key_get(&env.le_ctx, &mdt_thread_key);
5205 LASSERT(info != NULL);
5206 memset(info, 0, sizeof *info);
5207 info->mti_env = &env;
5208 info->mti_mdt = mdt;
5209 info->mti_exp = exp;
5211 if (!cfs_list_empty(&closing_list)) {
5212 struct md_attr *ma = &info->mti_attr;
5216 lmm_size = mdt->mdt_max_mdsize;
5217 OBD_ALLOC_LARGE(ma->ma_lmm, lmm_size);
5218 if (ma->ma_lmm == NULL)
5219 GOTO(out_lmm, rc = -ENOMEM);
5221 cookie_size = mdt->mdt_max_cookiesize;
5222 OBD_ALLOC_LARGE(ma->ma_cookie, cookie_size);
5223 if (ma->ma_cookie == NULL)
5224 GOTO(out_cookie, rc = -ENOMEM);
5226 /* Close any open files (which may also cause orphan unlinking). */
5227 cfs_list_for_each_entry_safe(mfd, n, &closing_list, mfd_list) {
5228 cfs_list_del_init(&mfd->mfd_list);
5229 memset(&ma->ma_attr, 0, sizeof(ma->ma_attr));
5230 ma->ma_lmm_size = lmm_size;
5231 ma->ma_cookie_size = cookie_size;
5233 /* It is not for setattr, just tell MDD to send
5234 * DESTROY RPC to OSS if needed */
5235 ma->ma_valid = MA_FLAGS;
5236 ma->ma_attr_flags = MDS_CLOSE_CLEANUP;
5237 /* Don't unlink orphan on failover umount, LU-184 */
5238 if (exp->exp_flags & OBD_OPT_FAILOVER)
5239 ma->ma_attr_flags |= MDS_KEEP_ORPHAN;
5240 mdt_mfd_close(info, mfd);
5242 OBD_FREE_LARGE(ma->ma_cookie, cookie_size);
5243 ma->ma_cookie = NULL;
5245 OBD_FREE_LARGE(ma->ma_lmm, lmm_size);
5249 info->mti_mdt = NULL;
5250 /* cleanup client slot early */
5251 /* Do not erase record for recoverable client. */
5252 if (!(exp->exp_flags & OBD_OPT_FAILOVER) || exp->exp_failed)
5253 lut_client_del(&env, exp);
5259 static int mdt_obd_disconnect(struct obd_export *exp)
5265 class_export_get(exp);
5267 rc = server_disconnect_export(exp);
5269 CDEBUG(D_IOCTL, "server disconnect error: %d\n", rc);
5271 rc = mdt_export_cleanup(exp);
5272 class_export_put(exp);
5276 /* FIXME: Can we avoid using these two interfaces? */
5277 static int mdt_init_export(struct obd_export *exp)
5279 struct mdt_export_data *med = &exp->exp_mdt_data;
5283 CFS_INIT_LIST_HEAD(&med->med_open_head);
5284 cfs_spin_lock_init(&med->med_open_lock);
5285 cfs_mutex_init(&med->med_idmap_mutex);
5286 med->med_idmap = NULL;
5287 cfs_spin_lock(&exp->exp_lock);
5288 exp->exp_connecting = 1;
5289 cfs_spin_unlock(&exp->exp_lock);
5291 /* self-export doesn't need client data and ldlm initialization */
5292 if (unlikely(obd_uuid_equals(&exp->exp_obd->obd_uuid,
5293 &exp->exp_client_uuid)))
5296 rc = lut_client_alloc(exp);
5298 rc = ldlm_init_export(exp);
5300 CERROR("%s: Error %d while initializing export\n",
5301 exp->exp_obd->obd_name, rc);
5305 static int mdt_destroy_export(struct obd_export *exp)
5309 if (exp_connect_rmtclient(exp))
5310 mdt_cleanup_idmap(&exp->exp_mdt_data);
5312 target_destroy_export(exp);
5313 /* destroy can be called from failed obd_setup, so
5314 * checking uuid is safer than obd_self_export */
5315 if (unlikely(obd_uuid_equals(&exp->exp_obd->obd_uuid,
5316 &exp->exp_client_uuid)))
5319 ldlm_destroy_export(exp);
5320 lut_client_free(exp);
5322 LASSERT(cfs_list_empty(&exp->exp_outstanding_replies));
5323 LASSERT(cfs_list_empty(&exp->exp_mdt_data.med_open_head));
5328 static void mdt_allow_cli(struct mdt_device *m, unsigned int flag)
5330 if (flag & CONFIG_LOG)
5331 cfs_set_bit(MDT_FL_CFGLOG, &m->mdt_state);
5333 /* also notify active event */
5334 if (flag & CONFIG_SYNC)
5335 cfs_set_bit(MDT_FL_SYNCED, &m->mdt_state);
5337 if (cfs_test_bit(MDT_FL_CFGLOG, &m->mdt_state) &&
5338 cfs_test_bit(MDT_FL_SYNCED, &m->mdt_state)) {
5339 struct obd_device *obd = m->mdt_md_dev.md_lu_dev.ld_obd;
5341 /* Open for clients */
5342 if (obd->obd_no_conn) {
5343 cfs_spin_lock(&obd->obd_dev_lock);
5344 obd->obd_no_conn = 0;
5345 cfs_spin_unlock(&obd->obd_dev_lock);
5350 static int mdt_upcall(const struct lu_env *env, struct md_device *md,
5351 enum md_upcall_event ev, void *data)
5353 struct mdt_device *m = mdt_dev(&md->md_lu_dev);
5354 struct md_device *next = m->mdt_child;
5355 struct mdt_thread_info *mti;
5361 rc = next->md_ops->mdo_maxsize_get(env, next,
5363 &m->mdt_max_cookiesize);
5364 CDEBUG(D_INFO, "get max mdsize %d max cookiesize %d\n",
5365 m->mdt_max_mdsize, m->mdt_max_cookiesize);
5366 mdt_allow_cli(m, CONFIG_SYNC);
5369 m->mdt_lut.lut_obd->u.obt.obt_mount_count;
5372 mti = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
5373 mti->mti_no_need_trans = 1;
5374 CDEBUG(D_INFO, "disable mdt trans for this thread\n");
5377 /* Check that MDT is not yet configured */
5378 LASSERT(!cfs_test_bit(MDT_FL_CFGLOG, &m->mdt_state));
5380 #ifdef HAVE_QUOTA_SUPPORT
5382 if (md->md_lu_dev.ld_obd->obd_recovering == 0 &&
5383 likely(md->md_lu_dev.ld_obd->obd_stopping == 0))
5384 next->md_ops->mdo_quota.mqo_recovery(env, next);
5388 CERROR("invalid event\n");
5395 static int mdt_obd_notify(struct obd_device *obd,
5396 struct obd_device *watched,
5397 enum obd_notify_event ev, void *data)
5399 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
5400 #ifdef HAVE_QUOTA_SUPPORT
5401 struct md_device *next = mdt->mdt_child;
5406 case OBD_NOTIFY_CONFIG:
5407 mdt_allow_cli(mdt, (unsigned long)data);
5409 #ifdef HAVE_QUOTA_SUPPORT
5410 /* quota_type has been processed, we can now handle
5411 * incoming quota requests */
5412 next->md_ops->mdo_quota.mqo_notify(NULL, next);
5416 CDEBUG(D_INFO, "Unhandled notification %#x\n", ev);
5421 static int mdt_rpc_fid2path(struct mdt_thread_info *info, void *key,
5422 void *val, int vallen)
5424 struct mdt_device *mdt = mdt_dev(info->mti_exp->exp_obd->obd_lu_dev);
5425 struct getinfo_fid2path *fpout, *fpin;
5428 fpin = key + cfs_size_round(sizeof(KEY_FID2PATH));
5431 if (ptlrpc_req_need_swab(info->mti_pill->rc_req))
5432 lustre_swab_fid2path(fpin);
5434 memcpy(fpout, fpin, sizeof(*fpin));
5435 if (fpout->gf_pathlen != vallen - sizeof(*fpin))
5438 rc = mdt_fid2path(info->mti_env, mdt, fpout);
5442 static int mdt_fid2path(const struct lu_env *env, struct mdt_device *mdt,
5443 struct getinfo_fid2path *fp)
5445 struct mdt_object *obj;
5449 CDEBUG(D_IOCTL, "path get "DFID" from "LPU64" #%d\n",
5450 PFID(&fp->gf_fid), fp->gf_recno, fp->gf_linkno);
5452 if (!fid_is_sane(&fp->gf_fid))
5455 obj = mdt_object_find(env, mdt, &fp->gf_fid);
5456 if (obj == NULL || IS_ERR(obj)) {
5457 CDEBUG(D_IOCTL, "no object "DFID": %ld\n", PFID(&fp->gf_fid),
5462 rc = lu_object_exists(&obj->mot_obj.mo_lu);
5468 mdt_object_put(env, obj);
5469 CDEBUG(D_IOCTL, "nonlocal object "DFID": %d\n",
5470 PFID(&fp->gf_fid), rc);
5474 rc = mo_path(env, md_object_next(&obj->mot_obj), fp->gf_path,
5475 fp->gf_pathlen, &fp->gf_recno, &fp->gf_linkno);
5476 mdt_object_put(env, obj);
5481 static int mdt_get_info(struct mdt_thread_info *info)
5483 struct ptlrpc_request *req = mdt_info_req(info);
5491 key = req_capsule_client_get(info->mti_pill, &RMF_GETINFO_KEY);
5493 CDEBUG(D_IOCTL, "No GETINFO key");
5496 keylen = req_capsule_get_size(info->mti_pill, &RMF_GETINFO_KEY,
5499 vallen = req_capsule_client_get(info->mti_pill, &RMF_GETINFO_VALLEN);
5500 if (vallen == NULL) {
5501 CDEBUG(D_IOCTL, "Unable to get RMF_GETINFO_VALLEN buffer");
5505 req_capsule_set_size(info->mti_pill, &RMF_GETINFO_VAL, RCL_SERVER,
5507 rc = req_capsule_server_pack(info->mti_pill);
5508 valout = req_capsule_server_get(info->mti_pill, &RMF_GETINFO_VAL);
5509 if (valout == NULL) {
5510 CDEBUG(D_IOCTL, "Unable to get get-info RPC out buffer");
5514 if (KEY_IS(KEY_FID2PATH))
5515 rc = mdt_rpc_fid2path(info, key, valout, *vallen);
5519 lustre_msg_set_status(req->rq_repmsg, rc);
5524 /* Pass the ioc down */
5525 static int mdt_ioc_child(struct lu_env *env, struct mdt_device *mdt,
5526 unsigned int cmd, int len, void *data)
5528 struct lu_context ioctl_session;
5529 struct md_device *next = mdt->mdt_child;
5533 rc = lu_context_init(&ioctl_session, LCT_SESSION);
5536 ioctl_session.lc_thread = (struct ptlrpc_thread *)cfs_current();
5537 lu_context_enter(&ioctl_session);
5538 env->le_ses = &ioctl_session;
5540 LASSERT(next->md_ops->mdo_iocontrol);
5541 rc = next->md_ops->mdo_iocontrol(env, next, cmd, len, data);
5543 lu_context_exit(&ioctl_session);
5544 lu_context_fini(&ioctl_session);
5548 static int mdt_ioc_version_get(struct mdt_thread_info *mti, void *karg)
5550 struct obd_ioctl_data *data = karg;
5551 struct lu_fid *fid = (struct lu_fid *)data->ioc_inlbuf1;
5553 struct mdt_object *obj;
5554 struct mdt_lock_handle *lh;
5558 CDEBUG(D_IOCTL, "getting version for "DFID"\n", PFID(fid));
5559 if (!fid_is_sane(fid))
5562 lh = &mti->mti_lh[MDT_LH_PARENT];
5563 mdt_lock_reg_init(lh, LCK_CR);
5565 obj = mdt_object_find_lock(mti, fid, lh, MDS_INODELOCK_UPDATE);
5567 RETURN(PTR_ERR(obj));
5569 rc = mdt_object_exists(obj);
5573 * before calling version get the correct MDS should be
5574 * fid, this is error to find remote object here
5576 CERROR("nonlocal object "DFID"\n", PFID(fid));
5577 } else if (rc == 0) {
5578 *(__u64 *)data->ioc_inlbuf2 = ENOENT_VERSION;
5581 version = dt_version_get(mti->mti_env, mdt_obj2dt(obj));
5582 *(__u64 *)data->ioc_inlbuf2 = version;
5585 mdt_object_unlock_put(mti, obj, lh, 1);
5589 /* ioctls on obd dev */
5590 static int mdt_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
5591 void *karg, void *uarg)
5594 struct obd_device *obd = exp->exp_obd;
5595 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
5596 struct dt_device *dt = mdt->mdt_bottom;
5600 CDEBUG(D_IOCTL, "handling ioctl cmd %#x\n", cmd);
5601 rc = lu_env_init(&env, LCT_MD_THREAD);
5607 rc = mdt_device_sync(&env, mdt);
5609 case OBD_IOC_SET_READONLY:
5610 rc = dt->dd_ops->dt_ro(&env, dt);
5612 case OBD_IOC_ABORT_RECOVERY:
5613 CERROR("Aborting recovery for device %s\n", obd->obd_name);
5614 target_stop_recovery_thread(obd);
5617 case OBD_IOC_CHANGELOG_REG:
5618 case OBD_IOC_CHANGELOG_DEREG:
5619 case OBD_IOC_CHANGELOG_CLEAR:
5620 rc = mdt_ioc_child(&env, mdt, cmd, len, karg);
5622 case OBD_IOC_GET_OBJ_VERSION: {
5623 struct mdt_thread_info *mti;
5624 mti = lu_context_key_get(&env.le_ctx, &mdt_thread_key);
5625 memset(mti, 0, sizeof *mti);
5626 mti->mti_env = &env;
5630 rc = mdt_ioc_version_get(mti, karg);
5634 CERROR("Not supported cmd = %d for device %s\n",
5635 cmd, obd->obd_name);
5643 int mdt_postrecov(const struct lu_env *env, struct mdt_device *mdt)
5645 struct lu_device *ld = md2lu_dev(mdt->mdt_child);
5646 #ifdef HAVE_QUOTA_SUPPORT
5647 struct obd_device *obd = mdt2obd_dev(mdt);
5648 struct md_device *next = mdt->mdt_child;
5653 rc = ld->ld_ops->ldo_recovery_complete(env, ld);
5654 #ifdef HAVE_QUOTA_SUPPORT
5655 if (likely(obd->obd_stopping == 0))
5656 next->md_ops->mdo_quota.mqo_recovery(env, next);
5661 int mdt_obd_postrecov(struct obd_device *obd)
5666 rc = lu_env_init(&env, LCT_MD_THREAD);
5669 rc = mdt_postrecov(&env, mdt_dev(obd->obd_lu_dev));
5675 * Send a copytool req to a client
5676 * Note this sends a request RPC from a server (MDT) to a client (MDC),
5677 * backwards of normal comms.
5679 int mdt_hsm_copytool_send(struct obd_export *exp)
5682 struct hsm_action_list *hal;
5683 struct hsm_action_item *hai;
5687 CWARN("%s: writing to mdc at %s\n", exp->exp_obd->obd_name,
5688 libcfs_nid2str(exp->exp_connection->c_peer.nid));
5690 len = sizeof(*lh) + sizeof(*hal) + MTI_NAME_MAXLEN +
5691 /* for mockup below */ 2 * cfs_size_round(sizeof(*hai));
5696 lh->kuc_magic = KUC_MAGIC;
5697 lh->kuc_transport = KUC_TRANSPORT_HSM;
5698 lh->kuc_msgtype = HMT_ACTION_LIST;
5699 lh->kuc_msglen = len;
5701 hal = (struct hsm_action_list *)(lh + 1);
5702 hal->hal_version = HAL_VERSION;
5703 hal->hal_archive_num = 1;
5704 obd_uuid2fsname(hal->hal_fsname, exp->exp_obd->obd_name,
5707 /* mock up an action list */
5709 hai = hai_zero(hal);
5710 hai->hai_action = HSMA_ARCHIVE;
5711 hai->hai_fid.f_oid = 0xA00A;
5712 hai->hai_len = sizeof(*hai);
5713 hai = hai_next(hai);
5714 hai->hai_action = HSMA_RESTORE;
5715 hai->hai_fid.f_oid = 0xB00B;
5716 hai->hai_len = sizeof(*hai);
5718 /* Uses the ldlm reverse import; this rpc will be seen by
5719 the ldlm_callback_handler */
5720 rc = do_set_info_async(exp->exp_imp_reverse,
5721 LDLM_SET_INFO, LUSTRE_OBD_VERSION,
5722 sizeof(KEY_HSM_COPYTOOL_SEND),
5723 KEY_HSM_COPYTOOL_SEND,
5731 static struct obd_ops mdt_obd_device_ops = {
5732 .o_owner = THIS_MODULE,
5733 .o_set_info_async = mdt_obd_set_info_async,
5734 .o_connect = mdt_obd_connect,
5735 .o_reconnect = mdt_obd_reconnect,
5736 .o_disconnect = mdt_obd_disconnect,
5737 .o_init_export = mdt_init_export,
5738 .o_destroy_export = mdt_destroy_export,
5739 .o_iocontrol = mdt_iocontrol,
5740 .o_postrecov = mdt_obd_postrecov,
5741 .o_notify = mdt_obd_notify
5744 static struct lu_device* mdt_device_fini(const struct lu_env *env,
5745 struct lu_device *d)
5747 struct mdt_device *m = mdt_dev(d);
5754 static struct lu_device *mdt_device_free(const struct lu_env *env,
5755 struct lu_device *d)
5757 struct mdt_device *m = mdt_dev(d);
5760 md_device_fini(&m->mdt_md_dev);
5765 static struct lu_device *mdt_device_alloc(const struct lu_env *env,
5766 struct lu_device_type *t,
5767 struct lustre_cfg *cfg)
5769 struct lu_device *l;
5770 struct mdt_device *m;
5776 l = &m->mdt_md_dev.md_lu_dev;
5777 rc = mdt_init0(env, m, t, cfg);
5779 mdt_device_free(env, l);
5783 md_upcall_init(&m->mdt_md_dev, mdt_upcall);
5785 l = ERR_PTR(-ENOMEM);
5789 /* context key constructor/destructor: mdt_key_init, mdt_key_fini */
5790 LU_KEY_INIT_FINI(mdt, struct mdt_thread_info);
5792 /* context key: mdt_thread_key */
5793 LU_CONTEXT_KEY_DEFINE(mdt, LCT_MD_THREAD);
5795 struct md_ucred *mdt_ucred(const struct mdt_thread_info *info)
5797 return md_ucred(info->mti_env);
5801 * Enable/disable COS (Commit On Sharing).
5803 * Set/Clear the COS flag in mdt options.
5805 * \param mdt mdt device
5806 * \param val 0 disables COS, other values enable COS
5808 void mdt_enable_cos(struct mdt_device *mdt, int val)
5813 mdt->mdt_opts.mo_cos = !!val;
5814 rc = lu_env_init(&env, LCT_LOCAL);
5815 if (unlikely(rc != 0)) {
5816 CWARN("lu_env initialization failed with rc = %d,"
5817 "cannot sync\n", rc);
5820 mdt_device_sync(&env, mdt);
5825 * Check COS (Commit On Sharing) status.
5827 * Return COS flag status.
5829 * \param mdt mdt device
5831 int mdt_cos_is_enabled(struct mdt_device *mdt)
5833 return mdt->mdt_opts.mo_cos != 0;
5836 /* type constructor/destructor: mdt_type_init, mdt_type_fini */
5837 LU_TYPE_INIT_FINI(mdt, &mdt_thread_key);
5839 static struct lu_device_type_operations mdt_device_type_ops = {
5840 .ldto_init = mdt_type_init,
5841 .ldto_fini = mdt_type_fini,
5843 .ldto_start = mdt_type_start,
5844 .ldto_stop = mdt_type_stop,
5846 .ldto_device_alloc = mdt_device_alloc,
5847 .ldto_device_free = mdt_device_free,
5848 .ldto_device_fini = mdt_device_fini
5851 static struct lu_device_type mdt_device_type = {
5852 .ldt_tags = LU_DEVICE_MD,
5853 .ldt_name = LUSTRE_MDT_NAME,
5854 .ldt_ops = &mdt_device_type_ops,
5855 .ldt_ctx_tags = LCT_MD_THREAD
5858 static int __init mdt_mod_init(void)
5860 struct lprocfs_static_vars lvars;
5863 lprocfs_mdt_init_vars(&lvars);
5864 rc = class_register_type(&mdt_obd_device_ops, NULL,
5865 lvars.module_vars, LUSTRE_MDT_NAME,
5871 static void __exit mdt_mod_exit(void)
5873 class_unregister_type(LUSTRE_MDT_NAME);
5877 #define DEF_HNDL(prefix, base, suffix, flags, opc, fn, fmt) \
5878 [prefix ## _ ## opc - prefix ## _ ## base] = { \
5880 .mh_fail_id = OBD_FAIL_ ## prefix ## _ ## opc ## suffix, \
5881 .mh_opc = prefix ## _ ## opc, \
5882 .mh_flags = flags, \
5887 #define DEF_MDT_HNDL(flags, name, fn, fmt) \
5888 DEF_HNDL(MDS, GETATTR, _NET, flags, name, fn, fmt)
5890 #define DEF_SEQ_HNDL(flags, name, fn, fmt) \
5891 DEF_HNDL(SEQ, QUERY, _NET, flags, name, fn, fmt)
5893 #define DEF_FLD_HNDL(flags, name, fn, fmt) \
5894 DEF_HNDL(FLD, QUERY, _NET, flags, name, fn, fmt)
5896 * Request with a format known in advance
5898 #define DEF_MDT_HNDL_F(flags, name, fn) \
5899 DEF_HNDL(MDS, GETATTR, _NET, flags, name, fn, &RQF_MDS_ ## name)
5901 #define DEF_SEQ_HNDL_F(flags, name, fn) \
5902 DEF_HNDL(SEQ, QUERY, _NET, flags, name, fn, &RQF_SEQ_ ## name)
5904 #define DEF_FLD_HNDL_F(flags, name, fn) \
5905 DEF_HNDL(FLD, QUERY, _NET, flags, name, fn, &RQF_FLD_ ## name)
5907 * Request with a format we do not yet know
5909 #define DEF_MDT_HNDL_0(flags, name, fn) \
5910 DEF_HNDL(MDS, GETATTR, _NET, flags, name, fn, NULL)
5912 static struct mdt_handler mdt_mds_ops[] = {
5913 DEF_MDT_HNDL_F(0, CONNECT, mdt_connect),
5914 DEF_MDT_HNDL_F(0, DISCONNECT, mdt_disconnect),
5915 DEF_MDT_HNDL (0, SET_INFO, mdt_set_info,
5917 DEF_MDT_HNDL_F(0, GET_INFO, mdt_get_info),
5918 DEF_MDT_HNDL_F(0 |HABEO_REFERO, GETSTATUS, mdt_getstatus),
5919 DEF_MDT_HNDL_F(HABEO_CORPUS, GETATTR, mdt_getattr),
5920 DEF_MDT_HNDL_F(HABEO_CORPUS|HABEO_REFERO, GETATTR_NAME, mdt_getattr_name),
5921 DEF_MDT_HNDL_F(HABEO_CORPUS, GETXATTR, mdt_getxattr),
5922 DEF_MDT_HNDL_F(0 |HABEO_REFERO, STATFS, mdt_statfs),
5923 DEF_MDT_HNDL_F(0 |MUTABOR, REINT, mdt_reint),
5924 DEF_MDT_HNDL_F(HABEO_CORPUS, CLOSE, mdt_close),
5925 DEF_MDT_HNDL_F(HABEO_CORPUS, DONE_WRITING, mdt_done_writing),
5926 DEF_MDT_HNDL_F(0 |HABEO_REFERO, PIN, mdt_pin),
5927 DEF_MDT_HNDL_0(0, SYNC, mdt_sync),
5928 DEF_MDT_HNDL_F(HABEO_CORPUS|HABEO_REFERO, IS_SUBDIR, mdt_is_subdir),
5929 #ifdef HAVE_QUOTA_SUPPORT
5930 DEF_MDT_HNDL_F(0, QUOTACHECK, mdt_quotacheck_handle),
5931 DEF_MDT_HNDL_F(0, QUOTACTL, mdt_quotactl_handle)
5935 #define DEF_OBD_HNDL(flags, name, fn) \
5936 DEF_HNDL(OBD, PING, _NET, flags, name, fn, NULL)
5939 static struct mdt_handler mdt_obd_ops[] = {
5940 DEF_OBD_HNDL(0, PING, mdt_obd_ping),
5941 DEF_OBD_HNDL(0, LOG_CANCEL, mdt_obd_log_cancel),
5942 DEF_OBD_HNDL(0, QC_CALLBACK, mdt_obd_qc_callback)
5945 #define DEF_DLM_HNDL_0(flags, name, fn) \
5946 DEF_HNDL(LDLM, ENQUEUE, , flags, name, fn, NULL)
5947 #define DEF_DLM_HNDL_F(flags, name, fn) \
5948 DEF_HNDL(LDLM, ENQUEUE, , flags, name, fn, &RQF_LDLM_ ## name)
5950 static struct mdt_handler mdt_dlm_ops[] = {
5951 DEF_DLM_HNDL_F(HABEO_CLAVIS, ENQUEUE, mdt_enqueue),
5952 DEF_DLM_HNDL_0(HABEO_CLAVIS, CONVERT, mdt_convert),
5953 DEF_DLM_HNDL_0(0, BL_CALLBACK, mdt_bl_callback),
5954 DEF_DLM_HNDL_0(0, CP_CALLBACK, mdt_cp_callback)
5957 #define DEF_LLOG_HNDL(flags, name, fn) \
5958 DEF_HNDL(LLOG, ORIGIN_HANDLE_CREATE, _NET, flags, name, fn, NULL)
5960 static struct mdt_handler mdt_llog_ops[] = {
5961 DEF_LLOG_HNDL(0, ORIGIN_HANDLE_CREATE, mdt_llog_create),
5962 DEF_LLOG_HNDL(0, ORIGIN_HANDLE_NEXT_BLOCK, mdt_llog_next_block),
5963 DEF_LLOG_HNDL(0, ORIGIN_HANDLE_READ_HEADER, mdt_llog_read_header),
5964 DEF_LLOG_HNDL(0, ORIGIN_HANDLE_WRITE_REC, NULL),
5965 DEF_LLOG_HNDL(0, ORIGIN_HANDLE_CLOSE, NULL),
5966 DEF_LLOG_HNDL(0, ORIGIN_CONNECT, NULL),
5967 DEF_LLOG_HNDL(0, CATINFO, NULL),
5968 DEF_LLOG_HNDL(0, ORIGIN_HANDLE_PREV_BLOCK, mdt_llog_prev_block),
5969 DEF_LLOG_HNDL(0, ORIGIN_HANDLE_DESTROY, mdt_llog_destroy),
5972 #define DEF_SEC_CTX_HNDL(name, fn) \
5973 DEF_HNDL(SEC_CTX, INIT, _NET, 0, name, fn, NULL)
5975 static struct mdt_handler mdt_sec_ctx_ops[] = {
5976 DEF_SEC_CTX_HNDL(INIT, mdt_sec_ctx_handle),
5977 DEF_SEC_CTX_HNDL(INIT_CONT, mdt_sec_ctx_handle),
5978 DEF_SEC_CTX_HNDL(FINI, mdt_sec_ctx_handle)
5981 static struct mdt_opc_slice mdt_regular_handlers[] = {
5983 .mos_opc_start = MDS_GETATTR,
5984 .mos_opc_end = MDS_LAST_OPC,
5985 .mos_hs = mdt_mds_ops
5988 .mos_opc_start = OBD_PING,
5989 .mos_opc_end = OBD_LAST_OPC,
5990 .mos_hs = mdt_obd_ops
5993 .mos_opc_start = LDLM_ENQUEUE,
5994 .mos_opc_end = LDLM_LAST_OPC,
5995 .mos_hs = mdt_dlm_ops
5998 .mos_opc_start = LLOG_ORIGIN_HANDLE_CREATE,
5999 .mos_opc_end = LLOG_LAST_OPC,
6000 .mos_hs = mdt_llog_ops
6003 .mos_opc_start = SEC_CTX_INIT,
6004 .mos_opc_end = SEC_LAST_OPC,
6005 .mos_hs = mdt_sec_ctx_ops
6012 static struct mdt_handler mdt_readpage_ops[] = {
6013 DEF_MDT_HNDL_F(0, CONNECT, mdt_connect),
6014 DEF_MDT_HNDL_F(HABEO_CORPUS|HABEO_REFERO, READPAGE, mdt_readpage),
6015 #ifdef HAVE_SPLIT_SUPPORT
6016 DEF_MDT_HNDL_F(HABEO_CORPUS|HABEO_REFERO, WRITEPAGE, mdt_writepage),
6020 * XXX: this is ugly and should be fixed one day, see mdc_close() for
6021 * detailed comments. --umka
6023 DEF_MDT_HNDL_F(HABEO_CORPUS, CLOSE, mdt_close),
6024 DEF_MDT_HNDL_F(HABEO_CORPUS, DONE_WRITING, mdt_done_writing),
6027 static struct mdt_opc_slice mdt_readpage_handlers[] = {
6029 .mos_opc_start = MDS_GETATTR,
6030 .mos_opc_end = MDS_LAST_OPC,
6031 .mos_hs = mdt_readpage_ops
6038 static struct mdt_handler mdt_xmds_ops[] = {
6039 DEF_MDT_HNDL_F(0, CONNECT, mdt_connect),
6040 DEF_MDT_HNDL_F(HABEO_CORPUS , GETATTR, mdt_getattr),
6041 DEF_MDT_HNDL_F(0 | MUTABOR , REINT, mdt_reint),
6042 DEF_MDT_HNDL_F(HABEO_CORPUS|HABEO_REFERO, IS_SUBDIR, mdt_is_subdir),
6045 static struct mdt_opc_slice mdt_xmds_handlers[] = {
6047 .mos_opc_start = MDS_GETATTR,
6048 .mos_opc_end = MDS_LAST_OPC,
6049 .mos_hs = mdt_xmds_ops
6052 .mos_opc_start = OBD_PING,
6053 .mos_opc_end = OBD_LAST_OPC,
6054 .mos_hs = mdt_obd_ops
6057 .mos_opc_start = SEC_CTX_INIT,
6058 .mos_opc_end = SEC_LAST_OPC,
6059 .mos_hs = mdt_sec_ctx_ops
6066 static struct mdt_handler mdt_seq_ops[] = {
6067 DEF_SEQ_HNDL_F(0, QUERY, (int (*)(struct mdt_thread_info *))seq_query)
6070 static struct mdt_opc_slice mdt_seq_handlers[] = {
6072 .mos_opc_start = SEQ_QUERY,
6073 .mos_opc_end = SEQ_LAST_OPC,
6074 .mos_hs = mdt_seq_ops
6081 static struct mdt_handler mdt_fld_ops[] = {
6082 DEF_FLD_HNDL_F(0, QUERY, (int (*)(struct mdt_thread_info *))fld_query)
6085 static struct mdt_opc_slice mdt_fld_handlers[] = {
6087 .mos_opc_start = FLD_QUERY,
6088 .mos_opc_end = FLD_LAST_OPC,
6089 .mos_hs = mdt_fld_ops
6096 MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");
6097 MODULE_DESCRIPTION("Lustre Meta-data Target ("LUSTRE_MDT_NAME")");
6098 MODULE_LICENSE("GPL");
6100 CFS_MODULE_PARM(mdt_num_threads, "ul", ulong, 0444,
6101 "number of mdt service threads to start");
6103 cfs_module(mdt, "0.2.0", mdt_mod_init, mdt_mod_exit);