4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
27 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2011, 2012, Whamcloud, Inc.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * lustre/mdt/mdt_handler.c
38 * Lustre Metadata Target (mdt) request handler
40 * Author: Peter Braam <braam@clusterfs.com>
41 * Author: Andreas Dilger <adilger@clusterfs.com>
42 * Author: Phil Schwan <phil@clusterfs.com>
43 * Author: Mike Shaver <shaver@clusterfs.com>
44 * Author: Nikita Danilov <nikita@clusterfs.com>
45 * Author: Huang Hua <huanghua@clusterfs.com>
46 * Author: Yury Umanets <umka@clusterfs.com>
49 #define DEBUG_SUBSYSTEM S_MDS
51 #include <linux/module.h>
53 * struct OBD_{ALLOC,FREE}*()
55 #include <obd_support.h>
56 /* struct ptlrpc_request */
57 #include <lustre_net.h>
58 /* struct obd_export */
59 #include <lustre_export.h>
60 /* struct obd_device */
63 #include <dt_object.h>
64 #include <lustre_mds.h>
65 #include <lustre_mdt.h>
66 #include <lustre_log.h>
67 #include "mdt_internal.h"
68 #include <lustre_acl.h>
69 #include <lustre_param.h>
70 #include <lustre_quota.h>
72 mdl_mode_t mdt_mdl_lock_modes[] = {
73 [LCK_MINMODE] = MDL_MINMODE,
80 [LCK_GROUP] = MDL_GROUP
83 ldlm_mode_t mdt_dlm_lock_modes[] = {
84 [MDL_MINMODE] = LCK_MINMODE,
91 [MDL_GROUP] = LCK_GROUP
95 * Initialized in mdt_mod_init().
97 static unsigned long mdt_num_threads;
98 CFS_MODULE_PARM(mdt_num_threads, "ul", ulong, 0444,
99 "number of MDS service threads to start "
100 "(deprecated in favor of mds_num_threads)");
102 static unsigned long mds_num_threads;
103 CFS_MODULE_PARM(mds_num_threads, "ul", ulong, 0444,
104 "number of MDS service threads to start");
106 static char *mds_num_cpts;
107 CFS_MODULE_PARM(mds_num_cpts, "c", charp, 0444,
108 "CPU partitions MDS threads should run on");
110 static unsigned long mds_rdpg_num_threads;
111 CFS_MODULE_PARM(mds_rdpg_num_threads, "ul", ulong, 0444,
112 "number of MDS readpage service threads to start");
114 static char *mds_rdpg_num_cpts;
115 CFS_MODULE_PARM(mds_rdpg_num_cpts, "c", charp, 0444,
116 "CPU partitions MDS readpage threads should run on");
118 /* NB: these two should be removed along with setattr service in the future */
119 static unsigned long mds_attr_num_threads;
120 CFS_MODULE_PARM(mds_attr_num_threads, "ul", ulong, 0444,
121 "number of MDS setattr service threads to start");
123 static char *mds_attr_num_cpts;
124 CFS_MODULE_PARM(mds_attr_num_cpts, "c", charp, 0444,
125 "CPU partitions MDS setattr threads should run on");
127 /* ptlrpc request handler for MDT. All handlers are
128 * grouped into several slices - struct mdt_opc_slice,
129 * and stored in an array - mdt_handlers[].
132 /* The name of this handler. */
134 /* Fail id for this handler, checked at the beginning of this handler*/
136 /* Operation code for this handler */
138 /* flags are listed in enum mdt_handler_flags below. */
140 /* The actual handler function to execute. */
141 int (*mh_act)(struct mdt_thread_info *info);
142 /* Request format for this request. */
143 const struct req_format *mh_fmt;
146 enum mdt_handler_flags {
148 * struct mdt_body is passed in the incoming message, and object
149 * identified by this fid exists on disk.
151 * "habeo corpus" == "I have a body"
153 HABEO_CORPUS = (1 << 0),
155 * struct ldlm_request is passed in the incoming message.
157 * "habeo clavis" == "I have a key"
159 HABEO_CLAVIS = (1 << 1),
161 * this request has fixed reply format, so that reply message can be
162 * packed by generic code.
164 * "habeo refero" == "I have a reply"
166 HABEO_REFERO = (1 << 2),
168 * this request will modify something, so check whether the filesystem
169 * is readonly or not, then return -EROFS to client asap if necessary.
171 * "mutabor" == "I shall modify"
176 struct mdt_opc_slice {
179 struct mdt_handler *mos_hs;
182 static struct mdt_opc_slice mdt_regular_handlers[];
183 static struct mdt_opc_slice mdt_readpage_handlers[];
184 static struct mdt_opc_slice mdt_xmds_handlers[];
185 static struct mdt_opc_slice mdt_seq_handlers[];
186 static struct mdt_opc_slice mdt_fld_handlers[];
188 static struct mdt_device *mdt_dev(struct lu_device *d);
189 static int mdt_regular_handle(struct ptlrpc_request *req);
190 static int mdt_unpack_req_pack_rep(struct mdt_thread_info *info, __u32 flags);
191 static int mdt_fid2path(const struct lu_env *env, struct mdt_device *mdt,
192 struct getinfo_fid2path *fp);
194 static const struct lu_object_operations mdt_obj_ops;
196 /* Slab for MDT object allocation */
197 static cfs_mem_cache_t *mdt_object_kmem;
199 static struct lu_kmem_descr mdt_caches[] = {
201 .ckd_cache = &mdt_object_kmem,
202 .ckd_name = "mdt_obj",
203 .ckd_size = sizeof(struct mdt_object)
210 int mdt_get_disposition(struct ldlm_reply *rep, int flag)
214 return (rep->lock_policy_res1 & flag);
217 void mdt_clear_disposition(struct mdt_thread_info *info,
218 struct ldlm_reply *rep, int flag)
221 info->mti_opdata &= ~flag;
223 rep->lock_policy_res1 &= ~flag;
226 void mdt_set_disposition(struct mdt_thread_info *info,
227 struct ldlm_reply *rep, int flag)
230 info->mti_opdata |= flag;
232 rep->lock_policy_res1 |= flag;
235 void mdt_lock_reg_init(struct mdt_lock_handle *lh, ldlm_mode_t lm)
237 lh->mlh_pdo_hash = 0;
238 lh->mlh_reg_mode = lm;
239 lh->mlh_type = MDT_REG_LOCK;
242 void mdt_lock_pdo_init(struct mdt_lock_handle *lh, ldlm_mode_t lm,
243 const char *name, int namelen)
245 lh->mlh_reg_mode = lm;
246 lh->mlh_type = MDT_PDO_LOCK;
248 if (name != NULL && (name[0] != '\0')) {
249 LASSERT(namelen > 0);
250 lh->mlh_pdo_hash = full_name_hash(name, namelen);
252 LASSERT(namelen == 0);
253 lh->mlh_pdo_hash = 0ull;
257 static void mdt_lock_pdo_mode(struct mdt_thread_info *info, struct mdt_object *o,
258 struct mdt_lock_handle *lh)
264 * Any dir access needs couple of locks:
266 * 1) on part of dir we gonna take lookup/modify;
268 * 2) on whole dir to protect it from concurrent splitting and/or to
269 * flush client's cache for readdir().
271 * so, for a given mode and object this routine decides what lock mode
272 * to use for lock #2:
274 * 1) if caller's gonna lookup in dir then we need to protect dir from
275 * being splitted only - LCK_CR
277 * 2) if caller's gonna modify dir then we need to protect dir from
278 * being splitted and to flush cache - LCK_CW
280 * 3) if caller's gonna modify dir and that dir seems ready for
281 * splitting then we need to protect it from any type of access
282 * (lookup/modify/split) - LCK_EX --bzzz
285 LASSERT(lh->mlh_reg_mode != LCK_MINMODE);
286 LASSERT(lh->mlh_pdo_mode == LCK_MINMODE);
289 * Ask underlaying level its opinion about preferable PDO lock mode
290 * having access type passed as regular lock mode:
292 * - MDL_MINMODE means that lower layer does not want to specify lock
295 * - MDL_NL means that no PDO lock should be taken. This is used in some
296 * cases. Say, for non-splittable directories no need to use PDO locks
299 mode = mdo_lock_mode(info->mti_env, mdt_object_child(o),
300 mdt_dlm_mode2mdl_mode(lh->mlh_reg_mode));
302 if (mode != MDL_MINMODE) {
303 lh->mlh_pdo_mode = mdt_mdl_mode2dlm_mode(mode);
306 * Lower layer does not want to specify locking mode. We do it
307 * our selves. No special protection is needed, just flush
308 * client's cache on modification and allow concurrent
311 switch (lh->mlh_reg_mode) {
313 lh->mlh_pdo_mode = LCK_EX;
316 lh->mlh_pdo_mode = LCK_CR;
319 lh->mlh_pdo_mode = LCK_CW;
322 CERROR("Not expected lock type (0x%x)\n",
323 (int)lh->mlh_reg_mode);
328 LASSERT(lh->mlh_pdo_mode != LCK_MINMODE);
332 static int mdt_getstatus(struct mdt_thread_info *info)
334 struct mdt_device *mdt = info->mti_mdt;
335 struct md_device *next = mdt->mdt_child;
336 struct mdt_body *repbody;
341 rc = mdt_check_ucred(info);
343 RETURN(err_serious(rc));
345 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_GETSTATUS_PACK))
346 RETURN(err_serious(-ENOMEM));
348 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
349 rc = next->md_ops->mdo_root_get(info->mti_env, next, &repbody->fid1);
353 repbody->valid |= OBD_MD_FLID;
355 if (mdt->mdt_opts.mo_mds_capa &&
356 info->mti_exp->exp_connect_flags & OBD_CONNECT_MDS_CAPA) {
357 struct mdt_object *root;
358 struct lustre_capa *capa;
360 root = mdt_object_find(info->mti_env, mdt, &repbody->fid1);
362 RETURN(PTR_ERR(root));
364 capa = req_capsule_server_get(info->mti_pill, &RMF_CAPA1);
366 capa->lc_opc = CAPA_OPC_MDS_DEFAULT;
367 rc = mo_capa_get(info->mti_env, mdt_object_child(root), capa,
369 mdt_object_put(info->mti_env, root);
371 repbody->valid |= OBD_MD_FLMDSCAPA;
377 static int mdt_statfs(struct mdt_thread_info *info)
379 struct ptlrpc_request *req = mdt_info_req(info);
380 struct md_device *next = info->mti_mdt->mdt_child;
381 struct ptlrpc_service_part *svcpt;
382 struct obd_statfs *osfs;
387 svcpt = info->mti_pill->rc_req->rq_rqbd->rqbd_svcpt;
389 /* This will trigger a watchdog timeout */
390 OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_STATFS_LCW_SLEEP,
391 (MDT_SERVICE_WATCHDOG_FACTOR *
392 at_get(&svcpt->scp_at_estimate)) + 1);
394 rc = mdt_check_ucred(info);
396 RETURN(err_serious(rc));
398 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_STATFS_PACK))
399 RETURN(err_serious(-ENOMEM));
401 osfs = req_capsule_server_get(info->mti_pill, &RMF_OBD_STATFS);
405 /** statfs information are cached in the mdt_device */
406 if (cfs_time_before_64(info->mti_mdt->mdt_osfs_age,
407 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS))) {
408 /** statfs data is too old, get up-to-date one */
409 rc = next->md_ops->mdo_statfs(info->mti_env, next, osfs);
412 cfs_spin_lock(&info->mti_mdt->mdt_osfs_lock);
413 info->mti_mdt->mdt_osfs = *osfs;
414 info->mti_mdt->mdt_osfs_age = cfs_time_current_64();
415 cfs_spin_unlock(&info->mti_mdt->mdt_osfs_lock);
417 /** use cached statfs data */
418 cfs_spin_lock(&info->mti_mdt->mdt_osfs_lock);
419 *osfs = info->mti_mdt->mdt_osfs;
420 cfs_spin_unlock(&info->mti_mdt->mdt_osfs_lock);
424 mdt_counter_incr(req, LPROC_MDT_STATFS);
430 * Pack SOM attributes into the reply.
431 * Call under a DLM UPDATE lock.
433 static void mdt_pack_size2body(struct mdt_thread_info *info,
434 struct mdt_object *mo)
437 struct md_attr *ma = &info->mti_attr;
439 LASSERT(ma->ma_attr.la_valid & LA_MODE);
440 b = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
442 /* Check if Size-on-MDS is supported, if this is a regular file,
443 * if SOM is enabled on the object and if SOM cache exists and valid.
444 * Otherwise do not pack Size-on-MDS attributes to the reply. */
445 if (!(mdt_conn_flags(info) & OBD_CONNECT_SOM) ||
446 !S_ISREG(ma->ma_attr.la_mode) ||
447 !mdt_object_is_som_enabled(mo) ||
448 !(ma->ma_valid & MA_SOM))
451 b->valid |= OBD_MD_FLSIZE | OBD_MD_FLBLOCKS;
452 b->size = ma->ma_som->msd_size;
453 b->blocks = ma->ma_som->msd_blocks;
456 void mdt_pack_attr2body(struct mdt_thread_info *info, struct mdt_body *b,
457 const struct lu_attr *attr, const struct lu_fid *fid)
459 struct md_attr *ma = &info->mti_attr;
461 LASSERT(ma->ma_valid & MA_INODE);
463 b->atime = attr->la_atime;
464 b->mtime = attr->la_mtime;
465 b->ctime = attr->la_ctime;
466 b->mode = attr->la_mode;
467 b->size = attr->la_size;
468 b->blocks = attr->la_blocks;
469 b->uid = attr->la_uid;
470 b->gid = attr->la_gid;
471 b->flags = attr->la_flags;
472 b->nlink = attr->la_nlink;
473 b->rdev = attr->la_rdev;
475 /*XXX should pack the reply body according to lu_valid*/
476 b->valid |= OBD_MD_FLCTIME | OBD_MD_FLUID |
477 OBD_MD_FLGID | OBD_MD_FLTYPE |
478 OBD_MD_FLMODE | OBD_MD_FLNLINK | OBD_MD_FLFLAGS |
479 OBD_MD_FLATIME | OBD_MD_FLMTIME ;
481 if (!S_ISREG(attr->la_mode)) {
482 b->valid |= OBD_MD_FLSIZE | OBD_MD_FLBLOCKS | OBD_MD_FLRDEV;
483 } else if (ma->ma_need & MA_LOV && !(ma->ma_valid & MA_LOV)) {
484 /* means no objects are allocated on osts. */
485 LASSERT(!(ma->ma_valid & MA_LOV));
486 /* just ignore blocks occupied by extend attributes on MDS */
488 /* if no object is allocated on osts, the size on mds is valid. b=22272 */
489 b->valid |= OBD_MD_FLSIZE | OBD_MD_FLBLOCKS;
494 b->valid |= OBD_MD_FLID;
496 /* FIXME: these should be fixed when new igif ready.*/
497 b->ino = fid_oid(fid); /* 1.6 compatibility */
498 b->generation = fid_ver(fid); /* 1.6 compatibility */
499 b->valid |= OBD_MD_FLGENER; /* 1.6 compatibility */
501 CDEBUG(D_INODE, DFID": nlink=%d, mode=%o, size="LPU64"\n",
502 PFID(fid), b->nlink, b->mode, b->size);
506 mdt_body_reverse_idmap(info, b);
508 if (b->valid & OBD_MD_FLSIZE)
509 CDEBUG(D_VFSTRACE, DFID": returning size %llu\n",
510 PFID(fid), (unsigned long long)b->size);
513 static inline int mdt_body_has_lov(const struct lu_attr *la,
514 const struct mdt_body *body)
516 return ((S_ISREG(la->la_mode) && (body->valid & OBD_MD_FLEASIZE)) ||
517 (S_ISDIR(la->la_mode) && (body->valid & OBD_MD_FLDIREA )) );
520 void mdt_client_compatibility(struct mdt_thread_info *info)
522 struct mdt_body *body;
523 struct ptlrpc_request *req = mdt_info_req(info);
524 struct obd_export *exp = req->rq_export;
525 struct md_attr *ma = &info->mti_attr;
526 struct lu_attr *la = &ma->ma_attr;
529 if (exp->exp_connect_flags & OBD_CONNECT_LAYOUTLOCK)
530 /* the client can deal with 16-bit lmm_stripe_count */
533 body = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
535 if (!mdt_body_has_lov(la, body))
538 /* now we have a reply with a lov for a client not compatible with the
539 * layout lock so we have to clean the layout generation number */
540 if (S_ISREG(la->la_mode))
541 ma->ma_lmm->lmm_layout_gen = 0;
545 static int mdt_big_lmm_get(const struct lu_env *env, struct mdt_object *o,
548 struct mdt_thread_info *info;
552 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
553 LASSERT(info != NULL);
554 LASSERT(ma->ma_lmm_size > 0);
555 LASSERT(info->mti_big_lmm_used == 0);
556 rc = mo_xattr_get(env, mdt_object_child(o), &LU_BUF_NULL,
561 /* big_lmm may need to be grown */
562 if (info->mti_big_lmmsize < rc) {
563 int size = size_roundup_power2(rc);
565 if (info->mti_big_lmmsize > 0) {
566 /* free old buffer */
567 LASSERT(info->mti_big_lmm);
568 OBD_FREE_LARGE(info->mti_big_lmm,
569 info->mti_big_lmmsize);
570 info->mti_big_lmm = NULL;
571 info->mti_big_lmmsize = 0;
574 OBD_ALLOC_LARGE(info->mti_big_lmm, size);
575 if (info->mti_big_lmm == NULL)
577 info->mti_big_lmmsize = size;
579 LASSERT(info->mti_big_lmmsize >= rc);
581 info->mti_buf.lb_buf = info->mti_big_lmm;
582 info->mti_buf.lb_len = info->mti_big_lmmsize;
583 rc = mo_xattr_get(env, mdt_object_child(o), &info->mti_buf,
588 info->mti_big_lmm_used = 1;
589 ma->ma_valid |= MA_LOV;
590 ma->ma_lmm = info->mti_big_lmm;
591 ma->ma_lmm_size = rc;
593 /* update mdt_max_mdsize so all clients will be aware about that */
594 if (info->mti_mdt->mdt_max_mdsize < rc)
595 info->mti_mdt->mdt_max_mdsize = rc;
600 int mdt_attr_get_lov(struct mdt_thread_info *info,
601 struct mdt_object *o, struct md_attr *ma)
603 struct md_object *next = mdt_object_child(o);
604 struct lu_buf *buf = &info->mti_buf;
607 buf->lb_buf = ma->ma_lmm;
608 buf->lb_len = ma->ma_lmm_size;
609 rc = mo_xattr_get(info->mti_env, next, buf, XATTR_NAME_LOV);
611 ma->ma_lmm_size = rc;
612 ma->ma_valid |= MA_LOV;
614 } else if (rc == -ENODATA) {
617 } else if (rc == -ERANGE) {
618 rc = mdt_big_lmm_get(info->mti_env, o, ma);
624 int mdt_attr_get_complex(struct mdt_thread_info *info,
625 struct mdt_object *o, struct md_attr *ma)
627 const struct lu_env *env = info->mti_env;
628 struct md_object *next = mdt_object_child(o);
629 struct lu_buf *buf = &info->mti_buf;
630 u32 mode = lu_object_attr(&next->mo_lu);
631 int need = ma->ma_need;
635 /* do we really need PFID */
636 LASSERT((ma->ma_need & MA_PFID) == 0);
640 if (need & MA_INODE) {
641 ma->ma_need = MA_INODE;
642 rc = mo_attr_get(env, next, ma);
645 ma->ma_valid |= MA_INODE;
648 if (need & MA_LOV && (S_ISREG(mode) || S_ISDIR(mode))) {
649 rc = mdt_attr_get_lov(info, o, ma);
654 if (need & MA_LMV && S_ISDIR(mode)) {
655 buf->lb_buf = ma->ma_lmv;
656 buf->lb_len = ma->ma_lmv_size;
657 rc2 = mo_xattr_get(env, next, buf, XATTR_NAME_LMV);
659 ma->ma_lmv_size = rc2;
660 ma->ma_valid |= MA_LMV;
661 } else if (rc2 == -ENODATA) {
669 if (rc == 0 && S_ISREG(mode) && (need & (MA_HSM | MA_SOM))) {
670 struct lustre_mdt_attrs *lma;
672 lma = (struct lustre_mdt_attrs *)info->mti_xattr_buf;
673 CLASSERT(sizeof(*lma) <= sizeof(info->mti_xattr_buf));
676 buf->lb_len = sizeof(info->mti_xattr_buf);
677 rc = mo_xattr_get(env, next, buf, XATTR_NAME_LMA);
679 lustre_lma_swab(lma);
680 /* Swab and copy LMA */
682 if (lma->lma_compat & LMAC_HSM)
683 ma->ma_hsm.mh_flags =
684 lma->lma_flags & HSM_FLAGS_MASK;
686 ma->ma_hsm.mh_flags = 0;
687 ma->ma_valid |= MA_HSM;
690 if (need & MA_SOM && lma->lma_compat & LMAC_SOM) {
691 LASSERT(ma->ma_som != NULL);
692 ma->ma_som->msd_ioepoch = lma->lma_ioepoch;
693 ma->ma_som->msd_size = lma->lma_som_size;
694 ma->ma_som->msd_blocks = lma->lma_som_blocks;
695 ma->ma_som->msd_mountid = lma->lma_som_mountid;
696 ma->ma_valid |= MA_SOM;
699 } else if (rc == -ENODATA) {
704 #ifdef CONFIG_FS_POSIX_ACL
705 if (need & MA_ACL_DEF && S_ISDIR(mode)) {
706 buf->lb_buf = ma->ma_acl;
707 buf->lb_len = ma->ma_acl_size;
708 rc2 = mo_xattr_get(env, next, buf, XATTR_NAME_ACL_DEFAULT);
710 ma->ma_acl_size = rc2;
711 ma->ma_valid |= MA_ACL_DEF;
712 } else if (rc2 == -ENODATA) {
721 CDEBUG(D_INODE, "after getattr rc = %d, ma_valid = "LPX64" ma_lmm=%p\n",
722 rc, ma->ma_valid, ma->ma_lmm);
726 static int mdt_getattr_internal(struct mdt_thread_info *info,
727 struct mdt_object *o, int ma_need)
729 struct md_object *next = mdt_object_child(o);
730 const struct mdt_body *reqbody = info->mti_body;
731 struct ptlrpc_request *req = mdt_info_req(info);
732 struct md_attr *ma = &info->mti_attr;
733 struct lu_attr *la = &ma->ma_attr;
734 struct req_capsule *pill = info->mti_pill;
735 const struct lu_env *env = info->mti_env;
736 struct mdt_body *repbody;
737 struct lu_buf *buffer = &info->mti_buf;
742 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_GETATTR_PACK))
743 RETURN(err_serious(-ENOMEM));
745 repbody = req_capsule_server_get(pill, &RMF_MDT_BODY);
749 rc = mdt_object_exists(o);
751 /* This object is located on remote node.*/
752 repbody->fid1 = *mdt_object_fid(o);
753 repbody->valid = OBD_MD_FLID | OBD_MD_MDS;
757 buffer->lb_len = reqbody->eadatasize;
758 if (buffer->lb_len > 0)
759 buffer->lb_buf = req_capsule_server_get(pill, &RMF_MDT_MD);
761 buffer->lb_buf = NULL;
763 /* If it is dir object and client require MEA, then we got MEA */
764 if (S_ISDIR(lu_object_attr(&next->mo_lu)) &&
765 reqbody->valid & OBD_MD_MEA) {
766 /* Assumption: MDT_MD size is enough for lmv size. */
767 ma->ma_lmv = buffer->lb_buf;
768 ma->ma_lmv_size = buffer->lb_len;
769 ma->ma_need = MA_LMV | MA_INODE;
771 ma->ma_lmm = buffer->lb_buf;
772 ma->ma_lmm_size = buffer->lb_len;
773 ma->ma_need = MA_LOV | MA_INODE;
776 if (S_ISDIR(lu_object_attr(&next->mo_lu)) &&
777 reqbody->valid & OBD_MD_FLDIREA &&
778 lustre_msg_get_opc(req->rq_reqmsg) == MDS_GETATTR) {
779 /* get default stripe info for this dir. */
780 ma->ma_need |= MA_LOV_DEF;
782 ma->ma_need |= ma_need;
783 if (ma->ma_need & MA_SOM)
784 ma->ma_som = &info->mti_u.som.data;
786 rc = mdt_attr_get_complex(info, o, ma);
788 CERROR("getattr error for "DFID": %d\n",
789 PFID(mdt_object_fid(o)), rc);
793 is_root = lu_fid_eq(mdt_object_fid(o), &info->mti_mdt->mdt_md_root_fid);
795 /* the Lustre protocol supposes to return default striping
796 * on the user-visible root if explicitly requested */
797 if ((ma->ma_valid & MA_LOV) == 0 && S_ISDIR(la->la_mode) &&
798 (ma->ma_need & MA_LOV_DEF && is_root) && (ma->ma_need & MA_LOV)) {
799 struct lu_fid rootfid;
800 struct mdt_object *root;
801 struct mdt_device *mdt = info->mti_mdt;
803 rc = dt_root_get(env, mdt->mdt_bottom, &rootfid);
806 root = mdt_object_find(env, mdt, &rootfid);
808 RETURN(PTR_ERR(root));
809 rc = mdt_attr_get_lov(info, root, ma);
810 mdt_object_put(info->mti_env, root);
812 CERROR("getattr error for "DFID": %d\n",
813 PFID(mdt_object_fid(o)), rc);
818 if (likely(ma->ma_valid & MA_INODE))
819 mdt_pack_attr2body(info, repbody, la, mdt_object_fid(o));
823 if (mdt_body_has_lov(la, reqbody)) {
824 if (ma->ma_valid & MA_LOV) {
825 LASSERT(ma->ma_lmm_size);
826 mdt_dump_lmm(D_INFO, ma->ma_lmm);
827 repbody->eadatasize = ma->ma_lmm_size;
828 if (S_ISDIR(la->la_mode))
829 repbody->valid |= OBD_MD_FLDIREA;
831 repbody->valid |= OBD_MD_FLEASIZE;
833 if (ma->ma_valid & MA_LMV) {
834 LASSERT(S_ISDIR(la->la_mode));
835 repbody->eadatasize = ma->ma_lmv_size;
836 repbody->valid |= (OBD_MD_FLDIREA|OBD_MD_MEA);
838 } else if (S_ISLNK(la->la_mode) &&
839 reqbody->valid & OBD_MD_LINKNAME) {
840 buffer->lb_buf = ma->ma_lmm;
841 /* eadatasize from client includes NULL-terminator, so
842 * there is no need to read it */
843 buffer->lb_len = reqbody->eadatasize - 1;
844 rc = mo_readlink(env, next, buffer);
845 if (unlikely(rc <= 0)) {
846 CERROR("readlink failed: %d\n", rc);
849 int print_limit = min_t(int, CFS_PAGE_SIZE - 128, rc);
851 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_READLINK_EPROTO))
853 repbody->valid |= OBD_MD_LINKNAME;
854 /* we need to report back size with NULL-terminator
855 * because client expects that */
856 repbody->eadatasize = rc + 1;
857 if (repbody->eadatasize != reqbody->eadatasize)
858 CERROR("Read shorter symlink %d, expected %d\n",
859 rc, reqbody->eadatasize - 1);
861 ((char *)ma->ma_lmm)[rc] = 0;
863 /* If the total CDEBUG() size is larger than a page, it
864 * will print a warning to the console, avoid this by
865 * printing just the last part of the symlink. */
866 CDEBUG(D_INODE, "symlink dest %s%.*s, len = %d\n",
867 print_limit < rc ? "..." : "", print_limit,
868 (char *)ma->ma_lmm + rc - print_limit, rc);
873 if (reqbody->valid & OBD_MD_FLMODEASIZE) {
874 repbody->max_cookiesize = 0;
875 repbody->max_mdsize = info->mti_mdt->mdt_max_mdsize;
876 repbody->valid |= OBD_MD_FLMODEASIZE;
877 CDEBUG(D_INODE, "I am going to change the MAX_MD_SIZE & "
878 "MAX_COOKIE to : %d:%d\n", repbody->max_mdsize,
879 repbody->max_cookiesize);
882 if (exp_connect_rmtclient(info->mti_exp) &&
883 reqbody->valid & OBD_MD_FLRMTPERM) {
884 void *buf = req_capsule_server_get(pill, &RMF_ACL);
886 /* mdt_getattr_lock only */
887 rc = mdt_pack_remote_perm(info, o, buf);
889 repbody->valid &= ~OBD_MD_FLRMTPERM;
890 repbody->aclsize = 0;
893 repbody->valid |= OBD_MD_FLRMTPERM;
894 repbody->aclsize = sizeof(struct mdt_remote_perm);
897 #ifdef CONFIG_FS_POSIX_ACL
898 else if ((req->rq_export->exp_connect_flags & OBD_CONNECT_ACL) &&
899 (reqbody->valid & OBD_MD_FLACL)) {
900 buffer->lb_buf = req_capsule_server_get(pill, &RMF_ACL);
901 buffer->lb_len = req_capsule_get_size(pill,
902 &RMF_ACL, RCL_SERVER);
903 if (buffer->lb_len > 0) {
904 rc = mo_xattr_get(env, next, buffer,
905 XATTR_NAME_ACL_ACCESS);
907 if (rc == -ENODATA) {
908 repbody->aclsize = 0;
909 repbody->valid |= OBD_MD_FLACL;
911 } else if (rc == -EOPNOTSUPP) {
914 CERROR("got acl size: %d\n", rc);
917 repbody->aclsize = rc;
918 repbody->valid |= OBD_MD_FLACL;
925 if (reqbody->valid & OBD_MD_FLMDSCAPA &&
926 info->mti_mdt->mdt_opts.mo_mds_capa &&
927 info->mti_exp->exp_connect_flags & OBD_CONNECT_MDS_CAPA) {
928 struct lustre_capa *capa;
930 capa = req_capsule_server_get(pill, &RMF_CAPA1);
932 capa->lc_opc = CAPA_OPC_MDS_DEFAULT;
933 rc = mo_capa_get(env, next, capa, 0);
936 repbody->valid |= OBD_MD_FLMDSCAPA;
941 mdt_counter_incr(req, LPROC_MDT_GETATTR);
946 static int mdt_renew_capa(struct mdt_thread_info *info)
948 struct mdt_object *obj = info->mti_object;
949 struct mdt_body *body;
950 struct lustre_capa *capa, *c;
954 /* if object doesn't exist, or server has disabled capability,
955 * return directly, client will find body->valid OBD_MD_FLOSSCAPA
958 if (!obj || !info->mti_mdt->mdt_opts.mo_oss_capa ||
959 !(info->mti_exp->exp_connect_flags & OBD_CONNECT_OSS_CAPA))
962 body = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
963 LASSERT(body != NULL);
965 c = req_capsule_client_get(info->mti_pill, &RMF_CAPA1);
968 capa = req_capsule_server_get(info->mti_pill, &RMF_CAPA2);
972 rc = mo_capa_get(info->mti_env, mdt_object_child(obj), capa, 1);
974 body->valid |= OBD_MD_FLOSSCAPA;
978 static int mdt_getattr(struct mdt_thread_info *info)
980 struct mdt_object *obj = info->mti_object;
981 struct req_capsule *pill = info->mti_pill;
982 struct mdt_body *reqbody;
983 struct mdt_body *repbody;
988 reqbody = req_capsule_client_get(pill, &RMF_MDT_BODY);
991 if (reqbody->valid & OBD_MD_FLOSSCAPA) {
992 rc = req_capsule_server_pack(pill);
994 RETURN(err_serious(rc));
995 rc = mdt_renew_capa(info);
996 GOTO(out_shrink, rc);
999 LASSERT(obj != NULL);
1000 LASSERT(lu_object_assert_exists(&obj->mot_obj.mo_lu));
1002 mode = lu_object_attr(&obj->mot_obj.mo_lu);
1004 /* old clients may not report needed easize, use max value then */
1005 req_capsule_set_size(pill, &RMF_MDT_MD, RCL_SERVER,
1006 reqbody->eadatasize == 0 ?
1007 info->mti_mdt->mdt_max_mdsize :
1008 reqbody->eadatasize);
1010 rc = req_capsule_server_pack(pill);
1011 if (unlikely(rc != 0))
1012 RETURN(err_serious(rc));
1014 repbody = req_capsule_server_get(pill, &RMF_MDT_BODY);
1015 LASSERT(repbody != NULL);
1016 repbody->eadatasize = 0;
1017 repbody->aclsize = 0;
1019 if (reqbody->valid & OBD_MD_FLRMTPERM)
1020 rc = mdt_init_ucred(info, reqbody);
1022 rc = mdt_check_ucred(info);
1024 GOTO(out_shrink, rc);
1026 info->mti_cross_ref = !!(reqbody->valid & OBD_MD_FLCROSSREF);
1029 * Don't check capability at all, because rename might getattr for
1030 * remote obj, and at that time no capability is available.
1032 mdt_set_capainfo(info, 1, &reqbody->fid1, BYPASS_CAPA);
1033 rc = mdt_getattr_internal(info, obj, 0);
1034 if (reqbody->valid & OBD_MD_FLRMTPERM)
1035 mdt_exit_ucred(info);
1038 mdt_client_compatibility(info);
1039 rc2 = mdt_fix_reply(info);
1045 static int mdt_is_subdir(struct mdt_thread_info *info)
1047 struct mdt_object *o = info->mti_object;
1048 struct req_capsule *pill = info->mti_pill;
1049 const struct mdt_body *body = info->mti_body;
1050 struct mdt_body *repbody;
1056 repbody = req_capsule_server_get(pill, &RMF_MDT_BODY);
1059 * We save last checked parent fid to @repbody->fid1 for remote
1062 LASSERT(fid_is_sane(&body->fid2));
1063 LASSERT(mdt_object_exists(o) > 0);
1064 rc = mdo_is_subdir(info->mti_env, mdt_object_child(o),
1065 &body->fid2, &repbody->fid1);
1066 if (rc == 0 || rc == -EREMOTE)
1067 repbody->valid |= OBD_MD_FLID;
1072 static int mdt_raw_lookup(struct mdt_thread_info *info,
1073 struct mdt_object *parent,
1074 const struct lu_name *lname,
1075 struct ldlm_reply *ldlm_rep)
1077 struct md_object *next = mdt_object_child(info->mti_object);
1078 const struct mdt_body *reqbody = info->mti_body;
1079 struct lu_fid *child_fid = &info->mti_tmp_fid1;
1080 struct mdt_body *repbody;
1084 if (reqbody->valid != OBD_MD_FLID)
1087 LASSERT(!info->mti_cross_ref);
1089 /* Only got the fid of this obj by name */
1090 fid_zero(child_fid);
1091 rc = mdo_lookup(info->mti_env, next, lname, child_fid,
1094 /* XXX is raw_lookup possible as intent operation? */
1097 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_NEG);
1100 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_POS);
1102 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
1105 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
1106 repbody->fid1 = *child_fid;
1107 repbody->valid = OBD_MD_FLID;
1113 * UPDATE lock should be taken against parent, and be release before exit;
1114 * child_bits lock should be taken against child, and be returned back:
1115 * (1)normal request should release the child lock;
1116 * (2)intent request will grant the lock to client.
1118 static int mdt_getattr_name_lock(struct mdt_thread_info *info,
1119 struct mdt_lock_handle *lhc,
1121 struct ldlm_reply *ldlm_rep)
1123 struct ptlrpc_request *req = mdt_info_req(info);
1124 struct mdt_body *reqbody = NULL;
1125 struct mdt_object *parent = info->mti_object;
1126 struct mdt_object *child;
1127 struct md_object *next = mdt_object_child(parent);
1128 struct lu_fid *child_fid = &info->mti_tmp_fid1;
1129 struct lu_name *lname = NULL;
1130 const char *name = NULL;
1132 struct mdt_lock_handle *lhp = NULL;
1133 struct ldlm_lock *lock;
1134 struct ldlm_res_id *res_id;
1141 is_resent = lustre_handle_is_used(&lhc->mlh_reg_lh);
1142 LASSERT(ergo(is_resent,
1143 lustre_msg_get_flags(req->rq_reqmsg) & MSG_RESENT));
1145 LASSERT(parent != NULL);
1146 name = req_capsule_client_get(info->mti_pill, &RMF_NAME);
1148 RETURN(err_serious(-EFAULT));
1150 namelen = req_capsule_get_size(info->mti_pill, &RMF_NAME,
1152 if (!info->mti_cross_ref) {
1154 * XXX: Check for "namelen == 0" is for getattr by fid
1155 * (OBD_CONNECT_ATTRFID), otherwise do not allow empty name,
1156 * that is the name must contain at least one character and
1157 * the terminating '\0'
1160 reqbody = req_capsule_client_get(info->mti_pill,
1162 if (unlikely(reqbody == NULL))
1163 RETURN(err_serious(-EFAULT));
1165 if (unlikely(!fid_is_sane(&reqbody->fid2)))
1166 RETURN(err_serious(-EINVAL));
1169 CDEBUG(D_INODE, "getattr with lock for "DFID"/"DFID", "
1171 PFID(mdt_object_fid(parent)),
1172 PFID(&reqbody->fid2), ldlm_rep);
1174 lname = mdt_name(info->mti_env, (char *)name, namelen);
1175 CDEBUG(D_INODE, "getattr with lock for "DFID"/%s, "
1176 "ldlm_rep = %p\n", PFID(mdt_object_fid(parent)),
1180 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_EXECD);
1182 rc = mdt_object_exists(parent);
1183 if (unlikely(rc == 0)) {
1184 LU_OBJECT_DEBUG(D_INODE, info->mti_env,
1185 &parent->mot_obj.mo_lu,
1186 "Parent doesn't exist!\n");
1188 } else if (!info->mti_cross_ref) {
1189 LASSERTF(rc > 0, "Parent "DFID" is on remote server\n",
1190 PFID(mdt_object_fid(parent)));
1193 rc = mdt_raw_lookup(info, parent, lname, ldlm_rep);
1201 if (info->mti_cross_ref) {
1202 /* Only getattr on the child. Parent is on another node. */
1203 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_POS);
1205 CDEBUG(D_INODE, "partial getattr_name child_fid = "DFID", "
1206 "ldlm_rep=%p\n", PFID(mdt_object_fid(child)), ldlm_rep);
1209 /* Do not take lock for resent case. */
1210 lock = ldlm_handle2lock(&lhc->mlh_reg_lh);
1211 LASSERTF(lock != NULL, "Invalid lock handle "LPX64"\n",
1212 lhc->mlh_reg_lh.cookie);
1213 LASSERT(fid_res_name_eq(mdt_object_fid(child),
1214 &lock->l_resource->lr_name));
1215 LDLM_LOCK_PUT(lock);
1218 mdt_lock_handle_init(lhc);
1219 mdt_lock_reg_init(lhc, LCK_PR);
1222 * Object's name is on another MDS, no lookup lock is
1223 * needed here but update is.
1225 child_bits &= ~MDS_INODELOCK_LOOKUP;
1226 child_bits |= MDS_INODELOCK_UPDATE;
1228 rc = mdt_object_lock(info, child, lhc, child_bits,
1232 /* Finally, we can get attr for child. */
1233 mdt_set_capainfo(info, 0, mdt_object_fid(child),
1235 rc = mdt_getattr_internal(info, child, 0);
1236 if (unlikely(rc != 0))
1237 mdt_object_unlock(info, child, lhc, 1);
1243 /* step 1: lock parent only if parent is a directory */
1244 if (S_ISDIR(lu_object_attr(&parent->mot_obj.mo_lu))) {
1245 lhp = &info->mti_lh[MDT_LH_PARENT];
1246 mdt_lock_pdo_init(lhp, LCK_PR, name, namelen);
1247 rc = mdt_object_lock(info, parent, lhp,
1248 MDS_INODELOCK_UPDATE,
1250 if (unlikely(rc != 0))
1254 /* step 2: lookup child's fid by name */
1255 fid_zero(child_fid);
1256 rc = mdo_lookup(info->mti_env, next, lname, child_fid,
1261 mdt_set_disposition(info, ldlm_rep,
1263 GOTO(out_parent, rc);
1265 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_POS);
1267 *child_fid = reqbody->fid2;
1268 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_POS);
1272 *step 3: find the child object by fid & lock it.
1273 * regardless if it is local or remote.
1275 child = mdt_object_find(info->mti_env, info->mti_mdt, child_fid);
1277 if (unlikely(IS_ERR(child)))
1278 GOTO(out_parent, rc = PTR_ERR(child));
1280 /* Do not take lock for resent case. */
1281 lock = ldlm_handle2lock(&lhc->mlh_reg_lh);
1282 LASSERTF(lock != NULL, "Invalid lock handle "LPX64"\n",
1283 lhc->mlh_reg_lh.cookie);
1285 res_id = &lock->l_resource->lr_name;
1286 if (!fid_res_name_eq(mdt_object_fid(child),
1287 &lock->l_resource->lr_name)) {
1288 LASSERTF(fid_res_name_eq(mdt_object_fid(parent),
1289 &lock->l_resource->lr_name),
1290 "Lock res_id: %lu/%lu/%lu, Fid: "DFID".\n",
1291 (unsigned long)res_id->name[0],
1292 (unsigned long)res_id->name[1],
1293 (unsigned long)res_id->name[2],
1294 PFID(mdt_object_fid(parent)));
1295 CWARN("Although resent, but still not get child lock"
1296 "parent:"DFID" child:"DFID"\n",
1297 PFID(mdt_object_fid(parent)),
1298 PFID(mdt_object_fid(child)));
1299 lustre_msg_clear_flags(req->rq_reqmsg, MSG_RESENT);
1300 LDLM_LOCK_PUT(lock);
1303 LDLM_LOCK_PUT(lock);
1307 OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_RESEND, obd_timeout*2);
1308 mdt_lock_handle_init(lhc);
1309 if (child_bits == MDS_INODELOCK_LAYOUT)
1310 mdt_lock_reg_init(lhc, LCK_CR);
1312 mdt_lock_reg_init(lhc, LCK_PR);
1314 if (mdt_object_exists(child) == 0) {
1315 LU_OBJECT_DEBUG(D_INODE, info->mti_env,
1316 &child->mot_obj.mo_lu,
1317 "Object doesn't exist!\n");
1318 GOTO(out_child, rc = -ENOENT);
1321 if (!(child_bits & MDS_INODELOCK_UPDATE)) {
1322 struct md_attr *ma = &info->mti_attr;
1325 ma->ma_need = MA_INODE;
1326 rc = mdt_attr_get_complex(info, child, ma);
1327 if (unlikely(rc != 0))
1328 GOTO(out_child, rc);
1330 /* layout lock is used only on regular files */
1331 if ((ma->ma_valid & MA_INODE) &&
1332 (ma->ma_attr.la_valid & LA_MODE) &&
1333 !S_ISREG(ma->ma_attr.la_mode))
1334 child_bits &= ~MDS_INODELOCK_LAYOUT;
1336 /* If the file has not been changed for some time, we
1337 * return not only a LOOKUP lock, but also an UPDATE
1338 * lock and this might save us RPC on later STAT. For
1339 * directories, it also let negative dentry starts
1340 * working for this dir. */
1341 if (ma->ma_valid & MA_INODE &&
1342 ma->ma_attr.la_valid & LA_CTIME &&
1343 info->mti_mdt->mdt_namespace->ns_ctime_age_limit +
1344 ma->ma_attr.la_ctime < cfs_time_current_sec())
1345 child_bits |= MDS_INODELOCK_UPDATE;
1348 rc = mdt_object_lock(info, child, lhc, child_bits,
1351 if (unlikely(rc != 0))
1352 GOTO(out_child, rc);
1355 lock = ldlm_handle2lock(&lhc->mlh_reg_lh);
1356 /* Get MA_SOM attributes if update lock is given. */
1358 lock->l_policy_data.l_inodebits.bits & MDS_INODELOCK_UPDATE &&
1359 S_ISREG(lu_object_attr(&mdt_object_child(child)->mo_lu)))
1362 /* finally, we can get attr for child. */
1363 mdt_set_capainfo(info, 1, child_fid, BYPASS_CAPA);
1364 rc = mdt_getattr_internal(info, child, ma_need);
1365 if (unlikely(rc != 0)) {
1366 mdt_object_unlock(info, child, lhc, 1);
1368 /* Debugging code. */
1369 res_id = &lock->l_resource->lr_name;
1370 LDLM_DEBUG(lock, "Returning lock to client");
1371 LASSERTF(fid_res_name_eq(mdt_object_fid(child),
1372 &lock->l_resource->lr_name),
1373 "Lock res_id: %lu/%lu/%lu, Fid: "DFID".\n",
1374 (unsigned long)res_id->name[0],
1375 (unsigned long)res_id->name[1],
1376 (unsigned long)res_id->name[2],
1377 PFID(mdt_object_fid(child)));
1378 mdt_pack_size2body(info, child);
1381 LDLM_LOCK_PUT(lock);
1385 mdt_object_put(info->mti_env, child);
1388 mdt_object_unlock(info, parent, lhp, 1);
1392 /* normal handler: should release the child lock */
1393 static int mdt_getattr_name(struct mdt_thread_info *info)
1395 struct mdt_lock_handle *lhc = &info->mti_lh[MDT_LH_CHILD];
1396 struct mdt_body *reqbody;
1397 struct mdt_body *repbody;
1401 reqbody = req_capsule_client_get(info->mti_pill, &RMF_MDT_BODY);
1402 LASSERT(reqbody != NULL);
1403 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
1404 LASSERT(repbody != NULL);
1406 info->mti_cross_ref = !!(reqbody->valid & OBD_MD_FLCROSSREF);
1407 repbody->eadatasize = 0;
1408 repbody->aclsize = 0;
1410 rc = mdt_init_ucred(info, reqbody);
1412 GOTO(out_shrink, rc);
1414 rc = mdt_getattr_name_lock(info, lhc, MDS_INODELOCK_UPDATE, NULL);
1415 if (lustre_handle_is_used(&lhc->mlh_reg_lh)) {
1416 ldlm_lock_decref(&lhc->mlh_reg_lh, lhc->mlh_reg_mode);
1417 lhc->mlh_reg_lh.cookie = 0;
1419 mdt_exit_ucred(info);
1422 mdt_client_compatibility(info);
1423 rc2 = mdt_fix_reply(info);
1429 static const struct lu_device_operations mdt_lu_ops;
1431 static int lu_device_is_mdt(struct lu_device *d)
1433 return ergo(d != NULL && d->ld_ops != NULL, d->ld_ops == &mdt_lu_ops);
1436 static int mdt_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
1437 void *karg, void *uarg);
1439 static int mdt_set_info(struct mdt_thread_info *info)
1441 struct ptlrpc_request *req = mdt_info_req(info);
1444 int keylen, vallen, rc = 0;
1447 rc = req_capsule_server_pack(info->mti_pill);
1451 key = req_capsule_client_get(info->mti_pill, &RMF_SETINFO_KEY);
1453 DEBUG_REQ(D_HA, req, "no set_info key");
1457 keylen = req_capsule_get_size(info->mti_pill, &RMF_SETINFO_KEY,
1460 val = req_capsule_client_get(info->mti_pill, &RMF_SETINFO_VAL);
1462 DEBUG_REQ(D_HA, req, "no set_info val");
1466 vallen = req_capsule_get_size(info->mti_pill, &RMF_SETINFO_VAL,
1469 /* Swab any part of val you need to here */
1470 if (KEY_IS(KEY_READ_ONLY)) {
1472 lustre_msg_set_status(req->rq_repmsg, 0);
1474 cfs_spin_lock(&req->rq_export->exp_lock);
1476 req->rq_export->exp_connect_flags |= OBD_CONNECT_RDONLY;
1478 req->rq_export->exp_connect_flags &=~OBD_CONNECT_RDONLY;
1479 cfs_spin_unlock(&req->rq_export->exp_lock);
1481 } else if (KEY_IS(KEY_CHANGELOG_CLEAR)) {
1482 struct changelog_setinfo *cs =
1483 (struct changelog_setinfo *)val;
1484 if (vallen != sizeof(*cs)) {
1485 CERROR("Bad changelog_clear setinfo size %d\n", vallen);
1488 if (ptlrpc_req_need_swab(req)) {
1489 __swab64s(&cs->cs_recno);
1490 __swab32s(&cs->cs_id);
1493 rc = mdt_iocontrol(OBD_IOC_CHANGELOG_CLEAR, info->mti_exp,
1495 lustre_msg_set_status(req->rq_repmsg, rc);
1503 static int mdt_connect(struct mdt_thread_info *info)
1506 struct ptlrpc_request *req;
1508 req = mdt_info_req(info);
1509 rc = target_handle_connect(req);
1511 LASSERT(req->rq_export != NULL);
1512 info->mti_mdt = mdt_dev(req->rq_export->exp_obd->obd_lu_dev);
1513 rc = mdt_init_sec_level(info);
1515 rc = mdt_init_idmap(info);
1517 obd_disconnect(class_export_get(req->rq_export));
1519 rc = err_serious(rc);
1524 static int mdt_disconnect(struct mdt_thread_info *info)
1529 rc = target_handle_disconnect(mdt_info_req(info));
1531 rc = err_serious(rc);
1535 static int mdt_sendpage(struct mdt_thread_info *info,
1536 struct lu_rdpg *rdpg, int nob)
1538 struct ptlrpc_request *req = mdt_info_req(info);
1539 struct obd_export *exp = req->rq_export;
1540 struct ptlrpc_bulk_desc *desc;
1541 struct l_wait_info *lwi = &info->mti_u.rdpg.mti_wait_info;
1548 desc = ptlrpc_prep_bulk_exp(req, rdpg->rp_npages, BULK_PUT_SOURCE,
1553 if (!(exp->exp_connect_flags & OBD_CONNECT_BRW_SIZE))
1554 /* old client requires reply size in it's PAGE_SIZE,
1555 * which is rdpg->rp_count */
1556 nob = rdpg->rp_count;
1558 for (i = 0, tmpcount = nob; i < rdpg->rp_npages && tmpcount > 0;
1559 i++, tmpcount -= tmpsize) {
1560 tmpsize = min_t(int, tmpcount, CFS_PAGE_SIZE);
1561 ptlrpc_prep_bulk_page_pin(desc, rdpg->rp_pages[i], 0, tmpsize);
1564 LASSERT(desc->bd_nob == nob);
1565 rc = target_bulk_io(exp, desc, lwi);
1566 ptlrpc_free_bulk_pin(desc);
1570 static int mdt_readpage(struct mdt_thread_info *info)
1572 struct mdt_object *object = info->mti_object;
1573 struct lu_rdpg *rdpg = &info->mti_u.rdpg.mti_rdpg;
1574 struct mdt_body *reqbody;
1575 struct mdt_body *repbody;
1580 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_READPAGE_PACK))
1581 RETURN(err_serious(-ENOMEM));
1583 reqbody = req_capsule_client_get(info->mti_pill, &RMF_MDT_BODY);
1584 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
1585 if (reqbody == NULL || repbody == NULL)
1586 RETURN(err_serious(-EFAULT));
1589 * prepare @rdpg before calling lower layers and transfer itself. Here
1590 * reqbody->size contains offset of where to start to read and
1591 * reqbody->nlink contains number bytes to read.
1593 rdpg->rp_hash = reqbody->size;
1594 if (rdpg->rp_hash != reqbody->size) {
1595 CERROR("Invalid hash: "LPX64" != "LPX64"\n",
1596 rdpg->rp_hash, reqbody->size);
1600 rdpg->rp_attrs = reqbody->mode;
1601 if (info->mti_exp->exp_connect_flags & OBD_CONNECT_64BITHASH)
1602 rdpg->rp_attrs |= LUDA_64BITHASH;
1603 rdpg->rp_count = min_t(unsigned int, reqbody->nlink,
1604 PTLRPC_MAX_BRW_SIZE);
1605 rdpg->rp_npages = (rdpg->rp_count + CFS_PAGE_SIZE - 1) >>
1607 OBD_ALLOC(rdpg->rp_pages, rdpg->rp_npages * sizeof rdpg->rp_pages[0]);
1608 if (rdpg->rp_pages == NULL)
1611 for (i = 0; i < rdpg->rp_npages; ++i) {
1612 rdpg->rp_pages[i] = cfs_alloc_page(CFS_ALLOC_STD);
1613 if (rdpg->rp_pages[i] == NULL)
1614 GOTO(free_rdpg, rc = -ENOMEM);
1617 /* call lower layers to fill allocated pages with directory data */
1618 rc = mo_readpage(info->mti_env, mdt_object_child(object), rdpg);
1620 GOTO(free_rdpg, rc);
1622 /* send pages to client */
1623 rc = mdt_sendpage(info, rdpg, rc);
1628 for (i = 0; i < rdpg->rp_npages; i++)
1629 if (rdpg->rp_pages[i] != NULL)
1630 cfs_free_page(rdpg->rp_pages[i]);
1631 OBD_FREE(rdpg->rp_pages, rdpg->rp_npages * sizeof rdpg->rp_pages[0]);
1633 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_SENDPAGE))
1639 static int mdt_reint_internal(struct mdt_thread_info *info,
1640 struct mdt_lock_handle *lhc,
1643 struct req_capsule *pill = info->mti_pill;
1644 struct mdt_body *repbody;
1649 rc = mdt_reint_unpack(info, op);
1651 CERROR("Can't unpack reint, rc %d\n", rc);
1652 RETURN(err_serious(rc));
1655 /* for replay (no_create) lmm is not needed, client has it already */
1656 if (req_capsule_has_field(pill, &RMF_MDT_MD, RCL_SERVER))
1657 req_capsule_set_size(pill, &RMF_MDT_MD, RCL_SERVER,
1658 info->mti_rr.rr_eadatalen);
1660 /* llog cookies are always 0, the field is kept for compatibility */
1661 if (req_capsule_has_field(pill, &RMF_LOGCOOKIES, RCL_SERVER))
1662 req_capsule_set_size(pill, &RMF_LOGCOOKIES, RCL_SERVER, 0);
1664 rc = req_capsule_server_pack(pill);
1666 CERROR("Can't pack response, rc %d\n", rc);
1667 RETURN(err_serious(rc));
1670 if (req_capsule_has_field(pill, &RMF_MDT_BODY, RCL_SERVER)) {
1671 repbody = req_capsule_server_get(pill, &RMF_MDT_BODY);
1673 repbody->eadatasize = 0;
1674 repbody->aclsize = 0;
1677 OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_REINT_DELAY, 10);
1679 /* for replay no cookkie / lmm need, because client have this already */
1680 if (info->mti_spec.no_create)
1681 if (req_capsule_has_field(pill, &RMF_MDT_MD, RCL_SERVER))
1682 req_capsule_set_size(pill, &RMF_MDT_MD, RCL_SERVER, 0);
1684 rc = mdt_init_ucred_reint(info);
1686 GOTO(out_shrink, rc);
1688 rc = mdt_fix_attr_ucred(info, op);
1690 GOTO(out_ucred, rc = err_serious(rc));
1692 if (mdt_check_resent(info, mdt_reconstruct, lhc)) {
1693 rc = lustre_msg_get_status(mdt_info_req(info)->rq_repmsg);
1694 GOTO(out_ucred, rc);
1696 rc = mdt_reint_rec(info, lhc);
1699 mdt_exit_ucred(info);
1701 mdt_client_compatibility(info);
1702 rc2 = mdt_fix_reply(info);
1708 static long mdt_reint_opcode(struct mdt_thread_info *info,
1709 const struct req_format **fmt)
1711 struct mdt_rec_reint *rec;
1714 opc = err_serious(-EFAULT);
1715 rec = req_capsule_client_get(info->mti_pill, &RMF_REC_REINT);
1717 opc = rec->rr_opcode;
1718 DEBUG_REQ(D_INODE, mdt_info_req(info), "reint opt = %ld", opc);
1719 if (opc < REINT_MAX && fmt[opc] != NULL)
1720 req_capsule_extend(info->mti_pill, fmt[opc]);
1722 CERROR("Unsupported opc: %ld\n", opc);
1723 opc = err_serious(opc);
1729 static int mdt_reint(struct mdt_thread_info *info)
1734 static const struct req_format *reint_fmts[REINT_MAX] = {
1735 [REINT_SETATTR] = &RQF_MDS_REINT_SETATTR,
1736 [REINT_CREATE] = &RQF_MDS_REINT_CREATE,
1737 [REINT_LINK] = &RQF_MDS_REINT_LINK,
1738 [REINT_UNLINK] = &RQF_MDS_REINT_UNLINK,
1739 [REINT_RENAME] = &RQF_MDS_REINT_RENAME,
1740 [REINT_OPEN] = &RQF_MDS_REINT_OPEN,
1741 [REINT_SETXATTR] = &RQF_MDS_REINT_SETXATTR
1746 opc = mdt_reint_opcode(info, reint_fmts);
1749 * No lock possible here from client to pass it to reint code
1752 rc = mdt_reint_internal(info, NULL, opc);
1757 info->mti_fail_id = OBD_FAIL_MDS_REINT_NET_REP;
1761 /* this should sync the whole device */
1762 static int mdt_device_sync(const struct lu_env *env, struct mdt_device *mdt)
1764 struct dt_device *dt = mdt->mdt_bottom;
1768 rc = dt->dd_ops->dt_sync(env, dt);
1772 /* this should sync this object */
1773 static int mdt_object_sync(struct mdt_thread_info *info)
1775 struct md_object *next;
1779 if (!mdt_object_exists(info->mti_object)) {
1780 CWARN("Non existing object "DFID"!\n",
1781 PFID(mdt_object_fid(info->mti_object)));
1784 next = mdt_object_child(info->mti_object);
1785 rc = mo_object_sync(info->mti_env, next);
1790 static int mdt_sync(struct mdt_thread_info *info)
1792 struct ptlrpc_request *req = mdt_info_req(info);
1793 struct req_capsule *pill = info->mti_pill;
1794 struct mdt_body *body;
1798 /* The fid may be zero, so we req_capsule_set manually */
1799 req_capsule_set(pill, &RQF_MDS_SYNC);
1801 body = req_capsule_client_get(pill, &RMF_MDT_BODY);
1803 RETURN(err_serious(-EINVAL));
1805 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_SYNC_PACK))
1806 RETURN(err_serious(-ENOMEM));
1808 if (fid_seq(&body->fid1) == 0) {
1809 /* sync the whole device */
1810 rc = req_capsule_server_pack(pill);
1812 rc = mdt_device_sync(info->mti_env, info->mti_mdt);
1814 rc = err_serious(rc);
1816 /* sync an object */
1817 rc = mdt_unpack_req_pack_rep(info, HABEO_CORPUS|HABEO_REFERO);
1819 rc = mdt_object_sync(info);
1821 const struct lu_fid *fid;
1822 struct lu_attr *la = &info->mti_attr.ma_attr;
1824 info->mti_attr.ma_need = MA_INODE;
1825 info->mti_attr.ma_valid = 0;
1826 rc = mdt_attr_get_complex(info, info->mti_object,
1829 body = req_capsule_server_get(pill,
1831 fid = mdt_object_fid(info->mti_object);
1832 mdt_pack_attr2body(info, body, la, fid);
1836 rc = err_serious(rc);
1839 mdt_counter_incr(req, LPROC_MDT_SYNC);
1845 * Quotacheck handler.
1846 * in-kernel quotacheck isn't supported any more.
1848 static int mdt_quotacheck(struct mdt_thread_info *info)
1850 struct obd_quotactl *oqctl;
1854 oqctl = req_capsule_client_get(info->mti_pill, &RMF_OBD_QUOTACTL);
1856 RETURN(err_serious(-EPROTO));
1858 rc = req_capsule_server_pack(info->mti_pill);
1860 RETURN(err_serious(rc));
1862 /* deprecated, not used any more */
1863 RETURN(-EOPNOTSUPP);
1867 * Handle quota control requests to consult current usage/limit, but also
1868 * to configure quota enforcement
1870 static int mdt_quotactl(struct mdt_thread_info *info)
1872 struct obd_export *exp = info->mti_exp;
1873 struct req_capsule *pill = info->mti_pill;
1874 struct obd_quotactl *oqctl, *repoqc;
1876 struct lu_device *qmt = info->mti_mdt->mdt_qmt_dev;
1879 oqctl = req_capsule_client_get(pill, &RMF_OBD_QUOTACTL);
1881 RETURN(err_serious(-EPROTO));
1883 rc = req_capsule_server_pack(pill);
1885 RETURN(err_serious(rc));
1887 switch (oqctl->qc_cmd) {
1889 case LUSTRE_Q_INVALIDATE:
1890 case LUSTRE_Q_FINVALIDATE:
1894 /* deprecated, not used any more */
1895 RETURN(-EOPNOTSUPP);
1896 /* master quotactl */
1902 RETURN(-EOPNOTSUPP);
1903 /* slave quotactl */
1908 CERROR("Unsupported quotactl command: %d\n", oqctl->qc_cmd);
1912 /* map uid/gid for remote client */
1914 if (exp_connect_rmtclient(exp)) {
1915 struct lustre_idmap_table *idmap;
1917 idmap = mdt_req2med(mdt_info_req(info))->med_idmap;
1919 if (unlikely(oqctl->qc_cmd != Q_GETQUOTA &&
1920 oqctl->qc_cmd != Q_GETINFO))
1923 if (oqctl->qc_type == USRQUOTA)
1924 id = lustre_idmap_lookup_uid(NULL, idmap, 0,
1926 else if (oqctl->qc_type == GRPQUOTA)
1927 id = lustre_idmap_lookup_gid(NULL, idmap, 0,
1932 if (id == CFS_IDMAP_NOTFOUND) {
1933 CDEBUG(D_QUOTA, "no mapping for id %u\n", oqctl->qc_id);
1938 repoqc = req_capsule_server_get(pill, &RMF_OBD_QUOTACTL);
1940 RETURN(err_serious(-EFAULT));
1942 if (oqctl->qc_id != id)
1943 swap(oqctl->qc_id, id);
1945 switch (oqctl->qc_cmd) {
1951 /* forward quotactl request to QMT */
1952 rc = qmt_hdls.qmth_quotactl(info->mti_env, qmt, oqctl);
1957 /* slave quotactl */
1958 rc = lquotactl_slv(info->mti_env, info->mti_mdt->mdt_bottom,
1963 CERROR("Unsupported quotactl command: %d\n", oqctl->qc_cmd);
1967 if (oqctl->qc_id != id)
1968 swap(oqctl->qc_id, id);
1975 * OBD PING and other handlers.
1977 static int mdt_obd_ping(struct mdt_thread_info *info)
1982 req_capsule_set(info->mti_pill, &RQF_OBD_PING);
1984 rc = target_handle_ping(mdt_info_req(info));
1986 rc = err_serious(rc);
1991 * OBD_IDX_READ handler
1993 static int mdt_obd_idx_read(struct mdt_thread_info *info)
1995 struct mdt_device *mdt = info->mti_mdt;
1996 struct lu_rdpg *rdpg = &info->mti_u.rdpg.mti_rdpg;
1997 struct idx_info *req_ii, *rep_ii;
2001 memset(rdpg, 0, sizeof(*rdpg));
2002 req_capsule_set(info->mti_pill, &RQF_OBD_IDX_READ);
2004 /* extract idx_info buffer from request & reply */
2005 req_ii = req_capsule_client_get(info->mti_pill, &RMF_IDX_INFO);
2006 if (req_ii == NULL || req_ii->ii_magic != IDX_INFO_MAGIC)
2007 RETURN(err_serious(-EPROTO));
2009 rc = req_capsule_server_pack(info->mti_pill);
2011 RETURN(err_serious(rc));
2013 rep_ii = req_capsule_server_get(info->mti_pill, &RMF_IDX_INFO);
2015 RETURN(err_serious(-EFAULT));
2016 rep_ii->ii_magic = IDX_INFO_MAGIC;
2018 /* extract hash to start with */
2019 rdpg->rp_hash = req_ii->ii_hash_start;
2021 /* extract requested attributes */
2022 rdpg->rp_attrs = req_ii->ii_attrs;
2024 /* check that fid packed in request is valid and supported */
2025 if (!fid_is_sane(&req_ii->ii_fid))
2027 rep_ii->ii_fid = req_ii->ii_fid;
2030 rep_ii->ii_flags = req_ii->ii_flags;
2032 /* compute number of pages to allocate, ii_count is the number of 4KB
2034 if (req_ii->ii_count <= 0)
2035 GOTO(out, rc = -EFAULT);
2036 rdpg->rp_count = min_t(unsigned int, req_ii->ii_count << LU_PAGE_SHIFT,
2037 PTLRPC_MAX_BRW_SIZE);
2038 rdpg->rp_npages = (rdpg->rp_count + CFS_PAGE_SIZE -1) >> CFS_PAGE_SHIFT;
2040 /* allocate pages to store the containers */
2041 OBD_ALLOC(rdpg->rp_pages, rdpg->rp_npages * sizeof(rdpg->rp_pages[0]));
2042 if (rdpg->rp_pages == NULL)
2043 GOTO(out, rc = -ENOMEM);
2044 for (i = 0; i < rdpg->rp_npages; i++) {
2045 rdpg->rp_pages[i] = cfs_alloc_page(CFS_ALLOC_STD);
2046 if (rdpg->rp_pages[i] == NULL)
2047 GOTO(out, rc = -ENOMEM);
2050 /* populate pages with key/record pairs */
2051 rc = dt_index_read(info->mti_env, mdt->mdt_bottom, rep_ii, rdpg);
2055 LASSERTF(rc <= rdpg->rp_count, "dt_index_read() returned more than "
2056 "asked %d > %d\n", rc, rdpg->rp_count);
2058 /* send pages to client */
2059 rc = mdt_sendpage(info, rdpg, rc);
2063 if (rdpg->rp_pages) {
2064 for (i = 0; i < rdpg->rp_npages; i++)
2065 if (rdpg->rp_pages[i])
2066 cfs_free_page(rdpg->rp_pages[i]);
2067 OBD_FREE(rdpg->rp_pages,
2068 rdpg->rp_npages * sizeof(rdpg->rp_pages[0]));
2073 static int mdt_obd_log_cancel(struct mdt_thread_info *info)
2075 return err_serious(-EOPNOTSUPP);
2078 static int mdt_obd_qc_callback(struct mdt_thread_info *info)
2080 return err_serious(-EOPNOTSUPP);
2088 /** clone llog ctxt from child (mdd)
2089 * This allows remote llog (replicator) access.
2090 * We can either pass all llog RPCs (eg mdt_llog_create) on to child where the
2091 * context was originally set up, or we can handle them directly.
2092 * I choose the latter, but that means I need any llog
2093 * contexts set up by child to be accessable by the mdt. So we clone the
2094 * context into our context list here.
2096 static int mdt_llog_ctxt_clone(const struct lu_env *env, struct mdt_device *mdt,
2099 struct md_device *next = mdt->mdt_child;
2100 struct llog_ctxt *ctxt;
2103 if (!llog_ctxt_null(mdt2obd_dev(mdt), idx))
2106 rc = next->md_ops->mdo_llog_ctxt_get(env, next, idx, (void **)&ctxt);
2107 if (rc || ctxt == NULL) {
2111 rc = llog_group_set_ctxt(&mdt2obd_dev(mdt)->obd_olg, ctxt, idx);
2113 CERROR("Can't set mdt ctxt %d\n", rc);
2118 static int mdt_llog_ctxt_unclone(const struct lu_env *env,
2119 struct mdt_device *mdt, int idx)
2121 struct llog_ctxt *ctxt;
2123 ctxt = llog_get_context(mdt2obd_dev(mdt), idx);
2126 /* Put once for the get we just did, and once for the clone */
2127 llog_ctxt_put(ctxt);
2128 llog_ctxt_put(ctxt);
2132 static int mdt_llog_create(struct mdt_thread_info *info)
2136 req_capsule_set(info->mti_pill, &RQF_LLOG_ORIGIN_HANDLE_CREATE);
2137 rc = llog_origin_handle_open(mdt_info_req(info));
2138 return (rc < 0 ? err_serious(rc) : rc);
2141 static int mdt_llog_destroy(struct mdt_thread_info *info)
2145 req_capsule_set(info->mti_pill, &RQF_LLOG_ORIGIN_HANDLE_DESTROY);
2146 rc = llog_origin_handle_destroy(mdt_info_req(info));
2147 return (rc < 0 ? err_serious(rc) : rc);
2150 static int mdt_llog_read_header(struct mdt_thread_info *info)
2154 req_capsule_set(info->mti_pill, &RQF_LLOG_ORIGIN_HANDLE_READ_HEADER);
2155 rc = llog_origin_handle_read_header(mdt_info_req(info));
2156 return (rc < 0 ? err_serious(rc) : rc);
2159 static int mdt_llog_next_block(struct mdt_thread_info *info)
2163 req_capsule_set(info->mti_pill, &RQF_LLOG_ORIGIN_HANDLE_NEXT_BLOCK);
2164 rc = llog_origin_handle_next_block(mdt_info_req(info));
2165 return (rc < 0 ? err_serious(rc) : rc);
2168 static int mdt_llog_prev_block(struct mdt_thread_info *info)
2172 req_capsule_set(info->mti_pill, &RQF_LLOG_ORIGIN_HANDLE_PREV_BLOCK);
2173 rc = llog_origin_handle_prev_block(mdt_info_req(info));
2174 return (rc < 0 ? err_serious(rc) : rc);
2181 static struct ldlm_callback_suite cbs = {
2182 .lcs_completion = ldlm_server_completion_ast,
2183 .lcs_blocking = ldlm_server_blocking_ast,
2184 .lcs_glimpse = ldlm_server_glimpse_ast
2187 static int mdt_enqueue(struct mdt_thread_info *info)
2189 struct ptlrpc_request *req;
2193 * info->mti_dlm_req already contains swapped and (if necessary)
2194 * converted dlm request.
2196 LASSERT(info->mti_dlm_req != NULL);
2198 req = mdt_info_req(info);
2199 rc = ldlm_handle_enqueue0(info->mti_mdt->mdt_namespace,
2200 req, info->mti_dlm_req, &cbs);
2201 info->mti_fail_id = OBD_FAIL_LDLM_REPLY;
2202 return rc ? err_serious(rc) : req->rq_status;
2205 static int mdt_convert(struct mdt_thread_info *info)
2208 struct ptlrpc_request *req;
2210 LASSERT(info->mti_dlm_req);
2211 req = mdt_info_req(info);
2212 rc = ldlm_handle_convert0(req, info->mti_dlm_req);
2213 return rc ? err_serious(rc) : req->rq_status;
2216 static int mdt_bl_callback(struct mdt_thread_info *info)
2218 CERROR("bl callbacks should not happen on MDS\n");
2220 return err_serious(-EOPNOTSUPP);
2223 static int mdt_cp_callback(struct mdt_thread_info *info)
2225 CERROR("cp callbacks should not happen on MDS\n");
2227 return err_serious(-EOPNOTSUPP);
2231 * sec context handlers
2233 static int mdt_sec_ctx_handle(struct mdt_thread_info *info)
2237 rc = mdt_handle_idmap(info);
2240 struct ptlrpc_request *req = mdt_info_req(info);
2243 opc = lustre_msg_get_opc(req->rq_reqmsg);
2244 if (opc == SEC_CTX_INIT || opc == SEC_CTX_INIT_CONT)
2245 sptlrpc_svc_ctx_invalidate(req);
2248 CFS_FAIL_TIMEOUT(OBD_FAIL_SEC_CTX_HDL_PAUSE, cfs_fail_val);
2254 * quota request handlers
2256 static int mdt_quota_dqacq(struct mdt_thread_info *info)
2258 struct lu_device *qmt = info->mti_mdt->mdt_qmt_dev;
2263 RETURN(err_serious(-EOPNOTSUPP));
2265 rc = qmt_hdls.qmth_dqacq(info->mti_env, qmt, mdt_info_req(info));
2269 static struct mdt_object *mdt_obj(struct lu_object *o)
2271 LASSERT(lu_device_is_mdt(o->lo_dev));
2272 return container_of0(o, struct mdt_object, mot_obj.mo_lu);
2275 struct mdt_object *mdt_object_new(const struct lu_env *env,
2276 struct mdt_device *d,
2277 const struct lu_fid *f)
2279 struct lu_object_conf conf = { .loc_flags = LOC_F_NEW };
2280 struct lu_object *o;
2281 struct mdt_object *m;
2284 CDEBUG(D_INFO, "Allocate object for "DFID"\n", PFID(f));
2285 o = lu_object_find(env, &d->mdt_md_dev.md_lu_dev, f, &conf);
2286 if (unlikely(IS_ERR(o)))
2287 m = (struct mdt_object *)o;
2293 struct mdt_object *mdt_object_find(const struct lu_env *env,
2294 struct mdt_device *d,
2295 const struct lu_fid *f)
2297 struct lu_object *o;
2298 struct mdt_object *m;
2301 CDEBUG(D_INFO, "Find object for "DFID"\n", PFID(f));
2302 o = lu_object_find(env, &d->mdt_md_dev.md_lu_dev, f, NULL);
2303 if (unlikely(IS_ERR(o)))
2304 m = (struct mdt_object *)o;
2311 * Asyncronous commit for mdt device.
2313 * Pass asynchonous commit call down the MDS stack.
2315 * \param env environment
2316 * \param mdt the mdt device
2318 static void mdt_device_commit_async(const struct lu_env *env,
2319 struct mdt_device *mdt)
2321 struct dt_device *dt = mdt->mdt_bottom;
2324 rc = dt->dd_ops->dt_commit_async(env, dt);
2325 if (unlikely(rc != 0))
2326 CWARN("async commit start failed with rc = %d", rc);
2330 * Mark the lock as "synchonous".
2332 * Mark the lock to deffer transaction commit to the unlock time.
2334 * \param lock the lock to mark as "synchonous"
2336 * \see mdt_is_lock_sync
2337 * \see mdt_save_lock
2339 static inline void mdt_set_lock_sync(struct ldlm_lock *lock)
2341 lock->l_ast_data = (void*)1;
2345 * Check whehter the lock "synchonous" or not.
2347 * \param lock the lock to check
2348 * \retval 1 the lock is "synchonous"
2349 * \retval 0 the lock isn't "synchronous"
2351 * \see mdt_set_lock_sync
2352 * \see mdt_save_lock
2354 static inline int mdt_is_lock_sync(struct ldlm_lock *lock)
2356 return lock->l_ast_data != NULL;
2360 * Blocking AST for mdt locks.
2362 * Starts transaction commit if in case of COS lock conflict or
2363 * deffers such a commit to the mdt_save_lock.
2365 * \param lock the lock which blocks a request or cancelling lock
2366 * \param desc unused
2367 * \param data unused
2368 * \param flag indicates whether this cancelling or blocking callback
2370 * \see ldlm_blocking_ast_nocheck
2372 int mdt_blocking_ast(struct ldlm_lock *lock, struct ldlm_lock_desc *desc,
2373 void *data, int flag)
2375 struct obd_device *obd = ldlm_lock_to_ns(lock)->ns_obd;
2376 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
2380 if (flag == LDLM_CB_CANCELING)
2382 lock_res_and_lock(lock);
2383 if (lock->l_blocking_ast != mdt_blocking_ast) {
2384 unlock_res_and_lock(lock);
2387 if (mdt_cos_is_enabled(mdt) &&
2388 lock->l_req_mode & (LCK_PW | LCK_EX) &&
2389 lock->l_blocking_lock != NULL &&
2390 lock->l_client_cookie != lock->l_blocking_lock->l_client_cookie) {
2391 mdt_set_lock_sync(lock);
2393 rc = ldlm_blocking_ast_nocheck(lock);
2395 /* There is no lock conflict if l_blocking_lock == NULL,
2396 * it indicates a blocking ast sent from ldlm_lock_decref_internal
2397 * when the last reference to a local lock was released */
2398 if (lock->l_req_mode == LCK_COS && lock->l_blocking_lock != NULL) {
2401 rc = lu_env_init(&env, LCT_LOCAL);
2402 if (unlikely(rc != 0))
2403 CWARN("lu_env initialization failed with rc = %d,"
2404 "cannot start asynchronous commit\n", rc);
2406 mdt_device_commit_async(&env, mdt);
2412 int mdt_object_lock(struct mdt_thread_info *info, struct mdt_object *o,
2413 struct mdt_lock_handle *lh, __u64 ibits, int locality)
2415 struct ldlm_namespace *ns = info->mti_mdt->mdt_namespace;
2416 ldlm_policy_data_t *policy = &info->mti_policy;
2417 struct ldlm_res_id *res_id = &info->mti_res_id;
2421 LASSERT(!lustre_handle_is_used(&lh->mlh_reg_lh));
2422 LASSERT(!lustre_handle_is_used(&lh->mlh_pdo_lh));
2423 LASSERT(lh->mlh_reg_mode != LCK_MINMODE);
2424 LASSERT(lh->mlh_type != MDT_NUL_LOCK);
2426 if (mdt_object_exists(o) < 0) {
2427 if (locality == MDT_CROSS_LOCK) {
2428 /* cross-ref object fix */
2429 ibits &= ~MDS_INODELOCK_UPDATE;
2430 ibits |= MDS_INODELOCK_LOOKUP;
2432 LASSERT(!(ibits & MDS_INODELOCK_UPDATE));
2433 LASSERT(ibits & MDS_INODELOCK_LOOKUP);
2435 /* No PDO lock on remote object */
2436 LASSERT(lh->mlh_type != MDT_PDO_LOCK);
2439 if (lh->mlh_type == MDT_PDO_LOCK) {
2440 /* check for exists after object is locked */
2441 if (mdt_object_exists(o) == 0) {
2442 /* Non-existent object shouldn't have PDO lock */
2445 /* Non-dir object shouldn't have PDO lock */
2446 if (!S_ISDIR(lu_object_attr(&o->mot_obj.mo_lu)))
2451 memset(policy, 0, sizeof(*policy));
2452 fid_build_reg_res_name(mdt_object_fid(o), res_id);
2455 * Take PDO lock on whole directory and build correct @res_id for lock
2456 * on part of directory.
2458 if (lh->mlh_pdo_hash != 0) {
2459 LASSERT(lh->mlh_type == MDT_PDO_LOCK);
2460 mdt_lock_pdo_mode(info, o, lh);
2461 if (lh->mlh_pdo_mode != LCK_NL) {
2463 * Do not use LDLM_FL_LOCAL_ONLY for parallel lock, it
2464 * is never going to be sent to client and we do not
2465 * want it slowed down due to possible cancels.
2467 policy->l_inodebits.bits = MDS_INODELOCK_UPDATE;
2468 rc = mdt_fid_lock(ns, &lh->mlh_pdo_lh, lh->mlh_pdo_mode,
2469 policy, res_id, LDLM_FL_ATOMIC_CB,
2470 &info->mti_exp->exp_handle.h_cookie);
2476 * Finish res_id initializing by name hash marking part of
2477 * directory which is taking modification.
2479 res_id->name[LUSTRE_RES_ID_HSH_OFF] = lh->mlh_pdo_hash;
2482 policy->l_inodebits.bits = ibits;
2485 * Use LDLM_FL_LOCAL_ONLY for this lock. We do not know yet if it is
2486 * going to be sent to client. If it is - mdt_intent_policy() path will
2487 * fix it up and turn FL_LOCAL flag off.
2489 rc = mdt_fid_lock(ns, &lh->mlh_reg_lh, lh->mlh_reg_mode, policy,
2490 res_id, LDLM_FL_LOCAL_ONLY | LDLM_FL_ATOMIC_CB,
2491 &info->mti_exp->exp_handle.h_cookie);
2493 mdt_object_unlock(info, o, lh, 1);
2494 else if (unlikely(OBD_FAIL_PRECHECK(OBD_FAIL_MDS_PDO_LOCK)) &&
2495 lh->mlh_pdo_hash != 0 &&
2496 (lh->mlh_reg_mode == LCK_PW || lh->mlh_reg_mode == LCK_EX)) {
2497 OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_PDO_LOCK, 15);
2504 * Save a lock within request object.
2506 * Keep the lock referenced until whether client ACK or transaction
2507 * commit happens or release the lock immediately depending on input
2508 * parameters. If COS is ON, a write lock is converted to COS lock
2511 * \param info thead info object
2512 * \param h lock handle
2513 * \param mode lock mode
2514 * \param decref force immediate lock releasing
2517 void mdt_save_lock(struct mdt_thread_info *info, struct lustre_handle *h,
2518 ldlm_mode_t mode, int decref)
2522 if (lustre_handle_is_used(h)) {
2523 if (decref || !info->mti_has_trans ||
2524 !(mode & (LCK_PW | LCK_EX))){
2525 mdt_fid_unlock(h, mode);
2527 struct mdt_device *mdt = info->mti_mdt;
2528 struct ldlm_lock *lock = ldlm_handle2lock(h);
2529 struct ptlrpc_request *req = mdt_info_req(info);
2532 LASSERTF(lock != NULL, "no lock for cookie "LPX64"\n",
2534 CDEBUG(D_HA, "request = %p reply state = %p"
2535 " transno = "LPD64"\n",
2536 req, req->rq_reply_state, req->rq_transno);
2537 if (mdt_cos_is_enabled(mdt)) {
2539 ldlm_lock_downgrade(lock, LCK_COS);
2542 ptlrpc_save_lock(req, h, mode, no_ack);
2543 if (mdt_is_lock_sync(lock)) {
2544 CDEBUG(D_HA, "found sync-lock,"
2545 " async commit started\n");
2546 mdt_device_commit_async(info->mti_env,
2549 LDLM_LOCK_PUT(lock);
2558 * Unlock mdt object.
2560 * Immeditely release the regular lock and the PDO lock or save the
2561 * lock in reqeuest and keep them referenced until client ACK or
2562 * transaction commit.
2564 * \param info thread info object
2565 * \param o mdt object
2566 * \param lh mdt lock handle referencing regular and PDO locks
2567 * \param decref force immediate lock releasing
2569 void mdt_object_unlock(struct mdt_thread_info *info, struct mdt_object *o,
2570 struct mdt_lock_handle *lh, int decref)
2574 mdt_save_lock(info, &lh->mlh_pdo_lh, lh->mlh_pdo_mode, decref);
2575 mdt_save_lock(info, &lh->mlh_reg_lh, lh->mlh_reg_mode, decref);
2580 struct mdt_object *mdt_object_find_lock(struct mdt_thread_info *info,
2581 const struct lu_fid *f,
2582 struct mdt_lock_handle *lh,
2585 struct mdt_object *o;
2587 o = mdt_object_find(info->mti_env, info->mti_mdt, f);
2591 rc = mdt_object_lock(info, o, lh, ibits,
2594 mdt_object_put(info->mti_env, o);
2601 void mdt_object_unlock_put(struct mdt_thread_info * info,
2602 struct mdt_object * o,
2603 struct mdt_lock_handle *lh,
2606 mdt_object_unlock(info, o, lh, decref);
2607 mdt_object_put(info->mti_env, o);
2610 static struct mdt_handler *mdt_handler_find(__u32 opc,
2611 struct mdt_opc_slice *supported)
2613 struct mdt_opc_slice *s;
2614 struct mdt_handler *h;
2617 for (s = supported; s->mos_hs != NULL; s++) {
2618 if (s->mos_opc_start <= opc && opc < s->mos_opc_end) {
2619 h = s->mos_hs + (opc - s->mos_opc_start);
2620 if (likely(h->mh_opc != 0))
2621 LASSERTF(h->mh_opc == opc,
2622 "opcode mismatch %d != %d\n",
2625 h = NULL; /* unsupported opc */
2632 static int mdt_lock_resname_compat(struct mdt_device *m,
2633 struct ldlm_request *req)
2635 /* XXX something... later. */
2639 static int mdt_lock_reply_compat(struct mdt_device *m, struct ldlm_reply *rep)
2641 /* XXX something... later. */
2646 * Generic code handling requests that have struct mdt_body passed in:
2648 * - extract mdt_body from request and save it in @info, if present;
2650 * - create lu_object, corresponding to the fid in mdt_body, and save it in
2653 * - if HABEO_CORPUS flag is set for this request type check whether object
2654 * actually exists on storage (lu_object_exists()).
2657 static int mdt_body_unpack(struct mdt_thread_info *info, __u32 flags)
2659 const struct mdt_body *body;
2660 struct mdt_object *obj;
2661 const struct lu_env *env;
2662 struct req_capsule *pill;
2666 env = info->mti_env;
2667 pill = info->mti_pill;
2669 body = info->mti_body = req_capsule_client_get(pill, &RMF_MDT_BODY);
2673 if (!(body->valid & OBD_MD_FLID))
2676 if (!fid_is_sane(&body->fid1)) {
2677 CERROR("Invalid fid: "DFID"\n", PFID(&body->fid1));
2682 * Do not get size or any capa fields before we check that request
2683 * contains capa actually. There are some requests which do not, for
2684 * instance MDS_IS_SUBDIR.
2686 if (req_capsule_has_field(pill, &RMF_CAPA1, RCL_CLIENT) &&
2687 req_capsule_get_size(pill, &RMF_CAPA1, RCL_CLIENT))
2688 mdt_set_capainfo(info, 0, &body->fid1,
2689 req_capsule_client_get(pill, &RMF_CAPA1));
2691 obj = mdt_object_find(env, info->mti_mdt, &body->fid1);
2693 if ((flags & HABEO_CORPUS) &&
2694 !mdt_object_exists(obj)) {
2695 mdt_object_put(env, obj);
2696 /* for capability renew ENOENT will be handled in
2698 if (body->valid & OBD_MD_FLOSSCAPA)
2703 info->mti_object = obj;
2712 static int mdt_unpack_req_pack_rep(struct mdt_thread_info *info, __u32 flags)
2714 struct req_capsule *pill = info->mti_pill;
2718 if (req_capsule_has_field(pill, &RMF_MDT_BODY, RCL_CLIENT))
2719 rc = mdt_body_unpack(info, flags);
2723 if (rc == 0 && (flags & HABEO_REFERO)) {
2725 if (req_capsule_has_field(pill, &RMF_MDT_MD, RCL_SERVER))
2726 req_capsule_set_size(pill, &RMF_MDT_MD, RCL_SERVER,
2727 info->mti_body->eadatasize);
2728 if (req_capsule_has_field(pill, &RMF_LOGCOOKIES, RCL_SERVER))
2729 req_capsule_set_size(pill, &RMF_LOGCOOKIES,
2732 rc = req_capsule_server_pack(pill);
2737 static int mdt_init_capa_ctxt(const struct lu_env *env, struct mdt_device *m)
2739 struct md_device *next = m->mdt_child;
2741 return next->md_ops->mdo_init_capa_ctxt(env, next,
2742 m->mdt_opts.mo_mds_capa,
2743 m->mdt_capa_timeout,
2749 * Invoke handler for this request opc. Also do necessary preprocessing
2750 * (according to handler ->mh_flags), and post-processing (setting of
2751 * ->last_{xid,committed}).
2753 static int mdt_req_handle(struct mdt_thread_info *info,
2754 struct mdt_handler *h, struct ptlrpc_request *req)
2756 int rc, serious = 0;
2761 LASSERT(h->mh_act != NULL);
2762 LASSERT(h->mh_opc == lustre_msg_get_opc(req->rq_reqmsg));
2763 LASSERT(current->journal_info == NULL);
2766 * Checking for various OBD_FAIL_$PREF_$OPC_NET codes. _Do_ not try
2767 * to put same checks into handlers like mdt_close(), mdt_reint(),
2768 * etc., without talking to mdt authors first. Checking same thing
2769 * there again is useless and returning 0 error without packing reply
2770 * is buggy! Handlers either pack reply or return error.
2772 * We return 0 here and do not send any reply in order to emulate
2773 * network failure. Do not send any reply in case any of NET related
2774 * fail_id has occured.
2776 if (OBD_FAIL_CHECK_ORSET(h->mh_fail_id, OBD_FAIL_ONCE))
2780 flags = h->mh_flags;
2781 LASSERT(ergo(flags & (HABEO_CORPUS|HABEO_REFERO), h->mh_fmt != NULL));
2783 if (h->mh_fmt != NULL) {
2784 req_capsule_set(info->mti_pill, h->mh_fmt);
2785 rc = mdt_unpack_req_pack_rep(info, flags);
2788 if (rc == 0 && flags & MUTABOR &&
2789 req->rq_export->exp_connect_flags & OBD_CONNECT_RDONLY)
2790 /* should it be rq_status? */
2793 if (rc == 0 && flags & HABEO_CLAVIS) {
2794 struct ldlm_request *dlm_req;
2796 LASSERT(h->mh_fmt != NULL);
2798 dlm_req = req_capsule_client_get(info->mti_pill, &RMF_DLM_REQ);
2799 if (dlm_req != NULL) {
2800 if (unlikely(dlm_req->lock_desc.l_resource.lr_type ==
2802 dlm_req->lock_desc.l_policy_data.\
2803 l_inodebits.bits == 0)) {
2805 * Lock without inodebits makes no sense and
2806 * will oops later in ldlm. If client miss to
2807 * set such bits, do not trigger ASSERTION.
2809 * For liblustre flock case, it maybe zero.
2813 if (info->mti_mdt->mdt_opts.mo_compat_resname)
2814 rc = mdt_lock_resname_compat(
2817 info->mti_dlm_req = dlm_req;
2824 /* capability setting changed via /proc, needs reinitialize ctxt */
2825 if (info->mti_mdt && info->mti_mdt->mdt_capa_conf) {
2826 mdt_init_capa_ctxt(info->mti_env, info->mti_mdt);
2827 info->mti_mdt->mdt_capa_conf = 0;
2830 if (likely(rc == 0)) {
2832 * Process request, there can be two types of rc:
2833 * 1) errors with msg unpack/pack, other failures outside the
2834 * operation itself. This is counted as serious errors;
2835 * 2) errors during fs operation, should be placed in rq_status
2838 rc = h->mh_act(info);
2840 !req->rq_no_reply && req->rq_reply_state == NULL) {
2841 DEBUG_REQ(D_ERROR, req, "MDT \"handler\" %s did not "
2842 "pack reply and returned 0 error\n",
2846 serious = is_serious(rc);
2847 rc = clear_serious(rc);
2851 req->rq_status = rc;
2854 * ELDLM_* codes which > 0 should be in rq_status only as well as
2855 * all non-serious errors.
2857 if (rc > 0 || !serious)
2860 LASSERT(current->journal_info == NULL);
2862 if (rc == 0 && (flags & HABEO_CLAVIS) &&
2863 info->mti_mdt->mdt_opts.mo_compat_resname) {
2864 struct ldlm_reply *dlmrep;
2866 dlmrep = req_capsule_server_get(info->mti_pill, &RMF_DLM_REP);
2868 rc = mdt_lock_reply_compat(info->mti_mdt, dlmrep);
2871 /* If we're DISCONNECTing, the mdt_export_data is already freed */
2872 if (likely(rc == 0 && req->rq_export && h->mh_opc != MDS_DISCONNECT))
2873 target_committed_to_req(req);
2875 if (unlikely(req_is_replay(req) &&
2876 lustre_msg_get_transno(req->rq_reqmsg) == 0)) {
2877 DEBUG_REQ(D_ERROR, req, "transno is 0 during REPLAY");
2881 target_send_reply(req, rc, info->mti_fail_id);
2885 void mdt_lock_handle_init(struct mdt_lock_handle *lh)
2887 lh->mlh_type = MDT_NUL_LOCK;
2888 lh->mlh_reg_lh.cookie = 0ull;
2889 lh->mlh_reg_mode = LCK_MINMODE;
2890 lh->mlh_pdo_lh.cookie = 0ull;
2891 lh->mlh_pdo_mode = LCK_MINMODE;
2894 void mdt_lock_handle_fini(struct mdt_lock_handle *lh)
2896 LASSERT(!lustre_handle_is_used(&lh->mlh_reg_lh));
2897 LASSERT(!lustre_handle_is_used(&lh->mlh_pdo_lh));
2901 * Initialize fields of struct mdt_thread_info. Other fields are left in
2902 * uninitialized state, because it's too expensive to zero out whole
2903 * mdt_thread_info (> 1K) on each request arrival.
2905 static void mdt_thread_info_init(struct ptlrpc_request *req,
2906 struct mdt_thread_info *info)
2909 struct md_capainfo *ci;
2911 req_capsule_init(&req->rq_pill, req, RCL_SERVER);
2912 info->mti_pill = &req->rq_pill;
2915 for (i = 0; i < ARRAY_SIZE(info->mti_lh); i++)
2916 mdt_lock_handle_init(&info->mti_lh[i]);
2918 /* mdt device: it can be NULL while CONNECT */
2919 if (req->rq_export) {
2920 info->mti_mdt = mdt_dev(req->rq_export->exp_obd->obd_lu_dev);
2921 info->mti_exp = req->rq_export;
2923 info->mti_mdt = NULL;
2924 info->mti_env = req->rq_svc_thread->t_env;
2925 ci = md_capainfo(info->mti_env);
2926 memset(ci, 0, sizeof *ci);
2927 if (req->rq_export) {
2928 if (exp_connect_rmtclient(req->rq_export))
2929 ci->mc_auth = LC_ID_CONVERT;
2930 else if (req->rq_export->exp_connect_flags &
2931 OBD_CONNECT_MDS_CAPA)
2932 ci->mc_auth = LC_ID_PLAIN;
2934 ci->mc_auth = LC_ID_NONE;
2937 info->mti_fail_id = OBD_FAIL_MDS_ALL_REPLY_NET;
2938 info->mti_transno = lustre_msg_get_transno(req->rq_reqmsg);
2939 info->mti_mos = NULL;
2941 memset(&info->mti_attr, 0, sizeof(info->mti_attr));
2942 info->mti_body = NULL;
2943 info->mti_object = NULL;
2944 info->mti_dlm_req = NULL;
2945 info->mti_has_trans = 0;
2946 info->mti_cross_ref = 0;
2947 info->mti_opdata = 0;
2948 info->mti_big_lmm_used = 0;
2950 /* To not check for split by default. */
2951 info->mti_spec.no_create = 0;
2954 static void mdt_thread_info_fini(struct mdt_thread_info *info)
2958 req_capsule_fini(info->mti_pill);
2959 if (info->mti_object != NULL) {
2960 mdt_object_put(info->mti_env, info->mti_object);
2961 info->mti_object = NULL;
2963 for (i = 0; i < ARRAY_SIZE(info->mti_lh); i++)
2964 mdt_lock_handle_fini(&info->mti_lh[i]);
2965 info->mti_env = NULL;
2968 static int mdt_filter_recovery_request(struct ptlrpc_request *req,
2969 struct obd_device *obd, int *process)
2971 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
2972 case MDS_CONNECT: /* This will never get here, but for completeness. */
2973 case OST_CONNECT: /* This will never get here, but for completeness. */
2974 case MDS_DISCONNECT:
2975 case OST_DISCONNECT:
2981 case MDS_DONE_WRITING:
2982 case MDS_SYNC: /* used in unmounting */
2988 *process = target_queue_recovery_request(req, obd);
2992 DEBUG_REQ(D_ERROR, req, "not permitted during recovery");
2999 * Handle recovery. Return:
3000 * +1: continue request processing;
3001 * -ve: abort immediately with the given error code;
3002 * 0: send reply with error code in req->rq_status;
3004 static int mdt_recovery(struct mdt_thread_info *info)
3006 struct ptlrpc_request *req = mdt_info_req(info);
3007 struct obd_device *obd;
3011 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
3014 case SEC_CTX_INIT_CONT:
3020 rc = mdt_handle_idmap(info);
3029 if (unlikely(!class_connected_export(req->rq_export))) {
3030 CERROR("operation %d on unconnected MDS from %s\n",
3031 lustre_msg_get_opc(req->rq_reqmsg),
3032 libcfs_id2str(req->rq_peer));
3033 /* FIXME: For CMD cleanup, when mds_B stop, the req from
3034 * mds_A will get -ENOTCONN(especially for ping req),
3035 * which will cause that mds_A deactive timeout, then when
3036 * mds_A cleanup, the cleanup process will be suspended since
3037 * deactive timeout is not zero.
3039 req->rq_status = -ENOTCONN;
3040 target_send_reply(req, -ENOTCONN, info->mti_fail_id);
3044 /* sanity check: if the xid matches, the request must be marked as a
3045 * resent or replayed */
3046 if (req_xid_is_last(req)) {
3047 if (!(lustre_msg_get_flags(req->rq_reqmsg) &
3048 (MSG_RESENT | MSG_REPLAY))) {
3049 DEBUG_REQ(D_WARNING, req, "rq_xid "LPU64" matches last_xid, "
3050 "expected REPLAY or RESENT flag (%x)", req->rq_xid,
3051 lustre_msg_get_flags(req->rq_reqmsg));
3053 req->rq_status = -ENOTCONN;
3058 /* else: note the opposite is not always true; a RESENT req after a
3059 * failover will usually not match the last_xid, since it was likely
3060 * never committed. A REPLAYed request will almost never match the
3061 * last xid, however it could for a committed, but still retained,
3064 obd = req->rq_export->exp_obd;
3066 /* Check for aborted recovery... */
3067 if (unlikely(obd->obd_recovering)) {
3070 DEBUG_REQ(D_INFO, req, "Got new replay");
3071 rc = mdt_filter_recovery_request(req, obd, &should_process);
3072 if (rc != 0 || !should_process)
3074 else if (should_process < 0) {
3075 req->rq_status = should_process;
3076 rc = ptlrpc_error(req);
3083 static int mdt_msg_check_version(struct lustre_msg *msg)
3087 switch (lustre_msg_get_opc(msg)) {
3089 case MDS_DISCONNECT:
3092 case SEC_CTX_INIT_CONT:
3095 rc = lustre_msg_check_version(msg, LUSTRE_OBD_VERSION);
3097 CERROR("bad opc %u version %08x, expecting %08x\n",
3098 lustre_msg_get_opc(msg),
3099 lustre_msg_get_version(msg),
3100 LUSTRE_OBD_VERSION);
3104 case MDS_GETATTR_NAME:
3111 case MDS_DONE_WRITING:
3118 case MDS_QUOTACHECK:
3124 rc = lustre_msg_check_version(msg, LUSTRE_MDS_VERSION);
3126 CERROR("bad opc %u version %08x, expecting %08x\n",
3127 lustre_msg_get_opc(msg),
3128 lustre_msg_get_version(msg),
3129 LUSTRE_MDS_VERSION);
3133 case LDLM_BL_CALLBACK:
3134 case LDLM_CP_CALLBACK:
3135 rc = lustre_msg_check_version(msg, LUSTRE_DLM_VERSION);
3137 CERROR("bad opc %u version %08x, expecting %08x\n",
3138 lustre_msg_get_opc(msg),
3139 lustre_msg_get_version(msg),
3140 LUSTRE_DLM_VERSION);
3142 case OBD_LOG_CANCEL:
3143 case LLOG_ORIGIN_HANDLE_CREATE:
3144 case LLOG_ORIGIN_HANDLE_NEXT_BLOCK:
3145 case LLOG_ORIGIN_HANDLE_READ_HEADER:
3146 case LLOG_ORIGIN_HANDLE_CLOSE:
3147 case LLOG_ORIGIN_HANDLE_DESTROY:
3148 case LLOG_ORIGIN_HANDLE_PREV_BLOCK:
3150 rc = lustre_msg_check_version(msg, LUSTRE_LOG_VERSION);
3152 CERROR("bad opc %u version %08x, expecting %08x\n",
3153 lustre_msg_get_opc(msg),
3154 lustre_msg_get_version(msg),
3155 LUSTRE_LOG_VERSION);
3158 CERROR("MDS unknown opcode %d\n", lustre_msg_get_opc(msg));
3164 static int mdt_handle0(struct ptlrpc_request *req,
3165 struct mdt_thread_info *info,
3166 struct mdt_opc_slice *supported)
3168 struct mdt_handler *h;
3169 struct lustre_msg *msg;
3174 if (OBD_FAIL_CHECK_ORSET(OBD_FAIL_MDS_ALL_REQUEST_NET, OBD_FAIL_ONCE))
3177 LASSERT(current->journal_info == NULL);
3179 msg = req->rq_reqmsg;
3180 rc = mdt_msg_check_version(msg);
3181 if (likely(rc == 0)) {
3182 rc = mdt_recovery(info);
3183 if (likely(rc == +1)) {
3184 h = mdt_handler_find(lustre_msg_get_opc(msg),
3186 if (likely(h != NULL)) {
3187 rc = mdt_req_handle(info, h, req);
3189 CERROR("The unsupported opc: 0x%x\n",
3190 lustre_msg_get_opc(msg) );
3191 req->rq_status = -ENOTSUPP;
3192 rc = ptlrpc_error(req);
3197 CERROR(LUSTRE_MDT_NAME" drops mal-formed request\n");
3202 * MDT handler function called by ptlrpc service thread when request comes.
3204 * XXX common "target" functionality should be factored into separate module
3205 * shared by mdt, ost and stand-alone services like fld.
3207 static int mdt_handle_common(struct ptlrpc_request *req,
3208 struct mdt_opc_slice *supported)
3211 struct mdt_thread_info *info;
3215 env = req->rq_svc_thread->t_env;
3216 LASSERT(env != NULL);
3217 LASSERT(env->le_ses != NULL);
3218 LASSERT(env->le_ctx.lc_thread == req->rq_svc_thread);
3219 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
3220 LASSERT(info != NULL);
3222 mdt_thread_info_init(req, info);
3224 rc = mdt_handle0(req, info, supported);
3226 mdt_thread_info_fini(info);
3231 * This is called from recovery code as handler of _all_ RPC types, FLD and SEQ
3234 int mdt_recovery_handle(struct ptlrpc_request *req)
3239 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
3241 rc = mdt_handle_common(req, mdt_fld_handlers);
3244 rc = mdt_handle_common(req, mdt_seq_handlers);
3247 rc = mdt_handle_common(req, mdt_regular_handlers);
3254 static int mdt_regular_handle(struct ptlrpc_request *req)
3256 return mdt_handle_common(req, mdt_regular_handlers);
3259 static int mdt_readpage_handle(struct ptlrpc_request *req)
3261 return mdt_handle_common(req, mdt_readpage_handlers);
3264 static int mdt_xmds_handle(struct ptlrpc_request *req)
3266 return mdt_handle_common(req, mdt_xmds_handlers);
3269 static int mdt_mdsc_handle(struct ptlrpc_request *req)
3271 return mdt_handle_common(req, mdt_seq_handlers);
3274 static int mdt_mdss_handle(struct ptlrpc_request *req)
3276 return mdt_handle_common(req, mdt_seq_handlers);
3279 static int mdt_dtss_handle(struct ptlrpc_request *req)
3281 return mdt_handle_common(req, mdt_seq_handlers);
3284 static int mdt_fld_handle(struct ptlrpc_request *req)
3286 return mdt_handle_common(req, mdt_fld_handlers);
3304 static int mdt_intent_getattr(enum mdt_it_code opcode,
3305 struct mdt_thread_info *info,
3306 struct ldlm_lock **,
3308 static int mdt_intent_reint(enum mdt_it_code opcode,
3309 struct mdt_thread_info *info,
3310 struct ldlm_lock **,
3313 static struct mdt_it_flavor {
3314 const struct req_format *it_fmt;
3316 int (*it_act)(enum mdt_it_code ,
3317 struct mdt_thread_info *,
3318 struct ldlm_lock **,
3321 } mdt_it_flavor[] = {
3323 .it_fmt = &RQF_LDLM_INTENT,
3324 /*.it_flags = HABEO_REFERO,*/
3326 .it_act = mdt_intent_reint,
3327 .it_reint = REINT_OPEN
3330 .it_fmt = &RQF_LDLM_INTENT,
3331 .it_flags = MUTABOR,
3332 .it_act = mdt_intent_reint,
3333 .it_reint = REINT_OPEN
3336 .it_fmt = &RQF_LDLM_INTENT,
3337 .it_flags = MUTABOR,
3338 .it_act = mdt_intent_reint,
3339 .it_reint = REINT_CREATE
3341 [MDT_IT_GETATTR] = {
3342 .it_fmt = &RQF_LDLM_INTENT_GETATTR,
3343 .it_flags = HABEO_REFERO,
3344 .it_act = mdt_intent_getattr
3346 [MDT_IT_READDIR] = {
3352 .it_fmt = &RQF_LDLM_INTENT_GETATTR,
3353 .it_flags = HABEO_REFERO,
3354 .it_act = mdt_intent_getattr
3357 .it_fmt = &RQF_LDLM_INTENT_UNLINK,
3358 .it_flags = MUTABOR,
3360 .it_reint = REINT_UNLINK
3364 .it_flags = MUTABOR,
3367 [MDT_IT_GETXATTR] = {
3373 .it_fmt = &RQF_LDLM_INTENT_GETATTR,
3374 .it_flags = HABEO_REFERO,
3375 .it_act = mdt_intent_getattr
3379 int mdt_intent_lock_replace(struct mdt_thread_info *info,
3380 struct ldlm_lock **lockp,
3381 struct ldlm_lock *new_lock,
3382 struct mdt_lock_handle *lh,
3385 struct ptlrpc_request *req = mdt_info_req(info);
3386 struct ldlm_lock *lock = *lockp;
3389 * Get new lock only for cases when possible resent did not find any
3392 if (new_lock == NULL)
3393 new_lock = ldlm_handle2lock_long(&lh->mlh_reg_lh, 0);
3395 if (new_lock == NULL && (flags & LDLM_FL_INTENT_ONLY)) {
3396 lh->mlh_reg_lh.cookie = 0;
3400 LASSERTF(new_lock != NULL,
3401 "lockh "LPX64"\n", lh->mlh_reg_lh.cookie);
3404 * If we've already given this lock to a client once, then we should
3405 * have no readers or writers. Otherwise, we should have one reader
3406 * _or_ writer ref (which will be zeroed below) before returning the
3409 if (new_lock->l_export == req->rq_export) {
3410 LASSERT(new_lock->l_readers + new_lock->l_writers == 0);
3412 LASSERT(new_lock->l_export == NULL);
3413 LASSERT(new_lock->l_readers + new_lock->l_writers == 1);
3418 if (new_lock->l_export == req->rq_export) {
3420 * Already gave this to the client, which means that we
3421 * reconstructed a reply.
3423 LASSERT(lustre_msg_get_flags(req->rq_reqmsg) &
3425 lh->mlh_reg_lh.cookie = 0;
3426 RETURN(ELDLM_LOCK_REPLACED);
3430 * Fixup the lock to be given to the client.
3432 lock_res_and_lock(new_lock);
3433 /* Zero new_lock->l_readers and new_lock->l_writers without triggering
3434 * possible blocking AST. */
3435 while (new_lock->l_readers > 0) {
3436 lu_ref_del(&new_lock->l_reference, "reader", new_lock);
3437 lu_ref_del(&new_lock->l_reference, "user", new_lock);
3438 new_lock->l_readers--;
3440 while (new_lock->l_writers > 0) {
3441 lu_ref_del(&new_lock->l_reference, "writer", new_lock);
3442 lu_ref_del(&new_lock->l_reference, "user", new_lock);
3443 new_lock->l_writers--;
3446 new_lock->l_export = class_export_lock_get(req->rq_export, new_lock);
3447 new_lock->l_blocking_ast = lock->l_blocking_ast;
3448 new_lock->l_completion_ast = lock->l_completion_ast;
3449 new_lock->l_remote_handle = lock->l_remote_handle;
3450 new_lock->l_flags &= ~LDLM_FL_LOCAL;
3452 unlock_res_and_lock(new_lock);
3454 cfs_hash_add(new_lock->l_export->exp_lock_hash,
3455 &new_lock->l_remote_handle,
3456 &new_lock->l_exp_hash);
3458 LDLM_LOCK_RELEASE(new_lock);
3459 lh->mlh_reg_lh.cookie = 0;
3461 RETURN(ELDLM_LOCK_REPLACED);
3464 static void mdt_intent_fixup_resent(struct mdt_thread_info *info,
3465 struct ldlm_lock *new_lock,
3466 struct ldlm_lock **old_lock,
3467 struct mdt_lock_handle *lh)
3469 struct ptlrpc_request *req = mdt_info_req(info);
3470 struct obd_export *exp = req->rq_export;
3471 struct lustre_handle remote_hdl;
3472 struct ldlm_request *dlmreq;
3473 struct ldlm_lock *lock;
3475 if (!(lustre_msg_get_flags(req->rq_reqmsg) & MSG_RESENT))
3478 dlmreq = req_capsule_client_get(info->mti_pill, &RMF_DLM_REQ);
3479 remote_hdl = dlmreq->lock_handle[0];
3481 /* In the function below, .hs_keycmp resolves to
3482 * ldlm_export_lock_keycmp() */
3483 /* coverity[overrun-buffer-val] */
3484 lock = cfs_hash_lookup(exp->exp_lock_hash, &remote_hdl);
3486 if (lock != new_lock) {
3487 lh->mlh_reg_lh.cookie = lock->l_handle.h_cookie;
3488 lh->mlh_reg_mode = lock->l_granted_mode;
3490 LDLM_DEBUG(lock, "Restoring lock cookie");
3491 DEBUG_REQ(D_DLMTRACE, req,
3492 "restoring lock cookie "LPX64,
3493 lh->mlh_reg_lh.cookie);
3495 *old_lock = LDLM_LOCK_GET(lock);
3496 cfs_hash_put(exp->exp_lock_hash, &lock->l_exp_hash);
3500 cfs_hash_put(exp->exp_lock_hash, &lock->l_exp_hash);
3504 * If the xid matches, then we know this is a resent request, and allow
3505 * it. (It's probably an OPEN, for which we don't send a lock.
3507 if (req_xid_is_last(req))
3511 * This remote handle isn't enqueued, so we never received or processed
3512 * this request. Clear MSG_RESENT, because it can be handled like any
3513 * normal request now.
3515 lustre_msg_clear_flags(req->rq_reqmsg, MSG_RESENT);
3517 DEBUG_REQ(D_DLMTRACE, req, "no existing lock with rhandle "LPX64,
3521 static int mdt_intent_getattr(enum mdt_it_code opcode,
3522 struct mdt_thread_info *info,
3523 struct ldlm_lock **lockp,
3526 struct mdt_lock_handle *lhc = &info->mti_lh[MDT_LH_RMT];
3527 struct ldlm_lock *new_lock = NULL;
3529 struct ldlm_reply *ldlm_rep;
3530 struct ptlrpc_request *req;
3531 struct mdt_body *reqbody;
3532 struct mdt_body *repbody;
3536 reqbody = req_capsule_client_get(info->mti_pill, &RMF_MDT_BODY);
3539 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
3542 info->mti_cross_ref = !!(reqbody->valid & OBD_MD_FLCROSSREF);
3543 repbody->eadatasize = 0;
3544 repbody->aclsize = 0;
3548 child_bits = MDS_INODELOCK_LOOKUP;
3550 case MDT_IT_GETATTR:
3551 child_bits = MDS_INODELOCK_LOOKUP | MDS_INODELOCK_UPDATE;
3553 case MDT_IT_LAYOUT: {
3554 static int printed = 0;
3557 CERROR("layout lock not supported by this version\n");
3560 GOTO(out_shrink, rc = -EINVAL);
3564 CERROR("Unsupported intent (%d)\n", opcode);
3565 GOTO(out_shrink, rc = -EINVAL);
3568 rc = mdt_init_ucred(info, reqbody);
3570 GOTO(out_shrink, rc);
3572 req = info->mti_pill->rc_req;
3573 ldlm_rep = req_capsule_server_get(info->mti_pill, &RMF_DLM_REP);
3574 mdt_set_disposition(info, ldlm_rep, DISP_IT_EXECD);
3576 /* Get lock from request for possible resent case. */
3577 mdt_intent_fixup_resent(info, *lockp, &new_lock, lhc);
3579 ldlm_rep->lock_policy_res2 =
3580 mdt_getattr_name_lock(info, lhc, child_bits, ldlm_rep);
3582 if (mdt_get_disposition(ldlm_rep, DISP_LOOKUP_NEG))
3583 ldlm_rep->lock_policy_res2 = 0;
3584 if (!mdt_get_disposition(ldlm_rep, DISP_LOOKUP_POS) ||
3585 ldlm_rep->lock_policy_res2) {
3586 lhc->mlh_reg_lh.cookie = 0ull;
3587 GOTO(out_ucred, rc = ELDLM_LOCK_ABORTED);
3590 rc = mdt_intent_lock_replace(info, lockp, new_lock, lhc, flags);
3593 mdt_exit_ucred(info);
3595 mdt_client_compatibility(info);
3596 rc2 = mdt_fix_reply(info);
3602 static int mdt_intent_reint(enum mdt_it_code opcode,
3603 struct mdt_thread_info *info,
3604 struct ldlm_lock **lockp,
3607 struct mdt_lock_handle *lhc = &info->mti_lh[MDT_LH_RMT];
3608 struct ldlm_reply *rep = NULL;
3612 static const struct req_format *intent_fmts[REINT_MAX] = {
3613 [REINT_CREATE] = &RQF_LDLM_INTENT_CREATE,
3614 [REINT_OPEN] = &RQF_LDLM_INTENT_OPEN
3619 opc = mdt_reint_opcode(info, intent_fmts);
3623 if (mdt_it_flavor[opcode].it_reint != opc) {
3624 CERROR("Reint code %ld doesn't match intent: %d\n",
3626 RETURN(err_serious(-EPROTO));
3629 /* Get lock from request for possible resent case. */
3630 mdt_intent_fixup_resent(info, *lockp, NULL, lhc);
3632 rc = mdt_reint_internal(info, lhc, opc);
3634 /* Check whether the reply has been packed successfully. */
3635 if (mdt_info_req(info)->rq_repmsg != NULL)
3636 rep = req_capsule_server_get(info->mti_pill, &RMF_DLM_REP);
3638 RETURN(err_serious(-EFAULT));
3640 /* MDC expects this in any case */
3642 mdt_set_disposition(info, rep, DISP_LOOKUP_EXECD);
3644 /* Cross-ref case, the lock should be returned to the client */
3645 if (rc == -EREMOTE) {
3646 LASSERT(lustre_handle_is_used(&lhc->mlh_reg_lh));
3647 rep->lock_policy_res2 = 0;
3648 rc = mdt_intent_lock_replace(info, lockp, NULL, lhc, flags);
3651 rep->lock_policy_res2 = clear_serious(rc);
3653 if (rep->lock_policy_res2 == -ENOENT &&
3654 mdt_get_disposition(rep, DISP_LOOKUP_NEG))
3655 rep->lock_policy_res2 = 0;
3657 if (rc == -ENOTCONN || rc == -ENODEV ||
3658 rc == -EOVERFLOW) { /**< if VBR failure then return error */
3660 * If it is the disconnect error (ENODEV & ENOCONN), the error
3661 * will be returned by rq_status, and client at ptlrpc layer
3662 * will detect this, then disconnect, reconnect the import
3663 * immediately, instead of impacting the following the rpc.
3665 lhc->mlh_reg_lh.cookie = 0ull;
3669 * For other cases, the error will be returned by intent.
3670 * and client will retrieve the result from intent.
3673 * FIXME: when open lock is finished, that should be
3676 if (lustre_handle_is_used(&lhc->mlh_reg_lh)) {
3677 LASSERTF(rc == 0, "Error occurred but lock handle "
3678 "is still in use\n");
3679 rep->lock_policy_res2 = 0;
3680 rc = mdt_intent_lock_replace(info, lockp, NULL, lhc, flags);
3683 lhc->mlh_reg_lh.cookie = 0ull;
3684 RETURN(ELDLM_LOCK_ABORTED);
3689 static int mdt_intent_code(long itcode)
3697 case IT_OPEN|IT_CREAT:
3704 rc = MDT_IT_READDIR;
3707 rc = MDT_IT_GETATTR;
3719 rc = MDT_IT_GETXATTR;
3724 case IT_QUOTA_DQACQ:
3729 CERROR("Unknown intent opcode: %ld\n", itcode);
3736 static int mdt_intent_opc(long itopc, struct mdt_thread_info *info,
3737 struct ldlm_lock **lockp, __u64 flags)
3739 struct req_capsule *pill;
3740 struct mdt_it_flavor *flv;
3745 opc = mdt_intent_code(itopc);
3749 pill = info->mti_pill;
3751 if (opc == MDT_IT_QUOTA) {
3752 struct lu_device *qmt = info->mti_mdt->mdt_qmt_dev;
3755 RETURN(-EOPNOTSUPP);
3757 /* pass the request to quota master */
3758 rc = qmt_hdls.qmth_intent_policy(info->mti_env, qmt,
3759 mdt_info_req(info), lockp,
3764 flv = &mdt_it_flavor[opc];
3765 if (flv->it_fmt != NULL)
3766 req_capsule_extend(pill, flv->it_fmt);
3768 rc = mdt_unpack_req_pack_rep(info, flv->it_flags);
3770 struct ptlrpc_request *req = mdt_info_req(info);
3771 if (flv->it_flags & MUTABOR &&
3772 req->rq_export->exp_connect_flags & OBD_CONNECT_RDONLY)
3775 if (rc == 0 && flv->it_act != NULL) {
3776 /* execute policy */
3777 rc = flv->it_act(opc, info, lockp, flags);
3784 static int mdt_intent_policy(struct ldlm_namespace *ns,
3785 struct ldlm_lock **lockp, void *req_cookie,
3786 ldlm_mode_t mode, __u64 flags, void *data)
3788 struct mdt_thread_info *info;
3789 struct ptlrpc_request *req = req_cookie;
3790 struct ldlm_intent *it;
3791 struct req_capsule *pill;
3796 LASSERT(req != NULL);
3798 info = lu_context_key_get(&req->rq_svc_thread->t_env->le_ctx,
3800 LASSERT(info != NULL);
3801 pill = info->mti_pill;
3802 LASSERT(pill->rc_req == req);
3804 if (req->rq_reqmsg->lm_bufcount > DLM_INTENT_IT_OFF) {
3805 req_capsule_extend(pill, &RQF_LDLM_INTENT_BASIC);
3806 it = req_capsule_client_get(pill, &RMF_LDLM_INTENT);
3808 rc = mdt_intent_opc(it->opc, info, lockp, flags);
3812 /* Lock without inodebits makes no sense and will oops
3813 * later in ldlm. Let's check it now to see if we have
3814 * ibits corrupted somewhere in mdt_intent_opc().
3815 * The case for client miss to set ibits has been
3816 * processed by others. */
3817 LASSERT(ergo(info->mti_dlm_req->lock_desc.l_resource.\
3818 lr_type == LDLM_IBITS,
3819 info->mti_dlm_req->lock_desc.\
3820 l_policy_data.l_inodebits.bits != 0));
3822 rc = err_serious(-EFAULT);
3824 /* No intent was provided */
3825 LASSERT(pill->rc_fmt == &RQF_LDLM_ENQUEUE);
3826 rc = req_capsule_server_pack(pill);
3828 rc = err_serious(rc);
3833 static int mdt_seq_fini(const struct lu_env *env,
3834 struct mdt_device *m)
3836 struct md_site *ms = mdt_md_site(m);
3840 if (ms->ms_server_seq) {
3841 seq_server_fini(ms->ms_server_seq, env);
3842 OBD_FREE_PTR(ms->ms_server_seq);
3843 ms->ms_server_seq = NULL;
3846 if (ms->ms_control_seq) {
3847 seq_server_fini(ms->ms_control_seq, env);
3848 OBD_FREE_PTR(ms->ms_control_seq);
3849 ms->ms_control_seq = NULL;
3852 if (ms->ms_client_seq) {
3853 seq_client_fini(ms->ms_client_seq);
3854 OBD_FREE_PTR(ms->ms_client_seq);
3855 ms->ms_client_seq = NULL;
3862 static int mdt_seq_init(const struct lu_env *env,
3864 struct mdt_device *m)
3871 ms = mdt_md_site(m);
3874 * This is sequence-controller node. Init seq-controller server on local
3877 if (ms->ms_node_id == 0) {
3878 LASSERT(ms->ms_control_seq == NULL);
3880 OBD_ALLOC_PTR(ms->ms_control_seq);
3881 if (ms->ms_control_seq == NULL)
3884 rc = seq_server_init(ms->ms_control_seq,
3885 m->mdt_bottom, uuid,
3886 LUSTRE_SEQ_CONTROLLER,
3891 GOTO(out_seq_fini, rc);
3893 OBD_ALLOC_PTR(ms->ms_client_seq);
3894 if (ms->ms_client_seq == NULL)
3895 GOTO(out_seq_fini, rc = -ENOMEM);
3897 OBD_ALLOC(prefix, MAX_OBD_NAME + 5);
3898 if (prefix == NULL) {
3899 OBD_FREE_PTR(ms->ms_client_seq);
3900 GOTO(out_seq_fini, rc = -ENOMEM);
3903 snprintf(prefix, MAX_OBD_NAME + 5, "ctl-%s",
3907 * Init seq-controller client after seq-controller server is
3908 * ready. Pass ms->ms_control_seq to it for direct talking.
3910 rc = seq_client_init(ms->ms_client_seq, NULL,
3911 LUSTRE_SEQ_METADATA, prefix,
3912 ms->ms_control_seq);
3913 OBD_FREE(prefix, MAX_OBD_NAME + 5);
3916 GOTO(out_seq_fini, rc);
3919 /* Init seq-server on local MDT */
3920 LASSERT(ms->ms_server_seq == NULL);
3922 OBD_ALLOC_PTR(ms->ms_server_seq);
3923 if (ms->ms_server_seq == NULL)
3924 GOTO(out_seq_fini, rc = -ENOMEM);
3926 rc = seq_server_init(ms->ms_server_seq,
3927 m->mdt_bottom, uuid,
3932 GOTO(out_seq_fini, rc = -ENOMEM);
3934 /* Assign seq-controller client to local seq-server. */
3935 if (ms->ms_node_id == 0) {
3936 LASSERT(ms->ms_client_seq != NULL);
3938 rc = seq_server_set_cli(ms->ms_server_seq,
3946 mdt_seq_fini(env, m);
3951 * Init client sequence manager which is used by local MDS to talk to sequence
3952 * controller on remote node.
3954 static int mdt_seq_init_cli(const struct lu_env *env,
3955 struct mdt_device *m,
3956 struct lustre_cfg *cfg)
3958 struct md_site *ms = mdt_md_site(m);
3959 struct obd_device *mdc;
3960 struct obd_uuid *uuidp, *mdcuuidp;
3961 char *uuid_str, *mdc_uuid_str;
3964 struct mdt_thread_info *info;
3965 char *p, *index_string = lustre_cfg_string(cfg, 2);
3968 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
3969 uuidp = &info->mti_u.uuid[0];
3970 mdcuuidp = &info->mti_u.uuid[1];
3972 LASSERT(index_string);
3974 index = simple_strtol(index_string, &p, 10);
3976 CERROR("Invalid index in lustre_cgf, offset 2\n");
3980 /* check if this is adding the first MDC and controller is not yet
3982 if (index != 0 || ms->ms_client_seq)
3985 uuid_str = lustre_cfg_string(cfg, 1);
3986 mdc_uuid_str = lustre_cfg_string(cfg, 4);
3987 obd_str2uuid(uuidp, uuid_str);
3988 obd_str2uuid(mdcuuidp, mdc_uuid_str);
3990 mdc = class_find_client_obd(uuidp, LUSTRE_MDC_NAME, mdcuuidp);
3992 CERROR("can't find controller MDC by uuid %s\n",
3995 } else if (!mdc->obd_set_up) {
3996 CERROR("target %s not set up\n", mdc->obd_name);
3999 LASSERT(ms->ms_control_exp);
4000 OBD_ALLOC_PTR(ms->ms_client_seq);
4001 if (ms->ms_client_seq != NULL) {
4004 OBD_ALLOC(prefix, MAX_OBD_NAME + 5);
4008 snprintf(prefix, MAX_OBD_NAME + 5, "ctl-%s",
4011 rc = seq_client_init(ms->ms_client_seq,
4013 LUSTRE_SEQ_METADATA,
4015 OBD_FREE(prefix, MAX_OBD_NAME + 5);
4022 LASSERT(ms->ms_server_seq != NULL);
4023 rc = seq_server_set_cli(ms->ms_server_seq, ms->ms_client_seq,
4030 static void mdt_seq_fini_cli(struct mdt_device *m)
4036 ms = mdt_md_site(m);
4039 if (ms->ms_server_seq)
4040 seq_server_set_cli(ms->ms_server_seq,
4043 if (ms->ms_control_exp) {
4044 class_export_put(ms->ms_control_exp);
4045 ms->ms_control_exp = NULL;
4054 static int mdt_fld_fini(const struct lu_env *env,
4055 struct mdt_device *m)
4057 struct md_site *ms = mdt_md_site(m);
4060 if (ms && ms->ms_server_fld) {
4061 fld_server_fini(ms->ms_server_fld, env);
4062 OBD_FREE_PTR(ms->ms_server_fld);
4063 ms->ms_server_fld = NULL;
4069 static int mdt_fld_init(const struct lu_env *env,
4071 struct mdt_device *m)
4077 ms = mdt_md_site(m);
4079 OBD_ALLOC_PTR(ms->ms_server_fld);
4080 if (ms->ms_server_fld == NULL)
4081 RETURN(rc = -ENOMEM);
4083 rc = fld_server_init(ms->ms_server_fld,
4084 m->mdt_bottom, uuid,
4085 env, ms->ms_node_id);
4087 OBD_FREE_PTR(ms->ms_server_fld);
4088 ms->ms_server_fld = NULL;
4095 /* device init/fini methods */
4096 static void mdt_stop_ptlrpc_service(struct mdt_device *m)
4099 if (m->mdt_regular_service != NULL) {
4100 ptlrpc_unregister_service(m->mdt_regular_service);
4101 m->mdt_regular_service = NULL;
4103 if (m->mdt_readpage_service != NULL) {
4104 ptlrpc_unregister_service(m->mdt_readpage_service);
4105 m->mdt_readpage_service = NULL;
4107 if (m->mdt_xmds_service != NULL) {
4108 ptlrpc_unregister_service(m->mdt_xmds_service);
4109 m->mdt_xmds_service = NULL;
4111 if (m->mdt_setattr_service != NULL) {
4112 ptlrpc_unregister_service(m->mdt_setattr_service);
4113 m->mdt_setattr_service = NULL;
4115 if (m->mdt_mdsc_service != NULL) {
4116 ptlrpc_unregister_service(m->mdt_mdsc_service);
4117 m->mdt_mdsc_service = NULL;
4119 if (m->mdt_mdss_service != NULL) {
4120 ptlrpc_unregister_service(m->mdt_mdss_service);
4121 m->mdt_mdss_service = NULL;
4123 if (m->mdt_dtss_service != NULL) {
4124 ptlrpc_unregister_service(m->mdt_dtss_service);
4125 m->mdt_dtss_service = NULL;
4127 if (m->mdt_fld_service != NULL) {
4128 ptlrpc_unregister_service(m->mdt_fld_service);
4129 m->mdt_fld_service = NULL;
4134 static int mdt_start_ptlrpc_service(struct mdt_device *m)
4136 static struct ptlrpc_service_conf conf;
4137 cfs_proc_dir_entry_t *procfs_entry;
4141 m->mdt_ldlm_client = &m->mdt_md_dev.md_lu_dev.ld_obd->obd_ldlm_client;
4142 ptlrpc_init_client(LDLM_CB_REQUEST_PORTAL, LDLM_CB_REPLY_PORTAL,
4143 "mdt_ldlm_client", m->mdt_ldlm_client);
4145 procfs_entry = m->mdt_md_dev.md_lu_dev.ld_obd->obd_proc_entry;
4147 conf = (typeof(conf)) {
4148 .psc_name = LUSTRE_MDT_NAME,
4149 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
4151 .bc_nbufs = MDS_NBUFS,
4152 .bc_buf_size = MDS_BUFSIZE,
4153 .bc_req_max_size = MDS_MAXREQSIZE,
4154 .bc_rep_max_size = MDS_MAXREPSIZE,
4155 .bc_req_portal = MDS_REQUEST_PORTAL,
4156 .bc_rep_portal = MDC_REPLY_PORTAL,
4159 * We'd like to have a mechanism to set this on a per-device
4160 * basis, but alas...
4163 .tc_thr_name = LUSTRE_MDT_NAME,
4164 .tc_thr_factor = MDT_THR_FACTOR,
4165 .tc_nthrs_init = MDT_NTHRS_INIT,
4166 .tc_nthrs_base = MDT_NTHRS_BASE,
4167 .tc_nthrs_max = MDT_NTHRS_MAX,
4168 .tc_nthrs_user = mds_num_threads,
4169 .tc_cpu_affinity = 1,
4170 .tc_ctx_tags = LCT_MD_THREAD,
4173 .cc_pattern = mds_num_cpts,
4176 .so_req_handler = mdt_regular_handle,
4177 .so_req_printer = target_print_req,
4178 .so_hpreq_handler = ptlrpc_hpreq_handler,
4181 m->mdt_regular_service = ptlrpc_register_service(&conf, procfs_entry);
4182 if (IS_ERR(m->mdt_regular_service)) {
4183 rc = PTR_ERR(m->mdt_regular_service);
4184 CERROR("failed to start regular mdt service: %d\n", rc);
4185 m->mdt_regular_service = NULL;
4191 * readpage service configuration. Parameters have to be adjusted,
4194 memset(&conf, 0, sizeof(conf));
4195 conf = (typeof(conf)) {
4196 .psc_name = LUSTRE_MDT_NAME "_readpage",
4197 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
4199 .bc_nbufs = MDS_NBUFS,
4200 .bc_buf_size = MDS_BUFSIZE,
4201 .bc_req_max_size = MDS_MAXREQSIZE,
4202 .bc_rep_max_size = MDS_MAXREPSIZE,
4203 .bc_req_portal = MDS_READPAGE_PORTAL,
4204 .bc_rep_portal = MDC_REPLY_PORTAL,
4207 .tc_thr_name = "mdt_rdpg",
4208 .tc_thr_factor = MDT_RDPG_THR_FACTOR,
4209 .tc_nthrs_init = MDT_RDPG_NTHRS_INIT,
4210 .tc_nthrs_base = MDT_RDPG_NTHRS_BASE,
4211 .tc_nthrs_max = MDT_RDPG_NTHRS_MAX,
4212 .tc_nthrs_user = mds_rdpg_num_threads,
4213 .tc_cpu_affinity = 1,
4214 .tc_ctx_tags = LCT_MD_THREAD,
4217 .cc_pattern = mds_rdpg_num_cpts,
4220 .so_req_handler = mdt_readpage_handle,
4221 .so_req_printer = target_print_req,
4224 m->mdt_readpage_service = ptlrpc_register_service(&conf, procfs_entry);
4225 if (IS_ERR(m->mdt_readpage_service)) {
4226 rc = PTR_ERR(m->mdt_readpage_service);
4227 CERROR("failed to start readpage service: %d\n", rc);
4228 m->mdt_readpage_service = NULL;
4230 GOTO(err_mdt_svc, rc);
4234 * setattr service configuration.
4236 * XXX To keep the compatibility with old client(< 2.2), we need to
4237 * preserve this portal for a certain time, it should be removed
4238 * eventually. LU-617.
4240 memset(&conf, 0, sizeof(conf));
4241 conf = (typeof(conf)) {
4242 .psc_name = LUSTRE_MDT_NAME "_setattr",
4243 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
4245 .bc_nbufs = MDS_NBUFS,
4246 .bc_buf_size = MDS_BUFSIZE,
4247 .bc_req_max_size = MDS_MAXREQSIZE,
4248 .bc_rep_max_size = MDS_MAXREPSIZE,
4249 .bc_req_portal = MDS_SETATTR_PORTAL,
4250 .bc_rep_portal = MDC_REPLY_PORTAL,
4253 .tc_thr_name = "mdt_attr",
4254 .tc_thr_factor = MDT_SETA_THR_FACTOR,
4255 .tc_nthrs_init = MDT_SETA_NTHRS_INIT,
4256 .tc_nthrs_base = MDT_SETA_NTHRS_BASE,
4257 .tc_nthrs_max = MDT_SETA_NTHRS_MAX,
4258 .tc_nthrs_user = mds_attr_num_threads,
4259 .tc_cpu_affinity = 1,
4260 .tc_ctx_tags = LCT_MD_THREAD,
4263 .cc_pattern = mds_attr_num_cpts,
4266 .so_req_handler = mdt_regular_handle,
4267 .so_req_printer = target_print_req,
4270 m->mdt_setattr_service = ptlrpc_register_service(&conf, procfs_entry);
4271 if (IS_ERR(m->mdt_setattr_service)) {
4272 rc = PTR_ERR(m->mdt_setattr_service);
4273 CERROR("failed to start setattr service: %d\n", rc);
4274 m->mdt_setattr_service = NULL;
4276 GOTO(err_mdt_svc, rc);
4280 * sequence controller service configuration
4282 memset(&conf, 0, sizeof(conf));
4283 conf = (typeof(conf)) {
4284 .psc_name = LUSTRE_MDT_NAME "_mdsc",
4285 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
4287 .bc_nbufs = MDS_NBUFS,
4288 .bc_buf_size = MDS_BUFSIZE,
4289 .bc_req_max_size = SEQ_MAXREQSIZE,
4290 .bc_rep_max_size = SEQ_MAXREPSIZE,
4291 .bc_req_portal = SEQ_CONTROLLER_PORTAL,
4292 .bc_rep_portal = MDC_REPLY_PORTAL,
4295 .tc_thr_name = "mdt_mdsc",
4296 .tc_nthrs_init = MDT_OTHR_NTHRS_INIT,
4297 .tc_nthrs_max = MDT_OTHR_NTHRS_MAX,
4298 .tc_ctx_tags = LCT_MD_THREAD,
4301 .so_req_handler = mdt_mdsc_handle,
4302 .so_req_printer = target_print_req,
4305 m->mdt_mdsc_service = ptlrpc_register_service(&conf, procfs_entry);
4306 if (IS_ERR(m->mdt_mdsc_service)) {
4307 rc = PTR_ERR(m->mdt_mdsc_service);
4308 CERROR("failed to start seq controller service: %d\n", rc);
4309 m->mdt_mdsc_service = NULL;
4311 GOTO(err_mdt_svc, rc);
4315 * metadata sequence server service configuration
4317 memset(&conf, 0, sizeof(conf));
4318 conf = (typeof(conf)) {
4319 .psc_name = LUSTRE_MDT_NAME "_mdss",
4320 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
4322 .bc_nbufs = MDS_NBUFS,
4323 .bc_buf_size = MDS_BUFSIZE,
4324 .bc_req_max_size = SEQ_MAXREQSIZE,
4325 .bc_rep_max_size = SEQ_MAXREPSIZE,
4326 .bc_req_portal = SEQ_METADATA_PORTAL,
4327 .bc_rep_portal = MDC_REPLY_PORTAL,
4330 .tc_thr_name = "mdt_mdss",
4331 .tc_nthrs_init = MDT_OTHR_NTHRS_INIT,
4332 .tc_nthrs_max = MDT_OTHR_NTHRS_MAX,
4333 .tc_ctx_tags = LCT_MD_THREAD | LCT_DT_THREAD
4336 .so_req_handler = mdt_mdss_handle,
4337 .so_req_printer = target_print_req,
4340 m->mdt_mdss_service = ptlrpc_register_service(&conf, procfs_entry);
4341 if (IS_ERR(m->mdt_mdss_service)) {
4342 rc = PTR_ERR(m->mdt_mdss_service);
4343 CERROR("failed to start metadata seq server service: %d\n", rc);
4344 m->mdt_mdss_service = NULL;
4346 GOTO(err_mdt_svc, rc);
4350 * Data sequence server service configuration. We want to have really
4351 * cluster-wide sequences space. This is why we start only one sequence
4352 * controller which manages space.
4354 memset(&conf, 0, sizeof(conf));
4355 conf = (typeof(conf)) {
4356 .psc_name = LUSTRE_MDT_NAME "_dtss",
4357 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
4359 .bc_nbufs = MDS_NBUFS,
4360 .bc_buf_size = MDS_BUFSIZE,
4361 .bc_req_max_size = SEQ_MAXREQSIZE,
4362 .bc_rep_max_size = SEQ_MAXREPSIZE,
4363 .bc_req_portal = SEQ_DATA_PORTAL,
4364 .bc_rep_portal = OSC_REPLY_PORTAL,
4367 .tc_thr_name = "mdt_dtss",
4368 .tc_nthrs_init = MDT_OTHR_NTHRS_INIT,
4369 .tc_nthrs_max = MDT_OTHR_NTHRS_MAX,
4370 .tc_ctx_tags = LCT_MD_THREAD | LCT_DT_THREAD
4373 .so_req_handler = mdt_dtss_handle,
4374 .so_req_printer = target_print_req,
4377 m->mdt_dtss_service = ptlrpc_register_service(&conf, procfs_entry);
4378 if (IS_ERR(m->mdt_dtss_service)) {
4379 rc = PTR_ERR(m->mdt_dtss_service);
4380 CERROR("failed to start data seq server service: %d\n", rc);
4381 m->mdt_dtss_service = NULL;
4383 GOTO(err_mdt_svc, rc);
4386 /* FLD service start */
4387 memset(&conf, 0, sizeof(conf));
4388 conf = (typeof(conf)) {
4389 .psc_name = LUSTRE_MDT_NAME "_fld",
4390 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
4392 .bc_nbufs = MDS_NBUFS,
4393 .bc_buf_size = MDS_BUFSIZE,
4394 .bc_req_max_size = FLD_MAXREQSIZE,
4395 .bc_rep_max_size = FLD_MAXREPSIZE,
4396 .bc_req_portal = FLD_REQUEST_PORTAL,
4397 .bc_rep_portal = MDC_REPLY_PORTAL,
4400 .tc_thr_name = "mdt_fld",
4401 .tc_nthrs_init = MDT_OTHR_NTHRS_INIT,
4402 .tc_nthrs_max = MDT_OTHR_NTHRS_MAX,
4403 .tc_ctx_tags = LCT_DT_THREAD | LCT_MD_THREAD
4406 .so_req_handler = mdt_fld_handle,
4407 .so_req_printer = target_print_req,
4410 m->mdt_fld_service = ptlrpc_register_service(&conf, procfs_entry);
4411 if (IS_ERR(m->mdt_fld_service)) {
4412 rc = PTR_ERR(m->mdt_fld_service);
4413 CERROR("failed to start fld service: %d\n", rc);
4414 m->mdt_fld_service = NULL;
4416 GOTO(err_mdt_svc, rc);
4420 * mds-mds service configuration. Separate portal is used to allow
4421 * mds-mds requests be not blocked during recovery.
4423 memset(&conf, 0, sizeof(conf));
4424 conf = (typeof(conf)) {
4425 .psc_name = LUSTRE_MDT_NAME "_mds",
4426 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
4428 .bc_nbufs = MDS_NBUFS,
4429 .bc_buf_size = MDS_BUFSIZE,
4430 .bc_req_max_size = MDS_MAXREQSIZE,
4431 .bc_rep_max_size = MDS_MAXREPSIZE,
4432 .bc_req_portal = MDS_MDS_PORTAL,
4433 .bc_rep_portal = MDC_REPLY_PORTAL,
4436 .tc_thr_name = "mdt_mds",
4437 .tc_nthrs_init = MDT_OTHR_NTHRS_INIT,
4438 .tc_nthrs_max = MDT_OTHR_NTHRS_MAX,
4439 .tc_ctx_tags = LCT_MD_THREAD,
4442 .so_req_handler = mdt_xmds_handle,
4443 .so_req_printer = target_print_req,
4444 .so_hpreq_handler = ptlrpc_hpreq_handler,
4447 m->mdt_xmds_service = ptlrpc_register_service(&conf, procfs_entry);
4448 if (IS_ERR(m->mdt_xmds_service)) {
4449 rc = PTR_ERR(m->mdt_xmds_service);
4450 CERROR("failed to start xmds service: %d\n", rc);
4451 m->mdt_xmds_service = NULL;
4453 GOTO(err_mdt_svc, rc);
4459 mdt_stop_ptlrpc_service(m);
4464 static void mdt_stack_fini(const struct lu_env *env,
4465 struct mdt_device *m, struct lu_device *top)
4467 struct obd_device *obd = mdt2obd_dev(m);
4468 struct lustre_cfg_bufs *bufs;
4469 struct lustre_cfg *lcfg;
4470 struct mdt_thread_info *info;
4474 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
4475 LASSERT(info != NULL);
4477 lu_dev_del_linkage(top->ld_site, top);
4479 lu_site_purge(env, top->ld_site, -1);
4481 bufs = &info->mti_u.bufs;
4482 /* process cleanup, pass mdt obd name to get obd umount flags */
4483 /* another purpose is to let all layers to release their objects */
4484 lustre_cfg_bufs_reset(bufs, obd->obd_name);
4489 lustre_cfg_bufs_set_string(bufs, 1, flags);
4490 lcfg = lustre_cfg_new(LCFG_CLEANUP, bufs);
4492 CERROR("Cannot alloc lcfg!\n");
4496 top->ld_ops->ldo_process_config(env, top, lcfg);
4497 lustre_cfg_free(lcfg);
4499 lu_site_purge(env, top->ld_site, -1);
4501 m->mdt_child = NULL;
4502 m->mdt_bottom = NULL;
4504 obd_disconnect(m->mdt_child_exp);
4505 m->mdt_child_exp = NULL;
4507 obd_disconnect(m->mdt_bottom_exp);
4508 m->mdt_child_exp = NULL;
4511 static int mdt_connect_to_next(const struct lu_env *env, struct mdt_device *m,
4512 const char *next, struct obd_export **exp)
4514 struct obd_connect_data *data = NULL;
4515 struct obd_device *obd;
4519 OBD_ALLOC_PTR(data);
4521 GOTO(out, rc = -ENOMEM);
4523 obd = class_name2obd(next);
4525 CERROR("%s: can't locate next device: %s\n",
4526 m->mdt_md_dev.md_lu_dev.ld_obd->obd_name, next);
4527 GOTO(out, rc = -ENOTCONN);
4530 data->ocd_connect_flags = OBD_CONNECT_VERSION;
4531 data->ocd_version = LUSTRE_VERSION_CODE;
4533 rc = obd_connect(NULL, exp, obd, &obd->obd_uuid, data, NULL);
4535 CERROR("%s: cannot connect to next dev %s (%d)\n",
4536 m->mdt_md_dev.md_lu_dev.ld_obd->obd_name, next, rc);
4546 static int mdt_stack_init(const struct lu_env *env, struct mdt_device *mdt,
4547 struct lustre_cfg *cfg)
4549 char *dev = lustre_cfg_string(cfg, 0);
4550 int rc, name_size, uuid_size;
4551 char *name, *uuid, *p;
4552 struct lustre_cfg_bufs *bufs;
4553 struct lustre_cfg *lcfg;
4554 struct obd_device *obd;
4555 struct lustre_profile *lprof;
4556 struct lu_site *site;
4559 /* in 1.8 we had the only device in the stack - MDS.
4560 * 2.0 introduces MDT, MDD, OSD; MDT starts others internally.
4561 * in 2.3 OSD is instantiated by obd_mount.c, so we need
4562 * to generate names and setup MDT, MDD. MDT will be using
4563 * generated name to connect to MDD. for MDD the next device
4564 * will be LOD with name taken from so called "profile" which
4565 * is generated by mount_option line
4567 * 1.8 MGS generates config. commands like this:
4568 * #06 (104)mount_option 0: 1:lustre-MDT0000 2:lustre-mdtlov
4569 * #08 (120)setup 0:lustre-MDT0000 1:dev 2:type 3:lustre-MDT0000
4570 * 2.0 MGS generates config. commands like this:
4571 * #07 (112)mount_option 0: 1:lustre-MDT0000 2:lustre-MDT0000-mdtlov
4572 * #08 (160)setup 0:lustre-MDT0000 1:lustre-MDT0000_UUID 2:0
4573 * 3:lustre-MDT0000-mdtlov 4:f
4575 * we generate MDD name from MDT one, just replacing T with D
4577 * after all the preparations, the logical equivalent will be
4578 * #01 (160)setup 0:lustre-MDD0000 1:lustre-MDD0000_UUID 2:0
4579 * 3:lustre-MDT0000-mdtlov 4:f
4580 * #02 (160)setup 0:lustre-MDT0000 1:lustre-MDT0000_UUID 2:0
4581 * 3:lustre-MDD0000 4:f
4583 * notice we build the stack from down to top: MDD first, then MDT */
4585 name_size = MAX_OBD_NAME;
4586 uuid_size = MAX_OBD_NAME;
4588 OBD_ALLOC(name, name_size);
4589 OBD_ALLOC(uuid, uuid_size);
4590 if (name == NULL || uuid == NULL)
4591 GOTO(cleanup_mem, rc = -ENOMEM);
4593 OBD_ALLOC_PTR(bufs);
4595 GOTO(cleanup_mem, rc = -ENOMEM);
4598 p = strstr(name, "-MDT");
4600 GOTO(cleanup_mem, rc = -ENOMEM);
4603 snprintf(uuid, MAX_OBD_NAME, "%s_UUID", name);
4605 lprof = class_get_profile(lustre_cfg_string(cfg, 0));
4606 if (lprof == NULL || lprof->lp_dt == NULL) {
4607 CERROR("can't find the profile: %s\n",
4608 lustre_cfg_string(cfg, 0));
4609 GOTO(cleanup_mem, rc = -EINVAL);
4612 lustre_cfg_bufs_reset(bufs, name);
4613 lustre_cfg_bufs_set_string(bufs, 1, LUSTRE_MDD_NAME);
4614 lustre_cfg_bufs_set_string(bufs, 2, uuid);
4615 lustre_cfg_bufs_set_string(bufs, 3, lprof->lp_dt);
4617 lcfg = lustre_cfg_new(LCFG_ATTACH, bufs);
4619 GOTO(free_bufs, rc = -ENOMEM);
4621 rc = class_attach(lcfg);
4623 GOTO(lcfg_cleanup, rc);
4625 obd = class_name2obd(name);
4627 CERROR("Can not find obd %s (%s in config)\n",
4628 MDD_OBD_NAME, lustre_cfg_string(cfg, 0));
4629 GOTO(class_detach, rc = -EINVAL);
4632 lustre_cfg_free(lcfg);
4634 lustre_cfg_bufs_reset(bufs, name);
4635 lustre_cfg_bufs_set_string(bufs, 1, uuid);
4636 lustre_cfg_bufs_set_string(bufs, 2, dev);
4637 lustre_cfg_bufs_set_string(bufs, 3, lprof->lp_dt);
4639 lcfg = lustre_cfg_new(LCFG_SETUP, bufs);
4641 rc = class_setup(obd, lcfg);
4643 GOTO(class_detach, rc);
4645 /* connect to MDD we just setup */
4646 rc = mdt_connect_to_next(env, mdt, name, &mdt->mdt_child_exp);
4650 site = mdt->mdt_child_exp->exp_obd->obd_lu_dev->ld_site;
4652 LASSERT(mdt->mdt_md_dev.md_lu_dev.ld_site == NULL);
4653 mdt->mdt_md_dev.md_lu_dev.ld_site = site;
4654 site->ls_top_dev = &mdt->mdt_md_dev.md_lu_dev;
4655 mdt->mdt_child = lu2md_dev(mdt->mdt_child_exp->exp_obd->obd_lu_dev);
4658 /* now connect to bottom OSD */
4659 snprintf(name, MAX_OBD_NAME, "%s-osd", dev);
4660 rc = mdt_connect_to_next(env, mdt, name, &mdt->mdt_bottom_exp);
4664 lu2dt_dev(mdt->mdt_bottom_exp->exp_obd->obd_lu_dev);
4667 rc = lu_env_refill((struct lu_env *)env);
4669 CERROR("Failure to refill session: '%d'\n", rc);
4671 lu_dev_add_linkage(site, &mdt->mdt_md_dev.md_lu_dev);
4676 class_detach(obd, lcfg);
4678 lustre_cfg_free(lcfg);
4683 OBD_FREE(name, name_size);
4685 OBD_FREE(uuid, uuid_size);
4689 /* setup quota master target on MDT0 */
4690 static int mdt_quota_init(const struct lu_env *env, struct mdt_device *mdt,
4691 struct lustre_cfg *cfg)
4693 struct obd_device *obd;
4694 char *dev = lustre_cfg_string(cfg, 0);
4695 char *qmtname, *uuid, *p;
4696 struct lustre_cfg_bufs *bufs;
4697 struct lustre_cfg *lcfg;
4698 struct lustre_profile *lprof;
4699 struct obd_connect_data *data;
4703 LASSERT(mdt->mdt_qmt_exp == NULL);
4704 LASSERT(mdt->mdt_qmt_dev == NULL);
4706 /* quota master is on MDT0 only for now */
4707 if (mdt->mdt_mite.ms_node_id != 0)
4710 /* MGS generates config commands which look as follows:
4711 * #01 (160)setup 0:lustre-MDT0000 1:lustre-MDT0000_UUID 2:0
4712 * 3:lustre-MDT0000-mdtlov 4:f
4714 * We generate the QMT name from the MDT one, just replacing MD with QM
4715 * after all the preparations, the logical equivalent will be:
4716 * #01 (160)setup 0:lustre-QMT0000 1:lustre-QMT0000_UUID 2:0
4717 * 3:lustre-MDT0000-osd 4:f */
4718 OBD_ALLOC(qmtname, MAX_OBD_NAME);
4719 OBD_ALLOC(uuid, UUID_MAX);
4720 OBD_ALLOC_PTR(bufs);
4721 OBD_ALLOC_PTR(data);
4722 if (qmtname == NULL || uuid == NULL || bufs == NULL || data == NULL)
4723 GOTO(cleanup_mem, rc = -ENOMEM);
4725 strcpy(qmtname, dev);
4726 p = strstr(qmtname, "-MDT");
4728 GOTO(cleanup_mem, rc = -ENOMEM);
4729 /* replace MD with QM */
4733 snprintf(uuid, UUID_MAX, "%s_UUID", qmtname);
4735 lprof = class_get_profile(lustre_cfg_string(cfg, 0));
4736 if (lprof == NULL || lprof->lp_dt == NULL) {
4737 CERROR("can't find profile for %s\n",
4738 lustre_cfg_string(cfg, 0));
4739 GOTO(cleanup_mem, rc = -EINVAL);
4742 lustre_cfg_bufs_reset(bufs, qmtname);
4743 lustre_cfg_bufs_set_string(bufs, 1, LUSTRE_QMT_NAME);
4744 lustre_cfg_bufs_set_string(bufs, 2, uuid);
4745 lustre_cfg_bufs_set_string(bufs, 3, lprof->lp_dt);
4747 lcfg = lustre_cfg_new(LCFG_ATTACH, bufs);
4749 GOTO(cleanup_mem, rc = -ENOMEM);
4751 rc = class_attach(lcfg);
4753 GOTO(lcfg_cleanup, rc);
4755 obd = class_name2obd(qmtname);
4757 CERROR("Can not find obd %s (%s in config)\n", qmtname,
4758 lustre_cfg_string(cfg, 0));
4759 GOTO(class_detach, rc = -EINVAL);
4762 lustre_cfg_free(lcfg);
4764 lustre_cfg_bufs_reset(bufs, qmtname);
4765 lustre_cfg_bufs_set_string(bufs, 1, uuid);
4766 lustre_cfg_bufs_set_string(bufs, 2, dev);
4768 /* for quota, the next device should be the OSD device */
4769 lustre_cfg_bufs_set_string(bufs, 3,
4770 mdt->mdt_bottom->dd_lu_dev.ld_obd->obd_name);
4772 lcfg = lustre_cfg_new(LCFG_SETUP, bufs);
4774 rc = class_setup(obd, lcfg);
4776 GOTO(class_detach, rc);
4778 mdt->mdt_qmt_dev = obd->obd_lu_dev;
4780 /* configure local quota objects */
4781 rc = mdt->mdt_qmt_dev->ld_ops->ldo_prepare(env,
4782 &mdt->mdt_md_dev.md_lu_dev,
4785 GOTO(class_cleanup, rc);
4787 /* connect to quota master target */
4788 data->ocd_connect_flags = OBD_CONNECT_VERSION;
4789 data->ocd_version = LUSTRE_VERSION_CODE;
4790 rc = obd_connect(NULL, &mdt->mdt_qmt_exp, obd, &obd->obd_uuid,
4793 CERROR("cannot connect to quota master device %s (%d)\n",
4795 GOTO(class_cleanup, rc);
4801 class_manual_cleanup(obd);
4802 mdt->mdt_qmt_dev = NULL;
4806 class_detach(obd, lcfg);
4808 lustre_cfg_free(lcfg);
4813 OBD_FREE(qmtname, MAX_OBD_NAME);
4815 OBD_FREE(uuid, UUID_MAX);
4821 /* Shutdown quota master target associated with mdt */
4822 static void mdt_quota_fini(const struct lu_env *env, struct mdt_device *mdt)
4826 if (mdt->mdt_qmt_exp == NULL)
4828 LASSERT(mdt->mdt_qmt_dev != NULL);
4830 /* the qmt automatically shuts down when the mdt disconnects */
4831 obd_disconnect(mdt->mdt_qmt_exp);
4832 mdt->mdt_qmt_exp = NULL;
4833 mdt->mdt_qmt_dev = NULL;
4837 static void mdt_fini(const struct lu_env *env, struct mdt_device *m)
4839 struct md_device *next = m->mdt_child;
4840 struct lu_device *d = &m->mdt_md_dev.md_lu_dev;
4841 struct obd_device *obd = mdt2obd_dev(m);
4844 target_recovery_fini(obd);
4846 ping_evictor_stop();
4848 mdt_stop_ptlrpc_service(m);
4849 mdt_llog_ctxt_unclone(env, m, LLOG_CHANGELOG_ORIG_CTXT);
4850 obd_exports_barrier(obd);
4851 obd_zombie_barrier();
4855 tgt_fini(env, &m->mdt_lut);
4856 mdt_fs_cleanup(env, m);
4857 upcall_cache_cleanup(m->mdt_identity_cache);
4858 m->mdt_identity_cache = NULL;
4860 if (m->mdt_namespace != NULL) {
4861 ldlm_namespace_free(m->mdt_namespace, NULL,
4862 d->ld_obd->obd_force);
4863 d->ld_obd->obd_namespace = m->mdt_namespace = NULL;
4866 mdt_quota_fini(env, m);
4868 cfs_free_nidlist(&m->mdt_nosquash_nids);
4869 if (m->mdt_nosquash_str) {
4870 OBD_FREE(m->mdt_nosquash_str, m->mdt_nosquash_strlen);
4871 m->mdt_nosquash_str = NULL;
4872 m->mdt_nosquash_strlen = 0;
4875 mdt_seq_fini(env, m);
4876 mdt_seq_fini_cli(m);
4877 mdt_fld_fini(env, m);
4878 sptlrpc_rule_set_free(&m->mdt_sptlrpc_rset);
4880 next->md_ops->mdo_init_capa_ctxt(env, next, 0, 0, 0, NULL);
4881 cfs_timer_disarm(&m->mdt_ck_timer);
4882 mdt_ck_thread_stop(m);
4887 mdt_stack_fini(env, m, md2lu_dev(m->mdt_child));
4889 LASSERT(cfs_atomic_read(&d->ld_ref) == 0);
4891 server_put_mount(mdt2obd_dev(m)->obd_name, NULL);
4896 static int mdt_adapt_sptlrpc_conf(struct obd_device *obd, int initial)
4898 struct mdt_device *m = mdt_dev(obd->obd_lu_dev);
4899 struct sptlrpc_rule_set tmp_rset;
4902 sptlrpc_rule_set_init(&tmp_rset);
4903 rc = sptlrpc_conf_target_get_rules(obd, &tmp_rset, initial);
4905 CERROR("mdt %s: failed get sptlrpc rules: %d\n",
4910 sptlrpc_target_update_exp_flavor(obd, &tmp_rset);
4912 cfs_write_lock(&m->mdt_sptlrpc_lock);
4913 sptlrpc_rule_set_free(&m->mdt_sptlrpc_rset);
4914 m->mdt_sptlrpc_rset = tmp_rset;
4915 cfs_write_unlock(&m->mdt_sptlrpc_lock);
4920 int mdt_postrecov(const struct lu_env *, struct mdt_device *);
4922 static int mdt_init0(const struct lu_env *env, struct mdt_device *m,
4923 struct lu_device_type *ldt, struct lustre_cfg *cfg)
4925 struct mdt_thread_info *info;
4926 struct obd_device *obd;
4927 const char *dev = lustre_cfg_string(cfg, 0);
4928 const char *num = lustre_cfg_string(cfg, 2);
4929 struct lustre_mount_info *lmi = NULL;
4930 struct lustre_sb_info *lsi;
4932 struct md_site *mite;
4933 const char *identity_upcall = "NONE";
4934 struct md_device *next;
4940 md_device_init(&m->mdt_md_dev, ldt);
4942 * Environment (env) might be missing mdt_thread_key values at that
4943 * point, if device is allocated when mdt_thread_key is in QUIESCENT
4946 * Usually device allocation path doesn't use module key values, but
4947 * mdt has to do a lot of work here, so allocate key value.
4949 rc = lu_env_refill((struct lu_env *)env);
4953 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
4954 LASSERT(info != NULL);
4956 obd = class_name2obd(dev);
4957 LASSERT(obd != NULL);
4959 m->mdt_max_mdsize = MAX_MD_SIZE; /* 4 stripes */
4961 m->mdt_som_conf = 0;
4963 m->mdt_opts.mo_cos = MDT_COS_DEFAULT;
4964 lmi = server_get_mount(dev);
4966 CERROR("Cannot get mount info for %s!\n", dev);
4969 lsi = s2lsi(lmi->lmi_sb);
4970 /* CMD is supported only in IAM mode */
4972 node_id = simple_strtol(num, NULL, 10);
4973 obd->u.obt.obt_magic = OBT_MAGIC;
4976 cfs_rwlock_init(&m->mdt_sptlrpc_lock);
4977 sptlrpc_rule_set_init(&m->mdt_sptlrpc_rset);
4979 cfs_spin_lock_init(&m->mdt_ioepoch_lock);
4980 m->mdt_opts.mo_compat_resname = 0;
4981 m->mdt_opts.mo_mds_capa = 1;
4982 m->mdt_opts.mo_oss_capa = 1;
4983 m->mdt_capa_timeout = CAPA_TIMEOUT;
4984 m->mdt_capa_alg = CAPA_HMAC_ALG_SHA1;
4985 m->mdt_ck_timeout = CAPA_KEY_TIMEOUT;
4986 m->mdt_squash_uid = 0;
4987 m->mdt_squash_gid = 0;
4988 CFS_INIT_LIST_HEAD(&m->mdt_nosquash_nids);
4989 m->mdt_nosquash_str = NULL;
4990 m->mdt_nosquash_strlen = 0;
4991 cfs_init_rwsem(&m->mdt_squash_sem);
4992 cfs_spin_lock_init(&m->mdt_osfs_lock);
4993 m->mdt_osfs_age = cfs_time_shift_64(-1000);
4995 m->mdt_md_dev.md_lu_dev.ld_ops = &mdt_lu_ops;
4996 m->mdt_md_dev.md_lu_dev.ld_obd = obd;
4997 /* set this lu_device to obd, because error handling need it */
4998 obd->obd_lu_dev = &m->mdt_md_dev.md_lu_dev;
5000 /* init the stack */
5001 rc = mdt_stack_init((struct lu_env *)env, m, cfg);
5003 CERROR("Can't init device stack, rc %d\n", rc);
5007 s = m->mdt_md_dev.md_lu_dev.ld_site;
5008 mite = &m->mdt_mite;
5009 s->ld_md_site = mite;
5012 /* set server index */
5013 mite->ms_node_id = node_id;
5015 /* failover is the default
5016 * FIXME: we do not failout mds0/mgs, which may cause some problems.
5017 * assumed whose ms_node_id == 0 XXX
5019 obd->obd_replayable = 1;
5020 /* No connection accepted until configurations will finish */
5021 obd->obd_no_conn = 1;
5023 if (cfg->lcfg_bufcount > 4 && LUSTRE_CFG_BUFLEN(cfg, 4) > 0) {
5024 char *str = lustre_cfg_string(cfg, 4);
5025 if (strchr(str, 'n')) {
5026 CWARN("%s: recovery disabled\n", obd->obd_name);
5027 obd->obd_replayable = 0;
5031 rc = tgt_init(env, &m->mdt_lut, obd, m->mdt_bottom);
5033 GOTO(err_fini_stack, rc);
5035 snprintf(info->mti_u.ns_name, sizeof info->mti_u.ns_name,
5036 LUSTRE_MDT_NAME"-%p", m);
5037 m->mdt_namespace = ldlm_namespace_new(obd, info->mti_u.ns_name,
5038 LDLM_NAMESPACE_SERVER,
5039 LDLM_NAMESPACE_GREEDY,
5041 if (m->mdt_namespace == NULL)
5042 GOTO(err_fini_seq, rc = -ENOMEM);
5044 m->mdt_namespace->ns_lvbp = m;
5045 m->mdt_namespace->ns_lvbo = &mdt_lvbo;
5047 ldlm_register_intent(m->mdt_namespace, mdt_intent_policy);
5048 /* set obd_namespace for compatibility with old code */
5049 obd->obd_namespace = m->mdt_namespace;
5051 cfs_timer_init(&m->mdt_ck_timer, mdt_ck_timer_callback, m);
5053 rc = mdt_ck_thread_start(m);
5055 GOTO(err_free_ns, rc);
5057 rc = mdt_fs_setup(env, m, obd, lsi);
5061 mdt_adapt_sptlrpc_conf(obd, 1);
5063 next = m->mdt_child;
5064 rc = next->md_ops->mdo_iocontrol(env, next, OBD_IOC_GET_MNTOPT, 0,
5067 GOTO(err_llog_cleanup, rc);
5069 if (mntopts & MNTOPT_USERXATTR)
5070 m->mdt_opts.mo_user_xattr = 1;
5072 m->mdt_opts.mo_user_xattr = 0;
5074 if (mntopts & MNTOPT_ACL)
5075 m->mdt_opts.mo_acl = 1;
5077 m->mdt_opts.mo_acl = 0;
5079 /* XXX: to support suppgid for ACL, we enable identity_upcall
5080 * by default, otherwise, maybe got unexpected -EACCESS. */
5081 if (m->mdt_opts.mo_acl)
5082 identity_upcall = MDT_IDENTITY_UPCALL_PATH;
5084 m->mdt_identity_cache = upcall_cache_init(obd->obd_name,identity_upcall,
5085 &mdt_identity_upcall_cache_ops);
5086 if (IS_ERR(m->mdt_identity_cache)) {
5087 rc = PTR_ERR(m->mdt_identity_cache);
5088 m->mdt_identity_cache = NULL;
5089 GOTO(err_llog_cleanup, rc);
5092 rc = mdt_procfs_init(m, dev);
5094 CERROR("Can't init MDT lprocfs, rc %d\n", rc);
5095 GOTO(err_recovery, rc);
5098 rc = mdt_quota_init(env, m, cfg);
5100 GOTO(err_procfs, rc);
5102 rc = mdt_start_ptlrpc_service(m);
5104 GOTO(err_quota, rc);
5106 ping_evictor_start();
5108 /* recovery will be started upon mdt_prepare()
5109 * when the whole stack is complete and ready
5110 * to serve the requests */
5112 mdt_init_capa_ctxt(env, m);
5114 /* Reduce the initial timeout on an MDS because it doesn't need such
5115 * a long timeout as an OST does. Adaptive timeouts will adjust this
5116 * value appropriately. */
5117 if (ldlm_timeout == LDLM_TIMEOUT_DEFAULT)
5118 ldlm_timeout = MDS_LDLM_TIMEOUT_DEFAULT;
5122 ping_evictor_stop();
5123 mdt_stop_ptlrpc_service(m);
5125 mdt_quota_fini(env, m);
5129 target_recovery_fini(obd);
5130 upcall_cache_cleanup(m->mdt_identity_cache);
5131 m->mdt_identity_cache = NULL;
5133 mdt_llog_ctxt_unclone(env, m, LLOG_CHANGELOG_ORIG_CTXT);
5134 mdt_fs_cleanup(env, m);
5136 cfs_timer_disarm(&m->mdt_ck_timer);
5137 mdt_ck_thread_stop(m);
5139 ldlm_namespace_free(m->mdt_namespace, NULL, 0);
5140 obd->obd_namespace = m->mdt_namespace = NULL;
5142 mdt_seq_fini(env, m);
5143 mdt_fld_fini(env, m);
5144 tgt_fini(env, &m->mdt_lut);
5146 mdt_stack_fini(env, m, md2lu_dev(m->mdt_child));
5149 server_put_mount(dev, lmi->lmi_mnt);
5153 /* For interoperability, the left element is old parameter, the right one
5154 * is the new version of the parameter, if some parameter is deprecated,
5155 * the new version should be set as NULL. */
5156 static struct cfg_interop_param mdt_interop_param[] = {
5157 { "mdt.group_upcall", NULL },
5158 { "mdt.quota_type", NULL },
5159 { "mdd.quota_type", NULL },
5160 { "mdt.rootsquash", "mdt.root_squash" },
5161 { "mdt.nosquash_nid", "mdt.nosquash_nids" },
5165 /* used by MGS to process specific configurations */
5166 static int mdt_process_config(const struct lu_env *env,
5167 struct lu_device *d, struct lustre_cfg *cfg)
5169 struct mdt_device *m = mdt_dev(d);
5170 struct md_device *md_next = m->mdt_child;
5171 struct lu_device *next = md2lu_dev(md_next);
5175 switch (cfg->lcfg_command) {
5177 struct lprocfs_static_vars lvars;
5178 struct obd_device *obd = d->ld_obd;
5180 /* For interoperability */
5181 struct cfg_interop_param *ptr = NULL;
5182 struct lustre_cfg *old_cfg = NULL;
5185 param = lustre_cfg_string(cfg, 1);
5186 if (param == NULL) {
5187 CERROR("param is empty\n");
5192 ptr = class_find_old_param(param, mdt_interop_param);
5194 if (ptr->new_param == NULL) {
5196 CWARN("For interoperability, skip this %s."
5197 " It is obsolete.\n", ptr->old_param);
5201 CWARN("Found old param %s, changed it to %s.\n",
5202 ptr->old_param, ptr->new_param);
5205 cfg = lustre_cfg_rename(old_cfg, ptr->new_param);
5212 lprocfs_mdt_init_vars(&lvars);
5213 rc = class_process_proc_param(PARAM_MDT, lvars.obd_vars,
5215 if (rc > 0 || rc == -ENOSYS)
5216 /* we don't understand; pass it on */
5217 rc = next->ld_ops->ldo_process_config(env, next, cfg);
5219 if (old_cfg != NULL)
5220 lustre_cfg_free(cfg);
5226 * Add mdc hook to get first MDT uuid and connect it to
5227 * ls->controller to use for seq manager.
5229 rc = next->ld_ops->ldo_process_config(env, next, cfg);
5231 CERROR("Can't add mdc, rc %d\n", rc);
5233 rc = mdt_seq_init_cli(env, mdt_dev(d), cfg);
5236 /* others are passed further */
5237 rc = next->ld_ops->ldo_process_config(env, next, cfg);
5243 static struct lu_object *mdt_object_alloc(const struct lu_env *env,
5244 const struct lu_object_header *hdr,
5245 struct lu_device *d)
5247 struct mdt_object *mo;
5251 OBD_SLAB_ALLOC_PTR_GFP(mo, mdt_object_kmem, CFS_ALLOC_IO);
5253 struct lu_object *o;
5254 struct lu_object_header *h;
5256 o = &mo->mot_obj.mo_lu;
5257 h = &mo->mot_header;
5258 lu_object_header_init(h);
5259 lu_object_init(o, h, d);
5260 lu_object_add_top(h, o);
5261 o->lo_ops = &mdt_obj_ops;
5262 cfs_mutex_init(&mo->mot_ioepoch_mutex);
5263 cfs_mutex_init(&mo->mot_lov_mutex);
5269 static int mdt_object_init(const struct lu_env *env, struct lu_object *o,
5270 const struct lu_object_conf *unused)
5272 struct mdt_device *d = mdt_dev(o->lo_dev);
5273 struct lu_device *under;
5274 struct lu_object *below;
5278 CDEBUG(D_INFO, "object init, fid = "DFID"\n",
5279 PFID(lu_object_fid(o)));
5281 under = &d->mdt_child->md_lu_dev;
5282 below = under->ld_ops->ldo_object_alloc(env, o->lo_header, under);
5283 if (below != NULL) {
5284 lu_object_add(o, below);
5291 static void mdt_object_free(const struct lu_env *env, struct lu_object *o)
5293 struct mdt_object *mo = mdt_obj(o);
5294 struct lu_object_header *h;
5298 CDEBUG(D_INFO, "object free, fid = "DFID"\n",
5299 PFID(lu_object_fid(o)));
5302 lu_object_header_fini(h);
5303 OBD_SLAB_FREE_PTR(mo, mdt_object_kmem);
5308 static int mdt_object_print(const struct lu_env *env, void *cookie,
5309 lu_printer_t p, const struct lu_object *o)
5311 struct mdt_object *mdto = mdt_obj((struct lu_object *)o);
5312 return (*p)(env, cookie, LUSTRE_MDT_NAME"-object@%p(ioepoch="LPU64" "
5313 "flags="LPX64", epochcount=%d, writecount=%d)",
5314 mdto, mdto->mot_ioepoch, mdto->mot_flags,
5315 mdto->mot_ioepoch_count, mdto->mot_writecount);
5318 static int mdt_prepare(const struct lu_env *env,
5319 struct lu_device *pdev,
5320 struct lu_device *cdev)
5322 struct mdt_device *mdt = mdt_dev(cdev);
5323 struct lu_device *next = &mdt->mdt_child->md_lu_dev;
5324 struct obd_device *obd = cdev->ld_obd;
5331 rc = next->ld_ops->ldo_prepare(env, cdev, next);
5335 rc = mdt_llog_ctxt_clone(env, mdt, LLOG_CHANGELOG_ORIG_CTXT);
5339 rc = mdt_fld_init(env, obd->obd_name, mdt);
5343 rc = mdt_seq_init(env, obd->obd_name, mdt);
5347 rc = mdt->mdt_child->md_ops->mdo_root_get(env, mdt->mdt_child,
5348 &mdt->mdt_md_root_fid);
5352 LASSERT(!cfs_test_bit(MDT_FL_CFGLOG, &mdt->mdt_state));
5353 target_recovery_init(&mdt->mdt_lut, mdt_recovery_handle);
5354 cfs_set_bit(MDT_FL_CFGLOG, &mdt->mdt_state);
5355 LASSERT(obd->obd_no_conn);
5356 cfs_spin_lock(&obd->obd_dev_lock);
5357 obd->obd_no_conn = 0;
5358 cfs_spin_unlock(&obd->obd_dev_lock);
5360 if (obd->obd_recovering == 0)
5361 mdt_postrecov(env, mdt);
5366 static const struct lu_device_operations mdt_lu_ops = {
5367 .ldo_object_alloc = mdt_object_alloc,
5368 .ldo_process_config = mdt_process_config,
5369 .ldo_prepare = mdt_prepare,
5372 static const struct lu_object_operations mdt_obj_ops = {
5373 .loo_object_init = mdt_object_init,
5374 .loo_object_free = mdt_object_free,
5375 .loo_object_print = mdt_object_print
5378 static int mdt_obd_set_info_async(const struct lu_env *env,
5379 struct obd_export *exp,
5380 __u32 keylen, void *key,
5381 __u32 vallen, void *val,
5382 struct ptlrpc_request_set *set)
5384 struct obd_device *obd = exp->exp_obd;
5390 if (KEY_IS(KEY_SPTLRPC_CONF)) {
5391 rc = mdt_adapt_sptlrpc_conf(obd, 0);
5398 /* mds_connect_internal */
5399 static int mdt_connect_internal(struct obd_export *exp,
5400 struct mdt_device *mdt,
5401 struct obd_connect_data *data)
5404 data->ocd_connect_flags &= MDT_CONNECT_SUPPORTED;
5405 data->ocd_ibits_known &= MDS_INODELOCK_FULL;
5407 /* If no known bits (which should not happen, probably,
5408 as everybody should support LOOKUP and UPDATE bits at least)
5409 revert to compat mode with plain locks. */
5410 if (!data->ocd_ibits_known &&
5411 data->ocd_connect_flags & OBD_CONNECT_IBITS)
5412 data->ocd_connect_flags &= ~OBD_CONNECT_IBITS;
5414 if (!mdt->mdt_opts.mo_acl)
5415 data->ocd_connect_flags &= ~OBD_CONNECT_ACL;
5417 if (!mdt->mdt_opts.mo_user_xattr)
5418 data->ocd_connect_flags &= ~OBD_CONNECT_XATTR;
5420 if (!mdt->mdt_som_conf)
5421 data->ocd_connect_flags &= ~OBD_CONNECT_SOM;
5423 if (data->ocd_connect_flags & OBD_CONNECT_BRW_SIZE) {
5424 data->ocd_brw_size = min(data->ocd_brw_size,
5425 (__u32)(PTLRPC_MAX_BRW_PAGES << CFS_PAGE_SHIFT));
5426 if (data->ocd_brw_size == 0) {
5427 CERROR("%s: cli %s/%p ocd_connect_flags: "LPX64
5428 " ocd_version: %x ocd_grant: %d "
5429 "ocd_index: %u ocd_brw_size is "
5430 "unexpectedly zero, network data "
5431 "corruption? Refusing connection of this"
5433 exp->exp_obd->obd_name,
5434 exp->exp_client_uuid.uuid,
5435 exp, data->ocd_connect_flags, data->ocd_version,
5436 data->ocd_grant, data->ocd_index);
5441 cfs_spin_lock(&exp->exp_lock);
5442 exp->exp_connect_flags = data->ocd_connect_flags;
5443 cfs_spin_unlock(&exp->exp_lock);
5444 data->ocd_version = LUSTRE_VERSION_CODE;
5445 exp->exp_mdt_data.med_ibits_known = data->ocd_ibits_known;
5449 if (mdt->mdt_opts.mo_acl &&
5450 ((exp->exp_connect_flags & OBD_CONNECT_ACL) == 0)) {
5451 CWARN("%s: MDS requires ACL support but client does not\n",
5452 mdt->mdt_md_dev.md_lu_dev.ld_obd->obd_name);
5457 if ((exp->exp_connect_flags & OBD_CONNECT_FID) == 0) {
5458 CWARN("%s: MDS requires FID support, but client not\n",
5459 mdt->mdt_md_dev.md_lu_dev.ld_obd->obd_name);
5463 if (mdt->mdt_som_conf && !exp_connect_som(exp) &&
5464 !(exp->exp_connect_flags & OBD_CONNECT_MDS_MDS)) {
5465 CWARN("%s: MDS has SOM enabled, but client does not support "
5466 "it\n", mdt->mdt_md_dev.md_lu_dev.ld_obd->obd_name);
5473 static int mdt_connect_check_sptlrpc(struct mdt_device *mdt,
5474 struct obd_export *exp,
5475 struct ptlrpc_request *req)
5477 struct sptlrpc_flavor flvr;
5480 if (exp->exp_flvr.sf_rpc == SPTLRPC_FLVR_INVALID) {
5481 cfs_read_lock(&mdt->mdt_sptlrpc_lock);
5482 sptlrpc_target_choose_flavor(&mdt->mdt_sptlrpc_rset,
5486 cfs_read_unlock(&mdt->mdt_sptlrpc_lock);
5488 cfs_spin_lock(&exp->exp_lock);
5490 exp->exp_sp_peer = req->rq_sp_from;
5491 exp->exp_flvr = flvr;
5493 if (exp->exp_flvr.sf_rpc != SPTLRPC_FLVR_ANY &&
5494 exp->exp_flvr.sf_rpc != req->rq_flvr.sf_rpc) {
5495 CERROR("unauthorized rpc flavor %x from %s, "
5496 "expect %x\n", req->rq_flvr.sf_rpc,
5497 libcfs_nid2str(req->rq_peer.nid),
5498 exp->exp_flvr.sf_rpc);
5502 cfs_spin_unlock(&exp->exp_lock);
5504 if (exp->exp_sp_peer != req->rq_sp_from) {
5505 CERROR("RPC source %s doesn't match %s\n",
5506 sptlrpc_part2name(req->rq_sp_from),
5507 sptlrpc_part2name(exp->exp_sp_peer));
5510 rc = sptlrpc_target_export_check(exp, req);
5517 /* mds_connect copy */
5518 static int mdt_obd_connect(const struct lu_env *env,
5519 struct obd_export **exp, struct obd_device *obd,
5520 struct obd_uuid *cluuid,
5521 struct obd_connect_data *data,
5524 struct mdt_thread_info *info;
5525 struct obd_export *lexp;
5526 struct lustre_handle conn = { 0 };
5527 struct mdt_device *mdt;
5528 struct ptlrpc_request *req;
5532 LASSERT(env != NULL);
5533 if (!exp || !obd || !cluuid)
5536 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
5537 req = info->mti_pill->rc_req;
5538 mdt = mdt_dev(obd->obd_lu_dev);
5541 * first, check whether the stack is ready to handle requests
5542 * XXX: probably not very appropriate method is used now
5543 * at some point we should find a better one
5545 if (!cfs_test_bit(MDT_FL_SYNCED, &mdt->mdt_state)) {
5546 rc = obd_health_check(env, mdt->mdt_child_exp->exp_obd);
5549 cfs_set_bit(MDT_FL_SYNCED, &mdt->mdt_state);
5552 rc = class_connect(&conn, obd, cluuid);
5556 lexp = class_conn2export(&conn);
5557 LASSERT(lexp != NULL);
5559 rc = mdt_connect_check_sptlrpc(mdt, lexp, req);
5563 if (OBD_FAIL_CHECK(OBD_FAIL_TGT_RCVG_FLAG))
5564 lustre_msg_add_op_flags(req->rq_repmsg, MSG_CONNECT_RECOVERING);
5566 rc = mdt_connect_internal(lexp, mdt, data);
5568 struct lsd_client_data *lcd = lexp->exp_target_data.ted_lcd;
5571 info->mti_exp = lexp;
5572 memcpy(lcd->lcd_uuid, cluuid, sizeof lcd->lcd_uuid);
5573 rc = tgt_client_new(env, lexp);
5575 mdt_export_stats_init(obd, lexp, localdata);
5580 class_disconnect(lexp);
5589 static int mdt_obd_reconnect(const struct lu_env *env,
5590 struct obd_export *exp, struct obd_device *obd,
5591 struct obd_uuid *cluuid,
5592 struct obd_connect_data *data,
5595 struct mdt_thread_info *info;
5596 struct mdt_device *mdt;
5597 struct ptlrpc_request *req;
5601 if (exp == NULL || obd == NULL || cluuid == NULL)
5604 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
5605 req = info->mti_pill->rc_req;
5606 mdt = mdt_dev(obd->obd_lu_dev);
5608 rc = mdt_connect_check_sptlrpc(mdt, exp, req);
5612 rc = mdt_connect_internal(exp, mdt_dev(obd->obd_lu_dev), data);
5614 mdt_export_stats_init(obd, exp, localdata);
5619 static int mdt_export_cleanup(struct obd_export *exp)
5621 struct mdt_export_data *med = &exp->exp_mdt_data;
5622 struct obd_device *obd = exp->exp_obd;
5623 struct mdt_device *mdt;
5624 struct mdt_thread_info *info;
5626 CFS_LIST_HEAD(closing_list);
5627 struct mdt_file_data *mfd, *n;
5631 cfs_spin_lock(&med->med_open_lock);
5632 while (!cfs_list_empty(&med->med_open_head)) {
5633 cfs_list_t *tmp = med->med_open_head.next;
5634 mfd = cfs_list_entry(tmp, struct mdt_file_data, mfd_list);
5636 /* Remove mfd handle so it can't be found again.
5637 * We are consuming the mfd_list reference here. */
5638 class_handle_unhash(&mfd->mfd_handle);
5639 cfs_list_move_tail(&mfd->mfd_list, &closing_list);
5641 cfs_spin_unlock(&med->med_open_lock);
5642 mdt = mdt_dev(obd->obd_lu_dev);
5643 LASSERT(mdt != NULL);
5645 rc = lu_env_init(&env, LCT_MD_THREAD);
5649 info = lu_context_key_get(&env.le_ctx, &mdt_thread_key);
5650 LASSERT(info != NULL);
5651 memset(info, 0, sizeof *info);
5652 info->mti_env = &env;
5653 info->mti_mdt = mdt;
5654 info->mti_exp = exp;
5656 if (!cfs_list_empty(&closing_list)) {
5657 struct md_attr *ma = &info->mti_attr;
5659 /* Close any open files (which may also cause orphan unlinking). */
5660 cfs_list_for_each_entry_safe(mfd, n, &closing_list, mfd_list) {
5661 cfs_list_del_init(&mfd->mfd_list);
5662 ma->ma_need = ma->ma_valid = 0;
5663 /* Don't unlink orphan on failover umount, LU-184 */
5664 if (exp->exp_flags & OBD_OPT_FAILOVER) {
5665 ma->ma_valid = MA_FLAGS;
5666 ma->ma_attr_flags |= MDS_KEEP_ORPHAN;
5668 mdt_mfd_close(info, mfd);
5671 info->mti_mdt = NULL;
5672 /* cleanup client slot early */
5673 /* Do not erase record for recoverable client. */
5674 if (!(exp->exp_flags & OBD_OPT_FAILOVER) || exp->exp_failed)
5675 tgt_client_del(&env, exp);
5681 static int mdt_obd_disconnect(struct obd_export *exp)
5687 class_export_get(exp);
5689 rc = server_disconnect_export(exp);
5691 CDEBUG(D_IOCTL, "server disconnect error: %d\n", rc);
5693 rc = mdt_export_cleanup(exp);
5694 class_export_put(exp);
5698 /* FIXME: Can we avoid using these two interfaces? */
5699 static int mdt_init_export(struct obd_export *exp)
5701 struct mdt_export_data *med = &exp->exp_mdt_data;
5705 CFS_INIT_LIST_HEAD(&med->med_open_head);
5706 cfs_spin_lock_init(&med->med_open_lock);
5707 cfs_mutex_init(&med->med_idmap_mutex);
5708 med->med_idmap = NULL;
5709 cfs_spin_lock(&exp->exp_lock);
5710 exp->exp_connecting = 1;
5711 cfs_spin_unlock(&exp->exp_lock);
5713 /* self-export doesn't need client data and ldlm initialization */
5714 if (unlikely(obd_uuid_equals(&exp->exp_obd->obd_uuid,
5715 &exp->exp_client_uuid)))
5718 rc = tgt_client_alloc(exp);
5722 rc = ldlm_init_export(exp);
5729 tgt_client_free(exp);
5731 CERROR("%s: Failed to initialize export: rc = %d\n",
5732 exp->exp_obd->obd_name, rc);
5736 static int mdt_destroy_export(struct obd_export *exp)
5740 if (exp_connect_rmtclient(exp))
5741 mdt_cleanup_idmap(&exp->exp_mdt_data);
5743 target_destroy_export(exp);
5744 /* destroy can be called from failed obd_setup, so
5745 * checking uuid is safer than obd_self_export */
5746 if (unlikely(obd_uuid_equals(&exp->exp_obd->obd_uuid,
5747 &exp->exp_client_uuid)))
5750 ldlm_destroy_export(exp);
5751 tgt_client_free(exp);
5753 LASSERT(cfs_list_empty(&exp->exp_outstanding_replies));
5754 LASSERT(cfs_list_empty(&exp->exp_mdt_data.med_open_head));
5759 static int mdt_rpc_fid2path(struct mdt_thread_info *info, void *key,
5760 void *val, int vallen)
5762 struct mdt_device *mdt = mdt_dev(info->mti_exp->exp_obd->obd_lu_dev);
5763 struct getinfo_fid2path *fpout, *fpin;
5766 fpin = key + cfs_size_round(sizeof(KEY_FID2PATH));
5769 if (ptlrpc_req_need_swab(info->mti_pill->rc_req))
5770 lustre_swab_fid2path(fpin);
5772 memcpy(fpout, fpin, sizeof(*fpin));
5773 if (fpout->gf_pathlen != vallen - sizeof(*fpin))
5776 rc = mdt_fid2path(info->mti_env, mdt, fpout);
5780 static int mdt_fid2path(const struct lu_env *env, struct mdt_device *mdt,
5781 struct getinfo_fid2path *fp)
5783 struct mdt_object *obj;
5784 struct obd_device *obd = mdt2obd_dev(mdt);
5788 CDEBUG(D_IOCTL, "path get "DFID" from "LPU64" #%d\n",
5789 PFID(&fp->gf_fid), fp->gf_recno, fp->gf_linkno);
5791 if (!fid_is_sane(&fp->gf_fid))
5794 if (!fid_is_norm(&fp->gf_fid) && !fid_is_igif(&fp->gf_fid)) {
5795 CWARN("%s: "DFID" is invalid, sequence should be "
5796 ">= "LPX64"\n", obd->obd_name,
5797 PFID(&fp->gf_fid), (__u64)FID_SEQ_NORMAL);
5801 obj = mdt_object_find(env, mdt, &fp->gf_fid);
5802 if (obj == NULL || IS_ERR(obj)) {
5803 CDEBUG(D_IOCTL, "no object "DFID": %ld\n", PFID(&fp->gf_fid),
5808 rc = lu_object_exists(&obj->mot_obj.mo_lu);
5814 mdt_object_put(env, obj);
5815 CDEBUG(D_IOCTL, "nonlocal object "DFID": %d\n",
5816 PFID(&fp->gf_fid), rc);
5820 rc = mo_path(env, md_object_next(&obj->mot_obj), fp->gf_path,
5821 fp->gf_pathlen, &fp->gf_recno, &fp->gf_linkno);
5822 mdt_object_put(env, obj);
5827 static int mdt_get_info(struct mdt_thread_info *info)
5829 struct ptlrpc_request *req = mdt_info_req(info);
5837 key = req_capsule_client_get(info->mti_pill, &RMF_GETINFO_KEY);
5839 CDEBUG(D_IOCTL, "No GETINFO key");
5842 keylen = req_capsule_get_size(info->mti_pill, &RMF_GETINFO_KEY,
5845 vallen = req_capsule_client_get(info->mti_pill, &RMF_GETINFO_VALLEN);
5846 if (vallen == NULL) {
5847 CDEBUG(D_IOCTL, "Unable to get RMF_GETINFO_VALLEN buffer");
5851 req_capsule_set_size(info->mti_pill, &RMF_GETINFO_VAL, RCL_SERVER,
5853 rc = req_capsule_server_pack(info->mti_pill);
5854 valout = req_capsule_server_get(info->mti_pill, &RMF_GETINFO_VAL);
5855 if (valout == NULL) {
5856 CDEBUG(D_IOCTL, "Unable to get get-info RPC out buffer");
5860 if (KEY_IS(KEY_FID2PATH))
5861 rc = mdt_rpc_fid2path(info, key, valout, *vallen);
5865 lustre_msg_set_status(req->rq_repmsg, rc);
5870 /* Pass the ioc down */
5871 static int mdt_ioc_child(struct lu_env *env, struct mdt_device *mdt,
5872 unsigned int cmd, int len, void *data)
5874 struct lu_context ioctl_session;
5875 struct md_device *next = mdt->mdt_child;
5879 rc = lu_context_init(&ioctl_session, LCT_SESSION);
5882 ioctl_session.lc_thread = (struct ptlrpc_thread *)cfs_current();
5883 lu_context_enter(&ioctl_session);
5884 env->le_ses = &ioctl_session;
5886 LASSERT(next->md_ops->mdo_iocontrol);
5887 rc = next->md_ops->mdo_iocontrol(env, next, cmd, len, data);
5889 lu_context_exit(&ioctl_session);
5890 lu_context_fini(&ioctl_session);
5894 static int mdt_ioc_version_get(struct mdt_thread_info *mti, void *karg)
5896 struct obd_ioctl_data *data = karg;
5897 struct lu_fid *fid = (struct lu_fid *)data->ioc_inlbuf1;
5899 struct mdt_object *obj;
5900 struct mdt_lock_handle *lh;
5904 CDEBUG(D_IOCTL, "getting version for "DFID"\n", PFID(fid));
5905 if (!fid_is_sane(fid))
5908 lh = &mti->mti_lh[MDT_LH_PARENT];
5909 mdt_lock_reg_init(lh, LCK_CR);
5911 obj = mdt_object_find_lock(mti, fid, lh, MDS_INODELOCK_UPDATE);
5913 RETURN(PTR_ERR(obj));
5915 rc = mdt_object_exists(obj);
5919 * before calling version get the correct MDS should be
5920 * fid, this is error to find remote object here
5922 CERROR("nonlocal object "DFID"\n", PFID(fid));
5923 } else if (rc == 0) {
5924 *(__u64 *)data->ioc_inlbuf2 = ENOENT_VERSION;
5927 version = dt_version_get(mti->mti_env, mdt_obj2dt(obj));
5928 *(__u64 *)data->ioc_inlbuf2 = version;
5931 mdt_object_unlock_put(mti, obj, lh, 1);
5935 /* ioctls on obd dev */
5936 static int mdt_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
5937 void *karg, void *uarg)
5940 struct obd_device *obd = exp->exp_obd;
5941 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
5942 struct dt_device *dt = mdt->mdt_bottom;
5946 CDEBUG(D_IOCTL, "handling ioctl cmd %#x\n", cmd);
5947 rc = lu_env_init(&env, LCT_MD_THREAD);
5953 rc = mdt_device_sync(&env, mdt);
5955 case OBD_IOC_SET_READONLY:
5956 rc = dt->dd_ops->dt_ro(&env, dt);
5958 case OBD_IOC_ABORT_RECOVERY:
5959 CERROR("Aborting recovery for device %s\n", obd->obd_name);
5960 target_stop_recovery_thread(obd);
5963 case OBD_IOC_CHANGELOG_REG:
5964 case OBD_IOC_CHANGELOG_DEREG:
5965 case OBD_IOC_CHANGELOG_CLEAR:
5966 rc = mdt_ioc_child(&env, mdt, cmd, len, karg);
5968 case OBD_IOC_START_LFSCK:
5969 case OBD_IOC_STOP_LFSCK: {
5970 struct md_device *next = mdt->mdt_child;
5971 struct obd_ioctl_data *data = karg;
5973 if (unlikely(data == NULL)) {
5978 rc = next->md_ops->mdo_iocontrol(&env, next, cmd,
5983 case OBD_IOC_GET_OBJ_VERSION: {
5984 struct mdt_thread_info *mti;
5985 mti = lu_context_key_get(&env.le_ctx, &mdt_thread_key);
5986 memset(mti, 0, sizeof *mti);
5987 mti->mti_env = &env;
5991 rc = mdt_ioc_version_get(mti, karg);
5995 CERROR("Not supported cmd = %d for device %s\n",
5996 cmd, obd->obd_name);
6004 int mdt_postrecov(const struct lu_env *env, struct mdt_device *mdt)
6006 struct lu_device *ld = md2lu_dev(mdt->mdt_child);
6010 rc = ld->ld_ops->ldo_recovery_complete(env, ld);
6014 int mdt_obd_postrecov(struct obd_device *obd)
6019 rc = lu_env_init(&env, LCT_MD_THREAD);
6022 rc = mdt_postrecov(&env, mdt_dev(obd->obd_lu_dev));
6028 * Send a copytool req to a client
6029 * Note this sends a request RPC from a server (MDT) to a client (MDC),
6030 * backwards of normal comms.
6032 int mdt_hsm_copytool_send(struct obd_export *exp)
6035 struct hsm_action_list *hal;
6036 struct hsm_action_item *hai;
6040 CWARN("%s: writing to mdc at %s\n", exp->exp_obd->obd_name,
6041 libcfs_nid2str(exp->exp_connection->c_peer.nid));
6043 len = sizeof(*lh) + sizeof(*hal) + MTI_NAME_MAXLEN +
6044 /* for mockup below */ 2 * cfs_size_round(sizeof(*hai));
6049 lh->kuc_magic = KUC_MAGIC;
6050 lh->kuc_transport = KUC_TRANSPORT_HSM;
6051 lh->kuc_msgtype = HMT_ACTION_LIST;
6052 lh->kuc_msglen = len;
6054 hal = (struct hsm_action_list *)(lh + 1);
6055 hal->hal_version = HAL_VERSION;
6056 hal->hal_archive_num = 1;
6057 obd_uuid2fsname(hal->hal_fsname, exp->exp_obd->obd_name,
6060 /* mock up an action list */
6062 hai = hai_zero(hal);
6063 hai->hai_action = HSMA_ARCHIVE;
6064 hai->hai_fid.f_oid = 0xA00A;
6065 hai->hai_len = sizeof(*hai);
6066 hai = hai_next(hai);
6067 hai->hai_action = HSMA_RESTORE;
6068 hai->hai_fid.f_oid = 0xB00B;
6069 hai->hai_len = sizeof(*hai);
6071 /* Uses the ldlm reverse import; this rpc will be seen by
6072 the ldlm_callback_handler */
6073 rc = do_set_info_async(exp->exp_imp_reverse,
6074 LDLM_SET_INFO, LUSTRE_OBD_VERSION,
6075 sizeof(KEY_HSM_COPYTOOL_SEND),
6076 KEY_HSM_COPYTOOL_SEND,
6084 static struct obd_ops mdt_obd_device_ops = {
6085 .o_owner = THIS_MODULE,
6086 .o_set_info_async = mdt_obd_set_info_async,
6087 .o_connect = mdt_obd_connect,
6088 .o_reconnect = mdt_obd_reconnect,
6089 .o_disconnect = mdt_obd_disconnect,
6090 .o_init_export = mdt_init_export,
6091 .o_destroy_export = mdt_destroy_export,
6092 .o_iocontrol = mdt_iocontrol,
6093 .o_postrecov = mdt_obd_postrecov,
6096 static struct lu_device* mdt_device_fini(const struct lu_env *env,
6097 struct lu_device *d)
6099 struct mdt_device *m = mdt_dev(d);
6106 static struct lu_device *mdt_device_free(const struct lu_env *env,
6107 struct lu_device *d)
6109 struct mdt_device *m = mdt_dev(d);
6112 md_device_fini(&m->mdt_md_dev);
6117 static struct lu_device *mdt_device_alloc(const struct lu_env *env,
6118 struct lu_device_type *t,
6119 struct lustre_cfg *cfg)
6121 struct lu_device *l;
6122 struct mdt_device *m;
6128 l = &m->mdt_md_dev.md_lu_dev;
6129 rc = mdt_init0(env, m, t, cfg);
6131 mdt_device_free(env, l);
6136 l = ERR_PTR(-ENOMEM);
6140 /* context key constructor/destructor: mdt_key_init, mdt_key_fini */
6141 LU_KEY_INIT(mdt, struct mdt_thread_info);
6143 static void mdt_key_fini(const struct lu_context *ctx,
6144 struct lu_context_key *key, void* data)
6146 struct mdt_thread_info *info = data;
6148 if (info->mti_big_lmm) {
6149 OBD_FREE_LARGE(info->mti_big_lmm, info->mti_big_lmmsize);
6150 info->mti_big_lmm = NULL;
6151 info->mti_big_lmmsize = 0;
6156 /* context key: mdt_thread_key */
6157 LU_CONTEXT_KEY_DEFINE(mdt, LCT_MD_THREAD);
6159 struct md_ucred *mdt_ucred(const struct mdt_thread_info *info)
6161 return md_ucred(info->mti_env);
6165 * Enable/disable COS (Commit On Sharing).
6167 * Set/Clear the COS flag in mdt options.
6169 * \param mdt mdt device
6170 * \param val 0 disables COS, other values enable COS
6172 void mdt_enable_cos(struct mdt_device *mdt, int val)
6177 mdt->mdt_opts.mo_cos = !!val;
6178 rc = lu_env_init(&env, LCT_LOCAL);
6179 if (unlikely(rc != 0)) {
6180 CWARN("lu_env initialization failed with rc = %d,"
6181 "cannot sync\n", rc);
6184 mdt_device_sync(&env, mdt);
6189 * Check COS (Commit On Sharing) status.
6191 * Return COS flag status.
6193 * \param mdt mdt device
6195 int mdt_cos_is_enabled(struct mdt_device *mdt)
6197 return mdt->mdt_opts.mo_cos != 0;
6200 /* type constructor/destructor: mdt_type_init, mdt_type_fini */
6201 LU_TYPE_INIT_FINI(mdt, &mdt_thread_key);
6203 static struct lu_device_type_operations mdt_device_type_ops = {
6204 .ldto_init = mdt_type_init,
6205 .ldto_fini = mdt_type_fini,
6207 .ldto_start = mdt_type_start,
6208 .ldto_stop = mdt_type_stop,
6210 .ldto_device_alloc = mdt_device_alloc,
6211 .ldto_device_free = mdt_device_free,
6212 .ldto_device_fini = mdt_device_fini
6215 static struct lu_device_type mdt_device_type = {
6216 .ldt_tags = LU_DEVICE_MD,
6217 .ldt_name = LUSTRE_MDT_NAME,
6218 .ldt_ops = &mdt_device_type_ops,
6219 .ldt_ctx_tags = LCT_MD_THREAD
6222 static int __init mdt_mod_init(void)
6224 struct lprocfs_static_vars lvars;
6227 rc = lu_kmem_init(mdt_caches);
6231 if (mdt_num_threads != 0 && mds_num_threads == 0) {
6232 LCONSOLE_INFO("mdt_num_threads module parameter is deprecated,"
6233 "use mds_num_threads instead or unset both for"
6234 "dynamic thread startup\n");
6235 mds_num_threads = mdt_num_threads;
6238 lprocfs_mdt_init_vars(&lvars);
6239 rc = class_register_type(&mdt_obd_device_ops, NULL,
6240 lvars.module_vars, LUSTRE_MDT_NAME,
6244 lu_kmem_fini(mdt_caches);
6248 static void __exit mdt_mod_exit(void)
6250 class_unregister_type(LUSTRE_MDT_NAME);
6251 lu_kmem_fini(mdt_caches);
6254 #define DEFINE_RPC_HANDLER(base, flags, opc, fn, fmt) \
6257 .mh_fail_id = OBD_FAIL_ ## opc ## _NET, \
6259 .mh_flags = flags, \
6264 /* Request with a format known in advance */
6265 #define DEF_MDT_HDL(flags, name, fn) \
6266 DEFINE_RPC_HANDLER(MDS_GETATTR, flags, name, fn, &RQF_ ## name)
6268 /* Request with a format we do not yet know */
6269 #define DEF_MDT_HDL_VAR(flags, name, fn) \
6270 DEFINE_RPC_HANDLER(MDS_GETATTR, flags, name, fn, NULL)
6272 /* Map one non-standard request format handler. This should probably get
6273 * a common OBD_SET_INFO RPC opcode instead of this mismatch. */
6274 #define RQF_MDS_SET_INFO RQF_OBD_SET_INFO
6276 static struct mdt_handler mdt_mds_ops[] = {
6277 DEF_MDT_HDL(0, MDS_CONNECT, mdt_connect),
6278 DEF_MDT_HDL(0, MDS_DISCONNECT, mdt_disconnect),
6279 DEF_MDT_HDL(0, MDS_SET_INFO, mdt_set_info),
6280 DEF_MDT_HDL(0, MDS_GET_INFO, mdt_get_info),
6281 DEF_MDT_HDL(0 | HABEO_REFERO, MDS_GETSTATUS, mdt_getstatus),
6282 DEF_MDT_HDL(HABEO_CORPUS, MDS_GETATTR, mdt_getattr),
6283 DEF_MDT_HDL(HABEO_CORPUS| HABEO_REFERO, MDS_GETATTR_NAME, mdt_getattr_name),
6284 DEF_MDT_HDL(HABEO_CORPUS, MDS_GETXATTR, mdt_getxattr),
6285 DEF_MDT_HDL(0 | HABEO_REFERO, MDS_STATFS, mdt_statfs),
6286 DEF_MDT_HDL(0 | MUTABOR, MDS_REINT, mdt_reint),
6287 DEF_MDT_HDL(HABEO_CORPUS, MDS_CLOSE, mdt_close),
6288 DEF_MDT_HDL(HABEO_CORPUS, MDS_DONE_WRITING, mdt_done_writing),
6289 DEF_MDT_HDL(0 | HABEO_REFERO, MDS_PIN, mdt_pin),
6290 DEF_MDT_HDL_VAR(0, MDS_SYNC, mdt_sync),
6291 DEF_MDT_HDL(HABEO_CORPUS| HABEO_REFERO, MDS_IS_SUBDIR, mdt_is_subdir),
6292 DEF_MDT_HDL(0, MDS_QUOTACHECK, mdt_quotacheck),
6293 DEF_MDT_HDL(0, MDS_QUOTACTL, mdt_quotactl)
6296 #define DEF_OBD_HDL(flags, name, fn) \
6297 DEFINE_RPC_HANDLER(OBD_PING, flags, name, fn, NULL)
6299 static struct mdt_handler mdt_obd_ops[] = {
6300 DEF_OBD_HDL(0, OBD_PING, mdt_obd_ping),
6301 DEF_OBD_HDL(0, OBD_LOG_CANCEL, mdt_obd_log_cancel),
6302 DEF_OBD_HDL(0, OBD_QC_CALLBACK, mdt_obd_qc_callback),
6303 DEF_OBD_HDL(0, OBD_IDX_READ, mdt_obd_idx_read)
6306 #define DEF_DLM_HDL_VAR(flags, name, fn) \
6307 DEFINE_RPC_HANDLER(LDLM_ENQUEUE, flags, name, fn, NULL)
6308 #define DEF_DLM_HDL(flags, name, fn) \
6309 DEFINE_RPC_HANDLER(LDLM_ENQUEUE, flags, name, fn, &RQF_ ## name)
6311 static struct mdt_handler mdt_dlm_ops[] = {
6312 DEF_DLM_HDL (HABEO_CLAVIS, LDLM_ENQUEUE, mdt_enqueue),
6313 DEF_DLM_HDL_VAR(HABEO_CLAVIS, LDLM_CONVERT, mdt_convert),
6314 DEF_DLM_HDL_VAR(0, LDLM_BL_CALLBACK, mdt_bl_callback),
6315 DEF_DLM_HDL_VAR(0, LDLM_CP_CALLBACK, mdt_cp_callback)
6318 #define DEF_LLOG_HDL(flags, name, fn) \
6319 DEFINE_RPC_HANDLER(LLOG_ORIGIN_HANDLE_CREATE, flags, name, fn, NULL)
6321 static struct mdt_handler mdt_llog_ops[] = {
6322 DEF_LLOG_HDL(0, LLOG_ORIGIN_HANDLE_CREATE, mdt_llog_create),
6323 DEF_LLOG_HDL(0, LLOG_ORIGIN_HANDLE_NEXT_BLOCK, mdt_llog_next_block),
6324 DEF_LLOG_HDL(0, LLOG_ORIGIN_HANDLE_READ_HEADER, mdt_llog_read_header),
6325 DEF_LLOG_HDL(0, LLOG_ORIGIN_HANDLE_WRITE_REC, NULL),
6326 DEF_LLOG_HDL(0, LLOG_ORIGIN_HANDLE_CLOSE, NULL),
6327 DEF_LLOG_HDL(0, LLOG_ORIGIN_CONNECT, NULL),
6328 DEF_LLOG_HDL(0, LLOG_CATINFO, NULL),
6329 DEF_LLOG_HDL(0, LLOG_ORIGIN_HANDLE_PREV_BLOCK, mdt_llog_prev_block),
6330 DEF_LLOG_HDL(0, LLOG_ORIGIN_HANDLE_DESTROY, mdt_llog_destroy),
6333 #define DEF_SEC_HDL(flags, name, fn) \
6334 DEFINE_RPC_HANDLER(SEC_CTX_INIT, flags, name, fn, NULL)
6336 static struct mdt_handler mdt_sec_ctx_ops[] = {
6337 DEF_SEC_HDL(0, SEC_CTX_INIT, mdt_sec_ctx_handle),
6338 DEF_SEC_HDL(0, SEC_CTX_INIT_CONT,mdt_sec_ctx_handle),
6339 DEF_SEC_HDL(0, SEC_CTX_FINI, mdt_sec_ctx_handle)
6342 #define DEF_QUOTA_HDL(flags, name, fn) \
6343 DEFINE_RPC_HANDLER(QUOTA_DQACQ, flags, name, fn, &RQF_ ## name)
6345 static struct mdt_handler mdt_quota_ops[] = {
6346 DEF_QUOTA_HDL(HABEO_REFERO, QUOTA_DQACQ, mdt_quota_dqacq),
6349 static struct mdt_opc_slice mdt_regular_handlers[] = {
6351 .mos_opc_start = MDS_GETATTR,
6352 .mos_opc_end = MDS_LAST_OPC,
6353 .mos_hs = mdt_mds_ops
6356 .mos_opc_start = OBD_PING,
6357 .mos_opc_end = OBD_LAST_OPC,
6358 .mos_hs = mdt_obd_ops
6361 .mos_opc_start = LDLM_ENQUEUE,
6362 .mos_opc_end = LDLM_LAST_OPC,
6363 .mos_hs = mdt_dlm_ops
6366 .mos_opc_start = LLOG_ORIGIN_HANDLE_CREATE,
6367 .mos_opc_end = LLOG_LAST_OPC,
6368 .mos_hs = mdt_llog_ops
6371 .mos_opc_start = SEC_CTX_INIT,
6372 .mos_opc_end = SEC_LAST_OPC,
6373 .mos_hs = mdt_sec_ctx_ops
6376 .mos_opc_start = QUOTA_DQACQ,
6377 .mos_opc_end = QUOTA_LAST_OPC,
6378 .mos_hs = mdt_quota_ops
6385 /* Readpage/readdir handlers */
6386 static struct mdt_handler mdt_readpage_ops[] = {
6387 DEF_MDT_HDL(0, MDS_CONNECT, mdt_connect),
6388 DEF_MDT_HDL(HABEO_CORPUS | HABEO_REFERO, MDS_READPAGE, mdt_readpage),
6389 /* XXX: this is ugly and should be fixed one day, see mdc_close() for
6390 * detailed comments. --umka */
6391 DEF_MDT_HDL(HABEO_CORPUS, MDS_CLOSE, mdt_close),
6392 DEF_MDT_HDL(HABEO_CORPUS, MDS_DONE_WRITING, mdt_done_writing),
6395 static struct mdt_opc_slice mdt_readpage_handlers[] = {
6397 .mos_opc_start = MDS_GETATTR,
6398 .mos_opc_end = MDS_LAST_OPC,
6399 .mos_hs = mdt_readpage_ops
6402 .mos_opc_start = OBD_FIRST_OPC,
6403 .mos_opc_end = OBD_LAST_OPC,
6404 .mos_hs = mdt_obd_ops
6411 /* Cross MDT operation handlers for DNE */
6412 static struct mdt_handler mdt_xmds_ops[] = {
6413 DEF_MDT_HDL(0, MDS_CONNECT, mdt_connect),
6414 DEF_MDT_HDL(HABEO_CORPUS, MDS_GETATTR, mdt_getattr),
6415 DEF_MDT_HDL(0 | MUTABOR, MDS_REINT, mdt_reint),
6416 DEF_MDT_HDL(HABEO_CORPUS| HABEO_REFERO, MDS_IS_SUBDIR, mdt_is_subdir),
6419 static struct mdt_opc_slice mdt_xmds_handlers[] = {
6421 .mos_opc_start = MDS_GETATTR,
6422 .mos_opc_end = MDS_LAST_OPC,
6423 .mos_hs = mdt_xmds_ops
6426 .mos_opc_start = OBD_PING,
6427 .mos_opc_end = OBD_LAST_OPC,
6428 .mos_hs = mdt_obd_ops
6431 .mos_opc_start = SEC_CTX_INIT,
6432 .mos_opc_end = SEC_LAST_OPC,
6433 .mos_hs = mdt_sec_ctx_ops
6440 /* Sequence service handlers */
6441 #define DEF_SEQ_HDL(flags, name, fn) \
6442 DEFINE_RPC_HANDLER(SEQ_QUERY, flags, name, fn, &RQF_ ## name)
6444 static struct mdt_handler mdt_seq_ops[] = {
6445 DEF_SEQ_HDL(0, SEQ_QUERY, (void *)seq_query),
6448 static struct mdt_opc_slice mdt_seq_handlers[] = {
6450 .mos_opc_start = SEQ_QUERY,
6451 .mos_opc_end = SEQ_LAST_OPC,
6452 .mos_hs = mdt_seq_ops
6459 /* FID Location Database handlers */
6460 #define DEF_FLD_HDL(flags, name, fn) \
6461 DEFINE_RPC_HANDLER(FLD_QUERY, flags, name, fn, &RQF_ ## name)
6463 static struct mdt_handler mdt_fld_ops[] = {
6464 DEF_FLD_HDL(0, FLD_QUERY, (void *)fld_query),
6467 static struct mdt_opc_slice mdt_fld_handlers[] = {
6469 .mos_opc_start = FLD_QUERY,
6470 .mos_opc_end = FLD_LAST_OPC,
6471 .mos_hs = mdt_fld_ops
6478 MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");
6479 MODULE_DESCRIPTION("Lustre Metadata Target ("LUSTRE_MDT_NAME")");
6480 MODULE_LICENSE("GPL");
6482 cfs_module(mdt, LUSTRE_VERSION_STRING, mdt_mod_init, mdt_mod_exit);