1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 only,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License version 2 for more details (a copy is included
16 * in the LICENSE file that accompanied this code).
18 * You should have received a copy of the GNU General Public License
19 * version 2 along with this program; If not, see
20 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
29 * Copyright 2008 Sun Microsystems, Inc. All rights reserved
30 * Use is subject to license terms.
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>
50 # define EXPORT_SYMTAB
52 #define DEBUG_SUBSYSTEM S_MDS
54 #include <linux/module.h>
56 * struct OBD_{ALLOC,FREE}*()
58 #include <obd_support.h>
59 /* struct ptlrpc_request */
60 #include <lustre_net.h>
61 /* struct obd_export */
62 #include <lustre_export.h>
63 /* struct obd_device */
66 #include <dt_object.h>
67 #include <lustre_mds.h>
68 #include <lustre_mdt.h>
69 #include "mdt_internal.h"
70 #ifdef HAVE_QUOTA_SUPPORT
71 # include <lustre_quota.h>
73 #include <lustre_acl.h>
74 #include <lustre_param.h>
75 #include <lustre_fsfilt.h>
77 mdl_mode_t mdt_mdl_lock_modes[] = {
78 [LCK_MINMODE] = MDL_MINMODE,
85 [LCK_GROUP] = MDL_GROUP
88 ldlm_mode_t mdt_dlm_lock_modes[] = {
89 [MDL_MINMODE] = LCK_MINMODE,
96 [MDL_GROUP] = LCK_GROUP
100 * Initialized in mdt_mod_init().
102 unsigned long mdt_num_threads;
104 /* ptlrpc request handler for MDT. All handlers are
105 * grouped into several slices - struct mdt_opc_slice,
106 * and stored in an array - mdt_handlers[].
109 /* The name of this handler. */
111 /* Fail id for this handler, checked at the beginning of this handler*/
113 /* Operation code for this handler */
115 /* flags are listed in enum mdt_handler_flags below. */
117 /* The actual handler function to execute. */
118 int (*mh_act)(struct mdt_thread_info *info);
119 /* Request format for this request. */
120 const struct req_format *mh_fmt;
123 enum mdt_handler_flags {
125 * struct mdt_body is passed in the incoming message, and object
126 * identified by this fid exists on disk.
128 * "habeo corpus" == "I have a body"
130 HABEO_CORPUS = (1 << 0),
132 * struct ldlm_request is passed in the incoming message.
134 * "habeo clavis" == "I have a key"
136 HABEO_CLAVIS = (1 << 1),
138 * this request has fixed reply format, so that reply message can be
139 * packed by generic code.
141 * "habeo refero" == "I have a reply"
143 HABEO_REFERO = (1 << 2),
145 * this request will modify something, so check whether the filesystem
146 * is readonly or not, then return -EROFS to client asap if necessary.
148 * "mutabor" == "I shall modify"
153 struct mdt_opc_slice {
156 struct mdt_handler *mos_hs;
159 static struct mdt_opc_slice mdt_regular_handlers[];
160 static struct mdt_opc_slice mdt_readpage_handlers[];
161 static struct mdt_opc_slice mdt_xmds_handlers[];
162 static struct mdt_opc_slice mdt_seq_handlers[];
163 static struct mdt_opc_slice mdt_fld_handlers[];
165 static struct mdt_device *mdt_dev(struct lu_device *d);
166 static int mdt_regular_handle(struct ptlrpc_request *req);
167 static int mdt_unpack_req_pack_rep(struct mdt_thread_info *info, __u32 flags);
168 static int mdt_fid2path(const struct lu_env *env, struct mdt_device *mdt,
169 struct getinfo_fid2path *fp);
171 static const struct lu_object_operations mdt_obj_ops;
173 int mdt_get_disposition(struct ldlm_reply *rep, int flag)
177 return (rep->lock_policy_res1 & flag);
180 void mdt_clear_disposition(struct mdt_thread_info *info,
181 struct ldlm_reply *rep, int flag)
184 info->mti_opdata &= ~flag;
186 rep->lock_policy_res1 &= ~flag;
189 void mdt_set_disposition(struct mdt_thread_info *info,
190 struct ldlm_reply *rep, int flag)
193 info->mti_opdata |= flag;
195 rep->lock_policy_res1 |= flag;
198 void mdt_lock_reg_init(struct mdt_lock_handle *lh, ldlm_mode_t lm)
200 lh->mlh_pdo_hash = 0;
201 lh->mlh_reg_mode = lm;
202 lh->mlh_type = MDT_REG_LOCK;
205 void mdt_lock_pdo_init(struct mdt_lock_handle *lh, ldlm_mode_t lm,
206 const char *name, int namelen)
208 lh->mlh_reg_mode = lm;
209 lh->mlh_type = MDT_PDO_LOCK;
212 LASSERT(namelen > 0);
213 lh->mlh_pdo_hash = full_name_hash(name, namelen);
215 LASSERT(namelen == 0);
216 lh->mlh_pdo_hash = 0ull;
220 static void mdt_lock_pdo_mode(struct mdt_thread_info *info, struct mdt_object *o,
221 struct mdt_lock_handle *lh)
227 * Any dir access needs couple of locks:
229 * 1) on part of dir we gonna take lookup/modify;
231 * 2) on whole dir to protect it from concurrent splitting and/or to
232 * flush client's cache for readdir().
234 * so, for a given mode and object this routine decides what lock mode
235 * to use for lock #2:
237 * 1) if caller's gonna lookup in dir then we need to protect dir from
238 * being splitted only - LCK_CR
240 * 2) if caller's gonna modify dir then we need to protect dir from
241 * being splitted and to flush cache - LCK_CW
243 * 3) if caller's gonna modify dir and that dir seems ready for
244 * splitting then we need to protect it from any type of access
245 * (lookup/modify/split) - LCK_EX --bzzz
248 LASSERT(lh->mlh_reg_mode != LCK_MINMODE);
249 LASSERT(lh->mlh_pdo_mode == LCK_MINMODE);
252 * Ask underlaying level its opinion about preferable PDO lock mode
253 * having access type passed as regular lock mode:
255 * - MDL_MINMODE means that lower layer does not want to specify lock
258 * - MDL_NL means that no PDO lock should be taken. This is used in some
259 * cases. Say, for non-splittable directories no need to use PDO locks
262 mode = mdo_lock_mode(info->mti_env, mdt_object_child(o),
263 mdt_dlm_mode2mdl_mode(lh->mlh_reg_mode));
265 if (mode != MDL_MINMODE) {
266 lh->mlh_pdo_mode = mdt_mdl_mode2dlm_mode(mode);
269 * Lower layer does not want to specify locking mode. We do it
270 * our selves. No special protection is needed, just flush
271 * client's cache on modification and allow concurrent
274 switch (lh->mlh_reg_mode) {
276 lh->mlh_pdo_mode = LCK_EX;
279 lh->mlh_pdo_mode = LCK_CR;
282 lh->mlh_pdo_mode = LCK_CW;
285 CERROR("Not expected lock type (0x%x)\n",
286 (int)lh->mlh_reg_mode);
291 LASSERT(lh->mlh_pdo_mode != LCK_MINMODE);
295 static int mdt_getstatus(struct mdt_thread_info *info)
297 struct mdt_device *mdt = info->mti_mdt;
298 struct md_device *next = mdt->mdt_child;
299 struct mdt_body *repbody;
304 rc = mdt_check_ucred(info);
306 RETURN(err_serious(rc));
308 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_GETSTATUS_PACK))
309 RETURN(err_serious(-ENOMEM));
311 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
312 rc = next->md_ops->mdo_root_get(info->mti_env, next, &repbody->fid1);
316 repbody->valid |= OBD_MD_FLID;
318 if (mdt->mdt_opts.mo_mds_capa &&
319 info->mti_exp->exp_connect_flags & OBD_CONNECT_MDS_CAPA) {
320 struct mdt_object *root;
321 struct lustre_capa *capa;
323 root = mdt_object_find(info->mti_env, mdt, &repbody->fid1);
325 RETURN(PTR_ERR(root));
327 capa = req_capsule_server_get(info->mti_pill, &RMF_CAPA1);
329 capa->lc_opc = CAPA_OPC_MDS_DEFAULT;
330 rc = mo_capa_get(info->mti_env, mdt_object_child(root), capa,
332 mdt_object_put(info->mti_env, root);
334 repbody->valid |= OBD_MD_FLMDSCAPA;
340 static int mdt_statfs(struct mdt_thread_info *info)
342 struct md_device *next = info->mti_mdt->mdt_child;
343 struct ptlrpc_service *svc;
344 struct obd_statfs *osfs;
349 svc = info->mti_pill->rc_req->rq_rqbd->rqbd_service;
351 /* This will trigger a watchdog timeout */
352 OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_STATFS_LCW_SLEEP,
353 (MDT_SERVICE_WATCHDOG_FACTOR *
354 at_get(&svc->srv_at_estimate)) + 1);
356 rc = mdt_check_ucred(info);
358 RETURN(err_serious(rc));
360 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_STATFS_PACK)) {
361 rc = err_serious(-ENOMEM);
363 osfs = req_capsule_server_get(info->mti_pill, &RMF_OBD_STATFS);
364 rc = next->md_ops->mdo_statfs(info->mti_env, next,
366 statfs_pack(osfs, &info->mti_u.ksfs);
372 * Pack SOM attributes into the reply.
373 * Call under a DLM UPDATE lock.
375 static void mdt_pack_size2body(struct mdt_thread_info *info,
376 struct mdt_object *mo)
379 struct md_attr *ma = &info->mti_attr;
381 LASSERT(ma->ma_attr.la_valid & LA_MODE);
382 b = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
384 /* Check if Size-on-MDS is supported, if this is a regular file,
385 * if SOM is enabled on the object and if SOM cache exists and valid.
386 * Otherwise do not pack Size-on-MDS attributes to the reply. */
387 if (!(mdt_conn_flags(info) & OBD_CONNECT_SOM) ||
388 !S_ISREG(ma->ma_attr.la_mode) ||
389 !mdt_object_is_som_enabled(mo) ||
390 !(ma->ma_valid & MA_SOM))
393 b->valid |= OBD_MD_FLSIZE | OBD_MD_FLBLOCKS;
394 b->size = ma->ma_som->msd_size;
395 b->blocks = ma->ma_som->msd_blocks;
398 void mdt_pack_attr2body(struct mdt_thread_info *info, struct mdt_body *b,
399 const struct lu_attr *attr, const struct lu_fid *fid)
401 /*XXX should pack the reply body according to lu_valid*/
402 b->valid |= OBD_MD_FLCTIME | OBD_MD_FLUID |
403 OBD_MD_FLGID | OBD_MD_FLTYPE |
404 OBD_MD_FLMODE | OBD_MD_FLNLINK | OBD_MD_FLFLAGS |
405 OBD_MD_FLATIME | OBD_MD_FLMTIME ;
407 if (!S_ISREG(attr->la_mode))
408 b->valid |= OBD_MD_FLSIZE | OBD_MD_FLBLOCKS | OBD_MD_FLRDEV;
410 b->atime = attr->la_atime;
411 b->mtime = attr->la_mtime;
412 b->ctime = attr->la_ctime;
413 b->mode = attr->la_mode;
414 b->size = attr->la_size;
415 b->blocks = attr->la_blocks;
416 b->uid = attr->la_uid;
417 b->gid = attr->la_gid;
418 b->flags = attr->la_flags;
419 b->nlink = attr->la_nlink;
420 b->rdev = attr->la_rdev;
424 b->valid |= OBD_MD_FLID;
426 /* FIXME: these should be fixed when new igif ready.*/
427 b->ino = fid_oid(fid); /* 1.6 compatibility */
428 b->generation = fid_ver(fid); /* 1.6 compatibility */
429 b->valid |= OBD_MD_FLGENER; /* 1.6 compatibility */
431 CDEBUG(D_INODE, DFID": nlink=%d, mode=%o, size="LPU64"\n",
432 PFID(fid), b->nlink, b->mode, b->size);
436 mdt_body_reverse_idmap(info, b);
439 static inline int mdt_body_has_lov(const struct lu_attr *la,
440 const struct mdt_body *body)
442 return ((S_ISREG(la->la_mode) && (body->valid & OBD_MD_FLEASIZE)) ||
443 (S_ISDIR(la->la_mode) && (body->valid & OBD_MD_FLDIREA )) );
446 static int mdt_getattr_internal(struct mdt_thread_info *info,
447 struct mdt_object *o, int ma_need)
449 struct md_object *next = mdt_object_child(o);
450 const struct mdt_body *reqbody = info->mti_body;
451 struct ptlrpc_request *req = mdt_info_req(info);
452 struct md_attr *ma = &info->mti_attr;
453 struct lu_attr *la = &ma->ma_attr;
454 struct req_capsule *pill = info->mti_pill;
455 const struct lu_env *env = info->mti_env;
456 struct mdt_body *repbody;
457 struct lu_buf *buffer = &info->mti_buf;
461 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_GETATTR_PACK))
462 RETURN(err_serious(-ENOMEM));
464 repbody = req_capsule_server_get(pill, &RMF_MDT_BODY);
468 rc = mdt_object_exists(o);
470 /* This object is located on remote node.*/
471 repbody->fid1 = *mdt_object_fid(o);
472 repbody->valid = OBD_MD_FLID | OBD_MD_MDS;
476 buffer->lb_buf = req_capsule_server_get(pill, &RMF_MDT_MD);
477 buffer->lb_len = req_capsule_get_size(pill, &RMF_MDT_MD, RCL_SERVER);
479 /* If it is dir object and client require MEA, then we got MEA */
480 if (S_ISDIR(lu_object_attr(&next->mo_lu)) &&
481 reqbody->valid & OBD_MD_MEA) {
482 /* Assumption: MDT_MD size is enough for lmv size. */
483 ma->ma_lmv = buffer->lb_buf;
484 ma->ma_lmv_size = buffer->lb_len;
485 ma->ma_need = MA_LMV | MA_INODE;
487 ma->ma_lmm = buffer->lb_buf;
488 ma->ma_lmm_size = buffer->lb_len;
489 ma->ma_need = MA_LOV | MA_INODE;
492 if (S_ISDIR(lu_object_attr(&next->mo_lu)) &&
493 reqbody->valid & OBD_MD_FLDIREA &&
494 lustre_msg_get_opc(req->rq_reqmsg) == MDS_GETATTR) {
495 /* get default stripe info for this dir. */
496 ma->ma_need |= MA_LOV_DEF;
498 ma->ma_need |= ma_need;
499 if (ma->ma_need & MA_SOM)
500 ma->ma_som = &info->mti_u.som.data;
502 rc = mo_attr_get(env, next, ma);
504 CERROR("getattr error for "DFID": %d\n",
505 PFID(mdt_object_fid(o)), rc);
509 if (likely(ma->ma_valid & MA_INODE))
510 mdt_pack_attr2body(info, repbody, la, mdt_object_fid(o));
514 if (mdt_body_has_lov(la, reqbody)) {
515 if (ma->ma_valid & MA_LOV) {
516 LASSERT(ma->ma_lmm_size);
517 mdt_dump_lmm(D_INFO, ma->ma_lmm);
518 repbody->eadatasize = ma->ma_lmm_size;
519 if (S_ISDIR(la->la_mode))
520 repbody->valid |= OBD_MD_FLDIREA;
522 repbody->valid |= OBD_MD_FLEASIZE;
524 if (ma->ma_valid & MA_LMV) {
525 LASSERT(S_ISDIR(la->la_mode));
526 repbody->eadatasize = ma->ma_lmv_size;
527 repbody->valid |= (OBD_MD_FLDIREA|OBD_MD_MEA);
529 if (!(ma->ma_valid & MA_LOV) && !(ma->ma_valid & MA_LMV)) {
530 repbody->valid |= OBD_MD_FLSIZE | OBD_MD_FLBLOCKS;
532 } else if (S_ISLNK(la->la_mode) &&
533 reqbody->valid & OBD_MD_LINKNAME) {
534 buffer->lb_buf = ma->ma_lmm;
535 buffer->lb_len = reqbody->eadatasize;
536 rc = mo_readlink(env, next, buffer);
537 if (unlikely(rc <= 0)) {
538 CERROR("readlink failed: %d\n", rc);
541 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_READLINK_EPROTO))
543 repbody->valid |= OBD_MD_LINKNAME;
544 repbody->eadatasize = rc;
546 ((char*)ma->ma_lmm)[rc - 1] = 0;
547 CDEBUG(D_INODE, "symlink dest %s, len = %d\n",
548 (char*)ma->ma_lmm, rc);
553 if (reqbody->valid & OBD_MD_FLMODEASIZE) {
554 repbody->max_cookiesize = info->mti_mdt->mdt_max_cookiesize;
555 repbody->max_mdsize = info->mti_mdt->mdt_max_mdsize;
556 repbody->valid |= OBD_MD_FLMODEASIZE;
557 CDEBUG(D_INODE, "I am going to change the MAX_MD_SIZE & "
558 "MAX_COOKIE to : %d:%d\n", repbody->max_mdsize,
559 repbody->max_cookiesize);
562 if (exp_connect_rmtclient(info->mti_exp) &&
563 reqbody->valid & OBD_MD_FLRMTPERM) {
564 void *buf = req_capsule_server_get(pill, &RMF_ACL);
566 /* mdt_getattr_lock only */
567 rc = mdt_pack_remote_perm(info, o, buf);
569 repbody->valid &= ~OBD_MD_FLRMTPERM;
570 repbody->aclsize = 0;
573 repbody->valid |= OBD_MD_FLRMTPERM;
574 repbody->aclsize = sizeof(struct mdt_remote_perm);
577 #ifdef CONFIG_FS_POSIX_ACL
578 else if ((req->rq_export->exp_connect_flags & OBD_CONNECT_ACL) &&
579 (reqbody->valid & OBD_MD_FLACL)) {
580 buffer->lb_buf = req_capsule_server_get(pill, &RMF_ACL);
581 buffer->lb_len = req_capsule_get_size(pill,
582 &RMF_ACL, RCL_SERVER);
583 if (buffer->lb_len > 0) {
584 rc = mo_xattr_get(env, next, buffer,
585 XATTR_NAME_ACL_ACCESS);
587 if (rc == -ENODATA) {
588 repbody->aclsize = 0;
589 repbody->valid |= OBD_MD_FLACL;
591 } else if (rc == -EOPNOTSUPP) {
594 CERROR("got acl size: %d\n", rc);
597 repbody->aclsize = rc;
598 repbody->valid |= OBD_MD_FLACL;
605 if (reqbody->valid & OBD_MD_FLMDSCAPA &&
606 info->mti_mdt->mdt_opts.mo_mds_capa &&
607 info->mti_exp->exp_connect_flags & OBD_CONNECT_MDS_CAPA) {
608 struct lustre_capa *capa;
610 capa = req_capsule_server_get(pill, &RMF_CAPA1);
612 capa->lc_opc = CAPA_OPC_MDS_DEFAULT;
613 rc = mo_capa_get(env, next, capa, 0);
616 repbody->valid |= OBD_MD_FLMDSCAPA;
621 static int mdt_renew_capa(struct mdt_thread_info *info)
623 struct mdt_object *obj = info->mti_object;
624 struct mdt_body *body;
625 struct lustre_capa *capa, *c;
629 /* if object doesn't exist, or server has disabled capability,
630 * return directly, client will find body->valid OBD_MD_FLOSSCAPA
633 if (!obj || !info->mti_mdt->mdt_opts.mo_oss_capa ||
634 !(info->mti_exp->exp_connect_flags & OBD_CONNECT_OSS_CAPA))
637 body = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
638 LASSERT(body != NULL);
640 c = req_capsule_client_get(info->mti_pill, &RMF_CAPA1);
643 capa = req_capsule_server_get(info->mti_pill, &RMF_CAPA2);
647 rc = mo_capa_get(info->mti_env, mdt_object_child(obj), capa, 1);
649 body->valid |= OBD_MD_FLOSSCAPA;
653 static int mdt_getattr(struct mdt_thread_info *info)
655 struct mdt_object *obj = info->mti_object;
656 struct req_capsule *pill = info->mti_pill;
657 struct mdt_body *reqbody;
658 struct mdt_body *repbody;
664 reqbody = req_capsule_client_get(pill, &RMF_MDT_BODY);
667 if (reqbody->valid & OBD_MD_FLOSSCAPA) {
668 rc = req_capsule_server_pack(pill);
670 RETURN(err_serious(rc));
671 rc = mdt_renew_capa(info);
672 GOTO(out_shrink, rc);
675 LASSERT(obj != NULL);
676 LASSERT(lu_object_assert_exists(&obj->mot_obj.mo_lu));
678 mode = lu_object_attr(&obj->mot_obj.mo_lu);
679 if (S_ISLNK(mode) && (reqbody->valid & OBD_MD_LINKNAME) &&
680 (reqbody->eadatasize > info->mti_mdt->mdt_max_mdsize))
681 md_size = reqbody->eadatasize;
683 md_size = info->mti_mdt->mdt_max_mdsize;
685 req_capsule_set_size(pill, &RMF_MDT_MD, RCL_SERVER, md_size);
687 rc = req_capsule_server_pack(pill);
688 if (unlikely(rc != 0))
689 RETURN(err_serious(rc));
691 repbody = req_capsule_server_get(pill, &RMF_MDT_BODY);
692 LASSERT(repbody != NULL);
693 repbody->eadatasize = 0;
694 repbody->aclsize = 0;
696 if (reqbody->valid & OBD_MD_FLRMTPERM)
697 rc = mdt_init_ucred(info, reqbody);
699 rc = mdt_check_ucred(info);
701 GOTO(out_shrink, rc);
703 info->mti_spec.sp_ck_split = !!(reqbody->valid & OBD_MD_FLCKSPLIT);
704 info->mti_cross_ref = !!(reqbody->valid & OBD_MD_FLCROSSREF);
707 * Don't check capability at all, because rename might getattr for
708 * remote obj, and at that time no capability is available.
710 mdt_set_capainfo(info, 1, &reqbody->fid1, BYPASS_CAPA);
711 rc = mdt_getattr_internal(info, obj, 0);
712 if (reqbody->valid & OBD_MD_FLRMTPERM)
713 mdt_exit_ucred(info);
716 mdt_shrink_reply(info);
720 static int mdt_is_subdir(struct mdt_thread_info *info)
722 struct mdt_object *o = info->mti_object;
723 struct req_capsule *pill = info->mti_pill;
724 const struct mdt_body *body = info->mti_body;
725 struct mdt_body *repbody;
731 repbody = req_capsule_server_get(pill, &RMF_MDT_BODY);
734 * We save last checked parent fid to @repbody->fid1 for remote
737 LASSERT(fid_is_sane(&body->fid2));
738 LASSERT(mdt_object_exists(o) > 0);
739 rc = mdo_is_subdir(info->mti_env, mdt_object_child(o),
740 &body->fid2, &repbody->fid1);
741 if (rc == 0 || rc == -EREMOTE)
742 repbody->valid |= OBD_MD_FLID;
747 static int mdt_raw_lookup(struct mdt_thread_info *info,
748 struct mdt_object *parent,
749 const struct lu_name *lname,
750 struct ldlm_reply *ldlm_rep)
752 struct md_object *next = mdt_object_child(info->mti_object);
753 const struct mdt_body *reqbody = info->mti_body;
754 struct lu_fid *child_fid = &info->mti_tmp_fid1;
755 struct mdt_body *repbody;
759 if (reqbody->valid != OBD_MD_FLID)
762 LASSERT(!info->mti_cross_ref);
764 /* Only got the fid of this obj by name */
765 rc = mdo_lookup(info->mti_env, next, lname, child_fid,
768 /* XXX is raw_lookup possible as intent operation? */
771 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_NEG);
774 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_POS);
776 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
779 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
780 repbody->fid1 = *child_fid;
781 repbody->valid = OBD_MD_FLID;
787 * UPDATE lock should be taken against parent, and be release before exit;
788 * child_bits lock should be taken against child, and be returned back:
789 * (1)normal request should release the child lock;
790 * (2)intent request will grant the lock to client.
792 static int mdt_getattr_name_lock(struct mdt_thread_info *info,
793 struct mdt_lock_handle *lhc,
795 struct ldlm_reply *ldlm_rep)
797 struct ptlrpc_request *req = mdt_info_req(info);
798 struct mdt_body *reqbody = NULL;
799 struct mdt_object *parent = info->mti_object;
800 struct mdt_object *child;
801 struct md_object *next = mdt_object_child(parent);
802 struct lu_fid *child_fid = &info->mti_tmp_fid1;
803 struct lu_name *lname = NULL;
804 const char *name = NULL;
806 struct mdt_lock_handle *lhp;
807 struct ldlm_lock *lock;
808 struct ldlm_res_id *res_id;
815 is_resent = lustre_handle_is_used(&lhc->mlh_reg_lh);
816 LASSERT(ergo(is_resent,
817 lustre_msg_get_flags(req->rq_reqmsg) & MSG_RESENT));
819 LASSERT(parent != NULL);
820 name = req_capsule_client_get(info->mti_pill, &RMF_NAME);
822 RETURN(err_serious(-EFAULT));
824 namelen = req_capsule_get_size(info->mti_pill, &RMF_NAME,
826 if (!info->mti_cross_ref) {
828 * XXX: Check for "namelen == 0" is for getattr by fid
829 * (OBD_CONNECT_ATTRFID), otherwise do not allow empty name,
830 * that is the name must contain at least one character and
831 * the terminating '\0'
834 reqbody = req_capsule_client_get(info->mti_pill,
836 LASSERT(fid_is_sane(&reqbody->fid2));
839 CDEBUG(D_INODE, "getattr with lock for "DFID"/"DFID", "
841 PFID(mdt_object_fid(parent)), PFID(&reqbody->fid2),
844 lname = mdt_name(info->mti_env, (char *)name, namelen);
845 CDEBUG(D_INODE, "getattr with lock for "DFID"/%s, "
846 "ldlm_rep = %p\n", PFID(mdt_object_fid(parent)),
850 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_EXECD);
852 rc = mdt_object_exists(parent);
853 if (unlikely(rc == 0)) {
854 LU_OBJECT_DEBUG(D_WARNING, info->mti_env,
855 &parent->mot_obj.mo_lu,
856 "Parent doesn't exist!\n");
858 } else if (!info->mti_cross_ref) {
859 LASSERTF(rc > 0, "Parent "DFID" is on remote server\n",
860 PFID(mdt_object_fid(parent)));
863 rc = mdt_raw_lookup(info, parent, lname, ldlm_rep);
871 if (info->mti_cross_ref) {
872 /* Only getattr on the child. Parent is on another node. */
873 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_POS);
875 CDEBUG(D_INODE, "partial getattr_name child_fid = "DFID", "
876 "ldlm_rep=%p\n", PFID(mdt_object_fid(child)), ldlm_rep);
879 /* Do not take lock for resent case. */
880 lock = ldlm_handle2lock(&lhc->mlh_reg_lh);
881 LASSERTF(lock != NULL, "Invalid lock handle "LPX64"\n",
882 lhc->mlh_reg_lh.cookie);
883 LASSERT(fid_res_name_eq(mdt_object_fid(child),
884 &lock->l_resource->lr_name));
888 mdt_lock_handle_init(lhc);
889 mdt_lock_reg_init(lhc, LCK_PR);
892 * Object's name is on another MDS, no lookup lock is
893 * needed here but update is.
895 child_bits &= ~MDS_INODELOCK_LOOKUP;
896 child_bits |= MDS_INODELOCK_UPDATE;
898 rc = mdt_object_lock(info, child, lhc, child_bits,
902 /* Finally, we can get attr for child. */
903 mdt_set_capainfo(info, 0, mdt_object_fid(child),
905 rc = mdt_getattr_internal(info, child, 0);
906 if (unlikely(rc != 0))
907 mdt_object_unlock(info, child, lhc, 1);
912 /* step 1: lock parent */
913 lhp = &info->mti_lh[MDT_LH_PARENT];
914 mdt_lock_pdo_init(lhp, LCK_PR, name, namelen);
915 rc = mdt_object_lock(info, parent, lhp, MDS_INODELOCK_UPDATE,
918 if (unlikely(rc != 0))
922 /* step 2: lookup child's fid by name */
923 rc = mdo_lookup(info->mti_env, next, lname, child_fid,
928 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_NEG);
929 GOTO(out_parent, rc);
931 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_POS);
933 *child_fid = reqbody->fid2;
934 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_POS);
938 *step 3: find the child object by fid & lock it.
939 * regardless if it is local or remote.
941 child = mdt_object_find(info->mti_env, info->mti_mdt, child_fid);
943 if (unlikely(IS_ERR(child)))
944 GOTO(out_parent, rc = PTR_ERR(child));
946 /* Do not take lock for resent case. */
947 lock = ldlm_handle2lock(&lhc->mlh_reg_lh);
948 LASSERTF(lock != NULL, "Invalid lock handle "LPX64"\n",
949 lhc->mlh_reg_lh.cookie);
951 res_id = &lock->l_resource->lr_name;
952 if (!fid_res_name_eq(mdt_object_fid(child),
953 &lock->l_resource->lr_name)) {
954 LASSERTF(fid_res_name_eq(mdt_object_fid(parent),
955 &lock->l_resource->lr_name),
956 "Lock res_id: %lu/%lu/%lu, Fid: "DFID".\n",
957 (unsigned long)res_id->name[0],
958 (unsigned long)res_id->name[1],
959 (unsigned long)res_id->name[2],
960 PFID(mdt_object_fid(parent)));
961 CWARN("Although resent, but still not get child lock"
962 "parent:"DFID" child:"DFID"\n",
963 PFID(mdt_object_fid(parent)),
964 PFID(mdt_object_fid(child)));
965 lustre_msg_clear_flags(req->rq_reqmsg, MSG_RESENT);
974 ma = &info->mti_attr;
976 OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_RESEND, obd_timeout*2);
977 mdt_lock_handle_init(lhc);
978 mdt_lock_reg_init(lhc, LCK_PR);
980 if (mdt_object_exists(child) == 0) {
981 LU_OBJECT_DEBUG(D_WARNING, info->mti_env,
982 &child->mot_obj.mo_lu,
983 "Object doesn't exist!\n");
984 GOTO(out_child, rc = -ESTALE);
988 ma->ma_need = MA_INODE;
989 rc = mo_attr_get(info->mti_env, next, ma);
990 if (unlikely(rc != 0))
993 /* If the file has not been changed for some time, we return
994 * not only a LOOKUP lock, but also an UPDATE lock and this
995 * might save us RPC on later STAT. For directories, it also
996 * let negative dentry starts working for this dir. */
997 if (ma->ma_valid & MA_INODE &&
998 ma->ma_attr.la_valid & LA_CTIME &&
999 info->mti_mdt->mdt_namespace->ns_ctime_age_limit +
1000 ma->ma_attr.la_ctime < cfs_time_current_sec())
1001 child_bits |= MDS_INODELOCK_UPDATE;
1003 rc = mdt_object_lock(info, child, lhc, child_bits,
1006 if (unlikely(rc != 0))
1007 GOTO(out_child, rc);
1010 lock = ldlm_handle2lock(&lhc->mlh_reg_lh);
1011 /* Get MA_SOM attributes if update lock is given. */
1013 lock->l_policy_data.l_inodebits.bits & MDS_INODELOCK_UPDATE &&
1014 S_ISREG(lu_object_attr(&mdt_object_child(child)->mo_lu)))
1017 /* finally, we can get attr for child. */
1018 mdt_set_capainfo(info, 1, child_fid, BYPASS_CAPA);
1019 rc = mdt_getattr_internal(info, child, ma_need);
1020 if (unlikely(rc != 0)) {
1021 mdt_object_unlock(info, child, lhc, 1);
1023 /* Debugging code. */
1024 res_id = &lock->l_resource->lr_name;
1025 LDLM_DEBUG(lock, "Returning lock to client");
1026 LASSERTF(fid_res_name_eq(mdt_object_fid(child),
1027 &lock->l_resource->lr_name),
1028 "Lock res_id: %lu/%lu/%lu, Fid: "DFID".\n",
1029 (unsigned long)res_id->name[0],
1030 (unsigned long)res_id->name[1],
1031 (unsigned long)res_id->name[2],
1032 PFID(mdt_object_fid(child)));
1033 mdt_pack_size2body(info, child);
1036 LDLM_LOCK_PUT(lock);
1040 mdt_object_put(info->mti_env, child);
1042 mdt_object_unlock(info, parent, lhp, 1);
1046 /* normal handler: should release the child lock */
1047 static int mdt_getattr_name(struct mdt_thread_info *info)
1049 struct mdt_lock_handle *lhc = &info->mti_lh[MDT_LH_CHILD];
1050 struct mdt_body *reqbody;
1051 struct mdt_body *repbody;
1055 reqbody = req_capsule_client_get(info->mti_pill, &RMF_MDT_BODY);
1056 LASSERT(reqbody != NULL);
1057 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
1058 LASSERT(repbody != NULL);
1060 info->mti_spec.sp_ck_split = !!(reqbody->valid & OBD_MD_FLCKSPLIT);
1061 info->mti_cross_ref = !!(reqbody->valid & OBD_MD_FLCROSSREF);
1062 repbody->eadatasize = 0;
1063 repbody->aclsize = 0;
1065 rc = mdt_init_ucred(info, reqbody);
1067 GOTO(out_shrink, rc);
1069 rc = mdt_getattr_name_lock(info, lhc, MDS_INODELOCK_UPDATE, NULL);
1070 if (lustre_handle_is_used(&lhc->mlh_reg_lh)) {
1071 ldlm_lock_decref(&lhc->mlh_reg_lh, lhc->mlh_reg_mode);
1072 lhc->mlh_reg_lh.cookie = 0;
1074 mdt_exit_ucred(info);
1077 mdt_shrink_reply(info);
1081 static const struct lu_device_operations mdt_lu_ops;
1083 static int lu_device_is_mdt(struct lu_device *d)
1085 return ergo(d != NULL && d->ld_ops != NULL, d->ld_ops == &mdt_lu_ops);
1088 static int mdt_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
1089 void *karg, void *uarg);
1091 static int mdt_set_info(struct mdt_thread_info *info)
1093 struct ptlrpc_request *req = mdt_info_req(info);
1096 int keylen, vallen, rc = 0;
1099 rc = req_capsule_server_pack(info->mti_pill);
1103 key = req_capsule_client_get(info->mti_pill, &RMF_SETINFO_KEY);
1105 DEBUG_REQ(D_HA, req, "no set_info key");
1109 keylen = req_capsule_get_size(info->mti_pill, &RMF_SETINFO_KEY,
1112 val = req_capsule_client_get(info->mti_pill, &RMF_SETINFO_VAL);
1114 DEBUG_REQ(D_HA, req, "no set_info val");
1118 vallen = req_capsule_get_size(info->mti_pill, &RMF_SETINFO_VAL,
1121 /* Swab any part of val you need to here */
1122 if (KEY_IS(KEY_READ_ONLY)) {
1124 lustre_msg_set_status(req->rq_repmsg, 0);
1126 cfs_spin_lock(&req->rq_export->exp_lock);
1128 req->rq_export->exp_connect_flags |= OBD_CONNECT_RDONLY;
1130 req->rq_export->exp_connect_flags &=~OBD_CONNECT_RDONLY;
1131 cfs_spin_unlock(&req->rq_export->exp_lock);
1133 } else if (KEY_IS(KEY_CHANGELOG_CLEAR)) {
1134 struct changelog_setinfo *cs =
1135 (struct changelog_setinfo *)val;
1136 if (vallen != sizeof(*cs)) {
1137 CERROR("Bad changelog_clear setinfo size %d\n", vallen);
1140 if (ptlrpc_req_need_swab(req)) {
1141 __swab64s(&cs->cs_recno);
1142 __swab32s(&cs->cs_id);
1145 rc = mdt_iocontrol(OBD_IOC_CHANGELOG_CLEAR, info->mti_exp,
1147 lustre_msg_set_status(req->rq_repmsg, rc);
1155 static int mdt_connect(struct mdt_thread_info *info)
1158 struct ptlrpc_request *req;
1160 req = mdt_info_req(info);
1161 rc = target_handle_connect(req);
1163 LASSERT(req->rq_export != NULL);
1164 info->mti_mdt = mdt_dev(req->rq_export->exp_obd->obd_lu_dev);
1165 rc = mdt_init_sec_level(info);
1167 rc = mdt_init_idmap(info);
1169 obd_disconnect(class_export_get(req->rq_export));
1171 rc = err_serious(rc);
1176 static int mdt_disconnect(struct mdt_thread_info *info)
1181 rc = target_handle_disconnect(mdt_info_req(info));
1183 rc = err_serious(rc);
1187 static int mdt_sendpage(struct mdt_thread_info *info,
1188 struct lu_rdpg *rdpg)
1190 struct ptlrpc_request *req = mdt_info_req(info);
1191 struct obd_export *exp = req->rq_export;
1192 struct ptlrpc_bulk_desc *desc;
1193 struct l_wait_info *lwi = &info->mti_u.rdpg.mti_wait_info;
1201 desc = ptlrpc_prep_bulk_exp(req, rdpg->rp_npages, BULK_PUT_SOURCE,
1206 for (i = 0, tmpcount = rdpg->rp_count;
1207 i < rdpg->rp_npages; i++, tmpcount -= tmpsize) {
1208 tmpsize = min_t(int, tmpcount, CFS_PAGE_SIZE);
1209 ptlrpc_prep_bulk_page(desc, rdpg->rp_pages[i], 0, tmpsize);
1212 LASSERT(desc->bd_nob == rdpg->rp_count);
1213 rc = sptlrpc_svc_wrap_bulk(req, desc);
1215 GOTO(free_desc, rc);
1217 rc = ptlrpc_start_bulk_transfer(desc);
1219 GOTO(free_desc, rc);
1221 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_SENDPAGE))
1222 GOTO(abort_bulk, rc = 0);
1224 timeout = (int) req->rq_deadline - cfs_time_current_sec();
1226 CERROR("Req deadline already passed %lu (now: %lu)\n",
1227 req->rq_deadline, cfs_time_current_sec());
1228 *lwi = LWI_TIMEOUT_INTERVAL(cfs_time_seconds(max(timeout, 1)),
1229 cfs_time_seconds(1), NULL, NULL);
1230 rc = l_wait_event(desc->bd_waitq, !ptlrpc_server_bulk_active(desc) ||
1231 exp->exp_failed || exp->exp_abort_active_req, lwi);
1232 LASSERT (rc == 0 || rc == -ETIMEDOUT);
1235 if (desc->bd_success &&
1236 desc->bd_nob_transferred == rdpg->rp_count)
1237 GOTO(free_desc, rc);
1240 if (exp->exp_abort_active_req || exp->exp_failed)
1241 GOTO(abort_bulk, rc);
1244 DEBUG_REQ(D_ERROR, req, "bulk failed: %s %d(%d), evicting %s@%s",
1245 (rc == -ETIMEDOUT) ? "timeout" : "network error",
1246 desc->bd_nob_transferred, rdpg->rp_count,
1247 exp->exp_client_uuid.uuid,
1248 exp->exp_connection->c_remote_uuid.uuid);
1250 class_fail_export(exp);
1254 ptlrpc_abort_bulk(desc);
1256 ptlrpc_free_bulk(desc);
1260 #ifdef HAVE_SPLIT_SUPPORT
1262 * Retrieve dir entry from the page and insert it to the slave object, actually,
1263 * this should be in osd layer, but since it will not in the final product, so
1264 * just do it here and do not define more moo api anymore for this.
1266 static int mdt_write_dir_page(struct mdt_thread_info *info, struct page *page,
1269 struct mdt_object *object = info->mti_object;
1270 struct lu_fid *lf = &info->mti_tmp_fid2;
1271 struct md_attr *ma = &info->mti_attr;
1272 struct lu_dirpage *dp;
1273 struct lu_dirent *ent;
1274 int rc = 0, offset = 0;
1277 /* Make sure we have at least one entry. */
1282 * Disable trans for this name insert, since it will include many trans
1285 info->mti_no_need_trans = 1;
1287 * When write_dir_page, no need update parent's ctime,
1288 * and no permission check for name_insert.
1290 ma->ma_attr.la_ctime = 0;
1291 ma->ma_attr.la_valid = LA_MODE;
1292 ma->ma_valid = MA_INODE;
1295 dp = page_address(page);
1296 offset = (int)((__u32)lu_dirent_start(dp) - (__u32)dp);
1298 for (ent = lu_dirent_start(dp); ent != NULL;
1299 ent = lu_dirent_next(ent)) {
1300 struct lu_name *lname;
1303 if (le16_to_cpu(ent->lde_namelen) == 0)
1306 fid_le_to_cpu(lf, &ent->lde_fid);
1307 if (le64_to_cpu(ent->lde_hash) & MAX_HASH_HIGHEST_BIT)
1308 ma->ma_attr.la_mode = S_IFDIR;
1310 ma->ma_attr.la_mode = 0;
1311 OBD_ALLOC(name, le16_to_cpu(ent->lde_namelen) + 1);
1313 GOTO(out, rc = -ENOMEM);
1315 memcpy(name, ent->lde_name, le16_to_cpu(ent->lde_namelen));
1316 lname = mdt_name(info->mti_env, name,
1317 le16_to_cpu(ent->lde_namelen));
1318 ma->ma_attr_flags |= (MDS_PERM_BYPASS | MDS_QUOTA_IGNORE);
1319 rc = mdo_name_insert(info->mti_env,
1320 md_object_next(&object->mot_obj),
1322 OBD_FREE(name, le16_to_cpu(ent->lde_namelen) + 1);
1324 CERROR("Can't insert %*.*s, rc %d\n",
1325 le16_to_cpu(ent->lde_namelen),
1326 le16_to_cpu(ent->lde_namelen),
1331 offset += lu_dirent_size(ent);
1341 static int mdt_bulk_timeout(void *data)
1345 CERROR("mdt bulk transfer timeout \n");
1350 static int mdt_writepage(struct mdt_thread_info *info)
1352 struct ptlrpc_request *req = mdt_info_req(info);
1353 struct mdt_body *reqbody;
1354 struct l_wait_info *lwi;
1355 struct ptlrpc_bulk_desc *desc;
1361 reqbody = req_capsule_client_get(info->mti_pill, &RMF_MDT_BODY);
1362 if (reqbody == NULL)
1363 RETURN(err_serious(-EFAULT));
1365 desc = ptlrpc_prep_bulk_exp(req, 1, BULK_GET_SINK, MDS_BULK_PORTAL);
1367 RETURN(err_serious(-ENOMEM));
1369 /* allocate the page for the desc */
1370 page = cfs_alloc_page(CFS_ALLOC_STD);
1372 GOTO(desc_cleanup, rc = -ENOMEM);
1374 CDEBUG(D_INFO, "Received page offset %d size %d \n",
1375 (int)reqbody->size, (int)reqbody->nlink);
1377 ptlrpc_prep_bulk_page(desc, page, (int)reqbody->size,
1378 (int)reqbody->nlink);
1380 rc = sptlrpc_svc_prep_bulk(req, desc);
1382 GOTO(cleanup_page, rc);
1384 * Check if client was evicted while we were doing i/o before touching
1389 GOTO(cleanup_page, rc = -ENOMEM);
1391 if (desc->bd_export->exp_failed)
1394 rc = ptlrpc_start_bulk_transfer (desc);
1396 *lwi = LWI_TIMEOUT_INTERVAL(obd_timeout * CFS_HZ / 4, CFS_HZ,
1397 mdt_bulk_timeout, desc);
1398 rc = l_wait_event(desc->bd_waitq, !ptlrpc_bulk_active(desc) ||
1399 desc->bd_export->exp_failed, lwi);
1400 LASSERT(rc == 0 || rc == -ETIMEDOUT);
1401 if (rc == -ETIMEDOUT) {
1402 DEBUG_REQ(D_ERROR, req, "timeout on bulk GET");
1403 ptlrpc_abort_bulk(desc);
1404 } else if (desc->bd_export->exp_failed) {
1405 DEBUG_REQ(D_ERROR, req, "Eviction on bulk GET");
1407 ptlrpc_abort_bulk(desc);
1408 } else if (!desc->bd_success ||
1409 desc->bd_nob_transferred != desc->bd_nob) {
1410 DEBUG_REQ(D_ERROR, req, "%s bulk GET %d(%d)",
1412 "truncated" : "network error on",
1413 desc->bd_nob_transferred, desc->bd_nob);
1414 /* XXX should this be a different errno? */
1418 DEBUG_REQ(D_ERROR, req, "ptlrpc_bulk_get failed: rc %d", rc);
1421 GOTO(cleanup_lwi, rc);
1422 rc = mdt_write_dir_page(info, page, reqbody->nlink);
1427 cfs_free_page(page);
1429 ptlrpc_free_bulk(desc);
1434 static int mdt_readpage(struct mdt_thread_info *info)
1436 struct mdt_object *object = info->mti_object;
1437 struct lu_rdpg *rdpg = &info->mti_u.rdpg.mti_rdpg;
1438 struct mdt_body *reqbody;
1439 struct mdt_body *repbody;
1444 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_READPAGE_PACK))
1445 RETURN(err_serious(-ENOMEM));
1447 reqbody = req_capsule_client_get(info->mti_pill, &RMF_MDT_BODY);
1448 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
1449 if (reqbody == NULL || repbody == NULL)
1450 RETURN(err_serious(-EFAULT));
1453 * prepare @rdpg before calling lower layers and transfer itself. Here
1454 * reqbody->size contains offset of where to start to read and
1455 * reqbody->nlink contains number bytes to read.
1457 rdpg->rp_hash = reqbody->size;
1458 if (rdpg->rp_hash != reqbody->size) {
1459 CERROR("Invalid hash: "LPX64" != "LPX64"\n",
1460 rdpg->rp_hash, reqbody->size);
1464 rdpg->rp_attrs = reqbody->mode;
1465 rdpg->rp_count = reqbody->nlink;
1466 rdpg->rp_npages = (rdpg->rp_count + CFS_PAGE_SIZE - 1)>>CFS_PAGE_SHIFT;
1467 OBD_ALLOC(rdpg->rp_pages, rdpg->rp_npages * sizeof rdpg->rp_pages[0]);
1468 if (rdpg->rp_pages == NULL)
1471 for (i = 0; i < rdpg->rp_npages; ++i) {
1472 rdpg->rp_pages[i] = cfs_alloc_page(CFS_ALLOC_STD);
1473 if (rdpg->rp_pages[i] == NULL)
1474 GOTO(free_rdpg, rc = -ENOMEM);
1477 /* call lower layers to fill allocated pages with directory data */
1478 rc = mo_readpage(info->mti_env, mdt_object_child(object), rdpg);
1480 GOTO(free_rdpg, rc);
1482 /* send pages to client */
1483 rc = mdt_sendpage(info, rdpg);
1488 for (i = 0; i < rdpg->rp_npages; i++)
1489 if (rdpg->rp_pages[i] != NULL)
1490 cfs_free_page(rdpg->rp_pages[i]);
1491 OBD_FREE(rdpg->rp_pages, rdpg->rp_npages * sizeof rdpg->rp_pages[0]);
1493 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_SENDPAGE))
1499 static int mdt_reint_internal(struct mdt_thread_info *info,
1500 struct mdt_lock_handle *lhc,
1503 struct req_capsule *pill = info->mti_pill;
1504 struct mdt_device *mdt = info->mti_mdt;
1505 struct md_quota *mq = md_quota(info->mti_env);
1506 struct mdt_body *repbody;
1511 if (req_capsule_has_field(pill, &RMF_MDT_MD, RCL_SERVER))
1512 req_capsule_set_size(pill, &RMF_MDT_MD, RCL_SERVER,
1513 mdt->mdt_max_mdsize);
1514 if (req_capsule_has_field(pill, &RMF_LOGCOOKIES, RCL_SERVER))
1515 req_capsule_set_size(pill, &RMF_LOGCOOKIES, RCL_SERVER,
1516 mdt->mdt_max_cookiesize);
1518 rc = req_capsule_server_pack(pill);
1520 CERROR("Can't pack response, rc %d\n", rc);
1521 RETURN(err_serious(rc));
1524 if (req_capsule_has_field(pill, &RMF_MDT_BODY, RCL_SERVER)) {
1525 repbody = req_capsule_server_get(pill, &RMF_MDT_BODY);
1527 repbody->eadatasize = 0;
1528 repbody->aclsize = 0;
1531 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_REINT_UNPACK))
1532 GOTO(out_shrink, rc = err_serious(-EFAULT));
1534 rc = mdt_reint_unpack(info, op);
1536 CERROR("Can't unpack reint, rc %d\n", rc);
1537 GOTO(out_shrink, rc = err_serious(rc));
1540 OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_REINT_DELAY, 10);
1542 /* for replay no cookkie / lmm need, because client have this already */
1543 if (info->mti_spec.no_create == 1) {
1544 if (req_capsule_has_field(pill, &RMF_MDT_MD, RCL_SERVER))
1545 req_capsule_set_size(pill, &RMF_MDT_MD, RCL_SERVER, 0);
1547 if (req_capsule_has_field(pill, &RMF_LOGCOOKIES, RCL_SERVER))
1548 req_capsule_set_size(pill, &RMF_LOGCOOKIES, RCL_SERVER,
1552 rc = mdt_init_ucred_reint(info);
1554 GOTO(out_shrink, rc);
1556 rc = mdt_fix_attr_ucred(info, op);
1558 GOTO(out_ucred, rc = err_serious(rc));
1560 if (mdt_check_resent(info, mdt_reconstruct, lhc)) {
1561 rc = lustre_msg_get_status(mdt_info_req(info)->rq_repmsg);
1562 GOTO(out_ucred, rc);
1564 mq->mq_exp = info->mti_exp;
1565 rc = mdt_reint_rec(info, lhc);
1568 mdt_exit_ucred(info);
1570 mdt_shrink_reply(info);
1574 static long mdt_reint_opcode(struct mdt_thread_info *info,
1575 const struct req_format **fmt)
1577 struct mdt_rec_reint *rec;
1580 opc = err_serious(-EFAULT);
1581 rec = req_capsule_client_get(info->mti_pill, &RMF_REC_REINT);
1583 opc = rec->rr_opcode;
1584 DEBUG_REQ(D_INODE, mdt_info_req(info), "reint opt = %ld", opc);
1585 if (opc < REINT_MAX && fmt[opc] != NULL)
1586 req_capsule_extend(info->mti_pill, fmt[opc]);
1588 CERROR("Unsupported opc: %ld\n", opc);
1589 opc = err_serious(opc);
1595 static int mdt_reint(struct mdt_thread_info *info)
1600 static const struct req_format *reint_fmts[REINT_MAX] = {
1601 [REINT_SETATTR] = &RQF_MDS_REINT_SETATTR,
1602 [REINT_CREATE] = &RQF_MDS_REINT_CREATE,
1603 [REINT_LINK] = &RQF_MDS_REINT_LINK,
1604 [REINT_UNLINK] = &RQF_MDS_REINT_UNLINK,
1605 [REINT_RENAME] = &RQF_MDS_REINT_RENAME,
1606 [REINT_OPEN] = &RQF_MDS_REINT_OPEN,
1607 [REINT_SETXATTR] = &RQF_MDS_REINT_SETXATTR
1612 opc = mdt_reint_opcode(info, reint_fmts);
1615 * No lock possible here from client to pass it to reint code
1618 rc = mdt_reint_internal(info, NULL, opc);
1623 info->mti_fail_id = OBD_FAIL_MDS_REINT_NET_REP;
1627 /* this should sync the whole device */
1628 static int mdt_device_sync(const struct lu_env *env, struct mdt_device *mdt)
1630 struct dt_device *dt = mdt->mdt_bottom;
1634 rc = dt->dd_ops->dt_sync(env, dt);
1638 /* this should sync this object */
1639 static int mdt_object_sync(struct mdt_thread_info *info)
1641 struct md_object *next;
1645 if (!mdt_object_exists(info->mti_object)) {
1646 CWARN("Non existing object "DFID"!\n",
1647 PFID(mdt_object_fid(info->mti_object)));
1650 next = mdt_object_child(info->mti_object);
1651 rc = mo_object_sync(info->mti_env, next);
1656 static int mdt_sync(struct mdt_thread_info *info)
1658 struct req_capsule *pill = info->mti_pill;
1659 struct mdt_body *body;
1663 /* The fid may be zero, so we req_capsule_set manually */
1664 req_capsule_set(pill, &RQF_MDS_SYNC);
1666 body = req_capsule_client_get(pill, &RMF_MDT_BODY);
1668 RETURN(err_serious(-EINVAL));
1670 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_SYNC_PACK))
1671 RETURN(err_serious(-ENOMEM));
1673 if (fid_seq(&body->fid1) == 0) {
1674 /* sync the whole device */
1675 rc = req_capsule_server_pack(pill);
1677 rc = mdt_device_sync(info->mti_env, info->mti_mdt);
1679 rc = err_serious(rc);
1681 /* sync an object */
1682 rc = mdt_unpack_req_pack_rep(info, HABEO_CORPUS|HABEO_REFERO);
1684 rc = mdt_object_sync(info);
1686 struct md_object *next;
1687 const struct lu_fid *fid;
1688 struct lu_attr *la = &info->mti_attr.ma_attr;
1690 next = mdt_object_child(info->mti_object);
1691 info->mti_attr.ma_need = MA_INODE;
1692 info->mti_attr.ma_valid = 0;
1693 rc = mo_attr_get(info->mti_env, next,
1696 body = req_capsule_server_get(pill,
1698 fid = mdt_object_fid(info->mti_object);
1699 mdt_pack_attr2body(info, body, la, fid);
1703 rc = err_serious(rc);
1708 #ifdef HAVE_QUOTA_SUPPORT
1709 static int mdt_quotacheck_handle(struct mdt_thread_info *info)
1711 struct obd_quotactl *oqctl;
1712 struct req_capsule *pill = info->mti_pill;
1713 struct obd_export *exp = info->mti_exp;
1714 struct md_quota *mq = md_quota(info->mti_env);
1715 struct md_device *next = info->mti_mdt->mdt_child;
1719 oqctl = req_capsule_client_get(pill, &RMF_OBD_QUOTACTL);
1723 /* remote client has no permission for quotacheck */
1724 if (unlikely(exp_connect_rmtclient(exp)))
1727 rc = req_capsule_server_pack(pill);
1732 rc = next->md_ops->mdo_quota.mqo_check(info->mti_env, next,
1737 static int mdt_quotactl_handle(struct mdt_thread_info *info)
1739 struct obd_quotactl *oqctl, *repoqc;
1740 struct req_capsule *pill = info->mti_pill;
1741 struct obd_export *exp = info->mti_exp;
1742 struct md_quota *mq = md_quota(info->mti_env);
1743 struct md_device *next = info->mti_mdt->mdt_child;
1744 const struct md_quota_operations *mqo = &next->md_ops->mdo_quota;
1748 oqctl = req_capsule_client_get(pill, &RMF_OBD_QUOTACTL);
1753 if (exp_connect_rmtclient(exp)) {
1754 struct ptlrpc_request *req = mdt_info_req(info);
1755 struct mdt_export_data *med = mdt_req2med(req);
1756 struct lustre_idmap_table *idmap = med->med_idmap;
1758 if (unlikely(oqctl->qc_cmd != Q_GETQUOTA &&
1759 oqctl->qc_cmd != Q_GETINFO))
1763 if (oqctl->qc_type == USRQUOTA)
1764 id = lustre_idmap_lookup_uid(NULL, idmap, 0,
1766 else if (oqctl->qc_type == GRPQUOTA)
1767 id = lustre_idmap_lookup_gid(NULL, idmap, 0,
1772 if (id == CFS_IDMAP_NOTFOUND) {
1773 CDEBUG(D_QUOTA, "no mapping for id %u\n",
1779 rc = req_capsule_server_pack(pill);
1783 repoqc = req_capsule_server_get(pill, &RMF_OBD_QUOTACTL);
1784 LASSERT(repoqc != NULL);
1787 switch (oqctl->qc_cmd) {
1789 rc = mqo->mqo_on(info->mti_env, next, oqctl->qc_type);
1792 rc = mqo->mqo_off(info->mti_env, next, oqctl->qc_type);
1795 rc = mqo->mqo_setinfo(info->mti_env, next, oqctl->qc_type, id,
1799 rc = mqo->mqo_getinfo(info->mti_env, next, oqctl->qc_type, id,
1803 rc = mqo->mqo_setquota(info->mti_env, next, oqctl->qc_type, id,
1807 rc = mqo->mqo_getquota(info->mti_env, next, oqctl->qc_type, id,
1811 rc = mqo->mqo_getoinfo(info->mti_env, next, oqctl->qc_type, id,
1815 rc = mqo->mqo_getoquota(info->mti_env, next, oqctl->qc_type, id,
1818 case LUSTRE_Q_INVALIDATE:
1819 rc = mqo->mqo_invalidate(info->mti_env, next, oqctl->qc_type);
1821 case LUSTRE_Q_FINVALIDATE:
1822 rc = mqo->mqo_finvalidate(info->mti_env, next, oqctl->qc_type);
1825 CERROR("unsupported mdt_quotactl command: %d\n",
1837 * OBD PING and other handlers.
1839 static int mdt_obd_ping(struct mdt_thread_info *info)
1844 req_capsule_set(info->mti_pill, &RQF_OBD_PING);
1846 rc = target_handle_ping(mdt_info_req(info));
1848 rc = err_serious(rc);
1852 static int mdt_obd_log_cancel(struct mdt_thread_info *info)
1854 return err_serious(-EOPNOTSUPP);
1857 static int mdt_obd_qc_callback(struct mdt_thread_info *info)
1859 return err_serious(-EOPNOTSUPP);
1867 /** clone llog ctxt from child (mdd)
1868 * This allows remote llog (replicator) access.
1869 * We can either pass all llog RPCs (eg mdt_llog_create) on to child where the
1870 * context was originally set up, or we can handle them directly.
1871 * I choose the latter, but that means I need any llog
1872 * contexts set up by child to be accessable by the mdt. So we clone the
1873 * context into our context list here.
1875 static int mdt_llog_ctxt_clone(const struct lu_env *env, struct mdt_device *mdt,
1878 struct md_device *next = mdt->mdt_child;
1879 struct llog_ctxt *ctxt;
1882 if (!llog_ctxt_null(mdt2obd_dev(mdt), idx))
1885 rc = next->md_ops->mdo_llog_ctxt_get(env, next, idx, (void **)&ctxt);
1886 if (rc || ctxt == NULL) {
1887 CERROR("Can't get mdd ctxt %d\n", rc);
1891 rc = llog_group_set_ctxt(&mdt2obd_dev(mdt)->obd_olg, ctxt, idx);
1893 CERROR("Can't set mdt ctxt %d\n", rc);
1898 static int mdt_llog_ctxt_unclone(const struct lu_env *env,
1899 struct mdt_device *mdt, int idx)
1901 struct llog_ctxt *ctxt;
1903 ctxt = llog_get_context(mdt2obd_dev(mdt), idx);
1906 /* Put once for the get we just did, and once for the clone */
1907 llog_ctxt_put(ctxt);
1908 llog_ctxt_put(ctxt);
1912 static int mdt_llog_create(struct mdt_thread_info *info)
1916 req_capsule_set(info->mti_pill, &RQF_LLOG_ORIGIN_HANDLE_CREATE);
1917 rc = llog_origin_handle_create(mdt_info_req(info));
1918 return (rc < 0 ? err_serious(rc) : rc);
1921 static int mdt_llog_destroy(struct mdt_thread_info *info)
1925 req_capsule_set(info->mti_pill, &RQF_LLOG_ORIGIN_HANDLE_DESTROY);
1926 rc = llog_origin_handle_destroy(mdt_info_req(info));
1927 return (rc < 0 ? err_serious(rc) : rc);
1930 static int mdt_llog_read_header(struct mdt_thread_info *info)
1934 req_capsule_set(info->mti_pill, &RQF_LLOG_ORIGIN_HANDLE_READ_HEADER);
1935 rc = llog_origin_handle_read_header(mdt_info_req(info));
1936 return (rc < 0 ? err_serious(rc) : rc);
1939 static int mdt_llog_next_block(struct mdt_thread_info *info)
1943 req_capsule_set(info->mti_pill, &RQF_LLOG_ORIGIN_HANDLE_NEXT_BLOCK);
1944 rc = llog_origin_handle_next_block(mdt_info_req(info));
1945 return (rc < 0 ? err_serious(rc) : rc);
1948 static int mdt_llog_prev_block(struct mdt_thread_info *info)
1952 req_capsule_set(info->mti_pill, &RQF_LLOG_ORIGIN_HANDLE_PREV_BLOCK);
1953 rc = llog_origin_handle_prev_block(mdt_info_req(info));
1954 return (rc < 0 ? err_serious(rc) : rc);
1961 static struct ldlm_callback_suite cbs = {
1962 .lcs_completion = ldlm_server_completion_ast,
1963 .lcs_blocking = ldlm_server_blocking_ast,
1967 static int mdt_enqueue(struct mdt_thread_info *info)
1969 struct ptlrpc_request *req;
1974 * info->mti_dlm_req already contains swapped and (if necessary)
1975 * converted dlm request.
1977 LASSERT(info->mti_dlm_req != NULL);
1979 req = mdt_info_req(info);
1982 * Lock without inodebits makes no sense and will oops later in
1983 * ldlm. Let's check it now to see if we have wrong lock from client or
1984 * bits get corrupted somewhere in mdt_intent_policy().
1986 req_bits = info->mti_dlm_req->lock_desc.l_policy_data.l_inodebits.bits;
1987 /* This is disabled because we need to support liblustre flock.
1988 * LASSERT(req_bits != 0);
1991 rc = ldlm_handle_enqueue0(info->mti_mdt->mdt_namespace,
1992 req, info->mti_dlm_req, &cbs);
1993 info->mti_fail_id = OBD_FAIL_LDLM_REPLY;
1994 return rc ? err_serious(rc) : req->rq_status;
1997 static int mdt_convert(struct mdt_thread_info *info)
2000 struct ptlrpc_request *req;
2002 LASSERT(info->mti_dlm_req);
2003 req = mdt_info_req(info);
2004 rc = ldlm_handle_convert0(req, info->mti_dlm_req);
2005 return rc ? err_serious(rc) : req->rq_status;
2008 static int mdt_bl_callback(struct mdt_thread_info *info)
2010 CERROR("bl callbacks should not happen on MDS\n");
2012 return err_serious(-EOPNOTSUPP);
2015 static int mdt_cp_callback(struct mdt_thread_info *info)
2017 CERROR("cp callbacks should not happen on MDS\n");
2019 return err_serious(-EOPNOTSUPP);
2023 * sec context handlers
2025 static int mdt_sec_ctx_handle(struct mdt_thread_info *info)
2029 rc = mdt_handle_idmap(info);
2032 struct ptlrpc_request *req = mdt_info_req(info);
2035 opc = lustre_msg_get_opc(req->rq_reqmsg);
2036 if (opc == SEC_CTX_INIT || opc == SEC_CTX_INIT_CONT)
2037 sptlrpc_svc_ctx_invalidate(req);
2040 OBD_FAIL_TIMEOUT(OBD_FAIL_SEC_CTX_HDL_PAUSE, obd_fail_val);
2045 static struct mdt_object *mdt_obj(struct lu_object *o)
2047 LASSERT(lu_device_is_mdt(o->lo_dev));
2048 return container_of0(o, struct mdt_object, mot_obj.mo_lu);
2051 struct mdt_object *mdt_object_find(const struct lu_env *env,
2052 struct mdt_device *d,
2053 const struct lu_fid *f)
2055 struct lu_object *o;
2056 struct mdt_object *m;
2059 CDEBUG(D_INFO, "Find object for "DFID"\n", PFID(f));
2060 o = lu_object_find(env, &d->mdt_md_dev.md_lu_dev, f, NULL);
2061 if (unlikely(IS_ERR(o)))
2062 m = (struct mdt_object *)o;
2069 * Asyncronous commit for mdt device.
2071 * Pass asynchonous commit call down the MDS stack.
2073 * \param env environment
2074 * \param mdt the mdt device
2076 static void mdt_device_commit_async(const struct lu_env *env,
2077 struct mdt_device *mdt)
2079 struct dt_device *dt = mdt->mdt_bottom;
2082 rc = dt->dd_ops->dt_commit_async(env, dt);
2083 if (unlikely(rc != 0))
2084 CWARN("async commit start failed with rc = %d", rc);
2088 * Mark the lock as "synchonous".
2090 * Mark the lock to deffer transaction commit to the unlock time.
2092 * \param lock the lock to mark as "synchonous"
2094 * \see mdt_is_lock_sync
2095 * \see mdt_save_lock
2097 static inline void mdt_set_lock_sync(struct ldlm_lock *lock)
2099 lock->l_ast_data = (void*)1;
2103 * Check whehter the lock "synchonous" or not.
2105 * \param lock the lock to check
2106 * \retval 1 the lock is "synchonous"
2107 * \retval 0 the lock isn't "synchronous"
2109 * \see mdt_set_lock_sync
2110 * \see mdt_save_lock
2112 static inline int mdt_is_lock_sync(struct ldlm_lock *lock)
2114 return lock->l_ast_data != NULL;
2118 * Blocking AST for mdt locks.
2120 * Starts transaction commit if in case of COS lock conflict or
2121 * deffers such a commit to the mdt_save_lock.
2123 * \param lock the lock which blocks a request or cancelling lock
2124 * \param desc unused
2125 * \param data unused
2126 * \param flag indicates whether this cancelling or blocking callback
2128 * \see ldlm_blocking_ast_nocheck
2130 int mdt_blocking_ast(struct ldlm_lock *lock, struct ldlm_lock_desc *desc,
2131 void *data, int flag)
2133 struct obd_device *obd = lock->l_resource->lr_namespace->ns_obd;
2134 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
2138 if (flag == LDLM_CB_CANCELING)
2140 lock_res_and_lock(lock);
2141 if (lock->l_blocking_ast != mdt_blocking_ast) {
2142 unlock_res_and_lock(lock);
2145 if (mdt_cos_is_enabled(mdt) &&
2146 lock->l_req_mode & (LCK_PW | LCK_EX) &&
2147 lock->l_blocking_lock != NULL &&
2148 lock->l_client_cookie != lock->l_blocking_lock->l_client_cookie) {
2149 mdt_set_lock_sync(lock);
2151 rc = ldlm_blocking_ast_nocheck(lock);
2153 /* There is no lock conflict if l_blocking_lock == NULL,
2154 * it indicates a blocking ast sent from ldlm_lock_decref_internal
2155 * when the last reference to a local lock was released */
2156 if (lock->l_req_mode == LCK_COS && lock->l_blocking_lock != NULL) {
2159 rc = lu_env_init(&env, LCT_MD_THREAD);
2160 if (unlikely(rc != 0))
2161 CWARN("lu_env initialization failed with rc = %d,"
2162 "cannot start asynchronous commit\n", rc);
2164 mdt_device_commit_async(&env, mdt);
2170 int mdt_object_lock(struct mdt_thread_info *info, struct mdt_object *o,
2171 struct mdt_lock_handle *lh, __u64 ibits, int locality)
2173 struct ldlm_namespace *ns = info->mti_mdt->mdt_namespace;
2174 ldlm_policy_data_t *policy = &info->mti_policy;
2175 struct ldlm_res_id *res_id = &info->mti_res_id;
2179 LASSERT(!lustre_handle_is_used(&lh->mlh_reg_lh));
2180 LASSERT(!lustre_handle_is_used(&lh->mlh_pdo_lh));
2181 LASSERT(lh->mlh_reg_mode != LCK_MINMODE);
2182 LASSERT(lh->mlh_type != MDT_NUL_LOCK);
2184 if (mdt_object_exists(o) < 0) {
2185 if (locality == MDT_CROSS_LOCK) {
2186 /* cross-ref object fix */
2187 ibits &= ~MDS_INODELOCK_UPDATE;
2188 ibits |= MDS_INODELOCK_LOOKUP;
2190 LASSERT(!(ibits & MDS_INODELOCK_UPDATE));
2191 LASSERT(ibits & MDS_INODELOCK_LOOKUP);
2193 /* No PDO lock on remote object */
2194 LASSERT(lh->mlh_type != MDT_PDO_LOCK);
2197 if (lh->mlh_type == MDT_PDO_LOCK) {
2198 /* check for exists after object is locked */
2199 if (mdt_object_exists(o) == 0) {
2200 /* Non-existent object shouldn't have PDO lock */
2203 /* Non-dir object shouldn't have PDO lock */
2204 LASSERT(S_ISDIR(lu_object_attr(&o->mot_obj.mo_lu)));
2208 memset(policy, 0, sizeof(*policy));
2209 fid_build_reg_res_name(mdt_object_fid(o), res_id);
2212 * Take PDO lock on whole directory and build correct @res_id for lock
2213 * on part of directory.
2215 if (lh->mlh_pdo_hash != 0) {
2216 LASSERT(lh->mlh_type == MDT_PDO_LOCK);
2217 mdt_lock_pdo_mode(info, o, lh);
2218 if (lh->mlh_pdo_mode != LCK_NL) {
2220 * Do not use LDLM_FL_LOCAL_ONLY for parallel lock, it
2221 * is never going to be sent to client and we do not
2222 * want it slowed down due to possible cancels.
2224 policy->l_inodebits.bits = MDS_INODELOCK_UPDATE;
2225 rc = mdt_fid_lock(ns, &lh->mlh_pdo_lh, lh->mlh_pdo_mode,
2226 policy, res_id, LDLM_FL_ATOMIC_CB,
2227 &info->mti_exp->exp_handle.h_cookie);
2233 * Finish res_id initializing by name hash marking part of
2234 * directory which is taking modification.
2236 res_id->name[LUSTRE_RES_ID_HSH_OFF] = lh->mlh_pdo_hash;
2239 policy->l_inodebits.bits = ibits;
2242 * Use LDLM_FL_LOCAL_ONLY for this lock. We do not know yet if it is
2243 * going to be sent to client. If it is - mdt_intent_policy() path will
2244 * fix it up and turn FL_LOCAL flag off.
2246 rc = mdt_fid_lock(ns, &lh->mlh_reg_lh, lh->mlh_reg_mode, policy,
2247 res_id, LDLM_FL_LOCAL_ONLY | LDLM_FL_ATOMIC_CB,
2248 &info->mti_exp->exp_handle.h_cookie);
2254 mdt_object_unlock(info, o, lh, 1);
2261 * Save a lock within request object.
2263 * Keep the lock referenced until whether client ACK or transaction
2264 * commit happens or release the lock immediately depending on input
2265 * parameters. If COS is ON, a write lock is converted to COS lock
2268 * \param info thead info object
2269 * \param h lock handle
2270 * \param mode lock mode
2271 * \param decref force immediate lock releasing
2274 void mdt_save_lock(struct mdt_thread_info *info, struct lustre_handle *h,
2275 ldlm_mode_t mode, int decref)
2279 if (lustre_handle_is_used(h)) {
2280 if (decref || !info->mti_has_trans ||
2281 !(mode & (LCK_PW | LCK_EX))){
2282 mdt_fid_unlock(h, mode);
2284 struct mdt_device *mdt = info->mti_mdt;
2285 struct ldlm_lock *lock = ldlm_handle2lock(h);
2286 struct ptlrpc_request *req = mdt_info_req(info);
2289 LASSERTF(lock != NULL, "no lock for cookie "LPX64"\n",
2291 CDEBUG(D_HA, "request = %p reply state = %p"
2292 " transno = "LPD64"\n",
2293 req, req->rq_reply_state, req->rq_transno);
2294 if (mdt_cos_is_enabled(mdt)) {
2296 ldlm_lock_downgrade(lock, LCK_COS);
2299 ptlrpc_save_lock(req, h, mode, no_ack);
2300 if (mdt_is_lock_sync(lock)) {
2301 CDEBUG(D_HA, "found sync-lock,"
2302 " async commit started\n");
2303 mdt_device_commit_async(info->mti_env,
2306 LDLM_LOCK_PUT(lock);
2315 * Unlock mdt object.
2317 * Immeditely release the regular lock and the PDO lock or save the
2318 * lock in reqeuest and keep them referenced until client ACK or
2319 * transaction commit.
2321 * \param info thread info object
2322 * \param o mdt object
2323 * \param lh mdt lock handle referencing regular and PDO locks
2324 * \param decref force immediate lock releasing
2326 void mdt_object_unlock(struct mdt_thread_info *info, struct mdt_object *o,
2327 struct mdt_lock_handle *lh, int decref)
2331 mdt_save_lock(info, &lh->mlh_pdo_lh, lh->mlh_pdo_mode, decref);
2332 mdt_save_lock(info, &lh->mlh_reg_lh, lh->mlh_reg_mode, decref);
2337 struct mdt_object *mdt_object_find_lock(struct mdt_thread_info *info,
2338 const struct lu_fid *f,
2339 struct mdt_lock_handle *lh,
2342 struct mdt_object *o;
2344 o = mdt_object_find(info->mti_env, info->mti_mdt, f);
2348 rc = mdt_object_lock(info, o, lh, ibits,
2351 mdt_object_put(info->mti_env, o);
2358 void mdt_object_unlock_put(struct mdt_thread_info * info,
2359 struct mdt_object * o,
2360 struct mdt_lock_handle *lh,
2363 mdt_object_unlock(info, o, lh, decref);
2364 mdt_object_put(info->mti_env, o);
2367 static struct mdt_handler *mdt_handler_find(__u32 opc,
2368 struct mdt_opc_slice *supported)
2370 struct mdt_opc_slice *s;
2371 struct mdt_handler *h;
2374 for (s = supported; s->mos_hs != NULL; s++) {
2375 if (s->mos_opc_start <= opc && opc < s->mos_opc_end) {
2376 h = s->mos_hs + (opc - s->mos_opc_start);
2377 if (likely(h->mh_opc != 0))
2378 LASSERTF(h->mh_opc == opc,
2379 "opcode mismatch %d != %d\n",
2382 h = NULL; /* unsupported opc */
2389 static int mdt_lock_resname_compat(struct mdt_device *m,
2390 struct ldlm_request *req)
2392 /* XXX something... later. */
2396 static int mdt_lock_reply_compat(struct mdt_device *m, struct ldlm_reply *rep)
2398 /* XXX something... later. */
2403 * Generic code handling requests that have struct mdt_body passed in:
2405 * - extract mdt_body from request and save it in @info, if present;
2407 * - create lu_object, corresponding to the fid in mdt_body, and save it in
2410 * - if HABEO_CORPUS flag is set for this request type check whether object
2411 * actually exists on storage (lu_object_exists()).
2414 static int mdt_body_unpack(struct mdt_thread_info *info, __u32 flags)
2416 const struct mdt_body *body;
2417 struct mdt_object *obj;
2418 const struct lu_env *env;
2419 struct req_capsule *pill;
2423 env = info->mti_env;
2424 pill = info->mti_pill;
2426 body = info->mti_body = req_capsule_client_get(pill, &RMF_MDT_BODY);
2430 if (!(body->valid & OBD_MD_FLID))
2433 if (!fid_is_sane(&body->fid1)) {
2434 CERROR("Invalid fid: "DFID"\n", PFID(&body->fid1));
2439 * Do not get size or any capa fields before we check that request
2440 * contains capa actually. There are some requests which do not, for
2441 * instance MDS_IS_SUBDIR.
2443 if (req_capsule_has_field(pill, &RMF_CAPA1, RCL_CLIENT) &&
2444 req_capsule_get_size(pill, &RMF_CAPA1, RCL_CLIENT))
2445 mdt_set_capainfo(info, 0, &body->fid1,
2446 req_capsule_client_get(pill, &RMF_CAPA1));
2448 obj = mdt_object_find(env, info->mti_mdt, &body->fid1);
2450 if ((flags & HABEO_CORPUS) &&
2451 !mdt_object_exists(obj)) {
2452 mdt_object_put(env, obj);
2453 /* for capability renew ENOENT will be handled in
2455 if (body->valid & OBD_MD_FLOSSCAPA)
2460 info->mti_object = obj;
2469 static int mdt_unpack_req_pack_rep(struct mdt_thread_info *info, __u32 flags)
2471 struct req_capsule *pill = info->mti_pill;
2475 if (req_capsule_has_field(pill, &RMF_MDT_BODY, RCL_CLIENT))
2476 rc = mdt_body_unpack(info, flags);
2480 if (rc == 0 && (flags & HABEO_REFERO)) {
2481 struct mdt_device *mdt = info->mti_mdt;
2485 if (req_capsule_has_field(pill, &RMF_MDT_MD, RCL_SERVER))
2486 req_capsule_set_size(pill, &RMF_MDT_MD, RCL_SERVER,
2487 mdt->mdt_max_mdsize);
2488 if (req_capsule_has_field(pill, &RMF_LOGCOOKIES, RCL_SERVER))
2489 req_capsule_set_size(pill, &RMF_LOGCOOKIES, RCL_SERVER,
2490 mdt->mdt_max_cookiesize);
2492 rc = req_capsule_server_pack(pill);
2497 static int mdt_init_capa_ctxt(const struct lu_env *env, struct mdt_device *m)
2499 struct md_device *next = m->mdt_child;
2501 return next->md_ops->mdo_init_capa_ctxt(env, next,
2502 m->mdt_opts.mo_mds_capa,
2503 m->mdt_capa_timeout,
2509 * Invoke handler for this request opc. Also do necessary preprocessing
2510 * (according to handler ->mh_flags), and post-processing (setting of
2511 * ->last_{xid,committed}).
2513 static int mdt_req_handle(struct mdt_thread_info *info,
2514 struct mdt_handler *h, struct ptlrpc_request *req)
2516 int rc, serious = 0;
2521 LASSERT(h->mh_act != NULL);
2522 LASSERT(h->mh_opc == lustre_msg_get_opc(req->rq_reqmsg));
2523 LASSERT(current->journal_info == NULL);
2526 * Checking for various OBD_FAIL_$PREF_$OPC_NET codes. _Do_ not try
2527 * to put same checks into handlers like mdt_close(), mdt_reint(),
2528 * etc., without talking to mdt authors first. Checking same thing
2529 * there again is useless and returning 0 error without packing reply
2530 * is buggy! Handlers either pack reply or return error.
2532 * We return 0 here and do not send any reply in order to emulate
2533 * network failure. Do not send any reply in case any of NET related
2534 * fail_id has occured.
2536 if (OBD_FAIL_CHECK_ORSET(h->mh_fail_id, OBD_FAIL_ONCE))
2540 flags = h->mh_flags;
2541 LASSERT(ergo(flags & (HABEO_CORPUS|HABEO_REFERO), h->mh_fmt != NULL));
2543 if (h->mh_fmt != NULL) {
2544 req_capsule_set(info->mti_pill, h->mh_fmt);
2545 rc = mdt_unpack_req_pack_rep(info, flags);
2548 if (rc == 0 && flags & MUTABOR &&
2549 req->rq_export->exp_connect_flags & OBD_CONNECT_RDONLY)
2550 /* should it be rq_status? */
2553 if (rc == 0 && flags & HABEO_CLAVIS) {
2554 struct ldlm_request *dlm_req;
2556 LASSERT(h->mh_fmt != NULL);
2558 dlm_req = req_capsule_client_get(info->mti_pill, &RMF_DLM_REQ);
2559 if (dlm_req != NULL) {
2560 if (info->mti_mdt->mdt_opts.mo_compat_resname)
2561 rc = mdt_lock_resname_compat(info->mti_mdt,
2563 info->mti_dlm_req = dlm_req;
2569 /* capability setting changed via /proc, needs reinitialize ctxt */
2570 if (info->mti_mdt && info->mti_mdt->mdt_capa_conf) {
2571 mdt_init_capa_ctxt(info->mti_env, info->mti_mdt);
2572 info->mti_mdt->mdt_capa_conf = 0;
2575 if (likely(rc == 0)) {
2577 * Process request, there can be two types of rc:
2578 * 1) errors with msg unpack/pack, other failures outside the
2579 * operation itself. This is counted as serious errors;
2580 * 2) errors during fs operation, should be placed in rq_status
2583 rc = h->mh_act(info);
2585 !req->rq_no_reply && req->rq_reply_state == NULL) {
2586 DEBUG_REQ(D_ERROR, req, "MDT \"handler\" %s did not "
2587 "pack reply and returned 0 error\n",
2591 serious = is_serious(rc);
2592 rc = clear_serious(rc);
2596 req->rq_status = rc;
2599 * ELDLM_* codes which > 0 should be in rq_status only as well as
2600 * all non-serious errors.
2602 if (rc > 0 || !serious)
2605 LASSERT(current->journal_info == NULL);
2607 if (rc == 0 && (flags & HABEO_CLAVIS) &&
2608 info->mti_mdt->mdt_opts.mo_compat_resname) {
2609 struct ldlm_reply *dlmrep;
2611 dlmrep = req_capsule_server_get(info->mti_pill, &RMF_DLM_REP);
2613 rc = mdt_lock_reply_compat(info->mti_mdt, dlmrep);
2616 /* If we're DISCONNECTing, the mdt_export_data is already freed */
2617 if (likely(rc == 0 && req->rq_export && h->mh_opc != MDS_DISCONNECT))
2618 target_committed_to_req(req);
2620 if (unlikely((lustre_msg_get_flags(req->rq_reqmsg) & MSG_REPLAY) &&
2621 lustre_msg_get_transno(req->rq_reqmsg) == 0)) {
2622 DEBUG_REQ(D_ERROR, req, "transno is 0 during REPLAY");
2626 target_send_reply(req, rc, info->mti_fail_id);
2630 void mdt_lock_handle_init(struct mdt_lock_handle *lh)
2632 lh->mlh_type = MDT_NUL_LOCK;
2633 lh->mlh_reg_lh.cookie = 0ull;
2634 lh->mlh_reg_mode = LCK_MINMODE;
2635 lh->mlh_pdo_lh.cookie = 0ull;
2636 lh->mlh_pdo_mode = LCK_MINMODE;
2639 void mdt_lock_handle_fini(struct mdt_lock_handle *lh)
2641 LASSERT(!lustre_handle_is_used(&lh->mlh_reg_lh));
2642 LASSERT(!lustre_handle_is_used(&lh->mlh_pdo_lh));
2646 * Initialize fields of struct mdt_thread_info. Other fields are left in
2647 * uninitialized state, because it's too expensive to zero out whole
2648 * mdt_thread_info (> 1K) on each request arrival.
2650 static void mdt_thread_info_init(struct ptlrpc_request *req,
2651 struct mdt_thread_info *info)
2654 struct md_capainfo *ci;
2656 req_capsule_init(&req->rq_pill, req, RCL_SERVER);
2657 info->mti_pill = &req->rq_pill;
2660 for (i = 0; i < ARRAY_SIZE(info->mti_lh); i++)
2661 mdt_lock_handle_init(&info->mti_lh[i]);
2663 /* mdt device: it can be NULL while CONNECT */
2664 if (req->rq_export) {
2665 info->mti_mdt = mdt_dev(req->rq_export->exp_obd->obd_lu_dev);
2666 info->mti_exp = req->rq_export;
2668 info->mti_mdt = NULL;
2669 info->mti_env = req->rq_svc_thread->t_env;
2670 ci = md_capainfo(info->mti_env);
2671 memset(ci, 0, sizeof *ci);
2672 if (req->rq_export) {
2673 if (exp_connect_rmtclient(req->rq_export))
2674 ci->mc_auth = LC_ID_CONVERT;
2675 else if (req->rq_export->exp_connect_flags &
2676 OBD_CONNECT_MDS_CAPA)
2677 ci->mc_auth = LC_ID_PLAIN;
2679 ci->mc_auth = LC_ID_NONE;
2682 info->mti_fail_id = OBD_FAIL_MDS_ALL_REPLY_NET;
2683 info->mti_transno = lustre_msg_get_transno(req->rq_reqmsg);
2684 info->mti_mos[0] = NULL;
2685 info->mti_mos[1] = NULL;
2686 info->mti_mos[2] = NULL;
2687 info->mti_mos[3] = NULL;
2689 memset(&info->mti_attr, 0, sizeof(info->mti_attr));
2690 info->mti_body = NULL;
2691 info->mti_object = NULL;
2692 info->mti_dlm_req = NULL;
2693 info->mti_has_trans = 0;
2694 info->mti_no_need_trans = 0;
2695 info->mti_cross_ref = 0;
2696 info->mti_opdata = 0;
2698 /* To not check for split by default. */
2699 info->mti_spec.sp_ck_split = 0;
2700 info->mti_spec.no_create = 0;
2703 static void mdt_thread_info_fini(struct mdt_thread_info *info)
2707 req_capsule_fini(info->mti_pill);
2708 if (info->mti_object != NULL) {
2710 * freeing an object may lead to OSD level transaction, do not
2711 * let it mess with MDT. bz19385.
2713 info->mti_no_need_trans = 1;
2714 mdt_object_put(info->mti_env, info->mti_object);
2715 info->mti_object = NULL;
2717 for (i = 0; i < ARRAY_SIZE(info->mti_lh); i++)
2718 mdt_lock_handle_fini(&info->mti_lh[i]);
2719 info->mti_env = NULL;
2722 static int mdt_filter_recovery_request(struct ptlrpc_request *req,
2723 struct obd_device *obd, int *process)
2725 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
2726 case MDS_CONNECT: /* This will never get here, but for completeness. */
2727 case OST_CONNECT: /* This will never get here, but for completeness. */
2728 case MDS_DISCONNECT:
2729 case OST_DISCONNECT:
2734 case MDS_DONE_WRITING:
2735 case MDS_SYNC: /* used in unmounting */
2741 *process = target_queue_recovery_request(req, obd);
2745 DEBUG_REQ(D_ERROR, req, "not permitted during recovery");
2752 * Handle recovery. Return:
2753 * +1: continue request processing;
2754 * -ve: abort immediately with the given error code;
2755 * 0: send reply with error code in req->rq_status;
2757 static int mdt_recovery(struct mdt_thread_info *info)
2759 struct ptlrpc_request *req = mdt_info_req(info);
2761 struct obd_device *obd;
2765 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
2768 case SEC_CTX_INIT_CONT:
2774 rc = mdt_handle_idmap(info);
2783 if (unlikely(!class_connected_export(req->rq_export))) {
2784 CERROR("operation %d on unconnected MDS from %s\n",
2785 lustre_msg_get_opc(req->rq_reqmsg),
2786 libcfs_id2str(req->rq_peer));
2787 /* FIXME: For CMD cleanup, when mds_B stop, the req from
2788 * mds_A will get -ENOTCONN(especially for ping req),
2789 * which will cause that mds_A deactive timeout, then when
2790 * mds_A cleanup, the cleanup process will be suspended since
2791 * deactive timeout is not zero.
2793 req->rq_status = -ENOTCONN;
2794 target_send_reply(req, -ENOTCONN, info->mti_fail_id);
2798 /* sanity check: if the xid matches, the request must be marked as a
2799 * resent or replayed */
2800 if (req_xid_is_last(req)) {
2801 if (!(lustre_msg_get_flags(req->rq_reqmsg) &
2802 (MSG_RESENT | MSG_REPLAY))) {
2803 DEBUG_REQ(D_WARNING, req, "rq_xid "LPU64" matches last_xid, "
2804 "expected REPLAY or RESENT flag (%x)", req->rq_xid,
2805 lustre_msg_get_flags(req->rq_reqmsg));
2807 req->rq_status = -ENOTCONN;
2812 /* else: note the opposite is not always true; a RESENT req after a
2813 * failover will usually not match the last_xid, since it was likely
2814 * never committed. A REPLAYed request will almost never match the
2815 * last xid, however it could for a committed, but still retained,
2818 obd = req->rq_export->exp_obd;
2820 /* Check for aborted recovery... */
2821 cfs_spin_lock_bh(&obd->obd_processing_task_lock);
2822 recovering = obd->obd_recovering;
2823 cfs_spin_unlock_bh(&obd->obd_processing_task_lock);
2824 if (unlikely(recovering)) {
2827 DEBUG_REQ(D_INFO, req, "Got new replay");
2828 rc = mdt_filter_recovery_request(req, obd, &should_process);
2829 if (rc != 0 || !should_process)
2831 else if (should_process < 0) {
2832 req->rq_status = should_process;
2833 rc = ptlrpc_error(req);
2840 static int mdt_msg_check_version(struct lustre_msg *msg)
2844 switch (lustre_msg_get_opc(msg)) {
2846 case MDS_DISCONNECT:
2850 case SEC_CTX_INIT_CONT:
2852 rc = lustre_msg_check_version(msg, LUSTRE_OBD_VERSION);
2854 CERROR("bad opc %u version %08x, expecting %08x\n",
2855 lustre_msg_get_opc(msg),
2856 lustre_msg_get_version(msg),
2857 LUSTRE_OBD_VERSION);
2861 case MDS_GETATTR_NAME:
2868 case MDS_DONE_WRITING:
2874 case MDS_QUOTACHECK:
2880 rc = lustre_msg_check_version(msg, LUSTRE_MDS_VERSION);
2882 CERROR("bad opc %u version %08x, expecting %08x\n",
2883 lustre_msg_get_opc(msg),
2884 lustre_msg_get_version(msg),
2885 LUSTRE_MDS_VERSION);
2889 case LDLM_BL_CALLBACK:
2890 case LDLM_CP_CALLBACK:
2891 rc = lustre_msg_check_version(msg, LUSTRE_DLM_VERSION);
2893 CERROR("bad opc %u version %08x, expecting %08x\n",
2894 lustre_msg_get_opc(msg),
2895 lustre_msg_get_version(msg),
2896 LUSTRE_DLM_VERSION);
2898 case OBD_LOG_CANCEL:
2899 case LLOG_ORIGIN_HANDLE_CREATE:
2900 case LLOG_ORIGIN_HANDLE_NEXT_BLOCK:
2901 case LLOG_ORIGIN_HANDLE_READ_HEADER:
2902 case LLOG_ORIGIN_HANDLE_CLOSE:
2903 case LLOG_ORIGIN_HANDLE_DESTROY:
2904 case LLOG_ORIGIN_HANDLE_PREV_BLOCK:
2906 rc = lustre_msg_check_version(msg, LUSTRE_LOG_VERSION);
2908 CERROR("bad opc %u version %08x, expecting %08x\n",
2909 lustre_msg_get_opc(msg),
2910 lustre_msg_get_version(msg),
2911 LUSTRE_LOG_VERSION);
2914 CERROR("MDS unknown opcode %d\n", lustre_msg_get_opc(msg));
2920 static int mdt_handle0(struct ptlrpc_request *req,
2921 struct mdt_thread_info *info,
2922 struct mdt_opc_slice *supported)
2924 struct mdt_handler *h;
2925 struct lustre_msg *msg;
2930 if (OBD_FAIL_CHECK_ORSET(OBD_FAIL_MDS_ALL_REQUEST_NET, OBD_FAIL_ONCE))
2933 LASSERT(current->journal_info == NULL);
2935 msg = req->rq_reqmsg;
2936 rc = mdt_msg_check_version(msg);
2937 if (likely(rc == 0)) {
2938 rc = mdt_recovery(info);
2939 if (likely(rc == +1)) {
2940 h = mdt_handler_find(lustre_msg_get_opc(msg),
2942 if (likely(h != NULL)) {
2943 rc = mdt_req_handle(info, h, req);
2945 CERROR("The unsupported opc: 0x%x\n",
2946 lustre_msg_get_opc(msg) );
2947 req->rq_status = -ENOTSUPP;
2948 rc = ptlrpc_error(req);
2953 CERROR(LUSTRE_MDT_NAME" drops mal-formed request\n");
2958 * MDT handler function called by ptlrpc service thread when request comes.
2960 * XXX common "target" functionality should be factored into separate module
2961 * shared by mdt, ost and stand-alone services like fld.
2963 static int mdt_handle_common(struct ptlrpc_request *req,
2964 struct mdt_opc_slice *supported)
2967 struct mdt_thread_info *info;
2971 env = req->rq_svc_thread->t_env;
2972 LASSERT(env != NULL);
2973 LASSERT(env->le_ses != NULL);
2974 LASSERT(env->le_ctx.lc_thread == req->rq_svc_thread);
2975 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
2976 LASSERT(info != NULL);
2978 mdt_thread_info_init(req, info);
2980 rc = mdt_handle0(req, info, supported);
2982 mdt_thread_info_fini(info);
2987 * This is called from recovery code as handler of _all_ RPC types, FLD and SEQ
2990 int mdt_recovery_handle(struct ptlrpc_request *req)
2995 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
2997 rc = mdt_handle_common(req, mdt_fld_handlers);
3000 rc = mdt_handle_common(req, mdt_seq_handlers);
3003 rc = mdt_handle_common(req, mdt_regular_handlers);
3010 static int mdt_regular_handle(struct ptlrpc_request *req)
3012 return mdt_handle_common(req, mdt_regular_handlers);
3015 static int mdt_readpage_handle(struct ptlrpc_request *req)
3017 return mdt_handle_common(req, mdt_readpage_handlers);
3020 static int mdt_xmds_handle(struct ptlrpc_request *req)
3022 return mdt_handle_common(req, mdt_xmds_handlers);
3025 static int mdt_mdsc_handle(struct ptlrpc_request *req)
3027 return mdt_handle_common(req, mdt_seq_handlers);
3030 static int mdt_mdss_handle(struct ptlrpc_request *req)
3032 return mdt_handle_common(req, mdt_seq_handlers);
3035 static int mdt_dtss_handle(struct ptlrpc_request *req)
3037 return mdt_handle_common(req, mdt_seq_handlers);
3040 static int mdt_fld_handle(struct ptlrpc_request *req)
3042 return mdt_handle_common(req, mdt_fld_handlers);
3058 static int mdt_intent_getattr(enum mdt_it_code opcode,
3059 struct mdt_thread_info *info,
3060 struct ldlm_lock **,
3062 static int mdt_intent_reint(enum mdt_it_code opcode,
3063 struct mdt_thread_info *info,
3064 struct ldlm_lock **,
3067 static struct mdt_it_flavor {
3068 const struct req_format *it_fmt;
3070 int (*it_act)(enum mdt_it_code ,
3071 struct mdt_thread_info *,
3072 struct ldlm_lock **,
3075 } mdt_it_flavor[] = {
3077 .it_fmt = &RQF_LDLM_INTENT,
3078 /*.it_flags = HABEO_REFERO,*/
3080 .it_act = mdt_intent_reint,
3081 .it_reint = REINT_OPEN
3084 .it_fmt = &RQF_LDLM_INTENT,
3085 .it_flags = MUTABOR,
3086 .it_act = mdt_intent_reint,
3087 .it_reint = REINT_OPEN
3090 .it_fmt = &RQF_LDLM_INTENT,
3091 .it_flags = MUTABOR,
3092 .it_act = mdt_intent_reint,
3093 .it_reint = REINT_CREATE
3095 [MDT_IT_GETATTR] = {
3096 .it_fmt = &RQF_LDLM_INTENT_GETATTR,
3097 .it_flags = HABEO_REFERO,
3098 .it_act = mdt_intent_getattr
3100 [MDT_IT_READDIR] = {
3106 .it_fmt = &RQF_LDLM_INTENT_GETATTR,
3107 .it_flags = HABEO_REFERO,
3108 .it_act = mdt_intent_getattr
3111 .it_fmt = &RQF_LDLM_INTENT_UNLINK,
3112 .it_flags = MUTABOR,
3114 .it_reint = REINT_UNLINK
3118 .it_flags = MUTABOR,
3121 [MDT_IT_GETXATTR] = {
3128 int mdt_intent_lock_replace(struct mdt_thread_info *info,
3129 struct ldlm_lock **lockp,
3130 struct ldlm_lock *new_lock,
3131 struct mdt_lock_handle *lh,
3134 struct ptlrpc_request *req = mdt_info_req(info);
3135 struct ldlm_lock *lock = *lockp;
3138 * Get new lock only for cases when possible resent did not find any
3141 if (new_lock == NULL)
3142 new_lock = ldlm_handle2lock_long(&lh->mlh_reg_lh, 0);
3144 if (new_lock == NULL && (flags & LDLM_FL_INTENT_ONLY)) {
3145 lh->mlh_reg_lh.cookie = 0;
3149 LASSERTF(new_lock != NULL,
3150 "lockh "LPX64"\n", lh->mlh_reg_lh.cookie);
3153 * If we've already given this lock to a client once, then we should
3154 * have no readers or writers. Otherwise, we should have one reader
3155 * _or_ writer ref (which will be zeroed below) before returning the
3158 if (new_lock->l_export == req->rq_export) {
3159 LASSERT(new_lock->l_readers + new_lock->l_writers == 0);
3161 LASSERT(new_lock->l_export == NULL);
3162 LASSERT(new_lock->l_readers + new_lock->l_writers == 1);
3167 if (new_lock->l_export == req->rq_export) {
3169 * Already gave this to the client, which means that we
3170 * reconstructed a reply.
3172 LASSERT(lustre_msg_get_flags(req->rq_reqmsg) &
3174 lh->mlh_reg_lh.cookie = 0;
3175 RETURN(ELDLM_LOCK_REPLACED);
3179 * Fixup the lock to be given to the client.
3181 lock_res_and_lock(new_lock);
3182 /* Zero new_lock->l_readers and new_lock->l_writers without triggering
3183 * possible blocking AST. */
3184 while (new_lock->l_readers > 0) {
3185 lu_ref_del(&new_lock->l_reference, "reader", new_lock);
3186 lu_ref_del(&new_lock->l_reference, "user", new_lock);
3187 new_lock->l_readers--;
3189 while (new_lock->l_writers > 0) {
3190 lu_ref_del(&new_lock->l_reference, "writer", new_lock);
3191 lu_ref_del(&new_lock->l_reference, "user", new_lock);
3192 new_lock->l_writers--;
3195 new_lock->l_export = class_export_lock_get(req->rq_export, new_lock);
3196 new_lock->l_blocking_ast = lock->l_blocking_ast;
3197 new_lock->l_completion_ast = lock->l_completion_ast;
3198 new_lock->l_remote_handle = lock->l_remote_handle;
3199 new_lock->l_flags &= ~LDLM_FL_LOCAL;
3201 unlock_res_and_lock(new_lock);
3203 cfs_hash_add(new_lock->l_export->exp_lock_hash,
3204 &new_lock->l_remote_handle,
3205 &new_lock->l_exp_hash);
3207 LDLM_LOCK_RELEASE(new_lock);
3208 lh->mlh_reg_lh.cookie = 0;
3210 RETURN(ELDLM_LOCK_REPLACED);
3213 static void mdt_intent_fixup_resent(struct mdt_thread_info *info,
3214 struct ldlm_lock *new_lock,
3215 struct ldlm_lock **old_lock,
3216 struct mdt_lock_handle *lh)
3218 struct ptlrpc_request *req = mdt_info_req(info);
3219 struct obd_export *exp = req->rq_export;
3220 struct lustre_handle remote_hdl;
3221 struct ldlm_request *dlmreq;
3222 struct ldlm_lock *lock;
3224 if (!(lustre_msg_get_flags(req->rq_reqmsg) & MSG_RESENT))
3227 dlmreq = req_capsule_client_get(info->mti_pill, &RMF_DLM_REQ);
3228 remote_hdl = dlmreq->lock_handle[0];
3230 lock = cfs_hash_lookup(exp->exp_lock_hash, &remote_hdl);
3232 if (lock != new_lock) {
3233 lh->mlh_reg_lh.cookie = lock->l_handle.h_cookie;
3234 lh->mlh_reg_mode = lock->l_granted_mode;
3236 LDLM_DEBUG(lock, "Restoring lock cookie");
3237 DEBUG_REQ(D_DLMTRACE, req,
3238 "restoring lock cookie "LPX64,
3239 lh->mlh_reg_lh.cookie);
3241 *old_lock = LDLM_LOCK_GET(lock);
3242 cfs_hash_put(exp->exp_lock_hash, &lock->l_exp_hash);
3246 cfs_hash_put(exp->exp_lock_hash, &lock->l_exp_hash);
3250 * If the xid matches, then we know this is a resent request, and allow
3251 * it. (It's probably an OPEN, for which we don't send a lock.
3253 if (req_xid_is_last(req))
3257 * This remote handle isn't enqueued, so we never received or processed
3258 * this request. Clear MSG_RESENT, because it can be handled like any
3259 * normal request now.
3261 lustre_msg_clear_flags(req->rq_reqmsg, MSG_RESENT);
3263 DEBUG_REQ(D_DLMTRACE, req, "no existing lock with rhandle "LPX64,
3267 static int mdt_intent_getattr(enum mdt_it_code opcode,
3268 struct mdt_thread_info *info,
3269 struct ldlm_lock **lockp,
3272 struct mdt_lock_handle *lhc = &info->mti_lh[MDT_LH_RMT];
3273 struct ldlm_lock *new_lock = NULL;
3275 struct ldlm_reply *ldlm_rep;
3276 struct ptlrpc_request *req;
3277 struct mdt_body *reqbody;
3278 struct mdt_body *repbody;
3282 reqbody = req_capsule_client_get(info->mti_pill, &RMF_MDT_BODY);
3285 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
3288 info->mti_spec.sp_ck_split = !!(reqbody->valid & OBD_MD_FLCKSPLIT);
3289 info->mti_cross_ref = !!(reqbody->valid & OBD_MD_FLCROSSREF);
3290 repbody->eadatasize = 0;
3291 repbody->aclsize = 0;
3295 child_bits = MDS_INODELOCK_LOOKUP;
3297 case MDT_IT_GETATTR:
3298 child_bits = MDS_INODELOCK_LOOKUP | MDS_INODELOCK_UPDATE;
3301 CERROR("Unhandled till now");
3302 GOTO(out_shrink, rc = -EINVAL);
3305 rc = mdt_init_ucred(info, reqbody);
3307 GOTO(out_shrink, rc);
3309 req = info->mti_pill->rc_req;
3310 ldlm_rep = req_capsule_server_get(info->mti_pill, &RMF_DLM_REP);
3311 mdt_set_disposition(info, ldlm_rep, DISP_IT_EXECD);
3313 /* Get lock from request for possible resent case. */
3314 mdt_intent_fixup_resent(info, *lockp, &new_lock, lhc);
3316 ldlm_rep->lock_policy_res2 =
3317 mdt_getattr_name_lock(info, lhc, child_bits, ldlm_rep);
3319 if (mdt_get_disposition(ldlm_rep, DISP_LOOKUP_NEG))
3320 ldlm_rep->lock_policy_res2 = 0;
3321 if (!mdt_get_disposition(ldlm_rep, DISP_LOOKUP_POS) ||
3322 ldlm_rep->lock_policy_res2) {
3323 lhc->mlh_reg_lh.cookie = 0ull;
3324 GOTO(out_ucred, rc = ELDLM_LOCK_ABORTED);
3327 rc = mdt_intent_lock_replace(info, lockp, new_lock, lhc, flags);
3330 mdt_exit_ucred(info);
3332 mdt_shrink_reply(info);
3336 static int mdt_intent_reint(enum mdt_it_code opcode,
3337 struct mdt_thread_info *info,
3338 struct ldlm_lock **lockp,
3341 struct mdt_lock_handle *lhc = &info->mti_lh[MDT_LH_RMT];
3342 struct ldlm_reply *rep = NULL;
3346 static const struct req_format *intent_fmts[REINT_MAX] = {
3347 [REINT_CREATE] = &RQF_LDLM_INTENT_CREATE,
3348 [REINT_OPEN] = &RQF_LDLM_INTENT_OPEN
3353 opc = mdt_reint_opcode(info, intent_fmts);
3357 if (mdt_it_flavor[opcode].it_reint != opc) {
3358 CERROR("Reint code %ld doesn't match intent: %d\n",
3360 RETURN(err_serious(-EPROTO));
3363 /* Get lock from request for possible resent case. */
3364 mdt_intent_fixup_resent(info, *lockp, NULL, lhc);
3366 rc = mdt_reint_internal(info, lhc, opc);
3368 /* Check whether the reply has been packed successfully. */
3369 if (mdt_info_req(info)->rq_repmsg != NULL)
3370 rep = req_capsule_server_get(info->mti_pill, &RMF_DLM_REP);
3372 RETURN(err_serious(-EFAULT));
3374 /* MDC expects this in any case */
3376 mdt_set_disposition(info, rep, DISP_LOOKUP_EXECD);
3378 /* Cross-ref case, the lock should be returned to the client */
3379 if (rc == -EREMOTE) {
3380 LASSERT(lustre_handle_is_used(&lhc->mlh_reg_lh));
3381 rep->lock_policy_res2 = 0;
3382 rc = mdt_intent_lock_replace(info, lockp, NULL, lhc, flags);
3385 rep->lock_policy_res2 = clear_serious(rc);
3387 if (rc == -ENOTCONN || rc == -ENODEV ||
3388 rc == -EOVERFLOW) { /**< if VBR failure then return error */
3390 * If it is the disconnect error (ENODEV & ENOCONN), the error
3391 * will be returned by rq_status, and client at ptlrpc layer
3392 * will detect this, then disconnect, reconnect the import
3393 * immediately, instead of impacting the following the rpc.
3395 lhc->mlh_reg_lh.cookie = 0ull;
3399 * For other cases, the error will be returned by intent.
3400 * and client will retrieve the result from intent.
3403 * FIXME: when open lock is finished, that should be
3406 if (lustre_handle_is_used(&lhc->mlh_reg_lh)) {
3407 rep->lock_policy_res2 = 0;
3408 rc = mdt_intent_lock_replace(info, lockp, NULL, lhc, flags);
3411 lhc->mlh_reg_lh.cookie = 0ull;
3412 RETURN(ELDLM_LOCK_ABORTED);
3417 static int mdt_intent_code(long itcode)
3425 case IT_OPEN|IT_CREAT:
3432 rc = MDT_IT_READDIR;
3435 rc = MDT_IT_GETATTR;
3447 rc = MDT_IT_GETXATTR;
3450 CERROR("Unknown intent opcode: %ld\n", itcode);
3457 static int mdt_intent_opc(long itopc, struct mdt_thread_info *info,
3458 struct ldlm_lock **lockp, int flags)
3460 struct req_capsule *pill;
3461 struct mdt_it_flavor *flv;
3466 opc = mdt_intent_code(itopc);
3470 pill = info->mti_pill;
3471 flv = &mdt_it_flavor[opc];
3473 if (flv->it_fmt != NULL)
3474 req_capsule_extend(pill, flv->it_fmt);
3476 rc = mdt_unpack_req_pack_rep(info, flv->it_flags);
3478 struct ptlrpc_request *req = mdt_info_req(info);
3479 if (flv->it_flags & MUTABOR &&
3480 req->rq_export->exp_connect_flags & OBD_CONNECT_RDONLY)
3483 if (rc == 0 && flv->it_act != NULL) {
3484 /* execute policy */
3485 rc = flv->it_act(opc, info, lockp, flags);
3492 static int mdt_intent_policy(struct ldlm_namespace *ns,
3493 struct ldlm_lock **lockp, void *req_cookie,
3494 ldlm_mode_t mode, int flags, void *data)
3496 struct mdt_thread_info *info;
3497 struct ptlrpc_request *req = req_cookie;
3498 struct ldlm_intent *it;
3499 struct req_capsule *pill;
3504 LASSERT(req != NULL);
3506 info = lu_context_key_get(&req->rq_svc_thread->t_env->le_ctx,
3508 LASSERT(info != NULL);
3509 pill = info->mti_pill;
3510 LASSERT(pill->rc_req == req);
3512 if (req->rq_reqmsg->lm_bufcount > DLM_INTENT_IT_OFF) {
3513 req_capsule_extend(pill, &RQF_LDLM_INTENT);
3514 it = req_capsule_client_get(pill, &RMF_LDLM_INTENT);
3516 const struct ldlm_request *dlmreq;
3519 rc = mdt_intent_opc(it->opc, info, lockp, flags);
3524 * Lock without inodebits makes no sense and will oops
3525 * later in ldlm. Let's check it now to see if we have
3526 * wrong lock from client or bits get corrupted
3527 * somewhere in mdt_intent_opc().
3529 dlmreq = info->mti_dlm_req;
3530 req_bits = dlmreq->lock_desc.l_policy_data.l_inodebits.bits;
3531 LASSERT(req_bits != 0);
3534 rc = err_serious(-EFAULT);
3536 /* No intent was provided */
3537 LASSERT(pill->rc_fmt == &RQF_LDLM_ENQUEUE);
3538 rc = req_capsule_server_pack(pill);
3540 rc = err_serious(rc);
3548 static void mdt_seq_adjust(const struct lu_env *env,
3549 struct mdt_device *m, int lost)
3551 struct md_site *ms = mdt_md_site(m);
3552 struct lu_seq_range out;
3555 LASSERT(ms && ms->ms_server_seq);
3557 /* get extra seq from seq_server, moving it's range up */
3558 while (lost-- > 0) {
3559 seq_server_alloc_meta(ms->ms_server_seq, NULL, &out, env);
3564 static int mdt_seq_fini(const struct lu_env *env,
3565 struct mdt_device *m)
3567 struct md_site *ms = mdt_md_site(m);
3571 if (ms->ms_server_seq) {
3572 seq_server_fini(ms->ms_server_seq, env);
3573 OBD_FREE_PTR(ms->ms_server_seq);
3574 ms->ms_server_seq = NULL;
3577 if (ms->ms_control_seq) {
3578 seq_server_fini(ms->ms_control_seq, env);
3579 OBD_FREE_PTR(ms->ms_control_seq);
3580 ms->ms_control_seq = NULL;
3583 if (ms->ms_client_seq) {
3584 seq_client_fini(ms->ms_client_seq);
3585 OBD_FREE_PTR(ms->ms_client_seq);
3586 ms->ms_client_seq = NULL;
3593 static int mdt_seq_init(const struct lu_env *env,
3595 struct mdt_device *m)
3602 ms = mdt_md_site(m);
3605 * This is sequence-controller node. Init seq-controller server on local
3608 if (ms->ms_node_id == 0) {
3609 LASSERT(ms->ms_control_seq == NULL);
3611 OBD_ALLOC_PTR(ms->ms_control_seq);
3612 if (ms->ms_control_seq == NULL)
3615 rc = seq_server_init(ms->ms_control_seq,
3616 m->mdt_bottom, uuid,
3617 LUSTRE_SEQ_CONTROLLER,
3622 GOTO(out_seq_fini, rc);
3624 OBD_ALLOC_PTR(ms->ms_client_seq);
3625 if (ms->ms_client_seq == NULL)
3626 GOTO(out_seq_fini, rc = -ENOMEM);
3628 OBD_ALLOC(prefix, MAX_OBD_NAME + 5);
3629 if (prefix == NULL) {
3630 OBD_FREE_PTR(ms->ms_client_seq);
3631 GOTO(out_seq_fini, rc = -ENOMEM);
3634 snprintf(prefix, MAX_OBD_NAME + 5, "ctl-%s",
3638 * Init seq-controller client after seq-controller server is
3639 * ready. Pass ms->ms_control_seq to it for direct talking.
3641 rc = seq_client_init(ms->ms_client_seq, NULL,
3642 LUSTRE_SEQ_METADATA, prefix,
3643 ms->ms_control_seq);
3644 OBD_FREE(prefix, MAX_OBD_NAME + 5);
3647 GOTO(out_seq_fini, rc);
3650 /* Init seq-server on local MDT */
3651 LASSERT(ms->ms_server_seq == NULL);
3653 OBD_ALLOC_PTR(ms->ms_server_seq);
3654 if (ms->ms_server_seq == NULL)
3655 GOTO(out_seq_fini, rc = -ENOMEM);
3657 rc = seq_server_init(ms->ms_server_seq,
3658 m->mdt_bottom, uuid,
3663 GOTO(out_seq_fini, rc = -ENOMEM);
3665 /* Assign seq-controller client to local seq-server. */
3666 if (ms->ms_node_id == 0) {
3667 LASSERT(ms->ms_client_seq != NULL);
3669 rc = seq_server_set_cli(ms->ms_server_seq,
3677 mdt_seq_fini(env, m);
3682 * Init client sequence manager which is used by local MDS to talk to sequence
3683 * controller on remote node.
3685 static int mdt_seq_init_cli(const struct lu_env *env,
3686 struct mdt_device *m,
3687 struct lustre_cfg *cfg)
3689 struct md_site *ms = mdt_md_site(m);
3690 struct obd_device *mdc;
3691 struct obd_uuid *uuidp, *mdcuuidp;
3692 char *uuid_str, *mdc_uuid_str;
3695 struct mdt_thread_info *info;
3696 char *p, *index_string = lustre_cfg_string(cfg, 2);
3699 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
3700 uuidp = &info->mti_u.uuid[0];
3701 mdcuuidp = &info->mti_u.uuid[1];
3703 LASSERT(index_string);
3705 index = simple_strtol(index_string, &p, 10);
3707 CERROR("Invalid index in lustre_cgf, offset 2\n");
3711 /* check if this is adding the first MDC and controller is not yet
3713 if (index != 0 || ms->ms_client_seq)
3716 uuid_str = lustre_cfg_string(cfg, 1);
3717 mdc_uuid_str = lustre_cfg_string(cfg, 4);
3718 obd_str2uuid(uuidp, uuid_str);
3719 obd_str2uuid(mdcuuidp, mdc_uuid_str);
3721 mdc = class_find_client_obd(uuidp, LUSTRE_MDC_NAME, mdcuuidp);
3723 CERROR("can't find controller MDC by uuid %s\n",
3726 } else if (!mdc->obd_set_up) {
3727 CERROR("target %s not set up\n", mdc->obd_name);
3730 LASSERT(ms->ms_control_exp);
3731 OBD_ALLOC_PTR(ms->ms_client_seq);
3732 if (ms->ms_client_seq != NULL) {
3735 OBD_ALLOC(prefix, MAX_OBD_NAME + 5);
3739 snprintf(prefix, MAX_OBD_NAME + 5, "ctl-%s",
3742 rc = seq_client_init(ms->ms_client_seq,
3744 LUSTRE_SEQ_METADATA,
3746 OBD_FREE(prefix, MAX_OBD_NAME + 5);
3753 LASSERT(ms->ms_server_seq != NULL);
3754 rc = seq_server_set_cli(ms->ms_server_seq, ms->ms_client_seq,
3761 static void mdt_seq_fini_cli(struct mdt_device *m)
3767 ms = mdt_md_site(m);
3770 if (ms->ms_server_seq)
3771 seq_server_set_cli(ms->ms_server_seq,
3774 if (ms->ms_control_exp) {
3775 class_export_put(ms->ms_control_exp);
3776 ms->ms_control_exp = NULL;
3785 static int mdt_fld_fini(const struct lu_env *env,
3786 struct mdt_device *m)
3788 struct md_site *ms = mdt_md_site(m);
3791 if (ms && ms->ms_server_fld) {
3792 fld_server_fini(ms->ms_server_fld, env);
3793 OBD_FREE_PTR(ms->ms_server_fld);
3794 ms->ms_server_fld = NULL;
3800 static int mdt_fld_init(const struct lu_env *env,
3802 struct mdt_device *m)
3808 ms = mdt_md_site(m);
3810 OBD_ALLOC_PTR(ms->ms_server_fld);
3811 if (ms->ms_server_fld == NULL)
3812 RETURN(rc = -ENOMEM);
3814 rc = fld_server_init(ms->ms_server_fld,
3815 m->mdt_bottom, uuid,
3816 env, ms->ms_node_id);
3818 OBD_FREE_PTR(ms->ms_server_fld);
3819 ms->ms_server_fld = NULL;
3826 /* device init/fini methods */
3827 static void mdt_stop_ptlrpc_service(struct mdt_device *m)
3830 if (m->mdt_regular_service != NULL) {
3831 ptlrpc_unregister_service(m->mdt_regular_service);
3832 m->mdt_regular_service = NULL;
3834 if (m->mdt_readpage_service != NULL) {
3835 ptlrpc_unregister_service(m->mdt_readpage_service);
3836 m->mdt_readpage_service = NULL;
3838 if (m->mdt_xmds_service != NULL) {
3839 ptlrpc_unregister_service(m->mdt_xmds_service);
3840 m->mdt_xmds_service = NULL;
3842 if (m->mdt_setattr_service != NULL) {
3843 ptlrpc_unregister_service(m->mdt_setattr_service);
3844 m->mdt_setattr_service = NULL;
3846 if (m->mdt_mdsc_service != NULL) {
3847 ptlrpc_unregister_service(m->mdt_mdsc_service);
3848 m->mdt_mdsc_service = NULL;
3850 if (m->mdt_mdss_service != NULL) {
3851 ptlrpc_unregister_service(m->mdt_mdss_service);
3852 m->mdt_mdss_service = NULL;
3854 if (m->mdt_dtss_service != NULL) {
3855 ptlrpc_unregister_service(m->mdt_dtss_service);
3856 m->mdt_dtss_service = NULL;
3858 if (m->mdt_fld_service != NULL) {
3859 ptlrpc_unregister_service(m->mdt_fld_service);
3860 m->mdt_fld_service = NULL;
3865 static int mdt_start_ptlrpc_service(struct mdt_device *m)
3868 static struct ptlrpc_service_conf conf;
3869 cfs_proc_dir_entry_t *procfs_entry;
3872 procfs_entry = m->mdt_md_dev.md_lu_dev.ld_obd->obd_proc_entry;
3874 conf = (typeof(conf)) {
3875 .psc_nbufs = MDS_NBUFS,
3876 .psc_bufsize = MDS_BUFSIZE,
3877 .psc_max_req_size = MDS_MAXREQSIZE,
3878 .psc_max_reply_size = MDS_MAXREPSIZE,
3879 .psc_req_portal = MDS_REQUEST_PORTAL,
3880 .psc_rep_portal = MDC_REPLY_PORTAL,
3881 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
3883 * We'd like to have a mechanism to set this on a per-device
3884 * basis, but alas...
3886 .psc_min_threads = min(max(mdt_num_threads, MDT_MIN_THREADS),
3888 .psc_max_threads = MDT_MAX_THREADS,
3889 .psc_ctx_tags = LCT_MD_THREAD
3892 m->mdt_ldlm_client = &m->mdt_md_dev.md_lu_dev.ld_obd->obd_ldlm_client;
3893 ptlrpc_init_client(LDLM_CB_REQUEST_PORTAL, LDLM_CB_REPLY_PORTAL,
3894 "mdt_ldlm_client", m->mdt_ldlm_client);
3896 m->mdt_regular_service =
3897 ptlrpc_init_svc_conf(&conf, mdt_regular_handle, LUSTRE_MDT_NAME,
3898 procfs_entry, target_print_req,
3900 if (m->mdt_regular_service == NULL)
3903 rc = ptlrpc_start_threads(NULL, m->mdt_regular_service);
3905 GOTO(err_mdt_svc, rc);
3908 * readpage service configuration. Parameters have to be adjusted,
3911 conf = (typeof(conf)) {
3912 .psc_nbufs = MDS_NBUFS,
3913 .psc_bufsize = MDS_BUFSIZE,
3914 .psc_max_req_size = MDS_MAXREQSIZE,
3915 .psc_max_reply_size = MDS_MAXREPSIZE,
3916 .psc_req_portal = MDS_READPAGE_PORTAL,
3917 .psc_rep_portal = MDC_REPLY_PORTAL,
3918 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
3919 .psc_min_threads = min(max(mdt_num_threads, MDT_MIN_THREADS),
3921 .psc_max_threads = MDT_MAX_THREADS,
3922 .psc_ctx_tags = LCT_MD_THREAD
3924 m->mdt_readpage_service =
3925 ptlrpc_init_svc_conf(&conf, mdt_readpage_handle,
3926 LUSTRE_MDT_NAME "_readpage",
3927 procfs_entry, target_print_req,"mdt_rdpg");
3929 if (m->mdt_readpage_service == NULL) {
3930 CERROR("failed to start readpage service\n");
3931 GOTO(err_mdt_svc, rc = -ENOMEM);
3934 rc = ptlrpc_start_threads(NULL, m->mdt_readpage_service);
3937 * setattr service configuration.
3939 conf = (typeof(conf)) {
3940 .psc_nbufs = MDS_NBUFS,
3941 .psc_bufsize = MDS_BUFSIZE,
3942 .psc_max_req_size = MDS_MAXREQSIZE,
3943 .psc_max_reply_size = MDS_MAXREPSIZE,
3944 .psc_req_portal = MDS_SETATTR_PORTAL,
3945 .psc_rep_portal = MDC_REPLY_PORTAL,
3946 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
3947 .psc_min_threads = min(max(mdt_num_threads, MDT_MIN_THREADS),
3949 .psc_max_threads = MDT_MAX_THREADS,
3950 .psc_ctx_tags = LCT_MD_THREAD
3953 m->mdt_setattr_service =
3954 ptlrpc_init_svc_conf(&conf, mdt_regular_handle,
3955 LUSTRE_MDT_NAME "_setattr",
3956 procfs_entry, target_print_req,"mdt_attr");
3958 if (!m->mdt_setattr_service) {
3959 CERROR("failed to start setattr service\n");
3960 GOTO(err_mdt_svc, rc = -ENOMEM);
3963 rc = ptlrpc_start_threads(NULL, m->mdt_setattr_service);
3965 GOTO(err_mdt_svc, rc);
3968 * sequence controller service configuration
3970 conf = (typeof(conf)) {
3971 .psc_nbufs = MDS_NBUFS,
3972 .psc_bufsize = MDS_BUFSIZE,
3973 .psc_max_req_size = SEQ_MAXREQSIZE,
3974 .psc_max_reply_size = SEQ_MAXREPSIZE,
3975 .psc_req_portal = SEQ_CONTROLLER_PORTAL,
3976 .psc_rep_portal = MDC_REPLY_PORTAL,
3977 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
3978 .psc_min_threads = SEQ_NUM_THREADS,
3979 .psc_max_threads = SEQ_NUM_THREADS,
3980 .psc_ctx_tags = LCT_MD_THREAD|LCT_DT_THREAD
3983 m->mdt_mdsc_service =
3984 ptlrpc_init_svc_conf(&conf, mdt_mdsc_handle,
3985 LUSTRE_MDT_NAME"_mdsc",
3986 procfs_entry, target_print_req,"mdt_mdsc");
3987 if (!m->mdt_mdsc_service) {
3988 CERROR("failed to start seq controller service\n");
3989 GOTO(err_mdt_svc, rc = -ENOMEM);
3992 rc = ptlrpc_start_threads(NULL, m->mdt_mdsc_service);
3994 GOTO(err_mdt_svc, rc);
3997 * metadata sequence server service configuration
3999 conf = (typeof(conf)) {
4000 .psc_nbufs = MDS_NBUFS,
4001 .psc_bufsize = MDS_BUFSIZE,
4002 .psc_max_req_size = SEQ_MAXREQSIZE,
4003 .psc_max_reply_size = SEQ_MAXREPSIZE,
4004 .psc_req_portal = SEQ_METADATA_PORTAL,
4005 .psc_rep_portal = MDC_REPLY_PORTAL,
4006 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
4007 .psc_min_threads = SEQ_NUM_THREADS,
4008 .psc_max_threads = SEQ_NUM_THREADS,
4009 .psc_ctx_tags = LCT_MD_THREAD|LCT_DT_THREAD
4012 m->mdt_mdss_service =
4013 ptlrpc_init_svc_conf(&conf, mdt_mdss_handle,
4014 LUSTRE_MDT_NAME"_mdss",
4015 procfs_entry, target_print_req,"mdt_mdss");
4016 if (!m->mdt_mdss_service) {
4017 CERROR("failed to start metadata seq server service\n");
4018 GOTO(err_mdt_svc, rc = -ENOMEM);
4021 rc = ptlrpc_start_threads(NULL, m->mdt_mdss_service);
4023 GOTO(err_mdt_svc, rc);
4027 * Data sequence server service configuration. We want to have really
4028 * cluster-wide sequences space. This is why we start only one sequence
4029 * controller which manages space.
4031 conf = (typeof(conf)) {
4032 .psc_nbufs = MDS_NBUFS,
4033 .psc_bufsize = MDS_BUFSIZE,
4034 .psc_max_req_size = SEQ_MAXREQSIZE,
4035 .psc_max_reply_size = SEQ_MAXREPSIZE,
4036 .psc_req_portal = SEQ_DATA_PORTAL,
4037 .psc_rep_portal = OSC_REPLY_PORTAL,
4038 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
4039 .psc_min_threads = SEQ_NUM_THREADS,
4040 .psc_max_threads = SEQ_NUM_THREADS,
4041 .psc_ctx_tags = LCT_MD_THREAD|LCT_DT_THREAD
4044 m->mdt_dtss_service =
4045 ptlrpc_init_svc_conf(&conf, mdt_dtss_handle,
4046 LUSTRE_MDT_NAME"_dtss",
4047 procfs_entry, target_print_req,"mdt_dtss");
4048 if (!m->mdt_dtss_service) {
4049 CERROR("failed to start data seq server service\n");
4050 GOTO(err_mdt_svc, rc = -ENOMEM);
4053 rc = ptlrpc_start_threads(NULL, m->mdt_dtss_service);
4055 GOTO(err_mdt_svc, rc);
4057 /* FLD service start */
4058 conf = (typeof(conf)) {
4059 .psc_nbufs = MDS_NBUFS,
4060 .psc_bufsize = MDS_BUFSIZE,
4061 .psc_max_req_size = FLD_MAXREQSIZE,
4062 .psc_max_reply_size = FLD_MAXREPSIZE,
4063 .psc_req_portal = FLD_REQUEST_PORTAL,
4064 .psc_rep_portal = MDC_REPLY_PORTAL,
4065 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
4066 .psc_min_threads = FLD_NUM_THREADS,
4067 .psc_max_threads = FLD_NUM_THREADS,
4068 .psc_ctx_tags = LCT_DT_THREAD|LCT_MD_THREAD
4071 m->mdt_fld_service =
4072 ptlrpc_init_svc_conf(&conf, mdt_fld_handle,
4073 LUSTRE_MDT_NAME"_fld",
4074 procfs_entry, target_print_req, "mdt_fld");
4075 if (!m->mdt_fld_service) {
4076 CERROR("failed to start fld service\n");
4077 GOTO(err_mdt_svc, rc = -ENOMEM);
4080 rc = ptlrpc_start_threads(NULL, m->mdt_fld_service);
4082 GOTO(err_mdt_svc, rc);
4085 * mds-mds service configuration. Separate portal is used to allow
4086 * mds-mds requests be not blocked during recovery.
4088 conf = (typeof(conf)) {
4089 .psc_nbufs = MDS_NBUFS,
4090 .psc_bufsize = MDS_BUFSIZE,
4091 .psc_max_req_size = MDS_MAXREQSIZE,
4092 .psc_max_reply_size = MDS_MAXREPSIZE,
4093 .psc_req_portal = MDS_MDS_PORTAL,
4094 .psc_rep_portal = MDC_REPLY_PORTAL,
4095 .psc_watchdog_factor = MDT_SERVICE_WATCHDOG_FACTOR,
4096 .psc_min_threads = min(max(mdt_num_threads, MDT_MIN_THREADS),
4098 .psc_max_threads = MDT_MAX_THREADS,
4099 .psc_ctx_tags = LCT_MD_THREAD
4101 m->mdt_xmds_service =
4102 ptlrpc_init_svc_conf(&conf, mdt_xmds_handle,
4103 LUSTRE_MDT_NAME "_mds",
4104 procfs_entry, target_print_req,"mdt_xmds");
4106 if (m->mdt_xmds_service == NULL) {
4107 CERROR("failed to start xmds service\n");
4108 GOTO(err_mdt_svc, rc = -ENOMEM);
4111 rc = ptlrpc_start_threads(NULL, m->mdt_xmds_service);
4113 GOTO(err_mdt_svc, rc);
4118 mdt_stop_ptlrpc_service(m);
4123 static void mdt_stack_fini(const struct lu_env *env,
4124 struct mdt_device *m, struct lu_device *top)
4126 struct obd_device *obd = mdt2obd_dev(m);
4127 struct lustre_cfg_bufs *bufs;
4128 struct lustre_cfg *lcfg;
4129 struct mdt_thread_info *info;
4133 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
4134 LASSERT(info != NULL);
4136 bufs = &info->mti_u.bufs;
4137 /* process cleanup, pass mdt obd name to get obd umount flags */
4138 lustre_cfg_bufs_reset(bufs, obd->obd_name);
4143 lustre_cfg_bufs_set_string(bufs, 1, flags);
4144 lcfg = lustre_cfg_new(LCFG_CLEANUP, bufs);
4146 CERROR("Cannot alloc lcfg!\n");
4151 top->ld_ops->ldo_process_config(env, top, lcfg);
4152 lustre_cfg_free(lcfg);
4154 lu_stack_fini(env, top);
4155 m->mdt_child = NULL;
4156 m->mdt_bottom = NULL;
4159 static struct lu_device *mdt_layer_setup(struct lu_env *env,
4160 const char *typename,
4161 struct lu_device *child,
4162 struct lustre_cfg *cfg)
4164 const char *dev = lustre_cfg_string(cfg, 0);
4165 struct obd_type *type;
4166 struct lu_device_type *ldt;
4167 struct lu_device *d;
4172 type = class_get_type(typename);
4174 CERROR("Unknown type: '%s'\n", typename);
4175 GOTO(out, rc = -ENODEV);
4178 rc = lu_env_refill((struct lu_env *)env);
4180 CERROR("Failure to refill session: '%d'\n", rc);
4186 CERROR("type: '%s'\n", typename);
4187 GOTO(out_type, rc = -EINVAL);
4190 ldt->ldt_obd_type = type;
4191 d = ldt->ldt_ops->ldto_device_alloc(env, ldt, cfg);
4193 CERROR("Cannot allocate device: '%s'\n", typename);
4194 GOTO(out_type, rc = -ENODEV);
4197 LASSERT(child->ld_site);
4198 d->ld_site = child->ld_site;
4201 rc = ldt->ldt_ops->ldto_device_init(env, d, dev, child);
4203 CERROR("can't init device '%s', rc %d\n", typename, rc);
4204 GOTO(out_alloc, rc);
4207 lu_ref_add(&d->ld_reference, "lu-stack", &lu_site_init);
4212 ldt->ldt_ops->ldto_device_free(env, d);
4215 class_put_type(type);
4220 static int mdt_stack_init(struct lu_env *env,
4221 struct mdt_device *m,
4222 struct lustre_cfg *cfg,
4223 struct lustre_mount_info *lmi)
4225 struct lu_device *d = &m->mdt_md_dev.md_lu_dev;
4226 struct lu_device *tmp;
4227 struct md_device *md;
4228 struct lu_device *child_lu_dev;
4232 /* init the stack */
4233 tmp = mdt_layer_setup(env, LUSTRE_OSD_NAME, d, cfg);
4235 RETURN(PTR_ERR(tmp));
4237 m->mdt_bottom = lu2dt_dev(tmp);
4239 tmp = mdt_layer_setup(env, LUSTRE_MDD_NAME, d, cfg);
4241 GOTO(out, rc = PTR_ERR(tmp));
4246 tmp = mdt_layer_setup(env, LUSTRE_CMM_NAME, d, cfg);
4248 GOTO(out, rc = PTR_ERR(tmp));
4251 /*set mdd upcall device*/
4252 md_upcall_dev_set(md, lu2md_dev(d));
4255 /*set cmm upcall device*/
4256 md_upcall_dev_set(md, &m->mdt_md_dev);
4258 m->mdt_child = lu2md_dev(d);
4260 /* process setup config */
4261 tmp = &m->mdt_md_dev.md_lu_dev;
4262 rc = tmp->ld_ops->ldo_process_config(env, tmp, cfg);
4266 /* initialize local objects */
4267 child_lu_dev = &m->mdt_child->md_lu_dev;
4269 rc = child_lu_dev->ld_ops->ldo_prepare(env,
4270 &m->mdt_md_dev.md_lu_dev,
4273 /* fini from last known good lu_device */
4275 mdt_stack_fini(env, m, d);
4281 * setup CONFIG_ORIG context, used to access local config log.
4282 * this may need to be rewrite as part of llog rewrite for lu-api.
4284 static int mdt_obd_llog_setup(struct obd_device *obd,
4285 struct lustre_sb_info *lsi)
4289 LASSERT(obd->obd_fsops == NULL);
4291 obd->obd_fsops = fsfilt_get_ops(MT_STR(lsi->lsi_ldd));
4292 if (IS_ERR(obd->obd_fsops))
4293 return PTR_ERR(obd->obd_fsops);
4295 rc = fsfilt_setup(obd, lsi->lsi_srv_mnt->mnt_sb);
4297 fsfilt_put_ops(obd->obd_fsops);
4301 OBD_SET_CTXT_MAGIC(&obd->obd_lvfs_ctxt);
4302 obd->obd_lvfs_ctxt.pwdmnt = lsi->lsi_srv_mnt;
4303 obd->obd_lvfs_ctxt.pwd = lsi->lsi_srv_mnt->mnt_root;
4304 obd->obd_lvfs_ctxt.fs = get_ds();
4306 rc = llog_setup(obd, &obd->obd_olg, LLOG_CONFIG_ORIG_CTXT, obd,
4307 0, NULL, &llog_lvfs_ops);
4309 CERROR("llog_setup() failed: %d\n", rc);
4310 fsfilt_put_ops(obd->obd_fsops);
4316 static void mdt_obd_llog_cleanup(struct obd_device *obd)
4318 struct llog_ctxt *ctxt;
4320 ctxt = llog_get_context(obd, LLOG_CONFIG_ORIG_CTXT);
4324 if (obd->obd_fsops) {
4325 fsfilt_put_ops(obd->obd_fsops);
4326 obd->obd_fsops = NULL;
4330 static void mdt_fini(const struct lu_env *env, struct mdt_device *m)
4332 struct md_device *next = m->mdt_child;
4333 struct lu_device *d = &m->mdt_md_dev.md_lu_dev;
4334 struct lu_site *ls = d->ld_site;
4335 struct obd_device *obd = mdt2obd_dev(m);
4338 target_recovery_fini(obd);
4340 ping_evictor_stop();
4342 mdt_stop_ptlrpc_service(m);
4343 mdt_llog_ctxt_unclone(env, m, LLOG_CHANGELOG_ORIG_CTXT);
4344 mdt_obd_llog_cleanup(obd);
4345 obd_exports_barrier(obd);
4346 obd_zombie_barrier();
4347 #ifdef HAVE_QUOTA_SUPPORT
4348 next->md_ops->mdo_quota.mqo_cleanup(env, next);
4350 lut_fini(env, &m->mdt_lut);
4351 mdt_fs_cleanup(env, m);
4352 upcall_cache_cleanup(m->mdt_identity_cache);
4353 m->mdt_identity_cache = NULL;
4355 if (m->mdt_namespace != NULL) {
4356 ldlm_namespace_free(m->mdt_namespace, NULL,
4357 d->ld_obd->obd_force);
4358 d->ld_obd->obd_namespace = m->mdt_namespace = NULL;
4361 cfs_free_nidlist(&m->mdt_nosquash_nids);
4362 if (m->mdt_nosquash_str) {
4363 OBD_FREE(m->mdt_nosquash_str, m->mdt_nosquash_strlen);
4364 m->mdt_nosquash_str = NULL;
4365 m->mdt_nosquash_strlen = 0;
4368 mdt_seq_fini(env, m);
4369 mdt_seq_fini_cli(m);
4370 mdt_fld_fini(env, m);
4371 sptlrpc_rule_set_free(&m->mdt_sptlrpc_rset);
4373 next->md_ops->mdo_init_capa_ctxt(env, next, 0, 0, 0, NULL);
4374 cfs_timer_disarm(&m->mdt_ck_timer);
4375 mdt_ck_thread_stop(m);
4380 mdt_stack_fini(env, m, md2lu_dev(m->mdt_child));
4382 lprocfs_free_per_client_stats(obd);
4383 lprocfs_free_obd_stats(obd);
4387 struct md_site *mite;
4390 mite = lu_site2md(ls);
4394 LASSERT(cfs_atomic_read(&d->ld_ref) == 0);
4399 static int mdt_adapt_sptlrpc_conf(struct obd_device *obd, int initial)
4401 struct mdt_device *m = mdt_dev(obd->obd_lu_dev);
4402 struct sptlrpc_rule_set tmp_rset;
4405 sptlrpc_rule_set_init(&tmp_rset);
4406 rc = sptlrpc_conf_target_get_rules(obd, &tmp_rset, initial);
4408 CERROR("mdt %s: failed get sptlrpc rules: %d\n",
4413 sptlrpc_target_update_exp_flavor(obd, &tmp_rset);
4415 cfs_write_lock(&m->mdt_sptlrpc_lock);
4416 sptlrpc_rule_set_free(&m->mdt_sptlrpc_rset);
4417 m->mdt_sptlrpc_rset = tmp_rset;
4418 cfs_write_unlock(&m->mdt_sptlrpc_lock);
4423 static void fsoptions_to_mdt_flags(struct mdt_device *m, char *options)
4427 m->mdt_opts.mo_mds_capa = 1;
4428 m->mdt_opts.mo_oss_capa = 1;
4429 #ifdef CONFIG_FS_POSIX_ACL
4430 /* ACLs should be enabled by default (b=13829) */
4431 m->mdt_opts.mo_acl = 1;
4432 LCONSOLE_INFO("Enabling ACL\n");
4434 m->mdt_opts.mo_acl = 0;
4435 LCONSOLE_INFO("Disabling ACL\n");
4444 while (*p && *p != ',')
4448 if ((len == sizeof("user_xattr") - 1) &&
4449 (memcmp(options, "user_xattr", len) == 0)) {
4450 m->mdt_opts.mo_user_xattr = 1;
4451 LCONSOLE_INFO("Enabling user_xattr\n");
4452 } else if ((len == sizeof("nouser_xattr") - 1) &&
4453 (memcmp(options, "nouser_xattr", len) == 0)) {
4454 m->mdt_opts.mo_user_xattr = 0;
4455 LCONSOLE_INFO("Disabling user_xattr\n");
4456 } else if ((len == sizeof("noacl") - 1) &&
4457 (memcmp(options, "noacl", len) == 0)) {
4458 m->mdt_opts.mo_acl = 0;
4459 LCONSOLE_INFO("Disabling ACL\n");
4466 int mdt_postrecov(const struct lu_env *, struct mdt_device *);
4468 static int mdt_init0(const struct lu_env *env, struct mdt_device *m,
4469 struct lu_device_type *ldt, struct lustre_cfg *cfg)
4471 struct mdt_thread_info *info;
4472 struct obd_device *obd;
4473 const char *dev = lustre_cfg_string(cfg, 0);
4474 const char *num = lustre_cfg_string(cfg, 2);
4475 struct lustre_mount_info *lmi = NULL;
4476 struct lustre_sb_info *lsi;
4477 struct lustre_disk_data *ldd;
4479 struct md_site *mite;
4480 const char *identity_upcall = "NONE";
4481 #ifdef HAVE_QUOTA_SUPPORT
4482 struct md_device *next;
4488 md_device_init(&m->mdt_md_dev, ldt);
4490 * Environment (env) might be missing mdt_thread_key values at that
4491 * point, if device is allocated when mdt_thread_key is in QUIESCENT
4494 * Usually device allocation path doesn't use module key values, but
4495 * mdt has to do a lot of work here, so allocate key value.
4497 rc = lu_env_refill((struct lu_env *)env);
4501 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
4502 LASSERT(info != NULL);
4504 obd = class_name2obd(dev);
4505 LASSERT(obd != NULL);
4507 cfs_spin_lock_init(&m->mdt_transno_lock);
4509 m->mdt_max_mdsize = MAX_MD_SIZE;
4510 m->mdt_max_cookiesize = sizeof(struct llog_cookie);
4511 m->mdt_som_conf = 0;
4513 m->mdt_opts.mo_user_xattr = 0;
4514 m->mdt_opts.mo_acl = 0;
4515 m->mdt_opts.mo_cos = MDT_COS_DEFAULT;
4516 lmi = server_get_mount_2(dev);
4518 CERROR("Cannot get mount info for %s!\n", dev);
4521 lsi = s2lsi(lmi->lmi_sb);
4522 fsoptions_to_mdt_flags(m, lsi->lsi_lmd->lmd_opts);
4523 /* CMD is supported only in IAM mode */
4526 node_id = simple_strtol(num, NULL, 10);
4527 if (!(ldd->ldd_flags & LDD_F_IAM_DIR) && node_id) {
4528 CERROR("CMD Operation not allowed in IOP mode\n");
4529 GOTO(err_lmi, rc = -EINVAL);
4533 cfs_rwlock_init(&m->mdt_sptlrpc_lock);
4534 sptlrpc_rule_set_init(&m->mdt_sptlrpc_rset);
4536 cfs_spin_lock_init(&m->mdt_ioepoch_lock);
4537 m->mdt_opts.mo_compat_resname = 0;
4538 m->mdt_capa_timeout = CAPA_TIMEOUT;
4539 m->mdt_capa_alg = CAPA_HMAC_ALG_SHA1;
4540 m->mdt_ck_timeout = CAPA_KEY_TIMEOUT;
4541 m->mdt_squash_uid = 0;
4542 m->mdt_squash_gid = 0;
4543 CFS_INIT_LIST_HEAD(&m->mdt_nosquash_nids);
4544 m->mdt_nosquash_str = NULL;
4545 m->mdt_nosquash_strlen = 0;
4546 cfs_init_rwsem(&m->mdt_squash_sem);
4548 cfs_spin_lock_init(&m->mdt_client_bitmap_lock);
4550 OBD_ALLOC_PTR(mite);
4552 GOTO(err_lmi, rc = -ENOMEM);
4556 m->mdt_md_dev.md_lu_dev.ld_ops = &mdt_lu_ops;
4557 m->mdt_md_dev.md_lu_dev.ld_obd = obd;
4558 /* set this lu_device to obd, because error handling need it */
4559 obd->obd_lu_dev = &m->mdt_md_dev.md_lu_dev;
4561 rc = lu_site_init(s, &m->mdt_md_dev.md_lu_dev);
4563 CERROR("Can't init lu_site, rc %d\n", rc);
4564 GOTO(err_free_site, rc);
4567 rc = mdt_procfs_init(m, dev);
4569 CERROR("Can't init MDT lprocfs, rc %d\n", rc);
4570 GOTO(err_fini_proc, rc);
4573 /* set server index */
4574 lu_site2md(s)->ms_node_id = node_id;
4576 /* failover is the default
4577 * FIXME: we do not failout mds0/mgs, which may cause some problems.
4578 * assumed whose ms_node_id == 0 XXX
4580 obd->obd_replayable = 1;
4581 /* No connection accepted until configurations will finish */
4582 obd->obd_no_conn = 1;
4584 if (cfg->lcfg_bufcount > 4 && LUSTRE_CFG_BUFLEN(cfg, 4) > 0) {
4585 char *str = lustre_cfg_string(cfg, 4);
4586 if (strchr(str, 'n')) {
4587 CWARN("%s: recovery disabled\n", obd->obd_name);
4588 obd->obd_replayable = 0;
4592 /* init the stack */
4593 rc = mdt_stack_init((struct lu_env *)env, m, cfg, lmi);
4595 CERROR("Can't init device stack, rc %d\n", rc);
4596 GOTO(err_fini_proc, rc);
4599 rc = lut_init(env, &m->mdt_lut, obd, m->mdt_bottom);
4601 GOTO(err_fini_stack, rc);
4603 rc = mdt_fld_init(env, obd->obd_name, m);
4607 rc = mdt_seq_init(env, obd->obd_name, m);
4609 GOTO(err_fini_fld, rc);
4611 snprintf(info->mti_u.ns_name, sizeof info->mti_u.ns_name,
4612 LUSTRE_MDT_NAME"-%p", m);
4613 m->mdt_namespace = ldlm_namespace_new(obd, info->mti_u.ns_name,
4614 LDLM_NAMESPACE_SERVER,
4615 LDLM_NAMESPACE_GREEDY);
4616 if (m->mdt_namespace == NULL)
4617 GOTO(err_fini_seq, rc = -ENOMEM);
4619 ldlm_register_intent(m->mdt_namespace, mdt_intent_policy);
4620 /* set obd_namespace for compatibility with old code */
4621 obd->obd_namespace = m->mdt_namespace;
4623 /* XXX: to support suppgid for ACL, we enable identity_upcall
4624 * by default, otherwise, maybe got unexpected -EACCESS. */
4625 if (m->mdt_opts.mo_acl)
4626 identity_upcall = MDT_IDENTITY_UPCALL_PATH;
4628 m->mdt_identity_cache = upcall_cache_init(obd->obd_name, identity_upcall,
4629 &mdt_identity_upcall_cache_ops);
4630 if (IS_ERR(m->mdt_identity_cache)) {
4631 rc = PTR_ERR(m->mdt_identity_cache);
4632 m->mdt_identity_cache = NULL;
4633 GOTO(err_free_ns, rc);
4636 cfs_timer_init(&m->mdt_ck_timer, mdt_ck_timer_callback, m);
4638 rc = mdt_ck_thread_start(m);
4640 GOTO(err_free_ns, rc);
4642 rc = mdt_fs_setup(env, m, obd, lsi);
4646 rc = mdt_obd_llog_setup(obd, lsi);
4648 GOTO(err_fs_cleanup, rc);
4650 rc = mdt_llog_ctxt_clone(env, m, LLOG_CHANGELOG_ORIG_CTXT);
4652 GOTO(err_llog_cleanup, rc);
4654 mdt_adapt_sptlrpc_conf(obd, 1);
4656 #ifdef HAVE_QUOTA_SUPPORT
4657 next = m->mdt_child;
4658 rc = next->md_ops->mdo_quota.mqo_setup(env, next, lmi->lmi_mnt);
4660 GOTO(err_llog_cleanup, rc);
4663 server_put_mount_2(dev, lmi->lmi_mnt);
4666 target_recovery_init(&m->mdt_lut, mdt_recovery_handle);
4668 rc = mdt_start_ptlrpc_service(m);
4670 GOTO(err_recovery, rc);
4672 ping_evictor_start();
4674 rc = lu_site_init_finish(s);
4676 GOTO(err_stop_service, rc);
4678 if (obd->obd_recovering == 0)
4679 mdt_postrecov(env, m);
4681 mdt_init_capa_ctxt(env, m);
4683 /* Reduce the initial timeout on an MDS because it doesn't need such
4684 * a long timeout as an OST does. Adaptive timeouts will adjust this
4685 * value appropriately. */
4686 if (ldlm_timeout == LDLM_TIMEOUT_DEFAULT)
4687 ldlm_timeout = MDS_LDLM_TIMEOUT_DEFAULT;
4692 ping_evictor_stop();
4693 mdt_stop_ptlrpc_service(m);
4695 target_recovery_fini(obd);
4696 #ifdef HAVE_QUOTA_SUPPORT
4697 next->md_ops->mdo_quota.mqo_cleanup(env, next);
4700 mdt_llog_ctxt_unclone(env, m, LLOG_CHANGELOG_ORIG_CTXT);
4701 mdt_obd_llog_cleanup(obd);
4703 mdt_fs_cleanup(env, m);
4705 cfs_timer_disarm(&m->mdt_ck_timer);
4706 mdt_ck_thread_stop(m);
4708 upcall_cache_cleanup(m->mdt_identity_cache);
4709 m->mdt_identity_cache = NULL;
4710 ldlm_namespace_free(m->mdt_namespace, NULL, 0);
4711 obd->obd_namespace = m->mdt_namespace = NULL;
4713 mdt_seq_fini(env, m);
4715 mdt_fld_fini(env, m);
4717 lut_fini(env, &m->mdt_lut);
4719 mdt_stack_fini(env, m, md2lu_dev(m->mdt_child));
4727 server_put_mount_2(dev, lmi->lmi_mnt);
4731 /* used by MGS to process specific configurations */
4732 static int mdt_process_config(const struct lu_env *env,
4733 struct lu_device *d, struct lustre_cfg *cfg)
4735 struct mdt_device *m = mdt_dev(d);
4736 struct md_device *md_next = m->mdt_child;
4737 struct lu_device *next = md2lu_dev(md_next);
4741 switch (cfg->lcfg_command) {
4743 struct lprocfs_static_vars lvars;
4744 struct obd_device *obd = d->ld_obd;
4747 * For interoperability between 1.8 and 2.0,
4748 * skip old "mdt.group_upcall" param.
4751 char *param = lustre_cfg_string(cfg, 1);
4752 if (param && !strncmp("mdt.group_upcall", param, 16)) {
4753 CWARN("For 1.8 interoperability, skip this"
4754 " mdt.group_upcall. It is obsolete\n");
4759 lprocfs_mdt_init_vars(&lvars);
4760 rc = class_process_proc_param(PARAM_MDT, lvars.obd_vars,
4762 if (rc > 0 || rc == -ENOSYS)
4763 /* we don't understand; pass it on */
4764 rc = next->ld_ops->ldo_process_config(env, next, cfg);
4769 * Add mdc hook to get first MDT uuid and connect it to
4770 * ls->controller to use for seq manager.
4772 rc = next->ld_ops->ldo_process_config(env, next, cfg);
4774 CERROR("Can't add mdc, rc %d\n", rc);
4776 rc = mdt_seq_init_cli(env, mdt_dev(d), cfg);
4779 /* others are passed further */
4780 rc = next->ld_ops->ldo_process_config(env, next, cfg);
4786 static struct lu_object *mdt_object_alloc(const struct lu_env *env,
4787 const struct lu_object_header *hdr,
4788 struct lu_device *d)
4790 struct mdt_object *mo;
4796 struct lu_object *o;
4797 struct lu_object_header *h;
4799 o = &mo->mot_obj.mo_lu;
4800 h = &mo->mot_header;
4801 lu_object_header_init(h);
4802 lu_object_init(o, h, d);
4803 lu_object_add_top(h, o);
4804 o->lo_ops = &mdt_obj_ops;
4805 cfs_sema_init(&mo->mot_ioepoch_sem, 1);
4811 static int mdt_object_init(const struct lu_env *env, struct lu_object *o,
4812 const struct lu_object_conf *unused)
4814 struct mdt_device *d = mdt_dev(o->lo_dev);
4815 struct lu_device *under;
4816 struct lu_object *below;
4820 CDEBUG(D_INFO, "object init, fid = "DFID"\n",
4821 PFID(lu_object_fid(o)));
4823 under = &d->mdt_child->md_lu_dev;
4824 below = under->ld_ops->ldo_object_alloc(env, o->lo_header, under);
4825 if (below != NULL) {
4826 lu_object_add(o, below);
4833 static void mdt_object_free(const struct lu_env *env, struct lu_object *o)
4835 struct mdt_object *mo = mdt_obj(o);
4836 struct lu_object_header *h;
4840 CDEBUG(D_INFO, "object free, fid = "DFID"\n",
4841 PFID(lu_object_fid(o)));
4844 lu_object_header_fini(h);
4849 static int mdt_object_print(const struct lu_env *env, void *cookie,
4850 lu_printer_t p, const struct lu_object *o)
4852 struct mdt_object *mdto = mdt_obj((struct lu_object *)o);
4853 return (*p)(env, cookie, LUSTRE_MDT_NAME"-object@%p(ioepoch=%llu "
4854 "flags=%llx, epochcount=%d, writecount=%d)",
4855 mdto, mdto->mot_ioepoch, mdto->mot_flags,
4856 mdto->mot_ioepoch_count, mdto->mot_writecount);
4859 static const struct lu_device_operations mdt_lu_ops = {
4860 .ldo_object_alloc = mdt_object_alloc,
4861 .ldo_process_config = mdt_process_config,
4864 static const struct lu_object_operations mdt_obj_ops = {
4865 .loo_object_init = mdt_object_init,
4866 .loo_object_free = mdt_object_free,
4867 .loo_object_print = mdt_object_print
4870 static int mdt_obd_set_info_async(struct obd_export *exp,
4871 __u32 keylen, void *key,
4872 __u32 vallen, void *val,
4873 struct ptlrpc_request_set *set)
4875 struct obd_device *obd = exp->exp_obd;
4881 if (KEY_IS(KEY_SPTLRPC_CONF)) {
4882 rc = mdt_adapt_sptlrpc_conf(obd, 0);
4889 /* mds_connect_internal */
4890 static int mdt_connect_internal(struct obd_export *exp,
4891 struct mdt_device *mdt,
4892 struct obd_connect_data *data)
4895 data->ocd_connect_flags &= MDT_CONNECT_SUPPORTED;
4896 data->ocd_ibits_known &= MDS_INODELOCK_FULL;
4898 /* If no known bits (which should not happen, probably,
4899 as everybody should support LOOKUP and UPDATE bits at least)
4900 revert to compat mode with plain locks. */
4901 if (!data->ocd_ibits_known &&
4902 data->ocd_connect_flags & OBD_CONNECT_IBITS)
4903 data->ocd_connect_flags &= ~OBD_CONNECT_IBITS;
4905 if (!mdt->mdt_opts.mo_acl)
4906 data->ocd_connect_flags &= ~OBD_CONNECT_ACL;
4908 if (!mdt->mdt_opts.mo_user_xattr)
4909 data->ocd_connect_flags &= ~OBD_CONNECT_XATTR;
4911 if (!mdt->mdt_som_conf)
4912 data->ocd_connect_flags &= ~OBD_CONNECT_SOM;
4914 cfs_spin_lock(&exp->exp_lock);
4915 exp->exp_connect_flags = data->ocd_connect_flags;
4916 cfs_spin_unlock(&exp->exp_lock);
4917 data->ocd_version = LUSTRE_VERSION_CODE;
4918 exp->exp_mdt_data.med_ibits_known = data->ocd_ibits_known;
4922 if (mdt->mdt_opts.mo_acl &&
4923 ((exp->exp_connect_flags & OBD_CONNECT_ACL) == 0)) {
4924 CWARN("%s: MDS requires ACL support but client does not\n",
4925 mdt->mdt_md_dev.md_lu_dev.ld_obd->obd_name);
4930 if ((exp->exp_connect_flags & OBD_CONNECT_FID) == 0) {
4931 CWARN("%s: MDS requires FID support, but client not\n",
4932 mdt->mdt_md_dev.md_lu_dev.ld_obd->obd_name);
4936 if (mdt->mdt_som_conf && !exp_connect_som(exp) &&
4937 !(exp->exp_connect_flags & OBD_CONNECT_MDS_MDS)) {
4938 CWARN("%s: MDS has SOM enabled, but client does not support "
4939 "it\n", mdt->mdt_md_dev.md_lu_dev.ld_obd->obd_name);
4946 static int mdt_connect_check_sptlrpc(struct mdt_device *mdt,
4947 struct obd_export *exp,
4948 struct ptlrpc_request *req)
4950 struct sptlrpc_flavor flvr;
4953 if (exp->exp_flvr.sf_rpc == SPTLRPC_FLVR_INVALID) {
4954 cfs_read_lock(&mdt->mdt_sptlrpc_lock);
4955 sptlrpc_target_choose_flavor(&mdt->mdt_sptlrpc_rset,
4959 cfs_read_unlock(&mdt->mdt_sptlrpc_lock);
4961 cfs_spin_lock(&exp->exp_lock);
4963 exp->exp_sp_peer = req->rq_sp_from;
4964 exp->exp_flvr = flvr;
4966 if (exp->exp_flvr.sf_rpc != SPTLRPC_FLVR_ANY &&
4967 exp->exp_flvr.sf_rpc != req->rq_flvr.sf_rpc) {
4968 CERROR("unauthorized rpc flavor %x from %s, "
4969 "expect %x\n", req->rq_flvr.sf_rpc,
4970 libcfs_nid2str(req->rq_peer.nid),
4971 exp->exp_flvr.sf_rpc);
4975 cfs_spin_unlock(&exp->exp_lock);
4977 if (exp->exp_sp_peer != req->rq_sp_from) {
4978 CERROR("RPC source %s doesn't match %s\n",
4979 sptlrpc_part2name(req->rq_sp_from),
4980 sptlrpc_part2name(exp->exp_sp_peer));
4983 rc = sptlrpc_target_export_check(exp, req);
4990 /* mds_connect copy */
4991 static int mdt_obd_connect(const struct lu_env *env,
4992 struct obd_export **exp, struct obd_device *obd,
4993 struct obd_uuid *cluuid,
4994 struct obd_connect_data *data,
4997 struct mdt_thread_info *info;
4998 struct lsd_client_data *lcd;
4999 struct obd_export *lexp;
5000 struct lustre_handle conn = { 0 };
5001 struct mdt_device *mdt;
5002 struct ptlrpc_request *req;
5006 LASSERT(env != NULL);
5007 if (!exp || !obd || !cluuid)
5010 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
5011 req = info->mti_pill->rc_req;
5012 mdt = mdt_dev(obd->obd_lu_dev);
5014 rc = class_connect(&conn, obd, cluuid);
5018 lexp = class_conn2export(&conn);
5019 LASSERT(lexp != NULL);
5021 rc = mdt_connect_check_sptlrpc(mdt, lexp, req);
5025 rc = mdt_connect_internal(lexp, mdt, data);
5029 struct mdt_thread_info *mti;
5030 mti = lu_context_key_get(&env->le_ctx,
5032 LASSERT(mti != NULL);
5033 mti->mti_exp = lexp;
5034 memcpy(lcd->lcd_uuid, cluuid, sizeof lcd->lcd_uuid);
5035 lexp->exp_mdt_data.med_lcd = lcd;
5036 rc = mdt_client_new(env, mdt);
5039 lexp->exp_mdt_data.med_lcd = NULL;
5041 mdt_export_stats_init(obd, lexp, localdata);
5049 class_disconnect(lexp);
5056 static int mdt_obd_reconnect(const struct lu_env *env,
5057 struct obd_export *exp, struct obd_device *obd,
5058 struct obd_uuid *cluuid,
5059 struct obd_connect_data *data,
5062 struct mdt_thread_info *info;
5063 struct mdt_device *mdt;
5064 struct ptlrpc_request *req;
5068 if (exp == NULL || obd == NULL || cluuid == NULL)
5071 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
5072 req = info->mti_pill->rc_req;
5073 mdt = mdt_dev(obd->obd_lu_dev);
5075 rc = mdt_connect_check_sptlrpc(mdt, exp, req);
5079 rc = mdt_connect_internal(exp, mdt_dev(obd->obd_lu_dev), data);
5081 mdt_export_stats_init(obd, exp, localdata);
5085 static int mdt_export_cleanup(struct obd_export *exp)
5087 struct mdt_export_data *med = &exp->exp_mdt_data;
5088 struct obd_device *obd = exp->exp_obd;
5089 struct mdt_device *mdt;
5090 struct mdt_thread_info *info;
5092 CFS_LIST_HEAD(closing_list);
5093 struct mdt_file_data *mfd, *n;
5097 cfs_spin_lock(&med->med_open_lock);
5098 while (!cfs_list_empty(&med->med_open_head)) {
5099 cfs_list_t *tmp = med->med_open_head.next;
5100 mfd = cfs_list_entry(tmp, struct mdt_file_data, mfd_list);
5102 /* Remove mfd handle so it can't be found again.
5103 * We are consuming the mfd_list reference here. */
5104 class_handle_unhash(&mfd->mfd_handle);
5105 cfs_list_move_tail(&mfd->mfd_list, &closing_list);
5107 cfs_spin_unlock(&med->med_open_lock);
5108 mdt = mdt_dev(obd->obd_lu_dev);
5109 LASSERT(mdt != NULL);
5111 rc = lu_env_init(&env, LCT_MD_THREAD);
5115 info = lu_context_key_get(&env.le_ctx, &mdt_thread_key);
5116 LASSERT(info != NULL);
5117 memset(info, 0, sizeof *info);
5118 info->mti_env = &env;
5119 info->mti_mdt = mdt;
5120 info->mti_exp = exp;
5122 if (!cfs_list_empty(&closing_list)) {
5123 struct md_attr *ma = &info->mti_attr;
5127 lmm_size = mdt->mdt_max_mdsize;
5128 OBD_ALLOC(ma->ma_lmm, lmm_size);
5129 if (ma->ma_lmm == NULL)
5130 GOTO(out_lmm, rc = -ENOMEM);
5132 cookie_size = mdt->mdt_max_cookiesize;
5133 OBD_ALLOC(ma->ma_cookie, cookie_size);
5134 if (ma->ma_cookie == NULL)
5135 GOTO(out_cookie, rc = -ENOMEM);
5137 /* Close any open files (which may also cause orphan unlinking). */
5138 cfs_list_for_each_entry_safe(mfd, n, &closing_list, mfd_list) {
5139 cfs_list_del_init(&mfd->mfd_list);
5140 memset(&ma->ma_attr, 0, sizeof(ma->ma_attr));
5141 ma->ma_lmm_size = lmm_size;
5142 ma->ma_cookie_size = cookie_size;
5144 /* It is not for setattr, just tell MDD to send
5145 * DESTROY RPC to OSS if needed */
5146 ma->ma_attr_flags = MDS_CLOSE_CLEANUP;
5147 ma->ma_valid = MA_FLAGS;
5148 mdt_mfd_close(info, mfd);
5150 OBD_FREE(ma->ma_cookie, cookie_size);
5151 ma->ma_cookie = NULL;
5153 OBD_FREE(ma->ma_lmm, lmm_size);
5157 info->mti_mdt = NULL;
5158 /* cleanup client slot early */
5159 mdt_client_del(&env, mdt);
5165 static int mdt_obd_disconnect(struct obd_export *exp)
5171 class_export_get(exp);
5173 rc = server_disconnect_export(exp);
5175 CDEBUG(D_IOCTL, "server disconnect error: %d\n", rc);
5177 rc = mdt_export_cleanup(exp);
5178 class_export_put(exp);
5182 /* FIXME: Can we avoid using these two interfaces? */
5183 static int mdt_init_export(struct obd_export *exp)
5185 struct mdt_export_data *med = &exp->exp_mdt_data;
5189 CFS_INIT_LIST_HEAD(&med->med_open_head);
5190 cfs_spin_lock_init(&med->med_open_lock);
5191 cfs_sema_init(&med->med_idmap_sem, 1);
5192 med->med_idmap = NULL;
5193 cfs_spin_lock(&exp->exp_lock);
5194 exp->exp_connecting = 1;
5195 cfs_spin_unlock(&exp->exp_lock);
5196 rc = ldlm_init_export(exp);
5198 CERROR("Error %d while initializing export\n", rc);
5202 static int mdt_destroy_export(struct obd_export *exp)
5204 struct mdt_export_data *med;
5208 med = &exp->exp_mdt_data;
5209 if (exp_connect_rmtclient(exp))
5210 mdt_cleanup_idmap(&exp->exp_mdt_data);
5212 target_destroy_export(exp);
5213 ldlm_destroy_export(exp);
5215 LASSERT(cfs_list_empty(&exp->exp_outstanding_replies));
5216 LASSERT(cfs_list_empty(&exp->exp_mdt_data.med_open_head));
5217 if (obd_uuid_equals(&exp->exp_client_uuid, &exp->exp_obd->obd_uuid))
5223 static void mdt_allow_cli(struct mdt_device *m, unsigned int flag)
5225 if (flag & CONFIG_LOG)
5226 m->mdt_fl_cfglog = 1;
5228 /* also notify active event */
5229 if (flag & CONFIG_SYNC)
5230 m->mdt_fl_synced = 1;
5232 if (m->mdt_fl_cfglog && m->mdt_fl_synced)
5233 /* Open for clients */
5234 m->mdt_md_dev.md_lu_dev.ld_obd->obd_no_conn = 0;
5237 static int mdt_upcall(const struct lu_env *env, struct md_device *md,
5238 enum md_upcall_event ev, void *data)
5240 struct mdt_device *m = mdt_dev(&md->md_lu_dev);
5241 struct md_device *next = m->mdt_child;
5242 struct mdt_thread_info *mti;
5248 rc = next->md_ops->mdo_maxsize_get(env, next,
5250 &m->mdt_max_cookiesize);
5251 CDEBUG(D_INFO, "get max mdsize %d max cookiesize %d\n",
5252 m->mdt_max_mdsize, m->mdt_max_cookiesize);
5253 mdt_allow_cli(m, CONFIG_SYNC);
5255 (*(__u64 *)data) = m->mdt_mount_count;
5258 mti = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
5259 mti->mti_no_need_trans = 1;
5260 CDEBUG(D_INFO, "disable mdt trans for this thread\n");
5263 /* Check that MDT is not yet configured */
5264 LASSERT(!m->mdt_fl_cfglog);
5266 #ifdef HAVE_QUOTA_SUPPORT
5268 if (md->md_lu_dev.ld_obd->obd_recovering == 0 &&
5269 likely(md->md_lu_dev.ld_obd->obd_stopping == 0))
5270 next->md_ops->mdo_quota.mqo_recovery(env, next);
5274 CERROR("invalid event\n");
5281 static int mdt_obd_notify(struct obd_device *host,
5282 struct obd_device *watched,
5283 enum obd_notify_event ev, void *data)
5285 struct mdt_device *mdt = mdt_dev(host->obd_lu_dev);
5286 #ifdef HAVE_QUOTA_SUPPORT
5287 struct md_device *next = mdt->mdt_child;
5292 case OBD_NOTIFY_CONFIG:
5293 mdt_allow_cli(mdt, (unsigned long)data);
5295 #ifdef HAVE_QUOTA_SUPPORT
5296 /* quota_type has been processed, we can now handle
5297 * incoming quota requests */
5298 next->md_ops->mdo_quota.mqo_notify(NULL, next);
5302 CDEBUG(D_INFO, "Unhandled notification %#x\n", ev);
5307 static int mdt_rpc_fid2path(struct mdt_thread_info *info, void *key,
5308 void *val, int vallen)
5310 struct mdt_device *mdt = mdt_dev(info->mti_exp->exp_obd->obd_lu_dev);
5311 struct getinfo_fid2path *fpout, *fpin;
5314 fpin = key + cfs_size_round(sizeof(KEY_FID2PATH));
5317 if (ptlrpc_req_need_swab(info->mti_pill->rc_req))
5318 lustre_swab_fid2path(fpin);
5320 memcpy(fpout, fpin, sizeof(*fpin));
5321 if (fpout->gf_pathlen != vallen - sizeof(*fpin))
5324 rc = mdt_fid2path(info->mti_env, mdt, fpout);
5328 static int mdt_fid2path(const struct lu_env *env, struct mdt_device *mdt,
5329 struct getinfo_fid2path *fp)
5331 struct mdt_object *obj;
5335 CDEBUG(D_IOCTL, "path get "DFID" from "LPU64" #%d\n",
5336 PFID(&fp->gf_fid), fp->gf_recno, fp->gf_linkno);
5338 if (!fid_is_sane(&fp->gf_fid))
5341 obj = mdt_object_find(env, mdt, &fp->gf_fid);
5342 if (obj == NULL || IS_ERR(obj)) {
5343 CDEBUG(D_IOCTL, "no object "DFID": %ld\n",PFID(&fp->gf_fid),
5348 rc = lu_object_exists(&obj->mot_obj.mo_lu);
5354 mdt_object_put(env, obj);
5355 CDEBUG(D_IOCTL, "nonlocal object "DFID": %d\n",
5356 PFID(&fp->gf_fid), rc);
5360 rc = mo_path(env, md_object_next(&obj->mot_obj), fp->gf_path,
5361 fp->gf_pathlen, &fp->gf_recno, &fp->gf_linkno);
5362 mdt_object_put(env, obj);
5367 static int mdt_get_info(struct mdt_thread_info *info)
5369 struct ptlrpc_request *req = mdt_info_req(info);
5377 key = req_capsule_client_get(info->mti_pill, &RMF_GETINFO_KEY);
5379 CDEBUG(D_IOCTL, "No GETINFO key");
5382 keylen = req_capsule_get_size(info->mti_pill, &RMF_GETINFO_KEY,
5385 vallen = req_capsule_client_get(info->mti_pill, &RMF_GETINFO_VALLEN);
5386 if (vallen == NULL) {
5387 CDEBUG(D_IOCTL, "Unable to get RMF_GETINFO_VALLEN buffer");
5391 req_capsule_set_size(info->mti_pill, &RMF_GETINFO_VAL, RCL_SERVER,
5393 rc = req_capsule_server_pack(info->mti_pill);
5394 valout = req_capsule_server_get(info->mti_pill, &RMF_GETINFO_VAL);
5395 if (valout == NULL) {
5396 CDEBUG(D_IOCTL, "Unable to get get-info RPC out buffer");
5400 if (KEY_IS(KEY_FID2PATH))
5401 rc = mdt_rpc_fid2path(info, key, valout, *vallen);
5405 lustre_msg_set_status(req->rq_repmsg, rc);
5410 /* Pass the ioc down */
5411 static int mdt_ioc_child(struct lu_env *env, struct mdt_device *mdt,
5412 unsigned int cmd, int len, void *data)
5414 struct lu_context ioctl_session;
5415 struct md_device *next = mdt->mdt_child;
5419 rc = lu_context_init(&ioctl_session, LCT_SESSION);
5422 ioctl_session.lc_thread = (struct ptlrpc_thread *)cfs_current();
5423 lu_context_enter(&ioctl_session);
5424 env->le_ses = &ioctl_session;
5426 LASSERT(next->md_ops->mdo_iocontrol);
5427 rc = next->md_ops->mdo_iocontrol(env, next, cmd, len, data);
5429 lu_context_exit(&ioctl_session);
5430 lu_context_fini(&ioctl_session);
5434 static int mdt_ioc_version_get(struct mdt_thread_info *mti, void *karg)
5436 struct obd_ioctl_data *data = karg;
5437 struct lu_fid *fid = (struct lu_fid *)data->ioc_inlbuf1;
5439 struct mdt_object *obj;
5440 struct mdt_lock_handle *lh;
5443 CDEBUG(D_IOCTL, "getting version for "DFID"\n", PFID(fid));
5444 if (!fid_is_sane(fid))
5447 lh = &mti->mti_lh[MDT_LH_PARENT];
5448 mdt_lock_reg_init(lh, LCK_CR);
5450 obj = mdt_object_find_lock(mti, fid, lh, MDS_INODELOCK_UPDATE);
5452 RETURN(PTR_ERR(obj));
5454 rc = mdt_object_exists(obj);
5458 * before calling version get the correct MDS should be
5459 * fid, this is error to find remote object here
5461 CERROR("nonlocal object "DFID"\n", PFID(fid));
5462 } else if (rc == 0) {
5464 CDEBUG(D_IOCTL, "no such object: "DFID"\n", PFID(fid));
5466 version = mo_version_get(mti->mti_env, mdt_object_child(obj));
5470 *(__u64 *)data->ioc_inlbuf2 = version;
5474 mdt_object_unlock_put(mti, obj, lh, 1);
5478 /* ioctls on obd dev */
5479 static int mdt_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
5480 void *karg, void *uarg)
5483 struct obd_device *obd = exp->exp_obd;
5484 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
5485 struct dt_device *dt = mdt->mdt_bottom;
5489 CDEBUG(D_IOCTL, "handling ioctl cmd %#x\n", cmd);
5490 rc = lu_env_init(&env, LCT_MD_THREAD);
5496 rc = mdt_device_sync(&env, mdt);
5498 case OBD_IOC_SET_READONLY:
5499 dt->dd_ops->dt_ro(&env, dt);
5501 case OBD_IOC_ABORT_RECOVERY:
5502 CERROR("Aborting recovery for device %s\n", obd->obd_name);
5503 target_stop_recovery_thread(obd);
5506 case OBD_IOC_CHANGELOG_REG:
5507 case OBD_IOC_CHANGELOG_DEREG:
5508 case OBD_IOC_CHANGELOG_CLEAR:
5509 rc = mdt_ioc_child(&env, mdt, cmd, len, karg);
5511 case OBD_IOC_GET_OBJ_VERSION: {
5512 struct mdt_thread_info *mti;
5513 mti = lu_context_key_get(&env.le_ctx, &mdt_thread_key);
5514 memset(mti, 0, sizeof *mti);
5515 mti->mti_env = &env;
5519 rc = mdt_ioc_version_get(mti, karg);
5523 CERROR("Not supported cmd = %d for device %s\n",
5524 cmd, obd->obd_name);
5532 int mdt_postrecov(const struct lu_env *env, struct mdt_device *mdt)
5534 struct lu_device *ld = md2lu_dev(mdt->mdt_child);
5535 struct obd_device *obd = mdt2obd_dev(mdt);
5536 #ifdef HAVE_QUOTA_SUPPORT
5537 struct md_device *next = mdt->mdt_child;
5541 /* if some clients didn't participate in recovery then we can possibly
5542 * lost sequence. Now we should increase sequence for safe value */
5543 lost = obd->obd_max_recoverable_clients - obd->obd_connected_clients;
5544 mdt_seq_adjust(env, mdt, lost);
5546 rc = ld->ld_ops->ldo_recovery_complete(env, ld);
5547 #ifdef HAVE_QUOTA_SUPPORT
5548 if (likely(obd->obd_stopping == 0))
5549 next->md_ops->mdo_quota.mqo_recovery(env, next);
5554 int mdt_obd_postrecov(struct obd_device *obd)
5559 rc = lu_env_init(&env, LCT_MD_THREAD);
5562 rc = mdt_postrecov(&env, mdt_dev(obd->obd_lu_dev));
5568 * Send a copytool req to a client
5569 * Note this sends a request RPC from a server (MDT) to a client (MDC),
5570 * backwards of normal comms.
5572 int mdt_hsm_copytool_send(struct obd_export *exp)
5575 struct hsm_action_list *hal;
5576 struct hsm_action_item *hai;
5580 CWARN("%s: writing to mdc at %s\n", exp->exp_obd->obd_name,
5581 libcfs_nid2str(exp->exp_connection->c_peer.nid));
5583 len = sizeof(*lh) + sizeof(*hal) + MTI_NAME_MAXLEN +
5584 /* for mockup below */ 2 * cfs_size_round(sizeof(*hai));
5589 lh->lnl_magic = LNL_MAGIC;
5590 lh->lnl_transport = LNL_TRANSPORT_HSM;
5591 lh->lnl_msgtype = HMT_ACTION_LIST;
5592 lh->lnl_msglen = len;
5594 hal = (struct hsm_action_list *)(lh + 1);
5595 hal->hal_version = HAL_VERSION;
5596 hal->hal_archive_num = 1;
5597 obd_uuid2fsname(hal->hal_fsname, exp->exp_obd->obd_name,
5600 /* mock up an action list */
5602 hai = hai_zero(hal);
5603 hai->hai_action = HSMA_ARCHIVE;
5604 hai->hai_fid.f_oid = 0xA00A;
5605 hai->hai_len = sizeof(*hai);
5606 hai = hai_next(hai);
5607 hai->hai_action = HSMA_RESTORE;
5608 hai->hai_fid.f_oid = 0xB00B;
5609 hai->hai_len = sizeof(*hai);
5611 /* Uses the ldlm reverse import; this rpc will be seen by
5612 the ldlm_callback_handler */
5613 rc = target_set_info_rpc(exp->exp_imp_reverse, LDLM_SET_INFO,
5614 sizeof(KEY_HSM_COPYTOOL_SEND),
5615 KEY_HSM_COPYTOOL_SEND,
5623 static struct obd_ops mdt_obd_device_ops = {
5624 .o_owner = THIS_MODULE,
5625 .o_set_info_async = mdt_obd_set_info_async,
5626 .o_connect = mdt_obd_connect,
5627 .o_reconnect = mdt_obd_reconnect,
5628 .o_disconnect = mdt_obd_disconnect,
5629 .o_init_export = mdt_init_export,
5630 .o_destroy_export = mdt_destroy_export,
5631 .o_iocontrol = mdt_iocontrol,
5632 .o_postrecov = mdt_obd_postrecov,
5633 .o_notify = mdt_obd_notify
5636 static struct lu_device* mdt_device_fini(const struct lu_env *env,
5637 struct lu_device *d)
5639 struct mdt_device *m = mdt_dev(d);
5646 static struct lu_device *mdt_device_free(const struct lu_env *env,
5647 struct lu_device *d)
5649 struct mdt_device *m = mdt_dev(d);
5652 md_device_fini(&m->mdt_md_dev);
5657 static struct lu_device *mdt_device_alloc(const struct lu_env *env,
5658 struct lu_device_type *t,
5659 struct lustre_cfg *cfg)
5661 struct lu_device *l;
5662 struct mdt_device *m;
5668 l = &m->mdt_md_dev.md_lu_dev;
5669 rc = mdt_init0(env, m, t, cfg);
5671 mdt_device_free(env, l);
5675 md_upcall_init(&m->mdt_md_dev, mdt_upcall);
5677 l = ERR_PTR(-ENOMEM);
5681 /* context key constructor/destructor: mdt_key_init, mdt_key_fini */
5682 LU_KEY_INIT_FINI(mdt, struct mdt_thread_info);
5684 /* context key: mdt_thread_key */
5685 LU_CONTEXT_KEY_DEFINE(mdt, LCT_MD_THREAD);
5687 /* context key constructor/destructor: mdt_txn_key_init, mdt_txn_key_fini */
5688 LU_KEY_INIT_FINI(mdt_txn, struct mdt_txn_info);
5690 struct lu_context_key mdt_txn_key = {
5691 .lct_tags = LCT_TX_HANDLE,
5692 .lct_init = mdt_txn_key_init,
5693 .lct_fini = mdt_txn_key_fini
5696 struct md_ucred *mdt_ucred(const struct mdt_thread_info *info)
5698 return md_ucred(info->mti_env);
5702 * Enable/disable COS (Commit On Sharing).
5704 * Set/Clear the COS flag in mdt options.
5706 * \param mdt mdt device
5707 * \param val 0 disables COS, other values enable COS
5709 void mdt_enable_cos(struct mdt_device *mdt, int val)
5714 mdt->mdt_opts.mo_cos = !!val;
5715 rc = lu_env_init(&env, LCT_MD_THREAD);
5716 if (unlikely(rc != 0)) {
5717 CWARN("lu_env initialization failed with rc = %d,"
5718 "cannot sync\n", rc);
5721 mdt_device_sync(&env, mdt);
5726 * Check COS (Commit On Sharing) status.
5728 * Return COS flag status.
5730 * \param mdt mdt device
5732 int mdt_cos_is_enabled(struct mdt_device *mdt)
5734 return mdt->mdt_opts.mo_cos != 0;
5737 /* type constructor/destructor: mdt_type_init, mdt_type_fini */
5738 LU_TYPE_INIT_FINI(mdt, &mdt_thread_key, &mdt_txn_key);
5740 static struct lu_device_type_operations mdt_device_type_ops = {
5741 .ldto_init = mdt_type_init,
5742 .ldto_fini = mdt_type_fini,
5744 .ldto_start = mdt_type_start,
5745 .ldto_stop = mdt_type_stop,
5747 .ldto_device_alloc = mdt_device_alloc,
5748 .ldto_device_free = mdt_device_free,
5749 .ldto_device_fini = mdt_device_fini
5752 static struct lu_device_type mdt_device_type = {
5753 .ldt_tags = LU_DEVICE_MD,
5754 .ldt_name = LUSTRE_MDT_NAME,
5755 .ldt_ops = &mdt_device_type_ops,
5756 .ldt_ctx_tags = LCT_MD_THREAD
5759 static struct lu_local_obj_desc mdt_last_recv = {
5760 .llod_name = LAST_RCVD,
5761 .llod_oid = MDT_LAST_RECV_OID,
5765 static int __init mdt_mod_init(void)
5767 struct lprocfs_static_vars lvars;
5770 llo_local_obj_register(&mdt_last_recv);
5772 mdt_num_threads = MDT_NUM_THREADS;
5773 lprocfs_mdt_init_vars(&lvars);
5774 rc = class_register_type(&mdt_obd_device_ops, NULL,
5775 lvars.module_vars, LUSTRE_MDT_NAME,
5781 static void __exit mdt_mod_exit(void)
5783 llo_local_obj_unregister(&mdt_last_recv);
5784 class_unregister_type(LUSTRE_MDT_NAME);
5788 #define DEF_HNDL(prefix, base, suffix, flags, opc, fn, fmt) \
5789 [prefix ## _ ## opc - prefix ## _ ## base] = { \
5791 .mh_fail_id = OBD_FAIL_ ## prefix ## _ ## opc ## suffix, \
5792 .mh_opc = prefix ## _ ## opc, \
5793 .mh_flags = flags, \
5798 #define DEF_MDT_HNDL(flags, name, fn, fmt) \
5799 DEF_HNDL(MDS, GETATTR, _NET, flags, name, fn, fmt)
5801 #define DEF_SEQ_HNDL(flags, name, fn, fmt) \
5802 DEF_HNDL(SEQ, QUERY, _NET, flags, name, fn, fmt)
5804 #define DEF_FLD_HNDL(flags, name, fn, fmt) \
5805 DEF_HNDL(FLD, QUERY, _NET, flags, name, fn, fmt)
5807 * Request with a format known in advance
5809 #define DEF_MDT_HNDL_F(flags, name, fn) \
5810 DEF_HNDL(MDS, GETATTR, _NET, flags, name, fn, &RQF_MDS_ ## name)
5812 #define DEF_SEQ_HNDL_F(flags, name, fn) \
5813 DEF_HNDL(SEQ, QUERY, _NET, flags, name, fn, &RQF_SEQ_ ## name)
5815 #define DEF_FLD_HNDL_F(flags, name, fn) \
5816 DEF_HNDL(FLD, QUERY, _NET, flags, name, fn, &RQF_FLD_ ## name)
5818 * Request with a format we do not yet know
5820 #define DEF_MDT_HNDL_0(flags, name, fn) \
5821 DEF_HNDL(MDS, GETATTR, _NET, flags, name, fn, NULL)
5823 static struct mdt_handler mdt_mds_ops[] = {
5824 DEF_MDT_HNDL_F(0, CONNECT, mdt_connect),
5825 DEF_MDT_HNDL_F(0, DISCONNECT, mdt_disconnect),
5826 DEF_MDT_HNDL (0, SET_INFO, mdt_set_info,
5828 DEF_MDT_HNDL_F(0, GET_INFO, mdt_get_info),
5829 DEF_MDT_HNDL_F(0 |HABEO_REFERO, GETSTATUS, mdt_getstatus),
5830 DEF_MDT_HNDL_F(HABEO_CORPUS, GETATTR, mdt_getattr),
5831 DEF_MDT_HNDL_F(HABEO_CORPUS|HABEO_REFERO, GETATTR_NAME, mdt_getattr_name),
5832 DEF_MDT_HNDL_F(HABEO_CORPUS, GETXATTR, mdt_getxattr),
5833 DEF_MDT_HNDL_F(0 |HABEO_REFERO, STATFS, mdt_statfs),
5834 DEF_MDT_HNDL_F(0 |MUTABOR, REINT, mdt_reint),
5835 DEF_MDT_HNDL_F(HABEO_CORPUS, CLOSE, mdt_close),
5836 DEF_MDT_HNDL_F(HABEO_CORPUS, DONE_WRITING, mdt_done_writing),
5837 DEF_MDT_HNDL_F(0 |HABEO_REFERO, PIN, mdt_pin),
5838 DEF_MDT_HNDL_0(0, SYNC, mdt_sync),
5839 DEF_MDT_HNDL_F(HABEO_CORPUS|HABEO_REFERO, IS_SUBDIR, mdt_is_subdir),
5840 #ifdef HAVE_QUOTA_SUPPORT
5841 DEF_MDT_HNDL_F(0, QUOTACHECK, mdt_quotacheck_handle),
5842 DEF_MDT_HNDL_F(0, QUOTACTL, mdt_quotactl_handle)
5846 #define DEF_OBD_HNDL(flags, name, fn) \
5847 DEF_HNDL(OBD, PING, _NET, flags, name, fn, NULL)
5850 static struct mdt_handler mdt_obd_ops[] = {
5851 DEF_OBD_HNDL(0, PING, mdt_obd_ping),
5852 DEF_OBD_HNDL(0, LOG_CANCEL, mdt_obd_log_cancel),
5853 DEF_OBD_HNDL(0, QC_CALLBACK, mdt_obd_qc_callback)
5856 #define DEF_DLM_HNDL_0(flags, name, fn) \
5857 DEF_HNDL(LDLM, ENQUEUE, , flags, name, fn, NULL)
5858 #define DEF_DLM_HNDL_F(flags, name, fn) \
5859 DEF_HNDL(LDLM, ENQUEUE, , flags, name, fn, &RQF_LDLM_ ## name)
5861 static struct mdt_handler mdt_dlm_ops[] = {
5862 DEF_DLM_HNDL_F(HABEO_CLAVIS, ENQUEUE, mdt_enqueue),
5863 DEF_DLM_HNDL_0(HABEO_CLAVIS, CONVERT, mdt_convert),
5864 DEF_DLM_HNDL_0(0, BL_CALLBACK, mdt_bl_callback),
5865 DEF_DLM_HNDL_0(0, CP_CALLBACK, mdt_cp_callback)
5868 #define DEF_LLOG_HNDL(flags, name, fn) \
5869 DEF_HNDL(LLOG, ORIGIN_HANDLE_CREATE, _NET, flags, name, fn, NULL)
5871 static struct mdt_handler mdt_llog_ops[] = {
5872 DEF_LLOG_HNDL(0, ORIGIN_HANDLE_CREATE, mdt_llog_create),
5873 DEF_LLOG_HNDL(0, ORIGIN_HANDLE_NEXT_BLOCK, mdt_llog_next_block),
5874 DEF_LLOG_HNDL(0, ORIGIN_HANDLE_READ_HEADER, mdt_llog_read_header),
5875 DEF_LLOG_HNDL(0, ORIGIN_HANDLE_WRITE_REC, NULL),
5876 DEF_LLOG_HNDL(0, ORIGIN_HANDLE_CLOSE, NULL),
5877 DEF_LLOG_HNDL(0, ORIGIN_CONNECT, NULL),
5878 DEF_LLOG_HNDL(0, CATINFO, NULL),
5879 DEF_LLOG_HNDL(0, ORIGIN_HANDLE_PREV_BLOCK, mdt_llog_prev_block),
5880 DEF_LLOG_HNDL(0, ORIGIN_HANDLE_DESTROY, mdt_llog_destroy),
5883 #define DEF_SEC_CTX_HNDL(name, fn) \
5884 DEF_HNDL(SEC_CTX, INIT, _NET, 0, name, fn, NULL)
5886 static struct mdt_handler mdt_sec_ctx_ops[] = {
5887 DEF_SEC_CTX_HNDL(INIT, mdt_sec_ctx_handle),
5888 DEF_SEC_CTX_HNDL(INIT_CONT, mdt_sec_ctx_handle),
5889 DEF_SEC_CTX_HNDL(FINI, mdt_sec_ctx_handle)
5892 static struct mdt_opc_slice mdt_regular_handlers[] = {
5894 .mos_opc_start = MDS_GETATTR,
5895 .mos_opc_end = MDS_LAST_OPC,
5896 .mos_hs = mdt_mds_ops
5899 .mos_opc_start = OBD_PING,
5900 .mos_opc_end = OBD_LAST_OPC,
5901 .mos_hs = mdt_obd_ops
5904 .mos_opc_start = LDLM_ENQUEUE,
5905 .mos_opc_end = LDLM_LAST_OPC,
5906 .mos_hs = mdt_dlm_ops
5909 .mos_opc_start = LLOG_ORIGIN_HANDLE_CREATE,
5910 .mos_opc_end = LLOG_LAST_OPC,
5911 .mos_hs = mdt_llog_ops
5914 .mos_opc_start = SEC_CTX_INIT,
5915 .mos_opc_end = SEC_LAST_OPC,
5916 .mos_hs = mdt_sec_ctx_ops
5923 static struct mdt_handler mdt_readpage_ops[] = {
5924 DEF_MDT_HNDL_F(0, CONNECT, mdt_connect),
5925 DEF_MDT_HNDL_F(HABEO_CORPUS|HABEO_REFERO, READPAGE, mdt_readpage),
5926 #ifdef HAVE_SPLIT_SUPPORT
5927 DEF_MDT_HNDL_F(HABEO_CORPUS|HABEO_REFERO, WRITEPAGE, mdt_writepage),
5931 * XXX: this is ugly and should be fixed one day, see mdc_close() for
5932 * detailed comments. --umka
5934 DEF_MDT_HNDL_F(HABEO_CORPUS, CLOSE, mdt_close),
5935 DEF_MDT_HNDL_F(HABEO_CORPUS, DONE_WRITING, mdt_done_writing),
5938 static struct mdt_opc_slice mdt_readpage_handlers[] = {
5940 .mos_opc_start = MDS_GETATTR,
5941 .mos_opc_end = MDS_LAST_OPC,
5942 .mos_hs = mdt_readpage_ops
5949 static struct mdt_handler mdt_xmds_ops[] = {
5950 DEF_MDT_HNDL_F(0, CONNECT, mdt_connect),
5951 DEF_MDT_HNDL_F(HABEO_CORPUS , GETATTR, mdt_getattr),
5952 DEF_MDT_HNDL_F(0 | MUTABOR , REINT, mdt_reint),
5953 DEF_MDT_HNDL_F(HABEO_CORPUS|HABEO_REFERO, IS_SUBDIR, mdt_is_subdir),
5956 static struct mdt_opc_slice mdt_xmds_handlers[] = {
5958 .mos_opc_start = MDS_GETATTR,
5959 .mos_opc_end = MDS_LAST_OPC,
5960 .mos_hs = mdt_xmds_ops
5963 .mos_opc_start = OBD_PING,
5964 .mos_opc_end = OBD_LAST_OPC,
5965 .mos_hs = mdt_obd_ops
5968 .mos_opc_start = SEC_CTX_INIT,
5969 .mos_opc_end = SEC_LAST_OPC,
5970 .mos_hs = mdt_sec_ctx_ops
5977 static struct mdt_handler mdt_seq_ops[] = {
5978 DEF_SEQ_HNDL_F(0, QUERY, (int (*)(struct mdt_thread_info *))seq_query)
5981 static struct mdt_opc_slice mdt_seq_handlers[] = {
5983 .mos_opc_start = SEQ_QUERY,
5984 .mos_opc_end = SEQ_LAST_OPC,
5985 .mos_hs = mdt_seq_ops
5992 static struct mdt_handler mdt_fld_ops[] = {
5993 DEF_FLD_HNDL_F(0, QUERY, (int (*)(struct mdt_thread_info *))fld_query)
5996 static struct mdt_opc_slice mdt_fld_handlers[] = {
5998 .mos_opc_start = FLD_QUERY,
5999 .mos_opc_end = FLD_LAST_OPC,
6000 .mos_hs = mdt_fld_ops
6007 MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");
6008 MODULE_DESCRIPTION("Lustre Meta-data Target ("LUSTRE_MDT_NAME")");
6009 MODULE_LICENSE("GPL");
6011 CFS_MODULE_PARM(mdt_num_threads, "ul", ulong, 0444,
6012 "number of mdt service threads to start");
6014 cfs_module(mdt, "0.2.0", mdt_mod_init, mdt_mod_exit);