1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 only,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License version 2 for more details (a copy is included
16 * in the LICENSE file that accompanied this code).
18 * You should have received a copy of the GNU General Public License
19 * version 2 along with this program; If not, see
20 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
29 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
30 * Use is subject to license terms.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * lustre/mdt/mdt_handler.c
38 * Lustre Metadata Target (mdt) request handler
40 * Author: Peter Braam <braam@clusterfs.com>
41 * Author: Andreas Dilger <adilger@clusterfs.com>
42 * Author: Phil Schwan <phil@clusterfs.com>
43 * Author: Mike Shaver <shaver@clusterfs.com>
44 * Author: Nikita Danilov <nikita@clusterfs.com>
45 * Author: Huang Hua <huanghua@clusterfs.com>
46 * Author: Yury Umanets <umka@clusterfs.com>
50 # define EXPORT_SYMTAB
52 #define DEBUG_SUBSYSTEM S_MDS
54 #include <linux/module.h>
56 * struct OBD_{ALLOC,FREE}*()
58 #include <obd_support.h>
59 /* struct ptlrpc_request */
60 #include <lustre_net.h>
61 /* struct obd_export */
62 #include <lustre_export.h>
63 /* struct obd_device */
66 #include <dt_object.h>
67 #include <lustre_mds.h>
68 #include <lustre_mdt.h>
69 #include "mdt_internal.h"
70 #ifdef HAVE_QUOTA_SUPPORT
71 # include <lustre_quota.h>
73 #include <lustre_acl.h>
74 #include <lustre_param.h>
75 #include <lustre_fsfilt.h>
77 mdl_mode_t mdt_mdl_lock_modes[] = {
78 [LCK_MINMODE] = MDL_MINMODE,
85 [LCK_GROUP] = MDL_GROUP
88 ldlm_mode_t mdt_dlm_lock_modes[] = {
89 [MDL_MINMODE] = LCK_MINMODE,
96 [MDL_GROUP] = LCK_GROUP
100 * Initialized in mdt_mod_init().
102 static unsigned long mdt_num_threads;
103 static unsigned long mdt_min_threads;
104 static unsigned long mdt_max_threads;
106 /* ptlrpc request handler for MDT. All handlers are
107 * grouped into several slices - struct mdt_opc_slice,
108 * and stored in an array - mdt_handlers[].
111 /* The name of this handler. */
113 /* Fail id for this handler, checked at the beginning of this handler*/
115 /* Operation code for this handler */
117 /* flags are listed in enum mdt_handler_flags below. */
119 /* The actual handler function to execute. */
120 int (*mh_act)(struct mdt_thread_info *info);
121 /* Request format for this request. */
122 const struct req_format *mh_fmt;
125 enum mdt_handler_flags {
127 * struct mdt_body is passed in the incoming message, and object
128 * identified by this fid exists on disk.
130 * "habeo corpus" == "I have a body"
132 HABEO_CORPUS = (1 << 0),
134 * struct ldlm_request is passed in the incoming message.
136 * "habeo clavis" == "I have a key"
138 HABEO_CLAVIS = (1 << 1),
140 * this request has fixed reply format, so that reply message can be
141 * packed by generic code.
143 * "habeo refero" == "I have a reply"
145 HABEO_REFERO = (1 << 2),
147 * this request will modify something, so check whether the filesystem
148 * is readonly or not, then return -EROFS to client asap if necessary.
150 * "mutabor" == "I shall modify"
155 struct mdt_opc_slice {
158 struct mdt_handler *mos_hs;
161 static struct mdt_opc_slice mdt_regular_handlers[];
162 static struct mdt_opc_slice mdt_readpage_handlers[];
163 static struct mdt_opc_slice mdt_xmds_handlers[];
164 static struct mdt_opc_slice mdt_seq_handlers[];
165 static struct mdt_opc_slice mdt_fld_handlers[];
167 static struct mdt_device *mdt_dev(struct lu_device *d);
168 static int mdt_regular_handle(struct ptlrpc_request *req);
169 static int mdt_unpack_req_pack_rep(struct mdt_thread_info *info, __u32 flags);
170 static int mdt_fid2path(const struct lu_env *env, struct mdt_device *mdt,
171 struct getinfo_fid2path *fp);
173 static const struct lu_object_operations mdt_obj_ops;
175 int mdt_get_disposition(struct ldlm_reply *rep, int flag)
179 return (rep->lock_policy_res1 & flag);
182 void mdt_clear_disposition(struct mdt_thread_info *info,
183 struct ldlm_reply *rep, int flag)
186 info->mti_opdata &= ~flag;
188 rep->lock_policy_res1 &= ~flag;
191 void mdt_set_disposition(struct mdt_thread_info *info,
192 struct ldlm_reply *rep, int flag)
195 info->mti_opdata |= flag;
197 rep->lock_policy_res1 |= flag;
200 void mdt_lock_reg_init(struct mdt_lock_handle *lh, ldlm_mode_t lm)
202 lh->mlh_pdo_hash = 0;
203 lh->mlh_reg_mode = lm;
204 lh->mlh_type = MDT_REG_LOCK;
207 void mdt_lock_pdo_init(struct mdt_lock_handle *lh, ldlm_mode_t lm,
208 const char *name, int namelen)
210 lh->mlh_reg_mode = lm;
211 lh->mlh_type = MDT_PDO_LOCK;
214 LASSERT(namelen > 0);
215 lh->mlh_pdo_hash = full_name_hash(name, namelen);
217 LASSERT(namelen == 0);
218 lh->mlh_pdo_hash = 0ull;
222 static void mdt_lock_pdo_mode(struct mdt_thread_info *info, struct mdt_object *o,
223 struct mdt_lock_handle *lh)
229 * Any dir access needs couple of locks:
231 * 1) on part of dir we gonna take lookup/modify;
233 * 2) on whole dir to protect it from concurrent splitting and/or to
234 * flush client's cache for readdir().
236 * so, for a given mode and object this routine decides what lock mode
237 * to use for lock #2:
239 * 1) if caller's gonna lookup in dir then we need to protect dir from
240 * being splitted only - LCK_CR
242 * 2) if caller's gonna modify dir then we need to protect dir from
243 * being splitted and to flush cache - LCK_CW
245 * 3) if caller's gonna modify dir and that dir seems ready for
246 * splitting then we need to protect it from any type of access
247 * (lookup/modify/split) - LCK_EX --bzzz
250 LASSERT(lh->mlh_reg_mode != LCK_MINMODE);
251 LASSERT(lh->mlh_pdo_mode == LCK_MINMODE);
254 * Ask underlaying level its opinion about preferable PDO lock mode
255 * having access type passed as regular lock mode:
257 * - MDL_MINMODE means that lower layer does not want to specify lock
260 * - MDL_NL means that no PDO lock should be taken. This is used in some
261 * cases. Say, for non-splittable directories no need to use PDO locks
264 mode = mdo_lock_mode(info->mti_env, mdt_object_child(o),
265 mdt_dlm_mode2mdl_mode(lh->mlh_reg_mode));
267 if (mode != MDL_MINMODE) {
268 lh->mlh_pdo_mode = mdt_mdl_mode2dlm_mode(mode);
271 * Lower layer does not want to specify locking mode. We do it
272 * our selves. No special protection is needed, just flush
273 * client's cache on modification and allow concurrent
276 switch (lh->mlh_reg_mode) {
278 lh->mlh_pdo_mode = LCK_EX;
281 lh->mlh_pdo_mode = LCK_CR;
284 lh->mlh_pdo_mode = LCK_CW;
287 CERROR("Not expected lock type (0x%x)\n",
288 (int)lh->mlh_reg_mode);
293 LASSERT(lh->mlh_pdo_mode != LCK_MINMODE);
297 static int mdt_getstatus(struct mdt_thread_info *info)
299 struct mdt_device *mdt = info->mti_mdt;
300 struct md_device *next = mdt->mdt_child;
301 struct mdt_body *repbody;
306 rc = mdt_check_ucred(info);
308 RETURN(err_serious(rc));
310 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_GETSTATUS_PACK))
311 RETURN(err_serious(-ENOMEM));
313 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
314 rc = next->md_ops->mdo_root_get(info->mti_env, next, &repbody->fid1);
318 repbody->valid |= OBD_MD_FLID;
320 if (mdt->mdt_opts.mo_mds_capa &&
321 info->mti_exp->exp_connect_flags & OBD_CONNECT_MDS_CAPA) {
322 struct mdt_object *root;
323 struct lustre_capa *capa;
325 root = mdt_object_find(info->mti_env, mdt, &repbody->fid1);
327 RETURN(PTR_ERR(root));
329 capa = req_capsule_server_get(info->mti_pill, &RMF_CAPA1);
331 capa->lc_opc = CAPA_OPC_MDS_DEFAULT;
332 rc = mo_capa_get(info->mti_env, mdt_object_child(root), capa,
334 mdt_object_put(info->mti_env, root);
336 repbody->valid |= OBD_MD_FLMDSCAPA;
342 static int mdt_statfs(struct mdt_thread_info *info)
344 struct md_device *next = info->mti_mdt->mdt_child;
345 struct ptlrpc_service *svc;
346 struct obd_statfs *osfs;
351 svc = info->mti_pill->rc_req->rq_rqbd->rqbd_service;
353 /* This will trigger a watchdog timeout */
354 OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_STATFS_LCW_SLEEP,
355 (MDT_SERVICE_WATCHDOG_FACTOR *
356 at_get(&svc->srv_at_estimate)) + 1);
358 rc = mdt_check_ucred(info);
360 RETURN(err_serious(rc));
362 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_STATFS_PACK)) {
363 rc = err_serious(-ENOMEM);
365 osfs = req_capsule_server_get(info->mti_pill, &RMF_OBD_STATFS);
366 rc = next->md_ops->mdo_statfs(info->mti_env, next,
368 statfs_pack(osfs, &info->mti_u.ksfs);
374 * Pack SOM attributes into the reply.
375 * Call under a DLM UPDATE lock.
377 static void mdt_pack_size2body(struct mdt_thread_info *info,
378 struct mdt_object *mo)
381 struct md_attr *ma = &info->mti_attr;
383 LASSERT(ma->ma_attr.la_valid & LA_MODE);
384 b = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
386 /* Check if Size-on-MDS is supported, if this is a regular file,
387 * if SOM is enabled on the object and if SOM cache exists and valid.
388 * Otherwise do not pack Size-on-MDS attributes to the reply. */
389 if (!(mdt_conn_flags(info) & OBD_CONNECT_SOM) ||
390 !S_ISREG(ma->ma_attr.la_mode) ||
391 !mdt_object_is_som_enabled(mo) ||
392 !(ma->ma_valid & MA_SOM))
395 b->valid |= OBD_MD_FLSIZE | OBD_MD_FLBLOCKS;
396 b->size = ma->ma_som->msd_size;
397 b->blocks = ma->ma_som->msd_blocks;
400 void mdt_pack_attr2body(struct mdt_thread_info *info, struct mdt_body *b,
401 const struct lu_attr *attr, const struct lu_fid *fid)
403 struct md_attr *ma = &info->mti_attr;
405 LASSERT(ma->ma_valid & MA_INODE);
407 b->atime = attr->la_atime;
408 b->mtime = attr->la_mtime;
409 b->ctime = attr->la_ctime;
410 b->mode = attr->la_mode;
411 b->size = attr->la_size;
412 b->blocks = attr->la_blocks;
413 b->uid = attr->la_uid;
414 b->gid = attr->la_gid;
415 b->flags = attr->la_flags;
416 b->nlink = attr->la_nlink;
417 b->rdev = attr->la_rdev;
419 /*XXX should pack the reply body according to lu_valid*/
420 b->valid |= OBD_MD_FLCTIME | OBD_MD_FLUID |
421 OBD_MD_FLGID | OBD_MD_FLTYPE |
422 OBD_MD_FLMODE | OBD_MD_FLNLINK | OBD_MD_FLFLAGS |
423 OBD_MD_FLATIME | OBD_MD_FLMTIME ;
425 if (!S_ISREG(attr->la_mode)) {
426 b->valid |= OBD_MD_FLSIZE | OBD_MD_FLBLOCKS | OBD_MD_FLRDEV;
427 } else if (ma->ma_need & MA_LOV && ma->ma_lmm_size == 0) {
428 /* means no objects are allocated on osts. */
429 LASSERT(!(ma->ma_valid & MA_LOV));
430 /* just ignore blocks occupied by extend attributes on MDS */
432 /* if no object is allocated on osts, the size on mds is valid. b=22272 */
433 b->valid |= OBD_MD_FLSIZE | OBD_MD_FLBLOCKS;
438 b->valid |= OBD_MD_FLID;
440 /* FIXME: these should be fixed when new igif ready.*/
441 b->ino = fid_oid(fid); /* 1.6 compatibility */
442 b->generation = fid_ver(fid); /* 1.6 compatibility */
443 b->valid |= OBD_MD_FLGENER; /* 1.6 compatibility */
445 CDEBUG(D_INODE, DFID": nlink=%d, mode=%o, size="LPU64"\n",
446 PFID(fid), b->nlink, b->mode, b->size);
450 mdt_body_reverse_idmap(info, b);
452 if (b->valid & OBD_MD_FLSIZE)
453 CDEBUG(D_VFSTRACE, DFID": returning size %llu\n",
454 PFID(fid), (unsigned long long)b->size);
457 static inline int mdt_body_has_lov(const struct lu_attr *la,
458 const struct mdt_body *body)
460 return ((S_ISREG(la->la_mode) && (body->valid & OBD_MD_FLEASIZE)) ||
461 (S_ISDIR(la->la_mode) && (body->valid & OBD_MD_FLDIREA )) );
464 static int mdt_getattr_internal(struct mdt_thread_info *info,
465 struct mdt_object *o, int ma_need)
467 struct md_object *next = mdt_object_child(o);
468 const struct mdt_body *reqbody = info->mti_body;
469 struct ptlrpc_request *req = mdt_info_req(info);
470 struct md_attr *ma = &info->mti_attr;
471 struct lu_attr *la = &ma->ma_attr;
472 struct req_capsule *pill = info->mti_pill;
473 const struct lu_env *env = info->mti_env;
474 struct mdt_body *repbody;
475 struct lu_buf *buffer = &info->mti_buf;
479 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_GETATTR_PACK))
480 RETURN(err_serious(-ENOMEM));
482 repbody = req_capsule_server_get(pill, &RMF_MDT_BODY);
486 rc = mdt_object_exists(o);
488 /* This object is located on remote node.*/
489 repbody->fid1 = *mdt_object_fid(o);
490 repbody->valid = OBD_MD_FLID | OBD_MD_MDS;
494 buffer->lb_buf = req_capsule_server_get(pill, &RMF_MDT_MD);
495 buffer->lb_len = req_capsule_get_size(pill, &RMF_MDT_MD, RCL_SERVER);
497 /* If it is dir object and client require MEA, then we got MEA */
498 if (S_ISDIR(lu_object_attr(&next->mo_lu)) &&
499 reqbody->valid & OBD_MD_MEA) {
500 /* Assumption: MDT_MD size is enough for lmv size. */
501 ma->ma_lmv = buffer->lb_buf;
502 ma->ma_lmv_size = buffer->lb_len;
503 ma->ma_need = MA_LMV | MA_INODE;
505 ma->ma_lmm = buffer->lb_buf;
506 ma->ma_lmm_size = buffer->lb_len;
507 ma->ma_need = MA_LOV | MA_INODE;
510 if (S_ISDIR(lu_object_attr(&next->mo_lu)) &&
511 reqbody->valid & OBD_MD_FLDIREA &&
512 lustre_msg_get_opc(req->rq_reqmsg) == MDS_GETATTR) {
513 /* get default stripe info for this dir. */
514 ma->ma_need |= MA_LOV_DEF;
516 ma->ma_need |= ma_need;
517 if (ma->ma_need & MA_SOM)
518 ma->ma_som = &info->mti_u.som.data;
520 rc = mo_attr_get(env, next, ma);
522 CERROR("getattr error for "DFID": %d\n",
523 PFID(mdt_object_fid(o)), rc);
527 if (likely(ma->ma_valid & MA_INODE))
528 mdt_pack_attr2body(info, repbody, la, mdt_object_fid(o));
532 if (mdt_body_has_lov(la, reqbody)) {
533 if (ma->ma_valid & MA_LOV) {
534 LASSERT(ma->ma_lmm_size);
535 mdt_dump_lmm(D_INFO, ma->ma_lmm);
536 repbody->eadatasize = ma->ma_lmm_size;
537 if (S_ISDIR(la->la_mode))
538 repbody->valid |= OBD_MD_FLDIREA;
540 repbody->valid |= OBD_MD_FLEASIZE;
542 if (ma->ma_valid & MA_LMV) {
543 LASSERT(S_ISDIR(la->la_mode));
544 repbody->eadatasize = ma->ma_lmv_size;
545 repbody->valid |= (OBD_MD_FLDIREA|OBD_MD_MEA);
547 } else if (S_ISLNK(la->la_mode) &&
548 reqbody->valid & OBD_MD_LINKNAME) {
549 buffer->lb_buf = ma->ma_lmm;
550 buffer->lb_len = reqbody->eadatasize;
551 rc = mo_readlink(env, next, buffer);
552 if (unlikely(rc <= 0)) {
553 CERROR("readlink failed: %d\n", rc);
556 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_READLINK_EPROTO))
558 repbody->valid |= OBD_MD_LINKNAME;
559 repbody->eadatasize = rc;
561 ((char*)ma->ma_lmm)[rc - 1] = 0;
562 CDEBUG(D_INODE, "symlink dest %s, len = %d\n",
563 (char*)ma->ma_lmm, rc);
568 if (reqbody->valid & OBD_MD_FLMODEASIZE) {
569 repbody->max_cookiesize = info->mti_mdt->mdt_max_cookiesize;
570 repbody->max_mdsize = info->mti_mdt->mdt_max_mdsize;
571 repbody->valid |= OBD_MD_FLMODEASIZE;
572 CDEBUG(D_INODE, "I am going to change the MAX_MD_SIZE & "
573 "MAX_COOKIE to : %d:%d\n", repbody->max_mdsize,
574 repbody->max_cookiesize);
577 if (exp_connect_rmtclient(info->mti_exp) &&
578 reqbody->valid & OBD_MD_FLRMTPERM) {
579 void *buf = req_capsule_server_get(pill, &RMF_ACL);
581 /* mdt_getattr_lock only */
582 rc = mdt_pack_remote_perm(info, o, buf);
584 repbody->valid &= ~OBD_MD_FLRMTPERM;
585 repbody->aclsize = 0;
588 repbody->valid |= OBD_MD_FLRMTPERM;
589 repbody->aclsize = sizeof(struct mdt_remote_perm);
592 #ifdef CONFIG_FS_POSIX_ACL
593 else if ((req->rq_export->exp_connect_flags & OBD_CONNECT_ACL) &&
594 (reqbody->valid & OBD_MD_FLACL)) {
595 buffer->lb_buf = req_capsule_server_get(pill, &RMF_ACL);
596 buffer->lb_len = req_capsule_get_size(pill,
597 &RMF_ACL, RCL_SERVER);
598 if (buffer->lb_len > 0) {
599 rc = mo_xattr_get(env, next, buffer,
600 XATTR_NAME_ACL_ACCESS);
602 if (rc == -ENODATA) {
603 repbody->aclsize = 0;
604 repbody->valid |= OBD_MD_FLACL;
606 } else if (rc == -EOPNOTSUPP) {
609 CERROR("got acl size: %d\n", rc);
612 repbody->aclsize = rc;
613 repbody->valid |= OBD_MD_FLACL;
620 if (reqbody->valid & OBD_MD_FLMDSCAPA &&
621 info->mti_mdt->mdt_opts.mo_mds_capa &&
622 info->mti_exp->exp_connect_flags & OBD_CONNECT_MDS_CAPA) {
623 struct lustre_capa *capa;
625 capa = req_capsule_server_get(pill, &RMF_CAPA1);
627 capa->lc_opc = CAPA_OPC_MDS_DEFAULT;
628 rc = mo_capa_get(env, next, capa, 0);
631 repbody->valid |= OBD_MD_FLMDSCAPA;
636 static int mdt_renew_capa(struct mdt_thread_info *info)
638 struct mdt_object *obj = info->mti_object;
639 struct mdt_body *body;
640 struct lustre_capa *capa, *c;
644 /* if object doesn't exist, or server has disabled capability,
645 * return directly, client will find body->valid OBD_MD_FLOSSCAPA
648 if (!obj || !info->mti_mdt->mdt_opts.mo_oss_capa ||
649 !(info->mti_exp->exp_connect_flags & OBD_CONNECT_OSS_CAPA))
652 body = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
653 LASSERT(body != NULL);
655 c = req_capsule_client_get(info->mti_pill, &RMF_CAPA1);
658 capa = req_capsule_server_get(info->mti_pill, &RMF_CAPA2);
662 rc = mo_capa_get(info->mti_env, mdt_object_child(obj), capa, 1);
664 body->valid |= OBD_MD_FLOSSCAPA;
668 static int mdt_getattr(struct mdt_thread_info *info)
670 struct mdt_object *obj = info->mti_object;
671 struct req_capsule *pill = info->mti_pill;
672 struct mdt_body *reqbody;
673 struct mdt_body *repbody;
679 reqbody = req_capsule_client_get(pill, &RMF_MDT_BODY);
682 if (reqbody->valid & OBD_MD_FLOSSCAPA) {
683 rc = req_capsule_server_pack(pill);
685 RETURN(err_serious(rc));
686 rc = mdt_renew_capa(info);
687 GOTO(out_shrink, rc);
690 LASSERT(obj != NULL);
691 LASSERT(lu_object_assert_exists(&obj->mot_obj.mo_lu));
693 mode = lu_object_attr(&obj->mot_obj.mo_lu);
694 if (S_ISLNK(mode) && (reqbody->valid & OBD_MD_LINKNAME) &&
695 (reqbody->eadatasize > info->mti_mdt->mdt_max_mdsize))
696 md_size = reqbody->eadatasize;
698 md_size = info->mti_mdt->mdt_max_mdsize;
700 req_capsule_set_size(pill, &RMF_MDT_MD, RCL_SERVER, md_size);
702 rc = req_capsule_server_pack(pill);
703 if (unlikely(rc != 0))
704 RETURN(err_serious(rc));
706 repbody = req_capsule_server_get(pill, &RMF_MDT_BODY);
707 LASSERT(repbody != NULL);
708 repbody->eadatasize = 0;
709 repbody->aclsize = 0;
711 if (reqbody->valid & OBD_MD_FLRMTPERM)
712 rc = mdt_init_ucred(info, reqbody);
714 rc = mdt_check_ucred(info);
716 GOTO(out_shrink, rc);
718 info->mti_spec.sp_ck_split = !!(reqbody->valid & OBD_MD_FLCKSPLIT);
719 info->mti_cross_ref = !!(reqbody->valid & OBD_MD_FLCROSSREF);
722 * Don't check capability at all, because rename might getattr for
723 * remote obj, and at that time no capability is available.
725 mdt_set_capainfo(info, 1, &reqbody->fid1, BYPASS_CAPA);
726 rc = mdt_getattr_internal(info, obj, 0);
727 if (reqbody->valid & OBD_MD_FLRMTPERM)
728 mdt_exit_ucred(info);
731 mdt_shrink_reply(info);
735 static int mdt_is_subdir(struct mdt_thread_info *info)
737 struct mdt_object *o = info->mti_object;
738 struct req_capsule *pill = info->mti_pill;
739 const struct mdt_body *body = info->mti_body;
740 struct mdt_body *repbody;
746 repbody = req_capsule_server_get(pill, &RMF_MDT_BODY);
749 * We save last checked parent fid to @repbody->fid1 for remote
752 LASSERT(fid_is_sane(&body->fid2));
753 LASSERT(mdt_object_exists(o) > 0);
754 rc = mdo_is_subdir(info->mti_env, mdt_object_child(o),
755 &body->fid2, &repbody->fid1);
756 if (rc == 0 || rc == -EREMOTE)
757 repbody->valid |= OBD_MD_FLID;
762 static int mdt_raw_lookup(struct mdt_thread_info *info,
763 struct mdt_object *parent,
764 const struct lu_name *lname,
765 struct ldlm_reply *ldlm_rep)
767 struct md_object *next = mdt_object_child(info->mti_object);
768 const struct mdt_body *reqbody = info->mti_body;
769 struct lu_fid *child_fid = &info->mti_tmp_fid1;
770 struct mdt_body *repbody;
774 if (reqbody->valid != OBD_MD_FLID)
777 LASSERT(!info->mti_cross_ref);
779 /* Only got the fid of this obj by name */
780 rc = mdo_lookup(info->mti_env, next, lname, child_fid,
783 /* XXX is raw_lookup possible as intent operation? */
786 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_NEG);
789 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_POS);
791 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
794 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
795 repbody->fid1 = *child_fid;
796 repbody->valid = OBD_MD_FLID;
802 * UPDATE lock should be taken against parent, and be release before exit;
803 * child_bits lock should be taken against child, and be returned back:
804 * (1)normal request should release the child lock;
805 * (2)intent request will grant the lock to client.
807 static int mdt_getattr_name_lock(struct mdt_thread_info *info,
808 struct mdt_lock_handle *lhc,
810 struct ldlm_reply *ldlm_rep)
812 struct ptlrpc_request *req = mdt_info_req(info);
813 struct mdt_body *reqbody = NULL;
814 struct mdt_object *parent = info->mti_object;
815 struct mdt_object *child;
816 struct md_object *next = mdt_object_child(parent);
817 struct lu_fid *child_fid = &info->mti_tmp_fid1;
818 struct lu_name *lname = NULL;
819 const char *name = NULL;
821 struct mdt_lock_handle *lhp;
822 struct ldlm_lock *lock;
823 struct ldlm_res_id *res_id;
830 is_resent = lustre_handle_is_used(&lhc->mlh_reg_lh);
831 LASSERT(ergo(is_resent,
832 lustre_msg_get_flags(req->rq_reqmsg) & MSG_RESENT));
834 LASSERT(parent != NULL);
835 name = req_capsule_client_get(info->mti_pill, &RMF_NAME);
837 RETURN(err_serious(-EFAULT));
839 namelen = req_capsule_get_size(info->mti_pill, &RMF_NAME,
841 if (!info->mti_cross_ref) {
843 * XXX: Check for "namelen == 0" is for getattr by fid
844 * (OBD_CONNECT_ATTRFID), otherwise do not allow empty name,
845 * that is the name must contain at least one character and
846 * the terminating '\0'
849 reqbody = req_capsule_client_get(info->mti_pill,
851 LASSERT(fid_is_sane(&reqbody->fid2));
854 CDEBUG(D_INODE, "getattr with lock for "DFID"/"DFID", "
856 PFID(mdt_object_fid(parent)), PFID(&reqbody->fid2),
859 lname = mdt_name(info->mti_env, (char *)name, namelen);
860 CDEBUG(D_INODE, "getattr with lock for "DFID"/%s, "
861 "ldlm_rep = %p\n", PFID(mdt_object_fid(parent)),
865 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_EXECD);
867 rc = mdt_object_exists(parent);
868 if (unlikely(rc == 0)) {
869 LU_OBJECT_DEBUG(D_WARNING, info->mti_env,
870 &parent->mot_obj.mo_lu,
871 "Parent doesn't exist!\n");
873 } else if (!info->mti_cross_ref) {
874 LASSERTF(rc > 0, "Parent "DFID" is on remote server\n",
875 PFID(mdt_object_fid(parent)));
878 rc = mdt_raw_lookup(info, parent, lname, ldlm_rep);
886 if (info->mti_cross_ref) {
887 /* Only getattr on the child. Parent is on another node. */
888 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_POS);
890 CDEBUG(D_INODE, "partial getattr_name child_fid = "DFID", "
891 "ldlm_rep=%p\n", PFID(mdt_object_fid(child)), ldlm_rep);
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);
898 LASSERT(fid_res_name_eq(mdt_object_fid(child),
899 &lock->l_resource->lr_name));
903 mdt_lock_handle_init(lhc);
904 mdt_lock_reg_init(lhc, LCK_PR);
907 * Object's name is on another MDS, no lookup lock is
908 * needed here but update is.
910 child_bits &= ~MDS_INODELOCK_LOOKUP;
911 child_bits |= MDS_INODELOCK_UPDATE;
913 rc = mdt_object_lock(info, child, lhc, child_bits,
917 /* Finally, we can get attr for child. */
918 mdt_set_capainfo(info, 0, mdt_object_fid(child),
920 rc = mdt_getattr_internal(info, child, 0);
921 if (unlikely(rc != 0))
922 mdt_object_unlock(info, child, lhc, 1);
927 /* step 1: lock parent */
928 lhp = &info->mti_lh[MDT_LH_PARENT];
929 mdt_lock_pdo_init(lhp, LCK_PR, name, namelen);
930 rc = mdt_object_lock(info, parent, lhp, MDS_INODELOCK_UPDATE,
933 if (unlikely(rc != 0))
937 /* step 2: lookup child's fid by name */
938 rc = mdo_lookup(info->mti_env, next, lname, child_fid,
943 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_NEG);
944 GOTO(out_parent, rc);
946 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_POS);
948 *child_fid = reqbody->fid2;
949 mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_POS);
953 *step 3: find the child object by fid & lock it.
954 * regardless if it is local or remote.
956 child = mdt_object_find(info->mti_env, info->mti_mdt, child_fid);
958 if (unlikely(IS_ERR(child)))
959 GOTO(out_parent, rc = PTR_ERR(child));
961 /* Do not take lock for resent case. */
962 lock = ldlm_handle2lock(&lhc->mlh_reg_lh);
963 LASSERTF(lock != NULL, "Invalid lock handle "LPX64"\n",
964 lhc->mlh_reg_lh.cookie);
966 res_id = &lock->l_resource->lr_name;
967 if (!fid_res_name_eq(mdt_object_fid(child),
968 &lock->l_resource->lr_name)) {
969 LASSERTF(fid_res_name_eq(mdt_object_fid(parent),
970 &lock->l_resource->lr_name),
971 "Lock res_id: %lu/%lu/%lu, Fid: "DFID".\n",
972 (unsigned long)res_id->name[0],
973 (unsigned long)res_id->name[1],
974 (unsigned long)res_id->name[2],
975 PFID(mdt_object_fid(parent)));
976 CWARN("Although resent, but still not get child lock"
977 "parent:"DFID" child:"DFID"\n",
978 PFID(mdt_object_fid(parent)),
979 PFID(mdt_object_fid(child)));
980 lustre_msg_clear_flags(req->rq_reqmsg, MSG_RESENT);
989 ma = &info->mti_attr;
991 OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_RESEND, obd_timeout*2);
992 mdt_lock_handle_init(lhc);
993 mdt_lock_reg_init(lhc, LCK_PR);
995 if (mdt_object_exists(child) == 0) {
996 LU_OBJECT_DEBUG(D_WARNING, info->mti_env,
997 &child->mot_obj.mo_lu,
998 "Object doesn't exist!\n");
999 GOTO(out_child, rc = -ESTALE);
1003 ma->ma_need = MA_INODE;
1004 rc = mo_attr_get(info->mti_env, next, ma);
1005 if (unlikely(rc != 0))
1006 GOTO(out_child, rc);
1008 /* If the file has not been changed for some time, we return
1009 * not only a LOOKUP lock, but also an UPDATE lock and this
1010 * might save us RPC on later STAT. For directories, it also
1011 * let negative dentry starts working for this dir. */
1012 if (ma->ma_valid & MA_INODE &&
1013 ma->ma_attr.la_valid & LA_CTIME &&
1014 info->mti_mdt->mdt_namespace->ns_ctime_age_limit +
1015 ma->ma_attr.la_ctime < cfs_time_current_sec())
1016 child_bits |= MDS_INODELOCK_UPDATE;
1018 rc = mdt_object_lock(info, child, lhc, child_bits,
1021 if (unlikely(rc != 0))
1022 GOTO(out_child, rc);
1025 lock = ldlm_handle2lock(&lhc->mlh_reg_lh);
1026 /* Get MA_SOM attributes if update lock is given. */
1028 lock->l_policy_data.l_inodebits.bits & MDS_INODELOCK_UPDATE &&
1029 S_ISREG(lu_object_attr(&mdt_object_child(child)->mo_lu)))
1032 /* finally, we can get attr for child. */
1033 mdt_set_capainfo(info, 1, child_fid, BYPASS_CAPA);
1034 rc = mdt_getattr_internal(info, child, ma_need);
1035 if (unlikely(rc != 0)) {
1036 mdt_object_unlock(info, child, lhc, 1);
1038 /* Debugging code. */
1039 res_id = &lock->l_resource->lr_name;
1040 LDLM_DEBUG(lock, "Returning lock to client");
1041 LASSERTF(fid_res_name_eq(mdt_object_fid(child),
1042 &lock->l_resource->lr_name),
1043 "Lock res_id: %lu/%lu/%lu, Fid: "DFID".\n",
1044 (unsigned long)res_id->name[0],
1045 (unsigned long)res_id->name[1],
1046 (unsigned long)res_id->name[2],
1047 PFID(mdt_object_fid(child)));
1048 mdt_pack_size2body(info, child);
1051 LDLM_LOCK_PUT(lock);
1055 mdt_object_put(info->mti_env, child);
1057 mdt_object_unlock(info, parent, lhp, 1);
1061 /* normal handler: should release the child lock */
1062 static int mdt_getattr_name(struct mdt_thread_info *info)
1064 struct mdt_lock_handle *lhc = &info->mti_lh[MDT_LH_CHILD];
1065 struct mdt_body *reqbody;
1066 struct mdt_body *repbody;
1070 reqbody = req_capsule_client_get(info->mti_pill, &RMF_MDT_BODY);
1071 LASSERT(reqbody != NULL);
1072 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
1073 LASSERT(repbody != NULL);
1075 info->mti_spec.sp_ck_split = !!(reqbody->valid & OBD_MD_FLCKSPLIT);
1076 info->mti_cross_ref = !!(reqbody->valid & OBD_MD_FLCROSSREF);
1077 repbody->eadatasize = 0;
1078 repbody->aclsize = 0;
1080 rc = mdt_init_ucred(info, reqbody);
1082 GOTO(out_shrink, rc);
1084 rc = mdt_getattr_name_lock(info, lhc, MDS_INODELOCK_UPDATE, NULL);
1085 if (lustre_handle_is_used(&lhc->mlh_reg_lh)) {
1086 ldlm_lock_decref(&lhc->mlh_reg_lh, lhc->mlh_reg_mode);
1087 lhc->mlh_reg_lh.cookie = 0;
1089 mdt_exit_ucred(info);
1092 mdt_shrink_reply(info);
1096 static const struct lu_device_operations mdt_lu_ops;
1098 static int lu_device_is_mdt(struct lu_device *d)
1100 return ergo(d != NULL && d->ld_ops != NULL, d->ld_ops == &mdt_lu_ops);
1103 static int mdt_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
1104 void *karg, void *uarg);
1106 static int mdt_set_info(struct mdt_thread_info *info)
1108 struct ptlrpc_request *req = mdt_info_req(info);
1111 int keylen, vallen, rc = 0;
1114 rc = req_capsule_server_pack(info->mti_pill);
1118 key = req_capsule_client_get(info->mti_pill, &RMF_SETINFO_KEY);
1120 DEBUG_REQ(D_HA, req, "no set_info key");
1124 keylen = req_capsule_get_size(info->mti_pill, &RMF_SETINFO_KEY,
1127 val = req_capsule_client_get(info->mti_pill, &RMF_SETINFO_VAL);
1129 DEBUG_REQ(D_HA, req, "no set_info val");
1133 vallen = req_capsule_get_size(info->mti_pill, &RMF_SETINFO_VAL,
1136 /* Swab any part of val you need to here */
1137 if (KEY_IS(KEY_READ_ONLY)) {
1139 lustre_msg_set_status(req->rq_repmsg, 0);
1141 cfs_spin_lock(&req->rq_export->exp_lock);
1143 req->rq_export->exp_connect_flags |= OBD_CONNECT_RDONLY;
1145 req->rq_export->exp_connect_flags &=~OBD_CONNECT_RDONLY;
1146 cfs_spin_unlock(&req->rq_export->exp_lock);
1148 } else if (KEY_IS(KEY_CHANGELOG_CLEAR)) {
1149 struct changelog_setinfo *cs =
1150 (struct changelog_setinfo *)val;
1151 if (vallen != sizeof(*cs)) {
1152 CERROR("Bad changelog_clear setinfo size %d\n", vallen);
1155 if (ptlrpc_req_need_swab(req)) {
1156 __swab64s(&cs->cs_recno);
1157 __swab32s(&cs->cs_id);
1160 rc = mdt_iocontrol(OBD_IOC_CHANGELOG_CLEAR, info->mti_exp,
1162 lustre_msg_set_status(req->rq_repmsg, rc);
1170 static int mdt_connect(struct mdt_thread_info *info)
1173 struct ptlrpc_request *req;
1175 req = mdt_info_req(info);
1176 rc = target_handle_connect(req);
1178 LASSERT(req->rq_export != NULL);
1179 info->mti_mdt = mdt_dev(req->rq_export->exp_obd->obd_lu_dev);
1180 rc = mdt_init_sec_level(info);
1182 rc = mdt_init_idmap(info);
1184 obd_disconnect(class_export_get(req->rq_export));
1186 rc = err_serious(rc);
1191 static int mdt_disconnect(struct mdt_thread_info *info)
1196 rc = target_handle_disconnect(mdt_info_req(info));
1198 rc = err_serious(rc);
1202 static int mdt_sendpage(struct mdt_thread_info *info,
1203 struct lu_rdpg *rdpg)
1205 struct ptlrpc_request *req = mdt_info_req(info);
1206 struct obd_export *exp = req->rq_export;
1207 struct ptlrpc_bulk_desc *desc;
1208 struct l_wait_info *lwi = &info->mti_u.rdpg.mti_wait_info;
1216 desc = ptlrpc_prep_bulk_exp(req, rdpg->rp_npages, BULK_PUT_SOURCE,
1221 for (i = 0, tmpcount = rdpg->rp_count;
1222 i < rdpg->rp_npages; i++, tmpcount -= tmpsize) {
1223 tmpsize = min_t(int, tmpcount, CFS_PAGE_SIZE);
1224 ptlrpc_prep_bulk_page(desc, rdpg->rp_pages[i], 0, tmpsize);
1227 LASSERT(desc->bd_nob == rdpg->rp_count);
1228 rc = sptlrpc_svc_wrap_bulk(req, desc);
1230 GOTO(free_desc, rc);
1232 rc = ptlrpc_start_bulk_transfer(desc);
1234 GOTO(free_desc, rc);
1236 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_SENDPAGE))
1237 GOTO(abort_bulk, rc = 0);
1240 timeout = (int) req->rq_deadline - cfs_time_current_sec();
1242 CERROR("Req deadline already passed %lu (now: %lu)\n",
1243 req->rq_deadline, cfs_time_current_sec());
1244 *lwi = LWI_TIMEOUT_INTERVAL(cfs_time_seconds(max(timeout, 1)),
1245 cfs_time_seconds(1), NULL, NULL);
1246 rc = l_wait_event(desc->bd_waitq,
1247 !ptlrpc_server_bulk_active(desc) ||
1249 exp->exp_abort_active_req, lwi);
1250 LASSERT (rc == 0 || rc == -ETIMEDOUT);
1251 } while ((rc == -ETIMEDOUT) &&
1252 (req->rq_deadline > cfs_time_current_sec()));
1255 if (desc->bd_success &&
1256 desc->bd_nob_transferred == rdpg->rp_count)
1257 GOTO(free_desc, rc);
1260 if (exp->exp_abort_active_req || exp->exp_failed)
1261 GOTO(abort_bulk, rc);
1264 DEBUG_REQ(D_ERROR, req, "bulk failed: %s %d(%d), evicting %s@%s",
1265 (rc == -ETIMEDOUT) ? "timeout" : "network error",
1266 desc->bd_nob_transferred, rdpg->rp_count,
1267 exp->exp_client_uuid.uuid,
1268 exp->exp_connection->c_remote_uuid.uuid);
1270 class_fail_export(exp);
1274 ptlrpc_abort_bulk(desc);
1276 ptlrpc_free_bulk(desc);
1280 #ifdef HAVE_SPLIT_SUPPORT
1282 * Retrieve dir entry from the page and insert it to the slave object, actually,
1283 * this should be in osd layer, but since it will not in the final product, so
1284 * just do it here and do not define more moo api anymore for this.
1286 static int mdt_write_dir_page(struct mdt_thread_info *info, struct page *page,
1289 struct mdt_object *object = info->mti_object;
1290 struct lu_fid *lf = &info->mti_tmp_fid2;
1291 struct md_attr *ma = &info->mti_attr;
1292 struct lu_dirpage *dp;
1293 struct lu_dirent *ent;
1294 int rc = 0, offset = 0;
1297 /* Make sure we have at least one entry. */
1302 * Disable trans for this name insert, since it will include many trans
1305 info->mti_no_need_trans = 1;
1307 * When write_dir_page, no need update parent's ctime,
1308 * and no permission check for name_insert.
1310 ma->ma_attr.la_ctime = 0;
1311 ma->ma_attr.la_valid = LA_MODE;
1312 ma->ma_valid = MA_INODE;
1315 dp = page_address(page);
1316 offset = (int)((__u32)lu_dirent_start(dp) - (__u32)dp);
1318 for (ent = lu_dirent_start(dp); ent != NULL;
1319 ent = lu_dirent_next(ent)) {
1320 struct lu_name *lname;
1323 if (le16_to_cpu(ent->lde_namelen) == 0)
1326 fid_le_to_cpu(lf, &ent->lde_fid);
1327 if (le64_to_cpu(ent->lde_hash) & MAX_HASH_HIGHEST_BIT)
1328 ma->ma_attr.la_mode = S_IFDIR;
1330 ma->ma_attr.la_mode = 0;
1331 OBD_ALLOC(name, le16_to_cpu(ent->lde_namelen) + 1);
1333 GOTO(out, rc = -ENOMEM);
1335 memcpy(name, ent->lde_name, le16_to_cpu(ent->lde_namelen));
1336 lname = mdt_name(info->mti_env, name,
1337 le16_to_cpu(ent->lde_namelen));
1338 ma->ma_attr_flags |= (MDS_PERM_BYPASS | MDS_QUOTA_IGNORE);
1339 rc = mdo_name_insert(info->mti_env,
1340 md_object_next(&object->mot_obj),
1342 OBD_FREE(name, le16_to_cpu(ent->lde_namelen) + 1);
1344 CERROR("Can't insert %*.*s, rc %d\n",
1345 le16_to_cpu(ent->lde_namelen),
1346 le16_to_cpu(ent->lde_namelen),
1351 offset += lu_dirent_size(ent);
1361 static int mdt_bulk_timeout(void *data)
1365 CERROR("mdt bulk transfer timeout \n");
1370 static int mdt_writepage(struct mdt_thread_info *info)
1372 struct ptlrpc_request *req = mdt_info_req(info);
1373 struct mdt_body *reqbody;
1374 struct l_wait_info *lwi;
1375 struct ptlrpc_bulk_desc *desc;
1381 reqbody = req_capsule_client_get(info->mti_pill, &RMF_MDT_BODY);
1382 if (reqbody == NULL)
1383 RETURN(err_serious(-EFAULT));
1385 desc = ptlrpc_prep_bulk_exp(req, 1, BULK_GET_SINK, MDS_BULK_PORTAL);
1387 RETURN(err_serious(-ENOMEM));
1389 /* allocate the page for the desc */
1390 page = cfs_alloc_page(CFS_ALLOC_STD);
1392 GOTO(desc_cleanup, rc = -ENOMEM);
1394 CDEBUG(D_INFO, "Received page offset %d size %d \n",
1395 (int)reqbody->size, (int)reqbody->nlink);
1397 ptlrpc_prep_bulk_page(desc, page, (int)reqbody->size,
1398 (int)reqbody->nlink);
1400 rc = sptlrpc_svc_prep_bulk(req, desc);
1402 GOTO(cleanup_page, rc);
1404 * Check if client was evicted while we were doing i/o before touching
1409 GOTO(cleanup_page, rc = -ENOMEM);
1411 if (desc->bd_export->exp_failed)
1414 rc = ptlrpc_start_bulk_transfer (desc);
1416 *lwi = LWI_TIMEOUT_INTERVAL(obd_timeout * CFS_HZ / 4, CFS_HZ,
1417 mdt_bulk_timeout, desc);
1418 rc = l_wait_event(desc->bd_waitq, !ptlrpc_bulk_active(desc) ||
1419 desc->bd_export->exp_failed, lwi);
1420 LASSERT(rc == 0 || rc == -ETIMEDOUT);
1421 if (rc == -ETIMEDOUT) {
1422 DEBUG_REQ(D_ERROR, req, "timeout on bulk GET");
1423 ptlrpc_abort_bulk(desc);
1424 } else if (desc->bd_export->exp_failed) {
1425 DEBUG_REQ(D_ERROR, req, "Eviction on bulk GET");
1427 ptlrpc_abort_bulk(desc);
1428 } else if (!desc->bd_success ||
1429 desc->bd_nob_transferred != desc->bd_nob) {
1430 DEBUG_REQ(D_ERROR, req, "%s bulk GET %d(%d)",
1432 "truncated" : "network error on",
1433 desc->bd_nob_transferred, desc->bd_nob);
1434 /* XXX should this be a different errno? */
1438 DEBUG_REQ(D_ERROR, req, "ptlrpc_bulk_get failed: rc %d", rc);
1441 GOTO(cleanup_lwi, rc);
1442 rc = mdt_write_dir_page(info, page, reqbody->nlink);
1447 cfs_free_page(page);
1449 ptlrpc_free_bulk(desc);
1454 static int mdt_readpage(struct mdt_thread_info *info)
1456 struct mdt_object *object = info->mti_object;
1457 struct lu_rdpg *rdpg = &info->mti_u.rdpg.mti_rdpg;
1458 struct mdt_body *reqbody;
1459 struct mdt_body *repbody;
1464 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_READPAGE_PACK))
1465 RETURN(err_serious(-ENOMEM));
1467 reqbody = req_capsule_client_get(info->mti_pill, &RMF_MDT_BODY);
1468 repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
1469 if (reqbody == NULL || repbody == NULL)
1470 RETURN(err_serious(-EFAULT));
1473 * prepare @rdpg before calling lower layers and transfer itself. Here
1474 * reqbody->size contains offset of where to start to read and
1475 * reqbody->nlink contains number bytes to read.
1477 rdpg->rp_hash = reqbody->size;
1478 if (rdpg->rp_hash != reqbody->size) {
1479 CERROR("Invalid hash: "LPX64" != "LPX64"\n",
1480 rdpg->rp_hash, reqbody->size);
1484 rdpg->rp_attrs = reqbody->mode;
1485 rdpg->rp_count = reqbody->nlink;
1486 rdpg->rp_npages = (rdpg->rp_count + CFS_PAGE_SIZE - 1)>>CFS_PAGE_SHIFT;
1487 OBD_ALLOC(rdpg->rp_pages, rdpg->rp_npages * sizeof rdpg->rp_pages[0]);
1488 if (rdpg->rp_pages == NULL)
1491 for (i = 0; i < rdpg->rp_npages; ++i) {
1492 rdpg->rp_pages[i] = cfs_alloc_page(CFS_ALLOC_STD);
1493 if (rdpg->rp_pages[i] == NULL)
1494 GOTO(free_rdpg, rc = -ENOMEM);
1497 /* call lower layers to fill allocated pages with directory data */
1498 rc = mo_readpage(info->mti_env, mdt_object_child(object), rdpg);
1500 GOTO(free_rdpg, rc);
1502 /* send pages to client */
1503 rc = mdt_sendpage(info, rdpg);
1508 for (i = 0; i < rdpg->rp_npages; i++)
1509 if (rdpg->rp_pages[i] != NULL)
1510 cfs_free_page(rdpg->rp_pages[i]);
1511 OBD_FREE(rdpg->rp_pages, rdpg->rp_npages * sizeof rdpg->rp_pages[0]);
1513 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_SENDPAGE))
1519 static int mdt_reint_internal(struct mdt_thread_info *info,
1520 struct mdt_lock_handle *lhc,
1523 struct req_capsule *pill = info->mti_pill;
1524 struct mdt_device *mdt = info->mti_mdt;
1525 struct md_quota *mq = md_quota(info->mti_env);
1526 struct mdt_body *repbody;
1531 if (req_capsule_has_field(pill, &RMF_MDT_MD, RCL_SERVER))
1532 req_capsule_set_size(pill, &RMF_MDT_MD, RCL_SERVER,
1533 mdt->mdt_max_mdsize);
1534 if (req_capsule_has_field(pill, &RMF_LOGCOOKIES, RCL_SERVER))
1535 req_capsule_set_size(pill, &RMF_LOGCOOKIES, RCL_SERVER,
1536 mdt->mdt_max_cookiesize);
1538 rc = req_capsule_server_pack(pill);
1540 CERROR("Can't pack response, rc %d\n", rc);
1541 RETURN(err_serious(rc));
1544 if (req_capsule_has_field(pill, &RMF_MDT_BODY, RCL_SERVER)) {
1545 repbody = req_capsule_server_get(pill, &RMF_MDT_BODY);
1547 repbody->eadatasize = 0;
1548 repbody->aclsize = 0;
1551 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_REINT_UNPACK))
1552 GOTO(out_shrink, rc = err_serious(-EFAULT));
1554 rc = mdt_reint_unpack(info, op);
1556 CERROR("Can't unpack reint, rc %d\n", rc);
1557 GOTO(out_shrink, rc = err_serious(rc));
1560 OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_REINT_DELAY, 10);
1562 /* for replay no cookkie / lmm need, because client have this already */
1563 if (info->mti_spec.no_create == 1) {
1564 if (req_capsule_has_field(pill, &RMF_MDT_MD, RCL_SERVER))
1565 req_capsule_set_size(pill, &RMF_MDT_MD, RCL_SERVER, 0);
1567 if (req_capsule_has_field(pill, &RMF_LOGCOOKIES, RCL_SERVER))
1568 req_capsule_set_size(pill, &RMF_LOGCOOKIES, RCL_SERVER,
1572 rc = mdt_init_ucred_reint(info);
1574 GOTO(out_shrink, rc);
1576 rc = mdt_fix_attr_ucred(info, op);
1578 GOTO(out_ucred, rc = err_serious(rc));
1580 if (mdt_check_resent(info, mdt_reconstruct, lhc)) {
1581 rc = lustre_msg_get_status(mdt_info_req(info)->rq_repmsg);
1582 GOTO(out_ucred, rc);
1584 mq->mq_exp = info->mti_exp;
1585 rc = mdt_reint_rec(info, lhc);
1588 mdt_exit_ucred(info);
1590 mdt_shrink_reply(info);
1594 static long mdt_reint_opcode(struct mdt_thread_info *info,
1595 const struct req_format **fmt)
1597 struct mdt_rec_reint *rec;
1600 opc = err_serious(-EFAULT);
1601 rec = req_capsule_client_get(info->mti_pill, &RMF_REC_REINT);
1603 opc = rec->rr_opcode;
1604 DEBUG_REQ(D_INODE, mdt_info_req(info), "reint opt = %ld", opc);
1605 if (opc < REINT_MAX && fmt[opc] != NULL)
1606 req_capsule_extend(info->mti_pill, fmt[opc]);
1608 CERROR("Unsupported opc: %ld\n", opc);
1609 opc = err_serious(opc);
1615 static int mdt_reint(struct mdt_thread_info *info)
1620 static const struct req_format *reint_fmts[REINT_MAX] = {
1621 [REINT_SETATTR] = &RQF_MDS_REINT_SETATTR,
1622 [REINT_CREATE] = &RQF_MDS_REINT_CREATE,
1623 [REINT_LINK] = &RQF_MDS_REINT_LINK,
1624 [REINT_UNLINK] = &RQF_MDS_REINT_UNLINK,
1625 [REINT_RENAME] = &RQF_MDS_REINT_RENAME,
1626 [REINT_OPEN] = &RQF_MDS_REINT_OPEN,
1627 [REINT_SETXATTR] = &RQF_MDS_REINT_SETXATTR
1632 opc = mdt_reint_opcode(info, reint_fmts);
1635 * No lock possible here from client to pass it to reint code
1638 rc = mdt_reint_internal(info, NULL, opc);
1643 info->mti_fail_id = OBD_FAIL_MDS_REINT_NET_REP;
1647 /* this should sync the whole device */
1648 static int mdt_device_sync(const struct lu_env *env, struct mdt_device *mdt)
1650 struct dt_device *dt = mdt->mdt_bottom;
1654 rc = dt->dd_ops->dt_sync(env, dt);
1658 /* this should sync this object */
1659 static int mdt_object_sync(struct mdt_thread_info *info)
1661 struct md_object *next;
1665 if (!mdt_object_exists(info->mti_object)) {
1666 CWARN("Non existing object "DFID"!\n",
1667 PFID(mdt_object_fid(info->mti_object)));
1670 next = mdt_object_child(info->mti_object);
1671 rc = mo_object_sync(info->mti_env, next);
1676 static int mdt_sync(struct mdt_thread_info *info)
1678 struct req_capsule *pill = info->mti_pill;
1679 struct mdt_body *body;
1683 /* The fid may be zero, so we req_capsule_set manually */
1684 req_capsule_set(pill, &RQF_MDS_SYNC);
1686 body = req_capsule_client_get(pill, &RMF_MDT_BODY);
1688 RETURN(err_serious(-EINVAL));
1690 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_SYNC_PACK))
1691 RETURN(err_serious(-ENOMEM));
1693 if (fid_seq(&body->fid1) == 0) {
1694 /* sync the whole device */
1695 rc = req_capsule_server_pack(pill);
1697 rc = mdt_device_sync(info->mti_env, info->mti_mdt);
1699 rc = err_serious(rc);
1701 /* sync an object */
1702 rc = mdt_unpack_req_pack_rep(info, HABEO_CORPUS|HABEO_REFERO);
1704 rc = mdt_object_sync(info);
1706 struct md_object *next;
1707 const struct lu_fid *fid;
1708 struct lu_attr *la = &info->mti_attr.ma_attr;
1710 next = mdt_object_child(info->mti_object);
1711 info->mti_attr.ma_need = MA_INODE;
1712 info->mti_attr.ma_valid = 0;
1713 rc = mo_attr_get(info->mti_env, next,
1716 body = req_capsule_server_get(pill,
1718 fid = mdt_object_fid(info->mti_object);
1719 mdt_pack_attr2body(info, body, la, fid);
1723 rc = err_serious(rc);
1728 #ifdef HAVE_QUOTA_SUPPORT
1729 static int mdt_quotacheck_handle(struct mdt_thread_info *info)
1731 struct obd_quotactl *oqctl;
1732 struct req_capsule *pill = info->mti_pill;
1733 struct obd_export *exp = info->mti_exp;
1734 struct md_quota *mq = md_quota(info->mti_env);
1735 struct md_device *next = info->mti_mdt->mdt_child;
1739 oqctl = req_capsule_client_get(pill, &RMF_OBD_QUOTACTL);
1743 /* remote client has no permission for quotacheck */
1744 if (unlikely(exp_connect_rmtclient(exp)))
1747 rc = req_capsule_server_pack(pill);
1752 rc = next->md_ops->mdo_quota.mqo_check(info->mti_env, next,
1757 static int mdt_quotactl_handle(struct mdt_thread_info *info)
1759 struct obd_quotactl *oqctl, *repoqc;
1760 struct req_capsule *pill = info->mti_pill;
1761 struct obd_export *exp = info->mti_exp;
1762 struct md_quota *mq = md_quota(info->mti_env);
1763 struct md_device *next = info->mti_mdt->mdt_child;
1764 const struct md_quota_operations *mqo = &next->md_ops->mdo_quota;
1768 oqctl = req_capsule_client_get(pill, &RMF_OBD_QUOTACTL);
1773 if (exp_connect_rmtclient(exp)) {
1774 struct ptlrpc_request *req = mdt_info_req(info);
1775 struct mdt_export_data *med = mdt_req2med(req);
1776 struct lustre_idmap_table *idmap = med->med_idmap;
1778 if (unlikely(oqctl->qc_cmd != Q_GETQUOTA &&
1779 oqctl->qc_cmd != Q_GETINFO))
1783 if (oqctl->qc_type == USRQUOTA)
1784 id = lustre_idmap_lookup_uid(NULL, idmap, 0,
1786 else if (oqctl->qc_type == GRPQUOTA)
1787 id = lustre_idmap_lookup_gid(NULL, idmap, 0,
1792 if (id == CFS_IDMAP_NOTFOUND) {
1793 CDEBUG(D_QUOTA, "no mapping for id %u\n",
1799 rc = req_capsule_server_pack(pill);
1803 repoqc = req_capsule_server_get(pill, &RMF_OBD_QUOTACTL);
1804 LASSERT(repoqc != NULL);
1807 switch (oqctl->qc_cmd) {
1809 rc = mqo->mqo_on(info->mti_env, next, oqctl->qc_type);
1812 rc = mqo->mqo_off(info->mti_env, next, oqctl->qc_type);
1815 rc = mqo->mqo_setinfo(info->mti_env, next, oqctl->qc_type, id,
1819 rc = mqo->mqo_getinfo(info->mti_env, next, oqctl->qc_type, id,
1823 rc = mqo->mqo_setquota(info->mti_env, next, oqctl->qc_type, id,
1827 rc = mqo->mqo_getquota(info->mti_env, next, oqctl->qc_type, id,
1831 rc = mqo->mqo_getoinfo(info->mti_env, next, oqctl->qc_type, id,
1835 rc = mqo->mqo_getoquota(info->mti_env, next, oqctl->qc_type, id,
1838 case LUSTRE_Q_INVALIDATE:
1839 rc = mqo->mqo_invalidate(info->mti_env, next, oqctl->qc_type);
1841 case LUSTRE_Q_FINVALIDATE:
1842 rc = mqo->mqo_finvalidate(info->mti_env, next, oqctl->qc_type);
1845 CERROR("unsupported mdt_quotactl command: %d\n",
1857 * OBD PING and other handlers.
1859 static int mdt_obd_ping(struct mdt_thread_info *info)
1864 req_capsule_set(info->mti_pill, &RQF_OBD_PING);
1866 rc = target_handle_ping(mdt_info_req(info));
1868 rc = err_serious(rc);
1872 static int mdt_obd_log_cancel(struct mdt_thread_info *info)
1874 return err_serious(-EOPNOTSUPP);
1877 static int mdt_obd_qc_callback(struct mdt_thread_info *info)
1879 return err_serious(-EOPNOTSUPP);
1887 /** clone llog ctxt from child (mdd)
1888 * This allows remote llog (replicator) access.
1889 * We can either pass all llog RPCs (eg mdt_llog_create) on to child where the
1890 * context was originally set up, or we can handle them directly.
1891 * I choose the latter, but that means I need any llog
1892 * contexts set up by child to be accessable by the mdt. So we clone the
1893 * context into our context list here.
1895 static int mdt_llog_ctxt_clone(const struct lu_env *env, struct mdt_device *mdt,
1898 struct md_device *next = mdt->mdt_child;
1899 struct llog_ctxt *ctxt;
1902 if (!llog_ctxt_null(mdt2obd_dev(mdt), idx))
1905 rc = next->md_ops->mdo_llog_ctxt_get(env, next, idx, (void **)&ctxt);
1906 if (rc || ctxt == NULL) {
1907 CERROR("Can't get mdd ctxt %d\n", rc);
1911 rc = llog_group_set_ctxt(&mdt2obd_dev(mdt)->obd_olg, ctxt, idx);
1913 CERROR("Can't set mdt ctxt %d\n", rc);
1918 static int mdt_llog_ctxt_unclone(const struct lu_env *env,
1919 struct mdt_device *mdt, int idx)
1921 struct llog_ctxt *ctxt;
1923 ctxt = llog_get_context(mdt2obd_dev(mdt), idx);
1926 /* Put once for the get we just did, and once for the clone */
1927 llog_ctxt_put(ctxt);
1928 llog_ctxt_put(ctxt);
1932 static int mdt_llog_create(struct mdt_thread_info *info)
1936 req_capsule_set(info->mti_pill, &RQF_LLOG_ORIGIN_HANDLE_CREATE);
1937 rc = llog_origin_handle_create(mdt_info_req(info));
1938 return (rc < 0 ? err_serious(rc) : rc);
1941 static int mdt_llog_destroy(struct mdt_thread_info *info)
1945 req_capsule_set(info->mti_pill, &RQF_LLOG_ORIGIN_HANDLE_DESTROY);
1946 rc = llog_origin_handle_destroy(mdt_info_req(info));
1947 return (rc < 0 ? err_serious(rc) : rc);
1950 static int mdt_llog_read_header(struct mdt_thread_info *info)
1954 req_capsule_set(info->mti_pill, &RQF_LLOG_ORIGIN_HANDLE_READ_HEADER);
1955 rc = llog_origin_handle_read_header(mdt_info_req(info));
1956 return (rc < 0 ? err_serious(rc) : rc);
1959 static int mdt_llog_next_block(struct mdt_thread_info *info)
1963 req_capsule_set(info->mti_pill, &RQF_LLOG_ORIGIN_HANDLE_NEXT_BLOCK);
1964 rc = llog_origin_handle_next_block(mdt_info_req(info));
1965 return (rc < 0 ? err_serious(rc) : rc);
1968 static int mdt_llog_prev_block(struct mdt_thread_info *info)
1972 req_capsule_set(info->mti_pill, &RQF_LLOG_ORIGIN_HANDLE_PREV_BLOCK);
1973 rc = llog_origin_handle_prev_block(mdt_info_req(info));
1974 return (rc < 0 ? err_serious(rc) : rc);
1981 static struct ldlm_callback_suite cbs = {
1982 .lcs_completion = ldlm_server_completion_ast,
1983 .lcs_blocking = ldlm_server_blocking_ast,
1987 static int mdt_enqueue(struct mdt_thread_info *info)
1989 struct ptlrpc_request *req;
1993 * info->mti_dlm_req already contains swapped and (if necessary)
1994 * converted dlm request.
1996 LASSERT(info->mti_dlm_req != NULL);
1998 req = mdt_info_req(info);
1999 rc = ldlm_handle_enqueue0(info->mti_mdt->mdt_namespace,
2000 req, info->mti_dlm_req, &cbs);
2001 info->mti_fail_id = OBD_FAIL_LDLM_REPLY;
2002 return rc ? err_serious(rc) : req->rq_status;
2005 static int mdt_convert(struct mdt_thread_info *info)
2008 struct ptlrpc_request *req;
2010 LASSERT(info->mti_dlm_req);
2011 req = mdt_info_req(info);
2012 rc = ldlm_handle_convert0(req, info->mti_dlm_req);
2013 return rc ? err_serious(rc) : req->rq_status;
2016 static int mdt_bl_callback(struct mdt_thread_info *info)
2018 CERROR("bl callbacks should not happen on MDS\n");
2020 return err_serious(-EOPNOTSUPP);
2023 static int mdt_cp_callback(struct mdt_thread_info *info)
2025 CERROR("cp callbacks should not happen on MDS\n");
2027 return err_serious(-EOPNOTSUPP);
2031 * sec context handlers
2033 static int mdt_sec_ctx_handle(struct mdt_thread_info *info)
2037 rc = mdt_handle_idmap(info);
2040 struct ptlrpc_request *req = mdt_info_req(info);
2043 opc = lustre_msg_get_opc(req->rq_reqmsg);
2044 if (opc == SEC_CTX_INIT || opc == SEC_CTX_INIT_CONT)
2045 sptlrpc_svc_ctx_invalidate(req);
2048 OBD_FAIL_TIMEOUT(OBD_FAIL_SEC_CTX_HDL_PAUSE, obd_fail_val);
2053 static struct mdt_object *mdt_obj(struct lu_object *o)
2055 LASSERT(lu_device_is_mdt(o->lo_dev));
2056 return container_of0(o, struct mdt_object, mot_obj.mo_lu);
2059 struct mdt_object *mdt_object_find(const struct lu_env *env,
2060 struct mdt_device *d,
2061 const struct lu_fid *f)
2063 struct lu_object *o;
2064 struct mdt_object *m;
2067 CDEBUG(D_INFO, "Find object for "DFID"\n", PFID(f));
2068 o = lu_object_find(env, &d->mdt_md_dev.md_lu_dev, f, NULL);
2069 if (unlikely(IS_ERR(o)))
2070 m = (struct mdt_object *)o;
2077 * Asyncronous commit for mdt device.
2079 * Pass asynchonous commit call down the MDS stack.
2081 * \param env environment
2082 * \param mdt the mdt device
2084 static void mdt_device_commit_async(const struct lu_env *env,
2085 struct mdt_device *mdt)
2087 struct dt_device *dt = mdt->mdt_bottom;
2090 rc = dt->dd_ops->dt_commit_async(env, dt);
2091 if (unlikely(rc != 0))
2092 CWARN("async commit start failed with rc = %d", rc);
2096 * Mark the lock as "synchonous".
2098 * Mark the lock to deffer transaction commit to the unlock time.
2100 * \param lock the lock to mark as "synchonous"
2102 * \see mdt_is_lock_sync
2103 * \see mdt_save_lock
2105 static inline void mdt_set_lock_sync(struct ldlm_lock *lock)
2107 lock->l_ast_data = (void*)1;
2111 * Check whehter the lock "synchonous" or not.
2113 * \param lock the lock to check
2114 * \retval 1 the lock is "synchonous"
2115 * \retval 0 the lock isn't "synchronous"
2117 * \see mdt_set_lock_sync
2118 * \see mdt_save_lock
2120 static inline int mdt_is_lock_sync(struct ldlm_lock *lock)
2122 return lock->l_ast_data != NULL;
2126 * Blocking AST for mdt locks.
2128 * Starts transaction commit if in case of COS lock conflict or
2129 * deffers such a commit to the mdt_save_lock.
2131 * \param lock the lock which blocks a request or cancelling lock
2132 * \param desc unused
2133 * \param data unused
2134 * \param flag indicates whether this cancelling or blocking callback
2136 * \see ldlm_blocking_ast_nocheck
2138 int mdt_blocking_ast(struct ldlm_lock *lock, struct ldlm_lock_desc *desc,
2139 void *data, int flag)
2141 struct obd_device *obd = ldlm_lock_to_ns(lock)->ns_obd;
2142 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
2146 if (flag == LDLM_CB_CANCELING)
2148 lock_res_and_lock(lock);
2149 if (lock->l_blocking_ast != mdt_blocking_ast) {
2150 unlock_res_and_lock(lock);
2153 if (mdt_cos_is_enabled(mdt) &&
2154 lock->l_req_mode & (LCK_PW | LCK_EX) &&
2155 lock->l_blocking_lock != NULL &&
2156 lock->l_client_cookie != lock->l_blocking_lock->l_client_cookie) {
2157 mdt_set_lock_sync(lock);
2159 rc = ldlm_blocking_ast_nocheck(lock);
2161 /* There is no lock conflict if l_blocking_lock == NULL,
2162 * it indicates a blocking ast sent from ldlm_lock_decref_internal
2163 * when the last reference to a local lock was released */
2164 if (lock->l_req_mode == LCK_COS && lock->l_blocking_lock != NULL) {
2167 rc = lu_env_init(&env, LCT_MD_THREAD);
2168 if (unlikely(rc != 0))
2169 CWARN("lu_env initialization failed with rc = %d,"
2170 "cannot start asynchronous commit\n", rc);
2172 mdt_device_commit_async(&env, mdt);
2178 int mdt_object_lock(struct mdt_thread_info *info, struct mdt_object *o,
2179 struct mdt_lock_handle *lh, __u64 ibits, int locality)
2181 struct ldlm_namespace *ns = info->mti_mdt->mdt_namespace;
2182 ldlm_policy_data_t *policy = &info->mti_policy;
2183 struct ldlm_res_id *res_id = &info->mti_res_id;
2187 LASSERT(!lustre_handle_is_used(&lh->mlh_reg_lh));
2188 LASSERT(!lustre_handle_is_used(&lh->mlh_pdo_lh));
2189 LASSERT(lh->mlh_reg_mode != LCK_MINMODE);
2190 LASSERT(lh->mlh_type != MDT_NUL_LOCK);
2192 if (mdt_object_exists(o) < 0) {
2193 if (locality == MDT_CROSS_LOCK) {
2194 /* cross-ref object fix */
2195 ibits &= ~MDS_INODELOCK_UPDATE;
2196 ibits |= MDS_INODELOCK_LOOKUP;
2198 LASSERT(!(ibits & MDS_INODELOCK_UPDATE));
2199 LASSERT(ibits & MDS_INODELOCK_LOOKUP);
2201 /* No PDO lock on remote object */
2202 LASSERT(lh->mlh_type != MDT_PDO_LOCK);
2205 if (lh->mlh_type == MDT_PDO_LOCK) {
2206 /* check for exists after object is locked */
2207 if (mdt_object_exists(o) == 0) {
2208 /* Non-existent object shouldn't have PDO lock */
2211 /* Non-dir object shouldn't have PDO lock */
2212 if (!S_ISDIR(lu_object_attr(&o->mot_obj.mo_lu)))
2217 memset(policy, 0, sizeof(*policy));
2218 fid_build_reg_res_name(mdt_object_fid(o), res_id);
2221 * Take PDO lock on whole directory and build correct @res_id for lock
2222 * on part of directory.
2224 if (lh->mlh_pdo_hash != 0) {
2225 LASSERT(lh->mlh_type == MDT_PDO_LOCK);
2226 mdt_lock_pdo_mode(info, o, lh);
2227 if (lh->mlh_pdo_mode != LCK_NL) {
2229 * Do not use LDLM_FL_LOCAL_ONLY for parallel lock, it
2230 * is never going to be sent to client and we do not
2231 * want it slowed down due to possible cancels.
2233 policy->l_inodebits.bits = MDS_INODELOCK_UPDATE;
2234 rc = mdt_fid_lock(ns, &lh->mlh_pdo_lh, lh->mlh_pdo_mode,
2235 policy, res_id, LDLM_FL_ATOMIC_CB,
2236 &info->mti_exp->exp_handle.h_cookie);
2242 * Finish res_id initializing by name hash marking part of
2243 * directory which is taking modification.
2245 res_id->name[LUSTRE_RES_ID_HSH_OFF] = lh->mlh_pdo_hash;
2248 policy->l_inodebits.bits = ibits;
2251 * Use LDLM_FL_LOCAL_ONLY for this lock. We do not know yet if it is
2252 * going to be sent to client. If it is - mdt_intent_policy() path will
2253 * fix it up and turn FL_LOCAL flag off.
2255 rc = mdt_fid_lock(ns, &lh->mlh_reg_lh, lh->mlh_reg_mode, policy,
2256 res_id, LDLM_FL_LOCAL_ONLY | LDLM_FL_ATOMIC_CB,
2257 &info->mti_exp->exp_handle.h_cookie);
2259 mdt_object_unlock(info, o, lh, 1);
2260 else if (unlikely(OBD_FAIL_PRECHECK(OBD_FAIL_MDS_PDO_LOCK)) &&
2261 lh->mlh_pdo_hash != 0 &&
2262 (lh->mlh_reg_mode == LCK_PW || lh->mlh_reg_mode == LCK_EX)) {
2263 OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_PDO_LOCK, 10);
2270 * Save a lock within request object.
2272 * Keep the lock referenced until whether client ACK or transaction
2273 * commit happens or release the lock immediately depending on input
2274 * parameters. If COS is ON, a write lock is converted to COS lock
2277 * \param info thead info object
2278 * \param h lock handle
2279 * \param mode lock mode
2280 * \param decref force immediate lock releasing
2283 void mdt_save_lock(struct mdt_thread_info *info, struct lustre_handle *h,
2284 ldlm_mode_t mode, int decref)
2288 if (lustre_handle_is_used(h)) {
2289 if (decref || !info->mti_has_trans ||
2290 !(mode & (LCK_PW | LCK_EX))){
2291 mdt_fid_unlock(h, mode);
2293 struct mdt_device *mdt = info->mti_mdt;
2294 struct ldlm_lock *lock = ldlm_handle2lock(h);
2295 struct ptlrpc_request *req = mdt_info_req(info);
2298 LASSERTF(lock != NULL, "no lock for cookie "LPX64"\n",
2300 CDEBUG(D_HA, "request = %p reply state = %p"
2301 " transno = "LPD64"\n",
2302 req, req->rq_reply_state, req->rq_transno);
2303 if (mdt_cos_is_enabled(mdt)) {
2305 ldlm_lock_downgrade(lock, LCK_COS);
2308 ptlrpc_save_lock(req, h, mode, no_ack);
2309 if (mdt_is_lock_sync(lock)) {
2310 CDEBUG(D_HA, "found sync-lock,"
2311 " async commit started\n");
2312 mdt_device_commit_async(info->mti_env,
2315 LDLM_LOCK_PUT(lock);
2324 * Unlock mdt object.
2326 * Immeditely release the regular lock and the PDO lock or save the
2327 * lock in reqeuest and keep them referenced until client ACK or
2328 * transaction commit.
2330 * \param info thread info object
2331 * \param o mdt object
2332 * \param lh mdt lock handle referencing regular and PDO locks
2333 * \param decref force immediate lock releasing
2335 void mdt_object_unlock(struct mdt_thread_info *info, struct mdt_object *o,
2336 struct mdt_lock_handle *lh, int decref)
2340 mdt_save_lock(info, &lh->mlh_pdo_lh, lh->mlh_pdo_mode, decref);
2341 mdt_save_lock(info, &lh->mlh_reg_lh, lh->mlh_reg_mode, decref);
2346 struct mdt_object *mdt_object_find_lock(struct mdt_thread_info *info,
2347 const struct lu_fid *f,
2348 struct mdt_lock_handle *lh,
2351 struct mdt_object *o;
2353 o = mdt_object_find(info->mti_env, info->mti_mdt, f);
2357 rc = mdt_object_lock(info, o, lh, ibits,
2360 mdt_object_put(info->mti_env, o);
2367 void mdt_object_unlock_put(struct mdt_thread_info * info,
2368 struct mdt_object * o,
2369 struct mdt_lock_handle *lh,
2372 mdt_object_unlock(info, o, lh, decref);
2373 mdt_object_put(info->mti_env, o);
2376 static struct mdt_handler *mdt_handler_find(__u32 opc,
2377 struct mdt_opc_slice *supported)
2379 struct mdt_opc_slice *s;
2380 struct mdt_handler *h;
2383 for (s = supported; s->mos_hs != NULL; s++) {
2384 if (s->mos_opc_start <= opc && opc < s->mos_opc_end) {
2385 h = s->mos_hs + (opc - s->mos_opc_start);
2386 if (likely(h->mh_opc != 0))
2387 LASSERTF(h->mh_opc == opc,
2388 "opcode mismatch %d != %d\n",
2391 h = NULL; /* unsupported opc */
2398 static int mdt_lock_resname_compat(struct mdt_device *m,
2399 struct ldlm_request *req)
2401 /* XXX something... later. */
2405 static int mdt_lock_reply_compat(struct mdt_device *m, struct ldlm_reply *rep)
2407 /* XXX something... later. */
2412 * Generic code handling requests that have struct mdt_body passed in:
2414 * - extract mdt_body from request and save it in @info, if present;
2416 * - create lu_object, corresponding to the fid in mdt_body, and save it in
2419 * - if HABEO_CORPUS flag is set for this request type check whether object
2420 * actually exists on storage (lu_object_exists()).
2423 static int mdt_body_unpack(struct mdt_thread_info *info, __u32 flags)
2425 const struct mdt_body *body;
2426 struct mdt_object *obj;
2427 const struct lu_env *env;
2428 struct req_capsule *pill;
2432 env = info->mti_env;
2433 pill = info->mti_pill;
2435 body = info->mti_body = req_capsule_client_get(pill, &RMF_MDT_BODY);
2439 if (!(body->valid & OBD_MD_FLID))
2442 if (!fid_is_sane(&body->fid1)) {
2443 CERROR("Invalid fid: "DFID"\n", PFID(&body->fid1));
2448 * Do not get size or any capa fields before we check that request
2449 * contains capa actually. There are some requests which do not, for
2450 * instance MDS_IS_SUBDIR.
2452 if (req_capsule_has_field(pill, &RMF_CAPA1, RCL_CLIENT) &&
2453 req_capsule_get_size(pill, &RMF_CAPA1, RCL_CLIENT))
2454 mdt_set_capainfo(info, 0, &body->fid1,
2455 req_capsule_client_get(pill, &RMF_CAPA1));
2457 obj = mdt_object_find(env, info->mti_mdt, &body->fid1);
2459 if ((flags & HABEO_CORPUS) &&
2460 !mdt_object_exists(obj)) {
2461 mdt_object_put(env, obj);
2462 /* for capability renew ENOENT will be handled in
2464 if (body->valid & OBD_MD_FLOSSCAPA)
2469 info->mti_object = obj;
2478 static int mdt_unpack_req_pack_rep(struct mdt_thread_info *info, __u32 flags)
2480 struct req_capsule *pill = info->mti_pill;
2484 if (req_capsule_has_field(pill, &RMF_MDT_BODY, RCL_CLIENT))
2485 rc = mdt_body_unpack(info, flags);
2489 if (rc == 0 && (flags & HABEO_REFERO)) {
2490 struct mdt_device *mdt = info->mti_mdt;
2494 if (req_capsule_has_field(pill, &RMF_MDT_MD, RCL_SERVER))
2495 req_capsule_set_size(pill, &RMF_MDT_MD, RCL_SERVER,
2496 mdt->mdt_max_mdsize);
2497 if (req_capsule_has_field(pill, &RMF_LOGCOOKIES, RCL_SERVER))
2498 req_capsule_set_size(pill, &RMF_LOGCOOKIES, RCL_SERVER,
2499 mdt->mdt_max_cookiesize);
2501 rc = req_capsule_server_pack(pill);
2506 static int mdt_init_capa_ctxt(const struct lu_env *env, struct mdt_device *m)
2508 struct md_device *next = m->mdt_child;
2510 return next->md_ops->mdo_init_capa_ctxt(env, next,
2511 m->mdt_opts.mo_mds_capa,
2512 m->mdt_capa_timeout,
2518 * Invoke handler for this request opc. Also do necessary preprocessing
2519 * (according to handler ->mh_flags), and post-processing (setting of
2520 * ->last_{xid,committed}).
2522 static int mdt_req_handle(struct mdt_thread_info *info,
2523 struct mdt_handler *h, struct ptlrpc_request *req)
2525 int rc, serious = 0;
2530 LASSERT(h->mh_act != NULL);
2531 LASSERT(h->mh_opc == lustre_msg_get_opc(req->rq_reqmsg));
2532 LASSERT(current->journal_info == NULL);
2535 * Checking for various OBD_FAIL_$PREF_$OPC_NET codes. _Do_ not try
2536 * to put same checks into handlers like mdt_close(), mdt_reint(),
2537 * etc., without talking to mdt authors first. Checking same thing
2538 * there again is useless and returning 0 error without packing reply
2539 * is buggy! Handlers either pack reply or return error.
2541 * We return 0 here and do not send any reply in order to emulate
2542 * network failure. Do not send any reply in case any of NET related
2543 * fail_id has occured.
2545 if (OBD_FAIL_CHECK_ORSET(h->mh_fail_id, OBD_FAIL_ONCE))
2549 flags = h->mh_flags;
2550 LASSERT(ergo(flags & (HABEO_CORPUS|HABEO_REFERO), h->mh_fmt != NULL));
2552 if (h->mh_fmt != NULL) {
2553 req_capsule_set(info->mti_pill, h->mh_fmt);
2554 rc = mdt_unpack_req_pack_rep(info, flags);
2557 if (rc == 0 && flags & MUTABOR &&
2558 req->rq_export->exp_connect_flags & OBD_CONNECT_RDONLY)
2559 /* should it be rq_status? */
2562 if (rc == 0 && flags & HABEO_CLAVIS) {
2563 struct ldlm_request *dlm_req;
2565 LASSERT(h->mh_fmt != NULL);
2567 dlm_req = req_capsule_client_get(info->mti_pill, &RMF_DLM_REQ);
2568 if (dlm_req != NULL) {
2569 if (unlikely(dlm_req->lock_desc.l_resource.lr_type ==
2571 dlm_req->lock_desc.l_policy_data.\
2572 l_inodebits.bits == 0)) {
2574 * Lock without inodebits makes no sense and
2575 * will oops later in ldlm. If client miss to
2576 * set such bits, do not trigger ASSERTION.
2578 * For liblustre flock case, it maybe zero.
2582 if (info->mti_mdt->mdt_opts.mo_compat_resname)
2583 rc = mdt_lock_resname_compat(
2586 info->mti_dlm_req = dlm_req;
2593 /* capability setting changed via /proc, needs reinitialize ctxt */
2594 if (info->mti_mdt && info->mti_mdt->mdt_capa_conf) {
2595 mdt_init_capa_ctxt(info->mti_env, info->mti_mdt);
2596 info->mti_mdt->mdt_capa_conf = 0;
2599 if (likely(rc == 0)) {
2601 * Process request, there can be two types of rc:
2602 * 1) errors with msg unpack/pack, other failures outside the
2603 * operation itself. This is counted as serious errors;
2604 * 2) errors during fs operation, should be placed in rq_status
2607 rc = h->mh_act(info);
2609 !req->rq_no_reply && req->rq_reply_state == NULL) {
2610 DEBUG_REQ(D_ERROR, req, "MDT \"handler\" %s did not "
2611 "pack reply and returned 0 error\n",
2615 serious = is_serious(rc);
2616 rc = clear_serious(rc);
2620 req->rq_status = rc;
2623 * ELDLM_* codes which > 0 should be in rq_status only as well as
2624 * all non-serious errors.
2626 if (rc > 0 || !serious)
2629 LASSERT(current->journal_info == NULL);
2631 if (rc == 0 && (flags & HABEO_CLAVIS) &&
2632 info->mti_mdt->mdt_opts.mo_compat_resname) {
2633 struct ldlm_reply *dlmrep;
2635 dlmrep = req_capsule_server_get(info->mti_pill, &RMF_DLM_REP);
2637 rc = mdt_lock_reply_compat(info->mti_mdt, dlmrep);
2640 /* If we're DISCONNECTing, the mdt_export_data is already freed */
2641 if (likely(rc == 0 && req->rq_export && h->mh_opc != MDS_DISCONNECT))
2642 target_committed_to_req(req);
2644 if (unlikely(req_is_replay(req) &&
2645 lustre_msg_get_transno(req->rq_reqmsg) == 0)) {
2646 DEBUG_REQ(D_ERROR, req, "transno is 0 during REPLAY");
2650 target_send_reply(req, rc, info->mti_fail_id);
2654 void mdt_lock_handle_init(struct mdt_lock_handle *lh)
2656 lh->mlh_type = MDT_NUL_LOCK;
2657 lh->mlh_reg_lh.cookie = 0ull;
2658 lh->mlh_reg_mode = LCK_MINMODE;
2659 lh->mlh_pdo_lh.cookie = 0ull;
2660 lh->mlh_pdo_mode = LCK_MINMODE;
2663 void mdt_lock_handle_fini(struct mdt_lock_handle *lh)
2665 LASSERT(!lustre_handle_is_used(&lh->mlh_reg_lh));
2666 LASSERT(!lustre_handle_is_used(&lh->mlh_pdo_lh));
2670 * Initialize fields of struct mdt_thread_info. Other fields are left in
2671 * uninitialized state, because it's too expensive to zero out whole
2672 * mdt_thread_info (> 1K) on each request arrival.
2674 static void mdt_thread_info_init(struct ptlrpc_request *req,
2675 struct mdt_thread_info *info)
2678 struct md_capainfo *ci;
2680 req_capsule_init(&req->rq_pill, req, RCL_SERVER);
2681 info->mti_pill = &req->rq_pill;
2684 for (i = 0; i < ARRAY_SIZE(info->mti_lh); i++)
2685 mdt_lock_handle_init(&info->mti_lh[i]);
2687 /* mdt device: it can be NULL while CONNECT */
2688 if (req->rq_export) {
2689 info->mti_mdt = mdt_dev(req->rq_export->exp_obd->obd_lu_dev);
2690 info->mti_exp = req->rq_export;
2692 info->mti_mdt = NULL;
2693 info->mti_env = req->rq_svc_thread->t_env;
2694 ci = md_capainfo(info->mti_env);
2695 memset(ci, 0, sizeof *ci);
2696 if (req->rq_export) {
2697 if (exp_connect_rmtclient(req->rq_export))
2698 ci->mc_auth = LC_ID_CONVERT;
2699 else if (req->rq_export->exp_connect_flags &
2700 OBD_CONNECT_MDS_CAPA)
2701 ci->mc_auth = LC_ID_PLAIN;
2703 ci->mc_auth = LC_ID_NONE;
2706 info->mti_fail_id = OBD_FAIL_MDS_ALL_REPLY_NET;
2707 info->mti_transno = lustre_msg_get_transno(req->rq_reqmsg);
2708 info->mti_mos = NULL;
2710 memset(&info->mti_attr, 0, sizeof(info->mti_attr));
2711 info->mti_body = NULL;
2712 info->mti_object = NULL;
2713 info->mti_dlm_req = NULL;
2714 info->mti_has_trans = 0;
2715 info->mti_no_need_trans = 0;
2716 info->mti_cross_ref = 0;
2717 info->mti_opdata = 0;
2719 /* To not check for split by default. */
2720 info->mti_spec.sp_ck_split = 0;
2721 info->mti_spec.no_create = 0;
2724 static void mdt_thread_info_fini(struct mdt_thread_info *info)
2728 req_capsule_fini(info->mti_pill);
2729 if (info->mti_object != NULL) {
2731 * freeing an object may lead to OSD level transaction, do not
2732 * let it mess with MDT. bz19385.
2734 info->mti_no_need_trans = 1;
2735 mdt_object_put(info->mti_env, info->mti_object);
2736 info->mti_object = NULL;
2738 for (i = 0; i < ARRAY_SIZE(info->mti_lh); i++)
2739 mdt_lock_handle_fini(&info->mti_lh[i]);
2740 info->mti_env = NULL;
2743 static int mdt_filter_recovery_request(struct ptlrpc_request *req,
2744 struct obd_device *obd, int *process)
2746 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
2747 case MDS_CONNECT: /* This will never get here, but for completeness. */
2748 case OST_CONNECT: /* This will never get here, but for completeness. */
2749 case MDS_DISCONNECT:
2750 case OST_DISCONNECT:
2755 case MDS_DONE_WRITING:
2756 case MDS_SYNC: /* used in unmounting */
2762 *process = target_queue_recovery_request(req, obd);
2766 DEBUG_REQ(D_ERROR, req, "not permitted during recovery");
2773 * Handle recovery. Return:
2774 * +1: continue request processing;
2775 * -ve: abort immediately with the given error code;
2776 * 0: send reply with error code in req->rq_status;
2778 static int mdt_recovery(struct mdt_thread_info *info)
2780 struct ptlrpc_request *req = mdt_info_req(info);
2781 struct obd_device *obd;
2785 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
2788 case SEC_CTX_INIT_CONT:
2794 rc = mdt_handle_idmap(info);
2803 if (unlikely(!class_connected_export(req->rq_export))) {
2804 CERROR("operation %d on unconnected MDS from %s\n",
2805 lustre_msg_get_opc(req->rq_reqmsg),
2806 libcfs_id2str(req->rq_peer));
2807 /* FIXME: For CMD cleanup, when mds_B stop, the req from
2808 * mds_A will get -ENOTCONN(especially for ping req),
2809 * which will cause that mds_A deactive timeout, then when
2810 * mds_A cleanup, the cleanup process will be suspended since
2811 * deactive timeout is not zero.
2813 req->rq_status = -ENOTCONN;
2814 target_send_reply(req, -ENOTCONN, info->mti_fail_id);
2818 /* sanity check: if the xid matches, the request must be marked as a
2819 * resent or replayed */
2820 if (req_xid_is_last(req)) {
2821 if (!(lustre_msg_get_flags(req->rq_reqmsg) &
2822 (MSG_RESENT | MSG_REPLAY))) {
2823 DEBUG_REQ(D_WARNING, req, "rq_xid "LPU64" matches last_xid, "
2824 "expected REPLAY or RESENT flag (%x)", req->rq_xid,
2825 lustre_msg_get_flags(req->rq_reqmsg));
2827 req->rq_status = -ENOTCONN;
2832 /* else: note the opposite is not always true; a RESENT req after a
2833 * failover will usually not match the last_xid, since it was likely
2834 * never committed. A REPLAYed request will almost never match the
2835 * last xid, however it could for a committed, but still retained,
2838 obd = req->rq_export->exp_obd;
2840 /* Check for aborted recovery... */
2841 if (unlikely(obd->obd_recovering)) {
2844 DEBUG_REQ(D_INFO, req, "Got new replay");
2845 rc = mdt_filter_recovery_request(req, obd, &should_process);
2846 if (rc != 0 || !should_process)
2848 else if (should_process < 0) {
2849 req->rq_status = should_process;
2850 rc = ptlrpc_error(req);
2857 static int mdt_msg_check_version(struct lustre_msg *msg)
2861 switch (lustre_msg_get_opc(msg)) {
2863 case MDS_DISCONNECT:
2866 case SEC_CTX_INIT_CONT:
2868 rc = lustre_msg_check_version(msg, LUSTRE_OBD_VERSION);
2870 CERROR("bad opc %u version %08x, expecting %08x\n",
2871 lustre_msg_get_opc(msg),
2872 lustre_msg_get_version(msg),
2873 LUSTRE_OBD_VERSION);
2877 case MDS_GETATTR_NAME:
2884 case MDS_DONE_WRITING:
2891 case MDS_QUOTACHECK:
2897 rc = lustre_msg_check_version(msg, LUSTRE_MDS_VERSION);
2899 CERROR("bad opc %u version %08x, expecting %08x\n",
2900 lustre_msg_get_opc(msg),
2901 lustre_msg_get_version(msg),
2902 LUSTRE_MDS_VERSION);
2906 case LDLM_BL_CALLBACK:
2907 case LDLM_CP_CALLBACK:
2908 rc = lustre_msg_check_version(msg, LUSTRE_DLM_VERSION);
2910 CERROR("bad opc %u version %08x, expecting %08x\n",
2911 lustre_msg_get_opc(msg),
2912 lustre_msg_get_version(msg),
2913 LUSTRE_DLM_VERSION);
2915 case OBD_LOG_CANCEL:
2916 case LLOG_ORIGIN_HANDLE_CREATE:
2917 case LLOG_ORIGIN_HANDLE_NEXT_BLOCK:
2918 case LLOG_ORIGIN_HANDLE_READ_HEADER:
2919 case LLOG_ORIGIN_HANDLE_CLOSE:
2920 case LLOG_ORIGIN_HANDLE_DESTROY:
2921 case LLOG_ORIGIN_HANDLE_PREV_BLOCK:
2923 rc = lustre_msg_check_version(msg, LUSTRE_LOG_VERSION);
2925 CERROR("bad opc %u version %08x, expecting %08x\n",
2926 lustre_msg_get_opc(msg),
2927 lustre_msg_get_version(msg),
2928 LUSTRE_LOG_VERSION);
2931 CERROR("MDS unknown opcode %d\n", lustre_msg_get_opc(msg));
2937 static int mdt_handle0(struct ptlrpc_request *req,
2938 struct mdt_thread_info *info,
2939 struct mdt_opc_slice *supported)
2941 struct mdt_handler *h;
2942 struct lustre_msg *msg;
2947 if (OBD_FAIL_CHECK_ORSET(OBD_FAIL_MDS_ALL_REQUEST_NET, OBD_FAIL_ONCE))
2950 LASSERT(current->journal_info == NULL);
2952 msg = req->rq_reqmsg;
2953 rc = mdt_msg_check_version(msg);
2954 if (likely(rc == 0)) {
2955 rc = mdt_recovery(info);
2956 if (likely(rc == +1)) {
2957 h = mdt_handler_find(lustre_msg_get_opc(msg),
2959 if (likely(h != NULL)) {
2960 rc = mdt_req_handle(info, h, req);
2962 CERROR("The unsupported opc: 0x%x\n",
2963 lustre_msg_get_opc(msg) );
2964 req->rq_status = -ENOTSUPP;
2965 rc = ptlrpc_error(req);
2970 CERROR(LUSTRE_MDT_NAME" drops mal-formed request\n");
2975 * MDT handler function called by ptlrpc service thread when request comes.
2977 * XXX common "target" functionality should be factored into separate module
2978 * shared by mdt, ost and stand-alone services like fld.
2980 static int mdt_handle_common(struct ptlrpc_request *req,
2981 struct mdt_opc_slice *supported)
2984 struct mdt_thread_info *info;
2988 env = req->rq_svc_thread->t_env;
2989 LASSERT(env != NULL);
2990 LASSERT(env->le_ses != NULL);
2991 LASSERT(env->le_ctx.lc_thread == req->rq_svc_thread);
2992 info = lu_context_key_get(&env->le_ctx, &mdt_thread_key);
2993 LASSERT(info != NULL);
2995 mdt_thread_info_init(req, info);
2997 rc = mdt_handle0(req, info, supported);
2999 mdt_thread_info_fini(info);
3004 * This is called from recovery code as handler of _all_ RPC types, FLD and SEQ
3007 int mdt_recovery_handle(struct ptlrpc_request *req)
3012 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
3014 rc = mdt_handle_common(req, mdt_fld_handlers);
3017 rc = mdt_handle_common(req, mdt_seq_handlers);
3020 rc = mdt_handle_common(req, mdt_regular_handlers);
3027 static int mdt_regular_handle(struct ptlrpc_request *req)
3029 return mdt_handle_common(req, mdt_regular_handlers);
3032 static int mdt_readpage_handle(struct ptlrpc_request *req)
3034 return mdt_handle_common(req, mdt_readpage_handlers);
3037 static int mdt_xmds_handle(struct ptlrpc_request *req)
3039 return mdt_handle_common(req, mdt_xmds_handlers);
3042 static int mdt_mdsc_handle(struct ptlrpc_request *req)
3044 return mdt_handle_common(req, mdt_seq_handlers);
3047 static int mdt_mdss_handle(struct ptlrpc_request *req)
3049 return mdt_handle_common(req, mdt_seq_handlers);
3052 static int mdt_dtss_handle(struct ptlrpc_request *req)
3054 return mdt_handle_common(req, mdt_seq_handlers);
3057 static int mdt_fld_handle(struct ptlrpc_request *req)
3059 return mdt_handle_common(req, mdt_fld_handlers);
3075 static int mdt_intent_getattr(enum mdt_it_code opcode,
3076 struct mdt_thread_info *info,
3077 struct ldlm_lock **,
3079 static int mdt_intent_reint(enum mdt_it_code opcode,
3080 struct mdt_thread_info *info,
3081 struct ldlm_lock **,
3084 static struct mdt_it_flavor {
3085 const struct req_format *it_fmt;
3087 int (*it_act)(enum mdt_it_code ,
3088 struct mdt_thread_info *,
3089 struct ldlm_lock **,
3092 } mdt_it_flavor[] = {
3094 .it_fmt = &RQF_LDLM_INTENT,
3095 /*.it_flags = HABEO_REFERO,*/
3097 .it_act = mdt_intent_reint,
3098 .it_reint = REINT_OPEN
3101 .it_fmt = &RQF_LDLM_INTENT,
3102 .it_flags = MUTABOR,
3103 .it_act = mdt_intent_reint,
3104 .it_reint = REINT_OPEN
3107 .it_fmt = &RQF_LDLM_INTENT,
3108 .it_flags = MUTABOR,
3109 .it_act = mdt_intent_reint,
3110 .it_reint = REINT_CREATE
3112 [MDT_IT_GETATTR] = {
3113 .it_fmt = &RQF_LDLM_INTENT_GETATTR,
3114 .it_flags = HABEO_REFERO,
3115 .it_act = mdt_intent_getattr
3117 [MDT_IT_READDIR] = {
3123 .it_fmt = &RQF_LDLM_INTENT_GETATTR,
3124 .it_flags = HABEO_REFERO,
3125 .it_act = mdt_intent_getattr
3128 .it_fmt = &RQF_LDLM_INTENT_UNLINK,
3129 .it_flags = MUTABOR,
3131 .it_reint = REINT_UNLINK
3135 .it_flags = MUTABOR,
3138 [MDT_IT_GETXATTR] = {
3145 int mdt_intent_lock_replace(struct mdt_thread_info *info,
3146 struct ldlm_lock **lockp,
3147 struct ldlm_lock *new_lock,
3148 struct mdt_lock_handle *lh,
3151 struct ptlrpc_request *req = mdt_info_req(info);
3152 struct ldlm_lock *lock = *lockp;
3155 * Get new lock only for cases when possible resent did not find any
3158 if (new_lock == NULL)
3159 new_lock = ldlm_handle2lock_long(&lh->mlh_reg_lh, 0);
3161 if (new_lock == NULL && (flags & LDLM_FL_INTENT_ONLY)) {
3162 lh->mlh_reg_lh.cookie = 0;
3166 LASSERTF(new_lock != NULL,
3167 "lockh "LPX64"\n", lh->mlh_reg_lh.cookie);
3170 * If we've already given this lock to a client once, then we should
3171 * have no readers or writers. Otherwise, we should have one reader
3172 * _or_ writer ref (which will be zeroed below) before returning the
3175 if (new_lock->l_export == req->rq_export) {
3176 LASSERT(new_lock->l_readers + new_lock->l_writers == 0);
3178 LASSERT(new_lock->l_export == NULL);
3179 LASSERT(new_lock->l_readers + new_lock->l_writers == 1);
3184 if (new_lock->l_export == req->rq_export) {
3186 * Already gave this to the client, which means that we
3187 * reconstructed a reply.
3189 LASSERT(lustre_msg_get_flags(req->rq_reqmsg) &
3191 lh->mlh_reg_lh.cookie = 0;
3192 RETURN(ELDLM_LOCK_REPLACED);
3196 * Fixup the lock to be given to the client.
3198 lock_res_and_lock(new_lock);
3199 /* Zero new_lock->l_readers and new_lock->l_writers without triggering
3200 * possible blocking AST. */
3201 while (new_lock->l_readers > 0) {
3202 lu_ref_del(&new_lock->l_reference, "reader", new_lock);
3203 lu_ref_del(&new_lock->l_reference, "user", new_lock);
3204 new_lock->l_readers--;
3206 while (new_lock->l_writers > 0) {
3207 lu_ref_del(&new_lock->l_reference, "writer", new_lock);
3208 lu_ref_del(&new_lock->l_reference, "user", new_lock);
3209 new_lock->l_writers--;
3212 new_lock->l_export = class_export_lock_get(req->rq_export, new_lock);
3213 new_lock->l_blocking_ast = lock->l_blocking_ast;
3214 new_lock->l_completion_ast = lock->l_completion_ast;
3215 new_lock->l_remote_handle = lock->l_remote_handle;
3216 new_lock->l_flags &= ~LDLM_FL_LOCAL;
3218 unlock_res_and_lock(new_lock);
3220 cfs_hash_add(new_lock->l_export->exp_lock_hash,
3221 &new_lock->l_remote_handle,
3222 &new_lock->l_exp_hash);
3224 LDLM_LOCK_RELEASE(new_lock);
3225 lh->mlh_reg_lh.cookie = 0;
3227 RETURN(ELDLM_LOCK_REPLACED);
3230 static void mdt_intent_fixup_resent(struct mdt_thread_info *info,
3231 struct ldlm_lock *new_lock,
3232 struct ldlm_lock **old_lock,
3233 struct mdt_lock_handle *lh)
3235 struct ptlrpc_request *req = mdt_info_req(info);
3236 struct obd_export *exp = req->rq_export;
3237 struct lustre_handle remote_hdl;
3238 struct ldlm_request *dlmreq;
3239 struct ldlm_lock *lock;
3241 if (!(lustre_msg_get_flags(req->rq_reqmsg) & MSG_RESENT))
3244 dlmreq = req_capsule_client_get(info->mti_pill, &RMF_DLM_REQ);
3245 remote_hdl = dlmreq->lock_handle[0];
3247 lock = cfs_hash_lookup(exp->exp_lock_hash, &re