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_part *svcpt;
342 struct obd_statfs *osfs;
347 svcpt = info->mti_pill->rc_req->rq_rqbd->rqbd_svcpt;
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(&svcpt->scp_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_new(const struct lu_env *env,
2078 struct mdt_device *d,
2079 const struct lu_fid *f)
2081 struct lu_object_conf conf = { .loc_flags = LOC_F_NEW };
2082 struct lu_object *o;
2083 struct mdt_object *m;
2086 CDEBUG(D_INFO, "Allocate object for "DFID"\n", PFID(f));
2087 o = lu_object_find(env, &d->mdt_md_dev.md_lu_dev, f, &conf);
2088 if (unlikely(IS_ERR(o)))
2089 m = (struct mdt_object *)o;
2095 struct mdt_object *mdt_object_find(const struct lu_env *env,
2096 struct mdt_device *d,
2097 const struct lu_fid *f)
2099 struct lu_object *o;
2100 struct mdt_object *m;
2103 CDEBUG(D_INFO, "Find object for "DFID"\n", PFID(f));
2104 o = lu_object_find(env, &d->mdt_md_dev.md_lu_dev, f, NULL);
2105 if (unlikely(IS_ERR(o)))
2106 m = (struct mdt_object *)o;
2113 * Asyncronous commit for mdt device.
2115 * Pass asynchonous commit call down the MDS stack.
2117 * \param env environment
2118 * \param mdt the mdt device
2120 static void mdt_device_commit_async(const struct lu_env *env,
2121 struct mdt_device *mdt)
2123 struct dt_device *dt = mdt->mdt_bottom;
2126 rc = dt->dd_ops->dt_commit_async(env, dt);
2127 if (unlikely(rc != 0))
2128 CWARN("async commit start failed with rc = %d", rc);
2132 * Mark the lock as "synchonous".
2134 * Mark the lock to deffer transaction commit to the unlock time.
2136 * \param lock the lock to mark as "synchonous"
2138 * \see mdt_is_lock_sync
2139 * \see mdt_save_lock
2141 static inline void mdt_set_lock_sync(struct ldlm_lock *lock)
2143 lock->l_ast_data = (void*)1;
2147 * Check whehter the lock "synchonous" or not.
2149 * \param lock the lock to check
2150 * \retval 1 the lock is "synchonous"
2151 * \retval 0 the lock isn't "synchronous"
2153 * \see mdt_set_lock_sync
2154 * \see mdt_save_lock
2156 static inline int mdt_is_lock_sync(struct ldlm_lock *lock)
2158 return lock->l_ast_data != NULL;
2162 * Blocking AST for mdt locks.
2164 * Starts transaction commit if in case of COS lock conflict or
2165 * deffers such a commit to the mdt_save_lock.
2167 * \param lock the lock which blocks a request or cancelling lock
2168 * \param desc unused
2169 * \param data unused
2170 * \param flag indicates whether this cancelling or blocking callback
2172 * \see ldlm_blocking_ast_nocheck
2174 int mdt_blocking_ast(struct ldlm_lock *lock, struct ldlm_lock_desc *desc,
2175 void *data, int flag)
2177 struct obd_device *obd = ldlm_lock_to_ns(lock)->ns_obd;
2178 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
2182 if (flag == LDLM_CB_CANCELING)
2184 lock_res_and_lock(lock);
2185 if (lock->l_blocking_ast != mdt_blocking_ast) {
2186 unlock_res_and_lock(lock);
2189 if (mdt_cos_is_enabled(mdt) &&
2190 lock->l_req_mode & (LCK_PW | LCK_EX) &&
2191 lock->l_blocking_lock != NULL &&
2192 lock->l_client_cookie != lock->l_blocking_lock->l_client_cookie) {
2193 mdt_set_lock_sync(lock);
2195 rc = ldlm_blocking_ast_nocheck(lock);
2197 /* There is no lock conflict if l_blocking_lock == NULL,
2198 * it indicates a blocking ast sent from ldlm_lock_decref_internal
2199 * when the last reference to a local lock was released */
2200 if (lock->l_req_mode == LCK_COS && lock->l_blocking_lock != NULL) {
2203 rc = lu_env_init(&env, LCT_LOCAL);
2204 if (unlikely(rc != 0))
2205 CWARN("lu_env initialization failed with rc = %d,"
2206 "cannot start asynchronous commit\n", rc);
2208 mdt_device_commit_async(&env, mdt);
2214 int mdt_object_lock(struct mdt_thread_info *info, struct mdt_object *o,
2215 struct mdt_lock_handle *lh, __u64 ibits, int locality)
2217 struct ldlm_namespace *ns = info->mti_mdt->mdt_namespace;
2218 ldlm_policy_data_t *policy = &info->mti_policy;
2219 struct ldlm_res_id *res_id = &info->mti_res_id;
2223 LASSERT(!lustre_handle_is_used(&lh->mlh_reg_lh));
2224 LASSERT(!lustre_handle_is_used(&lh->mlh_pdo_lh));
2225 LASSERT(lh->mlh_reg_mode != LCK_MINMODE);
2226 LASSERT(lh->mlh_type != MDT_NUL_LOCK);
2228 if (mdt_object_exists(o) < 0) {
2229 if (locality == MDT_CROSS_LOCK) {
2230 /* cross-ref object fix */
2231 ibits &= ~MDS_INODELOCK_UPDATE;
2232 ibits |= MDS_INODELOCK_LOOKUP;
2234 LASSERT(!(ibits & MDS_INODELOCK_UPDATE));
2235 LASSERT(ibits & MDS_INODELOCK_LOOKUP);
2237 /* No PDO lock on remote object */
2238 LASSERT(lh->mlh_type != MDT_PDO_LOCK);
2241 if (lh->mlh_type == MDT_PDO_LOCK) {
2242 /* check for exists after object is locked */
2243 if (mdt_object_exists(o) == 0) {
2244 /* Non-existent object shouldn't have PDO lock */
2247 /* Non-dir object shouldn't have PDO lock */
2248 if (!S_ISDIR(lu_object_attr(&o->mot_obj.mo_lu)))
2253 memset(policy, 0, sizeof(*policy));
2254 fid_build_reg_res_name(mdt_object_fid(o), res_id);
2257 * Take PDO lock on whole directory and build correct @res_id for lock
2258 * on part of directory.
2260 if (lh->mlh_pdo_hash != 0) {
2261 LASSERT(lh->mlh_type == MDT_PDO_LOCK);
2262 mdt_lock_pdo_mode(info, o, lh);
2263 if (lh->mlh_pdo_mode != LCK_NL) {
2265 * Do not use LDLM_FL_LOCAL_ONLY for parallel lock, it
2266 * is never going to be sent to client and we do not
2267 * want it slowed down due to possible cancels.
2269 policy->l_inodebits.bits = MDS_INODELOCK_UPDATE;
2270 rc = mdt_fid_lock(ns, &lh->mlh_pdo_lh, lh->mlh_pdo_mode,
2271 policy, res_id, LDLM_FL_ATOMIC_CB,
2272 &info->mti_exp->exp_handle.h_cookie);
2278 * Finish res_id initializing by name hash marking part of
2279 * directory which is taking modification.
2281 res_id->name[LUSTRE_RES_ID_HSH_OFF] = lh->mlh_pdo_hash;
2284 policy->l_inodebits.bits = ibits;
2287 * Use LDLM_FL_LOCAL_ONLY for this lock. We do not know yet if it is
2288 * going to be sent to client. If it is - mdt_intent_policy() path will
2289 * fix it up and turn FL_LOCAL flag off.
2291 rc = mdt_fid_lock(ns, &lh->mlh_reg_lh, lh->mlh_reg_mode, policy,
2292 res_id, LDLM_FL_LOCAL_ONLY | LDLM_FL_ATOMIC_CB,
2293 &info->mti_exp->exp_handle.h_cookie);
2295 mdt_object_unlock(info, o, lh, 1);
2296 else if (unlikely(OBD_FAIL_PRECHECK(OBD_FAIL_MDS_PDO_LOCK)) &&
2297 lh->mlh_pdo_hash != 0 &&
2298 (lh->mlh_reg_mode == LCK_PW || lh->mlh_reg_mode == LCK_EX)) {
2299 OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_PDO_LOCK, 15);
2306 * Save a lock within request object.
2308 * Keep the lock referenced until whether client ACK or transaction
2309 * commit happens or release the lock immediately depending on input
2310 * parameters. If COS is ON, a write lock is converted to COS lock
2313 * \param info thead info object
2314 * \param h lock handle
2315 * \param mode lock mode
2316 * \param decref force immediate lock releasing
2319 void mdt_save_lock(struct mdt_thread_info *info, struct lustre_handle *h,
2320 ldlm_mode_t mode, int decref)
2324 if (lustre_handle_is_used(h)) {
2325 if (decref || !info->mti_has_trans ||
2326 !(mode & (LCK_PW | LCK_EX))){
2327 mdt_fid_unlock(h, mode);
2329 struct mdt_device *mdt = info->mti_mdt;
2330 struct ldlm_lock *lock = ldlm_handle2lock(h);
2331 struct ptlrpc_request *req = mdt_info_req(info);
2334 LASSERTF(lock != NULL, "no lock for cookie "LPX64"\n",
2336 CDEBUG(D_HA, "request = %p reply state = %p"
2337 " transno = "LPD64"\n",
2338 req, req->rq_reply_state, req->rq_transno);
2339 if (mdt_cos_is_enabled(mdt)) {
2341 ldlm_lock_downgrade(lock, LCK_COS);
2344 ptlrpc_save_lock(req, h, mode, no_ack);
2345 if (mdt_is_lock_sync(lock)) {
2346 CDEBUG(D_HA, "found sync-lock,"
2347 " async commit started\n");
2348 mdt_device_commit_async(info->mti_env,
2351 LDLM_LOCK_PUT(lock);
2360 * Unlock mdt object.
2362 * Immeditely release the regular lock and the PDO lock or save the
2363 * lock in reqeuest and keep them referenced until client ACK or
2364 * transaction commit.
2366 * \param info thread info object
2367 * \param o mdt object
2368 * \param lh mdt lock handle referencing regular and PDO locks
2369 * \param decref force immediate lock releasing
2371 void mdt_object_unlock(struct mdt_thread_info *info, struct mdt_object *o,
2372 struct mdt_lock_handle *lh, int decref)
2376 mdt_save_lock(info, &lh->mlh_pdo_lh, lh->mlh_pdo_mode, decref);
2377 mdt_save_lock(info, &lh->mlh_reg_lh, lh->mlh_reg_mode, decref);
2382 struct mdt_object *mdt_object_find_lock(struct mdt_thread_info *info,
2383 const struct lu_fid *f,
2384 struct mdt_lock_handle *lh,
2387 struct mdt_object *o;
2389 o = mdt_object_find(info->mti_env, info->mti_mdt, f);
2393 rc = mdt_object_lock(info, o, lh, ibits,
2396 mdt_object_put(info->mti_env, o);
2403 void mdt_object_unlock_put(struct mdt_thread_info * info,
2404 struct mdt_object * o,
2405 struct mdt_lock_handle *lh,
2408 mdt_object_unlock(info, o, lh, decref);
2409 mdt_object_put(info->mti_env, o);
2412 static struct mdt_handler *mdt_handler_find(__u32 opc,
2413 struct mdt_opc_slice *supported)
2415 struct mdt_opc_slice *s;
2416 struct mdt_handler *h;
2419 for (s = supported; s->mos_hs != NULL; s++) {
2420 if (s->mos_opc_start <= opc && opc < s->mos_opc_end) {
2421 h = s->mos_hs + (opc - s->mos_opc_start);
2422 if (likely(h->mh_opc != 0))
2423 LASSERTF(h->mh_opc == opc,
2424 "opcode mismatch %d != %d\n",
2427 h = NULL; /* unsupported opc */
2434 static int mdt_lock_resname_compat(struct mdt_device *m,
2435 struct ldlm_request *req)
2437 /* XXX something... later. */
2441 static int mdt_lock_reply_compat(struct mdt_device *m, struct ldlm_reply *rep)
2443 /* XXX something... later. */
2448 * Generic code handling requests that have struct mdt_body passed in:
2450 * - extract mdt_body from request and save it in @info, if present;
2452 * - create lu_object, corresponding to the fid in mdt_body, and save it in
2455 * - if HABEO_CORPUS flag is set for this request type check whether object
2456 * actually exists on storage (lu_object_exists()).
2459 static int mdt_body_unpack(struct mdt_thread_info *info, __u32 flags)
2461 const struct mdt_body *body;
2462 struct mdt_object *obj;
2463 const struct lu_env *env;
2464 struct req_capsule *pill;
2468 env = info->mti_env;
2469 pill = info->mti_pill;
2471 body = info->mti_body = req_capsule_client_get(pill, &RMF_MDT_BODY);
2475 if (!(body->valid & OBD_MD_FLID))
2478 if (!fid_is_sane(&body->fid1)) {
2479 CERROR("Invalid fid: "DFID"\n", PFID(&body->fid1));
2484 * Do not get size or any capa fields before we check that request
2485 * contains capa actually. There are some requests which do not, for
2486 * instance MDS_IS_SUBDIR.
2488 if (req_capsule_has_field(pill, &RMF_CAPA1, RCL_CLIENT) &&
2489 req_capsule_get_size(pill, &RMF_CAPA1, RCL_CLIENT))
2490 mdt_set_capainfo(info, 0, &body->fid1,
2491 req_capsule_client_get(pill, &RMF_CAPA1));
2493 obj = mdt_object_find(env, info->mti_mdt, &body->fid1);
2495 if ((flags & HABEO_CORPUS) &&
2496 !mdt_object_exists(obj)) {
2497 mdt_object_put(env, obj);
2498 /* for capability renew ENOENT will be handled in
2500 if (body->valid & OBD_MD_FLOSSCAPA)
2505 info->mti_object = obj;
2514 static int mdt_unpack_req_pack_rep(struct mdt_thread_info *info, __u32 flags)
2516 struct req_capsule *pill = info->mti_pill;
2520 if (req_capsule_has_field(pill, &RMF_MDT_BODY, RCL_CLIENT))
2521 rc = mdt_body_unpack(info, flags);
2525 if (rc == 0 && (flags & HABEO_REFERO)) {
2527 if (req_capsule_has_field(pill, &RMF_MDT_MD, RCL_SERVER))
2528 req_capsule_set_size(pill, &RMF_MDT_MD, RCL_SERVER,
2529 info->mti_body->eadatasize);
2530 if (req_capsule_has_field(pill, &RMF_LOGCOOKIES, RCL_SERVER))
2531 req_capsule_set_size(pill, &RMF_LOGCOOKIES, RCL_SERVER,
2532 info->mti_mdt->mdt_max_cookiesize);
2534 rc = req_capsule_server_pack(pill);
2539 static int mdt_init_capa_ctxt(const struct lu_env *env, struct mdt_device *m)
2541 struct md_device *next = m->mdt_child;
2543 return next->md_ops->mdo_init_capa_ctxt(env, next,
2544 m->mdt_opts.mo_mds_capa,
2545 m->mdt_capa_timeout,
2551 * Invoke handler for this request opc. Also do necessary preprocessing
2552 * (according to handler ->mh_flags), and post-processing (setting of
2553 * ->last_{xid,committed}).
2555 static int mdt_req_handle(struct mdt_thread_info *info,
2556 struct mdt_handler *h, struct ptlrpc_request *req)
2558 int rc, serious = 0;
2563 LASSERT(h->mh_act != NULL);
2564 LASSERT(h->mh_opc == lustre_msg_get_opc(req->rq_reqmsg));
2565 LASSERT(current->journal_info == NULL);
2568 * Checking for various OBD_FAIL_$PREF_$OPC_NET codes. _Do_ not try
2569 * to put same checks into handlers like mdt_close(), mdt_reint(),
2570 * etc., without talking to mdt authors first. Checking same thing
2571 * there again is useless and returning 0 error without packing reply
2572 * is buggy! Handlers either pack reply or return error.
2574 * We return 0 here and do not send any reply in order to emulate
2575 * network failure. Do not send any reply in case any of NET related
2576 * fail_id has occured.
2578 if (OBD_FAIL_CHECK_ORSET(h->mh_fail_id, OBD_FAIL_ONCE))
2582 flags = h->mh_flags;
2583 LASSERT(ergo(flags & (HABEO_CORPUS|HABEO_REFERO), h->mh_fmt != NULL));
2585 if (h->mh_fmt != NULL) {
2586 req_capsule_set(info->mti_pill, h->mh_fmt);
2587 rc = mdt_unpack_req_pack_rep(info, flags);
2590 if (rc == 0 && flags & MUTABOR &&
2591 req->rq_export->exp_connect_flags & OBD_CONNECT_RDONLY)
2592 /* should it be rq_status? */
2595 if (rc == 0 && flags & HABEO_CLAVIS) {
2596 struct ldlm_request *dlm_req;
2598 LASSERT(h->mh_fmt != NULL);
2600 dlm_req = req_capsule_client_get(info->mti_pill, &RMF_DLM_REQ);
2601 if (dlm_req != NULL) {
2602 if (unlikely(dlm_req->lock_desc.l_resource.lr_type ==
2604 dlm_req->lock_desc.l_policy_data.\
2605 l_inodebits.bits == 0)) {
2607 * Lock without inodebits makes no sense and
2608 * will oops later in ldlm. If client miss to
2609 * set such bits, do not trigger ASSERTION.
2611 * For liblustre flock case, it maybe zero.
2615 if (info->mti_mdt->mdt_opts.mo_compat_resname)
2616 rc = mdt_lock_resname_compat(
2619 info->mti_dlm_req = dlm_req;
2626 /* capability setting changed via /proc, needs reinitialize ctxt */
2627 if (info->mti_mdt && info->mti_mdt->mdt_capa_conf) {
2628 mdt_init_capa_ctxt(info->mti_env, info->mti_mdt);
2629 info->mti_mdt->mdt_capa_conf = 0;
2632 if (likely(rc == 0)) {
2634 * Process request, there can be two types of rc:
2635 * 1) errors with msg unpack/pack, other failures outside the
2636 * operation itself. This is counted as serious errors;
2637 * 2) errors during fs operation, should be placed in rq_status
2640 rc = h->mh_act(info);
2642 !req->rq_no_reply && req->rq_reply_state == NULL) {
2643 DEBUG_REQ(D_ERROR, req, "MDT \"handler\" %s did not "
2644 "pack reply and returned 0 error\n",
2648 serious = is_serious(rc);
2649 rc = clear_serious(rc);
2653 req->rq_status = rc;
2656 * ELDLM_* codes which > 0 should be in rq_status only as well as
2657 * all non-serious errors.
2659 if (rc > 0 || !serious)
2662 LASSERT(current->journal_info == NULL);
2664 if (rc == 0 && (flags & HABEO_CLAVIS) &&
2665 info->mti_mdt->mdt_opts.mo_compat_resname) {
2666 struct ldlm_reply *dlmrep;
2668 dlmrep = req_capsule_server_get(info->mti_pill, &RMF_DLM_REP);
2670 rc = mdt_lock_reply_compat(info->mti_mdt, dlmrep);
2673 /* If we're DISCONNECTing, the mdt_export_data is already freed */
2674 if (likely(rc == 0 && req->rq_export && h->mh_opc != MDS_DISCONNECT))
2675 target_committed_to_req(req);
2677 if (unlikely(req_is_replay(req) &&
2678 lustre_msg_get_transno(req->rq_reqmsg) == 0)) {
2679 DEBUG_REQ(D_ERROR, req, "transno is 0 during REPLAY");
2683 target_send_reply(req, rc, info->mti_fail_id);
2687 void mdt_lock_handle_init(struct mdt_lock_handle *lh)
2689 lh->mlh_type = MDT_NUL_LOCK;
2690 lh->mlh_reg_lh.cookie = 0ull;
2691 lh->mlh_reg_mode = LCK_MINMODE;
2692 lh->mlh_pdo_lh.cookie = 0ull;
2693 lh->mlh_pdo_mode = LCK_MINMODE;
2696 void mdt_lock_handle_fini(struct mdt_lock_handle *lh)
2698 LASSERT(!lustre_handle_is_used(&lh->mlh_reg_lh));
2699 LASSERT(!lustre_handle_is_used(&lh->mlh_pdo_lh));
2703 * Initialize fields of struct mdt_thread_info. Other fields are left in
2704 * uninitialized state, because it's too expensive to zero out whole
2705 * mdt_thread_info (> 1K) on each request arrival.
2707 static void mdt_thread_info_init(struct ptlrpc_request *req,
2708 struct mdt_thread_info *info)
2711 struct md_capainfo *ci;
2713 req_capsule_init(&req->rq_pill, req, RCL_SERVER);
2714 info->mti_pill = &req->rq_pill;
2717 for (i = 0; i < ARRAY_SIZE(info->mti_lh); i++)
2718 mdt_lock_handle_init(&info->mti_lh[i]);
2720 /* mdt device: it can be NULL while CONNECT */
2721 if (req->rq_export) {
2722 info->mti_mdt = mdt_dev(req->rq_export->exp_obd->obd_lu_dev);
2723 info->mti_exp = req->rq_export;
2725 info->mti_mdt = NULL;
2726 info->mti_env = req->rq_svc_thread->t_env;
2727 ci = md_capainfo(info->mti_env);
2728 memset(ci, 0, sizeof *ci);
2729 if (req->rq_export) {
2730 if (exp_connect_rmtclient(req->rq_export))
2731 ci->mc_auth = LC_ID_CONVERT;
2732 else if (req->rq_export->exp_connect_flags &
2733 OBD_CONNECT_MDS_CAPA)
2734 ci->mc_auth = LC_ID_PLAIN;
2736 ci->mc_auth = LC_ID_NONE;
2739 info->mti_fail_id = OBD_FAIL_MDS_ALL_REPLY_NET;
2740 info->mti_transno = lustre_msg_get_transno(req->rq_reqmsg);
2741 info->mti_mos = NULL;
2743 memset(&info->mti_attr, 0, sizeof(info->mti_attr));
2744 info->mti_body = NULL;
2745 info->mti_object = NULL;
2746 info->mti_dlm_req = NULL;
2747 info->mti_has_trans = 0;
2748 info->mti_no_need_trans = 0;
2749 info->mti_cross_ref = 0;
2750 info->mti_opdata = 0;
2752 /* To not check for split by default. */
2753 info->mti_spec.sp_ck_split = 0;
2754 info->mti_spec.no_create = 0;
2757 static void mdt_thread_info_fini(struct mdt_thread_info *info)
2761 req_capsule_fini(info->mti_pill);
2762 if (info->mti_object != NULL) {
2764 * freeing an object may lead to OSD level transaction, do not
2765 * let it mess with MDT. bz19385.
2767 info->mti_no_need_trans = 1;
2768 mdt_object_put(info->mti_env, info->mti_object);
2769 info->mti_object = NULL;
2771 for (i = 0; i < ARRAY_SIZE(info->mti_lh); i++)
2772 mdt_lock_handle_fini(&info->mti_lh[i]);
2773 info->mti_env = NULL;
2776 static int mdt_filter_recovery_request(struct ptlrpc_request *req,
2777 struct obd_device *obd, int *process)
2779 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
2780 case MDS_CONNECT: /* This will never get here, but for completeness. */
2781 case OST_CONNECT: /* This will never get here, but for completeness. */
2782 case MDS_DISCONNECT:
2783 case OST_DISCONNECT:
2788 case MDS_DONE_WRITING:
2789 case MDS_SYNC: /* used in unmounting */
2795 *process = target_queue_recovery_request(req, obd);
2799 DEBUG_REQ(D_ERROR, req, "not permitted during recovery");
2806 * Handle recovery. Return:
2807 * +1: continue request processing;
2808 * -ve: abort immediately with the given error code;
2809 * 0: send reply with error code in req->rq_status;
2811 static int mdt_recovery(struct mdt_thread_info *info)
2813 struct ptlrpc_request *req = mdt_info_req(info);
2814 struct obd_device *obd;
2818 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
2821 case SEC_CTX_INIT_CONT:
2827 rc = mdt_handle_idmap(info);
2836 if (unlikely(!class_connected_export(req->rq_export))) {
2837 CERROR("operation %d on unconnected MDS from %s\n",
2838 lustre_msg_get_opc(req->rq_reqmsg),
2839 libcfs_id2str(req->rq_peer));
2840 /* FIXME: For CMD cleanup, when mds_B stop, the req from
2841 * mds_A will get -ENOTCONN(especially for ping req),
2842 * which will cause that mds_A deactive timeout, then when
2843 * mds_A cleanup, the cleanup process will be suspended since
2844 * deactive timeout is not zero.
2846 req->rq_status = -ENOTCONN;
2847 target_send_reply(req, -ENOTCONN, info->mti_fail_id);
2851 /* sanity check: if the xid matches, the request must be marked as a
2852 * resent or replayed */
2853 if (req_xid_is_last(req)) {
2854 if (!(lustre_msg_get_flags(req->rq_reqmsg) &
2855 (MSG_RESENT | MSG_REPLAY))) {
2856 DEBUG_REQ(D_WARNING, req, "rq_xid "LPU64" matches last_xid, "
2857 "expected REPLAY or RESENT flag (%x)", req->rq_xid,
2858 lustre_msg_get_flags(req->rq_reqmsg));
2860 req->rq_status = -ENOTCONN;
2865 /* else: note the opposite is not always true; a RESENT req after a
2866 * failover will usually not match the last_xid, since it was likely
2867 * never committed. A REPLAYed request will almost never match the
2868 * last xid, however it could for a committed, but still retained,
2871 obd = req->rq_export->exp_obd;
2873 /* Check for aborted recovery... */
2874 if (unlikely(obd->obd_recovering)) {
2877 DEBUG_REQ(D_INFO, req, "Got new replay");
2878 rc = mdt_filter_recovery_request(req, obd, &should_process);
2879 if (rc != 0 || !should_process)
2881 else if (should_process < 0) {
2882 req->rq_status = should_process;
2883 rc = ptlrpc_error(req);
2890 static int mdt_msg_check_version(struct lustre_msg *msg)
2894 switch (lustre_msg_get_opc(msg)) {
2896 case MDS_DISCONNECT:
2899 case SEC_CTX_INIT_CONT:
2901 rc = lustre_msg_check_version(msg, LUSTRE_OBD_VERSION);
2903 CERROR("bad opc %u version %08x, expecting %08x\n",
2904 lustre_msg_get_opc(msg),
2905 lustre_msg_get_version(msg),
2906 LUSTRE_OBD_VERSION);
2910 case MDS_GETATTR_NAME:
2917 case MDS_DONE_WRITING:
2924 case MDS_QUOTACHECK:
2930 rc = lustre_msg_check_version(msg, LUSTRE_MDS_VERSION);
2932 CERROR("bad opc %u version %08x, expecting %08x\n",
2933 lustre_msg_get_opc(msg),
2934 lustre_msg_get_version(msg),
2935 LUSTRE_MDS_VERSION);
2939 case LDLM_BL_CALLBACK:
2940 case LDLM_CP_CALLBACK:
2941 rc = lustre_msg_check_version(msg, LUSTRE_DLM_VERSION);
2943 CERROR("bad opc %u version %08x, expecting %08x\n",
2944 lustre_msg_get_opc(msg),
2945 lustre_msg_get_version(msg),
2946 LUSTRE_DLM_VERSION);
2948 case OBD_LOG_CANCEL:
2949 case LLOG_ORIGIN_HANDLE_CREATE:
2950 case LLOG_ORIGIN_HANDLE_NEXT_BLOCK:
2951 case LLOG_ORIGIN_HANDLE_READ_HEADER:
2952 case LLOG_ORIGIN_HANDLE_CLOSE:
2953 case LLOG_ORIGIN_HANDLE_DESTROY:
2954 case LLOG_ORIGIN_HANDLE_PREV_BLOCK:
2956 rc = lustre_msg_check_version(msg, LUSTRE_LOG_VERSION);
2958 CERROR("bad opc %u version %08x, expecting %08x\n",
2959 lustre_msg_get_opc(msg),
2960 lustre_msg_get_version(msg),
2961 LUSTRE_LOG_VERSION);
2964 CERROR("MDS unknown opcode %d\n", lustre_msg_get_opc(msg));
2970 static int mdt_handle0(struct ptlrpc_request *req,
2971 struct mdt_thread_info *info,
2972 struct mdt_opc_slice *supported)
2974 struct mdt_handler *h;
2975 struct lustre_msg *msg;
2980 if (OBD_FAIL_CHECK_ORSET(OBD_FAIL_MDS_ALL_REQUEST_NET, OBD_FAIL_ONCE))
2983 LASSERT(current->journal_info == NULL);
2985 msg = req->rq_reqmsg;
2986 rc = mdt_msg_check_version(msg);
2987 if (likely(rc == 0)) {
2988 rc = mdt_recovery(info);
2989 if (likely(rc == +1)) {
2990 h = mdt_handler_find(lustre_msg_get_opc(msg),
2992 if (likely(h != NULL)) {
2993 rc = mdt_req_handle(info, h, req);
2995 CERROR("The unsupported opc: 0x%x\n",
2996 lustre_msg_get_opc(msg) );
2997 req->rq_status = -ENOTSUPP;
2998 rc = ptlrpc_error(req);
3003 CERROR(LUSTRE_MDT_NAME" drops mal-formed request\n");
3008 * MDT handler function called by ptlrpc service thread when request comes.
3010 * XXX common "target" functionality should be factored into separate module
3011 * shared by mdt, ost and stand-alone services like fld.
3013 static int mdt_handle_common(struct ptlrpc_request *req,
3014 struct mdt_opc_slice *supported)
3017 struct mdt_thread_info *info;
3021 env = req->rq_svc_thread->t_env;
3022 LASSERT(env != NULL);
3023 LASSERT(env->le_ses != NULL);
3024 LASSERT(env->le_ctx.lc_thread == req->rq_svc_thread);
3025 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
3026 LASSERT(info != NULL);
3028 mdt_thread_info_init(req, info);
3030 rc = mdt_handle0(req, info, supported);
3032 mdt_thread_info_fini(info);
3037 * This is called from recovery code as handler of _all_ RPC types, FLD and SEQ
3040 int mdt_recovery_handle(struct ptlrpc_request *req)
3045 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
3047 rc = mdt_handle_common(req, mdt_fld_handlers);
3050 rc = mdt_handle_common(req, mdt_seq_handlers);
3053 rc = mdt_handle_common(req, mdt_regular_handlers);
3060 static int mdt_regular_handle(struct ptlrpc_request *req)
3062 return mdt_handle_common(req, mdt_regular_handlers);
3065 static int mdt_readpage_handle(struct ptlrpc_request *req)
3067 return mdt_handle_common(req, mdt_readpage_handlers);
3070 static int mdt_xmds_handle(struct ptlrpc_request *req)
3072 return mdt_handle_common(req, mdt_xmds_handlers);
3075 static int mdt_mdsc_handle(struct ptlrpc_request *req)
3077 return mdt_handle_common(req, mdt_seq_handlers);
3080 static int mdt_mdss_handle(struct ptlrpc_request *req)
3082 return mdt_handle_common(req, mdt_seq_handlers);
3085 static int mdt_dtss_handle(struct ptlrpc_request *req)
3087 return mdt_handle_common(req, mdt_seq_handlers);
3090 static int mdt_fld_handle(struct ptlrpc_request *req)
3092 return mdt_handle_common(req, mdt_fld_handlers);
3109 static int mdt_intent_getattr(enum mdt_it_code opcode,
3110 struct mdt_thread_info *info,
3111 struct ldlm_lock **,
3113 static int mdt_intent_reint(enum mdt_it_code opcode,
3114 struct mdt_thread_info *info,
3115 struct ldlm_lock **,
3118 static struct mdt_it_flavor {
3119 const struct req_format *it_fmt;
3121 int (*it_act)(enum mdt_it_code ,
3122 struct mdt_thread_info *,
3123 struct ldlm_lock **,
3126 } mdt_it_flavor[] = {
3128 .it_fmt = &RQF_LDLM_INTENT,
3129 /*.it_flags = HABEO_REFERO,*/
3131 .it_act = mdt_intent_reint,
3132 .it_reint = REINT_OPEN
3135 .it_fmt = &RQF_LDLM_INTENT,
3136 .it_flags = MUTABOR,
3137 .it_act = mdt_intent_reint,
3138 .it_reint = REINT_OPEN
3141 .it_fmt = &RQF_LDLM_INTENT,
3142 .it_flags = MUTABOR,
3143 .it_act = mdt_intent_reint,
3144 .it_reint = REINT_CREATE
3146 [MDT_IT_GETATTR] = {
3147 .it_fmt = &RQF_LDLM_INTENT_GETATTR,
3148 .it_flags = HABEO_REFERO,
3149 .it_act = mdt_intent_getattr
3151 [MDT_IT_READDIR] = {
3157 .it_fmt = &RQF_LDLM_INTENT_GETATTR,
3158 .it_flags = HABEO_REFERO,
3159 .it_act = mdt_intent_getattr
3162 .it_fmt = &RQF_LDLM_INTENT_UNLINK,
3163 .it_flags = MUTABOR,
3165 .it_reint = REINT_UNLINK
3169 .it_flags = MUTABOR,
3172 [MDT_IT_GETXATTR] = {
3178 .it_fmt = &RQF_LDLM_INTENT_GETATTR,
3179 .it_flags = HABEO_REFERO,
3180 .it_act = mdt_intent_getattr
3184 int mdt_intent_lock_replace(struct mdt_thread_info *info,
3185 struct ldlm_lock **lockp,
3186 struct ldlm_lock *new_lock,
3187 struct mdt_lock_handle *lh,
3190 struct ptlrpc_request *req = mdt_info_req(info);
3191 struct ldlm_lock *lock = *lockp;
3194 * Get new lock only for cases when possible resent did not find any
3197 if (new_lock == NULL)
3198 new_lock = ldlm_handle2lock_long(&lh->mlh_reg_lh, 0);
3200 if (new_lock == NULL && (flags & LDLM_FL_INTENT_ONLY)) {
3201 lh->mlh_reg_lh.cookie = 0;
3205 LASSERTF(new_lock != NULL,
3206 "lockh "LPX64"\n", lh->mlh_reg_lh.cookie);
3209 * If we've already given this lock to a client once, then we should
3210 * have no readers or writers. Otherwise, we should have one reader
3211 * _or_ writer ref (which will be zeroed below) before returning the
3214 if (new_lock->l_export == req->rq_export) {
3215 LASSERT(new_lock->l_readers + new_lock->l_writers == 0);
3217 LASSERT(new_lock->l_export == NULL);
3218 LASSERT(new_lock->l_readers + new_lock->l_writers == 1);
3223 if (new_lock->l_export == req->rq_export) {
3225 * Already gave this to the client, which means that we
3226 * reconstructed a reply.
3228 LASSERT(lustre_msg_get_flags(req->rq_reqmsg) &
3230 lh->mlh_reg_lh.cookie = 0;
3231 RETURN(ELDLM_LOCK_REPLACED);
3235 * Fixup the lock to be given to the client.
3237 lock_res_and_lock(new_lock);
3238 /* Zero new_lock->l_readers and new_lock->l_writers without triggering
3239 * possible blocking AST. */
3240 while (new_lock->l_readers > 0) {
3241 lu_ref_del(&new_lock->l_reference, "reader", new_lock);
3242 lu_ref_del(&new_lock->l_reference, "user", new_lock);
3243 new_lock->l_readers--;
3245 while (new_lock->l_writers > 0) {
3246 lu_ref_del(&new_lock->l_reference, "writer", new_lock);
3247 lu_ref_del(&new_lock->l_reference, "user", new_lock);
3248 new_lock->l_writers--;
3251 new_lock->l_export = class_export_lock_get(req->rq_export, new_lock);
3252 new_lock->l_blocking_ast = lock->l_blocking_ast;
3253 new_lock->l_completion_ast = lock->l_completion_ast;
3254 new_lock->l_remote_handle = lock->l_remote_handle;
3255 new_lock->l_flags &= ~LDLM_FL_LOCAL;
3257 unlock_res_and_lock(new_lock);
3259 cfs_hash_add(new_lock->l_export->exp_lock_hash,
3260 &new_lock->l_remote_handle,
3261 &new_lock->l_exp_hash);
3263 LDLM_LOCK_RELEASE(new_lock);
3264 lh->mlh_reg_lh.cookie = 0;
3266 RETURN(ELDLM_LOCK_REPLACED);
3269 static void mdt_intent_fixup_resent(struct mdt_thread_info *info,
3270 struct ldlm_lock *new_lock,
3271 struct ldlm_lock **old_lock,
3272 struct mdt_lock_handle *lh)
3274 struct ptlrpc_request *req = mdt_info_req(info);
3275 struct obd_export *exp = req->rq_export;
3276 struct lustre_handle remote_hdl;
3277 struct ldlm_request *dlmreq;
3278 struct ldlm_lock *lock;
3280 if (!(lustre_msg_get_flags(req->rq_reqmsg) & MSG_RESENT))
3283 dlmreq = req_capsule_client_get(info->mti_pill, &RMF_DLM_REQ);
3284 remote_hdl = dlmreq->lock_handle[0];
3286 lock = cfs_hash_lookup(exp->exp_lock_hash, &remote_hdl);
3288 if (lock != new_lock) {
3289 lh->mlh_reg_lh.cookie = lock->l_handle.h_cookie;
3290 lh->mlh_reg_mode = lock->l_granted_mode;
3292 LDLM_DEBUG(lock, "Restoring lock cookie");
3293 DEBUG_REQ(D_DLMTRACE, req,
3294 "restoring lock cookie "LPX64,
3295 lh->mlh_reg_lh.cookie);
3297 *old_lock = LDLM_LOCK_GET(lock);
3298 cfs_hash_put(exp->exp_lock_hash, &lock->l_exp_hash);
3302 cfs_hash_put(exp->exp_lock_hash, &lock->l_exp_hash);
3306 * If the xid matches, then we know this is a resent request, and allow
3307 * it. (It's probably an OPEN, for which we don't send a lock.
3309 if (req_xid_is_last(req))
3313 * This remote handle isn't enqueued, so we never received or processed
3314 * this request. Clear MSG_RESENT, because it can be handled like any
3315 * normal request now.
3317 lustre_msg_clear_flags(req->rq_reqmsg, MSG_RESENT);
3319 DEBUG_REQ(D_DLMTRACE, req, "no existing lock with rhandle "LPX64,
3323 static int mdt_intent_getattr(enum mdt_it_code opcode,
3324 struct mdt_thread_info *info,
3325 struct ldlm_lock **lockp,
3328 struct mdt_lock_handle *lhc = &info->mti_lh[MDT_LH_RMT];
3329 struct ldlm_lock *new_lock = NULL;
3331 struct ldlm_reply *ldlm_rep;
3332 struct ptlrpc_request *req;
3333 struct mdt_body *reqbody;
3334 struct mdt_body *repbody;
3338 reqbody = req_capsule_client_get(info->mti_pill, &RMF_MDT_BODY);
3341 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
3344 info->mti_spec.sp_ck_split = !!(reqbody->valid & OBD_MD_FLCKSPLIT);
3345 info->mti_cross_ref = !!(reqbody->valid & OBD_MD_FLCROSSREF);
3346 repbody->eadatasize = 0;
3347 repbody->aclsize = 0;
3351 child_bits = MDS_INODELOCK_LOOKUP;
3353 case MDT_IT_GETATTR:
3354 child_bits = MDS_INODELOCK_LOOKUP | MDS_INODELOCK_UPDATE;
3356 case MDT_IT_LAYOUT: {
3357 static int printed = 0;
3360 CERROR("layout lock not supported by this version\n");
3363 GOTO(out_shrink, rc = -EINVAL);
3367 CERROR("Unsupported intent (%d)\n", opcode);
3368 GOTO(out_shrink, rc = -EINVAL);
3371 rc = mdt_init_ucred(info, reqbody);
3373 GOTO(out_shrink, rc);
3375 req = info->mti_pill->rc_req;
3376 ldlm_rep = req_capsule_server_get(info->mti_pill, &RMF_DLM_REP);
3377 mdt_set_disposition(info, ldlm_rep, DISP_IT_EXECD);
3379 /* Get lock from request for possible resent case. */
3380 mdt_intent_fixup_resent(info, *lockp, &new_lock, lhc);
3382 ldlm_rep->lock_policy_res2 =
3383 mdt_getattr_name_lock(info, lhc, child_bits, ldlm_rep);
3385 if (mdt_get_disposition(ldlm_rep, DISP_LOOKUP_NEG))
3386 ldlm_rep->lock_policy_res2 = 0;
3387 if (!mdt_get_disposition(ldlm_rep, DISP_LOOKUP_POS) ||
3388 ldlm_rep->lock_policy_res2) {
3389 lhc->mlh_reg_lh.cookie = 0ull;
3390 GOTO(out_ucred, rc = ELDLM_LOCK_ABORTED);
3393 rc = mdt_intent_lock_replace(info, lockp, new_lock, lhc, flags);
3396 mdt_exit_ucred(info);
3398 mdt_client_compatibility(info);
3399 rc2 = mdt_fix_reply(info);
3405 static int mdt_intent_reint(enum mdt_it_code opcode,
3406 struct mdt_thread_info *info,
3407 struct ldlm_lock **lockp,
3410 struct mdt_lock_handle *lhc = &info->mti_lh[MDT_LH_RMT];
3411 struct ldlm_reply *rep = NULL;
3415 static const struct req_format *intent_fmts[REINT_MAX] = {
3416 [REINT_CREATE] = &RQF_LDLM_INTENT_CREATE,
3417 [REINT_OPEN] = &RQF_LDLM_INTENT_OPEN
3422 opc = mdt_reint_opcode(info, intent_fmts);
3426 if (mdt_it_flavor[opcode].it_reint != opc) {
3427 CERROR("Reint code %ld doesn't match intent: %d\n",
3429 RETURN(err_serious(-EPROTO));
3432 /* Get lock from request for possible resent case. */
3433 mdt_intent_fixup_resent(info, *lockp, NULL, lhc);
3435 rc = mdt_reint_internal(info, lhc, opc);
3437 /* Check whether the reply has been packed successfully. */
3438 if (mdt_info_req(info)->rq_repmsg != NULL)
3439 rep = req_capsule_server_get(info->mti_pill, &RMF_DLM_REP);
3441 RETURN(err_serious(-EFAULT));
3443 /* MDC expects this in any case */
3445 mdt_set_disposition(info, rep, DISP_LOOKUP_EXECD);
3447 /* Cross-ref case, the lock should be returned to the client */
3448 if (rc == -EREMOTE) {
3449 LASSERT(lustre_handle_is_used(&lhc->mlh_reg_lh));
3450 rep->lock_policy_res2 = 0;
3451 rc = mdt_intent_lock_replace(info, lockp, NULL, lhc, flags);
3454 rep->lock_policy_res2 = clear_serious(rc);
3456 if (rep->lock_policy_res2 == -ENOENT &&
3457 mdt_get_disposition(rep, DISP_LOOKUP_NEG))
3458 rep->lock_policy_res2 = 0;
3460 if (rc == -ENOTCONN || rc == -ENODEV ||
3461 rc == -EOVERFLOW) { /**< if VBR failure then return error */
3463 * If it is the disconnect error (ENODEV & ENOCONN), the error
3464 * will be returned by rq_status, and client at ptlrpc layer
3465 * will detect this, then disconnect, reconnect the import
3466 * immediately, instead of impacting the following the rpc.
3468 lhc->mlh_reg_lh.cookie = 0ull;
3472 * For other cases, the error will be returned by intent.
3473 * and client will retrieve the result from intent.
3476 * FIXME: when open lock is finished, that should be
3479 if (lustre_handle_is_used(&lhc->mlh_reg_lh)) {
3480 LASSERTF(rc == 0, "Error occurred but lock handle "
3481 "is still in use\n");
3482 rep->lock_policy_res2 = 0;
3483 rc = mdt_intent_lock_replace(info, lockp, NULL, lhc, flags);
3486 lhc->mlh_reg_lh.cookie = 0ull;
3487 RETURN(ELDLM_LOCK_ABORTED);
3492 static int mdt_intent_code(long itcode)
3500 case IT_OPEN|IT_CREAT:
3507 rc = MDT_IT_READDIR;
3510 rc = MDT_IT_GETATTR;
3522 rc = MDT_IT_GETXATTR;
3528 CERROR("Unknown intent opcode: %ld\n", itcode);
3535 static int mdt_intent_opc(long itopc, struct mdt_thread_info *info,
3536 struct ldlm_lock **lockp, int flags)
3538 struct req_capsule *pill;
3539 struct mdt_it_flavor *flv;
3544 opc = mdt_intent_code(itopc);
3548 pill = info->mti_pill;
3549 flv = &mdt_it_flavor[opc];
3551 if (flv->it_fmt != NULL)
3552 req_capsule_extend(pill, flv->it_fmt);
3554 rc = mdt_unpack_req_pack_rep(info, flv->it_flags);
3556 struct ptlrpc_request *req = mdt_info_req(info);
3557 if (flv->it_flags & MUTABOR &&
3558 req->rq_export->exp_connect_flags & OBD_CONNECT_RDONLY)
3561 if (rc == 0 && flv->it_act != NULL) {
3562 /* execute policy */
3563 rc = flv->it_act(opc, info, lockp, flags);
3570 static int mdt_intent_policy(struct ldlm_namespace *ns,
3571 struct ldlm_lock **lockp, void *req_cookie,
3572 ldlm_mode_t mode, int flags, void *data)
3574 struct mdt_thread_info *info;
3575 struct ptlrpc_request *req = req_cookie;
3576 struct ldlm_intent *it;
3577 struct req_capsule *pill;
3582 LASSERT(req != NULL);
3584 info = lu_context_key_get(&req->rq_svc_thread->t_env->le_ctx,
3586 LASSERT(info != NULL);
3587 pill = info->mti_pill;
3588 LASSERT(pill->rc_req == req);
3590 if (req->rq_reqmsg->lm_bufcount > DLM_INTENT_IT_OFF) {
3591 req_capsule_extend(pill, &RQF_LDLM_INTENT);
3592 it = req_capsule_client_get(pill, &RMF_LDLM_INTENT);
3594 rc = mdt_intent_opc(it->opc, info, lockp, flags);
3598 /* Lock without inodebits makes no sense and will oops
3599 * later in ldlm. Let's check it now to see if we have
3600 * ibits corrupted somewhere in mdt_intent_opc().
3601 * The case for client miss to set ibits has been
3602 * processed by others. */
3603 LASSERT(ergo(info->mti_dlm_req->lock_desc.l_resource.\
3604 lr_type == LDLM_IBITS,
3605 info->mti_dlm_req->lock_desc.\
3606 l_policy_data.l_inodebits.bits != 0));
3608 rc = err_serious(-EFAULT);
3610 /* No intent was provided */
3611 LASSERT(pill->rc_fmt == &RQF_LDLM_ENQUEUE);
3612 rc = req_capsule_server_pack(pill);
3614 rc = err_serious(rc);
3619 static int mdt_seq_fini(const struct lu_env *env,
3620 struct mdt_device *m)
3622 struct md_site *ms = mdt_md_site(m);
3626 if (ms->ms_server_seq) {
3627 seq_server_fini(ms->ms_server_seq, env);
3628 OBD_FREE_PTR(ms->ms_server_seq);
3629 ms->ms_server_seq = NULL;
3632 if (ms->ms_control_seq) {
3633 seq_server_fini(ms->ms_control_seq, env);
3634 OBD_FREE_PTR(ms->ms_control_seq);
3635 ms->ms_control_seq = NULL;
3638 if (ms->ms_client_seq) {
3639 seq_client_fini(ms->ms_client_seq);
3640 OBD_FREE_PTR(ms->ms_client_seq);
3641 ms->ms_client_seq = NULL;
3648 static int mdt_seq_init(const struct lu_env *env,
3650 struct mdt_device *m)
3657 ms = mdt_md_site(m);
3660 * This is sequence-controller node. Init seq-controller server on local
3663 if (ms->ms_node_id == 0) {
3664 LASSERT(ms->ms_control_seq == NULL);
3666 OBD_ALLOC_PTR(ms->ms_control_seq);
3667 if (ms->ms_control_seq == NULL)
3670 rc = seq_server_init(ms->ms_control_seq,
3671 m->mdt_bottom, uuid,
3672 LUSTRE_SEQ_CONTROLLER,
3677 GOTO(out_seq_fini, rc);
3679 OBD_ALLOC_PTR(ms->ms_client_seq);
3680 if (ms->ms_client_seq == NULL)
3681 GOTO(out_seq_fini, rc = -ENOMEM);
3683 OBD_ALLOC(prefix, MAX_OBD_NAME + 5);
3684 if (prefix == NULL) {
3685 OBD_FREE_PTR(ms->ms_client_seq);
3686 GOTO(out_seq_fini, rc = -ENOMEM);
3689 snprintf(prefix, MAX_OBD_NAME + 5, "ctl-%s",
3693 * Init seq-controller client after seq-controller server is
3694 * ready. Pass ms->ms_control_seq to it for direct talking.
3696 rc = seq_client_init(ms->ms_client_seq, NULL,
3697 LUSTRE_SEQ_METADATA, prefix,
3698 ms->ms_control_seq);
3699 OBD_FREE(prefix, MAX_OBD_NAME + 5);
3702 GOTO(out_seq_fini, rc);
3705 /* Init seq-server on local MDT */
3706 LASSERT(ms->ms_server_seq == NULL);
3708 OBD_ALLOC_PTR(ms->ms_server_seq);
3709 if (ms->ms_server_seq == NULL)
3710 GOTO(out_seq_fini, rc = -ENOMEM);
3712 rc = seq_server_init(ms->ms_server_seq,
3713 m->mdt_bottom, uuid,
3718 GOTO(out_seq_fini, rc = -ENOMEM);
3720 /* Assign seq-controller client to local seq-server. */
3721 if (ms->ms_node_id == 0) {
3722 LASSERT(ms->ms_client_seq != NULL);
3724 rc = seq_server_set_cli(ms->ms_server_seq,
3732 mdt_seq_fini(env, m);
3737 * Init client sequence manager which is used by local MDS to talk to sequence
3738 * controller on remote node.
3740 static int mdt_seq_init_cli(const struct lu_env *env,
3741 struct mdt_device *m,
3742 struct lustre_cfg *cfg)
3744 struct md_site *ms = mdt_md_site(m);
3745 struct obd_device *mdc;
3746 struct obd_uuid *uuidp, *mdcuuidp;
3747 char *uuid_str, *mdc_uuid_str;
3750 struct mdt_thread_info *info;
3751 char *p, *index_string = lustre_cfg_string(cfg, 2);
3754 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
3755 uuidp = &info->mti_u.uuid[0];
3756 mdcuuidp = &info->mti_u.uuid[1];
3758 LASSERT(index_string);
3760 index = simple_strtol(index_string, &p, 10);
3762 CERROR("Invalid index in lustre_cgf, offset 2\n");
3766 /* check if this is adding the first MDC and controller is not yet
3768 if (index != 0 || ms->ms_client_seq)
3771 uuid_str = lustre_cfg_string(cfg, 1);
3772 mdc_uuid_str = lustre_cfg_string(cfg, 4);
3773 obd_str2uuid(uuidp, uuid_str);
3774 obd_str2uuid(mdcuuidp, mdc_uuid_str);
3776 mdc = class_find_client_obd(uuidp, LUSTRE_MDC_NAME, mdcuuidp);
3778 CERROR("can't find controller MDC by uuid %s\n",
3781 } else if (!mdc->obd_set_up) {
3782 CERROR("target %s not set up\n", mdc->obd_name);
3785 LASSERT(ms->ms_control_exp);
3786 OBD_ALLOC_PTR(ms->ms_client_seq);
3787 if (ms->ms_client_seq != NULL) {
3790 OBD_ALLOC(prefix, MAX_OBD_NAME + 5);
3794 snprintf(prefix, MAX_OBD_NAME + 5, "ctl-%s",
3797 rc = seq_client_init(ms->ms_client_seq,
3799 LUSTRE_SEQ_METADATA,
3801 OBD_FREE(prefix, MAX_OBD_NAME + 5);
3808 LASSERT(ms->ms_server_seq != NULL);
3809 rc = seq_server_set_cli(ms->ms_server_seq, ms->ms_client_seq,
3816 static void mdt_seq_fini_cli(struct mdt_device *m)
3822 ms = mdt_md_site(m);
3825 if (ms->ms_server_seq)
3826 seq_server_set_cli(ms->ms_server_seq,
3829 if (ms->ms_control_exp) {
3830 class_export_put(ms->ms_control_exp);
3831 ms->ms_control_exp = NULL;
3840 static int mdt_fld_fini(const struct lu_env *env,
3841 struct mdt_device *m)
3843 struct md_site *ms = mdt_md_site(m);
3846 if (ms && ms->ms_server_fld) {
3847 fld_server_fini(ms->ms_server_fld, env);
3848 OBD_FREE_PTR(ms->ms_server_fld);
3849 ms->ms_server_fld = NULL;
3855 static int mdt_fld_init(const struct lu_env *env,
3857 struct mdt_device *m)
3863 ms = mdt_md_site(m);
3865 OBD_ALLOC_PTR(ms->ms_server_fld);
3866 if (ms->ms_server_fld == NULL)
3867 RETURN(rc = -ENOMEM);
3869 rc = fld_server_init(ms->ms_server_fld,
3870 m->mdt_bottom, uuid,
3871 env, ms->ms_node_id);
3873 OBD_FREE_PTR(ms->ms_server_fld);
3874 ms->ms_server_fld = NULL;
3881 /* device init/fini methods */
3882 static void mdt_stop_ptlrpc_service(struct mdt_device *m)
3885 if (m->mdt_regular_service != NULL) {
3886 ptlrpc_unregister_service(m->mdt_regular_service);
3887 m->mdt_regular_service = NULL;
3889 if (m->mdt_readpage_service != NULL) {
3890 ptlrpc_unregister_service(m->mdt_readpage_service);
3891 m->mdt_readpage_service = NULL;
3893 if (m->mdt_xmds_service != NULL) {
3894 ptlrpc_unregister_service(m->mdt_xmds_service);
3895 m->mdt_xmds_service = NULL;
3897 if (m->mdt_setattr_service != NULL) {
3898 ptlrpc_unregister_service(m->mdt_setattr_service);
3899 m->mdt_setattr_service = NULL;
3901 if (m->mdt_mdsc_service != NULL) {
3902 ptlrpc_unregister_service(m->mdt_mdsc_service);
3903 m->mdt_mdsc_service = NULL;
3905 if (m->mdt_mdss_service != NULL) {
3906 ptlrpc_unregister_service(m->mdt_mdss_service);
3907 m->mdt_mdss_service = NULL;
3909 if (m->mdt_dtss_service != NULL) {
3910 ptlrpc_unregister_service(m->mdt_dtss_service);
3911 m->mdt_dtss_service = NULL;
3913 if (m->mdt_fld_service != NULL) {
3914 ptlrpc_unregister_service(m->mdt_fld_service);
3915 m->mdt_fld_service = NULL;
3920 static int mdt_start_ptlrpc_service(struct mdt_device *m)
3922 static struct ptlrpc_service_conf conf;
3923 cfs_proc_dir_entry_t *procfs_entry;
3927 m->mdt_ldlm_client = &m->mdt_md_dev.md_lu_dev.ld_obd->obd_ldlm_client;
3928 ptlrpc_init_client(LDLM_CB_REQUEST_PORTAL, LDLM_CB_REPLY_PORTAL,
3929 "mdt_ldlm_client", m->mdt_ldlm_client);
3931 procfs_entry = m->mdt_md_dev.md_lu_dev.ld_obd->obd_proc_entry;
3933 conf = (typeof(conf)) {
3934 .psc_name = LUSTRE_MDT_NAME,
3935 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
3937 .bc_nbufs = MDS_NBUFS,
3938 .bc_buf_size = MDS_BUFSIZE,
3939 .bc_req_max_size = MDS_MAXREQSIZE,
3940 .bc_rep_max_size = MDS_MAXREPSIZE,
3941 .bc_req_portal = MDS_REQUEST_PORTAL,
3942 .bc_rep_portal = MDC_REPLY_PORTAL,
3945 * We'd like to have a mechanism to set this on a per-device
3946 * basis, but alas...
3949 .tc_thr_name = LUSTRE_MDT_NAME,
3950 .tc_nthrs_min = MDT_MIN_THREADS,
3951 .tc_nthrs_max = MDT_MAX_THREADS,
3952 .tc_nthrs_user = mdt_num_threads,
3953 .tc_ctx_tags = LCT_MD_THREAD,
3956 .so_req_handler = mdt_regular_handle,
3957 .so_req_printer = target_print_req,
3960 m->mdt_regular_service = ptlrpc_register_service(&conf, procfs_entry);
3961 if (IS_ERR(m->mdt_regular_service)) {
3962 rc = PTR_ERR(m->mdt_regular_service);
3963 CERROR("failed to start regular mdt service: %d\n", rc);
3964 m->mdt_regular_service = NULL;
3970 * readpage service configuration. Parameters have to be adjusted,
3973 memset(&conf, 0, sizeof(conf));
3974 conf = (typeof(conf)) {
3975 .psc_name = LUSTRE_MDT_NAME "_readpage",
3976 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
3978 .bc_nbufs = MDS_NBUFS,
3979 .bc_buf_size = MDS_BUFSIZE,
3980 .bc_req_max_size = MDS_MAXREQSIZE,
3981 .bc_rep_max_size = MDS_MAXREPSIZE,
3982 .bc_req_portal = MDS_READPAGE_PORTAL,
3983 .bc_rep_portal = MDC_REPLY_PORTAL,
3986 .tc_thr_name = "mdt_rdpg",
3987 .tc_nthrs_min = MDT_MIN_THREADS,
3988 .tc_nthrs_max = MDT_MAX_THREADS,
3989 .tc_nthrs_user = mdt_num_threads,
3990 .tc_ctx_tags = LCT_MD_THREAD,
3993 .so_req_handler = mdt_readpage_handle,
3994 .so_req_printer = target_print_req,
3997 m->mdt_readpage_service = ptlrpc_register_service(&conf, procfs_entry);
3998 if (IS_ERR(m->mdt_readpage_service)) {
3999 rc = PTR_ERR(m->mdt_readpage_service);
4000 CERROR("failed to start readpage service: %d\n", rc);
4001 m->mdt_readpage_service = NULL;
4003 GOTO(err_mdt_svc, rc);
4007 * setattr service configuration.
4009 * XXX To keep the compatibility with old client(< 2.2), we need to
4010 * preserve this portal for a certain time, it should be removed
4011 * eventually. LU-617.
4013 memset(&conf, 0, sizeof(conf));
4014 conf = (typeof(conf)) {
4015 .psc_name = LUSTRE_MDT_NAME "_setattr",
4016 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
4018 .bc_nbufs = MDS_NBUFS,
4019 .bc_buf_size = MDS_BUFSIZE,
4020 .bc_req_max_size = MDS_MAXREQSIZE,
4021 .bc_rep_max_size = MDS_MAXREPSIZE,
4022 .bc_req_portal = MDS_SETATTR_PORTAL,
4023 .bc_rep_portal = MDC_REPLY_PORTAL,
4026 .tc_thr_name = "mdt_attr",
4027 .tc_nthrs_min = MDT_MIN_THREADS,
4028 .tc_nthrs_max = MDT_MAX_THREADS,
4029 .tc_nthrs_user = mdt_num_threads,
4030 .tc_ctx_tags = LCT_MD_THREAD,
4033 .so_req_handler = mdt_regular_handle,
4034 .so_req_printer = target_print_req,
4037 m->mdt_setattr_service = ptlrpc_register_service(&conf, procfs_entry);
4038 if (IS_ERR(m->mdt_setattr_service)) {
4039 rc = PTR_ERR(m->mdt_setattr_service);
4040 CERROR("failed to start setattr service: %d\n", rc);
4041 m->mdt_setattr_service = NULL;
4043 GOTO(err_mdt_svc, rc);
4047 * sequence controller service configuration
4049 memset(&conf, 0, sizeof(conf));
4050 conf = (typeof(conf)) {
4051 .psc_name = LUSTRE_MDT_NAME "_mdsc",
4052 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
4054 .bc_nbufs = MDS_NBUFS,
4055 .bc_buf_size = MDS_BUFSIZE,
4056 .bc_req_max_size = SEQ_MAXREQSIZE,
4057 .bc_rep_max_size = SEQ_MAXREPSIZE,
4058 .bc_req_portal = SEQ_CONTROLLER_PORTAL,
4059 .bc_rep_portal = MDC_REPLY_PORTAL,
4062 .tc_thr_name = "mdt_mdsc",
4063 .tc_nthrs_min = MDT_MIN_THREADS,
4064 .tc_nthrs_max = MDT_MAX_THREADS,
4065 .tc_nthrs_user = mdt_num_threads,
4066 .tc_ctx_tags = LCT_MD_THREAD,
4069 .so_req_handler = mdt_mdsc_handle,
4070 .so_req_printer = target_print_req,
4073 m->mdt_mdsc_service = ptlrpc_register_service(&conf, procfs_entry);
4074 if (IS_ERR(m->mdt_mdsc_service)) {
4075 rc = PTR_ERR(m->mdt_mdsc_service);
4076 CERROR("failed to start seq controller service: %d\n", rc);
4077 m->mdt_mdsc_service = NULL;
4079 GOTO(err_mdt_svc, rc);
4083 * metadata sequence server service configuration
4085 memset(&conf, 0, sizeof(conf));
4086 conf = (typeof(conf)) {
4087 .psc_name = LUSTRE_MDT_NAME "_mdss",
4088 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
4090 .bc_nbufs = MDS_NBUFS,
4091 .bc_buf_size = MDS_BUFSIZE,
4092 .bc_req_max_size = SEQ_MAXREQSIZE,
4093 .bc_rep_max_size = SEQ_MAXREPSIZE,
4094 .bc_req_portal = SEQ_METADATA_PORTAL,
4095 .bc_rep_portal = MDC_REPLY_PORTAL,
4098 .tc_thr_name = "mdt_mdss",
4099 .tc_nthrs_min = MDT_MIN_THREADS,
4100 .tc_nthrs_max = MDT_MAX_THREADS,
4101 .tc_nthrs_user = mdt_num_threads,
4102 .tc_ctx_tags = LCT_MD_THREAD | LCT_DT_THREAD
4105 .so_req_handler = mdt_mdss_handle,
4106 .so_req_printer = target_print_req,
4109 m->mdt_mdss_service = ptlrpc_register_service(&conf, procfs_entry);
4110 if (IS_ERR(m->mdt_mdss_service)) {
4111 rc = PTR_ERR(m->mdt_mdss_service);
4112 CERROR("failed to start metadata seq server service: %d\n", rc);
4113 m->mdt_mdss_service = NULL;
4115 GOTO(err_mdt_svc, rc);
4119 * Data sequence server service configuration. We want to have really
4120 * cluster-wide sequences space. This is why we start only one sequence
4121 * controller which manages space.
4123 memset(&conf, 0, sizeof(conf));
4124 conf = (typeof(conf)) {
4125 .psc_name = LUSTRE_MDT_NAME "_dtss",
4126 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
4128 .bc_nbufs = MDS_NBUFS,
4129 .bc_buf_size = MDS_BUFSIZE,
4130 .bc_req_max_size = SEQ_MAXREQSIZE,
4131 .bc_rep_max_size = SEQ_MAXREPSIZE,
4132 .bc_req_portal = SEQ_DATA_PORTAL,
4133 .bc_rep_portal = OSC_REPLY_PORTAL,
4136 .tc_thr_name = "mdt_dtss",
4137 .tc_nthrs_min = MDT_MIN_THREADS,
4138 .tc_nthrs_max = MDT_MAX_THREADS,
4139 .tc_nthrs_user = mdt_num_threads,
4140 .tc_ctx_tags = LCT_MD_THREAD | LCT_DT_THREAD
4143 .so_req_handler = mdt_dtss_handle,
4144 .so_req_printer = target_print_req,
4147 m->mdt_dtss_service = ptlrpc_register_service(&conf, procfs_entry);
4148 if (IS_ERR(m->mdt_dtss_service)) {
4149 rc = PTR_ERR(m->mdt_dtss_service);
4150 CERROR("failed to start data seq server service: %d\n", rc);
4151 m->mdt_dtss_service = NULL;
4153 GOTO(err_mdt_svc, rc);
4156 /* FLD service start */
4157 memset(&conf, 0, sizeof(conf));
4158 conf = (typeof(conf)) {
4159 .psc_name = LUSTRE_MDT_NAME "_fld",
4160 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
4162 .bc_nbufs = MDS_NBUFS,
4163 .bc_buf_size = MDS_BUFSIZE,
4164 .bc_req_max_size = FLD_MAXREQSIZE,
4165 .bc_rep_max_size = FLD_MAXREPSIZE,
4166 .bc_req_portal = FLD_REQUEST_PORTAL,
4167 .bc_rep_portal = MDC_REPLY_PORTAL,
4170 .tc_thr_name = "mdt_fld",
4171 .tc_nthrs_min = MDT_MIN_THREADS,
4172 .tc_nthrs_max = MDT_MAX_THREADS,
4173 .tc_nthrs_user = mdt_num_threads,
4174 .tc_ctx_tags = LCT_DT_THREAD | LCT_MD_THREAD
4177 .so_req_handler = mdt_fld_handle,
4178 .so_req_printer = target_print_req,
4181 m->mdt_fld_service = ptlrpc_register_service(&conf, procfs_entry);
4182 if (IS_ERR(m->mdt_fld_service)) {
4183 rc = PTR_ERR(m->mdt_fld_service);
4184 CERROR("failed to start fld service: %d\n", rc);
4185 m->mdt_fld_service = NULL;
4187 GOTO(err_mdt_svc, rc);
4191 * mds-mds service configuration. Separate portal is used to allow
4192 * mds-mds requests be not blocked during recovery.
4194 memset(&conf, 0, sizeof(conf));
4195 conf = (typeof(conf)) {
4196 .psc_name = LUSTRE_MDT_NAME "_mds",
4197 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
4199 .bc_nbufs = MDS_NBUFS,
4200 .bc_buf_size = MDS_BUFSIZE,
4201 .bc_req_max_size = MDS_MAXREQSIZE,
4202 .bc_rep_max_size = MDS_MAXREPSIZE,
4203 .bc_req_portal = MDS_MDS_PORTAL,
4204 .bc_rep_portal = MDC_REPLY_PORTAL,
4207 .tc_thr_name = "mdt_mds",
4208 .tc_nthrs_min = MDT_MIN_THREADS,
4209 .tc_nthrs_max = MDT_MAX_THREADS,
4210 .tc_nthrs_user = mdt_num_threads,
4211 .tc_ctx_tags = LCT_MD_THREAD,
4214 .so_req_handler = mdt_xmds_handle,
4215 .so_req_printer = target_print_req,
4218 m->mdt_xmds_service = ptlrpc_register_service(&conf, procfs_entry);
4219 if (IS_ERR(m->mdt_xmds_service)) {
4220 rc = PTR_ERR(m->mdt_xmds_service);
4221 CERROR("failed to start xmds service: %d\n", rc);
4222 m->mdt_xmds_service = NULL;
4224 GOTO(err_mdt_svc, rc);
4230 mdt_stop_ptlrpc_service(m);
4235 static void mdt_stack_fini(const struct lu_env *env,
4236 struct mdt_device *m, struct lu_device *top)
4238 struct obd_device *obd = mdt2obd_dev(m);
4239 struct lustre_cfg_bufs *bufs;
4240 struct lustre_cfg *lcfg;
4241 struct mdt_thread_info *info;
4245 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
4246 LASSERT(info != NULL);
4248 bufs = &info->mti_u.bufs;
4249 /* process cleanup, pass mdt obd name to get obd umount flags */
4250 lustre_cfg_bufs_reset(bufs, obd->obd_name);
4255 lustre_cfg_bufs_set_string(bufs, 1, flags);
4256 lcfg = lustre_cfg_new(LCFG_CLEANUP, bufs);
4258 CERROR("Cannot alloc lcfg!\n");
4263 top->ld_ops->ldo_process_config(env, top, lcfg);
4264 lustre_cfg_free(lcfg);
4266 lu_stack_fini(env, top);
4267 m->mdt_child = NULL;
4268 m->mdt_bottom = NULL;
4271 static struct lu_device *mdt_layer_setup(struct lu_env *env,
4272 const char *typename,
4273 struct lu_device *child,
4274 struct lustre_cfg *cfg)
4276 const char *dev = lustre_cfg_string(cfg, 0);
4277 struct obd_type *type;
4278 struct lu_device_type *ldt;
4279 struct lu_device *d;
4284 type = class_get_type(typename);
4286 CERROR("Unknown type: '%s'\n", typename);
4287 GOTO(out, rc = -ENODEV);
4290 rc = lu_env_refill((struct lu_env *)env);
4292 CERROR("Failure to refill session: '%d'\n", rc);
4298 CERROR("type: '%s'\n", typename);
4299 GOTO(out_type, rc = -EINVAL);
4302 ldt->ldt_obd_type = type;
4303 d = ldt->ldt_ops->ldto_device_alloc(env, ldt, cfg);
4305 CERROR("Cannot allocate device: '%s'\n", typename);
4306 GOTO(out_type, rc = -ENODEV);
4309 LASSERT(child->ld_site);
4310 d->ld_site = child->ld_site;
4313 rc = ldt->ldt_ops->ldto_device_init(env, d, dev, child);
4315 CERROR("can't init device '%s', rc %d\n", typename, rc);
4316 GOTO(out_alloc, rc);
4319 lu_ref_add(&d->ld_reference, "lu-stack", &lu_site_init);
4321 cfs_spin_lock(&d->ld_site->ls_ld_lock);
4322 cfs_list_add_tail(&d->ld_linkage, &d->ld_site->ls_ld_linkage);
4323 cfs_spin_unlock(&d->ld_site->ls_ld_lock);
4327 ldt->ldt_ops->ldto_device_free(env, d);
4330 class_put_type(type);
4335 static int mdt_stack_init(struct lu_env *env,
4336 struct mdt_device *m,
4337 struct lustre_cfg *cfg,
4338 struct lustre_mount_info *lmi)
4340 struct lu_device *d = &m->mdt_md_dev.md_lu_dev;
4341 struct lu_device *tmp;
4342 struct md_device *md;
4343 struct lu_device *child_lu_dev;
4347 /* init the stack */
4348 tmp = mdt_layer_setup(env, LUSTRE_OSD_NAME, d, cfg);
4350 RETURN(PTR_ERR(tmp));
4352 m->mdt_bottom = lu2dt_dev(tmp);
4354 tmp = mdt_layer_setup(env, LUSTRE_MDD_NAME, d, cfg);
4356 GOTO(out, rc = PTR_ERR(tmp));
4361 tmp = mdt_layer_setup(env, LUSTRE_CMM_NAME, d, cfg);
4363 GOTO(out, rc = PTR_ERR(tmp));
4366 /*set mdd upcall device*/
4367 md_upcall_dev_set(md, lu2md_dev(d));
4370 /*set cmm upcall device*/
4371 md_upcall_dev_set(md, &m->mdt_md_dev);
4373 m->mdt_child = lu2md_dev(d);
4375 /* process setup config */
4376 tmp = &m->mdt_md_dev.md_lu_dev;
4377 rc = tmp->ld_ops->ldo_process_config(env, tmp, cfg);
4381 /* initialize local objects */
4382 child_lu_dev = &m->mdt_child->md_lu_dev;
4384 rc = child_lu_dev->ld_ops->ldo_prepare(env,
4385 &m->mdt_md_dev.md_lu_dev,
4388 /* fini from last known good lu_device */
4390 mdt_stack_fini(env, m, d);
4396 * setup CONFIG_ORIG context, used to access local config log.
4397 * this may need to be rewrite as part of llog rewrite for lu-api.
4399 static int mdt_obd_llog_setup(struct obd_device *obd,
4400 struct lustre_sb_info *lsi)
4404 LASSERT(obd->obd_fsops == NULL);
4406 obd->obd_fsops = fsfilt_get_ops(MT_STR(lsi->lsi_ldd));
4407 if (IS_ERR(obd->obd_fsops))
4408 return PTR_ERR(obd->obd_fsops);
4410 rc = fsfilt_setup(obd, lsi->lsi_srv_mnt->mnt_sb);
4412 fsfilt_put_ops(obd->obd_fsops);
4416 OBD_SET_CTXT_MAGIC(&obd->obd_lvfs_ctxt);
4417 obd->obd_lvfs_ctxt.pwdmnt = lsi->lsi_srv_mnt;
4418 obd->obd_lvfs_ctxt.pwd = lsi->lsi_srv_mnt->mnt_root;
4419 obd->obd_lvfs_ctxt.fs = get_ds();
4421 rc = llog_setup(obd, &obd->obd_olg, LLOG_CONFIG_ORIG_CTXT, obd,
4422 0, NULL, &llog_lvfs_ops);
4424 CERROR("llog_setup() failed: %d\n", rc);
4425 fsfilt_put_ops(obd->obd_fsops);
4431 static void mdt_obd_llog_cleanup(struct obd_device *obd)
4433 struct llog_ctxt *ctxt;
4435 ctxt = llog_get_context(obd, LLOG_CONFIG_ORIG_CTXT);
4439 if (obd->obd_fsops) {
4440 fsfilt_put_ops(obd->obd_fsops);
4441 obd->obd_fsops = NULL;
4445 static void mdt_fini(const struct lu_env *env, struct mdt_device *m)
4447 struct md_device *next = m->mdt_child;
4448 struct lu_device *d = &m->mdt_md_dev.md_lu_dev;
4449 struct lu_site *ls = d->ld_site;
4450 struct obd_device *obd = mdt2obd_dev(m);
4453 target_recovery_fini(obd);
4455 ping_evictor_stop();
4457 mdt_stop_ptlrpc_service(m);
4458 mdt_llog_ctxt_unclone(env, m, LLOG_CHANGELOG_ORIG_CTXT);
4459 mdt_obd_llog_cleanup(obd);
4460 obd_exports_barrier(obd);
4461 obd_zombie_barrier();
4465 #ifdef HAVE_QUOTA_SUPPORT
4466 next->md_ops->mdo_quota.mqo_cleanup(env, next);
4468 lut_fini(env, &m->mdt_lut);
4469 mdt_fs_cleanup(env, m);
4470 upcall_cache_cleanup(m->mdt_identity_cache);
4471 m->mdt_identity_cache = NULL;
4473 if (m->mdt_namespace != NULL) {
4474 ldlm_namespace_free(m->mdt_namespace, NULL,
4475 d->ld_obd->obd_force);
4476 d->ld_obd->obd_namespace = m->mdt_namespace = NULL;
4479 cfs_free_nidlist(&m->mdt_nosquash_nids);
4480 if (m->mdt_nosquash_str) {
4481 OBD_FREE(m->mdt_nosquash_str, m->mdt_nosquash_strlen);
4482 m->mdt_nosquash_str = NULL;
4483 m->mdt_nosquash_strlen = 0;
4486 mdt_seq_fini(env, m);
4487 mdt_seq_fini_cli(m);
4488 mdt_fld_fini(env, m);
4489 sptlrpc_rule_set_free(&m->mdt_sptlrpc_rset);
4491 next->md_ops->mdo_init_capa_ctxt(env, next, 0, 0, 0, NULL);
4492 cfs_timer_disarm(&m->mdt_ck_timer);
4493 mdt_ck_thread_stop(m);
4498 mdt_stack_fini(env, m, md2lu_dev(m->mdt_child));
4501 struct md_site *mite;
4504 mite = lu_site2md(ls);
4508 LASSERT(cfs_atomic_read(&d->ld_ref) == 0);
4513 static int mdt_adapt_sptlrpc_conf(struct obd_device *obd, int initial)
4515 struct mdt_device *m = mdt_dev(obd->obd_lu_dev);
4516 struct sptlrpc_rule_set tmp_rset;
4519 sptlrpc_rule_set_init(&tmp_rset);
4520 rc = sptlrpc_conf_target_get_rules(obd, &tmp_rset, initial);
4522 CERROR("mdt %s: failed get sptlrpc rules: %d\n",
4527 sptlrpc_target_update_exp_flavor(obd, &tmp_rset);
4529 cfs_write_lock(&m->mdt_sptlrpc_lock);
4530 sptlrpc_rule_set_free(&m->mdt_sptlrpc_rset);
4531 m->mdt_sptlrpc_rset = tmp_rset;
4532 cfs_write_unlock(&m->mdt_sptlrpc_lock);
4537 int mdt_postrecov(const struct lu_env *, struct mdt_device *);
4539 static int mdt_init0(const struct lu_env *env, struct mdt_device *m,
4540 struct lu_device_type *ldt, struct lustre_cfg *cfg)
4542 struct mdt_thread_info *info;
4543 struct obd_device *obd;
4544 const char *dev = lustre_cfg_string(cfg, 0);
4545 const char *num = lustre_cfg_string(cfg, 2);
4546 struct lustre_mount_info *lmi = NULL;
4547 struct lustre_sb_info *lsi;
4548 struct lustre_disk_data *ldd;
4550 struct md_site *mite;
4551 const char *identity_upcall = "NONE";
4552 struct md_device *next;
4558 md_device_init(&m->mdt_md_dev, ldt);
4560 * Environment (env) might be missing mdt_thread_key values at that
4561 * point, if device is allocated when mdt_thread_key is in QUIESCENT
4564 * Usually device allocation path doesn't use module key values, but
4565 * mdt has to do a lot of work here, so allocate key value.
4567 rc = lu_env_refill((struct lu_env *)env);
4571 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
4572 LASSERT(info != NULL);
4574 obd = class_name2obd(dev);
4575 LASSERT(obd != NULL);
4577 m->mdt_max_mdsize = MAX_MD_SIZE; /* 4 stripes */
4578 m->mdt_max_cookiesize = sizeof(struct llog_cookie);
4580 m->mdt_som_conf = 0;
4582 m->mdt_opts.mo_cos = MDT_COS_DEFAULT;
4583 lmi = server_get_mount_2(dev);
4585 CERROR("Cannot get mount info for %s!\n", dev);
4588 lsi = s2lsi(lmi->lmi_sb);
4589 /* CMD is supported only in IAM mode */
4592 node_id = simple_strtol(num, NULL, 10);
4593 if (!(ldd->ldd_flags & LDD_F_IAM_DIR) && node_id) {
4594 CERROR("CMD Operation not allowed in IOP mode\n");
4595 GOTO(err_lmi, rc = -EINVAL);
4598 obd->u.obt.obt_magic = OBT_MAGIC;
4601 cfs_rwlock_init(&m->mdt_sptlrpc_lock);
4602 sptlrpc_rule_set_init(&m->mdt_sptlrpc_rset);
4604 cfs_spin_lock_init(&m->mdt_ioepoch_lock);
4605 m->mdt_opts.mo_compat_resname = 0;
4606 m->mdt_opts.mo_mds_capa = 1;
4607 m->mdt_opts.mo_oss_capa = 1;
4608 m->mdt_capa_timeout = CAPA_TIMEOUT;
4609 m->mdt_capa_alg = CAPA_HMAC_ALG_SHA1;
4610 m->mdt_ck_timeout = CAPA_KEY_TIMEOUT;
4611 m->mdt_squash_uid = 0;
4612 m->mdt_squash_gid = 0;
4613 CFS_INIT_LIST_HEAD(&m->mdt_nosquash_nids);
4614 m->mdt_nosquash_str = NULL;
4615 m->mdt_nosquash_strlen = 0;
4616 cfs_init_rwsem(&m->mdt_squash_sem);
4618 OBD_ALLOC_PTR(mite);
4620 GOTO(err_lmi, rc = -ENOMEM);
4624 m->mdt_md_dev.md_lu_dev.ld_ops = &mdt_lu_ops;
4625 m->mdt_md_dev.md_lu_dev.ld_obd = obd;
4626 /* set this lu_device to obd, because error handling need it */
4627 obd->obd_lu_dev = &m->mdt_md_dev.md_lu_dev;
4629 rc = lu_site_init(s, &m->mdt_md_dev.md_lu_dev);
4631 CERROR("Can't init lu_site, rc %d\n", rc);
4632 GOTO(err_free_site, rc);
4635 /* set server index */
4636 lu_site2md(s)->ms_node_id = node_id;
4638 /* failover is the default
4639 * FIXME: we do not failout mds0/mgs, which may cause some problems.
4640 * assumed whose ms_node_id == 0 XXX
4642 obd->obd_replayable = 1;
4643 /* No connection accepted until configurations will finish */
4644 obd->obd_no_conn = 1;
4646 if (cfg->lcfg_bufcount > 4 && LUSTRE_CFG_BUFLEN(cfg, 4) > 0) {
4647 char *str = lustre_cfg_string(cfg, 4);
4648 if (strchr(str, 'n')) {
4649 CWARN("%s: recovery disabled\n", obd->obd_name);
4650 obd->obd_replayable = 0;
4654 /* init the stack */
4655 rc = mdt_stack_init((struct lu_env *)env, m, cfg, lmi);
4657 CERROR("Can't init device stack, rc %d\n", rc);
4658 GOTO(err_lu_site, rc);
4661 rc = lut_init(env, &m->mdt_lut, obd, m->mdt_bottom);
4663 GOTO(err_fini_stack, rc);
4665 rc = mdt_fld_init(env, obd->obd_name, m);
4669 rc = mdt_seq_init(env, obd->obd_name, m);
4671 GOTO(err_fini_fld, rc);
4673 snprintf(info->mti_u.ns_name, sizeof info->mti_u.ns_name,
4674 LUSTRE_MDT_NAME"-%p", m);
4675 m->mdt_namespace = ldlm_namespace_new(obd, info->mti_u.ns_name,
4676 LDLM_NAMESPACE_SERVER,
4677 LDLM_NAMESPACE_GREEDY,
4679 if (m->mdt_namespace == NULL)
4680 GOTO(err_fini_seq, rc = -ENOMEM);
4682 ldlm_register_intent(m->mdt_namespace, mdt_intent_policy);
4683 /* set obd_namespace for compatibility with old code */
4684 obd->obd_namespace = m->mdt_namespace;
4686 cfs_timer_init(&m->mdt_ck_timer, mdt_ck_timer_callback, m);
4688 rc = mdt_ck_thread_start(m);
4690 GOTO(err_free_ns, rc);
4692 rc = mdt_fs_setup(env, m, obd, lsi);
4696 rc = mdt_obd_llog_setup(obd, lsi);
4698 GOTO(err_fs_cleanup, rc);
4700 rc = mdt_llog_ctxt_clone(env, m, LLOG_CHANGELOG_ORIG_CTXT);
4702 GOTO(err_llog_cleanup, rc);
4704 mdt_adapt_sptlrpc_conf(obd, 1);
4706 next = m->mdt_child;
4707 #ifdef HAVE_QUOTA_SUPPORT
4708 rc = next->md_ops->mdo_quota.mqo_setup(env, next, lmi->lmi_mnt);
4710 GOTO(err_llog_cleanup, rc);
4713 server_put_mount_2(dev, lmi->lmi_mnt);
4716 rc = next->md_ops->mdo_iocontrol(env, next, OBD_IOC_GET_MNTOPT, 0,
4719 GOTO(err_quota, rc);
4721 if (mntopts & MNTOPT_USERXATTR)
4722 m->mdt_opts.mo_user_xattr = 1;
4724 m->mdt_opts.mo_user_xattr = 0;
4726 if (mntopts & MNTOPT_ACL)
4727 m->mdt_opts.mo_acl = 1;
4729 m->mdt_opts.mo_acl = 0;
4731 /* XXX: to support suppgid for ACL, we enable identity_upcall
4732 * by default, otherwise, maybe got unexpected -EACCESS. */
4733 if (m->mdt_opts.mo_acl)
4734 identity_upcall = MDT_IDENTITY_UPCALL_PATH;
4736 m->mdt_identity_cache = upcall_cache_init(obd->obd_name,identity_upcall,
4737 &mdt_identity_upcall_cache_ops);
4738 if (IS_ERR(m->mdt_identity_cache)) {
4739 rc = PTR_ERR(m->mdt_identity_cache);
4740 m->mdt_identity_cache = NULL;
4741 GOTO(err_quota, rc);
4744 target_recovery_init(&m->mdt_lut, mdt_recovery_handle);
4746 rc = mdt_procfs_init(m, dev);
4748 CERROR("Can't init MDT lprocfs, rc %d\n", rc);
4749 GOTO(err_recovery, rc);
4752 rc = mdt_start_ptlrpc_service(m);
4754 GOTO(err_procfs, rc);
4756 ping_evictor_start();
4758 rc = lu_site_init_finish(s);
4760 GOTO(err_stop_service, rc);
4762 if (obd->obd_recovering == 0)
4763 mdt_postrecov(env, m);
4765 mdt_init_capa_ctxt(env, m);
4767 /* Reduce the initial timeout on an MDS because it doesn't need such
4768 * a long timeout as an OST does. Adaptive timeouts will adjust this
4769 * value appropriately. */
4770 if (ldlm_timeout == LDLM_TIMEOUT_DEFAULT)
4771 ldlm_timeout = MDS_LDLM_TIMEOUT_DEFAULT;
4776 ping_evictor_stop();
4777 mdt_stop_ptlrpc_service(m);
4781 target_recovery_fini(obd);
4782 upcall_cache_cleanup(m->mdt_identity_cache);
4783 m->mdt_identity_cache = NULL;
4785 #ifdef HAVE_QUOTA_SUPPORT
4786 next->md_ops->mdo_quota.mqo_cleanup(env, next);
4789 mdt_llog_ctxt_unclone(env, m, LLOG_CHANGELOG_ORIG_CTXT);
4790 mdt_obd_llog_cleanup(obd);
4792 mdt_fs_cleanup(env, m);
4794 cfs_timer_disarm(&m->mdt_ck_timer);
4795 mdt_ck_thread_stop(m);
4797 ldlm_namespace_free(m->mdt_namespace, NULL, 0);
4798 obd->obd_namespace = m->mdt_namespace = NULL;
4800 mdt_seq_fini(env, m);
4802 mdt_fld_fini(env, m);
4804 lut_fini(env, &m->mdt_lut);
4806 mdt_stack_fini(env, m, md2lu_dev(m->mdt_child));
4813 server_put_mount_2(dev, lmi->lmi_mnt);
4817 /* used by MGS to process specific configurations */
4818 static int mdt_process_config(const struct lu_env *env,
4819 struct lu_device *d, struct lustre_cfg *cfg)
4821 struct mdt_device *m = mdt_dev(d);
4822 struct md_device *md_next = m->mdt_child;
4823 struct lu_device *next = md2lu_dev(md_next);
4827 switch (cfg->lcfg_command) {
4829 struct lprocfs_static_vars lvars;
4830 struct obd_device *obd = d->ld_obd;
4833 * For interoperability between 1.8 and 2.0,
4836 /* Skip old "mdt.group_upcall" param. */
4837 char *param = lustre_cfg_string(cfg, 1);
4838 if (param && !strncmp("mdt.group_upcall", param, 16)) {
4839 CWARN("For 1.8 interoperability, skip this"
4840 " mdt.group_upcall. It is obsolete\n");
4843 /* Rename old "mdt.quota_type" to "mdd.quota_type. */
4844 if (param && !strncmp("mdt.quota_type", param, 14)) {
4845 CWARN("Found old param mdt.quota_type, changed"
4846 " it to mdd.quota_type.\n");
4851 lprocfs_mdt_init_vars(&lvars);
4852 rc = class_process_proc_param(PARAM_MDT, lvars.obd_vars,
4854 if (rc > 0 || rc == -ENOSYS)
4855 /* we don't understand; pass it on */
4856 rc = next->ld_ops->ldo_process_config(env, next, cfg);
4861 * Add mdc hook to get first MDT uuid and connect it to
4862 * ls->controller to use for seq manager.
4864 rc = next->ld_ops->ldo_process_config(env, next, cfg);
4866 CERROR("Can't add mdc, rc %d\n", rc);
4868 rc = mdt_seq_init_cli(env, mdt_dev(d), cfg);
4871 /* others are passed further */
4872 rc = next->ld_ops->ldo_process_config(env, next, cfg);
4878 static struct lu_object *mdt_object_alloc(const struct lu_env *env,
4879 const struct lu_object_header *hdr,
4880 struct lu_device *d)
4882 struct mdt_object *mo;
4888 struct lu_object *o;
4889 struct lu_object_header *h;
4891 o = &mo->mot_obj.mo_lu;
4892 h = &mo->mot_header;
4893 lu_object_header_init(h);
4894 lu_object_init(o, h, d);
4895 lu_object_add_top(h, o);
4896 o->lo_ops = &mdt_obj_ops;
4897 cfs_mutex_init(&mo->mot_ioepoch_mutex);
4898 cfs_mutex_init(&mo->mot_lov_mutex);
4904 static int mdt_object_init(const struct lu_env *env, struct lu_object *o,
4905 const struct lu_object_conf *unused)
4907 struct mdt_device *d = mdt_dev(o->lo_dev);
4908 struct lu_device *under;
4909 struct lu_object *below;
4913 CDEBUG(D_INFO, "object init, fid = "DFID"\n",
4914 PFID(lu_object_fid(o)));
4916 under = &d->mdt_child->md_lu_dev;
4917 below = under->ld_ops->ldo_object_alloc(env, o->lo_header, under);
4918 if (below != NULL) {
4919 lu_object_add(o, below);
4926 static void mdt_object_free(const struct lu_env *env, struct lu_object *o)
4928 struct mdt_object *mo = mdt_obj(o);
4929 struct lu_object_header *h;
4933 CDEBUG(D_INFO, "object free, fid = "DFID"\n",
4934 PFID(lu_object_fid(o)));
4937 lu_object_header_fini(h);
4942 static int mdt_object_print(const struct lu_env *env, void *cookie,
4943 lu_printer_t p, const struct lu_object *o)
4945 struct mdt_object *mdto = mdt_obj((struct lu_object *)o);
4946 return (*p)(env, cookie, LUSTRE_MDT_NAME"-object@%p(ioepoch="LPU64" "
4947 "flags="LPX64", epochcount=%d, writecount=%d)",
4948 mdto, mdto->mot_ioepoch, mdto->mot_flags,
4949 mdto->mot_ioepoch_count, mdto->mot_writecount);
4952 static const struct lu_device_operations mdt_lu_ops = {
4953 .ldo_object_alloc = mdt_object_alloc,
4954 .ldo_process_config = mdt_process_config,
4957 static const struct lu_object_operations mdt_obj_ops = {
4958 .loo_object_init = mdt_object_init,
4959 .loo_object_free = mdt_object_free,
4960 .loo_object_print = mdt_object_print
4963 static int mdt_obd_set_info_async(const struct lu_env *env,
4964 struct obd_export *exp,
4965 __u32 keylen, void *key,
4966 __u32 vallen, void *val,
4967 struct ptlrpc_request_set *set)
4969 struct obd_device *obd = exp->exp_obd;
4975 if (KEY_IS(KEY_SPTLRPC_CONF)) {
4976 rc = mdt_adapt_sptlrpc_conf(obd, 0);
4983 /* mds_connect_internal */
4984 static int mdt_connect_internal(struct obd_export *exp,
4985 struct mdt_device *mdt,
4986 struct obd_connect_data *data)
4989 data->ocd_connect_flags &= MDT_CONNECT_SUPPORTED;
4990 data->ocd_ibits_known &= MDS_INODELOCK_FULL;
4992 /* If no known bits (which should not happen, probably,
4993 as everybody should support LOOKUP and UPDATE bits at least)
4994 revert to compat mode with plain locks. */
4995 if (!data->ocd_ibits_known &&
4996 data->ocd_connect_flags & OBD_CONNECT_IBITS)
4997 data->ocd_connect_flags &= ~OBD_CONNECT_IBITS;
4999 if (!mdt->mdt_opts.mo_acl)
5000 data->ocd_connect_flags &= ~OBD_CONNECT_ACL;
5002 if (!mdt->mdt_opts.mo_user_xattr)
5003 data->ocd_connect_flags &= ~OBD_CONNECT_XATTR;
5005 if (!mdt->mdt_som_conf)
5006 data->ocd_connect_flags &= ~OBD_CONNECT_SOM;
5008 if (data->ocd_connect_flags & OBD_CONNECT_BRW_SIZE) {
5009 data->ocd_brw_size = min(data->ocd_brw_size,
5010 (__u32)(PTLRPC_MAX_BRW_PAGES << CFS_PAGE_SHIFT));
5011 if (data->ocd_brw_size == 0) {
5012 CERROR("%s: cli %s/%p ocd_connect_flags: "LPX64
5013 " ocd_version: %x ocd_grant: %d "
5014 "ocd_index: %u ocd_brw_size is "
5015 "unexpectedly zero, network data "
5016 "corruption? Refusing connection of this"
5018 exp->exp_obd->obd_name,
5019 exp->exp_client_uuid.uuid,
5020 exp, data->ocd_connect_flags, data->ocd_version,
5021 data->ocd_grant, data->ocd_index);
5026 cfs_spin_lock(&exp->exp_lock);
5027 exp->exp_connect_flags = data->ocd_connect_flags;
5028 cfs_spin_unlock(&exp->exp_lock);
5029 data->ocd_version = LUSTRE_VERSION_CODE;
5030 exp->exp_mdt_data.med_ibits_known = data->ocd_ibits_known;
5034 if (mdt->mdt_opts.mo_acl &&
5035 ((exp->exp_connect_flags & OBD_CONNECT_ACL) == 0)) {
5036 CWARN("%s: MDS requires ACL support but client does not\n",
5037 mdt->mdt_md_dev.md_lu_dev.ld_obd->obd_name);
5042 if ((exp->exp_connect_flags & OBD_CONNECT_FID) == 0) {
5043 CWARN("%s: MDS requires FID support, but client not\n",
5044 mdt->mdt_md_dev.md_lu_dev.ld_obd->obd_name);
5048 if (mdt->mdt_som_conf && !exp_connect_som(exp) &&
5049 !(exp->exp_connect_flags & OBD_CONNECT_MDS_MDS)) {
5050 CWARN("%s: MDS has SOM enabled, but client does not support "
5051 "it\n", mdt->mdt_md_dev.md_lu_dev.ld_obd->obd_name);
5058 static int mdt_connect_check_sptlrpc(struct mdt_device *mdt,
5059 struct obd_export *exp,
5060 struct ptlrpc_request *req)
5062 struct sptlrpc_flavor flvr;
5065 if (exp->exp_flvr.sf_rpc == SPTLRPC_FLVR_INVALID) {
5066 cfs_read_lock(&mdt->mdt_sptlrpc_lock);
5067 sptlrpc_target_choose_flavor(&mdt->mdt_sptlrpc_rset,
5071 cfs_read_unlock(&mdt->mdt_sptlrpc_lock);
5073 cfs_spin_lock(&exp->exp_lock);
5075 exp->exp_sp_peer = req->rq_sp_from;
5076 exp->exp_flvr = flvr;
5078 if (exp->exp_flvr.sf_rpc != SPTLRPC_FLVR_ANY &&
5079 exp->exp_flvr.sf_rpc != req->rq_flvr.sf_rpc) {
5080 CERROR("unauthorized rpc flavor %x from %s, "
5081 "expect %x\n", req->rq_flvr.sf_rpc,
5082 libcfs_nid2str(req->rq_peer.nid),
5083 exp->exp_flvr.sf_rpc);
5087 cfs_spin_unlock(&exp->exp_lock);
5089 if (exp->exp_sp_peer != req->rq_sp_from) {
5090 CERROR("RPC source %s doesn't match %s\n",
5091 sptlrpc_part2name(req->rq_sp_from),
5092 sptlrpc_part2name(exp->exp_sp_peer));
5095 rc = sptlrpc_target_export_check(exp, req);
5102 /* mds_connect copy */
5103 static int mdt_obd_connect(const struct lu_env *env,
5104 struct obd_export **exp, struct obd_device *obd,
5105 struct obd_uuid *cluuid,
5106 struct obd_connect_data *data,
5109 struct mdt_thread_info *info;
5110 struct obd_export *lexp;
5111 struct lustre_handle conn = { 0 };
5112 struct mdt_device *mdt;
5113 struct ptlrpc_request *req;
5117 LASSERT(env != NULL);
5118 if (!exp || !obd || !cluuid)
5121 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
5122 req = info->mti_pill->rc_req;
5123 mdt = mdt_dev(obd->obd_lu_dev);
5125 rc = class_connect(&conn, obd, cluuid);
5129 lexp = class_conn2export(&conn);
5130 LASSERT(lexp != NULL);
5132 rc = mdt_connect_check_sptlrpc(mdt, lexp, req);
5136 if (OBD_FAIL_CHECK(OBD_FAIL_TGT_RCVG_FLAG))
5137 lustre_msg_add_op_flags(req->rq_repmsg, MSG_CONNECT_RECOVERING);
5139 rc = mdt_connect_internal(lexp, mdt, data);
5141 struct lsd_client_data *lcd = lexp->exp_target_data.ted_lcd;
5144 info->mti_exp = lexp;
5145 memcpy(lcd->lcd_uuid, cluuid, sizeof lcd->lcd_uuid);
5146 rc = lut_client_new(env, lexp);
5148 mdt_export_stats_init(obd, lexp, localdata);
5153 class_disconnect(lexp);
5162 static int mdt_obd_reconnect(const struct lu_env *env,
5163 struct obd_export *exp, struct obd_device *obd,
5164 struct obd_uuid *cluuid,
5165 struct obd_connect_data *data,
5168 struct mdt_thread_info *info;
5169 struct mdt_device *mdt;
5170 struct ptlrpc_request *req;
5174 if (exp == NULL || obd == NULL || cluuid == NULL)
5177 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
5178 req = info->mti_pill->rc_req;
5179 mdt = mdt_dev(obd->obd_lu_dev);
5181 rc = mdt_connect_check_sptlrpc(mdt, exp, req);
5185 rc = mdt_connect_internal(exp, mdt_dev(obd->obd_lu_dev), data);
5187 mdt_export_stats_init(obd, exp, localdata);
5192 static int mdt_export_cleanup(struct obd_export *exp)
5194 struct mdt_export_data *med = &exp->exp_mdt_data;
5195 struct obd_device *obd = exp->exp_obd;
5196 struct mdt_device *mdt;
5197 struct mdt_thread_info *info;
5199 CFS_LIST_HEAD(closing_list);
5200 struct mdt_file_data *mfd, *n;
5204 cfs_spin_lock(&med->med_open_lock);
5205 while (!cfs_list_empty(&med->med_open_head)) {
5206 cfs_list_t *tmp = med->med_open_head.next;
5207 mfd = cfs_list_entry(tmp, struct mdt_file_data, mfd_list);
5209 /* Remove mfd handle so it can't be found again.
5210 * We are consuming the mfd_list reference here. */
5211 class_handle_unhash(&mfd->mfd_handle);
5212 cfs_list_move_tail(&mfd->mfd_list, &closing_list);
5214 cfs_spin_unlock(&med->med_open_lock);
5215 mdt = mdt_dev(obd->obd_lu_dev);
5216 LASSERT(mdt != NULL);
5218 rc = lu_env_init(&env, LCT_MD_THREAD);
5222 info = lu_context_key_get(&env.le_ctx, &mdt_thread_key);
5223 LASSERT(info != NULL);
5224 memset(info, 0, sizeof *info);
5225 info->mti_env = &env;
5226 info->mti_mdt = mdt;
5227 info->mti_exp = exp;
5229 if (!cfs_list_empty(&closing_list)) {
5230 struct md_attr *ma = &info->mti_attr;
5234 lmm_size = mdt->mdt_max_mdsize;
5235 OBD_ALLOC_LARGE(ma->ma_lmm, lmm_size);
5236 if (ma->ma_lmm == NULL)
5237 GOTO(out_lmm, rc = -ENOMEM);
5239 cookie_size = mdt->mdt_max_cookiesize;
5240 OBD_ALLOC_LARGE(ma->ma_cookie, cookie_size);
5241 if (ma->ma_cookie == NULL)
5242 GOTO(out_cookie, rc = -ENOMEM);
5244 /* Close any open files (which may also cause orphan unlinking). */
5245 cfs_list_for_each_entry_safe(mfd, n, &closing_list, mfd_list) {
5246 cfs_list_del_init(&mfd->mfd_list);
5247 memset(&ma->ma_attr, 0, sizeof(ma->ma_attr));
5248 ma->ma_lmm_size = lmm_size;
5249 ma->ma_cookie_size = cookie_size;
5251 /* It is not for setattr, just tell MDD to send
5252 * DESTROY RPC to OSS if needed */
5253 ma->ma_valid = MA_FLAGS;
5254 ma->ma_attr_flags = MDS_CLOSE_CLEANUP;
5255 /* Don't unlink orphan on failover umount, LU-184 */
5256 if (exp->exp_flags & OBD_OPT_FAILOVER)
5257 ma->ma_attr_flags |= MDS_KEEP_ORPHAN;
5258 mdt_mfd_close(info, mfd);
5260 OBD_FREE_LARGE(ma->ma_cookie, cookie_size);
5261 ma->ma_cookie = NULL;
5263 OBD_FREE_LARGE(ma->ma_lmm, lmm_size);
5267 info->mti_mdt = NULL;
5268 /* cleanup client slot early */
5269 /* Do not erase record for recoverable client. */
5270 if (!(exp->exp_flags & OBD_OPT_FAILOVER) || exp->exp_failed)
5271 lut_client_del(&env, exp);
5277 static int mdt_obd_disconnect(struct obd_export *exp)
5283 class_export_get(exp);
5285 rc = server_disconnect_export(exp);
5287 CDEBUG(D_IOCTL, "server disconnect error: %d\n", rc);
5289 rc = mdt_export_cleanup(exp);
5290 class_export_put(exp);
5294 /* FIXME: Can we avoid using these two interfaces? */
5295 static int mdt_init_export(struct obd_export *exp)
5297 struct mdt_export_data *med = &exp->exp_mdt_data;
5301 CFS_INIT_LIST_HEAD(&med->med_open_head);
5302 cfs_spin_lock_init(&med->med_open_lock);
5303 cfs_mutex_init(&med->med_idmap_mutex);
5304 med->med_idmap = NULL;
5305 cfs_spin_lock(&exp->exp_lock);
5306 exp->exp_connecting = 1;
5307 cfs_spin_unlock(&exp->exp_lock);
5309 /* self-export doesn't need client data and ldlm initialization */
5310 if (unlikely(obd_uuid_equals(&exp->exp_obd->obd_uuid,
5311 &exp->exp_client_uuid)))
5314 rc = lut_client_alloc(exp);
5318 rc = ldlm_init_export(exp);
5325 lut_client_free(exp);
5327 CERROR("%s: Error %d while initializing export\n",
5328 exp->exp_obd->obd_name, rc);
5332 static int mdt_destroy_export(struct obd_export *exp)
5336 if (exp_connect_rmtclient(exp))
5337 mdt_cleanup_idmap(&exp->exp_mdt_data);
5339 target_destroy_export(exp);
5340 /* destroy can be called from failed obd_setup, so
5341 * checking uuid is safer than obd_self_export */
5342 if (unlikely(obd_uuid_equals(&exp->exp_obd->obd_uuid,
5343 &exp->exp_client_uuid)))
5346 ldlm_destroy_export(exp);
5347 lut_client_free(exp);
5349 LASSERT(cfs_list_empty(&exp->exp_outstanding_replies));
5350 LASSERT(cfs_list_empty(&exp->exp_mdt_data.med_open_head));
5355 static void mdt_allow_cli(struct mdt_device *m, unsigned int flag)
5357 if (flag & CONFIG_LOG)
5358 cfs_set_bit(MDT_FL_CFGLOG, &m->mdt_state);
5360 /* also notify active event */
5361 if (flag & CONFIG_SYNC)
5362 cfs_set_bit(MDT_FL_SYNCED, &m->mdt_state);
5364 if (cfs_test_bit(MDT_FL_CFGLOG, &m->mdt_state) &&
5365 cfs_test_bit(MDT_FL_SYNCED, &m->mdt_state)) {
5366 struct obd_device *obd = m->mdt_md_dev.md_lu_dev.ld_obd;
5368 /* Open for clients */
5369 if (obd->obd_no_conn) {
5370 cfs_spin_lock(&obd->obd_dev_lock);
5371 obd->obd_no_conn = 0;
5372 cfs_spin_unlock(&obd->obd_dev_lock);
5377 static int mdt_upcall(const struct lu_env *env, struct md_device *md,
5378 enum md_upcall_event ev, void *data)
5380 struct mdt_device *m = mdt_dev(&md->md_lu_dev);
5381 struct md_device *next = m->mdt_child;
5382 struct mdt_thread_info *mti;
5388 rc = next->md_ops->mdo_maxsize_get(env, next,
5390 &m->mdt_max_cookiesize);
5391 CDEBUG(D_INFO, "get max mdsize %d max cookiesize %d\n",
5392 m->mdt_max_mdsize, m->mdt_max_cookiesize);
5393 mdt_allow_cli(m, CONFIG_SYNC);
5396 m->mdt_lut.lut_obd->u.obt.obt_mount_count;
5399 mti = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
5400 mti->mti_no_need_trans = 1;
5401 CDEBUG(D_INFO, "disable mdt trans for this thread\n");
5404 /* Check that MDT is not yet configured */
5405 LASSERT(!cfs_test_bit(MDT_FL_CFGLOG, &m->mdt_state));
5407 #ifdef HAVE_QUOTA_SUPPORT
5409 if (md->md_lu_dev.ld_obd->obd_recovering == 0 &&
5410 likely(md->md_lu_dev.ld_obd->obd_stopping == 0))
5411 next->md_ops->mdo_quota.mqo_recovery(env, next);
5415 CERROR("invalid event\n");
5422 static int mdt_obd_notify(struct obd_device *obd,
5423 struct obd_device *watched,
5424 enum obd_notify_event ev, void *data)
5426 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
5427 #ifdef HAVE_QUOTA_SUPPORT
5428 struct md_device *next = mdt->mdt_child;
5433 case OBD_NOTIFY_CONFIG:
5434 mdt_allow_cli(mdt, (unsigned long)data);
5436 #ifdef HAVE_QUOTA_SUPPORT
5437 /* quota_type has been processed, we can now handle
5438 * incoming quota requests */
5439 next->md_ops->mdo_quota.mqo_notify(NULL, next);
5443 CDEBUG(D_INFO, "Unhandled notification %#x\n", ev);
5448 static int mdt_rpc_fid2path(struct mdt_thread_info *info, void *key,
5449 void *val, int vallen)
5451 struct mdt_device *mdt = mdt_dev(info->mti_exp->exp_obd->obd_lu_dev);
5452 struct getinfo_fid2path *fpout, *fpin;
5455 fpin = key + cfs_size_round(sizeof(KEY_FID2PATH));
5458 if (ptlrpc_req_need_swab(info->mti_pill->rc_req))
5459 lustre_swab_fid2path(fpin);
5461 memcpy(fpout, fpin, sizeof(*fpin));
5462 if (fpout->gf_pathlen != vallen - sizeof(*fpin))
5465 rc = mdt_fid2path(info->mti_env, mdt, fpout);
5469 static int mdt_fid2path(const struct lu_env *env, struct mdt_device *mdt,
5470 struct getinfo_fid2path *fp)
5472 struct mdt_object *obj;
5476 CDEBUG(D_IOCTL, "path get "DFID" from "LPU64" #%d\n",
5477 PFID(&fp->gf_fid), fp->gf_recno, fp->gf_linkno);
5479 if (!fid_is_sane(&fp->gf_fid))
5482 obj = mdt_object_find(env, mdt, &fp->gf_fid);
5483 if (obj == NULL || IS_ERR(obj)) {
5484 CDEBUG(D_IOCTL, "no object "DFID": %ld\n", PFID(&fp->gf_fid),
5489 rc = lu_object_exists(&obj->mot_obj.mo_lu);
5495 mdt_object_put(env, obj);
5496 CDEBUG(D_IOCTL, "nonlocal object "DFID": %d\n",
5497 PFID(&fp->gf_fid), rc);
5501 rc = mo_path(env, md_object_next(&obj->mot_obj), fp->gf_path,
5502 fp->gf_pathlen, &fp->gf_recno, &fp->gf_linkno);
5503 mdt_object_put(env, obj);
5508 static int mdt_get_info(struct mdt_thread_info *info)
5510 struct ptlrpc_request *req = mdt_info_req(info);
5518 key = req_capsule_client_get(info->mti_pill, &RMF_GETINFO_KEY);
5520 CDEBUG(D_IOCTL, "No GETINFO key");
5523 keylen = req_capsule_get_size(info->mti_pill, &RMF_GETINFO_KEY,
5526 vallen = req_capsule_client_get(info->mti_pill, &RMF_GETINFO_VALLEN);
5527 if (vallen == NULL) {
5528 CDEBUG(D_IOCTL, "Unable to get RMF_GETINFO_VALLEN buffer");
5532 req_capsule_set_size(info->mti_pill, &RMF_GETINFO_VAL, RCL_SERVER,
5534 rc = req_capsule_server_pack(info->mti_pill);
5535 valout = req_capsule_server_get(info->mti_pill, &RMF_GETINFO_VAL);
5536 if (valout == NULL) {
5537 CDEBUG(D_IOCTL, "Unable to get get-info RPC out buffer");
5541 if (KEY_IS(KEY_FID2PATH))
5542 rc = mdt_rpc_fid2path(info, key, valout, *vallen);
5546 lustre_msg_set_status(req->rq_repmsg, rc);
5551 /* Pass the ioc down */
5552 static int mdt_ioc_child(struct lu_env *env, struct mdt_device *mdt,
5553 unsigned int cmd, int len, void *data)
5555 struct lu_context ioctl_session;
5556 struct md_device *next = mdt->mdt_child;
5560 rc = lu_context_init(&ioctl_session, LCT_SESSION);
5563 ioctl_session.lc_thread = (struct ptlrpc_thread *)cfs_current();
5564 lu_context_enter(&ioctl_session);
5565 env->le_ses = &ioctl_session;
5567 LASSERT(next->md_ops->mdo_iocontrol);
5568 rc = next->md_ops->mdo_iocontrol(env, next, cmd, len, data);
5570 lu_context_exit(&ioctl_session);
5571 lu_context_fini(&ioctl_session);
5575 static int mdt_ioc_version_get(struct mdt_thread_info *mti, void *karg)
5577 struct obd_ioctl_data *data = karg;
5578 struct lu_fid *fid = (struct lu_fid *)data->ioc_inlbuf1;
5580 struct mdt_object *obj;
5581 struct mdt_lock_handle *lh;
5585 CDEBUG(D_IOCTL, "getting version for "DFID"\n", PFID(fid));
5586 if (!fid_is_sane(fid))
5589 lh = &mti->mti_lh[MDT_LH_PARENT];
5590 mdt_lock_reg_init(lh, LCK_CR);
5592 obj = mdt_object_find_lock(mti, fid, lh, MDS_INODELOCK_UPDATE);
5594 RETURN(PTR_ERR(obj));
5596 rc = mdt_object_exists(obj);
5600 * before calling version get the correct MDS should be
5601 * fid, this is error to find remote object here
5603 CERROR("nonlocal object "DFID"\n", PFID(fid));
5604 } else if (rc == 0) {
5605 *(__u64 *)data->ioc_inlbuf2 = ENOENT_VERSION;
5608 version = dt_version_get(mti->mti_env, mdt_obj2dt(obj));
5609 *(__u64 *)data->ioc_inlbuf2 = version;
5612 mdt_object_unlock_put(mti, obj, lh, 1);
5616 /* ioctls on obd dev */
5617 static int mdt_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
5618 void *karg, void *uarg)
5621 struct obd_device *obd = exp->exp_obd;
5622 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
5623 struct dt_device *dt = mdt->mdt_bottom;
5627 CDEBUG(D_IOCTL, "handling ioctl cmd %#x\n", cmd);
5628 rc = lu_env_init(&env, LCT_MD_THREAD);
5634 rc = mdt_device_sync(&env, mdt);
5636 case OBD_IOC_SET_READONLY:
5637 rc = dt->dd_ops->dt_ro(&env, dt);
5639 case OBD_IOC_ABORT_RECOVERY:
5640 CERROR("Aborting recovery for device %s\n", obd->obd_name);
5641 target_stop_recovery_thread(obd);
5644 case OBD_IOC_CHANGELOG_REG:
5645 case OBD_IOC_CHANGELOG_DEREG:
5646 case OBD_IOC_CHANGELOG_CLEAR:
5647 rc = mdt_ioc_child(&env, mdt, cmd, len, karg);
5649 case OBD_IOC_GET_OBJ_VERSION: {
5650 struct mdt_thread_info *mti;
5651 mti = lu_context_key_get(&env.le_ctx, &mdt_thread_key);
5652 memset(mti, 0, sizeof *mti);
5653 mti->mti_env = &env;
5657 rc = mdt_ioc_version_get(mti, karg);
5661 CERROR("Not supported cmd = %d for device %s\n",
5662 cmd, obd->obd_name);
5670 int mdt_postrecov(const struct lu_env *env, struct mdt_device *mdt)
5672 struct lu_device *ld = md2lu_dev(mdt->mdt_child);
5673 #ifdef HAVE_QUOTA_SUPPORT
5674 struct obd_device *obd = mdt2obd_dev(mdt);
5675 struct md_device *next = mdt->mdt_child;
5680 rc = ld->ld_ops->ldo_recovery_complete(env, ld);
5681 #ifdef HAVE_QUOTA_SUPPORT
5682 if (likely(obd->obd_stopping == 0))
5683 next->md_ops->mdo_quota.mqo_recovery(env, next);
5688 int mdt_obd_postrecov(struct obd_device *obd)
5693 rc = lu_env_init(&env, LCT_MD_THREAD);
5696 rc = mdt_postrecov(&env, mdt_dev(obd->obd_lu_dev));
5702 * Send a copytool req to a client
5703 * Note this sends a request RPC from a server (MDT) to a client (MDC),
5704 * backwards of normal comms.
5706 int mdt_hsm_copytool_send(struct obd_export *exp)
5709 struct hsm_action_list *hal;
5710 struct hsm_action_item *hai;
5714 CWARN("%s: writing to mdc at %s\n", exp->exp_obd->obd_name,
5715 libcfs_nid2str(exp->exp_connection->c_peer.nid));
5717 len = sizeof(*lh) + sizeof(*hal) + MTI_NAME_MAXLEN +
5718 /* for mockup below */ 2 * cfs_size_round(sizeof(*hai));
5723 lh->kuc_magic = KUC_MAGIC;
5724 lh->kuc_transport = KUC_TRANSPORT_HSM;
5725 lh->kuc_msgtype = HMT_ACTION_LIST;
5726 lh->kuc_msglen = len;
5728 hal = (struct hsm_action_list *)(lh + 1);
5729 hal->hal_version = HAL_VERSION;
5730 hal->hal_archive_num = 1;
5731 obd_uuid2fsname(hal->hal_fsname, exp->exp_obd->obd_name,
5734 /* mock up an action list */
5736 hai = hai_zero(hal);
5737 hai->hai_action = HSMA_ARCHIVE;
5738 hai->hai_fid.f_oid = 0xA00A;
5739 hai->hai_len = sizeof(*hai);
5740 hai = hai_next(hai);
5741 hai->hai_action = HSMA_RESTORE;
5742 hai->hai_fid.f_oid = 0xB00B;
5743 hai->hai_len = sizeof(*hai);
5745 /* Uses the ldlm reverse import; this rpc will be seen by
5746 the ldlm_callback_handler */
5747 rc = do_set_info_async(exp->exp_imp_reverse,
5748 LDLM_SET_INFO, LUSTRE_OBD_VERSION,
5749 sizeof(KEY_HSM_COPYTOOL_SEND),
5750 KEY_HSM_COPYTOOL_SEND,
5758 static struct obd_ops mdt_obd_device_ops = {
5759 .o_owner = THIS_MODULE,
5760 .o_set_info_async = mdt_obd_set_info_async,
5761 .o_connect = mdt_obd_connect,
5762 .o_reconnect = mdt_obd_reconnect,
5763 .o_disconnect = mdt_obd_disconnect,
5764 .o_init_export = mdt_init_export,
5765 .o_destroy_export = mdt_destroy_export,
5766 .o_iocontrol = mdt_iocontrol,
5767 .o_postrecov = mdt_obd_postrecov,
5768 .o_notify = mdt_obd_notify
5771 static struct lu_device* mdt_device_fini(const struct lu_env *env,
5772 struct lu_device *d)
5774 struct mdt_device *m = mdt_dev(d);
5781 static struct lu_device *mdt_device_free(const struct lu_env *env,
5782 struct lu_device *d)
5784 struct mdt_device *m = mdt_dev(d);
5787 md_device_fini(&m->mdt_md_dev);
5792 static struct lu_device *mdt_device_alloc(const struct lu_env *env,
5793 struct lu_device_type *t,
5794 struct lustre_cfg *cfg)
5796 struct lu_device *l;
5797 struct mdt_device *m;
5803 l = &m->mdt_md_dev.md_lu_dev;
5804 rc = mdt_init0(env, m, t, cfg);
5806 mdt_device_free(env, l);
5810 md_upcall_init(&m->mdt_md_dev, mdt_upcall);
5812 l = ERR_PTR(-ENOMEM);
5816 /* context key constructor/destructor: mdt_key_init, mdt_key_fini */
5817 LU_KEY_INIT_FINI(mdt, struct mdt_thread_info);
5819 /* context key: mdt_thread_key */
5820 LU_CONTEXT_KEY_DEFINE(mdt, LCT_MD_THREAD);
5822 struct md_ucred *mdt_ucred(const struct mdt_thread_info *info)
5824 return md_ucred(info->mti_env);
5828 * Enable/disable COS (Commit On Sharing).
5830 * Set/Clear the COS flag in mdt options.
5832 * \param mdt mdt device
5833 * \param val 0 disables COS, other values enable COS
5835 void mdt_enable_cos(struct mdt_device *mdt, int val)
5840 mdt->mdt_opts.mo_cos = !!val;
5841 rc = lu_env_init(&env, LCT_LOCAL);
5842 if (unlikely(rc != 0)) {
5843 CWARN("lu_env initialization failed with rc = %d,"
5844 "cannot sync\n", rc);
5847 mdt_device_sync(&env, mdt);
5852 * Check COS (Commit On Sharing) status.
5854 * Return COS flag status.
5856 * \param mdt mdt device
5858 int mdt_cos_is_enabled(struct mdt_device *mdt)
5860 return mdt->mdt_opts.mo_cos != 0;
5863 /* type constructor/destructor: mdt_type_init, mdt_type_fini */
5864 LU_TYPE_INIT_FINI(mdt, &mdt_thread_key);
5866 static struct lu_device_type_operations mdt_device_type_ops = {
5867 .ldto_init = mdt_type_init,
5868 .ldto_fini = mdt_type_fini,
5870 .ldto_start = mdt_type_start,
5871 .ldto_stop = mdt_type_stop,
5873 .ldto_device_alloc = mdt_device_alloc,
5874 .ldto_device_free = mdt_device_free,
5875 .ldto_device_fini = mdt_device_fini
5878 static struct lu_device_type mdt_device_type = {
5879 .ldt_tags = LU_DEVICE_MD,
5880 .ldt_name = LUSTRE_MDT_NAME,
5881 .ldt_ops = &mdt_device_type_ops,
5882 .ldt_ctx_tags = LCT_MD_THREAD
5885 static int __init mdt_mod_init(void)
5887 struct lprocfs_static_vars lvars;
5890 lprocfs_mdt_init_vars(&lvars);
5891 rc = class_register_type(&mdt_obd_device_ops, NULL,
5892 lvars.module_vars, LUSTRE_MDT_NAME,
5898 static void __exit mdt_mod_exit(void)
5900 class_unregister_type(LUSTRE_MDT_NAME);
5904 #define DEF_HNDL(prefix, base, suffix, flags, opc, fn, fmt) \
5905 [prefix ## _ ## opc - prefix ## _ ## base] = { \
5907 .mh_fail_id = OBD_FAIL_ ## prefix ## _ ## opc ## suffix, \
5908 .mh_opc = prefix ## _ ## opc, \
5909 .mh_flags = flags, \
5914 #define DEF_MDT_HNDL(flags, name, fn, fmt) \
5915 DEF_HNDL(MDS, GETATTR, _NET, flags, name, fn, fmt)
5917 #define DEF_SEQ_HNDL(flags, name, fn, fmt) \
5918 DEF_HNDL(SEQ, QUERY, _NET, flags, name, fn, fmt)
5920 #define DEF_FLD_HNDL(flags, name, fn, fmt) \
5921 DEF_HNDL(FLD, QUERY, _NET, flags, name, fn, fmt)
5923 * Request with a format known in advance
5925 #define DEF_MDT_HNDL_F(flags, name, fn) \
5926 DEF_HNDL(MDS, GETATTR, _NET, flags, name, fn, &RQF_MDS_ ## name)
5928 #define DEF_SEQ_HNDL_F(flags, name, fn) \
5929 DEF_HNDL(SEQ, QUERY, _NET, flags, name, fn, &RQF_SEQ_ ## name)
5931 #define DEF_FLD_HNDL_F(flags, name, fn) \
5932 DEF_HNDL(FLD, QUERY, _NET, flags, name, fn, &RQF_FLD_ ## name)
5934 * Request with a format we do not yet know
5936 #define DEF_MDT_HNDL_0(flags, name, fn) \
5937 DEF_HNDL(MDS, GETATTR, _NET, flags, name, fn, NULL)
5939 static struct mdt_handler mdt_mds_ops[] = {
5940 DEF_MDT_HNDL_F(0, CONNECT, mdt_connect),
5941 DEF_MDT_HNDL_F(0, DISCONNECT, mdt_disconnect),
5942 DEF_MDT_HNDL (0, SET_INFO, mdt_set_info,
5944 DEF_MDT_HNDL_F(0, GET_INFO, mdt_get_info),
5945 DEF_MDT_HNDL_F(0 |HABEO_REFERO, GETSTATUS, mdt_getstatus),
5946 DEF_MDT_HNDL_F(HABEO_CORPUS, GETATTR, mdt_getattr),
5947 DEF_MDT_HNDL_F(HABEO_CORPUS|HABEO_REFERO, GETATTR_NAME, mdt_getattr_name),
5948 DEF_MDT_HNDL_F(HABEO_CORPUS, GETXATTR, mdt_getxattr),
5949 DEF_MDT_HNDL_F(0 |HABEO_REFERO, STATFS, mdt_statfs),
5950 DEF_MDT_HNDL_F(0 |MUTABOR, REINT, mdt_reint),
5951 DEF_MDT_HNDL_F(HABEO_CORPUS, CLOSE, mdt_close),
5952 DEF_MDT_HNDL_F(HABEO_CORPUS, DONE_WRITING, mdt_done_writing),
5953 DEF_MDT_HNDL_F(0 |HABEO_REFERO, PIN, mdt_pin),
5954 DEF_MDT_HNDL_0(0, SYNC, mdt_sync),
5955 DEF_MDT_HNDL_F(HABEO_CORPUS|HABEO_REFERO, IS_SUBDIR, mdt_is_subdir),
5956 #ifdef HAVE_QUOTA_SUPPORT
5957 DEF_MDT_HNDL_F(0, QUOTACHECK, mdt_quotacheck_handle),
5958 DEF_MDT_HNDL_F(0, QUOTACTL, mdt_quotactl_handle)
5962 #define DEF_OBD_HNDL(flags, name, fn) \
5963 DEF_HNDL(OBD, PING, _NET, flags, name, fn, NULL)
5966 static struct mdt_handler mdt_obd_ops[] = {
5967 DEF_OBD_HNDL(0, PING, mdt_obd_ping),
5968 DEF_OBD_HNDL(0, LOG_CANCEL, mdt_obd_log_cancel),
5969 DEF_OBD_HNDL(0, QC_CALLBACK, mdt_obd_qc_callback)
5972 #define DEF_DLM_HNDL_0(flags, name, fn) \
5973 DEF_HNDL(LDLM, ENQUEUE, , flags, name, fn, NULL)
5974 #define DEF_DLM_HNDL_F(flags, name, fn) \
5975 DEF_HNDL(LDLM, ENQUEUE, , flags, name, fn, &RQF_LDLM_ ## name)
5977 static struct mdt_handler mdt_dlm_ops[] = {
5978 DEF_DLM_HNDL_F(HABEO_CLAVIS, ENQUEUE, mdt_enqueue),
5979 DEF_DLM_HNDL_0(HABEO_CLAVIS, CONVERT, mdt_convert),
5980 DEF_DLM_HNDL_0(0, BL_CALLBACK, mdt_bl_callback),
5981 DEF_DLM_HNDL_0(0, CP_CALLBACK, mdt_cp_callback)
5984 #define DEF_LLOG_HNDL(flags, name, fn) \
5985 DEF_HNDL(LLOG, ORIGIN_HANDLE_CREATE, _NET, flags, name, fn, NULL)
5987 static struct mdt_handler mdt_llog_ops[] = {
5988 DEF_LLOG_HNDL(0, ORIGIN_HANDLE_CREATE, mdt_llog_create),
5989 DEF_LLOG_HNDL(0, ORIGIN_HANDLE_NEXT_BLOCK, mdt_llog_next_block),
5990 DEF_LLOG_HNDL(0, ORIGIN_HANDLE_READ_HEADER, mdt_llog_read_header),
5991 DEF_LLOG_HNDL(0, ORIGIN_HANDLE_WRITE_REC, NULL),
5992 DEF_LLOG_HNDL(0, ORIGIN_HANDLE_CLOSE, NULL),
5993 DEF_LLOG_HNDL(0, ORIGIN_CONNECT, NULL),
5994 DEF_LLOG_HNDL(0, CATINFO, NULL),
5995 DEF_LLOG_HNDL(0, ORIGIN_HANDLE_PREV_BLOCK, mdt_llog_prev_block),
5996 DEF_LLOG_HNDL(0, ORIGIN_HANDLE_DESTROY, mdt_llog_destroy),
5999 #define DEF_SEC_CTX_HNDL(name, fn) \
6000 DEF_HNDL(SEC_CTX, INIT, _NET, 0, name, fn, NULL)
6002 static struct mdt_handler mdt_sec_ctx_ops[] = {
6003 DEF_SEC_CTX_HNDL(INIT, mdt_sec_ctx_handle),
6004 DEF_SEC_CTX_HNDL(INIT_CONT, mdt_sec_ctx_handle),
6005 DEF_SEC_CTX_HNDL(FINI, mdt_sec_ctx_handle)
6008 static struct mdt_opc_slice mdt_regular_handlers[] = {
6010 .mos_opc_start = MDS_GETATTR,
6011 .mos_opc_end = MDS_LAST_OPC,
6012 .mos_hs = mdt_mds_ops
6015 .mos_opc_start = OBD_PING,
6016 .mos_opc_end = OBD_LAST_OPC,
6017 .mos_hs = mdt_obd_ops
6020 .mos_opc_start = LDLM_ENQUEUE,
6021 .mos_opc_end = LDLM_LAST_OPC,
6022 .mos_hs = mdt_dlm_ops
6025 .mos_opc_start = LLOG_ORIGIN_HANDLE_CREATE,
6026 .mos_opc_end = LLOG_LAST_OPC,
6027 .mos_hs = mdt_llog_ops
6030 .mos_opc_start = SEC_CTX_INIT,
6031 .mos_opc_end = SEC_LAST_OPC,
6032 .mos_hs = mdt_sec_ctx_ops
6039 static struct mdt_handler mdt_readpage_ops[] = {
6040 DEF_MDT_HNDL_F(0, CONNECT, mdt_connect),
6041 DEF_MDT_HNDL_F(HABEO_CORPUS|HABEO_REFERO, READPAGE, mdt_readpage),
6042 #ifdef HAVE_SPLIT_SUPPORT
6043 DEF_MDT_HNDL_F(HABEO_CORPUS|HABEO_REFERO, WRITEPAGE, mdt_writepage),
6047 * XXX: this is ugly and should be fixed one day, see mdc_close() for
6048 * detailed comments. --umka
6050 DEF_MDT_HNDL_F(HABEO_CORPUS, CLOSE, mdt_close),
6051 DEF_MDT_HNDL_F(HABEO_CORPUS, DONE_WRITING, mdt_done_writing),
6054 static struct mdt_opc_slice mdt_readpage_handlers[] = {
6056 .mos_opc_start = MDS_GETATTR,
6057 .mos_opc_end = MDS_LAST_OPC,
6058 .mos_hs = mdt_readpage_ops
6065 static struct mdt_handler mdt_xmds_ops[] = {
6066 DEF_MDT_HNDL_F(0, CONNECT, mdt_connect),
6067 DEF_MDT_HNDL_F(HABEO_CORPUS , GETATTR, mdt_getattr),
6068 DEF_MDT_HNDL_F(0 | MUTABOR , REINT, mdt_reint),
6069 DEF_MDT_HNDL_F(HABEO_CORPUS|HABEO_REFERO, IS_SUBDIR, mdt_is_subdir),
6072 static struct mdt_opc_slice mdt_xmds_handlers[] = {
6074 .mos_opc_start = MDS_GETATTR,
6075 .mos_opc_end = MDS_LAST_OPC,
6076 .mos_hs = mdt_xmds_ops
6079 .mos_opc_start = OBD_PING,
6080 .mos_opc_end = OBD_LAST_OPC,
6081 .mos_hs = mdt_obd_ops
6084 .mos_opc_start = SEC_CTX_INIT,
6085 .mos_opc_end = SEC_LAST_OPC,
6086 .mos_hs = mdt_sec_ctx_ops
6093 static struct mdt_handler mdt_seq_ops[] = {
6094 DEF_SEQ_HNDL_F(0, QUERY, (int (*)(struct mdt_thread_info *))seq_query)
6097 static struct mdt_opc_slice mdt_seq_handlers[] = {
6099 .mos_opc_start = SEQ_QUERY,
6100 .mos_opc_end = SEQ_LAST_OPC,
6101 .mos_hs = mdt_seq_ops
6108 static struct mdt_handler mdt_fld_ops[] = {
6109 DEF_FLD_HNDL_F(0, QUERY, (int (*)(struct mdt_thread_info *))fld_query)
6112 static struct mdt_opc_slice mdt_fld_handlers[] = {
6114 .mos_opc_start = FLD_QUERY,
6115 .mos_opc_end = FLD_LAST_OPC,
6116 .mos_hs = mdt_fld_ops
6123 MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");
6124 MODULE_DESCRIPTION("Lustre Meta-data Target ("LUSTRE_MDT_NAME")");
6125 MODULE_LICENSE("GPL");
6127 CFS_MODULE_PARM(mdt_num_threads, "ul", ulong, 0444,
6128 "number of mdt service threads to start");
6130 cfs_module(mdt, "0.2.0", mdt_mod_init, mdt_mod_exit);