4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
27 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2011, 2012, Whamcloud, Inc.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * lustre/mdt/mdt_handler.c
38 * Lustre Metadata Target (mdt) request handler
40 * Author: Peter Braam <braam@clusterfs.com>
41 * Author: Andreas Dilger <adilger@clusterfs.com>
42 * Author: Phil Schwan <phil@clusterfs.com>
43 * Author: Mike Shaver <shaver@clusterfs.com>
44 * Author: Nikita Danilov <nikita@clusterfs.com>
45 * Author: Huang Hua <huanghua@clusterfs.com>
46 * Author: Yury Umanets <umka@clusterfs.com>
49 #define DEBUG_SUBSYSTEM S_MDS
51 #include <linux/module.h>
53 * struct OBD_{ALLOC,FREE}*()
55 #include <obd_support.h>
56 /* struct ptlrpc_request */
57 #include <lustre_net.h>
58 /* struct obd_export */
59 #include <lustre_export.h>
60 /* struct obd_device */
63 #include <dt_object.h>
64 #include <lustre_mds.h>
65 #include <lustre_mdt.h>
66 #include "mdt_internal.h"
67 #ifdef HAVE_QUOTA_SUPPORT
68 # include <lustre_quota.h>
70 #include <lustre_acl.h>
71 #include <lustre_param.h>
72 #include <lustre_fsfilt.h>
74 mdl_mode_t mdt_mdl_lock_modes[] = {
75 [LCK_MINMODE] = MDL_MINMODE,
82 [LCK_GROUP] = MDL_GROUP
85 ldlm_mode_t mdt_dlm_lock_modes[] = {
86 [MDL_MINMODE] = LCK_MINMODE,
93 [MDL_GROUP] = LCK_GROUP
97 * Initialized in mdt_mod_init().
99 static unsigned long mdt_num_threads;
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 int mdt_get_disposition(struct ldlm_reply *rep, int flag)
202 return (rep->lock_policy_res1 & flag);
205 void mdt_clear_disposition(struct mdt_thread_info *info,
206 struct ldlm_reply *rep, int flag)
209 info->mti_opdata &= ~flag;
211 rep->lock_policy_res1 &= ~flag;
214 void mdt_set_disposition(struct mdt_thread_info *info,
215 struct ldlm_reply *rep, int flag)
218 info->mti_opdata |= flag;
220 rep->lock_policy_res1 |= flag;
223 void mdt_lock_reg_init(struct mdt_lock_handle *lh, ldlm_mode_t lm)
225 lh->mlh_pdo_hash = 0;
226 lh->mlh_reg_mode = lm;
227 lh->mlh_type = MDT_REG_LOCK;
230 void mdt_lock_pdo_init(struct mdt_lock_handle *lh, ldlm_mode_t lm,
231 const char *name, int namelen)
233 lh->mlh_reg_mode = lm;
234 lh->mlh_type = MDT_PDO_LOCK;
236 if (name != NULL && (name[0] != '\0')) {
237 LASSERT(namelen > 0);
238 lh->mlh_pdo_hash = full_name_hash(name, namelen);
240 LASSERT(namelen == 0);
241 lh->mlh_pdo_hash = 0ull;
245 static void mdt_lock_pdo_mode(struct mdt_thread_info *info, struct mdt_object *o,
246 struct mdt_lock_handle *lh)
252 * Any dir access needs couple of locks:
254 * 1) on part of dir we gonna take lookup/modify;
256 * 2) on whole dir to protect it from concurrent splitting and/or to
257 * flush client's cache for readdir().
259 * so, for a given mode and object this routine decides what lock mode
260 * to use for lock #2:
262 * 1) if caller's gonna lookup in dir then we need to protect dir from
263 * being splitted only - LCK_CR
265 * 2) if caller's gonna modify dir then we need to protect dir from
266 * being splitted and to flush cache - LCK_CW
268 * 3) if caller's gonna modify dir and that dir seems ready for
269 * splitting then we need to protect it from any type of access
270 * (lookup/modify/split) - LCK_EX --bzzz
273 LASSERT(lh->mlh_reg_mode != LCK_MINMODE);
274 LASSERT(lh->mlh_pdo_mode == LCK_MINMODE);
277 * Ask underlaying level its opinion about preferable PDO lock mode
278 * having access type passed as regular lock mode:
280 * - MDL_MINMODE means that lower layer does not want to specify lock
283 * - MDL_NL means that no PDO lock should be taken. This is used in some
284 * cases. Say, for non-splittable directories no need to use PDO locks
287 mode = mdo_lock_mode(info->mti_env, mdt_object_child(o),
288 mdt_dlm_mode2mdl_mode(lh->mlh_reg_mode));
290 if (mode != MDL_MINMODE) {
291 lh->mlh_pdo_mode = mdt_mdl_mode2dlm_mode(mode);
294 * Lower layer does not want to specify locking mode. We do it
295 * our selves. No special protection is needed, just flush
296 * client's cache on modification and allow concurrent
299 switch (lh->mlh_reg_mode) {
301 lh->mlh_pdo_mode = LCK_EX;
304 lh->mlh_pdo_mode = LCK_CR;
307 lh->mlh_pdo_mode = LCK_CW;
310 CERROR("Not expected lock type (0x%x)\n",
311 (int)lh->mlh_reg_mode);
316 LASSERT(lh->mlh_pdo_mode != LCK_MINMODE);
320 static int mdt_getstatus(struct mdt_thread_info *info)
322 struct mdt_device *mdt = info->mti_mdt;
323 struct md_device *next = mdt->mdt_child;
324 struct mdt_body *repbody;
329 rc = mdt_check_ucred(info);
331 RETURN(err_serious(rc));
333 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_GETSTATUS_PACK))
334 RETURN(err_serious(-ENOMEM));
336 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
337 rc = next->md_ops->mdo_root_get(info->mti_env, next, &repbody->fid1);
341 repbody->valid |= OBD_MD_FLID;
343 if (mdt->mdt_opts.mo_mds_capa &&
344 info->mti_exp->exp_connect_flags & OBD_CONNECT_MDS_CAPA) {
345 struct mdt_object *root;
346 struct lustre_capa *capa;
348 root = mdt_object_find(info->mti_env, mdt, &repbody->fid1);
350 RETURN(PTR_ERR(root));
352 capa = req_capsule_server_get(info->mti_pill, &RMF_CAPA1);
354 capa->lc_opc = CAPA_OPC_MDS_DEFAULT;
355 rc = mo_capa_get(info->mti_env, mdt_object_child(root), capa,
357 mdt_object_put(info->mti_env, root);
359 repbody->valid |= OBD_MD_FLMDSCAPA;
365 static int mdt_statfs(struct mdt_thread_info *info)
367 struct ptlrpc_request *req = mdt_info_req(info);
368 struct md_device *next = info->mti_mdt->mdt_child;
369 struct ptlrpc_service_part *svcpt;
370 struct obd_statfs *osfs;
375 svcpt = info->mti_pill->rc_req->rq_rqbd->rqbd_svcpt;
377 /* This will trigger a watchdog timeout */
378 OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_STATFS_LCW_SLEEP,
379 (MDT_SERVICE_WATCHDOG_FACTOR *
380 at_get(&svcpt->scp_at_estimate)) + 1);
382 rc = mdt_check_ucred(info);
384 RETURN(err_serious(rc));
386 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_STATFS_PACK))
387 RETURN(err_serious(-ENOMEM));
389 osfs = req_capsule_server_get(info->mti_pill, &RMF_OBD_STATFS);
393 /** statfs information are cached in the mdt_device */
394 if (cfs_time_before_64(info->mti_mdt->mdt_osfs_age,
395 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS))) {
396 /** statfs data is too old, get up-to-date one */
397 rc = next->md_ops->mdo_statfs(info->mti_env, next, osfs);
400 cfs_spin_lock(&info->mti_mdt->mdt_osfs_lock);
401 info->mti_mdt->mdt_osfs = *osfs;
402 info->mti_mdt->mdt_osfs_age = cfs_time_current_64();
403 cfs_spin_unlock(&info->mti_mdt->mdt_osfs_lock);
405 /** use cached statfs data */
406 cfs_spin_lock(&info->mti_mdt->mdt_osfs_lock);
407 *osfs = info->mti_mdt->mdt_osfs;
408 cfs_spin_unlock(&info->mti_mdt->mdt_osfs_lock);
412 mdt_counter_incr(req, LPROC_MDT_STATFS);
418 * Pack SOM attributes into the reply.
419 * Call under a DLM UPDATE lock.
421 static void mdt_pack_size2body(struct mdt_thread_info *info,
422 struct mdt_object *mo)
425 struct md_attr *ma = &info->mti_attr;
427 LASSERT(ma->ma_attr.la_valid & LA_MODE);
428 b = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
430 /* Check if Size-on-MDS is supported, if this is a regular file,
431 * if SOM is enabled on the object and if SOM cache exists and valid.
432 * Otherwise do not pack Size-on-MDS attributes to the reply. */
433 if (!(mdt_conn_flags(info) & OBD_CONNECT_SOM) ||
434 !S_ISREG(ma->ma_attr.la_mode) ||
435 !mdt_object_is_som_enabled(mo) ||
436 !(ma->ma_valid & MA_SOM))
439 b->valid |= OBD_MD_FLSIZE | OBD_MD_FLBLOCKS;
440 b->size = ma->ma_som->msd_size;
441 b->blocks = ma->ma_som->msd_blocks;
444 void mdt_pack_attr2body(struct mdt_thread_info *info, struct mdt_body *b,
445 const struct lu_attr *attr, const struct lu_fid *fid)
447 struct md_attr *ma = &info->mti_attr;
449 LASSERT(ma->ma_valid & MA_INODE);
451 b->atime = attr->la_atime;
452 b->mtime = attr->la_mtime;
453 b->ctime = attr->la_ctime;
454 b->mode = attr->la_mode;
455 b->size = attr->la_size;
456 b->blocks = attr->la_blocks;
457 b->uid = attr->la_uid;
458 b->gid = attr->la_gid;
459 b->flags = attr->la_flags;
460 b->nlink = attr->la_nlink;
461 b->rdev = attr->la_rdev;
463 /*XXX should pack the reply body according to lu_valid*/
464 b->valid |= OBD_MD_FLCTIME | OBD_MD_FLUID |
465 OBD_MD_FLGID | OBD_MD_FLTYPE |
466 OBD_MD_FLMODE | OBD_MD_FLNLINK | OBD_MD_FLFLAGS |
467 OBD_MD_FLATIME | OBD_MD_FLMTIME ;
469 if (!S_ISREG(attr->la_mode)) {
470 b->valid |= OBD_MD_FLSIZE | OBD_MD_FLBLOCKS | OBD_MD_FLRDEV;
471 } else if (ma->ma_need & MA_LOV && ma->ma_lmm_size == 0) {
472 /* means no objects are allocated on osts. */
473 LASSERT(!(ma->ma_valid & MA_LOV));
474 /* just ignore blocks occupied by extend attributes on MDS */
476 /* if no object is allocated on osts, the size on mds is valid. b=22272 */
477 b->valid |= OBD_MD_FLSIZE | OBD_MD_FLBLOCKS;
482 b->valid |= OBD_MD_FLID;
484 /* FIXME: these should be fixed when new igif ready.*/
485 b->ino = fid_oid(fid); /* 1.6 compatibility */
486 b->generation = fid_ver(fid); /* 1.6 compatibility */
487 b->valid |= OBD_MD_FLGENER; /* 1.6 compatibility */
489 CDEBUG(D_INODE, DFID": nlink=%d, mode=%o, size="LPU64"\n",
490 PFID(fid), b->nlink, b->mode, b->size);
494 mdt_body_reverse_idmap(info, b);
496 if (b->valid & OBD_MD_FLSIZE)
497 CDEBUG(D_VFSTRACE, DFID": returning size %llu\n",
498 PFID(fid), (unsigned long long)b->size);
501 static inline int mdt_body_has_lov(const struct lu_attr *la,
502 const struct mdt_body *body)
504 return ((S_ISREG(la->la_mode) && (body->valid & OBD_MD_FLEASIZE)) ||
505 (S_ISDIR(la->la_mode) && (body->valid & OBD_MD_FLDIREA )) );
508 void mdt_client_compatibility(struct mdt_thread_info *info)
510 struct mdt_body *body;
511 struct ptlrpc_request *req = mdt_info_req(info);
512 struct obd_export *exp = req->rq_export;
513 struct md_attr *ma = &info->mti_attr;
514 struct lu_attr *la = &ma->ma_attr;
517 if (exp->exp_connect_flags & OBD_CONNECT_LAYOUTLOCK)
518 /* the client can deal with 16-bit lmm_stripe_count */
521 body = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
523 if (!mdt_body_has_lov(la, body))
526 /* now we have a reply with a lov for a client not compatible with the
527 * layout lock so we have to clean the layout generation number */
528 if (S_ISREG(la->la_mode))
529 ma->ma_lmm->lmm_layout_gen = 0;
534 static int mdt_getattr_internal(struct mdt_thread_info *info,
535 struct mdt_object *o, int ma_need)
537 struct md_object *next = mdt_object_child(o);
538 const struct mdt_body *reqbody = info->mti_body;
539 struct ptlrpc_request *req = mdt_info_req(info);
540 struct md_attr *ma = &info->mti_attr;
541 struct lu_attr *la = &ma->ma_attr;
542 struct req_capsule *pill = info->mti_pill;
543 const struct lu_env *env = info->mti_env;
544 struct mdt_body *repbody;
545 struct lu_buf *buffer = &info->mti_buf;
549 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_GETATTR_PACK))
550 RETURN(err_serious(-ENOMEM));
552 repbody = req_capsule_server_get(pill, &RMF_MDT_BODY);
556 rc = mdt_object_exists(o);
558 /* This object is located on remote node.*/
559 repbody->fid1 = *mdt_object_fid(o);
560 repbody->valid = OBD_MD_FLID | OBD_MD_MDS;
564 buffer->lb_buf = req_capsule_server_get(pill, &RMF_MDT_MD);
565 buffer->lb_len = req_capsule_get_size(pill, &RMF_MDT_MD, RCL_SERVER);
567 /* If it is dir object and client require MEA, then we got MEA */
568 if (S_ISDIR(lu_object_attr(&next->mo_lu)) &&
569 reqbody->valid & OBD_MD_MEA) {
570 /* Assumption: MDT_MD size is enough for lmv size. */
571 ma->ma_lmv = buffer->lb_buf;
572 ma->ma_lmv_size = buffer->lb_len;
573 ma->ma_need = MA_LMV | MA_INODE;
575 ma->ma_lmm = buffer->lb_buf;
576 ma->ma_lmm_size = buffer->lb_len;
577 ma->ma_need = MA_LOV | MA_INODE;
580 if (S_ISDIR(lu_object_attr(&next->mo_lu)) &&
581 reqbody->valid & OBD_MD_FLDIREA &&
582 lustre_msg_get_opc(req->rq_reqmsg) == MDS_GETATTR) {
583 /* get default stripe info for this dir. */
584 ma->ma_need |= MA_LOV_DEF;
586 ma->ma_need |= ma_need;
587 if (ma->ma_need & MA_SOM)
588 ma->ma_som = &info->mti_u.som.data;
590 rc = mo_attr_get(env, next, ma);
592 CERROR("getattr error for "DFID": %d\n",
593 PFID(mdt_object_fid(o)), rc);
597 if (likely(ma->ma_valid & MA_INODE))
598 mdt_pack_attr2body(info, repbody, la, mdt_object_fid(o));
602 if (mdt_body_has_lov(la, reqbody)) {
603 if (ma->ma_valid & MA_LOV) {
604 LASSERT(ma->ma_lmm_size);
605 mdt_dump_lmm(D_INFO, ma->ma_lmm);
606 repbody->eadatasize = ma->ma_lmm_size;
607 if (S_ISDIR(la->la_mode))
608 repbody->valid |= OBD_MD_FLDIREA;
610 repbody->valid |= OBD_MD_FLEASIZE;
612 if (ma->ma_valid & MA_LMV) {
613 LASSERT(S_ISDIR(la->la_mode));
614 repbody->eadatasize = ma->ma_lmv_size;
615 repbody->valid |= (OBD_MD_FLDIREA|OBD_MD_MEA);
617 } else if (S_ISLNK(la->la_mode) &&
618 reqbody->valid & OBD_MD_LINKNAME) {
619 buffer->lb_buf = ma->ma_lmm;
620 /* eadatasize from client includes NULL-terminator, so
621 * there is no need to read it */
622 buffer->lb_len = reqbody->eadatasize - 1;
623 rc = mo_readlink(env, next, buffer);
624 if (unlikely(rc <= 0)) {
625 CERROR("readlink failed: %d\n", rc);
628 int print_limit = min_t(int, CFS_PAGE_SIZE - 128, rc);
630 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_READLINK_EPROTO))
632 repbody->valid |= OBD_MD_LINKNAME;
633 /* we need to report back size with NULL-terminator
634 * because client expects that */
635 repbody->eadatasize = rc + 1;
636 if (repbody->eadatasize != reqbody->eadatasize)
637 CERROR("Read shorter symlink %d, expected %d\n",
638 rc, reqbody->eadatasize - 1);
640 ((char *)ma->ma_lmm)[rc] = 0;
642 /* If the total CDEBUG() size is larger than a page, it
643 * will print a warning to the console, avoid this by
644 * printing just the last part of the symlink. */
645 CDEBUG(D_INODE, "symlink dest %s%.*s, len = %d\n",
646 print_limit < rc ? "..." : "", print_limit,
647 (char *)ma->ma_lmm + rc - print_limit, rc);
652 if (reqbody->valid & OBD_MD_FLMODEASIZE) {
653 repbody->max_cookiesize = info->mti_mdt->mdt_max_cookiesize;
654 repbody->max_mdsize = info->mti_mdt->mdt_max_mdsize;
655 repbody->valid |= OBD_MD_FLMODEASIZE;
656 CDEBUG(D_INODE, "I am going to change the MAX_MD_SIZE & "
657 "MAX_COOKIE to : %d:%d\n", repbody->max_mdsize,
658 repbody->max_cookiesize);
661 if (exp_connect_rmtclient(info->mti_exp) &&
662 reqbody->valid & OBD_MD_FLRMTPERM) {
663 void *buf = req_capsule_server_get(pill, &RMF_ACL);
665 /* mdt_getattr_lock only */
666 rc = mdt_pack_remote_perm(info, o, buf);
668 repbody->valid &= ~OBD_MD_FLRMTPERM;
669 repbody->aclsize = 0;
672 repbody->valid |= OBD_MD_FLRMTPERM;
673 repbody->aclsize = sizeof(struct mdt_remote_perm);
676 #ifdef CONFIG_FS_POSIX_ACL
677 else if ((req->rq_export->exp_connect_flags & OBD_CONNECT_ACL) &&
678 (reqbody->valid & OBD_MD_FLACL)) {
679 buffer->lb_buf = req_capsule_server_get(pill, &RMF_ACL);
680 buffer->lb_len = req_capsule_get_size(pill,
681 &RMF_ACL, RCL_SERVER);
682 if (buffer->lb_len > 0) {
683 rc = mo_xattr_get(env, next, buffer,
684 XATTR_NAME_ACL_ACCESS);
686 if (rc == -ENODATA) {
687 repbody->aclsize = 0;
688 repbody->valid |= OBD_MD_FLACL;
690 } else if (rc == -EOPNOTSUPP) {
693 CERROR("got acl size: %d\n", rc);
696 repbody->aclsize = rc;
697 repbody->valid |= OBD_MD_FLACL;
704 if (reqbody->valid & OBD_MD_FLMDSCAPA &&
705 info->mti_mdt->mdt_opts.mo_mds_capa &&
706 info->mti_exp->exp_connect_flags & OBD_CONNECT_MDS_CAPA) {
707 struct lustre_capa *capa;
709 capa = req_capsule_server_get(pill, &RMF_CAPA1);
711 capa->lc_opc = CAPA_OPC_MDS_DEFAULT;
712 rc = mo_capa_get(env, next, capa, 0);
715 repbody->valid |= OBD_MD_FLMDSCAPA;
720 mdt_counter_incr(req, LPROC_MDT_GETATTR);
725 static int mdt_renew_capa(struct mdt_thread_info *info)
727 struct mdt_object *obj = info->mti_object;
728 struct mdt_body *body;
729 struct lustre_capa *capa, *c;
733 /* if object doesn't exist, or server has disabled capability,
734 * return directly, client will find body->valid OBD_MD_FLOSSCAPA
737 if (!obj || !info->mti_mdt->mdt_opts.mo_oss_capa ||
738 !(info->mti_exp->exp_connect_flags & OBD_CONNECT_OSS_CAPA))
741 body = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
742 LASSERT(body != NULL);
744 c = req_capsule_client_get(info->mti_pill, &RMF_CAPA1);
747 capa = req_capsule_server_get(info->mti_pill, &RMF_CAPA2);
751 rc = mo_capa_get(info->mti_env, mdt_object_child(obj), capa, 1);
753 body->valid |= OBD_MD_FLOSSCAPA;
757 static int mdt_getattr(struct mdt_thread_info *info)
759 struct mdt_object *obj = info->mti_object;
760 struct req_capsule *pill = info->mti_pill;
761 struct mdt_body *reqbody;
762 struct mdt_body *repbody;
767 reqbody = req_capsule_client_get(pill, &RMF_MDT_BODY);
770 if (reqbody->valid & OBD_MD_FLOSSCAPA) {
771 rc = req_capsule_server_pack(pill);
773 RETURN(err_serious(rc));
774 rc = mdt_renew_capa(info);
775 GOTO(out_shrink, rc);
778 LASSERT(obj != NULL);
779 LASSERT(lu_object_assert_exists(&obj->mot_obj.mo_lu));
781 mode = lu_object_attr(&obj->mot_obj.mo_lu);
783 /* old clients may not report needed easize, use max value then */
784 req_capsule_set_size(pill, &RMF_MDT_MD, RCL_SERVER,
785 reqbody->eadatasize == 0 ?
786 info->mti_mdt->mdt_max_mdsize :
787 reqbody->eadatasize);
789 rc = req_capsule_server_pack(pill);
790 if (unlikely(rc != 0))
791 RETURN(err_serious(rc));
793 repbody = req_capsule_server_get(pill, &RMF_MDT_BODY);
794 LASSERT(repbody != NULL);
795 repbody->eadatasize = 0;
796 repbody->aclsize = 0;
798 if (reqbody->valid & OBD_MD_FLRMTPERM)
799 rc = mdt_init_ucred(info, reqbody);
801 rc = mdt_check_ucred(info);
803 GOTO(out_shrink, rc);
805 info->mti_spec.sp_ck_split = !!(reqbody->valid & OBD_MD_FLCKSPLIT);
806 info->mti_cross_ref = !!(reqbody->valid & OBD_MD_FLCROSSREF);
809 * Don't check capability at all, because rename might getattr for
810 * remote obj, and at that time no capability is available.
812 mdt_set_capainfo(info, 1, &reqbody->fid1, BYPASS_CAPA);
813 rc = mdt_getattr_internal(info, obj, 0);
814 if (reqbody->valid & OBD_MD_FLRMTPERM)
815 mdt_exit_ucred(info);
818 mdt_client_compatibility(info);
819 rc2 = mdt_fix_reply(info);
825 static int mdt_is_subdir(struct mdt_thread_info *info)
827 struct mdt_object *o = info->mti_object;
828 struct req_capsule *pill = info->mti_pill;
829 const struct mdt_body *body = info->mti_body;
830 struct mdt_body *repbody;
836 repbody = req_capsule_server_get(pill, &RMF_MDT_BODY);
839 * We save last checked parent fid to @repbody->fid1 for remote
842 LASSERT(fid_is_sane(&body->fid2));
843 LASSERT(mdt_object_exists(o) > 0);
844 rc = mdo_is_subdir(info->mti_env, mdt_object_child(o),
845 &body->fid2, &repbody->fid1);
846 if (rc == 0 || rc == -EREMOTE)
847 repbody->valid |= OBD_MD_FLID;
852 static int mdt_raw_lookup(struct mdt_thread_info *info,
853 struct mdt_object *parent,
854 const struct lu_name *lname,
855 struct ldlm_reply *ldlm_rep)
857 struct md_object *next = mdt_object_child(info->mti_object);
858 const struct mdt_body *reqbody = info->mti_body;
859 struct lu_fid *child_fid = &info->mti_tmp_fid1;
860 struct mdt_body *repbody;
864 if (reqbody->valid != OBD_MD_FLID)
867 LASSERT(!info->mti_cross_ref);
869 /* Only got the fid of this obj by name */
871 rc = mdo_lookup(info->mti_env, next, lname, child_fid,
874 /* XXX is raw_lookup possible as intent operation? */
877 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_NEG);
880 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_POS);
882 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
885 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
886 repbody->fid1 = *child_fid;
887 repbody->valid = OBD_MD_FLID;
893 * UPDATE lock should be taken against parent, and be release before exit;
894 * child_bits lock should be taken against child, and be returned back:
895 * (1)normal request should release the child lock;
896 * (2)intent request will grant the lock to client.
898 static int mdt_getattr_name_lock(struct mdt_thread_info *info,
899 struct mdt_lock_handle *lhc,
901 struct ldlm_reply *ldlm_rep)
903 struct ptlrpc_request *req = mdt_info_req(info);
904 struct mdt_body *reqbody = NULL;
905 struct mdt_object *parent = info->mti_object;
906 struct mdt_object *child;
907 struct md_object *next = mdt_object_child(parent);
908 struct lu_fid *child_fid = &info->mti_tmp_fid1;
909 struct lu_name *lname = NULL;
910 const char *name = NULL;
912 struct mdt_lock_handle *lhp = NULL;
913 struct ldlm_lock *lock;
914 struct ldlm_res_id *res_id;
921 is_resent = lustre_handle_is_used(&lhc->mlh_reg_lh);
922 LASSERT(ergo(is_resent,
923 lustre_msg_get_flags(req->rq_reqmsg) & MSG_RESENT));
925 LASSERT(parent != NULL);
926 name = req_capsule_client_get(info->mti_pill, &RMF_NAME);
928 RETURN(err_serious(-EFAULT));
930 namelen = req_capsule_get_size(info->mti_pill, &RMF_NAME,
932 if (!info->mti_cross_ref) {
934 * XXX: Check for "namelen == 0" is for getattr by fid
935 * (OBD_CONNECT_ATTRFID), otherwise do not allow empty name,
936 * that is the name must contain at least one character and
937 * the terminating '\0'
940 reqbody = req_capsule_client_get(info->mti_pill,
942 if (unlikely(reqbody == NULL))
943 RETURN(err_serious(-EFAULT));
945 if (unlikely(!fid_is_sane(&reqbody->fid2)))
946 RETURN(err_serious(-EINVAL));
949 CDEBUG(D_INODE, "getattr with lock for "DFID"/"DFID", "
951 PFID(mdt_object_fid(parent)),
952 PFID(&reqbody->fid2), ldlm_rep);
954 lname = mdt_name(info->mti_env, (char *)name, namelen);
955 CDEBUG(D_INODE, "getattr with lock for "DFID"/%s, "
956 "ldlm_rep = %p\n", PFID(mdt_object_fid(parent)),
960 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_EXECD);
962 rc = mdt_object_exists(parent);
963 if (unlikely(rc == 0)) {
964 LU_OBJECT_DEBUG(D_INODE, info->mti_env,
965 &parent->mot_obj.mo_lu,
966 "Parent doesn't exist!\n");
968 } else if (!info->mti_cross_ref) {
969 LASSERTF(rc > 0, "Parent "DFID" is on remote server\n",
970 PFID(mdt_object_fid(parent)));
973 rc = mdt_raw_lookup(info, parent, lname, ldlm_rep);
981 if (info->mti_cross_ref) {
982 /* Only getattr on the child. Parent is on another node. */
983 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_POS);
985 CDEBUG(D_INODE, "partial getattr_name child_fid = "DFID", "
986 "ldlm_rep=%p\n", PFID(mdt_object_fid(child)), ldlm_rep);
989 /* Do not take lock for resent case. */
990 lock = ldlm_handle2lock(&lhc->mlh_reg_lh);
991 LASSERTF(lock != NULL, "Invalid lock handle "LPX64"\n",
992 lhc->mlh_reg_lh.cookie);
993 LASSERT(fid_res_name_eq(mdt_object_fid(child),
994 &lock->l_resource->lr_name));
998 mdt_lock_handle_init(lhc);
999 mdt_lock_reg_init(lhc, LCK_PR);
1002 * Object's name is on another MDS, no lookup lock is
1003 * needed here but update is.
1005 child_bits &= ~MDS_INODELOCK_LOOKUP;
1006 child_bits |= MDS_INODELOCK_UPDATE;
1008 rc = mdt_object_lock(info, child, lhc, child_bits,
1012 /* Finally, we can get attr for child. */
1013 mdt_set_capainfo(info, 0, mdt_object_fid(child),
1015 rc = mdt_getattr_internal(info, child, 0);
1016 if (unlikely(rc != 0))
1017 mdt_object_unlock(info, child, lhc, 1);
1023 /* step 1: lock parent only if parent is a directory */
1024 if (S_ISDIR(lu_object_attr(&parent->mot_obj.mo_lu))) {
1025 lhp = &info->mti_lh[MDT_LH_PARENT];
1026 mdt_lock_pdo_init(lhp, LCK_PR, name, namelen);
1027 rc = mdt_object_lock(info, parent, lhp,
1028 MDS_INODELOCK_UPDATE,
1030 if (unlikely(rc != 0))
1034 /* step 2: lookup child's fid by name */
1035 fid_zero(child_fid);
1036 rc = mdo_lookup(info->mti_env, next, lname, child_fid,
1041 mdt_set_disposition(info, ldlm_rep,
1043 GOTO(out_parent, rc);
1045 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_POS);
1047 *child_fid = reqbody->fid2;
1048 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_POS);
1052 *step 3: find the child object by fid & lock it.
1053 * regardless if it is local or remote.
1055 child = mdt_object_find(info->mti_env, info->mti_mdt, child_fid);
1057 if (unlikely(IS_ERR(child)))
1058 GOTO(out_parent, rc = PTR_ERR(child));
1060 /* Do not take lock for resent case. */
1061 lock = ldlm_handle2lock(&lhc->mlh_reg_lh);
1062 LASSERTF(lock != NULL, "Invalid lock handle "LPX64"\n",
1063 lhc->mlh_reg_lh.cookie);
1065 res_id = &lock->l_resource->lr_name;
1066 if (!fid_res_name_eq(mdt_object_fid(child),
1067 &lock->l_resource->lr_name)) {
1068 LASSERTF(fid_res_name_eq(mdt_object_fid(parent),
1069 &lock->l_resource->lr_name),
1070 "Lock res_id: %lu/%lu/%lu, Fid: "DFID".\n",
1071 (unsigned long)res_id->name[0],
1072 (unsigned long)res_id->name[1],
1073 (unsigned long)res_id->name[2],
1074 PFID(mdt_object_fid(parent)));
1075 CWARN("Although resent, but still not get child lock"
1076 "parent:"DFID" child:"DFID"\n",
1077 PFID(mdt_object_fid(parent)),
1078 PFID(mdt_object_fid(child)));
1079 lustre_msg_clear_flags(req->rq_reqmsg, MSG_RESENT);
1080 LDLM_LOCK_PUT(lock);
1083 LDLM_LOCK_PUT(lock);
1087 OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_RESEND, obd_timeout*2);
1088 mdt_lock_handle_init(lhc);
1089 if (child_bits == MDS_INODELOCK_LAYOUT)
1090 mdt_lock_reg_init(lhc, LCK_CR);
1092 mdt_lock_reg_init(lhc, LCK_PR);
1094 if (mdt_object_exists(child) == 0) {
1095 LU_OBJECT_DEBUG(D_INODE, info->mti_env,
1096 &child->mot_obj.mo_lu,
1097 "Object doesn't exist!\n");
1098 GOTO(out_child, rc = -ENOENT);
1101 if (!(child_bits & MDS_INODELOCK_UPDATE)) {
1102 struct md_attr *ma = &info->mti_attr;
1105 ma->ma_need = MA_INODE;
1106 rc = mo_attr_get(info->mti_env,
1107 mdt_object_child(child), ma);
1108 if (unlikely(rc != 0))
1109 GOTO(out_child, rc);
1111 /* layout lock is used only on regular files */
1112 if ((ma->ma_valid & MA_INODE) &&
1113 (ma->ma_attr.la_valid & LA_MODE) &&
1114 !S_ISREG(ma->ma_attr.la_mode))
1115 child_bits &= ~MDS_INODELOCK_LAYOUT;
1117 /* If the file has not been changed for some time, we
1118 * return not only a LOOKUP lock, but also an UPDATE
1119 * lock and this might save us RPC on later STAT. For
1120 * directories, it also let negative dentry starts
1121 * working for this dir. */
1122 if (ma->ma_valid & MA_INODE &&
1123 ma->ma_attr.la_valid & LA_CTIME &&
1124 info->mti_mdt->mdt_namespace->ns_ctime_age_limit +
1125 ma->ma_attr.la_ctime < cfs_time_current_sec())
1126 child_bits |= MDS_INODELOCK_UPDATE;
1129 rc = mdt_object_lock(info, child, lhc, child_bits,
1132 if (unlikely(rc != 0))
1133 GOTO(out_child, rc);
1136 lock = ldlm_handle2lock(&lhc->mlh_reg_lh);
1137 /* Get MA_SOM attributes if update lock is given. */
1139 lock->l_policy_data.l_inodebits.bits & MDS_INODELOCK_UPDATE &&
1140 S_ISREG(lu_object_attr(&mdt_object_child(child)->mo_lu)))
1143 /* finally, we can get attr for child. */
1144 mdt_set_capainfo(info, 1, child_fid, BYPASS_CAPA);
1145 rc = mdt_getattr_internal(info, child, ma_need);
1146 if (unlikely(rc != 0)) {
1147 mdt_object_unlock(info, child, lhc, 1);
1149 /* Debugging code. */
1150 res_id = &lock->l_resource->lr_name;
1151 LDLM_DEBUG(lock, "Returning lock to client");
1152 LASSERTF(fid_res_name_eq(mdt_object_fid(child),
1153 &lock->l_resource->lr_name),
1154 "Lock res_id: %lu/%lu/%lu, Fid: "DFID".\n",
1155 (unsigned long)res_id->name[0],
1156 (unsigned long)res_id->name[1],
1157 (unsigned long)res_id->name[2],
1158 PFID(mdt_object_fid(child)));
1159 mdt_pack_size2body(info, child);
1162 LDLM_LOCK_PUT(lock);
1166 mdt_object_put(info->mti_env, child);
1169 mdt_object_unlock(info, parent, lhp, 1);
1173 /* normal handler: should release the child lock */
1174 static int mdt_getattr_name(struct mdt_thread_info *info)
1176 struct mdt_lock_handle *lhc = &info->mti_lh[MDT_LH_CHILD];
1177 struct mdt_body *reqbody;
1178 struct mdt_body *repbody;
1182 reqbody = req_capsule_client_get(info->mti_pill, &RMF_MDT_BODY);
1183 LASSERT(reqbody != NULL);
1184 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
1185 LASSERT(repbody != NULL);
1187 info->mti_spec.sp_ck_split = !!(reqbody->valid & OBD_MD_FLCKSPLIT);
1188 info->mti_cross_ref = !!(reqbody->valid & OBD_MD_FLCROSSREF);
1189 repbody->eadatasize = 0;
1190 repbody->aclsize = 0;
1192 rc = mdt_init_ucred(info, reqbody);
1194 GOTO(out_shrink, rc);
1196 rc = mdt_getattr_name_lock(info, lhc, MDS_INODELOCK_UPDATE, NULL);
1197 if (lustre_handle_is_used(&lhc->mlh_reg_lh)) {
1198 ldlm_lock_decref(&lhc->mlh_reg_lh, lhc->mlh_reg_mode);
1199 lhc->mlh_reg_lh.cookie = 0;
1201 mdt_exit_ucred(info);
1204 mdt_client_compatibility(info);
1205 rc2 = mdt_fix_reply(info);
1211 static const struct lu_device_operations mdt_lu_ops;
1213 static int lu_device_is_mdt(struct lu_device *d)
1215 return ergo(d != NULL && d->ld_ops != NULL, d->ld_ops == &mdt_lu_ops);
1218 static int mdt_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
1219 void *karg, void *uarg);
1221 static int mdt_set_info(struct mdt_thread_info *info)
1223 struct ptlrpc_request *req = mdt_info_req(info);
1226 int keylen, vallen, rc = 0;
1229 rc = req_capsule_server_pack(info->mti_pill);
1233 key = req_capsule_client_get(info->mti_pill, &RMF_SETINFO_KEY);
1235 DEBUG_REQ(D_HA, req, "no set_info key");
1239 keylen = req_capsule_get_size(info->mti_pill, &RMF_SETINFO_KEY,
1242 val = req_capsule_client_get(info->mti_pill, &RMF_SETINFO_VAL);
1244 DEBUG_REQ(D_HA, req, "no set_info val");
1248 vallen = req_capsule_get_size(info->mti_pill, &RMF_SETINFO_VAL,
1251 /* Swab any part of val you need to here */
1252 if (KEY_IS(KEY_READ_ONLY)) {
1254 lustre_msg_set_status(req->rq_repmsg, 0);
1256 cfs_spin_lock(&req->rq_export->exp_lock);
1258 req->rq_export->exp_connect_flags |= OBD_CONNECT_RDONLY;
1260 req->rq_export->exp_connect_flags &=~OBD_CONNECT_RDONLY;
1261 cfs_spin_unlock(&req->rq_export->exp_lock);
1263 } else if (KEY_IS(KEY_CHANGELOG_CLEAR)) {
1264 struct changelog_setinfo *cs =
1265 (struct changelog_setinfo *)val;
1266 if (vallen != sizeof(*cs)) {
1267 CERROR("Bad changelog_clear setinfo size %d\n", vallen);
1270 if (ptlrpc_req_need_swab(req)) {
1271 __swab64s(&cs->cs_recno);
1272 __swab32s(&cs->cs_id);
1275 rc = mdt_iocontrol(OBD_IOC_CHANGELOG_CLEAR, info->mti_exp,
1277 lustre_msg_set_status(req->rq_repmsg, rc);
1285 static int mdt_connect(struct mdt_thread_info *info)
1288 struct ptlrpc_request *req;
1290 req = mdt_info_req(info);
1291 rc = target_handle_connect(req);
1293 LASSERT(req->rq_export != NULL);
1294 info->mti_mdt = mdt_dev(req->rq_export->exp_obd->obd_lu_dev);
1295 rc = mdt_init_sec_level(info);
1297 rc = mdt_init_idmap(info);
1299 obd_disconnect(class_export_get(req->rq_export));
1301 rc = err_serious(rc);
1306 static int mdt_disconnect(struct mdt_thread_info *info)
1311 rc = target_handle_disconnect(mdt_info_req(info));
1313 rc = err_serious(rc);
1317 static int mdt_sendpage(struct mdt_thread_info *info,
1318 struct lu_rdpg *rdpg, int nob)
1320 struct ptlrpc_request *req = mdt_info_req(info);
1321 struct obd_export *exp = req->rq_export;
1322 struct ptlrpc_bulk_desc *desc;
1323 struct l_wait_info *lwi = &info->mti_u.rdpg.mti_wait_info;
1330 desc = ptlrpc_prep_bulk_exp(req, rdpg->rp_npages, BULK_PUT_SOURCE,
1335 if (!(exp->exp_connect_flags & OBD_CONNECT_BRW_SIZE))
1336 /* old client requires reply size in it's PAGE_SIZE,
1337 * which is rdpg->rp_count */
1338 nob = rdpg->rp_count;
1340 for (i = 0, tmpcount = nob; i < rdpg->rp_npages && tmpcount > 0;
1341 i++, tmpcount -= tmpsize) {
1342 tmpsize = min_t(int, tmpcount, CFS_PAGE_SIZE);
1343 ptlrpc_prep_bulk_page(desc, rdpg->rp_pages[i], 0, tmpsize);
1346 LASSERT(desc->bd_nob == nob);
1347 rc = target_bulk_io(exp, desc, lwi);
1348 ptlrpc_free_bulk(desc);
1352 #ifdef HAVE_SPLIT_SUPPORT
1354 * Retrieve dir entry from the page and insert it to the slave object, actually,
1355 * this should be in osd layer, but since it will not in the final product, so
1356 * just do it here and do not define more moo api anymore for this.
1358 static int mdt_write_dir_page(struct mdt_thread_info *info, struct page *page,
1361 struct mdt_object *object = info->mti_object;
1362 struct lu_fid *lf = &info->mti_tmp_fid2;
1363 struct md_attr *ma = &info->mti_attr;
1364 struct lu_dirpage *dp;
1365 struct lu_dirent *ent;
1366 int rc = 0, offset = 0;
1369 /* Make sure we have at least one entry. */
1374 * Disable trans for this name insert, since it will include many trans
1377 info->mti_no_need_trans = 1;
1379 * When write_dir_page, no need update parent's ctime,
1380 * and no permission check for name_insert.
1382 ma->ma_attr.la_ctime = 0;
1383 ma->ma_attr.la_valid = LA_MODE;
1384 ma->ma_valid = MA_INODE;
1387 dp = page_address(page);
1388 offset = (int)((__u32)lu_dirent_start(dp) - (__u32)dp);
1390 for (ent = lu_dirent_start(dp); ent != NULL;
1391 ent = lu_dirent_next(ent)) {
1392 struct lu_name *lname;
1395 if (le16_to_cpu(ent->lde_namelen) == 0)
1398 fid_le_to_cpu(lf, &ent->lde_fid);
1399 if (le64_to_cpu(ent->lde_hash) & MAX_HASH_HIGHEST_BIT)
1400 ma->ma_attr.la_mode = S_IFDIR;
1402 ma->ma_attr.la_mode = 0;
1403 OBD_ALLOC(name, le16_to_cpu(ent->lde_namelen) + 1);
1405 GOTO(out, rc = -ENOMEM);
1407 memcpy(name, ent->lde_name, le16_to_cpu(ent->lde_namelen));
1408 lname = mdt_name(info->mti_env, name,
1409 le16_to_cpu(ent->lde_namelen));
1410 ma->ma_attr_flags |= (MDS_PERM_BYPASS | MDS_QUOTA_IGNORE);
1411 rc = mdo_name_insert(info->mti_env,
1412 md_object_next(&object->mot_obj),
1414 OBD_FREE(name, le16_to_cpu(ent->lde_namelen) + 1);
1416 CERROR("Can't insert %*.*s, rc %d\n",
1417 le16_to_cpu(ent->lde_namelen),
1418 le16_to_cpu(ent->lde_namelen),
1423 offset += lu_dirent_size(ent);
1433 static int mdt_bulk_timeout(void *data)
1437 CERROR("mdt bulk transfer timeout \n");
1442 static int mdt_writepage(struct mdt_thread_info *info)
1444 struct ptlrpc_request *req = mdt_info_req(info);
1445 struct mdt_body *reqbody;
1446 struct l_wait_info *lwi;
1447 struct ptlrpc_bulk_desc *desc;
1453 reqbody = req_capsule_client_get(info->mti_pill, &RMF_MDT_BODY);
1454 if (reqbody == NULL)
1455 RETURN(err_serious(-EFAULT));
1457 desc = ptlrpc_prep_bulk_exp(req, 1, BULK_GET_SINK, MDS_BULK_PORTAL);
1459 RETURN(err_serious(-ENOMEM));
1461 /* allocate the page for the desc */
1462 page = cfs_alloc_page(CFS_ALLOC_STD);
1464 GOTO(desc_cleanup, rc = -ENOMEM);
1466 CDEBUG(D_INFO, "Received page offset %d size %d \n",
1467 (int)reqbody->size, (int)reqbody->nlink);
1469 ptlrpc_prep_bulk_page(desc, page, (int)reqbody->size,
1470 (int)reqbody->nlink);
1472 rc = sptlrpc_svc_prep_bulk(req, desc);
1474 GOTO(cleanup_page, rc);
1476 * Check if client was evicted while we were doing i/o before touching
1481 GOTO(cleanup_page, rc = -ENOMEM);
1483 if (desc->bd_export->exp_failed)
1486 rc = ptlrpc_start_bulk_transfer (desc);
1488 *lwi = LWI_TIMEOUT_INTERVAL(obd_timeout * CFS_HZ / 4, CFS_HZ,
1489 mdt_bulk_timeout, desc);
1490 rc = l_wait_event(desc->bd_waitq, !ptlrpc_bulk_active(desc) ||
1491 desc->bd_export->exp_failed, lwi);
1492 LASSERT(rc == 0 || rc == -ETIMEDOUT);
1493 if (rc == -ETIMEDOUT) {
1494 DEBUG_REQ(D_ERROR, req, "timeout on bulk GET");
1495 ptlrpc_abort_bulk(desc);
1496 } else if (desc->bd_export->exp_failed) {
1497 DEBUG_REQ(D_ERROR, req, "Eviction on bulk GET");
1499 ptlrpc_abort_bulk(desc);
1500 } else if (!desc->bd_success ||
1501 desc->bd_nob_transferred != desc->bd_nob) {
1502 DEBUG_REQ(D_ERROR, req, "%s bulk GET %d(%d)",
1504 "truncated" : "network error on",
1505 desc->bd_nob_transferred, desc->bd_nob);
1506 /* XXX should this be a different errno? */
1510 DEBUG_REQ(D_ERROR, req, "ptlrpc_bulk_get failed: rc %d", rc);
1513 GOTO(cleanup_lwi, rc);
1514 rc = mdt_write_dir_page(info, page, reqbody->nlink);
1519 cfs_free_page(page);
1521 ptlrpc_free_bulk(desc);
1526 static int mdt_readpage(struct mdt_thread_info *info)
1528 struct mdt_object *object = info->mti_object;
1529 struct lu_rdpg *rdpg = &info->mti_u.rdpg.mti_rdpg;
1530 struct mdt_body *reqbody;
1531 struct mdt_body *repbody;
1536 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_READPAGE_PACK))
1537 RETURN(err_serious(-ENOMEM));
1539 reqbody = req_capsule_client_get(info->mti_pill, &RMF_MDT_BODY);
1540 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
1541 if (reqbody == NULL || repbody == NULL)
1542 RETURN(err_serious(-EFAULT));
1545 * prepare @rdpg before calling lower layers and transfer itself. Here
1546 * reqbody->size contains offset of where to start to read and
1547 * reqbody->nlink contains number bytes to read.
1549 rdpg->rp_hash = reqbody->size;
1550 if (rdpg->rp_hash != reqbody->size) {
1551 CERROR("Invalid hash: "LPX64" != "LPX64"\n",
1552 rdpg->rp_hash, reqbody->size);
1556 rdpg->rp_attrs = reqbody->mode;
1557 if (info->mti_exp->exp_connect_flags & OBD_CONNECT_64BITHASH)
1558 rdpg->rp_attrs |= LUDA_64BITHASH;
1559 rdpg->rp_count = min_t(unsigned int, reqbody->nlink,
1560 PTLRPC_MAX_BRW_SIZE);
1561 rdpg->rp_npages = (rdpg->rp_count + CFS_PAGE_SIZE - 1) >>
1563 OBD_ALLOC(rdpg->rp_pages, rdpg->rp_npages * sizeof rdpg->rp_pages[0]);
1564 if (rdpg->rp_pages == NULL)
1567 for (i = 0; i < rdpg->rp_npages; ++i) {
1568 rdpg->rp_pages[i] = cfs_alloc_page(CFS_ALLOC_STD);
1569 if (rdpg->rp_pages[i] == NULL)
1570 GOTO(free_rdpg, rc = -ENOMEM);
1573 /* call lower layers to fill allocated pages with directory data */
1574 rc = mo_readpage(info->mti_env, mdt_object_child(object), rdpg);
1576 GOTO(free_rdpg, rc);
1578 /* send pages to client */
1579 rc = mdt_sendpage(info, rdpg, rc);
1584 for (i = 0; i < rdpg->rp_npages; i++)
1585 if (rdpg->rp_pages[i] != NULL)
1586 cfs_free_page(rdpg->rp_pages[i]);
1587 OBD_FREE(rdpg->rp_pages, rdpg->rp_npages * sizeof rdpg->rp_pages[0]);
1589 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_SENDPAGE))
1595 static int mdt_reint_internal(struct mdt_thread_info *info,
1596 struct mdt_lock_handle *lhc,
1599 struct req_capsule *pill = info->mti_pill;
1600 struct md_quota *mq = md_quota(info->mti_env);
1601 struct mdt_body *repbody;
1606 rc = mdt_reint_unpack(info, op);
1608 CERROR("Can't unpack reint, rc %d\n", rc);
1609 RETURN(err_serious(rc));
1612 /* for replay (no_create) lmm is not needed, client has it already */
1613 if (req_capsule_has_field(pill, &RMF_MDT_MD, RCL_SERVER))
1614 req_capsule_set_size(pill, &RMF_MDT_MD, RCL_SERVER,
1615 info->mti_rr.rr_eadatalen);
1617 if (req_capsule_has_field(pill, &RMF_LOGCOOKIES, RCL_SERVER))
1618 req_capsule_set_size(pill, &RMF_LOGCOOKIES, RCL_SERVER,
1619 info->mti_mdt->mdt_max_cookiesize);
1621 rc = req_capsule_server_pack(pill);
1623 CERROR("Can't pack response, rc %d\n", rc);
1624 RETURN(err_serious(rc));
1627 if (req_capsule_has_field(pill, &RMF_MDT_BODY, RCL_SERVER)) {
1628 repbody = req_capsule_server_get(pill, &RMF_MDT_BODY);
1630 repbody->eadatasize = 0;
1631 repbody->aclsize = 0;
1634 OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_REINT_DELAY, 10);
1636 /* for replay no cookkie / lmm need, because client have this already */
1637 if (info->mti_spec.no_create)
1638 if (req_capsule_has_field(pill, &RMF_MDT_MD, RCL_SERVER))
1639 req_capsule_set_size(pill, &RMF_MDT_MD, RCL_SERVER, 0);
1641 rc = mdt_init_ucred_reint(info);
1643 GOTO(out_shrink, rc);
1645 rc = mdt_fix_attr_ucred(info, op);
1647 GOTO(out_ucred, rc = err_serious(rc));
1649 if (mdt_check_resent(info, mdt_reconstruct, lhc)) {
1650 rc = lustre_msg_get_status(mdt_info_req(info)->rq_repmsg);
1651 GOTO(out_ucred, rc);
1653 mq->mq_exp = info->mti_exp;
1654 rc = mdt_reint_rec(info, lhc);
1657 mdt_exit_ucred(info);
1659 mdt_client_compatibility(info);
1660 rc2 = mdt_fix_reply(info);
1666 static long mdt_reint_opcode(struct mdt_thread_info *info,
1667 const struct req_format **fmt)
1669 struct mdt_rec_reint *rec;
1672 opc = err_serious(-EFAULT);
1673 rec = req_capsule_client_get(info->mti_pill, &RMF_REC_REINT);
1675 opc = rec->rr_opcode;
1676 DEBUG_REQ(D_INODE, mdt_info_req(info), "reint opt = %ld", opc);
1677 if (opc < REINT_MAX && fmt[opc] != NULL)
1678 req_capsule_extend(info->mti_pill, fmt[opc]);
1680 CERROR("Unsupported opc: %ld\n", opc);
1681 opc = err_serious(opc);
1687 static int mdt_reint(struct mdt_thread_info *info)
1692 static const struct req_format *reint_fmts[REINT_MAX] = {
1693 [REINT_SETATTR] = &RQF_MDS_REINT_SETATTR,
1694 [REINT_CREATE] = &RQF_MDS_REINT_CREATE,
1695 [REINT_LINK] = &RQF_MDS_REINT_LINK,
1696 [REINT_UNLINK] = &RQF_MDS_REINT_UNLINK,
1697 [REINT_RENAME] = &RQF_MDS_REINT_RENAME,
1698 [REINT_OPEN] = &RQF_MDS_REINT_OPEN,
1699 [REINT_SETXATTR] = &RQF_MDS_REINT_SETXATTR
1704 opc = mdt_reint_opcode(info, reint_fmts);
1707 * No lock possible here from client to pass it to reint code
1710 rc = mdt_reint_internal(info, NULL, opc);
1715 info->mti_fail_id = OBD_FAIL_MDS_REINT_NET_REP;
1719 /* this should sync the whole device */
1720 static int mdt_device_sync(const struct lu_env *env, struct mdt_device *mdt)
1722 struct dt_device *dt = mdt->mdt_bottom;
1726 rc = dt->dd_ops->dt_sync(env, dt);
1730 /* this should sync this object */
1731 static int mdt_object_sync(struct mdt_thread_info *info)
1733 struct md_object *next;
1737 if (!mdt_object_exists(info->mti_object)) {
1738 CWARN("Non existing object "DFID"!\n",
1739 PFID(mdt_object_fid(info->mti_object)));
1742 next = mdt_object_child(info->mti_object);
1743 rc = mo_object_sync(info->mti_env, next);
1748 static int mdt_sync(struct mdt_thread_info *info)
1750 struct ptlrpc_request *req = mdt_info_req(info);
1751 struct req_capsule *pill = info->mti_pill;
1752 struct mdt_body *body;
1756 /* The fid may be zero, so we req_capsule_set manually */
1757 req_capsule_set(pill, &RQF_MDS_SYNC);
1759 body = req_capsule_client_get(pill, &RMF_MDT_BODY);
1761 RETURN(err_serious(-EINVAL));
1763 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_SYNC_PACK))
1764 RETURN(err_serious(-ENOMEM));
1766 if (fid_seq(&body->fid1) == 0) {
1767 /* sync the whole device */
1768 rc = req_capsule_server_pack(pill);
1770 rc = mdt_device_sync(info->mti_env, info->mti_mdt);
1772 rc = err_serious(rc);
1774 /* sync an object */
1775 rc = mdt_unpack_req_pack_rep(info, HABEO_CORPUS|HABEO_REFERO);
1777 rc = mdt_object_sync(info);
1779 struct md_object *next;
1780 const struct lu_fid *fid;
1781 struct lu_attr *la = &info->mti_attr.ma_attr;
1783 next = mdt_object_child(info->mti_object);
1784 info->mti_attr.ma_need = MA_INODE;
1785 info->mti_attr.ma_valid = 0;
1786 rc = mo_attr_get(info->mti_env, next,
1789 body = req_capsule_server_get(pill,
1791 fid = mdt_object_fid(info->mti_object);
1792 mdt_pack_attr2body(info, body, la, fid);
1796 rc = err_serious(rc);
1799 mdt_counter_incr(req, LPROC_MDT_SYNC);
1804 #ifdef HAVE_QUOTA_SUPPORT
1805 static int mdt_quotacheck_handle(struct mdt_thread_info *info)
1807 struct obd_quotactl *oqctl;
1808 struct req_capsule *pill = info->mti_pill;
1809 struct obd_export *exp = info->mti_exp;
1810 struct md_quota *mq = md_quota(info->mti_env);
1811 struct md_device *next = info->mti_mdt->mdt_child;
1815 oqctl = req_capsule_client_get(pill, &RMF_OBD_QUOTACTL);
1819 /* remote client has no permission for quotacheck */
1820 if (unlikely(exp_connect_rmtclient(exp)))
1823 rc = req_capsule_server_pack(pill);
1828 rc = next->md_ops->mdo_quota.mqo_check(info->mti_env, next,
1833 static int mdt_quotactl_handle(struct mdt_thread_info *info)
1835 struct obd_quotactl *oqctl, *repoqc;
1836 struct req_capsule *pill = info->mti_pill;
1837 struct obd_export *exp = info->mti_exp;
1838 struct md_quota *mq = md_quota(info->mti_env);
1839 struct md_device *next = info->mti_mdt->mdt_child;
1840 const struct md_quota_operations *mqo = &next->md_ops->mdo_quota;
1844 oqctl = req_capsule_client_get(pill, &RMF_OBD_QUOTACTL);
1849 if (exp_connect_rmtclient(exp)) {
1850 struct ptlrpc_request *req = mdt_info_req(info);
1851 struct mdt_export_data *med = mdt_req2med(req);
1852 struct lustre_idmap_table *idmap = med->med_idmap;
1854 if (unlikely(oqctl->qc_cmd != Q_GETQUOTA &&
1855 oqctl->qc_cmd != Q_GETINFO))
1859 if (oqctl->qc_type == USRQUOTA)
1860 id = lustre_idmap_lookup_uid(NULL, idmap, 0,
1862 else if (oqctl->qc_type == GRPQUOTA)
1863 id = lustre_idmap_lookup_gid(NULL, idmap, 0,
1868 if (id == CFS_IDMAP_NOTFOUND) {
1869 CDEBUG(D_QUOTA, "no mapping for id %u\n",
1875 rc = req_capsule_server_pack(pill);
1879 repoqc = req_capsule_server_get(pill, &RMF_OBD_QUOTACTL);
1880 LASSERT(repoqc != NULL);
1883 switch (oqctl->qc_cmd) {
1885 rc = mqo->mqo_on(info->mti_env, next, oqctl->qc_type);
1888 rc = mqo->mqo_off(info->mti_env, next, oqctl->qc_type);
1891 rc = mqo->mqo_setinfo(info->mti_env, next, oqctl->qc_type, id,
1895 rc = mqo->mqo_getinfo(info->mti_env, next, oqctl->qc_type, id,
1899 rc = mqo->mqo_setquota(info->mti_env, next, oqctl->qc_type, id,
1903 rc = mqo->mqo_getquota(info->mti_env, next, oqctl->qc_type, id,
1907 rc = mqo->mqo_getoinfo(info->mti_env, next, oqctl->qc_type, id,
1911 rc = mqo->mqo_getoquota(info->mti_env, next, oqctl->qc_type, id,
1914 case LUSTRE_Q_INVALIDATE:
1915 rc = mqo->mqo_invalidate(info->mti_env, next, oqctl->qc_type);
1917 case LUSTRE_Q_FINVALIDATE:
1918 rc = mqo->mqo_finvalidate(info->mti_env, next, oqctl->qc_type);
1921 CERROR("unsupported mdt_quotactl command: %d\n",
1933 * OBD PING and other handlers.
1935 static int mdt_obd_ping(struct mdt_thread_info *info)
1940 req_capsule_set(info->mti_pill, &RQF_OBD_PING);
1942 rc = target_handle_ping(mdt_info_req(info));
1944 rc = err_serious(rc);
1948 static int mdt_obd_log_cancel(struct mdt_thread_info *info)
1950 return err_serious(-EOPNOTSUPP);
1953 static int mdt_obd_qc_callback(struct mdt_thread_info *info)
1955 return err_serious(-EOPNOTSUPP);
1963 /** clone llog ctxt from child (mdd)
1964 * This allows remote llog (replicator) access.
1965 * We can either pass all llog RPCs (eg mdt_llog_create) on to child where the
1966 * context was originally set up, or we can handle them directly.
1967 * I choose the latter, but that means I need any llog
1968 * contexts set up by child to be accessable by the mdt. So we clone the
1969 * context into our context list here.
1971 static int mdt_llog_ctxt_clone(const struct lu_env *env, struct mdt_device *mdt,
1974 struct md_device *next = mdt->mdt_child;
1975 struct llog_ctxt *ctxt;
1978 if (!llog_ctxt_null(mdt2obd_dev(mdt), idx))
1981 rc = next->md_ops->mdo_llog_ctxt_get(env, next, idx, (void **)&ctxt);
1982 if (rc || ctxt == NULL) {
1983 CERROR("Can't get mdd ctxt %d\n", rc);
1987 rc = llog_group_set_ctxt(&mdt2obd_dev(mdt)->obd_olg, ctxt, idx);
1989 CERROR("Can't set mdt ctxt %d\n", rc);
1994 static int mdt_llog_ctxt_unclone(const struct lu_env *env,
1995 struct mdt_device *mdt, int idx)
1997 struct llog_ctxt *ctxt;
1999 ctxt = llog_get_context(mdt2obd_dev(mdt), idx);
2002 /* Put once for the get we just did, and once for the clone */
2003 llog_ctxt_put(ctxt);
2004 llog_ctxt_put(ctxt);
2008 static int mdt_llog_create(struct mdt_thread_info *info)
2012 req_capsule_set(info->mti_pill, &RQF_LLOG_ORIGIN_HANDLE_CREATE);
2013 rc = llog_origin_handle_create(mdt_info_req(info));
2014 return (rc < 0 ? err_serious(rc) : rc);
2017 static int mdt_llog_destroy(struct mdt_thread_info *info)
2021 req_capsule_set(info->mti_pill, &RQF_LLOG_ORIGIN_HANDLE_DESTROY);
2022 rc = llog_origin_handle_destroy(mdt_info_req(info));
2023 return (rc < 0 ? err_serious(rc) : rc);
2026 static int mdt_llog_read_header(struct mdt_thread_info *info)
2030 req_capsule_set(info->mti_pill, &RQF_LLOG_ORIGIN_HANDLE_READ_HEADER);
2031 rc = llog_origin_handle_read_header(mdt_info_req(info));
2032 return (rc < 0 ? err_serious(rc) : rc);
2035 static int mdt_llog_next_block(struct mdt_thread_info *info)
2039 req_capsule_set(info->mti_pill, &RQF_LLOG_ORIGIN_HANDLE_NEXT_BLOCK);
2040 rc = llog_origin_handle_next_block(mdt_info_req(info));
2041 return (rc < 0 ? err_serious(rc) : rc);
2044 static int mdt_llog_prev_block(struct mdt_thread_info *info)
2048 req_capsule_set(info->mti_pill, &RQF_LLOG_ORIGIN_HANDLE_PREV_BLOCK);
2049 rc = llog_origin_handle_prev_block(mdt_info_req(info));
2050 return (rc < 0 ? err_serious(rc) : rc);
2057 static struct ldlm_callback_suite cbs = {
2058 .lcs_completion = ldlm_server_completion_ast,
2059 .lcs_blocking = ldlm_server_blocking_ast,
2063 static int mdt_enqueue(struct mdt_thread_info *info)
2065 struct ptlrpc_request *req;
2069 * info->mti_dlm_req already contains swapped and (if necessary)
2070 * converted dlm request.
2072 LASSERT(info->mti_dlm_req != NULL);
2074 req = mdt_info_req(info);
2075 rc = ldlm_handle_enqueue0(info->mti_mdt->mdt_namespace,
2076 req, info->mti_dlm_req, &cbs);
2077 info->mti_fail_id = OBD_FAIL_LDLM_REPLY;
2078 return rc ? err_serious(rc) : req->rq_status;
2081 static int mdt_convert(struct mdt_thread_info *info)
2084 struct ptlrpc_request *req;
2086 LASSERT(info->mti_dlm_req);
2087 req = mdt_info_req(info);
2088 rc = ldlm_handle_convert0(req, info->mti_dlm_req);
2089 return rc ? err_serious(rc) : req->rq_status;
2092 static int mdt_bl_callback(struct mdt_thread_info *info)
2094 CERROR("bl callbacks should not happen on MDS\n");
2096 return err_serious(-EOPNOTSUPP);
2099 static int mdt_cp_callback(struct mdt_thread_info *info)
2101 CERROR("cp callbacks should not happen on MDS\n");
2103 return err_serious(-EOPNOTSUPP);
2107 * sec context handlers
2109 static int mdt_sec_ctx_handle(struct mdt_thread_info *info)
2113 rc = mdt_handle_idmap(info);
2116 struct ptlrpc_request *req = mdt_info_req(info);
2119 opc = lustre_msg_get_opc(req->rq_reqmsg);
2120 if (opc == SEC_CTX_INIT || opc == SEC_CTX_INIT_CONT)
2121 sptlrpc_svc_ctx_invalidate(req);
2124 CFS_FAIL_TIMEOUT(OBD_FAIL_SEC_CTX_HDL_PAUSE, cfs_fail_val);
2129 static struct mdt_object *mdt_obj(struct lu_object *o)
2131 LASSERT(lu_device_is_mdt(o->lo_dev));
2132 return container_of0(o, struct mdt_object, mot_obj.mo_lu);
2135 struct mdt_object *mdt_object_new(const struct lu_env *env,
2136 struct mdt_device *d,
2137 const struct lu_fid *f)
2139 struct lu_object_conf conf = { .loc_flags = LOC_F_NEW };
2140 struct lu_object *o;
2141 struct mdt_object *m;
2144 CDEBUG(D_INFO, "Allocate object for "DFID"\n", PFID(f));
2145 o = lu_object_find(env, &d->mdt_md_dev.md_lu_dev, f, &conf);
2146 if (unlikely(IS_ERR(o)))
2147 m = (struct mdt_object *)o;
2153 struct mdt_object *mdt_object_find(const struct lu_env *env,
2154 struct mdt_device *d,
2155 const struct lu_fid *f)
2157 struct lu_object *o;
2158 struct mdt_object *m;
2161 CDEBUG(D_INFO, "Find object for "DFID"\n", PFID(f));
2162 o = lu_object_find(env, &d->mdt_md_dev.md_lu_dev, f, NULL);
2163 if (unlikely(IS_ERR(o)))
2164 m = (struct mdt_object *)o;
2171 * Asyncronous commit for mdt device.
2173 * Pass asynchonous commit call down the MDS stack.
2175 * \param env environment
2176 * \param mdt the mdt device
2178 static void mdt_device_commit_async(const struct lu_env *env,
2179 struct mdt_device *mdt)
2181 struct dt_device *dt = mdt->mdt_bottom;
2184 rc = dt->dd_ops->dt_commit_async(env, dt);
2185 if (unlikely(rc != 0))
2186 CWARN("async commit start failed with rc = %d", rc);
2190 * Mark the lock as "synchonous".
2192 * Mark the lock to deffer transaction commit to the unlock time.
2194 * \param lock the lock to mark as "synchonous"
2196 * \see mdt_is_lock_sync
2197 * \see mdt_save_lock
2199 static inline void mdt_set_lock_sync(struct ldlm_lock *lock)
2201 lock->l_ast_data = (void*)1;
2205 * Check whehter the lock "synchonous" or not.
2207 * \param lock the lock to check
2208 * \retval 1 the lock is "synchonous"
2209 * \retval 0 the lock isn't "synchronous"
2211 * \see mdt_set_lock_sync
2212 * \see mdt_save_lock
2214 static inline int mdt_is_lock_sync(struct ldlm_lock *lock)
2216 return lock->l_ast_data != NULL;
2220 * Blocking AST for mdt locks.
2222 * Starts transaction commit if in case of COS lock conflict or
2223 * deffers such a commit to the mdt_save_lock.
2225 * \param lock the lock which blocks a request or cancelling lock
2226 * \param desc unused
2227 * \param data unused
2228 * \param flag indicates whether this cancelling or blocking callback
2230 * \see ldlm_blocking_ast_nocheck
2232 int mdt_blocking_ast(struct ldlm_lock *lock, struct ldlm_lock_desc *desc,
2233 void *data, int flag)
2235 struct obd_device *obd = ldlm_lock_to_ns(lock)->ns_obd;
2236 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
2240 if (flag == LDLM_CB_CANCELING)
2242 lock_res_and_lock(lock);
2243 if (lock->l_blocking_ast != mdt_blocking_ast) {
2244 unlock_res_and_lock(lock);
2247 if (mdt_cos_is_enabled(mdt) &&
2248 lock->l_req_mode & (LCK_PW | LCK_EX) &&
2249 lock->l_blocking_lock != NULL &&
2250 lock->l_client_cookie != lock->l_blocking_lock->l_client_cookie) {
2251 mdt_set_lock_sync(lock);
2253 rc = ldlm_blocking_ast_nocheck(lock);
2255 /* There is no lock conflict if l_blocking_lock == NULL,
2256 * it indicates a blocking ast sent from ldlm_lock_decref_internal
2257 * when the last reference to a local lock was released */
2258 if (lock->l_req_mode == LCK_COS && lock->l_blocking_lock != NULL) {
2261 rc = lu_env_init(&env, LCT_LOCAL);
2262 if (unlikely(rc != 0))
2263 CWARN("lu_env initialization failed with rc = %d,"
2264 "cannot start asynchronous commit\n", rc);
2266 mdt_device_commit_async(&env, mdt);
2272 int mdt_object_lock(struct mdt_thread_info *info, struct mdt_object *o,
2273 struct mdt_lock_handle *lh, __u64 ibits, int locality)
2275 struct ldlm_namespace *ns = info->mti_mdt->mdt_namespace;
2276 ldlm_policy_data_t *policy = &info->mti_policy;
2277 struct ldlm_res_id *res_id = &info->mti_res_id;
2281 LASSERT(!lustre_handle_is_used(&lh->mlh_reg_lh));
2282 LASSERT(!lustre_handle_is_used(&lh->mlh_pdo_lh));
2283 LASSERT(lh->mlh_reg_mode != LCK_MINMODE);
2284 LASSERT(lh->mlh_type != MDT_NUL_LOCK);
2286 if (mdt_object_exists(o) < 0) {
2287 if (locality == MDT_CROSS_LOCK) {
2288 /* cross-ref object fix */
2289 ibits &= ~MDS_INODELOCK_UPDATE;
2290 ibits |= MDS_INODELOCK_LOOKUP;
2292 LASSERT(!(ibits & MDS_INODELOCK_UPDATE));
2293 LASSERT(ibits & MDS_INODELOCK_LOOKUP);
2295 /* No PDO lock on remote object */
2296 LASSERT(lh->mlh_type != MDT_PDO_LOCK);
2299 if (lh->mlh_type == MDT_PDO_LOCK) {
2300 /* check for exists after object is locked */
2301 if (mdt_object_exists(o) == 0) {
2302 /* Non-existent object shouldn't have PDO lock */
2305 /* Non-dir object shouldn't have PDO lock */
2306 if (!S_ISDIR(lu_object_attr(&o->mot_obj.mo_lu)))
2311 memset(policy, 0, sizeof(*policy));
2312 fid_build_reg_res_name(mdt_object_fid(o), res_id);
2315 * Take PDO lock on whole directory and build correct @res_id for lock
2316 * on part of directory.
2318 if (lh->mlh_pdo_hash != 0) {
2319 LASSERT(lh->mlh_type == MDT_PDO_LOCK);
2320 mdt_lock_pdo_mode(info, o, lh);
2321 if (lh->mlh_pdo_mode != LCK_NL) {
2323 * Do not use LDLM_FL_LOCAL_ONLY for parallel lock, it
2324 * is never going to be sent to client and we do not
2325 * want it slowed down due to possible cancels.
2327 policy->l_inodebits.bits = MDS_INODELOCK_UPDATE;
2328 rc = mdt_fid_lock(ns, &lh->mlh_pdo_lh, lh->mlh_pdo_mode,
2329 policy, res_id, LDLM_FL_ATOMIC_CB,
2330 &info->mti_exp->exp_handle.h_cookie);
2336 * Finish res_id initializing by name hash marking part of
2337 * directory which is taking modification.
2339 res_id->name[LUSTRE_RES_ID_HSH_OFF] = lh->mlh_pdo_hash;
2342 policy->l_inodebits.bits = ibits;
2345 * Use LDLM_FL_LOCAL_ONLY for this lock. We do not know yet if it is
2346 * going to be sent to client. If it is - mdt_intent_policy() path will
2347 * fix it up and turn FL_LOCAL flag off.
2349 rc = mdt_fid_lock(ns, &lh->mlh_reg_lh, lh->mlh_reg_mode, policy,
2350 res_id, LDLM_FL_LOCAL_ONLY | LDLM_FL_ATOMIC_CB,
2351 &info->mti_exp->exp_handle.h_cookie);
2353 mdt_object_unlock(info, o, lh, 1);
2354 else if (unlikely(OBD_FAIL_PRECHECK(OBD_FAIL_MDS_PDO_LOCK)) &&
2355 lh->mlh_pdo_hash != 0 &&
2356 (lh->mlh_reg_mode == LCK_PW || lh->mlh_reg_mode == LCK_EX)) {
2357 OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_PDO_LOCK, 15);
2364 * Save a lock within request object.
2366 * Keep the lock referenced until whether client ACK or transaction
2367 * commit happens or release the lock immediately depending on input
2368 * parameters. If COS is ON, a write lock is converted to COS lock
2371 * \param info thead info object
2372 * \param h lock handle
2373 * \param mode lock mode
2374 * \param decref force immediate lock releasing
2377 void mdt_save_lock(struct mdt_thread_info *info, struct lustre_handle *h,
2378 ldlm_mode_t mode, int decref)
2382 if (lustre_handle_is_used(h)) {
2383 if (decref || !info->mti_has_trans ||
2384 !(mode & (LCK_PW | LCK_EX))){
2385 mdt_fid_unlock(h, mode);
2387 struct mdt_device *mdt = info->mti_mdt;
2388 struct ldlm_lock *lock = ldlm_handle2lock(h);
2389 struct ptlrpc_request *req = mdt_info_req(info);
2392 LASSERTF(lock != NULL, "no lock for cookie "LPX64"\n",
2394 CDEBUG(D_HA, "request = %p reply state = %p"
2395 " transno = "LPD64"\n",
2396 req, req->rq_reply_state, req->rq_transno);
2397 if (mdt_cos_is_enabled(mdt)) {
2399 ldlm_lock_downgrade(lock, LCK_COS);
2402 ptlrpc_save_lock(req, h, mode, no_ack);
2403 if (mdt_is_lock_sync(lock)) {
2404 CDEBUG(D_HA, "found sync-lock,"
2405 " async commit started\n");
2406 mdt_device_commit_async(info->mti_env,
2409 LDLM_LOCK_PUT(lock);
2418 * Unlock mdt object.
2420 * Immeditely release the regular lock and the PDO lock or save the
2421 * lock in reqeuest and keep them referenced until client ACK or
2422 * transaction commit.
2424 * \param info thread info object
2425 * \param o mdt object
2426 * \param lh mdt lock handle referencing regular and PDO locks
2427 * \param decref force immediate lock releasing
2429 void mdt_object_unlock(struct mdt_thread_info *info, struct mdt_object *o,
2430 struct mdt_lock_handle *lh, int decref)
2434 mdt_save_lock(info, &lh->mlh_pdo_lh, lh->mlh_pdo_mode, decref);
2435 mdt_save_lock(info, &lh->mlh_reg_lh, lh->mlh_reg_mode, decref);
2440 struct mdt_object *mdt_object_find_lock(struct mdt_thread_info *info,
2441 const struct lu_fid *f,
2442 struct mdt_lock_handle *lh,
2445 struct mdt_object *o;
2447 o = mdt_object_find(info->mti_env, info->mti_mdt, f);
2451 rc = mdt_object_lock(info, o, lh, ibits,
2454 mdt_object_put(info->mti_env, o);
2461 void mdt_object_unlock_put(struct mdt_thread_info * info,
2462 struct mdt_object * o,
2463 struct mdt_lock_handle *lh,
2466 mdt_object_unlock(info, o, lh, decref);
2467 mdt_object_put(info->mti_env, o);
2470 static struct mdt_handler *mdt_handler_find(__u32 opc,
2471 struct mdt_opc_slice *supported)
2473 struct mdt_opc_slice *s;
2474 struct mdt_handler *h;
2477 for (s = supported; s->mos_hs != NULL; s++) {
2478 if (s->mos_opc_start <= opc && opc < s->mos_opc_end) {
2479 h = s->mos_hs + (opc - s->mos_opc_start);
2480 if (likely(h->mh_opc != 0))
2481 LASSERTF(h->mh_opc == opc,
2482 "opcode mismatch %d != %d\n",
2485 h = NULL; /* unsupported opc */
2492 static int mdt_lock_resname_compat(struct mdt_device *m,
2493 struct ldlm_request *req)
2495 /* XXX something... later. */
2499 static int mdt_lock_reply_compat(struct mdt_device *m, struct ldlm_reply *rep)
2501 /* XXX something... later. */
2506 * Generic code handling requests that have struct mdt_body passed in:
2508 * - extract mdt_body from request and save it in @info, if present;
2510 * - create lu_object, corresponding to the fid in mdt_body, and save it in
2513 * - if HABEO_CORPUS flag is set for this request type check whether object
2514 * actually exists on storage (lu_object_exists()).
2517 static int mdt_body_unpack(struct mdt_thread_info *info, __u32 flags)
2519 const struct mdt_body *body;
2520 struct mdt_object *obj;
2521 const struct lu_env *env;
2522 struct req_capsule *pill;
2526 env = info->mti_env;
2527 pill = info->mti_pill;
2529 body = info->mti_body = req_capsule_client_get(pill, &RMF_MDT_BODY);
2533 if (!(body->valid & OBD_MD_FLID))
2536 if (!fid_is_sane(&body->fid1)) {
2537 CERROR("Invalid fid: "DFID"\n", PFID(&body->fid1));
2542 * Do not get size or any capa fields before we check that request
2543 * contains capa actually. There are some requests which do not, for
2544 * instance MDS_IS_SUBDIR.
2546 if (req_capsule_has_field(pill, &RMF_CAPA1, RCL_CLIENT) &&
2547 req_capsule_get_size(pill, &RMF_CAPA1, RCL_CLIENT))
2548 mdt_set_capainfo(info, 0, &body->fid1,
2549 req_capsule_client_get(pill, &RMF_CAPA1));
2551 obj = mdt_object_find(env, info->mti_mdt, &body->fid1);
2553 if ((flags & HABEO_CORPUS) &&
2554 !mdt_object_exists(obj)) {
2555 mdt_object_put(env, obj);
2556 /* for capability renew ENOENT will be handled in
2558 if (body->valid & OBD_MD_FLOSSCAPA)
2563 info->mti_object = obj;
2572 static int mdt_unpack_req_pack_rep(struct mdt_thread_info *info, __u32 flags)
2574 struct req_capsule *pill = info->mti_pill;
2578 if (req_capsule_has_field(pill, &RMF_MDT_BODY, RCL_CLIENT))
2579 rc = mdt_body_unpack(info, flags);
2583 if (rc == 0 && (flags & HABEO_REFERO)) {
2585 if (req_capsule_has_field(pill, &RMF_MDT_MD, RCL_SERVER))
2586 req_capsule_set_size(pill, &RMF_MDT_MD, RCL_SERVER,
2587 info->mti_body->eadatasize);
2588 if (req_capsule_has_field(pill, &RMF_LOGCOOKIES, RCL_SERVER))
2589 req_capsule_set_size(pill, &RMF_LOGCOOKIES, RCL_SERVER,
2590 info->mti_mdt->mdt_max_cookiesize);
2592 rc = req_capsule_server_pack(pill);
2597 static int mdt_init_capa_ctxt(const struct lu_env *env, struct mdt_device *m)
2599 struct md_device *next = m->mdt_child;
2601 return next->md_ops->mdo_init_capa_ctxt(env, next,
2602 m->mdt_opts.mo_mds_capa,
2603 m->mdt_capa_timeout,
2609 * Invoke handler for this request opc. Also do necessary preprocessing
2610 * (according to handler ->mh_flags), and post-processing (setting of
2611 * ->last_{xid,committed}).
2613 static int mdt_req_handle(struct mdt_thread_info *info,
2614 struct mdt_handler *h, struct ptlrpc_request *req)
2616 int rc, serious = 0;
2621 LASSERT(h->mh_act != NULL);
2622 LASSERT(h->mh_opc == lustre_msg_get_opc(req->rq_reqmsg));
2623 LASSERT(current->journal_info == NULL);
2626 * Checking for various OBD_FAIL_$PREF_$OPC_NET codes. _Do_ not try
2627 * to put same checks into handlers like mdt_close(), mdt_reint(),
2628 * etc., without talking to mdt authors first. Checking same thing
2629 * there again is useless and returning 0 error without packing reply
2630 * is buggy! Handlers either pack reply or return error.
2632 * We return 0 here and do not send any reply in order to emulate
2633 * network failure. Do not send any reply in case any of NET related
2634 * fail_id has occured.
2636 if (OBD_FAIL_CHECK_ORSET(h->mh_fail_id, OBD_FAIL_ONCE))
2640 flags = h->mh_flags;
2641 LASSERT(ergo(flags & (HABEO_CORPUS|HABEO_REFERO), h->mh_fmt != NULL));
2643 if (h->mh_fmt != NULL) {
2644 req_capsule_set(info->mti_pill, h->mh_fmt);
2645 rc = mdt_unpack_req_pack_rep(info, flags);
2648 if (rc == 0 && flags & MUTABOR &&
2649 req->rq_export->exp_connect_flags & OBD_CONNECT_RDONLY)
2650 /* should it be rq_status? */
2653 if (rc == 0 && flags & HABEO_CLAVIS) {
2654 struct ldlm_request *dlm_req;
2656 LASSERT(h->mh_fmt != NULL);
2658 dlm_req = req_capsule_client_get(info->mti_pill, &RMF_DLM_REQ);
2659 if (dlm_req != NULL) {
2660 if (unlikely(dlm_req->lock_desc.l_resource.lr_type ==
2662 dlm_req->lock_desc.l_policy_data.\
2663 l_inodebits.bits == 0)) {
2665 * Lock without inodebits makes no sense and
2666 * will oops later in ldlm. If client miss to
2667 * set such bits, do not trigger ASSERTION.
2669 * For liblustre flock case, it maybe zero.
2673 if (info->mti_mdt->mdt_opts.mo_compat_resname)
2674 rc = mdt_lock_resname_compat(
2677 info->mti_dlm_req = dlm_req;
2684 /* capability setting changed via /proc, needs reinitialize ctxt */
2685 if (info->mti_mdt && info->mti_mdt->mdt_capa_conf) {
2686 mdt_init_capa_ctxt(info->mti_env, info->mti_mdt);
2687 info->mti_mdt->mdt_capa_conf = 0;
2690 if (likely(rc == 0)) {
2692 * Process request, there can be two types of rc:
2693 * 1) errors with msg unpack/pack, other failures outside the
2694 * operation itself. This is counted as serious errors;
2695 * 2) errors during fs operation, should be placed in rq_status
2698 rc = h->mh_act(info);
2700 !req->rq_no_reply && req->rq_reply_state == NULL) {
2701 DEBUG_REQ(D_ERROR, req, "MDT \"handler\" %s did not "
2702 "pack reply and returned 0 error\n",
2706 serious = is_serious(rc);
2707 rc = clear_serious(rc);
2711 req->rq_status = rc;
2714 * ELDLM_* codes which > 0 should be in rq_status only as well as
2715 * all non-serious errors.
2717 if (rc > 0 || !serious)
2720 LASSERT(current->journal_info == NULL);
2722 if (rc == 0 && (flags & HABEO_CLAVIS) &&
2723 info->mti_mdt->mdt_opts.mo_compat_resname) {
2724 struct ldlm_reply *dlmrep;
2726 dlmrep = req_capsule_server_get(info->mti_pill, &RMF_DLM_REP);
2728 rc = mdt_lock_reply_compat(info->mti_mdt, dlmrep);
2731 /* If we're DISCONNECTing, the mdt_export_data is already freed */
2732 if (likely(rc == 0 && req->rq_export && h->mh_opc != MDS_DISCONNECT))
2733 target_committed_to_req(req);
2735 if (unlikely(req_is_replay(req) &&
2736 lustre_msg_get_transno(req->rq_reqmsg) == 0)) {
2737 DEBUG_REQ(D_ERROR, req, "transno is 0 during REPLAY");
2741 target_send_reply(req, rc, info->mti_fail_id);
2745 void mdt_lock_handle_init(struct mdt_lock_handle *lh)
2747 lh->mlh_type = MDT_NUL_LOCK;
2748 lh->mlh_reg_lh.cookie = 0ull;
2749 lh->mlh_reg_mode = LCK_MINMODE;
2750 lh->mlh_pdo_lh.cookie = 0ull;
2751 lh->mlh_pdo_mode = LCK_MINMODE;
2754 void mdt_lock_handle_fini(struct mdt_lock_handle *lh)
2756 LASSERT(!lustre_handle_is_used(&lh->mlh_reg_lh));
2757 LASSERT(!lustre_handle_is_used(&lh->mlh_pdo_lh));
2761 * Initialize fields of struct mdt_thread_info. Other fields are left in
2762 * uninitialized state, because it's too expensive to zero out whole
2763 * mdt_thread_info (> 1K) on each request arrival.
2765 static void mdt_thread_info_init(struct ptlrpc_request *req,
2766 struct mdt_thread_info *info)
2769 struct md_capainfo *ci;
2771 req_capsule_init(&req->rq_pill, req, RCL_SERVER);
2772 info->mti_pill = &req->rq_pill;
2775 for (i = 0; i < ARRAY_SIZE(info->mti_lh); i++)
2776 mdt_lock_handle_init(&info->mti_lh[i]);
2778 /* mdt device: it can be NULL while CONNECT */
2779 if (req->rq_export) {
2780 info->mti_mdt = mdt_dev(req->rq_export->exp_obd->obd_lu_dev);
2781 info->mti_exp = req->rq_export;
2783 info->mti_mdt = NULL;
2784 info->mti_env = req->rq_svc_thread->t_env;
2785 ci = md_capainfo(info->mti_env);
2786 memset(ci, 0, sizeof *ci);
2787 if (req->rq_export) {
2788 if (exp_connect_rmtclient(req->rq_export))
2789 ci->mc_auth = LC_ID_CONVERT;
2790 else if (req->rq_export->exp_connect_flags &
2791 OBD_CONNECT_MDS_CAPA)
2792 ci->mc_auth = LC_ID_PLAIN;
2794 ci->mc_auth = LC_ID_NONE;
2797 info->mti_fail_id = OBD_FAIL_MDS_ALL_REPLY_NET;
2798 info->mti_transno = lustre_msg_get_transno(req->rq_reqmsg);
2799 info->mti_mos = NULL;
2801 memset(&info->mti_attr, 0, sizeof(info->mti_attr));
2802 info->mti_body = NULL;
2803 info->mti_object = NULL;
2804 info->mti_dlm_req = NULL;
2805 info->mti_has_trans = 0;
2806 info->mti_no_need_trans = 0;
2807 info->mti_cross_ref = 0;
2808 info->mti_opdata = 0;
2810 /* To not check for split by default. */
2811 info->mti_spec.sp_ck_split = 0;
2812 info->mti_spec.no_create = 0;
2815 static void mdt_thread_info_fini(struct mdt_thread_info *info)
2819 req_capsule_fini(info->mti_pill);
2820 if (info->mti_object != NULL) {
2822 * freeing an object may lead to OSD level transaction, do not
2823 * let it mess with MDT. bz19385.
2825 info->mti_no_need_trans = 1;
2826 mdt_object_put(info->mti_env, info->mti_object);
2827 info->mti_object = NULL;
2829 for (i = 0; i < ARRAY_SIZE(info->mti_lh); i++)
2830 mdt_lock_handle_fini(&info->mti_lh[i]);
2831 info->mti_env = NULL;
2834 static int mdt_filter_recovery_request(struct ptlrpc_request *req,
2835 struct obd_device *obd, int *process)
2837 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
2838 case MDS_CONNECT: /* This will never get here, but for completeness. */
2839 case OST_CONNECT: /* This will never get here, but for completeness. */
2840 case MDS_DISCONNECT:
2841 case OST_DISCONNECT:
2846 case MDS_DONE_WRITING:
2847 case MDS_SYNC: /* used in unmounting */
2853 *process = target_queue_recovery_request(req, obd);
2857 DEBUG_REQ(D_ERROR, req, "not permitted during recovery");
2864 * Handle recovery. Return:
2865 * +1: continue request processing;
2866 * -ve: abort immediately with the given error code;
2867 * 0: send reply with error code in req->rq_status;
2869 static int mdt_recovery(struct mdt_thread_info *info)
2871 struct ptlrpc_request *req = mdt_info_req(info);
2872 struct obd_device *obd;
2876 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
2879 case SEC_CTX_INIT_CONT:
2885 rc = mdt_handle_idmap(info);
2894 if (unlikely(!class_connected_export(req->rq_export))) {
2895 CERROR("operation %d on unconnected MDS from %s\n",
2896 lustre_msg_get_opc(req->rq_reqmsg),
2897 libcfs_id2str(req->rq_peer));
2898 /* FIXME: For CMD cleanup, when mds_B stop, the req from
2899 * mds_A will get -ENOTCONN(especially for ping req),
2900 * which will cause that mds_A deactive timeout, then when
2901 * mds_A cleanup, the cleanup process will be suspended since
2902 * deactive timeout is not zero.
2904 req->rq_status = -ENOTCONN;
2905 target_send_reply(req, -ENOTCONN, info->mti_fail_id);
2909 /* sanity check: if the xid matches, the request must be marked as a
2910 * resent or replayed */
2911 if (req_xid_is_last(req)) {
2912 if (!(lustre_msg_get_flags(req->rq_reqmsg) &
2913 (MSG_RESENT | MSG_REPLAY))) {
2914 DEBUG_REQ(D_WARNING, req, "rq_xid "LPU64" matches last_xid, "
2915 "expected REPLAY or RESENT flag (%x)", req->rq_xid,
2916 lustre_msg_get_flags(req->rq_reqmsg));
2918 req->rq_status = -ENOTCONN;
2923 /* else: note the opposite is not always true; a RESENT req after a
2924 * failover will usually not match the last_xid, since it was likely
2925 * never committed. A REPLAYed request will almost never match the
2926 * last xid, however it could for a committed, but still retained,
2929 obd = req->rq_export->exp_obd;
2931 /* Check for aborted recovery... */
2932 if (unlikely(obd->obd_recovering)) {
2935 DEBUG_REQ(D_INFO, req, "Got new replay");
2936 rc = mdt_filter_recovery_request(req, obd, &should_process);
2937 if (rc != 0 || !should_process)
2939 else if (should_process < 0) {
2940 req->rq_status = should_process;
2941 rc = ptlrpc_error(req);
2948 static int mdt_msg_check_version(struct lustre_msg *msg)
2952 switch (lustre_msg_get_opc(msg)) {
2954 case MDS_DISCONNECT:
2957 case SEC_CTX_INIT_CONT:
2959 rc = lustre_msg_check_version(msg, LUSTRE_OBD_VERSION);
2961 CERROR("bad opc %u version %08x, expecting %08x\n",
2962 lustre_msg_get_opc(msg),
2963 lustre_msg_get_version(msg),
2964 LUSTRE_OBD_VERSION);
2968 case MDS_GETATTR_NAME:
2975 case MDS_DONE_WRITING:
2982 case MDS_QUOTACHECK:
2988 rc = lustre_msg_check_version(msg, LUSTRE_MDS_VERSION);
2990 CERROR("bad opc %u version %08x, expecting %08x\n",
2991 lustre_msg_get_opc(msg),
2992 lustre_msg_get_version(msg),
2993 LUSTRE_MDS_VERSION);
2997 case LDLM_BL_CALLBACK:
2998 case LDLM_CP_CALLBACK:
2999 rc = lustre_msg_check_version(msg, LUSTRE_DLM_VERSION);
3001 CERROR("bad opc %u version %08x, expecting %08x\n",
3002 lustre_msg_get_opc(msg),
3003 lustre_msg_get_version(msg),
3004 LUSTRE_DLM_VERSION);
3006 case OBD_LOG_CANCEL:
3007 case LLOG_ORIGIN_HANDLE_CREATE:
3008 case LLOG_ORIGIN_HANDLE_NEXT_BLOCK:
3009 case LLOG_ORIGIN_HANDLE_READ_HEADER:
3010 case LLOG_ORIGIN_HANDLE_CLOSE:
3011 case LLOG_ORIGIN_HANDLE_DESTROY:
3012 case LLOG_ORIGIN_HANDLE_PREV_BLOCK:
3014 rc = lustre_msg_check_version(msg, LUSTRE_LOG_VERSION);
3016 CERROR("bad opc %u version %08x, expecting %08x\n",
3017 lustre_msg_get_opc(msg),
3018 lustre_msg_get_version(msg),
3019 LUSTRE_LOG_VERSION);
3022 CERROR("MDS unknown opcode %d\n", lustre_msg_get_opc(msg));
3028 static int mdt_handle0(struct ptlrpc_request *req,
3029 struct mdt_thread_info *info,
3030 struct mdt_opc_slice *supported)
3032 struct mdt_handler *h;
3033 struct lustre_msg *msg;
3038 if (OBD_FAIL_CHECK_ORSET(OBD_FAIL_MDS_ALL_REQUEST_NET, OBD_FAIL_ONCE))
3041 LASSERT(current->journal_info == NULL);
3043 msg = req->rq_reqmsg;
3044 rc = mdt_msg_check_version(msg);
3045 if (likely(rc == 0)) {
3046 rc = mdt_recovery(info);
3047 if (likely(rc == +1)) {
3048 h = mdt_handler_find(lustre_msg_get_opc(msg),
3050 if (likely(h != NULL)) {
3051 rc = mdt_req_handle(info, h, req);
3053 CERROR("The unsupported opc: 0x%x\n",
3054 lustre_msg_get_opc(msg) );
3055 req->rq_status = -ENOTSUPP;
3056 rc = ptlrpc_error(req);
3061 CERROR(LUSTRE_MDT_NAME" drops mal-formed request\n");
3066 * MDT handler function called by ptlrpc service thread when request comes.
3068 * XXX common "target" functionality should be factored into separate module
3069 * shared by mdt, ost and stand-alone services like fld.
3071 static int mdt_handle_common(struct ptlrpc_request *req,
3072 struct mdt_opc_slice *supported)
3075 struct mdt_thread_info *info;
3079 env = req->rq_svc_thread->t_env;
3080 LASSERT(env != NULL);
3081 LASSERT(env->le_ses != NULL);
3082 LASSERT(env->le_ctx.lc_thread == req->rq_svc_thread);
3083 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
3084 LASSERT(info != NULL);
3086 mdt_thread_info_init(req, info);
3088 rc = mdt_handle0(req, info, supported);
3090 mdt_thread_info_fini(info);
3095 * This is called from recovery code as handler of _all_ RPC types, FLD and SEQ
3098 int mdt_recovery_handle(struct ptlrpc_request *req)
3103 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
3105 rc = mdt_handle_common(req, mdt_fld_handlers);
3108 rc = mdt_handle_common(req, mdt_seq_handlers);
3111 rc = mdt_handle_common(req, mdt_regular_handlers);
3118 static int mdt_regular_handle(struct ptlrpc_request *req)
3120 return mdt_handle_common(req, mdt_regular_handlers);
3123 static int mdt_readpage_handle(struct ptlrpc_request *req)
3125 return mdt_handle_common(req, mdt_readpage_handlers);
3128 static int mdt_xmds_handle(struct ptlrpc_request *req)
3130 return mdt_handle_common(req, mdt_xmds_handlers);
3133 static int mdt_mdsc_handle(struct ptlrpc_request *req)
3135 return mdt_handle_common(req, mdt_seq_handlers);
3138 static int mdt_mdss_handle(struct ptlrpc_request *req)
3140 return mdt_handle_common(req, mdt_seq_handlers);
3143 static int mdt_dtss_handle(struct ptlrpc_request *req)
3145 return mdt_handle_common(req, mdt_seq_handlers);
3148 static int mdt_fld_handle(struct ptlrpc_request *req)
3150 return mdt_handle_common(req, mdt_fld_handlers);
3167 static int mdt_intent_getattr(enum mdt_it_code opcode,
3168 struct mdt_thread_info *info,
3169 struct ldlm_lock **,
3171 static int mdt_intent_reint(enum mdt_it_code opcode,
3172 struct mdt_thread_info *info,
3173 struct ldlm_lock **,
3176 static struct mdt_it_flavor {
3177 const struct req_format *it_fmt;
3179 int (*it_act)(enum mdt_it_code ,
3180 struct mdt_thread_info *,
3181 struct ldlm_lock **,
3184 } mdt_it_flavor[] = {
3186 .it_fmt = &RQF_LDLM_INTENT,
3187 /*.it_flags = HABEO_REFERO,*/
3189 .it_act = mdt_intent_reint,
3190 .it_reint = REINT_OPEN
3193 .it_fmt = &RQF_LDLM_INTENT,
3194 .it_flags = MUTABOR,
3195 .it_act = mdt_intent_reint,
3196 .it_reint = REINT_OPEN
3199 .it_fmt = &RQF_LDLM_INTENT,
3200 .it_flags = MUTABOR,
3201 .it_act = mdt_intent_reint,
3202 .it_reint = REINT_CREATE
3204 [MDT_IT_GETATTR] = {
3205 .it_fmt = &RQF_LDLM_INTENT_GETATTR,
3206 .it_flags = HABEO_REFERO,
3207 .it_act = mdt_intent_getattr
3209 [MDT_IT_READDIR] = {
3215 .it_fmt = &RQF_LDLM_INTENT_GETATTR,
3216 .it_flags = HABEO_REFERO,
3217 .it_act = mdt_intent_getattr
3220 .it_fmt = &RQF_LDLM_INTENT_UNLINK,
3221 .it_flags = MUTABOR,
3223 .it_reint = REINT_UNLINK
3227 .it_flags = MUTABOR,
3230 [MDT_IT_GETXATTR] = {
3236 .it_fmt = &RQF_LDLM_INTENT_GETATTR,
3237 .it_flags = HABEO_REFERO,
3238 .it_act = mdt_intent_getattr
3242 int mdt_intent_lock_replace(struct mdt_thread_info *info,
3243 struct ldlm_lock **lockp,
3244 struct ldlm_lock *new_lock,
3245 struct mdt_lock_handle *lh,
3248 struct ptlrpc_request *req = mdt_info_req(info);
3249 struct ldlm_lock *lock = *lockp;
3252 * Get new lock only for cases when possible resent did not find any
3255 if (new_lock == NULL)
3256 new_lock = ldlm_handle2lock_long(&lh->mlh_reg_lh, 0);
3258 if (new_lock == NULL && (flags & LDLM_FL_INTENT_ONLY)) {
3259 lh->mlh_reg_lh.cookie = 0;
3263 LASSERTF(new_lock != NULL,
3264 "lockh "LPX64"\n", lh->mlh_reg_lh.cookie);
3267 * If we've already given this lock to a client once, then we should
3268 * have no readers or writers. Otherwise, we should have one reader
3269 * _or_ writer ref (which will be zeroed below) before returning the
3272 if (new_lock->l_export == req->rq_export) {
3273 LASSERT(new_lock->l_readers + new_lock->l_writers == 0);
3275 LASSERT(new_lock->l_export == NULL);
3276 LASSERT(new_lock->l_readers + new_lock->l_writers == 1);
3281 if (new_lock->l_export == req->rq_export) {
3283 * Already gave this to the client, which means that we
3284 * reconstructed a reply.
3286 LASSERT(lustre_msg_get_flags(req->rq_reqmsg) &
3288 lh->mlh_reg_lh.cookie = 0;
3289 RETURN(ELDLM_LOCK_REPLACED);
3293 * Fixup the lock to be given to the client.
3295 lock_res_and_lock(new_lock);
3296 /* Zero new_lock->l_readers and new_lock->l_writers without triggering
3297 * possible blocking AST. */
3298 while (new_lock->l_readers > 0) {
3299 lu_ref_del(&new_lock->l_reference, "reader", new_lock);
3300 lu_ref_del(&new_lock->l_reference, "user", new_lock);
3301 new_lock->l_readers--;
3303 while (new_lock->l_writers > 0) {
3304 lu_ref_del(&new_lock->l_reference, "writer", new_lock);
3305 lu_ref_del(&new_lock->l_reference, "user", new_lock);
3306 new_lock->l_writers--;
3309 new_lock->l_export = class_export_lock_get(req->rq_export, new_lock);
3310 new_lock->l_blocking_ast = lock->l_blocking_ast;
3311 new_lock->l_completion_ast = lock->l_completion_ast;
3312 new_lock->l_remote_handle = lock->l_remote_handle;
3313 new_lock->l_flags &= ~LDLM_FL_LOCAL;
3315 unlock_res_and_lock(new_lock);
3317 cfs_hash_add(new_lock->l_export->exp_lock_hash,
3318 &new_lock->l_remote_handle,
3319 &new_lock->l_exp_hash);
3321 LDLM_LOCK_RELEASE(new_lock);
3322 lh->mlh_reg_lh.cookie = 0;
3324 RETURN(ELDLM_LOCK_REPLACED);
3327 static void mdt_intent_fixup_resent(struct mdt_thread_info *info,
3328 struct ldlm_lock *new_lock,
3329 struct ldlm_lock **old_lock,
3330 struct mdt_lock_handle *lh)
3332 struct ptlrpc_request *req = mdt_info_req(info);
3333 struct obd_export *exp = req->rq_export;
3334 struct lustre_handle remote_hdl;
3335 struct ldlm_request *dlmreq;
3336 struct ldlm_lock *lock;
3338 if (!(lustre_msg_get_flags(req->rq_reqmsg) & MSG_RESENT))
3341 dlmreq = req_capsule_client_get(info->mti_pill, &RMF_DLM_REQ);
3342 remote_hdl = dlmreq->lock_handle[0];
3344 lock = cfs_hash_lookup(exp->exp_lock_hash, &remote_hdl);
3346 if (lock != new_lock) {
3347 lh->mlh_reg_lh.cookie = lock->l_handle.h_cookie;
3348 lh->mlh_reg_mode = lock->l_granted_mode;
3350 LDLM_DEBUG(lock, "Restoring lock cookie");
3351 DEBUG_REQ(D_DLMTRACE, req,
3352 "restoring lock cookie "LPX64,
3353 lh->mlh_reg_lh.cookie);
3355 *old_lock = LDLM_LOCK_GET(lock);
3356 cfs_hash_put(exp->exp_lock_hash, &lock->l_exp_hash);
3360 cfs_hash_put(exp->exp_lock_hash, &lock->l_exp_hash);
3364 * If the xid matches, then we know this is a resent request, and allow
3365 * it. (It's probably an OPEN, for which we don't send a lock.
3367 if (req_xid_is_last(req))
3371 * This remote handle isn't enqueued, so we never received or processed
3372 * this request. Clear MSG_RESENT, because it can be handled like any
3373 * normal request now.
3375 lustre_msg_clear_flags(req->rq_reqmsg, MSG_RESENT);
3377 DEBUG_REQ(D_DLMTRACE, req, "no existing lock with rhandle "LPX64,
3381 static int mdt_intent_getattr(enum mdt_it_code opcode,
3382 struct mdt_thread_info *info,
3383 struct ldlm_lock **lockp,
3386 struct mdt_lock_handle *lhc = &info->mti_lh[MDT_LH_RMT];
3387 struct ldlm_lock *new_lock = NULL;
3389 struct ldlm_reply *ldlm_rep;
3390 struct ptlrpc_request *req;
3391 struct mdt_body *reqbody;
3392 struct mdt_body *repbody;
3396 reqbody = req_capsule_client_get(info->mti_pill, &RMF_MDT_BODY);
3399 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
3402 info->mti_spec.sp_ck_split = !!(reqbody->valid & OBD_MD_FLCKSPLIT);
3403 info->mti_cross_ref = !!(reqbody->valid & OBD_MD_FLCROSSREF);
3404 repbody->eadatasize = 0;
3405 repbody->aclsize = 0;
3409 child_bits = MDS_INODELOCK_LOOKUP;
3411 case MDT_IT_GETATTR:
3412 child_bits = MDS_INODELOCK_LOOKUP | MDS_INODELOCK_UPDATE;
3414 case MDT_IT_LAYOUT: {
3415 static int printed = 0;
3418 CERROR("layout lock not supported by this version\n");
3421 GOTO(out_shrink, rc = -EINVAL);
3425 CERROR("Unsupported intent (%d)\n", opcode);
3426 GOTO(out_shrink, rc = -EINVAL);
3429 rc = mdt_init_ucred(info, reqbody);
3431 GOTO(out_shrink, rc);
3433 req = info->mti_pill->rc_req;
3434 ldlm_rep = req_capsule_server_get(info->mti_pill, &RMF_DLM_REP);
3435 mdt_set_disposition(info, ldlm_rep, DISP_IT_EXECD);
3437 /* Get lock from request for possible resent case. */
3438 mdt_intent_fixup_resent(info, *lockp, &new_lock, lhc);
3440 ldlm_rep->lock_policy_res2 =
3441 mdt_getattr_name_lock(info, lhc, child_bits, ldlm_rep);
3443 if (mdt_get_disposition(ldlm_rep, DISP_LOOKUP_NEG))
3444 ldlm_rep->lock_policy_res2 = 0;
3445 if (!mdt_get_disposition(ldlm_rep, DISP_LOOKUP_POS) ||
3446 ldlm_rep->lock_policy_res2) {
3447 lhc->mlh_reg_lh.cookie = 0ull;
3448 GOTO(out_ucred, rc = ELDLM_LOCK_ABORTED);
3451 rc = mdt_intent_lock_replace(info, lockp, new_lock, lhc, flags);
3454 mdt_exit_ucred(info);
3456 mdt_client_compatibility(info);
3457 rc2 = mdt_fix_reply(info);
3463 static int mdt_intent_reint(enum mdt_it_code opcode,
3464 struct mdt_thread_info *info,
3465 struct ldlm_lock **lockp,
3468 struct mdt_lock_handle *lhc = &info->mti_lh[MDT_LH_RMT];
3469 struct ldlm_reply *rep = NULL;
3473 static const struct req_format *intent_fmts[REINT_MAX] = {
3474 [REINT_CREATE] = &RQF_LDLM_INTENT_CREATE,
3475 [REINT_OPEN] = &RQF_LDLM_INTENT_OPEN
3480 opc = mdt_reint_opcode(info, intent_fmts);
3484 if (mdt_it_flavor[opcode].it_reint != opc) {
3485 CERROR("Reint code %ld doesn't match intent: %d\n",
3487 RETURN(err_serious(-EPROTO));
3490 /* Get lock from request for possible resent case. */
3491 mdt_intent_fixup_resent(info, *lockp, NULL, lhc);
3493 rc = mdt_reint_internal(info, lhc, opc);
3495 /* Check whether the reply has been packed successfully. */
3496 if (mdt_info_req(info)->rq_repmsg != NULL)
3497 rep = req_capsule_server_get(info->mti_pill, &RMF_DLM_REP);
3499 RETURN(err_serious(-EFAULT));
3501 /* MDC expects this in any case */
3503 mdt_set_disposition(info, rep, DISP_LOOKUP_EXECD);
3505 /* Cross-ref case, the lock should be returned to the client */
3506 if (rc == -EREMOTE) {
3507 LASSERT(lustre_handle_is_used(&lhc->mlh_reg_lh));
3508 rep->lock_policy_res2 = 0;
3509 rc = mdt_intent_lock_replace(info, lockp, NULL, lhc, flags);
3512 rep->lock_policy_res2 = clear_serious(rc);
3514 if (rep->lock_policy_res2 == -ENOENT &&
3515 mdt_get_disposition(rep, DISP_LOOKUP_NEG))
3516 rep->lock_policy_res2 = 0;
3518 if (rc == -ENOTCONN || rc == -ENODEV ||
3519 rc == -EOVERFLOW) { /**< if VBR failure then return error */
3521 * If it is the disconnect error (ENODEV & ENOCONN), the error
3522 * will be returned by rq_status, and client at ptlrpc layer
3523 * will detect this, then disconnect, reconnect the import
3524 * immediately, instead of impacting the following the rpc.
3526 lhc->mlh_reg_lh.cookie = 0ull;
3530 * For other cases, the error will be returned by intent.
3531 * and client will retrieve the result from intent.
3534 * FIXME: when open lock is finished, that should be
3537 if (lustre_handle_is_used(&lhc->mlh_reg_lh)) {
3538 LASSERTF(rc == 0, "Error occurred but lock handle "
3539 "is still in use\n");
3540 rep->lock_policy_res2 = 0;
3541 rc = mdt_intent_lock_replace(info, lockp, NULL, lhc, flags);
3544 lhc->mlh_reg_lh.cookie = 0ull;
3545 RETURN(ELDLM_LOCK_ABORTED);
3550 static int mdt_intent_code(long itcode)
3558 case IT_OPEN|IT_CREAT:
3565 rc = MDT_IT_READDIR;
3568 rc = MDT_IT_GETATTR;
3580 rc = MDT_IT_GETXATTR;
3586 CERROR("Unknown intent opcode: %ld\n", itcode);
3593 static int mdt_intent_opc(long itopc, struct mdt_thread_info *info,
3594 struct ldlm_lock **lockp, int flags)
3596 struct req_capsule *pill;
3597 struct mdt_it_flavor *flv;
3602 opc = mdt_intent_code(itopc);
3606 pill = info->mti_pill;
3607 flv = &mdt_it_flavor[opc];
3609 if (flv->it_fmt != NULL)
3610 req_capsule_extend(pill, flv->it_fmt);
3612 rc = mdt_unpack_req_pack_rep(info, flv->it_flags);
3614 struct ptlrpc_request *req = mdt_info_req(info);
3615 if (flv->it_flags & MUTABOR &&
3616 req->rq_export->exp_connect_flags & OBD_CONNECT_RDONLY)
3619 if (rc == 0 && flv->it_act != NULL) {
3620 /* execute policy */
3621 rc = flv->it_act(opc, info, lockp, flags);
3628 static int mdt_intent_policy(struct ldlm_namespace *ns,
3629 struct ldlm_lock **lockp, void *req_cookie,
3630 ldlm_mode_t mode, int flags, void *data)
3632 struct mdt_thread_info *info;
3633 struct ptlrpc_request *req = req_cookie;
3634 struct ldlm_intent *it;
3635 struct req_capsule *pill;
3640 LASSERT(req != NULL);
3642 info = lu_context_key_get(&req->rq_svc_thread->t_env->le_ctx,
3644 LASSERT(info != NULL);
3645 pill = info->mti_pill;
3646 LASSERT(pill->rc_req == req);
3648 if (req->rq_reqmsg->lm_bufcount > DLM_INTENT_IT_OFF) {
3649 req_capsule_extend(pill, &RQF_LDLM_INTENT);
3650 it = req_capsule_client_get(pill, &RMF_LDLM_INTENT);
3652 rc = mdt_intent_opc(it->opc, info, lockp, flags);
3656 /* Lock without inodebits makes no sense and will oops
3657 * later in ldlm. Let's check it now to see if we have
3658 * ibits corrupted somewhere in mdt_intent_opc().
3659 * The case for client miss to set ibits has been
3660 * processed by others. */
3661 LASSERT(ergo(info->mti_dlm_req->lock_desc.l_resource.\
3662 lr_type == LDLM_IBITS,
3663 info->mti_dlm_req->lock_desc.\
3664 l_policy_data.l_inodebits.bits != 0));
3666 rc = err_serious(-EFAULT);
3668 /* No intent was provided */
3669 LASSERT(pill->rc_fmt == &RQF_LDLM_ENQUEUE);
3670 rc = req_capsule_server_pack(pill);
3672 rc = err_serious(rc);
3677 static int mdt_seq_fini(const struct lu_env *env,
3678 struct mdt_device *m)
3680 struct md_site *ms = mdt_md_site(m);
3684 if (ms->ms_server_seq) {
3685 seq_server_fini(ms->ms_server_seq, env);
3686 OBD_FREE_PTR(ms->ms_server_seq);
3687 ms->ms_server_seq = NULL;
3690 if (ms->ms_control_seq) {
3691 seq_server_fini(ms->ms_control_seq, env);
3692 OBD_FREE_PTR(ms->ms_control_seq);
3693 ms->ms_control_seq = NULL;
3696 if (ms->ms_client_seq) {
3697 seq_client_fini(ms->ms_client_seq);
3698 OBD_FREE_PTR(ms->ms_client_seq);
3699 ms->ms_client_seq = NULL;
3706 static int mdt_seq_init(const struct lu_env *env,
3708 struct mdt_device *m)
3715 ms = mdt_md_site(m);
3718 * This is sequence-controller node. Init seq-controller server on local
3721 if (ms->ms_node_id == 0) {
3722 LASSERT(ms->ms_control_seq == NULL);
3724 OBD_ALLOC_PTR(ms->ms_control_seq);
3725 if (ms->ms_control_seq == NULL)
3728 rc = seq_server_init(ms->ms_control_seq,
3729 m->mdt_bottom, uuid,
3730 LUSTRE_SEQ_CONTROLLER,
3735 GOTO(out_seq_fini, rc);
3737 OBD_ALLOC_PTR(ms->ms_client_seq);
3738 if (ms->ms_client_seq == NULL)
3739 GOTO(out_seq_fini, rc = -ENOMEM);
3741 OBD_ALLOC(prefix, MAX_OBD_NAME + 5);
3742 if (prefix == NULL) {
3743 OBD_FREE_PTR(ms->ms_client_seq);
3744 GOTO(out_seq_fini, rc = -ENOMEM);
3747 snprintf(prefix, MAX_OBD_NAME + 5, "ctl-%s",
3751 * Init seq-controller client after seq-controller server is
3752 * ready. Pass ms->ms_control_seq to it for direct talking.
3754 rc = seq_client_init(ms->ms_client_seq, NULL,
3755 LUSTRE_SEQ_METADATA, prefix,
3756 ms->ms_control_seq);
3757 OBD_FREE(prefix, MAX_OBD_NAME + 5);
3760 GOTO(out_seq_fini, rc);
3763 /* Init seq-server on local MDT */
3764 LASSERT(ms->ms_server_seq == NULL);
3766 OBD_ALLOC_PTR(ms->ms_server_seq);
3767 if (ms->ms_server_seq == NULL)
3768 GOTO(out_seq_fini, rc = -ENOMEM);
3770 rc = seq_server_init(ms->ms_server_seq,
3771 m->mdt_bottom, uuid,
3776 GOTO(out_seq_fini, rc = -ENOMEM);
3778 /* Assign seq-controller client to local seq-server. */
3779 if (ms->ms_node_id == 0) {
3780 LASSERT(ms->ms_client_seq != NULL);
3782 rc = seq_server_set_cli(ms->ms_server_seq,
3790 mdt_seq_fini(env, m);
3795 * Init client sequence manager which is used by local MDS to talk to sequence
3796 * controller on remote node.
3798 static int mdt_seq_init_cli(const struct lu_env *env,
3799 struct mdt_device *m,
3800 struct lustre_cfg *cfg)
3802 struct md_site *ms = mdt_md_site(m);
3803 struct obd_device *mdc;
3804 struct obd_uuid *uuidp, *mdcuuidp;
3805 char *uuid_str, *mdc_uuid_str;
3808 struct mdt_thread_info *info;
3809 char *p, *index_string = lustre_cfg_string(cfg, 2);
3812 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
3813 uuidp = &info->mti_u.uuid[0];
3814 mdcuuidp = &info->mti_u.uuid[1];
3816 LASSERT(index_string);
3818 index = simple_strtol(index_string, &p, 10);
3820 CERROR("Invalid index in lustre_cgf, offset 2\n");
3824 /* check if this is adding the first MDC and controller is not yet
3826 if (index != 0 || ms->ms_client_seq)
3829 uuid_str = lustre_cfg_string(cfg, 1);
3830 mdc_uuid_str = lustre_cfg_string(cfg, 4);
3831 obd_str2uuid(uuidp, uuid_str);
3832 obd_str2uuid(mdcuuidp, mdc_uuid_str);
3834 mdc = class_find_client_obd(uuidp, LUSTRE_MDC_NAME, mdcuuidp);
3836 CERROR("can't find controller MDC by uuid %s\n",
3839 } else if (!mdc->obd_set_up) {
3840 CERROR("target %s not set up\n", mdc->obd_name);
3843 LASSERT(ms->ms_control_exp);
3844 OBD_ALLOC_PTR(ms->ms_client_seq);
3845 if (ms->ms_client_seq != NULL) {
3848 OBD_ALLOC(prefix, MAX_OBD_NAME + 5);
3852 snprintf(prefix, MAX_OBD_NAME + 5, "ctl-%s",
3855 rc = seq_client_init(ms->ms_client_seq,
3857 LUSTRE_SEQ_METADATA,
3859 OBD_FREE(prefix, MAX_OBD_NAME + 5);
3866 LASSERT(ms->ms_server_seq != NULL);
3867 rc = seq_server_set_cli(ms->ms_server_seq, ms->ms_client_seq,
3874 static void mdt_seq_fini_cli(struct mdt_device *m)
3880 ms = mdt_md_site(m);
3883 if (ms->ms_server_seq)
3884 seq_server_set_cli(ms->ms_server_seq,
3887 if (ms->ms_control_exp) {
3888 class_export_put(ms->ms_control_exp);
3889 ms->ms_control_exp = NULL;
3898 static int mdt_fld_fini(const struct lu_env *env,
3899 struct mdt_device *m)
3901 struct md_site *ms = mdt_md_site(m);
3904 if (ms && ms->ms_server_fld) {
3905 fld_server_fini(ms->ms_server_fld, env);
3906 OBD_FREE_PTR(ms->ms_server_fld);
3907 ms->ms_server_fld = NULL;
3913 static int mdt_fld_init(const struct lu_env *env,
3915 struct mdt_device *m)
3921 ms = mdt_md_site(m);
3923 OBD_ALLOC_PTR(ms->ms_server_fld);
3924 if (ms->ms_server_fld == NULL)
3925 RETURN(rc = -ENOMEM);
3927 rc = fld_server_init(ms->ms_server_fld,
3928 m->mdt_bottom, uuid,
3929 env, ms->ms_node_id);
3931 OBD_FREE_PTR(ms->ms_server_fld);
3932 ms->ms_server_fld = NULL;
3939 /* device init/fini methods */
3940 static void mdt_stop_ptlrpc_service(struct mdt_device *m)
3943 if (m->mdt_regular_service != NULL) {
3944 ptlrpc_unregister_service(m->mdt_regular_service);
3945 m->mdt_regular_service = NULL;
3947 if (m->mdt_readpage_service != NULL) {
3948 ptlrpc_unregister_service(m->mdt_readpage_service);
3949 m->mdt_readpage_service = NULL;
3951 if (m->mdt_xmds_service != NULL) {
3952 ptlrpc_unregister_service(m->mdt_xmds_service);
3953 m->mdt_xmds_service = NULL;
3955 if (m->mdt_setattr_service != NULL) {
3956 ptlrpc_unregister_service(m->mdt_setattr_service);
3957 m->mdt_setattr_service = NULL;
3959 if (m->mdt_mdsc_service != NULL) {
3960 ptlrpc_unregister_service(m->mdt_mdsc_service);
3961 m->mdt_mdsc_service = NULL;
3963 if (m->mdt_mdss_service != NULL) {
3964 ptlrpc_unregister_service(m->mdt_mdss_service);
3965 m->mdt_mdss_service = NULL;
3967 if (m->mdt_dtss_service != NULL) {
3968 ptlrpc_unregister_service(m->mdt_dtss_service);
3969 m->mdt_dtss_service = NULL;
3971 if (m->mdt_fld_service != NULL) {
3972 ptlrpc_unregister_service(m->mdt_fld_service);
3973 m->mdt_fld_service = NULL;
3978 static int mdt_start_ptlrpc_service(struct mdt_device *m)
3980 static struct ptlrpc_service_conf conf;
3981 cfs_proc_dir_entry_t *procfs_entry;
3985 m->mdt_ldlm_client = &m->mdt_md_dev.md_lu_dev.ld_obd->obd_ldlm_client;
3986 ptlrpc_init_client(LDLM_CB_REQUEST_PORTAL, LDLM_CB_REPLY_PORTAL,
3987 "mdt_ldlm_client", m->mdt_ldlm_client);
3989 procfs_entry = m->mdt_md_dev.md_lu_dev.ld_obd->obd_proc_entry;
3991 conf = (typeof(conf)) {
3992 .psc_name = LUSTRE_MDT_NAME,
3993 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
3995 .bc_nbufs = MDS_NBUFS,
3996 .bc_buf_size = MDS_BUFSIZE,
3997 .bc_req_max_size = MDS_MAXREQSIZE,
3998 .bc_rep_max_size = MDS_MAXREPSIZE,
3999 .bc_req_portal = MDS_REQUEST_PORTAL,
4000 .bc_rep_portal = MDC_REPLY_PORTAL,
4003 * We'd like to have a mechanism to set this on a per-device
4004 * basis, but alas...
4007 .tc_thr_name = LUSTRE_MDT_NAME,
4008 .tc_thr_factor = MDT_THR_FACTOR,
4009 .tc_nthrs_init = MDT_NTHRS_INIT,
4010 .tc_nthrs_base = MDT_NTHRS_BASE,
4011 .tc_nthrs_max = MDT_NTHRS_MAX,
4012 .tc_nthrs_user = mds_num_threads,
4013 .tc_cpu_affinity = 1,
4014 .tc_ctx_tags = LCT_MD_THREAD,
4017 .cc_pattern = mds_num_cpts,
4020 .so_req_handler = mdt_regular_handle,
4021 .so_req_printer = target_print_req,
4022 .so_hpreq_handler = ptlrpc_hpreq_handler,
4025 m->mdt_regular_service = ptlrpc_register_service(&conf, procfs_entry);
4026 if (IS_ERR(m->mdt_regular_service)) {
4027 rc = PTR_ERR(m->mdt_regular_service);
4028 CERROR("failed to start regular mdt service: %d\n", rc);
4029 m->mdt_regular_service = NULL;
4035 * readpage service configuration. Parameters have to be adjusted,
4038 memset(&conf, 0, sizeof(conf));
4039 conf = (typeof(conf)) {
4040 .psc_name = LUSTRE_MDT_NAME "_readpage",
4041 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
4043 .bc_nbufs = MDS_NBUFS,
4044 .bc_buf_size = MDS_BUFSIZE,
4045 .bc_req_max_size = MDS_MAXREQSIZE,
4046 .bc_rep_max_size = MDS_MAXREPSIZE,
4047 .bc_req_portal = MDS_READPAGE_PORTAL,
4048 .bc_rep_portal = MDC_REPLY_PORTAL,
4051 .tc_thr_name = "mdt_rdpg",
4052 .tc_thr_factor = MDT_RDPG_THR_FACTOR,
4053 .tc_nthrs_init = MDT_RDPG_NTHRS_INIT,
4054 .tc_nthrs_base = MDT_RDPG_NTHRS_BASE,
4055 .tc_nthrs_max = MDT_RDPG_NTHRS_MAX,
4056 .tc_nthrs_user = mds_rdpg_num_threads,
4057 .tc_cpu_affinity = 1,
4058 .tc_ctx_tags = LCT_MD_THREAD,
4061 .cc_pattern = mds_rdpg_num_cpts,
4064 .so_req_handler = mdt_readpage_handle,
4065 .so_req_printer = target_print_req,
4066 .so_hpreq_handler = NULL,
4069 m->mdt_readpage_service = ptlrpc_register_service(&conf, procfs_entry);
4070 if (IS_ERR(m->mdt_readpage_service)) {
4071 rc = PTR_ERR(m->mdt_readpage_service);
4072 CERROR("failed to start readpage service: %d\n", rc);
4073 m->mdt_readpage_service = NULL;
4075 GOTO(err_mdt_svc, rc);
4079 * setattr service configuration.
4081 * XXX To keep the compatibility with old client(< 2.2), we need to
4082 * preserve this portal for a certain time, it should be removed
4083 * eventually. LU-617.
4085 memset(&conf, 0, sizeof(conf));
4086 conf = (typeof(conf)) {
4087 .psc_name = LUSTRE_MDT_NAME "_setattr",
4088 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
4090 .bc_nbufs = MDS_NBUFS,
4091 .bc_buf_size = MDS_BUFSIZE,
4092 .bc_req_max_size = MDS_MAXREQSIZE,
4093 .bc_rep_max_size = MDS_MAXREPSIZE,
4094 .bc_req_portal = MDS_SETATTR_PORTAL,
4095 .bc_rep_portal = MDC_REPLY_PORTAL,
4098 .tc_thr_name = "mdt_attr",
4099 .tc_thr_factor = MDT_SETA_THR_FACTOR,
4100 .tc_nthrs_init = MDT_SETA_NTHRS_INIT,
4101 .tc_nthrs_base = MDT_SETA_NTHRS_BASE,
4102 .tc_nthrs_max = MDT_SETA_NTHRS_MAX,
4103 .tc_nthrs_user = mds_attr_num_threads,
4104 .tc_cpu_affinity = 1,
4105 .tc_ctx_tags = LCT_MD_THREAD,
4108 .cc_pattern = mds_attr_num_cpts,
4111 .so_req_handler = mdt_regular_handle,
4112 .so_req_printer = target_print_req,
4113 .so_hpreq_handler = NULL,
4116 m->mdt_setattr_service = ptlrpc_register_service(&conf, procfs_entry);
4117 if (IS_ERR(m->mdt_setattr_service)) {
4118 rc = PTR_ERR(m->mdt_setattr_service);
4119 CERROR("failed to start setattr service: %d\n", rc);
4120 m->mdt_setattr_service = NULL;
4122 GOTO(err_mdt_svc, rc);
4126 * sequence controller service configuration
4128 memset(&conf, 0, sizeof(conf));
4129 conf = (typeof(conf)) {
4130 .psc_name = LUSTRE_MDT_NAME "_mdsc",
4131 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
4133 .bc_nbufs = MDS_NBUFS,
4134 .bc_buf_size = MDS_BUFSIZE,
4135 .bc_req_max_size = SEQ_MAXREQSIZE,
4136 .bc_rep_max_size = SEQ_MAXREPSIZE,
4137 .bc_req_portal = SEQ_CONTROLLER_PORTAL,
4138 .bc_rep_portal = MDC_REPLY_PORTAL,
4141 .tc_thr_name = "mdt_mdsc",
4142 .tc_nthrs_init = MDT_OTHR_NTHRS_INIT,
4143 .tc_nthrs_max = MDT_OTHR_NTHRS_MAX,
4144 .tc_ctx_tags = LCT_MD_THREAD,
4147 .so_req_handler = mdt_mdsc_handle,
4148 .so_req_printer = target_print_req,
4149 .so_hpreq_handler = NULL,
4152 m->mdt_mdsc_service = ptlrpc_register_service(&conf, procfs_entry);
4153 if (IS_ERR(m->mdt_mdsc_service)) {
4154 rc = PTR_ERR(m->mdt_mdsc_service);
4155 CERROR("failed to start seq controller service: %d\n", rc);
4156 m->mdt_mdsc_service = NULL;
4158 GOTO(err_mdt_svc, rc);
4162 * metadata sequence server service configuration
4164 memset(&conf, 0, sizeof(conf));
4165 conf = (typeof(conf)) {
4166 .psc_name = LUSTRE_MDT_NAME "_mdss",
4167 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
4169 .bc_nbufs = MDS_NBUFS,
4170 .bc_buf_size = MDS_BUFSIZE,
4171 .bc_req_max_size = SEQ_MAXREQSIZE,
4172 .bc_rep_max_size = SEQ_MAXREPSIZE,
4173 .bc_req_portal = SEQ_METADATA_PORTAL,
4174 .bc_rep_portal = MDC_REPLY_PORTAL,
4177 .tc_thr_name = "mdt_mdss",
4178 .tc_nthrs_init = MDT_OTHR_NTHRS_INIT,
4179 .tc_nthrs_max = MDT_OTHR_NTHRS_MAX,
4180 .tc_ctx_tags = LCT_MD_THREAD | LCT_DT_THREAD
4183 .so_req_handler = mdt_mdss_handle,
4184 .so_req_printer = target_print_req,
4185 .so_hpreq_handler = NULL,
4188 m->mdt_mdss_service = ptlrpc_register_service(&conf, procfs_entry);
4189 if (IS_ERR(m->mdt_mdss_service)) {
4190 rc = PTR_ERR(m->mdt_mdss_service);
4191 CERROR("failed to start metadata seq server service: %d\n", rc);
4192 m->mdt_mdss_service = NULL;
4194 GOTO(err_mdt_svc, rc);
4198 * Data sequence server service configuration. We want to have really
4199 * cluster-wide sequences space. This is why we start only one sequence
4200 * controller which manages space.
4202 memset(&conf, 0, sizeof(conf));
4203 conf = (typeof(conf)) {
4204 .psc_name = LUSTRE_MDT_NAME "_dtss",
4205 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
4207 .bc_nbufs = MDS_NBUFS,
4208 .bc_buf_size = MDS_BUFSIZE,
4209 .bc_req_max_size = SEQ_MAXREQSIZE,
4210 .bc_rep_max_size = SEQ_MAXREPSIZE,
4211 .bc_req_portal = SEQ_DATA_PORTAL,
4212 .bc_rep_portal = OSC_REPLY_PORTAL,
4215 .tc_thr_name = "mdt_dtss",
4216 .tc_nthrs_init = MDT_OTHR_NTHRS_INIT,
4217 .tc_nthrs_max = MDT_OTHR_NTHRS_MAX,
4218 .tc_ctx_tags = LCT_MD_THREAD | LCT_DT_THREAD
4221 .so_req_handler = mdt_dtss_handle,
4222 .so_req_printer = target_print_req,
4223 .so_hpreq_handler = NULL,
4226 m->mdt_dtss_service = ptlrpc_register_service(&conf, procfs_entry);
4227 if (IS_ERR(m->mdt_dtss_service)) {
4228 rc = PTR_ERR(m->mdt_dtss_service);
4229 CERROR("failed to start data seq server service: %d\n", rc);
4230 m->mdt_dtss_service = NULL;
4232 GOTO(err_mdt_svc, rc);
4235 /* FLD service start */
4236 memset(&conf, 0, sizeof(conf));
4237 conf = (typeof(conf)) {
4238 .psc_name = LUSTRE_MDT_NAME "_fld",
4239 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
4241 .bc_nbufs = MDS_NBUFS,
4242 .bc_buf_size = MDS_BUFSIZE,
4243 .bc_req_max_size = FLD_MAXREQSIZE,
4244 .bc_rep_max_size = FLD_MAXREPSIZE,
4245 .bc_req_portal = FLD_REQUEST_PORTAL,
4246 .bc_rep_portal = MDC_REPLY_PORTAL,
4249 .tc_thr_name = "mdt_fld",
4250 .tc_nthrs_init = MDT_OTHR_NTHRS_INIT,
4251 .tc_nthrs_max = MDT_OTHR_NTHRS_MAX,
4252 .tc_ctx_tags = LCT_DT_THREAD | LCT_MD_THREAD
4255 .so_req_handler = mdt_fld_handle,
4256 .so_req_printer = target_print_req,
4257 .so_hpreq_handler = NULL,
4260 m->mdt_fld_service = ptlrpc_register_service(&conf, procfs_entry);
4261 if (IS_ERR(m->mdt_fld_service)) {
4262 rc = PTR_ERR(m->mdt_fld_service);
4263 CERROR("failed to start fld service: %d\n", rc);
4264 m->mdt_fld_service = NULL;
4266 GOTO(err_mdt_svc, rc);
4270 * mds-mds service configuration. Separate portal is used to allow
4271 * mds-mds requests be not blocked during recovery.
4273 memset(&conf, 0, sizeof(conf));
4274 conf = (typeof(conf)) {
4275 .psc_name = LUSTRE_MDT_NAME "_mds",
4276 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
4278 .bc_nbufs = MDS_NBUFS,
4279 .bc_buf_size = MDS_BUFSIZE,
4280 .bc_req_max_size = MDS_MAXREQSIZE,
4281 .bc_rep_max_size = MDS_MAXREPSIZE,
4282 .bc_req_portal = MDS_MDS_PORTAL,
4283 .bc_rep_portal = MDC_REPLY_PORTAL,
4286 .tc_thr_name = "mdt_mds",
4287 .tc_nthrs_init = MDT_OTHR_NTHRS_INIT,
4288 .tc_nthrs_max = MDT_OTHR_NTHRS_MAX,
4289 .tc_ctx_tags = LCT_MD_THREAD,
4292 .so_req_handler = mdt_xmds_handle,
4293 .so_req_printer = target_print_req,
4294 .so_hpreq_handler = ptlrpc_hpreq_handler,
4297 m->mdt_xmds_service = ptlrpc_register_service(&conf, procfs_entry);
4298 if (IS_ERR(m->mdt_xmds_service)) {
4299 rc = PTR_ERR(m->mdt_xmds_service);
4300 CERROR("failed to start xmds service: %d\n", rc);
4301 m->mdt_xmds_service = NULL;
4303 GOTO(err_mdt_svc, rc);
4309 mdt_stop_ptlrpc_service(m);
4314 static void mdt_stack_fini(const struct lu_env *env,
4315 struct mdt_device *m, struct lu_device *top)
4317 struct obd_device *obd = mdt2obd_dev(m);
4318 struct lustre_cfg_bufs *bufs;
4319 struct lustre_cfg *lcfg;
4320 struct mdt_thread_info *info;
4324 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
4325 LASSERT(info != NULL);
4327 lu_dev_del_linkage(top->ld_site, top);
4329 bufs = &info->mti_u.bufs;
4330 /* process cleanup, pass mdt obd name to get obd umount flags */
4331 lustre_cfg_bufs_reset(bufs, obd->obd_name);
4336 lustre_cfg_bufs_set_string(bufs, 1, flags);
4337 lcfg = lustre_cfg_new(LCFG_CLEANUP, bufs);
4339 CERROR("Cannot alloc lcfg!\n");
4343 top->ld_ops->ldo_process_config(env, top, lcfg);
4344 lustre_cfg_free(lcfg);
4346 lu_stack_fini(env, top);
4347 m->mdt_child = NULL;
4348 m->mdt_bottom = NULL;
4351 static struct lu_device *mdt_layer_setup(struct lu_env *env,
4352 const char *typename,
4353 struct lu_device *child,
4354 struct lustre_cfg *cfg)
4356 const char *dev = lustre_cfg_string(cfg, 0);
4357 struct obd_type *type;
4358 struct lu_device_type *ldt;
4359 struct lu_device *d;
4364 type = class_get_type(typename);
4366 CERROR("Unknown type: '%s'\n", typename);
4367 GOTO(out, rc = -ENODEV);
4370 rc = lu_env_refill((struct lu_env *)env);
4372 CERROR("Failure to refill session: '%d'\n", rc);
4378 CERROR("type: '%s'\n", typename);
4379 GOTO(out_type, rc = -EINVAL);
4382 ldt->ldt_obd_type = type;
4383 d = ldt->ldt_ops->ldto_device_alloc(env, ldt, cfg);
4385 CERROR("Cannot allocate device: '%s'\n", typename);
4386 GOTO(out_type, rc = -ENODEV);
4389 LASSERT(child->ld_site);
4390 d->ld_site = child->ld_site;
4393 rc = ldt->ldt_ops->ldto_device_init(env, d, dev, child);
4395 CERROR("can't init device '%s', rc %d\n", typename, rc);
4396 GOTO(out_alloc, rc);
4399 lu_ref_add(&d->ld_reference, "lu-stack", &lu_site_init);
4401 lu_dev_add_linkage(d->ld_site, d);
4404 ldt->ldt_ops->ldto_device_free(env, d);
4407 class_put_type(type);
4412 static int mdt_stack_init(struct lu_env *env,
4413 struct mdt_device *m,
4414 struct lustre_cfg *cfg,
4415 struct lustre_mount_info *lmi)
4417 struct lu_device *d = &m->mdt_md_dev.md_lu_dev;
4418 struct lu_device *tmp;
4419 struct md_device *md;
4420 struct lu_device *child_lu_dev;
4424 /* init the stack */
4425 tmp = mdt_layer_setup(env, LUSTRE_OSD_NAME, d, cfg);
4427 RETURN(PTR_ERR(tmp));
4429 m->mdt_bottom = lu2dt_dev(tmp);
4431 tmp = mdt_layer_setup(env, LUSTRE_MDD_NAME, d, cfg);
4433 GOTO(out, rc = PTR_ERR(tmp));
4438 tmp = mdt_layer_setup(env, LUSTRE_CMM_NAME, d, cfg);
4440 GOTO(out, rc = PTR_ERR(tmp));
4443 /*set mdd upcall device*/
4444 md_upcall_dev_set(md, lu2md_dev(d));
4447 /*set cmm upcall device*/
4448 md_upcall_dev_set(md, &m->mdt_md_dev);
4450 m->mdt_child = lu2md_dev(d);
4452 /* process setup config */
4453 tmp = &m->mdt_md_dev.md_lu_dev;
4454 rc = tmp->ld_ops->ldo_process_config(env, tmp, cfg);
4458 /* initialize local objects */
4459 child_lu_dev = &m->mdt_child->md_lu_dev;
4461 rc = child_lu_dev->ld_ops->ldo_prepare(env,
4462 &m->mdt_md_dev.md_lu_dev,
4465 /* fini from last known good lu_device */
4467 mdt_stack_fini(env, m, d);
4473 * setup CONFIG_ORIG context, used to access local config log.
4474 * this may need to be rewrite as part of llog rewrite for lu-api.
4476 static int mdt_obd_llog_setup(struct obd_device *obd,
4477 struct lustre_sb_info *lsi)
4481 LASSERT(obd->obd_fsops == NULL);
4483 obd->obd_fsops = fsfilt_get_ops(MT_STR(lsi->lsi_ldd));
4484 if (IS_ERR(obd->obd_fsops))
4485 return PTR_ERR(obd->obd_fsops);
4487 rc = fsfilt_setup(obd, lsi->lsi_srv_mnt->mnt_sb);
4489 fsfilt_put_ops(obd->obd_fsops);
4493 OBD_SET_CTXT_MAGIC(&obd->obd_lvfs_ctxt);
4494 obd->obd_lvfs_ctxt.pwdmnt = lsi->lsi_srv_mnt;
4495 obd->obd_lvfs_ctxt.pwd = lsi->lsi_srv_mnt->mnt_root;
4496 obd->obd_lvfs_ctxt.fs = get_ds();
4498 rc = llog_setup(obd, &obd->obd_olg, LLOG_CONFIG_ORIG_CTXT, obd,
4499 0, NULL, &llog_lvfs_ops);
4501 CERROR("llog_setup() failed: %d\n", rc);
4502 fsfilt_put_ops(obd->obd_fsops);
4508 static void mdt_obd_llog_cleanup(struct obd_device *obd)
4510 struct llog_ctxt *ctxt;
4512 ctxt = llog_get_context(obd, LLOG_CONFIG_ORIG_CTXT);
4516 if (obd->obd_fsops) {
4517 fsfilt_put_ops(obd->obd_fsops);
4518 obd->obd_fsops = NULL;
4522 static void mdt_fini(const struct lu_env *env, struct mdt_device *m)
4524 struct md_device *next = m->mdt_child;
4525 struct lu_device *d = &m->mdt_md_dev.md_lu_dev;
4526 struct lu_site *ls = d->ld_site;
4527 struct obd_device *obd = mdt2obd_dev(m);
4530 target_recovery_fini(obd);
4532 ping_evictor_stop();
4534 mdt_stop_ptlrpc_service(m);
4535 mdt_llog_ctxt_unclone(env, m, LLOG_CHANGELOG_ORIG_CTXT);
4536 mdt_obd_llog_cleanup(obd);
4537 obd_exports_barrier(obd);
4538 obd_zombie_barrier();
4542 #ifdef HAVE_QUOTA_SUPPORT
4543 next->md_ops->mdo_quota.mqo_cleanup(env, next);
4545 lut_fini(env, &m->mdt_lut);
4546 mdt_fs_cleanup(env, m);
4547 upcall_cache_cleanup(m->mdt_identity_cache);
4548 m->mdt_identity_cache = NULL;
4550 if (m->mdt_namespace != NULL) {
4551 ldlm_namespace_free(m->mdt_namespace, NULL,
4552 d->ld_obd->obd_force);
4553 d->ld_obd->obd_namespace = m->mdt_namespace = NULL;
4556 cfs_free_nidlist(&m->mdt_nosquash_nids);
4557 if (m->mdt_nosquash_str) {
4558 OBD_FREE(m->mdt_nosquash_str, m->mdt_nosquash_strlen);
4559 m->mdt_nosquash_str = NULL;
4560 m->mdt_nosquash_strlen = 0;
4563 mdt_seq_fini(env, m);
4564 mdt_seq_fini_cli(m);
4565 mdt_fld_fini(env, m);
4566 sptlrpc_rule_set_free(&m->mdt_sptlrpc_rset);
4568 next->md_ops->mdo_init_capa_ctxt(env, next, 0, 0, 0, NULL);
4569 cfs_timer_disarm(&m->mdt_ck_timer);
4570 mdt_ck_thread_stop(m);
4575 mdt_stack_fini(env, m, md2lu_dev(m->mdt_child));
4578 struct md_site *mite;
4581 mite = lu_site2md(ls);
4585 LASSERT(cfs_atomic_read(&d->ld_ref) == 0);
4590 static int mdt_adapt_sptlrpc_conf(struct obd_device *obd, int initial)
4592 struct mdt_device *m = mdt_dev(obd->obd_lu_dev);
4593 struct sptlrpc_rule_set tmp_rset;
4596 sptlrpc_rule_set_init(&tmp_rset);
4597 rc = sptlrpc_conf_target_get_rules(obd, &tmp_rset, initial);
4599 CERROR("mdt %s: failed get sptlrpc rules: %d\n",
4604 sptlrpc_target_update_exp_flavor(obd, &tmp_rset);
4606 cfs_write_lock(&m->mdt_sptlrpc_lock);
4607 sptlrpc_rule_set_free(&m->mdt_sptlrpc_rset);
4608 m->mdt_sptlrpc_rset = tmp_rset;
4609 cfs_write_unlock(&m->mdt_sptlrpc_lock);
4614 int mdt_postrecov(const struct lu_env *, struct mdt_device *);
4616 static int mdt_init0(const struct lu_env *env, struct mdt_device *m,
4617 struct lu_device_type *ldt, struct lustre_cfg *cfg)
4619 struct mdt_thread_info *info;
4620 struct obd_device *obd;
4621 const char *dev = lustre_cfg_string(cfg, 0);
4622 const char *num = lustre_cfg_string(cfg, 2);
4623 struct lustre_mount_info *lmi = NULL;
4624 struct lustre_sb_info *lsi;
4625 struct lustre_disk_data *ldd;
4627 struct md_site *mite;
4628 const char *identity_upcall = "NONE";
4629 struct md_device *next;
4635 md_device_init(&m->mdt_md_dev, ldt);
4637 * Environment (env) might be missing mdt_thread_key values at that
4638 * point, if device is allocated when mdt_thread_key is in QUIESCENT
4641 * Usually device allocation path doesn't use module key values, but
4642 * mdt has to do a lot of work here, so allocate key value.
4644 rc = lu_env_refill((struct lu_env *)env);
4648 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
4649 LASSERT(info != NULL);
4651 obd = class_name2obd(dev);
4652 LASSERT(obd != NULL);
4654 m->mdt_max_mdsize = MAX_MD_SIZE; /* 4 stripes */
4655 m->mdt_max_cookiesize = sizeof(struct llog_cookie);
4657 m->mdt_som_conf = 0;
4659 m->mdt_opts.mo_cos = MDT_COS_DEFAULT;
4660 lmi = server_get_mount_2(dev);
4662 CERROR("Cannot get mount info for %s!\n", dev);
4665 lsi = s2lsi(lmi->lmi_sb);
4666 /* CMD is supported only in IAM mode */
4669 node_id = simple_strtol(num, NULL, 10);
4670 if (!(ldd->ldd_flags & LDD_F_IAM_DIR) && node_id) {
4671 CERROR("CMD Operation not allowed in IOP mode\n");
4672 GOTO(err_lmi, rc = -EINVAL);
4675 obd->u.obt.obt_magic = OBT_MAGIC;
4678 cfs_rwlock_init(&m->mdt_sptlrpc_lock);
4679 sptlrpc_rule_set_init(&m->mdt_sptlrpc_rset);
4681 cfs_spin_lock_init(&m->mdt_ioepoch_lock);
4682 m->mdt_opts.mo_compat_resname = 0;
4683 m->mdt_opts.mo_mds_capa = 1;
4684 m->mdt_opts.mo_oss_capa = 1;
4685 m->mdt_capa_timeout = CAPA_TIMEOUT;
4686 m->mdt_capa_alg = CAPA_HMAC_ALG_SHA1;
4687 m->mdt_ck_timeout = CAPA_KEY_TIMEOUT;
4688 m->mdt_squash_uid = 0;
4689 m->mdt_squash_gid = 0;
4690 CFS_INIT_LIST_HEAD(&m->mdt_nosquash_nids);
4691 m->mdt_nosquash_str = NULL;
4692 m->mdt_nosquash_strlen = 0;
4693 cfs_init_rwsem(&m->mdt_squash_sem);
4695 OBD_ALLOC_PTR(mite);
4697 GOTO(err_lmi, rc = -ENOMEM);
4701 m->mdt_md_dev.md_lu_dev.ld_ops = &mdt_lu_ops;
4702 m->mdt_md_dev.md_lu_dev.ld_obd = obd;
4703 /* set this lu_device to obd, because error handling need it */
4704 obd->obd_lu_dev = &m->mdt_md_dev.md_lu_dev;
4706 rc = lu_site_init(s, &m->mdt_md_dev.md_lu_dev);
4708 CERROR("Can't init lu_site, rc %d\n", rc);
4709 GOTO(err_free_site, rc);
4712 /* set server index */
4713 lu_site2md(s)->ms_node_id = node_id;
4715 /* failover is the default
4716 * FIXME: we do not failout mds0/mgs, which may cause some problems.
4717 * assumed whose ms_node_id == 0 XXX
4719 obd->obd_replayable = 1;
4720 /* No connection accepted until configurations will finish */
4721 obd->obd_no_conn = 1;
4723 if (cfg->lcfg_bufcount > 4 && LUSTRE_CFG_BUFLEN(cfg, 4) > 0) {
4724 char *str = lustre_cfg_string(cfg, 4);
4725 if (strchr(str, 'n')) {
4726 CWARN("%s: recovery disabled\n", obd->obd_name);
4727 obd->obd_replayable = 0;
4731 /* init the stack */
4732 rc = mdt_stack_init((struct lu_env *)env, m, cfg, lmi);
4734 CERROR("Can't init device stack, rc %d\n", rc);
4735 GOTO(err_lu_site, rc);
4738 rc = lut_init(env, &m->mdt_lut, obd, m->mdt_bottom);
4740 GOTO(err_fini_stack, rc);
4742 rc = mdt_fld_init(env, obd->obd_name, m);
4746 rc = mdt_seq_init(env, obd->obd_name, m);
4748 GOTO(err_fini_fld, rc);
4750 snprintf(info->mti_u.ns_name, sizeof info->mti_u.ns_name,
4751 LUSTRE_MDT_NAME"-%p", m);
4752 m->mdt_namespace = ldlm_namespace_new(obd, info->mti_u.ns_name,
4753 LDLM_NAMESPACE_SERVER,
4754 LDLM_NAMESPACE_GREEDY,
4756 if (m->mdt_namespace == NULL)
4757 GOTO(err_fini_seq, rc = -ENOMEM);
4759 ldlm_register_intent(m->mdt_namespace, mdt_intent_policy);
4760 /* set obd_namespace for compatibility with old code */
4761 obd->obd_namespace = m->mdt_namespace;
4763 cfs_timer_init(&m->mdt_ck_timer, mdt_ck_timer_callback, m);
4765 rc = mdt_ck_thread_start(m);
4767 GOTO(err_free_ns, rc);
4769 rc = mdt_fs_setup(env, m, obd, lsi);
4773 rc = mdt_obd_llog_setup(obd, lsi);
4775 GOTO(err_fs_cleanup, rc);
4777 rc = mdt_llog_ctxt_clone(env, m, LLOG_CHANGELOG_ORIG_CTXT);
4779 GOTO(err_llog_cleanup, rc);
4781 mdt_adapt_sptlrpc_conf(obd, 1);
4783 next = m->mdt_child;
4784 #ifdef HAVE_QUOTA_SUPPORT
4785 rc = next->md_ops->mdo_quota.mqo_setup(env, next, lmi->lmi_mnt);
4787 GOTO(err_llog_cleanup, rc);
4790 server_put_mount_2(dev, lmi->lmi_mnt);
4793 rc = next->md_ops->mdo_iocontrol(env, next, OBD_IOC_GET_MNTOPT, 0,
4796 GOTO(err_quota, rc);
4798 if (mntopts & MNTOPT_USERXATTR)
4799 m->mdt_opts.mo_user_xattr = 1;
4801 m->mdt_opts.mo_user_xattr = 0;
4803 if (mntopts & MNTOPT_ACL)
4804 m->mdt_opts.mo_acl = 1;
4806 m->mdt_opts.mo_acl = 0;
4808 /* XXX: to support suppgid for ACL, we enable identity_upcall
4809 * by default, otherwise, maybe got unexpected -EACCESS. */
4810 if (m->mdt_opts.mo_acl)
4811 identity_upcall = MDT_IDENTITY_UPCALL_PATH;
4813 m->mdt_identity_cache = upcall_cache_init(obd->obd_name,identity_upcall,
4814 &mdt_identity_upcall_cache_ops);
4815 if (IS_ERR(m->mdt_identity_cache)) {
4816 rc = PTR_ERR(m->mdt_identity_cache);
4817 m->mdt_identity_cache = NULL;
4818 GOTO(err_quota, rc);
4821 target_recovery_init(&m->mdt_lut, mdt_recovery_handle);
4823 rc = mdt_procfs_init(m, dev);
4825 CERROR("Can't init MDT lprocfs, rc %d\n", rc);
4826 GOTO(err_recovery, rc);
4829 rc = mdt_start_ptlrpc_service(m);
4831 GOTO(err_procfs, rc);
4833 ping_evictor_start();
4835 rc = lu_site_init_finish(s);
4837 GOTO(err_stop_service, rc);
4839 if (obd->obd_recovering == 0)
4840 mdt_postrecov(env, m);
4842 mdt_init_capa_ctxt(env, m);
4844 /* Reduce the initial timeout on an MDS because it doesn't need such
4845 * a long timeout as an OST does. Adaptive timeouts will adjust this
4846 * value appropriately. */
4847 if (ldlm_timeout == LDLM_TIMEOUT_DEFAULT)
4848 ldlm_timeout = MDS_LDLM_TIMEOUT_DEFAULT;
4853 ping_evictor_stop();
4854 mdt_stop_ptlrpc_service(m);
4858 target_recovery_fini(obd);
4859 upcall_cache_cleanup(m->mdt_identity_cache);
4860 m->mdt_identity_cache = NULL;
4862 #ifdef HAVE_QUOTA_SUPPORT
4863 next->md_ops->mdo_quota.mqo_cleanup(env, next);
4866 mdt_llog_ctxt_unclone(env, m, LLOG_CHANGELOG_ORIG_CTXT);
4867 mdt_obd_llog_cleanup(obd);
4869 mdt_fs_cleanup(env, m);
4871 cfs_timer_disarm(&m->mdt_ck_timer);
4872 mdt_ck_thread_stop(m);
4874 ldlm_namespace_free(m->mdt_namespace, NULL, 0);
4875 obd->obd_namespace = m->mdt_namespace = NULL;
4877 mdt_seq_fini(env, m);
4879 mdt_fld_fini(env, m);
4881 lut_fini(env, &m->mdt_lut);
4883 mdt_stack_fini(env, m, md2lu_dev(m->mdt_child));
4890 server_put_mount_2(dev, lmi->lmi_mnt);
4894 /* For interoperability between 1.8 and 2.0. */
4895 #define CFG_GROUP_UPCALL "mdt.group_upcall"
4896 #define CFG_QUOTA_TYPE_OLD "mdt.quota_type"
4897 #define CFG_QUOTA_TYPE_NEW "mdd.quota_type"
4898 #define CFG_ROOT_SQUASH_OLD "mdt.rootsquash"
4899 #define CFG_ROOT_SQUASH_NEW "mdt.root_squash"
4900 #define CFG_NOSQUASH_NID_OLD "mdt.nosquash_nid"
4901 #define CFG_NOSQUASH_NID_NEW "mdt.nosquash_nids"
4903 /* used by MGS to process specific configurations */
4904 static int mdt_process_config(const struct lu_env *env,
4905 struct lu_device *d, struct lustre_cfg *cfg)
4907 struct mdt_device *m = mdt_dev(d);
4908 struct md_device *md_next = m->mdt_child;
4909 struct lu_device *next = md2lu_dev(md_next);
4913 switch (cfg->lcfg_command) {
4915 struct lprocfs_static_vars lvars;
4916 struct obd_device *obd = d->ld_obd;
4918 /* For interoperability between 1.8 and 2.0. */
4919 struct lustre_cfg *old_cfg = NULL;
4921 char *new_name = NULL;
4923 param = lustre_cfg_string(cfg, 1);
4924 if (param == NULL) {
4925 CERROR("param is empty\n");
4930 /* Skip old "mdt.group_upcall" param. */
4931 if (strncmp(param, CFG_GROUP_UPCALL,
4932 strlen(CFG_GROUP_UPCALL)) == 0) {
4933 CWARN("For 1.8 interoperability, skip this %s."
4934 " It is obsolete.\n", CFG_GROUP_UPCALL);
4938 /* Rename old "mdt.quota_type" to "mdd.quota_type". */
4939 if (strncmp(param, CFG_QUOTA_TYPE_OLD,
4940 strlen(CFG_QUOTA_TYPE_OLD)) == 0) {
4941 CWARN("Found old param %s, changed it to %s.\n",
4942 CFG_QUOTA_TYPE_OLD, CFG_QUOTA_TYPE_NEW);
4943 new_name = CFG_QUOTA_TYPE_NEW;
4945 } else if (strncmp(param, CFG_ROOT_SQUASH_OLD,
4946 strlen(CFG_ROOT_SQUASH_OLD)) == 0) {
4947 /* Rename old "mdt.rootsquash" to "mdt.root_squash". */
4948 CWARN("Found old param %s, changed it to %s.\n",
4949 CFG_ROOT_SQUASH_OLD, CFG_ROOT_SQUASH_NEW);
4950 new_name = CFG_ROOT_SQUASH_NEW;
4952 } else if (strncmp(param, CFG_NOSQUASH_NID_OLD,
4953 strlen(CFG_NOSQUASH_NID_OLD)) == 0 &&
4954 param[strlen(CFG_NOSQUASH_NID_OLD)] != 's') {
4956 * Rename old "mdt.nosquash_nid" to
4957 * "mdt.nosquash_nids".
4959 CWARN("Found old param %s, changed it to %s.\n",
4960 CFG_NOSQUASH_NID_OLD, CFG_NOSQUASH_NID_NEW);
4961 new_name = CFG_NOSQUASH_NID_NEW;
4964 if (new_name != NULL) {
4966 cfg = lustre_cfg_rename(old_cfg, new_name);
4973 lprocfs_mdt_init_vars(&lvars);
4974 rc = class_process_proc_param(PARAM_MDT, lvars.obd_vars,
4976 if (rc > 0 || rc == -ENOSYS)
4977 /* we don't understand; pass it on */
4978 rc = next->ld_ops->ldo_process_config(env, next, cfg);
4980 if (old_cfg != NULL)
4981 lustre_cfg_free(cfg);
4987 * Add mdc hook to get first MDT uuid and connect it to
4988 * ls->controller to use for seq manager.
4990 rc = next->ld_ops->ldo_process_config(env, next, cfg);
4992 CERROR("Can't add mdc, rc %d\n", rc);
4994 rc = mdt_seq_init_cli(env, mdt_dev(d), cfg);
4997 /* others are passed further */
4998 rc = next->ld_ops->ldo_process_config(env, next, cfg);
5004 static struct lu_object *mdt_object_alloc(const struct lu_env *env,
5005 const struct lu_object_header *hdr,
5006 struct lu_device *d)
5008 struct mdt_object *mo;
5014 struct lu_object *o;
5015 struct lu_object_header *h;
5017 o = &mo->mot_obj.mo_lu;
5018 h = &mo->mot_header;
5019 lu_object_header_init(h);
5020 lu_object_init(o, h, d);
5021 lu_object_add_top(h, o);
5022 o->lo_ops = &mdt_obj_ops;
5023 cfs_mutex_init(&mo->mot_ioepoch_mutex);
5024 cfs_mutex_init(&mo->mot_lov_mutex);
5030 static int mdt_object_init(const struct lu_env *env, struct lu_object *o,
5031 const struct lu_object_conf *unused)
5033 struct mdt_device *d = mdt_dev(o->lo_dev);
5034 struct lu_device *under;
5035 struct lu_object *below;
5039 CDEBUG(D_INFO, "object init, fid = "DFID"\n",
5040 PFID(lu_object_fid(o)));
5042 under = &d->mdt_child->md_lu_dev;
5043 below = under->ld_ops->ldo_object_alloc(env, o->lo_header, under);
5044 if (below != NULL) {
5045 lu_object_add(o, below);
5052 static void mdt_object_free(const struct lu_env *env, struct lu_object *o)
5054 struct mdt_object *mo = mdt_obj(o);
5055 struct lu_object_header *h;
5059 CDEBUG(D_INFO, "object free, fid = "DFID"\n",
5060 PFID(lu_object_fid(o)));
5063 lu_object_header_fini(h);
5068 static int mdt_object_print(const struct lu_env *env, void *cookie,
5069 lu_printer_t p, const struct lu_object *o)
5071 struct mdt_object *mdto = mdt_obj((struct lu_object *)o);
5072 return (*p)(env, cookie, LUSTRE_MDT_NAME"-object@%p(ioepoch="LPU64" "
5073 "flags="LPX64", epochcount=%d, writecount=%d)",
5074 mdto, mdto->mot_ioepoch, mdto->mot_flags,
5075 mdto->mot_ioepoch_count, mdto->mot_writecount);
5078 static const struct lu_device_operations mdt_lu_ops = {
5079 .ldo_object_alloc = mdt_object_alloc,
5080 .ldo_process_config = mdt_process_config,
5083 static const struct lu_object_operations mdt_obj_ops = {
5084 .loo_object_init = mdt_object_init,
5085 .loo_object_free = mdt_object_free,
5086 .loo_object_print = mdt_object_print
5089 static int mdt_obd_set_info_async(const struct lu_env *env,
5090 struct obd_export *exp,
5091 __u32 keylen, void *key,
5092 __u32 vallen, void *val,
5093 struct ptlrpc_request_set *set)
5095 struct obd_device *obd = exp->exp_obd;
5101 if (KEY_IS(KEY_SPTLRPC_CONF)) {
5102 rc = mdt_adapt_sptlrpc_conf(obd, 0);
5109 /* mds_connect_internal */
5110 static int mdt_connect_internal(struct obd_export *exp,
5111 struct mdt_device *mdt,
5112 struct obd_connect_data *data)
5115 data->ocd_connect_flags &= MDT_CONNECT_SUPPORTED;
5116 data->ocd_ibits_known &= MDS_INODELOCK_FULL;
5118 /* If no known bits (which should not happen, probably,
5119 as everybody should support LOOKUP and UPDATE bits at least)
5120 revert to compat mode with plain locks. */
5121 if (!data->ocd_ibits_known &&
5122 data->ocd_connect_flags & OBD_CONNECT_IBITS)
5123 data->ocd_connect_flags &= ~OBD_CONNECT_IBITS;
5125 if (!mdt->mdt_opts.mo_acl)
5126 data->ocd_connect_flags &= ~OBD_CONNECT_ACL;
5128 if (!mdt->mdt_opts.mo_user_xattr)
5129 data->ocd_connect_flags &= ~OBD_CONNECT_XATTR;
5131 if (!mdt->mdt_som_conf)
5132 data->ocd_connect_flags &= ~OBD_CONNECT_SOM;
5134 if (data->ocd_connect_flags & OBD_CONNECT_BRW_SIZE) {
5135 data->ocd_brw_size = min(data->ocd_brw_size,
5136 (__u32)(PTLRPC_MAX_BRW_PAGES << CFS_PAGE_SHIFT));
5137 if (data->ocd_brw_size == 0) {
5138 CERROR("%s: cli %s/%p ocd_connect_flags: "LPX64
5139 " ocd_version: %x ocd_grant: %d "
5140 "ocd_index: %u ocd_brw_size is "
5141 "unexpectedly zero, network data "
5142 "corruption? Refusing connection of this"
5144 exp->exp_obd->obd_name,
5145 exp->exp_client_uuid.uuid,
5146 exp, data->ocd_connect_flags, data->ocd_version,
5147 data->ocd_grant, data->ocd_index);
5152 cfs_spin_lock(&exp->exp_lock);
5153 exp->exp_connect_flags = data->ocd_connect_flags;
5154 cfs_spin_unlock(&exp->exp_lock);
5155 data->ocd_version = LUSTRE_VERSION_CODE;
5156 exp->exp_mdt_data.med_ibits_known = data->ocd_ibits_known;
5160 if (mdt->mdt_opts.mo_acl &&
5161 ((exp->exp_connect_flags & OBD_CONNECT_ACL) == 0)) {
5162 CWARN("%s: MDS requires ACL support but client does not\n",
5163 mdt->mdt_md_dev.md_lu_dev.ld_obd->obd_name);
5168 if ((exp->exp_connect_flags & OBD_CONNECT_FID) == 0) {
5169 CWARN("%s: MDS requires FID support, but client not\n",
5170 mdt->mdt_md_dev.md_lu_dev.ld_obd->obd_name);
5174 if (mdt->mdt_som_conf && !exp_connect_som(exp) &&
5175 !(exp->exp_connect_flags & OBD_CONNECT_MDS_MDS)) {
5176 CWARN("%s: MDS has SOM enabled, but client does not support "
5177 "it\n", mdt->mdt_md_dev.md_lu_dev.ld_obd->obd_name);
5184 static int mdt_connect_check_sptlrpc(struct mdt_device *mdt,
5185 struct obd_export *exp,
5186 struct ptlrpc_request *req)
5188 struct sptlrpc_flavor flvr;
5191 if (exp->exp_flvr.sf_rpc == SPTLRPC_FLVR_INVALID) {
5192 cfs_read_lock(&mdt->mdt_sptlrpc_lock);
5193 sptlrpc_target_choose_flavor(&mdt->mdt_sptlrpc_rset,
5197 cfs_read_unlock(&mdt->mdt_sptlrpc_lock);
5199 cfs_spin_lock(&exp->exp_lock);
5201 exp->exp_sp_peer = req->rq_sp_from;
5202 exp->exp_flvr = flvr;
5204 if (exp->exp_flvr.sf_rpc != SPTLRPC_FLVR_ANY &&
5205 exp->exp_flvr.sf_rpc != req->rq_flvr.sf_rpc) {
5206 CERROR("unauthorized rpc flavor %x from %s, "
5207 "expect %x\n", req->rq_flvr.sf_rpc,
5208 libcfs_nid2str(req->rq_peer.nid),
5209 exp->exp_flvr.sf_rpc);
5213 cfs_spin_unlock(&exp->exp_lock);
5215 if (exp->exp_sp_peer != req->rq_sp_from) {
5216 CERROR("RPC source %s doesn't match %s\n",
5217 sptlrpc_part2name(req->rq_sp_from),
5218 sptlrpc_part2name(exp->exp_sp_peer));
5221 rc = sptlrpc_target_export_check(exp, req);
5228 /* mds_connect copy */
5229 static int mdt_obd_connect(const struct lu_env *env,
5230 struct obd_export **exp, struct obd_device *obd,
5231 struct obd_uuid *cluuid,
5232 struct obd_connect_data *data,
5235 struct mdt_thread_info *info;
5236 struct obd_export *lexp;
5237 struct lustre_handle conn = { 0 };
5238 struct mdt_device *mdt;
5239 struct ptlrpc_request *req;
5243 LASSERT(env != NULL);
5244 if (!exp || !obd || !cluuid)
5247 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
5248 req = info->mti_pill->rc_req;
5249 mdt = mdt_dev(obd->obd_lu_dev);
5251 rc = class_connect(&conn, obd, cluuid);
5255 lexp = class_conn2export(&conn);
5256 LASSERT(lexp != NULL);
5258 rc = mdt_connect_check_sptlrpc(mdt, lexp, req);
5262 if (OBD_FAIL_CHECK(OBD_FAIL_TGT_RCVG_FLAG))
5263 lustre_msg_add_op_flags(req->rq_repmsg, MSG_CONNECT_RECOVERING);
5265 rc = mdt_connect_internal(lexp, mdt, data);
5267 struct lsd_client_data *lcd = lexp->exp_target_data.ted_lcd;
5270 info->mti_exp = lexp;
5271 memcpy(lcd->lcd_uuid, cluuid, sizeof lcd->lcd_uuid);
5272 rc = lut_client_new(env, lexp);
5274 mdt_export_stats_init(obd, lexp, localdata);
5279 class_disconnect(lexp);
5288 static int mdt_obd_reconnect(const struct lu_env *env,
5289 struct obd_export *exp, struct obd_device *obd,
5290 struct obd_uuid *cluuid,
5291 struct obd_connect_data *data,
5294 struct mdt_thread_info *info;
5295 struct mdt_device *mdt;
5296 struct ptlrpc_request *req;
5300 if (exp == NULL || obd == NULL || cluuid == NULL)
5303 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
5304 req = info->mti_pill->rc_req;
5305 mdt = mdt_dev(obd->obd_lu_dev);
5307 rc = mdt_connect_check_sptlrpc(mdt, exp, req);
5311 rc = mdt_connect_internal(exp, mdt_dev(obd->obd_lu_dev), data);
5313 mdt_export_stats_init(obd, exp, localdata);
5318 static int mdt_export_cleanup(struct obd_export *exp)
5320 struct mdt_export_data *med = &exp->exp_mdt_data;
5321 struct obd_device *obd = exp->exp_obd;
5322 struct mdt_device *mdt;
5323 struct mdt_thread_info *info;
5325 CFS_LIST_HEAD(closing_list);
5326 struct mdt_file_data *mfd, *n;
5330 cfs_spin_lock(&med->med_open_lock);
5331 while (!cfs_list_empty(&med->med_open_head)) {
5332 cfs_list_t *tmp = med->med_open_head.next;
5333 mfd = cfs_list_entry(tmp, struct mdt_file_data, mfd_list);
5335 /* Remove mfd handle so it can't be found again.
5336 * We are consuming the mfd_list reference here. */
5337 class_handle_unhash(&mfd->mfd_handle);
5338 cfs_list_move_tail(&mfd->mfd_list, &closing_list);
5340 cfs_spin_unlock(&med->med_open_lock);
5341 mdt = mdt_dev(obd->obd_lu_dev);
5342 LASSERT(mdt != NULL);
5344 rc = lu_env_init(&env, LCT_MD_THREAD);
5348 info = lu_context_key_get(&env.le_ctx, &mdt_thread_key);
5349 LASSERT(info != NULL);
5350 memset(info, 0, sizeof *info);
5351 info->mti_env = &env;
5352 info->mti_mdt = mdt;
5353 info->mti_exp = exp;
5355 if (!cfs_list_empty(&closing_list)) {
5356 struct md_attr *ma = &info->mti_attr;
5360 lmm_size = mdt->mdt_max_mdsize;
5361 OBD_ALLOC_LARGE(ma->ma_lmm, lmm_size);
5362 if (ma->ma_lmm == NULL)
5363 GOTO(out_lmm, rc = -ENOMEM);
5365 cookie_size = mdt->mdt_max_cookiesize;
5366 OBD_ALLOC_LARGE(ma->ma_cookie, cookie_size);
5367 if (ma->ma_cookie == NULL)
5368 GOTO(out_cookie, rc = -ENOMEM);
5370 /* Close any open files (which may also cause orphan unlinking). */
5371 cfs_list_for_each_entry_safe(mfd, n, &closing_list, mfd_list) {
5372 cfs_list_del_init(&mfd->mfd_list);
5373 memset(&ma->ma_attr, 0, sizeof(ma->ma_attr));
5374 ma->ma_lmm_size = lmm_size;
5375 ma->ma_cookie_size = cookie_size;
5377 /* It is not for setattr, just tell MDD to send
5378 * DESTROY RPC to OSS if needed */
5379 ma->ma_valid = MA_FLAGS;
5380 ma->ma_attr_flags = MDS_CLOSE_CLEANUP;
5381 /* Don't unlink orphan on failover umount, LU-184 */
5382 if (exp->exp_flags & OBD_OPT_FAILOVER)
5383 ma->ma_attr_flags |= MDS_KEEP_ORPHAN;
5384 mdt_mfd_close(info, mfd);
5386 OBD_FREE_LARGE(ma->ma_cookie, cookie_size);
5387 ma->ma_cookie = NULL;
5389 OBD_FREE_LARGE(ma->ma_lmm, lmm_size);
5393 info->mti_mdt = NULL;
5394 /* cleanup client slot early */
5395 /* Do not erase record for recoverable client. */
5396 if (!(exp->exp_flags & OBD_OPT_FAILOVER) || exp->exp_failed)
5397 lut_client_del(&env, exp);
5403 static int mdt_obd_disconnect(struct obd_export *exp)
5409 class_export_get(exp);
5411 rc = server_disconnect_export(exp);
5413 CDEBUG(D_IOCTL, "server disconnect error: %d\n", rc);
5415 rc = mdt_export_cleanup(exp);
5416 class_export_put(exp);
5420 /* FIXME: Can we avoid using these two interfaces? */
5421 static int mdt_init_export(struct obd_export *exp)
5423 struct mdt_export_data *med = &exp->exp_mdt_data;
5427 CFS_INIT_LIST_HEAD(&med->med_open_head);
5428 cfs_spin_lock_init(&med->med_open_lock);
5429 cfs_mutex_init(&med->med_idmap_mutex);
5430 med->med_idmap = NULL;
5431 cfs_spin_lock(&exp->exp_lock);
5432 exp->exp_connecting = 1;
5433 cfs_spin_unlock(&exp->exp_lock);
5435 /* self-export doesn't need client data and ldlm initialization */
5436 if (unlikely(obd_uuid_equals(&exp->exp_obd->obd_uuid,
5437 &exp->exp_client_uuid)))
5440 rc = lut_client_alloc(exp);
5444 rc = ldlm_init_export(exp);
5451 lut_client_free(exp);
5453 CERROR("%s: Failed to initialize export: rc = %d\n",
5454 exp->exp_obd->obd_name, rc);
5458 static int mdt_destroy_export(struct obd_export *exp)
5462 if (exp_connect_rmtclient(exp))
5463 mdt_cleanup_idmap(&exp->exp_mdt_data);
5465 target_destroy_export(exp);
5466 /* destroy can be called from failed obd_setup, so
5467 * checking uuid is safer than obd_self_export */
5468 if (unlikely(obd_uuid_equals(&exp->exp_obd->obd_uuid,
5469 &exp->exp_client_uuid)))
5472 ldlm_destroy_export(exp);
5473 lut_client_free(exp);
5475 LASSERT(cfs_list_empty(&exp->exp_outstanding_replies));
5476 LASSERT(cfs_list_empty(&exp->exp_mdt_data.med_open_head));
5481 static void mdt_allow_cli(struct mdt_device *m, unsigned int flag)
5483 if (flag & CONFIG_LOG)
5484 cfs_set_bit(MDT_FL_CFGLOG, &m->mdt_state);
5486 /* also notify active event */
5487 if (flag & CONFIG_SYNC)
5488 cfs_set_bit(MDT_FL_SYNCED, &m->mdt_state);
5490 if (cfs_test_bit(MDT_FL_CFGLOG, &m->mdt_state) &&
5491 cfs_test_bit(MDT_FL_SYNCED, &m->mdt_state)) {
5492 struct obd_device *obd = m->mdt_md_dev.md_lu_dev.ld_obd;
5494 /* Open for clients */
5495 if (obd->obd_no_conn) {
5496 cfs_spin_lock(&obd->obd_dev_lock);
5497 obd->obd_no_conn = 0;
5498 cfs_spin_unlock(&obd->obd_dev_lock);
5503 static int mdt_upcall(const struct lu_env *env, struct md_device *md,
5504 enum md_upcall_event ev, void *data)
5506 struct mdt_device *m = mdt_dev(&md->md_lu_dev);
5507 struct md_device *next = m->mdt_child;
5508 struct mdt_thread_info *mti;
5514 rc = next->md_ops->mdo_maxsize_get(env, next,
5516 &m->mdt_max_cookiesize);
5517 CDEBUG(D_INFO, "get max mdsize %d max cookiesize %d\n",
5518 m->mdt_max_mdsize, m->mdt_max_cookiesize);
5519 mdt_allow_cli(m, CONFIG_SYNC);
5522 m->mdt_lut.lut_obd->u.obt.obt_mount_count;
5525 mti = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
5526 mti->mti_no_need_trans = 1;
5527 CDEBUG(D_INFO, "disable mdt trans for this thread\n");
5530 /* Check that MDT is not yet configured */
5531 LASSERT(!cfs_test_bit(MDT_FL_CFGLOG, &m->mdt_state));
5533 #ifdef HAVE_QUOTA_SUPPORT
5535 if (md->md_lu_dev.ld_obd->obd_recovering == 0 &&
5536 likely(md->md_lu_dev.ld_obd->obd_stopping == 0))
5537 next->md_ops->mdo_quota.mqo_recovery(env, next);
5541 CERROR("invalid event\n");
5548 static int mdt_obd_notify(struct obd_device *obd,
5549 struct obd_device *watched,
5550 enum obd_notify_event ev, void *data)
5552 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
5553 #ifdef HAVE_QUOTA_SUPPORT
5554 struct md_device *next = mdt->mdt_child;
5559 case OBD_NOTIFY_CONFIG:
5560 mdt_allow_cli(mdt, (unsigned long)data);
5562 #ifdef HAVE_QUOTA_SUPPORT
5563 /* quota_type has been processed, we can now handle
5564 * incoming quota requests */
5565 next->md_ops->mdo_quota.mqo_notify(NULL, next);
5569 CDEBUG(D_INFO, "Unhandled notification %#x\n", ev);
5574 static int mdt_rpc_fid2path(struct mdt_thread_info *info, void *key,
5575 void *val, int vallen)
5577 struct mdt_device *mdt = mdt_dev(info->mti_exp->exp_obd->obd_lu_dev);
5578 struct getinfo_fid2path *fpout, *fpin;
5581 fpin = key + cfs_size_round(sizeof(KEY_FID2PATH));
5584 if (ptlrpc_req_need_swab(info->mti_pill->rc_req))
5585 lustre_swab_fid2path(fpin);
5587 memcpy(fpout, fpin, sizeof(*fpin));
5588 if (fpout->gf_pathlen != vallen - sizeof(*fpin))
5591 rc = mdt_fid2path(info->mti_env, mdt, fpout);
5595 static int mdt_fid2path(const struct lu_env *env, struct mdt_device *mdt,
5596 struct getinfo_fid2path *fp)
5598 struct mdt_object *obj;
5602 CDEBUG(D_IOCTL, "path get "DFID" from "LPU64" #%d\n",
5603 PFID(&fp->gf_fid), fp->gf_recno, fp->gf_linkno);
5605 if (!fid_is_sane(&fp->gf_fid))
5608 obj = mdt_object_find(env, mdt, &fp->gf_fid);
5609 if (obj == NULL || IS_ERR(obj)) {
5610 CDEBUG(D_IOCTL, "no object "DFID": %ld\n", PFID(&fp->gf_fid),
5615 rc = lu_object_exists(&obj->mot_obj.mo_lu);
5621 mdt_object_put(env, obj);
5622 CDEBUG(D_IOCTL, "nonlocal object "DFID": %d\n",
5623 PFID(&fp->gf_fid), rc);
5627 rc = mo_path(env, md_object_next(&obj->mot_obj), fp->gf_path,
5628 fp->gf_pathlen, &fp->gf_recno, &fp->gf_linkno);
5629 mdt_object_put(env, obj);
5634 static int mdt_get_info(struct mdt_thread_info *info)
5636 struct ptlrpc_request *req = mdt_info_req(info);
5644 key = req_capsule_client_get(info->mti_pill, &RMF_GETINFO_KEY);
5646 CDEBUG(D_IOCTL, "No GETINFO key");
5649 keylen = req_capsule_get_size(info->mti_pill, &RMF_GETINFO_KEY,
5652 vallen = req_capsule_client_get(info->mti_pill, &RMF_GETINFO_VALLEN);
5653 if (vallen == NULL) {
5654 CDEBUG(D_IOCTL, "Unable to get RMF_GETINFO_VALLEN buffer");
5658 req_capsule_set_size(info->mti_pill, &RMF_GETINFO_VAL, RCL_SERVER,
5660 rc = req_capsule_server_pack(info->mti_pill);
5661 valout = req_capsule_server_get(info->mti_pill, &RMF_GETINFO_VAL);
5662 if (valout == NULL) {
5663 CDEBUG(D_IOCTL, "Unable to get get-info RPC out buffer");
5667 if (KEY_IS(KEY_FID2PATH))
5668 rc = mdt_rpc_fid2path(info, key, valout, *vallen);
5672 lustre_msg_set_status(req->rq_repmsg, rc);
5677 /* Pass the ioc down */
5678 static int mdt_ioc_child(struct lu_env *env, struct mdt_device *mdt,
5679 unsigned int cmd, int len, void *data)
5681 struct lu_context ioctl_session;
5682 struct md_device *next = mdt->mdt_child;
5686 rc = lu_context_init(&ioctl_session, LCT_SESSION);
5689 ioctl_session.lc_thread = (struct ptlrpc_thread *)cfs_current();
5690 lu_context_enter(&ioctl_session);
5691 env->le_ses = &ioctl_session;
5693 LASSERT(next->md_ops->mdo_iocontrol);
5694 rc = next->md_ops->mdo_iocontrol(env, next, cmd, len, data);
5696 lu_context_exit(&ioctl_session);
5697 lu_context_fini(&ioctl_session);
5701 static int mdt_ioc_version_get(struct mdt_thread_info *mti, void *karg)
5703 struct obd_ioctl_data *data = karg;
5704 struct lu_fid *fid = (struct lu_fid *)data->ioc_inlbuf1;
5706 struct mdt_object *obj;
5707 struct mdt_lock_handle *lh;
5711 CDEBUG(D_IOCTL, "getting version for "DFID"\n", PFID(fid));
5712 if (!fid_is_sane(fid))
5715 lh = &mti->mti_lh[MDT_LH_PARENT];
5716 mdt_lock_reg_init(lh, LCK_CR);
5718 obj = mdt_object_find_lock(mti, fid, lh, MDS_INODELOCK_UPDATE);
5720 RETURN(PTR_ERR(obj));
5722 rc = mdt_object_exists(obj);
5726 * before calling version get the correct MDS should be
5727 * fid, this is error to find remote object here
5729 CERROR("nonlocal object "DFID"\n", PFID(fid));
5730 } else if (rc == 0) {
5731 *(__u64 *)data->ioc_inlbuf2 = ENOENT_VERSION;
5734 version = dt_version_get(mti->mti_env, mdt_obj2dt(obj));
5735 *(__u64 *)data->ioc_inlbuf2 = version;
5738 mdt_object_unlock_put(mti, obj, lh, 1);
5742 /* ioctls on obd dev */
5743 static int mdt_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
5744 void *karg, void *uarg)
5747 struct obd_device *obd = exp->exp_obd;
5748 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
5749 struct dt_device *dt = mdt->mdt_bottom;
5753 CDEBUG(D_IOCTL, "handling ioctl cmd %#x\n", cmd);
5754 rc = lu_env_init(&env, LCT_MD_THREAD);
5760 rc = mdt_device_sync(&env, mdt);
5762 case OBD_IOC_SET_READONLY:
5763 rc = dt->dd_ops->dt_ro(&env, dt);
5765 case OBD_IOC_ABORT_RECOVERY:
5766 CERROR("Aborting recovery for device %s\n", obd->obd_name);
5767 target_stop_recovery_thread(obd);
5770 case OBD_IOC_CHANGELOG_REG:
5771 case OBD_IOC_CHANGELOG_DEREG:
5772 case OBD_IOC_CHANGELOG_CLEAR:
5773 rc = mdt_ioc_child(&env, mdt, cmd, len, karg);
5775 case OBD_IOC_START_LFSCK:
5776 case OBD_IOC_STOP_LFSCK: {
5777 struct md_device *next = mdt->mdt_child;
5778 struct obd_ioctl_data *data = karg;
5780 if (unlikely(data == NULL)) {
5785 rc = next->md_ops->mdo_iocontrol(&env, next, cmd,
5790 case OBD_IOC_GET_OBJ_VERSION: {
5791 struct mdt_thread_info *mti;
5792 mti = lu_context_key_get(&env.le_ctx, &mdt_thread_key);
5793 memset(mti, 0, sizeof *mti);
5794 mti->mti_env = &env;
5798 rc = mdt_ioc_version_get(mti, karg);
5802 CERROR("Not supported cmd = %d for device %s\n",
5803 cmd, obd->obd_name);
5811 int mdt_postrecov(const struct lu_env *env, struct mdt_device *mdt)
5813 struct lu_device *ld = md2lu_dev(mdt->mdt_child);
5814 #ifdef HAVE_QUOTA_SUPPORT
5815 struct obd_device *obd = mdt2obd_dev(mdt);
5816 struct md_device *next = mdt->mdt_child;
5821 rc = ld->ld_ops->ldo_recovery_complete(env, ld);
5822 #ifdef HAVE_QUOTA_SUPPORT
5823 if (likely(obd->obd_stopping == 0))
5824 next->md_ops->mdo_quota.mqo_recovery(env, next);
5829 int mdt_obd_postrecov(struct obd_device *obd)
5834 rc = lu_env_init(&env, LCT_MD_THREAD);
5837 rc = mdt_postrecov(&env, mdt_dev(obd->obd_lu_dev));
5843 * Send a copytool req to a client
5844 * Note this sends a request RPC from a server (MDT) to a client (MDC),
5845 * backwards of normal comms.
5847 int mdt_hsm_copytool_send(struct obd_export *exp)
5850 struct hsm_action_list *hal;
5851 struct hsm_action_item *hai;
5855 CWARN("%s: writing to mdc at %s\n", exp->exp_obd->obd_name,
5856 libcfs_nid2str(exp->exp_connection->c_peer.nid));
5858 len = sizeof(*lh) + sizeof(*hal) + MTI_NAME_MAXLEN +
5859 /* for mockup below */ 2 * cfs_size_round(sizeof(*hai));
5864 lh->kuc_magic = KUC_MAGIC;
5865 lh->kuc_transport = KUC_TRANSPORT_HSM;
5866 lh->kuc_msgtype = HMT_ACTION_LIST;
5867 lh->kuc_msglen = len;
5869 hal = (struct hsm_action_list *)(lh + 1);
5870 hal->hal_version = HAL_VERSION;
5871 hal->hal_archive_num = 1;
5872 obd_uuid2fsname(hal->hal_fsname, exp->exp_obd->obd_name,
5875 /* mock up an action list */
5877 hai = hai_zero(hal);
5878 hai->hai_action = HSMA_ARCHIVE;
5879 hai->hai_fid.f_oid = 0xA00A;
5880 hai->hai_len = sizeof(*hai);
5881 hai = hai_next(hai);
5882 hai->hai_action = HSMA_RESTORE;
5883 hai->hai_fid.f_oid = 0xB00B;
5884 hai->hai_len = sizeof(*hai);
5886 /* Uses the ldlm reverse import; this rpc will be seen by
5887 the ldlm_callback_handler */
5888 rc = do_set_info_async(exp->exp_imp_reverse,
5889 LDLM_SET_INFO, LUSTRE_OBD_VERSION,
5890 sizeof(KEY_HSM_COPYTOOL_SEND),
5891 KEY_HSM_COPYTOOL_SEND,
5899 static struct obd_ops mdt_obd_device_ops = {
5900 .o_owner = THIS_MODULE,
5901 .o_set_info_async = mdt_obd_set_info_async,
5902 .o_connect = mdt_obd_connect,
5903 .o_reconnect = mdt_obd_reconnect,
5904 .o_disconnect = mdt_obd_disconnect,
5905 .o_init_export = mdt_init_export,
5906 .o_destroy_export = mdt_destroy_export,
5907 .o_iocontrol = mdt_iocontrol,
5908 .o_postrecov = mdt_obd_postrecov,
5909 .o_notify = mdt_obd_notify
5912 static struct lu_device* mdt_device_fini(const struct lu_env *env,
5913 struct lu_device *d)
5915 struct mdt_device *m = mdt_dev(d);
5922 static struct lu_device *mdt_device_free(const struct lu_env *env,
5923 struct lu_device *d)
5925 struct mdt_device *m = mdt_dev(d);
5928 md_device_fini(&m->mdt_md_dev);
5933 static struct lu_device *mdt_device_alloc(const struct lu_env *env,
5934 struct lu_device_type *t,
5935 struct lustre_cfg *cfg)
5937 struct lu_device *l;
5938 struct mdt_device *m;
5944 l = &m->mdt_md_dev.md_lu_dev;
5945 rc = mdt_init0(env, m, t, cfg);
5947 mdt_device_free(env, l);
5951 md_upcall_init(&m->mdt_md_dev, mdt_upcall);
5953 l = ERR_PTR(-ENOMEM);
5957 /* context key constructor/destructor: mdt_key_init, mdt_key_fini */
5958 LU_KEY_INIT_FINI(mdt, struct mdt_thread_info);
5960 /* context key: mdt_thread_key */
5961 LU_CONTEXT_KEY_DEFINE(mdt, LCT_MD_THREAD);
5963 struct md_ucred *mdt_ucred(const struct mdt_thread_info *info)
5965 return md_ucred(info->mti_env);
5969 * Enable/disable COS (Commit On Sharing).
5971 * Set/Clear the COS flag in mdt options.
5973 * \param mdt mdt device
5974 * \param val 0 disables COS, other values enable COS
5976 void mdt_enable_cos(struct mdt_device *mdt, int val)
5981 mdt->mdt_opts.mo_cos = !!val;
5982 rc = lu_env_init(&env, LCT_LOCAL);
5983 if (unlikely(rc != 0)) {
5984 CWARN("lu_env initialization failed with rc = %d,"
5985 "cannot sync\n", rc);
5988 mdt_device_sync(&env, mdt);
5993 * Check COS (Commit On Sharing) status.
5995 * Return COS flag status.
5997 * \param mdt mdt device
5999 int mdt_cos_is_enabled(struct mdt_device *mdt)
6001 return mdt->mdt_opts.mo_cos != 0;
6004 /* type constructor/destructor: mdt_type_init, mdt_type_fini */
6005 LU_TYPE_INIT_FINI(mdt, &mdt_thread_key);
6007 static struct lu_device_type_operations mdt_device_type_ops = {
6008 .ldto_init = mdt_type_init,
6009 .ldto_fini = mdt_type_fini,
6011 .ldto_start = mdt_type_start,
6012 .ldto_stop = mdt_type_stop,
6014 .ldto_device_alloc = mdt_device_alloc,
6015 .ldto_device_free = mdt_device_free,
6016 .ldto_device_fini = mdt_device_fini
6019 static struct lu_device_type mdt_device_type = {
6020 .ldt_tags = LU_DEVICE_MD,
6021 .ldt_name = LUSTRE_MDT_NAME,
6022 .ldt_ops = &mdt_device_type_ops,
6023 .ldt_ctx_tags = LCT_MD_THREAD
6026 static int __init mdt_mod_init(void)
6028 struct lprocfs_static_vars lvars;
6031 if (mdt_num_threads != 0 && mds_num_threads == 0) {
6032 LCONSOLE_INFO("mdt_num_threads module parameter is deprecated,"
6033 "use mds_num_threads instead or unset both for"
6034 "dynamic thread startup\n");
6035 mds_num_threads = mdt_num_threads;
6038 lprocfs_mdt_init_vars(&lvars);
6039 rc = class_register_type(&mdt_obd_device_ops, NULL,
6040 lvars.module_vars, LUSTRE_MDT_NAME,
6046 static void __exit mdt_mod_exit(void)
6048 class_unregister_type(LUSTRE_MDT_NAME);
6052 #define DEF_HNDL(prefix, base, suffix, flags, opc, fn, fmt) \
6053 [prefix ## _ ## opc - prefix ## _ ## base] = { \
6055 .mh_fail_id = OBD_FAIL_ ## prefix ## _ ## opc ## suffix, \
6056 .mh_opc = prefix ## _ ## opc, \
6057 .mh_flags = flags, \
6062 #define DEF_MDT_HNDL(flags, name, fn, fmt) \
6063 DEF_HNDL(MDS, GETATTR, _NET, flags, name, fn, fmt)
6065 #define DEF_SEQ_HNDL(flags, name, fn, fmt) \
6066 DEF_HNDL(SEQ, QUERY, _NET, flags, name, fn, fmt)
6068 #define DEF_FLD_HNDL(flags, name, fn, fmt) \
6069 DEF_HNDL(FLD, QUERY, _NET, flags, name, fn, fmt)
6071 * Request with a format known in advance
6073 #define DEF_MDT_HNDL_F(flags, name, fn) \
6074 DEF_HNDL(MDS, GETATTR, _NET, flags, name, fn, &RQF_MDS_ ## name)
6076 #define DEF_SEQ_HNDL_F(flags, name, fn) \
6077 DEF_HNDL(SEQ, QUERY, _NET, flags, name, fn, &RQF_SEQ_ ## name)
6079 #define DEF_FLD_HNDL_F(flags, name, fn) \
6080 DEF_HNDL(FLD, QUERY, _NET, flags, name, fn, &RQF_FLD_ ## name)
6082 * Request with a format we do not yet know
6084 #define DEF_MDT_HNDL_0(flags, name, fn) \
6085 DEF_HNDL(MDS, GETATTR, _NET, flags, name, fn, NULL)
6087 static struct mdt_handler mdt_mds_ops[] = {
6088 DEF_MDT_HNDL_F(0, CONNECT, mdt_connect),
6089 DEF_MDT_HNDL_F(0, DISCONNECT, mdt_disconnect),
6090 DEF_MDT_HNDL (0, SET_INFO, mdt_set_info,
6092 DEF_MDT_HNDL_F(0, GET_INFO, mdt_get_info),
6093 DEF_MDT_HNDL_F(0 |HABEO_REFERO, GETSTATUS, mdt_getstatus),
6094 DEF_MDT_HNDL_F(HABEO_CORPUS, GETATTR, mdt_getattr),
6095 DEF_MDT_HNDL_F(HABEO_CORPUS|HABEO_REFERO, GETATTR_NAME, mdt_getattr_name),
6096 DEF_MDT_HNDL_F(HABEO_CORPUS, GETXATTR, mdt_getxattr),
6097 DEF_MDT_HNDL_F(0 |HABEO_REFERO, STATFS, mdt_statfs),
6098 DEF_MDT_HNDL_F(0 |MUTABOR, REINT, mdt_reint),
6099 DEF_MDT_HNDL_F(HABEO_CORPUS, CLOSE, mdt_close),
6100 DEF_MDT_HNDL_F(HABEO_CORPUS, DONE_WRITING, mdt_done_writing),
6101 DEF_MDT_HNDL_F(0 |HABEO_REFERO, PIN, mdt_pin),
6102 DEF_MDT_HNDL_0(0, SYNC, mdt_sync),
6103 DEF_MDT_HNDL_F(HABEO_CORPUS|HABEO_REFERO, IS_SUBDIR, mdt_is_subdir),
6104 #ifdef HAVE_QUOTA_SUPPORT
6105 DEF_MDT_HNDL_F(0, QUOTACHECK, mdt_quotacheck_handle),
6106 DEF_MDT_HNDL_F(0, QUOTACTL, mdt_quotactl_handle)
6110 #define DEF_OBD_HNDL(flags, name, fn) \
6111 DEF_HNDL(OBD, PING, _NET, flags, name, fn, NULL)
6114 static struct mdt_handler mdt_obd_ops[] = {
6115 DEF_OBD_HNDL(0, PING, mdt_obd_ping),
6116 DEF_OBD_HNDL(0, LOG_CANCEL, mdt_obd_log_cancel),
6117 DEF_OBD_HNDL(0, QC_CALLBACK, mdt_obd_qc_callback)
6120 #define DEF_DLM_HNDL_0(flags, name, fn) \
6121 DEF_HNDL(LDLM, ENQUEUE, , flags, name, fn, NULL)
6122 #define DEF_DLM_HNDL_F(flags, name, fn) \
6123 DEF_HNDL(LDLM, ENQUEUE, , flags, name, fn, &RQF_LDLM_ ## name)
6125 static struct mdt_handler mdt_dlm_ops[] = {
6126 DEF_DLM_HNDL_F(HABEO_CLAVIS, ENQUEUE, mdt_enqueue),
6127 DEF_DLM_HNDL_0(HABEO_CLAVIS, CONVERT, mdt_convert),
6128 DEF_DLM_HNDL_0(0, BL_CALLBACK, mdt_bl_callback),
6129 DEF_DLM_HNDL_0(0, CP_CALLBACK, mdt_cp_callback)
6132 #define DEF_LLOG_HNDL(flags, name, fn) \
6133 DEF_HNDL(LLOG, ORIGIN_HANDLE_CREATE, _NET, flags, name, fn, NULL)
6135 static struct mdt_handler mdt_llog_ops[] = {
6136 DEF_LLOG_HNDL(0, ORIGIN_HANDLE_CREATE, mdt_llog_create),
6137 DEF_LLOG_HNDL(0, ORIGIN_HANDLE_NEXT_BLOCK, mdt_llog_next_block),
6138 DEF_LLOG_HNDL(0, ORIGIN_HANDLE_READ_HEADER, mdt_llog_read_header),
6139 DEF_LLOG_HNDL(0, ORIGIN_HANDLE_WRITE_REC, NULL),
6140 DEF_LLOG_HNDL(0, ORIGIN_HANDLE_CLOSE, NULL),
6141 DEF_LLOG_HNDL(0, ORIGIN_CONNECT, NULL),
6142 DEF_LLOG_HNDL(0, CATINFO, NULL),
6143 DEF_LLOG_HNDL(0, ORIGIN_HANDLE_PREV_BLOCK, mdt_llog_prev_block),
6144 DEF_LLOG_HNDL(0, ORIGIN_HANDLE_DESTROY, mdt_llog_destroy),
6147 #define DEF_SEC_CTX_HNDL(name, fn) \
6148 DEF_HNDL(SEC_CTX, INIT, _NET, 0, name, fn, NULL)
6150 static struct mdt_handler mdt_sec_ctx_ops[] = {
6151 DEF_SEC_CTX_HNDL(INIT, mdt_sec_ctx_handle),
6152 DEF_SEC_CTX_HNDL(INIT_CONT, mdt_sec_ctx_handle),
6153 DEF_SEC_CTX_HNDL(FINI, mdt_sec_ctx_handle)
6156 static struct mdt_opc_slice mdt_regular_handlers[] = {
6158 .mos_opc_start = MDS_GETATTR,
6159 .mos_opc_end = MDS_LAST_OPC,
6160 .mos_hs = mdt_mds_ops
6163 .mos_opc_start = OBD_PING,
6164 .mos_opc_end = OBD_LAST_OPC,
6165 .mos_hs = mdt_obd_ops
6168 .mos_opc_start = LDLM_ENQUEUE,
6169 .mos_opc_end = LDLM_LAST_OPC,
6170 .mos_hs = mdt_dlm_ops
6173 .mos_opc_start = LLOG_ORIGIN_HANDLE_CREATE,
6174 .mos_opc_end = LLOG_LAST_OPC,
6175 .mos_hs = mdt_llog_ops
6178 .mos_opc_start = SEC_CTX_INIT,
6179 .mos_opc_end = SEC_LAST_OPC,
6180 .mos_hs = mdt_sec_ctx_ops
6187 static struct mdt_handler mdt_readpage_ops[] = {
6188 DEF_MDT_HNDL_F(0, CONNECT, mdt_connect),
6189 DEF_MDT_HNDL_F(HABEO_CORPUS|HABEO_REFERO, READPAGE, mdt_readpage),
6190 #ifdef HAVE_SPLIT_SUPPORT
6191 DEF_MDT_HNDL_F(HABEO_CORPUS|HABEO_REFERO, WRITEPAGE, mdt_writepage),
6195 * XXX: this is ugly and should be fixed one day, see mdc_close() for
6196 * detailed comments. --umka
6198 DEF_MDT_HNDL_F(HABEO_CORPUS, CLOSE, mdt_close),
6199 DEF_MDT_HNDL_F(HABEO_CORPUS, DONE_WRITING, mdt_done_writing),
6202 static struct mdt_opc_slice mdt_readpage_handlers[] = {
6204 .mos_opc_start = MDS_GETATTR,
6205 .mos_opc_end = MDS_LAST_OPC,
6206 .mos_hs = mdt_readpage_ops
6213 static struct mdt_handler mdt_xmds_ops[] = {
6214 DEF_MDT_HNDL_F(0, CONNECT, mdt_connect),
6215 DEF_MDT_HNDL_F(HABEO_CORPUS , GETATTR, mdt_getattr),
6216 DEF_MDT_HNDL_F(0 | MUTABOR , REINT, mdt_reint),
6217 DEF_MDT_HNDL_F(HABEO_CORPUS|HABEO_REFERO, IS_SUBDIR, mdt_is_subdir),
6220 static struct mdt_opc_slice mdt_xmds_handlers[] = {
6222 .mos_opc_start = MDS_GETATTR,
6223 .mos_opc_end = MDS_LAST_OPC,
6224 .mos_hs = mdt_xmds_ops
6227 .mos_opc_start = OBD_PING,
6228 .mos_opc_end = OBD_LAST_OPC,
6229 .mos_hs = mdt_obd_ops
6232 .mos_opc_start = SEC_CTX_INIT,
6233 .mos_opc_end = SEC_LAST_OPC,
6234 .mos_hs = mdt_sec_ctx_ops
6241 static struct mdt_handler mdt_seq_ops[] = {
6242 DEF_SEQ_HNDL_F(0, QUERY, (int (*)(struct mdt_thread_info *))seq_query)
6245 static struct mdt_opc_slice mdt_seq_handlers[] = {
6247 .mos_opc_start = SEQ_QUERY,
6248 .mos_opc_end = SEQ_LAST_OPC,
6249 .mos_hs = mdt_seq_ops
6256 static struct mdt_handler mdt_fld_ops[] = {
6257 DEF_FLD_HNDL_F(0, QUERY, (int (*)(struct mdt_thread_info *))fld_query)
6260 static struct mdt_opc_slice mdt_fld_handlers[] = {
6262 .mos_opc_start = FLD_QUERY,
6263 .mos_opc_end = FLD_LAST_OPC,
6264 .mos_hs = mdt_fld_ops
6271 MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");
6272 MODULE_DESCRIPTION("Lustre Meta-data Target ("LUSTRE_MDT_NAME")");
6273 MODULE_LICENSE("GPL");
6275 cfs_module(mdt, "0.2.0", mdt_mod_init, mdt_mod_exit);