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);
1962 static int mdt_obd_log_cancel(struct mdt_thread_info *info)
1964 return err_serious(-EOPNOTSUPP);
1967 static int mdt_obd_qc_callback(struct mdt_thread_info *info)
1969 return err_serious(-EOPNOTSUPP);
1977 /** clone llog ctxt from child (mdd)
1978 * This allows remote llog (replicator) access.
1979 * We can either pass all llog RPCs (eg mdt_llog_create) on to child where the
1980 * context was originally set up, or we can handle them directly.
1981 * I choose the latter, but that means I need any llog
1982 * contexts set up by child to be accessable by the mdt. So we clone the
1983 * context into our context list here.
1985 static int mdt_llog_ctxt_clone(const struct lu_env *env, struct mdt_device *mdt,
1988 struct md_device *next = mdt->mdt_child;
1989 struct llog_ctxt *ctxt;
1992 if (!llog_ctxt_null(mdt2obd_dev(mdt), idx))
1995 rc = next->md_ops->mdo_llog_ctxt_get(env, next, idx, (void **)&ctxt);
1996 if (rc || ctxt == NULL) {
1997 CERROR("Can't get mdd ctxt %d\n", rc);
2001 rc = llog_group_set_ctxt(&mdt2obd_dev(mdt)->obd_olg, ctxt, idx);
2003 CERROR("Can't set mdt ctxt %d\n", rc);
2008 static int mdt_llog_ctxt_unclone(const struct lu_env *env,
2009 struct mdt_device *mdt, int idx)
2011 struct llog_ctxt *ctxt;
2013 ctxt = llog_get_context(mdt2obd_dev(mdt), idx);
2016 /* Put once for the get we just did, and once for the clone */
2017 llog_ctxt_put(ctxt);
2018 llog_ctxt_put(ctxt);
2022 static int mdt_llog_create(struct mdt_thread_info *info)
2026 req_capsule_set(info->mti_pill, &RQF_LLOG_ORIGIN_HANDLE_CREATE);
2027 rc = llog_origin_handle_open(mdt_info_req(info));
2028 return (rc < 0 ? err_serious(rc) : rc);
2031 static int mdt_llog_destroy(struct mdt_thread_info *info)
2035 req_capsule_set(info->mti_pill, &RQF_LLOG_ORIGIN_HANDLE_DESTROY);
2036 rc = llog_origin_handle_destroy(mdt_info_req(info));
2037 return (rc < 0 ? err_serious(rc) : rc);
2040 static int mdt_llog_read_header(struct mdt_thread_info *info)
2044 req_capsule_set(info->mti_pill, &RQF_LLOG_ORIGIN_HANDLE_READ_HEADER);
2045 rc = llog_origin_handle_read_header(mdt_info_req(info));
2046 return (rc < 0 ? err_serious(rc) : rc);
2049 static int mdt_llog_next_block(struct mdt_thread_info *info)
2053 req_capsule_set(info->mti_pill, &RQF_LLOG_ORIGIN_HANDLE_NEXT_BLOCK);
2054 rc = llog_origin_handle_next_block(mdt_info_req(info));
2055 return (rc < 0 ? err_serious(rc) : rc);
2058 static int mdt_llog_prev_block(struct mdt_thread_info *info)
2062 req_capsule_set(info->mti_pill, &RQF_LLOG_ORIGIN_HANDLE_PREV_BLOCK);
2063 rc = llog_origin_handle_prev_block(mdt_info_req(info));
2064 return (rc < 0 ? err_serious(rc) : rc);
2071 static struct ldlm_callback_suite cbs = {
2072 .lcs_completion = ldlm_server_completion_ast,
2073 .lcs_blocking = ldlm_server_blocking_ast,
2077 static int mdt_enqueue(struct mdt_thread_info *info)
2079 struct ptlrpc_request *req;
2083 * info->mti_dlm_req already contains swapped and (if necessary)
2084 * converted dlm request.
2086 LASSERT(info->mti_dlm_req != NULL);
2088 req = mdt_info_req(info);
2089 rc = ldlm_handle_enqueue0(info->mti_mdt->mdt_namespace,
2090 req, info->mti_dlm_req, &cbs);
2091 info->mti_fail_id = OBD_FAIL_LDLM_REPLY;
2092 return rc ? err_serious(rc) : req->rq_status;
2095 static int mdt_convert(struct mdt_thread_info *info)
2098 struct ptlrpc_request *req;
2100 LASSERT(info->mti_dlm_req);
2101 req = mdt_info_req(info);
2102 rc = ldlm_handle_convert0(req, info->mti_dlm_req);
2103 return rc ? err_serious(rc) : req->rq_status;
2106 static int mdt_bl_callback(struct mdt_thread_info *info)
2108 CERROR("bl callbacks should not happen on MDS\n");
2110 return err_serious(-EOPNOTSUPP);
2113 static int mdt_cp_callback(struct mdt_thread_info *info)
2115 CERROR("cp callbacks should not happen on MDS\n");
2117 return err_serious(-EOPNOTSUPP);
2121 * sec context handlers
2123 static int mdt_sec_ctx_handle(struct mdt_thread_info *info)
2127 rc = mdt_handle_idmap(info);
2130 struct ptlrpc_request *req = mdt_info_req(info);
2133 opc = lustre_msg_get_opc(req->rq_reqmsg);
2134 if (opc == SEC_CTX_INIT || opc == SEC_CTX_INIT_CONT)
2135 sptlrpc_svc_ctx_invalidate(req);
2138 CFS_FAIL_TIMEOUT(OBD_FAIL_SEC_CTX_HDL_PAUSE, cfs_fail_val);
2143 static struct mdt_object *mdt_obj(struct lu_object *o)
2145 LASSERT(lu_device_is_mdt(o->lo_dev));
2146 return container_of0(o, struct mdt_object, mot_obj.mo_lu);
2149 struct mdt_object *mdt_object_new(const struct lu_env *env,
2150 struct mdt_device *d,
2151 const struct lu_fid *f)
2153 struct lu_object_conf conf = { .loc_flags = LOC_F_NEW };
2154 struct lu_object *o;
2155 struct mdt_object *m;
2158 CDEBUG(D_INFO, "Allocate object for "DFID"\n", PFID(f));
2159 o = lu_object_find(env, &d->mdt_md_dev.md_lu_dev, f, &conf);
2160 if (unlikely(IS_ERR(o)))
2161 m = (struct mdt_object *)o;
2167 struct mdt_object *mdt_object_find(const struct lu_env *env,
2168 struct mdt_device *d,
2169 const struct lu_fid *f)
2171 struct lu_object *o;
2172 struct mdt_object *m;
2175 CDEBUG(D_INFO, "Find object for "DFID"\n", PFID(f));
2176 o = lu_object_find(env, &d->mdt_md_dev.md_lu_dev, f, NULL);
2177 if (unlikely(IS_ERR(o)))
2178 m = (struct mdt_object *)o;
2185 * Asyncronous commit for mdt device.
2187 * Pass asynchonous commit call down the MDS stack.
2189 * \param env environment
2190 * \param mdt the mdt device
2192 static void mdt_device_commit_async(const struct lu_env *env,
2193 struct mdt_device *mdt)
2195 struct dt_device *dt = mdt->mdt_bottom;
2198 rc = dt->dd_ops->dt_commit_async(env, dt);
2199 if (unlikely(rc != 0))
2200 CWARN("async commit start failed with rc = %d", rc);
2204 * Mark the lock as "synchonous".
2206 * Mark the lock to deffer transaction commit to the unlock time.
2208 * \param lock the lock to mark as "synchonous"
2210 * \see mdt_is_lock_sync
2211 * \see mdt_save_lock
2213 static inline void mdt_set_lock_sync(struct ldlm_lock *lock)
2215 lock->l_ast_data = (void*)1;
2219 * Check whehter the lock "synchonous" or not.
2221 * \param lock the lock to check
2222 * \retval 1 the lock is "synchonous"
2223 * \retval 0 the lock isn't "synchronous"
2225 * \see mdt_set_lock_sync
2226 * \see mdt_save_lock
2228 static inline int mdt_is_lock_sync(struct ldlm_lock *lock)
2230 return lock->l_ast_data != NULL;
2234 * Blocking AST for mdt locks.
2236 * Starts transaction commit if in case of COS lock conflict or
2237 * deffers such a commit to the mdt_save_lock.
2239 * \param lock the lock which blocks a request or cancelling lock
2240 * \param desc unused
2241 * \param data unused
2242 * \param flag indicates whether this cancelling or blocking callback
2244 * \see ldlm_blocking_ast_nocheck
2246 int mdt_blocking_ast(struct ldlm_lock *lock, struct ldlm_lock_desc *desc,
2247 void *data, int flag)
2249 struct obd_device *obd = ldlm_lock_to_ns(lock)->ns_obd;
2250 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
2254 if (flag == LDLM_CB_CANCELING)
2256 lock_res_and_lock(lock);
2257 if (lock->l_blocking_ast != mdt_blocking_ast) {
2258 unlock_res_and_lock(lock);
2261 if (mdt_cos_is_enabled(mdt) &&
2262 lock->l_req_mode & (LCK_PW | LCK_EX) &&
2263 lock->l_blocking_lock != NULL &&
2264 lock->l_client_cookie != lock->l_blocking_lock->l_client_cookie) {
2265 mdt_set_lock_sync(lock);
2267 rc = ldlm_blocking_ast_nocheck(lock);
2269 /* There is no lock conflict if l_blocking_lock == NULL,
2270 * it indicates a blocking ast sent from ldlm_lock_decref_internal
2271 * when the last reference to a local lock was released */
2272 if (lock->l_req_mode == LCK_COS && lock->l_blocking_lock != NULL) {
2275 rc = lu_env_init(&env, LCT_LOCAL);
2276 if (unlikely(rc != 0))
2277 CWARN("lu_env initialization failed with rc = %d,"
2278 "cannot start asynchronous commit\n", rc);
2280 mdt_device_commit_async(&env, mdt);
2286 int mdt_object_lock(struct mdt_thread_info *info, struct mdt_object *o,
2287 struct mdt_lock_handle *lh, __u64 ibits, int locality)
2289 struct ldlm_namespace *ns = info->mti_mdt->mdt_namespace;
2290 ldlm_policy_data_t *policy = &info->mti_policy;
2291 struct ldlm_res_id *res_id = &info->mti_res_id;
2295 LASSERT(!lustre_handle_is_used(&lh->mlh_reg_lh));
2296 LASSERT(!lustre_handle_is_used(&lh->mlh_pdo_lh));
2297 LASSERT(lh->mlh_reg_mode != LCK_MINMODE);
2298 LASSERT(lh->mlh_type != MDT_NUL_LOCK);
2300 if (mdt_object_exists(o) < 0) {
2301 if (locality == MDT_CROSS_LOCK) {
2302 /* cross-ref object fix */
2303 ibits &= ~MDS_INODELOCK_UPDATE;
2304 ibits |= MDS_INODELOCK_LOOKUP;
2306 LASSERT(!(ibits & MDS_INODELOCK_UPDATE));
2307 LASSERT(ibits & MDS_INODELOCK_LOOKUP);
2309 /* No PDO lock on remote object */
2310 LASSERT(lh->mlh_type != MDT_PDO_LOCK);
2313 if (lh->mlh_type == MDT_PDO_LOCK) {
2314 /* check for exists after object is locked */
2315 if (mdt_object_exists(o) == 0) {
2316 /* Non-existent object shouldn't have PDO lock */
2319 /* Non-dir object shouldn't have PDO lock */
2320 if (!S_ISDIR(lu_object_attr(&o->mot_obj.mo_lu)))
2325 memset(policy, 0, sizeof(*policy));
2326 fid_build_reg_res_name(mdt_object_fid(o), res_id);
2329 * Take PDO lock on whole directory and build correct @res_id for lock
2330 * on part of directory.
2332 if (lh->mlh_pdo_hash != 0) {
2333 LASSERT(lh->mlh_type == MDT_PDO_LOCK);
2334 mdt_lock_pdo_mode(info, o, lh);
2335 if (lh->mlh_pdo_mode != LCK_NL) {
2337 * Do not use LDLM_FL_LOCAL_ONLY for parallel lock, it
2338 * is never going to be sent to client and we do not
2339 * want it slowed down due to possible cancels.
2341 policy->l_inodebits.bits = MDS_INODELOCK_UPDATE;
2342 rc = mdt_fid_lock(ns, &lh->mlh_pdo_lh, lh->mlh_pdo_mode,
2343 policy, res_id, LDLM_FL_ATOMIC_CB,
2344 &info->mti_exp->exp_handle.h_cookie);
2350 * Finish res_id initializing by name hash marking part of
2351 * directory which is taking modification.
2353 res_id->name[LUSTRE_RES_ID_HSH_OFF] = lh->mlh_pdo_hash;
2356 policy->l_inodebits.bits = ibits;
2359 * Use LDLM_FL_LOCAL_ONLY for this lock. We do not know yet if it is
2360 * going to be sent to client. If it is - mdt_intent_policy() path will
2361 * fix it up and turn FL_LOCAL flag off.
2363 rc = mdt_fid_lock(ns, &lh->mlh_reg_lh, lh->mlh_reg_mode, policy,
2364 res_id, LDLM_FL_LOCAL_ONLY | LDLM_FL_ATOMIC_CB,
2365 &info->mti_exp->exp_handle.h_cookie);
2367 mdt_object_unlock(info, o, lh, 1);
2368 else if (unlikely(OBD_FAIL_PRECHECK(OBD_FAIL_MDS_PDO_LOCK)) &&
2369 lh->mlh_pdo_hash != 0 &&
2370 (lh->mlh_reg_mode == LCK_PW || lh->mlh_reg_mode == LCK_EX)) {
2371 OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_PDO_LOCK, 15);
2378 * Save a lock within request object.
2380 * Keep the lock referenced until whether client ACK or transaction
2381 * commit happens or release the lock immediately depending on input
2382 * parameters. If COS is ON, a write lock is converted to COS lock
2385 * \param info thead info object
2386 * \param h lock handle
2387 * \param mode lock mode
2388 * \param decref force immediate lock releasing
2391 void mdt_save_lock(struct mdt_thread_info *info, struct lustre_handle *h,
2392 ldlm_mode_t mode, int decref)
2396 if (lustre_handle_is_used(h)) {
2397 if (decref || !info->mti_has_trans ||
2398 !(mode & (LCK_PW | LCK_EX))){
2399 mdt_fid_unlock(h, mode);
2401 struct mdt_device *mdt = info->mti_mdt;
2402 struct ldlm_lock *lock = ldlm_handle2lock(h);
2403 struct ptlrpc_request *req = mdt_info_req(info);
2406 LASSERTF(lock != NULL, "no lock for cookie "LPX64"\n",
2408 CDEBUG(D_HA, "request = %p reply state = %p"
2409 " transno = "LPD64"\n",
2410 req, req->rq_reply_state, req->rq_transno);
2411 if (mdt_cos_is_enabled(mdt)) {
2413 ldlm_lock_downgrade(lock, LCK_COS);
2416 ptlrpc_save_lock(req, h, mode, no_ack);
2417 if (mdt_is_lock_sync(lock)) {
2418 CDEBUG(D_HA, "found sync-lock,"
2419 " async commit started\n");
2420 mdt_device_commit_async(info->mti_env,
2423 LDLM_LOCK_PUT(lock);
2432 * Unlock mdt object.
2434 * Immeditely release the regular lock and the PDO lock or save the
2435 * lock in reqeuest and keep them referenced until client ACK or
2436 * transaction commit.
2438 * \param info thread info object
2439 * \param o mdt object
2440 * \param lh mdt lock handle referencing regular and PDO locks
2441 * \param decref force immediate lock releasing
2443 void mdt_object_unlock(struct mdt_thread_info *info, struct mdt_object *o,
2444 struct mdt_lock_handle *lh, int decref)
2448 mdt_save_lock(info, &lh->mlh_pdo_lh, lh->mlh_pdo_mode, decref);
2449 mdt_save_lock(info, &lh->mlh_reg_lh, lh->mlh_reg_mode, decref);
2454 struct mdt_object *mdt_object_find_lock(struct mdt_thread_info *info,
2455 const struct lu_fid *f,
2456 struct mdt_lock_handle *lh,
2459 struct mdt_object *o;
2461 o = mdt_object_find(info->mti_env, info->mti_mdt, f);
2465 rc = mdt_object_lock(info, o, lh, ibits,
2468 mdt_object_put(info->mti_env, o);
2475 void mdt_object_unlock_put(struct mdt_thread_info * info,
2476 struct mdt_object * o,
2477 struct mdt_lock_handle *lh,
2480 mdt_object_unlock(info, o, lh, decref);
2481 mdt_object_put(info->mti_env, o);
2484 static struct mdt_handler *mdt_handler_find(__u32 opc,
2485 struct mdt_opc_slice *supported)
2487 struct mdt_opc_slice *s;
2488 struct mdt_handler *h;
2491 for (s = supported; s->mos_hs != NULL; s++) {
2492 if (s->mos_opc_start <= opc && opc < s->mos_opc_end) {
2493 h = s->mos_hs + (opc - s->mos_opc_start);
2494 if (likely(h->mh_opc != 0))
2495 LASSERTF(h->mh_opc == opc,
2496 "opcode mismatch %d != %d\n",
2499 h = NULL; /* unsupported opc */
2506 static int mdt_lock_resname_compat(struct mdt_device *m,
2507 struct ldlm_request *req)
2509 /* XXX something... later. */
2513 static int mdt_lock_reply_compat(struct mdt_device *m, struct ldlm_reply *rep)
2515 /* XXX something... later. */
2520 * Generic code handling requests that have struct mdt_body passed in:
2522 * - extract mdt_body from request and save it in @info, if present;
2524 * - create lu_object, corresponding to the fid in mdt_body, and save it in
2527 * - if HABEO_CORPUS flag is set for this request type check whether object
2528 * actually exists on storage (lu_object_exists()).
2531 static int mdt_body_unpack(struct mdt_thread_info *info, __u32 flags)
2533 const struct mdt_body *body;
2534 struct mdt_object *obj;
2535 const struct lu_env *env;
2536 struct req_capsule *pill;
2540 env = info->mti_env;
2541 pill = info->mti_pill;
2543 body = info->mti_body = req_capsule_client_get(pill, &RMF_MDT_BODY);
2547 if (!(body->valid & OBD_MD_FLID))
2550 if (!fid_is_sane(&body->fid1)) {
2551 CERROR("Invalid fid: "DFID"\n", PFID(&body->fid1));
2556 * Do not get size or any capa fields before we check that request
2557 * contains capa actually. There are some requests which do not, for
2558 * instance MDS_IS_SUBDIR.
2560 if (req_capsule_has_field(pill, &RMF_CAPA1, RCL_CLIENT) &&
2561 req_capsule_get_size(pill, &RMF_CAPA1, RCL_CLIENT))
2562 mdt_set_capainfo(info, 0, &body->fid1,
2563 req_capsule_client_get(pill, &RMF_CAPA1));
2565 obj = mdt_object_find(env, info->mti_mdt, &body->fid1);
2567 if ((flags & HABEO_CORPUS) &&
2568 !mdt_object_exists(obj)) {
2569 mdt_object_put(env, obj);
2570 /* for capability renew ENOENT will be handled in
2572 if (body->valid & OBD_MD_FLOSSCAPA)
2577 info->mti_object = obj;
2586 static int mdt_unpack_req_pack_rep(struct mdt_thread_info *info, __u32 flags)
2588 struct req_capsule *pill = info->mti_pill;
2592 if (req_capsule_has_field(pill, &RMF_MDT_BODY, RCL_CLIENT))
2593 rc = mdt_body_unpack(info, flags);
2597 if (rc == 0 && (flags & HABEO_REFERO)) {
2599 if (req_capsule_has_field(pill, &RMF_MDT_MD, RCL_SERVER))
2600 req_capsule_set_size(pill, &RMF_MDT_MD, RCL_SERVER,
2601 info->mti_body->eadatasize);
2602 if (req_capsule_has_field(pill, &RMF_LOGCOOKIES, RCL_SERVER))
2603 req_capsule_set_size(pill, &RMF_LOGCOOKIES, RCL_SERVER,
2604 info->mti_mdt->mdt_max_cookiesize);
2606 rc = req_capsule_server_pack(pill);
2611 static int mdt_init_capa_ctxt(const struct lu_env *env, struct mdt_device *m)
2613 struct md_device *next = m->mdt_child;
2615 return next->md_ops->mdo_init_capa_ctxt(env, next,
2616 m->mdt_opts.mo_mds_capa,
2617 m->mdt_capa_timeout,
2623 * Invoke handler for this request opc. Also do necessary preprocessing
2624 * (according to handler ->mh_flags), and post-processing (setting of
2625 * ->last_{xid,committed}).
2627 static int mdt_req_handle(struct mdt_thread_info *info,
2628 struct mdt_handler *h, struct ptlrpc_request *req)
2630 int rc, serious = 0;
2635 LASSERT(h->mh_act != NULL);
2636 LASSERT(h->mh_opc == lustre_msg_get_opc(req->rq_reqmsg));
2637 LASSERT(current->journal_info == NULL);
2640 * Checking for various OBD_FAIL_$PREF_$OPC_NET codes. _Do_ not try
2641 * to put same checks into handlers like mdt_close(), mdt_reint(),
2642 * etc., without talking to mdt authors first. Checking same thing
2643 * there again is useless and returning 0 error without packing reply
2644 * is buggy! Handlers either pack reply or return error.
2646 * We return 0 here and do not send any reply in order to emulate
2647 * network failure. Do not send any reply in case any of NET related
2648 * fail_id has occured.
2650 if (OBD_FAIL_CHECK_ORSET(h->mh_fail_id, OBD_FAIL_ONCE))
2654 flags = h->mh_flags;
2655 LASSERT(ergo(flags & (HABEO_CORPUS|HABEO_REFERO), h->mh_fmt != NULL));
2657 if (h->mh_fmt != NULL) {
2658 req_capsule_set(info->mti_pill, h->mh_fmt);
2659 rc = mdt_unpack_req_pack_rep(info, flags);
2662 if (rc == 0 && flags & MUTABOR &&
2663 req->rq_export->exp_connect_flags & OBD_CONNECT_RDONLY)
2664 /* should it be rq_status? */
2667 if (rc == 0 && flags & HABEO_CLAVIS) {
2668 struct ldlm_request *dlm_req;
2670 LASSERT(h->mh_fmt != NULL);
2672 dlm_req = req_capsule_client_get(info->mti_pill, &RMF_DLM_REQ);
2673 if (dlm_req != NULL) {
2674 if (unlikely(dlm_req->lock_desc.l_resource.lr_type ==
2676 dlm_req->lock_desc.l_policy_data.\
2677 l_inodebits.bits == 0)) {
2679 * Lock without inodebits makes no sense and
2680 * will oops later in ldlm. If client miss to
2681 * set such bits, do not trigger ASSERTION.
2683 * For liblustre flock case, it maybe zero.
2687 if (info->mti_mdt->mdt_opts.mo_compat_resname)
2688 rc = mdt_lock_resname_compat(
2691 info->mti_dlm_req = dlm_req;
2698 /* capability setting changed via /proc, needs reinitialize ctxt */
2699 if (info->mti_mdt && info->mti_mdt->mdt_capa_conf) {
2700 mdt_init_capa_ctxt(info->mti_env, info->mti_mdt);
2701 info->mti_mdt->mdt_capa_conf = 0;
2704 if (likely(rc == 0)) {
2706 * Process request, there can be two types of rc:
2707 * 1) errors with msg unpack/pack, other failures outside the
2708 * operation itself. This is counted as serious errors;
2709 * 2) errors during fs operation, should be placed in rq_status
2712 rc = h->mh_act(info);
2714 !req->rq_no_reply && req->rq_reply_state == NULL) {
2715 DEBUG_REQ(D_ERROR, req, "MDT \"handler\" %s did not "
2716 "pack reply and returned 0 error\n",
2720 serious = is_serious(rc);
2721 rc = clear_serious(rc);
2725 req->rq_status = rc;
2728 * ELDLM_* codes which > 0 should be in rq_status only as well as
2729 * all non-serious errors.
2731 if (rc > 0 || !serious)
2734 LASSERT(current->journal_info == NULL);
2736 if (rc == 0 && (flags & HABEO_CLAVIS) &&
2737 info->mti_mdt->mdt_opts.mo_compat_resname) {
2738 struct ldlm_reply *dlmrep;
2740 dlmrep = req_capsule_server_get(info->mti_pill, &RMF_DLM_REP);
2742 rc = mdt_lock_reply_compat(info->mti_mdt, dlmrep);
2745 /* If we're DISCONNECTing, the mdt_export_data is already freed */
2746 if (likely(rc == 0 && req->rq_export && h->mh_opc != MDS_DISCONNECT))
2747 target_committed_to_req(req);
2749 if (unlikely(req_is_replay(req) &&
2750 lustre_msg_get_transno(req->rq_reqmsg) == 0)) {
2751 DEBUG_REQ(D_ERROR, req, "transno is 0 during REPLAY");
2755 target_send_reply(req, rc, info->mti_fail_id);
2759 void mdt_lock_handle_init(struct mdt_lock_handle *lh)
2761 lh->mlh_type = MDT_NUL_LOCK;
2762 lh->mlh_reg_lh.cookie = 0ull;
2763 lh->mlh_reg_mode = LCK_MINMODE;
2764 lh->mlh_pdo_lh.cookie = 0ull;
2765 lh->mlh_pdo_mode = LCK_MINMODE;
2768 void mdt_lock_handle_fini(struct mdt_lock_handle *lh)
2770 LASSERT(!lustre_handle_is_used(&lh->mlh_reg_lh));
2771 LASSERT(!lustre_handle_is_used(&lh->mlh_pdo_lh));
2775 * Initialize fields of struct mdt_thread_info. Other fields are left in
2776 * uninitialized state, because it's too expensive to zero out whole
2777 * mdt_thread_info (> 1K) on each request arrival.
2779 static void mdt_thread_info_init(struct ptlrpc_request *req,
2780 struct mdt_thread_info *info)
2783 struct md_capainfo *ci;
2785 req_capsule_init(&req->rq_pill, req, RCL_SERVER);
2786 info->mti_pill = &req->rq_pill;
2789 for (i = 0; i < ARRAY_SIZE(info->mti_lh); i++)
2790 mdt_lock_handle_init(&info->mti_lh[i]);
2792 /* mdt device: it can be NULL while CONNECT */
2793 if (req->rq_export) {
2794 info->mti_mdt = mdt_dev(req->rq_export->exp_obd->obd_lu_dev);
2795 info->mti_exp = req->rq_export;
2797 info->mti_mdt = NULL;
2798 info->mti_env = req->rq_svc_thread->t_env;
2799 ci = md_capainfo(info->mti_env);
2800 memset(ci, 0, sizeof *ci);
2801 if (req->rq_export) {
2802 if (exp_connect_rmtclient(req->rq_export))
2803 ci->mc_auth = LC_ID_CONVERT;
2804 else if (req->rq_export->exp_connect_flags &
2805 OBD_CONNECT_MDS_CAPA)
2806 ci->mc_auth = LC_ID_PLAIN;
2808 ci->mc_auth = LC_ID_NONE;
2811 info->mti_fail_id = OBD_FAIL_MDS_ALL_REPLY_NET;
2812 info->mti_transno = lustre_msg_get_transno(req->rq_reqmsg);
2813 info->mti_mos = NULL;
2815 memset(&info->mti_attr, 0, sizeof(info->mti_attr));
2816 info->mti_body = NULL;
2817 info->mti_object = NULL;
2818 info->mti_dlm_req = NULL;
2819 info->mti_has_trans = 0;
2820 info->mti_no_need_trans = 0;
2821 info->mti_cross_ref = 0;
2822 info->mti_opdata = 0;
2824 /* To not check for split by default. */
2825 info->mti_spec.sp_ck_split = 0;
2826 info->mti_spec.no_create = 0;
2829 static void mdt_thread_info_fini(struct mdt_thread_info *info)
2833 req_capsule_fini(info->mti_pill);
2834 if (info->mti_object != NULL) {
2836 * freeing an object may lead to OSD level transaction, do not
2837 * let it mess with MDT. bz19385.
2839 info->mti_no_need_trans = 1;
2840 mdt_object_put(info->mti_env, info->mti_object);
2841 info->mti_object = NULL;
2843 for (i = 0; i < ARRAY_SIZE(info->mti_lh); i++)
2844 mdt_lock_handle_fini(&info->mti_lh[i]);
2845 info->mti_env = NULL;
2848 static int mdt_filter_recovery_request(struct ptlrpc_request *req,
2849 struct obd_device *obd, int *process)
2851 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
2852 case MDS_CONNECT: /* This will never get here, but for completeness. */
2853 case OST_CONNECT: /* This will never get here, but for completeness. */
2854 case MDS_DISCONNECT:
2855 case OST_DISCONNECT:
2860 case MDS_DONE_WRITING:
2861 case MDS_SYNC: /* used in unmounting */
2867 *process = target_queue_recovery_request(req, obd);
2871 DEBUG_REQ(D_ERROR, req, "not permitted during recovery");
2878 * Handle recovery. Return:
2879 * +1: continue request processing;
2880 * -ve: abort immediately with the given error code;
2881 * 0: send reply with error code in req->rq_status;
2883 static int mdt_recovery(struct mdt_thread_info *info)
2885 struct ptlrpc_request *req = mdt_info_req(info);
2886 struct obd_device *obd;
2890 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
2893 case SEC_CTX_INIT_CONT:
2899 rc = mdt_handle_idmap(info);
2908 if (unlikely(!class_connected_export(req->rq_export))) {
2909 CERROR("operation %d on unconnected MDS from %s\n",
2910 lustre_msg_get_opc(req->rq_reqmsg),
2911 libcfs_id2str(req->rq_peer));
2912 /* FIXME: For CMD cleanup, when mds_B stop, the req from
2913 * mds_A will get -ENOTCONN(especially for ping req),
2914 * which will cause that mds_A deactive timeout, then when
2915 * mds_A cleanup, the cleanup process will be suspended since
2916 * deactive timeout is not zero.
2918 req->rq_status = -ENOTCONN;
2919 target_send_reply(req, -ENOTCONN, info->mti_fail_id);
2923 /* sanity check: if the xid matches, the request must be marked as a
2924 * resent or replayed */
2925 if (req_xid_is_last(req)) {
2926 if (!(lustre_msg_get_flags(req->rq_reqmsg) &
2927 (MSG_RESENT | MSG_REPLAY))) {
2928 DEBUG_REQ(D_WARNING, req, "rq_xid "LPU64" matches last_xid, "
2929 "expected REPLAY or RESENT flag (%x)", req->rq_xid,
2930 lustre_msg_get_flags(req->rq_reqmsg));
2932 req->rq_status = -ENOTCONN;
2937 /* else: note the opposite is not always true; a RESENT req after a
2938 * failover will usually not match the last_xid, since it was likely
2939 * never committed. A REPLAYed request will almost never match the
2940 * last xid, however it could for a committed, but still retained,
2943 obd = req->rq_export->exp_obd;
2945 /* Check for aborted recovery... */
2946 if (unlikely(obd->obd_recovering)) {
2949 DEBUG_REQ(D_INFO, req, "Got new replay");
2950 rc = mdt_filter_recovery_request(req, obd, &should_process);
2951 if (rc != 0 || !should_process)
2953 else if (should_process < 0) {
2954 req->rq_status = should_process;
2955 rc = ptlrpc_error(req);
2962 static int mdt_msg_check_version(struct lustre_msg *msg)
2966 switch (lustre_msg_get_opc(msg)) {
2968 case MDS_DISCONNECT:
2971 case SEC_CTX_INIT_CONT:
2973 rc = lustre_msg_check_version(msg, LUSTRE_OBD_VERSION);
2975 CERROR("bad opc %u version %08x, expecting %08x\n",
2976 lustre_msg_get_opc(msg),
2977 lustre_msg_get_version(msg),
2978 LUSTRE_OBD_VERSION);
2982 case MDS_GETATTR_NAME:
2989 case MDS_DONE_WRITING:
2996 case MDS_QUOTACHECK:
3002 rc = lustre_msg_check_version(msg, LUSTRE_MDS_VERSION);
3004 CERROR("bad opc %u version %08x, expecting %08x\n",
3005 lustre_msg_get_opc(msg),
3006 lustre_msg_get_version(msg),
3007 LUSTRE_MDS_VERSION);
3011 case LDLM_BL_CALLBACK:
3012 case LDLM_CP_CALLBACK:
3013 rc = lustre_msg_check_version(msg, LUSTRE_DLM_VERSION);
3015 CERROR("bad opc %u version %08x, expecting %08x\n",
3016 lustre_msg_get_opc(msg),
3017 lustre_msg_get_version(msg),
3018 LUSTRE_DLM_VERSION);
3020 case OBD_LOG_CANCEL:
3021 case LLOG_ORIGIN_HANDLE_CREATE:
3022 case LLOG_ORIGIN_HANDLE_NEXT_BLOCK:
3023 case LLOG_ORIGIN_HANDLE_READ_HEADER:
3024 case LLOG_ORIGIN_HANDLE_CLOSE:
3025 case LLOG_ORIGIN_HANDLE_DESTROY:
3026 case LLOG_ORIGIN_HANDLE_PREV_BLOCK:
3028 rc = lustre_msg_check_version(msg, LUSTRE_LOG_VERSION);
3030 CERROR("bad opc %u version %08x, expecting %08x\n",
3031 lustre_msg_get_opc(msg),
3032 lustre_msg_get_version(msg),
3033 LUSTRE_LOG_VERSION);
3036 CERROR("MDS unknown opcode %d\n", lustre_msg_get_opc(msg));
3042 static int mdt_handle0(struct ptlrpc_request *req,
3043 struct mdt_thread_info *info,
3044 struct mdt_opc_slice *supported)
3046 struct mdt_handler *h;
3047 struct lustre_msg *msg;
3052 if (OBD_FAIL_CHECK_ORSET(OBD_FAIL_MDS_ALL_REQUEST_NET, OBD_FAIL_ONCE))
3055 LASSERT(current->journal_info == NULL);
3057 msg = req->rq_reqmsg;
3058 rc = mdt_msg_check_version(msg);
3059 if (likely(rc == 0)) {
3060 rc = mdt_recovery(info);
3061 if (likely(rc == +1)) {
3062 h = mdt_handler_find(lustre_msg_get_opc(msg),
3064 if (likely(h != NULL)) {
3065 rc = mdt_req_handle(info, h, req);
3067 CERROR("The unsupported opc: 0x%x\n",
3068 lustre_msg_get_opc(msg) );
3069 req->rq_status = -ENOTSUPP;
3070 rc = ptlrpc_error(req);
3075 CERROR(LUSTRE_MDT_NAME" drops mal-formed request\n");
3080 * MDT handler function called by ptlrpc service thread when request comes.
3082 * XXX common "target" functionality should be factored into separate module
3083 * shared by mdt, ost and stand-alone services like fld.
3085 static int mdt_handle_common(struct ptlrpc_request *req,
3086 struct mdt_opc_slice *supported)
3089 struct mdt_thread_info *info;
3093 env = req->rq_svc_thread->t_env;
3094 LASSERT(env != NULL);
3095 LASSERT(env->le_ses != NULL);
3096 LASSERT(env->le_ctx.lc_thread == req->rq_svc_thread);
3097 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
3098 LASSERT(info != NULL);
3100 mdt_thread_info_init(req, info);
3102 rc = mdt_handle0(req, info, supported);
3104 mdt_thread_info_fini(info);
3109 * This is called from recovery code as handler of _all_ RPC types, FLD and SEQ
3112 int mdt_recovery_handle(struct ptlrpc_request *req)
3117 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
3119 rc = mdt_handle_common(req, mdt_fld_handlers);
3122 rc = mdt_handle_common(req, mdt_seq_handlers);
3125 rc = mdt_handle_common(req, mdt_regular_handlers);
3132 static int mdt_regular_handle(struct ptlrpc_request *req)
3134 return mdt_handle_common(req, mdt_regular_handlers);
3137 static int mdt_readpage_handle(struct ptlrpc_request *req)
3139 return mdt_handle_common(req, mdt_readpage_handlers);
3142 static int mdt_xmds_handle(struct ptlrpc_request *req)
3144 return mdt_handle_common(req, mdt_xmds_handlers);
3147 static int mdt_mdsc_handle(struct ptlrpc_request *req)
3149 return mdt_handle_common(req, mdt_seq_handlers);
3152 static int mdt_mdss_handle(struct ptlrpc_request *req)
3154 return mdt_handle_common(req, mdt_seq_handlers);
3157 static int mdt_dtss_handle(struct ptlrpc_request *req)
3159 return mdt_handle_common(req, mdt_seq_handlers);
3162 static int mdt_fld_handle(struct ptlrpc_request *req)
3164 return mdt_handle_common(req, mdt_fld_handlers);
3181 static int mdt_intent_getattr(enum mdt_it_code opcode,
3182 struct mdt_thread_info *info,
3183 struct ldlm_lock **,
3185 static int mdt_intent_reint(enum mdt_it_code opcode,
3186 struct mdt_thread_info *info,
3187 struct ldlm_lock **,
3190 static struct mdt_it_flavor {
3191 const struct req_format *it_fmt;
3193 int (*it_act)(enum mdt_it_code ,
3194 struct mdt_thread_info *,
3195 struct ldlm_lock **,
3198 } mdt_it_flavor[] = {
3200 .it_fmt = &RQF_LDLM_INTENT,
3201 /*.it_flags = HABEO_REFERO,*/
3203 .it_act = mdt_intent_reint,
3204 .it_reint = REINT_OPEN
3207 .it_fmt = &RQF_LDLM_INTENT,
3208 .it_flags = MUTABOR,
3209 .it_act = mdt_intent_reint,
3210 .it_reint = REINT_OPEN
3213 .it_fmt = &RQF_LDLM_INTENT,
3214 .it_flags = MUTABOR,
3215 .it_act = mdt_intent_reint,
3216 .it_reint = REINT_CREATE
3218 [MDT_IT_GETATTR] = {
3219 .it_fmt = &RQF_LDLM_INTENT_GETATTR,
3220 .it_flags = HABEO_REFERO,
3221 .it_act = mdt_intent_getattr
3223 [MDT_IT_READDIR] = {
3229 .it_fmt = &RQF_LDLM_INTENT_GETATTR,
3230 .it_flags = HABEO_REFERO,
3231 .it_act = mdt_intent_getattr
3234 .it_fmt = &RQF_LDLM_INTENT_UNLINK,
3235 .it_flags = MUTABOR,
3237 .it_reint = REINT_UNLINK
3241 .it_flags = MUTABOR,
3244 [MDT_IT_GETXATTR] = {
3250 .it_fmt = &RQF_LDLM_INTENT_GETATTR,
3251 .it_flags = HABEO_REFERO,
3252 .it_act = mdt_intent_getattr
3256 int mdt_intent_lock_replace(struct mdt_thread_info *info,
3257 struct ldlm_lock **lockp,
3258 struct ldlm_lock *new_lock,
3259 struct mdt_lock_handle *lh,
3262 struct ptlrpc_request *req = mdt_info_req(info);
3263 struct ldlm_lock *lock = *lockp;
3266 * Get new lock only for cases when possible resent did not find any
3269 if (new_lock == NULL)
3270 new_lock = ldlm_handle2lock_long(&lh->mlh_reg_lh, 0);
3272 if (new_lock == NULL && (flags & LDLM_FL_INTENT_ONLY)) {
3273 lh->mlh_reg_lh.cookie = 0;
3277 LASSERTF(new_lock != NULL,
3278 "lockh "LPX64"\n", lh->mlh_reg_lh.cookie);
3281 * If we've already given this lock to a client once, then we should
3282 * have no readers or writers. Otherwise, we should have one reader
3283 * _or_ writer ref (which will be zeroed below) before returning the
3286 if (new_lock->l_export == req->rq_export) {
3287 LASSERT(new_lock->l_readers + new_lock->l_writers == 0);
3289 LASSERT(new_lock->l_export == NULL);
3290 LASSERT(new_lock->l_readers + new_lock->l_writers == 1);
3295 if (new_lock->l_export == req->rq_export) {
3297 * Already gave this to the client, which means that we
3298 * reconstructed a reply.
3300 LASSERT(lustre_msg_get_flags(req->rq_reqmsg) &
3302 lh->mlh_reg_lh.cookie = 0;
3303 RETURN(ELDLM_LOCK_REPLACED);
3307 * Fixup the lock to be given to the client.
3309 lock_res_and_lock(new_lock);
3310 /* Zero new_lock->l_readers and new_lock->l_writers without triggering
3311 * possible blocking AST. */
3312 while (new_lock->l_readers > 0) {
3313 lu_ref_del(&new_lock->l_reference, "reader", new_lock);
3314 lu_ref_del(&new_lock->l_reference, "user", new_lock);
3315 new_lock->l_readers--;
3317 while (new_lock->l_writers > 0) {
3318 lu_ref_del(&new_lock->l_reference, "writer", new_lock);
3319 lu_ref_del(&new_lock->l_reference, "user", new_lock);
3320 new_lock->l_writers--;
3323 new_lock->l_export = class_export_lock_get(req->rq_export, new_lock);
3324 new_lock->l_blocking_ast = lock->l_blocking_ast;
3325 new_lock->l_completion_ast = lock->l_completion_ast;
3326 new_lock->l_remote_handle = lock->l_remote_handle;
3327 new_lock->l_flags &= ~LDLM_FL_LOCAL;
3329 unlock_res_and_lock(new_lock);
3331 cfs_hash_add(new_lock->l_export->exp_lock_hash,
3332 &new_lock->l_remote_handle,
3333 &new_lock->l_exp_hash);
3335 LDLM_LOCK_RELEASE(new_lock);
3336 lh->mlh_reg_lh.cookie = 0;
3338 RETURN(ELDLM_LOCK_REPLACED);
3341 static void mdt_intent_fixup_resent(struct mdt_thread_info *info,
3342 struct ldlm_lock *new_lock,
3343 struct ldlm_lock **old_lock,
3344 struct mdt_lock_handle *lh)
3346 struct ptlrpc_request *req = mdt_info_req(info);
3347 struct obd_export *exp = req->rq_export;
3348 struct lustre_handle remote_hdl;
3349 struct ldlm_request *dlmreq;
3350 struct ldlm_lock *lock;
3352 if (!(lustre_msg_get_flags(req->rq_reqmsg) & MSG_RESENT))
3355 dlmreq = req_capsule_client_get(info->mti_pill, &RMF_DLM_REQ);
3356 remote_hdl = dlmreq->lock_handle[0];
3358 lock = cfs_hash_lookup(exp->exp_lock_hash, &remote_hdl);
3360 if (lock != new_lock) {
3361 lh->mlh_reg_lh.cookie = lock->l_handle.h_cookie;
3362 lh->mlh_reg_mode = lock->l_granted_mode;
3364 LDLM_DEBUG(lock, "Restoring lock cookie");
3365 DEBUG_REQ(D_DLMTRACE, req,
3366 "restoring lock cookie "LPX64,
3367 lh->mlh_reg_lh.cookie);
3369 *old_lock = LDLM_LOCK_GET(lock);
3370 cfs_hash_put(exp->exp_lock_hash, &lock->l_exp_hash);
3374 cfs_hash_put(exp->exp_lock_hash, &lock->l_exp_hash);
3378 * If the xid matches, then we know this is a resent request, and allow
3379 * it. (It's probably an OPEN, for which we don't send a lock.
3381 if (req_xid_is_last(req))
3385 * This remote handle isn't enqueued, so we never received or processed
3386 * this request. Clear MSG_RESENT, because it can be handled like any
3387 * normal request now.
3389 lustre_msg_clear_flags(req->rq_reqmsg, MSG_RESENT);
3391 DEBUG_REQ(D_DLMTRACE, req, "no existing lock with rhandle "LPX64,
3395 static int mdt_intent_getattr(enum mdt_it_code opcode,
3396 struct mdt_thread_info *info,
3397 struct ldlm_lock **lockp,
3400 struct mdt_lock_handle *lhc = &info->mti_lh[MDT_LH_RMT];
3401 struct ldlm_lock *new_lock = NULL;
3403 struct ldlm_reply *ldlm_rep;
3404 struct ptlrpc_request *req;
3405 struct mdt_body *reqbody;
3406 struct mdt_body *repbody;
3410 reqbody = req_capsule_client_get(info->mti_pill, &RMF_MDT_BODY);
3413 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
3416 info->mti_spec.sp_ck_split = !!(reqbody->valid & OBD_MD_FLCKSPLIT);
3417 info->mti_cross_ref = !!(reqbody->valid & OBD_MD_FLCROSSREF);
3418 repbody->eadatasize = 0;
3419 repbody->aclsize = 0;
3423 child_bits = MDS_INODELOCK_LOOKUP;
3425 case MDT_IT_GETATTR:
3426 child_bits = MDS_INODELOCK_LOOKUP | MDS_INODELOCK_UPDATE;
3428 case MDT_IT_LAYOUT: {
3429 static int printed = 0;
3432 CERROR("layout lock not supported by this version\n");
3435 GOTO(out_shrink, rc = -EINVAL);
3439 CERROR("Unsupported intent (%d)\n", opcode);
3440 GOTO(out_shrink, rc = -EINVAL);
3443 rc = mdt_init_ucred(info, reqbody);
3445 GOTO(out_shrink, rc);
3447 req = info->mti_pill->rc_req;
3448 ldlm_rep = req_capsule_server_get(info->mti_pill, &RMF_DLM_REP);
3449 mdt_set_disposition(info, ldlm_rep, DISP_IT_EXECD);
3451 /* Get lock from request for possible resent case. */
3452 mdt_intent_fixup_resent(info, *lockp, &new_lock, lhc);
3454 ldlm_rep->lock_policy_res2 =
3455 mdt_getattr_name_lock(info, lhc, child_bits, ldlm_rep);
3457 if (mdt_get_disposition(ldlm_rep, DISP_LOOKUP_NEG))
3458 ldlm_rep->lock_policy_res2 = 0;
3459 if (!mdt_get_disposition(ldlm_rep, DISP_LOOKUP_POS) ||
3460 ldlm_rep->lock_policy_res2) {
3461 lhc->mlh_reg_lh.cookie = 0ull;
3462 GOTO(out_ucred, rc = ELDLM_LOCK_ABORTED);
3465 rc = mdt_intent_lock_replace(info, lockp, new_lock, lhc, flags);
3468 mdt_exit_ucred(info);
3470 mdt_client_compatibility(info);
3471 rc2 = mdt_fix_reply(info);
3477 static int mdt_intent_reint(enum mdt_it_code opcode,
3478 struct mdt_thread_info *info,
3479 struct ldlm_lock **lockp,
3482 struct mdt_lock_handle *lhc = &info->mti_lh[MDT_LH_RMT];
3483 struct ldlm_reply *rep = NULL;
3487 static const struct req_format *intent_fmts[REINT_MAX] = {
3488 [REINT_CREATE] = &RQF_LDLM_INTENT_CREATE,
3489 [REINT_OPEN] = &RQF_LDLM_INTENT_OPEN
3494 opc = mdt_reint_opcode(info, intent_fmts);
3498 if (mdt_it_flavor[opcode].it_reint != opc) {
3499 CERROR("Reint code %ld doesn't match intent: %d\n",
3501 RETURN(err_serious(-EPROTO));
3504 /* Get lock from request for possible resent case. */
3505 mdt_intent_fixup_resent(info, *lockp, NULL, lhc);
3507 rc = mdt_reint_internal(info, lhc, opc);
3509 /* Check whether the reply has been packed successfully. */
3510 if (mdt_info_req(info)->rq_repmsg != NULL)
3511 rep = req_capsule_server_get(info->mti_pill, &RMF_DLM_REP);
3513 RETURN(err_serious(-EFAULT));
3515 /* MDC expects this in any case */
3517 mdt_set_disposition(info, rep, DISP_LOOKUP_EXECD);
3519 /* Cross-ref case, the lock should be returned to the client */
3520 if (rc == -EREMOTE) {
3521 LASSERT(lustre_handle_is_used(&lhc->mlh_reg_lh));
3522 rep->lock_policy_res2 = 0;
3523 rc = mdt_intent_lock_replace(info, lockp, NULL, lhc, flags);
3526 rep->lock_policy_res2 = clear_serious(rc);
3528 if (rep->lock_policy_res2 == -ENOENT &&
3529 mdt_get_disposition(rep, DISP_LOOKUP_NEG))
3530 rep->lock_policy_res2 = 0;
3532 if (rc == -ENOTCONN || rc == -ENODEV ||
3533 rc == -EOVERFLOW) { /**< if VBR failure then return error */
3535 * If it is the disconnect error (ENODEV & ENOCONN), the error
3536 * will be returned by rq_status, and client at ptlrpc layer
3537 * will detect this, then disconnect, reconnect the import
3538 * immediately, instead of impacting the following the rpc.
3540 lhc->mlh_reg_lh.cookie = 0ull;
3544 * For other cases, the error will be returned by intent.
3545 * and client will retrieve the result from intent.
3548 * FIXME: when open lock is finished, that should be
3551 if (lustre_handle_is_used(&lhc->mlh_reg_lh)) {
3552 LASSERTF(rc == 0, "Error occurred but lock handle "
3553 "is still in use\n");
3554 rep->lock_policy_res2 = 0;
3555 rc = mdt_intent_lock_replace(info, lockp, NULL, lhc, flags);
3558 lhc->mlh_reg_lh.cookie = 0ull;
3559 RETURN(ELDLM_LOCK_ABORTED);
3564 static int mdt_intent_code(long itcode)
3572 case IT_OPEN|IT_CREAT:
3579 rc = MDT_IT_READDIR;
3582 rc = MDT_IT_GETATTR;
3594 rc = MDT_IT_GETXATTR;
3600 CERROR("Unknown intent opcode: %ld\n", itcode);
3607 static int mdt_intent_opc(long itopc, struct mdt_thread_info *info,
3608 struct ldlm_lock **lockp, int flags)
3610 struct req_capsule *pill;
3611 struct mdt_it_flavor *flv;
3616 opc = mdt_intent_code(itopc);
3620 pill = info->mti_pill;
3621 flv = &mdt_it_flavor[opc];
3623 if (flv->it_fmt != NULL)
3624 req_capsule_extend(pill, flv->it_fmt);
3626 rc = mdt_unpack_req_pack_rep(info, flv->it_flags);
3628 struct ptlrpc_request *req = mdt_info_req(info);
3629 if (flv->it_flags & MUTABOR &&
3630 req->rq_export->exp_connect_flags & OBD_CONNECT_RDONLY)
3633 if (rc == 0 && flv->it_act != NULL) {
3634 /* execute policy */
3635 rc = flv->it_act(opc, info, lockp, flags);
3642 static int mdt_intent_policy(struct ldlm_namespace *ns,
3643 struct ldlm_lock **lockp, void *req_cookie,
3644 ldlm_mode_t mode, int flags, void *data)
3646 struct mdt_thread_info *info;
3647 struct ptlrpc_request *req = req_cookie;
3648 struct ldlm_intent *it;
3649 struct req_capsule *pill;
3654 LASSERT(req != NULL);
3656 info = lu_context_key_get(&req->rq_svc_thread->t_env->le_ctx,
3658 LASSERT(info != NULL);
3659 pill = info->mti_pill;
3660 LASSERT(pill->rc_req == req);
3662 if (req->rq_reqmsg->lm_bufcount > DLM_INTENT_IT_OFF) {
3663 req_capsule_extend(pill, &RQF_LDLM_INTENT);
3664 it = req_capsule_client_get(pill, &RMF_LDLM_INTENT);
3666 rc = mdt_intent_opc(it->opc, info, lockp, flags);
3670 /* Lock without inodebits makes no sense and will oops
3671 * later in ldlm. Let's check it now to see if we have
3672 * ibits corrupted somewhere in mdt_intent_opc().
3673 * The case for client miss to set ibits has been
3674 * processed by others. */
3675 LASSERT(ergo(info->mti_dlm_req->lock_desc.l_resource.\
3676 lr_type == LDLM_IBITS,
3677 info->mti_dlm_req->lock_desc.\
3678 l_policy_data.l_inodebits.bits != 0));
3680 rc = err_serious(-EFAULT);
3682 /* No intent was provided */
3683 LASSERT(pill->rc_fmt == &RQF_LDLM_ENQUEUE);
3684 rc = req_capsule_server_pack(pill);
3686 rc = err_serious(rc);
3691 static int mdt_seq_fini(const struct lu_env *env,
3692 struct mdt_device *m)
3694 struct md_site *ms = mdt_md_site(m);
3698 if (ms->ms_server_seq) {
3699 seq_server_fini(ms->ms_server_seq, env);
3700 OBD_FREE_PTR(ms->ms_server_seq);
3701 ms->ms_server_seq = NULL;
3704 if (ms->ms_control_seq) {
3705 seq_server_fini(ms->ms_control_seq, env);
3706 OBD_FREE_PTR(ms->ms_control_seq);
3707 ms->ms_control_seq = NULL;
3710 if (ms->ms_client_seq) {
3711 seq_client_fini(ms->ms_client_seq);
3712 OBD_FREE_PTR(ms->ms_client_seq);
3713 ms->ms_client_seq = NULL;
3720 static int mdt_seq_init(const struct lu_env *env,
3722 struct mdt_device *m)
3729 ms = mdt_md_site(m);
3732 * This is sequence-controller node. Init seq-controller server on local
3735 if (ms->ms_node_id == 0) {
3736 LASSERT(ms->ms_control_seq == NULL);
3738 OBD_ALLOC_PTR(ms->ms_control_seq);
3739 if (ms->ms_control_seq == NULL)
3742 rc = seq_server_init(ms->ms_control_seq,
3743 m->mdt_bottom, uuid,
3744 LUSTRE_SEQ_CONTROLLER,
3749 GOTO(out_seq_fini, rc);
3751 OBD_ALLOC_PTR(ms->ms_client_seq);
3752 if (ms->ms_client_seq == NULL)
3753 GOTO(out_seq_fini, rc = -ENOMEM);
3755 OBD_ALLOC(prefix, MAX_OBD_NAME + 5);
3756 if (prefix == NULL) {
3757 OBD_FREE_PTR(ms->ms_client_seq);
3758 GOTO(out_seq_fini, rc = -ENOMEM);
3761 snprintf(prefix, MAX_OBD_NAME + 5, "ctl-%s",
3765 * Init seq-controller client after seq-controller server is
3766 * ready. Pass ms->ms_control_seq to it for direct talking.
3768 rc = seq_client_init(ms->ms_client_seq, NULL,
3769 LUSTRE_SEQ_METADATA, prefix,
3770 ms->ms_control_seq);
3771 OBD_FREE(prefix, MAX_OBD_NAME + 5);
3774 GOTO(out_seq_fini, rc);
3777 /* Init seq-server on local MDT */
3778 LASSERT(ms->ms_server_seq == NULL);
3780 OBD_ALLOC_PTR(ms->ms_server_seq);
3781 if (ms->ms_server_seq == NULL)
3782 GOTO(out_seq_fini, rc = -ENOMEM);
3784 rc = seq_server_init(ms->ms_server_seq,
3785 m->mdt_bottom, uuid,
3790 GOTO(out_seq_fini, rc = -ENOMEM);
3792 /* Assign seq-controller client to local seq-server. */
3793 if (ms->ms_node_id == 0) {
3794 LASSERT(ms->ms_client_seq != NULL);
3796 rc = seq_server_set_cli(ms->ms_server_seq,
3804 mdt_seq_fini(env, m);
3809 * Init client sequence manager which is used by local MDS to talk to sequence
3810 * controller on remote node.
3812 static int mdt_seq_init_cli(const struct lu_env *env,
3813 struct mdt_device *m,
3814 struct lustre_cfg *cfg)
3816 struct md_site *ms = mdt_md_site(m);
3817 struct obd_device *mdc;
3818 struct obd_uuid *uuidp, *mdcuuidp;
3819 char *uuid_str, *mdc_uuid_str;
3822 struct mdt_thread_info *info;
3823 char *p, *index_string = lustre_cfg_string(cfg, 2);
3826 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
3827 uuidp = &info->mti_u.uuid[0];
3828 mdcuuidp = &info->mti_u.uuid[1];
3830 LASSERT(index_string);
3832 index = simple_strtol(index_string, &p, 10);
3834 CERROR("Invalid index in lustre_cgf, offset 2\n");
3838 /* check if this is adding the first MDC and controller is not yet
3840 if (index != 0 || ms->ms_client_seq)
3843 uuid_str = lustre_cfg_string(cfg, 1);
3844 mdc_uuid_str = lustre_cfg_string(cfg, 4);
3845 obd_str2uuid(uuidp, uuid_str);
3846 obd_str2uuid(mdcuuidp, mdc_uuid_str);
3848 mdc = class_find_client_obd(uuidp, LUSTRE_MDC_NAME, mdcuuidp);
3850 CERROR("can't find controller MDC by uuid %s\n",
3853 } else if (!mdc->obd_set_up) {
3854 CERROR("target %s not set up\n", mdc->obd_name);
3857 LASSERT(ms->ms_control_exp);
3858 OBD_ALLOC_PTR(ms->ms_client_seq);
3859 if (ms->ms_client_seq != NULL) {
3862 OBD_ALLOC(prefix, MAX_OBD_NAME + 5);
3866 snprintf(prefix, MAX_OBD_NAME + 5, "ctl-%s",
3869 rc = seq_client_init(ms->ms_client_seq,
3871 LUSTRE_SEQ_METADATA,
3873 OBD_FREE(prefix, MAX_OBD_NAME + 5);
3880 LASSERT(ms->ms_server_seq != NULL);
3881 rc = seq_server_set_cli(ms->ms_server_seq, ms->ms_client_seq,
3888 static void mdt_seq_fini_cli(struct mdt_device *m)
3894 ms = mdt_md_site(m);
3897 if (ms->ms_server_seq)
3898 seq_server_set_cli(ms->ms_server_seq,
3901 if (ms->ms_control_exp) {
3902 class_export_put(ms->ms_control_exp);
3903 ms->ms_control_exp = NULL;
3912 static int mdt_fld_fini(const struct lu_env *env,
3913 struct mdt_device *m)
3915 struct md_site *ms = mdt_md_site(m);
3918 if (ms && ms->ms_server_fld) {
3919 fld_server_fini(ms->ms_server_fld, env);
3920 OBD_FREE_PTR(ms->ms_server_fld);
3921 ms->ms_server_fld = NULL;
3927 static int mdt_fld_init(const struct lu_env *env,
3929 struct mdt_device *m)
3935 ms = mdt_md_site(m);
3937 OBD_ALLOC_PTR(ms->ms_server_fld);
3938 if (ms->ms_server_fld == NULL)
3939 RETURN(rc = -ENOMEM);
3941 rc = fld_server_init(ms->ms_server_fld,
3942 m->mdt_bottom, uuid,
3943 env, ms->ms_node_id);
3945 OBD_FREE_PTR(ms->ms_server_fld);
3946 ms->ms_server_fld = NULL;
3953 /* device init/fini methods */
3954 static void mdt_stop_ptlrpc_service(struct mdt_device *m)
3957 if (m->mdt_regular_service != NULL) {
3958 ptlrpc_unregister_service(m->mdt_regular_service);
3959 m->mdt_regular_service = NULL;
3961 if (m->mdt_readpage_service != NULL) {
3962 ptlrpc_unregister_service(m->mdt_readpage_service);
3963 m->mdt_readpage_service = NULL;
3965 if (m->mdt_xmds_service != NULL) {
3966 ptlrpc_unregister_service(m->mdt_xmds_service);
3967 m->mdt_xmds_service = NULL;
3969 if (m->mdt_setattr_service != NULL) {
3970 ptlrpc_unregister_service(m->mdt_setattr_service);
3971 m->mdt_setattr_service = NULL;
3973 if (m->mdt_mdsc_service != NULL) {
3974 ptlrpc_unregister_service(m->mdt_mdsc_service);
3975 m->mdt_mdsc_service = NULL;
3977 if (m->mdt_mdss_service != NULL) {
3978 ptlrpc_unregister_service(m->mdt_mdss_service);
3979 m->mdt_mdss_service = NULL;
3981 if (m->mdt_dtss_service != NULL) {
3982 ptlrpc_unregister_service(m->mdt_dtss_service);
3983 m->mdt_dtss_service = NULL;
3985 if (m->mdt_fld_service != NULL) {
3986 ptlrpc_unregister_service(m->mdt_fld_service);
3987 m->mdt_fld_service = NULL;
3992 static int mdt_start_ptlrpc_service(struct mdt_device *m)
3994 static struct ptlrpc_service_conf conf;
3995 cfs_proc_dir_entry_t *procfs_entry;
3999 m->mdt_ldlm_client = &m->mdt_md_dev.md_lu_dev.ld_obd->obd_ldlm_client;
4000 ptlrpc_init_client(LDLM_CB_REQUEST_PORTAL, LDLM_CB_REPLY_PORTAL,
4001 "mdt_ldlm_client", m->mdt_ldlm_client);
4003 procfs_entry = m->mdt_md_dev.md_lu_dev.ld_obd->obd_proc_entry;
4005 conf = (typeof(conf)) {
4006 .psc_name = LUSTRE_MDT_NAME,
4007 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
4009 .bc_nbufs = MDS_NBUFS,
4010 .bc_buf_size = MDS_BUFSIZE,
4011 .bc_req_max_size = MDS_MAXREQSIZE,
4012 .bc_rep_max_size = MDS_MAXREPSIZE,
4013 .bc_req_portal = MDS_REQUEST_PORTAL,
4014 .bc_rep_portal = MDC_REPLY_PORTAL,
4017 * We'd like to have a mechanism to set this on a per-device
4018 * basis, but alas...
4021 .tc_thr_name = LUSTRE_MDT_NAME,
4022 .tc_thr_factor = MDT_THR_FACTOR,
4023 .tc_nthrs_init = MDT_NTHRS_INIT,
4024 .tc_nthrs_base = MDT_NTHRS_BASE,
4025 .tc_nthrs_max = MDT_NTHRS_MAX,
4026 .tc_nthrs_user = mds_num_threads,
4027 .tc_cpu_affinity = 1,
4028 .tc_ctx_tags = LCT_MD_THREAD,
4031 .cc_pattern = mds_num_cpts,
4034 .so_req_handler = mdt_regular_handle,
4035 .so_req_printer = target_print_req,
4036 .so_hpreq_handler = ptlrpc_hpreq_handler,
4039 m->mdt_regular_service = ptlrpc_register_service(&conf, procfs_entry);
4040 if (IS_ERR(m->mdt_regular_service)) {
4041 rc = PTR_ERR(m->mdt_regular_service);
4042 CERROR("failed to start regular mdt service: %d\n", rc);
4043 m->mdt_regular_service = NULL;
4049 * readpage service configuration. Parameters have to be adjusted,
4052 memset(&conf, 0, sizeof(conf));
4053 conf = (typeof(conf)) {
4054 .psc_name = LUSTRE_MDT_NAME "_readpage",
4055 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
4057 .bc_nbufs = MDS_NBUFS,
4058 .bc_buf_size = MDS_BUFSIZE,
4059 .bc_req_max_size = MDS_MAXREQSIZE,
4060 .bc_rep_max_size = MDS_MAXREPSIZE,
4061 .bc_req_portal = MDS_READPAGE_PORTAL,
4062 .bc_rep_portal = MDC_REPLY_PORTAL,
4065 .tc_thr_name = "mdt_rdpg",
4066 .tc_thr_factor = MDT_RDPG_THR_FACTOR,
4067 .tc_nthrs_init = MDT_RDPG_NTHRS_INIT,
4068 .tc_nthrs_base = MDT_RDPG_NTHRS_BASE,
4069 .tc_nthrs_max = MDT_RDPG_NTHRS_MAX,
4070 .tc_nthrs_user = mds_rdpg_num_threads,
4071 .tc_cpu_affinity = 1,
4072 .tc_ctx_tags = LCT_MD_THREAD,
4075 .cc_pattern = mds_rdpg_num_cpts,
4078 .so_req_handler = mdt_readpage_handle,
4079 .so_req_printer = target_print_req,
4080 .so_hpreq_handler = NULL,
4083 m->mdt_readpage_service = ptlrpc_register_service(&conf, procfs_entry);
4084 if (IS_ERR(m->mdt_readpage_service)) {
4085 rc = PTR_ERR(m->mdt_readpage_service);
4086 CERROR("failed to start readpage service: %d\n", rc);
4087 m->mdt_readpage_service = NULL;
4089 GOTO(err_mdt_svc, rc);
4093 * setattr service configuration.
4095 * XXX To keep the compatibility with old client(< 2.2), we need to
4096 * preserve this portal for a certain time, it should be removed
4097 * eventually. LU-617.
4099 memset(&conf, 0, sizeof(conf));
4100 conf = (typeof(conf)) {
4101 .psc_name = LUSTRE_MDT_NAME "_setattr",
4102 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
4104 .bc_nbufs = MDS_NBUFS,
4105 .bc_buf_size = MDS_BUFSIZE,
4106 .bc_req_max_size = MDS_MAXREQSIZE,
4107 .bc_rep_max_size = MDS_MAXREPSIZE,
4108 .bc_req_portal = MDS_SETATTR_PORTAL,
4109 .bc_rep_portal = MDC_REPLY_PORTAL,
4112 .tc_thr_name = "mdt_attr",
4113 .tc_thr_factor = MDT_SETA_THR_FACTOR,
4114 .tc_nthrs_init = MDT_SETA_NTHRS_INIT,
4115 .tc_nthrs_base = MDT_SETA_NTHRS_BASE,
4116 .tc_nthrs_max = MDT_SETA_NTHRS_MAX,
4117 .tc_nthrs_user = mds_attr_num_threads,
4118 .tc_cpu_affinity = 1,
4119 .tc_ctx_tags = LCT_MD_THREAD,
4122 .cc_pattern = mds_attr_num_cpts,
4125 .so_req_handler = mdt_regular_handle,
4126 .so_req_printer = target_print_req,
4127 .so_hpreq_handler = NULL,
4130 m->mdt_setattr_service = ptlrpc_register_service(&conf, procfs_entry);
4131 if (IS_ERR(m->mdt_setattr_service)) {
4132 rc = PTR_ERR(m->mdt_setattr_service);
4133 CERROR("failed to start setattr service: %d\n", rc);
4134 m->mdt_setattr_service = NULL;
4136 GOTO(err_mdt_svc, rc);
4140 * sequence controller service configuration
4142 memset(&conf, 0, sizeof(conf));
4143 conf = (typeof(conf)) {
4144 .psc_name = LUSTRE_MDT_NAME "_mdsc",
4145 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
4147 .bc_nbufs = MDS_NBUFS,
4148 .bc_buf_size = MDS_BUFSIZE,
4149 .bc_req_max_size = SEQ_MAXREQSIZE,
4150 .bc_rep_max_size = SEQ_MAXREPSIZE,
4151 .bc_req_portal = SEQ_CONTROLLER_PORTAL,
4152 .bc_rep_portal = MDC_REPLY_PORTAL,
4155 .tc_thr_name = "mdt_mdsc",
4156 .tc_nthrs_init = MDT_OTHR_NTHRS_INIT,
4157 .tc_nthrs_max = MDT_OTHR_NTHRS_MAX,
4158 .tc_ctx_tags = LCT_MD_THREAD,
4161 .so_req_handler = mdt_mdsc_handle,
4162 .so_req_printer = target_print_req,
4163 .so_hpreq_handler = NULL,
4166 m->mdt_mdsc_service = ptlrpc_register_service(&conf, procfs_entry);
4167 if (IS_ERR(m->mdt_mdsc_service)) {
4168 rc = PTR_ERR(m->mdt_mdsc_service);
4169 CERROR("failed to start seq controller service: %d\n", rc);
4170 m->mdt_mdsc_service = NULL;
4172 GOTO(err_mdt_svc, rc);
4176 * metadata sequence server service configuration
4178 memset(&conf, 0, sizeof(conf));
4179 conf = (typeof(conf)) {
4180 .psc_name = LUSTRE_MDT_NAME "_mdss",
4181 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
4183 .bc_nbufs = MDS_NBUFS,
4184 .bc_buf_size = MDS_BUFSIZE,
4185 .bc_req_max_size = SEQ_MAXREQSIZE,
4186 .bc_rep_max_size = SEQ_MAXREPSIZE,
4187 .bc_req_portal = SEQ_METADATA_PORTAL,
4188 .bc_rep_portal = MDC_REPLY_PORTAL,
4191 .tc_thr_name = "mdt_mdss",
4192 .tc_nthrs_init = MDT_OTHR_NTHRS_INIT,
4193 .tc_nthrs_max = MDT_OTHR_NTHRS_MAX,
4194 .tc_ctx_tags = LCT_MD_THREAD | LCT_DT_THREAD
4197 .so_req_handler = mdt_mdss_handle,
4198 .so_req_printer = target_print_req,
4199 .so_hpreq_handler = NULL,
4202 m->mdt_mdss_service = ptlrpc_register_service(&conf, procfs_entry);
4203 if (IS_ERR(m->mdt_mdss_service)) {
4204 rc = PTR_ERR(m->mdt_mdss_service);
4205 CERROR("failed to start metadata seq server service: %d\n", rc);
4206 m->mdt_mdss_service = NULL;
4208 GOTO(err_mdt_svc, rc);
4212 * Data sequence server service configuration. We want to have really
4213 * cluster-wide sequences space. This is why we start only one sequence
4214 * controller which manages space.
4216 memset(&conf, 0, sizeof(conf));
4217 conf = (typeof(conf)) {
4218 .psc_name = LUSTRE_MDT_NAME "_dtss",
4219 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
4221 .bc_nbufs = MDS_NBUFS,
4222 .bc_buf_size = MDS_BUFSIZE,
4223 .bc_req_max_size = SEQ_MAXREQSIZE,
4224 .bc_rep_max_size = SEQ_MAXREPSIZE,
4225 .bc_req_portal = SEQ_DATA_PORTAL,
4226 .bc_rep_portal = OSC_REPLY_PORTAL,
4229 .tc_thr_name = "mdt_dtss",
4230 .tc_nthrs_init = MDT_OTHR_NTHRS_INIT,
4231 .tc_nthrs_max = MDT_OTHR_NTHRS_MAX,
4232 .tc_ctx_tags = LCT_MD_THREAD | LCT_DT_THREAD
4235 .so_req_handler = mdt_dtss_handle,
4236 .so_req_printer = target_print_req,
4237 .so_hpreq_handler = NULL,
4240 m->mdt_dtss_service = ptlrpc_register_service(&conf, procfs_entry);
4241 if (IS_ERR(m->mdt_dtss_service)) {
4242 rc = PTR_ERR(m->mdt_dtss_service);
4243 CERROR("failed to start data seq server service: %d\n", rc);
4244 m->mdt_dtss_service = NULL;
4246 GOTO(err_mdt_svc, rc);
4249 /* FLD service start */
4250 memset(&conf, 0, sizeof(conf));
4251 conf = (typeof(conf)) {
4252 .psc_name = LUSTRE_MDT_NAME "_fld",
4253 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
4255 .bc_nbufs = MDS_NBUFS,
4256 .bc_buf_size = MDS_BUFSIZE,
4257 .bc_req_max_size = FLD_MAXREQSIZE,
4258 .bc_rep_max_size = FLD_MAXREPSIZE,
4259 .bc_req_portal = FLD_REQUEST_PORTAL,
4260 .bc_rep_portal = MDC_REPLY_PORTAL,
4263 .tc_thr_name = "mdt_fld",
4264 .tc_nthrs_init = MDT_OTHR_NTHRS_INIT,
4265 .tc_nthrs_max = MDT_OTHR_NTHRS_MAX,
4266 .tc_ctx_tags = LCT_DT_THREAD | LCT_MD_THREAD
4269 .so_req_handler = mdt_fld_handle,
4270 .so_req_printer = target_print_req,
4271 .so_hpreq_handler = NULL,
4274 m->mdt_fld_service = ptlrpc_register_service(&conf, procfs_entry);
4275 if (IS_ERR(m->mdt_fld_service)) {
4276 rc = PTR_ERR(m->mdt_fld_service);
4277 CERROR("failed to start fld service: %d\n", rc);
4278 m->mdt_fld_service = NULL;
4280 GOTO(err_mdt_svc, rc);
4284 * mds-mds service configuration. Separate portal is used to allow
4285 * mds-mds requests be not blocked during recovery.
4287 memset(&conf, 0, sizeof(conf));
4288 conf = (typeof(conf)) {
4289 .psc_name = LUSTRE_MDT_NAME "_mds",
4290 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
4292 .bc_nbufs = MDS_NBUFS,
4293 .bc_buf_size = MDS_BUFSIZE,
4294 .bc_req_max_size = MDS_MAXREQSIZE,
4295 .bc_rep_max_size = MDS_MAXREPSIZE,
4296 .bc_req_portal = MDS_MDS_PORTAL,
4297 .bc_rep_portal = MDC_REPLY_PORTAL,
4300 .tc_thr_name = "mdt_mds",
4301 .tc_nthrs_init = MDT_OTHR_NTHRS_INIT,
4302 .tc_nthrs_max = MDT_OTHR_NTHRS_MAX,
4303 .tc_ctx_tags = LCT_MD_THREAD,
4306 .so_req_handler = mdt_xmds_handle,
4307 .so_req_printer = target_print_req,
4308 .so_hpreq_handler = ptlrpc_hpreq_handler,
4311 m->mdt_xmds_service = ptlrpc_register_service(&conf, procfs_entry);
4312 if (IS_ERR(m->mdt_xmds_service)) {
4313 rc = PTR_ERR(m->mdt_xmds_service);
4314 CERROR("failed to start xmds service: %d\n", rc);
4315 m->mdt_xmds_service = NULL;
4317 GOTO(err_mdt_svc, rc);
4323 mdt_stop_ptlrpc_service(m);
4328 static void mdt_stack_fini(const struct lu_env *env,
4329 struct mdt_device *m, struct lu_device *top)
4331 struct obd_device *obd = mdt2obd_dev(m);
4332 struct lustre_cfg_bufs *bufs;
4333 struct lustre_cfg *lcfg;
4334 struct mdt_thread_info *info;
4338 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
4339 LASSERT(info != NULL);
4341 lu_dev_del_linkage(top->ld_site, top);
4343 bufs = &info->mti_u.bufs;
4344 /* process cleanup, pass mdt obd name to get obd umount flags */
4345 lustre_cfg_bufs_reset(bufs, obd->obd_name);
4350 lustre_cfg_bufs_set_string(bufs, 1, flags);
4351 lcfg = lustre_cfg_new(LCFG_CLEANUP, bufs);
4353 CERROR("Cannot alloc lcfg!\n");
4357 top->ld_ops->ldo_process_config(env, top, lcfg);
4358 lustre_cfg_free(lcfg);
4360 lu_stack_fini(env, top);
4361 m->mdt_child = NULL;
4362 m->mdt_bottom = NULL;
4364 obd_disconnect(m->mdt_bottom_exp);
4367 static struct lu_device *mdt_layer_setup(struct lu_env *env,
4368 const char *typename,
4369 struct lu_device *child,
4370 struct lustre_cfg *cfg)
4372 const char *dev = lustre_cfg_string(cfg, 0);
4373 struct obd_type *type;
4374 struct lu_device_type *ldt;
4375 struct lu_device *d;
4380 type = class_get_type(typename);
4382 CERROR("Unknown type: '%s'\n", typename);
4383 GOTO(out, rc = -ENODEV);
4386 rc = lu_env_refill((struct lu_env *)env);
4388 CERROR("Failure to refill session: '%d'\n", rc);
4394 CERROR("type: '%s'\n", typename);
4395 GOTO(out_type, rc = -EINVAL);
4398 ldt->ldt_obd_type = type;
4399 d = ldt->ldt_ops->ldto_device_alloc(env, ldt, cfg);
4401 CERROR("Cannot allocate device: '%s'\n", typename);
4402 GOTO(out_type, rc = -ENODEV);
4405 LASSERT(child->ld_site);
4406 d->ld_site = child->ld_site;
4409 rc = ldt->ldt_ops->ldto_device_init(env, d, dev, child);
4411 CERROR("can't init device '%s', rc %d\n", typename, rc);
4412 GOTO(out_alloc, rc);
4415 lu_ref_add(&d->ld_reference, "lu-stack", &lu_site_init);
4417 lu_dev_add_linkage(d->ld_site, d);
4420 ldt->ldt_ops->ldto_device_free(env, d);
4423 class_put_type(type);
4428 static int mdt_connect_to_next(const struct lu_env *env, struct mdt_device *m,
4429 const char *next, struct obd_export **exp)
4431 struct obd_connect_data *data = NULL;
4432 struct obd_device *obd;
4436 OBD_ALLOC_PTR(data);
4438 GOTO(out, rc = -ENOMEM);
4440 obd = class_name2obd(next);
4442 CERROR("%s: can't locate next device: %s\n",
4443 m->mdt_md_dev.md_lu_dev.ld_obd->obd_name, next);
4444 GOTO(out, rc = -ENOTCONN);
4447 data->ocd_connect_flags = OBD_CONNECT_VERSION;
4448 data->ocd_version = LUSTRE_VERSION_CODE;
4450 rc = obd_connect(NULL, exp, obd, &obd->obd_uuid, data, NULL);
4452 CERROR("%s: cannot connect to next dev %s (%d)\n",
4453 m->mdt_md_dev.md_lu_dev.ld_obd->obd_name, next, rc);
4463 static int mdt_stack_init(struct lu_env *env,
4464 struct mdt_device *m,
4465 struct lustre_cfg *cfg,
4466 struct lustre_mount_info *lmi)
4468 struct lu_device *d = &m->mdt_md_dev.md_lu_dev;
4469 struct lu_device *tmp;
4470 struct md_device *md;
4471 struct lu_device *child_lu_dev;
4476 /* find bottom osd */
4477 OBD_ALLOC(osdname, MTI_NAME_MAXLEN);
4478 if (osdname == NULL)
4481 snprintf(osdname, MTI_NAME_MAXLEN, "%s-osd", lustre_cfg_string(cfg, 0));
4482 rc = mdt_connect_to_next(env, m, osdname, &m->mdt_bottom_exp);
4483 OBD_FREE(osdname, MTI_NAME_MAXLEN);
4487 tmp = m->mdt_bottom_exp->exp_obd->obd_lu_dev;
4489 m->mdt_bottom = lu2dt_dev(tmp);
4491 /* initialize site's pointers: md_site, top device */
4492 d->ld_site = tmp->ld_site;
4493 d->ld_site->ls_top_dev = d;
4494 m->mdt_mite.ms_lu = tmp->ld_site;
4495 tmp->ld_site->ld_md_site = &m->mdt_mite;
4496 LASSERT(d->ld_site);
4499 tmp = mdt_layer_setup(env, LUSTRE_MDD_NAME, d, cfg);
4501 GOTO(out, rc = PTR_ERR(tmp));
4506 tmp = mdt_layer_setup(env, LUSTRE_CMM_NAME, d, cfg);
4508 GOTO(out, rc = PTR_ERR(tmp));
4511 /*set mdd upcall device*/
4512 md_upcall_dev_set(md, lu2md_dev(d));
4515 /*set cmm upcall device*/
4516 md_upcall_dev_set(md, &m->mdt_md_dev);
4518 m->mdt_child = lu2md_dev(d);
4520 /* process setup config */
4521 tmp = &m->mdt_md_dev.md_lu_dev;
4522 rc = tmp->ld_ops->ldo_process_config(env, tmp, cfg);
4526 /* initialize local objects */
4527 child_lu_dev = &m->mdt_child->md_lu_dev;
4529 rc = child_lu_dev->ld_ops->ldo_prepare(env,
4530 &m->mdt_md_dev.md_lu_dev,
4533 /* fini from last known good lu_device */
4535 mdt_stack_fini(env, m, d);
4541 * setup CONFIG_ORIG context, used to access local config log.
4542 * this may need to be rewrite as part of llog rewrite for lu-api.
4544 static int mdt_obd_llog_setup(struct obd_device *obd,
4545 struct lustre_sb_info *lsi)
4549 LASSERT(obd->obd_fsops == NULL);
4551 obd->obd_fsops = fsfilt_get_ops(lsi->lsi_fstype);
4552 if (IS_ERR(obd->obd_fsops))
4553 return PTR_ERR(obd->obd_fsops);
4555 rc = fsfilt_setup(obd, lsi->lsi_srv_mnt->mnt_sb);
4557 fsfilt_put_ops(obd->obd_fsops);
4561 OBD_SET_CTXT_MAGIC(&obd->obd_lvfs_ctxt);
4562 obd->obd_lvfs_ctxt.pwdmnt = lsi->lsi_srv_mnt;
4563 obd->obd_lvfs_ctxt.pwd = lsi->lsi_srv_mnt->mnt_root;
4564 obd->obd_lvfs_ctxt.fs = get_ds();
4566 rc = llog_setup(obd, &obd->obd_olg, LLOG_CONFIG_ORIG_CTXT, obd,
4567 0, NULL, &llog_lvfs_ops);
4569 CERROR("llog_setup() failed: %d\n", rc);
4570 fsfilt_put_ops(obd->obd_fsops);
4576 static void mdt_obd_llog_cleanup(struct obd_device *obd)
4578 struct llog_ctxt *ctxt;
4580 ctxt = llog_get_context(obd, LLOG_CONFIG_ORIG_CTXT);
4584 if (obd->obd_fsops) {
4585 fsfilt_put_ops(obd->obd_fsops);
4586 obd->obd_fsops = NULL;
4590 static void mdt_fini(const struct lu_env *env, struct mdt_device *m)
4592 struct md_device *next = m->mdt_child;
4593 struct lu_device *d = &m->mdt_md_dev.md_lu_dev;
4594 struct obd_device *obd = mdt2obd_dev(m);
4597 target_recovery_fini(obd);
4599 ping_evictor_stop();
4601 mdt_stop_ptlrpc_service(m);
4602 mdt_llog_ctxt_unclone(env, m, LLOG_CHANGELOG_ORIG_CTXT);
4603 mdt_obd_llog_cleanup(obd);
4604 obd_exports_barrier(obd);
4605 obd_zombie_barrier();
4609 #ifdef HAVE_QUOTA_SUPPORT
4610 next->md_ops->mdo_quota.mqo_cleanup(env, next);
4612 lut_fini(env, &m->mdt_lut);
4613 mdt_fs_cleanup(env, m);
4614 upcall_cache_cleanup(m->mdt_identity_cache);
4615 m->mdt_identity_cache = NULL;
4617 if (m->mdt_namespace != NULL) {
4618 ldlm_namespace_free(m->mdt_namespace, NULL,
4619 d->ld_obd->obd_force);
4620 d->ld_obd->obd_namespace = m->mdt_namespace = NULL;
4623 cfs_free_nidlist(&m->mdt_nosquash_nids);
4624 if (m->mdt_nosquash_str) {
4625 OBD_FREE(m->mdt_nosquash_str, m->mdt_nosquash_strlen);
4626 m->mdt_nosquash_str = NULL;
4627 m->mdt_nosquash_strlen = 0;
4630 mdt_seq_fini(env, m);
4631 mdt_seq_fini_cli(m);
4632 mdt_fld_fini(env, m);
4633 sptlrpc_rule_set_free(&m->mdt_sptlrpc_rset);
4635 next->md_ops->mdo_init_capa_ctxt(env, next, 0, 0, 0, NULL);
4636 cfs_timer_disarm(&m->mdt_ck_timer);
4637 mdt_ck_thread_stop(m);
4642 mdt_stack_fini(env, m, md2lu_dev(m->mdt_child));
4644 LASSERT(cfs_atomic_read(&d->ld_ref) == 0);
4646 server_put_mount(mdt2obd_dev(m)->obd_name, NULL);
4651 static int mdt_adapt_sptlrpc_conf(struct obd_device *obd, int initial)
4653 struct mdt_device *m = mdt_dev(obd->obd_lu_dev);
4654 struct sptlrpc_rule_set tmp_rset;
4657 sptlrpc_rule_set_init(&tmp_rset);
4658 rc = sptlrpc_conf_target_get_rules(obd, &tmp_rset, initial);
4660 CERROR("mdt %s: failed get sptlrpc rules: %d\n",
4665 sptlrpc_target_update_exp_flavor(obd, &tmp_rset);
4667 cfs_write_lock(&m->mdt_sptlrpc_lock);
4668 sptlrpc_rule_set_free(&m->mdt_sptlrpc_rset);
4669 m->mdt_sptlrpc_rset = tmp_rset;
4670 cfs_write_unlock(&m->mdt_sptlrpc_lock);
4675 int mdt_postrecov(const struct lu_env *, struct mdt_device *);
4677 static int mdt_init0(const struct lu_env *env, struct mdt_device *m,
4678 struct lu_device_type *ldt, struct lustre_cfg *cfg)
4680 struct mdt_thread_info *info;
4681 struct obd_device *obd;
4682 const char *dev = lustre_cfg_string(cfg, 0);
4683 const char *num = lustre_cfg_string(cfg, 2);
4684 struct lustre_mount_info *lmi = NULL;
4685 struct lustre_sb_info *lsi;
4687 struct md_site *mite;
4688 const char *identity_upcall = "NONE";
4689 struct md_device *next;
4695 md_device_init(&m->mdt_md_dev, ldt);
4697 * Environment (env) might be missing mdt_thread_key values at that
4698 * point, if device is allocated when mdt_thread_key is in QUIESCENT
4701 * Usually device allocation path doesn't use module key values, but
4702 * mdt has to do a lot of work here, so allocate key value.
4704 rc = lu_env_refill((struct lu_env *)env);
4708 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
4709 LASSERT(info != NULL);
4711 obd = class_name2obd(dev);
4712 LASSERT(obd != NULL);
4714 m->mdt_max_mdsize = MAX_MD_SIZE; /* 4 stripes */
4715 m->mdt_max_cookiesize = sizeof(struct llog_cookie);
4717 m->mdt_som_conf = 0;
4719 m->mdt_opts.mo_cos = MDT_COS_DEFAULT;
4720 lmi = server_get_mount(dev);
4722 CERROR("Cannot get mount info for %s!\n", dev);
4725 lsi = s2lsi(lmi->lmi_sb);
4726 /* CMD is supported only in IAM mode */
4728 node_id = simple_strtol(num, NULL, 10);
4729 if (!(lsi->lsi_flags & LDD_F_IAM_DIR) && node_id) {
4730 CERROR("CMD Operation not allowed in IOP mode\n");
4731 GOTO(err_lmi, rc = -EINVAL);
4734 obd->u.obt.obt_magic = OBT_MAGIC;
4737 cfs_rwlock_init(&m->mdt_sptlrpc_lock);
4738 sptlrpc_rule_set_init(&m->mdt_sptlrpc_rset);
4740 cfs_spin_lock_init(&m->mdt_ioepoch_lock);
4741 m->mdt_opts.mo_compat_resname = 0;
4742 m->mdt_opts.mo_mds_capa = 1;
4743 m->mdt_opts.mo_oss_capa = 1;
4744 m->mdt_capa_timeout = CAPA_TIMEOUT;
4745 m->mdt_capa_alg = CAPA_HMAC_ALG_SHA1;
4746 m->mdt_ck_timeout = CAPA_KEY_TIMEOUT;
4747 m->mdt_squash_uid = 0;
4748 m->mdt_squash_gid = 0;
4749 CFS_INIT_LIST_HEAD(&m->mdt_nosquash_nids);
4750 m->mdt_nosquash_str = NULL;
4751 m->mdt_nosquash_strlen = 0;
4752 cfs_init_rwsem(&m->mdt_squash_sem);
4753 cfs_spin_lock_init(&m->mdt_osfs_lock);
4754 m->mdt_osfs_age = cfs_time_shift_64(-1000);
4756 m->mdt_md_dev.md_lu_dev.ld_ops = &mdt_lu_ops;
4757 m->mdt_md_dev.md_lu_dev.ld_obd = obd;
4758 /* set this lu_device to obd, because error handling need it */
4759 obd->obd_lu_dev = &m->mdt_md_dev.md_lu_dev;
4761 /* init the stack */
4762 rc = mdt_stack_init((struct lu_env *)env, m, cfg, lmi);
4764 CERROR("Can't init device stack, rc %d\n", rc);
4768 s = m->mdt_md_dev.md_lu_dev.ld_site;
4769 mite = &m->mdt_mite;
4771 /* set server index */
4772 mite->ms_node_id = node_id;
4774 /* failover is the default
4775 * FIXME: we do not failout mds0/mgs, which may cause some problems.
4776 * assumed whose ms_node_id == 0 XXX
4778 obd->obd_replayable = 1;
4779 /* No connection accepted until configurations will finish */
4780 obd->obd_no_conn = 1;
4782 if (cfg->lcfg_bufcount > 4 && LUSTRE_CFG_BUFLEN(cfg, 4) > 0) {
4783 char *str = lustre_cfg_string(cfg, 4);
4784 if (strchr(str, 'n')) {
4785 CWARN("%s: recovery disabled\n", obd->obd_name);
4786 obd->obd_replayable = 0;
4790 rc = lut_init(env, &m->mdt_lut, obd, m->mdt_bottom);
4792 GOTO(err_fini_stack, rc);
4794 rc = mdt_fld_init(env, obd->obd_name, m);
4798 rc = mdt_seq_init(env, obd->obd_name, m);
4800 GOTO(err_fini_fld, rc);
4802 snprintf(info->mti_u.ns_name, sizeof info->mti_u.ns_name,
4803 LUSTRE_MDT_NAME"-%p", m);
4804 m->mdt_namespace = ldlm_namespace_new(obd, info->mti_u.ns_name,
4805 LDLM_NAMESPACE_SERVER,
4806 LDLM_NAMESPACE_GREEDY,
4808 if (m->mdt_namespace == NULL)
4809 GOTO(err_fini_seq, rc = -ENOMEM);
4811 ldlm_register_intent(m->mdt_namespace, mdt_intent_policy);
4812 /* set obd_namespace for compatibility with old code */
4813 obd->obd_namespace = m->mdt_namespace;
4815 cfs_timer_init(&m->mdt_ck_timer, mdt_ck_timer_callback, m);
4817 rc = mdt_ck_thread_start(m);
4819 GOTO(err_free_ns, rc);
4821 rc = mdt_fs_setup(env, m, obd, lsi);
4825 rc = mdt_obd_llog_setup(obd, lsi);
4827 GOTO(err_fs_cleanup, rc);
4829 rc = mdt_llog_ctxt_clone(env, m, LLOG_CHANGELOG_ORIG_CTXT);
4831 GOTO(err_llog_cleanup, rc);
4833 mdt_adapt_sptlrpc_conf(obd, 1);
4835 next = m->mdt_child;
4836 #ifdef HAVE_QUOTA_SUPPORT
4837 rc = next->md_ops->mdo_quota.mqo_setup(env, next, lmi->lmi_mnt);
4839 GOTO(err_llog_cleanup, rc);
4842 rc = next->md_ops->mdo_iocontrol(env, next, OBD_IOC_GET_MNTOPT, 0,
4845 GOTO(err_quota, rc);
4847 if (mntopts & MNTOPT_USERXATTR)
4848 m->mdt_opts.mo_user_xattr = 1;
4850 m->mdt_opts.mo_user_xattr = 0;
4852 if (mntopts & MNTOPT_ACL)
4853 m->mdt_opts.mo_acl = 1;
4855 m->mdt_opts.mo_acl = 0;
4857 /* XXX: to support suppgid for ACL, we enable identity_upcall
4858 * by default, otherwise, maybe got unexpected -EACCESS. */
4859 if (m->mdt_opts.mo_acl)
4860 identity_upcall = MDT_IDENTITY_UPCALL_PATH;
4862 m->mdt_identity_cache = upcall_cache_init(obd->obd_name,identity_upcall,
4863 &mdt_identity_upcall_cache_ops);
4864 if (IS_ERR(m->mdt_identity_cache)) {
4865 rc = PTR_ERR(m->mdt_identity_cache);
4866 m->mdt_identity_cache = NULL;
4867 GOTO(err_quota, rc);
4870 target_recovery_init(&m->mdt_lut, mdt_recovery_handle);
4872 rc = mdt_procfs_init(m, dev);
4874 CERROR("Can't init MDT lprocfs, rc %d\n", rc);
4875 GOTO(err_recovery, rc);
4878 rc = mdt_start_ptlrpc_service(m);
4880 GOTO(err_procfs, rc);
4882 ping_evictor_start();
4884 if (obd->obd_recovering == 0)
4885 mdt_postrecov(env, m);
4887 mdt_init_capa_ctxt(env, m);
4889 /* Reduce the initial timeout on an MDS because it doesn't need such
4890 * a long timeout as an OST does. Adaptive timeouts will adjust this
4891 * value appropriately. */
4892 if (ldlm_timeout == LDLM_TIMEOUT_DEFAULT)
4893 ldlm_timeout = MDS_LDLM_TIMEOUT_DEFAULT;
4897 ping_evictor_stop();
4898 mdt_stop_ptlrpc_service(m);
4902 target_recovery_fini(obd);
4903 upcall_cache_cleanup(m->mdt_identity_cache);
4904 m->mdt_identity_cache = NULL;
4906 #ifdef HAVE_QUOTA_SUPPORT
4907 next->md_ops->mdo_quota.mqo_cleanup(env, next);
4910 mdt_llog_ctxt_unclone(env, m, LLOG_CHANGELOG_ORIG_CTXT);
4911 mdt_obd_llog_cleanup(obd);
4913 mdt_fs_cleanup(env, m);
4915 cfs_timer_disarm(&m->mdt_ck_timer);
4916 mdt_ck_thread_stop(m);
4918 ldlm_namespace_free(m->mdt_namespace, NULL, 0);
4919 obd->obd_namespace = m->mdt_namespace = NULL;
4921 mdt_seq_fini(env, m);
4923 mdt_fld_fini(env, m);
4925 lut_fini(env, &m->mdt_lut);
4927 mdt_stack_fini(env, m, md2lu_dev(m->mdt_child));
4930 server_put_mount(dev, lmi->lmi_mnt);
4934 /* For interoperability between 1.8 and 2.0. */
4935 static struct cfg_interop_param mdt_interop_param[] = {
4936 { "mdt.group_upcall", NULL },
4937 { "mdt.quota_type", "mdd.quota_type" },
4938 { "mdt.rootsquash", "mdt.root_squash" },
4939 { "mdt.nosquash_nid", "mdt.nosquash_nids" },
4943 /* used by MGS to process specific configurations */
4944 static int mdt_process_config(const struct lu_env *env,
4945 struct lu_device *d, struct lustre_cfg *cfg)
4947 struct mdt_device *m = mdt_dev(d);
4948 struct md_device *md_next = m->mdt_child;
4949 struct lu_device *next = md2lu_dev(md_next);
4953 switch (cfg->lcfg_command) {
4955 struct lprocfs_static_vars lvars;
4956 struct obd_device *obd = d->ld_obd;
4958 /* For interoperability between 1.8 and 2.0. */
4959 struct cfg_interop_param *ptr = NULL;
4960 struct lustre_cfg *old_cfg = NULL;
4963 param = lustre_cfg_string(cfg, 1);
4964 if (param == NULL) {
4965 CERROR("param is empty\n");
4970 ptr = class_find_old_param(param, mdt_interop_param);
4972 if (ptr->new_param == NULL) {
4973 CWARN("For 1.8 interoperability, skip this %s."
4974 " It is obsolete.\n", ptr->old_param);
4978 CWARN("Found old param %s, changed it to %s.\n",
4979 ptr->old_param, ptr->new_param);
4982 cfg = lustre_cfg_rename(old_cfg, ptr->new_param);
4989 lprocfs_mdt_init_vars(&lvars);
4990 rc = class_process_proc_param(PARAM_MDT, lvars.obd_vars,
4992 if (rc > 0 || rc == -ENOSYS)
4993 /* we don't understand; pass it on */
4994 rc = next->ld_ops->ldo_process_config(env, next, cfg);
4996 if (old_cfg != NULL)
4997 lustre_cfg_free(cfg);
5003 * Add mdc hook to get first MDT uuid and connect it to
5004 * ls->controller to use for seq manager.
5006 rc = next->ld_ops->ldo_process_config(env, next, cfg);
5008 CERROR("Can't add mdc, rc %d\n", rc);
5010 rc = mdt_seq_init_cli(env, mdt_dev(d), cfg);
5013 /* others are passed further */
5014 rc = next->ld_ops->ldo_process_config(env, next, cfg);
5020 static struct lu_object *mdt_object_alloc(const struct lu_env *env,
5021 const struct lu_object_header *hdr,
5022 struct lu_device *d)
5024 struct mdt_object *mo;
5028 OBD_SLAB_ALLOC_PTR_GFP(mo, mdt_object_kmem, CFS_ALLOC_IO);
5030 struct lu_object *o;
5031 struct lu_object_header *h;
5033 o = &mo->mot_obj.mo_lu;
5034 h = &mo->mot_header;
5035 lu_object_header_init(h);
5036 lu_object_init(o, h, d);
5037 lu_object_add_top(h, o);
5038 o->lo_ops = &mdt_obj_ops;
5039 cfs_mutex_init(&mo->mot_ioepoch_mutex);
5040 cfs_mutex_init(&mo->mot_lov_mutex);
5046 static int mdt_object_init(const struct lu_env *env, struct lu_object *o,
5047 const struct lu_object_conf *unused)
5049 struct mdt_device *d = mdt_dev(o->lo_dev);
5050 struct lu_device *under;
5051 struct lu_object *below;
5055 CDEBUG(D_INFO, "object init, fid = "DFID"\n",
5056 PFID(lu_object_fid(o)));
5058 under = &d->mdt_child->md_lu_dev;
5059 below = under->ld_ops->ldo_object_alloc(env, o->lo_header, under);
5060 if (below != NULL) {
5061 lu_object_add(o, below);
5068 static void mdt_object_free(const struct lu_env *env, struct lu_object *o)
5070 struct mdt_object *mo = mdt_obj(o);
5071 struct lu_object_header *h;
5075 CDEBUG(D_INFO, "object free, fid = "DFID"\n",
5076 PFID(lu_object_fid(o)));
5079 lu_object_header_fini(h);
5080 OBD_SLAB_FREE_PTR(mo, mdt_object_kmem);
5085 static int mdt_object_print(const struct lu_env *env, void *cookie,
5086 lu_printer_t p, const struct lu_object *o)
5088 struct mdt_object *mdto = mdt_obj((struct lu_object *)o);
5089 return (*p)(env, cookie, LUSTRE_MDT_NAME"-object@%p(ioepoch="LPU64" "
5090 "flags="LPX64", epochcount=%d, writecount=%d)",
5091 mdto, mdto->mot_ioepoch, mdto->mot_flags,
5092 mdto->mot_ioepoch_count, mdto->mot_writecount);
5095 static const struct lu_device_operations mdt_lu_ops = {
5096 .ldo_object_alloc = mdt_object_alloc,
5097 .ldo_process_config = mdt_process_config,
5100 static const struct lu_object_operations mdt_obj_ops = {
5101 .loo_object_init = mdt_object_init,
5102 .loo_object_free = mdt_object_free,
5103 .loo_object_print = mdt_object_print
5106 static int mdt_obd_set_info_async(const struct lu_env *env,
5107 struct obd_export *exp,
5108 __u32 keylen, void *key,
5109 __u32 vallen, void *val,
5110 struct ptlrpc_request_set *set)
5112 struct obd_device *obd = exp->exp_obd;
5118 if (KEY_IS(KEY_SPTLRPC_CONF)) {
5119 rc = mdt_adapt_sptlrpc_conf(obd, 0);
5126 /* mds_connect_internal */
5127 static int mdt_connect_internal(struct obd_export *exp,
5128 struct mdt_device *mdt,
5129 struct obd_connect_data *data)
5132 data->ocd_connect_flags &= MDT_CONNECT_SUPPORTED;
5133 data->ocd_ibits_known &= MDS_INODELOCK_FULL;
5135 /* If no known bits (which should not happen, probably,
5136 as everybody should support LOOKUP and UPDATE bits at least)
5137 revert to compat mode with plain locks. */
5138 if (!data->ocd_ibits_known &&
5139 data->ocd_connect_flags & OBD_CONNECT_IBITS)
5140 data->ocd_connect_flags &= ~OBD_CONNECT_IBITS;
5142 if (!mdt->mdt_opts.mo_acl)
5143 data->ocd_connect_flags &= ~OBD_CONNECT_ACL;
5145 if (!mdt->mdt_opts.mo_user_xattr)
5146 data->ocd_connect_flags &= ~OBD_CONNECT_XATTR;
5148 if (!mdt->mdt_som_conf)
5149 data->ocd_connect_flags &= ~OBD_CONNECT_SOM;
5151 if (data->ocd_connect_flags & OBD_CONNECT_BRW_SIZE) {
5152 data->ocd_brw_size = min(data->ocd_brw_size,
5153 (__u32)(PTLRPC_MAX_BRW_PAGES << CFS_PAGE_SHIFT));
5154 if (data->ocd_brw_size == 0) {
5155 CERROR("%s: cli %s/%p ocd_connect_flags: "LPX64
5156 " ocd_version: %x ocd_grant: %d "
5157 "ocd_index: %u ocd_brw_size is "
5158 "unexpectedly zero, network data "
5159 "corruption? Refusing connection of this"
5161 exp->exp_obd->obd_name,
5162 exp->exp_client_uuid.uuid,
5163 exp, data->ocd_connect_flags, data->ocd_version,
5164 data->ocd_grant, data->ocd_index);
5169 cfs_spin_lock(&exp->exp_lock);
5170 exp->exp_connect_flags = data->ocd_connect_flags;
5171 cfs_spin_unlock(&exp->exp_lock);
5172 data->ocd_version = LUSTRE_VERSION_CODE;
5173 exp->exp_mdt_data.med_ibits_known = data->ocd_ibits_known;
5177 if (mdt->mdt_opts.mo_acl &&
5178 ((exp->exp_connect_flags & OBD_CONNECT_ACL) == 0)) {
5179 CWARN("%s: MDS requires ACL support but client does not\n",
5180 mdt->mdt_md_dev.md_lu_dev.ld_obd->obd_name);
5185 if ((exp->exp_connect_flags & OBD_CONNECT_FID) == 0) {
5186 CWARN("%s: MDS requires FID support, but client not\n",
5187 mdt->mdt_md_dev.md_lu_dev.ld_obd->obd_name);
5191 if (mdt->mdt_som_conf && !exp_connect_som(exp) &&
5192 !(exp->exp_connect_flags & OBD_CONNECT_MDS_MDS)) {
5193 CWARN("%s: MDS has SOM enabled, but client does not support "
5194 "it\n", mdt->mdt_md_dev.md_lu_dev.ld_obd->obd_name);
5201 static int mdt_connect_check_sptlrpc(struct mdt_device *mdt,
5202 struct obd_export *exp,
5203 struct ptlrpc_request *req)
5205 struct sptlrpc_flavor flvr;
5208 if (exp->exp_flvr.sf_rpc == SPTLRPC_FLVR_INVALID) {
5209 cfs_read_lock(&mdt->mdt_sptlrpc_lock);
5210 sptlrpc_target_choose_flavor(&mdt->mdt_sptlrpc_rset,
5214 cfs_read_unlock(&mdt->mdt_sptlrpc_lock);
5216 cfs_spin_lock(&exp->exp_lock);
5218 exp->exp_sp_peer = req->rq_sp_from;
5219 exp->exp_flvr = flvr;
5221 if (exp->exp_flvr.sf_rpc != SPTLRPC_FLVR_ANY &&
5222 exp->exp_flvr.sf_rpc != req->rq_flvr.sf_rpc) {
5223 CERROR("unauthorized rpc flavor %x from %s, "
5224 "expect %x\n", req->rq_flvr.sf_rpc,
5225 libcfs_nid2str(req->rq_peer.nid),
5226 exp->exp_flvr.sf_rpc);
5230 cfs_spin_unlock(&exp->exp_lock);
5232 if (exp->exp_sp_peer != req->rq_sp_from) {
5233 CERROR("RPC source %s doesn't match %s\n",
5234 sptlrpc_part2name(req->rq_sp_from),
5235 sptlrpc_part2name(exp->exp_sp_peer));
5238 rc = sptlrpc_target_export_check(exp, req);
5245 /* mds_connect copy */
5246 static int mdt_obd_connect(const struct lu_env *env,
5247 struct obd_export **exp, struct obd_device *obd,
5248 struct obd_uuid *cluuid,
5249 struct obd_connect_data *data,
5252 struct mdt_thread_info *info;
5253 struct obd_export *lexp;
5254 struct lustre_handle conn = { 0 };
5255 struct mdt_device *mdt;
5256 struct ptlrpc_request *req;
5260 LASSERT(env != NULL);
5261 if (!exp || !obd || !cluuid)
5264 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
5265 req = info->mti_pill->rc_req;
5266 mdt = mdt_dev(obd->obd_lu_dev);
5268 rc = class_connect(&conn, obd, cluuid);
5272 lexp = class_conn2export(&conn);
5273 LASSERT(lexp != NULL);
5275 rc = mdt_connect_check_sptlrpc(mdt, lexp, req);
5279 if (OBD_FAIL_CHECK(OBD_FAIL_TGT_RCVG_FLAG))
5280 lustre_msg_add_op_flags(req->rq_repmsg, MSG_CONNECT_RECOVERING);
5282 rc = mdt_connect_internal(lexp, mdt, data);
5284 struct lsd_client_data *lcd = lexp->exp_target_data.ted_lcd;
5287 info->mti_exp = lexp;
5288 memcpy(lcd->lcd_uuid, cluuid, sizeof lcd->lcd_uuid);
5289 rc = lut_client_new(env, lexp);
5291 mdt_export_stats_init(obd, lexp, localdata);
5296 class_disconnect(lexp);
5305 static int mdt_obd_reconnect(const struct lu_env *env,
5306 struct obd_export *exp, struct obd_device *obd,
5307 struct obd_uuid *cluuid,
5308 struct obd_connect_data *data,
5311 struct mdt_thread_info *info;
5312 struct mdt_device *mdt;
5313 struct ptlrpc_request *req;
5317 if (exp == NULL || obd == NULL || cluuid == NULL)
5320 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
5321 req = info->mti_pill->rc_req;
5322 mdt = mdt_dev(obd->obd_lu_dev);
5324 rc = mdt_connect_check_sptlrpc(mdt, exp, req);
5328 rc = mdt_connect_internal(exp, mdt_dev(obd->obd_lu_dev), data);
5330 mdt_export_stats_init(obd, exp, localdata);
5335 static int mdt_export_cleanup(struct obd_export *exp)
5337 struct mdt_export_data *med = &exp->exp_mdt_data;
5338 struct obd_device *obd = exp->exp_obd;
5339 struct mdt_device *mdt;
5340 struct mdt_thread_info *info;
5342 CFS_LIST_HEAD(closing_list);
5343 struct mdt_file_data *mfd, *n;
5347 cfs_spin_lock(&med->med_open_lock);
5348 while (!cfs_list_empty(&med->med_open_head)) {
5349 cfs_list_t *tmp = med->med_open_head.next;
5350 mfd = cfs_list_entry(tmp, struct mdt_file_data, mfd_list);
5352 /* Remove mfd handle so it can't be found again.
5353 * We are consuming the mfd_list reference here. */
5354 class_handle_unhash(&mfd->mfd_handle);
5355 cfs_list_move_tail(&mfd->mfd_list, &closing_list);
5357 cfs_spin_unlock(&med->med_open_lock);
5358 mdt = mdt_dev(obd->obd_lu_dev);
5359 LASSERT(mdt != NULL);
5361 rc = lu_env_init(&env, LCT_MD_THREAD);
5365 info = lu_context_key_get(&env.le_ctx, &mdt_thread_key);
5366 LASSERT(info != NULL);
5367 memset(info, 0, sizeof *info);
5368 info->mti_env = &env;
5369 info->mti_mdt = mdt;
5370 info->mti_exp = exp;
5372 if (!cfs_list_empty(&closing_list)) {
5373 struct md_attr *ma = &info->mti_attr;
5377 lmm_size = mdt->mdt_max_mdsize;
5378 OBD_ALLOC_LARGE(ma->ma_lmm, lmm_size);
5379 if (ma->ma_lmm == NULL)
5380 GOTO(out_lmm, rc = -ENOMEM);
5382 cookie_size = mdt->mdt_max_cookiesize;
5383 OBD_ALLOC_LARGE(ma->ma_cookie, cookie_size);
5384 if (ma->ma_cookie == NULL)
5385 GOTO(out_cookie, rc = -ENOMEM);
5387 /* Close any open files (which may also cause orphan unlinking). */
5388 cfs_list_for_each_entry_safe(mfd, n, &closing_list, mfd_list) {
5389 cfs_list_del_init(&mfd->mfd_list);
5390 memset(&ma->ma_attr, 0, sizeof(ma->ma_attr));
5391 ma->ma_lmm_size = lmm_size;
5392 ma->ma_cookie_size = cookie_size;
5394 /* It is not for setattr, just tell MDD to send
5395 * DESTROY RPC to OSS if needed */
5396 ma->ma_valid = MA_FLAGS;
5397 ma->ma_attr_flags = MDS_CLOSE_CLEANUP;
5398 /* Don't unlink orphan on failover umount, LU-184 */
5399 if (exp->exp_flags & OBD_OPT_FAILOVER)
5400 ma->ma_attr_flags |= MDS_KEEP_ORPHAN;
5401 mdt_mfd_close(info, mfd);
5403 OBD_FREE_LARGE(ma->ma_cookie, cookie_size);
5404 ma->ma_cookie = NULL;
5406 OBD_FREE_LARGE(ma->ma_lmm, lmm_size);
5410 info->mti_mdt = NULL;
5411 /* cleanup client slot early */
5412 /* Do not erase record for recoverable client. */
5413 if (!(exp->exp_flags & OBD_OPT_FAILOVER) || exp->exp_failed)
5414 lut_client_del(&env, exp);
5420 static int mdt_obd_disconnect(struct obd_export *exp)
5426 class_export_get(exp);
5428 rc = server_disconnect_export(exp);
5430 CDEBUG(D_IOCTL, "server disconnect error: %d\n", rc);
5432 rc = mdt_export_cleanup(exp);
5433 class_export_put(exp);
5437 /* FIXME: Can we avoid using these two interfaces? */
5438 static int mdt_init_export(struct obd_export *exp)
5440 struct mdt_export_data *med = &exp->exp_mdt_data;
5444 CFS_INIT_LIST_HEAD(&med->med_open_head);
5445 cfs_spin_lock_init(&med->med_open_lock);
5446 cfs_mutex_init(&med->med_idmap_mutex);
5447 med->med_idmap = NULL;
5448 cfs_spin_lock(&exp->exp_lock);
5449 exp->exp_connecting = 1;
5450 cfs_spin_unlock(&exp->exp_lock);
5452 /* self-export doesn't need client data and ldlm initialization */
5453 if (unlikely(obd_uuid_equals(&exp->exp_obd->obd_uuid,
5454 &exp->exp_client_uuid)))
5457 rc = lut_client_alloc(exp);
5461 rc = ldlm_init_export(exp);
5468 lut_client_free(exp);
5470 CERROR("%s: Failed to initialize export: rc = %d\n",
5471 exp->exp_obd->obd_name, rc);
5475 static int mdt_destroy_export(struct obd_export *exp)
5479 if (exp_connect_rmtclient(exp))
5480 mdt_cleanup_idmap(&exp->exp_mdt_data);
5482 target_destroy_export(exp);
5483 /* destroy can be called from failed obd_setup, so
5484 * checking uuid is safer than obd_self_export */
5485 if (unlikely(obd_uuid_equals(&exp->exp_obd->obd_uuid,
5486 &exp->exp_client_uuid)))
5489 ldlm_destroy_export(exp);
5490 lut_client_free(exp);
5492 LASSERT(cfs_list_empty(&exp->exp_outstanding_replies));
5493 LASSERT(cfs_list_empty(&exp->exp_mdt_data.med_open_head));
5498 static void mdt_allow_cli(struct mdt_device *m, unsigned int flag)
5500 if (flag & CONFIG_LOG)
5501 cfs_set_bit(MDT_FL_CFGLOG, &m->mdt_state);
5503 /* also notify active event */
5504 if (flag & CONFIG_SYNC)
5505 cfs_set_bit(MDT_FL_SYNCED, &m->mdt_state);
5507 if (cfs_test_bit(MDT_FL_CFGLOG, &m->mdt_state) &&
5508 cfs_test_bit(MDT_FL_SYNCED, &m->mdt_state)) {
5509 struct obd_device *obd = m->mdt_md_dev.md_lu_dev.ld_obd;
5511 /* Open for clients */
5512 if (obd->obd_no_conn) {
5513 cfs_spin_lock(&obd->obd_dev_lock);
5514 obd->obd_no_conn = 0;
5515 cfs_spin_unlock(&obd->obd_dev_lock);
5520 static int mdt_upcall(const struct lu_env *env, struct md_device *md,
5521 enum md_upcall_event ev, void *data)
5523 struct mdt_device *m = mdt_dev(&md->md_lu_dev);
5524 struct md_device *next = m->mdt_child;
5525 struct mdt_thread_info *mti;
5531 rc = next->md_ops->mdo_maxsize_get(env, next,
5533 &m->mdt_max_cookiesize);
5534 CDEBUG(D_INFO, "get max mdsize %d max cookiesize %d\n",
5535 m->mdt_max_mdsize, m->mdt_max_cookiesize);
5536 mdt_allow_cli(m, CONFIG_SYNC);
5539 m->mdt_lut.lut_obd->u.obt.obt_mount_count;
5542 mti = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
5543 mti->mti_no_need_trans = 1;
5544 CDEBUG(D_INFO, "disable mdt trans for this thread\n");
5547 /* Check that MDT is not yet configured */
5548 LASSERT(!cfs_test_bit(MDT_FL_CFGLOG, &m->mdt_state));
5550 #ifdef HAVE_QUOTA_SUPPORT
5552 if (md->md_lu_dev.ld_obd->obd_recovering == 0 &&
5553 likely(md->md_lu_dev.ld_obd->obd_stopping == 0))
5554 next->md_ops->mdo_quota.mqo_recovery(env, next);
5558 CERROR("invalid event\n");
5565 static int mdt_obd_notify(struct obd_device *obd,
5566 struct obd_device *watched,
5567 enum obd_notify_event ev, void *data)
5569 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
5570 #ifdef HAVE_QUOTA_SUPPORT
5571 struct md_device *next = mdt->mdt_child;
5576 case OBD_NOTIFY_CONFIG:
5577 mdt_allow_cli(mdt, (unsigned long)data);
5579 #ifdef HAVE_QUOTA_SUPPORT
5580 /* quota_type has been processed, we can now handle
5581 * incoming quota requests */
5582 next->md_ops->mdo_quota.mqo_notify(NULL, next);
5586 CDEBUG(D_INFO, "Unhandled notification %#x\n", ev);
5591 static int mdt_rpc_fid2path(struct mdt_thread_info *info, void *key,
5592 void *val, int vallen)
5594 struct mdt_device *mdt = mdt_dev(info->mti_exp->exp_obd->obd_lu_dev);
5595 struct getinfo_fid2path *fpout, *fpin;
5598 fpin = key + cfs_size_round(sizeof(KEY_FID2PATH));
5601 if (ptlrpc_req_need_swab(info->mti_pill->rc_req))
5602 lustre_swab_fid2path(fpin);
5604 memcpy(fpout, fpin, sizeof(*fpin));
5605 if (fpout->gf_pathlen != vallen - sizeof(*fpin))
5608 rc = mdt_fid2path(info->mti_env, mdt, fpout);
5612 static int mdt_fid2path(const struct lu_env *env, struct mdt_device *mdt,
5613 struct getinfo_fid2path *fp)
5615 struct mdt_object *obj;
5619 CDEBUG(D_IOCTL, "path get "DFID" from "LPU64" #%d\n",
5620 PFID(&fp->gf_fid), fp->gf_recno, fp->gf_linkno);
5622 if (!fid_is_sane(&fp->gf_fid))
5625 obj = mdt_object_find(env, mdt, &fp->gf_fid);
5626 if (obj == NULL || IS_ERR(obj)) {
5627 CDEBUG(D_IOCTL, "no object "DFID": %ld\n", PFID(&fp->gf_fid),
5632 rc = lu_object_exists(&obj->mot_obj.mo_lu);
5638 mdt_object_put(env, obj);
5639 CDEBUG(D_IOCTL, "nonlocal object "DFID": %d\n",
5640 PFID(&fp->gf_fid), rc);
5644 rc = mo_path(env, md_object_next(&obj->mot_obj), fp->gf_path,
5645 fp->gf_pathlen, &fp->gf_recno, &fp->gf_linkno);
5646 mdt_object_put(env, obj);
5651 static int mdt_get_info(struct mdt_thread_info *info)
5653 struct ptlrpc_request *req = mdt_info_req(info);
5661 key = req_capsule_client_get(info->mti_pill, &RMF_GETINFO_KEY);
5663 CDEBUG(D_IOCTL, "No GETINFO key");
5666 keylen = req_capsule_get_size(info->mti_pill, &RMF_GETINFO_KEY,
5669 vallen = req_capsule_client_get(info->mti_pill, &RMF_GETINFO_VALLEN);
5670 if (vallen == NULL) {
5671 CDEBUG(D_IOCTL, "Unable to get RMF_GETINFO_VALLEN buffer");
5675 req_capsule_set_size(info->mti_pill, &RMF_GETINFO_VAL, RCL_SERVER,
5677 rc = req_capsule_server_pack(info->mti_pill);
5678 valout = req_capsule_server_get(info->mti_pill, &RMF_GETINFO_VAL);
5679 if (valout == NULL) {
5680 CDEBUG(D_IOCTL, "Unable to get get-info RPC out buffer");
5684 if (KEY_IS(KEY_FID2PATH))
5685 rc = mdt_rpc_fid2path(info, key, valout, *vallen);
5689 lustre_msg_set_status(req->rq_repmsg, rc);
5694 /* Pass the ioc down */
5695 static int mdt_ioc_child(struct lu_env *env, struct mdt_device *mdt,
5696 unsigned int cmd, int len, void *data)
5698 struct lu_context ioctl_session;
5699 struct md_device *next = mdt->mdt_child;
5703 rc = lu_context_init(&ioctl_session, LCT_SESSION);
5706 ioctl_session.lc_thread = (struct ptlrpc_thread *)cfs_current();
5707 lu_context_enter(&ioctl_session);
5708 env->le_ses = &ioctl_session;
5710 LASSERT(next->md_ops->mdo_iocontrol);
5711 rc = next->md_ops->mdo_iocontrol(env, next, cmd, len, data);
5713 lu_context_exit(&ioctl_session);
5714 lu_context_fini(&ioctl_session);
5718 static int mdt_ioc_version_get(struct mdt_thread_info *mti, void *karg)
5720 struct obd_ioctl_data *data = karg;
5721 struct lu_fid *fid = (struct lu_fid *)data->ioc_inlbuf1;
5723 struct mdt_object *obj;
5724 struct mdt_lock_handle *lh;
5728 CDEBUG(D_IOCTL, "getting version for "DFID"\n", PFID(fid));
5729 if (!fid_is_sane(fid))
5732 lh = &mti->mti_lh[MDT_LH_PARENT];
5733 mdt_lock_reg_init(lh, LCK_CR);
5735 obj = mdt_object_find_lock(mti, fid, lh, MDS_INODELOCK_UPDATE);
5737 RETURN(PTR_ERR(obj));
5739 rc = mdt_object_exists(obj);
5743 * before calling version get the correct MDS should be
5744 * fid, this is error to find remote object here
5746 CERROR("nonlocal object "DFID"\n", PFID(fid));
5747 } else if (rc == 0) {
5748 *(__u64 *)data->ioc_inlbuf2 = ENOENT_VERSION;
5751 version = dt_version_get(mti->mti_env, mdt_obj2dt(obj));
5752 *(__u64 *)data->ioc_inlbuf2 = version;
5755 mdt_object_unlock_put(mti, obj, lh, 1);
5759 /* ioctls on obd dev */
5760 static int mdt_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
5761 void *karg, void *uarg)
5764 struct obd_device *obd = exp->exp_obd;
5765 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
5766 struct dt_device *dt = mdt->mdt_bottom;
5770 CDEBUG(D_IOCTL, "handling ioctl cmd %#x\n", cmd);
5771 rc = lu_env_init(&env, LCT_MD_THREAD);
5777 rc = mdt_device_sync(&env, mdt);
5779 case OBD_IOC_SET_READONLY:
5780 rc = dt->dd_ops->dt_ro(&env, dt);
5782 case OBD_IOC_ABORT_RECOVERY:
5783 CERROR("Aborting recovery for device %s\n", obd->obd_name);
5784 target_stop_recovery_thread(obd);
5787 case OBD_IOC_CHANGELOG_REG:
5788 case OBD_IOC_CHANGELOG_DEREG:
5789 case OBD_IOC_CHANGELOG_CLEAR:
5790 rc = mdt_ioc_child(&env, mdt, cmd, len, karg);
5792 case OBD_IOC_START_LFSCK:
5793 case OBD_IOC_STOP_LFSCK: {
5794 struct md_device *next = mdt->mdt_child;
5795 struct obd_ioctl_data *data = karg;
5797 if (unlikely(data == NULL)) {
5802 rc = next->md_ops->mdo_iocontrol(&env, next, cmd,
5807 case OBD_IOC_GET_OBJ_VERSION: {
5808 struct mdt_thread_info *mti;
5809 mti = lu_context_key_get(&env.le_ctx, &mdt_thread_key);
5810 memset(mti, 0, sizeof *mti);
5811 mti->mti_env = &env;
5815 rc = mdt_ioc_version_get(mti, karg);
5819 CERROR("Not supported cmd = %d for device %s\n",
5820 cmd, obd->obd_name);
5828 int mdt_postrecov(const struct lu_env *env, struct mdt_device *mdt)
5830 struct lu_device *ld = md2lu_dev(mdt->mdt_child);
5831 #ifdef HAVE_QUOTA_SUPPORT
5832 struct obd_device *obd = mdt2obd_dev(mdt);
5833 struct md_device *next = mdt->mdt_child;
5838 rc = ld->ld_ops->ldo_recovery_complete(env, ld);
5839 #ifdef HAVE_QUOTA_SUPPORT
5840 if (likely(obd->obd_stopping == 0))
5841 next->md_ops->mdo_quota.mqo_recovery(env, next);
5846 int mdt_obd_postrecov(struct obd_device *obd)
5851 rc = lu_env_init(&env, LCT_MD_THREAD);
5854 rc = mdt_postrecov(&env, mdt_dev(obd->obd_lu_dev));
5860 * Send a copytool req to a client
5861 * Note this sends a request RPC from a server (MDT) to a client (MDC),
5862 * backwards of normal comms.
5864 int mdt_hsm_copytool_send(struct obd_export *exp)
5867 struct hsm_action_list *hal;
5868 struct hsm_action_item *hai;
5872 CWARN("%s: writing to mdc at %s\n", exp->exp_obd->obd_name,
5873 libcfs_nid2str(exp->exp_connection->c_peer.nid));
5875 len = sizeof(*lh) + sizeof(*hal) + MTI_NAME_MAXLEN +
5876 /* for mockup below */ 2 * cfs_size_round(sizeof(*hai));
5881 lh->kuc_magic = KUC_MAGIC;
5882 lh->kuc_transport = KUC_TRANSPORT_HSM;
5883 lh->kuc_msgtype = HMT_ACTION_LIST;
5884 lh->kuc_msglen = len;
5886 hal = (struct hsm_action_list *)(lh + 1);
5887 hal->hal_version = HAL_VERSION;
5888 hal->hal_archive_num = 1;
5889 obd_uuid2fsname(hal->hal_fsname, exp->exp_obd->obd_name,
5892 /* mock up an action list */
5894 hai = hai_zero(hal);
5895 hai->hai_action = HSMA_ARCHIVE;
5896 hai->hai_fid.f_oid = 0xA00A;
5897 hai->hai_len = sizeof(*hai);
5898 hai = hai_next(hai);
5899 hai->hai_action = HSMA_RESTORE;
5900 hai->hai_fid.f_oid = 0xB00B;
5901 hai->hai_len = sizeof(*hai);
5903 /* Uses the ldlm reverse import; this rpc will be seen by
5904 the ldlm_callback_handler */
5905 rc = do_set_info_async(exp->exp_imp_reverse,
5906 LDLM_SET_INFO, LUSTRE_OBD_VERSION,
5907 sizeof(KEY_HSM_COPYTOOL_SEND),
5908 KEY_HSM_COPYTOOL_SEND,
5916 static struct obd_ops mdt_obd_device_ops = {
5917 .o_owner = THIS_MODULE,
5918 .o_set_info_async = mdt_obd_set_info_async,
5919 .o_connect = mdt_obd_connect,
5920 .o_reconnect = mdt_obd_reconnect,
5921 .o_disconnect = mdt_obd_disconnect,
5922 .o_init_export = mdt_init_export,
5923 .o_destroy_export = mdt_destroy_export,
5924 .o_iocontrol = mdt_iocontrol,
5925 .o_postrecov = mdt_obd_postrecov,
5926 .o_notify = mdt_obd_notify
5929 static struct lu_device* mdt_device_fini(const struct lu_env *env,
5930 struct lu_device *d)
5932 struct mdt_device *m = mdt_dev(d);
5939 static struct lu_device *mdt_device_free(const struct lu_env *env,
5940 struct lu_device *d)
5942 struct mdt_device *m = mdt_dev(d);
5945 md_device_fini(&m->mdt_md_dev);
5950 static struct lu_device *mdt_device_alloc(const struct lu_env *env,
5951 struct lu_device_type *t,
5952 struct lustre_cfg *cfg)
5954 struct lu_device *l;
5955 struct mdt_device *m;
5961 l = &m->mdt_md_dev.md_lu_dev;
5962 rc = mdt_init0(env, m, t, cfg);
5964 mdt_device_free(env, l);
5968 md_upcall_init(&m->mdt_md_dev, mdt_upcall);
5970 l = ERR_PTR(-ENOMEM);
5974 /* context key constructor/destructor: mdt_key_init, mdt_key_fini */
5975 LU_KEY_INIT_FINI(mdt, struct mdt_thread_info);
5977 /* context key: mdt_thread_key */
5978 LU_CONTEXT_KEY_DEFINE(mdt, LCT_MD_THREAD);
5980 struct md_ucred *mdt_ucred(const struct mdt_thread_info *info)
5982 return md_ucred(info->mti_env);
5986 * Enable/disable COS (Commit On Sharing).
5988 * Set/Clear the COS flag in mdt options.
5990 * \param mdt mdt device
5991 * \param val 0 disables COS, other values enable COS
5993 void mdt_enable_cos(struct mdt_device *mdt, int val)
5998 mdt->mdt_opts.mo_cos = !!val;
5999 rc = lu_env_init(&env, LCT_LOCAL);
6000 if (unlikely(rc != 0)) {
6001 CWARN("lu_env initialization failed with rc = %d,"
6002 "cannot sync\n", rc);
6005 mdt_device_sync(&env, mdt);
6010 * Check COS (Commit On Sharing) status.
6012 * Return COS flag status.
6014 * \param mdt mdt device
6016 int mdt_cos_is_enabled(struct mdt_device *mdt)
6018 return mdt->mdt_opts.mo_cos != 0;
6021 /* type constructor/destructor: mdt_type_init, mdt_type_fini */
6022 LU_TYPE_INIT_FINI(mdt, &mdt_thread_key);
6024 static struct lu_device_type_operations mdt_device_type_ops = {
6025 .ldto_init = mdt_type_init,
6026 .ldto_fini = mdt_type_fini,
6028 .ldto_start = mdt_type_start,
6029 .ldto_stop = mdt_type_stop,
6031 .ldto_device_alloc = mdt_device_alloc,
6032 .ldto_device_free = mdt_device_free,
6033 .ldto_device_fini = mdt_device_fini
6036 static struct lu_device_type mdt_device_type = {
6037 .ldt_tags = LU_DEVICE_MD,
6038 .ldt_name = LUSTRE_MDT_NAME,
6039 .ldt_ops = &mdt_device_type_ops,
6040 .ldt_ctx_tags = LCT_MD_THREAD
6043 static int __init mdt_mod_init(void)
6045 struct lprocfs_static_vars lvars;
6048 rc = lu_kmem_init(mdt_caches);
6052 if (mdt_num_threads != 0 && mds_num_threads == 0) {
6053 LCONSOLE_INFO("mdt_num_threads module parameter is deprecated,"
6054 "use mds_num_threads instead or unset both for"
6055 "dynamic thread startup\n");
6056 mds_num_threads = mdt_num_threads;
6059 lprocfs_mdt_init_vars(&lvars);
6060 rc = class_register_type(&mdt_obd_device_ops, NULL,
6061 lvars.module_vars, LUSTRE_MDT_NAME,
6065 lu_kmem_fini(mdt_caches);
6069 static void __exit mdt_mod_exit(void)
6071 class_unregister_type(LUSTRE_MDT_NAME);
6072 lu_kmem_fini(mdt_caches);
6076 #define DEF_HNDL(prefix, base, suffix, flags, opc, fn, fmt) \
6077 [prefix ## _ ## opc - prefix ## _ ## base] = { \
6079 .mh_fail_id = OBD_FAIL_ ## prefix ## _ ## opc ## suffix, \
6080 .mh_opc = prefix ## _ ## opc, \
6081 .mh_flags = flags, \
6086 #define DEF_MDT_HNDL(flags, name, fn, fmt) \
6087 DEF_HNDL(MDS, GETATTR, _NET, flags, name, fn, fmt)
6089 #define DEF_SEQ_HNDL(flags, name, fn, fmt) \
6090 DEF_HNDL(SEQ, QUERY, _NET, flags, name, fn, fmt)
6092 #define DEF_FLD_HNDL(flags, name, fn, fmt) \
6093 DEF_HNDL(FLD, QUERY, _NET, flags, name, fn, fmt)
6095 * Request with a format known in advance
6097 #define DEF_MDT_HNDL_F(flags, name, fn) \
6098 DEF_HNDL(MDS, GETATTR, _NET, flags, name, fn, &RQF_MDS_ ## name)
6100 #define DEF_SEQ_HNDL_F(flags, name, fn) \
6101 DEF_HNDL(SEQ, QUERY, _NET, flags, name, fn, &RQF_SEQ_ ## name)
6103 #define DEF_FLD_HNDL_F(flags, name, fn) \
6104 DEF_HNDL(FLD, QUERY, _NET, flags, name, fn, &RQF_FLD_ ## name)
6106 * Request with a format we do not yet know
6108 #define DEF_MDT_HNDL_0(flags, name, fn) \
6109 DEF_HNDL(MDS, GETATTR, _NET, flags, name, fn, NULL)
6111 static struct mdt_handler mdt_mds_ops[] = {
6112 DEF_MDT_HNDL_F(0, CONNECT, mdt_connect),
6113 DEF_MDT_HNDL_F(0, DISCONNECT, mdt_disconnect),
6114 DEF_MDT_HNDL (0, SET_INFO, mdt_set_info,
6116 DEF_MDT_HNDL_F(0, GET_INFO, mdt_get_info),
6117 DEF_MDT_HNDL_F(0 |HABEO_REFERO, GETSTATUS, mdt_getstatus),
6118 DEF_MDT_HNDL_F(HABEO_CORPUS, GETATTR, mdt_getattr),
6119 DEF_MDT_HNDL_F(HABEO_CORPUS|HABEO_REFERO, GETATTR_NAME, mdt_getattr_name),
6120 DEF_MDT_HNDL_F(HABEO_CORPUS, GETXATTR, mdt_getxattr),
6121 DEF_MDT_HNDL_F(0 |HABEO_REFERO, STATFS, mdt_statfs),
6122 DEF_MDT_HNDL_F(0 |MUTABOR, REINT, mdt_reint),
6123 DEF_MDT_HNDL_F(HABEO_CORPUS, CLOSE, mdt_close),
6124 DEF_MDT_HNDL_F(HABEO_CORPUS, DONE_WRITING, mdt_done_writing),
6125 DEF_MDT_HNDL_F(0 |HABEO_REFERO, PIN, mdt_pin),
6126 DEF_MDT_HNDL_0(0, SYNC, mdt_sync),
6127 DEF_MDT_HNDL_F(HABEO_CORPUS|HABEO_REFERO, IS_SUBDIR, mdt_is_subdir),
6128 #ifdef HAVE_QUOTA_SUPPORT
6129 DEF_MDT_HNDL_F(0, QUOTACHECK, mdt_quotacheck_handle),
6130 DEF_MDT_HNDL_F(0, QUOTACTL, mdt_quotactl_handle)
6134 #define DEF_OBD_HNDL(flags, name, fn) \
6135 DEF_HNDL(OBD, PING, _NET, flags, name, fn, NULL)
6138 static struct mdt_handler mdt_obd_ops[] = {
6139 DEF_OBD_HNDL(0, PING, mdt_obd_ping),
6140 DEF_OBD_HNDL(0, LOG_CANCEL, mdt_obd_log_cancel),
6141 DEF_OBD_HNDL(0, QC_CALLBACK, mdt_obd_qc_callback)
6144 #define DEF_DLM_HNDL_0(flags, name, fn) \
6145 DEF_HNDL(LDLM, ENQUEUE, , flags, name, fn, NULL)
6146 #define DEF_DLM_HNDL_F(flags, name, fn) \
6147 DEF_HNDL(LDLM, ENQUEUE, , flags, name, fn, &RQF_LDLM_ ## name)
6149 static struct mdt_handler mdt_dlm_ops[] = {
6150 DEF_DLM_HNDL_F(HABEO_CLAVIS, ENQUEUE, mdt_enqueue),
6151 DEF_DLM_HNDL_0(HABEO_CLAVIS, CONVERT, mdt_convert),
6152 DEF_DLM_HNDL_0(0, BL_CALLBACK, mdt_bl_callback),
6153 DEF_DLM_HNDL_0(0, CP_CALLBACK, mdt_cp_callback)
6156 #define DEF_LLOG_HNDL(flags, name, fn) \
6157 DEF_HNDL(LLOG, ORIGIN_HANDLE_CREATE, _NET, flags, name, fn, NULL)
6159 static struct mdt_handler mdt_llog_ops[] = {
6160 DEF_LLOG_HNDL(0, ORIGIN_HANDLE_CREATE, mdt_llog_create),
6161 DEF_LLOG_HNDL(0, ORIGIN_HANDLE_NEXT_BLOCK, mdt_llog_next_block),
6162 DEF_LLOG_HNDL(0, ORIGIN_HANDLE_READ_HEADER, mdt_llog_read_header),
6163 DEF_LLOG_HNDL(0, ORIGIN_HANDLE_WRITE_REC, NULL),
6164 DEF_LLOG_HNDL(0, ORIGIN_HANDLE_CLOSE, NULL),
6165 DEF_LLOG_HNDL(0, ORIGIN_CONNECT, NULL),
6166 DEF_LLOG_HNDL(0, CATINFO, NULL),
6167 DEF_LLOG_HNDL(0, ORIGIN_HANDLE_PREV_BLOCK, mdt_llog_prev_block),
6168 DEF_LLOG_HNDL(0, ORIGIN_HANDLE_DESTROY, mdt_llog_destroy),
6171 #define DEF_SEC_CTX_HNDL(name, fn) \
6172 DEF_HNDL(SEC_CTX, INIT, _NET, 0, name, fn, NULL)
6174 static struct mdt_handler mdt_sec_ctx_ops[] = {
6175 DEF_SEC_CTX_HNDL(INIT, mdt_sec_ctx_handle),
6176 DEF_SEC_CTX_HNDL(INIT_CONT, mdt_sec_ctx_handle),
6177 DEF_SEC_CTX_HNDL(FINI, mdt_sec_ctx_handle)
6180 static struct mdt_opc_slice mdt_regular_handlers[] = {
6182 .mos_opc_start = MDS_GETATTR,
6183 .mos_opc_end = MDS_LAST_OPC,
6184 .mos_hs = mdt_mds_ops
6187 .mos_opc_start = OBD_PING,
6188 .mos_opc_end = OBD_LAST_OPC,
6189 .mos_hs = mdt_obd_ops
6192 .mos_opc_start = LDLM_ENQUEUE,
6193 .mos_opc_end = LDLM_LAST_OPC,
6194 .mos_hs = mdt_dlm_ops
6197 .mos_opc_start = LLOG_ORIGIN_HANDLE_CREATE,
6198 .mos_opc_end = LLOG_LAST_OPC,
6199 .mos_hs = mdt_llog_ops
6202 .mos_opc_start = SEC_CTX_INIT,
6203 .mos_opc_end = SEC_LAST_OPC,
6204 .mos_hs = mdt_sec_ctx_ops
6211 static struct mdt_handler mdt_readpage_ops[] = {
6212 DEF_MDT_HNDL_F(0, CONNECT, mdt_connect),
6213 DEF_MDT_HNDL_F(HABEO_CORPUS|HABEO_REFERO, READPAGE, mdt_readpage),
6214 #ifdef HAVE_SPLIT_SUPPORT
6215 DEF_MDT_HNDL_F(HABEO_CORPUS|HABEO_REFERO, WRITEPAGE, mdt_writepage),
6219 * XXX: this is ugly and should be fixed one day, see mdc_close() for
6220 * detailed comments. --umka
6222 DEF_MDT_HNDL_F(HABEO_CORPUS, CLOSE, mdt_close),
6223 DEF_MDT_HNDL_F(HABEO_CORPUS, DONE_WRITING, mdt_done_writing),
6226 static struct mdt_opc_slice mdt_readpage_handlers[] = {
6228 .mos_opc_start = MDS_GETATTR,
6229 .mos_opc_end = MDS_LAST_OPC,
6230 .mos_hs = mdt_readpage_ops
6237 static struct mdt_handler mdt_xmds_ops[] = {
6238 DEF_MDT_HNDL_F(0, CONNECT, mdt_connect),
6239 DEF_MDT_HNDL_F(HABEO_CORPUS , GETATTR, mdt_getattr),
6240 DEF_MDT_HNDL_F(0 | MUTABOR , REINT, mdt_reint),
6241 DEF_MDT_HNDL_F(HABEO_CORPUS|HABEO_REFERO, IS_SUBDIR, mdt_is_subdir),
6244 static struct mdt_opc_slice mdt_xmds_handlers[] = {
6246 .mos_opc_start = MDS_GETATTR,
6247 .mos_opc_end = MDS_LAST_OPC,
6248 .mos_hs = mdt_xmds_ops
6251 .mos_opc_start = OBD_PING,
6252 .mos_opc_end = OBD_LAST_OPC,
6253 .mos_hs = mdt_obd_ops
6256 .mos_opc_start = SEC_CTX_INIT,
6257 .mos_opc_end = SEC_LAST_OPC,
6258 .mos_hs = mdt_sec_ctx_ops
6265 static struct mdt_handler mdt_seq_ops[] = {
6266 DEF_SEQ_HNDL_F(0, QUERY, (int (*)(struct mdt_thread_info *))seq_query)
6269 static struct mdt_opc_slice mdt_seq_handlers[] = {
6271 .mos_opc_start = SEQ_QUERY,
6272 .mos_opc_end = SEQ_LAST_OPC,
6273 .mos_hs = mdt_seq_ops
6280 static struct mdt_handler mdt_fld_ops[] = {
6281 DEF_FLD_HNDL_F(0, QUERY, (int (*)(struct mdt_thread_info *))fld_query)
6284 static struct mdt_opc_slice mdt_fld_handlers[] = {
6286 .mos_opc_start = FLD_QUERY,
6287 .mos_opc_end = FLD_LAST_OPC,
6288 .mos_hs = mdt_fld_ops
6295 MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");
6296 MODULE_DESCRIPTION("Lustre Meta-data Target ("LUSTRE_MDT_NAME")");
6297 MODULE_LICENSE("GPL");
6299 cfs_module(mdt, "0.2.0", mdt_mod_init, mdt_mod_exit);