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 <lustre_log.h>
67 #include "mdt_internal.h"
68 #ifdef HAVE_QUOTA_SUPPORT
69 # include <lustre_quota.h>
71 #include <lustre_acl.h>
72 #include <lustre_param.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;
100 CFS_MODULE_PARM(mdt_num_threads, "ul", ulong, 0444,
101 "number of MDS service threads to start "
102 "(deprecated in favor of mds_num_threads)");
104 static unsigned long mds_num_threads;
105 CFS_MODULE_PARM(mds_num_threads, "ul", ulong, 0444,
106 "number of MDS service threads to start");
108 static char *mds_num_cpts;
109 CFS_MODULE_PARM(mds_num_cpts, "c", charp, 0444,
110 "CPU partitions MDS threads should run on");
112 static unsigned long mds_rdpg_num_threads;
113 CFS_MODULE_PARM(mds_rdpg_num_threads, "ul", ulong, 0444,
114 "number of MDS readpage service threads to start");
116 static char *mds_rdpg_num_cpts;
117 CFS_MODULE_PARM(mds_rdpg_num_cpts, "c", charp, 0444,
118 "CPU partitions MDS readpage threads should run on");
120 /* NB: these two should be removed along with setattr service in the future */
121 static unsigned long mds_attr_num_threads;
122 CFS_MODULE_PARM(mds_attr_num_threads, "ul", ulong, 0444,
123 "number of MDS setattr service threads to start");
125 static char *mds_attr_num_cpts;
126 CFS_MODULE_PARM(mds_attr_num_cpts, "c", charp, 0444,
127 "CPU partitions MDS setattr threads should run on");
129 /* ptlrpc request handler for MDT. All handlers are
130 * grouped into several slices - struct mdt_opc_slice,
131 * and stored in an array - mdt_handlers[].
134 /* The name of this handler. */
136 /* Fail id for this handler, checked at the beginning of this handler*/
138 /* Operation code for this handler */
140 /* flags are listed in enum mdt_handler_flags below. */
142 /* The actual handler function to execute. */
143 int (*mh_act)(struct mdt_thread_info *info);
144 /* Request format for this request. */
145 const struct req_format *mh_fmt;
148 enum mdt_handler_flags {
150 * struct mdt_body is passed in the incoming message, and object
151 * identified by this fid exists on disk.
153 * "habeo corpus" == "I have a body"
155 HABEO_CORPUS = (1 << 0),
157 * struct ldlm_request is passed in the incoming message.
159 * "habeo clavis" == "I have a key"
161 HABEO_CLAVIS = (1 << 1),
163 * this request has fixed reply format, so that reply message can be
164 * packed by generic code.
166 * "habeo refero" == "I have a reply"
168 HABEO_REFERO = (1 << 2),
170 * this request will modify something, so check whether the filesystem
171 * is readonly or not, then return -EROFS to client asap if necessary.
173 * "mutabor" == "I shall modify"
178 struct mdt_opc_slice {
181 struct mdt_handler *mos_hs;
184 static struct mdt_opc_slice mdt_regular_handlers[];
185 static struct mdt_opc_slice mdt_readpage_handlers[];
186 static struct mdt_opc_slice mdt_xmds_handlers[];
187 static struct mdt_opc_slice mdt_seq_handlers[];
188 static struct mdt_opc_slice mdt_fld_handlers[];
190 static struct mdt_device *mdt_dev(struct lu_device *d);
191 static int mdt_regular_handle(struct ptlrpc_request *req);
192 static int mdt_unpack_req_pack_rep(struct mdt_thread_info *info, __u32 flags);
193 static int mdt_fid2path(const struct lu_env *env, struct mdt_device *mdt,
194 struct getinfo_fid2path *fp);
196 static const struct lu_object_operations mdt_obj_ops;
198 /* Slab for MDT object allocation */
199 static cfs_mem_cache_t *mdt_object_kmem;
201 static struct lu_kmem_descr mdt_caches[] = {
203 .ckd_cache = &mdt_object_kmem,
204 .ckd_name = "mdt_obj",
205 .ckd_size = sizeof(struct mdt_object)
212 int mdt_get_disposition(struct ldlm_reply *rep, int flag)
216 return (rep->lock_policy_res1 & flag);
219 void mdt_clear_disposition(struct mdt_thread_info *info,
220 struct ldlm_reply *rep, int flag)
223 info->mti_opdata &= ~flag;
225 rep->lock_policy_res1 &= ~flag;
228 void mdt_set_disposition(struct mdt_thread_info *info,
229 struct ldlm_reply *rep, int flag)
232 info->mti_opdata |= flag;
234 rep->lock_policy_res1 |= flag;
237 void mdt_lock_reg_init(struct mdt_lock_handle *lh, ldlm_mode_t lm)
239 lh->mlh_pdo_hash = 0;
240 lh->mlh_reg_mode = lm;
241 lh->mlh_type = MDT_REG_LOCK;
244 void mdt_lock_pdo_init(struct mdt_lock_handle *lh, ldlm_mode_t lm,
245 const char *name, int namelen)
247 lh->mlh_reg_mode = lm;
248 lh->mlh_type = MDT_PDO_LOCK;
250 if (name != NULL && (name[0] != '\0')) {
251 LASSERT(namelen > 0);
252 lh->mlh_pdo_hash = full_name_hash(name, namelen);
254 LASSERT(namelen == 0);
255 lh->mlh_pdo_hash = 0ull;
259 static void mdt_lock_pdo_mode(struct mdt_thread_info *info, struct mdt_object *o,
260 struct mdt_lock_handle *lh)
266 * Any dir access needs couple of locks:
268 * 1) on part of dir we gonna take lookup/modify;
270 * 2) on whole dir to protect it from concurrent splitting and/or to
271 * flush client's cache for readdir().
273 * so, for a given mode and object this routine decides what lock mode
274 * to use for lock #2:
276 * 1) if caller's gonna lookup in dir then we need to protect dir from
277 * being splitted only - LCK_CR
279 * 2) if caller's gonna modify dir then we need to protect dir from
280 * being splitted and to flush cache - LCK_CW
282 * 3) if caller's gonna modify dir and that dir seems ready for
283 * splitting then we need to protect it from any type of access
284 * (lookup/modify/split) - LCK_EX --bzzz
287 LASSERT(lh->mlh_reg_mode != LCK_MINMODE);
288 LASSERT(lh->mlh_pdo_mode == LCK_MINMODE);
291 * Ask underlaying level its opinion about preferable PDO lock mode
292 * having access type passed as regular lock mode:
294 * - MDL_MINMODE means that lower layer does not want to specify lock
297 * - MDL_NL means that no PDO lock should be taken. This is used in some
298 * cases. Say, for non-splittable directories no need to use PDO locks
301 mode = mdo_lock_mode(info->mti_env, mdt_object_child(o),
302 mdt_dlm_mode2mdl_mode(lh->mlh_reg_mode));
304 if (mode != MDL_MINMODE) {
305 lh->mlh_pdo_mode = mdt_mdl_mode2dlm_mode(mode);
308 * Lower layer does not want to specify locking mode. We do it
309 * our selves. No special protection is needed, just flush
310 * client's cache on modification and allow concurrent
313 switch (lh->mlh_reg_mode) {
315 lh->mlh_pdo_mode = LCK_EX;
318 lh->mlh_pdo_mode = LCK_CR;
321 lh->mlh_pdo_mode = LCK_CW;
324 CERROR("Not expected lock type (0x%x)\n",
325 (int)lh->mlh_reg_mode);
330 LASSERT(lh->mlh_pdo_mode != LCK_MINMODE);
334 static int mdt_getstatus(struct mdt_thread_info *info)
336 struct mdt_device *mdt = info->mti_mdt;
337 struct md_device *next = mdt->mdt_child;
338 struct mdt_body *repbody;
343 rc = mdt_check_ucred(info);
345 RETURN(err_serious(rc));
347 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_GETSTATUS_PACK))
348 RETURN(err_serious(-ENOMEM));
350 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
351 rc = next->md_ops->mdo_root_get(info->mti_env, next, &repbody->fid1);
355 repbody->valid |= OBD_MD_FLID;
357 if (mdt->mdt_opts.mo_mds_capa &&
358 info->mti_exp->exp_connect_flags & OBD_CONNECT_MDS_CAPA) {
359 struct mdt_object *root;
360 struct lustre_capa *capa;
362 root = mdt_object_find(info->mti_env, mdt, &repbody->fid1);
364 RETURN(PTR_ERR(root));
366 capa = req_capsule_server_get(info->mti_pill, &RMF_CAPA1);
368 capa->lc_opc = CAPA_OPC_MDS_DEFAULT;
369 rc = mo_capa_get(info->mti_env, mdt_object_child(root), capa,
371 mdt_object_put(info->mti_env, root);
373 repbody->valid |= OBD_MD_FLMDSCAPA;
379 static int mdt_statfs(struct mdt_thread_info *info)
381 struct ptlrpc_request *req = mdt_info_req(info);
382 struct md_device *next = info->mti_mdt->mdt_child;
383 struct ptlrpc_service_part *svcpt;
384 struct obd_statfs *osfs;
389 svcpt = info->mti_pill->rc_req->rq_rqbd->rqbd_svcpt;
391 /* This will trigger a watchdog timeout */
392 OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_STATFS_LCW_SLEEP,
393 (MDT_SERVICE_WATCHDOG_FACTOR *
394 at_get(&svcpt->scp_at_estimate)) + 1);
396 rc = mdt_check_ucred(info);
398 RETURN(err_serious(rc));
400 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_STATFS_PACK))
401 RETURN(err_serious(-ENOMEM));
403 osfs = req_capsule_server_get(info->mti_pill, &RMF_OBD_STATFS);
407 /** statfs information are cached in the mdt_device */
408 if (cfs_time_before_64(info->mti_mdt->mdt_osfs_age,
409 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS))) {
410 /** statfs data is too old, get up-to-date one */
411 rc = next->md_ops->mdo_statfs(info->mti_env, next, osfs);
414 cfs_spin_lock(&info->mti_mdt->mdt_osfs_lock);
415 info->mti_mdt->mdt_osfs = *osfs;
416 info->mti_mdt->mdt_osfs_age = cfs_time_current_64();
417 cfs_spin_unlock(&info->mti_mdt->mdt_osfs_lock);
419 /** use cached statfs data */
420 cfs_spin_lock(&info->mti_mdt->mdt_osfs_lock);
421 *osfs = info->mti_mdt->mdt_osfs;
422 cfs_spin_unlock(&info->mti_mdt->mdt_osfs_lock);
426 mdt_counter_incr(req, LPROC_MDT_STATFS);
432 * Pack SOM attributes into the reply.
433 * Call under a DLM UPDATE lock.
435 static void mdt_pack_size2body(struct mdt_thread_info *info,
436 struct mdt_object *mo)
439 struct md_attr *ma = &info->mti_attr;
441 LASSERT(ma->ma_attr.la_valid & LA_MODE);
442 b = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
444 /* Check if Size-on-MDS is supported, if this is a regular file,
445 * if SOM is enabled on the object and if SOM cache exists and valid.
446 * Otherwise do not pack Size-on-MDS attributes to the reply. */
447 if (!(mdt_conn_flags(info) & OBD_CONNECT_SOM) ||
448 !S_ISREG(ma->ma_attr.la_mode) ||
449 !mdt_object_is_som_enabled(mo) ||
450 !(ma->ma_valid & MA_SOM))
453 b->valid |= OBD_MD_FLSIZE | OBD_MD_FLBLOCKS;
454 b->size = ma->ma_som->msd_size;
455 b->blocks = ma->ma_som->msd_blocks;
458 void mdt_pack_attr2body(struct mdt_thread_info *info, struct mdt_body *b,
459 const struct lu_attr *attr, const struct lu_fid *fid)
461 struct md_attr *ma = &info->mti_attr;
463 LASSERT(ma->ma_valid & MA_INODE);
465 b->atime = attr->la_atime;
466 b->mtime = attr->la_mtime;
467 b->ctime = attr->la_ctime;
468 b->mode = attr->la_mode;
469 b->size = attr->la_size;
470 b->blocks = attr->la_blocks;
471 b->uid = attr->la_uid;
472 b->gid = attr->la_gid;
473 b->flags = attr->la_flags;
474 b->nlink = attr->la_nlink;
475 b->rdev = attr->la_rdev;
477 /*XXX should pack the reply body according to lu_valid*/
478 b->valid |= OBD_MD_FLCTIME | OBD_MD_FLUID |
479 OBD_MD_FLGID | OBD_MD_FLTYPE |
480 OBD_MD_FLMODE | OBD_MD_FLNLINK | OBD_MD_FLFLAGS |
481 OBD_MD_FLATIME | OBD_MD_FLMTIME ;
483 if (!S_ISREG(attr->la_mode)) {
484 b->valid |= OBD_MD_FLSIZE | OBD_MD_FLBLOCKS | OBD_MD_FLRDEV;
485 } else if (ma->ma_need & MA_LOV && ma->ma_lmm_size == 0) {
486 /* means no objects are allocated on osts. */
487 LASSERT(!(ma->ma_valid & MA_LOV));
488 /* just ignore blocks occupied by extend attributes on MDS */
490 /* if no object is allocated on osts, the size on mds is valid. b=22272 */
491 b->valid |= OBD_MD_FLSIZE | OBD_MD_FLBLOCKS;
496 b->valid |= OBD_MD_FLID;
498 /* FIXME: these should be fixed when new igif ready.*/
499 b->ino = fid_oid(fid); /* 1.6 compatibility */
500 b->generation = fid_ver(fid); /* 1.6 compatibility */
501 b->valid |= OBD_MD_FLGENER; /* 1.6 compatibility */
503 CDEBUG(D_INODE, DFID": nlink=%d, mode=%o, size="LPU64"\n",
504 PFID(fid), b->nlink, b->mode, b->size);
508 mdt_body_reverse_idmap(info, b);
510 if (b->valid & OBD_MD_FLSIZE)
511 CDEBUG(D_VFSTRACE, DFID": returning size %llu\n",
512 PFID(fid), (unsigned long long)b->size);
515 static inline int mdt_body_has_lov(const struct lu_attr *la,
516 const struct mdt_body *body)
518 return ((S_ISREG(la->la_mode) && (body->valid & OBD_MD_FLEASIZE)) ||
519 (S_ISDIR(la->la_mode) && (body->valid & OBD_MD_FLDIREA )) );
522 void mdt_client_compatibility(struct mdt_thread_info *info)
524 struct mdt_body *body;
525 struct ptlrpc_request *req = mdt_info_req(info);
526 struct obd_export *exp = req->rq_export;
527 struct md_attr *ma = &info->mti_attr;
528 struct lu_attr *la = &ma->ma_attr;
531 if (exp->exp_connect_flags & OBD_CONNECT_LAYOUTLOCK)
532 /* the client can deal with 16-bit lmm_stripe_count */
535 body = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
537 if (!mdt_body_has_lov(la, body))
540 /* now we have a reply with a lov for a client not compatible with the
541 * layout lock so we have to clean the layout generation number */
542 if (S_ISREG(la->la_mode))
543 ma->ma_lmm->lmm_layout_gen = 0;
548 static int mdt_getattr_internal(struct mdt_thread_info *info,
549 struct mdt_object *o, int ma_need)
551 struct md_object *next = mdt_object_child(o);
552 const struct mdt_body *reqbody = info->mti_body;
553 struct ptlrpc_request *req = mdt_info_req(info);
554 struct md_attr *ma = &info->mti_attr;
555 struct lu_attr *la = &ma->ma_attr;
556 struct req_capsule *pill = info->mti_pill;
557 const struct lu_env *env = info->mti_env;
558 struct mdt_body *repbody;
559 struct lu_buf *buffer = &info->mti_buf;
563 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_GETATTR_PACK))
564 RETURN(err_serious(-ENOMEM));
566 repbody = req_capsule_server_get(pill, &RMF_MDT_BODY);
570 rc = mdt_object_exists(o);
572 /* This object is located on remote node.*/
573 repbody->fid1 = *mdt_object_fid(o);
574 repbody->valid = OBD_MD_FLID | OBD_MD_MDS;
578 buffer->lb_buf = req_capsule_server_get(pill, &RMF_MDT_MD);
579 buffer->lb_len = req_capsule_get_size(pill, &RMF_MDT_MD, RCL_SERVER);
581 /* If it is dir object and client require MEA, then we got MEA */
582 if (S_ISDIR(lu_object_attr(&next->mo_lu)) &&
583 reqbody->valid & OBD_MD_MEA) {
584 /* Assumption: MDT_MD size is enough for lmv size. */
585 ma->ma_lmv = buffer->lb_buf;
586 ma->ma_lmv_size = buffer->lb_len;
587 ma->ma_need = MA_LMV | MA_INODE;
589 ma->ma_lmm = buffer->lb_buf;
590 ma->ma_lmm_size = buffer->lb_len;
591 ma->ma_need = MA_LOV | MA_INODE;
594 if (S_ISDIR(lu_object_attr(&next->mo_lu)) &&
595 reqbody->valid & OBD_MD_FLDIREA &&
596 lustre_msg_get_opc(req->rq_reqmsg) == MDS_GETATTR) {
597 /* get default stripe info for this dir. */
598 ma->ma_need |= MA_LOV_DEF;
600 ma->ma_need |= ma_need;
601 if (ma->ma_need & MA_SOM)
602 ma->ma_som = &info->mti_u.som.data;
604 rc = mo_attr_get(env, next, ma);
606 CERROR("getattr error for "DFID": %d\n",
607 PFID(mdt_object_fid(o)), rc);
611 if (likely(ma->ma_valid & MA_INODE))
612 mdt_pack_attr2body(info, repbody, la, mdt_object_fid(o));
616 if (mdt_body_has_lov(la, reqbody)) {
617 if (ma->ma_valid & MA_LOV) {
618 LASSERT(ma->ma_lmm_size);
619 mdt_dump_lmm(D_INFO, ma->ma_lmm);
620 repbody->eadatasize = ma->ma_lmm_size;
621 if (S_ISDIR(la->la_mode))
622 repbody->valid |= OBD_MD_FLDIREA;
624 repbody->valid |= OBD_MD_FLEASIZE;
626 if (ma->ma_valid & MA_LMV) {
627 LASSERT(S_ISDIR(la->la_mode));
628 repbody->eadatasize = ma->ma_lmv_size;
629 repbody->valid |= (OBD_MD_FLDIREA|OBD_MD_MEA);
631 } else if (S_ISLNK(la->la_mode) &&
632 reqbody->valid & OBD_MD_LINKNAME) {
633 buffer->lb_buf = ma->ma_lmm;
634 /* eadatasize from client includes NULL-terminator, so
635 * there is no need to read it */
636 buffer->lb_len = reqbody->eadatasize - 1;
637 rc = mo_readlink(env, next, buffer);
638 if (unlikely(rc <= 0)) {
639 CERROR("readlink failed: %d\n", rc);
642 int print_limit = min_t(int, CFS_PAGE_SIZE - 128, rc);
644 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_READLINK_EPROTO))
646 repbody->valid |= OBD_MD_LINKNAME;
647 /* we need to report back size with NULL-terminator
648 * because client expects that */
649 repbody->eadatasize = rc + 1;
650 if (repbody->eadatasize != reqbody->eadatasize)
651 CERROR("Read shorter symlink %d, expected %d\n",
652 rc, reqbody->eadatasize - 1);
654 ((char *)ma->ma_lmm)[rc] = 0;
656 /* If the total CDEBUG() size is larger than a page, it
657 * will print a warning to the console, avoid this by
658 * printing just the last part of the symlink. */
659 CDEBUG(D_INODE, "symlink dest %s%.*s, len = %d\n",
660 print_limit < rc ? "..." : "", print_limit,
661 (char *)ma->ma_lmm + rc - print_limit, rc);
666 if (reqbody->valid & OBD_MD_FLMODEASIZE) {
667 repbody->max_cookiesize = info->mti_mdt->mdt_max_cookiesize;
668 repbody->max_mdsize = info->mti_mdt->mdt_max_mdsize;
669 repbody->valid |= OBD_MD_FLMODEASIZE;
670 CDEBUG(D_INODE, "I am going to change the MAX_MD_SIZE & "
671 "MAX_COOKIE to : %d:%d\n", repbody->max_mdsize,
672 repbody->max_cookiesize);
675 if (exp_connect_rmtclient(info->mti_exp) &&
676 reqbody->valid & OBD_MD_FLRMTPERM) {
677 void *buf = req_capsule_server_get(pill, &RMF_ACL);
679 /* mdt_getattr_lock only */
680 rc = mdt_pack_remote_perm(info, o, buf);
682 repbody->valid &= ~OBD_MD_FLRMTPERM;
683 repbody->aclsize = 0;
686 repbody->valid |= OBD_MD_FLRMTPERM;
687 repbody->aclsize = sizeof(struct mdt_remote_perm);
690 #ifdef CONFIG_FS_POSIX_ACL
691 else if ((req->rq_export->exp_connect_flags & OBD_CONNECT_ACL) &&
692 (reqbody->valid & OBD_MD_FLACL)) {
693 buffer->lb_buf = req_capsule_server_get(pill, &RMF_ACL);
694 buffer->lb_len = req_capsule_get_size(pill,
695 &RMF_ACL, RCL_SERVER);
696 if (buffer->lb_len > 0) {
697 rc = mo_xattr_get(env, next, buffer,
698 XATTR_NAME_ACL_ACCESS);
700 if (rc == -ENODATA) {
701 repbody->aclsize = 0;
702 repbody->valid |= OBD_MD_FLACL;
704 } else if (rc == -EOPNOTSUPP) {
707 CERROR("got acl size: %d\n", rc);
710 repbody->aclsize = rc;
711 repbody->valid |= OBD_MD_FLACL;
718 if (reqbody->valid & OBD_MD_FLMDSCAPA &&
719 info->mti_mdt->mdt_opts.mo_mds_capa &&
720 info->mti_exp->exp_connect_flags & OBD_CONNECT_MDS_CAPA) {
721 struct lustre_capa *capa;
723 capa = req_capsule_server_get(pill, &RMF_CAPA1);
725 capa->lc_opc = CAPA_OPC_MDS_DEFAULT;
726 rc = mo_capa_get(env, next, capa, 0);
729 repbody->valid |= OBD_MD_FLMDSCAPA;
734 mdt_counter_incr(req, LPROC_MDT_GETATTR);
739 static int mdt_renew_capa(struct mdt_thread_info *info)
741 struct mdt_object *obj = info->mti_object;
742 struct mdt_body *body;
743 struct lustre_capa *capa, *c;
747 /* if object doesn't exist, or server has disabled capability,
748 * return directly, client will find body->valid OBD_MD_FLOSSCAPA
751 if (!obj || !info->mti_mdt->mdt_opts.mo_oss_capa ||
752 !(info->mti_exp->exp_connect_flags & OBD_CONNECT_OSS_CAPA))
755 body = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
756 LASSERT(body != NULL);
758 c = req_capsule_client_get(info->mti_pill, &RMF_CAPA1);
761 capa = req_capsule_server_get(info->mti_pill, &RMF_CAPA2);
765 rc = mo_capa_get(info->mti_env, mdt_object_child(obj), capa, 1);
767 body->valid |= OBD_MD_FLOSSCAPA;
771 static int mdt_getattr(struct mdt_thread_info *info)
773 struct mdt_object *obj = info->mti_object;
774 struct req_capsule *pill = info->mti_pill;
775 struct mdt_body *reqbody;
776 struct mdt_body *repbody;
781 reqbody = req_capsule_client_get(pill, &RMF_MDT_BODY);
784 if (reqbody->valid & OBD_MD_FLOSSCAPA) {
785 rc = req_capsule_server_pack(pill);
787 RETURN(err_serious(rc));
788 rc = mdt_renew_capa(info);
789 GOTO(out_shrink, rc);
792 LASSERT(obj != NULL);
793 LASSERT(lu_object_assert_exists(&obj->mot_obj.mo_lu));
795 mode = lu_object_attr(&obj->mot_obj.mo_lu);
797 /* old clients may not report needed easize, use max value then */
798 req_capsule_set_size(pill, &RMF_MDT_MD, RCL_SERVER,
799 reqbody->eadatasize == 0 ?
800 info->mti_mdt->mdt_max_mdsize :
801 reqbody->eadatasize);
803 rc = req_capsule_server_pack(pill);
804 if (unlikely(rc != 0))
805 RETURN(err_serious(rc));
807 repbody = req_capsule_server_get(pill, &RMF_MDT_BODY);
808 LASSERT(repbody != NULL);
809 repbody->eadatasize = 0;
810 repbody->aclsize = 0;
812 if (reqbody->valid & OBD_MD_FLRMTPERM)
813 rc = mdt_init_ucred(info, reqbody);
815 rc = mdt_check_ucred(info);
817 GOTO(out_shrink, rc);
819 info->mti_spec.sp_ck_split = !!(reqbody->valid & OBD_MD_FLCKSPLIT);
820 info->mti_cross_ref = !!(reqbody->valid & OBD_MD_FLCROSSREF);
823 * Don't check capability at all, because rename might getattr for
824 * remote obj, and at that time no capability is available.
826 mdt_set_capainfo(info, 1, &reqbody->fid1, BYPASS_CAPA);
827 rc = mdt_getattr_internal(info, obj, 0);
828 if (reqbody->valid & OBD_MD_FLRMTPERM)
829 mdt_exit_ucred(info);
832 mdt_client_compatibility(info);
833 rc2 = mdt_fix_reply(info);
839 static int mdt_is_subdir(struct mdt_thread_info *info)
841 struct mdt_object *o = info->mti_object;
842 struct req_capsule *pill = info->mti_pill;
843 const struct mdt_body *body = info->mti_body;
844 struct mdt_body *repbody;
850 repbody = req_capsule_server_get(pill, &RMF_MDT_BODY);
853 * We save last checked parent fid to @repbody->fid1 for remote
856 LASSERT(fid_is_sane(&body->fid2));
857 LASSERT(mdt_object_exists(o) > 0);
858 rc = mdo_is_subdir(info->mti_env, mdt_object_child(o),
859 &body->fid2, &repbody->fid1);
860 if (rc == 0 || rc == -EREMOTE)
861 repbody->valid |= OBD_MD_FLID;
866 static int mdt_raw_lookup(struct mdt_thread_info *info,
867 struct mdt_object *parent,
868 const struct lu_name *lname,
869 struct ldlm_reply *ldlm_rep)
871 struct md_object *next = mdt_object_child(info->mti_object);
872 const struct mdt_body *reqbody = info->mti_body;
873 struct lu_fid *child_fid = &info->mti_tmp_fid1;
874 struct mdt_body *repbody;
878 if (reqbody->valid != OBD_MD_FLID)
881 LASSERT(!info->mti_cross_ref);
883 /* Only got the fid of this obj by name */
885 rc = mdo_lookup(info->mti_env, next, lname, child_fid,
888 /* XXX is raw_lookup possible as intent operation? */
891 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_NEG);
894 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_POS);
896 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
899 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
900 repbody->fid1 = *child_fid;
901 repbody->valid = OBD_MD_FLID;
907 * UPDATE lock should be taken against parent, and be release before exit;
908 * child_bits lock should be taken against child, and be returned back:
909 * (1)normal request should release the child lock;
910 * (2)intent request will grant the lock to client.
912 static int mdt_getattr_name_lock(struct mdt_thread_info *info,
913 struct mdt_lock_handle *lhc,
915 struct ldlm_reply *ldlm_rep)
917 struct ptlrpc_request *req = mdt_info_req(info);
918 struct mdt_body *reqbody = NULL;
919 struct mdt_object *parent = info->mti_object;
920 struct mdt_object *child;
921 struct md_object *next = mdt_object_child(parent);
922 struct lu_fid *child_fid = &info->mti_tmp_fid1;
923 struct lu_name *lname = NULL;
924 const char *name = NULL;
926 struct mdt_lock_handle *lhp = NULL;
927 struct ldlm_lock *lock;
928 struct ldlm_res_id *res_id;
935 is_resent = lustre_handle_is_used(&lhc->mlh_reg_lh);
936 LASSERT(ergo(is_resent,
937 lustre_msg_get_flags(req->rq_reqmsg) & MSG_RESENT));
939 LASSERT(parent != NULL);
940 name = req_capsule_client_get(info->mti_pill, &RMF_NAME);
942 RETURN(err_serious(-EFAULT));
944 namelen = req_capsule_get_size(info->mti_pill, &RMF_NAME,
946 if (!info->mti_cross_ref) {
948 * XXX: Check for "namelen == 0" is for getattr by fid
949 * (OBD_CONNECT_ATTRFID), otherwise do not allow empty name,
950 * that is the name must contain at least one character and
951 * the terminating '\0'
954 reqbody = req_capsule_client_get(info->mti_pill,
956 if (unlikely(reqbody == NULL))
957 RETURN(err_serious(-EFAULT));
959 if (unlikely(!fid_is_sane(&reqbody->fid2)))
960 RETURN(err_serious(-EINVAL));
963 CDEBUG(D_INODE, "getattr with lock for "DFID"/"DFID", "
965 PFID(mdt_object_fid(parent)),
966 PFID(&reqbody->fid2), ldlm_rep);
968 lname = mdt_name(info->mti_env, (char *)name, namelen);
969 CDEBUG(D_INODE, "getattr with lock for "DFID"/%s, "
970 "ldlm_rep = %p\n", PFID(mdt_object_fid(parent)),
974 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_EXECD);
976 rc = mdt_object_exists(parent);
977 if (unlikely(rc == 0)) {
978 LU_OBJECT_DEBUG(D_INODE, info->mti_env,
979 &parent->mot_obj.mo_lu,
980 "Parent doesn't exist!\n");
982 } else if (!info->mti_cross_ref) {
983 LASSERTF(rc > 0, "Parent "DFID" is on remote server\n",
984 PFID(mdt_object_fid(parent)));
987 rc = mdt_raw_lookup(info, parent, lname, ldlm_rep);
995 if (info->mti_cross_ref) {
996 /* Only getattr on the child. Parent is on another node. */
997 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_POS);
999 CDEBUG(D_INODE, "partial getattr_name child_fid = "DFID", "
1000 "ldlm_rep=%p\n", PFID(mdt_object_fid(child)), ldlm_rep);
1003 /* Do not take lock for resent case. */
1004 lock = ldlm_handle2lock(&lhc->mlh_reg_lh);
1005 LASSERTF(lock != NULL, "Invalid lock handle "LPX64"\n",
1006 lhc->mlh_reg_lh.cookie);
1007 LASSERT(fid_res_name_eq(mdt_object_fid(child),
1008 &lock->l_resource->lr_name));
1009 LDLM_LOCK_PUT(lock);
1012 mdt_lock_handle_init(lhc);
1013 mdt_lock_reg_init(lhc, LCK_PR);
1016 * Object's name is on another MDS, no lookup lock is
1017 * needed here but update is.
1019 child_bits &= ~MDS_INODELOCK_LOOKUP;
1020 child_bits |= MDS_INODELOCK_UPDATE;
1022 rc = mdt_object_lock(info, child, lhc, child_bits,
1026 /* Finally, we can get attr for child. */
1027 mdt_set_capainfo(info, 0, mdt_object_fid(child),
1029 rc = mdt_getattr_internal(info, child, 0);
1030 if (unlikely(rc != 0))
1031 mdt_object_unlock(info, child, lhc, 1);
1037 /* step 1: lock parent only if parent is a directory */
1038 if (S_ISDIR(lu_object_attr(&parent->mot_obj.mo_lu))) {
1039 lhp = &info->mti_lh[MDT_LH_PARENT];
1040 mdt_lock_pdo_init(lhp, LCK_PR, name, namelen);
1041 rc = mdt_object_lock(info, parent, lhp,
1042 MDS_INODELOCK_UPDATE,
1044 if (unlikely(rc != 0))
1048 /* step 2: lookup child's fid by name */
1049 fid_zero(child_fid);
1050 rc = mdo_lookup(info->mti_env, next, lname, child_fid,
1055 mdt_set_disposition(info, ldlm_rep,
1057 GOTO(out_parent, rc);
1059 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_POS);
1061 *child_fid = reqbody->fid2;
1062 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_POS);
1066 *step 3: find the child object by fid & lock it.
1067 * regardless if it is local or remote.
1069 child = mdt_object_find(info->mti_env, info->mti_mdt, child_fid);
1071 if (unlikely(IS_ERR(child)))
1072 GOTO(out_parent, rc = PTR_ERR(child));
1074 /* Do not take lock for resent case. */
1075 lock = ldlm_handle2lock(&lhc->mlh_reg_lh);
1076 LASSERTF(lock != NULL, "Invalid lock handle "LPX64"\n",
1077 lhc->mlh_reg_lh.cookie);
1079 res_id = &lock->l_resource->lr_name;
1080 if (!fid_res_name_eq(mdt_object_fid(child),
1081 &lock->l_resource->lr_name)) {
1082 LASSERTF(fid_res_name_eq(mdt_object_fid(parent),
1083 &lock->l_resource->lr_name),
1084 "Lock res_id: %lu/%lu/%lu, Fid: "DFID".\n",
1085 (unsigned long)res_id->name[0],
1086 (unsigned long)res_id->name[1],
1087 (unsigned long)res_id->name[2],
1088 PFID(mdt_object_fid(parent)));
1089 CWARN("Although resent, but still not get child lock"
1090 "parent:"DFID" child:"DFID"\n",
1091 PFID(mdt_object_fid(parent)),
1092 PFID(mdt_object_fid(child)));
1093 lustre_msg_clear_flags(req->rq_reqmsg, MSG_RESENT);
1094 LDLM_LOCK_PUT(lock);
1097 LDLM_LOCK_PUT(lock);
1101 OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_RESEND, obd_timeout*2);
1102 mdt_lock_handle_init(lhc);
1103 if (child_bits == MDS_INODELOCK_LAYOUT)
1104 mdt_lock_reg_init(lhc, LCK_CR);
1106 mdt_lock_reg_init(lhc, LCK_PR);
1108 if (mdt_object_exists(child) == 0) {
1109 LU_OBJECT_DEBUG(D_INODE, info->mti_env,
1110 &child->mot_obj.mo_lu,
1111 "Object doesn't exist!\n");
1112 GOTO(out_child, rc = -ENOENT);
1115 if (!(child_bits & MDS_INODELOCK_UPDATE)) {
1116 struct md_attr *ma = &info->mti_attr;
1119 ma->ma_need = MA_INODE;
1120 rc = mo_attr_get(info->mti_env,
1121 mdt_object_child(child), ma);
1122 if (unlikely(rc != 0))
1123 GOTO(out_child, rc);
1125 /* layout lock is used only on regular files */
1126 if ((ma->ma_valid & MA_INODE) &&
1127 (ma->ma_attr.la_valid & LA_MODE) &&
1128 !S_ISREG(ma->ma_attr.la_mode))
1129 child_bits &= ~MDS_INODELOCK_LAYOUT;
1131 /* If the file has not been changed for some time, we
1132 * return not only a LOOKUP lock, but also an UPDATE
1133 * lock and this might save us RPC on later STAT. For
1134 * directories, it also let negative dentry starts
1135 * working for this dir. */
1136 if (ma->ma_valid & MA_INODE &&
1137 ma->ma_attr.la_valid & LA_CTIME &&
1138 info->mti_mdt->mdt_namespace->ns_ctime_age_limit +
1139 ma->ma_attr.la_ctime < cfs_time_current_sec())
1140 child_bits |= MDS_INODELOCK_UPDATE;
1143 rc = mdt_object_lock(info, child, lhc, child_bits,
1146 if (unlikely(rc != 0))
1147 GOTO(out_child, rc);
1150 lock = ldlm_handle2lock(&lhc->mlh_reg_lh);
1151 /* Get MA_SOM attributes if update lock is given. */
1153 lock->l_policy_data.l_inodebits.bits & MDS_INODELOCK_UPDATE &&
1154 S_ISREG(lu_object_attr(&mdt_object_child(child)->mo_lu)))
1157 /* finally, we can get attr for child. */
1158 mdt_set_capainfo(info, 1, child_fid, BYPASS_CAPA);
1159 rc = mdt_getattr_internal(info, child, ma_need);
1160 if (unlikely(rc != 0)) {
1161 mdt_object_unlock(info, child, lhc, 1);
1163 /* Debugging code. */
1164 res_id = &lock->l_resource->lr_name;
1165 LDLM_DEBUG(lock, "Returning lock to client");
1166 LASSERTF(fid_res_name_eq(mdt_object_fid(child),
1167 &lock->l_resource->lr_name),
1168 "Lock res_id: %lu/%lu/%lu, Fid: "DFID".\n",
1169 (unsigned long)res_id->name[0],
1170 (unsigned long)res_id->name[1],
1171 (unsigned long)res_id->name[2],
1172 PFID(mdt_object_fid(child)));
1173 mdt_pack_size2body(info, child);
1176 LDLM_LOCK_PUT(lock);
1180 mdt_object_put(info->mti_env, child);
1183 mdt_object_unlock(info, parent, lhp, 1);
1187 /* normal handler: should release the child lock */
1188 static int mdt_getattr_name(struct mdt_thread_info *info)
1190 struct mdt_lock_handle *lhc = &info->mti_lh[MDT_LH_CHILD];
1191 struct mdt_body *reqbody;
1192 struct mdt_body *repbody;
1196 reqbody = req_capsule_client_get(info->mti_pill, &RMF_MDT_BODY);
1197 LASSERT(reqbody != NULL);
1198 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
1199 LASSERT(repbody != NULL);
1201 info->mti_spec.sp_ck_split = !!(reqbody->valid & OBD_MD_FLCKSPLIT);
1202 info->mti_cross_ref = !!(reqbody->valid & OBD_MD_FLCROSSREF);
1203 repbody->eadatasize = 0;
1204 repbody->aclsize = 0;
1206 rc = mdt_init_ucred(info, reqbody);
1208 GOTO(out_shrink, rc);
1210 rc = mdt_getattr_name_lock(info, lhc, MDS_INODELOCK_UPDATE, NULL);
1211 if (lustre_handle_is_used(&lhc->mlh_reg_lh)) {
1212 ldlm_lock_decref(&lhc->mlh_reg_lh, lhc->mlh_reg_mode);
1213 lhc->mlh_reg_lh.cookie = 0;
1215 mdt_exit_ucred(info);
1218 mdt_client_compatibility(info);
1219 rc2 = mdt_fix_reply(info);
1225 static const struct lu_device_operations mdt_lu_ops;
1227 static int lu_device_is_mdt(struct lu_device *d)
1229 return ergo(d != NULL && d->ld_ops != NULL, d->ld_ops == &mdt_lu_ops);
1232 static int mdt_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
1233 void *karg, void *uarg);
1235 static int mdt_set_info(struct mdt_thread_info *info)
1237 struct ptlrpc_request *req = mdt_info_req(info);
1240 int keylen, vallen, rc = 0;
1243 rc = req_capsule_server_pack(info->mti_pill);
1247 key = req_capsule_client_get(info->mti_pill, &RMF_SETINFO_KEY);
1249 DEBUG_REQ(D_HA, req, "no set_info key");
1253 keylen = req_capsule_get_size(info->mti_pill, &RMF_SETINFO_KEY,
1256 val = req_capsule_client_get(info->mti_pill, &RMF_SETINFO_VAL);
1258 DEBUG_REQ(D_HA, req, "no set_info val");
1262 vallen = req_capsule_get_size(info->mti_pill, &RMF_SETINFO_VAL,
1265 /* Swab any part of val you need to here */
1266 if (KEY_IS(KEY_READ_ONLY)) {
1268 lustre_msg_set_status(req->rq_repmsg, 0);
1270 cfs_spin_lock(&req->rq_export->exp_lock);
1272 req->rq_export->exp_connect_flags |= OBD_CONNECT_RDONLY;
1274 req->rq_export->exp_connect_flags &=~OBD_CONNECT_RDONLY;
1275 cfs_spin_unlock(&req->rq_export->exp_lock);
1277 } else if (KEY_IS(KEY_CHANGELOG_CLEAR)) {
1278 struct changelog_setinfo *cs =
1279 (struct changelog_setinfo *)val;
1280 if (vallen != sizeof(*cs)) {
1281 CERROR("Bad changelog_clear setinfo size %d\n", vallen);
1284 if (ptlrpc_req_need_swab(req)) {
1285 __swab64s(&cs->cs_recno);
1286 __swab32s(&cs->cs_id);
1289 rc = mdt_iocontrol(OBD_IOC_CHANGELOG_CLEAR, info->mti_exp,
1291 lustre_msg_set_status(req->rq_repmsg, rc);
1299 static int mdt_connect(struct mdt_thread_info *info)
1302 struct ptlrpc_request *req;
1304 req = mdt_info_req(info);
1305 rc = target_handle_connect(req);
1307 LASSERT(req->rq_export != NULL);
1308 info->mti_mdt = mdt_dev(req->rq_export->exp_obd->obd_lu_dev);
1309 rc = mdt_init_sec_level(info);
1311 rc = mdt_init_idmap(info);
1313 obd_disconnect(class_export_get(req->rq_export));
1315 rc = err_serious(rc);
1320 static int mdt_disconnect(struct mdt_thread_info *info)
1325 rc = target_handle_disconnect(mdt_info_req(info));
1327 rc = err_serious(rc);
1331 static int mdt_sendpage(struct mdt_thread_info *info,
1332 struct lu_rdpg *rdpg, int nob)
1334 struct ptlrpc_request *req = mdt_info_req(info);
1335 struct obd_export *exp = req->rq_export;
1336 struct ptlrpc_bulk_desc *desc;
1337 struct l_wait_info *lwi = &info->mti_u.rdpg.mti_wait_info;
1344 desc = ptlrpc_prep_bulk_exp(req, rdpg->rp_npages, BULK_PUT_SOURCE,
1349 if (!(exp->exp_connect_flags & OBD_CONNECT_BRW_SIZE))
1350 /* old client requires reply size in it's PAGE_SIZE,
1351 * which is rdpg->rp_count */
1352 nob = rdpg->rp_count;
1354 for (i = 0, tmpcount = nob; i < rdpg->rp_npages && tmpcount > 0;
1355 i++, tmpcount -= tmpsize) {
1356 tmpsize = min_t(int, tmpcount, CFS_PAGE_SIZE);
1357 ptlrpc_prep_bulk_page(desc, rdpg->rp_pages[i], 0, tmpsize);
1360 LASSERT(desc->bd_nob == nob);
1361 rc = target_bulk_io(exp, desc, lwi);
1362 ptlrpc_free_bulk(desc);
1366 #ifdef HAVE_SPLIT_SUPPORT
1368 * Retrieve dir entry from the page and insert it to the slave object, actually,
1369 * this should be in osd layer, but since it will not in the final product, so
1370 * just do it here and do not define more moo api anymore for this.
1372 static int mdt_write_dir_page(struct mdt_thread_info *info, struct page *page,
1375 struct mdt_object *object = info->mti_object;
1376 struct lu_fid *lf = &info->mti_tmp_fid2;
1377 struct md_attr *ma = &info->mti_attr;
1378 struct lu_dirpage *dp;
1379 struct lu_dirent *ent;
1380 int rc = 0, offset = 0;
1383 /* Make sure we have at least one entry. */
1388 * Disable trans for this name insert, since it will include many trans
1391 info->mti_no_need_trans = 1;
1393 * When write_dir_page, no need update parent's ctime,
1394 * and no permission check for name_insert.
1396 ma->ma_attr.la_ctime = 0;
1397 ma->ma_attr.la_valid = LA_MODE;
1398 ma->ma_valid = MA_INODE;
1401 dp = page_address(page);
1402 offset = (int)((__u32)lu_dirent_start(dp) - (__u32)dp);
1404 for (ent = lu_dirent_start(dp); ent != NULL;
1405 ent = lu_dirent_next(ent)) {
1406 struct lu_name *lname;
1409 if (le16_to_cpu(ent->lde_namelen) == 0)
1412 fid_le_to_cpu(lf, &ent->lde_fid);
1413 if (le64_to_cpu(ent->lde_hash) & MAX_HASH_HIGHEST_BIT)
1414 ma->ma_attr.la_mode = S_IFDIR;
1416 ma->ma_attr.la_mode = 0;
1417 OBD_ALLOC(name, le16_to_cpu(ent->lde_namelen) + 1);
1419 GOTO(out, rc = -ENOMEM);
1421 memcpy(name, ent->lde_name, le16_to_cpu(ent->lde_namelen));
1422 lname = mdt_name(info->mti_env, name,
1423 le16_to_cpu(ent->lde_namelen));
1424 ma->ma_attr_flags |= (MDS_PERM_BYPASS | MDS_QUOTA_IGNORE);
1425 rc = mdo_name_insert(info->mti_env,
1426 md_object_next(&object->mot_obj),
1428 OBD_FREE(name, le16_to_cpu(ent->lde_namelen) + 1);
1430 CERROR("Can't insert %*.*s, rc %d\n",
1431 le16_to_cpu(ent->lde_namelen),
1432 le16_to_cpu(ent->lde_namelen),
1437 offset += lu_dirent_size(ent);
1447 static int mdt_bulk_timeout(void *data)
1451 CERROR("mdt bulk transfer timeout \n");
1456 static int mdt_writepage(struct mdt_thread_info *info)
1458 struct ptlrpc_request *req = mdt_info_req(info);
1459 struct mdt_body *reqbody;
1460 struct l_wait_info *lwi;
1461 struct ptlrpc_bulk_desc *desc;
1467 reqbody = req_capsule_client_get(info->mti_pill, &RMF_MDT_BODY);
1468 if (reqbody == NULL)
1469 RETURN(err_serious(-EFAULT));
1471 desc = ptlrpc_prep_bulk_exp(req, 1, BULK_GET_SINK, MDS_BULK_PORTAL);
1473 RETURN(err_serious(-ENOMEM));
1475 /* allocate the page for the desc */
1476 page = cfs_alloc_page(CFS_ALLOC_STD);
1478 GOTO(desc_cleanup, rc = -ENOMEM);
1480 CDEBUG(D_INFO, "Received page offset %d size %d \n",
1481 (int)reqbody->size, (int)reqbody->nlink);
1483 ptlrpc_prep_bulk_page(desc, page, (int)reqbody->size,
1484 (int)reqbody->nlink);
1486 rc = sptlrpc_svc_prep_bulk(req, desc);
1488 GOTO(cleanup_page, rc);
1490 * Check if client was evicted while we were doing i/o before touching
1495 GOTO(cleanup_page, rc = -ENOMEM);
1497 if (desc->bd_export->exp_failed)
1500 rc = ptlrpc_start_bulk_transfer (desc);
1502 *lwi = LWI_TIMEOUT_INTERVAL(obd_timeout * CFS_HZ / 4, CFS_HZ,
1503 mdt_bulk_timeout, desc);
1504 rc = l_wait_event(desc->bd_waitq, !ptlrpc_bulk_active(desc) ||
1505 desc->bd_export->exp_failed, lwi);
1506 LASSERT(rc == 0 || rc == -ETIMEDOUT);
1507 if (rc == -ETIMEDOUT) {
1508 DEBUG_REQ(D_ERROR, req, "timeout on bulk GET");
1509 ptlrpc_abort_bulk(desc);
1510 } else if (desc->bd_export->exp_failed) {
1511 DEBUG_REQ(D_ERROR, req, "Eviction on bulk GET");
1513 ptlrpc_abort_bulk(desc);
1514 } else if (!desc->bd_success ||
1515 desc->bd_nob_transferred != desc->bd_nob) {
1516 DEBUG_REQ(D_ERROR, req, "%s bulk GET %d(%d)",
1518 "truncated" : "network error on",
1519 desc->bd_nob_transferred, desc->bd_nob);
1520 /* XXX should this be a different errno? */
1524 DEBUG_REQ(D_ERROR, req, "ptlrpc_bulk_get failed: rc %d", rc);
1527 GOTO(cleanup_lwi, rc);
1528 rc = mdt_write_dir_page(info, page, reqbody->nlink);
1533 cfs_free_page(page);
1535 ptlrpc_free_bulk(desc);
1540 static int mdt_readpage(struct mdt_thread_info *info)
1542 struct mdt_object *object = info->mti_object;
1543 struct lu_rdpg *rdpg = &info->mti_u.rdpg.mti_rdpg;
1544 struct mdt_body *reqbody;
1545 struct mdt_body *repbody;
1550 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_READPAGE_PACK))
1551 RETURN(err_serious(-ENOMEM));
1553 reqbody = req_capsule_client_get(info->mti_pill, &RMF_MDT_BODY);
1554 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
1555 if (reqbody == NULL || repbody == NULL)
1556 RETURN(err_serious(-EFAULT));
1559 * prepare @rdpg before calling lower layers and transfer itself. Here
1560 * reqbody->size contains offset of where to start to read and
1561 * reqbody->nlink contains number bytes to read.
1563 rdpg->rp_hash = reqbody->size;
1564 if (rdpg->rp_hash != reqbody->size) {
1565 CERROR("Invalid hash: "LPX64" != "LPX64"\n",
1566 rdpg->rp_hash, reqbody->size);
1570 rdpg->rp_attrs = reqbody->mode;
1571 if (info->mti_exp->exp_connect_flags & OBD_CONNECT_64BITHASH)
1572 rdpg->rp_attrs |= LUDA_64BITHASH;
1573 rdpg->rp_count = min_t(unsigned int, reqbody->nlink,
1574 PTLRPC_MAX_BRW_SIZE);
1575 rdpg->rp_npages = (rdpg->rp_count + CFS_PAGE_SIZE - 1) >>
1577 OBD_ALLOC(rdpg->rp_pages, rdpg->rp_npages * sizeof rdpg->rp_pages[0]);
1578 if (rdpg->rp_pages == NULL)
1581 for (i = 0; i < rdpg->rp_npages; ++i) {
1582 rdpg->rp_pages[i] = cfs_alloc_page(CFS_ALLOC_STD);
1583 if (rdpg->rp_pages[i] == NULL)
1584 GOTO(free_rdpg, rc = -ENOMEM);
1587 /* call lower layers to fill allocated pages with directory data */
1588 rc = mo_readpage(info->mti_env, mdt_object_child(object), rdpg);
1590 GOTO(free_rdpg, rc);
1592 /* send pages to client */
1593 rc = mdt_sendpage(info, rdpg, rc);
1598 for (i = 0; i < rdpg->rp_npages; i++)
1599 if (rdpg->rp_pages[i] != NULL)
1600 cfs_free_page(rdpg->rp_pages[i]);
1601 OBD_FREE(rdpg->rp_pages, rdpg->rp_npages * sizeof rdpg->rp_pages[0]);
1603 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_SENDPAGE))
1609 static int mdt_reint_internal(struct mdt_thread_info *info,
1610 struct mdt_lock_handle *lhc,
1613 struct req_capsule *pill = info->mti_pill;
1614 struct md_quota *mq = md_quota(info->mti_env);
1615 struct mdt_body *repbody;
1620 rc = mdt_reint_unpack(info, op);
1622 CERROR("Can't unpack reint, rc %d\n", rc);
1623 RETURN(err_serious(rc));
1626 /* for replay (no_create) lmm is not needed, client has it already */
1627 if (req_capsule_has_field(pill, &RMF_MDT_MD, RCL_SERVER))
1628 req_capsule_set_size(pill, &RMF_MDT_MD, RCL_SERVER,
1629 info->mti_rr.rr_eadatalen);
1631 if (req_capsule_has_field(pill, &RMF_LOGCOOKIES, RCL_SERVER))
1632 req_capsule_set_size(pill, &RMF_LOGCOOKIES, RCL_SERVER,
1633 info->mti_mdt->mdt_max_cookiesize);
1635 rc = req_capsule_server_pack(pill);
1637 CERROR("Can't pack response, rc %d\n", rc);
1638 RETURN(err_serious(rc));
1641 if (req_capsule_has_field(pill, &RMF_MDT_BODY, RCL_SERVER)) {
1642 repbody = req_capsule_server_get(pill, &RMF_MDT_BODY);
1644 repbody->eadatasize = 0;
1645 repbody->aclsize = 0;
1648 OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_REINT_DELAY, 10);
1650 /* for replay no cookkie / lmm need, because client have this already */
1651 if (info->mti_spec.no_create)
1652 if (req_capsule_has_field(pill, &RMF_MDT_MD, RCL_SERVER))
1653 req_capsule_set_size(pill, &RMF_MDT_MD, RCL_SERVER, 0);
1655 rc = mdt_init_ucred_reint(info);
1657 GOTO(out_shrink, rc);
1659 rc = mdt_fix_attr_ucred(info, op);
1661 GOTO(out_ucred, rc = err_serious(rc));
1663 if (mdt_check_resent(info, mdt_reconstruct, lhc)) {
1664 rc = lustre_msg_get_status(mdt_info_req(info)->rq_repmsg);
1665 GOTO(out_ucred, rc);
1667 mq->mq_exp = info->mti_exp;
1668 rc = mdt_reint_rec(info, lhc);
1671 mdt_exit_ucred(info);
1673 mdt_client_compatibility(info);
1674 rc2 = mdt_fix_reply(info);
1680 static long mdt_reint_opcode(struct mdt_thread_info *info,
1681 const struct req_format **fmt)
1683 struct mdt_rec_reint *rec;
1686 opc = err_serious(-EFAULT);
1687 rec = req_capsule_client_get(info->mti_pill, &RMF_REC_REINT);
1689 opc = rec->rr_opcode;
1690 DEBUG_REQ(D_INODE, mdt_info_req(info), "reint opt = %ld", opc);
1691 if (opc < REINT_MAX && fmt[opc] != NULL)
1692 req_capsule_extend(info->mti_pill, fmt[opc]);
1694 CERROR("Unsupported opc: %ld\n", opc);
1695 opc = err_serious(opc);
1701 static int mdt_reint(struct mdt_thread_info *info)
1706 static const struct req_format *reint_fmts[REINT_MAX] = {
1707 [REINT_SETATTR] = &RQF_MDS_REINT_SETATTR,
1708 [REINT_CREATE] = &RQF_MDS_REINT_CREATE,
1709 [REINT_LINK] = &RQF_MDS_REINT_LINK,
1710 [REINT_UNLINK] = &RQF_MDS_REINT_UNLINK,
1711 [REINT_RENAME] = &RQF_MDS_REINT_RENAME,
1712 [REINT_OPEN] = &RQF_MDS_REINT_OPEN,
1713 [REINT_SETXATTR] = &RQF_MDS_REINT_SETXATTR
1718 opc = mdt_reint_opcode(info, reint_fmts);
1721 * No lock possible here from client to pass it to reint code
1724 rc = mdt_reint_internal(info, NULL, opc);
1729 info->mti_fail_id = OBD_FAIL_MDS_REINT_NET_REP;
1733 /* this should sync the whole device */
1734 static int mdt_device_sync(const struct lu_env *env, struct mdt_device *mdt)
1736 struct dt_device *dt = mdt->mdt_bottom;
1740 rc = dt->dd_ops->dt_sync(env, dt);
1744 /* this should sync this object */
1745 static int mdt_object_sync(struct mdt_thread_info *info)
1747 struct md_object *next;
1751 if (!mdt_object_exists(info->mti_object)) {
1752 CWARN("Non existing object "DFID"!\n",
1753 PFID(mdt_object_fid(info->mti_object)));
1756 next = mdt_object_child(info->mti_object);
1757 rc = mo_object_sync(info->mti_env, next);
1762 static int mdt_sync(struct mdt_thread_info *info)
1764 struct ptlrpc_request *req = mdt_info_req(info);
1765 struct req_capsule *pill = info->mti_pill;
1766 struct mdt_body *body;
1770 /* The fid may be zero, so we req_capsule_set manually */
1771 req_capsule_set(pill, &RQF_MDS_SYNC);
1773 body = req_capsule_client_get(pill, &RMF_MDT_BODY);
1775 RETURN(err_serious(-EINVAL));
1777 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_SYNC_PACK))
1778 RETURN(err_serious(-ENOMEM));
1780 if (fid_seq(&body->fid1) == 0) {
1781 /* sync the whole device */
1782 rc = req_capsule_server_pack(pill);
1784 rc = mdt_device_sync(info->mti_env, info->mti_mdt);
1786 rc = err_serious(rc);
1788 /* sync an object */
1789 rc = mdt_unpack_req_pack_rep(info, HABEO_CORPUS|HABEO_REFERO);
1791 rc = mdt_object_sync(info);
1793 struct md_object *next;
1794 const struct lu_fid *fid;
1795 struct lu_attr *la = &info->mti_attr.ma_attr;
1797 next = mdt_object_child(info->mti_object);
1798 info->mti_attr.ma_need = MA_INODE;
1799 info->mti_attr.ma_valid = 0;
1800 rc = mo_attr_get(info->mti_env, next,
1803 body = req_capsule_server_get(pill,
1805 fid = mdt_object_fid(info->mti_object);
1806 mdt_pack_attr2body(info, body, la, fid);
1810 rc = err_serious(rc);
1813 mdt_counter_incr(req, LPROC_MDT_SYNC);
1818 #ifdef HAVE_QUOTA_SUPPORT
1819 static int mdt_quotacheck_handle(struct mdt_thread_info *info)
1821 struct obd_quotactl *oqctl;
1822 struct req_capsule *pill = info->mti_pill;
1823 struct obd_export *exp = info->mti_exp;
1824 struct md_quota *mq = md_quota(info->mti_env);
1825 struct md_device *next = info->mti_mdt->mdt_child;
1829 oqctl = req_capsule_client_get(pill, &RMF_OBD_QUOTACTL);
1833 /* remote client has no permission for quotacheck */
1834 if (unlikely(exp_connect_rmtclient(exp)))
1837 rc = req_capsule_server_pack(pill);
1842 rc = next->md_ops->mdo_quota.mqo_check(info->mti_env, next,
1847 static int mdt_quotactl_handle(struct mdt_thread_info *info)
1849 struct obd_quotactl *oqctl, *repoqc;
1850 struct req_capsule *pill = info->mti_pill;
1851 struct obd_export *exp = info->mti_exp;
1852 struct md_quota *mq = md_quota(info->mti_env);
1853 struct md_device *next = info->mti_mdt->mdt_child;
1854 const struct md_quota_operations *mqo = &next->md_ops->mdo_quota;
1858 oqctl = req_capsule_client_get(pill, &RMF_OBD_QUOTACTL);
1863 if (exp_connect_rmtclient(exp)) {
1864 struct ptlrpc_request *req = mdt_info_req(info);
1865 struct mdt_export_data *med = mdt_req2med(req);
1866 struct lustre_idmap_table *idmap = med->med_idmap;
1868 if (unlikely(oqctl->qc_cmd != Q_GETQUOTA &&
1869 oqctl->qc_cmd != Q_GETINFO))
1873 if (oqctl->qc_type == USRQUOTA)
1874 id = lustre_idmap_lookup_uid(NULL, idmap, 0,
1876 else if (oqctl->qc_type == GRPQUOTA)
1877 id = lustre_idmap_lookup_gid(NULL, idmap, 0,
1882 if (id == CFS_IDMAP_NOTFOUND) {
1883 CDEBUG(D_QUOTA, "no mapping for id %u\n",
1889 rc = req_capsule_server_pack(pill);
1893 repoqc = req_capsule_server_get(pill, &RMF_OBD_QUOTACTL);
1894 LASSERT(repoqc != NULL);
1897 switch (oqctl->qc_cmd) {
1899 rc = mqo->mqo_on(info->mti_env, next, oqctl->qc_type);
1902 rc = mqo->mqo_off(info->mti_env, next, oqctl->qc_type);
1905 rc = mqo->mqo_setinfo(info->mti_env, next, oqctl->qc_type, id,
1909 rc = mqo->mqo_getinfo(info->mti_env, next, oqctl->qc_type, id,
1913 rc = mqo->mqo_setquota(info->mti_env, next, oqctl->qc_type, id,
1917 rc = mqo->mqo_getquota(info->mti_env, next, oqctl->qc_type, id,
1921 rc = mqo->mqo_getoinfo(info->mti_env, next, oqctl->qc_type, id,
1925 rc = mqo->mqo_getoquota(info->mti_env, next, oqctl->qc_type, id,
1928 case LUSTRE_Q_INVALIDATE:
1929 rc = mqo->mqo_invalidate(info->mti_env, next, oqctl->qc_type);
1931 case LUSTRE_Q_FINVALIDATE:
1932 rc = mqo->mqo_finvalidate(info->mti_env, next, oqctl->qc_type);
1935 CERROR("unsupported mdt_quotactl command: %d\n",
1947 * OBD PING and other handlers.
1949 static int mdt_obd_ping(struct mdt_thread_info *info)
1954 req_capsule_set(info->mti_pill, &RQF_OBD_PING);
1956 rc = target_handle_ping(mdt_info_req(info));
1958 rc = err_serious(rc);
1963 * OBD_IDX_READ handler
1965 static int mdt_obd_idx_read(struct mdt_thread_info *info)
1967 struct mdt_device *mdt = info->mti_mdt;
1968 struct lu_rdpg *rdpg = &info->mti_u.rdpg.mti_rdpg;
1969 struct idx_info *req_ii, *rep_ii;
1973 memset(rdpg, 0, sizeof(*rdpg));
1974 req_capsule_set(info->mti_pill, &RQF_OBD_IDX_READ);
1976 /* extract idx_info buffer from request & reply */
1977 req_ii = req_capsule_client_get(info->mti_pill, &RMF_IDX_INFO);
1978 if (req_ii == NULL || req_ii->ii_magic != IDX_INFO_MAGIC)
1979 RETURN(err_serious(-EPROTO));
1981 rc = req_capsule_server_pack(info->mti_pill);
1983 RETURN(err_serious(rc));
1985 rep_ii = req_capsule_server_get(info->mti_pill, &RMF_IDX_INFO);
1987 RETURN(err_serious(-EFAULT));
1988 rep_ii->ii_magic = IDX_INFO_MAGIC;
1990 /* extract hash to start with */
1991 rdpg->rp_hash = req_ii->ii_hash_start;
1993 /* extract requested attributes */
1994 rdpg->rp_attrs = req_ii->ii_attrs;
1996 /* check that fid packed in request is valid and supported */
1997 if (!fid_is_sane(&req_ii->ii_fid))
1999 rep_ii->ii_fid = req_ii->ii_fid;
2002 rep_ii->ii_flags = req_ii->ii_flags;
2004 /* compute number of pages to allocate, ii_count is the number of 4KB
2006 if (req_ii->ii_count <= 0)
2007 GOTO(out, rc = -EFAULT);
2008 rdpg->rp_count = min_t(unsigned int, req_ii->ii_count << LU_PAGE_SHIFT,
2009 PTLRPC_MAX_BRW_SIZE);
2010 rdpg->rp_npages = (rdpg->rp_count + CFS_PAGE_SIZE -1) >> CFS_PAGE_SHIFT;
2012 /* allocate pages to store the containers */
2013 OBD_ALLOC(rdpg->rp_pages, rdpg->rp_npages * sizeof(rdpg->rp_pages[0]));
2014 if (rdpg->rp_pages == NULL)
2015 GOTO(out, rc = -ENOMEM);
2016 for (i = 0; i < rdpg->rp_npages; i++) {
2017 rdpg->rp_pages[i] = cfs_alloc_page(CFS_ALLOC_STD);
2018 if (rdpg->rp_pages[i] == NULL)
2019 GOTO(out, rc = -ENOMEM);
2022 /* populate pages with key/record pairs */
2023 rc = dt_index_read(info->mti_env, mdt->mdt_bottom, rep_ii, rdpg);
2027 LASSERTF(rc <= rdpg->rp_count, "dt_index_read() returned more than "
2028 "asked %d > %d\n", rc, rdpg->rp_count);
2030 /* send pages to client */
2031 rc = mdt_sendpage(info, rdpg, rc);
2035 if (rdpg->rp_pages) {
2036 for (i = 0; i < rdpg->rp_npages; i++)
2037 if (rdpg->rp_pages[i])
2038 cfs_free_page(rdpg->rp_pages[i]);
2039 OBD_FREE(rdpg->rp_pages,
2040 rdpg->rp_npages * sizeof(rdpg->rp_pages[0]));
2045 static int mdt_obd_log_cancel(struct mdt_thread_info *info)
2047 return err_serious(-EOPNOTSUPP);
2050 static int mdt_obd_qc_callback(struct mdt_thread_info *info)
2052 return err_serious(-EOPNOTSUPP);
2060 /** clone llog ctxt from child (mdd)
2061 * This allows remote llog (replicator) access.
2062 * We can either pass all llog RPCs (eg mdt_llog_create) on to child where the
2063 * context was originally set up, or we can handle them directly.
2064 * I choose the latter, but that means I need any llog
2065 * contexts set up by child to be accessable by the mdt. So we clone the
2066 * context into our context list here.
2068 static int mdt_llog_ctxt_clone(const struct lu_env *env, struct mdt_device *mdt,
2071 struct md_device *next = mdt->mdt_child;
2072 struct llog_ctxt *ctxt;
2075 if (!llog_ctxt_null(mdt2obd_dev(mdt), idx))
2078 rc = next->md_ops->mdo_llog_ctxt_get(env, next, idx, (void **)&ctxt);
2079 if (rc || ctxt == NULL) {
2080 CERROR("Can't get mdd ctxt %d\n", rc);
2084 rc = llog_group_set_ctxt(&mdt2obd_dev(mdt)->obd_olg, ctxt, idx);
2086 CERROR("Can't set mdt ctxt %d\n", rc);
2091 static int mdt_llog_ctxt_unclone(const struct lu_env *env,
2092 struct mdt_device *mdt, int idx)
2094 struct llog_ctxt *ctxt;
2096 ctxt = llog_get_context(mdt2obd_dev(mdt), idx);
2099 /* Put once for the get we just did, and once for the clone */
2100 llog_ctxt_put(ctxt);
2101 llog_ctxt_put(ctxt);
2105 static int mdt_llog_create(struct mdt_thread_info *info)
2109 req_capsule_set(info->mti_pill, &RQF_LLOG_ORIGIN_HANDLE_CREATE);
2110 rc = llog_origin_handle_open(mdt_info_req(info));
2111 return (rc < 0 ? err_serious(rc) : rc);
2114 static int mdt_llog_destroy(struct mdt_thread_info *info)
2118 req_capsule_set(info->mti_pill, &RQF_LLOG_ORIGIN_HANDLE_DESTROY);
2119 rc = llog_origin_handle_destroy(mdt_info_req(info));
2120 return (rc < 0 ? err_serious(rc) : rc);
2123 static int mdt_llog_read_header(struct mdt_thread_info *info)
2127 req_capsule_set(info->mti_pill, &RQF_LLOG_ORIGIN_HANDLE_READ_HEADER);
2128 rc = llog_origin_handle_read_header(mdt_info_req(info));
2129 return (rc < 0 ? err_serious(rc) : rc);
2132 static int mdt_llog_next_block(struct mdt_thread_info *info)
2136 req_capsule_set(info->mti_pill, &RQF_LLOG_ORIGIN_HANDLE_NEXT_BLOCK);
2137 rc = llog_origin_handle_next_block(mdt_info_req(info));
2138 return (rc < 0 ? err_serious(rc) : rc);
2141 static int mdt_llog_prev_block(struct mdt_thread_info *info)
2145 req_capsule_set(info->mti_pill, &RQF_LLOG_ORIGIN_HANDLE_PREV_BLOCK);
2146 rc = llog_origin_handle_prev_block(mdt_info_req(info));
2147 return (rc < 0 ? err_serious(rc) : rc);
2154 static struct ldlm_callback_suite cbs = {
2155 .lcs_completion = ldlm_server_completion_ast,
2156 .lcs_blocking = ldlm_server_blocking_ast,
2160 static int mdt_enqueue(struct mdt_thread_info *info)
2162 struct ptlrpc_request *req;
2166 * info->mti_dlm_req already contains swapped and (if necessary)
2167 * converted dlm request.
2169 LASSERT(info->mti_dlm_req != NULL);
2171 req = mdt_info_req(info);
2172 rc = ldlm_handle_enqueue0(info->mti_mdt->mdt_namespace,
2173 req, info->mti_dlm_req, &cbs);
2174 info->mti_fail_id = OBD_FAIL_LDLM_REPLY;
2175 return rc ? err_serious(rc) : req->rq_status;
2178 static int mdt_convert(struct mdt_thread_info *info)
2181 struct ptlrpc_request *req;
2183 LASSERT(info->mti_dlm_req);
2184 req = mdt_info_req(info);
2185 rc = ldlm_handle_convert0(req, info->mti_dlm_req);
2186 return rc ? err_serious(rc) : req->rq_status;
2189 static int mdt_bl_callback(struct mdt_thread_info *info)
2191 CERROR("bl callbacks should not happen on MDS\n");
2193 return err_serious(-EOPNOTSUPP);
2196 static int mdt_cp_callback(struct mdt_thread_info *info)
2198 CERROR("cp callbacks should not happen on MDS\n");
2200 return err_serious(-EOPNOTSUPP);
2204 * sec context handlers
2206 static int mdt_sec_ctx_handle(struct mdt_thread_info *info)
2210 rc = mdt_handle_idmap(info);
2213 struct ptlrpc_request *req = mdt_info_req(info);
2216 opc = lustre_msg_get_opc(req->rq_reqmsg);
2217 if (opc == SEC_CTX_INIT || opc == SEC_CTX_INIT_CONT)
2218 sptlrpc_svc_ctx_invalidate(req);
2221 CFS_FAIL_TIMEOUT(OBD_FAIL_SEC_CTX_HDL_PAUSE, cfs_fail_val);
2226 static struct mdt_object *mdt_obj(struct lu_object *o)
2228 LASSERT(lu_device_is_mdt(o->lo_dev));
2229 return container_of0(o, struct mdt_object, mot_obj.mo_lu);
2232 struct mdt_object *mdt_object_new(const struct lu_env *env,
2233 struct mdt_device *d,
2234 const struct lu_fid *f)
2236 struct lu_object_conf conf = { .loc_flags = LOC_F_NEW };
2237 struct lu_object *o;
2238 struct mdt_object *m;
2241 CDEBUG(D_INFO, "Allocate object for "DFID"\n", PFID(f));
2242 o = lu_object_find(env, &d->mdt_md_dev.md_lu_dev, f, &conf);
2243 if (unlikely(IS_ERR(o)))
2244 m = (struct mdt_object *)o;
2250 struct mdt_object *mdt_object_find(const struct lu_env *env,
2251 struct mdt_device *d,
2252 const struct lu_fid *f)
2254 struct lu_object *o;
2255 struct mdt_object *m;
2258 CDEBUG(D_INFO, "Find object for "DFID"\n", PFID(f));
2259 o = lu_object_find(env, &d->mdt_md_dev.md_lu_dev, f, NULL);
2260 if (unlikely(IS_ERR(o)))
2261 m = (struct mdt_object *)o;
2268 * Asyncronous commit for mdt device.
2270 * Pass asynchonous commit call down the MDS stack.
2272 * \param env environment
2273 * \param mdt the mdt device
2275 static void mdt_device_commit_async(const struct lu_env *env,
2276 struct mdt_device *mdt)
2278 struct dt_device *dt = mdt->mdt_bottom;
2281 rc = dt->dd_ops->dt_commit_async(env, dt);
2282 if (unlikely(rc != 0))
2283 CWARN("async commit start failed with rc = %d", rc);
2287 * Mark the lock as "synchonous".
2289 * Mark the lock to deffer transaction commit to the unlock time.
2291 * \param lock the lock to mark as "synchonous"
2293 * \see mdt_is_lock_sync
2294 * \see mdt_save_lock
2296 static inline void mdt_set_lock_sync(struct ldlm_lock *lock)
2298 lock->l_ast_data = (void*)1;
2302 * Check whehter the lock "synchonous" or not.
2304 * \param lock the lock to check
2305 * \retval 1 the lock is "synchonous"
2306 * \retval 0 the lock isn't "synchronous"
2308 * \see mdt_set_lock_sync
2309 * \see mdt_save_lock
2311 static inline int mdt_is_lock_sync(struct ldlm_lock *lock)
2313 return lock->l_ast_data != NULL;
2317 * Blocking AST for mdt locks.
2319 * Starts transaction commit if in case of COS lock conflict or
2320 * deffers such a commit to the mdt_save_lock.
2322 * \param lock the lock which blocks a request or cancelling lock
2323 * \param desc unused
2324 * \param data unused
2325 * \param flag indicates whether this cancelling or blocking callback
2327 * \see ldlm_blocking_ast_nocheck
2329 int mdt_blocking_ast(struct ldlm_lock *lock, struct ldlm_lock_desc *desc,
2330 void *data, int flag)
2332 struct obd_device *obd = ldlm_lock_to_ns(lock)->ns_obd;
2333 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
2337 if (flag == LDLM_CB_CANCELING)
2339 lock_res_and_lock(lock);
2340 if (lock->l_blocking_ast != mdt_blocking_ast) {
2341 unlock_res_and_lock(lock);
2344 if (mdt_cos_is_enabled(mdt) &&
2345 lock->l_req_mode & (LCK_PW | LCK_EX) &&
2346 lock->l_blocking_lock != NULL &&
2347 lock->l_client_cookie != lock->l_blocking_lock->l_client_cookie) {
2348 mdt_set_lock_sync(lock);
2350 rc = ldlm_blocking_ast_nocheck(lock);
2352 /* There is no lock conflict if l_blocking_lock == NULL,
2353 * it indicates a blocking ast sent from ldlm_lock_decref_internal
2354 * when the last reference to a local lock was released */
2355 if (lock->l_req_mode == LCK_COS && lock->l_blocking_lock != NULL) {
2358 rc = lu_env_init(&env, LCT_LOCAL);
2359 if (unlikely(rc != 0))
2360 CWARN("lu_env initialization failed with rc = %d,"
2361 "cannot start asynchronous commit\n", rc);
2363 mdt_device_commit_async(&env, mdt);
2369 int mdt_object_lock(struct mdt_thread_info *info, struct mdt_object *o,
2370 struct mdt_lock_handle *lh, __u64 ibits, int locality)
2372 struct ldlm_namespace *ns = info->mti_mdt->mdt_namespace;
2373 ldlm_policy_data_t *policy = &info->mti_policy;
2374 struct ldlm_res_id *res_id = &info->mti_res_id;
2378 LASSERT(!lustre_handle_is_used(&lh->mlh_reg_lh));
2379 LASSERT(!lustre_handle_is_used(&lh->mlh_pdo_lh));
2380 LASSERT(lh->mlh_reg_mode != LCK_MINMODE);
2381 LASSERT(lh->mlh_type != MDT_NUL_LOCK);
2383 if (mdt_object_exists(o) < 0) {
2384 if (locality == MDT_CROSS_LOCK) {
2385 /* cross-ref object fix */
2386 ibits &= ~MDS_INODELOCK_UPDATE;
2387 ibits |= MDS_INODELOCK_LOOKUP;
2389 LASSERT(!(ibits & MDS_INODELOCK_UPDATE));
2390 LASSERT(ibits & MDS_INODELOCK_LOOKUP);
2392 /* No PDO lock on remote object */
2393 LASSERT(lh->mlh_type != MDT_PDO_LOCK);
2396 if (lh->mlh_type == MDT_PDO_LOCK) {
2397 /* check for exists after object is locked */
2398 if (mdt_object_exists(o) == 0) {
2399 /* Non-existent object shouldn't have PDO lock */
2402 /* Non-dir object shouldn't have PDO lock */
2403 if (!S_ISDIR(lu_object_attr(&o->mot_obj.mo_lu)))
2408 memset(policy, 0, sizeof(*policy));
2409 fid_build_reg_res_name(mdt_object_fid(o), res_id);
2412 * Take PDO lock on whole directory and build correct @res_id for lock
2413 * on part of directory.
2415 if (lh->mlh_pdo_hash != 0) {
2416 LASSERT(lh->mlh_type == MDT_PDO_LOCK);
2417 mdt_lock_pdo_mode(info, o, lh);
2418 if (lh->mlh_pdo_mode != LCK_NL) {
2420 * Do not use LDLM_FL_LOCAL_ONLY for parallel lock, it
2421 * is never going to be sent to client and we do not
2422 * want it slowed down due to possible cancels.
2424 policy->l_inodebits.bits = MDS_INODELOCK_UPDATE;
2425 rc = mdt_fid_lock(ns, &lh->mlh_pdo_lh, lh->mlh_pdo_mode,
2426 policy, res_id, LDLM_FL_ATOMIC_CB,
2427 &info->mti_exp->exp_handle.h_cookie);
2433 * Finish res_id initializing by name hash marking part of
2434 * directory which is taking modification.
2436 res_id->name[LUSTRE_RES_ID_HSH_OFF] = lh->mlh_pdo_hash;
2439 policy->l_inodebits.bits = ibits;
2442 * Use LDLM_FL_LOCAL_ONLY for this lock. We do not know yet if it is
2443 * going to be sent to client. If it is - mdt_intent_policy() path will
2444 * fix it up and turn FL_LOCAL flag off.
2446 rc = mdt_fid_lock(ns, &lh->mlh_reg_lh, lh->mlh_reg_mode, policy,
2447 res_id, LDLM_FL_LOCAL_ONLY | LDLM_FL_ATOMIC_CB,
2448 &info->mti_exp->exp_handle.h_cookie);
2450 mdt_object_unlock(info, o, lh, 1);
2451 else if (unlikely(OBD_FAIL_PRECHECK(OBD_FAIL_MDS_PDO_LOCK)) &&
2452 lh->mlh_pdo_hash != 0 &&
2453 (lh->mlh_reg_mode == LCK_PW || lh->mlh_reg_mode == LCK_EX)) {
2454 OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_PDO_LOCK, 15);
2461 * Save a lock within request object.
2463 * Keep the lock referenced until whether client ACK or transaction
2464 * commit happens or release the lock immediately depending on input
2465 * parameters. If COS is ON, a write lock is converted to COS lock
2468 * \param info thead info object
2469 * \param h lock handle
2470 * \param mode lock mode
2471 * \param decref force immediate lock releasing
2474 void mdt_save_lock(struct mdt_thread_info *info, struct lustre_handle *h,
2475 ldlm_mode_t mode, int decref)
2479 if (lustre_handle_is_used(h)) {
2480 if (decref || !info->mti_has_trans ||
2481 !(mode & (LCK_PW | LCK_EX))){
2482 mdt_fid_unlock(h, mode);
2484 struct mdt_device *mdt = info->mti_mdt;
2485 struct ldlm_lock *lock = ldlm_handle2lock(h);
2486 struct ptlrpc_request *req = mdt_info_req(info);
2489 LASSERTF(lock != NULL, "no lock for cookie "LPX64"\n",
2491 CDEBUG(D_HA, "request = %p reply state = %p"
2492 " transno = "LPD64"\n",
2493 req, req->rq_reply_state, req->rq_transno);
2494 if (mdt_cos_is_enabled(mdt)) {
2496 ldlm_lock_downgrade(lock, LCK_COS);
2499 ptlrpc_save_lock(req, h, mode, no_ack);
2500 if (mdt_is_lock_sync(lock)) {
2501 CDEBUG(D_HA, "found sync-lock,"
2502 " async commit started\n");
2503 mdt_device_commit_async(info->mti_env,
2506 LDLM_LOCK_PUT(lock);
2515 * Unlock mdt object.
2517 * Immeditely release the regular lock and the PDO lock or save the
2518 * lock in reqeuest and keep them referenced until client ACK or
2519 * transaction commit.
2521 * \param info thread info object
2522 * \param o mdt object
2523 * \param lh mdt lock handle referencing regular and PDO locks
2524 * \param decref force immediate lock releasing
2526 void mdt_object_unlock(struct mdt_thread_info *info, struct mdt_object *o,
2527 struct mdt_lock_handle *lh, int decref)
2531 mdt_save_lock(info, &lh->mlh_pdo_lh, lh->mlh_pdo_mode, decref);
2532 mdt_save_lock(info, &lh->mlh_reg_lh, lh->mlh_reg_mode, decref);
2537 struct mdt_object *mdt_object_find_lock(struct mdt_thread_info *info,
2538 const struct lu_fid *f,
2539 struct mdt_lock_handle *lh,
2542 struct mdt_object *o;
2544 o = mdt_object_find(info->mti_env, info->mti_mdt, f);
2548 rc = mdt_object_lock(info, o, lh, ibits,
2551 mdt_object_put(info->mti_env, o);
2558 void mdt_object_unlock_put(struct mdt_thread_info * info,
2559 struct mdt_object * o,
2560 struct mdt_lock_handle *lh,
2563 mdt_object_unlock(info, o, lh, decref);
2564 mdt_object_put(info->mti_env, o);
2567 static struct mdt_handler *mdt_handler_find(__u32 opc,
2568 struct mdt_opc_slice *supported)
2570 struct mdt_opc_slice *s;
2571 struct mdt_handler *h;
2574 for (s = supported; s->mos_hs != NULL; s++) {
2575 if (s->mos_opc_start <= opc && opc < s->mos_opc_end) {
2576 h = s->mos_hs + (opc - s->mos_opc_start);
2577 if (likely(h->mh_opc != 0))
2578 LASSERTF(h->mh_opc == opc,
2579 "opcode mismatch %d != %d\n",
2582 h = NULL; /* unsupported opc */
2589 static int mdt_lock_resname_compat(struct mdt_device *m,
2590 struct ldlm_request *req)
2592 /* XXX something... later. */
2596 static int mdt_lock_reply_compat(struct mdt_device *m, struct ldlm_reply *rep)
2598 /* XXX something... later. */
2603 * Generic code handling requests that have struct mdt_body passed in:
2605 * - extract mdt_body from request and save it in @info, if present;
2607 * - create lu_object, corresponding to the fid in mdt_body, and save it in
2610 * - if HABEO_CORPUS flag is set for this request type check whether object
2611 * actually exists on storage (lu_object_exists()).
2614 static int mdt_body_unpack(struct mdt_thread_info *info, __u32 flags)
2616 const struct mdt_body *body;
2617 struct mdt_object *obj;
2618 const struct lu_env *env;
2619 struct req_capsule *pill;
2623 env = info->mti_env;
2624 pill = info->mti_pill;
2626 body = info->mti_body = req_capsule_client_get(pill, &RMF_MDT_BODY);
2630 if (!(body->valid & OBD_MD_FLID))
2633 if (!fid_is_sane(&body->fid1)) {
2634 CERROR("Invalid fid: "DFID"\n", PFID(&body->fid1));
2639 * Do not get size or any capa fields before we check that request
2640 * contains capa actually. There are some requests which do not, for
2641 * instance MDS_IS_SUBDIR.
2643 if (req_capsule_has_field(pill, &RMF_CAPA1, RCL_CLIENT) &&
2644 req_capsule_get_size(pill, &RMF_CAPA1, RCL_CLIENT))
2645 mdt_set_capainfo(info, 0, &body->fid1,
2646 req_capsule_client_get(pill, &RMF_CAPA1));
2648 obj = mdt_object_find(env, info->mti_mdt, &body->fid1);
2650 if ((flags & HABEO_CORPUS) &&
2651 !mdt_object_exists(obj)) {
2652 mdt_object_put(env, obj);
2653 /* for capability renew ENOENT will be handled in
2655 if (body->valid & OBD_MD_FLOSSCAPA)
2660 info->mti_object = obj;
2669 static int mdt_unpack_req_pack_rep(struct mdt_thread_info *info, __u32 flags)
2671 struct req_capsule *pill = info->mti_pill;
2675 if (req_capsule_has_field(pill, &RMF_MDT_BODY, RCL_CLIENT))
2676 rc = mdt_body_unpack(info, flags);
2680 if (rc == 0 && (flags & HABEO_REFERO)) {
2682 if (req_capsule_has_field(pill, &RMF_MDT_MD, RCL_SERVER))
2683 req_capsule_set_size(pill, &RMF_MDT_MD, RCL_SERVER,
2684 info->mti_body->eadatasize);
2685 if (req_capsule_has_field(pill, &RMF_LOGCOOKIES, RCL_SERVER))
2686 req_capsule_set_size(pill, &RMF_LOGCOOKIES, RCL_SERVER,
2687 info->mti_mdt->mdt_max_cookiesize);
2689 rc = req_capsule_server_pack(pill);
2694 static int mdt_init_capa_ctxt(const struct lu_env *env, struct mdt_device *m)
2696 struct md_device *next = m->mdt_child;
2698 return next->md_ops->mdo_init_capa_ctxt(env, next,
2699 m->mdt_opts.mo_mds_capa,
2700 m->mdt_capa_timeout,
2706 * Invoke handler for this request opc. Also do necessary preprocessing
2707 * (according to handler ->mh_flags), and post-processing (setting of
2708 * ->last_{xid,committed}).
2710 static int mdt_req_handle(struct mdt_thread_info *info,
2711 struct mdt_handler *h, struct ptlrpc_request *req)
2713 int rc, serious = 0;
2718 LASSERT(h->mh_act != NULL);
2719 LASSERT(h->mh_opc == lustre_msg_get_opc(req->rq_reqmsg));
2720 LASSERT(current->journal_info == NULL);
2723 * Checking for various OBD_FAIL_$PREF_$OPC_NET codes. _Do_ not try
2724 * to put same checks into handlers like mdt_close(), mdt_reint(),
2725 * etc., without talking to mdt authors first. Checking same thing
2726 * there again is useless and returning 0 error without packing reply
2727 * is buggy! Handlers either pack reply or return error.
2729 * We return 0 here and do not send any reply in order to emulate
2730 * network failure. Do not send any reply in case any of NET related
2731 * fail_id has occured.
2733 if (OBD_FAIL_CHECK_ORSET(h->mh_fail_id, OBD_FAIL_ONCE))
2737 flags = h->mh_flags;
2738 LASSERT(ergo(flags & (HABEO_CORPUS|HABEO_REFERO), h->mh_fmt != NULL));
2740 if (h->mh_fmt != NULL) {
2741 req_capsule_set(info->mti_pill, h->mh_fmt);
2742 rc = mdt_unpack_req_pack_rep(info, flags);
2745 if (rc == 0 && flags & MUTABOR &&
2746 req->rq_export->exp_connect_flags & OBD_CONNECT_RDONLY)
2747 /* should it be rq_status? */
2750 if (rc == 0 && flags & HABEO_CLAVIS) {
2751 struct ldlm_request *dlm_req;
2753 LASSERT(h->mh_fmt != NULL);
2755 dlm_req = req_capsule_client_get(info->mti_pill, &RMF_DLM_REQ);
2756 if (dlm_req != NULL) {
2757 if (unlikely(dlm_req->lock_desc.l_resource.lr_type ==
2759 dlm_req->lock_desc.l_policy_data.\
2760 l_inodebits.bits == 0)) {
2762 * Lock without inodebits makes no sense and
2763 * will oops later in ldlm. If client miss to
2764 * set such bits, do not trigger ASSERTION.
2766 * For liblustre flock case, it maybe zero.
2770 if (info->mti_mdt->mdt_opts.mo_compat_resname)
2771 rc = mdt_lock_resname_compat(
2774 info->mti_dlm_req = dlm_req;
2781 /* capability setting changed via /proc, needs reinitialize ctxt */
2782 if (info->mti_mdt && info->mti_mdt->mdt_capa_conf) {
2783 mdt_init_capa_ctxt(info->mti_env, info->mti_mdt);
2784 info->mti_mdt->mdt_capa_conf = 0;
2787 if (likely(rc == 0)) {
2789 * Process request, there can be two types of rc:
2790 * 1) errors with msg unpack/pack, other failures outside the
2791 * operation itself. This is counted as serious errors;
2792 * 2) errors during fs operation, should be placed in rq_status
2795 rc = h->mh_act(info);
2797 !req->rq_no_reply && req->rq_reply_state == NULL) {
2798 DEBUG_REQ(D_ERROR, req, "MDT \"handler\" %s did not "
2799 "pack reply and returned 0 error\n",
2803 serious = is_serious(rc);
2804 rc = clear_serious(rc);
2808 req->rq_status = rc;
2811 * ELDLM_* codes which > 0 should be in rq_status only as well as
2812 * all non-serious errors.
2814 if (rc > 0 || !serious)
2817 LASSERT(current->journal_info == NULL);
2819 if (rc == 0 && (flags & HABEO_CLAVIS) &&
2820 info->mti_mdt->mdt_opts.mo_compat_resname) {
2821 struct ldlm_reply *dlmrep;
2823 dlmrep = req_capsule_server_get(info->mti_pill, &RMF_DLM_REP);
2825 rc = mdt_lock_reply_compat(info->mti_mdt, dlmrep);
2828 /* If we're DISCONNECTing, the mdt_export_data is already freed */
2829 if (likely(rc == 0 && req->rq_export && h->mh_opc != MDS_DISCONNECT))
2830 target_committed_to_req(req);
2832 if (unlikely(req_is_replay(req) &&
2833 lustre_msg_get_transno(req->rq_reqmsg) == 0)) {
2834 DEBUG_REQ(D_ERROR, req, "transno is 0 during REPLAY");
2838 target_send_reply(req, rc, info->mti_fail_id);
2842 void mdt_lock_handle_init(struct mdt_lock_handle *lh)
2844 lh->mlh_type = MDT_NUL_LOCK;
2845 lh->mlh_reg_lh.cookie = 0ull;
2846 lh->mlh_reg_mode = LCK_MINMODE;
2847 lh->mlh_pdo_lh.cookie = 0ull;
2848 lh->mlh_pdo_mode = LCK_MINMODE;
2851 void mdt_lock_handle_fini(struct mdt_lock_handle *lh)
2853 LASSERT(!lustre_handle_is_used(&lh->mlh_reg_lh));
2854 LASSERT(!lustre_handle_is_used(&lh->mlh_pdo_lh));
2858 * Initialize fields of struct mdt_thread_info. Other fields are left in
2859 * uninitialized state, because it's too expensive to zero out whole
2860 * mdt_thread_info (> 1K) on each request arrival.
2862 static void mdt_thread_info_init(struct ptlrpc_request *req,
2863 struct mdt_thread_info *info)
2866 struct md_capainfo *ci;
2868 req_capsule_init(&req->rq_pill, req, RCL_SERVER);
2869 info->mti_pill = &req->rq_pill;
2872 for (i = 0; i < ARRAY_SIZE(info->mti_lh); i++)
2873 mdt_lock_handle_init(&info->mti_lh[i]);
2875 /* mdt device: it can be NULL while CONNECT */
2876 if (req->rq_export) {
2877 info->mti_mdt = mdt_dev(req->rq_export->exp_obd->obd_lu_dev);
2878 info->mti_exp = req->rq_export;
2880 info->mti_mdt = NULL;
2881 info->mti_env = req->rq_svc_thread->t_env;
2882 ci = md_capainfo(info->mti_env);
2883 memset(ci, 0, sizeof *ci);
2884 if (req->rq_export) {
2885 if (exp_connect_rmtclient(req->rq_export))
2886 ci->mc_auth = LC_ID_CONVERT;
2887 else if (req->rq_export->exp_connect_flags &
2888 OBD_CONNECT_MDS_CAPA)
2889 ci->mc_auth = LC_ID_PLAIN;
2891 ci->mc_auth = LC_ID_NONE;
2894 info->mti_fail_id = OBD_FAIL_MDS_ALL_REPLY_NET;
2895 info->mti_transno = lustre_msg_get_transno(req->rq_reqmsg);
2896 info->mti_mos = NULL;
2898 memset(&info->mti_attr, 0, sizeof(info->mti_attr));
2899 info->mti_body = NULL;
2900 info->mti_object = NULL;
2901 info->mti_dlm_req = NULL;
2902 info->mti_has_trans = 0;
2903 info->mti_no_need_trans = 0;
2904 info->mti_cross_ref = 0;
2905 info->mti_opdata = 0;
2907 /* To not check for split by default. */
2908 info->mti_spec.sp_ck_split = 0;
2909 info->mti_spec.no_create = 0;
2912 static void mdt_thread_info_fini(struct mdt_thread_info *info)
2916 req_capsule_fini(info->mti_pill);
2917 if (info->mti_object != NULL) {
2919 * freeing an object may lead to OSD level transaction, do not
2920 * let it mess with MDT. bz19385.
2922 info->mti_no_need_trans = 1;
2923 mdt_object_put(info->mti_env, info->mti_object);
2924 info->mti_object = NULL;
2926 for (i = 0; i < ARRAY_SIZE(info->mti_lh); i++)
2927 mdt_lock_handle_fini(&info->mti_lh[i]);
2928 info->mti_env = NULL;
2931 static int mdt_filter_recovery_request(struct ptlrpc_request *req,
2932 struct obd_device *obd, int *process)
2934 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
2935 case MDS_CONNECT: /* This will never get here, but for completeness. */
2936 case OST_CONNECT: /* This will never get here, but for completeness. */
2937 case MDS_DISCONNECT:
2938 case OST_DISCONNECT:
2943 case MDS_DONE_WRITING:
2944 case MDS_SYNC: /* used in unmounting */
2950 *process = target_queue_recovery_request(req, obd);
2954 DEBUG_REQ(D_ERROR, req, "not permitted during recovery");
2961 * Handle recovery. Return:
2962 * +1: continue request processing;
2963 * -ve: abort immediately with the given error code;
2964 * 0: send reply with error code in req->rq_status;
2966 static int mdt_recovery(struct mdt_thread_info *info)
2968 struct ptlrpc_request *req = mdt_info_req(info);
2969 struct obd_device *obd;
2973 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
2976 case SEC_CTX_INIT_CONT:
2982 rc = mdt_handle_idmap(info);
2991 if (unlikely(!class_connected_export(req->rq_export))) {
2992 CERROR("operation %d on unconnected MDS from %s\n",
2993 lustre_msg_get_opc(req->rq_reqmsg),
2994 libcfs_id2str(req->rq_peer));
2995 /* FIXME: For CMD cleanup, when mds_B stop, the req from
2996 * mds_A will get -ENOTCONN(especially for ping req),
2997 * which will cause that mds_A deactive timeout, then when
2998 * mds_A cleanup, the cleanup process will be suspended since
2999 * deactive timeout is not zero.
3001 req->rq_status = -ENOTCONN;
3002 target_send_reply(req, -ENOTCONN, info->mti_fail_id);
3006 /* sanity check: if the xid matches, the request must be marked as a
3007 * resent or replayed */
3008 if (req_xid_is_last(req)) {
3009 if (!(lustre_msg_get_flags(req->rq_reqmsg) &
3010 (MSG_RESENT | MSG_REPLAY))) {
3011 DEBUG_REQ(D_WARNING, req, "rq_xid "LPU64" matches last_xid, "
3012 "expected REPLAY or RESENT flag (%x)", req->rq_xid,
3013 lustre_msg_get_flags(req->rq_reqmsg));
3015 req->rq_status = -ENOTCONN;
3020 /* else: note the opposite is not always true; a RESENT req after a
3021 * failover will usually not match the last_xid, since it was likely
3022 * never committed. A REPLAYed request will almost never match the
3023 * last xid, however it could for a committed, but still retained,
3026 obd = req->rq_export->exp_obd;
3028 /* Check for aborted recovery... */
3029 if (unlikely(obd->obd_recovering)) {
3032 DEBUG_REQ(D_INFO, req, "Got new replay");
3033 rc = mdt_filter_recovery_request(req, obd, &should_process);
3034 if (rc != 0 || !should_process)
3036 else if (should_process < 0) {
3037 req->rq_status = should_process;
3038 rc = ptlrpc_error(req);
3045 static int mdt_msg_check_version(struct lustre_msg *msg)
3049 switch (lustre_msg_get_opc(msg)) {
3051 case MDS_DISCONNECT:
3054 case SEC_CTX_INIT_CONT:
3057 rc = lustre_msg_check_version(msg, LUSTRE_OBD_VERSION);
3059 CERROR("bad opc %u version %08x, expecting %08x\n",
3060 lustre_msg_get_opc(msg),
3061 lustre_msg_get_version(msg),
3062 LUSTRE_OBD_VERSION);
3066 case MDS_GETATTR_NAME:
3073 case MDS_DONE_WRITING:
3080 case MDS_QUOTACHECK:
3086 rc = lustre_msg_check_version(msg, LUSTRE_MDS_VERSION);
3088 CERROR("bad opc %u version %08x, expecting %08x\n",
3089 lustre_msg_get_opc(msg),
3090 lustre_msg_get_version(msg),
3091 LUSTRE_MDS_VERSION);
3095 case LDLM_BL_CALLBACK:
3096 case LDLM_CP_CALLBACK:
3097 rc = lustre_msg_check_version(msg, LUSTRE_DLM_VERSION);
3099 CERROR("bad opc %u version %08x, expecting %08x\n",
3100 lustre_msg_get_opc(msg),
3101 lustre_msg_get_version(msg),
3102 LUSTRE_DLM_VERSION);
3104 case OBD_LOG_CANCEL:
3105 case LLOG_ORIGIN_HANDLE_CREATE:
3106 case LLOG_ORIGIN_HANDLE_NEXT_BLOCK:
3107 case LLOG_ORIGIN_HANDLE_READ_HEADER:
3108 case LLOG_ORIGIN_HANDLE_CLOSE:
3109 case LLOG_ORIGIN_HANDLE_DESTROY:
3110 case LLOG_ORIGIN_HANDLE_PREV_BLOCK:
3112 rc = lustre_msg_check_version(msg, LUSTRE_LOG_VERSION);
3114 CERROR("bad opc %u version %08x, expecting %08x\n",
3115 lustre_msg_get_opc(msg),
3116 lustre_msg_get_version(msg),
3117 LUSTRE_LOG_VERSION);
3120 CERROR("MDS unknown opcode %d\n", lustre_msg_get_opc(msg));
3126 static int mdt_handle0(struct ptlrpc_request *req,
3127 struct mdt_thread_info *info,
3128 struct mdt_opc_slice *supported)
3130 struct mdt_handler *h;
3131 struct lustre_msg *msg;
3136 if (OBD_FAIL_CHECK_ORSET(OBD_FAIL_MDS_ALL_REQUEST_NET, OBD_FAIL_ONCE))
3139 LASSERT(current->journal_info == NULL);
3141 msg = req->rq_reqmsg;
3142 rc = mdt_msg_check_version(msg);
3143 if (likely(rc == 0)) {
3144 rc = mdt_recovery(info);
3145 if (likely(rc == +1)) {
3146 h = mdt_handler_find(lustre_msg_get_opc(msg),
3148 if (likely(h != NULL)) {
3149 rc = mdt_req_handle(info, h, req);
3151 CERROR("The unsupported opc: 0x%x\n",
3152 lustre_msg_get_opc(msg) );
3153 req->rq_status = -ENOTSUPP;
3154 rc = ptlrpc_error(req);
3159 CERROR(LUSTRE_MDT_NAME" drops mal-formed request\n");
3164 * MDT handler function called by ptlrpc service thread when request comes.
3166 * XXX common "target" functionality should be factored into separate module
3167 * shared by mdt, ost and stand-alone services like fld.
3169 static int mdt_handle_common(struct ptlrpc_request *req,
3170 struct mdt_opc_slice *supported)
3173 struct mdt_thread_info *info;
3177 env = req->rq_svc_thread->t_env;
3178 LASSERT(env != NULL);
3179 LASSERT(env->le_ses != NULL);
3180 LASSERT(env->le_ctx.lc_thread == req->rq_svc_thread);
3181 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
3182 LASSERT(info != NULL);
3184 mdt_thread_info_init(req, info);
3186 rc = mdt_handle0(req, info, supported);
3188 mdt_thread_info_fini(info);
3193 * This is called from recovery code as handler of _all_ RPC types, FLD and SEQ
3196 int mdt_recovery_handle(struct ptlrpc_request *req)
3201 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
3203 rc = mdt_handle_common(req, mdt_fld_handlers);
3206 rc = mdt_handle_common(req, mdt_seq_handlers);
3209 rc = mdt_handle_common(req, mdt_regular_handlers);
3216 static int mdt_regular_handle(struct ptlrpc_request *req)
3218 return mdt_handle_common(req, mdt_regular_handlers);
3221 static int mdt_readpage_handle(struct ptlrpc_request *req)
3223 return mdt_handle_common(req, mdt_readpage_handlers);
3226 static int mdt_xmds_handle(struct ptlrpc_request *req)
3228 return mdt_handle_common(req, mdt_xmds_handlers);
3231 static int mdt_mdsc_handle(struct ptlrpc_request *req)
3233 return mdt_handle_common(req, mdt_seq_handlers);
3236 static int mdt_mdss_handle(struct ptlrpc_request *req)
3238 return mdt_handle_common(req, mdt_seq_handlers);
3241 static int mdt_dtss_handle(struct ptlrpc_request *req)
3243 return mdt_handle_common(req, mdt_seq_handlers);
3246 static int mdt_fld_handle(struct ptlrpc_request *req)
3248 return mdt_handle_common(req, mdt_fld_handlers);
3265 static int mdt_intent_getattr(enum mdt_it_code opcode,
3266 struct mdt_thread_info *info,
3267 struct ldlm_lock **,
3269 static int mdt_intent_reint(enum mdt_it_code opcode,
3270 struct mdt_thread_info *info,
3271 struct ldlm_lock **,
3274 static struct mdt_it_flavor {
3275 const struct req_format *it_fmt;
3277 int (*it_act)(enum mdt_it_code ,
3278 struct mdt_thread_info *,
3279 struct ldlm_lock **,
3282 } mdt_it_flavor[] = {
3284 .it_fmt = &RQF_LDLM_INTENT,
3285 /*.it_flags = HABEO_REFERO,*/
3287 .it_act = mdt_intent_reint,
3288 .it_reint = REINT_OPEN
3291 .it_fmt = &RQF_LDLM_INTENT,
3292 .it_flags = MUTABOR,
3293 .it_act = mdt_intent_reint,
3294 .it_reint = REINT_OPEN
3297 .it_fmt = &RQF_LDLM_INTENT,
3298 .it_flags = MUTABOR,
3299 .it_act = mdt_intent_reint,
3300 .it_reint = REINT_CREATE
3302 [MDT_IT_GETATTR] = {
3303 .it_fmt = &RQF_LDLM_INTENT_GETATTR,
3304 .it_flags = HABEO_REFERO,
3305 .it_act = mdt_intent_getattr
3307 [MDT_IT_READDIR] = {
3313 .it_fmt = &RQF_LDLM_INTENT_GETATTR,
3314 .it_flags = HABEO_REFERO,
3315 .it_act = mdt_intent_getattr
3318 .it_fmt = &RQF_LDLM_INTENT_UNLINK,
3319 .it_flags = MUTABOR,
3321 .it_reint = REINT_UNLINK
3325 .it_flags = MUTABOR,
3328 [MDT_IT_GETXATTR] = {
3334 .it_fmt = &RQF_LDLM_INTENT_GETATTR,
3335 .it_flags = HABEO_REFERO,
3336 .it_act = mdt_intent_getattr
3340 int mdt_intent_lock_replace(struct mdt_thread_info *info,
3341 struct ldlm_lock **lockp,
3342 struct ldlm_lock *new_lock,
3343 struct mdt_lock_handle *lh,
3346 struct ptlrpc_request *req = mdt_info_req(info);
3347 struct ldlm_lock *lock = *lockp;
3350 * Get new lock only for cases when possible resent did not find any
3353 if (new_lock == NULL)
3354 new_lock = ldlm_handle2lock_long(&lh->mlh_reg_lh, 0);
3356 if (new_lock == NULL && (flags & LDLM_FL_INTENT_ONLY)) {
3357 lh->mlh_reg_lh.cookie = 0;
3361 LASSERTF(new_lock != NULL,
3362 "lockh "LPX64"\n", lh->mlh_reg_lh.cookie);
3365 * If we've already given this lock to a client once, then we should
3366 * have no readers or writers. Otherwise, we should have one reader
3367 * _or_ writer ref (which will be zeroed below) before returning the
3370 if (new_lock->l_export == req->rq_export) {
3371 LASSERT(new_lock->l_readers + new_lock->l_writers == 0);
3373 LASSERT(new_lock->l_export == NULL);
3374 LASSERT(new_lock->l_readers + new_lock->l_writers == 1);
3379 if (new_lock->l_export == req->rq_export) {
3381 * Already gave this to the client, which means that we
3382 * reconstructed a reply.
3384 LASSERT(lustre_msg_get_flags(req->rq_reqmsg) &
3386 lh->mlh_reg_lh.cookie = 0;
3387 RETURN(ELDLM_LOCK_REPLACED);
3391 * Fixup the lock to be given to the client.
3393 lock_res_and_lock(new_lock);
3394 /* Zero new_lock->l_readers and new_lock->l_writers without triggering
3395 * possible blocking AST. */
3396 while (new_lock->l_readers > 0) {
3397 lu_ref_del(&new_lock->l_reference, "reader", new_lock);
3398 lu_ref_del(&new_lock->l_reference, "user", new_lock);
3399 new_lock->l_readers--;
3401 while (new_lock->l_writers > 0) {
3402 lu_ref_del(&new_lock->l_reference, "writer", new_lock);
3403 lu_ref_del(&new_lock->l_reference, "user", new_lock);
3404 new_lock->l_writers--;
3407 new_lock->l_export = class_export_lock_get(req->rq_export, new_lock);
3408 new_lock->l_blocking_ast = lock->l_blocking_ast;
3409 new_lock->l_completion_ast = lock->l_completion_ast;
3410 new_lock->l_remote_handle = lock->l_remote_handle;
3411 new_lock->l_flags &= ~LDLM_FL_LOCAL;
3413 unlock_res_and_lock(new_lock);
3415 cfs_hash_add(new_lock->l_export->exp_lock_hash,
3416 &new_lock->l_remote_handle,
3417 &new_lock->l_exp_hash);
3419 LDLM_LOCK_RELEASE(new_lock);
3420 lh->mlh_reg_lh.cookie = 0;
3422 RETURN(ELDLM_LOCK_REPLACED);
3425 static void mdt_intent_fixup_resent(struct mdt_thread_info *info,
3426 struct ldlm_lock *new_lock,
3427 struct ldlm_lock **old_lock,
3428 struct mdt_lock_handle *lh)
3430 struct ptlrpc_request *req = mdt_info_req(info);
3431 struct obd_export *exp = req->rq_export;
3432 struct lustre_handle remote_hdl;
3433 struct ldlm_request *dlmreq;
3434 struct ldlm_lock *lock;
3436 if (!(lustre_msg_get_flags(req->rq_reqmsg) & MSG_RESENT))
3439 dlmreq = req_capsule_client_get(info->mti_pill, &RMF_DLM_REQ);
3440 remote_hdl = dlmreq->lock_handle[0];
3442 lock = cfs_hash_lookup(exp->exp_lock_hash, &remote_hdl);
3444 if (lock != new_lock) {
3445 lh->mlh_reg_lh.cookie = lock->l_handle.h_cookie;
3446 lh->mlh_reg_mode = lock->l_granted_mode;
3448 LDLM_DEBUG(lock, "Restoring lock cookie");
3449 DEBUG_REQ(D_DLMTRACE, req,
3450 "restoring lock cookie "LPX64,
3451 lh->mlh_reg_lh.cookie);
3453 *old_lock = LDLM_LOCK_GET(lock);
3454 cfs_hash_put(exp->exp_lock_hash, &lock->l_exp_hash);
3458 cfs_hash_put(exp->exp_lock_hash, &lock->l_exp_hash);
3462 * If the xid matches, then we know this is a resent request, and allow
3463 * it. (It's probably an OPEN, for which we don't send a lock.
3465 if (req_xid_is_last(req))
3469 * This remote handle isn't enqueued, so we never received or processed
3470 * this request. Clear MSG_RESENT, because it can be handled like any
3471 * normal request now.
3473 lustre_msg_clear_flags(req->rq_reqmsg, MSG_RESENT);
3475 DEBUG_REQ(D_DLMTRACE, req, "no existing lock with rhandle "LPX64,
3479 static int mdt_intent_getattr(enum mdt_it_code opcode,
3480 struct mdt_thread_info *info,
3481 struct ldlm_lock **lockp,
3484 struct mdt_lock_handle *lhc = &info->mti_lh[MDT_LH_RMT];
3485 struct ldlm_lock *new_lock = NULL;
3487 struct ldlm_reply *ldlm_rep;
3488 struct ptlrpc_request *req;
3489 struct mdt_body *reqbody;
3490 struct mdt_body *repbody;
3494 reqbody = req_capsule_client_get(info->mti_pill, &RMF_MDT_BODY);
3497 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
3500 info->mti_spec.sp_ck_split = !!(reqbody->valid & OBD_MD_FLCKSPLIT);
3501 info->mti_cross_ref = !!(reqbody->valid & OBD_MD_FLCROSSREF);
3502 repbody->eadatasize = 0;
3503 repbody->aclsize = 0;
3507 child_bits = MDS_INODELOCK_LOOKUP;
3509 case MDT_IT_GETATTR:
3510 child_bits = MDS_INODELOCK_LOOKUP | MDS_INODELOCK_UPDATE;
3512 case MDT_IT_LAYOUT: {
3513 static int printed = 0;
3516 CERROR("layout lock not supported by this version\n");
3519 GOTO(out_shrink, rc = -EINVAL);
3523 CERROR("Unsupported intent (%d)\n", opcode);
3524 GOTO(out_shrink, rc = -EINVAL);
3527 rc = mdt_init_ucred(info, reqbody);
3529 GOTO(out_shrink, rc);
3531 req = info->mti_pill->rc_req;
3532 ldlm_rep = req_capsule_server_get(info->mti_pill, &RMF_DLM_REP);
3533 mdt_set_disposition(info, ldlm_rep, DISP_IT_EXECD);
3535 /* Get lock from request for possible resent case. */
3536 mdt_intent_fixup_resent(info, *lockp, &new_lock, lhc);
3538 ldlm_rep->lock_policy_res2 =
3539 mdt_getattr_name_lock(info, lhc, child_bits, ldlm_rep);
3541 if (mdt_get_disposition(ldlm_rep, DISP_LOOKUP_NEG))
3542 ldlm_rep->lock_policy_res2 = 0;
3543 if (!mdt_get_disposition(ldlm_rep, DISP_LOOKUP_POS) ||
3544 ldlm_rep->lock_policy_res2) {
3545 lhc->mlh_reg_lh.cookie = 0ull;
3546 GOTO(out_ucred, rc = ELDLM_LOCK_ABORTED);
3549 rc = mdt_intent_lock_replace(info, lockp, new_lock, lhc, flags);
3552 mdt_exit_ucred(info);
3554 mdt_client_compatibility(info);
3555 rc2 = mdt_fix_reply(info);
3561 static int mdt_intent_reint(enum mdt_it_code opcode,
3562 struct mdt_thread_info *info,
3563 struct ldlm_lock **lockp,
3566 struct mdt_lock_handle *lhc = &info->mti_lh[MDT_LH_RMT];
3567 struct ldlm_reply *rep = NULL;
3571 static const struct req_format *intent_fmts[REINT_MAX] = {
3572 [REINT_CREATE] = &RQF_LDLM_INTENT_CREATE,
3573 [REINT_OPEN] = &RQF_LDLM_INTENT_OPEN
3578 opc = mdt_reint_opcode(info, intent_fmts);
3582 if (mdt_it_flavor[opcode].it_reint != opc) {
3583 CERROR("Reint code %ld doesn't match intent: %d\n",
3585 RETURN(err_serious(-EPROTO));
3588 /* Get lock from request for possible resent case. */
3589 mdt_intent_fixup_resent(info, *lockp, NULL, lhc);
3591 rc = mdt_reint_internal(info, lhc, opc);
3593 /* Check whether the reply has been packed successfully. */
3594 if (mdt_info_req(info)->rq_repmsg != NULL)
3595 rep = req_capsule_server_get(info->mti_pill, &RMF_DLM_REP);
3597 RETURN(err_serious(-EFAULT));
3599 /* MDC expects this in any case */
3601 mdt_set_disposition(info, rep, DISP_LOOKUP_EXECD);
3603 /* Cross-ref case, the lock should be returned to the client */
3604 if (rc == -EREMOTE) {
3605 LASSERT(lustre_handle_is_used(&lhc->mlh_reg_lh));
3606 rep->lock_policy_res2 = 0;
3607 rc = mdt_intent_lock_replace(info, lockp, NULL, lhc, flags);
3610 rep->lock_policy_res2 = clear_serious(rc);
3612 if (rep->lock_policy_res2 == -ENOENT &&
3613 mdt_get_disposition(rep, DISP_LOOKUP_NEG))
3614 rep->lock_policy_res2 = 0;
3616 if (rc == -ENOTCONN || rc == -ENODEV ||
3617 rc == -EOVERFLOW) { /**< if VBR failure then return error */
3619 * If it is the disconnect error (ENODEV & ENOCONN), the error
3620 * will be returned by rq_status, and client at ptlrpc layer
3621 * will detect this, then disconnect, reconnect the import
3622 * immediately, instead of impacting the following the rpc.
3624 lhc->mlh_reg_lh.cookie = 0ull;
3628 * For other cases, the error will be returned by intent.
3629 * and client will retrieve the result from intent.
3632 * FIXME: when open lock is finished, that should be
3635 if (lustre_handle_is_used(&lhc->mlh_reg_lh)) {
3636 LASSERTF(rc == 0, "Error occurred but lock handle "
3637 "is still in use\n");
3638 rep->lock_policy_res2 = 0;
3639 rc = mdt_intent_lock_replace(info, lockp, NULL, lhc, flags);
3642 lhc->mlh_reg_lh.cookie = 0ull;
3643 RETURN(ELDLM_LOCK_ABORTED);
3648 static int mdt_intent_code(long itcode)
3656 case IT_OPEN|IT_CREAT:
3663 rc = MDT_IT_READDIR;
3666 rc = MDT_IT_GETATTR;
3678 rc = MDT_IT_GETXATTR;
3684 CERROR("Unknown intent opcode: %ld\n", itcode);
3691 static int mdt_intent_opc(long itopc, struct mdt_thread_info *info,
3692 struct ldlm_lock **lockp, int flags)
3694 struct req_capsule *pill;
3695 struct mdt_it_flavor *flv;
3700 opc = mdt_intent_code(itopc);
3704 pill = info->mti_pill;
3705 flv = &mdt_it_flavor[opc];
3707 if (flv->it_fmt != NULL)
3708 req_capsule_extend(pill, flv->it_fmt);
3710 rc = mdt_unpack_req_pack_rep(info, flv->it_flags);
3712 struct ptlrpc_request *req = mdt_info_req(info);
3713 if (flv->it_flags & MUTABOR &&
3714 req->rq_export->exp_connect_flags & OBD_CONNECT_RDONLY)
3717 if (rc == 0 && flv->it_act != NULL) {
3718 /* execute policy */
3719 rc = flv->it_act(opc, info, lockp, flags);
3726 static int mdt_intent_policy(struct ldlm_namespace *ns,
3727 struct ldlm_lock **lockp, void *req_cookie,
3728 ldlm_mode_t mode, int flags, void *data)
3730 struct mdt_thread_info *info;
3731 struct ptlrpc_request *req = req_cookie;
3732 struct ldlm_intent *it;
3733 struct req_capsule *pill;
3738 LASSERT(req != NULL);
3740 info = lu_context_key_get(&req->rq_svc_thread->t_env->le_ctx,
3742 LASSERT(info != NULL);
3743 pill = info->mti_pill;
3744 LASSERT(pill->rc_req == req);
3746 if (req->rq_reqmsg->lm_bufcount > DLM_INTENT_IT_OFF) {
3747 req_capsule_extend(pill, &RQF_LDLM_INTENT);
3748 it = req_capsule_client_get(pill, &RMF_LDLM_INTENT);
3750 rc = mdt_intent_opc(it->opc, info, lockp, flags);
3754 /* Lock without inodebits makes no sense and will oops
3755 * later in ldlm. Let's check it now to see if we have
3756 * ibits corrupted somewhere in mdt_intent_opc().
3757 * The case for client miss to set ibits has been
3758 * processed by others. */
3759 LASSERT(ergo(info->mti_dlm_req->lock_desc.l_resource.\
3760 lr_type == LDLM_IBITS,
3761 info->mti_dlm_req->lock_desc.\
3762 l_policy_data.l_inodebits.bits != 0));
3764 rc = err_serious(-EFAULT);
3766 /* No intent was provided */
3767 LASSERT(pill->rc_fmt == &RQF_LDLM_ENQUEUE);
3768 rc = req_capsule_server_pack(pill);
3770 rc = err_serious(rc);
3775 static int mdt_seq_fini(const struct lu_env *env,
3776 struct mdt_device *m)
3778 struct md_site *ms = mdt_md_site(m);
3782 if (ms->ms_server_seq) {
3783 seq_server_fini(ms->ms_server_seq, env);
3784 OBD_FREE_PTR(ms->ms_server_seq);
3785 ms->ms_server_seq = NULL;
3788 if (ms->ms_control_seq) {
3789 seq_server_fini(ms->ms_control_seq, env);
3790 OBD_FREE_PTR(ms->ms_control_seq);
3791 ms->ms_control_seq = NULL;
3794 if (ms->ms_client_seq) {
3795 seq_client_fini(ms->ms_client_seq);
3796 OBD_FREE_PTR(ms->ms_client_seq);
3797 ms->ms_client_seq = NULL;
3804 static int mdt_seq_init(const struct lu_env *env,
3806 struct mdt_device *m)
3813 ms = mdt_md_site(m);
3816 * This is sequence-controller node. Init seq-controller server on local
3819 if (ms->ms_node_id == 0) {
3820 LASSERT(ms->ms_control_seq == NULL);
3822 OBD_ALLOC_PTR(ms->ms_control_seq);
3823 if (ms->ms_control_seq == NULL)
3826 rc = seq_server_init(ms->ms_control_seq,
3827 m->mdt_bottom, uuid,
3828 LUSTRE_SEQ_CONTROLLER,
3833 GOTO(out_seq_fini, rc);
3835 OBD_ALLOC_PTR(ms->ms_client_seq);
3836 if (ms->ms_client_seq == NULL)
3837 GOTO(out_seq_fini, rc = -ENOMEM);
3839 OBD_ALLOC(prefix, MAX_OBD_NAME + 5);
3840 if (prefix == NULL) {
3841 OBD_FREE_PTR(ms->ms_client_seq);
3842 GOTO(out_seq_fini, rc = -ENOMEM);
3845 snprintf(prefix, MAX_OBD_NAME + 5, "ctl-%s",
3849 * Init seq-controller client after seq-controller server is
3850 * ready. Pass ms->ms_control_seq to it for direct talking.
3852 rc = seq_client_init(ms->ms_client_seq, NULL,
3853 LUSTRE_SEQ_METADATA, prefix,
3854 ms->ms_control_seq);
3855 OBD_FREE(prefix, MAX_OBD_NAME + 5);
3858 GOTO(out_seq_fini, rc);
3861 /* Init seq-server on local MDT */
3862 LASSERT(ms->ms_server_seq == NULL);
3864 OBD_ALLOC_PTR(ms->ms_server_seq);
3865 if (ms->ms_server_seq == NULL)
3866 GOTO(out_seq_fini, rc = -ENOMEM);
3868 rc = seq_server_init(ms->ms_server_seq,
3869 m->mdt_bottom, uuid,
3874 GOTO(out_seq_fini, rc = -ENOMEM);
3876 /* Assign seq-controller client to local seq-server. */
3877 if (ms->ms_node_id == 0) {
3878 LASSERT(ms->ms_client_seq != NULL);
3880 rc = seq_server_set_cli(ms->ms_server_seq,
3888 mdt_seq_fini(env, m);
3893 * Init client sequence manager which is used by local MDS to talk to sequence
3894 * controller on remote node.
3896 static int mdt_seq_init_cli(const struct lu_env *env,
3897 struct mdt_device *m,
3898 struct lustre_cfg *cfg)
3900 struct md_site *ms = mdt_md_site(m);
3901 struct obd_device *mdc;
3902 struct obd_uuid *uuidp, *mdcuuidp;
3903 char *uuid_str, *mdc_uuid_str;
3906 struct mdt_thread_info *info;
3907 char *p, *index_string = lustre_cfg_string(cfg, 2);
3910 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
3911 uuidp = &info->mti_u.uuid[0];
3912 mdcuuidp = &info->mti_u.uuid[1];
3914 LASSERT(index_string);
3916 index = simple_strtol(index_string, &p, 10);
3918 CERROR("Invalid index in lustre_cgf, offset 2\n");
3922 /* check if this is adding the first MDC and controller is not yet
3924 if (index != 0 || ms->ms_client_seq)
3927 uuid_str = lustre_cfg_string(cfg, 1);
3928 mdc_uuid_str = lustre_cfg_string(cfg, 4);
3929 obd_str2uuid(uuidp, uuid_str);
3930 obd_str2uuid(mdcuuidp, mdc_uuid_str);
3932 mdc = class_find_client_obd(uuidp, LUSTRE_MDC_NAME, mdcuuidp);
3934 CERROR("can't find controller MDC by uuid %s\n",
3937 } else if (!mdc->obd_set_up) {
3938 CERROR("target %s not set up\n", mdc->obd_name);
3941 LASSERT(ms->ms_control_exp);
3942 OBD_ALLOC_PTR(ms->ms_client_seq);
3943 if (ms->ms_client_seq != NULL) {
3946 OBD_ALLOC(prefix, MAX_OBD_NAME + 5);
3950 snprintf(prefix, MAX_OBD_NAME + 5, "ctl-%s",
3953 rc = seq_client_init(ms->ms_client_seq,
3955 LUSTRE_SEQ_METADATA,
3957 OBD_FREE(prefix, MAX_OBD_NAME + 5);
3964 LASSERT(ms->ms_server_seq != NULL);
3965 rc = seq_server_set_cli(ms->ms_server_seq, ms->ms_client_seq,
3972 static void mdt_seq_fini_cli(struct mdt_device *m)
3978 ms = mdt_md_site(m);
3981 if (ms->ms_server_seq)
3982 seq_server_set_cli(ms->ms_server_seq,
3985 if (ms->ms_control_exp) {
3986 class_export_put(ms->ms_control_exp);
3987 ms->ms_control_exp = NULL;
3996 static int mdt_fld_fini(const struct lu_env *env,
3997 struct mdt_device *m)
3999 struct md_site *ms = mdt_md_site(m);
4002 if (ms && ms->ms_server_fld) {
4003 fld_server_fini(ms->ms_server_fld, env);
4004 OBD_FREE_PTR(ms->ms_server_fld);
4005 ms->ms_server_fld = NULL;
4011 static int mdt_fld_init(const struct lu_env *env,
4013 struct mdt_device *m)
4019 ms = mdt_md_site(m);
4021 OBD_ALLOC_PTR(ms->ms_server_fld);
4022 if (ms->ms_server_fld == NULL)
4023 RETURN(rc = -ENOMEM);
4025 rc = fld_server_init(ms->ms_server_fld,
4026 m->mdt_bottom, uuid,
4027 env, ms->ms_node_id);
4029 OBD_FREE_PTR(ms->ms_server_fld);
4030 ms->ms_server_fld = NULL;
4037 /* device init/fini methods */
4038 static void mdt_stop_ptlrpc_service(struct mdt_device *m)
4041 if (m->mdt_regular_service != NULL) {
4042 ptlrpc_unregister_service(m->mdt_regular_service);
4043 m->mdt_regular_service = NULL;
4045 if (m->mdt_readpage_service != NULL) {
4046 ptlrpc_unregister_service(m->mdt_readpage_service);
4047 m->mdt_readpage_service = NULL;
4049 if (m->mdt_xmds_service != NULL) {
4050 ptlrpc_unregister_service(m->mdt_xmds_service);
4051 m->mdt_xmds_service = NULL;
4053 if (m->mdt_setattr_service != NULL) {
4054 ptlrpc_unregister_service(m->mdt_setattr_service);
4055 m->mdt_setattr_service = NULL;
4057 if (m->mdt_mdsc_service != NULL) {
4058 ptlrpc_unregister_service(m->mdt_mdsc_service);
4059 m->mdt_mdsc_service = NULL;
4061 if (m->mdt_mdss_service != NULL) {
4062 ptlrpc_unregister_service(m->mdt_mdss_service);
4063 m->mdt_mdss_service = NULL;
4065 if (m->mdt_dtss_service != NULL) {
4066 ptlrpc_unregister_service(m->mdt_dtss_service);
4067 m->mdt_dtss_service = NULL;
4069 if (m->mdt_fld_service != NULL) {
4070 ptlrpc_unregister_service(m->mdt_fld_service);
4071 m->mdt_fld_service = NULL;
4076 static int mdt_start_ptlrpc_service(struct mdt_device *m)
4078 static struct ptlrpc_service_conf conf;
4079 cfs_proc_dir_entry_t *procfs_entry;
4083 m->mdt_ldlm_client = &m->mdt_md_dev.md_lu_dev.ld_obd->obd_ldlm_client;
4084 ptlrpc_init_client(LDLM_CB_REQUEST_PORTAL, LDLM_CB_REPLY_PORTAL,
4085 "mdt_ldlm_client", m->mdt_ldlm_client);
4087 procfs_entry = m->mdt_md_dev.md_lu_dev.ld_obd->obd_proc_entry;
4089 conf = (typeof(conf)) {
4090 .psc_name = LUSTRE_MDT_NAME,
4091 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
4093 .bc_nbufs = MDS_NBUFS,
4094 .bc_buf_size = MDS_BUFSIZE,
4095 .bc_req_max_size = MDS_MAXREQSIZE,
4096 .bc_rep_max_size = MDS_MAXREPSIZE,
4097 .bc_req_portal = MDS_REQUEST_PORTAL,
4098 .bc_rep_portal = MDC_REPLY_PORTAL,
4101 * We'd like to have a mechanism to set this on a per-device
4102 * basis, but alas...
4105 .tc_thr_name = LUSTRE_MDT_NAME,
4106 .tc_thr_factor = MDT_THR_FACTOR,
4107 .tc_nthrs_init = MDT_NTHRS_INIT,
4108 .tc_nthrs_base = MDT_NTHRS_BASE,
4109 .tc_nthrs_max = MDT_NTHRS_MAX,
4110 .tc_nthrs_user = mds_num_threads,
4111 .tc_cpu_affinity = 1,
4112 .tc_ctx_tags = LCT_MD_THREAD,
4115 .cc_pattern = mds_num_cpts,
4118 .so_req_handler = mdt_regular_handle,
4119 .so_req_printer = target_print_req,
4120 .so_hpreq_handler = ptlrpc_hpreq_handler,
4123 m->mdt_regular_service = ptlrpc_register_service(&conf, procfs_entry);
4124 if (IS_ERR(m->mdt_regular_service)) {
4125 rc = PTR_ERR(m->mdt_regular_service);
4126 CERROR("failed to start regular mdt service: %d\n", rc);
4127 m->mdt_regular_service = NULL;
4133 * readpage service configuration. Parameters have to be adjusted,
4136 memset(&conf, 0, sizeof(conf));
4137 conf = (typeof(conf)) {
4138 .psc_name = LUSTRE_MDT_NAME "_readpage",
4139 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
4141 .bc_nbufs = MDS_NBUFS,
4142 .bc_buf_size = MDS_BUFSIZE,
4143 .bc_req_max_size = MDS_MAXREQSIZE,
4144 .bc_rep_max_size = MDS_MAXREPSIZE,
4145 .bc_req_portal = MDS_READPAGE_PORTAL,
4146 .bc_rep_portal = MDC_REPLY_PORTAL,
4149 .tc_thr_name = "mdt_rdpg",
4150 .tc_thr_factor = MDT_RDPG_THR_FACTOR,
4151 .tc_nthrs_init = MDT_RDPG_NTHRS_INIT,
4152 .tc_nthrs_base = MDT_RDPG_NTHRS_BASE,
4153 .tc_nthrs_max = MDT_RDPG_NTHRS_MAX,
4154 .tc_nthrs_user = mds_rdpg_num_threads,
4155 .tc_cpu_affinity = 1,
4156 .tc_ctx_tags = LCT_MD_THREAD,
4159 .cc_pattern = mds_rdpg_num_cpts,
4162 .so_req_handler = mdt_readpage_handle,
4163 .so_req_printer = target_print_req,
4164 .so_hpreq_handler = NULL,
4167 m->mdt_readpage_service = ptlrpc_register_service(&conf, procfs_entry);
4168 if (IS_ERR(m->mdt_readpage_service)) {
4169 rc = PTR_ERR(m->mdt_readpage_service);
4170 CERROR("failed to start readpage service: %d\n", rc);
4171 m->mdt_readpage_service = NULL;
4173 GOTO(err_mdt_svc, rc);
4177 * setattr service configuration.
4179 * XXX To keep the compatibility with old client(< 2.2), we need to
4180 * preserve this portal for a certain time, it should be removed
4181 * eventually. LU-617.
4183 memset(&conf, 0, sizeof(conf));
4184 conf = (typeof(conf)) {
4185 .psc_name = LUSTRE_MDT_NAME "_setattr",
4186 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
4188 .bc_nbufs = MDS_NBUFS,
4189 .bc_buf_size = MDS_BUFSIZE,
4190 .bc_req_max_size = MDS_MAXREQSIZE,
4191 .bc_rep_max_size = MDS_MAXREPSIZE,
4192 .bc_req_portal = MDS_SETATTR_PORTAL,
4193 .bc_rep_portal = MDC_REPLY_PORTAL,
4196 .tc_thr_name = "mdt_attr",
4197 .tc_thr_factor = MDT_SETA_THR_FACTOR,
4198 .tc_nthrs_init = MDT_SETA_NTHRS_INIT,
4199 .tc_nthrs_base = MDT_SETA_NTHRS_BASE,
4200 .tc_nthrs_max = MDT_SETA_NTHRS_MAX,
4201 .tc_nthrs_user = mds_attr_num_threads,
4202 .tc_cpu_affinity = 1,
4203 .tc_ctx_tags = LCT_MD_THREAD,
4206 .cc_pattern = mds_attr_num_cpts,
4209 .so_req_handler = mdt_regular_handle,
4210 .so_req_printer = target_print_req,
4211 .so_hpreq_handler = NULL,
4214 m->mdt_setattr_service = ptlrpc_register_service(&conf, procfs_entry);
4215 if (IS_ERR(m->mdt_setattr_service)) {
4216 rc = PTR_ERR(m->mdt_setattr_service);
4217 CERROR("failed to start setattr service: %d\n", rc);
4218 m->mdt_setattr_service = NULL;
4220 GOTO(err_mdt_svc, rc);
4224 * sequence controller service configuration
4226 memset(&conf, 0, sizeof(conf));
4227 conf = (typeof(conf)) {
4228 .psc_name = LUSTRE_MDT_NAME "_mdsc",
4229 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
4231 .bc_nbufs = MDS_NBUFS,
4232 .bc_buf_size = MDS_BUFSIZE,
4233 .bc_req_max_size = SEQ_MAXREQSIZE,
4234 .bc_rep_max_size = SEQ_MAXREPSIZE,
4235 .bc_req_portal = SEQ_CONTROLLER_PORTAL,
4236 .bc_rep_portal = MDC_REPLY_PORTAL,
4239 .tc_thr_name = "mdt_mdsc",
4240 .tc_nthrs_init = MDT_OTHR_NTHRS_INIT,
4241 .tc_nthrs_max = MDT_OTHR_NTHRS_MAX,
4242 .tc_ctx_tags = LCT_MD_THREAD,
4245 .so_req_handler = mdt_mdsc_handle,
4246 .so_req_printer = target_print_req,
4247 .so_hpreq_handler = NULL,
4250 m->mdt_mdsc_service = ptlrpc_register_service(&conf, procfs_entry);
4251 if (IS_ERR(m->mdt_mdsc_service)) {
4252 rc = PTR_ERR(m->mdt_mdsc_service);
4253 CERROR("failed to start seq controller service: %d\n", rc);
4254 m->mdt_mdsc_service = NULL;
4256 GOTO(err_mdt_svc, rc);
4260 * metadata sequence server service configuration
4262 memset(&conf, 0, sizeof(conf));
4263 conf = (typeof(conf)) {
4264 .psc_name = LUSTRE_MDT_NAME "_mdss",
4265 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
4267 .bc_nbufs = MDS_NBUFS,
4268 .bc_buf_size = MDS_BUFSIZE,
4269 .bc_req_max_size = SEQ_MAXREQSIZE,
4270 .bc_rep_max_size = SEQ_MAXREPSIZE,
4271 .bc_req_portal = SEQ_METADATA_PORTAL,
4272 .bc_rep_portal = MDC_REPLY_PORTAL,
4275 .tc_thr_name = "mdt_mdss",
4276 .tc_nthrs_init = MDT_OTHR_NTHRS_INIT,
4277 .tc_nthrs_max = MDT_OTHR_NTHRS_MAX,
4278 .tc_ctx_tags = LCT_MD_THREAD | LCT_DT_THREAD
4281 .so_req_handler = mdt_mdss_handle,
4282 .so_req_printer = target_print_req,
4283 .so_hpreq_handler = NULL,
4286 m->mdt_mdss_service = ptlrpc_register_service(&conf, procfs_entry);
4287 if (IS_ERR(m->mdt_mdss_service)) {
4288 rc = PTR_ERR(m->mdt_mdss_service);
4289 CERROR("failed to start metadata seq server service: %d\n", rc);
4290 m->mdt_mdss_service = NULL;
4292 GOTO(err_mdt_svc, rc);
4296 * Data sequence server service configuration. We want to have really
4297 * cluster-wide sequences space. This is why we start only one sequence
4298 * controller which manages space.
4300 memset(&conf, 0, sizeof(conf));
4301 conf = (typeof(conf)) {
4302 .psc_name = LUSTRE_MDT_NAME "_dtss",
4303 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
4305 .bc_nbufs = MDS_NBUFS,
4306 .bc_buf_size = MDS_BUFSIZE,
4307 .bc_req_max_size = SEQ_MAXREQSIZE,
4308 .bc_rep_max_size = SEQ_MAXREPSIZE,
4309 .bc_req_portal = SEQ_DATA_PORTAL,
4310 .bc_rep_portal = OSC_REPLY_PORTAL,
4313 .tc_thr_name = "mdt_dtss",
4314 .tc_nthrs_init = MDT_OTHR_NTHRS_INIT,
4315 .tc_nthrs_max = MDT_OTHR_NTHRS_MAX,
4316 .tc_ctx_tags = LCT_MD_THREAD | LCT_DT_THREAD
4319 .so_req_handler = mdt_dtss_handle,
4320 .so_req_printer = target_print_req,
4321 .so_hpreq_handler = NULL,
4324 m->mdt_dtss_service = ptlrpc_register_service(&conf, procfs_entry);
4325 if (IS_ERR(m->mdt_dtss_service)) {
4326 rc = PTR_ERR(m->mdt_dtss_service);
4327 CERROR("failed to start data seq server service: %d\n", rc);
4328 m->mdt_dtss_service = NULL;
4330 GOTO(err_mdt_svc, rc);
4333 /* FLD service start */
4334 memset(&conf, 0, sizeof(conf));
4335 conf = (typeof(conf)) {
4336 .psc_name = LUSTRE_MDT_NAME "_fld",
4337 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
4339 .bc_nbufs = MDS_NBUFS,
4340 .bc_buf_size = MDS_BUFSIZE,
4341 .bc_req_max_size = FLD_MAXREQSIZE,
4342 .bc_rep_max_size = FLD_MAXREPSIZE,
4343 .bc_req_portal = FLD_REQUEST_PORTAL,
4344 .bc_rep_portal = MDC_REPLY_PORTAL,
4347 .tc_thr_name = "mdt_fld",
4348 .tc_nthrs_init = MDT_OTHR_NTHRS_INIT,
4349 .tc_nthrs_max = MDT_OTHR_NTHRS_MAX,
4350 .tc_ctx_tags = LCT_DT_THREAD | LCT_MD_THREAD
4353 .so_req_handler = mdt_fld_handle,
4354 .so_req_printer = target_print_req,
4355 .so_hpreq_handler = NULL,
4358 m->mdt_fld_service = ptlrpc_register_service(&conf, procfs_entry);
4359 if (IS_ERR(m->mdt_fld_service)) {
4360 rc = PTR_ERR(m->mdt_fld_service);
4361 CERROR("failed to start fld service: %d\n", rc);
4362 m->mdt_fld_service = NULL;
4364 GOTO(err_mdt_svc, rc);
4368 * mds-mds service configuration. Separate portal is used to allow
4369 * mds-mds requests be not blocked during recovery.
4371 memset(&conf, 0, sizeof(conf));
4372 conf = (typeof(conf)) {
4373 .psc_name = LUSTRE_MDT_NAME "_mds",
4374 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
4376 .bc_nbufs = MDS_NBUFS,
4377 .bc_buf_size = MDS_BUFSIZE,
4378 .bc_req_max_size = MDS_MAXREQSIZE,
4379 .bc_rep_max_size = MDS_MAXREPSIZE,
4380 .bc_req_portal = MDS_MDS_PORTAL,
4381 .bc_rep_portal = MDC_REPLY_PORTAL,
4384 .tc_thr_name = "mdt_mds",
4385 .tc_nthrs_init = MDT_OTHR_NTHRS_INIT,
4386 .tc_nthrs_max = MDT_OTHR_NTHRS_MAX,
4387 .tc_ctx_tags = LCT_MD_THREAD,
4390 .so_req_handler = mdt_xmds_handle,
4391 .so_req_printer = target_print_req,
4392 .so_hpreq_handler = ptlrpc_hpreq_handler,
4395 m->mdt_xmds_service = ptlrpc_register_service(&conf, procfs_entry);
4396 if (IS_ERR(m->mdt_xmds_service)) {
4397 rc = PTR_ERR(m->mdt_xmds_service);
4398 CERROR("failed to start xmds service: %d\n", rc);
4399 m->mdt_xmds_service = NULL;
4401 GOTO(err_mdt_svc, rc);
4407 mdt_stop_ptlrpc_service(m);
4412 static void mdt_stack_fini(const struct lu_env *env,
4413 struct mdt_device *m, struct lu_device *top)
4415 struct obd_device *obd = mdt2obd_dev(m);
4416 struct lustre_cfg_bufs *bufs;
4417 struct lustre_cfg *lcfg;
4418 struct mdt_thread_info *info;
4422 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
4423 LASSERT(info != NULL);
4425 lu_dev_del_linkage(top->ld_site, top);
4427 bufs = &info->mti_u.bufs;
4428 /* process cleanup, pass mdt obd name to get obd umount flags */
4429 lustre_cfg_bufs_reset(bufs, obd->obd_name);
4434 lustre_cfg_bufs_set_string(bufs, 1, flags);
4435 lcfg = lustre_cfg_new(LCFG_CLEANUP, bufs);
4437 CERROR("Cannot alloc lcfg!\n");
4441 top->ld_ops->ldo_process_config(env, top, lcfg);
4442 lustre_cfg_free(lcfg);
4444 lu_stack_fini(env, top);
4445 m->mdt_child = NULL;
4446 m->mdt_bottom = NULL;
4448 obd_disconnect(m->mdt_bottom_exp);
4451 static struct lu_device *mdt_layer_setup(struct lu_env *env,
4452 const char *typename,
4453 struct lu_device *child,
4454 struct lustre_cfg *cfg)
4456 const char *dev = lustre_cfg_string(cfg, 0);
4457 struct obd_type *type;
4458 struct lu_device_type *ldt;
4459 struct lu_device *d;
4464 type = class_get_type(typename);
4466 CERROR("Unknown type: '%s'\n", typename);
4467 GOTO(out, rc = -ENODEV);
4470 rc = lu_env_refill((struct lu_env *)env);
4472 CERROR("Failure to refill session: '%d'\n", rc);
4478 CERROR("type: '%s'\n", typename);
4479 GOTO(out_type, rc = -EINVAL);
4482 ldt->ldt_obd_type = type;
4483 d = ldt->ldt_ops->ldto_device_alloc(env, ldt, cfg);
4485 CERROR("Cannot allocate device: '%s'\n", typename);
4486 GOTO(out_type, rc = -ENODEV);
4489 LASSERT(child->ld_site);
4490 d->ld_site = child->ld_site;
4493 rc = ldt->ldt_ops->ldto_device_init(env, d, dev, child);
4495 CERROR("can't init device '%s', rc %d\n", typename, rc);
4496 GOTO(out_alloc, rc);
4499 lu_ref_add(&d->ld_reference, "lu-stack", &lu_site_init);
4501 lu_dev_add_linkage(d->ld_site, d);
4504 ldt->ldt_ops->ldto_device_free(env, d);
4507 class_put_type(type);
4512 static int mdt_connect_to_next(const struct lu_env *env, struct mdt_device *m,
4513 const char *next, struct obd_export **exp)
4515 struct obd_connect_data *data = NULL;
4516 struct obd_device *obd;
4520 OBD_ALLOC_PTR(data);
4522 GOTO(out, rc = -ENOMEM);
4524 obd = class_name2obd(next);
4526 CERROR("%s: can't locate next device: %s\n",
4527 m->mdt_md_dev.md_lu_dev.ld_obd->obd_name, next);
4528 GOTO(out, rc = -ENOTCONN);
4531 data->ocd_connect_flags = OBD_CONNECT_VERSION;
4532 data->ocd_version = LUSTRE_VERSION_CODE;
4534 rc = obd_connect(NULL, exp, obd, &obd->obd_uuid, data, NULL);
4536 CERROR("%s: cannot connect to next dev %s (%d)\n",
4537 m->mdt_md_dev.md_lu_dev.ld_obd->obd_name, next, rc);
4547 static int mdt_stack_init(struct lu_env *env,
4548 struct mdt_device *m,
4549 struct lustre_cfg *cfg,
4550 struct lustre_mount_info *lmi)
4552 struct lu_device *d = &m->mdt_md_dev.md_lu_dev;
4553 struct lu_device *tmp;
4554 struct md_device *md;
4555 struct lu_device *child_lu_dev;
4560 /* find bottom osd */
4561 OBD_ALLOC(osdname, MTI_NAME_MAXLEN);
4562 if (osdname == NULL)
4565 snprintf(osdname, MTI_NAME_MAXLEN, "%s-osd", lustre_cfg_string(cfg, 0));
4566 rc = mdt_connect_to_next(env, m, osdname, &m->mdt_bottom_exp);
4567 OBD_FREE(osdname, MTI_NAME_MAXLEN);
4571 tmp = m->mdt_bottom_exp->exp_obd->obd_lu_dev;
4573 m->mdt_bottom = lu2dt_dev(tmp);
4575 /* initialize site's pointers: md_site, top device */
4576 d->ld_site = tmp->ld_site;
4577 d->ld_site->ls_top_dev = d;
4578 m->mdt_mite.ms_lu = tmp->ld_site;
4579 tmp->ld_site->ld_md_site = &m->mdt_mite;
4580 LASSERT(d->ld_site);
4583 tmp = mdt_layer_setup(env, LUSTRE_MDD_NAME, d, cfg);
4585 GOTO(out, rc = PTR_ERR(tmp));
4590 tmp = mdt_layer_setup(env, LUSTRE_CMM_NAME, d, cfg);
4592 GOTO(out, rc = PTR_ERR(tmp));
4595 /*set mdd upcall device*/
4596 md_upcall_dev_set(md, lu2md_dev(d));
4599 /*set cmm upcall device*/
4600 md_upcall_dev_set(md, &m->mdt_md_dev);
4602 m->mdt_child = lu2md_dev(d);
4604 /* process setup config */
4605 tmp = &m->mdt_md_dev.md_lu_dev;
4606 rc = tmp->ld_ops->ldo_process_config(env, tmp, cfg);
4610 /* initialize local objects */
4611 child_lu_dev = &m->mdt_child->md_lu_dev;
4613 rc = child_lu_dev->ld_ops->ldo_prepare(env,
4614 &m->mdt_md_dev.md_lu_dev,
4617 /* fini from last known good lu_device */
4619 mdt_stack_fini(env, m, d);
4625 * setup CONFIG_ORIG context, used to access local config log.
4626 * this may need to be rewrite as part of llog rewrite for lu-api.
4628 static int mdt_obd_llog_setup(struct obd_device *obd,
4629 struct lustre_sb_info *lsi)
4633 LASSERT(obd->obd_fsops == NULL);
4635 obd->obd_fsops = fsfilt_get_ops(lsi->lsi_fstype);
4636 if (IS_ERR(obd->obd_fsops))
4637 return PTR_ERR(obd->obd_fsops);
4639 rc = fsfilt_setup(obd, lsi->lsi_srv_mnt->mnt_sb);
4641 fsfilt_put_ops(obd->obd_fsops);
4645 OBD_SET_CTXT_MAGIC(&obd->obd_lvfs_ctxt);
4646 obd->obd_lvfs_ctxt.pwdmnt = lsi->lsi_srv_mnt;
4647 obd->obd_lvfs_ctxt.pwd = lsi->lsi_srv_mnt->mnt_root;
4648 obd->obd_lvfs_ctxt.fs = get_ds();
4650 rc = llog_setup(obd, &obd->obd_olg, LLOG_CONFIG_ORIG_CTXT, obd,
4651 0, NULL, &llog_lvfs_ops);
4653 CERROR("llog_setup() failed: %d\n", rc);
4654 fsfilt_put_ops(obd->obd_fsops);
4660 static void mdt_obd_llog_cleanup(struct obd_device *obd)
4662 struct llog_ctxt *ctxt;
4664 ctxt = llog_get_context(obd, LLOG_CONFIG_ORIG_CTXT);
4668 if (obd->obd_fsops) {
4669 fsfilt_put_ops(obd->obd_fsops);
4670 obd->obd_fsops = NULL;
4674 static void mdt_fini(const struct lu_env *env, struct mdt_device *m)
4676 struct md_device *next = m->mdt_child;
4677 struct lu_device *d = &m->mdt_md_dev.md_lu_dev;
4678 struct obd_device *obd = mdt2obd_dev(m);
4681 target_recovery_fini(obd);
4683 ping_evictor_stop();
4685 mdt_stop_ptlrpc_service(m);
4686 mdt_llog_ctxt_unclone(env, m, LLOG_CHANGELOG_ORIG_CTXT);
4687 mdt_obd_llog_cleanup(obd);
4688 obd_exports_barrier(obd);
4689 obd_zombie_barrier();
4693 #ifdef HAVE_QUOTA_SUPPORT
4694 next->md_ops->mdo_quota.mqo_cleanup(env, next);
4696 lut_fini(env, &m->mdt_lut);
4697 mdt_fs_cleanup(env, m);
4698 upcall_cache_cleanup(m->mdt_identity_cache);
4699 m->mdt_identity_cache = NULL;
4701 if (m->mdt_namespace != NULL) {
4702 ldlm_namespace_free(m->mdt_namespace, NULL,
4703 d->ld_obd->obd_force);
4704 d->ld_obd->obd_namespace = m->mdt_namespace = NULL;
4707 cfs_free_nidlist(&m->mdt_nosquash_nids);
4708 if (m->mdt_nosquash_str) {
4709 OBD_FREE(m->mdt_nosquash_str, m->mdt_nosquash_strlen);
4710 m->mdt_nosquash_str = NULL;
4711 m->mdt_nosquash_strlen = 0;
4714 mdt_seq_fini(env, m);
4715 mdt_seq_fini_cli(m);
4716 mdt_fld_fini(env, m);
4717 sptlrpc_rule_set_free(&m->mdt_sptlrpc_rset);
4719 next->md_ops->mdo_init_capa_ctxt(env, next, 0, 0, 0, NULL);
4720 cfs_timer_disarm(&m->mdt_ck_timer);
4721 mdt_ck_thread_stop(m);
4726 mdt_stack_fini(env, m, md2lu_dev(m->mdt_child));
4728 LASSERT(cfs_atomic_read(&d->ld_ref) == 0);
4730 server_put_mount(mdt2obd_dev(m)->obd_name, NULL);
4735 static int mdt_adapt_sptlrpc_conf(struct obd_device *obd, int initial)
4737 struct mdt_device *m = mdt_dev(obd->obd_lu_dev);
4738 struct sptlrpc_rule_set tmp_rset;
4741 sptlrpc_rule_set_init(&tmp_rset);
4742 rc = sptlrpc_conf_target_get_rules(obd, &tmp_rset, initial);
4744 CERROR("mdt %s: failed get sptlrpc rules: %d\n",
4749 sptlrpc_target_update_exp_flavor(obd, &tmp_rset);
4751 cfs_write_lock(&m->mdt_sptlrpc_lock);
4752 sptlrpc_rule_set_free(&m->mdt_sptlrpc_rset);
4753 m->mdt_sptlrpc_rset = tmp_rset;
4754 cfs_write_unlock(&m->mdt_sptlrpc_lock);
4759 int mdt_postrecov(const struct lu_env *, struct mdt_device *);
4761 static int mdt_init0(const struct lu_env *env, struct mdt_device *m,
4762 struct lu_device_type *ldt, struct lustre_cfg *cfg)
4764 struct mdt_thread_info *info;
4765 struct obd_device *obd;
4766 const char *dev = lustre_cfg_string(cfg, 0);
4767 const char *num = lustre_cfg_string(cfg, 2);
4768 struct lustre_mount_info *lmi = NULL;
4769 struct lustre_sb_info *lsi;
4771 struct md_site *mite;
4772 const char *identity_upcall = "NONE";
4773 struct md_device *next;
4779 md_device_init(&m->mdt_md_dev, ldt);
4781 * Environment (env) might be missing mdt_thread_key values at that
4782 * point, if device is allocated when mdt_thread_key is in QUIESCENT
4785 * Usually device allocation path doesn't use module key values, but
4786 * mdt has to do a lot of work here, so allocate key value.
4788 rc = lu_env_refill((struct lu_env *)env);
4792 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
4793 LASSERT(info != NULL);
4795 obd = class_name2obd(dev);
4796 LASSERT(obd != NULL);
4798 m->mdt_max_mdsize = MAX_MD_SIZE; /* 4 stripes */
4799 m->mdt_max_cookiesize = sizeof(struct llog_cookie);
4801 m->mdt_som_conf = 0;
4803 m->mdt_opts.mo_cos = MDT_COS_DEFAULT;
4804 lmi = server_get_mount(dev);
4806 CERROR("Cannot get mount info for %s!\n", dev);
4809 lsi = s2lsi(lmi->lmi_sb);
4810 /* CMD is supported only in IAM mode */
4812 node_id = simple_strtol(num, NULL, 10);
4813 if (!(lsi->lsi_flags & LDD_F_IAM_DIR) && node_id) {
4814 CERROR("CMD Operation not allowed in IOP mode\n");
4815 GOTO(err_lmi, rc = -EINVAL);
4818 obd->u.obt.obt_magic = OBT_MAGIC;
4821 cfs_rwlock_init(&m->mdt_sptlrpc_lock);
4822 sptlrpc_rule_set_init(&m->mdt_sptlrpc_rset);
4824 cfs_spin_lock_init(&m->mdt_ioepoch_lock);
4825 m->mdt_opts.mo_compat_resname = 0;
4826 m->mdt_opts.mo_mds_capa = 1;
4827 m->mdt_opts.mo_oss_capa = 1;
4828 m->mdt_capa_timeout = CAPA_TIMEOUT;
4829 m->mdt_capa_alg = CAPA_HMAC_ALG_SHA1;
4830 m->mdt_ck_timeout = CAPA_KEY_TIMEOUT;
4831 m->mdt_squash_uid = 0;
4832 m->mdt_squash_gid = 0;
4833 CFS_INIT_LIST_HEAD(&m->mdt_nosquash_nids);
4834 m->mdt_nosquash_str = NULL;
4835 m->mdt_nosquash_strlen = 0;
4836 cfs_init_rwsem(&m->mdt_squash_sem);
4837 cfs_spin_lock_init(&m->mdt_osfs_lock);
4838 m->mdt_osfs_age = cfs_time_shift_64(-1000);
4840 m->mdt_md_dev.md_lu_dev.ld_ops = &mdt_lu_ops;
4841 m->mdt_md_dev.md_lu_dev.ld_obd = obd;
4842 /* set this lu_device to obd, because error handling need it */
4843 obd->obd_lu_dev = &m->mdt_md_dev.md_lu_dev;
4845 /* init the stack */
4846 rc = mdt_stack_init((struct lu_env *)env, m, cfg, lmi);
4848 CERROR("Can't init device stack, rc %d\n", rc);
4852 s = m->mdt_md_dev.md_lu_dev.ld_site;
4853 mite = &m->mdt_mite;
4855 /* set server index */
4856 mite->ms_node_id = node_id;
4858 /* failover is the default
4859 * FIXME: we do not failout mds0/mgs, which may cause some problems.
4860 * assumed whose ms_node_id == 0 XXX
4862 obd->obd_replayable = 1;
4863 /* No connection accepted until configurations will finish */
4864 obd->obd_no_conn = 1;
4866 if (cfg->lcfg_bufcount > 4 && LUSTRE_CFG_BUFLEN(cfg, 4) > 0) {
4867 char *str = lustre_cfg_string(cfg, 4);
4868 if (strchr(str, 'n')) {
4869 CWARN("%s: recovery disabled\n", obd->obd_name);
4870 obd->obd_replayable = 0;
4874 rc = lut_init(env, &m->mdt_lut, obd, m->mdt_bottom);
4876 GOTO(err_fini_stack, rc);
4878 rc = mdt_fld_init(env, obd->obd_name, m);
4882 rc = mdt_seq_init(env, obd->obd_name, m);
4884 GOTO(err_fini_fld, rc);
4886 snprintf(info->mti_u.ns_name, sizeof info->mti_u.ns_name,
4887 LUSTRE_MDT_NAME"-%p", m);
4888 m->mdt_namespace = ldlm_namespace_new(obd, info->mti_u.ns_name,
4889 LDLM_NAMESPACE_SERVER,
4890 LDLM_NAMESPACE_GREEDY,
4892 if (m->mdt_namespace == NULL)
4893 GOTO(err_fini_seq, rc = -ENOMEM);
4895 ldlm_register_intent(m->mdt_namespace, mdt_intent_policy);
4896 /* set obd_namespace for compatibility with old code */
4897 obd->obd_namespace = m->mdt_namespace;
4899 cfs_timer_init(&m->mdt_ck_timer, mdt_ck_timer_callback, m);
4901 rc = mdt_ck_thread_start(m);
4903 GOTO(err_free_ns, rc);
4905 rc = mdt_fs_setup(env, m, obd, lsi);
4909 rc = mdt_obd_llog_setup(obd, lsi);
4911 GOTO(err_fs_cleanup, rc);
4913 rc = mdt_llog_ctxt_clone(env, m, LLOG_CHANGELOG_ORIG_CTXT);
4915 GOTO(err_llog_cleanup, rc);
4917 mdt_adapt_sptlrpc_conf(obd, 1);
4919 next = m->mdt_child;
4920 #ifdef HAVE_QUOTA_SUPPORT
4921 rc = next->md_ops->mdo_quota.mqo_setup(env, next, lmi->lmi_mnt);
4923 GOTO(err_llog_cleanup, rc);
4926 rc = next->md_ops->mdo_iocontrol(env, next, OBD_IOC_GET_MNTOPT, 0,
4929 GOTO(err_quota, rc);
4931 if (mntopts & MNTOPT_USERXATTR)
4932 m->mdt_opts.mo_user_xattr = 1;
4934 m->mdt_opts.mo_user_xattr = 0;
4936 if (mntopts & MNTOPT_ACL)
4937 m->mdt_opts.mo_acl = 1;
4939 m->mdt_opts.mo_acl = 0;
4941 /* XXX: to support suppgid for ACL, we enable identity_upcall
4942 * by default, otherwise, maybe got unexpected -EACCESS. */
4943 if (m->mdt_opts.mo_acl)
4944 identity_upcall = MDT_IDENTITY_UPCALL_PATH;
4946 m->mdt_identity_cache = upcall_cache_init(obd->obd_name,identity_upcall,
4947 &mdt_identity_upcall_cache_ops);
4948 if (IS_ERR(m->mdt_identity_cache)) {
4949 rc = PTR_ERR(m->mdt_identity_cache);
4950 m->mdt_identity_cache = NULL;
4951 GOTO(err_quota, rc);
4954 target_recovery_init(&m->mdt_lut, mdt_recovery_handle);
4956 rc = mdt_procfs_init(m, dev);
4958 CERROR("Can't init MDT lprocfs, rc %d\n", rc);
4959 GOTO(err_recovery, rc);
4962 rc = mdt_start_ptlrpc_service(m);
4964 GOTO(err_procfs, rc);
4966 ping_evictor_start();
4968 if (obd->obd_recovering == 0)
4969 mdt_postrecov(env, m);
4971 mdt_init_capa_ctxt(env, m);
4973 /* Reduce the initial timeout on an MDS because it doesn't need such
4974 * a long timeout as an OST does. Adaptive timeouts will adjust this
4975 * value appropriately. */
4976 if (ldlm_timeout == LDLM_TIMEOUT_DEFAULT)
4977 ldlm_timeout = MDS_LDLM_TIMEOUT_DEFAULT;
4981 ping_evictor_stop();
4982 mdt_stop_ptlrpc_service(m);
4986 target_recovery_fini(obd);
4987 upcall_cache_cleanup(m->mdt_identity_cache);
4988 m->mdt_identity_cache = NULL;
4990 #ifdef HAVE_QUOTA_SUPPORT
4991 next->md_ops->mdo_quota.mqo_cleanup(env, next);
4994 mdt_llog_ctxt_unclone(env, m, LLOG_CHANGELOG_ORIG_CTXT);
4995 mdt_obd_llog_cleanup(obd);
4997 mdt_fs_cleanup(env, m);
4999 cfs_timer_disarm(&m->mdt_ck_timer);
5000 mdt_ck_thread_stop(m);
5002 ldlm_namespace_free(m->mdt_namespace, NULL, 0);
5003 obd->obd_namespace = m->mdt_namespace = NULL;
5005 mdt_seq_fini(env, m);
5007 mdt_fld_fini(env, m);
5009 lut_fini(env, &m->mdt_lut);
5011 mdt_stack_fini(env, m, md2lu_dev(m->mdt_child));
5014 server_put_mount(dev, lmi->lmi_mnt);
5018 /* For interoperability between 1.8 and 2.0. */
5019 static struct cfg_interop_param mdt_interop_param[] = {
5020 { "mdt.group_upcall", NULL },
5021 { "mdt.quota_type", "mdd.quota_type" },
5022 { "mdt.rootsquash", "mdt.root_squash" },
5023 { "mdt.nosquash_nid", "mdt.nosquash_nids" },
5027 /* used by MGS to process specific configurations */
5028 static int mdt_process_config(const struct lu_env *env,
5029 struct lu_device *d, struct lustre_cfg *cfg)
5031 struct mdt_device *m = mdt_dev(d);
5032 struct md_device *md_next = m->mdt_child;
5033 struct lu_device *next = md2lu_dev(md_next);
5037 switch (cfg->lcfg_command) {
5039 struct lprocfs_static_vars lvars;
5040 struct obd_device *obd = d->ld_obd;
5042 /* For interoperability between 1.8 and 2.0. */
5043 struct cfg_interop_param *ptr = NULL;
5044 struct lustre_cfg *old_cfg = NULL;
5047 param = lustre_cfg_string(cfg, 1);
5048 if (param == NULL) {
5049 CERROR("param is empty\n");
5054 ptr = class_find_old_param(param, mdt_interop_param);
5056 if (ptr->new_param == NULL) {
5057 CWARN("For 1.8 interoperability, skip this %s."
5058 " It is obsolete.\n", ptr->old_param);
5062 CWARN("Found old param %s, changed it to %s.\n",
5063 ptr->old_param, ptr->new_param);
5066 cfg = lustre_cfg_rename(old_cfg, ptr->new_param);
5073 lprocfs_mdt_init_vars(&lvars);
5074 rc = class_process_proc_param(PARAM_MDT, lvars.obd_vars,
5076 if (rc > 0 || rc == -ENOSYS)
5077 /* we don't understand; pass it on */
5078 rc = next->ld_ops->ldo_process_config(env, next, cfg);
5080 if (old_cfg != NULL)
5081 lustre_cfg_free(cfg);
5087 * Add mdc hook to get first MDT uuid and connect it to
5088 * ls->controller to use for seq manager.
5090 rc = next->ld_ops->ldo_process_config(env, next, cfg);
5092 CERROR("Can't add mdc, rc %d\n", rc);
5094 rc = mdt_seq_init_cli(env, mdt_dev(d), cfg);
5097 /* others are passed further */
5098 rc = next->ld_ops->ldo_process_config(env, next, cfg);
5104 static struct lu_object *mdt_object_alloc(const struct lu_env *env,
5105 const struct lu_object_header *hdr,
5106 struct lu_device *d)
5108 struct mdt_object *mo;
5112 OBD_SLAB_ALLOC_PTR_GFP(mo, mdt_object_kmem, CFS_ALLOC_IO);
5114 struct lu_object *o;
5115 struct lu_object_header *h;
5117 o = &mo->mot_obj.mo_lu;
5118 h = &mo->mot_header;
5119 lu_object_header_init(h);
5120 lu_object_init(o, h, d);
5121 lu_object_add_top(h, o);
5122 o->lo_ops = &mdt_obj_ops;
5123 cfs_mutex_init(&mo->mot_ioepoch_mutex);
5124 cfs_mutex_init(&mo->mot_lov_mutex);
5130 static int mdt_object_init(const struct lu_env *env, struct lu_object *o,
5131 const struct lu_object_conf *unused)
5133 struct mdt_device *d = mdt_dev(o->lo_dev);
5134 struct lu_device *under;
5135 struct lu_object *below;
5139 CDEBUG(D_INFO, "object init, fid = "DFID"\n",
5140 PFID(lu_object_fid(o)));
5142 under = &d->mdt_child->md_lu_dev;
5143 below = under->ld_ops->ldo_object_alloc(env, o->lo_header, under);
5144 if (below != NULL) {
5145 lu_object_add(o, below);
5152 static void mdt_object_free(const struct lu_env *env, struct lu_object *o)
5154 struct mdt_object *mo = mdt_obj(o);
5155 struct lu_object_header *h;
5159 CDEBUG(D_INFO, "object free, fid = "DFID"\n",
5160 PFID(lu_object_fid(o)));
5163 lu_object_header_fini(h);
5164 OBD_SLAB_FREE_PTR(mo, mdt_object_kmem);
5169 static int mdt_object_print(const struct lu_env *env, void *cookie,
5170 lu_printer_t p, const struct lu_object *o)
5172 struct mdt_object *mdto = mdt_obj((struct lu_object *)o);
5173 return (*p)(env, cookie, LUSTRE_MDT_NAME"-object@%p(ioepoch="LPU64" "
5174 "flags="LPX64", epochcount=%d, writecount=%d)",
5175 mdto, mdto->mot_ioepoch, mdto->mot_flags,
5176 mdto->mot_ioepoch_count, mdto->mot_writecount);
5179 static const struct lu_device_operations mdt_lu_ops = {
5180 .ldo_object_alloc = mdt_object_alloc,
5181 .ldo_process_config = mdt_process_config,
5184 static const struct lu_object_operations mdt_obj_ops = {
5185 .loo_object_init = mdt_object_init,
5186 .loo_object_free = mdt_object_free,
5187 .loo_object_print = mdt_object_print
5190 static int mdt_obd_set_info_async(const struct lu_env *env,
5191 struct obd_export *exp,
5192 __u32 keylen, void *key,
5193 __u32 vallen, void *val,
5194 struct ptlrpc_request_set *set)
5196 struct obd_device *obd = exp->exp_obd;
5202 if (KEY_IS(KEY_SPTLRPC_CONF)) {
5203 rc = mdt_adapt_sptlrpc_conf(obd, 0);
5210 /* mds_connect_internal */
5211 static int mdt_connect_internal(struct obd_export *exp,
5212 struct mdt_device *mdt,
5213 struct obd_connect_data *data)
5216 data->ocd_connect_flags &= MDT_CONNECT_SUPPORTED;
5217 data->ocd_ibits_known &= MDS_INODELOCK_FULL;
5219 /* If no known bits (which should not happen, probably,
5220 as everybody should support LOOKUP and UPDATE bits at least)
5221 revert to compat mode with plain locks. */
5222 if (!data->ocd_ibits_known &&
5223 data->ocd_connect_flags & OBD_CONNECT_IBITS)
5224 data->ocd_connect_flags &= ~OBD_CONNECT_IBITS;
5226 if (!mdt->mdt_opts.mo_acl)
5227 data->ocd_connect_flags &= ~OBD_CONNECT_ACL;
5229 if (!mdt->mdt_opts.mo_user_xattr)
5230 data->ocd_connect_flags &= ~OBD_CONNECT_XATTR;
5232 if (!mdt->mdt_som_conf)
5233 data->ocd_connect_flags &= ~OBD_CONNECT_SOM;
5235 if (data->ocd_connect_flags & OBD_CONNECT_BRW_SIZE) {
5236 data->ocd_brw_size = min(data->ocd_brw_size,
5237 (__u32)(PTLRPC_MAX_BRW_PAGES << CFS_PAGE_SHIFT));
5238 if (data->ocd_brw_size == 0) {
5239 CERROR("%s: cli %s/%p ocd_connect_flags: "LPX64
5240 " ocd_version: %x ocd_grant: %d "
5241 "ocd_index: %u ocd_brw_size is "
5242 "unexpectedly zero, network data "
5243 "corruption? Refusing connection of this"
5245 exp->exp_obd->obd_name,
5246 exp->exp_client_uuid.uuid,
5247 exp, data->ocd_connect_flags, data->ocd_version,
5248 data->ocd_grant, data->ocd_index);
5253 cfs_spin_lock(&exp->exp_lock);
5254 exp->exp_connect_flags = data->ocd_connect_flags;
5255 cfs_spin_unlock(&exp->exp_lock);
5256 data->ocd_version = LUSTRE_VERSION_CODE;
5257 exp->exp_mdt_data.med_ibits_known = data->ocd_ibits_known;
5261 if (mdt->mdt_opts.mo_acl &&
5262 ((exp->exp_connect_flags & OBD_CONNECT_ACL) == 0)) {
5263 CWARN("%s: MDS requires ACL support but client does not\n",
5264 mdt->mdt_md_dev.md_lu_dev.ld_obd->obd_name);
5269 if ((exp->exp_connect_flags & OBD_CONNECT_FID) == 0) {
5270 CWARN("%s: MDS requires FID support, but client not\n",
5271 mdt->mdt_md_dev.md_lu_dev.ld_obd->obd_name);
5275 if (mdt->mdt_som_conf && !exp_connect_som(exp) &&
5276 !(exp->exp_connect_flags & OBD_CONNECT_MDS_MDS)) {
5277 CWARN("%s: MDS has SOM enabled, but client does not support "
5278 "it\n", mdt->mdt_md_dev.md_lu_dev.ld_obd->obd_name);
5285 static int mdt_connect_check_sptlrpc(struct mdt_device *mdt,
5286 struct obd_export *exp,
5287 struct ptlrpc_request *req)
5289 struct sptlrpc_flavor flvr;
5292 if (exp->exp_flvr.sf_rpc == SPTLRPC_FLVR_INVALID) {
5293 cfs_read_lock(&mdt->mdt_sptlrpc_lock);
5294 sptlrpc_target_choose_flavor(&mdt->mdt_sptlrpc_rset,
5298 cfs_read_unlock(&mdt->mdt_sptlrpc_lock);
5300 cfs_spin_lock(&exp->exp_lock);
5302 exp->exp_sp_peer = req->rq_sp_from;
5303 exp->exp_flvr = flvr;
5305 if (exp->exp_flvr.sf_rpc != SPTLRPC_FLVR_ANY &&
5306 exp->exp_flvr.sf_rpc != req->rq_flvr.sf_rpc) {
5307 CERROR("unauthorized rpc flavor %x from %s, "
5308 "expect %x\n", req->rq_flvr.sf_rpc,
5309 libcfs_nid2str(req->rq_peer.nid),
5310 exp->exp_flvr.sf_rpc);
5314 cfs_spin_unlock(&exp->exp_lock);
5316 if (exp->exp_sp_peer != req->rq_sp_from) {
5317 CERROR("RPC source %s doesn't match %s\n",
5318 sptlrpc_part2name(req->rq_sp_from),
5319 sptlrpc_part2name(exp->exp_sp_peer));
5322 rc = sptlrpc_target_export_check(exp, req);
5329 /* mds_connect copy */
5330 static int mdt_obd_connect(const struct lu_env *env,
5331 struct obd_export **exp, struct obd_device *obd,
5332 struct obd_uuid *cluuid,
5333 struct obd_connect_data *data,
5336 struct mdt_thread_info *info;
5337 struct obd_export *lexp;
5338 struct lustre_handle conn = { 0 };
5339 struct mdt_device *mdt;
5340 struct ptlrpc_request *req;
5344 LASSERT(env != NULL);
5345 if (!exp || !obd || !cluuid)
5348 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
5349 req = info->mti_pill->rc_req;
5350 mdt = mdt_dev(obd->obd_lu_dev);
5352 rc = class_connect(&conn, obd, cluuid);
5356 lexp = class_conn2export(&conn);
5357 LASSERT(lexp != NULL);
5359 rc = mdt_connect_check_sptlrpc(mdt, lexp, req);
5363 if (OBD_FAIL_CHECK(OBD_FAIL_TGT_RCVG_FLAG))
5364 lustre_msg_add_op_flags(req->rq_repmsg, MSG_CONNECT_RECOVERING);
5366 rc = mdt_connect_internal(lexp, mdt, data);
5368 struct lsd_client_data *lcd = lexp->exp_target_data.ted_lcd;
5371 info->mti_exp = lexp;
5372 memcpy(lcd->lcd_uuid, cluuid, sizeof lcd->lcd_uuid);
5373 rc = lut_client_new(env, lexp);
5375 mdt_export_stats_init(obd, lexp, localdata);
5380 class_disconnect(lexp);
5389 static int mdt_obd_reconnect(const struct lu_env *env,
5390 struct obd_export *exp, struct obd_device *obd,
5391 struct obd_uuid *cluuid,
5392 struct obd_connect_data *data,
5395 struct mdt_thread_info *info;
5396 struct mdt_device *mdt;
5397 struct ptlrpc_request *req;
5401 if (exp == NULL || obd == NULL || cluuid == NULL)
5404 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
5405 req = info->mti_pill->rc_req;
5406 mdt = mdt_dev(obd->obd_lu_dev);
5408 rc = mdt_connect_check_sptlrpc(mdt, exp, req);
5412 rc = mdt_connect_internal(exp, mdt_dev(obd->obd_lu_dev), data);
5414 mdt_export_stats_init(obd, exp, localdata);
5419 static int mdt_export_cleanup(struct obd_export *exp)
5421 struct mdt_export_data *med = &exp->exp_mdt_data;
5422 struct obd_device *obd = exp->exp_obd;
5423 struct mdt_device *mdt;
5424 struct mdt_thread_info *info;
5426 CFS_LIST_HEAD(closing_list);
5427 struct mdt_file_data *mfd, *n;
5431 cfs_spin_lock(&med->med_open_lock);
5432 while (!cfs_list_empty(&med->med_open_head)) {
5433 cfs_list_t *tmp = med->med_open_head.next;
5434 mfd = cfs_list_entry(tmp, struct mdt_file_data, mfd_list);
5436 /* Remove mfd handle so it can't be found again.
5437 * We are consuming the mfd_list reference here. */
5438 class_handle_unhash(&mfd->mfd_handle);
5439 cfs_list_move_tail(&mfd->mfd_list, &closing_list);
5441 cfs_spin_unlock(&med->med_open_lock);
5442 mdt = mdt_dev(obd->obd_lu_dev);
5443 LASSERT(mdt != NULL);
5445 rc = lu_env_init(&env, LCT_MD_THREAD);
5449 info = lu_context_key_get(&env.le_ctx, &mdt_thread_key);
5450 LASSERT(info != NULL);
5451 memset(info, 0, sizeof *info);
5452 info->mti_env = &env;
5453 info->mti_mdt = mdt;
5454 info->mti_exp = exp;
5456 if (!cfs_list_empty(&closing_list)) {
5457 struct md_attr *ma = &info->mti_attr;
5461 lmm_size = mdt->mdt_max_mdsize;
5462 OBD_ALLOC_LARGE(ma->ma_lmm, lmm_size);
5463 if (ma->ma_lmm == NULL)
5464 GOTO(out_lmm, rc = -ENOMEM);
5466 cookie_size = mdt->mdt_max_cookiesize;
5467 OBD_ALLOC_LARGE(ma->ma_cookie, cookie_size);
5468 if (ma->ma_cookie == NULL)
5469 GOTO(out_cookie, rc = -ENOMEM);
5471 /* Close any open files (which may also cause orphan unlinking). */
5472 cfs_list_for_each_entry_safe(mfd, n, &closing_list, mfd_list) {
5473 cfs_list_del_init(&mfd->mfd_list);
5474 memset(&ma->ma_attr, 0, sizeof(ma->ma_attr));
5475 ma->ma_lmm_size = lmm_size;
5476 ma->ma_cookie_size = cookie_size;
5478 /* It is not for setattr, just tell MDD to send
5479 * DESTROY RPC to OSS if needed */
5480 ma->ma_valid = MA_FLAGS;
5481 ma->ma_attr_flags = MDS_CLOSE_CLEANUP;
5482 /* Don't unlink orphan on failover umount, LU-184 */
5483 if (exp->exp_flags & OBD_OPT_FAILOVER)
5484 ma->ma_attr_flags |= MDS_KEEP_ORPHAN;
5485 mdt_mfd_close(info, mfd);
5487 OBD_FREE_LARGE(ma->ma_cookie, cookie_size);
5488 ma->ma_cookie = NULL;
5490 OBD_FREE_LARGE(ma->ma_lmm, lmm_size);
5494 info->mti_mdt = NULL;
5495 /* cleanup client slot early */
5496 /* Do not erase record for recoverable client. */
5497 if (!(exp->exp_flags & OBD_OPT_FAILOVER) || exp->exp_failed)
5498 lut_client_del(&env, exp);
5504 static int mdt_obd_disconnect(struct obd_export *exp)
5510 class_export_get(exp);
5512 rc = server_disconnect_export(exp);
5514 CDEBUG(D_IOCTL, "server disconnect error: %d\n", rc);
5516 rc = mdt_export_cleanup(exp);
5517 class_export_put(exp);
5521 /* FIXME: Can we avoid using these two interfaces? */
5522 static int mdt_init_export(struct obd_export *exp)
5524 struct mdt_export_data *med = &exp->exp_mdt_data;
5528 CFS_INIT_LIST_HEAD(&med->med_open_head);
5529 cfs_spin_lock_init(&med->med_open_lock);
5530 cfs_mutex_init(&med->med_idmap_mutex);
5531 med->med_idmap = NULL;
5532 cfs_spin_lock(&exp->exp_lock);
5533 exp->exp_connecting = 1;
5534 cfs_spin_unlock(&exp->exp_lock);
5536 /* self-export doesn't need client data and ldlm initialization */
5537 if (unlikely(obd_uuid_equals(&exp->exp_obd->obd_uuid,
5538 &exp->exp_client_uuid)))
5541 rc = lut_client_alloc(exp);
5545 rc = ldlm_init_export(exp);
5552 lut_client_free(exp);
5554 CERROR("%s: Failed to initialize export: rc = %d\n",
5555 exp->exp_obd->obd_name, rc);
5559 static int mdt_destroy_export(struct obd_export *exp)
5563 if (exp_connect_rmtclient(exp))
5564 mdt_cleanup_idmap(&exp->exp_mdt_data);
5566 target_destroy_export(exp);
5567 /* destroy can be called from failed obd_setup, so
5568 * checking uuid is safer than obd_self_export */
5569 if (unlikely(obd_uuid_equals(&exp->exp_obd->obd_uuid,
5570 &exp->exp_client_uuid)))
5573 ldlm_destroy_export(exp);
5574 lut_client_free(exp);
5576 LASSERT(cfs_list_empty(&exp->exp_outstanding_replies));
5577 LASSERT(cfs_list_empty(&exp->exp_mdt_data.med_open_head));
5582 static void mdt_allow_cli(struct mdt_device *m, unsigned int flag)
5584 if (flag & CONFIG_LOG)
5585 cfs_set_bit(MDT_FL_CFGLOG, &m->mdt_state);
5587 /* also notify active event */
5588 if (flag & CONFIG_SYNC)
5589 cfs_set_bit(MDT_FL_SYNCED, &m->mdt_state);
5591 if (cfs_test_bit(MDT_FL_CFGLOG, &m->mdt_state) &&
5592 cfs_test_bit(MDT_FL_SYNCED, &m->mdt_state)) {
5593 struct obd_device *obd = m->mdt_md_dev.md_lu_dev.ld_obd;
5595 /* Open for clients */
5596 if (obd->obd_no_conn) {
5597 cfs_spin_lock(&obd->obd_dev_lock);
5598 obd->obd_no_conn = 0;
5599 cfs_spin_unlock(&obd->obd_dev_lock);
5604 static int mdt_upcall(const struct lu_env *env, struct md_device *md,
5605 enum md_upcall_event ev, void *data)
5607 struct mdt_device *m = mdt_dev(&md->md_lu_dev);
5608 struct md_device *next = m->mdt_child;
5609 struct mdt_thread_info *mti;
5615 rc = next->md_ops->mdo_maxsize_get(env, next,
5617 &m->mdt_max_cookiesize);
5618 CDEBUG(D_INFO, "get max mdsize %d max cookiesize %d\n",
5619 m->mdt_max_mdsize, m->mdt_max_cookiesize);
5620 mdt_allow_cli(m, CONFIG_SYNC);
5623 m->mdt_lut.lut_obd->u.obt.obt_mount_count;
5626 mti = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
5627 mti->mti_no_need_trans = 1;
5628 CDEBUG(D_INFO, "disable mdt trans for this thread\n");
5631 /* Check that MDT is not yet configured */
5632 LASSERT(!cfs_test_bit(MDT_FL_CFGLOG, &m->mdt_state));
5634 #ifdef HAVE_QUOTA_SUPPORT
5636 if (md->md_lu_dev.ld_obd->obd_recovering == 0 &&
5637 likely(md->md_lu_dev.ld_obd->obd_stopping == 0))
5638 next->md_ops->mdo_quota.mqo_recovery(env, next);
5642 CERROR("invalid event\n");
5649 static int mdt_obd_notify(struct obd_device *obd,
5650 struct obd_device *watched,
5651 enum obd_notify_event ev, void *data)
5653 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
5654 #ifdef HAVE_QUOTA_SUPPORT
5655 struct md_device *next = mdt->mdt_child;
5660 case OBD_NOTIFY_CONFIG:
5661 mdt_allow_cli(mdt, (unsigned long)data);
5663 #ifdef HAVE_QUOTA_SUPPORT
5664 /* quota_type has been processed, we can now handle
5665 * incoming quota requests */
5666 next->md_ops->mdo_quota.mqo_notify(NULL, next);
5670 CDEBUG(D_INFO, "Unhandled notification %#x\n", ev);
5675 static int mdt_rpc_fid2path(struct mdt_thread_info *info, void *key,
5676 void *val, int vallen)
5678 struct mdt_device *mdt = mdt_dev(info->mti_exp->exp_obd->obd_lu_dev);
5679 struct getinfo_fid2path *fpout, *fpin;
5682 fpin = key + cfs_size_round(sizeof(KEY_FID2PATH));
5685 if (ptlrpc_req_need_swab(info->mti_pill->rc_req))
5686 lustre_swab_fid2path(fpin);
5688 memcpy(fpout, fpin, sizeof(*fpin));
5689 if (fpout->gf_pathlen != vallen - sizeof(*fpin))
5692 rc = mdt_fid2path(info->mti_env, mdt, fpout);
5696 static int mdt_fid2path(const struct lu_env *env, struct mdt_device *mdt,
5697 struct getinfo_fid2path *fp)
5699 struct mdt_object *obj;
5703 CDEBUG(D_IOCTL, "path get "DFID" from "LPU64" #%d\n",
5704 PFID(&fp->gf_fid), fp->gf_recno, fp->gf_linkno);
5706 if (!fid_is_sane(&fp->gf_fid))
5709 obj = mdt_object_find(env, mdt, &fp->gf_fid);
5710 if (obj == NULL || IS_ERR(obj)) {
5711 CDEBUG(D_IOCTL, "no object "DFID": %ld\n", PFID(&fp->gf_fid),
5716 rc = lu_object_exists(&obj->mot_obj.mo_lu);
5722 mdt_object_put(env, obj);
5723 CDEBUG(D_IOCTL, "nonlocal object "DFID": %d\n",
5724 PFID(&fp->gf_fid), rc);
5728 rc = mo_path(env, md_object_next(&obj->mot_obj), fp->gf_path,
5729 fp->gf_pathlen, &fp->gf_recno, &fp->gf_linkno);
5730 mdt_object_put(env, obj);
5735 static int mdt_get_info(struct mdt_thread_info *info)
5737 struct ptlrpc_request *req = mdt_info_req(info);
5745 key = req_capsule_client_get(info->mti_pill, &RMF_GETINFO_KEY);
5747 CDEBUG(D_IOCTL, "No GETINFO key");
5750 keylen = req_capsule_get_size(info->mti_pill, &RMF_GETINFO_KEY,
5753 vallen = req_capsule_client_get(info->mti_pill, &RMF_GETINFO_VALLEN);
5754 if (vallen == NULL) {
5755 CDEBUG(D_IOCTL, "Unable to get RMF_GETINFO_VALLEN buffer");
5759 req_capsule_set_size(info->mti_pill, &RMF_GETINFO_VAL, RCL_SERVER,
5761 rc = req_capsule_server_pack(info->mti_pill);
5762 valout = req_capsule_server_get(info->mti_pill, &RMF_GETINFO_VAL);
5763 if (valout == NULL) {
5764 CDEBUG(D_IOCTL, "Unable to get get-info RPC out buffer");
5768 if (KEY_IS(KEY_FID2PATH))
5769 rc = mdt_rpc_fid2path(info, key, valout, *vallen);
5773 lustre_msg_set_status(req->rq_repmsg, rc);
5778 /* Pass the ioc down */
5779 static int mdt_ioc_child(struct lu_env *env, struct mdt_device *mdt,
5780 unsigned int cmd, int len, void *data)
5782 struct lu_context ioctl_session;
5783 struct md_device *next = mdt->mdt_child;
5787 rc = lu_context_init(&ioctl_session, LCT_SESSION);
5790 ioctl_session.lc_thread = (struct ptlrpc_thread *)cfs_current();
5791 lu_context_enter(&ioctl_session);
5792 env->le_ses = &ioctl_session;
5794 LASSERT(next->md_ops->mdo_iocontrol);
5795 rc = next->md_ops->mdo_iocontrol(env, next, cmd, len, data);
5797 lu_context_exit(&ioctl_session);
5798 lu_context_fini(&ioctl_session);
5802 static int mdt_ioc_version_get(struct mdt_thread_info *mti, void *karg)
5804 struct obd_ioctl_data *data = karg;
5805 struct lu_fid *fid = (struct lu_fid *)data->ioc_inlbuf1;
5807 struct mdt_object *obj;
5808 struct mdt_lock_handle *lh;
5812 CDEBUG(D_IOCTL, "getting version for "DFID"\n", PFID(fid));
5813 if (!fid_is_sane(fid))
5816 lh = &mti->mti_lh[MDT_LH_PARENT];
5817 mdt_lock_reg_init(lh, LCK_CR);
5819 obj = mdt_object_find_lock(mti, fid, lh, MDS_INODELOCK_UPDATE);
5821 RETURN(PTR_ERR(obj));
5823 rc = mdt_object_exists(obj);
5827 * before calling version get the correct MDS should be
5828 * fid, this is error to find remote object here
5830 CERROR("nonlocal object "DFID"\n", PFID(fid));
5831 } else if (rc == 0) {
5832 *(__u64 *)data->ioc_inlbuf2 = ENOENT_VERSION;
5835 version = dt_version_get(mti->mti_env, mdt_obj2dt(obj));
5836 *(__u64 *)data->ioc_inlbuf2 = version;
5839 mdt_object_unlock_put(mti, obj, lh, 1);
5843 /* ioctls on obd dev */
5844 static int mdt_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
5845 void *karg, void *uarg)
5848 struct obd_device *obd = exp->exp_obd;
5849 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
5850 struct dt_device *dt = mdt->mdt_bottom;
5854 CDEBUG(D_IOCTL, "handling ioctl cmd %#x\n", cmd);
5855 rc = lu_env_init(&env, LCT_MD_THREAD);
5861 rc = mdt_device_sync(&env, mdt);
5863 case OBD_IOC_SET_READONLY:
5864 rc = dt->dd_ops->dt_ro(&env, dt);
5866 case OBD_IOC_ABORT_RECOVERY:
5867 CERROR("Aborting recovery for device %s\n", obd->obd_name);
5868 target_stop_recovery_thread(obd);
5871 case OBD_IOC_CHANGELOG_REG:
5872 case OBD_IOC_CHANGELOG_DEREG:
5873 case OBD_IOC_CHANGELOG_CLEAR:
5874 rc = mdt_ioc_child(&env, mdt, cmd, len, karg);
5876 case OBD_IOC_START_LFSCK:
5877 case OBD_IOC_STOP_LFSCK: {
5878 struct md_device *next = mdt->mdt_child;
5879 struct obd_ioctl_data *data = karg;
5881 if (unlikely(data == NULL)) {
5886 rc = next->md_ops->mdo_iocontrol(&env, next, cmd,
5891 case OBD_IOC_GET_OBJ_VERSION: {
5892 struct mdt_thread_info *mti;
5893 mti = lu_context_key_get(&env.le_ctx, &mdt_thread_key);
5894 memset(mti, 0, sizeof *mti);
5895 mti->mti_env = &env;
5899 rc = mdt_ioc_version_get(mti, karg);
5903 CERROR("Not supported cmd = %d for device %s\n",
5904 cmd, obd->obd_name);
5912 int mdt_postrecov(const struct lu_env *env, struct mdt_device *mdt)
5914 struct lu_device *ld = md2lu_dev(mdt->mdt_child);
5915 #ifdef HAVE_QUOTA_SUPPORT
5916 struct obd_device *obd = mdt2obd_dev(mdt);
5917 struct md_device *next = mdt->mdt_child;
5922 rc = ld->ld_ops->ldo_recovery_complete(env, ld);
5923 #ifdef HAVE_QUOTA_SUPPORT
5924 if (likely(obd->obd_stopping == 0))
5925 next->md_ops->mdo_quota.mqo_recovery(env, next);
5930 int mdt_obd_postrecov(struct obd_device *obd)
5935 rc = lu_env_init(&env, LCT_MD_THREAD);
5938 rc = mdt_postrecov(&env, mdt_dev(obd->obd_lu_dev));
5944 * Send a copytool req to a client
5945 * Note this sends a request RPC from a server (MDT) to a client (MDC),
5946 * backwards of normal comms.
5948 int mdt_hsm_copytool_send(struct obd_export *exp)
5951 struct hsm_action_list *hal;
5952 struct hsm_action_item *hai;
5956 CWARN("%s: writing to mdc at %s\n", exp->exp_obd->obd_name,
5957 libcfs_nid2str(exp->exp_connection->c_peer.nid));
5959 len = sizeof(*lh) + sizeof(*hal) + MTI_NAME_MAXLEN +
5960 /* for mockup below */ 2 * cfs_size_round(sizeof(*hai));
5965 lh->kuc_magic = KUC_MAGIC;
5966 lh->kuc_transport = KUC_TRANSPORT_HSM;
5967 lh->kuc_msgtype = HMT_ACTION_LIST;
5968 lh->kuc_msglen = len;
5970 hal = (struct hsm_action_list *)(lh + 1);
5971 hal->hal_version = HAL_VERSION;
5972 hal->hal_archive_num = 1;
5973 obd_uuid2fsname(hal->hal_fsname, exp->exp_obd->obd_name,
5976 /* mock up an action list */
5978 hai = hai_zero(hal);
5979 hai->hai_action = HSMA_ARCHIVE;
5980 hai->hai_fid.f_oid = 0xA00A;
5981 hai->hai_len = sizeof(*hai);
5982 hai = hai_next(hai);
5983 hai->hai_action = HSMA_RESTORE;
5984 hai->hai_fid.f_oid = 0xB00B;
5985 hai->hai_len = sizeof(*hai);
5987 /* Uses the ldlm reverse import; this rpc will be seen by
5988 the ldlm_callback_handler */
5989 rc = do_set_info_async(exp->exp_imp_reverse,
5990 LDLM_SET_INFO, LUSTRE_OBD_VERSION,
5991 sizeof(KEY_HSM_COPYTOOL_SEND),
5992 KEY_HSM_COPYTOOL_SEND,
6000 static struct obd_ops mdt_obd_device_ops = {
6001 .o_owner = THIS_MODULE,
6002 .o_set_info_async = mdt_obd_set_info_async,
6003 .o_connect = mdt_obd_connect,
6004 .o_reconnect = mdt_obd_reconnect,
6005 .o_disconnect = mdt_obd_disconnect,
6006 .o_init_export = mdt_init_export,
6007 .o_destroy_export = mdt_destroy_export,
6008 .o_iocontrol = mdt_iocontrol,
6009 .o_postrecov = mdt_obd_postrecov,
6010 .o_notify = mdt_obd_notify
6013 static struct lu_device* mdt_device_fini(const struct lu_env *env,
6014 struct lu_device *d)
6016 struct mdt_device *m = mdt_dev(d);
6023 static struct lu_device *mdt_device_free(const struct lu_env *env,
6024 struct lu_device *d)
6026 struct mdt_device *m = mdt_dev(d);
6029 md_device_fini(&m->mdt_md_dev);
6034 static struct lu_device *mdt_device_alloc(const struct lu_env *env,
6035 struct lu_device_type *t,
6036 struct lustre_cfg *cfg)
6038 struct lu_device *l;
6039 struct mdt_device *m;
6045 l = &m->mdt_md_dev.md_lu_dev;
6046 rc = mdt_init0(env, m, t, cfg);
6048 mdt_device_free(env, l);
6052 md_upcall_init(&m->mdt_md_dev, mdt_upcall);
6054 l = ERR_PTR(-ENOMEM);
6058 /* context key constructor/destructor: mdt_key_init, mdt_key_fini */
6059 LU_KEY_INIT_FINI(mdt, struct mdt_thread_info);
6061 /* context key: mdt_thread_key */
6062 LU_CONTEXT_KEY_DEFINE(mdt, LCT_MD_THREAD);
6064 struct md_ucred *mdt_ucred(const struct mdt_thread_info *info)
6066 return md_ucred(info->mti_env);
6070 * Enable/disable COS (Commit On Sharing).
6072 * Set/Clear the COS flag in mdt options.
6074 * \param mdt mdt device
6075 * \param val 0 disables COS, other values enable COS
6077 void mdt_enable_cos(struct mdt_device *mdt, int val)
6082 mdt->mdt_opts.mo_cos = !!val;
6083 rc = lu_env_init(&env, LCT_LOCAL);
6084 if (unlikely(rc != 0)) {
6085 CWARN("lu_env initialization failed with rc = %d,"
6086 "cannot sync\n", rc);
6089 mdt_device_sync(&env, mdt);
6094 * Check COS (Commit On Sharing) status.
6096 * Return COS flag status.
6098 * \param mdt mdt device
6100 int mdt_cos_is_enabled(struct mdt_device *mdt)
6102 return mdt->mdt_opts.mo_cos != 0;
6105 /* type constructor/destructor: mdt_type_init, mdt_type_fini */
6106 LU_TYPE_INIT_FINI(mdt, &mdt_thread_key);
6108 static struct lu_device_type_operations mdt_device_type_ops = {
6109 .ldto_init = mdt_type_init,
6110 .ldto_fini = mdt_type_fini,
6112 .ldto_start = mdt_type_start,
6113 .ldto_stop = mdt_type_stop,
6115 .ldto_device_alloc = mdt_device_alloc,
6116 .ldto_device_free = mdt_device_free,
6117 .ldto_device_fini = mdt_device_fini
6120 static struct lu_device_type mdt_device_type = {
6121 .ldt_tags = LU_DEVICE_MD,
6122 .ldt_name = LUSTRE_MDT_NAME,
6123 .ldt_ops = &mdt_device_type_ops,
6124 .ldt_ctx_tags = LCT_MD_THREAD
6127 static int __init mdt_mod_init(void)
6129 struct lprocfs_static_vars lvars;
6132 rc = lu_kmem_init(mdt_caches);
6136 if (mdt_num_threads != 0 && mds_num_threads == 0) {
6137 LCONSOLE_INFO("mdt_num_threads module parameter is deprecated,"
6138 "use mds_num_threads instead or unset both for"
6139 "dynamic thread startup\n");
6140 mds_num_threads = mdt_num_threads;
6143 lprocfs_mdt_init_vars(&lvars);
6144 rc = class_register_type(&mdt_obd_device_ops, NULL,
6145 lvars.module_vars, LUSTRE_MDT_NAME,
6149 lu_kmem_fini(mdt_caches);
6153 static void __exit mdt_mod_exit(void)
6155 class_unregister_type(LUSTRE_MDT_NAME);
6156 lu_kmem_fini(mdt_caches);
6160 #define DEF_HNDL(prefix, base, suffix, flags, opc, fn, fmt) \
6161 [prefix ## _ ## opc - prefix ## _ ## base] = { \
6163 .mh_fail_id = OBD_FAIL_ ## prefix ## _ ## opc ## suffix, \
6164 .mh_opc = prefix ## _ ## opc, \
6165 .mh_flags = flags, \
6170 #define DEF_MDT_HNDL(flags, name, fn, fmt) \
6171 DEF_HNDL(MDS, GETATTR, _NET, flags, name, fn, fmt)
6173 #define DEF_SEQ_HNDL(flags, name, fn, fmt) \
6174 DEF_HNDL(SEQ, QUERY, _NET, flags, name, fn, fmt)
6176 #define DEF_FLD_HNDL(flags, name, fn, fmt) \
6177 DEF_HNDL(FLD, QUERY, _NET, flags, name, fn, fmt)
6179 * Request with a format known in advance
6181 #define DEF_MDT_HNDL_F(flags, name, fn) \
6182 DEF_HNDL(MDS, GETATTR, _NET, flags, name, fn, &RQF_MDS_ ## name)
6184 #define DEF_SEQ_HNDL_F(flags, name, fn) \
6185 DEF_HNDL(SEQ, QUERY, _NET, flags, name, fn, &RQF_SEQ_ ## name)
6187 #define DEF_FLD_HNDL_F(flags, name, fn) \
6188 DEF_HNDL(FLD, QUERY, _NET, flags, name, fn, &RQF_FLD_ ## name)
6190 * Request with a format we do not yet know
6192 #define DEF_MDT_HNDL_0(flags, name, fn) \
6193 DEF_HNDL(MDS, GETATTR, _NET, flags, name, fn, NULL)
6195 static struct mdt_handler mdt_mds_ops[] = {
6196 DEF_MDT_HNDL_F(0, CONNECT, mdt_connect),
6197 DEF_MDT_HNDL_F(0, DISCONNECT, mdt_disconnect),
6198 DEF_MDT_HNDL (0, SET_INFO, mdt_set_info,
6200 DEF_MDT_HNDL_F(0, GET_INFO, mdt_get_info),
6201 DEF_MDT_HNDL_F(0 |HABEO_REFERO, GETSTATUS, mdt_getstatus),
6202 DEF_MDT_HNDL_F(HABEO_CORPUS, GETATTR, mdt_getattr),
6203 DEF_MDT_HNDL_F(HABEO_CORPUS|HABEO_REFERO, GETATTR_NAME, mdt_getattr_name),
6204 DEF_MDT_HNDL_F(HABEO_CORPUS, GETXATTR, mdt_getxattr),
6205 DEF_MDT_HNDL_F(0 |HABEO_REFERO, STATFS, mdt_statfs),
6206 DEF_MDT_HNDL_F(0 |MUTABOR, REINT, mdt_reint),
6207 DEF_MDT_HNDL_F(HABEO_CORPUS, CLOSE, mdt_close),
6208 DEF_MDT_HNDL_F(HABEO_CORPUS, DONE_WRITING, mdt_done_writing),
6209 DEF_MDT_HNDL_F(0 |HABEO_REFERO, PIN, mdt_pin),
6210 DEF_MDT_HNDL_0(0, SYNC, mdt_sync),
6211 DEF_MDT_HNDL_F(HABEO_CORPUS|HABEO_REFERO, IS_SUBDIR, mdt_is_subdir),
6212 #ifdef HAVE_QUOTA_SUPPORT
6213 DEF_MDT_HNDL_F(0, QUOTACHECK, mdt_quotacheck_handle),
6214 DEF_MDT_HNDL_F(0, QUOTACTL, mdt_quotactl_handle)
6218 #define DEF_OBD_HNDL(flags, name, fn) \
6219 DEF_HNDL(OBD, PING, _NET, flags, name, fn, NULL)
6222 static struct mdt_handler mdt_obd_ops[] = {
6223 DEF_OBD_HNDL(0, PING, mdt_obd_ping),
6224 DEF_OBD_HNDL(0, LOG_CANCEL, mdt_obd_log_cancel),
6225 DEF_OBD_HNDL(0, QC_CALLBACK, mdt_obd_qc_callback),
6226 DEF_OBD_HNDL(0, IDX_READ, mdt_obd_idx_read)
6229 #define DEF_DLM_HNDL_0(flags, name, fn) \
6230 DEF_HNDL(LDLM, ENQUEUE, , flags, name, fn, NULL)
6231 #define DEF_DLM_HNDL_F(flags, name, fn) \
6232 DEF_HNDL(LDLM, ENQUEUE, , flags, name, fn, &RQF_LDLM_ ## name)
6234 static struct mdt_handler mdt_dlm_ops[] = {
6235 DEF_DLM_HNDL_F(HABEO_CLAVIS, ENQUEUE, mdt_enqueue),
6236 DEF_DLM_HNDL_0(HABEO_CLAVIS, CONVERT, mdt_convert),
6237 DEF_DLM_HNDL_0(0, BL_CALLBACK, mdt_bl_callback),
6238 DEF_DLM_HNDL_0(0, CP_CALLBACK, mdt_cp_callback)
6241 #define DEF_LLOG_HNDL(flags, name, fn) \
6242 DEF_HNDL(LLOG, ORIGIN_HANDLE_CREATE, _NET, flags, name, fn, NULL)
6244 static struct mdt_handler mdt_llog_ops[] = {
6245 DEF_LLOG_HNDL(0, ORIGIN_HANDLE_CREATE, mdt_llog_create),
6246 DEF_LLOG_HNDL(0, ORIGIN_HANDLE_NEXT_BLOCK, mdt_llog_next_block),
6247 DEF_LLOG_HNDL(0, ORIGIN_HANDLE_READ_HEADER, mdt_llog_read_header),
6248 DEF_LLOG_HNDL(0, ORIGIN_HANDLE_WRITE_REC, NULL),
6249 DEF_LLOG_HNDL(0, ORIGIN_HANDLE_CLOSE, NULL),
6250 DEF_LLOG_HNDL(0, ORIGIN_CONNECT, NULL),
6251 DEF_LLOG_HNDL(0, CATINFO, NULL),
6252 DEF_LLOG_HNDL(0, ORIGIN_HANDLE_PREV_BLOCK, mdt_llog_prev_block),
6253 DEF_LLOG_HNDL(0, ORIGIN_HANDLE_DESTROY, mdt_llog_destroy),
6256 #define DEF_SEC_CTX_HNDL(name, fn) \
6257 DEF_HNDL(SEC_CTX, INIT, _NET, 0, name, fn, NULL)
6259 static struct mdt_handler mdt_sec_ctx_ops[] = {
6260 DEF_SEC_CTX_HNDL(INIT, mdt_sec_ctx_handle),
6261 DEF_SEC_CTX_HNDL(INIT_CONT, mdt_sec_ctx_handle),
6262 DEF_SEC_CTX_HNDL(FINI, mdt_sec_ctx_handle)
6265 static struct mdt_opc_slice mdt_regular_handlers[] = {
6267 .mos_opc_start = MDS_GETATTR,
6268 .mos_opc_end = MDS_LAST_OPC,
6269 .mos_hs = mdt_mds_ops
6272 .mos_opc_start = OBD_PING,
6273 .mos_opc_end = OBD_LAST_OPC,
6274 .mos_hs = mdt_obd_ops
6277 .mos_opc_start = LDLM_ENQUEUE,
6278 .mos_opc_end = LDLM_LAST_OPC,
6279 .mos_hs = mdt_dlm_ops
6282 .mos_opc_start = LLOG_ORIGIN_HANDLE_CREATE,
6283 .mos_opc_end = LLOG_LAST_OPC,
6284 .mos_hs = mdt_llog_ops
6287 .mos_opc_start = SEC_CTX_INIT,
6288 .mos_opc_end = SEC_LAST_OPC,
6289 .mos_hs = mdt_sec_ctx_ops
6296 static struct mdt_handler mdt_readpage_ops[] = {
6297 DEF_MDT_HNDL_F(0, CONNECT, mdt_connect),
6298 DEF_MDT_HNDL_F(HABEO_CORPUS|HABEO_REFERO, READPAGE, mdt_readpage),
6299 #ifdef HAVE_SPLIT_SUPPORT
6300 DEF_MDT_HNDL_F(HABEO_CORPUS|HABEO_REFERO, WRITEPAGE, mdt_writepage),
6304 * XXX: this is ugly and should be fixed one day, see mdc_close() for
6305 * detailed comments. --umka
6307 DEF_MDT_HNDL_F(HABEO_CORPUS, CLOSE, mdt_close),
6308 DEF_MDT_HNDL_F(HABEO_CORPUS, DONE_WRITING, mdt_done_writing),
6311 static struct mdt_opc_slice mdt_readpage_handlers[] = {
6313 .mos_opc_start = MDS_GETATTR,
6314 .mos_opc_end = MDS_LAST_OPC,
6315 .mos_hs = mdt_readpage_ops
6318 .mos_opc_start = OBD_FIRST_OPC,
6319 .mos_opc_end = OBD_LAST_OPC,
6320 .mos_hs = mdt_obd_ops
6327 static struct mdt_handler mdt_xmds_ops[] = {
6328 DEF_MDT_HNDL_F(0, CONNECT, mdt_connect),
6329 DEF_MDT_HNDL_F(HABEO_CORPUS , GETATTR, mdt_getattr),
6330 DEF_MDT_HNDL_F(0 | MUTABOR , REINT, mdt_reint),
6331 DEF_MDT_HNDL_F(HABEO_CORPUS|HABEO_REFERO, IS_SUBDIR, mdt_is_subdir),
6334 static struct mdt_opc_slice mdt_xmds_handlers[] = {
6336 .mos_opc_start = MDS_GETATTR,
6337 .mos_opc_end = MDS_LAST_OPC,
6338 .mos_hs = mdt_xmds_ops
6341 .mos_opc_start = OBD_PING,
6342 .mos_opc_end = OBD_LAST_OPC,
6343 .mos_hs = mdt_obd_ops
6346 .mos_opc_start = SEC_CTX_INIT,
6347 .mos_opc_end = SEC_LAST_OPC,
6348 .mos_hs = mdt_sec_ctx_ops
6355 static struct mdt_handler mdt_seq_ops[] = {
6356 DEF_SEQ_HNDL_F(0, QUERY, (int (*)(struct mdt_thread_info *))seq_query)
6359 static struct mdt_opc_slice mdt_seq_handlers[] = {
6361 .mos_opc_start = SEQ_QUERY,
6362 .mos_opc_end = SEQ_LAST_OPC,
6363 .mos_hs = mdt_seq_ops
6370 static struct mdt_handler mdt_fld_ops[] = {
6371 DEF_FLD_HNDL_F(0, QUERY, (int (*)(struct mdt_thread_info *))fld_query)
6374 static struct mdt_opc_slice mdt_fld_handlers[] = {
6376 .mos_opc_start = FLD_QUERY,
6377 .mos_opc_end = FLD_LAST_OPC,
6378 .mos_hs = mdt_fld_ops
6385 MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");
6386 MODULE_DESCRIPTION("Lustre Meta-data Target ("LUSTRE_MDT_NAME")");
6387 MODULE_LICENSE("GPL");
6389 cfs_module(mdt, "0.2.0", mdt_mod_init, mdt_mod_exit);