1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * lustre/mdt/mdt_handler.c
5 * Lustre Metadata Target (mdt) request handler
7 * Copyright (c) 2006 Cluster File Systems, Inc.
8 * Author: Peter Braam <braam@clusterfs.com>
9 * Author: Andreas Dilger <adilger@clusterfs.com>
10 * Author: Phil Schwan <phil@clusterfs.com>
11 * Author: Mike Shaver <shaver@clusterfs.com>
12 * Author: Nikita Danilov <nikita@clusterfs.com>
13 * Author: Huang Hua <huanghua@clusterfs.com>
14 * Author: Yury Umanets <umka@clusterfs.com>
16 * This file is part of the Lustre file system, http://www.lustre.org
17 * Lustre is a trademark of Cluster File Systems, Inc.
19 * You may have signed or agreed to another license before downloading
20 * this software. If so, you are bound by the terms and conditions
21 * of that agreement, and the following does not apply to you. See the
22 * LICENSE file included with this distribution for more information.
24 * If you did not agree to a different license, then this copy of Lustre
25 * is open source software; you can redistribute it and/or modify it
26 * under the terms of version 2 of the GNU General Public License as
27 * published by the Free Software Foundation.
29 * In either case, Lustre is distributed in the hope that it will be
30 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
31 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32 * license text for more details.
36 # define EXPORT_SYMTAB
38 #define DEBUG_SUBSYSTEM S_MDS
40 #include <linux/module.h>
42 * struct OBD_{ALLOC,FREE}*()
44 #include <obd_support.h>
45 /* struct ptlrpc_request */
46 #include <lustre_net.h>
47 /* struct obd_export */
48 #include <lustre_export.h>
49 /* struct obd_device */
52 #include <dt_object.h>
53 #include <lustre_mds.h>
54 #include <lustre_mdt.h>
55 #include "mdt_internal.h"
56 #include <linux/lustre_acl.h>
57 #include <lustre_param.h>
59 mdl_mode_t mdt_mdl_lock_modes[] = {
60 [LCK_MINMODE] = MDL_MINMODE,
67 [LCK_GROUP] = MDL_GROUP
70 ldlm_mode_t mdt_dlm_lock_modes[] = {
71 [MDL_MINMODE] = LCK_MINMODE,
78 [MDL_GROUP] = LCK_GROUP
82 * Initialized in mdt_mod_init().
84 unsigned long mdt_num_threads;
86 /* ptlrpc request handler for MDT. All handlers are
87 * grouped into several slices - struct mdt_opc_slice,
88 * and stored in an array - mdt_handlers[].
91 /* The name of this handler. */
93 /* Fail id for this handler, checked at the beginning of this handler*/
95 /* Operation code for this handler */
97 /* flags are listed in enum mdt_handler_flags below. */
99 /* The actual handler function to execute. */
100 int (*mh_act)(struct mdt_thread_info *info);
101 /* Request format for this request. */
102 const struct req_format *mh_fmt;
105 enum mdt_handler_flags {
107 * struct mdt_body is passed in the incoming message, and object
108 * identified by this fid exists on disk.
110 * "habeo corpus" == "I have a body"
112 HABEO_CORPUS = (1 << 0),
114 * struct ldlm_request is passed in the incoming message.
116 * "habeo clavis" == "I have a key"
118 HABEO_CLAVIS = (1 << 1),
120 * this request has fixed reply format, so that reply message can be
121 * packed by generic code.
123 * "habeo refero" == "I have a reply"
125 HABEO_REFERO = (1 << 2),
127 * this request will modify something, so check whether the filesystem
128 * is readonly or not, then return -EROFS to client asap if necessary.
130 * "mutabor" == "I shall modify"
135 struct mdt_opc_slice {
138 struct mdt_handler *mos_hs;
141 static struct mdt_opc_slice mdt_regular_handlers[];
142 static struct mdt_opc_slice mdt_readpage_handlers[];
143 static struct mdt_opc_slice mdt_xmds_handlers[];
144 static struct mdt_opc_slice mdt_seq_handlers[];
145 static struct mdt_opc_slice mdt_fld_handlers[];
147 static struct mdt_device *mdt_dev(struct lu_device *d);
148 static int mdt_regular_handle(struct ptlrpc_request *req);
149 static int mdt_unpack_req_pack_rep(struct mdt_thread_info *info, __u32 flags);
151 static struct lu_object_operations mdt_obj_ops;
153 int mdt_get_disposition(struct ldlm_reply *rep, int flag)
157 return (rep->lock_policy_res1 & flag);
160 void mdt_clear_disposition(struct mdt_thread_info *info,
161 struct ldlm_reply *rep, int flag)
164 info->mti_opdata &= ~flag;
166 rep->lock_policy_res1 &= ~flag;
169 void mdt_set_disposition(struct mdt_thread_info *info,
170 struct ldlm_reply *rep, int flag)
173 info->mti_opdata |= flag;
175 rep->lock_policy_res1 |= flag;
178 void mdt_lock_reg_init(struct mdt_lock_handle *lh, ldlm_mode_t lm)
180 lh->mlh_pdo_hash = 0;
181 lh->mlh_reg_mode = lm;
182 lh->mlh_type = MDT_REG_LOCK;
185 void mdt_lock_pdo_init(struct mdt_lock_handle *lh, ldlm_mode_t lm,
186 const char *name, int namelen)
188 lh->mlh_reg_mode = lm;
189 lh->mlh_type = MDT_PDO_LOCK;
192 LASSERT(namelen > 0);
193 lh->mlh_pdo_hash = full_name_hash(name, namelen);
195 LASSERT(namelen == 0);
196 lh->mlh_pdo_hash = 0ull;
200 static void mdt_lock_pdo_mode(struct mdt_thread_info *info, struct mdt_object *o,
201 struct mdt_lock_handle *lh)
207 * Any dir access needs couple of locks:
209 * 1) on part of dir we gonna take lookup/modify;
211 * 2) on whole dir to protect it from concurrent splitting and/or to
212 * flush client's cache for readdir().
214 * so, for a given mode and object this routine decides what lock mode
215 * to use for lock #2:
217 * 1) if caller's gonna lookup in dir then we need to protect dir from
218 * being splitted only - LCK_CR
220 * 2) if caller's gonna modify dir then we need to protect dir from
221 * being splitted and to flush cache - LCK_CW
223 * 3) if caller's gonna modify dir and that dir seems ready for
224 * splitting then we need to protect it from any type of access
225 * (lookup/modify/split) - LCK_EX --bzzz
228 LASSERT(lh->mlh_reg_mode != LCK_MINMODE);
229 LASSERT(lh->mlh_pdo_mode == LCK_MINMODE);
232 * Ask underlaying level its opinion about preferable PDO lock mode
233 * having access type passed as regular lock mode:
235 * - MDL_MINMODE means that lower layer does not want to specify lock
238 * - MDL_NL means that no PDO lock should be taken. This is used in some
239 * cases. Say, for non-splittable directories no need to use PDO locks
242 mode = mdo_lock_mode(info->mti_env, mdt_object_child(o),
243 mdt_dlm_mode2mdl_mode(lh->mlh_reg_mode));
245 if (mode != MDL_MINMODE) {
246 lh->mlh_pdo_mode = mdt_mdl_mode2dlm_mode(mode);
249 * Lower layer does not want to specify locking mode. We do it
250 * our selves. No special protection is needed, just flush
251 * client's cache on modification and allow concurrent
254 switch (lh->mlh_reg_mode) {
256 lh->mlh_pdo_mode = LCK_EX;
259 lh->mlh_pdo_mode = LCK_CR;
262 lh->mlh_pdo_mode = LCK_CW;
265 CERROR("Not expected lock type (0x%x)\n",
266 (int)lh->mlh_reg_mode);
271 LASSERT(lh->mlh_pdo_mode != LCK_MINMODE);
275 static int mdt_getstatus(struct mdt_thread_info *info)
277 struct mdt_device *mdt = info->mti_mdt;
278 struct md_device *next = mdt->mdt_child;
279 struct mdt_body *repbody;
284 rc = mdt_check_ucred(info);
286 RETURN(err_serious(rc));
288 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_GETSTATUS_PACK))
289 RETURN(err_serious(-ENOMEM));
291 repbody = req_capsule_server_get(&info->mti_pill, &RMF_MDT_BODY);
292 rc = next->md_ops->mdo_root_get(info->mti_env, next, &repbody->fid1);
296 repbody->valid |= OBD_MD_FLID;
298 if (mdt->mdt_opts.mo_mds_capa) {
299 struct mdt_object *root;
300 struct lustre_capa *capa;
302 root = mdt_object_find(info->mti_env, mdt, &repbody->fid1);
304 RETURN(PTR_ERR(root));
306 capa = req_capsule_server_get(&info->mti_pill, &RMF_CAPA1);
308 capa->lc_opc = CAPA_OPC_MDS_DEFAULT;
310 rc = mo_capa_get(info->mti_env, mdt_object_child(root), capa,
312 mdt_object_put(info->mti_env, root);
314 repbody->valid |= OBD_MD_FLMDSCAPA;
320 static int mdt_statfs(struct mdt_thread_info *info)
322 struct md_device *next = info->mti_mdt->mdt_child;
323 struct obd_statfs *osfs;
328 /* This will trigger a watchdog timeout */
329 OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_STATFS_LCW_SLEEP,
330 (MDT_SERVICE_WATCHDOG_TIMEOUT / 1000) + 1);
332 rc = mdt_check_ucred(info);
334 RETURN(err_serious(rc));
336 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_STATFS_PACK)) {
337 rc = err_serious(-ENOMEM);
339 osfs = req_capsule_server_get(&info->mti_pill,&RMF_OBD_STATFS);
340 rc = next->md_ops->mdo_statfs(info->mti_env, next,
342 statfs_pack(osfs, &info->mti_u.ksfs);
347 void mdt_pack_size2body(struct mdt_thread_info *info, struct mdt_object *o)
350 struct lu_attr *attr = &info->mti_attr.ma_attr;
352 b = req_capsule_server_get(&info->mti_pill, &RMF_MDT_BODY);
354 /* Check if Size-on-MDS is enabled. */
355 if ((mdt_conn_flags(info) & OBD_CONNECT_SOM) &&
356 S_ISREG(attr->la_mode) && mdt_sizeonmds_enabled(o)) {
357 b->valid |= (OBD_MD_FLSIZE | OBD_MD_FLBLOCKS);
358 b->size = attr->la_size;
359 b->blocks = attr->la_blocks;
363 void mdt_pack_attr2body(struct mdt_thread_info *info, struct mdt_body *b,
364 const struct lu_attr *attr, const struct lu_fid *fid)
366 /*XXX should pack the reply body according to lu_valid*/
367 b->valid |= OBD_MD_FLCTIME | OBD_MD_FLUID |
368 OBD_MD_FLGID | OBD_MD_FLTYPE |
369 OBD_MD_FLMODE | OBD_MD_FLNLINK | OBD_MD_FLFLAGS |
370 OBD_MD_FLATIME | OBD_MD_FLMTIME ;
372 if (!S_ISREG(attr->la_mode))
373 b->valid |= OBD_MD_FLSIZE | OBD_MD_FLBLOCKS | OBD_MD_FLRDEV;
375 b->atime = attr->la_atime;
376 b->mtime = attr->la_mtime;
377 b->ctime = attr->la_ctime;
378 b->mode = attr->la_mode;
379 b->size = attr->la_size;
380 b->blocks = attr->la_blocks;
381 b->uid = attr->la_uid;
382 b->gid = attr->la_gid;
383 b->flags = attr->la_flags;
384 b->nlink = attr->la_nlink;
385 b->rdev = attr->la_rdev;
389 b->valid |= OBD_MD_FLID;
390 CDEBUG(D_INODE, ""DFID": nlink=%d, mode=%o, size="LPU64"\n",
391 PFID(fid), b->nlink, b->mode, b->size);
395 mdt_body_reverse_idmap(info, b);
398 static inline int mdt_body_has_lov(const struct lu_attr *la,
399 const struct mdt_body *body)
401 return ((S_ISREG(la->la_mode) && (body->valid & OBD_MD_FLEASIZE)) ||
402 (S_ISDIR(la->la_mode) && (body->valid & OBD_MD_FLDIREA )) );
405 static int mdt_getattr_internal(struct mdt_thread_info *info,
406 struct mdt_object *o)
408 struct md_object *next = mdt_object_child(o);
409 const struct mdt_body *reqbody = info->mti_body;
410 struct ptlrpc_request *req = mdt_info_req(info);
411 struct mdt_export_data *med = &req->rq_export->exp_mdt_data;
412 struct md_attr *ma = &info->mti_attr;
413 struct lu_attr *la = &ma->ma_attr;
414 struct req_capsule *pill = &info->mti_pill;
415 const struct lu_env *env = info->mti_env;
416 struct mdt_body *repbody;
417 struct lu_buf *buffer = &info->mti_buf;
421 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_GETATTR_PACK))
422 RETURN(err_serious(-ENOMEM));
424 repbody = req_capsule_server_get(pill, &RMF_MDT_BODY);
428 rc = mdt_object_exists(o);
430 /* This object is located on remote node.*/
431 repbody->fid1 = *mdt_object_fid(o);
432 repbody->valid = OBD_MD_FLID | OBD_MD_MDS;
436 buffer->lb_buf = req_capsule_server_get(pill, &RMF_MDT_MD);
437 buffer->lb_len = req_capsule_get_size(pill, &RMF_MDT_MD, RCL_SERVER);
439 /* If it is dir object and client require MEA, then we got MEA */
440 if (S_ISDIR(lu_object_attr(&next->mo_lu)) &&
441 reqbody->valid & OBD_MD_MEA) {
442 /* Assumption: MDT_MD size is enough for lmv size. */
443 ma->ma_lmv = buffer->lb_buf;
444 ma->ma_lmv_size = buffer->lb_len;
445 ma->ma_need = MA_LMV | MA_INODE;
447 ma->ma_lmm = buffer->lb_buf;
448 ma->ma_lmm_size = buffer->lb_len;
449 ma->ma_need = MA_LOV | MA_INODE;
452 rc = mo_attr_get(env, next, ma);
454 CERROR("getattr error for "DFID": %d\n",
455 PFID(mdt_object_fid(o)), rc);
459 if (likely(ma->ma_valid & MA_INODE))
460 mdt_pack_attr2body(info, repbody, la, mdt_object_fid(o));
464 if (mdt_body_has_lov(la, reqbody)) {
465 if (ma->ma_valid & MA_LOV) {
466 LASSERT(ma->ma_lmm_size);
467 mdt_dump_lmm(D_INFO, ma->ma_lmm);
468 repbody->eadatasize = ma->ma_lmm_size;
469 if (S_ISDIR(la->la_mode))
470 repbody->valid |= OBD_MD_FLDIREA;
472 repbody->valid |= OBD_MD_FLEASIZE;
474 if (ma->ma_valid & MA_LMV) {
475 LASSERT(S_ISDIR(la->la_mode));
476 repbody->eadatasize = ma->ma_lmv_size;
477 repbody->valid |= (OBD_MD_FLDIREA|OBD_MD_MEA);
479 if (!(ma->ma_valid & MA_LOV) && !(ma->ma_valid & MA_LMV)) {
480 repbody->valid |= OBD_MD_FLSIZE | OBD_MD_FLBLOCKS;
482 } else if (S_ISLNK(la->la_mode) &&
483 reqbody->valid & OBD_MD_LINKNAME) {
484 buffer->lb_buf = ma->ma_lmm;
485 buffer->lb_len = reqbody->eadatasize;
486 rc = mo_readlink(env, next, buffer);
487 if (unlikely(rc <= 0)) {
488 CERROR("readlink failed: %d\n", rc);
491 repbody->valid |= OBD_MD_LINKNAME;
492 repbody->eadatasize = rc;
494 ((char*)ma->ma_lmm)[rc - 1] = 0;
495 CDEBUG(D_INODE, "symlink dest %s, len = %d\n",
496 (char*)ma->ma_lmm, rc);
501 if (reqbody->valid & OBD_MD_FLMODEASIZE) {
502 repbody->max_cookiesize = info->mti_mdt->mdt_max_cookiesize;
503 repbody->max_mdsize = info->mti_mdt->mdt_max_mdsize;
504 repbody->valid |= OBD_MD_FLMODEASIZE;
505 CDEBUG(D_INODE, "I am going to change the MAX_MD_SIZE & "
506 "MAX_COOKIE to : %d:%d\n", repbody->max_mdsize,
507 repbody->max_cookiesize);
510 if (med->med_rmtclient && (reqbody->valid & OBD_MD_FLRMTPERM)) {
511 void *buf = req_capsule_server_get(pill, &RMF_ACL);
513 /* mdt_getattr_lock only */
514 rc = mdt_pack_remote_perm(info, o, buf);
516 repbody->valid &= ~OBD_MD_FLRMTPERM;
517 repbody->aclsize = 0;
520 repbody->valid |= OBD_MD_FLRMTPERM;
521 repbody->aclsize = sizeof(struct mdt_remote_perm);
524 #ifdef CONFIG_FS_POSIX_ACL
525 else if ((req->rq_export->exp_connect_flags & OBD_CONNECT_ACL) &&
526 (reqbody->valid & OBD_MD_FLACL)) {
527 buffer->lb_buf = req_capsule_server_get(pill, &RMF_ACL);
528 buffer->lb_len = req_capsule_get_size(pill,
529 &RMF_ACL, RCL_SERVER);
530 if (buffer->lb_len > 0) {
531 rc = mo_xattr_get(env, next, buffer,
532 XATTR_NAME_ACL_ACCESS);
534 if (rc == -ENODATA) {
535 repbody->aclsize = 0;
536 repbody->valid |= OBD_MD_FLACL;
538 } else if (rc == -EOPNOTSUPP) {
541 CERROR("got acl size: %d\n", rc);
544 repbody->aclsize = rc;
545 repbody->valid |= OBD_MD_FLACL;
552 if ((reqbody->valid & OBD_MD_FLMDSCAPA) &&
553 info->mti_mdt->mdt_opts.mo_mds_capa) {
554 struct lustre_capa *capa;
556 capa = req_capsule_server_get(&info->mti_pill, &RMF_CAPA1);
558 capa->lc_opc = CAPA_OPC_MDS_DEFAULT;
559 rc = mo_capa_get(env, next, capa, 0);
562 repbody->valid |= OBD_MD_FLMDSCAPA;
567 static int mdt_renew_capa(struct mdt_thread_info *info)
569 struct mdt_device *mdt = info->mti_mdt;
570 struct mdt_object *obj = info->mti_object;
571 struct mdt_body *body;
572 struct lustre_capa *capa, *c;
576 /* if object doesn't exist, or server has disabled capability,
577 * return directly, client will find body->valid OBD_MD_FLOSSCAPA
580 if (!obj || !mdt->mdt_opts.mo_mds_capa)
583 body = req_capsule_server_get(&info->mti_pill, &RMF_MDT_BODY);
584 LASSERT(body != NULL);
586 c = req_capsule_client_get(&info->mti_pill, &RMF_CAPA1);
589 capa = req_capsule_server_get(&info->mti_pill, &RMF_CAPA1);
593 rc = mo_capa_get(info->mti_env, mdt_object_child(obj), capa, 1);
595 body->valid |= OBD_MD_FLOSSCAPA;
600 static int mdt_getattr(struct mdt_thread_info *info)
602 struct mdt_object *obj = info->mti_object;
603 struct req_capsule *pill = &info->mti_pill;
604 struct mdt_body *reqbody;
605 struct mdt_body *repbody;
611 reqbody = req_capsule_client_get(pill, &RMF_MDT_BODY);
614 if (reqbody->valid & OBD_MD_FLOSSCAPA) {
615 rc = req_capsule_pack(pill);
617 rc = err_serious(rc);
619 rc = mdt_renew_capa(info);
620 mdt_shrink_reply(info);
625 LASSERT(obj != NULL);
626 LASSERT(lu_object_assert_exists(&obj->mot_obj.mo_lu));
628 mode = lu_object_attr(&obj->mot_obj.mo_lu);
629 if (S_ISLNK(mode) && (reqbody->valid & OBD_MD_LINKNAME) &&
630 (reqbody->eadatasize > info->mti_mdt->mdt_max_mdsize))
631 md_size = reqbody->eadatasize;
633 md_size = info->mti_mdt->mdt_max_mdsize;
635 req_capsule_set_size(pill, &RMF_MDT_MD, RCL_SERVER, md_size);
637 rc = req_capsule_pack(pill);
638 if (unlikely(rc != 0))
639 GOTO(out, rc = err_serious(rc));
641 repbody = req_capsule_server_get(pill, &RMF_MDT_BODY);
642 LASSERT(repbody != NULL);
643 repbody->eadatasize = 0;
644 repbody->aclsize = 0;
646 if (reqbody->valid & OBD_MD_FLRMTPERM)
647 rc = mdt_init_ucred(info, reqbody);
649 rc = mdt_check_ucred(info);
651 GOTO(out_shrink, rc);
653 info->mti_spec.sp_ck_split = !!(reqbody->valid & OBD_MD_FLCKSPLIT);
654 info->mti_cross_ref = !!(reqbody->valid & OBD_MD_FLCROSSREF);
657 * Don't check capability at all, because rename might getattr for
658 * remote obj, and at that time no capability is available.
660 mdt_set_capainfo(info, 1, &reqbody->fid1, BYPASS_CAPA);
661 rc = mdt_getattr_internal(info, obj);
662 if (reqbody->valid & OBD_MD_FLRMTPERM)
663 mdt_exit_ucred(info);
666 mdt_shrink_reply(info);
671 static int mdt_is_subdir(struct mdt_thread_info *info)
673 struct mdt_object *o = info->mti_object;
674 struct req_capsule *pill = &info->mti_pill;
675 const struct mdt_body *body = info->mti_body;
676 struct mdt_body *repbody;
682 repbody = req_capsule_server_get(pill, &RMF_MDT_BODY);
685 * We save last checked parent fid to @repbody->fid1 for remote
688 LASSERT(fid_is_sane(&body->fid2));
689 LASSERT(mdt_object_exists(o) > 0);
690 rc = mdo_is_subdir(info->mti_env, mdt_object_child(o),
691 &body->fid2, &repbody->fid1);
692 if (rc == 0 || rc == -EREMOTE)
693 repbody->valid |= OBD_MD_FLID;
698 static int mdt_raw_lookup(struct mdt_thread_info *info,
699 struct mdt_object *parent,
700 const struct lu_name *lname,
701 struct ldlm_reply *ldlm_rep)
703 struct md_object *next = mdt_object_child(info->mti_object);
704 const struct mdt_body *reqbody = info->mti_body;
705 struct lu_fid *child_fid = &info->mti_tmp_fid1;
706 struct mdt_body *repbody;
710 if (reqbody->valid != OBD_MD_FLID)
713 LASSERT(!info->mti_cross_ref);
715 /* Only got the fid of this obj by name */
716 rc = mdo_lookup(info->mti_env, next, lname, child_fid,
719 /* XXX is raw_lookup possible as intent operation? */
722 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_NEG);
725 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_POS);
727 repbody = req_capsule_server_get(&info->mti_pill, &RMF_MDT_BODY);
730 repbody = req_capsule_server_get(&info->mti_pill,
732 repbody->fid1 = *child_fid;
733 repbody->valid = OBD_MD_FLID;
739 * UPDATE lock should be taken against parent, and be release before exit;
740 * child_bits lock should be taken against child, and be returned back:
741 * (1)normal request should release the child lock;
742 * (2)intent request will grant the lock to client.
744 static int mdt_getattr_name_lock(struct mdt_thread_info *info,
745 struct mdt_lock_handle *lhc,
747 struct ldlm_reply *ldlm_rep)
749 struct ptlrpc_request *req = mdt_info_req(info);
750 struct mdt_body *reqbody = NULL;
751 struct mdt_object *parent = info->mti_object;
752 struct mdt_object *child;
753 struct md_object *next = mdt_object_child(parent);
754 struct lu_fid *child_fid = &info->mti_tmp_fid1;
755 struct lu_name *lname = NULL;
758 struct mdt_lock_handle *lhp;
759 struct ldlm_lock *lock;
760 struct ldlm_res_id *res_id;
766 is_resent = lustre_handle_is_used(&lhc->mlh_reg_lh);
767 LASSERT(ergo(is_resent,
768 lustre_msg_get_flags(req->rq_reqmsg) & MSG_RESENT));
770 LASSERT(parent != NULL);
771 name = req_capsule_client_get(&info->mti_pill, &RMF_NAME);
773 RETURN(err_serious(-EFAULT));
775 namelen = req_capsule_get_size(&info->mti_pill, &RMF_NAME,
777 LASSERT(namelen >= 0);
779 /* XXX: "namelen == 0" is for getattr by fid (OBD_CONNECT_ATTRFID),
780 * otherwise do not allow empty name, that is the name must contain
781 * at least one character and the terminating '\0'*/
783 reqbody =req_capsule_client_get(&info->mti_pill, &RMF_MDT_BODY);
784 LASSERT(fid_is_sane(&reqbody->fid2));
787 CDEBUG(D_INODE, "getattr with lock for "DFID"/"DFID", "
789 PFID(mdt_object_fid(parent)), PFID(&reqbody->fid2),
792 lname = mdt_name(info->mti_env, (char *)name, namelen);
793 CDEBUG(D_INODE, "getattr with lock for "DFID"/%s, "
795 PFID(mdt_object_fid(parent)), name, ldlm_rep);
798 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_EXECD);
800 rc = mdt_object_exists(parent);
801 if (unlikely(rc == 0)) {
802 LU_OBJECT_DEBUG(D_WARNING, info->mti_env,
803 &parent->mot_obj.mo_lu,
804 "Parent doesn't exist!\n");
807 LASSERTF(rc > 0, "Parent "DFID" is on remote server\n",
808 PFID(mdt_object_fid(parent)));
811 rc = mdt_raw_lookup(info, parent, lname, ldlm_rep);
819 if (info->mti_cross_ref) {
820 /* Only getattr on the child. Parent is on another node. */
821 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_POS);
823 CDEBUG(D_INODE, "partial getattr_name child_fid = "DFID", "
824 "ldlm_rep=%p\n", PFID(mdt_object_fid(child)), ldlm_rep);
827 /* Do not take lock for resent case. */
828 lock = ldlm_handle2lock(&lhc->mlh_reg_lh);
829 LASSERTF(lock != NULL, "Invalid lock handle "LPX64"\n",
830 lhc->mlh_reg_lh.cookie);
831 LASSERT(fid_res_name_eq(mdt_object_fid(child),
832 &lock->l_resource->lr_name));
836 mdt_lock_handle_init(lhc);
837 mdt_lock_reg_init(lhc, LCK_PR);
840 * Object's name is on another MDS, no lookup lock is
841 * needed here but update is.
843 child_bits &= ~MDS_INODELOCK_LOOKUP;
844 child_bits |= MDS_INODELOCK_UPDATE;
846 rc = mdt_object_lock(info, child, lhc, child_bits,
850 /* Finally, we can get attr for child. */
851 mdt_set_capainfo(info, 0, mdt_object_fid(child),
853 rc = mdt_getattr_internal(info, child);
854 if (unlikely(rc != 0))
855 mdt_object_unlock(info, child, lhc, 1);
860 /* step 1: lock parent */
861 lhp = &info->mti_lh[MDT_LH_PARENT];
862 mdt_lock_pdo_init(lhp, LCK_PR, name, namelen);
863 rc = mdt_object_lock(info, parent, lhp, MDS_INODELOCK_UPDATE,
866 if (unlikely(rc != 0))
870 /* step 2: lookup child's fid by name */
871 rc = mdo_lookup(info->mti_env, next, lname, child_fid,
876 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_NEG);
877 GOTO(out_parent, rc);
879 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_POS);
881 *child_fid = reqbody->fid2;
882 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_POS);
886 *step 3: find the child object by fid & lock it.
887 * regardless if it is local or remote.
889 child = mdt_object_find(info->mti_env, info->mti_mdt, child_fid);
891 if (unlikely(IS_ERR(child)))
892 GOTO(out_parent, rc = PTR_ERR(child));
894 /* Do not take lock for resent case. */
895 lock = ldlm_handle2lock(&lhc->mlh_reg_lh);
896 LASSERTF(lock != NULL, "Invalid lock handle "LPX64"\n",
897 lhc->mlh_reg_lh.cookie);
899 res_id = &lock->l_resource->lr_name;
900 if (!fid_res_name_eq(mdt_object_fid(child),
901 &lock->l_resource->lr_name)) {
902 LASSERTF(fid_res_name_eq(mdt_object_fid(parent),
903 &lock->l_resource->lr_name),
904 "Lock res_id: %lu/%lu/%lu, Fid: "DFID".\n",
905 (unsigned long)res_id->name[0],
906 (unsigned long)res_id->name[1],
907 (unsigned long)res_id->name[2],
908 PFID(mdt_object_fid(parent)));
909 CWARN("Although resent, but still not get child lock"
910 "parent:"DFID" child:"DFID"\n",
911 PFID(mdt_object_fid(parent)),
912 PFID(mdt_object_fid(child)));
913 lustre_msg_clear_flags(req->rq_reqmsg, MSG_RESENT);
921 mdt_lock_handle_init(lhc);
922 mdt_lock_reg_init(lhc, LCK_PR);
924 if (mdt_object_exists(child) == 0) {
925 LU_OBJECT_DEBUG(D_WARNING, info->mti_env,
926 &child->mot_obj.mo_lu,
927 "Object doesn't exist!\n");
929 rc = mdt_object_lock(info, child, lhc, child_bits,
932 if (unlikely(rc != 0))
936 /* finally, we can get attr for child. */
937 mdt_set_capainfo(info, 1, child_fid, BYPASS_CAPA);
938 rc = mdt_getattr_internal(info, child);
939 if (unlikely(rc != 0)) {
940 mdt_object_unlock(info, child, lhc, 1);
942 lock = ldlm_handle2lock(&lhc->mlh_reg_lh);
944 struct mdt_body *repbody;
947 /* Debugging code. */
948 res_id = &lock->l_resource->lr_name;
949 LDLM_DEBUG(lock, "Returning lock to client\n");
950 LASSERTF(fid_res_name_eq(mdt_object_fid(child),
951 &lock->l_resource->lr_name),
952 "Lock res_id: %lu/%lu/%lu, Fid: "DFID".\n",
953 (unsigned long)res_id->name[0],
954 (unsigned long)res_id->name[1],
955 (unsigned long)res_id->name[2],
956 PFID(mdt_object_fid(child)));
958 * Pack Size-on-MDS inode attributes to the body if
959 * update lock is given.
961 repbody = req_capsule_server_get(&info->mti_pill,
963 ma = &info->mti_attr.ma_attr;
964 if (lock->l_policy_data.l_inodebits.bits &
965 MDS_INODELOCK_UPDATE)
966 mdt_pack_size2body(info, child);
972 mdt_object_put(info->mti_env, child);
974 mdt_object_unlock(info, parent, lhp, 1);
979 /* normal handler: should release the child lock */
980 static int mdt_getattr_name(struct mdt_thread_info *info)
982 struct mdt_lock_handle *lhc = &info->mti_lh[MDT_LH_CHILD];
983 struct mdt_body *reqbody;
984 struct mdt_body *repbody;
988 reqbody = req_capsule_client_get(&info->mti_pill, &RMF_MDT_BODY);
989 LASSERT(reqbody != NULL);
990 repbody = req_capsule_server_get(&info->mti_pill, &RMF_MDT_BODY);
991 LASSERT(repbody != NULL);
993 info->mti_spec.sp_ck_split = !!(reqbody->valid & OBD_MD_FLCKSPLIT);
994 info->mti_cross_ref = !!(reqbody->valid & OBD_MD_FLCROSSREF);
995 repbody->eadatasize = 0;
996 repbody->aclsize = 0;
998 rc = mdt_init_ucred(info, reqbody);
1002 rc = mdt_getattr_name_lock(info, lhc, MDS_INODELOCK_UPDATE, NULL);
1003 if (lustre_handle_is_used(&lhc->mlh_reg_lh)) {
1004 ldlm_lock_decref(&lhc->mlh_reg_lh, lhc->mlh_reg_mode);
1005 lhc->mlh_reg_lh.cookie = 0;
1007 mdt_exit_ucred(info);
1010 mdt_shrink_reply(info);
1014 static struct lu_device_operations mdt_lu_ops;
1016 static int lu_device_is_mdt(struct lu_device *d)
1018 return ergo(d != NULL && d->ld_ops != NULL, d->ld_ops == &mdt_lu_ops);
1021 static int mdt_set_info(struct mdt_thread_info *info)
1023 struct ptlrpc_request *req = mdt_info_req(info);
1029 rc = lustre_pack_reply(req, 1, NULL, NULL);
1033 key = req_capsule_client_get(&info->mti_pill, &RMF_SETINFO_KEY);
1035 DEBUG_REQ(D_HA, req, "no set_info key");
1039 keylen = req_capsule_get_size(&info->mti_pill, &RMF_SETINFO_KEY,
1042 val = req_capsule_client_get(&info->mti_pill, &RMF_SETINFO_VAL);
1044 DEBUG_REQ(D_HA, req, "no set_info val");
1048 if (keylen != (sizeof(KEY_READ_ONLY) - 1) ||
1049 memcmp(key, KEY_READ_ONLY, keylen) != 0)
1053 lustre_msg_set_status(req->rq_repmsg, 0);
1055 spin_lock(&req->rq_export->exp_lock);
1057 req->rq_export->exp_connect_flags |= OBD_CONNECT_RDONLY;
1059 req->rq_export->exp_connect_flags &= ~OBD_CONNECT_RDONLY;
1060 spin_unlock(&req->rq_export->exp_lock);
1065 static int mdt_connect(struct mdt_thread_info *info)
1068 struct ptlrpc_request *req;
1070 req = mdt_info_req(info);
1071 rc = target_handle_connect(req);
1073 LASSERT(req->rq_export != NULL);
1074 info->mti_mdt = mdt_dev(req->rq_export->exp_obd->obd_lu_dev);
1075 rc = mdt_init_idmap(info);
1077 /* if mdt_init_idmap failed, revocation for connect */
1078 obd_disconnect(class_export_get(req->rq_export));
1080 rc = err_serious(rc);
1084 static int mdt_disconnect(struct mdt_thread_info *info)
1089 rc = target_handle_disconnect(mdt_info_req(info));
1091 rc = err_serious(rc);
1095 static int mdt_sendpage(struct mdt_thread_info *info,
1096 struct lu_rdpg *rdpg)
1098 struct ptlrpc_request *req = mdt_info_req(info);
1099 struct ptlrpc_bulk_desc *desc;
1100 struct l_wait_info *lwi = &info->mti_u.rdpg.mti_wait_info;
1107 desc = ptlrpc_prep_bulk_exp(req, rdpg->rp_npages, BULK_PUT_SOURCE,
1110 GOTO(out, rc = -ENOMEM);
1112 for (i = 0, tmpcount = rdpg->rp_count;
1113 i < rdpg->rp_npages; i++, tmpcount -= tmpsize) {
1114 tmpsize = min_t(int, tmpcount, CFS_PAGE_SIZE);
1115 ptlrpc_prep_bulk_page(desc, rdpg->rp_pages[i], 0, tmpsize);
1118 LASSERT(desc->bd_nob == rdpg->rp_count);
1119 rc = ptlrpc_start_bulk_transfer(desc);
1121 GOTO(free_desc, rc);
1123 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_SENDPAGE))
1124 GOTO(abort_bulk, rc);
1126 *lwi = LWI_TIMEOUT(obd_timeout * HZ / 4, NULL, NULL);
1127 rc = l_wait_event(desc->bd_waitq, !ptlrpc_bulk_active(desc), lwi);
1128 LASSERT (rc == 0 || rc == -ETIMEDOUT);
1131 if (desc->bd_success &&
1132 desc->bd_nob_transferred == rdpg->rp_count)
1133 GOTO(free_desc, rc);
1135 rc = -ETIMEDOUT; /* XXX should this be a different errno? */
1138 DEBUG_REQ(D_ERROR, req, "bulk failed: %s %d(%d), evicting %s@%s",
1139 (rc == -ETIMEDOUT) ? "timeout" : "network error",
1140 desc->bd_nob_transferred, rdpg->rp_count,
1141 req->rq_export->exp_client_uuid.uuid,
1142 req->rq_export->exp_connection->c_remote_uuid.uuid);
1144 class_fail_export(req->rq_export);
1148 ptlrpc_abort_bulk(desc);
1150 ptlrpc_free_bulk(desc);
1155 #ifdef HAVE_SPLIT_SUPPORT
1157 * Retrieve dir entry from the page and insert it to the slave object, actually,
1158 * this should be in osd layer, but since it will not in the final product, so
1159 * just do it here and do not define more moo api anymore for this.
1161 static int mdt_write_dir_page(struct mdt_thread_info *info, struct page *page,
1164 struct mdt_object *object = info->mti_object;
1165 struct lu_fid *lf = &info->mti_tmp_fid2;
1166 struct md_attr *ma = &info->mti_attr;
1167 struct lu_dirpage *dp;
1168 struct lu_dirent *ent;
1169 int rc = 0, offset = 0;
1172 /* Make sure we have at least one entry. */
1177 * Disable trans for this name insert, since it will include many trans
1180 info->mti_no_need_trans = 1;
1182 * When write_dir_page, no need update parent's ctime,
1183 * and no permission check for name_insert.
1185 ma->ma_attr.la_ctime = 0;
1186 ma->ma_attr.la_valid = LA_MODE;
1187 ma->ma_valid = MA_INODE;
1190 dp = page_address(page);
1191 offset = (int)((__u32)lu_dirent_start(dp) - (__u32)dp);
1193 for (ent = lu_dirent_start(dp); ent != NULL;
1194 ent = lu_dirent_next(ent)) {
1195 struct lu_name *lname;
1198 if (le16_to_cpu(ent->lde_namelen) == 0)
1201 fid_le_to_cpu(lf, &ent->lde_fid);
1202 if (le32_to_cpu(ent->lde_hash) & MAX_HASH_HIGHEST_BIT)
1203 ma->ma_attr.la_mode = S_IFDIR;
1205 ma->ma_attr.la_mode = 0;
1206 OBD_ALLOC(name, le16_to_cpu(ent->lde_namelen) + 1);
1208 GOTO(out, rc = -ENOMEM);
1210 memcpy(name, ent->lde_name, le16_to_cpu(ent->lde_namelen));
1211 lname = mdt_name(info->mti_env, name,
1212 le16_to_cpu(ent->lde_namelen) + 1);
1213 ma->ma_attr_flags |= MDS_PERM_BYPASS;
1214 rc = mdo_name_insert(info->mti_env,
1215 md_object_next(&object->mot_obj),
1217 OBD_FREE(name, le16_to_cpu(ent->lde_namelen) + 1);
1219 CERROR("Can't insert %*.*s, rc %d\n",
1220 le16_to_cpu(ent->lde_namelen),
1221 le16_to_cpu(ent->lde_namelen),
1226 offset += lu_dirent_size(ent);
1236 static int mdt_bulk_timeout(void *data)
1240 CERROR("mdt bulk transfer timeout \n");
1245 static int mdt_writepage(struct mdt_thread_info *info)
1247 struct ptlrpc_request *req = mdt_info_req(info);
1248 struct mdt_body *reqbody;
1249 struct l_wait_info *lwi;
1250 struct ptlrpc_bulk_desc *desc;
1256 reqbody = req_capsule_client_get(&info->mti_pill, &RMF_MDT_BODY);
1257 if (reqbody == NULL)
1258 RETURN(err_serious(-EFAULT));
1260 desc = ptlrpc_prep_bulk_exp(req, 1, BULK_GET_SINK, MDS_BULK_PORTAL);
1262 RETURN(err_serious(-ENOMEM));
1264 /* allocate the page for the desc */
1265 page = cfs_alloc_page(CFS_ALLOC_STD);
1267 GOTO(desc_cleanup, rc = -ENOMEM);
1269 CDEBUG(D_INFO, "Received page offset %d size %d \n",
1270 (int)reqbody->size, (int)reqbody->nlink);
1272 ptlrpc_prep_bulk_page(desc, page, (int)reqbody->size,
1273 (int)reqbody->nlink);
1276 * Check if client was evicted while we were doing i/o before touching
1281 GOTO(cleanup_page, rc = -ENOMEM);
1283 if (desc->bd_export->exp_failed)
1286 rc = ptlrpc_start_bulk_transfer (desc);
1288 *lwi = LWI_TIMEOUT_INTERVAL(obd_timeout * HZ / 4, HZ,
1289 mdt_bulk_timeout, desc);
1290 rc = l_wait_event(desc->bd_waitq, !ptlrpc_bulk_active(desc) ||
1291 desc->bd_export->exp_failed, lwi);
1292 LASSERT(rc == 0 || rc == -ETIMEDOUT);
1293 if (rc == -ETIMEDOUT) {
1294 DEBUG_REQ(D_ERROR, req, "timeout on bulk GET");
1295 ptlrpc_abort_bulk(desc);
1296 } else if (desc->bd_export->exp_failed) {
1297 DEBUG_REQ(D_ERROR, req, "Eviction on bulk GET");
1299 ptlrpc_abort_bulk(desc);
1300 } else if (!desc->bd_success ||
1301 desc->bd_nob_transferred != desc->bd_nob) {
1302 DEBUG_REQ(D_ERROR, req, "%s bulk GET %d(%d)",
1304 "truncated" : "network error on",
1305 desc->bd_nob_transferred, desc->bd_nob);
1306 /* XXX should this be a different errno? */
1310 DEBUG_REQ(D_ERROR, req, "ptlrpc_bulk_get failed: rc %d", rc);
1313 GOTO(cleanup_lwi, rc);
1314 rc = mdt_write_dir_page(info, page, reqbody->nlink);
1319 __cfs_free_page(page);
1321 ptlrpc_free_bulk(desc);
1326 static int mdt_readpage(struct mdt_thread_info *info)
1328 struct mdt_object *object = info->mti_object;
1329 struct lu_rdpg *rdpg = &info->mti_u.rdpg.mti_rdpg;
1330 struct mdt_body *reqbody;
1331 struct mdt_body *repbody;
1336 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_READPAGE_PACK))
1337 RETURN(err_serious(-ENOMEM));
1339 reqbody = req_capsule_client_get(&info->mti_pill, &RMF_MDT_BODY);
1340 repbody = req_capsule_server_get(&info->mti_pill, &RMF_MDT_BODY);
1341 if (reqbody == NULL || repbody == NULL)
1342 RETURN(err_serious(-EFAULT));
1344 rc = mdt_check_ucred(info);
1346 RETURN(err_serious(rc));
1349 * prepare @rdpg before calling lower layers and transfer itself. Here
1350 * reqbody->size contains offset of where to start to read and
1351 * reqbody->nlink contains number bytes to read.
1353 rdpg->rp_hash = reqbody->size;
1354 if ((__u64)rdpg->rp_hash != reqbody->size) {
1355 CERROR("Invalid hash: %#llx != %#llx\n",
1356 (__u64)rdpg->rp_hash, reqbody->size);
1359 rdpg->rp_count = reqbody->nlink;
1360 rdpg->rp_npages = (rdpg->rp_count + CFS_PAGE_SIZE - 1)>>CFS_PAGE_SHIFT;
1361 OBD_ALLOC(rdpg->rp_pages, rdpg->rp_npages * sizeof rdpg->rp_pages[0]);
1362 if (rdpg->rp_pages == NULL)
1365 for (i = 0; i < rdpg->rp_npages; ++i) {
1366 rdpg->rp_pages[i] = cfs_alloc_page(CFS_ALLOC_STD);
1367 if (rdpg->rp_pages[i] == NULL)
1368 GOTO(free_rdpg, rc = -ENOMEM);
1371 /* call lower layers to fill allocated pages with directory data */
1372 rc = mo_readpage(info->mti_env, mdt_object_child(object), rdpg);
1374 GOTO(free_rdpg, rc);
1376 /* send pages to client */
1377 rc = mdt_sendpage(info, rdpg);
1382 for (i = 0; i < rdpg->rp_npages; i++)
1383 if (rdpg->rp_pages[i] != NULL)
1384 __cfs_free_page(rdpg->rp_pages[i]);
1385 OBD_FREE(rdpg->rp_pages, rdpg->rp_npages * sizeof rdpg->rp_pages[0]);
1387 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_SENDPAGE))
1393 static int mdt_reint_internal(struct mdt_thread_info *info,
1394 struct mdt_lock_handle *lhc,
1397 struct req_capsule *pill = &info->mti_pill;
1398 struct mdt_device *mdt = info->mti_mdt;
1399 struct mdt_body *repbody;
1400 int need_shrink = 0;
1405 if (req_capsule_has_field(pill, &RMF_MDT_MD, RCL_SERVER)) {
1406 req_capsule_set_size(pill, &RMF_MDT_MD, RCL_SERVER,
1407 mdt->mdt_max_mdsize);
1410 if (req_capsule_has_field(pill, &RMF_LOGCOOKIES, RCL_SERVER)) {
1411 req_capsule_set_size(pill, &RMF_LOGCOOKIES, RCL_SERVER,
1412 mdt->mdt_max_cookiesize);
1415 rc = req_capsule_pack(pill);
1417 CERROR("Can't pack response, rc %d\n", rc);
1418 RETURN(err_serious(rc));
1421 if (req_capsule_has_field(pill, &RMF_MDT_BODY, RCL_SERVER)) {
1422 repbody = req_capsule_server_get(pill, &RMF_MDT_BODY);
1424 repbody->eadatasize = 0;
1425 repbody->aclsize = 0;
1428 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_REINT_UNPACK))
1429 GOTO(out_shrink, rc = err_serious(-EFAULT));
1431 rc = mdt_reint_unpack(info, op);
1433 CERROR("Can't unpack reint, rc %d\n", rc);
1434 GOTO(out_shrink, rc = err_serious(rc));
1437 rc = mdt_init_ucred_reint(info);
1439 GOTO(out_shrink, rc);
1441 rc = mdt_fix_attr_ucred(info, op);
1443 GOTO(out_ucred, rc = err_serious(rc));
1446 if (mdt_check_resent(info, mdt_reconstruct, lhc)) {
1447 rc = lustre_msg_get_status(mdt_info_req(info)->rq_repmsg);
1448 GOTO(out_ucred, rc);
1451 rc = mdt_reint_rec(info, lhc);
1454 mdt_exit_ucred(info);
1457 mdt_shrink_reply(info);
1461 static long mdt_reint_opcode(struct mdt_thread_info *info,
1462 const struct req_format **fmt)
1467 opc = err_serious(-EFAULT);
1468 ptr = req_capsule_client_get(&info->mti_pill, &RMF_REINT_OPC);
1471 DEBUG_REQ(D_INODE, mdt_info_req(info), "reint opt = %ld", opc);
1472 if (opc < REINT_MAX && fmt[opc] != NULL)
1473 req_capsule_extend(&info->mti_pill, fmt[opc]);
1475 CERROR("Unsupported opc: %ld\n", opc);
1476 opc = err_serious(opc);
1482 static int mdt_reint(struct mdt_thread_info *info)
1487 static const struct req_format *reint_fmts[REINT_MAX] = {
1488 [REINT_SETATTR] = &RQF_MDS_REINT_SETATTR,
1489 [REINT_CREATE] = &RQF_MDS_REINT_CREATE,
1490 [REINT_LINK] = &RQF_MDS_REINT_LINK,
1491 [REINT_UNLINK] = &RQF_MDS_REINT_UNLINK,
1492 [REINT_RENAME] = &RQF_MDS_REINT_RENAME,
1493 [REINT_OPEN] = &RQF_MDS_REINT_OPEN
1498 opc = mdt_reint_opcode(info, reint_fmts);
1501 * No lock possible here from client to pass it to reint code
1504 rc = mdt_reint_internal(info, NULL, opc);
1509 info->mti_fail_id = OBD_FAIL_MDS_REINT_NET_REP;
1513 /* TODO these two methods not available now. */
1515 /* this should sync the whole device */
1516 static int mdt_device_sync(struct mdt_thread_info *info)
1521 /* this should sync this object */
1522 static int mdt_object_sync(struct mdt_thread_info *info)
1527 static int mdt_sync(struct mdt_thread_info *info)
1529 struct req_capsule *pill = &info->mti_pill;
1530 struct mdt_body *body;
1534 /* The fid may be zero, so we req_capsule_set manually */
1535 req_capsule_set(pill, &RQF_MDS_SYNC);
1537 body = req_capsule_client_get(pill, &RMF_MDT_BODY);
1539 RETURN(err_serious(-EINVAL));
1541 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_SYNC_PACK))
1542 RETURN(err_serious(-ENOMEM));
1544 if (fid_seq(&body->fid1) == 0) {
1545 /* sync the whole device */
1546 rc = req_capsule_pack(pill);
1548 rc = mdt_device_sync(info);
1550 rc = err_serious(rc);
1552 /* sync an object */
1553 rc = mdt_unpack_req_pack_rep(info, HABEO_CORPUS|HABEO_REFERO);
1555 rc = mdt_object_sync(info);
1557 struct md_object *next;
1558 const struct lu_fid *fid;
1559 struct lu_attr *la = &info->mti_attr.ma_attr;
1561 next = mdt_object_child(info->mti_object);
1562 info->mti_attr.ma_need = MA_INODE;
1563 info->mti_attr.ma_valid = 0;
1564 rc = mo_attr_get(info->mti_env, next,
1567 body = req_capsule_server_get(pill,
1569 fid = mdt_object_fid(info->mti_object);
1570 mdt_pack_attr2body(info, body, la, fid);
1574 rc = err_serious(rc);
1579 static int mdt_quotacheck_handle(struct mdt_thread_info *info)
1581 return err_serious(-EOPNOTSUPP);
1584 static int mdt_quotactl_handle(struct mdt_thread_info *info)
1586 return err_serious(-EOPNOTSUPP);
1590 * OBD PING and other handlers.
1592 static int mdt_obd_ping(struct mdt_thread_info *info)
1596 rc = target_handle_ping(mdt_info_req(info));
1598 rc = err_serious(rc);
1602 static int mdt_obd_log_cancel(struct mdt_thread_info *info)
1604 return err_serious(-EOPNOTSUPP);
1607 static int mdt_obd_qc_callback(struct mdt_thread_info *info)
1609 return err_serious(-EOPNOTSUPP);
1616 static struct ldlm_callback_suite cbs = {
1617 .lcs_completion = ldlm_server_completion_ast,
1618 .lcs_blocking = ldlm_server_blocking_ast,
1622 static int mdt_enqueue(struct mdt_thread_info *info)
1624 struct ptlrpc_request *req;
1629 * info->mti_dlm_req already contains swapped and (if necessary)
1630 * converted dlm request.
1632 LASSERT(info->mti_dlm_req != NULL);
1634 if (OBD_FAIL_CHECK(OBD_FAIL_LDLM_ENQUEUE)) {
1635 info->mti_fail_id = OBD_FAIL_LDLM_ENQUEUE;
1639 req = mdt_info_req(info);
1642 * Lock without inodebits makes no sense and will oops later in
1643 * ldlm. Let's check it now to see if we have wrong lock from client or
1644 * bits get corrupted somewhere in mdt_intent_policy().
1646 req_bits = info->mti_dlm_req->lock_desc.l_policy_data.l_inodebits.bits;
1647 /* This is disabled because we need to support liblustre flock.
1648 * LASSERT(req_bits != 0);
1651 rc = ldlm_handle_enqueue0(info->mti_mdt->mdt_namespace,
1652 req, info->mti_dlm_req, &cbs);
1653 info->mti_fail_id = OBD_FAIL_LDLM_REPLY;
1654 return rc ? err_serious(rc) : req->rq_status;
1657 static int mdt_convert(struct mdt_thread_info *info)
1660 struct ptlrpc_request *req;
1662 LASSERT(info->mti_dlm_req);
1663 req = mdt_info_req(info);
1664 rc = ldlm_handle_convert0(req, info->mti_dlm_req);
1665 return rc ? err_serious(rc) : req->rq_status;
1668 static int mdt_bl_callback(struct mdt_thread_info *info)
1670 CERROR("bl callbacks should not happen on MDS\n");
1672 return err_serious(-EOPNOTSUPP);
1675 static int mdt_cp_callback(struct mdt_thread_info *info)
1677 CERROR("cp callbacks should not happen on MDS\n");
1679 return err_serious(-EOPNOTSUPP);
1683 * sec context handlers
1685 static int mdt_sec_ctx_handle(struct mdt_thread_info *info)
1689 rc = mdt_handle_idmap(info);
1692 struct ptlrpc_request *req = mdt_info_req(info);
1695 opc = lustre_msg_get_opc(req->rq_reqmsg);
1696 if (opc == SEC_CTX_INIT || opc == SEC_CTX_INIT_CONT)
1697 sptlrpc_svc_ctx_invalidate(req);
1703 static struct mdt_object *mdt_obj(struct lu_object *o)
1705 LASSERT(lu_device_is_mdt(o->lo_dev));
1706 return container_of0(o, struct mdt_object, mot_obj.mo_lu);
1709 struct mdt_object *mdt_object_find(const struct lu_env *env,
1710 struct mdt_device *d,
1711 const struct lu_fid *f)
1713 struct lu_object *o;
1714 struct mdt_object *m;
1717 o = lu_object_find(env, d->mdt_md_dev.md_lu_dev.ld_site, f);
1718 if (unlikely(IS_ERR(o)))
1719 m = (struct mdt_object *)o;
1725 int mdt_object_lock(struct mdt_thread_info *info, struct mdt_object *o,
1726 struct mdt_lock_handle *lh, __u64 ibits, int locality)
1728 struct ldlm_namespace *ns = info->mti_mdt->mdt_namespace;
1729 ldlm_policy_data_t *policy = &info->mti_policy;
1730 struct ldlm_res_id *res_id = &info->mti_res_id;
1734 LASSERT(!lustre_handle_is_used(&lh->mlh_reg_lh));
1735 LASSERT(!lustre_handle_is_used(&lh->mlh_pdo_lh));
1736 LASSERT(lh->mlh_reg_mode != LCK_MINMODE);
1737 LASSERT(lh->mlh_type != MDT_NUL_LOCK);
1739 if (mdt_object_exists(o) < 0) {
1740 if (locality == MDT_CROSS_LOCK) {
1741 /* cross-ref object fix */
1742 ibits &= ~MDS_INODELOCK_UPDATE;
1743 ibits |= MDS_INODELOCK_LOOKUP;
1745 LASSERT(!(ibits & MDS_INODELOCK_UPDATE));
1746 LASSERT(ibits & MDS_INODELOCK_LOOKUP);
1748 /* No PDO lock on remote object */
1749 LASSERT(lh->mlh_type != MDT_PDO_LOCK);
1752 memset(policy, 0, sizeof(*policy));
1753 fid_build_reg_res_name(mdt_object_fid(o), res_id);
1756 * Take PDO lock on whole directory and build correct @res_id for lock
1757 * on part of directory.
1759 if (lh->mlh_pdo_hash != 0) {
1760 LASSERT(lh->mlh_type == MDT_PDO_LOCK);
1761 mdt_lock_pdo_mode(info, o, lh);
1762 if (lh->mlh_pdo_mode != LCK_NL) {
1764 * Do not use LDLM_FL_LOCAL_ONLY for parallel lock, it
1765 * is never going to be sent to client and we do not
1766 * want it slowed down due to possible cancels.
1768 policy->l_inodebits.bits = MDS_INODELOCK_UPDATE;
1769 rc = mdt_fid_lock(ns, &lh->mlh_pdo_lh, lh->mlh_pdo_mode,
1770 policy, res_id, LDLM_FL_ATOMIC_CB);
1776 * Finish res_id initializing by name hash marking patr of
1777 * directory which is taking modification.
1779 res_id->name[LUSTRE_RES_ID_HSH_OFF] = lh->mlh_pdo_hash;
1782 policy->l_inodebits.bits = ibits;
1785 * Use LDLM_FL_LOCAL_ONLY for this lock. We do not know yet if it is
1786 * going to be sent to client. If it is - mdt_intent_policy() path will
1787 * fix it up and turns FL_LOCAL flag off.
1789 rc = mdt_fid_lock(ns, &lh->mlh_reg_lh, lh->mlh_reg_mode, policy,
1790 res_id, LDLM_FL_LOCAL_ONLY | LDLM_FL_ATOMIC_CB);
1795 if (lh->mlh_type == MDT_PDO_LOCK) {
1796 /* check for exists after object is locked */
1797 if (mdt_object_exists(o) == 0) {
1798 /* Non-existent object shouldn't have PDO lock */
1801 /* Non-dir object shouldn't have PDO lock */
1802 LASSERT(S_ISDIR(lu_object_attr(&o->mot_obj.mo_lu)));
1807 mdt_object_unlock(info, o, lh, 1);
1814 * Just call ldlm_lock_decref() if decref, else we only call ptlrpc_save_lock()
1815 * to save this lock in req. when transaction committed, req will be released,
1816 * and lock will, too.
1818 void mdt_object_unlock(struct mdt_thread_info *info, struct mdt_object *o,
1819 struct mdt_lock_handle *lh, int decref)
1821 struct ptlrpc_request *req = mdt_info_req(info);
1824 if (lustre_handle_is_used(&lh->mlh_pdo_lh)) {
1825 /* Do not save PDO locks to request, just decref. */
1826 mdt_fid_unlock(&lh->mlh_pdo_lh,
1828 lh->mlh_pdo_lh.cookie = 0ull;
1831 if (lustre_handle_is_used(&lh->mlh_reg_lh)) {
1833 mdt_fid_unlock(&lh->mlh_reg_lh,
1836 ptlrpc_save_lock(req, &lh->mlh_reg_lh,
1839 lh->mlh_reg_lh.cookie = 0ull;
1845 struct mdt_object *mdt_object_find_lock(struct mdt_thread_info *info,
1846 const struct lu_fid *f,
1847 struct mdt_lock_handle *lh,
1850 struct mdt_object *o;
1852 o = mdt_object_find(info->mti_env, info->mti_mdt, f);
1856 rc = mdt_object_lock(info, o, lh, ibits,
1859 mdt_object_put(info->mti_env, o);
1866 void mdt_object_unlock_put(struct mdt_thread_info * info,
1867 struct mdt_object * o,
1868 struct mdt_lock_handle *lh,
1871 mdt_object_unlock(info, o, lh, decref);
1872 mdt_object_put(info->mti_env, o);
1875 static struct mdt_handler *mdt_handler_find(__u32 opc,
1876 struct mdt_opc_slice *supported)
1878 struct mdt_opc_slice *s;
1879 struct mdt_handler *h;
1882 for (s = supported; s->mos_hs != NULL; s++) {
1883 if (s->mos_opc_start <= opc && opc < s->mos_opc_end) {
1884 h = s->mos_hs + (opc - s->mos_opc_start);
1885 if (likely(h->mh_opc != 0))
1886 LASSERT(h->mh_opc == opc);
1888 h = NULL; /* unsupported opc */
1895 static int mdt_lock_resname_compat(struct mdt_device *m,
1896 struct ldlm_request *req)
1898 /* XXX something... later. */
1902 static int mdt_lock_reply_compat(struct mdt_device *m, struct ldlm_reply *rep)
1904 /* XXX something... later. */
1909 * Generic code handling requests that have struct mdt_body passed in:
1911 * - extract mdt_body from request and save it in @info, if present;
1913 * - create lu_object, corresponding to the fid in mdt_body, and save it in
1916 * - if HABEO_CORPUS flag is set for this request type check whether object
1917 * actually exists on storage (lu_object_exists()).
1920 static int mdt_body_unpack(struct mdt_thread_info *info, __u32 flags)
1922 const struct mdt_body *body;
1923 struct mdt_object *obj;
1924 const struct lu_env *env;
1925 struct req_capsule *pill;
1928 env = info->mti_env;
1929 pill = &info->mti_pill;
1931 body = info->mti_body = req_capsule_client_get(pill, &RMF_MDT_BODY);
1935 if (!fid_is_sane(&body->fid1)) {
1936 CERROR("Invalid fid: "DFID"\n", PFID(&body->fid1));
1941 * Do not get size or any capa fields before we check that request
1942 * contains capa actually. There are some requests which do not, for
1943 * instance MDS_IS_SUBDIR.
1945 if (req_capsule_has_field(pill, &RMF_CAPA1, RCL_CLIENT) &&
1946 req_capsule_get_size(pill, &RMF_CAPA1, RCL_CLIENT))
1947 mdt_set_capainfo(info, 0, &body->fid1,
1948 req_capsule_client_get(pill, &RMF_CAPA1));
1950 obj = mdt_object_find(env, info->mti_mdt, &body->fid1);
1952 if ((flags & HABEO_CORPUS) &&
1953 !mdt_object_exists(obj)) {
1954 mdt_object_put(env, obj);
1955 /* for capability renew ENOENT will be handled in
1957 if (body->valid & OBD_MD_FLOSSCAPA)
1962 info->mti_object = obj;
1971 static int mdt_unpack_req_pack_rep(struct mdt_thread_info *info, __u32 flags)
1973 struct req_capsule *pill;
1977 pill = &info->mti_pill;
1979 if (req_capsule_has_field(pill, &RMF_MDT_BODY, RCL_CLIENT))
1980 rc = mdt_body_unpack(info, flags);
1984 if (rc == 0 && (flags & HABEO_REFERO)) {
1985 struct mdt_device *mdt = info->mti_mdt;
1988 if (req_capsule_has_field(pill, &RMF_MDT_MD, RCL_SERVER))
1989 req_capsule_set_size(pill, &RMF_MDT_MD, RCL_SERVER,
1990 mdt->mdt_max_mdsize);
1991 if (req_capsule_has_field(pill, &RMF_LOGCOOKIES, RCL_SERVER))
1992 req_capsule_set_size(pill, &RMF_LOGCOOKIES, RCL_SERVER,
1993 mdt->mdt_max_cookiesize);
1995 rc = req_capsule_pack(pill);
2000 static int mdt_init_capa_ctxt(const struct lu_env *env, struct mdt_device *m)
2002 struct md_device *next = m->mdt_child;
2004 return next->md_ops->mdo_init_capa_ctxt(env, next,
2005 m->mdt_opts.mo_mds_capa,
2006 m->mdt_capa_timeout,
2012 * Invoke handler for this request opc. Also do necessary preprocessing
2013 * (according to handler ->mh_flags), and post-processing (setting of
2014 * ->last_{xid,committed}).
2016 static int mdt_req_handle(struct mdt_thread_info *info,
2017 struct mdt_handler *h, struct ptlrpc_request *req)
2019 int rc, serious = 0;
2024 LASSERT(h->mh_act != NULL);
2025 LASSERT(h->mh_opc == lustre_msg_get_opc(req->rq_reqmsg));
2026 LASSERT(current->journal_info == NULL);
2029 * Mask out OBD_FAIL_ONCE, because that will stop
2030 * correct handling of failed req later in ldlm due to doing
2031 * obd_fail_loc |= OBD_FAIL_ONCE without actually
2032 * correct actions like it is done in target_send_reply_msg().
2034 if (h->mh_fail_id != 0) {
2036 * Set to info->mti_fail_id to handler fail_id, it will be used
2037 * later, and better than use default fail_id.
2039 if (OBD_FAIL_CHECK_RESET(h->mh_fail_id && OBD_FAIL_MASK_LOC,
2040 h->mh_fail_id & ~OBD_FAILED)) {
2041 info->mti_fail_id = h->mh_fail_id;
2047 flags = h->mh_flags;
2048 LASSERT(ergo(flags & (HABEO_CORPUS|HABEO_REFERO), h->mh_fmt != NULL));
2050 if (h->mh_fmt != NULL) {
2051 req_capsule_set(&info->mti_pill, h->mh_fmt);
2052 rc = mdt_unpack_req_pack_rep(info, flags);
2055 if (rc == 0 && flags & MUTABOR &&
2056 req->rq_export->exp_connect_flags & OBD_CONNECT_RDONLY)
2057 /* should it be rq_status? */
2060 if (rc == 0 && flags & HABEO_CLAVIS) {
2061 struct ldlm_request *dlm_req;
2063 LASSERT(h->mh_fmt != NULL);
2065 dlm_req = req_capsule_client_get(&info->mti_pill, &RMF_DLM_REQ);
2066 if (dlm_req != NULL) {
2067 if (info->mti_mdt->mdt_opts.mo_compat_resname)
2068 rc = mdt_lock_resname_compat(info->mti_mdt,
2070 info->mti_dlm_req = dlm_req;
2072 CERROR("Can't unpack dlm request\n");
2077 /* capability setting changed via /proc, needs reinitialize ctxt */
2078 if (info->mti_mdt && info->mti_mdt->mdt_capa_conf) {
2079 mdt_init_capa_ctxt(info->mti_env, info->mti_mdt);
2080 info->mti_mdt->mdt_capa_conf = 0;
2083 if (likely(rc == 0)) {
2085 * Process request, there can be two types of rc:
2086 * 1) errors with msg unpack/pack, other failures outside the
2087 * operation itself. This is counted as serious errors;
2088 * 2) errors during fs operation, should be placed in rq_status
2091 rc = h->mh_act(info);
2092 serious = is_serious(rc);
2093 rc = clear_serious(rc);
2097 req->rq_status = rc;
2100 * ELDLM_* codes which > 0 should be in rq_status only as well as
2101 * all non-serious errors.
2103 if (rc > 0 || !serious)
2106 LASSERT(current->journal_info == NULL);
2108 if (rc == 0 && (flags & HABEO_CLAVIS) &&
2109 info->mti_mdt->mdt_opts.mo_compat_resname) {
2110 struct ldlm_reply *dlmrep;
2112 dlmrep = req_capsule_server_get(&info->mti_pill, &RMF_DLM_REP);
2114 rc = mdt_lock_reply_compat(info->mti_mdt, dlmrep);
2117 /* If we're DISCONNECTing, the mdt_export_data is already freed */
2118 if (likely(rc == 0 && h->mh_opc != MDS_DISCONNECT))
2119 target_committed_to_req(req);
2121 if (unlikely((lustre_msg_get_flags(req->rq_reqmsg) & MSG_REPLAY) &&
2122 lustre_msg_get_transno(req->rq_reqmsg) == 0)) {
2123 DEBUG_REQ(D_ERROR, req, "transno is 0 during REPLAY");
2130 void mdt_lock_handle_init(struct mdt_lock_handle *lh)
2132 lh->mlh_type = MDT_NUL_LOCK;
2133 lh->mlh_reg_lh.cookie = 0ull;
2134 lh->mlh_reg_mode = LCK_MINMODE;
2135 lh->mlh_pdo_lh.cookie = 0ull;
2136 lh->mlh_pdo_mode = LCK_MINMODE;
2139 void mdt_lock_handle_fini(struct mdt_lock_handle *lh)
2141 LASSERT(!lustre_handle_is_used(&lh->mlh_reg_lh));
2142 LASSERT(!lustre_handle_is_used(&lh->mlh_pdo_lh));
2146 * Initialize fields of struct mdt_thread_info. Other fields are left in
2147 * uninitialized state, because it's too expensive to zero out whole
2148 * mdt_thread_info (> 1K) on each request arrival.
2150 static void mdt_thread_info_init(struct ptlrpc_request *req,
2151 struct mdt_thread_info *info)
2154 struct md_capainfo *ci;
2156 info->mti_rep_buf_nr = ARRAY_SIZE(info->mti_rep_buf_size);
2157 for (i = 0; i < ARRAY_SIZE(info->mti_rep_buf_size); i++)
2158 info->mti_rep_buf_size[i] = -1;
2159 req_capsule_init(&info->mti_pill, req, RCL_SERVER,
2160 info->mti_rep_buf_size);
2163 for (i = 0; i < ARRAY_SIZE(info->mti_lh); i++)
2164 mdt_lock_handle_init(&info->mti_lh[i]);
2166 /* mdt device: it can be NULL while CONNECT */
2167 if (req->rq_export) {
2168 info->mti_mdt = mdt_dev(req->rq_export->exp_obd->obd_lu_dev);
2169 info->mti_exp = req->rq_export;
2171 info->mti_mdt = NULL;
2172 info->mti_env = req->rq_svc_thread->t_env;
2173 ci = md_capainfo(info->mti_env);
2174 memset(ci, 0, sizeof *ci);
2176 info->mti_fail_id = OBD_FAIL_MDS_ALL_REPLY_NET;
2177 info->mti_transno = lustre_msg_get_transno(req->rq_reqmsg);
2179 memset(&info->mti_attr, 0, sizeof(info->mti_attr));
2180 info->mti_body = NULL;
2181 info->mti_object = NULL;
2182 info->mti_dlm_req = NULL;
2183 info->mti_has_trans = 0;
2184 info->mti_no_need_trans = 0;
2185 info->mti_cross_ref = 0;
2186 info->mti_opdata = 0;
2188 /* To not check for split by default. */
2189 info->mti_spec.sp_ck_split = 0;
2192 static void mdt_thread_info_fini(struct mdt_thread_info *info)
2196 req_capsule_fini(&info->mti_pill);
2197 if (info->mti_object != NULL) {
2198 mdt_object_put(info->mti_env, info->mti_object);
2199 info->mti_object = NULL;
2201 for (i = 0; i < ARRAY_SIZE(info->mti_lh); i++)
2202 mdt_lock_handle_fini(&info->mti_lh[i]);
2203 info->mti_env = NULL;
2207 extern int mds_filter_recovery_request(struct ptlrpc_request *req,
2208 struct obd_device *obd, int *process);
2210 * Handle recovery. Return:
2211 * +1: continue request processing;
2212 * -ve: abort immediately with the given error code;
2213 * 0: send reply with error code in req->rq_status;
2215 static int mdt_recovery(struct mdt_thread_info *info)
2217 struct ptlrpc_request *req = mdt_info_req(info);
2219 struct obd_device *obd;
2223 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
2226 case SEC_CTX_INIT_CONT:
2232 rc = mdt_handle_idmap(info);
2241 if (unlikely(req->rq_export == NULL)) {
2242 CERROR("operation %d on unconnected MDS from %s\n",
2243 lustre_msg_get_opc(req->rq_reqmsg),
2244 libcfs_id2str(req->rq_peer));
2245 /* FIXME: For CMD cleanup, when mds_B stop, the req from
2246 * mds_A will get -ENOTCONN(especially for ping req),
2247 * which will cause that mds_A deactive timeout, then when
2248 * mds_A cleanup, the cleanup process will be suspended since
2249 * deactive timeout is not zero.
2251 req->rq_status = -ENOTCONN;
2252 target_send_reply(req, -ENOTCONN, info->mti_fail_id);
2256 /* sanity check: if the xid matches, the request must be marked as a
2257 * resent or replayed */
2258 if (req_xid_is_last(req)) {
2259 if (!(lustre_msg_get_flags(req->rq_reqmsg) &
2260 (MSG_RESENT | MSG_REPLAY))) {
2261 DEBUG_REQ(D_WARNING, req, "rq_xid "LPU64" matches last_xid, "
2262 "expected REPLAY or RESENT flag (%x)", req->rq_xid,
2263 lustre_msg_get_flags(req->rq_reqmsg));
2265 req->rq_status = -ENOTCONN;
2270 /* else: note the opposite is not always true; a RESENT req after a
2271 * failover will usually not match the last_xid, since it was likely
2272 * never committed. A REPLAYed request will almost never match the
2273 * last xid, however it could for a committed, but still retained,
2276 obd = req->rq_export->exp_obd;
2278 /* Check for aborted recovery... */
2279 spin_lock_bh(&obd->obd_processing_task_lock);
2280 recovering = obd->obd_recovering;
2281 spin_unlock_bh(&obd->obd_processing_task_lock);
2282 if (unlikely(recovering)) {
2285 DEBUG_REQ(D_INFO, req, "Got new replay");
2286 rc = mds_filter_recovery_request(req, obd, &should_process);
2287 if (rc != 0 || !should_process)
2289 else if (should_process < 0) {
2290 req->rq_status = should_process;
2291 rc = ptlrpc_error(req);
2298 static int mdt_reply(struct ptlrpc_request *req, int rc,
2299 struct mdt_thread_info *info)
2304 if (req->rq_reply_state == NULL && rc == 0) {
2305 req->rq_status = rc;
2306 lustre_pack_reply(req, 1, NULL, NULL);
2309 target_send_reply(req, rc, info->mti_fail_id);
2314 extern int mds_msg_check_version(struct lustre_msg *msg);
2316 static int mdt_handle0(struct ptlrpc_request *req,
2317 struct mdt_thread_info *info,
2318 struct mdt_opc_slice *supported)
2320 struct mdt_handler *h;
2321 struct lustre_msg *msg;
2326 if (OBD_FAIL_CHECK_ORSET(OBD_FAIL_MDS_ALL_REQUEST_NET, OBD_FAIL_ONCE))
2329 LASSERT(current->journal_info == NULL);
2331 msg = req->rq_reqmsg;
2332 rc = mds_msg_check_version(msg);
2333 if (likely(rc == 0)) {
2334 rc = mdt_recovery(info);
2335 if (likely(rc == +1)) {
2336 h = mdt_handler_find(lustre_msg_get_opc(msg),
2338 if (likely(h != NULL)) {
2339 rc = mdt_req_handle(info, h, req);
2340 rc = mdt_reply(req, rc, info);
2342 CERROR("The unsupported opc: 0x%x\n", lustre_msg_get_opc(msg) );
2343 req->rq_status = -ENOTSUPP;
2344 rc = ptlrpc_error(req);
2349 CERROR(LUSTRE_MDT_NAME" drops mal-formed request\n");
2354 * MDT handler function called by ptlrpc service thread when request comes.
2356 * XXX common "target" functionality should be factored into separate module
2357 * shared by mdt, ost and stand-alone services like fld.
2359 static int mdt_handle_common(struct ptlrpc_request *req,
2360 struct mdt_opc_slice *supported)
2363 struct mdt_thread_info *info;
2367 env = req->rq_svc_thread->t_env;
2368 LASSERT(env != NULL);
2369 LASSERT(env->le_ses != NULL);
2370 LASSERT(env->le_ctx.lc_thread == req->rq_svc_thread);
2371 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
2372 LASSERT(info != NULL);
2374 mdt_thread_info_init(req, info);
2376 rc = mdt_handle0(req, info, supported);
2378 mdt_thread_info_fini(info);
2383 * This is called from recovery code as handler of _all_ RPC types, FLD and SEQ
2386 int mdt_recovery_handle(struct ptlrpc_request *req)
2391 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
2393 rc = mdt_handle_common(req, mdt_fld_handlers);
2396 rc = mdt_handle_common(req, mdt_seq_handlers);
2399 rc = mdt_handle_common(req, mdt_regular_handlers);
2406 static int mdt_regular_handle(struct ptlrpc_request *req)
2408 return mdt_handle_common(req, mdt_regular_handlers);
2411 static int mdt_readpage_handle(struct ptlrpc_request *req)
2413 return mdt_handle_common(req, mdt_readpage_handlers);
2416 static int mdt_xmds_handle(struct ptlrpc_request *req)
2418 return mdt_handle_common(req, mdt_xmds_handlers);
2421 static int mdt_mdsc_handle(struct ptlrpc_request *req)
2423 return mdt_handle_common(req, mdt_seq_handlers);
2426 static int mdt_mdss_handle(struct ptlrpc_request *req)
2428 return mdt_handle_common(req, mdt_seq_handlers);
2431 static int mdt_dtss_handle(struct ptlrpc_request *req)
2433 return mdt_handle_common(req, mdt_seq_handlers);
2436 static int mdt_fld_handle(struct ptlrpc_request *req)
2438 return mdt_handle_common(req, mdt_fld_handlers);
2454 static int mdt_intent_getattr(enum mdt_it_code opcode,
2455 struct mdt_thread_info *info,
2456 struct ldlm_lock **,
2458 static int mdt_intent_reint(enum mdt_it_code opcode,
2459 struct mdt_thread_info *info,
2460 struct ldlm_lock **,
2463 static struct mdt_it_flavor {
2464 const struct req_format *it_fmt;
2466 int (*it_act)(enum mdt_it_code ,
2467 struct mdt_thread_info *,
2468 struct ldlm_lock **,
2471 } mdt_it_flavor[] = {
2473 .it_fmt = &RQF_LDLM_INTENT,
2474 /*.it_flags = HABEO_REFERO,*/
2476 .it_act = mdt_intent_reint,
2477 .it_reint = REINT_OPEN
2480 .it_fmt = &RQF_LDLM_INTENT,
2481 .it_flags = MUTABOR,
2482 .it_act = mdt_intent_reint,
2483 .it_reint = REINT_OPEN
2486 .it_fmt = &RQF_LDLM_INTENT,
2487 .it_flags = MUTABOR,
2488 .it_act = mdt_intent_reint,
2489 .it_reint = REINT_CREATE
2491 [MDT_IT_GETATTR] = {
2492 .it_fmt = &RQF_LDLM_INTENT_GETATTR,
2493 .it_flags = HABEO_REFERO,
2494 .it_act = mdt_intent_getattr
2496 [MDT_IT_READDIR] = {
2502 .it_fmt = &RQF_LDLM_INTENT_GETATTR,
2503 .it_flags = HABEO_REFERO,
2504 .it_act = mdt_intent_getattr
2507 .it_fmt = &RQF_LDLM_INTENT_UNLINK,
2508 .it_flags = MUTABOR,
2510 .it_reint = REINT_UNLINK
2514 .it_flags = MUTABOR,
2517 [MDT_IT_GETXATTR] = {
2524 int mdt_intent_lock_replace(struct mdt_thread_info *info,
2525 struct ldlm_lock **lockp,
2526 struct ldlm_lock *new_lock,
2527 struct mdt_lock_handle *lh,
2530 struct ptlrpc_request *req = mdt_info_req(info);
2531 struct ldlm_lock *lock = *lockp;
2534 * Get new lock only for cases when possible resent did not find any
2537 if (new_lock == NULL)
2538 new_lock = ldlm_handle2lock(&lh->mlh_reg_lh);
2540 if (new_lock == NULL && (flags & LDLM_FL_INTENT_ONLY)) {
2541 lh->mlh_reg_lh.cookie = 0;
2545 LASSERTF(new_lock != NULL,
2546 "lockh "LPX64"\n", lh->mlh_reg_lh.cookie);
2549 * If we've already given this lock to a client once, then we should
2550 * have no readers or writers. Otherwise, we should have one reader
2551 * _or_ writer ref (which will be zeroed below) before returning the
2554 if (new_lock->l_export == req->rq_export) {
2555 LASSERT(new_lock->l_readers + new_lock->l_writers == 0);
2557 LASSERT(new_lock->l_export == NULL);
2558 LASSERT(new_lock->l_readers + new_lock->l_writers == 1);
2563 if (new_lock->l_export == req->rq_export) {
2565 * Already gave this to the client, which means that we
2566 * reconstructed a reply.
2568 LASSERT(lustre_msg_get_flags(req->rq_reqmsg) &
2570 lh->mlh_reg_lh.cookie = 0;
2571 RETURN(ELDLM_LOCK_REPLACED);
2574 /* This lock might already be given to the client by an resent req,
2575 * in this case we should return ELDLM_LOCK_ABORTED,
2576 * so we should check led_held_locks here, but it will affect
2577 * performance, FIXME
2579 /* Fixup the lock to be given to the client */
2580 lock_res_and_lock(new_lock);
2581 new_lock->l_readers = 0;
2582 new_lock->l_writers = 0;
2584 new_lock->l_export = class_export_get(req->rq_export);
2585 spin_lock(&req->rq_export->exp_ldlm_data.led_lock);
2586 list_add(&new_lock->l_export_chain,
2587 &new_lock->l_export->exp_ldlm_data.led_held_locks);
2588 spin_unlock(&req->rq_export->exp_ldlm_data.led_lock);
2590 new_lock->l_blocking_ast = lock->l_blocking_ast;
2591 new_lock->l_completion_ast = lock->l_completion_ast;
2592 new_lock->l_remote_handle = lock->l_remote_handle;
2593 new_lock->l_flags &= ~LDLM_FL_LOCAL;
2595 unlock_res_and_lock(new_lock);
2596 LDLM_LOCK_PUT(new_lock);
2597 lh->mlh_reg_lh.cookie = 0;
2599 RETURN(ELDLM_LOCK_REPLACED);
2602 static void mdt_intent_fixup_resent(struct mdt_thread_info *info,
2603 struct ldlm_lock *new_lock,
2604 struct ldlm_lock **old_lock,
2605 struct mdt_lock_handle *lh)
2607 struct ptlrpc_request *req = mdt_info_req(info);
2608 struct obd_export *exp = req->rq_export;
2609 struct lustre_handle remote_hdl;
2610 struct ldlm_request *dlmreq;
2611 struct list_head *iter;
2613 if (!(lustre_msg_get_flags(req->rq_reqmsg) & MSG_RESENT))
2616 dlmreq = req_capsule_client_get(&info->mti_pill, &RMF_DLM_REQ);
2617 remote_hdl = dlmreq->lock_handle[0];
2619 spin_lock(&exp->exp_ldlm_data.led_lock);
2620 list_for_each(iter, &exp->exp_ldlm_data.led_held_locks) {
2621 struct ldlm_lock *lock;
2622 lock = list_entry(iter, struct ldlm_lock, l_export_chain);
2623 if (lock == new_lock)
2625 if (lock->l_remote_handle.cookie == remote_hdl.cookie) {
2626 lh->mlh_reg_lh.cookie = lock->l_handle.h_cookie;
2627 lh->mlh_reg_mode = lock->l_granted_mode;
2629 LDLM_DEBUG(lock, "restoring lock cookie");
2630 DEBUG_REQ(D_DLMTRACE, req,
2631 "restoring lock cookie "LPX64,
2632 lh->mlh_reg_lh.cookie);
2634 *old_lock = LDLM_LOCK_GET(lock);
2635 spin_unlock(&exp->exp_ldlm_data.led_lock);
2639 spin_unlock(&exp->exp_ldlm_data.led_lock);
2642 * If the xid matches, then we know this is a resent request, and allow
2643 * it. (It's probably an OPEN, for which we don't send a lock.
2645 if (req_xid_is_last(req))
2649 * This remote handle isn't enqueued, so we never received or processed
2650 * this request. Clear MSG_RESENT, because it can be handled like any
2651 * normal request now.
2653 lustre_msg_clear_flags(req->rq_reqmsg, MSG_RESENT);
2655 DEBUG_REQ(D_DLMTRACE, req, "no existing lock with rhandle "LPX64,
2659 static int mdt_intent_getattr(enum mdt_it_code opcode,
2660 struct mdt_thread_info *info,
2661 struct ldlm_lock **lockp,
2664 struct mdt_lock_handle *lhc = &info->mti_lh[MDT_LH_RMT];
2665 struct ldlm_lock *new_lock = NULL;
2667 struct ldlm_reply *ldlm_rep;
2668 struct ptlrpc_request *req;
2669 struct mdt_body *reqbody;
2670 struct mdt_body *repbody;
2674 reqbody = req_capsule_client_get(&info->mti_pill, &RMF_MDT_BODY);
2677 repbody = req_capsule_server_get(&info->mti_pill, &RMF_MDT_BODY);
2680 info->mti_spec.sp_ck_split = !!(reqbody->valid & OBD_MD_FLCKSPLIT);
2681 info->mti_cross_ref = !!(reqbody->valid & OBD_MD_FLCROSSREF);
2682 repbody->eadatasize = 0;
2683 repbody->aclsize = 0;
2687 child_bits = MDS_INODELOCK_LOOKUP;
2689 case MDT_IT_GETATTR:
2690 child_bits = MDS_INODELOCK_LOOKUP | MDS_INODELOCK_UPDATE;
2693 CERROR("Unhandled till now");
2694 GOTO(out, rc = -EINVAL);
2697 rc = mdt_init_ucred(info, reqbody);
2701 req = info->mti_pill.rc_req;
2702 ldlm_rep = req_capsule_server_get(&info->mti_pill, &RMF_DLM_REP);
2703 mdt_set_disposition(info, ldlm_rep, DISP_IT_EXECD);
2705 /* Get lock from request for possible resent case. */
2706 mdt_intent_fixup_resent(info, *lockp, &new_lock, lhc);
2708 ldlm_rep->lock_policy_res2 =
2709 mdt_getattr_name_lock(info, lhc, child_bits, ldlm_rep);
2711 if (mdt_get_disposition(ldlm_rep, DISP_LOOKUP_NEG))
2712 ldlm_rep->lock_policy_res2 = 0;
2713 if (!mdt_get_disposition(ldlm_rep, DISP_LOOKUP_POS) ||
2714 ldlm_rep->lock_policy_res2) {
2715 lhc->mlh_reg_lh.cookie = 0ull;
2716 GOTO(out_ucred, rc = ELDLM_LOCK_ABORTED);
2719 rc = mdt_intent_lock_replace(info, lockp, new_lock, lhc, flags);
2722 mdt_exit_ucred(info);
2724 mdt_shrink_reply(info);
2728 static int mdt_intent_reint(enum mdt_it_code opcode,
2729 struct mdt_thread_info *info,
2730 struct ldlm_lock **lockp,
2733 struct mdt_lock_handle *lhc = &info->mti_lh[MDT_LH_RMT];
2734 struct ldlm_reply *rep = NULL;
2738 static const struct req_format *intent_fmts[REINT_MAX] = {
2739 [REINT_CREATE] = &RQF_LDLM_INTENT_CREATE,
2740 [REINT_OPEN] = &RQF_LDLM_INTENT_OPEN
2745 opc = mdt_reint_opcode(info, intent_fmts);
2747 GOTO(out, rc = opc);
2749 if (mdt_it_flavor[opcode].it_reint != opc) {
2750 CERROR("Reint code %ld doesn't match intent: %d\n",
2752 GOTO(out, rc = err_serious(-EPROTO));
2755 /* Get lock from request for possible resent case. */
2756 mdt_intent_fixup_resent(info, *lockp, NULL, lhc);
2758 rc = mdt_reint_internal(info, lhc, opc);
2760 /* Check whether the reply has been packed successfully. */
2761 if (mdt_info_req(info)->rq_repmsg != NULL)
2762 rep = req_capsule_server_get(&info->mti_pill, &RMF_DLM_REP);
2764 GOTO(out, rc = err_serious(-EFAULT));
2766 /* MDC expects this in any case */
2768 mdt_set_disposition(info, rep, DISP_LOOKUP_EXECD);
2770 /* Cross-ref case, the lock should be returned to the client */
2771 if (rc == -EREMOTE) {
2772 LASSERT(lustre_handle_is_used(&lhc->mlh_reg_lh));
2773 rep->lock_policy_res2 = 0;
2774 rc = mdt_intent_lock_replace(info, lockp, NULL, lhc, flags);
2777 rep->lock_policy_res2 = clear_serious(rc);
2779 lhc->mlh_reg_lh.cookie = 0ull;
2780 rc = ELDLM_LOCK_ABORTED;
2786 static int mdt_intent_code(long itcode)
2794 case IT_OPEN|IT_CREAT:
2801 rc = MDT_IT_READDIR;
2804 rc = MDT_IT_GETATTR;
2816 rc = MDT_IT_GETXATTR;
2819 CERROR("Unknown intent opcode: %ld\n", itcode);
2826 static int mdt_intent_opc(long itopc, struct mdt_thread_info *info,
2827 struct ldlm_lock **lockp, int flags)
2829 struct req_capsule *pill;
2830 struct mdt_it_flavor *flv;
2835 opc = mdt_intent_code(itopc);
2839 pill = &info->mti_pill;
2840 flv = &mdt_it_flavor[opc];
2842 if (flv->it_fmt != NULL)
2843 req_capsule_extend(pill, flv->it_fmt);
2845 rc = mdt_unpack_req_pack_rep(info, flv->it_flags);
2847 struct ptlrpc_request *req = mdt_info_req(info);
2848 if (flv->it_flags & MUTABOR &&
2849 req->rq_export->exp_connect_flags & OBD_CONNECT_RDONLY)
2852 if (rc == 0 && flv->it_act != NULL) {
2853 /* execute policy */
2854 rc = flv->it_act(opc, info, lockp, flags);
2860 static int mdt_intent_policy(struct ldlm_namespace *ns,
2861 struct ldlm_lock **lockp, void *req_cookie,
2862 ldlm_mode_t mode, int flags, void *data)
2864 struct mdt_thread_info *info;
2865 struct ptlrpc_request *req = req_cookie;
2866 struct ldlm_intent *it;
2867 struct req_capsule *pill;
2872 LASSERT(req != NULL);
2874 info = lu_context_key_get(&req->rq_svc_thread->t_env->le_ctx,
2876 LASSERT(info != NULL);
2877 pill = &info->mti_pill;
2878 LASSERT(pill->rc_req == req);
2880 if (req->rq_reqmsg->lm_bufcount > DLM_INTENT_IT_OFF) {
2881 req_capsule_extend(pill, &RQF_LDLM_INTENT);
2882 it = req_capsule_client_get(pill, &RMF_LDLM_INTENT);
2884 const struct ldlm_request *dlmreq;
2887 struct ldlm_lock *lock = *lockp;
2889 LDLM_DEBUG(lock, "intent policy opc: %s\n",
2890 ldlm_it2str(it->opc));
2893 rc = mdt_intent_opc(it->opc, info, lockp, flags);
2898 * Lock without inodebits makes no sense and will oops
2899 * later in ldlm. Let's check it now to see if we have
2900 * wrong lock from client or bits get corrupted
2901 * somewhere in mdt_intent_opc().
2903 dlmreq = info->mti_dlm_req;
2904 req_bits = dlmreq->lock_desc.l_policy_data.l_inodebits.bits;
2905 LASSERT(req_bits != 0);
2908 rc = err_serious(-EFAULT);
2910 /* No intent was provided */
2911 LASSERT(pill->rc_fmt == &RQF_LDLM_ENQUEUE);
2912 rc = req_capsule_pack(pill);
2914 rc = err_serious(rc);
2922 static void mdt_seq_adjust(const struct lu_env *env,
2923 struct mdt_device *m, int lost)
2925 struct lu_site *ls = m->mdt_md_dev.md_lu_dev.ld_site;
2926 struct lu_range out;
2929 LASSERT(ls && ls->ls_server_seq);
2931 /* get extra seq from seq_server, moving it's range up */
2932 while (lost-- > 0) {
2933 seq_server_alloc_meta(ls->ls_server_seq, NULL, &out, env);
2938 static int mdt_seq_fini(const struct lu_env *env,
2939 struct mdt_device *m)
2941 struct lu_site *ls = m->mdt_md_dev.md_lu_dev.ld_site;
2944 if (ls && ls->ls_server_seq) {
2945 seq_server_fini(ls->ls_server_seq, env);
2946 OBD_FREE_PTR(ls->ls_server_seq);
2947 ls->ls_server_seq = NULL;
2950 if (ls && ls->ls_control_seq) {
2951 seq_server_fini(ls->ls_control_seq, env);
2952 OBD_FREE_PTR(ls->ls_control_seq);
2953 ls->ls_control_seq = NULL;
2956 if (ls && ls->ls_client_seq) {
2957 seq_client_fini(ls->ls_client_seq);
2958 OBD_FREE_PTR(ls->ls_client_seq);
2959 ls->ls_client_seq = NULL;
2965 static int mdt_seq_init(const struct lu_env *env,
2967 struct mdt_device *m)
2974 ls = m->mdt_md_dev.md_lu_dev.ld_site;
2977 * This is sequence-controller node. Init seq-controller server on local
2980 if (ls->ls_node_id == 0) {
2981 LASSERT(ls->ls_control_seq == NULL);
2983 OBD_ALLOC_PTR(ls->ls_control_seq);
2984 if (ls->ls_control_seq == NULL)
2987 rc = seq_server_init(ls->ls_control_seq,
2988 m->mdt_bottom, uuid,
2989 LUSTRE_SEQ_CONTROLLER,
2993 GOTO(out_seq_fini, rc);
2995 OBD_ALLOC_PTR(ls->ls_client_seq);
2996 if (ls->ls_client_seq == NULL)
2997 GOTO(out_seq_fini, rc = -ENOMEM);
2999 OBD_ALLOC(prefix, MAX_OBD_NAME + 5);
3000 if (prefix == NULL) {
3001 OBD_FREE_PTR(ls->ls_client_seq);
3002 GOTO(out_seq_fini, rc = -ENOMEM);
3005 snprintf(prefix, MAX_OBD_NAME + 5, "ctl-%s",
3009 * Init seq-controller client after seq-controller server is
3010 * ready. Pass ls->ls_control_seq to it for direct talking.
3012 rc = seq_client_init(ls->ls_client_seq, NULL,
3013 LUSTRE_SEQ_METADATA, prefix,
3014 ls->ls_control_seq);
3015 OBD_FREE(prefix, MAX_OBD_NAME + 5);
3018 GOTO(out_seq_fini, rc);
3021 /* Init seq-server on local MDT */
3022 LASSERT(ls->ls_server_seq == NULL);
3024 OBD_ALLOC_PTR(ls->ls_server_seq);
3025 if (ls->ls_server_seq == NULL)
3026 GOTO(out_seq_fini, rc = -ENOMEM);
3028 rc = seq_server_init(ls->ls_server_seq,
3029 m->mdt_bottom, uuid,
3033 GOTO(out_seq_fini, rc = -ENOMEM);
3035 /* Assign seq-controller client to local seq-server. */
3036 if (ls->ls_node_id == 0) {
3037 LASSERT(ls->ls_client_seq != NULL);
3039 rc = seq_server_set_cli(ls->ls_server_seq,
3047 mdt_seq_fini(env, m);
3052 * Init client sequence manager which is used by local MDS to talk to sequence
3053 * controller on remote node.
3055 static int mdt_seq_init_cli(const struct lu_env *env,
3056 struct mdt_device *m,
3057 struct lustre_cfg *cfg)
3059 struct lu_site *ls = m->mdt_md_dev.md_lu_dev.ld_site;
3060 struct obd_device *mdc;
3061 struct obd_uuid *uuidp, *mdcuuidp;
3062 char *uuid_str, *mdc_uuid_str;
3065 struct mdt_thread_info *info;
3066 char *p, *index_string = lustre_cfg_string(cfg, 2);
3069 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
3070 uuidp = &info->mti_u.uuid[0];
3071 mdcuuidp = &info->mti_u.uuid[1];
3073 LASSERT(index_string);
3075 index = simple_strtol(index_string, &p, 10);
3077 CERROR("Invalid index in lustre_cgf, offset 2\n");
3081 /* check if this is adding the first MDC and controller is not yet
3083 if (index != 0 || ls->ls_client_seq)
3086 uuid_str = lustre_cfg_string(cfg, 1);
3087 mdc_uuid_str = lustre_cfg_string(cfg, 4);
3088 obd_str2uuid(uuidp, uuid_str);
3089 obd_str2uuid(mdcuuidp, mdc_uuid_str);
3091 mdc = class_find_client_obd(uuidp, LUSTRE_MDC_NAME, mdcuuidp);
3093 CERROR("can't find controller MDC by uuid %s\n",
3096 } else if (!mdc->obd_set_up) {
3097 CERROR("target %s not set up\n", mdc->obd_name);
3100 LASSERT(ls->ls_control_exp);
3101 OBD_ALLOC_PTR(ls->ls_client_seq);
3102 if (ls->ls_client_seq != NULL) {
3105 OBD_ALLOC(prefix, MAX_OBD_NAME + 5);
3109 snprintf(prefix, MAX_OBD_NAME + 5, "ctl-%s",
3112 rc = seq_client_init(ls->ls_client_seq,
3114 LUSTRE_SEQ_METADATA,
3116 OBD_FREE(prefix, MAX_OBD_NAME + 5);
3123 LASSERT(ls->ls_server_seq != NULL);
3124 rc = seq_server_set_cli(ls->ls_server_seq, ls->ls_client_seq,
3131 static void mdt_seq_fini_cli(struct mdt_device *m)
3137 ls = m->mdt_md_dev.md_lu_dev.ld_site;
3139 if (ls && ls->ls_server_seq)
3140 seq_server_set_cli(ls->ls_server_seq,
3143 if (ls && ls->ls_control_exp) {
3144 class_export_put(ls->ls_control_exp);
3145 ls->ls_control_exp = NULL;
3153 static int mdt_fld_fini(const struct lu_env *env,
3154 struct mdt_device *m)
3156 struct lu_site *ls = m->mdt_md_dev.md_lu_dev.ld_site;
3159 if (ls && ls->ls_server_fld) {
3160 fld_server_fini(ls->ls_server_fld, env);
3161 OBD_FREE_PTR(ls->ls_server_fld);
3162 ls->ls_server_fld = NULL;
3168 static int mdt_fld_init(const struct lu_env *env,
3170 struct mdt_device *m)
3176 ls = m->mdt_md_dev.md_lu_dev.ld_site;
3178 OBD_ALLOC_PTR(ls->ls_server_fld);
3179 if (ls->ls_server_fld == NULL)
3180 RETURN(rc = -ENOMEM);
3182 rc = fld_server_init(ls->ls_server_fld,
3183 m->mdt_bottom, uuid, env);
3185 OBD_FREE_PTR(ls->ls_server_fld);
3186 ls->ls_server_fld = NULL;
3193 /* device init/fini methods */
3194 static void mdt_stop_ptlrpc_service(struct mdt_device *m)
3197 if (m->mdt_regular_service != NULL) {
3198 ptlrpc_unregister_service(m->mdt_regular_service);
3199 m->mdt_regular_service = NULL;
3201 if (m->mdt_readpage_service != NULL) {
3202 ptlrpc_unregister_service(m->mdt_readpage_service);
3203 m->mdt_readpage_service = NULL;
3205 if (m->mdt_xmds_service != NULL) {
3206 ptlrpc_unregister_service(m->mdt_xmds_service);
3207 m->mdt_xmds_service = NULL;
3209 if (m->mdt_setattr_service != NULL) {
3210 ptlrpc_unregister_service(m->mdt_setattr_service);
3211 m->mdt_setattr_service = NULL;
3213 if (m->mdt_mdsc_service != NULL) {
3214 ptlrpc_unregister_service(m->mdt_mdsc_service);
3215 m->mdt_mdsc_service = NULL;
3217 if (m->mdt_mdss_service != NULL) {
3218 ptlrpc_unregister_service(m->mdt_mdss_service);
3219 m->mdt_mdss_service = NULL;
3221 if (m->mdt_dtss_service != NULL) {
3222 ptlrpc_unregister_service(m->mdt_dtss_service);
3223 m->mdt_dtss_service = NULL;
3225 if (m->mdt_fld_service != NULL) {
3226 ptlrpc_unregister_service(m->mdt_fld_service);
3227 m->mdt_fld_service = NULL;
3232 static int mdt_start_ptlrpc_service(struct mdt_device *m)
3235 static struct ptlrpc_service_conf conf;
3236 cfs_proc_dir_entry_t *procfs_entry;
3239 procfs_entry = m->mdt_md_dev.md_lu_dev.ld_obd->obd_proc_entry;
3241 conf = (typeof(conf)) {
3242 .psc_nbufs = MDS_NBUFS,
3243 .psc_bufsize = MDS_BUFSIZE,
3244 .psc_max_req_size = MDS_MAXREQSIZE,
3245 .psc_max_reply_size = MDS_MAXREPSIZE,
3246 .psc_req_portal = MDS_REQUEST_PORTAL,
3247 .psc_rep_portal = MDC_REPLY_PORTAL,
3248 .psc_watchdog_timeout = MDT_SERVICE_WATCHDOG_TIMEOUT,
3250 * We'd like to have a mechanism to set this on a per-device
3251 * basis, but alas...
3253 .psc_min_threads = min(max(mdt_num_threads, MDT_MIN_THREADS),
3255 .psc_max_threads = MDT_MAX_THREADS,
3256 .psc_ctx_tags = LCT_MD_THREAD
3259 m->mdt_ldlm_client = &m->mdt_md_dev.md_lu_dev.ld_obd->obd_ldlm_client;
3260 ptlrpc_init_client(LDLM_CB_REQUEST_PORTAL, LDLM_CB_REPLY_PORTAL,
3261 "mdt_ldlm_client", m->mdt_ldlm_client);
3263 m->mdt_regular_service =
3264 ptlrpc_init_svc_conf(&conf, mdt_regular_handle, LUSTRE_MDT_NAME,
3265 procfs_entry, NULL, LUSTRE_MDT_NAME);
3266 if (m->mdt_regular_service == NULL)
3269 rc = ptlrpc_start_threads(NULL, m->mdt_regular_service);
3271 GOTO(err_mdt_svc, rc);
3274 * readpage service configuration. Parameters have to be adjusted,
3277 conf = (typeof(conf)) {
3278 .psc_nbufs = MDS_NBUFS,
3279 .psc_bufsize = MDS_BUFSIZE,
3280 .psc_max_req_size = MDS_MAXREQSIZE,
3281 .psc_max_reply_size = MDS_MAXREPSIZE,
3282 .psc_req_portal = MDS_READPAGE_PORTAL,
3283 .psc_rep_portal = MDC_REPLY_PORTAL,
3284 .psc_watchdog_timeout = MDT_SERVICE_WATCHDOG_TIMEOUT,
3285 .psc_min_threads = min(max(mdt_num_threads, MDT_MIN_THREADS),
3287 .psc_max_threads = MDT_MAX_THREADS,
3288 .psc_ctx_tags = LCT_MD_THREAD
3290 m->mdt_readpage_service =
3291 ptlrpc_init_svc_conf(&conf, mdt_readpage_handle,
3292 LUSTRE_MDT_NAME "_readpage",
3293 procfs_entry, NULL, "mdt_rdpg");
3295 if (m->mdt_readpage_service == NULL) {
3296 CERROR("failed to start readpage service\n");
3297 GOTO(err_mdt_svc, rc = -ENOMEM);
3300 rc = ptlrpc_start_threads(NULL, m->mdt_readpage_service);
3303 * setattr service configuration.
3305 conf = (typeof(conf)) {
3306 .psc_nbufs = MDS_NBUFS,
3307 .psc_bufsize = MDS_BUFSIZE,
3308 .psc_max_req_size = MDS_MAXREQSIZE,
3309 .psc_max_reply_size = MDS_MAXREPSIZE,
3310 .psc_req_portal = MDS_SETATTR_PORTAL,
3311 .psc_rep_portal = MDC_REPLY_PORTAL,
3312 .psc_watchdog_timeout = MDT_SERVICE_WATCHDOG_TIMEOUT,
3313 .psc_min_threads = min(max(mdt_num_threads, MDT_MIN_THREADS),
3315 .psc_max_threads = MDT_MAX_THREADS,
3316 .psc_ctx_tags = LCT_MD_THREAD
3319 m->mdt_setattr_service =
3320 ptlrpc_init_svc_conf(&conf, mdt_regular_handle,
3321 LUSTRE_MDT_NAME "_setattr",
3322 procfs_entry, NULL, "mdt_attr");
3324 if (!m->mdt_setattr_service) {
3325 CERROR("failed to start setattr service\n");
3326 GOTO(err_mdt_svc, rc = -ENOMEM);
3329 rc = ptlrpc_start_threads(NULL, m->mdt_setattr_service);
3331 GOTO(err_mdt_svc, rc);
3334 * sequence controller service configuration
3336 conf = (typeof(conf)) {
3337 .psc_nbufs = MDS_NBUFS,
3338 .psc_bufsize = MDS_BUFSIZE,
3339 .psc_max_req_size = SEQ_MAXREQSIZE,
3340 .psc_max_reply_size = SEQ_MAXREPSIZE,
3341 .psc_req_portal = SEQ_CONTROLLER_PORTAL,
3342 .psc_rep_portal = MDC_REPLY_PORTAL,
3343 .psc_watchdog_timeout = MDT_SERVICE_WATCHDOG_TIMEOUT,
3344 .psc_min_threads = SEQ_NUM_THREADS,
3345 .psc_max_threads = SEQ_NUM_THREADS,
3346 .psc_ctx_tags = LCT_MD_THREAD|LCT_DT_THREAD
3349 m->mdt_mdsc_service =
3350 ptlrpc_init_svc_conf(&conf, mdt_mdsc_handle,
3351 LUSTRE_MDT_NAME"_mdsc",
3352 procfs_entry, NULL, "mdt_mdsc");
3353 if (!m->mdt_mdsc_service) {
3354 CERROR("failed to start seq controller service\n");
3355 GOTO(err_mdt_svc, rc = -ENOMEM);
3358 rc = ptlrpc_start_threads(NULL, m->mdt_mdsc_service);
3360 GOTO(err_mdt_svc, rc);
3363 * metadata sequence server service configuration
3365 conf = (typeof(conf)) {
3366 .psc_nbufs = MDS_NBUFS,
3367 .psc_bufsize = MDS_BUFSIZE,
3368 .psc_max_req_size = SEQ_MAXREQSIZE,
3369 .psc_max_reply_size = SEQ_MAXREPSIZE,
3370 .psc_req_portal = SEQ_METADATA_PORTAL,
3371 .psc_rep_portal = MDC_REPLY_PORTAL,
3372 .psc_watchdog_timeout = MDT_SERVICE_WATCHDOG_TIMEOUT,
3373 .psc_min_threads = SEQ_NUM_THREADS,
3374 .psc_max_threads = SEQ_NUM_THREADS,
3375 .psc_ctx_tags = LCT_MD_THREAD|LCT_DT_THREAD
3378 m->mdt_mdss_service =
3379 ptlrpc_init_svc_conf(&conf, mdt_mdss_handle,
3380 LUSTRE_MDT_NAME"_mdss",
3381 procfs_entry, NULL, "mdt_mdss");
3382 if (!m->mdt_mdss_service) {
3383 CERROR("failed to start metadata seq server service\n");
3384 GOTO(err_mdt_svc, rc = -ENOMEM);
3387 rc = ptlrpc_start_threads(NULL, m->mdt_mdss_service);
3389 GOTO(err_mdt_svc, rc);
3393 * Data sequence server service configuration. We want to have really
3394 * cluster-wide sequences space. This is why we start only one sequence
3395 * controller which manages space.
3397 conf = (typeof(conf)) {
3398 .psc_nbufs = MDS_NBUFS,
3399 .psc_bufsize = MDS_BUFSIZE,
3400 .psc_max_req_size = SEQ_MAXREQSIZE,
3401 .psc_max_reply_size = SEQ_MAXREPSIZE,
3402 .psc_req_portal = SEQ_DATA_PORTAL,
3403 .psc_rep_portal = OSC_REPLY_PORTAL,
3404 .psc_watchdog_timeout = MDT_SERVICE_WATCHDOG_TIMEOUT,
3405 .psc_min_threads = SEQ_NUM_THREADS,
3406 .psc_max_threads = SEQ_NUM_THREADS,
3407 .psc_ctx_tags = LCT_MD_THREAD|LCT_DT_THREAD
3410 m->mdt_dtss_service =
3411 ptlrpc_init_svc_conf(&conf, mdt_dtss_handle,
3412 LUSTRE_MDT_NAME"_dtss",
3413 procfs_entry, NULL, "mdt_dtss");
3414 if (!m->mdt_dtss_service) {
3415 CERROR("failed to start data seq server service\n");
3416 GOTO(err_mdt_svc, rc = -ENOMEM);
3419 rc = ptlrpc_start_threads(NULL, m->mdt_dtss_service);
3421 GOTO(err_mdt_svc, rc);
3423 /* FLD service start */
3424 conf = (typeof(conf)) {
3425 .psc_nbufs = MDS_NBUFS,
3426 .psc_bufsize = MDS_BUFSIZE,
3427 .psc_max_req_size = FLD_MAXREQSIZE,
3428 .psc_max_reply_size = FLD_MAXREPSIZE,
3429 .psc_req_portal = FLD_REQUEST_PORTAL,
3430 .psc_rep_portal = MDC_REPLY_PORTAL,
3431 .psc_watchdog_timeout = MDT_SERVICE_WATCHDOG_TIMEOUT,
3432 .psc_min_threads = FLD_NUM_THREADS,
3433 .psc_max_threads = FLD_NUM_THREADS,
3434 .psc_ctx_tags = LCT_DT_THREAD|LCT_MD_THREAD
3437 m->mdt_fld_service =
3438 ptlrpc_init_svc_conf(&conf, mdt_fld_handle,
3439 LUSTRE_MDT_NAME"_fld",
3440 procfs_entry, NULL, "mdt_fld");
3441 if (!m->mdt_fld_service) {
3442 CERROR("failed to start fld service\n");
3443 GOTO(err_mdt_svc, rc = -ENOMEM);
3446 rc = ptlrpc_start_threads(NULL, m->mdt_fld_service);
3448 GOTO(err_mdt_svc, rc);
3451 * mds-mds service configuration. Separate portal is used to allow
3452 * mds-mds requests be not blocked during recovery.
3454 conf = (typeof(conf)) {
3455 .psc_nbufs = MDS_NBUFS,
3456 .psc_bufsize = MDS_BUFSIZE,
3457 .psc_max_req_size = MDS_MAXREQSIZE,
3458 .psc_max_reply_size = MDS_MAXREPSIZE,
3459 .psc_req_portal = MDS_MDS_PORTAL,
3460 .psc_rep_portal = MDC_REPLY_PORTAL,
3461 .psc_watchdog_timeout = MDT_SERVICE_WATCHDOG_TIMEOUT,
3462 .psc_min_threads = min(max(mdt_num_threads, MDT_MIN_THREADS),
3464 .psc_max_threads = MDT_MAX_THREADS,
3465 .psc_ctx_tags = LCT_MD_THREAD
3467 m->mdt_xmds_service = ptlrpc_init_svc_conf(&conf, mdt_xmds_handle,
3468 LUSTRE_MDT_NAME "_mds",
3469 procfs_entry, NULL, "mdt_xmds");
3471 if (m->mdt_xmds_service == NULL) {
3472 CERROR("failed to start readpage service\n");
3473 GOTO(err_mdt_svc, rc = -ENOMEM);
3476 rc = ptlrpc_start_threads(NULL, m->mdt_xmds_service);
3478 GOTO(err_mdt_svc, rc);
3483 mdt_stop_ptlrpc_service(m);
3488 static void mdt_stack_fini(const struct lu_env *env,
3489 struct mdt_device *m, struct lu_device *top)
3491 struct lu_device *d = top, *n;
3492 struct obd_device *obd = m->mdt_md_dev.md_lu_dev.ld_obd;
3493 struct lustre_cfg_bufs *bufs;
3494 struct lustre_cfg *lcfg;
3495 struct mdt_thread_info *info;
3499 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
3500 LASSERT(info != NULL);
3502 bufs = &info->mti_u.bufs;
3503 /* process cleanup, pass mdt obd name to get obd umount flags */
3504 lustre_cfg_bufs_reset(bufs, obd->obd_name);
3509 lustre_cfg_bufs_set_string(bufs, 1, flags);
3510 lcfg = lustre_cfg_new(LCFG_CLEANUP, bufs);
3512 CERROR("Cannot alloc lcfg!\n");
3517 top->ld_ops->ldo_process_config(env, top, lcfg);
3518 lustre_cfg_free(lcfg);
3520 lu_site_purge(env, top->ld_site, ~0);
3522 struct obd_type *type;
3523 struct lu_device_type *ldt = d->ld_type;
3525 /* each fini() returns next device in stack of layers
3526 * * so we can avoid the recursion */
3527 n = ldt->ldt_ops->ldto_device_fini(env, d);
3529 ldt->ldt_ops->ldto_device_free(env, d);
3530 type = ldt->ldt_obd_type;
3532 class_put_type(type);
3534 /* switch to the next device in the layer */
3537 m->mdt_child = NULL;
3538 m->mdt_bottom = NULL;
3541 static struct lu_device *mdt_layer_setup(const struct lu_env *env,
3542 const char *typename,
3543 struct lu_device *child,
3544 struct lustre_cfg *cfg)
3546 const char *dev = lustre_cfg_string(cfg, 0);
3547 struct obd_type *type;
3548 struct lu_device_type *ldt;
3549 struct lu_device *d;
3554 type = class_get_type(typename);
3556 CERROR("Unknown type: '%s'\n", typename);
3557 GOTO(out, rc = -ENODEV);
3560 rc = lu_context_refill(&env->le_ctx);
3562 CERROR("Failure to refill context: '%d'\n", rc);
3566 if (env->le_ses != NULL) {
3567 rc = lu_context_refill(env->le_ses);
3569 CERROR("Failure to refill session: '%d'\n", rc);
3576 CERROR("type: '%s'\n", typename);
3577 GOTO(out_type, rc = -EINVAL);
3580 ldt->ldt_obd_type = type;
3581 d = ldt->ldt_ops->ldto_device_alloc(env, ldt, cfg);
3583 CERROR("Cannot allocate device: '%s'\n", typename);
3584 GOTO(out_type, rc = -ENODEV);
3587 LASSERT(child->ld_site);
3588 d->ld_site = child->ld_site;
3591 rc = ldt->ldt_ops->ldto_device_init(env, d, dev, child);
3593 CERROR("can't init device '%s', rc %d\n", typename, rc);
3594 GOTO(out_alloc, rc);
3601 ldt->ldt_ops->ldto_device_free(env, d);
3604 class_put_type(type);
3609 static int mdt_stack_init(const struct lu_env *env,
3610 struct mdt_device *m, struct lustre_cfg *cfg)
3612 struct lu_device *d = &m->mdt_md_dev.md_lu_dev;
3613 struct lu_device *tmp;
3614 struct md_device *md;
3618 /* init the stack */
3619 tmp = mdt_layer_setup(env, LUSTRE_OSD_NAME, d, cfg);
3621 RETURN(PTR_ERR(tmp));
3623 m->mdt_bottom = lu2dt_dev(tmp);
3625 tmp = mdt_layer_setup(env, LUSTRE_MDD_NAME, d, cfg);
3627 GOTO(out, rc = PTR_ERR(tmp));
3632 tmp = mdt_layer_setup(env, LUSTRE_CMM_NAME, d, cfg);
3634 GOTO(out, rc = PTR_ERR(tmp));
3637 /*set mdd upcall device*/
3638 md_upcall_dev_set(md, lu2md_dev(d));
3641 /*set cmm upcall device*/
3642 md_upcall_dev_set(md, &m->mdt_md_dev);
3644 m->mdt_child = lu2md_dev(d);
3646 /* process setup config */
3647 tmp = &m->mdt_md_dev.md_lu_dev;
3648 rc = tmp->ld_ops->ldo_process_config(env, tmp, cfg);
3651 /* fini from last known good lu_device */
3653 mdt_stack_fini(env, m, d);
3658 static void mdt_fini(const struct lu_env *env, struct mdt_device *m)
3660 struct md_device *next = m->mdt_child;
3661 struct lu_device *d = &m->mdt_md_dev.md_lu_dev;
3662 struct lu_site *ls = d->ld_site;
3663 struct obd_device *obd = m->mdt_md_dev.md_lu_dev.ld_obd;
3666 ping_evictor_stop();
3668 target_recovery_fini(obd);
3669 mdt_stop_ptlrpc_service(m);
3671 mdt_fs_cleanup(env, m);
3673 upcall_cache_cleanup(m->mdt_rmtacl_cache);
3674 m->mdt_rmtacl_cache = NULL;
3676 upcall_cache_cleanup(m->mdt_identity_cache);
3677 m->mdt_identity_cache = NULL;
3679 if (m->mdt_namespace != NULL) {
3680 ldlm_namespace_free(m->mdt_namespace, d->ld_obd->obd_force);
3681 d->ld_obd->obd_namespace = m->mdt_namespace = NULL;
3684 mdt_seq_fini(env, m);
3685 mdt_seq_fini_cli(m);
3686 mdt_fld_fini(env, m);
3688 ptlrpc_lprocfs_unregister_obd(d->ld_obd);
3689 lprocfs_obd_cleanup(d->ld_obd);
3691 if (m->mdt_rootsquash_info) {
3692 OBD_FREE_PTR(m->mdt_rootsquash_info);
3693 m->mdt_rootsquash_info = NULL;
3696 next->md_ops->mdo_init_capa_ctxt(env, next, 0, 0, 0, NULL);
3697 del_timer(&m->mdt_ck_timer);
3698 mdt_ck_thread_stop(m);
3700 /* finish the stack */
3701 mdt_stack_fini(env, m, md2lu_dev(m->mdt_child));
3704 if (!list_empty(&ls->ls_lru) || ls->ls_total != 0) {
3706 * Uh-oh, objects still exist.
3708 static DECLARE_LU_CDEBUG_PRINT_INFO(cookie, D_ERROR);
3710 lu_site_print(env, ls, &cookie, lu_cdebug_printer);
3717 LASSERT(atomic_read(&d->ld_ref) == 0);
3718 md_device_fini(&m->mdt_md_dev);
3723 static void fsoptions_to_mdt_flags(struct mdt_device *m, char *options)
3733 while (*p && *p != ',')
3737 if ((len == sizeof("user_xattr") - 1) &&
3738 (memcmp(options, "user_xattr", len) == 0)) {
3739 m->mdt_opts.mo_user_xattr = 1;
3740 LCONSOLE_INFO("Enabling user_xattr\n");
3741 } else if ((len == sizeof("nouser_xattr") - 1) &&
3742 (memcmp(options, "nouser_xattr", len) == 0)) {
3743 m->mdt_opts.mo_user_xattr = 0;
3744 LCONSOLE_INFO("Disabling user_xattr\n");
3745 } else if ((len == sizeof("acl") - 1) &&
3746 (memcmp(options, "acl", len) == 0)) {
3747 #ifdef CONFIG_FS_POSIX_ACL
3748 m->mdt_opts.mo_acl = 1;
3749 LCONSOLE_INFO("Enabling ACL\n");
3751 m->mdt_opts.mo_acl = 0;
3752 CWARN("ignoring unsupported acl mount option\n");
3753 LCONSOLE_INFO("Disabling ACL\n");
3755 } else if ((len == sizeof("noacl") - 1) &&
3756 (memcmp(options, "noacl", len) == 0)) {
3757 m->mdt_opts.mo_acl = 0;
3758 LCONSOLE_INFO("Disabling ACL\n");
3765 int mdt_postrecov(const struct lu_env *, struct mdt_device *);
3767 static int mdt_init0(const struct lu_env *env, struct mdt_device *m,
3768 struct lu_device_type *ldt, struct lustre_cfg *cfg)
3770 struct lprocfs_static_vars lvars;
3771 struct mdt_thread_info *info;
3772 struct obd_device *obd;
3773 const char *dev = lustre_cfg_string(cfg, 0);
3774 const char *num = lustre_cfg_string(cfg, 2);
3775 struct lustre_mount_info *lmi;
3776 struct lustre_sb_info *lsi;
3781 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
3782 LASSERT(info != NULL);
3784 obd = class_name2obd(dev);
3785 LASSERT(obd != NULL);
3787 spin_lock_init(&m->mdt_transno_lock);
3789 m->mdt_max_mdsize = MAX_MD_SIZE;
3790 m->mdt_max_cookiesize = sizeof(struct llog_cookie);
3792 m->mdt_opts.mo_user_xattr = 0;
3793 m->mdt_opts.mo_acl = 0;
3794 lmi = server_get_mount_2(dev);
3796 CERROR("Cannot get mount info for %s!\n", dev);
3799 lsi = s2lsi(lmi->lmi_sb);
3800 fsoptions_to_mdt_flags(m, lsi->lsi_lmd->lmd_opts);
3801 server_put_mount_2(dev, lmi->lmi_mnt);
3804 spin_lock_init(&m->mdt_ioepoch_lock);
3805 m->mdt_opts.mo_compat_resname = 0;
3806 m->mdt_capa_timeout = CAPA_TIMEOUT;
3807 m->mdt_capa_alg = CAPA_HMAC_ALG_SHA1;
3808 m->mdt_ck_timeout = CAPA_KEY_TIMEOUT;
3810 spin_lock_init(&m->mdt_client_bitmap_lock);
3816 md_device_init(&m->mdt_md_dev, ldt);
3817 m->mdt_md_dev.md_lu_dev.ld_ops = &mdt_lu_ops;
3818 m->mdt_md_dev.md_lu_dev.ld_obd = obd;
3819 /* set this lu_device to obd, because error handling need it */
3820 obd->obd_lu_dev = &m->mdt_md_dev.md_lu_dev;
3822 rc = lu_site_init(s, &m->mdt_md_dev.md_lu_dev);
3824 CERROR("Can't init lu_site, rc %d\n", rc);
3825 GOTO(err_free_site, rc);
3828 lprocfs_init_vars(mdt, &lvars);
3829 rc = lprocfs_obd_setup(obd, lvars.obd_vars);
3831 CERROR("Can't init lprocfs, rc %d\n", rc);
3832 GOTO(err_fini_site, rc);
3834 ptlrpc_lprocfs_register_obd(obd);
3836 rc = mdt_procfs_init(m, dev);
3838 CERROR("Can't init MDT lprocfs, rc %d\n", rc);
3839 GOTO(err_fini_proc, rc);
3842 /* set server index */
3844 s->ls_node_id = simple_strtol(num, NULL, 10);
3846 /* failover is the default
3847 * FIXME: we do not failout mds0/mgs, which may cause some problems.
3848 * assumed whose ls_node_id == 0 XXX
3850 obd->obd_replayable = 1;
3851 /* No connection accepted until configurations will finish */
3852 obd->obd_no_conn = 1;
3854 if (cfg->lcfg_bufcount > 4 && LUSTRE_CFG_BUFLEN(cfg, 4) > 0) {
3855 char *str = lustre_cfg_string(cfg, 4);
3856 if (strchr(str, 'n')) {
3857 CWARN("%s: recovery disabled\n", obd->obd_name);
3858 obd->obd_replayable = 0;
3862 /* init the stack */
3863 rc = mdt_stack_init(env, m, cfg);
3865 CERROR("Can't init device stack, rc %d\n", rc);
3866 GOTO(err_fini_proc, rc);
3869 rc = mdt_fld_init(env, obd->obd_name, m);
3871 GOTO(err_fini_stack, rc);
3873 rc = mdt_seq_init(env, obd->obd_name, m);
3875 GOTO(err_fini_fld, rc);
3877 snprintf(info->mti_u.ns_name, sizeof info->mti_u.ns_name,
3878 LUSTRE_MDT_NAME"-%p", m);
3879 m->mdt_namespace = ldlm_namespace_new(info->mti_u.ns_name,
3880 LDLM_NAMESPACE_SERVER,
3881 LDLM_NAMESPACE_GREEDY);
3882 if (m->mdt_namespace == NULL)
3883 GOTO(err_fini_seq, rc = -ENOMEM);
3885 ldlm_register_intent(m->mdt_namespace, mdt_intent_policy);
3886 /* set obd_namespace for compatibility with old code */
3887 obd->obd_namespace = m->mdt_namespace;
3889 m->mdt_identity_cache = upcall_cache_init(obd->obd_name,
3891 &mdt_identity_upcall_cache_ops);
3892 if (IS_ERR(m->mdt_identity_cache)) {
3893 rc = PTR_ERR(m->mdt_identity_cache);
3894 m->mdt_identity_cache = NULL;
3895 GOTO(err_free_ns, rc);
3898 m->mdt_rmtacl_cache = upcall_cache_init(obd->obd_name,
3899 MDT_RMTACL_UPCALL_PATH,
3900 &mdt_rmtacl_upcall_cache_ops);
3901 if (IS_ERR(m->mdt_rmtacl_cache)) {
3902 rc = PTR_ERR(m->mdt_rmtacl_cache);
3903 m->mdt_rmtacl_cache = NULL;
3904 GOTO(err_free_ns, rc);
3907 m->mdt_ck_timer.function = mdt_ck_timer_callback;
3908 m->mdt_ck_timer.data = (unsigned long)m;
3909 init_timer(&m->mdt_ck_timer);
3910 rc = mdt_ck_thread_start(m);
3912 GOTO(err_free_ns, rc);
3914 rc = mdt_fs_setup(env, m, obd);
3918 target_recovery_init(obd, mdt_recovery_handle);
3920 rc = mdt_start_ptlrpc_service(m);
3922 GOTO(err_fs_cleanup, rc);
3924 ping_evictor_start();
3926 rc = lu_site_init_finish(s);
3928 GOTO(err_stop_service, rc);
3930 if (obd->obd_recovering == 0)
3931 mdt_postrecov(env, m);
3933 mdt_init_capa_ctxt(env, m);
3935 if (ldlm_timeout == LDLM_TIMEOUT_DEFAULT)
3941 ping_evictor_stop();
3942 mdt_stop_ptlrpc_service(m);
3944 target_recovery_fini(obd);
3945 mdt_fs_cleanup(env, m);
3947 del_timer(&m->mdt_ck_timer);
3948 mdt_ck_thread_stop(m);
3950 upcall_cache_cleanup(m->mdt_rmtacl_cache);
3951 m->mdt_rmtacl_cache = NULL;
3952 upcall_cache_cleanup(m->mdt_identity_cache);
3953 m->mdt_identity_cache = NULL;
3954 ldlm_namespace_free(m->mdt_namespace, 0);
3955 obd->obd_namespace = m->mdt_namespace = NULL;
3957 mdt_seq_fini(env, m);
3959 mdt_fld_fini(env, m);
3961 mdt_stack_fini(env, m, md2lu_dev(m->mdt_child));
3964 lprocfs_obd_cleanup(obd);
3970 md_device_fini(&m->mdt_md_dev);
3974 /* used by MGS to process specific configurations */
3975 static int mdt_process_config(const struct lu_env *env,
3976 struct lu_device *d, struct lustre_cfg *cfg)
3978 struct mdt_device *m = mdt_dev(d);
3979 struct md_device *md_next = m->mdt_child;
3980 struct lu_device *next = md2lu_dev(md_next);
3984 switch (cfg->lcfg_command) {
3986 struct lprocfs_static_vars lvars;
3987 struct obd_device *obd = d->ld_obd;
3989 lprocfs_init_vars(mdt, &lvars);
3990 rc = class_process_proc_param(PARAM_MDT, lvars.obd_vars, cfg, obd);
3992 /* others are passed further */
3993 rc = next->ld_ops->ldo_process_config(env, next, cfg);
3998 * Add mdc hook to get first MDT uuid and connect it to
3999 * ls->controller to use for seq manager.
4001 rc = next->ld_ops->ldo_process_config(env, next, cfg);
4003 CERROR("Can't add mdc, rc %d\n", rc);
4005 rc = mdt_seq_init_cli(env, mdt_dev(d), cfg);
4008 /* others are passed further */
4009 rc = next->ld_ops->ldo_process_config(env, next, cfg);
4015 static struct lu_object *mdt_object_alloc(const struct lu_env *env,
4016 const struct lu_object_header *hdr,
4017 struct lu_device *d)
4019 struct mdt_object *mo;
4025 struct lu_object *o;
4026 struct lu_object_header *h;
4028 o = &mo->mot_obj.mo_lu;
4029 h = &mo->mot_header;
4030 lu_object_header_init(h);
4031 lu_object_init(o, h, d);
4032 lu_object_add_top(h, o);
4033 o->lo_ops = &mdt_obj_ops;
4039 static int mdt_object_init(const struct lu_env *env, struct lu_object *o)
4041 struct mdt_device *d = mdt_dev(o->lo_dev);
4042 struct lu_device *under;
4043 struct lu_object *below;
4047 CDEBUG(D_INFO, "object init, fid = "DFID"\n",
4048 PFID(lu_object_fid(o)));
4050 under = &d->mdt_child->md_lu_dev;
4051 below = under->ld_ops->ldo_object_alloc(env, o->lo_header, under);
4052 if (below != NULL) {
4053 lu_object_add(o, below);
4060 static void mdt_object_free(const struct lu_env *env, struct lu_object *o)
4062 struct mdt_object *mo = mdt_obj(o);
4063 struct lu_object_header *h;
4067 CDEBUG(D_INFO, "object free, fid = "DFID"\n",
4068 PFID(lu_object_fid(o)));
4071 lu_object_header_fini(h);
4076 static int mdt_object_print(const struct lu_env *env, void *cookie,
4077 lu_printer_t p, const struct lu_object *o)
4079 return (*p)(env, cookie, LUSTRE_MDT_NAME"-object@%p", o);
4082 static struct lu_device_operations mdt_lu_ops = {
4083 .ldo_object_alloc = mdt_object_alloc,
4084 .ldo_process_config = mdt_process_config
4087 static struct lu_object_operations mdt_obj_ops = {
4088 .loo_object_init = mdt_object_init,
4089 .loo_object_free = mdt_object_free,
4090 .loo_object_print = mdt_object_print
4093 /* mds_connect_internal */
4094 static int mdt_connect_internal(struct obd_export *exp,
4095 struct mdt_device *mdt,
4096 struct obd_connect_data *data)
4101 data->ocd_connect_flags &= MDT_CONNECT_SUPPORTED;
4102 data->ocd_ibits_known &= MDS_INODELOCK_FULL;
4104 /* If no known bits (which should not happen, probably,
4105 as everybody should support LOOKUP and UPDATE bits at least)
4106 revert to compat mode with plain locks. */
4107 if (!data->ocd_ibits_known &&
4108 data->ocd_connect_flags & OBD_CONNECT_IBITS)
4109 data->ocd_connect_flags &= ~OBD_CONNECT_IBITS;
4111 if (!mdt->mdt_opts.mo_acl)
4112 data->ocd_connect_flags &= ~OBD_CONNECT_ACL;
4114 if (!mdt->mdt_opts.mo_user_xattr)
4115 data->ocd_connect_flags &= ~OBD_CONNECT_XATTR;
4117 if (!mdt->mdt_opts.mo_mds_capa)
4118 data->ocd_connect_flags &= ~OBD_CONNECT_MDS_CAPA;
4120 if (!mdt->mdt_opts.mo_oss_capa)
4121 data->ocd_connect_flags &= ~OBD_CONNECT_OSS_CAPA;
4123 spin_lock(&exp->exp_lock);
4124 exp->exp_connect_flags = data->ocd_connect_flags;
4125 spin_unlock(&exp->exp_lock);
4126 data->ocd_version = LUSTRE_VERSION_CODE;
4127 exp->exp_mdt_data.med_ibits_known = data->ocd_ibits_known;
4131 if (mdt->mdt_opts.mo_acl &&
4132 ((exp->exp_connect_flags & OBD_CONNECT_ACL) == 0)) {
4133 CWARN("%s: MDS requires ACL support but client does not\n",
4134 mdt->mdt_md_dev.md_lu_dev.ld_obd->obd_name);
4139 flags = OBD_CONNECT_LCL_CLIENT | OBD_CONNECT_RMT_CLIENT;
4140 if ((exp->exp_connect_flags & flags) == flags) {
4141 CWARN("%s: both local and remote client flags are set\n",
4142 mdt->mdt_md_dev.md_lu_dev.ld_obd->obd_name);
4146 if (mdt->mdt_opts.mo_mds_capa &&
4147 ((exp->exp_connect_flags & OBD_CONNECT_MDS_CAPA) == 0)) {
4148 CWARN("%s: MDS requires capability support, but client not\n",
4149 mdt->mdt_md_dev.md_lu_dev.ld_obd->obd_name);
4153 if (mdt->mdt_opts.mo_oss_capa &&
4154 ((exp->exp_connect_flags & OBD_CONNECT_OSS_CAPA) == 0)) {
4155 CWARN("%s: MDS requires OSS capability support, "
4157 mdt->mdt_md_dev.md_lu_dev.ld_obd->obd_name);
4164 /* mds_connect copy */
4165 static int mdt_obd_connect(const struct lu_env *env,
4166 struct lustre_handle *conn, struct obd_device *obd,
4167 struct obd_uuid *cluuid,
4168 struct obd_connect_data *data)
4170 struct mdt_client_data *mcd;
4171 struct obd_export *exp;
4172 struct mdt_device *mdt;
4176 LASSERT(env != NULL);
4177 if (!conn || !obd || !cluuid)
4180 mdt = mdt_dev(obd->obd_lu_dev);
4182 rc = class_connect(conn, obd, cluuid);
4186 exp = class_conn2export(conn);
4187 LASSERT(exp != NULL);
4189 rc = mdt_connect_internal(exp, mdt, data);
4193 struct mdt_thread_info *mti;
4194 mti = lu_context_key_get(&env->le_ctx,
4196 LASSERT(mti != NULL);
4198 memcpy(mcd->mcd_uuid, cluuid, sizeof mcd->mcd_uuid);
4199 exp->exp_mdt_data.med_mcd = mcd;
4200 rc = mdt_client_new(env, mdt);
4203 exp->exp_mdt_data.med_mcd = NULL;
4210 class_disconnect(exp);
4212 class_export_put(exp);
4217 static int mdt_obd_reconnect(struct obd_export *exp, struct obd_device *obd,
4218 struct obd_uuid *cluuid,
4219 struct obd_connect_data *data)
4224 if (exp == NULL || obd == NULL || cluuid == NULL)
4227 rc = mdt_connect_internal(exp, mdt_dev(obd->obd_lu_dev), data);
4232 static int mdt_obd_disconnect(struct obd_export *exp)
4234 struct mdt_device *mdt = mdt_dev(exp->exp_obd->obd_lu_dev);
4239 class_export_get(exp);
4241 /* Disconnect early so that clients can't keep using export */
4242 rc = class_disconnect(exp);
4243 if (mdt->mdt_namespace != NULL || exp->exp_obd->obd_namespace != NULL)
4244 ldlm_cancel_locks_for_export(exp);
4246 /* complete all outstanding replies */
4247 spin_lock(&exp->exp_lock);
4248 while (!list_empty(&exp->exp_outstanding_replies)) {
4249 struct ptlrpc_reply_state *rs =
4250 list_entry(exp->exp_outstanding_replies.next,
4251 struct ptlrpc_reply_state, rs_exp_list);
4252 struct ptlrpc_service *svc = rs->rs_service;
4254 spin_lock(&svc->srv_lock);
4255 list_del_init(&rs->rs_exp_list);
4256 ptlrpc_schedule_difficult_reply(rs);
4257 spin_unlock(&svc->srv_lock);
4259 spin_unlock(&exp->exp_lock);
4261 class_export_put(exp);
4265 /* FIXME: Can we avoid using these two interfaces? */
4266 static int mdt_init_export(struct obd_export *exp)
4268 struct mdt_export_data *med = &exp->exp_mdt_data;
4271 INIT_LIST_HEAD(&med->med_open_head);
4272 spin_lock_init(&med->med_open_lock);
4273 spin_lock(&exp->exp_lock);
4274 exp->exp_connecting = 1;
4275 spin_unlock(&exp->exp_lock);
4279 static int mdt_destroy_export(struct obd_export *export)
4281 struct mdt_export_data *med;
4282 struct obd_device *obd = export->exp_obd;
4283 struct mdt_device *mdt;
4284 struct mdt_thread_info *info;
4292 med = &export->exp_mdt_data;
4293 if (med->med_rmtclient)
4294 mdt_cleanup_idmap(med);
4296 target_destroy_export(export);
4298 if (obd_uuid_equals(&export->exp_client_uuid, &obd->obd_uuid))
4301 mdt = mdt_dev(obd->obd_lu_dev);
4302 LASSERT(mdt != NULL);
4304 rc = lu_env_init(&env, NULL, LCT_MD_THREAD);
4308 info = lu_context_key_get(&env.le_ctx, &mdt_thread_key);
4309 LASSERT(info != NULL);
4310 memset(info, 0, sizeof *info);
4311 info->mti_env = &env;
4312 info->mti_mdt = mdt;
4313 info->mti_exp = export;
4315 ma = &info->mti_attr;
4316 lmm_size = ma->ma_lmm_size = mdt->mdt_max_mdsize;
4317 cookie_size = ma->ma_cookie_size = mdt->mdt_max_cookiesize;
4318 OBD_ALLOC(ma->ma_lmm, lmm_size);
4319 OBD_ALLOC(ma->ma_cookie, cookie_size);
4321 if (ma->ma_lmm == NULL || ma->ma_cookie == NULL)
4322 GOTO(out, rc = -ENOMEM);
4323 ma->ma_need = MA_LOV | MA_COOKIE;
4325 /* Close any open files (which may also cause orphan unlinking). */
4326 spin_lock(&med->med_open_lock);
4327 while (!list_empty(&med->med_open_head)) {
4328 struct list_head *tmp = med->med_open_head.next;
4329 struct mdt_file_data *mfd =
4330 list_entry(tmp, struct mdt_file_data, mfd_list);
4332 /* Remove mfd handle so it can't be found again.
4333 * We are consuming the mfd_list reference here. */
4334 class_handle_unhash(&mfd->mfd_handle);
4335 list_del_init(&mfd->mfd_list);
4336 spin_unlock(&med->med_open_lock);
4337 mdt_mfd_close(info, mfd);
4338 /* TODO: if we close the unlinked file,
4339 * we need to remove it's objects from OST */
4340 memset(&ma->ma_attr, 0, sizeof(ma->ma_attr));
4341 spin_lock(&med->med_open_lock);
4342 ma->ma_lmm_size = lmm_size;
4343 ma->ma_cookie_size = cookie_size;
4344 ma->ma_need = MA_LOV | MA_COOKIE;
4347 spin_unlock(&med->med_open_lock);
4348 info->mti_mdt = NULL;
4349 mdt_client_del(&env, mdt);
4354 OBD_FREE(ma->ma_lmm, lmm_size);
4358 OBD_FREE(ma->ma_cookie, cookie_size);
4359 ma->ma_cookie = NULL;
4366 static void mdt_allow_cli(struct mdt_device *m, unsigned int flag)
4368 if (flag & CONFIG_LOG)
4369 m->mdt_fl_cfglog = 1;
4370 if (flag & CONFIG_SYNC)
4371 m->mdt_fl_synced = 1;
4373 if (m->mdt_fl_cfglog /* bz11778: && m->mdt_fl_synced */)
4374 /* Open for clients */
4375 m->mdt_md_dev.md_lu_dev.ld_obd->obd_no_conn = 0;
4378 static int mdt_upcall(const struct lu_env *env, struct md_device *md,
4379 enum md_upcall_event ev)
4381 struct mdt_device *m = mdt_dev(&md->md_lu_dev);
4382 struct md_device *next = m->mdt_child;
4383 struct mdt_thread_info *mti;
4389 rc = next->md_ops->mdo_maxsize_get(env, next,
4391 &m->mdt_max_cookiesize);
4392 CDEBUG(D_INFO, "get max mdsize %d max cookiesize %d\n",
4393 m->mdt_max_mdsize, m->mdt_max_cookiesize);
4394 mdt_allow_cli(m, CONFIG_SYNC);
4397 mti = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
4398 mti->mti_no_need_trans = 1;
4399 CDEBUG(D_INFO, "disable mdt trans for this thread\n");
4402 /* Check that MDT is not yet configured */
4403 LASSERT(!m->mdt_fl_cfglog);
4406 CERROR("invalid event\n");
4413 static int mdt_obd_notify(struct obd_device *host,
4414 struct obd_device *watched,
4415 enum obd_notify_event ev, void *data)
4420 case OBD_NOTIFY_CONFIG:
4421 mdt_allow_cli(mdt_dev(host->obd_lu_dev), (unsigned int)data);
4424 CDEBUG(D_INFO, "Unhandled notification %#x\n", ev);
4429 static int mdt_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
4430 void *karg, void *uarg)
4433 struct obd_device *obd= exp->exp_obd;
4434 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
4435 struct dt_device *dt = mdt->mdt_bottom;
4439 CDEBUG(D_IOCTL, "handling ioctl cmd %#x\n", cmd);
4440 rc = lu_env_init(&env, NULL, LCT_MD_THREAD);
4446 rc = dt->dd_ops->dt_sync(&env, dt);
4448 case OBD_IOC_SET_READONLY:
4449 rc = dt->dd_ops->dt_sync(&env, dt);
4450 dt->dd_ops->dt_ro(&env, dt);
4452 case OBD_IOC_ABORT_RECOVERY:
4453 CERROR("Aborting recovery for device %s\n", obd->obd_name);
4454 target_stop_recovery_thread(obd);
4458 CERROR("Not supported cmd = %d for device %s\n",
4459 cmd, obd->obd_name);
4467 int mdt_postrecov(const struct lu_env *env, struct mdt_device *mdt)
4469 struct lu_device *ld = md2lu_dev(mdt->mdt_child);
4470 struct obd_device *obd = mdt->mdt_md_dev.md_lu_dev.ld_obd;
4473 /* if some clients didn't participate in recovery then we can possibly
4474 * lost sequence. Now we should increase sequence for safe value */
4475 lost = obd->obd_max_recoverable_clients - obd->obd_connected_clients;
4476 mdt_seq_adjust(env, mdt, lost);
4478 rc = ld->ld_ops->ldo_recovery_complete(env, ld);
4482 int mdt_obd_postrecov(struct obd_device *obd)
4487 rc = lu_env_init(&env, NULL, LCT_MD_THREAD);
4490 rc = mdt_postrecov(&env, mdt_dev(obd->obd_lu_dev));
4495 static struct obd_ops mdt_obd_device_ops = {
4496 .o_owner = THIS_MODULE,
4497 .o_connect = mdt_obd_connect,
4498 .o_reconnect = mdt_obd_reconnect,
4499 .o_disconnect = mdt_obd_disconnect,
4500 .o_init_export = mdt_init_export,
4501 .o_destroy_export = mdt_destroy_export,
4502 .o_iocontrol = mdt_iocontrol,
4503 .o_postrecov = mdt_obd_postrecov,
4504 .o_notify = mdt_obd_notify
4507 static struct lu_device* mdt_device_fini(const struct lu_env *env,
4508 struct lu_device *d)
4510 struct mdt_device *m = mdt_dev(d);
4517 static void mdt_device_free(const struct lu_env *env, struct lu_device *d)
4519 struct mdt_device *m = mdt_dev(d);
4524 static struct lu_device *mdt_device_alloc(const struct lu_env *env,
4525 struct lu_device_type *t,
4526 struct lustre_cfg *cfg)
4528 struct lu_device *l;
4529 struct mdt_device *m;
4535 l = &m->mdt_md_dev.md_lu_dev;
4536 rc = mdt_init0(env, m, t, cfg);
4542 md_upcall_init(&m->mdt_md_dev, mdt_upcall);
4544 l = ERR_PTR(-ENOMEM);
4548 /* context key constructor/destructor: mdt_key_init, mdt_key_fini */
4549 LU_KEY_INIT_FINI(mdt, struct mdt_thread_info);
4551 /* context key: mdt_thread_key */
4552 LU_CONTEXT_KEY_DEFINE(mdt, LCT_MD_THREAD);
4554 /* context key constructor/destructor: mdt_txn_key_init, mdt_txn_key_fini */
4555 LU_KEY_INIT_FINI(mdt_txn, struct mdt_txn_info);
4557 struct lu_context_key mdt_txn_key = {
4558 .lct_tags = LCT_TX_HANDLE,
4559 .lct_init = mdt_txn_key_init,
4560 .lct_fini = mdt_txn_key_fini
4563 struct md_ucred *mdt_ucred(const struct mdt_thread_info *info)
4565 return md_ucred(info->mti_env);
4568 /* type constructor/destructor: mdt_type_init, mdt_type_fini */
4569 LU_TYPE_INIT_FINI(mdt, &mdt_thread_key, &mdt_txn_key);
4571 static struct lu_device_type_operations mdt_device_type_ops = {
4572 .ldto_init = mdt_type_init,
4573 .ldto_fini = mdt_type_fini,
4575 .ldto_device_alloc = mdt_device_alloc,
4576 .ldto_device_free = mdt_device_free,
4577 .ldto_device_fini = mdt_device_fini
4580 static struct lu_device_type mdt_device_type = {
4581 .ldt_tags = LU_DEVICE_MD,
4582 .ldt_name = LUSTRE_MDT_NAME,
4583 .ldt_ops = &mdt_device_type_ops,
4584 .ldt_ctx_tags = LCT_MD_THREAD
4587 static int __init mdt_mod_init(void)
4589 struct lprocfs_static_vars lvars;
4592 mdt_num_threads = MDT_NUM_THREADS;
4593 lprocfs_init_vars(mdt, &lvars);
4594 rc = class_register_type(&mdt_obd_device_ops, NULL,
4595 lvars.module_vars, LUSTRE_MDT_NAME,
4601 static void __exit mdt_mod_exit(void)
4603 class_unregister_type(LUSTRE_MDT_NAME);
4607 #define DEF_HNDL(prefix, base, suffix, flags, opc, fn, fmt) \
4608 [prefix ## _ ## opc - prefix ## _ ## base] = { \
4610 .mh_fail_id = OBD_FAIL_ ## prefix ## _ ## opc ## suffix, \
4611 .mh_opc = prefix ## _ ## opc, \
4612 .mh_flags = flags, \
4617 #define DEF_MDT_HNDL(flags, name, fn, fmt) \
4618 DEF_HNDL(MDS, GETATTR, _NET, flags, name, fn, fmt)
4620 #define DEF_SEQ_HNDL(flags, name, fn, fmt) \
4621 DEF_HNDL(SEQ, QUERY, _NET, flags, name, fn, fmt)
4623 #define DEF_FLD_HNDL(flags, name, fn, fmt) \
4624 DEF_HNDL(FLD, QUERY, _NET, flags, name, fn, fmt)
4626 * Request with a format known in advance
4628 #define DEF_MDT_HNDL_F(flags, name, fn) \
4629 DEF_HNDL(MDS, GETATTR, _NET, flags, name, fn, &RQF_MDS_ ## name)
4631 #define DEF_SEQ_HNDL_F(flags, name, fn) \
4632 DEF_HNDL(SEQ, QUERY, _NET, flags, name, fn, &RQF_SEQ_ ## name)
4634 #define DEF_FLD_HNDL_F(flags, name, fn) \
4635 DEF_HNDL(FLD, QUERY, _NET, flags, name, fn, &RQF_FLD_ ## name)
4637 * Request with a format we do not yet know
4639 #define DEF_MDT_HNDL_0(flags, name, fn) \
4640 DEF_HNDL(MDS, GETATTR, _NET, flags, name, fn, NULL)
4642 static struct mdt_handler mdt_mds_ops[] = {
4643 DEF_MDT_HNDL_F(0, CONNECT, mdt_connect),
4644 DEF_MDT_HNDL_F(0, DISCONNECT, mdt_disconnect),
4645 DEF_MDT_HNDL_F(0, SET_INFO, mdt_set_info),
4646 DEF_MDT_HNDL_F(0 |HABEO_REFERO, GETSTATUS, mdt_getstatus),
4647 DEF_MDT_HNDL_F(HABEO_CORPUS, GETATTR, mdt_getattr),
4648 DEF_MDT_HNDL_F(HABEO_CORPUS|HABEO_REFERO, GETATTR_NAME, mdt_getattr_name),
4649 DEF_MDT_HNDL_F(HABEO_CORPUS|MUTABOR, SETXATTR, mdt_setxattr),
4650 DEF_MDT_HNDL_F(HABEO_CORPUS, GETXATTR, mdt_getxattr),
4651 DEF_MDT_HNDL_F(0 |HABEO_REFERO, STATFS, mdt_statfs),
4652 DEF_MDT_HNDL_F(0 |MUTABOR, REINT, mdt_reint),
4653 DEF_MDT_HNDL_F(HABEO_CORPUS, CLOSE, mdt_close),
4654 DEF_MDT_HNDL_F(HABEO_CORPUS, DONE_WRITING, mdt_done_writing),
4655 DEF_MDT_HNDL_F(0 |HABEO_REFERO, PIN, mdt_pin),
4656 DEF_MDT_HNDL_0(0, SYNC, mdt_sync),
4657 DEF_MDT_HNDL_F(HABEO_CORPUS|HABEO_REFERO, IS_SUBDIR, mdt_is_subdir),
4658 DEF_MDT_HNDL_0(0, QUOTACHECK, mdt_quotacheck_handle),
4659 DEF_MDT_HNDL_0(0, QUOTACTL, mdt_quotactl_handle)
4662 #define DEF_OBD_HNDL(flags, name, fn) \
4663 DEF_HNDL(OBD, PING, _NET, flags, name, fn, NULL)
4666 static struct mdt_handler mdt_obd_ops[] = {
4667 DEF_OBD_HNDL(0, PING, mdt_obd_ping),
4668 DEF_OBD_HNDL(0, LOG_CANCEL, mdt_obd_log_cancel),
4669 DEF_OBD_HNDL(0, QC_CALLBACK, mdt_obd_qc_callback)
4672 #define DEF_DLM_HNDL_0(flags, name, fn) \
4673 DEF_HNDL(LDLM, ENQUEUE, , flags, name, fn, NULL)
4674 #define DEF_DLM_HNDL_F(flags, name, fn) \
4675 DEF_HNDL(LDLM, ENQUEUE, , flags, name, fn, &RQF_LDLM_ ## name)
4677 static struct mdt_handler mdt_dlm_ops[] = {
4678 DEF_DLM_HNDL_F(HABEO_CLAVIS, ENQUEUE, mdt_enqueue),
4679 DEF_DLM_HNDL_0(HABEO_CLAVIS, CONVERT, mdt_convert),
4680 DEF_DLM_HNDL_0(0, BL_CALLBACK, mdt_bl_callback),
4681 DEF_DLM_HNDL_0(0, CP_CALLBACK, mdt_cp_callback)
4684 static struct mdt_handler mdt_llog_ops[] = {
4687 #define DEF_SEC_CTX_HNDL(name, fn) \
4688 DEF_HNDL(SEC_CTX, INIT, _NET, 0, name, fn, NULL)
4690 static struct mdt_handler mdt_sec_ctx_ops[] = {
4691 DEF_SEC_CTX_HNDL(INIT, mdt_sec_ctx_handle),
4692 DEF_SEC_CTX_HNDL(INIT_CONT, mdt_sec_ctx_handle),
4693 DEF_SEC_CTX_HNDL(FINI, mdt_sec_ctx_handle)
4696 static struct mdt_opc_slice mdt_regular_handlers[] = {
4698 .mos_opc_start = MDS_GETATTR,
4699 .mos_opc_end = MDS_LAST_OPC,
4700 .mos_hs = mdt_mds_ops
4703 .mos_opc_start = OBD_PING,
4704 .mos_opc_end = OBD_LAST_OPC,
4705 .mos_hs = mdt_obd_ops
4708 .mos_opc_start = LDLM_ENQUEUE,
4709 .mos_opc_end = LDLM_LAST_OPC,
4710 .mos_hs = mdt_dlm_ops
4713 .mos_opc_start = LLOG_ORIGIN_HANDLE_CREATE,
4714 .mos_opc_end = LLOG_LAST_OPC,
4715 .mos_hs = mdt_llog_ops
4718 .mos_opc_start = SEC_CTX_INIT,
4719 .mos_opc_end = SEC_LAST_OPC,
4720 .mos_hs = mdt_sec_ctx_ops
4727 static struct mdt_handler mdt_readpage_ops[] = {
4728 DEF_MDT_HNDL_F(0, CONNECT, mdt_connect),
4729 DEF_MDT_HNDL_F(HABEO_CORPUS|HABEO_REFERO, READPAGE, mdt_readpage),
4730 #ifdef HAVE_SPLIT_SUPPORT
4731 DEF_MDT_HNDL_F(HABEO_CORPUS|HABEO_REFERO, WRITEPAGE, mdt_writepage),
4735 * XXX: this is ugly and should be fixed one day, see mdc_close() for
4736 * detailed comments. --umka
4738 DEF_MDT_HNDL_F(HABEO_CORPUS, CLOSE, mdt_close),
4739 DEF_MDT_HNDL_F(HABEO_CORPUS, DONE_WRITING, mdt_done_writing),
4742 static struct mdt_opc_slice mdt_readpage_handlers[] = {
4744 .mos_opc_start = MDS_GETATTR,
4745 .mos_opc_end = MDS_LAST_OPC,
4746 .mos_hs = mdt_readpage_ops
4753 static struct mdt_handler mdt_xmds_ops[] = {
4754 DEF_MDT_HNDL_F(0, CONNECT, mdt_connect),
4755 DEF_MDT_HNDL_F(HABEO_CORPUS , GETATTR, mdt_getattr),
4756 DEF_MDT_HNDL_F(0 | MUTABOR , REINT, mdt_reint),
4757 DEF_MDT_HNDL_F(HABEO_CORPUS|HABEO_REFERO, IS_SUBDIR, mdt_is_subdir),
4760 static struct mdt_opc_slice mdt_xmds_handlers[] = {
4762 .mos_opc_start = MDS_GETATTR,
4763 .mos_opc_end = MDS_LAST_OPC,
4764 .mos_hs = mdt_xmds_ops
4767 .mos_opc_start = OBD_PING,
4768 .mos_opc_end = OBD_LAST_OPC,
4769 .mos_hs = mdt_obd_ops
4776 static struct mdt_handler mdt_seq_ops[] = {
4777 DEF_SEQ_HNDL_F(0, QUERY, (int (*)(struct mdt_thread_info *))seq_query)
4780 static struct mdt_opc_slice mdt_seq_handlers[] = {
4782 .mos_opc_start = SEQ_QUERY,
4783 .mos_opc_end = SEQ_LAST_OPC,
4784 .mos_hs = mdt_seq_ops
4791 static struct mdt_handler mdt_fld_ops[] = {
4792 DEF_FLD_HNDL_F(0, QUERY, (int (*)(struct mdt_thread_info *))fld_query)
4795 static struct mdt_opc_slice mdt_fld_handlers[] = {
4797 .mos_opc_start = FLD_QUERY,
4798 .mos_opc_end = FLD_LAST_OPC,
4799 .mos_hs = mdt_fld_ops
4806 MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
4807 MODULE_DESCRIPTION("Lustre Meta-data Target ("LUSTRE_MDT_NAME")");
4808 MODULE_LICENSE("GPL");
4810 CFS_MODULE_PARM(mdt_num_threads, "ul", ulong, 0444,
4811 "number of mdt service threads to start");
4813 cfs_module(mdt, "0.2.0", mdt_mod_init, mdt_mod_exit);