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 int print_limit = min_t(int, CFS_PAGE_SIZE - 128, rc);
584 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_READLINK_EPROTO))
586 repbody->valid |= OBD_MD_LINKNAME;
587 /* we need to report back size with NULL-terminator
588 * because client expects that */
589 repbody->eadatasize = rc + 1;
590 if (repbody->eadatasize != reqbody->eadatasize)
591 CERROR("Read shorter symlink %d, expected %d\n",
592 rc, reqbody->eadatasize - 1);
594 ((char *)ma->ma_lmm)[rc] = 0;
596 /* If the total CDEBUG() size is larger than a page, it
597 * will print a warning to the console, avoid this by
598 * printing just the last part of the symlink. */
599 CDEBUG(D_INODE, "symlink dest %s%.*s, len = %d\n",
600 print_limit < rc ? "..." : "", print_limit,
601 (char *)ma->ma_lmm + rc - print_limit, rc);
606 if (reqbody->valid & OBD_MD_FLMODEASIZE) {
607 repbody->max_cookiesize = info->mti_mdt->mdt_max_cookiesize;
608 repbody->max_mdsize = info->mti_mdt->mdt_max_mdsize;
609 repbody->valid |= OBD_MD_FLMODEASIZE;
610 CDEBUG(D_INODE, "I am going to change the MAX_MD_SIZE & "
611 "MAX_COOKIE to : %d:%d\n", repbody->max_mdsize,
612 repbody->max_cookiesize);
615 if (exp_connect_rmtclient(info->mti_exp) &&
616 reqbody->valid & OBD_MD_FLRMTPERM) {
617 void *buf = req_capsule_server_get(pill, &RMF_ACL);
619 /* mdt_getattr_lock only */
620 rc = mdt_pack_remote_perm(info, o, buf);
622 repbody->valid &= ~OBD_MD_FLRMTPERM;
623 repbody->aclsize = 0;
626 repbody->valid |= OBD_MD_FLRMTPERM;
627 repbody->aclsize = sizeof(struct mdt_remote_perm);
630 #ifdef CONFIG_FS_POSIX_ACL
631 else if ((req->rq_export->exp_connect_flags & OBD_CONNECT_ACL) &&
632 (reqbody->valid & OBD_MD_FLACL)) {
633 buffer->lb_buf = req_capsule_server_get(pill, &RMF_ACL);
634 buffer->lb_len = req_capsule_get_size(pill,
635 &RMF_ACL, RCL_SERVER);
636 if (buffer->lb_len > 0) {
637 rc = mo_xattr_get(env, next, buffer,
638 XATTR_NAME_ACL_ACCESS);
640 if (rc == -ENODATA) {
641 repbody->aclsize = 0;
642 repbody->valid |= OBD_MD_FLACL;
644 } else if (rc == -EOPNOTSUPP) {
647 CERROR("got acl size: %d\n", rc);
650 repbody->aclsize = rc;
651 repbody->valid |= OBD_MD_FLACL;
658 if (reqbody->valid & OBD_MD_FLMDSCAPA &&
659 info->mti_mdt->mdt_opts.mo_mds_capa &&
660 info->mti_exp->exp_connect_flags & OBD_CONNECT_MDS_CAPA) {
661 struct lustre_capa *capa;
663 capa = req_capsule_server_get(pill, &RMF_CAPA1);
665 capa->lc_opc = CAPA_OPC_MDS_DEFAULT;
666 rc = mo_capa_get(env, next, capa, 0);
669 repbody->valid |= OBD_MD_FLMDSCAPA;
674 mdt_counter_incr(req, LPROC_MDT_GETATTR);
679 static int mdt_renew_capa(struct mdt_thread_info *info)
681 struct mdt_object *obj = info->mti_object;
682 struct mdt_body *body;
683 struct lustre_capa *capa, *c;
687 /* if object doesn't exist, or server has disabled capability,
688 * return directly, client will find body->valid OBD_MD_FLOSSCAPA
691 if (!obj || !info->mti_mdt->mdt_opts.mo_oss_capa ||
692 !(info->mti_exp->exp_connect_flags & OBD_CONNECT_OSS_CAPA))
695 body = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
696 LASSERT(body != NULL);
698 c = req_capsule_client_get(info->mti_pill, &RMF_CAPA1);
701 capa = req_capsule_server_get(info->mti_pill, &RMF_CAPA2);
705 rc = mo_capa_get(info->mti_env, mdt_object_child(obj), capa, 1);
707 body->valid |= OBD_MD_FLOSSCAPA;
711 static int mdt_getattr(struct mdt_thread_info *info)
713 struct mdt_object *obj = info->mti_object;
714 struct req_capsule *pill = info->mti_pill;
715 struct mdt_body *reqbody;
716 struct mdt_body *repbody;
721 reqbody = req_capsule_client_get(pill, &RMF_MDT_BODY);
724 if (reqbody->valid & OBD_MD_FLOSSCAPA) {
725 rc = req_capsule_server_pack(pill);
727 RETURN(err_serious(rc));
728 rc = mdt_renew_capa(info);
729 GOTO(out_shrink, rc);
732 LASSERT(obj != NULL);
733 LASSERT(lu_object_assert_exists(&obj->mot_obj.mo_lu));
735 mode = lu_object_attr(&obj->mot_obj.mo_lu);
737 /* old clients may not report needed easize, use max value then */
738 req_capsule_set_size(pill, &RMF_MDT_MD, RCL_SERVER,
739 reqbody->eadatasize == 0 ?
740 info->mti_mdt->mdt_max_mdsize :
741 reqbody->eadatasize);
743 rc = req_capsule_server_pack(pill);
744 if (unlikely(rc != 0))
745 RETURN(err_serious(rc));
747 repbody = req_capsule_server_get(pill, &RMF_MDT_BODY);
748 LASSERT(repbody != NULL);
749 repbody->eadatasize = 0;
750 repbody->aclsize = 0;
752 if (reqbody->valid & OBD_MD_FLRMTPERM)
753 rc = mdt_init_ucred(info, reqbody);
755 rc = mdt_check_ucred(info);
757 GOTO(out_shrink, rc);
759 info->mti_spec.sp_ck_split = !!(reqbody->valid & OBD_MD_FLCKSPLIT);
760 info->mti_cross_ref = !!(reqbody->valid & OBD_MD_FLCROSSREF);
763 * Don't check capability at all, because rename might getattr for
764 * remote obj, and at that time no capability is available.
766 mdt_set_capainfo(info, 1, &reqbody->fid1, BYPASS_CAPA);
767 rc = mdt_getattr_internal(info, obj, 0);
768 if (reqbody->valid & OBD_MD_FLRMTPERM)
769 mdt_exit_ucred(info);
772 mdt_client_compatibility(info);
773 rc2 = mdt_fix_reply(info);
779 static int mdt_is_subdir(struct mdt_thread_info *info)
781 struct mdt_object *o = info->mti_object;
782 struct req_capsule *pill = info->mti_pill;
783 const struct mdt_body *body = info->mti_body;
784 struct mdt_body *repbody;
790 repbody = req_capsule_server_get(pill, &RMF_MDT_BODY);
793 * We save last checked parent fid to @repbody->fid1 for remote
796 LASSERT(fid_is_sane(&body->fid2));
797 LASSERT(mdt_object_exists(o) > 0);
798 rc = mdo_is_subdir(info->mti_env, mdt_object_child(o),
799 &body->fid2, &repbody->fid1);
800 if (rc == 0 || rc == -EREMOTE)
801 repbody->valid |= OBD_MD_FLID;
806 static int mdt_raw_lookup(struct mdt_thread_info *info,
807 struct mdt_object *parent,
808 const struct lu_name *lname,
809 struct ldlm_reply *ldlm_rep)
811 struct md_object *next = mdt_object_child(info->mti_object);
812 const struct mdt_body *reqbody = info->mti_body;
813 struct lu_fid *child_fid = &info->mti_tmp_fid1;
814 struct mdt_body *repbody;
818 if (reqbody->valid != OBD_MD_FLID)
821 LASSERT(!info->mti_cross_ref);
823 /* Only got the fid of this obj by name */
825 rc = mdo_lookup(info->mti_env, next, lname, child_fid,
828 /* XXX is raw_lookup possible as intent operation? */
831 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_NEG);
834 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_POS);
836 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
839 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
840 repbody->fid1 = *child_fid;
841 repbody->valid = OBD_MD_FLID;
847 * UPDATE lock should be taken against parent, and be release before exit;
848 * child_bits lock should be taken against child, and be returned back:
849 * (1)normal request should release the child lock;
850 * (2)intent request will grant the lock to client.
852 static int mdt_getattr_name_lock(struct mdt_thread_info *info,
853 struct mdt_lock_handle *lhc,
855 struct ldlm_reply *ldlm_rep)
857 struct ptlrpc_request *req = mdt_info_req(info);
858 struct mdt_body *reqbody = NULL;
859 struct mdt_object *parent = info->mti_object;
860 struct mdt_object *child;
861 struct md_object *next = mdt_object_child(parent);
862 struct lu_fid *child_fid = &info->mti_tmp_fid1;
863 struct lu_name *lname = NULL;
864 const char *name = NULL;
866 struct mdt_lock_handle *lhp = NULL;
867 struct ldlm_lock *lock;
868 struct ldlm_res_id *res_id;
875 is_resent = lustre_handle_is_used(&lhc->mlh_reg_lh);
876 LASSERT(ergo(is_resent,
877 lustre_msg_get_flags(req->rq_reqmsg) & MSG_RESENT));
879 LASSERT(parent != NULL);
880 name = req_capsule_client_get(info->mti_pill, &RMF_NAME);
882 RETURN(err_serious(-EFAULT));
884 namelen = req_capsule_get_size(info->mti_pill, &RMF_NAME,
886 if (!info->mti_cross_ref) {
888 * XXX: Check for "namelen == 0" is for getattr by fid
889 * (OBD_CONNECT_ATTRFID), otherwise do not allow empty name,
890 * that is the name must contain at least one character and
891 * the terminating '\0'
894 reqbody = req_capsule_client_get(info->mti_pill,
896 if (unlikely(reqbody == NULL))
897 RETURN(err_serious(-EFAULT));
899 if (unlikely(!fid_is_sane(&reqbody->fid2)))
900 RETURN(err_serious(-EINVAL));
903 CDEBUG(D_INODE, "getattr with lock for "DFID"/"DFID", "
905 PFID(mdt_object_fid(parent)),
906 PFID(&reqbody->fid2), ldlm_rep);
908 lname = mdt_name(info->mti_env, (char *)name, namelen);
909 CDEBUG(D_INODE, "getattr with lock for "DFID"/%s, "
910 "ldlm_rep = %p\n", PFID(mdt_object_fid(parent)),
914 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_EXECD);
916 rc = mdt_object_exists(parent);
917 if (unlikely(rc == 0)) {
918 LU_OBJECT_DEBUG(D_INODE, info->mti_env,
919 &parent->mot_obj.mo_lu,
920 "Parent doesn't exist!\n");
922 } else if (!info->mti_cross_ref) {
923 LASSERTF(rc > 0, "Parent "DFID" is on remote server\n",
924 PFID(mdt_object_fid(parent)));
927 rc = mdt_raw_lookup(info, parent, lname, ldlm_rep);
935 if (info->mti_cross_ref) {
936 /* Only getattr on the child. Parent is on another node. */
937 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_POS);
939 CDEBUG(D_INODE, "partial getattr_name child_fid = "DFID", "
940 "ldlm_rep=%p\n", PFID(mdt_object_fid(child)), ldlm_rep);
943 /* Do not take lock for resent case. */
944 lock = ldlm_handle2lock(&lhc->mlh_reg_lh);
945 LASSERTF(lock != NULL, "Invalid lock handle "LPX64"\n",
946 lhc->mlh_reg_lh.cookie);
947 LASSERT(fid_res_name_eq(mdt_object_fid(child),
948 &lock->l_resource->lr_name));
952 mdt_lock_handle_init(lhc);
953 mdt_lock_reg_init(lhc, LCK_PR);
956 * Object's name is on another MDS, no lookup lock is
957 * needed here but update is.
959 child_bits &= ~MDS_INODELOCK_LOOKUP;
960 child_bits |= MDS_INODELOCK_UPDATE;
962 rc = mdt_object_lock(info, child, lhc, child_bits,
966 /* Finally, we can get attr for child. */
967 mdt_set_capainfo(info, 0, mdt_object_fid(child),
969 rc = mdt_getattr_internal(info, child, 0);
970 if (unlikely(rc != 0))
971 mdt_object_unlock(info, child, lhc, 1);
977 /* step 1: lock parent only if parent is a directory */
978 if (S_ISDIR(lu_object_attr(&parent->mot_obj.mo_lu))) {
979 lhp = &info->mti_lh[MDT_LH_PARENT];
980 mdt_lock_pdo_init(lhp, LCK_PR, name, namelen);
981 rc = mdt_object_lock(info, parent, lhp,
982 MDS_INODELOCK_UPDATE,
984 if (unlikely(rc != 0))
988 /* step 2: lookup child's fid by name */
990 rc = mdo_lookup(info->mti_env, next, lname, child_fid,
995 mdt_set_disposition(info, ldlm_rep,
997 GOTO(out_parent, rc);
999 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_POS);
1001 *child_fid = reqbody->fid2;
1002 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_POS);
1006 *step 3: find the child object by fid & lock it.
1007 * regardless if it is local or remote.
1009 child = mdt_object_find(info->mti_env, info->mti_mdt, child_fid);
1011 if (unlikely(IS_ERR(child)))
1012 GOTO(out_parent, rc = PTR_ERR(child));
1014 /* Do not take lock for resent case. */
1015 lock = ldlm_handle2lock(&lhc->mlh_reg_lh);
1016 LASSERTF(lock != NULL, "Invalid lock handle "LPX64"\n",
1017 lhc->mlh_reg_lh.cookie);
1019 res_id = &lock->l_resource->lr_name;
1020 if (!fid_res_name_eq(mdt_object_fid(child),
1021 &lock->l_resource->lr_name)) {
1022 LASSERTF(fid_res_name_eq(mdt_object_fid(parent),
1023 &lock->l_resource->lr_name),
1024 "Lock res_id: %lu/%lu/%lu, Fid: "DFID".\n",
1025 (unsigned long)res_id->name[0],
1026 (unsigned long)res_id->name[1],
1027 (unsigned long)res_id->name[2],
1028 PFID(mdt_object_fid(parent)));
1029 CWARN("Although resent, but still not get child lock"
1030 "parent:"DFID" child:"DFID"\n",
1031 PFID(mdt_object_fid(parent)),
1032 PFID(mdt_object_fid(child)));
1033 lustre_msg_clear_flags(req->rq_reqmsg, MSG_RESENT);
1034 LDLM_LOCK_PUT(lock);
1037 LDLM_LOCK_PUT(lock);
1041 OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_RESEND, obd_timeout*2);
1042 mdt_lock_handle_init(lhc);
1043 if (child_bits == MDS_INODELOCK_LAYOUT)
1044 mdt_lock_reg_init(lhc, LCK_CR);
1046 mdt_lock_reg_init(lhc, LCK_PR);
1048 if (mdt_object_exists(child) == 0) {
1049 LU_OBJECT_DEBUG(D_INODE, info->mti_env,
1050 &child->mot_obj.mo_lu,
1051 "Object doesn't exist!\n");
1052 GOTO(out_child, rc = -ENOENT);
1055 if (!(child_bits & MDS_INODELOCK_UPDATE)) {
1056 struct md_attr *ma = &info->mti_attr;
1059 ma->ma_need = MA_INODE;
1060 rc = mo_attr_get(info->mti_env,
1061 mdt_object_child(child), ma);
1062 if (unlikely(rc != 0))
1063 GOTO(out_child, rc);
1065 /* layout lock is used only on regular files */
1066 if ((ma->ma_valid & MA_INODE) &&
1067 (ma->ma_attr.la_valid & LA_MODE) &&
1068 !S_ISREG(ma->ma_attr.la_mode))
1069 child_bits &= ~MDS_INODELOCK_LAYOUT;
1071 /* If the file has not been changed for some time, we
1072 * return not only a LOOKUP lock, but also an UPDATE
1073 * lock and this might save us RPC on later STAT. For
1074 * directories, it also let negative dentry starts
1075 * working for this dir. */
1076 if (ma->ma_valid & MA_INODE &&
1077 ma->ma_attr.la_valid & LA_CTIME &&
1078 info->mti_mdt->mdt_namespace->ns_ctime_age_limit +
1079 ma->ma_attr.la_ctime < cfs_time_current_sec())
1080 child_bits |= MDS_INODELOCK_UPDATE;
1083 rc = mdt_object_lock(info, child, lhc, child_bits,
1086 if (unlikely(rc != 0))
1087 GOTO(out_child, rc);
1090 lock = ldlm_handle2lock(&lhc->mlh_reg_lh);
1091 /* Get MA_SOM attributes if update lock is given. */
1093 lock->l_policy_data.l_inodebits.bits & MDS_INODELOCK_UPDATE &&
1094 S_ISREG(lu_object_attr(&mdt_object_child(child)->mo_lu)))
1097 /* finally, we can get attr for child. */
1098 mdt_set_capainfo(info, 1, child_fid, BYPASS_CAPA);
1099 rc = mdt_getattr_internal(info, child, ma_need);
1100 if (unlikely(rc != 0)) {
1101 mdt_object_unlock(info, child, lhc, 1);
1103 /* Debugging code. */
1104 res_id = &lock->l_resource->lr_name;
1105 LDLM_DEBUG(lock, "Returning lock to client");
1106 LASSERTF(fid_res_name_eq(mdt_object_fid(child),
1107 &lock->l_resource->lr_name),
1108 "Lock res_id: %lu/%lu/%lu, Fid: "DFID".\n",
1109 (unsigned long)res_id->name[0],
1110 (unsigned long)res_id->name[1],
1111 (unsigned long)res_id->name[2],
1112 PFID(mdt_object_fid(child)));
1113 mdt_pack_size2body(info, child);
1116 LDLM_LOCK_PUT(lock);
1120 mdt_object_put(info->mti_env, child);
1123 mdt_object_unlock(info, parent, lhp, 1);
1127 /* normal handler: should release the child lock */
1128 static int mdt_getattr_name(struct mdt_thread_info *info)
1130 struct mdt_lock_handle *lhc = &info->mti_lh[MDT_LH_CHILD];
1131 struct mdt_body *reqbody;
1132 struct mdt_body *repbody;
1136 reqbody = req_capsule_client_get(info->mti_pill, &RMF_MDT_BODY);
1137 LASSERT(reqbody != NULL);
1138 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
1139 LASSERT(repbody != NULL);
1141 info->mti_spec.sp_ck_split = !!(reqbody->valid & OBD_MD_FLCKSPLIT);
1142 info->mti_cross_ref = !!(reqbody->valid & OBD_MD_FLCROSSREF);
1143 repbody->eadatasize = 0;
1144 repbody->aclsize = 0;
1146 rc = mdt_init_ucred(info, reqbody);
1148 GOTO(out_shrink, rc);
1150 rc = mdt_getattr_name_lock(info, lhc, MDS_INODELOCK_UPDATE, NULL);
1151 if (lustre_handle_is_used(&lhc->mlh_reg_lh)) {
1152 ldlm_lock_decref(&lhc->mlh_reg_lh, lhc->mlh_reg_mode);
1153 lhc->mlh_reg_lh.cookie = 0;
1155 mdt_exit_ucred(info);
1158 mdt_client_compatibility(info);
1159 rc2 = mdt_fix_reply(info);
1165 static const struct lu_device_operations mdt_lu_ops;
1167 static int lu_device_is_mdt(struct lu_device *d)
1169 return ergo(d != NULL && d->ld_ops != NULL, d->ld_ops == &mdt_lu_ops);
1172 static int mdt_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
1173 void *karg, void *uarg);
1175 static int mdt_set_info(struct mdt_thread_info *info)
1177 struct ptlrpc_request *req = mdt_info_req(info);
1180 int keylen, vallen, rc = 0;
1183 rc = req_capsule_server_pack(info->mti_pill);
1187 key = req_capsule_client_get(info->mti_pill, &RMF_SETINFO_KEY);
1189 DEBUG_REQ(D_HA, req, "no set_info key");
1193 keylen = req_capsule_get_size(info->mti_pill, &RMF_SETINFO_KEY,
1196 val = req_capsule_client_get(info->mti_pill, &RMF_SETINFO_VAL);
1198 DEBUG_REQ(D_HA, req, "no set_info val");
1202 vallen = req_capsule_get_size(info->mti_pill, &RMF_SETINFO_VAL,
1205 /* Swab any part of val you need to here */
1206 if (KEY_IS(KEY_READ_ONLY)) {
1208 lustre_msg_set_status(req->rq_repmsg, 0);
1210 cfs_spin_lock(&req->rq_export->exp_lock);
1212 req->rq_export->exp_connect_flags |= OBD_CONNECT_RDONLY;
1214 req->rq_export->exp_connect_flags &=~OBD_CONNECT_RDONLY;
1215 cfs_spin_unlock(&req->rq_export->exp_lock);
1217 } else if (KEY_IS(KEY_CHANGELOG_CLEAR)) {
1218 struct changelog_setinfo *cs =
1219 (struct changelog_setinfo *)val;
1220 if (vallen != sizeof(*cs)) {
1221 CERROR("Bad changelog_clear setinfo size %d\n", vallen);
1224 if (ptlrpc_req_need_swab(req)) {
1225 __swab64s(&cs->cs_recno);
1226 __swab32s(&cs->cs_id);
1229 rc = mdt_iocontrol(OBD_IOC_CHANGELOG_CLEAR, info->mti_exp,
1231 lustre_msg_set_status(req->rq_repmsg, rc);
1239 static int mdt_connect(struct mdt_thread_info *info)
1242 struct ptlrpc_request *req;
1244 req = mdt_info_req(info);
1245 rc = target_handle_connect(req);
1247 LASSERT(req->rq_export != NULL);
1248 info->mti_mdt = mdt_dev(req->rq_export->exp_obd->obd_lu_dev);
1249 rc = mdt_init_sec_level(info);
1251 rc = mdt_init_idmap(info);
1253 obd_disconnect(class_export_get(req->rq_export));
1255 rc = err_serious(rc);
1260 static int mdt_disconnect(struct mdt_thread_info *info)
1265 rc = target_handle_disconnect(mdt_info_req(info));
1267 rc = err_serious(rc);
1271 static int mdt_sendpage(struct mdt_thread_info *info,
1272 struct lu_rdpg *rdpg, int nob)
1274 struct ptlrpc_request *req = mdt_info_req(info);
1275 struct obd_export *exp = req->rq_export;
1276 struct ptlrpc_bulk_desc *desc;
1277 struct l_wait_info *lwi = &info->mti_u.rdpg.mti_wait_info;
1284 desc = ptlrpc_prep_bulk_exp(req, rdpg->rp_npages, BULK_PUT_SOURCE,
1289 for (i = 0, tmpcount = nob;
1290 i < rdpg->rp_npages && tmpcount > 0; i++, tmpcount -= tmpsize) {
1291 tmpsize = min_t(int, tmpcount, CFS_PAGE_SIZE);
1292 ptlrpc_prep_bulk_page(desc, rdpg->rp_pages[i], 0, tmpsize);
1295 LASSERT(desc->bd_nob == nob);
1296 rc = target_bulk_io(exp, desc, lwi);
1297 ptlrpc_free_bulk(desc);
1301 #ifdef HAVE_SPLIT_SUPPORT
1303 * Retrieve dir entry from the page and insert it to the slave object, actually,
1304 * this should be in osd layer, but since it will not in the final product, so
1305 * just do it here and do not define more moo api anymore for this.
1307 static int mdt_write_dir_page(struct mdt_thread_info *info, struct page *page,
1310 struct mdt_object *object = info->mti_object;
1311 struct lu_fid *lf = &info->mti_tmp_fid2;
1312 struct md_attr *ma = &info->mti_attr;
1313 struct lu_dirpage *dp;
1314 struct lu_dirent *ent;
1315 int rc = 0, offset = 0;
1318 /* Make sure we have at least one entry. */
1323 * Disable trans for this name insert, since it will include many trans
1326 info->mti_no_need_trans = 1;
1328 * When write_dir_page, no need update parent's ctime,
1329 * and no permission check for name_insert.
1331 ma->ma_attr.la_ctime = 0;
1332 ma->ma_attr.la_valid = LA_MODE;
1333 ma->ma_valid = MA_INODE;
1336 dp = page_address(page);
1337 offset = (int)((__u32)lu_dirent_start(dp) - (__u32)dp);
1339 for (ent = lu_dirent_start(dp); ent != NULL;
1340 ent = lu_dirent_next(ent)) {
1341 struct lu_name *lname;
1344 if (le16_to_cpu(ent->lde_namelen) == 0)
1347 fid_le_to_cpu(lf, &ent->lde_fid);
1348 if (le64_to_cpu(ent->lde_hash) & MAX_HASH_HIGHEST_BIT)
1349 ma->ma_attr.la_mode = S_IFDIR;
1351 ma->ma_attr.la_mode = 0;
1352 OBD_ALLOC(name, le16_to_cpu(ent->lde_namelen) + 1);
1354 GOTO(out, rc = -ENOMEM);
1356 memcpy(name, ent->lde_name, le16_to_cpu(ent->lde_namelen));
1357 lname = mdt_name(info->mti_env, name,
1358 le16_to_cpu(ent->lde_namelen));
1359 ma->ma_attr_flags |= (MDS_PERM_BYPASS | MDS_QUOTA_IGNORE);
1360 rc = mdo_name_insert(info->mti_env,
1361 md_object_next(&object->mot_obj),
1363 OBD_FREE(name, le16_to_cpu(ent->lde_namelen) + 1);
1365 CERROR("Can't insert %*.*s, rc %d\n",
1366 le16_to_cpu(ent->lde_namelen),
1367 le16_to_cpu(ent->lde_namelen),
1372 offset += lu_dirent_size(ent);
1382 static int mdt_bulk_timeout(void *data)
1386 CERROR("mdt bulk transfer timeout \n");
1391 static int mdt_writepage(struct mdt_thread_info *info)
1393 struct ptlrpc_request *req = mdt_info_req(info);
1394 struct mdt_body *reqbody;
1395 struct l_wait_info *lwi;
1396 struct ptlrpc_bulk_desc *desc;
1402 reqbody = req_capsule_client_get(info->mti_pill, &RMF_MDT_BODY);
1403 if (reqbody == NULL)
1404 RETURN(err_serious(-EFAULT));
1406 desc = ptlrpc_prep_bulk_exp(req, 1, BULK_GET_SINK, MDS_BULK_PORTAL);
1408 RETURN(err_serious(-ENOMEM));
1410 /* allocate the page for the desc */
1411 page = cfs_alloc_page(CFS_ALLOC_STD);
1413 GOTO(desc_cleanup, rc = -ENOMEM);
1415 CDEBUG(D_INFO, "Received page offset %d size %d \n",
1416 (int)reqbody->size, (int)reqbody->nlink);
1418 ptlrpc_prep_bulk_page(desc, page, (int)reqbody->size,
1419 (int)reqbody->nlink);
1421 rc = sptlrpc_svc_prep_bulk(req, desc);
1423 GOTO(cleanup_page, rc);
1425 * Check if client was evicted while we were doing i/o before touching
1430 GOTO(cleanup_page, rc = -ENOMEM);
1432 if (desc->bd_export->exp_failed)
1435 rc = ptlrpc_start_bulk_transfer (desc);
1437 *lwi = LWI_TIMEOUT_INTERVAL(obd_timeout * CFS_HZ / 4, CFS_HZ,
1438 mdt_bulk_timeout, desc);
1439 rc = l_wait_event(desc->bd_waitq, !ptlrpc_bulk_active(desc) ||
1440 desc->bd_export->exp_failed, lwi);
1441 LASSERT(rc == 0 || rc == -ETIMEDOUT);
1442 if (rc == -ETIMEDOUT) {
1443 DEBUG_REQ(D_ERROR, req, "timeout on bulk GET");
1444 ptlrpc_abort_bulk(desc);
1445 } else if (desc->bd_export->exp_failed) {
1446 DEBUG_REQ(D_ERROR, req, "Eviction on bulk GET");
1448 ptlrpc_abort_bulk(desc);
1449 } else if (!desc->bd_success ||
1450 desc->bd_nob_transferred != desc->bd_nob) {
1451 DEBUG_REQ(D_ERROR, req, "%s bulk GET %d(%d)",
1453 "truncated" : "network error on",
1454 desc->bd_nob_transferred, desc->bd_nob);
1455 /* XXX should this be a different errno? */
1459 DEBUG_REQ(D_ERROR, req, "ptlrpc_bulk_get failed: rc %d", rc);
1462 GOTO(cleanup_lwi, rc);
1463 rc = mdt_write_dir_page(info, page, reqbody->nlink);
1468 cfs_free_page(page);
1470 ptlrpc_free_bulk(desc);
1475 static int mdt_readpage(struct mdt_thread_info *info)
1477 struct mdt_object *object = info->mti_object;
1478 struct lu_rdpg *rdpg = &info->mti_u.rdpg.mti_rdpg;
1479 struct mdt_body *reqbody;
1480 struct mdt_body *repbody;
1485 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_READPAGE_PACK))
1486 RETURN(err_serious(-ENOMEM));
1488 reqbody = req_capsule_client_get(info->mti_pill, &RMF_MDT_BODY);
1489 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
1490 if (reqbody == NULL || repbody == NULL)
1491 RETURN(err_serious(-EFAULT));
1494 * prepare @rdpg before calling lower layers and transfer itself. Here
1495 * reqbody->size contains offset of where to start to read and
1496 * reqbody->nlink contains number bytes to read.
1498 rdpg->rp_hash = reqbody->size;
1499 if (rdpg->rp_hash != reqbody->size) {
1500 CERROR("Invalid hash: "LPX64" != "LPX64"\n",
1501 rdpg->rp_hash, reqbody->size);
1505 rdpg->rp_attrs = reqbody->mode;
1506 if (info->mti_exp->exp_connect_flags & OBD_CONNECT_64BITHASH)
1507 rdpg->rp_attrs |= LUDA_64BITHASH;
1508 rdpg->rp_count = min_t(unsigned int, reqbody->nlink,
1509 PTLRPC_MAX_BRW_SIZE);
1510 rdpg->rp_npages = (rdpg->rp_count + CFS_PAGE_SIZE - 1) >>
1512 OBD_ALLOC(rdpg->rp_pages, rdpg->rp_npages * sizeof rdpg->rp_pages[0]);
1513 if (rdpg->rp_pages == NULL)
1516 for (i = 0; i < rdpg->rp_npages; ++i) {
1517 rdpg->rp_pages[i] = cfs_alloc_page(CFS_ALLOC_STD);
1518 if (rdpg->rp_pages[i] == NULL)
1519 GOTO(free_rdpg, rc = -ENOMEM);
1522 /* call lower layers to fill allocated pages with directory data */
1523 rc = mo_readpage(info->mti_env, mdt_object_child(object), rdpg);
1525 GOTO(free_rdpg, rc);
1527 /* send pages to client */
1528 rc = mdt_sendpage(info, rdpg, rc);
1533 for (i = 0; i < rdpg->rp_npages; i++)
1534 if (rdpg->rp_pages[i] != NULL)
1535 cfs_free_page(rdpg->rp_pages[i]);
1536 OBD_FREE(rdpg->rp_pages, rdpg->rp_npages * sizeof rdpg->rp_pages[0]);
1538 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_SENDPAGE))
1544 static int mdt_reint_internal(struct mdt_thread_info *info,
1545 struct mdt_lock_handle *lhc,
1548 struct req_capsule *pill = info->mti_pill;
1549 struct md_quota *mq = md_quota(info->mti_env);
1550 struct mdt_body *repbody;
1555 rc = mdt_reint_unpack(info, op);
1557 CERROR("Can't unpack reint, rc %d\n", rc);
1558 RETURN(err_serious(rc));
1561 /* for replay (no_create) lmm is not needed, client has it already */
1562 if (req_capsule_has_field(pill, &RMF_MDT_MD, RCL_SERVER))
1563 req_capsule_set_size(pill, &RMF_MDT_MD, RCL_SERVER,
1564 info->mti_rr.rr_eadatalen);
1566 if (req_capsule_has_field(pill, &RMF_LOGCOOKIES, RCL_SERVER))
1567 req_capsule_set_size(pill, &RMF_LOGCOOKIES, RCL_SERVER,
1568 info->mti_mdt->mdt_max_cookiesize);
1570 rc = req_capsule_server_pack(pill);
1572 CERROR("Can't pack response, rc %d\n", rc);
1573 RETURN(err_serious(rc));
1576 if (req_capsule_has_field(pill, &RMF_MDT_BODY, RCL_SERVER)) {
1577 repbody = req_capsule_server_get(pill, &RMF_MDT_BODY);
1579 repbody->eadatasize = 0;
1580 repbody->aclsize = 0;
1583 OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_REINT_DELAY, 10);
1585 /* for replay no cookkie / lmm need, because client have this already */
1586 if (info->mti_spec.no_create)
1587 if (req_capsule_has_field(pill, &RMF_MDT_MD, RCL_SERVER))
1588 req_capsule_set_size(pill, &RMF_MDT_MD, RCL_SERVER, 0);
1590 rc = mdt_init_ucred_reint(info);
1592 GOTO(out_shrink, rc);
1594 rc = mdt_fix_attr_ucred(info, op);
1596 GOTO(out_ucred, rc = err_serious(rc));
1598 if (mdt_check_resent(info, mdt_reconstruct, lhc)) {
1599 rc = lustre_msg_get_status(mdt_info_req(info)->rq_repmsg);
1600 GOTO(out_ucred, rc);
1602 mq->mq_exp = info->mti_exp;
1603 rc = mdt_reint_rec(info, lhc);
1606 mdt_exit_ucred(info);
1608 mdt_client_compatibility(info);
1609 rc2 = mdt_fix_reply(info);
1615 static long mdt_reint_opcode(struct mdt_thread_info *info,
1616 const struct req_format **fmt)
1618 struct mdt_rec_reint *rec;
1621 opc = err_serious(-EFAULT);
1622 rec = req_capsule_client_get(info->mti_pill, &RMF_REC_REINT);
1624 opc = rec->rr_opcode;
1625 DEBUG_REQ(D_INODE, mdt_info_req(info), "reint opt = %ld", opc);
1626 if (opc < REINT_MAX && fmt[opc] != NULL)
1627 req_capsule_extend(info->mti_pill, fmt[opc]);
1629 CERROR("Unsupported opc: %ld\n", opc);
1630 opc = err_serious(opc);
1636 static int mdt_reint(struct mdt_thread_info *info)
1641 static const struct req_format *reint_fmts[REINT_MAX] = {
1642 [REINT_SETATTR] = &RQF_MDS_REINT_SETATTR,
1643 [REINT_CREATE] = &RQF_MDS_REINT_CREATE,
1644 [REINT_LINK] = &RQF_MDS_REINT_LINK,
1645 [REINT_UNLINK] = &RQF_MDS_REINT_UNLINK,
1646 [REINT_RENAME] = &RQF_MDS_REINT_RENAME,
1647 [REINT_OPEN] = &RQF_MDS_REINT_OPEN,
1648 [REINT_SETXATTR] = &RQF_MDS_REINT_SETXATTR
1653 opc = mdt_reint_opcode(info, reint_fmts);
1656 * No lock possible here from client to pass it to reint code
1659 rc = mdt_reint_internal(info, NULL, opc);
1664 info->mti_fail_id = OBD_FAIL_MDS_REINT_NET_REP;
1668 /* this should sync the whole device */
1669 static int mdt_device_sync(const struct lu_env *env, struct mdt_device *mdt)
1671 struct dt_device *dt = mdt->mdt_bottom;
1675 rc = dt->dd_ops->dt_sync(env, dt);
1679 /* this should sync this object */
1680 static int mdt_object_sync(struct mdt_thread_info *info)
1682 struct md_object *next;
1686 if (!mdt_object_exists(info->mti_object)) {
1687 CWARN("Non existing object "DFID"!\n",
1688 PFID(mdt_object_fid(info->mti_object)));
1691 next = mdt_object_child(info->mti_object);
1692 rc = mo_object_sync(info->mti_env, next);
1697 static int mdt_sync(struct mdt_thread_info *info)
1699 struct ptlrpc_request *req = mdt_info_req(info);
1700 struct req_capsule *pill = info->mti_pill;
1701 struct mdt_body *body;
1705 /* The fid may be zero, so we req_capsule_set manually */
1706 req_capsule_set(pill, &RQF_MDS_SYNC);
1708 body = req_capsule_client_get(pill, &RMF_MDT_BODY);
1710 RETURN(err_serious(-EINVAL));
1712 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_SYNC_PACK))
1713 RETURN(err_serious(-ENOMEM));
1715 if (fid_seq(&body->fid1) == 0) {
1716 /* sync the whole device */
1717 rc = req_capsule_server_pack(pill);
1719 rc = mdt_device_sync(info->mti_env, info->mti_mdt);
1721 rc = err_serious(rc);
1723 /* sync an object */
1724 rc = mdt_unpack_req_pack_rep(info, HABEO_CORPUS|HABEO_REFERO);
1726 rc = mdt_object_sync(info);
1728 struct md_object *next;
1729 const struct lu_fid *fid;
1730 struct lu_attr *la = &info->mti_attr.ma_attr;
1732 next = mdt_object_child(info->mti_object);
1733 info->mti_attr.ma_need = MA_INODE;
1734 info->mti_attr.ma_valid = 0;
1735 rc = mo_attr_get(info->mti_env, next,
1738 body = req_capsule_server_get(pill,
1740 fid = mdt_object_fid(info->mti_object);
1741 mdt_pack_attr2body(info, body, la, fid);
1745 rc = err_serious(rc);
1748 mdt_counter_incr(req, LPROC_MDT_SYNC);
1753 #ifdef HAVE_QUOTA_SUPPORT
1754 static int mdt_quotacheck_handle(struct mdt_thread_info *info)
1756 struct obd_quotactl *oqctl;
1757 struct req_capsule *pill = info->mti_pill;
1758 struct obd_export *exp = info->mti_exp;
1759 struct md_quota *mq = md_quota(info->mti_env);
1760 struct md_device *next = info->mti_mdt->mdt_child;
1764 oqctl = req_capsule_client_get(pill, &RMF_OBD_QUOTACTL);
1768 /* remote client has no permission for quotacheck */
1769 if (unlikely(exp_connect_rmtclient(exp)))
1772 rc = req_capsule_server_pack(pill);
1777 rc = next->md_ops->mdo_quota.mqo_check(info->mti_env, next,
1782 static int mdt_quotactl_handle(struct mdt_thread_info *info)
1784 struct obd_quotactl *oqctl, *repoqc;
1785 struct req_capsule *pill = info->mti_pill;
1786 struct obd_export *exp = info->mti_exp;
1787 struct md_quota *mq = md_quota(info->mti_env);
1788 struct md_device *next = info->mti_mdt->mdt_child;
1789 const struct md_quota_operations *mqo = &next->md_ops->mdo_quota;
1793 oqctl = req_capsule_client_get(pill, &RMF_OBD_QUOTACTL);
1798 if (exp_connect_rmtclient(exp)) {
1799 struct ptlrpc_request *req = mdt_info_req(info);
1800 struct mdt_export_data *med = mdt_req2med(req);
1801 struct lustre_idmap_table *idmap = med->med_idmap;
1803 if (unlikely(oqctl->qc_cmd != Q_GETQUOTA &&
1804 oqctl->qc_cmd != Q_GETINFO))
1808 if (oqctl->qc_type == USRQUOTA)
1809 id = lustre_idmap_lookup_uid(NULL, idmap, 0,
1811 else if (oqctl->qc_type == GRPQUOTA)
1812 id = lustre_idmap_lookup_gid(NULL, idmap, 0,
1817 if (id == CFS_IDMAP_NOTFOUND) {
1818 CDEBUG(D_QUOTA, "no mapping for id %u\n",
1824 rc = req_capsule_server_pack(pill);
1828 repoqc = req_capsule_server_get(pill, &RMF_OBD_QUOTACTL);
1829 LASSERT(repoqc != NULL);
1832 switch (oqctl->qc_cmd) {
1834 rc = mqo->mqo_on(info->mti_env, next, oqctl->qc_type);
1837 rc = mqo->mqo_off(info->mti_env, next, oqctl->qc_type);
1840 rc = mqo->mqo_setinfo(info->mti_env, next, oqctl->qc_type, id,
1844 rc = mqo->mqo_getinfo(info->mti_env, next, oqctl->qc_type, id,
1848 rc = mqo->mqo_setquota(info->mti_env, next, oqctl->qc_type, id,
1852 rc = mqo->mqo_getquota(info->mti_env, next, oqctl->qc_type, id,
1856 rc = mqo->mqo_getoinfo(info->mti_env, next, oqctl->qc_type, id,
1860 rc = mqo->mqo_getoquota(info->mti_env, next, oqctl->qc_type, id,
1863 case LUSTRE_Q_INVALIDATE:
1864 rc = mqo->mqo_invalidate(info->mti_env, next, oqctl->qc_type);
1866 case LUSTRE_Q_FINVALIDATE:
1867 rc = mqo->mqo_finvalidate(info->mti_env, next, oqctl->qc_type);
1870 CERROR("unsupported mdt_quotactl command: %d\n",
1882 * OBD PING and other handlers.
1884 static int mdt_obd_ping(struct mdt_thread_info *info)
1889 req_capsule_set(info->mti_pill, &RQF_OBD_PING);
1891 rc = target_handle_ping(mdt_info_req(info));
1893 rc = err_serious(rc);
1897 static int mdt_obd_log_cancel(struct mdt_thread_info *info)
1899 return err_serious(-EOPNOTSUPP);
1902 static int mdt_obd_qc_callback(struct mdt_thread_info *info)
1904 return err_serious(-EOPNOTSUPP);
1912 /** clone llog ctxt from child (mdd)
1913 * This allows remote llog (replicator) access.
1914 * We can either pass all llog RPCs (eg mdt_llog_create) on to child where the
1915 * context was originally set up, or we can handle them directly.
1916 * I choose the latter, but that means I need any llog
1917 * contexts set up by child to be accessable by the mdt. So we clone the
1918 * context into our context list here.
1920 static int mdt_llog_ctxt_clone(const struct lu_env *env, struct mdt_device *mdt,
1923 struct md_device *next = mdt->mdt_child;
1924 struct llog_ctxt *ctxt;
1927 if (!llog_ctxt_null(mdt2obd_dev(mdt), idx))
1930 rc = next->md_ops->mdo_llog_ctxt_get(env, next, idx, (void **)&ctxt);
1931 if (rc || ctxt == NULL) {
1932 CERROR("Can't get mdd ctxt %d\n", rc);
1936 rc = llog_group_set_ctxt(&mdt2obd_dev(mdt)->obd_olg, ctxt, idx);
1938 CERROR("Can't set mdt ctxt %d\n", rc);
1943 static int mdt_llog_ctxt_unclone(const struct lu_env *env,
1944 struct mdt_device *mdt, int idx)
1946 struct llog_ctxt *ctxt;
1948 ctxt = llog_get_context(mdt2obd_dev(mdt), idx);
1951 /* Put once for the get we just did, and once for the clone */
1952 llog_ctxt_put(ctxt);
1953 llog_ctxt_put(ctxt);
1957 static int mdt_llog_create(struct mdt_thread_info *info)
1961 req_capsule_set(info->mti_pill, &RQF_LLOG_ORIGIN_HANDLE_CREATE);
1962 rc = llog_origin_handle_create(mdt_info_req(info));
1963 return (rc < 0 ? err_serious(rc) : rc);
1966 static int mdt_llog_destroy(struct mdt_thread_info *info)
1970 req_capsule_set(info->mti_pill, &RQF_LLOG_ORIGIN_HANDLE_DESTROY);
1971 rc = llog_origin_handle_destroy(mdt_info_req(info));
1972 return (rc < 0 ? err_serious(rc) : rc);
1975 static int mdt_llog_read_header(struct mdt_thread_info *info)
1979 req_capsule_set(info->mti_pill, &RQF_LLOG_ORIGIN_HANDLE_READ_HEADER);
1980 rc = llog_origin_handle_read_header(mdt_info_req(info));
1981 return (rc < 0 ? err_serious(rc) : rc);
1984 static int mdt_llog_next_block(struct mdt_thread_info *info)
1988 req_capsule_set(info->mti_pill, &RQF_LLOG_ORIGIN_HANDLE_NEXT_BLOCK);
1989 rc = llog_origin_handle_next_block(mdt_info_req(info));
1990 return (rc < 0 ? err_serious(rc) : rc);
1993 static int mdt_llog_prev_block(struct mdt_thread_info *info)
1997 req_capsule_set(info->mti_pill, &RQF_LLOG_ORIGIN_HANDLE_PREV_BLOCK);
1998 rc = llog_origin_handle_prev_block(mdt_info_req(info));
1999 return (rc < 0 ? err_serious(rc) : rc);
2006 static struct ldlm_callback_suite cbs = {
2007 .lcs_completion = ldlm_server_completion_ast,
2008 .lcs_blocking = ldlm_server_blocking_ast,
2012 static int mdt_enqueue(struct mdt_thread_info *info)
2014 struct ptlrpc_request *req;
2018 * info->mti_dlm_req already contains swapped and (if necessary)
2019 * converted dlm request.
2021 LASSERT(info->mti_dlm_req != NULL);
2023 req = mdt_info_req(info);
2024 rc = ldlm_handle_enqueue0(info->mti_mdt->mdt_namespace,
2025 req, info->mti_dlm_req, &cbs);
2026 info->mti_fail_id = OBD_FAIL_LDLM_REPLY;
2027 return rc ? err_serious(rc) : req->rq_status;
2030 static int mdt_convert(struct mdt_thread_info *info)
2033 struct ptlrpc_request *req;
2035 LASSERT(info->mti_dlm_req);
2036 req = mdt_info_req(info);
2037 rc = ldlm_handle_convert0(req, info->mti_dlm_req);
2038 return rc ? err_serious(rc) : req->rq_status;
2041 static int mdt_bl_callback(struct mdt_thread_info *info)
2043 CERROR("bl callbacks should not happen on MDS\n");
2045 return err_serious(-EOPNOTSUPP);
2048 static int mdt_cp_callback(struct mdt_thread_info *info)
2050 CERROR("cp callbacks should not happen on MDS\n");
2052 return err_serious(-EOPNOTSUPP);
2056 * sec context handlers
2058 static int mdt_sec_ctx_handle(struct mdt_thread_info *info)
2062 rc = mdt_handle_idmap(info);
2065 struct ptlrpc_request *req = mdt_info_req(info);
2068 opc = lustre_msg_get_opc(req->rq_reqmsg);
2069 if (opc == SEC_CTX_INIT || opc == SEC_CTX_INIT_CONT)
2070 sptlrpc_svc_ctx_invalidate(req);
2073 CFS_FAIL_TIMEOUT(OBD_FAIL_SEC_CTX_HDL_PAUSE, cfs_fail_val);
2078 static struct mdt_object *mdt_obj(struct lu_object *o)
2080 LASSERT(lu_device_is_mdt(o->lo_dev));
2081 return container_of0(o, struct mdt_object, mot_obj.mo_lu);
2084 struct mdt_object *mdt_object_new(const struct lu_env *env,
2085 struct mdt_device *d,
2086 const struct lu_fid *f)
2088 struct lu_object_conf conf = { .loc_flags = LOC_F_NEW };
2089 struct lu_object *o;
2090 struct mdt_object *m;
2093 CDEBUG(D_INFO, "Allocate object for "DFID"\n", PFID(f));
2094 o = lu_object_find(env, &d->mdt_md_dev.md_lu_dev, f, &conf);
2095 if (unlikely(IS_ERR(o)))
2096 m = (struct mdt_object *)o;
2102 struct mdt_object *mdt_object_find(const struct lu_env *env,
2103 struct mdt_device *d,
2104 const struct lu_fid *f)
2106 struct lu_object *o;
2107 struct mdt_object *m;
2110 CDEBUG(D_INFO, "Find object for "DFID"\n", PFID(f));
2111 o = lu_object_find(env, &d->mdt_md_dev.md_lu_dev, f, NULL);
2112 if (unlikely(IS_ERR(o)))
2113 m = (struct mdt_object *)o;
2120 * Asyncronous commit for mdt device.
2122 * Pass asynchonous commit call down the MDS stack.
2124 * \param env environment
2125 * \param mdt the mdt device
2127 static void mdt_device_commit_async(const struct lu_env *env,
2128 struct mdt_device *mdt)
2130 struct dt_device *dt = mdt->mdt_bottom;
2133 rc = dt->dd_ops->dt_commit_async(env, dt);
2134 if (unlikely(rc != 0))
2135 CWARN("async commit start failed with rc = %d", rc);
2139 * Mark the lock as "synchonous".
2141 * Mark the lock to deffer transaction commit to the unlock time.
2143 * \param lock the lock to mark as "synchonous"
2145 * \see mdt_is_lock_sync
2146 * \see mdt_save_lock
2148 static inline void mdt_set_lock_sync(struct ldlm_lock *lock)
2150 lock->l_ast_data = (void*)1;
2154 * Check whehter the lock "synchonous" or not.
2156 * \param lock the lock to check
2157 * \retval 1 the lock is "synchonous"
2158 * \retval 0 the lock isn't "synchronous"
2160 * \see mdt_set_lock_sync
2161 * \see mdt_save_lock
2163 static inline int mdt_is_lock_sync(struct ldlm_lock *lock)
2165 return lock->l_ast_data != NULL;
2169 * Blocking AST for mdt locks.
2171 * Starts transaction commit if in case of COS lock conflict or
2172 * deffers such a commit to the mdt_save_lock.
2174 * \param lock the lock which blocks a request or cancelling lock
2175 * \param desc unused
2176 * \param data unused
2177 * \param flag indicates whether this cancelling or blocking callback
2179 * \see ldlm_blocking_ast_nocheck
2181 int mdt_blocking_ast(struct ldlm_lock *lock, struct ldlm_lock_desc *desc,
2182 void *data, int flag)
2184 struct obd_device *obd = ldlm_lock_to_ns(lock)->ns_obd;
2185 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
2189 if (flag == LDLM_CB_CANCELING)
2191 lock_res_and_lock(lock);
2192 if (lock->l_blocking_ast != mdt_blocking_ast) {
2193 unlock_res_and_lock(lock);
2196 if (mdt_cos_is_enabled(mdt) &&
2197 lock->l_req_mode & (LCK_PW | LCK_EX) &&
2198 lock->l_blocking_lock != NULL &&
2199 lock->l_client_cookie != lock->l_blocking_lock->l_client_cookie) {
2200 mdt_set_lock_sync(lock);
2202 rc = ldlm_blocking_ast_nocheck(lock);
2204 /* There is no lock conflict if l_blocking_lock == NULL,
2205 * it indicates a blocking ast sent from ldlm_lock_decref_internal
2206 * when the last reference to a local lock was released */
2207 if (lock->l_req_mode == LCK_COS && lock->l_blocking_lock != NULL) {
2210 rc = lu_env_init(&env, LCT_LOCAL);
2211 if (unlikely(rc != 0))
2212 CWARN("lu_env initialization failed with rc = %d,"
2213 "cannot start asynchronous commit\n", rc);
2215 mdt_device_commit_async(&env, mdt);
2221 int mdt_object_lock(struct mdt_thread_info *info, struct mdt_object *o,
2222 struct mdt_lock_handle *lh, __u64 ibits, int locality)
2224 struct ldlm_namespace *ns = info->mti_mdt->mdt_namespace;
2225 ldlm_policy_data_t *policy = &info->mti_policy;
2226 struct ldlm_res_id *res_id = &info->mti_res_id;
2230 LASSERT(!lustre_handle_is_used(&lh->mlh_reg_lh));
2231 LASSERT(!lustre_handle_is_used(&lh->mlh_pdo_lh));
2232 LASSERT(lh->mlh_reg_mode != LCK_MINMODE);
2233 LASSERT(lh->mlh_type != MDT_NUL_LOCK);
2235 if (mdt_object_exists(o) < 0) {
2236 if (locality == MDT_CROSS_LOCK) {
2237 /* cross-ref object fix */
2238 ibits &= ~MDS_INODELOCK_UPDATE;
2239 ibits |= MDS_INODELOCK_LOOKUP;
2241 LASSERT(!(ibits & MDS_INODELOCK_UPDATE));
2242 LASSERT(ibits & MDS_INODELOCK_LOOKUP);
2244 /* No PDO lock on remote object */
2245 LASSERT(lh->mlh_type != MDT_PDO_LOCK);
2248 if (lh->mlh_type == MDT_PDO_LOCK) {
2249 /* check for exists after object is locked */
2250 if (mdt_object_exists(o) == 0) {
2251 /* Non-existent object shouldn't have PDO lock */
2254 /* Non-dir object shouldn't have PDO lock */
2255 if (!S_ISDIR(lu_object_attr(&o->mot_obj.mo_lu)))
2260 memset(policy, 0, sizeof(*policy));
2261 fid_build_reg_res_name(mdt_object_fid(o), res_id);
2264 * Take PDO lock on whole directory and build correct @res_id for lock
2265 * on part of directory.
2267 if (lh->mlh_pdo_hash != 0) {
2268 LASSERT(lh->mlh_type == MDT_PDO_LOCK);
2269 mdt_lock_pdo_mode(info, o, lh);
2270 if (lh->mlh_pdo_mode != LCK_NL) {
2272 * Do not use LDLM_FL_LOCAL_ONLY for parallel lock, it
2273 * is never going to be sent to client and we do not
2274 * want it slowed down due to possible cancels.
2276 policy->l_inodebits.bits = MDS_INODELOCK_UPDATE;
2277 rc = mdt_fid_lock(ns, &lh->mlh_pdo_lh, lh->mlh_pdo_mode,
2278 policy, res_id, LDLM_FL_ATOMIC_CB,
2279 &info->mti_exp->exp_handle.h_cookie);
2285 * Finish res_id initializing by name hash marking part of
2286 * directory which is taking modification.
2288 res_id->name[LUSTRE_RES_ID_HSH_OFF] = lh->mlh_pdo_hash;
2291 policy->l_inodebits.bits = ibits;
2294 * Use LDLM_FL_LOCAL_ONLY for this lock. We do not know yet if it is
2295 * going to be sent to client. If it is - mdt_intent_policy() path will
2296 * fix it up and turn FL_LOCAL flag off.
2298 rc = mdt_fid_lock(ns, &lh->mlh_reg_lh, lh->mlh_reg_mode, policy,
2299 res_id, LDLM_FL_LOCAL_ONLY | LDLM_FL_ATOMIC_CB,
2300 &info->mti_exp->exp_handle.h_cookie);
2302 mdt_object_unlock(info, o, lh, 1);
2303 else if (unlikely(OBD_FAIL_PRECHECK(OBD_FAIL_MDS_PDO_LOCK)) &&
2304 lh->mlh_pdo_hash != 0 &&
2305 (lh->mlh_reg_mode == LCK_PW || lh->mlh_reg_mode == LCK_EX)) {
2306 OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_PDO_LOCK, 15);
2313 * Save a lock within request object.
2315 * Keep the lock referenced until whether client ACK or transaction
2316 * commit happens or release the lock immediately depending on input
2317 * parameters. If COS is ON, a write lock is converted to COS lock
2320 * \param info thead info object
2321 * \param h lock handle
2322 * \param mode lock mode
2323 * \param decref force immediate lock releasing
2326 void mdt_save_lock(struct mdt_thread_info *info, struct lustre_handle *h,
2327 ldlm_mode_t mode, int decref)
2331 if (lustre_handle_is_used(h)) {
2332 if (decref || !info->mti_has_trans ||
2333 !(mode & (LCK_PW | LCK_EX))){
2334 mdt_fid_unlock(h, mode);
2336 struct mdt_device *mdt = info->mti_mdt;
2337 struct ldlm_lock *lock = ldlm_handle2lock(h);
2338 struct ptlrpc_request *req = mdt_info_req(info);
2341 LASSERTF(lock != NULL, "no lock for cookie "LPX64"\n",
2343 CDEBUG(D_HA, "request = %p reply state = %p"
2344 " transno = "LPD64"\n",
2345 req, req->rq_reply_state, req->rq_transno);
2346 if (mdt_cos_is_enabled(mdt)) {
2348 ldlm_lock_downgrade(lock, LCK_COS);
2351 ptlrpc_save_lock(req, h, mode, no_ack);
2352 if (mdt_is_lock_sync(lock)) {
2353 CDEBUG(D_HA, "found sync-lock,"
2354 " async commit started\n");
2355 mdt_device_commit_async(info->mti_env,
2358 LDLM_LOCK_PUT(lock);
2367 * Unlock mdt object.
2369 * Immeditely release the regular lock and the PDO lock or save the
2370 * lock in reqeuest and keep them referenced until client ACK or
2371 * transaction commit.
2373 * \param info thread info object
2374 * \param o mdt object
2375 * \param lh mdt lock handle referencing regular and PDO locks
2376 * \param decref force immediate lock releasing
2378 void mdt_object_unlock(struct mdt_thread_info *info, struct mdt_object *o,
2379 struct mdt_lock_handle *lh, int decref)
2383 mdt_save_lock(info, &lh->mlh_pdo_lh, lh->mlh_pdo_mode, decref);
2384 mdt_save_lock(info, &lh->mlh_reg_lh, lh->mlh_reg_mode, decref);
2389 struct mdt_object *mdt_object_find_lock(struct mdt_thread_info *info,
2390 const struct lu_fid *f,
2391 struct mdt_lock_handle *lh,
2394 struct mdt_object *o;
2396 o = mdt_object_find(info->mti_env, info->mti_mdt, f);
2400 rc = mdt_object_lock(info, o, lh, ibits,
2403 mdt_object_put(info->mti_env, o);
2410 void mdt_object_unlock_put(struct mdt_thread_info * info,
2411 struct mdt_object * o,
2412 struct mdt_lock_handle *lh,
2415 mdt_object_unlock(info, o, lh, decref);
2416 mdt_object_put(info->mti_env, o);
2419 static struct mdt_handler *mdt_handler_find(__u32 opc,
2420 struct mdt_opc_slice *supported)
2422 struct mdt_opc_slice *s;
2423 struct mdt_handler *h;
2426 for (s = supported; s->mos_hs != NULL; s++) {
2427 if (s->mos_opc_start <= opc && opc < s->mos_opc_end) {
2428 h = s->mos_hs + (opc - s->mos_opc_start);
2429 if (likely(h->mh_opc != 0))
2430 LASSERTF(h->mh_opc == opc,
2431 "opcode mismatch %d != %d\n",
2434 h = NULL; /* unsupported opc */
2441 static int mdt_lock_resname_compat(struct mdt_device *m,
2442 struct ldlm_request *req)
2444 /* XXX something... later. */
2448 static int mdt_lock_reply_compat(struct mdt_device *m, struct ldlm_reply *rep)
2450 /* XXX something... later. */
2455 * Generic code handling requests that have struct mdt_body passed in:
2457 * - extract mdt_body from request and save it in @info, if present;
2459 * - create lu_object, corresponding to the fid in mdt_body, and save it in
2462 * - if HABEO_CORPUS flag is set for this request type check whether object
2463 * actually exists on storage (lu_object_exists()).
2466 static int mdt_body_unpack(struct mdt_thread_info *info, __u32 flags)
2468 const struct mdt_body *body;
2469 struct mdt_object *obj;
2470 const struct lu_env *env;
2471 struct req_capsule *pill;
2475 env = info->mti_env;
2476 pill = info->mti_pill;
2478 body = info->mti_body = req_capsule_client_get(pill, &RMF_MDT_BODY);
2482 if (!(body->valid & OBD_MD_FLID))
2485 if (!fid_is_sane(&body->fid1)) {
2486 CERROR("Invalid fid: "DFID"\n", PFID(&body->fid1));
2491 * Do not get size or any capa fields before we check that request
2492 * contains capa actually. There are some requests which do not, for
2493 * instance MDS_IS_SUBDIR.
2495 if (req_capsule_has_field(pill, &RMF_CAPA1, RCL_CLIENT) &&
2496 req_capsule_get_size(pill, &RMF_CAPA1, RCL_CLIENT))
2497 mdt_set_capainfo(info, 0, &body->fid1,
2498 req_capsule_client_get(pill, &RMF_CAPA1));
2500 obj = mdt_object_find(env, info->mti_mdt, &body->fid1);
2502 if ((flags & HABEO_CORPUS) &&
2503 !mdt_object_exists(obj)) {
2504 mdt_object_put(env, obj);
2505 /* for capability renew ENOENT will be handled in
2507 if (body->valid & OBD_MD_FLOSSCAPA)
2512 info->mti_object = obj;
2521 static int mdt_unpack_req_pack_rep(struct mdt_thread_info *info, __u32 flags)
2523 struct req_capsule *pill = info->mti_pill;
2527 if (req_capsule_has_field(pill, &RMF_MDT_BODY, RCL_CLIENT))
2528 rc = mdt_body_unpack(info, flags);
2532 if (rc == 0 && (flags & HABEO_REFERO)) {
2534 if (req_capsule_has_field(pill, &RMF_MDT_MD, RCL_SERVER))
2535 req_capsule_set_size(pill, &RMF_MDT_MD, RCL_SERVER,
2536 info->mti_body->eadatasize);
2537 if (req_capsule_has_field(pill, &RMF_LOGCOOKIES, RCL_SERVER))
2538 req_capsule_set_size(pill, &RMF_LOGCOOKIES, RCL_SERVER,
2539 info->mti_mdt->mdt_max_cookiesize);
2541 rc = req_capsule_server_pack(pill);
2546 static int mdt_init_capa_ctxt(const struct lu_env *env, struct mdt_device *m)
2548 struct md_device *next = m->mdt_child;
2550 return next->md_ops->mdo_init_capa_ctxt(env, next,
2551 m->mdt_opts.mo_mds_capa,
2552 m->mdt_capa_timeout,
2558 * Invoke handler for this request opc. Also do necessary preprocessing
2559 * (according to handler ->mh_flags), and post-processing (setting of
2560 * ->last_{xid,committed}).
2562 static int mdt_req_handle(struct mdt_thread_info *info,
2563 struct mdt_handler *h, struct ptlrpc_request *req)
2565 int rc, serious = 0;
2570 LASSERT(h->mh_act != NULL);
2571 LASSERT(h->mh_opc == lustre_msg_get_opc(req->rq_reqmsg));
2572 LASSERT(current->journal_info == NULL);
2575 * Checking for various OBD_FAIL_$PREF_$OPC_NET codes. _Do_ not try
2576 * to put same checks into handlers like mdt_close(), mdt_reint(),
2577 * etc., without talking to mdt authors first. Checking same thing
2578 * there again is useless and returning 0 error without packing reply
2579 * is buggy! Handlers either pack reply or return error.
2581 * We return 0 here and do not send any reply in order to emulate
2582 * network failure. Do not send any reply in case any of NET related
2583 * fail_id has occured.
2585 if (OBD_FAIL_CHECK_ORSET(h->mh_fail_id, OBD_FAIL_ONCE))
2589 flags = h->mh_flags;
2590 LASSERT(ergo(flags & (HABEO_CORPUS|HABEO_REFERO), h->mh_fmt != NULL));
2592 if (h->mh_fmt != NULL) {
2593 req_capsule_set(info->mti_pill, h->mh_fmt);
2594 rc = mdt_unpack_req_pack_rep(info, flags);
2597 if (rc == 0 && flags & MUTABOR &&
2598 req->rq_export->exp_connect_flags & OBD_CONNECT_RDONLY)
2599 /* should it be rq_status? */
2602 if (rc == 0 && flags & HABEO_CLAVIS) {
2603 struct ldlm_request *dlm_req;
2605 LASSERT(h->mh_fmt != NULL);
2607 dlm_req = req_capsule_client_get(info->mti_pill, &RMF_DLM_REQ);
2608 if (dlm_req != NULL) {
2609 if (unlikely(dlm_req->lock_desc.l_resource.lr_type ==
2611 dlm_req->lock_desc.l_policy_data.\
2612 l_inodebits.bits == 0)) {
2614 * Lock without inodebits makes no sense and
2615 * will oops later in ldlm. If client miss to
2616 * set such bits, do not trigger ASSERTION.
2618 * For liblustre flock case, it maybe zero.
2622 if (info->mti_mdt->mdt_opts.mo_compat_resname)
2623 rc = mdt_lock_resname_compat(
2626 info->mti_dlm_req = dlm_req;
2633 /* capability setting changed via /proc, needs reinitialize ctxt */
2634 if (info->mti_mdt && info->mti_mdt->mdt_capa_conf) {
2635 mdt_init_capa_ctxt(info->mti_env, info->mti_mdt);
2636 info->mti_mdt->mdt_capa_conf = 0;
2639 if (likely(rc == 0)) {
2641 * Process request, there can be two types of rc:
2642 * 1) errors with msg unpack/pack, other failures outside the
2643 * operation itself. This is counted as serious errors;
2644 * 2) errors during fs operation, should be placed in rq_status
2647 rc = h->mh_act(info);
2649 !req->rq_no_reply && req->rq_reply_state == NULL) {
2650 DEBUG_REQ(D_ERROR, req, "MDT \"handler\" %s did not "
2651 "pack reply and returned 0 error\n",
2655 serious = is_serious(rc);
2656 rc = clear_serious(rc);
2660 req->rq_status = rc;
2663 * ELDLM_* codes which > 0 should be in rq_status only as well as
2664 * all non-serious errors.
2666 if (rc > 0 || !serious)
2669 LASSERT(current->journal_info == NULL);
2671 if (rc == 0 && (flags & HABEO_CLAVIS) &&
2672 info->mti_mdt->mdt_opts.mo_compat_resname) {
2673 struct ldlm_reply *dlmrep;
2675 dlmrep = req_capsule_server_get(info->mti_pill, &RMF_DLM_REP);
2677 rc = mdt_lock_reply_compat(info->mti_mdt, dlmrep);
2680 /* If we're DISCONNECTing, the mdt_export_data is already freed */
2681 if (likely(rc == 0 && req->rq_export && h->mh_opc != MDS_DISCONNECT))
2682 target_committed_to_req(req);
2684 if (unlikely(req_is_replay(req) &&
2685 lustre_msg_get_transno(req->rq_reqmsg) == 0)) {
2686 DEBUG_REQ(D_ERROR, req, "transno is 0 during REPLAY");
2690 target_send_reply(req, rc, info->mti_fail_id);
2694 void mdt_lock_handle_init(struct mdt_lock_handle *lh)
2696 lh->mlh_type = MDT_NUL_LOCK;
2697 lh->mlh_reg_lh.cookie = 0ull;
2698 lh->mlh_reg_mode = LCK_MINMODE;
2699 lh->mlh_pdo_lh.cookie = 0ull;
2700 lh->mlh_pdo_mode = LCK_MINMODE;
2703 void mdt_lock_handle_fini(struct mdt_lock_handle *lh)
2705 LASSERT(!lustre_handle_is_used(&lh->mlh_reg_lh));
2706 LASSERT(!lustre_handle_is_used(&lh->mlh_pdo_lh));
2710 * Initialize fields of struct mdt_thread_info. Other fields are left in
2711 * uninitialized state, because it's too expensive to zero out whole
2712 * mdt_thread_info (> 1K) on each request arrival.
2714 static void mdt_thread_info_init(struct ptlrpc_request *req,
2715 struct mdt_thread_info *info)
2718 struct md_capainfo *ci;
2720 req_capsule_init(&req->rq_pill, req, RCL_SERVER);
2721 info->mti_pill = &req->rq_pill;
2724 for (i = 0; i < ARRAY_SIZE(info->mti_lh); i++)
2725 mdt_lock_handle_init(&info->mti_lh[i]);
2727 /* mdt device: it can be NULL while CONNECT */
2728 if (req->rq_export) {
2729 info->mti_mdt = mdt_dev(req->rq_export->exp_obd->obd_lu_dev);
2730 info->mti_exp = req->rq_export;
2732 info->mti_mdt = NULL;
2733 info->mti_env = req->rq_svc_thread->t_env;
2734 ci = md_capainfo(info->mti_env);
2735 memset(ci, 0, sizeof *ci);
2736 if (req->rq_export) {
2737 if (exp_connect_rmtclient(req->rq_export))
2738 ci->mc_auth = LC_ID_CONVERT;
2739 else if (req->rq_export->exp_connect_flags &
2740 OBD_CONNECT_MDS_CAPA)
2741 ci->mc_auth = LC_ID_PLAIN;
2743 ci->mc_auth = LC_ID_NONE;
2746 info->mti_fail_id = OBD_FAIL_MDS_ALL_REPLY_NET;
2747 info->mti_transno = lustre_msg_get_transno(req->rq_reqmsg);
2748 info->mti_mos = NULL;
2750 memset(&info->mti_attr, 0, sizeof(info->mti_attr));
2751 info->mti_body = NULL;
2752 info->mti_object = NULL;
2753 info->mti_dlm_req = NULL;
2754 info->mti_has_trans = 0;
2755 info->mti_no_need_trans = 0;
2756 info->mti_cross_ref = 0;
2757 info->mti_opdata = 0;
2759 /* To not check for split by default. */
2760 info->mti_spec.sp_ck_split = 0;
2761 info->mti_spec.no_create = 0;
2764 static void mdt_thread_info_fini(struct mdt_thread_info *info)
2768 req_capsule_fini(info->mti_pill);
2769 if (info->mti_object != NULL) {
2771 * freeing an object may lead to OSD level transaction, do not
2772 * let it mess with MDT. bz19385.
2774 info->mti_no_need_trans = 1;
2775 mdt_object_put(info->mti_env, info->mti_object);
2776 info->mti_object = NULL;
2778 for (i = 0; i < ARRAY_SIZE(info->mti_lh); i++)
2779 mdt_lock_handle_fini(&info->mti_lh[i]);
2780 info->mti_env = NULL;
2783 static int mdt_filter_recovery_request(struct ptlrpc_request *req,
2784 struct obd_device *obd, int *process)
2786 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
2787 case MDS_CONNECT: /* This will never get here, but for completeness. */
2788 case OST_CONNECT: /* This will never get here, but for completeness. */
2789 case MDS_DISCONNECT:
2790 case OST_DISCONNECT:
2795 case MDS_DONE_WRITING:
2796 case MDS_SYNC: /* used in unmounting */
2802 *process = target_queue_recovery_request(req, obd);
2806 DEBUG_REQ(D_ERROR, req, "not permitted during recovery");
2813 * Handle recovery. Return:
2814 * +1: continue request processing;
2815 * -ve: abort immediately with the given error code;
2816 * 0: send reply with error code in req->rq_status;
2818 static int mdt_recovery(struct mdt_thread_info *info)
2820 struct ptlrpc_request *req = mdt_info_req(info);
2821 struct obd_device *obd;
2825 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
2828 case SEC_CTX_INIT_CONT:
2834 rc = mdt_handle_idmap(info);
2843 if (unlikely(!class_connected_export(req->rq_export))) {
2844 CERROR("operation %d on unconnected MDS from %s\n",
2845 lustre_msg_get_opc(req->rq_reqmsg),
2846 libcfs_id2str(req->rq_peer));
2847 /* FIXME: For CMD cleanup, when mds_B stop, the req from
2848 * mds_A will get -ENOTCONN(especially for ping req),
2849 * which will cause that mds_A deactive timeout, then when
2850 * mds_A cleanup, the cleanup process will be suspended since
2851 * deactive timeout is not zero.
2853 req->rq_status = -ENOTCONN;
2854 target_send_reply(req, -ENOTCONN, info->mti_fail_id);
2858 /* sanity check: if the xid matches, the request must be marked as a
2859 * resent or replayed */
2860 if (req_xid_is_last(req)) {
2861 if (!(lustre_msg_get_flags(req->rq_reqmsg) &
2862 (MSG_RESENT | MSG_REPLAY))) {
2863 DEBUG_REQ(D_WARNING, req, "rq_xid "LPU64" matches last_xid, "
2864 "expected REPLAY or RESENT flag (%x)", req->rq_xid,
2865 lustre_msg_get_flags(req->rq_reqmsg));
2867 req->rq_status = -ENOTCONN;
2872 /* else: note the opposite is not always true; a RESENT req after a
2873 * failover will usually not match the last_xid, since it was likely
2874 * never committed. A REPLAYed request will almost never match the
2875 * last xid, however it could for a committed, but still retained,
2878 obd = req->rq_export->exp_obd;
2880 /* Check for aborted recovery... */
2881 if (unlikely(obd->obd_recovering)) {
2884 DEBUG_REQ(D_INFO, req, "Got new replay");
2885 rc = mdt_filter_recovery_request(req, obd, &should_process);
2886 if (rc != 0 || !should_process)
2888 else if (should_process < 0) {
2889 req->rq_status = should_process;
2890 rc = ptlrpc_error(req);
2897 static int mdt_msg_check_version(struct lustre_msg *msg)
2901 switch (lustre_msg_get_opc(msg)) {
2903 case MDS_DISCONNECT:
2906 case SEC_CTX_INIT_CONT:
2908 rc = lustre_msg_check_version(msg, LUSTRE_OBD_VERSION);
2910 CERROR("bad opc %u version %08x, expecting %08x\n",
2911 lustre_msg_get_opc(msg),
2912 lustre_msg_get_version(msg),
2913 LUSTRE_OBD_VERSION);
2917 case MDS_GETATTR_NAME:
2924 case MDS_DONE_WRITING:
2931 case MDS_QUOTACHECK:
2937 rc = lustre_msg_check_version(msg, LUSTRE_MDS_VERSION);
2939 CERROR("bad opc %u version %08x, expecting %08x\n",
2940 lustre_msg_get_opc(msg),
2941 lustre_msg_get_version(msg),
2942 LUSTRE_MDS_VERSION);
2946 case LDLM_BL_CALLBACK:
2947 case LDLM_CP_CALLBACK:
2948 rc = lustre_msg_check_version(msg, LUSTRE_DLM_VERSION);
2950 CERROR("bad opc %u version %08x, expecting %08x\n",
2951 lustre_msg_get_opc(msg),
2952 lustre_msg_get_version(msg),
2953 LUSTRE_DLM_VERSION);
2955 case OBD_LOG_CANCEL:
2956 case LLOG_ORIGIN_HANDLE_CREATE:
2957 case LLOG_ORIGIN_HANDLE_NEXT_BLOCK:
2958 case LLOG_ORIGIN_HANDLE_READ_HEADER:
2959 case LLOG_ORIGIN_HANDLE_CLOSE:
2960 case LLOG_ORIGIN_HANDLE_DESTROY:
2961 case LLOG_ORIGIN_HANDLE_PREV_BLOCK:
2963 rc = lustre_msg_check_version(msg, LUSTRE_LOG_VERSION);
2965 CERROR("bad opc %u version %08x, expecting %08x\n",
2966 lustre_msg_get_opc(msg),
2967 lustre_msg_get_version(msg),
2968 LUSTRE_LOG_VERSION);
2971 CERROR("MDS unknown opcode %d\n", lustre_msg_get_opc(msg));
2977 static int mdt_handle0(struct ptlrpc_request *req,
2978 struct mdt_thread_info *info,
2979 struct mdt_opc_slice *supported)
2981 struct mdt_handler *h;
2982 struct lustre_msg *msg;
2987 if (OBD_FAIL_CHECK_ORSET(OBD_FAIL_MDS_ALL_REQUEST_NET, OBD_FAIL_ONCE))
2990 LASSERT(current->journal_info == NULL);
2992 msg = req->rq_reqmsg;
2993 rc = mdt_msg_check_version(msg);
2994 if (likely(rc == 0)) {
2995 rc = mdt_recovery(info);
2996 if (likely(rc == +1)) {
2997 h = mdt_handler_find(lustre_msg_get_opc(msg),
2999 if (likely(h != NULL)) {
3000 rc = mdt_req_handle(info, h, req);
3002 CERROR("The unsupported opc: 0x%x\n",
3003 lustre_msg_get_opc(msg) );
3004 req->rq_status = -ENOTSUPP;
3005 rc = ptlrpc_error(req);
3010 CERROR(LUSTRE_MDT_NAME" drops mal-formed request\n");
3015 * MDT handler function called by ptlrpc service thread when request comes.
3017 * XXX common "target" functionality should be factored into separate module
3018 * shared by mdt, ost and stand-alone services like fld.
3020 static int mdt_handle_common(struct ptlrpc_request *req,
3021 struct mdt_opc_slice *supported)
3024 struct mdt_thread_info *info;
3028 env = req->rq_svc_thread->t_env;
3029 LASSERT(env != NULL);
3030 LASSERT(env->le_ses != NULL);
3031 LASSERT(env->le_ctx.lc_thread == req->rq_svc_thread);
3032 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
3033 LASSERT(info != NULL);
3035 mdt_thread_info_init(req, info);
3037 rc = mdt_handle0(req, info, supported);
3039 mdt_thread_info_fini(info);
3044 * This is called from recovery code as handler of _all_ RPC types, FLD and SEQ
3047 int mdt_recovery_handle(struct ptlrpc_request *req)
3052 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
3054 rc = mdt_handle_common(req, mdt_fld_handlers);
3057 rc = mdt_handle_common(req, mdt_seq_handlers);
3060 rc = mdt_handle_common(req, mdt_regular_handlers);
3067 static int mdt_regular_handle(struct ptlrpc_request *req)
3069 return mdt_handle_common(req, mdt_regular_handlers);
3072 static int mdt_readpage_handle(struct ptlrpc_request *req)
3074 return mdt_handle_common(req, mdt_readpage_handlers);
3077 static int mdt_xmds_handle(struct ptlrpc_request *req)
3079 return mdt_handle_common(req, mdt_xmds_handlers);
3082 static int mdt_mdsc_handle(struct ptlrpc_request *req)
3084 return mdt_handle_common(req, mdt_seq_handlers);
3087 static int mdt_mdss_handle(struct ptlrpc_request *req)
3089 return mdt_handle_common(req, mdt_seq_handlers);
3092 static int mdt_dtss_handle(struct ptlrpc_request *req)
3094 return mdt_handle_common(req, mdt_seq_handlers);
3097 static int mdt_fld_handle(struct ptlrpc_request *req)
3099 return mdt_handle_common(req, mdt_fld_handlers);
3116 static int mdt_intent_getattr(enum mdt_it_code opcode,
3117 struct mdt_thread_info *info,
3118 struct ldlm_lock **,
3120 static int mdt_intent_reint(enum mdt_it_code opcode,
3121 struct mdt_thread_info *info,
3122 struct ldlm_lock **,
3125 static struct mdt_it_flavor {
3126 const struct req_format *it_fmt;
3128 int (*it_act)(enum mdt_it_code ,
3129 struct mdt_thread_info *,
3130 struct ldlm_lock **,
3133 } mdt_it_flavor[] = {
3135 .it_fmt = &RQF_LDLM_INTENT,
3136 /*.it_flags = HABEO_REFERO,*/
3138 .it_act = mdt_intent_reint,
3139 .it_reint = REINT_OPEN
3142 .it_fmt = &RQF_LDLM_INTENT,
3143 .it_flags = MUTABOR,
3144 .it_act = mdt_intent_reint,
3145 .it_reint = REINT_OPEN
3148 .it_fmt = &RQF_LDLM_INTENT,
3149 .it_flags = MUTABOR,
3150 .it_act = mdt_intent_reint,
3151 .it_reint = REINT_CREATE
3153 [MDT_IT_GETATTR] = {
3154 .it_fmt = &RQF_LDLM_INTENT_GETATTR,
3155 .it_flags = HABEO_REFERO,
3156 .it_act = mdt_intent_getattr
3158 [MDT_IT_READDIR] = {
3164 .it_fmt = &RQF_LDLM_INTENT_GETATTR,
3165 .it_flags = HABEO_REFERO,
3166 .it_act = mdt_intent_getattr
3169 .it_fmt = &RQF_LDLM_INTENT_UNLINK,
3170 .it_flags = MUTABOR,
3172 .it_reint = REINT_UNLINK
3176 .it_flags = MUTABOR,
3179 [MDT_IT_GETXATTR] = {
3185 .it_fmt = &RQF_LDLM_INTENT_GETATTR,
3186 .it_flags = HABEO_REFERO,
3187 .it_act = mdt_intent_getattr
3191 int mdt_intent_lock_replace(struct mdt_thread_info *info,
3192 struct ldlm_lock **lockp,
3193 struct ldlm_lock *new_lock,
3194 struct mdt_lock_handle *lh,
3197 struct ptlrpc_request *req = mdt_info_req(info);
3198 struct ldlm_lock *lock = *lockp;
3201 * Get new lock only for cases when possible resent did not find any
3204 if (new_lock == NULL)
3205 new_lock = ldlm_handle2lock_long(&lh->mlh_reg_lh, 0);
3207 if (new_lock == NULL && (flags & LDLM_FL_INTENT_ONLY)) {
3208 lh->mlh_reg_lh.cookie = 0;
3212 LASSERTF(new_lock != NULL,
3213 "lockh "LPX64"\n", lh->mlh_reg_lh.cookie);
3216 * If we've already given this lock to a client once, then we should
3217 * have no readers or writers. Otherwise, we should have one reader
3218 * _or_ writer ref (which will be zeroed below) before returning the
3221 if (new_lock->l_export == req->rq_export) {
3222 LASSERT(new_lock->l_readers + new_lock->l_writers == 0);
3224 LASSERT(new_lock->l_export == NULL);
3225 LASSERT(new_lock->l_readers + new_lock->l_writers == 1);
3230 if (new_lock->l_export == req->rq_export) {
3232 * Already gave this to the client, which means that we
3233 * reconstructed a reply.
3235 LASSERT(lustre_msg_get_flags(req->rq_reqmsg) &
3237 lh->mlh_reg_lh.cookie = 0;
3238 RETURN(ELDLM_LOCK_REPLACED);
3242 * Fixup the lock to be given to the client.
3244 lock_res_and_lock(new_lock);
3245 /* Zero new_lock->l_readers and new_lock->l_writers without triggering
3246 * possible blocking AST. */
3247 while (new_lock->l_readers > 0) {
3248 lu_ref_del(&new_lock->l_reference, "reader", new_lock);
3249 lu_ref_del(&new_lock->l_reference, "user", new_lock);
3250 new_lock->l_readers--;
3252 while (new_lock->l_writers > 0) {
3253 lu_ref_del(&new_lock->l_reference, "writer", new_lock);
3254 lu_ref_del(&new_lock->l_reference, "user", new_lock);
3255 new_lock->l_writers--;
3258 new_lock->l_export = class_export_lock_get(req->rq_export, new_lock);
3259 new_lock->l_blocking_ast = lock->l_blocking_ast;
3260 new_lock->l_completion_ast = lock->l_completion_ast;
3261 new_lock->l_remote_handle = lock->l_remote_handle;
3262 new_lock->l_flags &= ~LDLM_FL_LOCAL;
3264 unlock_res_and_lock(new_lock);
3266 cfs_hash_add(new_lock->l_export->exp_lock_hash,
3267 &new_lock->l_remote_handle,
3268 &new_lock->l_exp_hash);
3270 LDLM_LOCK_RELEASE(new_lock);
3271 lh->mlh_reg_lh.cookie = 0;
3273 RETURN(ELDLM_LOCK_REPLACED);
3276 static void mdt_intent_fixup_resent(struct mdt_thread_info *info,
3277 struct ldlm_lock *new_lock,
3278 struct ldlm_lock **old_lock,
3279 struct mdt_lock_handle *lh)
3281 struct ptlrpc_request *req = mdt_info_req(info);
3282 struct obd_export *exp = req->rq_export;
3283 struct lustre_handle remote_hdl;
3284 struct ldlm_request *dlmreq;
3285 struct ldlm_lock *lock;
3287 if (!(lustre_msg_get_flags(req->rq_reqmsg) & MSG_RESENT))
3290 dlmreq = req_capsule_client_get(info->mti_pill, &RMF_DLM_REQ);
3291 remote_hdl = dlmreq->lock_handle[0];
3293 lock = cfs_hash_lookup(exp->exp_lock_hash, &remote_hdl);
3295 if (lock != new_lock) {
3296 lh->mlh_reg_lh.cookie = lock->l_handle.h_cookie;
3297 lh->mlh_reg_mode = lock->l_granted_mode;
3299 LDLM_DEBUG(lock, "Restoring lock cookie");
3300 DEBUG_REQ(D_DLMTRACE, req,
3301 "restoring lock cookie "LPX64,
3302 lh->mlh_reg_lh.cookie);
3304 *old_lock = LDLM_LOCK_GET(lock);
3305 cfs_hash_put(exp->exp_lock_hash, &lock->l_exp_hash);
3309 cfs_hash_put(exp->exp_lock_hash, &lock->l_exp_hash);
3313 * If the xid matches, then we know this is a resent request, and allow
3314 * it. (It's probably an OPEN, for which we don't send a lock.
3316 if (req_xid_is_last(req))
3320 * This remote handle isn't enqueued, so we never received or processed
3321 * this request. Clear MSG_RESENT, because it can be handled like any
3322 * normal request now.
3324 lustre_msg_clear_flags(req->rq_reqmsg, MSG_RESENT);
3326 DEBUG_REQ(D_DLMTRACE, req, "no existing lock with rhandle "LPX64,
3330 static int mdt_intent_getattr(enum mdt_it_code opcode,
3331 struct mdt_thread_info *info,
3332 struct ldlm_lock **lockp,
3335 struct mdt_lock_handle *lhc = &info->mti_lh[MDT_LH_RMT];
3336 struct ldlm_lock *new_lock = NULL;
3338 struct ldlm_reply *ldlm_rep;
3339 struct ptlrpc_request *req;
3340 struct mdt_body *reqbody;
3341 struct mdt_body *repbody;
3345 reqbody = req_capsule_client_get(info->mti_pill, &RMF_MDT_BODY);
3348 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
3351 info->mti_spec.sp_ck_split = !!(reqbody->valid & OBD_MD_FLCKSPLIT);
3352 info->mti_cross_ref = !!(reqbody->valid & OBD_MD_FLCROSSREF);
3353 repbody->eadatasize = 0;
3354 repbody->aclsize = 0;
3358 child_bits = MDS_INODELOCK_LOOKUP;
3360 case MDT_IT_GETATTR:
3361 child_bits = MDS_INODELOCK_LOOKUP | MDS_INODELOCK_UPDATE;
3363 case MDT_IT_LAYOUT: {
3364 static int printed = 0;
3367 CERROR("layout lock not supported by this version\n");
3370 GOTO(out_shrink, rc = -EINVAL);
3374 CERROR("Unsupported intent (%d)\n", opcode);
3375 GOTO(out_shrink, rc = -EINVAL);
3378 rc = mdt_init_ucred(info, reqbody);
3380 GOTO(out_shrink, rc);
3382 req = info->mti_pill->rc_req;
3383 ldlm_rep = req_capsule_server_get(info->mti_pill, &RMF_DLM_REP);
3384 mdt_set_disposition(info, ldlm_rep, DISP_IT_EXECD);
3386 /* Get lock from request for possible resent case. */
3387 mdt_intent_fixup_resent(info, *lockp, &new_lock, lhc);
3389 ldlm_rep->lock_policy_res2 =
3390 mdt_getattr_name_lock(info, lhc, child_bits, ldlm_rep);
3392 if (mdt_get_disposition(ldlm_rep, DISP_LOOKUP_NEG))
3393 ldlm_rep->lock_policy_res2 = 0;
3394 if (!mdt_get_disposition(ldlm_rep, DISP_LOOKUP_POS) ||
3395 ldlm_rep->lock_policy_res2) {
3396 lhc->mlh_reg_lh.cookie = 0ull;
3397 GOTO(out_ucred, rc = ELDLM_LOCK_ABORTED);
3400 rc = mdt_intent_lock_replace(info, lockp, new_lock, lhc, flags);
3403 mdt_exit_ucred(info);
3405 mdt_client_compatibility(info);
3406 rc2 = mdt_fix_reply(info);
3412 static int mdt_intent_reint(enum mdt_it_code opcode,
3413 struct mdt_thread_info *info,
3414 struct ldlm_lock **lockp,
3417 struct mdt_lock_handle *lhc = &info->mti_lh[MDT_LH_RMT];
3418 struct ldlm_reply *rep = NULL;
3422 static const struct req_format *intent_fmts[REINT_MAX] = {
3423 [REINT_CREATE] = &RQF_LDLM_INTENT_CREATE,
3424 [REINT_OPEN] = &RQF_LDLM_INTENT_OPEN
3429 opc = mdt_reint_opcode(info, intent_fmts);
3433 if (mdt_it_flavor[opcode].it_reint != opc) {
3434 CERROR("Reint code %ld doesn't match intent: %d\n",
3436 RETURN(err_serious(-EPROTO));
3439 /* Get lock from request for possible resent case. */
3440 mdt_intent_fixup_resent(info, *lockp, NULL, lhc);
3442 rc = mdt_reint_internal(info, lhc, opc);
3444 /* Check whether the reply has been packed successfully. */
3445 if (mdt_info_req(info)->rq_repmsg != NULL)
3446 rep = req_capsule_server_get(info->mti_pill, &RMF_DLM_REP);
3448 RETURN(err_serious(-EFAULT));
3450 /* MDC expects this in any case */
3452 mdt_set_disposition(info, rep, DISP_LOOKUP_EXECD);
3454 /* Cross-ref case, the lock should be returned to the client */
3455 if (rc == -EREMOTE) {
3456 LASSERT(lustre_handle_is_used(&lhc->mlh_reg_lh));
3457 rep->lock_policy_res2 = 0;
3458 rc = mdt_intent_lock_replace(info, lockp, NULL, lhc, flags);
3461 rep->lock_policy_res2 = clear_serious(rc);
3463 if (rep->lock_policy_res2 == -ENOENT &&
3464 mdt_get_disposition(rep, DISP_LOOKUP_NEG))
3465 rep->lock_policy_res2 = 0;
3467 if (rc == -ENOTCONN || rc == -ENODEV ||
3468 rc == -EOVERFLOW) { /**< if VBR failure then return error */
3470 * If it is the disconnect error (ENODEV & ENOCONN), the error
3471 * will be returned by rq_status, and client at ptlrpc layer
3472 * will detect this, then disconnect, reconnect the import
3473 * immediately, instead of impacting the following the rpc.
3475 lhc->mlh_reg_lh.cookie = 0ull;
3479 * For other cases, the error will be returned by intent.
3480 * and client will retrieve the result from intent.
3483 * FIXME: when open lock is finished, that should be
3486 if (lustre_handle_is_used(&lhc->mlh_reg_lh)) {
3487 LASSERTF(rc == 0, "Error occurred but lock handle "
3488 "is still in use\n");
3489 rep->lock_policy_res2 = 0;
3490 rc = mdt_intent_lock_replace(info, lockp, NULL, lhc, flags);
3493 lhc->mlh_reg_lh.cookie = 0ull;
3494 RETURN(ELDLM_LOCK_ABORTED);
3499 static int mdt_intent_code(long itcode)
3507 case IT_OPEN|IT_CREAT:
3514 rc = MDT_IT_READDIR;
3517 rc = MDT_IT_GETATTR;
3529 rc = MDT_IT_GETXATTR;
3535 CERROR("Unknown intent opcode: %ld\n", itcode);
3542 static int mdt_intent_opc(long itopc, struct mdt_thread_info *info,
3543 struct ldlm_lock **lockp, int flags)
3545 struct req_capsule *pill;
3546 struct mdt_it_flavor *flv;
3551 opc = mdt_intent_code(itopc);
3555 pill = info->mti_pill;
3556 flv = &mdt_it_flavor[opc];
3558 if (flv->it_fmt != NULL)
3559 req_capsule_extend(pill, flv->it_fmt);
3561 rc = mdt_unpack_req_pack_rep(info, flv->it_flags);
3563 struct ptlrpc_request *req = mdt_info_req(info);
3564 if (flv->it_flags & MUTABOR &&
3565 req->rq_export->exp_connect_flags & OBD_CONNECT_RDONLY)
3568 if (rc == 0 && flv->it_act != NULL) {
3569 /* execute policy */
3570 rc = flv->it_act(opc, info, lockp, flags);
3577 static int mdt_intent_policy(struct ldlm_namespace *ns,
3578 struct ldlm_lock **lockp, void *req_cookie,
3579 ldlm_mode_t mode, int flags, void *data)
3581 struct mdt_thread_info *info;
3582 struct ptlrpc_request *req = req_cookie;
3583 struct ldlm_intent *it;
3584 struct req_capsule *pill;
3589 LASSERT(req != NULL);
3591 info = lu_context_key_get(&req->rq_svc_thread->t_env->le_ctx,
3593 LASSERT(info != NULL);
3594 pill = info->mti_pill;
3595 LASSERT(pill->rc_req == req);
3597 if (req->rq_reqmsg->lm_bufcount > DLM_INTENT_IT_OFF) {
3598 req_capsule_extend(pill, &RQF_LDLM_INTENT);
3599 it = req_capsule_client_get(pill, &RMF_LDLM_INTENT);
3601 rc = mdt_intent_opc(it->opc, info, lockp, flags);
3605 /* Lock without inodebits makes no sense and will oops
3606 * later in ldlm. Let's check it now to see if we have
3607 * ibits corrupted somewhere in mdt_intent_opc().
3608 * The case for client miss to set ibits has been
3609 * processed by others. */
3610 LASSERT(ergo(info->mti_dlm_req->lock_desc.l_resource.\
3611 lr_type == LDLM_IBITS,
3612 info->mti_dlm_req->lock_desc.\
3613 l_policy_data.l_inodebits.bits != 0));
3615 rc = err_serious(-EFAULT);
3617 /* No intent was provided */
3618 LASSERT(pill->rc_fmt == &RQF_LDLM_ENQUEUE);
3619 rc = req_capsule_server_pack(pill);
3621 rc = err_serious(rc);
3626 static int mdt_seq_fini(const struct lu_env *env,
3627 struct mdt_device *m)
3629 struct md_site *ms = mdt_md_site(m);
3633 if (ms->ms_server_seq) {
3634 seq_server_fini(ms->ms_server_seq, env);
3635 OBD_FREE_PTR(ms->ms_server_seq);
3636 ms->ms_server_seq = NULL;
3639 if (ms->ms_control_seq) {
3640 seq_server_fini(ms->ms_control_seq, env);
3641 OBD_FREE_PTR(ms->ms_control_seq);
3642 ms->ms_control_seq = NULL;
3645 if (ms->ms_client_seq) {
3646 seq_client_fini(ms->ms_client_seq);
3647 OBD_FREE_PTR(ms->ms_client_seq);
3648 ms->ms_client_seq = NULL;
3655 static int mdt_seq_init(const struct lu_env *env,
3657 struct mdt_device *m)
3664 ms = mdt_md_site(m);
3667 * This is sequence-controller node. Init seq-controller server on local
3670 if (ms->ms_node_id == 0) {
3671 LASSERT(ms->ms_control_seq == NULL);
3673 OBD_ALLOC_PTR(ms->ms_control_seq);
3674 if (ms->ms_control_seq == NULL)
3677 rc = seq_server_init(ms->ms_control_seq,
3678 m->mdt_bottom, uuid,
3679 LUSTRE_SEQ_CONTROLLER,
3684 GOTO(out_seq_fini, rc);
3686 OBD_ALLOC_PTR(ms->ms_client_seq);
3687 if (ms->ms_client_seq == NULL)
3688 GOTO(out_seq_fini, rc = -ENOMEM);
3690 OBD_ALLOC(prefix, MAX_OBD_NAME + 5);
3691 if (prefix == NULL) {
3692 OBD_FREE_PTR(ms->ms_client_seq);
3693 GOTO(out_seq_fini, rc = -ENOMEM);
3696 snprintf(prefix, MAX_OBD_NAME + 5, "ctl-%s",
3700 * Init seq-controller client after seq-controller server is
3701 * ready. Pass ms->ms_control_seq to it for direct talking.
3703 rc = seq_client_init(ms->ms_client_seq, NULL,
3704 LUSTRE_SEQ_METADATA, prefix,
3705 ms->ms_control_seq);
3706 OBD_FREE(prefix, MAX_OBD_NAME + 5);
3709 GOTO(out_seq_fini, rc);
3712 /* Init seq-server on local MDT */
3713 LASSERT(ms->ms_server_seq == NULL);
3715 OBD_ALLOC_PTR(ms->ms_server_seq);
3716 if (ms->ms_server_seq == NULL)
3717 GOTO(out_seq_fini, rc = -ENOMEM);
3719 rc = seq_server_init(ms->ms_server_seq,
3720 m->mdt_bottom, uuid,
3725 GOTO(out_seq_fini, rc = -ENOMEM);
3727 /* Assign seq-controller client to local seq-server. */
3728 if (ms->ms_node_id == 0) {
3729 LASSERT(ms->ms_client_seq != NULL);
3731 rc = seq_server_set_cli(ms->ms_server_seq,
3739 mdt_seq_fini(env, m);
3744 * Init client sequence manager which is used by local MDS to talk to sequence
3745 * controller on remote node.
3747 static int mdt_seq_init_cli(const struct lu_env *env,
3748 struct mdt_device *m,
3749 struct lustre_cfg *cfg)
3751 struct md_site *ms = mdt_md_site(m);
3752 struct obd_device *mdc;
3753 struct obd_uuid *uuidp, *mdcuuidp;
3754 char *uuid_str, *mdc_uuid_str;
3757 struct mdt_thread_info *info;
3758 char *p, *index_string = lustre_cfg_string(cfg, 2);
3761 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
3762 uuidp = &info->mti_u.uuid[0];
3763 mdcuuidp = &info->mti_u.uuid[1];
3765 LASSERT(index_string);
3767 index = simple_strtol(index_string, &p, 10);
3769 CERROR("Invalid index in lustre_cgf, offset 2\n");
3773 /* check if this is adding the first MDC and controller is not yet
3775 if (index != 0 || ms->ms_client_seq)
3778 uuid_str = lustre_cfg_string(cfg, 1);
3779 mdc_uuid_str = lustre_cfg_string(cfg, 4);
3780 obd_str2uuid(uuidp, uuid_str);
3781 obd_str2uuid(mdcuuidp, mdc_uuid_str);
3783 mdc = class_find_client_obd(uuidp, LUSTRE_MDC_NAME, mdcuuidp);
3785 CERROR("can't find controller MDC by uuid %s\n",
3788 } else if (!mdc->obd_set_up) {
3789 CERROR("target %s not set up\n", mdc->obd_name);
3792 LASSERT(ms->ms_control_exp);
3793 OBD_ALLOC_PTR(ms->ms_client_seq);
3794 if (ms->ms_client_seq != NULL) {
3797 OBD_ALLOC(prefix, MAX_OBD_NAME + 5);
3801 snprintf(prefix, MAX_OBD_NAME + 5, "ctl-%s",
3804 rc = seq_client_init(ms->ms_client_seq,
3806 LUSTRE_SEQ_METADATA,
3808 OBD_FREE(prefix, MAX_OBD_NAME + 5);
3815 LASSERT(ms->ms_server_seq != NULL);
3816 rc = seq_server_set_cli(ms->ms_server_seq, ms->ms_client_seq,
3823 static void mdt_seq_fini_cli(struct mdt_device *m)
3829 ms = mdt_md_site(m);
3832 if (ms->ms_server_seq)
3833 seq_server_set_cli(ms->ms_server_seq,
3836 if (ms->ms_control_exp) {
3837 class_export_put(ms->ms_control_exp);
3838 ms->ms_control_exp = NULL;
3847 static int mdt_fld_fini(const struct lu_env *env,
3848 struct mdt_device *m)
3850 struct md_site *ms = mdt_md_site(m);
3853 if (ms && ms->ms_server_fld) {
3854 fld_server_fini(ms->ms_server_fld, env);
3855 OBD_FREE_PTR(ms->ms_server_fld);
3856 ms->ms_server_fld = NULL;
3862 static int mdt_fld_init(const struct lu_env *env,
3864 struct mdt_device *m)
3870 ms = mdt_md_site(m);
3872 OBD_ALLOC_PTR(ms->ms_server_fld);
3873 if (ms->ms_server_fld == NULL)
3874 RETURN(rc = -ENOMEM);
3876 rc = fld_server_init(ms->ms_server_fld,
3877 m->mdt_bottom, uuid,
3878 env, ms->ms_node_id);
3880 OBD_FREE_PTR(ms->ms_server_fld);
3881 ms->ms_server_fld = NULL;
3888 /* device init/fini methods */
3889 static void mdt_stop_ptlrpc_service(struct mdt_device *m)
3892 if (m->mdt_regular_service != NULL) {
3893 ptlrpc_unregister_service(m->mdt_regular_service);
3894 m->mdt_regular_service = NULL;
3896 if (m->mdt_readpage_service != NULL) {
3897 ptlrpc_unregister_service(m->mdt_readpage_service);
3898 m->mdt_readpage_service = NULL;
3900 if (m->mdt_xmds_service != NULL) {
3901 ptlrpc_unregister_service(m->mdt_xmds_service);
3902 m->mdt_xmds_service = NULL;
3904 if (m->mdt_setattr_service != NULL) {
3905 ptlrpc_unregister_service(m->mdt_setattr_service);
3906 m->mdt_setattr_service = NULL;
3908 if (m->mdt_mdsc_service != NULL) {
3909 ptlrpc_unregister_service(m->mdt_mdsc_service);
3910 m->mdt_mdsc_service = NULL;
3912 if (m->mdt_mdss_service != NULL) {
3913 ptlrpc_unregister_service(m->mdt_mdss_service);
3914 m->mdt_mdss_service = NULL;
3916 if (m->mdt_dtss_service != NULL) {
3917 ptlrpc_unregister_service(m->mdt_dtss_service);
3918 m->mdt_dtss_service = NULL;
3920 if (m->mdt_fld_service != NULL) {
3921 ptlrpc_unregister_service(m->mdt_fld_service);
3922 m->mdt_fld_service = NULL;
3927 static int mdt_start_ptlrpc_service(struct mdt_device *m)
3929 static struct ptlrpc_service_conf conf;
3930 cfs_proc_dir_entry_t *procfs_entry;
3934 m->mdt_ldlm_client = &m->mdt_md_dev.md_lu_dev.ld_obd->obd_ldlm_client;
3935 ptlrpc_init_client(LDLM_CB_REQUEST_PORTAL, LDLM_CB_REPLY_PORTAL,
3936 "mdt_ldlm_client", m->mdt_ldlm_client);
3938 procfs_entry = m->mdt_md_dev.md_lu_dev.ld_obd->obd_proc_entry;
3940 conf = (typeof(conf)) {
3941 .psc_name = LUSTRE_MDT_NAME,
3942 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
3944 .bc_nbufs = MDS_NBUFS,
3945 .bc_buf_size = MDS_BUFSIZE,
3946 .bc_req_max_size = MDS_MAXREQSIZE,
3947 .bc_rep_max_size = MDS_MAXREPSIZE,
3948 .bc_req_portal = MDS_REQUEST_PORTAL,
3949 .bc_rep_portal = MDC_REPLY_PORTAL,
3952 * We'd like to have a mechanism to set this on a per-device
3953 * basis, but alas...
3956 .tc_thr_name = LUSTRE_MDT_NAME,
3957 .tc_nthrs_min = MDT_MIN_THREADS,
3958 .tc_nthrs_max = MDT_MAX_THREADS,
3959 .tc_nthrs_user = mdt_num_threads,
3960 .tc_ctx_tags = LCT_MD_THREAD,
3963 .so_req_handler = mdt_regular_handle,
3964 .so_req_printer = target_print_req,
3967 m->mdt_regular_service = ptlrpc_register_service(&conf, procfs_entry);
3968 if (IS_ERR(m->mdt_regular_service)) {
3969 rc = PTR_ERR(m->mdt_regular_service);
3970 CERROR("failed to start regular mdt service: %d\n", rc);
3971 m->mdt_regular_service = NULL;
3977 * readpage service configuration. Parameters have to be adjusted,
3980 memset(&conf, 0, sizeof(conf));
3981 conf = (typeof(conf)) {
3982 .psc_name = LUSTRE_MDT_NAME "_readpage",
3983 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
3985 .bc_nbufs = MDS_NBUFS,
3986 .bc_buf_size = MDS_BUFSIZE,
3987 .bc_req_max_size = MDS_MAXREQSIZE,
3988 .bc_rep_max_size = MDS_MAXREPSIZE,
3989 .bc_req_portal = MDS_READPAGE_PORTAL,
3990 .bc_rep_portal = MDC_REPLY_PORTAL,
3993 .tc_thr_name = "mdt_rdpg",
3994 .tc_nthrs_min = MDT_MIN_THREADS,
3995 .tc_nthrs_max = MDT_MAX_THREADS,
3996 .tc_nthrs_user = mdt_num_threads,
3997 .tc_ctx_tags = LCT_MD_THREAD,
4000 .so_req_handler = mdt_readpage_handle,
4001 .so_req_printer = target_print_req,
4004 m->mdt_readpage_service = ptlrpc_register_service(&conf, procfs_entry);
4005 if (IS_ERR(m->mdt_readpage_service)) {
4006 rc = PTR_ERR(m->mdt_readpage_service);
4007 CERROR("failed to start readpage service: %d\n", rc);
4008 m->mdt_readpage_service = NULL;
4010 GOTO(err_mdt_svc, rc);
4014 * setattr service configuration.
4016 * XXX To keep the compatibility with old client(< 2.2), we need to
4017 * preserve this portal for a certain time, it should be removed
4018 * eventually. LU-617.
4020 memset(&conf, 0, sizeof(conf));
4021 conf = (typeof(conf)) {
4022 .psc_name = LUSTRE_MDT_NAME "_setattr",
4023 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
4025 .bc_nbufs = MDS_NBUFS,
4026 .bc_buf_size = MDS_BUFSIZE,
4027 .bc_req_max_size = MDS_MAXREQSIZE,
4028 .bc_rep_max_size = MDS_MAXREPSIZE,
4029 .bc_req_portal = MDS_SETATTR_PORTAL,
4030 .bc_rep_portal = MDC_REPLY_PORTAL,
4033 .tc_thr_name = "mdt_attr",
4034 .tc_nthrs_min = MDT_MIN_THREADS,
4035 .tc_nthrs_max = MDT_MAX_THREADS,
4036 .tc_nthrs_user = mdt_num_threads,
4037 .tc_ctx_tags = LCT_MD_THREAD,
4040 .so_req_handler = mdt_regular_handle,
4041 .so_req_printer = target_print_req,
4044 m->mdt_setattr_service = ptlrpc_register_service(&conf, procfs_entry);
4045 if (IS_ERR(m->mdt_setattr_service)) {
4046 rc = PTR_ERR(m->mdt_setattr_service);
4047 CERROR("failed to start setattr service: %d\n", rc);
4048 m->mdt_setattr_service = NULL;
4050 GOTO(err_mdt_svc, rc);
4054 * sequence controller service configuration
4056 memset(&conf, 0, sizeof(conf));
4057 conf = (typeof(conf)) {
4058 .psc_name = LUSTRE_MDT_NAME "_mdsc",
4059 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
4061 .bc_nbufs = MDS_NBUFS,
4062 .bc_buf_size = MDS_BUFSIZE,
4063 .bc_req_max_size = SEQ_MAXREQSIZE,
4064 .bc_rep_max_size = SEQ_MAXREPSIZE,
4065 .bc_req_portal = SEQ_CONTROLLER_PORTAL,
4066 .bc_rep_portal = MDC_REPLY_PORTAL,
4069 .tc_thr_name = "mdt_mdsc",
4070 .tc_nthrs_min = MDT_MIN_THREADS,
4071 .tc_nthrs_max = MDT_MAX_THREADS,
4072 .tc_nthrs_user = mdt_num_threads,
4073 .tc_ctx_tags = LCT_MD_THREAD,
4076 .so_req_handler = mdt_mdsc_handle,
4077 .so_req_printer = target_print_req,
4080 m->mdt_mdsc_service = ptlrpc_register_service(&conf, procfs_entry);
4081 if (IS_ERR(m->mdt_mdsc_service)) {
4082 rc = PTR_ERR(m->mdt_mdsc_service);
4083 CERROR("failed to start seq controller service: %d\n", rc);
4084 m->mdt_mdsc_service = NULL;
4086 GOTO(err_mdt_svc, rc);
4090 * metadata sequence server service configuration
4092 memset(&conf, 0, sizeof(conf));
4093 conf = (typeof(conf)) {
4094 .psc_name = LUSTRE_MDT_NAME "_mdss",
4095 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
4097 .bc_nbufs = MDS_NBUFS,
4098 .bc_buf_size = MDS_BUFSIZE,
4099 .bc_req_max_size = SEQ_MAXREQSIZE,
4100 .bc_rep_max_size = SEQ_MAXREPSIZE,
4101 .bc_req_portal = SEQ_METADATA_PORTAL,
4102 .bc_rep_portal = MDC_REPLY_PORTAL,
4105 .tc_thr_name = "mdt_mdss",
4106 .tc_nthrs_min = MDT_MIN_THREADS,
4107 .tc_nthrs_max = MDT_MAX_THREADS,
4108 .tc_nthrs_user = mdt_num_threads,
4109 .tc_ctx_tags = LCT_MD_THREAD | LCT_DT_THREAD
4112 .so_req_handler = mdt_mdss_handle,
4113 .so_req_printer = target_print_req,
4116 m->mdt_mdss_service = ptlrpc_register_service(&conf, procfs_entry);
4117 if (IS_ERR(m->mdt_mdss_service)) {
4118 rc = PTR_ERR(m->mdt_mdss_service);
4119 CERROR("failed to start metadata seq server service: %d\n", rc);
4120 m->mdt_mdss_service = NULL;
4122 GOTO(err_mdt_svc, rc);
4126 * Data sequence server service configuration. We want to have really
4127 * cluster-wide sequences space. This is why we start only one sequence
4128 * controller which manages space.
4130 memset(&conf, 0, sizeof(conf));
4131 conf = (typeof(conf)) {
4132 .psc_name = LUSTRE_MDT_NAME "_dtss",
4133 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
4135 .bc_nbufs = MDS_NBUFS,
4136 .bc_buf_size = MDS_BUFSIZE,
4137 .bc_req_max_size = SEQ_MAXREQSIZE,
4138 .bc_rep_max_size = SEQ_MAXREPSIZE,
4139 .bc_req_portal = SEQ_DATA_PORTAL,
4140 .bc_rep_portal = OSC_REPLY_PORTAL,
4143 .tc_thr_name = "mdt_dtss",
4144 .tc_nthrs_min = MDT_MIN_THREADS,
4145 .tc_nthrs_max = MDT_MAX_THREADS,
4146 .tc_nthrs_user = mdt_num_threads,
4147 .tc_ctx_tags = LCT_MD_THREAD | LCT_DT_THREAD
4150 .so_req_handler = mdt_dtss_handle,
4151 .so_req_printer = target_print_req,
4154 m->mdt_dtss_service = ptlrpc_register_service(&conf, procfs_entry);
4155 if (IS_ERR(m->mdt_dtss_service)) {
4156 rc = PTR_ERR(m->mdt_dtss_service);
4157 CERROR("failed to start data seq server service: %d\n", rc);
4158 m->mdt_dtss_service = NULL;
4160 GOTO(err_mdt_svc, rc);
4163 /* FLD service start */
4164 memset(&conf, 0, sizeof(conf));
4165 conf = (typeof(conf)) {
4166 .psc_name = LUSTRE_MDT_NAME "_fld",
4167 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
4169 .bc_nbufs = MDS_NBUFS,
4170 .bc_buf_size = MDS_BUFSIZE,
4171 .bc_req_max_size = FLD_MAXREQSIZE,
4172 .bc_rep_max_size = FLD_MAXREPSIZE,
4173 .bc_req_portal = FLD_REQUEST_PORTAL,
4174 .bc_rep_portal = MDC_REPLY_PORTAL,
4177 .tc_thr_name = "mdt_fld",
4178 .tc_nthrs_min = MDT_MIN_THREADS,
4179 .tc_nthrs_max = MDT_MAX_THREADS,
4180 .tc_nthrs_user = mdt_num_threads,
4181 .tc_ctx_tags = LCT_DT_THREAD | LCT_MD_THREAD
4184 .so_req_handler = mdt_fld_handle,
4185 .so_req_printer = target_print_req,
4188 m->mdt_fld_service = ptlrpc_register_service(&conf, procfs_entry);
4189 if (IS_ERR(m->mdt_fld_service)) {
4190 rc = PTR_ERR(m->mdt_fld_service);
4191 CERROR("failed to start fld service: %d\n", rc);
4192 m->mdt_fld_service = NULL;
4194 GOTO(err_mdt_svc, rc);
4198 * mds-mds service configuration. Separate portal is used to allow
4199 * mds-mds requests be not blocked during recovery.
4201 memset(&conf, 0, sizeof(conf));
4202 conf = (typeof(conf)) {
4203 .psc_name = LUSTRE_MDT_NAME "_mds",
4204 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
4206 .bc_nbufs = MDS_NBUFS,
4207 .bc_buf_size = MDS_BUFSIZE,
4208 .bc_req_max_size = MDS_MAXREQSIZE,
4209 .bc_rep_max_size = MDS_MAXREPSIZE,
4210 .bc_req_portal = MDS_MDS_PORTAL,
4211 .bc_rep_portal = MDC_REPLY_PORTAL,
4214 .tc_thr_name = "mdt_mds",
4215 .tc_nthrs_min = MDT_MIN_THREADS,
4216 .tc_nthrs_max = MDT_MAX_THREADS,
4217 .tc_nthrs_user = mdt_num_threads,
4218 .tc_ctx_tags = LCT_MD_THREAD,
4221 .so_req_handler = mdt_xmds_handle,
4222 .so_req_printer = target_print_req,
4225 m->mdt_xmds_service = ptlrpc_register_service(&conf, procfs_entry);
4226 if (IS_ERR(m->mdt_xmds_service)) {
4227 rc = PTR_ERR(m->mdt_xmds_service);
4228 CERROR("failed to start xmds service: %d\n", rc);
4229 m->mdt_xmds_service = NULL;
4231 GOTO(err_mdt_svc, rc);
4237 mdt_stop_ptlrpc_service(m);
4242 static void mdt_stack_fini(const struct lu_env *env,
4243 struct mdt_device *m, struct lu_device *top)
4245 struct obd_device *obd = mdt2obd_dev(m);
4246 struct lustre_cfg_bufs *bufs;
4247 struct lustre_cfg *lcfg;
4248 struct mdt_thread_info *info;
4252 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
4253 LASSERT(info != NULL);
4255 bufs = &info->mti_u.bufs;
4256 /* process cleanup, pass mdt obd name to get obd umount flags */
4257 lustre_cfg_bufs_reset(bufs, obd->obd_name);
4262 lustre_cfg_bufs_set_string(bufs, 1, flags);
4263 lcfg = lustre_cfg_new(LCFG_CLEANUP, bufs);
4265 CERROR("Cannot alloc lcfg!\n");
4270 top->ld_ops->ldo_process_config(env, top, lcfg);
4271 lustre_cfg_free(lcfg);
4273 lu_stack_fini(env, top);
4274 m->mdt_child = NULL;
4275 m->mdt_bottom = NULL;
4278 static struct lu_device *mdt_layer_setup(struct lu_env *env,
4279 const char *typename,
4280 struct lu_device *child,
4281 struct lustre_cfg *cfg)
4283 const char *dev = lustre_cfg_string(cfg, 0);
4284 struct obd_type *type;
4285 struct lu_device_type *ldt;
4286 struct lu_device *d;
4291 type = class_get_type(typename);
4293 CERROR("Unknown type: '%s'\n", typename);
4294 GOTO(out, rc = -ENODEV);
4297 rc = lu_env_refill((struct lu_env *)env);
4299 CERROR("Failure to refill session: '%d'\n", rc);
4305 CERROR("type: '%s'\n", typename);
4306 GOTO(out_type, rc = -EINVAL);
4309 ldt->ldt_obd_type = type;
4310 d = ldt->ldt_ops->ldto_device_alloc(env, ldt, cfg);
4312 CERROR("Cannot allocate device: '%s'\n", typename);
4313 GOTO(out_type, rc = -ENODEV);
4316 LASSERT(child->ld_site);
4317 d->ld_site = child->ld_site;
4320 rc = ldt->ldt_ops->ldto_device_init(env, d, dev, child);
4322 CERROR("can't init device '%s', rc %d\n", typename, rc);
4323 GOTO(out_alloc, rc);
4326 lu_ref_add(&d->ld_reference, "lu-stack", &lu_site_init);
4328 cfs_spin_lock(&d->ld_site->ls_ld_lock);
4329 cfs_list_add_tail(&d->ld_linkage, &d->ld_site->ls_ld_linkage);
4330 cfs_spin_unlock(&d->ld_site->ls_ld_lock);
4334 ldt->ldt_ops->ldto_device_free(env, d);
4337 class_put_type(type);
4342 static int mdt_stack_init(struct lu_env *env,
4343 struct mdt_device *m,
4344 struct lustre_cfg *cfg,
4345 struct lustre_mount_info *lmi)
4347 struct lu_device *d = &m->mdt_md_dev.md_lu_dev;
4348 struct lu_device *tmp;
4349 struct md_device *md;
4350 struct lu_device *child_lu_dev;
4354 /* init the stack */
4355 tmp = mdt_layer_setup(env, LUSTRE_OSD_NAME, d, cfg);
4357 RETURN(PTR_ERR(tmp));
4359 m->mdt_bottom = lu2dt_dev(tmp);
4361 tmp = mdt_layer_setup(env, LUSTRE_MDD_NAME, d, cfg);
4363 GOTO(out, rc = PTR_ERR(tmp));
4368 tmp = mdt_layer_setup(env, LUSTRE_CMM_NAME, d, cfg);
4370 GOTO(out, rc = PTR_ERR(tmp));
4373 /*set mdd upcall device*/
4374 md_upcall_dev_set(md, lu2md_dev(d));
4377 /*set cmm upcall device*/
4378 md_upcall_dev_set(md, &m->mdt_md_dev);
4380 m->mdt_child = lu2md_dev(d);
4382 /* process setup config */
4383 tmp = &m->mdt_md_dev.md_lu_dev;
4384 rc = tmp->ld_ops->ldo_process_config(env, tmp, cfg);
4388 /* initialize local objects */
4389 child_lu_dev = &m->mdt_child->md_lu_dev;
4391 rc = child_lu_dev->ld_ops->ldo_prepare(env,
4392 &m->mdt_md_dev.md_lu_dev,
4395 /* fini from last known good lu_device */
4397 mdt_stack_fini(env, m, d);
4403 * setup CONFIG_ORIG context, used to access local config log.
4404 * this may need to be rewrite as part of llog rewrite for lu-api.
4406 static int mdt_obd_llog_setup(struct obd_device *obd,
4407 struct lustre_sb_info *lsi)
4411 LASSERT(obd->obd_fsops == NULL);
4413 obd->obd_fsops = fsfilt_get_ops(MT_STR(lsi->lsi_ldd));
4414 if (IS_ERR(obd->obd_fsops))
4415 return PTR_ERR(obd->obd_fsops);
4417 rc = fsfilt_setup(obd, lsi->lsi_srv_mnt->mnt_sb);
4419 fsfilt_put_ops(obd->obd_fsops);
4423 OBD_SET_CTXT_MAGIC(&obd->obd_lvfs_ctxt);
4424 obd->obd_lvfs_ctxt.pwdmnt = lsi->lsi_srv_mnt;
4425 obd->obd_lvfs_ctxt.pwd = lsi->lsi_srv_mnt->mnt_root;
4426 obd->obd_lvfs_ctxt.fs = get_ds();
4428 rc = llog_setup(obd, &obd->obd_olg, LLOG_CONFIG_ORIG_CTXT, obd,
4429 0, NULL, &llog_lvfs_ops);
4431 CERROR("llog_setup() failed: %d\n", rc);
4432 fsfilt_put_ops(obd->obd_fsops);
4438 static void mdt_obd_llog_cleanup(struct obd_device *obd)
4440 struct llog_ctxt *ctxt;
4442 ctxt = llog_get_context(obd, LLOG_CONFIG_ORIG_CTXT);
4446 if (obd->obd_fsops) {
4447 fsfilt_put_ops(obd->obd_fsops);
4448 obd->obd_fsops = NULL;
4452 static void mdt_fini(const struct lu_env *env, struct mdt_device *m)
4454 struct md_device *next = m->mdt_child;
4455 struct lu_device *d = &m->mdt_md_dev.md_lu_dev;
4456 struct lu_site *ls = d->ld_site;
4457 struct obd_device *obd = mdt2obd_dev(m);
4460 target_recovery_fini(obd);
4462 ping_evictor_stop();
4464 mdt_stop_ptlrpc_service(m);
4465 mdt_llog_ctxt_unclone(env, m, LLOG_CHANGELOG_ORIG_CTXT);
4466 mdt_obd_llog_cleanup(obd);
4467 obd_exports_barrier(obd);
4468 obd_zombie_barrier();
4472 #ifdef HAVE_QUOTA_SUPPORT
4473 next->md_ops->mdo_quota.mqo_cleanup(env, next);
4475 lut_fini(env, &m->mdt_lut);
4476 mdt_fs_cleanup(env, m);
4477 upcall_cache_cleanup(m->mdt_identity_cache);
4478 m->mdt_identity_cache = NULL;
4480 if (m->mdt_namespace != NULL) {
4481 ldlm_namespace_free(m->mdt_namespace, NULL,
4482 d->ld_obd->obd_force);
4483 d->ld_obd->obd_namespace = m->mdt_namespace = NULL;
4486 cfs_free_nidlist(&m->mdt_nosquash_nids);
4487 if (m->mdt_nosquash_str) {
4488 OBD_FREE(m->mdt_nosquash_str, m->mdt_nosquash_strlen);
4489 m->mdt_nosquash_str = NULL;
4490 m->mdt_nosquash_strlen = 0;
4493 mdt_seq_fini(env, m);
4494 mdt_seq_fini_cli(m);
4495 mdt_fld_fini(env, m);
4496 sptlrpc_rule_set_free(&m->mdt_sptlrpc_rset);
4498 next->md_ops->mdo_init_capa_ctxt(env, next, 0, 0, 0, NULL);
4499 cfs_timer_disarm(&m->mdt_ck_timer);
4500 mdt_ck_thread_stop(m);
4505 mdt_stack_fini(env, m, md2lu_dev(m->mdt_child));
4508 struct md_site *mite;
4511 mite = lu_site2md(ls);
4515 LASSERT(cfs_atomic_read(&d->ld_ref) == 0);
4520 static int mdt_adapt_sptlrpc_conf(struct obd_device *obd, int initial)
4522 struct mdt_device *m = mdt_dev(obd->obd_lu_dev);
4523 struct sptlrpc_rule_set tmp_rset;
4526 sptlrpc_rule_set_init(&tmp_rset);
4527 rc = sptlrpc_conf_target_get_rules(obd, &tmp_rset, initial);
4529 CERROR("mdt %s: failed get sptlrpc rules: %d\n",
4534 sptlrpc_target_update_exp_flavor(obd, &tmp_rset);
4536 cfs_write_lock(&m->mdt_sptlrpc_lock);
4537 sptlrpc_rule_set_free(&m->mdt_sptlrpc_rset);
4538 m->mdt_sptlrpc_rset = tmp_rset;
4539 cfs_write_unlock(&m->mdt_sptlrpc_lock);
4544 int mdt_postrecov(const struct lu_env *, struct mdt_device *);
4546 static int mdt_init0(const struct lu_env *env, struct mdt_device *m,
4547 struct lu_device_type *ldt, struct lustre_cfg *cfg)
4549 struct mdt_thread_info *info;
4550 struct obd_device *obd;
4551 const char *dev = lustre_cfg_string(cfg, 0);
4552 const char *num = lustre_cfg_string(cfg, 2);
4553 struct lustre_mount_info *lmi = NULL;
4554 struct lustre_sb_info *lsi;
4555 struct lustre_disk_data *ldd;
4557 struct md_site *mite;
4558 const char *identity_upcall = "NONE";
4559 struct md_device *next;
4565 md_device_init(&m->mdt_md_dev, ldt);
4567 * Environment (env) might be missing mdt_thread_key values at that
4568 * point, if device is allocated when mdt_thread_key is in QUIESCENT
4571 * Usually device allocation path doesn't use module key values, but
4572 * mdt has to do a lot of work here, so allocate key value.
4574 rc = lu_env_refill((struct lu_env *)env);
4578 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
4579 LASSERT(info != NULL);
4581 obd = class_name2obd(dev);
4582 LASSERT(obd != NULL);
4584 m->mdt_max_mdsize = MAX_MD_SIZE; /* 4 stripes */
4585 m->mdt_max_cookiesize = sizeof(struct llog_cookie);
4587 m->mdt_som_conf = 0;
4589 m->mdt_opts.mo_cos = MDT_COS_DEFAULT;
4590 lmi = server_get_mount_2(dev);
4592 CERROR("Cannot get mount info for %s!\n", dev);
4595 lsi = s2lsi(lmi->lmi_sb);
4596 /* CMD is supported only in IAM mode */
4599 node_id = simple_strtol(num, NULL, 10);
4600 if (!(ldd->ldd_flags & LDD_F_IAM_DIR) && node_id) {
4601 CERROR("CMD Operation not allowed in IOP mode\n");
4602 GOTO(err_lmi, rc = -EINVAL);
4605 obd->u.obt.obt_magic = OBT_MAGIC;
4608 cfs_rwlock_init(&m->mdt_sptlrpc_lock);
4609 sptlrpc_rule_set_init(&m->mdt_sptlrpc_rset);
4611 cfs_spin_lock_init(&m->mdt_ioepoch_lock);
4612 m->mdt_opts.mo_compat_resname = 0;
4613 m->mdt_opts.mo_mds_capa = 1;
4614 m->mdt_opts.mo_oss_capa = 1;
4615 m->mdt_capa_timeout = CAPA_TIMEOUT;
4616 m->mdt_capa_alg = CAPA_HMAC_ALG_SHA1;
4617 m->mdt_ck_timeout = CAPA_KEY_TIMEOUT;
4618 m->mdt_squash_uid = 0;
4619 m->mdt_squash_gid = 0;
4620 CFS_INIT_LIST_HEAD(&m->mdt_nosquash_nids);
4621 m->mdt_nosquash_str = NULL;
4622 m->mdt_nosquash_strlen = 0;
4623 cfs_init_rwsem(&m->mdt_squash_sem);
4625 OBD_ALLOC_PTR(mite);
4627 GOTO(err_lmi, rc = -ENOMEM);
4631 m->mdt_md_dev.md_lu_dev.ld_ops = &mdt_lu_ops;
4632 m->mdt_md_dev.md_lu_dev.ld_obd = obd;
4633 /* set this lu_device to obd, because error handling need it */
4634 obd->obd_lu_dev = &m->mdt_md_dev.md_lu_dev;
4636 rc = lu_site_init(s, &m->mdt_md_dev.md_lu_dev);
4638 CERROR("Can't init lu_site, rc %d\n", rc);
4639 GOTO(err_free_site, rc);
4642 /* set server index */
4643 lu_site2md(s)->ms_node_id = node_id;
4645 /* failover is the default
4646 * FIXME: we do not failout mds0/mgs, which may cause some problems.
4647 * assumed whose ms_node_id == 0 XXX
4649 obd->obd_replayable = 1;
4650 /* No connection accepted until configurations will finish */
4651 obd->obd_no_conn = 1;
4653 if (cfg->lcfg_bufcount > 4 && LUSTRE_CFG_BUFLEN(cfg, 4) > 0) {
4654 char *str = lustre_cfg_string(cfg, 4);
4655 if (strchr(str, 'n')) {
4656 CWARN("%s: recovery disabled\n", obd->obd_name);
4657 obd->obd_replayable = 0;
4661 /* init the stack */
4662 rc = mdt_stack_init((struct lu_env *)env, m, cfg, lmi);
4664 CERROR("Can't init device stack, rc %d\n", rc);
4665 GOTO(err_lu_site, rc);
4668 rc = lut_init(env, &m->mdt_lut, obd, m->mdt_bottom);
4670 GOTO(err_fini_stack, rc);
4672 rc = mdt_fld_init(env, obd->obd_name, m);
4676 rc = mdt_seq_init(env, obd->obd_name, m);
4678 GOTO(err_fini_fld, rc);
4680 snprintf(info->mti_u.ns_name, sizeof info->mti_u.ns_name,
4681 LUSTRE_MDT_NAME"-%p", m);
4682 m->mdt_namespace = ldlm_namespace_new(obd, info->mti_u.ns_name,
4683 LDLM_NAMESPACE_SERVER,
4684 LDLM_NAMESPACE_GREEDY,
4686 if (m->mdt_namespace == NULL)
4687 GOTO(err_fini_seq, rc = -ENOMEM);
4689 ldlm_register_intent(m->mdt_namespace, mdt_intent_policy);
4690 /* set obd_namespace for compatibility with old code */
4691 obd->obd_namespace = m->mdt_namespace;
4693 cfs_timer_init(&m->mdt_ck_timer, mdt_ck_timer_callback, m);
4695 rc = mdt_ck_thread_start(m);
4697 GOTO(err_free_ns, rc);
4699 rc = mdt_fs_setup(env, m, obd, lsi);
4703 rc = mdt_obd_llog_setup(obd, lsi);
4705 GOTO(err_fs_cleanup, rc);
4707 rc = mdt_llog_ctxt_clone(env, m, LLOG_CHANGELOG_ORIG_CTXT);
4709 GOTO(err_llog_cleanup, rc);
4711 mdt_adapt_sptlrpc_conf(obd, 1);
4713 next = m->mdt_child;
4714 #ifdef HAVE_QUOTA_SUPPORT
4715 rc = next->md_ops->mdo_quota.mqo_setup(env, next, lmi->lmi_mnt);
4717 GOTO(err_llog_cleanup, rc);
4720 server_put_mount_2(dev, lmi->lmi_mnt);
4723 rc = next->md_ops->mdo_iocontrol(env, next, OBD_IOC_GET_MNTOPT, 0,
4726 GOTO(err_quota, rc);
4728 if (mntopts & MNTOPT_USERXATTR)
4729 m->mdt_opts.mo_user_xattr = 1;
4731 m->mdt_opts.mo_user_xattr = 0;
4733 if (mntopts & MNTOPT_ACL)
4734 m->mdt_opts.mo_acl = 1;
4736 m->mdt_opts.mo_acl = 0;
4738 /* XXX: to support suppgid for ACL, we enable identity_upcall
4739 * by default, otherwise, maybe got unexpected -EACCESS. */
4740 if (m->mdt_opts.mo_acl)
4741 identity_upcall = MDT_IDENTITY_UPCALL_PATH;
4743 m->mdt_identity_cache = upcall_cache_init(obd->obd_name,identity_upcall,
4744 &mdt_identity_upcall_cache_ops);
4745 if (IS_ERR(m->mdt_identity_cache)) {
4746 rc = PTR_ERR(m->mdt_identity_cache);
4747 m->mdt_identity_cache = NULL;
4748 GOTO(err_quota, rc);
4751 target_recovery_init(&m->mdt_lut, mdt_recovery_handle);
4753 rc = mdt_procfs_init(m, dev);
4755 CERROR("Can't init MDT lprocfs, rc %d\n", rc);
4756 GOTO(err_recovery, rc);
4759 rc = mdt_start_ptlrpc_service(m);
4761 GOTO(err_procfs, rc);
4763 ping_evictor_start();
4765 rc = lu_site_init_finish(s);
4767 GOTO(err_stop_service, rc);
4769 if (obd->obd_recovering == 0)
4770 mdt_postrecov(env, m);
4772 mdt_init_capa_ctxt(env, m);
4774 /* Reduce the initial timeout on an MDS because it doesn't need such
4775 * a long timeout as an OST does. Adaptive timeouts will adjust this
4776 * value appropriately. */
4777 if (ldlm_timeout == LDLM_TIMEOUT_DEFAULT)
4778 ldlm_timeout = MDS_LDLM_TIMEOUT_DEFAULT;
4783 ping_evictor_stop();
4784 mdt_stop_ptlrpc_service(m);
4788 target_recovery_fini(obd);
4789 upcall_cache_cleanup(m->mdt_identity_cache);
4790 m->mdt_identity_cache = NULL;
4792 #ifdef HAVE_QUOTA_SUPPORT
4793 next->md_ops->mdo_quota.mqo_cleanup(env, next);
4796 mdt_llog_ctxt_unclone(env, m, LLOG_CHANGELOG_ORIG_CTXT);
4797 mdt_obd_llog_cleanup(obd);
4799 mdt_fs_cleanup(env, m);
4801 cfs_timer_disarm(&m->mdt_ck_timer);
4802 mdt_ck_thread_stop(m);
4804 ldlm_namespace_free(m->mdt_namespace, NULL, 0);
4805 obd->obd_namespace = m->mdt_namespace = NULL;
4807 mdt_seq_fini(env, m);
4809 mdt_fld_fini(env, m);
4811 lut_fini(env, &m->mdt_lut);
4813 mdt_stack_fini(env, m, md2lu_dev(m->mdt_child));
4820 server_put_mount_2(dev, lmi->lmi_mnt);
4824 /* used by MGS to process specific configurations */
4825 static int mdt_process_config(const struct lu_env *env,
4826 struct lu_device *d, struct lustre_cfg *cfg)
4828 struct mdt_device *m = mdt_dev(d);
4829 struct md_device *md_next = m->mdt_child;
4830 struct lu_device *next = md2lu_dev(md_next);
4834 switch (cfg->lcfg_command) {
4836 struct lprocfs_static_vars lvars;
4837 struct obd_device *obd = d->ld_obd;
4840 * For interoperability between 1.8 and 2.0,
4843 /* Skip old "mdt.group_upcall" param. */
4844 char *param = lustre_cfg_string(cfg, 1);
4845 if (param && !strncmp("mdt.group_upcall", param, 16)) {
4846 CWARN("For 1.8 interoperability, skip this"
4847 " mdt.group_upcall. It is obsolete\n");
4850 /* Rename old "mdt.quota_type" to "mdd.quota_type. */
4851 if (param && !strncmp("mdt.quota_type", param, 14)) {
4852 CWARN("Found old param mdt.quota_type, changed"
4853 " it to mdd.quota_type.\n");
4858 lprocfs_mdt_init_vars(&lvars);
4859 rc = class_process_proc_param(PARAM_MDT, lvars.obd_vars,
4861 if (rc > 0 || rc == -ENOSYS)
4862 /* we don't understand; pass it on */
4863 rc = next->ld_ops->ldo_process_config(env, next, cfg);
4868 * Add mdc hook to get first MDT uuid and connect it to
4869 * ls->controller to use for seq manager.
4871 rc = next->ld_ops->ldo_process_config(env, next, cfg);
4873 CERROR("Can't add mdc, rc %d\n", rc);
4875 rc = mdt_seq_init_cli(env, mdt_dev(d), cfg);
4878 /* others are passed further */
4879 rc = next->ld_ops->ldo_process_config(env, next, cfg);
4885 static struct lu_object *mdt_object_alloc(const struct lu_env *env,
4886 const struct lu_object_header *hdr,
4887 struct lu_device *d)
4889 struct mdt_object *mo;
4895 struct lu_object *o;
4896 struct lu_object_header *h;
4898 o = &mo->mot_obj.mo_lu;
4899 h = &mo->mot_header;
4900 lu_object_header_init(h);
4901 lu_object_init(o, h, d);
4902 lu_object_add_top(h, o);
4903 o->lo_ops = &mdt_obj_ops;
4904 cfs_mutex_init(&mo->mot_ioepoch_mutex);
4905 cfs_mutex_init(&mo->mot_lov_mutex);
4911 static int mdt_object_init(const struct lu_env *env, struct lu_object *o,
4912 const struct lu_object_conf *unused)
4914 struct mdt_device *d = mdt_dev(o->lo_dev);
4915 struct lu_device *under;
4916 struct lu_object *below;
4920 CDEBUG(D_INFO, "object init, fid = "DFID"\n",
4921 PFID(lu_object_fid(o)));
4923 under = &d->mdt_child->md_lu_dev;
4924 below = under->ld_ops->ldo_object_alloc(env, o->lo_header, under);
4925 if (below != NULL) {
4926 lu_object_add(o, below);
4933 static void mdt_object_free(const struct lu_env *env, struct lu_object *o)
4935 struct mdt_object *mo = mdt_obj(o);
4936 struct lu_object_header *h;
4940 CDEBUG(D_INFO, "object free, fid = "DFID"\n",
4941 PFID(lu_object_fid(o)));
4944 lu_object_header_fini(h);
4949 static int mdt_object_print(const struct lu_env *env, void *cookie,
4950 lu_printer_t p, const struct lu_object *o)
4952 struct mdt_object *mdto = mdt_obj((struct lu_object *)o);
4953 return (*p)(env, cookie, LUSTRE_MDT_NAME"-object@%p(ioepoch="LPU64" "
4954 "flags="LPX64", epochcount=%d, writecount=%d)",
4955 mdto, mdto->mot_ioepoch, mdto->mot_flags,
4956 mdto->mot_ioepoch_count, mdto->mot_writecount);
4959 static const struct lu_device_operations mdt_lu_ops = {
4960 .ldo_object_alloc = mdt_object_alloc,
4961 .ldo_process_config = mdt_process_config,
4964 static const struct lu_object_operations mdt_obj_ops = {
4965 .loo_object_init = mdt_object_init,
4966 .loo_object_free = mdt_object_free,
4967 .loo_object_print = mdt_object_print
4970 static int mdt_obd_set_info_async(const struct lu_env *env,
4971 struct obd_export *exp,
4972 __u32 keylen, void *key,
4973 __u32 vallen, void *val,
4974 struct ptlrpc_request_set *set)
4976 struct obd_device *obd = exp->exp_obd;
4982 if (KEY_IS(KEY_SPTLRPC_CONF)) {
4983 rc = mdt_adapt_sptlrpc_conf(obd, 0);
4990 /* mds_connect_internal */
4991 static int mdt_connect_internal(struct obd_export *exp,
4992 struct mdt_device *mdt,
4993 struct obd_connect_data *data)
4996 data->ocd_connect_flags &= MDT_CONNECT_SUPPORTED;
4997 data->ocd_ibits_known &= MDS_INODELOCK_FULL;
4999 /* If no known bits (which should not happen, probably,
5000 as everybody should support LOOKUP and UPDATE bits at least)
5001 revert to compat mode with plain locks. */
5002 if (!data->ocd_ibits_known &&
5003 data->ocd_connect_flags & OBD_CONNECT_IBITS)
5004 data->ocd_connect_flags &= ~OBD_CONNECT_IBITS;
5006 if (!mdt->mdt_opts.mo_acl)
5007 data->ocd_connect_flags &= ~OBD_CONNECT_ACL;
5009 if (!mdt->mdt_opts.mo_user_xattr)
5010 data->ocd_connect_flags &= ~OBD_CONNECT_XATTR;
5012 if (!mdt->mdt_som_conf)
5013 data->ocd_connect_flags &= ~OBD_CONNECT_SOM;
5015 if (data->ocd_connect_flags & OBD_CONNECT_BRW_SIZE) {
5016 data->ocd_brw_size = min(data->ocd_brw_size,
5017 (__u32)(PTLRPC_MAX_BRW_PAGES << CFS_PAGE_SHIFT));
5018 if (data->ocd_brw_size == 0) {
5019 CERROR("%s: cli %s/%p ocd_connect_flags: "LPX64
5020 " ocd_version: %x ocd_grant: %d "
5021 "ocd_index: %u ocd_brw_size is "
5022 "unexpectedly zero, network data "
5023 "corruption? Refusing connection of this"
5025 exp->exp_obd->obd_name,
5026 exp->exp_client_uuid.uuid,
5027 exp, data->ocd_connect_flags, data->ocd_version,
5028 data->ocd_grant, data->ocd_index);
5033 cfs_spin_lock(&exp->exp_lock);
5034 exp->exp_connect_flags = data->ocd_connect_flags;
5035 cfs_spin_unlock(&exp->exp_lock);
5036 data->ocd_version = LUSTRE_VERSION_CODE;
5037 exp->exp_mdt_data.med_ibits_known = data->ocd_ibits_known;
5041 if (mdt->mdt_opts.mo_acl &&
5042 ((exp->exp_connect_flags & OBD_CONNECT_ACL) == 0)) {
5043 CWARN("%s: MDS requires ACL support but client does not\n",
5044 mdt->mdt_md_dev.md_lu_dev.ld_obd->obd_name);
5049 if ((exp->exp_connect_flags & OBD_CONNECT_FID) == 0) {
5050 CWARN("%s: MDS requires FID support, but client not\n",
5051 mdt->mdt_md_dev.md_lu_dev.ld_obd->obd_name);
5055 if (mdt->mdt_som_conf && !exp_connect_som(exp) &&
5056 !(exp->exp_connect_flags & OBD_CONNECT_MDS_MDS)) {
5057 CWARN("%s: MDS has SOM enabled, but client does not support "
5058 "it\n", mdt->mdt_md_dev.md_lu_dev.ld_obd->obd_name);
5065 static int mdt_connect_check_sptlrpc(struct mdt_device *mdt,
5066 struct obd_export *exp,
5067 struct ptlrpc_request *req)
5069 struct sptlrpc_flavor flvr;
5072 if (exp->exp_flvr.sf_rpc == SPTLRPC_FLVR_INVALID) {
5073 cfs_read_lock(&mdt->mdt_sptlrpc_lock);
5074 sptlrpc_target_choose_flavor(&mdt->mdt_sptlrpc_rset,
5078 cfs_read_unlock(&mdt->mdt_sptlrpc_lock);
5080 cfs_spin_lock(&exp->exp_lock);
5082 exp->exp_sp_peer = req->rq_sp_from;
5083 exp->exp_flvr = flvr;
5085 if (exp->exp_flvr.sf_rpc != SPTLRPC_FLVR_ANY &&
5086 exp->exp_flvr.sf_rpc != req->rq_flvr.sf_rpc) {
5087 CERROR("unauthorized rpc flavor %x from %s, "
5088 "expect %x\n", req->rq_flvr.sf_rpc,
5089 libcfs_nid2str(req->rq_peer.nid),
5090 exp->exp_flvr.sf_rpc);
5094 cfs_spin_unlock(&exp->exp_lock);
5096 if (exp->exp_sp_peer != req->rq_sp_from) {
5097 CERROR("RPC source %s doesn't match %s\n",
5098 sptlrpc_part2name(req->rq_sp_from),
5099 sptlrpc_part2name(exp->exp_sp_peer));
5102 rc = sptlrpc_target_export_check(exp, req);
5109 /* mds_connect copy */
5110 static int mdt_obd_connect(const struct lu_env *env,
5111 struct obd_export **exp, struct obd_device *obd,
5112 struct obd_uuid *cluuid,
5113 struct obd_connect_data *data,
5116 struct mdt_thread_info *info;
5117 struct obd_export *lexp;
5118 struct lustre_handle conn = { 0 };
5119 struct mdt_device *mdt;
5120 struct ptlrpc_request *req;
5124 LASSERT(env != NULL);
5125 if (!exp || !obd || !cluuid)
5128 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
5129 req = info->mti_pill->rc_req;
5130 mdt = mdt_dev(obd->obd_lu_dev);
5132 rc = class_connect(&conn, obd, cluuid);
5136 lexp = class_conn2export(&conn);
5137 LASSERT(lexp != NULL);
5139 rc = mdt_connect_check_sptlrpc(mdt, lexp, req);
5143 if (OBD_FAIL_CHECK(OBD_FAIL_TGT_RCVG_FLAG))
5144 lustre_msg_add_op_flags(req->rq_repmsg, MSG_CONNECT_RECOVERING);
5146 rc = mdt_connect_internal(lexp, mdt, data);
5148 struct lsd_client_data *lcd = lexp->exp_target_data.ted_lcd;
5151 info->mti_exp = lexp;
5152 memcpy(lcd->lcd_uuid, cluuid, sizeof lcd->lcd_uuid);
5153 rc = lut_client_new(env, lexp);
5155 mdt_export_stats_init(obd, lexp, localdata);
5160 class_disconnect(lexp);
5169 static int mdt_obd_reconnect(const struct lu_env *env,
5170 struct obd_export *exp, struct obd_device *obd,
5171 struct obd_uuid *cluuid,
5172 struct obd_connect_data *data,
5175 struct mdt_thread_info *info;
5176 struct mdt_device *mdt;
5177 struct ptlrpc_request *req;
5181 if (exp == NULL || obd == NULL || cluuid == NULL)
5184 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
5185 req = info->mti_pill->rc_req;
5186 mdt = mdt_dev(obd->obd_lu_dev);
5188 rc = mdt_connect_check_sptlrpc(mdt, exp, req);
5192 rc = mdt_connect_internal(exp, mdt_dev(obd->obd_lu_dev), data);
5194 mdt_export_stats_init(obd, exp, localdata);
5199 static int mdt_export_cleanup(struct obd_export *exp)
5201 struct mdt_export_data *med = &exp->exp_mdt_data;
5202 struct obd_device *obd = exp->exp_obd;
5203 struct mdt_device *mdt;
5204 struct mdt_thread_info *info;
5206 CFS_LIST_HEAD(closing_list);
5207 struct mdt_file_data *mfd, *n;
5211 cfs_spin_lock(&med->med_open_lock);
5212 while (!cfs_list_empty(&med->med_open_head)) {
5213 cfs_list_t *tmp = med->med_open_head.next;
5214 mfd = cfs_list_entry(tmp, struct mdt_file_data, mfd_list);
5216 /* Remove mfd handle so it can't be found again.
5217 * We are consuming the mfd_list reference here. */
5218 class_handle_unhash(&mfd->mfd_handle);
5219 cfs_list_move_tail(&mfd->mfd_list, &closing_list);
5221 cfs_spin_unlock(&med->med_open_lock);
5222 mdt = mdt_dev(obd->obd_lu_dev);
5223 LASSERT(mdt != NULL);
5225 rc = lu_env_init(&env, LCT_MD_THREAD);
5229 info = lu_context_key_get(&env.le_ctx, &mdt_thread_key);
5230 LASSERT(info != NULL);
5231 memset(info, 0, sizeof *info);
5232 info->mti_env = &env;
5233 info->mti_mdt = mdt;
5234 info->mti_exp = exp;
5236 if (!cfs_list_empty(&closing_list)) {
5237 struct md_attr *ma = &info->mti_attr;
5241 lmm_size = mdt->mdt_max_mdsize;
5242 OBD_ALLOC_LARGE(ma->ma_lmm, lmm_size);
5243 if (ma->ma_lmm == NULL)
5244 GOTO(out_lmm, rc = -ENOMEM);
5246 cookie_size = mdt->mdt_max_cookiesize;
5247 OBD_ALLOC_LARGE(ma->ma_cookie, cookie_size);
5248 if (ma->ma_cookie == NULL)
5249 GOTO(out_cookie, rc = -ENOMEM);
5251 /* Close any open files (which may also cause orphan unlinking). */
5252 cfs_list_for_each_entry_safe(mfd, n, &closing_list, mfd_list) {
5253 cfs_list_del_init(&mfd->mfd_list);
5254 memset(&ma->ma_attr, 0, sizeof(ma->ma_attr));
5255 ma->ma_lmm_size = lmm_size;
5256 ma->ma_cookie_size = cookie_size;
5258 /* It is not for setattr, just tell MDD to send
5259 * DESTROY RPC to OSS if needed */
5260 ma->ma_valid = MA_FLAGS;
5261 ma->ma_attr_flags = MDS_CLOSE_CLEANUP;
5262 /* Don't unlink orphan on failover umount, LU-184 */
5263 if (exp->exp_flags & OBD_OPT_FAILOVER)
5264 ma->ma_attr_flags |= MDS_KEEP_ORPHAN;
5265 mdt_mfd_close(info, mfd);
5267 OBD_FREE_LARGE(ma->ma_cookie, cookie_size);
5268 ma->ma_cookie = NULL;
5270 OBD_FREE_LARGE(ma->ma_lmm, lmm_size);
5274 info->mti_mdt = NULL;
5275 /* cleanup client slot early */
5276 /* Do not erase record for recoverable client. */
5277 if (!(exp->exp_flags & OBD_OPT_FAILOVER) || exp->exp_failed)
5278 lut_client_del(&env, exp);
5284 static int mdt_obd_disconnect(struct obd_export *exp)
5290 class_export_get(exp);
5292 rc = server_disconnect_export(exp);
5294 CDEBUG(D_IOCTL, "server disconnect error: %d\n", rc);
5296 rc = mdt_export_cleanup(exp);
5297 class_export_put(exp);
5301 /* FIXME: Can we avoid using these two interfaces? */
5302 static int mdt_init_export(struct obd_export *exp)
5304 struct mdt_export_data *med = &exp->exp_mdt_data;
5308 CFS_INIT_LIST_HEAD(&med->med_open_head);
5309 cfs_spin_lock_init(&med->med_open_lock);
5310 cfs_mutex_init(&med->med_idmap_mutex);
5311 med->med_idmap = NULL;
5312 cfs_spin_lock(&exp->exp_lock);
5313 exp->exp_connecting = 1;
5314 cfs_spin_unlock(&exp->exp_lock);
5316 /* self-export doesn't need client data and ldlm initialization */
5317 if (unlikely(obd_uuid_equals(&exp->exp_obd->obd_uuid,
5318 &exp->exp_client_uuid)))
5321 rc = lut_client_alloc(exp);
5325 rc = ldlm_init_export(exp);
5332 lut_client_free(exp);
5334 CERROR("%s: Error %d while initializing export\n",
5335 exp->exp_obd->obd_name, rc);
5339 static int mdt_destroy_export(struct obd_export *exp)
5343 if (exp_connect_rmtclient(exp))
5344 mdt_cleanup_idmap(&exp->exp_mdt_data);
5346 target_destroy_export(exp);
5347 /* destroy can be called from failed obd_setup, so
5348 * checking uuid is safer than obd_self_export */
5349 if (unlikely(obd_uuid_equals(&exp->exp_obd->obd_uuid,
5350 &exp->exp_client_uuid)))
5353 ldlm_destroy_export(exp);
5354 lut_client_free(exp);
5356 LASSERT(cfs_list_empty(&exp->exp_outstanding_replies));
5357 LASSERT(cfs_list_empty(&exp->exp_mdt_data.med_open_head));
5362 static void mdt_allow_cli(struct mdt_device *m, unsigned int flag)
5364 if (flag & CONFIG_LOG)
5365 cfs_set_bit(MDT_FL_CFGLOG, &m->mdt_state);
5367 /* also notify active event */
5368 if (flag & CONFIG_SYNC)
5369 cfs_set_bit(MDT_FL_SYNCED, &m->mdt_state);
5371 if (cfs_test_bit(MDT_FL_CFGLOG, &m->mdt_state) &&
5372 cfs_test_bit(MDT_FL_SYNCED, &m->mdt_state)) {
5373 struct obd_device *obd = m->mdt_md_dev.md_lu_dev.ld_obd;
5375 /* Open for clients */
5376 if (obd->obd_no_conn) {
5377 cfs_spin_lock(&obd->obd_dev_lock);
5378 obd->obd_no_conn = 0;
5379 cfs_spin_unlock(&obd->obd_dev_lock);
5384 static int mdt_upcall(const struct lu_env *env, struct md_device *md,
5385 enum md_upcall_event ev, void *data)
5387 struct mdt_device *m = mdt_dev(&md->md_lu_dev);
5388 struct md_device *next = m->mdt_child;
5389 struct mdt_thread_info *mti;
5395 rc = next->md_ops->mdo_maxsize_get(env, next,
5397 &m->mdt_max_cookiesize);
5398 CDEBUG(D_INFO, "get max mdsize %d max cookiesize %d\n",
5399 m->mdt_max_mdsize, m->mdt_max_cookiesize);
5400 mdt_allow_cli(m, CONFIG_SYNC);
5403 m->mdt_lut.lut_obd->u.obt.obt_mount_count;
5406 mti = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
5407 mti->mti_no_need_trans = 1;
5408 CDEBUG(D_INFO, "disable mdt trans for this thread\n");
5411 /* Check that MDT is not yet configured */
5412 LASSERT(!cfs_test_bit(MDT_FL_CFGLOG, &m->mdt_state));
5414 #ifdef HAVE_QUOTA_SUPPORT
5416 if (md->md_lu_dev.ld_obd->obd_recovering == 0 &&
5417 likely(md->md_lu_dev.ld_obd->obd_stopping == 0))
5418 next->md_ops->mdo_quota.mqo_recovery(env, next);
5422 CERROR("invalid event\n");
5429 static int mdt_obd_notify(struct obd_device *obd,
5430 struct obd_device *watched,
5431 enum obd_notify_event ev, void *data)
5433 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
5434 #ifdef HAVE_QUOTA_SUPPORT
5435 struct md_device *next = mdt->mdt_child;
5440 case OBD_NOTIFY_CONFIG:
5441 mdt_allow_cli(mdt, (unsigned long)data);
5443 #ifdef HAVE_QUOTA_SUPPORT
5444 /* quota_type has been processed, we can now handle
5445 * incoming quota requests */
5446 next->md_ops->mdo_quota.mqo_notify(NULL, next);
5450 CDEBUG(D_INFO, "Unhandled notification %#x\n", ev);
5455 static int mdt_rpc_fid2path(struct mdt_thread_info *info, void *key,
5456 void *val, int vallen)
5458 struct mdt_device *mdt = mdt_dev(info->mti_exp->exp_obd->obd_lu_dev);
5459 struct getinfo_fid2path *fpout, *fpin;
5462 fpin = key + cfs_size_round(sizeof(KEY_FID2PATH));
5465 if (ptlrpc_req_need_swab(info->mti_pill->rc_req))
5466 lustre_swab_fid2path(fpin);
5468 memcpy(fpout, fpin, sizeof(*fpin));
5469 if (fpout->gf_pathlen != vallen - sizeof(*fpin))
5472 rc = mdt_fid2path(info->mti_env, mdt, fpout);
5476 static int mdt_fid2path(const struct lu_env *env, struct mdt_device *mdt,
5477 struct getinfo_fid2path *fp)
5479 struct mdt_object *obj;
5483 CDEBUG(D_IOCTL, "path get "DFID" from "LPU64" #%d\n",
5484 PFID(&fp->gf_fid), fp->gf_recno, fp->gf_linkno);
5486 if (!fid_is_sane(&fp->gf_fid))
5489 obj = mdt_object_find(env, mdt, &fp->gf_fid);
5490 if (obj == NULL || IS_ERR(obj)) {
5491 CDEBUG(D_IOCTL, "no object "DFID": %ld\n", PFID(&fp->gf_fid),
5496 rc = lu_object_exists(&obj->mot_obj.mo_lu);
5502 mdt_object_put(env, obj);
5503 CDEBUG(D_IOCTL, "nonlocal object "DFID": %d\n",
5504 PFID(&fp->gf_fid), rc);
5508 rc = mo_path(env, md_object_next(&obj->mot_obj), fp->gf_path,
5509 fp->gf_pathlen, &fp->gf_recno, &fp->gf_linkno);
5510 mdt_object_put(env, obj);
5515 static int mdt_get_info(struct mdt_thread_info *info)
5517 struct ptlrpc_request *req = mdt_info_req(info);
5525 key = req_capsule_client_get(info->mti_pill, &RMF_GETINFO_KEY);
5527 CDEBUG(D_IOCTL, "No GETINFO key");
5530 keylen = req_capsule_get_size(info->mti_pill, &RMF_GETINFO_KEY,
5533 vallen = req_capsule_client_get(info->mti_pill, &RMF_GETINFO_VALLEN);
5534 if (vallen == NULL) {
5535 CDEBUG(D_IOCTL, "Unable to get RMF_GETINFO_VALLEN buffer");
5539 req_capsule_set_size(info->mti_pill, &RMF_GETINFO_VAL, RCL_SERVER,
5541 rc = req_capsule_server_pack(info->mti_pill);
5542 valout = req_capsule_server_get(info->mti_pill, &RMF_GETINFO_VAL);
5543 if (valout == NULL) {
5544 CDEBUG(D_IOCTL, "Unable to get get-info RPC out buffer");
5548 if (KEY_IS(KEY_FID2PATH))
5549 rc = mdt_rpc_fid2path(info, key, valout, *vallen);
5553 lustre_msg_set_status(req->rq_repmsg, rc);
5558 /* Pass the ioc down */
5559 static int mdt_ioc_child(struct lu_env *env, struct mdt_device *mdt,
5560 unsigned int cmd, int len, void *data)
5562 struct lu_context ioctl_session;
5563 struct md_device *next = mdt->mdt_child;
5567 rc = lu_context_init(&ioctl_session, LCT_SESSION);
5570 ioctl_session.lc_thread = (struct ptlrpc_thread *)cfs_current();
5571 lu_context_enter(&ioctl_session);
5572 env->le_ses = &ioctl_session;
5574 LASSERT(next->md_ops->mdo_iocontrol);
5575 rc = next->md_ops->mdo_iocontrol(env, next, cmd, len, data);
5577 lu_context_exit(&ioctl_session);
5578 lu_context_fini(&ioctl_session);
5582 static int mdt_ioc_version_get(struct mdt_thread_info *mti, void *karg)
5584 struct obd_ioctl_data *data = karg;
5585 struct lu_fid *fid = (struct lu_fid *)data->ioc_inlbuf1;
5587 struct mdt_object *obj;
5588 struct mdt_lock_handle *lh;
5592 CDEBUG(D_IOCTL, "getting version for "DFID"\n", PFID(fid));
5593 if (!fid_is_sane(fid))
5596 lh = &mti->mti_lh[MDT_LH_PARENT];
5597 mdt_lock_reg_init(lh, LCK_CR);
5599 obj = mdt_object_find_lock(mti, fid, lh, MDS_INODELOCK_UPDATE);
5601 RETURN(PTR_ERR(obj));
5603 rc = mdt_object_exists(obj);
5607 * before calling version get the correct MDS should be
5608 * fid, this is error to find remote object here
5610 CERROR("nonlocal object "DFID"\n", PFID(fid));
5611 } else if (rc == 0) {
5612 *(__u64 *)data->ioc_inlbuf2 = ENOENT_VERSION;
5615 version = dt_version_get(mti->mti_env, mdt_obj2dt(obj));
5616 *(__u64 *)data->ioc_inlbuf2 = version;
5619 mdt_object_unlock_put(mti, obj, lh, 1);
5623 /* ioctls on obd dev */
5624 static int mdt_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
5625 void *karg, void *uarg)
5628 struct obd_device *obd = exp->exp_obd;
5629 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
5630 struct dt_device *dt = mdt->mdt_bottom;
5634 CDEBUG(D_IOCTL, "handling ioctl cmd %#x\n", cmd);
5635 rc = lu_env_init(&env, LCT_MD_THREAD);
5641 rc = mdt_device_sync(&env, mdt);
5643 case OBD_IOC_SET_READONLY:
5644 rc = dt->dd_ops->dt_ro(&env, dt);
5646 case OBD_IOC_ABORT_RECOVERY:
5647 CERROR("Aborting recovery for device %s\n", obd->obd_name);
5648 target_stop_recovery_thread(obd);
5651 case OBD_IOC_CHANGELOG_REG:
5652 case OBD_IOC_CHANGELOG_DEREG:
5653 case OBD_IOC_CHANGELOG_CLEAR:
5654 rc = mdt_ioc_child(&env, mdt, cmd, len, karg);
5656 case OBD_IOC_GET_OBJ_VERSION: {
5657 struct mdt_thread_info *mti;
5658 mti = lu_context_key_get(&env.le_ctx, &mdt_thread_key);
5659 memset(mti, 0, sizeof *mti);
5660 mti->mti_env = &env;
5664 rc = mdt_ioc_version_get(mti, karg);
5668 CERROR("Not supported cmd = %d for device %s\n",
5669 cmd, obd->obd_name);
5677 int mdt_postrecov(const struct lu_env *env, struct mdt_device *mdt)
5679 struct lu_device *ld = md2lu_dev(mdt->mdt_child);
5680 #ifdef HAVE_QUOTA_SUPPORT
5681 struct obd_device *obd = mdt2obd_dev(mdt);
5682 struct md_device *next = mdt->mdt_child;
5687 rc = ld->ld_ops->ldo_recovery_complete(env, ld);
5688 #ifdef HAVE_QUOTA_SUPPORT
5689 if (likely(obd->obd_stopping == 0))
5690 next->md_ops->mdo_quota.mqo_recovery(env, next);
5695 int mdt_obd_postrecov(struct obd_device *obd)
5700 rc = lu_env_init(&env, LCT_MD_THREAD);
5703 rc = mdt_postrecov(&env, mdt_dev(obd->obd_lu_dev));
5709 * Send a copytool req to a client
5710 * Note this sends a request RPC from a server (MDT) to a client (MDC),
5711 * backwards of normal comms.
5713 int mdt_hsm_copytool_send(struct obd_export *exp)
5716 struct hsm_action_list *hal;
5717 struct hsm_action_item *hai;
5721 CWARN("%s: writing to mdc at %s\n", exp->exp_obd->obd_name,
5722 libcfs_nid2str(exp->exp_connection->c_peer.nid));
5724 len = sizeof(*lh) + sizeof(*hal) + MTI_NAME_MAXLEN +
5725 /* for mockup below */ 2 * cfs_size_round(sizeof(*hai));
5730 lh->kuc_magic = KUC_MAGIC;
5731 lh->kuc_transport = KUC_TRANSPORT_HSM;
5732 lh->kuc_msgtype = HMT_ACTION_LIST;
5733 lh->kuc_msglen = len;
5735 hal = (struct hsm_action_list *)(lh + 1);
5736 hal->hal_version = HAL_VERSION;
5737 hal->hal_archive_num = 1;
5738 obd_uuid2fsname(hal->hal_fsname, exp->exp_obd->obd_name,
5741 /* mock up an action list */
5743 hai = hai_zero(hal);
5744 hai->hai_action = HSMA_ARCHIVE;
5745 hai->hai_fid.f_oid = 0xA00A;
5746 hai->hai_len = sizeof(*hai);
5747 hai = hai_next(hai);
5748 hai->hai_action = HSMA_RESTORE;
5749 hai->hai_fid.f_oid = 0xB00B;
5750 hai->hai_len = sizeof(*hai);
5752 /* Uses the ldlm reverse import; this rpc will be seen by
5753 the ldlm_callback_handler */
5754 rc = do_set_info_async(exp->exp_imp_reverse,
5755 LDLM_SET_INFO, LUSTRE_OBD_VERSION,
5756 sizeof(KEY_HSM_COPYTOOL_SEND),
5757 KEY_HSM_COPYTOOL_SEND,
5765 static struct obd_ops mdt_obd_device_ops = {
5766 .o_owner = THIS_MODULE,
5767 .o_set_info_async = mdt_obd_set_info_async,
5768 .o_connect = mdt_obd_connect,
5769 .o_reconnect = mdt_obd_reconnect,
5770 .o_disconnect = mdt_obd_disconnect,
5771 .o_init_export = mdt_init_export,
5772 .o_destroy_export = mdt_destroy_export,
5773 .o_iocontrol = mdt_iocontrol,
5774 .o_postrecov = mdt_obd_postrecov,
5775 .o_notify = mdt_obd_notify
5778 static struct lu_device* mdt_device_fini(const struct lu_env *env,
5779 struct lu_device *d)
5781 struct mdt_device *m = mdt_dev(d);
5788 static struct lu_device *mdt_device_free(const struct lu_env *env,
5789 struct lu_device *d)
5791 struct mdt_device *m = mdt_dev(d);
5794 md_device_fini(&m->mdt_md_dev);
5799 static struct lu_device *mdt_device_alloc(const struct lu_env *env,
5800 struct lu_device_type *t,
5801 struct lustre_cfg *cfg)
5803 struct lu_device *l;
5804 struct mdt_device *m;
5810 l = &m->mdt_md_dev.md_lu_dev;
5811 rc = mdt_init0(env, m, t, cfg);
5813 mdt_device_free(env, l);
5817 md_upcall_init(&m->mdt_md_dev, mdt_upcall);
5819 l = ERR_PTR(-ENOMEM);
5823 /* context key constructor/destructor: mdt_key_init, mdt_key_fini */
5824 LU_KEY_INIT_FINI(mdt, struct mdt_thread_info);
5826 /* context key: mdt_thread_key */
5827 LU_CONTEXT_KEY_DEFINE(mdt, LCT_MD_THREAD);
5829 struct md_ucred *mdt_ucred(const struct mdt_thread_info *info)
5831 return md_ucred(info->mti_env);
5835 * Enable/disable COS (Commit On Sharing).
5837 * Set/Clear the COS flag in mdt options.
5839 * \param mdt mdt device
5840 * \param val 0 disables COS, other values enable COS
5842 void mdt_enable_cos(struct mdt_device *mdt, int val)
5847 mdt->mdt_opts.mo_cos = !!val;
5848 rc = lu_env_init(&env, LCT_LOCAL);
5849 if (unlikely(rc != 0)) {
5850 CWARN("lu_env initialization failed with rc = %d,"
5851 "cannot sync\n", rc);
5854 mdt_device_sync(&env, mdt);
5859 * Check COS (Commit On Sharing) status.
5861 * Return COS flag status.
5863 * \param mdt mdt device
5865 int mdt_cos_is_enabled(struct mdt_device *mdt)
5867 return mdt->mdt_opts.mo_cos != 0;
5870 /* type constructor/destructor: mdt_type_init, mdt_type_fini */
5871 LU_TYPE_INIT_FINI(mdt, &mdt_thread_key);
5873 static struct lu_device_type_operations mdt_device_type_ops = {
5874 .ldto_init = mdt_type_init,
5875 .ldto_fini = mdt_type_fini,
5877 .ldto_start = mdt_type_start,
5878 .ldto_stop = mdt_type_stop,
5880 .ldto_device_alloc = mdt_device_alloc,
5881 .ldto_device_free = mdt_device_free,
5882 .ldto_device_fini = mdt_device_fini
5885 static struct lu_device_type mdt_device_type = {
5886 .ldt_tags = LU_DEVICE_MD,
5887 .ldt_name = LUSTRE_MDT_NAME,
5888 .ldt_ops = &mdt_device_type_ops,
5889 .ldt_ctx_tags = LCT_MD_THREAD
5892 static int __init mdt_mod_init(void)
5894 struct lprocfs_static_vars lvars;
5897 lprocfs_mdt_init_vars(&lvars);
5898 rc = class_register_type(&mdt_obd_device_ops, NULL,
5899 lvars.module_vars, LUSTRE_MDT_NAME,
5905 static void __exit mdt_mod_exit(void)
5907 class_unregister_type(LUSTRE_MDT_NAME);
5911 #define DEF_HNDL(prefix, base, suffix, flags, opc, fn, fmt) \
5912 [prefix ## _ ## opc - prefix ## _ ## base] = { \
5914 .mh_fail_id = OBD_FAIL_ ## prefix ## _ ## opc ## suffix, \
5915 .mh_opc = prefix ## _ ## opc, \
5916 .mh_flags = flags, \
5921 #define DEF_MDT_HNDL(flags, name, fn, fmt) \
5922 DEF_HNDL(MDS, GETATTR, _NET, flags, name, fn, fmt)
5924 #define DEF_SEQ_HNDL(flags, name, fn, fmt) \
5925 DEF_HNDL(SEQ, QUERY, _NET, flags, name, fn, fmt)
5927 #define DEF_FLD_HNDL(flags, name, fn, fmt) \
5928 DEF_HNDL(FLD, QUERY, _NET, flags, name, fn, fmt)
5930 * Request with a format known in advance
5932 #define DEF_MDT_HNDL_F(flags, name, fn) \
5933 DEF_HNDL(MDS, GETATTR, _NET, flags, name, fn, &RQF_MDS_ ## name)
5935 #define DEF_SEQ_HNDL_F(flags, name, fn) \
5936 DEF_HNDL(SEQ, QUERY, _NET, flags, name, fn, &RQF_SEQ_ ## name)
5938 #define DEF_FLD_HNDL_F(flags, name, fn) \
5939 DEF_HNDL(FLD, QUERY, _NET, flags, name, fn, &RQF_FLD_ ## name)
5941 * Request with a format we do not yet know
5943 #define DEF_MDT_HNDL_0(flags, name, fn) \
5944 DEF_HNDL(MDS, GETATTR, _NET, flags, name, fn, NULL)
5946 static struct mdt_handler mdt_mds_ops[] = {
5947 DEF_MDT_HNDL_F(0, CONNECT, mdt_connect),
5948 DEF_MDT_HNDL_F(0, DISCONNECT, mdt_disconnect),
5949 DEF_MDT_HNDL (0, SET_INFO, mdt_set_info,
5951 DEF_MDT_HNDL_F(0, GET_INFO, mdt_get_info),
5952 DEF_MDT_HNDL_F(0 |HABEO_REFERO, GETSTATUS, mdt_getstatus),
5953 DEF_MDT_HNDL_F(HABEO_CORPUS, GETATTR, mdt_getattr),
5954 DEF_MDT_HNDL_F(HABEO_CORPUS|HABEO_REFERO, GETATTR_NAME, mdt_getattr_name),
5955 DEF_MDT_HNDL_F(HABEO_CORPUS, GETXATTR, mdt_getxattr),
5956 DEF_MDT_HNDL_F(0 |HABEO_REFERO, STATFS, mdt_statfs),
5957 DEF_MDT_HNDL_F(0 |MUTABOR, REINT, mdt_reint),
5958 DEF_MDT_HNDL_F(HABEO_CORPUS, CLOSE, mdt_close),
5959 DEF_MDT_HNDL_F(HABEO_CORPUS, DONE_WRITING, mdt_done_writing),
5960 DEF_MDT_HNDL_F(0 |HABEO_REFERO, PIN, mdt_pin),
5961 DEF_MDT_HNDL_0(0, SYNC, mdt_sync),
5962 DEF_MDT_HNDL_F(HABEO_CORPUS|HABEO_REFERO, IS_SUBDIR, mdt_is_subdir),
5963 #ifdef HAVE_QUOTA_SUPPORT
5964 DEF_MDT_HNDL_F(0, QUOTACHECK, mdt_quotacheck_handle),
5965 DEF_MDT_HNDL_F(0, QUOTACTL, mdt_quotactl_handle)
5969 #define DEF_OBD_HNDL(flags, name, fn) \
5970 DEF_HNDL(OBD, PING, _NET, flags, name, fn, NULL)
5973 static struct mdt_handler mdt_obd_ops[] = {
5974 DEF_OBD_HNDL(0, PING, mdt_obd_ping),
5975 DEF_OBD_HNDL(0, LOG_CANCEL, mdt_obd_log_cancel),
5976 DEF_OBD_HNDL(0, QC_CALLBACK, mdt_obd_qc_callback)
5979 #define DEF_DLM_HNDL_0(flags, name, fn) \
5980 DEF_HNDL(LDLM, ENQUEUE, , flags, name, fn, NULL)
5981 #define DEF_DLM_HNDL_F(flags, name, fn) \
5982 DEF_HNDL(LDLM, ENQUEUE, , flags, name, fn, &RQF_LDLM_ ## name)
5984 static struct mdt_handler mdt_dlm_ops[] = {
5985 DEF_DLM_HNDL_F(HABEO_CLAVIS, ENQUEUE, mdt_enqueue),
5986 DEF_DLM_HNDL_0(HABEO_CLAVIS, CONVERT, mdt_convert),
5987 DEF_DLM_HNDL_0(0, BL_CALLBACK, mdt_bl_callback),
5988 DEF_DLM_HNDL_0(0, CP_CALLBACK, mdt_cp_callback)
5991 #define DEF_LLOG_HNDL(flags, name, fn) \
5992 DEF_HNDL(LLOG, ORIGIN_HANDLE_CREATE, _NET, flags, name, fn, NULL)
5994 static struct mdt_handler mdt_llog_ops[] = {
5995 DEF_LLOG_HNDL(0, ORIGIN_HANDLE_CREATE, mdt_llog_create),
5996 DEF_LLOG_HNDL(0, ORIGIN_HANDLE_NEXT_BLOCK, mdt_llog_next_block),
5997 DEF_LLOG_HNDL(0, ORIGIN_HANDLE_READ_HEADER, mdt_llog_read_header),
5998 DEF_LLOG_HNDL(0, ORIGIN_HANDLE_WRITE_REC, NULL),
5999 DEF_LLOG_HNDL(0, ORIGIN_HANDLE_CLOSE, NULL),
6000 DEF_LLOG_HNDL(0, ORIGIN_CONNECT, NULL),
6001 DEF_LLOG_HNDL(0, CATINFO, NULL),
6002 DEF_LLOG_HNDL(0, ORIGIN_HANDLE_PREV_BLOCK, mdt_llog_prev_block),
6003 DEF_LLOG_HNDL(0, ORIGIN_HANDLE_DESTROY, mdt_llog_destroy),
6006 #define DEF_SEC_CTX_HNDL(name, fn) \
6007 DEF_HNDL(SEC_CTX, INIT, _NET, 0, name, fn, NULL)
6009 static struct mdt_handler mdt_sec_ctx_ops[] = {
6010 DEF_SEC_CTX_HNDL(INIT, mdt_sec_ctx_handle),
6011 DEF_SEC_CTX_HNDL(INIT_CONT, mdt_sec_ctx_handle),
6012 DEF_SEC_CTX_HNDL(FINI, mdt_sec_ctx_handle)
6015 static struct mdt_opc_slice mdt_regular_handlers[] = {
6017 .mos_opc_start = MDS_GETATTR,
6018 .mos_opc_end = MDS_LAST_OPC,
6019 .mos_hs = mdt_mds_ops
6022 .mos_opc_start = OBD_PING,
6023 .mos_opc_end = OBD_LAST_OPC,
6024 .mos_hs = mdt_obd_ops
6027 .mos_opc_start = LDLM_ENQUEUE,
6028 .mos_opc_end = LDLM_LAST_OPC,
6029 .mos_hs = mdt_dlm_ops
6032 .mos_opc_start = LLOG_ORIGIN_HANDLE_CREATE,
6033 .mos_opc_end = LLOG_LAST_OPC,
6034 .mos_hs = mdt_llog_ops
6037 .mos_opc_start = SEC_CTX_INIT,
6038 .mos_opc_end = SEC_LAST_OPC,
6039 .mos_hs = mdt_sec_ctx_ops
6046 static struct mdt_handler mdt_readpage_ops[] = {
6047 DEF_MDT_HNDL_F(0, CONNECT, mdt_connect),
6048 DEF_MDT_HNDL_F(HABEO_CORPUS|HABEO_REFERO, READPAGE, mdt_readpage),
6049 #ifdef HAVE_SPLIT_SUPPORT
6050 DEF_MDT_HNDL_F(HABEO_CORPUS|HABEO_REFERO, WRITEPAGE, mdt_writepage),
6054 * XXX: this is ugly and should be fixed one day, see mdc_close() for
6055 * detailed comments. --umka
6057 DEF_MDT_HNDL_F(HABEO_CORPUS, CLOSE, mdt_close),
6058 DEF_MDT_HNDL_F(HABEO_CORPUS, DONE_WRITING, mdt_done_writing),
6061 static struct mdt_opc_slice mdt_readpage_handlers[] = {
6063 .mos_opc_start = MDS_GETATTR,
6064 .mos_opc_end = MDS_LAST_OPC,
6065 .mos_hs = mdt_readpage_ops
6072 static struct mdt_handler mdt_xmds_ops[] = {
6073 DEF_MDT_HNDL_F(0, CONNECT, mdt_connect),
6074 DEF_MDT_HNDL_F(HABEO_CORPUS , GETATTR, mdt_getattr),
6075 DEF_MDT_HNDL_F(0 | MUTABOR , REINT, mdt_reint),
6076 DEF_MDT_HNDL_F(HABEO_CORPUS|HABEO_REFERO, IS_SUBDIR, mdt_is_subdir),
6079 static struct mdt_opc_slice mdt_xmds_handlers[] = {
6081 .mos_opc_start = MDS_GETATTR,
6082 .mos_opc_end = MDS_LAST_OPC,
6083 .mos_hs = mdt_xmds_ops
6086 .mos_opc_start = OBD_PING,
6087 .mos_opc_end = OBD_LAST_OPC,
6088 .mos_hs = mdt_obd_ops
6091 .mos_opc_start = SEC_CTX_INIT,
6092 .mos_opc_end = SEC_LAST_OPC,
6093 .mos_hs = mdt_sec_ctx_ops
6100 static struct mdt_handler mdt_seq_ops[] = {
6101 DEF_SEQ_HNDL_F(0, QUERY, (int (*)(struct mdt_thread_info *))seq_query)
6104 static struct mdt_opc_slice mdt_seq_handlers[] = {
6106 .mos_opc_start = SEQ_QUERY,
6107 .mos_opc_end = SEQ_LAST_OPC,
6108 .mos_hs = mdt_seq_ops
6115 static struct mdt_handler mdt_fld_ops[] = {
6116 DEF_FLD_HNDL_F(0, QUERY, (int (*)(struct mdt_thread_info *))fld_query)
6119 static struct mdt_opc_slice mdt_fld_handlers[] = {
6121 .mos_opc_start = FLD_QUERY,
6122 .mos_opc_end = FLD_LAST_OPC,
6123 .mos_hs = mdt_fld_ops
6130 MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");
6131 MODULE_DESCRIPTION("Lustre Meta-data Target ("LUSTRE_MDT_NAME")");
6132 MODULE_LICENSE("GPL");
6134 CFS_MODULE_PARM(mdt_num_threads, "ul", ulong, 0444,
6135 "number of mdt service threads to start");
6137 cfs_module(mdt, "0.2.0", mdt_mod_init, mdt_mod_exit);